decompiled_code:
__int64 __fastcall show_simple_menu(__int64 a1)
{
__int64 v1; // rbp
void (*v2)(void); // rdx
unsigned __int8 v3; // bl
char v4; // dl
__int64 (__fastcall *v5)(__int64); // rax
__int64 result; // rax
bool v7; // cf
bool v8; // zf
const char *v9; // rsi
const char *v10; // rdi
__int64 v11; // rcx

v1 = *(_QWORD *)(a1 + 32);
v2 = *(void (**)(void))(v1 + 8);
if ( v2 )
v2();
while ( 1 )
{
io_func[3](v1);
v3 = ((__int64 (__fastcall *)(__int64))io_func[6])(v1);
if ( (unsigned __int8)is_error() )
{
v9 = (const char *)get_error();
v10 = "quit";
v11 = 5LL;
do
{
if ( !v11 )
break;
v7 = *v9 < (unsigned int)*v10;
v8 = *v9++ == *v10++;
--v11;
}
while ( v8 );
if ( (!v7 && !v8) == v7 )
{
clear_error(v10, v9);
return 4LL;
}
}
v4 = *(_BYTE *)(v1 + 40LL * v3 + 16);
if ( v4 == 1 )
return 3LL;
if ( !v4 )
break;
v5 = *(__int64 (__fastcall **)(__int64))(v1 + 40LL * v3 + 40);
if ( v5 )
{
result = v5(v1 + 40LL * v3 + 16);
if ( (_BYTE)result != 3 )
return result;
}
}
return 4LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 v1; // rbp
void (*v2)(void); // rdx
unsigned __int8 v3; // bl
char v4; // dl
__int64 (__fastcall *v5)(__int64); // rax
__int64 result; // rax
bool v7; // cf
bool v8; // zf
const char *v9; // rsi
const char *v10; // rdi
__int64 v11; // rcx

v1 = *(_QWORD *)(a1 + 32);
v2 = *(void (**)(void))(v1 + 8);
if ( v2 )
v2();
while ( 1 )
{
io_func[3](v1);
v3 = ((__int64 (__fastcall *)(__int64))io_func[6])(v1);
if ( (unsigned __int8)is_error() )
{
v9 = (const char *)get_error();
v10 = "quit";
v11 = 5LL;
do
{
if ( !v11 )
break;
v7 = *v9 < (unsigned int)*v10;
v8 = *v9++ == *v10++;
--v11;
}
while ( v8 );
if ( (!v7 && !v8) == v7 )
{
clear_error(v10, v9);
return 4LL;
}
}
v4 = *(_BYTE *)(v1 + 40LL * v3 + 16);
if ( v4 == 1 )
return 3LL;
if ( !v4 )
break;
v5 = *(__int64 (__fastcall **)(__int64))(v1 + 40LL * v3 + 40);
if ( v5 )
{
result = v5(v1 + 40LL * v3 + 16);
if ( (_BYTE)result != 3 )
return result;
}
}
return 4LL;
}

original_code:
uint8_t show_simple_menu(menu_item_t const *ctx) {
   uint8_t input, choice;
   menu_list_t *menu = (menu_list_t*) ctx->data;
   if (menu->configure_settings)
      menu->configure_settings();
   while (1) {
      io_func.show_menu(menu);
      input = io_func.get_menu_input(menu);
      if (is_error() && !strncmp(get_error(), "quit", 5)) {
         clear_error();
         return MC_EXIT;
      }
      if (menu->menu[input].id == BACK)
         return MC_BACK;
      if (menu->menu[input].id == EXIT) {
         return MC_EXIT;
      }
      if (menu->menu[input].action)
         choice = menu->menu[input].action(&menu->menu[input]);
      if (choice != MC_BACK)
         return choice;
   }
}

canonical_original_code:
unsigned char show_simple_menu(struct menu_item *ctx) {
   unsigned char input; unsigned char choice;
   struct menu_list_t *menu = (menu_list_t*) ctx->data;
   if (menu->configure_settings)
      menu->configure_settings();
   while (1) {
      io_func.show_menu(menu);
      input = io_func.get_menu_input(menu);
      if (is_error() && !strncmp(get_error(), "quit", 5)) {
         clear_error();
         return MC_EXIT;
      }
      if (menu->menu[input].id == BACK)
         return MC_BACK;
      if (menu->menu[input].id == EXIT) {
         return MC_EXIT;
      }
      if (menu->menu[input].action)
         choice = menu->menu[input].action(&menu->menu[input]);
      if (choice != MC_BACK)
         return choice;
   }
}

variable_types:
input
unsigned char

variable_types: struct menu_list_t { unsigned char size; unsigned char action_item_num; void (*configure_settings)(); struct menu_item { unsigned char id; char *(*get_title)(); enum menu_item_type_t { MENU_ITEM_CLICKABLE=0, MENU_ITEM_EDITABLE=1, MENU_ITEM_TEXT=2 } type; unsigned char (*action)(struct menu_item *); void *data; } menu[]; } *

user_defined_types: struct menu_list_t { unsigned char size; unsigned char action_item_num; void (*configure_settings)(); struct menu_item menu[]; }


decompiled_code:
__int64 switch_and_start_game()
{
switch_players();
return 1LL;
}

canonical_decompiled_code:
__int64 func4()
{
switch_players();
return 1LL;
}

original_code:
uint8_t switch_and_start_game(menu_item_t const *ctx) {
   switch_players();
   return MC_START_NEW_GAME;
}

canonical_original_code:
unsigned char switch_and_start_game(struct menu_item *ctx) {
   switch_players();
   return MC_START_NEW_GAME;
}

variable_types: struct menu_item { unsigned char id; char *(*get_title)(); enum menu_item_type_t { MENU_ITEM_CLICKABLE=0, MENU_ITEM_EDITABLE=1, MENU_ITEM_TEXT=2 } type; unsigned char (*action)(struct menu_item *); void *data; } *

return_type: unsigned char

user_defined_types: struct menu_item { unsigned char id; char *(*get_title)(); enum menu_item_type_t type; unsigned char (*action)(struct menu_item *); void *data; }


decompiled_code:
__int64 __fastcall apply_player_name(__int64 a1)
{
__int64 v1; // rbx
_BYTE v3[264]; // [rsp+0h] [rbp-108h] BYREF

v1 = *(_QWORD *)(a1 + 32);
((void (__fastcall *)(__int64, _BYTE *))io_func[7])(a1, v3);
set_player_name((unsigned __int8)v1, v3);
return 3LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 v1; // rbx
_BYTE v3[264]; // [rsp+0h] [rbp-108h] BYREF

v1 = *(_QWORD *)(a1 + 32);
((void (__fastcall *)(__int64, _BYTE *))io_func[7])(a1, v3);
set_player_name((unsigned __int8)v1, v3);
return 3LL;
}

original_code:
uint8_t apply_player_name(menu_item_t const *ctx) {
   uint64_t player_id = (uint64_t) ctx->data;
   char input[256];
   io_func.get_string_input(ctx, input);
   set_player_name(player_id, input);
   return MC_BACK;
}

canonical_original_code:
unsigned char apply_player_name(struct menu_item *ctx) {
   unsigned long player_id = (uint64_t) ctx->data;
   char input[256];
   io_func.get_string_input(ctx, input);
   set_player_name(player_id, input);
   return MC_BACK;
}

variable_types:
input
char [256]

user_defined_types: enum menu_item_type_t { MENU_ITEM_CLICKABLE=0, MENU_ITEM_EDITABLE=1, MENU_ITEM_TEXT=2 }


decompiled_code:
__int64 get_player1_name()
{
return get_player_name(0LL);
}

canonical_decompiled_code:
__int64 func6()
{
return get_player_name(0LL);
}

original_code:
const char *get_player1_name() {
   return get_player_name(0);
}

return_type: char *


decompiled_code:
__int64 get_player2_name()
{
return get_player_name(1LL);
}

canonical_decompiled_code:
__int64 func7()
{
return get_player_name(1LL);
}

original_code:
const char *get_player2_name() {
   return get_player_name(1);
}


decompiled_code:
__int64 set_hot_seat_mode()
{
set_players();
set_player_func_list(0LL, &player_callbacks);
set_player_ctx(0LL, 0LL);
set_player_func_list(1LL, &player_callbacks);
return set_player_ctx(1LL, 0LL);
}

canonical_decompiled_code:
__int64 func8()
{
set_players();
set_player_func_list(0LL, &player_callbacks);
set_player_ctx(0LL, 0LL);
set_player_func_list(1LL, &player_callbacks);
return set_player_ctx(1LL, 0LL);
}

original_code:
void set_hot_seat_mode() {
   set_players();
   set_player_func_list(0, &player_callbacks);
   set_player_ctx(0, ((void *)0));
   set_player_func_list(1, &player_callbacks);
   set_player_ctx(1, ((void *)0));
}

return_type: void


decompiled_code:
__int64 set_computer_oponent_mode()
{
__int64 v0; // rax

set_players();
set_player_func_list(0LL, &player_callbacks);
set_player_ctx(0LL, 0LL);
set_player_func_list(1LL, &ai_callbacks);
set_player_ctx(1LL, &g_ai_data);
v0 = ((__int64 (__fastcall *)(__int64))io_func[2])(9LL);
return set_player_name(1LL, v0);
}

canonical_decompiled_code:
__int64 func9()
{
__int64 v0; // rax

set_players();
set_player_func_list(0LL, &player_callbacks);
set_player_ctx(0LL, 0LL);
set_player_func_list(1LL, &ai_callbacks);
set_player_ctx(1LL, &g_ai_data);
v0 = ((__int64 (__fastcall *)(__int64))io_func[2])(9LL);
return set_player_name(1LL, v0);
}

original_code:
void set_computer_oponent_mode() {
   set_players();
   set_player_func_list(0, &player_callbacks);
   set_player_ctx(0, ((void *)0));
   set_player_func_list(1, &ai_callbacks);
   set_player_ctx(1, (void *) &g_ai_data);
   set_player_name(1, io_func.get_code_str(DEFAULT_AI_NAME));
}


original_code:
uint8_t show_start_menu() {
   menu_item_t main_item = { .id = NONE, .type = MENU_ITEM_CLICKABLE,
      .data = (void *) &main_menu };
   return show_simple_menu(&main_item);
}

canonical_original_code:
unsigned char show_start_menu() {
   struct menu_item main_item = { .id = NONE, .type = MENU_ITEM_CLICKABLE,
      .data = (void *) &main_menu };
   return show_simple_menu(&main_item);
}

variable_types: struct menu_item { unsigned char id; char *(*get_title)(); enum menu_item_type_t { MENU_ITEM_CLICKABLE=0, MENU_ITEM_EDITABLE=1, MENU_ITEM_TEXT=2 } type; unsigned char (*action)(struct menu_item *); void *data; }


original_code:
uint8_t show_finish_menu() {
   menu_item_t finish_item = { .id = NONE, .type = MENU_ITEM_CLICKABLE,
         .data = (void *) &finish_menu };
   return show_simple_menu(&finish_item);
}

canonical_original_code:
unsigned char show_finish_menu() {
   struct menu_item finish_item = { .id = NONE, .type = MENU_ITEM_CLICKABLE,
         .data = (void *) &finish_menu };
   return show_simple_menu(&finish_item);
}


decompiled_code:
__int64 show_context_menu()
{
__int64 v1[7]; // [rsp+0h] [rbp-38h] BYREF

v1[0] = 18LL;
v1[1] = 0LL;
v1[2] = 0LL;
v1[3] = 0LL;
v1[4] = (__int64)&context_menu;
return show_simple_menu((__int64)v1);
}

original_code:
uint8_t show_context_menu() {
   menu_item_t context_item = { .id = NONE, .type = MENU_ITEM_CLICKABLE,
         .data = (void *) &context_menu };
   return show_simple_menu(&context_item);
}

canonical_original_code:
unsigned char show_context_menu() {
   struct menu_item context_item = { .id = NONE, .type = MENU_ITEM_CLICKABLE,
         .data = (void *) &context_menu };
   return show_simple_menu(&context_item);
}


decompiled_code:
__int64 __fastcall is_input_correct(unsigned __int8 a1, __int64 a2)
{
__int64 result; // rax

if ( !a1 || (result = 1LL, *(_BYTE *)(a2 + 1) < a1) )
{
puts("Error in menu, item is unknown");
result = 0LL;
}
return result;
}

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

if ( !a1 || (result = 1LL, *(_BYTE *)(a2 + 1) < a1) )
{
puts("Error in menu, item is unknown");
result = 0LL;
}
return result;
}

original_code:
static uint8_t is_input_correct(uint8_t input, menu_list_t const *cur_menu) {
   if (input > 0 && input <= cur_menu->action_item_num)
      return 1;
   printf("Error in menu, item is unknown\n");
   return 0;
}

canonical_original_code:
static unsigned char is_input_correct(unsigned char input, struct menu_list_t *cur_menu) {
   if (input > 0 && input <= cur_menu->action_item_num)
      return 1;
   printf("Error in menu, item is unknown\n");
   return 0;
}


decompiled_code:
__int64 get_ushort_from_input()
{
unsigned int v0; // ebp
int v1; // ebx

v0 = 0;
while ( 1 )
{
v1 = getchar();
if ( (_BYTE)v1 == 10 )
break;
if ( ((*_ctype_b_loc())[(unsigned __int8)v1] & 0x800) != 0 )
{
v0 = v1 + 10 * v0 - 48;
}
else
{
clear_input("Please enter only digit signs\n");
if ( (_BYTE)v1 == 27 )
{
skip_sign = 1;
return 0;
}
v0 = 0;
}
}
return v0;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // ebp
int v1; // ebx

v0 = 0;
while ( 1 )
{
v1 = getchar();
if ( (_BYTE)v1 == 10 )
break;
if ( ((*_ctype_b_loc())[(unsigned __int8)v1] & 0x800) != 0 )
{
v0 = v1 + 10 * v0 - 48;
}
else
{
func1("Please enter only digit signs\n");
if ( (_BYTE)v1 == 27 )
{
skip_sign = 1;
return 0;
}
v0 = 0;
}
}
return v0;
}

original_code:
static uint8_t get_ushort_from_input() {
   uint8_t choice = 0, ch;
   while ((ch = getchar()) != '\n') {
      if (!((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short int) _ISdigit)) {
         clear_input("Please enter only digit signs\n");
         choice = 0;
         if (ch == 27) {
            skip_sign = 1;
            return 0;
         }
         continue;
      }
      if (choice * 10 + (ch - 48) > (0x7fff * 2 + 1)) {
         clear_input("Entered choice is too long\n");
         choice = 0;
         continue;
      }
      choice = choice * 10 + (ch - 48);
   }
   return choice;
}

canonical_original_code:
static unsigned char get_ushort_from_input() {
   unsigned char choice = 0; unsigned char ch;
   while ((ch = getchar()) != '\n') {
      if (!((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short) _ISdigit)) {
         clear_input("Please enter only digit signs\n");
         choice = 0;
         if (ch == 27) {
            skip_sign = 1;
            return 0;
         }
         continue;
      }
      if (choice * 10 + (ch - 48) > (0x7fff * 2 + 1)) {
         clear_input("Entered choice is too long\n");
         choice = 0;
         continue;
      }
      choice = choice * 10 + (ch - 48);
   }
   return choice;
}

variable_types:
choice
unsigned char

variable_types:
ch
unsigned char


decompiled_code:
__int64 __fastcall choice2item(char a1, _BYTE *a2)
{
char v2; // al
int v3; // ecx
_DWORD *v4; // rsi
int v5; // ebx
char v6; // dl

v2 = a1;
v3 = (unsigned __int8)*a2;
if ( a1 && *a2 )
{
v4 = a2 + 32;
v5 = 0;
do
{
v6 = *v4 != 2;
++v5;
v4 += 10;
v2 -= v6;
}
while ( v2 && v5 < v3 );
}
else
{
v5 = 0;
}
if ( v2 )
set_error("menu items error", 16LL);
return (unsigned int)(v5 - 1);
}

canonical_decompiled_code:
__int64 __fastcall func3(char a1, _BYTE *a2)
{
char v2; // al
int v3; // ecx
_DWORD *v4; // rsi
int v5; // ebx
char v6; // dl

v2 = a1;
v3 = (unsigned __int8)*a2;
if ( a1 && *a2 )
{
v4 = a2 + 32;
v5 = 0;
do
{
v6 = *v4 != 2;
++v5;
v4 += 10;
v2 -= v6;
}
while ( v2 && v5 < v3 );
}
else
{
v5 = 0;
}
if ( v2 )
set_error("menu items error", 16LL);
return (unsigned int)(v5 - 1);
}

original_code:
static uint8_t choice2item(uint8_t choice, menu_list_t const *cur_menu) {
   int i;
   for (i = 0; i < cur_menu->size && choice; i++) {
      if (cur_menu->menu[i].type != MENU_ITEM_TEXT)
         choice--;
   }
   if (choice != 0)
      set_error("menu items error", strlen("menu items error"));
   return i - 1;
}

canonical_original_code:
static unsigned char choice2item(unsigned char choice, struct menu_list_t *cur_menu) {
   int i;
   for (i = 0; i < cur_menu->size && choice; i++) {
      if (cur_menu->menu[i].type != MENU_ITEM_TEXT)
         choice--;
   }
   if (choice != 0)
      set_error("menu items error", strlen("menu items error"));
   return i - 1;
}

variable_types: i int


decompiled_code:
char *__fastcall get_code_str(unsigned __int8 a1)
{
return output_code_table[a1];
}

canonical_decompiled_code:
char *__fastcall func4(unsigned __int8 a1)
{
return output_code_table[a1];
}

original_code:
char const * get_code_str(uint8_t code) {
   return output_code_table[code];
}

canonical_original_code:
char *get_code_str(unsigned char code) {
   return output_code_table[code];
}

variable_types:
code
unsigned char


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

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

original_code: uint8_t init_io() { return 0; }

canonical_original_code: unsigned char init_io() { return 0; }


decompiled_code:
void clear_io()
{
;
}

canonical_decompiled_code:
void func6()
{
;
}

original_code: void clear_io() { }

canonical_original_code: void clear_io() { }


decompiled_code:
int __fastcall show_menu(_BYTE *a1)
{
int result; // eax
unsigned __int8 *v2; // rbx
int v3; // ebp
int v4; // er12
int v5; // eax
const char *v6; // rax
char v7[296]; // [rsp+0h] [rbp-128h] BYREF

result = system("clear");
if ( *a1 )
{
v2 = a1 + 16;
v3 = 0;
v4 = 1;
do
{
v5 = *((_DWORD *)v2 + 4);
if ( v5 == 1 )
{
v6 = (const char *)(*((__int64 (**)(void))v2 + 1))();
snprintf(v7, 0x100uLL, "%d) %s\n", (unsigned __int8)v4++, v6);
}
else if ( v5 == 2 )
{
snprintf(v7, 0x100uLL, "%s\n", output_code_table[*v2]);
}
else if ( v5 )
{
snprintf(v7, 0x100uLL, "%s\n", "item not supported");
}
else
{
snprintf(v7, 0x100uLL, "%d) %s\n", (unsigned __int8)v4++, output_code_table[*v2]);
}
printf("%s", v7);
++v3;
v2 += 40;
result = (unsigned __int8)*a1;
}
while ( result > v3 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(_BYTE *a1)
{
int result; // eax
unsigned __int8 *v2; // rbx
int v3; // ebp
int v4; // er12
int v5; // eax
const char *v6; // rax
char v7[296]; // [rsp+0h] [rbp-128h] BYREF

result = system("clear");
if ( *a1 )
{
v2 = a1 + 16;
v3 = 0;
v4 = 1;
do
{
v5 = *((_DWORD *)v2 + 4);
if ( v5 == 1 )
{
v6 = (const char *)(*((__int64 (**)(void))v2 + 1))();
snprintf(v7, 0x100uLL, "%d) %s\n", (unsigned __int8)v4++, v6);
}
else if ( v5 == 2 )
{
snprintf(v7, 0x100uLL, "%s\n", output_code_table[*v2]);
}
else if ( v5 )
{
snprintf(v7, 0x100uLL, "%s\n", "item not supported");
}
else
{
snprintf(v7, 0x100uLL, "%d) %s\n", (unsigned __int8)v4++, output_code_table[*v2]);
}
printf("%s", v7);
++v3;
v2 += 40;
result = (unsigned __int8)*a1;
}
while ( result > v3 );
}
return result;
}

original_code:
void show_menu(menu_list_t const *list) {
   uint8_t num = 1;
   char item_msg[256];
   system("clear");
   for (int ind = 0; ind < list->size; ind++) {
      switch (list->menu[ind].type) {
         case MENU_ITEM_CLICKABLE:
            snprintf(item_msg, 256, "%d) %s\n", num++,
               output_code_table[list->menu[ind].id]);
            break;
         case MENU_ITEM_EDITABLE:
            snprintf(item_msg, 256, "%d) %s\n", num++,
               list->menu[ind].get_title());
            break;
         case MENU_ITEM_TEXT:
            snprintf(item_msg, 256, "%s\n",
               output_code_table[list->menu[ind].id]);
            break;
         default:
            snprintf(item_msg, 256, "%s\n",
               "item not supported");
      }
      printf("%s", item_msg);
   }
}

canonical_original_code:
void show_menu(struct menu_list_t *list) {
   unsigned char num = 1;
   char item_msg[256];
   system("clear");
   for (int ind = 0; ind < list->size; ind++) {
      switch (list->menu[ind].type) {
         case MENU_ITEM_CLICKABLE:
            snprintf(item_msg, 256, "%d) %s\n", num++,
               output_code_table[list->menu[ind].id]);
            break;
         case MENU_ITEM_EDITABLE:
            snprintf(item_msg, 256, "%d) %s\n", num++,
               list->menu[ind].get_title());
            break;
         case MENU_ITEM_TEXT:
            snprintf(item_msg, 256, "%s\n",
               output_code_table[list->menu[ind].id]);
            break;
         default:
            snprintf(item_msg, 256, "%s\n",
               "item not supported");
      }
      printf("%s", item_msg);
   }
}

variable_types:
num
unsigned char

variable_types: ind int


original_code:
void show_field(uint8_t **field, point_t const *size) {
   char output[3];
   char *delimeter;
   int32_t i,j;
   delimeter = (char *) malloc(size->x * 2 * sizeof(char) + 2);
   for (i = 0; i < size->x * 2 - 1; i++)
      delimeter[i] = '-';
   delimeter[i] = '\n';
   delimeter[i + 1] = '\0';
   system("clear");
   for (i = 0; i < size->y; i++) {
      for (j = 0; j < size->x; j++) {
         snprintf(output, 3, "%s%c", ttt_code_table[field[i][j]],
            j == size->x - 1 ? '\n' : '|');
         printf("%s", output);
      }
      if (i != size->y - 1)
         printf("%s", delimeter);
   }
   free(delimeter);
}

canonical_original_code:
void show_field(unsigned char **field, struct point_t *size) {
   char output[3];
   char *delimeter;
   int i; int j;
   delimeter = (char *) malloc(size->x * 2 * sizeof(char) + 2);
   for (i = 0; i < size->x * 2 - 1; i++)
      delimeter[i] = '-';
   delimeter[i] = '\n';
   delimeter[i + 1] = '\0';
   system("clear");
   for (i = 0; i < size->y; i++) {
      for (j = 0; j < size->x; j++) {
         snprintf(output, 3, "%s%c", ttt_code_table[field[i][j]],
            j == size->x - 1 ? '\n' : '|');
         printf("%s", output);
      }
      if (i != size->y - 1)
         printf("%s", delimeter);
   }
   free(delimeter);
}

variable_types:
field
unsigned char **

variable_types: struct point_t { unsigned char x; unsigned char y; } *

variable_types:
output
char [3]

variable_types:
delimeter
char *

variable_types: j int


decompiled_code:
__int64 __fastcall get_menu_input(_BYTE *a1)
{
unsigned __int8 i; // al
char v2; // bl

puts("Enter your choice");
for ( i = get_ushort_from_input(); ; i = get_ushort_from_input() )
{
v2 = i;
if ( (unsigned __int8)is_input_correct(i, (__int64)a1) )
{
if ( !skip_sign )
break;
}
skip_sign = 0;
}
return choice2item(v2, a1);
}

canonical_decompiled_code:
__int64 __fastcall func10(_BYTE *a1)
{
unsigned __int8 i; // al
char v2; // bl

puts("Enter your choice");
for ( i = func2(); ; i = func2() )
{
v2 = i;
if ( (unsigned __int8)func0(i, (__int64)a1) )
{
if ( !skip_sign )
break;
}
skip_sign = 0;
}
return func3(v2, a1);
}

original_code:
uint8_t get_menu_input(menu_list_t const *cur_menu) {
   uint8_t choice;
   uint8_t item;
   printf("%s", "Enter your choice\n");
   choice = get_ushort_from_input();
   while (!is_input_correct(choice, cur_menu) || skip_sign) {
      skip_sign = 0;
      choice = get_ushort_from_input();
   }
   item = choice2item(choice, cur_menu);
   return item;
}

canonical_original_code:
unsigned char get_menu_input(struct menu_list_t *cur_menu) {
   unsigned char choice;
   unsigned char item;
   printf("%s", "Enter your choice\n");
   choice = get_ushort_from_input();
   while (!is_input_correct(choice, cur_menu) || skip_sign) {
      skip_sign = 0;
      choice = get_ushort_from_input();
   }
   item = choice2item(choice, cur_menu);
   return item;
}

variable_types:
item
unsigned char


decompiled_code:
char *__fastcall get_string_input(unsigned __int8 *a1, char *a2)
{
char *result; // rax

if ( (unsigned int)*a1 - 7 <= 1 )
printf("Enter %s's new name\n", output_code_table[*a1]);
else
printf("Error in menu, item is unknown\n");
fgets(a2, 256, stdin);
result = &a2[strlen(a2) - 1];
if ( *result == 10 )
*result = 0;
return result;
}

canonical_decompiled_code:
char *__fastcall func11(unsigned __int8 *a1, char *a2)
{
char *result; // rax

if ( (unsigned int)*a1 - 7 <= 1 )
printf("Enter %s's new name\n", output_code_table[*a1]);
else
printf("Error in menu, item is unknown\n");
fgets(a2, 256, stdin);
result = &a2[strlen(a2) - 1];
if ( *result == 10 )
*result = 0;
return result;
}

original_code:
void get_string_input(menu_item_t const *menu, char *message) {
   switch (menu->id) {
      case DEFAULT_PLAYER_NAME1:
      case DEFAULT_PLAYER_NAME2:
         printf("Enter %s's new name\n", output_code_table[menu->id]);
         break;
      default:
         printf("Error in menu, item is unknown\n", output_code_table[menu->id]);
   }
   fgets(message, 256, stdin);
   if (message[strlen(message) - 1] == '\n')
      message[strlen(message) - 1] = '\0';
}

canonical_original_code:
void get_string_input(struct menu_item *menu, char *message) {
   switch (menu->id) {
      case DEFAULT_PLAYER_NAME1:
      case DEFAULT_PLAYER_NAME2:
         printf("Enter %s's new name\n", output_code_table[menu->id]);
         break;
      default:
         printf("Error in menu, item is unknown\n", output_code_table[menu->id]);
   }
   fgets(message, 256, stdin);
   if (message[strlen(message) - 1] == '\n')
      message[strlen(message) - 1] = '\0';
}

variable_types:
message
char *


decompiled_code:
int __fastcall show_error(const char *a1)
{
printf("\nERROR: %s\nPress any key to exit\n", a1);
return getchar();
}

canonical_decompiled_code:
int __fastcall func13(const char *a1)
{
printf("\nERROR: %s\nPress any key to exit\n", a1);
return getchar();
}

original_code:
void show_error(char *msg) {
   printf("\nERROR: %s\nPress any key to exit\n", msg);
   getchar();
}

variable_types:
msg
char *


decompiled_code:
__int64 __fastcall check_and_apply_last_move(_QWORD *a1, __int64 a2, _BYTE *a3, char a4)
{
__int64 v6; // rdx
__int64 v7; // rax
unsigned __int8 v9; // [rsp+Eh] [rbp-2Ah] BYREF
unsigned __int8 v10; // [rsp+Fh] [rbp-29h]

rule_func(&v9);
if ( !v10 )
return 0LL;
v6 = 0LL;
while ( !v9 )
{
LABEL_8:
++v6;
++a1;
if ( v10 <= (int)v6 )
return 0LL;
}
v7 = 0LL;
while ( *(_BYTE *)(*(_QWORD *)(a2 + 8 * v6) + v7) == *(_BYTE *)(*a1 + v7) )
{
if ( v9 <= (int)++v7 )
goto LABEL_8;
}
*a3 = v7;
a3[1] = v6;
*(_BYTE *)(*a1 + v7) = a4;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, __int64 a2, _BYTE *a3, char a4)
{
__int64 v6; // rdx
__int64 v7; // rax
unsigned __int8 v9; // [rsp+Eh] [rbp-2Ah] BYREF
unsigned __int8 v10; // [rsp+Fh] [rbp-29h]

rule_func(&v9);
if ( !v10 )
return 0LL;
v6 = 0LL;
while ( !v9 )
{
LABEL_8:
++v6;
++a1;
if ( v10 <= (int)v6 )
return 0LL;
}
v7 = 0LL;
while ( *(_BYTE *)(*(_QWORD *)(a2 + 8 * v6) + v7) == *(_BYTE *)(*a1 + v7) )
{
if ( v9 <= (int)++v7 )
goto LABEL_8;
}
*a3 = v7;
a3[1] = v6;
*(_BYTE *)(*a1 + v7) = a4;
return 1LL;
}

original_code:
static uint8_t check_and_apply_last_move(uint8_t **old_field,
      uint8_t const **new_field, point_t *move, uint8_t item) {
   point_t size;
   rule_func.get_field_size(&size);
   for (int i = 0; i < size.y; i++) {
      for (int j = 0; j < size.x; j++) {
         if (new_field[i][j] == old_field[i][j])
            continue;
         move->x = j; move->y = i;;
         old_field[i][j] = item;
         return 1;
      }
   }
   return 0;
}

canonical_original_code:
static unsigned char check_and_apply_last_move(unsigned char **old_field, unsigned char **new_field, struct point_t *move, unsigned char item) {
   struct point_t size;
   rule_func.get_field_size(&size);
   for (int i = 0; i < size.y; i++) {
      for (int j = 0; j < size.x; j++) {
         if (new_field[i][j] == old_field[i][j])
            continue;
         move->x = j; move->y = i;;
         old_field[i][j] = item;
         return 1;
      }
   }
   return 0;
}

variable_types: struct point_t { unsigned char x; unsigned char y; }


decompiled_code:
__int64 __fastcall is_point_on_line(unsigned __int8 *a1, unsigned __int8 *a2)
{
unsigned __int8 v2; // al
unsigned __int8 v3; // dl
unsigned __int8 v4; // cl
unsigned __int8 v5; // di

v2 = *a1;
v3 = *a2;
if ( *a1 == *a2 )
{
LOBYTE(a2) = a1[1] != a2[1];
}
else
{
v4 = a1[1];
v5 = a2[1];
LODWORD(a2) = 1;
if ( v4 != v5 )
{
if ( v3 == v5 && v2 == v4 )
{
LODWORD(a2) = 1;
}
else
{
LODWORD(a2) = 0;
if ( v4 + v2 == 2 )
LOBYTE(a2) = v5 + v3 == 2;
}
}
}
return (unsigned int)a2;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int8 *a1, unsigned __int8 *a2)
{
unsigned __int8 v2; // al
unsigned __int8 v3; // dl
unsigned __int8 v4; // cl
unsigned __int8 v5; // di

v2 = *a1;
v3 = *a2;
if ( *a1 == *a2 )
{
LOBYTE(a2) = a1[1] != a2[1];
}
else
{
v4 = a1[1];
v5 = a2[1];
LODWORD(a2) = 1;
if ( v4 != v5 )
{
if ( v3 == v5 && v2 == v4 )
{
LODWORD(a2) = 1;
}
else
{
LODWORD(a2) = 0;
if ( v4 + v2 == 2 )
LOBYTE(a2) = v5 + v3 == 2;
}
}
}
return (unsigned int)a2;
}

original_code:
static uint8_t is_point_on_line(point_t const *first, point_t const *second) {
   if (first->x == second->x && first->y == second->y)
      return 0;
   else if (first->x == second->x || first->y == second->y)
      return 1;
   else if (first->x - first->y == 0 && second->x - second->y == 0)
      return 1;
   else if (first->x + first->y == 2 && second->x + second->y == 2)
      return 1;
   return 0;
}

canonical_original_code:
static unsigned char is_point_on_line(struct point_t *first, struct point_t *second) {
   if (first->x == second->x && first->y == second->y)
      return 0;
   else if (first->x == second->x || first->y == second->y)
      return 1;
   else if (first->x - first->y == 0 && second->x - second->y == 0)
      return 1;
   else if (first->x + first->y == 2 && second->x + second->y == 2)
      return 1;
   return 0;
}

variable_types:
second
struct point_t *

user_defined_types: struct point_t { unsigned char x; unsigned char y; }


original_code:
void init_data(player_ent_t *ctx) {
   point_t size;
   uint8_t **mark_field;
   uint8_t **own_field;
   ai_data_t *ai_ctx = (ai_data_t *) ctx->player_ctx;
   uint8_t item = (ctx == g_player[0] ? CROSS : NOUGHT);
   if (is_data_init)
      return;
   is_data_init = 1;
   rule_func.get_field_size(&size);
   mark_field = (uint8_t **) calloc(size.y, sizeof(uint8_t *));
   own_field = (uint8_t **) calloc(size.y, sizeof(uint8_t *));
   for (int i = 0; i < size.y; i++) {
      mark_field[i] = (uint8_t *) calloc(size.x, sizeof(uint8_t));
      own_field[i] = (uint8_t *) calloc(size.x, sizeof(uint8_t));
      for (int j = 0; j < size.x; j++) {
         if (i == 1 && j == 1)
            mark_field[i][j] = (item == CROSS ? 1 : 50);
         else if (i == 1 || j == 1)
            mark_field[i][j] = (item == CROSS ? 1 : 1);
         else
            mark_field[i][j] = (item == CROSS ? 12 : 25);
      }
   }
   ai_ctx->marked_fld = mark_field;
   ai_ctx->own_fld = own_field;
}

canonical_original_code:
void init_data(struct player_ent_t *ctx) {
   struct point_t size;
   unsigned char **mark_field;
   unsigned char **own_field;
   struct ai_data_t *ai_ctx = (ai_data_t *) ctx->player_ctx;
   unsigned char item = (ctx == g_player[0] ? CROSS : NOUGHT);
   if (is_data_init)
      return;
   is_data_init = 1;
   rule_func.get_field_size(&size);
   mark_field = (unsigned char **) calloc(size.y, sizeof(unsigned char *));
   own_field = (unsigned char **) calloc(size.y, sizeof(unsigned char *));
   for (int i = 0; i < size.y; i++) {
      mark_field[i] = (unsigned char *) calloc(size.x, sizeof(unsigned char));
      own_field[i] = (unsigned char *) calloc(size.x, sizeof(unsigned char));
      for (int j = 0; j < size.x; j++) {
         if (i == 1 && j == 1)
            mark_field[i][j] = (item == CROSS ? 1 : 50);
         else if (i == 1 || j == 1)
            mark_field[i][j] = (item == CROSS ? 1 : 1);
         else
            mark_field[i][j] = (item == CROSS ? 12 : 25);
      }
   }
   ai_ctx->marked_fld = mark_field;
   ai_ctx->own_fld = own_field;
}

variable_types: struct player_ent_t { struct player_func_list { void (*init_player)(struct player_ent_t *); int (*get_player_input)(struct point_t { unsigned char x; unsigned char y; } *, struct player_ent_t *); void (*clear_data)(struct player_ent_t *); } *func_list; char name[256]; void *player_ctx; } *

variable_types: struct ai_data_t { unsigned char **marked_fld; unsigned char **own_fld; } *

user_defined_types: struct player_ent_t { struct player_func_list *func_list; char name[256]; void *player_ctx; }

user_defined_types: struct player_func_list { void (*init_player)(struct player_ent_t *); int (*get_player_input)(struct point_t *, struct player_ent_t *); void (*clear_data)(struct player_ent_t *); }


original_code:
int make_move(point_t *move, player_ent_t const *ctx) {
   point_t size, op_prev_move;
   uint8_t found_move = 0;
   ai_data_t *ai_ctx = (ai_data_t *) ctx->player_ctx;
   rule_func.get_field_size(&size);
   if (check_and_apply_last_move(ai_ctx->own_fld,
      (uint8_t const **)rule_func.get_field(), &op_prev_move,
      (ctx == g_player[0] ? NOUGHT : CROSS))) {
      recalculate_values((uint8_t const **) ai_ctx->own_fld, ai_ctx->marked_fld,
         &op_prev_move, 0);
   }
   for (int i = 0; i < size.y; i++) {
      for (int j = 0; j < size.x; j++) {
         if (!found_move && ai_ctx->own_fld[i][j] == EMPTY) {
            move->x = j; move->y = i;;
            found_move = 1;
         }
         else if (found_move && ai_ctx->marked_fld[move->y][move->x] <
            ai_ctx->marked_fld[i][j]) {
            move->x = j; move->y = i;;
         }
      }
   }
   if (found_move) {
      ai_ctx->own_fld[move->y][move->x] = (ctx == g_player[0] ? CROSS : NOUGHT);
      recalculate_values((uint8_t const **) ai_ctx->own_fld, ai_ctx->marked_fld,
         move, 1);
   }
   if (!found_move)
      set_error("ai error, no move found", strlen("ai error, no move found"));
   return 1;
}

canonical_original_code:
int make_move(struct point_t *move, struct player_ent_t *ctx) {
   struct point_t size; struct point_t op_prev_move;
   unsigned char found_move = 0;
   struct ai_data_t *ai_ctx = (ai_data_t *) ctx->player_ctx;
   rule_func.get_field_size(&size);
   if (check_and_apply_last_move(ai_ctx->own_fld,
      (unsigned char **)rule_func.get_field(), &op_prev_move,
      (ctx == g_player[0] ? NOUGHT : CROSS))) {
      recalculate_values((unsigned char **) ai_ctx->own_fld, ai_ctx->marked_fld,
         &op_prev_move, 0);
   }
   for (int i = 0; i < size.y; i++) {
      for (int j = 0; j < size.x; j++) {
         if (!found_move && ai_ctx->own_fld[i][j] == EMPTY) {
            move->x = j; move->y = i;;
            found_move = 1;
         }
         else if (found_move && ai_ctx->marked_fld[move->y][move->x] <
            ai_ctx->marked_fld[i][j]) {
            move->x = j; move->y = i;;
         }
      }
   }
   if (found_move) {
      ai_ctx->own_fld[move->y][move->x] = (ctx == g_player[0] ? CROSS : NOUGHT);
      recalculate_values((unsigned char **) ai_ctx->own_fld, ai_ctx->marked_fld,
         move, 1);
   }
   if (!found_move)
      set_error("ai error, no move found", strlen("ai error, no move found"));
   return 1;
}

variable_types: struct player_ent_t { struct player_func_list { void (*init_player)(struct player_ent_t *); int (*get_player_input)(struct point_t *, struct player_ent_t *); void (*clear_data)(struct player_ent_t *); } *func_list; char name[256]; void *player_ctx; } *

return_type: int

user_defined_types: struct ai_data_t { unsigned char **marked_fld; unsigned char **own_fld; }


decompiled_code:
void __fastcall clear_data(__int64 a1)
{
void **v1; // rbp
__int64 v2; // rbx
char v3; // [rsp+0h] [rbp-1Ah] BYREF
unsigned __int8 v4; // [rsp+1h] [rbp-19h]

if ( is_data_init )
{
v1 = *(void ***)(a1 + 264);
is_data_init = 0;
rule_func(&v3);
if ( v4 )
{
v2 = 0LL;
do
{
free(*((void **)*v1 + v2));
free(*((void **)v1[1] + v2++));
}
while ( v4 > (int)v2 );
}
free(*v1);
free(v1[1]);
}
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1)
{
void **v1; // rbp
__int64 v2; // rbx
char v3; // [rsp+0h] [rbp-1Ah] BYREF
unsigned __int8 v4; // [rsp+1h] [rbp-19h]

if ( is_data_init )
{
v1 = *(void ***)(a1 + 264);
is_data_init = 0;
rule_func(&v3);
if ( v4 )
{
v2 = 0LL;
do
{
free(*((void **)*v1 + v2));
free(*((void **)v1[1] + v2++));
}
while ( v4 > (int)v2 );
}
free(*v1);
free(v1[1]);
}
}

original_code:
void clear_data(player_ent_t *ctx) {
   point_t size;
   ai_data_t *ai_ctx = (ai_data_t *) ctx->player_ctx;
   if (!is_data_init)
      return;
   is_data_init = 0;
   rule_func.get_field_size(&size);
   for (int i = 0; i < size.y; i++) {
      free(ai_ctx->marked_fld[i]);
      free(ai_ctx->own_fld[i]);
   }
   free(ai_ctx->marked_fld);
   free(ai_ctx->own_fld);
}

canonical_original_code:
void clear_data(struct player_ent_t *ctx) {
   struct point_t size;
   struct ai_data_t *ai_ctx = (ai_data_t *) ctx->player_ctx;
   if (!is_data_init)
      return;
   is_data_init = 0;
   rule_func.get_field_size(&size);
   for (int i = 0; i < size.y; i++) {
      free(ai_ctx->marked_fld[i]);
      free(ai_ctx->own_fld[i]);
   }
   free(ai_ctx->marked_fld);
   free(ai_ctx->own_fld);
}

variable_types: i int


decompiled_code:
void set_players()
{
g_player = (__int64)&player_ent1;
*(&g_player + 1) = (__int64)&player_ent2;
}

canonical_decompiled_code:
void func0()
{
g_player = (__int64)&player_ent1;
*(&g_player + 1) = (__int64)&player_ent2;
}

original_code:
void set_players() {
   g_player[0] = &player_ent1;
   g_player[1] = &player_ent2;
}


decompiled_code:
void *switch_players()
{
void *v0; // rax
void *result; // rax

v0 = &player_ent2;
if ( (_UNKNOWN *)g_player != &player_ent1 )
v0 = &player_ent1;
g_player = (__int64)v0;
result = &player_ent1;
if ( (_UNKNOWN *)*(&g_player + 1) != &player_ent2 )
result = &player_ent2;
*(&g_player + 1) = (__int64)result;
return result;
}

canonical_decompiled_code:
void *func1()
{
void *v0; // rax
void *result; // rax

v0 = &player_ent2;
if ( (_UNKNOWN *)g_player != &player_ent1 )
v0 = &player_ent1;
g_player = (__int64)v0;
result = &player_ent1;
if ( (_UNKNOWN *)*(&g_player + 1) != &player_ent2 )
result = &player_ent2;
*(&g_player + 1) = (__int64)result;
return result;
}

original_code:
void switch_players() {
   g_player[0] = g_player[0] == &player_ent1 ? &player_ent2 : &player_ent1;
   g_player[1] = g_player[1] == &player_ent2 ? &player_ent1 : &player_ent2;
}


decompiled_code:
int __fastcall set_player_name(unsigned __int8 a1, const char *a2)
{
return snprintf((char *)(g_player[a1] + 8), 0x100uLL, "%s", a2);
}

canonical_decompiled_code:
int __fastcall func2(unsigned __int8 a1, const char *a2)
{
return snprintf((char *)(g_player[a1] + 8), 0x100uLL, "%s", a2);
}

original_code:
void set_player_name(uint8_t player_id, char const *value) {
   snprintf(g_player[player_id]->name, 256, "%s", value);
}

canonical_original_code:
void set_player_name(unsigned char player_id, char *value) {
   snprintf(g_player[player_id]->name, 256, "%s", value);
}

variable_types:
value
char *


decompiled_code:
__int64 __fastcall set_player_ctx(unsigned __int8 a1, __int64 a2)
{
__int64 result; // rax

result = g_player[a1];
*(_QWORD *)(result + 264) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int8 a1, __int64 a2)
{
__int64 result; // rax

result = g_player[a1];
*(_QWORD *)(result + 264) = a2;
return result;
}

original_code:
void set_player_ctx(uint8_t player_id, void *ctx) {
   g_player[player_id]->player_ctx = ctx;
}

canonical_original_code:
void set_player_ctx(unsigned char player_id, void *ctx) {
   g_player[player_id]->player_ctx = ctx;
}

variable_types:
ctx
void *


decompiled_code:
__int64 __fastcall get_player_name(unsigned __int8 a1)
{
return g_player[a1] + 8;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int8 a1)
{
return g_player[a1] + 8;
}

original_code:
char const *get_player_name(uint8_t player_id) {
   return g_player[player_id]->name;
}

canonical_original_code:
char *get_player_name(unsigned char player_id) {
   return g_player[player_id]->name;
}


decompiled_code:
__int64 __fastcall get_player_func_list(unsigned __int8 a1)
{
return *(_QWORD *)g_player[a1];
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int8 a1)
{
return *(_QWORD *)g_player[a1];
}

original_code:
player_func_list_t const *get_player_func_list(uint8_t player_id) {
   return g_player[player_id]->func_list;
}

canonical_original_code:
struct player_func_list *get_player_func_list(unsigned char player_id) {
   return g_player[player_id]->func_list;
}

return_type: struct player_func_list { void (*init_player)(struct player_ent_t { struct player_func_list *func_list; char name[256]; void *player_ctx; } *); int (*get_player_input)(struct point_t { unsigned char x; unsigned char y; } *, struct player_ent_t *); void (*clear_data)(struct player_ent_t *); } *


decompiled_code:
__int64 __fastcall get_player_ctx(unsigned __int8 a1)
{
return *(_QWORD *)(g_player[a1] + 264);
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int8 a1)
{
return *(_QWORD *)(g_player[a1] + 264);
}

original_code:
void *get_player_ctx(uint8_t player_id) {
   return g_player[player_id]->player_ctx;
}

canonical_original_code:
void *get_player_ctx(unsigned char player_id) {
   return g_player[player_id]->player_ctx;
}

return_type: void *


decompiled_code:
int __fastcall set_error(const char *a1, unsigned __int8 a2)
{
size_t v2; // rax

error = 1;
v2 = a2 + 1LL;
if ( a2 == 0xFF )
v2 = 256LL;
return snprintf(err_msg, v2, "%s", a1);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1, unsigned __int8 a2)
{
size_t v2; // rax

error = 1;
v2 = a2 + 1LL;
if ( a2 == 0xFF )
v2 = 256LL;
return snprintf(err_msg, v2, "%s", a1);
}

original_code:
void set_error(const char *msg, uint8_t len) {
   error = 1;
   snprintf(err_msg, len + 1 < 256 ? len + 1 :
      256, "%s", msg);
}

canonical_original_code:
void set_error(char *msg, unsigned char len) {
   error = 1;
   snprintf(err_msg, len + 1 < 256 ? len + 1 :
      256, "%s", msg);
}

variable_types:
len
unsigned char


decompiled_code:
void clear_error()
{
error = 0;
}

canonical_decompiled_code:
void func1()
{
error = 0;
}

original_code:
void clear_error() {
   error = 0;
}

canonical_original_code:
void clear_error() {
   error = 0;
}


decompiled_code:
__int64 is_error()
{
return (unsigned __int8)error;
}

canonical_decompiled_code:
__int64 func2()
{
return (unsigned __int8)error;
}

original_code:
uint8_t is_error() {
   return error;
}

canonical_original_code:
unsigned char is_error() {
   return error;
}


decompiled_code:
char *get_error()
{
return err_msg;
}

canonical_decompiled_code:
char *func3()
{
return err_msg;
}

original_code:
char *get_error() {
   return err_msg;
}

canonical_original_code:
char *get_error() {
   return err_msg;
}


decompiled_code:
__int64 test_mult_m_calloc()
{
__int64 v0; // rax
_QWORD *v1; // rbp
_QWORD *v2; // rbx
_QWORD *v3; // rbp
_BYTE *v4; // rax
_BYTE *v5; // rdx

tcase_fn_start("test_mult_m_calloc", "check_memory_handling.c", 56LL);
v0 = m_calloc(10LL, 8LL);
if ( v0 )
{
v1 = (_QWORD *)v0;
mark_point("check_memory_handling.c", 66LL);
v2 = v1;
v3 = v1 + 10;
LABEL_3:
v4 = (_BYTE *)m_calloc(1LL, 1000LL);
*v2 = v4;
v5 = v4 + 1000;
while ( !*v4 )
{
if ( ++v4 == v5 )
{
if ( ++v2 != v3 )
goto LABEL_3;
return m_freeall();
}
}
}
else
{
ck_assert_failed("check_memory_handling.c", 66LL, "Assertion 'memarray!=NULL' failed", "Got no memory!", 0LL);
}
ck_assert_failed("check_memory_handling.c", 73LL, "Failed", "Memory was not clear!", 0LL);
return test_small_m_calloc();
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rax
_QWORD *v1; // rbp
_QWORD *v2; // rbx
_QWORD *v3; // rbp
_BYTE *v4; // rax
_BYTE *v5; // rdx

tcase_fn_start("test_mult_m_calloc", "check_memory_handling.c", 56LL);
v0 = m_calloc(10LL, 8LL);
if ( v0 )
{
v1 = (_QWORD *)v0;
mark_point("check_memory_handling.c", 66LL);
v2 = v1;
v3 = v1 + 10;
LABEL_3:
v4 = (_BYTE *)m_calloc(1LL, 1000LL);
*v2 = v4;
v5 = v4 + 1000;
while ( !*v4 )
{
if ( ++v4 == v5 )
{
if ( ++v2 != v3 )
goto LABEL_3;
return m_freeall();
}
}
}
else
{
ck_assert_failed("check_memory_handling.c", 66LL, "Assertion 'memarray!=NULL' failed", "Got no memory!", 0LL);
}
ck_assert_failed("check_memory_handling.c", 73LL, "Failed", "Memory was not clear!", 0LL);
return func1();
}

original_code:
static void test_mult_m_calloc (int _i __attribute__ ((unused))){ tcase_fn_start ("""test_mult_m_calloc", "check_memory_handling.c", 56);
{
 void **memarray=((void *)0);
 int i=0;
 int j=0;
 memarray=m_calloc((10),sizeof(void *));
 (memarray!=((void *)0)) ? _mark_point("check_memory_handling.c", 66) : _ck_assert_failed("check_memory_handling.c", 66, "Assertion '""memarray!=NULL""' failed" ,"Got no memory!", ((void *)0));
 for(i=0; i<(10);i++) {
  memarray[i]=m_calloc(1, (1000));
  for(j=0; j<(1000);j++) {
   if (((char*) memarray[i])[j] != 0)
    _ck_assert_failed("check_memory_handling.c", 73, "Failed" ,"Memory was not clear!", ((void *)0));
  }
 }
 m_freeall();
}
}

canonical_original_code:
static void test_mult_m_calloc(int _i){ tcase_fn_start ("""test_mult_m_calloc", "check_memory_handling.c", 56);
{
 void **memarray = ((void *)0);
 int i = 0;
 int j = 0;
 memarray=m_calloc((10),sizeof(void *));
 (memarray!=((void *)0)) ? _mark_point("check_memory_handling.c", 66) : _ck_assert_failed("check_memory_handling.c", 66, "Assertion '""memarray!=NULL""' failed" ,"Got no memory!", ((void *)0));
 for(i=0; i<(10);i++) {
  memarray[i]=m_calloc(1, (1000));
  for(j=0; j<(1000);j++) {
   if (((char *) memarray[i])[j] != 0)
    _ck_assert_failed("check_memory_handling.c", 73, "Failed" ,"Memory was not clear!", ((void *)0));
  }
 }
 m_freeall();
}
}

variable_types:
memarray
void **


decompiled_code:
__int64 test_small_m_calloc()
{
__int64 v0; // rax
_BYTE *v1; // rbx
_BYTE *v2; // rax

tcase_fn_start("test_small_m_calloc", "check_memory_handling.c", 37LL);
v0 = m_calloc(100LL, 100LL);
if ( v0 )
{
v1 = (_BYTE *)v0;
mark_point("check_memory_handling.c", 44LL);
v2 = v1;
while ( !*v2 )
{
if ( ++v2 == v1 + 10000 )
return m_freeall();
}
}
else
{
ck_assert_failed("check_memory_handling.c", 44LL, "Assertion 'mem!=NULL' failed", "Got no memory!", 0LL);
}
ck_assert_failed("check_memory_handling.c", 48LL, "Failed", "Memory was not clear!", 0LL);
return test_small_calloc();
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rax
_BYTE *v1; // rbx
_BYTE *v2; // rax

tcase_fn_start("test_small_m_calloc", "check_memory_handling.c", 37LL);
v0 = m_calloc(100LL, 100LL);
if ( v0 )
{
v1 = (_BYTE *)v0;
mark_point("check_memory_handling.c", 44LL);
v2 = v1;
while ( !*v2 )
{
if ( ++v2 == v1 + 10000 )
return m_freeall();
}
}
else
{
ck_assert_failed("check_memory_handling.c", 44LL, "Assertion 'mem!=NULL' failed", "Got no memory!", 0LL);
}
ck_assert_failed("check_memory_handling.c", 48LL, "Failed", "Memory was not clear!", 0LL);
return func2();
}

original_code:
static void test_small_m_calloc (int _i __attribute__ ((unused))){ tcase_fn_start ("""test_small_m_calloc", "check_memory_handling.c", 37);
{
 void * mem=((void *)0);
 int i=0;
 mem=m_calloc(100,100);
 (mem!=((void *)0)) ? _mark_point("check_memory_handling.c", 44) : _ck_assert_failed("check_memory_handling.c", 44, "Assertion '""mem!=NULL""' failed" ,"Got no memory!", ((void *)0));
 for(i=0; i<100*100;i++) {
  if (((char*) mem)[i] != 0)
   _ck_assert_failed("check_memory_handling.c", 48, "Failed" ,"Memory was not clear!", ((void *)0));
 }
 m_freeall();
}
}

canonical_original_code:
static void test_small_m_calloc(int _i){ tcase_fn_start ("""test_small_m_calloc", "check_memory_handling.c", 37);
{
 void *mem = ((void *)0);
 int i = 0;
 mem=m_calloc(100,100);
 (mem!=((void *)0)) ? _mark_point("check_memory_handling.c", 44) : _ck_assert_failed("check_memory_handling.c", 44, "Assertion '""mem!=NULL""' failed" ,"Got no memory!", ((void *)0));
 for(i=0; i<100*100;i++) {
  if (((char *) mem)[i] != 0)
   _ck_assert_failed("check_memory_handling.c", 48, "Failed" ,"Memory was not clear!", ((void *)0));
 }
 m_freeall();
}
}

variable_types:
mem
void *


decompiled_code:
__int64 test_small_calloc()
{
__int64 v0; // rax
_BYTE *v1; // rbx
_BYTE *v2; // rax

tcase_fn_start("test_small_calloc", "check_memory_handling.c", 19LL);
v0 = mycalloc(100LL, 100LL);
if ( v0 )
{
v1 = (_BYTE *)v0;
mark_point("check_memory_handling.c", 26LL);
v2 = v1;
while ( !*v2 )
{
if ( ++v2 == v1 + 10000 )
return myfree(v1);
}
}
else
{
ck_assert_failed("check_memory_handling.c", 26LL, "Assertion 'mem!=NULL' failed", "Got no memory!", 0LL);
}
ck_assert_failed("check_memory_handling.c", 30LL, "Failed", "Memory was not clear!", 0LL);
return test_small_malloc();
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rax
_BYTE *v1; // rbx
_BYTE *v2; // rax

tcase_fn_start("test_small_calloc", "check_memory_handling.c", 19LL);
v0 = mycalloc(100LL, 100LL);
if ( v0 )
{
v1 = (_BYTE *)v0;
mark_point("check_memory_handling.c", 26LL);
v2 = v1;
while ( !*v2 )
{
if ( ++v2 == v1 + 10000 )
return myfree(v1);
}
}
else
{
ck_assert_failed("check_memory_handling.c", 26LL, "Assertion 'mem!=NULL' failed", "Got no memory!", 0LL);
}
ck_assert_failed("check_memory_handling.c", 30LL, "Failed", "Memory was not clear!", 0LL);
return func3();
}

original_code:
static void test_small_calloc (int _i __attribute__ ((unused))){ tcase_fn_start ("""test_small_calloc", "check_memory_handling.c", 19);
{
 void * mem=((void *)0);
 int i=0;
 mem=mycalloc(100,100);
 (mem!=((void *)0)) ? _mark_point("check_memory_handling.c", 26) : _ck_assert_failed("check_memory_handling.c", 26, "Assertion '""mem!=NULL""' failed" ,"Got no memory!", ((void *)0));
 for(i=0; i<100*100;i++) {
  if (((char*) mem)[i] != 0)
   _ck_assert_failed("check_memory_handling.c", 30, "Failed" ,"Memory was not clear!", ((void *)0));
 }
 myfree(mem);
}
}

canonical_original_code:
static void test_small_calloc(int _i){ tcase_fn_start ("""test_small_calloc", "check_memory_handling.c", 19);
{
 void *mem = ((void *)0);
 int i = 0;
 mem=mycalloc(100,100);
 (mem!=((void *)0)) ? _mark_point("check_memory_handling.c", 26) : _ck_assert_failed("check_memory_handling.c", 26, "Assertion '""mem!=NULL""' failed" ,"Got no memory!", ((void *)0));
 for(i=0; i<100*100;i++) {
  if (((char *) mem)[i] != 0)
   _ck_assert_failed("check_memory_handling.c", 30, "Failed" ,"Memory was not clear!", ((void *)0));
 }
 myfree(mem);
}
}


decompiled_code:
__int64 test_small_malloc()
{
__int64 v0; // rax
__int64 v1; // rbx
__int64 result; // rax

tcase_fn_start("test_small_malloc", "check_memory_handling.c", 7LL);
v0 = mymalloc(1000LL);
if ( v0 )
{
v1 = v0;
mark_point("check_memory_handling.c", 12LL);
result = myfree(v1);
}
else
{
ck_assert_failed("check_memory_handling.c", 12LL, "Assertion 'mem!=NULL' failed", "Got no memory!", 0LL);
result = memory_suite();
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rax
__int64 v1; // rbx
__int64 result; // rax

tcase_fn_start("test_small_malloc", "check_memory_handling.c", 7LL);
v0 = mymalloc(1000LL);
if ( v0 )
{
v1 = v0;
mark_point("check_memory_handling.c", 12LL);
result = myfree(v1);
}
else
{
ck_assert_failed("check_memory_handling.c", 12LL, "Assertion 'mem!=NULL' failed", "Got no memory!", 0LL);
result = func4();
}
return result;
}

original_code:
static void test_small_malloc (int _i __attribute__ ((unused))){ tcase_fn_start ("""test_small_malloc", "check_memory_handling.c", 7);
{
 void * mem=((void *)0);
 mem=mymalloc(1000);
 (mem!=((void *)0)) ? _mark_point("check_memory_handling.c", 12) : _ck_assert_failed("check_memory_handling.c", 12, "Assertion '""mem!=NULL""' failed" ,"Got no memory!", ((void *)0));
 myfree(mem);
}
}

canonical_original_code:
static void test_small_malloc(int _i){ tcase_fn_start ("""test_small_malloc", "check_memory_handling.c", 7);
{
 void *mem = ((void *)0);
 mem=mymalloc(1000);
 (mem!=((void *)0)) ? _mark_point("check_memory_handling.c", 12) : _ck_assert_failed("check_memory_handling.c", 12, "Assertion '""mem!=NULL""' failed" ,"Got no memory!", ((void *)0));
 myfree(mem);
}
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // rbx
int v5; // ebp

v3 = memory_suite();
v4 = srunner_create(v3, argv);
srunner_run_all(v4, 2LL);
v5 = srunner_ntests_failed(v4);
srunner_free(v4);
return v5 != 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // rbx
int v5; // ebp

v3 = func4();
v4 = srunner_create(v3, argv);
srunner_run_all(v4, 2LL);
v5 = srunner_ntests_failed(v4);
srunner_free(v4);
return v5 != 0;
}

original_code:
int main(int argc, char *argv[]) {
   int i, labelsfile = 0;
   BOOLEAN source_set=0;
   BOOLEAN has_strc;
   int options[24], nopt=0;
   NODATA = (char*)mymalloc(2 * sizeof(char));
   strcpy(NODATA, "M");
   OPTREC optrec[24] = {
      {"-h", &help}, {"-help", &help}, {"--help", &help}, {"-?", &help},
      {"-silent", &silent}, {"--silent", &silent},
      {"-noplot", &noplot}, {"--noplot", &noplot},
      {"-log", &log_set}, {"--log", &log_set},
      {"-nofile", &nofile}, {"--nofile", &nofile},
      {"-nobell", &nobell}, {"--nobell", &nobell},
      {"-thist", &thist}, {"--thist", &thist},
      {"--bernhard",&bernhard},
      {"--header", &has_header},
      {"--noheader", &noheader},
      {"--xsample", &xsample},
      {"--xcols", &xcols},
      {"--color", &color},
      {"--quiet",&silent},
      {"--version", &version} };
   prefs_filename = (char*)mymalloc(15 * sizeof(char));
   strcpy(prefs_filename, "/etc/statistrc");
   has_strc = read_options();
   myfree(prefs_filename);
   prefs_filename = ((void *)0);
   set_prefs_filename();
   signal(13, handle_pipe_interrupt);
   signal(8, handle_fpe_interrupt);
   signal(2, handle_term_interrupt);
   signal(15, handle_term_interrupt);
   setlocale (6, "");
   bindtextdomain ("statist", "/progetti/statist-1.4.2/os2/share/locale");
   textdomain ("statist");
   is_utf8 = get_utf8_status();
   if(has_strc)
     read_options();
   else
     has_strc = read_options();
   set_default_colors();
   for (i=1; i<argc; i++) {
     if (argv[i][0]=='-') {
       options[nopt] = i;
       nopt ++;
       if (nopt > 24) {
  out_err(2, "", 0, gettext ("Too many options") );
       }
     }
   }
   if (!get_options(argv, options, nopt, optrec)) {
     exit(1);
   }
   out_d(gettext (("\nSTATIST --- Version %s\n " "(C) Dirk Melcher 1997-1999\n (C) Bernhard Reiter 1998-2009\n (C) Jakson Aquino 2005-2009\n STATIST comes with ABSOLUTELY NO WARRANTY; it is Free Software under GNU GPL.\n Read the file COPYING for details.\n\n")), "1.4.2");
  if(version){
    exit(0);
  }
  if(silent)
    verbose = 0;
  if(noheader)
    detect_header = 0;
  if(verbose){
    out_d(gettext (" Hint: You can often answer \"%s\" for the number of columns.\n"),
 gettext (("all")) );
    if(has_strc == 0)
      out_d(gettext ("\n You can create an ~/.statistrc file to increase statist " "functionality.\n There is an example of statistrc at %s.\n"),
   "/progetti/statist-1.4.2/os2/share/doc/statist");
  }
   out_d("\n");
   if (help) {
     help_msg();
     exit(0);
   }
   if(xsample){
     extract_sample(argc, argv);
     finish();
     exit(0);
   }
   for (i=1; i<argc; i++) {
     if (!(argv[i][0]=='-')){
       if(strcmp(argv[i-1], "--labels") == 0){
  labelsfile = i;
       } else
  if(strcmp(argv[i-1], "--na-string") == 0){
    NODATA = (char*)mymalloc((strlen(argv[i]) + 1) * sizeof(char));
    strcpy(NODATA, argv[i]);
  } else
    if(strcmp(argv[i-1], "--sep") == 0){
      if(strcmp(argv[i], "\\t") == 0)
        sep = '\t';
      else
        sep = argv[i][0];
    } else
      if(strcmp(argv[i-1], "--dec") == 0){
        dec = argv[i][0];
      } else
        if(!xcols){
   if (!source_set) {
     sourcename = (char*) mycalloc(strlen(argv[i]) + 1, sizeof(char));
     strcpy(sourcename, argv[i]);
     source_set = 1;
   }
   else {
     if(silent)
       out_err(2, "", 0,
    gettext (" More than one data file given!"));
     else{
       out_err(1, "", 0,
    gettext (" More than one data file given!\n" "   Only the first one will be read."));
       if(verbose)
         out_d(gettext ("   If you really want to load more than one file, please\n" "   choose the menu option:\n" "   'Data management | Read another file'\n"));
       mywait();
     }
   }
        }
     }
   }
   if(xcols){
     extract_cols(argc, argv);
     finish();
     exit(0);
   }
   if ( (!source_set) && (!nofile) ) {
     ls();
     out_i(gettext ("Name of data file: ") );
     fgets((line), (255 -1), (stdin)); if (strlen(line) <=1) { empty = 1; } else { line[strlen(line)-1]='\0'; empty = 0; }
       if (empty) {
  out_d(gettext ("No data file given. "));
  nofile = 1;
       } else {
  sourcename = (char*) mycalloc(strlen(line) + 1, sizeof(char));
  sscanf(line, "%s", sourcename);
  if(!(myexist(sourcename))){
    nofile = 1;
    out_err(1, "", 0,
        gettext ("File \"%s\" not found!"), sourcename);
    myfree(sourcename);
    sourcename = ((void *)0);
  }
       }
   }
   if (log_set) {
     if ((logfile = fopen(("statist.log"), ("wt")))==((void *)0)) { out_err(2, "", 0, gettext (" System reports error while opening file %s:\n   %s"), "statist.log", strerror((*__errno_location ()))); };
     if(!nofile)
       out_r(gettext ("Source file = %s\n\n"), sourcename);
   }
   if(dec != '.' && dec != ','){
     if(silent){
       out_err(0, "", 0,
    gettext ("Invalid decimal delimiter: '%c'. Please, choose either ',' or '.'"), dec);
     } else{
       out_err(1, "", 0,
    gettext ("Invalid decimal delimiter: '%c'. Please, choose either ',' or '.'"), dec);
       if(!nofile)
  show_file_head(sourcename);
       set_fileformat();
     }
   }
   if(sep && !(sep == ' ' || sep == ',' || sep == ';' || sep == '\t')){
       if(silent){
  out_err(0, "", 0, gettext ("Invalid field separator: '%c'"), sep);
       } else{
  out_err(1, "", 0, gettext ("Invalid field separator: '%c'"), sep);
  if(!nofile)
    show_file_head(sourcename);
  set_fileformat();
       }
     }
   if(nofile){
     out_d(gettext ("Load file using menu option\n" "Data management | Read another file\n"));
   } else{
     readsourcefile(sourcename);
     mywait();
   }
   out_d("\n");
   if(labelsfile){
     if(myexist(argv[labelsfile]))
       read_labels(argv[labelsfile]);
     else{
       out_err(1, "", 0,
    gettext ("File \"%s\" not found!"),
    argv[labelsfile]);
     }
   }
   main_menue();
   finish();
   return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
   int i; int labelsfile = 0;
   short source_set = 0;
   short has_strc;
   int options[24]; int nopt = 0;
   NODATA = (char *)mymalloc(2 * sizeof(char));
   strcpy(NODATA, "M");
   struct OPTREC optrec[24] = {
      {"-h", &help}, {"-help", &help}, {"--help", &help}, {"-?", &help},
      {"-silent", &silent}, {"--silent", &silent},
      {"-noplot", &noplot}, {"--noplot", &noplot},
      {"-log", &log_set}, {"--log", &log_set},
      {"-nofile", &nofile}, {"--nofile", &nofile},
      {"-nobell", &nobell}, {"--nobell", &nobell},
      {"-thist", &thist}, {"--thist", &thist},
      {"--bernhard",&bernhard},
      {"--header", &has_header},
      {"--noheader", &noheader},
      {"--xsample", &xsample},
      {"--xcols", &xcols},
      {"--color", &color},
      {"--quiet",&silent},
      {"--version", &version} };
   prefs_filename = (char *)mymalloc(15 * sizeof(char));
   strcpy(prefs_filename, "/etc/statistrc");
   has_strc = read_options();
   myfree(prefs_filename);
   prefs_filename = ((void *)0);
   set_prefs_filename();
   signal(13, handle_pipe_interrupt);
   signal(8, handle_fpe_interrupt);
   signal(2, handle_term_interrupt);
   signal(15, handle_term_interrupt);
   setlocale (6, "");
   bindtextdomain ("statist", "/progetti/statist-1.4.2/os2/share/locale");
   textdomain ("statist");
   is_utf8 = get_utf8_status();
   if(has_strc)
     read_options();
   else
     has_strc = read_options();
   set_default_colors();
   for (i=1; i<argc; i++) {
     if (argv[i][0]=='-') {
       options[nopt] = i;
       nopt ++;
       if (nopt > 24) {
  out_err(2, "", 0, gettext ("Too many options") );
       }
     }
   }
   if (!get_options(argv, options, nopt, optrec)) {
     exit(1);
   }
   out_d(gettext (("\nSTATIST --- Version %s\n " "(C) Dirk Melcher 1997-1999\n (C) Bernhard Reiter 1998-2009\n (C) Jakson Aquino 2005-2009\n STATIST comes with ABSOLUTELY NO WARRANTY; it is Free Software under GNU GPL.\n Read the file COPYING for details.\n\n")), "1.4.2");
  if(version){
    exit(0);
  }
  if(silent)
    verbose = 0;
  if(noheader)
    detect_header = 0;
  if(verbose){
    out_d(gettext (" Hint: You can often answer \"%s\" for the number of columns.\n"),
 gettext (("all")) );
    if(has_strc == 0)
      out_d(gettext ("\n You can create an ~/.statistrc file to increase statist " "functionality.\n There is an example of statistrc at %s.\n"),
   "/progetti/statist-1.4.2/os2/share/doc/statist");
  }
   out_d("\n");
   if (help) {
     help_msg();
     exit(0);
   }
   if(xsample){
     extract_sample(argc, argv);
     finish();
     exit(0);
   }
   for (i=1; i<argc; i++) {
     if (!(argv[i][0]=='-')){
       if(strcmp(argv[i-1], "--labels") == 0){
  labelsfile = i;
       } else
  if(strcmp(argv[i-1], "--na-string") == 0){
    NODATA = (char *)mymalloc((strlen(argv[i]) + 1) * sizeof(char));
    strcpy(NODATA, argv[i]);
  } else
    if(strcmp(argv[i-1], "--sep") == 0){
      if(strcmp(argv[i], "\\t") == 0)
        sep = '\t';
      else
        sep = argv[i][0];
    } else
      if(strcmp(argv[i-1], "--dec") == 0){
        dec = argv[i][0];
      } else
        if(!xcols){
   if (!source_set) {
     sourcename = (char *) mycalloc(strlen(argv[i]) + 1, sizeof(char));
     strcpy(sourcename, argv[i]);
     source_set = 1;
   }
   else {
     if(silent)
       out_err(2, "", 0,
    gettext (" More than one data file given!"));
     else{
       out_err(1, "", 0,
    gettext (" More than one data file given!\n" "   Only the first one will be read."));
       if(verbose)
         out_d(gettext ("   If you really want to load more than one file, please\n" "   choose the menu option:\n" "   'Data management | Read another file'\n"));
       mywait();
     }
   }
        }
     }
   }
   if(xcols){
     extract_cols(argc, argv);
     finish();
     exit(0);
   }
   if ( (!source_set) && (!nofile) ) {
     ls();
     out_i(gettext ("Name of data file: ") );
     fgets((line), (255 -1), (stdin)); if (strlen(line) <=1) { empty = 1; } else { line[strlen(line)-1]='\0'; empty = 0; }
       if (empty) {
  out_d(gettext ("No data file given. "));
  nofile = 1;
       } else {
  sourcename = (char *) mycalloc(strlen(line) + 1, sizeof(char));
  sscanf(line, "%s", sourcename);
  if(!(myexist(sourcename))){
    nofile = 1;
    out_err(1, "", 0,
        gettext ("File \"%s\" not found!"), sourcename);
    myfree(sourcename);
    sourcename = ((void *)0);
  }
       }
   }
   if (log_set) {
     if ((logfile = fopen(("statist.log"), ("wt")))==((void *)0)) { out_err(2, "", 0, gettext (" System reports error while opening file %s:\n   %s"), "statist.log", strerror((*__errno_location ()))); };
     if(!nofile)
       out_r(gettext ("Source file = %s\n\n"), sourcename);
   }
   if(dec != '.' && dec != ','){
     if(silent){
       out_err(0, "", 0,
    gettext ("Invalid decimal delimiter: '%c'. Please, choose either ',' or '.'"), dec);
     } else{
       out_err(1, "", 0,
    gettext ("Invalid decimal delimiter: '%c'. Please, choose either ',' or '.'"), dec);
       if(!nofile)
  show_file_head(sourcename);
       set_fileformat();
     }
   }
   if(sep && !(sep == ' ' || sep == ',' || sep == ';' || sep == '\t')){
       if(silent){
  out_err(0, "", 0, gettext ("Invalid field separator: '%c'"), sep);
       } else{
  out_err(1, "", 0, gettext ("Invalid field separator: '%c'"), sep);
  if(!nofile)
    show_file_head(sourcename);
  set_fileformat();
       }
     }
   if(nofile){
     out_d(gettext ("Load file using menu option\n" "Data management | Read another file\n"));
   } else{
     readsourcefile(sourcename);
     mywait();
   }
   out_d("\n");
   if(labelsfile){
     if(myexist(argv[labelsfile]))
       read_labels(argv[labelsfile]);
     else{
       out_err(1, "", 0,
    gettext ("File \"%s\" not found!"),
    argv[labelsfile]);
     }
   }
   main_menue();
   finish();
   return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: labelsfile int

variable_types:
options
int [24]

variable_types: nopt int

variable_types: struct OPTREC { char *optstr; short *optvar; } [24]


myrealloc

decompiled_code:
void *__fastcall myrealloc(void *a1, int a2)
{
void *result; // rax
char *v3; // rax

result = realloc(a1, a2);
if ( !result )
{
v3 = dcgettext(0LL, "Not enough memory. Terminating!", 5);
out_err(2LL, &unk_1C8, 0LL, v3);
finish();
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1, int a2)
{
void *result; // rax
char *v3; // rax

result = realloc(a1, a2);
if ( !result )
{
v3 = dcgettext(0LL, "Not enough memory. Terminating!", 5);
out_err(2LL, &unk_1C8, 0LL, v3);
finish();
exit(1);
}
return result;
}

original_code:
void *myrealloc(void * pointer, int newsize) {
  pointer = realloc(pointer, newsize);
  if (pointer == ((void *)0)) {
     out_err(2, "", 0,
  gettext ("Not enough memory. Terminating!") );
     finish();
     exit(1);
  }
  return pointer;
}

canonical_original_code:
void *myrealloc(void *pointer, int newsize) {
  pointer = realloc(pointer, newsize);
  if (pointer == ((void *)0)) {
     out_err(2, "", 0,
  gettext ("Not enough memory. Terminating!") );
     finish();
     exit(1);
  }
  return pointer;
}

variable_types:
pointer
void *

variable_types: newsize int


mycalloc

decompiled_code:
void *__fastcall mycalloc(int a1, int a2)
{
void *result; // rax
char *v3; // rax

result = calloc(a1, a2);
if ( !result )
{
v3 = dcgettext(0LL, "Not enough memory. Terminating!", 5);
out_err(2LL, &unk_1C8, 0LL, v3);
finish();
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(int a1, int a2)
{
void *result; // rax
char *v3; // rax

result = calloc(a1, a2);
if ( !result )
{
v3 = dcgettext(0LL, "Not enough memory. Terminating!", 5);
out_err(2LL, &unk_1C8, 0LL, v3);
finish();
exit(1);
}
return result;
}

original_code:
void *mycalloc(int nitems, int size) {
  void *pointer;
  pointer = calloc(nitems, size);
  if (pointer == ((void *)0)) {
     out_err(2, "", 0,
  gettext ("Not enough memory. Terminating!") );
     finish();
     exit(1);
  }
  return pointer;
}

variable_types: nitems int

variable_types: size int


mymalloc

decompiled_code:
void *__fastcall mymalloc(int a1)
{
void *result; // rax
char *v2; // rax

result = malloc(a1);
if ( !result )
{
v2 = dcgettext(0LL, "Not enough memory. Terminating!", 5);
out_err(2LL, &unk_1C8, 0LL, v2);
finish();
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func2(int a1)
{
void *result; // rax
char *v2; // rax

result = malloc(a1);
if ( !result )
{
v2 = dcgettext(0LL, "Not enough memory. Terminating!", 5);
out_err(2LL, &unk_1C8, 0LL, v2);
finish();
exit(1);
}
return result;
}

original_code:
void *mymalloc(int size) {
  void *pointer;
  pointer = malloc(size);
  if (pointer == ((void *)0)) {
     out_err(2, "", 0,
  gettext ("Not enough memory. Terminating!") );
     finish();
     exit(1);
  }
  return pointer;
}


myfree

decompiled_code:
void __fastcall myfree(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func3(void *a1)
{
free(a1);
}

original_code:
void myfree(void *ptr) {
  free(ptr);
}

canonical_original_code:
void myfree(void *ptr) {
  free(ptr);
}

variable_types:
ptr
void *


decompiled_code:
void *__fastcall m_calloc(int a1, int a2)
{
_QWORD *v2; // rbp
void *result; // rax

v2 = mycalloc(1, 24);
result = mycalloc(a1, a2);
v2[2] = result;
*v2 = a2 * a1;
v2[1] = ptr_memory_chunks;
ptr_memory_chunks = (__int64)v2;
return result;
}

canonical_decompiled_code:
void *__fastcall func4(int a1, int a2)
{
_QWORD *v2; // rbp
void *result; // rax

v2 = func1(1, 24);
result = func1(a1, a2);
v2[2] = result;
*v2 = a2 * a1;
v2[1] = ptr_memory_chunks;
ptr_memory_chunks = (__int64)v2;
return result;
}

original_code:
void *m_calloc(int nitems, int size) {
  memory_chunk *chunk;
  chunk = mycalloc(1,sizeof(memory_chunk));
  chunk->memory = mycalloc(nitems, size);
  chunk->size = nitems * size;
  chunk->previous_chunk=ptr_memory_chunks;
  ptr_memory_chunks=chunk;
  return chunk->memory;
}

canonical_original_code:
void *m_calloc(int nitems, int size) {
  struct memory_chunk *chunk;
  chunk = mycalloc(1,sizeof(memory_chunk));
  chunk->memory = mycalloc(nitems, size);
  chunk->size = nitems * size;
  chunk->previous_chunk=ptr_memory_chunks;
  ptr_memory_chunks=chunk;
  return chunk->memory;
}

variable_types: struct memory_chunk { unsigned long size; void *previous_chunk; void *memory; } *


decompiled_code:
__int64 m_freeall()
{
__int64 v0; // rbx
void *v1; // rdi

v0 = ptr_memory_chunks;
while ( v0 )
{
myfree(*(void **)(v0 + 16));
v1 = (void *)v0;
v0 = *(_QWORD *)(v0 + 8);
ptr_memory_chunks = v0;
myfree(v1);
}
return 0LL;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 v0; // rbx
void *v1; // rdi

v0 = ptr_memory_chunks;
while ( v0 )
{
func3(*(void **)(v0 + 16));
v1 = (void *)v0;
v0 = *(_QWORD *)(v0 + 8);
ptr_memory_chunks = v0;
func3(v1);
}
return 0LL;
}

original_code:
int m_freeall(void) {
  memory_chunk *chunk=((void *)0);
  while(ptr_memory_chunks!=((void *)0)) {
    chunk=ptr_memory_chunks;
    myfree(chunk->memory);
    ptr_memory_chunks=chunk->previous_chunk;
    myfree(chunk);
  }
  return 0;
}

canonical_original_code:
int m_freeall() {
  struct memory_chunk *chunk = ((void *)0);
  while(ptr_memory_chunks!=((void *)0)) {
    chunk=ptr_memory_chunks;
    myfree(chunk->memory);
    ptr_memory_chunks=chunk->previous_chunk;
    myfree(chunk);
  }
  return 0;
}

user_defined_types: struct memory_chunk { unsigned long size; void *previous_chunk; void *memory; }


newtrans

decompiled_code:
_BYTE *newtrans()
{
_BYTE *result; // rax

result = malloc(0x20uLL);
*result = 0;
result[1] = 0;
result[2] = 0;
result[3] = 0;
result[4] = 0;
result[5] = 0;
result[6] = 0;
*((_DWORD *)result + 2) = 0;
*((_QWORD *)result + 3) = 0LL;
return result;
}

canonical_decompiled_code:
_BYTE *func6()
{
_BYTE *result; // rax

result = malloc(0x20uLL);
*result = 0;
result[1] = 0;
result[2] = 0;
result[3] = 0;
result[4] = 0;
result[5] = 0;
result[6] = 0;
*((_DWORD *)result + 2) = 0;
*((_QWORD *)result + 3) = 0LL;
return result;
}

original_code:
trans
newtrans() {
    trans new;
    int i;
    new = (trans) malloc(sizeof (struct transx));
    for (i=0; i<((50 +6)/8); i++) new->states[i] = 0;
    new->anyst = 0;
    new->nxt = ((void *)0);
    return(new);
}

canonical_original_code:
struct transx *newtrans() {
    struct transx *new;
    int i;
    new = (struct transx *) malloc(sizeof (struct transx));
    for (i=0; i<((50 +6)/8); i++) new->states[i] = 0;
    new->anyst = 0;
    new->nxt = ((void *)0);
    return(new);
}

variable_types: struct transx { unsigned char states[-1]; int anyst; unsigned char inchr; int actno; struct transx *nxt; } *

variable_types: i int


emptytbl

decompiled_code:
__int64 emptytbl()
{
__int64 result; // rax
int v1; // edx

result = (unsigned int)nstates;
v1 = 96 * nstates;
if ( 96 * nstates > 0 )
{
result = 0LL;
do
tbl[result++] = -1;
while ( result != v1 );
}
return result;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 result; // rax
int v1; // edx

result = (unsigned int)nstates;
v1 = 96 * nstates;
if ( 96 * nstates > 0 )
{
result = 0LL;
do
tbl[result++] = -1;
while ( result != v1 );
}
return result;
}

original_code:
void
emptytbl() {
    int i;
    for (i=0; i<nstates*96; i++) tbl[i] = -1;
}


clrhash

decompiled_code:
__int64 *clrhash()
{
__int64 *result; // rax

result = &htab;
do
*result++ = 0LL;
while ( result != (__int64 *)(unsigned int)((_DWORD)&htab + 808) );
return result;
}

canonical_decompiled_code:
__int64 *func19()
{
__int64 *result; // rax

result = &htab;
do
*result++ = 0LL;
while ( result != (__int64 *)(unsigned int)((_DWORD)&htab + 808) );
return result;
}

original_code:
void
clrhash() {
    int i;
    for (i=0; i<101; i++) htab[i] = ((void *)0);
}


usage

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

if ( !versio || !*versio )
versio = "gkermit UNKNOWN VERSION";
if ( !build )
build = "UNKNOWN BUILD";
if ( !url )
url = &unk_E96;
if ( !email )
email = &unk_E96;
fprintf(stderr, "%s: %s.\n", versio, build);
fwrite("Usage: gkermit [ options ]\n", 1uLL, 0x1CuLL, stderr);
fwrite("Options:\n", 1uLL, 9uLL, stderr);
fwrite(" -r Receive files\n", 1uLL, 0x17uLL, stderr);
fwrite(" -s fn Send files\n", 1uLL, 0x14uLL, stderr);
fwrite(" -g fn Get files from server\n", 1uLL, 0x1FuLL, stderr);
fwrite(" -a fn As-name for single file\n", 1uLL, 0x21uLL, stderr);
fwrite(" -i Image (binary) mode transfer\n", 1uLL, 0x26uLL, stderr);
fwrite(" -T Text mode transfer\n", 1uLL, 0x1CuLL, stderr);
fwrite(" -P Path/filename conversion disabled\n", 1uLL, 0x2BuLL, stderr);
fwrite(" -w Write over existing files with same name\n", 1uLL, 0x32uLL, stderr);
fwrite(" -K Keep incompletely received files\n", 1uLL, 0x2AuLL, stderr);
fwrite(" -p x Parity: x = o[dd],e[ven],m[ark],s[pace],n[one]\n", 1uLL, 0x38uLL, stderr);
fprintf(stderr, " -e n Receive packet-length (40-%d)\n", 9000LL);
fwrite(" -b n Timeout (sec, 0 = none)\n", 1uLL, 0x21uLL, stderr);
fwrite(" -x Force Xon/Xoff (--x = Don't force Xon/Xoff)\n", 1uLL, 0x35uLL, stderr);
fwrite(" -S Disable streaming\n", 1uLL, 0x1BuLL, stderr);
fwrite(" -X External protocol\n", 1uLL, 0x1BuLL, stderr);
fwrite(" -q Quiet (suppress messages)\n", 1uLL, 0x23uLL, stderr);
fwrite(" -d [fn] Debug to ./debug.log [or specified file]\n", 1uLL, 0x32uLL, stderr);
fwrite(" -h Help (this message)\n", 1uLL, 0x1DuLL, stderr);
if ( *url || (result = email, *email) )
result = fprintf(stderr, "More info: %s <%s>", url, email);
return result;
}

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

if ( !versio || !*versio )
versio = "gkermit UNKNOWN VERSION";
if ( !build )
build = "UNKNOWN BUILD";
if ( !url )
url = &unk_E96;
if ( !email )
email = &unk_E96;
fprintf(stderr, "%s: %s.\n", versio, build);
fwrite("Usage: gkermit [ options ]\n", 1uLL, 0x1CuLL, stderr);
fwrite("Options:\n", 1uLL, 9uLL, stderr);
fwrite(" -r Receive files\n", 1uLL, 0x17uLL, stderr);
fwrite(" -s fn Send files\n", 1uLL, 0x14uLL, stderr);
fwrite(" -g fn Get files from server\n", 1uLL, 0x1FuLL, stderr);
fwrite(" -a fn As-name for single file\n", 1uLL, 0x21uLL, stderr);
fwrite(" -i Image (binary) mode transfer\n", 1uLL, 0x26uLL, stderr);
fwrite(" -T Text mode transfer\n", 1uLL, 0x1CuLL, stderr);
fwrite(" -P Path/filename conversion disabled\n", 1uLL, 0x2BuLL, stderr);
fwrite(" -w Write over existing files with same name\n", 1uLL, 0x32uLL, stderr);
fwrite(" -K Keep incompletely received files\n", 1uLL, 0x2AuLL, stderr);
fwrite(" -p x Parity: x = o[dd],e[ven],m[ark],s[pace],n[one]\n", 1uLL, 0x38uLL, stderr);
fprintf(stderr, " -e n Receive packet-length (40-%d)\n", 9000LL);
fwrite(" -b n Timeout (sec, 0 = none)\n", 1uLL, 0x21uLL, stderr);
fwrite(" -x Force Xon/Xoff (--x = Don't force Xon/Xoff)\n", 1uLL, 0x35uLL, stderr);
fwrite(" -S Disable streaming\n", 1uLL, 0x1BuLL, stderr);
fwrite(" -X External protocol\n", 1uLL, 0x1BuLL, stderr);
fwrite(" -q Quiet (suppress messages)\n", 1uLL, 0x23uLL, stderr);
fwrite(" -d [fn] Debug to ./debug.log [or specified file]\n", 1uLL, 0x32uLL, stderr);
fwrite(" -h Help (this message)\n", 1uLL, 0x1DuLL, stderr);
if ( *url || (result = email, *email) )
result = fprintf(stderr, "More info: %s <%s>", url, email);
return result;
}

original_code:
void
usage() {
    extern char * versio, * build, * url, * email;
    if (!versio) versio = "";
    if (!*versio) versio = "gkermit UNKNOWN VERSION";
    if (!build) build = "UNKNOWN BUILD";
    if (!url) url = "";
    if (!email) email = "";
    fprintf(stderr,"%s: %s.\n",versio,build);
    fprintf(stderr,"Usage:  gkermit [ options ]\n");
    fprintf(stderr,"Options:\n");
    fprintf(stderr," -r      Receive files\n");
    fprintf(stderr," -s fn   Send files\n");
    fprintf(stderr," -g fn   Get files from server\n");
    fprintf(stderr," -a fn   As-name for single file\n");
    fprintf(stderr," -i      Image (binary) mode transfer\n");
    fprintf(stderr," -T      Text mode transfer\n");
    fprintf(stderr," -P      Path/filename conversion disabled\n");
    fprintf(stderr," -w      Write over existing files with same name\n");
    fprintf(stderr," -K      Keep incompletely received files\n");
    fprintf(stderr," -p x    Parity: x = o[dd],e[ven],m[ark],s[pace],n[one]\n")
      ;
    fprintf(stderr," -e n    Receive packet-length (40-%d)\n",9000);
    fprintf(stderr," -b n    Timeout (sec, 0 = none)\n");
    fprintf(stderr," -x      Force Xon/Xoff (--x = Don't force Xon/Xoff)\n");
    fprintf(stderr," -S      Disable streaming\n");
    fprintf(stderr," -X      External protocol\n");
    fprintf(stderr," -q      Quiet (suppress messages)\n");
    fprintf(stderr," -d [fn] Debug to ./debug.log [or specified file]\n");
    fprintf(stderr," -h      Help (this message)\n");
    if (*url || *email)
      fprintf(stderr,"More info: %s <%s>",url,email);
}

canonical_original_code:
void usage() {
    extern char *versio; extern char *build; extern char *url; extern char *email;
    if (!versio) versio = "";
    if (!*versio) versio = "gkermit UNKNOWN VERSION";
    if (!build) build = "UNKNOWN BUILD";
    if (!url) url = "";
    if (!email) email = "";
    fprintf(stderr,"%s: %s.\n",versio,build);
    fprintf(stderr,"Usage:  gkermit [ options ]\n");
    fprintf(stderr,"Options:\n");
    fprintf(stderr," -r      Receive files\n");
    fprintf(stderr," -s fn   Send files\n");
    fprintf(stderr," -g fn   Get files from server\n");
    fprintf(stderr," -a fn   As-name for single file\n");
    fprintf(stderr," -i      Image (binary) mode transfer\n");
    fprintf(stderr," -T      Text mode transfer\n");
    fprintf(stderr," -P      Path/filename conversion disabled\n");
    fprintf(stderr," -w      Write over existing files with same name\n");
    fprintf(stderr," -K      Keep incompletely received files\n");
    fprintf(stderr," -p x    Parity: x = o[dd],e[ven],m[ark],s[pace],n[one]\n")
      ;
    fprintf(stderr," -e n    Receive packet-length (40-%d)\n",9000);
    fprintf(stderr," -b n    Timeout (sec, 0 = none)\n");
    fprintf(stderr," -x      Force Xon/Xoff (--x = Don't force Xon/Xoff)\n");
    fprintf(stderr," -S      Disable streaming\n");
    fprintf(stderr," -X      External protocol\n");
    fprintf(stderr," -q      Quiet (suppress messages)\n");
    fprintf(stderr," -d [fn] Debug to ./debug.log [or specified file]\n");
    fprintf(stderr," -h      Help (this message)\n");
    if (*url || *email)
      fprintf(stderr,"More info: %s <%s>",url,email);
}

variable_types:
versio
char *

variable_types:
build
char *

variable_types:
url
char *

variable_types:
email
char *


doarg

decompiled_code:
__int64 __fastcall doarg(char a1)
{
__int64 v1; // rbx
char v2; // al
__int64 v3; // rax
int i; // edx
__int64 v5; // rdx
__int64 v6; // rdx
char v7; // dl
const char *v8; // rdi
const char *v9; // rcx
const char *v10; // rdx
__int64 v11; // rdx
const char *v12; // rdx
__int64 v13; // rdx
int v14; // eax
__int64 v15; // rdx
int v16; // eax

v1 = *xargv + 1LL;
if ( a1 )
{
v2 = a1;
do
{
switch ( v2 )
{
case '-':
if ( *(_BYTE *)(v1 + 1) == 120 )
{
xonxoff = 0;
noxonxoff = 1;
}
else
{
fatal("invalid argument, type 'gkermit -h' for help");
}
v3 = v1 + 1;
break;
case '?':
case 'h':
usage();
doexit(0LL);
goto LABEL_27;
case 'K':
keep = 1;
v3 = v1;
break;
case 'P':
literal = 1;
v3 = v1;
break;
case 'S':
streamok = -1;
v3 = v1;
break;
case 'T':
manual = 1;
text = 1;
v3 = v1;
break;
case 'X':
quiet = 1;
nomodes = 1;
v3 = v1;
break;
case 'a':
if ( *(_BYTE *)(v1 + 1) )
fatal("invalid argument bundling after -a");
v11 = xargv;
xargv += 8LL;
if ( !--xargc || **(_BYTE **)(v11 + 8) == 45 )
fatal("missing name for -a");
v12 = (const char *)*xargv;
cmarg2 = *xargv;
v3 = v1;
if ( debug )
{
fprintf(db, "as-name: %s\n", v12);
v3 = v1;
}
break;
case 'b':
if ( *(_BYTE *)(v1 + 1) )
fatal("invalid argument bundling after -b");
v15 = xargv;
xargv += 8LL;
--xargc;
if ( xargc <= 0 || **(_BYTE **)(v15 + 8) == 45 )
fatal("missing value");
v16 = atoi((const char *)*xargv);
if ( v16 > 90 )
v16 = 90;
if ( v16 < 0 )
v16 = 0;
timint = v16;
v3 = v1;
break;
case 'd':
if ( xargc <= 1 || (v8 = *(const char **)(xargv + 8LL), *v8 == 45) )
{
db = fopen("debug.log", "w");
}
else
{
xargv += 8LL;
--xargc;
db = fopen(v8, "w");
}
v3 = v1;
if ( db )
{
if ( !versio )
versio = &unk_E96;
if ( !build )
build = &unk_E96;
debug = 1;
setbuf(db, 0LL);
v9 = (const char *)build;
if ( !*build )
v9 = "BUILD UNKNOWN";
v10 = (const char *)versio;
if ( !*versio )
v10 = "GKERMIT VERSION UNKNOWN";
fprintf(db, "%s: %s\n", v10, v9);
fprintf(db, "MAXPATHLEN = %d\n", 1024LL);
v3 = v1;
if ( gptr )
{
fprintf(db, "GKERMIT=\"%s\"\n", (const char *)gptr);
v3 = v1;
}
}
break;
case 'e':
if ( *(_BYTE *)(v1 + 1) )
fatal("invalid argument bundling after -e");
v13 = xargv;
xargv += 8LL;
--xargc;
if ( xargc <= 0 || **(_BYTE **)(v13 + 8) == 45 )
fatal("missing length");
v14 = atoi((const char *)*xargv);
if ( (unsigned int)(v14 - 40) > 0x2300 )
{
fatal("Unsupported packet length");
v3 = v1;
}
else
{
urpsiz = v14;
if ( v14 > 94 )
rpsiz = 94;
else
rpsiz = v14;
v3 = v1;
}
break;
case 'g':
if ( action )
fatal("conflicting actions");
if ( *(_BYTE *)(v1 + 1) )
fatal("invalid argument bundling after -g");
v5 = xargv;
xargv += 8LL;
if ( !--xargc || **(_BYTE **)(v5 + 8) == 45 )
fatal("missing filename for -g");
cmarg = *xargv;
action = 114;
v3 = v1;
break;
case 'i':
LABEL_27:
manual = 1;
text = 0;
v3 = v1;
break;
case 'p':
if ( *(_BYTE *)(v1 + 1) )
fatal("invalid argument bundling");
v6 = xargv;
xargv += 8LL;
--xargc;
if ( xargc <= 0 || **(_BYTE **)(v6 + 8) == 45 )
fatal("missing parity");
v7 = *(_BYTE *)*xargv;
switch ( v7 )
{
case 'e':
case 'm':
case 'o':
case 's':
parity = v7;
v3 = v1;
break;
case 'n':
parity = 0;
v3 = v1;
break;
default:
fatal("invalid parity");
v3 = v1;
break;
}
break;
case 'q':
quiet = 1;
v3 = v1;
break;
case 'r':
if ( action )
fatal("conflicting actions");
action = 118;
v3 = v1;
break;
case 's':
if ( action )
fatal("conflicting actions");
if ( *(_BYTE *)(v1 + 1) )
fatal("invalid argument bundling after -s");
nfils = 0;
cmlist = xargv + 8LL;
if ( zchki(*(_QWORD *)(xargv + 8LL)) < 0 )
fatal("file not found or not accessible");
for ( i = xargc--; xargc > 0; i = xargc-- )
{
xargv += 8LL;
if ( *(_BYTE *)*xargv == 45 )
break;
++nfils;
}
xargc = i;
xargv -= 8LL;
if ( nfils <= 0 )
fatal("missing filename for -s");
action = 115;
v3 = v1;
break;
case 'w':
backup = 0;
v3 = v1;
break;
case 'x':
xonxoff = 1;
noxonxoff = 0;
v3 = v1;
break;
default:
fatal("invalid argument, type 'gkermit -h' for help");
v3 = v1;
break;
}
v1 = v3 + 1;
v2 = *(_BYTE *)(v3 + 1);
}
while ( v2 );
}
if ( debug )
{
if ( action )
fprintf(db, "cmdlin action = %c\n", (unsigned int)action);
else
fwrite("cmdlin action = (none)\n", 1uLL, 0x17uLL, db);
}
return (unsigned int)action;
}

canonical_decompiled_code:
__int64 __fastcall func2(char a1)
{
__int64 v1; // rbx
char v2; // al
__int64 v3; // rax
int i; // edx
__int64 v5; // rdx
__int64 v6; // rdx
char v7; // dl
const char *v8; // rdi
const char *v9; // rcx
const char *v10; // rdx
__int64 v11; // rdx
const char *v12; // rdx
__int64 v13; // rdx
int v14; // eax
__int64 v15; // rdx
int v16; // eax

v1 = *xargv + 1LL;
if ( a1 )
{
v2 = a1;
do
{
switch ( v2 )
{
case '-':
if ( *(_BYTE *)(v1 + 1) == 120 )
{
xonxoff = 0;
noxonxoff = 1;
}
else
{
func0("invalid argument, type 'gkermit -h' for help");
}
v3 = v1 + 1;
break;
case '?':
case 'h':
func1();
doexit(0LL);
goto LABEL_27;
case 'K':
keep = 1;
v3 = v1;
break;
case 'P':
literal = 1;
v3 = v1;
break;
case 'S':
streamok = -1;
v3 = v1;
break;
case 'T':
manual = 1;
text = 1;
v3 = v1;
break;
case 'X':
quiet = 1;
nomodes = 1;
v3 = v1;
break;
case 'a':
if ( *(_BYTE *)(v1 + 1) )
func0("invalid argument bundling after -a");
v11 = xargv;
xargv += 8LL;
if ( !--xargc || **(_BYTE **)(v11 + 8) == 45 )
func0("missing name for -a");
v12 = (const char *)*xargv;
cmarg2 = *xargv;
v3 = v1;
if ( debug )
{
fprintf(db, "as-name: %s\n", v12);
v3 = v1;
}
break;
case 'b':
if ( *(_BYTE *)(v1 + 1) )
func0("invalid argument bundling after -b");
v15 = xargv;
xargv += 8LL;
--xargc;
if ( xargc <= 0 || **(_BYTE **)(v15 + 8) == 45 )
func0("missing value");
v16 = atoi((const char *)*xargv);
if ( v16 > 90 )
v16 = 90;
if ( v16 < 0 )
v16 = 0;
timint = v16;
v3 = v1;
break;
case 'd':
if ( xargc <= 1 || (v8 = *(const char **)(xargv + 8LL), *v8 == 45) )
{
db = fopen("debug.log", "w");
}
else
{
xargv += 8LL;
--xargc;
db = fopen(v8, "w");
}
v3 = v1;
if ( db )
{
if ( !versio )
versio = &unk_E96;
if ( !build )
build = &unk_E96;
debug = 1;
setbuf(db, 0LL);
v9 = (const char *)build;
if ( !*build )
v9 = "BUILD UNKNOWN";
v10 = (const char *)versio;
if ( !*versio )
v10 = "GKERMIT VERSION UNKNOWN";
fprintf(db, "%s: %s\n", v10, v9);
fprintf(db, "MAXPATHLEN = %d\n", 1024LL);
v3 = v1;
if ( gptr )
{
fprintf(db, "GKERMIT=\"%s\"\n", (const char *)gptr);
v3 = v1;
}
}
break;
case 'e':
if ( *(_BYTE *)(v1 + 1) )
func0("invalid argument bundling after -e");
v13 = xargv;
xargv += 8LL;
--xargc;
if ( xargc <= 0 || **(_BYTE **)(v13 + 8) == 45 )
func0("missing length");
v14 = atoi((const char *)*xargv);
if ( (unsigned int)(v14 - 40) > 0x2300 )
{
func0("Unsupported packet length");
v3 = v1;
}
else
{
urpsiz = v14;
if ( v14 > 94 )
rpsiz = 94;
else
rpsiz = v14;
v3 = v1;
}
break;
case 'g':
if ( action )
func0("conflicting actions");
if ( *(_BYTE *)(v1 + 1) )
func0("invalid argument bundling after -g");
v5 = xargv;
xargv += 8LL;
if ( !--xargc || **(_BYTE **)(v5 + 8) == 45 )
func0("missing filename for -g");
cmarg = *xargv;
action = 114;
v3 = v1;
break;
case 'i':
LABEL_27:
manual = 1;
text = 0;
v3 = v1;
break;
case 'p':
if ( *(_BYTE *)(v1 + 1) )
func0("invalid argument bundling");
v6 = xargv;
xargv += 8LL;
--xargc;
if ( xargc <= 0 || **(_BYTE **)(v6 + 8) == 45 )
func0("missing parity");
v7 = *(_BYTE *)*xargv;
switch ( v7 )
{
case 'e':
case 'm':
case 'o':
case 's':
parity = v7;
v3 = v1;
break;
case 'n':
parity = 0;
v3 = v1;
break;
default:
func0("invalid parity");
v3 = v1;
break;
}
break;
case 'q':
quiet = 1;
v3 = v1;
break;
case 'r':
if ( action )
func0("conflicting actions");
action = 118;
v3 = v1;
break;
case 's':
if ( action )
func0("conflicting actions");
if ( *(_BYTE *)(v1 + 1) )
func0("invalid argument bundling after -s");
nfils = 0;
cmlist = xargv + 8LL;
if ( zchki(*(_QWORD *)(xargv + 8LL)) < 0 )
func0("file not found or not accessible");
for ( i = xargc--; xargc > 0; i = xargc-- )
{
xargv += 8LL;
if ( *(_BYTE *)*xargv == 45 )
break;
++nfils;
}
xargc = i;
xargv -= 8LL;
if ( nfils <= 0 )
func0("missing filename for -s");
action = 115;
v3 = v1;
break;
case 'w':
backup = 0;
v3 = v1;
break;
case 'x':
xonxoff = 1;
noxonxoff = 0;
v3 = v1;
break;
default:
func0("invalid argument, type 'gkermit -h' for help");
v3 = v1;
break;
}
v1 = v3 + 1;
v2 = *(_BYTE *)(v3 + 1);
}
while ( v2 );
}
if ( debug )
{
if ( action )
fprintf(db, "cmdlin action = %c\n", (unsigned int)action);
else
fwrite("cmdlin action = (none)\n", 1uLL, 0x17uLL, db);
}
return (unsigned int)action;
}

original_code:
static int
doarg(char x)
{
    int z; char *xp, **p;
    xp = *xargv+1;
    while (x) {
 switch (x) {
   case 'r':
     if (action) fatal("conflicting actions");
     action = 'v';
     break;
   case 's':
     if (action) fatal("conflicting actions");
     if (*(xp+1)) fatal("invalid argument bundling after -s");
     nfils = 0;
     cmlist = xargv+1;
     if (zchki(*cmlist) < 0)
       fatal("file not found or not accessible");
     while (--xargc > 0) {
  *xargv++;
  if (**xargv == '-')
    break;
  nfils++;
     }
     xargc++, *xargv--;
     if (nfils < 1) fatal("missing filename for -s");
     action = 's';
     break;
   case 'g':
     if (action) fatal("conflicting actions");
     if (*(xp+1)) fatal("invalid argument bundling after -g");
     *xargv++, xargc--;
     if ((xargc == 0) || (**xargv == '-'))
       fatal("missing filename for -g");
     cmarg = *xargv;
     action = 'r';
     break;
   case 'h':
   case '?':
     usage();
     doexit(0);
   case 'i':
     manual = 1;
     text = 0;
     break;
   case 'T':
     manual = 1;
     text = 1;
     break;
   case 'p':
     if (*(xp+1)) fatal("invalid argument bundling");
     *xargv++, xargc--;
     if ((xargc < 1) || (**xargv == '-'))
       fatal("missing parity");
     switch(x = **xargv) {
       case 'e':
       case 'o':
       case 'm':
       case 's': parity = x; break;
       case 'n': parity = 0; break;
       default: fatal("invalid parity");
     }
     break;
   case 'w':
     backup = 0;
     break;
   case 'd':
     p = xargv;
     *p++;
     if ((xargc < 2) || (**p == '-')) {
  db = fopen("debug.log","w");
     } else {
  *xargv++, xargc--;
  db = fopen(*xargv,"w");
     }
     if (db) {
  extern char * versio, * build;
  if (!versio) versio = "";
  if (!build) build = "";
  debug = 1;
  setbuf(db,((void *)0));
  fprintf(db,"%s: %s\n",
   (*versio ? versio : "GKERMIT VERSION UNKNOWN"),
   (*build ? build : "BUILD UNKNOWN")
   );
  fprintf(db,"MAXPATHLEN = %d\n",1024);
  if (gptr) fprintf(db,"GKERMIT=\"%s\"\n",gptr);
     }
     break;
   case 'a':
     if (*(xp+1)) fatal("invalid argument bundling after -a");
     *xargv++, xargc--;
     if ((xargc == 0) || (**xargv == '-'))
       fatal("missing name for -a");
     cmarg2 = *xargv;
     if (debug) fprintf(db,"as-name: %s\n",cmarg2);
     break;
   case 'e':
     if (*(xp+1)) fatal("invalid argument bundling after -e");
     xargv++, xargc--;
     if ((xargc < 1) || (**xargv == '-'))
       fatal("missing length");
     z = atoi(*xargv);
     if (z >= 40 && z <= 9000) {
  rpsiz = urpsiz = z;
  if (z > 94) rpsiz = 94;
     } else {
  fatal("Unsupported packet length");
     }
     break;
   case 'b':
     if (*(xp+1)) fatal("invalid argument bundling after -b");
     xargv++, xargc--;
     if ((xargc < 1) || (**xargv == '-'))
       fatal("missing value");
     z = atoi(*xargv);
     if (z < 0) z = 0;
     if (z > 90) z = 90;
     timint = z;
     break;
   case 'P':
     literal = 1;
     break;
   case 'q':
     quiet = 1;
     break;
   case 'K':
     keep = 1;
     break;
   case 'S':
     streamok = -1;
     break;
   case 'X':
     quiet = 1;
            nomodes = 1;
     break;
   case 'x':
     xonxoff = 1;
     noxonxoff = 0;
     break;
   case '-':
     if (*(xp+1) == 'x') {
  xonxoff = 0;
  noxonxoff = 1;
     } else {
  fatal("invalid argument, type 'gkermit -h' for help");
     }
     xp++;
     break;
   default:
     fatal("invalid argument, type 'gkermit -h' for help");
        }
 x = *++xp;
    }
    if (debug) {
 if (action)
   fprintf(db,"cmdlin action = %c\n",action);
 else
   fprintf(db,"cmdlin action = (none)\n");
    }
    return(action);
}

canonical_original_code:
static int doarg(char x)
{
    int z; char *xp; char **p;
    xp = *xargv+1;
    while (x) {
 switch (x) {
   case 'r':
     if (action) fatal("conflicting actions");
     action = 'v';
     break;
   case 's':
     if (action) fatal("conflicting actions");
     if (*(xp+1)) fatal("invalid argument bundling after -s");
     nfils = 0;
     cmlist = xargv+1;
     if (zchki(*cmlist) < 0)
       fatal("file not found or not accessible");
     while (--xargc > 0) {
  *xargv++;
  if (**xargv == '-')
    break;
  nfils++;
     }
     xargc++, *xargv--;
     if (nfils < 1) fatal("missing filename for -s");
     action = 's';
     break;
   case 'g':
     if (action) fatal("conflicting actions");
     if (*(xp+1)) fatal("invalid argument bundling after -g");
     *xargv++, xargc--;
     if ((xargc == 0) || (**xargv == '-'))
       fatal("missing filename for -g");
     cmarg = *xargv;
     action = 'r';
     break;
   case 'h':
   case '?':
     usage();
     doexit(0);
   case 'i':
     manual = 1;
     text = 0;
     break;
   case 'T':
     manual = 1;
     text = 1;
     break;
   case 'p':
     if (*(xp+1)) fatal("invalid argument bundling");
     *xargv++, xargc--;
     if ((xargc < 1) || (**xargv == '-'))
       fatal("missing parity");
     switch(x = **xargv) {
       case 'e':
       case 'o':
       case 'm':
       case 's': parity = x; break;
       case 'n': parity = 0; break;
       default: fatal("invalid parity");
     }
     break;
   case 'w':
     backup = 0;
     break;
   case 'd':
     p = xargv;
     *p++;
     if ((xargc < 2) || (**p == '-')) {
  db = fopen("debug.log","w");
     } else {
  *xargv++, xargc--;
  db = fopen(*xargv,"w");
     }
     if (db) {
  extern char *versio; extern char *build;
  if (!versio) versio = "";
  if (!build) build = "";
  debug = 1;
  setbuf(db,((void *)0));
  fprintf(db,"%s: %s\n",
   (*versio ? versio : "GKERMIT VERSION UNKNOWN"),
   (*build ? build : "BUILD UNKNOWN")
   );
  fprintf(db,"MAXPATHLEN = %d\n",1024);
  if (gptr) fprintf(db,"GKERMIT=\"%s\"\n",gptr);
     }
     break;
   case 'a':
     if (*(xp+1)) fatal("invalid argument bundling after -a");
     *xargv++, xargc--;
     if ((xargc == 0) || (**xargv == '-'))
       fatal("missing name for -a");
     cmarg2 = *xargv;
     if (debug) fprintf(db,"as-name: %s\n",cmarg2);
     break;
   case 'e':
     if (*(xp+1)) fatal("invalid argument bundling after -e");
     xargv++, xargc--;
     if ((xargc < 1) || (**xargv == '-'))
       fatal("missing length");
     z = atoi(*xargv);
     if (z >= 40 && z <= 9000) {
  rpsiz = urpsiz = z;
  if (z > 94) rpsiz = 94;
     } else {
  fatal("Unsupported packet length");
     }
     break;
   case 'b':
     if (*(xp+1)) fatal("invalid argument bundling after -b");
     xargv++, xargc--;
     if ((xargc < 1) || (**xargv == '-'))
       fatal("missing value");
     z = atoi(*xargv);
     if (z < 0) z = 0;
     if (z > 90) z = 90;
     timint = z;
     break;
   case 'P':
     literal = 1;
     break;
   case 'q':
     quiet = 1;
     break;
   case 'K':
     keep = 1;
     break;
   case 'S':
     streamok = -1;
     break;
   case 'X':
     quiet = 1;
            nomodes = 1;
     break;
   case 'x':
     xonxoff = 1;
     noxonxoff = 0;
     break;
   case '-':
     if (*(xp+1) == 'x') {
  xonxoff = 0;
  noxonxoff = 1;
     } else {
  fatal("invalid argument, type 'gkermit -h' for help");
     }
     xp++;
     break;
   default:
     fatal("invalid argument, type 'gkermit -h' for help");
        }
 x = *++xp;
    }
    if (debug) {
 if (action)
   fprintf(db,"cmdlin action = %c\n",action);
 else
   fprintf(db,"cmdlin action = (none)\n");
    }
    return(action);
}

variable_types: x char

variable_types: z int

variable_types:
xp
char *

variable_types:
p
char **


cmdlin

decompiled_code:
__int64 cmdlin()
{
char *v0; // rax
__int64 v1; // rbx
char v2; // dl
int v3; // ecx
char *v4; // rax
char v5; // r11
int v6; // er8
bool v7; // di
__int64 v8; // rbp
int v9; // ebx
int v11; // eax
__int64 v12; // rdx
__int64 v13; // rdx

cmarg = &unk_E96;
cmlist = 0LL;
action = 0;
v0 = getenv("GKERMIT");
if ( v0 )
{
v1 = (__int64)v0;
strncpy(&gbuf, v0, 0xFFuLL);
byte_E5F = 0;
gptr = v1;
v2 = gbuf;
if ( gbuf )
{
v3 = gargc;
v4 = &gbuf;
v5 = 0;
v6 = 0;
while ( v3 <= 31 )
{
if ( v6 )
{
if ( v2 <= 32 )
{
*v4 = 0;
v6 = 0;
}
}
else if ( v2 > 32 )
{
gargs[v3++] = (__int64)v4;
v5 = 1;
v6 = 1;
}
v2 = v4[1];
v7 = (int)(1 - (unsigned int)&gbuf + (_DWORD)v4++) <= 255;
if ( v2 == 0 || !v7 )
{
if ( v5 )
gargc = v3;
goto LABEL_14;
}
}
if ( v5 )
gargc = v3;
}
LABEL_14:
v8 = xargv;
v9 = xargc;
xargv = gargs;
xargc = gargc - 1;
if ( gargc > 0 )
{
do
{
v12 = *xargv;
if ( *(_BYTE *)*xargv == 45 )
{
if ( (int)doarg(*(_BYTE *)(v12 + 1)) < 0 )
doexit(1LL);
}
else
{
fprintf(stderr, "?GKERMIT variable option error: \"%s\"\n", (const char *)v12);
usage();
doexit(0LL);
}
xargv += 8LL;
v11 = xargc--;
}
while ( v11 > 0 );
}
xargv = v8;
xargc = v9;
}
--xargc;
for ( ; xargc > 0; --xargc )
{
xargv += 8LL;
v13 = *xargv;
if ( *(_BYTE *)*xargv == 45 )
{
if ( (int)doarg(*(_BYTE *)(v13 + 1)) < 0 )
doexit(1LL);
}
else
{
fprintf(stderr, "?Command-line option error: \"%s\"\n", (const char *)v13);
usage();
doexit(1LL);
}
}
return (unsigned int)action;
}

canonical_decompiled_code:
__int64 func3()
{
char *v0; // rax
__int64 v1; // rbx
char v2; // dl
int v3; // ecx
char *v4; // rax
char v5; // r11
int v6; // er8
bool v7; // di
__int64 v8; // rbp
int v9; // ebx
int v11; // eax
__int64 v12; // rdx
__int64 v13; // rdx

cmarg = &unk_E96;
cmlist = 0LL;
action = 0;
v0 = getenv("GKERMIT");
if ( v0 )
{
v1 = (__int64)v0;
strncpy(&gbuf, v0, 0xFFuLL);
byte_E5F = 0;
gptr = v1;
v2 = gbuf;
if ( gbuf )
{
v3 = gargc;
v4 = &gbuf;
v5 = 0;
v6 = 0;
while ( v3 <= 31 )
{
if ( v6 )
{
if ( v2 <= 32 )
{
*v4 = 0;
v6 = 0;
}
}
else if ( v2 > 32 )
{
gargs[v3++] = (__int64)v4;
v5 = 1;
v6 = 1;
}
v2 = v4[1];
v7 = (int)(1 - (unsigned int)&gbuf + (_DWORD)v4++) <= 255;
if ( v2 == 0 || !v7 )
{
if ( v5 )
gargc = v3;
goto LABEL_14;
}
}
if ( v5 )
gargc = v3;
}
LABEL_14:
v8 = xargv;
v9 = xargc;
xargv = gargs;
xargc = gargc - 1;
if ( gargc > 0 )
{
do
{
v12 = *xargv;
if ( *(_BYTE *)*xargv == 45 )
{
if ( (int)func2(*(_BYTE *)(v12 + 1)) < 0 )
doexit(1LL);
}
else
{
fprintf(stderr, "?GKERMIT variable option error: \"%s\"\n", (const char *)v12);
func1();
doexit(0LL);
}
xargv += 8LL;
v11 = xargc--;
}
while ( v11 > 0 );
}
xargv = v8;
xargc = v9;
}
--xargc;
for ( ; xargc > 0; --xargc )
{
xargv += 8LL;
v13 = *xargv;
if ( *(_BYTE *)*xargv == 45 )
{
if ( (int)func2(*(_BYTE *)(v13 + 1)) < 0 )
doexit(1LL);
}
else
{
fprintf(stderr, "?Command-line option error: \"%s\"\n", (const char *)v13);
func1();
doexit(1LL);
}
}
return (unsigned int)action;
}

original_code:
int
cmdlin() {
    char c;
    int x;
    char * p = ((void *)0);
    cmarg = "";
    cmlist = ((void *)0);
    action = 0;
    if ((p = getenv("GKERMIT"))) {
 int i, xc, flag = 0;
 char **xv = ((void *)0);
 strncpy(gbuf,p,256 -1);
 gbuf[256 -1] = '\000';
 gptr = p;
 p = gbuf;
 for (i = 0; gbuf[i] && i < 256 && gargc < 32; i++) {
     if (!flag) {
  if (gbuf[i] <= '\040')
    continue;
  flag = 1;
  gargs[gargc++] = &gbuf[i];
     } else if (flag && gbuf[i] <= '\040') {
  gbuf[i] = '\000';
  flag = 0;
  continue;
     }
 }
 xv = xargv;
 xc = xargc;
 xargv = gargs;
 xargc = gargc;
 while (xargc-- > 0) {
     if (**xargv == '-') {
  c = *(*xargv+1);
  x = doarg(c);
  if (x < 0) doexit(1);
     } else {
  fprintf(stderr,
   "?GKERMIT variable option error: \"%s\"\n",
   *xargv
   );
  usage();
  doexit(0);
     }
     xargv++;
 }
 xargv = xv;
 xargc = xc;
    }
    while (--xargc > 0) {
 xargv++;
     if (**xargv == '-') {
     c = *(*xargv+1);
     x = doarg(c);
     if (x < 0) doexit(1);
     } else {
     fprintf(stderr,"?Command-line option error: \"%s\"\n", *xargv);
     usage();
     doexit(1);
 }
    }
    return(action);
}

canonical_original_code:
int cmdlin() {
    char c;
    int x;
    char *p = ((void *)0);
    cmarg = "";
    cmlist = ((void *)0);
    action = 0;
    if ((p = getenv("GKERMIT"))) {
 int i; int xc; int flag = 0;
 char **xv = ((void *)0);
 strncpy(gbuf,p,256 -1);
 gbuf[256 -1] = '\000';
 gptr = p;
 p = gbuf;
 for (i = 0; gbuf[i] && i < 256 && gargc < 32; i++) {
     if (!flag) {
  if (gbuf[i] <= '\040')
    continue;
  flag = 1;
  gargs[gargc++] = &gbuf[i];
     } else if (flag && gbuf[i] <= '\040') {
  gbuf[i] = '\000';
  flag = 0;
  continue;
     }
 }
 xv = xargv;
 xc = xargc;
 xargv = gargs;
 xargc = gargc;
 while (xargc-- > 0) {
     if (**xargv == '-') {
  c = *(*xargv+1);
  x = doarg(c);
  if (x < 0) doexit(1);
     } else {
  fprintf(stderr,
   "?GKERMIT variable option error: \"%s\"\n",
   *xargv
   );
  usage();
  doexit(0);
     }
     xargv++;
 }
 xargv = xv;
 xargc = xc;
    }
    while (--xargc > 0) {
 xargv++;
     if (**xargv == '-') {
     c = *(*xargv+1);
     x = doarg(c);
     if (x < 0) doexit(1);
     } else {
     fprintf(stderr,"?Command-line option error: \"%s\"\n", *xargv);
     usage();
     doexit(1);
 }
    }
    return(action);
}

variable_types: c char

variable_types: x int

variable_types:
p
char *

variable_types: xc int

variable_types: flag int

variable_types:
xv
char **


streamon

decompiled_code:
void streamon()
{
if ( streamok > 0 )
{
streaming = 1;
timint = 0;
}
}

canonical_decompiled_code:
void func0()
{
if ( streamok > 0 )
{
streaming = 1;
timint = 0;
}
}

original_code:
static void
streamon() {
    x = 0;
    if (streamok > 0) {
 streaming = 1;
 timint = 0;
    }
}