repo: vieux/dcpu-vv

decompiled_code:
bool __fastcall basic_operation(__int64 errnum, unsigned __int16 a2, const char *a3, _WORD *a4)
{
int v4; // ebx
__int64 v6; // rcx

v6 = (unsigned __int16)*a4;
*(_QWORD *)(errnum + 131096) += *((unsigned __int8 *)&basic_opcodes + 4 * a2 + 3);
switch ( a2 )
{
case 1u:
LOWORD(v4) = (_WORD)a3;
goto LABEL_3;
case 2u:
LOWORD(v4) = v6 + (_WORD)a3;
*(_WORD *)(errnum + 131094) = ((unsigned __int16)v6 + (unsigned int)(unsigned __int16)a3) >> 16;
goto LABEL_3;
case 3u:
LOWORD(v4) = v6 - (_WORD)a3;
*(_WORD *)(errnum + 131094) = -(((unsigned __int16)v6 - (unsigned int)(unsigned __int16)a3) >> 16 != 0);
goto LABEL_3;
case 4u:
LOWORD(v4) = (_WORD)a3 * v6;
*(_WORD *)(errnum + 131094) = ((unsigned __int16)a3 * (unsigned int)(unsigned __int16)v6) >> 16;
goto LABEL_3;
case 5u:
if ( (_WORD)a3 )
{
LOWORD(v4) = (unsigned __int16)v6 / (unsigned __int16)a3;
*(_WORD *)(errnum + 131094) = ((_DWORD)v6 << 16) / (int)(unsigned __int16)a3;
}
else
{
*(_WORD *)(errnum + 131094) = 0;
LOWORD(v4) = 0;
}
goto LABEL_3;
case 6u:
LOWORD(v4) = 0;
if ( (_WORD)a3 )
LOWORD(v4) = (unsigned __int16)v6 % (unsigned __int16)a3;
goto LABEL_3;
case 7u:
v4 = (unsigned __int16)v6 << (char)a3;
*(_WORD *)(errnum + 131094) = HIWORD(v4);
goto LABEL_3;
case 8u:
v4 = (int)(unsigned __int16)v6 >> (char)a3;
*(_WORD *)(errnum + 131094) = (unsigned __int16)v6 << 16 >> (char)a3;
goto LABEL_3;
case 9u:
LOWORD(v4) = (unsigned __int16)a3 & v6;
goto LABEL_3;
case 0xAu:
LOWORD(v4) = (unsigned __int16)a3 | v6;
goto LABEL_3;
case 0xBu:
LOWORD(v4) = (unsigned __int16)a3 ^ v6;
goto LABEL_3;
case 0xCu:
return (_WORD)v6 != (unsigned __int16)a3;
case 0xDu:
return (_WORD)v6 == (unsigned __int16)a3;
case 0xEu:
return (unsigned __int16)v6 <= (unsigned __int16)a3;
case 0xFu:
return ((unsigned __int16)a3 & (unsigned __int16)v6) == 0;
default:
error((int)"Invalide Opcode", errnum, a3, v6);
LABEL_3:
*a4 = v4;
return 0;
}
}

canonical_decompiled_code:
bool __fastcall func0(__int64 errnum, unsigned __int16 a2, const char *a3, _WORD *a4)
{
int v4; // ebx
__int64 v6; // rcx

v6 = (unsigned __int16)*a4;
*(_QWORD *)(errnum + 131096) += *((unsigned __int8 *)&basic_opcodes + 4 * a2 + 3);
switch ( a2 )
{
case 1u:
LOWORD(v4) = (_WORD)a3;
goto LABEL_3;
case 2u:
LOWORD(v4) = v6 + (_WORD)a3;
*(_WORD *)(errnum + 131094) = ((unsigned __int16)v6 + (unsigned int)(unsigned __int16)a3) >> 16;
goto LABEL_3;
case 3u:
LOWORD(v4) = v6 - (_WORD)a3;
*(_WORD *)(errnum + 131094) = -(((unsigned __int16)v6 - (unsigned int)(unsigned __int16)a3) >> 16 != 0);
goto LABEL_3;
case 4u:
LOWORD(v4) = (_WORD)a3 * v6;
*(_WORD *)(errnum + 131094) = ((unsigned __int16)a3 * (unsigned int)(unsigned __int16)v6) >> 16;
goto LABEL_3;
case 5u:
if ( (_WORD)a3 )
{
LOWORD(v4) = (unsigned __int16)v6 / (unsigned __int16)a3;
*(_WORD *)(errnum + 131094) = ((_DWORD)v6 << 16) / (int)(unsigned __int16)a3;
}
else
{
*(_WORD *)(errnum + 131094) = 0;
LOWORD(v4) = 0;
}
goto LABEL_3;
case 6u:
LOWORD(v4) = 0;
if ( (_WORD)a3 )
LOWORD(v4) = (unsigned __int16)v6 % (unsigned __int16)a3;
goto LABEL_3;
case 7u:
v4 = (unsigned __int16)v6 << (char)a3;
*(_WORD *)(errnum + 131094) = HIWORD(v4);
goto LABEL_3;
case 8u:
v4 = (int)(unsigned __int16)v6 >> (char)a3;
*(_WORD *)(errnum + 131094) = (unsigned __int16)v6 << 16 >> (char)a3;
goto LABEL_3;
case 9u:
LOWORD(v4) = (unsigned __int16)a3 & v6;
goto LABEL_3;
case 0xAu:
LOWORD(v4) = (unsigned __int16)a3 | v6;
goto LABEL_3;
case 0xBu:
LOWORD(v4) = (unsigned __int16)a3 ^ v6;
goto LABEL_3;
case 0xCu:
return (_WORD)v6 != (unsigned __int16)a3;
case 0xDu:
return (_WORD)v6 == (unsigned __int16)a3;
case 0xEu:
return (unsigned __int16)v6 <= (unsigned __int16)a3;
case 0xFu:
return ((unsigned __int16)a3 & (unsigned __int16)v6) == 0;
default:
error((int)"Invalide Opcode", errnum, a3, v6);
LABEL_3:
*a4 = v4;
return 0;
}
}

original_code:
_Bool basic_operation(dcpu16 *cpu, u16 code , u16 b, u16 *toSet)
{
  u16 a = *toSet;
  u32 result;
  cpu->cycle += basic_opcodes[code].cycle_cost;
  switch (code)
    {
    case 0x1: result = b; break;
    case 0x2: result = a+b; cpu->o = (result >> 16 ? 0x0001 : 0); break;
    case 0x3: result = a-b; cpu->o = (result >> 16 ? 0xFFFF : 0); break;
    case 0x4: result = a*b; cpu->o = (result >> 16); break;
    case 0x5: if (b) {result = a/b; cpu->o = (a << 16) / b; } else {result = cpu->o = 0;} break;
    case 0x6: if (b) {result = a%b;} else {result = 0;} break;
    case 0x7: result = a<<b; cpu->o = result >> 16; break;
    case 0x8: result = a>>b; cpu->o = ((a<<16)>>b); break;
    case 0x9: result = a&b; break;
    case 0xa: result = a|b; break;
    case 0xb: result = a^b; break;
    case 0xc: return (a != b);
    case 0xd: return (a == b);
    case 0xe: return (a <= b);
    case 0xf: return ((a&b) == 0);
    default:
      error("Invalide Opcode", cpu);
    }
  *toSet = result;
  return 0;
}

canonical_original_code:
_Bool basic_operation(struct dcpu16 *cpu, unsigned short code, unsigned short b, unsigned short *toSet)
{
  unsigned short a = *toSet;
  unsigned int result;
  cpu->cycle += basic_opcodes[code].cycle_cost;
  switch (code)
    {
    case 0x1: result = b; break;
    case 0x2: result = a+b; cpu->o = (result >> 16 ? 0x0001 : 0); break;
    case 0x3: result = a-b; cpu->o = (result >> 16 ? 0xFFFF : 0); break;
    case 0x4: result = a*b; cpu->o = (result >> 16); break;
    case 0x5: if (b) {result = a/b; cpu->o = (a << 16) / b; } else {result = cpu->o = 0;} break;
    case 0x6: if (b) {result = a%b;} else {result = 0;} break;
    case 0x7: result = a<<b; cpu->o = result >> 16; break;
    case 0x8: result = a>>b; cpu->o = ((a<<16)>>b); break;
    case 0x9: result = a&b; break;
    case 0xa: result = a|b; break;
    case 0xb: result = a^b; break;
    case 0xc: return (a != b);
    case 0xd: return (a == b);
    case 0xe: return (a <= b);
    case 0xf: return ((a&b) == 0);
    default:
      error("Invalide Opcode", cpu);
    }
  *toSet = result;
  return 0;
}

variable_types: struct dcpu16 { unsigned short unused; unsigned short ram[65536]; unsigned short r[8]; unsigned short pc; unsigned short sp; unsigned short o; long cycle; char *program_name; } *

variable_types:
code
unsigned short

variable_types:
b
unsigned short

variable_types:
toSet
unsigned short *

variable_types:
a
unsigned short

variable_types:
result
unsigned int


decompiled_code:
__int64 __fastcall extended_operation(__int64 errnum, unsigned __int16 a2, const char *a3)
{
unsigned __int16 v3; // ax

if ( a2 == 1 )
{
v3 = *(_WORD *)(errnum + 131092) - 1;
*(_WORD *)(errnum + 131092) = v3;
*(_WORD *)(errnum + 2LL * v3 + 2) = *(_WORD *)(errnum + 131090);
*(_WORD *)(errnum + 131090) = (_WORD)a3;
}
else
{
error((int)"Invalide Opcode", errnum, a3);
}
*(_QWORD *)(errnum + 131096) += *((unsigned __int8 *)&non_basic_opcodes + 4 * a2 + 3);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 errnum, unsigned __int16 a2, const char *a3)
{
unsigned __int16 v3; // ax

if ( a2 == 1 )
{
v3 = *(_WORD *)(errnum + 131092) - 1;
*(_WORD *)(errnum + 131092) = v3;
*(_WORD *)(errnum + 2LL * v3 + 2) = *(_WORD *)(errnum + 131090);
*(_WORD *)(errnum + 131090) = (_WORD)a3;
}
else
{
error((int)"Invalide Opcode", errnum, a3);
}
*(_QWORD *)(errnum + 131096) += *((unsigned __int8 *)&non_basic_opcodes + 4 * a2 + 3);
return 0LL;
}

original_code:
_Bool extended_operation(dcpu16 *cpu, u16 code , u16 a)
{
  switch (code)
    {
    case 0x1: cpu->ram[--(cpu->sp)] = cpu->pc; cpu->pc = a; break;
    default: error("Invalide Opcode", cpu);
    }
  cpu->cycle += non_basic_opcodes[code].cycle_cost;
  return 0;
}

canonical_original_code:
_Bool extended_operation(struct dcpu16 *cpu, unsigned short code, unsigned short a)
{
  switch (code)
    {
    case 0x1: cpu->ram[--(cpu->sp)] = cpu->pc; cpu->pc = a; break;
    default: error("Invalide Opcode", cpu);
    }
  cpu->cycle += non_basic_opcodes[code].cycle_cost;
  return 0;
}

user_defined_types: struct dcpu16 { unsigned short unused; unsigned short ram[65536]; unsigned short r[8]; unsigned short pc; unsigned short sp; unsigned short o; long cycle; char *program_name; }


error

decompiled_code:
void __fastcall __noreturn error(const char *a1, __int64 a2)
{
if ( a2 )
{
fprintf(stderr, "[ERROR] %s as 0x%x, generating core file...\n", a1, *(unsigned __int16 *)(a2 + 131090));
core(a1, a2);
}
else
{
fprintf(stderr, "[ERROR] %s, generating core file...\n", a1);
}
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(const char *a1, __int64 a2)
{
if ( a2 )
{
fprintf(stderr, "[ERROR] %s as 0x%x, generating core file...\n", a1, *(unsigned __int16 *)(a2 + 131090));
func0(a1, a2);
}
else
{
fprintf(stderr, "[ERROR] %s, generating core file...\n", a1);
}
exit(1);
}

original_code:
void error(char *str, dcpu16 *cpu)
{
  if (cpu != ((void *)0))
    {
      fprintf(stderr, "[ERROR] %s as 0x%x, generating core file...\n", str, cpu->pc);
      core(str, cpu);
    }
  else
    fprintf(stderr, "[ERROR] %s, generating core file...\n", str);
  exit(1);
}

canonical_original_code:
void error(char *str, struct dcpu16 *cpu)
{
  if (cpu != ((void *)0))
    {
      fprintf(stderr, "[ERROR] %s as 0x%x, generating core file...\n", str, cpu->pc);
      core(str, cpu);
    }
  else
    fprintf(stderr, "[ERROR] %s, generating core file...\n", str);
  exit(1);
}

variable_types:
str
char *

return_type: void


skipInstruction

decompiled_code:
__int64 __fastcall skipInstruction(__int64 a1)
{
unsigned __int16 v1; // ax
unsigned __int16 v2; // bp
__int64 result; // rax

v1 = *(_WORD *)(a1 + 131090);
*(_WORD *)(a1 + 131090) = v1 + 1;
v2 = *(_WORD *)(a1 + 2LL * v1 + 2);
*(_WORD *)(a1 + 131090) += (unsigned __int8)opcode_pc_cost((v2 >> 4) & 0x3F);
result = (unsigned __int8)opcode_pc_cost(v2 >> 10);
*(_WORD *)(a1 + 131090) += (unsigned __int8)result;
++*(_QWORD *)(a1 + 131096);
return result;
}

original_code:
static inline void skipInstruction(dcpu16 *cpu)
{
  instruction i = {.value = cpu->ram[cpu->pc++]};
  cpu->pc += opcode_pc_cost(i.value_a);
  cpu->pc += opcode_pc_cost(i.value_b);
  cpu->cycle++;
}

canonical_original_code:
static inline void skipInstruction(struct dcpu16 *cpu)
{
  union instruction i = {.value = cpu->ram[cpu->pc++]};
  cpu->pc += opcode_pc_cost(i.value_a);
  cpu->pc += opcode_pc_cost(i.value_b);
  cpu->cycle++;
}

variable_types: union instruction { unsigned short value; struct { unsigned short opcode; unsigned short value_a; unsigned short value_b; }; }


handleInstruction

decompiled_code:
__int64 __fastcall handleInstruction(__int64 a1)
{
unsigned __int16 v1; // ax
unsigned __int16 v2; // bp
unsigned __int16 *v3; // rax
__int64 v5; // r12
unsigned __int16 *v6; // rax

v1 = *(_WORD *)(a1 + 131090);
*(_WORD *)(a1 + 131090) = v1 + 1;
v2 = *(_WORD *)(a1 + 2LL * v1 + 2);
if ( (v2 & 0xF) != 0 )
{
v5 = access_opcode(a1, (v2 >> 4) & 0x3F);
v6 = (unsigned __int16 *)access_opcode(a1, v2 >> 10);
if ( (unsigned __int8)basic_operation(a1, v2 & 0xF, *v6, v5) )
skipInstruction(a1);
}
else
{
v3 = (unsigned __int16 *)access_opcode(a1, v2 >> 10);
extended_operation(a1, (v2 >> 4) & 0x3F, *v3);
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
unsigned __int16 v1; // ax
unsigned __int16 v2; // bp
unsigned __int16 *v3; // rax
__int64 v5; // r12
unsigned __int16 *v6; // rax

v1 = *(_WORD *)(a1 + 131090);
*(_WORD *)(a1 + 131090) = v1 + 1;
v2 = *(_WORD *)(a1 + 2LL * v1 + 2);
if ( (v2 & 0xF) != 0 )
{
v5 = access_opcode(a1, (v2 >> 4) & 0x3F);
v6 = (unsigned __int16 *)access_opcode(a1, v2 >> 10);
if ( (unsigned __int8)basic_operation(a1, v2 & 0xF, *v6, v5) )
func0(a1);
}
else
{
v3 = (unsigned __int16 *)access_opcode(a1, v2 >> 10);
extended_operation(a1, (v2 >> 4) & 0x3F, *v3);
}
return 1LL;
}

original_code:
_Bool handleInstruction(dcpu16 *cpu)
{
  instruction i = {.value = cpu->ram[cpu->pc++]};
  if (i.opcode == 0) {
    extended_operation(cpu, i.value_a, *access_opcode(cpu, i.value_b));
  } else {
    if (basic_operation(cpu, i.opcode, *access_opcode(cpu, i.value_b), access_opcode(cpu, i.value_a)))
      skipInstruction(cpu);
  }
  return 1;
}

canonical_original_code:
_Bool handleInstruction(struct dcpu16 *cpu)
{
  union instruction i = {.value = cpu->ram[cpu->pc++]};
  if (i.opcode == 0) {
    extended_operation(cpu, i.value_a, *access_opcode(cpu, i.value_b));
  } else {
    if (basic_operation(cpu, i.opcode, *access_opcode(cpu, i.value_b), access_opcode(cpu, i.value_a)))
      skipInstruction(cpu);
  }
  return 1;
}

user_defined_types: union instruction { unsigned short value; struct { unsigned short opcode; unsigned short value_a; unsigned short value_b; }; }


decompiled_code:
__int64 __fastcall dcpu_start(__int64 a1)
{
const char *v1; // rdx

if ( !(unsigned __int8)loadFile() )
error((int)"Can't open file", 0, v1);
while ( (unsigned __int8)handleInstruction(a1) )
usleep(0x64u);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
const char *v1; // rdx

if ( !(unsigned __int8)loadFile() )
error((int)"Can't open file", 0, v1);
while ( (unsigned __int8)func1(a1) )
usleep(0x64u);
return 0LL;
}

original_code:
void* dcpu_start(void *arg)
{
  dcpu16 *cpu = arg;
  if (!loadFile(cpu))
    error("Can't open file", ((void *)0));
  while (handleInstruction(cpu))
    {
      usleep(100);
    }
  return ((void *)0);
}

canonical_original_code:
void *dcpu_start(void *arg)
{
  struct dcpu16 *cpu = arg;
  if (!loadFile(cpu))
    error("Can't open file", ((void *)0));
  while (handleInstruction(cpu))
    {
      usleep(100);
    }
  return ((void *)0);
}

variable_types:
arg
void *

return_type: void *


usage

decompiled_code:
int __fastcall usage(const char **a1)
{
return fprintf(stderr, "%s: [file.hex|file.bin ....]\n", *a1);
}

canonical_decompiled_code:
int __fastcall func0(const char **a1)
{
return fprintf(stderr, "%s: [file.hex|file.bin ....]\n", *a1);
}

original_code:
void usage(char **av)
{
  fprintf(stderr, "%s: [file.hex|file.bin ....]\n", av[0]);
}

variable_types:
av
char **


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

if ( a1 == 4 )
return 1LL;
if ( a1 > 4 )
{
result = 3LL;
if ( a1 != 6 )
result = (unsigned int)a1;
}
else
{
result = 4LL;
if ( a1 != 1 )
{
result = 6LL;
if ( a1 != 3 )
result = (unsigned int)a1;
}
}
return result;
}

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

if ( a1 == 4 )
return 1LL;
if ( a1 > 4 )
{
result = 3LL;
if ( a1 != 6 )
result = (unsigned int)a1;
}
else
{
result = 4LL;
if ( a1 != 1 )
{
result = 6LL;
if ( a1 != 3 )
result = (unsigned int)a1;
}
}
return result;
}

original_code:
int to_ncurses_color(int c)
{
  switch(c)
    {
    case 1: return 4;
    case 3: return 6;
    case 4: return 1;
    case 6: return 3;
    default: return c;
    }
}

variable_types: c int

return_type: int


repo: vigetlabs/bode

decompiled_code:
char *__fastcall file_get_extension(char *a1)
{
char *v1; // rax
char *v2; // rbx
char *stringp; // [rsp+8h] [rbp-10h] BYREF

stringp = a1;
do
{
v2 = v1;
v1 = strsep(&stringp, ".");
}
while ( v1 );
return v2;
}

canonical_decompiled_code:
char *__fastcall func0(char *a1)
{
char *v1; // rax
char *v2; // rbx
char *stringp; // [rsp+8h] [rbp-10h] BYREF

stringp = a1;
do
{
v2 = v1;
v1 = strsep(&stringp, ".");
}
while ( v1 );
return v2;
}

original_code:
char *
file_get_extension(char *filename)
{
    const char *d = ".";
    char *token,
         *ext,
         *fp = filename;
    while ((token = strsep(&fp, d)) != ((void *)0)) {
        ext = token;
    }
    return ext;
}

canonical_original_code:
char *file_get_extension(char *filename)
{
    char *d = ".";
    char *token; char *ext; char *fp = filename;
    while ((token = strsep(&fp, d)) != ((void *)0)) {
        ext = token;
    }
    return ext;
}

variable_types:
filename
char *

variable_types:
d
char *

variable_types:
token
char *

variable_types:
ext
char *

variable_types:
fp
char *

return_type: char *


decompiled_code:
__int64 __fastcall file_content_type_for(__int64 a1, char *a2)
{
char *v2; // rax

v2 = file_get_extension(a2);
return mime_types_find_content_type(a1, v2);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, char *a2)
{
char *v2; // rax

v2 = func0(a2);
return mime_types_find_content_type(a1, v2);
}

original_code:
char *
file_content_type_for(MimeTypes *mime_types, char *filename)
{
    char *ext = file_get_extension(filename);
    return mime_types_find_content_type(mime_types, ext);
}

canonical_original_code:
char *file_content_type_for(struct MimeTypes *mime_types, char *filename)
{
    char *ext = file_get_extension(filename);
    return mime_types_find_content_type(mime_types, ext);
}

variable_types: struct MimeTypes { struct MimeType { char *content_type; char *extension; } **types; int count; int allocated; } *

user_defined_types: struct MimeTypes { struct MimeType **types; int count; int allocated; }


decompiled_code:
_BOOL8 __fastcall ends_with(const char *a1, unsigned __int8 a2)
{
return a1[(int)strlen(a1)] == a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(const char *a1, unsigned __int8 a2)
{
return a1[(int)strlen(a1)] == a2;
}

original_code:
int
ends_with(char *path, char end)
{
    int index = strlen(path);
    return path[index] == end;
}

variable_types:
path
char *

variable_types: end char

variable_types: index int


decompiled_code:
char *__fastcall path_append(const char *a1, __int64 a2)
{
char *v2; // rbx
char *ptr; // [rsp+8h] [rbp-20h] BYREF

v2 = (char *)calloc(6uLL, 1uLL);
if ( ends_with(a1, 0x2Fu) )
{
*(_DWORD *)v2 = 1931834149;
}
else
{
*(_DWORD *)v2 = 623866661;
v2[4] = 115;
}
asprintf(&ptr, v2, a1, a2);
free(v2);
return ptr;
}

canonical_decompiled_code:
char *__fastcall func3(const char *a1, __int64 a2)
{
char *v2; // rbx
char *ptr; // [rsp+8h] [rbp-20h] BYREF

v2 = (char *)calloc(6uLL, 1uLL);
if ( func2(a1, 0x2Fu) )
{
*(_DWORD *)v2 = 1931834149;
}
else
{
*(_DWORD *)v2 = 623866661;
v2[4] = 115;
}
asprintf(&ptr, v2, a1, a2);
free(v2);
return ptr;
}

original_code:
char *
path_append(char *path, const char *filename)
{
    char *full_path;
    char *format = calloc(6, sizeof(char));
    if (ends_with(path, '/')) {
        strncpy(format, "%s%s", 4);
    } else {
        strncpy(format, "%s/%s", 5);
    }
    asprintf(&full_path, format, path, filename);
    free(format);
    return full_path;
}

canonical_original_code:
char *path_append(char *path, char *filename)
{
    char *full_path;
    char *format = calloc(6, sizeof(char));
    if (ends_with(path, '/')) {
        strncpy(format, "%s%s", 4);
    } else {
        strncpy(format, "%s/%s", 5);
    }
    asprintf(&full_path, format, path, filename);
    free(format);
    return full_path;
}

variable_types:
format
char *


decompiled_code:
_BOOL8 __fastcall file_is_type(const char *a1, int a2)
{
int v2; // edx
_BOOL8 result; // rax
struct stat v4; // [rsp+0h] [rbp-98h] BYREF

v2 = stat(a1, &v4);
result = 0LL;
if ( !v2 )
result = (v4.st_mode & a2) == a2;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(const char *a1, int a2)
{
int v2; // edx
_BOOL8 result; // rax
struct stat v4; // [rsp+0h] [rbp-98h] BYREF

v2 = stat(a1, &v4);
result = 0LL;
if ( !v2 )
result = (v4.st_mode & a2) == a2;
return result;
}

original_code:
int
file_is_type(char *filename, int type)
{
    struct stat fs;
    if (stat(filename, &fs) == 0) {
        return (fs.st_mode & type) == type;
    }
    return 0;
}

variable_types: type int

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
_BOOL8 __fastcall is_file(const char *a1)
{
return file_is_type(a1, 0x8000);
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(const char *a1)
{
return func4(a1, 0x8000);
}

original_code:
int
is_file(char *filename)
{
    return file_is_type(filename, 0100000);
}


decompiled_code:
_BOOL8 __fastcall is_dir(const char *a1)
{
return file_is_type(a1, 0x4000);
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(const char *a1)
{
return func4(a1, 0x4000);
}

original_code:
int
is_dir(char *filename)
{
    return file_is_type(filename, 0040000);
}


decompiled_code:
char *__fastcall file_path_for(char *s)
{
char *result; // rax
_BOOL4 v2; // edx

if ( is_file(s) )
return strdup(s);
v2 = is_dir(s);
result = 0LL;
if ( v2 )
result = path_append(s, (__int64)"index.html");
return result;
}

canonical_decompiled_code:
char *__fastcall func7(char *s)
{
char *result; // rax
_BOOL4 v2; // edx

if ( func5(s) )
return strdup(s);
v2 = func6(s);
result = 0LL;
if ( v2 )
result = func3(s, (__int64)"index.html");
return result;
}

original_code:
char *
file_path_for(char *requested_filename)
{
    char *filename = ((void *)0);
    if (is_file(requested_filename)) {
        filename = strdup(requested_filename);
    } else if (is_dir(requested_filename)) {
        filename = path_append(requested_filename, "index.html");
    }
    return filename;
}

canonical_original_code:
char *file_path_for(char *requested_filename)
{
    char *filename = ((void *)0);
    if (is_file(requested_filename)) {
        filename = strdup(requested_filename);
    } else if (is_dir(requested_filename)) {
        filename = path_append(requested_filename, "index.html");
    }
    return filename;
}


decompiled_code:
const char *__fastcall mime_types_find_content_type(__int64 **a1, const char *a2)
{
int v2; // eax
__int64 *v3; // rbx
__int64 v4; // r13
__int64 v5; // rbp

v2 = *((_DWORD *)a1 + 2);
if ( v2 <= 0 )
return "application/octet-stream";
v3 = *a1;
v4 = (__int64)&(*a1)[(unsigned int)(v2 - 1) + 1];
while ( 1 )
{
v5 = *v3;
if ( !strcmp(a2, *(const char **)(*v3 + 8)) )
break;
if ( ++v3 == (__int64 *)v4 )
return "application/octet-stream";
}
return *(const char **)v5;
}

canonical_decompiled_code:
const char *__fastcall func0(__int64 **a1, const char *a2)
{
int v2; // eax
__int64 *v3; // rbx
__int64 v4; // r13
__int64 v5; // rbp

v2 = *((_DWORD *)a1 + 2);
if ( v2 <= 0 )
return "application/octet-stream";
v3 = *a1;
v4 = (__int64)&(*a1)[(unsigned int)(v2 - 1) + 1];
while ( 1 )
{
v5 = *v3;
if ( !strcmp(a2, *(const char **)(*v3 + 8)) )
break;
if ( ++v3 == (__int64 *)v4 )
return "application/octet-stream";
}
return *(const char **)v5;
}

original_code:
char *
mime_types_find_content_type(MimeTypes *mime_types, char *ext)
{
    int i = 0;
    for (i = 0; i < mime_types->count; i++) {
        if (strcmp(ext, mime_types->types[i]->extension) == 0) {
            return mime_types->types[i]->content_type;
        }
    }
    return "application/octet-stream";
}

canonical_original_code:
char *mime_types_find_content_type(struct MimeTypes *mime_types, char *ext)
{
    int i = 0;
    for (i = 0; i < mime_types->count; i++) {
        if (strcmp(ext, mime_types->types[i]->extension) == 0) {
            return mime_types->types[i]->content_type;
        }
    }
    return "application/octet-stream";
}

variable_types: i int

user_defined_types: struct MimeType { char *content_type; char *extension; }


decompiled_code:
void __fastcall mime_type_free(void *ptr)
{
void *v2; // rdi
void *v3; // rdi

v2 = *(void **)ptr;
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 1);
if ( v3 )
free(v3);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
void *v2; // rdi
void *v3; // rdi

v2 = *(void **)ptr;
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 1);
if ( v3 )
free(v3);
free(ptr);
}

original_code:
void
mime_type_free(MimeType *mime_type)
{
    if (mime_type->content_type) { free(mime_type->content_type); }
    if (mime_type->extension) { free(mime_type->extension); }
    free(mime_type);
}

canonical_original_code:
void mime_type_free(struct MimeType *mime_type)
{
    if (mime_type->content_type) { free(mime_type->content_type); }
    if (mime_type->extension) { free(mime_type->extension); }
    free(mime_type);
}

variable_types: struct MimeType { char *content_type; char *extension; } *


decompiled_code:
void __fastcall mime_types_free(void *ptr)
{
__int64 v1; // rbx

if ( *((int *)ptr + 2) > 0 )
{
v1 = 0LL;
do
mime_type_free(*(void **)(*(_QWORD *)ptr + 8 * v1++));
while ( *((_DWORD *)ptr + 2) > (int)v1 );
}
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
__int64 v1; // rbx

if ( *((int *)ptr + 2) > 0 )
{
v1 = 0LL;
do
func1(*(void **)(*(_QWORD *)ptr + 8 * v1++));
while ( *((_DWORD *)ptr + 2) > (int)v1 );
}
free(*(void **)ptr);
free(ptr);
}

original_code:
void
mime_types_free(MimeTypes *mime_types)
{
    int i = 0;
    for (i = 0; i < mime_types->count; i++) {
        mime_type_free(mime_types->types[i]);
    }
    free(mime_types->types);
    free(mime_types);
}

canonical_original_code:
void mime_types_free(struct MimeTypes *mime_types)
{
    int i = 0;
    for (i = 0; i < mime_types->count; i++) {
        mime_type_free(mime_types->types[i]);
    }
    free(mime_types->types);
    free(mime_types);
}


decompiled_code:
void __fastcall config_free(void *ptr)
{
void *v2; // rdi
void *v3; // rdi

v2 = *(void **)ptr;
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 1);
if ( v3 )
free(v3);
free(ptr);
}

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

v2 = *(void **)ptr;
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 1);
if ( v3 )
free(v3);
free(ptr);
}

original_code:
void
config_free(Config *config)
{
    if (config->document_root) { free(config->document_root); }
    if (config->config_dir) { free(config->config_dir); }
    free(config);
}

canonical_original_code:
void config_free(struct Config *config)
{
    if (config->document_root) { free(config->document_root); }
    if (config->config_dir) { free(config->config_dir); }
    free(config);
}

variable_types: struct Config { char *document_root; char *config_dir; int port; } *


decompiled_code:
__int64 __fastcall write_value(void **a1, const char *a2, int a3)
{
char *v4; // rax

v4 = (char *)realloc(*a1, 8LL * a3);
*a1 = v4;
strncpy(v4, a2, a3 - 1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(void **a1, const char *a2, int a3)
{
char *v4; // rax

v4 = (char *)realloc(*a1, 8LL * a3);
*a1 = v4;
strncpy(v4, a2, a3 - 1);
return 0LL;
}

original_code:
int
write_value(char **target, char *value, int buf_length)
{
    *target = realloc(*target, buf_length * sizeof(char *));
    strncpy(*target, value, buf_length - 1);
    return 0;
}

variable_types:
target
char **

variable_types:
value
char *


decompiled_code:
void *config_create()
{
void *v0; // rbx

v0 = malloc(0x18uLL);
*(_QWORD *)v0 = 0LL;
*((_QWORD *)v0 + 1) = 0LL;
write_value((void **)v0, "root", 1024);
write_value((void **)v0 + 1, "config", 1024);
*((_DWORD *)v0 + 4) = 8080;
return v0;
}

original_code:
Config *
config_create()
{
    Config *config = malloc(sizeof(Config));
    config->document_root = ((void *)0);
    config->config_dir = ((void *)0);
    write_value(&config->document_root, "root", 1024);
    write_value(&config->config_dir, "config", 1024);
    config->port = 8080;
    return config;
}

canonical_original_code:
struct Config *config_create()
{
    struct Config *config = malloc(sizeof(Config));
    config->document_root = ((void *)0);
    config->config_dir = ((void *)0);
    write_value(&config->document_root, "root", 1024);
    write_value(&config->config_dir, "config", 1024);
    config->port = 8080;
    return config;
}

return_type: struct Config { char *document_root; char *config_dir; int port; } *


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

result = (__int64)a3;
switch ( a2 )
{
case 2:
return write_value((void **)(a1 + 8), a3, 1024);
case 3:
result = *(unsigned int *)a3;
*(_DWORD *)(a1 + 16) = result;
break;
case 1:
result = write_value((void **)a1, a3, 1024);
break;
}
return result;
}

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

result = (__int64)a3;
switch ( a2 )
{
case 2:
return func1((void **)(a1 + 8), a3, 1024);
case 3:
result = *(unsigned int *)a3;
*(_DWORD *)(a1 + 16) = result;
break;
case 1:
result = func1((void **)a1, a3, 1024);
break;
}
return result;
}

original_code:
void
config_set(Config *config, int attr, void *value)
{
    switch (attr) {
        case 1:
            write_value(&config->document_root, (char *)value, 1024);
            break;
        case 2:
            write_value(&config->config_dir, (char *)value, 1024);
            break;
        case 3:
            config->port = *(int *)value;
            break;
        default:
            break;
    }
}

canonical_original_code:
void config_set(struct Config *config, int attr, void *value)
{
    switch (attr) {
        case 1:
            write_value(&config->document_root, (char *)value, 1024);
            break;
        case 2:
            write_value(&config->config_dir, (char *)value, 1024);
            break;
        case 3:
            config->port = *(int *)value;
            break;
        default:
            break;
    }
}

variable_types: attr int

variable_types:
value
void *

user_defined_types: struct Config { char *document_root; char *config_dir; int port; }


decompiled_code:
void __fastcall header_free(void *ptr)
{
void *v2; // rdi
void *v3; // rdi

v2 = *(void **)ptr;
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 1);
if ( v3 )
free(v3);
free(ptr);
}

original_code:
void
header_free(Header *header)
{
    if (header->key) { free(header->key); }
    if (header->value) { free(header->value); }
    free(header);
}

canonical_original_code:
void header_free(struct Header *header)
{
    if (header->key) { free(header->key); }
    if (header->value) { free(header->value); }
    free(header);
}

variable_types: struct Header { char *key; char *value; } *


repo: vighneshbirodkar/vigredis

original_code:
int string_get_bit(vr_string* s,int n)
{
    int index,offset;
    char mask;
    char *str = s->string;
    if(n > s->len*8)
    {
        return 0;
    }
    else
    {
        index = n/8;
        offset = (n%8);
        mask = 0x80 >> offset;
        if(str[index] & mask)
            return 1;
        else
            return 0;
    }
}

canonical_original_code:
int string_get_bit(struct vr_string *s, int n)
{
    int index; int offset;
    char mask;
    char *str = s->string;
    if(n > s->len*8)
    {
        return 0;
    }
    else
    {
        index = n/8;
        offset = (n%8);
        mask = 0x80 >> offset;
        if(str[index] & mask)
            return 1;
        else
            return 0;
    }
}

variable_types: struct vr_string { int len; char *string; } *

variable_types: n int

variable_types: offset int

variable_types: mask char

variable_types:
str
char *


original_code:
int string_set_bit(vr_string* s,int n,char bit)
{
    int index,offset;
    char mask,value;
    char* str = s->string;
    char *new_str;
    int old_val;
    if ( n < s->len*8)
    {
        index = n/8;
        offset = (n%8);
        mask = 0x80 >> offset;
        value = (bit*0x80) >> offset;
        old_val = str[index] & mask;
        str[index] = (str[index] & ~mask) | (value & mask) ;
    }
    else
    {
        index = n/8;
        new_str = (char*)malloc(index+1);
        bzero(new_str,index+1);
        strncpy(new_str,str,s->len);
        if(str != ((void *)0))
            free(str);
        s->string = new_str;
        s->len = index + 1;
        str = s->string;
        index = n/8;
        offset = (n%8);
        mask = 0x80 >> offset;
        value = (bit*0x80) >> offset;
        old_val = str[index] & mask;
        str[index] = (str[index] & ~mask) | (value & mask) ;
    }
    if (old_val)
        return 1;
    else
        return 0;
}

canonical_original_code:
int string_set_bit(struct vr_string *s, int n, char bit)
{
    int index; int offset;
    char mask; char value;
    char *str = s->string;
    char *new_str;
    int old_val;
    if ( n < s->len*8)
    {
        index = n/8;
        offset = (n%8);
        mask = 0x80 >> offset;
        value = (bit*0x80) >> offset;
        old_val = str[index] & mask;
        str[index] = (str[index] & ~mask) | (value & mask) ;
    }
    else
    {
        index = n/8;
        new_str = (char *)malloc(index+1);
        bzero(new_str,index+1);
        strncpy(new_str,str,s->len);
        if(str != ((void *)0))
            free(str);
        s->string = new_str;
        s->len = index + 1;
        str = s->string;
        index = n/8;
        offset = (n%8);
        mask = 0x80 >> offset;
        value = (bit*0x80) >> offset;
        old_val = str[index] & mask;
        str[index] = (str[index] & ~mask) | (value & mask) ;
    }
    if (old_val)
        return 1;
    else
        return 0;
}

variable_types: bit char

variable_types: index int

variable_types: value char

user_defined_types: struct vr_string { int len; char *string; }


decompiled_code:
double get_time_ms()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return (double)SLODWORD(v1.tv_usec) / 1000.0 / 1000.0 / 1000.0 + (double)SLODWORD(v1.tv_sec);
}

canonical_decompiled_code:
double func0()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return (double)SLODWORD(v1.tv_usec) / 1000.0 / 1000.0 / 1000.0 + (double)SLODWORD(v1.tv_sec);
}

original_code:
double get_time_ms()
{
    struct timeval now;
    double d;
    gettimeofday(&now, ((void *)0));
    d = now.tv_sec + ((double)now.tv_usec)/1000/1000/1000;
    return d;
}

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

variable_types: d double

return_type: double


decompiled_code:
void __fastcall str_lower(char *a1)
{
char *v1; // rbp
char v2; // bl
const __int32_t **v3; // rdx

if ( a1 )
{
v1 = a1;
v2 = *a1;
if ( *a1 )
{
v3 = _ctype_tolower_loc();
do
{
*v1++ = (*v3)[v2];
v2 = *v1;
}
while ( *v1 );
}
}
}

canonical_decompiled_code:
void __fastcall func2(char *a1)
{
char *v1; // rbp
char v2; // bl
const __int32_t **v3; // rdx

if ( a1 )
{
v1 = a1;
v2 = *a1;
if ( *a1 )
{
v3 = _ctype_tolower_loc();
do
{
*v1++ = (*v3)[v2];
v2 = *v1;
}
while ( *v1 );
}
}
}

original_code:
void str_lower( char* s )
{
    int i=0;
    if (s == ((void *)0))
        return;
    while(s[i])
    {
        s[i] = tolower(s[i]);
        i++;
    }
}

canonical_original_code:
void str_lower(char *s)
{
    int i = 0;
    if (s == ((void *)0))
        return;
    while(s[i])
    {
        s[i] = tolower(s[i]);
        i++;
    }
}

variable_types:
s
char *

variable_types: i int


rstrip

decompiled_code:
char *__fastcall rstrip(const char *a1)
{
char *result; // rax
int v2; // er12
int v3; // ebp
const unsigned __int16 **v4; // rsi
__int64 v5; // rdi

result = (char *)strlen(a1);
v2 = (_DWORD)result - 1;
if ( (int)result - 1 > 0 )
{
v3 = (int)result;
v4 = _ctype_b_loc();
result = (char *)&a1[v2];
v5 = (__int64)&result[-(v3 - 2) - 1];
do
{
if ( ((*v4)[*result] & 0x2000) == 0 )
break;
*result-- = 0;
}
while ( result != (char *)v5 );
}
return result;
}

canonical_decompiled_code:
char *__fastcall func3(const char *a1)
{
char *result; // rax
int v2; // er12
int v3; // ebp
const unsigned __int16 **v4; // rsi
__int64 v5; // rdi

result = (char *)strlen(a1);
v2 = (_DWORD)result - 1;
if ( (int)result - 1 > 0 )
{
v3 = (int)result;
v4 = _ctype_b_loc();
result = (char *)&a1[v2];
v5 = (__int64)&result[-(v3 - 2) - 1];
do
{
if ( ((*v4)[*result] & 0x2000) == 0 )
break;
*result-- = 0;
}
while ( result != (char *)v5 );
}
return result;
}

original_code:
void rstrip(char* s)
{
    int i = strlen(s)-1;
    if (s == ((void *)0))
        return;
    while(i > 0)
    {
        if(((*__ctype_b_loc ())[(int) ((s[i]))] & (unsigned short int) _ISspace))
            s[i] = 0;
        else
            break;
        i--;
    }
}

canonical_original_code:
void rstrip(char *s)
{
    int i = strlen(s)-1;
    if (s == ((void *)0))
        return;
    while(i > 0)
    {
        if(((*__ctype_b_loc ())[(int) ((s[i]))] & (unsigned short) _ISspace))
            s[i] = 0;
        else
            break;
        i--;
    }
}


isint

decompiled_code:
__int64 __fastcall isint(char *a1)
{
char v1; // bl
const unsigned __int16 *v2; // rax
char *v3; // rdi

v1 = *a1;
if ( !*a1 )
return 1LL;
v2 = *_ctype_b_loc();
v3 = a1 + 1;
while ( (v2[v1] & 0x800) != 0 )
{
v1 = *v3++;
if ( !v1 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *a1)
{
char v1; // bl
const unsigned __int16 *v2; // rax
char *v3; // rdi

v1 = *a1;
if ( !*a1 )
return 1LL;
v2 = *_ctype_b_loc();
v3 = a1 + 1;
while ( (v2[v1] & 0x800) != 0 )
{
v1 = *v3++;
if ( !v1 )
return 1LL;
}
return 0LL;
}

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

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


decompiled_code:
__int64 __fastcall isint_neg(char *a1)
{
char v1; // bl
const unsigned __int16 *v2; // rdx
char *v3; // rdi

v1 = *a1;
if ( !*a1 )
return 1LL;
v2 = *_ctype_b_loc();
v3 = a1 + 1;
do
{
if ( (v2[v1] & 0x800) == 0 && v1 != 45 )
return 0LL;
v1 = *v3++;
}
while ( v1 );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *a1)
{
char v1; // bl
const unsigned __int16 *v2; // rdx
char *v3; // rdi

v1 = *a1;
if ( !*a1 )
return 1LL;
v2 = *_ctype_b_loc();
v3 = a1 + 1;
do
{
if ( (v2[v1] & 0x800) == 0 && v1 != 45 )
return 0LL;
v1 = *v3++;
}
while ( v1 );
return 1LL;
}

original_code:
int isint_neg(char *s)
{
    int i=0;
    while(s[i])
    {
        if(!(((*__ctype_b_loc ())[(int) ((s[i]))] & (unsigned short int) _ISdigit) || s[i] == '-'))
            return 0;
        i++;
    }
    return 1;
}

canonical_original_code:
int isint_neg(char *s)
{
    int i = 0;
    while(s[i])
    {
        if(!(((*__ctype_b_loc ())[(int) ((s[i]))] & (unsigned short) _ISdigit) || s[i] == '-'))
            return 0;
        i++;
    }
    return 1;
}


isdouble

decompiled_code:
__int64 __fastcall isdouble(char *a1)
{
char v1; // bl
const unsigned __int16 *v2; // rdx
char *v3; // rdi

v1 = *a1;
if ( !*a1 )
return 1LL;
v2 = *_ctype_b_loc();
v3 = a1 + 1;
do
{
if ( (v2[v1] & 0x800) == 0 && (unsigned __int8)(v1 - 45) > 1u )
return 0LL;
v1 = *v3++;
}
while ( v1 );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *a1)
{
char v1; // bl
const unsigned __int16 *v2; // rdx
char *v3; // rdi

v1 = *a1;
if ( !*a1 )
return 1LL;
v2 = *_ctype_b_loc();
v3 = a1 + 1;
do
{
if ( (v2[v1] & 0x800) == 0 && (unsigned __int8)(v1 - 45) > 1u )
return 0LL;
v1 = *v3++;
}
while ( v1 );
return 1LL;
}

original_code:
int isdouble(char *s)
{
    int i=0;
    while(s[i])
    {
        if(! (((*__ctype_b_loc ())[(int) ((s[i]))] & (unsigned short int) _ISdigit) || (s[i] == '.') || (s[i] == '-') ) )
            return 0;
        i++;
    }
    return 1;
}

canonical_original_code:
int isdouble(char *s)
{
    int i = 0;
    while(s[i])
    {
        if(! (((*__ctype_b_loc ())[(int) ((s[i]))] & (unsigned short) _ISdigit) || (s[i] == '.') || (s[i] == '-') ) )
            return 0;
        i++;
    }
    return 1;
}


decompiled_code:
__int64 __fastcall dict_init(__int64 a1, char a2)
{
unsigned int v2; // ebx
__int64 result; // rax

*(_DWORD *)a1 = 0;
*(_DWORD *)(a1 + 4) = 8;
*(_QWORD *)(a1 + 16) = malloc(0x80uLL);
*(_BYTE *)(a1 + 8) = a2;
v2 = 0;
do
result = list_init(*(_QWORD *)(a1 + 16) + 16LL * v2++, (unsigned int)a2);
while ( *(_DWORD *)(a1 + 4) > v2 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, char a2)
{
unsigned int v2; // ebx
__int64 result; // rax

*(_DWORD *)a1 = 0;
*(_DWORD *)(a1 + 4) = 8;
*(_QWORD *)(a1 + 16) = malloc(0x80uLL);
*(_BYTE *)(a1 + 8) = a2;
v2 = 0;
do
result = list_init(*(_QWORD *)(a1 + 16) + 16LL * v2++, (unsigned int)a2);
while ( *(_DWORD *)(a1 + 4) > v2 );
return result;
}

original_code:
void dict_init(dict* d,char type)
{
    uint32_t i;
    d->len = 0;
    d->size = 8;
    d->table = (list*)malloc(sizeof(list)*8);
    d->type = type;
    for(i=0;i < d->size ;i ++)
        list_init(&d->table[i],type);
}

canonical_original_code:
void dict_init(struct dict_ *d, char type)
{
    unsigned int i;
    d->len = 0;
    d->size = 8;
    d->table = (struct list *)malloc(sizeof(list)*8);
    d->type = type;
    for(i=0;i < d->size ;i ++)
        list_init(&d->table[i],type);
}

variable_types: struct dict_ { unsigned int len; unsigned int size; char type; struct list { char type; unsigned int len; struct list_node { struct list_node *next; int klen; char *key; union vr_object { double value; struct set { struct dict_ set_dict; struct skip_list { struct skip_list_node { double score; struct skip_list_node **next; char *key; int klen; } *header; int level; } set_list; int len; } *obj_set; struct vr_string { int len; char *string; } string; } object; double expiry; } *root; } *table; } *

variable_types: type char

variable_types:
i
unsigned int

user_defined_types: struct dict_ { unsigned int len; unsigned int size; char type; struct list *table; }

user_defined_types: struct list { char type; unsigned int len; struct list_node *root; }

user_defined_types: struct list_node { struct list_node *next; int klen; char *key; union vr_object object; double expiry; }

user_defined_types: union vr_object { double value; struct set *obj_set; struct vr_string string; }

user_defined_types: struct set { struct dict_ set_dict; struct skip_list set_list; int len; }

user_defined_types: struct skip_list { struct skip_list_node *header; int level; }


decompiled_code:
__int64 __fastcall dict_get_bit(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, _QWORD *a5)
{
unsigned int v8; // edx
__int64 v9; // rax
unsigned int v10; // edx

v8 = (unsigned int)hash_string_32(a2, a3) % *(_DWORD *)(a1 + 4);
if ( *(_BYTE *)(a1 + 8) == 1 )
{
v9 = list_find(*(_QWORD *)(a1 + 16) + 16LL * v8, a2, a3);
v10 = 0;
if ( v9 )
{
*a5 = *(_QWORD *)(v9 + 40);
v10 = string_get_bit(v9 + 24, a4, 0LL);
}
}
else
{
puts("Incompatible Dict Operation");
v10 = -3;
}
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, _QWORD *a5)
{
unsigned int v8; // edx
__int64 v9; // rax
unsigned int v10; // edx

v8 = (unsigned int)hash_string_32(a2, a3) % *(_DWORD *)(a1 + 4);
if ( *(_BYTE *)(a1 + 8) == 1 )
{
v9 = list_find(*(_QWORD *)(a1 + 16) + 16LL * v8, a2, a3);
v10 = 0;
if ( v9 )
{
*a5 = *(_QWORD *)(v9 + 40);
v10 = string_get_bit(v9 + 24, a4, 0LL);
}
}
else
{
puts("Incompatible Dict Operation");
v10 = -3;
}
return v10;
}

original_code:
int dict_get_bit(dict *d,char* key,int klen,int n,double* expiry)
{
    list_node* tmp;
    uint32_t hash = hash_string_32(key,klen);
    uint32_t index = hash % d->size;
    if(d->type != 1)
    {
        printf("Incompatible Dict Operation\n");
        return -3;
    }
    tmp = list_find(&d->table[index],key,klen);
    if(tmp)
    {
        *expiry = tmp->expiry;
        return string_get_bit(&tmp->object.string,n);
    }
    else
        return 0;
}

canonical_original_code:
int dict_get_bit(struct dict_ *d, char *key, int klen, int n, double *expiry)
{
    struct list_node *tmp;
    unsigned int hash = hash_string_32(key,klen);
    unsigned int index = hash % d->size;
    if(d->type != 1)
    {
        printf("Incompatible Dict Operation\n");
        return -3;
    }
    tmp = list_find(&d->table[index],key,klen);
    if(tmp)
    {
        *expiry = tmp->expiry;
        return string_get_bit(&tmp->object.string,n);
    }
    else
        return 0;
}

variable_types:
key
char *

variable_types: klen int

variable_types:
expiry
double *

variable_types: struct list_node { struct list_node *next; int klen; char *key; union vr_object { double value; struct set { struct dict_ { unsigned int len; unsigned int size; char type; struct list { char type; unsigned int len; struct list_node *root; } *table; } set_dict; struct skip_list { struct skip_list_node { double score; struct skip_list_node **next; char *key; int klen; } *header; int level; } set_list; int len; } *obj_set; struct vr_string { int len; char *string; } string; } object; double expiry; } *

variable_types:
hash
unsigned int

variable_types:
index
unsigned int


original_code:
void dict_expand(dict *d)
{
    list* old_table = d->table;
    uint32_t old_size = d->size;
    uint32_t i;
    list_node *tmp,*current;
    d->table = (list*)malloc(sizeof(list)*old_size*2);
    d->size = old_size*2;
    for(i=0;i < d->size ;i ++)
        list_init(&d->table[i],d->type);
    d->len = 0;
    for(i=0;i < old_size;i++)
    {
        current = old_table[i].root;
        while(current != ((void *)0))
        {
            tmp = current;
            current = current->next;
            dict_add_object(d,tmp->key,tmp->klen,tmp->object,0,tmp->expiry);
            free(tmp->key);
            free(tmp);
        }
    }
    free(old_table);
}

canonical_original_code:
void dict_expand(struct dict_ *d)
{
    struct list *old_table = d->table;
    unsigned int old_size = d->size;
    unsigned int i;
    struct list_node *tmp; struct list_node *current;
    d->table = (struct list *)malloc(sizeof(list)*old_size*2);
    d->size = old_size*2;
    for(i=0;i < d->size ;i ++)
        list_init(&d->table[i],d->type);
    d->len = 0;
    for(i=0;i < old_size;i++)
    {
        current = old_table[i].root;
        while(current != ((void *)0))
        {
            tmp = current;
            current = current->next;
            dict_add_object(d,tmp->key,tmp->klen,tmp->object,0,tmp->expiry);
            free(tmp->key);
            free(tmp);
        }
    }
    free(old_table);
}

variable_types: struct list { char type; unsigned int len; struct list_node { struct list_node *next; int klen; char *key; union vr_object { double value; struct set { struct dict_ { unsigned int len; unsigned int size; char type; struct list *table; } set_dict; struct skip_list { struct skip_list_node { double score; struct skip_list_node **next; char *key; int klen; } *header; int level; } set_list; int len; } *obj_set; struct vr_string { int len; char *string; } string; } object; double expiry; } *root; } *


decompiled_code:
__int64 __fastcall dict_add_object(__int64 a1, __int64 a2, unsigned int a3, __int64 a4, __int64 a5, unsigned int a6, double a7)
{
unsigned int v11; // eax
unsigned int v12; // ebp

v11 = hash_string_32(a2, a3);
v12 = list_add_object(*(_QWORD *)(a1 + 16) + 16LL * (v11 % *(_DWORD *)(a1 + 4)), a2, a3, a4, a5, a6, a7);
if ( !v12 )
++*(_DWORD *)a1;
if ( *(_DWORD *)a1 > *(_DWORD *)(a1 + 4) )
dict_expand(a1);
return v12;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, unsigned int a3, __int64 a4, __int64 a5, unsigned int a6, double a7)
{
unsigned int v11; // eax
unsigned int v12; // ebp

v11 = hash_string_32(a2, a3);
v12 = list_add_object(*(_QWORD *)(a1 + 16) + 16LL * (v11 % *(_DWORD *)(a1 + 4)), a2, a3, a4, a5, a6, a7);
if ( !v12 )
++*(_DWORD *)a1;
if ( *(_DWORD *)a1 > *(_DWORD *)(a1 + 4) )
func2(a1);
return v12;
}

original_code:
int dict_add_object(dict *d,char* key,int klen,vr_object object,int flag,double expiry)
{
    uint32_t hash = hash_string_32(key,klen);
    uint32_t index = hash % d->size;
    int ret_val;
    ret_val = list_add_object(&d->table[index],key,klen,object,flag,expiry);
    if( ret_val == 0)
        d->len++;
    if(d->len > d->size)
        dict_expand(d);
    return ret_val;
}

canonical_original_code:
int dict_add_object(struct dict_ *d, char *key, int klen, union vr_object object, int flag, double expiry)
{
    unsigned int hash = hash_string_32(key,klen);
    unsigned int index = hash % d->size;
    int ret_val;
    ret_val = list_add_object(&d->table[index],key,klen,object,flag,expiry);
    if( ret_val == 0)
        d->len++;
    if(d->len > d->size)
        dict_expand(d);
    return ret_val;
}

variable_types:
object
union vr_object

variable_types: flag int

variable_types: expiry double

user_defined_types: struct skip_list_node { double score; struct skip_list_node **next; char *key; int klen; }


decompiled_code:
__int64 __fastcall dict_add_double(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, double a5, double a6)
{
if ( *(_BYTE *)(a1 + 8) == 2 )
return dict_add_object(a1, a2, a3, *(__int64 *)&a5, 0LL, a4, a6);
puts("Incompatible Dict Addition");
return 4294967293LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, double a5, double a6)
{
if ( *(_BYTE *)(a1 + 8) == 2 )
return func3(a1, a2, a3, *(__int64 *)&a5, 0LL, a4, a6);
puts("Incompatible Dict Addition");
return 4294967293LL;
}

original_code:
int dict_add_double(dict *d,char *key,int klen,double value,int flag,double expiry)
{
    if(d->type != 2)
    {
        printf("Incompatible Dict Addition\n");
        return -3;
    }
    vr_object obj;
    obj.value = value;
    return dict_add_object(d,key,klen,obj,flag,expiry);
}

canonical_original_code:
int dict_add_double(struct dict_ *d, char *key, int klen, double value, int flag, double expiry)
{
    if(d->type != 2)
    {
        printf("Incompatible Dict Addition\n");
        return -3;
    }
    union vr_object obj;
    obj.value = value;
    return dict_add_object(d,key,klen,obj,flag,expiry);
}

variable_types: value double

variable_types: union vr_object { double value; struct set { struct dict_ { unsigned int len; unsigned int size; char type; struct list { char type; unsigned int len; struct list_node { struct list_node *next; int klen; char *key; union vr_object object; double expiry; } *root; } *table; } set_dict; struct skip_list { struct skip_list_node { double score; struct skip_list_node **next; char *key; int klen; } *header; int level; } set_list; int len; } *obj_set; struct vr_string { int len; char *string; } string; }


decompiled_code:
__int64 __fastcall dict_add_string(__int64 a1, __int64 a2, unsigned int a3, const char *a4, unsigned int a5, unsigned int a6, double a7)
{
__int64 v9; // r15
size_t v10; // rbx
char *v11; // r12
__int64 result; // rax

if ( *(_BYTE *)(a1 + 8) == 1 )
{
v9 = a5;
v10 = (int)a5;
v11 = (char *)malloc((int)a5);
strncpy(v11, a4, v10);
result = dict_add_object(a1, a2, a3, v9, (__int64)v11, a6, a7);
}
else
{
puts("Incompatible Dict Addition");
result = 4294967293LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, unsigned int a3, const char *a4, unsigned int a5, unsigned int a6, double a7)
{
__int64 v9; // r15
size_t v10; // rbx
char *v11; // r12
__int64 result; // rax

if ( *(_BYTE *)(a1 + 8) == 1 )
{
v9 = a5;
v10 = (int)a5;
v11 = (char *)malloc((int)a5);
strncpy(v11, a4, v10);
result = func3(a1, a2, a3, v9, (__int64)v11, a6, a7);
}
else
{
puts("Incompatible Dict Addition");
result = 4294967293LL;
}
return result;
}

original_code:
int dict_add_string(dict *d,char* key,int klen,char* value,int vlen,int flag,double expiry)
{
    if(d->type != 1)
    {
        printf("Incompatible Dict Addition\n");
        return -3;
    }
    vr_object obj;
    obj.string.len = vlen;
    obj.string.string = (char*)malloc(sizeof(char)*vlen);
    strncpy(obj.string.string,value,vlen);
    return dict_add_object(d,key,klen,obj,flag,expiry);
}

canonical_original_code:
int dict_add_string(struct dict_ *d, char *key, int klen, char *value, int vlen, int flag, double expiry)
{
    if(d->type != 1)
    {
        printf("Incompatible Dict Addition\n");
        return -3;
    }
    union vr_object obj;
    obj.string.len = vlen;
    obj.string.string = (char *)malloc(sizeof(char)*vlen);
    strncpy(obj.string.string,value,vlen);
    return dict_add_object(d,key,klen,obj,flag,expiry);
}

variable_types:
value
char *

variable_types: vlen int


decompiled_code:
__int64 __fastcall dict_set_bit(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, char a5, _QWORD *a6)
{
unsigned int v10; // edx
__int64 v11; // rax
unsigned int v12; // ebp
__int64 v14; // [rsp+0h] [rbp-48h] BYREF
__int64 v15; // [rsp+8h] [rbp-40h]

v10 = (unsigned int)hash_string_32(a2, a3) % *(_DWORD *)(a1 + 4);
if ( *(_BYTE *)(a1 + 8) == 1 )
{
v11 = list_find(*(_QWORD *)(a1 + 16) + 16LL * v10, a2, a3);
if ( v11 )
{
*a6 = *(_QWORD *)(v11 + 40);
v12 = string_set_bit(v11 + 24, a4, (unsigned int)a5);
}
else
{
v15 = 0LL;
LODWORD(v14) = 0;
v12 = string_set_bit(&v14, a4, (unsigned int)a5);
dict_add_object(a1, a2, a3, v14, v15, 0, -1.0);
}
}
else
{
puts("Incompatible Dict Operation");
v12 = -3;
}
return v12;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, char a5, _QWORD *a6)
{
unsigned int v10; // edx
__int64 v11; // rax
unsigned int v12; // ebp
__int64 v14; // [rsp+0h] [rbp-48h] BYREF
__int64 v15; // [rsp+8h] [rbp-40h]

v10 = (unsigned int)hash_string_32(a2, a3) % *(_DWORD *)(a1 + 4);
if ( *(_BYTE *)(a1 + 8) == 1 )
{
v11 = list_find(*(_QWORD *)(a1 + 16) + 16LL * v10, a2, a3);
if ( v11 )
{
*a6 = *(_QWORD *)(v11 + 40);
v12 = string_set_bit(v11 + 24, a4, (unsigned int)a5);
}
else
{
v15 = 0LL;
LODWORD(v14) = 0;
v12 = string_set_bit(&v14, a4, (unsigned int)a5);
func3(a1, a2, a3, v14, v15, 0, -1.0);
}
}
else
{
puts("Incompatible Dict Operation");
v12 = -3;
}
return v12;
}

original_code:
int dict_set_bit(dict *d,char* key,int klen,int n,char b,double* expiry)
{
    list_node* tmp;
    int ret;
    uint32_t hash = hash_string_32(key,klen);
    uint32_t index = hash % d->size;
    if(d->type != 1)
    {
        printf("Incompatible Dict Operation\n");
        return -3;
    }
    tmp = list_find(&d->table[index],key,klen);
    if(tmp)
    {
        *expiry = tmp->expiry;
        return string_set_bit(&tmp->object.string,n,b);
    }
    else
    {
        vr_object obj;
        obj.string.string = ((void *)0);
        obj.string.len = 0;
        ret = string_set_bit(&obj.string,n,b);
        dict_add_object(d,key,klen,obj,0,-1);
        return ret;
    }
}

canonical_original_code:
int dict_set_bit(struct dict_ *d, char *key, int klen, int n, char b, double *expiry)
{
    struct list_node *tmp;
    int ret;
    unsigned int hash = hash_string_32(key,klen);
    unsigned int index = hash % d->size;
    if(d->type != 1)
    {
        printf("Incompatible Dict Operation\n");
        return -3;
    }
    tmp = list_find(&d->table[index],key,klen);
    if(tmp)
    {
        *expiry = tmp->expiry;
        return string_set_bit(&tmp->object.string,n,b);
    }
    else
    {
        union vr_object obj;
        obj.string.string = ((void *)0);
        obj.string.len = 0;
        ret = string_set_bit(&obj.string,n,b);
        dict_add_object(d,key,klen,obj,0,-1);
        return ret;
    }
}

variable_types: struct dict_ { unsigned int len; unsigned int size; char type; struct list { char type; unsigned int len; struct list_node { struct list_node *next; int klen; char *key; union vr_object { double value; struct set { struct dict_ set_dict; struct skip_list { struct skip_list_node { double score; struct skip_list_node **next; char *key; int klen; } *header; int level; } set_list; int len; } *obj_set; struct vr_string { int len; char *string; } string; } object; double expiry; } *root; } *table; } *

variable_types: n int

variable_types: b char

variable_types: ret int


original_code:
void dict_contract(dict *d)
{
    list* old_table = d->table;
    uint32_t old_size = d->size;
    uint32_t i;
    uint32_t new_size = 8;
    list_node *tmp,*current;
    while(new_size < d->len)
        new_size *= 2;
    d->table = (list*)malloc(sizeof(list)*new_size);
    d->size = new_size;
    d->len = 0;
    for(i=0;i < d->size ;i ++)
        list_init(&d->table[i],d->type);
    for(i=0;i < old_size;i++)
    {
        current = old_table[i].root;
        while(current != ((void *)0))
        {
            tmp = current;
            current = current->next;
            dict_add_object(d,tmp->key,tmp->klen,tmp->object,0,tmp->expiry);
            free(tmp->key);
            free(tmp);
        }
    }
    free(old_table);
}

canonical_original_code:
void dict_contract(struct dict_ *d)
{
    struct list *old_table = d->table;
    unsigned int old_size = d->size;
    unsigned int i;
    unsigned int new_size = 8;
    struct list_node *tmp; struct list_node *current;
    while(new_size < d->len)
        new_size *= 2;
    d->table = (struct list *)malloc(sizeof(list)*new_size);
    d->size = new_size;
    d->len = 0;
    for(i=0;i < d->size ;i ++)
        list_init(&d->table[i],d->type);
    for(i=0;i < old_size;i++)
    {
        current = old_table[i].root;
        while(current != ((void *)0))
        {
            tmp = current;
            current = current->next;
            dict_add_object(d,tmp->key,tmp->klen,tmp->object,0,tmp->expiry);
            free(tmp->key);
            free(tmp);
        }
    }
    free(old_table);
}

variable_types:
i
unsigned int


decompiled_code:
__int64 __fastcall dict_delete(__int64 a1, __int64 a2, unsigned int a3)
{
unsigned int v4; // eax
unsigned int v5; // ebp

v4 = hash_string_32(a2, a3);
v5 = list_delete_object(*(_QWORD *)(a1 + 16) + 16LL * (v4 % *(_DWORD *)(a1 + 4)), a2, a3);
if ( v5 == -1 )
--*(_DWORD *)a1;
if ( *(_DWORD *)a1 < *(_DWORD *)(a1 + 4) / 0xAu )
dict_contract(a1);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2, unsigned int a3)
{
unsigned int v4; // eax
unsigned int v5; // ebp

v4 = hash_string_32(a2, a3);
v5 = list_delete_object(*(_QWORD *)(a1 + 16) + 16LL * (v4 % *(_DWORD *)(a1 + 4)), a2, a3);
if ( v5 == -1 )
--*(_DWORD *)a1;
if ( *(_DWORD *)a1 < *(_DWORD *)(a1 + 4) / 0xAu )
func7(a1);
return v5;
}

original_code:
int dict_delete(dict *d,char *key,int klen)
{
    uint32_t hash = hash_string_32(key,klen);
    uint32_t index = hash % d->size;
    int ret_val;
    ret_val = list_delete_object(&d->table[index],key,klen);
    if( ret_val == -1)
        d->len--;
    if(d->len < (d->size/10))
        dict_contract(d);
    return ret_val;
}

canonical_original_code:
int dict_delete(struct dict_ *d, char *key, int klen)
{
    unsigned int hash = hash_string_32(key,klen);
    unsigned int index = hash % d->size;
    int ret_val;
    ret_val = list_delete_object(&d->table[index],key,klen);
    if( ret_val == -1)
        d->len--;
    if(d->len < (d->size/10))
        dict_contract(d);
    return ret_val;
}

variable_types:
key
char *

variable_types: klen int


decompiled_code:
__int64 __fastcall dict_delete_ife(__int64 a1, __int64 a2, unsigned int a3, double a4)
{
unsigned int v5; // eax
unsigned int v6; // ebp

v5 = hash_string_32(a2, a3);
v6 = list_delete_object_ife(*(_QWORD *)(a1 + 16) + 16LL * (v5 % *(_DWORD *)(a1 + 4)), a2, a3, a4);
if ( v6 == -1 )
--*(_DWORD *)a1;
if ( *(_DWORD *)a1 < *(_DWORD *)(a1 + 4) / 0xAu )
dict_contract(a1);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, unsigned int a3, double a4)
{
unsigned int v5; // eax
unsigned int v6; // ebp

v5 = hash_string_32(a2, a3);
v6 = list_delete_object_ife(*(_QWORD *)(a1 + 16) + 16LL * (v5 % *(_DWORD *)(a1 + 4)), a2, a3, a4);
if ( v6 == -1 )
--*(_DWORD *)a1;
if ( *(_DWORD *)a1 < *(_DWORD *)(a1 + 4) / 0xAu )
func7(a1);
return v6;
}

original_code:
int dict_delete_ife(dict *d,char *key,int klen, double time)
{
    uint32_t hash = hash_string_32(key,klen);
    uint32_t index = hash % d->size;
    int ret_val;
    ret_val = list_delete_object_ife(&d->table[index],key,klen,time);
    if(ret_val == -1)
        d->len--;
    if(d->len < (d->size/10))
        dict_contract(d);
    return ret_val;
}

canonical_original_code:
int dict_delete_ife(struct dict_ *d, char *key, int klen, double time)
{
    unsigned int hash = hash_string_32(key,klen);
    unsigned int index = hash % d->size;
    int ret_val;
    ret_val = list_delete_object_ife(&d->table[index],key,klen,time);
    if(ret_val == -1)
        d->len--;
    if(d->len < (d->size/10))
        dict_contract(d);
    return ret_val;
}

variable_types: time double

variable_types:
hash
unsigned int


original_code:
void dict_print(dict *d)
{
    uint32_t i;
    list_node* tmp ;
    printf("Length = %u\n",d->len);
    for(i=0; i<d->size; i++)
    {
        tmp = (&d->table[i])->root;
        while( tmp != ((void *)0))
        {
            if(d->type == 1)
                printf("%.*s : %.*s\n", (int)tmp->klen, tmp->key , (int)tmp->object.string.len, tmp->object.string.string);
            if(d->type == 2)
                printf("%.*s : %lf\n", (int)tmp->klen, tmp->key , tmp->object.value);
            if(d->type == 3)
            {
                printf("SET - %.*s\n",tmp->klen,tmp->key);
                printf("-------------\n");
                set_print(tmp->object.obj_set);
            }
            tmp = tmp->next;
        }
    }
}

canonical_original_code:
void dict_print(struct dict_ *d)
{
    unsigned int i;
    struct list_node *tmp;
    printf("Length = %u\n",d->len);
    for(i=0; i<d->size; i++)
    {
        tmp = (&d->table[i])->root;
        while( tmp != ((void *)0))
        {
            if(d->type == 1)
                printf("%.*s : %.*s\n", (int)tmp->klen, tmp->key , (int)tmp->object.string.len, tmp->object.string.string);
            if(d->type == 2)
                printf("%.*s : %lf\n", (int)tmp->klen, tmp->key , tmp->object.value);
            if(d->type == 3)
            {
                printf("SET - %.*s\n",tmp->klen,tmp->key);
                printf("-------------\n");
                set_print(tmp->object.obj_set);
            }
            tmp = tmp->next;
        }
    }
}

variable_types: struct list_node { struct list_node *next; int klen; char *key; union vr_object { double value; struct set { struct dict_ { unsigned int len; unsigned int size; char type; struct list { char type; unsigned int len; struct list_node *root; } *table; } set_dict; struct skip_list { struct skip_list_node { double score; struct skip_list_node **next; char *key; int klen; } *header; int level; } set_list; int len; } *obj_set; struct vr_string { int len; char *string; } string; } object; double expiry; } *


decompiled_code:
__int64 __fastcall dict_get(__int64 a1, __int64 a2, unsigned int a3, _QWORD *a4)
{
unsigned int v6; // eax
__int64 result; // rax

v6 = hash_string_32(a2, a3);
result = list_find(*(_QWORD *)(a1 + 16) + 16LL * (v6 % *(_DWORD *)(a1 + 4)), a2, a3);
if ( result )
{
*a4 = *(_QWORD *)(result + 40);
result += 24LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2, unsigned int a3, _QWORD *a4)
{
unsigned int v6; // eax
__int64 result; // rax

v6 = hash_string_32(a2, a3);
result = list_find(*(_QWORD *)(a1 + 16) + 16LL * (v6 % *(_DWORD *)(a1 + 4)), a2, a3);
if ( result )
{
*a4 = *(_QWORD *)(result + 40);
result += 24LL;
}
return result;
}

original_code:
vr_object* dict_get(dict *d,char* key,int klen,double* expiry)
{
    uint32_t hash = hash_string_32(key,klen);
    uint32_t index = hash % d->size;
    list_node* tmp;
    tmp = list_find(&d->table[index],key,klen);
    if(tmp)
    {
        *expiry = tmp->expiry;
        return &tmp->object;
    }
    else
        return ((void *)0);
}

canonical_original_code:
union vr_object *dict_get(struct dict_ *d, char *key, int klen, double *expiry)
{
    unsigned int hash = hash_string_32(key,klen);
    unsigned int index = hash % d->size;
    struct list_node *tmp;
    tmp = list_find(&d->table[index],key,klen);
    if(tmp)
    {
        *expiry = tmp->expiry;
        return &tmp->object;
    }
    else
        return ((void *)0);
}

variable_types:
d
struct dict_ *

variable_types:
expiry
double *

variable_types:
index
unsigned int

return_type: union vr_object { double value; struct set { struct dict_ { unsigned int len; unsigned int size; char type; struct list { char type; unsigned int len; struct list_node { struct list_node *next; int klen; char *key; union vr_object object; double expiry; } *root; } *table; } set_dict; struct skip_list { struct skip_list_node { double score; struct skip_list_node **next; char *key; int klen; } *header; int level; } set_list; int len; } *obj_set; struct vr_string { int len; char *string; } string; } *


decompiled_code:
__int64 __fastcall dict_get_string(__int64 a1, __int64 a2, unsigned int a3, _QWORD *a4)
{
if ( *(_BYTE *)(a1 + 8) == 1 )
return dict_get(a1, a2, a3, a4);
puts("Incompatible Dict Addition");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2, unsigned int a3, _QWORD *a4)
{
if ( *(_BYTE *)(a1 + 8) == 1 )
return func11(a1, a2, a3, a4);
puts("Incompatible Dict Addition");
return 0LL;
}

original_code:
vr_string* dict_get_string(dict* d,char* key,int klen,double * expiry)
{
    if(d->type != 1)
    {
        printf("Incompatible Dict Addition\n");
        return ((void *)0);
    }
    return &dict_get(d,key,klen,expiry)->string;
}

canonical_original_code:
struct vr_string *dict_get_string(struct dict_ *d, char *key, int klen, double *expiry)
{
    if(d->type != 1)
    {
        printf("Incompatible Dict Addition\n");
        return ((void *)0);
    }
    return &dict_get(d,key,klen,expiry)->string;
}

variable_types: struct dict_ { unsigned int len; unsigned int size; char type; struct list { char type; unsigned int len; struct list_node { struct list_node *next; int klen; char *key; union vr_object { double value; struct set { struct dict_ set_dict; struct skip_list { struct skip_list_node { double score; struct skip_list_node **next; char *key; int klen; } *header; int level; } set_list; int len; } *obj_set; struct vr_string string; } object; double expiry; } *root; } *table; } *

return_type: struct vr_string { int len; char *string; } *


decompiled_code:
void __fastcall dict_delete_expired(__int64 a1, __int64 a2)
{
double v2; // rbp
__int64 v3; // rbx

v2 = get_time_ms();
while ( v2 > skip_list_first(a2) )
{
v3 = skip_list_pop(a2);
dict_delete_ife(a1, *(_QWORD *)(v3 + 16), *(_DWORD *)(v3 + 24), v2);
free(*(void **)(v3 + 16));
free(*(void **)(v3 + 8));
free((void *)v3);
}
}

canonical_decompiled_code:
void __fastcall func13(__int64 a1, __int64 a2)
{
double v2; // rbp
__int64 v3; // rbx

v2 = get_time_ms();
while ( v2 > skip_list_first(a2) )
{
v3 = skip_list_pop(a2);
func9(a1, *(_QWORD *)(v3 + 16), *(_DWORD *)(v3 + 24), v2);
free(*(void **)(v3 + 16));
free(*(void **)(v3 + 8));
free((void *)v3);
}
}

original_code:
void dict_delete_expired(dict *d,skip_list* sl)
{
    double time = get_time_ms();
    skip_list_node* tmp;
    while( (time > skip_list_first(sl) ))
    {
        tmp = skip_list_pop(sl);
        dict_delete_ife(d,tmp->key,tmp->klen,time);
        free(tmp->key);
        free(tmp->next);
        free(tmp);
    }
}

canonical_original_code:
void dict_delete_expired(struct dict_ *d, struct skip_list *sl)
{
    double time = get_time_ms();
    struct skip_list_node *tmp;
    while( (time > skip_list_first(sl) ))
    {
        tmp = skip_list_pop(sl);
        dict_delete_ife(d,tmp->key,tmp->klen,time);
        free(tmp->key);
        free(tmp->next);
        free(tmp);
    }
}

variable_types:
sl
struct skip_list *

variable_types: struct skip_list_node { double score; struct skip_list_node **next; char *key; int klen; } *


original_code:
void dict_clear(dict *d)
{
    list_node* tmp,*current;
    int i;
    for(i=0;i < d->size;i++)
    {
        current = d->table[i].root;
        while(current != ((void *)0))
        {
            tmp = current;
            current = current->next;
            free(tmp->key);
            if(d->type == 1)
            {
                free(tmp->object.string.string);
            }
            if(d->type == 3)
            {
                set_clear(tmp->object.obj_set);
                free(tmp->object.obj_set);
            }
            free(tmp);
        }
    }
    free(d->table);
}

canonical_original_code:
void dict_clear(struct dict_ *d)
{
    struct list_node *tmp; struct list_node *current;
    int i;
    for(i=0;i < d->size;i++)
    {
        current = d->table[i].root;
        while(current != ((void *)0))
        {
            tmp = current;
            current = current->next;
            free(tmp->key);
            if(d->type == 1)
            {
                free(tmp->object.string.string);
            }
            if(d->type == 3)
            {
                set_clear(tmp->object.obj_set);
                free(tmp->object.obj_set);
            }
            free(tmp);
        }
    }
    free(d->table);
}

variable_types: i int


decompiled_code:
__int64 random_level()
{
int i; // ebx
int v1; // eax

for ( i = 1; ; ++i )
{
v1 = rand();
if ( i > 31 || v1 > 1073741822 )
break;
}
return (unsigned int)i;
}

canonical_decompiled_code:
__int64 func0()
{
int i; // ebx
int v1; // eax

for ( i = 1; ; ++i )
{
v1 = rand();
if ( i > 31 || v1 > 1073741822 )
break;
}
return (unsigned int)i;
}

variable_types: x int


original_code:
void skip_list_insert(skip_list *sl,double score,char* key,int klen)
{
    int i;
    int v;
    skip_list_node* update[32];
    skip_list_node* x = sl->header;
    for(i=(sl->level-1); i >= 0 ; i--)
    {
        while( (x->next[i] != ((void *)0)) && x->next[i]->score < score )
            x = x->next[i];
        update[i] = x;
    }
    x = x->next[0];
    v = random_level();
    if(v > sl->level)
    {
        for(i=(sl->level );i < v;i++)
            update[i]= sl->header;
        sl->level = v;
    }
    x = (skip_list_node*)malloc(sizeof(skip_list_node));
    x->score = score;
    x->key = (char*)malloc(klen);
    strncpy(x->key,key,klen);
    x->klen = klen;
    x->next = (skip_list_node**)malloc(v*sizeof(char*));
    for(i=0;i < v;i++)
    {
        x->next[i] = update[i]->next[i];
        update[i]->next[i] = x;
    }
}

canonical_original_code:
void skip_list_insert(struct skip_list *sl, double score, char *key, int klen)
{
    int i;
    int v;
    struct skip_list_node *update[32];
    struct skip_list_node *x = sl->header;
    for(i=(sl->level-1); i >= 0 ; i--)
    {
        while( (x->next[i] != ((void *)0)) && x->next[i]->score < score )
            x = x->next[i];
        update[i] = x;
    }
    x = x->next[0];
    v = random_level();
    if(v > sl->level)
    {
        for(i=(sl->level );i < v;i++)
            update[i]= sl->header;
        sl->level = v;
    }
    x = (struct skip_list_node *)malloc(sizeof(skip_list_node));
    x->score = score;
    x->key = (char *)malloc(klen);
    strncpy(x->key,key,klen);
    x->klen = klen;
    x->next = (struct skip_list_node **)malloc(v*sizeof(char *));
    for(i=0;i < v;i++)
    {
        x->next[i] = update[i]->next[i];
        update[i]->next[i] = x;
    }
}

variable_types: struct skip_list { struct skip_list_node { double score; struct skip_list_node **next; char *key; int klen; } *header; int level; } *

variable_types: score double

variable_types: v int

variable_types: struct skip_list_node { double score; struct skip_list_node **next; char *key; int klen; } *[32]


original_code:
skip_list_node* skip_list_point(skip_list* sl,double score)
{
    int i;
    skip_list_node* x = sl->header;
    for(i=(sl->level-1); i >= 0 ; i--)
    {
        while( ( x->next[i] != ((void *)0)) && (x->next[i]->score < score) )
            x = x->next[i];
    }
    x = x->next[0];
    return x;
}

canonical_original_code:
struct skip_list_node *skip_list_point(struct skip_list *sl, double score)
{
    int i;
    struct skip_list_node *x = sl->header;
    for(i=(sl->level-1); i >= 0 ; i--)
    {
        while( ( x->next[i] != ((void *)0)) && (x->next[i]->score < score) )
            x = x->next[i];
    }
    x = x->next[0];
    return x;
}

variable_types: struct skip_list { struct skip_list_node *header; int level; } *

return_type: struct skip_list_node { double score; struct skip_list_node **next; char *key; int klen; } *


original_code:
void skip_list_delete_with_key(skip_list *sl,double score,char* key,int klen)
{
    skip_list_node* update[32];
    skip_list_node* x = sl->header;
    int i;
    for(i=(sl->level-1); i >= 0 ; i--)
    {
        while( ( x->next[i] != ((void *)0)) && (x->next[i]->score < score) )
            x = x->next[i];
        update[i] = x;
    }
    x = x->next[0];
    if( x == ((void *)0))
    {
        printf("Fatal : key not found\n");
        return;
    }
    while( (x->next[0] != ((void *)0)) && ( abs(x->score-score) < 0.000000001 ) && (x->klen != klen) && ( strncmp(x->key,key,klen) != 0) )
    {
        x = x->next[0];
    }
    if( (x->klen == klen) && (strncmp(x->key,key,klen) == 0) )
    {
        for(i=0;i < sl->level;i++)
        {
            if( update[i]->next[i] != x)
                break;
            update[i]->next[i] = x->next[i];
        }
        free(x->key);
        free(x->next);
        free(x);
        while( (sl->level > 0) && (sl->header->next[sl->level] == ((void *)0)) )
        {
            sl->level--;
        }
    }
    else
        printf("Fatal : key not found\n");
}

canonical_original_code:
void skip_list_delete_with_key(struct skip_list *sl, double score, char *key, int klen)
{
    struct skip_list_node *update[32];
    struct skip_list_node *x = sl->header;
    int i;
    for(i=(sl->level-1); i >= 0 ; i--)
    {
        while( ( x->next[i] != ((void *)0)) && (x->next[i]->score < score) )
            x = x->next[i];
        update[i] = x;
    }
    x = x->next[0];
    if( x == ((void *)0))
    {
        printf("Fatal : key not found\n");
        return;
    }
    while( (x->next[0] != ((void *)0)) && ( abs(x->score-score) < 0.000000001 ) && (x->klen != klen) && ( strncmp(x->key,key,klen) != 0) )
    {
        x = x->next[0];
    }
    if( (x->klen == klen) && (strncmp(x->key,key,klen) == 0) )
    {
        for(i=0;i < sl->level;i++)
        {
            if( update[i]->next[i] != x)
                break;
            update[i]->next[i] = x->next[i];
        }
        free(x->key);
        free(x->next);
        free(x);
        while( (sl->level > 0) && (sl->header->next[sl->level] == ((void *)0)) )
        {
            sl->level--;
        }
    }
    else
        printf("Fatal : key not found\n");
}

variable_types:
key
char *

variable_types: klen int


decompiled_code:
double __fastcall skip_list_first(__int64 a1)
{
double *v1; // rax
double result; // xmm0_8

v1 = **(double ***)(*(_QWORD *)a1 + 8LL);
result = *(double *)&LC1;
if ( v1 )
result = *v1;
return result;
}

canonical_decompiled_code:
double __fastcall func5(__int64 a1)
{
double *v1; // rax
double result; // xmm0_8

v1 = **(double ***)(*(_QWORD *)a1 + 8LL);
result = *(double *)&LC1;
if ( v1 )
result = *v1;
return result;
}

original_code:
double skip_list_first(skip_list* sl)
{
    if(sl->header->next[0])
        return sl->header->next[0]->score;
    else
        return ((double)1.79769313486231570814527423731704357e+308L);
}

canonical_original_code:
double skip_list_first(struct skip_list *sl)
{
    if(sl->header->next[0])
        return sl->header->next[0]->score;
    else
        return ((double)1.79769313486231570814527423731704357e+308L);
}


decompiled_code:
_BOOL8 __fastcall skip_list_empty(__int64 a1)
{
return **(_QWORD **)(*(_QWORD *)a1 + 8LL) == 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(__int64 a1)
{
return **(_QWORD **)(*(_QWORD *)a1 + 8LL) == 0LL;
}

original_code:
int skip_list_empty(skip_list* sl)
{
    return (sl->header->next[0] == ((void *)0));
}

canonical_original_code:
int skip_list_empty(struct skip_list *sl)
{
    return (sl->header->next[0] == ((void *)0));
}


original_code:
skip_list_node* skip_list_pop(skip_list *sl)
{
    int i;
    skip_list_node* first = sl->header->next[0];
    for(i=0;i<32;i++)
    {
        if(sl->header->next[i] == first )
            sl->header->next[i] = first->next[0];
    }
    return first;
}

canonical_original_code:
struct skip_list_node *skip_list_pop(struct skip_list *sl)
{
    int i;
    struct skip_list_node *first = sl->header->next[0];
    for(i=0;i<32;i++)
    {
        if(sl->header->next[i] == first )
            sl->header->next[i] = first->next[0];
    }
    return first;
}


decompiled_code:
int __fastcall skip_list_print(__int64 a1)
{
__int64 v1; // rbx
unsigned int v2; // ebp
__int64 v3; // rdx

v1 = **(_QWORD **)(*(_QWORD *)a1 + 8LL);
if ( v1 )
{
v2 = 1;
do
{
v3 = (unsigned int)(int)*(double *)v1;
if ( *(double *)v1 == (double)(int)v3 )
printf("%d) %d , %.*s \n", v2, v3, *(_DWORD *)(v1 + 24), *(const char **)(v1 + 16));
else
printf("%d) %lf , %.*s \n", v2, *(double *)v1, *(_DWORD *)(v1 + 24), *(const char **)(v1 + 16));
v1 = **(_QWORD **)(v1 + 8);
++v2;
}
while ( v1 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1)
{
__int64 v1; // rbx
unsigned int v2; // ebp
__int64 v3; // rdx

v1 = **(_QWORD **)(*(_QWORD *)a1 + 8LL);
if ( v1 )
{
v2 = 1;
do
{
v3 = (unsigned int)(int)*(double *)v1;
if ( *(double *)v1 == (double)(int)v3 )
printf("%d) %d , %.*s \n", v2, v3, *(_DWORD *)(v1 + 24), *(const char **)(v1 + 16));
else
printf("%d) %lf , %.*s \n", v2, *(double *)v1, *(_DWORD *)(v1 + 24), *(const char **)(v1 + 16));
v1 = **(_QWORD **)(v1 + 8);
++v2;
}
while ( v1 );
}
return putchar(10);
}

original_code:
void skip_list_print(skip_list* sl)
{
    skip_list_node* tmp = sl->header;
    tmp = tmp->next[0];
    int counter = 1;
    int trunc;
    while(tmp != ((void *)0))
    {
        trunc = (int)tmp->score;
        if(trunc == tmp->score)
            printf("%d) %d , %.*s \n",counter,trunc,tmp->klen,tmp->key);
        else
            printf("%d) %lf , %.*s \n",counter,tmp->score,tmp->klen,tmp->key);
        tmp = tmp->next[0];
        counter++;
    }
    printf("\n");
}

canonical_original_code:
void skip_list_print(struct skip_list *sl)
{
    struct skip_list_node *tmp = sl->header;
    tmp = tmp->next[0];
    int counter = 1;
    int trunc;
    while(tmp != ((void *)0))
    {
        trunc = (int)tmp->score;
        if(trunc == tmp->score)
            printf("%d) %d , %.*s \n",counter,trunc,tmp->klen,tmp->key);
        else
            printf("%d) %lf , %.*s \n",counter,tmp->score,tmp->klen,tmp->key);
        tmp = tmp->next[0];
        counter++;
    }
    printf("\n");
}

variable_types: counter int

variable_types: trunc int


decompiled_code:
void __fastcall skip_list_clear(void **a1)
{
void **v1; // rbx

while ( !skip_list_empty((__int64)a1) )
{
v1 = (void **)skip_list_pop((__int64)a1);
free(v1[2]);
free(v1[1]);
free(v1);
}
free(*((void **)*a1 + 1));
free(*a1);
}

original_code:
void skip_list_clear(skip_list* sl)
{
    skip_list_node* tmp;
    while(!skip_list_empty(sl))
    {
        tmp = skip_list_pop(sl);
        free(tmp->key);
        free(tmp->next);
        free(tmp);
    }
    free(sl->header->next);
    free(sl->header);
}

canonical_original_code:
void skip_list_clear(struct skip_list *sl)
{
    struct skip_list_node *tmp;
    while(!skip_list_empty(sl))
    {
        tmp = skip_list_pop(sl);
        free(tmp->key);
        free(tmp->next);
        free(tmp);
    }
    free(sl->header->next);
    free(sl->header);
}


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

dict_init(a1, 2LL);
result = skip_list_init(a1 + 24);
*(_DWORD *)(a1 + 40) = 0;
return result;
}

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

dict_init(a1, 2LL);
result = skip_list_init(a1 + 24);
*(_DWORD *)(a1 + 40) = 0;
return result;
}

original_code:
void set_init(set *s)
{
    dict_init(&s->set_dict,2);
    skip_list_init(&s->set_list);
    s->len = 0;
}

canonical_original_code:
void set_init(struct set *s)
{
    dict_init(&s->set_dict,2);
    skip_list_init(&s->set_list);
    s->len = 0;
}

variable_types: struct set { struct dict_ { unsigned int len; unsigned int size; char type; struct list { char type; unsigned int len; struct list_node { struct list_node *next; int klen; char *key; union vr_object { double value; struct set *obj_set; struct vr_string { int len; char *string; } string; } object; double expiry; } *root; } *table; } set_dict; struct skip_list { struct skip_list_node { double score; struct skip_list_node **next; char *key; int klen; } *header; int level; } set_list; int len; } *


decompiled_code:
__int64 __fastcall set_add(__int64 a1, __int64 a2, __int64 a3, double a4)
{
unsigned int v4; // ebp
double *v5; // rax
unsigned int v6; // er14
char v8[64]; // [rsp+8h] [rbp-40h] BYREF

v4 = a3;
v5 = (double *)dict_get(a1, a2, a3, v8);
if ( v5 )
{
if ( (int)(a4 - *v5) )
{
skip_list_delete_with_key(a1 + 24, a2, v4);
v6 = dict_add_double(a1, a2, v4, 0LL, a4, -1.0);
skip_list_insert(a1 + 24, a2, v4, a4);
if ( v6 != -1 )
puts("Fatal : Key which is supposed to exist, does not exist");
}
else
{
v6 = -1;
}
}
else
{
v6 = dict_add_double(a1, a2, v4, 0LL, a4, -1.0);
skip_list_insert(a1 + 24, a2, v4, a4);
if ( v6 )
puts("Fatal : Key which is not supposed to exists, does exist");
++*(_DWORD *)(a1 + 40);
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3, double a4)
{
unsigned int v4; // ebp
double *v5; // rax
unsigned int v6; // er14
char v8[64]; // [rsp+8h] [rbp-40h] BYREF

v4 = a3;
v5 = (double *)dict_get(a1, a2, a3, v8);
if ( v5 )
{
if ( (int)(a4 - *v5) )
{
skip_list_delete_with_key(a1 + 24, a2, v4);
v6 = dict_add_double(a1, a2, v4, 0LL, a4, -1.0);
skip_list_insert(a1 + 24, a2, v4, a4);
if ( v6 != -1 )
puts("Fatal : Key which is supposed to exist, does not exist");
}
else
{
v6 = -1;
}
}
else
{
v6 = dict_add_double(a1, a2, v4, 0LL, a4, -1.0);
skip_list_insert(a1 + 24, a2, v4, a4);
if ( v6 )
puts("Fatal : Key which is not supposed to exists, does exist");
++*(_DWORD *)(a1 + 40);
}
return v6;
}

original_code:
int set_add(set *s,char* key,int klen,double score)
{
    int ret;
    double exp;
    vr_object *obj;
    obj = dict_get(&s->set_dict,key,klen,&exp);
    if( obj == ((void *)0))
    {
        ret = dict_add_double(&s->set_dict,key,klen,score,0,-1);
        skip_list_insert(&s->set_list,score,key,klen);
        if(ret != 0)
            printf("Fatal : Key which is not supposed to exists, does exist\n");
        s->len = s->len + 1;
    }
    else
    {
        if(( abs(score-obj->value) < 0.000000001 ))
            return -1;
        skip_list_delete_with_key(&s->set_list,obj->value,key,klen);
        ret = dict_add_double(&s->set_dict,key,klen,score,0,-1);
        skip_list_insert(&s->set_list,score,key,klen);
        if(ret != -1)
            printf("Fatal : Key which is supposed to exist, does not exist\n");
    }
    return ret;
}

canonical_original_code:
int set_add(struct set *s, char *key, int klen, double score)
{
    int ret;
    double exp;
    union vr_object *obj;
    obj = dict_get(&s->set_dict,key,klen,&exp);
    if( obj == ((void *)0))
    {
        ret = dict_add_double(&s->set_dict,key,klen,score,0,-1);
        skip_list_insert(&s->set_list,score,key,klen);
        if(ret != 0)
            printf("Fatal : Key which is not supposed to exists, does exist\n");
        s->len = s->len + 1;
    }
    else
    {
        if(( abs(score-obj->value) < 0.000000001 ))
            return -1;
        skip_list_delete_with_key(&s->set_list,obj->value,key,klen);
        ret = dict_add_double(&s->set_dict,key,klen,score,0,-1);
        skip_list_insert(&s->set_list,score,key,klen);
        if(ret != -1)
            printf("Fatal : Key which is supposed to exist, does not exist\n");
    }
    return ret;
}

variable_types: ret int

variable_types: exp double

variable_types: union vr_object { double value; struct set { struct dict_ { unsigned int len; unsigned int size; char type; struct list { char type; unsigned int len; struct list_node { struct list_node *next; int klen; char *key; union vr_object object; double expiry; } *root; } *table; } set_dict; struct skip_list { struct skip_list_node { double score; struct skip_list_node **next; char *key; int klen; } *header; int level; } set_list; int len; } *obj_set; struct vr_string { int len; char *string; } string; } *


decompiled_code:
__int64 __fastcall set_print(__int64 a1)
{
return skip_list_print(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return skip_list_print(a1 + 24);
}

original_code:
void set_print(set* s)
{
    skip_list_print(&s->set_list);
}

canonical_original_code:
void set_print(struct set *s)
{
    skip_list_print(&s->set_list);
}


decompiled_code:
__int64 __fastcall set_clear(__int64 a1)
{
dict_clear();
return skip_list_clear(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
dict_clear();
return skip_list_clear(a1 + 24);
}

original_code:
void set_clear(set *s)
{
    dict_clear(&s->set_dict);
    skip_list_clear(&s->set_list);
}

canonical_original_code:
void set_clear(struct set *s)
{
    dict_clear(&s->set_dict);
    skip_list_clear(&s->set_list);
}


repo: vijkp/Remodel

decompiled_code:
int __fastcall main_dispatch_all_leaf_nodes(__int64 a1)
{
int result; // eax
__int64 v2; // rbp
__int64 v3; // rax
__int64 v4; // rbp
__int64 v5; // rbp

if ( !a1 )
_assert_fail("rmnode != NULL", "main.c", 0xBAu, "main_dispatch_all_leaf_nodes");
result = *(_DWORD *)(a1 + 296);
if ( result )
{
v2 = 0LL;
if ( result > 0 )
{
do
result = main_dispatch_all_leaf_nodes(*(_QWORD *)(*(_QWORD *)(a1 + 288) + 8 * v2++));
while ( *(_DWORD *)(a1 + 296) > (int)v2 );
}
}
else
{
if ( *(_DWORD *)(a1 + 256) != 1 )
_assert_fail("rmnode->type == RM_TYPE_TARGET", "main.c", 0xBCu, "main_dispatch_all_leaf_nodes");
v3 = *(_QWORD *)(a1 + 264);
if ( *(_DWORD *)(v3 + 280) == 1 )
{
*(_DWORD *)(v3 + 280) = 2;
v5 = queue_node_new();
*(_QWORD *)(v5 + 16) = a1;
pthread_mutex_lock((pthread_mutex_t *)((char *)dispatch_queue + 272));
queue_add_node(dispatch_queue, v5);
result = pthread_mutex_unlock((pthread_mutex_t *)((char *)dispatch_queue + 272));
}
else
{
v4 = queue_node_new();
*(_QWORD *)(v4 + 16) = a1;
pthread_mutex_lock((pthread_mutex_t *)((char *)monitor_queue + 272));
queue_add_node(monitor_queue, v4);
result = pthread_mutex_unlock((pthread_mutex_t *)((char *)monitor_queue + 272));
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
int result; // eax
__int64 v2; // rbp
__int64 v3; // rax
__int64 v4; // rbp
__int64 v5; // rbp

if ( !a1 )
_assert_fail("rmnode != NULL", "main.c", 0xBAu, "main_dispatch_all_leaf_nodes");
result = *(_DWORD *)(a1 + 296);
if ( result )
{
v2 = 0LL;
if ( result > 0 )
{
do
result = func0(*(_QWORD *)(*(_QWORD *)(a1 + 288) + 8 * v2++));
while ( *(_DWORD *)(a1 + 296) > (int)v2 );
}
}
else
{
if ( *(_DWORD *)(a1 + 256) != 1 )
_assert_fail("rmnode->type == RM_TYPE_TARGET", "main.c", 0xBCu, "main_dispatch_all_leaf_nodes");
v3 = *(_QWORD *)(a1 + 264);
if ( *(_DWORD *)(v3 + 280) == 1 )
{
*(_DWORD *)(v3 + 280) = 2;
v5 = queue_node_new();
*(_QWORD *)(v5 + 16) = a1;
pthread_mutex_lock((pthread_mutex_t *)((char *)dispatch_queue + 272));
queue_add_node(dispatch_queue, v5);
result = pthread_mutex_unlock((pthread_mutex_t *)((char *)dispatch_queue + 272));
}
else
{
v4 = queue_node_new();
*(_QWORD *)(v4 + 16) = a1;
pthread_mutex_lock((pthread_mutex_t *)((char *)monitor_queue + 272));
queue_add_node(monitor_queue, v4);
result = pthread_mutex_unlock((pthread_mutex_t *)((char *)monitor_queue + 272));
}
}
return result;
}

original_code:
void main_dispatch_all_leaf_nodes(remodel_node_t *rmnode) {
    queue_node_t *queue_node = ((void *)0);
    build_state_t build_state;
    int i;
    ((void) sizeof ((rmnode != ((void *)0)) ? 1 : 0), __extension__ ({ if (rmnode != ((void *)0)) ; else __assert_fail ("rmnode != NULL", "main.c", 186, __extension__ __PRETTY_FUNCTION__); }));
    if (rmnode->child_nodes == 0) {
        ((void) sizeof ((rmnode->type == RM_TYPE_TARGET) ? 1 : 0), __extension__ ({ if (rmnode->type == RM_TYPE_TARGET) ; else __assert_fail ("rmnode->type == RM_TYPE_TARGET", "main.c", 188, __extension__ __PRETTY_FUNCTION__); }));
        build_state = rmnode->target->build_state;
        if (build_state == RM_BUILD_READY) {
            rmnode->target->build_state = RM_BUILD_ONQ;
        }
        queue_node = queue_node_new();
        queue_node->data = (void *)rmnode;
        if (build_state == RM_BUILD_READY) {
            do { pthread_mutex_lock(&(dispatch_queue->mtx)); queue_add_node(dispatch_queue, queue_node); pthread_mutex_unlock(&(dispatch_queue->mtx)); } while(0);
        } else {
            do { pthread_mutex_lock(&(monitor_queue->mtx)); queue_add_node(monitor_queue, queue_node); pthread_mutex_unlock(&(monitor_queue->mtx)); } while(0);
        }
        return;
    }
    for (i = 0; i < rmnode->child_nodes; i++) {
        main_dispatch_all_leaf_nodes(rmnode->children[i]);
    }
}

canonical_original_code:
void main_dispatch_all_leaf_nodes(struct remodel_node_ *rmnode) {
    struct queue_node_ *queue_node = ((void *)0);
    enum build_state_t build_state;
    int i;
    ((void) sizeof ((rmnode != ((void *)0)) ? 1 : 0), __extension__ ({ if (rmnode != ((void *)0)) ; else __assert_fail ("rmnode != NULL", "main.c", 186, __extension__ __PRETTY_FUNCTION__); }));
    if (rmnode->child_nodes == 0) {
        ((void) sizeof ((rmnode->type == RM_TYPE_TARGET) ? 1 : 0), __extension__ ({ if (rmnode->type == RM_TYPE_TARGET) ; else __assert_fail ("rmnode->type == RM_TYPE_TARGET", "main.c", 188, __extension__ __PRETTY_FUNCTION__); }));
        build_state = rmnode->target->build_state;
        if (build_state == RM_BUILD_READY) {
            rmnode->target->build_state = RM_BUILD_ONQ;
        }
        queue_node = queue_node_new();
        queue_node->data = (void *)rmnode;
        if (build_state == RM_BUILD_READY) {
            do { pthread_mutex_lock(&(dispatch_queue->mtx)); queue_add_node(dispatch_queue, queue_node); pthread_mutex_unlock(&(dispatch_queue->mtx)); } while(0);
        } else {
            do { pthread_mutex_lock(&(monitor_queue->mtx)); queue_add_node(monitor_queue, queue_node); pthread_mutex_unlock(&(monitor_queue->mtx)); } while(0);
        }
        return;
    }
    for (i = 0; i < rmnode->child_nodes; i++) {
        main_dispatch_all_leaf_nodes(rmnode->children[i]);
    }
}

variable_types: struct remodel_node_ { char name[256]; enum rm_file_type_t { RM_TYPE_UNKNOWN=0, RM_TYPE_TARGET=1, RM_TYPE_SRC=2, RM_TYPE_HEADER=3 } type; struct target_ { char name[256]; char *command; struct dependency_ { char name[256]; enum rm_file_type_t { RM_TYPE_UNKNOWN=0, RM_TYPE_TARGET=1, RM_TYPE_SRC=2, RM_TYPE_HEADER=3 } type; struct dependency_ *next; } *dp_head; struct target_ *next; enum build_state_t { RM_BUILD_DONE=0, RM_BUILD_READY=1, RM_BUILD_ONQ=2, RM_BUILD_RUNNING=3 } build_state; int total_dp; int changed_dp; } *target; struct srcfile_ { char name[256]; char md5hash[-1]; _Bool md5_present; _Bool md5_changed; struct srcfile_ *next; } *srcfile; struct remodel_node_ *parent; struct remodel_node_ **children; int child_nodes; } *

variable_types: struct queue_node_ { struct queue_node_ *prev; struct queue_node_ *next; void *data; _Bool signal; } *

user_defined_types: struct remodel_node_ { char name[256]; enum rm_file_type_t type; struct target_ *target; struct srcfile_ *srcfile; struct remodel_node_ *parent; struct remodel_node_ **children; int child_nodes; }

user_defined_types: struct target_ { char name[256]; char *command; struct dependency_ *dp_head; struct target_ *next; enum build_state_t build_state; int total_dp; int changed_dp; }

user_defined_types: struct dependency_ { char name[256]; enum rm_file_type_t type; struct dependency_ *next; }