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

*(_DWORD *)(a1 + 12) = 1;
*(_DWORD *)(a1 + 4) = 1;
result = HT_PLAYER_UNINIT;
*(_WORD *)(a1 + 8) = HT_PLAYER_UNINIT;
*(_WORD *)a1 = HT_AIM_DEPTHMAX_UNINIT;
return result;
}

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

*(_DWORD *)(a1 + 12) = 1;
*(_DWORD *)(a1 + 4) = 1;
result = HT_PLAYER_UNINIT;
*(_WORD *)(a1 + 8) = HT_PLAYER_UNINIT;
*(_WORD *)a1 = HT_AIM_DEPTHMAX_UNINIT;
return result;
}

original_code:
void
ui_action_init (
 struct ui_action * const act
 )
{
 act->type = HT_UI_ACT_UNK;
 act->info.contr.type = HT_AIT_UNK;
 act->info.contr.p_index = HT_PLAYER_UNINIT;
 act->info.contr.args.minimax.depth_max = HT_AIM_DEPTHMAX_UNINIT;
}

canonical_original_code:
void ui_action_init(struct ui_action *act)
{
 act->type = HT_UI_ACT_UNK;
 act->info.contr.type = HT_AIT_UNK;
 act->info.contr.p_index = HT_PLAYER_UNINIT;
 act->info.contr.args.minimax.depth_max = HT_AIM_DEPTHMAX_UNINIT;
}

variable_types: struct ui_action { union { struct ui_action_contr { union { struct ai_minimax_args { unsigned short depth_max; } minimax; } args; enum AITYPE { HT_AIT_NONE=0, HT_AIT_UNK=1, HT_AIT_MINIMAX=2 } type; unsigned short p_index; } contr; struct move { unsigned short pos; } mov; } info; enum HT_UI_ACTT { HT_UI_ACT_NONE=0, HT_UI_ACT_UNK=1, HT_UI_ACT_SPECIAL=2, HT_UI_ACT_CONTR=3, HT_UI_ACT_MOVE=4, HT_UI_ACT_QUIT=5 } type; } *

user_defined_types: struct ui_action { union { struct ui_action_contr contr; struct move mov; } info; enum HT_UI_ACTT type; }

user_defined_types: struct ui_action_contr { union { struct ai_minimax_args minimax; } args; enum AITYPE type; unsigned short p_index; }


repo: adolg/worldots

decompiled_code:
__int64 ui_def()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func5()
{
return 1LL;
}

original_code:
enum HT_UIT
ui_def (void)
{
 return HT_UIT_MSQU;
}

canonical_original_code:
enum HT_UIT ui_def()
{
 return HT_UIT_MSQU;
}

return_type: enum HT_UIT { HT_UIT_NONE=0, HT_UIT_MSQU=1 }


IsQueueEmpty

decompiled_code:
_BOOL8 IsQueueEmpty()
{
return g_queue_size == 0;
}

canonical_decompiled_code:
_BOOL8 func0()
{
return g_queue_size == 0;
}

original_code: static int IsQueueEmpty() { return g_queue_size == 0; }

return_type: int


IsQueueFull

decompiled_code:
_BOOL8 IsQueueFull()
{
return g_queue_size == 16;
}

canonical_decompiled_code:
_BOOL8 func1()
{
return g_queue_size == 16;
}

original_code: static int IsQueueFull() { return g_queue_size == 16; }


InitializeMessageQueue

decompiled_code:
int InitializeMessageQueue()
{
pthread_mutex_init(&g_queue_mutex, 0LL);
return pthread_cond_init(&g_queue_not_empty_cond, 0LL);
}

canonical_decompiled_code:
int func2()
{
pthread_mutex_init(&g_queue_mutex, 0LL);
return pthread_cond_init(&g_queue_not_empty_cond, 0LL);
}

original_code:
void InitializeMessageQueue() {
  pthread_mutex_init(&g_queue_mutex, ((void *)0));
  pthread_cond_init(&g_queue_not_empty_cond, ((void *)0));
}

return_type: void


EnqueueMessage

decompiled_code:
__int64 __fastcall EnqueueMessage(void *ptr)
{
int v1; // eax
__int64 result; // rax

pthread_mutex_lock(&g_queue_mutex);
if ( IsQueueFull() )
{
pthread_mutex_unlock(&g_queue_mutex);
free(ptr);
result = 0LL;
}
else
{
v1 = g_queue_end;
g_queue[g_queue_end] = (__int64)ptr;
g_queue_end = (v1 + 1) % 16;
++g_queue_size;
pthread_cond_signal(&g_queue_not_empty_cond);
pthread_mutex_unlock(&g_queue_mutex);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *ptr)
{
int v1; // eax
__int64 result; // rax

pthread_mutex_lock(&g_queue_mutex);
if ( func1() )
{
pthread_mutex_unlock(&g_queue_mutex);
free(ptr);
result = 0LL;
}
else
{
v1 = g_queue_end;
g_queue[g_queue_end] = (__int64)ptr;
g_queue_end = (v1 + 1) % 16;
++g_queue_size;
pthread_cond_signal(&g_queue_not_empty_cond);
pthread_mutex_unlock(&g_queue_mutex);
result = 1LL;
}
return result;
}

original_code:
int EnqueueMessage(char* message) {
  pthread_mutex_lock(&g_queue_mutex);
  if (IsQueueFull()) {
    pthread_mutex_unlock(&g_queue_mutex);
    free(message);
    return 0;
  }
  g_queue[g_queue_end] = message;
  g_queue_end = (g_queue_end + 1) % 16;
  g_queue_size++;
  pthread_cond_signal(&g_queue_not_empty_cond);
  pthread_mutex_unlock(&g_queue_mutex);
  return 1;
}

canonical_original_code:
int EnqueueMessage(char *message) {
  pthread_mutex_lock(&g_queue_mutex);
  if (IsQueueFull()) {
    pthread_mutex_unlock(&g_queue_mutex);
    free(message);
    return 0;
  }
  g_queue[g_queue_end] = message;
  g_queue_end = (g_queue_end + 1) % 16;
  g_queue_size++;
  pthread_cond_signal(&g_queue_not_empty_cond);
  pthread_mutex_unlock(&g_queue_mutex);
  return 1;
}

variable_types:
message
char *


DequeueMessage

decompiled_code:
__int64 DequeueMessage()
{
__int64 v0; // rbx

pthread_mutex_lock(&g_queue_mutex);
while ( IsQueueEmpty() )
pthread_cond_wait(&g_queue_not_empty_cond, &g_queue_mutex);
v0 = g_queue[g_queue_start];
g_queue_start = (g_queue_start + 1) % 16;
--g_queue_size;
pthread_mutex_unlock(&g_queue_mutex);
return v0;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // rbx

pthread_mutex_lock(&g_queue_mutex);
while ( func0() )
pthread_cond_wait(&g_queue_not_empty_cond, &g_queue_mutex);
v0 = g_queue[g_queue_start];
g_queue_start = (g_queue_start + 1) % 16;
--g_queue_size;
pthread_mutex_unlock(&g_queue_mutex);
return v0;
}

original_code:
char* DequeueMessage() {
  char* message = ((void *)0);
  pthread_mutex_lock(&g_queue_mutex);
  while (IsQueueEmpty()) {
    pthread_cond_wait(&g_queue_not_empty_cond, &g_queue_mutex);
  }
  message = g_queue[g_queue_start];
  g_queue_start = (g_queue_start + 1) % 16;
  g_queue_size--;
  pthread_mutex_unlock(&g_queue_mutex);
  return message;
}

canonical_original_code:
char *DequeueMessage() {
  char *message = ((void *)0);
  pthread_mutex_lock(&g_queue_mutex);
  while (IsQueueEmpty()) {
    pthread_cond_wait(&g_queue_not_empty_cond, &g_queue_mutex);
  }
  message = g_queue[g_queue_start];
  g_queue_start = (g_queue_start + 1) % 16;
  g_queue_size--;
  pthread_mutex_unlock(&g_queue_mutex);
  return message;
}

return_type: char *


decompiled_code:
__int64 __fastcall aiminimax_depth_max_valid(unsigned __int16 a1)
{
return (HT_AIM_DEPTHMAX_MIN <= a1) & (unsigned __int8)(a1 <= 0x3E8u);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int16 a1)
{
return (HT_AIM_DEPTHMAX_MIN <= a1) & (unsigned __int8)(a1 <= 0x3E8u);
}

original_code:
HT_BOOL
aiminimax_depth_max_valid (
 const unsigned short depth_max
 )
{
 return depth_max >= HT_AIM_DEPTHMAX_MIN
 && depth_max <= (unsigned short)1000 ? HT_TRUE : HT_FALSE;
}

canonical_original_code:
enum HT_BOOL_ aiminimax_depth_max_valid(unsigned short depth_max)
{
 return depth_max >= HT_AIM_DEPTHMAX_MIN
 && depth_max <= (unsigned short)1000 ? HT_TRUE : HT_FALSE;
}

return_type: enum HT_BOOL_ { HT_FALSE=0, HT_TRUE=1 }


decompiled_code:
void __fastcall free_aiminimax(void *ptr)
{
void *v2; // rdi
int v3; // ebp
int v4; // ebp
__int64 v5; // rdi

v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
if ( *((_QWORD *)ptr + 5) )
{
if ( *((_WORD *)ptr + 1) != 0xFFFF )
{
v3 = 0;
do
free_board(*(_QWORD *)(*((_QWORD *)ptr + 5) + 8LL * (unsigned __int16)v3++));
while ( (unsigned __int16)(*((_WORD *)ptr + 1) + 1) > (unsigned __int16)v3 );
}
free(*((void **)ptr + 5));
}
if ( *((_QWORD *)ptr + 4) )
{
if ( *((_WORD *)ptr + 1) != 0xFFFF )
{
v4 = 0;
do
free_listm(*(_QWORD *)(*((_QWORD *)ptr + 4) + 8LL * (unsigned __int16)v4++));
while ( (unsigned __int16)(*((_WORD *)ptr + 1) + 1) > (unsigned __int16)v4 );
}
free(*((void **)ptr + 4));
}
v5 = *((_QWORD *)ptr + 2);
if ( v5 )
free_listm(v5);
if ( *((_QWORD *)ptr + 3) )
free_listmh();
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
void *v2; // rdi
int v3; // ebp
int v4; // ebp
__int64 v5; // rdi

v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
if ( *((_QWORD *)ptr + 5) )
{
if ( *((_WORD *)ptr + 1) != 0xFFFF )
{
v3 = 0;
do
free_board(*(_QWORD *)(*((_QWORD *)ptr + 5) + 8LL * (unsigned __int16)v3++));
while ( (unsigned __int16)(*((_WORD *)ptr + 1) + 1) > (unsigned __int16)v3 );
}
free(*((void **)ptr + 5));
}
if ( *((_QWORD *)ptr + 4) )
{
if ( *((_WORD *)ptr + 1) != 0xFFFF )
{
v4 = 0;
do
free_listm(*(_QWORD *)(*((_QWORD *)ptr + 4) + 8LL * (unsigned __int16)v4++));
while ( (unsigned __int16)(*((_WORD *)ptr + 1) + 1) > (unsigned __int16)v4 );
}
free(*((void **)ptr + 4));
}
v5 = *((_QWORD *)ptr + 2);
if ( v5 )
free_listm(v5);
if ( *((_QWORD *)ptr + 3) )
free_listmh();
free(ptr);
}

original_code:
void
free_aiminimax (
 struct aiminimax * const aim
 )
{
 if (((void *)0) != aim->board_escval)
 {
  free (aim->board_escval);
 }
 if (((void *)0) != aim->opt_buf_board)
 {
  unsigned short i;
  for (i = (unsigned short)0;
  i < (unsigned short)(aim->depth_max + 1); i++)
  {
   free_board (aim->opt_buf_board[i]);
  }
  free (aim->opt_buf_board);
 }
 if (((void *)0) != aim->opt_buf_moves)
 {
  unsigned short i;
  for (i = (unsigned short)0;
  i < (unsigned short)(aim->depth_max + 1); i++)
  {
   free_listm (aim->opt_buf_moves[i]);
  }
  free (aim->opt_buf_moves);
 }
 if (((void *)0) != aim->opt_moves)
 {
  free_listm (aim->opt_moves);
 }
 if (((void *)0) != aim->opt_movehist)
 {
  free_listmh (aim->opt_movehist);
 }
 free(aim);
}

canonical_original_code:
void free_aiminimax(struct aiminimax *aim)
{
 if (((void *)0) != aim->board_escval)
 {
  free (aim->board_escval);
 }
 if (((void *)0) != aim->opt_buf_board)
 {
  unsigned short i;
  for (i = (unsigned short)0;
  i < (unsigned short)(aim->depth_max + 1); i++)
  {
   free_board (aim->opt_buf_board[i]);
  }
  free (aim->opt_buf_board);
 }
 if (((void *)0) != aim->opt_buf_moves)
 {
  unsigned short i;
  for (i = (unsigned short)0;
  i < (unsigned short)(aim->depth_max + 1); i++)
  {
   free_listm (aim->opt_buf_moves[i]);
  }
  free (aim->opt_buf_moves);
 }
 if (((void *)0) != aim->opt_moves)
 {
  free_listm (aim->opt_moves);
 }
 if (((void *)0) != aim->opt_movehist)
 {
  free_listmh (aim->opt_movehist);
 }
 free(aim);
}

variable_types: struct aiminimax { unsigned short p_index; unsigned short depth_max; int *board_escval; struct listm { struct move { unsigned short pos; } *elems; unsigned long elemc; unsigned long capc; } *opt_moves; struct listmh { struct moveh { enum HT_BOOL_ { HT_FALSE=0, HT_TRUE=1 } irrev; unsigned short pos; } *elems; unsigned long elemc; unsigned long capc; } *opt_movehist; struct listm **opt_buf_moves; struct board { unsigned char *pieces; unsigned short turn; } **opt_buf_board; unsigned short opt_buf_len; } *

variable_types:
i
unsigned short

user_defined_types: struct aiminimax { unsigned short p_index; unsigned short depth_max; int *board_escval; struct listm *opt_moves; struct listmh *opt_movehist; struct listm **opt_buf_moves; struct board **opt_buf_board; unsigned short opt_buf_len; }

user_defined_types: struct listm { struct move *elems; unsigned long elemc; unsigned long capc; }

user_defined_types: struct listmh { struct moveh *elems; unsigned long elemc; unsigned long capc; }

user_defined_types: struct moveh { enum HT_BOOL_ irrev; unsigned short pos; }


startStdinThread

decompiled_code:
void startStdinThread()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void startStdinThread() {
}

canonical_original_code:
void startStdinThread() {
}


decompiled_code:
__int64 __fastcall listmh_grow(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rax
unsigned __int64 v3; // rbp
void *v4; // rax

v2 = *(_QWORD *)(a1 + 16);
v3 = v2 + 1;
if ( v2 < a2 )
v3 = a2;
v4 = realloc(*(void **)a1, 8 * v3);
if ( !v4 )
return 3LL;
*(_QWORD *)a1 = v4;
*(_QWORD *)(a1 + 16) = v3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rax
unsigned __int64 v3; // rbp
void *v4; // rax

v2 = *(_QWORD *)(a1 + 16);
v3 = v2 + 1;
if ( v2 < a2 )
v3 = a2;
v4 = realloc(*(void **)a1, 8 * v3);
if ( !v4 )
return 3LL;
*(_QWORD *)a1 = v4;
*(_QWORD *)(a1 + 16) = v3;
return 0LL;
}

original_code:
static
enum HT_FR
listmh_grow (
 struct listmh * const l,
 size_t capc_new
 )
{
 struct moveh * elems_new = ((void *)0);
 if (capc_new <= l->capc)
 {
  capc_new = l->capc + 1;
 }
 elems_new = realloc(l->elems, sizeof(* l->elems) * capc_new);
 if (((void *)0) == elems_new)
 {
  return HT_FR_FAIL_ALLOC;
 }
 l->elems = elems_new;
 l->capc = capc_new;
 return HT_FR_SUCCESS;
}

canonical_original_code:
static enum HT_FR listmh_grow(struct listmh *l, unsigned long capc_new)
{
 struct moveh *elems_new = ((void *)0);
 if (capc_new <= l->capc)
 {
  capc_new = l->capc + 1;
 }
 elems_new = realloc(l->elems, sizeof(* l->elems) * capc_new);
 if (((void *)0) == elems_new)
 {
  return HT_FR_FAIL_ALLOC;
 }
 l->elems = elems_new;
 l->capc = capc_new;
 return HT_FR_SUCCESS;
}

variable_types: struct listmh { struct moveh { enum HT_BOOL_ { HT_FALSE=0, HT_TRUE=1 } irrev; unsigned short pos; } *elems; unsigned long elemc; unsigned long capc; } *

return_type: enum HT_FR { HT_FR_NONE=-1, HT_FR_SUCCESS=0, HT_FR_FAIL_NULLPTR=1, HT_FR_FAIL_ARROB=2, HT_FR_FAIL_ALLOC=3, HT_FR_FAIL_ENUM_UNK=4, HT_FR_FAIL_ILL_ARG=5, HT_FR_FAIL_ILL_STATE=6, HT_FR_FAIL_IO_ENV_UNDEF=7, HT_FR_FAIL_IO_FILE_R=8, HT_FR_FAIL_IO_PRINT=9, HT_FR_FAIL_POSIX=10, HT_FR_FAIL_IO=11, HT_FR_FAIL_INVOC=12, HT_FR_FAIL_RREADER=13, HT_FR_FAIL_UI_NONE=14, HT_FR_FAIL_UIMQ_API=15 }


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

v2 = *(void **)ptr;
if ( v2 )
free(v2);
free(ptr);
}

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

v2 = *(void **)ptr;
if ( v2 )
free(v2);
free(ptr);
}

original_code:
void
free_listmh (
 struct listmh * const l
 )
{
 if (((void *)0) != l->elems)
 {
  free (l->elems);
 }
 free (l);
}

canonical_original_code:
void free_listmh(struct listmh *l)
{
 if (((void *)0) != l->elems)
 {
  free (l->elems);
 }
 free (l);
}


original_code:
enum HT_FR
listmh_add (
 struct listmh * const l,
 const unsigned short pos,
 const unsigned short dest,
 const HT_BOOL irrev
 )
{
 if (((void *)0) == l->elems)
 {
  return HT_FR_FAIL_NULLPTR;
 }
 if (l->elemc + 1 > l->capc)
 {
  const enum HT_FR fr = listmh_grow(l, (size_t)
   ((float)l->capc * HT_LISTMH_MEMC_GROWF));
  if (HT_FR_SUCCESS != fr)
  {
   return fr;
  }
 }
 l->elems[l->elemc].irrev = irrev;
 l->elems[l->elemc].pos = pos;
 l->elems[l->elemc].dest = dest;
 l->elemc++;
 return HT_FR_SUCCESS;
}

canonical_original_code:
enum HT_FR listmh_add(struct listmh *l, unsigned short pos, unsigned short dest, enum HT_BOOL_ irrev)
{
 if (((void *)0) == l->elems)
 {
  return HT_FR_FAIL_NULLPTR;
 }
 if (l->elemc + 1 > l->capc)
 {
  enum HT_FR fr = listmh_grow(l, (size_t)
   ((float)l->capc * HT_LISTMH_MEMC_GROWF));
  if (HT_FR_SUCCESS != fr)
  {
   return fr;
  }
 }
 l->elems[l->elemc].irrev = irrev;
 l->elems[l->elemc].pos = pos;
 l->elems[l->elemc].dest = dest;
 l->elemc++;
 return HT_FR_SUCCESS;
}

variable_types:
pos
unsigned short

variable_types:
dest
unsigned short

variable_types:
irrev
enum HT_BOOL_ { HT_FALSE=0, HT_TRUE=1 }

variable_types: enum HT_FR { HT_FR_NONE=-1, HT_FR_SUCCESS=0, HT_FR_FAIL_NULLPTR=1, HT_FR_FAIL_ARROB=2, HT_FR_FAIL_ALLOC=3, HT_FR_FAIL_ENUM_UNK=4, HT_FR_FAIL_ILL_ARG=5, HT_FR_FAIL_ILL_STATE=6, HT_FR_FAIL_IO_ENV_UNDEF=7, HT_FR_FAIL_IO_FILE_R=8, HT_FR_FAIL_IO_PRINT=9, HT_FR_FAIL_POSIX=10, HT_FR_FAIL_IO=11, HT_FR_FAIL_INVOC=12, HT_FR_FAIL_RREADER=13, HT_FR_FAIL_UI_NONE=14, HT_FR_FAIL_UIMQ_API=15 }


original_code:
enum HT_FR
listmh_copy (
 const struct listmh * const src,
  struct listmh * const dest
 )
{
 size_t i;
 if (src->elemc > dest->capc)
 {
  const enum HT_FR fr = listmh_grow(dest, src->elemc);
  if (HT_FR_SUCCESS != fr)
  {
   return fr;
  }
 }
 dest->elemc = src->elemc;
 for (i = (size_t)0; i < src->elemc; i++)
 {
  dest->elems[i].pos = src->elems[i].pos;
  dest->elems[i].dest = src->elems[i].dest;
  dest->elems[i].irrev = src->elems[i].irrev;
 }
 return HT_FR_SUCCESS;
}

canonical_original_code:
enum HT_FR listmh_copy(struct listmh *src, struct listmh *dest)
{
 unsigned long i;
 if (src->elemc > dest->capc)
 {
  enum HT_FR fr = listmh_grow(dest, src->elemc);
  if (HT_FR_SUCCESS != fr)
  {
   return fr;
  }
 }
 dest->elemc = src->elemc;
 for (i = (unsigned long)0; i < src->elemc; i++)
 {
  dest->elems[i].pos = src->elems[i].pos;
  dest->elems[i].dest = src->elems[i].dest;
  dest->elems[i].irrev = src->elems[i].irrev;
 }
 return HT_FR_SUCCESS;
}

variable_types:
dest
struct listmh *

variable_types:
i
unsigned long

user_defined_types: enum HT_FR { HT_FR_NONE=-1, HT_FR_SUCCESS=0, HT_FR_FAIL_NULLPTR=1, HT_FR_FAIL_ARROB=2, HT_FR_FAIL_ALLOC=3, HT_FR_FAIL_ENUM_UNK=4, HT_FR_FAIL_ILL_ARG=5, HT_FR_FAIL_ILL_STATE=6, HT_FR_FAIL_IO_ENV_UNDEF=7, HT_FR_FAIL_IO_FILE_R=8, HT_FR_FAIL_IO_PRINT=9, HT_FR_FAIL_POSIX=10, HT_FR_FAIL_IO=11, HT_FR_FAIL_INVOC=12, HT_FR_FAIL_RREADER=13, HT_FR_FAIL_UI_NONE=14, HT_FR_FAIL_UIMQ_API=15 }


decompiled_code:
_BOOL8 __fastcall type_square_can_capture(__int64 a1, unsigned __int8 a2)
{
return (*(_BYTE *)(a1 + 1) & a2) == a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(__int64 a1, unsigned __int8 a2)
{
return (*(_BYTE *)(a1 + 1) & a2) == a2;
}

original_code:
HT_BOOL
type_square_can_capture (
 const struct type_square * const ts,
 const HT_BIT_U8 pbit
 )
{
 return ((unsigned int)pbit & (unsigned int)ts->captures)
  == (unsigned int)pbit;
}

canonical_original_code:
enum HT_BOOL_ type_square_can_capture(struct type_square *ts, unsigned char pbit)
{
 return ((unsigned int)pbit & (unsigned int)ts->captures)
  == (unsigned int)pbit;
}

variable_types: struct type_square { unsigned char bit; unsigned char captures; unsigned short capt_sides; enum HT_BOOL_ { HT_FALSE=0, HT_TRUE=1 } escape; } *

variable_types:
pbit
unsigned char

user_defined_types: struct type_square { unsigned char bit; unsigned char captures; unsigned short capt_sides; enum HT_BOOL_ escape; }


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

result = HT_BIT_U8_EMPTY;
*(_BYTE *)a1 = HT_BIT_U8_EMPTY;
*(_BYTE *)(a1 + 1) = result;
*(_WORD *)(a1 + 2) = HT_TSQUARE_CAPT_SIDES_NONE;
*(_DWORD *)(a1 + 4) = 0;
return result;
}

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

result = HT_BIT_U8_EMPTY;
*(_BYTE *)a1 = HT_BIT_U8_EMPTY;
*(_BYTE *)(a1 + 1) = result;
*(_WORD *)(a1 + 2) = HT_TSQUARE_CAPT_SIDES_NONE;
*(_DWORD *)(a1 + 4) = 0;
return result;
}

original_code:
void
type_square_init (
 struct type_square * const ts
 )
{
 ts->bit = HT_BIT_U8_EMPTY;
 ts->captures = HT_BIT_U8_EMPTY;
 ts->capt_sides = HT_TSQUARE_CAPT_SIDES_NONE;
 ts->escape = HT_FALSE;
}

canonical_original_code:
void type_square_init(struct type_square *ts)
{
 ts->bit = HT_BIT_U8_EMPTY;
 ts->captures = HT_BIT_U8_EMPTY;
 ts->capt_sides = HT_TSQUARE_CAPT_SIDES_NONE;
 ts->escape = HT_FALSE;
}


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

if ( a1 > 0x20u )
{
result = 6LL;
if ( a1 != 64 )
result = (unsigned int)(a1 != 0x80) + 7;
}
else
{
result = 8LL;
if ( a1 )
{
switch ( a1 )
{
case 1u:
result = 0LL;
break;
case 2u:
result = 1LL;
break;
case 4u:
result = 2LL;
break;
case 8u:
result = 3LL;
break;
case 0x10u:
result = 4LL;
break;
case 0x20u:
result = 5LL;
break;
default:
result = 8LL;
break;
}
}
}
return result;
}

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

if ( a1 > 0x20u )
{
result = 6LL;
if ( a1 != 64 )
result = (unsigned int)(a1 != 0x80) + 7;
}
else
{
result = 8LL;
if ( a1 )
{
switch ( a1 )
{
case 1u:
result = 0LL;
break;
case 2u:
result = 1LL;
break;
case 4u:
result = 2LL;
break;
case 8u:
result = 3LL;
break;
case 0x10u:
result = 4LL;
break;
case 0x20u:
result = 5LL;
break;
default:
result = 8LL;
break;
}
}
}
return result;
}

original_code:
unsigned short
type_index_get (
 const HT_BIT_U8 bit
 )
{
 switch (bit)
 {
  case 1:
   return (unsigned short)0;
  case 2:
   return (unsigned short)1;
  case 4:
   return (unsigned short)2;
  case 8:
   return (unsigned short)3;
  case 16:
   return (unsigned short)4;
  case 32:
   return (unsigned short)5;
  case 64:
   return (unsigned short)6;
  case 128:
   return (unsigned short)7;
  default:
   return (unsigned short)8;
 }
}

canonical_original_code:
unsigned short type_index_get(unsigned char bit)
{
 switch (bit)
 {
  case 1:
   return (unsigned short)0;
  case 2:
   return (unsigned short)1;
  case 4:
   return (unsigned short)2;
  case 8:
   return (unsigned short)3;
  case 16:
   return (unsigned short)4;
  case 32:
   return (unsigned short)5;
  case 64:
   return (unsigned short)6;
  case 128:
   return (unsigned short)7;
  default:
   return (unsigned short)8;
 }
}

variable_types:
bit
unsigned char

return_type: unsigned short


decompiled_code:
_BOOL8 __fastcall valid_size(__int16 a1)
{
return (unsigned __int16)(a1 - 1) <= 0x1Eu;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(__int16 a1)
{
return (unsigned __int16)(a1 - 1) <= 0x1Eu;
}

original_code:
HT_BOOL
valid_size (
 const unsigned short w_or_h
 )
{
 return w_or_h >= SIZE_BOARD_MIN && w_or_h <= SIZE_BOARD_MAX;
}

canonical_original_code:
enum HT_BOOL_ valid_size(unsigned short w_or_h)
{
 return w_or_h >= SIZE_BOARD_MIN && w_or_h <= SIZE_BOARD_MAX;
}


repo: adovzh/dna-search

decompiled_code:
int __fastcall print_current_time(time_t *timer)
{
char v2[80]; // [rsp+0h] [rbp-98h] BYREF
struct tm tp; // [rsp+50h] [rbp-48h] BYREF

gettimeofday((struct timeval *)timer, 0LL);
localtime_r(timer, &tp);
strftime(v2, 0x4EuLL, "%b%e %H:%M:%S", &tp);
return printf("%s.%03d", v2, timer[1] / 1000);
}

canonical_decompiled_code:
int __fastcall func0(time_t *timer)
{
char v2[80]; // [rsp+0h] [rbp-98h] BYREF
struct tm tp; // [rsp+50h] [rbp-48h] BYREF

gettimeofday((struct timeval *)timer, 0LL);
localtime_r(timer, &tp);
strftime(v2, 0x4EuLL, "%b%e %H:%M:%S", &tp);
return printf("%s.%03d", v2, timer[1] / 1000);
}

original_code:
void print_current_time(struct timeval *tv) {
 struct tm time_tm;
 char formatted[78];
 gettimeofday(tv, ((void *)0));
 localtime_r(&tv->tv_sec, &time_tm);
 strftime(formatted, sizeof formatted, "%b%e %H:%M:%S", &time_tm);
 printf("%s.%03d", formatted, (int)(tv->tv_usec / 1000));
}

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

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; }

variable_types:
formatted
char [78]


decompiled_code:
int __fastcall print_elapsed_time(__int64 a1, _QWORD *a2)
{
unsigned int v2; // er8
__int64 v3; // rdx
unsigned int v4; // eax

v2 = *a2 - *(_DWORD *)a1;
v3 = (a2[1] - *(_QWORD *)(a1 + 8)) / 1000LL;
v4 = v3;
if ( (int)v3 < 0 )
{
--v2;
v4 = v3 + 1000;
}
return printf("Elapsed: %d.%03d\n", v2, v4);
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, _QWORD *a2)
{
unsigned int v2; // er8
__int64 v3; // rdx
unsigned int v4; // eax

v2 = *a2 - *(_DWORD *)a1;
v3 = (a2[1] - *(_QWORD *)(a1 + 8)) / 1000LL;
v4 = v3;
if ( (int)v3 < 0 )
{
--v2;
v4 = v3 + 1000;
}
return printf("Elapsed: %d.%03d\n", v2, v4);
}

original_code:
void print_elapsed_time(struct timeval *start_time, struct timeval *end_time) {
 int seconds = end_time->tv_sec - start_time->tv_sec;
 int millis = (end_time->tv_usec - start_time->tv_usec) / 1000;
 if (millis < 0) {
  seconds--;
  millis += 1000;
 }
 printf("Elapsed: %d.%03d\n", seconds, millis);
}

variable_types: seconds int

variable_types: millis int

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


decompiled_code:
__int64 __fastcall calc_elapsed_time(_QWORD *a1, _QWORD *a2)
{
return a2[1] + 1000000LL * (*a2 - *a1) - a1[1];
}

original_code:
long calc_elapsed_time(struct timeval *start_time, struct timeval *end_time) {
 return (end_time->tv_sec - start_time->tv_sec) * 1000000 + end_time->tv_usec - start_time->tv_usec;
}

return_type: long


decompiled_code:
int __fastcall found_handler(unsigned int a1)
{
time_t v2[3]; // [rsp+0h] [rbp-18h] BYREF

print_current_time(v2);
return printf(" FOUND SEQUENCE STARTING AT %u\n", a1);
}

canonical_decompiled_code:
int __fastcall func3(unsigned int a1)
{
time_t v2[3]; // [rsp+0h] [rbp-18h] BYREF

func0(v2);
return printf(" FOUND SEQUENCE STARTING AT %u\n", a1);
}

original_code:
void found_handler(bufindex_t pos) {
 struct timeval tv;
 print_current_time(&tv);
 printf(" FOUND SEQUENCE STARTING AT %u\n", pos);
}

canonical_original_code:
void found_handler(unsigned int pos) {
 struct timeval tv;
 print_current_time(&tv);
 printf(" FOUND SEQUENCE STARTING AT %u\n", pos);
}

variable_types:
pos
unsigned int

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


decompiled_code:
int __fastcall submit_job(__int64 a1)
{
int v1; // eax
int result; // eax

pthread_mutex_lock(&queue_lock);
v1 = tail++;
job_queue[v1] = a1;
pthread_cond_broadcast(&read_cond);
result = pthread_mutex_unlock(&queue_lock);
++jobs_posted;
return result;
}

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

pthread_mutex_lock(&queue_lock);
v1 = tail++;
job_queue[v1] = a1;
pthread_cond_broadcast(&read_cond);
result = pthread_mutex_unlock(&queue_lock);
++jobs_posted;
return result;
}

original_code:
void submit_job(job_t *buf) {
 pthread_mutex_lock(&queue_lock);
 job_queue[tail++] = buf;
 pthread_cond_broadcast(&read_cond);
 pthread_mutex_unlock(&queue_lock);
 jobs_posted++;
}

canonical_original_code:
void submit_job(struct _job_t *buf) {
 pthread_mutex_lock(&queue_lock);
 job_queue[tail++] = buf;
 pthread_cond_broadcast(&read_cond);
 pthread_mutex_unlock(&queue_lock);
 jobs_posted++;
}

variable_types: struct _job_t { char *buf; unsigned int len; unsigned int offset; } *


decompiled_code:
__int64 request_job()
{
int i; // eax
__int64 v1; // rbx

pthread_mutex_lock(&queue_lock);
for ( i = head; head == tail; i = head )
pthread_cond_wait(&read_cond, &queue_lock);
head = i + 1;
v1 = job_queue[i];
pthread_mutex_unlock(&queue_lock);
return v1;
}

canonical_decompiled_code:
__int64 func1()
{
int i; // eax
__int64 v1; // rbx

pthread_mutex_lock(&queue_lock);
for ( i = head; head == tail; i = head )
pthread_cond_wait(&read_cond, &queue_lock);
head = i + 1;
v1 = job_queue[i];
pthread_mutex_unlock(&queue_lock);
return v1;
}

original_code:
job_t *request_job() {
 pthread_mutex_lock(&queue_lock);
 while (head == tail)
  pthread_cond_wait(&read_cond, &queue_lock);
 job_t *job = job_queue[head++];
 pthread_mutex_unlock(&queue_lock);
 return job;
}

canonical_original_code:
struct _job_t *request_job() {
 pthread_mutex_lock(&queue_lock);
 while (head == tail)
  pthread_cond_wait(&read_cond, &queue_lock);
 struct _job_t *job = job_queue[head++];
 pthread_mutex_unlock(&queue_lock);
 return job;
}

return_type: struct _job_t { char *buf; unsigned int len; unsigned int offset; } *


decompiled_code:
int complete_job()
{
pthread_mutex_lock(&jobs_completed_lock);
++jobs_completed;
pthread_cond_broadcast(&jobs_completed_cond);
return pthread_mutex_unlock(&jobs_completed_lock);
}

canonical_decompiled_code:
int func2()
{
pthread_mutex_lock(&jobs_completed_lock);
++jobs_completed;
pthread_cond_broadcast(&jobs_completed_cond);
return pthread_mutex_unlock(&jobs_completed_lock);
}

original_code:
void complete_job() {
 pthread_mutex_lock(&jobs_completed_lock);
 jobs_completed++;
 pthread_cond_broadcast(&jobs_completed_cond);
 pthread_mutex_unlock(&jobs_completed_lock);
}


decompiled_code:
int wait_jobs_completed()
{
int v0; // eax
unsigned int v1; // ebx
char *v2; // rax
struct timespec v4; // [rsp+0h] [rbp-28h] BYREF
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

gettimeofday(&tv, 0LL);
v4.tv_sec = tv.tv_sec + 90;
v4.tv_nsec = 0LL;
pthread_mutex_lock(&jobs_completed_lock);
while ( jobs_posted > jobs_completed )
{
v0 = pthread_cond_timedwait(&jobs_completed_cond, &jobs_completed_lock, &v4);
v1 = v0;
if ( v0 )
{
v2 = strerror(v0);
printf("Timed wait: %d, %s\n", v1, v2);
return pthread_mutex_unlock(&jobs_completed_lock);
}
}
return pthread_mutex_unlock(&jobs_completed_lock);
}

canonical_decompiled_code:
int func3()
{
int v0; // eax
unsigned int v1; // ebx
char *v2; // rax
struct timespec v4; // [rsp+0h] [rbp-28h] BYREF
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

gettimeofday(&tv, 0LL);
v4.tv_sec = tv.tv_sec + 90;
v4.tv_nsec = 0LL;
pthread_mutex_lock(&jobs_completed_lock);
while ( jobs_posted > jobs_completed )
{
v0 = pthread_cond_timedwait(&jobs_completed_cond, &jobs_completed_lock, &v4);
v1 = v0;
if ( v0 )
{
v2 = strerror(v0);
printf("Timed wait: %d, %s\n", v1, v2);
return pthread_mutex_unlock(&jobs_completed_lock);
}
}
return pthread_mutex_unlock(&jobs_completed_lock);
}

original_code:
void wait_jobs_completed() {
 int errorno = 0;
 struct timeval tv;
 struct timespec timeout;
 gettimeofday(&tv, ((void *)0));
 timeout.tv_sec = tv.tv_sec + 90;
    timeout.tv_nsec = 0;
 pthread_mutex_lock(&jobs_completed_lock);
 while (!errorno && jobs_posted > jobs_completed)
  errorno = pthread_cond_timedwait(&jobs_completed_cond, &jobs_completed_lock, &timeout);
 if (errorno){
  printf("Timed wait: %d, %s\n", errorno, strerror(errorno));
 }
 pthread_mutex_unlock(&jobs_completed_lock);
}

variable_types: errorno int

variable_types: struct timespec { long tv_sec; long tv_nsec; }


decompiled_code:
void __fastcall __noreturn handle_job(void *a1)
{
unsigned int *v1; // rbx

while ( 1 )
{
v1 = (unsigned int *)request_job(a1);
search(*(_QWORD *)v1, 0LL, v1[2], v1[3], &found_handler);
a1 = v1;
free(v1);
complete_job();
}
}

canonical_decompiled_code:
void __fastcall __noreturn func0(void *a1)
{
unsigned int *v1; // rbx

while ( 1 )
{
v1 = (unsigned int *)request_job(a1);
search(*(_QWORD *)v1, 0LL, v1[2], v1[3], &found_handler);
a1 = v1;
free(v1);
complete_job();
}
}

original_code:
void *handle_job(void *arg) {
 while (1) {
  job_t *job = request_job();
  search(job->buf, 0, job->len, job->offset, found_handler);
  free(job);
  complete_job();
 }
}

canonical_original_code:
void *handle_job(void *arg) {
 while (1) {
  struct _job_t *job = request_job();
  search(job->buf, 0, job->len, job->offset, found_handler);
  free(job);
  complete_job();
 }
}

variable_types:
arg
void *

return_type: void *

user_defined_types: struct _job_t { char *buf; unsigned int len; unsigned int offset; }


decompiled_code:
int init_threads()
{
pthread_t *v0; // rbx
int result; // eax

pthread_mutex_init(&queue_lock, 0LL);
pthread_cond_init(&read_cond, 0LL);
pthread_mutex_init(&jobs_completed_lock, 0LL);
pthread_cond_init(&jobs_completed_cond, 0LL);
v0 = &threads;
do
result = pthread_create(v0++, 0LL, (void *(*)(void *))handle_job, 0LL);
while ( v0 != (pthread_t *)&unk_188 );
return result;
}

canonical_decompiled_code:
int func1()
{
pthread_t *v0; // rbx
int result; // eax

pthread_mutex_init(&queue_lock, 0LL);
pthread_cond_init(&read_cond, 0LL);
pthread_mutex_init(&jobs_completed_lock, 0LL);
pthread_cond_init(&jobs_completed_cond, 0LL);
v0 = &threads;
do
result = pthread_create(v0++, 0LL, (void *(*)(void *))handle_job, 0LL);
while ( v0 != (pthread_t *)&unk_188 );
return result;
}

original_code:
void init_threads() {
 int i;
 pthread_t *p = threads;
 pthread_mutex_init(&queue_lock, ((void *)0));
 pthread_cond_init(&read_cond, ((void *)0));
 pthread_mutex_init(&jobs_completed_lock, ((void *)0));
 pthread_cond_init(&jobs_completed_cond, ((void *)0));
 for (i = 0; i < 17; i++, p++)
  pthread_create(p, ((void *)0), handle_job, ((void *)0));
}

canonical_original_code:
void init_threads() {
 int i;
 unsigned long *p = threads;
 pthread_mutex_init(&queue_lock, ((void *)0));
 pthread_cond_init(&read_cond, ((void *)0));
 pthread_mutex_init(&jobs_completed_lock, ((void *)0));
 pthread_cond_init(&jobs_completed_cond, ((void *)0));
 for (i = 0; i < 17; i++, p++)
  pthread_create(p, ((void *)0), handle_job, ((void *)0));
}

variable_types: i int

variable_types:
p
unsigned long *


decompiled_code:
int destroy_threads()
{
pthread_t *v0; // rbx

v0 = &threads;
do
pthread_cancel(*v0++);
while ( v0 != (pthread_t *)&unk_188 );
pthread_cond_destroy(&jobs_completed_cond);
pthread_mutex_destroy(&jobs_completed_lock);
pthread_cond_destroy(&read_cond);
return pthread_mutex_destroy(&queue_lock);
}

canonical_decompiled_code:
int func2()
{
pthread_t *v0; // rbx

v0 = &threads;
do
pthread_cancel(*v0++);
while ( v0 != (pthread_t *)&unk_188 );
pthread_cond_destroy(&jobs_completed_cond);
pthread_mutex_destroy(&jobs_completed_lock);
pthread_cond_destroy(&read_cond);
return pthread_mutex_destroy(&queue_lock);
}

original_code:
void destroy_threads() {
 int i;
 pthread_t *p = threads;
 for (i = 0; i < 17; i++, p++)
  pthread_cancel(*p);
 pthread_cond_destroy(&jobs_completed_cond);
 pthread_mutex_destroy(&jobs_completed_lock);
 pthread_cond_destroy(&read_cond);
 pthread_mutex_destroy(&queue_lock);
}

canonical_original_code:
void destroy_threads() {
 int i;
 unsigned long *p = threads;
 for (i = 0; i < 17; i++, p++)
  pthread_cancel(*p);
 pthread_cond_destroy(&jobs_completed_cond);
 pthread_mutex_destroy(&jobs_completed_lock);
 pthread_cond_destroy(&read_cond);
 pthread_mutex_destroy(&queue_lock);
}


decompiled_code:
size_t __fastcall init_needle(const char *a1)
{
size_t result; // rax

needle = (__int64)a1;
result = strlen(a1);
needle_len = result;
return result;
}

canonical_decompiled_code:
size_t __fastcall func0(const char *a1)
{
size_t result; // rax

needle = (__int64)a1;
result = strlen(a1);
needle_len = result;
return result;
}

original_code:
void init_needle(char *s) {
 needle = s;
 needle_len = strlen(s);
}

variable_types:
s
char *


decompiled_code:
void __fastcall brute_force(__int64 a1, unsigned int a2, int a3, unsigned int a4, void (__fastcall *a5)(_QWORD))
{
char *v5; // rbp
unsigned int v6; // ebx
int v8; // er12

v5 = (char *)(a1 + a2);
if ( a3 )
{
v6 = a4;
v8 = a3 + a4;
do
{
if ( !memcmp(v5, needle, needle_len) )
a5(v6);
++v5;
++v6;
}
while ( v6 != v8 );
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, unsigned int a2, int a3, unsigned int a4, void (__fastcall *a5)(_QWORD))
{
char *v5; // rbp
unsigned int v6; // ebx
int v8; // er12

v5 = (char *)(a1 + a2);
if ( a3 )
{
v6 = a4;
v8 = a3 + a4;
do
{
if ( !memcmp(v5, needle, needle_len) )
a5(v6);
++v5;
++v6;
}
while ( v6 != v8 );
}
}

original_code:
void brute_force(char *buffer, bufindex_t start, buflen_t len, bufindex_t offset, P_LISTENER listener) {
 char *p;
 buflen_t countdown = len;
 for (p = buffer + start; countdown; p++, countdown--)
  if (!memcmp(p, needle, needle_len))
   listener(len - countdown + offset);
}

canonical_original_code:
void brute_force(char *buffer, unsigned int start, unsigned int len, unsigned int offset, void (*listener)(unsigned int)) {
 char *p;
 unsigned int countdown = len;
 for (p = buffer + start; countdown; p++, countdown--)
  if (!memcmp(p, needle, needle_len))
   listener(len - countdown + offset);
}

variable_types:
buffer
char *

variable_types:
start
unsigned int

variable_types:
len
unsigned int

variable_types:
offset
unsigned int

variable_types:
listener
void (*)(unsigned int)

variable_types:
p
char *

variable_types:
countdown
unsigned int


repo: adrian-bl/bbjobs

decompiled_code:
void __fastcall pr_lhand(void *src)
{
size_t v1; // rax
char v2[40]; // [rsp+0h] [rbp-28h] BYREF

if ( src )
{
strcpy(v2, " ");
v1 = strlen((const char *)src);
memcpy(v2, src, v1);
if ( pr_pmode )
printf("%llu ", pr_pfx);
printf(" %s : ", v2);
}
}

canonical_decompiled_code:
void __fastcall func0(void *src)
{
size_t v1; // rax
char v2[40]; // [rsp+0h] [rbp-28h] BYREF

if ( src )
{
strcpy(v2, " ");
v1 = strlen((const char *)src);
memcpy(v2, src, v1);
if ( pr_pmode )
printf("%llu ", pr_pfx);
printf(" %s : ", v2);
}
}

original_code:
void pr_lhand(char *lhand) {
 char xbuff[20];
 if(lhand != ((void *)0)) {
  memset(xbuff, ' ', 20);
  xbuff[20 -1] = '\0';
  memcpy(xbuff, lhand, strlen(lhand));
  if(_pr_pmode) printf("%llu ", _pr_pfx);
  printf("  %s : ", xbuff);
 }
}

variable_types:
lhand
char *

variable_types:
xbuff
char [20]


decompiled_code:
int __fastcall pr_duration(void *a1, __int64 a2)
{
pr_lhand(a1);
if ( a2 <= 300 || pr_pmode )
{
printf("%d sec", (unsigned int)a2);
}
else if ( a2 > 3600 )
{
printf("%d h %d min", (unsigned int)((int)a2 / 3600), (unsigned int)((int)a2 / 60 % 60));
}
else
{
printf("%d min", (unsigned int)((int)a2 / 60));
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func1(void *a1, __int64 a2)
{
func0(a1);
if ( a2 <= 300 || pr_pmode )
{
printf("%d sec", (unsigned int)a2);
}
else if ( a2 > 3600 )
{
printf("%d h %d min", (unsigned int)((int)a2 / 3600), (unsigned int)((int)a2 / 60 % 60));
}
else
{
printf("%d min", (unsigned int)((int)a2 / 60));
}
return putchar(10);
}

original_code:
void pr_duration(char *lhand, time_t sec) {
 pr_lhand(lhand);
 if(sec <= 300 || _pr_pmode) {
  printf("%d sec", (int)sec);
 }
 else if(sec <= 60*60) {
  printf("%d min", (int)sec/60);
 }
 else {
  printf("%d h %d min", (int)sec/60/60, (int)sec/60%60);
 }
 printf("\n");
}

canonical_original_code:
void pr_duration(char *lhand, long sec) {
 pr_lhand(lhand);
 if(sec <= 300 || _pr_pmode) {
  printf("%d sec", (int)sec);
 }
 else if(sec <= 60*60) {
  printf("%d min", (int)sec/60);
 }
 else {
  printf("%d h %d min", (int)sec/60/60, (int)sec/60%60);
 }
 printf("\n");
}

variable_types: sec long


decompiled_code:
int __fastcall pr_int(void *a1, unsigned int a2)
{
pr_lhand(a1);
return printf("%d\n", a2);
}

canonical_decompiled_code:
int __fastcall func2(void *a1, unsigned int a2)
{
func0(a1);
return printf("%d\n", a2);
}

original_code:
void pr_int(char *lhand, int value) {
 pr_lhand(lhand);
 printf("%d\n", value);
}

variable_types: value int


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

v2 = a2;
pr_lhand(a1);
if ( !*a2 )
v2 = "-";
return puts(v2);
}

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

v2 = a2;
func0(a1);
if ( !*a2 )
v2 = "-";
return puts(v2);
}

original_code:
void pr_str(char *lhand, char *str) {
 pr_lhand(lhand);
 printf("%s\n", ( strlen(str) == 0 ? "-" : str ) );
}

variable_types:
str
char *


decompiled_code:
int __fastcall pr_ts(void *a1, time_t a2)
{
struct tm *v2; // rax
time_t timer; // [rsp+8h] [rbp-80h] BYREF
char s[120]; // [rsp+10h] [rbp-78h] BYREF

timer = a2;
v2 = localtime(&timer);
strftime(s, 0x64uLL, "%R %F", v2);
return pr_str(a1, s);
}

canonical_decompiled_code:
int __fastcall func4(void *a1, time_t a2)
{
struct tm *v2; // rax
time_t timer; // [rsp+8h] [rbp-80h] BYREF
char s[120]; // [rsp+10h] [rbp-78h] BYREF

timer = a2;
v2 = localtime(&timer);
strftime(s, 0x64uLL, "%R %F", v2);
return func3(a1, s);
}

original_code:
void pr_ts(char *lhand, time_t ts) {
 char dst[100];
 struct tm *tmp;
 tmp = localtime(&ts);
 strftime(dst, sizeof(dst), "%R %F", tmp);
 pr_str(lhand, dst);
}

canonical_original_code:
void pr_ts(char *lhand, long ts) {
 char dst[100];
 struct tm *tmp;
 tmp = localtime(&ts);
 strftime(dst, sizeof(dst), "%R %F", tmp);
 pr_str(lhand, dst);
}

variable_types: ts long

variable_types:
dst
char [100]

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *


decompiled_code:
int __fastcall pr_stn(void *a1, const char *a2, signed int a3)
{
const char *v3; // rbx
size_t v4; // rbp
char *v6; // rax
char v7[6]; // [rsp+0h] [rbp-8Eh] BYREF
char v8[136]; // [rsp+6h] [rbp-88h] BYREF

v3 = a2;
if ( (unsigned int)a3 > 0x64 )
{
snprintf(v8, 0x64uLL, "%s", a2);
v4 = 100LL;
}
else
{
v4 = a3;
snprintf(v8, a3, "%s", a2);
if ( v4 <= 5 )
goto LABEL_3;
}
if ( strlen(a2) > v4 )
{
v6 = &v7[v4];
*(_DWORD *)v6 = 774778459;
v6[4] = 93;
}
LABEL_3:
if ( !pr_pmode )
v3 = v8;
return pr_str(a1, v3);
}

canonical_decompiled_code:
int __fastcall func5(void *a1, const char *a2, signed int a3)
{
const char *v3; // rbx
size_t v4; // rbp
char *v6; // rax
char v7[6]; // [rsp+0h] [rbp-8Eh] BYREF
char v8[136]; // [rsp+6h] [rbp-88h] BYREF

v3 = a2;
if ( (unsigned int)a3 > 0x64 )
{
snprintf(v8, 0x64uLL, "%s", a2);
v4 = 100LL;
}
else
{
v4 = a3;
snprintf(v8, a3, "%s", a2);
if ( v4 <= 5 )
goto LABEL_3;
}
if ( strlen(a2) > v4 )
{
v6 = &v7[v4];
*(_DWORD *)v6 = 774778459;
v6[4] = 93;
}
LABEL_3:
if ( !pr_pmode )
v3 = v8;
return func3(a1, v3);
}

original_code:
void pr_stn(char *lhand, char *str, int limit) {
 char dst[100];
 if(limit > sizeof(dst))
  limit = sizeof(dst);
 snprintf(dst, limit, "%s", str);
 if(limit > strlen("[...]") && strlen(str) > limit) {
  memcpy(&dst[limit-1-strlen("[...]")], "[...]", strlen("[...]"));
 }
 pr_str(lhand, (_pr_pmode ? str : dst ) );
}

variable_types: limit int


decompiled_code:
int __fastcall pr_prct(void *a1, double a2)
{
pr_lhand(a1);
return printf("%.1f %%\n", a2);
}

canonical_decompiled_code:
int __fastcall func6(void *a1, double a2)
{
func0(a1);
return printf("%.1f %%\n", a2);
}

original_code:
void pr_prct(char *lhand, double num) {
 pr_lhand(lhand);
 printf("%.1f %%\n", num);
}

variable_types: num double


decompiled_code:
int __fastcall pr_fancy(char *s)
{
int v1; // eax
int result; // eax

v1 = fileno(stdout);
if ( isatty(v1) )
result = printf("\x1B[1;32m%s\x1B[0m\n", s);
else
result = puts(s);
return result;
}

canonical_decompiled_code:
int __fastcall func7(char *s)
{
int v1; // eax
int result; // eax

v1 = fileno(stdout);
if ( isatty(v1) )
result = printf("\x1B[1;32m%s\x1B[0m\n", s);
else
result = puts(s);
return result;
}

original_code:
void pr_fancy(char *lhand) {
 if(isatty(fileno(stdout))) {
  printf("\x1b[1;32m%s\x1b[0m\n",lhand);
 }
 else {
  printf("%s\n", lhand);
 }
}


decompiled_code:
void __fastcall pr_set_output_parseable(int a1)
{
pr_pmode = a1;
}

canonical_decompiled_code:
void __fastcall func8(int a1)
{
pr_pmode = a1;
}

original_code:
void pr_set_output_parseable(int x) {
 _pr_pmode = x;
}

variable_types: x int


decompiled_code:
void __fastcall pr_set_prefix(__int64 a1)
{
pr_pfx = a1;
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1)
{
pr_pfx = a1;
}

original_code:
void pr_set_prefix(long long unsigned jid) {
 _pr_pfx = jid;
}

canonical_original_code:
void pr_set_prefix(unsigned long long jid) {
 _pr_pfx = jid;
}

variable_types:
jid
unsigned long long


repo: adsgray/CServer

decompiled_code:
__int64 __fastcall get_rq_type(char *s1)
{
int v1; // edx
__int64 result; // rax
int v3; // edx
int v4; // edx

v1 = strncasecmp(s1, "GET", 3uLL);
result = 1LL;
if ( v1 )
{
v3 = strncasecmp(s1, "POST", 4uLL);
result = 2LL;
if ( v3 )
{
v4 = strncasecmp(s1, "HEAD", 4uLL);
result = 0LL;
if ( v4 )
result = 3 - ((unsigned int)(strncasecmp(s1, "PUT", 3uLL) == 0) - 1);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s1)
{
int v1; // edx
__int64 result; // rax
int v3; // edx
int v4; // edx

v1 = strncasecmp(s1, "GET", 3uLL);
result = 1LL;
if ( v1 )
{
v3 = strncasecmp(s1, "POST", 4uLL);
result = 2LL;
if ( v3 )
{
v4 = strncasecmp(s1, "HEAD", 4uLL);
result = 0LL;
if ( v4 )
result = 3 - ((unsigned int)(strncasecmp(s1, "PUT", 3uLL) == 0) - 1);
}
}
return result;
}

original_code:
static RQ_TYPE get_rq_type(char *raw)
{
 if (!strncasecmp(raw, "GET", strlen("GET"))) return GET;
 if (!strncasecmp(raw, "POST", strlen("POST"))) return POST;
 if (!strncasecmp(raw, "HEAD", strlen("HEAD"))) return HEAD;
 if (!strncasecmp(raw, "PUT", strlen("PUT"))) return PUT;
 return RQ_UNKNOWN;
}

canonical_original_code:
static enum RQ_TYPE get_rq_type(char *raw)
{
 if (!strncasecmp(raw, "GET", strlen("GET"))) return GET;
 if (!strncasecmp(raw, "POST", strlen("POST"))) return POST;
 if (!strncasecmp(raw, "HEAD", strlen("HEAD"))) return HEAD;
 if (!strncasecmp(raw, "PUT", strlen("PUT"))) return PUT;
 return RQ_UNKNOWN;
}

variable_types:
raw
char *

return_type: enum RQ_TYPE { HEAD=0, GET=1, POST=2, PUT=3, RQ_UNKNOWN=4 }


decompiled_code:
char *__fastcall get_path(const char *a1)
{
char *v1; // rax
char *v2; // rbx
const char *v3; // r12
char *v4; // rax
int v5; // ebp

v1 = strchr(a1, 32);
v2 = v1;
if ( v1 )
{
v3 = v1 + 1;
v4 = strchr(v1 + 1, 32);
v2 = v4;
if ( v4 )
{
v5 = (_DWORD)v4 - 1 - (_DWORD)v3;
v2 = (char *)ag_malloc(v5 + 2);
strncpy(v2, v3, v5 + 1);
}
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func1(const char *a1)
{
char *v1; // rax
char *v2; // rbx
const char *v3; // r12
char *v4; // rax
int v5; // ebp

v1 = strchr(a1, 32);
v2 = v1;
if ( v1 )
{
v3 = v1 + 1;
v4 = strchr(v1 + 1, 32);
v2 = v4;
if ( v4 )
{
v5 = (_DWORD)v4 - 1 - (_DWORD)v3;
v2 = (char *)ag_malloc(v5 + 2);
strncpy(v2, v3, v5 + 1);
}
}
return v2;
}

original_code:
static char *get_path(char *raw)
{
 char *start_path;
 char *end_path;
 char *rval;
 int plength;
 start_path = strstr(raw, " ");;
 if (!start_path) return ((void *)0);
 start_path++;
 end_path = strstr(start_path, " ");
 if (!end_path) return ((void *)0);
 end_path--;
 plength = end_path - start_path + 1;
 rval = ag_malloc(plength + 1);
 strncpy(rval, start_path, plength);
 return rval;
}

variable_types:
rval
char *

variable_types: plength int


decompiled_code:
char *__fastcall get_prot(const char *a1)
{
char *v1; // rax
char *v2; // rbx
char *v3; // rax
const char *v4; // r12
char *v5; // rax
int v6; // ebp

v1 = strchr(a1, 32);
v2 = v1;
if ( v1 )
{
v3 = strchr(v1 + 1, 32);
v2 = v3;
if ( v3 )
{
v4 = v3 + 1;
v5 = strstr(v3 + 1, "\r\n");
v2 = v5;
if ( v5 )
{
v6 = (_DWORD)v5 - 1 - (_DWORD)v4;
v2 = (char *)ag_malloc(v6 + 2);
strncpy(v2, v4, v6 + 1);
}
}
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func2(const char *a1)
{
char *v1; // rax
char *v2; // rbx
char *v3; // rax
const char *v4; // r12
char *v5; // rax
int v6; // ebp

v1 = strchr(a1, 32);
v2 = v1;
if ( v1 )
{
v3 = strchr(v1 + 1, 32);
v2 = v3;
if ( v3 )
{
v4 = v3 + 1;
v5 = strstr(v3 + 1, "\r\n");
v2 = v5;
if ( v5 )
{
v6 = (_DWORD)v5 - 1 - (_DWORD)v4;
v2 = (char *)ag_malloc(v6 + 2);
strncpy(v2, v4, v6 + 1);
}
}
}
return v2;
}

original_code:
static char *get_prot(char *raw)
{
 char *start_prot;
 char *end_prot;
 char *rval;
 int plength;
 start_prot = strstr(raw, " ");
 if (!start_prot) return ((void *)0);
 start_prot++;
 start_prot = strstr(start_prot, " ");
 if (!start_prot) return ((void *)0);
 start_prot++;
 end_prot = strstr(start_prot, "\r\n");
 if (!end_prot) return ((void *)0);
 end_prot--;
 plength = end_prot - start_prot + 1;
 rval = ag_malloc(plength + 1);
 strncpy(rval, start_prot, plength);
 return rval;
}


decompiled_code:
__int64 __fastcall destroy_request(void *ptr)
{
void *v2; // rdi
void *v3; // rdi
void *v4; // rdi
void **v5; // rbx

v2 = (void *)*((_QWORD *)ptr + 11);
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 12);
if ( v3 )
free(v3);
v4 = (void *)*((_QWORD *)ptr + 13);
if ( v4 )
free(v4);
v5 = (void **)((char *)ptr + 8);
do
{
if ( *v5 )
free(*v5);
++v5;
}
while ( v5 != (void **)((char *)ptr + 88) );
free(ptr);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *ptr)
{
void *v2; // rdi
void *v3; // rdi
void *v4; // rdi
void **v5; // rbx

v2 = (void *)*((_QWORD *)ptr + 11);
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 12);
if ( v3 )
free(v3);
v4 = (void *)*((_QWORD *)ptr + 13);
if ( v4 )
free(v4);
v5 = (void **)((char *)ptr + 8);
do
{
if ( *v5 )
free(*v5);
++v5;
}
while ( v5 != (void **)((char *)ptr + 88) );
free(ptr);
return 1LL;
}

original_code:
int destroy_request(void *arg)
{
 request_t rq = arg;
 int i;
 if (rq->prot) free(rq->prot);
 if (rq->path) free(rq->path);
 if (rq->body) free(rq->body);
 for (i = 0; i < H_MAX; i++) {
  if (rq->headers[i]) free(rq->headers[i]);
 }
 free(rq);
 rq = ((void *)0);
 return 1;
}

canonical_original_code:
int destroy_request(void *arg)
{
 struct _http_request *rq = arg;
 int i;
 if (rq->prot) free(rq->prot);
 if (rq->path) free(rq->path);
 if (rq->body) free(rq->body);
 for (i = 0; i < H_MAX; i++) {
  if (rq->headers[i]) free(rq->headers[i]);
 }
 free(rq);
 rq = ((void *)0);
 return 1;
}

variable_types:
arg
void *

variable_types: struct _http_request { enum RQ_TYPE { HEAD=0, GET=1, POST=2, PUT=3, RQ_UNKNOWN=4 } rtype; char *headers[-1]; char *prot; char *path; char *body; char *content_type; char *raw; int (*destroy)(void *); } *

variable_types: i int

user_defined_types: struct _http_request { enum RQ_TYPE rtype; char *headers[-1]; char *prot; char *path; char *body; char *content_type; char *raw; int (*destroy)(void *); }


decompiled_code:
char *__fastcall str_toupper(const char *a1)
{
char *v1; // rbp
size_t i; // rbx
const unsigned __int16 **v3; // rax
__int64 v4; // r12

v1 = strdup(a1);
for ( i = 0LL; strlen(v1) > i; ++i )
{
v3 = _ctype_b_loc();
v4 = v1[i];
if ( ((*v3)[v4] & 0x200) != 0 )
v1[i] = (*_ctype_toupper_loc())[v4];
}
return v1;
}

canonical_decompiled_code:
char *__fastcall func4(const char *a1)
{
char *v1; // rbp
size_t i; // rbx
const unsigned __int16 **v3; // rax
__int64 v4; // r12

v1 = strdup(a1);
for ( i = 0LL; strlen(v1) > i; ++i )
{
v3 = _ctype_b_loc();
v4 = v1[i];
if ( ((*v3)[v4] & 0x200) != 0 )
v1[i] = (*_ctype_toupper_loc())[v4];
}
return v1;
}

original_code:
static char *str_toupper(char *fr)
{
 char *rval;
 int i;
 rval = strdup(fr);
 for (i = 0; i < strlen(rval); i++) {
  if (((*__ctype_b_loc ())[(int) ((rval[i]))] & (unsigned short int) _ISlower))
   rval[i] = toupper(rval[i]);
 }
 return rval;
}

canonical_original_code:
static char *str_toupper(char *fr)
{
 char *rval;
 int i;
 rval = strdup(fr);
 for (i = 0; i < strlen(rval); i++) {
  if (((*__ctype_b_loc ())[(int) ((rval[i]))] & (unsigned short) _ISlower))
   rval[i] = toupper(rval[i]);
 }
 return rval;
}

variable_types:
fr
char *


decompiled_code:
const char *__fastcall get_content_type(const char *a1)
{
char *v1; // rbx
const char *v2; // rbp

v1 = str_toupper(a1);
v2 = "image/gif";
if ( !strstr(v1, ".GIF") )
{
v2 = "image/jpeg";
if ( !strstr(v1, ".JPEG") && !strstr(v1, ".JPG") )
{
v2 = "image/png";
if ( !strstr(v1, ".PNG") )
{
v2 = "image/x-xbitmap";
if ( !strstr(v1, ".BMP") )
{
v2 = "text/plain";
if ( !strstr(v1, ".TXT") )
v2 = "text/html";
}
}
}
}
free(v1);
return v2;
}

canonical_decompiled_code:
const char *__fastcall func5(const char *a1)
{
char *v1; // rbx
const char *v2; // rbp

v1 = func4(a1);
v2 = "image/gif";
if ( !strstr(v1, ".GIF") )
{
v2 = "image/jpeg";
if ( !strstr(v1, ".JPEG") && !strstr(v1, ".JPG") )
{
v2 = "image/png";
if ( !strstr(v1, ".PNG") )
{
v2 = "image/x-xbitmap";
if ( !strstr(v1, ".BMP") )
{
v2 = "text/plain";
if ( !strstr(v1, ".TXT") )
v2 = "text/html";
}
}
}
}
free(v1);
return v2;
}

original_code:
static char *get_content_type(char *path)
{
 char *up_path;
 char *rval;
 up_path = str_toupper(path);
 if (strstr(up_path,".GIF")) rval = CT_IMGGIF;
 else if (strstr(up_path,".JPEG") ||
   strstr(up_path,".JPG")) rval = CT_IMGJPEG;
 else if (strstr(up_path,".PNG")) rval = CT_IMGPNG;
 else if (strstr(up_path,".BMP")) rval = CT_IMGBMP;
 else if (strstr(up_path,".TXT")) rval = CT_TEXTPLAIN;
 else rval = CT_TEXTHTML;
 free(up_path);
 return rval;
}

variable_types:
path
char *


decompiled_code:
char *__fastcall get_headers(__int64 a1, const char *a2)
{
char *v2; // r15
const char *v3; // r13
const char *v4; // rbp
char *v5; // rbx
char *result; // rax
__int64 v7; // rbx
int v8; // er14
const char *v9; // r12
size_t v10; // rbp

v2 = strstr(a2, "\r\n\r\n");
v3 = a2 + 2;
LABEL_3:
while ( 1 )
{
result = strstr(v3, "\r\n");
if ( !result || v2 == result )
return result;
v3 = result + 2;
v7 = 0LL;
while ( 1 )
{
v8 = v7;
v9 = header_names[v7];
v10 = strlen(v9);
if ( !strncmp(v3, v9, v10) )
break;
if ( ++v7 == 10 )
goto LABEL_3;
}
v4 = &v3[v10];
v5 = strstr(v4, "\r\n");
*v5 = 0;
*(_QWORD *)(a1 + 8LL * v8 + 8) = strdup(v4);
*v5 = 13;
}
}

canonical_decompiled_code:
char *__fastcall func6(__int64 a1, const char *a2)
{
char *v2; // r15
const char *v3; // r13
const char *v4; // rbp
char *v5; // rbx
char *result; // rax
__int64 v7; // rbx
int v8; // er14
const char *v9; // r12
size_t v10; // rbp

v2 = strstr(a2, "\r\n\r\n");
v3 = a2 + 2;
LABEL_3:
while ( 1 )
{
result = strstr(v3, "\r\n");
if ( !result || v2 == result )
return result;
v3 = result + 2;
v7 = 0LL;
while ( 1 )
{
v8 = v7;
v9 = header_names[v7];
v10 = strlen(v9);
if ( !strncmp(v3, v9, v10) )
break;
if ( ++v7 == 10 )
goto LABEL_3;
}
v4 = &v3[v10];
v5 = strstr(v4, "\r\n");
*v5 = 0;
*(_QWORD *)(a1 + 8LL * v8 + 8) = strdup(v4);
*v5 = 13;
}
}

original_code:
static void get_headers(request_t rq, char *raw) {
 int i;
 char *pos = raw;
 char *end_headers;
 end_headers = strstr(raw, "\r\n\r\n");
 pos += 2;
 for (;;) {
  pos = strstr(pos, "\r\n");
  if (!pos || pos == end_headers) return;
  pos += 2;
  for (i = 0; i < H_MAX; i++) {
   if (!strncmp(pos,
    header_names[i],
    strlen(header_names[i])))
   {
    char *tmp1, *tmp2;
    tmp1 = pos + strlen(header_names[i]);
    tmp2 = strstr(tmp1,"\r\n");
    *tmp2 = '\0';
    rq->headers[i] = strdup(tmp1);
    *tmp2 = '\r';
    break;
   }
  }
 }
}

canonical_original_code:
static void get_headers(struct _http_request *rq, char *raw) {
 int i;
 char *pos = raw;
 char *end_headers;
 end_headers = strstr(raw, "\r\n\r\n");
 pos += 2;
 for (;;) {
  pos = strstr(pos, "\r\n");
  if (!pos || pos == end_headers) return;
  pos += 2;
  for (i = 0; i < H_MAX; i++) {
   if (!strncmp(pos,
    header_names[i],
    strlen(header_names[i])))
   {
    char *tmp1; char *tmp2;
    tmp1 = pos + strlen(header_names[i]);
    tmp2 = strstr(tmp1,"\r\n");
    *tmp2 = '\0';
    rq->headers[i] = strdup(tmp1);
    *tmp2 = '\r';
    break;
   }
  }
 }
}

variable_types:
pos
char *

user_defined_types: enum RQ_TYPE { HEAD=0, GET=1, POST=2, PUT=3, RQ_UNKNOWN=4 }


decompiled_code:
__int64 __fastcall new_request(char *haystack, __int64 a2)
{
__int64 v2; // rbx
int v3; // eax
int v4; // er12
char *v5; // rax
char *v6; // rax

v2 = a2;
v3 = get_rq_type(haystack);
if ( v3 == 4 )
return 0LL;
v4 = v3;
if ( !a2 )
v2 = ag_malloc(136LL);
*(_QWORD *)(v2 + 128) = destroy_request;
*(_DWORD *)v2 = v4;
v5 = get_path(haystack);
*(_QWORD *)(v2 + 96) = v5;
*(_QWORD *)(v2 + 112) = get_content_type(v5);
*(_QWORD *)(v2 + 88) = get_prot(haystack);
*(_QWORD *)(v2 + 104) = haystack;
get_headers(v2, haystack);
v6 = strstr(haystack, "\r\n\r\n");
*(_QWORD *)(v2 + 104) = strdup(v6 + 4);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *haystack, __int64 a2)
{
__int64 v2; // rbx
int v3; // eax
int v4; // er12
char *v5; // rax
char *v6; // rax

v2 = a2;
v3 = func0(haystack);
if ( v3 == 4 )
return 0LL;
v4 = v3;
if ( !a2 )
v2 = ag_malloc(136LL);
*(_QWORD *)(v2 + 128) = destroy_request;
*(_DWORD *)v2 = v4;
v5 = func1(haystack);
*(_QWORD *)(v2 + 96) = v5;
*(_QWORD *)(v2 + 112) = func5(v5);
*(_QWORD *)(v2 + 88) = func2(haystack);
*(_QWORD *)(v2 + 104) = haystack;
func6(v2, haystack);
v6 = strstr(haystack, "\r\n\r\n");
*(_QWORD *)(v2 + 104) = strdup(v6 + 4);
return v2;
}

original_code:
request_t new_request(char *raw, request_t rq)
{
 RQ_TYPE rqt;
 char *end_headers;
 rqt = get_rq_type(raw);
 if (rqt == RQ_UNKNOWN) return ((void *)0);
 if (!rq) rq = ag_malloc(sizeof(struct _http_request));
 rq->destroy = destroy_request;
 rq->rtype = rqt;
 rq->path = get_path(raw);
 rq->content_type = get_content_type(rq->path);
 rq->prot = get_prot(raw);
 rq->body = raw;
 get_headers(rq, raw);
 end_headers = strstr(raw, "\r\n\r\n");
 end_headers += 4;
 rq->body = strdup(end_headers);
 return rq;
}

canonical_original_code:
struct _http_request *new_request(char *raw, struct _http_request *rq)
{
 enum RQ_TYPE rqt;
 char *end_headers;
 rqt = get_rq_type(raw);
 if (rqt == RQ_UNKNOWN) return ((void *)0);
 if (!rq) rq = ag_malloc(sizeof(struct _http_request));
 rq->destroy = destroy_request;
 rq->rtype = rqt;
 rq->path = get_path(raw);
 rq->content_type = get_content_type(rq->path);
 rq->prot = get_prot(raw);
 rq->body = raw;
 get_headers(rq, raw);
 end_headers = strstr(raw, "\r\n\r\n");
 end_headers += 4;
 rq->body = strdup(end_headers);
 return rq;
}

variable_types:
rq
struct _http_request *

return_type: struct _http_request { enum RQ_TYPE { HEAD=0, GET=1, POST=2, PUT=3, RQ_UNKNOWN=4 } rtype; char *headers[-1]; char *prot; char *path; char *body; char *content_type; char *raw; int (*destroy)(void *); } *


decompiled_code:
int __fastcall gr_printstats(__int64 a1)
{
int result; // eax

result = fprintf(
stderr,
"n=%d m=%d usage=%.2f%%\n",
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12),
(float)((float)(100 * *(_DWORD *)(a1 + 8)) / (float)*(int *)(a1 + 12)));
if ( *(_QWORD *)(a1 + 24) )
result = gr_printstats();
return result;
}

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

result = fprintf(
stderr,
"n=%d m=%d usage=%.2f%%\n",
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12),
(float)((float)(100 * *(_DWORD *)(a1 + 8)) / (float)*(int *)(a1 + 12)));
if ( *(_QWORD *)(a1 + 24) )
result = func0();
return result;
}

original_code:
static void gr_printstats(gr_t gr)
{
 fprintf(stderr, "n=%d m=%d usage=%.2f%%\n",
         gr->num, gr->max,
  100*gr->num/(float)gr->max);
 if (gr->chain) gr_printstats(gr->chain);
}

canonical_original_code:
static void gr_printstats(struct genresource *gr)
{
 fprintf(stderr, "n=%d m=%d usage=%.2f%%\n",
         gr->num, gr->max,
  100*gr->num/(float)gr->max);
 if (gr->chain) gr_printstats(gr->chain);
}

variable_types: struct genresource { struct resource_t { void *data; int (*ff)(void *); } *ptrs; int num; int max; struct genresource *next; struct genresource *chain; } *

user_defined_types: struct genresource { struct resource_t *ptrs; int num; int max; struct genresource *next; struct genresource *chain; }


decompiled_code:
__int64 __fastcall gr_clear(__int64 a1)
{
void *v2; // rdi
unsigned int v3; // er13
__int64 i; // rbx
__int64 v6; // rax
void *v7; // rdi
__int64 (*v8)(void); // rax

if ( !a1 )
_assert_fail("gr", "libserver/gr.c", 0x38u, "gr_clear");
if ( !*(_QWORD *)a1 )
_assert_fail("gr->ptrs", "libserver/gr.c", 0x39u, "gr_clear");
v2 = *(void **)(a1 + 24);
v3 = 0;
if ( v2 )
{
if ( destroy_chains_on_clear )
{
v3 = gr_destroy(v2);
*(_QWORD *)(a1 + 24) = 0LL;
}
else
{
v3 = gr_clear();
}
}
for ( i = 0LL; *(_DWORD *)(a1 + 8) > (int)i; ++i )
{
v6 = *(_QWORD *)a1 + 16 * i;
v7 = *(void **)v6;
if ( *(_QWORD *)v6 )
{
v8 = *(__int64 (**)(void))(v6 + 8);
if ( v8 )
v3 += v8();
else
free(v7);
*(_QWORD *)(*(_QWORD *)a1 + 16 * i) = 0LL;
}
}
*(_DWORD *)(a1 + 8) = 0;
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
void *v2; // rdi
unsigned int v3; // er13
__int64 i; // rbx
__int64 v6; // rax
void *v7; // rdi
__int64 (*v8)(void); // rax

if ( !a1 )
_assert_fail("gr", "libserver/gr.c", 0x38u, "gr_clear");
if ( !*(_QWORD *)a1 )
_assert_fail("gr->ptrs", "libserver/gr.c", 0x39u, "gr_clear");
v2 = *(void **)(a1 + 24);
v3 = 0;
if ( v2 )
{
if ( destroy_chains_on_clear )
{
v3 = func2(v2);
*(_QWORD *)(a1 + 24) = 0LL;
}
else
{
v3 = func1();
}
}
for ( i = 0LL; *(_DWORD *)(a1 + 8) > (int)i; ++i )
{
v6 = *(_QWORD *)a1 + 16 * i;
v7 = *(void **)v6;
if ( *(_QWORD *)v6 )
{
v8 = *(__int64 (**)(void))(v6 + 8);
if ( v8 )
v3 += v8();
else
free(v7);
*(_QWORD *)(*(_QWORD *)a1 + 16 * i) = 0LL;
}
}
*(_DWORD *)(a1 + 8) = 0;
return v3;
}

original_code:
int gr_clear(gr_t gr)
{
 int i;
 int ret_val = 0;
 ((void) sizeof ((gr) ? 1 : 0), __extension__ ({ if (gr) ; else __assert_fail ("gr", "libserver/gr.c", 56, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((gr->ptrs) ? 1 : 0), __extension__ ({ if (gr->ptrs) ; else __assert_fail ("gr->ptrs", "libserver/gr.c", 57, __extension__ __PRETTY_FUNCTION__); }));
 if (gr->chain) {
  if (dbg) fprintf(stderr, "gr_clear: clearing chain\n");
  if (destroy_chains_on_clear) {
   ret_val += gr_destroy(gr->chain);
   gr->chain = ((void *)0);
  } else {
   ret_val += gr_clear(gr->chain);
  }
 }
 for (i = 0; i < gr->num; i++) {
  if (gr->ptrs[i].data) {
   if (gr->ptrs[i].ff)
    ret_val += (*gr->ptrs[i].ff)(gr->ptrs[i].data);
   else
    free(gr->ptrs[i].data);
   gr->ptrs[i].data = ((void *)0);
  }
 }
 if (dbg) fprintf(stderr, "gr_clear: cleared %d\n", i);
 gr->num = 0;
 return ret_val;
}

canonical_original_code:
int gr_clear(struct genresource *gr)
{
 int i;
 int ret_val = 0;
 ((void) sizeof ((gr) ? 1 : 0), __extension__ ({ if (gr) ; else __assert_fail ("gr", "libserver/gr.c", 56, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((gr->ptrs) ? 1 : 0), __extension__ ({ if (gr->ptrs) ; else __assert_fail ("gr->ptrs", "libserver/gr.c", 57, __extension__ __PRETTY_FUNCTION__); }));
 if (gr->chain) {
  if (dbg) fprintf(stderr, "gr_clear: clearing chain\n");
  if (destroy_chains_on_clear) {
   ret_val += gr_destroy(gr->chain);
   gr->chain = ((void *)0);
  } else {
   ret_val += gr_clear(gr->chain);
  }
 }
 for (i = 0; i < gr->num; i++) {
  if (gr->ptrs[i].data) {
   if (gr->ptrs[i].ff)
    ret_val += (*gr->ptrs[i].ff)(gr->ptrs[i].data);
   else
    free(gr->ptrs[i].data);
   gr->ptrs[i].data = ((void *)0);
  }
 }
 if (dbg) fprintf(stderr, "gr_clear: cleared %d\n", i);
 gr->num = 0;
 return ret_val;
}

user_defined_types: struct resource_t { void *data; int (*ff)(void *); }


decompiled_code:
__int64 __fastcall gr_destroy(void *ptr)
{
unsigned int v1; // ebp

v1 = 0;
if ( ptr )
{
v1 = gr_clear((__int64)ptr);
free(*(void **)ptr);
free(ptr);
}
return v1;
}

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

v1 = 0;
if ( ptr )
{
v1 = func1((__int64)ptr);
free(*(void **)ptr);
free(ptr);
}
return v1;
}

original_code:
int gr_destroy(gr_t gr)
{
 int ret_val;
 if (!gr) return 0;
 ret_val = gr_clear(gr);
 free(gr->ptrs);
 free(gr);
 return ret_val;
}

canonical_original_code:
int gr_destroy(struct genresource *gr)
{
 int ret_val;
 if (!gr) return 0;
 ret_val = gr_clear(gr);
 free(gr->ptrs);
 free(gr);
 return ret_val;
}


original_code:
int gr_track(gr_t gr, void *ptr, free_func ff)
{
 recurse:
 if (gr->num == gr->max) {
  if (!gr->chain) {
   if (dbg) fprintf(stderr, "gr_track: chaining %d\n",
                   gr->max);
   gr->chain = gr_init(2*gr->max);
  }
  gr = gr->chain;
  goto recurse;
 }
 gr->ptrs[gr->num].data = ptr;
 gr->ptrs[gr->num++].ff = ff;
 return 1;
}

canonical_original_code:
int gr_track(struct genresource *gr, void *ptr, int (*ff)(void *))
{
 recurse:
 if (gr->num == gr->max) {
  if (!gr->chain) {
   if (dbg) fprintf(stderr, "gr_track: chaining %d\n",
                   gr->max);
   gr->chain = gr_init(2*gr->max);
  }
  gr = gr->chain;
  goto recurse;
 }
 gr->ptrs[gr->num].data = ptr;
 gr->ptrs[gr->num++].ff = ff;
 return 1;
}

variable_types:
ptr
void *

variable_types:
ff
int (*)(void *)


decompiled_code:
void *__fastcall gr_malloc(_QWORD *a1, size_t a2)
{
void *v2; // rax
void *v3; // rbx

if ( !a1 )
_assert_fail("gr", "libserver/gr.c", 0x5Eu, "gr_malloc");
if ( !*a1 )
_assert_fail("gr->ptrs", "libserver/gr.c", 0x5Fu, "gr_malloc");
v2 = calloc(1uLL, a2);
v3 = v2;
if ( v2 && !(unsigned int)gr_track((__int64)a1, (__int64)v2, 0LL) )
{
free(v3);
v3 = 0LL;
}
return v3;
}

canonical_decompiled_code:
void *__fastcall func4(_QWORD *a1, size_t a2)
{
void *v2; // rax
void *v3; // rbx

if ( !a1 )
_assert_fail("gr", "libserver/gr.c", 0x5Eu, "gr_malloc");
if ( !*a1 )
_assert_fail("gr->ptrs", "libserver/gr.c", 0x5Fu, "gr_malloc");
v2 = calloc(1uLL, a2);
v3 = v2;
if ( v2 && !(unsigned int)func3((__int64)a1, (__int64)v2, 0LL) )
{
free(v3);
v3 = 0LL;
}
return v3;
}

original_code:
void *gr_malloc(gr_t gr, size_t size)
{
 void *r;
 ((void) sizeof ((gr) ? 1 : 0), __extension__ ({ if (gr) ; else __assert_fail ("gr", "libserver/gr.c", 94, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((gr->ptrs) ? 1 : 0), __extension__ ({ if (gr->ptrs) ; else __assert_fail ("gr->ptrs", "libserver/gr.c", 95, __extension__ __PRETTY_FUNCTION__); }));
 r = calloc(1, size);
 if (!r) {
  if (dbg) fprintf(stderr, "gr_malloc: calloc failed\n");
  return r;
 }
 if (!gr_track(gr, r, ((void *)0))) {
  if (dbg) fprintf(stderr, "gr_malloc: gr_track failed\n");
  free(r);
  return ((void *)0);
 }
 return r;
}

canonical_original_code:
void *gr_malloc(struct genresource *gr, unsigned long size)
{
 void *r;
 ((void) sizeof ((gr) ? 1 : 0), __extension__ ({ if (gr) ; else __assert_fail ("gr", "libserver/gr.c", 94, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((gr->ptrs) ? 1 : 0), __extension__ ({ if (gr->ptrs) ; else __assert_fail ("gr->ptrs", "libserver/gr.c", 95, __extension__ __PRETTY_FUNCTION__); }));
 r = calloc(1, size);
 if (!r) {
  if (dbg) fprintf(stderr, "gr_malloc: calloc failed\n");
  return r;
 }
 if (!gr_track(gr, r, ((void *)0))) {
  if (dbg) fprintf(stderr, "gr_malloc: gr_track failed\n");
  free(r);
  return ((void *)0);
 }
 return r;
}

variable_types:
size
unsigned long

variable_types:
r
void *


decompiled_code:
__int64 gr_finish()
{
int v0; // er12
void *v1; // rbx
unsigned int v2; // ebp
void *v3; // rdi

v0 = destroy_chains_on_clear;
destroy_chains_on_clear = 1;
v1 = gr_List;
gr_List = 0LL;
if ( v1 )
{
v2 = 0;
do
{
v3 = v1;
v1 = (void *)*((_QWORD *)v1 + 2);
v2 += gr_destroy(v3);
}
while ( v1 );
}
else
{
v2 = 0;
}
destroy_chains_on_clear = v0;
return v2;
}

canonical_decompiled_code:
__int64 func5()
{
int v0; // er12
void *v1; // rbx
unsigned int v2; // ebp
void *v3; // rdi

v0 = destroy_chains_on_clear;
destroy_chains_on_clear = 1;
v1 = gr_List;
gr_List = 0LL;
if ( v1 )
{
v2 = 0;
do
{
v3 = v1;
v1 = (void *)*((_QWORD *)v1 + 2);
v2 += func2(v3);
}
while ( v1 );
}
else
{
v2 = 0;
}
destroy_chains_on_clear = v0;
return v2;
}

original_code:
int gr_finish()
{
 gr_t cur;
 gr_t prev = ((void *)0);
 int ret_val = 0;
 int save = destroy_chains_on_clear;
 destroy_chains_on_clear = 1;
 cur = gr_List;
 gr_List = ((void *)0);
 while (cur) {
  prev = cur;
  cur = cur->next;
  ret_val += gr_destroy(prev);
 }
 destroy_chains_on_clear = save;
 return ret_val;
}

canonical_original_code:
int gr_finish()
{
 struct genresource *cur;
 struct genresource *prev = ((void *)0);
 int ret_val = 0;
 int save = destroy_chains_on_clear;
 destroy_chains_on_clear = 1;
 cur = gr_List;
 gr_List = ((void *)0);
 while (cur) {
  prev = cur;
  cur = cur->next;
  ret_val += gr_destroy(prev);
 }
 destroy_chains_on_clear = save;
 return ret_val;
}

variable_types: save int


decompiled_code:
size_t __fastcall gr_stats(_QWORD *a1)
{
_QWORD *v1; // rbx
size_t result; // rax

v1 = a1;
if ( a1 || (v1 = gr_List) != 0LL )
{
do
{
gr_printstats((__int64)v1);
result = fwrite("----------------------\n", 1uLL, 0x17uLL, stderr);
v1 = (_QWORD *)v1[2];
}
while ( v1 );
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func6(_QWORD *a1)
{
_QWORD *v1; // rbx
size_t result; // rax

v1 = a1;
if ( a1 || (v1 = gr_List) != 0LL )
{
do
{
func0((__int64)v1);
result = fwrite("----------------------\n", 1uLL, 0x17uLL, stderr);
v1 = (_QWORD *)v1[2];
}
while ( v1 );
}
return result;
}

original_code:
void gr_stats(gr_t gr)
{
 gr_t cur = gr;
 if (!cur) cur = gr_List;
 while (cur) {
  gr_printstats(cur);
  fprintf(stderr, "----------------------\n");
  cur = cur->next;
 }
}

canonical_original_code:
void gr_stats(struct genresource *gr)
{
 struct genresource *cur = gr;
 if (!cur) cur = gr_List;
 while (cur) {
  gr_printstats(cur);
  fprintf(stderr, "----------------------\n");
  cur = cur->next;
 }
}


decompiled_code:
__int64 __fastcall gr_iter_next(void *ptr)
{
unsigned int (__fastcall *v1)(_QWORD); // r12
__int64 *v2; // rbp
int v3; // eax
__int64 result; // rax
__int64 v5; // rdx
int v6; // eax
__int64 v7; // rdx

if ( !ptr )
return 0LL;
v1 = (unsigned int (__fastcall *)(_QWORD))*((_QWORD *)ptr + 2);
v2 = *(__int64 **)ptr;
if ( *(_QWORD *)ptr )
{
while ( 1 )
{
v3 = *((_DWORD *)ptr + 2);
if ( v3 < *((_DWORD *)v2 + 2) )
break;
LABEL_7:
v2 = (__int64 *)v2[3];
*(_QWORD *)ptr = v2;
*((_DWORD *)ptr + 2) = 0;
if ( !v2 )
goto LABEL_8;
}
if ( v1 )
{
while ( !v1(*(_QWORD *)(*v2 + 16LL * v3)) )
{
v3 = *((_DWORD *)ptr + 2) + 1;
*((_DWORD *)ptr + 2) = v3;
if ( v3 >= *((_DWORD *)v2 + 2) )
goto LABEL_7;
}
v5 = *v2;
v6 = *((_DWORD *)ptr + 2);
*((_DWORD *)ptr + 2) = v6 + 1;
result = *(_QWORD *)(v5 + 16LL * v6);
}
else
{
v7 = *v2;
*((_DWORD *)ptr + 2) = v3 + 1;
result = *(_QWORD *)(v7 + 16LL * v3);
}
}
else
{
LABEL_8:
free(ptr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(void *ptr)
{
unsigned int (__fastcall *v1)(_QWORD); // r12
__int64 *v2; // rbp
int v3; // eax
__int64 result; // rax
__int64 v5; // rdx
int v6; // eax
__int64 v7; // rdx

if ( !ptr )
return 0LL;
v1 = (unsigned int (__fastcall *)(_QWORD))*((_QWORD *)ptr + 2);
v2 = *(__int64 **)ptr;
if ( *(_QWORD *)ptr )
{
while ( 1 )
{
v3 = *((_DWORD *)ptr + 2);
if ( v3 < *((_DWORD *)v2 + 2) )
break;
LABEL_7:
v2 = (__int64 *)v2[3];
*(_QWORD *)ptr = v2;
*((_DWORD *)ptr + 2) = 0;
if ( !v2 )
goto LABEL_8;
}
if ( v1 )
{
while ( !v1(*(_QWORD *)(*v2 + 16LL * v3)) )
{
v3 = *((_DWORD *)ptr + 2) + 1;
*((_DWORD *)ptr + 2) = v3;
if ( v3 >= *((_DWORD *)v2 + 2) )
goto LABEL_7;
}
v5 = *v2;
v6 = *((_DWORD *)ptr + 2);
*((_DWORD *)ptr + 2) = v6 + 1;
result = *(_QWORD *)(v5 + 16LL * v6);
}
else
{
v7 = *v2;
*((_DWORD *)ptr + 2) = v3 + 1;
result = *(_QWORD *)(v7 + 16LL * v3);
}
}
else
{
LABEL_8:
free(ptr);
result = 0LL;
}
return result;
}

original_code:
void *gr_iter_next(iter_t iter)
{
 gr_t gr;
 iter_return_p f;
 if (!iter) return ((void *)0);
 f = iter->f;
 recurse:
 gr = iter->gr;
 if (!gr) {
  free(iter);
  return ((void *)0);
 }
 while (iter->cur < gr->num) {
  if (f) {
   if ((*f)(gr->ptrs[iter->cur].data))
    return gr->ptrs[iter->cur++].data;
   else iter->cur++;
  }
  else return gr->ptrs[iter->cur++].data;
 }
 iter->gr = gr->chain;
 iter->cur = 0;
 goto recurse;
}

canonical_original_code:
void *gr_iter_next(struct iterator_context *iter)
{
 struct genresource *gr;
 int (*f)(void *);
 if (!iter) return ((void *)0);
 f = iter->f;
 recurse:
 gr = iter->gr;
 if (!gr) {
  free(iter);
  return ((void *)0);
 }
 while (iter->cur < gr->num) {
  if (f) {
   if ((*f)(gr->ptrs[iter->cur].data))
    return gr->ptrs[iter->cur++].data;
   else iter->cur++;
  }
  else return gr->ptrs[iter->cur++].data;
 }
 iter->gr = gr->chain;
 iter->cur = 0;
 goto recurse;
}

variable_types: struct iterator_context { struct genresource { struct resource_t { void *data; int (*ff)(void *); } *ptrs; int num; int max; struct genresource *next; struct genresource *chain; } *gr; int cur; int (*f)(void *); } *

variable_types:
f
int (*)(void *)

user_defined_types: struct iterator_context { struct genresource *gr; int cur; int (*f)(void *); }


decompiled_code:
_BOOL8 __fastcall gr_free_filed(void *ptr)
{
int v1; // ebp

v1 = close(*(_DWORD *)ptr);
free(ptr);
return v1 != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(void *ptr)
{
int v1; // ebp

v1 = close(*(_DWORD *)ptr);
free(ptr);
return v1 != 0;
}

original_code:
int gr_free_filed(void *foo)
{
 int ret_val = 0;
 struct filed_wrapper *fd = foo;
 if (fd >= 0 && close(fd->filed) != 0) ret_val = 1;
 free(foo);
 return ret_val;
}

variable_types:
foo
void *

variable_types:
fd
struct filed_wrapper { int filed; } *


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

result = new_handler();
*(_QWORD *)(result + 48) = SMTP_info_con;
return result;
}

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

result = new_handler();
*(_QWORD *)(result + 48) = SMTP_info_con;
return result;
}

original_code:
static handler_t SMTP_Info_handler()
{
 handler_t hd;
 hd = new_handler();
 hd->handle_con = SMTP_info_con;
 return hd;
}

canonical_original_code:
static struct _handler_t *SMTP_Info_handler()
{
 struct _handler_t *hd;
 hd = new_handler();
 hd->handle_con = SMTP_info_con;
 return hd;
}

variable_types: struct _handler_t { struct _queue_connector { void *prev; } _qcon; struct _server_t { char *name; char *pidfile; char *logfile; int logfd; int *stats; unsigned short port; int backlog; int numthreads; int maxcon; int uid; int listen_sk; struct handler_rec { unsigned long tid; struct _handler_t *hd; } *handlers; struct _handler_t *(*newhandler)(); void (*summary)(struct _server_t *, int); int (*destroy)(void *); void *(*start)(void *); struct _wait_queue_t { union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } m; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } w; int num; int max; int num_refused; struct _queue_t { struct _queue_connector *first; void (*push)(struct _queue_t *, void *); void *(*pop)(struct _queue_t *); int (*destroy)(void *); } *cons_queue; int (*add_con)(struct _wait_queue_t *, struct _connection_t { struct _queue_connector _qcon; int sk; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } *name; void *clientdata; struct _connection_t *prev; int (*destroy)(void *); } *); void (*wait_on)(struct _wait_queue_t *, struct _handler_t *); int (*destroy)(void *); } *wq; } *svr; int hd_state; struct _connection_t *con; void *(*start)(void *); void (*handle_con)(struct _handler_t *); char *(*get_state)(struct _handler_t *); int (*destroy)(void *); } *

user_defined_types: struct _handler_t { struct _queue_connector _qcon; struct _server_t *svr; int hd_state; struct _connection_t *con; void *(*start)(void *); void (*handle_con)(struct _handler_t *); char *(*get_state)(struct _handler_t *); int (*destroy)(void *); }

user_defined_types: struct _server_t { char *name; char *pidfile; char *logfile; int logfd; int *stats; unsigned short port; int backlog; int numthreads; int maxcon; int uid; int listen_sk; struct handler_rec *handlers; struct _handler_t *(*newhandler)(); void (*summary)(struct _server_t *, int); int (*destroy)(void *); void *(*start)(void *); struct _wait_queue_t *wq; }

user_defined_types: struct _wait_queue_t { union pthread_mutex_t m; union pthread_cond_t w; int num; int max; int num_refused; struct _queue_t *cons_queue; int (*add_con)(struct _wait_queue_t *, struct _connection_t *); void (*wait_on)(struct _wait_queue_t *, struct _handler_t *); int (*destroy)(void *); }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }

user_defined_types: struct _connection_t { struct _queue_connector _qcon; int sk; struct sockaddr_in *name; void *clientdata; struct _connection_t *prev; int (*destroy)(void *); }

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }


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

result = new_handler();
*(_QWORD *)(result + 48) = SMTP_with_options;
return result;
}

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

result = new_handler();
*(_QWORD *)(result + 48) = SMTP_with_options;
return result;
}

original_code:
static handler_t SMTP_new_handler()
{
 handler_t hd;
 hd = new_handler();
 hd->handle_con = SMTP_with_options;
 return hd;
}

canonical_original_code:
static struct _handler_t *SMTP_new_handler()
{
 struct _handler_t *hd;
 hd = new_handler();
 hd->handle_con = SMTP_with_options;
 return hd;
}

return_type: struct _handler_t { struct _queue_connector { void *prev; } _qcon; struct _server_t { char *name; char *pidfile; char *logfile; int logfd; int *stats; unsigned short port; int backlog; int numthreads; int maxcon; int uid; int listen_sk; struct handler_rec { unsigned long tid; struct _handler_t *hd; } *handlers; struct _handler_t *(*newhandler)(); void (*summary)(struct _server_t *, int); int (*destroy)(void *); void *(*start)(void *); struct _wait_queue_t { union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } m; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } w; int num; int max; int num_refused; struct _queue_t { struct _queue_connector *first; void (*push)(struct _queue_t *, void *); void *(*pop)(struct _queue_t *); int (*destroy)(void *); } *cons_queue; int (*add_con)(struct _wait_queue_t *, struct _connection_t { struct _queue_connector _qcon; int sk; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } *name; void *clientdata; struct _connection_t *prev; int (*destroy)(void *); } *); void (*wait_on)(struct _wait_queue_t *, struct _handler_t *); int (*destroy)(void *); } *wq; } *svr; int hd_state; struct _connection_t *con; void *(*start)(void *); void (*handle_con)(struct _handler_t *); char *(*get_state)(struct _handler_t *); int (*destroy)(void *); } *


decompiled_code:
void __fastcall server_handler_summary(__int64 a1, int a2)
{
__int64 v2; // rbp
__int64 v3; // rdx
const char *v4; // rax
size_t v5; // rax
char v6[552]; // [rsp-228h] [rbp-228h] BYREF

if ( *(int *)(a1 + 48) > 0 )
{
v2 = 0LL;
do
{
v3 = *(_QWORD *)(*(_QWORD *)(a1 + 64) + 16 * v2 + 8);
memset(v6, 0, 0x200uLL);
v4 = (const char *)(*(__int64 (__fastcall **)(__int64))(v3 + 56))(v3);
sprintf(v6, "handler %d: tid=0x%x state=%s\n", (unsigned int)v2, *(_QWORD *)(*(_QWORD *)(a1 + 64) + 16 * v2), v4);
v5 = strlen(v6);
write(a2, v6, v5);
++v2;
}
while ( *(_DWORD *)(a1 + 48) > (int)v2 );
}
}

original_code:
static void server_handler_summary(server_t svr, int fd)
{
 char buf[512];
 int i;
 handler_t hd;
 for (i = 0; i < svr->numthreads; i++) {
  hd = svr->handlers[i].hd;
  memset((void *)buf, 0, 512);
  sprintf(buf, "handler %d: tid=0x%x state=%s\n",
   i, (int)svr->handlers[i].tid, hd->get_state(hd));
  (void)write(fd, buf, strlen(buf));
 }
}

canonical_original_code:
static void server_handler_summary(struct _server_t *svr, int fd)
{
 char buf[512];
 int i;
 struct _handler_t *hd;
 for (i = 0; i < svr->numthreads; i++) {
  hd = svr->handlers[i].hd;
  memset((void *)buf, 0, 512);
  sprintf(buf, "handler %d: tid=0x%x state=%s\n",
   i, (int)svr->handlers[i].tid, hd->get_state(hd));
  (void)write(fd, buf, strlen(buf));
 }
}

variable_types: struct _server_t { char *name; char *pidfile; char *logfile; int logfd; int *stats; unsigned short port; int backlog; int numthreads; int maxcon; int uid; int listen_sk; struct handler_rec { unsigned long tid; struct _handler_t { struct _queue_connector { void *prev; } _qcon; struct _server_t *svr; int hd_state; struct _connection_t { struct _queue_connector _qcon; int sk; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } *name; void *clientdata; struct _connection_t *prev; int (*destroy)(void *); } *con; void *(*start)(void *); void (*handle_con)(struct _handler_t *); char *(*get_state)(struct _handler_t *); int (*destroy)(void *); } *hd; } *handlers; struct _handler_t *(*newhandler)(); void (*summary)(struct _server_t *, int); int (*destroy)(void *); void *(*start)(void *); struct _wait_queue_t { union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } m; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } w; int num; int max; int num_refused; struct _queue_t { struct _queue_connector *first; void (*push)(struct _queue_t *, void *); void *(*pop)(struct _queue_t *); int (*destroy)(void *); } *cons_queue; int (*add_con)(struct _wait_queue_t *, struct _connection_t *); void (*wait_on)(struct _wait_queue_t *, struct _handler_t *); int (*destroy)(void *); } *wq; } *

variable_types: fd int

variable_types:
buf
char [512]

user_defined_types: struct handler_rec { unsigned long tid; struct _handler_t *hd; }


decompiled_code:
// bad sp value at call has been detected, the output may be wrong!
void __fastcall SMTP_summary(__int64 a1, int a2)
{
size_t v2; // rax
size_t v3; // rax
unsigned int *v4; // rax
__int64 v5; // r9
__int64 v6; // r8
size_t v7; // rax
__int64 v8; // r9
__int64 v9; // r8
__int64 v10; // rcx
size_t v11; // rax
_QWORD v12[69]; // [rsp+60h] [rbp-228h] BYREF

if ( a1 )
{
memset(v12, 0, 0x200uLL);
sprintf(
(char *)v12,
"%s pidf=%s port=%d numth=%d maxcon=%d\n uid=%d numcon=%d num_ref=%d\n\n",
*(const char **)a1,
*(const char **)(a1 + 8),
*(unsigned __int16 *)(a1 + 40),
*(unsigned int *)(a1 + 48),
*(unsigned int *)(a1 + 52),
*(unsigned int *)(a1 + 56),
*(unsigned int *)(*(_QWORD *)(a1 + 104) + 88LL),
*(unsigned int *)(*(_QWORD *)(a1 + 104) + 96LL));
v2 = strlen((const char *)v12);
write(a2, v12, v2);
server_handler_summary(a1, a2);
memset(v12, 0, 0x200uLL);
sprintf(
(char *)v12,
"%s pidf=%s logf=%s port=%d numth=%d\n maxcon=%d uid=%d numcon=%d num_ref=%d\n\n",
*(const char **)SMTP_server,
*(const char **)(SMTP_server + 8),
*(const char **)(SMTP_server + 16),
*(unsigned __int16 *)(SMTP_server + 40),
*(unsigned int *)(SMTP_server + 48),
*(unsigned int *)(SMTP_server + 52),
*(unsigned int *)(SMTP_server + 56),
*(unsigned int *)(*(_QWORD *)(SMTP_server + 104) + 88LL),
*(unsigned int *)(*(_QWORD *)(SMTP_server + 104) + 96LL));
v3 = strlen((const char *)v12);
write(a2, v12, v3);
server_handler_summary(SMTP_server, a2);
memset(v12, 0, 0x200uLL);
v4 = *(unsigned int **)(SMTP_server + 32);
v5 = v4[2];
v6 = v4[1];
v12[1] = v4[4];
v12[0] = v4[3];
sprintf((char *)v12, "%s cons=%d bytes=%d 4xx=%d 5xx=%d dropped=%d\n\n", *(const char **)SMTP_server, *v4, v6, v5);
v7 = strlen((const char *)v12);
write(a2, v12, v7);
memset(v12, 0, 0x200uLL);
v8 = *(unsigned int *)(options + 12);
v9 = *(unsigned int *)(options + 8);
v10 = *(unsigned int *)(options + 4);
LODWORD(v12[0]) = *(_DWORD *)(options + 16);
sprintf(
(char *)v12,
"min_delay=%d max_delay=%d percent_4xx=%d percent_5xx=%d percent_dropped=%d\n\n",
*(unsigned int *)options,
v10,
v9,
v8);
v11 = strlen((const char *)v12);
write(a2, v12, v11);
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, int a2)
{
size_t v2; // rax
size_t v3; // rax
unsigned int *v4; // rax
__int64 v5; // r9
__int64 v6; // r8
size_t v7; // rax
__int64 v8; // r9
__int64 v9; // r8
__int64 v10; // rcx
size_t v11; // rax
_QWORD v12[69]; // [rsp+60h] [rbp-228h] BYREF

if ( a1 )
{
memset(v12, 0, 0x200uLL);
sprintf(
(char *)v12,
"%s pidf=%s port=%d numth=%d maxcon=%d\n uid=%d numcon=%d num_ref=%d\n\n",
*(const char **)a1,
*(const char **)(a1 + 8),
*(unsigned __int16 *)(a1 + 40),
*(unsigned int *)(a1 + 48),
*(unsigned int *)(a1 + 52),
*(unsigned int *)(a1 + 56),
*(unsigned int *)(*(_QWORD *)(a1 + 104) + 88LL),
*(unsigned int *)(*(_QWORD *)(a1 + 104) + 96LL));
v2 = strlen((const char *)v12);
write(a2, v12, v2);
func2(a1, a2);
memset(v12, 0, 0x200uLL);
sprintf(
(char *)v12,
"%s pidf=%s logf=%s port=%d numth=%d\n maxcon=%d uid=%d numcon=%d num_ref=%d\n\n",
*(const char **)SMTP_server,
*(const char **)(SMTP_server + 8),
*(const char **)(SMTP_server + 16),
*(unsigned __int16 *)(SMTP_server + 40),
*(unsigned int *)(SMTP_server + 48),
*(unsigned int *)(SMTP_server + 52),
*(unsigned int *)(SMTP_server + 56),
*(unsigned int *)(*(_QWORD *)(SMTP_server + 104) + 88LL),
*(unsigned int *)(*(_QWORD *)(SMTP_server + 104) + 96LL));
v3 = strlen((const char *)v12);
write(a2, v12, v3);
func2(SMTP_server, a2);
memset(v12, 0, 0x200uLL);
v4 = *(unsigned int **)(SMTP_server + 32);
v5 = v4[2];
v6 = v4[1];
v12[1] = v4[4];
v12[0] = v4[3];
sprintf((char *)v12, "%s cons=%d bytes=%d 4xx=%d 5xx=%d dropped=%d\n\n", *(const char **)SMTP_server, *v4, v6, v5);
v7 = strlen((const char *)v12);
write(a2, v12, v7);
memset(v12, 0, 0x200uLL);
v8 = *(unsigned int *)(options + 12);
v9 = *(unsigned int *)(options + 8);
v10 = *(unsigned int *)(options + 4);
LODWORD(v12[0]) = *(_DWORD *)(options + 16);
sprintf(
(char *)v12,
"min_delay=%d max_delay=%d percent_4xx=%d percent_5xx=%d percent_dropped=%d\n\n",
*(unsigned int *)options,
v10,
v9,
v8);
v11 = strlen((const char *)v12);
write(a2, v12, v11);
}
}

original_code:
static void SMTP_summary(server_t self, int fd)
{
 char buf[512];
 if (!self) return;
 memset((void *)buf, 0, 512);
 sprintf(buf, "%s pidf=%s port=%d numth=%d maxcon=%d\n uid=%d numcon=%d num_ref=%d\n\n",
  self->name, self->pidfile, self->port, self->numthreads,
  self->maxcon, self->uid, self->wq->num, self->wq->num_refused);
 (void)write(fd, buf, strlen(buf));
 server_handler_summary(self, fd);
 memset((void *)buf, 0, 512);
 sprintf(buf, "%s pidf=%s logf=%s port=%d numth=%d\n maxcon=%d uid=%d numcon=%d num_ref=%d\n\n",
  SMTP_server->name, SMTP_server->pidfile, SMTP_server->logfile,
  SMTP_server->port, SMTP_server->numthreads,
  SMTP_server->maxcon, SMTP_server->uid,
  SMTP_server->wq->num, SMTP_server->wq->num_refused);
 (void)write(fd, buf, strlen(buf));
 server_handler_summary(SMTP_server, fd);
 memset((void *)buf, 0, 512);
 sprintf(buf, "%s cons=%d bytes=%d 4xx=%d 5xx=%d dropped=%d\n\n",
  SMTP_server->name,
  SMTP_server->stats[SMTP_connections_processed],
  SMTP_server->stats[SMTP_bytes_processed],
  SMTP_server->stats[SMTP_4xx],
  SMTP_server->stats[SMTP_5xx],
  SMTP_server->stats[SMTP_dropped]);
 (void)write(fd, buf, strlen(buf));
 memset((void *)buf, 0, 512);
 sprintf(buf, "min_delay=%d max_delay=%d percent_4xx=%d percent_5xx=%d percent_dropped=%d\n\n",
  options->min_delay, options->max_delay, options->percent_4xx,
  options->percent_5xx, options->percent_dropped);
 (void)write(fd, buf, strlen(buf));
}

canonical_original_code:
static void SMTP_summary(struct _server_t *self, int fd)
{
 char buf[512];
 if (!self) return;
 memset((void *)buf, 0, 512);
 sprintf(buf, "%s pidf=%s port=%d numth=%d maxcon=%d\n uid=%d numcon=%d num_ref=%d\n\n",
  self->name, self->pidfile, self->port, self->numthreads,
  self->maxcon, self->uid, self->wq->num, self->wq->num_refused);
 (void)write(fd, buf, strlen(buf));
 server_handler_summary(self, fd);
 memset((void *)buf, 0, 512);
 sprintf(buf, "%s pidf=%s logf=%s port=%d numth=%d\n maxcon=%d uid=%d numcon=%d num_ref=%d\n\n",
  SMTP_server->name, SMTP_server->pidfile, SMTP_server->logfile,
  SMTP_server->port, SMTP_server->numthreads,
  SMTP_server->maxcon, SMTP_server->uid,
  SMTP_server->wq->num, SMTP_server->wq->num_refused);
 (void)write(fd, buf, strlen(buf));
 server_handler_summary(SMTP_server, fd);
 memset((void *)buf, 0, 512);
 sprintf(buf, "%s cons=%d bytes=%d 4xx=%d 5xx=%d dropped=%d\n\n",
  SMTP_server->name,
  SMTP_server->stats[SMTP_connections_processed],
  SMTP_server->stats[SMTP_bytes_processed],
  SMTP_server->stats[SMTP_4xx],
  SMTP_server->stats[SMTP_5xx],
  SMTP_server->stats[SMTP_dropped]);
 (void)write(fd, buf, strlen(buf));
 memset((void *)buf, 0, 512);
 sprintf(buf, "min_delay=%d max_delay=%d percent_4xx=%d percent_5xx=%d percent_dropped=%d\n\n",
  options->min_delay, options->max_delay, options->percent_4xx,
  options->percent_5xx, options->percent_dropped);
 (void)write(fd, buf, strlen(buf));
}

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }

user_defined_types: struct _queue_t { struct _queue_connector *first; void (*push)(struct _queue_t *, void *); void *(*pop)(struct _queue_t *); int (*destroy)(void *); }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


decompiled_code:
__int64 __fastcall SMTP_set_command(char *haystack)
{
__int64 result; // rax
char *v2; // rax
char *v3; // rax
char *v4; // rax
char *v5; // rax
char *v6; // rax

result = 0LL;
if ( *haystack )
{
v2 = strstr(haystack, "min_delay");
if ( v2 )
{
*(_DWORD *)options = atoi(v2 + 10);
result = 1LL;
}
else
{
v3 = strstr(haystack, "max_delay");
if ( v3 )
{
*(_DWORD *)(options + 4) = atoi(v3 + 10);
result = 1LL;
}
else
{
v4 = strstr(haystack, "percent_4xx");
if ( v4 )
{
*(_DWORD *)(options + 8) = atoi(v4 + 12);
result = 1LL;
}
else
{
v5 = strstr(haystack, "percent_5xx");
if ( v5 )
{
*(_DWORD *)(options + 12) = atoi(v5 + 12);
result = 1LL;
}
else
{
v6 = strstr(haystack, "percent_dropped");
if ( v6 )
{
*(_DWORD *)(options + 16) = atoi(v6 + 16);
result = 1LL;
}
else
{
result = 0LL;
}
}
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *haystack)
{
__int64 result; // rax
char *v2; // rax
char *v3; // rax
char *v4; // rax
char *v5; // rax
char *v6; // rax

result = 0LL;
if ( *haystack )
{
v2 = strstr(haystack, "min_delay");
if ( v2 )
{
*(_DWORD *)options = atoi(v2 + 10);
result = 1LL;
}
else
{
v3 = strstr(haystack, "max_delay");
if ( v3 )
{
*(_DWORD *)(options + 4) = atoi(v3 + 10);
result = 1LL;
}
else
{
v4 = strstr(haystack, "percent_4xx");
if ( v4 )
{
*(_DWORD *)(options + 8) = atoi(v4 + 12);
result = 1LL;
}
else
{
v5 = strstr(haystack, "percent_5xx");
if ( v5 )
{
*(_DWORD *)(options + 12) = atoi(v5 + 12);
result = 1LL;
}
else
{
v6 = strstr(haystack, "percent_dropped");
if ( v6 )
{
*(_DWORD *)(options + 16) = atoi(v6 + 16);
result = 1LL;
}
else
{
result = 0LL;
}
}
}
}
}
}
return result;
}

original_code:
static int SMTP_set_command(char *cmd)
{
 int num;
 char *pos;
 if (!strlen(cmd)) return 0;
 if ((pos = strstr(cmd, "min_delay")) != ((void *)0)) {
  pos += strlen("min_delay") + 1;
  num = atoi(pos);
  options->min_delay = num;
 }
 else if ((pos = strstr(cmd, "max_delay")) != ((void *)0)) {
  pos += strlen("max_delay") + 1;
  num = atoi(pos);
  options->max_delay = num;
 }
 else if ((pos = strstr(cmd, "percent_4xx")) != ((void *)0)) {
  pos += strlen("percent_4xx") + 1;
  num = atoi(pos);
  options->percent_4xx = num;
 }
 else if ((pos = strstr(cmd, "percent_5xx")) != ((void *)0)) {
  pos += strlen("percent_5xx") + 1;
  num = atoi(pos);
  options->percent_5xx = num;
 }
 else if ((pos = strstr(cmd, "percent_dropped")) != ((void *)0)) {
  pos += strlen("percent_dropped") + 1;
  num = atoi(pos);
  options->percent_dropped = num;
 } else return 0;
 return 1;
}

variable_types:
cmd
char *

variable_types: num int