errorMsg

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

va_start(arg, format);
pthread_mutex_lock(&g_mIO);
vfprintf(stderr, format, arg);
if ( l_logFile )
{
va_end(arg);
va_start(arg, format);
vfprintf(l_logFile, format, arg);
}
return pthread_mutex_unlock(&g_mIO);
}

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

va_start(arg, format);
pthread_mutex_lock(&g_mIO);
vfprintf(stderr, format, arg);
if ( l_logFile )
{
va_end(arg);
va_start(arg, format);
vfprintf(l_logFile, format, arg);
}
return pthread_mutex_unlock(&g_mIO);
}

original_code:
void errorMsg(char *fmt, ...)
{
  va_list arg_ptr;
  __builtin_va_start(arg_ptr,fmt);
  pthread_mutex_lock( &g_mIO);
  vfprintf(stderr,fmt,arg_ptr);
  if (((void *)0) != l_logFile)
  {
     __builtin_va_start(arg_ptr,fmt);
     vfprintf(l_logFile,fmt,arg_ptr);
  }
  pthread_mutex_unlock( &g_mIO);
  __builtin_va_end(arg_ptr);
}

canonical_original_code:
void errorMsg(char *fmt, ...)
{
  __builtin_va_list arg_ptr;
  __builtin_va_start(arg_ptr,fmt);
  pthread_mutex_lock( &g_mIO);
  vfprintf(stderr,fmt,arg_ptr);
  if (((void *)0) != l_logFile)
  {
     __builtin_va_start(arg_ptr,fmt);
     vfprintf(l_logFile,fmt,arg_ptr);
  }
  pthread_mutex_unlock( &g_mIO);
  __builtin_va_end(arg_ptr);
}

variable_types:
fmt
char *


unblockedMessage

repo: mtentukov/LameWavEncoder

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

va_start(arg, format);
result = vfprintf(stdout, format, arg);
if ( l_logFile )
{
va_end(arg);
va_start(arg, format);
result = vfprintf(l_logFile, format, arg);
}
return result;
}

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

va_start(arg, format);
result = vfprintf(stdout, format, arg);
if ( l_logFile )
{
va_end(arg);
va_start(arg, format);
result = vfprintf(l_logFile, format, arg);
}
return result;
}

original_code:
void unblockedMessage(char *fmt, ...)
{
  va_list arg_ptr;
  __builtin_va_start(arg_ptr,fmt);
  vfprintf(stdout,fmt,arg_ptr);
  if (((void *)0) != l_logFile)
  {
     __builtin_va_start(arg_ptr,fmt);
     vfprintf(l_logFile,fmt,arg_ptr);
  }
  __builtin_va_end(arg_ptr);
}

canonical_original_code:
void unblockedMessage(char *fmt, ...)
{
  __builtin_va_list arg_ptr;
  __builtin_va_start(arg_ptr,fmt);
  vfprintf(stdout,fmt,arg_ptr);
  if (((void *)0) != l_logFile)
  {
     __builtin_va_start(arg_ptr,fmt);
     vfprintf(l_logFile,fmt,arg_ptr);
  }
  __builtin_va_end(arg_ptr);
}

return_type: void


message

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

va_start(arg, format);
pthread_mutex_lock(&g_mIO);
vfprintf(stdout, format, arg);
if ( l_logFile )
{
va_end(arg);
va_start(arg, format);
vfprintf(l_logFile, format, arg);
}
return pthread_mutex_unlock(&g_mIO);
}

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

va_start(arg, format);
pthread_mutex_lock(&g_mIO);
vfprintf(stdout, format, arg);
if ( l_logFile )
{
va_end(arg);
va_start(arg, format);
vfprintf(l_logFile, format, arg);
}
return pthread_mutex_unlock(&g_mIO);
}

original_code:
void message(char *fmt, ...)
{
  va_list arg_ptr;
  __builtin_va_start(arg_ptr,fmt);
  pthread_mutex_lock( &g_mIO);
  vfprintf(stdout,fmt,arg_ptr);
  if (((void *)0) != l_logFile)
  {
     __builtin_va_start(arg_ptr,fmt);
     vfprintf(l_logFile,fmt,arg_ptr);
  }
  pthread_mutex_unlock( &g_mIO);
  __builtin_va_end(arg_ptr);
}

canonical_original_code:
void message(char *fmt, ...)
{
  __builtin_va_list arg_ptr;
  __builtin_va_start(arg_ptr,fmt);
  pthread_mutex_lock( &g_mIO);
  vfprintf(stdout,fmt,arg_ptr);
  if (((void *)0) != l_logFile)
  {
     __builtin_va_start(arg_ptr,fmt);
     vfprintf(l_logFile,fmt,arg_ptr);
  }
  pthread_mutex_unlock( &g_mIO);
  __builtin_va_end(arg_ptr);
}


blockMessage

decompiled_code:
int blockMessage()
{
return pthread_mutex_lock(&g_mIO);
}

canonical_decompiled_code:
int func5()
{
return pthread_mutex_lock(&g_mIO);
}

original_code:
void blockMessage(void)
{
  pthread_mutex_lock (&g_mIO);
}

canonical_original_code:
void blockMessage()
{
  pthread_mutex_lock (&g_mIO);
}


unblockMessage

decompiled_code:
int unblockMessage()
{
return pthread_mutex_unlock(&g_mIO);
}

canonical_decompiled_code:
int func6()
{
return pthread_mutex_unlock(&g_mIO);
}

original_code:
void unblockMessage(void)
{
  pthread_mutex_unlock (&g_mIO);
}

canonical_original_code:
void unblockMessage()
{
  pthread_mutex_unlock (&g_mIO);
}


halt

decompiled_code:
void __noreturn halt(int status, char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, format);
pthread_mutex_lock(&g_mIO);
vfprintf(stderr, format, arg);
if ( l_logFile )
{
va_end(arg);
va_start(arg, format);
vfprintf(l_logFile, format, arg);
}
pthread_mutex_unlock(&g_mIO);
exit(status);
}

canonical_decompiled_code:
void __noreturn func7(int status, char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, format);
pthread_mutex_lock(&g_mIO);
vfprintf(stderr, format, arg);
if ( l_logFile )
{
va_end(arg);
va_start(arg, format);
vfprintf(l_logFile, format, arg);
}
pthread_mutex_unlock(&g_mIO);
exit(status);
}

original_code:
void halt(int retval,char *fmt, ...)
{
  va_list arg_ptr;
  __builtin_va_start(arg_ptr,fmt);
  pthread_mutex_lock( &g_mIO);
  vfprintf(stderr,fmt,arg_ptr);
 if (((void *)0) != l_logFile)
  {
     __builtin_va_start(arg_ptr,fmt);
     vfprintf(l_logFile,fmt,arg_ptr);
  }
  __builtin_va_end(arg_ptr);
  pthread_mutex_unlock( &g_mIO);
  exit(retval);
}

canonical_original_code:
void halt(int retval, char *fmt, ...)
{
  __builtin_va_list arg_ptr;
  __builtin_va_start(arg_ptr,fmt);
  pthread_mutex_lock( &g_mIO);
  vfprintf(stderr,fmt,arg_ptr);
 if (((void *)0) != l_logFile)
  {
     __builtin_va_start(arg_ptr,fmt);
     vfprintf(l_logFile,fmt,arg_ptr);
  }
  __builtin_va_end(arg_ptr);
  pthread_mutex_unlock( &g_mIO);
  exit(retval);
}

variable_types: retval int


main

canonical_name: main

repo: mtippett/LEDSign

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er14
void *v4; // r12
int v6; // er15
int v7; // eax
__int64 v8; // rsi
size_t v9; // r15
unsigned int v10; // er13
bool v11; // cf
bool v12; // zf
int v13; // eax
const char *v14; // rdi
__int64 v15; // rcx
const char *v16; // rsi
unsigned int v17; // ebp
__int64 v18; // rbx
const char *v19; // r12
size_t v20; // rax
__int64 v21; // rsi
char *src; // [rsp+8h] [rbp-B0h]
unsigned int srca; // [rsp+8h] [rbp-B0h]
int longind[2]; // [rsp+10h] [rbp-A8h] BYREF
struct termios timer[2]; // [rsp+40h] [rbp-78h] BYREF

v3 = 0;
v4 = 0LL;
while ( 1 )
{
v6 = optind;
longind[0] = 0;
if ( !optind )
v6 = 1;
v7 = getopt_long(argc, (char *const *)argv, "t:d:0:1:2:3:4:5:6:", &long_options_0, longind);
v8 = (unsigned int)v7;
if ( v7 == -1 )
break;
if ( v7 == 100 )
{
printf("option device with option %s\n", optarg);
src = optarg;
v9 = strlen(optarg);
v4 = malloc(v9);
memcpy(v4, src, v9 + 1);
}
else if ( v7 > 100 )
{
if ( v7 != 116 )
goto LABEL_9;
if ( optarg )
{
date = (__int64)getdate(optarg);
if ( !date )
{
printf("Invalid date string \"%s\" code %d\n", optarg, (unsigned int)getdate_err);
exit(1);
}
}
else
{
*(_QWORD *)&timer[0].c_iflag = time(0LL);
date = (__int64)localtime((const time_t *)timer);
}
printf("Time f %s\n", optarg);
}
else if ( v7 > 54 )
{
if ( v7 != 63 )
LABEL_9:
printf("?? getopt returned character code 0%o ??\n", (unsigned int)v7);
}
else
{
if ( v7 <= 47 )
goto LABEL_9;
if ( v3 )
{
if ( v3 != v6 )
{
srca = v7;
puts("digits occur in two different argv-elements.");
v8 = srca;
}
}
v3 = v6;
printf("option %c,%s\n", v8, optarg);
}
}
v10 = 0;
if ( optind < argc )
{
v10 = argc - optind;
memcpy(longind, &argv[optind], 8LL * (unsigned int)(argc + ~optind) + 8);
optind = argc;
printf("message_count %d\n", v10);
}
if ( !v4 )
{
puts("Device name must be specified with -d or --device");
exit(-1);
}
printf("Opening file %s\n", (const char *)v4);
v13 = open((const char *)v4, 3394);
v14 = "/dev/";
v15 = 5LL;
v16 = (const char *)v4;
do
{
if ( !v15 )
break;
v11 = *v16 < (unsigned int)*v14;
v12 = *v16++ == *v14++;
--v15;
}
while ( v12 );
v17 = v13;
if ( (!v11 && !v12) == v11 )
{
puts("Assuming tty semantics");
tcgetattr(v17, timer);
cfsetspeed(timer, 0xFu);
v16 = 0LL;
tcsetattr(v17, 0, timer);
}
puts("Attention");
sign_proto_attention(v17, v16);
usleep(0x186A0u);
if ( v10 )
{
v18 = 0LL;
do
{
v19 = *(const char **)&longind[2 * v18];
printf("Write buffer %d with %s\n", (unsigned int)v18, v19);
v20 = strlen(v19);
v21 = (unsigned int)v18++;
sign_proto_write_buffer(v17, v21, v19, v20, 53LL, 66LL);
usleep(0x15F90u);
}
while ( (int)v10 > (int)v18 );
}
puts("Activate");
sign_proto_activate(v17, v10);
usleep(0x15F90u);
if ( date )
{
puts("Set Time");
sign_proto_set_time(v17, date);
usleep(0x15F90u);
}
puts("Close");
close(v17);
return 0;
}

original_code:
int main(int argc, char **argv) {
    int testfile;
    struct termios term;
    char *device_name = ((void *)0);
    char *my_string;
    char *messages[6];
    int message_count = 0;
    int c;
    int digit_optind = 0;
    my_string = (char *) malloc(250);
    while (1) {
               int this_option_optind = optind ? optind : 1;
               int option_index = 0;
               static struct option long_options[] = {
                   {"device", 1, ((void *)0), 'd'},
                   {"time", 2, ((void *)0), 't'},
                   {0, 0, 0, 0}
               };
               c = getopt_long(argc, argv, "t:d:0:1:2:3:4:5:6:",
                        long_options, &option_index);
               if (c == -1)
                   break;
               switch (c) {
               case '0':
               case '1':
               case '2':
               case '3':
               case '4':
               case '5':
               case '6':
                   if (digit_optind != 0 && digit_optind != this_option_optind)
                     printf("digits occur in two different argv-elements.\n");
                   digit_optind = this_option_optind;
                   printf("option %c,%s\n", c, optarg);
                   break;
               case 'd':
                   printf("option device with option %s\n", optarg);
            device_name = malloc(strlen(optarg));
     strcpy(device_name, optarg);
                   break;
               case 't':
     if (optarg != ((void *)0)) {
   date = getdate(optarg);
   if (date == ((void *)0)) {
    printf("Invalid date string \"%s\" code %d\n",optarg,getdate_err);
    exit(1);
   }
     } else {
          time_t current_time;
          current_time = time(((void *)0));
          date = localtime(&current_time);
            }
                   printf("Time f %s\n", optarg);
                   break;
               case '?':
                   break;
               default:
                   printf("?? getopt returned character code 0%o ??\n", c);
               }
           }
    if (optind < argc) {
        while (optind < argc) {
  messages[message_count] = argv[optind];
  message_count++;
  optind++;
 }
        printf("message_count %d\n", message_count);
    }
    if(device_name == ((void *)0)) {
 printf("Device name must be specified with -d or --device\n");
 exit(-1);
    }
    printf("Opening file %s\n", device_name);
    testfile = open(device_name, 02 | 0400 | 0100| 04000|02000);
    if(strstr(device_name, "/dev/") == device_name) {
     printf("Assuming tty semantics\n");
     tcgetattr(testfile, &term);
 cfsetspeed(&term,0000017);
 tcsetattr(testfile,0,&term);
    }
    printf("Attention\n");
    sign_proto_attention(testfile);
    usleep(100000);
    for( c= 0; c < message_count; c++ ) {
     printf("Write buffer %d with %s\n", c, messages[c]);
        sign_proto_write_buffer(testfile, c, messages[c], strlen(messages[c]), 0x35, 0x42);
        usleep(90000);
    }
    printf("Activate\n");
    sign_proto_activate(testfile,c);
    usleep(90000);
    if (date != ((void *)0)) {
 printf("Set Time\n");
 sign_proto_set_time(testfile, date);
     usleep(90000);
    }
    printf("Close\n");
    close(testfile);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
    int testfile;
    struct termios term;
    char *device_name = ((void *)0);
    char *my_string;
    char *messages[6];
    int message_count = 0;
    int c;
    int digit_optind = 0;
    my_string = (char *) malloc(250);
    while (1) {
               int this_option_optind = optind ? optind : 1;
               int option_index = 0;
               static struct option long_options[] = {
                   {"device", 1, ((void *)0), 'd'},
                   {"time", 2, ((void *)0), 't'},
                   {0, 0, 0, 0}
               };
               c = getopt_long(argc, argv, "t:d:0:1:2:3:4:5:6:",
                        long_options, &option_index);
               if (c == -1)
                   break;
               switch (c) {
               case '0':
               case '1':
               case '2':
               case '3':
               case '4':
               case '5':
               case '6':
                   if (digit_optind != 0 && digit_optind != this_option_optind)
                     printf("digits occur in two different argv-elements.\n");
                   digit_optind = this_option_optind;
                   printf("option %c,%s\n", c, optarg);
                   break;
               case 'd':
                   printf("option device with option %s\n", optarg);
            device_name = malloc(strlen(optarg));
     strcpy(device_name, optarg);
                   break;
               case 't':
     if (optarg != ((void *)0)) {
   date = getdate(optarg);
   if (date == ((void *)0)) {
    printf("Invalid date string \"%s\" code %d\n",optarg,getdate_err);
    exit(1);
   }
     } else {
          long current_time;
          current_time = time(((void *)0));
          date = localtime(&current_time);
            }
                   printf("Time f %s\n", optarg);
                   break;
               case '?':
                   break;
               default:
                   printf("?? getopt returned character code 0%o ??\n", c);
               }
           }
    if (optind < argc) {
        while (optind < argc) {
  messages[message_count] = argv[optind];
  message_count++;
  optind++;
 }
        printf("message_count %d\n", message_count);
    }
    if(device_name == ((void *)0)) {
 printf("Device name must be specified with -d or --device\n");
 exit(-1);
    }
    printf("Opening file %s\n", device_name);
    testfile = open(device_name, 02 | 0400 | 0100| 04000|02000);
    if(strstr(device_name, "/dev/") == device_name) {
     printf("Assuming tty semantics\n");
     tcgetattr(testfile, &term);
 cfsetspeed(&term,0000017);
 tcsetattr(testfile,0,&term);
    }
    printf("Attention\n");
    sign_proto_attention(testfile);
    usleep(100000);
    for( c= 0; c < message_count; c++ ) {
     printf("Write buffer %d with %s\n", c, messages[c]);
        sign_proto_write_buffer(testfile, c, messages[c], strlen(messages[c]), 0x35, 0x42);
        usleep(90000);
    }
    printf("Activate\n");
    sign_proto_activate(testfile,c);
    usleep(90000);
    if (date != ((void *)0)) {
 printf("Set Time\n");
 sign_proto_set_time(testfile, date);
     usleep(90000);
    }
    printf("Close\n");
    close(testfile);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: testfile int

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

variable_types:
messages
char *[6]

variable_types: c int

variable_types: struct option { char *name; int has_arg; int *flag; int val; } []

return_type: int


repo: mtottenh/IMPS

decompiled_code:
void __fastcall symbol_table_free_aux(void ***a1)
{
void **v2; // rdi

v2 = *a1;
if ( v2 )
{
symbol_table_free_aux(v2 + 2);
free(**a1);
free(*a1);
*a1 = 0LL;
}
}

canonical_decompiled_code:
void __fastcall func0(void ***a1)
{
void **v2; // rdi

v2 = *a1;
if ( v2 )
{
func0(v2 + 2);
free(**a1);
free(*a1);
*a1 = 0LL;
}
}

original_code:
static void symbol_table_free_aux(Symbol_Table_Entry **entry_ptr) {
 if(*entry_ptr != ((void *)0)) {
  symbol_table_free_aux(&((*entry_ptr)->next));
  free((*entry_ptr)->key);
  (*entry_ptr)->key = ((void *)0);
  free(*entry_ptr);
  *entry_ptr = ((void *)0);
 }
}

canonical_original_code:
static void symbol_table_free_aux(struct Symbol_Table_Entry **entry_ptr) {
 if(*entry_ptr != ((void *)0)) {
  symbol_table_free_aux(&((*entry_ptr)->next));
  free((*entry_ptr)->key);
  (*entry_ptr)->key = ((void *)0);
  free(*entry_ptr);
  *entry_ptr = ((void *)0);
 }
}

variable_types: struct Symbol_Table_Entry { char *key; unsigned short value; struct Symbol_Table_Entry *next; } **


decompiled_code:
void __fastcall symbol_table_free(void ****a1)
{
symbol_table_free_aux(*a1);
free(*a1);
*a1 = 0LL;
}

canonical_decompiled_code:
void __fastcall func2(void ****a1)
{
func0(*a1);
free(*a1);
*a1 = 0LL;
}

original_code:
void symbol_table_free(Symbol_Table **entry_ptr) {
 symbol_table_free_aux(&((*entry_ptr)->head));
 free(*entry_ptr);
 *entry_ptr = ((void *)0);
}

canonical_original_code:
void symbol_table_free(struct Symbol_Table **entry_ptr) {
 symbol_table_free_aux(&((*entry_ptr)->head));
 free(*entry_ptr);
 *entry_ptr = ((void *)0);
}

variable_types: struct Symbol_Table { struct Symbol_Table_Entry { char *key; unsigned short value; struct Symbol_Table_Entry *next; } *head; } **

user_defined_types: struct Symbol_Table { struct Symbol_Table_Entry *head; }


decompiled_code:
__int64 __fastcall symbol_table_getLength(__int64 a1)
{
__int64 v1; // r8
__int64 i; // rax

if ( !a1 )
return -1LL;
v1 = 0LL;
for ( i = *(_QWORD *)(*(_QWORD *)a1 + 16LL); i; ++v1 )
i = *(_QWORD *)(i + 16);
return v1;
}

original_code:
size_t symbol_table_getLength(Symbol_Table *table) {
 if (table == ((void *)0)) {
  return -1;
 }
 size_t counter = 0;
 for(Symbol_Table_Entry *i = table->head; i->next != ((void *)0); i=i->next) {
  counter++;
 }
 return counter;
}

canonical_original_code:
unsigned long symbol_table_getLength(struct Symbol_Table *table) {
 if (table == ((void *)0)) {
  return -1;
 }
 unsigned long counter = 0;
 for(struct Symbol_Table_Entry *i = table->head; i->next != ((void *)0); i=i->next) {
  counter++;
 }
 return counter;
}

variable_types: struct Symbol_Table { struct Symbol_Table_Entry { char *key; unsigned short value; struct Symbol_Table_Entry *next; } *head; } *

variable_types:
counter
unsigned long

return_type: unsigned long


decompiled_code:
__int64 __fastcall symbol_table_put(__int64 *a1, const char *a2, __int16 a3)
{
__int64 v4; // rbp
__int64 v5; // rdx
__int64 v6; // rax
__int64 v7; // rbx
bool v8; // zf
size_t v9; // rax
char **v10; // rbx
char *v11; // rax
char *v12; // r14
size_t v13; // rax
char **v14; // rax
__int64 result; // rax
void *v16; // rax

v4 = (__int64)a1;
v5 = *a1;
if ( *a1 )
{
v6 = *(_QWORD *)(v5 + 16);
v7 = *a1;
if ( v6 )
{
while ( 1 )
{
v7 = v6;
v6 = *(_QWORD *)(v6 + 16);
if ( !v6 )
break;
v5 = v7;
}
v4 = v5 + 16;
}
*(_QWORD *)(v7 + 16) = malloc(0x18uLL);
v8 = *(_QWORD *)(*(_QWORD *)v4 + 16LL) == 0LL;
v4 = *(_QWORD *)v4 + 16LL;
if ( v8 )
{
perror("malloc'ing space for i->next");
return 1LL;
}
}
else
{
v16 = malloc(0x18uLL);
*a1 = (__int64)v16;
if ( !v16 )
{
perror("Error malloc'ing in emptry table");
return 1LL;
}
}
v9 = strlen(a2);
v10 = *(char ***)v4;
v11 = (char *)malloc(v9);
*v10 = v11;
v12 = v11;
if ( v11 )
{
v13 = strlen(a2);
strncpy(v12, a2, v13);
v14 = *(char ***)v4;
*((_WORD *)v14 + 4) = a3;
v14[2] = 0LL;
result = 0LL;
}
else
{
perror("malloc'ing space for key");
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 *a1, const char *a2, __int16 a3)
{
__int64 v4; // rbp
__int64 v5; // rdx
__int64 v6; // rax
__int64 v7; // rbx
bool v8; // zf
size_t v9; // rax
char **v10; // rbx
char *v11; // rax
char *v12; // r14
size_t v13; // rax
char **v14; // rax
__int64 result; // rax
void *v16; // rax

v4 = (__int64)a1;
v5 = *a1;
if ( *a1 )
{
v6 = *(_QWORD *)(v5 + 16);
v7 = *a1;
if ( v6 )
{
while ( 1 )
{
v7 = v6;
v6 = *(_QWORD *)(v6 + 16);
if ( !v6 )
break;
v5 = v7;
}
v4 = v5 + 16;
}
*(_QWORD *)(v7 + 16) = malloc(0x18uLL);
v8 = *(_QWORD *)(*(_QWORD *)v4 + 16LL) == 0LL;
v4 = *(_QWORD *)v4 + 16LL;
if ( v8 )
{
perror("malloc'ing space for i->next");
return 1LL;
}
}
else
{
v16 = malloc(0x18uLL);
*a1 = (__int64)v16;
if ( !v16 )
{
perror("Error malloc'ing in emptry table");
return 1LL;
}
}
v9 = strlen(a2);
v10 = *(char ***)v4;
v11 = (char *)malloc(v9);
*v10 = v11;
v12 = v11;
if ( v11 )
{
v13 = strlen(a2);
strncpy(v12, a2, v13);
v14 = *(char ***)v4;
*((_WORD *)v14 + 4) = a3;
v14[2] = 0LL;
result = 0LL;
}
else
{
perror("malloc'ing space for key");
result = 1LL;
}
return result;
}

original_code:
int symbol_table_put(Symbol_Table* table, Key key, Value value) {
 Symbol_Table_Entry **entry_ptr = &(table->head);
 if ((*entry_ptr) == ((void *)0) ) {
  (*entry_ptr) = malloc(sizeof(Symbol_Table_Entry));
  if ((*entry_ptr) == ((void *)0)) {
   perror("Error malloc'ing in emptry table");
   return 1;
  }
 } else {
  while((*entry_ptr)->next != ((void *)0)) {
    entry_ptr = &((*entry_ptr)->next);
  }
  (*entry_ptr)->next = malloc(sizeof(Symbol_Table_Entry));
  if ((*entry_ptr)->next == ((void *)0)) {
   perror("malloc'ing space for i->next");
   return 1;
  }
  entry_ptr = &((*entry_ptr)->next);
 }
 (*entry_ptr)->key = malloc(strlen(key));
 if ((*entry_ptr)->key == ((void *)0)) {
  perror("malloc'ing space for key");
  return 1;
 }
 strncpy((*entry_ptr)->key, key, strlen(key));
 (*entry_ptr)->value = value;
 (*entry_ptr)->next = ((void *)0);
 return 0;
}

canonical_original_code:
int symbol_table_put(struct Symbol_Table *table, char *key, unsigned short value) {
 struct Symbol_Table_Entry **entry_ptr = &(table->head);
 if ((*entry_ptr) == ((void *)0) ) {
  (*entry_ptr) = malloc(sizeof(Symbol_Table_Entry));
  if ((*entry_ptr) == ((void *)0)) {
   perror("Error malloc'ing in emptry table");
   return 1;
  }
 } else {
  while((*entry_ptr)->next != ((void *)0)) {
    entry_ptr = &((*entry_ptr)->next);
  }
  (*entry_ptr)->next = malloc(sizeof(Symbol_Table_Entry));
  if ((*entry_ptr)->next == ((void *)0)) {
   perror("malloc'ing space for i->next");
   return 1;
  }
  entry_ptr = &((*entry_ptr)->next);
 }
 (*entry_ptr)->key = malloc(strlen(key));
 if ((*entry_ptr)->key == ((void *)0)) {
  perror("malloc'ing space for key");
  return 1;
 }
 strncpy((*entry_ptr)->key, key, strlen(key));
 (*entry_ptr)->value = value;
 (*entry_ptr)->next = ((void *)0);
 return 0;
}

variable_types:
key
char *

variable_types:
value
unsigned short

user_defined_types: struct Symbol_Table_Entry { char *key; unsigned short value; struct Symbol_Table_Entry *next; }


decompiled_code:
__int64 *symbol_table_new()
{
__int64 *v0; // r12

v0 = (__int64 *)malloc(8uLL);
symbol_table_put(v0, "halt", 0);
symbol_table_put(v0, "add", 1);
symbol_table_put(v0, "addi", 2);
symbol_table_put(v0, "sub", 3);
symbol_table_put(v0, "subi", 4);
symbol_table_put(v0, "mul", 5);
symbol_table_put(v0, "muli", 6);
symbol_table_put(v0, "lw", 7);
symbol_table_put(v0, "sw", 8);
symbol_table_put(v0, "beq", 9);
symbol_table_put(v0, "bne", 10);
symbol_table_put(v0, "blt", 11);
symbol_table_put(v0, "bgt", 12);
symbol_table_put(v0, "ble", 13);
symbol_table_put(v0, "bge", 14);
symbol_table_put(v0, "jmp", 15);
symbol_table_put(v0, "jr", 16);
symbol_table_put(v0, "jal", 17);
symbol_table_put(v0, "out", 18);
symbol_table_put(v0, ".fill", 19);
symbol_table_put(v0, ".skip", 20);
symbol_table_put(v0, "push", 21);
symbol_table_put(v0, "pop", 22);
symbol_table_put(v0, "call", 23);
symbol_table_put(v0, "ret", 24);
symbol_table_put(v0, "mov", 25);
symbol_table_put(v0, "inc", 26);
return v0;
}

original_code:
Symbol_Table* symbol_table_new(void) {
 Symbol_Table* s = malloc(sizeof(Symbol_Table));
 symbol_table_put(s, "halt", HALT);
 symbol_table_put(s, "add", ADD);
 symbol_table_put(s, "addi", ADDI);
 symbol_table_put(s, "sub", SUB);
 symbol_table_put(s, "subi", SUBI);
 symbol_table_put(s, "mul", MUL);
 symbol_table_put(s, "muli", MULI);
 symbol_table_put(s, "lw", LW);
 symbol_table_put(s, "sw", SW);
 symbol_table_put(s, "beq", BEQ);
 symbol_table_put(s, "bne", BNE);
 symbol_table_put(s, "blt", BLT);
 symbol_table_put(s, "bgt", BGT);
 symbol_table_put(s, "ble", BLE);
 symbol_table_put(s, "bge", BGE);
 symbol_table_put(s, "jmp", JMP);
 symbol_table_put(s, "jr", JR);
 symbol_table_put(s, "jal", JAL);
 symbol_table_put(s, "out", OUT);
 symbol_table_put(s, ".fill", FILL);
 symbol_table_put(s, ".skip", SKIP);
 symbol_table_put(s, "push", PUSH);
 symbol_table_put(s, "pop", POP);
 symbol_table_put(s, "call", CALL);
 symbol_table_put(s, "ret", RET);
 symbol_table_put(s, "mov", MOV);
 symbol_table_put(s, "inc", INC);
 return s;
}

canonical_original_code:
struct Symbol_Table *symbol_table_new() {
 struct Symbol_Table *s = malloc(sizeof(Symbol_Table));
 symbol_table_put(s, "halt", HALT);
 symbol_table_put(s, "add", ADD);
 symbol_table_put(s, "addi", ADDI);
 symbol_table_put(s, "sub", SUB);
 symbol_table_put(s, "subi", SUBI);
 symbol_table_put(s, "mul", MUL);
 symbol_table_put(s, "muli", MULI);
 symbol_table_put(s, "lw", LW);
 symbol_table_put(s, "sw", SW);
 symbol_table_put(s, "beq", BEQ);
 symbol_table_put(s, "bne", BNE);
 symbol_table_put(s, "blt", BLT);
 symbol_table_put(s, "bgt", BGT);
 symbol_table_put(s, "ble", BLE);
 symbol_table_put(s, "bge", BGE);
 symbol_table_put(s, "jmp", JMP);
 symbol_table_put(s, "jr", JR);
 symbol_table_put(s, "jal", JAL);
 symbol_table_put(s, "out", OUT);
 symbol_table_put(s, ".fill", FILL);
 symbol_table_put(s, ".skip", SKIP);
 symbol_table_put(s, "push", PUSH);
 symbol_table_put(s, "pop", POP);
 symbol_table_put(s, "call", CALL);
 symbol_table_put(s, "ret", RET);
 symbol_table_put(s, "mov", MOV);
 symbol_table_put(s, "inc", INC);
 return s;
}

return_type: struct Symbol_Table { struct Symbol_Table_Entry { char *key; unsigned short value; struct Symbol_Table_Entry *next; } *head; } *


decompiled_code:
int __fastcall symbol_table_contains(__int64 *a1, const char *a2)
{
__int64 i; // rbx
int result; // eax

for ( i = *a1; ; i = *(_QWORD *)(i + 16) )
{
result = strcmp(*(const char **)i, a2);
if ( !result )
break;
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(__int64 *a1, const char *a2)
{
__int64 i; // rbx
int result; // eax

for ( i = *a1; ; i = *(_QWORD *)(i + 16) )
{
result = strcmp(*(const char **)i, a2);
if ( !result )
break;
}
return result;
}

original_code:
int symbol_table_contains(Symbol_Table* table, Key key) {
 Symbol_Table_Entry *s = table->head;
 while ((strcmp(s->key, key) != 0) && s != ((void *)0)) {
  s = s->next;
 }
 return s == ((void *)0) ? 1 : 0;
}

canonical_original_code:
int symbol_table_contains(struct Symbol_Table *table, char *key) {
 struct Symbol_Table_Entry *s = table->head;
 while ((strcmp(s->key, key) != 0) && s != ((void *)0)) {
  s = s->next;
 }
 return s == ((void *)0) ? 1 : 0;
}

variable_types: struct Symbol_Table_Entry { char *key; unsigned short value; struct Symbol_Table_Entry *next; } *


decompiled_code:
__int64 __fastcall symbol_table_get(__int64 *a1, const char *a2)
{
__int64 i; // r12

for ( i = *a1; i; i = *(_QWORD *)(i + 16) )
{
if ( !strcmp(*(const char **)i, a2) )
break;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 *a1, const char *a2)
{
__int64 i; // r12

for ( i = *a1; i; i = *(_QWORD *)(i + 16) )
{
if ( !strcmp(*(const char **)i, a2) )
break;
}
return i;
}

original_code:
Symbol_Table_Entry* symbol_table_get(Symbol_Table* table, Key key) {
 Symbol_Table_Entry *entry_ptr = table->head;
 while((entry_ptr != ((void *)0)) && (strcmp(entry_ptr->key, key) !=0)) {
  entry_ptr = entry_ptr->next;
 }
 return entry_ptr;
}

canonical_original_code:
struct Symbol_Table_Entry *symbol_table_get(struct Symbol_Table *table, char *key) {
 struct Symbol_Table_Entry *entry_ptr = table->head;
 while((entry_ptr != ((void *)0)) && (strcmp(entry_ptr->key, key) !=0)) {
  entry_ptr = entry_ptr->next;
 }
 return entry_ptr;
}

variable_types: struct Symbol_Table { struct Symbol_Table_Entry *head; } *

return_type: struct Symbol_Table_Entry { char *key; unsigned short value; struct Symbol_Table_Entry *next; } *


decompiled_code:
__int64 __fastcall symbol_table_remove(__int64 *a1, const char *a2)
{
__int64 v2; // rbp
const char **v3; // rax

v2 = symbol_table_get(a1, a2);
v3 = symbol_table_getprev_isra_0((const char **)*a1, a2);
if ( v3 )
v3[2] = *(const char **)(v2 + 16);
else
*a1 = *(_QWORD *)(v2 + 16);
free(*(void **)v2);
free((void *)v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 *a1, const char *a2)
{
__int64 v2; // rbp
const char **v3; // rax

v2 = func7(a1, a2);
v3 = func1((const char **)*a1, a2);
if ( v3 )
v3[2] = *(const char **)(v2 + 16);
else
*a1 = *(_QWORD *)(v2 + 16);
free(*(void **)v2);
free((void *)v2);
return 0LL;
}

original_code:
int symbol_table_remove(Symbol_Table* table, Key key) {
 Symbol_Table_Entry *current = symbol_table_get(table,key);
 Symbol_Table_Entry *prev = symbol_table_getprev(table,key);
 if (prev == ((void *)0)) {
  table->head = current->next;
 } else {
  prev->next = current->next;
 }
 free(current->key);
 free(current);
 current = ((void *)0);
 return 0;
}

canonical_original_code:
int symbol_table_remove(struct Symbol_Table *table, char *key) {
 struct Symbol_Table_Entry *current = symbol_table_get(table,key);
 struct Symbol_Table_Entry *prev = symbol_table_getprev(table,key);
 if (prev == ((void *)0)) {
  table->head = current->next;
 } else {
  prev->next = current->next;
 }
 free(current->key);
 free(current);
 current = ((void *)0);
 return 0;
}


decompiled_code:
int __fastcall symbol_table_print(__int64 *a1)
{
__int64 i; // rbx
int result; // eax

if ( !a1 )
return fwrite("Erorr: Not a valid symbol table,please call symbol_table_new()\n", 1uLL, 0x3FuLL, stderr);
for ( i = *a1; i; i = *(_QWORD *)(i + 16) )
result = printf("Key: %s\t Value: %d\n", *(const char **)i, *(unsigned __int16 *)(i + 8));
return result;
}

canonical_decompiled_code:
int __fastcall func9(__int64 *a1)
{
__int64 i; // rbx
int result; // eax

if ( !a1 )
return fwrite("Erorr: Not a valid symbol table,please call symbol_table_new()\n", 1uLL, 0x3FuLL, stderr);
for ( i = *a1; i; i = *(_QWORD *)(i + 16) )
result = printf("Key: %s\t Value: %d\n", *(const char **)i, *(unsigned __int16 *)(i + 8));
return result;
}

original_code:
void symbol_table_print(Symbol_Table* table) {
 if (table == ((void *)0)) {
  fprintf(stderr,"Erorr: Not a valid symbol table,"
    "please call symbol_table_new()\n");
  return;
 }
 Symbol_Table_Entry *entry_ptr = table->head;
 for ( ; entry_ptr != ((void *)0); entry_ptr = entry_ptr->next) {
  printf("Key: %s\t Value: %d\n",
   entry_ptr->key, entry_ptr->value);
 }
}

canonical_original_code:
void symbol_table_print(struct Symbol_Table *table) {
 if (table == ((void *)0)) {
  fprintf(stderr,"Erorr: Not a valid symbol table,"
    "please call symbol_table_new()\n");
  return;
 }
 struct Symbol_Table_Entry *entry_ptr = table->head;
 for ( ; entry_ptr != ((void *)0); entry_ptr = entry_ptr->next) {
  printf("Key: %s\t Value: %d\n",
   entry_ptr->key, entry_ptr->value);
 }
}


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

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

original_code:
uint32_t assemble_halt(Instruction instruction) {
 return 0;
}

canonical_original_code:
unsigned int assemble_halt(struct Instruction instruction) {
 return 0;
}

variable_types: struct Instruction { unsigned int opcode; char *operand1; char *operand2; char *operand3; struct Symbol_Table { struct Symbol_Table_Entry { char *key; unsigned short value; struct Symbol_Table_Entry *next; } *head; } *table; unsigned short *address; }

return_type: unsigned int

user_defined_types: struct Instruction { unsigned int opcode; char *operand1; char *operand2; char *operand3; struct Symbol_Table *table; unsigned short *address; }


decompiled_code:
int __fastcall assemble_fill(int a1, int a2, int a3, int a4, int a5, int a6, int a7, char *nptr)
{
return atoi(nptr);
}

canonical_decompiled_code:
int __fastcall func1(int a1, int a2, int a3, int a4, int a5, int a6, int a7, char *nptr)
{
return atoi(nptr);
}

original_code:
uint32_t assemble_fill(Instruction instruction) {
 return (uint32_t) atoi(instruction.operand1);
}

canonical_original_code:
unsigned int assemble_fill(struct Instruction instruction) {
 return (unsigned int) atoi(instruction.operand1);
}


decompiled_code:
__int64 __fastcall assemble_skip(int a1, int a2, int a3, int a4, int a5, int a6, int a7, char *nptr, int a9, int a10, int a11, __int64 a12)
{
int v12; // eax

v12 = atoi(nptr);
if ( v12 > 0 )
*(_WORD *)a12 += v12;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2, int a3, int a4, int a5, int a6, int a7, char *nptr, int a9, int a10, int a11, __int64 a12)
{
int v12; // eax

v12 = atoi(nptr);
if ( v12 > 0 )
*(_WORD *)a12 += v12;
return 0LL;
}

original_code:
uint32_t assemble_skip(Instruction instruction) {
 int num_reserve = atoi(instruction.operand1);
 for(int i = 0; i < num_reserve; i++) {
  *(instruction.address) += 1;
 }
 return 0;
}

canonical_original_code:
unsigned int assemble_skip(struct Instruction instruction) {
 int num_reserve = atoi(instruction.operand1);
 for(int i = 0; i < num_reserve; i++) {
  *(instruction.address) += 1;
 }
 return 0;
}

variable_types: i int


decompiled_code:
__int64 __fastcall eval_immediate(char *nptr, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rax

result = 0LL;
if ( nptr )
{
v3 = symbol_table_get(a2, nptr);
if ( v3 )
result = *(unsigned __int16 *)(v3 + 8);
else
result = (unsigned __int16)strtol(nptr, 0LL, 0);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *nptr, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rax

result = 0LL;
if ( nptr )
{
v3 = symbol_table_get(a2, nptr);
if ( v3 )
result = *(unsigned __int16 *)(v3 + 8);
else
result = (unsigned __int16)strtol(nptr, 0LL, 0);
}
return result;
}

original_code:
uint32_t eval_immediate(char* immediate, Symbol_Table* table) {
 uint32_t result = 0;
 if (immediate == ((void *)0)) {
  return result;
 }
 Symbol_Table_Entry* label_entry = symbol_table_get(table, immediate);
 if (label_entry != ((void *)0)) {
  result = (uint32_t) label_entry->value;
 } else {
  result = (uint32_t) strtol(immediate, ((void *)0), 0);
 }
 result &= 0xFFFF;
 return result;
}

canonical_original_code:
unsigned int eval_immediate(char *immediate, struct Symbol_Table *table) {
 unsigned int result = 0;
 if (immediate == ((void *)0)) {
  return result;
 }
 struct Symbol_Table_Entry *label_entry = symbol_table_get(table, immediate);
 if (label_entry != ((void *)0)) {
  result = (unsigned int) label_entry->value;
 } else {
  result = (unsigned int) strtol(immediate, ((void *)0), 0);
 }
 result &= 0xFFFF;
 return result;
}

variable_types:
immediate
char *

variable_types:
result
unsigned int


decompiled_code:
__int64 __fastcall assemble_jtype(int a1, int a2, int a3, int a4, int a5, int a6, int a7, char *nptr, int a9, int a10, __int64 a11)
{
return (a7 << 26) | (unsigned int)eval_immediate(nptr, a11);
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1, int a2, int a3, int a4, int a5, int a6, int a7, char *nptr, int a9, int a10, __int64 a11)
{
return (a7 << 26) | (unsigned int)func5(nptr, a11);
}

original_code:
uint32_t assemble_jtype(Instruction instruction) {
 uint32_t result = instruction.opcode << (32 - 6);
 result |= eval_immediate(instruction.operand1, instruction.table);
 return result;
}

canonical_original_code:
unsigned int assemble_jtype(struct Instruction instruction) {
 unsigned int result = instruction.opcode << (32 - 6);
 result |= eval_immediate(instruction.operand1, instruction.table);
 return result;
}


decompiled_code:
int __fastcall eval_register(__int64 a1)
{
return atoi((const char *)(a1 + 1));
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1)
{
return atoi((const char *)(a1 + 1));
}

original_code:
uint32_t eval_register(char* regstring) {
 regstring++;
  return (uint32_t) atoi(regstring);
}

canonical_original_code:
unsigned int eval_register(char *regstring) {
 regstring++;
  return (unsigned int) atoi(regstring);
}

variable_types:
regstring
char *


original_code:
uint32_t assemble_rtype(Instruction instruction) {
 int shift = 32;
 uint32_t result = instruction.opcode << (shift -= 6);
 if (instruction.operand1 != ((void *)0)) {
  result |= (eval_register(instruction.operand1)
    << (shift -= 5));
 }
 if (instruction.operand2 != ((void *)0)) {
  result |= (eval_register(instruction.operand2)
    << (shift -= 5));
 }
 if (instruction.operand3 != ((void *)0)) {
  result |= (eval_register(instruction.operand3)
    << (shift -= 5));
 }
 return result;
}

canonical_original_code:
unsigned int assemble_rtype(struct Instruction instruction) {
 int shift = 32;
 unsigned int result = instruction.opcode << (shift -= 6);
 if (instruction.operand1 != ((void *)0)) {
  result |= (eval_register(instruction.operand1)
    << (shift -= 5));
 }
 if (instruction.operand2 != ((void *)0)) {
  result |= (eval_register(instruction.operand2)
    << (shift -= 5));
 }
 if (instruction.operand3 != ((void *)0)) {
  result |= (eval_register(instruction.operand3)
    << (shift -= 5));
 }
 return result;
}

variable_types: shift int


decompiled_code:
int __fastcall eval_stype(__int64 a1, char *a2, _DWORD *a3)
{
if ( !a2 )
return 0;
if ( *a2 == 36 )
return eval_register((__int64)a2);
*a3 |= 1u;
return eval_immediate(a2, a1);
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1, char *a2, _DWORD *a3)
{
if ( !a2 )
return 0;
if ( *a2 == 36 )
return func7((__int64)a2);
*a3 |= 1u;
return func5(a2, a1);
}

original_code:
uint32_t eval_stype(Symbol_Table* table, char* operand, uint32_t* flags) {
 if (operand == ((void *)0)) {
  return 0;
 }
 else if (operand[0] == '$') {
  return eval_register(operand);
 }
 else {
  *flags |= 0x1;
  return eval_immediate(operand, table);
 }
}

canonical_original_code:
unsigned int eval_stype(struct Symbol_Table *table, char *operand, unsigned int *flags) {
 if (operand == ((void *)0)) {
  return 0;
 }
 else if (operand[0] == '$') {
  return eval_register(operand);
 }
 else {
  *flags |= 0x1;
  return eval_immediate(operand, table);
 }
}

variable_types:
operand
char *

variable_types:
flags
unsigned int *


decompiled_code:
__int64 __fastcall assemble_stype(int a1, int a2, int a3, int a4, int a5, int a6, int a7, char *s, int a9, int a10, __int64 a11)
{
char *v11; // rbp
int v12; // eax
int v14[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v11 = s;
v14[0] = 0;
if ( s && *s == 91 && s[strlen(s) - 1] == 93 )
{
v14[0] = 2;
s[strlen(s + 1)] = 0;
v11 = s + 1;
}
v12 = eval_stype(a11, v11, v14);
return v12 | (unsigned int)(a7 << 26) | (v14[0] << 24);
}

original_code:
uint32_t assemble_stype(Instruction instruction) {
 int shift = 32;
 uint32_t result = instruction.opcode << (shift -= 6);
 uint32_t flags = 0x0;
 char* operand1 = instruction.operand1;
 if (operand1 != ((void *)0) && operand1[0] == '['
   && operand1[strlen(operand1) - 1] == ']') {
  flags |= 0x2;
  operand1++;
  operand1[strlen(operand1) - 1] = '\0';
 }
 uint32_t operand_value = eval_stype(instruction.table, operand1,
       &flags);
 result |= flags << (shift -= 2);
 result |= operand_value;
 return result;
}

canonical_original_code:
unsigned int assemble_stype(struct Instruction instruction) {
 int shift = 32;
 unsigned int result = instruction.opcode << (shift -= 6);
 unsigned int flags = 0x0;
 char *operand1 = instruction.operand1;
 if (operand1 != ((void *)0) && operand1[0] == '['
   && operand1[strlen(operand1) - 1] == ']') {
  flags |= 0x2;
  operand1++;
  operand1[strlen(operand1) - 1] = '\0';
 }
 unsigned int operand_value = eval_stype(instruction.table, operand1,
       &flags);
 result |= flags << (shift -= 2);
 result |= operand_value;
 return result;
}

variable_types:
flags
unsigned int


decompiled_code:
__int64 __fastcall assemble_branch(int a1, int a2, int a3, int a4, int a5, int a6, int a7, __int64 a8, __int64 a9, char *nptr, __int64 a11, __int64 a12)
{
int v12; // ebp
int v13; // ebx

v12 = eval_register(a8);
v13 = (eval_register(a9) << 16) | (v12 << 21) | (a7 << 26);
return v13 | (unsigned int)(unsigned __int16)((int)eval_immediate(nptr, a11) / 4 - *(_WORD *)a12);
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1, int a2, int a3, int a4, int a5, int a6, int a7, __int64 a8, __int64 a9, char *nptr, __int64 a11, __int64 a12)
{
int v12; // ebp
int v13; // ebx

v12 = func7(a8);
v13 = (func7(a9) << 16) | (v12 << 21) | (a7 << 26);
return v13 | (unsigned int)(unsigned __int16)((int)func5(nptr, a11) / 4 - *(_WORD *)a12);
}

original_code:
uint32_t assemble_branch(Instruction instruction) {
 int shift = 32;
 uint32_t result = instruction.opcode << (shift -= 6);
 result |= (eval_register(instruction.operand1) << (shift -= 5));
 result |= (eval_register(instruction.operand2) << (shift -= 5));
 int32_t offset = eval_immediate(instruction.operand3,
     instruction.table);
 offset /= 32 / 8;
 offset -= *(instruction.address);
 offset &= 0xFFFF;
 result |= offset;
 return result;
}

canonical_original_code:
unsigned int assemble_branch(struct Instruction instruction) {
 int shift = 32;
 unsigned int result = instruction.opcode << (shift -= 6);
 result |= (eval_register(instruction.operand1) << (shift -= 5));
 result |= (eval_register(instruction.operand2) << (shift -= 5));
 int offset = eval_immediate(instruction.operand3,
     instruction.table);
 offset /= 32 / 8;
 offset -= *(instruction.address);
 offset &= 0xFFFF;
 result |= offset;
 return result;
}

variable_types: offset int


decompiled_code:
__int64 __fastcall assemble_itype(int a1, int a2, int a3, int a4, int a5, int a6, int a7, __int64 a8, __int64 a9, char *nptr, __int64 a11, __int64 a12)
{
int v12; // er12
int v13; // ebp

if ( (unsigned int)(a7 - 9) <= 5 )
return assemble_branch(a1, a2, a3, a4, a5, a6, a7, a8, a9, nptr, a11, a12);
v12 = eval_register(a8);
v13 = eval_register(a9);
return (v12 << 21) | (unsigned int)eval_immediate(nptr, a11) | (a7 << 26) | (v13 << 16);
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1, int a2, int a3, int a4, int a5, int a6, int a7, __int64 a8, __int64 a9, char *nptr, __int64 a11, __int64 a12)
{
int v12; // er12
int v13; // ebp

if ( (unsigned int)(a7 - 9) <= 5 )
return func11(a1, a2, a3, a4, a5, a6, a7, a8, a9, nptr, a11, a12);
v12 = func7(a8);
v13 = func7(a9);
return (v12 << 21) | (unsigned int)func5(nptr, a11) | (a7 << 26) | (v13 << 16);
}

original_code:
uint32_t assemble_itype(Instruction instruction) {
 if (instruction.opcode >= 9
  && instruction.opcode <= 14) {
  return assemble_branch(instruction);
 }
 int shift = 32;
 uint32_t result = instruction.opcode << (shift -= 6);
 result |= (eval_register(instruction.operand1) << (shift -= 5));
 result |= (eval_register(instruction.operand2) << (shift -= 5));
 result |= eval_immediate(instruction.operand3, instruction.table);
 return result;
}

canonical_original_code:
unsigned int assemble_itype(struct Instruction instruction) {
 if (instruction.opcode >= 9
  && instruction.opcode <= 14) {
  return assemble_branch(instruction);
 }
 int shift = 32;
 unsigned int result = instruction.opcode << (shift -= 6);
 result |= (eval_register(instruction.operand1) << (shift -= 5));
 result |= (eval_register(instruction.operand2) << (shift -= 5));
 result |= eval_immediate(instruction.operand3, instruction.table);
 return result;
}


decompiled_code:
_BOOL8 __fastcall is_valid_opcode(unsigned __int8 a1)
{
return a1 <= 0x1Au;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(unsigned __int8 a1)
{
return a1 <= 0x1Au;
}

original_code:
int is_valid_opcode(uint8_t opcode) {
 return opcode < 27;
}

canonical_original_code:
int is_valid_opcode(unsigned char opcode) {
 return opcode < 27;
}

variable_types:
opcode
unsigned char


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

result = 0LL;
if ( a1 > 0xFFFC )
{
fprintf(stderr, "*** Cannot access memory location '%d'.\n", a1);
result = 1LL;
}
return result;
}

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

result = 0LL;
if ( a1 > 0xFFFC )
{
fprintf(stderr, "*** Cannot access memory location '%d'.\n", a1);
result = 1LL;
}
return result;
}

original_code:
int check_mem_access(int location) {
 if (location < 0 || location > 65536 - 4) {
  fprintf(stderr, "*** Cannot access memory "
   "location '%d'.\n", location);
  return 1;
 }
 return 0;
}

variable_types: location int


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

result = 0LL;
if ( a1 > 0x7FFFF )
{
fprintf(stderr, "*** Cannot access memory address '%u'. \n", a1);
result = 1LL;
}
return result;
}

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

result = 0LL;
if ( a1 > 0x7FFFF )
{
fprintf(stderr, "*** Cannot access memory address '%u'. \n", a1);
result = 1LL;
}
return result;
}

original_code:
int check_address(uint32_t address) {
 if(address >= (8 * 65536)) {
  fprintf(stderr, "*** Cannot access memory "
   "address '%u'. \n", address);
  return 1;
 }
 return 0;
}

canonical_original_code:
int check_address(unsigned int address) {
 if(address >= (8 * 65536)) {
  fprintf(stderr, "*** Cannot access memory "
   "address '%u'. \n", address);
  return 1;
 }
 return 0;
}

variable_types:
address
unsigned int


extract

decompiled_code:
__int64 __fastcall extract(int a1, char a2, char a3)
{
char v3; // r8
int v4; // ecx
int v5; // esi
int v6; // esi
unsigned int v7; // eax
int v8; // edx

v3 = 31 - a3;
v4 = (unsigned __int8)(31 - a3);
v5 = (unsigned __int8)(31 - a2);
if ( v4 > v5 )
return 0LL;
v6 = v5 + 1;
v7 = 0;
do
{
v8 = 1 << v4++;
v7 += v8;
}
while ( v4 != v6 );
return (a1 & v7) >> v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, char a2, char a3)
{
char v3; // r8
int v4; // ecx
int v5; // esi
int v6; // esi
unsigned int v7; // eax
int v8; // edx

v3 = 31 - a3;
v4 = (unsigned __int8)(31 - a3);
v5 = (unsigned __int8)(31 - a2);
if ( v4 > v5 )
return 0LL;
v6 = v5 + 1;
v7 = 0;
do
{
v8 = 1 << v4++;
v7 += v8;
}
while ( v4 != v6 );
return (a1 & v7) >> v3;
}

original_code:
uint32_t extract(uint32_t instruction, uint8_t start, uint8_t end) {
 uint32_t mask = 0;
 start = 31 - start;
 end = 31 - end;
 for (int i = end; i <= start; i++) {
  mask += (1 << i);
 }
 return (mask & instruction) >> end;
}

canonical_original_code:
unsigned int extract(unsigned int instruction, unsigned char start, unsigned char end) {
 unsigned int mask = 0;
 start = 31 - start;
 end = 31 - end;
 for (int i = end; i <= start; i++) {
  mask += (1 << i);
 }
 return (mask & instruction) >> end;
}

variable_types:
instruction
unsigned int

variable_types:
start
unsigned char

variable_types:
end
unsigned char

variable_types:
mask
unsigned int


decompiled_code:
__int64 __fastcall extract_opcode(int a1)
{
return extract(a1, 0, 5);
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
return func3(a1, 0, 5);
}

original_code:
uint8_t extract_opcode(uint32_t instruction) {
 uint8_t opcode = (uint8_t)extract(instruction, START_OPCODE, END_OPCODE);
 return opcode;
}

canonical_original_code:
unsigned char extract_opcode(unsigned int instruction) {
 unsigned char opcode = (uint8_t)extract(instruction, START_OPCODE, END_OPCODE);
 return opcode;
}

return_type: unsigned char


decompiled_code:
__int64 __fastcall extract_address(int a1)
{
return extract(a1, 6, 31);
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1)
{
return func3(a1, 6, 31);
}

original_code:
uint32_t extract_address(uint32_t instruction) {
 return extract(instruction, (END_OPCODE + 1), 31);
}

canonical_original_code:
unsigned int extract_address(unsigned int instruction) {
 return extract(instruction, (END_OPCODE + 1), 31);
}


decompiled_code:
unsigned __int64 __fastcall extract_r(int a1)
{
char v1; // bl
int v2; // er10
int v3; // er10
unsigned __int8 v4; // al
char v5; // r11
unsigned __int16 v7; // [rsp+Dh] [rbp-Bh]

v1 = extract(a1, 6, 10);
extract(v2, 11, 15);
v4 = extract(v3, 16, 20);
LOBYTE(v7) = v1;
HIBYTE(v7) = v5;
return v7 | ((unsigned __int64)v4 << 16);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func6(int a1)
{
char v1; // bl
int v2; // er10
int v3; // er10
unsigned __int8 v4; // al
char v5; // r11
unsigned __int16 v7; // [rsp+Dh] [rbp-Bh]

v1 = func3(a1, 6, 10);
func3(v2, 11, 15);
v4 = func3(v3, 16, 20);
LOBYTE(v7) = v1;
HIBYTE(v7) = v5;
return v7 | ((unsigned __int64)v4 << 16);
}

original_code:
OperandsR extract_r(uint32_t instruction) {
 OperandsR operands;
 uint8_t r1_start = END_OPCODE + 1;
 uint8_t r2_start = r1_start + REG_WIDTH;
 uint8_t r3_start = r2_start + REG_WIDTH;
 operands.r1 = extract(instruction, r1_start, r2_start - 1);
 operands.r2 = extract(instruction, r2_start, r3_start - 1);
 operands.r3 = extract(instruction, r3_start, r3_start + REG_WIDTH - 1);
 return operands;
}

canonical_original_code:
struct OperandsR extract_r(unsigned int instruction) {
 struct OperandsR operands;
 unsigned char r1_start = END_OPCODE + 1;
 unsigned char r2_start = r1_start + REG_WIDTH;
 unsigned char r3_start = r2_start + REG_WIDTH;
 operands.r1 = extract(instruction, r1_start, r2_start - 1);
 operands.r2 = extract(instruction, r2_start, r3_start - 1);
 operands.r3 = extract(instruction, r3_start, r3_start + REG_WIDTH - 1);
 return operands;
}

variable_types: struct OperandsR { unsigned char r1; unsigned char r2; unsigned char r3; }


decompiled_code:
__int64 __fastcall extract_i(int a1)
{
int v1; // er10
char v2; // bl
int v3; // er10
int v4; // edx
char v5; // r11
unsigned __int16 v6; // ax

extract(a1, 6, 10);
v2 = extract(v1, 11, 15);
v4 = extract(v3, 16, 31);
LOBYTE(v6) = v5;
HIBYTE(v6) = v2;
return (v4 << 16) | (unsigned int)v6;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
int v1; // er10
char v2; // bl
int v3; // er10
int v4; // edx
char v5; // r11
unsigned __int16 v6; // ax

func3(a1, 6, 10);
v2 = func3(v1, 11, 15);
v4 = func3(v3, 16, 31);
LOBYTE(v6) = v5;
HIBYTE(v6) = v2;
return (v4 << 16) | (unsigned int)v6;
}

original_code:
OperandsI extract_i(uint32_t instruction) {
 OperandsI operands;
 uint8_t r1_start = END_OPCODE + 1;
 uint8_t r2_start = r1_start + REG_WIDTH;
 uint8_t immediate_start = r2_start + REG_WIDTH;
 operands.r1 = extract(instruction, r1_start, r2_start - 1);
 operands.r2 = extract(instruction, r2_start, immediate_start - 1 );
 operands.immediate = (int16_t)extract(instruction, immediate_start,
   31);
 return operands;
}

canonical_original_code:
struct OperandsI extract_i(unsigned int instruction) {
 struct OperandsI operands;
 unsigned char r1_start = END_OPCODE + 1;
 unsigned char r2_start = r1_start + REG_WIDTH;
 unsigned char immediate_start = r2_start + REG_WIDTH;
 operands.r1 = extract(instruction, r1_start, r2_start - 1);
 operands.r2 = extract(instruction, r2_start, immediate_start - 1 );
 operands.immediate = (short)extract(instruction, immediate_start,
   31);
 return operands;
}

variable_types: struct OperandsI { unsigned char r1; unsigned char r2; short immediate; }


decompiled_code:
__int64 __fastcall stack_dump(__int64 a1)
{
unsigned int v1; // ebx
__int64 v2; // rax
__int64 v3; // rdx
__int64 result; // rax

if ( *(_WORD *)(a1 + 2) != 0xFFFF )
{
v1 = 0xFFFF;
do
{
v2 = v1;
v3 = v1 - 0x10000;
v1 -= 4;
fprintf(stderr, "Stack Address [%d] : %d\t", v3, *(unsigned int *)(a1 + v2 + 8));
result = *(unsigned __int16 *)(a1 + 2);
}
while ( (unsigned int)result < v1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
unsigned int v1; // ebx
__int64 v2; // rax
__int64 v3; // rdx
__int64 result; // rax

if ( *(_WORD *)(a1 + 2) != 0xFFFF )
{
v1 = 0xFFFF;
do
{
v2 = v1;
v3 = v1 - 0x10000;
v1 -= 4;
fprintf(stderr, "Stack Address [%d] : %d\t", v3, *(unsigned int *)(a1 + v2 + 8));
result = *(unsigned __int16 *)(a1 + 2);
}
while ( (unsigned int)result < v1 );
}
return result;
}

original_code:
static void stack_dump(State* machine_state) {
 for (uint32_t i = 65536 - 1; i > machine_state->sp; i -= 4) {
  uint32_t *stackelem = (uint32_t *)&machine_state->mem[i];
  fprintf(stderr, "Stack Address [%d] : %d\t",
     (i - 65536), *stackelem);
  if (i % 2 == 0) {
   fprintf(stderr,"\n");
  }
 }
}

canonical_original_code:
static void stack_dump(struct State *machine_state) {
 for (unsigned int i = 65536 - 1; i > machine_state->sp; i -= 4) {
  unsigned int *stackelem = (uint32_t *)&machine_state->mem[i];
  fprintf(stderr, "Stack Address [%d] : %d\t",
     (i - 65536), *stackelem);
  if (i % 2 == 0) {
   fprintf(stderr,"\n");
  }
 }
}

variable_types: struct State { unsigned short pc; unsigned short sp; unsigned short stack_size; unsigned short stack_boundary; unsigned char mem[65536]; unsigned int reg[32]; } *

variable_types:
i
unsigned int

variable_types:
stackelem
unsigned int *


decompiled_code:
int __fastcall halt_instruction(__int64 a1, unsigned __int16 *a2)
{
int v2; // ebp
__int64 v3; // rbx

v2 = 1;
v3 = 0LL;
fprintf(stderr, " PC: 0x%x\t", *a2);
do
{
while ( 1 )
{
++v2;
fprintf(stderr, "R%02d: 0x%x", (unsigned int)v3, *(unsigned int *)&a2[2 * v3 + 32772]);
if ( (unsigned __int8)v2 <= 3u )
break;
++v3;
v2 = 0;
fputc(10, stderr);
if ( v3 == 32 )
return fputc(10, stderr);
}
++v3;
fputc(9, stderr);
}
while ( v3 != 32 );
return fputc(10, stderr);
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, unsigned __int16 *a2)
{
int v2; // ebp
__int64 v3; // rbx

v2 = 1;
v3 = 0LL;
fprintf(stderr, " PC: 0x%x\t", *a2);
do
{
while ( 1 )
{
++v2;
fprintf(stderr, "R%02d: 0x%x", (unsigned int)v3, *(unsigned int *)&a2[2 * v3 + 32772]);
if ( (unsigned __int8)v2 <= 3u )
break;
++v3;
v2 = 0;
fputc(10, stderr);
if ( v3 == 32 )
return fputc(10, stderr);
}
++v3;
fputc(9, stderr);
}
while ( v3 != 32 );
return fputc(10, stderr);
}

original_code:
void halt_instruction(uint32_t instruction, State *machine_state) {
        fprintf(stderr, " PC: 0x%x\t", machine_state->pc);
 uint8_t num_cols = 1;
        for(int i = 0; i < 32; i++) {
                fprintf(stderr, "R%02d: 0x%x", i, machine_state->reg[i]);
  num_cols++;
  if (num_cols >= 4) {
   fprintf(stderr, "\n");
   num_cols = 0;
  }
  else {
   fprintf(stderr, "\t");
  }
        }
 fprintf(stderr, "\n");
}

canonical_original_code:
void halt_instruction(unsigned int instruction, struct State *machine_state) {
        fprintf(stderr, " PC: 0x%x\t", machine_state->pc);
 unsigned char num_cols = 1;
        for(int i = 0; i < 32; i++) {
                fprintf(stderr, "R%02d: 0x%x", i, machine_state->reg[i]);
  num_cols++;
  if (num_cols >= 4) {
   fprintf(stderr, "\n");
   num_cols = 0;
  }
  else {
   fprintf(stderr, "\t");
  }
        }
 fprintf(stderr, "\n");
}

variable_types: i int

user_defined_types: struct State { unsigned short pc; unsigned short sp; unsigned short stack_size; unsigned short stack_boundary; unsigned char mem[65536]; unsigned int reg[32]; }


decompiled_code:
__int64 __fastcall jal_instruction(__int64 a1, unsigned __int16 *a2)
{
unsigned int v2; // eax
unsigned __int16 v3; // bp
int v4; // eax
__int64 result; // rax

v2 = extract_address();
v3 = v2;
if ( (unsigned int)check_address(v2) )
{
fwrite("*** Terminating...\n", 1uLL, 0x13uLL, stdout);
exit(1);
}
v4 = *a2;
*a2 = v3;
result = (unsigned int)(v4 + 4);
*((_DWORD *)a2 + 16417) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1, unsigned __int16 *a2)
{
unsigned int v2; // eax
unsigned __int16 v3; // bp
int v4; // eax
__int64 result; // rax

v2 = extract_address();
v3 = v2;
if ( (unsigned int)check_address(v2) )
{
fwrite("*** Terminating...\n", 1uLL, 0x13uLL, stdout);
exit(1);
}
v4 = *a2;
*a2 = v3;
result = (unsigned int)(v4 + 4);
*((_DWORD *)a2 + 16417) = result;
return result;
}

original_code:
void jal_instruction(uint32_t instruction, State *machine_state) {
        uint32_t address = extract_address(instruction);
 if(check_address(address)) {
  fprintf(stdout, "*** Terminating...\n");
  exit(1);
 }
        machine_state->reg[31] = (machine_state->pc + 4);
        machine_state->pc = address;
}

canonical_original_code:
void jal_instruction(unsigned int instruction, struct State *machine_state) {
        unsigned int address = extract_address(instruction);
 if(check_address(address)) {
  fprintf(stdout, "*** Terminating...\n");
  exit(1);
 }
        machine_state->reg[31] = (machine_state->pc + 4);
        machine_state->pc = address;
}


decompiled_code:
__int64 __fastcall call_instruction(__int64 a1, unsigned __int16 *a2)
{
unsigned int v2; // er8
__int64 v3; // rdx
unsigned __int16 v4; // r8
int v5; // eax
__int64 result; // rax

increment_pc(a2, 1);
v4 = extract(v2, 8LL, v3);
v5 = a2[1];
*(_DWORD *)((char *)a2 + a2[1] + 8) = *a2;
result = (unsigned int)(v5 - 4);
*a2 = v4;
a2[1] = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func23(__int64 a1, unsigned __int16 *a2)
{
unsigned int v2; // er8
__int64 v3; // rdx
unsigned __int16 v4; // r8
int v5; // eax
__int64 result; // rax

func1(a2, 1);
v4 = extract(v2, 8LL, v3);
v5 = a2[1];
*(_DWORD *)((char *)a2 + a2[1] + 8) = *a2;
result = (unsigned int)(v5 - 4);
*a2 = v4;
a2[1] = result;
return result;
}

original_code:
void call_instruction(uint32_t instruction, State *machine_state) {
 increment_pc(machine_state, 1);
 uint32_t value = (uint32_t) extract(instruction,8,31);
 uint32_t *pointer = (uint32_t *)&machine_state->mem[machine_state->sp];
 *pointer = (uint32_t) machine_state->pc;
 machine_state->sp -= 4;
 machine_state->pc = value;
}

canonical_original_code:
void call_instruction(unsigned int instruction, struct State *machine_state) {
 increment_pc(machine_state, 1);
 unsigned int value = (uint32_t) extract(instruction,8,31);
 unsigned int *pointer = (uint32_t *)&machine_state->mem[machine_state->sp];
 *pointer = (unsigned int) machine_state->pc;
 machine_state->sp -= 4;
 machine_state->pc = value;
}

variable_types:
value
unsigned int

variable_types:
pointer
unsigned int *


decompiled_code:
void __fastcall copy_token(void **a1, const char *a2)
{
size_t v2; // rax
const char *v3; // rax
char *v4; // r12
size_t v5; // rax
size_t v6; // rax

if ( a2 )
{
v2 = strlen(a2);
v3 = (const char *)realloc(*a1, v2);
*a1 = (void *)v3;
v4 = (char *)v3;
if ( !v3 )
{
perror("Couldn't reallocate memory for *dest");
exit(1);
}
v5 = strlen(v3);
memset(v4, 0, v5);
v6 = strlen(a2);
strncpy((char *)*a1, a2, v6);
}
else
{
*a1 = 0LL;
}
}

canonical_decompiled_code:
void __fastcall func0(void **a1, const char *a2)
{
size_t v2; // rax
const char *v3; // rax
char *v4; // r12
size_t v5; // rax
size_t v6; // rax

if ( a2 )
{
v2 = strlen(a2);
v3 = (const char *)realloc(*a1, v2);
*a1 = (void *)v3;
v4 = (char *)v3;
if ( !v3 )
{
perror("Couldn't reallocate memory for *dest");
exit(1);
}
v5 = strlen(v3);
memset(v4, 0, v5);
v6 = strlen(a2);
strncpy((char *)*a1, a2, v6);
}
else
{
*a1 = 0LL;
}
}

original_code:
void copy_token(char **dest, const void *src) {
 if (src == ((void *)0)) {
  *dest = ((void *)0);
 } else {
  *dest = realloc(*dest, strlen(src));
  if (*dest == ((void *)0)) {
   perror("Couldn't reallocate memory for *dest");
   exit(1);
  }
  memset(*dest, '\0',strlen(*dest));
  strncpy(*dest, src, strlen(src));
 }
}

canonical_original_code:
void copy_token(char **dest, void *src) {
 if (src == ((void *)0)) {
  *dest = ((void *)0);
 } else {
  *dest = realloc(*dest, strlen(src));
  if (*dest == ((void *)0)) {
   perror("Couldn't reallocate memory for *dest");
   exit(1);
  }
  memset(*dest, '\0',strlen(*dest));
  strncpy(*dest, src, strlen(src));
 }
}

variable_types:
dest
char **

variable_types:
src
void *


init

decompiled_code:
__int64 __fastcall init(_QWORD *a1)
{
__int64 result; // rax

*a1 = 0xFBFB0400FFFB0000LL;
memset(a1 + 1, 0, 0x10000uLL);
result = 0LL;
a1[8193] = 0LL;
a1[8208] = 0LL;
memset(
(void *)((unsigned __int64)(a1 + 8194) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 65552) & 0xFFFFFFF8) + 65672) >> 3));
return result;
}

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

*a1 = 0xFBFB0400FFFB0000LL;
memset(a1 + 1, 0, 0x10000uLL);
result = 0LL;
a1[8193] = 0LL;
a1[8208] = 0LL;
memset(
(void *)((unsigned __int64)(a1 + 8194) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 65552) & 0xFFFFFFF8) + 65672) >> 3));
return result;
}

original_code:
int init(State *machine_state) {
 machine_state->pc = 0;
 machine_state->sp = 65536 - 5;
 machine_state->stack_size = 1024;
 machine_state->stack_boundary = machine_state->sp - machine_state->stack_size;
 memset(machine_state->mem, 0, sizeof(uint8_t) * 65536);
 memset(machine_state->reg, 0, sizeof(uint32_t) * 32);
 return 0;
}

canonical_original_code:
int init(struct State *machine_state) {
 machine_state->pc = 0;
 machine_state->sp = 65536 - 5;
 machine_state->stack_size = 1024;
 machine_state->stack_boundary = machine_state->sp - machine_state->stack_size;
 memset(machine_state->mem, 0, sizeof(unsigned char) * 65536);
 memset(machine_state->reg, 0, sizeof(unsigned int) * 32);
 return 0;
}


main

repo: mtoyoda/sl

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rdx
const char **v4; // rcx
unsigned int v5; // ebx

if ( argc > 1 )
{
v3 = argv + 1;
v4 = &argv[(unsigned int)(argc - 2) + 2];
do
{
while ( **v3 != 45 )
{
if ( ++v3 == v4 )
goto LABEL_6;
}
option(*v3 + 1, argv, v3 + 1, v4);
}
while ( v3 != v4 );
}
LABEL_6:
initscr();
signal(2, (__sighandler_t)1);
noecho();
curs_set(0);
nodelay(stdscr__NCURSES6_TINFO_5_0_19991023, 1);
leaveok(stdscr__NCURSES6_TINFO_5_0_19991023, 1);
scrollok(stdscr__NCURSES6_TINFO_5_0_19991023, 0);
v5 = COLS__NCURSES6_TINFO_5_0_19991023 - 1;
while ( LOGO != 1 )
{
if ( C51 == 1 )
{
if ( (unsigned int)add_C51(v5) == -1 )
goto LABEL_12;
}
else if ( (unsigned int)add_D51() == -1 )
{
goto LABEL_12;
}
LABEL_8:
--v5;
wgetch(stdscr__NCURSES6_TINFO_5_0_19991023);
wrefresh(stdscr__NCURSES6_TINFO_5_0_19991023);
usleep(0x9C40u);
}
if ( (unsigned int)add_sl(v5) != -1 )
goto LABEL_8;
LABEL_12:
mvcur(0, COLS__NCURSES6_TINFO_5_0_19991023 - 1, LINES__NCURSES6_TINFO_5_0_19991023 - 1, 0);
endwin();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rdx
const char **v4; // rcx
unsigned int v5; // ebx

if ( argc > 1 )
{
v3 = argv + 1;
v4 = &argv[(unsigned int)(argc - 2) + 2];
do
{
while ( **v3 != 45 )
{
if ( ++v3 == v4 )
goto LABEL_6;
}
func8(*v3 + 1, argv, v3 + 1, v4);
}
while ( v3 != v4 );
}
LABEL_6:
initscr();
signal(2, (__sighandler_t)1);
noecho();
curs_set(0);
nodelay(stdscr__NCURSES6_TINFO_5_0_19991023, 1);
leaveok(stdscr__NCURSES6_TINFO_5_0_19991023, 1);
scrollok(stdscr__NCURSES6_TINFO_5_0_19991023, 0);
v5 = COLS__NCURSES6_TINFO_5_0_19991023 - 1;
while ( LOGO != 1 )
{
if ( C51 == 1 )
{
if ( (unsigned int)func13(v5) == -1 )
goto LABEL_12;
}
else if ( (unsigned int)func12() == -1 )
{
goto LABEL_12;
}
LABEL_8:
--v5;
wgetch(stdscr__NCURSES6_TINFO_5_0_19991023);
wrefresh(stdscr__NCURSES6_TINFO_5_0_19991023);
usleep(0x9C40u);
}
if ( (unsigned int)func11(v5) != -1 )
goto LABEL_8;
LABEL_12:
mvcur(0, COLS__NCURSES6_TINFO_5_0_19991023 - 1, LINES__NCURSES6_TINFO_5_0_19991023 - 1, 0);
endwin();
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    int x, i;
    for (i = 1; i < argc; ++i) {
        if (*argv[i] == '-') {
            option(argv[i] + 1);
        }
    }
    initscr();
    signal(2, ((__sighandler_t) 1));
    noecho();
    curs_set(0);
    nodelay(stdscr, 1);
    leaveok(stdscr, 1);
    scrollok(stdscr, 0);
    for (x = COLS - 1; ; --x) {
        if (LOGO == 1) {
            if (add_sl(x) == (-1)) break;
        }
        else if (C51 == 1) {
            if (add_C51(x) == (-1)) break;
        }
        else {
            if (add_D51(x) == (-1)) break;
        }
        wgetch(stdscr);
        wrefresh(stdscr);
        usleep(40000);
    }
    mvcur(0, COLS - 1, LINES - 1, 0);
    endwin();
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    int x; int i;
    for (i = 1; i < argc; ++i) {
        if (*argv[i] == '-') {
            option(argv[i] + 1);
        }
    }
    initscr();
    signal(2, ((void (*)(int)) 1));
    noecho();
    curs_set(0);
    nodelay(stdscr, 1);
    leaveok(stdscr, 1);
    scrollok(stdscr, 0);
    for (x = COLS - 1; ; --x) {
        if (LOGO == 1) {
            if (add_sl(x) == (-1)) break;
        }
        else if (C51 == 1) {
            if (add_C51(x) == (-1)) break;
        }
        else {
            if (add_D51(x) == (-1)) break;
        }
        wgetch(stdscr);
        wrefresh(stdscr);
        usleep(40000);
    }
    mvcur(0, COLS - 1, LINES - 1, 0);
    endwin();
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: x int


decompiled_code:
__int64 __fastcall my_mvaddstr(int a1, int a2, char *a3)
{
char *v4; // rbx
int v5; // ebp

if ( a2 < 0 )
{
while ( *a3 )
{
++a3;
if ( !++a2 )
goto LABEL_6;
}
return 0xFFFFFFFFLL;
}
LABEL_6:
v4 = a3;
v5 = a2 - (_DWORD)a3;
if ( *a3 )
{
while ( wmove(stdscr__NCURSES6_TINFO_5_0_19991023, a1, v5 + (_DWORD)v4) != -1
&& waddch(stdscr__NCURSES6_TINFO_5_0_19991023, (unsigned int)*v4) != -1 )
{
if ( !*++v4 )
return 0LL;
}
return 0xFFFFFFFFLL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, int a2, char *a3)
{
char *v4; // rbx
int v5; // ebp

if ( a2 < 0 )
{
while ( *a3 )
{
++a3;
if ( !++a2 )
goto LABEL_6;
}
return 0xFFFFFFFFLL;
}
LABEL_6:
v4 = a3;
v5 = a2 - (_DWORD)a3;
if ( *a3 )
{
while ( wmove(stdscr__NCURSES6_TINFO_5_0_19991023, a1, v5 + (_DWORD)v4) != -1
&& waddch(stdscr__NCURSES6_TINFO_5_0_19991023, (unsigned int)*v4) != -1 )
{
if ( !*++v4 )
return 0LL;
}
return 0xFFFFFFFFLL;
}
return 0LL;
}

variable_types: y int

variable_types:
str
char *


option

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

option:
while ( 1 )
{
result = *a1;
if ( !(_BYTE)result )
return result;
while ( 1 )
{
++a1;
if ( (_BYTE)result == 99 )
{
C51 = 1;
goto option;
}
if ( (char)result > 99 )
break;
if ( (_BYTE)result == 70 )
{
FLY = 1;
goto option;
}
if ( (_BYTE)result != 97 )
goto option;
ACCIDENT = 1;
result = *a1;
if ( !(_BYTE)result )
return result;
}
if ( (_BYTE)result == 108 )
LOGO = 1;
}
}

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

option:
while ( 1 )
{
result = *a1;
if ( !(_BYTE)result )
return result;
while ( 1 )
{
++a1;
if ( (_BYTE)result == 99 )
{
C51 = 1;
goto option;
}
if ( (char)result > 99 )
break;
if ( (_BYTE)result == 70 )
{
FLY = 1;
goto option;
}
if ( (_BYTE)result != 97 )
goto option;
ACCIDENT = 1;
result = *a1;
if ( !(_BYTE)result )
return result;
}
if ( (_BYTE)result == 108 )
LOGO = 1;
}
}

original_code:
void option(char *str)
{
    extern int ACCIDENT, LOGO, FLY, C51;
    while (*str != '\0') {
        switch (*str++) {
            case 'a': ACCIDENT = 1; break;
            case 'F': FLY = 1; break;
            case 'l': LOGO = 1; break;
            case 'c': C51 = 1; break;
            default: break;
        }
    }
}

canonical_original_code:
void option(char *str)
{
    extern int ACCIDENT; extern int LOGO; extern int FLY; extern int C51;
    while (*str != '\0') {
        switch (*str++) {
            case 'a': ACCIDENT = 1; break;
            case 'F': FLY = 1; break;
            case 'l': LOGO = 1; break;
            case 'c': C51 = 1; break;
            default: break;
        }
    }
}

variable_types: ACCIDENT int

variable_types: LOGO int

variable_types: FLY int


variable_types:
man
char *[2][2]


variable_types: struct smokes { int y; int ptrn; } [1000]

variable_types: sum int

variable_types:
Smoke
char *[2][16]

variable_types:
Eraser
char *[16]

variable_types:
dy
int [16]

variable_types:
dx
int [16]


variable_types:
coal
char *[-1]

variable_types:
car
char *[-1]

variable_types: i int


variable_types: dy int


main

repo: mugit/effprog

original_code:
int main(int argc, char *argv[]) {
    struct block input1, input2;
    char *p, *nextp, *endp;
    unsigned int i;
    unsigned long r = 0;
    int currentLookup;
    int *cache;
    int cacheSize = (1<<20);
    int cacheCounter;
    if (argc!=3) {
        fprintf(stderr, "usage: %s <dict-file> <lookup-file>\n", argv[0]);
        exit(1);
    }
    input1 = slurp(argv[1]);
    input2 = slurp(argv[2]);
    for (p=input1.addr, endp=input1.addr+input1.len, i=0; p<endp; i++) {
        nextp=memchr(p, '\n', endp-p);
        if (nextp == ((void *)0))
            break;
        insert(p, nextp-p, i);
        p = nextp+1;
    }
    cache = calloc((1<<20), sizeof(int));
    for (i = 0; i < 10; i++) {
        for (p = input2.addr, endp = input2.addr + input2.len, cacheCounter = 0; p < endp; cacheCounter++) {
            nextp = memchr(p, '\n', endp-p);
            if (nextp == ((void *)0)) {
                break;
            }
            if (i == 0) {
                currentLookup = lookup(p, nextp - p);
                if (cacheCounter >= cacheSize) {
                    cache = realloc(cache, 96 * sizeof(int));
                    cacheSize += 96;
                }
                cache[cacheCounter] = currentLookup;
            } else {
                currentLookup = cache[cacheCounter];
            }
            r = ((unsigned long)r) * 2654435761L + currentLookup;
            r = r + (r>>32);
            p = nextp+1;
        }
    }
    printf("%ld\n",r);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
    struct block input1; struct block input2;
    char *p; char *nextp; char *endp;
    unsigned int i;
    unsigned long r = 0;
    int currentLookup;
    int *cache;
    int cacheSize = (1<<20);
    int cacheCounter;
    if (argc!=3) {
        fprintf(stderr, "usage: %s <dict-file> <lookup-file>\n", argv[0]);
        exit(1);
    }
    input1 = slurp(argv[1]);
    input2 = slurp(argv[2]);
    for (p=input1.addr, endp=input1.addr+input1.len, i=0; p<endp; i++) {
        nextp=memchr(p, '\n', endp-p);
        if (nextp == ((void *)0))
            break;
        insert(p, nextp-p, i);
        p = nextp+1;
    }
    cache = calloc((1<<20), sizeof(int));
    for (i = 0; i < 10; i++) {
        for (p = input2.addr, endp = input2.addr + input2.len, cacheCounter = 0; p < endp; cacheCounter++) {
            nextp = memchr(p, '\n', endp-p);
            if (nextp == ((void *)0)) {
                break;
            }
            if (i == 0) {
                currentLookup = lookup(p, nextp - p);
                if (cacheCounter >= cacheSize) {
                    cache = realloc(cache, 96 * sizeof(int));
                    cacheSize += 96;
                }
                cache[cacheCounter] = currentLookup;
            } else {
                currentLookup = cache[cacheCounter];
            }
            r = ((unsigned long)r) * 2654435761L + currentLookup;
            r = r + (r>>32);
            p = nextp+1;
        }
    }
    printf("%ld\n",r);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct block { char *addr; unsigned long len; }

variable_types:
p
char *

variable_types:
nextp
char *

variable_types:
endp
char *

variable_types:
i
unsigned int

variable_types:
r
unsigned long

variable_types: currentLookup int

variable_types:
cache
int *

variable_types: cacheSize int

variable_types: cacheCounter int


slurp

decompiled_code:
void *__fastcall slurp(const char *a1)
{
int v1; // eax
int v2; // ebx
void *result; // rax
struct stat v4; // [rsp+0h] [rbp-A8h] BYREF

v1 = open(a1, 0);
if ( v1 == -1
|| (v2 = v1, (unsigned int)fstat(v1, &v4) == -1)
|| (result = mmap(0LL, v4.st_size + 7, 3, 2, v2, 0LL), result == (void *)-1LL) )
{
err(1, "%s", a1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func7(const char *a1)
{
int v1; // eax
int v2; // ebx
void *result; // rax
struct stat v4; // [rsp+0h] [rbp-A8h] BYREF

v1 = open(a1, 0);
if ( v1 == -1
|| (v2 = v1, (unsigned int)func12(v1, &v4) == -1)
|| (result = mmap(0LL, v4.st_size + 7, 3, 2, v2, 0LL), result == (void *)-1LL) )
{
err(1, "%s", a1);
}
return result;
}

original_code:
struct block slurp(char *filename) {
    int fd=open(filename,00);
    char *s;
    struct stat statbuf;
    struct block r;
    if (fd==-1)
        err(1, "%s", filename);
    if (fstat(fd, &statbuf)==-1)
        err(1, "%s", filename);
    s = mmap(((void *)0),statbuf.st_size+7, 0x1|0x2,0|0x02,fd, 0);
    if (s==((void *) -1))
        err(1, "%s", filename);
    r.addr = s;
    r.len = statbuf.st_size;
    return r;
}

canonical_original_code:
struct block slurp(char *filename) {
    int fd = open(filename,00);
    char *s;
    struct stat statbuf;
    struct block r;
    if (fd==-1)
        err(1, "%s", filename);
    if (fstat(fd, &statbuf)==-1)
        err(1, "%s", filename);
    s = mmap(((void *)0),statbuf.st_size+7, 0x1|0x2,0|0x02,fd, 0);
    if (s==((void *) -1))
        err(1, "%s", filename);
    r.addr = s;
    r.len = statbuf.st_size;
    return r;
}

variable_types:
filename
char *

variable_types: fd int

variable_types:
s
char *

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

return_type: struct block { char *addr; unsigned long len; }

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


hash

original_code:
unsigned long hash(char *addr, size_t len) {
    uint128_t x = 0, w;
    size_t i, shift;
    for (i = 0; i + 7 < len; i += 8) {
        w = *(unsigned long *)(addr+i);
        x = (x + w)*13493690561280548289ULL;
    }
    if (i < len) {
        shift = ((i - len) << 3) + 64;
        w = (*(unsigned long *)(addr + i)) << shift;
        x = (x + w)*13493690561280548289ULL;
    }
    return x+(x>>64);
}

canonical_original_code:
unsigned long hash(char *addr, unsigned long len) {
    unsigned int x = 0; unsigned int w;
    unsigned long i; unsigned long shift;
    for (i = 0; i + 7 < len; i += 8) {
        w = *(unsigned long *)(addr+i);
        x = (x + w)*13493690561280548289ULL;
    }
    if (i < len) {
        shift = ((i - len) << 3) + 64;
        w = (*(unsigned long *)(addr + i)) << shift;
        x = (x + w)*13493690561280548289ULL;
    }
    return x+(x>>64);
}

variable_types:
addr
char *

variable_types:
len
unsigned long

variable_types:
x
unsigned int

variable_types:
w
unsigned int

variable_types:
i
unsigned long

variable_types:
shift
unsigned long


lookup

decompiled_code:
__int64 __fastcall lookup(void *s1, size_t n)
{
__int64 v2; // rbx

v2 = ht[hash((unsigned __int64 *)s1, n) & 0xFFFFF];
if ( !v2 )
return 0xFFFFFFFFLL;
while ( *(_QWORD *)(v2 + 16) != n || memcmp(s1, *(const void **)(v2 + 8), n) )
{
v2 = *(_QWORD *)v2;
if ( !v2 )
return 0xFFFFFFFFLL;
}
return *(unsigned int *)(v2 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func9(void *s1, size_t n)
{
__int64 v2; // rbx

v2 = ht[func8((unsigned __int64 *)s1, n) & 0xFFFFF];
if ( !v2 )
return 0xFFFFFFFFLL;
while ( *(_QWORD *)(v2 + 16) != n || memcmp(s1, *(const void **)(v2 + 8), n) )
{
v2 = *(_QWORD *)v2;
if ( !v2 )
return 0xFFFFFFFFLL;
}
return *(unsigned int *)(v2 + 24);
}

original_code:
int lookup(char *keyaddr, size_t keylen) {
    struct hashnode *l = ht[hash(keyaddr, keylen) & ((1<<20)-1)];
    while (l!=((void *)0)) {
        if (keylen == l->keylen && memcmp(keyaddr, l->keyaddr, keylen) == 0)
            return l->value;
        l = l->next;
    }
    return -1;
}

canonical_original_code:
int lookup(char *keyaddr, unsigned long keylen) {
    struct hashnode *l = ht[hash(keyaddr, keylen) & ((1<<20)-1)];
    while (l!=((void *)0)) {
        if (keylen == l->keylen && memcmp(keyaddr, l->keyaddr, keylen) == 0)
            return l->value;
        l = l->next;
    }
    return -1;
}

variable_types:
keyaddr
char *

variable_types:
keylen
unsigned long

variable_types: struct hashnode { struct hashnode *next; char *keyaddr; unsigned long keylen; int value; } *


main

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

v3 = libusb_init();
if ( v3 < 0 )
{
v4 = v3;
fwrite("Error initializing libusb. \n", 1uLL, 0x1CuLL, stderr);
}
else if ( (unsigned int)find_hid_device(0LL, argv) )
{
v4 = -1;
fwrite("Device not found. \n", 1uLL, 0x13uLL, stderr);
}
else
{
libusb_detach_kernel_driver();
libusb_set_configuration();
v4 = libusb_claim_interface();
if ( v4 )
{
fwrite("Failed to claim interface. \n", 1uLL, 0x1CuLL, stderr);
}
else
{
display = XOpenDisplay(0LL);
do
v5 = libusb_bulk_transfer();
while ( v5 != -4 );
libusb_release_interface();
libusb_close();
}
}
return v4;
}

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

v3 = libusb_init();
if ( v3 < 0 )
{
v4 = v3;
fwrite("Error initializing libusb. \n", 1uLL, 0x1CuLL, stderr);
}
else if ( (unsigned int)func7(0LL, argv) )
{
v4 = -1;
fwrite("Device not found. \n", 1uLL, 0x13uLL, stderr);
}
else
{
libusb_detach_kernel_driver();
libusb_set_configuration();
v4 = libusb_claim_interface();
if ( v4 )
{
fwrite("Failed to claim interface. \n", 1uLL, 0x1CuLL, stderr);
}
else
{
display = XOpenDisplay(0LL);
do
v5 = libusb_bulk_transfer();
while ( v5 != -4 );
libusb_release_interface();
libusb_close();
}
}
return v4;
}

original_code:
int main(){
    int r = 1;
    r = libusb_init(((void *)0));
    if (r < 0) {
        fprintf(stderr, "Error initializing libusb. \n");
        return r;
    }
    if (find_hid_device()) {
        fprintf(stderr, "Device not found. \n");
        return -1;
    }
    libusb_detach_kernel_driver(devh, 0);
    r = libusb_set_configuration(devh, 1);
    r = libusb_claim_interface(devh, 0);
    if (r) {
        fprintf(stderr, "Failed to claim interface. \n");
        return r;
    }
    unsigned char data[10];
    int actual = 0;
    display = XOpenDisplay(((void *)0));
    do{
        memset(data, 0, sizeof(data));
        r = libusb_bulk_transfer(devh, ENDPOINT_UP, data, 8, &actual, 0);
        switch(data[2]){
            case 78:
                fprintf(stderr, "PgUp\n");
                send_key(0xff55);
                break;
            case 75:
                fprintf(stderr, "PgDn\n");
                send_key(0xff56);
                break;
        }
    } while (r != LIBUSB_ERROR_NO_DEVICE);
    r = libusb_release_interface(devh, 0);
    libusb_close(devh);
    return 0;
}

variable_types: r int

variable_types:
data
unsigned char [10]

variable_types: actual int


decompiled_code:
_BOOL8 find_hid_device()
{
devh = libusb_open_device_with_vid_pid();
return devh == 0;
}

canonical_decompiled_code:
_BOOL8 func7()
{
devh = libusb_open_device_with_vid_pid();
return devh == 0;
}

original_code:
int find_hid_device(void){
    devh = libusb_open_device_with_vid_pid(((void *)0), HID_VENDOR, HID_PRODUCT);
    return devh ? 0 : 1;
}

canonical_original_code:
int find_hid_device(){
    devh = libusb_open_device_with_vid_pid(((void *)0), HID_VENDOR, HID_PRODUCT);
    return devh ? 0 : 1;
}


decompiled_code:
int __fastcall send_key(unsigned int a1)
{
XKeysymToKeycode(display, a1);
XTestFakeKeyEvent();
XTestFakeKeyEvent();
return XFlush(display);
}

canonical_decompiled_code:
int __fastcall func8(unsigned int a1)
{
XKeysymToKeycode(display, a1);
XTestFakeKeyEvent();
XTestFakeKeyEvent();
return XFlush(display);
}

original_code:
void send_key(unsigned int key){
    unsigned int keycode;
    keycode = XKeysymToKeycode(display, key);
    XTestFakeKeyEvent(display, keycode, 1, 0);
    XTestFakeKeyEvent(display, keycode, 0, 0);
    XFlush(display);
}

variable_types:
key
unsigned int

variable_types:
keycode
unsigned int


decompiled_code:
__int64 __fastcall cairo_image_view_destroy_surface(__int64 a1, __int64 a2)
{
return cairo_surface_destroy(a2);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
return cairo_surface_destroy(a2);
}

original_code:
static void
cairo_image_view_destroy_surface (gpointer instance,
      gpointer surface)
{
  cairo_surface_destroy (surface);
}

canonical_original_code:
static void cairo_image_view_destroy_surface(void *instance, void *surface)
{
  cairo_surface_destroy (surface);
}

variable_types:
instance
void *

variable_types:
surface
void *


decompiled_code:
// attributes: thunk
__int64 __fastcall cairo_vector_view_destroy_surface(__int64 a1, __int64 a2)
{
return cairo_image_view_destroy_surface(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
return func2(a1, a2);
}

original_code:
static void
cairo_vector_view_destroy_surface (gpointer instance,
       gpointer surface)
{
  cairo_surface_destroy (surface);
}

canonical_original_code:
static void cairo_vector_view_destroy_surface(void *instance, void *surface)
{
  cairo_surface_destroy (surface);
}


decompiled_code:
void cairo_image_view_destroy()
{
;
}

canonical_decompiled_code:
void func15()
{
;
}

original_code:
static void
cairo_image_view_destroy (gpointer instance __attribute__((__unused__)))
{
}

canonical_original_code:
static void cairo_image_view_destroy(void *instance)
{
}


decompiled_code:
__int64 __fastcall pangoft2_view_destroy_surface(__int64 a1, __int64 a2)
{
g_free(*(_QWORD *)(a2 + 16));
return g_slice_free1(40LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
g_free(*(_QWORD *)(a2 + 16));
return g_slice_free1(40LL, a2);
}

original_code:
static void
pangoft2_view_destroy_surface (gpointer instance __attribute__((__unused__)),
          gpointer surface)
{
  FT_Bitmap *bitmap = (FT_Bitmap *) surface;
  g_free (bitmap->buffer);
  do { if (1) g_slice_free1 (sizeof (FT_Bitmap), (bitmap)); else (void) ((FT_Bitmap*) 0 == (bitmap)); } while (0);
}

canonical_original_code:
static void pangoft2_view_destroy_surface(void *instance, void *surface)
{
  struct FT_Bitmap_ *bitmap = (FT_Bitmap *) surface;
  g_free (bitmap->buffer);
  do { if (1) g_slice_free1 (sizeof (FT_Bitmap), (bitmap)); else (void) ((struct FT_Bitmap_ *) 0 == (bitmap)); } while (0);
}

variable_types: struct FT_Bitmap_ { unsigned int rows; unsigned int width; int pitch; unsigned char *buffer; unsigned short num_grays; unsigned char pixel_mode; unsigned char palette_mode; void *palette; } *


decompiled_code:
// attributes: thunk
__int64 pangoft2_view_destroy()
{
return g_object_unref();
}

canonical_decompiled_code:
__int64 func5()
{
return g_object_unref();
}

original_code:
static void
pangoft2_view_destroy (gpointer instance)
{
  g_object_unref (instance);
}

canonical_original_code:
static void pangoft2_view_destroy(void *instance)
{
  g_object_unref (instance);
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
glob = 0;
gtk_init();
gtk_window_new();
gtk_drawing_area_new();
gtk_widget_set_size_request();
gtk_container_get_type();
g_type_check_instance_cast();
gtk_container_add();
gtk_widget_add_events();
g_type_check_instance_cast();
g_signal_connect_data();
g_signal_connect_data();
g_signal_connect_data();
gtk_window_get_type();
g_type_check_instance_cast();
gtk_window_set_position();
g_type_check_instance_cast();
gtk_window_set_default_size();
g_type_check_instance_cast();
gtk_window_set_title();
gtk_widget_show_all();
gtk_main();
return 0;
}

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

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

variable_types: argc int

variable_types:
argv
char **


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

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


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r8
__int64 v4; // rbp
int result; // eax
__int64 v6; // rbp

if ( argc == 3 )
{
v3 = argv[1];
if ( !strcmp("1_1", v3) )
{
cairo_svg_surface_create();
cairo_svg_surface_restrict_to_version();
v6 = cairo_create();
cairo_set_source_rgb();
cairo_select_font_face();
cairo_set_font_size();
gen_page_1(v6, "Sans", 40.0, 0.0);
goto LABEL_5;
}
if ( !strcmp("1_2", v3) )
{
cairo_svg_surface_create();
cairo_svg_surface_restrict_to_version();
v4 = cairo_create();
cairo_set_source_rgb();
cairo_select_font_face();
cairo_set_font_size();
gen_page_1(v4, "Sans", 40.0, 0.0);
gen_page_2(v4);
LABEL_5:
cairo_surface_destroy();
cairo_destroy();
return 0;
}
fwrite("ERROR: SVG version must be 1_1 or 1_2!\n", 1uLL, 0x27uLL, stderr);
result = -1;
}
else
{
fprintf(stderr, "%s [svg_version] [output file]\n", *argv);
fwrite("\tsvg version = 1_1 or 1_2\n", 1uLL, 0x1AuLL, stderr);
result = -1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r8
__int64 v4; // rbp
int result; // eax
__int64 v6; // rbp

if ( argc == 3 )
{
v3 = argv[1];
if ( !strcmp("1_1", v3) )
{
cairo_svg_surface_create();
cairo_svg_surface_restrict_to_version();
v6 = cairo_create();
cairo_set_source_rgb();
cairo_select_font_face();
cairo_set_font_size();
func7(v6, "Sans", 40.0, 0.0);
goto LABEL_5;
}
if ( !strcmp("1_2", v3) )
{
cairo_svg_surface_create();
cairo_svg_surface_restrict_to_version();
v4 = cairo_create();
cairo_set_source_rgb();
cairo_select_font_face();
cairo_set_font_size();
func7(v4, "Sans", 40.0, 0.0);
func8(v4);
LABEL_5:
cairo_surface_destroy();
cairo_destroy();
return 0;
}
fwrite("ERROR: SVG version must be 1_1 or 1_2!\n", 1uLL, 0x27uLL, stderr);
result = -1;
}
else
{
fprintf(stderr, "%s [svg_version] [output file]\n", *argv);
fwrite("\tsvg version = 1_1 or 1_2\n", 1uLL, 0x1AuLL, stderr);
result = -1;
}
return result;
}


testReallocateFn

repo: munificent/wren

decompiled_code:
void *__fastcall testReallocateFn(void *ptr, size_t size, const char *a3)
{
if ( strcmp(a3, "my user data") )
return 0LL;
if ( size )
return realloc(ptr, size);
free(ptr);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(void *ptr, size_t size, const char *a3)
{
if ( strcmp(a3, "my user data") )
return 0LL;
if ( size )
return realloc(ptr, size);
free(ptr);
return 0LL;
}

original_code:
void* testReallocateFn(void* ptr, size_t newSize, void* userData) {
  if (strcmp(userData, data) != 0) return ((void *)0);
  if (newSize == 0)
  {
    free(ptr);
    return ((void *)0);
  }
  return realloc(ptr, newSize);
}

canonical_original_code:
void *testReallocateFn(void *ptr, unsigned long newSize, void *userData) {
  if (strcmp(userData, data) != 0) return ((void *)0);
  if (newSize == 0)
  {
    free(ptr);
    return ((void *)0);
  }
  return realloc(ptr, newSize);
}

variable_types:
ptr
void *

variable_types:
newSize
unsigned long

variable_types:
userData
void *

return_type: void *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
const char *v5; // r13
char v6; // bl
int v7; // ebp

v3 = handle_args(argc, argv, envp);
if ( !v3 )
{
v5 = argv[1];
v6 = isModuleAnAPITest(v5);
vm = initVM(v6);
v7 = runFile(vm, v5);
if ( v6 )
v3 = APITest_Run(vm, v5);
if ( v7 == 1 )
{
v3 = 65;
}
else if ( v7 == 2 )
{
v3 = 70;
}
else
{
wrenFreeVM(vm);
}
}
return v3;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
const char *v5; // r13
char v6; // bl
int v7; // ebp

v3 = handle_args(argc, argv, envp);
if ( !v3 )
{
v5 = argv[1];
v6 = isModuleAnAPITest(v5);
vm = func0(v6);
v7 = runFile(vm, v5);
if ( v6 )
v3 = APITest_Run(vm, v5);
if ( v7 == 1 )
{
v3 = 65;
}
else if ( v7 == 2 )
{
v3 = 70;
}
else
{
wrenFreeVM(vm);
}
}
return v3;
}

original_code:
int main(int argc, const char* argv[]) {
  int handled = handle_args(argc, argv);
  if(handled != 0) return handled;
  int exitCode = 0;
  const char* testName = argv[1];
  _Bool isAPITest = isModuleAnAPITest(testName);
  vm = initVM(isAPITest);
  WrenInterpretResult result = runFile(vm, testName);
  if(isAPITest) {
    exitCode = APITest_Run(vm, testName);
  }
  if (result == WREN_RESULT_COMPILE_ERROR) return 65;
  if (result == WREN_RESULT_RUNTIME_ERROR) return 70;
  wrenFreeVM(vm);
  return exitCode;
}

canonical_original_code:
int main(int argc, char *argv[]) {
  int handled = handle_args(argc, argv);
  if(handled != 0) return handled;
  int exitCode = 0;
  char *testName = argv[1];
  _Bool isAPITest = isModuleAnAPITest(testName);
  vm = initVM(isAPITest);
  enum WrenInterpretResult result = runFile(vm, testName);
  if(isAPITest) {
    exitCode = APITest_Run(vm, testName);
  }
  if (result == WREN_RESULT_COMPILE_ERROR) return 65;
  if (result == WREN_RESULT_RUNTIME_ERROR) return 70;
  wrenFreeVM(vm);
  return exitCode;
}

variable_types:
argv
char *[]

variable_types: handled int

variable_types: exitCode int

variable_types:
testName
char *

variable_types: enum WrenInterpretResult { WREN_RESULT_SUCCESS=0, WREN_RESULT_COMPILE_ERROR=1, WREN_RESULT_RUNTIME_ERROR=2 }