decompiled_code:
int __fastcall run_fork_child(__int64 a1)
{
int result; // eax
int *v2; // rax
char *v3; // rax

limitres((_QWORD *)a1);
stdinout_redirect((char *)(a1 + 10272), (char *)(a1 + 14368));
chrootjail((char *)(a1 + 0x2000));
kill(*(_DWORD *)(a1 + 16476), 10);
change_uid();
result = execl((const char *)(a1 + 4096), (const char *)(a1 + 2048), 0LL);
if ( result == -1 )
{
puts("Can't execl.");
v2 = _errno_location();
v3 = strerror(*v2);
result = puts(v3);
}
return result;
}

canonical_decompiled_code:
int __fastcall func14(__int64 a1)
{
int result; // eax
int *v2; // rax
char *v3; // rax

func1((_QWORD *)a1);
func13((char *)(a1 + 10272), (char *)(a1 + 14368));
func5((char *)(a1 + 0x2000));
kill(*(_DWORD *)(a1 + 16476), 10);
func4();
result = execl((const char *)(a1 + 4096), (const char *)(a1 + 2048), 0LL);
if ( result == -1 )
{
puts("Can't execl.");
v2 = _errno_location();
v3 = strerror(*v2);
result = puts(v3);
}
return result;
}

original_code:
void run_fork_child(struct RunItem* ri)
{
 limitres(ri);
 stdinout_redirect(ri->bc_in, ri->tmp_out);
 chrootjail(ri->chroot_path);
 kill(ri->fpid, 10);
 change_uid();
 if (execl(ri->prog_jail_path, ri->prog_file, ((void *)0)) == -1)
 {
  printf("Can't execl.\n");
  printf("%s\n", strerror((*__errno_location ())));
 }
}

canonical_original_code:
void run_fork_child(struct RunItem *ri)
{
 limitres(ri);
 stdinout_redirect(ri->bc_in, ri->tmp_out);
 chrootjail(ri->chroot_path);
 kill(ri->fpid, 10);
 change_uid();
 if (execl(ri->prog_jail_path, ri->prog_file, ((void *)0)) == -1)
 {
  printf("Can't execl.\n");
  printf("%s\n", strerror((*__errno_location ())));
 }
}


run

repo: liheyuan/lincore

decompiled_code:
__int64 __fastcall run(char *src)
{
__pid_t v2; // eax

if ( (unsigned int)run_check((__int64)src) || (unsigned int)run_before(src) )
return *((unsigned int *)src + 4108);
v2 = fork();
*((_DWORD *)src + 4118) = v2;
if ( v2 != -1 )
{
if ( !v2 )
{
run_fork_child((__int64)src);
exit(0);
}
while ( !(unsigned int)run_father_while((__int64)src) )
;
run_after((__int64)src);
return *((unsigned int *)src + 4108);
}
*((_DWORD *)src + 4108) = 8;
return 8LL;
}

canonical_decompiled_code:
__int64 __fastcall func15(char *src)
{
__pid_t v2; // eax

if ( (unsigned int)func0((__int64)src) || (unsigned int)func7(src) )
return *((unsigned int *)src + 4108);
v2 = fork();
*((_DWORD *)src + 4118) = v2;
if ( v2 != -1 )
{
if ( !v2 )
{
func14((__int64)src);
exit(0);
}
while ( !(unsigned int)func11((__int64)src) )
;
func12((__int64)src);
return *((unsigned int *)src + 4108);
}
*((_DWORD *)src + 4108) = 8;
return 8LL;
}

original_code:
int run(struct RunItem *ri)
{
 pid_t cpid;
 if (run_check(ri))
 {
  return ri->result;
 }
 if (run_before(ri))
 {
  return ri->result;
 }
 ri->cpid = cpid = fork();
 if (cpid == -1)
 {
  ri->result = 8;
  return ri->result;
 }
 else if (cpid == 0)
 {
  run_fork_child(ri);
  exit(0);
 }
 else
 {
  while (1)
  {
   if (run_father_while(ri))
   {
    break;
   }
  }
  run_after(ri);
  return ri->result;
 }
}

canonical_original_code:
int run(struct RunItem *ri)
{
 int cpid;
 if (run_check(ri))
 {
  return ri->result;
 }
 if (run_before(ri))
 {
  return ri->result;
 }
 ri->cpid = cpid = fork();
 if (cpid == -1)
 {
  ri->result = 8;
  return ri->result;
 }
 else if (cpid == 0)
 {
  run_fork_child(ri);
  exit(0);
 }
 else
 {
  while (1)
  {
   if (run_father_while(ri))
   {
    break;
   }
  }
  run_after(ri);
  return ri->result;
 }
}

variable_types: struct RunItem { char prog_path[2048]; char prog_file[2048]; char prog_jail_path[2048]; char prog_jail_path_temp[2048]; char chroot_path[2048]; unsigned long long tl; unsigned long long ml; unsigned long long sl; unsigned long long ol; char bc_in[2048]; char bc_out[2048]; char tmp_out[2048]; unsigned long long use_mem; unsigned long long use_time; int result; struct timeval { long tv_sec; long tv_usec; } t_begin; struct timeval t_end; int cpid; int fpid; } *

variable_types: cpid int

return_type: int

user_defined_types: struct RunItem { char prog_path[2048]; char prog_file[2048]; char prog_jail_path[2048]; char prog_jail_path_temp[2048]; char chroot_path[2048]; unsigned long long tl; unsigned long long ml; unsigned long long sl; unsigned long long ol; char bc_in[2048]; char bc_out[2048]; char tmp_out[2048]; unsigned long long use_mem; unsigned long long use_time; int result; struct timeval t_begin; struct timeval t_end; int cpid; int fpid; }


decompiled_code:
int __fastcall exe_priv(const char *a1)
{
return chmod(a1, 0x1FFu);
}

canonical_decompiled_code:
int __fastcall func3(const char *a1)
{
return chmod(a1, 0x1FFu);
}

original_code:
int exe_priv(char* file)
{
 return chmod(file, 00777);
}

canonical_original_code:
int exe_priv(char *file)
{
 return chmod(file, 00777);
}

variable_types:
file
char *


delete

decompiled_code:
// attributes: thunk
int delete(const char *name)
{
return unlink(name);
}

canonical_decompiled_code:
int func4(const char *name)
{
return unlink(name);
}

original_code:
int delete(char* path)
{
 return unlink(path);
}

canonical_original_code:
int delete(char *path)
{
 return unlink(path);
}

variable_types:
path
char *


isfileok

decompiled_code:
_BOOL8 __fastcall isfileok(char *name)
{
int v1; // er8
_BOOL8 result; // rax

v1 = access(name, 0);
result = 0LL;
if ( !v1 )
result = access(name, 4) == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(char *name)
{
int v1; // er8
_BOOL8 result; // rax

v1 = access(name, 0);
result = 0LL;
if ( !v1 )
result = access(name, 4) == 0;
return result;
}

original_code:
int isfileok(char* path)
{
 if (access(path, 0) == 0 && access(path, 4) == 0)
 {
  return 1;
 }
 else
 {
  return 0;
 }
}

canonical_original_code:
int isfileok(char *path)
{
 if (access(path, 0) == 0 && access(path, 4) == 0)
 {
  return 1;
 }
 else
 {
  return 0;
 }
}


isdirok

decompiled_code:
_BOOL8 __fastcall isdirok(const char *a1)
{
int v1; // eax
_BOOL4 v2; // er8
struct stat v4; // [rsp+0h] [rbp-98h] BYREF

v1 = lstat(a1, &v4);
v2 = 0;
if ( v1 != -1 && (v4.st_mode & 0xF000) == 0x4000 && (v4.st_mode & 0x1C0) != 0 )
v2 = (v4.st_mode & 0x2D) == 45;
return v2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(const char *a1)
{
int v1; // eax
_BOOL4 v2; // er8
struct stat v4; // [rsp+0h] [rbp-98h] BYREF

v1 = lstat(a1, &v4);
v2 = 0;
if ( v1 != -1 && (v4.st_mode & 0xF000) == 0x4000 && (v4.st_mode & 0x1C0) != 0 )
v2 = (v4.st_mode & 0x2D) == 45;
return v2;
}

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

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


curtime

decompiled_code:
int __fastcall curtime(struct timeval *a1)
{
return gettimeofday(a1, 0LL);
}

canonical_decompiled_code:
int __fastcall func0(struct timeval *a1)
{
return gettimeofday(a1, 0LL);
}

original_code:
void curtime(struct timeval* time)
{
 gettimeofday(time, ((void *)0));
}

canonical_original_code:
void curtime(struct timeval *time)
{
 gettimeofday(time, ((void *)0));
}

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

return_type: void


mydifftime

original_code:
unsigned long long mydifftime(struct timeval* begin, struct timeval* end)
{
 if (begin->tv_sec == 0 && begin->tv_usec == 0)
 {
  return 0;
 }
 else
 {
  long long diff = (end->tv_sec - begin->tv_sec) * 1000000
    + (end->tv_usec - begin->tv_usec);
  if (diff < 0)
  {
   return 0;
  }
  diff /= 1000;
  return diff;
 }
}

canonical_original_code:
unsigned long long mydifftime(struct timeval *begin, struct timeval *end)
{
 if (begin->tv_sec == 0 && begin->tv_usec == 0)
 {
  return 0;
 }
 else
 {
  long long diff = (end->tv_sec - begin->tv_sec) * 1000000
    + (end->tv_usec - begin->tv_usec);
  if (diff < 0)
  {
   return 0;
  }
  diff /= 1000;
  return diff;
 }
}

variable_types:
end
struct timeval *

variable_types:
diff
long long

return_type: unsigned long long

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


max

decompiled_code:
unsigned __int64 __fastcall max(unsigned __int64 a1, unsigned __int64 a2)
{
unsigned __int64 result; // rax

result = a2;
if ( a1 >= a2 )
result = a1;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func4(unsigned __int64 a1, unsigned __int64 a2)
{
unsigned __int64 result; // rax

result = a2;
if ( a1 >= a2 )
result = a1;
return result;
}

original_code:
unsigned long long max(unsigned long a, unsigned long b)
{
 if (a >= b)
 {
  return a;
 }
 else
 {
  return b;
 }
}

variable_types:
a
unsigned long

variable_types:
b
unsigned long


decompiled_code:
char *__fastcall print_bytes(unsigned __int8 *a1, int a2)
{
unsigned __int8 *v2; // rbx
char *v3; // r12
__int64 v4; // r14
__int64 v5; // rdx
char *v6; // rdi
char *result; // rax

if ( a2 > 0 )
{
v2 = a1;
v3 = buf_0;
v4 = (__int64)&a1[a2 - 1 + 1];
do
{
v5 = *v2;
v6 = v3;
++v2;
v3 += 2;
sprintf(v6, "%02X", v5);
}
while ( v2 != (unsigned __int8 *)v4 );
}
result = buf_0;
buf_0[2 * a2] = 0;
return result;
}

canonical_decompiled_code:
char *__fastcall func4(unsigned __int8 *a1, int a2)
{
unsigned __int8 *v2; // rbx
char *v3; // r12
__int64 v4; // r14
__int64 v5; // rdx
char *v6; // rdi
char *result; // rax

if ( a2 > 0 )
{
v2 = a1;
v3 = buf_0;
v4 = (__int64)&a1[a2 - 1 + 1];
do
{
v5 = *v2;
v6 = v3;
++v2;
v3 += 2;
sprintf(v6, "%02X", v5);
}
while ( v2 != (unsigned __int8 *)v4 );
}
result = buf_0;
buf_0[2 * a2] = 0;
return result;
}

original_code:
char* print_bytes(gconstpointer p,int size){
    static char buf[10000];
    int t=0;
    for(t=0;t<size;t++){
        sprintf(buf+t*2,"%02X",(*(const guchar*)(p+t)));
    }
    buf[size*2]=0;
    return buf;
}

canonical_original_code:
char *print_bytes(void *p, int size){
    static char buf[10000];
    int t = 0;
    for(t=0;t<size;t++){
        sprintf(buf+t*2,"%02X",(*(unsigned char *)(p+t)));
    }
    buf[size*2]=0;
    return buf;
}

variable_types:
p
void *

variable_types: size int

variable_types:
buf
char [10000]

variable_types: t int

return_type: char *


original_code:
TaskQueue *queue_init(TaskQueue *f,int size1,int size2,int size3){
    if(f==((void *)0)){
        f=((TaskQueue *) g_malloc_n ((1), sizeof (TaskQueue)));
    }
    f->size1=size1;
    f->size2=size2;
    f->size3=size3;
    f->size3_=1;
    f->interval=((Double *) g_malloc_n ((size3+1), sizeof (Double)));
    f->interval[0]=((double)1.79769313486231570814527423731704357e+308L);
    f->dataSize=((int *) g_malloc_n ((size3+1), sizeof (int)));
    f->data=((gpointer *) g_malloc_n ((size3+1), sizeof (gpointer)));
    f->data[0]=g_malloc(size1*(size2+1));
    f->dataSize[0]=0;
    return f;
}

canonical_original_code:
struct _TaskQueue *queue_init(struct _TaskQueue *f, int size1, int size2, int size3){
    if(f==((void *)0)){
        f=((struct _TaskQueue *) g_malloc_n ((1), sizeof (TaskQueue)));
    }
    f->size1=size1;
    f->size2=size2;
    f->size3=size3;
    f->size3_=1;
    f->interval=((double *) g_malloc_n ((size3+1), sizeof (Double)));
    f->interval[0]=((double)1.79769313486231570814527423731704357e+308L);
    f->dataSize=((int *) g_malloc_n ((size3+1), sizeof (int)));
    f->data=((void **) g_malloc_n ((size3+1), sizeof (gpointer)));
    f->data[0]=g_malloc(size1*(size2+1));
    f->dataSize[0]=0;
    return f;
}

variable_types:
f
struct _TaskQueue *

return_type: struct _TaskQueue { int size1; int size2; int size3; int size3_; double *interval; int *dataSize; void **data; } *


original_code:
gpointer queue_pull(TaskQueue *queue){
    do { if (queue->size3_>0) ; else g_assertion_message_expr (((gchar*) 0), "queue.c", 79, ((const char*) (__func__)), "queue->size3_>0"); } while (0);
    gpointer f=queue->data[0];
    *(Dollar*)(f+queue->dataSize[0]*queue->size1)=-1.;
    int t;
    queue->size3_--;
    for(t=0;t<queue->size3_;t++){
        queue->data[t]=queue->data[t+1];
        queue->dataSize[t]=queue->dataSize[t+1];
        queue->interval[t]=queue->interval[t+1];
    }
    if(queue->size3_==0){
        queue->data[0]=g_malloc(queue->size1*(queue->size2+1));
        queue->dataSize[0]=0;
        queue->size3_++;
    }
    return f;
}

canonical_original_code:
void *queue_pull(struct _TaskQueue *queue){
    do { if (queue->size3_>0) ; else g_assertion_message_expr (((char *) 0), "queue.c", 79, ((char *) (__func__)), "queue->size3_>0"); } while (0);
    void *f = queue->data[0];
    *(double *)(f+queue->dataSize[0]*queue->size1)=-1.;
    int t;
    queue->size3_--;
    for(t=0;t<queue->size3_;t++){
        queue->data[t]=queue->data[t+1];
        queue->dataSize[t]=queue->dataSize[t+1];
        queue->interval[t]=queue->interval[t+1];
    }
    if(queue->size3_==0){
        queue->data[0]=g_malloc(queue->size1*(queue->size2+1));
        queue->dataSize[0]=0;
        queue->size3_++;
    }
    return f;
}

variable_types: struct _TaskQueue { int size1; int size2; int size3; int size3_; double *interval; int *dataSize; void **data; } *

variable_types:
f
void *

return_type: void *


quickselect

original_code:
Double quickselect(gpointer block,gpointer tmp,int size,gint32 b,gint32 c){
    gint32 r1,r2;
    Double key=((double)1.79769313486231570814527423731704357e+308L);
    while(c!=b&&c!=0){
        r1=g_random_int_range(0,b);
        memcpy(tmp,block+(r1*size),size);
        memcpy(block+(r1*size),block,size);
        r2=0;
        key=(*(Dollar*)(tmp));
        for(r1=1;r1<b;r1++){
            if((*(Dollar*)(block+r1*size))<key){
                memcpy(block+r2*size,block+r1*size,size);
                r2++;
                memcpy(block+r1*size,block+r2*size,size);
            }
        }
        memcpy(block+r2*size,tmp,size);
        if(r2<c){
            r2++;
            block+=r2*size;
            b-=r2;
            c-=r2;
        }else{
            b=r2;
        }
    }
    return key;
}

canonical_original_code:
double quickselect(void *block, void *tmp, int size, int b, int c){
    int r1; int r2;
    double key = ((double)1.79769313486231570814527423731704357e+308L);
    while(c!=b&&c!=0){
        r1=g_random_int_range(0,b);
        memcpy(tmp,block+(r1*size),size);
        memcpy(block+(r1*size),block,size);
        r2=0;
        key=(*(double *)(tmp));
        for(r1=1;r1<b;r1++){
            if((*(double *)(block+r1*size))<key){
                memcpy(block+r2*size,block+r1*size,size);
                r2++;
                memcpy(block+r1*size,block+r2*size,size);
            }
        }
        memcpy(block+r2*size,tmp,size);
        if(r2<c){
            r2++;
            block+=r2*size;
            b-=r2;
            c-=r2;
        }else{
            b=r2;
        }
    }
    return key;
}

variable_types:
block
void *

variable_types:
tmp
void *

variable_types: b int

variable_types: c int

variable_types: key double

return_type: double


original_code:
gchar queue_insert(TaskQueue *queue,gconstpointer element){
    Double key=*(Double*) element;
    int t=-1;
    int ret=0;
    while(queue->interval[++t]<key){}
    if(queue->dataSize[t]<queue->size2){
        void* tmp=malloc(queue->size1);
        memcpy(tmp,element,queue->size1);
        memcpy(queue->data[t]+(queue->dataSize[t])*queue->size1,tmp,queue->size1);
        memcpy(queue->data[t]+(queue->dataSize[t])*queue->size1,element,queue->size1);
        queue->dataSize[t]++;
        ret=0;
    }else{
        gpointer block=queue->data[t];
        memcpy(block+queue->size2*queue->size1,element,queue->size1);
        gpointer tmp=(gpointer)g_malloc(queue->size1);
        Double cutoff = quickselect(block,tmp,queue->size1,(gint32)queue->size2+1,(gint32)((queue->size2+1)/2));
        g_free(tmp);
        int t2;
        for(t2=queue->size3_;t2>t;t2--){
            queue->data[t2]=queue->data[t2-1];
            queue->dataSize[t2]=queue->dataSize[t2-1];
            queue->interval[t2]=queue->interval[t2-1];
        }
        queue->dataSize[t]=(queue->size2+1)/2;
        queue->size3_++;
        if(t!=queue->size3-1){
            int newSize=queue->size2/2+1;
            queue->data[t+1]=((void *)0);
            queue->data[t+1]=(gpointer)g_malloc(queue->size1*(queue->size2+1));
            queue->dataSize[t+1]=newSize;
            memcpy(queue->data[t+1],block+((queue->size2+1)/2)*queue->size1,newSize*queue->size1);
            queue->interval[t]=cutoff;
            if(queue->size3_>queue->size3){
                queue->size3_--;
                g_free(queue->data[queue->size3]);
                queue->interval[queue->size3-1]=((double)1.79769313486231570814527423731704357e+308L);
                ret=3;
            }else{
                ret=2;
            }
        }else{
            queue->size3_--;
            ret=1;
        }
    }
    return ret;
}

canonical_original_code:
char queue_insert(struct _TaskQueue *queue, void *element){
    double key = *(Double*) element;
    int t = -1;
    int ret = 0;
    while(queue->interval[++t]<key){}
    if(queue->dataSize[t]<queue->size2){
        void *tmp = malloc(queue->size1);
        memcpy(tmp,element,queue->size1);
        memcpy(queue->data[t]+(queue->dataSize[t])*queue->size1,tmp,queue->size1);
        memcpy(queue->data[t]+(queue->dataSize[t])*queue->size1,element,queue->size1);
        queue->dataSize[t]++;
        ret=0;
    }else{
        void *block = queue->data[t];
        memcpy(block+queue->size2*queue->size1,element,queue->size1);
        void *tmp = (gpointer)g_malloc(queue->size1);
        double cutoff = quickselect(block,tmp,queue->size1,(gint32)queue->size2+1,(gint32)((queue->size2+1)/2));
        g_free(tmp);
        int t2;
        for(t2=queue->size3_;t2>t;t2--){
            queue->data[t2]=queue->data[t2-1];
            queue->dataSize[t2]=queue->dataSize[t2-1];
            queue->interval[t2]=queue->interval[t2-1];
        }
        queue->dataSize[t]=(queue->size2+1)/2;
        queue->size3_++;
        if(t!=queue->size3-1){
            int newSize = queue->size2/2+1;
            queue->data[t+1]=((void *)0);
            queue->data[t+1]=(void *)g_malloc(queue->size1*(queue->size2+1));
            queue->dataSize[t+1]=newSize;
            memcpy(queue->data[t+1],block+((queue->size2+1)/2)*queue->size1,newSize*queue->size1);
            queue->interval[t]=cutoff;
            if(queue->size3_>queue->size3){
                queue->size3_--;
                g_free(queue->data[queue->size3]);
                queue->interval[queue->size3-1]=((double)1.79769313486231570814527423731704357e+308L);
                ret=3;
            }else{
                ret=2;
            }
        }else{
            queue->size3_--;
            ret=1;
        }
    }
    return ret;
}

variable_types:
element
void *

variable_types: ret int

variable_types: cutoff double

variable_types: newSize int

return_type: char

user_defined_types: struct _TaskQueue { int size1; int size2; int size3; int size3_; double *interval; int *dataSize; void **data; }


decompiled_code:
void __fastcall queue_free(void *ptr)
{
__int64 v2; // rbx
__int64 v3; // rdi

if ( *((int *)ptr + 3) > 0 )
{
v2 = 0LL;
do
{
v3 = *(_QWORD *)(*((_QWORD *)ptr + 4) + 8 * v2++);
g_free(v3);
}
while ( *((_DWORD *)ptr + 3) > (int)v2 );
}
free(*((void **)ptr + 2));
free(*((void **)ptr + 3));
free(*((void **)ptr + 4));
free(ptr);
}

original_code:
void queue_free(TaskQueue *queue){
    int t;
    for(t=0;t<queue->size3_;t++){
        g_free(queue->data[t]);
    }
    free(queue->interval);
    free(queue->dataSize);
    free(queue->data);
    free(queue);
}

canonical_original_code:
void queue_free(struct _TaskQueue *queue){
    int t;
    for(t=0;t<queue->size3_;t++){
        g_free(queue->data[t]);
    }
    free(queue->interval);
    free(queue->dataSize);
    free(queue->data);
    free(queue);
}


original_code:
void queue_print(GLogLevelFlags flags, TaskQueue *queue){
    g_log(((gchar*) 0),flags,"--- queue ---");
    g_log(((gchar*) 0),flags,"%4d|%4d|%4d|%4d",queue->size1,queue->size2,queue->size3,queue->size3_);
    int t;
    for(t=0;t<queue->size3_;t++){
        Double a=queue->interval[t];
        int size=queue->dataSize[t];
        g_log(((gchar*) 0),flags,"block:%3d, size:%5d, interval: %5.3lf",t,size,a);
        int t2;
        for(t2=0;t2<size;t2++){
            g_log(((gchar*) 0),flags,"%10.3lf:%s",(*(Dollar*)(queue->data[t]+queue->size1*t2)),print_bytes(queue->data[t]+queue->size1*t2+sizeof(Dollar),queue->size1-sizeof(Dollar)));
        }
    }
    g_log(((gchar*) 0),flags,"--- end queue ---");
}

canonical_original_code:
void queue_print(enum GLogLevelFlags flags, struct _TaskQueue *queue){
    g_log(((char *) 0),flags,"--- queue ---");
    g_log(((char *) 0),flags,"%4d|%4d|%4d|%4d",queue->size1,queue->size2,queue->size3,queue->size3_);
    int t;
    for(t=0;t<queue->size3_;t++){
        double a = queue->interval[t];
        int size = queue->dataSize[t];
        g_log(((char *) 0),flags,"block:%3d, size:%5d, interval: %5.3lf",t,size,a);
        int t2;
        for(t2=0;t2<size;t2++){
            g_log(((char *) 0),flags,"%10.3lf:%s",(*(double *)(queue->data[t]+queue->size1*t2)),print_bytes(queue->data[t]+queue->size1*t2+sizeof(Dollar),queue->size1-sizeof(Dollar)));
        }
    }
    g_log(((char *) 0),flags,"--- end queue ---");
}

variable_types: enum GLogLevelFlags { G_LOG_FLAG_RECURSION=expr, G_LOG_FLAG_FATAL=expr, G_LOG_LEVEL_ERROR=expr, G_LOG_LEVEL_CRITICAL=expr, G_LOG_LEVEL_WARNING=expr, G_LOG_LEVEL_MESSAGE=expr, G_LOG_LEVEL_INFO=expr, G_LOG_LEVEL_DEBUG=expr, G_LOG_LEVEL_MASK=expr }

variable_types: a double


compareTypeCost

decompiled_code:
__int64 __fastcall compareTypeCost(const void *a1, const void *a2)
{
return (*((double *)a1 + 3) > *((double *)a2 + 3)) - (unsigned int)(*((double *)a2 + 3) > *((double *)a1 + 3));
}

canonical_decompiled_code:
__int64 __fastcall func0(const void *a1, const void *a2)
{
return (*((double *)a1 + 3) > *((double *)a2 + 3)) - (unsigned int)(*((double *)a2 + 3) > *((double *)a1 + 3));
}

original_code:
int compareTypeCost (const void *a, const void *b){
    const Double *da = &((const TypeB*) a)->cost;
    const Double *db = &((const TypeB*) b)->cost;
    return (*da > *db) - (*da < *db);
}

canonical_original_code:
int compareTypeCost(void *a, void *b){
    double *da = &((const TypeB*) a)->cost;
    double *db = &((const TypeB*) b)->cost;
    return (*da > *db) - (*da < *db);
}

variable_types:
a
void *

variable_types:
b
void *

variable_types:
da
double *

variable_types:
db
double *


setupTypes

original_code:
int setupTypes(TypeB* types,const char* buf){
    int t;
    for(t=0;t<198;t++){
        int i1,i2,i3;
        Double E,Fy,Density,Area,Moment,CostVol;
        char name[6];
        int n=sscanf(buf,"%d %d %d %5s %lf %lf %lf %lf %lf %lf\n",&i1,&i2,&i3,name,&E,&Fy,&Density,&Area,&Moment,&CostVol);
        while(*(buf++)!='\n'){}
        if(n!=10){
            return 1;
        }
        types[t].index=(Byte)(1*i1+99*i2+3*i3);
        strcpy(types[t].name,name);
        types[t].weight=1.25*Density*Area*9.8066/2000;
        types[t].AE=Area*E;
        types[t].cost=CostVol*Area*Density*2;
        types[t].tensionStrength=0.95*Fy*Area;
        types[t].inverseRadiusOfGyration=sqrt(Area/Moment);
        types[t].FyArea_d_CEMoment=Fy*Area/(9.8696044*E*Moment);
        types[t].FyArea=Fy*Area;
    }
    qsort(types,198,sizeof(TypeB),compareTypeCost);
    for(t=0;t<198;++t){
        types[t].index2=t;
    }
    return 0;
}

canonical_original_code:
int setupTypes(struct TypeB *types, char *buf){
    int t;
    for(t=0;t<198;t++){
        int i1; int i2; int i3;
        double E; double Fy; double Density; double Area; double Moment; double CostVol;
        char name[6];
        int n = sscanf(buf,"%d %d %d %5s %lf %lf %lf %lf %lf %lf\n",&i1,&i2,&i3,name,&E,&Fy,&Density,&Area,&Moment,&CostVol);
        while(*(buf++)!='\n'){}
        if(n!=10){
            return 1;
        }
        types[t].index=(Byte)(1*i1+99*i2+3*i3);
        strcpy(types[t].name,name);
        types[t].weight=1.25*Density*Area*9.8066/2000;
        types[t].AE=Area*E;
        types[t].cost=CostVol*Area*Density*2;
        types[t].tensionStrength=0.95*Fy*Area;
        types[t].inverseRadiusOfGyration=sqrt(Area/Moment);
        types[t].FyArea_d_CEMoment=Fy*Area/(9.8696044*E*Moment);
        types[t].FyArea=Fy*Area;
    }
    qsort(types,198,sizeof(TypeB),compareTypeCost);
    for(t=0;t<198;++t){
        types[t].index2=t;
    }
    return 0;
}

variable_types: struct TypeB { unsigned char index; unsigned char index2; char name[6]; double weight; double AE; double cost; double tensionStrength; double inverseRadiusOfGyration; double FyArea_d_CEMoment; double FyArea; } *

variable_types:
buf
char *

variable_types: t int

variable_types: E double

variable_types: Fy double

variable_types: Density double

variable_types: Area double

variable_types: Moment double

variable_types: CostVol double

variable_types:
name
char [6]

variable_types: n int


getCompressionStrength

decompiled_code:
double __fastcall getCompressionStrength(__int64 a1, double a2)
{
double v2; // xmm1_8
double result; // xmm0_8

v2 = a2 * a2 * *(double *)(a1 + 48);
if ( v2 <= 2.25 )
result = pow(0.66, v2) * 0.9 * *(double *)(a1 + 56);
else
result = 0.792 * *(double *)(a1 + 56) / v2;
return result;
}

canonical_decompiled_code:
double __fastcall func2(__int64 a1, double a2)
{
double v2; // xmm1_8
double result; // xmm0_8

v2 = a2 * a2 * *(double *)(a1 + 48);
if ( v2 <= 2.25 )
result = pow(0.66, v2) * 0.9 * *(double *)(a1 + 56);
else
result = 0.792 * *(double *)(a1 + 56) / v2;
return result;
}

original_code:
Double getCompressionStrength(const TypeB* type,Double length){
  Double lambda=length*length*type->FyArea_d_CEMoment;
  return lambda<=2.25?
           0.9*pow(0.66,lambda)*type->FyArea:
           0.792*type->FyArea/lambda;
}

canonical_original_code:
double getCompressionStrength(struct TypeB *type, double length){
  double lambda = length*length*type->FyArea_d_CEMoment;
  return lambda<=2.25?
           0.9*pow(0.66,lambda)*type->FyArea:
           0.792*type->FyArea/lambda;
}

variable_types: length double

variable_types: lambda double

user_defined_types: struct TypeB { unsigned char index; unsigned char index2; char name[6]; double weight; double AE; double cost; double tensionStrength; double inverseRadiusOfGyration; double FyArea_d_CEMoment; double FyArea; }


ifPassType

decompiled_code:
_BOOL8 __fastcall ifPassType(__int64 a1, double a2, double a3, double a4, double a5)
{
_BOOL8 result; // rax

if ( *(double *)(a1 + 32) >= a3 && a5 > *(double *)(a1 + 40) * a4 )
result = getCompressionStrength(a1, a4) >= a2;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(__int64 a1, double a2, double a3, double a4, double a5)
{
_BOOL8 result; // rax

if ( *(double *)(a1 + 32) >= a3 && a5 > *(double *)(a1 + 40) * a4 )
result = func2(a1, a4) >= a2;
else
result = 0LL;
return result;
}

original_code:
Bool ifPassType(const TypeB* type,Double compression,Double tension,Double length,Double slenderness){
  return (tension <= type->tensionStrength)&&
         (slenderness>length*type->inverseRadiusOfGyration)&&
         (compression <= getCompressionStrength(type,length));
}

canonical_original_code:
int ifPassType(struct TypeB *type, double compression, double tension, double length, double slenderness){
  return (tension <= type->tensionStrength)&&
         (slenderness>length*type->inverseRadiusOfGyration)&&
         (compression <= getCompressionStrength(type,length));
}

variable_types: compression double

variable_types: tension double

variable_types: slenderness double


original_code:
char* type_print(const TypeB* type){
    static char buf[200];
    sprintf(buf,"type[%s|%0.4lfkN|%7.0lf_|$%4.2lf|%5.2lfkN|%3.3lf/m|%3.3lf_|%5.2lfkN]",
            type->name,
            type->weight,
            type->AE,
            type->cost,
            type->tensionStrength,
            type->inverseRadiusOfGyration,
            type->FyArea_d_CEMoment,
            type->FyArea);
    return buf;
}

canonical_original_code:
char *type_print(struct TypeB *type){
    static char buf[200];
    sprintf(buf,"type[%s|%0.4lfkN|%7.0lf_|$%4.2lf|%5.2lfkN|%3.3lf/m|%3.3lf_|%5.2lfkN]",
            type->name,
            type->weight,
            type->AE,
            type->cost,
            type->tensionStrength,
            type->inverseRadiusOfGyration,
            type->FyArea_d_CEMoment,
            type->FyArea);
    return buf;
}

variable_types:
buf
char [200]


readFile

decompiled_code:
__int64 __fastcall readFile(__int64 a1, int a2)
{
__int64 result; // rax
__int64 v3; // [rsp+8h] [rbp-28h] BYREF
__int64 v4; // [rsp+10h] [rbp-20h] BYREF
int v5[4]; // [rsp+18h] [rbp-18h] BYREF

v3 = 0LL;
v4 = 0LL;
g_file_get_contents(a1, &v4, v5, &v3);
if ( v3 )
{
g_log(0LL, 8LL, "ERROR: %s\n", *(const char **)(v3 + 8));
g_error_free(v3);
result = 0LL;
}
else
{
if ( a2 )
endecrypt_rc4(v4, v5[0]);
result = v4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
__int64 result; // rax
__int64 v3; // [rsp+8h] [rbp-28h] BYREF
__int64 v4; // [rsp+10h] [rbp-20h] BYREF
int v5[4]; // [rsp+18h] [rbp-18h] BYREF

v3 = 0LL;
v4 = 0LL;
g_file_get_contents(a1, &v4, v5, &v3);
if ( v3 )
{
g_log(0LL, 8LL, "ERROR: %s\n", *(const char **)(v3 + 8));
g_error_free(v3);
result = 0LL;
}
else
{
if ( a2 )
endecrypt_rc4(v4, v5[0]);
result = v4;
}
return result;
}

original_code:
guchar* readFile(const gchar* path,Bool encrypt){
    GError* error=((void *)0);
    guchar *buf=((void *)0);
    gsize size;
    g_file_get_contents(path,&buf,&size,&error);
    if (error) {
        g_log (((gchar*) 0), G_LOG_LEVEL_CRITICAL, "ERROR: %s\n",error->message);
        g_error_free(error);
        return 0;
    }
    if(encrypt){
        endecrypt_rc4(buf,(int)size);
    }
    return buf;
}

canonical_original_code:
unsigned char *readFile(char *path, int encrypt){
    struct _GError *error = ((void *)0);
    unsigned char *buf = ((void *)0);
    unsigned long size;
    g_file_get_contents(path,&buf,&size,&error);
    if (error) {
        g_log (((char *) 0), G_LOG_LEVEL_CRITICAL, "ERROR: %s\n",error->message);
        g_error_free(error);
        return 0;
    }
    if(encrypt){
        endecrypt_rc4(buf,(int)size);
    }
    return buf;
}

variable_types:
path
char *

variable_types: encrypt int

variable_types: struct _GError { unsigned int domain; int code; char *message; } *

variable_types:
buf
unsigned char *

variable_types:
size
unsigned long

return_type: unsigned char *


writeFile

decompiled_code:
__int64 __fastcall writeFile(__int64 a1, const char *a2, int a3)
{
size_t v4; // rax
size_t v5; // r13
char *v6; // r12

v4 = strlen(a2);
v5 = v4;
if ( a3 )
{
v6 = strndup(a2, v4);
endecrypt_rc4(v6, (int)v5);
g_file_set_contents(a1, v6, v5, 0LL);
free(v6);
}
else
{
g_file_set_contents(a1, a2, v4, 0LL);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const char *a2, int a3)
{
size_t v4; // rax
size_t v5; // r13
char *v6; // r12

v4 = strlen(a2);
v5 = v4;
if ( a3 )
{
v6 = strndup(a2, v4);
endecrypt_rc4(v6, (int)v5);
g_file_set_contents(a1, v6, v5, 0LL);
free(v6);
}
else
{
g_file_set_contents(a1, a2, v4, 0LL);
}
return 0LL;
}

original_code:
int writeFile(const gchar* path, const guchar* buf,Bool encrypt){
    gsize size=strlen(buf);
    GError *error=((void *)0);
    if(encrypt){
        buf=strndup(buf,size);
        endecrypt_rc4(buf,(int)size);
        g_file_set_contents(path,buf,size,error);
        free(buf);
    }else{
        g_file_set_contents(path,buf,size,error);
    }
    if(error!=((void *)0)){
        g_log (((gchar*) 0), G_LOG_LEVEL_CRITICAL, "ERROR: %s\n",error->message);
        g_error_free(error);
        return 2;
    }
    return 0;
}

canonical_original_code:
int writeFile(char *path, unsigned char *buf, int encrypt){
    unsigned long size = strlen(buf);
    struct _GError *error = ((void *)0);
    if(encrypt){
        buf=strndup(buf,size);
        endecrypt_rc4(buf,(int)size);
        g_file_set_contents(path,buf,size,error);
        free(buf);
    }else{
        g_file_set_contents(path,buf,size,error);
    }
    if(error!=((void *)0)){
        g_log (((char *) 0), G_LOG_LEVEL_CRITICAL, "ERROR: %s\n",error->message);
        g_error_free(error);
        return 2;
    }
    return 0;
}

user_defined_types: struct _GError { unsigned int domain; int code; char *message; }


findIndex

decompiled_code:
__int64 __fastcall findIndex(unsigned __int8 *a1, int a2)
{
__int64 result; // rax

result = 0LL;
while ( *a1 != a2 )
{
result = (unsigned int)(result + 1);
a1 += 64;
if ( (_DWORD)result == 198 )
return 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int8 *a1, int a2)
{
__int64 result; // rax

result = 0LL;
while ( *a1 != a2 )
{
result = (unsigned int)(result + 1);
a1 += 64;
if ( (_DWORD)result == 198 )
return 0xFFFFFFFFLL;
}
return result;
}

original_code:
int findIndex(const TypeB *types,int index){
    int t;
    for(t=0;t<198;t++){
        if(types[t].index==index){
            return t;
        }
    }
    return -1;
}

canonical_original_code:
int findIndex(struct TypeB *types, int index){
    int t;
    for(t=0;t<198;t++){
        if(types[t].index==index){
            return t;
        }
    }
    return -1;
}

variable_types: struct TypeB { unsigned char index; unsigned char index2; char name[6]; double weight; double AE; double cost; double tensionStrength; double inverseRadiusOfGyration; double FyArea_d_CEMoment; double FyArea; } *

variable_types: index int

variable_types: t int


rebaseBridge

original_code:
const BridgeInfo* rebaseBridge(const BridgeInfo* bridgeInfo,gpointer thc_ph){
    BridgeInfo* f=g_memdup(bridgeInfo,sizeof(BridgeInfo));
    f->buf=strdup(f->buf);
    gchar *buf2=f->buf+19 +f->fixedJointSize*6;
    PositionHintB *position=(PositionHintB*)(thc_ph+(sizeof(Dollar)+8*sizeof(Byte)+(f->memberSize)));
    int t1;
    for(t1=f->fixedJointSize;t1<f->totalJointSize;++t1){
        int t2=t1-f->fixedJointSize;
        f->positionHint.xy[t1*2 ]+=((((position->joints[t2]>>4)&15)^8)-8);
        f->positionHint.xy[t1*2+1]+=((((position->joints[t2] )&15)^8)-8);
        sprintf(buf2,"%3d%3d",f->positionHint.xy[t1*2 ],f->positionHint.xy[t1*2+1]);
        buf2+=6;
    }
    memcpy(&f->typeHint,thc_ph,(sizeof(Dollar)+8*sizeof(Byte)+(f->memberSize)));
    char end=*(buf2+8*f->memberSize);
    for(t1=0;t1<f->memberSize;t1++){
        int i=f->types[f->typeHint.bundle[f->typeHint.member[t1]]].index;
        int i1,i2,i3;
        i1=(i)%3;i2=(i)/99;i3=((i)/3)%33;
        sprintf(buf2,"%2d%2d%1d%1d%2d",f->memberLinks[t1].j1+1,f->memberLinks[t1].j2+1,i1,i2,i3);
        buf2+=8;
    }
    *buf2=end;
    return f;
}

canonical_original_code:
struct _BridgeInfo *rebaseBridge(struct _BridgeInfo *bridgeInfo, void *thc_ph){
    struct _BridgeInfo *f = g_memdup(bridgeInfo,sizeof(BridgeInfo));
    f->buf=strdup(f->buf);
    char *buf2 = f->buf+19 +f->fixedJointSize*6;
    struct PositionHintB *position = (PositionHintB*)(thc_ph+(sizeof(Dollar)+8*sizeof(Byte)+(f->memberSize)));
    int t1;
    for(t1=f->fixedJointSize;t1<f->totalJointSize;++t1){
        int t2 = t1-f->fixedJointSize;
        f->positionHint.xy[t1*2 ]+=((((position->joints[t2]>>4)&15)^8)-8);
        f->positionHint.xy[t1*2+1]+=((((position->joints[t2] )&15)^8)-8);
        sprintf(buf2,"%3d%3d",f->positionHint.xy[t1*2 ],f->positionHint.xy[t1*2+1]);
        buf2+=6;
    }
    memcpy(&f->typeHint,thc_ph,(sizeof(double)+8*sizeof(Byte)+(f->memberSize)));
    char end = *(buf2+8*f->memberSize);
    for(t1=0;t1<f->memberSize;t1++){
        int i = f->types[f->typeHint.bundle[f->typeHint.member[t1]]].index;
        int i1; int i2; int i3;
        i1=(i)%3;i2=(i)/99;i3=((i)/3)%33;
        sprintf(buf2,"%2d%2d%1d%1d%2d",f->memberLinks[t1].j1+1,f->memberLinks[t1].j2+1,i1,i2,i3);
        buf2+=8;
    }
    *buf2=end;
    return f;
}

variable_types:
bridgeInfo
struct _BridgeInfo *

variable_types: struct _BridgeInfo { char *buf; int fixedJointSize; int deckSize; double deckWeight; double backWeight; double frontWeight; double slenderness; int fixedIndex[20]; int typeSize; struct TypeB { unsigned char index; unsigned char index2; char name[6]; double weight; double AE; double cost; double tensionStrength; double inverseRadiusOfGyration; double FyArea_d_CEMoment; double FyArea; } types[198]; double bundleCost; int totalJointSize; int memberSize; struct MemberLink { int j1; } memberLinks[120]; double baseCost; struct PositionHint { int xy[-1]; } positionHint; struct TypeHintCostB { double cost; unsigned char bundle[8]; unsigned char member[120]; } typeHint; } *

variable_types: struct PositionHintB { unsigned char joints[30]; } *

variable_types: end char

variable_types: i int

user_defined_types: struct _BridgeInfo { char *buf; int fixedJointSize; int deckSize; double deckWeight; double backWeight; double frontWeight; double slenderness; int fixedIndex[20]; int typeSize; struct TypeB types[198]; double bundleCost; int totalJointSize; int memberSize; struct MemberLink memberLinks[120]; double baseCost; struct PositionHint positionHint; struct TypeHintCostB typeHint; }


saveBridge

decompiled_code:
__int64 __fastcall saveBridge(__int64 a1, const char **a2)
{
return writeFile(a1, *a2, 1);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, const char **a2)
{
return func1(a1, *a2, 1);
}

original_code:
void saveBridge(const char* path,const BridgeInfo *bridgeInfo){
    writeFile(path,bridgeInfo->buf,(!(0)));
}

canonical_original_code:
void saveBridge(char *path, struct _BridgeInfo *bridgeInfo){
    writeFile(path,bridgeInfo->buf,(!(0)));
}

user_defined_types: struct TypeHintCostB { double cost; unsigned char bundle[8]; unsigned char member[120]; }


decompiled_code:
void *__fastcall log_get_flag(int a1)
{
__int64 i; // rax
char v2; // dl

for ( i = 0LL; i != 8; ++i )
{
v2 = 32;
if ( _bittest(&a1, i) )
v2 = cbuf_1[i];
byte_151[i] = v2;
}
return &buf_0;
}

canonical_decompiled_code:
void *__fastcall func0(int a1)
{
__int64 i; // rax
char v2; // dl

for ( i = 0LL; i != 8; ++i )
{
v2 = 32;
if ( _bittest(&a1, i) )
v2 = cbuf_1[i];
byte_151[i] = v2;
}
return &buf_0;
}

original_code:
const gchar* log_get_flag(GLogLevelFlags flag){
    static gchar buf[]="[RFECWMID]";
    static const gchar cbuf[]={'R','F','E','C','W','M','I','D'};
    int t=0;
    for(t=0;t<8;t++){
        buf[t+1]=(flag&(1<<t))==0?' ':cbuf[t];
    }
    return buf;
}

canonical_original_code:
char *log_get_flag(enum GLogLevelFlags flag){
    static char buf[] = "[RFECWMID]";
    static char cbuf[] = {'R','F','E','C','W','M','I','D'};
    int t = 0;
    for(t=0;t<8;t++){
        buf[t+1]=(flag&(1<<t))==0?' ':cbuf[t];
    }
    return buf;
}

variable_types: enum GLogLevelFlags { G_LOG_FLAG_RECURSION=expr, G_LOG_FLAG_FATAL=expr, G_LOG_LEVEL_ERROR=expr, G_LOG_LEVEL_CRITICAL=expr, G_LOG_LEVEL_WARNING=expr, G_LOG_LEVEL_MESSAGE=expr, G_LOG_LEVEL_INFO=expr, G_LOG_LEVEL_DEBUG=expr, G_LOG_LEVEL_MASK=expr }

variable_types:
buf
char []

variable_types:
cbuf
char []


decompiled_code:
int __fastcall log_func_FILE(__int64 a1, int a2, const char *a3, FILE *a4)
{
const char *v6; // rax

v6 = (const char *)log_get_flag(a2);
fputs(v6, a4);
fputs(a3, a4);
return fputc(10, a4);
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, int a2, const char *a3, FILE *a4)
{
const char *v6; // rax

v6 = (const char *)func0(a2);
fputs(v6, a4);
fputs(a3, a4);
return fputc(10, a4);
}

original_code:
void log_func_FILE(const gchar *log_domain,GLogLevelFlags log_level,const gchar *message,gpointer user_data){
    fputs(log_get_flag(log_level),user_data);
    fputs(message,user_data);
    fputs("\n",user_data);
}

canonical_original_code:
void log_func_FILE(char *log_domain, enum GLogLevelFlags log_level, char *message, void *user_data){
    fputs(log_get_flag(log_level),user_data);
    fputs(message,user_data);
    fputs("\n",user_data);
}

variable_types:
message
char *

user_defined_types: enum GLogLevelFlags { G_LOG_FLAG_RECURSION=expr, G_LOG_FLAG_FATAL=expr, G_LOG_LEVEL_ERROR=expr, G_LOG_LEVEL_CRITICAL=expr, G_LOG_LEVEL_WARNING=expr, G_LOG_LEVEL_MESSAGE=expr, G_LOG_LEVEL_INFO=expr, G_LOG_LEVEL_DEBUG=expr, G_LOG_LEVEL_MASK=expr }


decompiled_code:
__int64 __fastcall log_func_iochannel(__int64 a1, int a2, __int64 a3, __int64 a4)
{
void *v6; // rax

v6 = log_get_flag(a2);
g_io_channel_write_chars(a4, v6, -1LL, 0LL, 0LL);
g_io_channel_write_chars(a4, a3, -1LL, 0LL, 0LL);
return g_io_channel_write_chars(a4, &unk_15C, -1LL, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2, __int64 a3, __int64 a4)
{
void *v6; // rax

v6 = func0(a2);
g_io_channel_write_chars(a4, v6, -1LL, 0LL, 0LL);
g_io_channel_write_chars(a4, a3, -1LL, 0LL, 0LL);
return g_io_channel_write_chars(a4, &unk_15C, -1LL, 0LL, 0LL);
}

original_code:
void log_func_iochannel(const gchar *log_domain,GLogLevelFlags log_level,const gchar *message,gpointer user_data){
    g_io_channel_write_chars(user_data,log_get_flag(log_level),-1,((void *)0),((void *)0));
    g_io_channel_write_chars(user_data,message,-1,((void *)0),((void *)0));
    g_io_channel_write_chars(user_data,"\n",-1,((void *)0),((void *)0));
}

canonical_original_code:
void log_func_iochannel(char *log_domain, enum GLogLevelFlags log_level, char *message, void *user_data){
    g_io_channel_write_chars(user_data,log_get_flag(log_level),-1,((void *)0),((void *)0));
    g_io_channel_write_chars(user_data,message,-1,((void *)0),((void *)0));
    g_io_channel_write_chars(user_data,"\n",-1,((void *)0),((void *)0));
}


original_code:
void result_print(GLogLevelFlags flags,const Result* result, const BridgeInfo *bridgeInfo,TypeHintCostB *thc){
    g_log(((gchar*) 0),flags,"--- result ---");
    int jointSize=bridgeInfo->totalJointSize;
    int t1,t2;
    g_log(((gchar*) 0),flags,"cost: %lf",(*(Dollar*)(thc)));
    g_log(((gchar*) 0),flags,"joints:%d , %d",jointSize,bridgeInfo->fixedJointSize);
    g_log(((gchar*) 0),flags,"i :  x  |  y  ");
    for(t1=0;t1<jointSize;t1++){
        g_log(((gchar*) 0),flags,"%2d:%5.2lf|%5.2lf",t1,result->XY[t1*2],result->XY[t1*2+1]);
    }
    int memberSize=bridgeInfo->memberSize;
    g_log(((gchar*) 0),flags,"members:%d",memberSize);
    g_log(((gchar*) 0),flags," i :j1|j2|    T     |    C     |   Tmax   |   Cmax   | T  | C  |length|name");
    for(t1=0;t1<memberSize;t1++){
        const TypeB* type=&bridgeInfo->types[thc->bundle[thc->member[t1]]];
        Double max=result->maxForce[t1];
        Double min=-result->minForce[t1];
        Double max2=type->tensionStrength;
        Double min2=getCompressionStrength(type,result->memberLength[t1]);
        g_log(((gchar*) 0),flags,"%3d:%2d|%2d|%10.2lf|%10.2lf|%10.2lf|%10.2lf|%1.2lf|%1.2lf|%2.3lf|%s",t1,bridgeInfo->memberLinks[t1].j1,bridgeInfo->memberLinks[t1].j2,max,min,max2,min2,max/max2,min/min2,result->memberLength[t1],type->name);
    }
    return 0;
}

canonical_original_code:
void result_print(enum GLogLevelFlags flags, struct _Result *result, struct _BridgeInfo *bridgeInfo, struct TypeHintCostB *thc){
    g_log(((char *) 0),flags,"--- result ---");
    int jointSize = bridgeInfo->totalJointSize;
    int t1; int t2;
    g_log(((char *) 0),flags,"cost: %lf",(*(double *)(thc)));
    g_log(((char *) 0),flags,"joints:%d , %d",jointSize,bridgeInfo->fixedJointSize);
    g_log(((char *) 0),flags,"i :  x  |  y  ");
    for(t1=0;t1<jointSize;t1++){
        g_log(((char *) 0),flags,"%2d:%5.2lf|%5.2lf",t1,result->XY[t1*2],result->XY[t1*2+1]);
    }
    int memberSize = bridgeInfo->memberSize;
    g_log(((char *) 0),flags,"members:%d",memberSize);
    g_log(((char *) 0),flags," i :j1|j2|    T     |    C     |   Tmax   |   Cmax   | T  | C  |length|name");
    for(t1=0;t1<memberSize;t1++){
        struct TypeB *type = &bridgeInfo->types[thc->bundle[thc->member[t1]]];
        double max = result->maxForce[t1];
        double min = -result->minForce[t1];
        double max2 = type->tensionStrength;
        double min2 = getCompressionStrength(type,result->memberLength[t1]);
        g_log(((char *) 0),flags,"%3d:%2d|%2d|%10.2lf|%10.2lf|%10.2lf|%10.2lf|%1.2lf|%1.2lf|%2.3lf|%s",t1,bridgeInfo->memberLinks[t1].j1,bridgeInfo->memberLinks[t1].j2,max,min,max2,min2,max/max2,min/min2,result->memberLength[t1],type->name);
    }
    return 0;
}

variable_types: struct _Result { double XY[-1]; double matrix[-1]; double memberLength[120]; double loads[50]; double jdisplacement[-1]; double memberForce[-1]; double maxForce[120]; double minForce[120]; double totalCost; enum Status { LOADED=0, SOLVED_GOOD=1, SOLVED_UNSTABLE=2, OPTIMIZED_BETTER=3, OPTIMIZED_UNCHANGED=4, OPTIMIZED_WORSE=5, OPTIMIZED_MAX_BUNDLE=6, OPTIMIZED_MAX_COST=7 } status; } *

variable_types:
thc
struct TypeHintCostB *

variable_types: jointSize int

variable_types: memberSize int

variable_types: max double

variable_types: min double

user_defined_types: struct _Result { double XY[-1]; double matrix[-1]; double memberLength[120]; double loads[50]; double jdisplacement[-1]; double memberForce[-1]; double maxForce[120]; double minForce[120]; double totalCost; enum Status status; }


original_code:
void setup_rc4(TRC4State *state, const char *key, int keylen)
{
    unsigned int tmp,x,y;
    if (keylen > 256)
 keylen = 256;
    for (x = 0; x < 256; x++)
        state->buf[x] = x;
    state->x=state->y=0;
    for (x = y = 0; x < 256; x++) {
        y = (y + state->buf[x] + key[x % keylen]) & 255;
        tmp = state->buf[x];
 state->buf[x] = state->buf[y];
 state->buf[y] = tmp;
    }
    state->x = x;
    state->y = y;
}

canonical_original_code:
void setup_rc4(struct TRC4State_t *state, char *key, int keylen)
{
    unsigned int tmp; unsigned int x; unsigned int y;
    if (keylen > 256)
 keylen = 256;
    for (x = 0; x < 256; x++)
        state->buf[x] = x;
    state->x=state->y=0;
    for (x = y = 0; x < 256; x++) {
        y = (y + state->buf[x] + key[x % keylen]) & 255;
        tmp = state->buf[x];
 state->buf[x] = state->buf[y];
 state->buf[y] = tmp;
    }
    state->x = x;
    state->y = y;
}

variable_types: struct TRC4State_t { unsigned char buf[256]; int x; } *

variable_types:
key
char *

variable_types: keylen int

variable_types:
tmp
unsigned int

variable_types:
x
unsigned int

variable_types:
y
unsigned int


original_code:
unsigned long endecrypt_rc4_state(unsigned char *buf, unsigned long len, TRC4State *state)
{
    int x=state->x;
    int y=state->y;
    int i;
    unsigned char *s=(unsigned char*)state;
    unsigned char tmp;
    for(i=0;i<len;i++){
        x=(x+1)&255;
        y=(y+s[x])&255;
        tmp=s[x];
        s[x]=s[y];
        s[y]=tmp;
        buf[i]^=s[(s[x]+s[y])&255];
    }
    state->x=x;
    state->y=y;
    return 0;
}

canonical_original_code:
unsigned long endecrypt_rc4_state(unsigned char *buf, unsigned long len, struct TRC4State_t *state)
{
    int x = state->x;
    int y = state->y;
    int i;
    unsigned char *s = (unsigned char*)state;
    unsigned char tmp;
    for(i=0;i<len;i++){
        x=(x+1)&255;
        y=(y+s[x])&255;
        tmp=s[x];
        s[x]=s[y];
        s[y]=tmp;
        buf[i]^=s[(s[x]+s[y])&255];
    }
    state->x=x;
    state->y=y;
    return 0;
}

variable_types:
buf
unsigned char *

variable_types:
len
unsigned long

variable_types: x int

variable_types: y int

variable_types: i int

variable_types:
s
unsigned char *

variable_types:
tmp
unsigned char

return_type: unsigned long

user_defined_types: struct TRC4State_t { unsigned char buf[256]; int x; }


decompiled_code:
__int64 __fastcall endecrypt_rc4(_BYTE *a1, __int64 a2)
{
char v3[288]; // [rsp+0h] [rbp-120h] BYREF

setup_rc4((__int64)v3, (__int64)"QuenchHollow", 12);
return endecrypt_rc4_state(a1, a2, (__int64)v3);
}

canonical_decompiled_code:
__int64 __fastcall func2(_BYTE *a1, __int64 a2)
{
char v3[288]; // [rsp+0h] [rbp-120h] BYREF

func0((__int64)v3, (__int64)"QuenchHollow", 12);
return func1(a1, a2, (__int64)v3);
}

original_code:
unsigned long endecrypt_rc4(unsigned char *buf, unsigned long len){
  TRC4State state;
  setup_rc4(&state, "QuenchHollow", 12);
  return endecrypt_rc4_state(buf, len, &state);
}

canonical_original_code:
unsigned long endecrypt_rc4(unsigned char *buf, unsigned long len){
  struct TRC4State_t state;
  setup_rc4(&state, "QuenchHollow", 12);
  return endecrypt_rc4_state(buf, len, &state);
}

variable_types: struct TRC4State_t { unsigned char buf[256]; int x; }


original_code:
int test3(){
    TaskQueue *queue=queue_init(((void *)0),sizeof(Double),20,10);
    int t;
    Double tmp;
    for(t=0;t<1000;t++){
        tmp=g_random_double();
        queue_insert(queue,&tmp);
    }
    for(t=0;t<queue->size3_;t++){
        Double a=queue->interval[t];
        int size=queue->dataSize[t];
        int t2;
        printf("block %3d, size: %d, interval: %lf\n",t,size,a);
        for(t2=0;t2<size;t2++){
            printf("%lf ",(*(Double*)(queue->data[t]+queue->size1*t2)));
        }
        printf("\n");
    }
    return 0;
}

canonical_original_code:
int test3(){
    struct _TaskQueue *queue = queue_init(((void *)0),sizeof(Double),20,10);
    int t;
    double tmp;
    for(t=0;t<1000;t++){
        tmp=g_random_double();
        queue_insert(queue,&tmp);
    }
    for(t=0;t<queue->size3_;t++){
        double a = queue->interval[t];
        int size = queue->dataSize[t];
        int t2;
        printf("block %3d, size: %d, interval: %lf\n",t,size,a);
        for(t2=0;t2<size;t2++){
            printf("%lf ",(*(double *)(queue->data[t]+queue->size1*t2)));
        }
        printf("\n");
    }
    return 0;
}

variable_types: struct _TaskQueue { int size1; int size2; int size3; int size3_; double *interval; int *dataSize; void **data; } *

variable_types: t int

variable_types: tmp double

variable_types: a double

variable_types: size int


original_code:
int test4(){
    CostTable *table=table_init(((void *)0),sizeof(Double),16,0.5);
    int size=100;
    int t;
    Double *table2=(Double*)malloc(size*2*sizeof(Double));
    Double tmp1;
    Double tmp2;
    printf("size: %d,%d\n",(int)sizeof(Double),(int)sizeof(Dollar));
    for(t=0;t<size;t++){
        tmp1=g_random_double();
        tmp2=g_random_double();
        table_insert(table,&tmp1,tmp2);
        table2[2*t]=tmp1;
        table2[2*t+1]=tmp2;
        int i=table_hash(&tmp1,8,table->size2);
        printf("%1.5f,%1.5f,%1.5f,%1.5f,%d\n",tmp1,tmp2,*(Double*)(table->data+16*i),*(Double*)(table->data+16*i+8),i);
    }
    table_print(G_LOG_LEVEL_MESSAGE,table);
    table_free(table);
    return 0;
}

canonical_original_code:
int test4(){
    struct _CostTable *table = table_init(((void *)0),sizeof(Double),16,0.5);
    int size = 100;
    int t;
    double *table2 = (Double*)malloc(size*2*sizeof(Double));
    double tmp1;
    double tmp2;
    printf("size: %d,%d\n",(int)sizeof(Double),(int)sizeof(Dollar));
    for(t=0;t<size;t++){
        tmp1=g_random_double();
        tmp2=g_random_double();
        table_insert(table,&tmp1,tmp2);
        table2[2*t]=tmp1;
        table2[2*t+1]=tmp2;
        int i = table_hash(&tmp1,8,table->size2);
        printf("%1.5f,%1.5f,%1.5f,%1.5f,%d\n",tmp1,tmp2,*(double *)(table->data+16*i),*(double *)(table->data+16*i+8),i);
    }
    table_print(G_LOG_LEVEL_MESSAGE,table);
    table_free(table);
    return 0;
}

variable_types: struct _CostTable { int size1; int size2; int size2_; float limit; void *data; } *


writeNum

repo: lijnk/vmtrans

decompiled_code:
void __fastcall writeNum(int a1)
{
int v1; // ebx
int v2; // ebp
size_t v3; // r13
_BYTE *v4; // r12
__int64 v5; // rdx

v1 = a1;
if ( a1 )
{
v2 = (int)log10((double)a1);
v3 = v2 + 1;
v4 = calloc(v2 + 2, 1uLL);
if ( v2 < 0 )
goto LABEL_5;
}
else
{
v2 = 0;
v3 = 1LL;
v4 = calloc(2uLL, 1uLL);
}
v5 = v2;
do
{
v4[v5--] = v1 % 10 + 48;
v1 /= 10;
}
while ( (int)v5 >= 0 );
LABEL_5:
fwrite(v4, 1uLL, v3, vm_ofp);
free(v4);
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
int v1; // ebx
int v2; // ebp
size_t v3; // r13
_BYTE *v4; // r12
__int64 v5; // rdx

v1 = a1;
if ( a1 )
{
v2 = (int)log10((double)a1);
v3 = v2 + 1;
v4 = calloc(v2 + 2, 1uLL);
if ( v2 < 0 )
goto LABEL_5;
}
else
{
v2 = 0;
v3 = 1LL;
v4 = calloc(2uLL, 1uLL);
}
v5 = v2;
do
{
v4[v5--] = v1 % 10 + 48;
v1 /= 10;
}
while ( (int)v5 >= 0 );
LABEL_5:
fwrite(v4, 1uLL, v3, vm_ofp);
free(v4);
}

original_code:
void writeNum(int n)
{
 int len = n==0?1:(int)log10((double)n) + 1;
 int temp = n;
 char* str = (char*) calloc(len+1, sizeof(char));
 for(int i = len-1; i>=0; i--)
 {
  str[i] = (temp % 10) + '0';
  temp /= 10;
 }
 fwrite(str, 1, len, _vm_ofp);
 free(str);
}

canonical_original_code:
void writeNum(int n)
{
 int len = n==0?1:(int)log10((double)n) + 1;
 int temp = n;
 char *str = (char*) calloc(len+1, sizeof(char));
 for(int i = len-1; i>=0; i--)
 {
  str[i] = (temp % 10) + '0';
  temp /= 10;
 }
 fwrite(str, 1, len, _vm_ofp);
 free(str);
}

variable_types: n int

variable_types: len int

variable_types: temp int

variable_types:
str
char *


writeArith

decompiled_code:
int __fastcall writeArith(char *s2)
{
__int64 v1; // rbx
int result; // eax
const char *v3; // rbp
size_t v4; // rax
const char *v5; // rbp
size_t v6; // rax
const char *v7; // rbp
size_t v8; // rax
char *s1; // [rsp+0h] [rbp-A8h]
char *s[20]; // [rsp+8h] [rbp-A0h]

v1 = 0LL;
s1 = (char *)&unk_E49;
s[0] = "D=D+M\n";
s[1] = "sub";
s[2] = "D=D-M\n";
s[3] = "or";
s[4] = "D=D|M\n";
s[5] = "and";
s[6] = "D=D&M\n";
s[7] = "not";
s[8] = "M=!M\n";
s[9] = "neg";
s[10] = "M=-M\n";
s[11] = "eq";
s[12] = "D;JEQ\n";
s[13] = "gt";
s[14] = "D;JLT\n";
s[15] = "lt";
s[16] = "D;JGT\n";
while ( 1 )
{
result = strcmp((&s1)[2 * v1], s2);
if ( !result )
break;
if ( ++v1 == 9 )
return result;
}
if ( (int)v1 > 5 )
{
fwrite("@SP\nAM=M-1\nD=M\nA=A-1\nM=D-M\n@CMP", 1uLL, 0x1DuLL, vm_ofp);
writeNum(vm_lbln);
fwrite("\nD=A\n@SP\nA=M\nM=D\nA=A-1\nD=M\n@LCMP\n", 1uLL, 0x21uLL, vm_ofp);
v5 = s[2 * (int)v1];
v6 = strlen(v5);
fwrite(v5, 1uLL, v6, vm_ofp);
fwrite("@SP\nA=M-1\nM=0\n(CMP", 1uLL, 0x10uLL, vm_ofp);
writeNum(vm_lbln);
result = fwrite(")\n", 1uLL, 2uLL, vm_ofp);
++vm_lbln;
}
else if ( (int)v1 > 3 )
{
fwrite("@SP\nA=M-1\n", 1uLL, 0xAuLL, vm_ofp);
v7 = s[2 * (int)v1];
v8 = strlen(v7);
result = fwrite(v7, 1uLL, v8, vm_ofp);
}
else if ( (unsigned int)v1 <= 3 )
{
fwrite("@SP\nM=M-1\nA=M-1\nD=M\nA=A+1\n", 1uLL, 0x1AuLL, vm_ofp);
v3 = s[2 * (int)v1];
v4 = strlen(v3);
fwrite(v3, 1uLL, v4, vm_ofp);
result = fwrite("A=A-1\nM=D\n", 1uLL, 0xAuLL, vm_ofp);
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(char *s2)
{
__int64 v1; // rbx
int result; // eax
const char *v3; // rbp
size_t v4; // rax
const char *v5; // rbp
size_t v6; // rax
const char *v7; // rbp
size_t v8; // rax
char *s1; // [rsp+0h] [rbp-A8h]
char *s[20]; // [rsp+8h] [rbp-A0h]

v1 = 0LL;
s1 = (char *)&unk_E49;
s[0] = "D=D+M\n";
s[1] = "sub";
s[2] = "D=D-M\n";
s[3] = "or";
s[4] = "D=D|M\n";
s[5] = "and";
s[6] = "D=D&M\n";
s[7] = "not";
s[8] = "M=!M\n";
s[9] = "neg";
s[10] = "M=-M\n";
s[11] = "eq";
s[12] = "D;JEQ\n";
s[13] = "gt";
s[14] = "D;JLT\n";
s[15] = "lt";
s[16] = "D;JGT\n";
while ( 1 )
{
result = strcmp((&s1)[2 * v1], s2);
if ( !result )
break;
if ( ++v1 == 9 )
return result;
}
if ( (int)v1 > 5 )
{
fwrite("@SP\nAM=M-1\nD=M\nA=A-1\nM=D-M\n@CMP", 1uLL, 0x1DuLL, vm_ofp);
func0(vm_lbln);
fwrite("\nD=A\n@SP\nA=M\nM=D\nA=A-1\nD=M\n@LCMP\n", 1uLL, 0x21uLL, vm_ofp);
v5 = s[2 * (int)v1];
v6 = strlen(v5);
fwrite(v5, 1uLL, v6, vm_ofp);
fwrite("@SP\nA=M-1\nM=0\n(CMP", 1uLL, 0x10uLL, vm_ofp);
func0(vm_lbln);
result = fwrite(")\n", 1uLL, 2uLL, vm_ofp);
++vm_lbln;
}
else if ( (int)v1 > 3 )
{
fwrite("@SP\nA=M-1\n", 1uLL, 0xAuLL, vm_ofp);
v7 = s[2 * (int)v1];
v8 = strlen(v7);
result = fwrite(v7, 1uLL, v8, vm_ofp);
}
else if ( (unsigned int)v1 <= 3 )
{
fwrite("@SP\nM=M-1\nA=M-1\nD=M\nA=A+1\n", 1uLL, 0x1AuLL, vm_ofp);
v3 = s[2 * (int)v1];
v4 = strlen(v3);
fwrite(v3, 1uLL, v4, vm_ofp);
result = fwrite("A=A-1\nM=D\n", 1uLL, 0xAuLL, vm_ofp);
}
return result;
}

original_code:
void writeArith(char* cmd)
{
 const struct {
  char* addr;
  char* hasm;
 } Dict[] = {
  {"add", "D=D+M\n"},
  {"sub", "D=D-M\n"},
  {"or", "D=D|M\n"},
  {"and", "D=D&M\n"},
  {"not", "M=!M\n"},
  {"neg", "M=-M\n"},
  {"eq", "D;JEQ\n"},
  {"gt", "D;JLT\n"},
  {"lt", "D;JGT\n"}
 };
 int i;
 for(i=0; i<9; i++)
 {
  if(strcmp(Dict[i].addr, cmd) == 0)
   break;
 }
 switch(i)
 {
  case 0:
  case 1:
  case 2:
  case 3:
   fwrite("@SP\nM=M-1\nA=M-1\nD=M\nA=A+1\n", 1, 26, _vm_ofp);
   fwrite(Dict[i].hasm, 1, strlen(Dict[i].hasm), _vm_ofp);
   fwrite("A=A-1\nM=D\n", 1, 10, _vm_ofp);
   break;
  case 4:
  case 5:
   fwrite("@SP\nA=M-1\n", 1, 10, _vm_ofp);
   fwrite(Dict[i].hasm, 1, strlen(Dict[i].hasm), _vm_ofp);
   break;
  case 6:
  case 7:
  case 8:
   fwrite("@SP\nAM=M-1\nD=M\nA=A-1\nM=D-M\n@CMP", 1, 29, _vm_ofp);
   writeNum(_vm_lbln);
   fwrite("\nD=A\n@SP\nA=M\nM=D\nA=A-1\nD=M\n@LCMP\n", 1, 33, _vm_ofp);
   fwrite(Dict[i].hasm, 1, strlen(Dict[i].hasm), _vm_ofp);
   fwrite("@SP\nA=M-1\nM=0\n(CMP", 1, 16, _vm_ofp);
   writeNum(_vm_lbln);
   fwrite(")\n", 1, 2, _vm_ofp);
   _vm_lbln++;
   break;
  default:
   return;
 }
}

canonical_original_code:
void writeArith(char *cmd)
{
 struct { char *addr; char *hasm; } Dict[] = {
  {"add", "D=D+M\n"},
  {"sub", "D=D-M\n"},
  {"or", "D=D|M\n"},
  {"and", "D=D&M\n"},
  {"not", "M=!M\n"},
  {"neg", "M=-M\n"},
  {"eq", "D;JEQ\n"},
  {"gt", "D;JLT\n"},
  {"lt", "D;JGT\n"}
 };
 int i;
 for(i=0; i<9; i++)
 {
  if(strcmp(Dict[i].addr, cmd) == 0)
   break;
 }
 switch(i)
 {
  case 0:
  case 1:
  case 2:
  case 3:
   fwrite("@SP\nM=M-1\nA=M-1\nD=M\nA=A+1\n", 1, 26, _vm_ofp);
   fwrite(Dict[i].hasm, 1, strlen(Dict[i].hasm), _vm_ofp);
   fwrite("A=A-1\nM=D\n", 1, 10, _vm_ofp);
   break;
  case 4:
  case 5:
   fwrite("@SP\nA=M-1\n", 1, 10, _vm_ofp);
   fwrite(Dict[i].hasm, 1, strlen(Dict[i].hasm), _vm_ofp);
   break;
  case 6:
  case 7:
  case 8:
   fwrite("@SP\nAM=M-1\nD=M\nA=A-1\nM=D-M\n@CMP", 1, 29, _vm_ofp);
   writeNum(_vm_lbln);
   fwrite("\nD=A\n@SP\nA=M\nM=D\nA=A-1\nD=M\n@LCMP\n", 1, 33, _vm_ofp);
   fwrite(Dict[i].hasm, 1, strlen(Dict[i].hasm), _vm_ofp);
   fwrite("@SP\nA=M-1\nM=0\n(CMP", 1, 16, _vm_ofp);
   writeNum(_vm_lbln);
   fwrite(")\n", 1, 2, _vm_ofp);
   _vm_lbln++;
   break;
  default:
   return;
 }
}

variable_types:
cmd
char *

variable_types:
Dict
struct { char *addr; char *hasm; } []


writePush

decompiled_code:
int __fastcall writePush(char *s2, int a2)
{
__int64 v2; // rbx
char *v4; // rbp
size_t v5; // rax
const char *v6; // rbp
size_t v7; // rax
FILE *v8; // rcx
const char *v9; // rdi
const char *v10; // rbp
size_t v11; // rax
char *s1; // [rsp+0h] [rbp-A8h]
char *s[20]; // [rsp+8h] [rbp-A0h]

v2 = 0LL;
s1 = "local";
s[0] = "@LCL\n";
s[1] = "argument";
s[2] = "@ARG\n";
s[3] = "this";
s[4] = "@THIS\n";
s[5] = "that";
s[6] = "@THAT\n";
s[7] = "pointer";
s[8] = "@THIS\n";
s[9] = "temp";
s[10] = "@5\n";
s[11] = "static";
s[12] = (char *)&unk_F38;
s[13] = "constant";
s[14] = (char *)&unk_F38;
while ( strcmp((&s1)[2 * v2], s2) )
{
if ( ++v2 == 8 )
return printf("Unknown push segment: \"%s\"\n", s2);
}
if ( (int)v2 <= 5 )
{
if ( (int)v2 > 3 )
{
v10 = s[2 * (int)v2];
v11 = strlen(v10);
fwrite(v10, 1uLL, v11, vm_ofp);
v8 = vm_ofp;
v9 = "D=A\n@";
}
else
{
if ( (unsigned int)v2 > 3 )
return printf("Unknown push segment: \"%s\"\n", s2);
v6 = s[2 * (int)v2];
v7 = strlen(v6);
fwrite(v6, 1uLL, v7, vm_ofp);
v8 = vm_ofp;
v9 = "D=M\n@";
}
fwrite(v9, 1uLL, 5uLL, v8);
writeNum(a2);
fwrite("\nA=D+A\nD=M\n", 1uLL, 0xBuLL, vm_ofp);
}
else
{
fwrite("@", 1uLL, 1uLL, vm_ofp);
if ( (_DWORD)v2 == 6 )
{
v4 = vm_sv;
v5 = strlen(vm_sv);
fwrite(v4, 1uLL, v5, vm_ofp);
fwrite(".", 1uLL, 1uLL, vm_ofp);
writeNum(a2);
fwrite("\nD=M\n", 1uLL, 5uLL, vm_ofp);
}
else
{
writeNum(a2);
fwrite("\nD=A\n", 1uLL, 5uLL, vm_ofp);
}
}
return fwrite("@SP\nM=M+1\nA=M-1\nM=D\n", 1uLL, 0x14uLL, vm_ofp);
}

canonical_decompiled_code:
int __fastcall func2(char *s2, int a2)
{
__int64 v2; // rbx
char *v4; // rbp
size_t v5; // rax
const char *v6; // rbp
size_t v7; // rax
FILE *v8; // rcx
const char *v9; // rdi
const char *v10; // rbp
size_t v11; // rax
char *s1; // [rsp+0h] [rbp-A8h]
char *s[20]; // [rsp+8h] [rbp-A0h]

v2 = 0LL;
s1 = "local";
s[0] = "@LCL\n";
s[1] = "argument";
s[2] = "@ARG\n";
s[3] = "this";
s[4] = "@THIS\n";
s[5] = "that";
s[6] = "@THAT\n";
s[7] = "pointer";
s[8] = "@THIS\n";
s[9] = "temp";
s[10] = "@5\n";
s[11] = "static";
s[12] = (char *)&unk_F38;
s[13] = "constant";
s[14] = (char *)&unk_F38;
while ( strcmp((&s1)[2 * v2], s2) )
{
if ( ++v2 == 8 )
return printf("Unknown push segment: \"%s\"\n", s2);
}
if ( (int)v2 <= 5 )
{
if ( (int)v2 > 3 )
{
v10 = s[2 * (int)v2];
v11 = strlen(v10);
fwrite(v10, 1uLL, v11, vm_ofp);
v8 = vm_ofp;
v9 = "D=A\n@";
}
else
{
if ( (unsigned int)v2 > 3 )
return printf("Unknown push segment: \"%s\"\n", s2);
v6 = s[2 * (int)v2];
v7 = strlen(v6);
fwrite(v6, 1uLL, v7, vm_ofp);
v8 = vm_ofp;
v9 = "D=M\n@";
}
fwrite(v9, 1uLL, 5uLL, v8);
func0(a2);
fwrite("\nA=D+A\nD=M\n", 1uLL, 0xBuLL, vm_ofp);
}
else
{
fwrite("@", 1uLL, 1uLL, vm_ofp);
if ( (_DWORD)v2 == 6 )
{
v4 = vm_sv;
v5 = strlen(vm_sv);
fwrite(v4, 1uLL, v5, vm_ofp);
fwrite(".", 1uLL, 1uLL, vm_ofp);
func0(a2);
fwrite("\nD=M\n", 1uLL, 5uLL, vm_ofp);
}
else
{
func0(a2);
fwrite("\nD=A\n", 1uLL, 5uLL, vm_ofp);
}
}
return fwrite("@SP\nM=M+1\nA=M-1\nM=D\n", 1uLL, 0x14uLL, vm_ofp);
}

original_code:
void writePush(char* seg, int index)
{
 const struct {
  char* addr;
  char* hasm;
 } Dict[] = {
  {"local", "@LCL\n"},
  {"argument", "@ARG\n"},
  {"this", "@THIS\n"},
  {"that", "@THAT\n"},
  {"pointer", "@THIS\n"},
  {"temp", "@5\n"},
  {"static", ""},
  {"constant", ""},
 };
 int i;
 for(i=0; i<8; i++)
 {
  if(strcmp(Dict[i].addr, seg) == 0)
   break;
 }
 switch(i)
 {
  case 0:
  case 1:
  case 2:
  case 3:
   fwrite(Dict[i].hasm, 1, strlen(Dict[i].hasm), _vm_ofp);
   fwrite("D=M\n@", 1, 5, _vm_ofp);
   writeNum(index);
   fwrite("\nA=D+A\nD=M\n", 1, 11, _vm_ofp);
   break;
  case 4:
  case 5:
   fwrite(Dict[i].hasm, 1, strlen(Dict[i].hasm), _vm_ofp);
   fwrite("D=A\n@", 1, 5, _vm_ofp);
   writeNum(index);
   fwrite("\nA=D+A\nD=M\n", 1, 11, _vm_ofp);
   break;
  case 6:
   fwrite("@", 1, 1, _vm_ofp);
   fwrite(_vm_sv, 1, strlen(_vm_sv), _vm_ofp);
   fwrite(".", 1, 1, _vm_ofp);
   writeNum(index);
   fwrite("\nD=M\n", 1, 5, _vm_ofp);
   break;
  case 7:
   fwrite("@", 1, 1, _vm_ofp);
   writeNum(index);
   fwrite("\nD=A\n", 1, 5, _vm_ofp);
   break;
  default:
   printf("Unknown push segment: \"%s\"\n", seg);
   return;
 }
 fwrite("@SP\nM=M+1\nA=M-1\nM=D\n", 1, 20, _vm_ofp);
}

canonical_original_code:
void writePush(char *seg, int index)
{
 struct { char *addr; char *hasm; } Dict[] = {
  {"local", "@LCL\n"},
  {"argument", "@ARG\n"},
  {"this", "@THIS\n"},
  {"that", "@THAT\n"},
  {"pointer", "@THIS\n"},
  {"temp", "@5\n"},
  {"static", ""},
  {"constant", ""},
 };
 int i;
 for(i=0; i<8; i++)
 {
  if(strcmp(Dict[i].addr, seg) == 0)
   break;
 }
 switch(i)
 {
  case 0:
  case 1:
  case 2:
  case 3:
   fwrite(Dict[i].hasm, 1, strlen(Dict[i].hasm), _vm_ofp);
   fwrite("D=M\n@", 1, 5, _vm_ofp);
   writeNum(index);
   fwrite("\nA=D+A\nD=M\n", 1, 11, _vm_ofp);
   break;
  case 4:
  case 5:
   fwrite(Dict[i].hasm, 1, strlen(Dict[i].hasm), _vm_ofp);
   fwrite("D=A\n@", 1, 5, _vm_ofp);
   writeNum(index);
   fwrite("\nA=D+A\nD=M\n", 1, 11, _vm_ofp);
   break;
  case 6:
   fwrite("@", 1, 1, _vm_ofp);
   fwrite(_vm_sv, 1, strlen(_vm_sv), _vm_ofp);
   fwrite(".", 1, 1, _vm_ofp);
   writeNum(index);
   fwrite("\nD=M\n", 1, 5, _vm_ofp);
   break;
  case 7:
   fwrite("@", 1, 1, _vm_ofp);
   writeNum(index);
   fwrite("\nD=A\n", 1, 5, _vm_ofp);
   break;
  default:
   printf("Unknown push segment: \"%s\"\n", seg);
   return;
 }
 fwrite("@SP\nM=M+1\nA=M-1\nM=D\n", 1, 20, _vm_ofp);
}

variable_types:
seg
char *

variable_types: index int


writePop

decompiled_code:
int __fastcall writePop(char *s2, int a2)
{
__int64 v2; // rbx
int result; // eax
const char *v4; // rbp
size_t v5; // rax
FILE *v6; // rcx
const char *v7; // rdi
const char *v8; // rbp
size_t v9; // rax
char *v10; // rbp
size_t v11; // rax
char *s1; // [rsp+0h] [rbp-98h]
char *s[18]; // [rsp+8h] [rbp-90h]

v2 = 0LL;
s1 = "local";
s[0] = "@LCL\n";
s[1] = "argument";
s[2] = "@ARG\n";
s[3] = "this";
s[4] = "@THIS\n";
s[5] = "that";
s[6] = "@THAT\n";
s[7] = "pointer";
s[8] = "@THIS\n";
s[9] = "temp";
s[10] = "@5\n";
s[11] = "static";
s[12] = (char *)&unk_F38;
while ( strcmp((&s1)[2 * v2], s2) )
{
if ( ++v2 == 7 )
return printf("Unknown pop segment: \"%s\"\n", s2);
}
if ( (_DWORD)v2 == 6 )
{
fwrite("@SP\nAM=M-1\nD=M\n@", 1uLL, 0x10uLL, vm_ofp);
v10 = vm_sv;
v11 = strlen(vm_sv);
fwrite(v10, 1uLL, v11, vm_ofp);
fwrite(".", 1uLL, 1uLL, vm_ofp);
writeNum(a2);
result = fwrite("\nM=D\n", 1uLL, 5uLL, vm_ofp);
}
else
{
if ( (int)v2 > 3 )
{
v8 = s[2 * (int)v2];
v9 = strlen(v8);
fwrite(v8, 1uLL, v9, vm_ofp);
v6 = vm_ofp;
v7 = "D=A\n@";
}
else
{
if ( (unsigned int)v2 > 3 )
return printf("Unknown pop segment: \"%s\"\n", s2);
v4 = s[2 * (int)v2];
v5 = strlen(v4);
fwrite(v4, 1uLL, v5, vm_ofp);
v6 = vm_ofp;
v7 = "D=M\n@";
}
fwrite(v7, 1uLL, 5uLL, v6);
writeNum(a2);
fwrite("\nD=D+A\n", 1uLL, 7uLL, vm_ofp);
result = fwrite("@SP\nM=M-1\nA=M+1\nM=D\nA=A-1\nD=M\nA=A+1\nA=M\nM=D\n", 1uLL, 0x2CuLL, vm_ofp);
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(char *s2, int a2)
{
__int64 v2; // rbx
int result; // eax
const char *v4; // rbp
size_t v5; // rax
FILE *v6; // rcx
const char *v7; // rdi
const char *v8; // rbp
size_t v9; // rax
char *v10; // rbp
size_t v11; // rax
char *s1; // [rsp+0h] [rbp-98h]
char *s[18]; // [rsp+8h] [rbp-90h]

v2 = 0LL;
s1 = "local";
s[0] = "@LCL\n";
s[1] = "argument";
s[2] = "@ARG\n";
s[3] = "this";
s[4] = "@THIS\n";
s[5] = "that";
s[6] = "@THAT\n";
s[7] = "pointer";
s[8] = "@THIS\n";
s[9] = "temp";
s[10] = "@5\n";
s[11] = "static";
s[12] = (char *)&unk_F38;
while ( strcmp((&s1)[2 * v2], s2) )
{
if ( ++v2 == 7 )
return printf("Unknown pop segment: \"%s\"\n", s2);
}
if ( (_DWORD)v2 == 6 )
{
fwrite("@SP\nAM=M-1\nD=M\n@", 1uLL, 0x10uLL, vm_ofp);
v10 = vm_sv;
v11 = strlen(vm_sv);
fwrite(v10, 1uLL, v11, vm_ofp);
fwrite(".", 1uLL, 1uLL, vm_ofp);
func0(a2);
result = fwrite("\nM=D\n", 1uLL, 5uLL, vm_ofp);
}
else
{
if ( (int)v2 > 3 )
{
v8 = s[2 * (int)v2];
v9 = strlen(v8);
fwrite(v8, 1uLL, v9, vm_ofp);
v6 = vm_ofp;
v7 = "D=A\n@";
}
else
{
if ( (unsigned int)v2 > 3 )
return printf("Unknown pop segment: \"%s\"\n", s2);
v4 = s[2 * (int)v2];
v5 = strlen(v4);
fwrite(v4, 1uLL, v5, vm_ofp);
v6 = vm_ofp;
v7 = "D=M\n@";
}
fwrite(v7, 1uLL, 5uLL, v6);
func0(a2);
fwrite("\nD=D+A\n", 1uLL, 7uLL, vm_ofp);
result = fwrite("@SP\nM=M-1\nA=M+1\nM=D\nA=A-1\nD=M\nA=A+1\nA=M\nM=D\n", 1uLL, 0x2CuLL, vm_ofp);
}
return result;
}

original_code:
void writePop(char* seg, int index)
{
 const struct {
  char* addr;
  char* hasm;
 } Dict[] = {
  {"local", "@LCL\n"},
  {"argument", "@ARG\n"},
  {"this", "@THIS\n"},
  {"that", "@THAT\n"},
  {"pointer", "@THIS\n"},
  {"temp", "@5\n"},
  {"static", ""}
 };
 int i;
 for(i=0; i<7; i++)
 {
  if(strcmp(Dict[i].addr, seg) == 0)
   break;
 }
 switch(i)
 {
  case 0:
  case 1:
  case 2:
  case 3:
   fwrite(Dict[i].hasm, 1, strlen(Dict[i].hasm), _vm_ofp);
   fwrite("D=M\n@", 1, 5, _vm_ofp);
   writeNum(index);
   fwrite("\nD=D+A\n", 1, 7, _vm_ofp);
   break;
  case 4:
  case 5:
   fwrite(Dict[i].hasm, 1, strlen(Dict[i].hasm), _vm_ofp);
   fwrite("D=A\n@", 1, 5, _vm_ofp);
   writeNum(index);
   fwrite("\nD=D+A\n", 1, 7, _vm_ofp);
   break;
  case 6:
   fwrite("@SP\nAM=M-1\nD=M\n@", 1, 16, _vm_ofp);
   fwrite(_vm_sv, 1, strlen(_vm_sv), _vm_ofp);
   fwrite(".", 1, 1, _vm_ofp);
   writeNum(index);
   fwrite("\nM=D\n", 1, 5, _vm_ofp);
   return;
  default:
   printf("Unknown pop segment: \"%s\"\n", seg);
   return;
 }
 fwrite("@SP\nM=M-1\nA=M+1\nM=D\nA=A-1\nD=M\nA=A+1\nA=M\nM=D\n", 1, 44, _vm_ofp);
}

canonical_original_code:
void writePop(char *seg, int index)
{
 struct { char *addr; char *hasm; } Dict[] = {
  {"local", "@LCL\n"},
  {"argument", "@ARG\n"},
  {"this", "@THIS\n"},
  {"that", "@THAT\n"},
  {"pointer", "@THIS\n"},
  {"temp", "@5\n"},
  {"static", ""}
 };
 int i;
 for(i=0; i<7; i++)
 {
  if(strcmp(Dict[i].addr, seg) == 0)
   break;
 }
 switch(i)
 {
  case 0:
  case 1:
  case 2:
  case 3:
   fwrite(Dict[i].hasm, 1, strlen(Dict[i].hasm), _vm_ofp);
   fwrite("D=M\n@", 1, 5, _vm_ofp);
   writeNum(index);
   fwrite("\nD=D+A\n", 1, 7, _vm_ofp);
   break;
  case 4:
  case 5:
   fwrite(Dict[i].hasm, 1, strlen(Dict[i].hasm), _vm_ofp);
   fwrite("D=A\n@", 1, 5, _vm_ofp);
   writeNum(index);
   fwrite("\nD=D+A\n", 1, 7, _vm_ofp);
   break;
  case 6:
   fwrite("@SP\nAM=M-1\nD=M\n@", 1, 16, _vm_ofp);
   fwrite(_vm_sv, 1, strlen(_vm_sv), _vm_ofp);
   fwrite(".", 1, 1, _vm_ofp);
   writeNum(index);
   fwrite("\nM=D\n", 1, 5, _vm_ofp);
   return;
  default:
   printf("Unknown pop segment: \"%s\"\n", seg);
   return;
 }
 fwrite("@SP\nM=M-1\nA=M+1\nM=D\nA=A-1\nD=M\nA=A+1\nA=M\nM=D\n", 1, 44, _vm_ofp);
}

variable_types: i int


writeLabel

decompiled_code:
size_t __fastcall writeLabel(char *s)
{
char *v1; // r12
size_t v2; // rax
size_t v3; // rax

fwrite("(", 1uLL, 1uLL, vm_ofp);
v1 = vm_fcn;
v2 = strlen(vm_fcn);
fwrite(v1, 1uLL, v2, vm_ofp);
fwrite("$", 1uLL, 1uLL, vm_ofp);
v3 = strlen(s);
fwrite(s, 1uLL, v3, vm_ofp);
return fwrite(")\n", 1uLL, 2uLL, vm_ofp);
}

canonical_decompiled_code:
size_t __fastcall func4(char *s)
{
char *v1; // r12
size_t v2; // rax
size_t v3; // rax

fwrite("(", 1uLL, 1uLL, vm_ofp);
v1 = vm_fcn;
v2 = strlen(vm_fcn);
fwrite(v1, 1uLL, v2, vm_ofp);
fwrite("$", 1uLL, 1uLL, vm_ofp);
v3 = strlen(s);
fwrite(s, 1uLL, v3, vm_ofp);
return fwrite(")\n", 1uLL, 2uLL, vm_ofp);
}

original_code:
void writeLabel(char* lab)
{
 fwrite("(", 1, 1, _vm_ofp);
 fwrite(_vm_fcn, 1, strlen(_vm_fcn), _vm_ofp);
 fwrite("$", 1, 1, _vm_ofp);
 fwrite(lab, 1, strlen(lab), _vm_ofp);
 fwrite(")\n", 1, 2, _vm_ofp);
}

canonical_original_code:
void writeLabel(char *lab)
{
 fwrite("(", 1, 1, _vm_ofp);
 fwrite(_vm_fcn, 1, strlen(_vm_fcn), _vm_ofp);
 fwrite("$", 1, 1, _vm_ofp);
 fwrite(lab, 1, strlen(lab), _vm_ofp);
 fwrite(")\n", 1, 2, _vm_ofp);
}

variable_types:
lab
char *


writeGoto

decompiled_code:
size_t __fastcall writeGoto(char *s)
{
char *v1; // r12
size_t v2; // rax
size_t v3; // rax

fwrite("@", 1uLL, 1uLL, vm_ofp);
v1 = vm_fcn;
v2 = strlen(vm_fcn);
fwrite(v1, 1uLL, v2, vm_ofp);
fwrite("$", 1uLL, 1uLL, vm_ofp);
v3 = strlen(s);
fwrite(s, 1uLL, v3, vm_ofp);
return fwrite("\n0;JMP\n", 1uLL, 7uLL, vm_ofp);
}

canonical_decompiled_code:
size_t __fastcall func5(char *s)
{
char *v1; // r12
size_t v2; // rax
size_t v3; // rax

fwrite("@", 1uLL, 1uLL, vm_ofp);
v1 = vm_fcn;
v2 = strlen(vm_fcn);
fwrite(v1, 1uLL, v2, vm_ofp);
fwrite("$", 1uLL, 1uLL, vm_ofp);
v3 = strlen(s);
fwrite(s, 1uLL, v3, vm_ofp);
return fwrite("\n0;JMP\n", 1uLL, 7uLL, vm_ofp);
}

original_code:
void writeGoto(char* lab)
{
 fwrite("@", 1, 1, _vm_ofp);
 fwrite(_vm_fcn, 1, strlen(_vm_fcn), _vm_ofp);
 fwrite("$", 1, 1, _vm_ofp);
 fwrite(lab, 1, strlen(lab), _vm_ofp);
 fwrite("\n0;JMP\n", 1, 7, _vm_ofp);
}

canonical_original_code:
void writeGoto(char *lab)
{
 fwrite("@", 1, 1, _vm_ofp);
 fwrite(_vm_fcn, 1, strlen(_vm_fcn), _vm_ofp);
 fwrite("$", 1, 1, _vm_ofp);
 fwrite(lab, 1, strlen(lab), _vm_ofp);
 fwrite("\n0;JMP\n", 1, 7, _vm_ofp);
}


writeIf

decompiled_code:
size_t __fastcall writeIf(char *s)
{
char *v1; // r12
size_t v2; // rax
size_t v3; // rax

fwrite("@SP\nAM=M-1\nD=M\n@", 1uLL, 0x10uLL, vm_ofp);
v1 = vm_fcn;
v2 = strlen(vm_fcn);
fwrite(v1, 1uLL, v2, vm_ofp);
fwrite("$", 1uLL, 1uLL, vm_ofp);
v3 = strlen(s);
fwrite(s, 1uLL, v3, vm_ofp);
return fwrite("\nD;JNE\n", 1uLL, 7uLL, vm_ofp);
}

canonical_decompiled_code:
size_t __fastcall func6(char *s)
{
char *v1; // r12
size_t v2; // rax
size_t v3; // rax

fwrite("@SP\nAM=M-1\nD=M\n@", 1uLL, 0x10uLL, vm_ofp);
v1 = vm_fcn;
v2 = strlen(vm_fcn);
fwrite(v1, 1uLL, v2, vm_ofp);
fwrite("$", 1uLL, 1uLL, vm_ofp);
v3 = strlen(s);
fwrite(s, 1uLL, v3, vm_ofp);
return fwrite("\nD;JNE\n", 1uLL, 7uLL, vm_ofp);
}

original_code:
void writeIf(char* lab)
{
 fwrite("@SP\nAM=M-1\nD=M\n@", 1, 16, _vm_ofp);
 fwrite(_vm_fcn, 1, strlen(_vm_fcn), _vm_ofp);
 fwrite("$", 1, 1, _vm_ofp);
 fwrite(lab, 1, strlen(lab), _vm_ofp);
 fwrite("\nD;JNE\n", 1, 7, _vm_ofp);
}

canonical_original_code:
void writeIf(char *lab)
{
 fwrite("@SP\nAM=M-1\nD=M\n@", 1, 16, _vm_ofp);
 fwrite(_vm_fcn, 1, strlen(_vm_fcn), _vm_ofp);
 fwrite("$", 1, 1, _vm_ofp);
 fwrite(lab, 1, strlen(lab), _vm_ofp);
 fwrite("\nD;JNE\n", 1, 7, _vm_ofp);
}


writeCall

decompiled_code:
size_t __fastcall writeCall(char *s, int a2)
{
size_t v2; // rax
size_t result; // rax

fwrite("@LC", 1uLL, 3uLL, vm_ofp);
writeNum(vm_lcn);
fwrite("\nD=A\n@SP\nM=M+1\nA=M-1\nM=D\n", 1uLL, 0x19uLL, vm_ofp);
fwrite("@LCL\nD=M\n@SP\nM=M+1\nA=M-1\nM=D\n", 1uLL, 0x1DuLL, vm_ofp);
fwrite("@ARG\nD=M\n@SP\nM=M+1\nA=M-1\nM=D\n", 1uLL, 0x1DuLL, vm_ofp);
fwrite("@THIS\nD=M\n@SP\nM=M+1\nA=M-1\nM=D\n", 1uLL, 0x1EuLL, vm_ofp);
fwrite("@THAT\nD=M\n@SP\nM=M+1\nA=M-1\nM=D\n", 1uLL, 0x1EuLL, vm_ofp);
fwrite("@SP\nD=M\n@", 1uLL, 9uLL, vm_ofp);
writeNum(a2);
fwrite("\nD=D-A\n@5\nD=D-A\n@ARG\nM=D\n", 1uLL, 0x19uLL, vm_ofp);
fwrite("@SP\nD=M\n@LCL\nM=D\n@", 1uLL, 0x12uLL, vm_ofp);
v2 = strlen(s);
fwrite(s, 1uLL, v2, vm_ofp);
fwrite("\n0;JMP\n(LC", 1uLL, 0xAuLL, vm_ofp);
writeNum(vm_lcn);
result = fwrite(")\n", 1uLL, 2uLL, vm_ofp);
++vm_lcn;
return result;
}

canonical_decompiled_code:
size_t __fastcall func7(char *s, int a2)
{
size_t v2; // rax
size_t result; // rax

fwrite("@LC", 1uLL, 3uLL, vm_ofp);
func0(vm_lcn);
fwrite("\nD=A\n@SP\nM=M+1\nA=M-1\nM=D\n", 1uLL, 0x19uLL, vm_ofp);
fwrite("@LCL\nD=M\n@SP\nM=M+1\nA=M-1\nM=D\n", 1uLL, 0x1DuLL, vm_ofp);
fwrite("@ARG\nD=M\n@SP\nM=M+1\nA=M-1\nM=D\n", 1uLL, 0x1DuLL, vm_ofp);
fwrite("@THIS\nD=M\n@SP\nM=M+1\nA=M-1\nM=D\n", 1uLL, 0x1EuLL, vm_ofp);
fwrite("@THAT\nD=M\n@SP\nM=M+1\nA=M-1\nM=D\n", 1uLL, 0x1EuLL, vm_ofp);
fwrite("@SP\nD=M\n@", 1uLL, 9uLL, vm_ofp);
func0(a2);
fwrite("\nD=D-A\n@5\nD=D-A\n@ARG\nM=D\n", 1uLL, 0x19uLL, vm_ofp);
fwrite("@SP\nD=M\n@LCL\nM=D\n@", 1uLL, 0x12uLL, vm_ofp);
v2 = strlen(s);
fwrite(s, 1uLL, v2, vm_ofp);
fwrite("\n0;JMP\n(LC", 1uLL, 0xAuLL, vm_ofp);
func0(vm_lcn);
result = fwrite(")\n", 1uLL, 2uLL, vm_ofp);
++vm_lcn;
return result;
}

original_code:
void writeCall(char* fn, int args)
{
 fwrite("@LC", 1, 3, _vm_ofp);
 writeNum(_vm_lcn);
 fwrite("\nD=A\n@SP\nM=M+1\nA=M-1\nM=D\n", 1, 25, _vm_ofp);
 fwrite("@LCL\nD=M\n@SP\nM=M+1\nA=M-1\nM=D\n", 1, 29, _vm_ofp);
 fwrite("@ARG\nD=M\n@SP\nM=M+1\nA=M-1\nM=D\n", 1, 29, _vm_ofp);
 fwrite("@THIS\nD=M\n@SP\nM=M+1\nA=M-1\nM=D\n", 1, 30, _vm_ofp);
 fwrite("@THAT\nD=M\n@SP\nM=M+1\nA=M-1\nM=D\n", 1, 30, _vm_ofp);
 fwrite("@SP\nD=M\n@", 1, 9, _vm_ofp);
 writeNum(args);
 fwrite("\nD=D-A\n@5\nD=D-A\n@ARG\nM=D\n", 1, 25, _vm_ofp);
 fwrite("@SP\nD=M\n@LCL\nM=D\n@", 1, 18, _vm_ofp);
 fwrite(fn, 1, strlen(fn), _vm_ofp);
 fwrite("\n0;JMP\n(LC", 1, 10, _vm_ofp);
 writeNum(_vm_lcn);
 fwrite(")\n", 1, 2, _vm_ofp);
 _vm_lcn++;
}

canonical_original_code:
void writeCall(char *fn, int args)
{
 fwrite("@LC", 1, 3, _vm_ofp);
 writeNum(_vm_lcn);
 fwrite("\nD=A\n@SP\nM=M+1\nA=M-1\nM=D\n", 1, 25, _vm_ofp);
 fwrite("@LCL\nD=M\n@SP\nM=M+1\nA=M-1\nM=D\n", 1, 29, _vm_ofp);
 fwrite("@ARG\nD=M\n@SP\nM=M+1\nA=M-1\nM=D\n", 1, 29, _vm_ofp);
 fwrite("@THIS\nD=M\n@SP\nM=M+1\nA=M-1\nM=D\n", 1, 30, _vm_ofp);
 fwrite("@THAT\nD=M\n@SP\nM=M+1\nA=M-1\nM=D\n", 1, 30, _vm_ofp);
 fwrite("@SP\nD=M\n@", 1, 9, _vm_ofp);
 writeNum(args);
 fwrite("\nD=D-A\n@5\nD=D-A\n@ARG\nM=D\n", 1, 25, _vm_ofp);
 fwrite("@SP\nD=M\n@LCL\nM=D\n@", 1, 18, _vm_ofp);
 fwrite(fn, 1, strlen(fn), _vm_ofp);
 fwrite("\n0;JMP\n(LC", 1, 10, _vm_ofp);
 writeNum(_vm_lcn);
 fwrite(")\n", 1, 2, _vm_ofp);
 _vm_lcn++;
}

variable_types:
fn
char *

variable_types: args int


writeInit

decompiled_code:
size_t writeInit()
{
fwrite("@256\nD=A\n@SP\nM=D\n", 1uLL, 0x11uLL, vm_ofp);
writeCall("Sys.init", 0);
return fwrite("(LCMP)\n@SP\nA=M-1\nM=-1\nA=A+1\nA=M\n0;JMP\n", 1uLL, 0x26uLL, vm_ofp);
}

canonical_decompiled_code:
size_t func8()
{
fwrite("@256\nD=A\n@SP\nM=D\n", 1uLL, 0x11uLL, vm_ofp);
func7("Sys.init", 0);
return fwrite("(LCMP)\n@SP\nA=M-1\nM=-1\nA=A+1\nA=M\n0;JMP\n", 1uLL, 0x26uLL, vm_ofp);
}

original_code:
void writeInit()
{
 fwrite("@256\nD=A\n@SP\nM=D\n", 1, 17, _vm_ofp);
 writeCall("Sys.init", 0);
 fwrite("(LCMP)\n@SP\nA=M-1\nM=-1\nA=A+1\nA=M\n0;JMP\n", 1, 38, _vm_ofp);
}


writeReturn

decompiled_code:
size_t writeReturn()
{
fwrite("@LCL\nD=M\n@R15\nM=D\n", 1uLL, 0x12uLL, vm_ofp);
fwrite("@5\nD=A\n@R15\nA=M-D\nD=M\n@R14\nM=D\n", 1uLL, 0x1FuLL, vm_ofp);
fwrite("@SP\nA=M-1\nD=M\n@ARG\nA=M\nM=D\n", 1uLL, 0x1BuLL, vm_ofp);
fwrite("@ARG\nD=M+1\n@SP\nM=D\n", 1uLL, 0x13uLL, vm_ofp);
fwrite("@R15\nAM=M-1\nD=M\n@THAT\nM=D\n", 1uLL, 0x1AuLL, vm_ofp);
fwrite("@R15\nAM=M-1\nD=M\n@THIS\nM=D\n", 1uLL, 0x1AuLL, vm_ofp);
fwrite("@R15\nAM=M-1\nD=M\n@ARG\nM=D\n", 1uLL, 0x19uLL, vm_ofp);
fwrite("@R15\nAM=M-1\nD=M\n@LCL\nM=D\n", 1uLL, 0x19uLL, vm_ofp);
return fwrite("@R14\nA=M\n0;JMP\n", 1uLL, 0xFuLL, vm_ofp);
}

canonical_decompiled_code:
size_t func9()
{
fwrite("@LCL\nD=M\n@R15\nM=D\n", 1uLL, 0x12uLL, vm_ofp);
fwrite("@5\nD=A\n@R15\nA=M-D\nD=M\n@R14\nM=D\n", 1uLL, 0x1FuLL, vm_ofp);
fwrite("@SP\nA=M-1\nD=M\n@ARG\nA=M\nM=D\n", 1uLL, 0x1BuLL, vm_ofp);
fwrite("@ARG\nD=M+1\n@SP\nM=D\n", 1uLL, 0x13uLL, vm_ofp);
fwrite("@R15\nAM=M-1\nD=M\n@THAT\nM=D\n", 1uLL, 0x1AuLL, vm_ofp);
fwrite("@R15\nAM=M-1\nD=M\n@THIS\nM=D\n", 1uLL, 0x1AuLL, vm_ofp);
fwrite("@R15\nAM=M-1\nD=M\n@ARG\nM=D\n", 1uLL, 0x19uLL, vm_ofp);
fwrite("@R15\nAM=M-1\nD=M\n@LCL\nM=D\n", 1uLL, 0x19uLL, vm_ofp);
return fwrite("@R14\nA=M\n0;JMP\n", 1uLL, 0xFuLL, vm_ofp);
}

original_code:
void writeReturn()
{
 fwrite("@LCL\nD=M\n@R15\nM=D\n", 1, 18, _vm_ofp);
 fwrite("@5\nD=A\n@R15\nA=M-D\nD=M\n@R14\nM=D\n", 1, 31, _vm_ofp);
 fwrite("@SP\nA=M-1\nD=M\n@ARG\nA=M\nM=D\n", 1, 27, _vm_ofp);
 fwrite("@ARG\nD=M+1\n@SP\nM=D\n", 1, 19, _vm_ofp);
 fwrite("@R15\nAM=M-1\nD=M\n@THAT\nM=D\n", 1, 26, _vm_ofp);
 fwrite("@R15\nAM=M-1\nD=M\n@THIS\nM=D\n", 1, 26, _vm_ofp);
 fwrite("@R15\nAM=M-1\nD=M\n@ARG\nM=D\n", 1, 25, _vm_ofp);
 fwrite("@R15\nAM=M-1\nD=M\n@LCL\nM=D\n", 1, 25, _vm_ofp);
 fwrite("@R14\nA=M\n0;JMP\n", 1, 15, _vm_ofp);
}


writeFunction

decompiled_code:
size_t __fastcall writeFunction(char *src, int a2)
{
size_t v2; // rax
char *v3; // r13
size_t v4; // rax
size_t v5; // rax
int i; // ebx

if ( vm_fcn )
free(vm_fcn);
v2 = strlen(src);
v3 = (char *)calloc(v2, 1uLL);
vm_fcn = v3;
v4 = strlen(src);
strncpy(v3, src, v4);
fwrite("(", 1uLL, 1uLL, vm_ofp);
v5 = strlen(src);
fwrite(src, 1uLL, v5, vm_ofp);
fwrite(")\n@SP\nA=M\n", 1uLL, 0xAuLL, vm_ofp);
if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
fwrite("M=0\nA=A+1\n", 1uLL, 0xAuLL, vm_ofp);
}
return fwrite("D=A\n@SP\nM=D\n", 1uLL, 0xCuLL, vm_ofp);
}

canonical_decompiled_code:
size_t __fastcall func10(char *src, int a2)
{
size_t v2; // rax
char *v3; // r13
size_t v4; // rax
size_t v5; // rax
int i; // ebx

if ( vm_fcn )
free(vm_fcn);
v2 = strlen(src);
v3 = (char *)calloc(v2, 1uLL);
vm_fcn = v3;
v4 = strlen(src);
strncpy(v3, src, v4);
fwrite("(", 1uLL, 1uLL, vm_ofp);
v5 = strlen(src);
fwrite(src, 1uLL, v5, vm_ofp);
fwrite(")\n@SP\nA=M\n", 1uLL, 0xAuLL, vm_ofp);
if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
fwrite("M=0\nA=A+1\n", 1uLL, 0xAuLL, vm_ofp);
}
return fwrite("D=A\n@SP\nM=D\n", 1uLL, 0xCuLL, vm_ofp);
}

original_code:
void writeFunction(char* fn, int lcls)
{
 if(_vm_fcn != ((void *)0))
  free(_vm_fcn);
 _vm_fcn = (char*) calloc(strlen(fn), sizeof(char));
 strncpy(_vm_fcn, fn, strlen(fn));
 fwrite("(", 1, 1, _vm_ofp);
 fwrite(fn, 1, strlen(fn), _vm_ofp);
 fwrite(")\n@SP\nA=M\n", 1, 10, _vm_ofp);
 for(int i = 0; i<lcls; i++)
  fwrite("M=0\nA=A+1\n", 1, 10, _vm_ofp);
 fwrite("D=A\n@SP\nM=D\n", 1, 12, _vm_ofp);
}

canonical_original_code:
void writeFunction(char *fn, int lcls)
{
 if(_vm_fcn != ((void *)0))
  free(_vm_fcn);
 _vm_fcn = (char *) calloc(strlen(fn), sizeof(char));
 strncpy(_vm_fcn, fn, strlen(fn));
 fwrite("(", 1, 1, _vm_ofp);
 fwrite(fn, 1, strlen(fn), _vm_ofp);
 fwrite(")\n@SP\nA=M\n", 1, 10, _vm_ofp);
 for(int i = 0; i<lcls; i++)
  fwrite("M=0\nA=A+1\n", 1, 10, _vm_ofp);
 fwrite("D=A\n@SP\nM=D\n", 1, 12, _vm_ofp);
}

variable_types: lcls int


initParse

decompiled_code:
size_t __fastcall initParse(const char *a1)
{
size_t result; // rax

parser_stream = (__int64)a1;
parser_com = 0LL;
parser_cur = 0;
result = strlen(a1);
parser_ln = 0;
parser_sz = result;
return result;
}

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

parser_stream = (__int64)a1;
parser_com = 0LL;
parser_cur = 0;
result = strlen(a1);
parser_ln = 0;
parser_sz = result;
return result;
}

original_code:
void initParse(char* buf)
{
 _parser_stream = buf;
 _parser_com = ((void *)0);
 _parser_cur = 0;
 _parser_sz = strlen(_parser_stream);
 _parser_ln = 0;
}

canonical_original_code:
void initParse(char *buf)
{
 _parser_stream = buf;
 _parser_com = ((void *)0);
 _parser_cur = 0;
 _parser_sz = strlen(_parser_stream);
 _parser_ln = 0;
}

variable_types:
buf
char *


hasMoreCommands

decompiled_code:
bool hasMoreCommands()
{
return parser_cur < parser_sz;
}

canonical_decompiled_code:
bool func1()
{
return parser_cur < parser_sz;
}

original_code:
_Bool hasMoreCommands()
{
 if(_parser_cur < _parser_sz)
  return 1;
 return 0;
}


resetCmd

decompiled_code:
void resetCmd()
{
if ( parser_com )
{
free(parser_com);
parser_com = 0LL;
}
}

canonical_decompiled_code:
void func2()
{
if ( parser_com )
{
free(parser_com);
parser_com = 0LL;
}
}

original_code:
void resetCmd()
{
 if(_parser_com != ((void *)0))
 {
  free(_parser_com);
  _parser_com = ((void *)0);
 }
}


advance

decompiled_code:
bool advance()
{
int v0; // ebx
const char *v1; // r12
char *v2; // rbp
char *v3; // rax
char *v4; // rbx
size_t v5; // rbx
char *v6; // rbp
unsigned int v7; // ecx
bool v8; // di
int v9; // er8
__int64 v10; // rax
char *v11; // rax
char *v12; // rax
char v13; // di
__int64 v14; // rsi
__int64 v15; // rdx
char *v16; // rcx
unsigned int v17; // eax
char v18; // dl
bool result; // al

while ( 1 )
{
resetCmd();
v0 = parser_stream;
v1 = (const char *)(parser_stream + parser_cur);
v2 = strchr(v1, 10);
if ( !v2 )
v2 = (char *)&v1[strlen(v1)];
parser_cur = (_DWORD)v2 - v0 + 1;
v3 = strstr(v1, "//");
v4 = v3;
if ( !v3 || v2 <= v3 )
v4 = v2;
v5 = v4 - v1;
v6 = (char *)calloc(v5, 1uLL);
strncpy(v6, v1, v5);
if ( v5 )
{
v7 = 0;
v8 = 1;
v9 = 0;
v10 = 0LL;
while ( 1 )
{
v11 = &v6[v10];
if ( *v11 != 32 && (*v11 & 0xFB) != 9 )
break;
if ( v8 )
{
*v11 = 32;
++v9;
LABEL_8:
v10 = ++v7;
if ( v7 >= v5 )
goto LABEL_12;
}
else
{
v8 = *v11 == 32 || (*v11 & 0xFB) == 9;
v10 = ++v7;
if ( v7 >= v5 )
{
LABEL_12:
v12 = (char *)calloc(v5 + 1 - v9, 1uLL);
v13 = 1;
LODWORD(v14) = 0;
v15 = 0LL;
parser_com = v12;
v16 = v12;
v17 = 0;
while ( 1 )
{
while ( 1 )
{
v18 = v6[v15];
if ( v18 == 32 )
break;
v16[v17 - (unsigned int)v14] = v18;
v16 = parser_com;
v13 = 0;
LABEL_14:
v15 = ++v17;
if ( v17 >= v5 )
goto LABEL_18;
}
if ( !v13 )
{
v13 = 1;
v16[v17 - (unsigned int)v14] = 32;
v16 = parser_com;
goto LABEL_14;
}
LODWORD(v14) = v14 + 1;
v15 = ++v17;
if ( v17 >= v5 )
{
LABEL_18:
v14 = (int)v14;
goto LABEL_19;
}
}
}
}
}
v8 = 0;
goto LABEL_8;
}
v14 = 0LL;
parser_com = (char *)calloc(1uLL, 1uLL);
v16 = parser_com;
LABEL_19:
v16[v5 - 1 - v14] = 0;
++parser_ln;
free(v6);
if ( *parser_com )
return 1;
result = hasMoreCommands();
if ( !result )
return result;
resetCmd();
}
}

canonical_decompiled_code:
bool func3()
{
int v0; // ebx
const char *v1; // r12
char *v2; // rbp
char *v3; // rax
char *v4; // rbx
size_t v5; // rbx
char *v6; // rbp
unsigned int v7; // ecx
bool v8; // di
int v9; // er8
__int64 v10; // rax
char *v11; // rax
char *v12; // rax
char v13; // di
__int64 v14; // rsi
__int64 v15; // rdx
char *v16; // rcx
unsigned int v17; // eax
char v18; // dl
bool result; // al

while ( 1 )
{
func2();
v0 = parser_stream;
v1 = (const char *)(parser_stream + parser_cur);
v2 = strchr(v1, 10);
if ( !v2 )
v2 = (char *)&v1[strlen(v1)];
parser_cur = (_DWORD)v2 - v0 + 1;
v3 = strstr(v1, "//");
v4 = v3;
if ( !v3 || v2 <= v3 )
v4 = v2;
v5 = v4 - v1;
v6 = (char *)calloc(v5, 1uLL);
strncpy(v6, v1, v5);
if ( v5 )
{
v7 = 0;
v8 = 1;
v9 = 0;
v10 = 0LL;
while ( 1 )
{
v11 = &v6[v10];
if ( *v11 != 32 && (*v11 & 0xFB) != 9 )
break;
if ( v8 )
{
*v11 = 32;
++v9;
LABEL_8:
v10 = ++v7;
if ( v7 >= v5 )
goto LABEL_12;
}
else
{
v8 = *v11 == 32 || (*v11 & 0xFB) == 9;
v10 = ++v7;
if ( v7 >= v5 )
{
LABEL_12:
v12 = (char *)calloc(v5 + 1 - v9, 1uLL);
v13 = 1;
LODWORD(v14) = 0;
v15 = 0LL;
parser_com = v12;
v16 = v12;
v17 = 0;
while ( 1 )
{
while ( 1 )
{
v18 = v6[v15];
if ( v18 == 32 )
break;
v16[v17 - (unsigned int)v14] = v18;
v16 = parser_com;
v13 = 0;
LABEL_14:
v15 = ++v17;
if ( v17 >= v5 )
goto LABEL_18;
}
if ( !v13 )
{
v13 = 1;
v16[v17 - (unsigned int)v14] = 32;
v16 = parser_com;
goto LABEL_14;
}
LODWORD(v14) = v14 + 1;
v15 = ++v17;
if ( v17 >= v5 )
{
LABEL_18:
v14 = (int)v14;
goto LABEL_19;
}
}
}
}
}
v8 = 0;
goto LABEL_8;
}
v14 = 0LL;
parser_com = (char *)calloc(1uLL, 1uLL);
v16 = parser_com;
LABEL_19:
v16[v5 - 1 - v14] = 0;
++parser_ln;
free(v6);
if ( *parser_com )
return 1;
result = func1();
if ( !result )
return result;
func2();
}
}

original_code:
_Bool advance()
{
 resetCmd();
 char* sp = _parser_stream+_parser_cur;
 char* ep = strchr(sp, '\n');
 char* res;
 size_t size;
 if(ep == ((void *)0))
  ep = strchr(sp, 0);
 _parser_cur = (ep - _parser_stream) + 1;
 char* tp = strstr(sp, "//");
 if(tp != ((void *)0) && tp < ep)
  ep = tp;
 size = ep-sp;
 res = (char*) calloc(size, sizeof(char));
 strncpy(res, sp, size);
 int ws = 0;
 _Bool is = 1;
 for(unsigned int i = 0; i<size; i++)
 {
  if(res[i] == ' ' || res[i] == '\t' || res[i] == '\r')
  {
   if(is)
   {
    ws++;
    res[i] = ' ';
   }
   else
    is = 1;
  }
  else
   is = 0;
 }
 _parser_com = (char*) calloc(size - ws + 1, sizeof(char));
 is = 1;
 ws = 0;
 for(unsigned int i = 0; i<size; i++)
 {
  if(res[i] == ' ')
  {
   if(is)
    ws++;
   else
   {
    _parser_com[i-ws] = res[i];
    is = 1;
   }
  }
  else
  {
   _parser_com[i-ws] = res[i];
   is = 0;
  }
 }
 _parser_com[size-ws-1] = 0;
 _parser_ln++;
 free(res);
 if(_parser_com[0] == 0)
 {
  if(!hasMoreCommands())
   return 0;
  resetCmd();
  return advance();
 }
 return 1;
}

canonical_original_code:
_Bool advance()
{
 resetCmd();
 char *sp = _parser_stream+_parser_cur;
 char *ep = strchr(sp, '\n');
 char *res;
 unsigned long size;
 if(ep == ((void *)0))
  ep = strchr(sp, 0);
 _parser_cur = (ep - _parser_stream) + 1;
 char *tp = strstr(sp, "//");
 if(tp != ((void *)0) && tp < ep)
  ep = tp;
 size = ep-sp;
 res = (char *) calloc(size, sizeof(char));
 strncpy(res, sp, size);
 int ws = 0;
 _Bool is = 1;
 for(unsigned int i = 0; i<size; i++)
 {
  if(res[i] == ' ' || res[i] == '\t' || res[i] == '\r')
  {
   if(is)
   {
    ws++;
    res[i] = ' ';
   }
   else
    is = 1;
  }
  else
   is = 0;
 }
 _parser_com = (char *) calloc(size - ws + 1, sizeof(char));
 is = 1;
 ws = 0;
 for(unsigned int i = 0; i<size; i++)
 {
  if(res[i] == ' ')
  {
   if(is)
    ws++;
   else
   {
    _parser_com[i-ws] = res[i];
    is = 1;
   }
  }
  else
  {
   _parser_com[i-ws] = res[i];
   is = 0;
  }
 }
 _parser_com[size-ws-1] = 0;
 _parser_ln++;
 free(res);
 if(_parser_com[0] == 0)
 {
  if(!hasMoreCommands())
   return 0;
  resetCmd();
  return advance();
 }
 return 1;
}

variable_types:
sp
char *

variable_types:
ep
char *

variable_types:
res
char *

variable_types:
size
unsigned long

variable_types:
tp
char *

variable_types: ws int

variable_types:
i
unsigned int


commandType

original_code:
int commandType()
{
 char* tp = strchr(_parser_com, ' ');
 char* com;
 int res = -1;
 if((tp = strchr(_parser_com, ' ')) == ((void *)0))
  tp = strchr(_parser_com, 0);
 const char* Type[] =
 {
  "add", "sub", "neg",
  "eq", "gt", "lt",
  "and", "or", "not",
  "push", "pop", "label",
  "goto", "if-goto", "function",
  "call", "return"
 };
 com = (char*) calloc(tp - _parser_com + 1, sizeof(char));
 strncpy(com, _parser_com, tp - _parser_com);
 com[tp - _parser_com] = 0;
 for(int i = 0; i<17; i++)
 {
  if(strcmp(com, Type[i]) == 0)
  {
   res = (i-8)<0 ? 0 : (i-8);
   break;
  }
 }
 free(com);
 return res;
}

canonical_original_code:
int commandType()
{
 char *tp = strchr(_parser_com, ' ');
 char *com;
 int res = -1;
 if((tp = strchr(_parser_com, ' ')) == ((void *)0))
  tp = strchr(_parser_com, 0);
 char *Type[] = {
  "add", "sub", "neg",
  "eq", "gt", "lt",
  "and", "or", "not",
  "push", "pop", "label",
  "goto", "if-goto", "function",
  "call", "return"
 };
 com = (char *) calloc(tp - _parser_com + 1, sizeof(char));
 strncpy(com, _parser_com, tp - _parser_com);
 com[tp - _parser_com] = 0;
 for(int i = 0; i<17; i++)
 {
  if(strcmp(com, Type[i]) == 0)
  {
   res = (i-8)<0 ? 0 : (i-8);
   break;
  }
 }
 free(com);
 return res;
}

variable_types:
com
char *

variable_types: res int

variable_types:
Type
char *[]


decompiled_code:
char *arg1()
{
char *v0; // r12
char *v1; // rbx
size_t v2; // rbx
const char *v3; // rsi
char *result; // rax
const char *v5; // rbp
signed __int64 v6; // rbx
char *v7; // rax
size_t v8; // rdx
char *v9; // r12

v0 = strchr(parser_com, 32);
if ( (unsigned int)commandType() )
{
if ( v0 )
{
v1 = strchr(v0 + 1, 32);
if ( !v1 )
v1 = &v0[strlen(v0)];
v2 = v1 - v0;
v3 = v0 + 1;
v0 = (char *)calloc(v2, 1uLL);
strncpy(v0, v3, v2 - 1);
v0[v2 - 1] = 0;
}
result = v0;
}
else
{
v5 = parser_com;
if ( !v0 )
v0 = (char *)&v5[strlen(parser_com)];
v6 = v0 - v5;
v7 = (char *)calloc(v0 - v5 + 1, 1uLL);
v8 = v0 - v5;
v9 = v7;
strncpy(v7, v5, v8);
v9[v6] = 0;
result = v9;
}
return result;
}

canonical_decompiled_code:
char *func5()
{
char *v0; // r12
char *v1; // rbx
size_t v2; // rbx
const char *v3; // rsi
char *result; // rax
const char *v5; // rbp
signed __int64 v6; // rbx
char *v7; // rax
size_t v8; // rdx
char *v9; // r12

v0 = strchr(parser_com, 32);
if ( (unsigned int)func4() )
{
if ( v0 )
{
v1 = strchr(v0 + 1, 32);
if ( !v1 )
v1 = &v0[strlen(v0)];
v2 = v1 - v0;
v3 = v0 + 1;
v0 = (char *)calloc(v2, 1uLL);
strncpy(v0, v3, v2 - 1);
v0[v2 - 1] = 0;
}
result = v0;
}
else
{
v5 = parser_com;
if ( !v0 )
v0 = (char *)&v5[strlen(parser_com)];
v6 = v0 - v5;
v7 = (char *)calloc(v0 - v5 + 1, 1uLL);
v8 = v0 - v5;
v9 = v7;
strncpy(v7, v5, v8);
v9[v6] = 0;
result = v9;
}
return result;
}

original_code:
char* arg1()
{
 char* sp = strchr(_parser_com, ' ');
 char* ep;
 char* res;
 if(commandType() == C_ARITHMETIC)
 {
 if(sp == ((void *)0))
  sp = strchr(_parser_com, 0);
  res = (char*) calloc(sp-_parser_com+1, sizeof(char));
  strncpy(res, _parser_com, sp-_parser_com);
  res[sp-_parser_com] = 0;
  return res;
 }
 if(sp == ((void *)0))
  return ((void *)0);
 if((ep = strchr(sp+1, ' ')) == ((void *)0))
  ep = strchr(sp, 0);
 res = (char*) calloc(ep-sp, sizeof(char));
 strncpy(res, sp+1, ep-sp-1);
 res[ep-sp-1] = 0;
 return res;
}

canonical_original_code:
char *arg1()
{
 char *sp = strchr(_parser_com, ' ');
 char *ep;
 char *res;
 if(commandType() == C_ARITHMETIC)
 {
 if(sp == ((void *)0))
  sp = strchr(_parser_com, 0);
  res = (char *) calloc(sp-_parser_com+1, sizeof(char));
  strncpy(res, _parser_com, sp-_parser_com);
  res[sp-_parser_com] = 0;
  return res;
 }
 if(sp == ((void *)0))
  return ((void *)0);
 if((ep = strchr(sp+1, ' ')) == ((void *)0))
  ep = strchr(sp, 0);
 res = (char *) calloc(ep-sp, sizeof(char));
 strncpy(res, sp+1, ep-sp-1);
 res[ep-sp-1] = 0;
 return res;
}


toNum

decompiled_code:
__int64 __fastcall toNum(const char *a1)
{
size_t v1; // rsi
size_t v2; // rax
unsigned int v3; // ecx
int v4; // edx
unsigned int v5; // er8
int v6; // eax
unsigned __int8 v7; // al

v1 = strlen(a1);
v2 = (unsigned int)(v1 - 1);
if ( v1 <= v2 )
return 0;
v3 = v1 - 1;
v4 = 1;
v5 = 0;
while ( 1 )
{
v7 = a1[v2] - 48;
if ( v7 > 9u )
break;
v6 = v4 * (char)v7;
v4 *= 10;
v5 += v6;
v2 = --v3;
if ( v1 <= v3 )
return v5;
}
return (unsigned int)-1;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1)
{
size_t v1; // rsi
size_t v2; // rax
unsigned int v3; // ecx
int v4; // edx
unsigned int v5; // er8
int v6; // eax
unsigned __int8 v7; // al

v1 = strlen(a1);
v2 = (unsigned int)(v1 - 1);
if ( v1 <= v2 )
return 0;
v3 = v1 - 1;
v4 = 1;
v5 = 0;
while ( 1 )
{
v7 = a1[v2] - 48;
if ( v7 > 9u )
break;
v6 = v4 * (char)v7;
v4 *= 10;
v5 += v6;
v2 = --v3;
if ( v1 <= v3 )
return v5;
}
return (unsigned int)-1;
}

original_code:
int toNum(char* s)
{
 int res = 0;
 int mul = 1;
 for(unsigned int i=strlen(s) - 1; i < strlen(s); i--)
 {
  if(s[i] < 48 || s[i] > 57)
   return -1;
  res += (s[i] - 48) * mul;
  mul *= 10;
 }
 return res;
}

canonical_original_code:
int toNum(char *s)
{
 int res = 0;
 int mul = 1;
 for(unsigned int i = strlen(s) - 1; i < strlen(s); i--)
 {
  if(s[i] < 48 || s[i] > 57)
   return -1;
  res += (s[i] - 48) * mul;
  mul *= 10;
 }
 return res;
}

variable_types:
s
char *

variable_types: mul int


decompiled_code:
__int64 arg2()
{
char *v0; // rax
char *v1; // rbx
size_t v2; // r12
char *v3; // rbp
unsigned int v4; // er12

v0 = strrchr(parser_com, 32);
if ( !v0 )
return (unsigned int)-1;
v1 = v0;
v2 = strlen(v0);
v3 = (char *)calloc(v2, 1uLL);
strncpy(v3, v1 + 1, v2);
v3[v2] = 0;
v4 = toNum(v3);
free(v3);
return v4;
}

canonical_decompiled_code:
__int64 func7()
{
char *v0; // rax
char *v1; // rbx
size_t v2; // r12
char *v3; // rbp
unsigned int v4; // er12

v0 = strrchr(parser_com, 32);
if ( !v0 )
return (unsigned int)-1;
v1 = v0;
v2 = strlen(v0);
v3 = (char *)calloc(v2, 1uLL);
strncpy(v3, v1 + 1, v2);
v3[v2] = 0;
v4 = func6(v3);
free(v3);
return v4;
}

original_code:
int arg2()
{
 char* sp = strrchr(_parser_com, ' ');
 char* ep;
 char* d;
 int res = -1;
 if(sp == ((void *)0))
  return res;
 ep = strchr(sp, 0);
 d = (char*) calloc(ep-sp, sizeof(char));
 strncpy(d, sp+1, ep-sp);
 d[ep-sp] = 0;
 res = toNum(d);
 free(d);
 return res;
}

canonical_original_code:
int arg2()
{
 char *sp = strrchr(_parser_com, ' ');
 char *ep;
 char *d;
 int res = -1;
 if(sp == ((void *)0))
  return res;
 ep = strchr(sp, 0);
 d = (char *) calloc(ep-sp, sizeof(char));
 strncpy(d, sp+1, ep-sp);
 d[ep-sp] = 0;
 res = toNum(d);
 free(d);
 return res;
}

variable_types:
d
char *


debugString

decompiled_code:
int __fastcall debugString(char *s)
{
unsigned int v1; // ebp
__int64 v2; // rbx
__int64 v3; // rsi

v1 = 0;
v2 = 0LL;
printf("DEBUG: ");
do
{
v3 = (unsigned int)s[v2];
v2 = ++v1;
printf("%d ", v3);
}
while ( v1 <= strlen(s) );
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func8(char *s)
{
unsigned int v1; // ebp
__int64 v2; // rbx
__int64 v3; // rsi

v1 = 0;
v2 = 0LL;
printf("DEBUG: ");
do
{
v3 = (unsigned int)s[v2];
v2 = ++v1;
printf("%d ", v3);
}
while ( v1 <= strlen(s) );
return putchar(10);
}

original_code:
void debugString(char* s)
{
 printf("DEBUG: ");
 for(unsigned int i = 0; i<=strlen(s); i++)
 {
  printf("%d ", s[i]);
 }
 printf("\n");
}

canonical_original_code:
void debugString(char *s)
{
 printf("DEBUG: ");
 for(unsigned int i = 0; i<=strlen(s); i++)
 {
  printf("%d ", s[i]);
 }
 printf("\n");
}


main

canonical_name: main

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

if ( argc <= 2 )
{
puts("Usage: vmtrans <output> <input, ...>");
result = 1;
}
else
{
v4 = argv + 2;
v5 = &argv[(unsigned int)(argc - 3) + 3];
do
{
v6 = (__int64)*v4++;
vmstart(v6, argv, envp);
}
while ( v4 != v5 );
vmasm((unsigned int)(argc - 2), argv + 2, argv[1]);
result = 0;
}
return result;
}

original_code:
int main(int argc, char** argv)
{
 if(argc < 3)
 {
  printf("Usage: vmtrans <output> <input, ...>\n");
  return 1;
 }
 for(int i = 2; i < argc; i++)
 {
  vmstart(argv[i]);
 }
 vmasm(argc-2, argv+2, argv[1]);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 if(argc < 3)
 {
  printf("Usage: vmtrans <output> <input, ...>\n");
  return 1;
 }
 for(int i = 2; i < argc; i++)
 {
  vmstart(argv[i]);
 }
 vmasm(argc-2, argv+2, argv[1]);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: i int


vmstart

decompiled_code:
int __fastcall vmstart(char *s)
{
char *v1; // r12
size_t v2; // r12
char *v3; // r13
char *v4; // r14
const char *v5; // r13

v1 = strrchr(s, 46);
if ( !v1 )
v1 = &s[strlen(s)];
v2 = v1 - s;
vm_ifn = s;
vm_fcn = 0LL;
v3 = (char *)calloc(v2 + 3, 1uLL);
vm_ofn = (__int64)v3;
v4 = (char *)calloc(v2, 1uLL);
vm_sv = (__int64)v4;
strncpy(v3, s, v2);
strncpy(v4, s, v2);
strcat(v3, ".s");
vm_ofp = fopen(v5, "wb");
if ( !vm_lbln )
vm_lbln = 1;
if ( !vm_lcn )
vm_lcn = 1;
vmtrans();
return fclose(vm_ofp);
}

canonical_decompiled_code:
int __fastcall func1(char *s)
{
char *v1; // r12
size_t v2; // r12
char *v3; // r13
char *v4; // r14
const char *v5; // r13

v1 = strrchr(s, 46);
if ( !v1 )
v1 = &s[strlen(s)];
v2 = v1 - s;
vm_ifn = s;
vm_fcn = 0LL;
v3 = (char *)calloc(v2 + 3, 1uLL);
vm_ofn = (__int64)v3;
v4 = (char *)calloc(v2, 1uLL);
vm_sv = (__int64)v4;
strncpy(v3, s, v2);
strncpy(v4, s, v2);
strcat(v3, ".s");
vm_ofp = fopen(v5, "wb");
if ( !vm_lbln )
vm_lbln = 1;
if ( !vm_lcn )
vm_lcn = 1;
func0();
return fclose(vm_ofp);
}

original_code:
void vmstart(char* fn)
{
 char* sp = strrchr(fn, '.');
 if(sp == ((void *)0))
  sp = fn + strlen(fn);
 _vm_ifn = fn;
 _vm_fcn = ((void *)0);
 _vm_ofn = (char*) calloc(sp-fn+3, sizeof(char));
 _vm_sv = (char*) calloc(sp-fn, sizeof(char));
 strncpy(_vm_ofn, fn, sp-fn);
 strncpy(_vm_sv, fn, sp-fn);
 strcat(_vm_ofn, ".s\0");
 _vm_ofp = fopen(_vm_ofn, "wb");
 if(_vm_lbln == 0)
  _vm_lbln = 1;
 if(_vm_lcn == 0)
  _vm_lcn = 1;
 vmtrans();
 fclose(_vm_ofp);
}

canonical_original_code:
void vmstart(char *fn)
{
 char *sp = strrchr(fn, '.');
 if(sp == ((void *)0))
  sp = fn + strlen(fn);
 _vm_ifn = fn;
 _vm_fcn = ((void *)0);
 _vm_ofn = (char *) calloc(sp-fn+3, sizeof(char));
 _vm_sv = (char *) calloc(sp-fn, sizeof(char));
 strncpy(_vm_ofn, fn, sp-fn);
 strncpy(_vm_sv, fn, sp-fn);
 strcat(_vm_ofn, ".s\0");
 _vm_ofp = fopen(_vm_ofn, "wb");
 if(_vm_lbln == 0)
  _vm_lbln = 1;
 if(_vm_lcn == 0)
  _vm_lcn = 1;
 vmtrans();
 fclose(_vm_ofp);
}

variable_types:
fn
char *


vminitout

decompiled_code:
__int64 __fastcall vminitout(const char *a1)
{
FILE *v1; // rax
__int64 v2; // rdx
__int64 v3; // rcx
unsigned int v4; // er8

v1 = fopen(a1, "wb");
v4 = 1;
vm_ofp = v1;
if ( v1 )
{
writeInit(a1, "wb", v2, v3, 1LL);
v4 = 0;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
FILE *v1; // rax
__int64 v2; // rdx
__int64 v3; // rcx
unsigned int v4; // er8

v1 = fopen(a1, "wb");
v4 = 1;
vm_ofp = v1;
if ( v1 )
{
writeInit(a1, "wb", v2, v3, 1LL);
v4 = 0;
}
return v4;
}

original_code:
int vminitout(char* out)
{
 if((_vm_ofp = fopen(out, "wb")) == ((void *)0))
  return 1;
 writeInit();
 return 0;
}

canonical_original_code:
int vminitout(char *out)
{
 if((_vm_ofp = fopen(out, "wb")) == ((void *)0))
  return 1;
 writeInit();
 return 0;
}

variable_types:
out
char *