repo: sengaya/libkeepalive

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebx
const char *v5; // rsi
socklen_t optlen; // [rsp+8h] [rbp-10h] BYREF
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

optlen = 4;
v3 = socket(2, 1, 6);
if ( v3 >= 0 )
{
v4 = v3;
if ( getsockopt(v3, 1, 9, optval, &optlen) >= 0 )
{
v5 = (const char *)&unk_402004;
if ( !optval[0] )
v5 = (const char *)&unk_402007;
printf("SO_KEEPALIVE is %s\n", v5);
if ( optval[0] )
{
if ( getsockopt(v4, 6, 6, optval, &optlen) < 0 )
{
perror("getsockopt()");
close(v4);
exit(1);
}
printf("TCP_KEEPCNT = %d\n", (unsigned int)optval[0]);
if ( getsockopt(v4, 6, 4, optval, &optlen) < 0 )
{
perror("getsockopt()");
close(v4);
exit(1);
}
printf("TCP_KEEPIDLE = %d\n", (unsigned int)optval[0]);
if ( getsockopt(v4, 6, 5, optval, &optlen) < 0 )
{
perror("getsockopt()");
close(v4);
exit(1);
}
printf("TCP_KEEPINTVL = %d\n", (unsigned int)optval[0]);
}
close(v4);
exit(0);
}
perror("getsockopt()");
close(v4);
exit(1);
}
perror("socket()");
exit(1);
}

original_code:
int main()
{
   int s;
   int optval;
   socklen_t optlen = sizeof(optval);
   if((s = socket(2, SOCK_STREAM, IPPROTO_TCP)) < 0) {
      perror("socket()");
      exit(1);
   }
   if(getsockopt(s, 1, 9, &optval, &optlen) < 0) {
      perror("getsockopt()");
      close(s);
      exit(1);
   }
   printf("SO_KEEPALIVE is %s\n", (optval ? "ON" : "OFF"));
   if(optval) {
      if(getsockopt(s, 6, 6, &optval, &optlen) < 0) {
         perror("getsockopt()");
         close(s);
         exit(1);
      }
      printf("TCP_KEEPCNT   = %d\n", optval);
      if(getsockopt(s, 6, 4, &optval, &optlen) < 0) {
         perror("getsockopt()");
         close(s);
         exit(1);
      }
      printf("TCP_KEEPIDLE  = %d\n", optval);
      if(getsockopt(s, 6, 5, &optval, &optlen) < 0) {
         perror("getsockopt()");
         close(s);
         exit(1);
      }
      printf("TCP_KEEPINTVL = %d\n", optval);
   }
   close(s);
   exit(0);
}

canonical_original_code:
int main()
{
   int s;
   int optval;
   unsigned int optlen = sizeof(optval);
   if((s = socket(2, SOCK_STREAM, IPPROTO_TCP)) < 0) {
      perror("socket()");
      exit(1);
   }
   if(getsockopt(s, 1, 9, &optval, &optlen) < 0) {
      perror("getsockopt()");
      close(s);
      exit(1);
   }
   printf("SO_KEEPALIVE is %s\n", (optval ? "ON" : "OFF"));
   if(optval) {
      if(getsockopt(s, 6, 6, &optval, &optlen) < 0) {
         perror("getsockopt()");
         close(s);
         exit(1);
      }
      printf("TCP_KEEPCNT   = %d\n", optval);
      if(getsockopt(s, 6, 4, &optval, &optlen) < 0) {
         perror("getsockopt()");
         close(s);
         exit(1);
      }
      printf("TCP_KEEPIDLE  = %d\n", optval);
      if(getsockopt(s, 6, 5, &optval, &optlen) < 0) {
         perror("getsockopt()");
         close(s);
         exit(1);
      }
      printf("TCP_KEEPINTVL = %d\n", optval);
   }
   close(s);
   exit(0);
}

variable_types: s int

variable_types: optval int

variable_types:
optlen
unsigned int


repo: senko/calcc

decompiled_code:
_BOOL8 __fastcall in_eax(int a1)
{
return eax_var == a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(int a1)
{
return eax_var == a1;
}

original_code: static int in_eax(int index) { return (eax_var == index); }

variable_types: index int

return_type: int


invalidate

decompiled_code:
void __fastcall invalidate(int a1)
{
if ( eax_var == a1 )
eax_var = -1;
}

canonical_decompiled_code:
void __fastcall func1(int a1)
{
if ( eax_var == a1 )
eax_var = -1;
}

original_code: static void invalidate(int index) { if (eax_var == index) eax_var = -1; }

return_type: void


decompiled_code:
void __fastcall set_eax(int a1)
{
invalidate(a1);
eax_var = a1;
}

canonical_decompiled_code:
void __fastcall func2(int a1)
{
func1(a1);
eax_var = a1;
}

original_code: static void set_eax(int index) { invalidate(index); eax_var = index; }


loc

decompiled_code:
char *__fastcall loc(int a1)
{
if ( argc > a1 )
sprintf(location_0, "[ebp + %d]", (unsigned int)(4 * a1 + 8));
else
sprintf(location_0, "[ebp - %d]", (unsigned int)(4 * (a1 - argc) + 4));
return strdup(location_0);
}

canonical_decompiled_code:
char *__fastcall func3(int a1)
{
if ( argc > a1 )
sprintf(location_0, "[ebp + %d]", (unsigned int)(4 * a1 + 8));
else
sprintf(location_0, "[ebp - %d]", (unsigned int)(4 * (a1 - argc) + 4));
return strdup(location_0);
}

original_code:
static char *loc(int index)
{
 static char location[128];
 if (index >= argc)
  sprintf(location, "[ebp - %d]", 4 * (1 + index - argc));
 else
  sprintf(location, "[ebp + %d]", 4 * (2 + index));
 return strdup(location);
}

variable_types:
location
char [128]

return_type: char *


decompiled_code:
void __fastcall emit_3c(const char *a1, int a2, int a3, int a4)
{
char *v6; // r14
char *v7; // r12
char *v8; // rbp

v6 = loc(a2);
v7 = loc(a3);
v8 = loc(a4);
if ( !in_eax(a2) )
fprintf(out, "\tmov eax, %s\n", v6);
free(v6);
fprintf(out, "\t%s eax, %s\n", a1, v7);
free(v7);
fprintf(out, "\tmov %s, eax\n", v8);
free(v8);
set_eax(a4);
}

canonical_decompiled_code:
void __fastcall func4(const char *a1, int a2, int a3, int a4)
{
char *v6; // r14
char *v7; // r12
char *v8; // rbp

v6 = func3(a2);
v7 = func3(a3);
v8 = func3(a4);
if ( !func0(a2) )
fprintf(out, "\tmov eax, %s\n", v6);
free(v6);
fprintf(out, "\t%s eax, %s\n", a1, v7);
free(v7);
fprintf(out, "\tmov %s, eax\n", v8);
free(v8);
func2(a4);
}

original_code:
static void emit_3c(char *op, int left, int right, int result)
{
 char *a, *b, *c;
 a = loc(left); b = loc(right); c = loc(result);
 if (!in_eax(left)) fprintf(out, "\tmov eax, %s\n", a); free(a);
 fprintf(out, "\t%s eax, %s\n", op, b); free(b);
 fprintf(out, "\tmov %s, eax\n", c); free(c);
 set_eax(result);
}

canonical_original_code:
static void emit_3c(char *op, int left, int right, int result)
{
 char *a; char *b; char *c;
 a = loc(left); b = loc(right); c = loc(result);
 if (!in_eax(left)) fprintf(out, "\tmov eax, %s\n", a); free(a);
 fprintf(out, "\t%s eax, %s\n", op, b); free(b);
 fprintf(out, "\tmov %s, eax\n", c); free(c);
 set_eax(result);
}

variable_types:
op
char *

variable_types: left int

variable_types: right int

variable_types: result int

variable_types:
a
char *

variable_types:
b
char *

variable_types:
c
char *


decompiled_code:
void __fastcall emit_divop(const char *a1, int a2, int a3, int a4)
{
char *v6; // r14
char *v7; // r12
char *v8; // rbp

v6 = loc(a2);
v7 = loc(a3);
v8 = loc(a4);
fwrite("\txor edx, edx\n", 1uLL, 0xEuLL, out);
if ( !in_eax(a2) )
fprintf(out, "\tmov eax, %s\n", v6);
free(v6);
fprintf(out, "\tidiv long %s\n", v7);
free(v7);
fprintf(out, "\tmov %s, %s\n", v8, a1);
free(v8);
invalidate(a4);
eax_var = -1;
}

canonical_decompiled_code:
void __fastcall func5(const char *a1, int a2, int a3, int a4)
{
char *v6; // r14
char *v7; // r12
char *v8; // rbp

v6 = func3(a2);
v7 = func3(a3);
v8 = func3(a4);
fwrite("\txor edx, edx\n", 1uLL, 0xEuLL, out);
if ( !func0(a2) )
fprintf(out, "\tmov eax, %s\n", v6);
free(v6);
fprintf(out, "\tidiv long %s\n", v7);
free(v7);
fprintf(out, "\tmov %s, %s\n", v8, a1);
free(v8);
func1(a4);
eax_var = -1;
}

original_code:
static void emit_divop(char *reg, int left, int right, int result)
{
 char *a, *b, *c;
 a = loc(left); b = loc(right); c = loc(result);
 fprintf(out, "\txor edx, edx\n");
 if (!in_eax(left)) fprintf(out, "\tmov eax, %s\n", a); free(a);
 fprintf(out, "\tidiv long %s\n", b); free(b);
 fprintf(out, "\tmov %s, %s\n", c, reg); free(c);
 invalidate(result); eax_var = -1;
}

canonical_original_code:
static void emit_divop(char *reg, int left, int right, int result)
{
 char *a; char *b; char *c;
 a = loc(left); b = loc(right); c = loc(result);
 fprintf(out, "\txor edx, edx\n");
 if (!in_eax(left)) fprintf(out, "\tmov eax, %s\n", a); free(a);
 fprintf(out, "\tidiv long %s\n", b); free(b);
 fprintf(out, "\tmov %s, %s\n", c, reg); free(c);
 invalidate(result); eax_var = -1;
}

variable_types:
reg
char *


decompiled_code:
void __fastcall emit_3float(const char *a1, unsigned int a2, unsigned int a3, int a4)
{
char *v6; // r12
char *v7; // rbp
char *v8; // rbx
const char *v9; // r15
char v10; // al
const char *v11; // r14
int v12; // [rsp+Ch] [rbp-3Ch]

v6 = loc(a2);
v7 = loc(a3);
v12 = a4;
v8 = loc(a4);
v9 = "fld";
if ( (unsigned __int8)var_type(a2) == 1 )
v9 = "fild";
v10 = var_type(a3);
v11 = (const char *)&unk_D03;
if ( v10 == 1 )
v11 = "i";
fprintf(out, "\t; floating point '%s': %s & %s -> %s\n", a1, v6, v7, v8);
fprintf(out, "\t%s long %s\n", v9, v6);
free(v6);
fprintf(out, "\tf%s%s long %s\n", v11, a1, v7);
free(v7);
fprintf(out, "\tfstp long %s\n", v8);
free(v8);
invalidate(v12);
}

canonical_decompiled_code:
void __fastcall func6(const char *a1, unsigned int a2, unsigned int a3, int a4)
{
char *v6; // r12
char *v7; // rbp
char *v8; // rbx
const char *v9; // r15
char v10; // al
const char *v11; // r14
int v12; // [rsp+Ch] [rbp-3Ch]

v6 = func3(a2);
v7 = func3(a3);
v12 = a4;
v8 = func3(a4);
v9 = "fld";
if ( (unsigned __int8)var_type(a2) == 1 )
v9 = "fild";
v10 = var_type(a3);
v11 = (const char *)&unk_D03;
if ( v10 == 1 )
v11 = "i";
fprintf(out, "\t; floating point '%s': %s & %s -> %s\n", a1, v6, v7, v8);
fprintf(out, "\t%s long %s\n", v9, v6);
free(v6);
fprintf(out, "\tf%s%s long %s\n", v11, a1, v7);
free(v7);
fprintf(out, "\tfstp long %s\n", v8);
free(v8);
func1(v12);
}

original_code:
static void emit_3float(char *op, int left, int right, int result)
{
 char *a, *b, *c;
 char *lm = "fld";
 char *iop = "";
 a = loc(left); b = loc(right); c = loc(result);
 if (var_type(left) == 1) lm = "fild";
 if (var_type(right) == 1) iop = "i";
 fprintf(out, "\t; floating point '%s': %s & %s -> %s\n", op, a, b, c);
 fprintf(out, "\t%s long %s\n", lm, a); free(a);
 fprintf(out, "\tf%s%s long %s\n", iop, op, b); free(b);
 fprintf(out, "\tfstp long %s\n", c); free(c);
 invalidate(result);
}

canonical_original_code:
static void emit_3float(char *op, int left, int right, int result)
{
 char *a; char *b; char *c;
 char *lm = "fld";
 char *iop = "";
 a = loc(left); b = loc(right); c = loc(result);
 if (var_type(left) == 1) lm = "fild";
 if (var_type(right) == 1) iop = "i";
 fprintf(out, "\t; floating point '%s': %s & %s -> %s\n", op, a, b, c);
 fprintf(out, "\t%s long %s\n", lm, a); free(a);
 fprintf(out, "\tf%s%s long %s\n", iop, op, b); free(b);
 fprintf(out, "\tfstp long %s\n", c); free(c);
 invalidate(result);
}

variable_types:
lm
char *

variable_types:
iop
char *


decompiled_code:
__int64 __fastcall emit_init(const char *a1)
{
out = fopen(a1, "w");
if ( out )
return 0LL;
perror("can't open output file");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1)
{
out = fopen(a1, "w");
if ( out )
return 0LL;
perror("can't open output file");
return 0xFFFFFFFFLL;
}

original_code:
int emit_init(char *file)
{
 out = fopen(file, "w");
 if (!out) {
  perror("can't open output file");
  return -1;
 }
 return 0;
}

variable_types:
file
char *


decompiled_code:
int emit_finish()
{
fputc(10, out);
return fclose(out);
}

canonical_decompiled_code:
int func8()
{
fputc(10, out);
return fclose(out);
}

original_code:
void emit_finish(void)
{
 fprintf(out, "\n");
 fclose(out);
}

canonical_original_code:
void emit_finish()
{
 fprintf(out, "\n");
 fclose(out);
}


decompiled_code:
void emit_variable()
{
;
}

canonical_decompiled_code:
void func9()
{
;
}

original_code:
void emit_variable(char *name)
{
}

canonical_original_code:
void emit_variable(char *name)
{
}

variable_types:
name
char *


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

fprintf(out, "\n\nglobal %s:function\n%s:\n", a1, a1);
fwrite("\tpush ebp\n", 1uLL, 0xAuLL, out);
fwrite("\tmov ebp, esp\n", 1uLL, 0xEuLL, out);
result = fprintf(out, "\tsub esp, %d\n\n", 4096LL);
argc = a2;
eax_var = -1;
return result;
}

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

fprintf(out, "\n\nglobal %s:function\n%s:\n", a1, a1);
fwrite("\tpush ebp\n", 1uLL, 0xAuLL, out);
fwrite("\tmov ebp, esp\n", 1uLL, 0xEuLL, out);
result = fprintf(out, "\tsub esp, %d\n\n", 4096LL);
argc = a2;
eax_var = -1;
return result;
}

original_code:
void emit_function_start(char *name, int fargc)
{
 fprintf(out, "\n\nglobal %s:function\n%s:\n", name, name);
 fprintf(out, "\tpush ebp\n");
 fprintf(out, "\tmov ebp, esp\n");
 fprintf(out, "\tsub esp, %d\n\n", 1024 * 4);
 argc = fargc; eax_var = -1;
}

variable_types: fargc int


decompiled_code:
size_t emit_function_end()
{
fwrite(".Lfe:\n", 1uLL, 6uLL, out);
fwrite("\tleave\n", 1uLL, 7uLL, out);
return fwrite("\tret\n\n", 1uLL, 6uLL, out);
}

canonical_decompiled_code:
size_t func11()
{
fwrite(".Lfe:\n", 1uLL, 6uLL, out);
fwrite("\tleave\n", 1uLL, 7uLL, out);
return fwrite("\tret\n\n", 1uLL, 6uLL, out);
}

original_code:
void emit_function_end(void)
{
 fprintf(out, ".Lfe:\n");
 fprintf(out, "\tleave\n");
 fprintf(out, "\tret\n\n");
}

canonical_original_code:
void emit_function_end()
{
 fprintf(out, ".Lfe:\n");
 fprintf(out, "\tleave\n");
 fprintf(out, "\tret\n\n");
}


decompiled_code:
size_t __fastcall emit_return(int a1)
{
char *v1; // rbp

v1 = loc(a1);
if ( a1 != -1 && !in_eax(a1) )
fprintf(out, "\tmov eax, %s\n", v1);
free(v1);
return fwrite("\tjmp .Lfe\n", 1uLL, 0xAuLL, out);
}

canonical_decompiled_code:
size_t __fastcall func12(int a1)
{
char *v1; // rbp

v1 = func3(a1);
if ( a1 != -1 && !func0(a1) )
fprintf(out, "\tmov eax, %s\n", v1);
free(v1);
return fwrite("\tjmp .Lfe\n", 1uLL, 0xAuLL, out);
}

original_code:
void emit_return(int idx)
{
 char *a = loc(idx);
 if (idx != -1) {
  if (!in_eax(idx)) fprintf(out, "\tmov eax, %s\n", a);
 }
 free(a);
 fprintf(out, "\tjmp .Lfe\n");
}

variable_types: idx int


decompiled_code:
void __fastcall emit_call_arg(int a1)
{
char *v1; // rbp

v1 = loc(a1);
if ( in_eax(a1) )
fwrite("\tpush eax\n", 1uLL, 0xAuLL, out);
else
fprintf(out, "\tpush long %s\n", v1);
free(v1);
}

canonical_decompiled_code:
void __fastcall func13(int a1)
{
char *v1; // rbp

v1 = func3(a1);
if ( func0(a1) )
fwrite("\tpush eax\n", 1uLL, 0xAuLL, out);
else
fprintf(out, "\tpush long %s\n", v1);
free(v1);
}

original_code:
void emit_call_arg(int idx)
{
 char *a = loc(idx);
 if (in_eax(idx))
  fprintf(out, "\tpush eax\n");
 else
  fprintf(out, "\tpush long %s\n", a);
 free(a);
}


decompiled_code:
void __fastcall emit_call(const char *a1, int a2, int a3)
{
char *v4; // r12

v4 = loc(a3);
fprintf(out, "\tcall %s\n", a1);
if ( a2 > 0 )
fprintf(out, "\tadd esp, %d\n", (unsigned int)(4 * a2));
fprintf(out, "\tmov %s, eax\n", v4);
free(v4);
set_eax(a3);
}

canonical_decompiled_code:
void __fastcall func14(const char *a1, int a2, int a3)
{
char *v4; // r12

v4 = func3(a3);
fprintf(out, "\tcall %s\n", a1);
if ( a2 > 0 )
fprintf(out, "\tadd esp, %d\n", (unsigned int)(4 * a2));
fprintf(out, "\tmov %s, eax\n", v4);
free(v4);
func2(a3);
}

original_code:
void emit_call(char *name, int fargc, int idx)
{
 char *a = loc(idx);
 fprintf(out, "\tcall %s\n", name);
 if (fargc > 0) fprintf(out, "\tadd esp, %d\n", fargc * 4);
 fprintf(out, "\tmov %s, eax\n", a); free(a);
 set_eax(idx);
}


decompiled_code:
void __fastcall emit_constant(int a1, __int64 a2)
{
char *v2; // rbx

v2 = loc(a1);
fprintf(out, "\tmov %s, long %ld\n", v2, a2);
free(v2);
}

canonical_decompiled_code:
void __fastcall func15(int a1, __int64 a2)
{
char *v2; // rbx

v2 = func3(a1);
fprintf(out, "\tmov %s, long %ld\n", v2, a2);
free(v2);
}

original_code:
void emit_constant(int idx, long val)
{
 char *a = loc(idx);
 fprintf(out, "\tmov %s, long %ld\n", a, val); free(a);
}

variable_types: val long


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

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

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


decompiled_code:
void __fastcall emit_div(__int64 a1, unsigned int a2, int a3)
{
if ( (unsigned __int8)var_type(a1) == 2 || (unsigned __int8)var_type(a2) == 2 )
{
emit_3float("div", a1, a2, a3);
}
else
{
emit_divop("eax", a1, a2, a3);
set_eax(a3);
}
}

canonical_decompiled_code:
void __fastcall func17(__int64 a1, unsigned int a2, int a3)
{
if ( (unsigned __int8)var_type(a1) == 2 || (unsigned __int8)var_type(a2) == 2 )
{
func6("div", a1, a2, a3);
}
else
{
func5("eax", a1, a2, a3);
func2(a3);
}
}

original_code:
void emit_div(int left, int right, int result)
{
 if ((var_type(left) == 2) || (var_type(right) == 2)) {
  emit_3float("div", left, right, result);
  return;
 }
 emit_divop("eax", left, right, result);
 set_eax(result);
}


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


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


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; // r12
char *v7; // rbp
const char *v8; // r15
char v10; // al
const char *v11; // rdx
char v12; // al
const char *v13; // rdx

v6 = loc(a2);
v7 = loc(a3);
switch ( a1 )
{
case 500:
v8 = "jnz";
break;
case 501:
v8 = "jz";
break;
case 502:
v8 = "jge";
break;
case 503:
v8 = "jg";
break;
case 504:
v8 = "jle";
break;
case 505:
v8 = "jl";
break;
default:
v8 = "jmp";
break;
}
if ( (unsigned __int8)var_type(a2) == 2 && (unsigned __int8)var_type(a3) == 1 )
{
v10 = var_type(a2);
v11 = "i";
if ( v10 != 1 )
v11 = (const char *)&unk_D03;
fprintf(out, "\tf%sld long %s\n", v11, v6);
v12 = var_type(a3);
v13 = "i";
if ( v12 != 1 )
v13 = (const char *)&unk_D03;
fprintf(out, "\tf%scom long %s\n", v13, v6);
}
else
{
if ( !in_eax(a2) )
fprintf(out, "\tmov eax, %s\n", v6);
fprintf(out, "\tcmp eax, %s\n", v7);
}
free(v6);
free(v7);
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; // r12
char *v7; // rbp
const char *v8; // r15
char v10; // al
const char *v11; // rdx
char v12; // al
const char *v13; // rdx

v6 = func3(a2);
v7 = func3(a3);
switch ( a1 )
{
case 500:
v8 = "jnz";
break;
case 501:
v8 = "jz";
break;
case 502:
v8 = "jge";
break;
case 503:
v8 = "jg";
break;
case 504:
v8 = "jle";
break;
case 505:
v8 = "jl";
break;
default:
v8 = "jmp";
break;
}
if ( (unsigned __int8)var_type(a2) == 2 && (unsigned __int8)var_type(a3) == 1 )
{
v10 = var_type(a2);
v11 = "i";
if ( v10 != 1 )
v11 = (const char *)&unk_D03;
fprintf(out, "\tf%sld long %s\n", v11, v6);
v12 = var_type(a3);
v13 = "i";
if ( v12 != 1 )
v13 = (const char *)&unk_D03;
fprintf(out, "\tf%scom long %s\n", v13, v6);
}
else
{
if ( !func0(a2) )
fprintf(out, "\tmov eax, %s\n", v6);
fprintf(out, "\tcmp eax, %s\n", v7);
}
free(v6);
free(v7);
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:
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);
}


decompiled_code:
size_t __fastcall emit_asciiz(unsigned int a1, char *a2)
{
char *v2; // rbx
char v3; // dl

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

canonical_decompiled_code:
size_t __fastcall func25(unsigned int a1, char *a2)
{
char *v2; // rbx
char v3; // dl

v2 = a2;
fprintf(out, "LC%d: db ", a1);
v3 = *a2;
if ( *a2 )
{
do
{
++v2;
fprintf(out, "%d, ", (unsigned int)v3);
v3 = *v2;
}
while ( *v2 );
}
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; // r12
char *v3; // rbp

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; // r12
char *v3; // rbp

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

variable_types:
a
char *


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

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; // r12
char *v3; // rbp

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

variable_types:
b
char *


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

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; // r13
char *v3; // r12

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()
{
char *v0; // r12
int v1; // ebp
char v2; // bl
char *result; // rax
char v4[1064]; // [rsp+0h] [rbp-428h] BYREF

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

canonical_decompiled_code:
char *func0()
{
char *v0; // r12
int v1; // ebp
char v2; // bl
char *result; // rax
char v4[1064]; // [rsp+0h] [rbp-428h] BYREF

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

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


decompiled_code:
char *detect_string()
{
char *v0; // rbp
int i; // ebx
char v2; // al
char v3; // dl
char v4; // al
char v5; // dl
char v7[16424]; // [rsp+0h] [rbp-4028h] BYREF

input_consume();
v0 = v7;
for ( i = 0; i != 0x4000; ++i )
{
if ( !(unsigned __int8)input_peek() )
break;
v3 = input_peek();
v2 = v3;
if ( v3 == 34 )
break;
if ( v3 == 92 )
{
input_consume();
v4 = input_peek();
v5 = v4;
if ( v4 == 114 )
{
v2 = 13;
goto LABEL_4;
}
if ( v4 > 114 )
{
v2 = 9;
if ( v5 != 116 )
goto LABEL_13;
}
else
{
v2 = 7;
if ( v5 == 97 )
goto LABEL_4;
if ( v5 != 110 )
{
LABEL_13:
v2 = v5;
goto LABEL_4;
}
v2 = 10;
}
}
LABEL_4:
*v0 = v2;
input_consume();
++v0;
}
if ( (unsigned __int8)input_peek() == 34 )
input_consume();
v7[i] = 0;
return strdup(v7);
}

canonical_decompiled_code:
char *func1()
{
char *v0; // rbp
int i; // ebx
char v2; // al
char v3; // dl
char v4; // al
char v5; // dl
char v7[16424]; // [rsp+0h] [rbp-4028h] BYREF

input_consume();
v0 = v7;
for ( i = 0; i != 0x4000; ++i )
{
if ( !(unsigned __int8)input_peek() )
break;
v3 = input_peek();
v2 = v3;
if ( v3 == 34 )
break;
if ( v3 == 92 )
{
input_consume();
v4 = input_peek();
v5 = v4;
if ( v4 == 114 )
{
v2 = 13;
goto LABEL_4;
}
if ( v4 > 114 )
{
v2 = 9;
if ( v5 != 116 )
goto LABEL_13;
}
else
{
v2 = 7;
if ( v5 == 97 )
goto LABEL_4;
if ( v5 != 110 )
{
LABEL_13:
v2 = v5;
goto LABEL_4;
}
v2 = 10;
}
}
LABEL_4:
*v0 = v2;
input_consume();
++v0;
}
if ( (unsigned __int8)input_peek() == 34 )
input_consume();
v7[i] = 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 lex_peek()
{
if ( !lex_token_type )
detect_token();
return (unsigned int)lex_token_type;
}

canonical_decompiled_code:
__int64 func6()
{
if ( !lex_token_type )
func4();
return (unsigned int)lex_token_type;
}

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


decompiled_code:
int lex_consume()
{
int result; // eax

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

canonical_decompiled_code:
int func7()
{
int result; // eax

if ( !lex_token_type )
func6();
if ( lex_token_string )
free(lex_token_string);
result = printf("consuming(%d)\n", (unsigned int)lex_token_type);
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; // ebp
void *v5; // rdi

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

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

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

strings = malloc(0x2000uLL);
result = 0LL;
memset(strings, 0, 0x2000uLL);
return result;
}

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

strings = malloc(0x2000uLL);
result = 0LL;
memset(strings, 0, 0x2000uLL);
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; // rdx
__int64 result; // rax

v1 = strings;
result = 0LL;
while ( *v1 )
{
result = (unsigned int)(result + 1);
++v1;
if ( (_DWORD)result == 1024 )
return 0xFFFFFFFFLL;
}
*((_QWORD *)strings + (int)result) = a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
_QWORD *v1; // rdx
__int64 result; // rax

v1 = strings;
result = 0LL;
while ( *v1 )
{
result = (unsigned int)(result + 1);
++v1;
if ( (_DWORD)result == 1024 )
return 0xFFFFFFFFLL;
}
*((_QWORD *)strings + (int)result) = a1;
return result;
}

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()
{
variables = malloc(0x8000uLL);
return memset(variables, 0, 0x8000uLL);
}

canonical_decompiled_code:
void *func0()
{
variables = malloc(0x8000uLL);
return memset(variables, 0, 0x8000uLL);
}

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; // ecx

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; // ecx

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; // eax
const char **v2; // rbx
unsigned int i; // ebp

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

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

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

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

variable_types:
name
char *


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

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

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

if ( a1 && (unsigned int)func6(a1) != -1 )
{
printf("redeclaring variable '%s'\n", a1);
v3 = -1;
}
else
{
v2 = variables;
v3 = 0;
while ( *v2 )
{
++v3;
v2 += 32;
if ( v3 == 1024 )
return (unsigned int)-1;
}
if ( a1 )
printf("declared variable '%s' (slot %d)\n", a1, v3);
else
printf("putting temporary in slot %d\n", v3);
v4 = (char *)variables + 32 * (int)v3;
*((_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()
{
functions = malloc(0x4000uLL);
return memset(functions, 0, 0x4000uLL);
}

canonical_decompiled_code:
void *func0()
{
functions = malloc(0x4000uLL);
return memset(functions, 0, 0x4000uLL);
}

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; // r13

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

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

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

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
unsigned int v6; // ecx
_QWORD *v8; // rdx
int v9; // eax
char *v10; // rax
const char *v11; // rsi

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

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

v5 = func2(a1);
v6 = v5;
if ( v5 == -1 )
{
v8 = functions;
v9 = 0;
while ( *v8 )
{
++v9;
v8 += 2;
if ( v9 == 1024 )
return v6;
}
v10 = (char *)functions + 16 * v9;
*(_QWORD *)v10 = a1;
*((_DWORD *)v10 + 2) = a2;
v10[12] = a3;
v11 = "float";
if ( a3 != 2 )
v11 = "int";
printf("declared %s function '%s' with %d arguments\n", v11, a1, a2);
v6 = 0;
}
else if ( v5 == a2 )
{
v6 = 0;
}
else
{
printf("redeclaring function '%s'\n", a1);
v6 = -1;
}
return 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; // r13

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

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

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

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

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; // rsi
unsigned int v3; // edx

v2 = *_ctype_b_loc();
v3 = 0;
while ( (v2[*a1] & 0x400) == 0 )
v3 += *a1++ == 9;
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1)
{
const unsigned __int16 *v2; // rsi
unsigned int v3; // edx

v2 = *_ctype_b_loc();
v3 = 0;
while ( (v2[*a1] & 0x400) == 0 )
v3 += *a1++ == 9;
return v3;
}

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; // rdx
int i; // eax
__int64 result; // rax

v1 = menu;
if ( a1 > 0 )
{
v1 = *(_QWORD *)(menu + 16);
for ( i = 0; i != a1; ++i )
;
}
if ( !v1 )
return 0LL;
LODWORD(result) = 0;
do
{
v1 = *(_QWORD *)(v1 + 48);
result = (unsigned int)(result + 1);
}
while ( v1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
__int64 v1; // rdx
int i; // eax
__int64 result; // rax

v1 = menu;
if ( a1 > 0 )
{
v1 = *(_QWORD *)(menu + 16);
for ( i = 0; i != a1; ++i )
;
}
if ( !v1 )
return 0LL;
LODWORD(result) = 0;
do
{
v1 = *(_QWORD *)(v1 + 48);
result = (unsigned int)(result + 1);
}
while ( v1 );
return result;
}

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)
{
unsigned __int64 v1; // rbp
int v2; // er13
size_t result; // rax
char v4; // bl

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

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

v1 = 0LL;
v2 = 0;
while ( 1 )
{
result = strlen(s);
if ( v2 > 1 || result <= v1 )
break;
v4 = s[v1];
if ( v4 == 34 || v4 == 39 )
++v2;
s[v1++] = (*_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();
return draw(argc, argv);
}

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

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

if ( !a1 )
return 0LL;
LODWORD(result) = 0;
do
{
a1 = *(_QWORD *)(a1 + 48);
result = (unsigned int)(result + 1);
}
while ( a1 );
return result;
}

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

if ( !a1 )
return 0LL;
LODWORD(result) = 0;
do
{
a1 = *(_QWORD *)(a1 + 48);
result = (unsigned int)(result + 1);
}
while ( a1 );
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; }


decompiled_code:
__int64 __fastcall days_in_month(int a1, int a2)
{
__int64 result; // rax

result = 30LL;
if ( (a1 & 0xFFFFFFFD) != 4 && (a1 & 0xFFFFFFFD) != 9 )
{
result = 31LL;
if ( a1 == 2 )
{
if ( a2 == 100 * (a2 / 100) || (result = 29LL, (a2 & 3) != 0) )
result = (unsigned int)(a2 == 400 * (a2 / 400)) + 28;
}
}
return result;
}

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

result = 30LL;
if ( (a1 & 0xFFFFFFFD) != 4 && (a1 & 0xFFFFFFFD) != 9 )
{
result = 31LL;
if ( a1 == 2 )
{
if ( a2 == 100 * (a2 / 100) || (result = 29LL, (a2 & 3) != 0) )
result = (unsigned int)(a2 == 400 * (a2 / 400)) + 28;
}
}
return result;
}

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

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 + *v2 * a2;
if ( v5 > 9 )
{
v3 = v5 / 10;
*v2 = v5 % 10;
}
else
{
*v2 = v5;
v3 = 0;
}
result = v2 - 1;
if ( v2 == a1 )
break;
--v2;
}
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 + *v2 * a2;
if ( v5 > 9 )
{
v3 = v5 / 10;
*v2 = v5 % 10;
}
else
{
*v2 = v5;
v3 = 0;
}
result = v2 - 1;
if ( v2 == a1 )
break;
--v2;
}
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)
{
char *v3; // rbx
char *v4; // rax
int i; // ebp
__int64 v6; // rsi
int v8[160]; // [rsp+0h] [rbp-298h] BYREF
char v9[24]; // [rsp+280h] [rbp-18h] BYREF

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

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx
char *v4; // rax
int i; // ebp
__int64 v6; // rsi
int v8[160]; // [rsp+0h] [rbp-298h] BYREF
char v9[24]; // [rsp+280h] [rbp-18h] BYREF

v3 = (char *)v8;
v4 = (char *)v8;
do
{
*(_DWORD *)v4 = 0;
v4 += 4;
}
while ( v4 != v9 );
v8[159] = 1;
for ( i = 2; i != 100; ++i )
func7(v8, i);
LODWORD(v6) = 0;
do
{
v6 = (unsigned int)(*(_DWORD *)v3 + v6);
v3 += 4;
}
while ( v3 != v9 );
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 i; // er14
__int64 v3; // rax
__int64 v4; // rbx
__int64 v5; // r12
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v10; // rax

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

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 *a1, unsigned int a2)
{
unsigned int i; // er14
__int64 v3; // rax
__int64 v4; // rbx
__int64 v5; // r12
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v10; // rax

for ( i = 0; ; ++i )
{
v3 = bi_copy(*a1);
v4 = bi_int_divide(v3, a2);
v5 = bi_copy(*a1);
v6 = bi_copy(v4);
v7 = bi_int_multiply(v6, a2);
if ( (unsigned int)bi_compare(v7, v5) )
break;
bi_free(*a1);
*a1 = v4;
}
if ( i )
{
v10 = int_to_bi(a2);
func0(v10, i);
}
v8 = int_to_bi(a2);
return (int)bi_compare(v4, 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 v5; // rbx
int v6; // ebp
unsigned int i; // ebx
__int64 v8; // rbx
__int64 v9; // rax
__int64 v10; // rax
__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
{
v5 = 0LL;
while ( 1 )
{
v6 = v5;
if ( !test_fact(v11, low_primes[v5]) )
break;
if ( ++v5 == 9592 )
{
for ( i = 6 * ((low_primes[v6] + 5) / 6) - 1; test_fact(v11, i) && test_fact(v11, i + 2); i += 6 )
;
break;
}
}
v8 = bi_1;
v9 = bi_copy(v11[0]);
if ( (unsigned int)bi_compare(v9, v8) )
{
v10 = bi_copy(v11[0]);
print_fact(v10, 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 v5; // rbx
int v6; // ebp
unsigned int i; // ebx
__int64 v8; // rbx
__int64 v9; // rax
__int64 v10; // rax
__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
{
v5 = 0LL;
while ( 1 )
{
v6 = v5;
if ( !func1(v11, low_primes[v5]) )
break;
if ( ++v5 == 9592 )
{
for ( i = 6 * ((low_primes[v6] + 5) / 6) - 1; func1(v11, i) && func1(v11, i + 2); i += 6 )
;
break;
}
}
v8 = bi_1;
v9 = bi_copy(v11[0]);
if ( (unsigned int)bi_compare(v9, v8) )
{
v10 = bi_copy(v11[0]);
func0(v10, 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; // r12
size_t v2; // rax
size_t v3; // rbx
char v4; // al
__int64 v5; // rbx
size_t v6; // rax
__int64 v7; // rax
int result; // eax
__int64 v9; // rbx
__int64 v10; // r12
__int64 v11; // rax
__int64 v12; // rbp
__int64 v13; // rax
__int64 v14; // rax
__int64 v15; // rax
__int64 v16; // rax
__int64 v17; // rax
__int64 v18; // rbp
__int64 v19; // rax

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

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

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

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)
{
char **v3; // rbx
char v4[1032]; // [rsp+0h] [rbp-408h] BYREF

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

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

argv0 = (__int64)*argv;
bi_initialize(argc, argv, envp);
bi_no_check();
if ( argc == 1 )
{
while ( fgets(v4, 1000, stdin) )
func3(v4);
}
else if ( argc > 1 )
{
v3 = (char **)(argv + 1);
do
func3(*v3++);
while ( v3 != (char **)&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; // edx
unsigned int v4; // eax
__int64 v5; // rdi

v2 = a1 % a2;
if ( !(a1 % a2) )
return (unsigned int)a2;
v4 = a1 % a2;
if ( a2 <= v2 )
v4 = a2;
v5 = (unsigned int)v2;
if ( a2 >= v2 )
v5 = (unsigned int)a2;
return gcd(v5, v4);
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, int a2)
{
int v2; // edx
unsigned int v4; // eax
__int64 v5; // rdi

v2 = a1 % a2;
if ( !(a1 % a2) )
return (unsigned int)a2;
v4 = a1 % a2;
if ( a2 <= v2 )
v4 = a2;
v5 = (unsigned int)v2;
if ( a2 >= v2 )
v5 = (unsigned int)a2;
return func8(v5, v4);
}

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;
prev_val = bi_0;
result = (char *)&vars;
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;
prev_val = bi_0;
result = (char *)&vars;
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

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

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

bi_free(prev_val);
v0 = (char *)&vars;
do
{
bi_free(*(_QWORD *)v0);
v0 += 8;
}
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();
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)
{
_DWORD *v3; // rax

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

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

if ( a2 <= 0 )
return 0LL;
v3 = a1;
while ( *v3 != a3 )
{
if ( ++v3 == &a1[a2 - 1 + 1] )
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


factorial

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

switch ( a1 )
{
case 0u:
case 1u:
result = 1LL;
break;
case 2u:
result = a1;
break;
case 3u:
result = 6LL;
break;
case 4u:
result = 24LL;
break;
case 5u:
result = 120LL;
break;
case 6u:
result = 720LL;
break;
case 7u:
result = 5040LL;
break;
case 8u:
result = 40320LL;
break;
case 9u:
result = 362880LL;
break;
default:
result = a1 * (unsigned int)factorial(a1 - 1);
break;
}
return result;
}

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

switch ( a1 )
{
case 0u:
case 1u:
result = 1LL;
break;
case 2u:
result = a1;
break;
case 3u:
result = 6LL;
break;
case 4u:
result = 24LL;
break;
case 5u:
result = 120LL;
break;
case 6u:
result = 720LL;
break;
case 7u:
result = 5040LL;
break;
case 8u:
result = 40320LL;
break;
case 9u:
result = 362880LL;
break;
default:
result = a1 * (unsigned int)func7(a1 - 1);
break;
}
return result;
}

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


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
unsigned int v4; // er13
int v5; // ebx
__int64 v6; // rbp
int v8[70]; // [rsp+0h] [rbp-118h] BYREF

v3 = 0;
v4 = 0;
do
{
v8[0] = v3;
v5 = sum_digits_factorials(v3);
v6 = 1LL;
while ( !(unsigned int)has_factorials(v8, v6, v5) )
{
v8[v6] = v5;
v5 = sum_digits_factorials(v5);
if ( ++v6 == 60 )
{
++v4;
break;
}
}
++v3;
}
while ( v3 != 1000000 );
printf("%d\n", v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
unsigned int v4; // er13
int v5; // ebx
__int64 v6; // rbp
int v8[70]; // [rsp+0h] [rbp-118h] BYREF

v3 = 0;
v4 = 0;
do
{
v8[0] = v3;
v5 = func8(v3);
v6 = 1LL;
while ( !(unsigned int)func9(v8, v6, v5) )
{
v8[v6] = v5;
v5 = func8(v5);
if ( ++v6 == 60 )
{
++v4;
break;
}
}
++v3;
}
while ( v3 != 1000000 );
printf("%d\n", v4);
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]


duplicate

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

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

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

v1 = a1 + 304;
LODWORD(result) = 0;
while ( 1 )
{
v3 = result + 2 * *v1;
if ( v3 > 9 )
{
result = (unsigned int)(v3 / 10);
*v1 = v3 % 10;
}
else
{
*v1 = v3;
result = 0LL;
}
if ( v1 == a1 )
break;
--v1;
}
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; // rbx
char *v4; // rax
int v5; // ebp
__int64 v6; // rsi
int v8[305]; // [rsp+0h] [rbp-4E8h] BYREF
char v9[36]; // [rsp+4C4h] [rbp-24h] BYREF

v3 = (char *)v8;
v4 = (char *)v8;
do
{
*(_DWORD *)v4 = 0;
v4 += 4;
}
while ( v4 != v9 );
v8[304] = 1;
v5 = 1000;
do
{
duplicate(v8);
--v5;
}
while ( v5 );
v6 = 0LL;
do
{
v6 += *(int *)v3;
v3 += 4;
}
while ( v3 != v9 );
printf("%llu\n", v6);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx
char *v4; // rax
int v5; // ebp
__int64 v6; // rsi
int v8[305]; // [rsp+0h] [rbp-4E8h] BYREF
char v9[36]; // [rsp+4C4h] [rbp-24h] BYREF

v3 = (char *)v8;
v4 = (char *)v8;
do
{
*(_DWORD *)v4 = 0;
v4 += 4;
}
while ( v4 != v9 );
v8[304] = 1;
v5 = 1000;
do
{
func7(v8);
--v5;
}
while ( v5 );
v6 = 0LL;
do
{
v6 += *(int *)v3;
v3 += 4;
}
while ( v3 != v9 );
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 result; // rax

switch ( a1 )
{
case 2:
result = 0LL;
break;
case 3:
result = 1LL;
break;
case 5:
result = 2LL;
break;
case 7:
result = 3LL;
break;
case 11:
result = 4LL;
break;
case 13:
result = 5LL;
break;
case 17:
result = 6LL;
break;
case 19:
result = 7LL;
break;
default:
result = 0xFFFFFFFFLL;
break;
}
return result;
}

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

switch ( a1 )
{
case 2:
result = 0LL;
break;
case 3:
result = 1LL;
break;
case 5:
result = 2LL;
break;
case 7:
result = 3LL;
break;
case 11:
result = 4LL;
break;
case 13:
result = 5LL;
break;
case 17:
result = 6LL;
break;
case 19:
result = 7LL;
break;
default:
result = 0xFFFFFFFFLL;
break;
}
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


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


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
_DWORD *v4; // rdi
__int64 i; // rax
int v6; // edx
int v7; // eax
unsigned int v8; // er12
int v9; // ebx
int v10; // edx
int j; // eax
__int64 v13[7]; // [rsp+0h] [rbp-38h]

v13[0] = 0LL;
v13[1] = 0LL;
v13[2] = 0LL;
v13[3] = 0LL;
v3 = 20;
do
{
if ( (unsigned int)is_prime(v3) )
{
v7 = position(v3);
if ( !*((_DWORD *)v13 + v7) )
*((_DWORD *)v13 + v7) = 1;
}
else
{
v4 = divisors(v3);
for ( i = 0LL; i != 8; ++i )
{
v6 = v4[i];
if ( v6 > *(_DWORD *)((char *)v13 + i * 4) )
*(_DWORD *)((char *)v13 + i * 4) = v6;
}
free(v4);
}
--v3;
}
while ( v3 );
v8 = 1;
v9 = 20;
do
{
if ( (unsigned int)is_prime(v9) )
{
v10 = *((_DWORD *)v13 + (int)position(v9));
if ( v10 > 0 )
{
for ( j = 0; j != v10; ++j )
v8 *= v9;
}
}
--v9;
}
while ( v9 );
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 letters_in_number(unsigned __int64 a1)
{
__int64 result; // rax
int v2; // ebx
__int64 v3; // rdx
int v4; // ebp
__int64 v5; // rdi
int v6; // ebp
int v7; // eax
int v8; // er12

result = (unsigned int)a1;
if ( (_DWORD)a1 )
{
v2 = a1;
result = 3LL;
if ( (unsigned int)(a1 - 1) > 1 )
{
if ( (_DWORD)a1 == 3 )
{
result = 5LL;
}
else
{
result = 4LL;
if ( (unsigned int)(a1 - 4) > 1 )
{
if ( (_DWORD)a1 == 6 )
return 3LL;
result = 5LL;
if ( (unsigned int)(a1 - 7) > 1 )
{
if ( (_DWORD)a1 == 9 )
return 4LL;
if ( (_DWORD)a1 == 10 )
return 3LL;
result = 6LL;
if ( (unsigned int)(a1 - 11) > 1 )
{
result = 8LL;
if ( (unsigned int)(a1 - 13) > 1 )
{
result = 7LL;
if ( (unsigned int)(a1 - 15) > 1 )
{
if ( (_DWORD)a1 == 17 )
return 9LL;
result = 8LL;
if ( (unsigned int)(a1 - 18) > 1 )
{
if ( (_DWORD)a1 == 30 || (_DWORD)a1 == 20 )
return 6LL;
if ( (unsigned int)a1 > 0x3C )
{
switch ( (_DWORD)a1 )
{
case 0x50:
case 0x46:
return 7LL;
case 0x5A:
return 6LL;
case 0x3E8:
return 11LL;
}
if ( (int)a1 <= 99 )
{
v4 = 0;
}
else
{
v7 = letters_in_number((unsigned int)((int)a1 / 100));
v8 = 100 * ((int)a1 / 100);
v5 = (unsigned int)((int)a1 % 100);
v4 = v7 + 10;
if ( v2 == v8 )
{
v4 = v7 + 7;
return v4 + (unsigned int)letters_in_number(v5);
}
}
LABEL_18:
v5 = (unsigned int)(v2 % 100);
if ( (int)v5 > 19 )
{
v6 = letters_in_number((unsigned int)(10 * (v2 / 10 % 10))) + v4;
return v6 + (unsigned int)letters_in_number((unsigned int)(v2 % 10));
}
return v4 + (unsigned int)letters_in_number(v5);
}
result = 5LL;
v3 = 0x1004010000000000LL;
v4 = 0;
if ( !_bittest64(&v3, a1) )
goto LABEL_18;
}
}
}
}
}
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned __int64 a1)
{
__int64 result; // rax
int v2; // ebx
__int64 v3; // rdx
int v4; // ebp
__int64 v5; // rdi
int v6; // ebp
int v7; // eax
int v8; // er12

result = (unsigned int)a1;
if ( (_DWORD)a1 )
{
v2 = a1;
result = 3LL;
if ( (unsigned int)(a1 - 1) > 1 )
{
if ( (_DWORD)a1 == 3 )
{
result = 5LL;
}
else
{
result = 4LL;
if ( (unsigned int)(a1 - 4) > 1 )
{
if ( (_DWORD)a1 == 6 )
return 3LL;
result = 5LL;
if ( (unsigned int)(a1 - 7) > 1 )
{
if ( (_DWORD)a1 == 9 )
return 4LL;
if ( (_DWORD)a1 == 10 )
return 3LL;
result = 6LL;
if ( (unsigned int)(a1 - 11) > 1 )
{
result = 8LL;
if ( (unsigned int)(a1 - 13) > 1 )
{
result = 7LL;
if ( (unsigned int)(a1 - 15) > 1 )
{
if ( (_DWORD)a1 == 17 )
return 9LL;
result = 8LL;
if ( (unsigned int)(a1 - 18) > 1 )
{
if ( (_DWORD)a1 == 30 || (_DWORD)a1 == 20 )
return 6LL;
if ( (unsigned int)a1 > 0x3C )
{
switch ( (_DWORD)a1 )
{
case 0x50:
case 0x46:
return 7LL;
case 0x5A:
return 6LL;
case 0x3E8:
return 11LL;
}
if ( (int)a1 <= 99 )
{
v4 = 0;
}
else
{
v7 = func7((unsigned int)((int)a1 / 100));
v8 = 100 * ((int)a1 / 100);
v5 = (unsigned int)((int)a1 % 100);
v4 = v7 + 10;
if ( v2 == v8 )
{
v4 = v7 + 7;
return v4 + (unsigned int)func7(v5);
}
}
LABEL_18:
v5 = (unsigned int)(v2 % 100);
if ( (int)v5 > 19 )
{
v6 = func7((unsigned int)(10 * (v2 / 10 % 10))) + v4;
return v6 + (unsigned int)func7((unsigned int)(v2 % 10));
}
return v4 + (unsigned int)func7(v5);
}
result = 5LL;
v3 = 0x1004010000000000LL;
v4 = 0;
if ( !_bittest64(&v3, a1) )
goto LABEL_18;
}
}
}
}
}
}
}
}
}
return result;
}

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; // ebx
__int64 v4; // rbp

v3 = 1;
v4 = 0LL;
do
v4 += (int)letters_in_number(v3++);
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; // ebx
__int64 v4; // rbp

v3 = 1;
v4 = 0LL;
do
v4 += (int)func7(v3++);
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(signed int a1)
{
unsigned int v1; // ebx
int v3; // eax
int v4; // ecx
char *v5; // rdx
__int64 v6; // rax
char s[15]; // [rsp+9h] [rbp-Fh] BYREF

v1 = a1 % 11;
if ( a1 % 11 )
return 0;
v3 = sprintf(s, "%d", (unsigned int)a1);
v4 = v3 / 2;
if ( v3 <= 1 )
return 1;
v5 = &s[v3];
v6 = 0LL;
while ( s[v6] == *(v5 - 1) )
{
++v6;
--v5;
if ( v4 <= (int)v6 )
return 1;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func7(signed int a1)
{
unsigned int v1; // ebx
int v3; // eax
int v4; // ecx
char *v5; // rdx
__int64 v6; // rax
char s[15]; // [rsp+9h] [rbp-Fh] BYREF

v1 = a1 % 11;
if ( a1 % 11 )
return 0;
v3 = sprintf(s, "%d", (unsigned int)a1);
v4 = v3 / 2;
if ( v3 <= 1 )
return 1;
v5 = &s[v3];
v6 = 0LL;
while ( s[v6] == *(v5 - 1) )
{
++v6;
--v5;
if ( v4 <= (int)v6 )
return 1;
}
return v1;
}

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