original_code:
void
list_insert_node(struct list *list, void *content, unsigned int code)
{
 struct node *new;
 new = malloc(sizeof(struct node));
 if (!new) {
  printf("malloc: %s\n", strerror((*__errno_location ())));
  return;
 }
 new->content = content;
 new->code = code;
 if (list->head == ((void *)0)) {
  list->head = new;
  list->tail = new;
  new->next = new->prev = ((void *)0);
  list->len = 1;
 } else {
  list->head->prev = new;
  new->next = list->head;
  new->prev = ((void *)0);
  list->head = new;
  list->len++;
 }
}

variable_types:
content
void *

variable_types:
code
unsigned int

variable_types: struct node { void *content; unsigned int code; struct node *next; struct node *prev; } *


repo: thexhr/dermob

decompiled_code:
void __fastcall list_free_list(void *ptr)
{
__int64 i; // rbx

for ( i = *(_QWORD *)ptr; *(_QWORD *)ptr; i = *(_QWORD *)ptr )
{
*(_QWORD *)ptr = *(_QWORD *)(i + 16);
free(*(void **)i);
free((void *)i);
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
__int64 i; // rbx

for ( i = *(_QWORD *)ptr; *(_QWORD *)ptr; i = *(_QWORD *)ptr )
{
*(_QWORD *)ptr = *(_QWORD *)(i + 16);
free(*(void **)i);
free((void *)i);
}
free(ptr);
}

original_code:
void
list_free_list(struct list *list)
{
 struct node *cursor;
 while ((cursor = list->head)) {
  list->head = cursor->next;
  free(cursor->content);
  free(cursor);
 }
 free(list);
}

variable_types: struct list { struct node { void *content; unsigned int code; struct node *next; struct node *prev; } *head; struct node *tail; unsigned int len; } *

return_type: void

user_defined_types: struct list { struct node *head; struct node *tail; unsigned int len; }


original_code:
void
list_remove_node(struct list *list, struct node *temp)
{
 if ((temp == list->head) && (temp != list->tail)) {
  list->head = temp->next;
  list->head->prev = ((void *)0);
 } else if ((temp != list->head) && (temp == list->tail)) {
  list->tail = temp->prev;
  list->tail->next = ((void *)0);
 } else if ((temp == list->head) && (temp == list->tail)) {
  list->tail = list->head = ((void *)0);
 } else {
  temp->prev->next = temp->next;
  temp->next->prev = temp->prev;
 }
 free(temp->content);
 free(temp);
}

variable_types:
temp
struct node *

user_defined_types: struct node { void *content; unsigned int code; struct node *next; struct node *prev; }


decompiled_code:
void __fastcall list_remove(__int64 *a1, unsigned int (__fastcall *a2)(__int64))
{
__int64 v2; // rbx
__int64 v3; // r12

v2 = *a1;
while ( v2 )
{
if ( a1[1] == v2 )
{
if ( !a2(v2) )
return;
v3 = 0LL;
}
else
{
v3 = *(_QWORD *)(v2 + 16);
if ( !a2(v2) )
{
v2 = v3;
continue;
}
}
list_remove_node(a1, v2);
v2 = v3;
}
}

original_code:
void
list_remove(struct list *list, int (*cond)(struct node*))
{
 struct node *cursor,
   *temp;
 cursor = list->head;
 while (cursor != ((void *)0)) {
  temp = cursor;
  cursor = (cursor != list->tail) ? cursor->next : ((void *)0);
  if ((*cond)(temp))
   list_remove_node(list, temp);
 }
}

canonical_original_code:
void list_remove(struct list *list, int (*cond)(struct node *))
{
 struct node *cursor; struct node *temp;
 cursor = list->head;
 while (cursor != ((void *)0)) {
  temp = cursor;
  cursor = (cursor != list->tail) ? cursor->next : ((void *)0);
  if ((*cond)(temp))
   list_remove_node(list, temp);
 }
}

variable_types:
cond
int (*)(struct node *)


original_code:
int
analyse_fat_header(char *buffer, int *offset, struct fat_header *rfh)
{
 struct fat_header *fh;
 char *ptr;
 fh = malloc(sizeof(*fh));
 ptr = buffer;
 memcpy(fh, ptr, sizeof(*fh));
 if (fh->magic != 0xbebafeca && fh->magic != 0xcafebabe) {
  free(fh);
  rfh = ((void *)0);
  return(-1);
 }
 if (fh->magic == 0xcafebabe)
  bo_b = 1;
 else if (fh->magic == 0xbebafeca)
  bo_b = 0;
 *offset += sizeof(*fh);
 memcpy(rfh, fh, sizeof(*fh));
 free(fh);
 return(1);
}

variable_types:
buffer
char *

variable_types:
offset
int *

variable_types: struct fat_header { unsigned int magic; unsigned int nfat_arch; } *

variable_types:
ptr
char *

return_type: int


original_code:
int
analyse_fat_arch(char *buffer, int *offset, struct fat_arch *rfa)
{
 char *ptr;
 ptr = buffer;
 ptr += *offset;
 memcpy(rfa, ptr, sizeof(*rfa));
 *offset += sizeof(*rfa);
 return(0);
}

variable_types: struct fat_arch { int cputype; int cpusubtype; unsigned int offset; unsigned int size; unsigned int align; } *


decompiled_code:
__int64 __fastcall determine_mo_arch(int *a1)
{
int v1; // edx
__int64 result; // rax

v1 = *a1;
result = 0LL;
if ( *a1 != -17958193 )
{
result = 1LL;
if ( v1 != -805638658 )
{
result = 2LL;
if ( v1 != -17958194 )
result = 4 * (unsigned int)(v1 == -822415874) - 1;
}
}
return result;
}

original_code:
int
determine_mo_arch(char *buffer)
{
 struct mach_header_magic mhh;
 char *ptr = buffer;
 int ret = -1;
 memcpy(&mhh, ptr, sizeof(mhh));
 if (mhh.magic == 0xfeedfacf)
  ret = 0;
 else if (mhh.magic == 0xcffaedfe)
  ret = 1;
 else if (mhh.magic == 0xfeedface)
  ret = 2;
 else if (mhh.magic == 0xcefaedfe)
  ret = 3;
 return ret;
}

variable_types: struct mach_header_magic { unsigned int magic; }

variable_types: ret int


original_code:
int
analyse_mo_header(char *buffer, int *offset, struct mach_header *rmh)
{
 struct mach_header *mh;
 char *ptr;
 int moa;
 ptr = buffer;
 if (offset > 0)
  ptr += *offset;
 moa = determine_mo_arch(buffer);
 if (moa != 0 && moa != 1 && moa != 2 && moa != 3) {
  printf("Cannot determine mach-o architecture\n");
  return(1);
 }
 mh = malloc(sizeof(*mh));
 if (mh == ((void *)0)) {
  printf("Cannot allocate memory\n");
  return(1);
 }
 memcpy(mh, ptr, sizeof(*mh));
 if ((mh->magic == 0xfeedface && bo_a == 1) ||
  (mh->magic == 0xfeedfacf && bo_a == 1))
  bo_b = 1;
 else if ((mh->magic == 0xcefaedfe && bo_a == 1) ||
     (mh->magic == 0xcffaedfe && bo_a == 1))
  bo_b = 0;
 else if ((mh->magic == 0xfeedface && bo_a != 1) ||
     (mh->magic == 0xfeedfacf && bo_a != 1))
  bo_b = 0;
 else if ((mh->magic == 0xcefaedfe && bo_a != 1) ||
     (mh->magic == 0xcffaedfe && bo_a != 1))
  bo_b = 1;
 offset_moh = *offset;
 *offset += sizeof(*mh);
 memcpy(rmh, mh, sizeof(*rmh));
 free(mh);
 return(0);
}

variable_types: struct mach_header { unsigned int magic; int cputype; int cpusubtype; unsigned int filetype; unsigned int ncmds; unsigned int sizeofcmds; unsigned int flags; } *

variable_types: moa int


original_code:
void
examine_section(char *buffer, int *offset, struct section *rsec)
{
 char *ptr;
 ptr = buffer;
 ptr += *offset;
 memcpy(rsec, ptr, sizeof(*rsec));
 *offset += sizeof(*rsec);
}

variable_types: struct section { char sectname[16]; char segname[16]; unsigned int addr; unsigned int size; unsigned int offset; unsigned int align; unsigned int reloff; unsigned int nreloc; unsigned int flags; unsigned int reserved1; unsigned int reserved2; } *


decompiled_code:
__int64 __fastcall examine_segmet(__int64 a1, int *a2, int a3, __int64 a4, _DWORD *a5)
{
const __m128i *v5; // rbx
__int64 result; // rax
__m128i *v8; // r12
__m128i *v9; // rax
__m128i *v10; // rax
__m128i *v11; // rax
__m128i *v12; // rax

v5 = (const __m128i *)(a1 + *a2);
switch ( a3 )
{
case 1:
v8 = (__m128i *)malloc(0x38uLL);
*v8 = _mm_loadu_si128(v5);
v8[1] = _mm_loadu_si128(v5 + 1);
v8[2] = _mm_loadu_si128(v5 + 2);
v8[3].m128i_i64[0] = v5[3].m128i_i64[0];
list_insert_node(lst, v8, 6LL);
*a5 = swapi(v8[3].m128i_u32[0]);
result = 56LL;
break;
case 2:
v9 = (__m128i *)malloc(0x18uLL);
*v9 = _mm_loadu_si128(v5);
v9[1].m128i_i64[0] = v5[1].m128i_i64[0];
list_insert_node(lst, v9, 7LL);
result = 24LL;
break;
case 11:
v11 = (__m128i *)malloc(0x50uLL);
*v11 = _mm_loadu_si128(v5);
v11[1] = _mm_loadu_si128(v5 + 1);
v11[2] = _mm_loadu_si128(v5 + 2);
v11[3] = _mm_loadu_si128(v5 + 3);
v11[4] = _mm_loadu_si128(v5 + 4);
list_insert_node(lst, v11, 9LL);
result = 80LL;
break;
case 12:
dynamic = 1;
v10 = (__m128i *)malloc(0x18uLL);
*v10 = _mm_loadu_si128(v5);
v10[1].m128i_i64[0] = v5[1].m128i_i64[0];
list_insert_node(lst, v10, 8LL);
result = 24LL;
break;
case 13:
mprintf("id dylib\n");
result = 0LL;
break;
case 14:
result = 12LL;
break;
case 17:
mprintf("routines\n");
result = 0LL;
break;
case 22:
v12 = (__m128i *)malloc(0x10uLL);
*v12 = _mm_loadu_si128(v5);
list_insert_node(lst, v12, 10LL);
result = 16LL;
break;
default:
result = 0LL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int *a2, int a3, __int64 a4, _DWORD *a5)
{
const __m128i *v5; // rbx
__int64 result; // rax
__m128i *v8; // r12
__m128i *v9; // rax
__m128i *v10; // rax
__m128i *v11; // rax
__m128i *v12; // rax

v5 = (const __m128i *)(a1 + *a2);
switch ( a3 )
{
case 1:
v8 = (__m128i *)malloc(0x38uLL);
*v8 = _mm_loadu_si128(v5);
v8[1] = _mm_loadu_si128(v5 + 1);
v8[2] = _mm_loadu_si128(v5 + 2);
v8[3].m128i_i64[0] = v5[3].m128i_i64[0];
list_insert_node(lst, v8, 6LL);
*a5 = swapi(v8[3].m128i_u32[0]);
result = 56LL;
break;
case 2:
v9 = (__m128i *)malloc(0x18uLL);
*v9 = _mm_loadu_si128(v5);
v9[1].m128i_i64[0] = v5[1].m128i_i64[0];
list_insert_node(lst, v9, 7LL);
result = 24LL;
break;
case 11:
v11 = (__m128i *)malloc(0x50uLL);
*v11 = _mm_loadu_si128(v5);
v11[1] = _mm_loadu_si128(v5 + 1);
v11[2] = _mm_loadu_si128(v5 + 2);
v11[3] = _mm_loadu_si128(v5 + 3);
v11[4] = _mm_loadu_si128(v5 + 4);
list_insert_node(lst, v11, 9LL);
result = 80LL;
break;
case 12:
dynamic = 1;
v10 = (__m128i *)malloc(0x18uLL);
*v10 = _mm_loadu_si128(v5);
v10[1].m128i_i64[0] = v5[1].m128i_i64[0];
list_insert_node(lst, v10, 8LL);
result = 24LL;
break;
case 13:
mprintf("id dylib\n");
result = 0LL;
break;
case 14:
result = 12LL;
break;
case 17:
mprintf("routines\n");
result = 0LL;
break;
case 22:
v12 = (__m128i *)malloc(0x10uLL);
*v12 = _mm_loadu_si128(v5);
list_insert_node(lst, v12, 10LL);
result = 16LL;
break;
default:
result = 0LL;
break;
}
return result;
}

original_code:
int
examine_segmet(char *buffer, int *offset, int cmd, int cmdsize, int *nofx)
{
 struct segment_command *sc;
 struct symtab_command *symc;
 struct dylib_command *dly;
 struct dylinker_command *dlnk;
 struct dysymtab_command *dsym;
 struct twolevel_hints_command *two;
 int ret = 0;
 char *ptr;
 ptr = buffer;
 ptr += *offset;
 switch(cmd) {
  case 0x1:
   sc = malloc(sizeof(*sc));
   memcpy(sc, ptr, sizeof(*sc));
   list_insert_node(lst, sc, 0x6);
   *nofx = swapi(sc->nsects);
   ret = sizeof(*sc);
   break;
  case 0x2:
   symc = malloc(sizeof(*symc));
   memcpy(symc, ptr, sizeof(*symc));
   list_insert_node(lst, symc, 0x7);
   ret = sizeof(*symc);
   break;
  case 0xc:
   dynamic = 1;
   dly = malloc(sizeof(*dly));
   memcpy(dly, ptr, sizeof(*dly));
   list_insert_node(lst, dly, 0x8);
   ret = sizeof(*dly);
   break;
  case 0xe:
   dlnk = malloc(sizeof(*dlnk));
   memcpy(dlnk, ptr, sizeof(*dlnk));
   ret = sizeof(*dlnk);
   break;
  case 0xb:
   dsym = malloc(sizeof(*dsym));
   memcpy(dsym, ptr, sizeof(*dsym));
   list_insert_node(lst, dsym, 0x9);
   ret = sizeof(*dsym);
   break;
  case 0x16:
   two = malloc(sizeof(*two));
   memcpy(two, ptr, sizeof(*two));
   list_insert_node(lst, two, 0xa);
   ret = sizeof(*two);
   break;
  case 0x4:
  case 0x5:
   break;
  case 0x11:
   mprintf("routines\n");
   break;
  case 0xd:
   mprintf("id dylib\n");
   break;
  default:
   break;
 }
 return (ret);
}

variable_types: cmd int

variable_types: cmdsize int

variable_types:
nofx
int *

variable_types: struct segment_command { unsigned int cmd; unsigned int cmdsize; char segname[16]; unsigned int vmaddr; unsigned int vmsize; unsigned int fileoff; unsigned int filesize; int maxprot; int initprot; unsigned int nsects; unsigned int flags; } *

variable_types: struct symtab_command { unsigned int cmd; unsigned int cmdsize; unsigned int symoff; unsigned int nsyms; unsigned int stroff; unsigned int strsize; } *

variable_types: struct dylib_command { unsigned int cmd; unsigned int cmdsize; struct dylib { union lc_str { unsigned int offset; } name; unsigned int timestamp; unsigned int current_version; unsigned int compatibility_version; } dylib; } *

variable_types: struct dylinker_command { unsigned int cmd; unsigned int cmdsize; union lc_str { unsigned int offset; } name; } *

variable_types: struct dysymtab_command { unsigned int cmd; unsigned int cmdsize; unsigned int ilocalsym; unsigned int nlocalsym; unsigned int iextdefsym; unsigned int nextdefsym; unsigned int iundefsym; unsigned int nundefsym; unsigned int tocoff; unsigned int ntoc; unsigned int modtaboff; unsigned int nmodtab; unsigned int extrefsymoff; unsigned int nextrefsyms; unsigned int indirectsymoff; unsigned int nindirectsyms; unsigned int extreloff; unsigned int nextrel; unsigned int locreloff; unsigned int nlocrel; } *

variable_types: struct twolevel_hints_command { unsigned int cmd; unsigned int cmdsize; unsigned int offset; unsigned int nhints; } *

user_defined_types: struct dylib_command { unsigned int cmd; unsigned int cmdsize; struct dylib dylib; }

user_defined_types: struct dylinker_command { unsigned int cmd; unsigned int cmdsize; union lc_str name; }

user_defined_types: struct dylib { union lc_str name; unsigned int timestamp; unsigned int current_version; unsigned int compatibility_version; }


original_code:
void
display_buffer(char *buffer, int addr, int offset, int size)
{
 char *ptr;
 char line[17];
 int i, j=0;
 if (offset < 0)
  return;
 printf("Starting at address 0x%x offset %d size %d\n", addr, offset, size);
 ptr = buffer;
 ptr += offset;
 ptr += offset_moh;
 offset += offset_moh;
 memset(line, 0, sizeof(line));
 for (i = 0; i < size; i++) {
  if (j == 0)
   printf("%.08x  ", offset+i);
  printf("%.02x ", (*ptr & 0xFF));
  if (((*__ctype_b_loc ())[(int) ((*ptr & 0xFF))] & (unsigned short int) _ISprint))
   line[j] = (*ptr & 0xFF);
  else
   line[j] = '.';
  j++;
  if (j == 16) {
   printf(" %s\n", line);
   j = 0;
  } else if (j == 8)
   printf(" ");
  ptr += 1;
 }
 printf("\n");
}

canonical_original_code:
void display_buffer(char *buffer, int addr, int offset, int size)
{
 char *ptr;
 char line[17];
 int i; int j = 0;
 if (offset < 0)
  return;
 printf("Starting at address 0x%x offset %d size %d\n", addr, offset, size);
 ptr = buffer;
 ptr += offset;
 ptr += offset_moh;
 offset += offset_moh;
 memset(line, 0, sizeof(line));
 for (i = 0; i < size; i++) {
  if (j == 0)
   printf("%.08x  ", offset+i);
  printf("%.02x ", (*ptr & 0xFF));
  if (((*__ctype_b_loc ())[(int) ((*ptr & 0xFF))] & (unsigned short) _ISprint))
   line[j] = (*ptr & 0xFF);
  else
   line[j] = '.';
  j++;
  if (j == 16) {
   printf(" %s\n", line);
   j = 0;
  } else if (j == 8)
   printf(" ");
  ptr += 1;
 }
 printf("\n");
}

variable_types:
buffer
char *

variable_types: addr int

variable_types: offset int

variable_types: size int

variable_types:
line
char [17]

variable_types: i int

variable_types: j int


mean

decompiled_code:
double __fastcall mean(_QWORD *a1, __int64 a2)
{
_QWORD *v2; // rax
double v3; // xmm0_8

if ( a2 <= 0 )
{
v3 = 0.0;
}
else
{
v2 = a1;
v3 = 0.0;
do
v3 = v3 + (double)(int)*v2++;
while ( v2 != &a1[a2] );
}
return v3 / (double)(int)a2;
}

canonical_decompiled_code:
double __fastcall func0(_QWORD *a1, __int64 a2)
{
_QWORD *v2; // rax
double v3; // xmm0_8

if ( a2 <= 0 )
{
v3 = 0.0;
}
else
{
v2 = a1;
v3 = 0.0;
do
v3 = v3 + (double)(int)*v2++;
while ( v2 != &a1[a2] );
}
return v3 / (double)(int)a2;
}

original_code:
double mean( long int *values, long int max )
{
  long int j;
  double m;
  m = 0.;
  for ( j = 0 ; j < max ; j++ ) {
    m += (double)values[j];
  }
  m = m / (double)max;
  return m;
}

canonical_original_code:
double mean(long *values, long max)
{
  long j;
  double m;
  m = 0.;
  for ( j = 0 ; j < max ; j++ ) {
    m += (double)values[j];
  }
  m = m / (double)max;
  return m;
}

variable_types:
values
long *

variable_types: max long

variable_types: j long

variable_types: m double

return_type: double


meanr

decompiled_code:
double __fastcall meanr(double *a1, __int64 a2)
{
double *v2; // rax
double v3; // xmm0_8

if ( a2 <= 0 )
{
v3 = 0.0;
}
else
{
v2 = a1;
v3 = 0.0;
do
v3 = v3 + *v2++;
while ( v2 != &a1[a2] );
}
return v3 / (double)(int)a2;
}

canonical_decompiled_code:
double __fastcall func1(double *a1, __int64 a2)
{
double *v2; // rax
double v3; // xmm0_8

if ( a2 <= 0 )
{
v3 = 0.0;
}
else
{
v2 = a1;
v3 = 0.0;
do
v3 = v3 + *v2++;
while ( v2 != &a1[a2] );
}
return v3 / (double)(int)a2;
}

original_code:
double meanr( double *values, long int max )
{
  long int j;
  double m;
  m = 0.;
  for ( j = 0 ; j < max ; j++ ) {
    m += values[j];
  }
  m = m / (double)max;
  return m;
}

canonical_original_code:
double meanr(double *values, long max)
{
  long j;
  double m;
  m = 0.;
  for ( j = 0 ; j < max ; j++ ) {
    m += values[j];
  }
  m = m / (double)max;
  return m;
}

variable_types:
values
double *


decompiled_code:
double __fastcall std_deviation(_QWORD *a1, __int64 a2, double a3)
{
_QWORD *v3; // rax
double v4; // xmm1_8
double v5; // xmm1_8
double result; // xmm0_8

if ( a2 <= 1 )
return 0.0;
v3 = a1;
v4 = 0.0;
do
{
v4 = v4 + ((double)(int)*v3 - a3) * ((double)(int)*v3 - a3);
++v3;
}
while ( v3 != &a1[a2] );
v5 = v4 / (double)((int)a2 - 1);
if ( v5 < 0.0 )
result = sqrt(v5);
else
result = sqrt(v5);
return result;
}

canonical_decompiled_code:
double __fastcall func2(_QWORD *a1, __int64 a2, double a3)
{
_QWORD *v3; // rax
double v4; // xmm1_8
double v5; // xmm1_8
double result; // xmm0_8

if ( a2 <= 1 )
return 0.0;
v3 = a1;
v4 = 0.0;
do
{
v4 = v4 + ((double)(int)*v3 - a3) * ((double)(int)*v3 - a3);
++v3;
}
while ( v3 != &a1[a2] );
v5 = v4 / (double)((int)a2 - 1);
if ( v5 < 0.0 )
result = sqrt(v5);
else
result = sqrt(v5);
return result;
}

original_code:
double std_deviation( long int *values, long int max, double mean )
{
  long int j;
  double dev = 0.;
  if (max <= 1)
    return 0.;
  for ( j = 0 ; j < max; j++ ) {
    dev += ((double)values[j] - mean) * ((double)values[j] - mean);
  }
  return sqrt(dev/(double)(max - 1));
}

canonical_original_code:
double std_deviation(long *values, long max, double mean)
{
  long j;
  double dev = 0.;
  if (max <= 1)
    return 0.;
  for ( j = 0 ; j < max; j++ ) {
    dev += ((double)values[j] - mean) * ((double)values[j] - mean);
  }
  return sqrt(dev/(double)(max - 1));
}

variable_types: mean double

variable_types: dev double


decompiled_code:
double __fastcall std_deviationr(double *a1, __int64 a2, double a3)
{
double *v3; // rax
double v4; // xmm1_8
double v5; // xmm1_8
double result; // xmm0_8

if ( a2 <= 1 )
return 0.0;
v3 = a1;
v4 = 0.0;
do
{
v4 = v4 + (*v3 - a3) * (*v3 - a3);
++v3;
}
while ( v3 != &a1[a2] );
v5 = v4 / (double)((int)a2 - 1);
if ( v5 < 0.0 )
result = sqrt(v5);
else
result = sqrt(v5);
return result;
}

canonical_decompiled_code:
double __fastcall func3(double *a1, __int64 a2, double a3)
{
double *v3; // rax
double v4; // xmm1_8
double v5; // xmm1_8
double result; // xmm0_8

if ( a2 <= 1 )
return 0.0;
v3 = a1;
v4 = 0.0;
do
{
v4 = v4 + (*v3 - a3) * (*v3 - a3);
++v3;
}
while ( v3 != &a1[a2] );
v5 = v4 / (double)((int)a2 - 1);
if ( v5 < 0.0 )
result = sqrt(v5);
else
result = sqrt(v5);
return result;
}

original_code:
double std_deviationr( double *values, long int max, double mean )
{
  long int j;
  double dev;
  if (max <= 1)
    return 0.;
  dev = 0.;
  for ( j = 0 ; j < max ; j++ ) {
    dev += ((double)values[j] - mean) * ((double)values[j] - mean);
  }
  return sqrt(dev/(double)(max - 1));
}

canonical_original_code:
double std_deviationr(double *values, long max, double mean)
{
  long j;
  double dev;
  if (max <= 1)
    return 0.;
  dev = 0.;
  for ( j = 0 ; j < max ; j++ ) {
    dev += ((double)values[j] - mean) * ((double)values[j] - mean);
  }
  return sqrt(dev/(double)(max - 1));
}


original_code:
long int best_of_vector( long int *values, long int l )
{
  long int min, k;
  k = 0;
  min = values[k];
  for( k = 1 ; k < l ; k++ ) {
    if( values[k] < min ) {
      min = values[k];
    }
  }
  return min;
}

canonical_original_code:
long best_of_vector(long *values, long l)
{
  long min; long k;
  k = 0;
  min = values[k];
  for( k = 1 ; k < l ; k++ ) {
    if( values[k] < min ) {
      min = values[k];
    }
  }
  return min;
}

variable_types: l long

variable_types: min long

variable_types: k long

return_type: long


original_code:
long int worst_of_vector( long int *values, long int l )
{
  long int max, k;
  k = 0;
  max = values[k];
  for( k = 1 ; k < l ; k++ ) {
    if( values[k] > max ){
      max = values[k];
    }
  }
  return max;
}

canonical_original_code:
long worst_of_vector(long *values, long l)
{
  long max; long k;
  k = 0;
  max = values[k];
  for( k = 1 ; k < l ; k++ ) {
    if( values[k] > max ){
      max = values[k];
    }
  }
  return max;
}


original_code:
void swap2(long int v[], long int v2[], long int i, long int j)
{
  long int tmp;
  tmp = v[i];
  v[i] = v[j];
  v[j] = tmp;
  tmp = v2[i];
  v2[i] = v2[j];
  v2[j] = tmp;
}

canonical_original_code:
void swap2(long v[], long v2[], long i, long j)
{
  long tmp;
  tmp = v[i];
  v[i] = v[j];
  v[j] = tmp;
  tmp = v2[i];
  v2[i] = v2[j];
  v2[j] = tmp;
}

variable_types:
v
long []

variable_types: i long

variable_types: tmp long


original_code:
void sort2(long int v[], long int v2[], long int left, long int right)
{
  long int k, last;
  if (left >= right)
    return;
  swap2(v, v2, left, (left + right)/2);
  last = left;
  for (k=left+1; k <= right; k++)
    if (v[k] < v[left])
      swap2(v, v2, ++last, k);
  swap2(v, v2, left, last);
  sort2(v, v2, left, last);
  sort2(v, v2, last+1, right);
}

canonical_original_code:
void sort2(long v[], long v2[], long left, long right)
{
  long k; long last;
  if (left >= right)
    return;
  swap2(v, v2, left, (left + right)/2);
  last = left;
  for (k=left+1; k <= right; k++)
    if (v[k] < v[left])
      swap2(v, v2, ++last, k);
  swap2(v, v2, left, last);
  sort2(v, v2, left, last);
  sort2(v, v2, last+1, right);
}

variable_types: left long

variable_types: right long

variable_types: last long


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

v1 = -2836 * ((__int64)*a1 / 127773) + 16807 * ((__int64)*a1 % 127773);
result = v1 + (v1 < 0 ? 0x7FFFFFFFuLL : 0);
*a1 = result;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func11(unsigned __int64 *a1)
{
__int64 v1; // rax
unsigned __int64 result; // rax

v1 = -2836 * ((__int64)*a1 / 127773) + 16807 * ((__int64)*a1 % 127773);
result = v1 + (v1 < 0 ? 0x7FFFFFFFuLL : 0);
*a1 = result;
return result;
}

original_code:
long int random_number( long *idum )
{
  long k;
  k =(*idum)/127773;
  *idum = 16807 * (*idum - k * 127773) - 2836 * k;
  if (*idum < 0 ) *idum += 2147483647;
  return *idum;
}

variable_types:
idum
long *


decompiled_code:
__int64 termination_condition()
{
__int64 result; // rax
double v1; // xmm0_8

if ( n_tours < max_tours || (v1 = elapsed_time(1LL), LODWORD(result) = 1, v1 < max_time) )
LODWORD(result) = *(_QWORD *)(best_so_far_ant + 16LL) <= optimal;
return (int)result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
double v1; // xmm0_8

if ( n_tours < max_tours || (v1 = elapsed_time(1LL), LODWORD(result) = 1, v1 < max_time) )
LODWORD(result) = *(_QWORD *)(best_so_far_ant + 16LL) <= optimal;
return (int)result;
}

original_code:
long int termination_condition( void )
{
  return ( ((n_tours >= max_tours) && (elapsed_time( VIRTUAL ) >= max_time)) ||
   ((*best_so_far_ant).tour_length <= optimal));
}

canonical_original_code:
long termination_condition()
{
  return ( ((n_tours >= max_tours) && (elapsed_time( VIRTUAL ) >= max_time)) ||
   ((*best_so_far_ant).tour_length <= optimal));
}


decompiled_code:
__int64 construct_solutions()
{
__int64 v0; // rbp
__int64 v1; // rbx
__int64 v2; // rbp
__int64 v3; // rbx
__int64 v4; // r13
__int64 v5; // r12
__int64 v6; // rbx
__int64 result; // rax
__int64 v8; // rbx
_QWORD *v9; // rbp

if ( n_ants <= 0 )
{
if ( n <= 1 )
{
result = n_ants;
goto LABEL_22;
}
}
else
{
v0 = 0LL;
v1 = 0LL;
do
{
ant_empty_memory((char *)ant + v0);
++v1;
v0 += 24LL;
}
while ( n_ants > v1 );
if ( n_ants > 0 )
{
v2 = 0LL;
v3 = 0LL;
do
{
place_ant((char *)ant + v2, 0LL);
++v3;
v2 += 24LL;
}
while ( n_ants > v3 );
}
v4 = n;
if ( n <= 1 )
goto LABEL_15;
}
v5 = 0LL;
do
{
++v5;
if ( n_ants > 0 )
{
v6 = 0LL;
do
{
neighbour_choose_and_move_to_next((char *)ant + 24 * v6, v5);
if ( acs_flag )
local_acs_pheromone_update((char *)ant + 24 * v6, v5);
++v6;
}
while ( n_ants > v6 );
}
v4 = n;
}
while ( n - 1 > v5 );
LABEL_15:
result = n_ants;
if ( n_ants > 0 )
{
v8 = 0LL;
do
{
*(_QWORD *)(*((_QWORD *)ant + 3 * v8) + 8 * n) = **((_QWORD **)ant + 3 * v8);
v9 = (char *)ant + 24 * v8;
v9[2] = compute_tour_length(*v9);
if ( acs_flag )
local_acs_pheromone_update((char *)ant + 24 * v8, v4);
++v8;
result = n_ants;
}
while ( n_ants > v8 );
}
LABEL_22:
n_tours += result;
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rbp
__int64 v1; // rbx
__int64 v2; // rbp
__int64 v3; // rbx
__int64 v4; // r13
__int64 v5; // r12
__int64 v6; // rbx
__int64 result; // rax
__int64 v8; // rbx
_QWORD *v9; // rbp

if ( n_ants <= 0 )
{
if ( n <= 1 )
{
result = n_ants;
goto LABEL_22;
}
}
else
{
v0 = 0LL;
v1 = 0LL;
do
{
ant_empty_memory((char *)ant + v0);
++v1;
v0 += 24LL;
}
while ( n_ants > v1 );
if ( n_ants > 0 )
{
v2 = 0LL;
v3 = 0LL;
do
{
place_ant((char *)ant + v2, 0LL);
++v3;
v2 += 24LL;
}
while ( n_ants > v3 );
}
v4 = n;
if ( n <= 1 )
goto LABEL_15;
}
v5 = 0LL;
do
{
++v5;
if ( n_ants > 0 )
{
v6 = 0LL;
do
{
neighbour_choose_and_move_to_next((char *)ant + 24 * v6, v5);
if ( acs_flag )
local_acs_pheromone_update((char *)ant + 24 * v6, v5);
++v6;
}
while ( n_ants > v6 );
}
v4 = n;
}
while ( n - 1 > v5 );
LABEL_15:
result = n_ants;
if ( n_ants > 0 )
{
v8 = 0LL;
do
{
*(_QWORD *)(*((_QWORD *)ant + 3 * v8) + 8 * n) = **((_QWORD **)ant + 3 * v8);
v9 = (char *)ant + 24 * v8;
v9[2] = compute_tour_length(*v9);
if ( acs_flag )
local_acs_pheromone_update((char *)ant + 24 * v8, v4);
++v8;
result = n_ants;
}
while ( n_ants > v8 );
}
LABEL_22:
n_tours += result;
return result;
}

original_code:
void construct_solutions( void )
{
    long int k;
    long int step;
    ;
    for ( k = 0 ; k < n_ants ; k++) {
 ant_empty_memory( &ant[k] );
    }
    step = 0;
    for ( k = 0 ; k < n_ants ; k++ )
 place_ant( &ant[k], step);
    while ( step < n-1 ) {
 step++;
 for ( k = 0 ; k < n_ants ; k++ ) {
     neighbour_choose_and_move_to_next( &ant[k], step);
     if ( acs_flag )
  local_acs_pheromone_update( &ant[k], step );
 }
    }
    step = n;
    for ( k = 0 ; k < n_ants ; k++ ) {
 ant[k].tour[n] = ant[k].tour[0];
 ant[k].tour_length = compute_tour_length( ant[k].tour );
 if ( acs_flag )
     local_acs_pheromone_update( &ant[k], step );
    }
    n_tours += n_ants;
}

canonical_original_code:
void construct_solutions()
{
    long k;
    long step;
    ;
    for ( k = 0 ; k < n_ants ; k++) {
 ant_empty_memory( &ant[k] );
    }
    step = 0;
    for ( k = 0 ; k < n_ants ; k++ )
 place_ant( &ant[k], step);
    while ( step < n-1 ) {
 step++;
 for ( k = 0 ; k < n_ants ; k++ ) {
     neighbour_choose_and_move_to_next( &ant[k], step);
     if ( acs_flag )
  local_acs_pheromone_update( &ant[k], step );
 }
    }
    step = n;
    for ( k = 0 ; k < n_ants ; k++ ) {
 ant[k].tour[n] = ant[k].tour[0];
 ant[k].tour_length = compute_tour_length( ant[k].tour );
 if ( acs_flag )
     local_acs_pheromone_update( &ant[k], step );
    }
    n_tours += n_ants;
}

variable_types: step long


decompiled_code:
int __fastcall init_try(__int64 a1)
{
double v2; // [rsp+8h] [rbp-10h]
double v3; // [rsp+8h] [rbp-10h]

start_timers();
time_used = elapsed_time(1LL);
time_passed = time_used;
fprintf(comp_report, "seed %ld\n", seed);
fflush(comp_report);
n_tours = 1LL;
iteration = 1LL;
restart_iteration = 1LL;
lambda = LC1;
*(_QWORD *)(best_so_far_ant + 16LL) = 0x7FFFFFFFFFFFFFFFLL;
found_best = 0LL;
if ( acs_flag )
goto LABEL_6;
if ( !mmas_flag )
{
if ( bwas_flag )
goto LABEL_4;
trail_0 = 1.0 / ((double)(int)nn_tour() * rho);
init_pheromone_trails();
LABEL_6:
if ( !bwas_flag )
{
LABEL_7:
if ( !mmas_flag )
goto LABEL_8;
goto LABEL_12;
}
LABEL_4:
v2 = (double)(int)n;
trail_0 = 1.0 / ((double)(int)nn_tour() * v2);
init_pheromone_trails();
goto LABEL_7;
}
if ( bwas_flag )
goto LABEL_4;
LABEL_12:
trail_max = 1.0 / ((double)(int)nn_tour() * rho);
trail_min = trail_max / ((double)(int)n + (double)(int)n);
init_pheromone_trails();
LABEL_8:
if ( acs_flag )
{
v3 = (double)(int)n;
trail_0 = 1.0 / ((double)(int)nn_tour() * v3);
init_pheromone_trails();
}
compute_total_information();
fprintf(comp_report, "begin try %li \n", a1);
return fprintf(stat_report, "begin try %li \n", a1);
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
double v2; // [rsp+8h] [rbp-10h]
double v3; // [rsp+8h] [rbp-10h]

start_timers();
time_used = elapsed_time(1LL);
time_passed = time_used;
fprintf(comp_report, "seed %ld\n", seed);
fflush(comp_report);
n_tours = 1LL;
iteration = 1LL;
restart_iteration = 1LL;
lambda = LC1;
*(_QWORD *)(best_so_far_ant + 16LL) = 0x7FFFFFFFFFFFFFFFLL;
found_best = 0LL;
if ( acs_flag )
goto LABEL_6;
if ( !mmas_flag )
{
if ( bwas_flag )
goto LABEL_4;
trail_0 = 1.0 / ((double)(int)nn_tour() * rho);
init_pheromone_trails();
LABEL_6:
if ( !bwas_flag )
{
LABEL_7:
if ( !mmas_flag )
goto LABEL_8;
goto LABEL_12;
}
LABEL_4:
v2 = (double)(int)n;
trail_0 = 1.0 / ((double)(int)nn_tour() * v2);
init_pheromone_trails();
goto LABEL_7;
}
if ( bwas_flag )
goto LABEL_4;
LABEL_12:
trail_max = 1.0 / ((double)(int)nn_tour() * rho);
trail_min = trail_max / ((double)(int)n + (double)(int)n);
init_pheromone_trails();
LABEL_8:
if ( acs_flag )
{
v3 = (double)(int)n;
trail_0 = 1.0 / ((double)(int)nn_tour() * v3);
init_pheromone_trails();
}
compute_total_information();
fprintf(comp_report, "begin try %li \n", a1);
return fprintf(stat_report, "begin try %li \n", a1);
}

original_code:
void init_try( long int ntry )
{
    ;
    start_timers();
    time_used = elapsed_time( VIRTUAL );
    time_passed = time_used;
    fprintf(comp_report,"seed %ld\n",seed);
    fflush(comp_report);
    n_tours = 1;
    iteration = 1;
    restart_iteration = 1;
    lambda = 0.05;
    (*best_so_far_ant).tour_length = 0x7fffffffffffffffL;
    found_best = 0;
    if ( !(acs_flag || mmas_flag || bwas_flag) ) {
 trail_0 = 1. / ( (rho) * nn_tour() );
 init_pheromone_trails( trail_0 );
    }
    if ( bwas_flag ) {
 trail_0 = 1. / ( (double) n * (double) nn_tour()) ;
 init_pheromone_trails( trail_0 );
    }
    if ( mmas_flag ) {
 trail_max = 1. / ( (rho) * nn_tour() );
 trail_min = trail_max / ( 2. * n );
 init_pheromone_trails( trail_max );
    }
    if ( acs_flag ) {
 trail_0 = 1. / ( (double) n * (double) nn_tour( ) ) ;
 init_pheromone_trails( trail_0 );
    }
    compute_total_information();
    fprintf(comp_report,"begin try %li \n",ntry);
    fprintf(stat_report,"begin try %li \n",ntry);
}

canonical_original_code:
void init_try(long ntry)
{
    ;
    start_timers();
    time_used = elapsed_time( VIRTUAL );
    time_passed = time_used;
    fprintf(comp_report,"seed %ld\n",seed);
    fflush(comp_report);
    n_tours = 1;
    iteration = 1;
    restart_iteration = 1;
    lambda = 0.05;
    (*best_so_far_ant).tour_length = 0x7fffffffffffffffL;
    found_best = 0;
    if ( !(acs_flag || mmas_flag || bwas_flag) ) {
 trail_0 = 1. / ( (rho) * nn_tour() );
 init_pheromone_trails( trail_0 );
    }
    if ( bwas_flag ) {
 trail_0 = 1. / ( (double) n * (double) nn_tour()) ;
 init_pheromone_trails( trail_0 );
    }
    if ( mmas_flag ) {
 trail_max = 1. / ( (rho) * nn_tour() );
 trail_min = trail_max / ( 2. * n );
 init_pheromone_trails( trail_max );
    }
    if ( acs_flag ) {
 trail_0 = 1. / ( (double) n * (double) nn_tour( ) ) ;
 init_pheromone_trails( trail_0 );
    }
    compute_total_information();
    fprintf(comp_report,"begin try %li \n",ntry);
    fprintf(stat_report,"begin try %li \n",ntry);
}

variable_types: ntry long


decompiled_code:
void local_search()
{
__int64 v0; // rbx
__int64 v1; // rbp
char *v2; // r12

if ( n_ants > 0 )
{
v0 = 0LL;
v1 = 0LL;
do
{
switch ( ls_flag )
{
case 1LL:
two_opt_first(*(_QWORD *)((char *)ant + v0));
break;
case 2LL:
two_h_opt_first(*(_QWORD *)((char *)ant + v0));
break;
case 3LL:
three_opt_first(*(_QWORD *)((char *)ant + v0));
break;
default:
fwrite("type of local search procedure not correctly specified\n", 1uLL, 0x37uLL, stderr);
exit(1);
}
v2 = (char *)ant + v0;
*((_QWORD *)v2 + 2) = compute_tour_length(*(_QWORD *)((char *)ant + v0));
++v1;
v0 += 24LL;
}
while ( n_ants > v1 );
}
}

canonical_decompiled_code:
void func3()
{
__int64 v0; // rbx
__int64 v1; // rbp
char *v2; // r12

if ( n_ants > 0 )
{
v0 = 0LL;
v1 = 0LL;
do
{
switch ( ls_flag )
{
case 1LL:
two_opt_first(*(_QWORD *)((char *)ant + v0));
break;
case 2LL:
two_h_opt_first(*(_QWORD *)((char *)ant + v0));
break;
case 3LL:
three_opt_first(*(_QWORD *)((char *)ant + v0));
break;
default:
fwrite("type of local search procedure not correctly specified\n", 1uLL, 0x37uLL, stderr);
exit(1);
}
v2 = (char *)ant + v0;
*((_QWORD *)v2 + 2) = compute_tour_length(*(_QWORD *)((char *)ant + v0));
++v1;
v0 += 24LL;
}
while ( n_ants > v1 );
}
}

original_code:
void local_search( void )
{
    long int k;
    ;
    for ( k = 0 ; k < n_ants ; k++ ) {
 if ( ls_flag == 1 )
     two_opt_first( ant[k].tour );
 else if ( ls_flag == 2 )
     two_h_opt_first( ant[k].tour );
 else if ( ls_flag == 3 )
     three_opt_first( ant[k].tour );
 else {
     fprintf(stderr,"type of local search procedure not correctly specified\n");
     exit(1);
 }
 ant[k].tour_length = compute_tour_length( ant[k].tour );
    }
}

canonical_original_code:
void local_search()
{
    long k;
    ;
    for ( k = 0 ; k < n_ants ; k++ ) {
 if ( ls_flag == 1 )
     two_opt_first( ant[k].tour );
 else if ( ls_flag == 2 )
     two_h_opt_first( ant[k].tour );
 else if ( ls_flag == 3 )
     three_opt_first( ant[k].tour );
 else {
     fprintf(stderr,"type of local search procedure not correctly specified\n");
     exit(1);
 }
 ant[k].tour_length = compute_tour_length( ant[k].tour );
    }
}


decompiled_code:
int update_statistics()
{
__int64 v0; // rbx
char *v1; // rbx
__int64 v2; // rax
double v3; // xmm2_8
double v4; // xmm0_8

v0 = 24 * find_best();
if ( *(_QWORD *)((char *)ant + v0 + 16) < *(_QWORD *)(best_so_far_ant + 16LL) )
{
time_used = elapsed_time(1LL);
copy_from_to((char *)ant + v0, best_so_far_ant);
copy_from_to((char *)ant + v0, restart_best_ant);
found_best = iteration;
restart_found_best = iteration;
found_branching = node_branching(lambda);
branching_factor = found_branching;
if ( mmas_flag )
{
if ( ls_flag )
{
trail_max = 1.0 / ((double)(int)*(_QWORD *)(best_so_far_ant + 16LL) * rho);
trail_min = trail_max / ((double)(int)n + (double)(int)n);
trail_0 = trail_max;
}
else
{
v3 = exp(-2.995732273553991 / (double)(int)n);
trail_max = 1.0 / ((double)(int)*(_QWORD *)(best_so_far_ant + 16LL) * rho);
trail_0 = trail_max;
trail_min = trail_max * ((1.0 - v3) / (v3 * (double)(int)((nn_ants + 1LL) / 2)));
}
}
write_report();
}
v1 = (char *)ant + v0;
v2 = *(_QWORD *)(restart_best_ant + 16LL);
if ( *((_QWORD *)v1 + 2) < v2 )
{
copy_from_to(v1, restart_best_ant);
restart_found_best = iteration;
v4 = elapsed_time(1LL);
LODWORD(v2) = printf(
"restart best: %ld, restart_found_best %ld, time %.2f\n",
*(_QWORD *)(restart_best_ant + 16LL),
restart_found_best,
v4);
}
return v2;
}

canonical_decompiled_code:
int func4()
{
__int64 v0; // rbx
char *v1; // rbx
__int64 v2; // rax
double v3; // xmm2_8
double v4; // xmm0_8

v0 = 24 * find_best();
if ( *(_QWORD *)((char *)ant + v0 + 16) < *(_QWORD *)(best_so_far_ant + 16LL) )
{
time_used = elapsed_time(1LL);
copy_from_to((char *)ant + v0, best_so_far_ant);
copy_from_to((char *)ant + v0, restart_best_ant);
found_best = iteration;
restart_found_best = iteration;
found_branching = node_branching(lambda);
branching_factor = found_branching;
if ( mmas_flag )
{
if ( ls_flag )
{
trail_max = 1.0 / ((double)(int)*(_QWORD *)(best_so_far_ant + 16LL) * rho);
trail_min = trail_max / ((double)(int)n + (double)(int)n);
trail_0 = trail_max;
}
else
{
v3 = exp(-2.995732273553991 / (double)(int)n);
trail_max = 1.0 / ((double)(int)*(_QWORD *)(best_so_far_ant + 16LL) * rho);
trail_0 = trail_max;
trail_min = trail_max * ((1.0 - v3) / (v3 * (double)(int)((nn_ants + 1LL) / 2)));
}
}
write_report();
}
v1 = (char *)ant + v0;
v2 = *(_QWORD *)(restart_best_ant + 16LL);
if ( *((_QWORD *)v1 + 2) < v2 )
{
copy_from_to(v1, restart_best_ant);
restart_found_best = iteration;
v4 = elapsed_time(1LL);
LODWORD(v2) = printf(
"restart best: %ld, restart_found_best %ld, time %.2f\n",
*(_QWORD *)(restart_best_ant + 16LL),
restart_found_best,
v4);
}
return v2;
}

original_code:
void update_statistics( void )
{
    long int iteration_best_ant;
    double p_x;
    iteration_best_ant = find_best();
    if ( ant[iteration_best_ant].tour_length < (*best_so_far_ant).tour_length ) {
 time_used = elapsed_time( VIRTUAL );
 copy_from_to( &ant[iteration_best_ant], best_so_far_ant );
 copy_from_to( &ant[iteration_best_ant], restart_best_ant );
 found_best = iteration;
 restart_found_best = iteration;
 found_branching = node_branching(lambda);
 branching_factor = found_branching;
 if ( mmas_flag ) {
     if ( !ls_flag ) {
  p_x = exp(log(0.05)/n);
  trail_min = 1. * (1. - p_x) / (p_x * (double)((nn_ants + 1) / 2));
  trail_max = 1. / ( (rho) * (*best_so_far_ant).tour_length );
  trail_0 = trail_max;
  trail_min = trail_max * trail_min;
     } else {
  trail_max = 1. / ( (rho) * (*best_so_far_ant).tour_length );
  trail_min = trail_max / ( 2. * n );
  trail_0 = trail_max;
     }
 }
 write_report();
    }
    if ( ant[iteration_best_ant].tour_length < (*restart_best_ant).tour_length ) {
 copy_from_to( &ant[iteration_best_ant], restart_best_ant );
 restart_found_best = iteration;
 printf("restart best: %ld, restart_found_best %ld, time %.2f\n",(*restart_best_ant).tour_length, restart_found_best, elapsed_time ( VIRTUAL ));
    }
}

canonical_original_code:
void update_statistics()
{
    long iteration_best_ant;
    double p_x;
    iteration_best_ant = find_best();
    if ( ant[iteration_best_ant].tour_length < (*best_so_far_ant).tour_length ) {
 time_used = elapsed_time( VIRTUAL );
 copy_from_to( &ant[iteration_best_ant], best_so_far_ant );
 copy_from_to( &ant[iteration_best_ant], restart_best_ant );
 found_best = iteration;
 restart_found_best = iteration;
 found_branching = node_branching(lambda);
 branching_factor = found_branching;
 if ( mmas_flag ) {
     if ( !ls_flag ) {
  p_x = exp(log(0.05)/n);
  trail_min = 1. * (1. - p_x) / (p_x * (double)((nn_ants + 1) / 2));
  trail_max = 1. / ( (rho) * (*best_so_far_ant).tour_length );
  trail_0 = trail_max;
  trail_min = trail_max * trail_min;
     } else {
  trail_max = 1. / ( (rho) * (*best_so_far_ant).tour_length );
  trail_min = trail_max / ( 2. * n );
  trail_0 = trail_max;
     }
 }
 write_report();
    }
    if ( ant[iteration_best_ant].tour_length < (*restart_best_ant).tour_length ) {
 copy_from_to( &ant[iteration_best_ant], restart_best_ant );
 restart_found_best = iteration;
 printf("restart best: %ld, restart_found_best %ld, time %.2f\n",(*restart_best_ant).tour_length, restart_found_best, elapsed_time ( VIRTUAL ));
    }
}


decompiled_code:
int search_control_and_statistics()
{
__int64 v0; // rax
double v1; // rbx
double v2; // xmm0_8

v0 = 100 * (iteration / 100LL);
if ( iteration == v0 )
{
population_statistics();
v1 = node_branching(lambda);
branching_factor = *(_QWORD *)&v1;
v2 = elapsed_time(1LL);
printf(
"\nbest so far %ld, iteration: %ld, time %.2f, b_fac %.5f\n",
*(_QWORD *)(best_so_far_ant + 16LL),
iteration,
v2,
v1);
if ( mmas_flag && branch_fac > branching_factor && (__int64)(iteration - restart_found_best) > 250 )
{
puts("INIT TRAILS!!!");
*(_QWORD *)(restart_best_ant + 16LL) = 0x7FFFFFFFFFFFFFFFLL;
init_pheromone_trails(trail_max);
compute_total_information();
restart_iteration = iteration;
restart_time = elapsed_time(1LL);
}
LODWORD(v0) = printf("try %li, iteration %li, b-fac %f \n\n", n_try, iteration, branching_factor);
}
return v0;
}

canonical_decompiled_code:
int func5()
{
__int64 v0; // rax
double v1; // rbx
double v2; // xmm0_8

v0 = 100 * (iteration / 100LL);
if ( iteration == v0 )
{
population_statistics();
v1 = node_branching(lambda);
branching_factor = *(_QWORD *)&v1;
v2 = elapsed_time(1LL);
printf(
"\nbest so far %ld, iteration: %ld, time %.2f, b_fac %.5f\n",
*(_QWORD *)(best_so_far_ant + 16LL),
iteration,
v2,
v1);
if ( mmas_flag && branch_fac > branching_factor && (__int64)(iteration - restart_found_best) > 250 )
{
puts("INIT TRAILS!!!");
*(_QWORD *)(restart_best_ant + 16LL) = 0x7FFFFFFFFFFFFFFFLL;
init_pheromone_trails(trail_max);
compute_total_information();
restart_iteration = iteration;
restart_time = elapsed_time(1LL);
}
LODWORD(v0) = printf("try %li, iteration %li, b-fac %f \n\n", n_try, iteration, branching_factor);
}
return v0;
}

original_code:
void search_control_and_statistics( void )
{
    ;
    if (!(iteration % 100)) {
 population_statistics();
 branching_factor = node_branching(lambda);
 printf("\nbest so far %ld, iteration: %ld, time %.2f, b_fac %.5f\n",(*best_so_far_ant).tour_length,iteration,elapsed_time( VIRTUAL),branching_factor);
 if ( mmas_flag && (branching_factor < branch_fac) && (iteration - restart_found_best > 250) ) {
     printf("INIT TRAILS!!!\n"); (*restart_best_ant).tour_length = 0x7fffffffffffffffL;
     init_pheromone_trails( trail_max );
     compute_total_information();
     restart_iteration = iteration;
     restart_time = elapsed_time( VIRTUAL );
 }
 printf("try %li, iteration %li, b-fac %f \n\n", n_try,iteration,branching_factor);
    }
}

canonical_original_code:
void search_control_and_statistics()
{
    ;
    if (!(iteration % 100)) {
 population_statistics();
 branching_factor = node_branching(lambda);
 printf("\nbest so far %ld, iteration: %ld, time %.2f, b_fac %.5f\n",(*best_so_far_ant).tour_length,iteration,elapsed_time( VIRTUAL),branching_factor);
 if ( mmas_flag && (branching_factor < branch_fac) && (iteration - restart_found_best > 250) ) {
     printf("INIT TRAILS!!!\n"); (*restart_best_ant).tour_length = 0x7fffffffffffffffL;
     init_pheromone_trails( trail_max );
     compute_total_information();
     restart_iteration = iteration;
     restart_time = elapsed_time( VIRTUAL );
 }
 printf("try %li, iteration %li, b-fac %f \n\n", n_try,iteration,branching_factor);
    }
}


decompiled_code:
__int64 as_update()
{
__int64 v0; // rbp
__int64 v1; // rbx
__int64 result; // rax

if ( n_ants > 0 )
{
v0 = 0LL;
v1 = 0LL;
do
{
result = global_update_pheromone((char *)ant + v0);
++v1;
v0 += 24LL;
}
while ( n_ants > v1 );
}
return result;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 v0; // rbp
__int64 v1; // rbx
__int64 result; // rax

if ( n_ants > 0 )
{
v0 = 0LL;
v1 = 0LL;
do
{
result = global_update_pheromone((char *)ant + v0);
++v1;
v0 += 24LL;
}
while ( n_ants > v1 );
}
return result;
}

original_code:
void as_update( void )
{
    long int k;
    ;
    for ( k = 0 ; k < n_ants ; k++ )
 global_update_pheromone( &ant[k] );
}

canonical_original_code:
void as_update()
{
    long k;
    ;
    for ( k = 0 ; k < n_ants ; k++ )
 global_update_pheromone( &ant[k] );
}


decompiled_code:
__int64 eas_update()
{
__int64 v0; // rbp
__int64 v1; // rbx

if ( n_ants > 0 )
{
v0 = 0LL;
v1 = 0LL;
do
{
global_update_pheromone((char *)ant + v0);
++v1;
v0 += 24LL;
}
while ( n_ants > v1 );
}
return global_update_pheromone_weighted(best_so_far_ant, elitist_ants);
}

canonical_decompiled_code:
__int64 func7()
{
__int64 v0; // rbp
__int64 v1; // rbx

if ( n_ants > 0 )
{
v0 = 0LL;
v1 = 0LL;
do
{
global_update_pheromone((char *)ant + v0);
++v1;
v0 += 24LL;
}
while ( n_ants > v1 );
}
return global_update_pheromone_weighted(best_so_far_ant, elitist_ants);
}

original_code:
void eas_update( void )
{
    long int k;
    ;
    for ( k = 0 ; k < n_ants ; k++ )
 global_update_pheromone( &ant[k] );
    global_update_pheromone_weighted( best_so_far_ant, elitist_ants );
}

canonical_original_code:
void eas_update()
{
    long k;
    ;
    for ( k = 0 ; k < n_ants ; k++ )
 global_update_pheromone( &ant[k] );
    global_update_pheromone_weighted( best_so_far_ant, elitist_ants );
}


decompiled_code:
void ras_update()
{
__int64 v0; // r12
__int64 v1; // rbp
__int64 *v2; // rax
__int64 *v3; // rbx
__int64 *v4; // rdx
__int64 *v5; // rsi
__int64 v6; // r8
__int64 v7; // rbp
__int64 v8; // rcx
__int64 v9; // rax
__int64 v10; // rdi

v0 = n_ants;
v1 = n_ants;
v2 = (__int64 *)malloc(8LL * n_ants);
v3 = v2;
if ( v0 > 0 )
{
v4 = (__int64 *)((char *)ant + 16);
v5 = &v2[v1];
do
{
*v2 = *v4;
v4 += 3;
++v2;
}
while ( v2 != v5 );
}
v6 = ras_ranks;
if ( ras_ranks > 1 )
{
v7 = 0LL;
do
{
v8 = *v3;
v9 = 0LL;
v10 = 0LL;
if ( n_ants > 0 )
{
while ( ++v9 != n_ants )
{
if ( v3[v9] < v8 )
{
v10 = v9;
v8 = v3[v9];
}
}
}
v3[v10] = 0x7FFFFFFFFFFFFFFFLL;
global_update_pheromone_weighted((char *)ant + 24 * v10, v6 - v7++ - 1);
v6 = ras_ranks;
}
while ( ras_ranks - 1LL > v7 );
}
global_update_pheromone_weighted(best_so_far_ant, v6);
free(v3);
}

canonical_decompiled_code:
void func8()
{
__int64 v0; // r12
__int64 v1; // rbp
__int64 *v2; // rax
__int64 *v3; // rbx
__int64 *v4; // rdx
__int64 *v5; // rsi
__int64 v6; // r8
__int64 v7; // rbp
__int64 v8; // rcx
__int64 v9; // rax
__int64 v10; // rdi

v0 = n_ants;
v1 = n_ants;
v2 = (__int64 *)malloc(8LL * n_ants);
v3 = v2;
if ( v0 > 0 )
{
v4 = (__int64 *)((char *)ant + 16);
v5 = &v2[v1];
do
{
*v2 = *v4;
v4 += 3;
++v2;
}
while ( v2 != v5 );
}
v6 = ras_ranks;
if ( ras_ranks > 1 )
{
v7 = 0LL;
do
{
v8 = *v3;
v9 = 0LL;
v10 = 0LL;
if ( n_ants > 0 )
{
while ( ++v9 != n_ants )
{
if ( v3[v9] < v8 )
{
v10 = v9;
v8 = v3[v9];
}
}
}
v3[v10] = 0x7FFFFFFFFFFFFFFFLL;
global_update_pheromone_weighted((char *)ant + 24 * v10, v6 - v7++ - 1);
v6 = ras_ranks;
}
while ( ras_ranks - 1LL > v7 );
}
global_update_pheromone_weighted(best_so_far_ant, v6);
free(v3);
}

original_code:
void ras_update( void )
{
    long int i, k, b, target;
    long int *help_b;
    ;
    help_b = malloc( n_ants * sizeof(long int) );
    for ( k = 0 ; k < n_ants ; k++ )
 help_b[k] = ant[k].tour_length;
    for ( i = 0 ; i < ras_ranks-1 ; i++ ) {
 b = help_b[0]; target = 0;
 for ( k = 0 ; k < n_ants ; k++ ) {
     if ( help_b[k] < b ) {
  b = help_b[k]; target = k;
     }
 }
 help_b[target] = 0x7fffffffffffffffL;
 global_update_pheromone_weighted( &ant[target], ras_ranks-i-1 );
    }
    global_update_pheromone_weighted( best_so_far_ant, ras_ranks );
    free ( help_b );
}

canonical_original_code:
void ras_update()
{
    long i; long k; long b; long target;
    long *help_b;
    ;
    help_b = malloc( n_ants * sizeof(long) );
    for ( k = 0 ; k < n_ants ; k++ )
 help_b[k] = ant[k].tour_length;
    for ( i = 0 ; i < ras_ranks-1 ; i++ ) {
 b = help_b[0]; target = 0;
 for ( k = 0 ; k < n_ants ; k++ ) {
     if ( help_b[k] < b ) {
  b = help_b[k]; target = k;
     }
 }
 help_b[target] = 0x7fffffffffffffffL;
 global_update_pheromone_weighted( &ant[target], ras_ranks-i-1 );
    }
    global_update_pheromone_weighted( best_so_far_ant, ras_ranks );
    free ( help_b );
}

variable_types: b long

variable_types: target long


decompiled_code:
__int64 mmas_update()
{
__int64 result; // rax
__int64 v1; // rax

if ( (__int64)iteration % u_gb )
{
v1 = find_best();
result = global_update_pheromone((char *)ant + 24 * v1);
}
else if ( u_gb == 1LL && (__int64)(restart_found_best - iteration) > 50 )
{
result = global_update_pheromone(best_so_far_ant);
}
else
{
result = global_update_pheromone(restart_best_ant);
}
if ( ls_flag )
{
result = iteration - restart_iteration;
if ( (__int64)(iteration - restart_iteration) > 24 )
{
if ( result > 74 )
{
if ( result > 124 )
{
result = (result < 250) + 1LL;
u_gb = result;
}
else
{
u_gb = 3LL;
}
}
else
{
u_gb = 5LL;
}
}
else
{
u_gb = 25LL;
}
}
else
{
u_gb = 25LL;
}
return result;
}

canonical_decompiled_code:
__int64 func9()
{
__int64 result; // rax
__int64 v1; // rax

if ( (__int64)iteration % u_gb )
{
v1 = find_best();
result = global_update_pheromone((char *)ant + 24 * v1);
}
else if ( u_gb == 1LL && (__int64)(restart_found_best - iteration) > 50 )
{
result = global_update_pheromone(best_so_far_ant);
}
else
{
result = global_update_pheromone(restart_best_ant);
}
if ( ls_flag )
{
result = iteration - restart_iteration;
if ( (__int64)(iteration - restart_iteration) > 24 )
{
if ( result > 74 )
{
if ( result > 124 )
{
result = (result < 250) + 1LL;
u_gb = result;
}
else
{
u_gb = 3LL;
}
}
else
{
u_gb = 5LL;
}
}
else
{
u_gb = 25LL;
}
}
else
{
u_gb = 25LL;
}
return result;
}

original_code:
void mmas_update( void )
{
    long int iteration_best_ant;
    ;
    if ( iteration % u_gb ) {
 iteration_best_ant = find_best();
 global_update_pheromone( &ant[iteration_best_ant] );
    }
    else {
 if ( u_gb == 1 && (restart_found_best - iteration > 50))
     global_update_pheromone( best_so_far_ant );
 else
     global_update_pheromone( restart_best_ant );
    }
    if ( ls_flag ) {
 if ( ( iteration - restart_iteration ) < 25 )
     u_gb = 25;
 else if ( (iteration - restart_iteration) < 75 )
     u_gb = 5;
 else if ( (iteration - restart_iteration) < 125 )
     u_gb = 3;
 else if ( (iteration - restart_iteration) < 250 )
     u_gb = 2;
 else
     u_gb = 1;
    } else
 u_gb = 25;
}

canonical_original_code:
void mmas_update()
{
    long iteration_best_ant;
    ;
    if ( iteration % u_gb ) {
 iteration_best_ant = find_best();
 global_update_pheromone( &ant[iteration_best_ant] );
    }
    else {
 if ( u_gb == 1 && (restart_found_best - iteration > 50))
     global_update_pheromone( best_so_far_ant );
 else
     global_update_pheromone( restart_best_ant );
    }
    if ( ls_flag ) {
 if ( ( iteration - restart_iteration ) < 25 )
     u_gb = 25;
 else if ( (iteration - restart_iteration) < 75 )
     u_gb = 5;
 else if ( (iteration - restart_iteration) < 125 )
     u_gb = 3;
 else if ( (iteration - restart_iteration) < 250 )
     u_gb = 2;
 else
     u_gb = 1;
    } else
 u_gb = 25;
}


decompiled_code:
int bwas_update()
{
__int64 v0; // rbx

global_update_pheromone(best_so_far_ant);
v0 = 24 * find_worst();
bwas_worst_ant_update(best_so_far_ant, (char *)ant + v0);
if ( (unsigned int)(int)((double)(int)n * 0.05) <= distance_between_ants(best_so_far_ant, (char *)ant + v0) )
return bwas_pheromone_mutation();
*(_QWORD *)(restart_best_ant + 16LL) = 0x7FFFFFFFFFFFFFFFLL;
init_pheromone_trails(trail_0);
restart_iteration = iteration;
restart_time = elapsed_time(1LL);
return printf("init pheromone trails with %.15f, iteration %ld\n", trail_0, iteration);
}

canonical_decompiled_code:
int func10()
{
__int64 v0; // rbx

global_update_pheromone(best_so_far_ant);
v0 = 24 * find_worst();
bwas_worst_ant_update(best_so_far_ant, (char *)ant + v0);
if ( (unsigned int)(int)((double)(int)n * 0.05) <= distance_between_ants(best_so_far_ant, (char *)ant + v0) )
return bwas_pheromone_mutation();
*(_QWORD *)(restart_best_ant + 16LL) = 0x7FFFFFFFFFFFFFFFLL;
init_pheromone_trails(trail_0);
restart_iteration = iteration;
restart_time = elapsed_time(1LL);
return printf("init pheromone trails with %.15f, iteration %ld\n", trail_0, iteration);
}

original_code:
void bwas_update( void )
{
    long int iteration_worst_ant, distance_best_worst;
    ;
    global_update_pheromone( best_so_far_ant );
    iteration_worst_ant = find_worst();
    bwas_worst_ant_update( best_so_far_ant, &ant[iteration_worst_ant] );
    distance_best_worst = distance_between_ants( best_so_far_ant, &ant[iteration_worst_ant]);
    if ( distance_best_worst < (long int) (0.05 * (double) n) ) {
 (*restart_best_ant).tour_length = 0x7fffffffffffffffL;
 init_pheromone_trails( trail_0 );
 restart_iteration = iteration;
 restart_time = elapsed_time( VIRTUAL );
 printf("init pheromone trails with %.15f, iteration %ld\n",trail_0,iteration);
    }
    else
 bwas_pheromone_mutation();
}

canonical_original_code:
void bwas_update()
{
    long iteration_worst_ant; long distance_best_worst;
    ;
    global_update_pheromone( best_so_far_ant );
    iteration_worst_ant = find_worst();
    bwas_worst_ant_update( best_so_far_ant, &ant[iteration_worst_ant] );
    distance_best_worst = distance_between_ants( best_so_far_ant, &ant[iteration_worst_ant]);
    if ( distance_best_worst < (long) (0.05 * (double) n) ) {
 (*restart_best_ant).tour_length = 0x7fffffffffffffffL;
 init_pheromone_trails( trail_0 );
 restart_iteration = iteration;
 restart_time = elapsed_time( VIRTUAL );
 printf("init pheromone trails with %.15f, iteration %ld\n",trail_0,iteration);
    }
    else
 bwas_pheromone_mutation();
}


decompiled_code:
__int64 acs_global_update()
{
return global_acs_pheromone_update(best_so_far_ant);
}

canonical_decompiled_code:
__int64 func11()
{
return global_acs_pheromone_update(best_so_far_ant);
}

original_code:
void acs_global_update( void )
{
    ;
    global_acs_pheromone_update( best_so_far_ant );
}

canonical_original_code:
void acs_global_update()
{
    ;
    global_acs_pheromone_update( best_so_far_ant );
}


decompiled_code:
__int64 pheromone_trail_update()
{
__int64 result; // rax

result = bwas_flag | ras_flag | eas_flag | as_flag;
if ( !result )
{
if ( !mmas_flag )
goto LABEL_7;
if ( ls_flag )
goto LABEL_4;
goto LABEL_16;
}
if ( !ls_flag )
{
LABEL_16:
result = evaporation();
goto LABEL_5;
}
if ( mmas_flag )
{
LABEL_4:
result = mmas_evaporation_nn_list();
goto LABEL_5;
}
result = evaporation_nn_list();
LABEL_5:
if ( as_flag )
{
as_update();
goto LABEL_18;
}
if ( eas_flag )
{
eas_update();
goto LABEL_18;
}
LABEL_7:
if ( ras_flag )
{
ras_update();
}
else if ( mmas_flag )
{
mmas_update();
}
else if ( bwas_flag )
{
bwas_update();
}
else
{
if ( !acs_flag )
{
if ( !as_flag )
return result;
goto LABEL_32;
}
acs_global_update();
}
LABEL_18:
if ( mmas_flag )
{
if ( ls_flag )
{
if ( as_flag )
return compute_nn_list_total_information();
result = bwas_flag | mmas_flag | ras_flag | eas_flag;
if ( result )
return compute_nn_list_total_information();
return result;
}
check_pheromone_trail_limits();
}
if ( as_flag || (result = bwas_flag | mmas_flag | ras_flag | eas_flag) != 0 )
{
LABEL_32:
if ( !ls_flag )
return compute_total_information();
return compute_nn_list_total_information();
}
return result;
}

canonical_decompiled_code:
__int64 func12()
{
__int64 result; // rax

result = bwas_flag | ras_flag | eas_flag | as_flag;
if ( !result )
{
if ( !mmas_flag )
goto LABEL_7;
if ( ls_flag )
goto LABEL_4;
goto LABEL_16;
}
if ( !ls_flag )
{
LABEL_16:
result = evaporation();
goto LABEL_5;
}
if ( mmas_flag )
{
LABEL_4:
result = mmas_evaporation_nn_list();
goto LABEL_5;
}
result = evaporation_nn_list();
LABEL_5:
if ( as_flag )
{
func6();
goto LABEL_18;
}
if ( eas_flag )
{
func7();
goto LABEL_18;
}
LABEL_7:
if ( ras_flag )
{
func8();
}
else if ( mmas_flag )
{
func9();
}
else if ( bwas_flag )
{
func10();
}
else
{
if ( !acs_flag )
{
if ( !as_flag )
return result;
goto LABEL_32;
}
func11();
}
LABEL_18:
if ( mmas_flag )
{
if ( ls_flag )
{
if ( as_flag )
return compute_nn_list_total_information();
result = bwas_flag | mmas_flag | ras_flag | eas_flag;
if ( result )
return compute_nn_list_total_information();
return result;
}
check_pheromone_trail_limits();
}
if ( as_flag || (result = bwas_flag | mmas_flag | ras_flag | eas_flag) != 0 )
{
LABEL_32:
if ( !ls_flag )
return compute_total_information();
return compute_nn_list_total_information();
}
return result;
}

original_code:
void pheromone_trail_update( void )
{
    if ( as_flag || eas_flag || ras_flag || bwas_flag || mmas_flag ) {
 if ( ls_flag ) {
     if ( mmas_flag )
  mmas_evaporation_nn_list();
     else
  evaporation_nn_list();
 } else {
     evaporation();
 }
    }
    if ( as_flag )
 as_update();
    else if ( eas_flag )
 eas_update();
    else if ( ras_flag )
 ras_update();
    else if ( mmas_flag )
 mmas_update();
    else if ( bwas_flag )
 bwas_update();
    else if ( acs_flag )
 acs_global_update();
    if ( mmas_flag && !ls_flag )
 check_pheromone_trail_limits();
    if ( as_flag || eas_flag || ras_flag || mmas_flag || bwas_flag ) {
 if ( ls_flag ) {
     compute_nn_list_total_information();
 } else {
     compute_total_information();
 }
    }
}

canonical_original_code:
void pheromone_trail_update()
{
    if ( as_flag || eas_flag || ras_flag || bwas_flag || mmas_flag ) {
 if ( ls_flag ) {
     if ( mmas_flag )
  mmas_evaporation_nn_list();
     else
  evaporation_nn_list();
 } else {
     evaporation();
 }
    }
    if ( as_flag )
 as_update();
    else if ( eas_flag )
 eas_update();
    else if ( ras_flag )
 ras_update();
    else if ( mmas_flag )
 mmas_update();
    else if ( bwas_flag )
 bwas_update();
    else if ( acs_flag )
 acs_global_update();
    if ( mmas_flag && !ls_flag )
 check_pheromone_trail_limits();
    if ( as_flag || eas_flag || ras_flag || mmas_flag || bwas_flag ) {
 if ( ls_flag ) {
     compute_nn_list_total_information();
 } else {
     compute_total_information();
 }
    }
}


main

canonical_name: main

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

start_timers(argc, argv, envp);
init_program(argc, argv);
seed = time(0LL);
*((_QWORD *)&instance + 30) = compute_nn_lists();
pheromone = (void *)generate_double_matrix(n, n);
total = (void *)generate_double_matrix(n, n);
time_used = elapsed_time(1LL);
printf("Initialization took %.10f seconds\n", time_used);
n_try = 0LL;
if ( max_tries > 0 )
{
v3 = 0LL;
do
{
init_try(v3);
while ( !termination_condition() )
{
construct_solutions();
if ( ls_flag > 0 )
local_search();
update_statistics();
pheromone_trail_update();
search_control_and_statistics();
++iteration;
}
exit_try(n_try);
v3 = n_try + 1LL;
n_try = v3;
}
while ( v3 < max_tries );
}
exit_program();
free(*((void **)&instance + 29));
free(*((void **)&instance + 30));
free(pheromone);
free(total);
free(best_in_try);
free(best_found_at);
free(time_best_found);
free(time_total_run);
if ( n_ants > 0 )
{
v4 = 0LL;
v5 = 0LL;
do
{
free(*(void **)((char *)ant + v4));
free(*(void **)((char *)ant + v4 + 8));
++v5;
v4 += 24LL;
}
while ( n_ants > v5 );
}
free(ant);
free((void *)*best_so_far_ant);
free(*(void **)(best_so_far_ant + 8LL));
free(prob_of_selection);
return 0;
}

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

start_timers(argc, argv, envp);
init_program(argc, argv);
seed = time(0LL);
*((_QWORD *)&instance + 30) = compute_nn_lists();
pheromone = (void *)generate_double_matrix(n, n);
total = (void *)generate_double_matrix(n, n);
time_used = elapsed_time(1LL);
printf("Initialization took %.10f seconds\n", time_used);
n_try = 0LL;
if ( max_tries > 0 )
{
v3 = 0LL;
do
{
func2(v3);
while ( !func0() )
{
func1();
if ( ls_flag > 0 )
func3();
func4();
func12();
func5();
++iteration;
}
exit_try(n_try);
v3 = n_try + 1LL;
n_try = v3;
}
while ( v3 < max_tries );
}
exit_program();
free(*((void **)&instance + 29));
free(*((void **)&instance + 30));
free(pheromone);
free(total);
free(best_in_try);
free(best_found_at);
free(time_best_found);
free(time_total_run);
if ( n_ants > 0 )
{
v4 = 0LL;
v5 = 0LL;
do
{
free(*(void **)((char *)ant + v4));
free(*(void **)((char *)ant + v4 + 8));
++v5;
v4 += 24LL;
}
while ( n_ants > v5 );
}
free(ant);
free((void *)*best_so_far_ant);
free(*(void **)(best_so_far_ant + 8LL));
free(prob_of_selection);
return 0;
}

original_code:
int main(int argc, char *argv[]) {
    long int i;
    start_timers();
    init_program(argc, argv);
    seed = (long int) time(((void *)0));
    instance.nn_list = compute_nn_lists();
    pheromone = generate_double_matrix( n, n );
    total = generate_double_matrix( n, n );
    time_used = elapsed_time( VIRTUAL );
    printf("Initialization took %.10f seconds\n",time_used);
    for ( n_try = 0 ; n_try < max_tries ; n_try++ ) {
 init_try(n_try);
 while ( !termination_condition() ) {
     construct_solutions();
     if ( ls_flag > 0 )
  local_search();
     update_statistics();
     pheromone_trail_update();
     search_control_and_statistics();
     iteration++;
 }
 exit_try(n_try);
    }
    exit_program();
    free( instance.distance );
    free( instance.nn_list );
    free( pheromone );
    free( total );
    free( best_in_try );
    free( best_found_at );
    free( time_best_found );
    free( time_total_run );
    for ( i = 0 ; i < n_ants ; i++ ) {
 free( ant[i].tour );
 free( ant[i].visited );
    }
    free( ant );
    free( (*best_so_far_ant).tour );
    free( (*best_so_far_ant).visited );
    free( prob_of_selection );
    return(0);
}

canonical_original_code:
int main(int argc, char *argv[]) {
    long i;
    start_timers();
    init_program(argc, argv);
    seed = (long) time(((void *)0));
    instance.nn_list = compute_nn_lists();
    pheromone = generate_double_matrix( n, n );
    total = generate_double_matrix( n, n );
    time_used = elapsed_time( VIRTUAL );
    printf("Initialization took %.10f seconds\n",time_used);
    for ( n_try = 0 ; n_try < max_tries ; n_try++ ) {
 init_try(n_try);
 while ( !termination_condition() ) {
     construct_solutions();
     if ( ls_flag > 0 )
  local_search();
     update_statistics();
     pheromone_trail_update();
     search_control_and_statistics();
     iteration++;
 }
 exit_try(n_try);
    }
    exit_program();
    free( instance.distance );
    free( instance.nn_list );
    free( pheromone );
    free( total );
    free( best_in_try );
    free( best_found_at );
    free( time_best_found );
    free( time_total_run );
    for ( i = 0 ; i < n_ants ; i++ ) {
 free( ant[i].tour );
 free( ant[i].visited );
    }
    free( ant );
    free( (*best_so_far_ant).tour );
    free( (*best_so_far_ant).visited );
    free( prob_of_selection );
    return(0);
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
clock_t start_timers()
{
clock_t result; // rax

result = clock();
start_time = result;
return result;
}

canonical_decompiled_code:
clock_t func0()
{
clock_t result; // rax

result = clock();
start_time = result;
return result;
}

original_code:
void start_timers()
{
    start_time = clock();
}


dtrunc

decompiled_code:
double __fastcall dtrunc(double a1)
{
return (double)(int)a1;
}

canonical_decompiled_code:
double __fastcall func0(double a1)
{
return (double)(int)a1;
}

original_code:
static double dtrunc (double x)
{
    int k;
    k = (int) x;
    x = (double) k;
    return x;
}

canonical_original_code:
static double dtrunc(double x)
{
    int k;
    k = (int) x;
    x = (double) k;
    return x;
}

variable_types: x double

variable_types: k int


decompiled_code:
__int64 __fastcall round_distance(__int64 a1, __int64 a2)
{
double *v2; // rdi
double v3; // xmm0_8
__int64 result; // rax

v2 = (double *)(instance[28] + 16 * a1);
v3 = (v2[1] - *(double *)(instance[28] + 16 * a2 + 8)) * (v2[1] - *(double *)(instance[28] + 16 * a2 + 8))
+ (*v2 - *(double *)(instance[28] + 16 * a2)) * (*v2 - *(double *)(instance[28] + 16 * a2));
if ( v3 < 0.0 )
result = (unsigned int)(int)(sqrt(v3) + 0.5);
else
result = (unsigned int)(int)(sqrt(v3) + 0.5);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
double *v2; // rdi
double v3; // xmm0_8
__int64 result; // rax

v2 = (double *)(instance[28] + 16 * a1);
v3 = (v2[1] - *(double *)(instance[28] + 16 * a2 + 8)) * (v2[1] - *(double *)(instance[28] + 16 * a2 + 8))
+ (*v2 - *(double *)(instance[28] + 16 * a2)) * (*v2 - *(double *)(instance[28] + 16 * a2));
if ( v3 < 0.0 )
result = (unsigned int)(int)(sqrt(v3) + 0.5);
else
result = (unsigned int)(int)(sqrt(v3) + 0.5);
return result;
}

original_code:
long int round_distance (long int i, long int j)
{
    double xd = instance.nodeptr[i].x - instance.nodeptr[j].x;
    double yd = instance.nodeptr[i].y - instance.nodeptr[j].y;
    double r = sqrt(xd*xd + yd*yd) + 0.5;
    return (long int) r;
}

canonical_original_code:
long round_distance(long i, long j)
{
    double xd = instance.nodeptr[i].x - instance.nodeptr[j].x;
    double yd = instance.nodeptr[i].y - instance.nodeptr[j].y;
    double r = sqrt(xd*xd + yd*yd) + 0.5;
    return (long) r;
}

variable_types: j long

variable_types: xd double

variable_types: yd double

variable_types: r double


decompiled_code:
__int64 __fastcall ceil_distance(__int64 a1, __int64 a2)
{
double *v2; // rdi
double v3; // xmm0_8
__int64 result; // rax

v2 = (double *)(instance[28] + 16 * a1);
v3 = (v2[1] - *(double *)(instance[28] + 16 * a2 + 8)) * (v2[1] - *(double *)(instance[28] + 16 * a2 + 8))
+ (*v2 - *(double *)(instance[28] + 16 * a2)) * (*v2 - *(double *)(instance[28] + 16 * a2));
if ( v3 < 0.0 )
result = (unsigned int)(int)(sqrt(v3) + 0.000000001);
else
result = (unsigned int)(int)(sqrt(v3) + 0.000000001);
return result;
}

original_code:
long int ceil_distance (long int i, long int j)
{
    double xd = instance.nodeptr[i].x - instance.nodeptr[j].x;
    double yd = instance.nodeptr[i].y - instance.nodeptr[j].y;
    double r = sqrt(xd*xd + yd*yd) + 0.000000001;
    return (long int)r;
}

canonical_original_code:
long ceil_distance(long i, long j)
{
    double xd = instance.nodeptr[i].x - instance.nodeptr[j].x;
    double yd = instance.nodeptr[i].y - instance.nodeptr[j].y;
    double r = sqrt(xd*xd + yd*yd) + 0.000000001;
    return (long)r;
}

variable_types: i long


original_code:
long int geo_distance (long int i, long int j)
{
    double deg, min;
    double lati, latj, longi, longj;
    double q1, q2, q3;
    long int dd;
    double x1 = instance.nodeptr[i].x, x2 = instance.nodeptr[j].x,
 y1 = instance.nodeptr[i].y, y2 = instance.nodeptr[j].y;
    deg = dtrunc (x1);
    min = x1 - deg;
    lati = 3.14159265358979323846264 * (deg + 5.0 * min / 3.0) / 180.0;
    deg = dtrunc (x2);
    min = x2 - deg;
    latj = 3.14159265358979323846264 * (deg + 5.0 * min / 3.0) / 180.0;
    deg = dtrunc (y1);
    min = y1 - deg;
    longi = 3.14159265358979323846264 * (deg + 5.0 * min / 3.0) / 180.0;
    deg = dtrunc (y2);
    min = y2 - deg;
    longj = 3.14159265358979323846264 * (deg + 5.0 * min / 3.0) / 180.0;
    q1 = cos (longi - longj);
    q2 = cos (lati - latj);
    q3 = cos (lati + latj);
    dd = (int) (6378.388 * acos (0.5 * ((1.0 + q1) * q2 - (1.0 - q1) * q3)) + 1.0);
    return dd;
}

canonical_original_code:
long geo_distance(long i, long j)
{
    double deg; double min;
    double lati; double latj; double longi; double longj;
    double q1; double q2; double q3;
    long dd;
    double x1 = instance.nodeptr[i].x; double x2 = instance.nodeptr[j].x; double y1 = instance.nodeptr[i].y; double y2 = instance.nodeptr[j].y;
    deg = dtrunc (x1);
    min = x1 - deg;
    lati = 3.14159265358979323846264 * (deg + 5.0 * min / 3.0) / 180.0;
    deg = dtrunc (x2);
    min = x2 - deg;
    latj = 3.14159265358979323846264 * (deg + 5.0 * min / 3.0) / 180.0;
    deg = dtrunc (y1);
    min = y1 - deg;
    longi = 3.14159265358979323846264 * (deg + 5.0 * min / 3.0) / 180.0;
    deg = dtrunc (y2);
    min = y2 - deg;
    longj = 3.14159265358979323846264 * (deg + 5.0 * min / 3.0) / 180.0;
    q1 = cos (longi - longj);
    q2 = cos (lati - latj);
    q3 = cos (lati + latj);
    dd = (int) (6378.388 * acos (0.5 * ((1.0 + q1) * q2 - (1.0 - q1) * q3)) + 1.0);
    return dd;
}

variable_types: deg double

variable_types: min double

variable_types: lati double

variable_types: latj double

variable_types: longi double

variable_types: longj double

variable_types: dd long


decompiled_code:
__int64 __fastcall att_distance(__int64 a1, __int64 a2)
{
double *v2; // rdi
double *v3; // rsi
double v4; // xmm0_8
double v5; // xmm1_8
double v6; // rbx
double v7; // xmm0_8
__int64 result; // rax

v2 = (double *)(instance[28] + 16 * a1);
v3 = (double *)(instance[28] + 16 * a2);
v4 = v2[1] - v3[1];
v5 = ((*v2 - *v3) * (*v2 - *v3) + v4 * v4) / 10.0;
if ( v5 < 0.0 )
v6 = sqrt(v5);
else
v6 = sqrt(v5);
v7 = dtrunc(v6);
if ( v6 <= v7 )
result = (int)v7;
else
result = (int)v7 + 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
double *v2; // rdi
double *v3; // rsi
double v4; // xmm0_8
double v5; // xmm1_8
double v6; // rbx
double v7; // xmm0_8
__int64 result; // rax

v2 = (double *)(instance[28] + 16 * a1);
v3 = (double *)(instance[28] + 16 * a2);
v4 = v2[1] - v3[1];
v5 = ((*v2 - *v3) * (*v2 - *v3) + v4 * v4) / 10.0;
if ( v5 < 0.0 )
v6 = sqrt(v5);
else
v6 = sqrt(v5);
v7 = func0(v6);
if ( v6 <= v7 )
result = (int)v7;
else
result = (int)v7 + 1;
return result;
}

original_code:
long int att_distance (long int i, long int j)
{
    double xd = instance.nodeptr[i].x - instance.nodeptr[j].x;
    double yd = instance.nodeptr[i].y - instance.nodeptr[j].y;
    double rij = sqrt ((xd * xd + yd * yd) / 10.0);
    double tij = dtrunc (rij);
    long int dij;
    if (tij < rij)
        dij = (int) tij + 1;
    else
        dij = (int) tij;
    return dij;
}

canonical_original_code:
long att_distance(long i, long j)
{
    double xd = instance.nodeptr[i].x - instance.nodeptr[j].x;
    double yd = instance.nodeptr[i].y - instance.nodeptr[j].y;
    double rij = sqrt ((xd * xd + yd * yd) / 10.0);
    double tij = dtrunc (rij);
    long dij;
    if (tij < rij)
        dij = (int) tij + 1;
    else
        dij = (int) tij;
    return dij;
}

variable_types: rij double

variable_types: tij double

variable_types: dij long


decompiled_code:
_QWORD *compute_distances()
{
__int64 v0; // rbx
_QWORD *v1; // rax
_QWORD *v2; // r13
signed __int64 v3; // r12
signed __int64 v5; // rbx
_QWORD *v6; // rbp

v0 = n;
v1 = malloc(8 * n * (n + 1));
if ( !v1 )
{
fwrite("Out of memory, exit.", 1uLL, 0x14uLL, stderr);
exit(1);
}
v2 = v1;
v3 = 0LL;
if ( v0 > 0 )
{
do
{
v2[v3] = &v2[v3 * v0 + v0];
if ( (__int64)n > 0 )
{
v5 = 0LL;
do
{
v6 = (_QWORD *)(v2[v3] + 8 * v5);
*v6 = distance(v3, v5++);
}
while ( (__int64)n > v5 );
}
++v3;
v0 = n;
}
while ( (__int64)n > v3 );
}
return v2;
}

original_code:
long int ** compute_distances(void)
{
    long int i, j;
    long int **matrix;
    if((matrix = malloc(sizeof(long int) * n * n +
   sizeof(long int *) * n )) == ((void *)0)){
 fprintf(stderr,"Out of memory, exit.");
 exit(1);
    }
    for ( i = 0 ; i < n ; i++ ) {
 matrix[i] = (long int *)(matrix + n) + i*n;
 for ( j = 0 ; j < n ; j++ ) {
     matrix[i][j] = distance(i, j);
 }
    }
    return matrix;
}

canonical_original_code:
long **compute_distances()
{
    long i; long j;
    long **matrix;
    if((matrix = malloc(sizeof(long) * n * n +
   sizeof(long *) * n )) == ((void *)0)){
 fprintf(stderr,"Out of memory, exit.");
 exit(1);
    }
    for ( i = 0 ; i < n ; i++ ) {
 matrix[i] = (long *)(matrix + n) + i*n;
 for ( j = 0 ; j < n ; j++ ) {
     matrix[i][j] = distance(i, j);
 }
    }
    return matrix;
}

variable_types:
matrix
long **

return_type: long **


decompiled_code:
__int64 __fastcall compute_tour_length(_QWORD *a1)
{
_QWORD *v1; // rax
_QWORD *v2; // rdi
__int64 v3; // rdx

if ( (__int64)n <= 0 )
return 0LL;
v1 = a1;
v2 = &a1[n];
v3 = 0LL;
do
{
v3 += *(_QWORD *)(*(_QWORD *)(instance[29] + 8LL * *v1) + 8LL * v1[1]);
++v1;
}
while ( v1 != v2 );
return v3;
}

original_code:
long int compute_tour_length( long int *t )
{
    int i;
    long int tour_length = 0;
    for ( i = 0 ; i < n ; i++ ) {
 tour_length += instance.distance[t[i]][t[i+1]];
    }
    return tour_length;
}

canonical_original_code:
long compute_tour_length(long *t)
{
    int i;
    long tour_length = 0;
    for ( i = 0 ; i < n ; i++ ) {
 tour_length += instance.distance[t[i]][t[i+1]];
    }
    return tour_length;
}

variable_types:
t
long *

variable_types: i int


repo: thiagorcdl/SimpleDES

original_code:
char ip_1(char charmeleon){
 char c = 0;
 c |= (charmeleon << 3) & 0x80;
 c |= (charmeleon >> 1) & 0x40;
 c |= (charmeleon ) & 0x20;
 c |= (charmeleon << 1) & 0x10;
 c |= (charmeleon << 2) & 0x08;
 c |= (charmeleon >> 4) & 0x04;
 c |= (charmeleon << 1) & 0x02;
 c |= (charmeleon >> 2) & 0x01;
 return c;
}

variable_types: charmeleon char

variable_types: c char

return_type: char


expansion

original_code:
char expansion(char charizard){
 char c = 0;
 c |= (charizard << 7) & 0x80;
 c |= (charizard << 3) & 0x40;
 c |= (charizard << 3) & 0x20;
 c |= (charizard << 3) & 0x10;
 c |= (charizard << 1) & 0x08;
 c |= (charizard << 1) & 0x04;
 c |= (charizard << 1) & 0x02;
 c |= (charizard >> 3) & 0x01;
 return c;
}

variable_types: charizard char


variable_types: seila short

variable_types: c short

return_type: short


canonical_decompiled_code:
__int64 __fastcall func13(__int16 a1)
{
char v1; // dl
int v2; // eax
int v3; // edi

v2 = (a1 >> 3) & 0x63;
v3 = 4 * a1;
v1 = v3;
LOWORD(v3) = v3 & 0x390;
return v1 & 4 | v1 & 8 | v3 | (unsigned int)v2;
}


fk

variable_types: exp char

variable_types: d char

variable_types: a char

variable_types: b char

variable_types: lin char

variable_types: col char


getArgs

decompiled_code:
__int64 __fastcall getArgs(int a1)
{
unsigned int v1; // ebp

v1 = 0;
if ( a1 == 2 )
{
v1 = read(0, &plainText, (size_t)&unk_40000000);
__isoc99_sscanf();
key &= 0x3FFu;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func15(int a1)
{
unsigned int v1; // ebp

v1 = 0;
if ( a1 == 2 )
{
v1 = read(0, &plainText, (size_t)&unk_40000000);
__isoc99_sscanf();
key &= 0x3FFu;
}
return v1;
}

original_code:
int getArgs(int argc, char **argv){
 int size=0;
 if(argc != 2)
  return 0;
 else {
  size = read(0, plainText, (1<<30));
  sscanf(argv[1], "%hx", &key);
  key = key & 0x03ff;
  return size;
 }
}

canonical_original_code:
int getArgs(int argc, char **argv){
 int size = 0;
 if(argc != 2)
  return 0;
 else {
  size = read(0, plainText, (1<<30));
  sscanf(argv[1], "%hx", &key);
  key = key & 0x03ff;
  return size;
 }
}

variable_types: argc int

variable_types:
argv
char **

variable_types: size int


verbose

repo: thiakil/rb-download

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

if ( verbose )
{
va_start(arg, a1);
vprintf(a1, arg);
result = putchar(10);
}
return result;
}

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

if ( verbose )
{
va_start(arg, a1);
vprintf(a1, arg);
result = putchar(10);
}
return result;
}

original_code:
void
verbose(char *message, ...)
{
 va_list ap;
 if(_verbose)
 {
         __builtin_va_start(ap,message);
         vprintf(message, ap);
  printf("\n");
         __builtin_va_end(ap);
 }
 return;
}

canonical_original_code:
void verbose(char *message, ...)
{
 __builtin_va_list ap;
 if(_verbose)
 {
         __builtin_va_start(ap,message);
         vprintf(message, ap);
  printf("\n");
         __builtin_va_end(ap);
 }
 return;
}

variable_types:
message
char *


vverbose

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

if ( verbose > 1 )
{
va_start(arg, a1);
vprintf(a1, arg);
result = putchar(10);
}
return result;
}

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

if ( verbose > 1 )
{
va_start(arg, a1);
vprintf(a1, arg);
result = putchar(10);
}
return result;
}

original_code:
void
vverbose(char *message, ...)
{
 va_list ap;
 if(_verbose > 1)
 {
         __builtin_va_start(ap,message);
         vprintf(message, ap);
  printf("\n");
         __builtin_va_end(ap);
 }
 return;
}

canonical_original_code:
void vverbose(char *message, ...)
{
 __builtin_va_list ap;
 if(_verbose > 1)
 {
         __builtin_va_start(ap,message);
         vprintf(message, ap);
  printf("\n");
         __builtin_va_end(ap);
 }
 return;
}


vhexdump

decompiled_code:
__int64 vhexdump()
{
__int64 result; // rax

if ( verbose > 1 )
result = hexdump();
return result;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 result; // rax

if ( verbose > 1 )
result = hexdump();
return result;
}

original_code:
void
vhexdump(unsigned char *data, size_t nbytes)
{
 if(_verbose > 1)
  hexdump(data, nbytes);
 return;
}

canonical_original_code:
void vhexdump(unsigned char *data, unsigned long nbytes)
{
 if(_verbose > 1)
  hexdump(data, nbytes);
 return;
}

variable_types:
data
unsigned char *

variable_types:
nbytes
unsigned long


usage

decompiled_code:
__int64 __fastcall usage(const char *a1)
{
return fatal(
"Usage: %s [-v] [-a <adapter>] [-x <frontend>] [-y <demux>] [-z <dvr>] [-b <base_dir>] [-t <timeout>] [-f <cha"
"nnels_file>] [-l <listen_addr>] [-c carousel_id] [<service_id>|any[:default_service_id]]",
a1);
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1)
{
return fatal(
"Usage: %s [-v] [-a <adapter>] [-x <frontend>] [-y <demux>] [-z <dvr>] [-b <base_dir>] [-t <timeout>] [-f <cha"
"nnels_file>] [-l <listen_addr>] [-c carousel_id] [<service_id>|any[:default_service_id]]",
a1);
}

original_code:
void
usage(char *prog_name)
{
 fatal("Usage: %s [-v] "
   "[-a <adapter>] "
   "[-x <frontend>] "
   "[-y <demux>] "
   "[-z <dvr>] "
   "[-b <base_dir>] "
   "[-t <timeout>] "
   "[-f <channels_file>] "
   "[-l <listen_addr>] "
   "[-c carousel_id] "
   "[<service_id>|any[:default_service_id]]", prog_name);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r15
char *v4; // r14
char *v5; // r13
unsigned int v6; // er12
int v7; // eax
__int64 v8; // rax
const char *v9; // rdx
int v10; // ebx
const char *v11; // r13
unsigned __int16 v12; // r13
const char *v13; // rbp
int *v14; // rax
char *v15; // rax
unsigned int v17; // [rsp+Ch] [rbp-5Ch]
unsigned int v18; // [rsp+10h] [rbp-58h]
unsigned int v19; // [rsp+14h] [rbp-54h]
unsigned int v20; // [rsp+18h] [rbp-50h]
unsigned int v21; // [rsp+1Ch] [rbp-4Ch]
char v22[2]; // [rsp+20h] [rbp-48h] BYREF
__int16 v23; // [rsp+22h] [rbp-46h] BYREF
int v24[17]; // [rsp+24h] [rbp-44h] BYREF

v3 = *argv;
v24[0] = _bswap_32(0);
v23 = _bswap_16(10101);
v21 = -1;
v4 = 0LL;
v18 = 10;
v5 = 0LL;
v20 = 0;
v19 = 0;
v17 = 0;
v6 = 0;
while ( 1 )
{
v7 = getopt(argc, (char *const *)argv, "a:x:y:z:b:f:t:l:c:v");
if ( v7 == -1 )
break;
switch ( v7 )
{
case 'a':
v6 = strtoul(optarg, 0LL, 0);
break;
case 'b':
v5 = optarg;
break;
case 'c':
v21 = strtoul(optarg, 0LL, 0);
break;
case 'f':
v4 = optarg;
break;
case 'l':
if ( (int)parse_addr(optarg, v24, &v23) < 0 )
fatal("Unable to resolve host %s", optarg);
break;
case 't':
v18 = strtoul(optarg, 0LL, 0);
break;
case 'v':
++verbose;
break;
case 'x':
v17 = strtoul(optarg, 0LL, 0);
break;
case 'y':
v19 = strtoul(optarg, 0LL, 0);
break;
case 'z':
v20 = strtoul(optarg, 0LL, 0);
break;
default:
usage(v3);
break;
}
}
v8 = zap_name(v6, v17);
if ( !(unsigned __int8)init_channels_conf(v8, v4) )
error((int)"Unable to open channels.conf file", (int)v4, v9);
if ( v5 && chdir(v5) < 0 )
{
v14 = _errno_location();
v15 = strerror(*v14);
fatal("Unable to cd to '%s': %s", v5, v15);
}
if ( !(unsigned __int8)cache_init() )
fatal("Unable to initialise cache");
if ( optind == argc )
{
list_channels(v6, v19, v18);
v10 = 0;
}
else
{
v10 = argc - optind;
if ( argc - optind != 1 )
{
usage(v3);
return 0;
}
v11 = argv[optind];
if ( strncmp(v11, "any", 3uLL) && strncmp(v11, "ANY", 3uLL) )
{
v12 = strtoul(v11, 0LL, 0);
goto LABEL_32;
}
v12 = get_first_service_id(v6, v19, v18);
if ( v12 )
{
verbose("got serviceid from already tuned channel");
goto LABEL_32;
}
v13 = argv[optind];
if ( strlen(v13) > 4 )
{
v12 = strtoul(v13 + 4, 0LL, 0);
LABEL_32:
start_listener(v22, v6, v17, v19, v20, v18, v12, v21);
return 0;
}
}
return v10;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r15
char *v4; // r14
char *v5; // r13
unsigned int v6; // er12
int v7; // eax
__int64 v8; // rax
const char *v9; // rdx
int v10; // ebx
const char *v11; // r13
unsigned __int16 v12; // r13
const char *v13; // rbp
int *v14; // rax
char *v15; // rax
unsigned int v17; // [rsp+Ch] [rbp-5Ch]
unsigned int v18; // [rsp+10h] [rbp-58h]
unsigned int v19; // [rsp+14h] [rbp-54h]
unsigned int v20; // [rsp+18h] [rbp-50h]
unsigned int v21; // [rsp+1Ch] [rbp-4Ch]
char v22[2]; // [rsp+20h] [rbp-48h] BYREF
__int16 v23; // [rsp+22h] [rbp-46h] BYREF
int v24[17]; // [rsp+24h] [rbp-44h] BYREF

v3 = *argv;
v24[0] = func0(0);
v23 = func1(10101);
v21 = -1;
v4 = 0LL;
v18 = 10;
v5 = 0LL;
v20 = 0;
v19 = 0;
v17 = 0;
v6 = 0;
while ( 1 )
{
v7 = getopt(argc, (char *const *)argv, "a:x:y:z:b:f:t:l:c:v");
if ( v7 == -1 )
break;
switch ( v7 )
{
case 'a':
v6 = strtoul(optarg, 0LL, 0);
break;
case 'b':
v5 = optarg;
break;
case 'c':
v21 = strtoul(optarg, 0LL, 0);
break;
case 'f':
v4 = optarg;
break;
case 'l':
if ( (int)parse_addr(optarg, v24, &v23) < 0 )
fatal("Unable to resolve host %s", optarg);
break;
case 't':
v18 = strtoul(optarg, 0LL, 0);
break;
case 'v':
++verbose;
break;
case 'x':
v17 = strtoul(optarg, 0LL, 0);
break;
case 'y':
v19 = strtoul(optarg, 0LL, 0);
break;
case 'z':
v20 = strtoul(optarg, 0LL, 0);
break;
default:
func5(v3);
break;
}
}
v8 = zap_name(v6, v17);
if ( !(unsigned __int8)init_channels_conf(v8, v4) )
error((int)"Unable to open channels.conf file", (int)v4, v9);
if ( v5 && chdir(v5) < 0 )
{
v14 = _errno_location();
v15 = strerror(*v14);
fatal("Unable to cd to '%s': %s", v5, v15);
}
if ( !(unsigned __int8)cache_init() )
fatal("Unable to initialise cache");
if ( optind == argc )
{
list_channels(v6, v19, v18);
v10 = 0;
}
else
{
v10 = argc - optind;
if ( argc - optind != 1 )
{
func5(v3);
return 0;
}
v11 = argv[optind];
if ( strncmp(v11, "any", 3uLL) && strncmp(v11, "ANY", 3uLL) )
{
v12 = strtoul(v11, 0LL, 0);
goto LABEL_32;
}
v12 = get_first_service_id(v6, v19, v18);
if ( v12 )
{
func2("got serviceid from already tuned channel");
goto LABEL_32;
}
v13 = argv[optind];
if ( strlen(v13) > 4 )
{
v12 = strtoul(v13 + 4, 0LL, 0);
LABEL_32:
start_listener(v22, v6, v17, v19, v20, v18, v12, v21);
return 0;
}
}
return v10;
}

original_code:
int
main(int argc, char *argv[])
{
 char *prog_name = argv[0];
 unsigned int adapter;
 unsigned int frontend;
 unsigned int demux;
 unsigned int dvr;
 char *base_dir;
 unsigned int timeout;
 char *channels_file;
 struct sockaddr_in listen_addr;
 int carousel_id;
 uint16_t service_id;
 int arg;
 adapter = 0;
 frontend = 0;
 demux = 0;
 dvr = 0;
 base_dir = ((void *)0);
 timeout = 10;
 channels_file = ((void *)0);
 listen_addr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
 listen_addr.sin_port = htons(10101);
 carousel_id = -1;
 while((arg = getopt(argc, argv, "a:x:y:z:b:f:t:l:c:v")) != (-1))
 {
  switch(arg)
  {
  case 'a':
   adapter = strtoul(optarg, ((void *)0), 0);
   break;
  case 'x':
   frontend = strtoul(optarg, ((void *)0), 0);
   break;
  case 'y':
   demux = strtoul(optarg, ((void *)0), 0);
   break;
  case 'z':
   dvr = strtoul(optarg, ((void *)0), 0);
   break;
  case 'b':
   base_dir = optarg;
   break;
  case 'f':
   channels_file = optarg;
   break;
  case 't':
   timeout = strtoul(optarg, ((void *)0), 0);
   break;
  case 'l':
   if(parse_addr(optarg, &listen_addr.sin_addr, &listen_addr.sin_port) < 0)
    fatal("Unable to resolve host %s", optarg);
   break;
  case 'c':
   carousel_id = strtoul(optarg, ((void *)0), 0);
   break;
  case 'v':
   _verbose ++;
   break;
  default:
   usage(prog_name);
   break;
  }
 }
 if(!init_channels_conf(zap_name(adapter, frontend), channels_file))
  error("Unable to open channels.conf file");
 if(base_dir != ((void *)0)
 && chdir(base_dir) < 0)
  fatal("Unable to cd to '%s': %s", base_dir, strerror((*__errno_location ())));
 if(!cache_init())
  fatal("Unable to initialise cache");
 if(argc == optind)
 {
  list_channels(adapter, demux, timeout);
 }
 else if(argc - optind == 1)
 {
  if (strncmp(argv[optind], "any", 3) == 0 || strncmp(argv[optind], "ANY", 3) == 0)
    {
      service_id = get_first_service_id(adapter, demux, timeout);
      if (service_id == 0 && strlen(argv[optind]) > 4)
        service_id = strtoul(&argv[optind][4], ((void *)0), 0);
      else if (service_id > 0)
        verbose("got serviceid from already tuned channel");
      else
        return 1;
    }
    else
      service_id = strtoul(argv[optind], ((void *)0), 0);
  start_listener(&listen_addr, adapter, frontend, demux, dvr, timeout, service_id, carousel_id);
 }
 else
 {
  usage(prog_name);
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 char *prog_name = argv[0];
 unsigned int adapter;
 unsigned int frontend;
 unsigned int demux;
 unsigned int dvr;
 char *base_dir;
 unsigned int timeout;
 char *channels_file;
 struct sockaddr_in listen_addr;
 int carousel_id;
 unsigned short service_id;
 int arg;
 adapter = 0;
 frontend = 0;
 demux = 0;
 dvr = 0;
 base_dir = ((void *)0);
 timeout = 10;
 channels_file = ((void *)0);
 listen_addr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
 listen_addr.sin_port = htons(10101);
 carousel_id = -1;
 while((arg = getopt(argc, argv, "a:x:y:z:b:f:t:l:c:v")) != (-1))
 {
  switch(arg)
  {
  case 'a':
   adapter = strtoul(optarg, ((void *)0), 0);
   break;
  case 'x':
   frontend = strtoul(optarg, ((void *)0), 0);
   break;
  case 'y':
   demux = strtoul(optarg, ((void *)0), 0);
   break;
  case 'z':
   dvr = strtoul(optarg, ((void *)0), 0);
   break;
  case 'b':
   base_dir = optarg;
   break;
  case 'f':
   channels_file = optarg;
   break;
  case 't':
   timeout = strtoul(optarg, ((void *)0), 0);
   break;
  case 'l':
   if(parse_addr(optarg, &listen_addr.sin_addr, &listen_addr.sin_port) < 0)
    fatal("Unable to resolve host %s", optarg);
   break;
  case 'c':
   carousel_id = strtoul(optarg, ((void *)0), 0);
   break;
  case 'v':
   _verbose ++;
   break;
  default:
   usage(prog_name);
   break;
  }
 }
 if(!init_channels_conf(zap_name(adapter, frontend), channels_file))
  error("Unable to open channels.conf file");
 if(base_dir != ((void *)0)
 && chdir(base_dir) < 0)
  fatal("Unable to cd to '%s': %s", base_dir, strerror((*__errno_location ())));
 if(!cache_init())
  fatal("Unable to initialise cache");
 if(argc == optind)
 {
  list_channels(adapter, demux, timeout);
 }
 else if(argc - optind == 1)
 {
  if (strncmp(argv[optind], "any", 3) == 0 || strncmp(argv[optind], "ANY", 3) == 0)
    {
      service_id = get_first_service_id(adapter, demux, timeout);
      if (service_id == 0 && strlen(argv[optind]) > 4)
        service_id = strtoul(&argv[optind][4], ((void *)0), 0);
      else if (service_id > 0)
        verbose("got serviceid from already tuned channel");
      else
        return 1;
    }
    else
      service_id = strtoul(argv[optind], ((void *)0), 0);
  start_listener(&listen_addr, adapter, frontend, demux, dvr, timeout, service_id, carousel_id);
 }
 else
 {
  usage(prog_name);
 }
 return 0;
}

variable_types:
argv
char *[]

variable_types:
adapter
unsigned int

variable_types:
frontend
unsigned int

variable_types:
demux
unsigned int

variable_types:
dvr
unsigned int

variable_types:
timeout
unsigned 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: arg int

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


decompiled_code:
__int64 __fastcall read_table(const char *a1, unsigned __int16 a2, char a3, unsigned int a4, _BYTE *a5, char a6)
{
char v6; // r13
char v8; // r12
int v10; // eax
int v11; // ebx
int v12; // er12
__int64 v13; // r13
int *v15; // rax
char *v16; // rax
int *v17; // rax
int v18; // eax
const char *v19; // rdx
int v20; // edi
int v21; // eax
const char *v22; // rdx
int *v23; // rax
int v24; // eax
const char *v25; // rdx
int errnum; // [rsp+8h] [rbp-110h]
struct timeval timeout; // [rsp+10h] [rbp-108h] BYREF
fd_set readfds; // [rsp+20h] [rbp-F8h] BYREF
__int64 v31[7]; // [rsp+A0h] [rbp-78h] BYREF
int v32; // [rsp+D8h] [rbp-40h]

errnum = (int)a1;
v6 = a3;
v8 = a6;
v10 = open(a1, 2);
if ( v10 < 0 )
{
v15 = _errno_location();
v16 = strerror(*v15);
error((int)"open '%s': %s", (int)a1, v16);
return 0LL;
}
v11 = v10;
v31[1] = 0LL;
v31[2] = 0xFF000000FF0000LL;
v31[3] = 0LL;
v31[4] = 0LL;
v31[5] = 0LL;
v31[6] = 0LL;
v31[0] = a2;
v32 = 4;
BYTE2(v31[0]) = v6;
BYTE6(v31[0]) = v8;
if ( ioctl(v10, 0x403C6F2BuLL, v31) < 0 )
{
v17 = _errno_location();
v18 = (unsigned int)strerror(*v17);
error((int)"ioctl DMX_SET_FILTER: %s", v18, v19);
close(v11);
return 0LL;
}
timeout.tv_sec = a4;
timeout.tv_usec = 0LL;
v12 = v11 >> 6;
v13 = 1LL << (v11 % 64);
while ( 1 )
{
*a5 = ~a3;
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[v12] |= v13;
if ( select(v11 + 1, &readfds, 0LL, 0LL, &timeout) < 0 )
{
v20 = *_errno_location();
if ( v20 != 4 )
{
v21 = (unsigned int)strerror(v20);
error((int)"read_table: select: %s", v21, v22);
close(v11);
return 0LL;
}
goto LABEL_7;
}
if ( (readfds.fds_bits[v12] & v13) == 0 )
break;
if ( (int)read(v11, a5, 0x1000uLL) < 0 )
{
v23 = _errno_location();
v24 = (unsigned int)strerror(*v23);
error((int)"read: %s", v24, v25);
close(v11);
return 0LL;
}
LABEL_7:
if ( *a5 == a3 && a5[6] == a6 )
{
close(v11);
return 1LL;
}
}
error((int)"Timeout reading %s", errnum, 0LL);
close(v11);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, unsigned __int16 a2, char a3, unsigned int a4, _BYTE *a5, char a6)
{
char v6; // r13
char v8; // r12
int v10; // eax
int v11; // ebx
int v12; // er12
__int64 v13; // r13
int *v15; // rax
char *v16; // rax
int *v17; // rax
int v18; // eax
const char *v19; // rdx
int v20; // edi
int v21; // eax
const char *v22; // rdx
int *v23; // rax
int v24; // eax
const char *v25; // rdx
int errnum; // [rsp+8h] [rbp-110h]
struct timeval timeout; // [rsp+10h] [rbp-108h] BYREF
fd_set readfds; // [rsp+20h] [rbp-F8h] BYREF
__int64 v31[7]; // [rsp+A0h] [rbp-78h] BYREF
int v32; // [rsp+D8h] [rbp-40h]

errnum = (int)a1;
v6 = a3;
v8 = a6;
v10 = open(a1, 2);
if ( v10 < 0 )
{
v15 = _errno_location();
v16 = strerror(*v15);
error((int)"open '%s': %s", (int)a1, v16);
return 0LL;
}
v11 = v10;
v31[1] = 0LL;
v31[2] = 0xFF000000FF0000LL;
v31[3] = 0LL;
v31[4] = 0LL;
v31[5] = 0LL;
v31[6] = 0LL;
v31[0] = a2;
v32 = 4;
BYTE2(v31[0]) = v6;
BYTE6(v31[0]) = v8;
if ( ioctl(v10, 0x403C6F2BuLL, v31) < 0 )
{
v17 = _errno_location();
v18 = (unsigned int)strerror(*v17);
error((int)"ioctl DMX_SET_FILTER: %s", v18, v19);
close(v11);
return 0LL;
}
timeout.tv_sec = a4;
timeout.tv_usec = 0LL;
v12 = v11 >> 6;
v13 = 1LL << (v11 % 64);
while ( 1 )
{
*a5 = ~a3;
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[v12] |= v13;
if ( select(v11 + 1, &readfds, 0LL, 0LL, &timeout) < 0 )
{
v20 = *_errno_location();
if ( v20 != 4 )
{
v21 = (unsigned int)strerror(v20);
error((int)"read_table: select: %s", v21, v22);
close(v11);
return 0LL;
}
goto LABEL_7;
}
if ( (readfds.fds_bits[v12] & v13) == 0 )
break;
if ( (int)read(v11, a5, 0x1000uLL) < 0 )
{
v23 = _errno_location();
v24 = (unsigned int)strerror(*v23);
error((int)"read: %s", v24, v25);
close(v11);
return 0LL;
}
LABEL_7:
if ( *a5 == a3 && a5[6] == a6 )
{
close(v11);
return 1LL;
}
}
error((int)"Timeout reading %s", errnum, 0LL);
close(v11);
return 0LL;
}

original_code:
_Bool
read_table(char *device, uint16_t pid, uint8_t tid, unsigned int secs, unsigned char *out, unsigned char sn)
{
 int fd_data;
 struct dmx_sct_filter_params sctFilterParams;
 fd_set readfds;
 struct timeval timeout;
 int n;
 if((fd_data = open(device, 02)) < 0)
 {
  error("open '%s': %s", device, strerror((*__errno_location ())));
  return 0;
 }
 memset(&sctFilterParams, 0, sizeof(sctFilterParams));
 sctFilterParams.pid = pid;
 sctFilterParams.timeout = 0;
 sctFilterParams.flags = 4;
 sctFilterParams.filter.filter[0] = tid;
 sctFilterParams.filter.mask[0] = 0xff;
 sctFilterParams.filter.filter[4] = sn;
 sctFilterParams.filter.mask[4] = 0xff;
 if(ioctl(fd_data, (((1U) << (((0 +8)+8)+14)) | ((('o')) << (0 +8)) | (((43)) << 0) | ((((sizeof(struct dmx_sct_filter_params)))) << ((0 +8)+8))), &sctFilterParams) < 0)
 {
  error("ioctl DMX_SET_FILTER: %s", strerror((*__errno_location ())));
  close(fd_data);
  return 0;
 }
 timeout.tv_sec = secs;
 timeout.tv_usec = 0;
 do
 {
  out[0] = ~tid;
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&readfds)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&readfds)->__fds_bits)[((fd_data) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd_data) % (8 * (int) sizeof (__fd_mask)))))));
  if(select(fd_data + 1, &readfds, ((void *)0), ((void *)0), &timeout) < 0)
  {
   if((*__errno_location ()) == 4)
    continue;
   error("read_table: select: %s", strerror((*__errno_location ())));
   close(fd_data);
   return 0;
  }
  if(((((&readfds)->__fds_bits)[((fd_data) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((fd_data) % (8 * (int) sizeof (__fd_mask)))))) != 0))
  {
   if((n = read(fd_data, out, 4096)) < 0)
   {
    error("read: %s", strerror((*__errno_location ())));
    close(fd_data);
    return 0;
   }
  }
  else
  {
   error("Timeout reading %s", device);
   close(fd_data);
   return 0;
  }
 }
 while(out[0] != tid || out[6] != sn);
 close(fd_data);
 return 1;
}

canonical_original_code:
_Bool read_table(char *device, unsigned short pid, unsigned char tid, unsigned int secs, unsigned char *out, unsigned char sn)
{
 int fd_data;
 struct dmx_sct_filter_params sctFilterParams;
 struct fd_set readfds;
 struct timeval timeout;
 int n;
 if((fd_data = open(device, 02)) < 0)
 {
  error("open '%s': %s", device, strerror((*__errno_location ())));
  return 0;
 }
 memset(&sctFilterParams, 0, sizeof(sctFilterParams));
 sctFilterParams.pid = pid;
 sctFilterParams.timeout = 0;
 sctFilterParams.flags = 4;
 sctFilterParams.filter.filter[0] = tid;
 sctFilterParams.filter.mask[0] = 0xff;
 sctFilterParams.filter.filter[4] = sn;
 sctFilterParams.filter.mask[4] = 0xff;
 if(ioctl(fd_data, (((1U) << (((0 +8)+8)+14)) | ((('o')) << (0 +8)) | (((43)) << 0) | ((((sizeof(struct dmx_sct_filter_params)))) << ((0 +8)+8))), &sctFilterParams) < 0)
 {
  error("ioctl DMX_SET_FILTER: %s", strerror((*__errno_location ())));
  close(fd_data);
  return 0;
 }
 timeout.tv_sec = secs;
 timeout.tv_usec = 0;
 do
 {
  out[0] = ~tid;
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&readfds)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&readfds)->__fds_bits)[((fd_data) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd_data) % (8 * (int) sizeof (__fd_mask)))))));
  if(select(fd_data + 1, &readfds, ((void *)0), ((void *)0), &timeout) < 0)
  {
   if((*__errno_location ()) == 4)
    continue;
   error("read_table: select: %s", strerror((*__errno_location ())));
   close(fd_data);
   return 0;
  }
  if(((((&readfds)->__fds_bits)[((fd_data) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((fd_data) % (8 * (int) sizeof (__fd_mask)))))) != 0))
  {
   if((n = read(fd_data, out, 4096)) < 0)
   {
    error("read: %s", strerror((*__errno_location ())));
    close(fd_data);
    return 0;
   }
  }
  else
  {
   error("Timeout reading %s", device);
   close(fd_data);
   return 0;
  }
 }
 while(out[0] != tid || out[6] != sn);
 close(fd_data);
 return 1;
}

variable_types:
device
char *

variable_types:
pid
unsigned short

variable_types:
tid
unsigned char

variable_types:
secs
unsigned int

variable_types:
out
unsigned char *

variable_types:
sn
unsigned char

variable_types: struct dmx_sct_filter_params { unsigned short pid; struct dmx_filter { unsigned char filter[16]; unsigned char mask[16]; unsigned char mode[16]; } filter; unsigned int timeout; unsigned int flags; }

variable_types:
readfds
struct fd_set { long __fds_bits[-1]; }

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

variable_types: n int

user_defined_types: struct dmx_sct_filter_params { unsigned short pid; struct dmx_filter filter; unsigned int timeout; unsigned int flags; }


decompiled_code:
__int64 __fastcall read_pat(const char *a1, unsigned int a2, _BYTE *a3)
{
unsigned int v4; // ebx
const char *v6; // rdx

v4 = cache_load("pat", a3);
if ( !(_BYTE)v4 )
{
v4 = read_table(a1, 0, 0, a2, a3, 0);
if ( (_BYTE)v4 )
cache_save("pat", a3);
else
error((int)"Unable to read PAT", 0, v6);
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, unsigned int a2, _BYTE *a3)
{
unsigned int v4; // ebx
const char *v6; // rdx

v4 = cache_load("pat", a3);
if ( !(_BYTE)v4 )
{
v4 = func0(a1, 0, 0, a2, a3, 0);
if ( (_BYTE)v4 )
cache_save("pat", a3);
else
error((int)"Unable to read PAT", 0, v6);
}
return v4;
}

original_code:
_Bool
read_pat(char *demux, unsigned int timeout, unsigned char *out)
{
 if(cache_load("pat", out))
  return 1;
 if(!read_table(demux, 0x0000, 0x00, timeout, out, 0))
 {
  error("Unable to read PAT");
  return 0;
 }
 cache_save("pat", out);
 return 1;
}

variable_types:
demux
char *