decompiled_code:
void __fastcall oss_mixer_destroy(void *ptr)
{
int *v1; // r12

v1 = (int *)*((_QWORD *)ptr + 23);
if ( v1 )
{
if ( *v1 >= 0 )
close(*v1);
free(v1);
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
int *v1; // r12

v1 = (int *)*((_QWORD *)ptr + 23);
if ( v1 )
{
if ( *v1 >= 0 )
close(*v1);
free(v1);
}
free(ptr);
}

original_code:
static void oss_mixer_destroy(struct sysdep_mixer_struct *mixer)
{
   struct oss_mixer_priv_data *priv = mixer->_priv;
   if(priv)
   {
      if(priv->fd >= 0)
         close(priv->fd);
      free(priv);
   }
   free(mixer);
}


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

crtc_param_num = 0;
crtc_command = a1 >> 5;
result = a1 >> 5;
switch ( (char)result )
{
case 0:
crtc_status &= 0xE9u;
crtc_active = 0;
text_display = 0;
screen_update_force = 1;
return result;
case 1:
crtc_active = 1;
crtc_reverse_display = a1 & 1;
result = crtc_status & 0xF7 | 0x10u;
crtc_status = crtc_status & 0xF7 | 0x10;
if ( (dmac_mode & 4) == 0 || crtc_intr_mask != 3 )
goto LABEL_6;
if ( (grph_pile & 1) != 0 )
{
if ( (grph_ctrl & 0x10) != 0 )
LABEL_6:
text_display = 0;
else
text_display = 1;
}
else
{
text_display = 2;
}
screen_update_palette = 1;
screen_update_force = 1;
break;
case 2:
crtc_intr_mask = a1 & 3;
result = a1 & 3;
if ( (dmac_mode & 4) == 0 || !crtc_active || (_BYTE)result != 3 )
goto LABEL_15;
if ( (grph_pile & 1) != 0 )
{
if ( (grph_ctrl & 0x10) != 0 )
LABEL_15:
text_display = 0;
else
text_display = 1;
}
else
{
text_display = 2;
}
screen_update_force = 1;
break;
case 3:
crtc_status &= 0xFEu;
return result;
case 4:
crtc_cursor = -1LL;
crtc_load_cursor_position = a1 & 1;
return result;
case 5:
case 6:
crtc_status &= 0xF9u;
return result;
default:
return result;
}
return result;
}

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

crtc_param_num = 0;
crtc_command = a1 >> 5;
result = a1 >> 5;
switch ( (char)result )
{
case 0:
crtc_status &= 0xE9u;
crtc_active = 0;
text_display = 0;
screen_update_force = 1;
return result;
case 1:
crtc_active = 1;
crtc_reverse_display = a1 & 1;
result = crtc_status & 0xF7 | 0x10u;
crtc_status = crtc_status & 0xF7 | 0x10;
if ( (dmac_mode & 4) == 0 || crtc_intr_mask != 3 )
goto LABEL_6;
if ( (grph_pile & 1) != 0 )
{
if ( (grph_ctrl & 0x10) != 0 )
LABEL_6:
text_display = 0;
else
text_display = 1;
}
else
{
text_display = 2;
}
screen_update_palette = 1;
screen_update_force = 1;
break;
case 2:
crtc_intr_mask = a1 & 3;
result = a1 & 3;
if ( (dmac_mode & 4) == 0 || !crtc_active || (_BYTE)result != 3 )
goto LABEL_15;
if ( (grph_pile & 1) != 0 )
{
if ( (grph_ctrl & 0x10) != 0 )
LABEL_15:
text_display = 0;
else
text_display = 1;
}
else
{
text_display = 2;
}
screen_update_force = 1;
break;
case 3:
crtc_status &= 0xFEu;
return result;
case 4:
crtc_cursor = -1LL;
crtc_load_cursor_position = a1 & 1;
return result;
case 5:
case 6:
crtc_status &= 0xF9u;
return result;
default:
return result;
}
return result;
}

original_code:
void crtc_out_command( byte data )
{
  crtc_command = data >> 5;
  crtc_param_num = 0;
  switch( crtc_command ){
  case CRTC_RESET:
    crtc_status &= ~( (0x10) | (0x04) | (0x02) );
    crtc_active = (0);
    do{ if( (dmac_mode & 0x4) && (crtc_active) && crtc_intr_mask==3){ if( !(grph_pile & (0x01)) ){ text_display = TEXT_ENABLE; }else{ if( grph_ctrl & (0x10) ) text_display = TEXT_DISABLE; else text_display = TEXT_ATTR_ONLY; } }else{ text_display = TEXT_DISABLE; } }while(0);
    screen_update_force = (1);
    break;
  case CRTC_START_DISPLAY:
    crtc_reverse_display = data & 0x01;
    crtc_status |= (0x10);
    crtc_status &= ~( (0x08) );
    crtc_active = (1);
    do{ if( (dmac_mode & 0x4) && (crtc_active) && crtc_intr_mask==3){ if( !(grph_pile & (0x01)) ){ text_display = TEXT_ENABLE; }else{ if( grph_ctrl & (0x10) ) text_display = TEXT_DISABLE; else text_display = TEXT_ATTR_ONLY; } }else{ text_display = TEXT_DISABLE; } }while(0);
    do{ screen_update_palette = (1); screen_update_force = (1); }while(0);
    break;
  case CRTC_SET_INTERRUPT_MASK:
    crtc_intr_mask = data & 0x03;
    do{ if( (dmac_mode & 0x4) && (crtc_active) && crtc_intr_mask==3){ if( !(grph_pile & (0x01)) ){ text_display = TEXT_ENABLE; }else{ if( grph_ctrl & (0x10) ) text_display = TEXT_DISABLE; else text_display = TEXT_ATTR_ONLY; } }else{ text_display = TEXT_DISABLE; } }while(0);
    screen_update_force = (1);
    break;
  case CRTC_READ_LIGHT_PEN:
    crtc_status &= ~( (0x01) );
    break;
  case CRTC_LOAD_CURSOR_POSITION:
    crtc_load_cursor_position = data & 0x01;
    crtc_cursor[ 0 ] = -1;
    crtc_cursor[ 1 ] = -1;
    break;
  case CRTC_RESET_INTERRUPT:
  case CRTC_RESET_COUNTERS:
    crtc_status &= ~( (0x04) | (0x02) );
    break;
  }
}

canonical_original_code:
void crtc_out_command(unsigned char data)
{
  crtc_command = data >> 5;
  crtc_param_num = 0;
  switch( crtc_command ){
  case CRTC_RESET:
    crtc_status &= ~( (0x10) | (0x04) | (0x02) );
    crtc_active = (0);
    do{ if( (dmac_mode & 0x4) && (crtc_active) && crtc_intr_mask==3){ if( !(grph_pile & (0x01)) ){ text_display = TEXT_ENABLE; }else{ if( grph_ctrl & (0x10) ) text_display = TEXT_DISABLE; else text_display = TEXT_ATTR_ONLY; } }else{ text_display = TEXT_DISABLE; } }while(0);
    screen_update_force = (1);
    break;
  case CRTC_START_DISPLAY:
    crtc_reverse_display = data & 0x01;
    crtc_status |= (0x10);
    crtc_status &= ~( (0x08) );
    crtc_active = (1);
    do{ if( (dmac_mode & 0x4) && (crtc_active) && crtc_intr_mask==3){ if( !(grph_pile & (0x01)) ){ text_display = TEXT_ENABLE; }else{ if( grph_ctrl & (0x10) ) text_display = TEXT_DISABLE; else text_display = TEXT_ATTR_ONLY; } }else{ text_display = TEXT_DISABLE; } }while(0);
    do{ screen_update_palette = (1); screen_update_force = (1); }while(0);
    break;
  case CRTC_SET_INTERRUPT_MASK:
    crtc_intr_mask = data & 0x03;
    do{ if( (dmac_mode & 0x4) && (crtc_active) && crtc_intr_mask==3){ if( !(grph_pile & (0x01)) ){ text_display = TEXT_ENABLE; }else{ if( grph_ctrl & (0x10) ) text_display = TEXT_DISABLE; else text_display = TEXT_ATTR_ONLY; } }else{ text_display = TEXT_DISABLE; } }while(0);
    screen_update_force = (1);
    break;
  case CRTC_READ_LIGHT_PEN:
    crtc_status &= ~( (0x01) );
    break;
  case CRTC_LOAD_CURSOR_POSITION:
    crtc_load_cursor_position = data & 0x01;
    crtc_cursor[ 0 ] = -1;
    crtc_cursor[ 1 ] = -1;
    break;
  case CRTC_RESET_INTERRUPT:
  case CRTC_RESET_COUNTERS:
    crtc_status &= ~( (0x04) | (0x02) );
    break;
  }
}

variable_types:
data
unsigned char

return_type: void


decompiled_code:
__int64 __fastcall crtc_out_parameter(unsigned __int8 a1)
{
__int64 result; // rax
int v2; // eax
char v3; // al
char v4; // dl
unsigned __int8 v5; // cl
int v6; // ecx
int v7; // eax
int v8; // eax
unsigned __int8 v9; // dl

result = (unsigned int)crtc_command;
if ( crtc_command )
{
if ( crtc_command == 4 )
{
result = crtc_param_num;
if ( crtc_param_num <= 1 )
{
++crtc_param_num;
if ( crtc_load_cursor_position )
*((_DWORD *)&crtc_cursor + result) = a1;
else
*((_DWORD *)&crtc_cursor + result) = -1;
}
}
}
else
{
v2 = crtc_param_num;
if ( crtc_param_num <= 4 )
{
crtc_format[crtc_param_num] = a1;
crtc_param_num = v2 + 1;
}
v3 = crtc_format[2];
crtc_skip_line = v3 & 0x80;
v4 = crtc_format[4];
crtc_attr_non_separate = v4 & 0x80;
crtc_attr_color = v4 & 0x40;
crtc_attr_non_special = v4 & 0x20;
crtc_cursor_blink = v3 & 0x20;
crtc_cursor_style = (v3 & 0x40) == 0 ? 8 : 1;
v5 = (crtc_format[1] & 0x3F) + 1;
blink_cycle = 8 * (unsigned __int8)(((unsigned __int8)crtc_format[1] >> 6) + 1);
if ( v5 <= 0x14u )
{
crtc_sz_lines = 20;
v6 = 20;
}
else if ( v5 <= 0x18u )
{
crtc_sz_lines = 24;
v6 = 24;
}
else
{
crtc_sz_lines = 25;
v6 = 25;
}
LOBYTE(v7) = (crtc_format[0] & 0x7F) + 2;
if ( (unsigned __int8)v7 > 0x50u )
{
crtc_sz_columns = 80;
v7 = 80;
}
else
{
v7 = (unsigned __int8)v7;
crtc_sz_columns = (unsigned __int8)v7;
}
if ( (v4 & 0x20) != 0 )
{
crtc_sz_attrs = 0;
}
else
{
v9 = (v4 & 0x1F) + 1;
if ( v9 > 0x14u )
{
crtc_sz_attrs = 20;
v7 += 40;
}
else
{
crtc_sz_attrs = v9;
v7 += 2 * v9;
}
}
crtc_byte_per_line = v7;
v8 = 10;
if ( v6 != 20 )
{
v8 = 8;
v6 = 25;
}
crtc_font_height = v8;
CRTC_SZ_LINES = v6;
result = blink_ctrl_update();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 a1)
{
__int64 result; // rax
int v2; // eax
char v3; // al
char v4; // dl
unsigned __int8 v5; // cl
int v6; // ecx
int v7; // eax
int v8; // eax
unsigned __int8 v9; // dl

result = (unsigned int)crtc_command;
if ( crtc_command )
{
if ( crtc_command == 4 )
{
result = crtc_param_num;
if ( crtc_param_num <= 1 )
{
++crtc_param_num;
if ( crtc_load_cursor_position )
*((_DWORD *)&crtc_cursor + result) = a1;
else
*((_DWORD *)&crtc_cursor + result) = -1;
}
}
}
else
{
v2 = crtc_param_num;
if ( crtc_param_num <= 4 )
{
crtc_format[crtc_param_num] = a1;
crtc_param_num = v2 + 1;
}
v3 = crtc_format[2];
crtc_skip_line = v3 & 0x80;
v4 = crtc_format[4];
crtc_attr_non_separate = v4 & 0x80;
crtc_attr_color = v4 & 0x40;
crtc_attr_non_special = v4 & 0x20;
crtc_cursor_blink = v3 & 0x20;
crtc_cursor_style = (v3 & 0x40) == 0 ? 8 : 1;
v5 = (crtc_format[1] & 0x3F) + 1;
blink_cycle = 8 * (unsigned __int8)(((unsigned __int8)crtc_format[1] >> 6) + 1);
if ( v5 <= 0x14u )
{
crtc_sz_lines = 20;
v6 = 20;
}
else if ( v5 <= 0x18u )
{
crtc_sz_lines = 24;
v6 = 24;
}
else
{
crtc_sz_lines = 25;
v6 = 25;
}
LOBYTE(v7) = (crtc_format[0] & 0x7F) + 2;
if ( (unsigned __int8)v7 > 0x50u )
{
crtc_sz_columns = 80;
v7 = 80;
}
else
{
v7 = (unsigned __int8)v7;
crtc_sz_columns = (unsigned __int8)v7;
}
if ( (v4 & 0x20) != 0 )
{
crtc_sz_attrs = 0;
}
else
{
v9 = (v4 & 0x1F) + 1;
if ( v9 > 0x14u )
{
crtc_sz_attrs = 20;
v7 += 40;
}
else
{
crtc_sz_attrs = v9;
v7 += 2 * v9;
}
}
crtc_byte_per_line = v7;
v8 = 10;
if ( v6 != 20 )
{
v8 = 8;
v6 = 25;
}
crtc_font_height = v8;
CRTC_SZ_LINES = v6;
result = blink_ctrl_update();
}
return result;
}

original_code:
void crtc_out_parameter( byte data )
{
  switch( crtc_command ){
  case CRTC_RESET:
    if( crtc_param_num < 5 ){
      crtc_format[ crtc_param_num++ ] = data;
    }
    crtc_skip_line = crtc_format[2] & 0x80;
    crtc_attr_non_separate = crtc_format[4] & 0x80;
    crtc_attr_color = crtc_format[4] & 0x40;
    crtc_attr_non_special = crtc_format[4] & 0x20;
    crtc_cursor_style =(crtc_format[2] & 0x40) ?0x01 :0x08;
    crtc_cursor_blink = crtc_format[2] & 0x20;
    blink_cycle =(crtc_format[1]>>6) * 8 +8;
    crtc_sz_lines =(crtc_format[1] & 0x3f) +1;
    if ( crtc_sz_lines <= 20 ) crtc_sz_lines = 20;
    else if( crtc_sz_lines >= 25 ) crtc_sz_lines = 25;
    else crtc_sz_lines = 24;
    crtc_sz_columns =(crtc_format[0] & 0x7f) +2;
    if( crtc_sz_columns > 80 ) crtc_sz_columns = 80;
    crtc_sz_attrs =(crtc_format[4] & 0x1f) +1;
    if ( crtc_attr_non_special ) crtc_sz_attrs = 0;
    else if( crtc_sz_attrs > 20 ) crtc_sz_attrs = 20;
    crtc_byte_per_line = crtc_sz_columns + crtc_sz_attrs * 2;
    crtc_font_height = (crtc_sz_lines>20) ? 8 : 10;
    CRTC_SZ_LINES = (crtc_sz_lines>20) ? 25 : 20;
    blink_ctrl_update();
    break;
  case CRTC_LOAD_CURSOR_POSITION:
    if( crtc_param_num < 2 ){
      if( crtc_load_cursor_position ){
 crtc_cursor[ crtc_param_num++ ] = data;
      }else{
 crtc_cursor[ crtc_param_num++ ] = -1;
      }
    }
    break;
  }
}

canonical_original_code:
void crtc_out_parameter(unsigned char data)
{
  switch( crtc_command ){
  case CRTC_RESET:
    if( crtc_param_num < 5 ){
      crtc_format[ crtc_param_num++ ] = data;
    }
    crtc_skip_line = crtc_format[2] & 0x80;
    crtc_attr_non_separate = crtc_format[4] & 0x80;
    crtc_attr_color = crtc_format[4] & 0x40;
    crtc_attr_non_special = crtc_format[4] & 0x20;
    crtc_cursor_style =(crtc_format[2] & 0x40) ?0x01 :0x08;
    crtc_cursor_blink = crtc_format[2] & 0x20;
    blink_cycle =(crtc_format[1]>>6) * 8 +8;
    crtc_sz_lines =(crtc_format[1] & 0x3f) +1;
    if ( crtc_sz_lines <= 20 ) crtc_sz_lines = 20;
    else if( crtc_sz_lines >= 25 ) crtc_sz_lines = 25;
    else crtc_sz_lines = 24;
    crtc_sz_columns =(crtc_format[0] & 0x7f) +2;
    if( crtc_sz_columns > 80 ) crtc_sz_columns = 80;
    crtc_sz_attrs =(crtc_format[4] & 0x1f) +1;
    if ( crtc_attr_non_special ) crtc_sz_attrs = 0;
    else if( crtc_sz_attrs > 20 ) crtc_sz_attrs = 20;
    crtc_byte_per_line = crtc_sz_columns + crtc_sz_attrs * 2;
    crtc_font_height = (crtc_sz_lines>20) ? 8 : 10;
    CRTC_SZ_LINES = (crtc_sz_lines>20) ? 25 : 20;
    blink_ctrl_update();
    break;
  case CRTC_LOAD_CURSOR_POSITION:
    if( crtc_param_num < 2 ){
      if( crtc_load_cursor_position ){
 crtc_cursor[ crtc_param_num++ ] = data;
      }else{
 crtc_cursor[ crtc_param_num++ ] = -1;
      }
    }
    break;
  }
}


decompiled_code:
__int64 crtc_init()
{
crtc_out_command(0);
crtc_out_parameter(0xCEu);
crtc_out_parameter(0x98u);
crtc_out_parameter(0x6Fu);
crtc_out_parameter(0x58u);
crtc_out_parameter(0x53u);
crtc_out_command(0x80u);
crtc_out_parameter(0);
return crtc_out_parameter(0);
}

canonical_decompiled_code:
__int64 func2()
{
func0(0);
func1(0xCEu);
func1(0x98u);
func1(0x6Fu);
func1(0x58u);
func1(0x53u);
func0(0x80u);
func1(0);
return func1(0);
}

original_code:
void crtc_init( void )
{
  crtc_out_command( CRTC_RESET << 5 );
  crtc_out_parameter( 0xce );
  crtc_out_parameter( 0x98 );
  crtc_out_parameter( 0x6f );
  crtc_out_parameter( 0x58 );
  crtc_out_parameter( 0x53 );
  crtc_out_command( CRTC_LOAD_CURSOR_POSITION << 5 );
  crtc_out_parameter( 0 );
  crtc_out_parameter( 0 );
}

canonical_original_code:
void crtc_init()
{
  crtc_out_command( CRTC_RESET << 5 );
  crtc_out_parameter( 0xce );
  crtc_out_parameter( 0x98 );
  crtc_out_parameter( 0x6f );
  crtc_out_parameter( 0x58 );
  crtc_out_parameter( 0x53 );
  crtc_out_command( CRTC_LOAD_CURSOR_POSITION << 5 );
  crtc_out_parameter( 0 );
  crtc_out_parameter( 0 );
}


decompiled_code:
__int64 crtc_in_status()
{
return (unsigned __int8)crtc_status;
}

canonical_decompiled_code:
__int64 func3()
{
return (unsigned __int8)crtc_status;
}

original_code:
byte crtc_in_status( void )
{
  return crtc_status;
}

canonical_original_code:
unsigned char crtc_in_status()
{
  return crtc_status;
}

return_type: unsigned char


decompiled_code:
__int64 crtc_in_parameter()
{
__int64 result; // rax
__int64 v1; // rdx

result = 0xFFFFFFFFLL;
if ( crtc_command == 3 )
{
v1 = crtc_param_num;
if ( crtc_param_num <= 1 )
{
++crtc_param_num;
result = (unsigned __int8)crtc_light_pen[v1];
}
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 result; // rax
__int64 v1; // rdx

result = 0xFFFFFFFFLL;
if ( crtc_command == 3 )
{
v1 = crtc_param_num;
if ( crtc_param_num <= 1 )
{
++crtc_param_num;
result = (unsigned __int8)crtc_light_pen[v1];
}
}
return result;
}

original_code:
byte crtc_in_parameter( void )
{
  byte data = 0xff;
  switch( crtc_command ){
  case CRTC_READ_LIGHT_PEN:
    if( crtc_param_num < 2 ){
      data = crtc_light_pen[ crtc_param_num++ ];
    }
    return data;
  }
  return 0xff;
}

canonical_original_code:
unsigned char crtc_in_parameter()
{
  unsigned char data = 0xff;
  switch( crtc_command ){
  case CRTC_READ_LIGHT_PEN:
    if( crtc_param_num < 2 ){
      data = crtc_light_pen[ crtc_param_num++ ];
    }
    return data;
  }
  return 0xff;
}


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

result = 0xF3C800000000LL;
dmac_flipflop = 0;
dmac_address = 0xF3C800000000LL;
dmac_counter = 0LL;
return result;
}

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

result = 0xF3C800000000LL;
dmac_flipflop = 0;
dmac_address = 0xF3C800000000LL;
dmac_counter = 0LL;
return result;
}

original_code:
void dmac_init( void )
{
  dmac_flipflop = 0;
  dmac_address[0].W = 0;
  dmac_address[1].W = 0;
  dmac_address[2].W = 0xf3c8;
  dmac_address[3].W = 0;
  dmac_counter[0].W = 0;
  dmac_counter[1].W = 0;
  dmac_counter[2].W = 0;
  dmac_counter[3].W = 0;
}

canonical_original_code:
void dmac_init()
{
  dmac_flipflop = 0;
  dmac_address[0].W = 0;
  dmac_address[1].W = 0;
  dmac_address[2].W = 0xf3c8;
  dmac_address[3].W = 0;
  dmac_counter[0].W = 0;
  dmac_counter[1].W = 0;
  dmac_counter[2].W = 0;
  dmac_counter[3].W = 0;
}


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

dmac_flipflop = 0;
result = a1;
dmac_mode = a1;
if ( (a1 & 4) == 0 )
goto LABEL_3;
result = (unsigned int)crtc_active;
if ( !crtc_active || crtc_intr_mask != 3 )
goto LABEL_3;
if ( (grph_pile & 1) == 0 )
{
text_display = 2;
goto LABEL_4;
}
if ( (grph_ctrl & 0x10) == 0 )
text_display = 1;
else
LABEL_3:
text_display = 0;
LABEL_4:
screen_update_force = 1;
return result;
}

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

dmac_flipflop = 0;
result = a1;
dmac_mode = a1;
if ( (a1 & 4) == 0 )
goto LABEL_3;
result = (unsigned int)crtc_active;
if ( !crtc_active || crtc_intr_mask != 3 )
goto LABEL_3;
if ( (grph_pile & 1) == 0 )
{
text_display = 2;
goto LABEL_4;
}
if ( (grph_ctrl & 0x10) == 0 )
text_display = 1;
else
LABEL_3:
text_display = 0;
LABEL_4:
screen_update_force = 1;
return result;
}

original_code:
void dmac_out_mode( byte data )
{
  dmac_flipflop = 0;
  dmac_mode = data;
  do{ if( (dmac_mode & 0x4) && (crtc_active) && crtc_intr_mask==3){ if( !(grph_pile & (0x01)) ){ text_display = TEXT_ENABLE; }else{ if( grph_ctrl & (0x10) ) text_display = TEXT_DISABLE; else text_display = TEXT_ATTR_ONLY; } }else{ text_display = TEXT_DISABLE; } }while(0);
  screen_update_force = (1);
}

canonical_original_code:
void dmac_out_mode(unsigned char data)
{
  dmac_flipflop = 0;
  dmac_mode = data;
  do{ if( (dmac_mode & 0x4) && (crtc_active) && crtc_intr_mask==3){ if( !(grph_pile & (0x01)) ){ text_display = TEXT_ENABLE; }else{ if( grph_ctrl & (0x10) ) text_display = TEXT_DISABLE; else text_display = TEXT_ATTR_ONLY; } }else{ text_display = TEXT_DISABLE; } }while(0);
  screen_update_force = (1);
}


decompiled_code:
__int64 dmac_in_status()
{
return 31LL;
}

canonical_decompiled_code:
__int64 func7()
{
return 31LL;
}

original_code:
byte dmac_in_status( void )
{
  return 0x1f;
}

canonical_original_code:
unsigned char dmac_in_status()
{
  return 0x1f;
}


decompiled_code:
__int64 __fastcall dmac_out_address(unsigned __int8 a1, char a2)
{
int v2; // eax
__int64 result; // rax

v2 = dmac_flipflop;
if ( dmac_flipflop )
*((_BYTE *)&dmac_address + 2 * a1 + 1) = a2;
else
*((_BYTE *)&dmac_address + 2 * a1) = a2;
screen_update_force = 1;
result = v2 ^ 1u;
dmac_flipflop = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned __int8 a1, char a2)
{
int v2; // eax
__int64 result; // rax

v2 = dmac_flipflop;
if ( dmac_flipflop )
*((_BYTE *)&dmac_address + 2 * a1 + 1) = a2;
else
*((_BYTE *)&dmac_address + 2 * a1) = a2;
screen_update_force = 1;
result = v2 ^ 1u;
dmac_flipflop = result;
return result;
}

original_code:
void dmac_out_address( byte addr, byte data )
{
  if( dmac_flipflop==0 ) dmac_address[ addr ].B.l=data;
  else dmac_address[ addr ].B.h=data;
  dmac_flipflop ^= 0x1;
  screen_update_force = (1);
}

canonical_original_code:
void dmac_out_address(unsigned char addr, unsigned char data)
{
  if( dmac_flipflop==0 ) dmac_address[ addr ].B.l=data;
  else dmac_address[ addr ].B.h=data;
  dmac_flipflop ^= 0x1;
  screen_update_force = (1);
}

variable_types:
addr
unsigned char


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

result = dmac_flipflop ^ 1u;
if ( dmac_flipflop )
*((_BYTE *)&dmac_counter + 2 * a1 + 1) = a2;
else
*((_BYTE *)&dmac_counter + 2 * a1) = a2;
dmac_flipflop = result;
return result;
}

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

result = dmac_flipflop ^ 1u;
if ( dmac_flipflop )
*((_BYTE *)&dmac_counter + 2 * a1 + 1) = a2;
else
*((_BYTE *)&dmac_counter + 2 * a1) = a2;
dmac_flipflop = result;
return result;
}

original_code:
void dmac_out_counter( byte addr, byte data )
{
  if( dmac_flipflop==0 ) dmac_counter[ addr ].B.l=data;
  else dmac_counter[ addr ].B.h=data;
  dmac_flipflop ^= 0x1;
}

canonical_original_code:
void dmac_out_counter(unsigned char addr, unsigned char data)
{
  if( dmac_flipflop==0 ) dmac_counter[ addr ].B.l=data;
  else dmac_counter[ addr ].B.h=data;
  dmac_flipflop ^= 0x1;
}


decompiled_code:
__int64 __fastcall dmac_in_address(unsigned __int8 a1)
{
unsigned int v1; // er8

v1 = *((unsigned __int8 *)&dmac_address + 2 * a1);
if ( dmac_flipflop )
v1 = *((unsigned __int8 *)&dmac_address + 2 * a1 + 1);
dmac_flipflop ^= 1u;
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned __int8 a1)
{
unsigned int v1; // er8

v1 = *((unsigned __int8 *)&dmac_address + 2 * a1);
if ( dmac_flipflop )
v1 = *((unsigned __int8 *)&dmac_address + 2 * a1 + 1);
dmac_flipflop ^= 1u;
return v1;
}

original_code:
byte dmac_in_address( byte addr )
{
  byte data;
  if( dmac_flipflop==0 ) data = dmac_address[ addr ].B.l;
  else data = dmac_address[ addr ].B.h;
  dmac_flipflop ^= 0x1;
  return data;
}

canonical_original_code:
unsigned char dmac_in_address(unsigned char addr)
{
  unsigned char data;
  if( dmac_flipflop==0 ) data = dmac_address[ addr ].B.l;
  else data = dmac_address[ addr ].B.h;
  dmac_flipflop ^= 0x1;
  return data;
}


decompiled_code:
__int64 __fastcall dmac_in_counter(unsigned __int8 a1)
{
unsigned int v1; // er8

v1 = *((unsigned __int8 *)&dmac_counter + 2 * a1);
if ( dmac_flipflop )
v1 = *((unsigned __int8 *)&dmac_counter + 2 * a1 + 1);
dmac_flipflop ^= 1u;
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned __int8 a1)
{
unsigned int v1; // er8

v1 = *((unsigned __int8 *)&dmac_counter + 2 * a1);
if ( dmac_flipflop )
v1 = *((unsigned __int8 *)&dmac_counter + 2 * a1 + 1);
dmac_flipflop ^= 1u;
return v1;
}

original_code:
byte dmac_in_counter( byte addr )
{
  byte data;
  if( dmac_flipflop==0 ) data = dmac_counter[ addr ].B.l;
  else data = dmac_counter[ addr ].B.h;
  dmac_flipflop ^= 0x1;
  return data;
}

canonical_original_code:
unsigned char dmac_in_counter(unsigned char addr)
{
  unsigned char data;
  if( dmac_flipflop==0 ) data = dmac_counter[ addr ].B.l;
  else data = dmac_counter[ addr ].B.h;
  dmac_flipflop ^= 0x1;
  return data;
}


decompiled_code:
_BOOL8 statesave_crtcdmac()
{
return (unsigned int)statesave_table("CRTC", &suspend_crtcdmac_work) == 0;
}

canonical_decompiled_code:
_BOOL8 func12()
{
return (unsigned int)statesave_table("CRTC", &suspend_crtcdmac_work) == 0;
}

original_code:
int statesave_crtcdmac( void )
{
  if( statesave_table( "CRTC", suspend_crtcdmac_work ) == (0) ) return (1);
  else return (0);
}

canonical_original_code:
int statesave_crtcdmac()
{
  if( statesave_table( "CRTC", suspend_crtcdmac_work ) == (0) ) return (1);
  else return (0);
}

return_type: int


decompiled_code:
_BOOL8 stateload_crtcdmac()
{
return (unsigned int)stateload_table("CRTC", &suspend_crtcdmac_work) == 0;
}

canonical_decompiled_code:
_BOOL8 func13()
{
return (unsigned int)stateload_table("CRTC", &suspend_crtcdmac_work) == 0;
}

original_code:
int stateload_crtcdmac( void )
{
  if( stateload_table( "CRTC", suspend_crtcdmac_work ) == (0) ) return (1);
  else return (0);
}

canonical_original_code:
int stateload_crtcdmac()
{
  if( stateload_table( "CRTC", suspend_crtcdmac_work ) == (0) ) return (1);
  else return (0);
}


decompiled_code:
void sigterm_handler()
{
if ( (unsigned int)get_emu_mode() == 6 )
q8tk_event_quit();
set_emu_mode(8LL);
z80_state_intchk = 0;
z80_state_goal = 1;
z80main_cpu[9] = 0;
z80sub_cpu[9] = 0;
}

canonical_decompiled_code:
void func0()
{
if ( (unsigned int)get_emu_mode() == 6 )
q8tk_event_quit();
set_emu_mode(8LL);
z80_state_intchk = 0;
z80_state_goal = 1;
z80main_cpu[9] = 0;
z80sub_cpu[9] = 0;
}

original_code:
static void sigterm_handler( int dummy )
{
  if( get_emu_mode() == MENU ){
    q8tk_event_quit();
  }
  set_emu_mode( QUIT );
  do{ z80_state_intchk = 0; z80_state_goal = 1; }while(0);
  z80main_cpu.icount = 0;
  z80sub_cpu.icount = 0;
}

canonical_original_code:
static void sigterm_handler(int dummy)
{
  if( get_emu_mode() == MENU ){
    q8tk_event_quit();
  }
  set_emu_mode( QUIT );
  do{ z80_state_intchk = 0; z80_state_goal = 1; }while(0);
  z80main_cpu.icount = 0;
  z80sub_cpu.icount = 0;
}

variable_types: dummy int


decompiled_code:
void sigint_handler()
{
if ( (unsigned int)get_emu_mode() == 6 )
q8tk_event_quit();
if ( (unsigned int)get_emu_mode() != 5 )
{
set_emu_mode(5LL);
z80_state_intchk = 0;
z80_state_goal = 1;
}
signal(2, sigint_handler);
}

canonical_decompiled_code:
void func1()
{
if ( (unsigned int)get_emu_mode() == 6 )
q8tk_event_quit();
if ( (unsigned int)get_emu_mode() != 5 )
{
set_emu_mode(5LL);
z80_state_intchk = 0;
z80_state_goal = 1;
}
signal(2, sigint_handler);
}

original_code:
static void sigint_handler( int dummy )
{
  if( get_emu_mode() == MENU ){
    q8tk_event_quit();
  }
  if( get_emu_mode() != MONITOR ){
    set_emu_mode( MONITOR );
    do{ z80_state_intchk = 0; z80_state_goal = 1; }while(0);
  }
  signal( 2, sigint_handler );
}

canonical_original_code:
static void sigint_handler(int dummy)
{
  if( get_emu_mode() == MENU ){
    q8tk_event_quit();
  }
  if( get_emu_mode() != MONITOR ){
    set_emu_mode( MONITOR );
    do{ z80_state_intchk = 0; z80_state_goal = 1; }while(0);
  }
  signal( 2, sigint_handler );
}


decompiled_code:
__sighandler_t set_signal()
{
void (*v0)(); // rsi

v0 = sigint_handler;
if ( !debug_mode )
v0 = sigterm_handler;
signal(2, (__sighandler_t)v0);
return signal(15, (__sighandler_t)sigterm_handler);
}

canonical_decompiled_code:
__sighandler_t func2()
{
void (*v0)(); // rsi

v0 = sigint_handler;
if ( !debug_mode )
v0 = sigterm_handler;
signal(2, (__sighandler_t)v0);
return signal(15, (__sighandler_t)sigterm_handler);
}

original_code:
void set_signal( void )
{
  if( debug_mode ){
    signal( 2, sigint_handler );
    signal( 15, sigterm_handler );
  }else{
    signal( 2, sigterm_handler );
    signal( 15, sigterm_handler );
  }
}

canonical_original_code:
void set_signal()
{
  if( debug_mode ){
    signal( 2, sigint_handler );
    signal( 15, sigterm_handler );
  }else{
    signal( 2, sigterm_handler );
    signal( 15, sigterm_handler );
  }
}


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

result = gettimeofday(&start_tv, 0LL);
if ( result )
{
result = verbose_wait;
if ( verbose_wait )
result = puts("Clock Error");
tick_error = 1;
start_tv.tv_sec = 0LL;
start_tv.tv_usec = 0LL;
}
return result;
}

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

result = gettimeofday(&start_tv, 0LL);
if ( result )
{
result = verbose_wait;
if ( verbose_wait )
result = puts("Clock Error");
tick_error = 1;
start_tv.tv_sec = 0LL;
start_tv.tv_usec = 0LL;
}
return result;
}

original_code:
static __inline__ void set_tick( void )
{
  if( gettimeofday( &start_tv, 0 ) ){
    if( verbose_wait ) printf( "Clock Error\n" );
    tick_error = (1);
    start_tv.tv_sec = 0;
    start_tv.tv_usec = 0;
  }
}

canonical_original_code:
static __inline__ void set_tick()
{
  if( gettimeofday( &start_tv, 0 ) ){
    if( verbose_wait ) printf( "Clock Error\n" );
    tick_error = (1);
    start_tv.tv_sec = 0;
    start_tv.tv_usec = 0;
  }
}


decompiled_code:
__time_t get_tick()
{
__time_t v0; // rdx
__suseconds_t v1; // rax
struct timeval v3; // [rsp+0h] [rbp-18h] BYREF

if ( gettimeofday(&v3, 0LL) )
{
if ( verbose_wait && !tick_error )
puts("Clock Error");
tick_error = 1;
v1 = 1LL;
v0 = 1LL;
}
else
{
v0 = v3.tv_sec;
v1 = v3.tv_usec;
}
return 1000000 * (v0 - start_tv.tv_sec) + v1 - start_tv.tv_usec;
}

canonical_decompiled_code:
__time_t func1()
{
__time_t v0; // rdx
__suseconds_t v1; // rax
struct timeval v3; // [rsp+0h] [rbp-18h] BYREF

if ( gettimeofday(&v3, 0LL) )
{
if ( verbose_wait && !tick_error )
puts("Clock Error");
tick_error = 1;
v1 = 1LL;
v0 = 1LL;
}
else
{
v0 = v3.tv_sec;
v1 = v3.tv_usec;
}
return 1000000 * (v0 - start_tv.tv_sec) + v1 - start_tv.tv_usec;
}

original_code:
static __inline__ T_WAIT_TICK get_tick( void )
{
  struct timeval tv;
  if( gettimeofday( &tv, 0 ) ){
    if( verbose_wait ){ if( tick_error==(0) ) printf( "Clock Error\n" ); }
    tick_error = (1);
    tv.tv_sec = 1;
    tv.tv_usec = 1;
  }
  return ( (T_WAIT_TICK)(tv.tv_sec - start_tv.tv_sec) * 1000000 +
    (T_WAIT_TICK)(tv.tv_usec - start_tv.tv_usec) );
}

canonical_original_code:
static __inline__ long get_tick()
{
  struct timeval tv;
  if( gettimeofday( &tv, 0 ) ){
    if( verbose_wait ){ if( tick_error==(0) ) printf( "Clock Error\n" ); }
    tick_error = (1);
    tv.tv_sec = 1;
    tv.tv_usec = 1;
  }
  return ( (T_WAIT_TICK)(tv.tv_sec - start_tv.tv_sec) * 1000000 +
    (T_WAIT_TICK)(tv.tv_usec - start_tv.tv_usec) );
}

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

return_type: long


decompiled_code:
int __fastcall delay_usec(unsigned int a1)
{
struct timeval v2; // [rsp+0h] [rbp-18h] BYREF

v2.tv_sec = 0LL;
v2.tv_usec = a1;
return select(0, 0LL, 0LL, 0LL, &v2);
}

canonical_decompiled_code:
int __fastcall func2(unsigned int a1)
{
struct timeval v2; // [rsp+0h] [rbp-18h] BYREF

v2.tv_sec = 0LL;
v2.tv_usec = a1;
return select(0, 0LL, 0LL, 0LL, &v2);
}

original_code:
static __inline__ void delay_usec( unsigned int usec )
{
  struct timeval tv;
  tv.tv_sec = 0;
  tv.tv_usec = usec;
  select( 0, ((void *)0), ((void *)0), ((void *)0), &tv );
}

canonical_original_code:
static __inline__ void delay_usec(unsigned int usec)
{
  struct timeval tv;
  tv.tv_sec = 0;
  tv.tv_usec = usec;
  select( 0, ((void *)0), ((void *)0), ((void *)0), &tv );
}

variable_types:
usec
unsigned int

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


decompiled_code:
void wait_vsync_term()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
void wait_vsync_term( void )
{
}

canonical_original_code:
void wait_vsync_term()
{
}


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

set_tick();
wait_counter = 0;
sleep_min_time = wait_sleep_min_us;
delta_time = (unsigned int)(int)(1000000.0 / ((double)wait_rate * 55.4 / 100.0));
result = delta_time + get_tick();
next_time = result;
return result;
}

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

func0();
wait_counter = 0;
sleep_min_time = wait_sleep_min_us;
delta_time = (unsigned int)(int)(1000000.0 / ((double)wait_rate * 55.4 / 100.0));
result = delta_time + func1();
next_time = result;
return result;
}

original_code:
void wait_vsync_reset( void )
{
  set_tick();
  sleep_min_time = wait_sleep_min_us;
  wait_counter = 0;
  delta_time = (T_WAIT_TICK)(1000000.0/( (55.4) * wait_rate / 100 ));
  next_time = get_tick() + delta_time;
}

canonical_original_code:
void wait_vsync_reset()
{
  set_tick();
  sleep_min_time = wait_sleep_min_us;
  wait_counter = 0;
  delta_time = (T_WAIT_TICK)(1000000.0/( (55.4) * wait_rate / 100 ));
  next_time = get_tick() + delta_time;
}


decompiled_code:
__int64 wait_vsync_init()
{
if ( verbose_proc )
puts("\nTimer start (gettimeofday(2) - based)");
wait_vsync_reset();
return 1LL;
}

canonical_decompiled_code:
__int64 func5()
{
if ( verbose_proc )
puts("\nTimer start (gettimeofday(2) - based)");
func4();
return 1LL;
}

original_code:
int wait_vsync_init( void )
{
  if( verbose_proc ){
    printf("\nTimer start (gettimeofday(2) - based)\n" );
  }
  wait_vsync_reset();
  return (1);
}

canonical_original_code:
int wait_vsync_init()
{
  if( verbose_proc ){
    printf("\nTimer start (gettimeofday(2) - based)\n" );
  }
  wait_vsync_reset();
  return (1);
}


decompiled_code:
__int64 wait_vsync()
{
__int64 v0; // rbx
__time_t v1; // rax
__int64 v2; // rbx
__time_t v3; // r8
__int64 v4; // rax
__int64 result; // rax
__time_t v6; // r8

v0 = next_time;
v1 = get_tick();
if ( tick_error || (v2 = v0 - v1, v2 <= 0) )
{
next_time += delta_time;
if ( ++wait_counter > 9 )
{
wait_vsync_reset();
result = use_auto_skip;
if ( !use_auto_skip )
return result;
}
else
{
result = use_auto_skip;
if ( !use_auto_skip )
return result;
}
result = (unsigned int)(skip_counter + 1);
skip_counter = result;
if ( (int)result <= 14 )
{
do_skip_draw = 1;
return result;
}
skip_counter = 0;
do_skip_draw = 0;
LABEL_21:
already_skip_draw = 0;
return reset_frame_counter();
}
if ( wait_by_sleep )
{
if ( sleep_min_time <= v2 )
{
delay_usec(v2);
result = delta_time;
next_time += delta_time;
goto LABEL_8;
}
do
{
v3 = get_tick();
v4 = next_time;
}
while ( v3 < next_time && !tick_error );
}
else
{
do
{
v6 = get_tick();
v4 = next_time;
}
while ( v6 < next_time && !tick_error );
}
result = delta_time + v4;
next_time = result;
LABEL_8:
wait_counter = 0;
if ( use_auto_skip )
{
skip_counter = 0;
do_skip_draw = 0;
if ( already_skip_draw )
goto LABEL_21;
}
return result;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 v0; // rbx
__time_t v1; // rax
__int64 v2; // rbx
__time_t v3; // r8
__int64 v4; // rax
__int64 result; // rax
__time_t v6; // r8

v0 = next_time;
v1 = func1();
if ( tick_error || (v2 = v0 - v1, v2 <= 0) )
{
next_time += delta_time;
if ( ++wait_counter > 9 )
{
func4();
result = use_auto_skip;
if ( !use_auto_skip )
return result;
}
else
{
result = use_auto_skip;
if ( !use_auto_skip )
return result;
}
result = (unsigned int)(skip_counter + 1);
skip_counter = result;
if ( (int)result <= 14 )
{
do_skip_draw = 1;
return result;
}
skip_counter = 0;
do_skip_draw = 0;
LABEL_21:
already_skip_draw = 0;
return reset_frame_counter();
}
if ( wait_by_sleep )
{
if ( sleep_min_time <= v2 )
{
func2(v2);
result = delta_time;
next_time += delta_time;
goto LABEL_8;
}
do
{
v3 = func1();
v4 = next_time;
}
while ( v3 < next_time && !tick_error );
}
else
{
do
{
v6 = func1();
v4 = next_time;
}
while ( v6 < next_time && !tick_error );
}
result = delta_time + v4;
next_time = result;
LABEL_8:
wait_counter = 0;
if ( use_auto_skip )
{
skip_counter = 0;
do_skip_draw = 0;
if ( already_skip_draw )
goto LABEL_21;
}
return result;
}

original_code:
void wait_vsync( void )
{
  int on_time = (0);
  T_WAIT_TICK diff_us;
  diff_us = next_time - get_tick();
  if( tick_error == (0) ){
    if( diff_us > 0 ){
      if( wait_by_sleep ){
 if( diff_us < sleep_min_time ){
   while( tick_error == (0) ){
     if( next_time <= get_tick() )
       break;
   }
 }else{
   delay_usec( diff_us );
 }
      }else{
 while( tick_error == (0) ){
   if( next_time <= get_tick() )
     break;
 }
      }
      on_time = (1);
    }
  }
  next_time += delta_time;
  if( on_time ){
    wait_counter = 0;
  }else{
    wait_counter ++;
    if( wait_counter >= wait_count_max ){
      wait_vsync_reset();
    }
  }
  if( use_auto_skip ){
    if( on_time ){
      skip_counter = 0;
      do_skip_draw = (0);
      if( already_skip_draw ){
 already_skip_draw = (0);
 reset_frame_counter();
      }
    }else{
      skip_counter++;
      if( skip_counter >= skip_count_max ){
 skip_counter = 0;
 do_skip_draw = (0);
 already_skip_draw = (0);
 reset_frame_counter();
      }else{
 do_skip_draw = (1);
      }
    }
  }
  return;
}

canonical_original_code:
void wait_vsync()
{
  int on_time = (0);
  long diff_us;
  diff_us = next_time - get_tick();
  if( tick_error == (0) ){
    if( diff_us > 0 ){
      if( wait_by_sleep ){
 if( diff_us < sleep_min_time ){
   while( tick_error == (0) ){
     if( next_time <= get_tick() )
       break;
   }
 }else{
   delay_usec( diff_us );
 }
      }else{
 while( tick_error == (0) ){
   if( next_time <= get_tick() )
     break;
 }
      }
      on_time = (1);
    }
  }
  next_time += delta_time;
  if( on_time ){
    wait_counter = 0;
  }else{
    wait_counter ++;
    if( wait_counter >= wait_count_max ){
      wait_vsync_reset();
    }
  }
  if( use_auto_skip ){
    if( on_time ){
      skip_counter = 0;
      do_skip_draw = (0);
      if( already_skip_draw ){
 already_skip_draw = (0);
 reset_frame_counter();
      }
    }else{
      skip_counter++;
      if( skip_counter >= skip_count_max ){
 skip_counter = 0;
 do_skip_draw = (0);
 already_skip_draw = (0);
 reset_frame_counter();
      }else{
 do_skip_draw = (1);
      }
    }
  }
  return;
}


decompiled_code:
int wait_menu()
{
return delay_usec(0x411Au);
}

canonical_decompiled_code:
int func7()
{
return func2(0x411Au);
}

original_code:
void wait_menu( void )
{
  delay_usec( 1000000 / 60 );
}

canonical_original_code:
void wait_menu()
{
  delay_usec( 1000000 / 60 );
}


decompiled_code:
int print_gettimeofday()
{
int result; // eax
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

result = gettimeofday(&v1, 0LL);
if ( !result )
result = printf("%ld.%06ld\n", v1.tv_sec, v1.tv_usec);
return result;
}

canonical_decompiled_code:
int func8()
{
int result; // eax
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

result = gettimeofday(&v1, 0LL);
if ( !result )
result = printf("%ld.%06ld\n", v1.tv_sec, v1.tv_usec);
return result;
}

original_code:
void print_gettimeofday(void)
{
  struct timeval tv;
  if( gettimeofday( &tv, 0 ) == 0 ){
    printf( "%ld.%06ld\n", tv.tv_sec, tv.tv_usec );
  }
}

canonical_original_code:
void print_gettimeofday()
{
  struct timeval tv;
  if( gettimeofday( &tv, 0 ) == 0 ){
    printf( "%ld.%06ld\n", tv.tv_sec, tv.tv_usec );
  }
}


decompiled_code:
int __fastcall print_lapse(int a1)
{
__time_t v1; // rsi
__suseconds_t v2; // rdx

if ( !t0_2.tv_sec || a1 < 0 )
return gettimeofday(&t0_2, 0LL);
gettimeofday(&t1_1, 0LL);
if ( a1 )
{
v1 = t1_1.tv_sec - t0_2.tv_sec;
v2 = t1_1.tv_usec - t0_2.tv_usec;
dt_0 = t1_1.tv_sec - t0_2.tv_sec;
qword_478 = t1_1.tv_usec - t0_2.tv_usec;
if ( t1_1.tv_usec - t0_2.tv_usec < 0 )
{
--v1;
v2 += 1000000LL;
dt_0 = v1;
qword_478 = v2;
}
printf("%ld.%06ld\n", v1, v2);
}
t0_2 = t1_1;
return t1_1.tv_usec;
}

canonical_decompiled_code:
int __fastcall func9(int a1)
{
__time_t v1; // rsi
__suseconds_t v2; // rdx

if ( !t0_2.tv_sec || a1 < 0 )
return gettimeofday(&t0_2, 0LL);
gettimeofday(&t1_1, 0LL);
if ( a1 )
{
v1 = t1_1.tv_sec - t0_2.tv_sec;
v2 = t1_1.tv_usec - t0_2.tv_usec;
dt_0 = t1_1.tv_sec - t0_2.tv_sec;
qword_478 = t1_1.tv_usec - t0_2.tv_usec;
if ( t1_1.tv_usec - t0_2.tv_usec < 0 )
{
--v1;
v2 += 1000000LL;
dt_0 = v1;
qword_478 = v2;
}
printf("%ld.%06ld\n", v1, v2);
}
t0_2 = t1_1;
return t1_1.tv_usec;
}

original_code:
void print_lapse(int flag)
{
  static struct timeval t0, t1, dt;
  if( t0.tv_sec == 0 || flag < 0 ){
    gettimeofday( &t0, 0 );
  }else{
    gettimeofday( &t1, 0 );
    if( flag > 0 ){
      dt.tv_sec = t1.tv_sec - t0.tv_sec;
      dt.tv_usec = t1.tv_usec - t0.tv_usec;
      if( dt.tv_usec < 0 ){
 dt.tv_sec --;
 dt.tv_usec += 1000000;
      }
      printf( "%ld.%06ld\n", dt.tv_sec, dt.tv_usec );
    }
    t0.tv_sec = t1.tv_sec;
    t0.tv_usec = t1.tv_usec;
  }
}

canonical_original_code:
void print_lapse(int flag)
{
  static struct timeval t0; static struct timeval t1; static struct timeval dt;
  if( t0.tv_sec == 0 || flag < 0 ){
    gettimeofday( &t0, 0 );
  }else{
    gettimeofday( &t1, 0 );
    if( flag > 0 ){
      dt.tv_sec = t1.tv_sec - t0.tv_sec;
      dt.tv_usec = t1.tv_usec - t0.tv_usec;
      if( dt.tv_usec < 0 ){
 dt.tv_sec --;
 dt.tv_usec += 1000000;
      }
      printf( "%ld.%06ld\n", dt.tv_sec, dt.tv_usec );
    }
    t0.tv_sec = t1.tv_sec;
    t0.tv_usec = t1.tv_usec;
  }
}

variable_types: flag int


decompiled_code:
__int64 __fastcall z80_line_disasm(__int64 a1, unsigned __int16 a2)
{
__int64 v2; // rbp
unsigned int v3; // er12
unsigned int v4; // er12
__int64 v5; // rsi
unsigned __int8 v7; // al
const char **v8; // rbp
unsigned int v9; // er15
unsigned __int8 v10; // bl
int v11; // er15
int v12; // er12
__int64 v13; // rsi
unsigned __int8 v14; // al
unsigned __int8 v15; // bl
unsigned __int8 v16; // al
unsigned __int8 v17; // r15
unsigned __int8 v18; // al
char v19; // al
char v20; // al
int v21; // er15
unsigned int v22; // er15
unsigned __int8 v23; // bl
const char **v24; // rbp
unsigned __int8 v25; // r12
unsigned __int8 v26; // bl
unsigned __int8 v27; // al
__int64 v28; // r8
char v29; // al
unsigned __int8 v30; // [rsp+Fh] [rbp-39h]

v2 = (*(unsigned __int8 (__fastcall **)(_QWORD))(a1 + 64))(a2);
v3 = Instruction[4 * v2];
switch ( v3 )
{
case 0u:
printf_head(a1, a2, 1);
v3 = 1;
printf((&off_9E68)[2 * v2]);
return v3;
case 1u:
v3 = 2;
v10 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 1));
printf_head(a1, a2, 2);
printf((&off_9E68)[2 * v2], v10);
return v3;
case 2u:
v11 = (*(unsigned __int8 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 1));
v12 = (*(unsigned __int8 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 2));
printf_head(a1, a2, 3);
v13 = (unsigned int)(v11 + (v12 << 8));
v3 = 3;
printf((&off_9E68)[2 * v2], v13);
return v3;
case 3u:
v4 = a2 + (*(char (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 1)) + 2;
printf_head(a1, a2, 2);
v5 = v4;
v3 = 2;
printf((&off_9E68)[2 * v2], v5);
return v3;
case 4u:
v7 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))(a2);
if ( v7 == 0xED )
{
v8 = (const char **)((char *)&Instruction_ED
+ 16 * (*(unsigned __int8 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 1)));
}
else if ( v7 > 0xEDu )
{
if ( v7 != 0xFD )
goto LABEL_26;
v8 = (const char **)((char *)&Instruction_FD
+ 16 * (*(unsigned __int8 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 1)));
}
else
{
if ( v7 != 0xCB )
{
if ( v7 == 0xDD )
{
v8 = (const char **)((char *)&Instruction_DD
+ 16 * (*(unsigned __int8 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 1)));
goto LABEL_9;
}
LABEL_26:
v3 = 2;
printf(" - Internal Error ! - ");
return v3;
}
v8 = (const char **)((char *)&Instruction_CB
+ 16 * (*(unsigned __int8 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 1)));
}
LABEL_9:
v9 = *(_DWORD *)v8;
switch ( *(_DWORD *)v8 )
{
case 0:
v3 = 2;
printf_head(a1, a2, 2);
printf(v8[1]);
return v3;
case 1:
v3 = 3;
v23 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 2));
printf_head(a1, a2, 3);
printf(v8[1], v23);
return v3;
case 2:
v21 = (*(unsigned __int8 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 2));
v22 = ((*(unsigned __int8 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 3)) << 8) + v21;
printf_head(a1, a2, 4);
printf(v8[1], v22);
return v3;
case 4:
v20 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))(a2);
if ( v20 == -35 )
{
v24 = (const char **)((char *)&Instruction_DD_CB
+ 16 * (*(unsigned __int8 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 3)));
}
else
{
if ( v20 != -3 )
{
v3 = v9;
printf(" - Internal Error - ");
return v3;
}
v24 = (const char **)((char *)&Instruction_FD_CB
+ 16 * (*(unsigned __int8 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 3)));
}
if ( *(_DWORD *)v24 == 5 )
{
v3 = v9;
printf_head(a1, a2, 4);
v29 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 2));
printf(v24[1], (unsigned int)v29);
}
else
{
if ( *(_DWORD *)v24 != 7 )
goto LABEL_13;
printf_head(a1, a2, 4);
v25 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 3));
v30 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 2));
v26 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 1));
v27 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))(a2);
v28 = v25;
v3 = v9;
printf(v24[1], v27, v26, v30, v28);
}
break;
case 5:
v3 = 3;
printf_head(a1, a2, 3);
v19 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 2));
printf(v8[1], (unsigned int)v19);
return v3;
case 6:
v17 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 3));
printf_head(a1, a2, 4);
v18 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 2));
printf(v8[1], v18, v17);
return v3;
case 7:
v3 = 2;
printf_head(a1, a2, 2);
v15 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 1));
v16 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))(a2);
printf(v8[1], v16, v15);
return v3;
case 8:
v3 = 1;
printf_head(a1, a2, 1);
v14 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))(a2);
printf(v8[1], v14);
return v3;
default:
goto LABEL_13;
}
return v3;
default:
LABEL_13:
v3 = 1;
printf(" - Internal Error - ");
return v3;
}
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned __int16 a2)
{
__int64 v2; // rbp
unsigned int v3; // er12
unsigned int v4; // er12
__int64 v5; // rsi
unsigned __int8 v7; // al
const char **v8; // rbp
unsigned int v9; // er15
unsigned __int8 v10; // bl
int v11; // er15
int v12; // er12
__int64 v13; // rsi
unsigned __int8 v14; // al
unsigned __int8 v15; // bl
unsigned __int8 v16; // al
unsigned __int8 v17; // r15
unsigned __int8 v18; // al
char v19; // al
char v20; // al
int v21; // er15
unsigned int v22; // er15
unsigned __int8 v23; // bl
const char **v24; // rbp
unsigned __int8 v25; // r12
unsigned __int8 v26; // bl
unsigned __int8 v27; // al
__int64 v28; // r8
char v29; // al
unsigned __int8 v30; // [rsp+Fh] [rbp-39h]

v2 = (*(unsigned __int8 (__fastcall **)(_QWORD))(a1 + 64))(a2);
v3 = Instruction[4 * v2];
switch ( v3 )
{
case 0u:
func0(a1, a2, 1);
v3 = 1;
printf((&off_9E68)[2 * v2]);
return v3;
case 1u:
v3 = 2;
v10 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 1));
func0(a1, a2, 2);
printf((&off_9E68)[2 * v2], v10);
return v3;
case 2u:
v11 = (*(unsigned __int8 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 1));
v12 = (*(unsigned __int8 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 2));
func0(a1, a2, 3);
v13 = (unsigned int)(v11 + (v12 << 8));
v3 = 3;
printf((&off_9E68)[2 * v2], v13);
return v3;
case 3u:
v4 = a2 + (*(char (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 1)) + 2;
func0(a1, a2, 2);
v5 = v4;
v3 = 2;
printf((&off_9E68)[2 * v2], v5);
return v3;
case 4u:
v7 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))(a2);
if ( v7 == 0xED )
{
v8 = (const char **)((char *)&Instruction_ED
+ 16 * (*(unsigned __int8 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 1)));
}
else if ( v7 > 0xEDu )
{
if ( v7 != 0xFD )
goto LABEL_26;
v8 = (const char **)((char *)&Instruction_FD
+ 16 * (*(unsigned __int8 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 1)));
}
else
{
if ( v7 != 0xCB )
{
if ( v7 == 0xDD )
{
v8 = (const char **)((char *)&Instruction_DD
+ 16 * (*(unsigned __int8 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 1)));
goto LABEL_9;
}
LABEL_26:
v3 = 2;
printf(" - Internal Error ! - ");
return v3;
}
v8 = (const char **)((char *)&Instruction_CB
+ 16 * (*(unsigned __int8 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 1)));
}
LABEL_9:
v9 = *(_DWORD *)v8;
switch ( *(_DWORD *)v8 )
{
case 0:
v3 = 2;
func0(a1, a2, 2);
printf(v8[1]);
return v3;
case 1:
v3 = 3;
v23 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 2));
func0(a1, a2, 3);
printf(v8[1], v23);
return v3;
case 2:
v21 = (*(unsigned __int8 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 2));
v22 = ((*(unsigned __int8 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 3)) << 8) + v21;
func0(a1, a2, 4);
printf(v8[1], v22);
return v3;
case 4:
v20 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))(a2);
if ( v20 == -35 )
{
v24 = (const char **)((char *)&Instruction_DD_CB
+ 16 * (*(unsigned __int8 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 3)));
}
else
{
if ( v20 != -3 )
{
v3 = v9;
printf(" - Internal Error - ");
return v3;
}
v24 = (const char **)((char *)&Instruction_FD_CB
+ 16 * (*(unsigned __int8 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 3)));
}
if ( *(_DWORD *)v24 == 5 )
{
v3 = v9;
func0(a1, a2, 4);
v29 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 2));
printf(v24[1], (unsigned int)v29);
}
else
{
if ( *(_DWORD *)v24 != 7 )
goto LABEL_13;
func0(a1, a2, 4);
v25 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 3));
v30 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 2));
v26 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 1));
v27 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))(a2);
v28 = v25;
v3 = v9;
printf(v24[1], v27, v26, v30, v28);
}
break;
case 5:
v3 = 3;
func0(a1, a2, 3);
v19 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 2));
printf(v8[1], (unsigned int)v19);
return v3;
case 6:
v17 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 3));
func0(a1, a2, 4);
v18 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 2));
printf(v8[1], v18, v17);
return v3;
case 7:
v3 = 2;
func0(a1, a2, 2);
v15 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 1));
v16 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))(a2);
printf(v8[1], v16, v15);
return v3;
case 8:
v3 = 1;
func0(a1, a2, 1);
v14 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))(a2);
printf(v8[1], v14);
return v3;
default:
goto LABEL_13;
}
return v3;
default:
LABEL_13:
v3 = 1;
printf(" - Internal Error - ");
return v3;
}
}

original_code:
int z80_line_disasm( z80arch *z80, word pc )
{
  int num;
  Mnemonics *Inst;
  Inst = &Instruction[ (z80->mem_read)(pc) ];
  switch( Inst->type ){
  case OP_NOTHING:
    printf_head( z80, pc, 1 );
    printf( Inst->str );
    return 1;
  case OP_NUM_8:
    num = (z80->mem_read)(pc+1);
    printf_head( z80, pc, 2 );
    printf( Inst->str, num );
    return 2;
  case OP_NUM_16:
    num = (z80->mem_read)(pc+1) + (z80->mem_read)(pc+2)*256;
    printf_head( z80, pc, 3 );
    printf( Inst->str, num );
    return 3;
  case OP_ADR_REL:
    num = pc +2 + (offset)(z80->mem_read)(pc+1);
    printf_head( z80, pc, 2 );
    printf( Inst->str, num );
    return 2;
  case OP_PREFIX:
    switch( (z80->mem_read)(pc) ){
    case 0xCB: Inst = &Instruction_CB[ (z80->mem_read)(pc+1) ]; break;
    case 0xDD: Inst = &Instruction_DD[ (z80->mem_read)(pc+1) ]; break;
    case 0xED: Inst = &Instruction_ED[ (z80->mem_read)(pc+1) ]; break;
    case 0xFD: Inst = &Instruction_FD[ (z80->mem_read)(pc+1) ]; break;
    default: printf(" - Internal Error ! - "); return 2;
    }
    switch( Inst->type ){
    case OP_NOTHING:
      printf_head( z80, pc, 2 );
      printf( Inst->str );
      return 2;
    case OP_UNEXIST:
      printf_head( z80, pc, 2 );
      printf( Inst->str, (z80->mem_read)(pc), (z80->mem_read)(pc+1) );
      return 2;
    case OP_SKIP:
      printf_head( z80, pc, 1 );
      printf( Inst->str, (z80->mem_read)(pc) );
      return 1;
    case OP_NUM_8:
      num = (z80->mem_read)(pc+2);
      printf_head( z80, pc, 3 );
      printf( Inst->str, num );
      return 3;
    case OP_NUM_16:
      num = (z80->mem_read)(pc+2) + (z80->mem_read)(pc+3)*256;
      printf_head( z80, pc, 4 );
      printf( Inst->str, num );
      return 4;
    case OP_INDEX:
      printf_head( z80, pc, 3 );
      printf( Inst->str, (offset)(z80->mem_read)(pc+2) );
      return 3;
    case OP_IDX_NUM:
      num = (int)(z80->mem_read)(pc+3);
      printf_head( z80, pc, 4 );
      printf( Inst->str, (int)(z80->mem_read)(pc+2) ,num );
      return 4;
    case OP_PREFIX:
      switch( (z80->mem_read)(pc) ){
      case 0xDD: Inst = &Instruction_DD_CB[ (z80->mem_read)(pc+3) ]; break;
      case 0xFD: Inst = &Instruction_FD_CB[ (z80->mem_read)(pc+3) ]; break;
      default: printf(" - Internal Error - "); return 4;
      }
      switch( Inst->type ){
      case OP_INDEX:
 printf_head( z80, pc, 4 );
 printf( Inst->str, (offset)(z80->mem_read)(pc+2) );
 return 4;
      case OP_UNEXIST:
 printf_head( z80, pc, 4 );
 printf( Inst->str, (z80->mem_read)(pc), (z80->mem_read)(pc+1),
                    (z80->mem_read)(pc+2),(z80->mem_read)(pc+3));
 return 4;
      }
      break;
    }
    break;
  }
  printf(" - Internal Error - ");
  return 1;
}

canonical_original_code:
int z80_line_disasm(struct z80arch *z80, unsigned short pc)
{
  int num;
  struct Mnemonics *Inst;
  Inst = &Instruction[ (z80->mem_read)(pc) ];
  switch( Inst->type ){
  case OP_NOTHING:
    printf_head( z80, pc, 1 );
    printf( Inst->str );
    return 1;
  case OP_NUM_8:
    num = (z80->mem_read)(pc+1);
    printf_head( z80, pc, 2 );
    printf( Inst->str, num );
    return 2;
  case OP_NUM_16:
    num = (z80->mem_read)(pc+1) + (z80->mem_read)(pc+2)*256;
    printf_head( z80, pc, 3 );
    printf( Inst->str, num );
    return 3;
  case OP_ADR_REL:
    num = pc +2 + (offset)(z80->mem_read)(pc+1);
    printf_head( z80, pc, 2 );
    printf( Inst->str, num );
    return 2;
  case OP_PREFIX:
    switch( (z80->mem_read)(pc) ){
    case 0xCB: Inst = &Instruction_CB[ (z80->mem_read)(pc+1) ]; break;
    case 0xDD: Inst = &Instruction_DD[ (z80->mem_read)(pc+1) ]; break;
    case 0xED: Inst = &Instruction_ED[ (z80->mem_read)(pc+1) ]; break;
    case 0xFD: Inst = &Instruction_FD[ (z80->mem_read)(pc+1) ]; break;
    default: printf(" - Internal Error ! - "); return 2;
    }
    switch( Inst->type ){
    case OP_NOTHING:
      printf_head( z80, pc, 2 );
      printf( Inst->str );
      return 2;
    case OP_UNEXIST:
      printf_head( z80, pc, 2 );
      printf( Inst->str, (z80->mem_read)(pc), (z80->mem_read)(pc+1) );
      return 2;
    case OP_SKIP:
      printf_head( z80, pc, 1 );
      printf( Inst->str, (z80->mem_read)(pc) );
      return 1;
    case OP_NUM_8:
      num = (z80->mem_read)(pc+2);
      printf_head( z80, pc, 3 );
      printf( Inst->str, num );
      return 3;
    case OP_NUM_16:
      num = (z80->mem_read)(pc+2) + (z80->mem_read)(pc+3)*256;
      printf_head( z80, pc, 4 );
      printf( Inst->str, num );
      return 4;
    case OP_INDEX:
      printf_head( z80, pc, 3 );
      printf( Inst->str, (offset)(z80->mem_read)(pc+2) );
      return 3;
    case OP_IDX_NUM:
      num = (int)(z80->mem_read)(pc+3);
      printf_head( z80, pc, 4 );
      printf( Inst->str, (int)(z80->mem_read)(pc+2) ,num );
      return 4;
    case OP_PREFIX:
      switch( (z80->mem_read)(pc) ){
      case 0xDD: Inst = &Instruction_DD_CB[ (z80->mem_read)(pc+3) ]; break;
      case 0xFD: Inst = &Instruction_FD_CB[ (z80->mem_read)(pc+3) ]; break;
      default: printf(" - Internal Error - "); return 4;
      }
      switch( Inst->type ){
      case OP_INDEX:
 printf_head( z80, pc, 4 );
 printf( Inst->str, (offset)(z80->mem_read)(pc+2) );
 return 4;
      case OP_UNEXIST:
 printf_head( z80, pc, 4 );
 printf( Inst->str, (z80->mem_read)(pc), (z80->mem_read)(pc+1),
                    (z80->mem_read)(pc+2),(z80->mem_read)(pc+3));
 return 4;
      }
      break;
    }
    break;
  }
  printf(" - Internal Error - ");
  return 1;
}

variable_types: struct z80arch { union pair { struct { unsigned char l; } B; unsigned short W; } AF; union pair IX; union pair AF1; unsigned char I; unsigned char R_saved; unsigned char IFF; unsigned char IM; unsigned char HALT; int INT_active; int icount; int state0; int skip_intr_chk; unsigned char log; unsigned char break_if_halt; unsigned char (*fetch)(unsigned short); unsigned char (*mem_read)(unsigned short); void (*mem_write)(unsigned short, unsigned char); unsigned char (*io_read)(unsigned char); void (*io_write)(unsigned char, unsigned char); void (*intr_update)(); int (*intr_ack)(); union pair PC_prev; } *

variable_types:
pc
unsigned short

variable_types: num int

variable_types: struct Mnemonics { int type; char *str; } *

user_defined_types: struct z80arch { union pair AF; union pair IX; union pair AF1; unsigned char I; unsigned char R_saved; unsigned char IFF; unsigned char IM; unsigned char HALT; int INT_active; int icount; int state0; int skip_intr_chk; unsigned char log; unsigned char break_if_halt; unsigned char (*fetch)(unsigned short); unsigned char (*mem_read)(unsigned short); void (*mem_write)(unsigned short, unsigned char); unsigned char (*io_read)(unsigned char); void (*io_write)(unsigned char, unsigned char); void (*intr_update)(); int (*intr_ack)(); union pair PC_prev; }


variable_types:
mes
char *

variable_types:
flags
char [8]

variable_types:
fbuf
char [10]

variable_types: i int

variable_types: j int

user_defined_types: union pair { struct { unsigned char l; } B; unsigned short W; }


decompiled_code:
int __fastcall printf_head(__int64 a1, unsigned __int16 a2, int a3)
{
unsigned __int8 v4; // al
int result; // eax
unsigned __int8 v6; // bp
unsigned __int8 v7; // bl
unsigned __int8 v8; // al
unsigned __int8 v9; // bl
unsigned __int8 v10; // al
unsigned __int8 v11; // r13
unsigned __int8 v12; // bp
unsigned __int8 v13; // bl
unsigned __int8 v14; // al

printf("%04X ", a2);
switch ( a3 )
{
case 3:
v6 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 2));
v7 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 1));
v8 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))(a2);
result = printf("%02X%02X%02X ", v8, v7, v6);
break;
case 4:
v11 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 3));
v12 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 2));
v13 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 1));
v14 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))(a2);
result = printf("%02X%02X%02X%02X ", v14, v13, v12, v11);
break;
case 2:
v9 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 1));
v10 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))(a2);
result = printf("%02X%02X ", v10, v9);
break;
default:
v4 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))(a2);
result = printf("%02X ", v4);
break;
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, unsigned __int16 a2, int a3)
{
unsigned __int8 v4; // al
int result; // eax
unsigned __int8 v6; // bp
unsigned __int8 v7; // bl
unsigned __int8 v8; // al
unsigned __int8 v9; // bl
unsigned __int8 v10; // al
unsigned __int8 v11; // r13
unsigned __int8 v12; // bp
unsigned __int8 v13; // bl
unsigned __int8 v14; // al

printf("%04X ", a2);
switch ( a3 )
{
case 3:
v6 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 2));
v7 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 1));
v8 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))(a2);
result = printf("%02X%02X%02X ", v8, v7, v6);
break;
case 4:
v11 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 3));
v12 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 2));
v13 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 1));
v14 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))(a2);
result = printf("%02X%02X%02X%02X ", v14, v13, v12, v11);
break;
case 2:
v9 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))((unsigned __int16)(a2 + 1));
v10 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))(a2);
result = printf("%02X%02X ", v10, v9);
break;
default:
v4 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 64))(a2);
result = printf("%02X ", v4);
break;
}
return result;
}

original_code:
static void printf_head( z80arch *z80, word pc, int num )
{
  printf("%04X ",pc);
  switch( num ){
  case 1:
    printf("%02X       ", (z80->mem_read)(pc));
    break;
  case 2:
    printf("%02X%02X     ", (z80->mem_read)(pc), (z80->mem_read)(pc+1));
    break;
  case 3:
    printf("%02X%02X%02X   ", (z80->mem_read)(pc), (z80->mem_read)(pc+1),
                        (z80->mem_read)(pc+2));
    break;
  case 4:
    printf("%02X%02X%02X%02X ",(z80->mem_read)(pc), (z80->mem_read)(pc+1),
                        (z80->mem_read)(pc+2),(z80->mem_read)(pc+3));
    break;
  default:
    printf("Internal Error -");
    break;
  }
}

canonical_original_code:
static void printf_head(struct z80arch *z80, unsigned short pc, int num)
{
  printf("%04X ",pc);
  switch( num ){
  case 1:
    printf("%02X       ", (z80->mem_read)(pc));
    break;
  case 2:
    printf("%02X%02X     ", (z80->mem_read)(pc), (z80->mem_read)(pc+1));
    break;
  case 3:
    printf("%02X%02X%02X   ", (z80->mem_read)(pc), (z80->mem_read)(pc+1),
                        (z80->mem_read)(pc+2));
    break;
  case 4:
    printf("%02X%02X%02X%02X ",(z80->mem_read)(pc), (z80->mem_read)(pc+1),
                        (z80->mem_read)(pc+2),(z80->mem_read)(pc+3));
    break;
  default:
    printf("Internal Error -");
    break;
  }
}


variable_types: struct SYSTEM_PALETTE_T { unsigned char red; unsigned char green; unsigned char blue; unsigned char padding; } [16]

variable_types:
pal
struct { int pal; int col; } [16]


decompiled_code:
void menu_set_status()
{
menu_draw_force = 1;
}

canonical_decompiled_code:
void func1()
{
menu_draw_force = 1;
}

original_code:
void menu_set_status( void )
{
  menu_draw_force = (1);
}

canonical_original_code:
void menu_set_status()
{
  menu_draw_force = (1);
}


decompiled_code:
void menu_trans_palette()
{
menu_need_trans_palette = 1;
}

canonical_decompiled_code:
void func2()
{
menu_need_trans_palette = 1;
}

original_code:
void menu_trans_palette( void )
{
  menu_need_trans_palette = (1);
}

canonical_original_code:
void menu_trans_palette()
{
  menu_need_trans_palette = (1);
}


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

if ( menu_need_trans_palette )
{
menu_palette();
menu_need_trans_palette = 0;
}
if ( menu_draw_force )
{
result = draw_menu_screen_force();
menu_screen_current ^= 1u;
menu_draw_force = 0;
}
else
{
result = draw_menu_screen();
menu_screen_current ^= 1u;
}
return result;
}

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

if ( menu_need_trans_palette )
{
func0();
menu_need_trans_palette = 0;
}
if ( menu_draw_force )
{
result = draw_menu_screen_force();
menu_screen_current ^= 1u;
menu_draw_force = 0;
}
else
{
result = draw_menu_screen();
menu_screen_current ^= 1u;
}
return result;
}

original_code:
void menu_draw_screen( void )
{
  if( menu_need_trans_palette ){
    menu_palette();
    menu_need_trans_palette = (0);
  }
  if( menu_draw_force ){
    draw_menu_screen_force();
    menu_draw_force = (0);
  }else{
    draw_menu_screen();
  }
  menu_screen_current ^= 1;
}

canonical_original_code:
void menu_draw_screen()
{
  if( menu_need_trans_palette ){
    menu_palette();
    menu_need_trans_palette = (0);
  }
  if( menu_draw_force ){
    draw_menu_screen_force();
    menu_draw_force = (0);
  }else{
    draw_menu_screen();
  }
  menu_screen_current ^= 1;
}


decompiled_code:
__int64 __fastcall YM_DELTAT_ADPCM_Read(__int64 a1)
{
__int64 result; // rax
unsigned int v2; // edx
void (__fastcall *v3)(_QWORD); // r8
unsigned __int8 v4; // [rsp+1h] [rbp-9h]

result = *(unsigned __int8 *)(a1 + 93);
if ( (_BYTE)result )
{
*(_BYTE *)(a1 + 93) = result - 1;
return 0LL;
}
v2 = *(_DWORD *)(a1 + 40);
v3 = *(void (__fastcall **)(_QWORD))(a1 + 96);
if ( v2 == 2 * *(_DWORD *)(a1 + 60) )
{
if ( v3 && *(_BYTE *)(a1 + 113) )
goto LABEL_5;
}
else
{
result = *(unsigned __int8 *)(*(_QWORD *)a1 + (v2 >> 1));
*(_DWORD *)(a1 + 40) = v2 + 2;
if ( v3 && *(_BYTE *)(a1 + 114) )
{
LABEL_5:
v4 = result;
v3(*(unsigned __int8 *)(a1 + 112));
return v4;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 result; // rax
unsigned int v2; // edx
void (__fastcall *v3)(_QWORD); // r8
unsigned __int8 v4; // [rsp+1h] [rbp-9h]

result = *(unsigned __int8 *)(a1 + 93);
if ( (_BYTE)result )
{
*(_BYTE *)(a1 + 93) = result - 1;
return 0LL;
}
v2 = *(_DWORD *)(a1 + 40);
v3 = *(void (__fastcall **)(_QWORD))(a1 + 96);
if ( v2 == 2 * *(_DWORD *)(a1 + 60) )
{
if ( v3 && *(_BYTE *)(a1 + 113) )
goto LABEL_5;
}
else
{
result = *(unsigned __int8 *)(*(_QWORD *)a1 + (v2 >> 1));
*(_DWORD *)(a1 + 40) = v2 + 2;
if ( v3 && *(_BYTE *)(a1 + 114) )
{
LABEL_5:
v4 = result;
v3(*(unsigned __int8 *)(a1 + 112));
return v4;
}
}
return result;
}

original_code:
UINT8 YM_DELTAT_ADPCM_Read(YM_DELTAT *DELTAT)
{
 UINT8 v = 0;
 if (DELTAT->memread)
 {
  DELTAT->memread--;
  return 0;
 }
 if ( DELTAT->now_addr != (DELTAT->end<<1) )
 {
  v = DELTAT->memory[DELTAT->now_addr>>1];
  DELTAT->now_addr+=2;
  if(DELTAT->status_set_handler)
   if(DELTAT->status_change_BRDY_bit)
    (DELTAT->status_set_handler)(DELTAT->status_change_which_chip, DELTAT->status_change_BRDY_bit);
 }
 else
 {
  if(DELTAT->status_set_handler)
   if(DELTAT->status_change_EOS_bit)
    (DELTAT->status_set_handler)(DELTAT->status_change_which_chip, DELTAT->status_change_EOS_bit);
 }
 return v;
}

canonical_original_code:
unsigned char YM_DELTAT_ADPCM_Read(struct deltat_adpcm_state *DELTAT)
{
 unsigned char v = 0;
 if (DELTAT->memread)
 {
  DELTAT->memread--;
  return 0;
 }
 if ( DELTAT->now_addr != (DELTAT->end<<1) )
 {
  v = DELTAT->memory[DELTAT->now_addr>>1];
  DELTAT->now_addr+=2;
  if(DELTAT->status_set_handler)
   if(DELTAT->status_change_BRDY_bit)
    (DELTAT->status_set_handler)(DELTAT->status_change_which_chip, DELTAT->status_change_BRDY_bit);
 }
 else
 {
  if(DELTAT->status_set_handler)
   if(DELTAT->status_change_EOS_bit)
    (DELTAT->status_set_handler)(DELTAT->status_change_which_chip, DELTAT->status_change_EOS_bit);
 }
 return v;
}

variable_types: struct deltat_adpcm_state { unsigned char *memory; int *output_pointer; int *pan; double freqbase; unsigned int memory_size; int output_range; unsigned int now_addr; unsigned int now_step; unsigned int step; unsigned int start; unsigned int limit; unsigned int end; unsigned int delta; int volume; int acc; int adpcmd; int adpcml; int prev_acc; unsigned char now_data; unsigned char portstate; unsigned char control2; unsigned char portshift; unsigned char DRAMportshift; unsigned char memread; void (*status_set_handler)(unsigned char which_chip, unsigned char status_bits); void (*status_reset_handler)(unsigned char which_chip, unsigned char status_bits); unsigned char status_change_which_chip; unsigned char status_change_EOS_bit; unsigned char status_change_BRDY_bit; unsigned char status_change_ZERO_bit; unsigned char PCM_BSY; unsigned char reg[16]; } *

variable_types:
v
unsigned char


original_code:
void YM_DELTAT_ADPCM_Write(YM_DELTAT *DELTAT,int r,int v)
{
 if(r>=0x10) return;
 DELTAT->reg[r] = v;
 switch( r )
 {
 case 0x00:
  DELTAT->portstate = v & (0x80|0x40|0x20|0x10);
  if( DELTAT->portstate&0x80 )
  {
   DELTAT->PCM_BSY = 1;
   DELTAT->now_step = 0;
   DELTAT->acc = 0;
   DELTAT->prev_acc = 0;
   DELTAT->adpcml = 0;
   DELTAT->adpcmd = (127);
  }
  if( DELTAT->portstate&0x20 )
  {
   DELTAT->now_addr = DELTAT->start << 1;
   DELTAT->memread = 2;
   if(DELTAT->memory == 0)
   {
    logerror("YM Delta-T ADPCM rom not mapped\n");
    DELTAT->portstate = 0x00;
    DELTAT->PCM_BSY = 0;
   }
   else
   {
    if( DELTAT->end >= DELTAT->memory_size )
    {
     logerror("YM Delta-T ADPCM end out of range: $%08x\n", DELTAT->end);
     DELTAT->end = DELTAT->memory_size - 1;
    }
    if( DELTAT->start >= DELTAT->memory_size )
    {
     logerror("YM Delta-T ADPCM start out of range: $%08x\n", DELTAT->start);
     DELTAT->portstate = 0x00;
     DELTAT->PCM_BSY = 0;
    }
   }
  }
  else
  {
   DELTAT->now_addr = 0;
  }
  if( v & 0x01 )
  {
   DELTAT->portstate = 0x00;
   DELTAT->PCM_BSY = 0;
  }
  break;
 case 0x01:
  DELTAT->pan = &DELTAT->output_pointer[(v>>6)&0x03];
  if ((DELTAT->control2 & 3) != (v & 3))
  {
   static UINT8 dram_rightshift[4]={3,0,0,0};
   if (DELTAT->DRAMportshift != dram_rightshift[v&3])
   {
    DELTAT->DRAMportshift = dram_rightshift[v&3];
    DELTAT->start = (DELTAT->reg[0x3]*0x0100 | DELTAT->reg[0x2]) << (DELTAT->portshift - DELTAT->DRAMportshift);
    DELTAT->end = (DELTAT->reg[0x5]*0x0100 | DELTAT->reg[0x4]) << (DELTAT->portshift - DELTAT->DRAMportshift);
    DELTAT->end += (1 << (DELTAT->portshift-DELTAT->DRAMportshift) ) - 1;
    DELTAT->limit = (DELTAT->reg[0xd]*0x0100 | DELTAT->reg[0xc]) << (DELTAT->portshift - DELTAT->DRAMportshift);
    DELTAT->limit += (1 << (DELTAT->portshift-DELTAT->DRAMportshift) ) - 1;
   }
  }
  DELTAT->control2 = v;
  break;
 case 0x02:
 case 0x03:
  DELTAT->start = (DELTAT->reg[0x3]*0x0100 | DELTAT->reg[0x2]) << (DELTAT->portshift - DELTAT->DRAMportshift);
  break;
 case 0x04:
 case 0x05:
  DELTAT->end = (DELTAT->reg[0x5]*0x0100 | DELTAT->reg[0x4]) << (DELTAT->portshift - DELTAT->DRAMportshift);
  DELTAT->end += (1 << (DELTAT->portshift-DELTAT->DRAMportshift) ) - 1;
  break;
 case 0x06:
 case 0x07:
  break;
 case 0x08:
  if ( (DELTAT->portstate & 0xe0)==0x60 )
  {
   if ( DELTAT->now_addr != (DELTAT->end<<1) )
   {
    DELTAT->memory[DELTAT->now_addr>>1] = v;
     DELTAT->now_addr+=2;
    if(DELTAT->status_set_handler)
     if(DELTAT->status_change_BRDY_bit)
      (DELTAT->status_set_handler)(DELTAT->status_change_which_chip, DELTAT->status_change_BRDY_bit);
   }
   else
   {
    if(DELTAT->status_set_handler)
     if(DELTAT->status_change_EOS_bit)
      (DELTAT->status_set_handler)(DELTAT->status_change_which_chip, DELTAT->status_change_EOS_bit);
   }
            return;
  }
  if ( (DELTAT->portstate & 0xe0)==0x80 )
  {
   DELTAT->now_data = v;
   return;
  }
   break;
 case 0x09:
 case 0x0a:
  DELTAT->delta = (DELTAT->reg[0xa]*0x0100 | DELTAT->reg[0x9]);
  DELTAT->step = (UINT32)( (double)(DELTAT->delta ) * (DELTAT->freqbase) );
  break;
 case 0x0b:
  {
   INT32 oldvol = DELTAT->volume;
   DELTAT->volume = (v&0xff) * (DELTAT->output_range/256) / 32768;
   if( oldvol != 0 )
   {
    DELTAT->adpcml = (int)((double)DELTAT->adpcml / (double)oldvol * (double)DELTAT->volume);
   }
  }
  break;
 case 0x0c:
 case 0x0d:
  DELTAT->limit = (DELTAT->reg[0xd]*0x0100 | DELTAT->reg[0xc]) << (DELTAT->portshift - DELTAT->DRAMportshift);
  DELTAT->limit += (1 << (DELTAT->portshift-DELTAT->DRAMportshift) ) - 1;
  break;
 }
}

canonical_original_code:
void YM_DELTAT_ADPCM_Write(struct deltat_adpcm_state *DELTAT, int r, int v)
{
 if(r>=0x10) return;
 DELTAT->reg[r] = v;
 switch( r )
 {
 case 0x00:
  DELTAT->portstate = v & (0x80|0x40|0x20|0x10);
  if( DELTAT->portstate&0x80 )
  {
   DELTAT->PCM_BSY = 1;
   DELTAT->now_step = 0;
   DELTAT->acc = 0;
   DELTAT->prev_acc = 0;
   DELTAT->adpcml = 0;
   DELTAT->adpcmd = (127);
  }
  if( DELTAT->portstate&0x20 )
  {
   DELTAT->now_addr = DELTAT->start << 1;
   DELTAT->memread = 2;
   if(DELTAT->memory == 0)
   {
    logerror("YM Delta-T ADPCM rom not mapped\n");
    DELTAT->portstate = 0x00;
    DELTAT->PCM_BSY = 0;
   }
   else
   {
    if( DELTAT->end >= DELTAT->memory_size )
    {
     logerror("YM Delta-T ADPCM end out of range: $%08x\n", DELTAT->end);
     DELTAT->end = DELTAT->memory_size - 1;
    }
    if( DELTAT->start >= DELTAT->memory_size )
    {
     logerror("YM Delta-T ADPCM start out of range: $%08x\n", DELTAT->start);
     DELTAT->portstate = 0x00;
     DELTAT->PCM_BSY = 0;
    }
   }
  }
  else
  {
   DELTAT->now_addr = 0;
  }
  if( v & 0x01 )
  {
   DELTAT->portstate = 0x00;
   DELTAT->PCM_BSY = 0;
  }
  break;
 case 0x01:
  DELTAT->pan = &DELTAT->output_pointer[(v>>6)&0x03];
  if ((DELTAT->control2 & 3) != (v & 3))
  {
   static unsigned char dram_rightshift[4] = {3,0,0,0};
   if (DELTAT->DRAMportshift != dram_rightshift[v&3])
   {
    DELTAT->DRAMportshift = dram_rightshift[v&3];
    DELTAT->start = (DELTAT->reg[0x3]*0x0100 | DELTAT->reg[0x2]) << (DELTAT->portshift - DELTAT->DRAMportshift);
    DELTAT->end = (DELTAT->reg[0x5]*0x0100 | DELTAT->reg[0x4]) << (DELTAT->portshift - DELTAT->DRAMportshift);
    DELTAT->end += (1 << (DELTAT->portshift-DELTAT->DRAMportshift) ) - 1;
    DELTAT->limit = (DELTAT->reg[0xd]*0x0100 | DELTAT->reg[0xc]) << (DELTAT->portshift - DELTAT->DRAMportshift);
    DELTAT->limit += (1 << (DELTAT->portshift-DELTAT->DRAMportshift) ) - 1;
   }
  }
  DELTAT->control2 = v;
  break;
 case 0x02:
 case 0x03:
  DELTAT->start = (DELTAT->reg[0x3]*0x0100 | DELTAT->reg[0x2]) << (DELTAT->portshift - DELTAT->DRAMportshift);
  break;
 case 0x04:
 case 0x05:
  DELTAT->end = (DELTAT->reg[0x5]*0x0100 | DELTAT->reg[0x4]) << (DELTAT->portshift - DELTAT->DRAMportshift);
  DELTAT->end += (1 << (DELTAT->portshift-DELTAT->DRAMportshift) ) - 1;
  break;
 case 0x06:
 case 0x07:
  break;
 case 0x08:
  if ( (DELTAT->portstate & 0xe0)==0x60 )
  {
   if ( DELTAT->now_addr != (DELTAT->end<<1) )
   {
    DELTAT->memory[DELTAT->now_addr>>1] = v;
     DELTAT->now_addr+=2;
    if(DELTAT->status_set_handler)
     if(DELTAT->status_change_BRDY_bit)
      (DELTAT->status_set_handler)(DELTAT->status_change_which_chip, DELTAT->status_change_BRDY_bit);
   }
   else
   {
    if(DELTAT->status_set_handler)
     if(DELTAT->status_change_EOS_bit)
      (DELTAT->status_set_handler)(DELTAT->status_change_which_chip, DELTAT->status_change_EOS_bit);
   }
            return;
  }
  if ( (DELTAT->portstate & 0xe0)==0x80 )
  {
   DELTAT->now_data = v;
   return;
  }
   break;
 case 0x09:
 case 0x0a:
  DELTAT->delta = (DELTAT->reg[0xa]*0x0100 | DELTAT->reg[0x9]);
  DELTAT->step = (UINT32)( (double)(DELTAT->delta ) * (DELTAT->freqbase) );
  break;
 case 0x0b:
  {
   int oldvol = DELTAT->volume;
   DELTAT->volume = (v&0xff) * (DELTAT->output_range/256) / 32768;
   if( oldvol != 0 )
   {
    DELTAT->adpcml = (int)((double)DELTAT->adpcml / (double)oldvol * (double)DELTAT->volume);
   }
  }
  break;
 case 0x0c:
 case 0x0d:
  DELTAT->limit = (DELTAT->reg[0xd]*0x0100 | DELTAT->reg[0xc]) << (DELTAT->portshift - DELTAT->DRAMportshift);
  DELTAT->limit += (1 << (DELTAT->portshift-DELTAT->DRAMportshift) ) - 1;
  break;
 }
}

variable_types: r int

variable_types: v int

variable_types: oldvol int

user_defined_types: struct deltat_adpcm_state { unsigned char *memory; int *output_pointer; int *pan; double freqbase; unsigned int memory_size; int output_range; unsigned int now_addr; unsigned int now_step; unsigned int step; unsigned int start; unsigned int limit; unsigned int end; unsigned int delta; int volume; int acc; int adpcmd; int adpcml; int prev_acc; unsigned char now_data; unsigned char portstate; unsigned char control2; unsigned char portshift; unsigned char DRAMportshift; unsigned char memread; void (*status_set_handler)(unsigned char which_chip, unsigned char status_bits); void (*status_reset_handler)(unsigned char which_chip, unsigned char status_bits); unsigned char status_change_which_chip; unsigned char status_change_EOS_bit; unsigned char status_change_BRDY_bit; unsigned char status_change_ZERO_bit; unsigned char PCM_BSY; unsigned char reg[16]; }


original_code:
void YM_DELTAT_ADPCM_Reset(YM_DELTAT *DELTAT,int pan)
{
 DELTAT->now_addr = 0;
 DELTAT->now_step = 0;
 DELTAT->step = 0;
 DELTAT->start = 0;
 DELTAT->end = 0;
 DELTAT->limit = ~0;
 DELTAT->volume = 0;
 DELTAT->pan = &DELTAT->output_pointer[pan];
 DELTAT->acc = 0;
 DELTAT->prev_acc = 0;
 DELTAT->adpcmd = 127;
 DELTAT->adpcml = 0;
 DELTAT->portstate = 0;
 DELTAT->DRAMportshift = 3;
 DELTAT->control2 = 0;
}

canonical_original_code:
void YM_DELTAT_ADPCM_Reset(struct deltat_adpcm_state *DELTAT, int pan)
{
 DELTAT->now_addr = 0;
 DELTAT->now_step = 0;
 DELTAT->step = 0;
 DELTAT->start = 0;
 DELTAT->end = 0;
 DELTAT->limit = ~0;
 DELTAT->volume = 0;
 DELTAT->pan = &DELTAT->output_pointer[pan];
 DELTAT->acc = 0;
 DELTAT->prev_acc = 0;
 DELTAT->adpcmd = 127;
 DELTAT->adpcml = 0;
 DELTAT->portstate = 0;
 DELTAT->DRAMportshift = 3;
 DELTAT->control2 = 0;
}

variable_types: pan int


uclock

decompiled_code:
__suseconds_t uclock()
{
__suseconds_t result; // rax
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
if ( init_sec_0 )
return v1.tv_usec + 1000000 * (v1.tv_sec - init_sec_0);
result = v1.tv_usec + init_sec_0;
init_sec_0 = v1.tv_sec;
return result;
}

canonical_decompiled_code:
__suseconds_t func0()
{
__suseconds_t result; // rax
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
if ( init_sec_0 )
return v1.tv_usec + 1000000 * (v1.tv_sec - init_sec_0);
result = v1.tv_usec + init_sec_0;
init_sec_0 = v1.tv_sec;
return result;
}

original_code:
uclock_t uclock(void)
{
  static uclock_t init_sec = 0;
  struct timeval tv;
  gettimeofday(&tv, 0);
  if (init_sec == 0) init_sec = tv.tv_sec;
  return (tv.tv_sec - init_sec) * 1000000 + tv.tv_usec;
}

canonical_original_code:
long uclock()
{
  static long init_sec = 0;
  struct timeval tv;
  gettimeofday(&tv, 0);
  if (init_sec == 0) init_sec = tv.tv_sec;
  return (tv.tv_sec - init_sec) * 1000000 + tv.tv_usec;
}

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


decompiled_code:
int __fastcall print_columns(char *s, __int64 a2)
{
return fprint_columns(stdout, s, a2);
}

canonical_decompiled_code:
int __fastcall func2(char *s, __int64 a2)
{
return func1(stdout, s, a2);
}

original_code:
void print_columns(const char *text1, const char *text2)
{
   fprint_columns(stdout, text1, text2);
}

canonical_original_code:
void print_columns(char *text1, char *text2)
{
   fprint_columns(stdout, text1, text2);
}


main

canonical_name: main

decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
const char *v4; // r15
const char **v5; // rbx
const char ***v6; // rax
bool v7; // cf
bool v8; // zf
int v9; // er9
const char **v10; // r11
const char **v11; // r8
__int64 v12; // rcx
FILE *v13; // r14
FILE *v14; // rbp
int v15; // ebx
int v16; // er13
const char *v18; // rcx
__int16 ptr; // [rsp+8h] [rbp-40h] BYREF
__int16 v20; // [rsp+Ah] [rbp-3Eh]
__int16 v21; // [rsp+Ch] [rbp-3Ch]
__int16 v22; // [rsp+Eh] [rbp-3Ah]

if ( argc == 1 )
LABEL_34:
help(*(_QWORD *)&argc, argv, envp);
if ( argc <= 1 )
goto LABEL_37;
envp = (const char **)(unsigned int)(argc - 2);
v5 = argv;
v6 = (const char ***)(argv + 1);
v7 = 0;
v8 = 1;
v9 = 0;
v10 = &argv[(_QWORD)envp + 2];
do
{
while ( 1 )
{
v11 = *v6;
v12 = 6LL;
*(_QWORD *)&argc = "-help";
argv = *v6;
do
{
if ( !v12 )
break;
v7 = *(_BYTE *)argv < **(_BYTE **)&argc;
v8 = *(_BYTE *)argv == **(_BYTE **)&argc;
argv = (const char **)((char *)argv + 1);
++*(_QWORD *)&argc;
--v12;
}
while ( v8 );
LOBYTE(envp) = (!v7 && !v8) - v7;
if ( !(_BYTE)envp )
goto LABEL_34;
if ( *(_BYTE *)v11 == 45 )
{
fwrite("Unknown option.\n", 1uLL, 0x10uLL, stderr);
exit(1);
}
if ( v9 )
break;
++v6;
v4 = (const char *)v11;
v9 = 1;
v7 = v6 < (const char ***)v10;
v8 = v6 == (const char ***)v10;
if ( v6 == (const char ***)v10 )
goto LABEL_13;
}
if ( v9 != 1 )
{
fwrite("Bad argument ( Too many argument ).\n", 1uLL, 0x24uLL, stderr);
exit(1);
}
++v6;
v3 = (const char *)v11;
v9 = 2;
v7 = v6 < (const char ***)v10;
v8 = v6 == (const char ***)v10;
}
while ( v6 != (const char ***)v10 );
LABEL_13:
if ( v9 != 2 )
{
LABEL_37:
fwrite("Bad argument ( Too short argument ).\n", 1uLL, 0x25uLL, stderr);
exit(1);
}
v13 = fopen(v4, "rb");
if ( !v13 )
{
v18 = v4;
goto LABEL_39;
}
v14 = fopen(v3, "wb");
if ( !v14 )
{
v18 = v3;
LABEL_39:
fprintf(stderr, "\n%s: Can't open file %s\n", *v5, v18);
exit(1);
}
v15 = fseek(v13, 4096LL, 0);
if ( v15 )
error(0LL, v4);
v16 = 256;
do
{
if ( fread(&ptr, 1uLL, 8uLL, v13) != 8 )
error(1LL, v4);
if ( fwrite(&ptr, 1uLL, 8uLL, v14) != 8 )
LABEL_32:
error(2LL, v3);
--v16;
}
while ( v16 );
do
{
ptr = -(v15 & 1) & 0xF0F0;
v20 = ((__int16)((_WORD)v15 << 14) >> 15) & 0xF0F0;
v21 = ((__int16)((_WORD)v15 << 13) >> 15) & 0xF0F0;
v22 = ((__int16)((_WORD)v15 << 12) >> 15) & 0xF0F0;
if ( (v15 & 0x10) != 0 )
{
HIBYTE(ptr) |= 0xFu;
LOBYTE(ptr) = HIBYTE(ptr);
}
if ( (v15 & 0x20) != 0 )
{
HIBYTE(v20) |= 0xFu;
LOBYTE(v20) = HIBYTE(v20);
}
if ( (v15 & 0x40) != 0 )
{
HIBYTE(v21) |= 0xFu;
LOBYTE(v21) = HIBYTE(v21);
}
if ( (v15 & 0x80u) != 0 )
{
HIBYTE(v22) |= 0xFu;
LOBYTE(v22) = HIBYTE(v22);
}
if ( fwrite(&ptr, 1uLL, 8uLL, v14) != 8 )
goto LABEL_32;
++v15;
}
while ( v15 != 256 );
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
const char *v4; // r15
const char **v5; // rbx
const char ***v6; // rax
bool v7; // cf
bool v8; // zf
int v9; // er9
const char **v10; // r11
const char **v11; // r8
__int64 v12; // rcx
FILE *v13; // r14
FILE *v14; // rbp
int v15; // ebx
int v16; // er13
const char *v18; // rcx
__int16 ptr; // [rsp+8h] [rbp-40h] BYREF
__int16 v20; // [rsp+Ah] [rbp-3Eh]
__int16 v21; // [rsp+Ch] [rbp-3Ch]
__int16 v22; // [rsp+Eh] [rbp-3Ah]

if ( argc == 1 )
LABEL_34:
func7(*(_QWORD *)&argc, argv, envp);
if ( argc <= 1 )
goto LABEL_37;
envp = (const char **)(unsigned int)(argc - 2);
v5 = argv;
v6 = (const char ***)(argv + 1);
v7 = 0;
v8 = 1;
v9 = 0;
v10 = &argv[(_QWORD)envp + 2];
do
{
while ( 1 )
{
v11 = *v6;
v12 = 6LL;
*(_QWORD *)&argc = "-help";
argv = *v6;
do
{
if ( !v12 )
break;
v7 = *(_BYTE *)argv < **(_BYTE **)&argc;
v8 = *(_BYTE *)argv == **(_BYTE **)&argc;
argv = (const char **)((char *)argv + 1);
++*(_QWORD *)&argc;
--v12;
}
while ( v8 );
LOBYTE(envp) = (!v7 && !v8) - v7;
if ( !(_BYTE)envp )
goto LABEL_34;
if ( *(_BYTE *)v11 == 45 )
{
fwrite("Unknown option.\n", 1uLL, 0x10uLL, stderr);
exit(1);
}
if ( v9 )
break;
++v6;
v4 = (const char *)v11;
v9 = 1;
v7 = v6 < (const char ***)v10;
v8 = v6 == (const char ***)v10;
if ( v6 == (const char ***)v10 )
goto LABEL_13;
}
if ( v9 != 1 )
{
fwrite("Bad argument ( Too many argument ).\n", 1uLL, 0x24uLL, stderr);
exit(1);
}
++v6;
v3 = (const char *)v11;
v9 = 2;
v7 = v6 < (const char ***)v10;
v8 = v6 == (const char ***)v10;
}
while ( v6 != (const char ***)v10 );
LABEL_13:
if ( v9 != 2 )
{
LABEL_37:
fwrite("Bad argument ( Too short argument ).\n", 1uLL, 0x25uLL, stderr);
exit(1);
}
v13 = fopen(v4, "rb");
if ( !v13 )
{
v18 = v4;
goto LABEL_39;
}
v14 = fopen(v3, "wb");
if ( !v14 )
{
v18 = v3;
LABEL_39:
fprintf(stderr, "\n%s: Can't open file %s\n", *v5, v18);
exit(1);
}
v15 = fseek(v13, 4096LL, 0);
if ( v15 )
func8(0LL, v4);
v16 = 256;
do
{
if ( fread(&ptr, 1uLL, 8uLL, v13) != 8 )
func8(1LL, v4);
if ( fwrite(&ptr, 1uLL, 8uLL, v14) != 8 )
LABEL_32:
func8(2LL, v3);
--v16;
}
while ( v16 );
do
{
ptr = -(v15 & 1) & 0xF0F0;
v20 = ((__int16)((_WORD)v15 << 14) >> 15) & 0xF0F0;
v21 = ((__int16)((_WORD)v15 << 13) >> 15) & 0xF0F0;
v22 = ((__int16)((_WORD)v15 << 12) >> 15) & 0xF0F0;
if ( (v15 & 0x10) != 0 )
{
HIBYTE(ptr) |= 0xFu;
LOBYTE(ptr) = HIBYTE(ptr);
}
if ( (v15 & 0x20) != 0 )
{
HIBYTE(v20) |= 0xFu;
LOBYTE(v20) = HIBYTE(v20);
}
if ( (v15 & 0x40) != 0 )
{
HIBYTE(v21) |= 0xFu;
LOBYTE(v21) = HIBYTE(v21);
}
if ( (v15 & 0x80u) != 0 )
{
HIBYTE(v22) |= 0xFu;
LOBYTE(v22) = HIBYTE(v22);
}
if ( fwrite(&ptr, 1uLL, 8uLL, v14) != 8 )
goto LABEL_32;
++v15;
}
while ( v15 != 256 );
return 0;
}

original_code:
int main( int argc, char *argv[] )
{
  int x = 1;
  x11_system_init();
  if( setuid( getuid() ) != 0 ){
    fprintf( stderr, "%s : setuid error\n", argv[0] );
    x11_system_term();
    return -1;
  }
  if( getuid() == 0 ) snapshot_cmd_enable = (0);
  if( *(char *)&x != 1 ){
    fprintf( stderr,
      "%s CAN'T EXCUTE !\n"
      "This machine is Big-Endian.\n"
      "Compile again comment-out 'LSB_FIRST = 1' in Makefile.\n",
      argv[0] );
    x11_system_term();
    return -1;
  }
  xmame_system_init();
  quasi88_atexit( the_end );
  if( osd_environment() ){
    if( config_init( argc, argv ) ){
      quasi88();
    }
  }
  xmame_system_term();
  x11_system_term();
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  int x = 1;
  x11_system_init();
  if( setuid( getuid() ) != 0 ){
    fprintf( stderr, "%s : setuid error\n", argv[0] );
    x11_system_term();
    return -1;
  }
  if( getuid() == 0 ) snapshot_cmd_enable = (0);
  if( *(char *)&x != 1 ){
    fprintf( stderr,
      "%s CAN'T EXCUTE !\n"
      "This machine is Big-Endian.\n"
      "Compile again comment-out 'LSB_FIRST = 1' in Makefile.\n",
      argv[0] );
    x11_system_term();
    return -1;
  }
  xmame_system_init();
  quasi88_atexit( the_end );
  if( osd_environment() ){
    if( config_init( argc, argv ) ){
      quasi88();
    }
  }
  xmame_system_term();
  x11_system_term();
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: x int


repo: tphaster/smime-gate

decompiled_code:
void __fastcall __noreturn thread_r(void *a1)
{
__int16 v1; // bx
unsigned int v2; // ebp
_OWORD v3[2]; // [rsp+0h] [rbp-28h] BYREF

v1 = _bswap_16_constprop_0(a1);
while ( 1 )
{
v2 = Socket(2LL, 1LL, 0LL);
v3[0] = 0LL;
LOWORD(v3[0]) = 2;
WORD1(v3[0]) = v1;
inet_pton(2, addr, (char *)v3 + 4);
Connect(v2, v3, 16LL);
str_cli(v2, mails_per_session);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func2(void *a1)
{
__int16 v1; // bx
unsigned int v2; // ebp
_OWORD v3[2]; // [rsp+0h] [rbp-28h] BYREF

v1 = func0(a1);
while ( 1 )
{
v2 = Socket(2LL, 1LL, 0LL);
v3[0] = 0LL;
LOWORD(v3[0]) = 2;
WORD1(v3[0]) = v1;
inet_pton(2, addr, (char *)v3 + 4);
Connect(v2, v3, 16LL);
func1(v2, mails_per_session);
}
}

original_code:
void* thread_r (void* arg __attribute__((__unused__)))
{
    int sockfd;
    struct sockaddr_in servaddr;
    for (;;) {
        sockfd = Socket(2, SOCK_STREAM, 0);
        memset(&servaddr, 0, sizeof(servaddr));
        servaddr.sin_family = 2;
        servaddr.sin_port = htons(5555);
        inet_pton(2, addr, &servaddr.sin_addr);
        Connect(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr));
        str_cli(sockfd, mails_per_session);
    }
    exit(0);
}

canonical_original_code:
void *thread_r(void *arg)
{
    int sockfd;
    struct sockaddr_in servaddr;
    for (;;) {
        sockfd = Socket(2, SOCK_STREAM, 0);
        memset(&servaddr, 0, sizeof(servaddr));
        servaddr.sin_family = 2;
        servaddr.sin_port = htons(5555);
        inet_pton(2, addr, &servaddr.sin_addr);
        Connect(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr));
        str_cli(sockfd, mails_per_session);
    }
    exit(0);
}

variable_types:
arg
void *

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

return_type: void *

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

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


decompiled_code:
int __fastcall str_cli(unsigned int a1, int a2)
{
int v2; // er12
int result; // eax
int v4; // ebp
char v5; // r14
unsigned int v6; // er15
int v7; // ebx
_BYTE v8[104]; // [rsp+0h] [rbp-68h] BYREF

v2 = a2;
if ( !a2 )
{
v5 = 1;
v4 = 5;
v6 = 1;
LABEL_14:
pthread_mutex_lock(&mutex);
++sessions;
pthread_mutex_unlock(&mutex);
goto LABEL_5;
}
if ( a2 == 1 )
{
v4 = 1;
v5 = 0;
v6 = 3;
goto LABEL_14;
}
pthread_mutex_lock(&mutex);
++sessions;
result = pthread_mutex_unlock(&mutex);
if ( a2 <= 0 )
return result;
v4 = a2;
v5 = 1;
v2 = 1;
v6 = 1;
LABEL_5:
v7 = 0;
do
{
if ( v7 + 1 == v4 && v5 )
v6 = 2;
pthread_mutex_lock(&mutex);
load_mail_from_file("./mail-test", v8);
if ( (unsigned int)smtp_send_mail(a1, v8, v6) )
{
++errors;
}
else
{
++mails;
kbytes += 96;
}
v7 += v2;
v6 = 0;
free_mail_object(v8);
result = pthread_mutex_unlock(&mutex);
}
while ( v7 < v4 );
return result;
}

canonical_decompiled_code:
int __fastcall func1(unsigned int a1, int a2)
{
int v2; // er12
int result; // eax
int v4; // ebp
char v5; // r14
unsigned int v6; // er15
int v7; // ebx
_BYTE v8[104]; // [rsp+0h] [rbp-68h] BYREF

v2 = a2;
if ( !a2 )
{
v5 = 1;
v4 = 5;
v6 = 1;
LABEL_14:
pthread_mutex_lock(&mutex);
++sessions;
pthread_mutex_unlock(&mutex);
goto LABEL_5;
}
if ( a2 == 1 )
{
v4 = 1;
v5 = 0;
v6 = 3;
goto LABEL_14;
}
pthread_mutex_lock(&mutex);
++sessions;
result = pthread_mutex_unlock(&mutex);
if ( a2 <= 0 )
return result;
v4 = a2;
v5 = 1;
v2 = 1;
v6 = 1;
LABEL_5:
v7 = 0;
do
{
if ( v7 + 1 == v4 && v5 )
v6 = 2;
pthread_mutex_lock(&mutex);
load_mail_from_file("./mail-test", v8);
if ( (unsigned int)smtp_send_mail(a1, v8, v6) )
{
++errors;
}
else
{
++mails;
kbytes += 96;
}
v7 += v2;
v6 = 0;
free_mail_object(v8);
result = pthread_mutex_unlock(&mutex);
}
while ( v7 < v4 );
return result;
}

original_code:
void str_cli (int sockfd, int mps)
{
    int ret, i, cli, inc = 1;
    struct mail_object mail;
    if (mps == 0) {
        inc = 0;
        mps = 5;
    }
    if (mps == 1)
        cli = 0x1 | 0x2;
    else
        cli = 0x1 | 0x0;
    pthread_mutex_lock(&mutex);
    ++sessions;
    pthread_mutex_unlock(&mutex);
    for (i = 0; i < mps; i += inc) {
        if (i+1 == mps && mps != 1)
            cli = 0x0 | 0x2;
        pthread_mutex_lock(&mutex);
        load_mail_from_file("./mail-test", &mail);
        if (0 == (ret = smtp_send_mail(sockfd, &mail, cli))) {
            ++mails;
            kbytes += 96;
        }
        else {
            ++errors;
        }
        free_mail_object(&mail);
        pthread_mutex_unlock(&mutex);
        cli = 0x0 | 0x0;
    }
}

canonical_original_code:
void str_cli(int sockfd, int mps)
{
    int ret; int i; int cli; int inc = 1;
    struct mail_object mail;
    if (mps == 0) {
        inc = 0;
        mps = 5;
    }
    if (mps == 1)
        cli = 0x1 | 0x2;
    else
        cli = 0x1 | 0x0;
    pthread_mutex_lock(&mutex);
    ++sessions;
    pthread_mutex_unlock(&mutex);
    for (i = 0; i < mps; i += inc) {
        if (i+1 == mps && mps != 1)
            cli = 0x0 | 0x2;
        pthread_mutex_lock(&mutex);
        load_mail_from_file("./mail-test", &mail);
        if (0 == (ret = smtp_send_mail(sockfd, &mail, cli))) {
            ++mails;
            kbytes += 96;
        }
        else {
            ++errors;
        }
        free_mail_object(&mail);
        pthread_mutex_unlock(&mutex);
        cli = 0x0 | 0x0;
    }
}

variable_types: mps int

variable_types: ret int

variable_types: i int

variable_types: cli int

variable_types: inc int

variable_types: struct mail_object { char *mail_from; char **rcpt_to; unsigned long no_rcpt; char *data; unsigned long data_size; }


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // rdi
int v4; // eax
const char *v5; // rdi
int v6; // ebx
int v7; // ebp
__int64 v8; // rdx
pthread_t newthread[4]; // [rsp+8h] [rbp-20h] BYREF

if ( argc != 4 )
err_quit("usage: client <IPaddress> <mails per session> <threads>", argv, envp);
v3 = argv[2];
addr = (char *)argv[1];
v4 = atoi(v3);
v5 = argv[3];
mails_per_session = v4;
v6 = atoi(v5);
interval = time(0LL) + 60;
if ( v6 > 0 )
{
v7 = 0;
do
{
v7 += pthread_create(newthread, 0LL, (void *(*)(void *))thread_r, 0LL);
--v6;
}
while ( v6 );
if ( v7 )
err_quit("ERROR: Some threads did not start, exiting...\n", 0LL, v8);
}
puts("mails,kbytes,errors,sessions");
while ( 1 )
{
do
usleep(0xC8u);
while ( time(0LL) <= interval );
interval += 60LL;
pthread_mutex_lock(&mutex);
printf("%d,%d,%d,%d\n", (unsigned int)mails, (unsigned int)kbytes, (unsigned int)errors, (unsigned int)sessions);
mails = 0;
kbytes = 0;
errors = 0;
sessions = 0;
pthread_mutex_unlock(&mutex);
}
}

original_code:
int main (int argc, char **argv)
{
    pthread_t th_id;
    int ret = 0, threads;
    if (argc != 4)
        err_quit("usage: client <IPaddress> <mails per session> <threads>");
    addr = argv[1];
    mails_per_session = atoi(argv[2]);
    threads = atoi(argv[3]);
    interval = time(((void *)0)) + 60;
    for (;threads > 0; --threads) {
        ret += pthread_create(&th_id, ((void *)0), thread_r, ((void *)0));
    }
    if (ret != 0)
        err_quit("ERROR: Some threads did not start, exiting...\n");
    printf("mails,kbytes,errors,sessions\n");
    for (;;) {
        usleep(200);
        if (time(((void *)0)) > interval) {
            interval += 60;
            pthread_mutex_lock(&mutex);
            printf("%d,%d,%d,%d\n", mails, kbytes, errors, sessions);
            mails = 0;
            kbytes = 0;
            errors = 0;
            sessions = 0;
            pthread_mutex_unlock(&mutex);
        }
    }
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    unsigned long th_id;
    int ret = 0; int threads;
    if (argc != 4)
        err_quit("usage: client <IPaddress> <mails per session> <threads>");
    addr = argv[1];
    mails_per_session = atoi(argv[2]);
    threads = atoi(argv[3]);
    interval = time(((void *)0)) + 60;
    for (;threads > 0; --threads) {
        ret += pthread_create(&th_id, ((void *)0), thread_r, ((void *)0));
    }
    if (ret != 0)
        err_quit("ERROR: Some threads did not start, exiting...\n");
    printf("mails,kbytes,errors,sessions\n");
    for (;;) {
        usleep(200);
        if (time(((void *)0)) > interval) {
            interval += 60;
            pthread_mutex_lock(&mutex);
            printf("%d,%d,%d,%d\n", mails, kbytes, errors, sessions);
            mails = 0;
            kbytes = 0;
            errors = 0;
            sessions = 0;
            pthread_mutex_unlock(&mutex);
        }
    }
    return 0;
}

variable_types:
argv
char **

variable_types: threads int


decompiled_code:
char *__fastcall generate_filename(unsigned int a1)
{
char *v1; // r12
unsigned int v2; // ebp
unsigned int v3; // eax

v1 = (char *)malloc(0x30uLL);
if ( v1 )
{
v2 = time(0LL);
v3 = getpid();
snprintf(v1, 0x30uLL, "/var/run/smime-gate/mail%d_%d-%d", v2, v3, a1);
}
return v1;
}

canonical_decompiled_code:
char *__fastcall func0(unsigned int a1)
{
char *v1; // r12
unsigned int v2; // ebp
unsigned int v3; // eax

v1 = (char *)malloc(0x30uLL);
if ( v1 )
{
v2 = time(0LL);
v3 = getpid();
snprintf(v1, 0x30uLL, "/var/run/smime-gate/mail%d_%d-%d", v2, v3, a1);
}
return v1;
}

original_code:
static char *generate_filename (unsigned int nr)
{
    char *fn = malloc(48);
    unsigned int t, p;
    if (((void *)0) != fn) {
        t = time(((void *)0));
        p = getpid();
        snprintf(fn, 48, "/var/run/smime-gate" "/mail%d_%d-%d", t, p, nr);
    }
    return fn;
}

canonical_original_code:
static char *generate_filename(unsigned int nr)
{
    char *fn = malloc(48);
    unsigned int t; unsigned int p;
    if (((void *)0) != fn) {
        t = time(((void *)0));
        p = getpid();
        snprintf(fn, 48, "/var/run/smime-gate" "/mail%d_%d-%d", t, p, nr);
    }
    return fn;
}

variable_types:
nr
unsigned int

variable_types:
fn
char *

variable_types:
t
unsigned int

variable_types:
p
unsigned int

return_type: char *