decompiled_code:
__int64 __fastcall tower_upd_normal(__int64 a1, int a2)
{
__int64 v3; // rbp
unsigned int v4; // eax
__int64 v5; // r12
__int64 result; // rax
__int64 v7; // rsi
__int64 v8; // rdx
int v9; // esi

v3 = *(_QWORD *)(a1 + 32);
if ( v3 )
{
if ( (unsigned int)damage_not_worthwhile(*(_QWORD *)(a1 + 32), *(unsigned int *)(a1 + 28))
|| distance2_isra_0(*(float *)(a1 + 4), *(float *)(a1 + 8), *(float *)(v3 + 24), *(float *)(v3 + 28)) > *(float *)(a1 + 24) )
{
noob_ref_destroy(v3);
v4 = *(_DWORD *)(a1 + 16);
if ( v4 >= *(_DWORD *)(a1 + 20) )
{
LABEL_5:
v5 = a1 + 4;
result = noob_find_target(a1 + 4, *(unsigned int *)(a1 + 28));
v3 = result;
if ( !result )
{
LABEL_8:
*(_QWORD *)(a1 + 32) = v3;
return result;
}
v4 = *(_DWORD *)(a1 + 16);
v7 = *(unsigned int *)(a1 + 20);
LABEL_7:
v8 = *(unsigned int *)(a1 + 28);
*(_DWORD *)(a1 + 16) = v4 - v7;
result = bullet_new(v5, v7, v8, v3);
goto LABEL_8;
}
v3 = 0LL;
}
else
{
v4 = *(_DWORD *)(a1 + 16);
v7 = *(unsigned int *)(a1 + 20);
if ( v4 >= (unsigned int)v7 )
{
v5 = a1 + 4;
goto LABEL_7;
}
}
}
else
{
v4 = *(_DWORD *)(a1 + 16);
if ( v4 >= *(_DWORD *)(a1 + 20) )
goto LABEL_5;
}
v9 = *(_DWORD *)(a1 + 12);
*(_QWORD *)(a1 + 32) = v3;
result = a2 * v9 + v4;
*(_DWORD *)(a1 + 16) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2)
{
__int64 v3; // rbp
unsigned int v4; // eax
__int64 v5; // r12
__int64 result; // rax
__int64 v7; // rsi
__int64 v8; // rdx
int v9; // esi

v3 = *(_QWORD *)(a1 + 32);
if ( v3 )
{
if ( (unsigned int)damage_not_worthwhile(*(_QWORD *)(a1 + 32), *(unsigned int *)(a1 + 28))
|| func1(*(float *)(a1 + 4), *(float *)(a1 + 8), *(float *)(v3 + 24), *(float *)(v3 + 28)) > *(float *)(a1 + 24) )
{
noob_ref_destroy(v3);
v4 = *(_DWORD *)(a1 + 16);
if ( v4 >= *(_DWORD *)(a1 + 20) )
{
LABEL_5:
v5 = a1 + 4;
result = noob_find_target(a1 + 4, *(unsigned int *)(a1 + 28));
v3 = result;
if ( !result )
{
LABEL_8:
*(_QWORD *)(a1 + 32) = v3;
return result;
}
v4 = *(_DWORD *)(a1 + 16);
v7 = *(unsigned int *)(a1 + 20);
LABEL_7:
v8 = *(unsigned int *)(a1 + 28);
*(_DWORD *)(a1 + 16) = v4 - v7;
result = bullet_new(v5, v7, v8, v3);
goto LABEL_8;
}
v3 = 0LL;
}
else
{
v4 = *(_DWORD *)(a1 + 16);
v7 = *(unsigned int *)(a1 + 20);
if ( v4 >= (unsigned int)v7 )
{
v5 = a1 + 4;
goto LABEL_7;
}
}
}
else
{
v4 = *(_DWORD *)(a1 + 16);
if ( v4 >= *(_DWORD *)(a1 + 20) )
goto LABEL_5;
}
v9 = *(_DWORD *)(a1 + 12);
*(_QWORD *)(a1 + 32) = v3;
result = a2 * v9 + v4;
*(_DWORD *)(a1 + 16) = result;
return result;
}

original_code:
void tower_upd_normal(tower_t *tower, int dt)
{
 noob_t *target = tower->target;
 if(target != ((void *)0) && (damage_not_worthwhile(target, tower->type) ||
                       distance2(&tower->pos, &target->pos) > tower->range)) {
  noob_ref_destroy(target);
  target = ((void *)0);
 }
 if(tower->energy < tower->energymax) {
  tower->energy += tower->power * dt;
  goto out;
 }
 if(target == ((void *)0)) {
  target = noob_find_target(&tower->pos, tower->type);
  if(target == ((void *)0))
   goto out;
 }
 tower->energy -= tower->energymax;
 bullet_new(&tower->pos, tower->energymax, tower->type, target);
out:
 tower->target = target;
 return;
}

canonical_original_code:
void tower_upd_normal(struct tower_t *tower, int dt)
{
 struct noob_t *target = tower->target;
 if(target != ((void *)0) && (damage_not_worthwhile(target, tower->type) ||
                       distance2(&tower->pos, &target->pos) > tower->range)) {
  noob_ref_destroy(target);
  target = ((void *)0);
 }
 if(tower->energy < tower->energymax) {
  tower->energy += tower->power * dt;
  goto out;
 }
 if(target == ((void *)0)) {
  target = noob_find_target(&tower->pos, tower->type);
  if(target == ((void *)0))
   goto out;
 }
 tower->energy -= tower->energymax;
 bullet_new(&tower->pos, tower->energymax, tower->type, target);
out:
 tower->target = target;
 return;
}


repo: kalenedrael/kgtd

decompiled_code:
__int64 __fastcall tower_update_all(unsigned int a1)
{
__int64 i; // rbx
__int64 result; // rax

for ( i = tower_list; i; i = *(_QWORD *)(i + 48) )
result = (*(__int64 (__fastcall **)(__int64, _QWORD))(i + 40))(i, a1);
return result;
}

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

for ( i = tower_list; i; i = *(_QWORD *)(i + 48) )
result = (*(__int64 (__fastcall **)(__int64, _QWORD))(i + 40))(i, a1);
return result;
}

original_code:
void tower_update_all(int dt)
{
 tower_t *cur;
 for(cur = (&tower_list)->head; cur; cur = (cur)->list.next)
  cur->update(cur, dt);
}

canonical_original_code:
void tower_update_all(int dt)
{
 struct tower_t *cur;
 for(cur = (&tower_list)->head; cur; cur = (cur)->list.next)
  cur->update(cur, dt);
}

variable_types: dt int

variable_types: struct tower_t { enum grid_type { GRID_TYPE_NONE=0, GRID_TYPE_TOWER=1, GRID_TYPE_PATH=2 } g; struct pos_t { float x; float y; } pos; unsigned int power; unsigned int energy; unsigned int energymax; float range; enum ttype { TT_PLASMA=0, TT_LTNG=1, TT_CW=2, TT_PULSE=3, TT_APCR=4, TT_APFSDS=5, TT_DU=6, TT_HE=7, TT_HEAT=8, TT_AREA=9, TT_BASIC=10, TT_NONE=11 } type; struct noob_t { struct { struct noob_t *next; } list; struct path_t { enum grid_type { GRID_TYPE_NONE=0, GRID_TYPE_TOWER=1, GRID_TYPE_PATH=2 } g; struct pos_t pos; struct path_t *next; } *path; struct pos_t pos; float speed; int hp; int max_hp; int shield; int max_shield; int stun_time; unsigned int refcnt; unsigned char armor_type; unsigned char future_stun; unsigned char is_dead; } *target; void (*update)(struct tower_t *, int); struct { struct tower_t *next; } list; } *

return_type: void

user_defined_types: struct tower_t { enum grid_type g; struct pos_t pos; unsigned int power; unsigned int energy; unsigned int energymax; float range; enum ttype type; struct noob_t *target; void (*update)(struct tower_t *, int); struct { struct tower_t *next; } list; }

user_defined_types: struct noob_t { struct { struct noob_t *next; } list; struct path_t *path; struct pos_t pos; float speed; int hp; int max_hp; int shield; int max_shield; int stun_time; unsigned int refcnt; unsigned char armor_type; unsigned char future_stun; unsigned char is_dead; }

user_defined_types: struct path_t { enum grid_type g; struct pos_t pos; struct path_t *next; }


decompiled_code:
__int64 tower_draw_all()
{
__int64 i; // rbx
__int64 result; // rax

for ( i = tower_list; i; i = *(_QWORD *)(i + 48) )
result = draw_each(i);
return result;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 i; // rbx
__int64 result; // rax

for ( i = tower_list; i; i = *(_QWORD *)(i + 48) )
result = func0(i);
return result;
}

original_code:
void tower_draw_all()
{
 tower_t *cur;
 for(cur = (&tower_list)->head; cur; cur = (cur)->list.next)
  draw_each(cur);
}

canonical_original_code:
void tower_draw_all()
{
 struct tower_t *cur;
 for(cur = (&tower_list)->head; cur; cur = (cur)->list.next)
  draw_each(cur);
}

user_defined_types: enum grid_type { GRID_TYPE_NONE=0, GRID_TYPE_TOWER=1, GRID_TYPE_PATH=2 }

user_defined_types: enum ttype { TT_PLASMA=0, TT_LTNG=1, TT_CW=2, TT_PULSE=3, TT_APCR=4, TT_APFSDS=5, TT_DU=6, TT_HE=7, TT_HEAT=8, TT_AREA=9, TT_BASIC=10, TT_NONE=11 }


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

v0 = (unsigned int)((_DWORD)&grid + 1600);
do
{
result = (char *)(v0 - 1600);
do
{
*(_DWORD *)result = 0;
result += 64;
}
while ( result != (char *)v0 );
v0 = (unsigned __int64)(result + 1600);
}
while ( result != (char *)&grid + 30400 );
return result;
}

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

v0 = (unsigned int)((_DWORD)&grid + 1600);
do
{
result = (char *)(v0 - 1600);
do
{
*(_DWORD *)result = 0;
result += 64;
}
while ( result != (char *)v0 );
v0 = (unsigned __int64)(result + 1600);
}
while ( result != (char *)&grid + 30400 );
return result;
}

variable_types: i int

variable_types: j int


decompiled_code:
__int64 init_prelight()
{
int v0; // ebx
float v1; // xmm0_4
int i; // ebx
float v3; // xmm1_4
int v4; // ebx
float v5; // xmm1_4
float j; // xmm0_4
float v7; // xmm0_4
float v8; // xmm0_4
float v9; // xmm1_4
int v10; // ebx
float v11; // xmm1_4
float k; // xmm0_4
float v13; // xmm0_4
float cosx; // [rsp+8h] [rbp-10h] BYREF
float sinx[3]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = -64;
glNewList(19LL, 4864LL);
glColor4f(1.0, 1.0, 1.0);
glBegin(1LL);
do
{
v1 = (float)v0;
v0 += 32;
glVertex2f(v1, -96.0);
glVertex2f(v1, 128.0);
}
while ( v0 != 128 );
for ( i = -64; i != 128; i += 32 )
{
v3 = (float)i;
glVertex2f(-96.0, v3);
glVertex2f(128.0, v3);
}
((void (*)(void))glEnd)();
v4 = 0;
glEndList();
glNewList(20LL, 4864LL);
glBegin(6LL);
glColor4f(0.0, 0.0, 0.0);
glVertex2f(0.0, 0.0);
glColor4f(0.0, 0.0, 0.0);
v5 = *(float *)&LC0;
for ( j = 0.0; ; j = sinx[0] )
{
v8 = j * 96.0;
++v4;
v9 = v5 * 96.0;
glVertex2f(v8, v9);
if ( v4 == 65 )
break;
v7 = (double)v4 * 0.09817477042468103;
sincosf(v7, sinx, &cosx);
v5 = cosx;
}
glEnd(v8, v9, 0.0, COERCE_DOUBLE((unsigned __int64)LC0));
v10 = 0;
glEndList();
glNewList(21LL, 4864LL);
v11 = *(float *)&LC0;
for ( k = 0.0; ; k = sinx[0] )
{
glVertex2f(k, v11);
if ( ++v10 == 65 )
break;
v13 = (double)v10 * 0.09817477042468103;
sincosf(v13, sinx, &cosx);
v11 = cosx;
}
glEndList();
glNewList(22LL, 4864LL);
glBegin(6LL);
glVertex3f(0.0, 0.0);
glColor4f(0.0, 0.0, 0.0);
glCallList(21LL);
glEnd(0.0, 0.0, 0.0, 0.0);
return glEndList();
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // ebx
float v1; // xmm0_4
int i; // ebx
float v3; // xmm1_4
int v4; // ebx
float v5; // xmm1_4
float j; // xmm0_4
float v7; // xmm0_4
float v8; // xmm0_4
float v9; // xmm1_4
int v10; // ebx
float v11; // xmm1_4
float k; // xmm0_4
float v13; // xmm0_4
float cosx; // [rsp+8h] [rbp-10h] BYREF
float sinx[3]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = -64;
glNewList(19LL, 4864LL);
glColor4f(1.0, 1.0, 1.0);
glBegin(1LL);
do
{
v1 = (float)v0;
v0 += 32;
glVertex2f(v1, -96.0);
glVertex2f(v1, 128.0);
}
while ( v0 != 128 );
for ( i = -64; i != 128; i += 32 )
{
v3 = (float)i;
glVertex2f(-96.0, v3);
glVertex2f(128.0, v3);
}
((void (*)(void))glEnd)();
v4 = 0;
glEndList();
glNewList(20LL, 4864LL);
glBegin(6LL);
glColor4f(0.0, 0.0, 0.0);
glVertex2f(0.0, 0.0);
glColor4f(0.0, 0.0, 0.0);
v5 = *(float *)&LC0;
for ( j = 0.0; ; j = sinx[0] )
{
v8 = j * 96.0;
++v4;
v9 = v5 * 96.0;
glVertex2f(v8, v9);
if ( v4 == 65 )
break;
v7 = (double)v4 * 0.09817477042468103;
sincosf(v7, sinx, &cosx);
v5 = cosx;
}
glEnd(v8, v9, 0.0, COERCE_DOUBLE((unsigned __int64)LC0));
v10 = 0;
glEndList();
glNewList(21LL, 4864LL);
v11 = *(float *)&LC0;
for ( k = 0.0; ; k = sinx[0] )
{
glVertex2f(k, v11);
if ( ++v10 == 65 )
break;
v13 = (double)v10 * 0.09817477042468103;
sincosf(v13, sinx, &cosx);
v11 = cosx;
}
glEndList();
glNewList(22LL, 4864LL);
glBegin(6LL);
glVertex3f(0.0, 0.0);
glColor4f(0.0, 0.0, 0.0);
glCallList(21LL);
glEnd(0.0, 0.0, 0.0, 0.0);
return glEndList();
}


decompiled_code:
__int64 init_vertex_lists()
{
void *v0; // rcx
__int64 i; // rbx
__int64 result; // rax
__int64 v3; // rax

v0 = &tower_points;
for ( i = 1LL; ; ++i )
{
glVertexPointer(2LL, 5126LL, 0LL, v0);
glNewList((unsigned int)i, 4864LL);
if ( i != 14 )
break;
glDrawElements(1LL, 16LL, 5121LL, &icon_du);
glEndList();
LABEL_3:
v3 = i;
v0 = *(&off_8B8 + 2 * v3);
}
glDrawArrays((unsigned int)dword_8A4[4 * i], 0LL, (unsigned int)lists[4 * i]);
result = glEndList();
if ( i != 18 )
goto LABEL_3;
return result;
}

canonical_decompiled_code:
__int64 func1()
{
void *v0; // rcx
__int64 i; // rbx
__int64 result; // rax
__int64 v3; // rax

v0 = &tower_points;
for ( i = 1LL; ; ++i )
{
glVertexPointer(2LL, 5126LL, 0LL, v0);
glNewList((unsigned int)i, 4864LL);
if ( i != 14 )
break;
glDrawElements(1LL, 16LL, 5121LL, &icon_du);
glEndList();
LABEL_3:
v3 = i;
v0 = *(&off_8B8 + 2 * v3);
}
glDrawArrays((unsigned int)dword_8A4[4 * i], 0LL, (unsigned int)lists[4 * i]);
result = glEndList();
if ( i != 18 )
goto LABEL_3;
return result;
}

original_code:
static void init_vertex_lists()
{
 int i;
 for(i = DISPLAY_LIST_BEGIN; i <= DISPLAY_LIST_TOWER_END; i++) {
  glVertexPointer(2, 0x1406, 0, lists[i].list);
  glNewList(i, 0x1300);
  if(i == (DISPLAY_LIST_TOWER_BASE + (TT_DU)))
   glDrawElements(lists[i].type, lists[i].size,
                  0x1401, icon_du);
  else
   glDrawArrays(lists[i].type, 0, lists[i].size);
  glEndList();
 }
}


decompiled_code:
__int64 graphics_init()
{
glEnableClientState(32884LL);
init_prelight();
init_vertex_lists();
glDisableClientState(32884LL);
return glEnable(2848LL);
}

canonical_decompiled_code:
__int64 func2()
{
glEnableClientState(32884LL);
func0();
func1();
glDisableClientState(32884LL);
return glEnable(2848LL);
}

original_code:
void graphics_init(void)
{
 glEnableClientState(0x8074);
 init_prelight();
 init_vertex_lists();
 glDisableClientState(0x8074);
 glEnable(0x0B20);
}

canonical_original_code:
void graphics_init()
{
 glEnableClientState(0x8074);
 init_prelight();
 init_vertex_lists();
 glDisableClientState(0x8074);
 glEnable(0x0B20);
}


original_code:
static path_t *path_new(int x, int y)
{
 grid[y][x].g = GRID_TYPE_PATH;
 grid[y][x].p.pos.x = x * 32 + 32/2;
 grid[y][x].p.pos.y = y * 32 + 32/2;
 return &(grid[y][x].p);
}

canonical_original_code:
static struct path_t *path_new(int x, int y)
{
 grid[y][x].g = GRID_TYPE_PATH;
 grid[y][x].p.pos.x = x * 32 + 32/2;
 grid[y][x].p.pos.y = y * 32 + 32/2;
 return &(grid[y][x].p);
}

variable_types: x int

variable_types: y int

return_type: struct path_t { enum grid_type { GRID_TYPE_NONE=0, GRID_TYPE_TOWER=1, GRID_TYPE_PATH=2 } g; struct pos_t { float x; float y; } pos; struct path_t *next; } *


original_code:
static int rel_dir(int x, int y, path_t *rel)
{
 if(rel == &(grid[y + 1][x].p))
  return DIR_UP;
 if(rel == &(grid[y - 1][x].p))
  return DIR_DOWN;
 if(rel == &(grid[y][x + 1].p))
  return DIR_RIGHT;
 if(rel == &(grid[y][x - 1].p))
  return DIR_LEFT;
 return DIR_NONE;
}

canonical_original_code:
static int rel_dir(int x, int y, struct path_t *rel)
{
 if(rel == &(grid[y + 1][x].p))
  return DIR_UP;
 if(rel == &(grid[y - 1][x].p))
  return DIR_DOWN;
 if(rel == &(grid[y][x + 1].p))
  return DIR_RIGHT;
 if(rel == &(grid[y][x - 1].p))
  return DIR_LEFT;
 return DIR_NONE;
}

variable_types: struct path_t { enum grid_type { GRID_TYPE_NONE=0, GRID_TYPE_TOWER=1, GRID_TYPE_PATH=2 } g; struct pos_t { float x; float y; } pos; struct path_t *next; } *

return_type: int


original_code:
void path_load(state_t *state, map_t *map)
{
 int cur_x = map->x_start, cur_y = map->y_start, i;
 int new_x, new_y;
 int length = map->length;
 int *path = map->path;
 float x, y;
 path_t *cur, *prev = ((void *)0);
 cur = state->path = path_new(map->x_start, map->y_start);
 for(i = 0; i < length; i+=2) {
  new_x = cur_x + path[i];
  if(path[i] > 0) {
   for(; cur_x < new_x; cur_x++) {
    cur->next = path_new(cur_x, cur_y);
    cur = cur->next;
   }
  }
  else if(path[i] < 0) {
   for(; cur_x > new_x; cur_x--) {
    cur->next = path_new(cur_x, cur_y);
    cur = cur->next;
   }
  }
  if(i == length - 1)
   break;
  new_y = cur_y + path[i+1];
  if(path[i + 1] > 0) {
   for(; cur_y < new_y; cur_y++) {
    cur->next = path_new(cur_x, cur_y);
    cur = cur->next;
   }
  }
  else if(path[i + 1] < 0) {
   for(; cur_y > new_y; cur_y--) {
    cur->next = path_new(cur_x, cur_y);
    cur = cur->next;
   }
  }
 }
 cur->next = ((void *)0);
 glNewList(DISPLAY_LIST_PATH, 0x1300);
 glBegin(0x0007);
 for(cur = state->path; cur != ((void *)0); cur = cur->next) {
  x = cur->pos.x;
  y = cur->pos.y;
  if(cur->next == ((void *)0))
   glColor3f(0.9, 0.2, 0.2);
  else if(cur == state->path)
   glColor3f(0.1, 0.5, 0.1);
  else
   glColor3f(0.1, 0.1, 0.1);
  glVertex2f(x - 32/2, y - 32/2);
  glVertex2f(x + 32/2, y - 32/2);
  glVertex2f(x + 32/2, y + 32/2);
  glVertex2f(x - 32/2, y + 32/2);
 }
 glEnd();
 cur = state->path;
 cur_x = map->x_start;
 cur_y = map->y_start;
 glBegin(0x0001);
 for(i = 0; i < length; i+=2) {
  new_x = cur_x + path[i];
  if(path[i] > 0) {
   for(; cur_x < new_x; cur_x++) {
    draw_one(cur_x, cur_y, cur, prev);
    prev = cur;
    cur = cur->next;
   }
  }
  else if(path[i] < 0) {
   for(; cur_x > new_x; cur_x--) {
    draw_one(cur_x, cur_y, cur, prev);
    prev = cur;
    cur = cur->next;
   }
  }
  if(i == length - 1)
   break;
  new_y = cur_y + path[i+1];
  if(path[i + 1] > 0) {
   for(; cur_y < new_y; cur_y++) {
    draw_one(cur_x, cur_y, cur, prev);
    prev = cur;
    cur = cur->next;
   }
  }
  else if(path[i + 1] < 0) {
   for(; cur_y > new_y; cur_y--) {
    draw_one(cur_x, cur_y, cur, prev);
    prev = cur;
    cur = cur->next;
   }
  }
 }
 glEnd();
 glEndList();
}

canonical_original_code:
void path_load(struct state_t *state, struct map_t *map)
{
 int cur_x = map->x_start; int cur_y = map->y_start; int i;
 int new_x; int new_y;
 int length = map->length;
 int *path = map->path;
 float x; float y;
 struct path_t *cur; struct path_t *prev = ((void *)0);
 cur = state->path = path_new(map->x_start, map->y_start);
 for(i = 0; i < length; i+=2) {
  new_x = cur_x + path[i];
  if(path[i] > 0) {
   for(; cur_x < new_x; cur_x++) {
    cur->next = path_new(cur_x, cur_y);
    cur = cur->next;
   }
  }
  else if(path[i] < 0) {
   for(; cur_x > new_x; cur_x--) {
    cur->next = path_new(cur_x, cur_y);
    cur = cur->next;
   }
  }
  if(i == length - 1)
   break;
  new_y = cur_y + path[i+1];
  if(path[i + 1] > 0) {
   for(; cur_y < new_y; cur_y++) {
    cur->next = path_new(cur_x, cur_y);
    cur = cur->next;
   }
  }
  else if(path[i + 1] < 0) {
   for(; cur_y > new_y; cur_y--) {
    cur->next = path_new(cur_x, cur_y);
    cur = cur->next;
   }
  }
 }
 cur->next = ((void *)0);
 glNewList(DISPLAY_LIST_PATH, 0x1300);
 glBegin(0x0007);
 for(cur = state->path; cur != ((void *)0); cur = cur->next) {
  x = cur->pos.x;
  y = cur->pos.y;
  if(cur->next == ((void *)0))
   glColor3f(0.9, 0.2, 0.2);
  else if(cur == state->path)
   glColor3f(0.1, 0.5, 0.1);
  else
   glColor3f(0.1, 0.1, 0.1);
  glVertex2f(x - 32/2, y - 32/2);
  glVertex2f(x + 32/2, y - 32/2);
  glVertex2f(x + 32/2, y + 32/2);
  glVertex2f(x - 32/2, y + 32/2);
 }
 glEnd();
 cur = state->path;
 cur_x = map->x_start;
 cur_y = map->y_start;
 glBegin(0x0001);
 for(i = 0; i < length; i+=2) {
  new_x = cur_x + path[i];
  if(path[i] > 0) {
   for(; cur_x < new_x; cur_x++) {
    draw_one(cur_x, cur_y, cur, prev);
    prev = cur;
    cur = cur->next;
   }
  }
  else if(path[i] < 0) {
   for(; cur_x > new_x; cur_x--) {
    draw_one(cur_x, cur_y, cur, prev);
    prev = cur;
    cur = cur->next;
   }
  }
  if(i == length - 1)
   break;
  new_y = cur_y + path[i+1];
  if(path[i + 1] > 0) {
   for(; cur_y < new_y; cur_y++) {
    draw_one(cur_x, cur_y, cur, prev);
    prev = cur;
    cur = cur->next;
   }
  }
  else if(path[i + 1] < 0) {
   for(; cur_y > new_y; cur_y--) {
    draw_one(cur_x, cur_y, cur, prev);
    prev = cur;
    cur = cur->next;
   }
  }
 }
 glEnd();
 glEndList();
}

variable_types: struct state_t { int score; int gil; int kills; int leaks; int level_noobs; int total_noobs; int power_used; int max_power; int towers; int until_next; enum ttype { TT_PLASMA=0, TT_LTNG=1, TT_CW=2, TT_PULSE=3, TT_APCR=4, TT_APFSDS=5, TT_DU=6, TT_HE=7, TT_HEAT=8, TT_AREA=9, TT_BASIC=10, TT_NONE=11 } selected; struct path_t { enum grid_type { GRID_TYPE_NONE=0, GRID_TYPE_TOWER=1, GRID_TYPE_PATH=2 } g; struct pos_t { float x; float y; } pos; struct path_t *next; } *path; struct level_t { struct level_t *next; struct map_t { int *path; int length; int x_start; int y_start; } map; struct wave_t { struct wave_t *next; int noobs; int hp; int shield; int delay; float speed; unsigned char armor_type; } *waves; } *level; struct wave_t *wave; } *

variable_types:
map
struct map_t *

variable_types: length int

variable_types:
path
int *

variable_types: x float

variable_types: y float

user_defined_types: struct state_t { int score; int gil; int kills; int leaks; int level_noobs; int total_noobs; int power_used; int max_power; int towers; int until_next; enum ttype selected; struct path_t *path; struct level_t *level; struct wave_t *wave; }

user_defined_types: struct level_t { struct level_t *next; struct map_t map; struct wave_t *waves; }


decompiled_code:
__int64 path_draw_all()
{
return glCallList(23LL);
}

canonical_decompiled_code:
__int64 func4()
{
return glCallList(23LL);
}

original_code:
void path_draw_all(state_t *state)
{
 glCallList(DISPLAY_LIST_PATH);
}

canonical_original_code:
void path_draw_all(struct state_t *state)
{
 glCallList(DISPLAY_LIST_PATH);
}

user_defined_types: struct map_t { int *path; int length; int x_start; int y_start; }

user_defined_types: struct wave_t { struct wave_t *next; int noobs; int hp; int shield; int delay; float speed; unsigned char armor_type; }


decompiled_code:
__int64 __fastcall level_init(__int64 a1)
{
__int64 v1; // rsi
__int64 v2; // rax
__int64 result; // rax

v1 = levels;
v2 = *(_QWORD *)(levels + 32LL);
*(_QWORD *)(a1 + 56) = levels;
*(_QWORD *)(a1 + 64) = v2;
result = path_load(a1, v1 + 8);
*(_DWORD *)(a1 + 36) = 20000;
until_spawn = 0;
return result;
}

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

v1 = levels;
v2 = *(_QWORD *)(levels + 32LL);
*(_QWORD *)(a1 + 56) = levels;
*(_QWORD *)(a1 + 64) = v2;
result = path_load(a1, v1 + 8);
*(_DWORD *)(a1 + 36) = 20000;
until_spawn = 0;
return result;
}

original_code:
void level_init(state_t *state)
{
 state->level = levels;
 state->wave = levels->waves;
 path_load(state, &state->level->map);
 until_spawn = 0;
 state->until_next = 20 * 1000;
}

canonical_original_code:
void level_init(struct state_t *state)
{
 state->level = levels;
 state->wave = levels->waves;
 path_load(state, &state->level->map);
 until_spawn = 0;
 state->until_next = 20 * 1000;
}


original_code:
void level_update(int dt, state_t *state)
{
 int next = state->until_next;
 wave_t *wave = state->wave;
 level_t *level = state->level;
 next = next > dt ? next - dt : 0;
 if(next == 0 && level != ((void *)0) && state->level_noobs >= wave->noobs) {
  if(wave->next != ((void *)0)) {
   state->wave = wave = wave->next;
   next = 20 * 1000;
   state->level_noobs = 0;
  }
  else if(state->kills + state->leaks >= state->total_noobs) {
   state->level = level->next;
   if(state->level != ((void *)0)) {
    state->wave = wave = state->level->waves;
    tower_init();
    grid_init();
    state->towers = 0;
    state->power_used = 0;
    path_load(state, &level->next->map);
   }
   next = 20 * 1000;
   state->level_noobs = 0;
  }
 }
 state->until_next = next;
 until_spawn = until_spawn > dt ? until_spawn - dt : 0;
 if(state->level_noobs == wave->noobs)
  return;
 if(until_spawn == 0) {
  noob_spawn(wave->speed, wave->hp, wave->shield,
             wave->armor_type, state);
  if(level != ((void *)0))
   state->level_noobs++;
  until_spawn += wave->delay;
 }
}

canonical_original_code:
void level_update(int dt, struct state_t *state)
{
 int next = state->until_next;
 struct wave_t *wave = state->wave;
 struct level_t *level = state->level;
 next = next > dt ? next - dt : 0;
 if(next == 0 && level != ((void *)0) && state->level_noobs >= wave->noobs) {
  if(wave->next != ((void *)0)) {
   state->wave = wave = wave->next;
   next = 20 * 1000;
   state->level_noobs = 0;
  }
  else if(state->kills + state->leaks >= state->total_noobs) {
   state->level = level->next;
   if(state->level != ((void *)0)) {
    state->wave = wave = state->level->waves;
    tower_init();
    grid_init();
    state->towers = 0;
    state->power_used = 0;
    path_load(state, &level->next->map);
   }
   next = 20 * 1000;
   state->level_noobs = 0;
  }
 }
 state->until_next = next;
 until_spawn = until_spawn > dt ? until_spawn - dt : 0;
 if(state->level_noobs == wave->noobs)
  return;
 if(until_spawn == 0) {
  noob_spawn(wave->speed, wave->hp, wave->shield,
             wave->armor_type, state);
  if(level != ((void *)0))
   state->level_noobs++;
  until_spawn += wave->delay;
 }
}

variable_types: next int

variable_types: struct level_t { struct level_t *next; struct map_t { int *path; int length; int x_start; int y_start; } map; struct wave_t { struct wave_t *next; int noobs; int hp; int shield; int delay; float speed; unsigned char armor_type; } *waves; } *


Name

repo: kalxas/zoo-project

decompiled_code:
__int64 Name()
{
unsigned int v0; // eax
char v2[104]; // [rsp+0h] [rbp-68h] BYREF

v0 = cgiFormStringNoNewlines("name", v2, 81LL);
switch ( v0 )
{
case 0u:
FCGI_printf("Name fetched, result code: cgiFormSuccess
\n", v0);
break;
case 1u:
FCGI_printf("Name fetched, result code: cgiFormTruncated
\n", v0);
break;
case 3u:
FCGI_printf("Name fetched, result code: cgiFormEmpty
\n", v0);
break;
case 4u:
FCGI_printf("Name fetched, result code: cgiFormNotFound
\n", v0);
break;
case 7u:
FCGI_printf("Name fetched, result code: cgiFormMemory
\n", v0);
break;
default:
FCGI_printf("Name fetched, unexpected result code: %d\n", v0);
break;
}
return FCGI_printf("Name: %s
\n", v2);
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // eax
char v2[104]; // [rsp+0h] [rbp-68h] BYREF

v0 = cgiFormStringNoNewlines("name", v2, 81LL);
switch ( v0 )
{
case 0u:
FCGI_printf("Name fetched, result code: cgiFormSuccess
\n", v0);
break;
case 1u:
FCGI_printf("Name fetched, result code: cgiFormTruncated
\n", v0);
break;
case 3u:
FCGI_printf("Name fetched, result code: cgiFormEmpty
\n", v0);
break;
case 4u:
FCGI_printf("Name fetched, result code: cgiFormNotFound
\n", v0);
break;
case 7u:
FCGI_printf("Name fetched, result code: cgiFormMemory
\n", v0);
break;
default:
FCGI_printf("Name fetched, unexpected result code: %d\n", v0);
break;
}
return FCGI_printf("Name: %s
\n", v2);
}

original_code:
void Name() {
 char name[81];
 int result = cgiFormStringNoNewlines("name", name, 81);
 switch (result) {
  case cgiFormSuccess:
  FCGI_printf( "Name fetched, result code: cgiFormSuccess
\n");
  break;
  case cgiFormTruncated:
  FCGI_printf( "Name fetched, result code: cgiFormTruncated
\n");
  break;
  case cgiFormEmpty:
  FCGI_printf( "Name fetched, result code: cgiFormEmpty
\n");
  break;
  case cgiFormNotFound:
  FCGI_printf( "Name fetched, result code: cgiFormNotFound
\n");
  break;
  case cgiFormMemory:
  FCGI_printf( "Name fetched, result code: cgiFormMemory
\n");
  break;
  default:
  FCGI_printf( "Name fetched, unexpected result code: %d\n", result);
  break;
 }
 FCGI_printf( "Name: %s
\n", name);
}

variable_types:
name
char [81]

variable_types: result int


Address

decompiled_code:
__int64 Address()
{
char v1[264]; // [rsp+0h] [rbp-108h] BYREF

cgiFormString("address", v1, 241LL);
return FCGI_printf("Address: <PRE>\n%s</PRE>\n", v1);
}

canonical_decompiled_code:
__int64 func1()
{
char v1[264]; // [rsp+0h] [rbp-108h] BYREF

cgiFormString("address", v1, 241LL);
return FCGI_printf("Address: <PRE>\n%s</PRE>\n", v1);
}

original_code:
void Address() {
 char address[241];
 cgiFormString("address", address, 241);
 FCGI_printf( "Address: <PRE>\n%s</PRE>\n", address);
}

variable_types:
address
char [241]


Hungry

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

if ( (unsigned int)cgiFormCheckboxSingle("hungry") )
result = FCGI_printf("I'm Not Hungry!
\n");
else
result = FCGI_printf("I'm Hungry!
\n");
return result;
}

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

if ( (unsigned int)cgiFormCheckboxSingle("hungry") )
result = FCGI_printf("I'm Not Hungry!
\n");
else
result = FCGI_printf("I'm Hungry!
\n");
return result;
}

original_code:
void Hungry() {
 if (cgiFormCheckboxSingle("hungry") == cgiFormSuccess) {
  FCGI_printf( "I'm Hungry!
\n");
 } else {
  FCGI_printf( "I'm Not Hungry!
\n");
 }
}


Temperature

decompiled_code:
__int64 Temperature()
{
double v1[2]; // [rsp+8h] [rbp-10h] BYREF

cgiFormDoubleBounded("temperature", v1, 80.0, 120.0, 98.59999999999999);
return FCGI_printf("My temperature is %f.<BR>\n", v1[0]);
}

canonical_decompiled_code:
__int64 func3()
{
double v1[2]; // [rsp+8h] [rbp-10h] BYREF

cgiFormDoubleBounded("temperature", v1, 80.0, 120.0, 98.59999999999999);
return FCGI_printf("My temperature is %f.<BR>\n", v1[0]);
}

original_code:
void Temperature() {
 double temperature;
 cgiFormDoubleBounded("temperature", &temperature, 80.0, 120.0, 98.6);
 FCGI_printf( "My temperature is %f.<BR>\n", temperature);
}

variable_types: temperature double


Frogs

decompiled_code:
__int64 Frogs()
{
unsigned int v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

cgiFormInteger("frogs", v1, 0LL);
return FCGI_printf("I have eaten %d frogs.<BR>\n", v1[0]);
}

canonical_decompiled_code:
__int64 func4()
{
unsigned int v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

cgiFormInteger("frogs", v1, 0LL);
return FCGI_printf("I have eaten %d frogs.<BR>\n", v1[0]);
}

original_code:
void Frogs() {
 int frogsEaten;
 cgiFormInteger("frogs", &frogsEaten, 0);
 FCGI_printf( "I have eaten %d frogs.<BR>\n", frogsEaten);
}

variable_types: frogsEaten int


Color

decompiled_code:
__int64 Color()
{
int v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

cgiFormSelectSingle("colors", &colors, 3LL, v1, 0LL);
return FCGI_printf("I am: %s<BR>\n", (&colors)[v1[0]]);
}

canonical_decompiled_code:
__int64 func5()
{
int v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

cgiFormSelectSingle("colors", &colors, 3LL, v1, 0LL);
return FCGI_printf("I am: %s<BR>\n", (&colors)[v1[0]]);
}

original_code:
void Color() {
 int colorChoice;
 cgiFormSelectSingle("colors", colors, 3, &colorChoice, 0);
 FCGI_printf( "I am: %s<BR>\n", colors[colorChoice]);
}

variable_types: colorChoice int


Flavors

decompiled_code:
__int64 Flavors()
{
__int64 v0; // rbx
_BYTE v2[24]; // [rsp+0h] [rbp-18h] BYREF

if ( (unsigned int)cgiFormSelectMultiple("flavors", flavors, 3LL, &v2[4], v2) == 4 )
return FCGI_printf("I hate ice cream.<p>\n");
v0 = 0LL;
FCGI_printf("My favorite ice cream flavors are:\n");
FCGI_printf("<ul>\n");
do
{
if ( *(_DWORD *)&v2[4 * v0 + 4] )
FCGI_printf("<li>%s\n", flavors[v0]);
++v0;
}
while ( v0 != 3 );
return FCGI_printf("</ul>\n");
}

canonical_decompiled_code:
__int64 func6()
{
__int64 v0; // rbx
_BYTE v2[24]; // [rsp+0h] [rbp-18h] BYREF

if ( (unsigned int)cgiFormSelectMultiple("flavors", flavors, 3LL, &v2[4], v2) == 4 )
return FCGI_printf("I hate ice cream.<p>\n");
v0 = 0LL;
FCGI_printf("My favorite ice cream flavors are:\n");
FCGI_printf("<ul>\n");
do
{
if ( *(_DWORD *)&v2[4 * v0 + 4] )
FCGI_printf("<li>%s\n", flavors[v0]);
++v0;
}
while ( v0 != 3 );
return FCGI_printf("</ul>\n");
}

original_code:
void Flavors() {
 int flavorChoices[3];
 int i;
 int result;
 int invalid;
 result = cgiFormSelectMultiple("flavors", flavors, 3,
  flavorChoices, &invalid);
 if (result == cgiFormNotFound) {
  FCGI_printf( "I hate ice cream.<p>\n");
 } else {
  FCGI_printf( "My favorite ice cream flavors are:\n");
  FCGI_printf( "<ul>\n");
  for (i=0; (i < 3); i++) {
   if (flavorChoices[i]) {
    FCGI_printf( "<li>%s\n", flavors[i]);
   }
  }
  FCGI_printf( "</ul>\n");
 }
}

variable_types:
flavorChoices
int [3]

variable_types: i int

variable_types: invalid int


RadioButtons

decompiled_code:
__int64 RadioButtons()
{
int v1; // [rsp+0h] [rbp-18h] BYREF
char v2[18]; // [rsp+6h] [rbp-12h] BYREF

cgiFormRadio("age", ages, 4LL, &v1, 0LL);
FCGI_printf("Age of Truck: %s (method #1)
\n", ages[v1]);
cgiFormString("age", v2, 10LL);
return FCGI_printf("Age of Truck: %s (method #2)
\n", v2);
}

canonical_decompiled_code:
__int64 func7()
{
int v1; // [rsp+0h] [rbp-18h] BYREF
char v2[18]; // [rsp+6h] [rbp-12h] BYREF

cgiFormRadio("age", ages, 4LL, &v1, 0LL);
FCGI_printf("Age of Truck: %s (method #1)
\n", ages[v1]);
cgiFormString("age", v2, 10LL);
return FCGI_printf("Age of Truck: %s (method #2)
\n", v2);
}

original_code:
void RadioButtons() {
 int ageChoice;
 char ageText[10];
 cgiFormRadio("age", ages, 4, &ageChoice, 0);
 FCGI_printf( "Age of Truck: %s (method #1)
\n",
  ages[ageChoice]);
 cgiFormString("age", ageText, 10);
 FCGI_printf( "Age of Truck: %s (method #2)
\n", ageText);
}

variable_types: ageChoice int

variable_types:
ageText
char [10]


NonExButtons

decompiled_code:
__int64 NonExButtons()
{
__int64 v0; // rbx
const char *v1; // rsi
__int64 v2; // rbx
__int64 result; // rax
char v4[4]; // [rsp+4h] [rbp-24h] BYREF
const char **v5; // [rsp+8h] [rbp-20h] BYREF
int v6[6]; // [rsp+10h] [rbp-18h] BYREF

FCGI_printf("Votes (method 1):
\n");
if ( (unsigned int)cgiFormCheckboxMultiple("vote", votes, 4LL, v6, v4) == 4 )
{
FCGI_printf("I hate them all!
\n");
}
else
{
v0 = 0LL;
FCGI_printf("My preferred candidates are:\n");
FCGI_printf("
\n");
do
{
if ( v6[v0] )
FCGI_printf("
%s\n", votes[v0]);
++v0;
}
while ( v0 != 4 );
FCGI_printf("
\n");
}
FCGI_printf("Votes (method 2):
\n");
if ( (unsigned int)cgiFormStringMultiple("vote", &v5) == 4 )
{
FCGI_printf("I hate them all!
\n");
result = cgiStringArrayFree(v5);
}
else
{
FCGI_printf("My preferred candidates are:\n");
FCGI_printf("
\n");
v1 = *v5;
if ( *v5 )
{
v2 = 1LL;
do
{
FCGI_printf("
%s\n", v1);
v1 = v5[v2++];
}
while ( v1 );
}
FCGI_printf("
\n");
result = cgiStringArrayFree(v5);
}
return result;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 v0; // rbx
const char *v1; // rsi
__int64 v2; // rbx
__int64 result; // rax
char v4[4]; // [rsp+4h] [rbp-24h] BYREF
const char **v5; // [rsp+8h] [rbp-20h] BYREF
int v6[6]; // [rsp+10h] [rbp-18h] BYREF

FCGI_printf("Votes (method 1):
\n");
if ( (unsigned int)cgiFormCheckboxMultiple("vote", votes, 4LL, v6, v4) == 4 )
{
FCGI_printf("I hate them all!
\n");
}
else
{
v0 = 0LL;
FCGI_printf("My preferred candidates are:\n");
FCGI_printf("
\n");
do
{
if ( v6[v0] )
FCGI_printf("
%s\n", votes[v0]);
++v0;
}
while ( v0 != 4 );
FCGI_printf("
\n");
}
FCGI_printf("Votes (method 2):
\n");
if ( (unsigned int)cgiFormStringMultiple("vote", &v5) == 4 )
{
FCGI_printf("I hate them all!
\n");
result = cgiStringArrayFree(v5);
}
else
{
FCGI_printf("My preferred candidates are:\n");
FCGI_printf("
\n");
v1 = *v5;
if ( *v5 )
{
v2 = 1LL;
do
{
FCGI_printf("
%s\n", v1);
v1 = v5[v2++];
}
while ( v1 );
}
FCGI_printf("
\n");
result = cgiStringArrayFree(v5);
}
return result;
}

original_code:
void NonExButtons() {
 int voteChoices[4];
 int i;
 int result;
 int invalid;
 char **responses;
 FCGI_printf( "Votes (method 1):
\n");
 result = cgiFormCheckboxMultiple("vote", votes, 4,
  voteChoices, &invalid);
 if (result == cgiFormNotFound) {
  FCGI_printf( "I hate them all!
\n");
 } else {
  FCGI_printf( "My preferred candidates are:\n");
  FCGI_printf( "
\n");
  for (i=0; (i < 4); i++) {
   if (voteChoices[i]) {
    FCGI_printf( "
%s\n", votes[i]);
   }
  }
  FCGI_printf( "
\n");
 }
 FCGI_printf( "Votes (method 2):
\n");
 result = cgiFormStringMultiple("vote", &responses);
 if (result == cgiFormNotFound) {
  FCGI_printf( "I hate them all!
\n");
 } else {
  int i = 0;
  FCGI_printf( "My preferred candidates are:\n");
  FCGI_printf( "
\n");
  while (responses[i]) {
   FCGI_printf( "
%s\n", responses[i]);
   i++;
  }
  FCGI_printf( "
\n");
 }
 cgiStringArrayFree(responses);
}

variable_types:
voteChoices
int [4]

variable_types:
responses
char **


cgiMain

decompiled_code:
__int64 cgiMain()
{
dup2(cgiOut, (_DWORD)&fcgi_sF + 16);
FCGI_printf("Content-Type: text/html; charset=utf-8\r\nStatus: 200 OK\r\n\r\n");
FCGI_printf("\n");
FCGI_printf("<TITLE>cgic test</TITLE>\n");
FCGI_printf("
cgic test
\n");
Name();
Address();
Hungry();
Temperature();
Frogs();
Color();
Flavors();
NonExButtons();
RadioButtons();
FCGI_printf("\n");
return 0LL;
}

canonical_decompiled_code:
__int64 func9()
{
dup2(cgiOut, (_DWORD)&fcgi_sF + 16);
FCGI_printf("Content-Type: text/html; charset=utf-8\r\nStatus: 200 OK\r\n\r\n");
FCGI_printf("\n");
FCGI_printf("<TITLE>cgic test</TITLE>\n");
FCGI_printf("
cgic test
\n");
func0();
func1();
func2();
func3();
func4();
func5();
func6();
func8();
func7();
FCGI_printf("\n");
return 0LL;
}

original_code:
int cgiMain() {
 dup2(cgiOut,(&_fcgi_sF[1]));
 FCGI_printf("Content-Type: text/html; charset=utf-8\r\nStatus: 200 OK\r\n\r\n");
 FCGI_printf( "\n");
 FCGI_printf( "<TITLE>cgic test</TITLE>\n");
 FCGI_printf( "
cgic test
\n");
 Name();
 Address();
 Hungry();
 Temperature();
 Frogs();
 Color();
 Flavors();
 NonExButtons();
 RadioButtons();
 FCGI_printf( "\n");
 return 0;
}


repo: kamanashisroy/miniim

decompiled_code:
__int64 __fastcall opp_any_obj_callback(__int64 a1, int a2, __int64 a3, __int64 a4, int a5)
{
if ( a2 == 512 )
{
*(_QWORD *)(a1 + a5 - 8) = a3;
}
else if ( a2 == 513 )
{
(*(void (__fastcall **)(__int64, __int64, _QWORD, __int64, _QWORD))(a1 + a5 - 8))(
a1,
513LL,
0LL,
a4,
(unsigned int)(a5 - 8));
return 0LL;
}
return 0LL;
}

original_code:
static int opp_any_obj_callback(void*data, int callback, void*cb_data, va_list ap, int size) {
 void*obj = data;
 switch(callback) {
 case OPPN_ACTION_INITIALIZE:
 {
  struct any_obj*cb = (data+size);
  cb--;
  cb->cb = cb_data;
  break;
 }
 case OPPN_ACTION_FINALIZE:
 {
  struct any_obj*cb = (data+size);
  cb--;
  cb->cb(obj, OPPN_ACTION_FINALIZE, ((void *)0), ap, size - sizeof(struct any_obj));
  break;
 }
 }
 return 0;
}

canonical_original_code:
static int opp_any_obj_callback(void *data, int callback, void *cb_data, __builtin_va_list ap, int size) {
 void *obj = data;
 switch(callback) {
 case OPPN_ACTION_INITIALIZE:
 {
  struct any_obj *cb = (data+size);
  cb--;
  cb->cb = cb_data;
  break;
 }
 case OPPN_ACTION_FINALIZE:
 {
  struct any_obj *cb = (data+size);
  cb--;
  cb->cb(obj, OPPN_ACTION_FINALIZE, ((void *)0), ap, size - sizeof(struct any_obj));
  break;
 }
 }
 return 0;
}

variable_types:
data
void *

variable_types: callback int

variable_types: size int

variable_types:
obj
void *

variable_types: struct any_obj { int (*cb)(void *data, int callback, void *cb_data, __builtin_va_list ap, int size); } *


decompiled_code:
__int64 opp_any_obj_alloc(unsigned int a1, void (__fastcall *a2)(__int64, __int64, __int64, __va_list_tag *, _QWORD), __int64 a3, ...)
{
__int64 v4; // r12
gcc_va_list va; // [rsp+8h] [rbp-F0h] BYREF

va_start(va, a3);
v4 = opp_alloc4(&objs, (unsigned __int16)(a1 + 8), 0LL, a2);
a2(v4, 512LL, a3, va, a1);
return v4;
}

canonical_decompiled_code:
__int64 func1(unsigned int a1, void (__fastcall *a2)(__int64, __int64, __int64, __va_list_tag *, _QWORD), __int64 a3, ...)
{
__int64 v4; // r12
gcc_va_list va; // [rsp+8h] [rbp-F0h] BYREF

va_start(va, a3);
v4 = opp_alloc4(&objs, (unsigned __int16)(a1 + 8), 0LL, a2);
a2(v4, 512LL, a3, va, a1);
return v4;
}

original_code:
void*opp_any_obj_alloc(int size, opp_callback_t cb, void*arg, ...) {
 void*obj = opp_alloc4(&objs, size+sizeof(struct any_obj), 0, cb);
 va_list ap;
 __builtin_va_start(ap,arg);
 cb(obj, OPPN_ACTION_INITIALIZE, arg, ap, size);
 __builtin_va_end(ap);
 return obj;
}

canonical_original_code:
void *opp_any_obj_alloc(int size, int (*cb)(void *data, int callback, void *cb_data, __builtin_va_list ap, int size), void *arg, ...) {
 void *obj = opp_alloc4(&objs, size+sizeof(struct any_obj), 0, cb);
 __builtin_va_list ap;
 __builtin_va_start(ap,arg);
 cb(obj, OPPN_ACTION_INITIALIZE, arg, ap, size);
 __builtin_va_end(ap);
 return obj;
}

variable_types: int (*)(void *data, int callback, void *cb_data, __builtin_va_list ap, int size)

variable_types:
arg
void *

return_type: void *


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

result = opp_factory_create_full(&objs, 1LL, 32LL, 1LL, 3LL, opp_any_obj_callback);
if ( (_DWORD)result )
_assert_fail(
"!({opp_factory_create_full(&objs, 1, 32, 1, OPPF_HAS_LOCK | OPPF_SWEEP_ON_UNREF, opp_any_obj_callback);})",
"src/core/opp_any_obj.c",
0x3Au,
"opp_any_obj_system_init");
return result;
}

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

result = opp_factory_create_full(&objs, 1LL, 32LL, 1LL, 3LL, opp_any_obj_callback);
if ( (_DWORD)result )
_assert_fail(
"!({opp_factory_create_full(&objs, 1, 32, 1, OPPF_HAS_LOCK | OPPF_SWEEP_ON_UNREF, opp_any_obj_callback);})",
"src/core/opp_any_obj.c",
0x3Au,
"opp_any_obj_system_init");
return result;
}

original_code:
void opp_any_obj_system_init() {
 ((void) sizeof ((!({opp_factory_create_full(&objs, 1, 32, 1, OPPF_HAS_LOCK | OPPF_SWEEP_ON_UNREF, opp_any_obj_callback);})) ? 1 : 0), __extension__ ({ if (!({opp_factory_create_full(&objs, 1, 32, 1, OPPF_HAS_LOCK | OPPF_SWEEP_ON_UNREF, opp_any_obj_callback);})) ; else __assert_fail ("!({opp_factory_create_full(&objs, 1, 32, 1, OPPF_HAS_LOCK | OPPF_SWEEP_ON_UNREF, opp_any_obj_callback);})", "src/core/opp_any_obj.c", 58, __extension__ __PRETTY_FUNCTION__); }));
}


decompiled_code:
__int64 opp_any_obj_system_deinit()
{
return opp_factory_destroy(&objs);
}

canonical_decompiled_code:
__int64 func3()
{
return opp_factory_destroy(&objs);
}

original_code:
void opp_any_obj_system_deinit() {
 opp_factory_destroy(&objs);
}


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

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

original_code:
static int opp_str2_verb_helper(const void*data, const void*func_data) {
 return 0;
}

canonical_original_code:
static int opp_str2_verb_helper(void *data, void *func_data) {
 return 0;
}


decompiled_code:
__int64 __fastcall opp_str2_alloc(unsigned __int16 a1)
{
return opp_alloc4(&str2_factory, a1, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int16 a1)
{
return opp_alloc4(&str2_factory, a1, 0LL, 0LL);
}

original_code:
char*opp_str2_alloc(int size) {
 return (char*)opp_alloc4(&str2_factory, size, 0, ((void *)0));
}

canonical_original_code:
char *opp_str2_alloc(int size) {
 return (char *)opp_alloc4(&str2_factory, size, 0, ((void *)0));
}

return_type: char *


decompiled_code:
__int64 __fastcall opp_str2_reuse2(__int64 *a1, const char *a2)
{
__int64 result; // rax
__int64 v3; // rdx
__int64 v4; // rcx
__int64 v5; // r8
int v6; // er12
void *v7; // rax

result = opp_unref(a1, "src/core/opp_str2.c", 58LL);
*a1 = 0LL;
if ( a2 && *a2 )
{
if ( (unsigned int)opp_exists(&str2_factory, a2, v3, v4, v5) )
{
result = opp_ref(a2, "src/core/opp_str2.c", 66LL);
*a1 = (__int64)a2;
}
else
{
v6 = strlen(a2);
v7 = (void *)opp_alloc4(&str2_factory, (unsigned __int16)(v6 + 1), 0LL, 0LL);
*a1 = (__int64)v7;
memcpy(v7, a2, v6);
result = *a1;
*(_BYTE *)(*a1 + v6) = 0;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 *a1, const char *a2)
{
__int64 result; // rax
__int64 v3; // rdx
__int64 v4; // rcx
__int64 v5; // r8
int v6; // er12
void *v7; // rax

result = opp_unref(a1, "src/core/opp_str2.c", 58LL);
*a1 = 0LL;
if ( a2 && *a2 )
{
if ( (unsigned int)opp_exists(&str2_factory, a2, v3, v4, v5) )
{
result = opp_ref(a2, "src/core/opp_str2.c", 66LL);
*a1 = (__int64)a2;
}
else
{
v6 = strlen(a2);
v7 = (void *)opp_alloc4(&str2_factory, (unsigned __int16)(v6 + 1), 0LL, 0LL);
*a1 = (__int64)v7;
memcpy(v7, a2, v6);
result = *a1;
*(_BYTE *)(*a1 + v6) = 0;
}
}
return result;
}

original_code:
void opp_str2_reuse2(char**dest, char*string) {
 int len;
 opp_unref((void**)&(*dest), "src/core/opp_str2.c", 58);
 *dest = ((void *)0);
 if(!string || !string[0]) {
  return;
 }
 if(opp_exists(&str2_factory, string)) {
  ({opp_ref(string, "src/core/opp_str2.c", 66);});
  *dest = string;
  return;
 }
 len = strlen(string);
 *dest = (char*)opp_alloc4(&str2_factory, len+1, 0, ((void *)0));
 memcpy(*dest, string, len);
 *(*dest + len) = '\0';
}

canonical_original_code:
void opp_str2_reuse2(char **dest, char *string) {
 int len;
 opp_unref((void **)&(*dest), "src/core/opp_str2.c", 58);
 *dest = ((void *)0);
 if(!string || !string[0]) {
  return;
 }
 if(opp_exists(&str2_factory, string)) {
  ({opp_ref(string, "src/core/opp_str2.c", 66);});
  *dest = string;
  return;
 }
 len = strlen(string);
 *dest = (char *)opp_alloc4(&str2_factory, len+1, 0, ((void *)0));
 memcpy(*dest, string, len);
 *(*dest + len) = '\0';
}

variable_types:
dest
char **

variable_types:
string
char *

variable_types: len int


decompiled_code:
__int64 __fastcall opp_str2_dup2(__int64 *a1, const char *a2)
{
__int64 result; // rax
int v3; // er12
void *v4; // rax

result = opp_unref(a1, "src/core/opp_str2.c", 100LL);
*a1 = 0LL;
if ( a2 )
{
if ( *a2 )
{
v3 = strlen(a2);
v4 = (void *)opp_alloc4(&str2_factory, (unsigned __int16)(v3 + 1), 0LL, 0LL);
*a1 = (__int64)v4;
memcpy(v4, a2, v3);
result = *a1;
*(_BYTE *)(*a1 + v3) = 0;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 *a1, const char *a2)
{
__int64 result; // rax
int v3; // er12
void *v4; // rax

result = opp_unref(a1, "src/core/opp_str2.c", 100LL);
*a1 = 0LL;
if ( a2 )
{
if ( *a2 )
{
v3 = strlen(a2);
v4 = (void *)opp_alloc4(&str2_factory, (unsigned __int16)(v3 + 1), 0LL, 0LL);
*a1 = (__int64)v4;
memcpy(v4, a2, v3);
result = *a1;
*(_BYTE *)(*a1 + v3) = 0;
}
}
return result;
}

original_code:
void opp_str2_dup2(char**dest, const char*string) {
 int len;
 opp_unref((void**)&(*dest), "src/core/opp_str2.c", 100);
 *dest = ((void *)0);
 if(!string || !string[0]) {
  return;
 }
 len = strlen(string);
 *dest = (char*)opp_alloc4(&str2_factory, len+1, 0, ((void *)0));
 memcpy(*dest, string, len);
 *(*dest + len) = '\0';
}

canonical_original_code:
void opp_str2_dup2(char **dest, char *string) {
 int len;
 opp_unref((void **)&(*dest), "src/core/opp_str2.c", 100);
 *dest = ((void *)0);
 if(!string || !string[0]) {
  return;
 }
 len = strlen(string);
 *dest = (char *)opp_alloc4(&str2_factory, len+1, 0, ((void *)0));
 memcpy(*dest, string, len);
 *(*dest + len) = '\0';
}


decompiled_code:
__int64 __fastcall opp_str2system_verb(__int64 a1, __int64 a2)
{
return opp_factory_verb(&str2_factory, opp_str2_verb_helper, 0LL, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
return opp_factory_verb(&str2_factory, opp_str2_verb_helper, 0LL, a1, a2);
}

original_code:
void opp_str2system_verb(void (*log)(void *log_data, const char*fmt, ...), void*log_data) {
 opp_factory_verb(&str2_factory, opp_str2_verb_helper, ((void *)0), log, log_data);
}

canonical_original_code:
void opp_str2system_verb(void (*log)(void *log_data, char *fmt, ...), void *log_data) {
 opp_factory_verb(&str2_factory, opp_str2_verb_helper, ((void *)0), log, log_data);
}

variable_types: void (*)(void *log_data, char *fmt, ...)


decompiled_code:
__int64 opp_str2system_init()
{
return opp_factory_create_full(&str2_factory, 1024LL, 32LL, 1LL, 3LL, 0LL);
}

canonical_decompiled_code:
__int64 func5()
{
return opp_factory_create_full(&str2_factory, 1024LL, 32LL, 1LL, 3LL, 0LL);
}

original_code:
void opp_str2system_init() {
  ({opp_factory_create_full(&str2_factory, OPP_STR2_BUFFER_INC, 32, 1, OPPF_HAS_LOCK | OPPF_SWEEP_ON_UNREF, ((void *)0));});
}


decompiled_code:
__int64 opp_str2system_deinit()
{
return opp_factory_destroy(&str2_factory);
}

canonical_decompiled_code:
__int64 func6()
{
return opp_factory_destroy(&str2_factory);
}

original_code:
void opp_str2system_deinit() {
 opp_factory_destroy(&str2_factory);
}


decompiled_code:
__int64 __fastcall opp_xultb_str_callback(__int64 a1, int a2)
{
if ( a2 == 513 )
opp_unref(a1, "src/core/xultb_string.c", 98LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
if ( a2 == 513 )
opp_unref(a1, "src/core/xultb_string.c", 98LL);
return 0LL;
}

original_code:
static int opp_xultb_str_callback(void*data, int callback, void*cb_data, va_list ap, int size) {
 xultb_str_t*string = (xultb_str_t*)data;
 switch(callback) {
 case OPPN_ACTION_INITIALIZE:
  return 0;
 case OPPN_ACTION_FINALIZE:
  opp_unref((void**)&(string->proto), "src/core/xultb_string.c", 98);
  break;
 }
 return 0;
}

canonical_original_code:
static int opp_xultb_str_callback(void *data, int callback, void *cb_data, __builtin_va_list ap, int size) {
 struct xultb_str *string = (xultb_str_t*)data;
 switch(callback) {
 case OPPN_ACTION_INITIALIZE:
  return 0;
 case OPPN_ACTION_FINALIZE:
  opp_unref((void **)&(string->proto), "src/core/xultb_string.c", 98);
  break;
 }
 return 0;
}

variable_types: struct xultb_str { struct xultb_str *proto; int hash; int size; int len; char *str; } *


original_code:
xultb_str_t*xultb_str_clone(const char*content, int len, int scalability_index) {
 ({if(!(content && len)) return ((void *)0);});
 struct xultb_str*str = opp_alloc4(&xultb2_factory, sizeof(struct xultb_str)+len+1, 0, ((void *)0));
 ({if(!(str)) return ((void *)0);});
 str->size = len+1;
 str->len = len;
 str->str = (char*)(str+1);
 if(len) {
  memcpy(str->str, content, len);
 }
 *(str->str+len) = '\0';
 str->hash = 0;
 str->proto = ((void *)0);
 return str;
}

canonical_original_code:
struct xultb_str *xultb_str_clone(char *content, int len, int scalability_index) {
 ({if(!(content && len)) return ((void *)0);});
 struct xultb_str *str = opp_alloc4(&xultb2_factory, sizeof(struct xultb_str)+len+1, 0, ((void *)0));
 ({if(!(str)) return ((void *)0);});
 str->size = len+1;
 str->len = len;
 str->str = (char *)(str+1);
 if(len) {
  memcpy(str->str, content, len);
 }
 *(str->str+len) = '\0';
 str->hash = 0;
 str->proto = ((void *)0);
 return str;
}

variable_types:
content
char *

return_type: struct xultb_str { struct xultb_str *proto; int hash; int size; int len; char *str; } *


decompiled_code:
__int64 __fastcall xultb_str_trim(__int64 a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return a1;
}

original_code:
xultb_str_t*xultb_str_trim(xultb_str_t*text) {
 return text;
}

canonical_original_code:
struct xultb_str *xultb_str_trim(struct xultb_str *text) {
 return text;
}

variable_types:
text
struct xultb_str *

user_defined_types: struct xultb_str { struct xultb_str *proto; int hash; int size; int len; char *str; }


original_code:
xultb_str_t*xultb_str_cat(xultb_str_t*text, xultb_str_t*suffix) {
 ((void) sizeof ((text->size > (text->len + suffix->len)) ? 1 : 0), __extension__ ({ if (text->size > (text->len + suffix->len)) ; else __assert_fail ("text->size > (text->len + suffix->len)", "src/core/xultb_string.c", 61, __extension__ __PRETTY_FUNCTION__); }));
 memcpy(text->str+text->len, suffix->str, suffix->len);
 text->len += suffix->len;
 *(text->str+text->len) = '\0';
 return text;
}

canonical_original_code:
struct xultb_str *xultb_str_cat(struct xultb_str *text, struct xultb_str *suffix) {
 ((void) sizeof ((text->size > (text->len + suffix->len)) ? 1 : 0), __extension__ ({ if (text->size > (text->len + suffix->len)) ; else __assert_fail ("text->size > (text->len + suffix->len)", "src/core/xultb_string.c", 61, __extension__ __PRETTY_FUNCTION__); }));
 memcpy(text->str+text->len, suffix->str, suffix->len);
 text->len += suffix->len;
 *(text->str+text->len) = '\0';
 return text;
}

variable_types:
suffix
struct xultb_str *


decompiled_code:
__int64 __fastcall xultb_str_cat_char(__int64 a1, char a2)
{
__int64 v2; // rdx
__int64 result; // rax
int v4; // edi
__int64 v5; // rcx

v2 = *(int *)(a1 + 16);
if ( *(_DWORD *)(a1 + 12) <= (int)v2 + 1 )
_assert_fail("text->size > (text->len + 1)", "src/core/xultb_string.c", 0x45u, "xultb_str_cat_char");
result = a1;
*(_BYTE *)(*(_QWORD *)(a1 + 24) + v2) = a2;
v4 = *(_DWORD *)(a1 + 16);
v5 = *(_QWORD *)(result + 24);
*(_DWORD *)(result + 16) = v4 + 1;
*(_BYTE *)(v5 + v4 + 1) = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, char a2)
{
__int64 v2; // rdx
__int64 result; // rax
int v4; // edi
__int64 v5; // rcx

v2 = *(int *)(a1 + 16);
if ( *(_DWORD *)(a1 + 12) <= (int)v2 + 1 )
_assert_fail("text->size > (text->len + 1)", "src/core/xultb_string.c", 0x45u, "xultb_str_cat_char");
result = a1;
*(_BYTE *)(*(_QWORD *)(a1 + 24) + v2) = a2;
v4 = *(_DWORD *)(a1 + 16);
v5 = *(_QWORD *)(result + 24);
*(_DWORD *)(result + 16) = v4 + 1;
*(_BYTE *)(v5 + v4 + 1) = 0;
return result;
}

original_code:
xultb_str_t*xultb_str_cat_char(xultb_str_t*text, char c) {
 ((void) sizeof ((text->size > (text->len + 1)) ? 1 : 0), __extension__ ({ if (text->size > (text->len + 1)) ; else __assert_fail ("text->size > (text->len + 1)", "src/core/xultb_string.c", 69, __extension__ __PRETTY_FUNCTION__); }));
 *(text->str+text->len) = c;
 text->len++;
 *(text->str+text->len) = '\0';
 return text;
}

canonical_original_code:
struct xultb_str *xultb_str_cat_char(struct xultb_str *text, char c) {
 ((void) sizeof ((text->size > (text->len + 1)) ? 1 : 0), __extension__ ({ if (text->size > (text->len + 1)) ; else __assert_fail ("text->size > (text->len + 1)", "src/core/xultb_string.c", 69, __extension__ __PRETTY_FUNCTION__); }));
 *(text->str+text->len) = c;
 text->len++;
 *(text->str+text->len) = '\0';
 return text;
}

variable_types: c char


decompiled_code:
__int64 __fastcall xultb_str_cat_static(__int64 a1, const char *a2)
{
int v3; // eax
__int64 v4; // rdi
int v5; // ebx
int v6; // ebx
__int64 v7; // rax

v3 = strlen(a2);
v4 = *(int *)(a1 + 16);
v5 = v3;
if ( *(_DWORD *)(a1 + 12) <= (int)v4 + v3 )
_assert_fail("text->size > (text->len + len)", "src/core/xultb_string.c", 0x4Eu, "xultb_str_cat_static");
memcpy((void *)(*(_QWORD *)(a1 + 24) + v4), a2, v3);
v6 = *(_DWORD *)(a1 + 16) + v5;
v7 = *(_QWORD *)(a1 + 24);
*(_DWORD *)(a1 + 16) = v6;
*(_BYTE *)(v7 + v6) = 0;
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, const char *a2)
{
int v3; // eax
__int64 v4; // rdi
int v5; // ebx
int v6; // ebx
__int64 v7; // rax

v3 = strlen(a2);
v4 = *(int *)(a1 + 16);
v5 = v3;
if ( *(_DWORD *)(a1 + 12) <= (int)v4 + v3 )
_assert_fail("text->size > (text->len + len)", "src/core/xultb_string.c", 0x4Eu, "xultb_str_cat_static");
memcpy((void *)(*(_QWORD *)(a1 + 24) + v4), a2, v3);
v6 = *(_DWORD *)(a1 + 16) + v5;
v7 = *(_QWORD *)(a1 + 24);
*(_DWORD *)(a1 + 16) = v6;
*(_BYTE *)(v7 + v6) = 0;
return a1;
}

original_code:
xultb_str_t*xultb_str_cat_static(xultb_str_t*text, char*suffix) {
 int len = strlen(suffix);
 ((void) sizeof ((text->size > (text->len + len)) ? 1 : 0), __extension__ ({ if (text->size > (text->len + len)) ; else __assert_fail ("text->size > (text->len + len)", "src/core/xultb_string.c", 78, __extension__ __PRETTY_FUNCTION__); }));
 memcpy(text->str+text->len, suffix, len);
 text->len += len;
 *(text->str+text->len) = '\0';
 return text;
}

canonical_original_code:
struct xultb_str *xultb_str_cat_static(struct xultb_str *text, char *suffix) {
 int len = strlen(suffix);
 ((void) sizeof ((text->size > (text->len + len)) ? 1 : 0), __extension__ ({ if (text->size > (text->len + len)) ; else __assert_fail ("text->size > (text->len + len)", "src/core/xultb_string.c", 78, __extension__ __PRETTY_FUNCTION__); }));
 memcpy(text->str+text->len, suffix, len);
 text->len += len;
 *(text->str+text->len) = '\0';
 return text;
}

variable_types:
suffix
char *


decompiled_code:
__int64 __fastcall xultb_str_set_len(__int64 a1, int a2)
{
__int64 v2; // rdx
__int64 result; // rax

if ( *(_DWORD *)(a1 + 12) <= a2 )
_assert_fail("text->size > len", "src/core/xultb_string.c", 0x56u, "xultb_str_set_len");
v2 = *(_QWORD *)(a1 + 24);
*(_DWORD *)(a1 + 16) = a2;
result = a1;
*(_BYTE *)(v2 + a2) = 0;
return result;
}

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

if ( *(_DWORD *)(a1 + 12) <= a2 )
_assert_fail("text->size > len", "src/core/xultb_string.c", 0x56u, "xultb_str_set_len");
v2 = *(_QWORD *)(a1 + 24);
*(_DWORD *)(a1 + 16) = a2;
result = a1;
*(_BYTE *)(v2 + a2) = 0;
return result;
}

original_code:
xultb_str_t*xultb_str_set_len(xultb_str_t*text, int len) {
 ((void) sizeof ((text->size > len) ? 1 : 0), __extension__ ({ if (text->size > len) ; else __assert_fail ("text->size > len", "src/core/xultb_string.c", 86, __extension__ __PRETTY_FUNCTION__); }));
 text->len = len;
 *(text->str+len) = '\0';
 return text;
}

canonical_original_code:
struct xultb_str *xultb_str_set_len(struct xultb_str *text, int len) {
 ((void) sizeof ((text->size > len) ? 1 : 0), __extension__ ({ if (text->size > len) ; else __assert_fail ("text->size > len", "src/core/xultb_string.c", 86, __extension__ __PRETTY_FUNCTION__); }));
 text->len = len;
 *(text->str+len) = '\0';
 return text;
}


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

if ( (unsigned int)opp_factory_create_full(&xultb2_factory, 128LL, 64LL, 1LL, 3LL, opp_xultb_str_callback) )
_assert_fail(
"!({opp_factory_create_full(&xultb2_factory, 128, sizeof(struct xultb_str)+32, 1, OPPF_HAS_LOCK | OPPF_SWEEP_ON_UNR"
"EF, opp_xultb_str_callback);})",
"src/core/xultb_string.c",
0x69u,
"xultb_str_system_init");
BLANK_STRING = xultb_str_alloc((__int64)&unk_466, 0, 0LL);
ASTERISKS_STRING = xultb_str_alloc((__int64)"***********************************************", 30, 0LL);
result = xultb_str_alloc((__int64)".", 1, 0LL);
DOT = result;
return result;
}

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

if ( (unsigned int)opp_factory_create_full(&xultb2_factory, 128LL, 64LL, 1LL, 3LL, opp_xultb_str_callback) )
_assert_fail(
"!({opp_factory_create_full(&xultb2_factory, 128, sizeof(struct xultb_str)+32, 1, OPPF_HAS_LOCK | OPPF_SWEEP_ON_UNR"
"EF, opp_xultb_str_callback);})",
"src/core/xultb_string.c",
0x69u,
"xultb_str_system_init");
BLANK_STRING = func1((__int64)&unk_466, 0, 0LL);
ASTERISKS_STRING = func1((__int64)"***********************************************", 30, 0LL);
result = func1((__int64)".", 1, 0LL);
DOT = result;
return result;
}

original_code:
void xultb_str_system_init() {
 ((void) sizeof ((!({opp_factory_create_full(&xultb2_factory, 128, sizeof(struct xultb_str)+32, 1, OPPF_HAS_LOCK | OPPF_SWEEP_ON_UNREF, opp_xultb_str_callback);})) ? 1 : 0), __extension__ ({ if (!({opp_factory_create_full(&xultb2_factory, 128, sizeof(struct xultb_str)+32, 1, OPPF_HAS_LOCK | OPPF_SWEEP_ON_UNREF, opp_xultb_str_callback);})) ; else __assert_fail ("!({opp_factory_create_full(&xultb2_factory, 128, sizeof(struct xultb_str)+32, 1, OPPF_HAS_LOCK | OPPF_SWEEP_ON_UNREF, opp_xultb_str_callback);})", "src/core/xultb_string.c", 105, __extension__ __PRETTY_FUNCTION__); }));
 BLANK_STRING = xultb_str_alloc("", 0, ((void *)0), 0);
 ASTERISKS_STRING = xultb_str_alloc("***********************************************", 30, ((void *)0), 0);
 DOT = xultb_str_alloc(".", 1, ((void *)0), 0);
}


decompiled_code:
__int64 xultb_str_system_deinit()
{
return opp_factory_destroy(&xultb2_factory);
}

canonical_decompiled_code:
__int64 func9()
{
return opp_factory_destroy(&xultb2_factory);
}

original_code:
void xultb_str_system_deinit() {
 opp_factory_destroy(&xultb2_factory);
}


decompiled_code:
__int64 __fastcall xultb_wrap_next(__int64 a1, __int64 a2, unsigned int a3, int a4)
{
unsigned int v4; // er15
int v5; // er12
__int64 v6; // rbp
int i; // ebx
int v8; // eax
unsigned int v10; // ebx
__int64 v11; // rcx
int v12; // [rsp+8h] [rbp-40h]

v4 = a3;
if ( a4 <= 0 || a2 == 0 )
return 0xFFFFFFFFLL;
if ( !a1 )
return 0xFFFFFFFFLL;
v5 = *(_DWORD *)(a1 + 16);
if ( a3 == v5 )
return 0xFFFFFFFFLL;
v12 = a3;
v6 = (int)a3;
for ( i = a3; ; ++i )
{
if ( i < v5 && *(char *)(*(_QWORD *)(a1 + 24) + v6) > 32 )
goto LABEL_13;
v8 = (*(__int64 (__fastcall **)(__int64, __int64, _QWORD, _QWORD))(a2 + 8))(a2, a1, v4, i - v4);
if ( a4 < v8 )
break;
LABEL_11:
if ( i >= v5 )
{
v12 = i;
return v12 + (unsigned int)(v12 < v5);
}
v12 = i;
if ( *(_BYTE *)(*(_QWORD *)(a1 + 24) + v6) == 10 )
return v12 + (unsigned int)(v12 < v5);
LABEL_13:
++v6;
}
if ( v12 != v4 )
{
if ( a4 < v8 )
return v12 + (unsigned int)(v12 < v5);
goto LABEL_11;
}
v10 = i - 1 - v4;
do
{
v11 = v10;
v12 = v4 + v10--;
}
while ( (*(int (__fastcall **)(__int64, __int64, _QWORD, __int64))(a2 + 8))(a2, a1, v4, v11) > a4 );
return v12 + (unsigned int)(v12 < v5);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, unsigned int a3, int a4)
{
unsigned int v4; // er15
int v5; // er12
__int64 v6; // rbp
int i; // ebx
int v8; // eax
unsigned int v10; // ebx
__int64 v11; // rcx
int v12; // [rsp+8h] [rbp-40h]

v4 = a3;
if ( a4 <= 0 || a2 == 0 )
return 0xFFFFFFFFLL;
if ( !a1 )
return 0xFFFFFFFFLL;
v5 = *(_DWORD *)(a1 + 16);
if ( a3 == v5 )
return 0xFFFFFFFFLL;
v12 = a3;
v6 = (int)a3;
for ( i = a3; ; ++i )
{
if ( i < v5 && *(char *)(*(_QWORD *)(a1 + 24) + v6) > 32 )
goto LABEL_13;
v8 = (*(__int64 (__fastcall **)(__int64, __int64, _QWORD, _QWORD))(a2 + 8))(a2, a1, v4, i - v4);
if ( a4 < v8 )
break;
LABEL_11:
if ( i >= v5 )
{
v12 = i;
return v12 + (unsigned int)(v12 < v5);
}
v12 = i;
if ( *(_BYTE *)(*(_QWORD *)(a1 + 24) + v6) == 10 )
return v12 + (unsigned int)(v12 < v5);
LABEL_13:
++v6;
}
if ( v12 != v4 )
{
if ( a4 < v8 )
return v12 + (unsigned int)(v12 < v5);
goto LABEL_11;
}
v10 = i - 1 - v4;
do
{
v11 = v10;
v12 = v4 + v10--;
}
while ( (*(int (__fastcall **)(__int64, __int64, _QWORD, __int64))(a2 + 8))(a2, a1, v4, v11) > a4 );
return v12 + (unsigned int)(v12 < v5);
}

original_code:
int xultb_wrap_next(xultb_str_t*str, xultb_font_t*font, int pos, int width) {
 int i = pos,start = pos;
 if(str == ((void *)0) || font == ((void *)0) || width <= 0 ) {
   return -1;
 }
 int len = str->len;
 if(pos == len) {
   return -1;
 }
 while (1) {
  while (i < len && str->str[i] > ' ')i++;
  int w = font->substring_width(font, str, start, i - start);
  if (pos == start) {
     if (w > width) {
      while (font->substring_width (font, str, start, (--i - start )) > width);
      pos = i;
      break;
     }
    }
    if (w <= width) pos = i;
  if (w > width || i >= len || str->str[i] == '\n') break;
  i++;
 }
 pos += (pos >= len) ? 0 : 1;
 return pos;
}

canonical_original_code:
int xultb_wrap_next(struct xultb_str *str, struct xultb_font *font, int pos, int width) {
 int i = pos; int start = pos;
 if(str == ((void *)0) || font == ((void *)0) || width <= 0 ) {
   return -1;
 }
 int len = str->len;
 if(pos == len) {
   return -1;
 }
 while (1) {
  while (i < len && str->str[i] > ' ')i++;
  int w = font->substring_width(font, str, start, i - start);
  if (pos == start) {
     if (w > width) {
      while (font->substring_width (font, str, start, (--i - start )) > width);
      pos = i;
      break;
     }
    }
    if (w <= width) pos = i;
  if (w > width || i >= len || str->str[i] == '\n') break;
  i++;
 }
 pos += (pos >= len) ? 0 : 1;
 return pos;
}

variable_types: struct xultb_font { int (*get_height)(struct xultb_font *font); int (*substring_width)(struct xultb_font *font, struct xultb_str *str, int offset, int width); } *

variable_types: pos int

variable_types: width int

variable_types: i int

variable_types: start int

variable_types: w int


usage

repo: kamenoseiji/PolariS

decompiled_code:
__int64 usage()
{
fwrite("USAGE: polaris_start [-chipv] \n", 1uLL, 0x1FuLL, stderr);
fwrite(" -a : Specify autocorrelation files to save.\n", 1uLL, 0x2EuLL, stderr);
fwrite(
" 0 -> CH0 is recorded, 12 -> CH1 and CH2 are recorded. Default: no autocorr, recorded. \n",
1uLL,
0x5EuLL,
stderr);
fwrite(" -b : Specify bandwidth [MHz] for each IF. Default: 8 MHz.\n", 1uLL, 0x3CuLL, stderr);
fwrite(" -c : Specify crosscorrelation files not saved.\n", 1uLL, 0x31uLL, stderr);
fwrite(
" 0 -> CH0xCH2 is recorded, 01 -> all Xcorrs are recorded. Default: no xcorr, recoreded. \n",
1uLL,
0x5FuLL,
stderr);
fwrite(" -f : Specify antialias filter width [MHz]. Default: through\n", 1uLL, 0x3EuLL, stderr);
fwrite(" -h : Show help \n", 1uLL, 0x12uLL, stderr);
fwrite(
" -i : Recording time [sec]. Unless specified, polaris keep recordeng until shm_init.\n",
1uLL,
0x56uLL,
stderr);
fwrite(" -q : Specify quantization bits. Default: 4 bit.\n", 1uLL, 0x32uLL, stderr);
fwrite(" -p : Specify bit-distibution files to save. Index is the same with -a option.\n", 1uLL, 0x50uLL, stderr);
fwrite(" -s : Specify number of spectral channels (2^n).\n", 1uLL, 0x32uLL, stderr);
fwrite(
" -v : Specify PGPLOT window to display spectra. /xw -> X window, /gif -> GIF, /null -> no view.\n",
1uLL,
0x61uLL,
stderr);
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
fwrite("USAGE: polaris_start [-chipv] \n", 1uLL, 0x1FuLL, stderr);
fwrite(" -a : Specify autocorrelation files to save.\n", 1uLL, 0x2EuLL, stderr);
fwrite(
" 0 -> CH0 is recorded, 12 -> CH1 and CH2 are recorded. Default: no autocorr, recorded. \n",
1uLL,
0x5EuLL,
stderr);
fwrite(" -b : Specify bandwidth [MHz] for each IF. Default: 8 MHz.\n", 1uLL, 0x3CuLL, stderr);
fwrite(" -c : Specify crosscorrelation files not saved.\n", 1uLL, 0x31uLL, stderr);
fwrite(
" 0 -> CH0xCH2 is recorded, 01 -> all Xcorrs are recorded. Default: no xcorr, recoreded. \n",
1uLL,
0x5FuLL,
stderr);
fwrite(" -f : Specify antialias filter width [MHz]. Default: through\n", 1uLL, 0x3EuLL, stderr);
fwrite(" -h : Show help \n", 1uLL, 0x12uLL, stderr);
fwrite(
" -i : Recording time [sec]. Unless specified, polaris keep recordeng until shm_init.\n",
1uLL,
0x56uLL,
stderr);
fwrite(" -q : Specify quantization bits. Default: 4 bit.\n", 1uLL, 0x32uLL, stderr);
fwrite(" -p : Specify bit-distibution files to save. Index is the same with -a option.\n", 1uLL, 0x50uLL, stderr);
fwrite(" -s : Specify number of spectral channels (2^n).\n", 1uLL, 0x32uLL, stderr);
fwrite(
" -v : Specify PGPLOT window to display spectra. /xw -> X window, /gif -> GIF, /null -> no view.\n",
1uLL,
0x61uLL,
stderr);
return 0LL;
}

original_code:
int usage(){
 fprintf(stderr, "USAGE: polaris_start [-chipv] \n");
 fprintf(stderr, "  -a : Specify autocorrelation files to save.\n");
 fprintf(stderr, "       0 -> CH0 is recorded, 12 -> CH1 and CH2 are recorded. Default: no autocorr, recorded. \n");
 fprintf(stderr, "  -b : Specify bandwidth [MHz] for each IF. Default: 8 MHz.\n");
 fprintf(stderr, "  -c : Specify crosscorrelation files not saved.\n");
 fprintf(stderr, "       0 -> CH0xCH2 is recorded, 01 -> all Xcorrs are recorded. Default: no xcorr, recoreded. \n");
 fprintf(stderr, "  -f : Specify antialias filter width [MHz]. Default: through\n");
 fprintf(stderr, "  -h : Show help \n");
 fprintf(stderr, "  -i : Recording time [sec]. Unless specified, polaris keep recordeng until shm_init.\n");
 fprintf(stderr, "  -q : Specify quantization bits. Default: 4 bit.\n");
 fprintf(stderr, "  -p : Specify bit-distibution files to save. Index is the same with -a option.\n");
 fprintf(stderr, "  -s : Specify number of spectral channels (2^n).\n");
 fprintf(stderr, "  -v : Specify PGPLOT window to display spectra. /xw -> X window, /gif -> GIF, /null -> no view.\n");
 return(0);
}


decompiled_code:
__int64 __fastcall valid_bit(char *s)
{
unsigned int v1; // er12

v1 = strchr(s, 48) != 0LL;
if ( strchr(s, 49) )
v1 |= 2u;
if ( strchr(s, 50) )
v1 |= 4u;
if ( strchr(s, 51) )
v1 |= 8u;
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *s)
{
unsigned int v1; // er12

v1 = strchr(s, 48) != 0LL;
if ( strchr(s, 49) )
v1 |= 2u;
if ( strchr(s, 50) )
v1 |= 4u;
if ( strchr(s, 51) )
v1 |= 8u;
return v1;
}

original_code:
int valid_bit( char *option ){
 int valid = 0;
 if(strstr( option, "0" ) != ((void *)0)) valid |= 0x01;
 if(strstr( option, "1" ) != ((void *)0)) valid |= 0x02;
 if(strstr( option, "2" ) != ((void *)0)) valid |= 0x04;
 if(strstr( option, "3" ) != ((void *)0)) valid |= 0x08;
 return(valid);
}

canonical_original_code:
int valid_bit(char *option){
 int valid = 0;
 if(strstr( option, "0" ) != ((void *)0)) valid |= 0x01;
 if(strstr( option, "1" ) != ((void *)0)) valid |= 0x02;
 if(strstr( option, "2" ) != ((void *)0)) valid |= 0x04;
 if(strstr( option, "3" ) != ((void *)0)) valid |= 0x08;
 return(valid);
}

variable_types:
option
char *

variable_types: valid int


decompiled_code:
__int64 __fastcall shm_access(key_t a1, size_t a2, int *a3, _DWORD *a4)
{
int v6; // eax
__int64 result; // rax

v6 = shmget(a1, a2, 292);
*a3 = v6;
if ( v6 < 0 )
{
puts("Can't Access to the Shared Memory !! ");
result = 0xFFFFFFFFLL;
}
else
{
*a4 = (unsigned int)shmat(v6, 0LL, 0);
result = (unsigned int)*a3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(key_t a1, size_t a2, int *a3, _DWORD *a4)
{
int v6; // eax
__int64 result; // rax

v6 = shmget(a1, a2, 292);
*a3 = v6;
if ( v6 < 0 )
{
puts("Can't Access to the Shared Memory !! ");
result = 0xFFFFFFFFLL;
}
else
{
*a4 = (unsigned int)shmat(v6, 0LL, 0);
result = (unsigned int)*a3;
}
return result;
}

original_code:
int shm_access(
 key_t shm_key,
 size_t shm_size,
 int *shrd_id,
 int *shm_ptr)
{
 *shrd_id = shmget(shm_key, shm_size, 0444);
 if( *shrd_id < 0 ){
  printf("Can't Access to the Shared Memory !! \n" );
  return(-1);
 }
 *shm_ptr = (int)shmat( *shrd_id, ((void *)0), 0);
 return( *shrd_id);
}

canonical_original_code:
int shm_access(int shm_key, unsigned long shm_size, int *shrd_id, int *shm_ptr)
{
 *shrd_id = shmget(shm_key, shm_size, 0444);
 if( *shrd_id < 0 ){
  printf("Can't Access to the Shared Memory !! \n" );
  return(-1);
 }
 *shm_ptr = (int)shmat( *shrd_id, ((void *)0), 0);
 return( *shrd_id);
}


isPattern

repo: kametang/FunctionCollection

decompiled_code:
__int64 __fastcall isPattern(char a1, _BYTE *a2)
{
while ( 1 )
{
if ( !*a2 )
return 1LL;
if ( a1 == *a2 )
break;
++a2;
}
return 2LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1, _BYTE *a2)
{
while ( 1 )
{
if ( !*a2 )
return 1LL;
if ( a1 == *a2 )
break;
++a2;
}
return 2LL;
}

original_code:
char isPattern(char c, char * pattern)
{
    char *p = pattern;
    while(*p){
        if(c == *p)
            return s_pattern;
        p++;
    }
    return s_node;
}

canonical_original_code:
char isPattern(char c, char *pattern)
{
    char *p = pattern;
    while(*p){
        if(c == *p)
            return s_pattern;
        p++;
    }
    return s_node;
}

variable_types:
pattern
char *

variable_types:
p
char *

return_type: char


split

original_code:
SplitStr split(char *buffer, char *pattern)
{
    SplitStr res;
    char *scan = buffer;
    int node = 0;
    int i = 0;
    int maxlen = 0;
    char status, condition;
    char c;
    while(*scan){
        status = isPattern(*scan++, pattern);
        if(status == s_pattern){
            maxlen = i > maxlen?i:maxlen;
            i = 0;
            continue;
        }
        if(!i)
            node++;
        i++;
    }
    maxlen = maxlen > i?maxlen:i;
    res.str = (char**)twoDA(node, maxlen, sizeof(char));
    res.count = node;
    res.len = maxlen;
    scan = buffer;
    node = 0;
    i = 0;
    status = 0;
    while(*scan){
        c = *scan++;
        condition = isPattern(c, pattern);
        if(status == s_node && condition == s_pattern){
            status = s_pattern;
            node++;
            i = 0;
        }
        else if(condition == s_node)
            status = s_node;
        if(condition == s_pattern)
            continue;
        res.str[node][i++] = c;
    }
    return res;
}

canonical_original_code:
struct SplitStr split(char *buffer, char *pattern)
{
    struct SplitStr res;
    char *scan = buffer;
    int node = 0;
    int i = 0;
    int maxlen = 0;
    char status; char condition;
    char c;
    while(*scan){
        status = isPattern(*scan++, pattern);
        if(status == s_pattern){
            maxlen = i > maxlen?i:maxlen;
            i = 0;
            continue;
        }
        if(!i)
            node++;
        i++;
    }
    maxlen = maxlen > i?maxlen:i;
    res.str = (char **)twoDA(node, maxlen, sizeof(char));
    res.count = node;
    res.len = maxlen;
    scan = buffer;
    node = 0;
    i = 0;
    status = 0;
    while(*scan){
        c = *scan++;
        condition = isPattern(c, pattern);
        if(status == s_node && condition == s_pattern){
            status = s_pattern;
            node++;
            i = 0;
        }
        else if(condition == s_node)
            status = s_node;
        if(condition == s_pattern)
            continue;
        res.str[node][i++] = c;
    }
    return res;
}

variable_types:
buffer
char *

variable_types: struct SplitStr { int count; int len; char **str; }

variable_types:
scan
char *

variable_types: node int

variable_types: maxlen int

variable_types: status char

variable_types: condition char


splitClean

decompiled_code:
void __fastcall splitClean(__int64 a1, void *a2)
{
free(a2);
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, void *a2)
{
free(a2);
}

original_code:
void splitClean(SplitStr n)
{
    free(n.str);
}

canonical_original_code:
void splitClean(struct SplitStr n)
{
    free(n.str);
}

user_defined_types: struct SplitStr { int count; int len; char **str; }


original_code:
int str2int(const char * buf)
{
    int num = 0;
    int i = 0;
    int scale = 1;
    if(buf[0] == '-'){
        scale = -1;
        i = 1;
    }
    for(; buf[i] != '\0'; i++)
    {
        num *= 10;
        num += (int)buf[i] - 48;
    }
    return num*scale;
}

canonical_original_code:
int str2int(char *buf)
{
    int num = 0;
    int i = 0;
    int scale = 1;
    if(buf[0] == '-'){
        scale = -1;
        i = 1;
    }
    for(; buf[i] != '\0'; i++)
    {
        num *= 10;
        num += (int)buf[i] - 48;
    }
    return num*scale;
}

variable_types:
buf
char *

variable_types: num int

variable_types: scale int


hasNum

decompiled_code:
__int64 __fastcall hasNum(void *src, __int64 a2, const char *a3)
{
size_t v4; // r13
void *v5; // rax
char *v6; // rax
char *v7; // rax
char *v8; // rdi

v4 = strlen((const char *)src) + 1;
v5 = malloc(v4);
v6 = (char *)memcpy(v5, src, v4);
v7 = strtok(v6, a3);
if ( !v7 )
return 0xFFFFFFFFLL;
v8 = v7;
while ( a2 != (int)str2int(v8) )
{
v8 = strtok(0LL, a3);
if ( !v8 )
return 0xFFFFFFFFLL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *src, __int64 a2, const char *a3)
{
size_t v4; // r13
void *v5; // rax
char *v6; // rax
char *v7; // rax
char *v8; // rdi

v4 = strlen((const char *)src) + 1;
v5 = malloc(v4);
v6 = (char *)memcpy(v5, src, v4);
v7 = strtok(v6, a3);
if ( !v7 )
return 0xFFFFFFFFLL;
v8 = v7;
while ( a2 != (int)func0(v8) )
{
v8 = strtok(0LL, a3);
if ( !v8 )
return 0xFFFFFFFFLL;
}
return 0LL;
}

original_code:
int hasNum(const char *buf, char * pattern, const char *splitPattern)
{
    char *tmp = (char *)malloc(strlen(buf) + 1*sizeof(char));
    char *p = ((void *)0);
    strcpy(tmp, buf);
    p = strtok(tmp, splitPattern);
    while(p != ((void *)0)){
        if(pattern == str2int(p))
            return 0;
        else
            p = strtok(((void *)0), splitPattern);
    }
    return -1;
}

canonical_original_code:
int hasNum(char *buf, char *pattern, char *splitPattern)
{
    char *tmp = (char *)malloc(strlen(buf) + 1*sizeof(char));
    char *p = ((void *)0);
    strcpy(tmp, buf);
    p = strtok(tmp, splitPattern);
    while(p != ((void *)0)){
        if(pattern == str2int(p))
            return 0;
        else
            p = strtok(((void *)0), splitPattern);
    }
    return -1;
}

variable_types:
splitPattern
char *

variable_types:
tmp
char *


hasLine

decompiled_code:
__int64 __fastcall hasLine(char *s, char *needle)
{
__int128 v4[9]; // [rsp+0h] [rbp-98h] BYREF

v4[0] = 0LL;
v4[1] = 0LL;
v4[2] = 0LL;
v4[3] = 0LL;
v4[4] = 0LL;
v4[5] = 0LL;
v4[6] = 0LL;
v4[7] = 0LL;
do
{
sscanf(s, "%[^\n]", v4);
s += strlen((const char *)v4) + 1;
}
while ( *s && !strstr((const char *)v4, needle) );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s, char *needle)
{
__int128 v4[9]; // [rsp+0h] [rbp-98h] BYREF

v4[0] = 0LL;
v4[1] = 0LL;
v4[2] = 0LL;
v4[3] = 0LL;
v4[4] = 0LL;
v4[5] = 0LL;
v4[6] = 0LL;
v4[7] = 0LL;
do
{
sscanf(s, "%[^\n]", v4);
s += strlen((const char *)v4) + 1;
}
while ( *s && !strstr((const char *)v4, needle) );
return 0LL;
}

original_code:
char * hasLine(const char * buf, const char * linePattern)
{
    char *tmp = buf;
    char *res = ((void *)0);
    char line[128] = {0};
    do
    {
        sscanf(tmp, "%[^\n]", line);
        tmp += strlen(line) + 1;
        if(tmp[0] == '\0')
            break;
        res = strstr(line, linePattern);
    } while (res == ((void *)0));
    return res;
}

canonical_original_code:
char *hasLine(char *buf, char *linePattern)
{
    char *tmp = buf;
    char *res = ((void *)0);
    char line[128] = {0};
    do
    {
        sscanf(tmp, "%[^\n]", line);
        tmp += strlen(line) + 1;
        if(tmp[0] == '\0')
            break;
        res = strstr(line, linePattern);
    } while (res == ((void *)0));
    return res;
}

variable_types:
linePattern
char *

variable_types:
res
char *

variable_types:
line
char [128]


decompiled_code:
char *__fastcall int2str(int a1)
{
int v1; // edx
int i; // eax
int v3; // ecx
__int64 v4; // rsi
__int64 v5; // rdi
int v6; // edx
int v7; // kr00_4
int v8; // eax
char *result; // rax

v1 = a1;
memset(cc, 0, sizeof(cc));
if ( a1 <= 1 )
{
if ( a1 != 1 )
{
result = cc;
cc[0] = 0;
return result;
}
v3 = 0;
}
else
{
for ( i = 1; i < a1; i *= 10 )
v3 = i;
}
v4 = 1LL;
do
{
v5 = (int)v4++;
v7 = v1;
v6 = v1 >> 31;
v8 = __SPAIR64__(v6, v7) / v3;
v1 = __SPAIR64__(v6, v7) % v3;
v3 /= 0xAu;
*(_BYTE *)(v4 + 158) = v8 + 48;
}
while ( v1 );
cc[v5] = 0;
return cc;
}

canonical_decompiled_code:
char *__fastcall func0(int a1)
{
int v1; // edx
int i; // eax
int v3; // ecx
__int64 v4; // rsi
__int64 v5; // rdi
int v6; // edx
int v7; // kr00_4
int v8; // eax
char *result; // rax

v1 = a1;
memset(cc, 0, sizeof(cc));
if ( a1 <= 1 )
{
if ( a1 != 1 )
{
result = cc;
cc[0] = 0;
return result;
}
v3 = 0;
}
else
{
for ( i = 1; i < a1; i *= 10 )
v3 = i;
}
v4 = 1LL;
do
{
v5 = (int)v4++;
v7 = v1;
v6 = v1 >> 31;
v8 = __SPAIR64__(v6, v7) / v3;
v1 = __SPAIR64__(v6, v7) % v3;
v3 /= 0xAu;
*(_BYTE *)(v4 + 158) = v8 + 48;
}
while ( v1 );
cc[v5] = 0;
return cc;
}

original_code:
char * int2str(int n)
{
 int scale = 1;
 int id = 0;
 memset(cc, 0, 256);
 while(scale < n) scale *= 10;
 scale /= 10;
 while(n > 0){
  cc[id++] = n/scale + '0';
  n %= scale;
  scale /= 10;
 }
 cc[id] = '\0';
 return cc;
}

canonical_original_code:
char *int2str(int n)
{
 int scale = 1;
 int id = 0;
 memset(cc, 0, 256);
 while(scale < n) scale *= 10;
 scale /= 10;
 while(n > 0){
  cc[id++] = n/scale + '0';
  n %= scale;
  scale /= 10;
 }
 cc[id] = '\0';
 return cc;
}

variable_types: n int

variable_types: id int


repo: kanemathers/odmetrics

decompiled_code:
__pid_t sigchild_handler()
{
__pid_t result; // eax

do
result = waitpid(-1, 0LL, 1);
while ( result > 0 );
return result;
}

canonical_decompiled_code:
__pid_t func0()
{
__pid_t result; // eax

do
result = waitpid(-1, 0LL, 1);
while ( result > 0 );
return result;
}

original_code:
static void sigchild_handler(int s)
{
    while (waitpid(-1, ((void *)0), 1) > 0);
}

variable_types: s int


decompiled_code:
__int64 __fastcall net_listen(const char *a1, const char *a2)
{
struct addrinfo *v2; // rbp
int v3; // eax
unsigned int v4; // er12
int v6; // edi
int optval; // [rsp+0h] [rbp-54h] BYREF
struct addrinfo *pai; // [rsp+4h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+Ch] [rbp-48h] BYREF

*(_OWORD *)&req.ai_flags = 0LL;
optval = 1;
req.ai_socktype = 1;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
if ( getaddrinfo(a1, a2, &req, &pai) )
return (unsigned int)-1;
v2 = pai;
if ( !pai )
{
LABEL_12:
freeaddrinfo(v2);
return 0xFFFFFFFFLL;
}
while ( 1 )
{
v3 = socket(v2->ai_family, v2->ai_socktype, v2->ai_protocol);
v4 = v3;
if ( v3 >= 0 )
break;
LABEL_10:
v2 = v2->ai_next;
if ( !v2 )
{
v2 = pai;
goto LABEL_12;
}
}
if ( setsockopt(v3, 1, 2, &optval, 4u) || bind(v4, v2->ai_addr, v2->ai_addrlen) )
{
close(v4);
goto LABEL_10;
}
freeaddrinfo(pai);
if ( listen(v4, 10) )
{
v6 = v4;
v4 = -1;
close(v6);
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, const char *a2)
{
struct addrinfo *v2; // rbp
int v3; // eax
unsigned int v4; // er12
int v6; // edi
int optval; // [rsp+0h] [rbp-54h] BYREF
struct addrinfo *pai; // [rsp+4h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+Ch] [rbp-48h] BYREF

*(_OWORD *)&req.ai_flags = 0LL;
optval = 1;
req.ai_socktype = 1;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
if ( getaddrinfo(a1, a2, &req, &pai) )
return (unsigned int)-1;
v2 = pai;
if ( !pai )
{
LABEL_12:
freeaddrinfo(v2);
return 0xFFFFFFFFLL;
}
while ( 1 )
{
v3 = socket(v2->ai_family, v2->ai_socktype, v2->ai_protocol);
v4 = v3;
if ( v3 >= 0 )
break;
LABEL_10:
v2 = v2->ai_next;
if ( !v2 )
{
v2 = pai;
goto LABEL_12;
}
}
if ( setsockopt(v3, 1, 2, &optval, 4u) || bind(v4, v2->ai_addr, v2->ai_addrlen) )
{
close(v4);
goto LABEL_10;
}
freeaddrinfo(pai);
if ( listen(v4, 10) )
{
v6 = v4;
v4 = -1;
close(v6);
}
return v4;
}

original_code:
static int net_listen(const char *hostname, const char *port)
{
    int yes = 1;
    int sockfd;
    struct addrinfo hints;
    struct addrinfo *info;
    struct addrinfo *p;
    memset(&hints, 0, sizeof hints);
    hints.ai_family = 0;
    hints.ai_socktype = SOCK_STREAM;
    if (getaddrinfo(hostname, port, &hints, &info) != 0)
        return -1;
    for (p = info; p != ((void *)0); p = p->ai_next)
    {
        sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol);
        if (sockfd < 0)
            continue;
        if (setsockopt(sockfd, 1, 2, &yes, sizeof yes) != 0)
        {
            close(sockfd);
            continue;
        }
        if (bind(sockfd, p->ai_addr, p->ai_addrlen) != 0)
        {
            close(sockfd);
            continue;
        }
        freeaddrinfo(info);
        if (listen(sockfd, 10) != 0)
        {
            close(sockfd);
            return -1;
        }
        return sockfd;
    }
    freeaddrinfo(info);
    return -1;
}

canonical_original_code:
static int net_listen(char *hostname, char *port)
{
    int yes = 1;
    int sockfd;
    struct addrinfo hints;
    struct addrinfo *info;
    struct addrinfo *p;
    memset(&hints, 0, sizeof hints);
    hints.ai_family = 0;
    hints.ai_socktype = SOCK_STREAM;
    if (getaddrinfo(hostname, port, &hints, &info) != 0)
        return -1;
    for (p = info; p != ((void *)0); p = p->ai_next)
    {
        sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol);
        if (sockfd < 0)
            continue;
        if (setsockopt(sockfd, 1, 2, &yes, sizeof yes) != 0)
        {
            close(sockfd);
            continue;
        }
        if (bind(sockfd, p->ai_addr, p->ai_addrlen) != 0)
        {
            close(sockfd);
            continue;
        }
        freeaddrinfo(info);
        if (listen(sockfd, 10) != 0)
        {
            close(sockfd);
            return -1;
        }
        return sockfd;
    }
    freeaddrinfo(info);
    return -1;
}

variable_types:
hostname
char *

variable_types:
port
char *

variable_types: yes int

variable_types: sockfd int

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


decompiled_code:
void *__fastcall start_server(void *a1)
{
__int64 v1; // r13
int v2; // er12
int v3; // ebp
char *v4; // r12
socklen_t addr_len; // [rsp+8h] [rbp-150h] BYREF
int v7; // [rsp+Ch] [rbp-14Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-148h] BYREF
struct sigaction v9; // [rsp+90h] [rbp-C8h] BYREF

v1 = *((_QWORD *)a1 + 2);
v2 = net_listen(*(const char **)a1, *((const char **)a1 + 1));
free(a1);
if ( v2 >= 0 )
{
v9.sa_handler = (__sighandler_t)sigchild_handler;
sigemptyset(&v9.sa_mask);
v9.sa_flags = 0x10000000;
if ( !sigaction(17, &v9, 0LL) )
{
while ( 1 )
{
addr_len = 128;
v3 = accept(v2, &addr, &addr_len);
if ( !fork() )
break;
close(v3);
}
close(v2);
v4 = (char *)odm_metrics_serialize(v1);
v7 = strlen(v4);
net_sendall_isra_0(v3, (__int64)v4, &v7);
free(v4);
close(v3);
exit(0);
}
}
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func3(void *a1)
{
__int64 v1; // r13
int v2; // er12
int v3; // ebp
char *v4; // r12
socklen_t addr_len; // [rsp+8h] [rbp-150h] BYREF
int v7; // [rsp+Ch] [rbp-14Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-148h] BYREF
struct sigaction v9; // [rsp+90h] [rbp-C8h] BYREF

v1 = *((_QWORD *)a1 + 2);
v2 = func1(*(const char **)a1, *((const char **)a1 + 1));
free(a1);
if ( v2 >= 0 )
{
v9.sa_handler = (__sighandler_t)sigchild_handler;
sigemptyset(&v9.sa_mask);
v9.sa_flags = 0x10000000;
if ( !sigaction(17, &v9, 0LL) )
{
while ( 1 )
{
addr_len = 128;
v3 = accept(v2, &addr, &addr_len);
if ( !fork() )
break;
close(v3);
}
close(v2);
v4 = (char *)odm_metrics_serialize(v1);
v7 = strlen(v4);
func2(v3, (__int64)v4, &v7);
free(v4);
close(v3);
exit(0);
}
}
return 0LL;
}

original_code:
static void *start_server(void *args)
{
    struct serverargs *serverargs = args;
    odm_t *odm = serverargs->odm;
    int sockfd;
    int new_fd;
    struct sockaddr_storage their_addr;
    socklen_t sin_size;
    struct sigaction sa;
    char *metrics;
    int metrics_len;
    sockfd = net_listen(serverargs->hostname, serverargs->port);
    free(serverargs);
    if (sockfd < 0)
        return ((void *)0);
    sa.__sigaction_handler.sa_handler = sigchild_handler;
    sigemptyset(&sa.sa_mask);
    sa.sa_flags = 0x10000000;
    if (sigaction(17, &sa, ((void *)0)) != 0)
        return ((void *)0);
    while (1)
    {
        sin_size = sizeof their_addr;
        new_fd = accept(sockfd, (struct sockaddr *) &their_addr, &sin_size);
        if (fork() == 0)
        {
            close(sockfd);
            metrics = odm_metrics_serialize(odm);
            metrics_len = strlen(metrics);
            net_sendall(new_fd, metrics, &metrics_len);
            free(metrics);
            close(new_fd);
            exit(0);
        }
        close(new_fd);
    }
    return ((void *)0);
}

canonical_original_code:
static void *start_server(void *args)
{
    struct serverargs *serverargs = args;
    struct odm *odm = serverargs->odm;
    int sockfd;
    int new_fd;
    struct sockaddr_storage their_addr;
    unsigned int sin_size;
    struct sigaction sa;
    char *metrics;
    int metrics_len;
    sockfd = net_listen(serverargs->hostname, serverargs->port);
    free(serverargs);
    if (sockfd < 0)
        return ((void *)0);
    sa.__sigaction_handler.sa_handler = sigchild_handler;
    sigemptyset(&sa.sa_mask);
    sa.sa_flags = 0x10000000;
    if (sigaction(17, &sa, ((void *)0)) != 0)
        return ((void *)0);
    while (1)
    {
        sin_size = sizeof their_addr;
        new_fd = accept(sockfd, (struct sockaddr *) &their_addr, &sin_size);
        if (fork() == 0)
        {
            close(sockfd);
            metrics = odm_metrics_serialize(odm);
            metrics_len = strlen(metrics);
            net_sendall(new_fd, metrics, &metrics_len);
            free(metrics);
            close(new_fd);
            exit(0);
        }
        close(new_fd);
    }
    return ((void *)0);
}

variable_types:
args
void *

variable_types: struct serverargs { char *hostname; char *port; struct odm { struct metric { char *key; int *value; struct UT_hash_handle { struct UT_hash_table { struct UT_hash_bucket { struct UT_hash_handle *hh_head; unsigned int count; unsigned int expand_mult; } *buckets; unsigned int num_buckets; unsigned int num_items; struct UT_hash_handle *tail; long hho; unsigned int ideal_chain_maxlen; unsigned int nonideal_items; unsigned int ineff_expands; unsigned int signature; } *tbl; void *prev; void *next; struct UT_hash_handle *hh_prev; struct UT_hash_handle *hh_next; void *key; unsigned int keylen; unsigned int hashv; } hh; } *metrics; unsigned long server; } *odm; } *

variable_types: struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; }

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

variable_types:
metrics
char *

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct serverargs { char *hostname; char *port; struct odm *odm; }

user_defined_types: struct odm { struct metric *metrics; unsigned long server; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }

user_defined_types: struct metric { char *key; int *value; struct UT_hash_handle hh; }

user_defined_types: struct UT_hash_handle { struct UT_hash_table *tbl; void *prev; void *next; struct UT_hash_handle *hh_prev; struct UT_hash_handle *hh_next; void *key; unsigned int keylen; unsigned int hashv; }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }

user_defined_types: struct UT_hash_table { struct UT_hash_bucket *buckets; unsigned int num_buckets; unsigned int num_items; struct UT_hash_handle *tail; long hho; unsigned int ideal_chain_maxlen; unsigned int nonideal_items; unsigned int ineff_expands; unsigned int signature; }


decompiled_code:
__int64 __fastcall odm_serve(__int64 a1, __int64 a2, __int64 a3)
{
_QWORD *v4; // rax

v4 = malloc(0x18uLL);
*v4 = a2;
v4[1] = a3;
v4[2] = a1;
pthread_create((pthread_t *)(a1 + 8), 0LL, start_server, v4);
pthread_detach(*(_QWORD *)(a1 + 8));
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, __int64 a3)
{
_QWORD *v4; // rax

v4 = malloc(0x18uLL);
*v4 = a2;
v4[1] = a3;
v4[2] = a1;
pthread_create((pthread_t *)(a1 + 8), 0LL, start_server, v4);
pthread_detach(*(_QWORD *)(a1 + 8));
return 0LL;
}

original_code:
int odm_serve(odm_t *odm, const char *hostname, const char *port)
{
    struct serverargs *serverargs = malloc(sizeof *serverargs);
    serverargs->hostname = hostname;
    serverargs->port = port;
    serverargs->odm = odm;
    pthread_create(&(odm->server), ((void *)0), start_server, serverargs);
    pthread_detach(odm->server);
    return 0;
}

canonical_original_code:
int odm_serve(struct odm *odm, char *hostname, char *port)
{
    struct serverargs *serverargs = malloc(sizeof *serverargs);
    serverargs->hostname = hostname;
    serverargs->port = port;
    serverargs->odm = odm;
    pthread_create(&(odm->server), ((void *)0), start_server, serverargs);
    pthread_detach(odm->server);
    return 0;
}

variable_types: struct odm { struct metric { char *key; int *value; struct UT_hash_handle { struct UT_hash_table { struct UT_hash_bucket { struct UT_hash_handle *hh_head; unsigned int count; unsigned int expand_mult; } *buckets; unsigned int num_buckets; unsigned int num_items; struct UT_hash_handle *tail; long hho; unsigned int ideal_chain_maxlen; unsigned int nonideal_items; unsigned int ineff_expands; unsigned int signature; } *tbl; void *prev; void *next; struct UT_hash_handle *hh_prev; struct UT_hash_handle *hh_next; void *key; unsigned int keylen; unsigned int hashv; } hh; } *metrics; unsigned long server; } *


decompiled_code:
__int64 __fastcall odm_init(_QWORD *a1)
{
*a1 = 0LL;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1)
{
*a1 = 0LL;
return 0LL;
}

original_code:
int odm_init(odm_t *odm)
{
    odm->metrics = ((void *)0);
    return 0;
}

canonical_original_code:
int odm_init(struct odm *odm)
{
    odm->metrics = ((void *)0);
    return 0;
}

user_defined_types: struct UT_hash_bucket { struct UT_hash_handle *hh_head; unsigned int count; unsigned int expand_mult; }