ackPacketPrint

decompiled_code:
int __fastcall ackPacketPrint(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, unsigned __int16 a7, __int64 a8, __int64 a9)
{
__int64 i; // rbx

puts("AckPacket :");
printf("\tcurrBlock = %u\n", a7);
printf("\tAck Seq No = %u\n", (unsigned int)a9);
for ( i = 0LL; i != 3; ++i )
printf("\tdofs for block %i = %u\n", (unsigned int)i, *(unsigned __int8 *)(a8 + i));
printf("\tloss = %u\n", WORD2(a9));
return printf("\ttotal = %u\n", HIWORD(a9));
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, unsigned __int16 a7, __int64 a8, __int64 a9)
{
__int64 i; // rbx

puts("AckPacket :");
printf("\tcurrBlock = %u\n", a7);
printf("\tAck Seq No = %u\n", (unsigned int)a9);
for ( i = 0LL; i != 3; ++i )
printf("\tdofs for block %i = %u\n", (unsigned int)i, *(unsigned __int8 *)(a8 + i));
printf("\tloss = %u\n", WORD2(a9));
return printf("\ttotal = %u\n", HIWORD(a9));
}

original_code:
void ackPacketPrint(ackpacket p){
    int i;
    printf("AckPacket :\n");
    printf("\tcurrBlock = %u\n", p.ack_currBlock);
    printf("\tAck Seq No = %u\n", p.ack_seqNo);
    for(i = 0; i < 3; i++){
        printf("\tdofs for block %i = %u\n", i, p.ack_dofs[i]);
    }
    printf("\tloss = %u\n", p.ack_loss);
    printf("\ttotal = %u\n", p.ack_total);
}

canonical_original_code:
void ackPacketPrint(struct ackpacket_t p){
    int i;
    printf("AckPacket :\n");
    printf("\tcurrBlock = %u\n", p.ack_currBlock);
    printf("\tAck Seq No = %u\n", p.ack_seqNo);
    for(i = 0; i < 3; i++){
        printf("\tdofs for block %i = %u\n", i, p.ack_dofs[i]);
    }
    printf("\tloss = %u\n", p.ack_loss);
    printf("\ttotal = %u\n", p.ack_total);
}

variable_types: struct ackpacket_t { unsigned short ack_currBlock; unsigned char *ack_dofs; unsigned int ack_seqNo; unsigned short ack_loss; unsigned short ack_total; }


printMux

repo: GregoireDelannoy/TCPeP

decompiled_code:
__int64 __fastcall printMux(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, unsigned int a8, unsigned int a9, __int64 a10, _QWORD *a11, _QWORD *a12, int a13)
{
const char *v13; // rdi
__int64 v14; // rdx
__int64 v15; // rcx
__int64 v16; // r8
__int64 v17; // r9
__int64 v18; // rdx
__int64 v19; // rcx
__int64 v20; // r8
__int64 v21; // r9

puts("Mux :");
printf("\tsock_fd = %d\n", (unsigned int)a7);
printf("\tsport = %u\n", WORD2(a7));
printf("\tdport = %u\n", HIWORD(a7));
printf("\tremote_ip = %u\n", a8);
printf("\tremote udp = %u\n", a9);
printf("\tRandom ID = %u\n", WORD2(a10));
switch ( a13 )
{
case 3:
v13 = "\tState opened duplex";
puts("\tState opened duplex");
break;
case 4:
v13 = "\tState init";
puts("\tState init");
break;
case 2:
v13 = "\tState opened simplex";
puts("\tState opened simplex");
break;
default:
v13 = "\tState unknown";
puts("\tState unknown");
break;
}
encoderStatePrint(
v13,
WORD2(a10),
v14,
v15,
v16,
v17,
*a11,
a11[1],
a11[2],
a11[3],
a11[4],
a11[5],
a11[6],
a11[7],
a11[8],
a11[9],
a11[10],
a11[11]);
return decoderStatePrint(
v13,
WORD2(a10),
v18,
v19,
v20,
v21,
*a12,
a12[1],
a12[2],
a12[3],
a12[4],
a12[5],
a12[6],
a12[7],
a12[8],
a12[9]);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, unsigned int a8, unsigned int a9, __int64 a10, _QWORD *a11, _QWORD *a12, int a13)
{
const char *v13; // rdi
__int64 v14; // rdx
__int64 v15; // rcx
__int64 v16; // r8
__int64 v17; // r9
__int64 v18; // rdx
__int64 v19; // rcx
__int64 v20; // r8
__int64 v21; // r9

puts("Mux :");
printf("\tsock_fd = %d\n", (unsigned int)a7);
printf("\tsport = %u\n", WORD2(a7));
printf("\tdport = %u\n", HIWORD(a7));
printf("\tremote_ip = %u\n", a8);
printf("\tremote udp = %u\n", a9);
printf("\tRandom ID = %u\n", WORD2(a10));
switch ( a13 )
{
case 3:
v13 = "\tState opened duplex";
puts("\tState opened duplex");
break;
case 4:
v13 = "\tState init";
puts("\tState init");
break;
case 2:
v13 = "\tState opened simplex";
puts("\tState opened simplex");
break;
default:
v13 = "\tState unknown";
puts("\tState unknown");
break;
}
encoderStatePrint(
v13,
WORD2(a10),
v14,
v15,
v16,
v17,
*a11,
a11[1],
a11[2],
a11[3],
a11[4],
a11[5],
a11[6],
a11[7],
a11[8],
a11[9],
a11[10],
a11[11]);
return decoderStatePrint(
v13,
WORD2(a10),
v18,
v19,
v20,
v21,
*a12,
a12[1],
a12[2],
a12[3],
a12[4],
a12[5],
a12[6],
a12[7],
a12[8],
a12[9]);
}

original_code:
void printMux(muxstate mux){
    printf("Mux :\n");
    printf("\tsock_fd = %d\n", mux.sock_fd);
    printf("\tsport = %u\n", mux.sport);
    printf("\tdport = %u\n", mux.dport);
    printf("\tremote_ip = %u\n", mux.remote_ip);
    printf("\tremote udp = %u\n", (unsigned int)mux.udpRemote.sin_addr.s_addr);
    printf("\tRandom ID = %u\n", mux.randomId);
    switch(mux.state){
        case 0x04:
            printf("\tState init\n");
            break;
        case 0x03:
            printf("\tState opened duplex\n");
            break;
        case 0x02:
            printf("\tState opened simplex\n");
            break;
        default:
            printf("\tState unknown\n");
    }
    encoderStatePrint(*(mux.encoderState));
    decoderStatePrint(*(mux.decoderState));
}

canonical_original_code:
void printMux(struct muxstate_t mux){
    printf("Mux :\n");
    printf("\tsock_fd = %d\n", mux.sock_fd);
    printf("\tsport = %u\n", mux.sport);
    printf("\tdport = %u\n", mux.dport);
    printf("\tremote_ip = %u\n", mux.remote_ip);
    printf("\tremote udp = %u\n", (unsigned int)mux.udpRemote.sin_addr.s_addr);
    printf("\tRandom ID = %u\n", mux.randomId);
    switch(mux.state){
        case 0x04:
            printf("\tState init\n");
            break;
        case 0x03:
            printf("\tState opened duplex\n");
            break;
        case 0x02:
            printf("\tState opened simplex\n");
            break;
        default:
            printf("\tState unknown\n");
    }
    encoderStatePrint(*(mux.encoderState));
    decoderStatePrint(*(mux.decoderState));
}

variable_types: struct muxstate_t { int sock_fd; unsigned short sport; unsigned short dport; unsigned int remote_ip; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } udpRemote; unsigned short randomId; struct encoderstate_t { struct block_t { struct matrix_t { unsigned char **data; int nRows; int nColumns; } *dataMatrix; int nPackets; int isSentPacket[127]; unsigned char dofs; } *blocks; int numBlock; struct timeval { long tv_sec; long tv_usec; } nextTimeout; struct packetsentinfo_t { unsigned int seqNo; unsigned short blockNo; struct timeval sentAt; } **packetSentInfos; int *nPacketSent; float p; double shortTermRttAverage; double longTermRttAverage; unsigned int seqNo_Next; unsigned int seqNo_Una; struct timeval time_lastAck; float congestionWindow; unsigned short currBlock; int slowStartMode; int timeOutCounter; int isOutstandingData; unsigned char **dataToSend; int *dataToSendSize; int nDataToSend; } *encoderState; struct decoderstate_t { struct matrix_t **blocks; struct matrix_t **coefficients; struct lossInformationBuffer_t { int isReceived[512]; int currentIndex; } *lossBuffer; unsigned short currBlock; int numBlock; int *nPacketsInBlock; int **isSentPacketInBlock; unsigned char *dataToSend; int nDataToSend; unsigned char **ackToSend; int *ackToSendSize; int nAckToSend; unsigned int lastSeqReceived; unsigned long stats_nAppendedNotInnovativeGaloisFirstBlock; unsigned long stats_nAppendedNotInnovativeGaloisOtherBlock; unsigned long stats_nOutdated; unsigned long stats_nAppendedNotInnovativeCounter; unsigned long stats_nInnovative; } *decoderState; int state; int localSocketReadState; int localSocketWriteState; int remoteSocketReadState; int remoteSocketWriteState; struct timeval lastWriteSent; int remoteOutstandingData; int localOutstandingData; struct timeval lastOutstandingSent; }

return_type: void

user_defined_types: struct muxstate_t { int sock_fd; unsigned short sport; unsigned short dport; unsigned int remote_ip; struct sockaddr_in udpRemote; unsigned short randomId; struct encoderstate_t *encoderState; struct decoderstate_t *decoderState; int state; int localSocketReadState; int localSocketWriteState; int remoteSocketReadState; int remoteSocketWriteState; struct timeval lastWriteSent; int remoteOutstandingData; int localOutstandingData; struct timeval lastOutstandingSent; }

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct encoderstate_t { struct block_t *blocks; int numBlock; struct timeval nextTimeout; struct packetsentinfo_t **packetSentInfos; int *nPacketSent; float p; double shortTermRttAverage; double longTermRttAverage; unsigned int seqNo_Next; unsigned int seqNo_Una; struct timeval time_lastAck; float congestionWindow; unsigned short currBlock; int slowStartMode; int timeOutCounter; int isOutstandingData; unsigned char **dataToSend; int *dataToSendSize; int nDataToSend; }

user_defined_types: struct decoderstate_t { struct matrix_t **blocks; struct matrix_t **coefficients; struct lossInformationBuffer_t *lossBuffer; unsigned short currBlock; int numBlock; int *nPacketsInBlock; int **isSentPacketInBlock; unsigned char *dataToSend; int nDataToSend; unsigned char **ackToSend; int *ackToSendSize; int nAckToSend; unsigned int lastSeqReceived; unsigned long stats_nAppendedNotInnovativeGaloisFirstBlock; unsigned long stats_nAppendedNotInnovativeGaloisOtherBlock; unsigned long stats_nOutdated; unsigned long stats_nAppendedNotInnovativeCounter; unsigned long stats_nInnovative; }

user_defined_types: struct block_t { struct matrix_t *dataMatrix; int nPackets; int isSentPacket[127]; unsigned char dofs; }


assignMux

original_code:
int assignMux(uint16_t sport, uint16_t dport, uint32_t remote_ip, uint16_t randomId, int sock_fd, muxstate** statesTable, int* tableLength, struct sockaddr_in udpRemoteAddr){
    int i;
    for(i=0; i<(*tableLength); i++){
        if(
            ((*statesTable)[i].sport == sport) &&
            ((*statesTable)[i].dport == dport) &&
            ((*statesTable)[i].remote_ip == remote_ip) &&
            ((*statesTable)[i].udpRemote.sin_addr.s_addr == udpRemoteAddr.sin_addr.s_addr) &&
            ((*statesTable)[i].udpRemote.sin_port == udpRemoteAddr.sin_port) &&
            ((*statesTable)[i].randomId == randomId)
        ){
            return i;
        }
    }
    printf("No existing mux ; create one\n");
    (*tableLength)++;
    *statesTable = realloc(*statesTable, (*tableLength) * sizeof(muxstate));
    (*statesTable)[(*tableLength) - 1].sport = sport;
    (*statesTable)[(*tableLength) - 1].dport = dport;
    (*statesTable)[(*tableLength) - 1].remote_ip = remote_ip;
    (*statesTable)[(*tableLength) - 1].sock_fd = sock_fd;
    (*statesTable)[(*tableLength) - 1].randomId = randomId;
    (*statesTable)[(*tableLength) - 1].encoderState = encoderStateInit();
    (*statesTable)[(*tableLength) - 1].decoderState = decoderStateInit();
    (*statesTable)[(*tableLength) - 1].state = 0x04;
    (*statesTable)[(*tableLength) - 1].localSocketReadState = 0x00;
    (*statesTable)[(*tableLength) - 1].localSocketWriteState = 0x00;
    (*statesTable)[(*tableLength) - 1].remoteSocketReadState = 0x01;
    (*statesTable)[(*tableLength) - 1].remoteSocketWriteState = 0x01;
    (*statesTable)[(*tableLength) - 1].localOutstandingData = 0x00;
    (*statesTable)[(*tableLength) - 1].remoteOutstandingData = 0x01;
    (*statesTable)[(*tableLength) - 1].lastWriteSent.tv_sec = 1;
    (*statesTable)[(*tableLength) - 1].lastWriteSent.tv_usec = 0;
    (*statesTable)[(*tableLength) - 1].lastOutstandingSent.tv_sec = 1;
    (*statesTable)[(*tableLength) - 1].lastOutstandingSent.tv_usec = 0;
    memset(&((*statesTable)[(*tableLength) - 1].udpRemote), 0, sizeof((*statesTable)[(*tableLength) - 1].udpRemote));
    (*statesTable)[(*tableLength) - 1].udpRemote.sin_family = 2;
    (*statesTable)[(*tableLength) - 1].udpRemote.sin_addr.s_addr = udpRemoteAddr.sin_addr.s_addr;
    (*statesTable)[(*tableLength) - 1].udpRemote.sin_port = udpRemoteAddr.sin_port;
    return (*tableLength) - 1;
}

canonical_original_code:
int assignMux(unsigned short sport, unsigned short dport, unsigned int remote_ip, unsigned short randomId, int sock_fd, struct muxstate_t **statesTable, int *tableLength, struct sockaddr_in udpRemoteAddr){
    int i;
    for(i=0; i<(*tableLength); i++){
        if(
            ((*statesTable)[i].sport == sport) &&
            ((*statesTable)[i].dport == dport) &&
            ((*statesTable)[i].remote_ip == remote_ip) &&
            ((*statesTable)[i].udpRemote.sin_addr.s_addr == udpRemoteAddr.sin_addr.s_addr) &&
            ((*statesTable)[i].udpRemote.sin_port == udpRemoteAddr.sin_port) &&
            ((*statesTable)[i].randomId == randomId)
        ){
            return i;
        }
    }
    printf("No existing mux ; create one\n");
    (*tableLength)++;
    *statesTable = realloc(*statesTable, (*tableLength) * sizeof(muxstate));
    (*statesTable)[(*tableLength) - 1].sport = sport;
    (*statesTable)[(*tableLength) - 1].dport = dport;
    (*statesTable)[(*tableLength) - 1].remote_ip = remote_ip;
    (*statesTable)[(*tableLength) - 1].sock_fd = sock_fd;
    (*statesTable)[(*tableLength) - 1].randomId = randomId;
    (*statesTable)[(*tableLength) - 1].encoderState = encoderStateInit();
    (*statesTable)[(*tableLength) - 1].decoderState = decoderStateInit();
    (*statesTable)[(*tableLength) - 1].state = 0x04;
    (*statesTable)[(*tableLength) - 1].localSocketReadState = 0x00;
    (*statesTable)[(*tableLength) - 1].localSocketWriteState = 0x00;
    (*statesTable)[(*tableLength) - 1].remoteSocketReadState = 0x01;
    (*statesTable)[(*tableLength) - 1].remoteSocketWriteState = 0x01;
    (*statesTable)[(*tableLength) - 1].localOutstandingData = 0x00;
    (*statesTable)[(*tableLength) - 1].remoteOutstandingData = 0x01;
    (*statesTable)[(*tableLength) - 1].lastWriteSent.tv_sec = 1;
    (*statesTable)[(*tableLength) - 1].lastWriteSent.tv_usec = 0;
    (*statesTable)[(*tableLength) - 1].lastOutstandingSent.tv_sec = 1;
    (*statesTable)[(*tableLength) - 1].lastOutstandingSent.tv_usec = 0;
    memset(&((*statesTable)[(*tableLength) - 1].udpRemote), 0, sizeof((*statesTable)[(*tableLength) - 1].udpRemote));
    (*statesTable)[(*tableLength) - 1].udpRemote.sin_family = 2;
    (*statesTable)[(*tableLength) - 1].udpRemote.sin_addr.s_addr = udpRemoteAddr.sin_addr.s_addr;
    (*statesTable)[(*tableLength) - 1].udpRemote.sin_port = udpRemoteAddr.sin_port;
    return (*tableLength) - 1;
}

variable_types:
sport
unsigned short

variable_types:
dport
unsigned short

variable_types:
randomId
unsigned short

variable_types: struct muxstate_t { int sock_fd; unsigned short sport; unsigned short dport; unsigned int remote_ip; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } udpRemote; unsigned short randomId; struct encoderstate_t { struct block_t { struct matrix_t { unsigned char **data; int nRows; int nColumns; } *dataMatrix; int nPackets; int isSentPacket[127]; unsigned char dofs; } *blocks; int numBlock; struct timeval { long tv_sec; long tv_usec; } nextTimeout; struct packetsentinfo_t { unsigned int seqNo; unsigned short blockNo; struct timeval sentAt; } **packetSentInfos; int *nPacketSent; float p; double shortTermRttAverage; double longTermRttAverage; unsigned int seqNo_Next; unsigned int seqNo_Una; struct timeval time_lastAck; float congestionWindow; unsigned short currBlock; int slowStartMode; int timeOutCounter; int isOutstandingData; unsigned char **dataToSend; int *dataToSendSize; int nDataToSend; } *encoderState; struct decoderstate_t { struct matrix_t **blocks; struct matrix_t **coefficients; struct lossInformationBuffer_t { int isReceived[512]; int currentIndex; } *lossBuffer; unsigned short currBlock; int numBlock; int *nPacketsInBlock; int **isSentPacketInBlock; unsigned char *dataToSend; int nDataToSend; unsigned char **ackToSend; int *ackToSendSize; int nAckToSend; unsigned int lastSeqReceived; unsigned long stats_nAppendedNotInnovativeGaloisFirstBlock; unsigned long stats_nAppendedNotInnovativeGaloisOtherBlock; unsigned long stats_nOutdated; unsigned long stats_nAppendedNotInnovativeCounter; unsigned long stats_nInnovative; } *decoderState; int state; int localSocketReadState; int localSocketWriteState; int remoteSocketReadState; int remoteSocketWriteState; struct timeval lastWriteSent; int remoteOutstandingData; int localOutstandingData; struct timeval lastOutstandingSent; } **

variable_types:
tableLength
int *

variable_types:
udpRemoteAddr
struct sockaddr_in

variable_types: i int

return_type: int


removeMux

original_code:
void removeMux(int index, muxstate** statesTable, int* tableLength){
    if(index >= (*tableLength)){
        my_err("in removeMux : index>= size\n");
        exit(1);
    } else {
        int i;
        if((*statesTable)[index].sock_fd != -1){
            if(close((*statesTable)[index].sock_fd) != 0){
                perror("In removeMux : error while close()ing");
                exit(1);
            }
        } else {
            printf("Removing a Mux whithout opened socket (fd == -1)\n");
        }
        encoderStateFree((*statesTable)[index].encoderState);
        decoderStateFree((*statesTable)[index].decoderState);
        for(i = index; i < ((*tableLength) - 1); i++){
            (*statesTable)[i] = (*statesTable)[i + 1];
        }
        (*tableLength)--;
        *statesTable = realloc(*statesTable, (*tableLength) * sizeof(muxstate));
    }
}

canonical_original_code:
void removeMux(int index, struct muxstate_t **statesTable, int *tableLength){
    if(index >= (*tableLength)){
        my_err("in removeMux : index>= size\n");
        exit(1);
    } else {
        int i;
        if((*statesTable)[index].sock_fd != -1){
            if(close((*statesTable)[index].sock_fd) != 0){
                perror("In removeMux : error while close()ing");
                exit(1);
            }
        } else {
            printf("Removing a Mux whithout opened socket (fd == -1)\n");
        }
        encoderStateFree((*statesTable)[index].encoderState);
        decoderStateFree((*statesTable)[index].decoderState);
        for(i = index; i < ((*tableLength) - 1); i++){
            (*statesTable)[i] = (*statesTable)[i + 1];
        }
        (*tableLength)--;
        *statesTable = realloc(*statesTable, (*tableLength) * sizeof(muxstate));
    }
}

variable_types: index int

user_defined_types: struct timeval { long tv_sec; long tv_usec; }

user_defined_types: struct lossInformationBuffer_t { int isReceived[512]; int currentIndex; }

user_defined_types: struct packetsentinfo_t { unsigned int seqNo; unsigned short blockNo; struct timeval sentAt; }

user_defined_types: struct matrix_t { unsigned char **data; int nRows; int nColumns; }


muxedToBuffer

decompiled_code:
__int64 __fastcall muxedToBuffer(__int64 a1, void *a2, int a3, int *a4, __int64 a5, _BYTE *a6)
{
int v10; // ebp

if ( a3 <= 10 )
return 0LL;
*(_WORD *)(a5 + 4) = _bswap_16(*(_WORD *)a1);
*(_WORD *)(a5 + 6) = _bswap_16(*(_WORD *)(a1 + 2));
*(_DWORD *)(a5 + 8) = _bswap_32(*(_DWORD *)(a1 + 4));
*a6 = *(_BYTE *)(a1 + 8);
*(_WORD *)(a5 + 28) = _bswap_16(*(_WORD *)(a1 + 9));
if ( *a6 > 9u )
{
puts("In protocol.c/muxedToBuffer : We received an incoherent buffer. DIE.");
exit(1);
}
v10 = a3 - 11;
memcpy(a2, (const void *)(a1 + 11), v10);
*a4 = v10;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, void *a2, int a3, int *a4, __int64 a5, _BYTE *a6)
{
int v10; // ebp

if ( a3 <= 10 )
return 0LL;
*(_WORD *)(a5 + 4) = func1(*(_WORD *)a1);
*(_WORD *)(a5 + 6) = func1(*(_WORD *)(a1 + 2));
*(_DWORD *)(a5 + 8) = func0(*(_DWORD *)(a1 + 4));
*a6 = *(_BYTE *)(a1 + 8);
*(_WORD *)(a5 + 28) = func1(*(_WORD *)(a1 + 9));
if ( *a6 > 9u )
{
puts("In protocol.c/muxedToBuffer : We received an incoherent buffer. DIE.");
exit(1);
}
v10 = a3 - 11;
memcpy(a2, (const void *)(a1 + 11), v10);
*a4 = v10;
return 1LL;
}

original_code:
int muxedToBuffer(uint8_t* src, uint8_t* dst, int srcLen, int* dstLen, muxstate* mux, uint8_t* type){
    uint16_t tmp16;
    uint32_t tmp32;
    uint8_t tmp8;
    if(srcLen >= 11){
        memcpy(&tmp16, src, 2);
        mux->sport = ntohs(tmp16);
        memcpy(&tmp16, src + 2, 2);
        mux->dport = ntohs(tmp16);
        memcpy(&tmp32, src + 4, 4);
        mux->remote_ip = ntohl(tmp32);
        memcpy(&tmp8, src + 8, 1);
        (*type) = tmp8;
        memcpy(&tmp16, src + 9, 2);
        mux->randomId = ntohs(tmp16);
        if( (*type == 0x01)
          || (*type == 0x02)
          || (*type == 0x00)
          || (*type == 0x03)
          || (*type == 0x04)
          || (*type == 0x05)
          || (*type == 0x06)
          || (*type == 0x07)
          || (*type == 0x08)
          || (*type == 0x09)
        ){
            memcpy(dst, src + 11, srcLen - 11);
            (*dstLen) = srcLen - 11;
            return 1==1;
        } else {
            printf("In protocol.c/muxedToBuffer : We received an incoherent buffer. DIE.\n");
            exit(1);
        }
    }
    return 1==0;
}

canonical_original_code:
int muxedToBuffer(unsigned char *src, unsigned char *dst, int srcLen, int *dstLen, struct muxstate_t *mux, unsigned char *type){
    unsigned short tmp16;
    unsigned int tmp32;
    unsigned char tmp8;
    if(srcLen >= 11){
        memcpy(&tmp16, src, 2);
        mux->sport = ntohs(tmp16);
        memcpy(&tmp16, src + 2, 2);
        mux->dport = ntohs(tmp16);
        memcpy(&tmp32, src + 4, 4);
        mux->remote_ip = ntohl(tmp32);
        memcpy(&tmp8, src + 8, 1);
        (*type) = tmp8;
        memcpy(&tmp16, src + 9, 2);
        mux->randomId = ntohs(tmp16);
        if( (*type == 0x01)
          || (*type == 0x02)
          || (*type == 0x00)
          || (*type == 0x03)
          || (*type == 0x04)
          || (*type == 0x05)
          || (*type == 0x06)
          || (*type == 0x07)
          || (*type == 0x08)
          || (*type == 0x09)
        ){
            memcpy(dst, src + 11, srcLen - 11);
            (*dstLen) = srcLen - 11;
            return 1==1;
        } else {
            printf("In protocol.c/muxedToBuffer : We received an incoherent buffer. DIE.\n");
            exit(1);
        }
    }
    return 1==0;
}

variable_types:
src
unsigned char *

variable_types:
dst
unsigned char *

variable_types: srcLen int

variable_types:
dstLen
int *

variable_types: struct muxstate_t { int sock_fd; unsigned short sport; unsigned short dport; unsigned int remote_ip; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } udpRemote; unsigned short randomId; struct encoderstate_t { struct block_t { struct matrix_t { unsigned char **data; int nRows; int nColumns; } *dataMatrix; int nPackets; int isSentPacket[127]; unsigned char dofs; } *blocks; int numBlock; struct timeval { long tv_sec; long tv_usec; } nextTimeout; struct packetsentinfo_t { unsigned int seqNo; unsigned short blockNo; struct timeval sentAt; } **packetSentInfos; int *nPacketSent; float p; double shortTermRttAverage; double longTermRttAverage; unsigned int seqNo_Next; unsigned int seqNo_Una; struct timeval time_lastAck; float congestionWindow; unsigned short currBlock; int slowStartMode; int timeOutCounter; int isOutstandingData; unsigned char **dataToSend; int *dataToSendSize; int nDataToSend; } *encoderState; struct decoderstate_t { struct matrix_t **blocks; struct matrix_t **coefficients; struct lossInformationBuffer_t { int isReceived[512]; int currentIndex; } *lossBuffer; unsigned short currBlock; int numBlock; int *nPacketsInBlock; int **isSentPacketInBlock; unsigned char *dataToSend; int nDataToSend; unsigned char **ackToSend; int *ackToSendSize; int nAckToSend; unsigned int lastSeqReceived; unsigned long stats_nAppendedNotInnovativeGaloisFirstBlock; unsigned long stats_nAppendedNotInnovativeGaloisOtherBlock; unsigned long stats_nOutdated; unsigned long stats_nAppendedNotInnovativeCounter; unsigned long stats_nInnovative; } *decoderState; int state; int localSocketReadState; int localSocketWriteState; int remoteSocketReadState; int remoteSocketWriteState; struct timeval lastWriteSent; int remoteOutstandingData; int localOutstandingData; struct timeval lastOutstandingSent; } *

variable_types:
type
unsigned char *


gadd

decompiled_code:
__int64 __fastcall gadd(int a1, unsigned int a2)
{
return a1 ^ a2;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, unsigned int a2)
{
return a1 ^ a2;
}

original_code:
uint8_t gadd(uint8_t a, uint8_t b) {
    return a ^ b;
}

canonical_original_code:
unsigned char gadd(unsigned char a, unsigned char b) {
    return a ^ b;
}

variable_types:
a
unsigned char

variable_types:
b
unsigned char

return_type: unsigned char


gsub

decompiled_code:
__int64 __fastcall gsub(int a1, unsigned int a2)
{
return a1 ^ a2;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, unsigned int a2)
{
return a1 ^ a2;
}

original_code:
uint8_t gsub(uint8_t a, uint8_t b) {
    return a ^ b;
}

canonical_original_code:
unsigned char gsub(unsigned char a, unsigned char b) {
    return a ^ b;
}


gmul

decompiled_code:
__int64 __fastcall gmul(unsigned __int8 a1, unsigned __int8 a2)
{
__int64 result; // rax

if ( a1 && a2 )
result = (unsigned __int8)atable[(unsigned __int8)ltable[a2] + (unsigned __int8)ltable[a1]];
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int8 a1, unsigned __int8 a2)
{
__int64 result; // rax

if ( a1 && a2 )
result = (unsigned __int8)atable[(unsigned __int8)ltable[a2] + (unsigned __int8)ltable[a1]];
else
result = 0LL;
return result;
}

original_code:
uint8_t gmul(uint8_t a, uint8_t b) {
    if((a == 0) || (b == 0)){
        return 0;
    } else {
        return atable[ltable[a] + ltable[b]];
    }
}

canonical_original_code:
unsigned char gmul(unsigned char a, unsigned char b) {
    if((a == 0) || (b == 0)){
        return 0;
    } else {
        return atable[ltable[a] + ltable[b]];
    }
}


gdiv

decompiled_code:
__int64 __fastcall gdiv(unsigned int a1, unsigned __int8 a2)
{
if ( !(_BYTE)a1 )
return a1;
if ( !a2 )
{
printf("Code tried to divide %x by %x !\n", (unsigned __int8)a1, 0LL);
exit(1);
}
return (unsigned __int8)atable[(unsigned __int8)ltable[(unsigned __int8)a1] + 255 - (unsigned __int8)ltable[a2]];
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, unsigned __int8 a2)
{
if ( !(_BYTE)a1 )
return a1;
if ( !a2 )
{
printf("Code tried to divide %x by %x !\n", (unsigned __int8)a1, 0LL);
exit(1);
}
return (unsigned __int8)atable[(unsigned __int8)ltable[(unsigned __int8)a1] + 255 - (unsigned __int8)ltable[a2]];
}

original_code:
uint8_t gdiv(uint8_t a, uint8_t b) {
    if(a == 0){
        return 0;
    } else if(b == 0){
        printf("Code tried to divide %x by %x !\n", a, b);
        exit(1);
    } else {
        return atable[255 + ltable[a] - ltable[b]];
    }
}

canonical_original_code:
unsigned char gdiv(unsigned char a, unsigned char b) {
    if(a == 0){
        return 0;
    } else if(b == 0){
        printf("Code tried to divide %x by %x !\n", a, b);
        exit(1);
    } else {
        return atable[255 + ltable[a] - ltable[b]];
    }
}


getRandom

decompiled_code:
__int64 getRandom()
{
unsigned int i; // edx

for ( i = random(); !(_BYTE)i; i = random() )
;
return i;
}

canonical_decompiled_code:
__int64 func4()
{
unsigned int i; // edx

for ( i = random(); !(_BYTE)i; i = random() )
;
return i;
}

original_code:
uint8_t getRandom(){
    int n = random();
    while(((n & 0xFF) == 0x00)){
        n = random();
    }
    return (uint8_t)n;
}

canonical_original_code:
unsigned char getRandom(){
    int n = random();
    while(((n & 0xFF) == 0x00)){
        n = random();
    }
    return (unsigned char)n;
}

variable_types: n int


usage

decompiled_code:
void __noreturn usage()
{
fwrite("Usage:\n", 1uLL, 7uLL, stderr);
fwrite("-h: Print this message\n", 1uLL, 0x17uLL, stderr);
fwrite("-P: Proxy mode\n", 1uLL, 0xFuLL, stderr);
fwrite("-C <proxy IP address>: Client mode\n", 1uLL, 0x23uLL, stderr);
fwrite("-t <TCP port to listen on> (client only)\n", 1uLL, 0x29uLL, stderr);
fwrite("-u <UDP port to use>\n", 1uLL, 0x15uLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func0()
{
fwrite("Usage:\n", 1uLL, 7uLL, stderr);
fwrite("-h: Print this message\n", 1uLL, 0x17uLL, stderr);
fwrite("-P: Proxy mode\n", 1uLL, 0xFuLL, stderr);
fwrite("-C <proxy IP address>: Client mode\n", 1uLL, 0x23uLL, stderr);
fwrite("-t <TCP port to listen on> (client only)\n", 1uLL, 0x29uLL, stderr);
fwrite("-u <UDP port to use>\n", 1uLL, 0x15uLL, stderr);
exit(1);
}

original_code:
void usage(void) {
    fprintf(stderr, "Usage:\n");
    fprintf(stderr, "-h: Print this message\n");
    fprintf(stderr, "-P: Proxy mode\n");
    fprintf(stderr, "-C <proxy IP address>: Client mode\n");
    fprintf(stderr, "-t <TCP port to listen on> (client only)\n");
    fprintf(stderr, "-u <UDP port to use>\n");
    exit(1);
}

canonical_original_code:
void usage() {
    fprintf(stderr, "Usage:\n");
    fprintf(stderr, "-h: Print this message\n");
    fprintf(stderr, "-P: Proxy mode\n");
    fprintf(stderr, "-C <proxy IP address>: Client mode\n");
    fprintf(stderr, "-t <TCP port to listen on> (client only)\n");
    fprintf(stderr, "-u <UDP port to use>\n");
    exit(1);
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_DWORD *v3; // rbx
int v4; // eax
int v5; // eax

v3 = malloc(0x30uLL);
globalStateInit(v3);
progname = (__int64)*argv;
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "hPp:C:t:u:");
if ( v4 <= 0 )
break;
if ( v4 == 104 )
usage();
if ( v4 > 104 )
{
if ( v4 == 116 )
{
*v3 = atoi(optarg);
}
else
{
if ( v4 != 117 )
goto LABEL_14;
v3[1] = atoi(optarg);
}
}
else if ( v4 == 67 )
{
v3[4] = 0;
strncpy(*((char **)v3 + 3), optarg, 0xFuLL);
}
else
{
if ( v4 != 80 )
{
LABEL_14:
my_err("Unknown option %c\n", (unsigned int)v4);
usage();
}
v3[4] = 1;
}
}
if ( argc - optind > 0 )
{
my_err("Too many options!\n");
usage();
}
v5 = v3[4];
if ( v5 < 0 )
{
my_err("Must specify client or PROXY mode!\n");
usage();
}
if ( v5 )
{
if ( v3[1] )
goto LABEL_21;
LABEL_26:
my_err("Must specify port numbers\n");
usage();
}
if ( !**((_BYTE **)v3 + 3) )
{
my_err("Must specify PROXY address!\n");
usage();
}
if ( !v3[1] || !*v3 )
goto LABEL_26;
LABEL_21:
signal(13, (__sighandler_t)((char *)usage + 1));
initializeNetwork(v3);
infiniteWaitLoop(v3);
globalStateFree(v3);
free(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_DWORD *v3; // rbx
int v4; // eax
int v5; // eax

v3 = malloc(0x30uLL);
globalStateInit(v3);
progname = (__int64)*argv;
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "hPp:C:t:u:");
if ( v4 <= 0 )
break;
if ( v4 == 104 )
func0();
if ( v4 > 104 )
{
if ( v4 == 116 )
{
*v3 = atoi(optarg);
}
else
{
if ( v4 != 117 )
goto LABEL_14;
v3[1] = atoi(optarg);
}
}
else if ( v4 == 67 )
{
v3[4] = 0;
strncpy(*((char **)v3 + 3), optarg, 0xFuLL);
}
else
{
if ( v4 != 80 )
{
LABEL_14:
my_err("Unknown option %c\n", (unsigned int)v4);
func0();
}
v3[4] = 1;
}
}
if ( argc - optind > 0 )
{
my_err("Too many options!\n");
func0();
}
v5 = v3[4];
if ( v5 < 0 )
{
my_err("Must specify client or PROXY mode!\n");
func0();
}
if ( v5 )
{
if ( v3[1] )
goto LABEL_21;
LABEL_26:
my_err("Must specify port numbers\n");
func0();
}
if ( !**((_BYTE **)v3 + 3) )
{
my_err("Must specify PROXY address!\n");
func0();
}
if ( !v3[1] || !*v3 )
goto LABEL_26;
LABEL_21:
signal(13, (__sighandler_t)((char *)usage + 1));
initializeNetwork(v3);
infiniteWaitLoop(v3);
globalStateFree(v3);
free(v3);
return 0;
}

original_code:
int main(int argc, char *argv[]) {
    int option;
    globalstate* globalState = malloc(sizeof(globalstate));
    globalStateInit(globalState);
    progname = argv[0];
    while((option = getopt(argc, argv, "hPp:C:t:u:")) > 0) {
        switch(option) {
            case 'h':
                usage();
                break;
            case 'P':
                globalState->cliproxy = 1;
                break;
            case 'C':
                globalState->cliproxy = 0;
                strncpy(globalState->remote_ip,optarg,15);
                break;
            case 't':
                globalState->tcpListenerPort = atoi(optarg);
                break;
            case 'u':
                globalState->udpPort = atoi(optarg);
                break;
            default:
                my_err("Unknown option %c\n", option);
                usage();
        }
    }
    argv += optind;
    argc -= optind;
    if(argc > 0) {
        my_err("Too many options!\n");
        usage();
    }
    if(globalState->cliproxy < 0) {
        my_err("Must specify client or PROXY mode!\n");
        usage();
    } else if((globalState->cliproxy == 0)&&(globalState->remote_ip[0] == '\0')) {
        my_err("Must specify PROXY address!\n");
        usage();
    } else if(globalState->udpPort == 0 || (globalState->cliproxy == 0 && globalState->tcpListenerPort == 0 )){
        my_err("Must specify port numbers\n");
        usage();
    }
    signal(13, ((__sighandler_t) 1));
    initializeNetwork(globalState);
    infiniteWaitLoop(globalState);
    globalStateFree(globalState);
    free(globalState);
    return(0);
}

canonical_original_code:
int main(int argc, char *argv[]) {
    int option;
    struct globalstate_t *globalState = malloc(sizeof(globalstate));
    globalStateInit(globalState);
    progname = argv[0];
    while((option = getopt(argc, argv, "hPp:C:t:u:")) > 0) {
        switch(option) {
            case 'h':
                usage();
                break;
            case 'P':
                globalState->cliproxy = 1;
                break;
            case 'C':
                globalState->cliproxy = 0;
                strncpy(globalState->remote_ip,optarg,15);
                break;
            case 't':
                globalState->tcpListenerPort = atoi(optarg);
                break;
            case 'u':
                globalState->udpPort = atoi(optarg);
                break;
            default:
                my_err("Unknown option %c\n", option);
                usage();
        }
    }
    argv += optind;
    argc -= optind;
    if(argc > 0) {
        my_err("Too many options!\n");
        usage();
    }
    if(globalState->cliproxy < 0) {
        my_err("Must specify client or PROXY mode!\n");
        usage();
    } else if((globalState->cliproxy == 0)&&(globalState->remote_ip[0] == '\0')) {
        my_err("Must specify PROXY address!\n");
        usage();
    } else if(globalState->udpPort == 0 || (globalState->cliproxy == 0 && globalState->tcpListenerPort == 0 )){
        my_err("Must specify port numbers\n");
        usage();
    }
    signal(13, ((void (*)(int)) 1));
    initializeNetwork(globalState);
    infiniteWaitLoop(globalState);
    globalStateFree(globalState);
    free(globalState);
    return(0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: option int

variable_types: struct globalstate_t { int tcpListenerPort; int udpPort; int tcpListenerSock_fd; int udpSock_fd; int cliproxy; char *remote_ip; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } remote; } *

user_defined_types: struct globalstate_t { int tcpListenerPort; int udpPort; int tcpListenerSock_fd; int udpSock_fd; int cliproxy; char *remote_ip; struct sockaddr_in remote; }


repo: Gregwar/ASCII-Tetris

decompiled_code:
int tetris_cleanup_io()
{
int v0; // eax

v0 = fileno(stdin);
return tcsetattr(v0, 0, &save);
}

canonical_decompiled_code:
int func0()
{
int v0; // eax

v0 = fileno(stdin);
return tcsetattr(v0, 0, &save);
}

original_code:
void
tetris_cleanup_io() {
    tcsetattr(fileno(stdin),0,&save);
}


decompiled_code:
int tetris_signal_quit()
{
return tetris_cleanup_io();
}

canonical_decompiled_code:
int func1()
{
return func0();
}

original_code:
void
tetris_signal_quit(int s) {
    tetris_cleanup_io();
}

variable_types: s int


decompiled_code:
int tetris_set_ioconfig()
{
int v0; // ebx
unsigned int v1; // eax
struct termios v3; // [rsp+0h] [rbp-48h] BYREF

v0 = fileno(stdin);
tcgetattr(v0, &save);
*(__m128i *)&v3.c_iflag = _mm_load_si128((const __m128i *)&save);
*(__m128i *)&v3.c_line = _mm_load_si128((const __m128i *)&save.c_line);
*(__m128i *)&v3.c_cc[15] = _mm_load_si128((const __m128i *)&save.c_cc[15]);
*(_QWORD *)&v3.c_cc[31] = *(_QWORD *)&save.c_cc[31];
v3.c_ospeed = save.c_ospeed;
v3.c_lflag &= 0xFFFFFFF5;
tcsetattr(v0, 0, &v3);
v1 = fcntl(v0, 3, 0LL);
BYTE1(v1) |= 8u;
return fcntl(v0, 4, v1);
}

canonical_decompiled_code:
int func2()
{
int v0; // ebx
unsigned int v1; // eax
struct termios v3; // [rsp+0h] [rbp-48h] BYREF

v0 = fileno(stdin);
tcgetattr(v0, &save);
*(__m128i *)&v3.c_iflag = _mm_load_si128((const __m128i *)&save);
*(__m128i *)&v3.c_line = _mm_load_si128((const __m128i *)&save.c_line);
*(__m128i *)&v3.c_cc[15] = _mm_load_si128((const __m128i *)&save.c_cc[15]);
*(_QWORD *)&v3.c_cc[31] = *(_QWORD *)&save.c_cc[31];
v3.c_ospeed = save.c_ospeed;
v3.c_lflag &= 0xFFFFFFF5;
tcsetattr(v0, 0, &v3);
v1 = fcntl(v0, 3, 0LL);
BYTE1(v1) |= 8u;
return fcntl(v0, 4, v1);
}

original_code:
void
tetris_set_ioconfig() {
    struct termios custom;
    int fd=fileno(stdin);
    tcgetattr(fd, &save);
    custom=save;
    custom.c_lflag &= ~(0000002|0000010);
    tcsetattr(fd,0,&custom);
    fcntl(fd, 4, fcntl(fd, 3, 0)|04000);
}

canonical_original_code:
void tetris_set_ioconfig() {
    struct termios custom;
    int fd = fileno(stdin);
    tcgetattr(fd, &save);
    custom=save;
    custom.c_lflag &= ~(0000002|0000010);
    tcsetattr(fd,0,&custom);
    fcntl(fd, 4, fcntl(fd, 3, 0)|04000);
}

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }

variable_types: fd int


original_code:
void
tetris_clean(struct tetris *t) {
    int x;
    for (x=0; x<t->w; x++) {
        free(t->game[x]);
    }
    free(t->game);
}

variable_types: struct tetris { char **game; int w; int h; int level; int gameover; int score; struct tetris_block { char data[5][5]; int w; int h; } current; int x; int y; } *

variable_types: x int

user_defined_types: struct tetris { char **game; int w; int h; int level; int gameover; int score; struct tetris_block current; int x; int y; }


original_code:
void
tetris_print(struct tetris *t) {
    int x,y;
    for (x=0; x<30; x++)
        printf("\n");
    printf("[LEVEL: %d | SCORE: %d]\n", t->level, t->score);
    for (x=0; x<2*t->w+2; x++)
        printf("~");
    printf("\n");
    for (y=0; y<t->h; y++) {
        printf ("!");
        for (x=0; x<t->w; x++) {
            if (x>=t->x && y>=t->y
                    && x<(t->x+t->current.w) && y<(t->y+t->current.h)
                    && t->current.data[y-t->y][x-t->x]!=' ')
                printf("%c ", t->current.data[y-t->y][x-t->x]);
            else
                printf("%c ", t->game[x][y]);
        }
        printf ("!\n");
    }
    for (x=0; x<2*t->w+2; x++)
        printf("~");
    printf("\n");
}

canonical_original_code:
void tetris_print(struct tetris *t) {
    int x; int y;
    for (x=0; x<30; x++)
        printf("\n");
    printf("[LEVEL: %d | SCORE: %d]\n", t->level, t->score);
    for (x=0; x<2*t->w+2; x++)
        printf("~");
    printf("\n");
    for (y=0; y<t->h; y++) {
        printf ("!");
        for (x=0; x<t->w; x++) {
            if (x>=t->x && y>=t->y
                    && x<(t->x+t->current.w) && y<(t->y+t->current.h)
                    && t->current.data[y-t->y][x-t->x]!=' ')
                printf("%c ", t->current.data[y-t->y][x-t->x]);
            else
                printf("%c ", t->game[x][y]);
        }
        printf ("!\n");
    }
    for (x=0; x<2*t->w+2; x++)
        printf("~");
    printf("\n");
}

variable_types: y int

user_defined_types: struct tetris_block { char data[5][5]; int w; int h; }


original_code:
int
tetris_hittest(struct tetris *t) {
    int x,y,X,Y;
    struct tetris_block b=t->current;
    for (x=0; x<b.w; x++)
        for (y=0; y<b.h; y++) {
            X=t->x+x;
            Y=t->y+y;
            if (X<0 || X>=t->w)
                return 1;
            if (b.data[y][x]!=' ') {
                if ((Y>=t->h) ||
                        (X>=0 && X<t->w && Y>=0 && t->game[X][Y]!=' ')) {
                    return 1;
                }
            }
        }
    return 0;
}

canonical_original_code:
int tetris_hittest(struct tetris *t) {
    int x; int y; int X; int Y;
    struct tetris_block b = t->current;
    for (x=0; x<b.w; x++)
        for (y=0; y<b.h; y++) {
            X=t->x+x;
            Y=t->y+y;
            if (X<0 || X>=t->w)
                return 1;
            if (b.data[y][x]!=' ') {
                if ((Y>=t->h) ||
                        (X>=0 && X<t->w && Y>=0 && t->game[X][Y]!=' ')) {
                    return 1;
                }
            }
        }
    return 0;
}

variable_types: X int

variable_types: Y int

variable_types: struct tetris_block { char data[5][5]; int w; int h; }


decompiled_code:
__int64 __fastcall tetris_new_block(__int64 a1)
{
unsigned __int64 v1; // rax
__int64 result; // rax

v1 = 36 * (random() % 6uLL);
*(__m128i *)(a1 + 28) = _mm_loadu_si128((const __m128i *)((char *)&blocks + v1));
*(__m128i *)(a1 + 44) = _mm_loadu_si128((const __m128i *)((char *)&blocks + v1 + 16));
*(_DWORD *)(a1 + 60) = *(_DWORD *)((char *)&blocks + v1 + 32);
*(_QWORD *)(a1 + 64) = (unsigned int)(*(_DWORD *)(a1 + 8) / 2 - *(_DWORD *)(a1 + 56) / 2);
result = tetris_hittest(a1);
if ( (_DWORD)result )
*(_DWORD *)(a1 + 20) = 1;
return result;
}

original_code:
void
tetris_new_block(struct tetris *t) {
    t->current=blocks[random()%(sizeof(blocks)/sizeof(struct tetris_block))];
    t->x=(t->w/2) - (t->current.w/2);
    t->y=0;
    if (tetris_hittest(t)) {
        t->gameover=1;
    }
}


original_code:
void
tetris_print_block(struct tetris *t) {
    int x,y,X,Y;
    struct tetris_block b=t->current;
    for (x=0; x<b.w; x++)
        for (y=0; y<b.h; y++) {
            if (b.data[y][x]!=' ')
                t->game[t->x+x][t->y+y]=b.data[y][x];
        }
}

canonical_original_code:
void tetris_print_block(struct tetris *t) {
    int x; int y; int X; int Y;
    struct tetris_block b = t->current;
    for (x=0; x<b.w; x++)
        for (y=0; y<b.h; y++) {
            if (b.data[y][x]!=' ')
                t->game[t->x+x][t->y+y]=b.data[y][x];
        }
}


original_code:
void
tetris_rotate(struct tetris *t) {
    struct tetris_block b=t->current;
    struct tetris_block s=b;
    int x,y;
    b.w=s.h;
    b.h=s.w;
    for (x=0; x<s.w; x++)
        for (y=0; y<s.h; y++) {
            b.data[x][y]=s.data[s.h-y-1][x];
        }
    x=t->x;
    y=t->y;
    t->x-=(b.w-s.w)/2;
    t->y-=(b.h-s.h)/2;
    t->current=b;
    if (tetris_hittest(t)) {
        t->current=s;
        t->x=x;
        t->y=y;
    }
}

canonical_original_code:
void tetris_rotate(struct tetris *t) {
    struct tetris_block b = t->current;
    struct tetris_block s = b;
    int x; int y;
    b.w=s.h;
    b.h=s.w;
    for (x=0; x<s.w; x++)
        for (y=0; y<s.h; y++) {
            b.data[x][y]=s.data[s.h-y-1][x];
        }
    x=t->x;
    y=t->y;
    t->x-=(b.w-s.w)/2;
    t->y-=(b.h-s.h)/2;
    t->current=b;
    if (tetris_hittest(t)) {
        t->current=s;
        t->x=x;
        t->y=y;
    }
}


decompiled_code:
__int64 __fastcall tetris_gravity(__int64 a1)
{
int v1; // ebp
__int64 result; // rax

v1 = *(_DWORD *)(a1 + 68);
*(_DWORD *)(a1 + 68) = v1 + 1;
result = tetris_hittest(a1);
if ( (_DWORD)result )
{
*(_DWORD *)(a1 + 68) = v1;
tetris_print_block(a1);
result = tetris_new_block(a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
int v1; // ebp
__int64 result; // rax

v1 = *(_DWORD *)(a1 + 68);
*(_DWORD *)(a1 + 68) = v1 + 1;
result = func6(a1);
if ( (_DWORD)result )
{
*(_DWORD *)(a1 + 68) = v1;
func8(a1);
result = func7(a1);
}
return result;
}

original_code:
void
tetris_gravity(struct tetris *t) {
    int x,y;
    t->y++;
    if (tetris_hittest(t)) {
        t->y--;
        tetris_print_block(t);
        tetris_new_block(t);
    }
}

canonical_original_code:
void tetris_gravity(struct tetris *t) {
    int x; int y;
    t->y++;
    if (tetris_hittest(t)) {
        t->y--;
        tetris_print_block(t);
        tetris_new_block(t);
    }
}


decompiled_code:
__int64 __fastcall tetris_fall(__int64 a1, int a2)
{
__int64 result; // rax
__int64 v3; // r8
__int64 v4; // rsi
__int64 v5; // r9

result = (unsigned int)a2;
if ( a2 > 0 )
{
v3 = a2;
v4 = a2 - 1LL;
v5 = v3 - 2 - (unsigned int)(result - 1);
do
{
for ( result = 0LL; *(_DWORD *)(a1 + 8) > (int)result; ++result )
*(_BYTE *)(*(_QWORD *)(*(_QWORD *)a1 + 8 * result) + v3) = *(_BYTE *)(*(_QWORD *)(*(_QWORD *)a1 + 8 * result)
+ v4);
--v4;
--v3;
}
while ( v4 != v5 );
}
if ( *(int *)(a1 + 8) > 0 )
{
result = 0LL;
do
**(_BYTE **)(*(_QWORD *)a1 + 8 * result++) = 32;
while ( *(_DWORD *)(a1 + 8) > (int)result );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, int a2)
{
__int64 result; // rax
__int64 v3; // r8
__int64 v4; // rsi
__int64 v5; // r9

result = (unsigned int)a2;
if ( a2 > 0 )
{
v3 = a2;
v4 = a2 - 1LL;
v5 = v3 - 2 - (unsigned int)(result - 1);
do
{
for ( result = 0LL; *(_DWORD *)(a1 + 8) > (int)result; ++result )
*(_BYTE *)(*(_QWORD *)(*(_QWORD *)a1 + 8 * result) + v3) = *(_BYTE *)(*(_QWORD *)(*(_QWORD *)a1 + 8 * result)
+ v4);
--v4;
--v3;
}
while ( v4 != v5 );
}
if ( *(int *)(a1 + 8) > 0 )
{
result = 0LL;
do
**(_BYTE **)(*(_QWORD *)a1 + 8 * result++) = 32;
while ( *(_DWORD *)(a1 + 8) > (int)result );
}
return result;
}

original_code:
void
tetris_fall(struct tetris *t, int l) {
    int x,y;
    for (y=l; y>0; y--) {
        for (x=0; x<t->w; x++)
            t->game[x][y]=t->game[x][y-1];
    }
    for (x=0; x<t->w; x++)
        t->game[x][0]=' ';
}

canonical_original_code:
void tetris_fall(struct tetris *t, int l) {
    int x; int y;
    for (y=l; y>0; y--) {
        for (x=0; x<t->w; x++)
            t->game[x][y]=t->game[x][y-1];
    }
    for (x=0; x<t->w; x++)
        t->game[x][0]=' ';
}

variable_types: l int


original_code:
void
tetris_check_lines(struct tetris *t) {
    int x,y,l;
    int p=100;
    for (y=t->h-1; y>=0; y--) {
        l=1;
        for (x=0; x<t->w && l; x++) {
            if (t->game[x][y]==' ') {
                l=0;
            }
        }
        if (l) {
            t->score += p;
            p*=2;
            tetris_fall(t, y);
            y++;
        }
    }
}

canonical_original_code:
void tetris_check_lines(struct tetris *t) {
    int x; int y; int l;
    int p = 100;
    for (y=t->h-1; y>=0; y--) {
        l=1;
        for (x=0; x<t->w && l; x++) {
            if (t->game[x][y]==' ') {
                l=0;
            }
        }
        if (l) {
            t->score += p;
            p*=2;
            tetris_fall(t, y);
            y++;
        }
    }
}

variable_types: p int


decompiled_code:
__int64 __fastcall tetris_level(__int64 a1)
{
int v1; // edx
__int64 i; // rax

v1 = *(_DWORD *)(a1 + 24);
for ( i = 1LL; i != 8; ++i )
{
if ( v1 < levels[2 * i - 2] )
break;
*(_DWORD *)(a1 + 16) = i;
}
return (unsigned int)levels[2 * *(_DWORD *)(a1 + 16) - 1];
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
int v1; // edx
__int64 i; // rax

v1 = *(_DWORD *)(a1 + 24);
for ( i = 1LL; i != 8; ++i )
{
if ( v1 < levels[2 * i - 2] )
break;
*(_DWORD *)(a1 + 16) = i;
}
return (unsigned int)levels[2 * *(_DWORD *)(a1 + 16) - 1];
}

original_code:
int
tetris_level(struct tetris *t) {
    int i;
    for (i=0; i<(sizeof(levels)/sizeof(struct tetris_level)); i++) {
        if (t->score>=levels[i].score) {
            t->level = i+1;
        } else break;
    }
    return levels[t->level-1].nsec;
}

variable_types: i int

user_defined_types: struct tetris_level { int score; int nsec; }


decompiled_code:
int __fastcall tetris_run(int a1, int a2)
{
unsigned int v2; // eax
int v3; // ebp
char v4; // al
int v5; // ebx
int v6; // ebx
_BYTE v8[20]; // [rsp+0h] [rbp-78h] BYREF
int v9; // [rsp+14h] [rbp-64h]
int v10; // [rsp+40h] [rbp-38h]
struct timespec requested_time; // [rsp+50h] [rbp-28h] BYREF

tetris_set_ioconfig();
tetris_init((__int64)v8, a1, a2);
v2 = time(0LL);
srand(v2);
requested_time.tv_sec = 0LL;
requested_time.tv_nsec = 1000000LL;
tetris_new_block((__int64)v8);
if ( !v9 )
{
nanosleep(&requested_time, 0LL);
v3 = 1;
while ( 1 )
{
if ( v3 == 350 * (v3 / 350) )
{
tetris_gravity((__int64)v8);
tetris_check_lines((__int64)v8);
}
while ( 1 )
{
v4 = getchar();
if ( v4 <= 0 )
break;
if ( v4 == 113 )
{
v6 = v10--;
if ( (unsigned int)tetris_hittest((__int64)v8) )
v10 = v6;
}
else if ( v4 > 113 )
{
if ( v4 == 115 )
tetris_gravity((__int64)v8);
}
else if ( v4 == 32 )
{
tetris_rotate((__int64)v8);
}
else if ( v4 == 100 )
{
v5 = v10++;
if ( (unsigned int)tetris_hittest((__int64)v8) )
v10 = v5;
}
}
requested_time.tv_nsec = (int)tetris_level((__int64)v8);
if ( v9 )
break;
nanosleep(&requested_time, 0LL);
++v3;
if ( v3 == 50 * (v3 / 50) )
tetris_print((__int64)v8);
}
}
tetris_print((__int64)v8);
puts("*** GAME OVER ***");
tetris_clean((__int64)v8);
return tetris_cleanup_io();
}

canonical_decompiled_code:
int __fastcall func14(int a1, int a2)
{
unsigned int v2; // eax
int v3; // ebp
char v4; // al
int v5; // ebx
int v6; // ebx
_BYTE v8[20]; // [rsp+0h] [rbp-78h] BYREF
int v9; // [rsp+14h] [rbp-64h]
int v10; // [rsp+40h] [rbp-38h]
struct timespec requested_time; // [rsp+50h] [rbp-28h] BYREF

func2();
func3((__int64)v8, a1, a2);
v2 = time(0LL);
srand(v2);
requested_time.tv_sec = 0LL;
requested_time.tv_nsec = 1000000LL;
func7((__int64)v8);
if ( !v9 )
{
nanosleep(&requested_time, 0LL);
v3 = 1;
while ( 1 )
{
if ( v3 == 350 * (v3 / 350) )
{
func10((__int64)v8);
func12((__int64)v8);
}
while ( 1 )
{
v4 = getchar();
if ( v4 <= 0 )
break;
if ( v4 == 113 )
{
v6 = v10--;
if ( (unsigned int)func6((__int64)v8) )
v10 = v6;
}
else if ( v4 > 113 )
{
if ( v4 == 115 )
func10((__int64)v8);
}
else if ( v4 == 32 )
{
func9((__int64)v8);
}
else if ( v4 == 100 )
{
v5 = v10++;
if ( (unsigned int)func6((__int64)v8) )
v10 = v5;
}
}
requested_time.tv_nsec = (int)func13((__int64)v8);
if ( v9 )
break;
nanosleep(&requested_time, 0LL);
++v3;
if ( v3 == 50 * (v3 / 50) )
func5((__int64)v8);
}
}
func5((__int64)v8);
puts("*** GAME OVER ***");
func4((__int64)v8);
return func0();
}

original_code:
void
tetris_run(int w, int h) {
    struct timespec tm;
    struct tetris t;
    char cmd;
    int count=0;
    tetris_set_ioconfig();
    tetris_init(&t, w, h);
    srand(time(((void *)0)));
    tm.tv_sec=0;
    tm.tv_nsec=1000000;
    tetris_new_block(&t);
    while (!t.gameover) {
        nanosleep(&tm, ((void *)0));
        count++;
        if (count%50 == 0) {
            tetris_print(&t);
        }
        if (count%350 == 0) {
            tetris_gravity(&t);
            tetris_check_lines(&t);
        }
        while ((cmd=getchar())>0) {
            switch (cmd) {
                case 'q':
                    t.x--;
                    if (tetris_hittest(&t))
                        t.x++;
                    break;
                case 'd':
                    t.x++;
                    if (tetris_hittest(&t))
                        t.x--;
                    break;
                case 's':
                    tetris_gravity(&t);
                    break;
                case ' ':
                    tetris_rotate(&t);
                    break;
            }
        }
        tm.tv_nsec=tetris_level(&t);
    }
    tetris_print(&t);
    printf("*** GAME OVER ***\n");
    tetris_clean(&t);
    tetris_cleanup_io();
}

canonical_original_code:
void tetris_run(int w, int h) {
    struct timespec tm;
    struct tetris t;
    char cmd;
    int count = 0;
    tetris_set_ioconfig();
    tetris_init(&t, w, h);
    srand(time(((void *)0)));
    tm.tv_sec=0;
    tm.tv_nsec=1000000;
    tetris_new_block(&t);
    while (!t.gameover) {
        nanosleep(&tm, ((void *)0));
        count++;
        if (count%50 == 0) {
            tetris_print(&t);
        }
        if (count%350 == 0) {
            tetris_gravity(&t);
            tetris_check_lines(&t);
        }
        while ((cmd=getchar())>0) {
            switch (cmd) {
                case 'q':
                    t.x--;
                    if (tetris_hittest(&t))
                        t.x++;
                    break;
                case 'd':
                    t.x++;
                    if (tetris_hittest(&t))
                        t.x--;
                    break;
                case 's':
                    tetris_gravity(&t);
                    break;
                case ' ':
                    tetris_rotate(&t);
                    break;
            }
        }
        tm.tv_nsec=tetris_level(&t);
    }
    tetris_print(&t);
    printf("*** GAME OVER ***\n");
    tetris_clean(&t);
    tetris_cleanup_io();
}

variable_types: w int

variable_types: h int

variable_types: struct timespec { long tv_sec; long tv_nsec; }

variable_types: struct tetris { char **game; int w; int h; int level; int gameover; int score; struct tetris_block { char data[5][5]; int w; int h; } current; int x; int y; }

variable_types: cmd char

variable_types: count int


repo: Groundworkstech/dynamips-gdb-mod

decompiled_code:
__int64 __fastcall check_bit(int a1, int a2, char a3)
{
int v3; // eax
__int64 result; // rax

v3 = 1 << a3;
if ( (a1 & (1 << a3)) != 0 )
result = (a2 & v3) == 0;
else
result = 2 * (unsigned int)((a2 & v3) != 0);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2, char a3)
{
int v3; // eax
__int64 result; // rax

v3 = 1 << a3;
if ( (a1 & (1 << a3)) != 0 )
result = (a2 & v3) == 0;
else
result = 2 * (unsigned int)((a2 & v3) != 0);
return result;
}

original_code:
static inline int check_bit(u_int old,u_int new,u_int bit)
{
   int mask = 1 << bit;
   if ((old & mask) && !(new & mask))
      return(1);
   if (!(old & mask) && (new & mask))
      return(2);
   return(0);
}

canonical_original_code:
static inline int check_bit(unsigned int old, unsigned int new, unsigned int bit)
{
   int mask = 1 << bit;
   if ((old & mask) && !(new & mask))
      return(1);
   if (!(old & mask) && (new & mask))
      return(2);
   return(0);
}

variable_types:
old
unsigned int

variable_types:
new
unsigned int

variable_types:
bit
unsigned int

variable_types: mask int


original_code:
static void nmc93cX6_check_cs(struct nmc93cX6_group *g,u_int old,u_int new)
{
   int i,res;
   for(i=0;i<g->nr_eeprom;i++)
   {
      if (g->dout_status == EEPROM_DOUT_HIGH)
         g->state[i].dataout_val = 1;
      if (g->debug)
      {
         printf("EEPROM %s(%d): check_cs:  check_bit(old,new,select_bit) "
                "[%8.8x, %8.8x, %d (mask = %8.8x)] = %d\n",
                g->description, i,
                old, new, g->def[i]->select_bit, 1 << g->def[i]->select_bit,
                check_bit(old,new,g->def[i]->select_bit));
      }
      if ((res = check_bit(old,new,g->def[i]->select_bit)) != 0) {
         g->state[i].cmd_len = 0;
         g->state[i].cmd_val = 0;
         if (res == 2)
            g->state[i].state = EEPROM_STATE_WAIT_CMD;
         else
            g->state[i].state = EEPROM_STATE_INACTIVE;
      }
   }
}

canonical_original_code:
static void nmc93cX6_check_cs(struct nmc93cX6_group *g, unsigned int old, unsigned int new)
{
   int i; int res;
   for(i=0;i<g->nr_eeprom;i++)
   {
      if (g->dout_status == EEPROM_DOUT_HIGH)
         g->state[i].dataout_val = 1;
      if (g->debug)
      {
         printf("EEPROM %s(%d): check_cs:  check_bit(old,new,select_bit) "
                "[%8.8x, %8.8x, %d (mask = %8.8x)] = %d\n",
                g->description, i,
                old, new, g->def[i]->select_bit, 1 << g->def[i]->select_bit,
                check_bit(old,new,g->def[i]->select_bit));
      }
      if ((res = check_bit(old,new,g->def[i]->select_bit)) != 0) {
         g->state[i].cmd_len = 0;
         g->state[i].cmd_val = 0;
         if (res == 2)
            g->state[i].state = EEPROM_STATE_WAIT_CMD;
         else
            g->state[i].state = EEPROM_STATE_INACTIVE;
      }
   }
}

variable_types: struct nmc93cX6_group { unsigned int eeprom_type; unsigned int nr_eeprom; unsigned int eeprom_reg; unsigned int reverse_data; unsigned int dout_status; int debug; char *description; struct nmc93cX6_eeprom_def { unsigned int clock_bit; unsigned int select_bit; unsigned int din_bit; unsigned int dout_bit; } *def[16]; struct nmc93cX6_eeprom_state { unsigned int cmd_len; unsigned int cmd_val; unsigned int state; unsigned int dataout_pos; unsigned int dataout_val; } state[16]; struct cisco_eeprom { char *name; unsigned short *data; unsigned long len; } *eeprom[16]; } *

variable_types: res int

user_defined_types: struct nmc93cX6_group { unsigned int eeprom_type; unsigned int nr_eeprom; unsigned int eeprom_reg; unsigned int reverse_data; unsigned int dout_status; int debug; char *description; struct nmc93cX6_eeprom_def *def[16]; struct nmc93cX6_eeprom_state state[16]; struct cisco_eeprom *eeprom[16]; }


decompiled_code:
__int64 __fastcall nmc93cX6_check_clk_group(__int64 a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
unsigned int *v8; // rax
unsigned int v9; // er14
unsigned int v10; // er15
__int64 result; // rax
__int64 v12; // rax
int v13; // er12
unsigned int v14; // eax
int v15; // ecx
int v16; // esi
__int64 v17; // rdx
__int64 v18; // rdi

v8 = *(unsigned int **)(a1 + 8LL * (int)a2 + 32);
v9 = *v8;
v10 = v8[2];
if ( *(_DWORD *)(a1 + 20) )
{
v12 = check_bit(a3, a4, v9);
printf(
"EEPROM %s(%d): check_clk: check_bit(old,new,select_bit) [%8.8x, %8.8x, %d (mask = %8.8x)] = %d\n",
*(const char **)(a1 + 24),
a2,
a3,
a4,
v9,
(unsigned int)(1 << v9),
v12);
}
result = check_bit(a3, a4, v9);
if ( (_DWORD)result == 2 )
{
result = *(unsigned int *)(a1 + 20LL * (int)a2 + 168);
if ( (_DWORD)result != 1 )
{
if ( (_DWORD)result == 2 )
{
v14 = nmc94cX6_get_addr((_DWORD *)a1, *(_DWORD *)(a1 + 20LL * (int)a2 + 164));
v15 = *(_DWORD *)(a1 + 20LL * (int)a2 + 172);
v16 = v15 + 1;
*(_DWORD *)(a1 + 20LL * (int)a2 + 172) = v15 + 1;
if ( *(_DWORD *)(a1 + 12) )
LOBYTE(v15) = 15 - v15;
v17 = *(_QWORD *)(a1 + 8LL * (int)a2 + 480);
if ( v17 && (v18 = *(_QWORD *)(v17 + 8)) != 0 && (unsigned __int64)v14 < *(_QWORD *)(v17 + 16) )
result = (1 << v15) & (unsigned int)*(unsigned __int16 *)(v18 + 2LL * v14);
else
result = (unsigned int)(1 << v15);
*(_DWORD *)(a1 + 20LL * (int)a2 + 176) = result;
if ( v16 == 16 )
{
*(_DWORD *)(a1 + 20LL * (int)a2 + 168) = 0;
*(_DWORD *)(a1 + 20LL * (int)a2 + 172) = 0;
}
}
return result;
}
result = *(unsigned int *)(a1 + 20LL * (int)a2 + 160);
if ( (_DWORD)result )
{
if ( (a4 & (1 << v10)) == 0 )
goto LABEL_11;
}
else if ( (a4 & (1 << v10)) == 0 )
{
return result;
}
*(_DWORD *)(a1 + 20LL * (int)a2 + 164) |= 1 << result;
LABEL_11:
v13 = result + 1;
*(_DWORD *)(a1 + 20LL * (int)a2 + 160) = result + 1;
result = nmc94cX6_get_cmd_len((_DWORD *)a1);
if ( v13 == (_DWORD)result )
{
*(_DWORD *)(a1 + 20LL * (int)a2 + 160) = 0;
result = *(_DWORD *)(a1 + 20LL * (int)a2 + 164) & 7;
if ( (_DWORD)result == 3 )
{
*(_DWORD *)(a1 + 20LL * (int)a2 + 168) = 2;
*(_DWORD *)(a1 + 20LL * (int)a2 + 172) = 0;
}
}
}
return result;
}

original_code:
static void nmc93cX6_check_clk_group(struct nmc93cX6_group *g,int group_id,
                                     u_int old,u_int new)
{
   struct cisco_eeprom *eeprom;
   u_int cmd,op,addr,pos;
   u_int clk_bit, din_bit;
   u_int cmd_len;
   clk_bit = g->def[group_id]->clock_bit;
   din_bit = g->def[group_id]->din_bit;
   if (g->debug)
   {
      printf("EEPROM %s(%d): check_clk: check_bit(old,new,select_bit) "
             "[%8.8x, %8.8x, %d (mask = %8.8x)] = %d\n",
             g->description, group_id,
             old, new, clk_bit, 1 << clk_bit, check_bit(old,new,clk_bit));
   }
   if (check_bit(old,new,clk_bit) != 2)
      return;
   switch(g->state[group_id].state)
   {
      case EEPROM_STATE_WAIT_CMD:
         if ((g->state[group_id].cmd_len == 0) && !(new & (1 << din_bit)))
            break;
         if (new & (1 << din_bit))
            g->state[group_id].cmd_val |= (1 << g->state[group_id].cmd_len);
         g->state[group_id].cmd_len++;
         cmd_len = nmc94cX6_get_cmd_len(g);
         if (g->state[group_id].cmd_len == cmd_len)
         {
            g->state[group_id].cmd_len = 0;
            cmd = g->state[group_id].cmd_val;
            op = cmd & 0x7;
            switch(op) {
               case (0x1 | 0x2):
                  g->state[group_id].state = EEPROM_STATE_DATAOUT;
                  g->state[group_id].dataout_pos = 0;
                  break;
            }
         }
         break;
      case EEPROM_STATE_DATAOUT:
         cmd = g->state[group_id].cmd_val;
         addr = nmc94cX6_get_addr(g,cmd);
         pos = g->state[group_id].dataout_pos++;
         if (g->reverse_data)
            pos = 15 - pos;
         eeprom = g->eeprom[group_id];
         if (eeprom && eeprom->data && (addr < eeprom->len)) {
            g->state[group_id].dataout_val = eeprom->data[addr] & (1 << pos);
         } else {
            g->state[group_id].dataout_val = (1 << pos);
         }
         if (g->state[group_id].dataout_pos == 16) {
            g->state[group_id].state = EEPROM_STATE_INACTIVE;
            g->state[group_id].dataout_pos = 0;
         }
         break;
   }
}

canonical_original_code:
static void nmc93cX6_check_clk_group(struct nmc93cX6_group *g, int group_id, unsigned int old, unsigned int new)
{
   struct cisco_eeprom *eeprom;
   unsigned int cmd; unsigned int op; unsigned int addr; unsigned int pos;
   unsigned int clk_bit; unsigned int din_bit;
   unsigned int cmd_len;
   clk_bit = g->def[group_id]->clock_bit;
   din_bit = g->def[group_id]->din_bit;
   if (g->debug)
   {
      printf("EEPROM %s(%d): check_clk: check_bit(old,new,select_bit) "
             "[%8.8x, %8.8x, %d (mask = %8.8x)] = %d\n",
             g->description, group_id,
             old, new, clk_bit, 1 << clk_bit, check_bit(old,new,clk_bit));
   }
   if (check_bit(old,new,clk_bit) != 2)
      return;
   switch(g->state[group_id].state)
   {
      case EEPROM_STATE_WAIT_CMD:
         if ((g->state[group_id].cmd_len == 0) && !(new & (1 << din_bit)))
            break;
         if (new & (1 << din_bit))
            g->state[group_id].cmd_val |= (1 << g->state[group_id].cmd_len);
         g->state[group_id].cmd_len++;
         cmd_len = nmc94cX6_get_cmd_len(g);
         if (g->state[group_id].cmd_len == cmd_len)
         {
            g->state[group_id].cmd_len = 0;
            cmd = g->state[group_id].cmd_val;
            op = cmd & 0x7;
            switch(op) {
               case (0x1 | 0x2):
                  g->state[group_id].state = EEPROM_STATE_DATAOUT;
                  g->state[group_id].dataout_pos = 0;
                  break;
            }
         }
         break;
      case EEPROM_STATE_DATAOUT:
         cmd = g->state[group_id].cmd_val;
         addr = nmc94cX6_get_addr(g,cmd);
         pos = g->state[group_id].dataout_pos++;
         if (g->reverse_data)
            pos = 15 - pos;
         eeprom = g->eeprom[group_id];
         if (eeprom && eeprom->data && (addr < eeprom->len)) {
            g->state[group_id].dataout_val = eeprom->data[addr] & (1 << pos);
         } else {
            g->state[group_id].dataout_val = (1 << pos);
         }
         if (g->state[group_id].dataout_pos == 16) {
            g->state[group_id].state = EEPROM_STATE_INACTIVE;
            g->state[group_id].dataout_pos = 0;
         }
         break;
   }
}

variable_types: struct cisco_eeprom { char *name; unsigned short *data; unsigned long len; } *

variable_types:
cmd
unsigned int

variable_types:
op
unsigned int

variable_types:
addr
unsigned int

variable_types:
pos
unsigned int

user_defined_types: struct nmc93cX6_eeprom_state { unsigned int cmd_len; unsigned int cmd_val; unsigned int state; unsigned int dataout_pos; unsigned int dataout_val; }

user_defined_types: struct nmc93cX6_eeprom_def { unsigned int clock_bit; unsigned int select_bit; unsigned int din_bit; unsigned int dout_bit; }


decompiled_code:
__int64 __fastcall nmc93cX6_check_clk(__int64 a1, unsigned int a2, unsigned int a3)
{
unsigned int v4; // ebx
__int64 result; // rax

if ( *(_DWORD *)(a1 + 4) )
{
v4 = 0;
do
result = nmc93cX6_check_clk_group(a1, v4++, a2, a3);
while ( *(_DWORD *)(a1 + 4) > v4 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned int a2, unsigned int a3)
{
unsigned int v4; // ebx
__int64 result; // rax

if ( *(_DWORD *)(a1 + 4) )
{
v4 = 0;
do
result = func4(a1, v4++, a2, a3);
while ( *(_DWORD *)(a1 + 4) > v4 );
}
return result;
}

original_code:
void nmc93cX6_check_clk(struct nmc93cX6_group *g,u_int old,u_int new)
{
   int i;
   for(i=0;i<g->nr_eeprom;i++)
      nmc93cX6_check_clk_group(g,i,old,new);
}

canonical_original_code:
void nmc93cX6_check_clk(struct nmc93cX6_group *g, unsigned int old, unsigned int new)
{
   int i;
   for(i=0;i<g->nr_eeprom;i++)
      nmc93cX6_check_clk_group(g,i,old,new);
}

variable_types: i int

user_defined_types: struct cisco_eeprom { char *name; unsigned short *data; unsigned long len; }


decompiled_code:
__int64 __fastcall nmc93cX6_write(__int64 a1, unsigned int a2)
{
unsigned int v2; // er12
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 8);
nmc93cX6_check_cs(a1, v2, a2);
result = nmc93cX6_check_clk(a1, v2, a2);
*(_DWORD *)(a1 + 8) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned int a2)
{
unsigned int v2; // er12
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 8);
func2(a1, v2, a2);
result = func5(a1, v2, a2);
*(_DWORD *)(a1 + 8) = a2;
return result;
}

original_code:
void nmc93cX6_write(struct nmc93cX6_group *g,u_int data)
{
   u_int new = data, old = g->eeprom_reg;
   nmc93cX6_check_cs(g,old,new);
   nmc93cX6_check_clk(g,old,new);
   g->eeprom_reg = new;
}

canonical_original_code:
void nmc93cX6_write(struct nmc93cX6_group *g, unsigned int data)
{
   unsigned int new = data; unsigned int old = g->eeprom_reg;
   nmc93cX6_check_cs(g,old,new);
   nmc93cX6_check_clk(g,old,new);
   g->eeprom_reg = new;
}

variable_types:
data
unsigned int


decompiled_code:
__int64 __fastcall nmc93cX6_is_active(__int64 a1, unsigned int a2)
{
return *(_DWORD *)(a1 + 8) & (unsigned int)(1 << *(_DWORD *)(*(_QWORD *)(a1 + 8LL * a2 + 32) + 4LL));
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, unsigned int a2)
{
return *(_DWORD *)(a1 + 8) & (unsigned int)(1 << *(_DWORD *)(*(_QWORD *)(a1 + 8LL * a2 + 32) + 4LL));
}

original_code:
u_int nmc93cX6_is_active(struct nmc93cX6_group *g,u_int group_id)
{
   return(g->eeprom_reg & (1 << g->def[group_id]->select_bit));
}

canonical_original_code:
unsigned int nmc93cX6_is_active(struct nmc93cX6_group *g, unsigned int group_id)
{
   return(g->eeprom_reg & (1 << g->def[group_id]->select_bit));
}

return_type: unsigned int


decompiled_code:
__int64 __fastcall nmc93cX6_get_dout(__int64 a1, unsigned int a2)
{
__int64 result; // rax

result = *(unsigned int *)(a1 + 20LL * a2 + 176);
if ( (_DWORD)result )
result = (unsigned int)(1 << *(_DWORD *)(*(_QWORD *)(a1 + 8LL * a2 + 32) + 12LL));
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, unsigned int a2)
{
__int64 result; // rax

result = *(unsigned int *)(a1 + 20LL * a2 + 176);
if ( (_DWORD)result )
result = (unsigned int)(1 << *(_DWORD *)(*(_QWORD *)(a1 + 8LL * a2 + 32) + 12LL));
return result;
}

original_code:
u_int nmc93cX6_get_dout(struct nmc93cX6_group *g,u_int group_id)
{
   if (g->state[group_id].dataout_val)
      return(1 << g->def[group_id]->dout_bit);
   else
      return(0);
}

canonical_original_code:
unsigned int nmc93cX6_get_dout(struct nmc93cX6_group *g, unsigned int group_id)
{
   if (g->state[group_id].dataout_val)
      return(1 << g->def[group_id]->dout_bit);
   else
      return(0);
}


original_code:
u_int nmc93cX6_read(struct nmc93cX6_group *g)
{
   u_int res;
   int i;
   res = g->eeprom_reg;
   for(i=0;i<g->nr_eeprom;i++) {
      if (!(g->eeprom_reg & (1 << g->def[i]->select_bit)))
         continue;
      if (g->state[i].dataout_val)
         res |= 1 << g->def[i]->dout_bit;
      else
         res &= ~(1 << g->def[i]->dout_bit);
   }
   return(res);
}

canonical_original_code:
unsigned int nmc93cX6_read(struct nmc93cX6_group *g)
{
   unsigned int res;
   int i;
   res = g->eeprom_reg;
   for(i=0;i<g->nr_eeprom;i++) {
      if (!(g->eeprom_reg & (1 << g->def[i]->select_bit)))
         continue;
      if (g->state[i].dataout_val)
         res |= 1 << g->def[i]->dout_bit;
      else
         res &= ~(1 << g->def[i]->dout_bit);
   }
   return(res);
}

variable_types:
res
unsigned int


decompiled_code:
void __fastcall so_delete(void *ptr)
{
if ( ptr )
{
free(*(void **)ptr);
free(*((void **)ptr + 1));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
if ( ptr )
{
free(*(void **)ptr);
free(*((void **)ptr + 1));
free(ptr);
}
}

original_code:
static void so_delete(struct store_object *so)
{
   if (so != ((void *)0)) {
      free(so->name);
      free(so->data);
      free(so);
   }
}

variable_types: struct store_object { char *name; void *data; unsigned long len; } *


decompiled_code:
__int64 __fastcall so_reg_delete(void *a1)
{
so_delete(a1);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(void *a1)
{
func3(a1);
return 1LL;
}

original_code:
static int so_reg_delete(void *data,void *arg)
{
   so_delete((struct store_object *)data);
   return(1);
}

canonical_original_code:
static int so_reg_delete(void *data, void *arg)
{
   so_delete((struct store_object *)data);
   return(1);
}

variable_types:
data
void *

variable_types:
arg
void *

user_defined_types: struct store_object { char *name; void *data; unsigned long len; }


decompiled_code:
__int64 __fastcall so_delete_from_registry(__int64 a1)
{
return registry_delete_if_unused(a1, 7LL, so_reg_delete, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return registry_delete_if_unused(a1, 7LL, so_reg_delete, 0LL);
}

original_code:
static int so_delete_from_registry(char *name)
{
   return(registry_delete_if_unused(name,OBJ_TYPE_STORE,so_reg_delete,((void *)0)));
}

variable_types:
name
char *


decompiled_code:
void **__fastcall so_create(char *s, void *a2, void *a3)
{
void **v4; // rbx
char *v5; // rdi

v4 = (void **)malloc(0x18uLL);
if ( v4 )
{
v5 = strdup(s);
*v4 = v5;
if ( v5 )
{
v4[1] = a2;
v4[2] = a3;
if ( (unsigned int)registry_add(v5, 7LL, v4) != -1 )
return v4;
free(*v4);
}
free(v4);
v4 = 0LL;
}
return v4;
}

canonical_decompiled_code:
void **__fastcall func8(char *s, void *a2, void *a3)
{
void **v4; // rbx
char *v5; // rdi

v4 = (void **)malloc(0x18uLL);
if ( v4 )
{
v5 = strdup(s);
*v4 = v5;
if ( v5 )
{
v4[1] = a2;
v4[2] = a3;
if ( (unsigned int)registry_add(v5, 7LL, v4) != -1 )
return v4;
free(*v4);
}
free(v4);
v4 = 0LL;
}
return v4;
}

original_code:
static struct store_object *so_create(char *name,void *data,size_t len)
{
   struct store_object *so;
   if (!(so = malloc(sizeof(*so))))
      return ((void *)0);
   if (!(so->name = strdup(name)))
      goto err_name;
   so->data = data;
   so->len = len;
   if (registry_add(so->name,OBJ_TYPE_STORE,so) == -1)
      goto err_registry;
   return so;
 err_registry:
   free(so->name);
 err_name:
   free(so);
   return ((void *)0);
}

canonical_original_code:
static struct store_object *so_create(char *name, void *data, unsigned long len)
{
   struct store_object *so;
   if (!(so = malloc(sizeof(*so))))
      return ((void *)0);
   if (!(so->name = strdup(name)))
      goto err_name;
   so->data = data;
   so->len = len;
   if (registry_add(so->name,OBJ_TYPE_STORE,so) == -1)
      goto err_registry;
   return so;
 err_registry:
   free(so->name);
 err_name:
   free(so);
   return ((void *)0);
}

variable_types:
len
unsigned long

return_type: struct store_object { char *name; void *data; unsigned long len; } *


gethexnum

original_code:
boolean gethexnum (char *srcstr, char **retstr, int *retvalue)
{
  char *str = srcstr;
  unsigned long value = 0;
  while (*str && (((*str >= 'a') && (*str <= 'f')) ||
    ((*str >= '0') && (*str <= '9'))))
    {
      value =
 value * 16 + (*str <= '9' ? (*str++ - '0') : (*str++ - 'a' + 10));
    }
  if (str == srcstr)
    {
      return (0);
    }
  *retvalue = value;
  *retstr = str;
  return (1);
}

canonical_original_code:
unsigned char gethexnum(char *srcstr, char **retstr, int *retvalue)
{
  char *str = srcstr;
  unsigned long value = 0;
  while (*str && (((*str >= 'a') && (*str <= 'f')) ||
    ((*str >= '0') && (*str <= '9'))))
    {
      value =
 value * 16 + (*str <= '9' ? (*str++ - '0') : (*str++ - 'a' + 10));
    }
  if (str == srcstr)
    {
      return (0);
    }
  *retvalue = value;
  *retstr = str;
  return (1);
}

variable_types:
srcstr
char *

variable_types:
retstr
char **

variable_types:
retvalue
int *

variable_types:
str
char *

variable_types:
value
unsigned long


parsehexnum

decompiled_code:
__int64 __fastcall parsehexnum(char *a1, _DWORD *a2)
{
char *v3; // [rsp+8h] [rbp-8h] BYREF

return gethexnum(a1, &v3, a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1, _DWORD *a2)
{
char *v3; // [rsp+8h] [rbp-8h] BYREF

return func0(a1, &v3, a2);
}

original_code:
boolean parsehexnum (char *srcstr, int *retvalue)
{
  char *dummy;
  return (gethexnum (srcstr, &dummy, retvalue));
}

canonical_original_code:
unsigned char parsehexnum(char *srcstr, int *retvalue)
{
  char *dummy;
  return (gethexnum (srcstr, &dummy, retvalue));
}

variable_types:
dummy
char *


decompiled_code:
__int64 __fastcall parse2hexnum(char *a1, _DWORD *a2, _DWORD *a3)
{
__int64 result; // rax
char *v5; // rdx
char *v6; // rdi
int v7; // [rsp+0h] [rbp-20h] BYREF
int v8; // [rsp+4h] [rbp-1Ch] BYREF
char *v9[3]; // [rsp+8h] [rbp-18h] BYREF

result = gethexnum(a1, v9, &v8);
if ( (_BYTE)result )
{
v5 = v9[0];
v6 = ++v9[0];
result = 0LL;
if ( *v5 == 44 )
{
result = gethexnum(v6, v9, &v7);
if ( (_BYTE)result )
{
*a2 = v8;
*a3 = v7;
result = 1LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1, _DWORD *a2, _DWORD *a3)
{
__int64 result; // rax
char *v5; // rdx
char *v6; // rdi
int v7; // [rsp+0h] [rbp-20h] BYREF
int v8; // [rsp+4h] [rbp-1Ch] BYREF
char *v9[3]; // [rsp+8h] [rbp-18h] BYREF

result = func0(a1, v9, &v8);
if ( (_BYTE)result )
{
v5 = v9[0];
v6 = ++v9[0];
result = 0LL;
if ( *v5 == 44 )
{
result = func0(v6, v9, &v7);
if ( (_BYTE)result )
{
*a2 = v8;
*a3 = v7;
result = 1LL;
}
}
}
return result;
}

original_code:
boolean parse2hexnum (char *srcstr, int *retvalue1, int *retvalue2)
{
  char *str;
  int value1, value2;
  if (!gethexnum (srcstr, &str, &value1) || (*str++ != ',') ||
      !gethexnum (str, &str, &value2))
    {
      return (0);
    }
  *retvalue1 = value1;
  *retvalue2 = value2;
  return (1);
}

canonical_original_code:
unsigned char parse2hexnum(char *srcstr, int *retvalue1, int *retvalue2)
{
  char *str;
  int value1; int value2;
  if (!gethexnum (srcstr, &str, &value1) || (*str++ != ',') ||
      !gethexnum (str, &str, &value2))
    {
      return (0);
    }
  *retvalue1 = value1;
  *retvalue2 = value2;
  return (1);
}


decompiled_code:
char *__fastcall gdb_compress(char *src, char *dest)
{
return strcpy(dest, src);
}

canonical_decompiled_code:
char *__fastcall func3(char *src, char *dest)
{
return strcpy(dest, src);
}

original_code:
void
gdb_compress (char *src, char *dest)
{
  char previous = 0;
  int repeat = 0;
  strcpy (dest, src);
  return;
  do
    {
      if ((*src == previous) && (repeat != 255))
 {
   repeat++;
 }
      else
 {
   if (repeat > 3)
     {
       dest = dest - repeat;
       *dest++ = '*';
       *dest++ = tohexchar (repeat >> 4);
       *dest++ = tohexchar (repeat);
     }
   repeat = 0;
 }
      *dest++ = *src;
      previous = *src;
    }
  while (*src++);
}

canonical_original_code:
void gdb_compress(char *src, char *dest)
{
  char previous = 0;
  int repeat = 0;
  strcpy (dest, src);
  return;
  do
    {
      if ((*src == previous) && (repeat != 255))
 {
   repeat++;
 }
      else
 {
   if (repeat > 3)
     {
       dest = dest - repeat;
       *dest++ = '*';
       *dest++ = tohexchar (repeat >> 4);
       *dest++ = tohexchar (repeat);
     }
   repeat = 0;
 }
      *dest++ = *src;
      previous = *src;
    }
  while (*src++);
}

variable_types:
src
char *

variable_types:
dest
char *

variable_types: previous char

variable_types: repeat int


decompiled_code:
char *__fastcall gdb_expand(char *src, char *dest)
{
return strcpy(dest, src);
}

canonical_decompiled_code:
char *__fastcall func4(char *src, char *dest)
{
return strcpy(dest, src);
}

original_code:
void
gdb_expand (char *src, char *dest)
{
  int i;
  int repeat;
  strcpy (dest, src);
  return;
  do
    {
      if (*src == '*')
 {
   repeat = (chartohex (src[1]) << 4) + chartohex (src[2]);
   for (i = 0; i < repeat; i++)
     {
       *dest++ = *(src - 1);
     }
   src += 2;
 }
      else
 {
   *dest++ = *src;
 }
    }
  while (*src++);
}

canonical_original_code:
void gdb_expand(char *src, char *dest)
{
  int i;
  int repeat;
  strcpy (dest, src);
  return;
  do
    {
      if (*src == '*')
 {
   repeat = (chartohex (src[1]) << 4) + chartohex (src[2]);
   for (i = 0; i < repeat; i++)
     {
       *dest++ = *(src - 1);
     }
   src += 2;
 }
      else
 {
   *dest++ = *src;
 }
    }
  while (*src++);
}

variable_types: i int


tohexchar

decompiled_code:
__int64 __fastcall tohexchar(char a1)
{
return (unsigned __int8)hexchars[a1 & 0xF];
}

canonical_decompiled_code:
__int64 __fastcall func5(char a1)
{
return (unsigned __int8)hexchars[a1 & 0xF];
}

original_code:
char
tohexchar (unsigned char c)
{
  c &= 0x0f;
  return (hexchars[c]);
}

canonical_original_code:
char tohexchar(unsigned char c)
{
  c &= 0x0f;
  return (hexchars[c]);
}

variable_types:
c
unsigned char

return_type: char


chartohex

decompiled_code:
__int64 __fastcall chartohex(unsigned __int8 a1)
{
__int64 result; // rax

if ( (unsigned __int8)(a1 - 65) <= 5u )
return (unsigned int)a1 - 55;
if ( (unsigned __int8)(a1 - 97) <= 5u )
return (unsigned int)a1 - 87;
result = (unsigned int)a1 - 48;
if ( (unsigned __int8)(a1 - 48) >= 0xAu )
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned __int8 a1)
{
__int64 result; // rax

if ( (unsigned __int8)(a1 - 65) <= 5u )
return (unsigned int)a1 - 55;
if ( (unsigned __int8)(a1 - 97) <= 5u )
return (unsigned int)a1 - 87;
result = (unsigned int)a1 - 48;
if ( (unsigned __int8)(a1 - 48) >= 0xAu )
result = 0LL;
return result;
}

variable_types:
ch
unsigned char


decompiled_code:
int gdb_printf(const char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
return vprintf(a1, arg);
}

canonical_decompiled_code:
int func8(const char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
return vprintf(a1, arg);
}

original_code:
int
gdb_printf (const char *fmt, ...)
{
  va_list ap;
  int res;
  __builtin_va_start(ap,fmt);
  res = vprintf (fmt, ap);
  __builtin_va_end(ap);
  return res;
}

canonical_original_code:
int gdb_printf(char *fmt, ...)
{
  __builtin_va_list ap;
  int res;
  __builtin_va_start(ap,fmt);
  res = vprintf (fmt, ap);
  __builtin_va_end(ap);
  return res;
}

variable_types:
fmt
char *

variable_types: res int


decompiled_code:
__int64 ipv6_init_masks()
{
__int64 v0; // rdx
int i; // esi
__int64 result; // rax
char *v3; // r8

memset(ipv6_masks, 0xFFu, sizeof(ipv6_masks));
v0 = 0LL;
for ( i = 0; i != 128; ++i )
{
result = (unsigned int)((i >> 3) + 1);
v3 = &ipv6_masks[16 * i + (i >> 3)];
*v3 = (unsigned __int8)*v3 << (8 - (i & 7));
if ( (int)result <= 15 )
{
result = (int)result;
do
ipv6_masks[v0 + result++] = 0;
while ( (int)result <= 15 );
}
v0 += 16LL;
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rdx
int i; // esi
__int64 result; // rax
char *v3; // r8

memset(ipv6_masks, 0xFFu, sizeof(ipv6_masks));
v0 = 0LL;
for ( i = 0; i != 128; ++i )
{
result = (unsigned int)((i >> 3) + 1);
v3 = &ipv6_masks[16 * i + (i >> 3)];
*v3 = (unsigned __int8)*v3 << (8 - (i & 7));
if ( (int)result <= 15 )
{
result = (int)result;
do
ipv6_masks[v0 + result++] = 0;
while ( (int)result <= 15 );
}
v0 += 16LL;
}
return result;
}

original_code:
void ipv6_init_masks(void)
{
   int i,index;
   memset(ipv6_masks,0xff,sizeof(ipv6_masks));
   for(i=0;i<128;i++)
   {
      index = i >> 3;
      ipv6_masks[i].ip6.u6_addr8[index++] <<= (8 - (i & 7));
      while(index<16)
         ipv6_masks[i].ip6.u6_addr8[index++] = 0;
   }
}

canonical_original_code:
void ipv6_init_masks()
{
   int i; int index;
   memset(ipv6_masks,0xff,sizeof(ipv6_masks));
   for(i=0;i<128;i++)
   {
      index = i >> 3;
      ipv6_masks[i].ip6.u6_addr8[index++] <<= (8 - (i & 7));
      while(index<16)
         ipv6_masks[i].ip6.u6_addr8[index++] = 0;
   }
}

variable_types: index int


decompiled_code:
char *__fastcall n_ip_ntoa(char *a1, unsigned int a2)
{
sprintf(a1, "%u.%u.%u.%u", (unsigned __int8)a2, BYTE1(a2), BYTE2(a2), HIBYTE(a2));
return a1;
}

canonical_decompiled_code:
char *__fastcall func3(char *a1, unsigned int a2)
{
sprintf(a1, "%u.%u.%u.%u", (unsigned __int8)a2, BYTE1(a2), BYTE2(a2), HIBYTE(a2));
return a1;
}

original_code:
char *n_ip_ntoa(char *buffer,n_ip_addr_t ip_addr)
{
   u_char *p = (u_char *)&ip_addr;
   sprintf(buffer,"%u.%u.%u.%u",p[0],p[1],p[2],p[3]);
   return(buffer);
}

canonical_original_code:
char *n_ip_ntoa(char *buffer, unsigned int ip_addr)
{
   unsigned char *p = (u_char *)&ip_addr;
   sprintf(buffer,"%u.%u.%u.%u",p[0],p[1],p[2],p[3]);
   return(buffer);
}

variable_types:
buffer
char *

variable_types:
p
unsigned char *

return_type: char *


decompiled_code:
const char *__fastcall n_ipv6_ntoa(char *buf, const void *a2)
{
return inet_ntop(10, a2, buf, 0x2Eu);
}

canonical_decompiled_code:
const char *__fastcall func4(char *buf, const void *a2)
{
return inet_ntop(10, a2, buf, 0x2Eu);
}

original_code:
char *n_ipv6_ntoa(char *buffer,n_ipv6_addr_t *ipv6_addr)
{
   return((char *)inet_ntop(10,ipv6_addr,buffer,46));
}

canonical_original_code:
char *n_ipv6_ntoa(char *buffer, struct n_ipv6_addr_t *ipv6_addr)
{
   return((char *)inet_ntop(10,ipv6_addr,buffer,46));
}

variable_types: struct n_ipv6_addr_t { union { unsigned int u6_addr32[4]; unsigned short u6_addr16[8]; unsigned char u6_addr8[16]; } ip6; } *


decompiled_code:
__int64 __fastcall n_ip_aton(_DWORD *a1, const char *a2)
{
struct in_addr inp; // [rsp+Ch] [rbp-Ch] BYREF

if ( !inet_aton(a2, &inp) )
return 0xFFFFFFFFLL;
*a1 = _bswap_32(inp.s_addr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(_DWORD *a1, const char *a2)
{
struct in_addr inp; // [rsp+Ch] [rbp-Ch] BYREF

if ( !inet_aton(a2, &inp) )
return 0xFFFFFFFFLL;
*a1 = func0(inp.s_addr);
return 0LL;
}

original_code:
int n_ip_aton(n_ip_addr_t *ip_addr,char *ip_str)
{
   struct in_addr addr;
   if (inet_aton(ip_str,&addr) == 0)
      return(-1);
   *ip_addr = ntohl(addr.s_addr);
   return(0);
}

canonical_original_code:
int n_ip_aton(unsigned int *ip_addr, char *ip_str)
{
   struct in_addr addr;
   if (inet_aton(ip_str,&addr) == 0)
      return(-1);
   *ip_addr = ntohl(addr.s_addr);
   return(0);
}

variable_types:
addr
struct in_addr { unsigned int s_addr; }


decompiled_code:
int __fastcall n_ipv6_aton(void *buf, const char *a2)
{
return inet_pton(10, a2, buf);
}

canonical_decompiled_code:
int __fastcall func6(void *buf, const char *a2)
{
return inet_pton(10, a2, buf);
}

original_code:
int n_ipv6_aton(n_ipv6_addr_t *ipv6_addr,char *ip_str)
{
   return(inet_pton(10,ip_str,ipv6_addr));
}

canonical_original_code:
int n_ipv6_aton(struct n_ipv6_addr_t *ipv6_addr, char *ip_str)
{
   return(inet_pton(10,ip_str,ipv6_addr));
}

user_defined_types: struct n_ipv6_addr_t { union { unsigned int u6_addr32[4]; unsigned short u6_addr16[8]; unsigned char u6_addr8[16]; } ip6; }


decompiled_code:
__int64 __fastcall ip_parse_cidr(char *s, _DWORD *a2, _DWORD *a3)
{
char *v4; // rax
unsigned __int64 v5; // r13
char *v6; // rax
char *v7; // rbx
unsigned int v8; // ebp
char *endptr; // [rsp+8h] [rbp-30h] BYREF

v4 = strchr(s, 47);
if ( !v4 )
return (unsigned int)-1;
v5 = strtoul(v4 + 1, &endptr, 0);
if ( *endptr || v5 > 0x20 )
return (unsigned int)-1;
v6 = strdup(s);
v7 = v6;
if ( !v6 )
return (unsigned int)-1;
*strchr(v6, 47) = 0;
v8 = n_ip_aton(a2, v7);
if ( v8 == -1 )
{
free(v7);
}
else
{
*a3 = ip_masks[v5];
free(v7);
v8 = 0;
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *s, _DWORD *a2, _DWORD *a3)
{
char *v4; // rax
unsigned __int64 v5; // r13
char *v6; // rax
char *v7; // rbx
unsigned int v8; // ebp
char *endptr; // [rsp+8h] [rbp-30h] BYREF

v4 = strchr(s, 47);
if ( !v4 )
return (unsigned int)-1;
v5 = strtoul(v4 + 1, &endptr, 0);
if ( *endptr || v5 > 0x20 )
return (unsigned int)-1;
v6 = strdup(s);
v7 = v6;
if ( !v6 )
return (unsigned int)-1;
*strchr(v6, 47) = 0;
v8 = func5(a2, v7);
if ( v8 == -1 )
{
free(v7);
}
else
{
*a3 = ip_masks[v5];
free(v7);
v8 = 0;
}
return v8;
}

original_code:
int ip_parse_cidr(char *token,n_ip_addr_t *net_addr,n_ip_addr_t *net_mask)
{
   char *sl,*tmp,*err;
   u_long mask;
   if ((sl = strchr(token,'/')) == ((void *)0))
      return(-1);
   mask = strtoul(sl+1,&err,0);
   if (*err != 0)
      return(-1);
   if (mask > 32)
      return(-1);
   if ((tmp = strdup(token)) == ((void *)0))
      return(-1);
   sl = strchr(tmp,'/');
   *sl = 0;
   if (n_ip_aton(net_addr,tmp) == -1) {
      free(tmp);
      return(-1);
   }
   *net_mask = ip_masks[mask];
   free(tmp);
   return(0);
}

canonical_original_code:
int ip_parse_cidr(char *token, unsigned int *net_addr, unsigned int *net_mask)
{
   char *sl; char *tmp; char *err;
   unsigned long mask;
   if ((sl = strchr(token,'/')) == ((void *)0))
      return(-1);
   mask = strtoul(sl+1,&err,0);
   if (*err != 0)
      return(-1);
   if (mask > 32)
      return(-1);
   if ((tmp = strdup(token)) == ((void *)0))
      return(-1);
   sl = strchr(tmp,'/');
   *sl = 0;
   if (n_ip_aton(net_addr,tmp) == -1) {
      free(tmp);
      return(-1);
   }
   *net_mask = ip_masks[mask];
   free(tmp);
   return(0);
}

variable_types:
token
char *

variable_types:
sl
char *

variable_types:
tmp
char *

variable_types:
err
char *

variable_types:
mask
unsigned long


decompiled_code:
__int64 __fastcall ipv6_parse_cidr(char *s, void *buf, _DWORD *a3)
{
char *v4; // rax
unsigned __int64 v5; // r13
char *v6; // rax
char *v7; // rbx
__int64 result; // rax
char *endptr; // [rsp+8h] [rbp-30h] BYREF

v4 = strchr(s, 47);
if ( !v4 )
return 0xFFFFFFFFLL;
v5 = strtoul(v4 + 1, &endptr, 0);
if ( *endptr || v5 > 0x80 )
return 0xFFFFFFFFLL;
v6 = strdup(s);
v7 = v6;
if ( !v6 )
return 0xFFFFFFFFLL;
*strchr(v6, 47) = 0;
if ( n_ipv6_aton(buf, v7) <= 0 )
{
free(v7);
result = 0xFFFFFFFFLL;
}
else
{
*a3 = v5;
free(v7);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *s, void *buf, _DWORD *a3)
{
char *v4; // rax
unsigned __int64 v5; // r13
char *v6; // rax
char *v7; // rbx
__int64 result; // rax
char *endptr; // [rsp+8h] [rbp-30h] BYREF

v4 = strchr(s, 47);
if ( !v4 )
return 0xFFFFFFFFLL;
v5 = strtoul(v4 + 1, &endptr, 0);
if ( *endptr || v5 > 0x80 )
return 0xFFFFFFFFLL;
v6 = strdup(s);
v7 = v6;
if ( !v6 )
return 0xFFFFFFFFLL;
*strchr(v6, 47) = 0;
if ( func6(buf, v7) <= 0 )
{
free(v7);
result = 0xFFFFFFFFLL;
}
else
{
*a3 = v5;
free(v7);
result = 0LL;
}
return result;
}

original_code:
int ipv6_parse_cidr(char *token,n_ipv6_addr_t *net_addr,u_int *net_mask)
{
   char *sl,*tmp,*err;
   u_long mask;
   if ((sl = strchr(token,'/')) == ((void *)0))
      return(-1);
   mask = strtoul(sl+1,&err,0);
   if (*err != 0)
      return(-1);
   if (mask > 128)
      return(-1);
   if ((tmp = strdup(token)) == ((void *)0))
      return(-1);
   sl = strchr(tmp,'/');
   *sl = 0;
   if (n_ipv6_aton(net_addr,tmp) <= 0) {
      free(tmp);
      return(-1);
   }
   *net_mask = (u_int)mask;
   free(tmp);
   return(0);
}

canonical_original_code:
int ipv6_parse_cidr(char *token, struct n_ipv6_addr_t *net_addr, unsigned int *net_mask)
{
   char *sl; char *tmp; char *err;
   unsigned long mask;
   if ((sl = strchr(token,'/')) == ((void *)0))
      return(-1);
   mask = strtoul(sl+1,&err,0);
   if (*err != 0)
      return(-1);
   if (mask > 128)
      return(-1);
   if ((tmp = strdup(token)) == ((void *)0))
      return(-1);
   sl = strchr(tmp,'/');
   *sl = 0;
   if (n_ipv6_aton(net_addr,tmp) <= 0) {
      free(tmp);
      return(-1);
   }
   *net_mask = (unsigned int)mask;
   free(tmp);
   return(0);
}


decompiled_code:
__int64 __fastcall parse_mac_addr(_BYTE *a1, const char *a2)
{
int v2; // edx
__int64 result; // rax
__int64 i; // rax
char v5; // al
char v6; // al
char v7; // al
int v8; // [rsp+0h] [rbp-38h] BYREF
int v9; // [rsp+4h] [rbp-34h] BYREF
int v10; // [rsp+8h] [rbp-30h] BYREF
char v11; // [rsp+Ch] [rbp-2Ch] BYREF
char v12; // [rsp+10h] [rbp-28h] BYREF
char v13; // [rsp+14h] [rbp-24h] BYREF

if ( sscanf(a2, "%x:%x:%x:%x:%x:%x", &v8, &v9, &v10, &v11, &v12, &v13) == 6 )
{
for ( i = 0LL; i != 6; ++i )
a1[i] = *(&v8 + i);
result = 0LL;
}
else
{
v2 = sscanf(a2, "%x.%x.%x", &v8, &v9, &v10);
result = 0xFFFFFFFFLL;
if ( v2 == 3 )
{
v5 = v8;
*a1 = BYTE1(v8);
a1[1] = v5;
v6 = v9;
a1[2] = BYTE1(v9);
a1[3] = v6;
v7 = v10;
a1[4] = BYTE1(v10);
a1[5] = v7;
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(_BYTE *a1, const char *a2)
{
int v2; // edx
__int64 result; // rax
__int64 i; // rax
char v5; // al
char v6; // al
char v7; // al
int v8; // [rsp+0h] [rbp-38h] BYREF
int v9; // [rsp+4h] [rbp-34h] BYREF
int v10; // [rsp+8h] [rbp-30h] BYREF
char v11; // [rsp+Ch] [rbp-2Ch] BYREF
char v12; // [rsp+10h] [rbp-28h] BYREF
char v13; // [rsp+14h] [rbp-24h] BYREF

if ( sscanf(a2, "%x:%x:%x:%x:%x:%x", &v8, &v9, &v10, &v11, &v12, &v13) == 6 )
{
for ( i = 0LL; i != 6; ++i )
a1[i] = *(&v8 + i);
result = 0LL;
}
else
{
v2 = sscanf(a2, "%x.%x.%x", &v8, &v9, &v10);
result = 0xFFFFFFFFLL;
if ( v2 == 3 )
{
v5 = v8;
*a1 = BYTE1(v8);
a1[1] = v5;
v6 = v9;
a1[2] = BYTE1(v9);
a1[3] = v6;
v7 = v10;
a1[4] = BYTE1(v10);
a1[5] = v7;
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int parse_mac_addr(n_eth_addr_t *addr,char *str)
{
   u_int v[6];
   int i,res;
   res = sscanf(str,"%x:%x:%x:%x:%x:%x",&v[0],&v[1],&v[2],&v[3],&v[4],&v[5]);
   if (res == 6) {
      for(i=0;i<6;i++)
         addr->eth_addr_byte[i] = v[i];
      return(0);
   }
   res = sscanf(str,"%x.%x.%x",&v[0],&v[1],&v[2]);
   if (res == 3) {
      addr->eth_addr_byte[0] = (v[0] >> 8) & 0xFF;
      addr->eth_addr_byte[1] = v[0] & 0xFF;
      addr->eth_addr_byte[2] = (v[1] >> 8) & 0xFF;
      addr->eth_addr_byte[3] = v[1] & 0xFF;
      addr->eth_addr_byte[4] = (v[2] >> 8) & 0xFF;
      addr->eth_addr_byte[5] = v[2] & 0xFF;
   }
   return(-1);
}

canonical_original_code:
int parse_mac_addr(struct n_eth_addr_t *addr, char *str)
{
   unsigned int v[6];
   int i; int res;
   res = sscanf(str,"%x:%x:%x:%x:%x:%x",&v[0],&v[1],&v[2],&v[3],&v[4],&v[5]);
   if (res == 6) {
      for(i=0;i<6;i++)
         addr->eth_addr_byte[i] = v[i];
      return(0);
   }
   res = sscanf(str,"%x.%x.%x",&v[0],&v[1],&v[2]);
   if (res == 3) {
      addr->eth_addr_byte[0] = (v[0] >> 8) & 0xFF;
      addr->eth_addr_byte[1] = v[0] & 0xFF;
      addr->eth_addr_byte[2] = (v[1] >> 8) & 0xFF;
      addr->eth_addr_byte[3] = v[1] & 0xFF;
      addr->eth_addr_byte[4] = (v[2] >> 8) & 0xFF;
      addr->eth_addr_byte[5] = v[2] & 0xFF;
   }
   return(-1);
}

variable_types: struct n_eth_addr_t { unsigned char eth_addr_byte[6]; } *

variable_types:
str
char *

variable_types:
v
unsigned int [6]


original_code:
char *n_eth_ntoa(char *buffer,n_eth_addr_t *addr,int format)
{
   char *str_format;
   if (format == 0) {
      str_format = "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x";
   } else {
      str_format = "%2.2x%2.2x.%2.2x%2.2x.%2.2x%2.2x";
   }
   sprintf(buffer,str_format,
           addr->eth_addr_byte[0],addr->eth_addr_byte[1],
           addr->eth_addr_byte[2],addr->eth_addr_byte[3],
           addr->eth_addr_byte[4],addr->eth_addr_byte[5]);
   return(buffer);
}

canonical_original_code:
char *n_eth_ntoa(char *buffer, struct n_eth_addr_t *addr, int format)
{
   char *str_format;
   if (format == 0) {
      str_format = "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x";
   } else {
      str_format = "%2.2x%2.2x.%2.2x%2.2x.%2.2x%2.2x";
   }
   sprintf(buffer,str_format,
           addr->eth_addr_byte[0],addr->eth_addr_byte[1],
           addr->eth_addr_byte[2],addr->eth_addr_byte[3],
           addr->eth_addr_byte[4],addr->eth_addr_byte[5]);
   return(buffer);
}

variable_types: format int

user_defined_types: struct n_eth_addr_t { unsigned char eth_addr_byte[6]; }