original_code:
int main1() {
    double *ans, *evecs, *evals ;
    double X[] = {
 3, 1, 3,
 1, 5, 9,
 2, 6, 5,
 1.3, 2.9, 0.01
    };
    double Y[] = {
 0.5, .998, 12.1,
 11.2, 7.3, 8.995
    } ;
    double Z[] = {
 1, 2, 3,
 4, 5, 6,
 7, 8, 9
    } ;
    printf("X\n") ;
    write_matrix_double(X, stdout, 3, 4, "%.3lf ") ;
    putchar('\n') ;
    ans = XTX(X, 3, 4, 1.0) ;
    printf("XTX\n") ;
    write_matrix_double(ans, stdout, 4, 4, "%.5lf ") ;
    free(ans) ;
    putchar('\n') ;
    printf("t(X) %%*%% X\n") ;
    ans = matprod(X, X, 1, 0, 3, 4, 3, 4, 1.0) ;
    write_matrix_double(ans, stdout, 4, 4, "%.5lf ") ;
    free(ans) ;
    printf("Y\n") ;
    write_matrix_double(Y, stdout, 3, 2, "%.3lf ") ;
    putchar('\n') ;
    printf("t(X) %%*%% Y\n") ;
    ans = matprod(X, Y, 1, 0, 3, 4, 3, 2, 1.0) ;
    write_matrix_double(ans, stdout, 4, 2, "%.5lf ") ;
    printf("Z\n") ;
    write_matrix_double(Z, stdout, 3, 3, "%.3lf ") ;
    evals = (double *) malloc_dan((3) * sizeof(double)) ;
    evecs = (double *) malloc_dan((3*3) * sizeof(double)) ;
    eigen(Z, 3, 3, 0, evals, evecs) ;
    print_stdout("eigenvalues of Z\n\n") ;
    print_stdout("eigenvectors of Z\n\n") ;
    return 0 ;
}

canonical_original_code:
int main1() {
    double *ans; double *evecs; double *evals;
    double X[] = {
 3, 1, 3,
 1, 5, 9,
 2, 6, 5,
 1.3, 2.9, 0.01
    };
    double Y[] = {
 0.5, .998, 12.1,
 11.2, 7.3, 8.995
    };
    double Z[] = {
 1, 2, 3,
 4, 5, 6,
 7, 8, 9
    };
    printf("X\n") ;
    write_matrix_double(X, stdout, 3, 4, "%.3lf ") ;
    putchar('\n') ;
    ans = XTX(X, 3, 4, 1.0) ;
    printf("XTX\n") ;
    write_matrix_double(ans, stdout, 4, 4, "%.5lf ") ;
    free(ans) ;
    putchar('\n') ;
    printf("t(X) %%*%% X\n") ;
    ans = matprod(X, X, 1, 0, 3, 4, 3, 4, 1.0) ;
    write_matrix_double(ans, stdout, 4, 4, "%.5lf ") ;
    free(ans) ;
    printf("Y\n") ;
    write_matrix_double(Y, stdout, 3, 2, "%.3lf ") ;
    putchar('\n') ;
    printf("t(X) %%*%% Y\n") ;
    ans = matprod(X, Y, 1, 0, 3, 4, 3, 2, 1.0) ;
    write_matrix_double(ans, stdout, 4, 2, "%.5lf ") ;
    printf("Z\n") ;
    write_matrix_double(Z, stdout, 3, 3, "%.3lf ") ;
    evals = (double *) malloc_dan((3) * sizeof(double)) ;
    evecs = (double *) malloc_dan((3*3) * sizeof(double)) ;
    eigen(Z, 3, 3, 0, evals, evecs) ;
    print_stdout("eigenvalues of Z\n\n") ;
    print_stdout("eigenvectors of Z\n\n") ;
    return 0 ;
}

variable_types:
evecs
double *

variable_types:
evals
double *

variable_types:
X
double []

variable_types:
Y
double []

variable_types:
Z
double []


repo: danidomi/fteqcc

decompiled_code:
void __fastcall Hash_InitTable(__int64 a1, int a2, __int64 a3)
{
*(_DWORD *)a1 = a2;
*(_QWORD *)(a1 + 8) = a3;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, int a2, __int64 a3)
{
*(_DWORD *)a1 = a2;
*(_QWORD *)(a1 + 8) = a3;
}

original_code:
void Hash_InitTable(hashtable_t *table, unsigned int numbucks, void *mem)
{
 table->numbuckets = numbucks;
 table->bucket = (bucket_t **)mem;
}

canonical_original_code:
void Hash_InitTable(struct hashtable_s *table, unsigned int numbucks, void *mem)
{
 table->numbuckets = numbucks;
 table->bucket = (struct bucket_s **)mem;
}

variable_types: struct hashtable_s { unsigned int numbuckets; struct bucket_s { void *data; union { char *string; unsigned int value; } key; struct bucket_s *next; } **bucket; } *

variable_types:
numbucks
unsigned int

variable_types:
mem
void *

return_type: void

user_defined_types: struct hashtable_s { unsigned int numbuckets; struct bucket_s **bucket; }


decompiled_code:
__int64 __fastcall Hash_Key(_BYTE *a1, unsigned int a2)
{
int v2; // edx
unsigned int v3; // eax
unsigned int v4; // ecx
int v5; // eax

v2 = (char)*a1;
if ( !*a1 )
return 0LL;
v3 = 0;
do
{
++a1;
v4 = v3;
v5 = v2 + 8 * v3 + v3;
v2 = (char)*a1;
v3 = (v4 >> 28) + v5;
}
while ( *a1 );
return v3 % a2;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1, unsigned int a2)
{
int v2; // edx
unsigned int v3; // eax
unsigned int v4; // ecx
int v5; // eax

v2 = (char)*a1;
if ( !*a1 )
return 0LL;
v3 = 0;
do
{
++a1;
v4 = v3;
v5 = v2 + 8 * v3 + v3;
v2 = (char)*a1;
v3 = (v4 >> 28) + v5;
}
while ( *a1 );
return v3 % a2;
}

original_code:
unsigned int Hash_Key(const char *name, unsigned int modulus)
{
 unsigned int key;
 for (key=0;*name; name++)
  key += ((key<<3) + (key>>28) + *name);
 return (key%modulus);
}

canonical_original_code:
unsigned int Hash_Key(char *name, unsigned int modulus)
{
 unsigned int key;
 for (key=0;*name; name++)
  key += ((key<<3) + (key>>28) + *name);
 return (key%modulus);
}

variable_types:
name
char *

variable_types:
modulus
unsigned int

variable_types:
key
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall Hash_KeyInsensative(char *a1, unsigned int a2)
{
char v2; // dl
unsigned int v4; // eax
int v5; // esi
unsigned int v6; // er8

v2 = *a1;
if ( !*a1 )
return 0LL;
v4 = 0;
do
{
while ( 1 )
{
v5 = v2;
v6 = v4 >> 28;
if ( (unsigned __int8)(v2 - 65) > 0x19u )
break;
v2 = *++a1;
v4 = v5 + v6 + 9 * v4 + 32;
if ( !v2 )
return v4 % a2;
}
v2 = *++a1;
v4 += v5 + v6 + 8 * v4;
}
while ( v2 );
return v4 % a2;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1, unsigned int a2)
{
char v2; // dl
unsigned int v4; // eax
int v5; // esi
unsigned int v6; // er8

v2 = *a1;
if ( !*a1 )
return 0LL;
v4 = 0;
do
{
while ( 1 )
{
v5 = v2;
v6 = v4 >> 28;
if ( (unsigned __int8)(v2 - 65) > 0x19u )
break;
v2 = *++a1;
v4 = v5 + v6 + 9 * v4 + 32;
if ( !v2 )
return v4 % a2;
}
v2 = *++a1;
v4 += v5 + v6 + 8 * v4;
}
while ( v2 );
return v4 % a2;
}

original_code:
unsigned int Hash_KeyInsensative(const char *name, unsigned int modulus)
{
 unsigned int key;
 for (key=0;*name; name++)
 {
  if (*name >= 'A' && *name <= 'Z')
   key += ((key<<3) + (key>>28) + (*name-'A'+'a'));
  else
   key += ((key<<3) + (key>>28) + *name);
 }
 return (key%modulus);
}

canonical_original_code:
unsigned int Hash_KeyInsensative(char *name, unsigned int modulus)
{
 unsigned int key;
 for (key=0;*name; name++)
 {
  if (*name >= 'A' && *name <= 'Z')
   key += ((key<<3) + (key>>28) + (*name-'A'+'a'));
  else
   key += ((key<<3) + (key>>28) + *name);
 }
 return (key%modulus);
}


decompiled_code:
__int64 __fastcall Hash_AddKey(__int64 a1, unsigned int a2, __int64 a3, __int64 a4)
{
unsigned int v5; // edx
__int64 v6; // rax
_QWORD *v7; // rax

v5 = a2 % *(_DWORD *)a1;
v6 = *(_QWORD *)(a1 + 8);
*(_QWORD *)a4 = a3;
*(_DWORD *)(a4 + 8) = a2;
v7 = (_QWORD *)(v6 + 8LL * v5);
*(_QWORD *)(a4 + 16) = *v7;
*v7 = a4;
return a4;
}

original_code:
void *Hash_AddKey(hashtable_t *table, unsigned int key, void *data, bucket_t *buck)
{
 unsigned int bucknum = key%table->numbuckets;
 buck->data = data;
 buck->key.value = key;
 buck->next = table->bucket[bucknum];
 table->bucket[bucknum] = buck;
 return buck;
}

canonical_original_code:
void *Hash_AddKey(struct hashtable_s *table, unsigned int key, void *data, struct bucket_s *buck)
{
 unsigned int bucknum = key%table->numbuckets;
 buck->data = data;
 buck->key.value = key;
 buck->next = table->bucket[bucknum];
 table->bucket[bucknum] = buck;
 return buck;
}

variable_types:
data
void *

variable_types:
buck
struct bucket_s *

variable_types:
bucknum
unsigned int

return_type: void *

user_defined_types: struct bucket_s { void *data; union { char *string; unsigned int value; } key; struct bucket_s *next; }


original_code:
void Hash_Remove(hashtable_t *table, const char *name)
{
 unsigned int bucknum = Hash_Key(name, table->numbuckets);
 bucket_t *buck;
 buck = table->bucket[bucknum];
 if (!(((*name)!=(*buck->key.string)) || strcmp(name+1,buck->key.string+1)))
 {
  table->bucket[bucknum] = buck->next;
  return;
 }
 while(buck->next)
 {
  if (!(((*name)!=(*buck->next->key.string)) || strcmp(name+1,buck->next->key.string+1)))
  {
   buck->next = buck->next->next;
   return;
  }
  buck = buck->next;
 }
 return;
}

canonical_original_code:
void Hash_Remove(struct hashtable_s *table, char *name)
{
 unsigned int bucknum = Hash_Key(name, table->numbuckets);
 struct bucket_s *buck;
 buck = table->bucket[bucknum];
 if (!(((*name)!=(*buck->key.string)) || strcmp(name+1,buck->key.string+1)))
 {
  table->bucket[bucknum] = buck->next;
  return;
 }
 while(buck->next)
 {
  if (!(((*name)!=(*buck->next->key.string)) || strcmp(name+1,buck->next->key.string+1)))
  {
   buck->next = buck->next->next;
   return;
  }
  buck = buck->next;
 }
 return;
}

variable_types: struct bucket_s { void *data; union { char *string; unsigned int value; } key; struct bucket_s *next; } *


original_code:
void Hash_RemoveData(hashtable_t *table, const char *name, void *data)
{
 unsigned int bucknum = Hash_Key(name, table->numbuckets);
 bucket_t *buck;
 buck = table->bucket[bucknum];
 if (buck->data == data)
  if (!(((*name)!=(*buck->key.string)) || strcmp(name+1,buck->key.string+1)))
  {
   table->bucket[bucknum] = buck->next;
   return;
  }
 while(buck->next)
 {
  if (buck->next->data == data)
   if (!(((*name)!=(*buck->next->key.string)) || strcmp(name+1,buck->next->key.string+1)))
   {
    buck->next = buck->next->next;
    return;
   }
  buck = buck->next;
 }
 return;
}

canonical_original_code:
void Hash_RemoveData(struct hashtable_s *table, char *name, void *data)
{
 unsigned int bucknum = Hash_Key(name, table->numbuckets);
 struct bucket_s *buck;
 buck = table->bucket[bucknum];
 if (buck->data == data)
  if (!(((*name)!=(*buck->key.string)) || strcmp(name+1,buck->key.string+1)))
  {
   table->bucket[bucknum] = buck->next;
   return;
  }
 while(buck->next)
 {
  if (buck->next->data == data)
   if (!(((*name)!=(*buck->next->key.string)) || strcmp(name+1,buck->next->key.string+1)))
   {
    buck->next = buck->next->next;
    return;
   }
  buck = buck->next;
 }
 return;
}


qccHunkAlloc

decompiled_code:
char *__fastcall qccHunkAlloc(__int64 a1)
{
unsigned __int64 v1; // rbx
int v2; // edi

v1 = (a1 + 7) & 0xFFFFFFFFFFFFFFF8LL;
qccalloced += v1;
v2 = qccalloced;
if ( qccalloced > qcchunksize )
{
QCC_Error(56LL, "Compile hunk was filled");
v2 = qccalloced;
}
memset((char *)qcchunk + v2 - v1, 0, v1);
return (char *)qcchunk + qccalloced - v1;
}

canonical_decompiled_code:
char *__fastcall func0(__int64 a1)
{
unsigned __int64 v1; // rbx
int v2; // edi

v1 = (a1 + 7) & 0xFFFFFFFFFFFFFFF8LL;
qccalloced += v1;
v2 = qccalloced;
if ( qccalloced > qcchunksize )
{
QCC_Error(56LL, "Compile hunk was filled");
v2 = qccalloced;
}
memset((char *)qcchunk + v2 - v1, 0, v1);
return (char *)qcchunk + qccalloced - v1;
}

original_code:
void *qccHunkAlloc(size_t mem)
{
 mem = (mem + 7)&~7;
 qccalloced+=mem;
 if (qccalloced > qcchunksize)
  QCC_Error(ERR_INTERNAL, "Compile hunk was filled");
 memset(qcchunk+qccalloced-mem, 0, mem);
 return qcchunk+qccalloced-mem;
}

canonical_original_code:
void *qccHunkAlloc(unsigned long mem)
{
 mem = (mem + 7)&~7;
 qccalloced+=mem;
 if (qccalloced > qcchunksize)
  QCC_Error(ERR_INTERNAL, "Compile hunk was filled");
 memset(qcchunk+qccalloced-mem, 0, mem);
 return qcchunk+qccalloced-mem;
}

variable_types:
mem
unsigned long


qccClearHunk

decompiled_code:
void qccClearHunk()
{
if ( qcchunk )
{
free(qcchunk);
qcchunk = 0LL;
}
}

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

original_code:
void qccClearHunk(void)
{
 if (qcchunk)
 {
  free(qcchunk);
  qcchunk=((void *)0);
 }
}

canonical_original_code:
void qccClearHunk()
{
 if (qcchunk)
 {
  free(qcchunk);
  qcchunk=((void *)0);
 }
}


PostCompile

decompiled_code:
void PostCompile()
{
if ( !qccpersisthunk )
qccClearHunk();
if ( asmfile )
{
fclose(asmfile);
asmfile = 0LL;
}
}

canonical_decompiled_code:
void func2()
{
if ( !qccpersisthunk )
func1();
if ( asmfile )
{
fclose(asmfile);
asmfile = 0LL;
}
}

original_code:
void PostCompile(void)
{
 if (!qccpersisthunk)
  qccClearHunk();
 if (asmfile)
 {
  fclose(asmfile);
  asmfile = ((void *)0);
 }
}

canonical_original_code:
void PostCompile()
{
 if (!qccpersisthunk)
  qccClearHunk();
 if (asmfile)
 {
  fclose(asmfile);
  asmfile = ((void *)0);
 }
}


PreCompile

decompiled_code:
void *PreCompile()
{
int v0; // ebp
int v1; // ebx
void *result; // rax

QCC_PR_ResetErrorScope();
qccClearHunk();
qcc_gamedir = 0;
qcchunksize = 0x8000000;
qcchunk = malloc(0x8000000uLL);
if ( !qcchunk )
{
v0 = 4;
v1 = 0x8000000;
while ( 1 )
{
v1 >>= 1;
qcchunksize = v1;
result = malloc(v1);
qcchunk = result;
if ( result )
break;
if ( !--v0 )
goto LABEL_5;
}
}
result = &loc_1;
LABEL_5:
qccalloced = 0;
return result;
}

canonical_decompiled_code:
void *func3()
{
int v0; // ebp
int v1; // ebx
void *result; // rax

QCC_PR_ResetErrorScope();
func1();
qcc_gamedir = 0;
qcchunksize = 0x8000000;
qcchunk = malloc(0x8000000uLL);
if ( !qcchunk )
{
v0 = 4;
v1 = 0x8000000;
while ( 1 )
{
v1 >>= 1;
qcchunksize = v1;
result = malloc(v1);
qcchunk = result;
if ( result )
break;
if ( !--v0 )
goto LABEL_5;
}
}
result = &loc_1;
LABEL_5:
qccalloced = 0;
return result;
}

original_code:
pbool PreCompile(void)
{
 QCC_PR_ResetErrorScope();
 qccClearHunk();
 strcpy(qcc_gamedir, "");
 qcchunk = malloc(qcchunksize=128*1024*1024);
 while(!qcchunk && qcchunksize > 8*1024*1024)
 {
  qcchunksize /= 2;
  qcchunk = malloc(qcchunksize);
 }
 qccalloced=0;
 return !!qcchunk;
}

canonical_original_code:
int PreCompile()
{
 QCC_PR_ResetErrorScope();
 qccClearHunk();
 strcpy(qcc_gamedir, "");
 qcchunk = malloc(qcchunksize=128*1024*1024);
 while(!qcchunk && qcchunksize > 8*1024*1024)
 {
  qcchunksize /= 2;
  qcchunk = malloc(qcchunksize);
 }
 qccalloced=0;
 return !!qcchunk;
}

return_type: int


decompiled_code:
__int64 __fastcall QC_strncasecmp(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 v3; // rcx
__int64 i; // rax
unsigned int v5; // edx
unsigned int v6; // er9
unsigned int v7; // er8
unsigned int v8; // er10

v3 = a3;
for ( i = 0LL; ; ++i )
{
v5 = *(char *)(a1 + i);
v7 = *(char *)(a2 + i);
if ( v3 == i )
return 0;
if ( v5 != v7 )
break;
LABEL_5:
if ( !v7 )
return v7;
}
v8 = v7 - 97;
if ( v5 - 97 <= 0x19 )
{
v5 -= 32;
if ( v8 > 0x19 )
{
v6 = *(char *)(a2 + i);
v7 = v5;
goto LABEL_4;
}
LABEL_10:
v6 = v7 - 32;
v7 = v5;
LABEL_4:
if ( v6 != v5 )
return 0xFFFFFFFFLL;
goto LABEL_5;
}
if ( v8 <= 0x19 )
goto LABEL_10;
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 v3; // rcx
__int64 i; // rax
unsigned int v5; // edx
unsigned int v6; // er9
unsigned int v7; // er8
unsigned int v8; // er10

v3 = a3;
for ( i = 0LL; ; ++i )
{
v5 = *(char *)(a1 + i);
v7 = *(char *)(a2 + i);
if ( v3 == i )
return 0;
if ( v5 != v7 )
break;
LABEL_5:
if ( !v7 )
return v7;
}
v8 = v7 - 97;
if ( v5 - 97 <= 0x19 )
{
v5 -= 32;
if ( v8 > 0x19 )
{
v6 = *(char *)(a2 + i);
v7 = v5;
goto LABEL_4;
}
LABEL_10:
v6 = v7 - 32;
v7 = v5;
LABEL_4:
if ( v6 != v5 )
return 0xFFFFFFFFLL;
goto LABEL_5;
}
if ( v8 <= 0x19 )
goto LABEL_10;
return 0xFFFFFFFFLL;
}

variable_types: n int


editbadfile

decompiled_code:
char *__fastcall editbadfile(char *src, int a2)
{
char *result; // rax

result = strcpy(&errorfile, src);
errorline = a2;
return result;
}

canonical_decompiled_code:
char *__fastcall func9(char *src, int a2)
{
char *result; // rax

result = strcpy(&errorfile, src);
errorline = a2;
return result;
}

original_code:
void editbadfile(char *fname, int line)
{
 strcpy(errorfile, fname);
 errorline = line;
}

variable_types:
fname
char *

variable_types: line int


decompiled_code:
_BOOL8 __fastcall QC_decodeMethodSupported(unsigned int a1)
{
return a1 <= 1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(unsigned int a1)
{
return a1 <= 1;
}

original_code:
pbool QC_decodeMethodSupported(int method)
{
 if (method == 0)
  return true;
 if (method == 1)
  return true;
 if (method == 2)
 {
 }
 return false;
}

canonical_original_code:
int QC_decodeMethodSupported(int method)
{
 if (method == 0)
  return true;
 if (method == 1)
  return true;
 if (method == 2)
 {
 }
 return false;
}

variable_types: method int


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

va_start(arg, format);
vsnprintf(msg_1, 0x7FFuLL, format, arg);
return QCC_Error(56LL, "%s", msg_1);
}

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

va_start(arg, format);
vsnprintf(msg_1, 0x7FFuLL, format, arg);
return QCC_Error(56LL, "%s", msg_1);
}

original_code:
void Sys_Error(const char *text, ...)
{
 va_list argptr;
 static char msg[2048];
 __builtin_va_start(argptr,text);
 vsnprintf (msg,sizeof(msg)-1, text,argptr);
 __builtin_va_end(argptr);
 QCC_Error(ERR_INTERNAL, "%s", msg);
}

canonical_original_code:
void Sys_Error(char *text, ...)
{
 __builtin_va_list argptr;
 static char msg[2048];
 __builtin_va_start(argptr,text);
 vsnprintf (msg,sizeof(msg)-1, text,argptr);
 __builtin_va_end(argptr);
 QCC_Error(ERR_INTERNAL, "%s", msg);
}

variable_types:
text
char *

variable_types:
msg
char [2048]


logprintf

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

va_start(arg, format);
vsnprintf(string_0, 0x400uLL, format, arg);
printf("%s", string_0);
if ( logfile )
fputs(string_0, logfile);
return 0LL;
}

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

va_start(arg, format);
vsnprintf(string_0, 0x400uLL, format, arg);
printf("%s", string_0);
if ( logfile )
fputs(string_0, logfile);
return 0LL;
}

original_code:
int logprintf(const char *format, ...)
{
 va_list argptr;
 static char string[1024];
 __builtin_va_start(argptr,format);
 vsnprintf (string,sizeof(string), format,argptr);
 __builtin_va_end(argptr);
 printf("%s", string);
 if (logfile)
  fputs(string, logfile);
 return 0;
}

canonical_original_code:
int logprintf(char *format, ...)
{
 __builtin_va_list argptr;
 static char string[1024];
 __builtin_va_start(argptr,format);
 vsnprintf (string,sizeof(string), format,argptr);
 __builtin_va_end(argptr);
 printf("%s", string);
 if (logfile)
  fputs(string, logfile);
 return 0;
}

variable_types:
format
char *

variable_types:
string
char [1024]


decompiled_code:
__int64 __fastcall char2pset(char a1)
{
__int64 v1; // rax
char i; // dl

v1 = 0LL;
for ( i = 49; ; i = color_table[v1] )
{
if ( i == a1 )
return 1LL << v1;
if ( ++v1 == 64 )
break;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1)
{
__int64 v1; // rax
char i; // dl

v1 = 0LL;
for ( i = 49; ; i = color_table[v1] )
{
if ( i == a1 )
return 1LL << v1;
if ( ++v1 == 64 )
break;
}
return 0LL;
}

original_code:
pset_t
char2pset (char c)
{
  for (int i = 0; i < 64; i++)
    {
      if (color_table[i] == c)
 return (((pset_t) 1) << i);
    }
  return (0);
}

canonical_original_code:
unsigned long char2pset(char c)
{
  for (int i = 0; i < 64; i++)
    {
      if (color_table[i] == c)
 return (((unsigned long) 1) << i);
    }
  return (0);
}

variable_types: c char

variable_types: i int

return_type: unsigned long


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

result = -1LL;
if ( a1 <= 0x40 )
result = 0xFFFFFFFFFFFFFFFFLL >> (64 - (unsigned __int8)a1);
return result;
}

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

result = -1LL;
if ( a1 <= 0x40 )
result = 0xFFFFFFFFFFFFFFFFLL >> (64 - (unsigned __int8)a1);
return result;
}

canonical_original_code:
unsigned long pset_full(unsigned long color_range)
{
  return (color_range > 64 ? (18446744073709551615UL)
   : (18446744073709551615UL) >> (64 - color_range));
}


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

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

original_code:
pset_t
pset_empty (void)
{
  return (0);
}

canonical_original_code:
unsigned long pset_empty()
{
  return (0);
}


decompiled_code:
__int64 __fastcall pset_set(__int64 a1, char a2)
{
__int64 v2; // rax
__int64 v3; // r8

v2 = char2pset(a2);
return v3 | v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, char a2)
{
__int64 v2; // rax
__int64 v3; // r8

v2 = func0(a2);
return v3 | v2;
}

original_code:
pset_t
pset_set (pset_t pset, char c)
{
  return (pset | char2pset (c));
}

canonical_original_code:
unsigned long pset_set(unsigned long pset, char c)
{
  return (pset | char2pset (c));
}

variable_types:
pset
unsigned long


decompiled_code:
__int64 __fastcall pset_discard(__int64 a1, char a2)
{
__int64 v2; // rax
__int64 v3; // r8

v2 = char2pset(a2);
return v3 & ~v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, char a2)
{
__int64 v2; // rax
__int64 v3; // r8

v2 = func0(a2);
return v3 & ~v2;
}

original_code:
pset_t
pset_discard (pset_t pset, char c)
{
  return (pset & (~ char2pset (c)));
}

canonical_original_code:
unsigned long pset_discard(unsigned long pset, char c)
{
  return (pset & (~ char2pset (c)));
}


decompiled_code:
__int64 __fastcall pset_negate(__int64 a1)
{
return ~a1;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return ~a1;
}

original_code:
pset_t
pset_negate (pset_t pset)
{
  return (~pset);
}

canonical_original_code:
unsigned long pset_negate(unsigned long pset)
{
  return (~pset);
}


decompiled_code:
__int64 __fastcall pset_and(__int64 a1, __int64 a2)
{
return a2 & a1;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
return a2 & a1;
}

original_code:
pset_t
pset_and (pset_t pset1, pset_t pset2)
{
  return (pset1 & pset2);
}

canonical_original_code:
unsigned long pset_and(unsigned long pset1, unsigned long pset2)
{
  return (pset1 & pset2);
}


decompiled_code:
__int64 __fastcall pset_or(__int64 a1, __int64 a2)
{
return a2 | a1;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
return a2 | a1;
}

original_code:
pset_t
pset_or (pset_t pset1, pset_t pset2)
{
  return (pset1 | pset2);
}

canonical_original_code:
unsigned long pset_or(unsigned long pset1, unsigned long pset2)
{
  return (pset1 | pset2);
}


decompiled_code:
__int64 __fastcall pset_xor(__int64 a1, __int64 a2)
{
return a2 ^ a1;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2)
{
return a2 ^ a1;
}

original_code:
pset_t
pset_xor (pset_t pset1, pset_t pset2)
{
  return (pset1 ^ pset2);
}

canonical_original_code:
unsigned long pset_xor(unsigned long pset1, unsigned long pset2)
{
  return (pset1 ^ pset2);
}


decompiled_code:
bool __fastcall pset_is_included(__int64 a1, __int64 a2)
{
return (a2 | a1) == a2;
}

canonical_decompiled_code:
bool __fastcall func10(__int64 a1, __int64 a2)
{
return (a2 | a1) == a2;
}

original_code:
_Bool
pset_is_included (pset_t pset1, pset_t pset2)
{
  return ((pset1 | pset2) == pset2);
}

canonical_original_code:
_Bool pset_is_included(unsigned long pset1, unsigned long pset2)
{
  return ((pset1 | pset2) == pset2);
}


decompiled_code:
bool __fastcall pset_is_singleton(__int64 a1)
{
bool result; // al

result = 0;
if ( a1 )
result = (a1 & -a1) == a1;
return result;
}

canonical_decompiled_code:
bool __fastcall func11(__int64 a1)
{
bool result; // al

result = 0;
if ( a1 )
result = (a1 & -a1) == a1;
return result;
}

original_code:
_Bool
pset_is_singleton (pset_t pset)
{
  return (pset == 0 ? 0 : (pset & (- pset)) == pset);
}

canonical_original_code:
_Bool pset_is_singleton(unsigned long pset)
{
  return (pset == 0 ? 0 : (pset & (- pset)) == pset);
}


original_code:
size_t
pset_cardinality (pset_t pset)
{
  static const uint64_t m1 = 0x5555555555555555;
  static const uint64_t m2 = 0x3333333333333333;
  static const uint64_t m4 = 0x0f0f0f0f0f0f0f0f;
  static const uint64_t h01 = 0x0101010101010101;
  pset -= (pset >> 1) & m1;
  pset = (pset & m2) + ((pset >> 2) & m2);
  pset = (pset + (pset >> 4)) & m4;
  return (pset * h01)>>56;
}

canonical_original_code:
unsigned long pset_cardinality(unsigned long pset)
{
  static unsigned long m1 = 0x5555555555555555;
  static unsigned long m2 = 0x3333333333333333;
  static unsigned long m4 = 0x0f0f0f0f0f0f0f0f;
  static unsigned long h01 = 0x0101010101010101;
  pset -= (pset >> 1) & m1;
  pset = (pset & m2) + ((pset >> 2) & m2);
  pset = (pset + (pset >> 4)) & m4;
  return (pset * h01)>>56;
}


decompiled_code:
__int64 __fastcall pset_leftmost(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // r8

v1 = pset_negate(a1 - 1);
return pset_and(v2, v1);
}

original_code:
pset_t
pset_leftmost (pset_t pset)
{
  return (pset_and (pset, pset_negate (pset - 1)));
}

canonical_original_code:
unsigned long pset_leftmost(unsigned long pset)
{
  return (pset_and (pset, pset_negate (pset - 1)));
}


decompiled_code:
__int64 out_of_memory()
{
fprintf(stderr, "%s: error: out of memory!\n", (const char *)exec_name);
return usage(1LL);
}

canonical_decompiled_code:
__int64 func0()
{
fprintf(stderr, "%s: error: out of memory!\n", (const char *)exec_name);
return usage(1LL);
}

original_code:
static void
out_of_memory ()
{
  fprintf (stderr, "%s: error: out of memory!\n", exec_name);
  usage (1);
}

canonical_original_code:
static void out_of_memory()
{
  fprintf (stderr, "%s: error: out of memory!\n", exec_name);
  usage (1);
}


shuffle

original_code:
static void
shuffle (int* const arr, int size)
{
  srand (time (((void *)0)));
  for (int i = 0; i < size - 1; i++)
    {
      int r = i + (rand () % (size - i));
      int t = arr[i];
      arr[i] = arr[r];
      arr[r] = t;
    }
}

canonical_original_code:
static void shuffle(int *arr, int size)
{
  srand (time (((void *)0)));
  for (int i = 0; i < size - 1; i++)
    {
      int r = i + (rand () % (size - i));
      int t = arr[i];
      arr[i] = arr[r];
      arr[r] = t;
    }
}

variable_types:
arr
int *

variable_types: size int

variable_types: r int

variable_types: t int


decompiled_code:
void __fastcall grid_free(void *ptr)
{
unsigned int v1; // ebx
__int64 v2; // rax

if ( ptr )
{
if ( grid_size )
{
v1 = 0;
v2 = 0LL;
do
{
free(*((void **)ptr + v2));
v2 = ++v1;
}
while ( v1 < grid_size );
}
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
unsigned int v1; // ebx
__int64 v2; // rax

if ( ptr )
{
if ( grid_size )
{
v1 = 0;
v2 = 0LL;
do
{
free(*((void **)ptr + v2));
v2 = ++v1;
}
while ( v1 < grid_size );
}
free(ptr);
}
}

original_code:
void
grid_free (pset_t** grid)
{
  if (grid == ((void *)0))
    return;
  for (unsigned int i = 0; i < grid_size; i++)
    free (grid[i]);
  free (grid);
}

canonical_original_code:
void grid_free(unsigned long **grid)
{
  if (grid == ((void *)0))
    return;
  for (unsigned int i = 0; i < grid_size; i++)
    free (grid[i]);
  free (grid);
}

variable_types:
grid
unsigned long **

variable_types:
i
unsigned int


decompiled_code:
void __fastcall stack_free(void *ptr)
{
void **v1; // rbx
void **v2; // rbp

if ( ptr )
{
v1 = (void **)ptr;
do
{
v2 = v1;
v1 = (void **)v1[4];
grid_free(*v2);
free(v2);
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
void **v1; // rbx
void **v2; // rbp

if ( ptr )
{
v1 = (void **)ptr;
do
{
v2 = v1;
v1 = (void **)v1[4];
func2(*v2);
free(v2);
}
while ( v1 );
}
}

original_code:
static void
stack_free (choice_t* stack)
{
  if (stack == ((void *)0))
    return;
  choice_t* prev = stack->previous;
  grid_free (stack->grid);
  free (stack);
  return (stack_free (prev));
}

canonical_original_code:
static void stack_free(struct choice *stack)
{
  if (stack == ((void *)0))
    return;
  struct choice *prev = stack->previous;
  grid_free (stack->grid);
  free (stack);
  return (stack_free (prev));
}

variable_types: struct choice { unsigned long **grid; unsigned long x; unsigned long y; unsigned long choice; struct choice *previous; } *


original_code:
static choice_t*
stack_pop (choice_t* stack, pset_t** grid)
{
  if (stack == ((void *)0))
    return (((void *)0));
  choice_t* prev = stack->previous;
  stack->grid[stack->x][stack->y] = pset_and (stack->grid[stack->x][stack->y],
           pset_negate (stack->choice));
  for (unsigned int i = 0; i < grid_size; i++)
    for (unsigned int j = 0; j < grid_size; j++)
      grid[i][j] = stack->grid[i][j];
  grid_free (stack->grid);
  free (stack);
  return (prev);
}

canonical_original_code:
static struct choice *stack_pop(struct choice *stack, unsigned long **grid)
{
  if (stack == ((void *)0))
    return (((void *)0));
  struct choice *prev = stack->previous;
  stack->grid[stack->x][stack->y] = pset_and (stack->grid[stack->x][stack->y],
           pset_negate (stack->choice));
  for (unsigned int i = 0; i < grid_size; i++)
    for (unsigned int j = 0; j < grid_size; j++)
      grid[i][j] = stack->grid[i][j];
  grid_free (stack->grid);
  free (stack);
  return (prev);
}

variable_types:
stack
struct choice *

variable_types:
j
unsigned int

return_type: struct choice { unsigned long **grid; unsigned long x; unsigned long y; unsigned long choice; struct choice *previous; } *


decompiled_code:
_QWORD *grid_alloc()
{
size_t v0; // rdi
_QWORD *v1; // r12
unsigned int v2; // ebp
__int64 v3; // rbx
void *v4; // rax

v0 = grid_size;
v1 = calloc(grid_size, 8uLL);
if ( !v1 )
{
out_of_memory(v0);
v0 = grid_size;
}
v2 = 0;
v3 = 0LL;
if ( v0 )
{
do
{
v4 = calloc(v0, 8uLL);
v1[v3] = v4;
if ( !v4 )
out_of_memory(v0);
v0 = grid_size;
v3 = ++v2;
}
while ( v2 < grid_size );
}
return v1;
}

canonical_decompiled_code:
_QWORD *func5()
{
size_t v0; // rdi
_QWORD *v1; // r12
unsigned int v2; // ebp
__int64 v3; // rbx
void *v4; // rax

v0 = grid_size;
v1 = calloc(grid_size, 8uLL);
if ( !v1 )
{
func0(v0);
v0 = grid_size;
}
v2 = 0;
v3 = 0LL;
if ( v0 )
{
do
{
v4 = calloc(v0, 8uLL);
v1[v3] = v4;
if ( !v4 )
func0(v0);
v0 = grid_size;
v3 = ++v2;
}
while ( v2 < grid_size );
}
return v1;
}

original_code:
pset_t**
grid_alloc (void)
{
  pset_t** ret;
  ret = calloc (grid_size, sizeof (pset_t*));
  if (ret == ((void *)0))
    out_of_memory ();
  for (unsigned int i = 0; i < grid_size; i++)
    {
      ret[i] = calloc (grid_size, sizeof (pset_t));
      if (ret[i] == ((void *)0))
 out_of_memory ();
    }
  return (ret);
}

canonical_original_code:
unsigned long **grid_alloc()
{
  unsigned long **ret;
  ret = calloc (grid_size, sizeof (unsigned long *));
  if (ret == ((void *)0))
    out_of_memory ();
  for (unsigned int i = 0; i < grid_size; i++)
    {
      ret[i] = calloc (grid_size, sizeof (pset_t));
      if (ret[i] == ((void *)0))
 out_of_memory ();
    }
  return (ret);
}

variable_types:
ret
unsigned long **

return_type: unsigned long **


decompiled_code:
int __fastcall grid_print(_QWORD **a1)
{
__int64 v1; // rax
unsigned int v2; // er13
unsigned __int64 v3; // r12
unsigned int v4; // ebp
__int64 v5; // rbx
_QWORD *v6; // r15
size_t v7; // rdi
__int64 v8; // r14
__int64 v9; // rbx
unsigned int v10; // er14
unsigned int v11; // ebp
__int64 v12; // r15
_QWORD *v13; // r13
__int64 v14; // rbx
unsigned __int64 v15; // rbx
__int128 v18[4]; // [rsp+8h] [rbp-88h] BYREF
char v19; // [rsp+48h] [rbp-48h]

LODWORD(v1) = grid_size;
v19 = 0;
v18[0] = 0LL;
v18[1] = 0LL;
v18[2] = 0LL;
v18[3] = 0LL;
if ( grid_size == 1 )
{
if ( !random_choice )
{
pset2str(v18, **a1);
LODWORD(v1) = fprintf(output_stream, "%s\n", (const char *)v18);
return v1;
}
}
else if ( !grid_size )
{
return v1;
}
v2 = 0;
v3 = 0LL;
v1 = 0LL;
do
{
v4 = 0;
v5 = 0LL;
v6 = &a1[v1];
do
{
v8 = 8 * v5;
if ( pset_cardinality(*(_QWORD *)(*v6 + 8 * v5)) > v3 )
{
v9 = *(_QWORD *)(*v6 + 8 * v5);
if ( v9 != pset_full(grid_size) )
v3 = pset_cardinality(*(_QWORD *)(*v6 + v8));
}
v7 = grid_size;
v5 = ++v4;
}
while ( v4 < grid_size );
v1 = ++v2;
}
while ( grid_size > v2 );
if ( grid_size )
{
v10 = 0;
v1 = 0LL;
do
{
if ( v7 )
{
v11 = 0;
v12 = 0LL;
v13 = &a1[v1];
do
{
v14 = *(_QWORD *)(*v13 + 8 * v12);
if ( v14 == pset_full(v7) )
{
v15 = v3;
fputc(95, output_stream);
}
else
{
v15 = v3 - pset_cardinality(*(_QWORD *)(*v13 + 8 * v12));
pset2str(v18, *(_QWORD *)(*v13 + 8 * v12));
fprintf(output_stream, "%s ", (const char *)v18);
}
for ( ; v15; --v15 )
fputc(32, output_stream);
v7 = grid_size;
v12 = ++v11;
}
while ( v11 < grid_size );
}
fputc(10, output_stream);
v7 = grid_size;
v1 = ++v10;
}
while ( v10 < grid_size );
}
return v1;
}

canonical_decompiled_code:
int __fastcall func6(_QWORD **a1)
{
__int64 v1; // rax
unsigned int v2; // er13
unsigned __int64 v3; // r12
unsigned int v4; // ebp
__int64 v5; // rbx
_QWORD *v6; // r15
size_t v7; // rdi
__int64 v8; // r14
__int64 v9; // rbx
unsigned int v10; // er14
unsigned int v11; // ebp
__int64 v12; // r15
_QWORD *v13; // r13
__int64 v14; // rbx
unsigned __int64 v15; // rbx
__int128 v18[4]; // [rsp+8h] [rbp-88h] BYREF
char v19; // [rsp+48h] [rbp-48h]

LODWORD(v1) = grid_size;
v19 = 0;
v18[0] = 0LL;
v18[1] = 0LL;
v18[2] = 0LL;
v18[3] = 0LL;
if ( grid_size == 1 )
{
if ( !random_choice )
{
pset2str(v18, **a1);
LODWORD(v1) = fprintf(output_stream, "%s\n", (const char *)v18);
return v1;
}
}
else if ( !grid_size )
{
return v1;
}
v2 = 0;
v3 = 0LL;
v1 = 0LL;
do
{
v4 = 0;
v5 = 0LL;
v6 = &a1[v1];
do
{
v8 = 8 * v5;
if ( pset_cardinality(*(_QWORD *)(*v6 + 8 * v5)) > v3 )
{
v9 = *(_QWORD *)(*v6 + 8 * v5);
if ( v9 != pset_full(grid_size) )
v3 = pset_cardinality(*(_QWORD *)(*v6 + v8));
}
v7 = grid_size;
v5 = ++v4;
}
while ( v4 < grid_size );
v1 = ++v2;
}
while ( grid_size > v2 );
if ( grid_size )
{
v10 = 0;
v1 = 0LL;
do
{
if ( v7 )
{
v11 = 0;
v12 = 0LL;
v13 = &a1[v1];
do
{
v14 = *(_QWORD *)(*v13 + 8 * v12);
if ( v14 == pset_full(v7) )
{
v15 = v3;
fputc(95, output_stream);
}
else
{
v15 = v3 - pset_cardinality(*(_QWORD *)(*v13 + 8 * v12));
pset2str(v18, *(_QWORD *)(*v13 + 8 * v12));
fprintf(output_stream, "%s ", (const char *)v18);
}
for ( ; v15; --v15 )
fputc(32, output_stream);
v7 = grid_size;
v12 = ++v11;
}
while ( v11 < grid_size );
}
fputc(10, output_stream);
v7 = grid_size;
v1 = ++v10;
}
while ( v10 < grid_size );
}
return v1;
}

original_code:
void
grid_print (const pset_t** grid)
{
  char str[64 +1] = {0};
  size_t max_cardinality = 0;
  if (grid_size == 1 && !random_choice)
    {
      pset2str (str,grid[0][0]);
      fprintf (output_stream, "%s\n", str);
      return;
    }
  for (unsigned int i = 0; i < grid_size; i++)
    for (unsigned int j = 0; j < grid_size; j++)
      {
 if (pset_cardinality (grid[i][j]) > max_cardinality
     && grid[i][j] != pset_full (grid_size))
   max_cardinality = pset_cardinality(grid[i][j]);
      }
  for (unsigned int i = 0; i < grid_size; i++)
    {
      for (unsigned int j = 0; j < grid_size; j++)
 {
   size_t spaces_length;
   if (grid[i][j] == pset_full (grid_size))
     {
       spaces_length = max_cardinality;
       fprintf (output_stream, "_");
     }
   else
     {
       spaces_length = max_cardinality - pset_cardinality(grid[i][j]);
       pset2str (str, grid[i][j]);
       fprintf (output_stream, "%s ", str);
     }
   for (;spaces_length > 0; spaces_length--)
     fputc (' ', output_stream);
 }
      fprintf (output_stream, "\n");
    }
}

canonical_original_code:
void grid_print(unsigned long **grid)
{
  char str[-1] = {0};
  unsigned long max_cardinality = 0;
  if (grid_size == 1 && !random_choice)
    {
      pset2str (str,grid[0][0]);
      fprintf (output_stream, "%s\n", str);
      return;
    }
  for (unsigned int i = 0; i < grid_size; i++)
    for (unsigned int j = 0; j < grid_size; j++)
      {
 if (pset_cardinality (grid[i][j]) > max_cardinality
     && grid[i][j] != pset_full (grid_size))
   max_cardinality = pset_cardinality(grid[i][j]);
      }
  for (unsigned int i = 0; i < grid_size; i++)
    {
      for (unsigned int j = 0; j < grid_size; j++)
 {
   unsigned long spaces_length;
   if (grid[i][j] == pset_full (grid_size))
     {
       spaces_length = max_cardinality;
       fprintf (output_stream, "_");
     }
   else
     {
       spaces_length = max_cardinality - pset_cardinality(grid[i][j]);
       pset2str (str, grid[i][j]);
       fprintf (output_stream, "%s ", str);
     }
   for (;spaces_length > 0; spaces_length--)
     fputc (' ', output_stream);
 }
      fprintf (output_stream, "\n");
    }
}

variable_types:
str
char [-1]


decompiled_code:
int __fastcall stack_print(__int64 a1)
{
int result; // eax
char v2[80]; // [rsp-50h] [rbp-A8h] BYREF
char v3[88]; // [rsp+0h] [rbp-58h] BYREF

if ( a1 )
{
pset2str(v2, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)a1 + 8LL * *(_QWORD *)(a1 + 8)) + 8LL * *(_QWORD *)(a1 + 16)));
pset2str(v3, *(_QWORD *)(a1 + 24));
if ( verbose )
grid_print(*(_QWORD ***)a1);
result = fprintf(
output_stream,
"Next choice at: grid[%d][%d] = '%s', and choice is = '%s'\n",
*(_QWORD *)(a1 + 8),
*(_QWORD *)(a1 + 16),
v2,
v3);
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1)
{
int result; // eax
char v2[80]; // [rsp-50h] [rbp-A8h] BYREF
char v3[88]; // [rsp+0h] [rbp-58h] BYREF

if ( a1 )
{
pset2str(v2, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)a1 + 8LL * *(_QWORD *)(a1 + 8)) + 8LL * *(_QWORD *)(a1 + 16)));
pset2str(v3, *(_QWORD *)(a1 + 24));
if ( verbose )
func6(*(_QWORD ***)a1);
result = fprintf(
output_stream,
"Next choice at: grid[%d][%d] = '%s', and choice is = '%s'\n",
*(_QWORD *)(a1 + 8),
*(_QWORD *)(a1 + 16),
v2,
v3);
}
return result;
}

original_code:
static void
stack_print (const choice_t* stack)
{
  if (stack == ((void *)0))
    return;
   char str1[64 + 1];
   char str2[64 + 1];
   pset2str (str1, stack->grid[stack->x][stack->y]);
   pset2str (str2, stack->choice);
   if (verbose)
     grid_print ((const pset_t**) stack->grid);
   fprintf (output_stream,
     "Next choice at: grid[%d][%d] = '%s', and choice is = '%s'\n",
    (int) stack->x, (int) stack->y, str1, str2);
}

canonical_original_code:
static void stack_print(struct choice *stack)
{
  if (stack == ((void *)0))
    return;
   char str1[-1];
   char str2[-1];
   pset2str (str1, stack->grid[stack->x][stack->y]);
   pset2str (str2, stack->choice);
   if (verbose)
     grid_print ((unsigned long **) stack->grid);
   fprintf (output_stream,
     "Next choice at: grid[%d][%d] = '%s', and choice is = '%s'\n",
    (int) stack->x, (int) stack->y, str1, str2);
}

user_defined_types: struct choice { unsigned long **grid; unsigned long x; unsigned long y; unsigned long choice; struct choice *previous; }


decompiled_code:
__int64 __fastcall number_of_solutions(__int64 *a1)
{
unsigned int v1; // er12
_QWORD *i; // rbp
int v3; // eax

v1 = 0;
while ( 2 )
{
for ( i = 0LL; ; i = stack_push(i, a1) )
{
v3 = grid_heuristics(a1);
if ( v3 != 1 )
break;
LABEL_7:
;
}
while ( v3 == 2 )
{
if ( !i )
return v1;
LABEL_6:
i = (_QWORD *)stack_pop(i, a1);
v3 = grid_heuristics(a1);
if ( v3 == 1 )
goto LABEL_7;
}
if ( v3 )
continue;
break;
}
++v1;
if ( i )
goto LABEL_6;
stack_free(0LL);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 *a1)
{
unsigned int v1; // er12
_QWORD *i; // rbp
int v3; // eax

v1 = 0;
while ( 2 )
{
for ( i = 0LL; ; i = stack_push(i, a1) )
{
v3 = grid_heuristics(a1);
if ( v3 != 1 )
break;
LABEL_7:
;
}
while ( v3 == 2 )
{
if ( !i )
return v1;
LABEL_6:
i = (_QWORD *)func4(i, a1);
v3 = grid_heuristics(a1);
if ( v3 == 1 )
goto LABEL_7;
}
if ( v3 )
continue;
break;
}
++v1;
if ( i )
goto LABEL_6;
func3(0LL);
return v1;
}

original_code:
static int
number_of_solutions (pset_t** grid)
{
  choice_t* stack = ((void *)0);
  int sols = 0;
  for (;;)
    {
      switch (grid_heuristics (grid))
 {
 case 0:
   sols++;
   if (stack == ((void *)0))
     {
       stack_free (stack);
       return (sols);
     }
   else
     {
       stack = stack_pop (stack, grid);
       break;
     }
 case 1:
   stack = stack_push (stack, grid);
   break;
 case 2:
   if (stack == ((void *)0))
     {
       return (sols);
     }
   stack = stack_pop (stack, grid);
   break;
 }
    }
}

canonical_original_code:
static int number_of_solutions(unsigned long **grid)
{
  struct choice *stack = ((void *)0);
  int sols = 0;
  for (;;)
    {
      switch (grid_heuristics (grid))
 {
 case 0:
   sols++;
   if (stack == ((void *)0))
     {
       stack_free (stack);
       return (sols);
     }
   else
     {
       stack = stack_pop (stack, grid);
       break;
     }
 case 1:
   stack = stack_push (stack, grid);
   break;
 case 2:
   if (stack == ((void *)0))
     {
       return (sols);
     }
   stack = stack_pop (stack, grid);
   break;
 }
    }
}

variable_types: sols int


decompiled_code:
__int64 __fastcall grid_solver(__int64 *a1)
{
_QWORD *i; // rbp
int v2; // eax
unsigned int v3; // er12

while ( 2 )
{
for ( i = 0LL; ; i = stack_push(i, a1) )
{
v2 = grid_heuristics(a1);
if ( v2 != 1 )
break;
LABEL_11:
;
}
while ( v2 == 2 )
{
if ( !i )
{
v3 = (unsigned __int8)random_choice;
if ( random_choice )
return 0;
fwrite("Grid could not be solved\n", 1uLL, 0x19uLL, output_stream);
return v3;
}
i = (_QWORD *)stack_pop(i, a1);
v2 = grid_heuristics(a1);
if ( v2 == 1 )
goto LABEL_11;
}
if ( v2 )
continue;
break;
}
if ( !random_choice )
{
fwrite("Grid has been solved\n", 1uLL, 0x15uLL, output_stream);
grid_print((_QWORD **)a1);
}
v3 = 1;
stack_free(i);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 *a1)
{
_QWORD *i; // rbp
int v2; // eax
unsigned int v3; // er12

while ( 2 )
{
for ( i = 0LL; ; i = stack_push(i, a1) )
{
v2 = grid_heuristics(a1);
if ( v2 != 1 )
break;
LABEL_11:
;
}
while ( v2 == 2 )
{
if ( !i )
{
v3 = (unsigned __int8)random_choice;
if ( random_choice )
return 0;
fwrite("Grid could not be solved\n", 1uLL, 0x19uLL, output_stream);
return v3;
}
i = (_QWORD *)func4(i, a1);
v2 = grid_heuristics(a1);
if ( v2 == 1 )
goto LABEL_11;
}
if ( v2 )
continue;
break;
}
if ( !random_choice )
{
fwrite("Grid has been solved\n", 1uLL, 0x15uLL, output_stream);
func6((_QWORD **)a1);
}
v3 = 1;
func3(i);
return v3;
}

original_code:
_Bool
grid_solver (pset_t** grid)
{
  choice_t* stack = ((void *)0);
  for (;;)
    {
      switch (grid_heuristics (grid))
 {
 case 0:
   if (!random_choice)
     {
       fprintf (output_stream, "Grid has been solved\n");
       grid_print ((const pset_t**) grid);
     }
   stack_free (stack);
   return (1);
 case 1:
   stack = stack_push (stack, grid);
   break;
 case 2:
   if (stack == ((void *)0))
     {
       if (!random_choice)
  fprintf (output_stream, "Grid could not be solved\n");
       return (0);
     }
   stack = stack_pop (stack, grid);
   break;
 }
    }
}

canonical_original_code:
_Bool grid_solver(unsigned long **grid)
{
  struct choice *stack = ((void *)0);
  for (;;)
    {
      switch (grid_heuristics (grid))
 {
 case 0:
   if (!random_choice)
     {
       fprintf (output_stream, "Grid has been solved\n");
       grid_print ((unsigned long **) grid);
     }
   stack_free (stack);
   return (1);
 case 1:
   stack = stack_push (stack, grid);
   break;
 case 2:
   if (stack == ((void *)0))
     {
       if (!random_choice)
  fprintf (output_stream, "Grid could not be solved\n");
       return (0);
     }
   stack = stack_pop (stack, grid);
   break;
 }
    }
}


original_code:
static _Bool
check_input_char (char c)
{
  const char tbl[] = "123456789"
                     "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                     "abcdefghijklmnopqrstuvwxyz"
                     "@&*";
  if (c == '_')
    return (1);
  for (unsigned int i = 0; i < grid_size; i++)
    if (c == tbl[i])
      return (1);
  return (0);
}

canonical_original_code:
static _Bool check_input_char(char c)
{
  char tbl[] = "123456789"
                     "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                     "abcdefghijklmnopqrstuvwxyz"
                     "@&*";
  if (c == '_')
    return (1);
  for (unsigned int i = 0; i < grid_size; i++)
    if (c == tbl[i])
      return (1);
  return (0);
}

variable_types:
tbl
char []


version

decompiled_code:
void __noreturn version()
{
printf("%s %d.%d.%d\nThis software is a sudoku solver\n", "sudoku", 1LL, 0LL, 0LL);
exit(0);
}

canonical_decompiled_code:
void __noreturn func0()
{
printf("%s %d.%d.%d\nThis software is a sudoku solver\n", "sudoku", 1LL, 0LL, 0LL);
exit(0);
}

original_code:
static void
version (void)
{
  printf ("%s %d.%d.%d\n"
   "This software is a sudoku solver\n",
   "sudoku", 1, 0, 0);
  exit (0);
}

canonical_original_code:
static void version()
{
  printf ("%s %d.%d.%d\n"
   "This software is a sudoku solver\n",
   "sudoku", 1, 0, 0);
  exit (0);
}


usage

decompiled_code:
void __fastcall __noreturn usage(int status)
{
char *v1; // rax

v1 = _xpg_basename(exec_name);
if ( status )
fprintf(stderr, "Try `%s --help` for more information\n", v1);
else
printf(
"Usage: %s [OPTION] FILE\n"
"Solve Sudoku puzzles of variable sizes (1-64)\n"
"\n"
" -o, --output=FILE write result to FILE\n"
" -s, --strict generate a unique-solution grid -g, --generate=SIZE generates a grid of size SIZE (by defau"
"lt 9)\n"
" -v, --verbose verbose output\n"
" -V, --version display version and exit\n"
" -h, --help display this help\n",
v1);
grid_free(grid);
fclose(output_stream);
exit(status);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(int status)
{
char *v1; // rax

v1 = _xpg_basename(exec_name);
if ( status )
fprintf(stderr, "Try `%s --help` for more information\n", v1);
else
printf(
"Usage: %s [OPTION] FILE\n"
"Solve Sudoku puzzles of variable sizes (1-64)\n"
"\n"
" -o, --output=FILE write result to FILE\n"
" -s, --strict generate a unique-solution grid -g, --generate=SIZE generates a grid of size SIZE (by defau"
"lt 9)\n"
" -v, --verbose verbose output\n"
" -V, --version display version and exit\n"
" -h, --help display this help\n",
v1);
grid_free(grid);
fclose(output_stream);
exit(status);
}

original_code:
void
usage (int status)
{
  if (status == 0)
    {
      printf (
 "Usage: %s [OPTION] FILE\n"
        "Solve Sudoku puzzles of variable sizes (1-64)\n"
 "\n"
 "  -o, --output=FILE   write result to FILE\n"
 "  -s, --strict        generate a unique-solution grid"
 "  -g, --generate=SIZE generates a grid of size SIZE (by default 9)\n"
        "  -v, --verbose       verbose output\n"
 "  -V, --version       display version and exit\n"
 "  -h, --help          display this help\n",
        __xpg_basename(exec_name));
    }
  else
    {
      fprintf (stderr, "Try `%s --help` for more information\n",
        __xpg_basename(exec_name));
    }
  grid_free (grid);
  fclose (output_stream);
  exit (status);
}

canonical_original_code:
void usage(int status)
{
  if (status == 0)
    {
      printf (
 "Usage: %s [OPTION] FILE\n"
        "Solve Sudoku puzzles of variable sizes (1-64)\n"
 "\n"
 "  -o, --output=FILE   write result to FILE\n"
 "  -s, --strict        generate a unique-solution grid"
 "  -g, --generate=SIZE generates a grid of size SIZE (by default 9)\n"
        "  -v, --verbose       verbose output\n"
 "  -V, --version       display version and exit\n"
 "  -h, --help          display this help\n",
        __xpg_basename(exec_name));
    }
  else
    {
      fprintf (stderr, "Try `%s --help` for more information\n",
        __xpg_basename(exec_name));
    }
  grid_free (grid);
  fclose (output_stream);
  exit (status);
}

variable_types: status int


main

canonical_name: main

repo: danielgjackson/xed

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

fwrite("XED File Format Parser\n", 1uLL, 0x17uLL, stderr);
fwrite("2013, Dan Jackson\n", 1uLL, 0x12uLL, stderr);
fputc(10, stderr);
if ( argc <= 1 )
goto LABEL_11;
v3 = argv[1];
if ( !strcasecmp(v3, "--help") )
goto LABEL_11;
if ( *v3 == 45 )
{
fprintf(stderr, "ERROR: Unknown option: %s\n", v3);
LABEL_11:
fwrite("ERROR: Input file not specified.\n", 1uLL, 0x21uLL, stderr);
LABEL_8:
fputc(10, stderr);
fwrite("Usage: xed_decode <input.xed>\n", 1uLL, 0x1EuLL, stderr);
fputc(10, stderr);
return -1;
}
if ( argc != 2 )
{
v4 = argv[2];
if ( strcasecmp(v4, "--help") )
{
if ( *v4 == 45 )
fprintf(stderr, "ERROR: Unknown option: %s\n", v4);
else
fprintf(stderr, "ERROR: Unknown positional parameter: %s\n", v4);
}
goto LABEL_8;
}
fprintf(stderr, "NOTE: Processing: %s\n", v3);
v6 = xed_decode(v3);
fwrite("NOTE: End processing\n", 1uLL, 0x15uLL, stderr);
return v6;
}

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

fwrite("XED File Format Parser\n", 1uLL, 0x17uLL, stderr);
fwrite("2013, Dan Jackson\n", 1uLL, 0x12uLL, stderr);
fputc(10, stderr);
if ( argc <= 1 )
goto LABEL_11;
v3 = argv[1];
if ( !strcasecmp(v3, "--help") )
goto LABEL_11;
if ( *v3 == 45 )
{
fprintf(stderr, "ERROR: Unknown option: %s\n", v3);
LABEL_11:
fwrite("ERROR: Input file not specified.\n", 1uLL, 0x21uLL, stderr);
LABEL_8:
fputc(10, stderr);
fwrite("Usage: xed_decode <input.xed>\n", 1uLL, 0x1EuLL, stderr);
fputc(10, stderr);
return -1;
}
if ( argc != 2 )
{
v4 = argv[2];
if ( strcasecmp(v4, "--help") )
{
if ( *v4 == 45 )
fprintf(stderr, "ERROR: Unknown option: %s\n", v4);
else
fprintf(stderr, "ERROR: Unknown positional parameter: %s\n", v4);
}
goto LABEL_8;
}
fprintf(stderr, "NOTE: Processing: %s\n", v3);
v6 = func0(v3);
fwrite("NOTE: End processing\n", 1uLL, 0x15uLL, stderr);
return v6;
}

original_code:
int main(int argc, char *argv[])
{
    int ret = 0;
    char help = 0;
    int positional;
    int i;
    const char *infile = ((void *)0);
    fprintf(stderr, "XED File Format Parser\n");
    fprintf(stderr, "2013, Dan Jackson\n");
    fprintf(stderr, "\n");
    positional = 0;
    for (i = 1; i < argc; i++)
    {
        if (!strcasecmp(argv[i], "--help")) { help = 1; break; }
        else if (argv[i][0] == '-')
        {
            fprintf(stderr, "ERROR: Unknown option: %s\n", argv[i]);
            help = 1;
            break;
        }
        else
        {
            positional++;
            if (positional == 1)
            {
                infile = argv[i];
            }
            else
            {
                fprintf(stderr, "ERROR: Unknown positional parameter: %s\n", argv[i]);
                help = 1;
                break;
            }
        }
    }
    if (infile == ((void *)0)) { fprintf(stderr, "ERROR: Input file not specified.\n"); help = 1; }
    if (help)
    {
        fprintf(stderr, "\n");
        fprintf(stderr, "Usage: xed_decode <input.xed>\n");
        fprintf(stderr, "\n");
        ret = -1;
    }
    else
    {
        fprintf(stderr, "NOTE: Processing: %s\n", infile);
        ret = xed_decode(infile);
        fprintf(stderr, "NOTE: End processing\n");
    }
    return ret;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    int ret = 0;
    char help = 0;
    int positional;
    int i;
    char *infile = ((void *)0);
    fprintf(stderr, "XED File Format Parser\n");
    fprintf(stderr, "2013, Dan Jackson\n");
    fprintf(stderr, "\n");
    positional = 0;
    for (i = 1; i < argc; i++)
    {
        if (!strcasecmp(argv[i], "--help")) { help = 1; break; }
        else if (argv[i][0] == '-')
        {
            fprintf(stderr, "ERROR: Unknown option: %s\n", argv[i]);
            help = 1;
            break;
        }
        else
        {
            positional++;
            if (positional == 1)
            {
                infile = argv[i];
            }
            else
            {
                fprintf(stderr, "ERROR: Unknown positional parameter: %s\n", argv[i]);
                help = 1;
                break;
            }
        }
    }
    if (infile == ((void *)0)) { fprintf(stderr, "ERROR: Input file not specified.\n"); help = 1; }
    if (help)
    {
        fprintf(stderr, "\n");
        fprintf(stderr, "Usage: xed_decode <input.xed>\n");
        fprintf(stderr, "\n");
        ret = -1;
    }
    else
    {
        fprintf(stderr, "NOTE: Processing: %s\n", infile);
        ret = xed_decode(infile);
        fprintf(stderr, "NOTE: End processing\n");
    }
    return ret;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: ret int

variable_types: help char

variable_types: positional int

variable_types:
infile
char *


repo: danielgtaylor/jpeg-archive

decompiled_code:
float __fastcall KBND_SYMMETRIC(__int64 a1, int a2, int a3, int a4, int a5)
{
if ( a4 < 0 )
{
a4 = ~a4;
LABEL_3:
if ( a5 >= 0 )
goto LABEL_4;
LABEL_8:
a5 = ~a5;
return *(float *)(a1 + 4LL * (a4 + a2 * a5));
}
if ( a4 < a2 )
goto LABEL_3;
a4 = a2 - (a4 - a2) - 1;
if ( a5 < 0 )
goto LABEL_8;
LABEL_4:
if ( a5 >= a3 )
a5 = a3 - (a5 - a3) - 1;
return *(float *)(a1 + 4LL * (a4 + a2 * a5));
}

canonical_decompiled_code:
float __fastcall func1(__int64 a1, int a2, int a3, int a4, int a5)
{
if ( a4 < 0 )
{
a4 = ~a4;
LABEL_3:
if ( a5 >= 0 )
goto LABEL_4;
LABEL_8:
a5 = ~a5;
return *(float *)(a1 + 4LL * (a4 + a2 * a5));
}
if ( a4 < a2 )
goto LABEL_3;
a4 = a2 - (a4 - a2) - 1;
if ( a5 < 0 )
goto LABEL_8;
LABEL_4:
if ( a5 >= a3 )
a5 = a3 - (a5 - a3) - 1;
return *(float *)(a1 + 4LL * (a4 + a2 * a5));
}

original_code:
float KBND_SYMMETRIC(const float *img, int w, int h, int x, int y, float bnd_const)
{
    if (x<0) x=-1-x;
    else if (x>=w) x=(w-(x-w))-1;
    if (y<0) y=-1-y;
    else if (y>=h) y=(h-(y-h))-1;
    return img[y*w + x];
}

canonical_original_code:
float KBND_SYMMETRIC(float *img, int w, int h, int x, int y, float bnd_const)
{
    if (x<0) x=-1-x;
    else if (x>=w) x=(w-(x-w))-1;
    if (y<0) y=-1-y;
    else if (y>=h) y=(h-(y-h))-1;
    return img[y*w + x];
}

variable_types:
img
float *

variable_types: w int

variable_types: h int

variable_types: x int

variable_types: y int

return_type: float


decompiled_code:
float __fastcall KBND_REPLICATE(__int64 a1, int a2, int a3, int a4, int a5)
{
int v6; // esi

v6 = 0;
if ( a4 < 0 )
a4 = 0;
if ( a2 <= a4 )
a4 = a2 - 1;
if ( a5 >= 0 )
v6 = a5;
if ( v6 >= a3 )
v6 = a3 - 1;
return *(float *)(a1 + 4LL * (a4 + a2 * v6));
}

original_code:
float KBND_REPLICATE(const float *img, int w, int h, int x, int y, float bnd_const)
{
    if (x<0) x=0;
    if (x>=w) x=w-1;
    if (y<0) y=0;
    if (y>=h) y=h-1;
    return img[y*w + x];
}

canonical_original_code:
float KBND_REPLICATE(float *img, int w, int h, int x, int y, float bnd_const)
{
    if (x<0) x=0;
    if (x>=w) x=w-1;
    if (y<0) y=0;
    if (y>=h) y=h-1;
    return img[y*w + x];
}


decompiled_code:
float __fastcall KBND_CONSTANT(__int64 a1, int a2, int a3, int a4, int a5)
{
float result; // xmm0_4

if ( a4 < 0 )
a4 = 0;
if ( a5 < 0 )
a5 = 0;
if ( a4 < a2 && a5 < a3 )
result = *(float *)(a1 + 4LL * (a4 + a2 * a5));
return result;
}

canonical_decompiled_code:
float __fastcall func3(__int64 a1, int a2, int a3, int a4, int a5)
{
float result; // xmm0_4

if ( a4 < 0 )
a4 = 0;
if ( a5 < 0 )
a5 = 0;
if ( a4 < a2 && a5 < a3 )
result = *(float *)(a1 + 4LL * (a4 + a2 * a5));
return result;
}

original_code:
float KBND_CONSTANT(const float *img, int w, int h, int x, int y, float bnd_const)
{
    if (x<0) x=0;
    if (y<0) y=0;
    if (x>=w || y>=h)
        return bnd_const;
    return img[y*w + x];
}

canonical_original_code:
float KBND_CONSTANT(float *img, int w, int h, int x, int y, float bnd_const)
{
    if (x<0) x=0;
    if (y<0) y=0;
    if (x>=w || y>=h)
        return bnd_const;
    return img[y*w + x];
}


clamp

original_code:
float clamp(float low, float value, float high) {
    return (value < low) ? low : ((value > high) ? high : value);
}

variable_types: low float

variable_types: value float

variable_types: high float


interpolate

original_code:
int interpolate(const unsigned char *image, int width, int components, float x, float y, int offset) {
    int stride = width * components;
    float px = x - floor(x);
    float py = y - floor(y);
    int x1 = floor(x);
    int x2 = ceil(x);
    int y1 = floor(y);
    int y2 = ceil(y);
    float top = (float) image[y1 * stride + x1 * components + offset] * (1.0 - px) +
                (float) image[y1 * stride + x2 * components + offset] * px;
    float bot = (float) image[y2 * stride + x1 * components + offset] * (1.0 - px) +
                (float) image[y2 * stride + x2 * components + offset] * px;
    return (top * (1.0 - py)) + (bot * py);
}

canonical_original_code:
int interpolate(unsigned char *image, int width, int components, float x, float y, int offset) {
    int stride = width * components;
    float px = x - floor(x);
    float py = y - floor(y);
    int x1 = floor(x);
    int x2 = ceil(x);
    int y1 = floor(y);
    int y2 = ceil(y);
    float top = (float) image[y1 * stride + x1 * components + offset] * (1.0 - px) +
                (float) image[y1 * stride + x2 * components + offset] * px;
    float bot = (float) image[y2 * stride + x1 * components + offset] * (1.0 - px) +
                (float) image[y2 * stride + x2 * components + offset] * px;
    return (top * (1.0 - py)) + (bot * py);
}

variable_types:
image
unsigned char *

variable_types: width int

variable_types: components int

variable_types: x float

variable_types: y float

variable_types: offset int

variable_types: stride int

variable_types: px float

variable_types: py float

variable_types: top float

variable_types: bot float


meanPixelError

original_code:
float meanPixelError(const unsigned char *original, const unsigned char *compressed, int width, int height, int components) {
    float pme = 0.0;
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            for (int z = 0; z < components; z++) {
                int offset = y * width * components + x * components + z;
                pme += abs(original[offset] - compressed[offset]);
            }
        }
    }
    return pme / (width * height * components);
}

canonical_original_code:
float meanPixelError(unsigned char *original, unsigned char *compressed, int width, int height, int components) {
    float pme = 0.0;
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            for (int z = 0; z < components; z++) {
                int offset = y * width * components + x * components + z;
                pme += abs(original[offset] - compressed[offset]);
            }
        }
    }
    return pme / (width * height * components);
}

variable_types:
original
unsigned char *

variable_types:
compressed
unsigned char *

variable_types: height int

variable_types: pme float

variable_types: z int


defish

original_code:
void defish(const unsigned char *input, unsigned char *output, int width, int height, int components, float strength, float zoom) {
    const int cx = width / 2;
    const int cy = height / 2;
    const float len = sqrt(width * width + height * height);
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            float dx = (cx - x) * zoom;
            float dy = (cy - y) * zoom;
            float r = sqrt(dx * dx + dy * dy) / len * strength;
            float theta = 1.0;
            if (r != 0.0) {
                theta = atan(r) / r;
            }
            dx = clamp(0.0, (float) width / 2.0 - theta * dx, width);
            dy = clamp(0.0, (float) height / 2.0 - theta * dy, height);
            for (int z = 0; z < components; z++) {
                output[y * width * components + x * components + z] = interpolate(input, width, components, dx, dy, z);
            }
        }
    }
}

canonical_original_code:
void defish(unsigned char *input, unsigned char *output, int width, int height, int components, float strength, float zoom) {
    int cx = width / 2;
    int cy = height / 2;
    float len = sqrt(width * width + height * height);
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            float dx = (cx - x) * zoom;
            float dy = (cy - y) * zoom;
            float r = sqrt(dx * dx + dy * dy) / len * strength;
            float theta = 1.0;
            if (r != 0.0) {
                theta = atan(r) / r;
            }
            dx = clamp(0.0, (float) width / 2.0 - theta * dx, width);
            dy = clamp(0.0, (float) height / 2.0 - theta * dy, height);
            for (int z = 0; z < components; z++) {
                output[y * width * components + x * components + z] = interpolate(input, width, components, dx, dy, z);
            }
        }
    }
}

variable_types:
input
unsigned char *

variable_types:
output
unsigned char *

variable_types: strength float

variable_types: zoom float

variable_types: cx int

variable_types: cy int

variable_types: len float

variable_types: y int

variable_types: x int

variable_types: dx float

variable_types: dy float

variable_types: r float

variable_types: theta float


grayscale

original_code:
long grayscale(const unsigned char *input, unsigned char **output, int width, int height) {
    int stride = width * 3;
    *output = malloc(width * height);
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            (*output)[y * width + x] = input[y * stride + x * 3] * 0.299 +
                                       input[y * stride + x * 3 + 1] * 0.587 +
                                       input[y * stride + x * 3 + 2] * 0.114 + 0.5;
        }
    }
    return width * height;
}

canonical_original_code:
long grayscale(unsigned char *input, unsigned char **output, int width, int height) {
    int stride = width * 3;
    *output = malloc(width * height);
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            (*output)[y * width + x] = input[y * stride + x * 3] * 0.299 +
                                       input[y * stride + x * 3 + 1] * 0.587 +
                                       input[y * stride + x * 3 + 2] * 0.114 + 0.5;
        }
    }
    return width * height;
}

variable_types:
output
unsigned char **

variable_types: width int

variable_types: stride int

return_type: long


maxluma

decompiled_code:
__int64 __fastcall maxluma(_BYTE *a1, int a2, int a3, int a4)
{
__int64 v5; // r9
unsigned int v6; // er8
int v7; // esi
__int64 v8; // rcx
_BYTE *v9; // rax

if ( a4 <= 0 )
return 0LL;
v5 = a2;
v6 = 0;
v7 = 0;
v8 = (__int64)&a1[a3 - 1 + 1];
do
{
v9 = a1;
if ( a3 > 0 )
{
do
{
if ( (unsigned __int8)v6 < *v9 )
v6 = (unsigned __int8)*v9;
++v9;
}
while ( v9 != (_BYTE *)v8 );
}
++v7;
a1 += v5;
v8 += v5;
}
while ( a4 != v7 );
return v6;
}

original_code:
static uint8_t maxluma(uint8_t *buf, int stride, int width, int height)
{
    uint8_t *in = buf;
    uint8_t max = 0;
    int i, j;
    for (i = 0; i < height; i++) {
        for (j = 0; j < width; j++)
            max = (in[j] > max ? in[j] : max);
        in += stride;
    }
    return max;
}

canonical_original_code:
static unsigned char maxluma(unsigned char *buf, int stride, int width, int height)
{
    unsigned char *in = buf;
    unsigned char max = 0;
    int i; int j;
    for (i = 0; i < height; i++) {
        for (j = 0; j < width; j++)
            max = (in[j] > max ? in[j] : max);
        in += stride;
    }
    return max;
}

variable_types:
buf
unsigned char *

variable_types: height int

variable_types:
in
unsigned char *

variable_types:
max
unsigned char

variable_types: i int

variable_types: j int

return_type: unsigned char


original_code:
static double psnr_factor(uint8_t *orig, uint8_t *cmp, int orig_stride,
                          int cmp_stride, int width, int height, uint8_t max)
{
    uint8_t *old, *new;
    double ret;
    int sum;
    int i, j;
    sum = 0;
    old = orig;
    new = cmp;
    for (i = 0; i < height; i++) {
        for (j = 0; j < width; j++)
            sum += (old[j] - new[j]) * (old[j] - new[j]);
        old += orig_stride;
        new += cmp_stride;
    }
    ret = (double) sum / (double) (width * height);
    ret = 10.0 * log10(65025.0 / ret);
    if (max > 128)
        ret /= 50.0;
    else
        ret /= (0.0016 * (double) (max * max)) - (0.38 * (double) max + 72.5);
    return ((ret < 1.0 ? ret : 1.0) > 0.0 ? (ret < 1.0 ? ret : 1.0) : 0.0);
}

canonical_original_code:
static double psnr_factor(unsigned char *orig, unsigned char *cmp, int orig_stride, int cmp_stride, int width, int height, unsigned char max)
{
    unsigned char *old; unsigned char *new;
    double ret;
    int sum;
    int i; int j;
    sum = 0;
    old = orig;
    new = cmp;
    for (i = 0; i < height; i++) {
        for (j = 0; j < width; j++)
            sum += (old[j] - new[j]) * (old[j] - new[j]);
        old += orig_stride;
        new += cmp_stride;
    }
    ret = (double) sum / (double) (width * height);
    ret = 10.0 * log10(65025.0 / ret);
    if (max > 128)
        ret /= 50.0;
    else
        ret /= (0.0016 * (double) (max * max)) - (0.38 * (double) max + 72.5);
    return ((ret < 1.0 ? ret : 1.0) > 0.0 ? (ret < 1.0 ? ret : 1.0) : 0.0);
}

variable_types:
orig
unsigned char *

variable_types:
cmp
unsigned char *

variable_types:
old
unsigned char *

variable_types:
new
unsigned char *

variable_types: ret double

variable_types: sum int

return_type: double


decompiled_code:
double __fastcall smallfry_metric(_BYTE *a1, __int64 a2, int a3, int a4)
{
unsigned __int8 v6; // r14
double v7; // xmm9_8

v6 = maxluma(a1, a3, a3, a4);
v7 = psnr_factor((__int64)a1, a2, a3, a3, a3, a4, v6);
return 37.1891885161239 * v7 + COERCE_DOUBLE(aae_factor((__int64)a1, a2, a3, a3, a3, a4, v6)) * 78.5328607296973;
}

original_code:
double smallfry_metric(uint8_t *inbuf, uint8_t *outbuf, int width, int height)
{
    double p, a, b;
    uint8_t max;
    max = maxluma(inbuf, width, width, height);
    p = psnr_factor(inbuf, outbuf, width, width, width, height, max);
    a = aae_factor(inbuf, outbuf, width, width, width, height, max);
    b = p * 37.1891885161239 + a * 78.5328607296973;
    return b;
}

canonical_original_code:
double smallfry_metric(unsigned char *inbuf, unsigned char *outbuf, int width, int height)
{
    double p; double a; double b;
    unsigned char max;
    max = maxluma(inbuf, width, width, height);
    p = psnr_factor(inbuf, outbuf, width, width, width, height, max);
    a = aae_factor(inbuf, outbuf, width, width, width, height, max);
    b = p * 37.1891885161239 + a * 78.5328607296973;
    return b;
}

variable_types:
inbuf
unsigned char *

variable_types:
outbuf
unsigned char *

variable_types: p double

variable_types: a double

variable_types: b double


scale

decompiled_code:
unsigned __int64 __fastcall scale(__int64 a1, int a2, int a3, unsigned __int64 *a4, int a5, int a6)
{
unsigned __int64 result; // rax
int v13; // edi
int v14; // esi
__int64 v15; // rdx
float v16; // xmm0_4

result = (unsigned __int64)malloc(a6 * (__int64)a5);
*a4 = result;
if ( a6 > 0 )
{
v13 = 0;
v14 = 0;
do
{
if ( a5 > 0 )
{
v15 = v13;
LODWORD(result) = 0;
do
{
v16 = (float)(int)result;
result = (unsigned int)(result + 1);
*(_BYTE *)(*a4 + v15++) = *(_BYTE *)(a1
+ a2 * (int)((float)((float)((float)v14 / (float)a6) * (float)a3) + 0.5)
+ (int)((float)((float)(v16 / (float)a5) * (float)a2) + 0.5));
}
while ( a5 != (_DWORD)result );
}
++v14;
v13 += a5;
}
while ( a6 != v14 );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(__int64 a1, int a2, int a3, unsigned __int64 *a4, int a5, int a6)
{
unsigned __int64 result; // rax
int v13; // edi
int v14; // esi
__int64 v15; // rdx
float v16; // xmm0_4

result = (unsigned __int64)malloc(a6 * (__int64)a5);
*a4 = result;
if ( a6 > 0 )
{
v13 = 0;
v14 = 0;
do
{
if ( a5 > 0 )
{
v15 = v13;
LODWORD(result) = 0;
do
{
v16 = (float)(int)result;
result = (unsigned int)(result + 1);
*(_BYTE *)(*a4 + v15++) = *(_BYTE *)(a1
+ a2 * (int)((float)((float)((float)v14 / (float)a6) * (float)a3) + 0.5)
+ (int)((float)((float)(v16 / (float)a5) * (float)a2) + 0.5));
}
while ( a5 != (_DWORD)result );
}
++v14;
v13 += a5;
}
while ( a6 != v14 );
}
return result;
}

original_code:
void scale(unsigned char *image, int width, int height, unsigned char **newImage, int newWidth, int newHeight) {
    *newImage = malloc((unsigned long) newWidth * newHeight);
    for (int y = 0; y < newHeight; y++) {
        for (int x = 0; x < newWidth; x++) {
            int oldY = (float) y / newHeight * height + 0.5;
            int oldX = (float) x / newWidth * width + 0.5;
            (*newImage)[y * newWidth + x] = image[oldY * width + oldX];
        }
    }
}

variable_types:
image
unsigned char *

variable_types: width int

variable_types:
newImage
unsigned char **

variable_types: newWidth int

variable_types: newHeight int

variable_types: y int

variable_types: x int

variable_types: oldY int

variable_types: oldX int


genHash

decompiled_code:
void *__fastcall genHash(__int64 a1, int a2, int a3, _QWORD *a4)
{
void *result; // rax
int v9; // edi
int v10; // esi

result = malloc(a3 * (__int64)a2);
*a4 = result;
if ( a3 > 0 )
{
v9 = 0;
v10 = 0;
do
{
result = (void *)v9;
if ( a2 > 0 )
{
do
{
*((_BYTE *)result + *a4) = *((_BYTE *)result + a1) < *((_BYTE *)result + a1 + 1);
result = (char *)result + 1;
}
while ( result != (void *)((unsigned int)(a2 - 1) + 1LL + v9) );
}
++v10;
v9 += a2;
}
while ( a3 != v10 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(__int64 a1, int a2, int a3, _QWORD *a4)
{
void *result; // rax
int v9; // edi
int v10; // esi

result = malloc(a3 * (__int64)a2);
*a4 = result;
if ( a3 > 0 )
{
v9 = 0;
v10 = 0;
do
{
result = (void *)v9;
if ( a2 > 0 )
{
do
{
*((_BYTE *)result + *a4) = *((_BYTE *)result + a1) < *((_BYTE *)result + a1 + 1);
result = (char *)result + 1;
}
while ( result != (void *)((unsigned int)(a2 - 1) + 1LL + v9) );
}
++v10;
v9 += a2;
}
while ( a3 != v10 );
}
return result;
}

original_code:
void genHash(unsigned char *image, int width, int height, unsigned char **hash) {
    *hash = malloc((unsigned long) width * height);
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            int pos = y * width + x;
            (*hash)[pos] = image[pos] < image[pos + 1];
        }
    }
}

variable_types: height int

variable_types:
hash
unsigned char **

variable_types: pos int


jpegHash

decompiled_code:
__int64 __fastcall jpegHash(__int64 a1, _QWORD *a2, int a3)
{
__int64 v4; // r8
__int64 result; // rax
int v6; // [rsp+8h] [rbp-30h] BYREF
int v7; // [rsp+Ch] [rbp-2Ch] BYREF
void *ptr; // [rsp+10h] [rbp-28h] BYREF
void *v9; // [rsp+18h] [rbp-20h] BYREF

v4 = decodeFile(a1, &ptr, 2LL, &v6, &v7, 1LL);
result = 1LL;
if ( v4 )
{
scale((__int64)ptr, v6, v7, (unsigned __int64 *)&v9, a3, a3);
free(ptr);
genHash((__int64)v9, a3, a3, a2);
free(v9);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, _QWORD *a2, int a3)
{
__int64 v4; // r8
__int64 result; // rax
int v6; // [rsp+8h] [rbp-30h] BYREF
int v7; // [rsp+Ch] [rbp-2Ch] BYREF
void *ptr; // [rsp+10h] [rbp-28h] BYREF
void *v9; // [rsp+18h] [rbp-20h] BYREF

v4 = decodeFile(a1, &ptr, 2LL, &v6, &v7, 1LL);
result = 1LL;
if ( v4 )
{
func0((__int64)ptr, v6, v7, (unsigned __int64 *)&v9, a3, a3);
free(ptr);
func1((__int64)v9, a3, a3, a2);
free(v9);
result = 0LL;
}
return result;
}

original_code:
int jpegHash(const char *filename, unsigned char **hash, int size) {
    unsigned char *image;
    unsigned long imageSize = 0;
    unsigned char *scaled;
    int width, height;
    imageSize = decodeFile(filename, &image, FILETYPE_JPEG, &width, &height, JCS_GRAYSCALE);
    if (!imageSize)
        return 1;
    scale(image, width, height, &scaled, size, size);
    free(image);
    genHash(scaled, size, size, hash);
    free(scaled);
    return 0;
}

canonical_original_code:
int jpegHash(char *filename, unsigned char **hash, int size) {
    unsigned char *image;
    unsigned long imageSize = 0;
    unsigned char *scaled;
    int width; int height;
    imageSize = decodeFile(filename, &image, FILETYPE_JPEG, &width, &height, JCS_GRAYSCALE);
    if (!imageSize)
        return 1;
    scale(image, width, height, &scaled, size, size);
    free(image);
    genHash(scaled, size, size, hash);
    free(scaled);
    return 0;
}

variable_types:
filename
char *

variable_types: size int

variable_types:
imageSize
unsigned long

variable_types:
scaled
unsigned char *


jpegHashFromBuffer

decompiled_code:
__int64 __fastcall jpegHashFromBuffer(__int64 a1, __int64 a2, _QWORD *a3, int a4)
{
__int64 v6; // r8
__int64 result; // rax
int v8; // [rsp+10h] [rbp-30h] BYREF
int v9; // [rsp+14h] [rbp-2Ch] BYREF
void *ptr; // [rsp+18h] [rbp-28h] BYREF
void *v11; // [rsp+20h] [rbp-20h] BYREF

v6 = decodeFileFromBuffer(a1, a2, &ptr, 2LL, &v8, &v9, 1LL);
result = 1LL;
if ( v6 )
{
scale((__int64)ptr, v8, v9, (unsigned __int64 *)&v11, a4, a4);
free(ptr);
genHash((__int64)v11, a4, a4, a3);
free(v11);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, _QWORD *a3, int a4)
{
__int64 v6; // r8
__int64 result; // rax
int v8; // [rsp+10h] [rbp-30h] BYREF
int v9; // [rsp+14h] [rbp-2Ch] BYREF
void *ptr; // [rsp+18h] [rbp-28h] BYREF
void *v11; // [rsp+20h] [rbp-20h] BYREF

v6 = decodeFileFromBuffer(a1, a2, &ptr, 2LL, &v8, &v9, 1LL);
result = 1LL;
if ( v6 )
{
func0((__int64)ptr, v8, v9, (unsigned __int64 *)&v11, a4, a4);
free(ptr);
func1((__int64)v11, a4, a4, a3);
free(v11);
result = 0LL;
}
return result;
}

original_code:
int jpegHashFromBuffer(unsigned char *imageBuf, long bufSize, unsigned char **hash, int size) {
    unsigned char *image;
    unsigned long imageSize = 0;
    unsigned char *scaled;
    int width, height;
    imageSize = decodeFileFromBuffer(imageBuf, bufSize, &image, FILETYPE_JPEG, &width, &height, JCS_GRAYSCALE);
    if (!imageSize)
        return 1;
    scale(image, width, height, &scaled, size, size);
    free(image);
    genHash(scaled, size, size, hash);
    free(scaled);
    return 0;
}

canonical_original_code:
int jpegHashFromBuffer(unsigned char *imageBuf, long bufSize, unsigned char **hash, int size) {
    unsigned char *image;
    unsigned long imageSize = 0;
    unsigned char *scaled;
    int width; int height;
    imageSize = decodeFileFromBuffer(imageBuf, bufSize, &image, FILETYPE_JPEG, &width, &height, JCS_GRAYSCALE);
    if (!imageSize)
        return 1;
    scale(image, width, height, &scaled, size, size);
    free(image);
    genHash(scaled, size, size, hash);
    free(scaled);
    return 0;
}

variable_types:
imageBuf
unsigned char *

variable_types: bufSize long


hammingDist

decompiled_code:
__int64 __fastcall hammingDist(__int64 a1, __int64 a2, unsigned int a3)
{
unsigned int v3; // er8
__int64 v4; // rcx
__int64 v5; // rax
bool v6; // dl

v3 = a3;
if ( a3 )
{
v4 = a3;
v5 = 0LL;
v3 = 0;
do
{
v6 = *(_BYTE *)(a1 + v5) != *(_BYTE *)(a2 + v5);
++v5;
v3 += v6;
}
while ( v5 != v4 );
}
return v3;
}

original_code:
unsigned int hammingDist(const unsigned char *hash1, const unsigned char *hash2, int hashLength) {
    unsigned int dist = 0;
    for (unsigned int x = 0; x < hashLength; x++) {
        if (hash1[x] != hash2[x]) {
            dist++;
        }
    }
    return dist;
}

canonical_original_code:
unsigned int hammingDist(unsigned char *hash1, unsigned char *hash2, int hashLength) {
    unsigned int dist = 0;
    for (unsigned int x = 0; x < hashLength; x++) {
        if (hash1[x] != hash2[x]) {
            dist++;
        }
    }
    return dist;
}

variable_types: hashLength int

variable_types:
dist
unsigned int

variable_types:
x
unsigned int


original_code:
float iqa_mse(const unsigned char *ref, const unsigned char *cmp, int w, int h, int stride)
{
    int error, offset;
    unsigned long long sum=0;
    int ww,hh;
    for (hh=0; hh<h; ++hh) {
        offset = hh*stride;
        for (ww=0; ww<w; ++ww, ++offset) {
            error = ref[offset] - cmp[offset];
            sum += error * error;
        }
    }
    return (float)( (double)sum / (double)(w*h) );
}

canonical_original_code:
float iqa_mse(unsigned char *ref, unsigned char *cmp, int w, int h, int stride)
{
    int error; int offset;
    unsigned long long sum = 0;
    int ww; int hh;
    for (hh=0; hh<h; ++hh) {
        offset = hh*stride;
        for (ww=0; ww<w; ++ww, ++offset) {
            error = ref[offset] - cmp[offset];
            sum += error * error;
        }
    }
    return (float)( (double)sum / (double)(w*h) );
}

variable_types:
ref
unsigned char *

variable_types:
cmp
unsigned char *

variable_types: w int

variable_types: h int

variable_types: stride int

variable_types: error int

variable_types: offset int

variable_types:
sum
unsigned long long

variable_types: ww int

variable_types: hh int


decompiled_code:
float iqa_psnr()
{
double v0; // xmm0_8

v0 = iqa_mse();
return log10((float)(65025.0 / *(float *)&v0)) * 10.0;
}

canonical_decompiled_code:
float func0()
{
double v0; // xmm0_8

v0 = iqa_mse();
return log10((float)(65025.0 / *(float *)&v0)) * 10.0;
}

original_code:
float iqa_psnr(const unsigned char *ref, const unsigned char *cmp, int w, int h, int stride)
{
    const int L_sqd = 255 * 255;
    return (float)( 10.0 * log10( L_sqd / iqa_mse(ref,cmp,w,h,stride) ) );
}

canonical_original_code:
float iqa_psnr(unsigned char *ref, unsigned char *cmp, int w, int h, int stride)
{
    int L_sqd = 255 * 255;
    return (float)( 10.0 * log10( L_sqd / iqa_mse(ref,cmp,w,h,stride) ) );
}


repo: danielmartin/localthresh

decompiled_code:
void __noreturn print_usage()
{
fwrite("Usage: localthresh Mean input_image output_image [-w window_size] [-c constant]\n", 1uLL, 0x50uLL, stderr);
fwrite(
" localthresh Niblack input_image output_image [-w window_size] [-c constant] [-k std_constant]\n",
1uLL,
0x65uLL,
stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func0()
{
fwrite("Usage: localthresh Mean input_image output_image [-w window_size] [-c constant]\n", 1uLL, 0x50uLL, stderr);
fwrite(
" localthresh Niblack input_image output_image [-w window_size] [-c constant] [-k std_constant]\n",
1uLL,
0x65uLL,
stderr);
exit(1);
}

original_code:
static void
print_usage()
{
    fprintf(stderr, "Usage: localthresh Mean input_image output_image [-w window_size] [-c constant]\n");
    fprintf(stderr, "       localthresh Niblack input_image output_image [-w window_size] [-c constant] [-k std_constant]\n");
    exit(1);
}


repo: danielverkamp/mathparse

original_code:
static tok get_number_oct(const char **s)
{
 const char *end;
 tok ret;
 ret.type = T_NONE;
 ret.val = 0.0;
 if ((*s)[0] != '0' || (*s)[1] != 'o')
  return ret;
 for (end = *s + 2; *end >= '0' && *end <= '7'; end++)
  ret.val = ret.val * 8.0 + (*end - '0');
 if (end != *s + 2) {
  ret.type = T_NUM;
  *s = end;
 }
 return ret;
}

canonical_original_code:
static struct tok get_number_oct(char **s)
{
 char *end;
 struct tok ret;
 ret.type = T_NONE;
 ret.val = 0.0;
 if ((*s)[0] != '0' || (*s)[1] != 'o')
  return ret;
 for (end = *s + 2; *end >= '0' && *end <= '7'; end++)
  ret.val = ret.val * 8.0 + (*end - '0');
 if (end != *s + 2) {
  ret.type = T_NUM;
  *s = end;
 }
 return ret;
}

variable_types:
s
char **

variable_types:
end
char *

variable_types: struct tok { int type; double val; char *str; }


original_code:
static tok get_number_hex(const char **s)
{
 const char *end;
 tok ret;
 ret.type = T_NONE;
 ret.val = 0.0;
 if ((*s)[0] != '0' || (*s)[1] != 'x')
  return ret;
 for (end = *s + 2; ; end++) {
  if (*end >= '0' && *end <= '9')
   ret.val = ret.val * 16.0 + (*end - '0');
  else if (*end >= 'A' && *end <= 'F')
   ret.val = ret.val * 16.0 + (*end - 'A') + 10.0;
  else if (*end >= 'a' && *end <= 'f')
   ret.val = ret.val * 16.0 + (*end - 'a') + 10.0;
  else
   break;
 }
 if (end != *s + 2) {
  ret.type = T_NUM;
  *s = end;
 }
 return ret;
}

canonical_original_code:
static struct tok get_number_hex(char **s)
{
 char *end;
 struct tok ret;
 ret.type = T_NONE;
 ret.val = 0.0;
 if ((*s)[0] != '0' || (*s)[1] != 'x')
  return ret;
 for (end = *s + 2; ; end++) {
  if (*end >= '0' && *end <= '9')
   ret.val = ret.val * 16.0 + (*end - '0');
  else if (*end >= 'A' && *end <= 'F')
   ret.val = ret.val * 16.0 + (*end - 'A') + 10.0;
  else if (*end >= 'a' && *end <= 'f')
   ret.val = ret.val * 16.0 + (*end - 'a') + 10.0;
  else
   break;
 }
 if (end != *s + 2) {
  ret.type = T_NUM;
  *s = end;
 }
 return ret;
}

return_type: struct tok { int type; double val; char *str; }


original_code:
static tok get_number_bin(const char **s)
{
 const char *end;
 tok ret;
 ret.type = T_NONE;
 ret.val = 0.0;
 if ((*s)[0] != '0' || (*s)[1] != 'b')
  return ret;
 for (end = *s + 2; *end == '0' || *end == '1'; end++)
  ret.val = ret.val * 2.0 + (*end - '0');
 if (end != *s + 2) {
  ret.type = T_NUM;
  *s = end;
 }
 return ret;
}

canonical_original_code:
static struct tok get_number_bin(char **s)
{
 char *end;
 struct tok ret;
 ret.type = T_NONE;
 ret.val = 0.0;
 if ((*s)[0] != '0' || (*s)[1] != 'b')
  return ret;
 for (end = *s + 2; *end == '0' || *end == '1'; end++)
  ret.val = ret.val * 2.0 + (*end - '0');
 if (end != *s + 2) {
  ret.type = T_NUM;
  *s = end;
 }
 return ret;
}

user_defined_types: struct tok { int type; double val; char *str; }


factorial

decompiled_code:
double __fastcall factorial(double a1)
{
double result; // xmm0_8

result = *(double *)&LC4;
if ( a1 > 170.0 )
return 1.0 / 0.0;
if ( a1 > 0.0 )
result = factorial(a1 - 1.0) * a1;
return result;
}

canonical_decompiled_code:
double __fastcall func3(double a1)
{
double result; // xmm0_8

result = *(double *)&LC4;
if ( a1 > 170.0 )
return 1.0 / 0.0;
if ( a1 > 0.0 )
result = func3(a1 - 1.0) * a1;
return result;
}

original_code:
static double factorial(double x)
{
 if (__builtin_isnan (x)) return x;
 if (x > 170.0) return 1.0/0.0;
 if (x <= 0.0) return 1.0;
 return x * factorial(x - 1.0);
}

variable_types: x double


decompiled_code:
__int64 __fastcall get_number_dec(__int64 a1, char **a2, double a3)
{
int v3; // ecx
int v4; // edx
int v5; // er8
int v8; // edi
char *v9; // rsi
char *v10; // rbx
char v11; // al
void *v12; // rsp
const char *v13; // rax
int v14; // eax
__int64 result; // rax
__int64 v16; // [rsp+0h] [rbp-20h] BYREF

v3 = 0;
v4 = 0;
v5 = 0;
v8 = 0;
v9 = *a2;
v10 = v9;
v11 = *v9;
if ( *v9 > 69 )
goto LABEL_8;
while ( v11 > 42 )
{
switch ( v11 )
{
case '+':
if ( !v4 )
goto LABEL_12;
if ( v10 == v9 )
goto LABEL_23;
v3 |= v8;
if ( v3 )
goto LABEL_13;
v8 = v4;
++v10;
break;
case '-':
if ( !v4 )
goto LABEL_12;
if ( v10 == v9 )
goto LABEL_23;
v8 |= v3;
if ( v8 )
goto LABEL_13;
v3 = v4;
++v10;
break;
case '.':
if ( v5 )
goto LABEL_12;
v5 = 1;
goto LABEL_6;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
LABEL_6:
++v10;
break;
case 'E':
goto LABEL_9;
default:
goto LABEL_12;
}
while ( 1 )
{
v11 = *v10;
if ( *v10 <= 69 )
break;
LABEL_8:
if ( v11 != 101 )
goto LABEL_12;
LABEL_9:
if ( v10 == v9 )
goto LABEL_23;
if ( v4 )
goto LABEL_13;
v4 = 1;
++v10;
}
}
LABEL_12:
if ( v10 == v9 )
{
LABEL_23:
v14 = 0;
}
else
{
LABEL_13:
v12 = alloca((int)v10 - (int)v9 + 1 + 8LL);
v13 = (const char *)memcpy(&v16, v9, (int)v10 - (int)v9);
v13[(int)v10 - (int)v9] = 0;
a3 = atof(v13);
*a2 = v10;
v14 = 8;
}
*(_DWORD *)a1 = v14;
result = a1;
*(_QWORD *)(a1 + 16) = 0LL;
*(double *)(a1 + 8) = a3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, char **a2, double a3)
{
int v3; // ecx
int v4; // edx
int v5; // er8
int v8; // edi
char *v9; // rsi
char *v10; // rbx
char v11; // al
void *v12; // rsp
const char *v13; // rax
int v14; // eax
__int64 result; // rax
__int64 v16; // [rsp+0h] [rbp-20h] BYREF

v3 = 0;
v4 = 0;
v5 = 0;
v8 = 0;
v9 = *a2;
v10 = v9;
v11 = *v9;
if ( *v9 > 69 )
goto LABEL_8;
while ( v11 > 42 )
{
switch ( v11 )
{
case '+':
if ( !v4 )
goto LABEL_12;
if ( v10 == v9 )
goto LABEL_23;
v3 |= v8;
if ( v3 )
goto LABEL_13;
v8 = v4;
++v10;
break;
case '-':
if ( !v4 )
goto LABEL_12;
if ( v10 == v9 )
goto LABEL_23;
v8 |= v3;
if ( v8 )
goto LABEL_13;
v3 = v4;
++v10;
break;
case '.':
if ( v5 )
goto LABEL_12;
v5 = 1;
goto LABEL_6;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
LABEL_6:
++v10;
break;
case 'E':
goto LABEL_9;
default:
goto LABEL_12;
}
while ( 1 )
{
v11 = *v10;
if ( *v10 <= 69 )
break;
LABEL_8:
if ( v11 != 101 )
goto LABEL_12;
LABEL_9:
if ( v10 == v9 )
goto LABEL_23;
if ( v4 )
goto LABEL_13;
v4 = 1;
++v10;
}
}
LABEL_12:
if ( v10 == v9 )
{
LABEL_23:
v14 = 0;
}
else
{
LABEL_13:
v12 = alloca((int)v10 - (int)v9 + 1 + 8LL);
v13 = (const char *)memcpy(&v16, v9, (int)v10 - (int)v9);
v13[(int)v10 - (int)v9] = 0;
a3 = atof(v13);
*a2 = v10;
v14 = 8;
}
*(_DWORD *)a1 = v14;
result = a1;
*(_QWORD *)(a1 + 16) = 0LL;
*(double *)(a1 + 8) = a3;
return result;
}

original_code:
static tok get_number_dec(const char **s)
{
 const char *end;
 tok ret;
 char *num;
 int dot_count = 0, e_count = 0, neg_count = 0, plus_count = 0;
 ret.type = T_NONE;
 for (end = *s; ; end++) {
  switch (*end) {
  case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
   break;
  case '.':
   if (dot_count++)
    goto done;
   break;
  case 'e': case 'E':
   if (end == *s || e_count++)
    goto done;
   break;
  case '-':
   if (!e_count)
    goto done;
   if (end == *s)
    goto done;
   if (plus_count || neg_count++)
    goto done;
   break;
  case '+':
   if (!e_count)
    goto done;
   if (end == *s)
    goto done;
   if (neg_count || plus_count++)
    goto done;
   break;
  default:
   goto done;
  }
 }
done:
 if (end != *s) {
  int len = end - *s;
  num = __builtin_alloca (len + 1);
  memcpy(num, *s, len);
  num[len] = 0;
  ret.type = T_NUM;
  ret.val = atof(num);
  *s = end;
 }
 return ret;
}

canonical_original_code:
static struct tok get_number_dec(char **s)
{
 char *end;
 struct tok ret;
 char *num;
 int dot_count = 0; int e_count = 0; int neg_count = 0; int plus_count = 0;
 ret.type = T_NONE;
 for (end = *s; ; end++) {
  switch (*end) {
  case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
   break;
  case '.':
   if (dot_count++)
    goto done;
   break;
  case 'e': case 'E':
   if (end == *s || e_count++)
    goto done;
   break;
  case '-':
   if (!e_count)
    goto done;
   if (end == *s)
    goto done;
   if (plus_count || neg_count++)
    goto done;
   break;
  case '+':
   if (!e_count)
    goto done;
   if (end == *s)
    goto done;
   if (neg_count || plus_count++)
    goto done;
   break;
  default:
   goto done;
  }
 }
done:
 if (end != *s) {
  int len = end - *s;
  num = __builtin_alloca (len + 1);
  memcpy(num, *s, len);
  num[len] = 0;
  ret.type = T_NUM;
  ret.val = atof(num);
  *s = end;
 }
 return ret;
}

variable_types:
num
char *

variable_types: len int


original_code:
static void get_token(parse_ctx *ctx)
{
 char c;
 if (ctx->t.type == T_WORD) {
  free(ctx->t.str);
  ctx->t.str = ((void *)0);
 }
 ctx->t.type = T_NONE;
 do {
  ctx->t = get_number(ctx->s);
  if (ctx->t.type == T_NONE) {
   ctx->t = get_word(ctx->s);
  }
  if (ctx->t.type == T_NONE) {
   c = **ctx->s;
   (*ctx->s)++;
   switch (c) {
   case 0: ctx->t.type = T_EOF; break;
   case '+': ctx->t.type = T_PLUS; break;
   case '-': ctx->t.type = T_MINUS; break;
   case '*': ctx->t.type = T_MUL; break;
   case '/': ctx->t.type = T_DIV; break;
   case '(': ctx->t.type = T_LPAREN; break;
   case ')': ctx->t.type = T_RPAREN; break;
   case '^': ctx->t.type = T_POW; break;
   case '!': ctx->t.type = T_BANG; break;
   case '%': ctx->t.type = T_MOD; break;
   }
  }
 } while (ctx->t.type == T_NONE && c);
}

canonical_original_code:
static void get_token(struct parse_ctx *ctx)
{
 char c;
 if (ctx->t.type == T_WORD) {
  free(ctx->t.str);
  ctx->t.str = ((void *)0);
 }
 ctx->t.type = T_NONE;
 do {
  ctx->t = get_number(ctx->s);
  if (ctx->t.type == T_NONE) {
   ctx->t = get_word(ctx->s);
  }
  if (ctx->t.type == T_NONE) {
   c = **ctx->s;
   (*ctx->s)++;
   switch (c) {
   case 0: ctx->t.type = T_EOF; break;
   case '+': ctx->t.type = T_PLUS; break;
   case '-': ctx->t.type = T_MINUS; break;
   case '*': ctx->t.type = T_MUL; break;
   case '/': ctx->t.type = T_DIV; break;
   case '(': ctx->t.type = T_LPAREN; break;
   case ')': ctx->t.type = T_RPAREN; break;
   case '^': ctx->t.type = T_POW; break;
   case '!': ctx->t.type = T_BANG; break;
   case '%': ctx->t.type = T_MOD; break;
   }
  }
 } while (ctx->t.type == T_NONE && c);
}

variable_types: struct parse_ctx { struct tok { int type; double val; char *str; } t; char **s; } *

variable_types: c char

user_defined_types: struct parse_ctx { struct tok t; char **s; }


decompiled_code:
void **__fastcall find_const(char *s2)
{
void **v1; // r12
const char *v3; // rdi

v1 = &consts;
v3 = (const char *)&unk_10E0;
do
{
if ( !strcasecmp(v3, s2) )
return v1;
v3 = (const char *)v1[2];
v1 += 2;
}
while ( v3 );
return 0LL;
}

canonical_decompiled_code:
void **__fastcall func7(char *s2)
{
void **v1; // r12
const char *v3; // rdi

v1 = &consts;
v3 = (const char *)&unk_10E0;
do
{
if ( !strcasecmp(v3, s2) )
return v1;
v3 = (const char *)v1[2];
v1 += 2;
}
while ( v3 );
return 0LL;
}

original_code:
static const constant *find_const(const char *name)
{
 const constant *c;
 for (c = consts; c->name; c++)
  if (!strcasecmp(c->name, name))
   return c;
 return ((void *)0);
}

canonical_original_code:
static struct constant *find_const(char *name)
{
 struct constant *c;
 for (c = consts; c->name; c++)
  if (!strcasecmp(c->name, name))
   return c;
 return ((void *)0);
}

variable_types:
name
char *

variable_types: struct constant { char *name; double val; } *


decompiled_code:
char **__fastcall find_funct(char *s2)
{
char **v1; // r12
const char *v3; // rdi

v1 = &functs;
v3 = "acos";
do
{
if ( !strcasecmp(v3, s2) )
return v1;
v3 = v1[2];
v1 += 2;
}
while ( v3 );
return 0LL;
}

canonical_decompiled_code:
char **__fastcall func8(char *s2)
{
char **v1; // r12
const char *v3; // rdi

v1 = &functs;
v3 = "acos";
do
{
if ( !strcasecmp(v3, s2) )
return v1;
v3 = v1[2];
v1 += 2;
}
while ( v3 );
return 0LL;
}

original_code:
static const funct *find_funct(const char *name)
{
 const funct *f;
 for (f = functs; f->name; f++)
  if (!strcasecmp(f->name, name))
   return f;
 return ((void *)0);
}

canonical_original_code:
static struct funct *find_funct(char *name)
{
 struct funct *f;
 for (f = functs; f->name; f++)
  if (!strcasecmp(f->name, name))
   return f;
 return ((void *)0);
}

variable_types: struct funct { char *name; double (*funct)(double); } *


decompiled_code:
double __fastcall rand_dbl(double a1)
{
return (double)rand() * a1 / 2147483647.0;
}

canonical_decompiled_code:
double __fastcall func9(double a1)
{
return (double)rand() * a1 / 2147483647.0;
}

original_code:
static double rand_dbl(double max)
{
 return (double)rand() * max / (double)2147483647;
}

variable_types: max double


roll

decompiled_code:
__int64 __fastcall roll(int a1, int a2)
{
int v2; // ebx
unsigned int v3; // er12

if ( a1 <= 0 || a2 <= 0 )
return 0LL;
if ( a1 > 100 )
return (unsigned int)-1;
v2 = 0;
v3 = 0;
do
{
++v2;
v3 += rand() % a2 + 1;
}
while ( a1 > v2 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, int a2)
{
int v2; // ebx
unsigned int v3; // er12

if ( a1 <= 0 || a2 <= 0 )
return 0LL;
if ( a1 > 100 )
return (unsigned int)-1;
v2 = 0;
v3 = 0;
do
{
++v2;
v3 += rand() % a2 + 1;
}
while ( a1 > v2 );
return v3;
}

original_code:
static int roll(int x, int y)
{
 int ret = 0, i;
 if (x <= 0 || y <= 0)
  return 0;
 if (x > 100 || y > 2147483647)
  return -1;
 for (i = 0; i < x; i++)
  ret += (rand() % y) + 1;
 return ret;
}

canonical_original_code:
static int roll(int x, int y)
{
 int ret = 0; int i;
 if (x <= 0 || y <= 0)
  return 0;
 if (x > 100 || y > 2147483647)
  return -1;
 for (i = 0; i < x; i++)
  ret += (rand() % y) + 1;
 return ret;
}

variable_types: x int

variable_types: y int

variable_types: ret int

variable_types: i int


err

decompiled_code:
void __noreturn err()
{
fwrite("parse error\n", 1uLL, 0xCuLL, stderr);
}

canonical_decompiled_code:
void __noreturn func11()
{
fwrite("parse error\n", 1uLL, 0xCuLL, stderr);
}

original_code:
static void err()
{
 fprintf(stderr, "parse error\n");
}


power

original_code:
static double power(parse_ctx *ctx)
{
 double ret;
 switch (ctx->t.type) {
 case T_NUM:
  ret = ctx->t.val;
  get_token(ctx);
  return ret;
 case T_WORD:
 {
  const constant *c = find_const(ctx->t.str);
  const funct *f = ((void *)0);
  if (!c) {
   f = find_funct(ctx->t.str);
   if (!f) {
    err();
    return 0.0;
   }
   get_token(ctx);
   get_token(ctx);
   ret = f->funct(expr(ctx));
  } else {
   ret = c->val;
  }
  get_token(ctx);
  return ret;
 }
 case T_LPAREN:
  get_token(ctx);
  ret = expr(ctx);
  get_token(ctx);
  return ret;
 default:
  err();
  return 0.0;
 }
}

canonical_original_code:
static double power(struct parse_ctx *ctx)
{
 double ret;
 switch (ctx->t.type) {
 case T_NUM:
  ret = ctx->t.val;
  get_token(ctx);
  return ret;
 case T_WORD:
 {
  struct constant *c = find_const(ctx->t.str);
  struct funct *f = ((void *)0);
  if (!c) {
   f = find_funct(ctx->t.str);
   if (!f) {
    err();
    return 0.0;
   }
   get_token(ctx);
   get_token(ctx);
   ret = f->funct(expr(ctx));
  } else {
   ret = c->val;
  }
  get_token(ctx);
  return ret;
 }
 case T_LPAREN:
  get_token(ctx);
  ret = expr(ctx);
  get_token(ctx);
  return ret;
 default:
  err();
  return 0.0;
 }
}

variable_types: ret double

user_defined_types: struct constant { char *name; double val; }

user_defined_types: struct funct { char *name; double (*funct)(double); }


unary

original_code:
static double unary(parse_ctx *ctx)
{
 double ret;
 ret = power(ctx);
 while (ctx->t.type == T_POW ||
  (ctx->t.type == T_WORD &&
  tolower(ctx->t.str[0]) == 'd' &&
  ctx->t.str[1] == '\0'))
 {
  int type = ctx->t.type;
  get_token(ctx);
  if (type == T_POW)
   ret = pow(ret, power(ctx));
  else
   ret = roll(ret, power(ctx));
 }
 return ret;
}

canonical_original_code:
static double unary(struct parse_ctx *ctx)
{
 double ret;
 ret = power(ctx);
 while (ctx->t.type == T_POW ||
  (ctx->t.type == T_WORD &&
  tolower(ctx->t.str[0]) == 'd' &&
  ctx->t.str[1] == '\0'))
 {
  int type = ctx->t.type;
  get_token(ctx);
  if (type == T_POW)
   ret = pow(ret, power(ctx));
  else
   ret = roll(ret, power(ctx));
 }
 return ret;
}

variable_types: type int


factor

original_code:
static double factor(parse_ctx *ctx)
{
 double ret;
 int sign = 1;
 while (ctx->t.type == T_MINUS || ctx->t.type == T_PLUS) {
  if (ctx->t.type == T_MINUS)
   sign = -sign;
  get_token(ctx);
 }
 ret = sign * unary(ctx);
 while (ctx->t.type == T_BANG) {
  get_token(ctx);
  ret = factorial(floor(ret));
 }
 return ret;
}

canonical_original_code:
static double factor(struct parse_ctx *ctx)
{
 double ret;
 int sign = 1;
 while (ctx->t.type == T_MINUS || ctx->t.type == T_PLUS) {
  if (ctx->t.type == T_MINUS)
   sign = -sign;
  get_token(ctx);
 }
 ret = sign * unary(ctx);
 while (ctx->t.type == T_BANG) {
  get_token(ctx);
  ret = factorial(floor(ret));
 }
 return ret;
}

variable_types: sign int


term

decompiled_code:
double __fastcall term(int *a1, __m128 a2)
{
int v2; // ebx
double v4; // [rsp+8h] [rbp-20h]

*(double *)a2.m128_u64 = factor(a1, a2);
v4 = *(double *)a2.m128_u64;
while ( 1 )
{
v2 = *a1;
if ( (unsigned int)(*a1 - 4) > 1 && v2 != 12 )
break;
get_token((__int64)a1, a2);
switch ( v2 )
{
case 4:
*(double *)a2.m128_u64 = factor(a1, a2) * v4;
v4 = *(double *)a2.m128_u64;
break;
case 5:
*(double *)a2.m128_u64 = factor(a1, a2);
v4 = v4 / *(double *)a2.m128_u64;
break;
case 12:
*(double *)a2.m128_u64 = factor(a1, a2);
v4 = (double)(int)((unsigned int)(int)v4 % (__int64)(unsigned int)(int)*(double *)a2.m128_u64);
break;
}
}
return v4;
}

canonical_decompiled_code:
double __fastcall func15(int *a1, __m128 a2)
{
int v2; // ebx
double v4; // [rsp+8h] [rbp-20h]

*(double *)a2.m128_u64 = func14(a1, a2);
v4 = *(double *)a2.m128_u64;
while ( 1 )
{
v2 = *a1;
if ( (unsigned int)(*a1 - 4) > 1 && v2 != 12 )
break;
func6((__int64)a1, a2);
switch ( v2 )
{
case 4:
*(double *)a2.m128_u64 = func14(a1, a2) * v4;
v4 = *(double *)a2.m128_u64;
break;
case 5:
*(double *)a2.m128_u64 = func14(a1, a2);
v4 = v4 / *(double *)a2.m128_u64;
break;
case 12:
*(double *)a2.m128_u64 = func14(a1, a2);
v4 = (double)(int)((unsigned int)(int)v4 % (__int64)(unsigned int)(int)*(double *)a2.m128_u64);
break;
}
}
return v4;
}

original_code:
static double term(parse_ctx *ctx)
{
 double ret;
 int op;
 ret = factor(ctx);
 while (ctx->t.type == T_MUL || ctx->t.type == T_DIV || ctx->t.type == T_MOD) {
  op = ctx->t.type;
  get_token(ctx);
  if (op == T_MUL)
   ret *= factor(ctx);
  else if (op == T_DIV)
   ret /= factor(ctx);
  else if (op == T_MOD)
   ret = (double)((long long)ret % (long long)factor(ctx));
 }
 return ret;
}

canonical_original_code:
static double term(struct parse_ctx *ctx)
{
 double ret;
 int op;
 ret = factor(ctx);
 while (ctx->t.type == T_MUL || ctx->t.type == T_DIV || ctx->t.type == T_MOD) {
  op = ctx->t.type;
  get_token(ctx);
  if (op == T_MUL)
   ret *= factor(ctx);
  else if (op == T_DIV)
   ret /= factor(ctx);
  else if (op == T_MOD)
   ret = (double)((long long)ret % (long long)factor(ctx));
 }
 return ret;
}

variable_types: op int


expr

decompiled_code:
double __fastcall expr(int *a1, __m128 a2)
{
int v2; // ebp
double i; // [rsp+8h] [rbp-20h]

*(double *)a2.m128_u64 = term(a1, a2);
for ( i = *(double *)a2.m128_u64; ; i = *(double *)a2.m128_u64 )
{
v2 = *a1;
if ( (unsigned int)(*a1 - 2) > 1 )
break;
while ( 1 )
{
get_token((__int64)a1, a2);
if ( v2 == 2 )
break;
*(double *)a2.m128_u64 = term(a1, a2);
v2 = *a1;
i = i - *(double *)a2.m128_u64;
if ( (unsigned int)(*a1 - 2) > 1 )
return i;
}
*(double *)a2.m128_u64 = term(a1, a2) + i;
}
return i;
}

original_code:
static double expr(parse_ctx *ctx)
{
 double ret;
 int op;
 ret = term(ctx);
 while (ctx->t.type == T_PLUS || ctx->t.type == T_MINUS) {
  op = ctx->t.type;
  get_token(ctx);
  if (op == T_PLUS)
   ret += term(ctx);
  else if (op == T_MINUS)
   ret -= term(ctx);
 }
 return ret;
}

canonical_original_code:
static double expr(struct parse_ctx *ctx)
{
 double ret;
 int op;
 ret = term(ctx);
 while (ctx->t.type == T_PLUS || ctx->t.type == T_MINUS) {
  op = ctx->t.type;
  get_token(ctx);
  if (op == T_PLUS)
   ret += term(ctx);
  else if (op == T_MINUS)
   ret -= term(ctx);
 }
 return ret;
}


parse

original_code:
double parse(const char *s)
{
 parse_ctx ctx;
 ctx.t.str = ((void *)0);
 ctx.s = &s;
 get_token(&ctx);
 return expr(&ctx);
}

canonical_original_code:
double parse(char *s)
{
 struct parse_ctx ctx;
 ctx.t.str = ((void *)0);
 ctx.s = &s;
 get_token(&ctx);
 return expr(&ctx);
}

variable_types:
s
char *

variable_types: struct parse_ctx { struct tok { int type; double val; char *str; } t; char **s; }


repo: danihegglin/ChronosAndroid

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

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

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

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

original_code:
void
ndn_digest_destroy(struct ndn_digest **pd)
{
    if (*pd != ((void *)0)) {
        free(*pd);
        *pd = ((void *)0);
    }
}

variable_types: struct ndn_digest { enum ndn_digest_id { NDN_DIGEST_DEFAULT=0, NDN_DIGEST_SHA1=1, NDN_DIGEST_SHA224=2, NDN_DIGEST_SHA256=3, NDN_DIGEST_SHA384=4, NDN_DIGEST_SHA512=5 } id; unsigned short sz; short ready; struct SHA256state_st { unsigned int h[8]; unsigned int Nl; unsigned int data[16]; unsigned int num; } sha256_ctx; } **

user_defined_types: struct ndn_digest { enum ndn_digest_id id; unsigned short sz; short ready; struct SHA256state_st sha256_ctx; }


decompiled_code:
__int64 __fastcall ndn_digest_getid(unsigned int *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int *a1)
{
return *a1;
}

original_code:
enum ndn_digest_id
ndn_digest_getid(struct ndn_digest *d)
{
    return(d->id);
}

variable_types: struct ndn_digest { enum ndn_digest_id { NDN_DIGEST_DEFAULT=0, NDN_DIGEST_SHA1=1, NDN_DIGEST_SHA224=2, NDN_DIGEST_SHA256=3, NDN_DIGEST_SHA384=4, NDN_DIGEST_SHA512=5 } id; unsigned short sz; short ready; struct SHA256state_st { unsigned int h[8]; unsigned int Nl; unsigned int data[16]; unsigned int num; } sha256_ctx; } *