original_code:
void file_probe()
{
 struct mach_header *mac;
 struct fat_header *fat;
 Elf32_Ehdr *elf;
 _IMAGE_DOS_HEADER *mzexe;
 _IMAGE_NT_HEADERS *pe;
 _IMAGE_FILE_HEADER *pe2;
 int x;
 if(!fc_ptr) {printf("no file loaded!\n"); return;}
 mac=(struct mach_header*)fc_ptr->faddr;
 if((mac->magic==0xfeedface)||(mac->magic==0xcefaedfe)||(mac->magic==0xfeedfacf)||(mac->magic==0xcffaedfe))
 {
  fc_ptr->file_type=FT_MACHO;
  if(mac->magic==0xfeedface) {fc_ptr->file_endian=fc_ptr->cpu_endian;fc_ptr->file_bit_class=bit32;}
  if(mac->magic==0xcefaedfe) {fc_ptr->file_endian=(~fc_ptr->cpu_endian) & 1;fc_ptr->file_bit_class=bit32;}
  if(mac->magic==0xfeedfacf) {fc_ptr->file_endian=fc_ptr->cpu_endian;fc_ptr->file_bit_class=bit64;}
  if(mac->magic==0xcffaedfe) {fc_ptr->file_endian=(~fc_ptr->cpu_endian) & 1;fc_ptr->file_bit_class=bit64;}
  fc_ptr->file_cpu_type=get_data32(mac->cputype);
  return;
 }
 fat=(struct fat_header*)fc_ptr->faddr;
 if((fat->magic==0xcafebabe)||(fat->magic==0xbebafeca))
 {
  fc_ptr->file_type=FT_FATMACHO;
  fc_ptr->file_endian=big_endian;
  return;
 }
 elf=(Elf32_Ehdr*)fc_ptr->faddr;
 if((strncmp("\177ELF",(char *)elf->e_ident,4))==0)
 {
  fc_ptr->file_type=FT_ELF;
  if(elf->e_ident[5]==1) fc_ptr->file_endian=little_endian;
  if(elf->e_ident[5]==2) fc_ptr->file_endian=big_endian;
  if(elf->e_ident[4]==1) fc_ptr->file_bit_class=bit32;
  if(elf->e_ident[4]==2) fc_ptr->file_bit_class=bit64;
  fc_ptr->file_cpu_type=get_data16(elf->e_machine);
  return;
 }
 mzexe=(_IMAGE_DOS_HEADER*)fc_ptr->faddr;
 x=(int)mzexe->e_magic;
 if((x==0x5A4D)||(x==0x4d5a))
 {
  fc_ptr->file_type=FT_MZEXE;
  fc_ptr->file_endian=little_endian;
  x=get_data32(mzexe->e_lfanew);
  pe=(_IMAGE_NT_HEADERS*)(fc_ptr->faddr+x);
  x=get_data32(pe->Signature);
  if(x==0x00004550)
  {
   fc_ptr->file_type=FT_PE;
   pe2=(_IMAGE_FILE_HEADER*) (&pe->FileHeader);
   fc_ptr->file_cpu_type=get_data16(pe2->Machine);
   switch(fc_ptr->file_cpu_type) {
    case 0x8664:
    case 0x200:
     fc_ptr->file_bit_class=bit64;
     fc_ptr->file_endian=little_endian;
     break;
    case 0x266:
    case 0x466:
     fc_ptr->file_bit_class=bit16;
     break;
    default:
     fc_ptr->file_bit_class=bit32;
     fc_ptr->file_endian=little_endian;
     break;
   }
  }
 }
}

canonical_original_code:
void file_probe()
{
 struct mach_header *mac;
 struct fat_header *fat;
 struct Elf32_Ehdr *elf;
 struct _IMAGE_DOS_HEADER *mzexe;
 struct _IMAGE_NT_HEADERS *pe;
 struct _IMAGE_FILE_HEADER *pe2;
 int x;
 if(!fc_ptr) {printf("no file loaded!\n"); return;}
 mac=(struct mach_header *)fc_ptr->faddr;
 if((mac->magic==0xfeedface)||(mac->magic==0xcefaedfe)||(mac->magic==0xfeedfacf)||(mac->magic==0xcffaedfe))
 {
  fc_ptr->file_type=FT_MACHO;
  if(mac->magic==0xfeedface) {fc_ptr->file_endian=fc_ptr->cpu_endian;fc_ptr->file_bit_class=bit32;}
  if(mac->magic==0xcefaedfe) {fc_ptr->file_endian=(~fc_ptr->cpu_endian) & 1;fc_ptr->file_bit_class=bit32;}
  if(mac->magic==0xfeedfacf) {fc_ptr->file_endian=fc_ptr->cpu_endian;fc_ptr->file_bit_class=bit64;}
  if(mac->magic==0xcffaedfe) {fc_ptr->file_endian=(~fc_ptr->cpu_endian) & 1;fc_ptr->file_bit_class=bit64;}
  fc_ptr->file_cpu_type=get_data32(mac->cputype);
  return;
 }
 fat=(struct fat_header *)fc_ptr->faddr;
 if((fat->magic==0xcafebabe)||(fat->magic==0xbebafeca))
 {
  fc_ptr->file_type=FT_FATMACHO;
  fc_ptr->file_endian=big_endian;
  return;
 }
 elf=(struct Elf32_Ehdr *)fc_ptr->faddr;
 if((strncmp("\177ELF",(char *)elf->e_ident,4))==0)
 {
  fc_ptr->file_type=FT_ELF;
  if(elf->e_ident[5]==1) fc_ptr->file_endian=little_endian;
  if(elf->e_ident[5]==2) fc_ptr->file_endian=big_endian;
  if(elf->e_ident[4]==1) fc_ptr->file_bit_class=bit32;
  if(elf->e_ident[4]==2) fc_ptr->file_bit_class=bit64;
  fc_ptr->file_cpu_type=get_data16(elf->e_machine);
  return;
 }
 mzexe=(struct _IMAGE_DOS_HEADER *)fc_ptr->faddr;
 x=(int)mzexe->e_magic;
 if((x==0x5A4D)||(x==0x4d5a))
 {
  fc_ptr->file_type=FT_MZEXE;
  fc_ptr->file_endian=little_endian;
  x=get_data32(mzexe->e_lfanew);
  pe=(struct _IMAGE_NT_HEADERS *)(fc_ptr->faddr+x);
  x=get_data32(pe->Signature);
  if(x==0x00004550)
  {
   fc_ptr->file_type=FT_PE;
   pe2=(struct _IMAGE_FILE_HEADER *) (&pe->FileHeader);
   fc_ptr->file_cpu_type=get_data16(pe2->Machine);
   switch(fc_ptr->file_cpu_type) {
    case 0x8664:
    case 0x200:
     fc_ptr->file_bit_class=bit64;
     fc_ptr->file_endian=little_endian;
     break;
    case 0x266:
    case 0x466:
     fc_ptr->file_bit_class=bit16;
     break;
    default:
     fc_ptr->file_bit_class=bit32;
     fc_ptr->file_endian=little_endian;
     break;
   }
  }
 }
}

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

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

variable_types: struct Elf32_Ehdr { unsigned char e_ident[-1]; unsigned short e_type; unsigned short e_machine; unsigned int e_version; unsigned int e_entry; unsigned int e_phoff; unsigned int e_shoff; unsigned int e_flags; unsigned short e_ehsize; unsigned short e_phentsize; unsigned short e_phnum; unsigned short e_shentsize; unsigned short e_shnum; unsigned short e_shstrndx; } *

variable_types: struct _IMAGE_DOS_HEADER { unsigned short e_magic; unsigned short e_cblp; unsigned short e_cp; unsigned short e_crlc; unsigned short e_cparhdr; unsigned short e_minalloc; unsigned short e_maxalloc; unsigned short e_ss; unsigned short e_sp; unsigned short e_csum; unsigned short e_ip; unsigned short e_cs; unsigned short e_lfarlc; unsigned short e_ovno; unsigned short e_res[4]; unsigned short e_oemid; unsigned short e_oeminfo; unsigned short e_res2[10]; unsigned int e_lfanew; } *

variable_types: struct _IMAGE_NT_HEADERS { unsigned int Signature; struct _IMAGE_FILE_HEADER { unsigned short Machine; unsigned short NumberOfSections; unsigned int TimeDateStamp; unsigned int PointerToSymbolTable; unsigned int NumberOfSymbols; unsigned short SizeOfOptionalHeader; unsigned short Characteristics; } FileHeader; struct _IMAGE_OPTIONAL_HEADER { unsigned short Magic; unsigned char MajorLinkerVersion; unsigned char MinorLinkerVersion; unsigned int SizeOfCode; unsigned int SizeOfInitializedData; unsigned int SizeOfUninitializedData; unsigned int AddressOfEntryPoint; unsigned int BaseOfCode; unsigned int BaseOfData; unsigned int ImageBase; unsigned int SectionAlignment; unsigned int FileAlignment; unsigned short MajorOperatingSystemVersion; unsigned short MinorOperatingSystemVersion; unsigned short MajorImageVersion; unsigned short MinorImageVersion; unsigned short MajorSubsystemVersion; unsigned short MinorSubsystemVersion; unsigned int Reserved1; unsigned int SizeOfImage; unsigned int SizeOfHeaders; unsigned int CheckSum; unsigned short Subsystem; unsigned short DllCharacteristics; unsigned int SizeOfStackReserve; unsigned int SizeOfStackCommit; unsigned int SizeOfHeapReserve; unsigned int SizeOfHeapCommit; unsigned int LoaderFlags; unsigned int NumberOfRvaAndSizes; struct _IMAGE_DATA_DIRECTORY { unsigned int VirtualAddress; unsigned int Size; } DataDirectory[16]; } OptionalHeader; } *

variable_types: struct _IMAGE_FILE_HEADER { unsigned short Machine; unsigned short NumberOfSections; unsigned int TimeDateStamp; unsigned int PointerToSymbolTable; unsigned int NumberOfSymbols; unsigned short SizeOfOptionalHeader; unsigned short Characteristics; } *

variable_types: x int

user_defined_types: struct _IMAGE_NT_HEADERS { unsigned int Signature; struct _IMAGE_FILE_HEADER FileHeader; struct _IMAGE_OPTIONAL_HEADER OptionalHeader; }

user_defined_types: struct _IMAGE_OPTIONAL_HEADER { unsigned short Magic; unsigned char MajorLinkerVersion; unsigned char MinorLinkerVersion; unsigned int SizeOfCode; unsigned int SizeOfInitializedData; unsigned int SizeOfUninitializedData; unsigned int AddressOfEntryPoint; unsigned int BaseOfCode; unsigned int BaseOfData; unsigned int ImageBase; unsigned int SectionAlignment; unsigned int FileAlignment; unsigned short MajorOperatingSystemVersion; unsigned short MinorOperatingSystemVersion; unsigned short MajorImageVersion; unsigned short MinorImageVersion; unsigned short MajorSubsystemVersion; unsigned short MinorSubsystemVersion; unsigned int Reserved1; unsigned int SizeOfImage; unsigned int SizeOfHeaders; unsigned int CheckSum; unsigned short Subsystem; unsigned short DllCharacteristics; unsigned int SizeOfStackReserve; unsigned int SizeOfStackCommit; unsigned int SizeOfHeapReserve; unsigned int SizeOfHeapCommit; unsigned int LoaderFlags; unsigned int NumberOfRvaAndSizes; struct _IMAGE_DATA_DIRECTORY DataDirectory[16]; }


repo: elboza/dwarf-ng

decompiled_code:
__int64 get_s_val()
{
int v0; // eax

if ( !fc_ptr )
goto LABEL_9;
v0 = *(_DWORD *)(fc_ptr + 1056);
if ( v0 != 4 )
{
if ( v0 > 4 )
{
if ( v0 == 5 )
return fatmacho_get_s_val();
}
else
{
if ( v0 == 2 )
return 0LL;
if ( v0 == 3 )
return elf_get_s_val();
}
LABEL_9:
puts("unknown file.");
return 0LL;
}
return macho_get_s_val();
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // eax

if ( !fc_ptr )
goto LABEL_9;
v0 = *(_DWORD *)(fc_ptr + 1056);
if ( v0 != 4 )
{
if ( v0 > 4 )
{
if ( v0 == 5 )
return fatmacho_get_s_val();
}
else
{
if ( v0 == 2 )
return 0LL;
if ( v0 == 3 )
return elf_get_s_val();
}
LABEL_9:
puts("unknown file.");
return 0LL;
}
return macho_get_s_val();
}

original_code:
struct _var* get_s_val(struct _structvar *ptr)
{
 struct _var *var;
 if(!fc_ptr) {printf("unknown file.\n"); return ((void *)0);}
 switch(fc_ptr->file_type){
  case FT_ELF:
   var=elf_get_s_val(ptr);
   return var;
   break;
  case FT_FATMACHO:
   var=fatmacho_get_s_val(ptr);
   return var;
   break;
  case FT_MACHO:
   var=macho_get_s_val(ptr);
   return var;
   break;
  case FT_PE:
   break;
  default:
   printf("unknown file.\n");
   return ((void *)0);
   break;
 }
 return ((void *)0);
}

canonical_original_code:
struct _var *get_s_val(struct _structvar *ptr)
{
 struct _var *var;
 if(!fc_ptr) {printf("unknown file.\n"); return ((void *)0);}
 switch(fc_ptr->file_type){
  case FT_ELF:
   var=elf_get_s_val(ptr);
   return var;
   break;
  case FT_FATMACHO:
   var=fatmacho_get_s_val(ptr);
   return var;
   break;
  case FT_MACHO:
   var=macho_get_s_val(ptr);
   return var;
   break;
  case FT_PE:
   break;
  default:
   printf("unknown file.\n");
   return ((void *)0);
   break;
 }
 return ((void *)0);
}

variable_types: struct _structvar { char name[255]; int num; struct _structvar *next; } *

variable_types: struct _var { char *name; int type; int var_type; union { char *s; long num; } val; } *


decompiled_code:
int __fastcall set_s_val(__int64 a1, __int64 a2)
{
int v2; // eax

if ( !fc_ptr )
return puts("unknown file.");
v2 = *(_DWORD *)(fc_ptr + 1056);
if ( v2 == 4 )
{
macho_set_s_val();
return destroytmpvar(a2);
}
if ( v2 > 4 )
{
if ( v2 == 5 )
{
fatmacho_set_s_val();
return destroytmpvar(a2);
}
}
else
{
if ( v2 == 2 )
{
pe_set_s_val();
return destroytmpvar(a2);
}
if ( v2 == 3 )
{
elf_set_s_val();
return destroytmpvar(a2);
}
}
puts("unknown file.");
return destroytmpvar(a2);
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, __int64 a2)
{
int v2; // eax

if ( !fc_ptr )
return puts("unknown file.");
v2 = *(_DWORD *)(fc_ptr + 1056);
if ( v2 == 4 )
{
macho_set_s_val();
return destroytmpvar(a2);
}
if ( v2 > 4 )
{
if ( v2 == 5 )
{
fatmacho_set_s_val();
return destroytmpvar(a2);
}
}
else
{
if ( v2 == 2 )
{
pe_set_s_val();
return destroytmpvar(a2);
}
if ( v2 == 3 )
{
elf_set_s_val();
return destroytmpvar(a2);
}
}
puts("unknown file.");
return destroytmpvar(a2);
}

original_code:
void set_s_val(struct _structvar *ptr,struct _var *val)
{
 if(!fc_ptr) {printf("unknown file.\n"); return;}
 switch(fc_ptr->file_type){
  case FT_ELF:
   elf_set_s_val(ptr,val);
   break;
  case FT_FATMACHO:
   fatmacho_set_s_val(ptr,val);
   break;
  case FT_MACHO:
   macho_set_s_val(ptr,val);
   break;
  case FT_PE:
   pe_set_s_val(ptr,val);
   break;
  default:
   printf("unknown file.\n");
   break;
 }
 destroytmpvar(val);
}

canonical_original_code:
void set_s_val(struct _structvar *ptr, struct _var *val)
{
 if(!fc_ptr) {printf("unknown file.\n"); return;}
 switch(fc_ptr->file_type){
  case FT_ELF:
   elf_set_s_val(ptr,val);
   break;
  case FT_FATMACHO:
   fatmacho_set_s_val(ptr,val);
   break;
  case FT_MACHO:
   macho_set_s_val(ptr,val);
   break;
  case FT_PE:
   pe_set_s_val(ptr,val);
   break;
  default:
   printf("unknown file.\n");
   break;
 }
 destroytmpvar(val);
}

return_type: void

user_defined_types: struct _structvar { char name[255]; int num; struct _structvar *next; }

user_defined_types: struct _var { char *name; int type; int var_type; union { char *s; long num; } val; }


repo: elderberry-capstone/elderberry

decompiled_code:
__int64 __fastcall common_cb(unsigned int a1, unsigned int a2)
{
__int64 result; // rax
unsigned int v3; // [rsp+Ch] [rbp-Ch]

result = readsocket(a2, &buffer, 1000LL);
if ( (int)result > 0 )
{
v3 = result;
FCF_Log(a1, &buffer, (unsigned int)result);
result = v3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, unsigned int a2)
{
__int64 result; // rax
unsigned int v3; // [rsp+Ch] [rbp-Ch]

result = readsocket(a2, &buffer, 1000LL);
if ( (int)result > 0 )
{
v3 = result;
FCF_Log(a1, &buffer, (unsigned int)result);
result = v3;
}
return result;
}

original_code:
static int common_cb (uint32_t fourcc, int fd) {
 int rc = readsocket(fd, buffer, sizeof(buffer));
 if (rc > 0) {
  FCF_Log(fourcc, buffer, rc);
 }
 return rc;
}

canonical_original_code:
static int common_cb(unsigned int fourcc, int fd) {
 int rc = readsocket(fd, buffer, sizeof(buffer));
 if (rc > 0) {
  FCF_Log(fourcc, buffer, rc);
 }
 return rc;
}

variable_types:
fourcc
unsigned int

variable_types: fd int

variable_types: rc int

return_type: int


decompiled_code:
__int64 virtgyro_cb()
{
unsigned int v0; // eax
unsigned int *v1; // rdx

v0 = _bswap_32(0x4759524Fu);
return common_cb(v0, *v1);
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // eax
unsigned int *v1; // rdx

v0 = func0(0x4759524Fu);
return func1(v0, *v1);
}

original_code:
static int virtgyro_cb (struct pollfd *pfd) {
 return common_cb (htonl((('G') << 24) | (('Y') << 16) | (('R') << 8) | ('O')), pfd->fd);
}

canonical_original_code:
static int virtgyro_cb(struct pollfd *pfd) {
 return common_cb (htonl((('G') << 24) | (('Y') << 16) | (('R') << 8) | ('O')), pfd->fd);
}

variable_types: struct pollfd { int fd; short events; short revents; } *


decompiled_code:
__int64 virtacc_cb()
{
unsigned int v0; // eax
unsigned int *v1; // rdx

v0 = _bswap_32(0x4143434Fu);
return common_cb(v0, *v1);
}

canonical_decompiled_code:
__int64 func3()
{
unsigned int v0; // eax
unsigned int *v1; // rdx

v0 = func0(0x4143434Fu);
return func1(v0, *v1);
}

original_code:
static int virtacc_cb (struct pollfd *pfd) {
 return common_cb (htonl((('A') << 24) | (('C') << 16) | (('C') << 8) | ('O')), pfd->fd);
}

canonical_original_code:
static int virtacc_cb(struct pollfd *pfd) {
 return common_cb (htonl((('A') << 24) | (('C') << 16) | (('C') << 8) | ('O')), pfd->fd);
}

user_defined_types: struct pollfd { int fd; short events; short revents; }


initvirtdev

decompiled_code:
__int64 __fastcall initvirtdev(const char *a1, unsigned int a2, __int64 a3)
{
unsigned int v4; // eax

printf("probing %s: (waiting for connection localhost:%d)\n", a1, a2);
v4 = getsocket(a2);
return fcf_addfd(v4, 1LL, a3);
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1, unsigned int a2, __int64 a3)
{
unsigned int v4; // eax

printf("probing %s: (waiting for connection localhost:%d)\n", a1, a2);
v4 = getsocket(a2);
return fcf_addfd(v4, 1LL, a3);
}

original_code:
static int initvirtdev (const char* devname, int port, pollCallback cb) {
 printf ("probing %s: (waiting for connection localhost:%d)\n", devname, port);
 int fd = getsocket(port);
 int rc = fcf_addfd (fd, 0x001, cb);
 return rc;
}

canonical_original_code:
static int initvirtdev(char *devname, int port, int (*cb)(struct pollfd *pfd)) {
 printf ("probing %s: (waiting for connection localhost:%d)\n", devname, port);
 int fd = getsocket(port);
 int rc = fcf_addfd (fd, 0x001, cb);
 return rc;
}

variable_types:
devname
char *

variable_types: port int

variable_types: int (*)(struct pollfd { int fd; short events; short revents; } *pfd)


decompiled_code:
__int64 init_virtgyro()
{
return initvirtdev("virt gyro", 0x1F91u, (__int64)virtgyro_cb);
}

canonical_decompiled_code:
__int64 func5()
{
return func4("virt gyro", 0x1F91u, (__int64)virtgyro_cb);
}

original_code:
int init_virtgyro() {
 return initvirtdev ("virt gyro", 8081, virtgyro_cb);
}


decompiled_code:
__int64 init_virtacc()
{
return initvirtdev("virt acc", 0x1F92u, (__int64)virtacc_cb);
}

canonical_decompiled_code:
__int64 func6()
{
return func4("virt acc", 0x1F92u, (__int64)virtacc_cb);
}

original_code:
int init_virtacc() {
 return initvirtdev ("virt acc", 8082, virtacc_cb);
}


signalhandler

decompiled_code:
void __fastcall signalhandler(unsigned int a1)
{
printf("\n **signal handler: signum = %d", a1);
if ( a1 == 2 )
stop_main_loop();
}

canonical_decompiled_code:
void __fastcall func0(unsigned int a1)
{
printf("\n **signal handler: signum = %d", a1);
if ( a1 == 2 )
stop_main_loop();
}

original_code:
static void signalhandler(int signum) {
    printf ("\n **signal handler: signum = %d", signum);
    if (signum == 2) {
        stop_main_loop ();
    }
}

variable_types: signum int


handleErrorPoll

decompiled_code:
__int64 handleErrorPoll()
{
int v0; // er12
char *v1; // r13
unsigned int v2; // eax

v0 = *_errno_location();
v1 = strerror(v0);
printf("\n poll error handling: errno=%d %s ", (unsigned int)v0, v1);
if ( v0 == 14 )
{
printf("EFAULT");
}
else if ( v0 > 14 )
{
if ( v0 == 22 )
printf("EINVAL");
}
else if ( v0 == 4 )
{
printf("EINTR");
}
else if ( v0 == 12 )
{
printf("ENOMEM");
}
v2 = _bswap_32_constprop_0();
return printf_tagged_message(v2, "\n poll returned with errno=%d %s", (unsigned int)v0, v1);
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // er12
char *v1; // r13
unsigned int v2; // eax

v0 = *_errno_location();
v1 = strerror(v0);
printf("\n poll error handling: errno=%d %s ", (unsigned int)v0, v1);
if ( v0 == 14 )
{
printf("EFAULT");
}
else if ( v0 > 14 )
{
if ( v0 == 22 )
printf("EINVAL");
}
else if ( v0 == 4 )
{
printf("EINTR");
}
else if ( v0 == 12 )
{
printf("ENOMEM");
}
v2 = func1();
return printf_tagged_message(v2, "\n poll returned with errno=%d %s", (unsigned int)v0, v1);
}

original_code:
void handleErrorPoll(void) {
    int err = (*__errno_location ());
    char *msg = strerror(err);
    printf ("\n poll error handling: errno=%d %s ", err, msg);
    switch(err) {
        case 14: printf ("EFAULT"); break;
        case 4: printf ("EINTR"); break;
        case 22: printf ("EINVAL"); break;
        case 12: printf ("ENOMEM"); break;
    }
    printf_tagged_message(htonl((('L') << 24) | (('O') << 16) | (('G') << 8) | ('S')), "\n poll returned with errno=%d %s", err, msg);
}

canonical_original_code:
void handleErrorPoll() {
    int err = (*__errno_location ());
    char *msg = strerror(err);
    printf ("\n poll error handling: errno=%d %s ", err, msg);
    switch(err) {
        case 14: printf ("EFAULT"); break;
        case 4: printf ("EINTR"); break;
        case 22: printf ("EINVAL"); break;
        case 12: printf ("ENOMEM"); break;
    }
    printf_tagged_message(htonl((('L') << 24) | (('O') << 16) | (('G') << 8) | ('S')), "\n poll returned with errno=%d %s", err, msg);
}

variable_types: err int

variable_types:
msg
char *


decompiled_code:
void start_main_loop()
{
run_fc = 1;
}

canonical_decompiled_code:
void func0()
{
run_fc = 1;
}

original_code:
static void start_main_loop() {
 run_fc = 1;
}


decompiled_code:
int __fastcall debug_fd(const char *a1, unsigned int a2, unsigned int *a3)
{
__int16 v4; // bx

printf(
"%s fd[%d]: fd=%d events=%X revents=%X",
a1,
a2,
*a3,
(unsigned int)*((__int16 *)a3 + 2),
(unsigned int)*((__int16 *)a3 + 3));
v4 = *((_WORD *)a3 + 3);
if ( (v4 & 8) == 0 )
{
if ( (v4 & 0x10) == 0 )
goto LABEL_3;
LABEL_6:
printf("\nPOLLHUP - Hang up");
if ( (v4 & 0x20) == 0 )
return fflush(stdout);
goto LABEL_7;
}
printf("\nPOLLERR - Error condition");
if ( (v4 & 0x10) != 0 )
goto LABEL_6;
LABEL_3:
if ( (v4 & 0x20) == 0 )
return fflush(stdout);
LABEL_7:
printf("\nPOLLNVAL - Invalid request: fd not open");
return fflush(stdout);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1, unsigned int a2, unsigned int *a3)
{
__int16 v4; // bx

printf(
"%s fd[%d]: fd=%d events=%X revents=%X",
a1,
a2,
*a3,
(unsigned int)*((__int16 *)a3 + 2),
(unsigned int)*((__int16 *)a3 + 3));
v4 = *((_WORD *)a3 + 3);
if ( (v4 & 8) == 0 )
{
if ( (v4 & 0x10) == 0 )
goto LABEL_3;
LABEL_6:
printf("\nPOLLHUP - Hang up");
if ( (v4 & 0x20) == 0 )
return fflush(stdout);
goto LABEL_7;
}
printf("\nPOLLERR - Error condition");
if ( (v4 & 0x10) != 0 )
goto LABEL_6;
LABEL_3:
if ( (v4 & 0x20) == 0 )
return fflush(stdout);
LABEL_7:
printf("\nPOLLNVAL - Invalid request: fd not open");
return fflush(stdout);
}

original_code:
static void debug_fd (const char *msg, int i, struct pollfd *pfd) {
 printf("%s fd[%d]: fd=%d events=%X revents=%X", msg, i, pfd->fd, pfd->events, pfd->revents);
 int re = pfd->revents;
 if (re & 0x008) printf("\nPOLLERR - Error condition");
 if (re & 0x010) printf("\nPOLLHUP - Hang up");
 if (re & 0x020) printf("\nPOLLNVAL - Invalid request: fd not open");
 fflush (stdout);
}

canonical_original_code:
static void debug_fd(char *msg, int i, struct pollfd *pfd) {
 printf("%s fd[%d]: fd=%d events=%X revents=%X", msg, i, pfd->fd, pfd->events, pfd->revents);
 int re = pfd->revents;
 if (re & 0x008) printf("\nPOLLERR - Error condition");
 if (re & 0x010) printf("\nPOLLHUP - Hang up");
 if (re & 0x020) printf("\nPOLLNVAL - Invalid request: fd not open");
 fflush (stdout);
}

variable_types: i int

variable_types: re int


decompiled_code:
__int64 __fastcall fcf_addfd(int a1, __int16 a2, __int64 a3)
{
__int64 result; // rax

result = (unsigned int)nfds;
if ( nfds > 99 )
return 0xFFFFFFFFLL;
++nfds;
*(&fds.fd + 2 * (unsigned int)result) = a1;
*(&fds.events + 4 * (unsigned int)result) = a2;
callbacks[(unsigned int)result] = a3;
cbCat[(unsigned int)result] = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, __int16 a2, __int64 a3)
{
__int64 result; // rax

result = (unsigned int)nfds;
if ( nfds > 99 )
return 0xFFFFFFFFLL;
++nfds;
*(&fds.fd + 2 * (unsigned int)result) = a1;
*(&fds.events + 4 * (unsigned int)result) = a2;
callbacks[(unsigned int)result] = a3;
cbCat[(unsigned int)result] = 0;
return result;
}

original_code:
int fcf_addfd (int fd, short events, pollCallback cb) {
 if (nfds >= 100) {
  return -1;
 }
 unsigned int i = nfds++;
 fds[i].fd = fd;
 fds[i].events = events;
 callbacks[i] = cb;
 cbCat[i] = standard;
 return i;
}

canonical_original_code:
int fcf_addfd(int fd, short events, int (*cb)(struct pollfd *pfd)) {
 if (nfds >= 100) {
  return -1;
 }
 unsigned int i = nfds++;
 fds[i].fd = fd;
 fds[i].events = events;
 callbacks[i] = cb;
 cbCat[i] = standard;
 return i;
}

variable_types: events short

variable_types:
i
unsigned int


decompiled_code:
__int64 __fastcall fcf_addfd_ppc(int a1, __int16 a2, __int64 a3)
{
__int64 result; // rax

result = fcf_addfd(a1, a2, a3);
if ( (int)result >= 0 )
cbCat[(int)result] = 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, __int16 a2, __int64 a3)
{
__int64 result; // rax

result = func2(a1, a2, a3);
if ( (int)result >= 0 )
cbCat[(int)result] = 1;
return result;
}

original_code:
int fcf_addfd_ppc (int fd, short events, pollCallback cb)
{
 int i = fcf_addfd (fd, events, cb);
 if (i >= 0) {
  cbCat[i] = ppc;
 }
 return i;
}

canonical_original_code:
int fcf_addfd_ppc(int fd, short events, int (*cb)(struct pollfd *pfd))
{
 int i = fcf_addfd (fd, events, cb);
 if (i >= 0) {
  cbCat[i] = ppc;
 }
 return i;
}


decompiled_code:
__int64 __fastcall fcf_removefd(int a1)
{
__int64 v1; // rax
__int64 v2; // rdx
int v3; // esi
__int64 result; // rax

if ( nfds <= 0 )
return 0xFFFFFFFFLL;
v1 = 0LL;
while ( 1 )
{
v2 = (int)v1;
if ( *(&fds.fd + 2 * v1) == a1 )
break;
if ( ++v1 == nfds )
return 0xFFFFFFFFLL;
}
v3 = nfds - 1;
result = 0LL;
nfds = v3;
if ( (int)v2 < v3 )
{
*(&fds + v2) = *(&fds + v3);
callbacks[v2] = callbacks[v3];
cbCat[v2] = cbCat[v3];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
__int64 v1; // rax
__int64 v2; // rdx
int v3; // esi
__int64 result; // rax

if ( nfds <= 0 )
return 0xFFFFFFFFLL;
v1 = 0LL;
while ( 1 )
{
v2 = (int)v1;
if ( *(&fds.fd + 2 * v1) == a1 )
break;
if ( ++v1 == nfds )
return 0xFFFFFFFFLL;
}
v3 = nfds - 1;
result = 0LL;
nfds = v3;
if ( (int)v2 < v3 )
{
*(&fds + v2) = *(&fds + v3);
callbacks[v2] = callbacks[v3];
cbCat[v2] = cbCat[v3];
}
return result;
}

original_code:
int fcf_removefd (int fd) {
 for (int i = 0; i < nfds; i++) {
  if (fds[i].fd == fd) {
   nfds--;
   if (i < nfds) {
    fds[i] = fds[nfds];
    callbacks[i] = callbacks[nfds];
    cbCat[i] = cbCat[nfds];
   }
   return 0;
  }
 }
 return -1;
}

canonical_original_code:
int fcf_removefd(int fd) {
 for (int i = 0; i < nfds; i++) {
  if (fds[i].fd == fd) {
   nfds--;
   if (i < nfds) {
    fds[i] = fds[nfds];
    callbacks[i] = callbacks[nfds];
    cbCat[i] = cbCat[nfds];
   }
   return 0;
  }
 }
 return -1;
}


decompiled_code:
void stop_main_loop()
{
run_fc = 0;
}

canonical_decompiled_code:
void func5()
{
run_fc = 0;
}

original_code:
void stop_main_loop() {
 run_fc = 0;
}

canonical_original_code:
void stop_main_loop() {
 run_fc = 0;
}


decompiled_code:
__int64 run_main_loop()
{
unsigned int v0; // er14
unsigned int *v1; // r12
struct pollfd *v2; // rbp
int i; // ebx
unsigned int v4; // esi
__int64 v5; // rbp
struct pollfd *v6; // r14
int v7; // ebx
unsigned int v8; // esi
__int64 v9; // rbx
int v10; // er13
__int64 v11; // r14
__int64 v12; // rbx
__int64 v14; // rdx
int v15; // er9
__int64 v16; // rax
int v17; // edi
__int64 v18; // r14
unsigned int v19; // [rsp+4h] [rbp-364h]
__int64 v20[108]; // [rsp+8h] [rbp-360h]

start_main_loop();
HIDWORD(v20[0]) = run_fc;
if ( run_fc )
{
HIDWORD(v20[0]) = 0;
v0 = 0;
v1 = (unsigned int *)_errno_location();
while ( 1 )
{
v2 = &fds;
for ( i = 0; nfds > i; ++v2 )
{
v4 = i++;
debug_fd("\nbefore poll<<< ", v4, (unsigned int *)v2);
}
printf("\nwaiting");
fflush(stdout);
*v1 = 0;
v5 = (unsigned int)poll(&fds, nfds, -1);
v19 = v0 + 1;
printf("\n%d. poll returned with rc=%d errno=%d", v0, v5, *v1);
if ( nfds <= 0 )
{
if ( (_DWORD)v5 != -1 )
{
if ( (_DWORD)v5 )
goto LABEL_21;
LABEL_25:
printf("poll timed out");
if ( !run_fc )
break;
goto LABEL_22;
}
}
else
{
v6 = &fds;
v7 = 0;
do
{
v8 = v7++;
debug_fd("\n after poll>>> ", v8, (unsigned int *)v6++);
}
while ( nfds > v7 );
if ( (_DWORD)v5 != -1 )
{
if ( (_DWORD)v5 )
{
if ( nfds <= 0 || (int)v5 <= 0 )
goto LABEL_21;
LODWORD(v20[0]) = 0;
v9 = 0LL;
while ( 2 )
{
v10 = v9;
if ( *(&fds.revents + 4 * v9) )
{
LODWORD(v5) = v5 - 1;
debug_fd("\n active fd ", v9, (unsigned int *)&fds + 2 * v9);
if ( !cbCat[v9] )
{
((void (__fastcall *)(struct pollfd *))callbacks[v9])(&fds + v9);
++v9;
if ( v10 + 1 >= nfds )
{
LABEL_18:
if ( LODWORD(v20[0]) )
{
v11 = SLODWORD(v20[0]);
v12 = 0LL;
do
{
printf("\n calling ppc callback [%d]", (unsigned int)v12);
((void (__fastcall *)(struct pollfd *))v20[++v12])(&fds);
}
while ( v11 != v12 );
}
goto LABEL_21;
}
goto LABEL_14;
}
v14 = callbacks[v9];
v15 = 1;
if ( LODWORD(v20[0]) )
{
v16 = 1LL;
v15 = LODWORD(v20[0]) + 1;
do
{
if ( v20[v16] == v14 )
goto LABEL_33;
v17 = v16++;
}
while ( v16 != LODWORD(v20[0]) + 1 );
if ( v17 != LODWORD(v20[0]) )
{
LABEL_33:
printf(
"\n multiple active ppc, ignoring callback for fd[%d]: fd=%d",
(unsigned int)v9,
*((unsigned int *)&fds.fd + 2 * v9));
goto LABEL_13;
}
}
v18 = SLODWORD(v20[0]);
LODWORD(v20[0]) = v15;
v20[v18 + 1] = v14;
}
LABEL_13:
++v9;
if ( v10 + 1 >= nfds )
goto LABEL_18;
LABEL_14:
if ( (int)v5 <= 0 )
goto LABEL_18;
continue;
}
}
goto LABEL_25;
}
}
if ( *v1 != 4 )
{
perror("run_main_loop: poll returned with error");
stop_main_loop();
HIDWORD(v20[0]) = -1;
}
LABEL_21:
if ( !run_fc )
break;
LABEL_22:
v0 = v19;
}
}
printf("\n exiting main loop");
return HIDWORD(v20[0]);
}

canonical_decompiled_code:
__int64 func6()
{
unsigned int v0; // er14
unsigned int *v1; // r12
struct pollfd *v2; // rbp
int i; // ebx
unsigned int v4; // esi
__int64 v5; // rbp
struct pollfd *v6; // r14
int v7; // ebx
unsigned int v8; // esi
__int64 v9; // rbx
int v10; // er13
__int64 v11; // r14
__int64 v12; // rbx
__int64 v14; // rdx
int v15; // er9
__int64 v16; // rax
int v17; // edi
__int64 v18; // r14
unsigned int v19; // [rsp+4h] [rbp-364h]
__int64 v20[108]; // [rsp+8h] [rbp-360h]

func0();
HIDWORD(v20[0]) = run_fc;
if ( run_fc )
{
HIDWORD(v20[0]) = 0;
v0 = 0;
v1 = (unsigned int *)_errno_location();
while ( 1 )
{
v2 = &fds;
for ( i = 0; nfds > i; ++v2 )
{
v4 = i++;
func1("\nbefore poll<<< ", v4, (unsigned int *)v2);
}
printf("\nwaiting");
fflush(stdout);
*v1 = 0;
v5 = (unsigned int)poll(&fds, nfds, -1);
v19 = v0 + 1;
printf("\n%d. poll returned with rc=%d errno=%d", v0, v5, *v1);
if ( nfds <= 0 )
{
if ( (_DWORD)v5 != -1 )
{
if ( (_DWORD)v5 )
goto LABEL_21;
LABEL_25:
printf("poll timed out");
if ( !run_fc )
break;
goto LABEL_22;
}
}
else
{
v6 = &fds;
v7 = 0;
do
{
v8 = v7++;
func1("\n after poll>>> ", v8, (unsigned int *)v6++);
}
while ( nfds > v7 );
if ( (_DWORD)v5 != -1 )
{
if ( (_DWORD)v5 )
{
if ( nfds <= 0 || (int)v5 <= 0 )
goto LABEL_21;
LODWORD(v20[0]) = 0;
v9 = 0LL;
while ( 2 )
{
v10 = v9;
if ( *(&fds.revents + 4 * v9) )
{
LODWORD(v5) = v5 - 1;
func1("\n active fd ", v9, (unsigned int *)&fds + 2 * v9);
if ( !cbCat[v9] )
{
((void (__fastcall *)(struct pollfd *))callbacks[v9])(&fds + v9);
++v9;
if ( v10 + 1 >= nfds )
{
LABEL_18:
if ( LODWORD(v20[0]) )
{
v11 = SLODWORD(v20[0]);
v12 = 0LL;
do
{
printf("\n calling ppc callback [%d]", (unsigned int)v12);
((void (__fastcall *)(struct pollfd *))v20[++v12])(&fds);
}
while ( v11 != v12 );
}
goto LABEL_21;
}
goto LABEL_14;
}
v14 = callbacks[v9];
v15 = 1;
if ( LODWORD(v20[0]) )
{
v16 = 1LL;
v15 = LODWORD(v20[0]) + 1;
do
{
if ( v20[v16] == v14 )
goto LABEL_33;
v17 = v16++;
}
while ( v16 != LODWORD(v20[0]) + 1 );
if ( v17 != LODWORD(v20[0]) )
{
LABEL_33:
printf(
"\n multiple active ppc, ignoring callback for fd[%d]: fd=%d",
(unsigned int)v9,
*((unsigned int *)&fds.fd + 2 * v9));
goto LABEL_13;
}
}
v18 = SLODWORD(v20[0]);
LODWORD(v20[0]) = v15;
v20[v18 + 1] = v14;
}
LABEL_13:
++v9;
if ( v10 + 1 >= nfds )
goto LABEL_18;
LABEL_14:
if ( (int)v5 <= 0 )
goto LABEL_18;
continue;
}
}
goto LABEL_25;
}
}
if ( *v1 != 4 )
{
perror("run_main_loop: poll returned with error");
func5();
HIDWORD(v20[0]) = -1;
}
LABEL_21:
if ( !run_fc )
break;
LABEL_22:
v0 = v19;
}
}
printf("\n exiting main loop");
return HIDWORD(v20[0]);
}

original_code:
int run_main_loop() {
 pollCallback ppc[100];
 int nppc= 0;
 int count = 0;
 int ret = 0;
 start_main_loop();
 while (run_fc) {
  for (int i = 0; i < nfds; i++) {
   debug_fd("\nbefore poll<<< ", i, &fds[i]);
  }
  printf("\nwaiting");
  fflush (stdout);
  (*__errno_location ()) = 0;
  int rc = poll(fds, nfds, -1);
  printf ("\n%d. poll returned with rc=%d errno=%d", count++, rc, (*__errno_location ()));
  for (int i = 0; i < nfds; i++) {
   debug_fd("\n   after poll>>> ", i, &fds[i]);
  }
  switch (rc) {
  case -1:
   if ((*__errno_location ()) != 4) {
    perror ("run_main_loop: poll returned with error");
    ret = -1;
    stop_main_loop();
   }
   break;
  case 0:
   printf("poll timed out");
   break;
  default:
   nppc = 0;
   for (int i = 0; i < nfds && rc > 0; i++) {
    if(fds[i].revents != 0) {
     debug_fd("\n active fd ", i, &fds[i]);
     rc--;
     if (cbCat[i] == standard) {
      callbacks[i](&fds[i]);
     } else {
      int j;
      for (j = 0; j < nppc && ppc[j] != callbacks[i]; j++)
      { }
      if (j == nppc) {
       ppc[nppc++] = callbacks[i];
      } else {
       printf ("\n multiple active ppc, ignoring callback for fd[%d]: fd=%d", i, fds[i].fd);
      }
     }
    }
   }
   for (int j = 0; j < nppc; j++) {
    printf ("\n calling ppc callback [%d]", j);
    ppc[j](fds);
   }
   break;
  }
 }
 printf("\n exiting main loop");
 return ret;
}

canonical_original_code:
int run_main_loop() {
 int (*ppc[100])(struct pollfd *pfd);
 int nppc = 0;
 int count = 0;
 int ret = 0;
 start_main_loop();
 while (run_fc) {
  for (int i = 0; i < nfds; i++) {
   debug_fd("\nbefore poll<<< ", i, &fds[i]);
  }
  printf("\nwaiting");
  fflush (stdout);
  (*__errno_location ()) = 0;
  int rc = poll(fds, nfds, -1);
  printf ("\n%d. poll returned with rc=%d errno=%d", count++, rc, (*__errno_location ()));
  for (int i = 0; i < nfds; i++) {
   debug_fd("\n   after poll>>> ", i, &fds[i]);
  }
  switch (rc) {
  case -1:
   if ((*__errno_location ()) != 4) {
    perror ("run_main_loop: poll returned with error");
    ret = -1;
    stop_main_loop();
   }
   break;
  case 0:
   printf("poll timed out");
   break;
  default:
   nppc = 0;
   for (int i = 0; i < nfds && rc > 0; i++) {
    if(fds[i].revents != 0) {
     debug_fd("\n active fd ", i, &fds[i]);
     rc--;
     if (cbCat[i] == standard) {
      callbacks[i](&fds[i]);
     } else {
      int j;
      for (j = 0; j < nppc && ppc[j] != callbacks[i]; j++)
      { }
      if (j == nppc) {
       ppc[nppc++] = callbacks[i];
      } else {
       printf ("\n multiple active ppc, ignoring callback for fd[%d]: fd=%d", i, fds[i].fd);
      }
     }
    }
   }
   for (int j = 0; j < nppc; j++) {
    printf ("\n calling ppc callback [%d]", j);
    ppc[j](fds);
   }
   break;
  }
 }
 printf("\n exiting main loop");
 return ret;
}

variable_types: int (*[100])(struct pollfd { int fd; short events; short revents; } *pfd)

variable_types: nppc int

variable_types: count int

variable_types: ret int

variable_types: j int


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

switch ( a1 )
{
case 0xFFFFFF9D:
result = fprintf(stderr, "**%s: ERROR_OTHER\n", a2);
break;
case 0xFFFFFFF4:
result = fprintf(stderr, "**%s: ERROR_NOT_SUPPORTED\n", a2);
break;
case 0xFFFFFFF5:
result = fprintf(stderr, "**%s: ERROR_NO_MEM\n", a2);
break;
case 0xFFFFFFF6:
result = fprintf(stderr, "**%s: ERROR_INTERRUPTED\n", a2);
break;
case 0xFFFFFFF7:
result = fprintf(stderr, "**%s: ERROR_PIPE\n", a2);
break;
case 0xFFFFFFF8:
result = fprintf(stderr, "**%s: ERROR_OVERFLOW\n", a2);
break;
case 0xFFFFFFF9:
result = fprintf(stderr, "**%s: ERROR_TIMEOUT\n", a2);
break;
case 0xFFFFFFFA:
result = fprintf(stderr, "**%s: ERROR_BUSY\n", a2);
break;
case 0xFFFFFFFB:
result = fprintf(stderr, "**%s: ERROR_NOT_FOUND\n", a2);
break;
case 0xFFFFFFFC:
result = fprintf(stderr, "**%s: ERROR_NO_DEVICE\n", a2);
break;
case 0xFFFFFFFD:
result = fprintf(stderr, "**%s: ERROR_ACCESS\n", a2);
break;
case 0xFFFFFFFE:
result = fprintf(stderr, "**%s: ERROR_INVALID_PARAM\n", a2);
break;
case 0xFFFFFFFF:
result = fprintf(stderr, "**%s: ERROR_IO\n", a2);
break;
case 0u:
result = fprintf(stderr, "**%s: SUCCESS\n", a2);
break;
default:
result = fprintf(stderr, "***%s: unknown error %i ***\n", a2, a1);
break;
}
return result;
}

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

switch ( a1 )
{
case 0xFFFFFF9D:
result = fprintf(stderr, "**%s: ERROR_OTHER\n", a2);
break;
case 0xFFFFFFF4:
result = fprintf(stderr, "**%s: ERROR_NOT_SUPPORTED\n", a2);
break;
case 0xFFFFFFF5:
result = fprintf(stderr, "**%s: ERROR_NO_MEM\n", a2);
break;
case 0xFFFFFFF6:
result = fprintf(stderr, "**%s: ERROR_INTERRUPTED\n", a2);
break;
case 0xFFFFFFF7:
result = fprintf(stderr, "**%s: ERROR_PIPE\n", a2);
break;
case 0xFFFFFFF8:
result = fprintf(stderr, "**%s: ERROR_OVERFLOW\n", a2);
break;
case 0xFFFFFFF9:
result = fprintf(stderr, "**%s: ERROR_TIMEOUT\n", a2);
break;
case 0xFFFFFFFA:
result = fprintf(stderr, "**%s: ERROR_BUSY\n", a2);
break;
case 0xFFFFFFFB:
result = fprintf(stderr, "**%s: ERROR_NOT_FOUND\n", a2);
break;
case 0xFFFFFFFC:
result = fprintf(stderr, "**%s: ERROR_NO_DEVICE\n", a2);
break;
case 0xFFFFFFFD:
result = fprintf(stderr, "**%s: ERROR_ACCESS\n", a2);
break;
case 0xFFFFFFFE:
result = fprintf(stderr, "**%s: ERROR_INVALID_PARAM\n", a2);
break;
case 0xFFFFFFFF:
result = fprintf(stderr, "**%s: ERROR_IO\n", a2);
break;
case 0u:
result = fprintf(stderr, "**%s: SUCCESS\n", a2);
break;
default:
result = fprintf(stderr, "***%s: unknown error %i ***\n", a2, a1);
break;
}
return result;
}

original_code:
void print_libusb_error(int libusberrno, const char* str) {
 switch(libusberrno) {
 case LIBUSB_SUCCESS:
  fprintf(stderr, "**%s: SUCCESS\n",str);
  break;
 case LIBUSB_ERROR_IO:
  fprintf(stderr, "**%s: ERROR_IO\n",str);
  break;
 case LIBUSB_ERROR_INVALID_PARAM:
  fprintf(stderr, "**%s: ERROR_INVALID_PARAM\n",str);
  break;
 case LIBUSB_ERROR_ACCESS:
  fprintf(stderr, "**%s: ERROR_ACCESS\n",str);
  break;
 case LIBUSB_ERROR_NO_DEVICE:
  fprintf(stderr, "**%s: ERROR_NO_DEVICE\n",str);
  break;
 case LIBUSB_ERROR_NOT_FOUND:
  fprintf(stderr, "**%s: ERROR_NOT_FOUND\n",str);
  break;
 case LIBUSB_ERROR_BUSY:
    fprintf(stderr, "**%s: ERROR_BUSY\n",str);
    break;
 case LIBUSB_ERROR_TIMEOUT:
  fprintf(stderr, "**%s: ERROR_TIMEOUT\n",str);
  break;
 case LIBUSB_ERROR_OVERFLOW:
  fprintf(stderr, "**%s: ERROR_OVERFLOW\n",str);
  break;
 case LIBUSB_ERROR_PIPE:
  fprintf(stderr, "**%s: ERROR_PIPE\n",str);
  break;
 case LIBUSB_ERROR_INTERRUPTED:
  fprintf(stderr, "**%s: ERROR_INTERRUPTED\n",str);
  break;
 case LIBUSB_ERROR_NO_MEM:
  fprintf(stderr, "**%s: ERROR_NO_MEM\n",str);
  break;
 case LIBUSB_ERROR_NOT_SUPPORTED:
  fprintf(stderr, "**%s: ERROR_NOT_SUPPORTED\n",str);
  break;
 case LIBUSB_ERROR_OTHER:
  fprintf(stderr, "**%s: ERROR_OTHER\n",str);
  break;
 default:
  fprintf(stderr, "***%s:  unknown error %i ***\n", str, libusberrno);
  break;
 }
}

canonical_original_code:
void print_libusb_error(int libusberrno, char *str) {
 switch(libusberrno) {
 case LIBUSB_SUCCESS:
  fprintf(stderr, "**%s: SUCCESS\n",str);
  break;
 case LIBUSB_ERROR_IO:
  fprintf(stderr, "**%s: ERROR_IO\n",str);
  break;
 case LIBUSB_ERROR_INVALID_PARAM:
  fprintf(stderr, "**%s: ERROR_INVALID_PARAM\n",str);
  break;
 case LIBUSB_ERROR_ACCESS:
  fprintf(stderr, "**%s: ERROR_ACCESS\n",str);
  break;
 case LIBUSB_ERROR_NO_DEVICE:
  fprintf(stderr, "**%s: ERROR_NO_DEVICE\n",str);
  break;
 case LIBUSB_ERROR_NOT_FOUND:
  fprintf(stderr, "**%s: ERROR_NOT_FOUND\n",str);
  break;
 case LIBUSB_ERROR_BUSY:
    fprintf(stderr, "**%s: ERROR_BUSY\n",str);
    break;
 case LIBUSB_ERROR_TIMEOUT:
  fprintf(stderr, "**%s: ERROR_TIMEOUT\n",str);
  break;
 case LIBUSB_ERROR_OVERFLOW:
  fprintf(stderr, "**%s: ERROR_OVERFLOW\n",str);
  break;
 case LIBUSB_ERROR_PIPE:
  fprintf(stderr, "**%s: ERROR_PIPE\n",str);
  break;
 case LIBUSB_ERROR_INTERRUPTED:
  fprintf(stderr, "**%s: ERROR_INTERRUPTED\n",str);
  break;
 case LIBUSB_ERROR_NO_MEM:
  fprintf(stderr, "**%s: ERROR_NO_MEM\n",str);
  break;
 case LIBUSB_ERROR_NOT_SUPPORTED:
  fprintf(stderr, "**%s: ERROR_NOT_SUPPORTED\n",str);
  break;
 case LIBUSB_ERROR_OTHER:
  fprintf(stderr, "**%s: ERROR_OTHER\n",str);
  break;
 default:
  fprintf(stderr, "***%s:  unknown error %i ***\n", str, libusberrno);
  break;
 }
}

variable_types: libusberrno int

variable_types:
str
char *


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

switch ( a1 )
{
case 0u:
result = fprintf(stderr, "**%s: LIBUSB_TRANSFER_COMPLETED\n", a2);
break;
case 1u:
result = fprintf(stderr, "**%s: LIBUSB_TRANSFER_ERROR\n", a2);
break;
case 2u:
result = fprintf(stderr, "**%s: LIBUSB_TRANSFER_TIMED_OUT\n", a2);
break;
case 3u:
result = fprintf(stderr, "**%s: LIBUSB_TRANSFER_CANCELLED\n", a2);
break;
case 4u:
result = fprintf(stderr, "**%s: LIBUSB_TRANSFER_STALL\n", a2);
break;
case 5u:
result = fprintf(stderr, "**%s: LIBUSB_TRANSFER_NO_DEVICE\n", a2);
break;
case 6u:
result = fprintf(stderr, "**%s: LIBUSB_TRANSFER_OVERFLOW\n", a2);
break;
default:
result = fprintf(stderr, "***%s: Unknown transfer status %i***\n", a2, a1);
break;
}
return result;
}

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

switch ( a1 )
{
case 0u:
result = fprintf(stderr, "**%s: LIBUSB_TRANSFER_COMPLETED\n", a2);
break;
case 1u:
result = fprintf(stderr, "**%s: LIBUSB_TRANSFER_ERROR\n", a2);
break;
case 2u:
result = fprintf(stderr, "**%s: LIBUSB_TRANSFER_TIMED_OUT\n", a2);
break;
case 3u:
result = fprintf(stderr, "**%s: LIBUSB_TRANSFER_CANCELLED\n", a2);
break;
case 4u:
result = fprintf(stderr, "**%s: LIBUSB_TRANSFER_STALL\n", a2);
break;
case 5u:
result = fprintf(stderr, "**%s: LIBUSB_TRANSFER_NO_DEVICE\n", a2);
break;
case 6u:
result = fprintf(stderr, "**%s: LIBUSB_TRANSFER_OVERFLOW\n", a2);
break;
default:
result = fprintf(stderr, "***%s: Unknown transfer status %i***\n", a2, a1);
break;
}
return result;
}

original_code:
void print_libusb_transfer_error(int status, const char* str){
 switch(status){
 case LIBUSB_TRANSFER_COMPLETED:
  fprintf(stderr, "**%s: LIBUSB_TRANSFER_COMPLETED\n", str);
  break;
 case LIBUSB_TRANSFER_ERROR:
  fprintf(stderr, "**%s: LIBUSB_TRANSFER_ERROR\n", str);
  break;
 case LIBUSB_TRANSFER_TIMED_OUT:
  fprintf(stderr, "**%s: LIBUSB_TRANSFER_TIMED_OUT\n", str);
  break;
 case LIBUSB_TRANSFER_CANCELLED:
  fprintf(stderr, "**%s: LIBUSB_TRANSFER_CANCELLED\n", str);
  break;
 case LIBUSB_TRANSFER_STALL:
  fprintf(stderr, "**%s: LIBUSB_TRANSFER_STALL\n", str);
  break;
 case LIBUSB_TRANSFER_NO_DEVICE:
  fprintf(stderr, "**%s: LIBUSB_TRANSFER_NO_DEVICE\n", str);
  break;
 case LIBUSB_TRANSFER_OVERFLOW:
  fprintf(stderr, "**%s: LIBUSB_TRANSFER_OVERFLOW\n", str);
  break;
 default:
  fprintf(stderr, "***%s: Unknown transfer status %i***\n", str, status);
  break;
 }
}

canonical_original_code:
void print_libusb_transfer_error(int status, char *str){
 switch(status){
 case LIBUSB_TRANSFER_COMPLETED:
  fprintf(stderr, "**%s: LIBUSB_TRANSFER_COMPLETED\n", str);
  break;
 case LIBUSB_TRANSFER_ERROR:
  fprintf(stderr, "**%s: LIBUSB_TRANSFER_ERROR\n", str);
  break;
 case LIBUSB_TRANSFER_TIMED_OUT:
  fprintf(stderr, "**%s: LIBUSB_TRANSFER_TIMED_OUT\n", str);
  break;
 case LIBUSB_TRANSFER_CANCELLED:
  fprintf(stderr, "**%s: LIBUSB_TRANSFER_CANCELLED\n", str);
  break;
 case LIBUSB_TRANSFER_STALL:
  fprintf(stderr, "**%s: LIBUSB_TRANSFER_STALL\n", str);
  break;
 case LIBUSB_TRANSFER_NO_DEVICE:
  fprintf(stderr, "**%s: LIBUSB_TRANSFER_NO_DEVICE\n", str);
  break;
 case LIBUSB_TRANSFER_OVERFLOW:
  fprintf(stderr, "**%s: LIBUSB_TRANSFER_OVERFLOW\n", str);
  break;
 default:
  fprintf(stderr, "***%s: Unknown transfer status %i***\n", str, status);
  break;
 }
}

variable_types: status int


decompiled_code:
__int64 libusb_cb()
{
libusb_handle_events_timeout(gcontext, &nonblocking);
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
libusb_handle_events_timeout(gcontext, &nonblocking);
return 0LL;
}

original_code:
static int libusb_cb(struct pollfd *pfd) {
 libusb_handle_events_timeout(gcontext, &nonblocking);
 return 0;
}

variable_types: struct pollfd { int fd; short events; short revents; } *


decompiled_code:
__int64 __fastcall usb_fd_added_cb(__int64 a1, __int16 a2)
{
unsigned int v2; // eax

v2 = _bswap_32_constprop_0(a1, "\n usb_fd_added_cb");
printf_tagged_message(v2);
flush_buffers();
return fcf_addfd_ppc((unsigned int)a1, (unsigned int)a2, libusb_cb);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int16 a2)
{
unsigned int v2; // eax

v2 = func1(a1, "\n usb_fd_added_cb");
printf_tagged_message(v2);
flush_buffers();
return fcf_addfd_ppc((unsigned int)a1, (unsigned int)a2, libusb_cb);
}

original_code:
static void usb_fd_added_cb(int fd, short events, void * source){
 printf_tagged_message(htonl((('L') << 24) | (('O') << 16) | (('G') << 8) | ('S')), "\n usb_fd_added_cb");
 flush_buffers();
 fcf_addfd_ppc (fd, events, libusb_cb);
}

canonical_original_code:
static void usb_fd_added_cb(int fd, short events, void *source){
 printf_tagged_message(htonl((('L') << 24) | (('O') << 16) | (('G') << 8) | ('S')), "\n usb_fd_added_cb");
 flush_buffers();
 fcf_addfd_ppc (fd, events, libusb_cb);
}

variable_types: fd int

variable_types:
source
void *


decompiled_code:
__int64 __fastcall usb_fd_removed_cb(__int64 a1)
{
unsigned int v1; // ebp
__int64 v2; // rdi

v1 = a1;
v2 = (unsigned int)_bswap_32_constprop_0(a1, "\n usb_fd_removed_cb");
printf_tagged_message(v2);
flush_buffers();
return fcf_removefd(v1);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
unsigned int v1; // ebp
__int64 v2; // rdi

v1 = a1;
v2 = (unsigned int)func1(a1, "\n usb_fd_removed_cb");
printf_tagged_message(v2);
flush_buffers();
return fcf_removefd(v1);
}

original_code:
static void usb_fd_removed_cb(int fd, void* source){
 printf_tagged_message(htonl((('L') << 24) | (('O') << 16) | (('G') << 8) | ('S')), "\n usb_fd_removed_cb");
 flush_buffers();
 fcf_removefd (fd);
}

canonical_original_code:
static void usb_fd_removed_cb(int fd, void *source){
 printf_tagged_message(htonl((('L') << 24) | (('O') << 16) | (('G') << 8) | ('S')), "\n usb_fd_removed_cb");
 flush_buffers();
 fcf_removefd (fd);
}


decompiled_code:
__syscall_slong_t get_timestamp()
{
struct timespec v1; // [rsp+0h] [rbp-18h] BYREF

clock_gettime(1, &v1);
return v1.tv_nsec + 1000000000 * (v1.tv_sec - starttime.tv_sec) - starttime.tv_nsec;
}

canonical_decompiled_code:
__syscall_slong_t func0()
{
struct timespec v1; // [rsp+0h] [rbp-18h] BYREF

clock_gettime(1, &v1);
return v1.tv_nsec + 1000000000 * (v1.tv_sec - starttime.tv_sec) - starttime.tv_nsec;
}

original_code:
static uint64_t get_timestamp(void)
{
 struct timespec now;
 clock_gettime(1, &now);
 now.tv_sec -= starttime.tv_sec;
 now.tv_nsec -= starttime.tv_nsec;
 return now.tv_nsec + (uint64_t) now.tv_sec * 1000000000;
}

canonical_original_code:
static unsigned long get_timestamp()
{
 struct timespec now;
 clock_gettime(1, &now);
 now.tv_sec -= starttime.tv_sec;
 now.tv_nsec -= starttime.tv_nsec;
 return now.tv_nsec + (unsigned long) now.tv_sec * 1000000000;
}

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

return_type: unsigned long


decompiled_code:
FILE *open_logfile()
{
unsigned int v0; // ebx
char *v1; // rbp
int v2; // edi
int v3; // eax
FILE *result; // rax
char *v5; // rax

v0 = 0;
mkdir("logs", 0x1FFu);
v1 = (char *)malloc(9uLL);
while ( 1 )
{
snprintf(v1, 9uLL, "%s/%03d", "logs", v0);
v3 = open(v1, 193, 292LL);
if ( v3 != -1 )
break;
v2 = *_errno_location();
if ( (v2 & 0xFFFFFFFB) != 17 )
{
v5 = strerror(v2);
printf("permanent failure creating logfile %s: %s\n", v1, v5);
exit(1);
}
if ( ++v0 == 1000 )
{
printf("tried %d filenames but couldn't create any logfile in %s\n", 1000LL, "logs");
exit(1);
}
}
result = fdopen(v3, "w");
logfile = result;
return result;
}

canonical_decompiled_code:
FILE *func1()
{
unsigned int v0; // ebx
char *v1; // rbp
int v2; // edi
int v3; // eax
FILE *result; // rax
char *v5; // rax

v0 = 0;
mkdir("logs", 0x1FFu);
v1 = (char *)malloc(9uLL);
while ( 1 )
{
snprintf(v1, 9uLL, "%s/%03d", "logs", v0);
v3 = open(v1, 193, 292LL);
if ( v3 != -1 )
break;
v2 = *_errno_location();
if ( (v2 & 0xFFFFFFFB) != 17 )
{
v5 = strerror(v2);
printf("permanent failure creating logfile %s: %s\n", v1, v5);
exit(1);
}
if ( ++v0 == 1000 )
{
printf("tried %d filenames but couldn't create any logfile in %s\n", 1000LL, "logs");
exit(1);
}
}
result = fdopen(v3, "w");
logfile = result;
return result;
}

original_code:
static void open_logfile(void)
{
 mkdir(logdir, 0777);
 const int attempt_count = 1e3;
 const int bufsize = strlen(logdir) + 3 + 2;
 char *buf = malloc(bufsize);
 int i;
 for(i = 0; i < attempt_count; ++i)
 {
  snprintf(buf, bufsize, "%s/%0" "3" "d", logdir, i);
  int fd = open(buf, 01 | 0100 | 0200, 0444);
  if(fd == -1)
  {
          if((*__errno_location ()) == 17 || (*__errno_location ()) == 21)
    continue;
   printf("permanent failure creating logfile %s: %s\n", buf, strerror((*__errno_location ())));
   exit(1);
  }
  logfile = fdopen(fd, "w");
  return;
 }
 printf("tried %d filenames but couldn't create any logfile in %s\n", i, logdir);
 exit(1);
}

canonical_original_code:
static void open_logfile()
{
 mkdir(logdir, 0777);
 int attempt_count = 1e3;
 int bufsize = strlen(logdir) + 3 + 2;
 char *buf = malloc(bufsize);
 int i;
 for(i = 0; i < attempt_count; ++i)
 {
  snprintf(buf, bufsize, "%s/%0" "3" "d", logdir, i);
  int fd = open(buf, 01 | 0100 | 0200, 0444);
  if(fd == -1)
  {
          if((*__errno_location ()) == 17 || (*__errno_location ()) == 21)
    continue;
   printf("permanent failure creating logfile %s: %s\n", buf, strerror((*__errno_location ())));
   exit(1);
  }
  logfile = fdopen(fd, "w");
  return;
 }
 printf("tried %d filenames but couldn't create any logfile in %s\n", i, logdir);
 exit(1);
}

variable_types: bufsize int

variable_types:
buf
char *


decompiled_code:
int open_socket()
{
socklen_t v0; // edx
int v1; // er8
struct sockaddr v3; // [rsp+0h] [rbp-18h] BYREF

*(_QWORD *)&v3.sa_data[6] = 0LL;
net_fd = socket(2, 2, 0);
v3.sa_family = 2;
*(_WORD *)v3.sa_data = _bswap_16(5005);
*(_DWORD *)&v3.sa_data[2] = _bswap_32(0x7F000001u);
return connect(v1, &v3, v0);
}

canonical_decompiled_code:
int func4()
{
socklen_t v0; // edx
int v1; // er8
struct sockaddr v3; // [rsp+0h] [rbp-18h] BYREF

*(_QWORD *)&v3.sa_data[6] = 0LL;
net_fd = socket(2, 2, 0);
v3.sa_family = 2;
*(_WORD *)v3.sa_data = func2(5005);
*(_DWORD *)&v3.sa_data[2] = func3(0x7F000001u);
return connect(v1, &v3, v0);
}

original_code:
static void open_socket(void)
{
 net_fd = socket(2, SOCK_DGRAM, 0);
 struct sockaddr_in remote = { 2 };
 remote.sin_port = htons(5005);
 if(loopback)
  remote.sin_addr.s_addr = htonl(((in_addr_t) 0x7f000001));
 connect(net_fd, (struct sockaddr *) &remote, sizeof(struct sockaddr));
}

canonical_original_code:
static void open_socket()
{
 net_fd = socket(2, SOCK_DGRAM, 0);
 struct sockaddr_in remote = { 2 };
 remote.sin_port = htons(5005);
 if(loopback)
  remote.sin_addr.s_addr = htonl(((unsigned int) 0x7f000001));
 connect(net_fd, (struct sockaddr *) &remote, sizeof(struct sockaddr));
}

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

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

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


decompiled_code:
void flush_buffers()
{
int v0; // eax

if ( pos != &unk_4A4 )
{
send(net_fd, &bucket, (_BYTE *)pos - (_BYTE *)&bucket, 0);
pos = &unk_4A4;
v0 = _bswap_32(bucket);
bucket = _bswap_32(v0 + 1);
fflush(logfile);
}
}

canonical_decompiled_code:
void func5()
{
int v0; // eax

if ( pos != &unk_4A4 )
{
send(net_fd, &bucket, (_BYTE *)pos - (_BYTE *)&bucket, 0);
pos = &unk_4A4;
v0 = func3(bucket);
bucket = func3(v0 + 1);
fflush(logfile);
}
}

original_code:
void flush_buffers(void)
{
 if(pos == bucket.buf)
  return;
 send(net_fd, &bucket, pos - (char *) &bucket, 0);
 pos = bucket.buf;
 bucket.seq = htonl(ntohl(bucket.seq) + 1);
 fflush(logfile);
}

canonical_original_code:
void flush_buffers()
{
 if(pos == bucket.buf)
  return;
 send(net_fd, &bucket, pos - (char *) &bucket, 0);
 pos = bucket.buf;
 bucket.seq = htonl(ntohl(bucket.seq) + 1);
 fflush(logfile);
}


decompiled_code:
size_t printf_tagged_message(int a1, const char *a2, ...)
{
unsigned __int16 v2; // ax
gcc_va_list arg; // [rsp+8h] [rbp-4D0h] BYREF
char s[1024]; // [rsp+20h] [rbp-4B8h] BYREF

va_start(arg, a2);
v2 = vsnprintf(s, 0x400uLL, a2, arg);
return write_tagged_message(a1, s, v2);
}

canonical_decompiled_code:
size_t func7(int a1, const char *a2, ...)
{
unsigned __int16 v2; // ax
gcc_va_list arg; // [rsp+8h] [rbp-4D0h] BYREF
char s[1024]; // [rsp+20h] [rbp-4B8h] BYREF

va_start(arg, a2);
v2 = vsnprintf(s, 0x400uLL, a2, arg);
return func6(a1, s, v2);
}

original_code:
void printf_tagged_message(uint32_t fourcc, const char *fmt, ...)
{
 char buf[1024];
 int len;
 va_list ap;
 __builtin_va_start(ap,fmt);
 len = vsnprintf(buf, sizeof buf, fmt, ap);
 __builtin_va_end(ap);
 write_tagged_message(fourcc, buf, len);
}

canonical_original_code:
void printf_tagged_message(unsigned int fourcc, char *fmt, ...)
{
 char buf[1024];
 int len;
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 len = vsnprintf(buf, sizeof buf, fmt, ap);
 __builtin_va_end(ap);
 write_tagged_message(fourcc, buf, len);
}

variable_types:
fourcc
unsigned int

variable_types:
fmt
char *

variable_types:
buf
char [1024]

variable_types: len int


decompiled_code:
void init_logging()
{
int v0; // eax

open_logfile();
open_socket();
clock_gettime(1, &starttime);
v0 = _bswap_32(0x4C4F4753u);
printf_tagged_message(v0, "initialized");
flush_buffers();
}

canonical_decompiled_code:
void func8()
{
int v0; // eax

func1();
func4();
clock_gettime(1, &starttime);
v0 = func3(0x4C4F4753u);
func7(v0, "initialized");
func5();
}

original_code:
void init_logging(void)
{
 open_logfile();
 open_socket();
 clock_gettime(1, &starttime);
 printf_tagged_message(htonl((('L') << 24) | (('O') << 16) | (('G') << 8) | ('S')), "initialized");
 flush_buffers();
}

canonical_original_code:
void init_logging()
{
 open_logfile();
 open_socket();
 clock_gettime(1, &starttime);
 printf_tagged_message(htonl((('L') << 24) | (('O') << 16) | (('G') << 8) | ('S')), "initialized");
 flush_buffers();
}


printbuffer

decompiled_code:
int __fastcall printbuffer(unsigned int a1, unsigned __int8 *a2, __int64 a3)
{
int v3; // ebp
unsigned __int8 *v4; // rbx
__int64 v5; // r12
__int64 v6; // rsi
__int64 v7; // rdx

v3 = a3;
v4 = a2;
printf("\nfourcc=%d buffer act_len=%d buffer: ", a1, a3);
if ( v3 > 0 )
{
v5 = (__int64)&a2[v3 - 1 + 1];
do
{
v6 = *v4;
v7 = 46LL;
if ( (unsigned __int8)v6 > 0x1Fu )
v7 = *v4;
++v4;
printf("%02X(%c) ", v6, v7);
}
while ( v4 != (unsigned __int8 *)v5 );
}
putchar(10);
return fflush(stdout);
}

canonical_decompiled_code:
int __fastcall func9(unsigned int a1, unsigned __int8 *a2, __int64 a3)
{
int v3; // ebp
unsigned __int8 *v4; // rbx
__int64 v5; // r12
__int64 v6; // rsi
__int64 v7; // rdx

v3 = a3;
v4 = a2;
printf("\nfourcc=%d buffer act_len=%d buffer: ", a1, a3);
if ( v3 > 0 )
{
v5 = (__int64)&a2[v3 - 1 + 1];
do
{
v6 = *v4;
v7 = 46LL;
if ( (unsigned __int8)v6 > 0x1Fu )
v7 = *v4;
++v4;
printf("%02X(%c) ", v6, v7);
}
while ( v4 != (unsigned __int8 *)v5 );
}
putchar(10);
return fflush(stdout);
}

original_code:
void printbuffer(uint32_t fourcc, const unsigned char *buffer, int act_len)
{
 printf("\nfourcc=%d buffer act_len=%d buffer: ", fourcc, act_len);
 for (int i = 0; i < act_len; i++) {
  unsigned char c = buffer[i];
  printf ("%02X(%c) ", c, c < 32 ? '.': c);
 }
 printf("\n");
 fflush(stdout);
}

canonical_original_code:
void printbuffer(unsigned int fourcc, unsigned char *buffer, int act_len)
{
 printf("\nfourcc=%d buffer act_len=%d buffer: ", fourcc, act_len);
 for (int i = 0; i < act_len; i++) {
  unsigned char c = buffer[i];
  printf ("%02X(%c) ", c, c < 32 ? '.': c);
 }
 printf("\n");
 fflush(stdout);
}

variable_types:
buffer
unsigned char *

variable_types: i int

variable_types:
c
unsigned char


decompiled_code:
// attributes: thunk
__int64 FCFERR_Poll()
{
return handleErrorPoll();
}

canonical_decompiled_code:
__int64 func0()
{
return handleErrorPoll();
}

original_code:
void FCFERR_Poll() {
        handleErrorPoll();
}


decompiled_code:
__int64 __fastcall FCF_Log(__int64 a1, __int64 a2, unsigned int a3)
{
write_tagged_message(a1, a2, (unsigned __int16)a3);
return printbuffer((unsigned int)a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, unsigned int a3)
{
write_tagged_message(a1, a2, (unsigned __int16)a3);
return printbuffer((unsigned int)a1, a2, a3);
}

original_code:
void FCF_Log (uint32_t fourcc, const unsigned char *buf, int act_len) {
  write_tagged_message(fourcc, buf, act_len);
  printbuffer(fourcc, buf, act_len);
}

canonical_original_code:
void FCF_Log(unsigned int fourcc, unsigned char *buf, int act_len) {
  write_tagged_message(fourcc, buf, act_len);
  printbuffer(fourcc, buf, act_len);
}

variable_types:
buf
unsigned char *


decompiled_code:
// attributes: thunk
__int64 FCF_ProfSendMsg()
{
return profReceiveMsg();
}

canonical_decompiled_code:
__int64 func3()
{
return profReceiveMsg();
}

original_code:
void FCF_ProfSendMsg(const char *message){
  profReceiveMsg(message);
}

canonical_original_code:
void FCF_ProfSendMsg(char *message){
  profReceiveMsg(message);
}

variable_types:
message
char *


decompiled_code:
__int64 profiling_cb()
{
FCF_ProfSendMsg(&unk_108);
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
FCF_ProfSendMsg(&unk_108);
return 0LL;
}

original_code:
static int profiling_cb (struct pollfd *pfd) {
 FCF_ProfSendMsg("");
 return 0;
}

canonical_original_code:
static int profiling_cb(struct pollfd *pfd) {
 FCF_ProfSendMsg("");
 return 0;
}


InitProfiling

decompiled_code:
int InitProfiling()
{
unsigned int v0; // ebp

t.it_interval.tv_sec = 0LL;
t.it_interval.tv_nsec = 0LL;
t.it_value.tv_sec = 0LL;
t.it_value.tv_nsec = 1LL;
v0 = timerfd_create(0, 0);
thefd = v0;
timerfd_settime(v0, 0, &t, 0LL);
fcf_addfd(v0, 1LL, profiling_cb);
return printf("\nprofile fd : %d", (unsigned int)thefd);
}

canonical_decompiled_code:
int func1()
{
unsigned int v0; // ebp

t.it_interval.tv_sec = 0LL;
t.it_interval.tv_nsec = 0LL;
t.it_value.tv_sec = 0LL;
t.it_value.tv_nsec = 1LL;
v0 = timerfd_create(0, 0);
thefd = v0;
timerfd_settime(v0, 0, &t, 0LL);
fcf_addfd(v0, 1LL, profiling_cb);
return printf("\nprofile fd : %d", (unsigned int)thefd);
}

original_code:
void InitProfiling() {
 t.it_interval.tv_sec = 0;
 t.it_interval.tv_nsec = 0;
 t.it_value.tv_sec = 0;
 t.it_value.tv_nsec = 1;
    thefd = timerfd_create(0, 0);
    timerfd_settime(thefd, 0, &t, ((void *)0));
    fcf_addfd(thefd, 0x001, profiling_cb);
    printf ("\nprofile fd : %d", thefd);
}


profReceiveMsg

decompiled_code:
__int64 profReceiveMsg()
{
if ( count == 10000000 )
stop_main_loop();
return (unsigned int)++count;
}

canonical_decompiled_code:
__int64 func2()
{
if ( count == 10000000 )
stop_main_loop();
return (unsigned int)++count;
}

original_code:
void profReceiveMsg (const char *msg) {
    if (count == 10000000){
        stop_main_loop();
    }
    count++;
}

canonical_original_code:
void profReceiveMsg(char *msg) {
    if (count == 10000000){
        stop_main_loop();
    }
    count++;
}

variable_types:
msg
char *


decompiled_code:
char *find_frames()
{
_BYTE *v0; // r12
char *v1; // rdi
char *result; // rax
char *v3; // rbx
signed __int64 v4; // rdx
int v5; // ecx
signed __int64 v6; // rbp
unsigned int v7; // eax
signed __int64 v8; // rbx

v0 = cur;
v1 = (char *)&buf;
while ( 1 )
{
result = (char *)memchr(v1, 36, v0 - v1);
v3 = result;
if ( !result )
break;
v4 = v0 - result;
if ( v0 - result <= 7 )
goto LABEL_10;
v1 = result + 1;
if ( *(_WORD *)(result + 1) == 18754 && result[3] == 78 && !result[5] )
{
v5 = *((unsigned __int16 *)result + 3);
v6 = v5 + 12;
if ( v4 < v6 )
{
LABEL_10:
v8 = result - (char *)&buf;
result = (char *)memmove(&buf, result, v4);
cur = &v0[-v8];
return result;
}
v1 = result + 4;
if ( *(_WORD *)&result[v5 + 10] == 2573 )
{
v7 = _bswap_32((unsigned __int8)result[4] | 0x47505300u);
FCF_Log(v7, v3 + 8);
v0 = cur;
v1 = &v3[v6];
}
}
}
cur = &buf;
return result;
}

canonical_decompiled_code:
char *func1()
{
_BYTE *v0; // r12
char *v1; // rdi
char *result; // rax
char *v3; // rbx
signed __int64 v4; // rdx
int v5; // ecx
signed __int64 v6; // rbp
unsigned int v7; // eax
signed __int64 v8; // rbx

v0 = cur;
v1 = (char *)&buf;
while ( 1 )
{
result = (char *)memchr(v1, 36, v0 - v1);
v3 = result;
if ( !result )
break;
v4 = v0 - result;
if ( v0 - result <= 7 )
goto LABEL_10;
v1 = result + 1;
if ( *(_WORD *)(result + 1) == 18754 && result[3] == 78 && !result[5] )
{
v5 = *((unsigned __int16 *)result + 3);
v6 = v5 + 12;
if ( v4 < v6 )
{
LABEL_10:
v8 = result - (char *)&buf;
result = (char *)memmove(&buf, result, v4);
cur = &v0[-v8];
return result;
}
v1 = result + 4;
if ( *(_WORD *)&result[v5 + 10] == 2573 )
{
v7 = func0((unsigned __int8)result[4] | 0x47505300u);
FCF_Log(v7, v3 + 8);
v0 = cur;
v1 = &v3[v6];
}
}
}
cur = &buf;
return result;
}

original_code:
static void find_frames(void)
{
 unsigned char *pos = buf;
 while((pos = memchr(pos, '$', cur - pos)))
 {
  if(cur - pos < 8)
   break;
  if(memcmp(pos + 1, "BIN", 3) != 0 || pos[5] != 0)
  {
   ++pos;
   continue;
  }
  int data_length = pos[6] | (pos[7] << 8);
  if(cur - pos < data_length + 12)
   break;
  if(memcmp(pos + data_length + 10, "\r\n", 2) != 0)
  {
   pos += 4;
   continue;
  }
  FCF_Log (htonl((('G') << 24) | (('P') << 16) | (('S') << 8) | (pos[4])), pos + 8, data_length + 2);
  pos += data_length + 12;
 }
 if(pos == ((void *)0))
  cur = buf;
 else
 {
  memmove(buf, pos, cur - pos);
  cur -= pos - buf;
 }
}

canonical_original_code:
static void find_frames()
{
 unsigned char *pos = buf;
 while((pos = memchr(pos, '$', cur - pos)))
 {
  if(cur - pos < 8)
   break;
  if(memcmp(pos + 1, "BIN", 3) != 0 || pos[5] != 0)
  {
   ++pos;
   continue;
  }
  int data_length = pos[6] | (pos[7] << 8);
  if(cur - pos < data_length + 12)
   break;
  if(memcmp(pos + data_length + 10, "\r\n", 2) != 0)
  {
   pos += 4;
   continue;
  }
  FCF_Log (htonl((('G') << 24) | (('P') << 16) | (('S') << 8) | (pos[4])), pos + 8, data_length + 2);
  pos += data_length + 12;
 }
 if(pos == ((void *)0))
  cur = buf;
 else
 {
  memmove(buf, pos, cur - pos);
  cur -= pos - buf;
 }
}

variable_types:
pos
unsigned char *


decompiled_code:
__int64 __fastcall read_gps_cb(__int64 a1)
{
ssize_t v2; // rax

if ( *(_WORD *)(a1 + 6) != 1 )
return 0LL;
v2 = read(*(_DWORD *)a1, cur, (char *)&device - (_BYTE *)cur);
if ( v2 <= 0 )
return 0LL;
cur = (char *)cur + v2;
find_frames();
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
ssize_t v2; // rax

if ( *(_WORD *)(a1 + 6) != 1 )
return 0LL;
v2 = read(*(_DWORD *)a1, cur, (char *)&device - (_BYTE *)cur);
if ( v2 <= 0 )
return 0LL;
cur = (char *)cur + v2;
func1();
return 1LL;
}

original_code:
static int read_gps_cb (struct pollfd *pfd) {
 if (pfd->revents != 0x001) {
  return 0;
 }
 ssize_t nread = read (pfd->fd, cur, sizeof(buf)-(cur-buf));
 if (nread <= 0) {
  return 0;
 }
 cur += nread;
 find_frames();
 return 1;
}

canonical_original_code:
static int read_gps_cb(struct pollfd *pfd) {
 if (pfd->revents != 0x001) {
  return 0;
 }
 long nread = read (pfd->fd, cur, sizeof(buf)-(cur-buf));
 if (nread <= 0) {
  return 0;
 }
 cur += nread;
 find_frames();
 return 1;
}

variable_types: struct pollfd { int fd; short events; short revents; } *

variable_types: nread long


decompiled_code:
void __fastcall set_gps_devicepath(char *a1)
{
device = a1;
}

canonical_decompiled_code:
void __fastcall func3(char *a1)
{
device = a1;
}

original_code:
void set_gps_devicepath (const char *dev) {
 device = dev;
}

canonical_original_code:
void set_gps_devicepath(char *dev) {
 device = dev;
}

variable_types:
dev
char *


decompiled_code:
void __fastcall common_cb(__int64 a1, unsigned int a2)
{
__int64 v3; // rdi
__int64 v4; // rdx
_BYTE *v6; // rsi

v3 = *(unsigned int *)(a1 + 16);
if ( (_DWORD)v3 )
{
if ( (_DWORD)v3 != 3 )
print_libusb_transfer_error(v3, "imu_cb");
}
else
{
v4 = *(unsigned int *)(a1 + 24);
v6 = *(_BYTE **)(a1 + 48);
if ( (_DWORD)v4 == 13 && (v4 = 12LL, (*v6 & 0xF0) == 64) )
FCF_Log(a2, v6, 13LL);
else
FCF_Log(a2, v6, v4);
if ( (unsigned int)libusb_submit_transfer(a1) )
print_libusb_transfer_error(*(unsigned int *)(a1 + 16), "imu_cb resub");
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, unsigned int a2)
{
__int64 v3; // rdi
__int64 v4; // rdx
_BYTE *v6; // rsi

v3 = *(unsigned int *)(a1 + 16);
if ( (_DWORD)v3 )
{
if ( (_DWORD)v3 != 3 )
print_libusb_transfer_error(v3, "imu_cb");
}
else
{
v4 = *(unsigned int *)(a1 + 24);
v6 = *(_BYTE **)(a1 + 48);
if ( (_DWORD)v4 == 13 && (v4 = 12LL, (*v6 & 0xF0) == 64) )
FCF_Log(a2, v6, 13LL);
else
FCF_Log(a2, v6, v4);
if ( (unsigned int)libusb_submit_transfer(a1) )
print_libusb_transfer_error(*(unsigned int *)(a1 + 16), "imu_cb resub");
}
}

original_code:
static int common_cb (uint32_t fourcc, int fd) {
 int rc = readsocket(fd, buffer, sizeof(buffer));
 if (rc > 0) {
  FCF_Log(fourcc, buffer, rc);
 }
 return rc;
}

canonical_original_code:
static int common_cb(unsigned int fourcc, int fd) {
 int rc = readsocket(fd, buffer, sizeof(buffer));
 if (rc > 0) {
  FCF_Log(fourcc, buffer, rc);
 }
 return rc;
}

variable_types: fd int

variable_types: rc int


decompiled_code:
void __fastcall common_cb(__int64 a1, unsigned int a2)
{
__int64 v3; // rdi

v3 = *(unsigned int *)(a1 + 16);
if ( (_DWORD)v3 )
{
if ( (_DWORD)v3 != 3 )
print_libusb_transfer_error(v3, "common_cb");
}
else
{
FCF_Log(a2, *(_QWORD *)(a1 + 48), *(unsigned int *)(a1 + 24));
if ( (unsigned int)libusb_submit_transfer(a1) )
print_libusb_transfer_error(*(unsigned int *)(a1 + 16), "common_cb resub");
}
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, unsigned int a2)
{
__int64 v3; // rdi

v3 = *(unsigned int *)(a1 + 16);
if ( (_DWORD)v3 )
{
if ( (_DWORD)v3 != 3 )
print_libusb_transfer_error(v3, "common_cb");
}
else
{
FCF_Log(a2, *(_QWORD *)(a1 + 48), *(unsigned int *)(a1 + 24));
if ( (unsigned int)libusb_submit_transfer(a1) )
print_libusb_transfer_error(*(unsigned int *)(a1 + 16), "common_cb resub");
}
}


decompiled_code:
void __fastcall common_cb(__int64 a1, unsigned int a2)
{
__int64 v3; // rdi
__int64 v4; // rdx

v3 = *(unsigned int *)(a1 + 16);
if ( (_DWORD)v3 )
{
if ( (_DWORD)v3 != 3 )
print_libusb_transfer_error(v3, "adis_cb");
}
else
{
v4 = *(unsigned int *)(a1 + 24);
if ( (_DWORD)v4 == 24 )
v4 = 24LL;
FCF_Log(a2, *(_QWORD *)(a1 + 48), v4);
if ( (unsigned int)libusb_submit_transfer(a1) )
print_libusb_transfer_error(*(unsigned int *)(a1 + 16), "adis_cb resub");
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, unsigned int a2)
{
__int64 v3; // rdi
__int64 v4; // rdx

v3 = *(unsigned int *)(a1 + 16);
if ( (_DWORD)v3 )
{
if ( (_DWORD)v3 != 3 )
print_libusb_transfer_error(v3, "adis_cb");
}
else
{
v4 = *(unsigned int *)(a1 + 24);
if ( (_DWORD)v4 == 24 )
v4 = 24LL;
FCF_Log(a2, *(_QWORD *)(a1 + 48), v4);
if ( (unsigned int)libusb_submit_transfer(a1) )
print_libusb_transfer_error(*(unsigned int *)(a1 + 16), "adis_cb resub");
}
}


dieWithUserMessage

decompiled_code:
void __fastcall __noreturn dieWithUserMessage(const char *a1, const char *a2)
{
fputs(a1, stderr);
fwrite(&unk_75, 1uLL, 2uLL, stderr);
fputs(a2, stderr);
fputc(10, stderr);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1, const char *a2)
{
fputs(a1, stderr);
fwrite(&unk_75, 1uLL, 2uLL, stderr);
fputs(a2, stderr);
fputc(10, stderr);
exit(1);
}

original_code:
void dieWithUserMessage(const char* message, const char* detail){
    fputs(message, stderr);
    fputs(": ", stderr);
    fputs(detail, stderr);
    fputc('\n', stderr);
    exit(1);
}

canonical_original_code:
void dieWithUserMessage(char *message, char *detail){
    fputs(message, stderr);
    fputs(": ", stderr);
    fputs(detail, stderr);
    fputc('\n', stderr);
    exit(1);
}

variable_types:
detail
char *


dieWithSystemMessage

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

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

original_code:
void dieWithSystemMessage(const char* message){
    perror(message);
    exit(1);
}

canonical_original_code:
void dieWithSystemMessage(char *message){
    perror(message);
    exit(1);
}


initSymbolTable

decompiled_code:
__int64 __fastcall initSymbolTable(__int64 a1, const char *a2)
{
size_t v2; // rax
__int64 result; // rax

if ( a2 )
{
v2 = strlen(a2);
*(_QWORD *)a1 = malloc(v2 + 1);
*(_QWORD *)a1 = strdup(a2);
}
else
{
*(_QWORD *)a1 = 0LL;
}
result = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
*(_WORD *)(a1 + 8) = 0;
*(_QWORD *)(a1 + 24) = 0LL;
*(_QWORD *)(a1 + 32) = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, const char *a2)
{
size_t v2; // rax
__int64 result; // rax

if ( a2 )
{
v2 = strlen(a2);
*(_QWORD *)a1 = malloc(v2 + 1);
*(_QWORD *)a1 = strdup(a2);
}
else
{
*(_QWORD *)a1 = 0LL;
}
result = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
*(_WORD *)(a1 + 8) = 0;
*(_QWORD *)(a1 + 24) = 0LL;
*(_QWORD *)(a1 + 32) = 0LL;
return result;
}

original_code:
void initSymbolTable(SYMREC* table, const char* name){
    if (name != ((void *)0)){
        table->name = (char*)malloc(strlen(name) + 1);
        table->name = strdup(name);
    }
    else{
        table->name = ((void *)0);
    }
    table->id_type = 0;
    table->value.type = ((void *)0);
    table->location = ((void *)0);
    table->next = ((void *)0);
    return;
}

canonical_original_code:
void initSymbolTable(struct _symrec *table, char *name){
    if (name != ((void *)0)){
        table->name = (char *)malloc(strlen(name) + 1);
        table->name = strdup(name);
    }
    else{
        table->name = ((void *)0);
    }
    table->id_type = 0;
    table->value.type = ((void *)0);
    table->location = ((void *)0);
    table->next = ((void *)0);
    return;
}

variable_types: struct _symrec { char *name; unsigned short id_type; union { char *type; struct _symrec *list; } value; struct _symloc { unsigned int line; unsigned short column; } *location; struct _symrec *next; } *

variable_types:
name
char *

user_defined_types: struct _symrec { char *name; unsigned short id_type; union { char *type; struct _symrec *list; } value; struct _symloc *location; struct _symrec *next; }


freeSymbolTable

decompiled_code:
void __fastcall freeSymbolTable(_QWORD *a1)
{
__int64 i; // rbp
void *v3; // rdi

for ( i = a1[4]; i; i = a1[4] )
{
if ( ((*(_WORD *)(i + 8) - 3) & 0xFFFD) == 0 )
freeSymbolTable(*(_QWORD *)(i + 16));
v3 = *(void **)(i + 24);
a1[4] = *(_QWORD *)(i + 32);
free(v3);
free((void *)i);
}
free(a1);
}

original_code:
void freeSymbolTable(SYMREC* table){
    SYMREC *node;
    node = table->next;
    while (node != ((void *)0)){
        if ((node->id_type == PROCEDURE_DECLARATION)
                || (node->id_type == FUNCTION_DECLARATION)){
            freeSymbolTable(node->value.list);
        }
        table->next = node->next;
        free(node->location);
        free(node);
        node = table->next;
    }
    free(table);
    return;
}

canonical_original_code:
void freeSymbolTable(struct _symrec *table){
    struct _symrec *node;
    node = table->next;
    while (node != ((void *)0)){
        if ((node->id_type == PROCEDURE_DECLARATION)
                || (node->id_type == FUNCTION_DECLARATION)){
            freeSymbolTable(node->value.list);
        }
        table->next = node->next;
        free(node->location);
        free(node);
        node = table->next;
    }
    free(table);
    return;
}

user_defined_types: struct _symloc { unsigned int line; unsigned short column; }


checkSymbolTable

decompiled_code:
__int64 __fastcall checkSymbolTable(__int64 a1, const char *a2, __int16 a3, unsigned int *a4)
{
__int64 v6; // rbx
unsigned int v7; // er14
__int64 result; // rax

v6 = *(_QWORD *)(a1 + 32);
if ( v6 )
{
while ( strcmp(a2, *(const char **)v6) )
{
v6 = *(_QWORD *)(v6 + 32);
if ( !v6 )
goto LABEL_9;
}
if ( a3 == 3 )
{
fprintf(stderr, "Line %u:%u : Multiple Declaration of Procedure '%s'\n", *a4, *((unsigned __int16 *)a4 + 2), a2);
result = 0LL;
}
else if ( a3 == 5 )
{
fprintf(stderr, "Line %u:%u : Multiple Declaration of Function '%s'\n", *a4, *((unsigned __int16 *)a4 + 2), a2);
result = 0LL;
}
else
{
v7 = 0;
if ( a3 != 1 )
return v7;
fprintf(stderr, "Line %u:%u : Multiple Declaration of Identifier '%s'\n", *a4, *((unsigned __int16 *)a4 + 2), a2);
result = 0LL;
}
}
else
{
LABEL_9:
if ( a3 == 6 )
{
fprintf(stderr, "Line %u:%u : Undefined Function Reference '%s'\n", *a4, *((unsigned __int16 *)a4 + 2), a2);
result = 1LL;
}
else
{
if ( a3 != 7 )
{
v7 = 1;
if ( a3 == 4 )
{
fprintf(stderr, "Line %u:%u : Undefined Procedure Reference '%s'\n", *a4, *((unsigned __int16 *)a4 + 2), a2);
return 1LL;
}
return v7;
}
fprintf(stderr, "Line %u:%u : Undefined Variable Reference '%s'\n", *a4, *((unsigned __int16 *)a4 + 2), a2);
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char *a2, __int16 a3, unsigned int *a4)
{
__int64 v6; // rbx
unsigned int v7; // er14
__int64 result; // rax

v6 = *(_QWORD *)(a1 + 32);
if ( v6 )
{
while ( strcmp(a2, *(const char **)v6) )
{
v6 = *(_QWORD *)(v6 + 32);
if ( !v6 )
goto LABEL_9;
}
if ( a3 == 3 )
{
fprintf(stderr, "Line %u:%u : Multiple Declaration of Procedure '%s'\n", *a4, *((unsigned __int16 *)a4 + 2), a2);
result = 0LL;
}
else if ( a3 == 5 )
{
fprintf(stderr, "Line %u:%u : Multiple Declaration of Function '%s'\n", *a4, *((unsigned __int16 *)a4 + 2), a2);
result = 0LL;
}
else
{
v7 = 0;
if ( a3 != 1 )
return v7;
fprintf(stderr, "Line %u:%u : Multiple Declaration of Identifier '%s'\n", *a4, *((unsigned __int16 *)a4 + 2), a2);
result = 0LL;
}
}
else
{
LABEL_9:
if ( a3 == 6 )
{
fprintf(stderr, "Line %u:%u : Undefined Function Reference '%s'\n", *a4, *((unsigned __int16 *)a4 + 2), a2);
result = 1LL;
}
else
{
if ( a3 != 7 )
{
v7 = 1;
if ( a3 == 4 )
{
fprintf(stderr, "Line %u:%u : Undefined Procedure Reference '%s'\n", *a4, *((unsigned __int16 *)a4 + 2), a2);
return 1LL;
}
return v7;
}
fprintf(stderr, "Line %u:%u : Undefined Variable Reference '%s'\n", *a4, *((unsigned __int16 *)a4 + 2), a2);
result = 1LL;
}
}
return result;
}

original_code:
_Bool checkSymbolTable( const SYMREC* table,
                        const char* name,
                        u_int16 type,
                        const SYMLOC* location){
    SYMREC *node;
    for (node = table->next; node != ((void *)0); node = node->next){
        if (strcmp(name, node->name) == 0){
            switch (type){
                case DECLARATION_LEFT:
                    fprintf(stderr, "Line %u:%u : Multiple Declaration of Identifier '%s'\n", location->line,
                                                                                location->column,
                                                                                name);
                    break;
                case PROCEDURE_DECLARATION:
                    fprintf(stderr, "Line %u:%u : Multiple Declaration of Procedure '%s'\n", location->line,
                                                                                location->column,
                                                                                name);
                    break;
                case FUNCTION_DECLARATION:
                    fprintf(stderr, "Line %u:%u : Multiple Declaration of Function '%s'\n", location->line,
                                                                                location->column,
                                                                                name);
                    break;
                default:
                    break;
            }
            return 0;
        }
    }
    switch (type){
        case PROCEDURE_REFERENCE:
            fprintf(stderr, "Line %u:%u : Undefined Procedure Reference '%s'\n", location->line,
                                                                                location->column,
                                                                                name);
            break;
        case FUNCTION_REFERENCE:
            fprintf(stderr, "Line %u:%u : Undefined Function Reference '%s'\n", location->line,
                                                                                location->column,
                                                                                name);
            break;
        case VARIABLE_REFERENCE:
            fprintf(stderr, "Line %u:%u : Undefined Variable Reference '%s'\n", location->line,
                                                                                location->column,
                                                                                name);
            break;
        default:
            break;
    }
    return 1;
}

canonical_original_code:
_Bool checkSymbolTable(struct _symrec *table, char *name, unsigned short type, struct _symloc *location){
    struct _symrec *node;
    for (node = table->next; node != ((void *)0); node = node->next){
        if (strcmp(name, node->name) == 0){
            switch (type){
                case DECLARATION_LEFT:
                    fprintf(stderr, "Line %u:%u : Multiple Declaration of Identifier '%s'\n", location->line,
                                                                                location->column,
                                                                                name);
                    break;
                case PROCEDURE_DECLARATION:
                    fprintf(stderr, "Line %u:%u : Multiple Declaration of Procedure '%s'\n", location->line,
                                                                                location->column,
                                                                                name);
                    break;
                case FUNCTION_DECLARATION:
                    fprintf(stderr, "Line %u:%u : Multiple Declaration of Function '%s'\n", location->line,
                                                                                location->column,
                                                                                name);
                    break;
                default:
                    break;
            }
            return 0;
        }
    }
    switch (type){
        case PROCEDURE_REFERENCE:
            fprintf(stderr, "Line %u:%u : Undefined Procedure Reference '%s'\n", location->line,
                                                                                location->column,
                                                                                name);
            break;
        case FUNCTION_REFERENCE:
            fprintf(stderr, "Line %u:%u : Undefined Function Reference '%s'\n", location->line,
                                                                                location->column,
                                                                                name);
            break;
        case VARIABLE_REFERENCE:
            fprintf(stderr, "Line %u:%u : Undefined Variable Reference '%s'\n", location->line,
                                                                                location->column,
                                                                                name);
            break;
        default:
            break;
    }
    return 1;
}

variable_types:
type
unsigned short

variable_types:
location
struct _symloc *


putSymbolTable

decompiled_code:
void __fastcall putSymbolTable(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rbp
unsigned int *v4; // rcx
__int16 v5; // dx

if ( a2 )
{
v2 = a2;
do
{
while ( 1 )
{
v3 = v2;
v2 = *(_QWORD *)(v2 + 32);
v4 = *(unsigned int **)(v3 + 24);
v5 = *(_WORD *)(v3 + 8);
*(_QWORD *)(v3 + 32) = 0LL;
if ( !(unsigned __int8)checkSymbolTable(a1, *(const char **)v3, v5, v4) )
break;
*(_QWORD *)(v3 + 32) = *(_QWORD *)(a1 + 32);
*(_QWORD *)(a1 + 32) = v3;
if ( !v2 )
return;
}
free((void *)v3);
}
while ( v2 );
}
}

original_code:
void putSymbolTable(SYMREC* table, SYMREC* list){
    SYMREC *node;
    node = list;
    while (node != ((void *)0)){
        list = node->next;
        node->next = ((void *)0);
        if (checkSymbolTable(table, node->name, node->id_type, node->location)){
            node->next = table->next;
            table->next = node;
        }
        else{
            free(node);
        }
        node = list;
    }
    return;
}

canonical_original_code:
void putSymbolTable(struct _symrec *table, struct _symrec *list){
    struct _symrec *node;
    node = list;
    while (node != ((void *)0)){
        list = node->next;
        node->next = ((void *)0);
        if (checkSymbolTable(table, node->name, node->id_type, node->location)){
            node->next = table->next;
            table->next = node;
        }
        else{
            free(node);
        }
        node = list;
    }
    return;
}

variable_types:
list
struct _symrec *


setIdentifier

original_code:
void setIdentifier( SYMREC* list,
                    u_int16 type,
                    const char *value,
                    SYMREC* child){
    SYMREC *node;
    for (node = list; node != ((void *)0); node = node->next){
        node->id_type = type;
        if ((value == ((void *)0)) && (child == ((void *)0))){
            node->value.type = ((void *)0);
        }
        else if (value != ((void *)0)){
            node->value.type = strdup(value);
        }
        else{
            node->value.list = child;
        }
    }
    return;
}

canonical_original_code:
void setIdentifier(struct _symrec *list, unsigned short type, char *value, struct _symrec *child){
    struct _symrec *node;
    for (node = list; node != ((void *)0); node = node->next){
        node->id_type = type;
        if ((value == ((void *)0)) && (child == ((void *)0))){
            node->value.type = ((void *)0);
        }
        else if (value != ((void *)0)){
            node->value.type = strdup(value);
        }
        else{
            node->value.list = child;
        }
    }
    return;
}

variable_types:
value
char *

variable_types:
child
struct _symrec *


main

canonical_name: main

repo: elgitolero/ipc-stuff

decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbx
unsigned int v4; // eax
unsigned int v5; // ebp
const __int32_t **v6; // rax
int v7; // eax
__int64 v9; // rax
_BYTE v10[120]; // [rsp+0h] [rbp-78h] BYREF

if ( argc == 1 )
goto LABEL_13;
v3 = argv;
v4 = ftok(".", 109);
argv = (const char **)944;
*(_QWORD *)&argc = v4;
v5 = msgget(v4, 944);
if ( v5 == -1 )
{
perror("msgget");
exit(1);
}
v6 = __ctype_tolower_loc();
envp = (const char **)*v3[1];
v7 = (*v6)[(_QWORD)envp];
if ( v7 == 114 )
{
v9 = atol(v3[2]);
read_message(v5, v10, v9);
return 0;
}
if ( v7 > 114 )
{
if ( v7 == 115 )
{
atol(v3[2]);
send_message(v5, v10);
return 0;
}
LABEL_13:
usage(*(_QWORD *)&argc, argv, envp);
}
if ( v7 == 100 )
{
remove_queue(v5);
return 0;
}
if ( v7 != 109 )
goto LABEL_13;
change_queue_mode(v5);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbx
unsigned int v4; // eax
unsigned int v5; // ebp
const __int32_t **v6; // rax
int v7; // eax
__int64 v9; // rax
_BYTE v10[120]; // [rsp+0h] [rbp-78h] BYREF

if ( argc == 1 )
goto LABEL_13;
v3 = argv;
v4 = ftok(".", 109);
argv = (const char **)944;
*(_QWORD *)&argc = v4;
v5 = msgget(v4, 944);
if ( v5 == -1 )
{
perror("msgget");
exit(1);
}
v6 = __ctype_tolower_loc();
envp = (const char **)*v3[1];
v7 = (*v6)[(_QWORD)envp];
if ( v7 == 114 )
{
v9 = atol(v3[2]);
func8(v5, v10, v9);
return 0;
}
if ( v7 > 114 )
{
if ( v7 == 115 )
{
atol(v3[2]);
func7(v5, v10);
return 0;
}
LABEL_13:
func11(*(_QWORD *)&argc, argv, envp);
}
if ( v7 == 100 )
{
func9(v5);
return 0;
}
if ( v7 != 109 )
goto LABEL_13;
func10(v5);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
        key_t key;
        int msgqueue_id;
        struct mymsgbuf qbuf;
        if(argc == 1)
                usage();
        key = ftok(".", 'm');
        if((msgqueue_id = msgget(key, 01000|0660)) == -1) {
                perror("msgget");
                exit(1);
        }
        switch(tolower(argv[1][0]))
        {
                case 's': send_message(msgqueue_id, (struct mymsgbuf *)&qbuf,
                                       atol(argv[2]), argv[3]);
                          break;
                case 'r': read_message(msgqueue_id, &qbuf, atol(argv[2]));
                          break;
                case 'd': remove_queue(msgqueue_id);
                          break;
                case 'm': change_queue_mode(msgqueue_id, argv[2]);
                          break;
                 default: usage();
        }
        return(0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
        int key;
        int msgqueue_id;
        struct mymsgbuf qbuf;
        if(argc == 1)
                usage();
        key = ftok(".", 'm');
        if((msgqueue_id = msgget(key, 01000|0660)) == -1) {
                perror("msgget");
                exit(1);
        }
        switch(tolower(argv[1][0]))
        {
                case 's': send_message(msgqueue_id, (struct mymsgbuf *)&qbuf,
                                       atol(argv[2]), argv[3]);
                          break;
                case 'r': read_message(msgqueue_id, &qbuf, atol(argv[2]));
                          break;
                case 'd': remove_queue(msgqueue_id);
                          break;
                case 'm': change_queue_mode(msgqueue_id, argv[2]);
                          break;
                 default: usage();
        }
        return(0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: key int

variable_types: struct mymsgbuf { long mtype; char mtext[80]; }


decompiled_code:
int __fastcall remove_queue(int a1)
{
return msgctl(a1, 0, 0LL);
}

canonical_decompiled_code:
int __fastcall func9(int a1)
{
return msgctl(a1, 0, 0LL);
}

original_code:
void remove_queue(int qid)
{
        msgctl(qid, 0, 0);
}

variable_types: qid int


decompiled_code:
int __fastcall change_queue_mode(int msqid)
{
struct msqid_ds v2; // [rsp+0h] [rbp-98h] BYREF

msgctl(msqid, 2, &v2);
__isoc99_sscanf();
return msgctl(msqid, 1, &v2);
}

canonical_decompiled_code:
int __fastcall func10(int msqid)
{
struct msqid_ds v2; // [rsp+0h] [rbp-98h] BYREF

msgctl(msqid, 2, &v2);
__isoc99_sscanf();
return msgctl(msqid, 1, &v2);
}

original_code:
void change_queue_mode(int qid, char *mode)
{
        struct msqid_ds myqueue_ds;
        msgctl(qid, 2, &myqueue_ds);
        sscanf(mode, "%ho", &myqueue_ds.msg_perm.mode);
        msgctl(qid, 1, &myqueue_ds);
}

variable_types:
mode
char *

variable_types: struct msqid_ds { struct ipc_perm { int __key; unsigned int uid; unsigned int gid; unsigned int cuid; unsigned int cgid; unsigned short mode; unsigned short __pad1; unsigned short __seq; unsigned short __pad2; unsigned long __glibc_reserved1; unsigned long __glibc_reserved2; } msg_perm; long msg_stime; long msg_rtime; long msg_ctime; unsigned long __msg_cbytes; unsigned long msg_qnum; unsigned long msg_qbytes; int msg_lspid; int msg_lrpid; unsigned long __glibc_reserved4; unsigned long __glibc_reserved5; }

user_defined_types: struct msqid_ds { struct ipc_perm msg_perm; long msg_stime; long msg_rtime; long msg_ctime; unsigned long __msg_cbytes; unsigned long msg_qnum; unsigned long msg_qbytes; int msg_lspid; int msg_lrpid; unsigned long __glibc_reserved4; unsigned long __glibc_reserved5; }


usage

decompiled_code:
void __noreturn usage()
{
fwrite("msgtool - A utility for tinkering with msg queues\n", 1uLL, 0x32uLL, _bss_start);
fwrite("\nUSAGE: msgtool (s)end <type> <messagetext>\n", 1uLL, 0x2CuLL, _bss_start);
fwrite(" (r)ecv <type>\n", 1uLL, 0x1DuLL, _bss_start);
fwrite(" (d)elete\n", 1uLL, 0x18uLL, _bss_start);
fwrite(" (m)ode <octal mode>\n", 1uLL, 0x23uLL, _bss_start);
exit(1);
}

canonical_decompiled_code:
void __noreturn func11()
{
fwrite("msgtool - A utility for tinkering with msg queues\n", 1uLL, 0x32uLL, _bss_start);
fwrite("\nUSAGE: msgtool (s)end <type> <messagetext>\n", 1uLL, 0x2CuLL, _bss_start);
fwrite(" (r)ecv <type>\n", 1uLL, 0x1DuLL, _bss_start);
fwrite(" (d)elete\n", 1uLL, 0x18uLL, _bss_start);
fwrite(" (m)ode <octal mode>\n", 1uLL, 0x23uLL, _bss_start);
exit(1);
}

original_code:
void usage(void)
{
        fprintf(stderr, "msgtool - A utility for tinkering with msg queues\n");
        fprintf(stderr, "\nUSAGE: msgtool (s)end <type> <messagetext>\n");
        fprintf(stderr, "               (r)ecv <type>\n");
        fprintf(stderr, "               (d)elete\n");
        fprintf(stderr, "               (m)ode <octal mode>\n");
        exit(1);
}

canonical_original_code:
void usage()
{
        fprintf(stderr, "msgtool - A utility for tinkering with msg queues\n");
        fprintf(stderr, "\nUSAGE: msgtool (s)end <type> <messagetext>\n");
        fprintf(stderr, "               (r)ecv <type>\n");
        fprintf(stderr, "               (d)elete\n");
        fprintf(stderr, "               (m)ode <octal mode>\n");
        exit(1);
}


main

repo: eliben/libjit-samples

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
run_from_rwx(argc, argv, envp);
emit_to_rw_run_from_rx();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func11(argc, argv, envp);
func12();
return 0;
}

original_code:
int main(int argc, char** argv) {
  run_from_rwx();
  emit_to_rw_run_from_rx();
  return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
  run_from_rwx();
  emit_to_rw_run_from_rx();
  return 0;
}

variable_types:
argv
char **


decompiled_code:
void *__fastcall alloc_executable_memory(size_t len)
{
void *result; // rax

result = mmap(0LL, len, 7, 34, -1, 0LL);
if ( result == (void *)-1LL )
{
perror("mmap");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
void *__fastcall func7(size_t len)
{
void *result; // rax

result = mmap(0LL, len, 7, 34, -1, 0LL);
if ( result == (void *)-1LL )
{
perror("mmap");
result = 0LL;
}
return result;
}

original_code:
void* alloc_executable_memory(size_t size) {
  void* ptr = mmap(0, size,
                   0x1 | 0x2 | 0x4,
                   0x02 | 0x20, -1, 0);
  if (ptr == (void*)-1) {
    perror("mmap");
    return ((void *)0);
  }
  return ptr;
}

canonical_original_code:
void *alloc_executable_memory(unsigned long size) {
  void *ptr = mmap(0, size,
                   0x1 | 0x2 | 0x4,
                   0x02 | 0x20, -1, 0);
  if (ptr == (void *)-1) {
    perror("mmap");
    return ((void *)0);
  }
  return ptr;
}

variable_types:
size
unsigned long

variable_types:
ptr
void *

return_type: void *


decompiled_code:
void *__fastcall alloc_writable_memory(size_t len)
{
void *result; // rax

result = mmap(0LL, len, 3, 34, -1, 0LL);
if ( result == (void *)-1LL )
{
perror("mmap");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
void *__fastcall func8(size_t len)
{
void *result; // rax

result = mmap(0LL, len, 3, 34, -1, 0LL);
if ( result == (void *)-1LL )
{
perror("mmap");
result = 0LL;
}
return result;
}

original_code:
void* alloc_writable_memory(size_t size) {
  void* ptr = mmap(0, size,
                   0x1 | 0x2,
                   0x02 | 0x20, -1, 0);
  if (ptr == (void*)-1) {
    perror("mmap");
    return ((void *)0);
  }
  return ptr;
}

canonical_original_code:
void *alloc_writable_memory(unsigned long size) {
  void *ptr = mmap(0, size,
                   0x1 | 0x2,
                   0x02 | 0x20, -1, 0);
  if (ptr == (void *)-1) {
    perror("mmap");
    return ((void *)0);
  }
  return ptr;
}


decompiled_code:
__int64 __fastcall make_memory_executable(void *a1, size_t a2)
{
if ( mprotect(a1, a2, 5) != -1 )
return 0LL;
perror("mprotect");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func9(void *a1, size_t a2)
{
if ( mprotect(a1, a2, 5) != -1 )
return 0LL;
perror("mprotect");
return 0xFFFFFFFFLL;
}

original_code:
int make_memory_executable(void* m, size_t size) {
  if (mprotect(m, size, 0x1 | 0x4) == -1) {
    perror("mprotect");
    return -1;
  }
  return 0;
}

canonical_original_code:
int make_memory_executable(void *m, unsigned long size) {
  if (mprotect(m, size, 0x1 | 0x4) == -1) {
    perror("mprotect");
    return -1;
  }
  return 0;
}

variable_types:
m
void *


decompiled_code:
__int64 __fastcall emit_code_into_memory(_QWORD *a1)
{
*a1 = 0xC304C08348F88948LL;
return 8LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD *a1)
{
*a1 = 0xC304C08348F88948LL;
return 8LL;
}

original_code:
size_t emit_code_into_memory(unsigned char* m) {
  unsigned char code[] = {
    0x48, 0x89, 0xf8,
    0x48, 0x83, 0xc0, 0x04,
    0xc3
  };
  memcpy(m, code, sizeof(code));
  return sizeof(code);
}

canonical_original_code:
unsigned long emit_code_into_memory(unsigned char *m) {
  unsigned char code[] = {
    0x48, 0x89, 0xf8,
    0x48, 0x83, 0xc0, 0x04,
    0xc3
  };
  memcpy(m, code, sizeof(code));
  return sizeof(code);
}

variable_types:
m
unsigned char *

variable_types:
code
unsigned char []


decompiled_code:
int emit_to_rw_run_from_rx()
{
_QWORD *v0; // rbx
__int64 v1; // rax

v0 = alloc_writable_memory(0x400uLL);
emit_code_into_memory(v0);
make_memory_executable(v0, 0x400uLL);
v1 = ((__int64 (__fastcall *)(__int64))v0)(2LL);
return printf("result = %d\n", v1);
}

canonical_decompiled_code:
int func12()
{
_QWORD *v0; // rbx
__int64 v1; // rax

v0 = func8(0x400uLL);
func10(v0);
func9(v0, 0x400uLL);
v1 = ((__int64 (__fastcall *)(__int64))v0)(2LL);
return printf("result = %d\n", v1);
}

original_code:
void emit_to_rw_run_from_rx() {
  void* m = alloc_writable_memory(SIZE);
  emit_code_into_memory(m);
  make_memory_executable(m, SIZE);
  JittedFunc func = m;
  int result = func(2);
  printf("result = %d\n", result);
}

canonical_original_code:
void emit_to_rw_run_from_rx() {
  void *m = alloc_writable_memory(SIZE);
  emit_code_into_memory(m);
  make_memory_executable(m, SIZE);
  long (*func)(long) = m;
  int result = func(2);
  printf("result = %d\n", result);
}

variable_types:
func
long (*)(long)

variable_types: result int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int16 v3; // bx
unsigned int v4; // eax
__int64 v5; // rsi
__int64 v6; // rdi
__int64 v7; // rdi

v3 = 0;
v4 = time(0LL);
srand(v4);
init_map(&map, 20LL, 20LL);
generate_map(&map, 1LL);
SDL_Init();
v5 = 20 * (unsigned int)(unsigned __int8)byte_404148;
v6 = 20 * (unsigned int)(unsigned __int8)byte_404149;
screen = SDL_SetVideoMode();
load_images(v6, v5);
do
{
while ( (unsigned int)SDL_PollEvent() )
{
while ( event == 12 || dword_4040B8 == 27 || dword_4040B8 == 13 )
{
v3 = 1;
if ( !(unsigned int)SDL_PollEvent() )
goto LABEL_7;
}
}
LABEL_7:
image_draw_test(&event);
v7 = screen;
SDL_Flip();
}
while ( !v3 );
free_images(v7);
free_map(&map);
SDL_Quit();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int16 v3; // bx
unsigned int v4; // eax
__int64 v5; // rsi
__int64 v6; // rdi
__int64 v7; // rdi

v3 = 0;
v4 = time(0LL);
srand(v4);
func9(&map, 20LL, 20LL);
func16(&map, 1LL);
SDL_Init();
v5 = 20 * (unsigned int)(unsigned __int8)byte_404148;
v6 = 20 * (unsigned int)(unsigned __int8)byte_404149;
screen = SDL_SetVideoMode();
func17(v6, v5);
do
{
while ( (unsigned int)SDL_PollEvent() )
{
while ( event == 12 || dword_4040B8 == 27 || dword_4040B8 == 13 )
{
v3 = 1;
if ( !(unsigned int)SDL_PollEvent() )
goto LABEL_7;
}
}
LABEL_7:
func19(&event);
v7 = screen;
SDL_Flip();
}
while ( !v3 );
func18(v7);
func7(&map);
SDL_Quit();
return 0;
}

original_code:
int main(int argc, char* args[]) {
 srand(time(((void *)0)));
 init_map(&map, 20, 20);
 generate_map(&map, 1);
 SDL_Init(0x0000FFFF);
 screen = SDL_SetVideoMode(20 * map.width, 20 * map.height, 32, 0x00000000);
 load_images();
 short quit = 0;
 while (!quit) {
  while (SDL_PollEvent(&event)) {
   if (event.type == SDL_QUIT || event.key.keysym.sym == SDLK_ESCAPE || event.key.keysym.sym == SDLK_RETURN) {
    quit = 1;
   }
  }
  for (int i = 0; i < map.width * map.height; i++) {
  }
  image_draw_test();
  SDL_Flip(screen);
 }
 free_images();
 free_map(&map);
 SDL_Quit();
 return 0;
}

canonical_original_code:
int main(int argc, char *args[]) {
 srand(time(((void *)0)));
 init_map(&map, 20, 20);
 generate_map(&map, 1);
 SDL_Init(0x0000FFFF);
 screen = SDL_SetVideoMode(20 * map.width, 20 * map.height, 32, 0x00000000);
 load_images();
 short quit = 0;
 while (!quit) {
  while (SDL_PollEvent(&event)) {
   if (event.type == SDL_QUIT || event.key.keysym.sym == SDLK_ESCAPE || event.key.keysym.sym == SDLK_RETURN) {
    quit = 1;
   }
  }
  for (int i = 0; i < map.width * map.height; i++) {
  }
  image_draw_test();
  SDL_Flip(screen);
 }
 free_images();
 free_map(&map);
 SDL_Quit();
 return 0;
}

variable_types:
args
char *[]

variable_types: quit short

variable_types: i int


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

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

original_code:
void free_map(struct Map *map) {
 free(map->tiles);
}

variable_types: struct Map { struct Tile { unsigned char x; unsigned char y; short type; short direction; } *tiles; unsigned char height; } *

user_defined_types: struct Map { struct Tile *tiles; unsigned char height; }


decompiled_code:
__int64 __fastcall get_tile(__int64 a1, unsigned __int8 a2, unsigned __int8 a3)
{
return *(_QWORD *)a1 + 6LL * (a2 + a3 * *(unsigned __int8 *)(a1 + 9));
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, unsigned __int8 a2, unsigned __int8 a3)
{
return *(_QWORD *)a1 + 6LL * (a2 + a3 * *(unsigned __int8 *)(a1 + 9));
}

original_code:
struct Tile *get_tile(struct Map *map, uint8_t x, uint8_t y) {
 return map->tiles + ((y * map->width) + x);
}

canonical_original_code:
struct Tile *get_tile(struct Map *map, unsigned char x, unsigned char y) {
 return map->tiles + ((y * map->width) + x);
}

variable_types: struct Map { struct Tile *tiles; unsigned char height; } *

variable_types:
x
unsigned char

variable_types:
y
unsigned char

return_type: struct Tile { unsigned char x; unsigned char y; short type; short direction; } *