decompiled_code:
void generate_final_x86()
{
const char *v0; // rbx
__int64 v1; // rax
__int64 v2; // rbx
const char *v3; // rax
const char *v4; // rax
__int64 v5; // rax
const char *v6; // rax
const char *v7; // rax
const char *v8; // rax
const char *v9; // rax
const char *v10; // rax
const char *v11; // rax
const char *v12; // rbx
_DWORD *v13; // rbx
int v14; // edx
const char *v15; // r13
__int64 v16; // r12
const char *v17; // rbx
bool v18; // al
bool v19; // cf
bool v20; // zf
const char *v21; // rdi
__int64 v22; // rcx
const char *v23; // rsi
unsigned int v24; // ebx
unsigned int v25; // ebx
char v26[296]; // [rsp+0h] [rbp-128h] BYREF

v0 = (const char *)gqp;
if ( gqp )
{
do
{
v3 = (const char *)label(v0 + 140);
sprintf(v26, "%s:\n", v3);
add_machine_code_x86(v26);
if ( !strcmp(v0, "begin_block") )
{
v1 = lookup(v0 + 35);
v2 = v1;
if ( !v1 )
_assert_fail("tmp != NULL", "cg_x86.c", 0xBBu, "generate_final_x86");
if ( *(_DWORD *)(v1 + 16) == 2 )
{
strcpy(&prog_name, *(const char **)v1);
strcpy(v26, "main:\n");
add_machine_code_x86(v26);
sprintf(v26, "\tmovl %%esp, %%ebp\n");
add_machine_code_x86(v26);
sprintf(v26, "\tsubl $%d, %%esp\n", *(unsigned int *)(cur_scope + 48LL));
}
else
{
sprintf(v26, "\tmovl %%ebp, %%esp\n");
}
add_machine_code_x86(v26);
ncur = *(_DWORD *)(v2 + 12);
}
else if ( !strcmp(v0, "end_block") )
{
fputc(10, stderr);
v5 = lookup(v0 + 35);
if ( !v5 )
_assert_fail("tmp != NULL", "cg_x86.c", 0xD3u, "generate_final_x86");
if ( *(_DWORD *)(v5 + 16) != 2 )
{
sprintf(v26, "\tmovl %%ebp, %%esp\n");
add_machine_code_x86(v26);
strcpy(v26, "\tret\n");
add_machine_code_x86(v26);
}
}
else if ( !strcmp(v0, "jump") )
{
v6 = (const char *)label(v0 + 105);
sprintf(v26, "\tjmp %s\n", v6);
add_machine_code_x86(v26);
}
else if ( !strcmp(v0, "print") )
{
load_x86("eax", v0 + 35);
sprintf(v26, "\tsubl $%d, %%esp\n", *(unsigned int *)(cur_scope + 48LL));
add_machine_code_x86(v26);
strcpy(v26, "\tcall print\n");
add_machine_code_x86(v26);
sprintf(v26, "\taddl $%d, %%esp\n", *(unsigned int *)(cur_scope + 48LL));
add_machine_code_x86(v26);
}
else if ( !strcmp(v0, ":=") )
{
load_x86("eax", v0 + 35);
store_x86("eax", (__int64)(v0 + 105));
}
else if ( !strcmp(v0, "+") )
{
load_x86("eax", v0 + 35);
load_x86("edx", v0 + 70);
sprintf(v26, "\taddl %%edx, %%eax\n");
add_machine_code_x86(v26);
store_x86("eax", (__int64)(v0 + 105));
}
else if ( !strcmp(v0, "-") )
{
load_x86("eax", v0 + 35);
load_x86("edx", v0 + 70);
sprintf(v26, "\tsubl %%edx, %%eax\n");
add_machine_code_x86(v26);
store_x86("eax", (__int64)(v0 + 105));
}
else if ( !strcmp(v0, "*") )
{
load_x86("eax", v0 + 35);
load_x86("ecx", v0 + 70);
sprintf(v26, "\timul %%ecx\n");
add_machine_code_x86(v26);
store_x86("eax", (__int64)(v0 + 105));
}
else if ( !strcmp(v0, "/") )
{
load_x86("eax", v0 + 35);
load_x86("ecx", v0 + 70);
sprintf(v26, "\tcltd\n\tidiv %%ecx\n");
add_machine_code_x86(v26);
store_x86("eax", (__int64)(v0 + 105));
}
else if ( !strcmp(v0, "=")
|| !strcmp(v0, "<")
|| !strcmp(v0, ">")
|| !strcmp(v0, "<=")
|| !strcmp(v0, ">=")
|| !strcmp(v0, "<>") )
{
load_x86("eax", v0 + 35);
load_x86("edx", v0 + 70);
sprintf(v26, "\tcmp %%edx, %%eax\n");
add_machine_code_x86(v26);
if ( !strcmp(v0, "=") )
{
v7 = (const char *)label(v0 + 105);
sprintf(v26, "\tje %s\n", v7);
add_machine_code_x86(v26);
}
if ( !strcmp(v0, "<") )
{
v8 = (const char *)label(v0 + 105);
sprintf(v26, "\tjl %s\n", v8);
add_machine_code_x86(v26);
}
if ( !strcmp(v0, ">") )
{
v9 = (const char *)label(v0 + 105);
sprintf(v26, "\tjg %s\n", v9);
add_machine_code_x86(v26);
}
if ( !strcmp(v0, "<=") )
{
v10 = (const char *)label(v0 + 105);
sprintf(v26, "\tjle %s\n", v10);
add_machine_code_x86(v26);
}
if ( !strcmp(v0, ">=") )
{
v11 = (const char *)label(v0 + 105);
sprintf(v26, "\tjge %s\n", v11);
add_machine_code_x86(v26);
}
if ( !strcmp(v0, "<>") )
{
v4 = (const char *)label(v0 + 105);
sprintf(v26, "\tjne %s\n", v4);
add_machine_code_x86(v26);
}
}
else if ( !strcmp(v0, "call") )
{
v13 = (_DWORD *)lookup(v0 + 105);
arguments -= v13[12];
v14 = v13[3];
if ( v14 == ncur )
{
sprintf(v26, "\tmovl -4(%%ebp), %%edx\n");
add_machine_code_x86(v26);
sprintf(v26, "\tmovl %%edx, -%d(%%ebp)\n", (unsigned int)(*(_DWORD *)(cur_scope + 48LL) + 4));
add_machine_code_x86(v26);
}
else if ( v14 > ncur )
{
sprintf(v26, "\tmovl %%ebp, -%d(%%ebp)\n", (unsigned int)(*(_DWORD *)(cur_scope + 48LL) + 4));
add_machine_code_x86(v26);
}
sprintf(v26, "\tsubl $%d, %%ebp\n", *(unsigned int *)(cur_scope + 48LL));
add_machine_code_x86(v26);
sprintf(v26, "\tmovl %%ebp, %%esp\n");
add_machine_code_x86(v26);
sprintf(v26, "\tpopl %%eax\n");
add_machine_code_x86(v26);
sprintf(v26, "\tcall L%d\n", (unsigned int)v13[6]);
add_machine_code_x86(v26);
sprintf(v26, "\taddl $%d, %%ebp\n", *(unsigned int *)(cur_scope + 48LL));
add_machine_code_x86(v26);
sprintf(v26, "\tmovl %%ebp, %%esp\n");
add_machine_code_x86(v26);
}
else if ( !strcmp(v0, "par") )
{
v15 = v0 + 70;
v16 = lookup(v0 + 70);
v17 = v0 + 35;
v18 = strcmp(v17, "CV") != 0;
v19 = 0;
v20 = !v18;
if ( v18 )
{
v21 = "RET";
v22 = 4LL;
v23 = v17;
do
{
if ( !v22 )
break;
v19 = *v23 < (unsigned int)*v21;
v20 = *v23++ == *v21++;
--v22;
}
while ( v20 );
if ( (!v19 && !v20) == v19 )
{
sprintf(v26, "\tmovl %%ebp, %%edx\n");
add_machine_code_x86(v26);
sprintf(v26, "\taddl $-%d, %%edx\n", *(unsigned int *)(v16 + 8));
add_machine_code_x86(v26);
sprintf(v26, "\tmovl %%edx, -%d(%%ebp)\n", (unsigned int)(*(_DWORD *)(cur_scope + 48LL) + 8));
add_machine_code_x86(v26);
}
else
{
v24 = *(_DWORD *)(cur_scope + 48LL) + 4 * arguments++ + 12;
if ( *(_DWORD *)(v16 + 12) == ncur )
{
if ( *(_DWORD *)(v16 + 92) == 4 && *(_DWORD *)(v16 + 56) == 1 )
{
sprintf(v26, "\tmovl %%ebp, %%edx\n");
add_machine_code_x86(v26);
sprintf(v26, "\taddl $-%d, %%edx\n", *(unsigned int *)(v16 + 8));
add_machine_code_x86(v26);
sprintf(v26, "\tmovl (%%edx), %%eax\n");
add_machine_code_x86(v26);
sprintf(v26, "\tmovl %%eax, -%d(%%ebp)\n", v24);
add_machine_code_x86(v26);
}
else
{
sprintf(v26, "\tmovl %%ebp, %%edx\n");
add_machine_code_x86(v26);
sprintf(v26, "\taddl $-%d, %%edx\n", *(unsigned int *)(v16 + 8));
add_machine_code_x86(v26);
sprintf(v26, "\tmovl %%edx, -%d(%%ebp)\n", v24);
add_machine_code_x86(v26);
}
}
else
{
gnlvcode(*(_QWORD *)v16, v23);
if ( *(_DWORD *)(v16 + 92) == 4 && *(_DWORD *)(v16 + 56) == 1 )
{
sprintf(v26, "\tmovl (%%ebx), %%eax\n");
add_machine_code_x86(v26);
sprintf(v26, "\tmovl %%eax, -%d(%%ebp)\n", v24);
add_machine_code_x86(v26);
}
else
{
sprintf(v26, "\tmovl %%ebx, -%d(%%ebp)\n", v24);
add_machine_code_x86(v26);
}
}
}
}
else
{
v25 = *(_DWORD *)(cur_scope + 48LL) + 4 * arguments++ + 12;
load_x86("edx", v15);
sprintf(v26, "\tmovl %%edx, -%d(%%ebp)\n\n", v25);
add_machine_code_x86(v26);
}
}
else
{
if ( !strcmp(v0, "halt") )
{
sprintf(v26, "\tmovl %%ebp, %%esp\n");
add_machine_code_x86(v26);
strcpy(v26, "\tret\n");
add_machine_code_x86(v26);
return;
}
if ( !strcmp(v0, "retv") )
{
v12 = v0 + 35;
if ( !strcmp(v12, "_") )
load_x86("eax", "0");
else
load_x86("eax", v12);
sprintf(v26, "\tmovl -8(%%ebp), %%edx\n");
add_machine_code_x86(v26);
sprintf(v26, "\tmovl %%eax, (%%edx)\n");
add_machine_code_x86(v26);
sprintf(v26, "\tmovl %%ebp, %%esp\n");
add_machine_code_x86(v26);
strcpy(v26, "\tret\n");
add_machine_code_x86(v26);
}
}
v0 = *(const char **)(gqp + 184LL);
gqp = v0;
}
while ( v0 );
}
}

canonical_decompiled_code:
void func6()
{
const char *v0; // rbx
__int64 v1; // rax
__int64 v2; // rbx
const char *v3; // rax
const char *v4; // rax
__int64 v5; // rax
const char *v6; // rax
const char *v7; // rax
const char *v8; // rax
const char *v9; // rax
const char *v10; // rax
const char *v11; // rax
const char *v12; // rbx
_DWORD *v13; // rbx
int v14; // edx
const char *v15; // r13
__int64 v16; // r12
const char *v17; // rbx
bool v18; // al
bool v19; // cf
bool v20; // zf
const char *v21; // rdi
__int64 v22; // rcx
const char *v23; // rsi
unsigned int v24; // ebx
unsigned int v25; // ebx
char v26[296]; // [rsp+0h] [rbp-128h] BYREF

v0 = (const char *)gqp;
if ( gqp )
{
do
{
v3 = (const char *)label(v0 + 140);
sprintf(v26, "%s:\n", v3);
func2(v26);
if ( !strcmp(v0, "begin_block") )
{
v1 = lookup(v0 + 35);
v2 = v1;
if ( !v1 )
_assert_fail("tmp != NULL", "cg_x86.c", 0xBBu, "generate_final_x86");
if ( *(_DWORD *)(v1 + 16) == 2 )
{
strcpy(&prog_name, *(const char **)v1);
strcpy(v26, "main:\n");
func2(v26);
sprintf(v26, "\tmovl %%esp, %%ebp\n");
func2(v26);
sprintf(v26, "\tsubl $%d, %%esp\n", *(unsigned int *)(cur_scope + 48LL));
}
else
{
sprintf(v26, "\tmovl %%ebp, %%esp\n");
}
func2(v26);
ncur = *(_DWORD *)(v2 + 12);
}
else if ( !strcmp(v0, "end_block") )
{
fputc(10, stderr);
v5 = lookup(v0 + 35);
if ( !v5 )
_assert_fail("tmp != NULL", "cg_x86.c", 0xD3u, "generate_final_x86");
if ( *(_DWORD *)(v5 + 16) != 2 )
{
sprintf(v26, "\tmovl %%ebp, %%esp\n");
func2(v26);
strcpy(v26, "\tret\n");
func2(v26);
}
}
else if ( !strcmp(v0, "jump") )
{
v6 = (const char *)label(v0 + 105);
sprintf(v26, "\tjmp %s\n", v6);
func2(v26);
}
else if ( !strcmp(v0, "print") )
{
func4("eax", v0 + 35);
sprintf(v26, "\tsubl $%d, %%esp\n", *(unsigned int *)(cur_scope + 48LL));
func2(v26);
strcpy(v26, "\tcall print\n");
func2(v26);
sprintf(v26, "\taddl $%d, %%esp\n", *(unsigned int *)(cur_scope + 48LL));
func2(v26);
}
else if ( !strcmp(v0, ":=") )
{
func4("eax", v0 + 35);
func5("eax", (__int64)(v0 + 105));
}
else if ( !strcmp(v0, "+") )
{
func4("eax", v0 + 35);
func4("edx", v0 + 70);
sprintf(v26, "\taddl %%edx, %%eax\n");
func2(v26);
func5("eax", (__int64)(v0 + 105));
}
else if ( !strcmp(v0, "-") )
{
func4("eax", v0 + 35);
func4("edx", v0 + 70);
sprintf(v26, "\tsubl %%edx, %%eax\n");
func2(v26);
func5("eax", (__int64)(v0 + 105));
}
else if ( !strcmp(v0, "*") )
{
func4("eax", v0 + 35);
func4("ecx", v0 + 70);
sprintf(v26, "\timul %%ecx\n");
func2(v26);
func5("eax", (__int64)(v0 + 105));
}
else if ( !strcmp(v0, "/") )
{
func4("eax", v0 + 35);
func4("ecx", v0 + 70);
sprintf(v26, "\tcltd\n\tidiv %%ecx\n");
func2(v26);
func5("eax", (__int64)(v0 + 105));
}
else if ( !strcmp(v0, "=")
|| !strcmp(v0, "<")
|| !strcmp(v0, ">")
|| !strcmp(v0, "<=")
|| !strcmp(v0, ">=")
|| !strcmp(v0, "<>") )
{
func4("eax", v0 + 35);
func4("edx", v0 + 70);
sprintf(v26, "\tcmp %%edx, %%eax\n");
func2(v26);
if ( !strcmp(v0, "=") )
{
v7 = (const char *)label(v0 + 105);
sprintf(v26, "\tje %s\n", v7);
func2(v26);
}
if ( !strcmp(v0, "<") )
{
v8 = (const char *)label(v0 + 105);
sprintf(v26, "\tjl %s\n", v8);
func2(v26);
}
if ( !strcmp(v0, ">") )
{
v9 = (const char *)label(v0 + 105);
sprintf(v26, "\tjg %s\n", v9);
func2(v26);
}
if ( !strcmp(v0, "<=") )
{
v10 = (const char *)label(v0 + 105);
sprintf(v26, "\tjle %s\n", v10);
func2(v26);
}
if ( !strcmp(v0, ">=") )
{
v11 = (const char *)label(v0 + 105);
sprintf(v26, "\tjge %s\n", v11);
func2(v26);
}
if ( !strcmp(v0, "<>") )
{
v4 = (const char *)label(v0 + 105);
sprintf(v26, "\tjne %s\n", v4);
func2(v26);
}
}
else if ( !strcmp(v0, "call") )
{
v13 = (_DWORD *)lookup(v0 + 105);
arguments -= v13[12];
v14 = v13[3];
if ( v14 == ncur )
{
sprintf(v26, "\tmovl -4(%%ebp), %%edx\n");
func2(v26);
sprintf(v26, "\tmovl %%edx, -%d(%%ebp)\n", (unsigned int)(*(_DWORD *)(cur_scope + 48LL) + 4));
func2(v26);
}
else if ( v14 > ncur )
{
sprintf(v26, "\tmovl %%ebp, -%d(%%ebp)\n", (unsigned int)(*(_DWORD *)(cur_scope + 48LL) + 4));
func2(v26);
}
sprintf(v26, "\tsubl $%d, %%ebp\n", *(unsigned int *)(cur_scope + 48LL));
func2(v26);
sprintf(v26, "\tmovl %%ebp, %%esp\n");
func2(v26);
sprintf(v26, "\tpopl %%eax\n");
func2(v26);
sprintf(v26, "\tcall L%d\n", (unsigned int)v13[6]);
func2(v26);
sprintf(v26, "\taddl $%d, %%ebp\n", *(unsigned int *)(cur_scope + 48LL));
func2(v26);
sprintf(v26, "\tmovl %%ebp, %%esp\n");
func2(v26);
}
else if ( !strcmp(v0, "par") )
{
v15 = v0 + 70;
v16 = lookup(v0 + 70);
v17 = v0 + 35;
v18 = strcmp(v17, "CV") != 0;
v19 = 0;
v20 = !v18;
if ( v18 )
{
v21 = "RET";
v22 = 4LL;
v23 = v17;
do
{
if ( !v22 )
break;
v19 = *v23 < (unsigned int)*v21;
v20 = *v23++ == *v21++;
--v22;
}
while ( v20 );
if ( (!v19 && !v20) == v19 )
{
sprintf(v26, "\tmovl %%ebp, %%edx\n");
func2(v26);
sprintf(v26, "\taddl $-%d, %%edx\n", *(unsigned int *)(v16 + 8));
func2(v26);
sprintf(v26, "\tmovl %%edx, -%d(%%ebp)\n", (unsigned int)(*(_DWORD *)(cur_scope + 48LL) + 8));
func2(v26);
}
else
{
v24 = *(_DWORD *)(cur_scope + 48LL) + 4 * arguments++ + 12;
if ( *(_DWORD *)(v16 + 12) == ncur )
{
if ( *(_DWORD *)(v16 + 92) == 4 && *(_DWORD *)(v16 + 56) == 1 )
{
sprintf(v26, "\tmovl %%ebp, %%edx\n");
func2(v26);
sprintf(v26, "\taddl $-%d, %%edx\n", *(unsigned int *)(v16 + 8));
func2(v26);
sprintf(v26, "\tmovl (%%edx), %%eax\n");
func2(v26);
sprintf(v26, "\tmovl %%eax, -%d(%%ebp)\n", v24);
func2(v26);
}
else
{
sprintf(v26, "\tmovl %%ebp, %%edx\n");
func2(v26);
sprintf(v26, "\taddl $-%d, %%edx\n", *(unsigned int *)(v16 + 8));
func2(v26);
sprintf(v26, "\tmovl %%edx, -%d(%%ebp)\n", v24);
func2(v26);
}
}
else
{
gnlvcode(*(_QWORD *)v16, v23);
if ( *(_DWORD *)(v16 + 92) == 4 && *(_DWORD *)(v16 + 56) == 1 )
{
sprintf(v26, "\tmovl (%%ebx), %%eax\n");
func2(v26);
sprintf(v26, "\tmovl %%eax, -%d(%%ebp)\n", v24);
func2(v26);
}
else
{
sprintf(v26, "\tmovl %%ebx, -%d(%%ebp)\n", v24);
func2(v26);
}
}
}
}
else
{
v25 = *(_DWORD *)(cur_scope + 48LL) + 4 * arguments++ + 12;
func4("edx", v15);
sprintf(v26, "\tmovl %%edx, -%d(%%ebp)\n\n", v25);
func2(v26);
}
}
else
{
if ( !strcmp(v0, "halt") )
{
sprintf(v26, "\tmovl %%ebp, %%esp\n");
func2(v26);
strcpy(v26, "\tret\n");
func2(v26);
return;
}
if ( !strcmp(v0, "retv") )
{
v12 = v0 + 35;
if ( !strcmp(v12, "_") )
func4("eax", "0");
else
func4("eax", v12);
sprintf(v26, "\tmovl -8(%%ebp), %%edx\n");
func2(v26);
sprintf(v26, "\tmovl %%eax, (%%edx)\n");
func2(v26);
sprintf(v26, "\tmovl %%ebp, %%esp\n");
func2(v26);
strcpy(v26, "\tret\n");
func2(v26);
}
}
v0 = *(const char **)(gqp + 184LL);
gqp = v0;
}
while ( v0 );
}
}

original_code:
void generate_final_x86() {
 char s_tmp[255];
 while(gqp != ((void *)0)){
  struct quad* q = gqp;
  sprintf(s_tmp, "%s:\n", label(q->label));
  add_machine_code_x86( s_tmp );
  if (!strcmp(q->op,"begin_block")) {
   SYMBOL *tmp = lookup(q->x);
   ((void) sizeof ((tmp != ((void *)0)) ? 1 : 0), __extension__ ({ if (tmp != ((void *)0)) ; else __assert_fail ("tmp != NULL", "cg_x86.c", 187, __extension__ __PRETTY_FUNCTION__); }));
   if (tmp->func.type == PROG) {
    sprintf(prog_name, "%s", tmp->name);
    sprintf(s_tmp, "main:\n");
             add_machine_code_x86( s_tmp );
    sprintf(s_tmp, "\tmovl %%esp, %%ebp\n");
             add_machine_code_x86( s_tmp );
    sprintf(s_tmp, "\tsubl $%d, %%esp\n", cur_scope->framelength);
             add_machine_code_x86( s_tmp );
   } else {
    sprintf(s_tmp, "\tmovl %%ebp, %%esp\n");
             add_machine_code_x86( s_tmp );
   }
   ncur = tmp->level;
  } else if (!strcmp(q->op,"end_block")) {
   fprintf(stderr, "\n");
   SYMBOL *tmp = lookup(q->x);
   ((void) sizeof ((tmp != ((void *)0)) ? 1 : 0), __extension__ ({ if (tmp != ((void *)0)) ; else __assert_fail ("tmp != NULL", "cg_x86.c", 211, __extension__ __PRETTY_FUNCTION__); }));
   if (tmp->func.type != PROG) {
    sprintf(s_tmp, "\tmovl %%ebp, %%esp\n");
             add_machine_code_x86( s_tmp );
    sprintf(s_tmp, "\tret\n");
          add_machine_code_x86( s_tmp );
   }
  } else if ( strcmp( q->op, "jump") == 0){
            sprintf(s_tmp, "\tjmp %s\n", label(q->z) );
            add_machine_code_x86( s_tmp );
        } else if ( strcmp( q->op, "print") == 0){
   load_x86("eax", q->x);
   sprintf(s_tmp, "\tsubl $%d, %%esp\n", cur_scope->framelength);
            add_machine_code_x86( s_tmp );
   sprintf(s_tmp, "\tcall print\n");
   add_machine_code_x86( s_tmp );
   sprintf(s_tmp, "\taddl $%d, %%esp\n", cur_scope->framelength);
            add_machine_code_x86( s_tmp );
        } else if ( strcmp( q->op, ":=") == 0){
            load_x86("eax", q->x);
            store_x86("eax", q->z);
        } else if ( strcmp( q->op, "+") == 0){
            load_x86("eax", q->x);
            load_x86("edx", q->y);
            sprintf(s_tmp, "\taddl %%edx, %%eax\n" );
            add_machine_code_x86( s_tmp );
            store_x86("eax", q->z);
        } else if ( strcmp( q->op, "-") == 0){
            load_x86("eax", q->x);
            load_x86("edx", q->y);
            sprintf(s_tmp, "\tsubl %%edx, %%eax\n" );
            add_machine_code_x86( s_tmp );
            store_x86("eax", q->z);
        } else if ( strcmp( q->op, "*") == 0){
            load_x86("eax", q->x);
            load_x86("ecx", q->y);
            sprintf(s_tmp, "\timul %%ecx\n" );
            add_machine_code_x86( s_tmp );
            store_x86("eax", q->z);
        } else if ( strcmp( q->op, "/") == 0){
            load_x86("eax", q->x);
            load_x86("ecx", q->y);
            sprintf(s_tmp, "\tcltd\n\tidiv %%ecx\n" );
            add_machine_code_x86( s_tmp );
            store_x86("eax", q->z);
        } else if ( strcmp( q->op, "=") == 0 || strcmp( q->op, "<") == 0 || strcmp( q->op, ">") == 0 || strcmp( q->op, "<=") == 0 || strcmp( q->op, ">=") == 0 || strcmp( q->op, "<>") == 0 ){
            load_x86("eax", q->x);
            load_x86("edx", q->y);
            sprintf(s_tmp, "\tcmp %%edx, %%eax\n" );
            add_machine_code_x86( s_tmp );
            if ( strcmp( q->op, "=") == 0 ){
                sprintf(s_tmp, "\tje %s\n", label(q->z) );
                add_machine_code_x86( s_tmp );
            }
            if ( strcmp( q->op, "<") == 0 ){
                sprintf(s_tmp, "\tjl %s\n", label(q->z) );
                add_machine_code_x86( s_tmp );
            }
            if ( strcmp( q->op, ">") == 0 ){
                sprintf(s_tmp, "\tjg %s\n", label(q->z) );
                add_machine_code_x86( s_tmp );
            }
            if ( strcmp( q->op, "<=") == 0 ){
                sprintf(s_tmp, "\tjle %s\n", label(q->z) );
                add_machine_code_x86( s_tmp );
            }
            if ( strcmp( q->op, ">=") == 0 ){
                sprintf(s_tmp, "\tjge %s\n", label(q->z) );
                add_machine_code_x86( s_tmp );
            }
            if ( strcmp( q->op, "<>") == 0 ){
                sprintf(s_tmp, "\tjne %s\n", label(q->z) );
                add_machine_code_x86( s_tmp );
            }
        } else if ( strcmp( q->op, "call") == 0){
   SYMBOL *p = lookup( q->z );
   arguments -= p->func.num_arg;
   if ( p->level == ncur ) {
    sprintf(s_tmp, "\tmovl -4(%%ebp), %%edx\n");
             add_machine_code_x86( s_tmp );
    sprintf(s_tmp, "\tmovl %%edx, -%d(%%ebp)\n", cur_scope->framelength+4);
             add_machine_code_x86( s_tmp );
   } else if ( p->level > ncur ) {
    sprintf(s_tmp, "\tmovl %%ebp, -%d(%%ebp)\n", cur_scope->framelength+4);
             add_machine_code_x86( s_tmp );
   }
   sprintf(s_tmp, "\tsubl $%d, %%ebp\n", cur_scope->framelength);
            add_machine_code_x86( s_tmp );
   sprintf(s_tmp, "\tmovl %%ebp, %%esp\n");
            add_machine_code_x86( s_tmp );
   sprintf(s_tmp, "\tpopl %%eax\n");
            add_machine_code_x86( s_tmp );
   sprintf(s_tmp, "\tcall L%d\n", p->func.genquad);
   add_machine_code_x86( s_tmp );
   sprintf(s_tmp, "\taddl $%d, %%ebp\n", cur_scope->framelength );
            add_machine_code_x86( s_tmp );
   sprintf(s_tmp, "\tmovl %%ebp, %%esp\n");
            add_machine_code_x86( s_tmp );
        } else if ( strcmp( q->op, "par") == 0){
            SYMBOL *p = lookup( q->y );
            if ( !strcmp(q->x, "CV") ){
    int d = cur_scope->framelength + 12 + 4*arguments;
    arguments++;
                load_x86("edx", q->y);
    sprintf(s_tmp, "\tmovl %%edx, -%d(%%ebp)\n\n", d);
                add_machine_code_x86( s_tmp );
            } else if ( !strcmp(q->x, "RET") ){
    sprintf(s_tmp, "\tmovl %%ebp, %%edx\n");
             add_machine_code_x86( s_tmp );
    sprintf(s_tmp, "\taddl $-%d, %%edx\n", p->offset);
             add_machine_code_x86( s_tmp );
    sprintf(s_tmp, "\tmovl %%edx, -%d(%%ebp)\n", cur_scope->framelength+8);
             add_machine_code_x86( s_tmp );
            } else {
    int d = cur_scope->framelength + 12 + 4*arguments;
    arguments++;
    if ( ncur == p->level ) {
     if (p->type == TYPE_ARG && p->arg.type == INOUT ) {
      sprintf(s_tmp, "\tmovl %%ebp, %%edx\n");
               add_machine_code_x86( s_tmp );
      sprintf(s_tmp, "\taddl $-%d, %%edx\n", p->offset);
               add_machine_code_x86( s_tmp );
      sprintf(s_tmp, "\tmovl (%%edx), %%eax\n");
               add_machine_code_x86( s_tmp );
      sprintf(s_tmp, "\tmovl %%eax, -%d(%%ebp)\n", d);
               add_machine_code_x86( s_tmp );
     } else {
      sprintf(s_tmp, "\tmovl %%ebp, %%edx\n");
               add_machine_code_x86( s_tmp );
      sprintf(s_tmp, "\taddl $-%d, %%edx\n", p->offset);
      add_machine_code_x86( s_tmp );
      sprintf(s_tmp, "\tmovl %%edx, -%d(%%ebp)\n", d);
               add_machine_code_x86( s_tmp );
     }
    } else {
     gnlvcode(p->name);
     if (p->type == TYPE_ARG && p->arg.type == INOUT) {
      sprintf(s_tmp, "\tmovl (%%ebx), %%eax\n");
               add_machine_code_x86( s_tmp );
      sprintf(s_tmp, "\tmovl %%eax, -%d(%%ebp)\n", d);
               add_machine_code_x86( s_tmp );
     } else {
      sprintf(s_tmp, "\tmovl %%ebx, -%d(%%ebp)\n", d);
               add_machine_code_x86( s_tmp );
     }
    }
   }
        }else if ( strcmp( q->op, "halt") == 0){
   sprintf(s_tmp, "\tmovl %%ebp, %%esp\n");
            add_machine_code_x86( s_tmp );
   sprintf(s_tmp, "\tret\n");
   add_machine_code_x86( s_tmp );
   return;
  }else if ( strcmp( q->op, "retv") == 0){
            if( strcmp(q->x,"_") != 0 ){
                load_x86("eax", q->x);
            }else{
                load_x86("eax", "0");
            }
   sprintf(s_tmp, "\tmovl -8(%%ebp), %%edx\n");
            add_machine_code_x86( s_tmp );
            sprintf(s_tmp, "\tmovl %%eax, (%%edx)\n");
            add_machine_code_x86( s_tmp );
   sprintf(s_tmp, "\tmovl %%ebp, %%esp\n");
            add_machine_code_x86( s_tmp );
   sprintf(s_tmp, "\tret\n");
         add_machine_code_x86( s_tmp );
        }
  gqp = gqp->prev;
 }
}

canonical_original_code:
void generate_final_x86() {
 char s_tmp[255];
 while(gqp != ((void *)0)){
  struct quad *q = gqp;
  sprintf(s_tmp, "%s:\n", label(q->label));
  add_machine_code_x86( s_tmp );
  if (!strcmp(q->op,"begin_block")) {
   struct symbol *tmp = lookup(q->x);
   ((void) sizeof ((tmp != ((void *)0)) ? 1 : 0), __extension__ ({ if (tmp != ((void *)0)) ; else __assert_fail ("tmp != NULL", "cg_x86.c", 187, __extension__ __PRETTY_FUNCTION__); }));
   if (tmp->func.type == PROG) {
    sprintf(prog_name, "%s", tmp->name);
    sprintf(s_tmp, "main:\n");
             add_machine_code_x86( s_tmp );
    sprintf(s_tmp, "\tmovl %%esp, %%ebp\n");
             add_machine_code_x86( s_tmp );
    sprintf(s_tmp, "\tsubl $%d, %%esp\n", cur_scope->framelength);
             add_machine_code_x86( s_tmp );
   } else {
    sprintf(s_tmp, "\tmovl %%ebp, %%esp\n");
             add_machine_code_x86( s_tmp );
   }
   ncur = tmp->level;
  } else if (!strcmp(q->op,"end_block")) {
   fprintf(stderr, "\n");
   struct symbol *tmp = lookup(q->x);
   ((void) sizeof ((tmp != ((void *)0)) ? 1 : 0), __extension__ ({ if (tmp != ((void *)0)) ; else __assert_fail ("tmp != NULL", "cg_x86.c", 211, __extension__ __PRETTY_FUNCTION__); }));
   if (tmp->func.type != PROG) {
    sprintf(s_tmp, "\tmovl %%ebp, %%esp\n");
             add_machine_code_x86( s_tmp );
    sprintf(s_tmp, "\tret\n");
          add_machine_code_x86( s_tmp );
   }
  } else if ( strcmp( q->op, "jump") == 0){
            sprintf(s_tmp, "\tjmp %s\n", label(q->z) );
            add_machine_code_x86( s_tmp );
        } else if ( strcmp( q->op, "print") == 0){
   load_x86("eax", q->x);
   sprintf(s_tmp, "\tsubl $%d, %%esp\n", cur_scope->framelength);
            add_machine_code_x86( s_tmp );
   sprintf(s_tmp, "\tcall print\n");
   add_machine_code_x86( s_tmp );
   sprintf(s_tmp, "\taddl $%d, %%esp\n", cur_scope->framelength);
            add_machine_code_x86( s_tmp );
        } else if ( strcmp( q->op, ":=") == 0){
            load_x86("eax", q->x);
            store_x86("eax", q->z);
        } else if ( strcmp( q->op, "+") == 0){
            load_x86("eax", q->x);
            load_x86("edx", q->y);
            sprintf(s_tmp, "\taddl %%edx, %%eax\n" );
            add_machine_code_x86( s_tmp );
            store_x86("eax", q->z);
        } else if ( strcmp( q->op, "-") == 0){
            load_x86("eax", q->x);
            load_x86("edx", q->y);
            sprintf(s_tmp, "\tsubl %%edx, %%eax\n" );
            add_machine_code_x86( s_tmp );
            store_x86("eax", q->z);
        } else if ( strcmp( q->op, "*") == 0){
            load_x86("eax", q->x);
            load_x86("ecx", q->y);
            sprintf(s_tmp, "\timul %%ecx\n" );
            add_machine_code_x86( s_tmp );
            store_x86("eax", q->z);
        } else if ( strcmp( q->op, "/") == 0){
            load_x86("eax", q->x);
            load_x86("ecx", q->y);
            sprintf(s_tmp, "\tcltd\n\tidiv %%ecx\n" );
            add_machine_code_x86( s_tmp );
            store_x86("eax", q->z);
        } else if ( strcmp( q->op, "=") == 0 || strcmp( q->op, "<") == 0 || strcmp( q->op, ">") == 0 || strcmp( q->op, "<=") == 0 || strcmp( q->op, ">=") == 0 || strcmp( q->op, "<>") == 0 ){
            load_x86("eax", q->x);
            load_x86("edx", q->y);
            sprintf(s_tmp, "\tcmp %%edx, %%eax\n" );
            add_machine_code_x86( s_tmp );
            if ( strcmp( q->op, "=") == 0 ){
                sprintf(s_tmp, "\tje %s\n", label(q->z) );
                add_machine_code_x86( s_tmp );
            }
            if ( strcmp( q->op, "<") == 0 ){
                sprintf(s_tmp, "\tjl %s\n", label(q->z) );
                add_machine_code_x86( s_tmp );
            }
            if ( strcmp( q->op, ">") == 0 ){
                sprintf(s_tmp, "\tjg %s\n", label(q->z) );
                add_machine_code_x86( s_tmp );
            }
            if ( strcmp( q->op, "<=") == 0 ){
                sprintf(s_tmp, "\tjle %s\n", label(q->z) );
                add_machine_code_x86( s_tmp );
            }
            if ( strcmp( q->op, ">=") == 0 ){
                sprintf(s_tmp, "\tjge %s\n", label(q->z) );
                add_machine_code_x86( s_tmp );
            }
            if ( strcmp( q->op, "<>") == 0 ){
                sprintf(s_tmp, "\tjne %s\n", label(q->z) );
                add_machine_code_x86( s_tmp );
            }
        } else if ( strcmp( q->op, "call") == 0){
   struct symbol *p = lookup( q->z );
   arguments -= p->func.num_arg;
   if ( p->level == ncur ) {
    sprintf(s_tmp, "\tmovl -4(%%ebp), %%edx\n");
             add_machine_code_x86( s_tmp );
    sprintf(s_tmp, "\tmovl %%edx, -%d(%%ebp)\n", cur_scope->framelength+4);
             add_machine_code_x86( s_tmp );
   } else if ( p->level > ncur ) {
    sprintf(s_tmp, "\tmovl %%ebp, -%d(%%ebp)\n", cur_scope->framelength+4);
             add_machine_code_x86( s_tmp );
   }
   sprintf(s_tmp, "\tsubl $%d, %%ebp\n", cur_scope->framelength);
            add_machine_code_x86( s_tmp );
   sprintf(s_tmp, "\tmovl %%ebp, %%esp\n");
            add_machine_code_x86( s_tmp );
   sprintf(s_tmp, "\tpopl %%eax\n");
            add_machine_code_x86( s_tmp );
   sprintf(s_tmp, "\tcall L%d\n", p->func.genquad);
   add_machine_code_x86( s_tmp );
   sprintf(s_tmp, "\taddl $%d, %%ebp\n", cur_scope->framelength );
            add_machine_code_x86( s_tmp );
   sprintf(s_tmp, "\tmovl %%ebp, %%esp\n");
            add_machine_code_x86( s_tmp );
        } else if ( strcmp( q->op, "par") == 0){
            struct symbol *p = lookup( q->y );
            if ( !strcmp(q->x, "CV") ){
    int d = cur_scope->framelength + 12 + 4*arguments;
    arguments++;
                load_x86("edx", q->y);
    sprintf(s_tmp, "\tmovl %%edx, -%d(%%ebp)\n\n", d);
                add_machine_code_x86( s_tmp );
            } else if ( !strcmp(q->x, "RET") ){
    sprintf(s_tmp, "\tmovl %%ebp, %%edx\n");
             add_machine_code_x86( s_tmp );
    sprintf(s_tmp, "\taddl $-%d, %%edx\n", p->offset);
             add_machine_code_x86( s_tmp );
    sprintf(s_tmp, "\tmovl %%edx, -%d(%%ebp)\n", cur_scope->framelength+8);
             add_machine_code_x86( s_tmp );
            } else {
    int d = cur_scope->framelength + 12 + 4*arguments;
    arguments++;
    if ( ncur == p->level ) {
     if (p->type == TYPE_ARG && p->arg.type == INOUT ) {
      sprintf(s_tmp, "\tmovl %%ebp, %%edx\n");
               add_machine_code_x86( s_tmp );
      sprintf(s_tmp, "\taddl $-%d, %%edx\n", p->offset);
               add_machine_code_x86( s_tmp );
      sprintf(s_tmp, "\tmovl (%%edx), %%eax\n");
               add_machine_code_x86( s_tmp );
      sprintf(s_tmp, "\tmovl %%eax, -%d(%%ebp)\n", d);
               add_machine_code_x86( s_tmp );
     } else {
      sprintf(s_tmp, "\tmovl %%ebp, %%edx\n");
               add_machine_code_x86( s_tmp );
      sprintf(s_tmp, "\taddl $-%d, %%edx\n", p->offset);
      add_machine_code_x86( s_tmp );
      sprintf(s_tmp, "\tmovl %%edx, -%d(%%ebp)\n", d);
               add_machine_code_x86( s_tmp );
     }
    } else {
     gnlvcode(p->name);
     if (p->type == TYPE_ARG && p->arg.type == INOUT) {
      sprintf(s_tmp, "\tmovl (%%ebx), %%eax\n");
               add_machine_code_x86( s_tmp );
      sprintf(s_tmp, "\tmovl %%eax, -%d(%%ebp)\n", d);
               add_machine_code_x86( s_tmp );
     } else {
      sprintf(s_tmp, "\tmovl %%ebx, -%d(%%ebp)\n", d);
               add_machine_code_x86( s_tmp );
     }
    }
   }
        }else if ( strcmp( q->op, "halt") == 0){
   sprintf(s_tmp, "\tmovl %%ebp, %%esp\n");
            add_machine_code_x86( s_tmp );
   sprintf(s_tmp, "\tret\n");
   add_machine_code_x86( s_tmp );
   return;
  }else if ( strcmp( q->op, "retv") == 0){
            if( strcmp(q->x,"_") != 0 ){
                load_x86("eax", q->x);
            }else{
                load_x86("eax", "0");
            }
   sprintf(s_tmp, "\tmovl -8(%%ebp), %%edx\n");
            add_machine_code_x86( s_tmp );
            sprintf(s_tmp, "\tmovl %%eax, (%%edx)\n");
            add_machine_code_x86( s_tmp );
   sprintf(s_tmp, "\tmovl %%ebp, %%esp\n");
            add_machine_code_x86( s_tmp );
   sprintf(s_tmp, "\tret\n");
         add_machine_code_x86( s_tmp );
        }
  gqp = gqp->prev;
 }
}

variable_types: struct quad { char op[35]; char x[35]; char label[35]; struct quad *next; struct quad *prev; } *

variable_types: d int


repo: ptigas/ciscal

decompiled_code:
_QWORD *pop_scope()
{
_QWORD *result; // rax
__int64 v1; // rdx
__int64 v2; // rdx
__int64 i; // rdx

--level;
result = (_QWORD *)cur_scope;
v1 = *(_QWORD *)(cur_scope + 24);
if ( v1 && !*(_DWORD *)(v1 + 52) && !*(_DWORD *)(v1 + 16) )
{
fprintf(stderr, "line %d: function %s has no return stat.\n", line, *(const char **)v1);
exit(1);
}
v2 = *(_QWORD *)(cur_scope + 40);
if ( v2 )
{
*(_QWORD *)(v2 + 32) = 0LL;
result = (_QWORD *)result[5];
cur_scope = (__int64)result;
for ( i = result[2]; i; i = *(_QWORD *)(i + 96) )
{
if ( !*(_DWORD *)(i + 92) )
{
for ( result = *(_QWORD **)(i + 40); result; result = (_QWORD *)result[8] )
;
}
}
}
return result;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *result; // rax
__int64 v1; // rdx
__int64 v2; // rdx
__int64 i; // rdx

--level;
result = (_QWORD *)cur_scope;
v1 = *(_QWORD *)(cur_scope + 24);
if ( v1 && !*(_DWORD *)(v1 + 52) && !*(_DWORD *)(v1 + 16) )
{
fprintf(stderr, "line %d: function %s has no return stat.\n", line, *(const char **)v1);
exit(1);
}
v2 = *(_QWORD *)(cur_scope + 40);
if ( v2 )
{
*(_QWORD *)(v2 + 32) = 0LL;
result = (_QWORD *)result[5];
cur_scope = (__int64)result;
for ( i = result[2]; i; i = *(_QWORD *)(i + 96) )
{
if ( !*(_DWORD *)(i + 92) )
{
for ( result = *(_QWORD **)(i + 40); result; result = (_QWORD *)result[8] )
;
}
}
}
return result;
}

original_code:
void pop_scope() {
 SYMBOL *cur, *arg;
 level--;
 if (cur_scope->from) {
  if(cur_scope->from->func.has_return == 0 && cur_scope->from->func.type == FUNC) {
   fprintf(stderr, "line %d: function %s has no return stat.\n", line, cur_scope->from->name);
   exit(1);
  }
 }
 if(cur_scope->prev != ((void *)0)) {
  cur_scope->prev->next = ((void *)0);
  cur_scope = cur_scope->prev;
  cur = cur_scope->symbols;
  while(cur != ((void *)0)) {
   if (cur->type == TYPE_FUNC) {
    arg = cur->func.first_arg;
    while(arg != ((void *)0)) {
     arg = arg->arg.next_arg;
    }
   }
   cur = cur->next;
  }
 }
}

canonical_original_code:
void pop_scope() {
 struct symbol *cur; struct symbol *arg;
 level--;
 if (cur_scope->from) {
  if(cur_scope->from->func.has_return == 0 && cur_scope->from->func.type == FUNC) {
   fprintf(stderr, "line %d: function %s has no return stat.\n", line, cur_scope->from->name);
   exit(1);
  }
 }
 if(cur_scope->prev != ((void *)0)) {
  cur_scope->prev->next = ((void *)0);
  cur_scope = cur_scope->prev;
  cur = cur_scope->symbols;
  while(cur != ((void *)0)) {
   if (cur->type == TYPE_FUNC) {
    arg = cur->func.first_arg;
    while(arg != ((void *)0)) {
     arg = arg->arg.next_arg;
    }
   }
   cur = cur->next;
  }
 }
}

variable_types: struct symbol { char *name; int offset; int level; struct function { enum FTYPE { FUNC=0, PROC=1, PROG=2 } type; int size; int genquad; struct symbol *args; struct symbol *first_arg; int num_arg; int has_return; } func; struct argument { enum PARTYPE { IN=0, INOUT=1 } type; struct symbol *next_arg; struct symbol *func; int offset; int num; } arg; struct variable { int offset; } var; enum T { TYPE_FUNC=0, TYPE_VAR=1, TYPE_CONST=2, TYPE_TMP=3, TYPE_ARG=4 } type; struct symbol *next; } *

return_type: void

user_defined_types: struct symbol { char *name; int offset; int level; struct function func; struct argument arg; struct variable var; enum T type; struct symbol *next; }

user_defined_types: struct function { enum FTYPE type; int size; int genquad; struct symbol *args; struct symbol *first_arg; int num_arg; int has_return; }

user_defined_types: struct argument { enum PARTYPE type; struct symbol *next_arg; struct symbol *func; int offset; int num; }


decompiled_code:
size_t print_symbol_table()
{
__int64 i; // r12
__int64 v2; // rbp
__int64 j; // rbx
int v4; // eax

fwrite("-------------\n", 1uLL, 0xEuLL, stderr);
for ( i = global_scope; i; i = *(_QWORD *)(i + 32) )
{
fprintf(stderr, "%d: %s\n", *(unsigned int *)(i + 8), *(const char **)i);
for ( j = *(_QWORD *)(i + 16); j; j = *(_QWORD *)(j + 96) )
{
fprintf(stderr, "\t%s", *(const char **)j);
v4 = *(_DWORD *)(j + 92);
if ( v4 )
{
if ( v4 == 1 )
{
fprintf(stderr, "[V] offset %d", *(unsigned int *)(j + 8));
}
else if ( v4 == 4 )
{
fprintf(stderr, "[A] offset %d", *(unsigned int *)(j + 8));
}
else
{
fprintf(stderr, "[E] offset %d", *(unsigned int *)(j + 8));
}
}
else
{
v2 = *(_QWORD *)(j + 40);
fputc(40, stderr);
for ( ; v2; v2 = *(_QWORD *)(v2 + 64) )
fprintf(stderr, "%s ", *(const char **)v2);
fputc(41, stderr);
}
fputc(10, stderr);
}
fputc(10, stderr);
}
return fwrite("-------------\n", 1uLL, 0xEuLL, stderr);
}

canonical_decompiled_code:
size_t func1()
{
__int64 i; // r12
__int64 v2; // rbp
__int64 j; // rbx
int v4; // eax

fwrite("-------------\n", 1uLL, 0xEuLL, stderr);
for ( i = global_scope; i; i = *(_QWORD *)(i + 32) )
{
fprintf(stderr, "%d: %s\n", *(unsigned int *)(i + 8), *(const char **)i);
for ( j = *(_QWORD *)(i + 16); j; j = *(_QWORD *)(j + 96) )
{
fprintf(stderr, "\t%s", *(const char **)j);
v4 = *(_DWORD *)(j + 92);
if ( v4 )
{
if ( v4 == 1 )
{
fprintf(stderr, "[V] offset %d", *(unsigned int *)(j + 8));
}
else if ( v4 == 4 )
{
fprintf(stderr, "[A] offset %d", *(unsigned int *)(j + 8));
}
else
{
fprintf(stderr, "[E] offset %d", *(unsigned int *)(j + 8));
}
}
else
{
v2 = *(_QWORD *)(j + 40);
fputc(40, stderr);
for ( ; v2; v2 = *(_QWORD *)(v2 + 64) )
fprintf(stderr, "%s ", *(const char **)v2);
fputc(41, stderr);
}
fputc(10, stderr);
}
fputc(10, stderr);
}
return fwrite("-------------\n", 1uLL, 0xEuLL, stderr);
}

original_code:
void print_symbol_table() {
 SCOPE *cur;
 SYMBOL *sym, *arg;
 fprintf(stderr, "-------------\n");
 cur = global_scope;
 while (cur != ((void *)0)) {
  fprintf(stderr, "%d: %s\n", cur->level, cur->name);
  sym = cur->symbols;
  while (sym != ((void *)0)) {
   fprintf(stderr, "\t%s", sym->name);
   if (sym->type == TYPE_FUNC) {
    arg = sym->func.first_arg;
    fprintf(stderr, "(");
    while(arg != ((void *)0)) {
     fprintf(stderr, "%s ", arg->name);
     arg = arg->arg.next_arg;
    }
    fprintf(stderr, ")");
   } else if (sym->type == TYPE_VAR) {
    fprintf(stderr, "[V] offset %d", sym->offset);
   } else if (sym->type == TYPE_ARG) {
    fprintf(stderr, "[A] offset %d", sym->offset);
   } else {
    fprintf(stderr, "[E] offset %d", sym->offset);
   }
   fprintf(stderr, "\n");
   sym = sym->next;
  }
  fprintf(stderr, "\n");
  cur = cur->next;
 }
 fprintf(stderr, "-------------\n");
}

canonical_original_code:
void print_symbol_table() {
 struct scope *cur;
 struct symbol *sym; struct symbol *arg;
 fprintf(stderr, "-------------\n");
 cur = global_scope;
 while (cur != ((void *)0)) {
  fprintf(stderr, "%d: %s\n", cur->level, cur->name);
  sym = cur->symbols;
  while (sym != ((void *)0)) {
   fprintf(stderr, "\t%s", sym->name);
   if (sym->type == TYPE_FUNC) {
    arg = sym->func.first_arg;
    fprintf(stderr, "(");
    while(arg != ((void *)0)) {
     fprintf(stderr, "%s ", arg->name);
     arg = arg->arg.next_arg;
    }
    fprintf(stderr, ")");
   } else if (sym->type == TYPE_VAR) {
    fprintf(stderr, "[V] offset %d", sym->offset);
   } else if (sym->type == TYPE_ARG) {
    fprintf(stderr, "[A] offset %d", sym->offset);
   } else {
    fprintf(stderr, "[E] offset %d", sym->offset);
   }
   fprintf(stderr, "\n");
   sym = sym->next;
  }
  fprintf(stderr, "\n");
  cur = cur->next;
 }
 fprintf(stderr, "-------------\n");
}

variable_types: struct scope { char *name; int level; struct symbol { char *name; int offset; int level; struct function { enum FTYPE { FUNC=0, PROC=1, PROG=2 } type; int size; int genquad; struct symbol *args; struct symbol *first_arg; int num_arg; int has_return; } func; struct argument { enum PARTYPE { IN=0, INOUT=1 } type; struct symbol *next_arg; struct symbol *func; int offset; int num; } arg; struct variable { int offset; } var; enum T { TYPE_FUNC=0, TYPE_VAR=1, TYPE_CONST=2, TYPE_TMP=3, TYPE_ARG=4 } type; struct symbol *next; } *symbols; struct symbol *from; struct scope *next; struct scope *prev; int framelength; } *

user_defined_types: struct scope { char *name; int level; struct symbol *symbols; struct symbol *from; struct scope *next; struct scope *prev; int framelength; }


decompiled_code:
__int64 __fastcall install_symbol(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rdx

if ( *(_DWORD *)(a1 + 92) )
{
*(_DWORD *)(a1 + 12) = *(_DWORD *)(cur_scope + 8);
}
else if ( *(_DWORD *)(a1 + 16) == 2 )
{
*(_DWORD *)(a1 + 12) = 1;
}
else
{
*(_DWORD *)(a1 + 12) = *(_DWORD *)(cur_scope + 8) + 1;
}
result = cur_scope;
v2 = *(_QWORD *)(cur_scope + 16);
if ( v2 )
*(_QWORD *)(a1 + 96) = v2;
*(_QWORD *)(result + 16) = a1;
return result;
}

original_code:
void install_symbol(SYMBOL *sym) {
 if (sym->type == TYPE_FUNC && sym->func.type == PROG) {
  sym->level = 1;
 } else {
  if ( sym->type == TYPE_FUNC ) {
   sym->level = cur_scope->level+1;
  } else {
   sym->level = cur_scope->level;
  }
 }
 if(cur_scope->symbols == ((void *)0)) {
  cur_scope->symbols = sym;
 } else {
  sym->next = cur_scope->symbols;
  cur_scope->symbols = sym;
 }
}

canonical_original_code:
void install_symbol(struct symbol *sym) {
 if (sym->type == TYPE_FUNC && sym->func.type == PROG) {
  sym->level = 1;
 } else {
  if ( sym->type == TYPE_FUNC ) {
   sym->level = cur_scope->level+1;
  } else {
   sym->level = cur_scope->level;
  }
 }
 if(cur_scope->symbols == ((void *)0)) {
  cur_scope->symbols = sym;
 } else {
  sym->next = cur_scope->symbols;
  cur_scope->symbols = sym;
 }
}

user_defined_types: enum T { TYPE_FUNC=0, TYPE_VAR=1, TYPE_CONST=2, TYPE_TMP=3, TYPE_ARG=4 }


original_code:
void add_argument(char *name, PARTYPE par) {
 SYMBOL *sym = (SYMBOL*)malloc(sizeof(SYMBOL));
 sym->offset = cur_scope->framelength;
 sym->type = TYPE_ARG;
 sym->name = strdup(name);
 sym->arg.type = par;
 sym->arg.num = ++cur_scope->prev->symbols->func.num_arg;
 sym->arg.next_arg = ((void *)0);
 sym->arg.func = cur_scope->prev->symbols;
 sym->level = cur_scope->level;
 cur_scope->framelength += 4;
 install_symbol(sym);
 if( cur_scope->prev->symbols->func.args == ((void *)0) ) {
  cur_scope->prev->symbols->func.first_arg = sym;
  cur_scope->prev->symbols->func.args = sym;
 } else {
  cur_scope->prev->symbols->func.args->arg.next_arg = sym;
  cur_scope->prev->symbols->func.args = sym;
 }
}

canonical_original_code:
void add_argument(char *name, enum PARTYPE par) {
 struct symbol *sym = (SYMBOL*)malloc(sizeof(SYMBOL));
 sym->offset = cur_scope->framelength;
 sym->type = TYPE_ARG;
 sym->name = strdup(name);
 sym->arg.type = par;
 sym->arg.num = ++cur_scope->prev->symbols->func.num_arg;
 sym->arg.next_arg = ((void *)0);
 sym->arg.func = cur_scope->prev->symbols;
 sym->level = cur_scope->level;
 cur_scope->framelength += 4;
 install_symbol(sym);
 if( cur_scope->prev->symbols->func.args == ((void *)0) ) {
  cur_scope->prev->symbols->func.first_arg = sym;
  cur_scope->prev->symbols->func.args = sym;
 } else {
  cur_scope->prev->symbols->func.args->arg.next_arg = sym;
  cur_scope->prev->symbols->func.args = sym;
 }
}

variable_types:
name
char *

variable_types:
par
enum PARTYPE { IN=0, INOUT=1 }


lookup

decompiled_code:
__int64 __fastcall lookup(char *s2)
{
__int64 v1; // r12
__int64 v2; // rbx

v1 = cur_scope;
if ( !cur_scope )
return cur_scope;
while ( 1 )
{
v2 = *(_QWORD *)(v1 + 16);
if ( v2 )
break;
LABEL_5:
v1 = *(_QWORD *)(v1 + 40);
if ( !v1 )
return 0LL;
}
while ( strcmp(*(const char **)v2, s2) )
{
v2 = *(_QWORD *)(v2 + 96);
if ( !v2 )
goto LABEL_5;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *s2)
{
__int64 v1; // r12
__int64 v2; // rbx

v1 = cur_scope;
if ( !cur_scope )
return cur_scope;
while ( 1 )
{
v2 = *(_QWORD *)(v1 + 16);
if ( v2 )
break;
LABEL_5:
v1 = *(_QWORD *)(v1 + 40);
if ( !v1 )
return 0LL;
}
while ( strcmp(*(const char **)v2, s2) )
{
v2 = *(_QWORD *)(v2 + 96);
if ( !v2 )
goto LABEL_5;
}
return v2;
}

original_code:
SYMBOL * lookup(char *name) {
 SCOPE *cur;
 SYMBOL *sym;
 cur = cur_scope;
 while (cur != ((void *)0)) {
  sym = cur->symbols;
  while (sym != ((void *)0)) {
   if(!strcmp(sym->name, name)) {
    return sym;
   }
   sym = sym->next;
  }
  cur = cur->prev;
 }
 return ((void *)0);
}

canonical_original_code:
struct symbol *lookup(char *name) {
 struct scope *cur;
 struct symbol *sym;
 cur = cur_scope;
 while (cur != ((void *)0)) {
  sym = cur->symbols;
  while (sym != ((void *)0)) {
   if(!strcmp(sym->name, name)) {
    return sym;
   }
   sym = sym->next;
  }
  cur = cur->prev;
 }
 return ((void *)0);
}

return_type: struct symbol { char *name; int offset; int level; struct function { enum FTYPE { FUNC=0, PROC=1, PROG=2 } type; int size; int genquad; struct symbol *args; struct symbol *first_arg; int num_arg; int has_return; } func; struct argument { enum PARTYPE { IN=0, INOUT=1 } type; struct symbol *next_arg; struct symbol *func; int offset; int num; } arg; struct variable { int offset; } var; enum T { TYPE_FUNC=0, TYPE_VAR=1, TYPE_CONST=2, TYPE_TMP=3, TYPE_ARG=4 } type; struct symbol *next; } *


decompiled_code:
__int64 __fastcall new_variable(char *s2, int a2)
{
_DWORD *v2; // rbx
__int64 v3; // r12
__int64 v4; // rax

v2 = malloc(0x68uLL);
v3 = cur_scope;
v2[2] = *(_DWORD *)(cur_scope + 48);
*(_DWORD *)(v3 + 48) += 4;
v4 = lookup(s2);
if ( v4 && *(_DWORD *)(v4 + 12) == *(_DWORD *)(v3 + 8) )
{
if ( *(_DWORD *)(v4 + 92) != 4 )
{
fprintf(stderr, "error line %d: redecleration of %s in the same scope.\n", line, s2);
exit(1);
}
fprintf(stderr, "error line %d: redecleration of argument %s\n", line, s2);
exit(1);
}
v2[23] = 2 * (a2 == 1) + 1;
*(_QWORD *)v2 = strdup(s2);
*((_QWORD *)v2 + 12) = 0LL;
return install_symbol((__int64)v2);
}

canonical_decompiled_code:
__int64 __fastcall func6(char *s2, int a2)
{
_DWORD *v2; // rbx
__int64 v3; // r12
__int64 v4; // rax

v2 = malloc(0x68uLL);
v3 = cur_scope;
v2[2] = *(_DWORD *)(cur_scope + 48);
*(_DWORD *)(v3 + 48) += 4;
v4 = func4(s2);
if ( v4 && *(_DWORD *)(v4 + 12) == *(_DWORD *)(v3 + 8) )
{
if ( *(_DWORD *)(v4 + 92) != 4 )
{
fprintf(stderr, "error line %d: redecleration of %s in the same scope.\n", line, s2);
exit(1);
}
fprintf(stderr, "error line %d: redecleration of argument %s\n", line, s2);
exit(1);
}
v2[23] = 2 * (a2 == 1) + 1;
*(_QWORD *)v2 = strdup(s2);
*((_QWORD *)v2 + 12) = 0LL;
return func2((__int64)v2);
}

original_code:
void new_variable(char *name, int istmp) {
 SYMBOL *t;
 SYMBOL *sym = (SYMBOL*)malloc(sizeof(SYMBOL));
 sym->offset = cur_scope->framelength;
 cur_scope->framelength += 4;
 t = lookup(name);
 if(t != ((void *)0)) {
  if(t->level == cur_scope->level) {
   if (t->type == TYPE_ARG) {
    fprintf(stderr, "error line %d: redecleration of argument %s\n", line, name);
    exit(1);
   } else {
    fprintf(stderr, "error line %d: redecleration of %s in the same scope.\n", line, name);
    exit(1);
   }
  }
 }
 if (istmp == 1) {
  sym->type = TYPE_TMP;
 } else {
  sym->type = TYPE_VAR;
 }
 sym->name = strdup(name);
 sym->next = ((void *)0);
 install_symbol(sym);
}

canonical_original_code:
void new_variable(char *name, int istmp) {
 struct symbol *t;
 struct symbol *sym = (SYMBOL*)malloc(sizeof(SYMBOL));
 sym->offset = cur_scope->framelength;
 cur_scope->framelength += 4;
 t = lookup(name);
 if(t != ((void *)0)) {
  if(t->level == cur_scope->level) {
   if (t->type == TYPE_ARG) {
    fprintf(stderr, "error line %d: redecleration of argument %s\n", line, name);
    exit(1);
   } else {
    fprintf(stderr, "error line %d: redecleration of %s in the same scope.\n", line, name);
    exit(1);
   }
  }
 }
 if (istmp == 1) {
  sym->type = TYPE_TMP;
 } else {
  sym->type = TYPE_VAR;
 }
 sym->name = strdup(name);
 sym->next = ((void *)0);
 install_symbol(sym);
}

variable_types: istmp int


decompiled_code:
__int64 __fastcall new_function(char *s2, int a2)
{
_DWORD *v2; // rbx

v2 = malloc(0x68uLL);
if ( lookup(s2) )
{
fprintf(stderr, "error line %d: redecleration of %s\n", line, s2);
exit(1);
}
v2[23] = 0;
*(_QWORD *)v2 = strdup(s2);
v2[4] = a2;
v2[12] = 0;
v2[13] = 0;
*((_QWORD *)v2 + 4) = 0LL;
*((_QWORD *)v2 + 12) = 0LL;
return install_symbol((__int64)v2);
}

canonical_decompiled_code:
__int64 __fastcall func7(char *s2, int a2)
{
_DWORD *v2; // rbx

v2 = malloc(0x68uLL);
if ( func4(s2) )
{
fprintf(stderr, "error line %d: redecleration of %s\n", line, s2);
exit(1);
}
v2[23] = 0;
*(_QWORD *)v2 = strdup(s2);
v2[4] = a2;
v2[12] = 0;
v2[13] = 0;
*((_QWORD *)v2 + 4) = 0LL;
*((_QWORD *)v2 + 12) = 0LL;
return func2((__int64)v2);
}

original_code:
void new_function(char *name, FTYPE type) {
 SYMBOL *t;
 SYMBOL *sym = (SYMBOL*)malloc(sizeof(SYMBOL));
 t = lookup(name);
 if(t != ((void *)0)) {
  fprintf(stderr, "error line %d: redecleration of %s\n", line, name);
  exit(1);
 }
 sym->type = TYPE_FUNC;
 sym->name = strdup(name);
 sym->func.type = type;
 sym->func.num_arg = 0;
 sym->func.has_return = 0;
 sym->func.args = ((void *)0);
 sym->next = ((void *)0);
 install_symbol(sym);
}

canonical_original_code:
void new_function(char *name, enum FTYPE type) {
 struct symbol *t;
 struct symbol *sym = (SYMBOL*)malloc(sizeof(SYMBOL));
 t = lookup(name);
 if(t != ((void *)0)) {
  fprintf(stderr, "error line %d: redecleration of %s\n", line, name);
  exit(1);
 }
 sym->type = TYPE_FUNC;
 sym->name = strdup(name);
 sym->func.type = type;
 sym->func.num_arg = 0;
 sym->func.has_return = 0;
 sym->func.args = ((void *)0);
 sym->next = ((void *)0);
 install_symbol(sym);
}

variable_types:
type
enum FTYPE { FUNC=0, PROC=1, PROG=2 }


decompiled_code:
__int64 __fastcall is_const(const char *a1)
{
size_t v1; // r13
unsigned int i; // ebp

v1 = strlen(a1);
for ( i = 0; i < v1; ++i )
{
if ( ((*_ctype_b_loc())[a1[i]] & 0x800) == 0 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
size_t v1; // r13
unsigned int i; // ebp

v1 = strlen(a1);
for ( i = 0; i < v1; ++i )
{
if ( ((*_ctype_b_loc())[a1[i]] & 0x800) == 0 )
return 0LL;
}
return 1LL;
}

original_code:
int is_const(char *s) {
 unsigned int i;
 for(i=0; i<strlen(s); i++) {
  if(!((*__ctype_b_loc ())[(int) ((s[i]))] & (unsigned short int) _ISdigit)) {
   return 0;
  }
 }
 return 1;
}

canonical_original_code:
int is_const(char *s) {
 unsigned int i;
 for(i=0; i<strlen(s); i++) {
  if(!((*__ctype_b_loc ())[(int) ((s[i]))] & (unsigned short) _ISdigit)) {
   return 0;
  }
 }
 return 1;
}

variable_types:
s
char *

variable_types:
i
unsigned int

return_type: int


label

decompiled_code:
char *__fastcall label(const char *a1)
{
char v2[56]; // [rsp+0h] [rbp-38h] BYREF

sprintf(v2, "L%s", a1);
return strdup(v2);
}

canonical_decompiled_code:
char *__fastcall func1(const char *a1)
{
char v2[56]; // [rsp+0h] [rbp-38h] BYREF

sprintf(v2, "L%s", a1);
return strdup(v2);
}

original_code:
char * label( char *l ){
    char s[35];
    sprintf(s, "L%s", l);
    return strdup(s);
}

canonical_original_code:
char *label(char *l){
    char s[35];
    sprintf(s, "L%s", l);
    return strdup(s);
}

variable_types:
l
char *

variable_types:
s
char [35]

return_type: char *


decompiled_code:
__int64 __fastcall add_machine_code(char *src)
{
char *v1; // rbx
__int64 result; // rax

v1 = (char *)malloc(0x110uLL);
strcpy(v1, src);
result = mc;
if ( mc )
{
*(_QWORD *)(mc + 264) = v1;
*((_QWORD *)v1 + 32) = result;
mc = (__int64)v1;
}
else
{
*((_QWORD *)v1 + 32) = 0LL;
*((_QWORD *)v1 + 33) = 0LL;
mc = (__int64)v1;
mc_tail = v1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *src)
{
char *v1; // rbx
__int64 result; // rax

v1 = (char *)malloc(0x110uLL);
strcpy(v1, src);
result = mc;
if ( mc )
{
*(_QWORD *)(mc + 264) = v1;
*((_QWORD *)v1 + 32) = result;
mc = (__int64)v1;
}
else
{
*((_QWORD *)v1 + 32) = 0LL;
*((_QWORD *)v1 + 33) = 0LL;
mc = (__int64)v1;
mc_tail = v1;
}
return result;
}

original_code:
void add_machine_code( char *s ){
    struct code *tmp;
    tmp = (struct code*)malloc(sizeof(struct code));
    sprintf(tmp->cmd, "%s", s);
    if ( mc == ((void *)0) ){
        tmp->next = ((void *)0);
        tmp->prev = ((void *)0);
        mc = tmp;
        mc_tail = tmp;
    }else{
        mc->prev = tmp;
        tmp->next = mc;
        mc = tmp;
    }
}

canonical_original_code:
void add_machine_code(char *s){
    struct code *tmp;
    tmp = (struct code *)malloc(sizeof(struct code));
    sprintf(tmp->cmd, "%s", s);
    if ( mc == ((void *)0) ){
        tmp->next = ((void *)0);
        tmp->prev = ((void *)0);
        mc = tmp;
        mc_tail = tmp;
    }else{
        mc->prev = tmp;
        tmp->next = mc;
        mc = tmp;
    }
}

variable_types: struct code { char cmd[255]; struct code *next; struct code *prev; } *


gnlvcode

decompiled_code:
__int64 gnlvcode()
{
__int64 v0; // r14
int i; // ebx
char v3[296]; // [rsp+0h] [rbp-128h] BYREF

v0 = lookup();
strcpy(v3, "\tmovi R[255], M[R[0]+4]\n");
add_machine_code(v3);
for ( i = *(_DWORD *)(v0 + 12); ncur - 1 > i; ++i )
{
strcpy(v3, "\tmovi R[255], M[R[55]+4]\n");
add_machine_code(v3);
}
sprintf(v3, "\tmovi R[254], %d\n", *(unsigned int *)(v0 + 8));
add_machine_code(v3);
strcpy(v3, "\taddi R[255], R[254], R[255]\n");
return add_machine_code(v3);
}

original_code:
void gnlvcode(char *name) {
 char s_tmp[255];
 int i;
 SYMBOL *p = lookup(name);
 sprintf(s_tmp, "\tmovi R[255], M[R[0]+4]\n");
 add_machine_code( s_tmp );
 for(i=p->level; i<ncur-1; i++) {
  sprintf(s_tmp, "\tmovi R[255], M[R[55]+4]\n");
  add_machine_code( s_tmp );
 }
 sprintf(s_tmp, "\tmovi R[254], %d\n", p->offset);
 add_machine_code( s_tmp );
 sprintf(s_tmp, "\taddi R[255], R[254], R[255]\n");
 add_machine_code( s_tmp );
}

canonical_original_code:
void gnlvcode(char *name) {
 char s_tmp[255];
 int i;
 struct symbol *p = lookup(name);
 sprintf(s_tmp, "\tmovi R[255], M[R[0]+4]\n");
 add_machine_code( s_tmp );
 for(i=p->level; i<ncur-1; i++) {
  sprintf(s_tmp, "\tmovi R[255], M[R[55]+4]\n");
  add_machine_code( s_tmp );
 }
 sprintf(s_tmp, "\tmovi R[254], %d\n", p->offset);
 add_machine_code( s_tmp );
 sprintf(s_tmp, "\taddi R[255], R[254], R[255]\n");
 add_machine_code( s_tmp );
}

variable_types: i int


load

decompiled_code:
__int64 __fastcall load(const char *a1, const char *a2)
{
__int64 v2; // rbx
__int64 result; // rax
int v4; // edx
char v5[280]; // [rsp+0h] [rbp-118h] BYREF

if ( ((*_ctype_b_loc())[*a2] & 0x400) == 0 && *a2 != 36 )
{
sprintf(v5, "\tmovi %s, %s\n", a1, a2);
return add_machine_code(v5);
}
v2 = lookup(a2);
result = *(unsigned int *)(v2 + 12);
if ( (_DWORD)result == 1 )
{
if ( *(_DWORD *)(v2 + 92) != 3 )
{
sprintf(v5, "\tmovi %s, M[%d]\n", a1, (unsigned int)(*(_DWORD *)(v2 + 8) + 600));
return add_machine_code(v5);
}
v4 = ncur;
if ( ncur != 1 )
goto LABEL_5;
LABEL_14:
sprintf(v5, "\tmovi %s, M[R[0]+%d]\n", a1, *(unsigned int *)(v2 + 8));
return add_machine_code(v5);
}
v4 = ncur;
if ( (_DWORD)result == ncur )
{
if ( *(_DWORD *)(v2 + 92) == 4 && *(_DWORD *)(v2 + 56) == 1 )
{
sprintf(v5, "\tmovi R[255], M[R[0]+%d]\n", *(unsigned int *)(v2 + 8));
add_machine_code(v5);
sprintf(v5, "\tmovi %s, M[R[255]]\n", a1);
return add_machine_code(v5);
}
goto LABEL_14;
}
LABEL_5:
if ( (int)result < v4 )
{
gnlvcode(*(_QWORD *)v2);
if ( *(_DWORD *)(v2 + 92) == 4 && *(_DWORD *)(v2 + 56) == 1 )
{
strcpy(v5, "\tmovi R[255], M[R[255]]\n");
add_machine_code(v5);
sprintf(v5, "\tmovi %s, M[R[255]]\n", a1);
result = add_machine_code(v5);
}
else
{
sprintf(v5, "\tmovi %s, M[R[255]]\n", a1);
result = add_machine_code(v5);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1, const char *a2)
{
__int64 v2; // rbx
__int64 result; // rax
int v4; // edx
char v5[280]; // [rsp+0h] [rbp-118h] BYREF

if ( ((*_ctype_b_loc())[*a2] & 0x400) == 0 && *a2 != 36 )
{
sprintf(v5, "\tmovi %s, %s\n", a1, a2);
return func3(v5);
}
v2 = lookup(a2);
result = *(unsigned int *)(v2 + 12);
if ( (_DWORD)result == 1 )
{
if ( *(_DWORD *)(v2 + 92) != 3 )
{
sprintf(v5, "\tmovi %s, M[%d]\n", a1, (unsigned int)(*(_DWORD *)(v2 + 8) + 600));
return func3(v5);
}
v4 = ncur;
if ( ncur != 1 )
goto LABEL_5;
LABEL_14:
sprintf(v5, "\tmovi %s, M[R[0]+%d]\n", a1, *(unsigned int *)(v2 + 8));
return func3(v5);
}
v4 = ncur;
if ( (_DWORD)result == ncur )
{
if ( *(_DWORD *)(v2 + 92) == 4 && *(_DWORD *)(v2 + 56) == 1 )
{
sprintf(v5, "\tmovi R[255], M[R[0]+%d]\n", *(unsigned int *)(v2 + 8));
func3(v5);
sprintf(v5, "\tmovi %s, M[R[255]]\n", a1);
return func3(v5);
}
goto LABEL_14;
}
LABEL_5:
if ( (int)result < v4 )
{
func4(*(_QWORD *)v2);
if ( *(_DWORD *)(v2 + 92) == 4 && *(_DWORD *)(v2 + 56) == 1 )
{
strcpy(v5, "\tmovi R[255], M[R[255]]\n");
func3(v5);
sprintf(v5, "\tmovi %s, M[R[255]]\n", a1);
result = func3(v5);
}
else
{
sprintf(v5, "\tmovi %s, M[R[255]]\n", a1);
result = func3(v5);
}
}
return result;
}

original_code:
void load( char *R, char *a ){
 char s_tmp[255];
    if ( !((*__ctype_b_loc ())[(int) ((*a))] & (unsigned short int) _ISalpha) && *a != '$' ){
        sprintf(s_tmp, "\tmovi %s, %s\n", R, a);
        add_machine_code( s_tmp );
    }else{
        SYMBOL *p = lookup(a);
  if (p->level == 1 && p->type != TYPE_TMP) {
   sprintf(s_tmp, "\tmovi %s, M[%d]\n", R, 600+p->offset);
         add_machine_code( s_tmp );
  } else {
   if (p->level == ncur) {
    if (p->type == TYPE_ARG && p->arg.type == INOUT) {
     sprintf(s_tmp, "\tmovi R[255], M[R[0]+%d]\n", p->offset);
           add_machine_code( s_tmp );
     sprintf(s_tmp, "\tmovi %s, M[R[255]]\n", R);
           add_machine_code( s_tmp );
    } else {
     sprintf(s_tmp, "\tmovi %s, M[R[0]+%d]\n", R, p->offset);
           add_machine_code( s_tmp );
    }
    return;
   }else if (p->level < ncur) {
    gnlvcode(p->name);
    if (p->type == TYPE_ARG && p->arg.type == INOUT) {
     sprintf(s_tmp, "\tmovi R[255], M[R[255]]\n");
           add_machine_code( s_tmp );
     sprintf(s_tmp, "\tmovi %s, M[R[255]]\n", R);
           add_machine_code( s_tmp );
    } else {
     sprintf(s_tmp, "\tmovi %s, M[R[255]]\n", R);
           add_machine_code( s_tmp );
    }
    return;
   }
  }
    }
}

canonical_original_code:
void load(char *R, char *a){
 char s_tmp[255];
    if ( !((*__ctype_b_loc ())[(int) ((*a))] & (unsigned short) _ISalpha) && *a != '$' ){
        sprintf(s_tmp, "\tmovi %s, %s\n", R, a);
        add_machine_code( s_tmp );
    }else{
        struct symbol *p = lookup(a);
  if (p->level == 1 && p->type != TYPE_TMP) {
   sprintf(s_tmp, "\tmovi %s, M[%d]\n", R, 600+p->offset);
         add_machine_code( s_tmp );
  } else {
   if (p->level == ncur) {
    if (p->type == TYPE_ARG && p->arg.type == INOUT) {
     sprintf(s_tmp, "\tmovi R[255], M[R[0]+%d]\n", p->offset);
           add_machine_code( s_tmp );
     sprintf(s_tmp, "\tmovi %s, M[R[255]]\n", R);
           add_machine_code( s_tmp );
    } else {
     sprintf(s_tmp, "\tmovi %s, M[R[0]+%d]\n", R, p->offset);
           add_machine_code( s_tmp );
    }
    return;
   }else if (p->level < ncur) {
    gnlvcode(p->name);
    if (p->type == TYPE_ARG && p->arg.type == INOUT) {
     sprintf(s_tmp, "\tmovi R[255], M[R[255]]\n");
           add_machine_code( s_tmp );
     sprintf(s_tmp, "\tmovi %s, M[R[255]]\n", R);
           add_machine_code( s_tmp );
    } else {
     sprintf(s_tmp, "\tmovi %s, M[R[255]]\n", R);
           add_machine_code( s_tmp );
    }
    return;
   }
  }
    }
}

variable_types:
R
char *

variable_types:
a
char *


store

decompiled_code:
__int64 __fastcall store(const char *a1, __int64 a2)
{
__int64 v2; // rbx
__int64 result; // rax
int v4; // eax
char v5[280]; // [rsp+0h] [rbp-118h] BYREF

v2 = lookup(a2);
result = *(unsigned int *)(v2 + 12);
if ( (_DWORD)result != 1 )
{
if ( (_DWORD)result != ncur )
{
if ( (int)result >= ncur && *(_DWORD *)(v2 + 92) != 3 )
return result;
goto LABEL_8;
}
if ( *(_DWORD *)(v2 + 92) == 4 && *(_DWORD *)(v2 + 56) == 1 )
{
sprintf(v5, "\tmovi R[255], M[R[0]+%d]\n", *(unsigned int *)(v2 + 8));
add_machine_code(v5);
sprintf(v5, "\tmovi M[R[255]], %s\n", a1);
return add_machine_code(v5);
}
LABEL_15:
sprintf(v5, "\tmovi M[R[0]+%d], %s\n", *(unsigned int *)(v2 + 8), a1);
return add_machine_code(v5);
}
if ( *(_DWORD *)(v2 + 92) != 3 )
{
sprintf(v5, "\tmovi M[%d], %s\n", (unsigned int)(*(_DWORD *)(v2 + 8) + 600), a1);
return add_machine_code(v5);
}
if ( ncur == 1 )
goto LABEL_15;
LABEL_8:
gnlvcode(*(_QWORD *)v2);
v4 = *(_DWORD *)(v2 + 92);
if ( v4 == 3 || v4 == 4 && *(_DWORD *)(v2 + 56) == 1 )
{
strcpy(v5, "\tmovi R[255], M[R[255]]\n");
add_machine_code(v5);
sprintf(v5, "\tmovi M[R[255]], %s\n", a1);
result = add_machine_code(v5);
}
else
{
sprintf(v5, "\tmovi M[R[255]], %s\n", a1);
result = add_machine_code(v5);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1, __int64 a2)
{
__int64 v2; // rbx
__int64 result; // rax
int v4; // eax
char v5[280]; // [rsp+0h] [rbp-118h] BYREF

v2 = lookup(a2);
result = *(unsigned int *)(v2 + 12);
if ( (_DWORD)result != 1 )
{
if ( (_DWORD)result != ncur )
{
if ( (int)result >= ncur && *(_DWORD *)(v2 + 92) != 3 )
return result;
goto LABEL_8;
}
if ( *(_DWORD *)(v2 + 92) == 4 && *(_DWORD *)(v2 + 56) == 1 )
{
sprintf(v5, "\tmovi R[255], M[R[0]+%d]\n", *(unsigned int *)(v2 + 8));
func3(v5);
sprintf(v5, "\tmovi M[R[255]], %s\n", a1);
return func3(v5);
}
LABEL_15:
sprintf(v5, "\tmovi M[R[0]+%d], %s\n", *(unsigned int *)(v2 + 8), a1);
return func3(v5);
}
if ( *(_DWORD *)(v2 + 92) != 3 )
{
sprintf(v5, "\tmovi M[%d], %s\n", (unsigned int)(*(_DWORD *)(v2 + 8) + 600), a1);
return func3(v5);
}
if ( ncur == 1 )
goto LABEL_15;
LABEL_8:
func4(*(_QWORD *)v2);
v4 = *(_DWORD *)(v2 + 92);
if ( v4 == 3 || v4 == 4 && *(_DWORD *)(v2 + 56) == 1 )
{
strcpy(v5, "\tmovi R[255], M[R[255]]\n");
func3(v5);
sprintf(v5, "\tmovi M[R[255]], %s\n", a1);
result = func3(v5);
}
else
{
sprintf(v5, "\tmovi M[R[255]], %s\n", a1);
result = func3(v5);
}
return result;
}

original_code:
void store( char *R, char *a ){
 char s_tmp[255];
 SYMBOL *p = lookup(a);
 if (p->level == 1 && p->type != TYPE_TMP) {
  sprintf(s_tmp, "\tmovi M[%d], %s\n", 600+p->offset, R);
        add_machine_code( s_tmp );
 } else {
  if (p->level == ncur) {
   if (p->type == TYPE_ARG && p->arg.type == INOUT) {
    sprintf(s_tmp, "\tmovi R[255], M[R[0]+%d]\n", p->offset);
          add_machine_code( s_tmp );
    sprintf(s_tmp, "\tmovi M[R[255]], %s\n", R);
          add_machine_code( s_tmp );
   } else {
    sprintf(s_tmp, "\tmovi M[R[0]+%d], %s\n", p->offset, R);
          add_machine_code( s_tmp );
   }
   return;
  }else if (p->level < ncur || p->type == TYPE_TMP) {
   gnlvcode(p->name);
   if ( p->type == TYPE_TMP || (p->type == TYPE_ARG && p->arg.type == INOUT)) {
    sprintf(s_tmp, "\tmovi R[255], M[R[255]]\n");
          add_machine_code( s_tmp );
    sprintf(s_tmp, "\tmovi M[R[255]], %s\n", R);
          add_machine_code( s_tmp );
   } else {
    sprintf(s_tmp, "\tmovi M[R[255]], %s\n", R);
          add_machine_code( s_tmp );
   }
   return;
  }
 }
}

canonical_original_code:
void store(char *R, char *a){
 char s_tmp[255];
 struct symbol *p = lookup(a);
 if (p->level == 1 && p->type != TYPE_TMP) {
  sprintf(s_tmp, "\tmovi M[%d], %s\n", 600+p->offset, R);
        add_machine_code( s_tmp );
 } else {
  if (p->level == ncur) {
   if (p->type == TYPE_ARG && p->arg.type == INOUT) {
    sprintf(s_tmp, "\tmovi R[255], M[R[0]+%d]\n", p->offset);
          add_machine_code( s_tmp );
    sprintf(s_tmp, "\tmovi M[R[255]], %s\n", R);
          add_machine_code( s_tmp );
   } else {
    sprintf(s_tmp, "\tmovi M[R[0]+%d], %s\n", p->offset, R);
          add_machine_code( s_tmp );
   }
   return;
  }else if (p->level < ncur || p->type == TYPE_TMP) {
   gnlvcode(p->name);
   if ( p->type == TYPE_TMP || (p->type == TYPE_ARG && p->arg.type == INOUT)) {
    sprintf(s_tmp, "\tmovi R[255], M[R[255]]\n");
          add_machine_code( s_tmp );
    sprintf(s_tmp, "\tmovi M[R[255]], %s\n", R);
          add_machine_code( s_tmp );
   } else {
    sprintf(s_tmp, "\tmovi M[R[255]], %s\n", R);
          add_machine_code( s_tmp );
   }
   return;
  }
 }
}


decompiled_code:
void generate_final()
{
const char *v0; // r15
__int64 v1; // rax
char *v2; // rax
char *v3; // rax
__int64 v4; // rax
char *v5; // rax
char *v6; // rax
char *v7; // rax
char *v8; // rax
char *v9; // rax
char *v10; // rax
const char *v11; // r15
_DWORD *v12; // r14
int v13; // edx
__int64 v14; // r14
const char *v15; // r15
unsigned int v16; // er14
const char *v17; // [rsp+8h] [rbp-140h]
unsigned int v18; // [rsp+8h] [rbp-140h]
char s[312]; // [rsp+10h] [rbp-138h] BYREF

v0 = (const char *)gqp;
if ( gqp )
{
do
{
v2 = label(v0 + 140);
sprintf(s, "%s:\n", v2);
add_machine_code(s);
if ( !strcmp(v0, "begin_block") )
{
v1 = lookup(v0 + 35);
if ( !v1 )
_assert_fail("tmp != NULL", "cg.c", 0xBBu, "generate_final");
ncur = *(_DWORD *)(v1 + 12);
}
else if ( !strcmp(v0, "end_block") )
{
v4 = lookup(v0 + 35);
if ( !v4 )
_assert_fail("tmp != NULL", "cg.c", 0xC4u, "generate_final");
if ( *(_DWORD *)(v4 + 16) != 2 )
{
strcpy(s, "\tjmp M[R[0]]\n");
add_machine_code(s);
}
}
else if ( !strcmp(v0, "jump") )
{
v5 = label(v0 + 105);
sprintf(s, "\tjmp %s\n", v5);
add_machine_code(s);
}
else if ( !strcmp(v0, "print") )
{
load("R[1]", v0 + 35);
strcpy(s, "\touti R[1]\n");
add_machine_code(s);
}
else if ( !strcmp(v0, ":=") )
{
load("R[1]", v0 + 35);
store("R[1]", (__int64)(v0 + 105));
}
else if ( !strcmp(v0, "+") )
{
load("R[1]", v0 + 35);
load("R[2]", v0 + 70);
strcpy(s, "\taddi R[3], R[1], R[2]\n");
add_machine_code(s);
store("R[3]", (__int64)(v0 + 105));
}
else if ( !strcmp(v0, (const char *)asc_161C) )
{
load("R[1]", v0 + 35);
load("R[2]", v0 + 70);
strcpy(s, "\tsubi R[3], R[1], R[2]\n");
add_machine_code(s);
store("R[3]", (__int64)(v0 + 105));
}
else if ( !strcmp(v0, (const char *)&asc_161C[1]) )
{
load("R[1]", v0 + 35);
load("R[2]", v0 + 70);
strcpy(s, "\tmuli R[1], R[1], R[2]\n");
add_machine_code(s);
store("R[1]", (__int64)(v0 + 105));
}
else if ( !strcmp(v0, (const char *)&asc_161C[2]) )
{
load("R[1]", v0 + 35);
load("R[2]", v0 + 70);
strcpy(s, "\tdivi R[3], R[1], R[2]\n");
add_machine_code(s);
store("R[3]", (__int64)(v0 + 105));
}
else if ( !strcmp(v0, (const char *)&asc_161C[3])
|| !strcmp(v0, (const char *)&asc_161C[4])
|| !strcmp(v0, (const char *)&asc_161C[5])
|| !strcmp(v0, "<=")
|| !strcmp(v0, ">=")
|| !strcmp(v0, "<>") )
{
load("R[1]", v0 + 35);
load("R[2]", v0 + 70);
strcpy(s, "\tcmpi R[1],R[2]\n");
add_machine_code(s);
if ( !strcmp(v0, (const char *)&asc_161C[3]) )
{
v6 = label(v0 + 105);
sprintf(s, "\tje %s\n", v6);
add_machine_code(s);
}
if ( !strcmp(v0, (const char *)&asc_161C[4]) )
{
v7 = label(v0 + 105);
sprintf(s, "\tja %s\n", v7);
add_machine_code(s);
}
if ( !strcmp(v0, (const char *)&asc_161C[5]) )
{
v8 = label(v0 + 105);
sprintf(s, "\tjb %s\n", v8);
add_machine_code(s);
}
if ( !strcmp(v0, "<=") )
{
v9 = label(v0 + 105);
sprintf(s, "\tjae %s\n", v9);
add_machine_code(s);
}
if ( !strcmp(v0, ">=") )
{
v10 = label(v0 + 105);
sprintf(s, "\tjbe %s\n", v10);
add_machine_code(s);
}
if ( !strcmp(v0, "<>") )
{
v3 = label(v0 + 105);
sprintf(s, "\tjne %s\n", v3);
add_machine_code(s);
}
}
else if ( !strcmp(v0, "call") )
{
v12 = (_DWORD *)lookup(v0 + 105);
arguments -= v12[12];
v13 = v12[3];
if ( v13 == ncur )
{
strcpy(s, "\tmovi R[255], M[R[0]+4]\n");
add_machine_code(s);
sprintf(s, "\tmovi M[R[0]+%d], R[255]\n", (unsigned int)(*(_DWORD *)(cur_scope + 48LL) + 4));
add_machine_code(s);
}
else if ( v13 > ncur )
{
sprintf(s, "\tmovi M[R[0]+%d], R[0]\n", (unsigned int)(*(_DWORD *)(cur_scope + 48LL) + 4));
add_machine_code(s);
}
sprintf(s, "\tmovi R[255], %d\n", *(unsigned int *)(cur_scope + 48LL));
add_machine_code(s);
strcpy(s, "\taddi R[0], R[255], R[0]\n");
add_machine_code(s);
strcpy(s, "\tmovi R[255], $\n");
add_machine_code(s);
strcpy(s, "\tmovi R[254], 15\n");
add_machine_code(s);
strcpy(s, "\taddi R[255], R[255], R[254]\n");
add_machine_code(s);
strcpy(s, "\tmovi M[R[0]], R[255]\n");
add_machine_code(s);
sprintf(s, "\tjmp L%d\n", (unsigned int)v12[6]);
add_machine_code(s);
sprintf(s, "\tmovi R[255], %d\n", *(unsigned int *)(cur_scope + 48LL));
add_machine_code(s);
strcpy(s, "\tsubi R[0], R[0], R[255]\n");
add_machine_code(s);
}
else if ( !strcmp(v0, "par") )
{
v17 = v0 + 70;
v14 = lookup(v0 + 70);
v15 = v0 + 35;
if ( !strcmp(v15, "CV") )
{
v16 = *(_DWORD *)(cur_scope + 48LL) + 4 * arguments++ + 12;
load("R[255]", v17);
sprintf(s, "\tmovi M[R[0]+%d], R[255]\n", v16);
add_machine_code(s);
}
else if ( !strcmp(v15, "RET") )
{
strcpy(s, "\tmovi R[255], R[0]\n");
add_machine_code(s);
sprintf(s, "\tmovi R[254], %d\n", *(unsigned int *)(v14 + 8));
add_machine_code(s);
strcpy(s, "\taddi R[255], R[254], R[255]\n");
add_machine_code(s);
sprintf(s, "\tmovi M[R[0]+%d], R[255]\n", (unsigned int)(*(_DWORD *)(cur_scope + 48LL) + 8));
add_machine_code(s);
}
else
{
v18 = *(_DWORD *)(cur_scope + 48LL) + 4 * arguments++ + 12;
if ( *(_DWORD *)(v14 + 12) == ncur )
{
if ( *(_DWORD *)(v14 + 92) == 4 && *(_DWORD *)(v14 + 56) == 1 )
{
strcpy(s, "\tmovi R[255], R[0]\n");
add_machine_code(s);
sprintf(s, "\tmovi R[254], %d\n", *(unsigned int *)(v14 + 8));
add_machine_code(s);
strcpy(s, "\taddi R[255], R[254], R[255]\n");
add_machine_code(s);
strcpy(s, "\tmovi R[1], M[R[255]]\n");
add_machine_code(s);
sprintf(s, "\tmovi M[R[0]+%d], R[1]\n", v18);
add_machine_code(s);
}
else
{
strcpy(s, "\tmovi R[255], R[0]\n");
add_machine_code(s);
sprintf(s, "\tmovi R[254], %d\n", *(unsigned int *)(v14 + 8));
add_machine_code(s);
strcpy(s, "\taddi R[255], R[254], R[255]\n");
add_machine_code(s);
sprintf(s, "\tmovi M[R[0]+%d], R[255]\n", v18);
add_machine_code(s);
}
}
else
{
gnlvcode(*(_QWORD *)v14);
if ( *(_DWORD *)(v14 + 92) == 4 && *(_DWORD *)(v14 + 56) == 1 )
{
strcpy(s, "\tmovi R[1], M[R[255]]\n");
add_machine_code(s);
sprintf(s, "\tmovi M[R[0]+%d], R[1]\n", v18);
add_machine_code(s);
}
else
{
sprintf(s, "\tmovi M[R[0]+%d], R[255]\n", v18);
add_machine_code(s);
}
}
}
}
else
{
if ( !strcmp(v0, "halt") )
{
strcpy(s, "\thalt\n");
add_machine_code(s);
return;
}
if ( !strcmp(v0, "retv") )
{
v11 = v0 + 35;
if ( !strcmp(v11, "_") )
load("R[1]", "0");
else
load("R[1]", v11);
strcpy(s, "\tmovi R[255], M[R[0]+8]\n");
add_machine_code(s);
strcpy(s, "\tmovi M[R[255]], R[1]\n");
add_machine_code(s);
strcpy(s, "\tjmp M[R[0]]\n");
add_machine_code(s);
}
}
v0 = *(const char **)(gqp + 184LL);
gqp = v0;
}
while ( v0 );
}
}

original_code:
void generate_final() {
 char s_tmp[255];
 while(gqp != ((void *)0)){
  struct quad* q = gqp;
  sprintf(s_tmp, "%s:\n", label(q->label));
  add_machine_code( s_tmp );
  if (!strcmp(q->op,"begin_block")) {
   SYMBOL *tmp = lookup(q->x);
   ((void) sizeof ((tmp != ((void *)0)) ? 1 : 0), __extension__ ({ if (tmp != ((void *)0)) ; else __assert_fail ("tmp != NULL", "cg.c", 187, __extension__ __PRETTY_FUNCTION__); }));
   if (tmp->func.type == PROG) {
   }
   ncur = tmp->level;
  } else if (!strcmp(q->op,"end_block")) {
   SYMBOL *tmp = lookup(q->x);
   ((void) sizeof ((tmp != ((void *)0)) ? 1 : 0), __extension__ ({ if (tmp != ((void *)0)) ; else __assert_fail ("tmp != NULL", "cg.c", 196, __extension__ __PRETTY_FUNCTION__); }));
   if (tmp->func.type != PROG) {
    sprintf(s_tmp, "\tjmp M[R[0]]\n");
             add_machine_code( s_tmp );
   }
  } else if ( strcmp( q->op, "jump") == 0){
            sprintf(s_tmp, "\tjmp %s\n", label(q->z) );
            add_machine_code( s_tmp );
        } else if ( strcmp( q->op, "print") == 0){
   load("R[1]", q->x);
   sprintf(s_tmp, "\touti R[1]\n");
   add_machine_code( s_tmp );
        } else if ( strcmp( q->op, ":=") == 0){
            load("R[1]", q->x);
            store("R[1]", q->z);
        } else if ( strcmp( q->op, "+") == 0){
            load("R[1]", q->x);
            load("R[2]", q->y);
            sprintf(s_tmp, "\taddi R[3], R[1], R[2]\n" );
            add_machine_code( s_tmp );
            store("R[3]", q->z);
        } else if ( strcmp( q->op, "-") == 0){
            load("R[1]", q->x);
            load("R[2]", q->y);
            sprintf(s_tmp, "\tsubi R[3], R[1], R[2]\n" );
            add_machine_code( s_tmp );
            store("R[3]", q->z);
        } else if ( strcmp( q->op, "*") == 0){
            load("R[1]", q->x);
            load("R[2]", q->y);
            sprintf(s_tmp, "\tmuli R[1], R[1], R[2]\n" );
            add_machine_code( s_tmp );
            store("R[1]", q->z);
        } else if ( strcmp( q->op, "/") == 0){
            load("R[1]", q->x);
            load("R[2]", q->y);
            sprintf(s_tmp, "\tdivi R[3], R[1], R[2]\n" );
            add_machine_code( s_tmp );
            store("R[3]", q->z);
        } else if ( strcmp( q->op, "=") == 0 || strcmp( q->op, "<") == 0 || strcmp( q->op, ">") == 0 || strcmp( q->op, "<=") == 0 || strcmp( q->op, ">=") == 0 || strcmp( q->op, "<>") == 0 ){
            load("R[1]", q->x);
            load("R[2]", q->y);
            sprintf(s_tmp, "\tcmpi R[1],R[2]\n" );
            add_machine_code( s_tmp );
            if ( strcmp( q->op, "=") == 0 ){
                sprintf(s_tmp, "\tje %s\n", label(q->z) );
                add_machine_code( s_tmp );
            }
            if ( strcmp( q->op, "<") == 0 ){
                sprintf(s_tmp, "\tja %s\n", label(q->z) );
                add_machine_code( s_tmp );
            }
            if ( strcmp( q->op, ">") == 0 ){
                sprintf(s_tmp, "\tjb %s\n", label(q->z) );
                add_machine_code( s_tmp );
            }
            if ( strcmp( q->op, "<=") == 0 ){
                sprintf(s_tmp, "\tjae %s\n", label(q->z) );
                add_machine_code( s_tmp );
            }
            if ( strcmp( q->op, ">=") == 0 ){
                sprintf(s_tmp, "\tjbe %s\n", label(q->z) );
                add_machine_code( s_tmp );
            }
            if ( strcmp( q->op, "<>") == 0 ){
                sprintf(s_tmp, "\tjne %s\n", label(q->z) );
                add_machine_code( s_tmp );
            }
        } else if ( strcmp( q->op, "call") == 0){
   SYMBOL *p = lookup( q->z );
   arguments -= p->func.num_arg;
   if ( p->level == ncur ) {
    sprintf(s_tmp, "\tmovi R[255], M[R[0]+4]\n");
             add_machine_code( s_tmp );
    sprintf(s_tmp, "\tmovi M[R[0]+%d], R[255]\n", cur_scope->framelength+4);
             add_machine_code( s_tmp );
   } else if ( p->level > ncur ) {
    sprintf(s_tmp, "\tmovi M[R[0]+%d], R[0]\n", cur_scope->framelength+4);
             add_machine_code( s_tmp );
   }
            sprintf(s_tmp, "\tmovi R[255], %d\n", cur_scope->framelength );
            add_machine_code( s_tmp );
   sprintf(s_tmp, "\taddi R[0], R[255], R[0]\n");
            add_machine_code( s_tmp );
   sprintf(s_tmp, "\tmovi R[255], $\n");
            add_machine_code( s_tmp );
   sprintf(s_tmp, "\tmovi R[254], 15\n");
            add_machine_code( s_tmp );
   sprintf(s_tmp, "\taddi R[255], R[255], R[254]\n");
            add_machine_code( s_tmp );
   sprintf(s_tmp, "\tmovi M[R[0]], R[255]\n");
            add_machine_code( s_tmp );
   sprintf(s_tmp, "\tjmp L%d\n", p->func.genquad);
   add_machine_code( s_tmp );
   sprintf(s_tmp, "\tmovi R[255], %d\n", cur_scope->framelength );
            add_machine_code( s_tmp );
   sprintf(s_tmp, "\tsubi R[0], R[0], R[255]\n");
            add_machine_code( s_tmp );
        } else if ( strcmp( q->op, "par") == 0){
            SYMBOL *p = lookup( q->y );
            if ( !strcmp(q->x, "CV") ){
    int d = cur_scope->framelength + 12 + 4*arguments;
    arguments++;
                load("R[255]", q->y);
    sprintf(s_tmp, "\tmovi M[R[0]+%d], R[255]\n", d);
                add_machine_code( s_tmp );
            } else if ( !strcmp(q->x, "RET") ){
    sprintf(s_tmp, "\tmovi R[255], R[0]\n");
             add_machine_code( s_tmp );
    sprintf(s_tmp, "\tmovi R[254], %d\n", p->offset);
             add_machine_code( s_tmp );
    sprintf(s_tmp, "\taddi R[255], R[254], R[255]\n");
             add_machine_code( s_tmp );
    sprintf(s_tmp, "\tmovi M[R[0]+%d], R[255]\n", cur_scope->framelength+8);
             add_machine_code( s_tmp );
            } else {
    int d = cur_scope->framelength + 12 + 4*arguments;
    arguments++;
    if ( ncur == p->level ) {
     if (p->type == TYPE_ARG && p->arg.type == INOUT ) {
      sprintf(s_tmp, "\tmovi R[255], R[0]\n");
               add_machine_code( s_tmp );
      sprintf(s_tmp, "\tmovi R[254], %d\n", p->offset);
               add_machine_code( s_tmp );
      sprintf(s_tmp, "\taddi R[255], R[254], R[255]\n");
               add_machine_code( s_tmp );
      sprintf(s_tmp, "\tmovi R[1], M[R[255]]\n");
               add_machine_code( s_tmp );
      sprintf(s_tmp, "\tmovi M[R[0]+%d], R[1]\n", d);
               add_machine_code( s_tmp );
     } else {
      sprintf(s_tmp, "\tmovi R[255], R[0]\n");
               add_machine_code( s_tmp );
      sprintf(s_tmp, "\tmovi R[254], %d\n", p->offset);
               add_machine_code( s_tmp );
      sprintf(s_tmp, "\taddi R[255], R[254], R[255]\n");
      add_machine_code( s_tmp );
      sprintf(s_tmp, "\tmovi M[R[0]+%d], R[255]\n", d);
               add_machine_code( s_tmp );
     }
    } else {
     gnlvcode(p->name);
     if (p->type == TYPE_ARG && p->arg.type == INOUT) {
      sprintf(s_tmp, "\tmovi R[1], M[R[255]]\n");
               add_machine_code( s_tmp );
      sprintf(s_tmp, "\tmovi M[R[0]+%d], R[1]\n", d);
               add_machine_code( s_tmp );
     } else {
      sprintf(s_tmp, "\tmovi M[R[0]+%d], R[255]\n", d);
               add_machine_code( s_tmp );
     }
    }
   }
        }else if ( strcmp( q->op, "halt") == 0){
   sprintf(s_tmp, "\thalt\n");
      add_machine_code( s_tmp );
      return;
  }else if ( strcmp( q->op, "retv") == 0){
            if( strcmp(q->x,"_") != 0 ){
                load("R[1]", q->x);
            }else{
                load("R[1]", "0");
            }
            sprintf(s_tmp, "\tmovi R[255], M[R[0]+8]\n");
            add_machine_code( s_tmp );
            sprintf(s_tmp, "\tmovi M[R[255]], R[1]\n");
            add_machine_code( s_tmp );
   sprintf(s_tmp, "\tjmp M[R[0]]\n");
         add_machine_code( s_tmp );
        }
  gqp = gqp->prev;
 }
}

canonical_original_code:
void generate_final() {
 char s_tmp[255];
 while(gqp != ((void *)0)){
  struct quad *q = gqp;
  sprintf(s_tmp, "%s:\n", label(q->label));
  add_machine_code( s_tmp );
  if (!strcmp(q->op,"begin_block")) {
   struct symbol *tmp = lookup(q->x);
   ((void) sizeof ((tmp != ((void *)0)) ? 1 : 0), __extension__ ({ if (tmp != ((void *)0)) ; else __assert_fail ("tmp != NULL", "cg.c", 187, __extension__ __PRETTY_FUNCTION__); }));
   if (tmp->func.type == PROG) {
   }
   ncur = tmp->level;
  } else if (!strcmp(q->op,"end_block")) {
   struct symbol *tmp = lookup(q->x);
   ((void) sizeof ((tmp != ((void *)0)) ? 1 : 0), __extension__ ({ if (tmp != ((void *)0)) ; else __assert_fail ("tmp != NULL", "cg.c", 196, __extension__ __PRETTY_FUNCTION__); }));
   if (tmp->func.type != PROG) {
    sprintf(s_tmp, "\tjmp M[R[0]]\n");
             add_machine_code( s_tmp );
   }
  } else if ( strcmp( q->op, "jump") == 0){
            sprintf(s_tmp, "\tjmp %s\n", label(q->z) );
            add_machine_code( s_tmp );
        } else if ( strcmp( q->op, "print") == 0){
   load("R[1]", q->x);
   sprintf(s_tmp, "\touti R[1]\n");
   add_machine_code( s_tmp );
        } else if ( strcmp( q->op, ":=") == 0){
            load("R[1]", q->x);
            store("R[1]", q->z);
        } else if ( strcmp( q->op, "+") == 0){
            load("R[1]", q->x);
            load("R[2]", q->y);
            sprintf(s_tmp, "\taddi R[3], R[1], R[2]\n" );
            add_machine_code( s_tmp );
            store("R[3]", q->z);
        } else if ( strcmp( q->op, "-") == 0){
            load("R[1]", q->x);
            load("R[2]", q->y);
            sprintf(s_tmp, "\tsubi R[3], R[1], R[2]\n" );
            add_machine_code( s_tmp );
            store("R[3]", q->z);
        } else if ( strcmp( q->op, "*") == 0){
            load("R[1]", q->x);
            load("R[2]", q->y);
            sprintf(s_tmp, "\tmuli R[1], R[1], R[2]\n" );
            add_machine_code( s_tmp );
            store("R[1]", q->z);
        } else if ( strcmp( q->op, "/") == 0){
            load("R[1]", q->x);
            load("R[2]", q->y);
            sprintf(s_tmp, "\tdivi R[3], R[1], R[2]\n" );
            add_machine_code( s_tmp );
            store("R[3]", q->z);
        } else if ( strcmp( q->op, "=") == 0 || strcmp( q->op, "<") == 0 || strcmp( q->op, ">") == 0 || strcmp( q->op, "<=") == 0 || strcmp( q->op, ">=") == 0 || strcmp( q->op, "<>") == 0 ){
            load("R[1]", q->x);
            load("R[2]", q->y);
            sprintf(s_tmp, "\tcmpi R[1],R[2]\n" );
            add_machine_code( s_tmp );
            if ( strcmp( q->op, "=") == 0 ){
                sprintf(s_tmp, "\tje %s\n", label(q->z) );
                add_machine_code( s_tmp );
            }
            if ( strcmp( q->op, "<") == 0 ){
                sprintf(s_tmp, "\tja %s\n", label(q->z) );
                add_machine_code( s_tmp );
            }
            if ( strcmp( q->op, ">") == 0 ){
                sprintf(s_tmp, "\tjb %s\n", label(q->z) );
                add_machine_code( s_tmp );
            }
            if ( strcmp( q->op, "<=") == 0 ){
                sprintf(s_tmp, "\tjae %s\n", label(q->z) );
                add_machine_code( s_tmp );
            }
            if ( strcmp( q->op, ">=") == 0 ){
                sprintf(s_tmp, "\tjbe %s\n", label(q->z) );
                add_machine_code( s_tmp );
            }
            if ( strcmp( q->op, "<>") == 0 ){
                sprintf(s_tmp, "\tjne %s\n", label(q->z) );
                add_machine_code( s_tmp );
            }
        } else if ( strcmp( q->op, "call") == 0){
   struct symbol *p = lookup( q->z );
   arguments -= p->func.num_arg;
   if ( p->level == ncur ) {
    sprintf(s_tmp, "\tmovi R[255], M[R[0]+4]\n");
             add_machine_code( s_tmp );
    sprintf(s_tmp, "\tmovi M[R[0]+%d], R[255]\n", cur_scope->framelength+4);
             add_machine_code( s_tmp );
   } else if ( p->level > ncur ) {
    sprintf(s_tmp, "\tmovi M[R[0]+%d], R[0]\n", cur_scope->framelength+4);
             add_machine_code( s_tmp );
   }
            sprintf(s_tmp, "\tmovi R[255], %d\n", cur_scope->framelength );
            add_machine_code( s_tmp );
   sprintf(s_tmp, "\taddi R[0], R[255], R[0]\n");
            add_machine_code( s_tmp );
   sprintf(s_tmp, "\tmovi R[255], $\n");
            add_machine_code( s_tmp );
   sprintf(s_tmp, "\tmovi R[254], 15\n");
            add_machine_code( s_tmp );
   sprintf(s_tmp, "\taddi R[255], R[255], R[254]\n");
            add_machine_code( s_tmp );
   sprintf(s_tmp, "\tmovi M[R[0]], R[255]\n");
            add_machine_code( s_tmp );
   sprintf(s_tmp, "\tjmp L%d\n", p->func.genquad);
   add_machine_code( s_tmp );
   sprintf(s_tmp, "\tmovi R[255], %d\n", cur_scope->framelength );
            add_machine_code( s_tmp );
   sprintf(s_tmp, "\tsubi R[0], R[0], R[255]\n");
            add_machine_code( s_tmp );
        } else if ( strcmp( q->op, "par") == 0){
            struct symbol *p = lookup( q->y );
            if ( !strcmp(q->x, "CV") ){
    int d = cur_scope->framelength + 12 + 4*arguments;
    arguments++;
                load("R[255]", q->y);
    sprintf(s_tmp, "\tmovi M[R[0]+%d], R[255]\n", d);
                add_machine_code( s_tmp );
            } else if ( !strcmp(q->x, "RET") ){
    sprintf(s_tmp, "\tmovi R[255], R[0]\n");
             add_machine_code( s_tmp );
    sprintf(s_tmp, "\tmovi R[254], %d\n", p->offset);
             add_machine_code( s_tmp );
    sprintf(s_tmp, "\taddi R[255], R[254], R[255]\n");
             add_machine_code( s_tmp );
    sprintf(s_tmp, "\tmovi M[R[0]+%d], R[255]\n", cur_scope->framelength+8);
             add_machine_code( s_tmp );
            } else {
    int d = cur_scope->framelength + 12 + 4*arguments;
    arguments++;
    if ( ncur == p->level ) {
     if (p->type == TYPE_ARG && p->arg.type == INOUT ) {
      sprintf(s_tmp, "\tmovi R[255], R[0]\n");
               add_machine_code( s_tmp );
      sprintf(s_tmp, "\tmovi R[254], %d\n", p->offset);
               add_machine_code( s_tmp );
      sprintf(s_tmp, "\taddi R[255], R[254], R[255]\n");
               add_machine_code( s_tmp );
      sprintf(s_tmp, "\tmovi R[1], M[R[255]]\n");
               add_machine_code( s_tmp );
      sprintf(s_tmp, "\tmovi M[R[0]+%d], R[1]\n", d);
               add_machine_code( s_tmp );
     } else {
      sprintf(s_tmp, "\tmovi R[255], R[0]\n");
               add_machine_code( s_tmp );
      sprintf(s_tmp, "\tmovi R[254], %d\n", p->offset);
               add_machine_code( s_tmp );
      sprintf(s_tmp, "\taddi R[255], R[254], R[255]\n");
      add_machine_code( s_tmp );
      sprintf(s_tmp, "\tmovi M[R[0]+%d], R[255]\n", d);
               add_machine_code( s_tmp );
     }
    } else {
     gnlvcode(p->name);
     if (p->type == TYPE_ARG && p->arg.type == INOUT) {
      sprintf(s_tmp, "\tmovi R[1], M[R[255]]\n");
               add_machine_code( s_tmp );
      sprintf(s_tmp, "\tmovi M[R[0]+%d], R[1]\n", d);
               add_machine_code( s_tmp );
     } else {
      sprintf(s_tmp, "\tmovi M[R[0]+%d], R[255]\n", d);
               add_machine_code( s_tmp );
     }
    }
   }
        }else if ( strcmp( q->op, "halt") == 0){
   sprintf(s_tmp, "\thalt\n");
      add_machine_code( s_tmp );
      return;
  }else if ( strcmp( q->op, "retv") == 0){
            if( strcmp(q->x,"_") != 0 ){
                load("R[1]", q->x);
            }else{
                load("R[1]", "0");
            }
            sprintf(s_tmp, "\tmovi R[255], M[R[0]+8]\n");
            add_machine_code( s_tmp );
            sprintf(s_tmp, "\tmovi M[R[255]], R[1]\n");
            add_machine_code( s_tmp );
   sprintf(s_tmp, "\tjmp M[R[0]]\n");
         add_machine_code( s_tmp );
        }
  gqp = gqp->prev;
 }
}

user_defined_types: struct quad { char op[35]; char x[35]; char label[35]; struct quad *next; struct quad *prev; }


original_code:
char * int2string( int i ){
 char *s;
 int l;
 l = l<2?2:l;
    s = (char*)malloc(((int)ceil(log10(l))+1)*sizeof(char));
 memset(s, 0, 32);
 if(s == ((void *)0)) {
  { fprintf(stderr, "error: %s\r\n", "not enough memory"); exit(1); };
 }
 sprintf(s, "%d", i);
 return s;
}

canonical_original_code:
char *int2string(int i){
 char *s;
 int l;
 l = l<2?2:l;
    s = (char *)malloc(((int)ceil(log10(l))+1)*sizeof(char));
 memset(s, 0, 32);
 if(s == ((void *)0)) {
  { fprintf(stderr, "error: %s\r\n", "not enough memory"); exit(1); };
 }
 sprintf(s, "%d", i);
 return s;
}

variable_types: l int


nextquad

decompiled_code:
__int64 nextquad()
{
return (unsigned int)qlabel;
}

canonical_decompiled_code:
__int64 func1()
{
return (unsigned int)qlabel;
}

original_code:
int nextquad(){
 return qlabel;
}

canonical_original_code:
int nextquad(){
 return qlabel;
}


newquad

decompiled_code:
char *__fastcall newquad(char *src, char *a2, char *a3, char *a4)
{
char *v6; // rbx
__int64 v7; // rdx

v6 = (char *)malloc(0xC0uLL);
v7 = (unsigned int)qlabel++;
sprintf(v6 + 140, "%d", v7);
strcpy(v6, src);
strcpy(v6 + 35, a2);
strcpy(v6 + 70, a3);
strcpy(v6 + 105, a4);
return v6;
}

canonical_decompiled_code:
char *__fastcall func2(char *src, char *a2, char *a3, char *a4)
{
char *v6; // rbx
__int64 v7; // rdx

v6 = (char *)malloc(0xC0uLL);
v7 = (unsigned int)qlabel++;
sprintf(v6 + 140, "%d", v7);
strcpy(v6, src);
strcpy(v6 + 35, a2);
strcpy(v6 + 70, a3);
strcpy(v6 + 105, a4);
return v6;
}

original_code:
struct quad* newquad(char *op, char *x, char *y, char *z){
 struct quad* q;
 q = (struct quad*)malloc(sizeof(struct quad));
 sprintf(q->label,"%d",qlabel++);
 sprintf(q->op,"%s",op);
 sprintf(q->x,"%s",x);
 sprintf(q->y,"%s",y);
 sprintf(q->z,"%s",z);
 return q;
}

canonical_original_code:
struct quad *newquad(char *op, char *x, char *y, char *z){
 struct quad *q;
 q = (struct quad *)malloc(sizeof(struct quad));
 sprintf(q->label,"%d",qlabel++);
 sprintf(q->op,"%s",op);
 sprintf(q->x,"%s",x);
 sprintf(q->y,"%s",y);
 sprintf(q->z,"%s",z);
 return q;
}

variable_types:
op
char *

variable_types:
x
char *

variable_types:
y
char *

variable_types:
z
char *

variable_types: struct quad { char op[35]; char x[35]; char label[35]; struct quad *next; struct quad *prev; } *


genquad

decompiled_code:
char *__fastcall genquad(char *a1, char *a2, char *a3, char *a4)
{
char *v4; // rbx

v4 = newquad(a1, a2, a3, a4);
addtoquads((__int64)v4, &quads, &tail);
if ( !gqp )
gqp = quads;
return v4;
}

canonical_decompiled_code:
char *__fastcall func4(char *a1, char *a2, char *a3, char *a4)
{
char *v4; // rbx

v4 = func2(a1, a2, a3, a4);
func3((__int64)v4, &quads, &tail);
if ( !gqp )
gqp = quads;
return v4;
}

original_code:
struct quad* genquad(char *op, char *x, char *y, char *z){
 struct quad* q;
 q = newquad(op, x, y, z);
 addtoquads(q, &quads, &tail);
 if ( gqp == ((void *)0) ) {
  gqp = quads;
 }
 if( 0 ){
  printf("%s\t: %s %s %s %s\n", q->label, q->op, q->x, q->y, q->z);
 }
 return q;
}

canonical_original_code:
struct quad *genquad(char *op, char *x, char *y, char *z){
 struct quad *q;
 q = newquad(op, x, y, z);
 addtoquads(q, &quads, &tail);
 if ( gqp == ((void *)0) ) {
  gqp = quads;
 }
 if( 0 ){
  printf("%s\t: %s %s %s %s\n", q->label, q->op, q->x, q->y, q->z);
 }
 return q;
}

return_type: struct quad { char op[35]; char x[35]; char label[35]; struct quad *next; struct quad *prev; } *


fixquadlabels

decompiled_code:
void __fastcall fixquadlabels(unsigned int a1, unsigned int a2)
{
__int64 v2; // rbx
unsigned int v3; // er15
int v4; // er12
char *v5; // rax
char *v6; // rax
char *v7; // rax
char *v8; // rax

v2 = tail;
if ( tail )
{
v3 = a1;
v4 = 0;
do
{
v6 = int2string(a1);
if ( !strcmp((const char *)(v2 + 140), v6) )
{
v5 = int2string(a2);
v4 = strcmp((const char *)(v2 + 140), v5);
if ( v4 )
goto LABEL_9;
}
else
{
v7 = int2string(a2);
if ( !strcmp((const char *)(v2 + 140), v7) )
{
v4 = 0;
}
else if ( v4 )
{
LABEL_9:
v8 = int2string(v3);
strcpy((char *)(v2 + 140), v8);
++v3;
v4 = 1;
goto LABEL_5;
}
}
LABEL_5:
v2 = *(_QWORD *)(v2 + 184);
}
while ( v2 );
}
}

canonical_decompiled_code:
void __fastcall func6(unsigned int a1, unsigned int a2)
{
__int64 v2; // rbx
unsigned int v3; // er15
int v4; // er12
char *v5; // rax
char *v6; // rax
char *v7; // rax
char *v8; // rax

v2 = tail;
if ( tail )
{
v3 = a1;
v4 = 0;
do
{
v6 = func0(a1);
if ( !strcmp((const char *)(v2 + 140), v6) )
{
v5 = func0(a2);
v4 = strcmp((const char *)(v2 + 140), v5);
if ( v4 )
goto LABEL_9;
}
else
{
v7 = func0(a2);
if ( !strcmp((const char *)(v2 + 140), v7) )
{
v4 = 0;
}
else if ( v4 )
{
LABEL_9:
v8 = func0(v3);
strcpy((char *)(v2 + 140), v8);
++v3;
v4 = 1;
goto LABEL_5;
}
}
LABEL_5:
v2 = *(_QWORD *)(v2 + 184);
}
while ( v2 );
}
}

original_code:
void fixquadlabels(int from, int to){
 struct quad* q = tail;
 int i = from;
 int fix = 0;
 while(q != ((void *)0)){
  if (!strcmp(q->label, int2string(from))) {
   fix = 1;
  }
  if (!strcmp(q->label, int2string(to))) {
   fix = 0;
  }
  if (fix) {
   sprintf(q->label, "%s", int2string(i++));
  }
  q = q->prev;
 }
}

canonical_original_code:
void fixquadlabels(int from, int to){
 struct quad *q = tail;
 int i = from;
 int fix = 0;
 while(q != ((void *)0)){
  if (!strcmp(q->label, int2string(from))) {
   fix = 1;
  }
  if (!strcmp(q->label, int2string(to))) {
   fix = 0;
  }
  if (fix) {
   sprintf(q->label, "%s", int2string(i++));
  }
  q = q->prev;
 }
}

variable_types: from int

variable_types: to int

variable_types: fix int


newtemp

decompiled_code:
char *__fastcall newtemp(const char *a1)
{
__int64 v1; // rcx
char *v2; // rax
char v4[40]; // [rsp+0h] [rbp-28h] BYREF

v1 = (unsigned int)tempcounter++;
sprintf(v4, "%s_%d", a1, v1);
v2 = strdup(v4);
new_variable(v2, 1LL);
return strdup(v4);
}

canonical_decompiled_code:
char *__fastcall func7(const char *a1)
{
__int64 v1; // rcx
char *v2; // rax
char v4[40]; // [rsp+0h] [rbp-28h] BYREF

v1 = (unsigned int)tempcounter++;
sprintf(v4, "%s_%d", a1, v1);
v2 = strdup(v4);
new_variable(v2, 1LL);
return strdup(v4);
}

original_code:
char * newtemp(char *t){
 char s[30], *w;
 sprintf(s, "%s_%d", t, tempcounter++);
    w = strdup(s);
 new_variable(w, 1);
 return strdup(s);
}

canonical_original_code:
char *newtemp(char *t){
 char s[30]; char *w;
 sprintf(s, "%s_%d", t, tempcounter++);
    w = strdup(s);
 new_variable(w, 1);
 return strdup(s);
}

variable_types:
t
char *

variable_types:
s
char [30]

variable_types:
w
char *


makelist

decompiled_code:
char *__fastcall makelist(char *src)
{
char *v1; // rbx
char *result; // rax

v1 = (char *)malloc(0x38uLL);
result = strcpy(v1, src);
*((_QWORD *)v1 + 5) = 0LL;
*((_DWORD *)v1 + 12) = 0;
return result;
}

canonical_decompiled_code:
char *__fastcall func8(char *src)
{
char *v1; // rbx
char *result; // rax

v1 = (char *)malloc(0x38uLL);
result = strcpy(v1, src);
*((_QWORD *)v1 + 5) = 0LL;
*((_DWORD *)v1 + 12) = 0;
return result;
}

original_code:
struct list * makelist(char *x){
 struct list* tmp = (struct list*)malloc(sizeof(struct list));
 strcpy(tmp->name, x);
 tmp->next = ((void *)0);
 tmp->exitflag = 0;
 return tmp;
}

canonical_original_code:
struct list *makelist(char *x){
 struct list *tmp = (struct list*)malloc(sizeof(struct list));
 strcpy(tmp->name, x);
 tmp->next = ((void *)0);
 tmp->exitflag = 0;
 return tmp;
}

variable_types: struct list { char name[35]; struct list *next; int exitflag; } *


printlist

decompiled_code:
size_t __fastcall printlist(__int64 a1)
{
__int64 v1; // rbx

v1 = a1;
fwrite("[ ", 1uLL, 2uLL, stderr);
if ( a1 )
{
do
{
fprintf(stderr, "%s ", (const char *)v1);
v1 = *(_QWORD *)(v1 + 40);
}
while ( v1 );
}
return fwrite("]\n", 1uLL, 2uLL, stderr);
}

canonical_decompiled_code:
size_t __fastcall func9(__int64 a1)
{
__int64 v1; // rbx

v1 = a1;
fwrite("[ ", 1uLL, 2uLL, stderr);
if ( a1 )
{
do
{
fprintf(stderr, "%s ", (const char *)v1);
v1 = *(_QWORD *)(v1 + 40);
}
while ( v1 );
}
return fwrite("]\n", 1uLL, 2uLL, stderr);
}

original_code:
void printlist(struct list* l){
 fprintf(stderr, "[ ");
 while(l != ((void *)0)){
  fprintf(stderr, "%s ",l->name);
  l = l->next;
 }
 fprintf(stderr, "]\n");
}

canonical_original_code:
void printlist(struct list *l){
 fprintf(stderr, "[ ");
 while(l != ((void *)0)){
  fprintf(stderr, "%s ",l->name);
  l = l->next;
 }
 fprintf(stderr, "]\n");
}

user_defined_types: struct list { char name[35]; struct list *next; int exitflag; }


exitlist

decompiled_code:
__int64 __fastcall exitlist(__int64 a1)
{
if ( !a1 )
return 0LL;
while ( *(_DWORD *)(a1 + 48) != 1 )
{
a1 = *(_QWORD *)(a1 + 40);
if ( !a1 )
return 0LL;
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
if ( !a1 )
return 0LL;
while ( *(_DWORD *)(a1 + 48) != 1 )
{
a1 = *(_QWORD *)(a1 + 40);
if ( !a1 )
return 0LL;
}
return a1;
}

original_code:
struct list * exitlist(struct list *l) {
 while(l != ((void *)0)){
  if(l->exitflag == 1) {
   return l;
  }
  l = l->next;
 }
 return ((void *)0);
}

canonical_original_code:
struct list *exitlist(struct list *l) {
 while(l != ((void *)0)){
  if(l->exitflag == 1) {
   return l;
  }
  l = l->next;
 }
 return ((void *)0);
}

variable_types:
l
struct list *

return_type: struct list { char name[35]; struct list *next; int exitflag; } *


merge

original_code:
struct list * merge(struct list *a, struct list *b){
 struct list *t, *p;
 if(a == ((void *)0)){
  return b;
 }
 if(b == ((void *)0)){
  return a;
 }
 t = a;
    p = t;
 while(t->next != ((void *)0)){
  t = t->next;
 }
 t->next = b;
 return p;
}

canonical_original_code:
struct list *merge(struct list *a, struct list *b){
 struct list *t; struct list *p;
 if(a == ((void *)0)){
  return b;
 }
 if(b == ((void *)0)){
  return a;
 }
 t = a;
    p = t;
 while(t->next != ((void *)0)){
  t = t->next;
 }
 t->next = b;
 return p;
}

variable_types:
a
struct list *

variable_types:
b
struct list *


backpatch

decompiled_code:
void __fastcall backpatch(__int64 a1, const char *a2)
{
__int64 i; // rbp
__int64 j; // rbx

for ( i = a1; i; i = *(_QWORD *)(i + 40) )
{
for ( j = quads; j; j = *(_QWORD *)(j + 176) )
{
if ( !*(_DWORD *)(i + 48)
&& !strcmp((const char *)(j + 140), (const char *)i)
&& !strcmp((const char *)(j + 105), "_") )
{
strcpy((char *)(j + 105), a2);
}
}
}
}

canonical_decompiled_code:
void __fastcall func12(__int64 a1, const char *a2)
{
__int64 i; // rbp
__int64 j; // rbx

for ( i = a1; i; i = *(_QWORD *)(i + 40) )
{
for ( j = quads; j; j = *(_QWORD *)(j + 176) )
{
if ( !*(_DWORD *)(i + 48)
&& !strcmp((const char *)(j + 140), (const char *)i)
&& !strcmp((const char *)(j + 105), "_") )
{
strcpy((char *)(j + 105), a2);
}
}
}
}

original_code:
void backpatch(struct list* l, char* s){
 struct list* t;
 struct quad* q;
 t = l;
 while(t != ((void *)0)){
  q = quads;
  while(q != ((void *)0)){
   if(t->exitflag == 0 && !strcmp(q->label, t->name) && !strcmp(q->z,"_")){
    strcpy(q->z, s);
   }
   q = q->next;
  }
  t = t->next;
 }
}

canonical_original_code:
void backpatch(struct list *l, char *s){
 struct list *t;
 struct quad *q;
 t = l;
 while(t != ((void *)0)){
  q = quads;
  while(q != ((void *)0)){
   if(t->exitflag == 0 && !strcmp(q->label, t->name) && !strcmp(q->z,"_")){
    strcpy(q->z, s);
   }
   q = q->next;
  }
  t = t->next;
 }
}

variable_types:
s
char *


repo: ptitdoc/Archive-core-agent-linux

decompiled_code:
int fix_display()
{
return setenv("DISPLAY", ":0", 1);
}

canonical_decompiled_code:
int func19()
{
return setenv("DISPLAY", ":0", 1);
}

original_code:
static void fix_display()
{
 setenv("DISPLAY", ":0", 1);
}


decompiled_code:
__pid_t __fastcall produce_message(const char *a1, const char *a2, void *a3)
{
int *v3; // rax
char *v4; // rax
__pid_t result; // eax
char _0[1032]; // [rsp+0h] [rbp+0h] BYREF
char *ptr; // [rsp+408h] [rbp+408h] BYREF

vsnprintf(_0, 0x400uLL, a2, a3);
v3 = __errno_location();
v4 = strerror(*v3);
asprintf(&ptr, "%s: %s: %s (error type: %s)", program_invocation_short_name, a1, _0, v4);
fputs(ptr, stderr);
result = fork();
if ( result == -1 )
exit(1);
if ( !result )
{
fix_display();
execlp("zenity", "zenity", "--error", "--text", ptr, 0LL);
exit(1);
}
return result;
}

canonical_decompiled_code:
__pid_t __fastcall func20(const char *a1, const char *a2, void *a3)
{
int *v3; // rax
char *v4; // rax
__pid_t result; // eax
char _0[1032]; // [rsp+0h] [rbp+0h] BYREF
char *ptr; // [rsp+408h] [rbp+408h] BYREF

vsnprintf(_0, 0x400uLL, a2, a3);
v3 = __errno_location();
v4 = strerror(*v3);
asprintf(&ptr, "%s: %s: %s (error type: %s)", program_invocation_short_name, a1, _0, v4);
fputs(ptr, stderr);
result = fork();
if ( result == -1 )
exit(1);
if ( !result )
{
func19();
execlp("zenity", "zenity", "--error", "--text", ptr, 0LL);
exit(1);
}
return result;
}

original_code:
static void produce_message(char * type, const char *fmt, va_list args)
{
 char *dialog_msg;
 char buf[1024];
 (void) vsnprintf(buf, sizeof(buf), fmt, args);
 asprintf(&dialog_msg, "%s: %s: %s (error type: %s)",
   program_invocation_short_name, type, buf, strerror((*__errno_location ())));
 fprintf(stderr, "%s", dialog_msg);
 switch (fork()) {
 case -1:
  exit(1);
 case 0:
  fix_display();
  execlp("zenity", "zenity", "--error", "--text", dialog_msg, ((void *)0));
  exit(1);
 default:;
 }
}

canonical_original_code:
static void produce_message(char *type, char *fmt, __builtin_va_list args)
{
 char *dialog_msg;
 char buf[1024];
 (void) vsnprintf(buf, sizeof(buf), fmt, args);
 asprintf(&dialog_msg, "%s: %s: %s (error type: %s)",
   program_invocation_short_name, type, buf, strerror((*__errno_location ())));
 fprintf(stderr, "%s", dialog_msg);
 switch (fork()) {
 case -1:
  exit(1);
 case 0:
  fix_display();
  execlp("zenity", "zenity", "--error", "--text", dialog_msg, ((void *)0));
  exit(1);
 default:;
 }
}

variable_types:
type
char *

variable_types:
fmt
char *

variable_types:
buf
char [1024]


decompiled_code:
void __noreturn gui_fatal(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
produce_message("Fatal error", a1, va);
exit(1);
}

canonical_decompiled_code:
void __noreturn func21(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
func20("Fatal error", a1, va);
exit(1);
}

original_code:
void gui_fatal(const char *fmt, ...)
{
 va_list args;
 __builtin_va_start(args,fmt);
 produce_message("Fatal error", fmt, args);
 __builtin_va_end(args);
 exit(1);
}

canonical_original_code:
void gui_fatal(char *fmt, ...)
{
 __builtin_va_list args;
 __builtin_va_start(args,fmt);
 produce_message("Fatal error", fmt, args);
 __builtin_va_end(args);
 exit(1);
}


decompiled_code:
__pid_t gui_nonfatal(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
return produce_message("Information", a1, va);
}

canonical_decompiled_code:
__pid_t func22(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
return func20("Information", a1, va);
}

original_code:
void gui_nonfatal(const char *fmt, ...)
{
 va_list args;
 __builtin_va_start(args,fmt);
 produce_message("Information", fmt, args);
 __builtin_va_end(args);
}

canonical_original_code:
void gui_nonfatal(char *fmt, ...)
{
 __builtin_va_list args;
 __builtin_va_start(args,fmt);
 produce_message("Information", fmt, args);
 __builtin_va_end(args);
}