decompiled_code:
__int64 __fastcall bin_table_new(__int64 a1, const void *a2, int a3, int a4, int a5, int a6, int a7)
{
__int64 v8; // r13
int v11; // er8
_DWORD *v14; // rax
_DWORD *v15; // r15
size_t v16; // r13
void *v17; // rax
__int64 v18; // rdi
int *v19; // rcx
int v20; // esi
__int64 v21; // r9
int v22; // edx
int v23; // eax
__int64 n; // [rsp+8h] [rbp-50h]
__int64 v25; // [rsp+10h] [rbp-48h]

v8 = a4;
*(_DWORD *)(a1 + 24) = a6;
v11 = a7;
*(_DWORD *)(a1 + 28) = a7;
if ( a4 <= 0 || a3 <= 0 )
{
if ( !a6 )
goto LABEL_4;
fwrite("ERROR: bin_table: rows or collumns is less than 1\n", 1uLL, 0x32uLL, stderr);
if ( *(_DWORD *)(a1 + 28) )
LABEL_29:
exit(1);
return 0LL;
}
*(_DWORD *)(a1 + 20) = a4;
*(_DWORD *)(a1 + 16) = a3;
v25 = a3;
n = 24LL * a3;
v14 = malloc(n);
*(_QWORD *)a1 = v14;
v15 = v14;
memcpy(v14, a2, n);
v16 = 8 * v25 * v8;
v17 = malloc(v16);
v11 = a7;
*(_QWORD *)(a1 + 8) = v17;
v18 = (__int64)v17;
if ( !v17 )
{
if ( a6 )
fprintf(stderr, "ERROR: bin_table: could not allocate %zu bytes for table\n", v16);
if ( *(_DWORD *)(a1 + 28) )
goto LABEL_29;
return 0LL;
}
if ( a5 < 0 )
{
if ( a6 )
{
fwrite(
"ERROR: bin_table: max_total_width can not be less than zero. zero means no maximum.\n",
1uLL,
0x54uLL,
stderr);
v11 = *(_DWORD *)(a1 + 28);
}
goto LABEL_4;
}
v19 = v15 + 2;
v20 = 0;
v21 = -1LL;
v22 = 0;
do
{
v23 = *v19;
if ( *v19 != -1 )
{
if ( v23 > 0 )
{
v20 += v23;
goto LABEL_11;
}
if ( a6 )
{
fwrite("ERROR: bin_table: width of collumn can only be -1 of greater than zero\n", 1uLL, 0x47uLL, stderr);
v11 = *(_DWORD *)(a1 + 28);
}
LABEL_4:
if ( v11 )
goto LABEL_29;
return 0LL;
}
if ( (_DWORD)v21 != -1 )
{
if ( a6 )
{
fwrite("ERROR: bin_table: table can only have one padding collumn\n", 1uLL, 0x3AuLL, stderr);
v11 = *(_DWORD *)(a1 + 28);
}
goto LABEL_4;
}
if ( !a5 )
{
if ( a6 )
{
fwrite(
"ERROR: bin_table: table has padding collumn but no max total width is specified\n",
1uLL,
0x50uLL,
stderr);
v11 = *(_DWORD *)(a1 + 28);
}
goto LABEL_4;
}
v21 = v22;
LABEL_11:
if ( v20 > a5 )
{
if ( a6 )
{
fwrite(
"ERROR: bin_table: total width of collumns is greater than the maximum total width\n",
1uLL,
0x52uLL,
stderr);
v11 = *(_DWORD *)(a1 + 28);
}
goto LABEL_4;
}
++v22;
v19 += 6;
}
while ( a3 > v22 );
if ( (_DWORD)v21 != -1 )
v15[6 * v21 + 2] = a5 - v20;
initialize_table_isra_0(v18, *(_DWORD *)(a1 + 16), *(_DWORD *)(a1 + 20));
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const void *a2, int a3, int a4, int a5, int a6, int a7)
{
__int64 v8; // r13
int v11; // er8
_DWORD *v14; // rax
_DWORD *v15; // r15
size_t v16; // r13
void *v17; // rax
__int64 v18; // rdi
int *v19; // rcx
int v20; // esi
__int64 v21; // r9
int v22; // edx
int v23; // eax
__int64 n; // [rsp+8h] [rbp-50h]
__int64 v25; // [rsp+10h] [rbp-48h]

v8 = a4;
*(_DWORD *)(a1 + 24) = a6;
v11 = a7;
*(_DWORD *)(a1 + 28) = a7;
if ( a4 <= 0 || a3 <= 0 )
{
if ( !a6 )
goto LABEL_4;
fwrite("ERROR: bin_table: rows or collumns is less than 1\n", 1uLL, 0x32uLL, stderr);
if ( *(_DWORD *)(a1 + 28) )
LABEL_29:
exit(1);
return 0LL;
}
*(_DWORD *)(a1 + 20) = a4;
*(_DWORD *)(a1 + 16) = a3;
v25 = a3;
n = 24LL * a3;
v14 = malloc(n);
*(_QWORD *)a1 = v14;
v15 = v14;
memcpy(v14, a2, n);
v16 = 8 * v25 * v8;
v17 = malloc(v16);
v11 = a7;
*(_QWORD *)(a1 + 8) = v17;
v18 = (__int64)v17;
if ( !v17 )
{
if ( a6 )
fprintf(stderr, "ERROR: bin_table: could not allocate %zu bytes for table\n", v16);
if ( *(_DWORD *)(a1 + 28) )
goto LABEL_29;
return 0LL;
}
if ( a5 < 0 )
{
if ( a6 )
{
fwrite(
"ERROR: bin_table: max_total_width can not be less than zero. zero means no maximum.\n",
1uLL,
0x54uLL,
stderr);
v11 = *(_DWORD *)(a1 + 28);
}
goto LABEL_4;
}
v19 = v15 + 2;
v20 = 0;
v21 = -1LL;
v22 = 0;
do
{
v23 = *v19;
if ( *v19 != -1 )
{
if ( v23 > 0 )
{
v20 += v23;
goto LABEL_11;
}
if ( a6 )
{
fwrite("ERROR: bin_table: width of collumn can only be -1 of greater than zero\n", 1uLL, 0x47uLL, stderr);
v11 = *(_DWORD *)(a1 + 28);
}
LABEL_4:
if ( v11 )
goto LABEL_29;
return 0LL;
}
if ( (_DWORD)v21 != -1 )
{
if ( a6 )
{
fwrite("ERROR: bin_table: table can only have one padding collumn\n", 1uLL, 0x3AuLL, stderr);
v11 = *(_DWORD *)(a1 + 28);
}
goto LABEL_4;
}
if ( !a5 )
{
if ( a6 )
{
fwrite(
"ERROR: bin_table: table has padding collumn but no max total width is specified\n",
1uLL,
0x50uLL,
stderr);
v11 = *(_DWORD *)(a1 + 28);
}
goto LABEL_4;
}
v21 = v22;
LABEL_11:
if ( v20 > a5 )
{
if ( a6 )
{
fwrite(
"ERROR: bin_table: total width of collumns is greater than the maximum total width\n",
1uLL,
0x52uLL,
stderr);
v11 = *(_DWORD *)(a1 + 28);
}
goto LABEL_4;
}
++v22;
v19 += 6;
}
while ( a3 > v22 );
if ( (_DWORD)v21 != -1 )
v15[6 * v21 + 2] = a5 - v20;
func0(v18, *(_DWORD *)(a1 + 16), *(_DWORD *)(a1 + 20));
return 1LL;
}

original_code:
int bin_table_new(bin_table* table, bin_table_collumn_description* collumn_descriptions, int collumns, int rows, int max_total_width, int print_on_error, int exit_on_error)
{
 table->print_on_error = print_on_error;
 table->exit_on_error = exit_on_error;
 if(rows < 1 || collumns < 1)
 {
  do { if(table->print_on_error) { fprintf(stderr, "ERROR: bin_table: ""rows or collumns is less than 1""\n"); } if(table->exit_on_error) { exit(1); } } while(0);
  return 0;
 }
 table->rows = rows;
 table->collumns = collumns;
 size_t col_descrs_size = collumns*sizeof(bin_table_collumn_description);
 table->collumn_descriptions = malloc(col_descrs_size);
 memcpy(table->collumn_descriptions, collumn_descriptions, col_descrs_size);
 size_t cells_size = sizeof(bin_table_cell)*collumns*rows;
 table->cells = malloc(cells_size);
 if(table->cells == ((void *)0))
 {
  do { if(table->print_on_error) { fprintf(stderr, "ERROR: bin_table: ""could not allocate %zu bytes for table""\n", cells_size); } if(table->exit_on_error) { exit(1); } } while(0); return 0;
 }
 if(max_total_width < 0)
 {
  do { if(table->print_on_error) { fprintf(stderr, "ERROR: bin_table: ""max_total_width can not be less than zero. zero means no maximum.""\n"); } if(table->exit_on_error) { exit(1); } } while(0); return 0;
 }
 int n;
 int padding_collumn = -1;
 int total_width = 0;
 for(n = 0; n < collumns; ++n)
 {
  if(table->collumn_descriptions[n].width == -1)
  {
   if(padding_collumn == -1)
   {
    if(max_total_width != 0)
    {
     padding_collumn = n;
    }
    else
    {
     do { if(table->print_on_error) { fprintf(stderr, "ERROR: bin_table: ""table has padding collumn but no max total width is specified""\n"); } if(table->exit_on_error) { exit(1); } } while(0); return 0;
    }
   }
   else
   {
    do { if(table->print_on_error) { fprintf(stderr, "ERROR: bin_table: ""table can only have one padding collumn""\n"); } if(table->exit_on_error) { exit(1); } } while(0); return 0;
   }
  }
  else if(table->collumn_descriptions[n].width <= 0)
  {
   do { if(table->print_on_error) { fprintf(stderr, "ERROR: bin_table: ""width of collumn can only be -1 of greater than zero""\n"); } if(table->exit_on_error) { exit(1); } } while(0); return 0;
  }
  else
  {
   total_width += table->collumn_descriptions[n].width;
  }
  if(total_width > max_total_width)
  {
   do { if(table->print_on_error) { fprintf(stderr, "ERROR: bin_table: ""total width of collumns is greater than the maximum total width""\n"); } if(table->exit_on_error) { exit(1); } } while(0); return 0;
  }
 }
 if(padding_collumn != -1)
 {
  table->collumn_descriptions[padding_collumn].width = max_total_width - total_width;
 }
 initialize_table(table);
 return 1;
}

canonical_original_code:
int bin_table_new(struct bin_table *table, struct bin_table_collumn_description *collumn_descriptions, int collumns, int rows, int max_total_width, int print_on_error, int exit_on_error)
{
 table->print_on_error = print_on_error;
 table->exit_on_error = exit_on_error;
 if(rows < 1 || collumns < 1)
 {
  do { if(table->print_on_error) { fprintf(stderr, "ERROR: bin_table: ""rows or collumns is less than 1""\n"); } if(table->exit_on_error) { exit(1); } } while(0);
  return 0;
 }
 table->rows = rows;
 table->collumns = collumns;
 unsigned long col_descrs_size = collumns*sizeof(bin_table_collumn_description);
 table->collumn_descriptions = malloc(col_descrs_size);
 memcpy(table->collumn_descriptions, collumn_descriptions, col_descrs_size);
 unsigned long cells_size = sizeof(bin_table_cell)*collumns*rows;
 table->cells = malloc(cells_size);
 if(table->cells == ((void *)0))
 {
  do { if(table->print_on_error) { fprintf(stderr, "ERROR: bin_table: ""could not allocate %zu bytes for table""\n", cells_size); } if(table->exit_on_error) { exit(1); } } while(0); return 0;
 }
 if(max_total_width < 0)
 {
  do { if(table->print_on_error) { fprintf(stderr, "ERROR: bin_table: ""max_total_width can not be less than zero. zero means no maximum.""\n"); } if(table->exit_on_error) { exit(1); } } while(0); return 0;
 }
 int n;
 int padding_collumn = -1;
 int total_width = 0;
 for(n = 0; n < collumns; ++n)
 {
  if(table->collumn_descriptions[n].width == -1)
  {
   if(padding_collumn == -1)
   {
    if(max_total_width != 0)
    {
     padding_collumn = n;
    }
    else
    {
     do { if(table->print_on_error) { fprintf(stderr, "ERROR: bin_table: ""table has padding collumn but no max total width is specified""\n"); } if(table->exit_on_error) { exit(1); } } while(0); return 0;
    }
   }
   else
   {
    do { if(table->print_on_error) { fprintf(stderr, "ERROR: bin_table: ""table can only have one padding collumn""\n"); } if(table->exit_on_error) { exit(1); } } while(0); return 0;
   }
  }
  else if(table->collumn_descriptions[n].width <= 0)
  {
   do { if(table->print_on_error) { fprintf(stderr, "ERROR: bin_table: ""width of collumn can only be -1 of greater than zero""\n"); } if(table->exit_on_error) { exit(1); } } while(0); return 0;
  }
  else
  {
   total_width += table->collumn_descriptions[n].width;
  }
  if(total_width > max_total_width)
  {
   do { if(table->print_on_error) { fprintf(stderr, "ERROR: bin_table: ""total width of collumns is greater than the maximum total width""\n"); } if(table->exit_on_error) { exit(1); } } while(0); return 0;
  }
 }
 if(padding_collumn != -1)
 {
  table->collumn_descriptions[padding_collumn].width = max_total_width - total_width;
 }
 initialize_table(table);
 return 1;
}

variable_types: struct bin_table { struct bin_table_collumn_description { char *name; int width; int active_high; int index; } *collumn_descriptions; struct bin_table_cell { unsigned int value; unsigned int is_known; } *cells; int collumns; int rows; int print_on_error; int exit_on_error; } *

variable_types: collumns int

variable_types: rows int


decompiled_code:
void __fastcall bin_table_free(void **a1)
{
free(a1[1]);
free(*a1);
}

canonical_decompiled_code:
void __fastcall func2(void **a1)
{
free(a1[1]);
free(*a1);
}

original_code:
void bin_table_free(bin_table* table)
{
 free(table->cells);
 free(table->collumn_descriptions);
}

canonical_original_code:
void bin_table_free(struct bin_table *table)
{
 free(table->cells);
 free(table->collumn_descriptions);
}

return_type: void

user_defined_types: struct bin_table { struct bin_table_collumn_description *collumn_descriptions; struct bin_table_cell *cells; int collumns; int rows; int print_on_error; int exit_on_error; }

user_defined_types: struct bin_table_collumn_description { char *name; int width; int active_high; int index; }

user_defined_types: struct bin_table_cell { unsigned int value; unsigned int is_known; }


decompiled_code:
__int64 __fastcall bin_table_set_cell_value(__int64 a1, int a2, int a3, int a4)
{
int v5; // eax
__int64 v7; // r10
unsigned int v8; // ecx
int *v9; // rax

if ( *(_DWORD *)(a1 + 20) > a3 )
{
v5 = *(_DWORD *)(a1 + 16);
if ( v5 > a2 )
{
v7 = *(_QWORD *)a1 + 24LL * a2;
v8 = *(_DWORD *)(v7 + 8);
if ( 1 << v8 > a4 )
{
v9 = (int *)(*(_QWORD *)(a1 + 8) + 8LL * (v5 * a3 + a2));
*v9 = a4;
v9[1] = 1;
return 1LL;
}
if ( *(_DWORD *)(a1 + 24) )
fprintf(
stderr,
"ERROR: bin_table: value %d does not fit in collumn %s with width %d\n",
(unsigned int)a4,
*(const char **)v7,
v8);
}
else if ( *(_DWORD *)(a1 + 24) )
{
fwrite("ERROR: bin_table: collumn_index > number of collumns in table\n", 1uLL, 0x3EuLL, stderr);
}
}
else if ( *(_DWORD *)(a1 + 24) )
{
fwrite("ERROR: bin_table: row > number of rows in table\n", 1uLL, 0x30uLL, stderr);
}
if ( *(_DWORD *)(a1 + 28) )
exit(1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2, int a3, int a4)
{
int v5; // eax
__int64 v7; // r10
unsigned int v8; // ecx
int *v9; // rax

if ( *(_DWORD *)(a1 + 20) > a3 )
{
v5 = *(_DWORD *)(a1 + 16);
if ( v5 > a2 )
{
v7 = *(_QWORD *)a1 + 24LL * a2;
v8 = *(_DWORD *)(v7 + 8);
if ( 1 << v8 > a4 )
{
v9 = (int *)(*(_QWORD *)(a1 + 8) + 8LL * (v5 * a3 + a2));
*v9 = a4;
v9[1] = 1;
return 1LL;
}
if ( *(_DWORD *)(a1 + 24) )
fprintf(
stderr,
"ERROR: bin_table: value %d does not fit in collumn %s with width %d\n",
(unsigned int)a4,
*(const char **)v7,
v8);
}
else if ( *(_DWORD *)(a1 + 24) )
{
fwrite("ERROR: bin_table: collumn_index > number of collumns in table\n", 1uLL, 0x3EuLL, stderr);
}
}
else if ( *(_DWORD *)(a1 + 24) )
{
fwrite("ERROR: bin_table: row > number of rows in table\n", 1uLL, 0x30uLL, stderr);
}
if ( *(_DWORD *)(a1 + 28) )
exit(1);
return 0LL;
}

original_code:
int bin_table_set_cell_value(bin_table* table, int collumn_index, int row, int value)
{
 if(row >= table->rows)
 {
  do { if(table->print_on_error) { fprintf(stderr, "ERROR: bin_table: ""row > number of rows in table""\n"); } if(table->exit_on_error) { exit(1); } } while(0); return 0;
 }
 if(collumn_index >= table->collumns)
 {
  do { if(table->print_on_error) { fprintf(stderr, "ERROR: bin_table: ""collumn_index > number of collumns in table""\n"); } if(table->exit_on_error) { exit(1); } } while(0); return 0;
 }
 if(value >= (1 << table->collumn_descriptions[collumn_index].width))
 {
  do { if(table->print_on_error) { fprintf(stderr, "ERROR: bin_table: ""value %d does not fit in collumn %s with width %d""\n", value, table->collumn_descriptions[collumn_index].name, table->collumn_descriptions[collumn_index].width); } if(table->exit_on_error) { exit(1); } } while(0);
  return 0;
 }
 table->cells[row*table->collumns + collumn_index] = (bin_table_cell){.value = value, .is_known = 1};
 return 1;
}

canonical_original_code:
int bin_table_set_cell_value(struct bin_table *table, int collumn_index, int row, int value)
{
 if(row >= table->rows)
 {
  do { if(table->print_on_error) { fprintf(stderr, "ERROR: bin_table: ""row > number of rows in table""\n"); } if(table->exit_on_error) { exit(1); } } while(0); return 0;
 }
 if(collumn_index >= table->collumns)
 {
  do { if(table->print_on_error) { fprintf(stderr, "ERROR: bin_table: ""collumn_index > number of collumns in table""\n"); } if(table->exit_on_error) { exit(1); } } while(0); return 0;
 }
 if(value >= (1 << table->collumn_descriptions[collumn_index].width))
 {
  do { if(table->print_on_error) { fprintf(stderr, "ERROR: bin_table: ""value %d does not fit in collumn %s with width %d""\n", value, table->collumn_descriptions[collumn_index].name, table->collumn_descriptions[collumn_index].width); } if(table->exit_on_error) { exit(1); } } while(0);
  return 0;
 }
 table->cells[row*table->collumns + collumn_index] = (struct bin_table_cell){.value = value, .is_known = 1};
 return 1;
}

variable_types: row int

variable_types: value int

return_type: int


decompiled_code:
__int64 __fastcall bin_table_set_row_inactive(__int64 a1, int a2)
{
__int64 v2; // rbx
int v3; // ecx
__int64 v4; // rax

if ( *(int *)(a1 + 16) <= 0 )
return 1LL;
v2 = 0LL;
do
{
v4 = *(_QWORD *)a1 + 24 * v2;
if ( *(_DWORD *)(v4 + 12) )
v3 = 0;
else
v3 = (1 << *(_DWORD *)(v4 + 8)) - 1;
if ( !(unsigned int)bin_table_set_cell_value(a1, v2, a2, v3) )
return 0LL;
++v2;
}
while ( *(_DWORD *)(a1 + 16) > (int)v2 );
return 1LL;
}

original_code:
int bin_table_set_row_inactive(bin_table* table, int row)
{
 int n;
 for(n = 0; n < table->collumns; ++n)
 {
  if(table->collumn_descriptions[n].active_high)
  {
   if(!bin_table_set_cell_value(table, n, row, 0))
    return 0;
  }
  else
  {
   if(!bin_table_set_cell_value(table, n, row, (1 << table->collumn_descriptions[n].width) - 1))
    return 0;
  }
 }
 return 1;
}

canonical_original_code:
int bin_table_set_row_inactive(struct bin_table *table, int row)
{
 int n;
 for(n = 0; n < table->collumns; ++n)
 {
  if(table->collumn_descriptions[n].active_high)
  {
   if(!bin_table_set_cell_value(table, n, row, 0))
    return 0;
  }
  else
  {
   if(!bin_table_set_cell_value(table, n, row, (1 << table->collumn_descriptions[n].width) - 1))
    return 0;
  }
 }
 return 1;
}

variable_types: n int


decompiled_code:
__int64 __fastcall bin_table_get_cell_value(__int64 a1, int a2, int a3, _DWORD *a4)
{
int v5; // eax
_DWORD *v6; // rax

if ( *(_DWORD *)(a1 + 20) <= a3 )
{
if ( *(_DWORD *)(a1 + 24) )
{
fwrite("ERROR: bin_table: row > number of rows in table\n", 1uLL, 0x30uLL, stderr);
if ( !*(_DWORD *)(a1 + 28) )
return 0LL;
goto LABEL_11;
}
LABEL_3:
if ( !*(_DWORD *)(a1 + 28) )
return 0LL;
LABEL_11:
exit(1);
}
v5 = *(_DWORD *)(a1 + 16);
if ( v5 <= a2 )
{
if ( *(_DWORD *)(a1 + 24) )
fwrite("ERROR: bin_table: collumn_index > number of collumns in table\n", 1uLL, 0x3EuLL, stderr);
goto LABEL_3;
}
v6 = (_DWORD *)(*(_QWORD *)(a1 + 8) + 8LL * (v5 * a3 + a2));
if ( !v6[1] )
return 0LL;
*a4 = *v6;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2, int a3, _DWORD *a4)
{
int v5; // eax
_DWORD *v6; // rax

if ( *(_DWORD *)(a1 + 20) <= a3 )
{
if ( *(_DWORD *)(a1 + 24) )
{
fwrite("ERROR: bin_table: row > number of rows in table\n", 1uLL, 0x30uLL, stderr);
if ( !*(_DWORD *)(a1 + 28) )
return 0LL;
goto LABEL_11;
}
LABEL_3:
if ( !*(_DWORD *)(a1 + 28) )
return 0LL;
LABEL_11:
exit(1);
}
v5 = *(_DWORD *)(a1 + 16);
if ( v5 <= a2 )
{
if ( *(_DWORD *)(a1 + 24) )
fwrite("ERROR: bin_table: collumn_index > number of collumns in table\n", 1uLL, 0x3EuLL, stderr);
goto LABEL_3;
}
v6 = (_DWORD *)(*(_QWORD *)(a1 + 8) + 8LL * (v5 * a3 + a2));
if ( !v6[1] )
return 0LL;
*a4 = *v6;
return 1LL;
}

original_code:
int bin_table_get_cell_value(bin_table* table, int collumn_index, int row, int* out_val)
{
 if(row >= table->rows)
 {
  do { if(table->print_on_error) { fprintf(stderr, "ERROR: bin_table: ""row > number of rows in table""\n"); } if(table->exit_on_error) { exit(1); } } while(0); return 0;
 }
 if(collumn_index >= table->collumns)
 {
  do { if(table->print_on_error) { fprintf(stderr, "ERROR: bin_table: ""collumn_index > number of collumns in table""\n"); } if(table->exit_on_error) { exit(1); } } while(0); return 0;
 }
 if(!table->cells[row*table->collumns + collumn_index].is_known)
  return 0;
 *out_val = table->cells[row*table->collumns + collumn_index].value;
 return 1;
}

canonical_original_code:
int bin_table_get_cell_value(struct bin_table *table, int collumn_index, int row, int *out_val)
{
 if(row >= table->rows)
 {
  do { if(table->print_on_error) { fprintf(stderr, "ERROR: bin_table: ""row > number of rows in table""\n"); } if(table->exit_on_error) { exit(1); } } while(0); return 0;
 }
 if(collumn_index >= table->collumns)
 {
  do { if(table->print_on_error) { fprintf(stderr, "ERROR: bin_table: ""collumn_index > number of collumns in table""\n"); } if(table->exit_on_error) { exit(1); } } while(0); return 0;
 }
 if(!table->cells[row*table->collumns + collumn_index].is_known)
  return 0;
 *out_val = table->cells[row*table->collumns + collumn_index].value;
 return 1;
}


decompiled_code:
__int64 __fastcall bin_table_copy_row(__int64 a1, int a2, int a3)
{
int v3; // eax

v3 = *(_DWORD *)(a1 + 20);
if ( v3 > a2 )
{
if ( v3 > a3 )
{
memcpy(
(void *)(*(_QWORD *)(a1 + 8) + 8LL * *(_DWORD *)(a1 + 16) * a2),
(const void *)(*(_QWORD *)(a1 + 8) + 8LL * *(_DWORD *)(a1 + 16) * a3),
8LL * *(int *)(a1 + 16));
return 1LL;
}
if ( *(_DWORD *)(a1 + 24) )
fwrite("ERROR: bin_table: src row > number of rows\n", 1uLL, 0x2BuLL, stderr);
}
else if ( *(_DWORD *)(a1 + 24) )
{
fwrite("ERROR: bin_table: dest row > number of rows\n", 1uLL, 0x2CuLL, stderr);
}
if ( *(_DWORD *)(a1 + 28) )
exit(1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2, int a3)
{
int v3; // eax

v3 = *(_DWORD *)(a1 + 20);
if ( v3 > a2 )
{
if ( v3 > a3 )
{
memcpy(
(void *)(*(_QWORD *)(a1 + 8) + 8LL * *(_DWORD *)(a1 + 16) * a2),
(const void *)(*(_QWORD *)(a1 + 8) + 8LL * *(_DWORD *)(a1 + 16) * a3),
8LL * *(int *)(a1 + 16));
return 1LL;
}
if ( *(_DWORD *)(a1 + 24) )
fwrite("ERROR: bin_table: src row > number of rows\n", 1uLL, 0x2BuLL, stderr);
}
else if ( *(_DWORD *)(a1 + 24) )
{
fwrite("ERROR: bin_table: dest row > number of rows\n", 1uLL, 0x2CuLL, stderr);
}
if ( *(_DWORD *)(a1 + 28) )
exit(1);
return 0LL;
}

original_code:
int bin_table_copy_row(bin_table* table, int dest, int src)
{
 if(dest >= table->rows)
 {
  do { if(table->print_on_error) { fprintf(stderr, "ERROR: bin_table: ""dest row > number of rows""\n"); } if(table->exit_on_error) { exit(1); } } while(0); return 0;
 }
 if(src >= table->rows)
 {
  do { if(table->print_on_error) { fprintf(stderr, "ERROR: bin_table: ""src row > number of rows""\n"); } if(table->exit_on_error) { exit(1); } } while(0); return 0;
 }
 memcpy(&table->cells[dest*table->collumns], &table->cells[src*table->collumns], sizeof(bin_table_cell) * table->collumns);
 return 1;
}

canonical_original_code:
int bin_table_copy_row(struct bin_table *table, int dest, int src)
{
 if(dest >= table->rows)
 {
  do { if(table->print_on_error) { fprintf(stderr, "ERROR: bin_table: ""dest row > number of rows""\n"); } if(table->exit_on_error) { exit(1); } } while(0); return 0;
 }
 if(src >= table->rows)
 {
  do { if(table->print_on_error) { fprintf(stderr, "ERROR: bin_table: ""src row > number of rows""\n"); } if(table->exit_on_error) { exit(1); } } while(0); return 0;
 }
 memcpy(&table->cells[dest*table->collumns], &table->cells[src*table->collumns], sizeof(bin_table_cell) * table->collumns);
 return 1;
}

variable_types: dest int

variable_types: src int


decompiled_code:
__int64 __fastcall bin_table_collumn_by_name(__int64 a1, const char *a2)
{
int v2; // er14
const char **v3; // rbx
unsigned int v4; // er12
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 16);
if ( v2 <= 0 )
{
LABEL_6:
if ( *(_DWORD *)(a1 + 24) )
fprintf(stderr, "ERROR: bin_table: unkown collumn name %s.\n", a2);
if ( *(_DWORD *)(a1 + 28) )
exit(1);
result = 0xFFFFFFFFLL;
}
else
{
v3 = *(const char ***)a1;
v4 = 0;
while ( strcmp(a2, *v3) )
{
++v4;
v3 += 3;
if ( v4 == v2 )
goto LABEL_6;
}
result = v4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, const char *a2)
{
int v2; // er14
const char **v3; // rbx
unsigned int v4; // er12
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 16);
if ( v2 <= 0 )
{
LABEL_6:
if ( *(_DWORD *)(a1 + 24) )
fprintf(stderr, "ERROR: bin_table: unkown collumn name %s.\n", a2);
if ( *(_DWORD *)(a1 + 28) )
exit(1);
result = 0xFFFFFFFFLL;
}
else
{
v3 = *(const char ***)a1;
v4 = 0;
while ( strcmp(a2, *v3) )
{
++v4;
v3 += 3;
if ( v4 == v2 )
goto LABEL_6;
}
result = v4;
}
return result;
}

original_code:
int bin_table_collumn_by_name(bin_table* table, const char* name)
{
 int i;
 for(i = 0; i < table->collumns; i++)
 {
  if(!strcmp(name, table->collumn_descriptions[i].name))
   return i;
 }
 do { if(table->print_on_error) { fprintf(stderr, "ERROR: bin_table: ""unkown collumn name %s.""\n", name); } if(table->exit_on_error) { exit(1); } } while(0);
 return -1;
}

canonical_original_code:
int bin_table_collumn_by_name(struct bin_table *table, char *name)
{
 int i;
 for(i = 0; i < table->collumns; i++)
 {
  if(!strcmp(name, table->collumn_descriptions[i].name))
   return i;
 }
 do { if(table->print_on_error) { fprintf(stderr, "ERROR: bin_table: ""unkown collumn name %s.""\n", name); } if(table->exit_on_error) { exit(1); } } while(0);
 return -1;
}

variable_types:
name
char *

variable_types: i int


decompiled_code:
__int64 __fastcall serial_set_character_size(__int64 a1, int a2)
{
__int64 result; // rax

if ( a2 == 7 )
{
*(_DWORD *)(a1 + 32) |= 0x20u;
return 1LL;
}
if ( a2 > 7 )
{
if ( a2 == 8 )
{
*(_DWORD *)(a1 + 32) |= 0x30u;
return 1LL;
}
}
else
{
if ( a2 == 5 )
return 1LL;
if ( a2 == 6 )
{
*(_DWORD *)(a1 + 32) |= 0x10u;
return 1LL;
}
}
if ( *(_DWORD *)(a1 + 20) )
fprintf(stderr, "ERROR: device %s: unsupported character size: %d\n", *(const char **)(a1 + 8), (unsigned int)a2);
result = *(unsigned int *)(a1 + 16);
if ( (_DWORD)result )
exit(1);
return result;
}

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

if ( a2 == 7 )
{
*(_DWORD *)(a1 + 32) |= 0x20u;
return 1LL;
}
if ( a2 > 7 )
{
if ( a2 == 8 )
{
*(_DWORD *)(a1 + 32) |= 0x30u;
return 1LL;
}
}
else
{
if ( a2 == 5 )
return 1LL;
if ( a2 == 6 )
{
*(_DWORD *)(a1 + 32) |= 0x10u;
return 1LL;
}
}
if ( *(_DWORD *)(a1 + 20) )
fprintf(stderr, "ERROR: device %s: unsupported character size: %d\n", *(const char **)(a1 + 8), (unsigned int)a2);
result = *(unsigned int *)(a1 + 16);
if ( (_DWORD)result )
exit(1);
return result;
}

original_code:
int serial_set_character_size(serial_device* const dev, int char_size)
{
 switch(char_size)
 {
  case 5: dev->tios.c_cflag |= 0000000; break;
  case 6: dev->tios.c_cflag |= 0000020; break;
  case 7: dev->tios.c_cflag |= 0000040; break;
  case 8: dev->tios.c_cflag |= 0000060; break;
  default: do { if(dev->print_on_error) { fprintf(stderr, "ERROR: device %s: ""unsupported character size: %d""\n", dev->path, char_size); } if(dev->exit_on_error) { exit(1); } } while(0); return 0;
 }
 return 1;
}

canonical_original_code:
int serial_set_character_size(struct serial_device *dev, int char_size)
{
 switch(char_size)
 {
  case 5: dev->tios.c_cflag |= 0000000; break;
  case 6: dev->tios.c_cflag |= 0000020; break;
  case 7: dev->tios.c_cflag |= 0000040; break;
  case 8: dev->tios.c_cflag |= 0000060; break;
  default: do { if(dev->print_on_error) { fprintf(stderr, "ERROR: device %s: ""unsupported character size: %d""\n", dev->path, char_size); } if(dev->exit_on_error) { exit(1); } } while(0); return 0;
 }
 return 1;
}

variable_types: struct serial_device { int fd; char *path; int exit_on_error; int print_on_error; struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; } tios; } *

user_defined_types: struct serial_device { int fd; char *path; int exit_on_error; int print_on_error; struct termios tios; }


decompiled_code:
__int64 __fastcall serial_set_in_baudrate(__int64 a1, int a2)
{
__int64 result; // rax

if ( a2 == 600 )
{
cfsetispeed((struct termios *)(a1 + 24), 8u);
return 1LL;
}
if ( a2 > 600 )
{
if ( a2 == 4800 )
{
cfsetispeed((struct termios *)(a1 + 24), 0xCu);
return 1LL;
}
if ( a2 <= 4800 )
{
switch ( a2 )
{
case 1800:
cfsetispeed((struct termios *)(a1 + 24), 0xAu);
return 1LL;
case 2400:
cfsetispeed((struct termios *)(a1 + 24), 0xBu);
return 1LL;
case 1200:
cfsetispeed((struct termios *)(a1 + 24), 9u);
return 1LL;
}
}
else
{
switch ( a2 )
{
case 19200:
cfsetispeed((struct termios *)(a1 + 24), 0xEu);
return 1LL;
case 38400:
cfsetispeed((struct termios *)(a1 + 24), 0xFu);
return 1LL;
case 9600:
cfsetispeed((struct termios *)(a1 + 24), 0xDu);
return 1LL;
}
}
}
else
{
if ( a2 == 134 )
{
cfsetispeed((struct termios *)(a1 + 24), 4u);
return 1LL;
}
if ( a2 <= 134 )
{
switch ( a2 )
{
case 'K':
cfsetispeed((struct termios *)(a1 + 24), 2u);
return 1LL;
case 'n':
cfsetispeed((struct termios *)(a1 + 24), 3u);
return 1LL;
case '2':
cfsetispeed((struct termios *)(a1 + 24), 1u);
return 1LL;
}
}
else
{
switch ( a2 )
{
case 200:
cfsetispeed((struct termios *)(a1 + 24), 6u);
return 1LL;
case 300:
cfsetispeed((struct termios *)(a1 + 24), 7u);
return 1LL;
case 150:
cfsetispeed((struct termios *)(a1 + 24), 5u);
return 1LL;
}
}
}
if ( *(_DWORD *)(a1 + 20) )
fprintf(stderr, "ERROR: device %s: unsupported input baudrate: %d\n", *(const char **)(a1 + 8), (unsigned int)a2);
result = *(unsigned int *)(a1 + 16);
if ( (_DWORD)result )
exit(1);
return result;
}

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

if ( a2 == 600 )
{
cfsetispeed((struct termios *)(a1 + 24), 8u);
return 1LL;
}
if ( a2 > 600 )
{
if ( a2 == 4800 )
{
cfsetispeed((struct termios *)(a1 + 24), 0xCu);
return 1LL;
}
if ( a2 <= 4800 )
{
switch ( a2 )
{
case 1800:
cfsetispeed((struct termios *)(a1 + 24), 0xAu);
return 1LL;
case 2400:
cfsetispeed((struct termios *)(a1 + 24), 0xBu);
return 1LL;
case 1200:
cfsetispeed((struct termios *)(a1 + 24), 9u);
return 1LL;
}
}
else
{
switch ( a2 )
{
case 19200:
cfsetispeed((struct termios *)(a1 + 24), 0xEu);
return 1LL;
case 38400:
cfsetispeed((struct termios *)(a1 + 24), 0xFu);
return 1LL;
case 9600:
cfsetispeed((struct termios *)(a1 + 24), 0xDu);
return 1LL;
}
}
}
else
{
if ( a2 == 134 )
{
cfsetispeed((struct termios *)(a1 + 24), 4u);
return 1LL;
}
if ( a2 <= 134 )
{
switch ( a2 )
{
case 'K':
cfsetispeed((struct termios *)(a1 + 24), 2u);
return 1LL;
case 'n':
cfsetispeed((struct termios *)(a1 + 24), 3u);
return 1LL;
case '2':
cfsetispeed((struct termios *)(a1 + 24), 1u);
return 1LL;
}
}
else
{
switch ( a2 )
{
case 200:
cfsetispeed((struct termios *)(a1 + 24), 6u);
return 1LL;
case 300:
cfsetispeed((struct termios *)(a1 + 24), 7u);
return 1LL;
case 150:
cfsetispeed((struct termios *)(a1 + 24), 5u);
return 1LL;
}
}
}
if ( *(_DWORD *)(a1 + 20) )
fprintf(stderr, "ERROR: device %s: unsupported input baudrate: %d\n", *(const char **)(a1 + 8), (unsigned int)a2);
result = *(unsigned int *)(a1 + 16);
if ( (_DWORD)result )
exit(1);
return result;
}

original_code:
int serial_set_in_baudrate(serial_device* const dev, int in_baudrate)
{
 switch(in_baudrate)
 {
  case 50: cfsetispeed(&(dev->tios), 0000001); break;
  case 75: cfsetispeed(&(dev->tios), 0000002); break;
  case 110: cfsetispeed(&(dev->tios), 0000003); break;
  case 134: cfsetispeed(&(dev->tios), 0000004); break;
  case 150: cfsetispeed(&(dev->tios), 0000005); break;
  case 200: cfsetispeed(&(dev->tios), 0000006); break;
  case 300: cfsetispeed(&(dev->tios), 0000007); break;
  case 600: cfsetispeed(&(dev->tios), 0000010); break;
  case 1200: cfsetispeed(&(dev->tios), 0000011); break;
  case 1800: cfsetispeed(&(dev->tios), 0000012); break;
  case 2400: cfsetispeed(&(dev->tios), 0000013); break;
  case 4800: cfsetispeed(&(dev->tios), 0000014); break;
  case 9600: cfsetispeed(&(dev->tios), 0000015); break;
  case 19200: cfsetispeed(&(dev->tios), 0000016); break;
  case 38400: cfsetispeed(&(dev->tios), 0000017); break;
  default: do { if(dev->print_on_error) { fprintf(stderr, "ERROR: device %s: ""unsupported input baudrate: %d""\n", dev->path, in_baudrate); } if(dev->exit_on_error) { exit(1); } } while(0); return 0;
 }
 return 1;
}

canonical_original_code:
int serial_set_in_baudrate(struct serial_device *dev, int in_baudrate)
{
 switch(in_baudrate)
 {
  case 50: cfsetispeed(&(dev->tios), 0000001); break;
  case 75: cfsetispeed(&(dev->tios), 0000002); break;
  case 110: cfsetispeed(&(dev->tios), 0000003); break;
  case 134: cfsetispeed(&(dev->tios), 0000004); break;
  case 150: cfsetispeed(&(dev->tios), 0000005); break;
  case 200: cfsetispeed(&(dev->tios), 0000006); break;
  case 300: cfsetispeed(&(dev->tios), 0000007); break;
  case 600: cfsetispeed(&(dev->tios), 0000010); break;
  case 1200: cfsetispeed(&(dev->tios), 0000011); break;
  case 1800: cfsetispeed(&(dev->tios), 0000012); break;
  case 2400: cfsetispeed(&(dev->tios), 0000013); break;
  case 4800: cfsetispeed(&(dev->tios), 0000014); break;
  case 9600: cfsetispeed(&(dev->tios), 0000015); break;
  case 19200: cfsetispeed(&(dev->tios), 0000016); break;
  case 38400: cfsetispeed(&(dev->tios), 0000017); break;
  default: do { if(dev->print_on_error) { fprintf(stderr, "ERROR: device %s: ""unsupported input baudrate: %d""\n", dev->path, in_baudrate); } if(dev->exit_on_error) { exit(1); } } while(0); return 0;
 }
 return 1;
}

user_defined_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


decompiled_code:
__int64 __fastcall serial_set_out_baudrate(__int64 a1, int a2)
{
__int64 result; // rax

if ( a2 == 600 )
{
cfsetospeed((struct termios *)(a1 + 24), 8u);
return 1LL;
}
if ( a2 > 600 )
{
if ( a2 == 4800 )
{
cfsetospeed((struct termios *)(a1 + 24), 0xCu);
return 1LL;
}
if ( a2 <= 4800 )
{
switch ( a2 )
{
case 1800:
cfsetospeed((struct termios *)(a1 + 24), 0xAu);
return 1LL;
case 2400:
cfsetospeed((struct termios *)(a1 + 24), 0xBu);
return 1LL;
case 1200:
cfsetospeed((struct termios *)(a1 + 24), 9u);
return 1LL;
}
}
else
{
switch ( a2 )
{
case 19200:
cfsetospeed((struct termios *)(a1 + 24), 0xEu);
return 1LL;
case 38400:
cfsetospeed((struct termios *)(a1 + 24), 0xFu);
return 1LL;
case 9600:
cfsetospeed((struct termios *)(a1 + 24), 0xDu);
return 1LL;
}
}
}
else
{
if ( a2 == 134 )
{
cfsetospeed((struct termios *)(a1 + 24), 4u);
return 1LL;
}
if ( a2 <= 134 )
{
switch ( a2 )
{
case 'K':
cfsetospeed((struct termios *)(a1 + 24), 2u);
return 1LL;
case 'n':
cfsetospeed((struct termios *)(a1 + 24), 3u);
return 1LL;
case '2':
cfsetospeed((struct termios *)(a1 + 24), 1u);
return 1LL;
}
}
else
{
switch ( a2 )
{
case 200:
cfsetospeed((struct termios *)(a1 + 24), 6u);
return 1LL;
case 300:
cfsetospeed((struct termios *)(a1 + 24), 7u);
return 1LL;
case 150:
cfsetospeed((struct termios *)(a1 + 24), 5u);
return 1LL;
}
}
}
if ( *(_DWORD *)(a1 + 20) )
fprintf(stderr, "ERROR: device %s: unsupported output baudrate: %d\n", *(const char **)(a1 + 8), (unsigned int)a2);
result = *(unsigned int *)(a1 + 16);
if ( (_DWORD)result )
exit(1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
__int64 result; // rax

if ( a2 == 600 )
{
cfsetospeed((struct termios *)(a1 + 24), 8u);
return 1LL;
}
if ( a2 > 600 )
{
if ( a2 == 4800 )
{
cfsetospeed((struct termios *)(a1 + 24), 0xCu);
return 1LL;
}
if ( a2 <= 4800 )
{
switch ( a2 )
{
case 1800:
cfsetospeed((struct termios *)(a1 + 24), 0xAu);
return 1LL;
case 2400:
cfsetospeed((struct termios *)(a1 + 24), 0xBu);
return 1LL;
case 1200:
cfsetospeed((struct termios *)(a1 + 24), 9u);
return 1LL;
}
}
else
{
switch ( a2 )
{
case 19200:
cfsetospeed((struct termios *)(a1 + 24), 0xEu);
return 1LL;
case 38400:
cfsetospeed((struct termios *)(a1 + 24), 0xFu);
return 1LL;
case 9600:
cfsetospeed((struct termios *)(a1 + 24), 0xDu);
return 1LL;
}
}
}
else
{
if ( a2 == 134 )
{
cfsetospeed((struct termios *)(a1 + 24), 4u);
return 1LL;
}
if ( a2 <= 134 )
{
switch ( a2 )
{
case 'K':
cfsetospeed((struct termios *)(a1 + 24), 2u);
return 1LL;
case 'n':
cfsetospeed((struct termios *)(a1 + 24), 3u);
return 1LL;
case '2':
cfsetospeed((struct termios *)(a1 + 24), 1u);
return 1LL;
}
}
else
{
switch ( a2 )
{
case 200:
cfsetospeed((struct termios *)(a1 + 24), 6u);
return 1LL;
case 300:
cfsetospeed((struct termios *)(a1 + 24), 7u);
return 1LL;
case 150:
cfsetospeed((struct termios *)(a1 + 24), 5u);
return 1LL;
}
}
}
if ( *(_DWORD *)(a1 + 20) )
fprintf(stderr, "ERROR: device %s: unsupported output baudrate: %d\n", *(const char **)(a1 + 8), (unsigned int)a2);
result = *(unsigned int *)(a1 + 16);
if ( (_DWORD)result )
exit(1);
return result;
}

original_code:
int serial_set_out_baudrate(serial_device* const dev, int out_baudrate)
{
 switch(out_baudrate)
 {
  case 50: cfsetospeed(&(dev->tios), 0000001); break;
  case 75: cfsetospeed(&(dev->tios), 0000002); break;
  case 110: cfsetospeed(&(dev->tios), 0000003); break;
  case 134: cfsetospeed(&(dev->tios), 0000004); break;
  case 150: cfsetospeed(&(dev->tios), 0000005); break;
  case 200: cfsetospeed(&(dev->tios), 0000006); break;
  case 300: cfsetospeed(&(dev->tios), 0000007); break;
  case 600: cfsetospeed(&(dev->tios), 0000010); break;
  case 1200: cfsetospeed(&(dev->tios), 0000011); break;
  case 1800: cfsetospeed(&(dev->tios), 0000012); break;
  case 2400: cfsetospeed(&(dev->tios), 0000013); break;
  case 4800: cfsetospeed(&(dev->tios), 0000014); break;
  case 9600: cfsetospeed(&(dev->tios), 0000015); break;
  case 19200: cfsetospeed(&(dev->tios), 0000016); break;
  case 38400: cfsetospeed(&(dev->tios), 0000017); break;
  default: do { if(dev->print_on_error) { fprintf(stderr, "ERROR: device %s: ""unsupported output baudrate: %d""\n", dev->path, out_baudrate); } if(dev->exit_on_error) { exit(1); } } while(0); return 0;
 }
 return 1;
}

canonical_original_code:
int serial_set_out_baudrate(struct serial_device *dev, int out_baudrate)
{
 switch(out_baudrate)
 {
  case 50: cfsetospeed(&(dev->tios), 0000001); break;
  case 75: cfsetospeed(&(dev->tios), 0000002); break;
  case 110: cfsetospeed(&(dev->tios), 0000003); break;
  case 134: cfsetospeed(&(dev->tios), 0000004); break;
  case 150: cfsetospeed(&(dev->tios), 0000005); break;
  case 200: cfsetospeed(&(dev->tios), 0000006); break;
  case 300: cfsetospeed(&(dev->tios), 0000007); break;
  case 600: cfsetospeed(&(dev->tios), 0000010); break;
  case 1200: cfsetospeed(&(dev->tios), 0000011); break;
  case 1800: cfsetospeed(&(dev->tios), 0000012); break;
  case 2400: cfsetospeed(&(dev->tios), 0000013); break;
  case 4800: cfsetospeed(&(dev->tios), 0000014); break;
  case 9600: cfsetospeed(&(dev->tios), 0000015); break;
  case 19200: cfsetospeed(&(dev->tios), 0000016); break;
  case 38400: cfsetospeed(&(dev->tios), 0000017); break;
  default: do { if(dev->print_on_error) { fprintf(stderr, "ERROR: device %s: ""unsupported output baudrate: %d""\n", dev->path, out_baudrate); } if(dev->exit_on_error) { exit(1); } } while(0); return 0;
 }
 return 1;
}


decompiled_code:
__int64 __fastcall serial_set_stopbits(__int64 a1, unsigned int a2)
{
__int64 result; // rax

if ( a2 == 1 )
return 1LL;
if ( a2 == 2 )
{
*(_DWORD *)(a1 + 32) |= 0x40u;
result = 1LL;
}
else
{
if ( *(_DWORD *)(a1 + 20) )
fprintf(stderr, "ERROR: device %s: unsupported number of stop-bits: %d\n", *(const char **)(a1 + 8), a2);
result = *(unsigned int *)(a1 + 16);
if ( (_DWORD)result )
exit(1);
}
return result;
}

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

if ( a2 == 1 )
return 1LL;
if ( a2 == 2 )
{
*(_DWORD *)(a1 + 32) |= 0x40u;
result = 1LL;
}
else
{
if ( *(_DWORD *)(a1 + 20) )
fprintf(stderr, "ERROR: device %s: unsupported number of stop-bits: %d\n", *(const char **)(a1 + 8), a2);
result = *(unsigned int *)(a1 + 16);
if ( (_DWORD)result )
exit(1);
}
return result;
}

original_code:
int serial_set_stopbits(serial_device* const dev, int stopbits)
{
 switch(stopbits)
 {
  case 1: break;
  case 2: dev->tios.c_cflag |= 0000100; break;
  default: do { if(dev->print_on_error) { fprintf(stderr, "ERROR: device %s: ""unsupported number of stop-bits: %d""\n", dev->path, stopbits); } if(dev->exit_on_error) { exit(1); } } while(0); return 0;
 }
 return 1;
}

canonical_original_code:
int serial_set_stopbits(struct serial_device *dev, int stopbits)
{
 switch(stopbits)
 {
  case 1: break;
  case 2: dev->tios.c_cflag |= 0000100; break;
  default: do { if(dev->print_on_error) { fprintf(stderr, "ERROR: device %s: ""unsupported number of stop-bits: %d""\n", dev->path, stopbits); } if(dev->exit_on_error) { exit(1); } } while(0); return 0;
 }
 return 1;
}

variable_types: stopbits int


original_code:
void serial_set_parity(serial_device* const dev, int enable_parity, int odd_parity)
{
 if(enable_parity)
 {
  dev->tios.c_cflag |= 0000400;
  if(odd_parity)
   dev->tios.c_cflag |= 0001000;
  dev->tios.c_iflag |= 0000004 | 0000020;
 }
}

canonical_original_code:
void serial_set_parity(struct serial_device *dev, int enable_parity, int odd_parity)
{
 if(enable_parity)
 {
  dev->tios.c_cflag |= 0000400;
  if(odd_parity)
   dev->tios.c_cflag |= 0001000;
  dev->tios.c_iflag |= 0000004 | 0000020;
 }
}


decompiled_code:
__int64 __fastcall serial_flush_settings(__int64 a1)
{
int v1; // er8
__int64 result; // rax
int *v3; // rax
char *v4; // rax

v1 = tcsetattr(*(_DWORD *)a1, 0, (const struct termios *)(a1 + 24));
result = 1LL;
if ( v1 < 0 )
{
if ( *(_DWORD *)(a1 + 20) )
{
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, "ERROR: device %s: setting attributes failed: %s\n", *(const char **)(a1 + 8), v4);
}
result = *(unsigned int *)(a1 + 16);
if ( (_DWORD)result )
exit(1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
int v1; // er8
__int64 result; // rax
int *v3; // rax
char *v4; // rax

v1 = tcsetattr(*(_DWORD *)a1, 0, (const struct termios *)(a1 + 24));
result = 1LL;
if ( v1 < 0 )
{
if ( *(_DWORD *)(a1 + 20) )
{
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, "ERROR: device %s: setting attributes failed: %s\n", *(const char **)(a1 + 8), v4);
}
result = *(unsigned int *)(a1 + 16);
if ( (_DWORD)result )
exit(1);
}
return result;
}

original_code:
int serial_flush_settings(serial_device* const dev)
{
 if(tcsetattr(dev->fd, 0, &(dev->tios)) < 0)
 {
  do { if(dev->print_on_error) { fprintf(stderr, "ERROR: device %s: ""setting attributes failed: %s""\n", dev->path, strerror((*__errno_location ()))); } if(dev->exit_on_error) { exit(1); } } while(0); return 0;
 }
 return 1;
}

canonical_original_code:
int serial_flush_settings(struct serial_device *dev)
{
 if(tcsetattr(dev->fd, 0, &(dev->tios)) < 0)
 {
  do { if(dev->print_on_error) { fprintf(stderr, "ERROR: device %s: ""setting attributes failed: %s""\n", dev->path, strerror((*__errno_location ()))); } if(dev->exit_on_error) { exit(1); } } while(0); return 0;
 }
 return 1;
}


decompiled_code:
_BOOL8 __fastcall serial_open(__int64 a1, const char *a2, int a3, int a4, int a5, unsigned int a6, int a7, int a8, int a9, int a10, unsigned int a11)
{
int v15; // eax
int *v16; // rax
char *v17; // rax

*(_QWORD *)(a1 + 8) = a2;
*(_DWORD *)(a1 + 16) = a10;
*(_DWORD *)(a1 + 32) = 0;
*(_QWORD *)(a1 + 20) = a11;
if ( !(unsigned int)serial_set_character_size(a1, a3)
|| !(unsigned int)serial_set_in_baudrate(a1, a4)
|| !(unsigned int)serial_set_out_baudrate(a1, a5)
|| !(unsigned int)serial_set_stopbits(a1, a6) )
{
return 0LL;
}
serial_set_parity(a1, a7, a8);
*(_DWORD *)(a1 + 32) |= 0x880u;
*(_DWORD *)(a1 + 28) = 0;
*(_DWORD *)(a1 + 36) = 0;
v15 = open(a2, a9 == 0 ? 258 : 1052930);
*(_DWORD *)a1 = v15;
if ( v15 < 0 )
{
if ( *(_DWORD *)(a1 + 20) )
{
v16 = _errno_location();
v17 = strerror(*v16);
fprintf(stderr, "ERROR: device %s: opening failed: %s\n", *(const char **)(a1 + 8), v17);
}
if ( *(_DWORD *)(a1 + 16) )
exit(1);
return 0LL;
}
tcflush(v15, 0);
return (unsigned int)serial_flush_settings(a1) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(__int64 a1, const char *a2, int a3, int a4, int a5, unsigned int a6, int a7, int a8, int a9, int a10, unsigned int a11)
{
int v15; // eax
int *v16; // rax
char *v17; // rax

*(_QWORD *)(a1 + 8) = a2;
*(_DWORD *)(a1 + 16) = a10;
*(_DWORD *)(a1 + 32) = 0;
*(_QWORD *)(a1 + 20) = a11;
if ( !(unsigned int)func0(a1, a3)
|| !(unsigned int)func1(a1, a4)
|| !(unsigned int)func2(a1, a5)
|| !(unsigned int)func3(a1, a6) )
{
return 0LL;
}
func4(a1, a7, a8);
*(_DWORD *)(a1 + 32) |= 0x880u;
*(_DWORD *)(a1 + 28) = 0;
*(_DWORD *)(a1 + 36) = 0;
v15 = open(a2, a9 == 0 ? 258 : 1052930);
*(_DWORD *)a1 = v15;
if ( v15 < 0 )
{
if ( *(_DWORD *)(a1 + 20) )
{
v16 = _errno_location();
v17 = strerror(*v16);
fprintf(stderr, "ERROR: device %s: opening failed: %s\n", *(const char **)(a1 + 8), v17);
}
if ( *(_DWORD *)(a1 + 16) )
exit(1);
return 0LL;
}
tcflush(v15, 0);
return (unsigned int)func5(a1) != 0;
}

original_code:
int serial_open(serial_device* const dev, const char* const path, int char_size,
 int in_baudrate, int out_baudrate, int stopbits, int enable_parity,
 int odd_parity, int sync, int exit_on_error, int print_on_error)
{
 dev->exit_on_error = exit_on_error;
 dev->print_on_error = print_on_error;
 dev->path = path;
 dev->tios.c_cflag = 0;
 dev->tios.c_iflag = 0;
 if(!serial_set_character_size(dev, char_size))
  return 0;
 if(!serial_set_in_baudrate(dev, in_baudrate))
  return 0;
 if(!serial_set_out_baudrate(dev, out_baudrate))
  return 0;
 if(!serial_set_stopbits(dev, stopbits))
  return 0;
 serial_set_parity(dev, enable_parity, odd_parity);
 dev->tios.c_cflag |= 0004000 | 0000200;
 dev->tios.c_oflag = 0;
 dev->tios.c_lflag = 0;
 dev->fd = open(path, 02 | 0400 | (sync ? 04010000: 0));
 if(dev->fd < 0)
 {
  do { if(dev->print_on_error) { fprintf(stderr, "ERROR: device %s: ""opening failed: %s""\n", dev->path, strerror((*__errno_location ()))); } if(dev->exit_on_error) { exit(1); } } while(0); return 0;
 }
 tcflush(dev->fd, 0);
 if(!serial_flush_settings(dev))
  return 0;
 return 1;
}

canonical_original_code:
int serial_open(struct serial_device *dev, char *path, int char_size, int in_baudrate, int out_baudrate, int stopbits, int enable_parity, int odd_parity, int sync, int exit_on_error, int print_on_error)
{
 dev->exit_on_error = exit_on_error;
 dev->print_on_error = print_on_error;
 dev->path = path;
 dev->tios.c_cflag = 0;
 dev->tios.c_iflag = 0;
 if(!serial_set_character_size(dev, char_size))
  return 0;
 if(!serial_set_in_baudrate(dev, in_baudrate))
  return 0;
 if(!serial_set_out_baudrate(dev, out_baudrate))
  return 0;
 if(!serial_set_stopbits(dev, stopbits))
  return 0;
 serial_set_parity(dev, enable_parity, odd_parity);
 dev->tios.c_cflag |= 0004000 | 0000200;
 dev->tios.c_oflag = 0;
 dev->tios.c_lflag = 0;
 dev->fd = open(path, 02 | 0400 | (sync ? 04010000: 0));
 if(dev->fd < 0)
 {
  do { if(dev->print_on_error) { fprintf(stderr, "ERROR: device %s: ""opening failed: %s""\n", dev->path, strerror((*__errno_location ()))); } if(dev->exit_on_error) { exit(1); } } while(0); return 0;
 }
 tcflush(dev->fd, 0);
 if(!serial_flush_settings(dev))
  return 0;
 return 1;
}

variable_types:
path
char *

variable_types: sync int


decompiled_code:
int __fastcall serial_close(int *a1)
{
return close(*a1);
}

canonical_decompiled_code:
int __fastcall func7(int *a1)
{
return close(*a1);
}

original_code:
void serial_close(serial_device* const dev)
{
 close(dev->fd);
}

canonical_original_code:
void serial_close(struct serial_device *dev)
{
 close(dev->fd);
}


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

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

original_code:
int serial_get_fd(const serial_device* const dev)
{
 return dev->fd;
}

canonical_original_code:
int serial_get_fd(struct serial_device *dev)
{
 return dev->fd;
}


decompiled_code:
__int64 __fastcall serial_write(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int v5; // er12
__int64 v6; // rsi
unsigned int v7; // eax
unsigned int v8; // er14
int *v10; // rax
char *v11; // rax

if ( !a3 )
return 0;
v5 = 0;
v6 = 0LL;
while ( 1 )
{
v7 = write(*(_DWORD *)a1, (const void *)(a2 + v6), a3 - v6);
v8 = v7;
if ( v7 == -1 )
break;
v5 += v7;
v6 = (int)v5;
if ( v5 == a3 )
return v5;
}
if ( *(_DWORD *)(a1 + 20) )
{
v10 = _errno_location();
v11 = strerror(*v10);
fprintf(stderr, "ERROR: device %s: writing of %u bytes failed: %s\n", *(const char **)(a1 + 8), a3, v11);
}
if ( *(_DWORD *)(a1 + 16) )
exit(1);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int v5; // er12
__int64 v6; // rsi
unsigned int v7; // eax
unsigned int v8; // er14
int *v10; // rax
char *v11; // rax

if ( !a3 )
return 0;
v5 = 0;
v6 = 0LL;
while ( 1 )
{
v7 = write(*(_DWORD *)a1, (const void *)(a2 + v6), a3 - v6);
v8 = v7;
if ( v7 == -1 )
break;
v5 += v7;
v6 = (int)v5;
if ( v5 == a3 )
return v5;
}
if ( *(_DWORD *)(a1 + 20) )
{
v10 = _errno_location();
v11 = strerror(*v10);
fprintf(stderr, "ERROR: device %s: writing of %u bytes failed: %s\n", *(const char **)(a1 + 8), a3, v11);
}
if ( *(_DWORD *)(a1 + 16) )
exit(1);
return v8;
}

original_code:
int serial_write(const serial_device* const dev, const uint8_t* const buf, const size_t nbytes)
{
 int written = 0;
 int write_return;
 while(written != nbytes)
 {
  write_return = write(dev->fd, (char*) buf + written, nbytes - written);
  if(write_return == -1)
  {
   do { if(dev->print_on_error) { fprintf(stderr, "ERROR: device %s: ""writing of %u bytes failed: %s""\n", dev->path, nbytes, strerror((*__errno_location ()))); } if(dev->exit_on_error) { exit(1); } } while(0); return -1;
  }
  written += write_return;
 }
 return written;
}

canonical_original_code:
int serial_write(struct serial_device *dev, unsigned char *buf, unsigned long nbytes)
{
 int written = 0;
 int write_return;
 while(written != nbytes)
 {
  write_return = write(dev->fd, (char *) buf + written, nbytes - written);
  if(write_return == -1)
  {
   do { if(dev->print_on_error) { fprintf(stderr, "ERROR: device %s: ""writing of %u bytes failed: %s""\n", dev->path, nbytes, strerror((*__errno_location ()))); } if(dev->exit_on_error) { exit(1); } } while(0); return -1;
  }
  written += write_return;
 }
 return written;
}

variable_types:
buf
unsigned char *

variable_types:
nbytes
unsigned long

variable_types: written int


decompiled_code:
__int64 __fastcall serial_timed_read(__int64 a1, __int64 a2, unsigned __int64 a3, char a4)
{
unsigned int v6; // er13
__int64 v7; // rsi
unsigned int v8; // eax
unsigned int v9; // er14
int *v11; // rax
char *v12; // rax

*(_BYTE *)(a1 + 46) = a4;
*(_BYTE *)(a1 + 47) = 0;
serial_flush_settings(a1);
if ( !a3 )
return 0;
v6 = 0;
v7 = 0LL;
while ( 1 )
{
v8 = read(*(_DWORD *)a1, (void *)(a2 + v7), a3 - v7);
v9 = v8;
if ( v8 == -1 )
break;
if ( v8 )
{
v6 += v8;
v7 = (int)v6;
if ( (int)v6 < a3 )
continue;
}
return v6;
}
if ( *(_DWORD *)(a1 + 20) )
{
v11 = _errno_location();
v12 = strerror(*v11);
fprintf(stderr, "ERROR: device %s: reading %u bytes failed: %s\n", *(const char **)(a1 + 8), a3, v12);
}
if ( *(_DWORD *)(a1 + 16) )
exit(1);
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2, unsigned __int64 a3, char a4)
{
unsigned int v6; // er13
__int64 v7; // rsi
unsigned int v8; // eax
unsigned int v9; // er14
int *v11; // rax
char *v12; // rax

*(_BYTE *)(a1 + 46) = a4;
*(_BYTE *)(a1 + 47) = 0;
func5(a1);
if ( !a3 )
return 0;
v6 = 0;
v7 = 0LL;
while ( 1 )
{
v8 = read(*(_DWORD *)a1, (void *)(a2 + v7), a3 - v7);
v9 = v8;
if ( v8 == -1 )
break;
if ( v8 )
{
v6 += v8;
v7 = (int)v6;
if ( (int)v6 < a3 )
continue;
}
return v6;
}
if ( *(_DWORD *)(a1 + 20) )
{
v11 = _errno_location();
v12 = strerror(*v11);
fprintf(stderr, "ERROR: device %s: reading %u bytes failed: %s\n", *(const char **)(a1 + 8), a3, v12);
}
if ( *(_DWORD *)(a1 + 16) )
exit(1);
return v9;
}

original_code:
int serial_timed_read(serial_device* const dev, uint8_t* buf, const size_t nbytes, const int intercharacter_timeout)
{
 dev->tios.c_cc[5] = intercharacter_timeout;
 dev->tios.c_cc[6] = 0;
 serial_flush_settings(dev);
 int n = 0;
 while(n < nbytes)
 {
  int read_return = read(dev->fd, (char*)(buf + n), nbytes - n);
  if(read_return == -1)
  {
   do { if(dev->print_on_error) { fprintf(stderr, "ERROR: device %s: ""reading %u bytes failed: %s""\n", dev->path, nbytes, strerror((*__errno_location ()))); } if(dev->exit_on_error) { exit(1); } } while(0); return -1;
  }
  if(read_return == 0)
  {
   return n;
  }
  n += read_return;
 }
 return n;
}

canonical_original_code:
int serial_timed_read(struct serial_device *dev, unsigned char *buf, unsigned long nbytes, int intercharacter_timeout)
{
 dev->tios.c_cc[5] = intercharacter_timeout;
 dev->tios.c_cc[6] = 0;
 serial_flush_settings(dev);
 int n = 0;
 while(n < nbytes)
 {
  int read_return = read(dev->fd, (char*)(buf + n), nbytes - n);
  if(read_return == -1)
  {
   do { if(dev->print_on_error) { fprintf(stderr, "ERROR: device %s: ""reading %u bytes failed: %s""\n", dev->path, nbytes, strerror((*__errno_location ()))); } if(dev->exit_on_error) { exit(1); } } while(0); return -1;
  }
  if(read_return == 0)
  {
   return n;
  }
  n += read_return;
 }
 return n;
}


decompiled_code:
__int64 __fastcall serial_read(__int64 a1, __int64 a2, __int64 a3)
{
int v5; // er12
__int64 v6; // rsi
unsigned int v7; // eax
unsigned int v8; // er14
int *v10; // rax
char *v11; // rax

*(_BYTE *)(a1 + 47) = a3;
*(_BYTE *)(a1 + 46) = 0;
serial_flush_settings(a1);
if ( !a3 )
return 1;
v5 = 0;
v6 = 0LL;
while ( 1 )
{
v7 = read(*(_DWORD *)a1, (void *)(a2 + v6), a3 - v6);
v8 = v7;
if ( v7 == -1 )
break;
v5 += v7;
v6 = v5;
if ( v5 == a3 )
return 1;
}
if ( *(_DWORD *)(a1 + 20) )
{
v10 = _errno_location();
v11 = strerror(*v10);
fprintf(stderr, "ERROR: device %s: reading %u bytes failed: %s\n", *(const char **)(a1 + 8), a3, v11);
}
if ( *(_DWORD *)(a1 + 16) )
exit(1);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2, __int64 a3)
{
int v5; // er12
__int64 v6; // rsi
unsigned int v7; // eax
unsigned int v8; // er14
int *v10; // rax
char *v11; // rax

*(_BYTE *)(a1 + 47) = a3;
*(_BYTE *)(a1 + 46) = 0;
func5(a1);
if ( !a3 )
return 1;
v5 = 0;
v6 = 0LL;
while ( 1 )
{
v7 = read(*(_DWORD *)a1, (void *)(a2 + v6), a3 - v6);
v8 = v7;
if ( v7 == -1 )
break;
v5 += v7;
v6 = v5;
if ( v5 == a3 )
return 1;
}
if ( *(_DWORD *)(a1 + 20) )
{
v10 = _errno_location();
v11 = strerror(*v10);
fprintf(stderr, "ERROR: device %s: reading %u bytes failed: %s\n", *(const char **)(a1 + 8), a3, v11);
}
if ( *(_DWORD *)(a1 + 16) )
exit(1);
return v8;
}

original_code:
int serial_read(serial_device* const dev, uint8_t* buf, const size_t nbytes)
{
 dev->tios.c_cc[6] = nbytes;
 dev->tios.c_cc[5] = 0;
 serial_flush_settings(dev);
 int readn = 0;
 int read_return;
 while(readn != nbytes)
 {
  read_return = read(dev->fd, (char*) (buf + readn), nbytes - readn);
  if(read_return == -1)
  {
   do { if(dev->print_on_error) { fprintf(stderr, "ERROR: device %s: ""reading %u bytes failed: %s""\n", dev->path, nbytes, strerror((*__errno_location ()))); } if(dev->exit_on_error) { exit(1); } } while(0); return -1;
  }
  readn += read_return;
 }
 return 1;
}

canonical_original_code:
int serial_read(struct serial_device *dev, unsigned char *buf, unsigned long nbytes)
{
 dev->tios.c_cc[6] = nbytes;
 dev->tios.c_cc[5] = 0;
 serial_flush_settings(dev);
 int readn = 0;
 int read_return;
 while(readn != nbytes)
 {
  read_return = read(dev->fd, (char *) (buf + readn), nbytes - readn);
  if(read_return == -1)
  {
   do { if(dev->print_on_error) { fprintf(stderr, "ERROR: device %s: ""reading %u bytes failed: %s""\n", dev->path, nbytes, strerror((*__errno_location ()))); } if(dev->exit_on_error) { exit(1); } } while(0); return -1;
  }
  readn += read_return;
 }
 return 1;
}

variable_types: readn int


decompiled_code:
int __fastcall print_usage(const char *a1)
{
return printf("Usage:\n\t%s (width filename )+\n", a1);
}

canonical_decompiled_code:
int __fastcall func7(const char *a1)
{
return printf("Usage:\n\t%s (width filename )+\n", a1);
}

original_code:
void print_usage(const char* const arg0)
{
 printf("Usage:\n\t%s (width filename )+\n", arg0);
}

canonical_original_code:
void print_usage(char *arg0)
{
 printf("Usage:\n\t%s (width filename )+\n", arg0);
}


repo: thejh/cgoodies

decompiled_code:
int __fastcall ringbuffer_init(__int64 a1, unsigned __int64 a2, char a3)
{
unsigned __int64 v3; // rbx
size_t v4; // r12
void *v5; // rax
int result; // eax
int *v7; // rax
int v8; // er13
int *v9; // rbx

v3 = a2;
if ( !a2 || (v4 = 2 * a2, 2 * a2 < a2) || (a2 & 0xFFF) != 0 )
{
if ( !a3 )
{
*__errno_location() = 22;
return -1;
}
v3 = (a2 + 4095) & 0xFFFFFFFFFFFFF000LL;
v4 = 2 * v3;
}
*(_QWORD *)(a1 + 8) = v3;
v5 = mmap(0LL, v4, 3, 33, -1, 0LL);
*(_QWORD *)a1 = v5;
*(_QWORD *)(a1 + 16) = v5;
if ( !v5 )
return -1;
result = remap_file_pages(v5, v3, 0, v3 >> 12, 0);
if ( result )
{
v7 = __errno_location();
v8 = *v7;
v9 = v7;
munmap(*(void **)a1, v4);
result = -1;
*v9 = v8;
}
else
{
**(_BYTE **)a1 = 66;
if ( *(_BYTE *)(*(_QWORD *)a1 + v3) != 66 )
{
fwrite("ERROR: SOMETHING BORKED UP THE RINGBUFFER!\n", 1uLL, 0x2BuLL, stderr);
__assert_fail("0", "ringbuffer/ringbuffer.c", 0x1Cu, "ringbuffer_init");
}
**(_BYTE **)a1 = 0;
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1, unsigned __int64 a2, char a3)
{
unsigned __int64 v3; // rbx
size_t v4; // r12
void *v5; // rax
int result; // eax
int *v7; // rax
int v8; // er13
int *v9; // rbx

v3 = a2;
if ( !a2 || (v4 = 2 * a2, 2 * a2 < a2) || (a2 & 0xFFF) != 0 )
{
if ( !a3 )
{
*__errno_location() = 22;
return -1;
}
v3 = (a2 + 4095) & 0xFFFFFFFFFFFFF000LL;
v4 = 2 * v3;
}
*(_QWORD *)(a1 + 8) = v3;
v5 = mmap(0LL, v4, 3, 33, -1, 0LL);
*(_QWORD *)a1 = v5;
*(_QWORD *)(a1 + 16) = v5;
if ( !v5 )
return -1;
result = remap_file_pages(v5, v3, 0, v3 >> 12, 0);
if ( result )
{
v7 = __errno_location();
v8 = *v7;
v9 = v7;
munmap(*(void **)a1, v4);
result = -1;
*v9 = v8;
}
else
{
**(_BYTE **)a1 = 66;
if ( *(_BYTE *)(*(_QWORD *)a1 + v3) != 66 )
{
fwrite("ERROR: SOMETHING BORKED UP THE RINGBUFFER!\n", 1uLL, 0x2BuLL, stderr);
__assert_fail("0", "ringbuffer/ringbuffer.c", 0x1Cu, "ringbuffer_init");
}
**(_BYTE **)a1 = 0;
}
return result;
}

original_code:
int ringbuffer_init(struct ringbuffer *b, size_t size, _Bool roundup_ok) {
  int err;
  if (size == 0 || size*2 < size || (size%(1UL << 12)) != 0) {
    if (!roundup_ok) {
      (*__errno_location ()) = 22;
      return -1;
    }
    size = ((size+(1UL << 12)-1)/(1UL << 12))*(1UL << 12);
  }
  b->size = size;
  b->start = b->buf = mmap(((void *)0), size*2, 0x1|0x2, 0x01|0x20, -1, 0);
  if (b->buf == ((void *)0)) return -1;
  if (remap_file_pages(b->buf, size, 0, size/(1UL << 12), 0)) goto unmap;
  *(char *)b->buf = 0x42;
  if (*((char *)b->buf+size) != 0x42) {
    fprintf(stderr, "ERROR: SOMETHING BORKED UP THE RINGBUFFER!\n");
    ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "ringbuffer/ringbuffer.c", 28, __extension__ __PRETTY_FUNCTION__); }));
  }
  *(char *)b->buf = 0;
  return 0;
unmap:
  err = (*__errno_location ());
  munmap(b->buf, size*2);
  (*__errno_location ()) = err;
  return -1;
}

canonical_original_code:
int ringbuffer_init(struct ringbuffer *b, unsigned long size, _Bool roundup_ok) {
  int err;
  if (size == 0 || size*2 < size || (size%(1UL << 12)) != 0) {
    if (!roundup_ok) {
      (*__errno_location ()) = 22;
      return -1;
    }
    size = ((size+(1UL << 12)-1)/(1UL << 12))*(1UL << 12);
  }
  b->size = size;
  b->start = b->buf = mmap(((void *)0), size*2, 0x1|0x2, 0x01|0x20, -1, 0);
  if (b->buf == ((void *)0)) return -1;
  if (remap_file_pages(b->buf, size, 0, size/(1UL << 12), 0)) goto unmap;
  *(char *)b->buf = 0x42;
  if (*((char *)b->buf+size) != 0x42) {
    fprintf(stderr, "ERROR: SOMETHING BORKED UP THE RINGBUFFER!\n");
    ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "ringbuffer/ringbuffer.c", 28, __extension__ __PRETTY_FUNCTION__); }));
  }
  *(char *)b->buf = 0;
  return 0;
unmap:
  err = (*__errno_location ());
  munmap(b->buf, size*2);
  (*__errno_location ()) = err;
  return -1;
}

variable_types: struct ringbuffer { void *buf; unsigned long size; void *start; } *

variable_types:
size
unsigned long

variable_types: err int


decompiled_code:
int __fastcall ringbuffer_destroy(__int64 a1)
{
return munmap(*(void **)a1, 2LL * *(_QWORD *)(a1 + 8));
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1)
{
return munmap(*(void **)a1, 2LL * *(_QWORD *)(a1 + 8));
}

original_code:
int ringbuffer_destroy(struct ringbuffer *b) {
  return munmap(b->buf, b->size*2);
}

user_defined_types: struct ringbuffer { void *buf; unsigned long size; void *start; }


decompiled_code:
__int64 __fastcall ringbuffer_get_backread_ptr(__int64 a1)
{
return *(_QWORD *)(a1 + 8) + *(_QWORD *)(a1 + 16);
}

original_code:
void *ringbuffer_get_backread_ptr(struct ringbuffer *b) {
  return b->start + b->size;
}

return_type: void *


repo: thejh/libbufio

decompiled_code:
__int64 bufio_chain_append()
{
if ( !calloc(1uLL, 0x20uLL) )
{
*(_QWORD *)&dword_0 = 0LL;
BUG();
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func6()
{
if ( !calloc(1uLL, 0x20uLL) )
{
*(_QWORD *)&dword_0 = 0LL;
BUG();
}
return 0xFFFFFFFFLL;
}

original_code:
int bufio_chain_append(bufio_chain *bc, void *buf, size_t len) {
  bufio_chain_entry *e = calloc(1, sizeof(*e));
  if (e != ((void *)0)) return -1;
  e->next = ((void *)0);
  e->buf = buf;
  e->len = len;
  if (bc->head != ((void *)0)) {
    bc->tail->next = e;
  } else {
    bc->head = e;
  }
  bc->tail = e;
  return 0;
}

canonical_original_code:
int bufio_chain_append(struct bufio_chain *bc, void *buf, unsigned long len) {
  struct bufio_chain_entry *e = calloc(1, sizeof(*e));
  if (e != ((void *)0)) return -1;
  e->next = ((void *)0);
  e->buf = buf;
  e->len = len;
  if (bc->head != ((void *)0)) {
    bc->tail->next = e;
  } else {
    bc->head = e;
  }
  bc->tail = e;
  return 0;
}

variable_types: struct bufio_chain { struct bufio_chain_entry { struct bufio_chain_entry *next; void *buf; unsigned long len; long used; } *head; } *

variable_types:
buf
void *

variable_types:
len
unsigned long

user_defined_types: struct bufio_chain { struct bufio_chain_entry *head; }


original_code:
int bufio_chain_flush(bufio_chain *bc, int fd) {
  while (bc->head != ((void *)0)) {
    bufio_chain_entry *e = bc->head;
    int res = write(fd, e->buf+e->used, e->len-e->used);
    if (res < 0) return res;
    ((e->used == e->len || res != 0) ? (void) (0) : __assert_fail ("e->used == e->len || res != 0", "bufchain.c", 31, __extension__ __PRETTY_FUNCTION__));
    e->used += res;
    if (e->used == e->len) {
      bc->head = e->next;
      free(e->buf);
      free(e);
    }
  }
  bc->tail = ((void *)0);
  return 0;
}

canonical_original_code:
int bufio_chain_flush(struct bufio_chain *bc, int fd) {
  while (bc->head != ((void *)0)) {
    struct bufio_chain_entry *e = bc->head;
    int res = write(fd, e->buf+e->used, e->len-e->used);
    if (res < 0) return res;
    ((e->used == e->len || res != 0) ? (void) (0) : __assert_fail ("e->used == e->len || res != 0", "bufchain.c", 31, __extension__ __PRETTY_FUNCTION__));
    e->used += res;
    if (e->used == e->len) {
      bc->head = e->next;
      free(e->buf);
      free(e);
    }
  }
  bc->tail = ((void *)0);
  return 0;
}

variable_types: fd int

variable_types: struct bufio_chain_entry { struct bufio_chain_entry *next; void *buf; unsigned long len; long used; } *

variable_types: res int


main

canonical_name: main

repo: theloi/ashping

decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc > 1 && (*(_QWORD *)&argc = argv[1], argv = (const char **)"-r", strstr(*(const char **)&argc, "-r")) )
bin2hex();
else
hex2bin(*(_QWORD *)&argc, argv, envp);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc > 1 && (*(_QWORD *)&argc = argv[1], argv = (const char **)"-r", strstr(*(const char **)&argc, "-r")) )
func8();
else
func7(*(_QWORD *)&argc, argv, envp);
return 0;
}

original_code:
int main(int argc, char **argv)
{
 if (argc >= 2 && strstr(argv[1], "-r"))
  bin2hex();
 else
  hex2bin();
 return 0;
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
__int64 hex2bin()
{
int v0; // ebx
int v1; // eax
char buf[3]; // [rsp+9h] [rbp-Fh] BYREF
int v4; // [rsp+Ch] [rbp-Ch]

v4 = 0;
v0 = fileno(stdin);
while ( 1 )
{
v1 = read(v0, buf, 2uLL);
if ( v1 <= 0 )
break;
if ( v1 == 1 )
{
if ( buf[0] != 10 )
{
fwrite("input parse error, odd digits in hex file\n", 1uLL, 0x2AuLL, stderr);
exit(1);
}
exit(1);
}
buf[2] = 0;
__isoc99_sscanf();
putchar((unsigned __int8)v4);
}
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
int v0; // ebx
int v1; // eax
char buf[3]; // [rsp+9h] [rbp-Fh] BYREF
int v4; // [rsp+Ch] [rbp-Ch]

v4 = 0;
v0 = fileno(stdin);
while ( 1 )
{
v1 = read(v0, buf, 2uLL);
if ( v1 <= 0 )
break;
if ( v1 == 1 )
{
if ( buf[0] != 10 )
{
fwrite("input parse error, odd digits in hex file\n", 1uLL, 0x2AuLL, stderr);
exit(1);
}
exit(1);
}
buf[2] = 0;
__isoc99_sscanf();
putchar((unsigned __int8)v4);
}
return 0LL;
}

original_code:
int hex2bin(void)
{
 char hex[3];
 int d = 0;
 unsigned char c;
 int stdin_fd = fileno(stdin);
 int n_read;
 while((n_read = read(stdin_fd, hex, 2)) > 0)
 {
  if (n_read == 1)
  {
   if (hex[0] != '\n')
   {
    fprintf(stderr,
    "input parse error, odd digits in hex file\n");
    exit(1);
   }
   else
    exit(1);
  }
  hex[2] = '\0';
  sscanf(hex, "%x", &d);
  c = (unsigned char) d;
  printf("%c", c);
 }
 return 0;
}

canonical_original_code:
int hex2bin()
{
 char hex[3];
 int d = 0;
 unsigned char c;
 int stdin_fd = fileno(stdin);
 int n_read;
 while((n_read = read(stdin_fd, hex, 2)) > 0)
 {
  if (n_read == 1)
  {
   if (hex[0] != '\n')
   {
    fprintf(stderr,
    "input parse error, odd digits in hex file\n");
    exit(1);
   }
   else
    exit(1);
  }
  hex[2] = '\0';
  sscanf(hex, "%x", &d);
  c = (unsigned char) d;
  printf("%c", c);
 }
 return 0;
}

variable_types:
hex
char [3]

variable_types: d int

variable_types:
c
unsigned char


decompiled_code:
__int64 bin2hex()
{
int v0; // ebx
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

v0 = fileno(stdin);
while ( (int)read(v0, buf, 1uLL) > 0 )
printf("%.2x", (unsigned __int8)buf[0]);
return 0LL;
}

canonical_decompiled_code:
__int64 func8()
{
int v0; // ebx
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

v0 = fileno(stdin);
while ( (int)read(v0, buf, 1uLL) > 0 )
printf("%.2x", (unsigned __int8)buf[0]);
return 0LL;
}

original_code:
int bin2hex(void)
{
 int stdin_fd = fileno(stdin);
 int n_read;
 unsigned char c;
 while((n_read = read(stdin_fd, &c, 1)) > 0)
 {
  printf("%.2x", c);
 }
 return 0;
}

canonical_original_code:
int bin2hex()
{
 int stdin_fd = fileno(stdin);
 int n_read;
 unsigned char c;
 while((n_read = read(stdin_fd, &c, 1)) > 0)
 {
  printf("%.2x", c);
 }
 return 0;
}


usage

decompiled_code:
int usage()
{
puts("NAME:");
puts("\tconvert_csv_to_libsvm - Converts CSV file to LibSVM format.");
puts("\tPlace labels in first column of CSV, and features in remaining columns.\n");
puts("SYNOPSIS:");
puts("\t./convert_csv_to_libsvm -i [CSV_input_file] -o [LibSVM_output_file]\n");
puts("OPTIONS:");
puts("\t-i [CSV_input_file]");
puts("\t\tThe input CSV file.");
puts("\t-o [LibSVM_output_file]");
puts("\t\tThe output LibSVM file.");
puts("\t-m [mode]");
puts("\t\t0: Reprints classes verbatim as they appear in the CSV.");
puts("\t\t1: Forces classes in output file to be '+1' or '-1'. (Required by some binary classifiers such as LaSVM.)");
puts(off_402086);
return puts("\t\tOutput a small usage guide; no other output is generated.");
}

canonical_decompiled_code:
int func7()
{
puts("NAME:");
puts("\tconvert_csv_to_libsvm - Converts CSV file to LibSVM format.");
puts("\tPlace labels in first column of CSV, and features in remaining columns.\n");
puts("SYNOPSIS:");
puts("\t./convert_csv_to_libsvm -i [CSV_input_file] -o [LibSVM_output_file]\n");
puts("OPTIONS:");
puts("\t-i [CSV_input_file]");
puts("\t\tThe input CSV file.");
puts("\t-o [LibSVM_output_file]");
puts("\t\tThe output LibSVM file.");
puts("\t-m [mode]");
puts("\t\t0: Reprints classes verbatim as they appear in the CSV.");
puts("\t\t1: Forces classes in output file to be '+1' or '-1'. (Required by some binary classifiers such as LaSVM.)");
puts(off_402086);
return puts("\t\tOutput a small usage guide; no other output is generated.");
}

original_code:
void
usage (void) {
 printf ("NAME:\n");
 printf ("\tconvert_csv_to_libsvm - Converts CSV file to LibSVM format.\n");
 printf ("\tPlace labels in first column of CSV, and features in remaining columns.\n\n");
 printf ("SYNOPSIS:\n");
 printf ("\t./convert_csv_to_libsvm -i [CSV_input_file] -o [LibSVM_output_file]\n\n");
 printf ("OPTIONS:\n");
    printf ("\t-i [CSV_input_file]\n");
    printf ("\t\tThe input CSV file.\n");
    printf ("\t-o [LibSVM_output_file]\n");
    printf ("\t\tThe output LibSVM file.\n");
    printf ("\t-m [mode]\n");
    printf ("\t\t0: Reprints classes verbatim as they appear in the CSV.\n");
    printf ("\t\t1: Forces classes in output file to be '+1' or '-1'. (Required by some binary classifiers such as LaSVM.)\n");
    printf ("\t-h\n");
    printf ("\t\tOutput a small usage guide; no other output is generated.\n");
}

canonical_original_code:
void usage() {
 printf ("NAME:\n");
 printf ("\tconvert_csv_to_libsvm - Converts CSV file to LibSVM format.\n");
 printf ("\tPlace labels in first column of CSV, and features in remaining columns.\n\n");
 printf ("SYNOPSIS:\n");
 printf ("\t./convert_csv_to_libsvm -i [CSV_input_file] -o [LibSVM_output_file]\n\n");
 printf ("OPTIONS:\n");
    printf ("\t-i [CSV_input_file]\n");
    printf ("\t\tThe input CSV file.\n");
    printf ("\t-o [LibSVM_output_file]\n");
    printf ("\t\tThe output LibSVM file.\n");
    printf ("\t-m [mode]\n");
    printf ("\t\t0: Reprints classes verbatim as they appear in the CSV.\n");
    printf ("\t\t1: Forces classes in output file to be '+1' or '-1'. (Required by some binary classifiers such as LaSVM.)\n");
    printf ("\t-h\n");
    printf ("\t\tOutput a small usage guide; no other output is generated.\n");
}


repo: theqlabs/qchat

decompiled_code:
__int64 init_data_structures()
{
_DWORD *v0; // rax
_DWORD *v1; // rbx
void *v2; // rax
void *v3; // rax
__int64 result; // rax

v0 = malloc(0x10uLL);
alloc_clients_size = 8;
*v0 = 0;
v1 = v0;
clients = v0;
v2 = calloc(8uLL, 0x18uLL);
*((_QWORD *)v1 + 1) = v2;
if ( v2 )
{
v3 = malloc(0x1800uLL);
initialized = 1;
msg_buffer = (__int64)v3;
result = 0LL;
}
else
{
fwrite("Error initializing data structures\n", 1uLL, 0x23uLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
_DWORD *v0; // rax
_DWORD *v1; // rbx
void *v2; // rax
void *v3; // rax
__int64 result; // rax

v0 = malloc(0x10uLL);
alloc_clients_size = 8;
*v0 = 0;
v1 = v0;
clients = v0;
v2 = calloc(8uLL, 0x18uLL);
*((_QWORD *)v1 + 1) = v2;
if ( v2 )
{
v3 = malloc(0x1800uLL);
initialized = 1;
msg_buffer = (__int64)v3;
result = 0LL;
}
else
{
fwrite("Error initializing data structures\n", 1uLL, 0x23uLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int init_data_structures() {
 clients = malloc(sizeof(clist));
 clients->clientlist.clientlist_len = 0;
 alloc_clients_size = 8;
 cname *list_values = (cname*)calloc((size_t)8, sizeof(cname));
 clients->clientlist.clientlist_val = list_values;
 if (clients == ((void *)0) || clients->clientlist.clientlist_val == ((void *)0)) {
  fprintf(stderr, "Error initializing data structures\n");
  return -1;
 }
 msg_buffer = malloc(sizeof(msg_recv)*256);
 initialized = (1);
 return 0;
}

canonical_original_code:
int init_data_structures() {
 clients = malloc(sizeof(clist));
 clients->clientlist.clientlist_len = 0;
 alloc_clients_size = 8;
 struct cname *list_values = (cname*)calloc((size_t)8, sizeof(cname));
 clients->clientlist.clientlist_val = list_values;
 if (clients == ((void *)0) || clients->clientlist.clientlist_val == ((void *)0)) {
  fprintf(stderr, "Error initializing data structures\n");
  return -1;
 }
 msg_buffer = malloc(sizeof(msg_recv)*256);
 initialized = (1);
 return 0;
}

variable_types: struct cname { char *userName; char *hostname; int lport; int leader_flag; } *


decompiled_code:
void destroy_data_structures()
{
void *v0; // rdi
__int64 v1; // rax
void *v2; // rdi

if ( initialized )
{
v0 = clients;
if ( clients )
{
if ( *((_QWORD *)clients + 1) )
{
free(*((void **)clients + 1));
v0 = clients;
}
free(v0);
}
v1 = msg_buffer;
if ( msg_buffer )
{
if ( *(_QWORD *)msg_buffer )
{
free(*(void **)msg_buffer);
v1 = msg_buffer;
}
v2 = *(void **)(v1 + 8);
if ( v2 )
free(v2);
}
}
}

canonical_decompiled_code:
void func2()
{
void *v0; // rdi
__int64 v1; // rax
void *v2; // rdi

if ( initialized )
{
v0 = clients;
if ( clients )
{
if ( *((_QWORD *)clients + 1) )
{
free(*((void **)clients + 1));
v0 = clients;
}
free(v0);
}
v1 = msg_buffer;
if ( msg_buffer )
{
if ( *(_QWORD *)msg_buffer )
{
free(*(void **)msg_buffer);
v1 = msg_buffer;
}
v2 = *(void **)(v1 + 8);
if ( v2 )
free(v2);
}
}
}

original_code:
void destroy_data_structures() {
  if(initialized) {
    if(clients != ((void *)0)) {
      if (clients->clientlist.clientlist_val != ((void *)0)) {
        free(clients->clientlist.clientlist_val);
      }
      free(clients);
    }
    if(msg_buffer != ((void *)0)) {
     if (msg_buffer->msg_sent != ((void *)0)) {
      free(msg_buffer->msg_sent);
     }
     if (msg_buffer->user_sent != ((void *)0)){
      free(msg_buffer->user_sent);
     }
    }
  }
}


diep

decompiled_code:
void __fastcall __noreturn diep(const char *a1)
{
perror(a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func3(const char *a1)
{
perror(a1);
exit(1);
}

original_code:
void diep(char *s) {
  perror(s);
  exit(1);
}

variable_types:
s
char *


sendDatagram

decompiled_code:
int __fastcall sendDatagram(unsigned int a1, unsigned int a2, const char *a3, const char *a4)
{
ssize_t v7; // rax
_QWORD *v8; // rdx
int v9; // ebp
__int64 i; // rbx
__int64 v11; // rdx
__int16 v12; // ax
__int64 v13; // rdx
const char *v14; // rdi
struct sockaddr v16[4]; // [rsp+0h] [rbp-48h] BYREF

LODWORD(v7) = socket(2, 2, 17);
if ( (int)v7 < 0 )
{
fwrite("SOCKET CREATION FAILED", 1uLL, 0x16uLL, stderr);
exit(1);
}
v8 = clients;
v9 = v7;
for ( i = 0LL; *(_DWORD *)clients > (unsigned int)i; ++i )
{
v16[0] = 0LL;
v11 = v8[1];
v16[0].sa_family = 2;
v12 = _bswap_16(*(_WORD *)(v11 + 24 * i + 16));
v14 = *(const char **)(v13 + 8);
*(_WORD *)v16[0].sa_data = v12;
if ( !inet_aton(v14, (struct in_addr *)&v16[0].sa_data[2]) )
{
fwrite("inet_aton() failed\n", 1uLL, 0x13uLL, stderr);
exit(1);
}
sprintf(buf, "%d,%d,%s,%s", a1, a2, a3, a4);
v7 = sendto(v9, buf, 0x22CuLL, 0, v16, 0x10u);
if ( v7 < 0 )
{
fwrite("sendto", 1uLL, 6uLL, stderr);
exit(1);
}
v8 = clients;
}
return v7;
}

canonical_decompiled_code:
int __fastcall func4(unsigned int a1, unsigned int a2, const char *a3, const char *a4)
{
ssize_t v7; // rax
_QWORD *v8; // rdx
int v9; // ebp
__int64 i; // rbx
__int64 v11; // rdx
__int16 v12; // ax
__int64 v13; // rdx
const char *v14; // rdi
struct sockaddr v16[4]; // [rsp+0h] [rbp-48h] BYREF

LODWORD(v7) = socket(2, 2, 17);
if ( (int)v7 < 0 )
{
fwrite("SOCKET CREATION FAILED", 1uLL, 0x16uLL, stderr);
exit(1);
}
v8 = clients;
v9 = v7;
for ( i = 0LL; *(_DWORD *)clients > (unsigned int)i; ++i )
{
v16[0] = 0LL;
v11 = v8[1];
v16[0].sa_family = 2;
v12 = func0(*(_WORD *)(v11 + 24 * i + 16));
v14 = *(const char **)(v13 + 8);
*(_WORD *)v16[0].sa_data = v12;
if ( !inet_aton(v14, (struct in_addr *)&v16[0].sa_data[2]) )
{
fwrite("inet_aton() failed\n", 1uLL, 0x13uLL, stderr);
exit(1);
}
sprintf(buf, "%d,%d,%s,%s", a1, a2, a3, a4);
v7 = sendto(v9, buf, 0x22CuLL, 0, v16, 0x10u);
if ( v7 < 0 )
{
fwrite("sendto", 1uLL, 6uLL, stderr);
exit(1);
}
v8 = clients;
}
return v7;
}

original_code:
void sendDatagram(msg_type_t msgType, uint32_t sequence, uname sd_user, msg_send sd_message) {
 struct sockaddr_in addr;
 int fd, cnt, i;
 if ((fd=socket(2,SOCK_DGRAM,IPPROTO_UDP)) < 0) {
  fprintf(stderr, "SOCKET CREATION FAILED");
  exit(1);
 }
 for (i=0; i<clients->clientlist.clientlist_len; i++) {
  memset(&addr, 0, sizeof(addr));
  addr.sin_family=2;
  addr.sin_port=htons(clients->clientlist.clientlist_val[i].lport);
  if (inet_aton(clients->clientlist.clientlist_val[i].hostname, &addr.sin_addr)==0) {
  fprintf(stderr, "inet_aton() failed\n");
   exit(1);
  }
  sprintf(buf, "%d,%d,%s,%s", msgType, sequence, sd_user, sd_message);
  if (sendto(fd, buf, sizeof(buf), 0, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
   fprintf(stderr, "sendto");
   exit(1);
  }
 }
}

canonical_original_code:
void sendDatagram(enum msg_type_t msgType, unsigned int sequence, char *sd_user, char *sd_message) {
 struct sockaddr_in addr;
 int fd; int cnt; int i;
 if ((fd=socket(2,SOCK_DGRAM,IPPROTO_UDP)) < 0) {
  fprintf(stderr, "SOCKET CREATION FAILED");
  exit(1);
 }
 for (i=0; i<clients->clientlist.clientlist_len; i++) {
  memset(&addr, 0, sizeof(addr));
  addr.sin_family=2;
  addr.sin_port=htons(clients->clientlist.clientlist_val[i].lport);
  if (inet_aton(clients->clientlist.clientlist_val[i].hostname, &addr.sin_addr)==0) {
  fprintf(stderr, "inet_aton() failed\n");
   exit(1);
  }
  sprintf(buf, "%d,%d,%s,%s", msgType, sequence, sd_user, sd_message);
  if (sendto(fd, buf, sizeof(buf), 0, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
   fprintf(stderr, "sendto");
   exit(1);
  }
 }
}

variable_types: enum msg_type_t { TEXT=0, NEWUSER=1, USEREXIT=2, ELECTION=3 }

variable_types:
sequence
unsigned int

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

variable_types: cnt int

variable_types: i int

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

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


mcClients

decompiled_code:
int __fastcall mcClients(const char *a1, const char *a2, unsigned int a3, unsigned int a4)
{
__int64 v4; // r15
ssize_t v7; // rax
_QWORD *v8; // rdx
int v9; // ebp
__int64 i; // rbx
__int64 v11; // rdx
__int16 v12; // ax
__int64 v13; // rdx
const char *v14; // rdi
struct in_addr inp[4]; // [rsp+0h] [rbp-48h] BYREF

v4 = a4;
LODWORD(v7) = socket(2, 2, 0);
if ( (int)v7 < 0 )
{
fwrite("SOCKET CREATION FAILED", 1uLL, 0x16uLL, stderr);
exit(1);
}
v8 = clients;
v9 = v7;
for ( i = 0LL; *(_DWORD *)clients > (unsigned int)i; ++i )
{
*(_OWORD *)&inp[0].s_addr = 0LL;
v11 = v8[1];
LOWORD(inp[0].s_addr) = 2;
v12 = _bswap_16(*(_WORD *)(v11 + 24 * i + 16));
v14 = *(const char **)(v13 + 8);
HIWORD(inp[0].s_addr) = v12;
if ( !inet_aton(v14, &inp[1]) )
{
fwrite("inet_aton() failed\n", 1uLL, 0x13uLL, stderr);
exit(1);
}
sprintf(buf, "%d,%s,%s,%d,%d", 1LL, a1, a2, a3, v4);
v7 = sendto(v9, buf, 0x22CuLL, 0, (const struct sockaddr *)inp, 0x10u);
if ( v7 < 0 )
{
fwrite("sendto", 1uLL, 6uLL, stderr);
exit(1);
}
v8 = clients;
}
return v7;
}

canonical_decompiled_code:
int __fastcall func5(const char *a1, const char *a2, unsigned int a3, unsigned int a4)
{
__int64 v4; // r15
ssize_t v7; // rax
_QWORD *v8; // rdx
int v9; // ebp
__int64 i; // rbx
__int64 v11; // rdx
__int16 v12; // ax
__int64 v13; // rdx
const char *v14; // rdi
struct in_addr inp[4]; // [rsp+0h] [rbp-48h] BYREF

v4 = a4;
LODWORD(v7) = socket(2, 2, 0);
if ( (int)v7 < 0 )
{
fwrite("SOCKET CREATION FAILED", 1uLL, 0x16uLL, stderr);
exit(1);
}
v8 = clients;
v9 = v7;
for ( i = 0LL; *(_DWORD *)clients > (unsigned int)i; ++i )
{
*(_OWORD *)&inp[0].s_addr = 0LL;
v11 = v8[1];
LOWORD(inp[0].s_addr) = 2;
v12 = func0(*(_WORD *)(v11 + 24 * i + 16));
v14 = *(const char **)(v13 + 8);
HIWORD(inp[0].s_addr) = v12;
if ( !inet_aton(v14, &inp[1]) )
{
fwrite("inet_aton() failed\n", 1uLL, 0x13uLL, stderr);
exit(1);
}
sprintf(buf, "%d,%s,%s,%d,%d", 1LL, a1, a2, a3, v4);
v7 = sendto(v9, buf, 0x22CuLL, 0, (const struct sockaddr *)inp, 0x10u);
if ( v7 < 0 )
{
fwrite("sendto", 1uLL, 6uLL, stderr);
exit(1);
}
v8 = clients;
}
return v7;
}

original_code:
void mcClients(uname userName, hoststr hostname, int lport, int leader_flag) {
 struct sockaddr_in addr;
 int fd, cnt, i;
 if ((fd=socket(2,SOCK_DGRAM,0)) < 0) {
  fprintf(stderr, "SOCKET CREATION FAILED");
  exit(1);
 }
 for (i=0; i<clients->clientlist.clientlist_len; i++) {
  memset(&addr, 0, sizeof(addr));
  addr.sin_family=2;
  addr.sin_port=htons(clients->clientlist.clientlist_val[i].lport);
  if (inet_aton(clients->clientlist.clientlist_val[i].hostname, &addr.sin_addr)==0) {
  fprintf(stderr, "inet_aton() failed\n");
   exit(1);
  }
  sprintf(buf, "%d,%s,%s,%d,%d", NEWUSER, userName, hostname, lport, leader_flag);
  if (sendto(fd, buf, sizeof(buf), 0, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
   fprintf(stderr, "sendto");
   exit(1);
  }
 }
}

canonical_original_code:
void mcClients(char *userName, char *hostname, int lport, int leader_flag) {
 struct sockaddr_in addr;
 int fd; int cnt; int i;
 if ((fd=socket(2,SOCK_DGRAM,0)) < 0) {
  fprintf(stderr, "SOCKET CREATION FAILED");
  exit(1);
 }
 for (i=0; i<clients->clientlist.clientlist_len; i++) {
  memset(&addr, 0, sizeof(addr));
  addr.sin_family=2;
  addr.sin_port=htons(clients->clientlist.clientlist_val[i].lport);
  if (inet_aton(clients->clientlist.clientlist_val[i].hostname, &addr.sin_addr)==0) {
  fprintf(stderr, "inet_aton() failed\n");
   exit(1);
  }
  sprintf(buf, "%d,%s,%s,%d,%d", NEWUSER, userName, hostname, lport, leader_flag);
  if (sendto(fd, buf, sizeof(buf), 0, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
   fprintf(stderr, "sendto");
   exit(1);
  }
 }
}

variable_types:
userName
char *

variable_types:
hostname
char *

variable_types: lport int


mcExit

decompiled_code:
int __fastcall mcExit(const char *a1)
{
ssize_t v2; // rax
_QWORD *v3; // rdx
int v4; // ebp
__int64 i; // rbx
__int64 v6; // rdx
__int16 v7; // ax
__int64 v8; // rdx
const char *v9; // rdi
struct sockaddr v11[2]; // [rsp+0h] [rbp-28h] BYREF

LODWORD(v2) = socket(2, 2, 0);
if ( (int)v2 < 0 )
{
fwrite("SOCKET CREATION ERROR", 1uLL, 0x15uLL, stderr);
exit(1);
}
v3 = clients;
v4 = v2;
for ( i = 0LL; *(_DWORD *)clients > (unsigned int)i; ++i )
{
v11[0] = 0LL;
v6 = v3[1];
v11[0].sa_family = 2;
v7 = _bswap_16(*(_WORD *)(v6 + 24 * i + 16));
v9 = *(const char **)(v8 + 8);
*(_WORD *)v11[0].sa_data = v7;
if ( !inet_aton(v9, (struct in_addr *)&v11[0].sa_data[2]) )
{
fwrite("inet_aton() failed\n", 1uLL, 0x13uLL, stderr);
exit(1);
}
sprintf(buf, "%d,%s", 2LL, a1);
v2 = sendto(v4, buf, 0x22CuLL, 0, v11, 0x10u);
if ( v2 < 0 )
{
fwrite("sendto", 1uLL, 6uLL, stderr);
exit(1);
}
v3 = clients;
}
return v2;
}

canonical_decompiled_code:
int __fastcall func6(const char *a1)
{
ssize_t v2; // rax
_QWORD *v3; // rdx
int v4; // ebp
__int64 i; // rbx
__int64 v6; // rdx
__int16 v7; // ax
__int64 v8; // rdx
const char *v9; // rdi
struct sockaddr v11[2]; // [rsp+0h] [rbp-28h] BYREF

LODWORD(v2) = socket(2, 2, 0);
if ( (int)v2 < 0 )
{
fwrite("SOCKET CREATION ERROR", 1uLL, 0x15uLL, stderr);
exit(1);
}
v3 = clients;
v4 = v2;
for ( i = 0LL; *(_DWORD *)clients > (unsigned int)i; ++i )
{
v11[0] = 0LL;
v6 = v3[1];
v11[0].sa_family = 2;
v7 = func0(*(_WORD *)(v6 + 24 * i + 16));
v9 = *(const char **)(v8 + 8);
*(_WORD *)v11[0].sa_data = v7;
if ( !inet_aton(v9, (struct in_addr *)&v11[0].sa_data[2]) )
{
fwrite("inet_aton() failed\n", 1uLL, 0x13uLL, stderr);
exit(1);
}
sprintf(buf, "%d,%s", 2LL, a1);
v2 = sendto(v4, buf, 0x22CuLL, 0, v11, 0x10u);
if ( v2 < 0 )
{
fwrite("sendto", 1uLL, 6uLL, stderr);
exit(1);
}
v3 = clients;
}
return v2;
}

original_code:
void mcExit(uname *exitingUser) {
 struct sockaddr_in addr;
 int fd, cnt, i;
 if ((fd=socket(2,SOCK_DGRAM,0)) < 0) {
  fprintf(stderr, "SOCKET CREATION ERROR");
  exit(1);
 }
 for (i=0; i<clients->clientlist.clientlist_len; i++) {
  memset(&addr, 0, sizeof(addr));
  addr.sin_family=2;
  addr.sin_port=htons(clients->clientlist.clientlist_val[i].lport);
  if (inet_aton(clients->clientlist.clientlist_val[i].hostname, &addr.sin_addr)==0) {
  fprintf(stderr, "inet_aton() failed\n");
   exit(1);
  }
  sprintf(buf, "%d,%s", USEREXIT, exitingUser);
  if (sendto(fd, buf, sizeof(buf), 0, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
   fprintf(stderr, "sendto");
   exit(1);
  }
 }
}

canonical_original_code:
void mcExit(char **exitingUser) {
 struct sockaddr_in addr;
 int fd; int cnt; int i;
 if ((fd=socket(2,SOCK_DGRAM,0)) < 0) {
  fprintf(stderr, "SOCKET CREATION ERROR");
  exit(1);
 }
 for (i=0; i<clients->clientlist.clientlist_len; i++) {
  memset(&addr, 0, sizeof(addr));
  addr.sin_family=2;
  addr.sin_port=htons(clients->clientlist.clientlist_val[i].lport);
  if (inet_aton(clients->clientlist.clientlist_val[i].hostname, &addr.sin_addr)==0) {
  fprintf(stderr, "inet_aton() failed\n");
   exit(1);
  }
  sprintf(buf, "%d,%s", USEREXIT, exitingUser);
  if (sendto(fd, buf, sizeof(buf), 0, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
   fprintf(stderr, "sendto");
   exit(1);
  }
 }
}

variable_types:
exitingUser
char **

variable_types: fd int


decompiled_code:
__int64 __fastcall join_1_svc(__int64 a1)
{
__int64 v2; // r12
char *v3; // rax
const char *v4; // rdi
const char *v5; // rbp
char *v6; // rax
unsigned int v7; // edx
unsigned int v8; // ecx

if ( !initialized )
init_data_structures();
v2 = *((_QWORD *)clients + 1) + 24LL * *(unsigned int *)clients;
v3 = strdup(*(const char **)a1);
v4 = *(const char **)(a1 + 8);
*(_QWORD *)v2 = v3;
v5 = v3;
v6 = strdup(v4);
v7 = *(_DWORD *)(a1 + 16);
v8 = *(_DWORD *)(a1 + 20);
*(_QWORD *)(v2 + 8) = v6;
*(_DWORD *)(v2 + 16) = v7;
*(_DWORD *)(v2 + 20) = v8;
mcClients(v5, v6, v7, v8);
++*(_DWORD *)clients;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 v2; // r12
char *v3; // rax
const char *v4; // rdi
const char *v5; // rbp
char *v6; // rax
unsigned int v7; // edx
unsigned int v8; // ecx

if ( !initialized )
func1();
v2 = *((_QWORD *)clients + 1) + 24LL * *(unsigned int *)clients;
v3 = strdup(*(const char **)a1);
v4 = *(const char **)(a1 + 8);
*(_QWORD *)v2 = v3;
v5 = v3;
v6 = strdup(v4);
v7 = *(_DWORD *)(a1 + 16);
v8 = *(_DWORD *)(a1 + 20);
*(_QWORD *)(v2 + 8) = v6;
*(_DWORD *)(v2 + 16) = v7;
*(_DWORD *)(v2 + 20) = v8;
func5(v5, v6, v7, v8);
++*(_DWORD *)clients;
return 0LL;
}

original_code:
int *join_1_svc(cname *userdata, struct svc_req *rqstp) {
 int unameErr;
 status_code status;
 if (!initialized) {
  init_data_structures();
 }
 clients->clientlist.clientlist_val[clients->clientlist.clientlist_len].userName = (uname) strdup(userdata->userName);
 if (clients->clientlist.clientlist_val[clients->clientlist.clientlist_len].userName == ((void *)0)) {
  status = 2;
 }
 clients->clientlist.clientlist_val[clients->clientlist.clientlist_len].hostname = (hoststr) strdup(userdata->hostname);
 clients->clientlist.clientlist_val[clients->clientlist.clientlist_len].lport = userdata->lport;
  clients->clientlist.clientlist_val[clients->clientlist.clientlist_len].leader_flag = userdata->leader_flag;
 if (clients == ((void *)0)) {
  status = 1;
 }
  mcClients(
     clients->clientlist.clientlist_val[clients->clientlist.clientlist_len].userName,
     clients->clientlist.clientlist_val[clients->clientlist.clientlist_len].hostname,
     clients->clientlist.clientlist_val[clients->clientlist.clientlist_len].lport,
     clients->clientlist.clientlist_val[clients->clientlist.clientlist_len].leader_flag);
  clients->clientlist.clientlist_len++;
 return((int *)&status);
}

canonical_original_code:
int *join_1_svc(struct cname *userdata, struct svc_req *rqstp) {
 int unameErr;
 enum status_code status;
 if (!initialized) {
  init_data_structures();
 }
 clients->clientlist.clientlist_val[clients->clientlist.clientlist_len].userName = (char *) strdup(userdata->userName);
 if (clients->clientlist.clientlist_val[clients->clientlist.clientlist_len].userName == ((void *)0)) {
  status = 2;
 }
 clients->clientlist.clientlist_val[clients->clientlist.clientlist_len].hostname = (char *) strdup(userdata->hostname);
 clients->clientlist.clientlist_val[clients->clientlist.clientlist_len].lport = userdata->lport;
  clients->clientlist.clientlist_val[clients->clientlist.clientlist_len].leader_flag = userdata->leader_flag;
 if (clients == ((void *)0)) {
  status = 1;
 }
  mcClients(
     clients->clientlist.clientlist_val[clients->clientlist.clientlist_len].userName,
     clients->clientlist.clientlist_val[clients->clientlist.clientlist_len].hostname,
     clients->clientlist.clientlist_val[clients->clientlist.clientlist_len].lport,
     clients->clientlist.clientlist_val[clients->clientlist.clientlist_len].leader_flag);
  clients->clientlist.clientlist_len++;
 return((int *)&status);
}

variable_types: struct svc_req { unsigned long rq_prog; unsigned long rq_vers; unsigned long rq_proc; struct opaque_auth { int oa_flavor; char *oa_base; unsigned int oa_length; } rq_cred; char *rq_clntcred; struct SVCXPRT { int xp_sock; unsigned short xp_port; struct xp_ops { int (*xp_recv)(struct SVCXPRT *__xprt, struct rpc_msg { unsigned long rm_xid; enum msg_type { CALL=0, REPLY=1 } rm_direction; union { struct call_body { unsigned long cb_rpcvers; unsigned long cb_prog; unsigned long cb_vers; unsigned long cb_proc; struct opaque_auth cb_cred; struct opaque_auth cb_verf; } RM_cmb; struct reply_body { enum reply_stat { MSG_ACCEPTED=0, MSG_DENIED=1 } rp_stat; union { struct accepted_reply { struct opaque_auth ar_verf; enum accept_stat { SUCCESS=0, PROG_UNAVAIL=1, PROG_MISMATCH=2, PROC_UNAVAIL=3, GARBAGE_ARGS=4, SYSTEM_ERR=5 } ar_stat; union { struct { unsigned long low; unsigned long high; } AR_versions; struct { char *where; int (*proc)(struct XDR { enum xdr_op { XDR_ENCODE=0, XDR_DECODE=1, XDR_FREE=2 } x_op; struct xdr_ops { int (*x_getlong)(struct XDR *__xdrs, long *__lp); int (*x_putlong)(struct XDR *__xdrs, long *__lp); int (*x_getbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); int (*x_putbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); unsigned int (*x_getpostn)(struct XDR *__xdrs); int (*x_setpostn)(struct XDR *__xdrs, unsigned int __pos); int *(*x_inline)(struct XDR *__xdrs, unsigned int __len); void (*x_destroy)(struct XDR *__xdrs); int (*x_getint32)(struct XDR *__xdrs, int *__ip); int (*x_putint32)(struct XDR *__xdrs, int *__ip); } *x_ops; char *x_public; char *x_private; char *x_base; unsigned int x_handy; } *, void *, ...); } AR_results; } ru; } RP_ar; struct rejected_reply { enum reject_stat { RPC_MISMATCH=0, AUTH_ERROR=1 } rj_stat; union { struct { unsigned long low; unsigned long high; } RJ_versions; enum auth_stat { AUTH_OK=0, AUTH_BADCRED=1, AUTH_REJECTEDCRED=2, AUTH_BADVERF=3, AUTH_REJECTEDVERF=4, AUTH_TOOWEAK=5, AUTH_INVALIDRESP=6, AUTH_FAILED=7 } RJ_why; } ru; } RP_dr; } ru; } RM_rmb; } ru; } *__msg); enum xprt_stat { XPRT_DIED=0, XPRT_MOREREQS=1, XPRT_IDLE=2 } (*xp_stat)(struct SVCXPRT *__xprt); int (*xp_getargs)(struct SVCXPRT *__xprt, int (*__xdr_args)(struct XDR *, void *, ...), char *__args_ptr); int (*xp_reply)(struct SVCXPRT *__xprt, struct rpc_msg *__msg); int (*xp_freeargs)(struct SVCXPRT *__xprt, int (*__xdr_args)(struct XDR *, void *, ...), char *__args_ptr); void (*xp_destroy)(struct SVCXPRT *__xprt); } *xp_ops; int xp_addrlen; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } xp_raddr; struct opaque_auth xp_verf; char *xp_p1; char *xp_p2; char xp_pad[256]; } *rq_xprt; } *

variable_types: unameErr int

variable_types: enum status_code { JSUCCESS=0, JFAILURE=1, UNAMEINUSE=2, UNAMEINVALID=3 }

return_type: int *

user_defined_types: struct cname { char *userName; char *hostname; int lport; int leader_flag; }

user_defined_types: struct svc_req { unsigned long rq_prog; unsigned long rq_vers; unsigned long rq_proc; struct opaque_auth rq_cred; char *rq_clntcred; struct SVCXPRT *rq_xprt; }

user_defined_types: struct SVCXPRT { int xp_sock; unsigned short xp_port; struct xp_ops *xp_ops; int xp_addrlen; struct sockaddr_in xp_raddr; struct opaque_auth xp_verf; char *xp_p1; char *xp_p2; char xp_pad[256]; }

user_defined_types: struct xp_ops { int (*xp_recv)(struct SVCXPRT *__xprt, struct rpc_msg *__msg); enum xprt_stat (*xp_stat)(struct SVCXPRT *__xprt); int (*xp_getargs)(struct SVCXPRT *__xprt, int (*__xdr_args)(struct XDR *, void *, ...), char *__args_ptr); int (*xp_reply)(struct SVCXPRT *__xprt, struct rpc_msg *__msg); int (*xp_freeargs)(struct SVCXPRT *__xprt, int (*__xdr_args)(struct XDR *, void *, ...), char *__args_ptr); void (*xp_destroy)(struct SVCXPRT *__xprt); }

user_defined_types: struct rpc_msg { unsigned long rm_xid; enum msg_type rm_direction; union { struct call_body RM_cmb; struct reply_body RM_rmb; } ru; }

user_defined_types: struct reply_body { enum reply_stat rp_stat; union { struct accepted_reply RP_ar; struct rejected_reply RP_dr; } ru; }

user_defined_types: struct accepted_reply { struct opaque_auth ar_verf; enum accept_stat ar_stat; union { struct { unsigned long low; unsigned long high; } AR_versions; struct { char *where; int (*proc)(struct XDR *, void *, ...); } AR_results; } ru; }

user_defined_types: struct rejected_reply { enum reject_stat rj_stat; union { struct { unsigned long low; unsigned long high; } RJ_versions; enum auth_stat RJ_why; } ru; }

user_defined_types: struct XDR { enum xdr_op x_op; struct xdr_ops *x_ops; char *x_public; char *x_private; char *x_base; unsigned int x_handy; }


decompiled_code:
const char *__fastcall send_1_svc(__int64 a1)
{
const char *result; // rax
size_t v3; // rax
__int64 v4; // r12
char *v5; // rax
const char *v6; // rdi
char *v7; // rbp
size_t v8; // rax
void *v9; // rax
const char *v10; // rsi
__int64 v11; // rax
const char *v12; // rdx
const char *v13; // rcx

if ( !initialized )
init_data_structures();
result = *(const char **)a1;
if ( *(_QWORD *)a1 )
{
if ( (unsigned __int8)(*result + 1) <= 1u )
{
result = 0LL;
}
else
{
v3 = strlen(*(const char **)a1);
v4 = msg_buffer + 24LL * (unsigned __int8)seq_num;
v5 = (char *)malloc(8 * v3);
v6 = *(const char **)(a1 + 8);
*(_QWORD *)v4 = v5;
v7 = v5;
v8 = strlen(v6);
v9 = malloc(8 * v8);
v10 = *(const char **)a1;
*(_QWORD *)(v4 + 8) = v9;
strcpy(v7, v10);
strcpy(*(char **)(v4 + 8), *(const char **)(a1 + 8));
LODWORD(v10) = seq_num;
LODWORD(v6) = *(_DWORD *)(a1 + 20);
v11 = msg_buffer + 24LL * (unsigned __int8)seq_num;
v12 = *(const char **)(v11 + 8);
v13 = *(const char **)v11;
*(_DWORD *)(v11 + 16) = seq_num;
*(_DWORD *)(v11 + 20) = (_DWORD)v6;
sendDatagram((unsigned int)v6, (unsigned int)v10, v12, v13);
++seq_num;
result = (const char *)&result_2;
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func8(__int64 a1)
{
const char *result; // rax
size_t v3; // rax
__int64 v4; // r12
char *v5; // rax
const char *v6; // rdi
char *v7; // rbp
size_t v8; // rax
void *v9; // rax
const char *v10; // rsi
__int64 v11; // rax
const char *v12; // rdx
const char *v13; // rcx

if ( !initialized )
func1();
result = *(const char **)a1;
if ( *(_QWORD *)a1 )
{
if ( (unsigned __int8)(*result + 1) <= 1u )
{
result = 0LL;
}
else
{
v3 = strlen(*(const char **)a1);
v4 = msg_buffer + 24LL * (unsigned __int8)seq_num;
v5 = (char *)malloc(8 * v3);
v6 = *(const char **)(a1 + 8);
*(_QWORD *)v4 = v5;
v7 = v5;
v8 = strlen(v6);
v9 = malloc(8 * v8);
v10 = *(const char **)a1;
*(_QWORD *)(v4 + 8) = v9;
strcpy(v7, v10);
strcpy(*(char **)(v4 + 8), *(const char **)(a1 + 8));
LODWORD(v10) = seq_num;
LODWORD(v6) = *(_DWORD *)(a1 + 20);
v11 = msg_buffer + 24LL * (unsigned __int8)seq_num;
v12 = *(const char **)(v11 + 8);
v13 = *(const char **)v11;
*(_DWORD *)(v11 + 16) = seq_num;
*(_DWORD *)(v11 + 20) = (_DWORD)v6;
func4((unsigned int)v6, (unsigned int)v10, v12, v13);
++seq_num;
result = (const char *)&result_2;
}
}
return result;
}

original_code:
int *send_1_svc(msg_recv *message, struct svc_req *rqstp) {
 static int result = 0;
 int i;
 if (!initialized) {
  init_data_structures();
 }
 if (message->msg_sent == ((void *)0) || strlen(message->msg_sent) == 0 || message->msg_sent[0] == (-1)) {
  return(((void *)0));
 }
 msg_buffer[seq_num % 256].msg_sent = (char *) malloc(sizeof(msg_send)*strlen(message->msg_sent));
 msg_buffer[seq_num % 256].user_sent = (char *) malloc(sizeof(uname)*strlen(message->user_sent));
 strcpy(msg_buffer[seq_num % 256].msg_sent, message->msg_sent);
 strcpy(msg_buffer[seq_num % 256].user_sent, message->user_sent);
 msg_buffer[seq_num % 256].seq_num = seq_num;
 msg_buffer[seq_num % 256].msg_type = message->msg_type;
 sendDatagram(
    msg_buffer[seq_num % 256].msg_type,
    msg_buffer[seq_num % 256].seq_num,
    msg_buffer[seq_num % 256].user_sent,
    msg_buffer[seq_num % 256].msg_sent);
 seq_num = seq_num + 1;
 return(&result);
}

canonical_original_code:
int *send_1_svc(struct msg_recv *message, struct svc_req *rqstp) {
 static int result = 0;
 int i;
 if (!initialized) {
  init_data_structures();
 }
 if (message->msg_sent == ((void *)0) || strlen(message->msg_sent) == 0 || message->msg_sent[0] == (-1)) {
  return(((void *)0));
 }
 msg_buffer[seq_num % 256].msg_sent = (char *) malloc(sizeof(msg_send)*strlen(message->msg_sent));
 msg_buffer[seq_num % 256].user_sent = (char *) malloc(sizeof(uname)*strlen(message->user_sent));
 strcpy(msg_buffer[seq_num % 256].msg_sent, message->msg_sent);
 strcpy(msg_buffer[seq_num % 256].user_sent, message->user_sent);
 msg_buffer[seq_num % 256].seq_num = seq_num;
 msg_buffer[seq_num % 256].msg_type = message->msg_type;
 sendDatagram(
    msg_buffer[seq_num % 256].msg_type,
    msg_buffer[seq_num % 256].seq_num,
    msg_buffer[seq_num % 256].user_sent,
    msg_buffer[seq_num % 256].msg_sent);
 seq_num = seq_num + 1;
 return(&result);
}

variable_types: struct msg_recv { char *msg_sent; char *user_sent; unsigned int seq_num; enum msg_type_t { TEXT=0, NEWUSER=1, USEREXIT=2, ELECTION=3 } msg_type; } *

variable_types: result int

user_defined_types: struct msg_recv { char *msg_sent; char *user_sent; unsigned int seq_num; enum msg_type_t msg_type; }

user_defined_types: struct opaque_auth { int oa_flavor; char *oa_base; unsigned int oa_length; }

user_defined_types: enum xprt_stat { XPRT_DIED=0, XPRT_MOREREQS=1, XPRT_IDLE=2 }

user_defined_types: struct call_body { unsigned long cb_rpcvers; unsigned long cb_prog; unsigned long cb_vers; unsigned long cb_proc; struct opaque_auth cb_cred; struct opaque_auth cb_verf; }

user_defined_types: enum reply_stat { MSG_ACCEPTED=0, MSG_DENIED=1 }

user_defined_types: enum accept_stat { SUCCESS=0, PROG_UNAVAIL=1, PROG_MISMATCH=2, PROC_UNAVAIL=3, GARBAGE_ARGS=4, SYSTEM_ERR=5 }

user_defined_types: enum reject_stat { RPC_MISMATCH=0, AUTH_ERROR=1 }

user_defined_types: enum auth_stat { AUTH_OK=0, AUTH_BADCRED=1, AUTH_REJECTEDCRED=2, AUTH_BADVERF=3, AUTH_REJECTEDVERF=4, AUTH_TOOWEAK=5, AUTH_INVALIDRESP=6, AUTH_FAILED=7 }

user_defined_types: enum xdr_op { XDR_ENCODE=0, XDR_DECODE=1, XDR_FREE=2 }

user_defined_types: struct xdr_ops { int (*x_getlong)(struct XDR *__xdrs, long *__lp); int (*x_putlong)(struct XDR *__xdrs, long *__lp); int (*x_getbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); int (*x_putbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); unsigned int (*x_getpostn)(struct XDR *__xdrs); int (*x_setpostn)(struct XDR *__xdrs, unsigned int __pos); int *(*x_inline)(struct XDR *__xdrs, unsigned int __len); void (*x_destroy)(struct XDR *__xdrs); int (*x_getint32)(struct XDR *__xdrs, int *__ip); int (*x_putint32)(struct XDR *__xdrs, int *__ip); }


decompiled_code:
__int64 __fastcall redeliver_1_svc(unsigned __int8 *a1)
{
return msg_buffer + 24LL * *a1;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned __int8 *a1)
{
return msg_buffer + 24LL * *a1;
}

original_code:
msg_recv *redeliver_1_svc(u_int * seq_num, struct svc_req *rqstp) {
 return &(msg_buffer[*seq_num % 256]);
}

canonical_original_code:
struct msg_recv *redeliver_1_svc(unsigned int *seq_num, struct svc_req *rqstp) {
 return &(msg_buffer[*seq_num % 256]);
}

return_type: struct msg_recv { char *msg_sent; char *user_sent; unsigned int seq_num; enum msg_type_t { TEXT=0, NEWUSER=1, USEREXIT=2, ELECTION=3 } msg_type; } *

user_defined_types: struct svc_req { unsigned long rq_prog; unsigned long rq_vers; unsigned long rq_proc; struct opaque_auth rq_cred; char *rq_clntcred; struct SVCXPRT *rq_xprt; }

user_defined_types: struct SVCXPRT { int xp_sock; unsigned short xp_port; struct xp_ops *xp_ops; int xp_addrlen; struct sockaddr_in xp_raddr; struct opaque_auth xp_verf; char *xp_p1; char *xp_p2; char xp_pad[256]; }

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