main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
char v4; // al
const char **v5; // rbp
int v6; // er12
__off_t v7; // r13
void *v8; // rax
void *v9; // rbp
unsigned int v10; // er13
int v12; // eax
const char *v13; // rsi
int v14; // [rsp+8h] [rbp-C0h] BYREF
unsigned int v15; // [rsp+Ch] [rbp-BCh] BYREF
struct stat v16; // [rsp+10h] [rbp-B8h] BYREF

trigger = 0;
v14 = 0;
v15 = 0;
dynamic = 0;
dyn_display = 0;
if ( argc <= 1 )
LABEL_33:
usage(*argv);
v3 = 0;
while ( 2 )
{
v4 = getopt(argc, (char *const *)argv, "uhctxds");
if ( v4 != -1 )
{
switch ( v4 )
{
case 'c':
v3 |= 4u;
continue;
case 'd':
v3 |= 0x32u;
continue;
case 'h':
v3 |= 2u;
continue;
case 's':
v3 |= 0x64u;
continue;
case 't':
v3 |= 8u;
continue;
case 'u':
v3 |= 1u;
continue;
case 'x':
v3 |= 0x16u;
continue;
default:
goto LABEL_33;
}
}
break;
}
v5 = &argv[optind];
puts("dermob -- mach-o binary analyzer");
puts("\t(c) 2006-12 by xhr (@giessen.ccc.de)\n");
if ( stat(*v5, &v16) < 0 || (v6 = open(*v5, 0, 0LL), v6 < 0) )
errx(1, "Cannot open %s", *v5);
v7 = v16.st_size;
v8 = malloc(v16.st_size);
v9 = v8;
if ( !v8 )
errx(1, "Cannot allocate memory");
size = v7;
v10 = read(v6, v8, v7);
cpu = get_cpu_information();
bo_a = get_bo_information();
lst = list_create_list();
if ( v3 > 50 )
{
if ( v3 == 100 )
{
display_fat_header(lst, v9, &v14);
display_mo_header(lst, v9, &v14, &v15);
display_load_commands(lst, v9, &v14, v15);
display_buffer(v9, (unsigned int)cs_addr, (unsigned int)cs_offset, (unsigned int)cs_size);
goto LABEL_20;
}
goto LABEL_22;
}
if ( !v3 )
{
LABEL_22:
v12 = display_fat_header(lst, v9, &v14);
if ( v12 > 0 )
printf("- Universal Binary for %d architectures\n", (unsigned int)v12);
if ( (int)display_mo_header(lst, v9, &v14, &v15) <= 0 )
{
puts("No mach-o file");
exit(1);
}
puts("- Vaild mach-o binary");
dyn_display = 1;
display_load_commands(lst, v9, &v14, v15);
v13 = (const char *)&unk_239;
if ( !dynamic )
v13 = "- Statically linked\n";
printf("%s", v13);
goto LABEL_20;
}
switch ( v3 )
{
case 1:
display_fat_header(lst, v9, &v14);
list_traverse_list(lst);
break;
case 2:
case 3:
display_fat_header(lst, v9, &v14);
display_mo_header(lst, v9, &v14, &v15);
list_traverse_list(lst);
break;
case 4:
display_fat_header(lst, v9, &v14);
display_mo_header(lst, v9, &v14, &v15);
display_load_commands(lst, v9, &v14, v15);
list_traverse_list(lst);
break;
case 8:
display_fat_header(lst, v9, &v14);
display_mo_header(lst, v9, &v14, &v15);
display_load_commands(lst, v9, &v14, v15);
display_buffer(v9, (unsigned int)text_addr, (unsigned int)text_offset, (unsigned int)text_size);
break;
case 22:
display_buffer(v9, 0LL, 0LL, v10);
break;
case 50:
display_fat_header(lst, v9, &v14);
display_mo_header(lst, v9, &v14, &v15);
display_load_commands(lst, v9, &v14, v15);
display_buffer(v9, (unsigned int)data_addr, (unsigned int)data_offset, (unsigned int)data_size);
break;
default:
goto LABEL_22;
}
LABEL_20:
list_free_list(lst);
close(v6);
free(v9);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
char v4; // al
const char **v5; // rbp
int v6; // er12
__off_t v7; // r13
void *v8; // rax
void *v9; // rbp
unsigned int v10; // er13
int v12; // eax
const char *v13; // rsi
int v14; // [rsp+8h] [rbp-C0h] BYREF
unsigned int v15; // [rsp+Ch] [rbp-BCh] BYREF
struct stat v16; // [rsp+10h] [rbp-B8h] BYREF

trigger = 0;
v14 = 0;
v15 = 0;
dynamic = 0;
dyn_display = 0;
if ( argc <= 1 )
LABEL_33:
func0(*argv);
v3 = 0;
while ( 2 )
{
v4 = getopt(argc, (char *const *)argv, "uhctxds");
if ( v4 != -1 )
{
switch ( v4 )
{
case 'c':
v3 |= 4u;
continue;
case 'd':
v3 |= 0x32u;
continue;
case 'h':
v3 |= 2u;
continue;
case 's':
v3 |= 0x64u;
continue;
case 't':
v3 |= 8u;
continue;
case 'u':
v3 |= 1u;
continue;
case 'x':
v3 |= 0x16u;
continue;
default:
goto LABEL_33;
}
}
break;
}
v5 = &argv[optind];
puts("dermob -- mach-o binary analyzer");
puts("\t(c) 2006-12 by xhr (@giessen.ccc.de)\n");
if ( stat(*v5, &v16) < 0 || (v6 = open(*v5, 0, 0LL), v6 < 0) )
errx(1, "Cannot open %s", *v5);
v7 = v16.st_size;
v8 = malloc(v16.st_size);
v9 = v8;
if ( !v8 )
errx(1, "Cannot allocate memory");
size = v7;
v10 = read(v6, v8, v7);
cpu = get_cpu_information();
bo_a = get_bo_information();
lst = list_create_list();
if ( v3 > 50 )
{
if ( v3 == 100 )
{
display_fat_header(lst, v9, &v14);
display_mo_header(lst, v9, &v14, &v15);
display_load_commands(lst, v9, &v14, v15);
display_buffer(v9, (unsigned int)cs_addr, (unsigned int)cs_offset, (unsigned int)cs_size);
goto LABEL_20;
}
goto LABEL_22;
}
if ( !v3 )
{
LABEL_22:
v12 = display_fat_header(lst, v9, &v14);
if ( v12 > 0 )
printf("- Universal Binary for %d architectures\n", (unsigned int)v12);
if ( (int)display_mo_header(lst, v9, &v14, &v15) <= 0 )
{
puts("No mach-o file");
exit(1);
}
puts("- Vaild mach-o binary");
dyn_display = 1;
display_load_commands(lst, v9, &v14, v15);
v13 = (const char *)&unk_239;
if ( !dynamic )
v13 = "- Statically linked\n";
printf("%s", v13);
goto LABEL_20;
}
switch ( v3 )
{
case 1:
display_fat_header(lst, v9, &v14);
list_traverse_list(lst);
break;
case 2:
case 3:
display_fat_header(lst, v9, &v14);
display_mo_header(lst, v9, &v14, &v15);
list_traverse_list(lst);
break;
case 4:
display_fat_header(lst, v9, &v14);
display_mo_header(lst, v9, &v14, &v15);
display_load_commands(lst, v9, &v14, v15);
list_traverse_list(lst);
break;
case 8:
display_fat_header(lst, v9, &v14);
display_mo_header(lst, v9, &v14, &v15);
display_load_commands(lst, v9, &v14, v15);
display_buffer(v9, (unsigned int)text_addr, (unsigned int)text_offset, (unsigned int)text_size);
break;
case 22:
display_buffer(v9, 0LL, 0LL, v10);
break;
case 50:
display_fat_header(lst, v9, &v14);
display_mo_header(lst, v9, &v14, &v15);
display_load_commands(lst, v9, &v14, v15);
display_buffer(v9, (unsigned int)data_addr, (unsigned int)data_offset, (unsigned int)data_size);
break;
default:
goto LABEL_22;
}
LABEL_20:
list_free_list(lst);
close(v6);
free(v9);
return 0;
}

original_code:
int
main (int argc, char **argv)
{
 struct stat sb;
 char *buffer, ch;
 int fd, len=1, offset = 0, ncmds = 0, flag = 0, ret;
 trigger = 0;
 dynamic = 0;
 dyn_display = 0;
 if (argc < 2) {
  usage(argv[0]);
 }
 while ((ch = getopt(argc, argv, "uhctxds")) != -1) {
  switch (ch) {
  case 'u': flag |= 0x1; break;
  case 'h': flag |= 0x2; break;
  case 'c': flag |= 0x4; break;
  case 't': flag |= 0x8; break;
  case 'x': flag |= 0x16; break;
  case 'd': flag |= 0x32; break;
  case 's': flag |= 0x64; break;
  default: usage(argv[0]); break;
  }
 }
 argc -= optind;
 argv += optind;
 printf("dermob -- mach-o binary analyzer\n");
 printf("	(c) 2006-12 by xhr (@giessen.ccc.de)\n\n");
 if ((stat(argv[0], &sb)) < 0)
  errx(1, "Cannot open %s", argv[0]);
 if ((fd = open(argv[0], 00, 0)) < 0)
  errx(1, "Cannot open %s", argv[0]);
 if ((buffer = malloc(sb.st_size)) == ((void *)0))
  errx(1, "Cannot allocate memory");
 size = sb.st_size;
 len = read(fd, buffer, size);
 cpu = get_cpu_information();
 bo_a = get_bo_information();
 lst = list_create_list();
 switch (flag) {
  case 0x1:
   display_fat_header(lst, buffer, &offset);
   list_traverse_list(lst);
   break;
  case 0x2:
   display_fat_header(lst, buffer, &offset);
   display_mo_header(lst, buffer, &offset, &ncmds);
   list_traverse_list(lst);
   break;
  case 0x3:
   display_fat_header(lst, buffer, &offset);
   display_mo_header(lst, buffer, &offset, &ncmds);
   list_traverse_list(lst);
   break;
  case 0x4:
   display_fat_header(lst, buffer, &offset);
   display_mo_header(lst, buffer, &offset, &ncmds);
   display_load_commands(lst, buffer, &offset, ncmds);
   list_traverse_list(lst);
   break;
  case 0x8:
   display_fat_header(lst, buffer, &offset);
   display_mo_header(lst, buffer, &offset, &ncmds);
   display_load_commands(lst, buffer, &offset, ncmds);
   display_buffer(buffer, text_addr, text_offset, text_size);
   break;
  case 0x16:
   display_buffer(buffer, 0, 0, len);
   break;
  case 0x32:
   display_fat_header(lst, buffer, &offset);
   display_mo_header(lst, buffer, &offset, &ncmds);
   display_load_commands(lst, buffer, &offset, ncmds);
   display_buffer(buffer, data_addr, data_offset, data_size);
   break;
  case 0x64:
   display_fat_header(lst, buffer, &offset);
   display_mo_header(lst, buffer, &offset, &ncmds);
   display_load_commands(lst, buffer, &offset, ncmds);
   display_buffer(buffer, cs_addr, cs_offset, cs_size);
   break;
  default:
   ret = display_fat_header(lst, buffer, &offset);
   if (ret > 0)
    printf("- Universal Binary for %d architectures\n", ret);
   ret = display_mo_header(lst, buffer, &offset, &ncmds);
   if (ret > 0)
    printf("- Vaild mach-o binary\n");
   else {
    printf("No mach-o file\n");
    exit(1);
   }
   dyn_display = 1;
   display_load_commands(lst, buffer, &offset, ncmds);
   printf("%s", dynamic ? "" : "- Statically linked\n");
   break;
 }
 list_free_list(lst);
 close(fd);
 free(buffer);
 return (0);
}

canonical_original_code:
int main(int argc, char **argv)
{
 struct stat sb;
 char *buffer; char ch;
 int fd; int len = 1; int offset = 0; int ncmds = 0; int flag = 0; int ret;
 trigger = 0;
 dynamic = 0;
 dyn_display = 0;
 if (argc < 2) {
  usage(argv[0]);
 }
 while ((ch = getopt(argc, argv, "uhctxds")) != -1) {
  switch (ch) {
  case 'u': flag |= 0x1; break;
  case 'h': flag |= 0x2; break;
  case 'c': flag |= 0x4; break;
  case 't': flag |= 0x8; break;
  case 'x': flag |= 0x16; break;
  case 'd': flag |= 0x32; break;
  case 's': flag |= 0x64; break;
  default: usage(argv[0]); break;
  }
 }
 argc -= optind;
 argv += optind;
 printf("dermob -- mach-o binary analyzer\n");
 printf("	(c) 2006-12 by xhr (@giessen.ccc.de)\n\n");
 if ((stat(argv[0], &sb)) < 0)
  errx(1, "Cannot open %s", argv[0]);
 if ((fd = open(argv[0], 00, 0)) < 0)
  errx(1, "Cannot open %s", argv[0]);
 if ((buffer = malloc(sb.st_size)) == ((void *)0))
  errx(1, "Cannot allocate memory");
 size = sb.st_size;
 len = read(fd, buffer, size);
 cpu = get_cpu_information();
 bo_a = get_bo_information();
 lst = list_create_list();
 switch (flag) {
  case 0x1:
   display_fat_header(lst, buffer, &offset);
   list_traverse_list(lst);
   break;
  case 0x2:
   display_fat_header(lst, buffer, &offset);
   display_mo_header(lst, buffer, &offset, &ncmds);
   list_traverse_list(lst);
   break;
  case 0x3:
   display_fat_header(lst, buffer, &offset);
   display_mo_header(lst, buffer, &offset, &ncmds);
   list_traverse_list(lst);
   break;
  case 0x4:
   display_fat_header(lst, buffer, &offset);
   display_mo_header(lst, buffer, &offset, &ncmds);
   display_load_commands(lst, buffer, &offset, ncmds);
   list_traverse_list(lst);
   break;
  case 0x8:
   display_fat_header(lst, buffer, &offset);
   display_mo_header(lst, buffer, &offset, &ncmds);
   display_load_commands(lst, buffer, &offset, ncmds);
   display_buffer(buffer, text_addr, text_offset, text_size);
   break;
  case 0x16:
   display_buffer(buffer, 0, 0, len);
   break;
  case 0x32:
   display_fat_header(lst, buffer, &offset);
   display_mo_header(lst, buffer, &offset, &ncmds);
   display_load_commands(lst, buffer, &offset, ncmds);
   display_buffer(buffer, data_addr, data_offset, data_size);
   break;
  case 0x64:
   display_fat_header(lst, buffer, &offset);
   display_mo_header(lst, buffer, &offset, &ncmds);
   display_load_commands(lst, buffer, &offset, ncmds);
   display_buffer(buffer, cs_addr, cs_offset, cs_size);
   break;
  default:
   ret = display_fat_header(lst, buffer, &offset);
   if (ret > 0)
    printf("- Universal Binary for %d architectures\n", ret);
   ret = display_mo_header(lst, buffer, &offset, &ncmds);
   if (ret > 0)
    printf("- Vaild mach-o binary\n");
   else {
    printf("No mach-o file\n");
    exit(1);
   }
   dyn_display = 1;
   display_load_commands(lst, buffer, &offset, ncmds);
   printf("%s", dynamic ? "" : "- Statically linked\n");
   break;
 }
 list_free_list(lst);
 close(fd);
 free(buffer);
 return (0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

variable_types:
buffer
char *

variable_types: ch char

variable_types: len int

variable_types: offset int

variable_types: ncmds int

variable_types: flag int

variable_types: ret int

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


mprintf

repo: thexhr/dermob

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

if ( trigger != 1 )
{
va_start(arg, format);
result = vfprintf(stdout, format, arg);
}
return result;
}

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

if ( trigger != 1 )
{
va_start(arg, format);
result = vfprintf(stdout, format, arg);
}
return result;
}

original_code:
void
mprintf(const char *fmt, ...)
{
    va_list ap;
 if (trigger == 1)
  return;
 __builtin_va_start(ap,fmt);
 vfprintf(stdout, fmt, ap);
 __builtin_va_end(ap);
}

canonical_original_code:
void mprintf(char *fmt, ...)
{
    __builtin_va_list ap;
 if (trigger == 1)
  return;
 __builtin_va_start(ap,fmt);
 vfprintf(stdout, fmt, ap);
 __builtin_va_end(ap);
}

variable_types:
fmt
char *

return_type: void


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

switch ( a1 )
{
case 1:
result = mprintf("LC_SEGMENT\n");
break;
case 2:
result = mprintf("LC_SYMTAB\n");
break;
case 5:
result = mprintf("LC_UNIXTHREAD\n");
break;
case 11:
result = mprintf("LC_DYSYMTAB\n");
break;
case 12:
result = mprintf("LC_LOAD_DYLIB\n");
break;
case 14:
result = mprintf("LC_LOAD_DYLINKER\n");
break;
case 22:
result = mprintf("LC_TWOLEVEL_HINTS\n");
break;
default:
result = mprintf("\n");
break;
}
return result;
}

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

switch ( a1 )
{
case 1:
result = func0("LC_SEGMENT\n");
break;
case 2:
result = func0("LC_SYMTAB\n");
break;
case 5:
result = func0("LC_UNIXTHREAD\n");
break;
case 11:
result = func0("LC_DYSYMTAB\n");
break;
case 12:
result = func0("LC_LOAD_DYLIB\n");
break;
case 14:
result = func0("LC_LOAD_DYLINKER\n");
break;
case 22:
result = func0("LC_TWOLEVEL_HINTS\n");
break;
default:
result = func0("\n");
break;
}
return result;
}

original_code:
void
display_cmd_name(int cmd)
{
 switch(cmd) {
  case 0x1:
   mprintf("LC_SEGMENT\n"); break;
  case 0x2:
   mprintf("LC_SYMTAB\n"); break;
  case 0xc:
   mprintf("LC_LOAD_DYLIB\n"); break;
  case 0xe:
   mprintf("LC_LOAD_DYLINKER\n"); break;
  case 0xb:
   mprintf("LC_DYSYMTAB\n"); break;
  case 0x5:
   mprintf("LC_UNIXTHREAD\n"); break;
  case 0x16:
   mprintf("LC_TWOLEVEL_HINTS\n"); break;
  default:
   mprintf("\n"); break;
 }
}

variable_types: cmd int


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

if ( a1 > 18 )
{
if ( a1 == 16777223 )
return mprintf("x86_64");
return mprintf("\n");
}
if ( a1 <= 5 )
return mprintf("\n");
switch ( a1 )
{
case 6:
result = mprintf("MC680x0");
break;
case 7:
result = mprintf("x86_32");
break;
case 11:
result = mprintf("HPPA");
break;
case 14:
result = mprintf("Sparc");
break;
case 18:
result = mprintf("PowerPC");
break;
default:
return mprintf("\n");
}
return result;
}

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

if ( a1 > 18 )
{
if ( a1 == 16777223 )
return func0("x86_64");
return func0("\n");
}
if ( a1 <= 5 )
return func0("\n");
switch ( a1 )
{
case 6:
result = func0("MC680x0");
break;
case 7:
result = func0("x86_32");
break;
case 11:
result = func0("HPPA");
break;
case 14:
result = func0("Sparc");
break;
case 18:
result = func0("PowerPC");
break;
default:
return func0("\n");
}
return result;
}

original_code:
void
display_cpu_arch(int cputype)
{
        switch (cputype) {
  case ((cpu_type_t) 6):
   mprintf("MC680x0"); break;
  case ((cpu_type_t) 7):
   mprintf("x86_32"); break;
  case (((cpu_type_t) 7) | 0x01000000):
   mprintf("x86_64"); break;
  case ((cpu_type_t) 18):
   mprintf("PowerPC"); break;
  case ((cpu_type_t) 11):
   mprintf("HPPA"); break;
  case ((cpu_type_t) 14):
   mprintf("Sparc"); break;
  default:
   mprintf("\n"); break;
 }
}

canonical_original_code:
void display_cpu_arch(int cputype)
{
        switch (cputype) {
  case ((int) 6):
   mprintf("MC680x0"); break;
  case ((int) 7):
   mprintf("x86_32"); break;
  case (((int) 7) | 0x01000000):
   mprintf("x86_64"); break;
  case ((int) 18):
   mprintf("PowerPC"); break;
  case ((int) 11):
   mprintf("HPPA"); break;
  case ((int) 14):
   mprintf("Sparc"); break;
  default:
   mprintf("\n"); break;
 }
}

variable_types: cputype int


decompiled_code:
__int64 get_cpu_information()
{
return 7LL;
}

canonical_decompiled_code:
__int64 func3()
{
return 7LL;
}

original_code:
int
get_cpu_information()
{
  return(((cpu_type_t) 7));
 return(-1);
}

canonical_original_code:
int get_cpu_information()
{
  return(((int) 7));
 return(-1);
}

return_type: int


decompiled_code:
__int64 get_bo_information()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func4()
{
return 0LL;
}

original_code:
int
get_bo_information()
{
  return(0);
 return(-1);
}


swapi

decompiled_code:
__int64 __fastcall swapi(unsigned int a1)
{
__int64 result; // rax

result = a1;
if ( bo_a == 1 )
{
if ( bo_b )
return result;
return _byteswap_ulong(a1);
}
if ( !bo_a && bo_b == 1 )
return _byteswap_ulong(a1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1)
{
__int64 result; // rax

result = a1;
if ( bo_a == 1 )
{
if ( bo_b )
return result;
return _byteswap_ulong(a1);
}
if ( !bo_a && bo_b == 1 )
return _byteswap_ulong(a1);
return result;
}

variable_types:
i
unsigned int

variable_types:
ret
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall display_fat_header(__int64 a1, __int64 a2, _DWORD *a3)
{
unsigned int *v4; // rbp
int v5; // eax
int v6; // ebp
unsigned int v7; // er12
unsigned int *v8; // rbx
int v10[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v10[0] = 0;
v4 = (unsigned int *)malloc(8uLL);
if ( (int)analyse_fat_header(a2, v10, v4) < 0 )
{
v7 = -1;
free(v4);
}
else
{
list_insert_node(a1, v4, 1LL);
v5 = swapi(v4[1]);
v6 = v5;
if ( v5 <= 0 )
{
v7 = v5;
}
else
{
v7 = 0;
do
{
v8 = (unsigned int *)malloc(0x14uLL);
analyse_fat_arch(a2, v10, v8);
list_insert_node(a1, v8, 2LL);
if ( (unsigned int)swapi(v8[3]) > (unsigned __int64)size )
{
puts("Malformed universal binary. Size for one Architecture is larger than the complete binary.");
exit(1);
}
if ( (unsigned int)swapi(*v8) == cpu )
*a3 = swapi(v8[2]);
++v7;
}
while ( v6 != v7 );
}
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, _DWORD *a3)
{
unsigned int *v4; // rbp
int v5; // eax
int v6; // ebp
unsigned int v7; // er12
unsigned int *v8; // rbx
int v10[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v10[0] = 0;
v4 = (unsigned int *)malloc(8uLL);
if ( (int)analyse_fat_header(a2, v10, v4) < 0 )
{
v7 = -1;
free(v4);
}
else
{
list_insert_node(a1, v4, 1LL);
v5 = func5(v4[1]);
v6 = v5;
if ( v5 <= 0 )
{
v7 = v5;
}
else
{
v7 = 0;
do
{
v8 = (unsigned int *)malloc(0x14uLL);
analyse_fat_arch(a2, v10, v8);
list_insert_node(a1, v8, 2LL);
if ( (unsigned int)func5(v8[3]) > (unsigned __int64)size )
{
puts("Malformed universal binary. Size for one Architecture is larger than the complete binary.");
exit(1);
}
if ( (unsigned int)func5(*v8) == cpu )
*a3 = func5(v8[2]);
++v7;
}
while ( v6 != v7 );
}
}
return v7;
}

original_code:
int
display_fat_header(struct list *lst, char *buffer, int *roffset)
{
 struct fat_header *fh;
 struct fat_arch *fa;
 int offset = 0, i, narch;
 fh = malloc(sizeof(*fh));
 if (analyse_fat_header(buffer, &offset, fh) < 0) {
  free(fh);
  return(-1);
 }
 list_insert_node(lst, fh, 0x1);
 narch = swapi(fh->nfat_arch);
 for (i = 0; i < narch; i++) {
  fa = malloc(sizeof(*fa));
  analyse_fat_arch(buffer, &offset, fa);
  list_insert_node(lst, fa, 0x2);
  if (swapi(fa->size) > size) {
   printf("Malformed universal binary.  Size for one " "Architecture is larger than the complete binary.\n");
   exit(1);
  }
  if (cpu == swapi(fa->cputype))
   *roffset = swapi(fa->offset);
 }
 return(narch);
}

canonical_original_code:
int display_fat_header(struct list *lst, char *buffer, int *roffset)
{
 struct fat_header *fh;
 struct fat_arch *fa;
 int offset = 0; int i; int narch;
 fh = malloc(sizeof(*fh));
 if (analyse_fat_header(buffer, &offset, fh) < 0) {
  free(fh);
  return(-1);
 }
 list_insert_node(lst, fh, 0x1);
 narch = swapi(fh->nfat_arch);
 for (i = 0; i < narch; i++) {
  fa = malloc(sizeof(*fa));
  analyse_fat_arch(buffer, &offset, fa);
  list_insert_node(lst, fa, 0x2);
  if (swapi(fa->size) > size) {
   printf("Malformed universal binary.  Size for one " "Architecture is larger than the complete binary.\n");
   exit(1);
  }
  if (cpu == swapi(fa->cputype))
   *roffset = swapi(fa->offset);
 }
 return(narch);
}

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

variable_types:
roffset
int *

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

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

variable_types: i int

variable_types: narch int

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


decompiled_code:
__int64 __fastcall display_mo_header(__int64 a1, __int64 a2, __int64 a3, _DWORD *a4)
{
unsigned int *v6; // rbp
__int64 result; // rax

v6 = (unsigned int *)malloc(0x1CuLL);
if ( (int)analyse_mo_header(a2, a3, v6) < 0 )
{
free(v6);
result = 0xFFFFFFFFLL;
}
else
{
*a4 = swapi(v6[4]);
list_insert_node(a1, v6, 3LL);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, __int64 a3, _DWORD *a4)
{
unsigned int *v6; // rbp
__int64 result; // rax

v6 = (unsigned int *)malloc(0x1CuLL);
if ( (int)analyse_mo_header(a2, a3, v6) < 0 )
{
free(v6);
result = 0xFFFFFFFFLL;
}
else
{
*a4 = func5(v6[4]);
list_insert_node(a1, v6, 3LL);
result = 1LL;
}
return result;
}

original_code:
int
display_mo_header(struct list *lst, char *buffer, int *offset, int *ncmds)
{
 struct mach_header *mh;
 mh = malloc(sizeof(*mh));
 if (analyse_mo_header(buffer, offset, mh) < 0) {
  free(mh);
  return(-1);
 }
 *ncmds = swapi(mh->ncmds);
 list_insert_node(lst, mh, 0x3);
 return(1);
}

variable_types:
buffer
char *

variable_types:
offset
int *

variable_types:
ncmds
int *

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

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


decompiled_code:
void __fastcall display_load_commands(__int64 a1, __int64 a2, _DWORD *a3, int a4)
{
int i; // er15
unsigned int *v6; // rbx
unsigned int v7; // eax

if ( a4 > 0 )
{
for ( i = 0; i != a4; ++i )
{
v6 = (unsigned int *)malloc(8uLL);
analyse_load_command(a2, a3, v6);
list_insert_node(a1, v6, 4LL);
swapi(v6[1]);
v7 = swapi(*v6);
examine_segmet(a2, a3, v7);
*a3 += swapi(v6[1]);
}
}
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, __int64 a2, _DWORD *a3, int a4)
{
int i; // er15
unsigned int *v6; // rbx
unsigned int v7; // eax

if ( a4 > 0 )
{
for ( i = 0; i != a4; ++i )
{
v6 = (unsigned int *)malloc(8uLL);
analyse_load_command(a2, a3, v6);
list_insert_node(a1, v6, 4LL);
func5(v6[1]);
v7 = func5(*v6);
examine_segmet(a2, a3, v7);
*a3 += func5(v6[1]);
}
}
}

original_code:
void
display_load_commands(struct list *lst, char *buffer, int *offset, int ncmds)
{
 struct load_command *ld;
 struct section *sec;
 int i, nofx = 0, val = 0, j, offset_old;
 for (i = 0; i < ncmds; i++) {
  ld = malloc(sizeof(*ld));
  analyse_load_command(buffer, offset, ld);
  list_insert_node(lst, ld, 0x4);
  offset_old = *offset;
  val = examine_segmet(buffer, offset, swapi(ld->cmd), swapi(ld->cmdsize), &nofx);
  if (nofx > 0) {
   for (j = 0; j < nofx; j++) {
    sec = malloc(sizeof(*sec));
    if (j == 0) *offset += val;
    examine_section(buffer, offset, sec);
    if ((strcmp(sec->segname, "__TEXT") == 0) &&
        (strcmp(sec->sectname, "__text") == 0)) {
     text_addr = swapi(sec->addr);
     text_size = swapi(sec->size);
     text_offset = swapi(sec->offset);
    }
    if ((strcmp(sec->segname, "__TEXT") == 0) &&
        (strcmp(sec->sectname, "__cstring") == 0)) {
     cs_addr = swapi(sec->addr);
     cs_size = swapi(sec->size);
     cs_offset = swapi(sec->offset);
    }
    if ((strcmp(sec->segname, "__DATA") == 0) &&
        (strcmp(sec->sectname, "__data") == 0)) {
     data_addr = swapi(sec->addr);
     data_size = swapi(sec->size);
     data_offset = swapi(sec->offset);
    }
    list_insert_node(lst, sec, 0x5);
   }
   nofx = 0;
  }
  else
   *offset += swapi(ld->cmdsize);
 }
}

canonical_original_code:
void display_load_commands(struct list *lst, char *buffer, int *offset, int ncmds)
{
 struct load_command *ld;
 struct section *sec;
 int i; int nofx = 0; int val = 0; int j; int offset_old;
 for (i = 0; i < ncmds; i++) {
  ld = malloc(sizeof(*ld));
  analyse_load_command(buffer, offset, ld);
  list_insert_node(lst, ld, 0x4);
  offset_old = *offset;
  val = examine_segmet(buffer, offset, swapi(ld->cmd), swapi(ld->cmdsize), &nofx);
  if (nofx > 0) {
   for (j = 0; j < nofx; j++) {
    sec = malloc(sizeof(*sec));
    if (j == 0) *offset += val;
    examine_section(buffer, offset, sec);
    if ((strcmp(sec->segname, "__TEXT") == 0) &&
        (strcmp(sec->sectname, "__text") == 0)) {
     text_addr = swapi(sec->addr);
     text_size = swapi(sec->size);
     text_offset = swapi(sec->offset);
    }
    if ((strcmp(sec->segname, "__TEXT") == 0) &&
        (strcmp(sec->sectname, "__cstring") == 0)) {
     cs_addr = swapi(sec->addr);
     cs_size = swapi(sec->size);
     cs_offset = swapi(sec->offset);
    }
    if ((strcmp(sec->segname, "__DATA") == 0) &&
        (strcmp(sec->sectname, "__data") == 0)) {
     data_addr = swapi(sec->addr);
     data_size = swapi(sec->size);
     data_offset = swapi(sec->offset);
    }
    list_insert_node(lst, sec, 0x5);
   }
   nofx = 0;
  }
  else
   *offset += swapi(ld->cmdsize);
 }
}

variable_types: ncmds int

variable_types: struct load_command { unsigned int cmd; unsigned int cmdsize; } *

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; } *

variable_types: nofx int

variable_types: val int

variable_types: j int


decompiled_code:
int __fastcall print_lc_towlevel_hints(__int64 a1)
{
unsigned int v1; // eax
unsigned int v2; // eax

v1 = swapi(*(_DWORD *)(a1 + 8));
mprintf(" Offset:\t\t%d\n", v1);
v2 = swapi(*(_DWORD *)(a1 + 12));
return mprintf(" No of 2level hints:\t%d\n", v2);
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1)
{
unsigned int v1; // eax
unsigned int v2; // eax

v1 = func5(*(_DWORD *)(a1 + 8));
func0(" Offset:\t\t%d\n", v1);
v2 = func5(*(_DWORD *)(a1 + 12));
return func0(" No of 2level hints:\t%d\n", v2);
}

original_code:
void
print_lc_towlevel_hints(struct twolevel_hints_command *two)
{
 mprintf("  Offset:		%d\n", swapi(two->offset));
 mprintf("  No of 2level hints:	%d\n", swapi(two->nhints));
}

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


decompiled_code:
int __fastcall print_lc_dysymtab(unsigned int *a1)
{
unsigned int v1; // eax
unsigned int v2; // eax
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int v8; // eax
unsigned int v9; // eax
unsigned int v10; // eax
unsigned int v11; // eax
unsigned int v12; // eax
unsigned int v13; // eax
unsigned int v14; // eax
unsigned int v15; // eax
unsigned int v16; // eax
unsigned int v17; // eax
unsigned int v18; // eax

v1 = swapi(a1[2]);
mprintf(" ilocalsym:\t\t%d\n", v1);
v2 = swapi(a1[3]);
mprintf(" nlocalsym:\t\t%d\n", v2);
v3 = swapi(a1[4]);
mprintf(" iextdefsym:\t%d\n", v3);
v4 = swapi(a1[5]);
mprintf(" nextdefsym:\t%d\n", v4);
v5 = swapi(a1[6]);
mprintf(" iundefsym:\t\t%d\n", v5);
v6 = swapi(a1[7]);
mprintf(" nundefsym:\t\t%d\n", v6);
v7 = swapi(a1[8]);
mprintf(" tocoff:\t\t%d\n", v7);
v8 = swapi(a1[9]);
mprintf(" ntoc:\t\t%d\n", v8);
v9 = swapi(a1[10]);
mprintf(" modtaboff:\t\t%d\n", v9);
v10 = swapi(a1[11]);
mprintf(" nmodtab:\t\t%d\n", v10);
v11 = swapi(a1[12]);
mprintf(" extrefsymoff:\t%d\n", v11);
v12 = swapi(a1[13]);
mprintf(" nextrefsyms:\t%d\n", v12);
v13 = swapi(a1[14]);
mprintf(" indirectsymoff:\t%d\n", v13);
v14 = swapi(a1[15]);
mprintf(" nindirectsyms:\t%d\n", v14);
v15 = swapi(a1[16]);
mprintf(" extreloff:\t\t%d\n", v15);
v16 = swapi(a1[17]);
mprintf(" nextrel:\t\t%d\n", v16);
v17 = swapi(a1[18]);
mprintf(" locreloff:\t\t%d\n", v17);
v18 = swapi(a1[19]);
return mprintf(" nlocrel:\t\t%d\n", v18);
}

canonical_decompiled_code:
int __fastcall func10(unsigned int *a1)
{
unsigned int v1; // eax
unsigned int v2; // eax
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int v8; // eax
unsigned int v9; // eax
unsigned int v10; // eax
unsigned int v11; // eax
unsigned int v12; // eax
unsigned int v13; // eax
unsigned int v14; // eax
unsigned int v15; // eax
unsigned int v16; // eax
unsigned int v17; // eax
unsigned int v18; // eax

v1 = func5(a1[2]);
func0(" ilocalsym:\t\t%d\n", v1);
v2 = func5(a1[3]);
func0(" nlocalsym:\t\t%d\n", v2);
v3 = func5(a1[4]);
func0(" iextdefsym:\t%d\n", v3);
v4 = func5(a1[5]);
func0(" nextdefsym:\t%d\n", v4);
v5 = func5(a1[6]);
func0(" iundefsym:\t\t%d\n", v5);
v6 = func5(a1[7]);
func0(" nundefsym:\t\t%d\n", v6);
v7 = func5(a1[8]);
func0(" tocoff:\t\t%d\n", v7);
v8 = func5(a1[9]);
func0(" ntoc:\t\t%d\n", v8);
v9 = func5(a1[10]);
func0(" modtaboff:\t\t%d\n", v9);
v10 = func5(a1[11]);
func0(" nmodtab:\t\t%d\n", v10);
v11 = func5(a1[12]);
func0(" extrefsymoff:\t%d\n", v11);
v12 = func5(a1[13]);
func0(" nextrefsyms:\t%d\n", v12);
v13 = func5(a1[14]);
func0(" indirectsymoff:\t%d\n", v13);
v14 = func5(a1[15]);
func0(" nindirectsyms:\t%d\n", v14);
v15 = func5(a1[16]);
func0(" extreloff:\t\t%d\n", v15);
v16 = func5(a1[17]);
func0(" nextrel:\t\t%d\n", v16);
v17 = func5(a1[18]);
func0(" locreloff:\t\t%d\n", v17);
v18 = func5(a1[19]);
return func0(" nlocrel:\t\t%d\n", v18);
}

original_code:
void
print_lc_dysymtab(struct dysymtab_command *dsym)
{
 mprintf("    ilocalsym:		%d\n", swapi(dsym->ilocalsym));
 mprintf("    nlocalsym:		%d\n", swapi(dsym->nlocalsym));
 mprintf("    iextdefsym:	%d\n", swapi(dsym->iextdefsym));
 mprintf("    nextdefsym:	%d\n", swapi(dsym->nextdefsym));
 mprintf("    iundefsym:		%d\n", swapi(dsym->iundefsym));
 mprintf("    nundefsym:		%d\n", swapi(dsym->nundefsym));
 mprintf("    tocoff:		%d\n", swapi(dsym->tocoff));
 mprintf("    ntoc:		%d\n", swapi(dsym->ntoc));
 mprintf("    modtaboff:		%d\n", swapi(dsym->modtaboff));
 mprintf("    nmodtab:		%d\n", swapi(dsym->nmodtab));
 mprintf("    extrefsymoff:	%d\n", swapi(dsym->extrefsymoff));
 mprintf("    nextrefsyms:	%d\n", swapi(dsym->nextrefsyms));
 mprintf("    indirectsymoff:	%d\n", swapi(dsym->indirectsymoff));
 mprintf("    nindirectsyms:	%d\n", swapi(dsym->nindirectsyms));
 mprintf("    extreloff:		%d\n", swapi(dsym->extreloff));
 mprintf("    nextrel:		%d\n", swapi(dsym->nextrel));
 mprintf("    locreloff:		%d\n", swapi(dsym->locreloff));
 mprintf("    nlocrel:		%d\n", swapi(dsym->nlocrel));
}

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; } *


decompiled_code:
int __fastcall print_lc_load_dylib(unsigned int *a1)
{
int result; // eax
char *v2; // rax
unsigned int v3; // eax
unsigned int v4; // eax
time_t timer; // [rsp+0h] [rbp-10h] BYREF

result = dyn_display;
if ( dyn_display <= 0 )
{
timer = (unsigned int)swapi(a1[3]);
v2 = ctime(&timer);
mprintf(" Timestamp:\t\t%s", v2);
v3 = swapi(a1[4]);
mprintf(" Current version:\t0x%x\n", v3);
v4 = swapi(a1[5]);
result = mprintf(" Compat version:\t0x%x\n", v4);
}
else
{
trigger = 1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func11(unsigned int *a1)
{
int result; // eax
char *v2; // rax
unsigned int v3; // eax
unsigned int v4; // eax
time_t timer; // [rsp+0h] [rbp-10h] BYREF

result = dyn_display;
if ( dyn_display <= 0 )
{
timer = (unsigned int)func5(a1[3]);
v2 = ctime(&timer);
func0(" Timestamp:\t\t%s", v2);
v3 = func5(a1[4]);
func0(" Current version:\t0x%x\n", v3);
v4 = func5(a1[5]);
result = func0(" Compat version:\t0x%x\n", v4);
}
else
{
trigger = 1;
}
return result;
}

original_code:
void
print_lc_load_dylib(struct dylib_command *dly)
{
 time_t timev;
 if (dyn_display < 1) {
  timev = swapi(dly->dylib.timestamp);
  mprintf("    Timestamp:		%s", ctime(&timev));
  mprintf("    Current version:	0x%x\n", swapi(dly->dylib.current_version));
  mprintf("    Compat version:	0x%x\n", swapi(dly->dylib.compatibility_version));
 } else {
  trigger = 0;
  trigger = 1;
 }
}

canonical_original_code:
void print_lc_load_dylib(struct dylib_command *dly)
{
 long timev;
 if (dyn_display < 1) {
  timev = swapi(dly->dylib.timestamp);
  mprintf("    Timestamp:		%s", ctime(&timev));
  mprintf("    Current version:	0x%x\n", swapi(dly->dylib.current_version));
  mprintf("    Compat version:	0x%x\n", swapi(dly->dylib.compatibility_version));
 } else {
  trigger = 0;
  trigger = 1;
 }
}

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: timev long

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

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


decompiled_code:
int __fastcall print_lc_symtab(unsigned int *a1)
{
unsigned int v1; // eax
unsigned int v2; // eax
unsigned int v3; // eax
unsigned int v4; // eax

v1 = swapi(a1[2]);
mprintf(" Symbol table offset:\t%d bytes\n", v1);
v2 = swapi(a1[3]);
mprintf(" Symbol table entries:\t%d\n", v2);
v3 = swapi(a1[4]);
mprintf(" String table offset:\t%d bytes\n", v3);
v4 = swapi(a1[5]);
return mprintf(" String table size:\t\t%d bytes\n", v4);
}

canonical_decompiled_code:
int __fastcall func12(unsigned int *a1)
{
unsigned int v1; // eax
unsigned int v2; // eax
unsigned int v3; // eax
unsigned int v4; // eax

v1 = func5(a1[2]);
func0(" Symbol table offset:\t%d bytes\n", v1);
v2 = func5(a1[3]);
func0(" Symbol table entries:\t%d\n", v2);
v3 = func5(a1[4]);
func0(" String table offset:\t%d bytes\n", v3);
v4 = func5(a1[5]);
return func0(" String table size:\t\t%d bytes\n", v4);
}

original_code:
void
print_lc_symtab(struct symtab_command *symc)
{
 mprintf("    Symbol table offset:	%d bytes\n", swapi(symc->symoff));
 mprintf("    Symbol table entries:	%d\n", swapi(symc->nsyms));
 mprintf("    String table offset:	%d bytes\n", swapi(symc->stroff));
 mprintf("    String table size:		%d bytes\n", swapi(symc->strsize));
}

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


decompiled_code:
int __fastcall print_lc_segment(__int64 a1)
{
unsigned int v1; // eax
unsigned int v2; // eax
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int v8; // eax
unsigned int v9; // eax

mprintf(" Name:\t\t%s\n", (const char *)(a1 + 8));
v1 = swapi(*(_DWORD *)(a1 + 24));
mprintf(" VM addr:\t\t0x%.08x\n", v1);
v2 = swapi(*(_DWORD *)(a1 + 28));
mprintf(" VM size:\t\t0x%.08x\n", v2);
v3 = swapi(*(_DWORD *)(a1 + 28));
mprintf(" VM size:\t\t0x%.08x\n", v3);
v4 = swapi(*(_DWORD *)(a1 + 32));
mprintf(" File offset:\t0x%.08x\n", v4);
v5 = swapi(*(_DWORD *)(a1 + 36));
mprintf(" File size:\t\t%d bytes\n", v5);
v6 = swapi(*(_DWORD *)(a1 + 40));
mprintf(" Max prot:\t\t0x%.08x\n", v6);
v7 = swapi(*(_DWORD *)(a1 + 44));
mprintf(" Init prot:\t\t0x%.08x\n", v7);
v8 = swapi(*(_DWORD *)(a1 + 48));
mprintf(" No of sects:\t%d\n", v8);
v9 = swapi(*(_DWORD *)(a1 + 52));
return mprintf(" Flags:\t\t0x%.08x\n", v9);
}

canonical_decompiled_code:
int __fastcall func13(__int64 a1)
{
unsigned int v1; // eax
unsigned int v2; // eax
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int v8; // eax
unsigned int v9; // eax

func0(" Name:\t\t%s\n", (const char *)(a1 + 8));
v1 = func5(*(_DWORD *)(a1 + 24));
func0(" VM addr:\t\t0x%.08x\n", v1);
v2 = func5(*(_DWORD *)(a1 + 28));
func0(" VM size:\t\t0x%.08x\n", v2);
v3 = func5(*(_DWORD *)(a1 + 28));
func0(" VM size:\t\t0x%.08x\n", v3);
v4 = func5(*(_DWORD *)(a1 + 32));
func0(" File offset:\t0x%.08x\n", v4);
v5 = func5(*(_DWORD *)(a1 + 36));
func0(" File size:\t\t%d bytes\n", v5);
v6 = func5(*(_DWORD *)(a1 + 40));
func0(" Max prot:\t\t0x%.08x\n", v6);
v7 = func5(*(_DWORD *)(a1 + 44));
func0(" Init prot:\t\t0x%.08x\n", v7);
v8 = func5(*(_DWORD *)(a1 + 48));
func0(" No of sects:\t%d\n", v8);
v9 = func5(*(_DWORD *)(a1 + 52));
return func0(" Flags:\t\t0x%.08x\n", v9);
}

original_code:
void
print_lc_segment(struct segment_command *sc)
{
 mprintf("    Name:		%s\n", sc->segname);
 mprintf("    VM addr:		0x%.08x\n", swapi(sc->vmaddr));
 mprintf("    VM size:		0x%.08x\n", swapi(sc->vmsize));
 mprintf("    VM size:		0x%.08x\n", swapi(sc->vmsize));
 mprintf("    File offset:	0x%.08x\n", swapi(sc->fileoff));
 mprintf("    File size:		%d bytes\n", swapi(sc->filesize));
 mprintf("    Max prot:		0x%.08x\n", swapi(sc->maxprot));
 mprintf("    Init prot:		0x%.08x\n", swapi(sc->initprot));
 mprintf("    No of sects:	%d\n", swapi(sc->nsects));
 mprintf("    Flags:		0x%.08x\n", swapi(sc->flags));
}

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; } *


decompiled_code:
int __fastcall print_section(__int64 a1)
{
unsigned int v1; // eax
unsigned int v2; // eax
unsigned int v3; // eax

mprintf(" Sectname:\t%s\n", (const char *)a1);
v1 = swapi(*(_DWORD *)(a1 + 32));
mprintf(" VM addr:\t0x%.08x\n", v1);
v2 = swapi(*(_DWORD *)(a1 + 36));
mprintf(" VM size:\t%d bytes\n", v2);
v3 = swapi(*(_DWORD *)(a1 + 40));
mprintf(" Offset:\t%d\n", v3);
return mprintf("\n");
}

canonical_decompiled_code:
int __fastcall func14(__int64 a1)
{
unsigned int v1; // eax
unsigned int v2; // eax
unsigned int v3; // eax

func0(" Sectname:\t%s\n", (const char *)a1);
v1 = func5(*(_DWORD *)(a1 + 32));
func0(" VM addr:\t0x%.08x\n", v1);
v2 = func5(*(_DWORD *)(a1 + 36));
func0(" VM size:\t%d bytes\n", v2);
v3 = func5(*(_DWORD *)(a1 + 40));
func0(" Offset:\t%d\n", v3);
return func0("\n");
}

original_code:
void
print_section(struct section *sec)
{
 mprintf("     Sectname:	%s\n", sec->sectname);
 mprintf("     VM addr:	0x%.08x\n", swapi(sec->addr));
 mprintf("     VM size:	%d bytes\n", swapi(sec->size));
 mprintf("     Offset:	%d\n", swapi(sec->offset));
 mprintf("\n");
}

user_defined_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:
int __fastcall print_load_command(unsigned int *a1)
{
int v1; // eax
unsigned int v2; // eax

mprintf(" Command:\t");
v1 = swapi(*a1);
display_cmd_name(v1);
v2 = swapi(a1[1]);
return mprintf(" Command size:\t%d bytes\n", v2);
}

canonical_decompiled_code:
int __fastcall func15(unsigned int *a1)
{
int v1; // eax
unsigned int v2; // eax

func0(" Command:\t");
v1 = func5(*a1);
func1(v1);
v2 = func5(a1[1]);
return func0(" Command size:\t%d bytes\n", v2);
}

original_code:
void
print_load_command(struct load_command *ld)
{
 mprintf("    Command:	");
 display_cmd_name(swapi(ld->cmd));
 mprintf("    Command size:	%d bytes\n", swapi(ld->cmdsize));
}

user_defined_types: struct load_command { unsigned int cmd; unsigned int cmdsize; }


decompiled_code:
int __fastcall print_mo_header(unsigned int *a1)
{
unsigned int v1; // eax
int v2; // eax
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax

v1 = swapi(*a1);
mprintf("Magic:\t\t0x%x\n", v1);
mprintf(" CPU Type:\t");
v2 = swapi(a1[1]);
display_cpu_arch(v2);
mprintf("\n");
v3 = swapi(a1[2]);
mprintf(" Subtype:\t%d\n", v3);
v4 = swapi(a1[3]);
mprintf(" Filetype:\t0x%x\n", v4);
v5 = swapi(a1[4]);
mprintf(" No load cmds:\t%d cmds\n", v5);
v6 = swapi(a1[5]);
mprintf(" Size of cmds:\t%d bytes\n", v6);
v7 = swapi(a1[6]);
mprintf(" Flags:\t\t0x%.08x\n", v7);
return mprintf("\n");
}

canonical_decompiled_code:
int __fastcall func16(unsigned int *a1)
{
unsigned int v1; // eax
int v2; // eax
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax

v1 = func5(*a1);
func0("Magic:\t\t0x%x\n", v1);
func0(" CPU Type:\t");
v2 = func5(a1[1]);
func2(v2);
func0("\n");
v3 = func5(a1[2]);
func0(" Subtype:\t%d\n", v3);
v4 = func5(a1[3]);
func0(" Filetype:\t0x%x\n", v4);
v5 = func5(a1[4]);
func0(" No load cmds:\t%d cmds\n", v5);
v6 = func5(a1[5]);
func0(" Size of cmds:\t%d bytes\n", v6);
v7 = func5(a1[6]);
func0(" Flags:\t\t0x%.08x\n", v7);
return func0("\n");
}

original_code:
void
print_mo_header(struct mach_header *mh)
{
 mprintf("Magic:		0x%x\n", swapi(mh->magic));
 mprintf(" CPU Type:	");
 display_cpu_arch(swapi(mh->cputype));
 mprintf("\n");
 mprintf(" Subtype:	%d\n", swapi(mh->cpusubtype));
 mprintf(" Filetype:	0x%x\n", swapi(mh->filetype));
 mprintf(" No load cmds:	%d cmds\n", swapi(mh->ncmds));
 mprintf(" Size of cmds:	%d bytes\n", swapi(mh->sizeofcmds));
 mprintf(" Flags:		0x%.08x\n", swapi(mh->flags));
 mprintf("\n");
}

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


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

v1 = swapi(*a1);
return mprintf("Magic:\t\t0x%x\n", v1);
}

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

v1 = func5(*a1);
return func0("Magic:\t\t0x%x\n", v1);
}

original_code:
void
print_fat_header(struct fat_header *fh)
{
 mprintf("Magic:		0x%x\n", swapi(fh->magic));
}

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


decompiled_code:
int __fastcall print_fat_arch(unsigned int *a1)
{
unsigned int v2; // edi
unsigned int v3; // eax
int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int v8; // eax

v2 = *a1;
if ( bo_a == 1 )
{
mprintf(" CPU Type:\t(%x) ", _byteswap_ulong(v2));
display_cpu_arch(_byteswap_ulong(*a1));
mprintf("\n");
mprintf(" Subtype:\t%d\n", _byteswap_ulong(a1[1]));
mprintf(" Offest:\t%d\n", _byteswap_ulong(a1[2]));
mprintf(" Size:\t%d\n", _byteswap_ulong(a1[3]));
mprintf(" Align:\t%d\n", _byteswap_ulong(a1[4]));
}
else
{
v3 = swapi(v2);
mprintf(" CPU Type:\t(%x) ", v3);
v4 = swapi(*a1);
display_cpu_arch(v4);
mprintf("\n");
v5 = swapi(a1[1]);
mprintf(" Subtype:\t%d\n", v5);
v6 = swapi(a1[2]);
mprintf(" Offest:\t%d\n", v6);
v7 = swapi(a1[3]);
mprintf(" Size:\t%d\n", v7);
v8 = swapi(a1[4]);
mprintf(" Align:\t%d\n", v8);
}
return mprintf("\n");
}

canonical_decompiled_code:
int __fastcall func18(unsigned int *a1)
{
unsigned int v2; // edi
unsigned int v3; // eax
int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int v8; // eax

v2 = *a1;
if ( bo_a == 1 )
{
func0(" CPU Type:\t(%x) ", _byteswap_ulong(v2));
func2(_byteswap_ulong(*a1));
func0("\n");
func0(" Subtype:\t%d\n", _byteswap_ulong(a1[1]));
func0(" Offest:\t%d\n", _byteswap_ulong(a1[2]));
func0(" Size:\t%d\n", _byteswap_ulong(a1[3]));
func0(" Align:\t%d\n", _byteswap_ulong(a1[4]));
}
else
{
v3 = func5(v2);
func0(" CPU Type:\t(%x) ", v3);
v4 = func5(*a1);
func2(v4);
func0("\n");
v5 = func5(a1[1]);
func0(" Subtype:\t%d\n", v5);
v6 = func5(a1[2]);
func0(" Offest:\t%d\n", v6);
v7 = func5(a1[3]);
func0(" Size:\t%d\n", v7);
v8 = func5(a1[4]);
func0(" Align:\t%d\n", v8);
}
return func0("\n");
}

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


decompiled_code:
_QWORD *list_create_list()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
if ( result )
{
result[1] = 0LL;
*result = 0LL;
*((_DWORD *)result + 4) = 0;
}
return result;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
if ( result )
{
result[1] = 0LL;
*result = 0LL;
*((_DWORD *)result + 4) = 0;
}
return result;
}

original_code:
struct list *
list_create_list()
{
 struct list *list;
 list = malloc(sizeof(struct list));
 if (list != ((void *)0)) {
  list->head = list->tail = ((void *)0);
  list->len = 0;
  return (list);
 }
 return (((void *)0));
}

canonical_original_code:
struct list *list_create_list()
{
 struct list *list;
 list = malloc(sizeof(struct list));
 if (list != ((void *)0)) {
  list->head = list->tail = ((void *)0);
  list->len = 0;
  return (list);
 }
 return (((void *)0));
}

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


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; } *


decompiled_code:
void __fastcall list_free_list(void *ptr)
{
void **i; // rbp
void *v3; // rdi

for ( i = *(void ***)ptr; *(_QWORD *)ptr; i = *(void ***)ptr )
{
v3 = *i;
*(_QWORD *)ptr = i[2];
free(v3);
free(i);
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
void **i; // rbp
void *v3; // rdi

for ( i = *(void ***)ptr; *(_QWORD *)ptr; i = *(void ***)ptr )
{
v3 = *i;
*(_QWORD *)ptr = i[2];
free(v3);
free(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);
}


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 *


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

v2 = *a1;
if ( *a1 )
{
if ( a1[1] == v2 )
{
LABEL_7:
if ( a2(v2) )
list_remove_node(a1, v2);
}
else
{
while ( 1 )
{
v3 = *(_QWORD *)(v2 + 16);
if ( a2(v2) )
list_remove_node(a1, v2);
if ( !v3 )
break;
v2 = v3;
if ( a1[1] == v3 )
goto LABEL_7;
}
}
}
}

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:
ptr
char *

user_defined_types: struct fat_header { unsigned int magic; unsigned int nfat_arch; }


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);
}

user_defined_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; } *


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 dylinker_command { unsigned int cmd; unsigned int cmdsize; union lc_str name; }


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(__int64 a1, __int64 a2)
{
__int64 v2; // rax
double v3; // xmm0_8

if ( a2 <= 0 )
return 0.0 / (double)(int)a2;
v2 = a1 + 8 * a2;
v3 = 0.0;
do
{
a1 += 8LL;
v3 = v3 + (double)(int)*(_QWORD *)(a1 - 8);
}
while ( v2 != a1 );
return v3 / (double)(int)a2;
}

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

if ( a2 <= 0 )
return 0.0 / (double)(int)a2;
v2 = a1 + 8 * a2;
v3 = 0.0;
do
{
a1 += 8LL;
v3 = v3 + (double)(int)*(_QWORD *)(a1 - 8);
}
while ( v2 != a1 );
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 )
return 0.0 / (double)(int)a2;
v2 = &a1[a2];
v3 = 0.0;
do
v3 = v3 + *a1++;
while ( a1 != v2 );
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 )
return 0.0 / (double)(int)a2;
v2 = &a1[a2];
v3 = 0.0;
do
v3 = v3 + *a1++;
while ( a1 != v2 );
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:
void __fastcall std_deviation(__int64 a1, __int64 a2, double a3)
{
__int64 v4; // rax
double v5; // xmm1_8
double v6; // xmm0_8
double v7; // xmm1_8

if ( a2 > 1 )
{
v4 = a1 + 8 * a2;
v5 = 0.0;
do
{
a1 += 8LL;
v6 = (double)(int)*(_QWORD *)(a1 - 8) - a3;
v5 = v5 + v6 * v6;
}
while ( v4 != a1 );
v7 = v5 / (double)((int)a2 - 1);
if ( v7 < 0.0 )
sqrt(v7);
}
}

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:
void __fastcall std_deviationr(double *a1, __int64 a2, double a3)
{
double *v4; // rax
double v5; // xmm1_8
double v6; // xmm0_8
double v7; // xmm1_8

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

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 = 16807 * ((__int64)*a1 % 127773) - 2836 * ((__int64)*a1 / 127773);
result = v1 + (v1 < 0 ? 0x7FFFFFFFuLL : 0);
*a1 = result;
return result;
}

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

v1 = 16807 * ((__int64)*a1 % 127773) - 2836 * ((__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:
_BOOL8 termination_condition()
{
_BOOL8 result; // rax
double v1; // xmm0_8

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

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

if ( n_tours < max_tours || (v1 = elapsed_time(1LL), result = 1LL, v1 < max_time) )
result = *(_QWORD *)(best_so_far_ant + 16LL) <= optimal;
return 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 result; // rax
__int64 v1; // rbp
__int64 v2; // rbx
char *v3; // rdi
__int64 v4; // rbp
__int64 v5; // rbx
char *v6; // rdi
__int64 v7; // rdx
__int64 v8; // r13
__int64 v9; // r12
__int64 v10; // rbx
__int64 v11; // rbp
__int64 v12; // rbx
__int64 v13; // rbp
char *v14; // r12
__int64 v15; // rax
bool v16; // zf

result = n_ants;
if ( n_ants <= 0 )
{
if ( n <= 1 )
goto LABEL_21;
goto LABEL_8;
}
v1 = 0LL;
v2 = 0LL;
do
{
++v2;
v3 = (char *)ant + v1;
v1 += 24LL;
ant_empty_memory(v3);
result = n_ants;
}
while ( n_ants > v2 );
if ( n_ants > 0 )
{
v4 = 0LL;
v5 = 0LL;
do
{
++v5;
v6 = (char *)ant + v4;
v4 += 24LL;
place_ant(v6, 0LL);
result = n_ants;
}
while ( n_ants > v5 );
}
v7 = n;
v8 = n;
if ( n > 1 )
{
LABEL_8:
v9 = 0LL;
do
{
++v9;
if ( result > 0 )
{
v10 = 0LL;
do
{
while ( 1 )
{
v11 = 24 * v10;
neighbour_choose_and_move_to_next((char *)ant + 24 * v10, v9);
if ( acs_flag )
break;
result = n_ants;
if ( n_ants <= ++v10 )
goto LABEL_14;
}
++v10;
local_acs_pheromone_update((char *)ant + v11, v9);
result = n_ants;
}
while ( n_ants > v10 );
}
LABEL_14:
v7 = n;
v8 = n;
}
while ( n - 1 > v9 );
}
if ( result > 0 )
{
v12 = 0LL;
while ( 1 )
{
v13 = 24 * v12;
v14 = (char *)ant + 24 * v12;
*(_QWORD *)(*(_QWORD *)v14 + 8 * v7) = **(_QWORD **)v14;
v15 = compute_tour_length();
v16 = acs_flag == 0LL;
*((_QWORD *)v14 + 2) = v15;
if ( v16 )
{
result = n_ants;
if ( n_ants <= ++v12 )
break;
}
else
{
++v12;
local_acs_pheromone_update((char *)ant + v13, v8);
result = n_ants;
if ( n_ants <= v12 )
break;
}
v7 = n;
}
}
LABEL_21:
n_tours += result;
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax
__int64 v1; // rbp
__int64 v2; // rbx
char *v3; // rdi
__int64 v4; // rbp
__int64 v5; // rbx
char *v6; // rdi
__int64 v7; // rdx
__int64 v8; // r13
__int64 v9; // r12
__int64 v10; // rbx
__int64 v11; // rbp
__int64 v12; // rbx
__int64 v13; // rbp
char *v14; // r12
__int64 v15; // rax
bool v16; // zf

result = n_ants;
if ( n_ants <= 0 )
{
if ( n <= 1 )
goto LABEL_21;
goto LABEL_8;
}
v1 = 0LL;
v2 = 0LL;
do
{
++v2;
v3 = (char *)ant + v1;
v1 += 24LL;
ant_empty_memory(v3);
result = n_ants;
}
while ( n_ants > v2 );
if ( n_ants > 0 )
{
v4 = 0LL;
v5 = 0LL;
do
{
++v5;
v6 = (char *)ant + v4;
v4 += 24LL;
place_ant(v6, 0LL);
result = n_ants;
}
while ( n_ants > v5 );
}
v7 = n;
v8 = n;
if ( n > 1 )
{
LABEL_8:
v9 = 0LL;
do
{
++v9;
if ( result > 0 )
{
v10 = 0LL;
do
{
while ( 1 )
{
v11 = 24 * v10;
neighbour_choose_and_move_to_next((char *)ant + 24 * v10, v9);
if ( acs_flag )
break;
result = n_ants;
if ( n_ants <= ++v10 )
goto LABEL_14;
}
++v10;
local_acs_pheromone_update((char *)ant + v11, v9);
result = n_ants;
}
while ( n_ants > v10 );
}
LABEL_14:
v7 = n;
v8 = n;
}
while ( n - 1 > v9 );
}
if ( result > 0 )
{
v12 = 0LL;
while ( 1 )
{
v13 = 24 * v12;
v14 = (char *)ant + 24 * v12;
*(_QWORD *)(*(_QWORD *)v14 + 8 * v7) = **(_QWORD **)v14;
v15 = compute_tour_length();
v16 = acs_flag == 0LL;
*((_QWORD *)v14 + 2) = v15;
if ( v16 )
{
result = n_ants;
if ( n_ants <= ++v12 )
break;
}
else
{
++v12;
local_acs_pheromone_update((char *)ant + v13, v8);
result = n_ants;
if ( n_ants <= v12 )
break;
}
v7 = n;
}
}
LABEL_21:
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)
{
bool v1; // zf
double v3; // [rsp+8h] [rbp-10h]
double v4; // [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);
v1 = acs_flag == 0LL;
n_tours = 1LL;
lambda = LC1;
iteration = 1LL;
restart_iteration = 1LL;
*(_QWORD *)(best_so_far_ant + 16LL) = 0x7FFFFFFFFFFFFFFFLL;
found_best = 0LL;
if ( !v1 )
{
LABEL_8:
if ( !bwas_flag )
goto LABEL_9;
goto LABEL_12;
}
if ( mmas_flag )
{
if ( !bwas_flag )
goto LABEL_4;
goto LABEL_12;
}
if ( !bwas_flag )
{
trail_0 = 1.0 / ((double)(int)nn_tour() * rho);
init_pheromone_trails();
goto LABEL_8;
}
LABEL_12:
v4 = (double)(int)n;
trail_0 = 1.0 / ((double)(int)nn_tour() * v4);
init_pheromone_trails();
LABEL_9:
if ( !mmas_flag )
{
if ( !acs_flag )
goto LABEL_11;
goto LABEL_5;
}
LABEL_4:
trail_max = 1.0 / ((double)(int)nn_tour() * rho);
trail_min = trail_max / ((double)(int)n + (double)(int)n);
init_pheromone_trails();
if ( acs_flag )
{
LABEL_5:
v3 = (double)(int)n;
trail_0 = 1.0 / ((double)(int)nn_tour() * v3);
init_pheromone_trails();
}
LABEL_11:
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)
{
bool v1; // zf
double v3; // [rsp+8h] [rbp-10h]
double v4; // [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);
v1 = acs_flag == 0LL;
n_tours = 1LL;
lambda = LC1;
iteration = 1LL;
restart_iteration = 1LL;
*(_QWORD *)(best_so_far_ant + 16LL) = 0x7FFFFFFFFFFFFFFFLL;
found_best = 0LL;
if ( !v1 )
{
LABEL_8:
if ( !bwas_flag )
goto LABEL_9;
goto LABEL_12;
}
if ( mmas_flag )
{
if ( !bwas_flag )
goto LABEL_4;
goto LABEL_12;
}
if ( !bwas_flag )
{
trail_0 = 1.0 / ((double)(int)nn_tour() * rho);
init_pheromone_trails();
goto LABEL_8;
}
LABEL_12:
v4 = (double)(int)n;
trail_0 = 1.0 / ((double)(int)nn_tour() * v4);
init_pheromone_trails();
LABEL_9:
if ( !mmas_flag )
{
if ( !acs_flag )
goto LABEL_11;
goto LABEL_5;
}
LABEL_4:
trail_max = 1.0 / ((double)(int)nn_tour() * rho);
trail_min = trail_max / ((double)(int)n + (double)(int)n);
init_pheromone_trails();
if ( acs_flag )
{
LABEL_5:
v3 = (double)(int)n;
trail_0 = 1.0 / ((double)(int)nn_tour() * v3);
init_pheromone_trails();
}
LABEL_11:
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; // rbp
__int64 v1; // rbx
_QWORD *v2; // r12
__int64 v3; // rax
bool v4; // cc

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

canonical_decompiled_code:
void func3()
{
__int64 v0; // rbp
__int64 v1; // rbx
_QWORD *v2; // r12
__int64 v3; // rax
bool v4; // cc

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

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; // rdi
__int64 v2; // rax
__int64 v3; // rsi
double v4; // xmm1_8
char *v5; // rbx
double v6; // xmm0_8
double v7; // xmm2_8

v0 = 24 * find_best();
v1 = (char *)ant + v0;
v2 = *(_QWORD *)((char *)ant + v0 + 16);
if ( v2 >= *(_QWORD *)(best_so_far_ant + 16LL) )
{
v3 = restart_best_ant;
if ( *(_QWORD *)(restart_best_ant + 16LL) <= v2 )
return v2;
goto LABEL_8;
}
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 )
{
v4 = (double)(int)n;
if ( ls_flag )
{
trail_max = 1.0 / ((double)(int)*(_QWORD *)(best_so_far_ant + 16LL) * rho);
trail_0 = trail_max;
trail_min = trail_max / (v4 + v4);
}
else
{
v7 = exp(-2.995732273553991 / v4);
trail_max = 1.0 / ((double)(int)*(_QWORD *)(best_so_far_ant + 16LL) * rho);
trail_0 = trail_max;
trail_min = trail_max * ((1.0 - v7) / (v7 * (double)(int)((nn_ants + 1LL) / 2)));
}
}
write_report();
v3 = restart_best_ant;
v5 = (char *)ant + v0;
v2 = *((_QWORD *)v5 + 2);
v1 = v5;
if ( *(_QWORD *)(restart_best_ant + 16LL) > v2 )
{
LABEL_8:
copy_from_to(v1, v3);
restart_found_best = iteration;
v6 = elapsed_time(1LL);
LODWORD(v2) = printf(
"restart best: %ld, restart_found_best %ld, time %.2f\n",
*(_QWORD *)(restart_best_ant + 16LL),
restart_found_best,
v6);
}
return v2;
}

canonical_decompiled_code:
int func4()
{
__int64 v0; // rbx
char *v1; // rdi
__int64 v2; // rax
__int64 v3; // rsi
double v4; // xmm1_8
char *v5; // rbx
double v6; // xmm0_8
double v7; // xmm2_8

v0 = 24 * find_best();
v1 = (char *)ant + v0;
v2 = *(_QWORD *)((char *)ant + v0 + 16);
if ( v2 >= *(_QWORD *)(best_so_far_ant + 16LL) )
{
v3 = restart_best_ant;
if ( *(_QWORD *)(restart_best_ant + 16LL) <= v2 )
return v2;
goto LABEL_8;
}
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 )
{
v4 = (double)(int)n;
if ( ls_flag )
{
trail_max = 1.0 / ((double)(int)*(_QWORD *)(best_so_far_ant + 16LL) * rho);
trail_0 = trail_max;
trail_min = trail_max / (v4 + v4);
}
else
{
v7 = exp(-2.995732273553991 / v4);
trail_max = 1.0 / ((double)(int)*(_QWORD *)(best_so_far_ant + 16LL) * rho);
trail_0 = trail_max;
trail_min = trail_max * ((1.0 - v7) / (v7 * (double)(int)((nn_ants + 1LL) / 2)));
}
}
write_report();
v3 = restart_best_ant;
v5 = (char *)ant + v0;
v2 = *((_QWORD *)v5 + 2);
v1 = v5;
if ( *(_QWORD *)(restart_best_ant + 16LL) > v2 )
{
LABEL_8:
copy_from_to(v1, v3);
restart_found_best = iteration;
v6 = elapsed_time(1LL);
LODWORD(v2) = printf(
"restart best: %ld, restart_found_best %ld, time %.2f\n",
*(_QWORD *)(restart_best_ant + 16LL),
restart_found_best,
v6);
}
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()
{
unsigned __int64 v0; // rax
double v1; // xmm0_8
double v2; // xmm0_8
__int64 v3; // rdx
double v4; // xmm0_8
double v5; // xmm0_8
double v7; // [rsp+0h] [rbp-10h]

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

canonical_decompiled_code:
int func5()
{
unsigned __int64 v0; // rax
double v1; // xmm0_8
double v2; // xmm0_8
__int64 v3; // rdx
double v4; // xmm0_8
double v5; // xmm0_8
double v7; // [rsp+0h] [rbp-10h]

v0 = __ROR8__(0x8F5C28F5C28F5C29LL * iteration + 0x51EB851EB851EB8LL, 2);
if ( v0 <= 0x28F5C28F5C28F5CLL )
{
population_statistics();
branching_factor = node_branching(lambda);
v7 = branching_factor;
v1 = elapsed_time(1LL);
printf(
"\nbest so far %ld, iteration: %ld, time %.2f, b_fac %.5f\n",
*(_QWORD *)(best_so_far_ant + 16LL),
iteration,
v1,
v7);
v2 = branching_factor;
v3 = iteration;
if ( mmas_flag && branch_fac > branching_factor && (__int64)(iteration - restart_found_best) > 250 )
{
puts("INIT TRAILS!!!");
v4 = trail_max;
*(_QWORD *)(restart_best_ant + 16LL) = 0x7FFFFFFFFFFFFFFFLL;
init_pheromone_trails(v4);
compute_total_information();
restart_iteration = iteration;
v5 = elapsed_time(1LL);
v3 = iteration;
restart_time = *(_QWORD *)&v5;
v2 = branching_factor;
}
LODWORD(v0) = printf("try %li, iteration %li, b-fac %f \n\n", n_try, v3, v2);
}
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
char *v2; // rdi
__int64 result; // rax

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

canonical_decompiled_code:
__int64 func6()
{
__int64 v0; // rbp
__int64 v1; // rbx
char *v2; // rdi
__int64 result; // rax

if ( n_ants > 0 )
{
v0 = 0LL;
v1 = 0LL;
do
{
++v1;
v2 = (char *)ant + v0;
v0 += 24LL;
result = global_update_pheromone(v2);
}
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
char *v2; // rdi

if ( n_ants > 0 )
{
v0 = 0LL;
v1 = 0LL;
do
{
++v1;
v2 = (char *)ant + v0;
v0 += 24LL;
global_update_pheromone(v2);
}
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
char *v2; // rdi

if ( n_ants > 0 )
{
v0 = 0LL;
v1 = 0LL;
do
{
++v1;
v2 = (char *)ant + v0;
v0 += 24LL;
global_update_pheromone(v2);
}
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; // rbx
__int64 v1; // r12
char *v2; // rax
char *v3; // rbp
char *v4; // rsi
__int64 *v5; // rdx
__int64 v6; // rcx
__int64 v7; // r8
__int64 v8; // r13
__int64 v9; // rcx
__int64 v10; // rax
__int64 v11; // rsi
__int64 v12; // rdx
char *v13; // rax
__int64 i; // rdi
__int64 v15; // r8

v0 = n_ants;
v1 = 8LL * n_ants;
v2 = (char *)malloc(8LL * n_ants);
v3 = v2;
if ( v0 > 0 )
{
v4 = &v2[v1];
v5 = (__int64 *)((char *)ant + 16);
do
{
v6 = *v5;
v2 += 8;
v5 += 3;
*((_QWORD *)v2 - 1) = v6;
}
while ( v4 != v2 );
}
v7 = ras_ranks;
v8 = 0LL;
if ( ras_ranks > 1 )
{
v9 = *(_QWORD *)v3;
v10 = 0LL;
v11 = 0LL;
if ( v0 <= 0 )
goto LABEL_12;
LABEL_6:
while ( ++v10 != v0 )
{
while ( 1 )
{
v12 = *(_QWORD *)&v3[8 * v10];
if ( v9 <= v12 )
break;
v11 = v10++;
v9 = v12;
if ( v10 == v0 )
goto LABEL_9;
}
}
LABEL_9:
v13 = &v3[8 * v11];
for ( i = 24 * v11; ; i = 0LL )
{
*(_QWORD *)v13 = 0x7FFFFFFFFFFFFFFFLL;
v15 = v7 - v8++;
global_update_pheromone_weighted((char *)ant + i, v15 - 1);
v7 = ras_ranks;
if ( ras_ranks - 1LL <= v8 )
break;
v0 = n_ants;
v9 = *(_QWORD *)v3;
v10 = 0LL;
v11 = 0LL;
if ( n_ants > 0 )
goto LABEL_6;
LABEL_12:
v13 = v3;
}
}
global_update_pheromone_weighted(best_so_far_ant, v7);
free(v3);
}

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

v0 = n_ants;
v1 = 8LL * n_ants;
v2 = (char *)malloc(8LL * n_ants);
v3 = v2;
if ( v0 > 0 )
{
v4 = &v2[v1];
v5 = (__int64 *)((char *)ant + 16);
do
{
v6 = *v5;
v2 += 8;
v5 += 3;
*((_QWORD *)v2 - 1) = v6;
}
while ( v4 != v2 );
}
v7 = ras_ranks;
v8 = 0LL;
if ( ras_ranks > 1 )
{
v9 = *(_QWORD *)v3;
v10 = 0LL;
v11 = 0LL;
if ( v0 <= 0 )
goto LABEL_12;
LABEL_6:
while ( ++v10 != v0 )
{
while ( 1 )
{
v12 = *(_QWORD *)&v3[8 * v10];
if ( v9 <= v12 )
break;
v11 = v10++;
v9 = v12;
if ( v10 == v0 )
goto LABEL_9;
}
}
LABEL_9:
v13 = &v3[8 * v11];
for ( i = 24 * v11; ; i = 0LL )
{
*(_QWORD *)v13 = 0x7FFFFFFFFFFFFFFFLL;
v15 = v7 - v8++;
global_update_pheromone_weighted((char *)ant + i, v15 - 1);
v7 = ras_ranks;
if ( ras_ranks - 1LL <= v8 )
break;
v0 = n_ants;
v9 = *(_QWORD *)v3;
v10 = 0LL;
v11 = 0LL;
if ( n_ants > 0 )
goto LABEL_6;
LABEL_12:
v13 = v3;
}
}
global_update_pheromone_weighted(best_so_far_ant, v7);
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, (__int64)(iteration - restart_iteration) > 24) )
{
if ( result <= 74 )
{
u_gb = 5LL;
}
else if ( result > 124 )
{
result = (result < 250) + 1LL;
u_gb = result;
}
else
{
u_gb = 3LL;
}
}
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, (__int64)(iteration - restart_iteration) > 24) )
{
if ( result <= 74 )
{
u_gb = 5LL;
}
else if ( result > 124 )
{
result = (result < 250) + 1LL;
u_gb = result;
}
else
{
u_gb = 3LL;
}
}
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
double v1; // xmm0_8

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();
v1 = trail_0;
*(_QWORD *)(restart_best_ant + 16LL) = 0x7FFFFFFFFFFFFFFFLL;
init_pheromone_trails(v1);
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
double v1; // xmm0_8

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();
v1 = trail_0;
*(_QWORD *)(restart_best_ant + 16LL) = 0x7FFFFFFFFFFFFFFFLL;
init_pheromone_trails(v1);
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 );
}