original_code:
double xltek_convertSample( int sample, int headbox_type, int channel,
                            int discard_bits, const char *sw_version )
{
  static double const conv_8711 = 8711.0 / (2097152.0 - 0.5);
  static double const conv_5e7 = (5000000.0 / (1024.0 - 0.5)) / 64.0;
  static double const conv_2neg6 = 1.0 / 64.0;
  static double const conv_hyppo = (8711.0/(2097152.0-0.5))/(159.8/249.5);
  static double const conv_1e8 = (10000000.0 / (1024.0 - 0.5)) / 64.0;
  static double const conv_2e8 = (20000000.0 / 65536.0);
  static double const conv_108e6 = (10800000.0 / 65536.0) / 64.0;
  double as_doub;
  double two_power = pow(2.0, (double) discard_bits);
  switch (headbox_type) {
    case 1: as_doub = (double) sample * conv_8711 * two_power;
              break;
    case 3: as_doub = (double) sample * conv_8711 * two_power;
              break;
    case 4: if (channel <= 23) {
                as_doub = (double) sample * conv_8711 * two_power;
              } else {
                as_doub = (double) sample * conv_5e7 * two_power;
              }
              break;
    case 5: if (channel <= 25) {
                as_doub = (double) sample * conv_8711 * two_power;
              } else if (channel <= 31) {
                as_doub = (double) sample * conv_hyppo * two_power;
              } else if (channel <= 39 && atof(sw_version) < 3.4) {
                as_doub = (double) sample * conv_1e8 * two_power;
              } else if (channel <= 39 && atof(sw_version)) {
                as_doub = (double) sample * conv_2e8 * two_power;
              } else {
                as_doub = (double) sample * conv_2neg6 * two_power;
              }
              break;
    case 6: if (channel <= 31) {
                as_doub = (double) sample * conv_8711 * two_power;
              } else {
                as_doub = (double) sample * conv_5e7 * two_power;
              }
              break;
    case 8: if (channel <= 24) {
                as_doub = (double) sample * conv_8711 * two_power;
              } else {
                as_doub = (double) sample * conv_2neg6 * two_power;
              }
              break;
    case 9: if (channel <= 32) {
                as_doub = (double) sample * conv_8711 * two_power;
              } else {
                as_doub = (double) sample * conv_2neg6 * two_power;
              }
              break;
    case 14: if (channel <= 37) {
                as_doub = (double) sample * conv_8711 * two_power;
              } else if (channel <= 47) {
                as_doub = (double) sample * conv_108e6 * two_power;
              } else {
                as_doub = (double) sample * conv_2neg6 * two_power;
              }
              break;
    case 15: if (channel <= 27) {
                as_doub = (double) sample * conv_8711 * two_power;
              } else if (channel <= 31) {
                as_doub = (double) sample * conv_1e8 * two_power;
              } else {
                as_doub = (double) sample * conv_2neg6 * two_power;
              }
              break;
    case 17: if (channel <= 39) {
                as_doub = (double) sample * conv_8711 * two_power;
              } else if (channel <= 43) {
                as_doub = (double) sample * conv_108e6 * two_power;
              } else {
                as_doub = (double) sample * conv_2neg6 * two_power;
              }
              break;
    case 19: as_doub = (double) sample * conv_8711 * two_power;
              break;
    case 21: if (channel <= 127) {
                as_doub = (double) sample * conv_8711 * two_power;
              } else {
                as_doub = (double) sample * conv_2neg6 * two_power;
              }
              break;
    case 22: if (channel <= 31) {
                as_doub = (double) sample * conv_8711 * two_power;
              } else if (channel <= 39) {
                as_doub = (double) sample * conv_108e6 * two_power;
              } else if (channel <= 41) {
                as_doub = (double) sample * conv_2neg6 * two_power;
              } else {
                as_doub = (double) sample * conv_108e6 * two_power;
              }
              break;
    case 23: if (channel <= 31) {
                as_doub = (double) sample * conv_8711 * two_power;
              } else if (channel <= 35) {
                as_doub = (double) sample * conv_108e6 * two_power;
              } else if (channel <= 37) {
                as_doub = (double) sample * conv_2neg6 * two_power;
              } else {
                as_doub = (double) sample * conv_108e6 * two_power;
              }
              break;
    default:
      fprintf( stderr, "Unknown headbox type (%d)!\n", headbox_type );
      as_doub = 0.0;
  }
  return as_doub;
}

canonical_original_code:
double xltek_convertSample(int sample, int headbox_type, int channel, int discard_bits, char *sw_version)
{
  static double conv_8711 = 8711.0 / (2097152.0 - 0.5);
  static double conv_5e7 = (5000000.0 / (1024.0 - 0.5)) / 64.0;
  static double conv_2neg6 = 1.0 / 64.0;
  static double conv_hyppo = (8711.0/(2097152.0-0.5))/(159.8/249.5);
  static double conv_1e8 = (10000000.0 / (1024.0 - 0.5)) / 64.0;
  static double conv_2e8 = (20000000.0 / 65536.0);
  static double conv_108e6 = (10800000.0 / 65536.0) / 64.0;
  double as_doub;
  double two_power = pow(2.0, (double) discard_bits);
  switch (headbox_type) {
    case 1: as_doub = (double) sample * conv_8711 * two_power;
              break;
    case 3: as_doub = (double) sample * conv_8711 * two_power;
              break;
    case 4: if (channel <= 23) {
                as_doub = (double) sample * conv_8711 * two_power;
              } else {
                as_doub = (double) sample * conv_5e7 * two_power;
              }
              break;
    case 5: if (channel <= 25) {
                as_doub = (double) sample * conv_8711 * two_power;
              } else if (channel <= 31) {
                as_doub = (double) sample * conv_hyppo * two_power;
              } else if (channel <= 39 && atof(sw_version) < 3.4) {
                as_doub = (double) sample * conv_1e8 * two_power;
              } else if (channel <= 39 && atof(sw_version)) {
                as_doub = (double) sample * conv_2e8 * two_power;
              } else {
                as_doub = (double) sample * conv_2neg6 * two_power;
              }
              break;
    case 6: if (channel <= 31) {
                as_doub = (double) sample * conv_8711 * two_power;
              } else {
                as_doub = (double) sample * conv_5e7 * two_power;
              }
              break;
    case 8: if (channel <= 24) {
                as_doub = (double) sample * conv_8711 * two_power;
              } else {
                as_doub = (double) sample * conv_2neg6 * two_power;
              }
              break;
    case 9: if (channel <= 32) {
                as_doub = (double) sample * conv_8711 * two_power;
              } else {
                as_doub = (double) sample * conv_2neg6 * two_power;
              }
              break;
    case 14: if (channel <= 37) {
                as_doub = (double) sample * conv_8711 * two_power;
              } else if (channel <= 47) {
                as_doub = (double) sample * conv_108e6 * two_power;
              } else {
                as_doub = (double) sample * conv_2neg6 * two_power;
              }
              break;
    case 15: if (channel <= 27) {
                as_doub = (double) sample * conv_8711 * two_power;
              } else if (channel <= 31) {
                as_doub = (double) sample * conv_1e8 * two_power;
              } else {
                as_doub = (double) sample * conv_2neg6 * two_power;
              }
              break;
    case 17: if (channel <= 39) {
                as_doub = (double) sample * conv_8711 * two_power;
              } else if (channel <= 43) {
                as_doub = (double) sample * conv_108e6 * two_power;
              } else {
                as_doub = (double) sample * conv_2neg6 * two_power;
              }
              break;
    case 19: as_doub = (double) sample * conv_8711 * two_power;
              break;
    case 21: if (channel <= 127) {
                as_doub = (double) sample * conv_8711 * two_power;
              } else {
                as_doub = (double) sample * conv_2neg6 * two_power;
              }
              break;
    case 22: if (channel <= 31) {
                as_doub = (double) sample * conv_8711 * two_power;
              } else if (channel <= 39) {
                as_doub = (double) sample * conv_108e6 * two_power;
              } else if (channel <= 41) {
                as_doub = (double) sample * conv_2neg6 * two_power;
              } else {
                as_doub = (double) sample * conv_108e6 * two_power;
              }
              break;
    case 23: if (channel <= 31) {
                as_doub = (double) sample * conv_8711 * two_power;
              } else if (channel <= 35) {
                as_doub = (double) sample * conv_108e6 * two_power;
              } else if (channel <= 37) {
                as_doub = (double) sample * conv_2neg6 * two_power;
              } else {
                as_doub = (double) sample * conv_108e6 * two_power;
              }
              break;
    default:
      fprintf( stderr, "Unknown headbox type (%d)!\n", headbox_type );
      as_doub = 0.0;
  }
  return as_doub;
}

variable_types: sample int

variable_types: channel int

return_type: double


repo: brandtd/eyeblink

decompiled_code:
int __fastcall xltek_printErdHeaderS5(__int64 a1)
{
unsigned int v1; // er10
__int64 v2; // r8
__int64 v3; // r9
__int64 v4; // r11
char *v5; // rax
unsigned int v6; // esi
unsigned int v8; // [rsp+0h] [rbp-18h] BYREF
unsigned int v9; // [rsp+4h] [rbp-14h]
unsigned int v10; // [rsp+8h] [rbp-10h]
unsigned int v11; // [rsp+Ch] [rbp-Ch]
char v12; // [rsp+10h] [rbp-8h] BYREF

v2 = *(unsigned int *)(a1 + 148);
v3 = *(unsigned int *)(a1 + 152);
v4 = *(unsigned int *)(a1 + 156);
v5 = (char *)&v8;
v6 = num_headbox_types;
v8 = *(_DWORD *)(a1 + 144);
v1 = v8;
v9 = v2;
v10 = v3;
v11 = v4;
if ( num_headbox_types > v8 )
goto LABEL_3;
while ( 1 )
{
*(_DWORD *)v5 = 0;
LABEL_3:
v5 += 4;
if ( &v12 == v5 )
break;
while ( v6 > *(_DWORD *)v5 )
{
v5 += 4;
if ( &v12 == v5 )
return printf(
"ERD schema 5.\n"
"Sample frequency: %g\n"
"Number of channels: %d\n"
"Bits of delta per channel: %d\n"
"Storage order: --skipped--\n"
"\n"
"Headbox: type | serial | software version\n"
" ------------+----------+-----------------\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
"\n"
"DSP hardware version: %s\n"
"DSP software version: %s\n"
"Discarded least sig. bits: %d\n",
*(double *)a1,
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12),
v1,
&headbox_types[10 * v8],
*(unsigned int *)(a1 + 160),
(const char *)(a1 + 176),
v2,
&headbox_types[10 * v9],
*(unsigned int *)(a1 + 164),
(const char *)(a1 + 186),
v3,
&headbox_types[10 * v10],
*(unsigned int *)(a1 + 168),
(const char *)(a1 + 196),
v4,
&headbox_types[10 * v11],
*(unsigned int *)(a1 + 172),
(const char *)(a1 + 206),
(const char *)(a1 + 216),
(const char *)(a1 + 226),
*(unsigned int *)(a1 + 236));
}
}
return printf(
"ERD schema 5.\n"
"Sample frequency: %g\n"
"Number of channels: %d\n"
"Bits of delta per channel: %d\n"
"Storage order: --skipped--\n"
"\n"
"Headbox: type | serial | software version\n"
" ------------+----------+-----------------\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
"\n"
"DSP hardware version: %s\n"
"DSP software version: %s\n"
"Discarded least sig. bits: %d\n",
*(double *)a1,
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12),
v1,
&headbox_types[10 * v8],
*(unsigned int *)(a1 + 160),
(const char *)(a1 + 176),
v2,
&headbox_types[10 * v9],
*(unsigned int *)(a1 + 164),
(const char *)(a1 + 186),
v3,
&headbox_types[10 * v10],
*(unsigned int *)(a1 + 168),
(const char *)(a1 + 196),
v4,
&headbox_types[10 * v11],
*(unsigned int *)(a1 + 172),
(const char *)(a1 + 206),
(const char *)(a1 + 216),
(const char *)(a1 + 226),
*(unsigned int *)(a1 + 236));
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
unsigned int v1; // er10
__int64 v2; // r8
__int64 v3; // r9
__int64 v4; // r11
char *v5; // rax
unsigned int v6; // esi
unsigned int v8; // [rsp+0h] [rbp-18h] BYREF
unsigned int v9; // [rsp+4h] [rbp-14h]
unsigned int v10; // [rsp+8h] [rbp-10h]
unsigned int v11; // [rsp+Ch] [rbp-Ch]
char v12; // [rsp+10h] [rbp-8h] BYREF

v2 = *(unsigned int *)(a1 + 148);
v3 = *(unsigned int *)(a1 + 152);
v4 = *(unsigned int *)(a1 + 156);
v5 = (char *)&v8;
v6 = num_headbox_types;
v8 = *(_DWORD *)(a1 + 144);
v1 = v8;
v9 = v2;
v10 = v3;
v11 = v4;
if ( num_headbox_types > v8 )
goto LABEL_3;
while ( 1 )
{
*(_DWORD *)v5 = 0;
LABEL_3:
v5 += 4;
if ( &v12 == v5 )
break;
while ( v6 > *(_DWORD *)v5 )
{
v5 += 4;
if ( &v12 == v5 )
return printf(
"ERD schema 5.\n"
"Sample frequency: %g\n"
"Number of channels: %d\n"
"Bits of delta per channel: %d\n"
"Storage order: --skipped--\n"
"\n"
"Headbox: type | serial | software version\n"
" ------------+----------+-----------------\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
"\n"
"DSP hardware version: %s\n"
"DSP software version: %s\n"
"Discarded least sig. bits: %d\n",
*(double *)a1,
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12),
v1,
&headbox_types[10 * v8],
*(unsigned int *)(a1 + 160),
(const char *)(a1 + 176),
v2,
&headbox_types[10 * v9],
*(unsigned int *)(a1 + 164),
(const char *)(a1 + 186),
v3,
&headbox_types[10 * v10],
*(unsigned int *)(a1 + 168),
(const char *)(a1 + 196),
v4,
&headbox_types[10 * v11],
*(unsigned int *)(a1 + 172),
(const char *)(a1 + 206),
(const char *)(a1 + 216),
(const char *)(a1 + 226),
*(unsigned int *)(a1 + 236));
}
}
return printf(
"ERD schema 5.\n"
"Sample frequency: %g\n"
"Number of channels: %d\n"
"Bits of delta per channel: %d\n"
"Storage order: --skipped--\n"
"\n"
"Headbox: type | serial | software version\n"
" ------------+----------+-----------------\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
"\n"
"DSP hardware version: %s\n"
"DSP software version: %s\n"
"Discarded least sig. bits: %d\n",
*(double *)a1,
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12),
v1,
&headbox_types[10 * v8],
*(unsigned int *)(a1 + 160),
(const char *)(a1 + 176),
v2,
&headbox_types[10 * v9],
*(unsigned int *)(a1 + 164),
(const char *)(a1 + 186),
v3,
&headbox_types[10 * v10],
*(unsigned int *)(a1 + 168),
(const char *)(a1 + 196),
v4,
&headbox_types[10 * v11],
*(unsigned int *)(a1 + 172),
(const char *)(a1 + 206),
(const char *)(a1 + 216),
(const char *)(a1 + 226),
*(unsigned int *)(a1 + 236));
}

original_code:
void xltek_printErdHeaderS5( const xltek_erd_s5_t *head )
{
  unsigned int i, boxtype[4] = { head->m_headbox_type[0],
                                 head->m_headbox_type[1],
                                 head->m_headbox_type[2],
                                 head->m_headbox_type[3] };
  for (i = 0; i < 4; i++) {
    if (boxtype[i] >= _num_headbox_types) {
      boxtype[i] = 0;
    }
  }
  printf("ERD schema 5.\n"
         "Sample frequency:           %g\n"
         "Number of channels:         %d\n"
         "Bits of delta per channel:  %d\n"
         "Storage order:              --skipped--\n"
         "\n"
         "Headbox:  type        |  serial  | software version\n"
         "          ------------+----------+-----------------\n"
         "          %d %s | %08X | %s\n"
         "          %d %s | %08X | %s\n"
         "          %d %s | %08X | %s\n"
         "          %d %s | %08X | %s\n"
         "\n"
         "DSP hardware version:       %s\n"
         "DSP software version:       %s\n"
         "Discarded least sig. bits:  %d\n",
         head->m_sample_freq,
         head->m_num_channels,
         head->m_deltabits,
         head->m_headbox_type[0], _headbox_types[boxtype[0]],
            head->m_headbox_sn[0], head->m_headbox_sw_version[0],
         head->m_headbox_type[1], _headbox_types[boxtype[1]],
            head->m_headbox_sn[1], head->m_headbox_sw_version[1],
         head->m_headbox_type[2], _headbox_types[boxtype[2]],
            head->m_headbox_sn[2], head->m_headbox_sw_version[2],
         head->m_headbox_type[3], _headbox_types[boxtype[3]],
            head->m_headbox_sn[3], head->m_headbox_sw_version[3],
         head->m_dsp_hw_version,
         head->m_dsp_sw_version,
         head->m_discardbits );
}

canonical_original_code:
void xltek_printErdHeaderS5(struct xltek_erd_s5_t *head)
{
  unsigned int i; unsigned int boxtype[4] = { head->m_headbox_type[0],
                                 head->m_headbox_type[1],
                                 head->m_headbox_type[2],
                                 head->m_headbox_type[3] };
  for (i = 0; i < 4; i++) {
    if (boxtype[i] >= _num_headbox_types) {
      boxtype[i] = 0;
    }
  }
  printf("ERD schema 5.\n"
         "Sample frequency:           %g\n"
         "Number of channels:         %d\n"
         "Bits of delta per channel:  %d\n"
         "Storage order:              --skipped--\n"
         "\n"
         "Headbox:  type        |  serial  | software version\n"
         "          ------------+----------+-----------------\n"
         "          %d %s | %08X | %s\n"
         "          %d %s | %08X | %s\n"
         "          %d %s | %08X | %s\n"
         "          %d %s | %08X | %s\n"
         "\n"
         "DSP hardware version:       %s\n"
         "DSP software version:       %s\n"
         "Discarded least sig. bits:  %d\n",
         head->m_sample_freq,
         head->m_num_channels,
         head->m_deltabits,
         head->m_headbox_type[0], _headbox_types[boxtype[0]],
            head->m_headbox_sn[0], head->m_headbox_sw_version[0],
         head->m_headbox_type[1], _headbox_types[boxtype[1]],
            head->m_headbox_sn[1], head->m_headbox_sw_version[1],
         head->m_headbox_type[2], _headbox_types[boxtype[2]],
            head->m_headbox_sn[2], head->m_headbox_sw_version[2],
         head->m_headbox_type[3], _headbox_types[boxtype[3]],
            head->m_headbox_sn[3], head->m_headbox_sw_version[3],
         head->m_dsp_hw_version,
         head->m_dsp_sw_version,
         head->m_discardbits );
}

variable_types: struct xltek_erd_s5_t { double m_sample_freq; unsigned int m_num_channels; unsigned int m_deltabits; unsigned int m_phys_chan[32]; unsigned int m_headbox_type[4]; unsigned int m_headbox_sn[4]; char m_headbox_sw_version[4][10]; char m_dsp_hw_version[10]; char m_dsp_sw_version[10]; unsigned int m_discardbits; } *

variable_types:
i
unsigned int

variable_types:
boxtype
unsigned int [4]

return_type: void


decompiled_code:
int __fastcall xltek_printErdHeaderS6(__int64 a1)
{
unsigned int v1; // er10
__int64 v2; // r8
__int64 v3; // r9
__int64 v4; // r11
char *v5; // rax
unsigned int v6; // esi
unsigned int v8; // [rsp+0h] [rbp-18h] BYREF
unsigned int v9; // [rsp+4h] [rbp-14h]
unsigned int v10; // [rsp+8h] [rbp-10h]
unsigned int v11; // [rsp+Ch] [rbp-Ch]
char v12; // [rsp+10h] [rbp-8h] BYREF

v2 = *(unsigned int *)(a1 + 532);
v3 = *(unsigned int *)(a1 + 536);
v4 = *(unsigned int *)(a1 + 540);
v5 = (char *)&v8;
v6 = num_headbox_types;
v8 = *(_DWORD *)(a1 + 528);
v1 = v8;
v9 = v2;
v10 = v3;
v11 = v4;
if ( num_headbox_types > v8 )
goto LABEL_3;
while ( 1 )
{
*(_DWORD *)v5 = 0;
LABEL_3:
v5 += 4;
if ( &v12 == v5 )
break;
while ( v6 > *(_DWORD *)v5 )
{
v5 += 4;
if ( &v12 == v5 )
return printf(
"ERD schema 6.\n"
"Sample frequency: %g\n"
"Number of channels: %d\n"
"Bits of delta per channel: %d\n"
"Storage order: --skipped--\n"
"\n"
"Headbox: type | serial | software version\n"
" ------------+----------+-----------------\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
"\n"
"DSP hardware version: %s\n"
"DSP software version: %s\n"
"Discarded least sig. bits: %d\n",
*(double *)a1,
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12),
v1,
&headbox_types[10 * v8],
*(unsigned int *)(a1 + 544),
(const char *)(a1 + 560),
v2,
&headbox_types[10 * v9],
*(unsigned int *)(a1 + 548),
(const char *)(a1 + 570),
v3,
&headbox_types[10 * v10],
*(unsigned int *)(a1 + 552),
(const char *)(a1 + 580),
v4,
&headbox_types[10 * v11],
*(unsigned int *)(a1 + 556),
(const char *)(a1 + 590),
(const char *)(a1 + 600),
(const char *)(a1 + 610),
*(unsigned int *)(a1 + 620));
}
}
return printf(
"ERD schema 6.\n"
"Sample frequency: %g\n"
"Number of channels: %d\n"
"Bits of delta per channel: %d\n"
"Storage order: --skipped--\n"
"\n"
"Headbox: type | serial | software version\n"
" ------------+----------+-----------------\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
"\n"
"DSP hardware version: %s\n"
"DSP software version: %s\n"
"Discarded least sig. bits: %d\n",
*(double *)a1,
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12),
v1,
&headbox_types[10 * v8],
*(unsigned int *)(a1 + 544),
(const char *)(a1 + 560),
v2,
&headbox_types[10 * v9],
*(unsigned int *)(a1 + 548),
(const char *)(a1 + 570),
v3,
&headbox_types[10 * v10],
*(unsigned int *)(a1 + 552),
(const char *)(a1 + 580),
v4,
&headbox_types[10 * v11],
*(unsigned int *)(a1 + 556),
(const char *)(a1 + 590),
(const char *)(a1 + 600),
(const char *)(a1 + 610),
*(unsigned int *)(a1 + 620));
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
unsigned int v1; // er10
__int64 v2; // r8
__int64 v3; // r9
__int64 v4; // r11
char *v5; // rax
unsigned int v6; // esi
unsigned int v8; // [rsp+0h] [rbp-18h] BYREF
unsigned int v9; // [rsp+4h] [rbp-14h]
unsigned int v10; // [rsp+8h] [rbp-10h]
unsigned int v11; // [rsp+Ch] [rbp-Ch]
char v12; // [rsp+10h] [rbp-8h] BYREF

v2 = *(unsigned int *)(a1 + 532);
v3 = *(unsigned int *)(a1 + 536);
v4 = *(unsigned int *)(a1 + 540);
v5 = (char *)&v8;
v6 = num_headbox_types;
v8 = *(_DWORD *)(a1 + 528);
v1 = v8;
v9 = v2;
v10 = v3;
v11 = v4;
if ( num_headbox_types > v8 )
goto LABEL_3;
while ( 1 )
{
*(_DWORD *)v5 = 0;
LABEL_3:
v5 += 4;
if ( &v12 == v5 )
break;
while ( v6 > *(_DWORD *)v5 )
{
v5 += 4;
if ( &v12 == v5 )
return printf(
"ERD schema 6.\n"
"Sample frequency: %g\n"
"Number of channels: %d\n"
"Bits of delta per channel: %d\n"
"Storage order: --skipped--\n"
"\n"
"Headbox: type | serial | software version\n"
" ------------+----------+-----------------\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
"\n"
"DSP hardware version: %s\n"
"DSP software version: %s\n"
"Discarded least sig. bits: %d\n",
*(double *)a1,
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12),
v1,
&headbox_types[10 * v8],
*(unsigned int *)(a1 + 544),
(const char *)(a1 + 560),
v2,
&headbox_types[10 * v9],
*(unsigned int *)(a1 + 548),
(const char *)(a1 + 570),
v3,
&headbox_types[10 * v10],
*(unsigned int *)(a1 + 552),
(const char *)(a1 + 580),
v4,
&headbox_types[10 * v11],
*(unsigned int *)(a1 + 556),
(const char *)(a1 + 590),
(const char *)(a1 + 600),
(const char *)(a1 + 610),
*(unsigned int *)(a1 + 620));
}
}
return printf(
"ERD schema 6.\n"
"Sample frequency: %g\n"
"Number of channels: %d\n"
"Bits of delta per channel: %d\n"
"Storage order: --skipped--\n"
"\n"
"Headbox: type | serial | software version\n"
" ------------+----------+-----------------\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
" %d %s | %08X | %s\n"
"\n"
"DSP hardware version: %s\n"
"DSP software version: %s\n"
"Discarded least sig. bits: %d\n",
*(double *)a1,
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12),
v1,
&headbox_types[10 * v8],
*(unsigned int *)(a1 + 544),
(const char *)(a1 + 560),
v2,
&headbox_types[10 * v9],
*(unsigned int *)(a1 + 548),
(const char *)(a1 + 570),
v3,
&headbox_types[10 * v10],
*(unsigned int *)(a1 + 552),
(const char *)(a1 + 580),
v4,
&headbox_types[10 * v11],
*(unsigned int *)(a1 + 556),
(const char *)(a1 + 590),
(const char *)(a1 + 600),
(const char *)(a1 + 610),
*(unsigned int *)(a1 + 620));
}

original_code:
void xltek_printErdHeaderS6( const xltek_erd_s6_t *head )
{
  unsigned int i, boxtype[4] = { head->m_headbox_type[0],
                                 head->m_headbox_type[1],
                                 head->m_headbox_type[2],
                                 head->m_headbox_type[3] };
  for (i = 0; i < 4; i++) {
    if (boxtype[i] >= _num_headbox_types) {
      boxtype[i] = 0;
    }
  }
  printf("ERD schema 6.\n"
         "Sample frequency:           %g\n"
         "Number of channels:         %d\n"
         "Bits of delta per channel:  %d\n"
         "Storage order:              --skipped--\n"
         "\n"
         "Headbox:  type        |  serial  | software version\n"
         "          ------------+----------+-----------------\n"
         "          %d %s | %08X | %s\n"
         "          %d %s | %08X | %s\n"
         "          %d %s | %08X | %s\n"
         "          %d %s | %08X | %s\n"
         "\n"
         "DSP hardware version:       %s\n"
         "DSP software version:       %s\n"
         "Discarded least sig. bits:  %d\n",
         head->m_sample_freq,
         head->m_num_channels,
         head->m_deltabits,
         head->m_headbox_type[0], _headbox_types[boxtype[0]],
            head->m_headbox_sn[0], head->m_headbox_sw_version[0],
         head->m_headbox_type[1], _headbox_types[boxtype[1]],
            head->m_headbox_sn[1], head->m_headbox_sw_version[1],
         head->m_headbox_type[2], _headbox_types[boxtype[2]],
            head->m_headbox_sn[2], head->m_headbox_sw_version[2],
         head->m_headbox_type[3], _headbox_types[boxtype[3]],
            head->m_headbox_sn[3], head->m_headbox_sw_version[3],
         head->m_dsp_hw_version,
         head->m_dsp_sw_version,
         head->m_discardbits );
}

canonical_original_code:
void xltek_printErdHeaderS6(struct xltek_erd_s6_t *head)
{
  unsigned int i; unsigned int boxtype[4] = { head->m_headbox_type[0],
                                 head->m_headbox_type[1],
                                 head->m_headbox_type[2],
                                 head->m_headbox_type[3] };
  for (i = 0; i < 4; i++) {
    if (boxtype[i] >= _num_headbox_types) {
      boxtype[i] = 0;
    }
  }
  printf("ERD schema 6.\n"
         "Sample frequency:           %g\n"
         "Number of channels:         %d\n"
         "Bits of delta per channel:  %d\n"
         "Storage order:              --skipped--\n"
         "\n"
         "Headbox:  type        |  serial  | software version\n"
         "          ------------+----------+-----------------\n"
         "          %d %s | %08X | %s\n"
         "          %d %s | %08X | %s\n"
         "          %d %s | %08X | %s\n"
         "          %d %s | %08X | %s\n"
         "\n"
         "DSP hardware version:       %s\n"
         "DSP software version:       %s\n"
         "Discarded least sig. bits:  %d\n",
         head->m_sample_freq,
         head->m_num_channels,
         head->m_deltabits,
         head->m_headbox_type[0], _headbox_types[boxtype[0]],
            head->m_headbox_sn[0], head->m_headbox_sw_version[0],
         head->m_headbox_type[1], _headbox_types[boxtype[1]],
            head->m_headbox_sn[1], head->m_headbox_sw_version[1],
         head->m_headbox_type[2], _headbox_types[boxtype[2]],
            head->m_headbox_sn[2], head->m_headbox_sw_version[2],
         head->m_headbox_type[3], _headbox_types[boxtype[3]],
            head->m_headbox_sn[3], head->m_headbox_sw_version[3],
         head->m_dsp_hw_version,
         head->m_dsp_sw_version,
         head->m_discardbits );
}

variable_types: struct xltek_erd_s6_t { double m_sample_freq; unsigned int m_num_channels; unsigned int m_deltabits; unsigned int m_phys_chan[128]; unsigned int m_headbox_type[4]; unsigned int m_headbox_sn[4]; char m_headbox_sw_version[4][10]; char m_dsp_hw_version[10]; char m_dsp_sw_version[10]; unsigned int m_discardbits; } *


decompiled_code:
void __fastcall mat_freeMatrix(__int64 a1)
{
void *v2; // rdi

v2 = *(void **)a1;
if ( v2 )
{
free(v2);
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
}
}

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

v2 = *(void **)a1;
if ( v2 )
{
free(v2);
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
}
}

original_code:
void mat_freeMatrix( Matrix *mat )
{
  if (mat->elem) {
    free(mat->elem);
    mat->elem = ((void *)0);
    mat->rows = 0;
    mat->cols = 0;
  }
}

canonical_original_code:
void mat_freeMatrix(struct Matrix *mat)
{
  if (mat->elem) {
    free(mat->elem);
    mat->elem = ((void *)0);
    mat->rows = 0;
    mat->cols = 0;
  }
}

variable_types: struct Matrix { float *elem; int rows; int cols; int ld; int lag; } *


decompiled_code:
__int64 __fastcall mat_similar(__int64 a1, _QWORD *a2, float a3)
{
int v3; // edx
__int64 v4; // rax

if ( *(_QWORD *)(a1 + 8) != a2[1] )
return 0LL;
v3 = *(_DWORD *)(a1 + 8) * *(_DWORD *)(a1 + 12);
if ( v3 > 0 )
{
v4 = 0LL;
while ( COERCE_FLOAT(COERCE_UNSIGNED_INT(*(float *)(*(_QWORD *)a1 + 4 * v4) - *(float *)(*a2 + 4 * v4)) & LC2) <= a3 )
{
if ( v3 == ++v4 )
return 1LL;
}
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, _QWORD *a2, float a3)
{
int v3; // edx
__int64 v4; // rax

if ( *(_QWORD *)(a1 + 8) != a2[1] )
return 0LL;
v3 = *(_DWORD *)(a1 + 8) * *(_DWORD *)(a1 + 12);
if ( v3 > 0 )
{
v4 = 0LL;
while ( COERCE_FLOAT(COERCE_UNSIGNED_INT(*(float *)(*(_QWORD *)a1 + 4 * v4) - *(float *)(*a2 + 4 * v4)) & LC2) <= a3 )
{
if ( v3 == ++v4 )
return 1LL;
}
return 0LL;
}
return 1LL;
}

original_code:
int mat_similar( Matrix const *mat1, Matrix const *mat2, float epsilon )
{
  int i;
  if (mat1->rows != mat2->rows || mat1->cols != mat2->cols) {
    return 0;
  }
  for (i = 0; i < mat1->rows * mat1->cols; i++) {
    if (fabs(mat1->elem[i] - mat2->elem[i]) > epsilon) {
      return 0;
    }
  }
  return 1;
}

canonical_original_code:
int mat_similar(struct Matrix *mat1, struct Matrix *mat2, float epsilon)
{
  int i;
  if (mat1->rows != mat2->rows || mat1->cols != mat2->cols) {
    return 0;
  }
  for (i = 0; i < mat1->rows * mat1->cols; i++) {
    if (fabs(mat1->elem[i] - mat2->elem[i]) > epsilon) {
      return 0;
    }
  }
  return 1;
}

variable_types: epsilon float

variable_types: i int

return_type: int

user_defined_types: struct Matrix { float *elem; int rows; int cols; int ld; int lag; }


blinkSource

original_code:
int blinkSource( const Matrix *mat_S, const int *blinks, int len_blinks,
                 const BlinkParams *params )
{
  int i, steps_1, len_template, eb_start, template_start, length, source;
  float *eb_template, *templ;
  eb_template = (float*) calloc( mat_S->cols, sizeof(float) );
  templ = getTemplate( &steps_1, &len_template, params );
  for (i = 0; i < len_blinks; i++) {
    eb_start = blinks[i] - steps_1;
    if (eb_start < 0) { template_start = -eb_start; eb_start = 0; }
    else { template_start = 0; }
    if ((eb_start + len_template) >= mat_S->cols) {
      length = len_template - (eb_start + len_template - mat_S->cols);
    } else {
      length = len_template - template_start;
    }
    memcpy( eb_template + eb_start, templ + template_start,
            sizeof(float) * length );
  }
  source = maxCorrelate( mat_S, eb_template );
  free( eb_template );
  free( templ );
  return source;
}

canonical_original_code:
int blinkSource(struct Matrix *mat_S, int *blinks, int len_blinks, struct BlinkParams *params)
{
  int i; int steps_1; int len_template; int eb_start; int template_start; int length; int source;
  float *eb_template; float *templ;
  eb_template = (float *) calloc( mat_S->cols, sizeof(float) );
  templ = getTemplate( &steps_1, &len_template, params );
  for (i = 0; i < len_blinks; i++) {
    eb_start = blinks[i] - steps_1;
    if (eb_start < 0) { template_start = -eb_start; eb_start = 0; }
    else { template_start = 0; }
    if ((eb_start + len_template) >= mat_S->cols) {
      length = len_template - (eb_start + len_template - mat_S->cols);
    } else {
      length = len_template - template_start;
    }
    memcpy( eb_template + eb_start, templ + template_start,
            sizeof(float) * length );
  }
  source = maxCorrelate( mat_S, eb_template );
  free( eb_template );
  free( templ );
  return source;
}

variable_types:
blinks
int *

variable_types: struct BlinkParams { float f_s; float t_1; float t_cor; } *

variable_types: length int

variable_types: source int

variable_types:
templ
float *


decompiled_code:
void *__fastcall adc_MB_SetBuf(__int64 a1, size_t a2)
{
void *v3; // rdi
void *result; // rax

if ( !a1 )
{
fprintf(stderr, "Assertion failed: %s (%s: %d)\n", "mb", "adcmb.c", 60LL);
abort();
}
v3 = *(void **)(a1 + 24);
if ( v3 )
free(v3);
result = malloc(a2);
*(_QWORD *)(a1 + 24) = result;
if ( !result )
{
fprintf(stderr, "FATAL ERROR: OUT OF MEMORY (%s: %d)\n", "adcmb.c", 66LL);
abort();
}
return result;
}

canonical_decompiled_code:
void *__fastcall func0(__int64 a1, size_t a2)
{
void *v3; // rdi
void *result; // rax

if ( !a1 )
{
fprintf(stderr, "Assertion failed: %s (%s: %d)\n", "mb", "adcmb.c", 60LL);
abort();
}
v3 = *(void **)(a1 + 24);
if ( v3 )
free(v3);
result = malloc(a2);
*(_QWORD *)(a1 + 24) = result;
if ( !result )
{
fprintf(stderr, "FATAL ERROR: OUT OF MEMORY (%s: %d)\n", "adcmb.c", 66LL);
abort();
}
return result;
}

original_code:
void adc_MB_SetBuf(adc_MB_t * mb, size_t len)
{
    do { if (__builtin_expect ((!(mb)), 0)) { fprintf (stderr, "Assertion failed: %s (%s: %d)\n", "mb", "adcmb.c", 60); abort(); } } while (0);
    if (mb->buffer != ((void *)0)) {
 free(mb->buffer);
    }
    do { if (__builtin_expect ((!((mb->buffer = (char *) malloc(len * sizeof(char))))), 0)) { fprintf (stderr, "FATAL ERROR: OUT OF MEMORY (%s: %d)\n", "adcmb.c", 66); abort(); } } while (0);
}

canonical_original_code:
void adc_MB_SetBuf(struct adc_MB_t *mb, unsigned long len)
{
    do { if (__builtin_expect ((!(mb)), 0)) { fprintf (stderr, "Assertion failed: %s (%s: %d)\n", "mb", "adcmb.c", 60); abort(); } } while (0);
    if (mb->buffer != ((void *)0)) {
 free(mb->buffer);
    }
    do { if (__builtin_expect ((!((mb->buffer = (char *) malloc(len * sizeof(char))))), 0)) { fprintf (stderr, "FATAL ERROR: OUT OF MEMORY (%s: %d)\n", "adcmb.c", 66); abort(); } } while (0);
}

variable_types: struct adc_MB_t { unsigned long size; unsigned long allocated; void *block; char *buffer; } *

variable_types:
len
unsigned long


decompiled_code:
void *__fastcall adc_MB_Init(unsigned __int64 *a1, unsigned __int64 a2)
{
size_t v2; // r8
void *v3; // rax

if ( !a1 )
{
fprintf(stderr, "Assertion failed: %s (%s: %d)\n", "mb", "adcmb.c", 100LL);
abort();
}
v2 = a2 + 1;
*a1 = a2;
if ( a2 <= 0xF )
v2 = 17LL;
a1[1] = v2;
v3 = calloc(1uLL, v2);
a1[2] = (unsigned __int64)v3;
if ( !v3 )
{
fprintf(stderr, "FATAL ERROR: OUT OF MEMORY (%s: %d)\n", "adcmb.c", 110LL);
abort();
}
return adc_MB_SetBuf((__int64)a1, 0x200uLL);
}

canonical_decompiled_code:
void *__fastcall func1(unsigned __int64 *a1, unsigned __int64 a2)
{
size_t v2; // r8
void *v3; // rax

if ( !a1 )
{
fprintf(stderr, "Assertion failed: %s (%s: %d)\n", "mb", "adcmb.c", 100LL);
abort();
}
v2 = a2 + 1;
*a1 = a2;
if ( a2 <= 0xF )
v2 = 17LL;
a1[1] = v2;
v3 = calloc(1uLL, v2);
a1[2] = (unsigned __int64)v3;
if ( !v3 )
{
fprintf(stderr, "FATAL ERROR: OUT OF MEMORY (%s: %d)\n", "adcmb.c", 110LL);
abort();
}
return func0((__int64)a1, 0x200uLL);
}

original_code:
void adc_MB_Init(adc_MB_t * mb, size_t size)
{
    do { if (__builtin_expect ((!(mb)), 0)) { fprintf (stderr, "Assertion failed: %s (%s: %d)\n", "mb", "adcmb.c", 100); abort(); } } while (0);
    if (size < 0x0000010) {
 mb->allocated = 0x0000010 + 1;
    } else {
 mb->allocated = size + 1;
    }
    mb->size = size;
    do { if (__builtin_expect ((!((mb->block = (void *) calloc(1, mb->allocated)))), 0)) { fprintf (stderr, "FATAL ERROR: OUT OF MEMORY (%s: %d)\n", "adcmb.c", 110); abort(); } } while (0);
    adc_MB_SetBuf(mb, 512);
}

canonical_original_code:
void adc_MB_Init(struct adc_MB_t *mb, unsigned long size)
{
    do { if (__builtin_expect ((!(mb)), 0)) { fprintf (stderr, "Assertion failed: %s (%s: %d)\n", "mb", "adcmb.c", 100); abort(); } } while (0);
    if (size < 0x0000010) {
 mb->allocated = 0x0000010 + 1;
    } else {
 mb->allocated = size + 1;
    }
    mb->size = size;
    do { if (__builtin_expect ((!((mb->block = (void *) calloc(1, mb->allocated)))), 0)) { fprintf (stderr, "FATAL ERROR: OUT OF MEMORY (%s: %d)\n", "adcmb.c", 110); abort(); } } while (0);
    adc_MB_SetBuf(mb, 512);
}

variable_types:
size
unsigned long

user_defined_types: struct adc_MB_t { unsigned long size; unsigned long allocated; void *block; char *buffer; }


decompiled_code:
void __fastcall adc_MB_Clean(_QWORD *a1)
{
void *v2; // rdi

if ( a1 )
{
v2 = (void *)a1[2];
if ( v2 )
{
free(v2);
a1[2] = 0LL;
*a1 = 0LL;
a1[1] = 0LL;
}
}
}

original_code:
void adc_MB_Clean(adc_MB_t * mb)
{
    if (mb == ((void *)0) || mb->block == ((void *)0)) {
 return;
    }
    free(mb->block);
    mb->block = ((void *)0);
    mb->size = 0;
    mb->allocated = 0;
}

canonical_original_code:
void adc_MB_Clean(struct adc_MB_t *mb)
{
    if (mb == ((void *)0) || mb->block == ((void *)0)) {
 return;
    }
    free(mb->block);
    mb->block = ((void *)0);
    mb->size = 0;
    mb->allocated = 0;
}


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

if ( ptr )
{
adc_MB_Clean(ptr);
v2 = (void *)*((_QWORD *)ptr + 3);
if ( v2 )
free(v2);
free(ptr);
}
}

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

if ( ptr )
{
func3(ptr);
v2 = (void *)*((_QWORD *)ptr + 3);
if ( v2 )
free(v2);
free(ptr);
}
}

original_code:
void adc_MB_Free(adc_MB_t * mb)
{
    if (mb == ((void *)0)) {
 return;
    }
    adc_MB_Clean(mb);
    if (mb->buffer != ((void *)0)) {
 free(mb->buffer);
    }
    free(mb);
}

canonical_original_code:
void adc_MB_Free(struct adc_MB_t *mb)
{
    if (mb == ((void *)0)) {
 return;
    }
    adc_MB_Clean(mb);
    if (mb->buffer != ((void *)0)) {
 free(mb->buffer);
    }
    free(mb);
}


decompiled_code:
__int64 __fastcall adc_MB_Size(__int64 a1)
{
if ( !a1 )
{
fprintf(stderr, "Assertion failed: %s (%s: %d)\n", "mb", "adcmb.c", 142LL);
abort();
}
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
if ( !a1 )
{
fprintf(stderr, "Assertion failed: %s (%s: %d)\n", "mb", "adcmb.c", 142LL);
abort();
}
return *(_QWORD *)a1;
}

original_code:
size_t adc_MB_Size(adc_MB_t * mb)
{
    do { if (__builtin_expect ((!(mb)), 0)) { fprintf (stderr, "Assertion failed: %s (%s: %d)\n", "mb", "adcmb.c", 142); abort(); } } while (0);
    return (mb->size);
}

canonical_original_code:
unsigned long adc_MB_Size(struct adc_MB_t *mb)
{
    do { if (__builtin_expect ((!(mb)), 0)) { fprintf (stderr, "Assertion failed: %s (%s: %d)\n", "mb", "adcmb.c", 142); abort(); } } while (0);
    return (mb->size);
}

return_type: unsigned long


decompiled_code:
__int64 __fastcall adc_MB_ToString(_QWORD *a1)
{
__int64 result; // rax

if ( !a1 )
return 0LL;
result = a1[2];
if ( result )
*(_BYTE *)(result + *a1) = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1)
{
__int64 result; // rax

if ( !a1 )
return 0LL;
result = a1[2];
if ( result )
*(_BYTE *)(result + *a1) = 0;
return result;
}

original_code:
char *adc_MB_ToString(adc_MB_t * mb)
{
    char *tmp;
    if (mb == ((void *)0) || mb->block == ((void *)0)) {
 return (((void *)0));
    }
    tmp = (char *) mb->block;
    tmp[mb->size] = '\0';
    return (tmp);
}

canonical_original_code:
char *adc_MB_ToString(struct adc_MB_t *mb)
{
    char *tmp;
    if (mb == ((void *)0) || mb->block == ((void *)0)) {
 return (((void *)0));
    }
    tmp = (char *) mb->block;
    tmp[mb->size] = '\0';
    return (tmp);
}

variable_types:
tmp
char *

return_type: char *


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

if ( a1 )
result = *(_QWORD *)(a1 + 16);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(_QWORD *)(a1 + 16);
else
result = 0LL;
return result;
}

original_code:
void *adc_MB_Contents(adc_MB_t * mb)
{
    return (mb == ((void *)0) ? ((void *)0) : mb->block);
}

canonical_original_code:
void *adc_MB_Contents(struct adc_MB_t *mb)
{
    return (mb == ((void *)0) ? ((void *)0) : mb->block);
}

return_type: void *


decompiled_code:
void __fastcall adc_MB_Resize(size_t *a1, unsigned __int64 a2)
{
__int64 v2; // r8
const char *v3; // rdx
unsigned __int64 v4; // rax
size_t v5; // rdx
int v6; // eax
int v7; // eax
size_t v8; // rbx
void *v9; // rax
size_t v10; // r13
void *v11; // r14

v2 = 179LL;
v3 = "mb";
if ( !a1 )
{
LABEL_16:
fprintf(stderr, "Assertion failed: %s (%s: %d)\n", v3, "adcmb.c", v2);
abort();
}
v4 = a1[1];
if ( v4 >= a2 )
{
*a1 = a2;
return;
}
LODWORD(v5) = 1;
if ( v4 )
v5 = a1[1];
v6 = v5;
if ( (int)v5 <= 0x8000000 && (int)v5 < a2 )
{
do
v6 *= 2;
while ( v6 < a2 && v6 <= 0x8000000 );
}
v7 = v6 + 1;
if ( v7 > 0x8000000 )
{
v2 = 198LL;
v3 = "bytes <= MAX_BLOCK_SIZE";
goto LABEL_16;
}
v8 = v7;
v9 = calloc(v7, 1uLL);
v10 = (size_t)v9;
if ( !v9 )
{
fprintf(stderr, "FATAL ERROR: OUT OF MEMORY (%s: %d)\n", "adcmb.c", 200LL);
abort();
}
v11 = (void *)a1[2];
memcpy(v9, v11, *a1);
free(v11);
a1[2] = v10;
*a1 = a2;
a1[1] = v8;
}

canonical_decompiled_code:
void __fastcall func9(size_t *a1, unsigned __int64 a2)
{
__int64 v2; // r8
const char *v3; // rdx
unsigned __int64 v4; // rax
size_t v5; // rdx
int v6; // eax
int v7; // eax
size_t v8; // rbx
void *v9; // rax
size_t v10; // r13
void *v11; // r14

v2 = 179LL;
v3 = "mb";
if ( !a1 )
{
LABEL_16:
fprintf(stderr, "Assertion failed: %s (%s: %d)\n", v3, "adcmb.c", v2);
abort();
}
v4 = a1[1];
if ( v4 >= a2 )
{
*a1 = a2;
return;
}
LODWORD(v5) = 1;
if ( v4 )
v5 = a1[1];
v6 = v5;
if ( (int)v5 <= 0x8000000 && (int)v5 < a2 )
{
do
v6 *= 2;
while ( v6 < a2 && v6 <= 0x8000000 );
}
v7 = v6 + 1;
if ( v7 > 0x8000000 )
{
v2 = 198LL;
v3 = "bytes <= MAX_BLOCK_SIZE";
goto LABEL_16;
}
v8 = v7;
v9 = calloc(v7, 1uLL);
v10 = (size_t)v9;
if ( !v9 )
{
fprintf(stderr, "FATAL ERROR: OUT OF MEMORY (%s: %d)\n", "adcmb.c", 200LL);
abort();
}
v11 = (void *)a1[2];
memcpy(v9, v11, *a1);
free(v11);
a1[2] = v10;
*a1 = a2;
a1[1] = v8;
}

original_code:
void adc_MB_Resize(adc_MB_t * mb, size_t size)
{
    void *tmp = ((void *)0);
    int bytes;
    do { if (__builtin_expect ((!(mb)), 0)) { fprintf (stderr, "Assertion failed: %s (%s: %d)\n", "mb", "adcmb.c", 179); abort(); } } while (0);
    if (size <= mb->allocated) {
 mb->size = size;
 return;
    }
    if (mb->allocated == 0) {
 bytes = 1;
    } else {
 bytes = mb->allocated;
    }
    while (bytes < size && bytes <= 0x8000000) {
 bytes *= 2;
    }
    bytes++;
    do { if (__builtin_expect ((!(bytes <= 0x8000000)), 0)) { fprintf (stderr, "Assertion failed: %s (%s: %d)\n", "bytes <= MAX_BLOCK_SIZE", "adcmb.c", 198); abort(); } } while (0);
    do { if (__builtin_expect ((!((tmp = (void *) malloc(bytes)))), 0)) { fprintf (stderr, "FATAL ERROR: OUT OF MEMORY (%s: %d)\n", "adcmb.c", 200); abort(); } } while (0);
    memset(tmp, '\0', bytes);
    memcpy(tmp, mb->block, mb->size);
    free(mb->block);
    mb->block = tmp;
    mb->size = size;
    mb->allocated = bytes;
}

canonical_original_code:
void adc_MB_Resize(struct adc_MB_t *mb, unsigned long size)
{
    void *tmp = ((void *)0);
    int bytes;
    do { if (__builtin_expect ((!(mb)), 0)) { fprintf (stderr, "Assertion failed: %s (%s: %d)\n", "mb", "adcmb.c", 179); abort(); } } while (0);
    if (size <= mb->allocated) {
 mb->size = size;
 return;
    }
    if (mb->allocated == 0) {
 bytes = 1;
    } else {
 bytes = mb->allocated;
    }
    while (bytes < size && bytes <= 0x8000000) {
 bytes *= 2;
    }
    bytes++;
    do { if (__builtin_expect ((!(bytes <= 0x8000000)), 0)) { fprintf (stderr, "Assertion failed: %s (%s: %d)\n", "bytes <= MAX_BLOCK_SIZE", "adcmb.c", 198); abort(); } } while (0);
    do { if (__builtin_expect ((!((tmp = (void *) malloc(bytes)))), 0)) { fprintf (stderr, "FATAL ERROR: OUT OF MEMORY (%s: %d)\n", "adcmb.c", 200); abort(); } } while (0);
    memset(tmp, '\0', bytes);
    memcpy(tmp, mb->block, mb->size);
    free(mb->block);
    mb->block = tmp;
    mb->size = size;
    mb->allocated = bytes;
}

variable_types:
tmp
void *

variable_types: bytes int


decompiled_code:
void *__fastcall adc_MB_Append(size_t *a1, const void *a2, size_t a3)
{
__int64 v3; // rbp

if ( !a1 )
{
fprintf(stderr, "Assertion failed: %s (%s: %d)\n", "mb", "adcmb.c", 217LL);
abort();
}
v3 = *(int *)a1;
adc_MB_Resize(a1, v3 + a3);
return memcpy((void *)(v3 + a1[2]), a2, a3);
}

canonical_decompiled_code:
void *__fastcall func10(size_t *a1, const void *a2, size_t a3)
{
__int64 v3; // rbp

if ( !a1 )
{
fprintf(stderr, "Assertion failed: %s (%s: %d)\n", "mb", "adcmb.c", 217LL);
abort();
}
v3 = *(int *)a1;
func9(a1, v3 + a3);
return memcpy((void *)(v3 + a1[2]), a2, a3);
}

original_code:
void adc_MB_Append(adc_MB_t * mb, void *data, size_t len)
{
    int size;
    do { if (__builtin_expect ((!(mb)), 0)) { fprintf (stderr, "Assertion failed: %s (%s: %d)\n", "mb", "adcmb.c", 217); abort(); } } while (0);
    size = mb->size;
    adc_MB_Resize(mb, (size + len));
    memcpy(((unsigned char *) mb->block) + size, data, len);
}

canonical_original_code:
void adc_MB_Append(struct adc_MB_t *mb, void *data, unsigned long len)
{
    int size;
    do { if (__builtin_expect ((!(mb)), 0)) { fprintf (stderr, "Assertion failed: %s (%s: %d)\n", "mb", "adcmb.c", 217); abort(); } } while (0);
    size = mb->size;
    adc_MB_Resize(mb, (size + len));
    memcpy(((unsigned char *) mb->block) + size, data, len);
}

variable_types:
data
void *

variable_types: size int


decompiled_code:
void *__fastcall adc_MB_memcpy(__int64 a1, __int64 a2, const void *a3, size_t a4)
{
if ( a2 + a4 >= *(_QWORD *)(a1 + 8) )
{
fprintf(stderr, "Assertion failed: %s (%s: %d)\n", "(offset + len) < mb->allocated", "adcmb.c", 228LL);
abort();
}
return memcpy((void *)(*(_QWORD *)(a1 + 16) + a2), a3, a4);
}

canonical_decompiled_code:
void *__fastcall func11(__int64 a1, __int64 a2, const void *a3, size_t a4)
{
if ( a2 + a4 >= *(_QWORD *)(a1 + 8) )
{
fprintf(stderr, "Assertion failed: %s (%s: %d)\n", "(offset + len) < mb->allocated", "adcmb.c", 228LL);
abort();
}
return memcpy((void *)(*(_QWORD *)(a1 + 16) + a2), a3, a4);
}

original_code:
void adc_MB_memcpy(adc_MB_t * mb, size_t offset, void *data, size_t len)
{
    do { if (__builtin_expect ((!((offset + len) < mb->allocated)), 0)) { fprintf (stderr, "Assertion failed: %s (%s: %d)\n", "(offset + len) < mb->allocated", "adcmb.c", 228); abort(); } } while (0);
    memcpy(((unsigned char *) mb->block + offset), data, len);
}

canonical_original_code:
void adc_MB_memcpy(struct adc_MB_t *mb, unsigned long offset, void *data, unsigned long len)
{
    do { if (__builtin_expect ((!((offset + len) < mb->allocated)), 0)) { fprintf (stderr, "Assertion failed: %s (%s: %d)\n", "(offset + len) < mb->allocated", "adcmb.c", 228); abort(); } } while (0);
    memcpy(((unsigned char *) mb->block + offset), data, len);
}

variable_types:
offset
unsigned long


decompiled_code:
void *adc_MB_vsprintf(__int64 a1, const char *a2, ...)
{
int v2; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
v2 = vsprintf(*(char **)(a1 + 24), a2, arg);
return adc_MB_Append((size_t *)a1, *(const void **)(a1 + 24), v2);
}

canonical_decompiled_code:
void *func12(__int64 a1, const char *a2, ...)
{
int v2; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
v2 = vsprintf(*(char **)(a1 + 24), a2, arg);
return func10((size_t *)a1, *(const void **)(a1 + 24), v2);
}

original_code:
void adc_MB_vsprintf(adc_MB_t * mb, const char *fmt, ...)
{
    va_list args;
    int n;
    __builtin_va_start(args,fmt);
    n = vsprintf(mb->buffer, fmt, args);
    __builtin_va_end(args);
    adc_MB_Append(mb, mb->buffer, n);
}

canonical_original_code:
void adc_MB_vsprintf(struct adc_MB_t *mb, char *fmt, ...)
{
    __builtin_va_list args;
    int n;
    __builtin_va_start(args,fmt);
    n = vsprintf(mb->buffer, fmt, args);
    __builtin_va_end(args);
    adc_MB_Append(mb, mb->buffer, n);
}

variable_types:
fmt
char *

variable_types: n int


repo: brharp/lambda-calc

decompiled_code:
__int64 __fastcall get_binding(__int64 *a1, const wchar_t *a2)
{
__int64 *v2; // rbp
__int64 v3; // r12

if ( !a1 )
_assert_fail("env != 0", "env.c", 0x6Du, "get_binding");
v2 = a1;
if ( !a2 )
_assert_fail("name != 0", "env.c", 0x6Eu, "get_binding");
while ( 1 )
{
v3 = *v2;
if ( *v2 )
break;
LABEL_8:
v2 = (__int64 *)v2[1];
if ( !v2 )
return 0LL;
}
while ( wcscmp(*(const wchar_t **)v3, a2) )
{
v3 = *(_QWORD *)(v3 + 16);
if ( !v3 )
goto LABEL_8;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 *a1, const wchar_t *a2)
{
__int64 *v2; // rbp
__int64 v3; // r12

if ( !a1 )
_assert_fail("env != 0", "env.c", 0x6Du, "get_binding");
v2 = a1;
if ( !a2 )
_assert_fail("name != 0", "env.c", 0x6Eu, "get_binding");
while ( 1 )
{
v3 = *v2;
if ( *v2 )
break;
LABEL_8:
v2 = (__int64 *)v2[1];
if ( !v2 )
return 0LL;
}
while ( wcscmp(*(const wchar_t **)v3, a2) )
{
v3 = *(_QWORD *)(v3 + 16);
if ( !v3 )
goto LABEL_8;
}
return v3;
}

original_code:
static const Binding *get_binding(Env *env, const wchar_t *name)
{
 const Binding *bnd = (0);
 ((void) sizeof ((env != 0) ? 1 : 0), __extension__ ({ if (env != 0) ; else __assert_fail ("env != 0", "env.c", 109, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((name != 0) ? 1 : 0), __extension__ ({ if (name != 0) ; else __assert_fail ("name != 0", "env.c", 110, __extension__ __PRETTY_FUNCTION__); }));
 for (; env != 0; env = env->link) {
  for (bnd = env->bindings; bnd != (0); bnd = bnd->link) {
   if (wcscmp(bnd->name, name) == 0) {
    goto found;
   }
  }
 }
found:
 return bnd;
}

canonical_original_code:
static struct Binding *get_binding(struct Env *env, int *name)
{
 struct Binding *bnd = (0);
 ((void) sizeof ((env != 0) ? 1 : 0), __extension__ ({ if (env != 0) ; else __assert_fail ("env != 0", "env.c", 109, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((name != 0) ? 1 : 0), __extension__ ({ if (name != 0) ; else __assert_fail ("name != 0", "env.c", 110, __extension__ __PRETTY_FUNCTION__); }));
 for (; env != 0; env = env->link) {
  for (bnd = env->bindings; bnd != (0); bnd = bnd->link) {
   if (wcscmp(bnd->name, name) == 0) {
    goto found;
   }
  }
 }
found:
 return bnd;
}

variable_types:
env
struct Env *

variable_types:
name
int *

variable_types: struct Binding { int *name; struct Value { enum Type { T_Exp=0, T_Function=1, T_Thunk=2, T_Env=3 } type; union Object { struct Exp { enum Exp_Type { T_Exp_Symbol=0, T_Exp_Lambda=1, T_Exp_Pair=2, T_Exp_Quote=3, T_Exp_Assign=4, T_Exp_Seq=5, T_Exp_Num=6 } type; int *sval; struct Exp *child[2]; int nval; } *exp; struct Function { int *name; struct Exp *param; struct Exp *body; struct Env { struct Binding *bindings; struct Env *link; } *env; struct Value *(*apply)(struct Function *, struct Value *); } *function; struct Thunk { struct Value *value; struct Exp *exp; struct Env *env; } *thunk; struct Env *env; void *und; } data; } *value; struct Binding *link; } *

user_defined_types: struct Binding { int *name; struct Value *value; struct Binding *link; }

user_defined_types: struct Value { enum Type type; union Object data; }

user_defined_types: union Object { struct Exp *exp; struct Function *function; struct Thunk *thunk; struct Env *env; void *und; }

user_defined_types: struct Exp { enum Exp_Type type; int *sval; struct Exp *child[2]; int nval; }

user_defined_types: struct Function { int *name; struct Exp *param; struct Exp *body; struct Env *env; struct Value *(*apply)(struct Function *, struct Value *); }


bind

decompiled_code:
__int64 __fastcall bind(__int64 a1, __int64 a2, __int64 *a3)
{
if ( !a3 )
_assert_fail("env != 0", "env.c", 0xCDu, "bind");
if ( !a1 )
_assert_fail("name != 0", "env.c", 0xCEu, "bind");
if ( !a2 )
_assert_fail("value != 0", "env.c", 0xCFu, "bind");
if ( *(_DWORD *)a2 == 1 )
**(_QWORD **)(a2 + 8) = a1;
put_binding_isra_0(a3, a1, a2);
return a2;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, __int64 *a3)
{
if ( !a3 )
_assert_fail("env != 0", "env.c", 0xCDu, "bind");
if ( !a1 )
_assert_fail("name != 0", "env.c", 0xCEu, "bind");
if ( !a2 )
_assert_fail("value != 0", "env.c", 0xCFu, "bind");
if ( *(_DWORD *)a2 == 1 )
**(_QWORD **)(a2 + 8) = a1;
put_binding_isra_0(a3, a1, a2);
return a2;
}

original_code:
const Value *bind(const wchar_t *name, const Value *value, Env *env)
{
 Binding *bnd = 0;
 ((void) sizeof ((env != 0) ? 1 : 0), __extension__ ({ if (env != 0) ; else __assert_fail ("env != 0", "env.c", 205, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((name != 0) ? 1 : 0), __extension__ ({ if (name != 0) ; else __assert_fail ("name != 0", "env.c", 206, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((value != 0) ? 1 : 0), __extension__ ({ if (value != 0) ; else __assert_fail ("value != 0", "env.c", 207, __extension__ __PRETTY_FUNCTION__); }));
 if (value->type == T_Function) {
  value->data.function->name = name;
 }
 put_binding(env, name, value);
 return value;
}

canonical_original_code:
struct Value *bind(int *name, struct Value *value, struct Env *env)
{
 struct Binding *bnd = 0;
 ((void) sizeof ((env != 0) ? 1 : 0), __extension__ ({ if (env != 0) ; else __assert_fail ("env != 0", "env.c", 205, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((name != 0) ? 1 : 0), __extension__ ({ if (name != 0) ; else __assert_fail ("name != 0", "env.c", 206, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((value != 0) ? 1 : 0), __extension__ ({ if (value != 0) ; else __assert_fail ("value != 0", "env.c", 207, __extension__ __PRETTY_FUNCTION__); }));
 if (value->type == T_Function) {
  value->data.function->name = name;
 }
 put_binding(env, name, value);
 return value;
}

variable_types:
value
struct Value *

return_type: struct Value { enum Type { T_Exp=0, T_Function=1, T_Thunk=2, T_Env=3 } type; union Object { struct Exp { enum Exp_Type { T_Exp_Symbol=0, T_Exp_Lambda=1, T_Exp_Pair=2, T_Exp_Quote=3, T_Exp_Assign=4, T_Exp_Seq=5, T_Exp_Num=6 } type; int *sval; struct Exp *child[2]; int nval; } *exp; struct Function { int *name; struct Exp *param; struct Exp *body; struct Env { struct Binding { int *name; struct Value *value; struct Binding *link; } *bindings; struct Env *link; } *env; struct Value *(*apply)(struct Function *, struct Value *); } *function; struct Thunk { struct Value *value; struct Exp *exp; struct Env *env; } *thunk; struct Env *env; void *und; } data; } *

user_defined_types: struct Env { struct Binding *bindings; struct Env *link; }


lookup

decompiled_code:
__int64 __fastcall lookup(const wchar_t *a1, __int64 *a2)
{
__int64 v2; // rax
__int64 result; // rax

v2 = get_binding(a2, a1);
if ( !v2 || (result = *(_QWORD *)(v2 + 8)) == 0 )
_assert_fail("val != 0", "env.c", 0xF8u, "lookup");
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(const wchar_t *a1, __int64 *a2)
{
__int64 v2; // rax
__int64 result; // rax

v2 = func0(a2, a1);
if ( !v2 || (result = *(_QWORD *)(v2 + 8)) == 0 )
_assert_fail("val != 0", "env.c", 0xF8u, "lookup");
return result;
}

original_code:
const Value *lookup(const wchar_t * name, Env * env)
{
 const Binding *bnd = (0);
 const Value *val = 0;
 if ((bnd = get_binding(env, name)) != (0)) {
  val = bnd->value;
 }
 ((void) sizeof ((val != 0) ? 1 : 0), __extension__ ({ if (val != 0) ; else __assert_fail ("val != 0", "env.c", 248, __extension__ __PRETTY_FUNCTION__); }));
 return val;
}

canonical_original_code:
struct Value *lookup(int *name, struct Env *env)
{
 struct Binding *bnd = (0);
 struct Value *val = 0;
 if ((bnd = get_binding(env, name)) != (0)) {
  val = bnd->value;
 }
 ((void) sizeof ((val != 0) ? 1 : 0), __extension__ ({ if (val != 0) ; else __assert_fail ("val != 0", "env.c", 248, __extension__ __PRETTY_FUNCTION__); }));
 return val;
}

variable_types: struct Value { enum Type { T_Exp=0, T_Function=1, T_Thunk=2, T_Env=3 } type; union Object { struct Exp { enum Exp_Type { T_Exp_Symbol=0, T_Exp_Lambda=1, T_Exp_Pair=2, T_Exp_Quote=3, T_Exp_Assign=4, T_Exp_Seq=5, T_Exp_Num=6 } type; int *sval; struct Exp *child[2]; int nval; } *exp; struct Function { int *name; struct Exp *param; struct Exp *body; struct Env { struct Binding { int *name; struct Value *value; struct Binding *link; } *bindings; struct Env *link; } *env; struct Value *(*apply)(struct Function *, struct Value *); } *function; struct Thunk { struct Value *value; struct Exp *exp; struct Env *env; } *thunk; struct Env *env; void *und; } data; } *


decompiled_code:
_QWORD *get_global_environment()
{
_QWORD *result; // rax

result = (_QWORD *)global;
if ( !global )
{
result = make_env(0LL);
global = (__int64)result;
}
return result;
}

canonical_decompiled_code:
_QWORD *func5()
{
_QWORD *result; // rax

result = (_QWORD *)global;
if ( !global )
{
result = make_env(0LL);
global = (__int64)result;
}
return result;
}

canonical_original_code:
struct Env *get_global_environment()
{
    if (global == 0) {
 global = make_env(0);
    }
    return global;
}

return_type: struct Env { struct Binding { int *name; struct Value { enum Type { T_Exp=0, T_Function=1, T_Thunk=2, T_Env=3 } type; union Object { struct Exp { enum Exp_Type { T_Exp_Symbol=0, T_Exp_Lambda=1, T_Exp_Pair=2, T_Exp_Quote=3, T_Exp_Assign=4, T_Exp_Seq=5, T_Exp_Num=6 } type; int *sval; struct Exp *child[2]; int nval; } *exp; struct Function { int *name; struct Exp *param; struct Exp *body; struct Env *env; struct Value *(*apply)(struct Function *, struct Value *); } *function; struct Thunk { struct Value *value; struct Exp *exp; struct Env *env; } *thunk; struct Env *env; void *und; } data; } *value; struct Binding *link; } *bindings; struct Env *link; } *


decompiled_code:
__int64 __fastcall make_symbol_exp(wchar_t *s)
{
__int64 v1; // rax
__int64 v2; // r12

v1 = mymalloc(40LL);
*(_DWORD *)v1 = 0;
v2 = v1;
*(_QWORD *)(v1 + 8) = (int)wcsdup(s);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(wchar_t *s)
{
__int64 v1; // rax
__int64 v2; // r12

v1 = mymalloc(40LL);
*(_DWORD *)v1 = 0;
v2 = v1;
*(_QWORD *)(v1 + 8) = (int)wcsdup(s);
return v2;
}

original_code:
const Exp *make_symbol_exp(const wchar_t *name)
{
 Exp *exp = 0;
 exp = (Exp *)mymalloc(sizeof(*exp));
 exp->type = T_Exp_Symbol;
 exp->sval = _wcsdup(name);
 return exp;
}

canonical_original_code:
struct Exp *make_symbol_exp(int *name)
{
 struct Exp *exp = 0;
 exp = (struct Exp *)mymalloc(sizeof(*exp));
 exp->type = T_Exp_Symbol;
 exp->sval = _wcsdup(name);
 return exp;
}

variable_types: struct Exp { enum Exp_Type { T_Exp_Symbol=0, T_Exp_Lambda=1, T_Exp_Pair=2, T_Exp_Quote=3, T_Exp_Assign=4, T_Exp_Seq=5, T_Exp_Num=6 } type; int *sval; struct Exp *child[2]; int nval; } *


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

result = mymalloc(40LL);
*(_DWORD *)result = 1;
*(_QWORD *)(result + 16) = a1;
*(_QWORD *)(result + 24) = a2;
return result;
}

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

result = mymalloc(40LL);
*(_DWORD *)result = 1;
*(_QWORD *)(result + 16) = a1;
*(_QWORD *)(result + 24) = a2;
return result;
}

original_code:
const Exp *make_lambda_exp(const Exp *param, const Exp *body)
{
 Exp *exp = 0;
 exp = (Exp *)mymalloc(sizeof(*exp));
 exp->type = T_Exp_Lambda;
 exp->child[0] = param;
 exp->child[1] = body;
 return exp;
}

canonical_original_code:
struct Exp *make_lambda_exp(struct Exp *param, struct Exp *body)
{
 struct Exp *exp = 0;
 exp = (struct Exp *)mymalloc(sizeof(*exp));
 exp->type = T_Exp_Lambda;
 exp->child[0] = param;
 exp->child[1] = body;
 return exp;
}

variable_types:
param
struct Exp *

variable_types:
body
struct Exp *

return_type: struct Exp { enum Exp_Type { T_Exp_Symbol=0, T_Exp_Lambda=1, T_Exp_Pair=2, T_Exp_Quote=3, T_Exp_Assign=4, T_Exp_Seq=5, T_Exp_Num=6 } type; int *sval; struct Exp *child[2]; int nval; } *


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

result = mymalloc(40LL);
*(_DWORD *)result = 2;
*(_QWORD *)(result + 16) = a1;
*(_QWORD *)(result + 24) = a2;
return result;
}

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

result = mymalloc(40LL);
*(_DWORD *)result = 2;
*(_QWORD *)(result + 16) = a1;
*(_QWORD *)(result + 24) = a2;
return result;
}

original_code:
const Exp *make_pair_exp(const Exp *op, const Exp *operand)
{
 Exp *exp = 0;
 exp = (Exp *)mymalloc(sizeof(*exp));
 exp->type = T_Exp_Pair;
 exp->child[0] = op;
 exp->child[1] = operand;
 return exp;
}

canonical_original_code:
struct Exp *make_pair_exp(struct Exp *op, struct Exp *operand)
{
 struct Exp *exp = 0;
 exp = (struct Exp *)mymalloc(sizeof(*exp));
 exp->type = T_Exp_Pair;
 exp->child[0] = op;
 exp->child[1] = operand;
 return exp;
}

variable_types:
op
struct Exp *

variable_types:
operand
struct Exp *

user_defined_types: enum Exp_Type { T_Exp_Symbol=0, T_Exp_Lambda=1, T_Exp_Pair=2, T_Exp_Quote=3, T_Exp_Assign=4, T_Exp_Seq=5, T_Exp_Num=6 }


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

result = mymalloc(40LL);
*(_DWORD *)result = 3;
*(_QWORD *)(result + 16) = a1;
return result;
}

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

result = mymalloc(40LL);
*(_DWORD *)result = 3;
*(_QWORD *)(result + 16) = a1;
return result;
}

original_code:
const Exp *make_quote_exp(const Exp *body)
{
 Exp *exp = 0;
 exp = (Exp *) mymalloc(sizeof *exp);
 exp->type = T_Exp_Quote;
 exp->child[0] = body;
 return exp;
}

canonical_original_code:
struct Exp *make_quote_exp(struct Exp *body)
{
 struct Exp *exp = 0;
 exp = (struct Exp *) mymalloc(sizeof *exp);
 exp->type = T_Exp_Quote;
 exp->child[0] = body;
 return exp;
}


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

result = mymalloc(40LL);
*(_DWORD *)result = 4;
*(_QWORD *)(result + 16) = a1;
*(_QWORD *)(result + 24) = a2;
return result;
}

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

result = mymalloc(40LL);
*(_DWORD *)result = 4;
*(_QWORD *)(result + 16) = a1;
*(_QWORD *)(result + 24) = a2;
return result;
}

original_code:
const Exp *make_assign_exp(const Exp *key, const Exp *value)
{
 Exp *exp = 0;
 exp = (Exp *) mymalloc(sizeof(*exp));
 exp->type = T_Exp_Assign;
 exp->child[0] = key;
 exp->child[1] = value;
 return exp;
}

canonical_original_code:
struct Exp *make_assign_exp(struct Exp *key, struct Exp *value)
{
 struct Exp *exp = 0;
 exp = (struct Exp *) mymalloc(sizeof(*exp));
 exp->type = T_Exp_Assign;
 exp->child[0] = key;
 exp->child[1] = value;
 return exp;
}

variable_types:
key
struct Exp *

variable_types:
value
struct Exp *


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

result = mymalloc(40LL);
*(_DWORD *)result = 5;
*(_QWORD *)(result + 16) = a1;
*(_QWORD *)(result + 24) = a2;
return result;
}

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

result = mymalloc(40LL);
*(_DWORD *)result = 5;
*(_QWORD *)(result + 16) = a1;
*(_QWORD *)(result + 24) = a2;
return result;
}

original_code:
const Exp *make_seq_exp(const Exp *head, const Exp *tail)
{
 Exp *exp = 0;
 exp = (Exp *) mymalloc(sizeof(*exp));
 exp->type = T_Exp_Seq;
 exp->child[0] = head;
 exp->child[1] = tail;
 return exp;
}

canonical_original_code:
struct Exp *make_seq_exp(struct Exp *head, struct Exp *tail)
{
 struct Exp *exp = 0;
 exp = (struct Exp *) mymalloc(sizeof(*exp));
 exp->type = T_Exp_Seq;
 exp->child[0] = head;
 exp->child[1] = tail;
 return exp;
}

variable_types:
head
struct Exp *

variable_types:
tail
struct Exp *


mymalloc

decompiled_code:
void *__fastcall mymalloc(size_t a1)
{
void *result; // rax

if ( !a1 )
_assert_fail("sz > 0", "mystdlib.c", 0x17u, "mymalloc");
if ( a1 > 0x1FF )
_assert_fail("sz < 512", "mystdlib.c", 0x18u, "mymalloc");
result = malloc(a1);
if ( !result )
_assert_fail("ptr != 0", "mystdlib.c", 0x1Au, "mymalloc");
return result;
}

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

if ( !a1 )
_assert_fail("sz > 0", "mystdlib.c", 0x17u, "mymalloc");
if ( a1 > 0x1FF )
_assert_fail("sz < 512", "mystdlib.c", 0x18u, "mymalloc");
result = malloc(a1);
if ( !result )
_assert_fail("ptr != 0", "mystdlib.c", 0x1Au, "mymalloc");
return result;
}

original_code:
void *mymalloc(size_t sz)
{
    void *ptr;
    ((void) sizeof ((sz > 0) ? 1 : 0), __extension__ ({ if (sz > 0) ; else __assert_fail ("sz > 0", "mystdlib.c", 23, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((sz < 512) ? 1 : 0), __extension__ ({ if (sz < 512) ; else __assert_fail ("sz < 512", "mystdlib.c", 24, __extension__ __PRETTY_FUNCTION__); }));
    ptr = malloc(sz);
    ((void) sizeof ((ptr != 0) ? 1 : 0), __extension__ ({ if (ptr != 0) ; else __assert_fail ("ptr != 0", "mystdlib.c", 26, __extension__ __PRETTY_FUNCTION__); }));
    return ptr;
}

canonical_original_code:
void *mymalloc(unsigned long sz)
{
    void *ptr;
    ((void) sizeof ((sz > 0) ? 1 : 0), __extension__ ({ if (sz > 0) ; else __assert_fail ("sz > 0", "mystdlib.c", 23, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((sz < 512) ? 1 : 0), __extension__ ({ if (sz < 512) ; else __assert_fail ("sz < 512", "mystdlib.c", 24, __extension__ __PRETTY_FUNCTION__); }));
    ptr = malloc(sz);
    ((void) sizeof ((ptr != 0) ? 1 : 0), __extension__ ({ if (ptr != 0) ; else __assert_fail ("ptr != 0", "mystdlib.c", 26, __extension__ __PRETTY_FUNCTION__); }));
    return ptr;
}

variable_types:
sz
unsigned long

variable_types:
ptr
void *


pexp

decompiled_code:
wint_t __fastcall pexp(__int64 a1)
{
print_exp(a1, stderr);
return fputwc(10, stderr);
}

canonical_decompiled_code:
wint_t __fastcall func5(__int64 a1)
{
func0(a1, stderr);
return fputwc(10, stderr);
}

original_code:
void pexp(const Exp *exp) {
 print_exp(exp, stderr);
 fputwc(L'\n', stderr);
}

canonical_original_code:
void pexp(struct Exp *exp) {
 print_exp(exp, stderr);
 fputwc(L'\n', stderr);
}


handleError

repo: cohenadair/assignments

decompiled_code:
void __fastcall __noreturn handleError(const char *a1)
{
fprintf(stderr, "%s\n", a1);
exit(-1);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(const char *a1)
{
fprintf(stderr, "%s\n", a1);
exit(-1);
}

original_code:
void handleError(char *msg)
{
    fprintf(stderr, "%s\n", msg);
    exit(-1);
}

variable_types:
msg
char *


handleAccept

decompiled_code:
int __fastcall handleAccept(int fd)
{
int result; // eax
socklen_t addr_len; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

addr_len = 16;
result = accept(fd, &addr, &addr_len);
if ( result < 0 )
{
close(fd);
handleError("ERROR on accept");
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(int fd)
{
int result; // eax
socklen_t addr_len; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

addr_len = 16;
result = accept(fd, &addr, &addr_len);
if ( result < 0 )
{
close(fd);
func7("ERROR on accept");
}
return result;
}

original_code:
int handleAccept(int sockfd)
{
 int newsockfd, clilen;
 struct sockaddr_in serv_addr, cli_addr;
 clilen = sizeof(cli_addr);
 newsockfd = accept(
  sockfd,
  (struct sockaddr *)&cli_addr,
  (socklen_t *)&clilen);
 if (newsockfd < 0) {
  close(sockfd);
  handleError("ERROR on accept");
 }
 return newsockfd;
}

canonical_original_code:
int handleAccept(int sockfd)
{
 int newsockfd; int clilen;
 struct sockaddr_in serv_addr; struct sockaddr_in cli_addr;
 clilen = sizeof(cli_addr);
 newsockfd = accept(
  sockfd,
  (struct sockaddr *)&cli_addr,
  (unsigned int *)&clilen);
 if (newsockfd < 0) {
  close(sockfd);
  handleError("ERROR on accept");
 }
 return newsockfd;
}

variable_types: sockfd int

variable_types: newsockfd int

variable_types: clilen 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]; }

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]; }


handleBinding

decompiled_code:
__int64 __fastcall handleBinding(char *service)
{
int v1; // er12
struct addrinfo *v2; // rbp
int v3; // eax
struct addrinfo *pai; // [rsp+0h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+8h] [rbp-48h] BYREF

*(_QWORD *)&req.ai_flags = 0x200000001LL;
pai = 0LL;
*(_QWORD *)&req.ai_socktype = 0x600000001LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
if ( getaddrinfo(0LL, service, &req, &pai) )
handleError("ERROR in getaddrinfo()");
v2 = pai;
if ( !pai )
{
LABEL_10:
freeaddrinfo(v2);
if ( v1 >= 0 )
{
close(v1);
handleError("ERROR binding to port");
}
LABEL_11:
handleError("ERROR creating socket");
}
while ( 1 )
{
v3 = socket(v2->ai_family, v2->ai_socktype, v2->ai_protocol);
v1 = v3;
if ( v3 != -1 )
break;
LABEL_8:
v2 = v2->ai_next;
if ( !v2 )
{
v2 = pai;
goto LABEL_10;
}
}
if ( bind(v3, v2->ai_addr, v2->ai_addrlen) == -1 )
{
close(v1);
goto LABEL_8;
}
freeaddrinfo(pai);
if ( v1 < 0 )
goto LABEL_11;
return (unsigned int)v1;
}

canonical_decompiled_code:
__int64 __fastcall func10(char *service)
{
int v1; // er12
struct addrinfo *v2; // rbp
int v3; // eax
struct addrinfo *pai; // [rsp+0h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+8h] [rbp-48h] BYREF

*(_QWORD *)&req.ai_flags = 0x200000001LL;
pai = 0LL;
*(_QWORD *)&req.ai_socktype = 0x600000001LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
if ( getaddrinfo(0LL, service, &req, &pai) )
func7("ERROR in getaddrinfo()");
v2 = pai;
if ( !pai )
{
LABEL_10:
freeaddrinfo(v2);
if ( v1 >= 0 )
{
close(v1);
func7("ERROR binding to port");
}
LABEL_11:
func7("ERROR creating socket");
}
while ( 1 )
{
v3 = socket(v2->ai_family, v2->ai_socktype, v2->ai_protocol);
v1 = v3;
if ( v3 != -1 )
break;
LABEL_8:
v2 = v2->ai_next;
if ( !v2 )
{
v2 = pai;
goto LABEL_10;
}
}
if ( bind(v3, v2->ai_addr, v2->ai_addrlen) == -1 )
{
close(v1);
goto LABEL_8;
}
freeaddrinfo(pai);
if ( v1 < 0 )
goto LABEL_11;
return (unsigned int)v1;
}

original_code:
int handleBinding(char *portno)
{
 int sockfd;
 struct addrinfo *result = ((void *)0);
 struct addrinfo *p = ((void *)0);
 struct addrinfo hints;
 memset(&hints, 0, sizeof(struct addrinfo));
 hints.ai_flags = 0x0001;
 hints.ai_family = 2;
 hints.ai_socktype = SOCK_STREAM;
 hints.ai_protocol = IPPROTO_TCP;
 if (getaddrinfo(((void *)0), portno, &hints, &result) != 0)
  handleError("ERROR in getaddrinfo()");
 for (p = result; p != ((void *)0); p = p->ai_next) {
  sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol);
  if (sockfd == -1)
   continue;
  if (bind(sockfd, p->ai_addr, p->ai_addrlen) == -1) {
   close(sockfd);
   continue;
  }
  break;
 }
 freeaddrinfo(result);
 if (sockfd < 0)
  handleError("ERROR creating socket");
 if (p == ((void *)0)) {
  close(sockfd);
  handleError("ERROR binding to port");
 }
 return sockfd;
}

variable_types:
portno
char *

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

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


handleFortuneRequest

decompiled_code:
__int64 __fastcall handleFortuneRequest(int fd)
{
int v1; // eax
ssize_t v2; // r8
__int64 result; // rax
char buf; // [rsp+Eh] [rbp-Ah] BYREF
char v5[9]; // [rsp+Fh] [rbp-9h] BYREF

buf = 1;
v5[0] = strlen((&fortunes)[fortuneIndex_0 % 3]);
if ( write(fd, &buf, 1uLL) == -1 )
{
perror("Error writing FORTUNE_REPLY");
result = 1LL;
}
else
{
v5[0] = strlen((&fortunes)[fortuneIndex_0 % 3]);
if ( write(fd, v5, 1uLL) == -1 )
{
perror("Error Writing count");
result = 1LL;
}
else
{
v1 = fortuneIndex_0++;
v2 = write(fd, (&fortunes)[v1 % 3], (unsigned __int8)v5[0]);
result = 0LL;
if ( v2 == -1 )
{
perror("Error Writing Fortune");
result = 1LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(int fd)
{
int v1; // eax
ssize_t v2; // r8
__int64 result; // rax
char buf; // [rsp+Eh] [rbp-Ah] BYREF
char v5[9]; // [rsp+Fh] [rbp-9h] BYREF

buf = 1;
v5[0] = strlen((&fortunes)[fortuneIndex_0 % 3]);
if ( write(fd, &buf, 1uLL) == -1 )
{
perror("Error writing FORTUNE_REPLY");
result = 1LL;
}
else
{
v5[0] = strlen((&fortunes)[fortuneIndex_0 % 3]);
if ( write(fd, v5, 1uLL) == -1 )
{
perror("Error Writing count");
result = 1LL;
}
else
{
v1 = fortuneIndex_0++;
v2 = write(fd, (&fortunes)[v1 % 3], (unsigned __int8)v5[0]);
result = 0LL;
if ( v2 == -1 )
{
perror("Error Writing Fortune");
result = 1LL;
}
}
}
return result;
}

original_code:
int handleFortuneRequest(int sockfd)
{
 static int fortuneIndex = 0;
 uint8_t fortuneReply = 1;
 uint8_t count = (uint8_t)strlen(fortunes[fortuneIndex % 3]);
 if (write(sockfd, &fortuneReply, sizeof(uint8_t)) == -1) {
  perror("Error writing FORTUNE_REPLY");
  return 1;
 }
 count = strlen(fortunes[fortuneIndex % 3]);
 if (write(sockfd, &count, sizeof(uint8_t)) == -1) {
  perror("Error Writing count");
  return 1;
 }
 if (write(sockfd, fortunes[fortuneIndex++ % 3], count) == -1) {
  perror("Error Writing Fortune");
  return 1;
 }
 return 0;
}

canonical_original_code:
int handleFortuneRequest(int sockfd)
{
 static int fortuneIndex = 0;
 unsigned char fortuneReply = 1;
 unsigned char count = (uint8_t)strlen(fortunes[fortuneIndex % 3]);
 if (write(sockfd, &fortuneReply, sizeof(unsigned char)) == -1) {
  perror("Error writing FORTUNE_REPLY");
  return 1;
 }
 count = strlen(fortunes[fortuneIndex % 3]);
 if (write(sockfd, &count, sizeof(unsigned char)) == -1) {
  perror("Error Writing count");
  return 1;
 }
 if (write(sockfd, fortunes[fortuneIndex++ % 3], count) == -1) {
  perror("Error Writing Fortune");
  return 1;
 }
 return 0;
}

variable_types: fortuneIndex int

variable_types:
fortuneReply
unsigned char

variable_types:
count
unsigned char


handleFortuneQuit

decompiled_code:
__int64 __fastcall handleFortuneQuit(int a1)
{
close(a1);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1)
{
close(a1);
return 1LL;
}

original_code:
int handleFortuneQuit(int sockfd)
{
 close(sockfd);
 return 1;
}


handleFortuneServerProtocol

decompiled_code:
void __fastcall handleFortuneServerProtocol(int fd)
{
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

state_1 = 0;
while ( read(fd, buf, 1uLL) != -1 )
{
if ( buf[0] == 2 )
{
state_1 = handleFortuneQuit(fd);
if ( state_1 == 1 )
return;
}
else
{
if ( buf[0] == 3 )
{
close(fd);
handleError("Killed by client.");
}
if ( buf[0] )
{
close(fd);
handleError("ERROR during protocol");
}
state_1 = handleFortuneRequest(fd);
if ( state_1 == 1 )
return;
}
}
perror("Error reading socket");
}

canonical_decompiled_code:
void __fastcall func13(int fd)
{
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

state_1 = 0;
while ( read(fd, buf, 1uLL) != -1 )
{
if ( buf[0] == 2 )
{
state_1 = func12(fd);
if ( state_1 == 1 )
return;
}
else
{
if ( buf[0] == 3 )
{
close(fd);
func7("Killed by client.");
}
if ( buf[0] )
{
close(fd);
func7("ERROR during protocol");
}
state_1 = func11(fd);
if ( state_1 == 1 )
return;
}
}
perror("Error reading socket");
}

original_code:
void handleFortuneServerProtocol(int sockfd)
{
 static int state;
 uint8_t pduId;
 state = 0;
 while (state != 1) {
  if (read(sockfd, &pduId, sizeof(uint8_t)) == -1) {
   perror("Error reading socket");
   break;
  }
  switch( pduId ){
  case 0:
   state = handleFortuneRequest(sockfd);
   break;
  case 2:
   state = handleFortuneQuit(sockfd);
   break;
  case 3:
   close(sockfd);
   handleError("Killed by client.");
   break;
  default:
   close(sockfd);
   handleError("ERROR during protocol");
   break;
  }
 }
}

canonical_original_code:
void handleFortuneServerProtocol(int sockfd)
{
 static int state;
 unsigned char pduId;
 state = 0;
 while (state != 1) {
  if (read(sockfd, &pduId, sizeof(unsigned char)) == -1) {
   perror("Error reading socket");
   break;
  }
  switch( pduId ){
  case 0:
   state = handleFortuneRequest(sockfd);
   break;
  case 2:
   state = handleFortuneQuit(sockfd);
   break;
  case 3:
   close(sockfd);
   handleError("Killed by client.");
   break;
  default:
   close(sockfd);
   handleError("ERROR during protocol");
   break;
  }
 }
}

variable_types: state int

variable_types:
pduId
unsigned char


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

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

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

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

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

variable_types: s int


UnixServeTCPSocket

decompiled_code:
__int64 __fastcall UnixServeTCPSocket(__int64 a1, __int16 a2)
{
__int64 v2; // r12
socklen_t v3; // edx
int v4; // er8

v2 = (*(&socketFactory + 3))();
if ( !v2 )
return v2;
*(_DWORD *)(v2 + 64) = socket(2, 1, 0);
*(_OWORD *)(v2 + 48) = 0LL;
*(_WORD *)(v2 + 48) = 2;
*(_WORD *)(v2 + 50) = _bswap_16(a2);
if ( bind(v4, (const struct sockaddr *)(v2 + 48), v3) < 0 )
(*(void (__fastcall **)(__int64, const char *))(v2 + 32))(v2, "ERROR on binding");
if ( listen(*(_DWORD *)(v2 + 64), 5) >= 0 )
return v2;
(*(void (__fastcall **)(__int64, const char *))(v2 + 32))(v2, "ERROR on listen");
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int16 a2)
{
__int64 v2; // r12
socklen_t v3; // edx
int v4; // er8

v2 = (*(&socketFactory + 3))();
if ( !v2 )
return v2;
*(_DWORD *)(v2 + 64) = socket(2, 1, 0);
*(_OWORD *)(v2 + 48) = 0LL;
*(_WORD *)(v2 + 48) = 2;
*(_WORD *)(v2 + 50) = func3(a2);
if ( bind(v4, (const struct sockaddr *)(v2 + 48), v3) < 0 )
(*(void (__fastcall **)(__int64, const char *))(v2 + 32))(v2, "ERROR on binding");
if ( listen(*(_DWORD *)(v2 + 64), 5) >= 0 )
return v2;
(*(void (__fastcall **)(__int64, const char *))(v2 + 32))(v2, "ERROR on listen");
return v2;
}

original_code:
nmu_socket_t UnixServeTCPSocket(char *hostname, short port)
{
 nmu_socket_t pSocket = socketFactory.new();
 if(pSocket == ((void *)0))
  return ((void *)0);
 pSocket->sockfd = socket(2, SOCK_STREAM, 0);
 memset((char *) &pSocket->sockAddr, 0, sizeof(SocketAddress));
 pSocket->sockAddr.sin_family = 2;
 pSocket->sockAddr.sin_addr.s_addr = ((in_addr_t) 0x00000000);
 pSocket->sockAddr.sin_port = htons(port);
 if( bind(pSocket->sockfd, (struct sockaddr *) &pSocket->sockAddr, sizeof(SocketAddress)) < 0)
  pSocket->error(pSocket, "ERROR on binding");
 if(listen(pSocket->sockfd,5) < 0)
  pSocket->error( pSocket, "ERROR on listen" );;
 return pSocket;
}

canonical_original_code:
struct NMUSocket *UnixServeTCPSocket(char *hostname, short port)
{
 struct NMUSocket *pSocket = socketFactory.new();
 if(pSocket == ((void *)0))
  return ((void *)0);
 pSocket->sockfd = socket(2, SOCK_STREAM, 0);
 memset((char *) &pSocket->sockAddr, 0, sizeof(SocketAddress));
 pSocket->sockAddr.sin_family = 2;
 pSocket->sockAddr.sin_addr.s_addr = ((unsigned int) 0x00000000);
 pSocket->sockAddr.sin_port = htons(port);
 if( bind(pSocket->sockfd, (struct sockaddr *) &pSocket->sockAddr, sizeof(SocketAddress)) < 0)
  pSocket->error(pSocket, "ERROR on binding");
 if(listen(pSocket->sockfd,5) < 0)
  pSocket->error( pSocket, "ERROR on listen" );;
 return pSocket;
}

variable_types:
hostname
char *

variable_types: port short

variable_types: struct NMUSocket { struct NMUSocket *(*accept)(struct NMUSocket *); int (*read)(struct NMUSocket *, void *, int); int (*write)(struct NMUSocket *, void *, int); void (*close)(struct NMUSocket *); void (*error)(struct NMUSocket *, char *); void (*acceptAndForkService)(struct NMUSocket *, void (*)(struct NMUSocket *)); 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]; } sockAddr; int sockfd; } *

user_defined_types: struct NMUSocket { struct NMUSocket *(*accept)(struct NMUSocket *); int (*read)(struct NMUSocket *, void *, int); int (*write)(struct NMUSocket *, void *, int); void (*close)(struct NMUSocket *); void (*error)(struct NMUSocket *, char *); void (*acceptAndForkService)(struct NMUSocket *, void (*)(struct NMUSocket *)); struct sockaddr_in sockAddr; int sockfd; }


UnixConnectTCPSocket

decompiled_code:
__int64 __fastcall UnixConnectTCPSocket(char *name, char *service)
{
__int64 v2; // r12
struct addrinfo *v3; // rbp
int v4; // eax
struct addrinfo *pai; // [rsp+8h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-48h] BYREF

v2 = (*(&socketFactory + 3))();
*(_QWORD *)&req.ai_flags = 0LL;
pai = 0LL;
*(_QWORD *)&req.ai_socktype = 0x600000001LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
if ( getaddrinfo(name, service, &req, &pai) )
{
fwrite("getaddrinfo() failed\n", 1uLL, 0x15uLL, stderr);
exit(-1);
}
v3 = pai;
if ( pai )
{
do
{
v4 = socket(v3->ai_family, v3->ai_socktype, v3->ai_protocol);
*(_DWORD *)(v2 + 64) = v4;
if ( v4 != -1 )
{
if ( connect(v4, v3->ai_addr, v3->ai_addrlen) != -1 )
break;
close(*(_DWORD *)(v2 + 64));
*(_DWORD *)(v2 + 64) = -1;
}
v3 = v3->ai_next;
}
while ( v3 );
v3 = pai;
}
freeaddrinfo(v3);
if ( *(_DWORD *)(v2 + 64) == -1 )
{
fwrite("Error: Unable to connect to server.\n", 1uLL, 0x24uLL, stderr);
exit(-1);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *name, char *service)
{
__int64 v2; // r12
struct addrinfo *v3; // rbp
int v4; // eax
struct addrinfo *pai; // [rsp+8h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-48h] BYREF

v2 = (*(&socketFactory + 3))();
*(_QWORD *)&req.ai_flags = 0LL;
pai = 0LL;
*(_QWORD *)&req.ai_socktype = 0x600000001LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
if ( getaddrinfo(name, service, &req, &pai) )
{
fwrite("getaddrinfo() failed\n", 1uLL, 0x15uLL, stderr);
exit(-1);
}
v3 = pai;
if ( pai )
{
do
{
v4 = socket(v3->ai_family, v3->ai_socktype, v3->ai_protocol);
*(_DWORD *)(v2 + 64) = v4;
if ( v4 != -1 )
{
if ( connect(v4, v3->ai_addr, v3->ai_addrlen) != -1 )
break;
close(*(_DWORD *)(v2 + 64));
*(_DWORD *)(v2 + 64) = -1;
}
v3 = v3->ai_next;
}
while ( v3 );
v3 = pai;
}
freeaddrinfo(v3);
if ( *(_DWORD *)(v2 + 64) == -1 )
{
fwrite("Error: Unable to connect to server.\n", 1uLL, 0x24uLL, stderr);
exit(-1);
}
return v2;
}

original_code:
nmu_socket_t UnixConnectTCPSocket(char *hostname, char *port)
{
 nmu_socket_t pSocket = socketFactory.new();
 struct addrinfo *result = ((void *)0);
 struct addrinfo *next = ((void *)0);
 struct addrinfo hints;
 int returnValue;
 memset(&hints, 0, sizeof(struct addrinfo));
 hints.ai_family = 0;
 hints.ai_socktype = SOCK_STREAM;
 hints.ai_protocol = IPPROTO_TCP;
 returnValue = getaddrinfo(hostname, port, &hints, &result);
 if(returnValue != 0){
  fprintf(stderr, "getaddrinfo() failed\n");
  exit(-1);
 }
 for(next = result; next != ((void *)0); next = next->ai_next){
  pSocket->sockfd = socket(next->ai_family, next->ai_socktype, next->ai_protocol);
  if( pSocket->sockfd == -1 )
   continue;
  if(connect(pSocket->sockfd, next->ai_addr, next->ai_addrlen) == -1){
   close(pSocket->sockfd);
   pSocket->sockfd = -1;
   continue;
  }
  break;
 }
 freeaddrinfo(result);
 if( pSocket->sockfd == -1 ){
  fprintf(stderr, "Error: Unable to connect to server.\n");
  exit(-1);
 }
 return pSocket;
}

canonical_original_code:
struct NMUSocket *UnixConnectTCPSocket(char *hostname, char *port)
{
 struct NMUSocket *pSocket = socketFactory.new();
 struct addrinfo *result = ((void *)0);
 struct addrinfo *next = ((void *)0);
 struct addrinfo hints;
 int returnValue;
 memset(&hints, 0, sizeof(struct addrinfo));
 hints.ai_family = 0;
 hints.ai_socktype = SOCK_STREAM;
 hints.ai_protocol = IPPROTO_TCP;
 returnValue = getaddrinfo(hostname, port, &hints, &result);
 if(returnValue != 0){
  fprintf(stderr, "getaddrinfo() failed\n");
  exit(-1);
 }
 for(next = result; next != ((void *)0); next = next->ai_next){
  pSocket->sockfd = socket(next->ai_family, next->ai_socktype, next->ai_protocol);
  if( pSocket->sockfd == -1 )
   continue;
  if(connect(pSocket->sockfd, next->ai_addr, next->ai_addrlen) == -1){
   close(pSocket->sockfd);
   pSocket->sockfd = -1;
   continue;
  }
  break;
 }
 freeaddrinfo(result);
 if( pSocket->sockfd == -1 ){
  fprintf(stderr, "Error: Unable to connect to server.\n");
  exit(-1);
 }
 return pSocket;
}

variable_types:
port
char *

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

variable_types: returnValue int

return_type: struct NMUSocket { struct NMUSocket *(*accept)(struct NMUSocket *); int (*read)(struct NMUSocket *, void *, int); int (*write)(struct NMUSocket *, void *, int); void (*close)(struct NMUSocket *); void (*error)(struct NMUSocket *, char *); void (*acceptAndForkService)(struct NMUSocket *, void (*)(struct NMUSocket *)); 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]; } sockAddr; int sockfd; } *


Unixaccept

decompiled_code:
__int64 __fastcall Unixaccept(__int64 a1)
{
__int64 v1; // r12
int v2; // ebx
socklen_t addr_len[7]; // [rsp+Ch] [rbp-1Ch] BYREF

addr_len[0] = 16;
v1 = (*(&socketFactory + 3))();
v2 = accept(*(_DWORD *)(a1 + 64), (struct sockaddr *)(v1 + 48), addr_len);
if ( v2 < 0 )
{
free((void *)v1);
(*(void (__fastcall **)(__int64, const char *))(a1 + 32))(a1, "ERROR on accept");
}
*(_DWORD *)(v1 + 64) = v2;
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 v1; // r12
int v2; // ebx
socklen_t addr_len[7]; // [rsp+Ch] [rbp-1Ch] BYREF

addr_len[0] = 16;
v1 = (*(&socketFactory + 3))();
v2 = accept(*(_DWORD *)(a1 + 64), (struct sockaddr *)(v1 + 48), addr_len);
if ( v2 < 0 )
{
free((void *)v1);
(*(void (__fastcall **)(__int64, const char *))(a1 + 32))(a1, "ERROR on accept");
}
*(_DWORD *)(v1 + 64) = v2;
return v1;
}

original_code:
nmu_socket_t Unixaccept(nmu_socket_t pSocket)
{
 socklen_t sockAddrLength = sizeof(SocketAddress);
 nmu_socket_t pClientSocket = socketFactory.new();
 int newsockfd =
  accept(pSocket->sockfd, (struct sockaddr *)&(pClientSocket->sockAddr), &sockAddrLength);
 if (newsockfd < 0){
  free(pClientSocket);
  pSocket->error(pSocket, "ERROR on accept");
 }
 pClientSocket->sockfd = newsockfd;
 return pClientSocket;
}

canonical_original_code:
struct NMUSocket *Unixaccept(struct NMUSocket *pSocket)
{
 unsigned int sockAddrLength = sizeof(SocketAddress);
 struct NMUSocket *pClientSocket = socketFactory.new();
 int newsockfd = accept(pSocket->sockfd, (struct sockaddr *)&(pClientSocket->sockAddr), &sockAddrLength);
 if (newsockfd < 0){
  free(pClientSocket);
  pSocket->error(pSocket, "ERROR on accept");
 }
 pClientSocket->sockfd = newsockfd;
 return pClientSocket;
}

variable_types:
pSocket
struct NMUSocket *

variable_types:
sockAddrLength
unsigned int

variable_types: newsockfd int


Unixclose

decompiled_code:
void __fastcall Unixclose(void *ptr)
{
close(*((_DWORD *)ptr + 16));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
close(*((_DWORD *)ptr + 16));
free(ptr);
}

original_code:
void Unixclose(nmu_socket_t pSocket)
{
 close(pSocket->sockfd);
 free(pSocket);
}

canonical_original_code:
void Unixclose(struct NMUSocket *pSocket)
{
 close(pSocket->sockfd);
 free(pSocket);
}


Unixerror

decompiled_code:
void __fastcall __noreturn Unixerror(__int64 a1, const char *a2)
{
perror(a2);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func10(__int64 a1, const char *a2)
{
perror(a2);
exit(1);
}

original_code:
void Unixerror(nmu_socket_t pSocket, char *msg)
{
    perror(msg);
    exit(1);
}

canonical_original_code:
void Unixerror(struct NMUSocket *pSocket, char *msg)
{
    perror(msg);
    exit(1);
}

variable_types:
msg
char *


UnixAcceptAndForkService

decompiled_code:
__int64 __fastcall UnixAcceptAndForkService(__int64 a1, void (__fastcall *a2)(__int64))
{
__int64 v2; // rbp
__pid_t v3; // eax

v2 = (*(__int64 (**)(void))a1)();
v3 = fork();
if ( v3 < 0 )
{
fwrite("Could not fork protocol handler.\n", 1uLL, 0x21uLL, stderr);
(*(void (__fastcall **)(__int64))(v2 + 24))(v2);
}
else if ( !v3 )
{
(*(void (__fastcall **)(__int64))(a1 + 24))(a1);
a2(v2);
exit(0);
}
return (*(__int64 (__fastcall **)(__int64))(v2 + 24))(v2);
}

original_code:
void UnixAcceptAndForkService(nmu_socket_t pServerSocket, pFunVS protocol) {
 pid_t childPid;
 nmu_socket_t serviceSocket;
 serviceSocket = pServerSocket->accept(pServerSocket);
 childPid = fork();
 if(childPid < 0){
  fprintf( stderr, "Could not fork protocol handler.\n" );
  serviceSocket->close(serviceSocket);
 }
 if(childPid){
  serviceSocket->close(serviceSocket);
 }
 else {
  pServerSocket->close(pServerSocket);
  protocol(serviceSocket);
  exit(0);
 }
}

canonical_original_code:
void UnixAcceptAndForkService(struct NMUSocket *pServerSocket, void (*protocol)(struct NMUSocket *)) {
 int childPid;
 struct NMUSocket *serviceSocket;
 serviceSocket = pServerSocket->accept(pServerSocket);
 childPid = fork();
 if(childPid < 0){
  fprintf( stderr, "Could not fork protocol handler.\n" );
  serviceSocket->close(serviceSocket);
 }
 if(childPid){
  serviceSocket->close(serviceSocket);
 }
 else {
  pServerSocket->close(pServerSocket);
  protocol(serviceSocket);
  exit(0);
 }
}

variable_types:
protocol
void (*)(struct NMUSocket *)

variable_types: childPid int


Unixconnect

decompiled_code:
bool __fastcall Unixconnect(__int64 a1)
{
return connect(*(_DWORD *)(a1 + 64), (const struct sockaddr *)(a1 + 48), 0x10u) == 0;
}

canonical_decompiled_code:
bool __fastcall func12(__int64 a1)
{
return connect(*(_DWORD *)(a1 + 64), (const struct sockaddr *)(a1 + 48), 0x10u) == 0;
}

original_code:
_Bool Unixconnect(nmu_socket_t pSocket)
{
    return connect(
  pSocket->sockfd,
  (struct sockaddr *)&pSocket->sockAddr,
  sizeof(SocketAddress)) == 0;
}

canonical_original_code:
_Bool Unixconnect(struct NMUSocket *pSocket)
{
    return connect(
  pSocket->sockfd,
  (struct sockaddr *)&pSocket->sockAddr,
  sizeof(SocketAddress)) == 0;
}


UnixServeTCPSocket

decompiled_code:
__int64 __fastcall UnixServeTCPSocket(__int64 a1, __int16 a2)
{
__int64 v2; // r12
socklen_t v3; // edx
int v4; // er8

v2 = (*(&socketFactory + 3))();
if ( !v2 )
return v2;
*(_DWORD *)(v2 + 64) = socket(2, 1, 0);
*(_OWORD *)(v2 + 48) = 0LL;
*(_WORD *)(v2 + 48) = 2;
*(_WORD *)(v2 + 50) = _bswap_16(a2);
if ( bind(v4, (const struct sockaddr *)(v2 + 48), v3) < 0 )
(*(void (__fastcall **)(__int64, const char *))(v2 + 40))(v2, "ERROR on binding");
if ( listen(*(_DWORD *)(v2 + 64), 5) >= 0 )
return v2;
(*(void (__fastcall **)(__int64, const char *))(v2 + 40))(v2, "ERROR on listen");
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int16 a2)
{
__int64 v2; // r12
socklen_t v3; // edx
int v4; // er8

v2 = (*(&socketFactory + 3))();
if ( !v2 )
return v2;
*(_DWORD *)(v2 + 64) = socket(2, 1, 0);
*(_OWORD *)(v2 + 48) = 0LL;
*(_WORD *)(v2 + 48) = 2;
*(_WORD *)(v2 + 50) = func2(a2);
if ( bind(v4, (const struct sockaddr *)(v2 + 48), v3) < 0 )
(*(void (__fastcall **)(__int64, const char *))(v2 + 40))(v2, "ERROR on binding");
if ( listen(*(_DWORD *)(v2 + 64), 5) >= 0 )
return v2;
(*(void (__fastcall **)(__int64, const char *))(v2 + 40))(v2, "ERROR on listen");
return v2;
}


UnixConnectTCPSocket

canonical_decompiled_code:
__int64 __fastcall func4(char *name, char *service)
{
__int64 v2; // r12
struct addrinfo *v3; // rbp
int v4; // eax
struct addrinfo *pai; // [rsp+8h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-48h] BYREF

v2 = (*(&socketFactory + 3))();
*(_QWORD *)&req.ai_flags = 0LL;
pai = 0LL;
*(_QWORD *)&req.ai_socktype = 0x600000001LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
if ( getaddrinfo(name, service, &req, &pai) )
{
fwrite("getaddrinfo() failed\n", 1uLL, 0x15uLL, stderr);
exit(-1);
}
v3 = pai;
if ( pai )
{
do
{
v4 = socket(v3->ai_family, v3->ai_socktype, v3->ai_protocol);
*(_DWORD *)(v2 + 64) = v4;
if ( v4 != -1 )
{
if ( connect(v4, v3->ai_addr, v3->ai_addrlen) != -1 )
break;
close(*(_DWORD *)(v2 + 64));
*(_DWORD *)(v2 + 64) = -1;
}
v3 = v3->ai_next;
}
while ( v3 );
v3 = pai;
}
freeaddrinfo(v3);
if ( *(_DWORD *)(v2 + 64) == -1 )
{
fwrite("Error: Unable to connect to server.\n", 1uLL, 0x24uLL, stderr);
exit(-1);
}
return v2;
}

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


Unixaccept

decompiled_code:
__int64 __fastcall Unixaccept(__int64 a1)
{
__int64 v1; // r12
int v2; // ebx
socklen_t addr_len[7]; // [rsp+Ch] [rbp-1Ch] BYREF

addr_len[0] = 16;
v1 = (*(&socketFactory + 3))();
v2 = accept(*(_DWORD *)(a1 + 64), (struct sockaddr *)(v1 + 48), addr_len);
if ( v2 < 0 )
{
free((void *)v1);
(*(void (__fastcall **)(__int64, const char *))(a1 + 40))(a1, "ERROR on accept");
}
*(_DWORD *)(v1 + 64) = v2;
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 v1; // r12
int v2; // ebx
socklen_t addr_len[7]; // [rsp+Ch] [rbp-1Ch] BYREF

addr_len[0] = 16;
v1 = (*(&socketFactory + 3))();
v2 = accept(*(_DWORD *)(a1 + 64), (struct sockaddr *)(v1 + 48), addr_len);
if ( v2 < 0 )
{
free((void *)v1);
(*(void (__fastcall **)(__int64, const char *))(a1 + 40))(a1, "ERROR on accept");
}
*(_DWORD *)(v1 + 64) = v2;
return v1;
}


Unixclose

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
close(*((_DWORD *)ptr + 16));
free(ptr);
}


UnixAcceptAndServe

decompiled_code:
int __fastcall UnixAcceptAndServe(__int64 (**a1)(void), void *(*a2)(void *))
{
_QWORD *v2; // rax
_QWORD *v3; // rbx
int result; // eax
pthread_t newthread[4]; // [rsp+8h] [rbp-20h] BYREF

v2 = (_QWORD *)(*a1)();
v2[5] = &pthreadError;
v3 = v2;
result = pthread_create(newthread, 0LL, a2, v2);
if ( result )
{
fwrite("Failed to thread protocol handler.\n", 1uLL, 0x23uLL, stderr);
result = ((__int64 (__fastcall *)(_QWORD *))v3[4])(v3);
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(__int64 (**a1)(void), void *(*a2)(void *))
{
_QWORD *v2; // rax
_QWORD *v3; // rbx
int result; // eax
pthread_t newthread[4]; // [rsp+8h] [rbp-20h] BYREF

v2 = (_QWORD *)(*a1)();
v2[5] = &pthreadError;
v3 = v2;
result = pthread_create(newthread, 0LL, a2, v2);
if ( result )
{
fwrite("Failed to thread protocol handler.\n", 1uLL, 0x23uLL, stderr);
result = ((__int64 (__fastcall *)(_QWORD *))v3[4])(v3);
}
return result;
}

original_code:
void UnixAcceptAndServe(nmu_socket_t serveSocket, pFunPVS protocolHandler)
{
 nmu_socket_t serviceSocket;
 serviceSocket = serveSocket->accept(serveSocket);
 int result = 0;
 pthread_t pThreadId;
 serviceSocket->error = pthreadError;
 result = pthread_create(&pThreadId, ((void *)0), (pFunThread)protocolHandler, serviceSocket);
 if (result != 0) {
  fprintf(stderr, "Failed to thread protocol handler.\n");
  serviceSocket->close(serviceSocket);
 }
}

canonical_original_code:
void UnixAcceptAndServe(struct NMUSocket *serveSocket, void *(*protocolHandler)(struct NMUSocket *))
{
 struct NMUSocket *serviceSocket;
 serviceSocket = serveSocket->accept(serveSocket);
 int result = 0;
 unsigned long pThreadId;
 serviceSocket->error = pthreadError;
 result = pthread_create(&pThreadId, ((void *)0), (void *(*)(void *))protocolHandler, serviceSocket);
 if (result != 0) {
  fprintf(stderr, "Failed to thread protocol handler.\n");
  serviceSocket->close(serviceSocket);
 }
}

variable_types: struct NMUSocket { struct NMUSocket *(*accept)(struct NMUSocket *); void (*acceptAndServe)(struct NMUSocket *, void *(*)(struct NMUSocket *)); int (*read)(struct NMUSocket *, void *, int); int (*write)(struct NMUSocket *, void *, int); void (*close)(struct NMUSocket *); void (*error)(struct NMUSocket *, char *); 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]; } sockAddr; int sockfd; } *

variable_types:
protocolHandler
void *(*)(struct NMUSocket *)

variable_types: result int

variable_types:
pThreadId
unsigned long

user_defined_types: struct NMUSocket { struct NMUSocket *(*accept)(struct NMUSocket *); void (*acceptAndServe)(struct NMUSocket *, void *(*)(struct NMUSocket *)); int (*read)(struct NMUSocket *, void *, int); int (*write)(struct NMUSocket *, void *, int); void (*close)(struct NMUSocket *); void (*error)(struct NMUSocket *, char *); struct sockaddr_in sockAddr; int sockfd; }


pthreadError

decompiled_code:
void __fastcall __noreturn pthreadError(__int64 a1, const char *a2)
{
perror(a2);
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func11(__int64 a1, const char *a2)
{
perror(a2);
pthread_exit(0LL);
}

original_code:
void pthreadError(nmu_socket_t pSocket, char *msg) {
 perror(msg);
 pthread_exit(((void *)0));
}

canonical_original_code:
void pthreadError(struct NMUSocket *pSocket, char *msg) {
 perror(msg);
 pthread_exit(((void *)0));
}


UnixServeTCPSocket

decompiled_code:
__int64 __fastcall UnixServeTCPSocket(__int64 a1, __int16 a2)
{
__int64 v2; // r12
socklen_t v3; // edx
int v4; // er8

v2 = off_4040F8();
if ( !v2 )
return v2;
*(_DWORD *)(v2 + 56) = socket(2, 1, 0);
*(_OWORD *)(v2 + 40) = 0LL;
*(_WORD *)(v2 + 40) = 2;
*(_WORD *)(v2 + 42) = _bswap_16(a2);
if ( bind(v4, (const struct sockaddr *)(v2 + 40), v3) < 0 )
(*(void (__fastcall **)(__int64, const char *))(v2 + 32))(v2, "ERROR on binding");
if ( listen(*(_DWORD *)(v2 + 56), 5) >= 0 )
return v2;
(*(void (__fastcall **)(__int64, const char *))(v2 + 32))(v2, "ERROR on listen");
return v2;
}

variable_types:
hostname
char *