canonical_decompiled_code:
__int64 __fastcall func9(const char *a1)
{
int v1; // eax
unsigned int v2; // er12
void *v3; // rdx
int v4; // eax
int v6; // edi
int v7; // edi
int v8; // edi
struct sockaddr v9; // [rsp+0h] [rbp-28h] BYREF

v1 = socket(2, 1, 6);
if ( v1 < 0 )
{
v2 = -1;
perror("Cannot create socket");
}
else
{
v2 = v1;
v9 = 0LL;
v9.sa_family = 2;
*(_WORD *)v9.sa_data = func8(2LL, a1, &v9.sa_data[2]);
v4 = inet_pton(2, a1, v3);
if ( v4 < 0 )
{
perror("First parameter is not a valid address family");
v7 = v2;
v2 = -1;
close(v7);
}
else if ( v4 )
{
if ( connect(v2, &v9, 0x10u) < 0 )
{
perror("Connect failed");
v8 = v2;
v2 = -1;
close(v8);
}
}
else
{
perror("Char string (second parameter does not contain valid ipaddress)");
v6 = v2;
v2 = -1;
close(v6);
}
}
return v2;
}

canonical_original_code:
int a2open(char *ipaddr)
{
    struct sockaddr_in piaddr;
    int res;
    int fd = socket(2, SOCK_STREAM, IPPROTO_TCP);
    if (fd < 0)
    {
        perror("Cannot create socket");
        return -1;
    }
    memset(&piaddr, 0, sizeof(piaddr));
    piaddr.sin_family = 2;
    piaddr.sin_port = htons(6551);
    res = inet_pton(2, ipaddr, &piaddr.sin_addr);
    if (res < 0)
    {
        perror("First parameter is not a valid address family");
        close(fd);
        return -1;
    }
    else if (res == 0)
    {
        perror("Char string (second parameter does not contain valid ipaddress)");
        close(fd);
        return -1;
    }
    if (connect(fd, (struct sockaddr *)&piaddr, sizeof(piaddr)) < 0)
    {
        perror("Connect failed");
        close(fd);
        return -1;
    }
    return fd;
}

variable_types:
ipaddr
char *

variable_types: 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]; }

variable_types: res int


decompiled_code:
int __fastcall a2close(int fd)
{
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

buf[0] = -1;
write(fd, buf, 1uLL);
shutdown(fd, 2);
return close(fd);
}

canonical_decompiled_code:
int __fastcall func10(int fd)
{
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

buf[0] = -1;
write(fd, buf, 1uLL);
shutdown(fd, 2);
return close(fd);
}

original_code:
void a2close(int fd)
{
    char closepkt;
    closepkt = 0xFF;
    write(fd, &closepkt, 1);
    shutdown(fd, SHUT_RDWR);
    close(fd);
}

variable_types: fd int

variable_types: closepkt char

return_type: void


decompiled_code:
_BOOL8 __fastcall a2read(int fd, __int16 a2, int a3, void *a4)
{
char buf; // [rsp+8h] [rbp-20h] BYREF
__int16 v8; // [rsp+9h] [rbp-1Fh]
__int16 v9; // [rsp+Bh] [rbp-1Dh]

v8 = a2;
v9 = a3;
buf = -112;
write(fd, &buf, 5uLL);
read(fd, a4, a3);
read(fd, &buf, 2uLL);
return buf == -98;
}

canonical_decompiled_code:
_BOOL8 __fastcall func11(int fd, __int16 a2, int a3, void *a4)
{
char buf; // [rsp+8h] [rbp-20h] BYREF
__int16 v8; // [rsp+9h] [rbp-1Fh]
__int16 v9; // [rsp+Bh] [rbp-1Dh]

v8 = a2;
v9 = a3;
buf = -112;
write(fd, &buf, 5uLL);
read(fd, a4, a3);
read(fd, &buf, 2uLL);
return buf == -98;
}

original_code:
int a2read(int fd, int address, int count, char *buffer)
{
    char readpkt[8];
    readpkt[0] = 0x90;
    readpkt[1] = address;
    readpkt[2] = address >> 8;
    readpkt[3] = count;
    readpkt[4] = count >> 8;
    write(fd, readpkt, 5);
    read(fd, buffer, count);
    read(fd, readpkt, 2);
    return ((unsigned char)readpkt[0] == 0x9E);
}

variable_types: address int

variable_types: count int

variable_types:
buffer
char *

variable_types:
readpkt
char [8]

return_type: int


decompiled_code:
_BOOL8 __fastcall a2write(int fd, __int16 a2, int a3, const void *a4)
{
char buf; // [rsp+8h] [rbp-20h] BYREF
__int16 v8; // [rsp+9h] [rbp-1Fh]
__int16 v9; // [rsp+Bh] [rbp-1Dh]

v8 = a2;
v9 = a3;
buf = -110;
write(fd, &buf, 5uLL);
write(fd, a4, a3);
read(fd, &buf, 2uLL);
return buf == -98;
}

canonical_decompiled_code:
_BOOL8 __fastcall func12(int fd, __int16 a2, int a3, const void *a4)
{
char buf; // [rsp+8h] [rbp-20h] BYREF
__int16 v8; // [rsp+9h] [rbp-1Fh]
__int16 v9; // [rsp+Bh] [rbp-1Dh]

v8 = a2;
v9 = a3;
buf = -110;
write(fd, &buf, 5uLL);
write(fd, a4, a3);
read(fd, &buf, 2uLL);
return buf == -98;
}

original_code:
int a2write(int fd, int address, int count, char *buffer)
{
    char writepkt[8];
    writepkt[0] = 0x92;
    writepkt[1] = address;
    writepkt[2] = address >> 8;
    writepkt[3] = count;
    writepkt[4] = count >> 8;
    write(fd, writepkt, 5);
    write(fd, buffer, count);
    read(fd, writepkt, 2);
    return ((unsigned char)writepkt[0] == 0x9E);
}

variable_types:
writepkt
char [8]


decompiled_code:
_BOOL8 __fastcall a2call(int fd, __int16 a2, _DWORD *a3)
{
char buf; // [rsp+Ch] [rbp-1Ch] BYREF
__int16 v6; // [rsp+Dh] [rbp-1Bh]

v6 = a2;
buf = -102;
write(fd, &buf, 3uLL);
read(fd, &buf, 2uLL);
if ( a3 )
*a3 = (unsigned __int8)v6;
return buf == -98;
}

canonical_decompiled_code:
_BOOL8 __fastcall func13(int fd, __int16 a2, _DWORD *a3)
{
char buf; // [rsp+Ch] [rbp-1Ch] BYREF
__int16 v6; // [rsp+Dh] [rbp-1Bh]

v6 = a2;
buf = -102;
write(fd, &buf, 3uLL);
read(fd, &buf, 2uLL);
if ( a3 )
*a3 = (unsigned __int8)v6;
return buf == -98;
}

original_code:
int a2call(int fd, int address, int *result)
{
    char callpkt[4];
    callpkt[0] = 0x9A;
    callpkt[1] = address;
    callpkt[2] = address >> 8;
    write(fd, callpkt, 3);
    read(fd, callpkt, 2);
    if (result)
        *result = (unsigned char)callpkt[1];
    return ((unsigned char)callpkt[0] == 0x9E);
}

variable_types:
result
int *

variable_types:
callpkt
char [4]


decompiled_code:
_BOOL8 __fastcall a2quickcall(int fd, __int16 a2, _DWORD *a3)
{
char buf; // [rsp+Ch] [rbp-1Ch] BYREF
__int16 v6; // [rsp+Dh] [rbp-1Bh]

v6 = a2;
buf = -108;
write(fd, &buf, 3uLL);
read(fd, &buf, 2uLL);
if ( a3 )
*a3 = (unsigned __int8)v6;
return buf == -98;
}

canonical_decompiled_code:
_BOOL8 __fastcall func14(int fd, __int16 a2, _DWORD *a3)
{
char buf; // [rsp+Ch] [rbp-1Ch] BYREF
__int16 v6; // [rsp+Dh] [rbp-1Bh]

v6 = a2;
buf = -108;
write(fd, &buf, 3uLL);
read(fd, &buf, 2uLL);
if ( a3 )
*a3 = (unsigned __int8)v6;
return buf == -98;
}

original_code:
int a2quickcall(int fd, int address, int *result)
{
    char callpkt[4];
    callpkt[0] = 0x94;
    callpkt[1] = address;
    callpkt[2] = address >> 8;
    write(fd, callpkt, 3);
    read(fd, callpkt, 2);
    if (result)
        *result = (unsigned char)callpkt[1];
    return ((unsigned char)callpkt[0] == 0x9E);
}


createPacket

decompiled_code:
void *__fastcall createPacket(int a1, int a2)
{
return malloc(9 * a2 + 4LL * a1 + 20);
}

canonical_decompiled_code:
void *__fastcall func0(int a1, int a2)
{
return malloc(9 * a2 + 4LL * a1 + 20);
}

original_code:
char* createPacket(int numNeighbors, int numFiles){
 char* buf;
 buf = malloc(20*sizeof(char)+numNeighbors*sizeof(int)+numFiles*9);
 return buf;
}

canonical_original_code:
char *createPacket(int numNeighbors, int numFiles){
 char *buf;
 buf = malloc(20*sizeof(char)+numNeighbors*sizeof(int)+numFiles*9);
 return buf;
}

variable_types: numNeighbors int

variable_types: numFiles int

variable_types:
buf
char *

return_type: char *


addString

original_code:
char* addString(char* str, char* buf){
 memcpy(buf, str, 9);
 return buf+9;
}

canonical_original_code:
char *addString(char *str, char *buf){
 memcpy(buf, str, 9);
 return buf+9;
}

variable_types:
str
char *


readString

decompiled_code:
const char *__fastcall readString(char *a1, const char *a2)
{
strcpy(a1, a2);
return a2 + 9;
}

canonical_decompiled_code:
const char *__fastcall func2(char *a1, const char *a2)
{
strcpy(a1, a2);
return a2 + 9;
}

original_code:
char* readString(char str[9], char* buf){
 strcpy(str, buf);
 return buf + 9;
}

canonical_original_code:
char *readString(char str[9], char *buf){
 strcpy(str, buf);
 return buf + 9;
}

variable_types:
str
char [9]


addFiles

decompiled_code:
__int64 __fastcall addFiles(__int64 a1)
{
__int64 **v1; // rdx
__int64 v3; // rdx

v1 = (__int64 **)fileList;
if ( fileList )
{
do
{
addString(**v1, a1);
v1 = *(__int64 ***)(v3 + 8);
}
while ( v1 );
}
return a1;
}

original_code:
char* addFiles(char* start){
 node* curr = fileList.head;
 char* ptr;
 ptr = start;
 while( curr != ((void *)0) ){
  fileEntry* fe = (fileEntry*)curr->data;
  addString(fe->objectName, ptr);
  ptr += 9;
  curr = curr->next;
 }
 return ptr;
}

canonical_original_code:
char *addFiles(char *start){
 struct node_s *curr = fileList.head;
 char *ptr;
 ptr = start;
 while( curr != ((void *)0) ){
  struct fe *fe = (fileEntry*)curr->data;
  addString(fe->objectName, ptr);
  ptr += 9;
  curr = curr->next;
 }
 return ptr;
}

variable_types:
start
char *

variable_types: struct node_s { void *data; struct node_s *next; } *

variable_types:
ptr
char *

variable_types: struct fe { char *objectName; char *path; } *


printBuf

decompiled_code:
int __fastcall printBuf(char *a1, int a2)
{
__int64 v2; // rbp
char *v3; // rbx
int v4; // edi

if ( a2 > 0 )
{
v2 = (__int64)&a1[a2 - 1 + 1];
v3 = a1;
do
{
v4 = *v3++;
putchar(v4);
}
while ( v3 != (char *)v2 );
}
return puts("\nend");
}

canonical_decompiled_code:
int __fastcall func4(char *a1, int a2)
{
__int64 v2; // rbp
char *v3; // rbx
int v4; // edi

if ( a2 > 0 )
{
v2 = (__int64)&a1[a2 - 1 + 1];
v3 = a1;
do
{
v4 = *v3++;
putchar(v4);
}
while ( v3 != (char *)v2 );
}
return puts("\nend");
}

original_code:
void printBuf(char* buf, int len){
 int i;
 for( i = 0 ; i < len ; i++){
  printf("%c", buf[i]);
 }
 printf("\nend\n");
}

canonical_original_code:
void printBuf(char *buf, int len){
 int i;
 for( i = 0 ; i < len ; i++){
  printf("%c", buf[i]);
 }
 printf("\nend\n");
}

variable_types: len int

variable_types: i int


freeBuffer

decompiled_code:
void __fastcall freeBuffer(void *a1)
{
if ( a1 )
free(a1);
}

canonical_decompiled_code:
void __fastcall func5(void *a1)
{
if ( a1 )
free(a1);
}

original_code:
void freeBuffer(char* buf){
 if(buf != ((void *)0)){
  free(buf);
 }
}

canonical_original_code:
void freeBuffer(char *buf){
 if(buf != ((void *)0)){
  free(buf);
 }
}


addToResendList

decompiled_code:
int __fastcall addToResendList(int a1, unsigned int a2)
{
int *v2; // rax
int *v3; // rbx

v2 = isExist(a1, a2);
if ( v2 )
{
v3 = v2;
if ( *v2 != 1 )
{
LODWORD(v2) = printf("Add neighbor %d to resend list\n", a2);
*v3 = 1;
v3[2] = a1;
v3[1] = a2;
++numDeferMessages;
}
}
return (int)v2;
}

canonical_decompiled_code:
int __fastcall func7(int a1, unsigned int a2)
{
int *v2; // rax
int *v3; // rbx

v2 = func6(a1, a2);
if ( v2 )
{
v3 = v2;
if ( *v2 != 1 )
{
LODWORD(v2) = printf("Add neighbor %d to resend list\n", a2);
*v3 = 1;
v3[2] = a1;
v3[1] = a2;
++numDeferMessages;
}
}
return (int)v2;
}

original_code:
void addToResendList(int senderId, int receiverId){
 deferredMessage* df = isExist( senderId, receiverId);
 if( df ){
  if(df->inUse != 1){
  printf("Add neighbor %d to resend list\n", receiverId);
  df->inUse = 1;
  df->senderId = senderId;
  df->receiverId = receiverId;
  numDeferMessages ++ ;
  }
 }
}

canonical_original_code:
void addToResendList(int senderId, int receiverId){
 struct df *df = isExist( senderId, receiverId);
 if( df ){
  if(df->inUse != 1){
  printf("Add neighbor %d to resend list\n", receiverId);
  df->inUse = 1;
  df->senderId = senderId;
  df->receiverId = receiverId;
  numDeferMessages ++ ;
  }
 }
}

variable_types: senderId int

variable_types: receiverId int

variable_types: struct df { int inUse; int receiverId; int senderId; } *


removeFromResendList

decompiled_code:
int __fastcall removeFromResendList(int a1, unsigned int a2)
{
int *v2; // rax
int *v3; // rbx

v2 = isExist(a1, a2);
if ( v2 )
{
v3 = v2;
LODWORD(v2) = printf("Remove neighbor %d from resend list\n", a2);
*v3 = 0;
--numDeferMessages;
}
return (int)v2;
}

canonical_decompiled_code:
int __fastcall func8(int a1, unsigned int a2)
{
int *v2; // rax
int *v3; // rbx

v2 = func6(a1, a2);
if ( v2 )
{
v3 = v2;
LODWORD(v2) = printf("Remove neighbor %d from resend list\n", a2);
*v3 = 0;
--numDeferMessages;
}
return (int)v2;
}

original_code:
void removeFromResendList( int senderId, int receiverId ){
 deferredMessage* df = isExist( senderId , receiverId);
 if( df ){
  printf("Remove neighbor %d from resend list\n", receiverId);
  df->inUse = 0;
  numDeferMessages -- ;
 }
}

canonical_original_code:
void removeFromResendList(int senderId, int receiverId){
 struct df *df = isExist( senderId , receiverId);
 if( df ){
  printf("Remove neighbor %d from resend list\n", receiverId);
  df->inUse = 0;
  numDeferMessages -- ;
 }
}

user_defined_types: struct df { int inUse; int receiverId; int senderId; }


reTransmit

decompiled_code:
void __fastcall reTransmit(int fd, unsigned int a2, unsigned int a3)
{
__int64 v5; // rax
__int64 v6; // r15
_BYTE *v7; // r12
_DWORD *v8; // rbx
int **i; // rdx
_DWORD *v10; // rsi
__int64 v11; // rdx
__int64 *j; // rdx
__int64 v13; // rsi
__int64 v14; // rdx
const struct sockaddr *v15; // r15

v5 = getRoutingEntry(&routing, a3);
if ( v5 )
{
v6 = v5;
v7 = createPacket(*(_DWORD *)(v5 + 76), *(_DWORD *)(v5 + 72));
v8 = addHeader(v7);
for ( i = **(int ****)(v6 + 8); i; i = *(int ***)(v11 + 8) )
{
v10 = v8++;
addInt(**i, v10);
}
for ( j = **(__int64 ***)(v6 + 16); j; j = *(__int64 **)(v14 + 8) )
{
v13 = (__int64)v8;
v8 = (_DWORD *)((char *)v8 + 9);
addString(*j, v13);
}
v15 = (const struct sockaddr *)getRoutingEntry(&routing, a2);
if ( v15 )
{
printf("Retrans from %d to %d\n", a3, a2);
if ( sendto(fd, v7, (int)v8 - (int)v7 + 1, 0, v15 + 5, 0x10u) <= 0 )
puts("This is really bad");
}
freeBuffer(v7);
}
}

canonical_decompiled_code:
void __fastcall func9(int fd, unsigned int a2, unsigned int a3)
{
__int64 v5; // rax
__int64 v6; // r15
_BYTE *v7; // r12
_DWORD *v8; // rbx
int **i; // rdx
_DWORD *v10; // rsi
__int64 v11; // rdx
__int64 *j; // rdx
__int64 v13; // rsi
__int64 v14; // rdx
const struct sockaddr *v15; // r15

v5 = getRoutingEntry(&routing, a3);
if ( v5 )
{
v6 = v5;
v7 = func0(*(_DWORD *)(v5 + 76), *(_DWORD *)(v5 + 72));
v8 = addHeader(v7);
for ( i = **(int ****)(v6 + 8); i; i = *(int ***)(v11 + 8) )
{
v10 = v8++;
addInt(**i, v10);
}
for ( j = **(__int64 ***)(v6 + 16); j; j = *(__int64 **)(v14 + 8) )
{
v13 = (__int64)v8;
v8 = (_DWORD *)((char *)v8 + 9);
func1(*j, v13);
}
v15 = (const struct sockaddr *)getRoutingEntry(&routing, a2);
if ( v15 )
{
printf("Retrans from %d to %d\n", a3, a2);
if ( sendto(fd, v7, (int)v8 - (int)v7 + 1, 0, v15 + 5, 0x10u) <= 0 )
puts("This is really bad");
}
func5(v7);
}
}

original_code:
void reTransmit(int udp, int receiverId, int senderId ){
 routingEntry* re = getRoutingEntry( &routing , senderId );
 char* ptr;
 if( re != ((void *)0) ){
  char* sendBuf = createPacket(re->numLinks , re->numFiles);
  ptr = addHeader(sendBuf, 32, 0, senderId, re->seqNumReceive, re->numLinks, re->numFiles);
  node* curr = re->neighbors->head;
  while( curr != ((void *)0) ){
   int* id = (int* )curr->data;
    addInt(*id, ptr);
   ptr += sizeof(int);
   curr = curr->next;
  }
  curr = re->objects->head;
  while( curr != ((void *)0) ){
   char* objectName = (char* )curr->data;
   addString(objectName, ptr);
   ptr+=9;
   curr = curr->next;
  }
  routingEntry* neighborToReceive = getRoutingEntry( &routing, receiverId );
  if( neighborToReceive!= ((void *)0) ){
      ssize_t sen;
       int packetSize = ptr - sendBuf + 1;
   printf("Retrans from %d to %d\n", senderId ,receiverId);
       sen = sendto(udp, sendBuf ,packetSize, 0, (struct sockaddr *)&(neighborToReceive->cli_addr), sizeof(neighborToReceive->cli_addr));
       if(sen <= 0 ){
        printf("This is really bad\n");
       }
  }
  freeBuffer(sendBuf);
 }
}

canonical_original_code:
void reTransmit(int udp, int receiverId, int senderId){
 struct re *re = getRoutingEntry( &routing , senderId );
 char *ptr;
 if( re != ((void *)0) ){
  char *sendBuf = createPacket(re->numLinks , re->numFiles);
  ptr = addHeader(sendBuf, 32, 0, senderId, re->seqNumReceive, re->numLinks, re->numFiles);
  struct node_s *curr = re->neighbors->head;
  while( curr != ((void *)0) ){
   int *id = (int* )curr->data;
    addInt(*id, ptr);
   ptr += sizeof(int);
   curr = curr->next;
  }
  curr = re->objects->head;
  while( curr != ((void *)0) ){
   char *objectName = (char* )curr->data;
   addString(objectName, ptr);
   ptr+=9;
   curr = curr->next;
  }
  struct re *neighborToReceive = getRoutingEntry( &routing, receiverId );
  if( neighborToReceive!= ((void *)0) ){
      long sen;
       int packetSize = ptr - sendBuf + 1;
   printf("Retrans from %d to %d\n", senderId ,receiverId);
       sen = sendto(udp, sendBuf ,packetSize, 0, (struct sockaddr *)&(neighborToReceive->cli_addr), sizeof(neighborToReceive->cli_addr));
       if(sen <= 0 ){
        printf("This is really bad\n");
       }
  }
  freeBuffer(sendBuf);
 }
}

variable_types: udp int

variable_types: struct re { int nodeId; int nextHop; struct list { struct node_s { void *data; struct node_s *next; } *head; struct node_s *tail; } *neighbors; struct list *objects; struct re *parent; int visited; char *hostName; int routingPort; int localPort; int serverPort; int isNeighbor; int seqNumReceive; int ttl; int numFiles; int numLinks; 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]; } cli_addr; int neighborCountDown; int LSACountDown; int isDown; } *

variable_types:
sendBuf
char *

variable_types:
id
int *

variable_types:
objectName
char *

variable_types: sen long

variable_types: packetSize int

user_defined_types: struct re { int nodeId; int nextHop; struct list *neighbors; struct list *objects; struct re *parent; int visited; char *hostName; int routingPort; int localPort; int serverPort; int isNeighbor; int seqNumReceive; int ttl; int numFiles; int numLinks; struct sockaddr_in cli_addr; int neighborCountDown; int LSACountDown; int isDown; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }

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 list { struct node_s *head; struct node_s *tail; }


forward

decompiled_code:
void __fastcall forward(int fd, void *buf, int a3, unsigned int a4, int a5)
{
const struct sockaddr **v5; // rbx
const struct sockaddr *v8; // rbp
__int64 v9; // rdx
size_t n; // [rsp+8h] [rbp-40h]

--*((_BYTE *)buf + 1);
v5 = (const struct sockaddr **)routing;
if ( routing )
{
n = a3;
do
{
v8 = *v5;
if ( *(_DWORD *)&(*v5)[3].sa_data[10] )
{
v9 = *(unsigned int *)&v8->sa_family;
if ( (_DWORD)v9 != a5 && !*(_DWORD *)&v8[6].sa_data[6] )
{
printf("Start to forward packet from %d to node %d\n", a4, v9);
if ( sendto(fd, buf, n, 0, v8 + 5, 0x10u) <= 0 )
puts("This is really bad");
addToResendList(a4, *(_DWORD *)&v8->sa_family);
}
}
v5 = (const struct sockaddr **)v5[1];
}
while ( v5 );
}
}

canonical_decompiled_code:
void __fastcall func11(int fd, void *buf, int a3, unsigned int a4, int a5)
{
const struct sockaddr **v5; // rbx
const struct sockaddr *v8; // rbp
__int64 v9; // rdx
size_t n; // [rsp+8h] [rbp-40h]

--*((_BYTE *)buf + 1);
v5 = (const struct sockaddr **)routing;
if ( routing )
{
n = a3;
do
{
v8 = *v5;
if ( *(_DWORD *)&(*v5)[3].sa_data[10] )
{
v9 = *(unsigned int *)&v8->sa_family;
if ( (_DWORD)v9 != a5 && !*(_DWORD *)&v8[6].sa_data[6] )
{
printf("Start to forward packet from %d to node %d\n", a4, v9);
if ( sendto(fd, buf, n, 0, v8 + 5, 0x10u) <= 0 )
puts("This is really bad");
func7(a4, *(_DWORD *)&v8->sa_family);
}
}
v5 = (const struct sockaddr **)v5[1];
}
while ( v5 );
}
}

original_code:
void forward(int udp, char* packet, int packetSize, int senderId, int excludeId){
 char* ttl = packet+1;
 *ttl = *(ttl)-1;
 node* curr = routing.head;
 while( curr != ((void *)0) ){
  routingEntry* re = (routingEntry*)curr->data;
  if (re->isNeighbor && re->nodeId != excludeId && !re->isDown){
   ssize_t sen;
   printf("Start to forward packet from %d to node %d\n", senderId,re->nodeId);
   sen = sendto(udp, packet ,packetSize, 0, (struct sockaddr *)&(re->cli_addr), sizeof(re->cli_addr));
   if(sen <= 0 ){
    printf("This is really bad\n");
   }
   addToResendList(senderId, re->nodeId);
  }
  curr = curr->next;
 }
}

canonical_original_code:
void forward(int udp, char *packet, int packetSize, int senderId, int excludeId){
 char *ttl = packet+1;
 *ttl = *(ttl)-1;
 struct node_s *curr = routing.head;
 while( curr != ((void *)0) ){
  struct re *re = (routingEntry*)curr->data;
  if (re->isNeighbor && re->nodeId != excludeId && !re->isDown){
   long sen;
   printf("Start to forward packet from %d to node %d\n", senderId,re->nodeId);
   sen = sendto(udp, packet ,packetSize, 0, (struct sockaddr *)&(re->cli_addr), sizeof(re->cli_addr));
   if(sen <= 0 ){
    printf("This is really bad\n");
   }
   addToResendList(senderId, re->nodeId);
  }
  curr = curr->next;
 }
}

variable_types:
packet
char *

variable_types: excludeId int

variable_types:
ttl
char *

user_defined_types: struct node_s { void *data; struct node_s *next; }


sendAck

decompiled_code:
int __fastcall sendAck(int fd, int a2, int a3)
{
_BYTE *v4; // rax
_BYTE *v5; // rax
_WORD *v6; // rax
_WORD *v7; // rax
_DWORD *v8; // rax
unsigned int v9; // eax
int v10; // ecx
const struct sockaddr *v11; // r8
socklen_t v12; // er9
const void *v13; // r10
ssize_t v14; // rax

v4 = malloc(0xCuLL);
v5 = addChar(49, v4);
v6 = addChar(32, v5);
v7 = addShort(1, v6);
v8 = addInt(a2, v7);
v9 = (unsigned int)addInt(a3, v8);
v14 = sendto(fd, v13, (int)(v9 - (_DWORD)v13 + 1), v10, v11, v12);
if ( v14 <= 0 )
LODWORD(v14) = puts("This is really bad");
return v14;
}

canonical_decompiled_code:
int __fastcall func12(int fd, int a2, int a3)
{
_BYTE *v4; // rax
_BYTE *v5; // rax
_WORD *v6; // rax
_WORD *v7; // rax
_DWORD *v8; // rax
unsigned int v9; // eax
int v10; // ecx
const struct sockaddr *v11; // r8
socklen_t v12; // er9
const void *v13; // r10
ssize_t v14; // rax

v4 = malloc(0xCuLL);
v5 = addChar(49, v4);
v6 = addChar(32, v5);
v7 = addShort(1, v6);
v8 = addInt(a2, v7);
v9 = (unsigned int)addInt(a3, v8);
v14 = sendto(fd, v13, (int)(v9 - (_DWORD)v13 + 1), v10, v11, v12);
if ( v14 <= 0 )
LODWORD(v14) = puts("This is really bad");
return v14;
}

original_code:
void sendAck(int udp, int senderId, int seqNum, struct sockaddr_in cli_addr){
 char* ack = malloc(3*sizeof(int));
 char* ptr = ack;
 ptr = addChar('1', ptr);
 ptr = addChar(32,ptr);
 ptr = addShort(1, ptr);
 ptr = addInt(senderId, ptr);
 ptr = addInt(seqNum, ptr);
 int ackSize = ptr - ack + 1;
 ssize_t sen;
 sen = sendto(udp, ack, ackSize, 0, (struct sockaddr *)&cli_addr, sizeof(cli_addr));
 if(sen <= 0 ){
  printf("This is really bad\n");
 }
}

canonical_original_code:
void sendAck(int udp, int senderId, int seqNum, struct sockaddr_in cli_addr){
 char *ack = malloc(3*sizeof(int));
 char *ptr = ack;
 ptr = addChar('1', ptr);
 ptr = addChar(32,ptr);
 ptr = addShort(1, ptr);
 ptr = addInt(senderId, ptr);
 ptr = addInt(seqNum, ptr);
 int ackSize = ptr - ack + 1;
 long sen;
 sen = sendto(udp, ack, ackSize, 0, (struct sockaddr *)&cli_addr, sizeof(cli_addr));
 if(sen <= 0 ){
  printf("This is really bad\n");
 }
}

variable_types: seqNum int

variable_types: 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]; }

variable_types:
ack
char *

variable_types:
ptr
char *

variable_types: ackSize int


advertise

decompiled_code:
void __fastcall advertise(int fd, int a2, int a3)
{
unsigned int **v3; // rbx
__int64 v4; // rax
unsigned int *v5; // r13
_BYTE *v6; // rbp
_DWORD *v7; // rax
_DWORD *v8; // rax
unsigned int v9; // [rsp+8h] [rbp-40h]

v3 = (unsigned int **)routing;
v4 = getRoutingEntry(&routing, mynodeID);
++*(_DWORD *)(v4 + 64);
for ( ; v3; v3 = (unsigned int **)v3[1] )
{
while ( 1 )
{
v5 = *v3;
if ( (*v3)[15] )
break;
v3 = (unsigned int **)v3[1];
if ( !v3 )
return;
}
v6 = createPacket(a2, a3);
v7 = addHeader(v6);
v8 = addNodeIds(v7, mynodeID);
v9 = addFiles((__int64)v8) - (_DWORD)v6 + 1;
printf("The packet length is %d\n", v9);
printf("Advertise to node %d\n", *v5);
if ( sendto(fd, v6, (int)v9, 0, (const struct sockaddr *)v5 + 5, 0x10u) <= 0 )
puts("This is really bad");
addToResendList(mynodeID, *v5);
freeBuffer(v6);
}
}

canonical_decompiled_code:
void __fastcall func13(int fd, int a2, int a3)
{
unsigned int **v3; // rbx
__int64 v4; // rax
unsigned int *v5; // r13
_BYTE *v6; // rbp
_DWORD *v7; // rax
_DWORD *v8; // rax
unsigned int v9; // [rsp+8h] [rbp-40h]

v3 = (unsigned int **)routing;
v4 = getRoutingEntry(&routing, mynodeID);
++*(_DWORD *)(v4 + 64);
for ( ; v3; v3 = (unsigned int **)v3[1] )
{
while ( 1 )
{
v5 = *v3;
if ( (*v3)[15] )
break;
v3 = (unsigned int **)v3[1];
if ( !v3 )
return;
}
v6 = func0(a2, a3);
v7 = addHeader(v6);
v8 = addNodeIds(v7, mynodeID);
v9 = func3((__int64)v8) - (_DWORD)v6 + 1;
printf("The packet length is %d\n", v9);
printf("Advertise to node %d\n", *v5);
if ( sendto(fd, v6, (int)v9, 0, (const struct sockaddr *)v5 + 5, 0x10u) <= 0 )
puts("This is really bad");
func7(mynodeID, *v5);
func5(v6);
}
}

original_code:
void advertise(int udp, int numLinks, int numFiles){
 node* curr = routing.head;
 char* ptr;
 routingEntry* me = getRoutingEntry(&routing, mynodeID);
 me->seqNumReceive++;
 while( curr != ((void *)0) ){
  routingEntry* re = (routingEntry*)curr->data;
  if (re->isNeighbor){
   char* sendBuf = createPacket(numLinks, numFiles);
   ptr = addHeader(sendBuf, 32, 0, mynodeID, me->seqNumReceive, me->numLinks, me->numFiles);
   ptr = addNodeIds(ptr, mynodeID);
   ptr = addFiles(ptr);
   int packetSize = ptr-sendBuf+1;
   printf("The packet length is %d\n",packetSize );
   ssize_t sen;
   printf("Advertise to node %d\n", re->nodeId);
   sen = sendto(udp, sendBuf,packetSize, 0, (struct sockaddr *)&(re->cli_addr), sizeof(re->cli_addr));
   if(sen <= 0 ){
    printf("This is really bad\n");
   }
   addToResendList(mynodeID, re->nodeId);
   freeBuffer(sendBuf);
  }
  curr = curr->next;
 }
}

canonical_original_code:
void advertise(int udp, int numLinks, int numFiles){
 struct node_s *curr = routing.head;
 char *ptr;
 struct re *me = getRoutingEntry(&routing, mynodeID);
 me->seqNumReceive++;
 while( curr != ((void *)0) ){
  struct re *re = (routingEntry*)curr->data;
  if (re->isNeighbor){
   char *sendBuf = createPacket(numLinks, numFiles);
   ptr = addHeader(sendBuf, 32, 0, mynodeID, me->seqNumReceive, me->numLinks, me->numFiles);
   ptr = addNodeIds(ptr, mynodeID);
   ptr = addFiles(ptr);
   int packetSize = ptr-sendBuf+1;
   printf("The packet length is %d\n",packetSize );
   long sen;
   printf("Advertise to node %d\n", re->nodeId);
   sen = sendto(udp, sendBuf,packetSize, 0, (struct sockaddr *)&(re->cli_addr), sizeof(re->cli_addr));
   if(sen <= 0 ){
    printf("This is really bad\n");
   }
   addToResendList(mynodeID, re->nodeId);
   freeBuffer(sendBuf);
  }
  curr = curr->next;
 }
}

variable_types: numLinks int

variable_types: numFiles int

variable_types: struct node_s { void *data; struct node_s *next; } *


countDown

decompiled_code:
void __fastcall countDown(int fd)
{
unsigned int **v1; // rbp
__int64 v2; // rsi
__int64 v3; // rdx
unsigned int *v4; // rbx
__int64 v5; // rdx
_DWORD *v6; // r12
int **i; // rdx
_DWORD *v8; // rsi
__int64 v9; // rdx
__int64 *j; // r15
__int64 v11; // r14
__int64 v12; // rsi
__int64 v13; // rsi
__int64 v14; // rax
__int64 v15; // rsi
_BYTE *buf; // [rsp+8h] [rbp-40h]

v1 = (unsigned int **)routing;
if ( routing )
{
while ( 1 )
{
v4 = *v1;
if ( !(*v1)[15] )
break;
if ( v4[26] || (v5 = v4[24] - advCycle, v4[24] = v5, printf("Time limit for neighbor %d : %d\n", *v4, v5), v4[24]) )
{
LABEL_6:
v1 = (unsigned int **)v1[1];
if ( !v1 )
return;
}
else
{
buf = createPacket(v4[19], v4[18]);
v6 = addHeader(buf);
printf("**On behalf of %d", *v4);
for ( i = (int **)**((_QWORD **)v4 + 1); i; i = *(int ***)(v9 + 8) )
{
v8 = v6++;
addInt(**i, v8);
}
for ( j = (__int64 *)**((_QWORD **)v4 + 2); j; j = (__int64 *)j[1] )
{
v11 = *j;
printf("**add file %s\n", (const char *)*j);
v12 = (__int64)v6;
v6 = (_DWORD *)((char *)v6 + 9);
addString(v11, v12);
}
forward(fd, buf, (_DWORD)v6 - (_DWORD)buf + 1, *v4, *v4);
v13 = mynodeID;
v4[26] = 1;
v14 = getRoutingEntry(&routing, v13);
v15 = *v4;
--*(_DWORD *)(v14 + 76);
printf("Neighbor %d is down\n", v15);
v1 = (unsigned int **)v1[1];
if ( !v1 )
return;
}
}
v2 = *v4;
if ( (_DWORD)v2 != mynodeID )
{
v3 = v4[25] - advCycle;
v4[25] = v3;
printf("Time limit for LSA from node %d : %d\n", v2, v3);
if ( !v4[25] )
deleteRoutingEntry(*v4);
}
goto LABEL_6;
}
}

canonical_decompiled_code:
void __fastcall func14(int fd)
{
unsigned int **v1; // rbp
__int64 v2; // rsi
__int64 v3; // rdx
unsigned int *v4; // rbx
__int64 v5; // rdx
_DWORD *v6; // r12
int **i; // rdx
_DWORD *v8; // rsi
__int64 v9; // rdx
__int64 *j; // r15
__int64 v11; // r14
__int64 v12; // rsi
__int64 v13; // rsi
__int64 v14; // rax
__int64 v15; // rsi
_BYTE *buf; // [rsp+8h] [rbp-40h]

v1 = (unsigned int **)routing;
if ( routing )
{
while ( 1 )
{
v4 = *v1;
if ( !(*v1)[15] )
break;
if ( v4[26] || (v5 = v4[24] - advCycle, v4[24] = v5, printf("Time limit for neighbor %d : %d\n", *v4, v5), v4[24]) )
{
LABEL_6:
v1 = (unsigned int **)v1[1];
if ( !v1 )
return;
}
else
{
buf = func0(v4[19], v4[18]);
v6 = addHeader(buf);
printf("**On behalf of %d", *v4);
for ( i = (int **)**((_QWORD **)v4 + 1); i; i = *(int ***)(v9 + 8) )
{
v8 = v6++;
addInt(**i, v8);
}
for ( j = (__int64 *)**((_QWORD **)v4 + 2); j; j = (__int64 *)j[1] )
{
v11 = *j;
printf("**add file %s\n", (const char *)*j);
v12 = (__int64)v6;
v6 = (_DWORD *)((char *)v6 + 9);
func1(v11, v12);
}
func11(fd, buf, (_DWORD)v6 - (_DWORD)buf + 1, *v4, *v4);
v13 = mynodeID;
v4[26] = 1;
v14 = getRoutingEntry(&routing, v13);
v15 = *v4;
--*(_DWORD *)(v14 + 76);
printf("Neighbor %d is down\n", v15);
v1 = (unsigned int **)v1[1];
if ( !v1 )
return;
}
}
v2 = *v4;
if ( (_DWORD)v2 != mynodeID )
{
v3 = v4[25] - advCycle;
v4[25] = v3;
printf("Time limit for LSA from node %d : %d\n", v2, v3);
if ( !v4[25] )
deleteRoutingEntry(*v4);
}
goto LABEL_6;
}
}

original_code:
void countDown(int udp){
 node* curr = routing.head;
 while( curr != ((void *)0) ){
  routingEntry* re = (routingEntry* )curr->data;
  if( re->isNeighbor && !re->isDown){
   re->neighborCountDown -= advCycle;
   printf("Time limit for neighbor %d : %d\n", re->nodeId, re->neighborCountDown);
   if( re->neighborCountDown == 0 ){
   char* sendBuf = createPacket(re->numLinks, re->numFiles);
   char* ptr = sendBuf;
   ptr = addHeader(sendBuf,1,0, re->nodeId, re->seqNumReceive, re->numLinks, re->numFiles);
   printf("**On behalf of %d", re->nodeId);
   node* curr2 = re->neighbors->head;
   while( curr2 != ((void *)0) ){
    int* id = (int* )curr2->data;
     addInt(*id, ptr);
    ptr += sizeof(int);
    curr2 = curr2->next;
   }
   curr2 = re->objects->head;
   while( curr2 != ((void *)0) ){
    char* objectName = (char* )curr2->data;
    printf("**add file %s\n", objectName);
    addString(objectName, ptr);
    ptr+=9;
    curr2 = curr2->next;
   }
   int packetSize = ptr - sendBuf + 1;
   forward(udp, sendBuf, packetSize, re->nodeId, re->nodeId);
   re->isDown = 1;
   routingEntry* me = getRoutingEntry(&routing, mynodeID);
   me->numLinks--;
   printf("Neighbor %d is down\n", re->nodeId);
   }
  }
  else if( (!re->isNeighbor) && (re->nodeId != mynodeID)){
   re->LSACountDown -= advCycle;
   printf("Time limit for LSA from node %d : %d\n", re->nodeId, re->LSACountDown);
   if ( re->LSACountDown == 0){
    deleteRoutingEntry( re->nodeId );
   }
  }
  curr = curr->next;
 }
}

canonical_original_code:
void countDown(int udp){
 struct node_s *curr = routing.head;
 while( curr != ((void *)0) ){
  struct re *re = (routingEntry* )curr->data;
  if( re->isNeighbor && !re->isDown){
   re->neighborCountDown -= advCycle;
   printf("Time limit for neighbor %d : %d\n", re->nodeId, re->neighborCountDown);
   if( re->neighborCountDown == 0 ){
   char *sendBuf = createPacket(re->numLinks, re->numFiles);
   char *ptr = sendBuf;
   ptr = addHeader(sendBuf,1,0, re->nodeId, re->seqNumReceive, re->numLinks, re->numFiles);
   printf("**On behalf of %d", re->nodeId);
   struct node_s *curr2 = re->neighbors->head;
   while( curr2 != ((void *)0) ){
    int *id = (int* )curr2->data;
     addInt(*id, ptr);
    ptr += sizeof(int);
    curr2 = curr2->next;
   }
   curr2 = re->objects->head;
   while( curr2 != ((void *)0) ){
    char *objectName = (char* )curr2->data;
    printf("**add file %s\n", objectName);
    addString(objectName, ptr);
    ptr+=9;
    curr2 = curr2->next;
   }
   int packetSize = ptr - sendBuf + 1;
   forward(udp, sendBuf, packetSize, re->nodeId, re->nodeId);
   re->isDown = 1;
   struct re *me = getRoutingEntry(&routing, mynodeID);
   me->numLinks--;
   printf("Neighbor %d is down\n", re->nodeId);
   }
  }
  else if( (!re->isNeighbor) && (re->nodeId != mynodeID)){
   re->LSACountDown -= advCycle;
   printf("Time limit for LSA from node %d : %d\n", re->nodeId, re->LSACountDown);
   if ( re->LSACountDown == 0){
    deleteRoutingEntry( re->nodeId );
   }
  }
  curr = curr->next;
 }
}

variable_types: udp int

variable_types: struct re { int nodeId; int nextHop; struct list { struct node_s { void *data; struct node_s *next; } *head; struct node_s *tail; } *neighbors; struct list *objects; struct re *parent; int visited; char *hostName; int routingPort; int localPort; int serverPort; int isNeighbor; int seqNumReceive; int ttl; int numFiles; int numLinks; 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]; } cli_addr; int neighborCountDown; int LSACountDown; int isDown; } *


printLinkEnt

decompiled_code:
int __fastcall printLinkEnt(__int64 a1, int a2)
{
__int64 v2; // rbp
__int64 i; // rbx
__int64 v4; // rdx
__int64 v5; // rsi
int result; // eax

if ( a2 > 0 )
{
v2 = a2;
for ( i = 0LL; i != v2; ++i )
{
v4 = *(unsigned int *)(a1 + 4 * i);
v5 = (unsigned int)i;
result = printf("link entry %d is %d", v5, v4);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func15(__int64 a1, int a2)
{
__int64 v2; // rbp
__int64 i; // rbx
__int64 v4; // rdx
__int64 v5; // rsi
int result; // eax

if ( a2 > 0 )
{
v2 = a2;
for ( i = 0LL; i != v2; ++i )
{
v4 = *(unsigned int *)(a1 + 4 * i);
v5 = (unsigned int)i;
result = printf("link entry %d is %d", v5, v4);
}
}
return result;
}

original_code:
void printLinkEnt(char* buf, int numLinks){
 int i;
 int* intArr = (int *)buf;
 for(i = 0; i < numLinks; i++){
  printf("link entry %d is %d",i,intArr[i]);
 }
}

canonical_original_code:
void printLinkEnt(char *buf, int numLinks){
 int i;
 int *intArr = (int *)buf;
 for(i = 0; i < numLinks; i++){
  printf("link entry %d is %d",i,intArr[i]);
 }
}

variable_types:
buf
char *

variable_types: i int

variable_types:
intArr
int *


printFileEnt

decompiled_code:
int __fastcall printFileEnt(const char *a1, int a2)
{
unsigned int i; // ebx
int result; // eax

if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
{
result = printf("file entry %d is %s", i, a1);
a1 += 9;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func16(const char *a1, int a2)
{
unsigned int i; // ebx
int result; // eax

if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
{
result = printf("file entry %d is %s", i, a1);
a1 += 9;
}
}
return result;
}

original_code:
void printFileEnt(char* buf, int numFiles){
 int i;
 for(i = 0; i < numFiles; i++){
  printf("file entry %d is %s",i,buf + 9*i);
 }
}

canonical_original_code:
void printFileEnt(char *buf, int numFiles){
 int i;
 for(i = 0; i < numFiles; i++){
  printf("file entry %d is %s",i,buf + 9*i);
 }
}


getFileEntry

decompiled_code:
const char **__fastcall getFileEntry(__int64 *a1, const char *a2)
{
__int64 v2; // rbx
const char **v3; // r12

v2 = *a1;
if ( !*a1 )
return 0LL;
while ( 1 )
{
v3 = *(const char ***)v2;
if ( !strcmp(**(const char ***)v2, a2) )
break;
v2 = *(_QWORD *)(v2 + 8);
if ( !v2 )
return 0LL;
}
return v3;
}

canonical_decompiled_code:
const char **__fastcall func1(__int64 *a1, const char *a2)
{
__int64 v2; // rbx
const char **v3; // r12

v2 = *a1;
if ( !*a1 )
return 0LL;
while ( 1 )
{
v3 = *(const char ***)v2;
if ( !strcmp(**(const char ***)v2, a2) )
break;
v2 = *(_QWORD *)(v2 + 8);
if ( !v2 )
return 0LL;
}
return v3;
}

original_code:
fileEntry* getFileEntry(linkedList* list, char* obj){
 node* curr;
 curr = list->head;
 while( curr != ((void *)0) ){
  fileEntry* fe = (fileEntry*)curr->data;
  if ( strcmp(fe->objectName, obj) == 0){
   return fe;
  }
  curr = curr->next;
 }
 return ((void *)0);
}

canonical_original_code:
struct fe *getFileEntry(struct list *list, char *obj){
 struct node_s *curr;
 curr = list->head;
 while( curr != ((void *)0) ){
  struct fe *fe = (fileEntry*)curr->data;
  if ( strcmp(fe->objectName, obj) == 0){
   return fe;
  }
  curr = curr->next;
 }
 return ((void *)0);
}

variable_types: struct list { struct node_s { void *data; struct node_s *next; } *head; struct node_s *tail; } *

variable_types:
obj
char *

variable_types: struct fe { char *objectName; char *path; } *


containObject

decompiled_code:
__int64 __fastcall containObject(__int64 *a1, const char *a2)
{
__int64 v2; // rbx

v2 = *a1;
if ( !*a1 )
return 0LL;
while ( strcmp(*(const char **)v2, a2) )
{
v2 = *(_QWORD *)(v2 + 8);
if ( !v2 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 *a1, const char *a2)
{
__int64 v2; // rbx

v2 = *a1;
if ( !*a1 )
return 0LL;
while ( strcmp(*(const char **)v2, a2) )
{
v2 = *(_QWORD *)(v2 + 8);
if ( !v2 )
return 0LL;
}
return 1LL;
}

original_code:
int containObject(linkedList* list, char* obj){
 node* curr = list->head;
 while( curr != ((void *)0) ){
  char* objName = (char*)curr->data;
  if( strcmp(objName, obj) == 0){
   return 1;
  }
  curr = curr->next;
 }
 return 0;
}

canonical_original_code:
int containObject(struct list *list, char *obj){
 struct node_s *curr = list->head;
 while( curr != ((void *)0) ){
  char *objName = (char*)curr->data;
  if( strcmp(objName, obj) == 0){
   return 1;
  }
  curr = curr->next;
 }
 return 0;
}

variable_types:
objName
char *


getFileFromOther

decompiled_code:
__int64 __fastcall getFileFromOther(_QWORD **a1, const char *a2)
{
_QWORD *v2; // rbx
__int64 v3; // r12

v2 = *a1;
if ( !*a1 )
return 0LL;
while ( 1 )
{
v3 = *v2;
if ( (unsigned int)containObject(*(__int64 **)(*v2 + 16LL), a2) )
break;
v2 = (_QWORD *)v2[1];
if ( !v2 )
return 0LL;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD **a1, const char *a2)
{
_QWORD *v2; // rbx
__int64 v3; // r12

v2 = *a1;
if ( !*a1 )
return 0LL;
while ( 1 )
{
v3 = *v2;
if ( (unsigned int)func2(*(__int64 **)(*v2 + 16LL), a2) )
break;
v2 = (_QWORD *)v2[1];
if ( !v2 )
return 0LL;
}
return v3;
}

original_code:
routingEntry* getFileFromOther(linkedList* list, char* obj){
 node* curr = list->head;
 while( curr != ((void *)0) ){
  routingEntry* re = (routingEntry*)curr->data;
  if( containObject(re->objects, obj)){
   return re;
  }
  curr = curr->next;
 }
 return ((void *)0);
}

canonical_original_code:
struct re *getFileFromOther(struct list *list, char *obj){
 struct node_s *curr = list->head;
 while( curr != ((void *)0) ){
  struct re *re = (routingEntry*)curr->data;
  if( containObject(re->objects, obj)){
   return re;
  }
  curr = curr->next;
 }
 return ((void *)0);
}

variable_types:
list
struct list *

return_type: struct re { int nodeId; int nextHop; struct list { struct node_s { void *data; struct node_s *next; } *head; struct node_s *tail; } *neighbors; struct list *objects; struct re *parent; int visited; char *hostName; int routingPort; int localPort; int serverPort; int isNeighbor; int seqNumReceive; int ttl; int numFiles; int numLinks; 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]; } cli_addr; int neighborCountDown; int LSACountDown; int isDown; } *


freeNode

decompiled_code:
__int64 __fastcall freeNode(void *ptr)
{
__int64 v1; // r12
void *v3; // rdi

if ( !ptr )
return 0LL;
v1 = *((_QWORD *)ptr + 1);
v3 = *(void **)ptr;
if ( v3 )
free(v3);
free(ptr);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func4(void *ptr)
{
__int64 v1; // r12
void *v3; // rdi

if ( !ptr )
return 0LL;
v1 = *((_QWORD *)ptr + 1);
v3 = *(void **)ptr;
if ( v3 )
free(v3);
free(ptr);
return v1;
}

original_code:
node* freeNode(node* n){
 node* next;
 next = ((void *)0);
 if ( n != ((void *)0) ){
  next = n->next;
  if( n->data != ((void *)0) ){
   free(n->data);
  }
  free(n);
 }
 return next;
}

canonical_original_code:
struct node_s *freeNode(struct node_s *n){
 struct node_s *next;
 next = ((void *)0);
 if ( n != ((void *)0) ){
  next = n->next;
  if( n->data != ((void *)0) ){
   free(n->data);
  }
  free(n);
 }
 return next;
}

variable_types:
n
struct node_s *

return_type: struct node_s { void *data; struct node_s *next; } *


deleteRoutingEntry

decompiled_code:
void __fastcall deleteRoutingEntry(int a1)
{
_QWORD *v1; // r8
_QWORD *v3; // rdi
__int64 v4; // rax
void *v5; // rdi

v1 = routing;
if ( **(_DWORD **)routing == a1 )
{
if ( *(&routing + 1) == routing )
{
free(routing);
routing = 0LL;
*(&routing + 1) = 0LL;
}
else
{
v5 = routing;
routing = (void *)*((_QWORD *)routing + 1);
free(v5);
}
}
else
{
v3 = (_QWORD *)*((_QWORD *)routing + 1);
if ( v3 )
{
while ( 1 )
{
v4 = v3[1];
if ( *(_DWORD *)*v3 == a1 )
break;
v1 = v3;
if ( !v4 )
return;
v3 = (_QWORD *)v3[1];
}
v1[1] = v4;
if ( !v4 )
*(&routing + 1) = v1;
v3[1] = 0LL;
freeNode(v3);
}
}
}

canonical_decompiled_code:
void __fastcall func5(int a1)
{
_QWORD *v1; // r8
_QWORD *v3; // rdi
__int64 v4; // rax
void *v5; // rdi

v1 = routing;
if ( **(_DWORD **)routing == a1 )
{
if ( *(&routing + 1) == routing )
{
free(routing);
routing = 0LL;
*(&routing + 1) = 0LL;
}
else
{
v5 = routing;
routing = (void *)*((_QWORD *)routing + 1);
free(v5);
}
}
else
{
v3 = (_QWORD *)*((_QWORD *)routing + 1);
if ( v3 )
{
while ( 1 )
{
v4 = v3[1];
if ( *(_DWORD *)*v3 == a1 )
break;
v1 = v3;
if ( !v4 )
return;
v3 = (_QWORD *)v3[1];
}
v1[1] = v4;
if ( !v4 )
*(&routing + 1) = v1;
v3[1] = 0LL;
func4(v3);
}
}
}

original_code:
void deleteRoutingEntry(int nodeId){
 node* head = routing.head;
 routingEntry* re = (routingEntry*) head->data;
 if( re->nodeId == nodeId ){
  if( routing.head == routing.tail ){
   free(head);
   routing.head = ((void *)0);
   routing.tail = ((void *)0);
  }else{
   routing.head = routing.head->next;
   head->next = ((void *)0);
   free(head);
  }
  return;
 }
 node* curr = routing.head->next;
 node* pre = routing.head;
 while( curr != ((void *)0)){
  re = (routingEntry*) curr->data;
  if( re->nodeId == nodeId ){
   pre->next = curr->next;
   if( curr->next == ((void *)0)){
    routing.tail = pre;
   }
   curr->next = ((void *)0);
   freeNode(curr);
   return;
  }
  pre = curr;
  curr = curr->next;
 }
}

canonical_original_code:
void deleteRoutingEntry(int nodeId){
 struct node_s *head = routing.head;
 struct re *re = (routingEntry*) head->data;
 if( re->nodeId == nodeId ){
  if( routing.head == routing.tail ){
   free(head);
   routing.head = ((void *)0);
   routing.tail = ((void *)0);
  }else{
   routing.head = routing.head->next;
   head->next = ((void *)0);
   free(head);
  }
  return;
 }
 struct node_s *curr = routing.head->next;
 struct node_s *pre = routing.head;
 while( curr != ((void *)0)){
  re = (struct re *) curr->data;
  if( re->nodeId == nodeId ){
   pre->next = curr->next;
   if( curr->next == ((void *)0)){
    routing.tail = pre;
   }
   curr->next = ((void *)0);
   freeNode(curr);
   return;
  }
  pre = curr;
  curr = curr->next;
 }
}

variable_types: nodeId int


printFile

decompiled_code:
int __fastcall printFile(__int64 a1)
{
__int64 v1; // rbx
const char **v2; // rbp
int result; // eax

if ( a1 )
{
v1 = a1;
do
{
v2 = *(const char ***)v1;
puts(**(const char ***)v1);
result = puts(v2[1]);
v1 = *(_QWORD *)(v1 + 8);
}
while ( v1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1)
{
__int64 v1; // rbx
const char **v2; // rbp
int result; // eax

if ( a1 )
{
v1 = a1;
do
{
v2 = *(const char ***)v1;
puts(**(const char ***)v1);
result = puts(v2[1]);
v1 = *(_QWORD *)(v1 + 8);
}
while ( v1 );
}
return result;
}

original_code:
void printFile(linkedList list){
 node* currentp = list.head;
    while(currentp != ((void *)0)){
        fileEntry* entryp = (fileEntry *)currentp->data;
        printf("%s\n",entryp->objectName);
        printf("%s\n",entryp->path);
        currentp = currentp->next;
    }
}

canonical_original_code:
void printFile(struct list list){
 struct node_s *currentp = list.head;
    while(currentp != ((void *)0)){
        struct fe *entryp = (fileEntry *)currentp->data;
        printf("%s\n",entryp->objectName);
        printf("%s\n",entryp->path);
        currentp = currentp->next;
    }
}

variable_types: struct list { struct node_s { void *data; struct node_s *next; } *head; struct node_s *tail; }

user_defined_types: struct fe { char *objectName; char *path; }


printObjects

decompiled_code:
int __fastcall printObjects(__int64 *a1)
{
__int64 v1; // rbx

v1 = *a1;
printf("Objects: ");
for ( ; v1; v1 = *(_QWORD *)(v1 + 8) )
printf("%s ", *(const char **)v1);
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func8(__int64 *a1)
{
__int64 v1; // rbx

v1 = *a1;
printf("Objects: ");
for ( ; v1; v1 = *(_QWORD *)(v1 + 8) )
printf("%s ", *(const char **)v1);
return putchar(10);
}

original_code:
void printObjects(linkedList* list){
 node* currentp = list->head;
 printf("Objects: ");
    while(currentp != ((void *)0)){
        char* objectName = (char *)currentp->data;
        printf("%s  ",objectName);
        currentp = currentp->next;
    }
 printf("\n");
}

canonical_original_code:
void printObjects(struct list *list){
 struct node_s *currentp = list->head;
 printf("Objects: ");
    while(currentp != ((void *)0)){
        char *objectName = (char *)currentp->data;
        printf("%s  ",objectName);
        currentp = currentp->next;
    }
 printf("\n");
}

variable_types:
objectName
char *


printLinks

decompiled_code:
int __fastcall printLinks(unsigned int ***a1)
{
unsigned int **v1; // rbx

v1 = *a1;
printf("Neighbors: ");
for ( ; v1; v1 = (unsigned int **)v1[1] )
printf("%d ", **v1);
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func9(unsigned int ***a1)
{
unsigned int **v1; // rbx

v1 = *a1;
printf("Neighbors: ");
for ( ; v1; v1 = (unsigned int **)v1[1] )
printf("%d ", **v1);
return putchar(10);
}

original_code:
void printLinks(linkedList* list){
 node* currentp = list->head;
 printf("Neighbors: ");
    while(currentp != ((void *)0)){
        int* id = (int *)currentp->data;
        printf("%d  ",*id);
        currentp = currentp->next;
    }
 printf("\n");
}

canonical_original_code:
void printLinks(struct list *list){
 struct node_s *currentp = list->head;
 printf("Neighbors: ");
    while(currentp != ((void *)0)){
        int *id = (int *)currentp->data;
        printf("%d  ",*id);
        currentp = currentp->next;
    }
 printf("\n");
}

variable_types:
id
int *


printRouting

decompiled_code:
int __fastcall printRouting(_QWORD *a1)
{
_QWORD *v1; // rbp
unsigned int *v2; // rax
unsigned int *v3; // rbx
__int64 v4; // rsi

v1 = a1;
puts("\n--------------ROUTING TABLE-------------");
if ( a1 )
{
do
{
v3 = (unsigned int *)*v1;
if ( !*(_DWORD *)(*v1 + 104LL) )
{
v4 = *v3;
if ( (_DWORD)v4 == mynodeID )
printf("*Node %d, ", v4);
else
printf("Node %d, ", v4);
printf("nextHop %d, ", v3[1]);
printf("isDown %d, ", v3[26]);
printf("isVisited %d, ", v3[8]);
v2 = (unsigned int *)*((_QWORD *)v3 + 3);
if ( v2 )
printf("parentNode: %d\n", *v2);
else
puts("parent: unknown");
printObjects(*((__int64 **)v3 + 2));
printLinks(*((unsigned int ****)v3 + 1));
}
v1 = (_QWORD *)v1[1];
}
while ( v1 );
}
return puts("----------------------------------------\n");
}

canonical_decompiled_code:
int __fastcall func10(_QWORD *a1)
{
_QWORD *v1; // rbp
unsigned int *v2; // rax
unsigned int *v3; // rbx
__int64 v4; // rsi

v1 = a1;
puts("\n--------------ROUTING TABLE-------------");
if ( a1 )
{
do
{
v3 = (unsigned int *)*v1;
if ( !*(_DWORD *)(*v1 + 104LL) )
{
v4 = *v3;
if ( (_DWORD)v4 == mynodeID )
printf("*Node %d, ", v4);
else
printf("Node %d, ", v4);
printf("nextHop %d, ", v3[1]);
printf("isDown %d, ", v3[26]);
printf("isVisited %d, ", v3[8]);
v2 = (unsigned int *)*((_QWORD *)v3 + 3);
if ( v2 )
printf("parentNode: %d\n", *v2);
else
puts("parent: unknown");
func8(*((__int64 **)v3 + 2));
func9(*((unsigned int ****)v3 + 1));
}
v1 = (_QWORD *)v1[1];
}
while ( v1 );
}
return puts("----------------------------------------\n");
}

original_code:
void printRouting(linkedList list){
    node* currentp = list.head;
 printf("\n--------------ROUTING TABLE-------------\n");
    while( currentp != ((void *)0) ){
        routingEntry* entryp = (routingEntry *)currentp->data;
  if( !entryp->isDown){
  if( entryp->nodeId == mynodeID){
   printf("*Node %d, ", entryp->nodeId);
  }else{
   printf("Node %d, ", entryp->nodeId);
  }
  printf("nextHop %d, ", entryp->nextHop);
  printf("isDown %d, ", entryp->isDown);
  printf("isVisited %d, ", entryp->visited);
  if( entryp->parent == ((void *)0) ){
   printf("parent: unknown\n");
  }else{
   printf("parentNode: %d\n", entryp->parent->nodeId);
  }
  printObjects(entryp->objects);
  printLinks(entryp->neighbors);
 }
        currentp = currentp->next;
    }
 printf("----------------------------------------\n\n");
}

canonical_original_code:
void printRouting(struct list list){
    struct node_s *currentp = list.head;
 printf("\n--------------ROUTING TABLE-------------\n");
    while( currentp != ((void *)0) ){
        struct re *entryp = (routingEntry *)currentp->data;
  if( !entryp->isDown){
  if( entryp->nodeId == mynodeID){
   printf("*Node %d, ", entryp->nodeId);
  }else{
   printf("Node %d, ", entryp->nodeId);
  }
  printf("nextHop %d, ", entryp->nextHop);
  printf("isDown %d, ", entryp->isDown);
  printf("isVisited %d, ", entryp->visited);
  if( entryp->parent == ((void *)0) ){
   printf("parent: unknown\n");
  }else{
   printf("parentNode: %d\n", entryp->parent->nodeId);
  }
  printObjects(entryp->objects);
  printLinks(entryp->neighbors);
 }
        currentp = currentp->next;
    }
 printf("----------------------------------------\n\n");
}


printRoutingEntry

decompiled_code:
int __fastcall printRoutingEntry(unsigned int *a1)
{
printf("NodeId: %d\n", *a1);
printf("TTL: %d\n", a1[17]);
printf("Seq Num received: %d\n", a1[16]);
printf("Number of files: %d\n", a1[18]);
return printf("Number of links: %d\n", a1[19]);
}

canonical_decompiled_code:
int __fastcall func11(unsigned int *a1)
{
printf("NodeId: %d\n", *a1);
printf("TTL: %d\n", a1[17]);
printf("Seq Num received: %d\n", a1[16]);
printf("Number of files: %d\n", a1[18]);
return printf("Number of links: %d\n", a1[19]);
}

original_code:
void printRoutingEntry(routingEntry* re){
 printf("NodeId: %d\n", re->nodeId);
 printf("TTL: %d\n", re->ttl);
 printf("Seq Num received: %d\n", re->seqNumReceive);
 printf("Number of files: %d\n", re->numFiles);
 printf("Number of links: %d\n", re->numLinks);
}

canonical_original_code:
void printRoutingEntry(struct re *re){
 printf("NodeId: %d\n", re->nodeId);
 printf("TTL: %d\n", re->ttl);
 printf("Seq Num received: %d\n", re->seqNumReceive);
 printf("Number of files: %d\n", re->numFiles);
 printf("Number of links: %d\n", re->numLinks);
}


resolvNeighbor

decompiled_code:
__int64 __fastcall resolvNeighbor(__int64 a1)
{
const char ***v1; // rbx
const char **v2; // rbp
char *v3; // rax

v1 = (const char ***)routing;
if ( !routing )
return 0xFFFFFFFFLL;
while ( 1 )
{
v2 = *v1;
if ( *((_DWORD *)*v1 + 15) )
{
v3 = inet_ntoa(*(struct in_addr *)((char *)&a1 + 4));
if ( !strcmp(v2[5], v3) && *((_DWORD *)v2 + 12) == (unsigned __int16)_bswap_16(SWORD1(a1)) )
break;
}
v1 = (const char ***)v1[1];
if ( !v1 )
return 0xFFFFFFFFLL;
}
return *(unsigned int *)v2;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
const char ***v1; // rbx
const char **v2; // rbp
char *v3; // rax

v1 = (const char ***)routing;
if ( !routing )
return 0xFFFFFFFFLL;
while ( 1 )
{
v2 = *v1;
if ( *((_DWORD *)*v1 + 15) )
{
v3 = inet_ntoa(*(struct in_addr *)((char *)&a1 + 4));
if ( !strcmp(v2[5], v3) && *((_DWORD *)v2 + 12) == (unsigned __int16)func0(SWORD1(a1)) )
break;
}
v1 = (const char ***)v1[1];
if ( !v1 )
return 0xFFFFFFFFLL;
}
return *(unsigned int *)v2;
}

original_code:
int resolvNeighbor(struct sockaddr_in cli_addr){
 node* curr = routing.head;
 while( curr != ((void *)0)){
  routingEntry* re = (routingEntry *)curr->data;
  if( re->isNeighbor){
   if( strcmp(re->hostName, inet_ntoa(cli_addr.sin_addr)) == 0 && re->routingPort ==ntohs(cli_addr.sin_port) ){
    return re->nodeId;
   }
  }
  curr = curr->next;
 }
 return -1;
}

canonical_original_code:
int resolvNeighbor(struct sockaddr_in cli_addr){
 struct node_s *curr = routing.head;
 while( curr != ((void *)0)){
  struct re *re = (routingEntry *)curr->data;
  if( re->isNeighbor){
   if( strcmp(re->hostName, inet_ntoa(cli_addr.sin_addr)) == 0 && re->routingPort ==ntohs(cli_addr.sin_port) ){
    return re->nodeId;
   }
  }
  curr = curr->next;
 }
 return -1;
}

variable_types: 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]; }


decreaseTTL

decompiled_code:
__int64 *decreaseTTL()
{
__int64 *result; // rax
__int64 v1; // rdx

result = (__int64 *)routing;
if ( routing )
{
do
{
v1 = *result;
result = (__int64 *)result[1];
--*(_DWORD *)(v1 + 68);
}
while ( result );
}
return result;
}

canonical_decompiled_code:
__int64 *func13()
{
__int64 *result; // rax
__int64 v1; // rdx

result = (__int64 *)routing;
if ( routing )
{
do
{
v1 = *result;
result = (__int64 *)result[1];
--*(_DWORD *)(v1 + 68);
}
while ( result );
}
return result;
}

original_code:
void decreaseTTL(){
 node* curr = routing.head;
 while ( curr != ((void *)0) ){
  routingEntry* entryp = (routingEntry *)curr->data;
  entryp->ttl -= 1;
  curr = curr->next;
 }
}

canonical_original_code:
void decreaseTTL(){
 struct node_s *curr = routing.head;
 while ( curr != ((void *)0) ){
  struct re *entryp = (routingEntry *)curr->data;
  entryp->ttl -= 1;
  curr = curr->next;
 }
}

variable_types: struct node_s { void *data; struct node_s *next; } *


decompiled_code:
int __fastcall close_socket(int a1)
{
int result; // eax

result = close(a1);
if ( result )
{
fwrite("Failed closing socket.\n", 1uLL, 0x17uLL, stderr);
result = 1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func14(int a1)
{
int result; // eax

result = close(a1);
if ( result )
{
fwrite("Failed closing socket.\n", 1uLL, 0x17uLL, stderr);
result = 1;
}
return result;
}

original_code:
int close_socket(int sock)
{
    if (close(sock))
    {
        fprintf(stderr, "Failed closing socket.\n");
        return 1;
    }
    return 0;
}

variable_types: sock int


computeNextHop

decompiled_code:
__int64 __fastcall computeNextHop(unsigned int *a1, int a2)
{
unsigned int *v2; // rax

a1[8] = 0;
do
{
v2 = a1;
a1 = (unsigned int *)*((_QWORD *)a1 + 3);
if ( !a1 )
return 0xFFFFFFFFLL;
}
while ( *a1 != a2 );
return *v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int *a1, int a2)
{
unsigned int *v2; // rax

a1[8] = 0;
do
{
v2 = a1;
a1 = (unsigned int *)*((_QWORD *)a1 + 3);
if ( !a1 )
return 0xFFFFFFFFLL;
}
while ( *a1 != a2 );
return *v2;
}

original_code:
int computeNextHop(routingEntry* destination,int srcId){
 destination->visited = 0;
 routingEntry* curr = destination;
 while( (curr->parent) && (curr->parent->nodeId != srcId )){
  curr = curr->parent;
 }
 if(curr->parent == ((void *)0)){
  return -1;
 }
 return curr->nodeId;
}

canonical_original_code:
int computeNextHop(struct re *destination, int srcId){
 destination->visited = 0;
 struct re *curr = destination;
 while( (curr->parent) && (curr->parent->nodeId != srcId )){
  curr = curr->parent;
 }
 if(curr->parent == ((void *)0)){
  return -1;
 }
 return curr->nodeId;
}

variable_types: struct re { int nodeId; int nextHop; struct list { struct node_s { void *data; struct node_s *next; } *head; struct node_s *tail; } *neighbors; struct list *objects; struct re *parent; int visited; char *hostName; int routingPort; int localPort; int serverPort; int isNeighbor; int seqNumReceive; int ttl; int numFiles; int numLinks; 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]; } cli_addr; int neighborCountDown; int LSACountDown; int isDown; } *

variable_types: srcId int


popQue

original_code:
routingEntry* popQue(linkedList* que){
 node* temp = que->head;
 if(que->head == que->tail){
  que->head = ((void *)0);
  que->tail = ((void *)0);
 }
 else{
  que->head = que->head->next;
 }
 temp->next = ((void *)0);
 free(temp);
 routingEntry* re = temp->data;
 return re;
}

canonical_original_code:
struct re *popQue(struct list *que){
 struct node_s *temp = que->head;
 if(que->head == que->tail){
  que->head = ((void *)0);
  que->tail = ((void *)0);
 }
 else{
  que->head = que->head->next;
 }
 temp->next = ((void *)0);
 free(temp);
 struct re *re = temp->data;
 return re;
}

variable_types:
que
struct list *


computeParent

decompiled_code:
__int64 __fastcall computeParent(__int64 a1, __int64 a2)
{
__int64 result; // rax
unsigned int *v3; // r13
unsigned int *v4; // rbx
unsigned int *v5; // rbp
__int64 v6[7]; // [rsp+0h] [rbp-38h] BYREF

*(_DWORD *)(a2 + 32) = 1;
*(_QWORD *)(a2 + 24) = 0LL;
v6[0] = 0LL;
v6[1] = 0LL;
result = insert(v6, a2, 112LL);
while ( v6[0] )
{
v3 = (unsigned int *)popQue((__int64)v6);
printf("Pop node %d\n", *v3);
result = *((_QWORD *)v3 + 1);
v4 = *(unsigned int **)result;
if ( *(_QWORD *)result )
{
do
{
result = getRoutingEntry(a1, **(unsigned int **)v4);
v5 = (unsigned int *)result;
if ( result && !*(_DWORD *)(result + 32) )
{
result = *(unsigned int *)(result + 104);
if ( !(_DWORD)result )
{
printf("child id: %d\n", *v5);
*((_QWORD *)v5 + 3) = v3;
v5[8] = 1;
result = insert(v6, v5, 112LL);
}
}
v4 = (unsigned int *)*((_QWORD *)v4 + 1);
}
while ( v4 );
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int64 result; // rax
unsigned int *v3; // r13
unsigned int *v4; // rbx
unsigned int *v5; // rbp
__int64 v6[7]; // [rsp+0h] [rbp-38h] BYREF

*(_DWORD *)(a2 + 32) = 1;
*(_QWORD *)(a2 + 24) = 0LL;
v6[0] = 0LL;
v6[1] = 0LL;
result = insert(v6, a2, 112LL);
while ( v6[0] )
{
v3 = (unsigned int *)func2((__int64)v6);
printf("Pop node %d\n", *v3);
result = *((_QWORD *)v3 + 1);
v4 = *(unsigned int **)result;
if ( *(_QWORD *)result )
{
do
{
result = getRoutingEntry(a1, **(unsigned int **)v4);
v5 = (unsigned int *)result;
if ( result && !*(_DWORD *)(result + 32) )
{
result = *(unsigned int *)(result + 104);
if ( !(_DWORD)result )
{
printf("child id: %d\n", *v5);
*((_QWORD *)v5 + 3) = v3;
v5[8] = 1;
result = insert(v6, v5, 112LL);
}
}
v4 = (unsigned int *)*((_QWORD *)v4 + 1);
}
while ( v4 );
}
}
return result;
}

original_code:
void computeParent(linkedList* rTable, routingEntry* sourcep){
 linkedList que;
 que.head = ((void *)0);
 que.tail = ((void *)0);
 sourcep->visited = 1;
 sourcep->parent = ((void *)0);
 insert(&que, sourcep, sizeof(routingEntry));
 while(que.head != ((void *)0)){
  routingEntry* cur = popQue(&que);
  printf("Pop node %d\n", cur->nodeId);
  node* child = cur->neighbors->head;
  while(child != ((void *)0)){
   routingEntry* childEntry = getRoutingEntry(rTable, *(int *)child->data);
   if((childEntry) && (childEntry->visited == 0) && (!childEntry->isDown)){
    printf("child id: %d\n", childEntry->nodeId);
    childEntry->parent = cur;
    childEntry->visited = 1;
    insert(&que, childEntry, sizeof(routingEntry));
   }
   child = child->next;
  }
 }
}

canonical_original_code:
void computeParent(struct list *rTable, struct re *sourcep){
 struct list que;
 que.head = ((void *)0);
 que.tail = ((void *)0);
 sourcep->visited = 1;
 sourcep->parent = ((void *)0);
 insert(&que, sourcep, sizeof(routingEntry));
 while(que.head != ((void *)0)){
  struct re *cur = popQue(&que);
  printf("Pop node %d\n", cur->nodeId);
  struct node_s *child = cur->neighbors->head;
  while(child != ((void *)0)){
   struct re *childEntry = getRoutingEntry(rTable, *(int *)child->data);
   if((childEntry) && (childEntry->visited == 0) && (!childEntry->isDown)){
    printf("child id: %d\n", childEntry->nodeId);
    childEntry->parent = cur;
    childEntry->visited = 1;
    insert(&que, childEntry, sizeof(routingEntry));
   }
   child = child->next;
  }
 }
}

variable_types: struct re { int nodeId; int nextHop; struct list *neighbors; struct list *objects; struct re *parent; int visited; char *hostName; int routingPort; int localPort; int serverPort; int isNeighbor; int seqNumReceive; int ttl; int numFiles; int numLinks; 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]; } cli_addr; int neighborCountDown; int LSACountDown; int isDown; } *


main

canonical_name: main

repo: dsiroky/phpchroot

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbp
char *v4; // rax

v3 = getenv("PHPCFG_EXE");
v4 = getenv("PHPCFG_CFG");
if ( v3 && v4 )
execl(v3, v3, "-c", v4, 0LL);
else
printf("Content-type: text/html\n\ncfgerror\n%s\n%s", v3, v4);
return 0;
}

original_code:
int main(int argc, char **argv)
{
  char *phpexe = getenv("PHPCFG_EXE");
  char *phpcfg = getenv("PHPCFG_CFG");
  if ((phpexe == ((void *)0)) || (phpcfg == ((void *)0)))
  {
    printf("Content-type: text/html\n\ncfgerror\n%s\n%s", phpexe, phpcfg);
    return 0;
  }
  execl(phpexe, phpexe, "-c", phpcfg, ((void *)0));
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
phpexe
char *

variable_types:
phpcfg
char *


ccdprocparam

repo: dstndstn/dolphot

decompiled_code:
__int64 __fastcall ccdprocparam(char *s1, char *src)
{
unsigned int v2; // er12
__int64 result; // rax
char *endptr; // [rsp+8h] [rbp-20h] BYREF

if ( !strcasecmp(s1, "imager") )
{
strcpy(imager, src);
result = 1LL;
}
else if ( !strcasecmp(s1, "typekw") )
{
strcpy(typekw, src);
result = 1LL;
}
else if ( !strcasecmp(s1, "filtkw") )
{
strcpy(filtkw, src);
result = 1LL;
}
else if ( !strcasecmp(s1, "oversec") )
{
strcpy(oversec, src);
result = 1LL;
}
else if ( !strcasecmp(s1, "zerobase") )
{
strcpy(zerobase, src);
result = 1LL;
}
else if ( !strcasecmp(s1, "darkbase") )
{
strcpy(darkbase, src);
result = 1LL;
}
else if ( !strcasecmp(s1, "darktime") )
{
strcpy(darktime, src);
result = 1LL;
}
else if ( !strcasecmp(s1, "flatbase") )
{
strcpy(flatbase, src);
result = 1LL;
}
else if ( !strcasecmp(s1, "trimsec") )
{
strcpy(trimsec, src);
result = 1LL;
}
else if ( !strcasecmp(s1, "datasec") )
{
strcpy(datasec, src);
result = 1LL;
}
else if ( !strcasecmp(s1, "ccdsize") )
{
strcpy(ccdsize, src);
result = 1LL;
}
else if ( !strcasecmp(s1, "ccdsec") )
{
strcpy(ccdsec, src);
result = 1LL;
}
else if ( !strcasecmp(s1, "detsec") )
{
strcpy(detsec, src);
result = 1LL;
}
else
{
v2 = strtol(src, &endptr, 10);
if ( !*endptr )
{
if ( !strcasecmp(s1, "SPECIAL") )
{
SPECIAL = v2;
if ( v2 <= 1 )
return 1LL;
LABEL_34:
perr("Mask image must be 0 or 1");
}
if ( !strcasecmp(s1, "MASK") )
{
MASK = v2;
if ( v2 <= 1 )
return 1LL;
goto LABEL_34;
}
if ( !strcasecmp(s1, "OVERSCAN") )
{
OVERSCAN = v2;
if ( v2 > 2 )
perr("Overscan correction must be 0, 1, or 2");
return 1LL;
}
if ( !strcasecmp(s1, "ZERO") )
{
ZERO = v2;
if ( v2 > 1 )
perr("Zero correction must be 0 or 1");
return 1LL;
}
if ( !strcasecmp(s1, "DARK") )
{
DARK = v2;
if ( v2 > 1 )
perr("Dark correction must be 0 or 1");
return 1LL;
}
if ( !strcasecmp(s1, "FLAT") )
{
FLAT = v2;
if ( v2 > 1 )
perr("Flat correction must be 0 or 1");
return 1LL;
}
if ( !strcasecmp(s1, "TRIM") )
{
TRIM = v2;
if ( v2 > 1 )
perr("Trim image must be 0 or 1");
return 1LL;
}
if ( !strcasecmp(s1, "MERGEAMP") )
{
MERGEAMP = v2;
if ( v2 > 1 )
perr("Merge amplifiers must be 0 or 1");
return 1LL;
}
}
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s1, char *src)
{
unsigned int v2; // er12
__int64 result; // rax
char *endptr; // [rsp+8h] [rbp-20h] BYREF

if ( !strcasecmp(s1, "imager") )
{
strcpy(imager, src);
result = 1LL;
}
else if ( !strcasecmp(s1, "typekw") )
{
strcpy(typekw, src);
result = 1LL;
}
else if ( !strcasecmp(s1, "filtkw") )
{
strcpy(filtkw, src);
result = 1LL;
}
else if ( !strcasecmp(s1, "oversec") )
{
strcpy(oversec, src);
result = 1LL;
}
else if ( !strcasecmp(s1, "zerobase") )
{
strcpy(zerobase, src);
result = 1LL;
}
else if ( !strcasecmp(s1, "darkbase") )
{
strcpy(darkbase, src);
result = 1LL;
}
else if ( !strcasecmp(s1, "darktime") )
{
strcpy(darktime, src);
result = 1LL;
}
else if ( !strcasecmp(s1, "flatbase") )
{
strcpy(flatbase, src);
result = 1LL;
}
else if ( !strcasecmp(s1, "trimsec") )
{
strcpy(trimsec, src);
result = 1LL;
}
else if ( !strcasecmp(s1, "datasec") )
{
strcpy(datasec, src);
result = 1LL;
}
else if ( !strcasecmp(s1, "ccdsize") )
{
strcpy(ccdsize, src);
result = 1LL;
}
else if ( !strcasecmp(s1, "ccdsec") )
{
strcpy(ccdsec, src);
result = 1LL;
}
else if ( !strcasecmp(s1, "detsec") )
{
strcpy(detsec, src);
result = 1LL;
}
else
{
v2 = strtol(src, &endptr, 10);
if ( !*endptr )
{
if ( !strcasecmp(s1, "SPECIAL") )
{
SPECIAL = v2;
if ( v2 <= 1 )
return 1LL;
LABEL_34:
func0("Mask image must be 0 or 1");
}
if ( !strcasecmp(s1, "MASK") )
{
MASK = v2;
if ( v2 <= 1 )
return 1LL;
goto LABEL_34;
}
if ( !strcasecmp(s1, "OVERSCAN") )
{
OVERSCAN = v2;
if ( v2 > 2 )
func0("Overscan correction must be 0, 1, or 2");
return 1LL;
}
if ( !strcasecmp(s1, "ZERO") )
{
ZERO = v2;
if ( v2 > 1 )
func0("Zero correction must be 0 or 1");
return 1LL;
}
if ( !strcasecmp(s1, "DARK") )
{
DARK = v2;
if ( v2 > 1 )
func0("Dark correction must be 0 or 1");
return 1LL;
}
if ( !strcasecmp(s1, "FLAT") )
{
FLAT = v2;
if ( v2 > 1 )
func0("Flat correction must be 0 or 1");
return 1LL;
}
if ( !strcasecmp(s1, "TRIM") )
{
TRIM = v2;
if ( v2 > 1 )
func0("Trim image must be 0 or 1");
return 1LL;
}
if ( !strcasecmp(s1, "MERGEAMP") )
{
MERGEAMP = v2;
if ( v2 > 1 )
func0("Merge amplifiers must be 0 or 1");
return 1LL;
}
}
result = 0LL;
}
return result;
}

original_code:
int ccdprocparam(char*var,char*val) {
   int i;
   char *ptr;
   if (!strcasecmp(var,"imager")) {strcpy(imager,val); return 1;}
   if (!strcasecmp(var,"typekw")) {strcpy(typekw,val); return 1;}
   if (!strcasecmp(var,"filtkw")) {strcpy(filtkw,val); return 1;}
   if (!strcasecmp(var,"oversec")) {strcpy(oversec,val); return 1;}
   if (!strcasecmp(var,"zerobase")) {strcpy(zerobase,val); return 1;}
   if (!strcasecmp(var,"darkbase")) {strcpy(darkbase,val); return 1;}
   if (!strcasecmp(var,"darktime")) {strcpy(darktime,val); return 1;}
   if (!strcasecmp(var,"flatbase")) {strcpy(flatbase,val); return 1;}
   if (!strcasecmp(var,"trimsec")) {strcpy(trimsec,val); return 1;}
   if (!strcasecmp(var,"datasec")) {strcpy(datasec,val); return 1;}
   if (!strcasecmp(var,"ccdsize")) {strcpy(ccdsize,val); return 1;}
   if (!strcasecmp(var,"ccdsec")) {strcpy(ccdsec,val); return 1;}
   if (!strcasecmp(var,"detsec")) {strcpy(detsec,val); return 1;}
   i=strtol(val,&ptr,10);
   if (!*ptr) {
      if (!strcasecmp(var,"SPECIAL")) {SPECIAL=i; if (SPECIAL<0 || SPECIAL>1) perr("Mask image must be 0 or 1"); return 1;}
      if (!strcasecmp(var,"MASK")) {MASK=i; if (MASK<0 || MASK>1) perr("Mask image must be 0 or 1"); return 1;}
      if (!strcasecmp(var,"OVERSCAN")) {OVERSCAN=i; if (OVERSCAN<0 || OVERSCAN>2) perr("Overscan correction must be 0, 1, or 2"); return 1;}
      if (!strcasecmp(var,"ZERO")) {ZERO=i; if (ZERO<0 || ZERO>1) perr("Zero correction must be 0 or 1"); return 1;}
      if (!strcasecmp(var,"DARK")) {DARK=i; if (DARK<0 || DARK>1) perr("Dark correction must be 0 or 1"); return 1;}
      if (!strcasecmp(var,"FLAT")) {FLAT=i; if (FLAT<0 || FLAT>1) perr("Flat correction must be 0 or 1"); return 1;}
      if (!strcasecmp(var,"TRIM")) {TRIM=i; if (TRIM<0 || TRIM>1) perr("Trim image must be 0 or 1"); return 1;}
      if (!strcasecmp(var,"MERGEAMP")) {MERGEAMP=i; if (MERGEAMP<0 || MERGEAMP>1) perr("Merge amplifiers must be 0 or 1"); return 1;}
   }
   return 0;
}

canonical_original_code:
int ccdprocparam(char *var, char *val) {
   int i;
   char *ptr;
   if (!strcasecmp(var,"imager")) {strcpy(imager,val); return 1;}
   if (!strcasecmp(var,"typekw")) {strcpy(typekw,val); return 1;}
   if (!strcasecmp(var,"filtkw")) {strcpy(filtkw,val); return 1;}
   if (!strcasecmp(var,"oversec")) {strcpy(oversec,val); return 1;}
   if (!strcasecmp(var,"zerobase")) {strcpy(zerobase,val); return 1;}
   if (!strcasecmp(var,"darkbase")) {strcpy(darkbase,val); return 1;}
   if (!strcasecmp(var,"darktime")) {strcpy(darktime,val); return 1;}
   if (!strcasecmp(var,"flatbase")) {strcpy(flatbase,val); return 1;}
   if (!strcasecmp(var,"trimsec")) {strcpy(trimsec,val); return 1;}
   if (!strcasecmp(var,"datasec")) {strcpy(datasec,val); return 1;}
   if (!strcasecmp(var,"ccdsize")) {strcpy(ccdsize,val); return 1;}
   if (!strcasecmp(var,"ccdsec")) {strcpy(ccdsec,val); return 1;}
   if (!strcasecmp(var,"detsec")) {strcpy(detsec,val); return 1;}
   i=strtol(val,&ptr,10);
   if (!*ptr) {
      if (!strcasecmp(var,"SPECIAL")) {SPECIAL=i; if (SPECIAL<0 || SPECIAL>1) perr("Mask image must be 0 or 1"); return 1;}
      if (!strcasecmp(var,"MASK")) {MASK=i; if (MASK<0 || MASK>1) perr("Mask image must be 0 or 1"); return 1;}
      if (!strcasecmp(var,"OVERSCAN")) {OVERSCAN=i; if (OVERSCAN<0 || OVERSCAN>2) perr("Overscan correction must be 0, 1, or 2"); return 1;}
      if (!strcasecmp(var,"ZERO")) {ZERO=i; if (ZERO<0 || ZERO>1) perr("Zero correction must be 0 or 1"); return 1;}
      if (!strcasecmp(var,"DARK")) {DARK=i; if (DARK<0 || DARK>1) perr("Dark correction must be 0 or 1"); return 1;}
      if (!strcasecmp(var,"FLAT")) {FLAT=i; if (FLAT<0 || FLAT>1) perr("Flat correction must be 0 or 1"); return 1;}
      if (!strcasecmp(var,"TRIM")) {TRIM=i; if (TRIM<0 || TRIM>1) perr("Trim image must be 0 or 1"); return 1;}
      if (!strcasecmp(var,"MERGEAMP")) {MERGEAMP=i; if (MERGEAMP<0 || MERGEAMP>1) perr("Merge amplifiers must be 0 or 1"); return 1;}
   }
   return 0;
}

variable_types:
var
char *

variable_types:
val
char *

variable_types: i int

variable_types:
ptr
char *


parsesec

original_code:
int parsesec(imtype*img,char*str,int*x1,int*x2,int*y1,int*y2,int*z1,int*z2) {
   char*ptr;
   while (*str==32) str++;
   if (*(str++)!='[') return 1;
   while (*str==32) str++;
   if (*str=='*') {
      *x1=0;
      *x2=img->X;
      str++;
   }
   else {
      *x1=strtol(str,&ptr,10)-1;
      if (ptr==str) return 1;
      str=ptr;
      while (*str==32) str++;
      if (*(str++)!=':') return 1;
      *x2=strtol(str,&ptr,10);
      if (ptr==str) return 1;
      str=ptr;
   }
   while (*str==32) str++;
   if (*(str++)!=',') return 1;
   while (*str==32) str++;
   if (*str=='*') {
      *y1=0;
      *y2=img->Y;
      str++;
   }
   else {
      *y1=strtol(str,&ptr,10)-1;
      if (ptr==str) return 1;
      str=ptr;
      while (*str==32) str++;
      if (*(str++)!=':') return 1;
      *y2=strtol(str,&ptr,10);
      if (ptr==str) return 1;
      str=ptr;
   }
   while (*str==32) str++;
   if (*str==']') {
      *z1=0;
      *z2=img->Z;
      return 0;
   }
   if (*(str++)!=',') return 1;
   while (*str==32) str++;
   if (*str=='*') {
      *z1=0;
      *z2=img->Z;
      str++;
   }
   else {
      *z1=strtol(str,&ptr,10)-1;
      if (ptr==str) return 1;
      str=ptr;
      while (*str==32) str++;
      if (*(str++)!=':') return 1;
      *z2=strtol(str,&ptr,10);
      if (ptr==str) return 1;
      str=ptr;
   }
   while (*str==32) str++;
   if (*(str++)!=']') return 1;
   return 0;
}

canonical_original_code:
int parsesec(struct imtype *img, char *str, int *x1, int *x2, int *y1, int *y2, int *z1, int *z2) {
   char *ptr;
   while (*str==32) str++;
   if (*(str++)!='[') return 1;
   while (*str==32) str++;
   if (*str=='*') {
      *x1=0;
      *x2=img->X;
      str++;
   }
   else {
      *x1=strtol(str,&ptr,10)-1;
      if (ptr==str) return 1;
      str=ptr;
      while (*str==32) str++;
      if (*(str++)!=':') return 1;
      *x2=strtol(str,&ptr,10);
      if (ptr==str) return 1;
      str=ptr;
   }
   while (*str==32) str++;
   if (*(str++)!=',') return 1;
   while (*str==32) str++;
   if (*str=='*') {
      *y1=0;
      *y2=img->Y;
      str++;
   }
   else {
      *y1=strtol(str,&ptr,10)-1;
      if (ptr==str) return 1;
      str=ptr;
      while (*str==32) str++;
      if (*(str++)!=':') return 1;
      *y2=strtol(str,&ptr,10);
      if (ptr==str) return 1;
      str=ptr;
   }
   while (*str==32) str++;
   if (*str==']') {
      *z1=0;
      *z2=img->Z;
      return 0;
   }
   if (*(str++)!=',') return 1;
   while (*str==32) str++;
   if (*str=='*') {
      *z1=0;
      *z2=img->Z;
      str++;
   }
   else {
      *z1=strtol(str,&ptr,10)-1;
      if (ptr==str) return 1;
      str=ptr;
      while (*str==32) str++;
      if (*(str++)!=':') return 1;
      *z2=strtol(str,&ptr,10);
      if (ptr==str) return 1;
      str=ptr;
   }
   while (*str==32) str++;
   if (*(str++)!=']') return 1;
   return 0;
}

variable_types: struct imtype { int Ncards; double bzero; char xtension[81]; char (*cards)[81]; float ***data; struct bintabledatatype { char name[81]; int length; char type; unsigned long offset; } *bintabdata; } *

variable_types:
str
char *

user_defined_types: struct imtype { int Ncards; double bzero; char xtension[81]; char (*cards)[81]; float ***data; struct bintabledatatype *bintabdata; }


getsec

decompiled_code:
__int64 __fastcall getsec(_DWORD *a1, char *a2, _DWORD *a3, _DWORD *a4, _DWORD *a5, _DWORD *a6, _DWORD *a7, _DWORD *a8)
{
char *v13; // rax

if ( !parsesec(a1, a2, a3, a4, a5, a6, a7, a8) )
return 1LL;
v13 = (char *)getcardval(a1, a2, 0LL);
if ( !parsesec(a1, v13, a3, a4, a5, a6, a7, a8) )
return 1LL;
*a7 = 0;
*a5 = 0;
*a3 = 0;
*a4 = a1[2];
*a6 = a1[3];
*a8 = a1[4];
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(_DWORD *a1, char *a2, _DWORD *a3, _DWORD *a4, _DWORD *a5, _DWORD *a6, _DWORD *a7, _DWORD *a8)
{
char *v13; // rax

if ( !func2(a1, a2, a3, a4, a5, a6, a7, a8) )
return 1LL;
v13 = (char *)getcardval(a1, a2, 0LL);
if ( !func2(a1, v13, a3, a4, a5, a6, a7, a8) )
return 1LL;
*a7 = 0;
*a5 = 0;
*a3 = 0;
*a4 = a1[2];
*a6 = a1[3];
*a8 = a1[4];
return 0LL;
}

original_code:
int getsec(imtype*img,cardtype str,int*x1,int*x2,int*y1,int*y2,int*z1,int*z2) {
   if (!parsesec(img,str,x1,x2,y1,y2,z1,z2)) return 1;
   if (!parsesec(img,getcardval(img,str,0),x1,x2,y1,y2,z1,z2)) return 1;
   *x1=*y1=*z1=0;
   *x2=img->X;
   *y2=img->Y;
   *z2=img->Z;
   return 0;
}

canonical_original_code:
int getsec(struct imtype *img, char str[81], int *x1, int *x2, int *y1, int *y2, int *z1, int *z2) {
   if (!parsesec(img,str,x1,x2,y1,y2,z1,z2)) return 1;
   if (!parsesec(img,getcardval(img,str,0),x1,x2,y1,y2,z1,z2)) return 1;
   *x1=*y1=*z1=0;
   *x2=img->X;
   *y2=img->Y;
   *z2=img->Z;
   return 0;
}

variable_types:
str
char [81]

user_defined_types: struct bintabledatatype { char name[81]; int length; char type; unsigned long offset; }


perr

decompiled_code:
void __fastcall __noreturn perr(const char *a1)
{
puts(a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
puts(a1);
exit(1);
}

original_code:
void perr(char *str) {
   printf("%s\n",str);
   exit(1);
}


decompiled_code:
double *__fastcall WFC3fwddistort(int a1, int a2, double *a3, double *a4)
{
double *result; // rax
double v5; // xmm1_8
double v6; // xmm0_8

result = (double *)(WFC3filters + 2032LL * a2 + 272LL * a1);
v5 = *a4 - result[51];
v6 = *a3 - result[50];
*a3 = (result[68] * v6 * v6 * v5 * v6
+ result[57] * v6
+ result[56] * v5
+ result[58] * v5 * v5
+ result[59] * v6 * v5
+ result[60] * v6 * v6
+ result[61] * v5 * v5 * v5
+ result[62] * v6 * v5 * v5
+ result[63] * v6 * v6 * v5
+ result[64] * v6 * v6 * v6
+ result[65] * v5 * v5 * v5 * v5
+ result[66] * v6 * v5 * v5 * v5
+ result[67] * v6 * v6 * v5 * v5
+ result[69] * v6 * v6 * v6 * v6
+ result[55])
/ result[53];
*a4 = (v5 * (result[82] * v6 * v6) * v6
+ result[81] * v6 * v6 * v5 * v5
+ result[71] * v6
+ result[70] * v5
+ result[72] * v5 * v5
+ result[73] * v6 * v5
+ result[74] * v6 * v6
+ result[75] * v5 * v5 * v5
+ result[76] * v6 * v5 * v5
+ result[77] * v6 * v6 * v5
+ result[78] * v6 * v6 * v6
+ result[79] * v5 * v5 * v5 * v5
+ result[80] * v6 * v5 * v5 * v5
+ v6 * (result[83] * v6 * v6 * v6)
+ result[54])
/ result[53];
return result;
}

variable_types: cm int

variable_types: filt int

variable_types:
x
double *

variable_types:
y
double *


decompiled_code:
double __fastcall WFC3pixsize(int a1, int a2, double a3, double a4)
{
int v4; // er8
int v5; // er9
int v6; // er8
int v7; // er9
int v8; // er8
int v9; // er9
double v11; // [rsp+0h] [rbp-40h] BYREF
double v12; // [rsp+8h] [rbp-38h] BYREF
double v13; // [rsp+10h] [rbp-30h] BYREF
double v14; // [rsp+18h] [rbp-28h] BYREF
double v15; // [rsp+20h] [rbp-20h] BYREF
double v16; // [rsp+28h] [rbp-18h] BYREF
double v17; // [rsp+30h] [rbp-10h] BYREF
double v18; // [rsp+38h] [rbp-8h] BYREF

v11 = a3 - 0.5;
v12 = a4 - 0.5;
v13 = a3 + 0.5;
v14 = a4 + 0.5;
v15 = a3 - 0.5;
v16 = a4 + 0.5;
v17 = a3 + 0.5;
v18 = a4 - 0.5;
WFC3fwddistort(a1, a2, &v11, &v12);
WFC3fwddistort(v4, v5, &v13, &v14);
WFC3fwddistort(v6, v7, &v15, &v16);
WFC3fwddistort(v8, v9, &v17, &v18);
return COERCE_DOUBLE(COERCE_UNSIGNED_INT64((v15 - v11) * (v14 - v12) - (v16 - v12) * (v13 - v11)) & LC1) * 0.5
+ COERCE_DOUBLE(COERCE_UNSIGNED_INT64((v17 - v11) * (v14 - v12) - (v18 - v12) * (v13 - v11)) & LC1) * 0.5;
}

original_code:
double WFC3pixsize(int cm,int filt,double x,double y) {
   double x1=x-0.5; double y1=y-0.5;
   double x2=x+0.5; double y2=y+0.5;
   double xa=x-0.5; double ya=y+0.5;
   double xb=x+0.5; double yb=y-0.5;
   WFC3fwddistort(cm,filt,&x1,&y1);
   WFC3fwddistort(cm,filt,&x2,&y2);
   WFC3fwddistort(cm,filt,&xa,&ya);
   WFC3fwddistort(cm,filt,&xb,&yb);
   y2-=y1;
   x2-=x1;
   return 0.5*fabs((xa-x1)*y2-(ya-y1)*x2)+0.5*fabs((xb-x1)*y2-(yb-y1)*x2);
}

canonical_original_code:
double WFC3pixsize(int cm, int filt, double x, double y) {
   double x1 = x-0.5; double y1 = y-0.5;
   double x2 = x+0.5; double y2 = y+0.5;
   double xa = x-0.5; double ya = y+0.5;
   double xb = x+0.5; double yb = y-0.5;
   WFC3fwddistort(cm,filt,&x1,&y1);
   WFC3fwddistort(cm,filt,&x2,&y2);
   WFC3fwddistort(cm,filt,&xa,&ya);
   WFC3fwddistort(cm,filt,&xb,&yb);
   y2-=y1;
   x2-=x1;
   return 0.5*fabs((xa-x1)*y2-(ya-y1)*x2)+0.5*fabs((xb-x1)*y2-(yb-y1)*x2);
}

variable_types: x double

variable_types: y double

variable_types: xa double

variable_types: ya double

variable_types: xb double

variable_types: yb double

return_type: double


main

repo: dsw/proquint

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
const char **v4; // r12
__int64 v5; // rbx
__int64 v6; // rdx

v3 = argv[1];
if ( v3 )
{
v4 = argv + 1;
while ( 1 )
{
v5 = *v3;
if ( !(_BYTE)v5 )
goto LABEL_4;
if ( (_BYTE)v5 == 48 )
{
fwrite(
"Do not lead input strings with a zero.\n"
"For decimal, trim leading zeros.\n"
"For hex, lead with an 'x'.\n"
"We do not process octal.\n",
1uLL,
0x7CuLL,
stderr);
exit(1);
}
if ( (v5 & 0xDF) == 88 )
{
main_convertNumber(16LL, v3 + 1, envp);
goto LABEL_4;
}
if ( ((*__ctype_b_loc())[v5] & 0x800) != 0 )
{
main_convertNumber(10LL, v3, v6);
LABEL_4:
v3 = v4[1];
++v4;
if ( !v3 )
break;
}
else
{
++v4;
main_convertQuint(v3);
v3 = *v4;
if ( !*v4 )
break;
}
}
}
putchar(10);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
const char **v4; // r12
__int64 v5; // rbx
__int64 v6; // rdx

v3 = argv[1];
if ( v3 )
{
v4 = argv + 1;
while ( 1 )
{
v5 = *v3;
if ( !(_BYTE)v5 )
goto LABEL_4;
if ( (_BYTE)v5 == 48 )
{
fwrite(
"Do not lead input strings with a zero.\n"
"For decimal, trim leading zeros.\n"
"For hex, lead with an 'x'.\n"
"We do not process octal.\n",
1uLL,
0x7CuLL,
stderr);
exit(1);
}
if ( (v5 & 0xDF) == 88 )
{
func10(16LL, v3 + 1, envp);
goto LABEL_4;
}
if ( ((*__ctype_b_loc())[v5] & 0x800) != 0 )
{
func10(10LL, v3, v6);
LABEL_4:
v3 = v4[1];
++v4;
if ( !v3 )
break;
}
else
{
++v4;
func11(v3);
v3 = *v4;
if ( !*v4 )
break;
}
}
}
putchar(10);
return 0;
}

original_code:
int main(int argc, char const **argv) {
  --argc; ++argv;
  for(; *argv; --argc, ++argv) {
    char const *s = *argv;
    if (!s[0]) continue;
    if (s[0] == '0') {
      fprintf(stderr,
              "Do not lead input strings with a zero.\n"
              "For decimal, trim leading zeros.\n"
              "For hex, lead with an 'x'.\n"
              "We do not process octal.\n");
      exit(1);
    } else if (s[0] == 'x' || s[0] == 'X') {
      main_convertNumber(16, s+1);
    } else if (((*__ctype_b_loc ())[(int) ((s[0]))] & (unsigned short int) _ISdigit)) {
      main_convertNumber(10, s);
    } else {
      main_convertQuint(s);
    }
  }
  printf("\n");
  return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
  --argc; ++argv;
  for(; *argv; --argc, ++argv) {
    char *s = *argv;
    if (!s[0]) continue;
    if (s[0] == '0') {
      fprintf(stderr,
              "Do not lead input strings with a zero.\n"
              "For decimal, trim leading zeros.\n"
              "For hex, lead with an 'x'.\n"
              "We do not process octal.\n");
      exit(1);
    } else if (s[0] == 'x' || s[0] == 'X') {
      main_convertNumber(16, s+1);
    } else if (((*__ctype_b_loc ())[(int) ((s[0]))] & (unsigned short) _ISdigit)) {
      main_convertNumber(10, s);
    } else {
      main_convertQuint(s);
    }
  }
  printf("\n");
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
s
char *


decompiled_code:
__int64 __fastcall my_atoi(int a1, const char *a2)
{
unsigned int v2; // er10
char v3; // al
const char *v4; // rcx
unsigned int v5; // er9
int v6; // eax
__int64 result; // rax

v2 = *a2;
if ( !*a2 )
return 0LL;
v3 = *a2;
v4 = a2;
v5 = 0;
while ( 2 )
{
switch ( v3 )
{
case '0':
v6 = 0;
goto LABEL_6;
case '1':
v6 = 1;
goto LABEL_6;
case '2':
v6 = 2;
goto LABEL_6;
case '3':
v6 = 3;
goto LABEL_6;
case '4':
v6 = 4;
goto LABEL_6;
case '5':
v6 = 5;
goto LABEL_6;
case '6':
v6 = 6;
goto LABEL_6;
case '7':
v6 = 7;
goto LABEL_6;
case '8':
v6 = 8;
goto LABEL_6;
case '9':
v6 = 9;
goto LABEL_6;
case 'A':
case 'a':
v6 = 10;
goto LABEL_5;
case 'B':
case 'b':
v6 = 11;
goto LABEL_5;
case 'C':
case 'c':
v6 = 12;
goto LABEL_5;
case 'D':
case 'd':
v6 = 13;
goto LABEL_5;
case 'E':
case 'e':
v6 = 14;
goto LABEL_5;
case 'F':
case 'f':
v6 = 15;
LABEL_5:
if ( v6 >= a1 )
{
fprintf(stderr, "Numbers of base %d may not contain the digit '%c': '%s'.\n", (unsigned int)a1, v2, a2);
exit(1);
}
LABEL_6:
v2 = *++v4;
v5 = v6 + a1 * v5;
v3 = v2;
if ( v2 )
continue;
result = v5;
break;
default:
fprintf(stderr, "Illegal character in uint-word '%s': '%c'.\n", a2, v2);
exit(1);
}
return result;
}
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, const char *a2)
{
unsigned int v2; // er10
char v3; // al
const char *v4; // rcx
unsigned int v5; // er9
int v6; // eax
__int64 result; // rax

v2 = *a2;
if ( !*a2 )
return 0LL;
v3 = *a2;
v4 = a2;
v5 = 0;
while ( 2 )
{
switch ( v3 )
{
case '0':
v6 = 0;
goto LABEL_6;
case '1':
v6 = 1;
goto LABEL_6;
case '2':
v6 = 2;
goto LABEL_6;
case '3':
v6 = 3;
goto LABEL_6;
case '4':
v6 = 4;
goto LABEL_6;
case '5':
v6 = 5;
goto LABEL_6;
case '6':
v6 = 6;
goto LABEL_6;
case '7':
v6 = 7;
goto LABEL_6;
case '8':
v6 = 8;
goto LABEL_6;
case '9':
v6 = 9;
goto LABEL_6;
case 'A':
case 'a':
v6 = 10;
goto LABEL_5;
case 'B':
case 'b':
v6 = 11;
goto LABEL_5;
case 'C':
case 'c':
v6 = 12;
goto LABEL_5;
case 'D':
case 'd':
v6 = 13;
goto LABEL_5;
case 'E':
case 'e':
v6 = 14;
goto LABEL_5;
case 'F':
case 'f':
v6 = 15;
LABEL_5:
if ( v6 >= a1 )
{
fprintf(stderr, "Numbers of base %d may not contain the digit '%c': '%s'.\n", (unsigned int)a1, v2, a2);
exit(1);
}
LABEL_6:
v2 = *++v4;
v5 = v6 + a1 * v5;
v3 = v2;
if ( v2 )
continue;
result = v5;
break;
default:
fprintf(stderr, "Illegal character in uint-word '%s': '%c'.\n", a2, v2);
exit(1);
}
return result;
}
}

original_code:
static uint32_t my_atoi(int base, char const *s) {
  char const *const s_orig = s;
  uint32_t ret = 0;
  int c;
  for(; (c=*s); ++s) {
    int value = -1;
    switch(c) {
    case '0': value = 0; break;
    case '1': value = 1; break;
    case '2': value = 2; break;
    case '3': value = 3; break;
    case '4': value = 4; break;
    case '5': value = 5; break;
    case '6': value = 6; break;
    case '7': value = 7; break;
    case '8': value = 8; break;
    case '9': value = 9; break;
    case 'a': case 'A': value = 10; break;
    case 'b': case 'B': value = 11; break;
    case 'c': case 'C': value = 12; break;
    case 'd': case 'D': value = 13; break;
    case 'e': case 'E': value = 14; break;
    case 'f': case 'F': value = 15; break;
    default:
      fprintf(stderr, "Illegal character in uint-word '%s': '%c'.\n",
              s_orig, c);
      exit(1);
      break;
    }
    if (value < 0) {
      fprintf(stderr, "This cannot happen.");
      exit(1);
    }
    if (value >= base) {
      fprintf(stderr,
              "Numbers of base %d may not contain the digit '%c': '%s'.\n",
              base, c, s_orig);
      exit(1);
    }
    ret *= base;
    ret += value;
  }
  return ret;
}

canonical_original_code:
static unsigned int my_atoi(int base, char *s) {
  char *s_orig = s;
  unsigned int ret = 0;
  int c;
  for(; (c=*s); ++s) {
    int value = -1;
    switch(c) {
    case '0': value = 0; break;
    case '1': value = 1; break;
    case '2': value = 2; break;
    case '3': value = 3; break;
    case '4': value = 4; break;
    case '5': value = 5; break;
    case '6': value = 6; break;
    case '7': value = 7; break;
    case '8': value = 8; break;
    case '9': value = 9; break;
    case 'a': case 'A': value = 10; break;
    case 'b': case 'B': value = 11; break;
    case 'c': case 'C': value = 12; break;
    case 'd': case 'D': value = 13; break;
    case 'e': case 'E': value = 14; break;
    case 'f': case 'F': value = 15; break;
    default:
      fprintf(stderr, "Illegal character in uint-word '%s': '%c'.\n",
              s_orig, c);
      exit(1);
      break;
    }
    if (value < 0) {
      fprintf(stderr, "This cannot happen.");
      exit(1);
    }
    if (value >= base) {
      fprintf(stderr,
              "Numbers of base %d may not contain the digit '%c': '%s'.\n",
              base, c, s_orig);
      exit(1);
    }
    ret *= base;
    ret += value;
  }
  return ret;
}

variable_types: base int

variable_types:
ret
unsigned int

variable_types: c int

variable_types: value int

return_type: unsigned int


decompiled_code:
int __fastcall main_convertNumber(int a1, const char *a2)
{
unsigned int v2; // eax
__int128 v4; // [rsp+0h] [rbp-28h] BYREF
__int64 v5; // [rsp+10h] [rbp-18h]

v2 = my_atoi(a1, a2);
v4 = 0LL;
v5 = 0LL;
uint2quint(&v4, v2, 45);
return printf("%s ", (const char *)&v4);
}

canonical_decompiled_code:
int __fastcall func10(int a1, const char *a2)
{
unsigned int v2; // eax
__int128 v4; // [rsp+0h] [rbp-28h] BYREF
__int64 v5; // [rsp+10h] [rbp-18h]

v2 = func9(a1, a2);
v4 = 0LL;
v5 = 0LL;
func7(&v4, v2, 45);
return printf("%s ", (const char *)&v4);
}

original_code:
static void main_convertNumber(int base, char const *s) {
  int const QUINT_LEN = 5*2 + 1;
  int const DOUBLE_QUINT_LEN = 2*QUINT_LEN + 1;
  int const n = my_atoi(base, s);
  char quint[DOUBLE_QUINT_LEN+1];
  int i;
  for(i=0; i<DOUBLE_QUINT_LEN+1; ++i) quint[i] = '\0';
  uint2quint(quint, n, '-');
  printf("%s ", quint);
}

canonical_original_code:
static void main_convertNumber(int base, char *s) {
  int QUINT_LEN = 5*2 + 1;
  int DOUBLE_QUINT_LEN = 2*QUINT_LEN + 1;
  int n = my_atoi(base, s);
  char quint[-1];
  int i;
  for(i=0; i<DOUBLE_QUINT_LEN+1; ++i) quint[i] = '\0';
  uint2quint(quint, n, '-');
  printf("%s ", quint);
}

variable_types: n int

variable_types:
quint
char [-1]

variable_types: i int


decompiled_code:
int __fastcall main_convertQuint(char *a1)
{
unsigned int v1; // eax

v1 = quint2uint(a1);
return printf("x%x ", v1);
}

canonical_decompiled_code:
int __fastcall func11(char *a1)
{
unsigned int v1; // eax

v1 = func8(a1);
return printf("x%x ", v1);
}

original_code:
static void main_convertQuint(char const *s) {
  uint32_t uint0 = quint2uint(s);
  printf("x%x ", uint0);
}

canonical_original_code:
static void main_convertQuint(char *s) {
  unsigned int uint0 = quint2uint(s);
  printf("x%x ", uint0);
}


decompiled_code:
__int64 __fastcall mkdir_rec(char *src)
{
size_t v1; // rax
_BYTE *v2; // rbx
char *v3; // rbp
__int128 v5; // [rsp+0h] [rbp-218h] BYREF
char v6[496]; // [rsp+10h] [rbp-208h] BYREF

v5 = 0LL;
memset(v6, 0, sizeof(v6));
strcpy((char *)&v5, src);
v1 = strlen((const char *)&v5);
if ( v1 > 1 )
{
v2 = (char *)&v5 + 1;
v3 = (char *)&v5 + (unsigned int)(v1 - 2) + 2;
do
{
while ( *v2 != 47 )
{
if ( ++v2 == v3 )
goto LABEL_6;
}
*v2++ = 0;
mkdir((const char *)&v5, 0x1FFu);
*(v2 - 1) = 47;
}
while ( v2 != v3 );
}
LABEL_6:
mkdir((const char *)&v5, 0x1FFu);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *src)
{
size_t v1; // rax
_BYTE *v2; // rbx
char *v3; // rbp
__int128 v5; // [rsp+0h] [rbp-218h] BYREF
char v6[496]; // [rsp+10h] [rbp-208h] BYREF

v5 = 0LL;
memset(v6, 0, sizeof(v6));
strcpy((char *)&v5, src);
v1 = strlen((const char *)&v5);
if ( v1 > 1 )
{
v2 = (char *)&v5 + 1;
v3 = (char *)&v5 + (unsigned int)(v1 - 2) + 2;
do
{
while ( *v2 != 47 )
{
if ( ++v2 == v3 )
goto LABEL_6;
}
*v2++ = 0;
mkdir((const char *)&v5, 0x1FFu);
*(v2 - 1) = 47;
}
while ( v2 != v3 );
}
LABEL_6:
mkdir((const char *)&v5, 0x1FFu);
return 1LL;
}

original_code:
int mkdir_rec(const char* path)
{
 char szpath[512] = {0};
 int i = 0;
 int len = 0;
 sprintf (szpath, "%s", path);
 len = strlen(szpath);
 for (i = 1; i < len; i++)
 {
  if (szpath[i] == '/')
  {
   szpath[i] = '\0';
   mkdir (szpath, 0777);
   szpath[i] = '/';
  }
 }
 mkdir (szpath, 0777);
 return 1;
}

canonical_original_code:
int mkdir_rec(char *path)
{
 char szpath[512] = {0};
 int i = 0;
 int len = 0;
 sprintf (szpath, "%s", path);
 len = strlen(szpath);
 for (i = 1; i < len; i++)
 {
  if (szpath[i] == '/')
  {
   szpath[i] = '\0';
   mkdir (szpath, 0777);
   szpath[i] = '/';
  }
 }
 mkdir (szpath, 0777);
 return 1;
}

variable_types:
path
char *

variable_types:
szpath
char [512]

variable_types: len int


InitArgs

decompiled_code:
void __fastcall InitArgs(int a1, const char **a2)
{
if ( a1 > 1 && !strncasecmp(a2[1], "-v", 2uLL) )
{
printf("%s: v1.2 2011-03-24 version list:\n", *a2);
puts("\tv1.2: 2011-03-24:creating ");
exit(0);
}
}

canonical_decompiled_code:
void __fastcall func2(int a1, const char **a2)
{
if ( a1 > 1 && !strncasecmp(a2[1], "-v", 2uLL) )
{
printf("%s: v1.2 2011-03-24 version list:\n", *a2);
puts("\tv1.2: 2011-03-24:creating ");
exit(0);
}
}

original_code:
void InitArgs(int argc, char* argv[])
{
 if (argc > 1)
 {
  if (strncasecmp(argv[1], "-v", 2) == 0)
  {
   printf("%s: v1.2 2011-03-24 version list:\n", argv[0]);
   printf("\tv1.2: 2011-03-24:creating \n");
   exit(0);
  }
 }
}

canonical_original_code:
void InitArgs(int argc, char *argv[])
{
 if (argc > 1)
 {
  if (strncasecmp(argv[1], "-v", 2) == 0)
  {
   printf("%s: v1.2 2011-03-24 version list:\n", argv[0]);
   printf("\tv1.2: 2011-03-24:creating \n");
   exit(0);
  }
 }
}

variable_types:
argv
char *[]


original_code:
int deliver_app_task (thread_pool_t * pool, config_t * conf)
{
 unsigned int index = 0;
 for (index = 0; index < pool->thread_num; index++)
 {
  g_plist[index].func = repo_build_func;
  g_plist[index].data = ((void *)0);
  g_plist[index].conf = conf;
  g_plist[index].index = index+1;
  pool->thread_list[index].param = &g_plist[index];
 }
 for (index = 0; index < conf->repo_num; index++)
 {
   repo_t * pr = conf->repo_list + index;
   if (g_plist[index % pool->thread_num].data == ((void *)0) )
    g_plist[index % pool->thread_num].data = pr;
   else
   {
    pr->next = g_plist[index % pool->thread_num].data;
    g_plist[index % pool->thread_num].data = pr;
   }
 }
 return 1;
}

canonical_original_code:
int deliver_app_task(struct thread_pool_t *pool, struct config_t *conf)
{
 unsigned int index = 0;
 for (index = 0; index < pool->thread_num; index++)
 {
  g_plist[index].func = repo_build_func;
  g_plist[index].data = ((void *)0);
  g_plist[index].conf = conf;
  g_plist[index].index = index+1;
  pool->thread_list[index].param = &g_plist[index];
 }
 for (index = 0; index < conf->repo_num; index++)
 {
   struct _repo *pr = conf->repo_list + index;
   if (g_plist[index % pool->thread_num].data == ((void *)0) )
    g_plist[index % pool->thread_num].data = pr;
   else
   {
    pr->next = g_plist[index % pool->thread_num].data;
    g_plist[index % pool->thread_num].data = pr;
   }
 }
 return 1;
}

variable_types: struct thread_pool_t { struct thread_t { unsigned long thread; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; unsigned char status; unsigned int index; struct param_t { int (*func)(void *data); void *data; int index; void *conf; } *param; } thread_list[100]; unsigned int thread_num; } *

variable_types: struct config_t { unsigned short nthread; unsigned char daemon; unsigned char verb; char conf[256]; char user[64]; char basedir[256]; char sigfile[64]; int interval; struct _repo { char path[256]; char sigfile[256]; int intv; void *next; long last_update; } repo_list[100]; int repo_num; int loop; } *

variable_types:
index
unsigned int

variable_types: struct _repo { char path[256]; char sigfile[256]; int intv; void *next; long last_update; } *

user_defined_types: struct thread_pool_t { struct thread_t thread_list[100]; unsigned int thread_num; }

user_defined_types: struct config_t { unsigned short nthread; unsigned char daemon; unsigned char verb; char conf[256]; char user[64]; char basedir[256]; char sigfile[64]; int interval; struct _repo repo_list[100]; int repo_num; int loop; }

user_defined_types: struct thread_t { unsigned long thread; union pthread_mutex_t mutex; unsigned char status; unsigned int index; struct param_t *param; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


decompiled_code:
__int64 __fastcall start_thread(__int64 a1, __int64 a2)
{
unsigned int v2; // ebp
__int64 v3; // rbx
__int64 result; // rax

if ( !*(_DWORD *)(a1 + 6400) )
return 0LL;
v2 = 0;
v3 = a1 + 48;
do
{
*(_BYTE *)v3 = 2;
if ( *(_BYTE *)(a2 + 3) )
printf("starting thread \x1B[0;32;32m%03d\x1B[m\n", *(unsigned int *)(v3 + 4));
result = *(unsigned int *)(a1 + 6400);
++v2;
v3 += 64LL;
}
while ( (unsigned int)result > v2 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
unsigned int v2; // ebp
__int64 v3; // rbx
__int64 result; // rax

if ( !*(_DWORD *)(a1 + 6400) )
return 0LL;
v2 = 0;
v3 = a1 + 48;
do
{
*(_BYTE *)v3 = 2;
if ( *(_BYTE *)(a2 + 3) )
printf("starting thread \x1B[0;32;32m%03d\x1B[m\n", *(unsigned int *)(v3 + 4));
result = *(unsigned int *)(a1 + 6400);
++v2;
v3 += 64LL;
}
while ( (unsigned int)result > v2 );
return result;
}

original_code:
int start_thread(thread_pool_t * pool, const config_t * conf)
{
 unsigned int index = 0;
 for (index = 0; index < pool->thread_num; index++)
 {
  pool->thread_list[index].status = status_ready;
  if (conf->verb) printf ("starting thread ""\033[0;32;32m""%03d""\033[m""\n",pool->thread_list[index].index);
 }
 return pool->thread_num;
}

canonical_original_code:
int start_thread(struct thread_pool_t *pool, struct config_t *conf)
{
 unsigned int index = 0;
 for (index = 0; index < pool->thread_num; index++)
 {
  pool->thread_list[index].status = status_ready;
  if (conf->verb) printf ("starting thread ""\033[0;32;32m""%03d""\033[m""\n",pool->thread_list[index].index);
 }
 return pool->thread_num;
}

user_defined_types: struct _repo { char path[256]; char sigfile[256]; int intv; void *next; long last_update; }

user_defined_types: struct param_t { int (*func)(void *data); void *data; int index; void *conf; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }