decompiled_code:
void __fastcall emit_mod(__int64 a1, unsigned int a2, int a3)
{
if ( (unsigned __int8)var_type(a1) == 2 || (unsigned __int8)var_type(a2) == 2 )
{
puts("[panic] can't use modulo operation for floats");
exit(1);
}
emit_divop("edx", a1, a2, a3);
}

canonical_decompiled_code:
void __fastcall func18(__int64 a1, unsigned int a2, int a3)
{
if ( (unsigned __int8)var_type(a1) == 2 || (unsigned __int8)var_type(a2) == 2 )
{
puts("[panic] can't use modulo operation for floats");
exit(1);
}
func5("edx", a1, a2, a3);
}

original_code:
void emit_mod(int left, int right, int result)
{
 if ((var_type(left) == 2) || (var_type(right) == 2)) {
  printf("[panic] can't use modulo operation for floats\n");
  exit(1);
 }
 emit_divop("edx", left, right, result);
}


repo: senko/calcc

decompiled_code:
void __fastcall emit_add(__int64 a1, unsigned int a2, int a3)
{
if ( (unsigned __int8)var_type(a1) == 2 || (unsigned __int8)var_type(a2) == 2 )
emit_3float("add", a1, a2, a3);
else
emit_3c("add", a1, a2, a3);
}

canonical_decompiled_code:
void __fastcall func19(__int64 a1, unsigned int a2, int a3)
{
if ( (unsigned __int8)var_type(a1) == 2 || (unsigned __int8)var_type(a2) == 2 )
func6("add", a1, a2, a3);
else
func4("add", a1, a2, a3);
}

original_code:
void emit_add(int left, int right, int result)
{
 if ((var_type(left) == 2) || (var_type(right) == 2)) {
  emit_3float("add", left, right, result);
  return;
 }
 emit_3c("add", left, right, result);
}

variable_types: left int

variable_types: right int

variable_types: result int

return_type: void


decompiled_code:
void __fastcall emit_sub(__int64 a1, unsigned int a2, int a3)
{
if ( (unsigned __int8)var_type(a1) == 2 || (unsigned __int8)var_type(a2) == 2 )
emit_3float("sub", a1, a2, a3);
else
emit_3c("sub", a1, a2, a3);
}

canonical_decompiled_code:
void __fastcall func20(__int64 a1, unsigned int a2, int a3)
{
if ( (unsigned __int8)var_type(a1) == 2 || (unsigned __int8)var_type(a2) == 2 )
func6("sub", a1, a2, a3);
else
func4("sub", a1, a2, a3);
}

original_code:
void emit_sub(int left, int right, int result)
{
 if ((var_type(left) == 2) || (var_type(right) == 2)) {
  emit_3float("sub", left, right, result);
  return;
 }
 emit_3c("sub", left, right, result);
}


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

result = fprintf(out, ".L%d:\n", a1);
eax_var = -1;
return result;
}

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

result = fprintf(out, ".L%d:\n", a1);
eax_var = -1;
return result;
}

original_code:
void emit_label(int index)
{
 fprintf(out, ".L%d:\n", index);
 eax_var = -1;
}

variable_types: index int


decompiled_code:
int __fastcall emit_test(int a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
char *v6; // r13
__int64 v7; // rdi
const char *v8; // rbx
char *v9; // r12
char v11; // al
const char *v12; // rdx
char v13; // al
const char *v14; // rdx

v6 = loc(a2);
v7 = (unsigned int)(a1 - 500);
v8 = "jmp";
v9 = loc(a3);
if ( (unsigned int)v7 <= 5 )
v8 = CSWTCH_81[v7];
if ( (unsigned __int8)var_type(a2) == 2 && (unsigned __int8)var_type(a3) == 1 )
{
v11 = var_type(a2);
v12 = (const char *)&unk_DC3;
if ( v11 == 1 )
v12 = "i";
fprintf(out, "\tf%sld long %s\n", v12, v6);
v13 = var_type(a3);
v14 = (const char *)&unk_DC3;
if ( v13 == 1 )
v14 = "i";
fprintf(out, "\tf%scom long %s\n", v14, v6);
}
else
{
if ( !in_eax(a2) )
fprintf(out, "\tmov eax, %s\n", v6);
fprintf(out, "\tcmp eax, %s\n", v9);
}
free(v6);
free(v9);
return fprintf(out, "\t%s .L%d\n", v8, a4);
}

canonical_decompiled_code:
int __fastcall func22(int a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
char *v6; // r13
__int64 v7; // rdi
const char *v8; // rbx
char *v9; // r12
char v11; // al
const char *v12; // rdx
char v13; // al
const char *v14; // rdx

v6 = func3(a2);
v7 = (unsigned int)(a1 - 500);
v8 = "jmp";
v9 = func3(a3);
if ( (unsigned int)v7 <= 5 )
v8 = CSWTCH_81[v7];
if ( (unsigned __int8)var_type(a2) == 2 && (unsigned __int8)var_type(a3) == 1 )
{
v11 = var_type(a2);
v12 = (const char *)&unk_DC3;
if ( v11 == 1 )
v12 = "i";
fprintf(out, "\tf%sld long %s\n", v12, v6);
v13 = var_type(a3);
v14 = (const char *)&unk_DC3;
if ( v13 == 1 )
v14 = "i";
fprintf(out, "\tf%scom long %s\n", v14, v6);
}
else
{
if ( !func0(a2) )
fprintf(out, "\tmov eax, %s\n", v6);
fprintf(out, "\tcmp eax, %s\n", v9);
}
free(v6);
free(v9);
return fprintf(out, "\t%s .L%d\n", v8, a4);
}

original_code:
void emit_test(int op, int left, int right, int label)
{
 char *a, *b; char *opcode = "jmp";
 a = loc(left); b = loc(right);
 switch (op) {
  case 501: opcode = "jz"; break;
  case 500: opcode = "jnz"; break;
  case 505: opcode = "jl"; break;
  case 503: opcode = "jg"; break;
  case 504: opcode = "jle"; break;
  case 502: opcode = "jge"; break;
 }
 if ((var_type(left) == 2) && (var_type(right) == 1)) {
  fprintf(out, "\tf%sld long %s\n",
   (var_type(left) == 1) ? "i" : "", a);
  fprintf(out, "\tf%scom long %s\n",
   (var_type(right) == 1) ? "i" : "", a);
 } else {
  if (!in_eax(left)) fprintf(out, "\tmov eax, %s\n", a);
  fprintf(out, "\tcmp eax, %s\n", b);
 }
 free(a); free(b);
 fprintf(out, "\t%s .L%d\n", opcode, label);
}

canonical_original_code:
void emit_test(int op, int left, int right, int label)
{
 char *a; char *b; char *opcode = "jmp";
 a = loc(left); b = loc(right);
 switch (op) {
  case 501: opcode = "jz"; break;
  case 500: opcode = "jnz"; break;
  case 505: opcode = "jl"; break;
  case 503: opcode = "jg"; break;
  case 504: opcode = "jle"; break;
  case 502: opcode = "jge"; break;
 }
 if ((var_type(left) == 2) && (var_type(right) == 1)) {
  fprintf(out, "\tf%sld long %s\n",
   (var_type(left) == 1) ? "i" : "", a);
  fprintf(out, "\tf%scom long %s\n",
   (var_type(right) == 1) ? "i" : "", a);
 } else {
  if (!in_eax(left)) fprintf(out, "\tmov eax, %s\n", a);
  fprintf(out, "\tcmp eax, %s\n", b);
 }
 free(a); free(b);
 fprintf(out, "\t%s .L%d\n", opcode, label);
}

variable_types: op int

variable_types: label int

variable_types:
a
char *

variable_types:
b
char *

variable_types:
opcode
char *


decompiled_code:
int __fastcall emit_jump(unsigned int a1)
{
return fprintf(out, "\tjmp .L%d\n", a1);
}

canonical_decompiled_code:
int __fastcall func23(unsigned int a1)
{
return fprintf(out, "\tjmp .L%d\n", a1);
}

original_code:
void emit_jump(int label)
{
 fprintf(out, "\tjmp .L%d\n", label);
}


decompiled_code:
int __fastcall emit_extern(const char *a1)
{
return fprintf(out, "extern %s\n", a1);
}

canonical_decompiled_code:
int __fastcall func24(const char *a1)
{
return fprintf(out, "extern %s\n", a1);
}

original_code:
void emit_extern(char *name)
{
 fprintf(out, "extern %s\n", name);
}

variable_types:
name
char *


decompiled_code:
size_t __fastcall emit_asciiz(unsigned int a1, _BYTE *a2)
{
__int64 v3; // rdx

fprintf(out, "LC%d: db ", a1);
while ( 1 )
{
v3 = (unsigned int)(char)*a2;
if ( !*a2 )
break;
++a2;
fprintf(out, "%d, ", v3);
}
return fwrite("0\n", 1uLL, 2uLL, out);
}

canonical_decompiled_code:
size_t __fastcall func25(unsigned int a1, _BYTE *a2)
{
__int64 v3; // rdx

fprintf(out, "LC%d: db ", a1);
while ( 1 )
{
v3 = (unsigned int)(char)*a2;
if ( !*a2 )
break;
++a2;
fprintf(out, "%d, ", v3);
}
return fwrite("0\n", 1uLL, 2uLL, out);
}

original_code:
void emit_asciiz(int index, char *string)
{
 fprintf(out, "LC%d: db ", index);
 while (*string) fprintf(out, "%d, ", *string++);
 fprintf(out, "0\n");
}

variable_types:
string
char *


decompiled_code:
int __fastcall emit_pushref(unsigned int a1)
{
return fprintf(out, "\tpush LC%d\n", a1);
}

canonical_decompiled_code:
int __fastcall func26(unsigned int a1)
{
return fprintf(out, "\tpush LC%d\n", a1);
}

original_code:
void emit_pushref(int index)
{
 fprintf(out, "\tpush LC%d\n", index);
}


decompiled_code:
int __fastcall emit_pushconst(unsigned int a1)
{
return fprintf(out, "\tpush long %d\n", a1);
}

canonical_decompiled_code:
int __fastcall func27(unsigned int a1)
{
return fprintf(out, "\tpush long %d\n", a1);
}

original_code:
void emit_pushconst(int val)
{
 fprintf(out, "\tpush long %d\n", val);
}

variable_types: val int


decompiled_code:
void __fastcall emit_cast_f2i(int a1, int a2)
{
char *v2; // r13
char *v3; // r12

v2 = loc(a2);
v3 = loc(a1);
fwrite("\t; float -> integer : load, round, store\n", 1uLL, 0x29uLL, out);
fprintf(out, "\tfld long %s\n", v2);
free(v2);
fwrite("\tfrndint\n", 1uLL, 9uLL, out);
fprintf(out, "\tfistp long %s\n", v3);
free(v3);
invalidate(a1);
}

canonical_decompiled_code:
void __fastcall func28(int a1, int a2)
{
char *v2; // r13
char *v3; // r12

v2 = func3(a2);
v3 = func3(a1);
fwrite("\t; float -> integer : load, round, store\n", 1uLL, 0x29uLL, out);
fprintf(out, "\tfld long %s\n", v2);
free(v2);
fwrite("\tfrndint\n", 1uLL, 9uLL, out);
fprintf(out, "\tfistp long %s\n", v3);
free(v3);
func1(a1);
}

original_code:
void emit_cast_f2i(int dest, int src)
{
 char *a; char *b; a = loc(src); b = loc(dest);
 fprintf(out, "\t; float -> integer : load, round, store\n");
 fprintf(out, "\tfld long %s\n", a); free(a);
 fprintf(out, "\tfrndint\n");
 fprintf(out, "\tfistp long %s\n", b); free(b);
 invalidate(dest);
}

variable_types: dest int

variable_types: src int


decompiled_code:
void __fastcall emit_cast_i2f(int a1, int a2)
{
char *v2; // r13
char *v3; // r12

v2 = loc(a2);
v3 = loc(a1);
fwrite("\t; integer -> float : load, store\n", 1uLL, 0x22uLL, out);
fprintf(out, "\tfild long %s\n", v2);
free(v2);
fprintf(out, "\tfstp long %s\n", v3);
free(v3);
invalidate(a1);
}

canonical_decompiled_code:
void __fastcall func29(int a1, int a2)
{
char *v2; // r13
char *v3; // r12

v2 = func3(a2);
v3 = func3(a1);
fwrite("\t; integer -> float : load, store\n", 1uLL, 0x22uLL, out);
fprintf(out, "\tfild long %s\n", v2);
free(v2);
fprintf(out, "\tfstp long %s\n", v3);
free(v3);
func1(a1);
}

original_code:
void emit_cast_i2f(int dest, int src)
{
 char *a; char *b; a = loc(src); b = loc(dest);
 fprintf(out, "\t; integer -> float : load, store\n");
 fprintf(out, "\tfild long %s\n", a); free(a);
 fprintf(out, "\tfstp long %s\n", b); free(b);
 invalidate(dest);
}


decompiled_code:
void __fastcall emit_assign(__int64 a1, unsigned int a2)
{
char *v2; // r14
char *v3; // r13

if ( (unsigned __int8)var_type(a1) == 2 && (unsigned __int8)var_type(a2) == 1 )
{
emit_cast_i2f(a1, a2);
}
else if ( (unsigned __int8)var_type(a2) == 2 && (unsigned __int8)var_type((unsigned int)a1) == 1 )
{
emit_cast_f2i(a1, a2);
}
else
{
v2 = loc(a2);
v3 = loc(a1);
if ( !in_eax(a2) )
fprintf(out, "\tmov eax, %s\n", v2);
free(v2);
fprintf(out, "\tmov %s, eax\n", v3);
free(v3);
set_eax(a1);
}
}

canonical_decompiled_code:
void __fastcall func30(__int64 a1, unsigned int a2)
{
char *v2; // r14
char *v3; // r13

if ( (unsigned __int8)var_type(a1) == 2 && (unsigned __int8)var_type(a2) == 1 )
{
func29(a1, a2);
}
else if ( (unsigned __int8)var_type(a2) == 2 && (unsigned __int8)var_type((unsigned int)a1) == 1 )
{
func28(a1, a2);
}
else
{
v2 = func3(a2);
v3 = func3(a1);
if ( !func0(a2) )
fprintf(out, "\tmov eax, %s\n", v2);
free(v2);
fprintf(out, "\tmov %s, eax\n", v3);
free(v3);
func2(a1);
}
}

original_code:
void emit_assign(int dest, int src)
{
 char *a, *b;
 if ((var_type(dest) == 2) && (var_type(src) == 1))
  { emit_cast_i2f(dest, src); return; }
 else if ((var_type(src) == 2) && (var_type(dest) == 1))
  { emit_cast_f2i(dest, src); return; }
 a = loc(src); b = loc(dest);
 if (!in_eax(src)) fprintf(out, "\tmov eax, %s\n", a); free(a);
 fprintf(out, "\tmov %s, eax\n", b); free(b);
 set_eax(dest);
}

canonical_original_code:
void emit_assign(int dest, int src)
{
 char *a; char *b;
 if ((var_type(dest) == 2) && (var_type(src) == 1))
  { emit_cast_i2f(dest, src); return; }
 else if ((var_type(src) == 2) && (var_type(dest) == 1))
  { emit_cast_f2i(dest, src); return; }
 a = loc(src); b = loc(dest);
 if (!in_eax(src)) fprintf(out, "\tmov eax, %s\n", a); free(a);
 fprintf(out, "\tmov %s, eax\n", b); free(b);
 set_eax(dest);
}


decompiled_code:
char *detect_identifier()
{
__int64 v0; // rbp
char v1; // al
char *result; // rax
char v3[1064]; // [rsp+0h] [rbp-428h] BYREF

v0 = 0LL;
while ( 1 )
{
v1 = input_peek();
v3[v0] = v1;
if ( v1 != 95 && ((*_ctype_b_loc())[v1] & 8) == 0 )
break;
input_consume();
if ( ++v0 == 1024 )
{
v3[1024] = 0;
return strdup(v3);
}
}
v3[(int)v0] = 0;
result = 0LL;
if ( !(_DWORD)v0 )
return result;
return strdup(v3);
}

canonical_decompiled_code:
char *func0()
{
__int64 v0; // rbp
char v1; // al
char *result; // rax
char v3[1064]; // [rsp+0h] [rbp-428h] BYREF

v0 = 0LL;
while ( 1 )
{
v1 = input_peek();
v3[v0] = v1;
if ( v1 != 95 && ((*_ctype_b_loc())[v1] & 8) == 0 )
break;
input_consume();
if ( ++v0 == 1024 )
{
v3[1024] = 0;
return strdup(v3);
}
}
v3[(int)v0] = 0;
result = 0LL;
if ( !(_DWORD)v0 )
return result;
return strdup(v3);
}

original_code:
static char *detect_identifier(void)
{
 char tmp[1024 +1];
 int i;
 for (i = 0; i < 1024; i++) {
  tmp[i] = input_peek();
  if ((tmp[i] != '_') && !((*__ctype_b_loc ())[(int) ((tmp[i]))] & (unsigned short int) _ISalnum)) break;
  input_consume();
 }
 tmp[i] = 0;
 if (!i) return ((void *)0);
 return strdup(tmp);
}

canonical_original_code:
static char *detect_identifier()
{
 char tmp[-1];
 int i;
 for (i = 0; i < 1024; i++) {
  tmp[i] = input_peek();
  if ((tmp[i] != '_') && !((*__ctype_b_loc ())[(int) ((tmp[i]))] & (unsigned short) _ISalnum)) break;
  input_consume();
 }
 tmp[i] = 0;
 if (!i) return ((void *)0);
 return strdup(tmp);
}

variable_types:
tmp
char [-1]

variable_types: i int

return_type: char *


decompiled_code:
char *__fastcall detect_string(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rdx
__int64 v4; // r12
char v5; // al
char v7[16424]; // [rsp+0h] [rbp-4028h] BYREF

v2 = 0LL;
input_consume();
while ( 1 )
{
v4 = (int)v2;
if ( !(unsigned __int8)((__int64 (*)(void))input_peek)() )
break;
v5 = ((__int64 (*)(void))input_peek)();
v3 = (unsigned int)v5;
if ( v5 == 34 )
break;
if ( (_DWORD)v3 == 92 )
{
input_consume();
v5 = ((__int64 (*)(void))input_peek)();
if ( v5 == 114 )
{
v5 = 13;
}
else if ( v5 > 114 )
{
if ( v5 == 116 )
v5 = 9;
}
else if ( v5 == 97 )
{
v5 = 7;
}
else if ( v5 == 110 )
{
v5 = 10;
}
}
v7[v2++] = v5;
input_consume();
if ( v2 == 0x4000 )
{
v4 = 0x4000LL;
break;
}
}
if ( (unsigned __int8)input_peek(a1, a2, v3) == 34 )
input_consume();
v7[v4] = 0;
return strdup(v7);
}

original_code:
static char *detect_string(void)
{
 char tmp[16384 + 1];
 int i;
 int c;
 input_consume();
 for (i = 0; (i < 16384) && input_peek(); i++) {
  c = input_peek(); if (c == '"') break;
  if (c == '\\') {
   input_consume(); c = input_peek();
   switch (c) {
    case 't': c = '\t'; break;
    case 'n': c = '\n'; break;
    case 'r': c = '\r'; break;
    case 'a': c = '\a'; break;
   }
  }
  tmp[i] = c;
  input_consume();
 }
 if (input_peek() == '"') input_consume();
 tmp[i] = 0;
 return strdup(tmp);
}

canonical_original_code:
static char *detect_string()
{
 char tmp[-1];
 int i;
 int c;
 input_consume();
 for (i = 0; (i < 16384) && input_peek(); i++) {
  c = input_peek(); if (c == '"') break;
  if (c == '\\') {
   input_consume(); c = input_peek();
   switch (c) {
    case 't': c = '\t'; break;
    case 'n': c = '\n'; break;
    case 'r': c = '\r'; break;
    case 'a': c = '\a'; break;
   }
  }
  tmp[i] = c;
  input_consume();
 }
 if (input_peek() == '"') input_consume();
 tmp[i] = 0;
 return strdup(tmp);
}

variable_types: c int


decompiled_code:
void lex_init()
{
lex_token_type = 0;
lex_token_string = 0LL;
lex_token_integer = 0LL;
}

canonical_decompiled_code:
void func5()
{
lex_token_type = 0;
lex_token_string = 0LL;
lex_token_integer = 0LL;
}

original_code:
void lex_init(void)
{
 lex_token_type = 0;
 lex_token_string = ((void *)0);
 lex_token_integer = 0;
}

canonical_original_code:
void lex_init()
{
 lex_token_type = 0;
 lex_token_string = ((void *)0);
 lex_token_integer = 0;
}


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

result = (unsigned int)lex_token_type;
if ( !lex_token_type )
{
detect_token_isra_0(a1, a2);
result = (unsigned int)lex_token_type;
}
return result;
}

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

result = (unsigned int)lex_token_type;
if ( !lex_token_type )
{
func4(a1, a2);
result = (unsigned int)lex_token_type;
}
return result;
}

original_code:
int lex_peek(void)
{
 if (lex_token_type == 0) detect_token();
 return lex_token_type;
}

canonical_original_code:
int lex_peek()
{
 if (lex_token_type == 0) detect_token();
 return lex_token_type;
}

return_type: int


decompiled_code:
int __fastcall lex_consume(const char *a1, __int64 a2)
{
unsigned int v2; // ebp
int result; // eax

v2 = lex_token_type;
if ( !lex_token_type )
{
lex_peek(a1, a2);
v2 = lex_token_type;
}
if ( lex_token_string )
free(lex_token_string);
result = printf("consuming(%d)\n", v2);
lex_token_type = 0;
lex_token_string = 0LL;
lex_token_integer = 0LL;
return result;
}

canonical_decompiled_code:
int __fastcall func7(const char *a1, __int64 a2)
{
unsigned int v2; // ebp
int result; // eax

v2 = lex_token_type;
if ( !lex_token_type )
{
func6(a1, a2);
v2 = lex_token_type;
}
if ( lex_token_string )
free(lex_token_string);
result = printf("consuming(%d)\n", v2);
lex_token_type = 0;
lex_token_string = 0LL;
lex_token_integer = 0LL;
return result;
}

original_code:
void lex_consume(void)
{
 if (lex_token_type == 0) lex_peek();
 if (lex_token_string) free(lex_token_string);
 printf("consuming(%d)\n", lex_token_type);
 lex_token_type = 0;
 lex_token_string = ((void *)0);
 lex_token_integer = 0;
}

canonical_original_code:
void lex_consume()
{
 if (lex_token_type == 0) lex_peek();
 if (lex_token_string) free(lex_token_string);
 printf("consuming(%d)\n", lex_token_type);
 lex_token_type = 0;
 lex_token_string = ((void *)0);
 lex_token_integer = 0;
}


decompiled_code:
void *lex_get_string()
{
return lex_token_string;
}

canonical_decompiled_code:
void *func8()
{
return lex_token_string;
}

original_code:
char *lex_get_string(void)
{
 return lex_token_string;
}

canonical_original_code:
char *lex_get_string()
{
 return lex_token_string;
}


decompiled_code:
__int64 lex_get_integer()
{
return lex_token_integer;
}

canonical_decompiled_code:
__int64 func9()
{
return lex_token_integer;
}

original_code:
long lex_get_integer(void)
{
 return lex_token_integer;
}

canonical_original_code:
long lex_get_integer()
{
 return lex_token_integer;
}

return_type: long


main

canonical_name: main

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

if ( argc == 3 )
{
v5 = read_file(argv[1]);
if ( v5 )
{
input_init(v5);
func_init();
string_init();
lex_init();
if ( !(unsigned int)emit_init(argv[2]) )
{
v3 = parse_program();
if ( !v3 )
{
string_output();
puts("compile succeeded");
emit_finish();
return v3;
}
emit_finish();
unlink(argv[2]);
}
}
v3 = 1;
}
else
{
v3 = 1;
printf("Usage: %s <input> <output>\n", *argv);
}
return v3;
}

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

if ( argc == 3 )
{
v5 = func0(argv[1]);
if ( v5 )
{
input_init(v5);
func_init();
string_init();
lex_init();
if ( !(unsigned int)emit_init(argv[2]) )
{
v3 = parse_program();
if ( !v3 )
{
string_output();
puts("compile succeeded");
emit_finish();
return v3;
}
emit_finish();
unlink(argv[2]);
}
}
v3 = 1;
}
else
{
v3 = 1;
printf("Usage: %s <input> <output>\n", *argv);
}
return v3;
}

original_code:
int main(int argc, char *argv[])
{
 char *tmp;
 if (argc != 3) {
  printf("Usage: %s <input> <output>\n", argv[0]);
  return 1;
 }
 tmp = read_file(argv[1]); if (!tmp) return 1;
 input_init(tmp); func_init(); string_init(); lex_init();
 if (emit_init(argv[2])) return 1;
 if (parse_program()) {
  emit_finish();
  unlink(argv[2]);
  return 1;
 }
 string_output();
 printf("compile succeeded\n");
 emit_finish();
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
tmp
char *


decompiled_code:
void *string_init()
{
void *result; // rax

result = calloc(0x2000uLL, 1uLL);
strings = result;
return result;
}

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

result = calloc(0x2000uLL, 1uLL);
strings = result;
return result;
}

original_code:
void string_init(void)
{
 strings = malloc(1024 * sizeof(char *));
 memset(strings, 0, 1024 * sizeof(char *));
}

canonical_original_code:
void string_init()
{
 strings = malloc(1024 * sizeof(char *));
 memset(strings, 0, 1024 * sizeof(char *));
}


decompiled_code:
void string_fini()
{
free(strings);
strings = 0LL;
}

canonical_decompiled_code:
void func1()
{
free(strings);
strings = 0LL;
}

original_code:
void string_fini(void)
{
 free(strings); strings = ((void *)0);
}

canonical_original_code:
void string_fini()
{
 free(strings); strings = ((void *)0);
}


decompiled_code:
__int64 __fastcall string_decl(__int64 a1)
{
_QWORD *v1; // rax
unsigned int i; // er8

v1 = strings;
for ( i = 0; i != 1024; ++i )
{
if ( !*v1 )
{
*v1 = a1;
return i;
}
++v1;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
_QWORD *v1; // rax
unsigned int i; // er8

v1 = strings;
for ( i = 0; i != 1024; ++i )
{
if ( !*v1 )
{
*v1 = a1;
return i;
}
++v1;
}
return 0xFFFFFFFFLL;
}

original_code:
int string_decl(char *str)
{
 int i;
 for (i = 0; i < 1024; i++) if (!strings[i]) break;
 if (i == 1024) return -1;
 strings[i] = str;
 return i;
}

variable_types:
str
char *


decompiled_code:
void *string_output()
{
__int64 i; // rbx
void *result; // rax

for ( i = 0LL; i != 1024; ++i )
{
result = strings;
if ( *((_QWORD *)strings + i) )
result = (void *)emit_asciiz((unsigned int)i);
}
return result;
}

canonical_decompiled_code:
void *func3()
{
__int64 i; // rbx
void *result; // rax

for ( i = 0LL; i != 1024; ++i )
{
result = strings;
if ( *((_QWORD *)strings + i) )
result = (void *)emit_asciiz((unsigned int)i);
}
return result;
}

original_code:
void string_output(void)
{
 int i;
 for (i = 0; i < 1024; i++)
  if (strings[i]) emit_asciiz(i, strings[i]);
}

canonical_original_code:
void string_output()
{
 int i;
 for (i = 0; i < 1024; i++)
  if (strings[i]) emit_asciiz(i, strings[i]);
}


decompiled_code:
void *var_init()
{
void *result; // rax

result = calloc(0x8000uLL, 1uLL);
variables = result;
return result;
}

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

result = calloc(0x8000uLL, 1uLL);
variables = result;
return result;
}

original_code:
void var_init(void)
{
 variables = malloc(1024 * sizeof(var_t));
 memset(variables, 0, 1024 * sizeof(var_t));
}

canonical_original_code:
void var_init()
{
 variables = malloc(1024 * sizeof(var_t));
 memset(variables, 0, 1024 * sizeof(var_t));
}


decompiled_code:
void var_fini()
{
free(variables);
variables = 0LL;
}

canonical_decompiled_code:
void func1()
{
free(variables);
variables = 0LL;
}

original_code:
void var_fini(void)
{
 free(variables); variables = ((void *)0);
}

canonical_original_code:
void var_fini()
{
 free(variables); variables = ((void *)0);
}


decompiled_code:
__int64 __fastcall var_type(int a1)
{
return *((unsigned __int8 *)variables + 32 * a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
return *((unsigned __int8 *)variables + 32 * a1 + 24);
}

original_code:
char var_type(int idx)
{
 return variables[idx].type;
}

variable_types: idx int

return_type: char


decompiled_code:
void __fastcall var_set_type(int a1, char a2)
{
*((_BYTE *)variables + 32 * a1 + 24) = a2;
}

canonical_decompiled_code:
void __fastcall func4(int a1, char a2)
{
*((_BYTE *)variables + 32 * a1 + 24) = a2;
}

original_code:
void var_set_type(int idx, char type)
{
 variables[idx].type = type;
}

variable_types: type char


decompiled_code:
__int64 var_tcount()
{
_QWORD *v0; // rax
unsigned int v1; // er8

v0 = variables;
v1 = 0;
do
{
if ( !v0[1] )
v1 -= (*(_BYTE *)v0 == 0) - 1;
v0 += 4;
}
while ( v0 != (_QWORD *)((char *)variables + 0x8000) );
return v1;
}

canonical_decompiled_code:
__int64 func5()
{
_QWORD *v0; // rax
unsigned int v1; // er8

v0 = variables;
v1 = 0;
do
{
if ( !v0[1] )
v1 -= (*(_BYTE *)v0 == 0) - 1;
v0 += 4;
}
while ( v0 != (_QWORD *)((char *)variables + 0x8000) );
return v1;
}

original_code:
int var_tcount(void)
{
 int i, cnt;
 for (i = 0, cnt = 0; i < 1024; i++) {
  if (variables[i].name) continue;
  if (variables[i].used) cnt++;
 }
 return cnt;
}

canonical_original_code:
int var_tcount()
{
 int i; int cnt;
 for (i = 0, cnt = 0; i < 1024; i++) {
  if (variables[i].name) continue;
  if (variables[i].used) cnt++;
 }
 return cnt;
}

variable_types: cnt int


decompiled_code:
__int64 __fastcall var_get(char *s2)
{
unsigned int v1; // er12
unsigned int v2; // eax
const char **v3; // rbx

v1 = 0;
v2 = var_tcount("searching for '%s', total count %d\n", s2);
printf("searching for '%s', total count %d\n", s2, v2);
v3 = (const char **)((char *)variables + 8);
do
{
if ( *v3 && !strcmp(*v3, s2) )
{
printf("variable '%s' is in slot %d\n", s2, v1);
return v1;
}
++v1;
v3 += 4;
}
while ( v1 != 1024 );
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *s2)
{
unsigned int v1; // er12
unsigned int v2; // eax
const char **v3; // rbx

v1 = 0;
v2 = func5("searching for '%s', total count %d\n", s2);
printf("searching for '%s', total count %d\n", s2, v2);
v3 = (const char **)((char *)variables + 8);
do
{
if ( *v3 && !strcmp(*v3, s2) )
{
printf("variable '%s' is in slot %d\n", s2, v1);
return v1;
}
++v1;
v3 += 4;
}
while ( v1 != 1024 );
return 0xFFFFFFFFLL;
}

original_code:
int var_get(char *name)
{
 int i;
 printf("searching for '%s', total count %d\n",
  name, var_tcount());
 for (i = 0; i < 1024; i++) {
  if (!variables[i].name) continue;
  if (!strcmp(variables[i].name, name)) {
   printf("variable '%s' is in slot %d\n", name, i);
   return i;
  }
 }
 return -1;
}


decompiled_code:
__int64 __fastcall var_alloc(char *a1, char a2)
{
__int64 v2; // rbx
unsigned int v3; // er12
char *v4; // rbx

if ( a1 && (unsigned int)var_get(a1) != -1 )
{
v3 = -1;
printf("redeclaring variable '%s'\n", a1);
}
else
{
v2 = 0LL;
v3 = 0;
while ( *((_BYTE *)variables + v2) )
{
++v3;
v2 += 32LL;
if ( v3 == 1024 )
return 0xFFFFFFFFLL;
}
if ( a1 )
printf("declared variable '%s' (slot %d)\n", a1, v3);
else
printf("putting temporary in slot %d\n", v3);
v4 = (char *)variables + v2;
*((_QWORD *)v4 + 1) = a1;
v4[24] = a2;
*v4 = 1;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *a1, char a2)
{
__int64 v2; // rbx
unsigned int v3; // er12
char *v4; // rbx

if ( a1 && (unsigned int)func6(a1) != -1 )
{
v3 = -1;
printf("redeclaring variable '%s'\n", a1);
}
else
{
v2 = 0LL;
v3 = 0;
while ( *((_BYTE *)variables + v2) )
{
++v3;
v2 += 32LL;
if ( v3 == 1024 )
return 0xFFFFFFFFLL;
}
if ( a1 )
printf("declared variable '%s' (slot %d)\n", a1, v3);
else
printf("putting temporary in slot %d\n", v3);
v4 = (char *)variables + v2;
*((_QWORD *)v4 + 1) = a1;
v4[24] = a2;
*v4 = 1;
}
return v3;
}

original_code:
int var_alloc(char *name, char type)
{
 int i;
 if (name) {
  if (var_get(name) != -1) {
   printf("redeclaring variable '%s'\n", name);
   return -1;
  }
 }
 for (i = 0; i < 1024; i++) if (!variables[i].used) break;
 if (i == 1024) return -1;
 if (name)
  printf("declared variable '%s' (slot %d)\n", name, i);
 else
  printf("putting temporary in slot %d\n", i);
 variables[i].name = name;
 variables[i].type = type;
 variables[i].used = 1;
 return i;
}


decompiled_code:
void __fastcall input_init(void *a1)
{
input = a1;
ptr = (__int64)a1;
}

canonical_decompiled_code:
void __fastcall func0(void *a1)
{
input = a1;
ptr = (__int64)a1;
}

original_code:
void input_init(char *txt)
{
 input = txt;
 ptr = input;
}

variable_types:
txt
char *


decompiled_code:
void input_finish()
{
free(input);
}

canonical_decompiled_code:
void func1()
{
free(input);
}

original_code:
void input_finish()
{
 free(input);
}

canonical_original_code:
void input_finish()
{
 free(input);
}


decompiled_code:
__int64 input_peek()
{
return *(unsigned __int8 *)ptr;
}

canonical_decompiled_code:
__int64 func2()
{
return *(unsigned __int8 *)ptr;
}

original_code:
char input_peek(void)
{
 return *ptr;
}

canonical_original_code:
char input_peek()
{
 return *ptr;
}


decompiled_code:
__int64 input_consume()
{
__int64 result; // rax

result = ptr;
if ( *(_BYTE *)ptr )
result = ++ptr;
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 result; // rax

result = ptr;
if ( *(_BYTE *)ptr )
result = ++ptr;
return result;
}

original_code:
void input_consume(void)
{
 if (*ptr) ptr++;
}

canonical_original_code:
void input_consume()
{
 if (*ptr) ptr++;
}


decompiled_code:
void *func_init()
{
void *result; // rax

result = calloc(0x4000uLL, 1uLL);
functions = result;
return result;
}

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

result = calloc(0x4000uLL, 1uLL);
functions = result;
return result;
}

original_code:
void func_init(void)
{
 functions = malloc(1024 * sizeof(func_t));
 memset(functions, 0, 1024 * sizeof(func_t));
}

canonical_original_code:
void func_init()
{
 functions = malloc(1024 * sizeof(func_t));
 memset(functions, 0, 1024 * sizeof(func_t));
}


decompiled_code:
void func_fini()
{
free(functions);
functions = 0LL;
}

canonical_decompiled_code:
void func1()
{
free(functions);
functions = 0LL;
}

original_code:
void func_fini(void)
{
 free(functions); functions = ((void *)0);
}

canonical_original_code:
void func_fini()
{
 free(functions); functions = ((void *)0);
}


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

v1 = (const char **)functions;
v2 = (const char **)((char *)functions + 0x4000);
while ( 1 )
{
if ( !*v1 )
return 0xFFFFFFFFLL;
if ( !strcmp(*v1, s2) )
break;
v1 += 2;
if ( v1 == v2 )
return 0xFFFFFFFFLL;
}
return *((unsigned int *)v1 + 2);
}

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

v1 = (const char **)functions;
v2 = (const char **)((char *)functions + 0x4000);
while ( 1 )
{
if ( !*v1 )
return 0xFFFFFFFFLL;
if ( !strcmp(*v1, s2) )
break;
v1 += 2;
if ( v1 == v2 )
return 0xFFFFFFFFLL;
}
return *((unsigned int *)v1 + 2);
}

original_code:
int func_get(char *name)
{
 int i;
 for (i = 0; i < 1024; i++) {
  if (!functions[i].name) break;
  if (!strcmp(functions[i].name, name))
   return functions[i].argc;
 }
 return -1;
}


decompiled_code:
__int64 __fastcall func_decl(char *a1, unsigned int a2, char a3)
{
unsigned int v5; // eax
__int64 v6; // r8
char **v8; // rax
const char *v9; // rsi

v5 = func_get(a1);
v6 = v5;
if ( v5 == -1 )
{
v8 = (char **)functions;
while ( *v8 )
{
v8 += 2;
if ( (char *)functions + 0x4000 == (char *)v8 )
return (unsigned int)v6;
}
*v8 = a1;
v9 = "float";
*((_DWORD *)v8 + 2) = a2;
*((_BYTE *)v8 + 12) = a3;
if ( a3 != 2 )
v9 = "int";
printf("declared %s function '%s' with %d arguments\n", v9, a1, a2, v6);
}
else if ( v5 != a2 )
{
printf("redeclaring function '%s'\n", a1);
LODWORD(v6) = -1;
return (unsigned int)v6;
}
LODWORD(v6) = 0;
return (unsigned int)v6;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1, unsigned int a2, char a3)
{
unsigned int v5; // eax
__int64 v6; // r8
char **v8; // rax
const char *v9; // rsi

v5 = func2(a1);
v6 = v5;
if ( v5 == -1 )
{
v8 = (char **)functions;
while ( *v8 )
{
v8 += 2;
if ( (char *)functions + 0x4000 == (char *)v8 )
return (unsigned int)v6;
}
*v8 = a1;
v9 = "float";
*((_DWORD *)v8 + 2) = a2;
*((_BYTE *)v8 + 12) = a3;
if ( a3 != 2 )
v9 = "int";
printf("declared %s function '%s' with %d arguments\n", v9, a1, a2, v6);
}
else if ( v5 != a2 )
{
printf("redeclaring function '%s'\n", a1);
LODWORD(v6) = -1;
return (unsigned int)v6;
}
LODWORD(v6) = 0;
return (unsigned int)v6;
}

original_code:
int func_decl(char *name, int argc, char type)
{
 int i;
 i = func_get(name);
 if (i != -1) {
  if (i == argc) return 0;
  printf("redeclaring function '%s'\n", name);
  return -1;
 }
 for (i = 0; i < 1024; i++)
  if (!(functions[i].name)) break;
 if (i == 1024) return -1;
 functions[i].name = name;
 functions[i].argc = argc;
 functions[i].type = type;
 printf("declared %s function '%s' with %d arguments\n",
  (functions[i].type == 2) ? "float" : "int", name, argc);
 return 0;
}


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

v1 = (const char **)functions;
v2 = (const char **)((char *)functions + 0x4000);
while ( 1 )
{
if ( !*v1 )
return 0xFFFFFFFFLL;
if ( !strcmp(*v1, s2) )
break;
v1 += 2;
if ( v1 == v2 )
return 0xFFFFFFFFLL;
}
return *((unsigned __int8 *)v1 + 12);
}

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

v1 = (const char **)functions;
v2 = (const char **)((char *)functions + 0x4000);
while ( 1 )
{
if ( !*v1 )
return 0xFFFFFFFFLL;
if ( !strcmp(*v1, s2) )
break;
v1 += 2;
if ( v1 == v2 )
return 0xFFFFFFFFLL;
}
return *((unsigned __int8 *)v1 + 12);
}

original_code:
char func_get_type(char *name)
{
 int i;
 for (i = 0; i < 1024; i++) {
  if (!functions[i].name) break;
  if (!strcmp(functions[i].name, name))
   return functions[i].type;
 }
 return -1;
}


checkValues

repo: seokbeomKim/klicknmenu

decompiled_code:
__int64 checkValues()
{
__int64 result; // rax
bool v1; // zf

if ( menu_width < 0 )
menu_width = 150;
result = (unsigned int)menu_height;
if ( menu_height < 0 )
menu_height = 150;
if ( menu_padding < 0 )
menu_padding = 5;
if ( border_width < 0 )
border_width = 0;
if ( entry_height < 0 )
entry_height = 20;
if ( border_color )
{
if ( bgColor )
goto LABEL_13;
}
else
{
result = (__int64)malloc(8uLL);
v1 = bgColor == 0;
*(_DWORD *)result = 1717986851;
*(_WORD *)(result + 4) = 26214;
*(_BYTE *)(result + 6) = 102;
border_color = result;
if ( !v1 )
{
LABEL_13:
if ( fgColor )
goto LABEL_14;
goto LABEL_20;
}
}
result = (__int64)malloc(8uLL);
v1 = fgColor == 0;
*(_DWORD *)result = 808464419;
*(_WORD *)(result + 4) = 12336;
*(_BYTE *)(result + 6) = 48;
bgColor = result;
if ( !v1 )
{
LABEL_14:
if ( fontname )
goto LABEL_15;
goto LABEL_21;
}
LABEL_20:
result = (__int64)malloc(8uLL);
v1 = fontname == 0;
*(_DWORD *)result = 1717986851;
*(_WORD *)(result + 4) = 26214;
*(_BYTE *)(result + 6) = 102;
fgColor = result;
if ( !v1 )
{
LABEL_15:
if ( focus_bgColor )
goto LABEL_16;
goto LABEL_22;
}
LABEL_21:
result = (__int64)malloc(6uLL);
v1 = focus_bgColor == 0;
*(_DWORD *)result = 1702390118;
*(_BYTE *)(result + 4) = 100;
fontname = result;
if ( !v1 )
{
LABEL_16:
if ( focus_fgColor )
return result;
LABEL_23:
result = (__int64)malloc(8uLL);
*(_DWORD *)result = 1650734627;
*(_WORD *)(result + 4) = 25699;
*(_BYTE *)(result + 6) = 98;
focus_fgColor = result;
return result;
}
LABEL_22:
result = (__int64)malloc(8uLL);
v1 = focus_fgColor == 0;
*(_DWORD *)result = 808464419;
*(_WORD *)(result + 4) = 12336;
*(_BYTE *)(result + 6) = 48;
focus_bgColor = result;
if ( v1 )
goto LABEL_23;
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
bool v1; // zf

if ( menu_width < 0 )
menu_width = 150;
result = (unsigned int)menu_height;
if ( menu_height < 0 )
menu_height = 150;
if ( menu_padding < 0 )
menu_padding = 5;
if ( border_width < 0 )
border_width = 0;
if ( entry_height < 0 )
entry_height = 20;
if ( border_color )
{
if ( bgColor )
goto LABEL_13;
}
else
{
result = (__int64)malloc(8uLL);
v1 = bgColor == 0;
*(_DWORD *)result = 1717986851;
*(_WORD *)(result + 4) = 26214;
*(_BYTE *)(result + 6) = 102;
border_color = result;
if ( !v1 )
{
LABEL_13:
if ( fgColor )
goto LABEL_14;
goto LABEL_20;
}
}
result = (__int64)malloc(8uLL);
v1 = fgColor == 0;
*(_DWORD *)result = 808464419;
*(_WORD *)(result + 4) = 12336;
*(_BYTE *)(result + 6) = 48;
bgColor = result;
if ( !v1 )
{
LABEL_14:
if ( fontname )
goto LABEL_15;
goto LABEL_21;
}
LABEL_20:
result = (__int64)malloc(8uLL);
v1 = fontname == 0;
*(_DWORD *)result = 1717986851;
*(_WORD *)(result + 4) = 26214;
*(_BYTE *)(result + 6) = 102;
fgColor = result;
if ( !v1 )
{
LABEL_15:
if ( focus_bgColor )
goto LABEL_16;
goto LABEL_22;
}
LABEL_21:
result = (__int64)malloc(6uLL);
v1 = focus_bgColor == 0;
*(_DWORD *)result = 1702390118;
*(_BYTE *)(result + 4) = 100;
fontname = result;
if ( !v1 )
{
LABEL_16:
if ( focus_fgColor )
return result;
LABEL_23:
result = (__int64)malloc(8uLL);
*(_DWORD *)result = 1650734627;
*(_WORD *)(result + 4) = 25699;
*(_BYTE *)(result + 6) = 98;
focus_fgColor = result;
return result;
}
LABEL_22:
result = (__int64)malloc(8uLL);
v1 = focus_fgColor == 0;
*(_DWORD *)result = 808464419;
*(_WORD *)(result + 4) = 12336;
*(_BYTE *)(result + 6) = 48;
focus_bgColor = result;
if ( v1 )
goto LABEL_23;
return result;
}

original_code:
extern void
checkValues(void)
{
 if( menu_width < 0 ) menu_width = 150;
 if( menu_height < 0 ) menu_height = 150;
 if( menu_padding < 0 ) menu_padding = 5;
 if( border_width < 0 ) border_width = 0;
 if( entry_height < 0 ) entry_height = 20;
 if( border_color == ((void *)0) ) {
  char* tmp = (char*)malloc( sizeof( "#ffffff" ) );
  strncpy( tmp, "#ffffff", strlen( "#ffffff" ) );
  border_color = tmp;
 }
 if( bgColor == ((void *)0) ) {
  char* tmp = (char*)malloc( sizeof( "#ffffff" ) );
  strncpy( tmp, "#000000", strlen( "#000000" ) );
  bgColor = tmp;
 }
 if( fgColor == ((void *)0) ) {
  char* tmp = (char*)malloc( sizeof( "#ffffff" ) );
  strncpy( tmp, "#ffffff", strlen( "#ffffff" ) );
  fgColor = tmp;
 }
 if( fontname == ((void *)0) ) {
  char* tmp = (char*)malloc( sizeof( "fixed" ) );
  strncpy( tmp, "fixed", strlen( "fixed" ) );
  fontname = tmp;
 }
 if( focus_bgColor == ((void *)0) ) {
  char* tmp = (char*)malloc( sizeof( "#000000" ) );
  strncpy( tmp, "#000000", strlen( "#000000" ) );
  focus_bgColor = tmp;
 }
 if( focus_fgColor == ((void *)0) ) {
  char* tmp = (char*)malloc( sizeof( "#6dbcdb" ) );
  strncpy( tmp, "#6dbcdb", strlen( "#6dbcdb" ) );
  focus_fgColor = tmp;
 }
}

canonical_original_code:
extern void checkValues()
{
 if( menu_width < 0 ) menu_width = 150;
 if( menu_height < 0 ) menu_height = 150;
 if( menu_padding < 0 ) menu_padding = 5;
 if( border_width < 0 ) border_width = 0;
 if( entry_height < 0 ) entry_height = 20;
 if( border_color == ((void *)0) ) {
  char *tmp = (char*)malloc( sizeof( "#ffffff" ) );
  strncpy( tmp, "#ffffff", strlen( "#ffffff" ) );
  border_color = tmp;
 }
 if( bgColor == ((void *)0) ) {
  char *tmp = (char*)malloc( sizeof( "#ffffff" ) );
  strncpy( tmp, "#000000", strlen( "#000000" ) );
  bgColor = tmp;
 }
 if( fgColor == ((void *)0) ) {
  char *tmp = (char*)malloc( sizeof( "#ffffff" ) );
  strncpy( tmp, "#ffffff", strlen( "#ffffff" ) );
  fgColor = tmp;
 }
 if( fontname == ((void *)0) ) {
  char *tmp = (char*)malloc( sizeof( "fixed" ) );
  strncpy( tmp, "fixed", strlen( "fixed" ) );
  fontname = tmp;
 }
 if( focus_bgColor == ((void *)0) ) {
  char *tmp = (char*)malloc( sizeof( "#000000" ) );
  strncpy( tmp, "#000000", strlen( "#000000" ) );
  focus_bgColor = tmp;
 }
 if( focus_fgColor == ((void *)0) ) {
  char *tmp = (char*)malloc( sizeof( "#6dbcdb" ) );
  strncpy( tmp, "#6dbcdb", strlen( "#6dbcdb" ) );
  focus_fgColor = tmp;
 }
}


getLevel

decompiled_code:
__int64 __fastcall getLevel(char *a1)
{
const unsigned __int16 **v2; // rax
unsigned int i; // er8
__int64 v4; // rdx

v2 = _ctype_b_loc();
for ( i = 0; ; i += (_BYTE)v4 == 9 )
{
v4 = *a1;
if ( ((*v2)[v4] & 0x400) != 0 )
break;
++a1;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1)
{
const unsigned __int16 **v2; // rax
unsigned int i; // er8
__int64 v4; // rdx

v2 = _ctype_b_loc();
for ( i = 0; ; i += (_BYTE)v4 == 9 )
{
v4 = *a1;
if ( ((*v2)[v4] & 0x400) != 0 )
break;
++a1;
}
return i;
}

original_code:
extern int
getLevel(char* str)
{
 int rValue = 0;
 while( !((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short int) _ISalpha) )
        {
  if( *str == '\t' ) rValue++;
  str++;
 }
 return rValue;
}

canonical_original_code:
extern int getLevel(char *str)
{
 int rValue = 0;
 while( !((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short) _ISalpha) )
        {
  if( *str == '\t' ) rValue++;
  str++;
 }
 return rValue;
}

variable_types: rValue int


numberOfMenu

decompiled_code:
__int64 __fastcall numberOfMenu(int a1)
{
__int64 v1; // rax
unsigned int i; // er8

v1 = menu;
if ( a1 > 0 )
v1 = *(_QWORD *)(menu + 16);
for ( i = 0; v1; ++i )
v1 = *(_QWORD *)(v1 + 48);
return i;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
__int64 v1; // rax
unsigned int i; // er8

v1 = menu;
if ( a1 > 0 )
v1 = *(_QWORD *)(menu + 16);
for ( i = 0; v1; ++i )
v1 = *(_QWORD *)(v1 + 48);
return i;
}

original_code:
extern int
numberOfMenu(int level)
{
 ENTRY* cursor;
 int total = 0, index;
 cursor = menu;
        for( index = 0; index < level; index++ )
        {
  cursor = menu->child;
 }
 if( cursor == ((void *)0) )
                return 0;
 while( cursor != ((void *)0) )
        {
  cursor = cursor->next;
  total++;
 }
        return total;
}

canonical_original_code:
extern int numberOfMenu(int level)
{
 struct ENTRY *cursor;
 int total = 0; int index;
 cursor = menu;
        for( index = 0; index < level; index++ )
        {
  cursor = menu->child;
 }
 if( cursor == ((void *)0) )
                return 0;
 while( cursor != ((void *)0) )
        {
  cursor = cursor->next;
  total++;
 }
        return total;
}

variable_types: level int

variable_types: struct ENTRY { char *name; char *command; struct ENTRY *child; struct ENTRY *parent; char *xpmPath; struct ENTRY *prev; struct ENTRY *next; int level; } *

variable_types: total int

variable_types: index int


tolowerString

decompiled_code:
size_t __fastcall tolowerString(char *s)
{
int v1; // er13
unsigned __int64 i; // rbp
size_t result; // rax
__int64 v4; // rbx

v1 = 0;
for ( i = 0LL; ; ++i )
{
result = strlen(s);
if ( v1 > 1 || result <= i )
break;
v4 = s[i];
if ( (_BYTE)v4 == 34 || (_BYTE)v4 == 39 )
++v1;
s[i] = (*_ctype_tolower_loc())[v4];
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func3(char *s)
{
int v1; // er13
unsigned __int64 i; // rbp
size_t result; // rax
__int64 v4; // rbx

v1 = 0;
for ( i = 0LL; ; ++i )
{
result = strlen(s);
if ( v1 > 1 || result <= i )
break;
v4 = s[i];
if ( (_BYTE)v4 == 34 || (_BYTE)v4 == 39 )
++v1;
s[i] = (*_ctype_tolower_loc())[v4];
}
return result;
}

original_code:
extern void
tolowerString(char* str)
{
 int index = 0;
 int doublequote = 0;
 for( ; index < strlen(str); index++ ) {
  if( doublequote >= 2 ) break;
  else if( str[index] == '\"' || str[index] == '\'' ) doublequote++;
  str[index] = tolower(str[index]);
 }
}

canonical_original_code:
extern void tolowerString(char *str)
{
 int index = 0;
 int doublequote = 0;
 for( ; index < strlen(str); index++ ) {
  if( doublequote >= 2 ) break;
  else if( str[index] == '\"' || str[index] == '\'' ) doublequote++;
  str[index] = tolower(str[index]);
 }
}

variable_types: doublequote int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
initmenu();
checkValues(argc, argv);
return draw();
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func5();
func0(argc, argv);
return draw();
}

original_code:
int main(void)
{
 initmenu();
 checkValues();
 return draw();
}

canonical_original_code:
int main()
{
 initmenu();
 checkValues();
 return draw();
}


getEntryCount

decompiled_code:
__int64 __fastcall getEntryCount(__int64 a1)
{
__int64 result; // rax

for ( result = 0LL; a1; result = (unsigned int)(result + 1) )
a1 = *(_QWORD *)(a1 + 48);
return result;
}

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

for ( result = 0LL; a1; result = (unsigned int)(result + 1) )
a1 = *(_QWORD *)(a1 + 48);
return result;
}

original_code:
extern int
getEntryCount(ENTRY* entry)
{
 ENTRY* cursor = entry;
 int num = 0;
 while( cursor != ((void *)0) ) {
  cursor = cursor->next;
  num++;
 }
 return num;
}

canonical_original_code:
extern int getEntryCount(struct ENTRY *entry)
{
 struct ENTRY *cursor = entry;
 int num = 0;
 while( cursor != ((void *)0) ) {
  cursor = cursor->next;
  num++;
 }
 return num;
}

variable_types: num int

user_defined_types: struct ENTRY { char *name; char *command; struct ENTRY *child; struct ENTRY *parent; char *xpmPath; struct ENTRY *prev; struct ENTRY *next; int level; }


original_code:
int days_in_month(int month, int year) {
 if (month == 4 || month == 6 || month == 9 || month == 11) return 30;
 if (month == 2) {
  if (year % 100 != 0 && year % 4 == 0) return 29;
  if (year % 400 == 0) return 29;
  return 28;
 }
 return 31;
}

variable_types: month int

variable_types: year int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rcx
int v4; // er9
int v5; // er8
int i; // eax
__int64 v7; // r10

v3 = 1LL;
v4 = 1900;
v5 = 7;
do
{
for ( i = days_in_month((unsigned int)v3, (unsigned int)v4, envp, v3, (unsigned int)(v5 + 7));
i < v5;
v3 = (unsigned int)(v3 + 1) )
{
v5 -= i;
}
if ( v5 == 1 )
v7 -= (v4 <= 1900) - 1LL;
for ( ; (int)v3 > 12; ++v4 )
v3 = (unsigned int)(v3 - 12);
}
while ( v4 <= 2000 );
printf("%llu\n", v7);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rcx
int v4; // er9
int v5; // er8
int i; // eax
__int64 v7; // r10

v3 = 1LL;
v4 = 1900;
v5 = 7;
do
{
for ( i = func7((unsigned int)v3, (unsigned int)v4, envp, v3, (unsigned int)(v5 + 7));
i < v5;
v3 = (unsigned int)(v3 + 1) )
{
v5 -= i;
}
if ( v5 == 1 )
v7 -= (v4 <= 1900) - 1LL;
for ( ; (int)v3 > 12; ++v4 )
v3 = (unsigned int)(v3 - 12);
}
while ( v4 <= 2000 );
printf("%llu\n", v7);
return 0;
}

original_code:
int main() {
 int day = 7;
 int month = 1;
 int year = 1900;
 unsigned long long count = 0;
 do {
  day += 7;
  int dim = days_in_month(month, year);
  while (dim < day) {
   day -= dim;
   month++;
  }
  if (day == 1 && year > 1900) {
   ++count;
  }
  while (month > 12) {
   month -= 12;
   year += 1;
  }
 } while (year < 2001);
 printf("%llu\n", count);
}

variable_types: day int

variable_types:
count
unsigned long long

variable_types: dim int


multiple

decompiled_code:
int *__fastcall multiple(int *a1, int a2)
{
int *v2; // rcx
int v3; // edx
int *result; // rax
int v5; // eax

v2 = a1 + 159;
v3 = 0;
while ( 1 )
{
v5 = v3 + a2 * *v2;
if ( v5 > 9 )
break;
*v2 = v5;
v3 = 0;
result = v2 - 1;
if ( a1 == v2 )
return result;
LABEL_3:
v2 = result;
}
v3 = v5 / 10;
*v2 = v5 % 10;
result = v2 - 1;
if ( a1 != v2 )
goto LABEL_3;
return result;
}

canonical_decompiled_code:
int *__fastcall func7(int *a1, int a2)
{
int *v2; // rcx
int v3; // edx
int *result; // rax
int v5; // eax

v2 = a1 + 159;
v3 = 0;
while ( 1 )
{
v5 = v3 + a2 * *v2;
if ( v5 > 9 )
break;
*v2 = v5;
v3 = 0;
result = v2 - 1;
if ( a1 == v2 )
return result;
LABEL_3:
v2 = result;
}
v3 = v5 / 10;
*v2 = v5 % 10;
result = v2 - 1;
if ( a1 != v2 )
goto LABEL_3;
return result;
}

original_code:
void multiple(int* digits, int by) {
 int i;
 int extra = 0;
 for (i=160 -1;i>=0;--i) {
  digits[i] *= by;
  digits[i] += extra;
  extra = 0;
  if (digits[i] >= 10) {
   int new_digit = digits[i] % 10;
   extra = digits[i] / 10;
   digits[i] = new_digit;
  }
 }
}

canonical_original_code:
void multiple(int *digits, int by) {
 int i;
 int extra = 0;
 for (i=160 -1;i>=0;--i) {
  digits[i] *= by;
  digits[i] += extra;
  extra = 0;
  if (digits[i] >= 10) {
   int new_digit = digits[i] % 10;
   extra = digits[i] / 10;
   digits[i] = new_digit;
  }
 }
}

variable_types:
digits
int *

variable_types: by int

variable_types: i int

variable_types: extra int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er10
int *v4; // r9
char *v5; // rdi
__int64 v6; // rsi
int v8[160]; // [rsp+0h] [rbp-288h] BYREF
char v9; // [rsp+280h] [rbp-8h] BYREF

v3 = 2;
v4 = v8;
memset(v8, 0, sizeof(v8));
v8[159] = 1;
do
{
v5 = (char *)v4;
multiple(v4, v3, envp);
}
while ( v3 != 100 );
LODWORD(v6) = 0;
do
{
v6 = (unsigned int)(*(_DWORD *)v5 + v6);
v5 += 4;
}
while ( &v9 != v5 );
printf("%d\n", v6);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er10
int *v4; // r9
char *v5; // rdi
__int64 v6; // rsi
int v8[160]; // [rsp+0h] [rbp-288h] BYREF
char v9; // [rsp+280h] [rbp-8h] BYREF

v3 = 2;
v4 = v8;
memset(v8, 0, sizeof(v8));
v8[159] = 1;
do
{
v5 = (char *)v4;
func7(v4, v3, envp);
}
while ( v3 != 100 );
LODWORD(v6) = 0;
do
{
v6 = (unsigned int)(*(_DWORD *)v5 + v6);
v5 += 4;
}
while ( &v9 != v5 );
printf("%d\n", v6);
return 0;
}

original_code:
int main() {
 int digits[160];
 int i;
 for (i=0; i < 160;i++) {
  digits[i] = 0;
 }
 digits[160 -1] = 1;
 for (i=2; i < 100;i++) {
  multiple(digits, i);
 }
 int total = 0;
 for (i=0; i < 160;i++) {
  total += digits[i];
 }
 printf("%d\n", total);
}

variable_types:
digits
int [160]


decompiled_code:
int __fastcall print_fact(__int64 a1, unsigned int a2)
{
int result; // eax

putchar(32);
result = bi_print(stdout, a1);
if ( a2 != 1 )
result = printf("^%d", a2);
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, unsigned int a2)
{
int result; // eax

putchar(32);
result = bi_print(stdout, a1);
if ( a2 != 1 )
result = printf("^%d", a2);
return result;
}

original_code:
static void
print_fact( bigint fact, int power )
    {
    putchar( ' ' );
    bi_print( stdout, fact );
    if ( power != 1 )
        (void) printf( "^%d", power );
    }

canonical_original_code:
static void print_fact(void *fact, int power)
    {
    putchar( ' ' );
    bi_print( stdout, fact );
    if ( power != 1 )
        (void) printf( "^%d", power );
    }

variable_types:
fact
void *

variable_types: power int


decompiled_code:
_BOOL8 __fastcall test_fact(__int64 *a1, unsigned int a2)
{
unsigned int v2; // er13
__int64 i; // rbp
__int64 v4; // rax
__int64 v5; // r14
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v10; // rax

v2 = 0;
for ( i = *a1; ; *a1 = i )
{
v4 = bi_copy(i);
i = bi_int_divide(v4, a2);
v5 = bi_copy(*a1);
v6 = bi_copy(i);
v7 = bi_int_multiply(v6, a2);
if ( (unsigned int)bi_compare(v7, v5) )
break;
++v2;
bi_free(*a1);
}
if ( v2 )
{
v10 = int_to_bi(a2);
print_fact(v10, v2);
}
v8 = int_to_bi(a2);
return (int)bi_compare(i, v8) > 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 *a1, unsigned int a2)
{
unsigned int v2; // er13
__int64 i; // rbp
__int64 v4; // rax
__int64 v5; // r14
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v10; // rax

v2 = 0;
for ( i = *a1; ; *a1 = i )
{
v4 = bi_copy(i);
i = bi_int_divide(v4, a2);
v5 = bi_copy(*a1);
v6 = bi_copy(i);
v7 = bi_int_multiply(v6, a2);
if ( (unsigned int)bi_compare(v7, v5) )
break;
++v2;
bi_free(*a1);
}
if ( v2 )
{
v10 = int_to_bi(a2);
func0(v10, v2);
}
v8 = int_to_bi(a2);
return (int)bi_compare(i, v8) > 0;
}

original_code:
static int
test_fact( bigint* numP, int fact )
    {
    int power;
    bigint t;
    power = 0;
    for (;;)
 {
 t = bi_int_divide( bi_copy( *numP ), fact );
 if ( bi_compare( bi_int_multiply( bi_copy( t ), fact ), bi_copy( *numP ) ) != 0 )
     break;
 bi_free( *numP );
 *numP = t;
 ++power;
 }
    if ( power != 0 )
        print_fact( int_to_bi( fact ), power );
    if ( bi_compare( t, int_to_bi( fact ) ) > 0 )
        return 1;
    return 0;
    }

canonical_original_code:
static int test_fact(void **numP, int fact)
    {
    int power;
    void *t;
    power = 0;
    for (;;)
 {
 t = bi_int_divide( bi_copy( *numP ), fact );
 if ( bi_compare( bi_int_multiply( bi_copy( t ), fact ), bi_copy( *numP ) ) != 0 )
     break;
 bi_free( *numP );
 *numP = t;
 ++power;
 }
    if ( power != 0 )
        print_fact( int_to_bi( fact ), power );
    if ( bi_compare( t, int_to_bi( fact ) ) > 0 )
        return 1;
    return 0;
    }

variable_types:
numP
void **

variable_types: fact int

variable_types:
t
void *


factor

decompiled_code:
int __fastcall factor(__int64 a1)
{
__int64 v1; // rsi
__int64 v2; // rax
__int64 v3; // rax
__int64 *v4; // rbx
__int64 v5; // rsi
__int64 v6; // rbp
__int64 v7; // rax
__int64 v9; // rax
unsigned int i; // ebx
__int64 v11[4]; // [rsp+8h] [rbp-20h] BYREF

v11[0] = a1;
v1 = bi_copy(a1);
bi_print(stdout, v1);
printf(" =");
v2 = bi_copy(a1);
if ( (unsigned int)bi_is_zero(v2) || (v3 = bi_copy(v11[0]), (unsigned int)bi_is_one(v3)) )
{
print_fact(v11[0], 1u);
}
else
{
v4 = (__int64 *)&unk_5A8;
LODWORD(v5) = 2;
while ( test_fact(v11, v5) )
{
if ( v4 == (__int64 *)&unk_13160 )
{
for ( i = 99995; test_fact(v11, i) && test_fact(v11, i + 2); i += 6 )
;
break;
}
v5 = *v4++;
}
v6 = bi_1;
v7 = bi_copy(v11[0]);
if ( (unsigned int)bi_compare(v7, v6) )
{
v9 = bi_copy(v11[0]);
print_fact(v9, 1u);
}
bi_free(v11[0]);
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
__int64 v1; // rsi
__int64 v2; // rax
__int64 v3; // rax
__int64 *v4; // rbx
__int64 v5; // rsi
__int64 v6; // rbp
__int64 v7; // rax
__int64 v9; // rax
unsigned int i; // ebx
__int64 v11[4]; // [rsp+8h] [rbp-20h] BYREF

v11[0] = a1;
v1 = bi_copy(a1);
bi_print(stdout, v1);
printf(" =");
v2 = bi_copy(a1);
if ( (unsigned int)bi_is_zero(v2) || (v3 = bi_copy(v11[0]), (unsigned int)bi_is_one(v3)) )
{
func0(v11[0], 1u);
}
else
{
v4 = (__int64 *)&unk_5A8;
LODWORD(v5) = 2;
while ( func1(v11, v5) )
{
if ( v4 == (__int64 *)&unk_13160 )
{
for ( i = 99995; func1(v11, i) && func1(v11, i + 2); i += 6 )
;
break;
}
v5 = *v4++;
}
v6 = bi_1;
v7 = bi_copy(v11[0]);
if ( (unsigned int)bi_compare(v7, v6) )
{
v9 = bi_copy(v11[0]);
func0(v9, 1u);
}
bi_free(v11[0]);
}
return putchar(10);
}

original_code:
static void
factor( bigint num )
    {
    int p;
    int fact;
    bi_print( stdout, bi_copy( num ) );
    (void) printf( " =" );
    if ( bi_is_zero( bi_copy( num ) ) || bi_is_one( bi_copy( num ) ) )
 print_fact( num, 1 );
    else
        {
 for ( p = 0; p < sizeof(low_primes)/sizeof(*low_primes); ++p )
     if ( ! test_fact( &num, low_primes[p] ) )
  goto done;
 fact = ( low_primes[p - 1] + 5 ) / 6 * 6 - 1;
 for (;;)
     {
     if ( ! test_fact( &num, fact ) )
  break;
     fact += 2;
     if ( ! test_fact( &num, fact ) )
  break;
     fact += 4;
     }
 done:
        if ( bi_compare( bi_copy( num ), bi_1 ) != 0 )
            print_fact( bi_copy( num ), 1 );
 bi_free( num );
        }
    printf( "\n" );
    }

canonical_original_code:
static void factor(void *num)
    {
    int p;
    int fact;
    bi_print( stdout, bi_copy( num ) );
    (void) printf( " =" );
    if ( bi_is_zero( bi_copy( num ) ) || bi_is_one( bi_copy( num ) ) )
 print_fact( num, 1 );
    else
        {
 for ( p = 0; p < sizeof(low_primes)/sizeof(*low_primes); ++p )
     if ( ! test_fact( &num, low_primes[p] ) )
  goto done;
 fact = ( low_primes[p - 1] + 5 ) / 6 * 6 - 1;
 for (;;)
     {
     if ( ! test_fact( &num, fact ) )
  break;
     fact += 2;
     if ( ! test_fact( &num, fact ) )
  break;
     fact += 4;
     }
 done:
        if ( bi_compare( bi_copy( num ), bi_1 ) != 0 )
            print_fact( bi_copy( num ), 1 );
 bi_free( num );
        }
    printf( "\n" );
    }

variable_types:
num
void *

variable_types: p int


decompiled_code:
int __fastcall parse_arg(char *s)
{
__int64 v1; // r13
size_t v2; // rax
size_t v3; // rbp
char v4; // al
__int64 v5; // rbp
size_t v6; // rax
__int64 v7; // rbp
__int64 v8; // rax
__int64 v9; // r13
__int64 v10; // rax
__int64 v11; // r12
__int64 v12; // rax
__int64 v13; // rdi
__int64 v15; // rax
__int64 v16; // rax
__int64 v17; // rax
__int64 v18; // rbp
__int64 v19; // rax
__int64 v20; // r12
__int64 v21; // rax

v1 = (int)strspn(s, "0123456789");
v2 = strlen(s);
if ( v1 != v2 )
{
v3 = v2;
v4 = s[v1];
if ( v4 != 45 )
{
if ( v4 == 46 )
{
if ( strspn(&s[v1], ".") == v3 - v1 )
{
v5 = str_to_bi(s);
v6 = strlen(s) - v1;
switch ( v6 )
{
case 2uLL:
v7 = bi_int_multiply(v5, 100LL);
v16 = bi_copy(v7);
v9 = bi_int_add(v16, 99LL);
break;
case 3uLL:
v7 = bi_int_multiply(v5, 1000LL);
v15 = bi_copy(v7);
v9 = bi_int_add(v15, 999LL);
break;
case 1uLL:
v7 = bi_int_multiply(v5, 10LL);
v8 = bi_copy(v7);
v9 = bi_int_add(v8, 9LL);
break;
default:
fprintf(stderr, "%s: too many wildcard chars\n", argv0);
goto LABEL_9;
}
while ( 1 )
{
v11 = bi_copy(v9);
v12 = bi_copy(v7);
v13 = v7;
if ( (int)bi_compare(v12, v11) > 0 )
break;
v10 = bi_copy(v7);
factor(v10);
v7 = bi_int_add(v7, 1LL);
}
goto LABEL_13;
}
fprintf(stderr, "%s: wildcards must trail number\n", argv0);
}
else
{
fprintf(stderr, "usage: %s <int> <int>-<int> ...\n", argv0);
}
LABEL_9:
exit(1);
}
v18 = str_to_bi(s);
v9 = str_to_bi(&s[v1 + 1]);
while ( 1 )
{
v20 = bi_copy(v9);
v21 = bi_copy(v18);
v13 = v18;
if ( (int)bi_compare(v21, v20) > 0 )
break;
v19 = bi_copy(v18);
factor(v19);
v18 = bi_int_add(v18, 1LL);
}
LABEL_13:
bi_free(v13);
return bi_free(v9);
}
v17 = str_to_bi(s);
return factor(v17);
}

canonical_decompiled_code:
int __fastcall func3(char *s)
{
__int64 v1; // r13
size_t v2; // rax
size_t v3; // rbp
char v4; // al
__int64 v5; // rbp
size_t v6; // rax
__int64 v7; // rbp
__int64 v8; // rax
__int64 v9; // r13
__int64 v10; // rax
__int64 v11; // r12
__int64 v12; // rax
__int64 v13; // rdi
__int64 v15; // rax
__int64 v16; // rax
__int64 v17; // rax
__int64 v18; // rbp
__int64 v19; // rax
__int64 v20; // r12
__int64 v21; // rax

v1 = (int)strspn(s, "0123456789");
v2 = strlen(s);
if ( v1 != v2 )
{
v3 = v2;
v4 = s[v1];
if ( v4 != 45 )
{
if ( v4 == 46 )
{
if ( strspn(&s[v1], ".") == v3 - v1 )
{
v5 = str_to_bi(s);
v6 = strlen(s) - v1;
switch ( v6 )
{
case 2uLL:
v7 = bi_int_multiply(v5, 100LL);
v16 = bi_copy(v7);
v9 = bi_int_add(v16, 99LL);
break;
case 3uLL:
v7 = bi_int_multiply(v5, 1000LL);
v15 = bi_copy(v7);
v9 = bi_int_add(v15, 999LL);
break;
case 1uLL:
v7 = bi_int_multiply(v5, 10LL);
v8 = bi_copy(v7);
v9 = bi_int_add(v8, 9LL);
break;
default:
fprintf(stderr, "%s: too many wildcard chars\n", argv0);
goto LABEL_9;
}
while ( 1 )
{
v11 = bi_copy(v9);
v12 = bi_copy(v7);
v13 = v7;
if ( (int)bi_compare(v12, v11) > 0 )
break;
v10 = bi_copy(v7);
func2(v10);
v7 = bi_int_add(v7, 1LL);
}
goto LABEL_13;
}
fprintf(stderr, "%s: wildcards must trail number\n", argv0);
}
else
{
fprintf(stderr, "usage: %s <int> <int>-<int> ...\n", argv0);
}
LABEL_9:
exit(1);
}
v18 = str_to_bi(s);
v9 = str_to_bi(&s[v1 + 1]);
while ( 1 )
{
v20 = bi_copy(v9);
v21 = bi_copy(v18);
v13 = v18;
if ( (int)bi_compare(v21, v20) > 0 )
break;
v19 = bi_copy(v18);
func2(v19);
v18 = bi_int_add(v18, 1LL);
}
LABEL_13:
bi_free(v13);
return bi_free(v9);
}
v17 = str_to_bi(s);
return func2(v17);
}

original_code:
static void
parse_arg( char* arg )
    {
    int i;
    bigint n, n2;
    i = strspn( arg, "0123456789" );
    if ( i == strlen( arg ) )
 factor( str_to_bi( arg ) );
    else
 {
 if ( arg[i] == '-' )
     {
     n = str_to_bi( arg );
     n2 = str_to_bi( &arg[i+1] );
     for ( ; bi_compare( bi_copy( n ), bi_copy( n2 ) ) < 1;
    n = bi_int_add( n, 1 ) )
  factor( bi_copy( n ) );
     bi_free( n );
     bi_free( n2 );
     }
 else if ( arg[i] == '.' )
     {
     if ( strspn( &arg[i], "." ) != strlen( arg ) - i )
  {
  (void) fprintf(
      stderr, "%s: wildcards must trail number\n", argv0 );
  exit( 1 );
  }
     n = str_to_bi( arg );
     switch ( strlen( arg ) - i )
  {
  case 1:
  n = bi_int_multiply( n, 10 );
  n2 = bi_int_add( bi_copy( n ), 9 );
  break;
  case 2:
  n = bi_int_multiply( n, 100 );
  n2 = bi_int_add( bi_copy( n ), 99 );
  break;
  case 3:
  n = bi_int_multiply( n, 1000 );
  n2 = bi_int_add( bi_copy( n ), 999 );
  break;
  default:
  (void) fprintf(
      stderr, "%s: too many wildcard chars\n", argv0 );
  exit( 1 );
  }
     for ( ; bi_compare( bi_copy( n ), bi_copy( n2 ) ) < 1;
    n = bi_int_add( n, 1 ) )
  factor( bi_copy( n ) );
     bi_free( n );
     bi_free( n2 );
     }
 else
     {
     (void) fprintf(
  stderr, "usage:  %s <int> <int>-<int> ...\n", argv0 );
     exit( 1 );
     }
 }
    }

canonical_original_code:
static void parse_arg(char *arg)
    {
    int i;
    void *n; void *n2;
    i = strspn( arg, "0123456789" );
    if ( i == strlen( arg ) )
 factor( str_to_bi( arg ) );
    else
 {
 if ( arg[i] == '-' )
     {
     n = str_to_bi( arg );
     n2 = str_to_bi( &arg[i+1] );
     for ( ; bi_compare( bi_copy( n ), bi_copy( n2 ) ) < 1;
    n = bi_int_add( n, 1 ) )
  factor( bi_copy( n ) );
     bi_free( n );
     bi_free( n2 );
     }
 else if ( arg[i] == '.' )
     {
     if ( strspn( &arg[i], "." ) != strlen( arg ) - i )
  {
  (void) fprintf(
      stderr, "%s: wildcards must trail number\n", argv0 );
  exit( 1 );
  }
     n = str_to_bi( arg );
     switch ( strlen( arg ) - i )
  {
  case 1:
  n = bi_int_multiply( n, 10 );
  n2 = bi_int_add( bi_copy( n ), 9 );
  break;
  case 2:
  n = bi_int_multiply( n, 100 );
  n2 = bi_int_add( bi_copy( n ), 99 );
  break;
  case 3:
  n = bi_int_multiply( n, 1000 );
  n2 = bi_int_add( bi_copy( n ), 999 );
  break;
  default:
  (void) fprintf(
      stderr, "%s: too many wildcard chars\n", argv0 );
  exit( 1 );
  }
     for ( ; bi_compare( bi_copy( n ), bi_copy( n2 ) ) < 1;
    n = bi_int_add( n, 1 ) )
  factor( bi_copy( n ) );
     bi_free( n );
     bi_free( n2 );
     }
 else
     {
     (void) fprintf(
  stderr, "usage:  %s <int> <int>-<int> ...\n", argv0 );
     exit( 1 );
     }
 }
    }

variable_types:
arg
char *

variable_types:
n
void *


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char **v4; // rbx
char *v5; // rdi
char v6[1032]; // [rsp+0h] [rbp-408h] BYREF

argv0 = (__int64)*argv;
bi_initialize(argc, argv, envp);
bi_no_check();
if ( argc == 1 )
{
while ( fgets(v6, 1000, stdin) )
parse_arg(v6);
}
else if ( argc > 1 )
{
v4 = argv + 1;
do
{
v5 = (char *)*v4++;
parse_arg(v5);
}
while ( v4 != &argv[(unsigned int)(argc - 2) + 2] );
}
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char **v4; // rbx
char *v5; // rdi
char v6[1032]; // [rsp+0h] [rbp-408h] BYREF

argv0 = (__int64)*argv;
bi_initialize(argc, argv, envp);
bi_no_check();
if ( argc == 1 )
{
while ( fgets(v6, 1000, stdin) )
func3(v6);
}
else if ( argc > 1 )
{
v4 = argv + 1;
do
{
v5 = (char *)*v4++;
func3(v5);
}
while ( v4 != &argv[(unsigned int)(argc - 2) + 2] );
}
exit(0);
}

original_code:
int
main( int argc, char** argv )
    {
    int i;
    char buf[1000];
    argv0 = argv[0];
    bi_initialize();
    bi_no_check();
    if ( argc == 1 )
        while ( fgets( buf, sizeof(buf), stdin ) != (char*) 0 )
     parse_arg( buf );
    else
        for ( i = 1; i < argc; ++i )
            parse_arg( argv[i] );
    exit( 0 );
    }

canonical_original_code:
int main(int argc, char **argv)
    {
    int i;
    char buf[1000];
    argv0 = argv[0];
    bi_initialize();
    bi_no_check();
    if ( argc == 1 )
        while ( fgets( buf, sizeof(buf), stdin ) != (char *) 0 )
     parse_arg( buf );
    else
        for ( i = 1; i < argc; ++i )
            parse_arg( argv[i] );
    exit( 0 );
    }

variable_types: argc int

variable_types:
argv
char **

variable_types:
buf
char [1000]


gcd

decompiled_code:
__int64 __fastcall gcd(int a1, int a2)
{
int v2; // er8
int v3; // edx
int v4; // eax

v2 = a2;
v3 = a1 % a2;
if ( a1 % a2 )
{
do
{
v4 = v2;
if ( v2 < v3 )
v4 = v3;
if ( v2 > v3 )
v2 = v3;
v3 = v4 % v2;
}
while ( v4 % v2 );
}
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, int a2)
{
int v2; // er8
int v3; // edx
int v4; // eax

v2 = a2;
v3 = a1 % a2;
if ( a1 % a2 )
{
do
{
v4 = v2;
if ( v2 < v3 )
v4 = v3;
if ( v2 > v3 )
v2 = v3;
v3 = v4 % v2;
}
while ( v4 % v2 );
}
return (unsigned int)v2;
}

original_code:
int gcd(int num1, int num2) {
 int remainder = num1 % num2;
 if (remainder == 0) return num2;
 return gcd((num2>remainder?num2:remainder), (num2<remainder?num2:remainder));
}

variable_types: remainder int


divisors

original_code:
int divisors(int val, int *divisors_list) {
 int i, divisors_pos=0;
 if (!is_prime(val)) {
  i = val/2;
  if ((val&1)==0)divisors_list[divisors_pos++] = 2;
  if ((i&1)==0)i--;
  for (; i > 1; i-=2) {
   if (val % i == 0 && is_prime(i)) {
    divisors_list[divisors_pos++] = i;
   }
  }
 }
 return divisors_pos;
}

canonical_original_code:
int divisors(int val, int *divisors_list) {
 int i; int divisors_pos = 0;
 if (!is_prime(val)) {
  i = val/2;
  if ((val&1)==0)divisors_list[divisors_pos++] = 2;
  if ((i&1)==0)i--;
  for (; i > 1; i-=2) {
   if (val % i == 0 && is_prime(i)) {
    divisors_list[divisors_pos++] = i;
   }
  }
 }
 return divisors_pos;
}

variable_types: val int


decompiled_code:
void __noreturn handle_sig()
{
fwrite("Floating point exception (caught)\n", 1uLL, 0x22uLL, stderr);
longjmp(jb, 1);
}

canonical_decompiled_code:
void __noreturn func0()
{
fwrite("Floating point exception (caught)\n", 1uLL, 0x22uLL, stderr);
longjmp(jb, 1);
}

original_code:
static void
handle_sig( int sig )
    {
    (void) fprintf( stderr, "Floating point exception (caught)\n" );
    longjmp( jb, 1 );
    }

canonical_original_code:
static void handle_sig(int sig)
    {
    (void) fprintf( stderr, "Floating point exception (caught)\n" );
    longjmp( jb, 1 );
    }

variable_types: sig int


init

decompiled_code:
char *init()
{
__int64 v0; // rdx
char *result; // rax

bi_initialize();
bi_no_check();
v0 = bi_0;
result = (char *)&vars;
prev_val = bi_0;
do
{
*(_QWORD *)result = v0;
result += 8;
}
while ( result != "Floating point exception (caught)\n" );
return result;
}

canonical_decompiled_code:
char *func1()
{
__int64 v0; // rdx
char *result; // rax

bi_initialize();
bi_no_check();
v0 = bi_0;
result = (char *)&vars;
prev_val = bi_0;
do
{
*(_QWORD *)result = v0;
result += 8;
}
while ( result != "Floating point exception (caught)\n" );
return result;
}

original_code:
static void
init( void )
    {
    int i;
    bi_initialize();
    bi_no_check();
    prev_val = bi_0;
    for ( i = 0; i < 26; ++i )
 vars[i] = bi_0;
    }

canonical_original_code:
static void init()
    {
    int i;
    bi_initialize();
    bi_no_check();
    prev_val = bi_0;
    for ( i = 0; i < 26; ++i )
 vars[i] = bi_0;
    }

variable_types: i int


term

decompiled_code:
__int64 term()
{
char *v0; // rbx
__int64 v1; // rdi

v0 = (char *)&vars;
bi_free(prev_val);
do
{
v1 = *(_QWORD *)v0;
v0 += 8;
bi_free(v1);
}
while ( v0 != "Floating point exception (caught)\n" );
return bi_terminate();
}

canonical_decompiled_code:
__int64 func5()
{
char *v0; // rbx
__int64 v1; // rdi

v0 = (char *)&vars;
bi_free(prev_val);
do
{
v1 = *(_QWORD *)v0;
v0 += 8;
bi_free(v1);
}
while ( v0 != "Floating point exception (caught)\n" );
return bi_terminate();
}

original_code:
static void
term( void )
    {
    int i;
    bi_free( prev_val );
    for ( i = 0; i < 26; ++i )
 bi_free( vars[i] );
    bi_terminate();
    }

canonical_original_code:
static void term()
    {
    int i;
    bi_free( prev_val );
    for ( i = 0; i < 26; ++i )
 bi_free( vars[i] );
    bi_terminate();
    }


yyerror

decompiled_code:
int __fastcall yyerror(const char *a1)
{
return fprintf(stderr, "%s\n", a1);
}

canonical_decompiled_code:
int __fastcall func6(const char *a1)
{
return fprintf(stderr, "%s\n", a1);
}

original_code:
void
yyerror( char* msg )
    {
    (void) fprintf( stderr, "%s\n", msg );
    }

canonical_original_code:
void yyerror(char *msg)
    {
    (void) fprintf( stderr, "%s\n", msg );
    }

variable_types:
msg
char *


main

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

v3 = time(0LL);
v4 = getpid();
srandom(v3 ^ v4);
signal(8, (__sighandler_t)handle_sig);
init();
if ( setjmp(jb) )
reinit();
yyparse_isra_0();
term();
exit(0);
}

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

v3 = time(0LL);
v4 = getpid();
srandom(v3 ^ v4);
signal(8, (__sighandler_t)handle_sig);
func1();
if ( setjmp(jb) )
func4();
func7();
func5();
exit(0);
}

original_code:
int
main( int argc, char** argv )
    {
    srandom( (int) time( (time_t*) 0 ) ^ getpid() );
    signal( 8, handle_sig );
    init();
    if ( _setjmp (jb) != 0 )
 reinit();
    yyparse();
    term();
    exit( 0 );
    }

canonical_original_code:
int main(int argc, char **argv)
    {
    srandom( (int) time( (long *) 0 ) ^ getpid() );
    signal( 8, handle_sig );
    init();
    if ( _setjmp (jb) != 0 )
 reinit();
    yyparse();
    term();
    exit( 0 );
    }


original_code:
int sum_digits_factorials(int num) {
 int i, v = 0;
 int size = (int)floor(log10(num))+1;
 for (i=0;i<size;++i) {
  v += factorial((unsigned long long)(num/pow(10,i)) % 10);
 }
 return v;
}

canonical_original_code:
int sum_digits_factorials(int num) {
 int i; int v = 0;
 int size = (int)floor(log10(num))+1;
 for (i=0;i<size;++i) {
  v += factorial((unsigned long long)(num/pow(10,i)) % 10);
 }
 return v;
}

variable_types: num int

variable_types: v int

variable_types: size int


decompiled_code:
__int64 __fastcall has_factorials(_DWORD *a1, int a2, int a3)
{
__int64 v3; // rax

if ( a2 <= 0 )
return 0LL;
v3 = (__int64)&a1[a2 - 1 + 1];
while ( *a1 != a3 )
{
if ( ++a1 == (_DWORD *)v3 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(_DWORD *a1, int a2, int a3)
{
__int64 v3; // rax

if ( a2 <= 0 )
return 0LL;
v3 = (__int64)&a1[a2 - 1 + 1];
while ( *a1 != a3 )
{
if ( ++a1 == (_DWORD *)v3 )
return 0LL;
}
return 1LL;
}

original_code:
int has_factorials(int factorials[], int factorials_pos, int sum) {
 int i;
 for (i = 0; i < factorials_pos; i++) {
  if (factorials[i] == sum) return 1;
 }
 return 0;
}

variable_types:
factorials
int []

variable_types: sum int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er12
unsigned int v4; // ebp
__int64 v5; // rbx
unsigned int v6; // er8
unsigned int v7; // er8
int v9[66]; // [rsp+0h] [rbp-108h] BYREF

v3 = 0;
v4 = 0;
LABEL_2:
while ( 2 )
{
v9[0] = v4;
v5 = 1LL;
v6 = sum_digits_factorials(v4, argv, envp);
do
{
argv = (const char **)(unsigned int)v5;
if ( (unsigned int)has_factorials(v9, (unsigned int)v5, v6) )
{
if ( ++v4 != 1000000 )
goto LABEL_2;
goto LABEL_6;
}
v9[v5++] = v7;
v6 = sum_digits_factorials(v7, argv, envp);
}
while ( v5 != 60 );
++v4;
++v3;
if ( v4 != 1000000 )
continue;
break;
}
LABEL_6:
printf("%d\n", v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er12
unsigned int v4; // ebp
__int64 v5; // rbx
unsigned int v6; // er8
unsigned int v7; // er8
int v9[66]; // [rsp+0h] [rbp-108h] BYREF

v3 = 0;
v4 = 0;
LABEL_2:
while ( 2 )
{
v9[0] = v4;
v5 = 1LL;
v6 = func8(v4, argv, envp);
do
{
argv = (const char **)(unsigned int)v5;
if ( (unsigned int)func9(v9, (unsigned int)v5, v6) )
{
if ( ++v4 != 1000000 )
goto LABEL_2;
goto LABEL_6;
}
v9[v5++] = v7;
v6 = func8(v7, argv, envp);
}
while ( v5 != 60 );
++v4;
++v3;
if ( v4 != 1000000 )
continue;
break;
}
LABEL_6:
printf("%d\n", v3);
return 0;
}

original_code:
int main() {
 int c_total = 0;
 int i, sum;
 int factorials[60];
 int factorials_pos;
 for (i = 0; i < 1000000; i++) {
  factorials_pos = 0;
  sum = i;
  do {
   factorials[factorials_pos++] = sum;
   sum = sum_digits_factorials(sum);
   if (factorials_pos == 60) break;
  } while (!has_factorials(factorials, factorials_pos, sum));
  if (factorials_pos == 60) {
   c_total++;
  }
 }
 printf("%d\n", c_total);
 return 0;
}

canonical_original_code:
int main() {
 int c_total = 0;
 int i; int sum;
 int factorials[60];
 int factorials_pos;
 for (i = 0; i < 1000000; i++) {
  factorials_pos = 0;
  sum = i;
  do {
   factorials[factorials_pos++] = sum;
   sum = sum_digits_factorials(sum);
   if (factorials_pos == 60) break;
  } while (!has_factorials(factorials, factorials_pos, sum));
  if (factorials_pos == 60) {
   c_total++;
  }
 }
 printf("%d\n", c_total);
 return 0;
}

variable_types:
factorials
int [60]


factorial

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

v1 = a1;
v2 = 1;
if ( a1 > 9 )
{
do
{
v3 = v1--;
v2 *= v3;
}
while ( v1 != 9 );
a1 = 9;
}
return (unsigned int)(v2 * CSWTCH_2[a1]);
}

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

v1 = a1;
v2 = 1;
if ( a1 > 9 )
{
do
{
v3 = v1--;
v2 *= v3;
}
while ( v1 != 9 );
a1 = 9;
}
return (unsigned int)(v2 * CSWTCH_2[a1]);
}

original_code:
int factorial(int n) {
 switch (n) {
  case 0:
  case 1:
   return 1;
  case 2:
   return 2;
  case 3:
   return 6;
  case 4:
   return 24;
  case 5:
   return 120;
  case 6:
   return 720;
  case 7:
   return 5040;
  case 8:
   return 40320;
  case 9:
   return 362880;
  default:
   return n * factorial(n-1);
 }
}

variable_types: n int


duplicate

decompiled_code:
__int64 __fastcall duplicate(int *a1)
{
int *v1; // rdx
__int64 result; // rax
int *v3; // rcx
int v4; // ecx

v1 = a1 + 304;
LODWORD(result) = 0;
while ( 1 )
{
v4 = result + 2 * *v1;
if ( v4 > 9 )
break;
*v1 = v4;
result = 0LL;
v3 = v1 - 1;
if ( a1 == v1 )
return result;
LABEL_3:
v1 = v3;
}
result = (unsigned int)(v4 / 10);
*v1 = v4 % 10;
v3 = v1 - 1;
if ( a1 != v1 )
goto LABEL_3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int *a1)
{
int *v1; // rdx
__int64 result; // rax
int *v3; // rcx
int v4; // ecx

v1 = a1 + 304;
LODWORD(result) = 0;
while ( 1 )
{
v4 = result + 2 * *v1;
if ( v4 > 9 )
break;
*v1 = v4;
result = 0LL;
v3 = v1 - 1;
if ( a1 == v1 )
return result;
LABEL_3:
v1 = v3;
}
result = (unsigned int)(v4 / 10);
*v1 = v4 % 10;
v3 = v1 - 1;
if ( a1 != v1 )
goto LABEL_3;
return result;
}

original_code:
void duplicate(int* digits) {
 int i;
 int extra = 0;
 for (i=305 -1;i>=0;--i) {
  digits[i] *= 2;
  digits[i] += extra;
  extra = 0;
  if (digits[i] >= 10) {
   int new_digit = digits[i] % 10;
   extra = digits[i] / 10;
   digits[i] = new_digit;
  }
 }
}

canonical_original_code:
void duplicate(int *digits) {
 int i;
 int extra = 0;
 for (i=305 -1;i>=0;--i) {
  digits[i] *= 2;
  digits[i] += extra;
  extra = 0;
  if (digits[i] >= 10) {
   int new_digit = digits[i] % 10;
   extra = digits[i] / 10;
   digits[i] = new_digit;
  }
 }
}

variable_types:
digits
int *

variable_types: extra int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r8
char *v4; // rdi
int v5; // er9
__int64 v6; // rsi
__int64 v7; // rax
_BYTE v9[1216]; // [rsp+0h] [rbp-4D8h] BYREF
int v10; // [rsp+4C0h] [rbp-18h]
char v11; // [rsp+4C4h] [rbp-14h] BYREF

v3 = v9;
memset(v9, 0, sizeof(v9));
v10 = 1;
do
{
v4 = v3;
duplicate(v3, argv, envp);
}
while ( v5 != 1 );
v6 = 0LL;
do
{
v7 = *(int *)v4;
v4 += 4;
v6 += v7;
}
while ( &v11 != v4 );
printf("%llu\n", v6);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r8
char *v4; // rdi
int v5; // er9
__int64 v6; // rsi
__int64 v7; // rax
_BYTE v9[1216]; // [rsp+0h] [rbp-4D8h] BYREF
int v10; // [rsp+4C0h] [rbp-18h]
char v11; // [rsp+4C4h] [rbp-14h] BYREF

v3 = v9;
memset(v9, 0, sizeof(v9));
v10 = 1;
do
{
v4 = v3;
func7(v3, argv, envp);
}
while ( v5 != 1 );
v6 = 0LL;
do
{
v7 = *(int *)v4;
v4 += 4;
v6 += v7;
}
while ( &v11 != v4 );
printf("%llu\n", v6);
return 0;
}

original_code:
int main() {
 int digits[305];
 int i;
 for (i=0; i < 305;i++) {
  digits[i] = 0;
 }
 digits[305 -1] = 1;
 for (i=0; i < 1000;i++) {
  duplicate(digits);
 }
 unsigned long long total = 0;
 for (i=0; i < 305;i++) {
  total += digits[i];
 }
 printf("%llu\n", total);
}

variable_types:
digits
int [305]

variable_types:
total
unsigned long long


position

decompiled_code:
__int64 __fastcall position(int a1)
{
__int64 v1; // rdi
__int64 result; // rax

v1 = (unsigned int)(a1 - 2);
result = 0xFFFFFFFFLL;
if ( (unsigned int)v1 <= 0x11 )
result = (unsigned int)CSWTCH_2[v1];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
__int64 v1; // rdi
__int64 result; // rax

v1 = (unsigned int)(a1 - 2);
result = 0xFFFFFFFFLL;
if ( (unsigned int)v1 <= 0x11 )
result = (unsigned int)CSWTCH_2[v1];
return result;
}

original_code:
int position(int prime) {
 switch (prime) {
  case 2: return 0;
  case 3: return 1;
  case 5: return 2;
  case 7: return 3;
  case 11: return 4;
  case 13: return 5;
  case 17: return 6;
  case 19: return 7;
 }
 return -1;
}

variable_types: prime int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
int v4; // eax
char *v5; // rdi
__int64 i; // rax
int v7; // edx
__int64 v8; // rsi
unsigned int v9; // ecx
unsigned int v10; // ecx
int v11; // eax
__int128 v13[2]; // [rsp+0h] [rbp-28h]

v3 = 20;
v13[0] = 0LL;
v13[1] = 0LL;
do
{
while ( !(unsigned int)is_prime(v3, argv, envp) )
{
v5 = (char *)divisors(v3);
for ( i = 0LL; i != 32; i += 4LL )
{
v7 = *(_DWORD *)&v5[i];
if ( v7 > *(_DWORD *)((char *)v13 + i) )
*(_DWORD *)((char *)v13 + i) = v7;
}
free(v5);
if ( !--v3 )
goto LABEL_11;
}
v4 = position(v3);
envp = (const char **)*((unsigned int *)v13 + v4);
if ( !(_DWORD)envp )
*((_DWORD *)v13 + v4) = 1;
--v3;
}
while ( v3 );
LABEL_11:
v8 = 1LL;
v9 = 20;
do
{
while ( 1 )
{
if ( (unsigned int)is_prime(v9, v8, envp) )
{
envp = (const char **)*((unsigned int *)v13 + (int)position(v10));
if ( (int)envp > 0 )
break;
}
v9 = v10 - 1;
if ( !v9 )
goto LABEL_18;
}
v11 = 0;
do
{
++v11;
v8 = v10 * (unsigned int)v8;
}
while ( (_DWORD)envp != v11 );
v9 = v10 - 1;
}
while ( v9 );
LABEL_18:
printf("%d\n", v8);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
int v4; // eax
char *v5; // rdi
__int64 i; // rax
int v7; // edx
__int64 v8; // rsi
unsigned int v9; // ecx
unsigned int v10; // ecx
int v11; // eax
__int128 v13[2]; // [rsp+0h] [rbp-28h]

v3 = 20;
v13[0] = 0LL;
v13[1] = 0LL;
do
{
while ( !(unsigned int)func8(v3, argv, envp) )
{
v5 = (char *)divisors(v3);
for ( i = 0LL; i != 32; i += 4LL )
{
v7 = *(_DWORD *)&v5[i];
if ( v7 > *(_DWORD *)((char *)v13 + i) )
*(_DWORD *)((char *)v13 + i) = v7;
}
free(v5);
if ( !--v3 )
goto LABEL_11;
}
v4 = func7(v3);
envp = (const char **)*((unsigned int *)v13 + v4);
if ( !(_DWORD)envp )
*((_DWORD *)v13 + v4) = 1;
--v3;
}
while ( v3 );
LABEL_11:
v8 = 1LL;
v9 = 20;
do
{
while ( 1 )
{
if ( (unsigned int)func8(v9, v8, envp) )
{
envp = (const char **)*((unsigned int *)v13 + (int)func7(v10));
if ( (int)envp > 0 )
break;
}
v9 = v10 - 1;
if ( !v9 )
goto LABEL_18;
}
v11 = 0;
do
{
++v11;
v8 = v10 * (unsigned int)v8;
}
while ( (_DWORD)envp != v11 );
v9 = v10 - 1;
}
while ( v9 );
LABEL_18:
printf("%d\n", v8);
return 0;
}

original_code:
int main() {
 int primes[8] = {0,0,0,0,0,0,0,0};
 int i, j;
 for (i = 20; i > 0; --i) {
  if (is_prime(i)) {
   int pos = position(i);
   if (primes[pos] == 0) primes[pos] = 1;
  } else {
   int* local_primes = divisors(i);
   for (j = 0; j < 8; j++) {
    if (local_primes[j] > primes[j]) primes[j] = local_primes[j];
   }
   free(local_primes);
  }
 }
 int total = 1;
 for (i = 20; i > 0; --i) {
  if (is_prime(i)) {
   int pos = position(i);
   for (j = 0; j < primes[pos]; ++j) {
    total *= i;
   }
  }
 }
 printf("%d\n", total);
}

canonical_original_code:
int main() {
 int primes[8] = {0,0,0,0,0,0,0,0};
 int i; int j;
 for (i = 20; i > 0; --i) {
  if (is_prime(i)) {
   int pos = position(i);
   if (primes[pos] == 0) primes[pos] = 1;
  } else {
   int *local_primes = divisors(i);
   for (j = 0; j < 8; j++) {
    if (local_primes[j] > primes[j]) primes[j] = local_primes[j];
   }
   free(local_primes);
  }
 }
 int total = 1;
 for (i = 20; i > 0; --i) {
  if (is_prime(i)) {
   int pos = position(i);
   for (j = 0; j < primes[pos]; ++j) {
    total *= i;
   }
  }
 }
 printf("%d\n", total);
}

variable_types:
primes
int [8]

variable_types: j int

variable_types: pos int

variable_types: total int


decompiled_code:
__int64 __fastcall is_prime(int a1, __int64 a2)
{
unsigned int v2; // er12
int v4; // er13
int v5; // ebp
__int64 v6; // rdi
__int64 v7; // rdx

v2 = 1;
if ( !a1 )
return v2;
v2 = 0;
if ( a1 == 1 )
return v2;
v2 = 1;
if ( a1 == 2 )
return v2;
v2 = 0;
if ( (a1 & 1) == 0 )
return v2;
v4 = a1 / 2;
if ( a1 > 5 )
{
v5 = 2;
while ( 1 )
{
v6 = (unsigned int)(a1 / v5);
v7 = (unsigned int)(a1 >> 31);
v2 = a1 % (int)v6;
if ( !(a1 % (int)v6) )
{
LODWORD(v7) = a1 % (int)v6;
if ( (unsigned int)is_prime(v6, a2, v7) )
break;
}
if ( ++v5 >= v4 )
return 1LL;
}
return v2;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, __int64 a2)
{
unsigned int v2; // er12
int v4; // er13
int v5; // ebp
__int64 v6; // rdi
__int64 v7; // rdx

v2 = 1;
if ( !a1 )
return v2;
v2 = 0;
if ( a1 == 1 )
return v2;
v2 = 1;
if ( a1 == 2 )
return v2;
v2 = 0;
if ( (a1 & 1) == 0 )
return v2;
v4 = a1 / 2;
if ( a1 > 5 )
{
v5 = 2;
while ( 1 )
{
v6 = (unsigned int)(a1 / v5);
v7 = (unsigned int)(a1 >> 31);
v2 = a1 % (int)v6;
if ( !(a1 % (int)v6) )
{
LODWORD(v7) = a1 % (int)v6;
if ( (unsigned int)func8(v6, a2, v7) )
break;
}
if ( ++v5 >= v4 )
return 1LL;
}
return v2;
}
return 1LL;
}

original_code:
int is_prime(int num) {
 if (num == 0) return 1;
 if (num == 1) return 0;
 if (num == 2) return 1;
 if (num != 2 && num % 2 == 0) return 0;
 int num2, num3;
 for (num3 = 2; num3 < num / 2; ++num3) {
  num2 = num / num3;
  if (num % num2 == 0) {
   if (is_prime(num2)) {
    return 0;
   }
  }
 }
 return 1;
}

canonical_original_code:
int is_prime(int num) {
 if (num == 0) return 1;
 if (num == 1) return 0;
 if (num == 2) return 1;
 if (num != 2 && num % 2 == 0) return 0;
 int num2; int num3;
 for (num3 = 2; num3 < num / 2; ++num3) {
  num2 = num / num3;
  if (num % num2 == 0) {
   if (is_prime(num2)) {
    return 0;
   }
  }
 }
 return 1;
}


decompiled_code:
__int64 __fastcall letters_in_number(unsigned int a1, __int64 a2, __int64 a3, __int64 a4)
{
unsigned __int64 v4; // rbx
__int64 v5; // r12
unsigned int v6; // er14
int v7; // er15
int v8; // ebp
int v10; // er13
int v11; // eax

if ( !a1 )
return 0;
v4 = a1;
if ( a1 - 1 > 1 )
{
if ( a1 == 3 )
return 5;
if ( a1 - 4 <= 1 )
return 4;
if ( a1 != 6 )
{
if ( a1 - 7 > 1 )
{
if ( a1 != 9 )
{
if ( a1 != 10 )
{
v5 = 0x1004010000000000LL;
v6 = 0;
while ( 1 )
{
if ( (unsigned int)(v4 - 11) <= 1 )
{
LABEL_40:
v6 += 6;
return v6;
}
if ( (unsigned int)(v4 - 13) <= 1 )
goto LABEL_41;
if ( (unsigned int)(v4 - 15) <= 1 )
{
LABEL_42:
v6 += 7;
return v6;
}
if ( (_DWORD)v4 == 17 )
{
v6 += 9;
return v6;
}
if ( (unsigned int)(v4 - 18) <= 1 )
{
LABEL_41:
v6 += 8;
return v6;
}
if ( (_DWORD)v4 == 20 || (_DWORD)v4 == 30 )
goto LABEL_40;
if ( (unsigned int)v4 <= 0x3C )
{
if ( _bittest64(&v5, v4) )
goto LABEL_36;
}
else
{
switch ( (_DWORD)v4 )
{
case 0x46:
case 0x50:
goto LABEL_42;
case 0x5A:
goto LABEL_40;
case 0x3E8:
v6 += 11;
return v6;
}
}
v7 = 0;
v8 = (int)v4 % 100;
if ( (int)v4 > 99 )
{
v11 = letters_in_number((unsigned int)((int)v4 / 100), a2, (unsigned int)(100 * ((int)v4 / 100)), a4);
v7 = v11 + 7;
if ( !v8 )
{
LABEL_24:
v6 += v7;
v4 = (unsigned int)v8;
goto LABEL_25;
}
v7 = v11 + 10;
}
if ( v8 <= 19 )
goto LABEL_24;
v10 = (int)v4 / 10;
v4 = (unsigned int)((int)v4 % 10);
v6 += letters_in_number((unsigned int)(10 * (v10 % 10)), a2, (unsigned int)(v10 % 10), a4) + v7;
LABEL_25:
if ( !(_DWORD)v4 )
return v6;
if ( (unsigned int)(v4 - 1) <= 1 )
goto LABEL_33;
if ( (_DWORD)v4 == 3 )
goto LABEL_36;
if ( (unsigned int)(v4 - 4) <= 1 )
{
LABEL_44:
v6 += 4;
return v6;
}
if ( (_DWORD)v4 == 6 )
goto LABEL_33;
if ( (unsigned int)(v4 - 7) <= 1 )
{
LABEL_36:
v6 += 5;
return v6;
}
if ( (_DWORD)v4 == 9 )
goto LABEL_44;
if ( (_DWORD)v4 == 10 )
{
LABEL_33:
v6 += 3;
return v6;
}
}
}
return 3;
}
return 4;
}
return 5;
}
}
return 3;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1, __int64 a2, __int64 a3, __int64 a4)
{
unsigned __int64 v4; // rbx
__int64 v5; // r12
unsigned int v6; // er14
int v7; // er15
int v8; // ebp
int v10; // er13
int v11; // eax

if ( !a1 )
return 0;
v4 = a1;
if ( a1 - 1 > 1 )
{
if ( a1 == 3 )
return 5;
if ( a1 - 4 <= 1 )
return 4;
if ( a1 != 6 )
{
if ( a1 - 7 > 1 )
{
if ( a1 != 9 )
{
if ( a1 != 10 )
{
v5 = 0x1004010000000000LL;
v6 = 0;
while ( 1 )
{
if ( (unsigned int)(v4 - 11) <= 1 )
{
LABEL_40:
v6 += 6;
return v6;
}
if ( (unsigned int)(v4 - 13) <= 1 )
goto LABEL_41;
if ( (unsigned int)(v4 - 15) <= 1 )
{
LABEL_42:
v6 += 7;
return v6;
}
if ( (_DWORD)v4 == 17 )
{
v6 += 9;
return v6;
}
if ( (unsigned int)(v4 - 18) <= 1 )
{
LABEL_41:
v6 += 8;
return v6;
}
if ( (_DWORD)v4 == 20 || (_DWORD)v4 == 30 )
goto LABEL_40;
if ( (unsigned int)v4 <= 0x3C )
{
if ( _bittest64(&v5, v4) )
goto LABEL_36;
}
else
{
switch ( (_DWORD)v4 )
{
case 0x46:
case 0x50:
goto LABEL_42;
case 0x5A:
goto LABEL_40;
case 0x3E8:
v6 += 11;
return v6;
}
}
v7 = 0;
v8 = (int)v4 % 100;
if ( (int)v4 > 99 )
{
v11 = func7((unsigned int)((int)v4 / 100), a2, (unsigned int)(100 * ((int)v4 / 100)), a4);
v7 = v11 + 7;
if ( !v8 )
{
LABEL_24:
v6 += v7;
v4 = (unsigned int)v8;
goto LABEL_25;
}
v7 = v11 + 10;
}
if ( v8 <= 19 )
goto LABEL_24;
v10 = (int)v4 / 10;
v4 = (unsigned int)((int)v4 % 10);
v6 += func7((unsigned int)(10 * (v10 % 10)), a2, (unsigned int)(v10 % 10), a4) + v7;
LABEL_25:
if ( !(_DWORD)v4 )
return v6;
if ( (unsigned int)(v4 - 1) <= 1 )
goto LABEL_33;
if ( (_DWORD)v4 == 3 )
goto LABEL_36;
if ( (unsigned int)(v4 - 4) <= 1 )
{
LABEL_44:
v6 += 4;
return v6;
}
if ( (_DWORD)v4 == 6 )
goto LABEL_33;
if ( (unsigned int)(v4 - 7) <= 1 )
{
LABEL_36:
v6 += 5;
return v6;
}
if ( (_DWORD)v4 == 9 )
goto LABEL_44;
if ( (_DWORD)v4 == 10 )
{
LABEL_33:
v6 += 3;
return v6;
}
}
}
return 3;
}
return 4;
}
return 5;
}
}
return 3;
}

original_code:
int letters_in_number(int num) {
 if (num == 0) return 0;
 if (num == 1) return 3;
 if (num == 2) return 3;
 if (num == 3) return 5;
 if (num == 4) return 4;
 if (num == 5) return 4;
 if (num == 6) return 3;
 if (num == 7) return 5;
 if (num == 8) return 5;
 if (num == 9) return 4;
 if (num == 10) return 3;
 if (num == 11) return 6;
 if (num == 12) return 6;
 if (num == 13) return 8;
 if (num == 14) return 8;
 if (num == 15) return 7;
 if (num == 16) return 7;
 if (num == 17) return 9;
 if (num == 18) return 8;
 if (num == 19) return 8;
 if (num == 20) return 6;
 if (num == 30) return 6;
 if (num == 40) return 5;
 if (num == 50) return 5;
 if (num == 60) return 5;
 if (num == 70) return 7;
 if (num == 80) return 7;
 if (num == 90) return 6;
 if (num == 1000) return 11;
 int size = 0;
 if (num > 99) {
  size += 7 + letters_in_number(num / 100);
  if (num % 100 != 0) size += 3;
 }
 if (num % 100 < 20) {
  size += letters_in_number(num % 100);
 } else {
  size += letters_in_number(((num / 10) % 10) * 10);
  size += letters_in_number(num % 10);
 }
 return size;
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ecx
__int64 v4; // rsi

v3 = 1;
v4 = 0LL;
do
v4 += (int)letters_in_number(v3, v4, envp, v3 + 1);
while ( v3 != 1001 );
printf("%llu\n", v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ecx
__int64 v4; // rsi

v3 = 1;
v4 = 0LL;
do
v4 += (int)func7(v3, v4, envp, v3 + 1);
while ( v3 != 1001 );
printf("%llu\n", v4);
return 0;
}

original_code:
int main() {
 unsigned long long total = 0;
 int i;
 for (i=1;i<=1000;++i) total += letters_in_number(i);
 printf("%llu\n", total);
}

variable_types: i int


decompiled_code:
__int64 __fastcall is_palindromic(unsigned int a1)
{
int v2; // eax
int v3; // ecx
__int64 v4; // rdx
char *i; // rax
char s[15]; // [rsp+1h] [rbp-Fh] BYREF

if ( -1171354717 * a1 + 195225786 > 0x1745D174 )
return 0LL;
v2 = sprintf(s, "%d", a1);
v3 = v2 / 2;
if ( v2 <= 1 )
return 1LL;
v4 = 0LL;
for ( i = &s[v2]; s[v4] == *(i - 1); --i )
{
if ( v3 <= (int)++v4 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1)
{
int v2; // eax
int v3; // ecx
__int64 v4; // rdx
char *i; // rax
char s[15]; // [rsp+1h] [rbp-Fh] BYREF

if ( -1171354717 * a1 + 195225786 > 0x1745D174 )
return 0LL;
v2 = sprintf(s, "%d", a1);
v3 = v2 / 2;
if ( v2 <= 1 )
return 1LL;
v4 = 0LL;
for ( i = &s[v2]; s[v4] == *(i - 1); --i )
{
if ( v3 <= (int)++v4 )
return 1LL;
}
return 0LL;
}

original_code:
int is_palindromic(int num) {
 if (num % 11 != 0) return 0;
 char string[7];
 int chars = sprintf(string, "%d", num);
 int i;
 for (i = 0; i < chars/2; i++) {
  if (string[i] != string[chars-1-i]) return 0;
 }
 return 1;
}

variable_types: num int

variable_types:
string
char [7]

variable_types: chars int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er15
int v4; // er14
int v5; // er13
int v6; // er12
int v7; // ebx
int v8; // ebp

v3 = 997002;
v4 = 998001;
v5 = 999;
v6 = 0;
do
{
v7 = v4;
v8 = v3;
if ( v4 >= v6 )
{
while ( !(unsigned int)is_palindromic((unsigned int)v7, argv, envp) )
{
v7 = v8;
v8 -= v5;
if ( v7 < v6 )
goto LABEL_7;
}
v6 = v7;
}
LABEL_7:
v4 -= 999;
--v5;
v3 -= 998;
}
while ( v6 < v4 );
printf("Largest is %d\n", (unsigned int)v6);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er15
int v4; // er14
int v5; // er13
int v6; // er12
int v7; // ebx
int v8; // ebp

v3 = 997002;
v4 = 998001;
v5 = 999;
v6 = 0;
do
{
v7 = v4;
v8 = v3;
if ( v4 >= v6 )
{
while ( !(unsigned int)func7((unsigned int)v7, argv, envp) )
{
v7 = v8;
v8 -= v5;
if ( v7 < v6 )
goto LABEL_7;
}
v6 = v7;
}
LABEL_7:
v4 -= 999;
--v5;
v3 -= 998;
}
while ( v6 < v4 );
printf("Largest is %d\n", (unsigned int)v6);
return 0;
}

original_code:
int main() {
 int num1;
 int result = 0;
 for (num1 = 999; result < num1 * 999; num1--) {
  int num2 = 999;
  do {
   int tmp_result = num1 * num2;
   if (tmp_result < result) break;
   if (is_palindromic(tmp_result)) {
    result = tmp_result;
    break;
   }
   num2--;
  } while (1);
 }
 printf("Largest is %d\n", result);
}

variable_types: result int


sort

original_code:
void sort(char* arr[], int beg, int end)
{
  if (end > beg + 1)
  {
    char* piv = arr[beg];
    int l = beg + 1, r = end;
    while (l < r)
    {
      if (strcmp(arr[l],piv) <= 0)
        l++;
      else
        swap(&arr[l], &arr[--r]);
    }
    swap(&arr[--l], &arr[beg]);
    sort(arr, beg, l);
    sort(arr, r, end);
  }
}

canonical_original_code:
void sort(char *arr[], int beg, int end)
{
  if (end > beg + 1)
  {
    char *piv = arr[beg];
    int l = beg + 1; int r = end;
    while (l < r)
    {
      if (strcmp(arr[l],piv) <= 0)
        l++;
      else
        swap(&arr[l], &arr[--r]);
    }
    swap(&arr[--l], &arr[beg]);
    sort(arr, beg, l);
    sort(arr, r, end);
  }
}

variable_types:
arr
char *[]

variable_types: beg int

variable_types: end int

variable_types:
piv
char *

variable_types: l int

variable_types: r int


decompiled_code:
__int64 __fastcall alphabetical_value(const char *a1)
{
int v1; // eax
__int64 v2; // r8
__int64 v3; // rdx
int v4; // eax

v1 = strlen(a1);
if ( v1 <= 0 )
return 0LL;
v2 = 0LL;
v3 = (__int64)&a1[v1 - 1 + 1];
do
{
v4 = *a1++;
v2 += v4 - 64;
}
while ( a1 != (const char *)v3 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1)
{
int v1; // eax
__int64 v2; // r8
__int64 v3; // rdx
int v4; // eax

v1 = strlen(a1);
if ( v1 <= 0 )
return 0LL;
v2 = 0LL;
v3 = (__int64)&a1[v1 - 1 + 1];
do
{
v4 = *a1++;
v2 += v4 - 64;
}
while ( a1 != (const char *)v3 );
return v2;
}

original_code:
unsigned long long alphabetical_value(char* name) {
 unsigned long long total = 0;
 int i, c = strlen(name);
 for (i=0;i<c;++i) {
  total += name[i] - 64;
 }
 return total;
}

canonical_original_code:
unsigned long long alphabetical_value(char *name) {
 unsigned long long total = 0;
 int i; int c = strlen(name);
 for (i=0;i<c;++i) {
  total += name[i] - 64;
 }
 return total;
}

variable_types:
name
char *

variable_types:
total
unsigned long long

variable_types: c int

return_type: unsigned long long


combinatorics

decompiled_code:
unsigned __int64 __fastcall combinatorics(unsigned __int64 a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rcx
unsigned __int64 v3; // r9
unsigned __int64 v4; // rax
unsigned __int64 v5; // r8

if ( a1 - a2 >= a2 )
a2 = a1 - a2;
factorial(a1, a2);
if ( v3 <= v2 )
v2 = v3;
v4 = factorial(v2, 1LL);
return v5 / v4;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func8(unsigned __int64 a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rcx
unsigned __int64 v3; // r9
unsigned __int64 v4; // rax
unsigned __int64 v5; // r8

if ( a1 - a2 >= a2 )
a2 = a1 - a2;
func7(a1, a2);
if ( v3 <= v2 )
v2 = v3;
v4 = func7(v2, 1LL);
return v5 / v4;
}

original_code:
unsigned long long combinatorics(unsigned long long n, unsigned long long r) {
 return factorial(n, (r<n-r?n-r:r)) / factorial((r>n-r?n-r:r), 1);
}

variable_types:
n
unsigned long long

variable_types:
r
unsigned long long


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r11
unsigned int v4; // er12
int v5; // ebp
int v6; // er10
int v7; // ebx
int v8; // er10

v3 = 2LL;
v4 = 0;
v5 = 2;
do
{
v6 = 1;
v7 = (int)v3 >> 1;
if ( (int)v3 >> 1 != 1 )
{
do
{
if ( (unsigned __int64)combinatorics(v3, v6, envp) > 0xF4240 )
{
envp = (const char **)(unsigned int)(2 * v8);
v8 += v5;
v4 += v5 - (_DWORD)envp + 1;
}
v6 = v8 + 1;
}
while ( v7 > v6 );
}
v5 = ++v3;
}
while ( v3 != 101 );
printf("%d\n", v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r11
unsigned int v4; // er12
int v5; // ebp
int v6; // er10
int v7; // ebx
int v8; // er10

v3 = 2LL;
v4 = 0;
v5 = 2;
do
{
v6 = 1;
v7 = (int)v3 >> 1;
if ( (int)v3 >> 1 != 1 )
{
do
{
if ( (unsigned __int64)func8(v3, v6, envp) > 0xF4240 )
{
envp = (const char **)(unsigned int)(2 * v8);
v8 += v5;
v4 += v5 - (_DWORD)envp + 1;
}
v6 = v8 + 1;
}
while ( v7 > v6 );
}
v5 = ++v3;
}
while ( v3 != 101 );
printf("%d\n", v4);
return 0;
}

variable_types: j int


factorial

decompiled_code:
__int64 __fastcall factorial(unsigned __int64 a1, __int64 a2)
{
__int64 result; // rax
unsigned __int64 v3; // rdx

if ( a2 == a1 )
return 1LL;
result = 1LL;
if ( a1 <= 1 )
return 1LL;
do
{
v3 = a1--;
result *= v3;
}
while ( a1 != a2 && a1 > 1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned __int64 a1, __int64 a2)
{
__int64 result; // rax
unsigned __int64 v3; // rdx

if ( a2 == a1 )
return 1LL;
result = 1LL;
if ( a1 <= 1 )
return 1LL;
do
{
v3 = a1--;
result *= v3;
}
while ( a1 != a2 && a1 > 1 );
return result;
}

original_code:
unsigned long long factorial (unsigned long long n, unsigned long long upto) {
 if (n == upto || n < 2) return 1;
 return n * factorial(n-1, upto);
}

canonical_original_code:
unsigned long long factorial(unsigned long long n, unsigned long long upto) {
 if (n == upto || n < 2) return 1;
 return n * factorial(n-1, upto);
}

variable_types:
upto
unsigned long long


currency

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

result = 400LL;
if ( a1 <= 7 )
result = (unsigned int)CSWTCH_1[a1];
return result;
}

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

result = 400LL;
if ( a1 <= 7 )
result = (unsigned int)CSWTCH_1[a1];
return result;
}

original_code:
int currency(int pos) {
 switch (pos) {
  case 0: return 1;
  case 1: return 2;
  case 2: return 5;
  case 3: return 10;
  case 4: return 20;
  case 5: return 50;
  case 6: return 100;
  case 7: return 200;
 }
 return 400;
}

variable_types: pos int


main

original_code:
int main() {
 int a,b,c,d,e,f,g,h;
 int a_max,b_max,c_max,d_max,e_max,f_max,g_max,h_max;
 a_max = 200 / currency(0);
 b_max = 200 / currency(1);
 c_max = 200 / currency(2);
 d_max = 200 / currency(3);
 e_max = 200 / currency(4);
 f_max = 200 / currency(5);
 g_max = 200 / currency(6);
 h_max = 200 / currency(7);
 int counter = 0;
 for (a=0;a<=a_max;++a)
 for (b=0;b<=b_max;++b)
 for (c=0;c<=c_max;++c)
 for (d=0;d<=d_max;++d)
 for (e=0;e<=e_max;++e)
 for (f=0;f<=f_max;++f)
 for (g=0;g<=g_max;++g)
 for (h=0;h<=h_max;++h) {
  if (a*currency(0)+b*currency(1)+c*currency(2)+d*currency(3)+e*currency(4)+f*currency(5)+g*currency(6)+h*currency(7) == 200) {
   counter++;
  }
 }
 printf("%d\n", counter);
 return 0;
}

canonical_original_code:
int main() {
 int a; int b; int c; int d; int e; int f; int g; int h;
 int a_max; int b_max; int c_max; int d_max; int e_max; int f_max; int g_max; int h_max;
 a_max = 200 / currency(0);
 b_max = 200 / currency(1);
 c_max = 200 / currency(2);
 d_max = 200 / currency(3);
 e_max = 200 / currency(4);
 f_max = 200 / currency(5);
 g_max = 200 / currency(6);
 h_max = 200 / currency(7);
 int counter = 0;
 for (a=0;a<=a_max;++a)
 for (b=0;b<=b_max;++b)
 for (c=0;c<=c_max;++c)
 for (d=0;d<=d_max;++d)
 for (e=0;e<=e_max;++e)
 for (f=0;f<=f_max;++f)
 for (g=0;g<=g_max;++g)
 for (h=0;h<=h_max;++h) {
  if (a*currency(0)+b*currency(1)+c*currency(2)+d*currency(3)+e*currency(4)+f*currency(5)+g*currency(6)+h*currency(7) == 200) {
   counter++;
  }
 }
 printf("%d\n", counter);
 return 0;
}

variable_types: a int

variable_types: b int

variable_types: d int

variable_types: e int

variable_types: f int

variable_types: g int

variable_types: h int

variable_types: counter int