decompiled_code:
__int64 stateload_intr()
{
int v0; // edx
__int64 result; // rax
int v2; // edx
int v3; // eax

boost_cnt = 0;
v0 = stateload_table("INTR", &suspend_intr_work);
result = 0LL;
if ( !v0 )
{
if ( (unsigned int)stateload_table("INT2", &suspend_intr_work2) )
{
puts("stateload : Statefile is old. (ver 0.6.0?)");
vrtc_base2 = (int)((double)vsync_intr_base * 0.8928571428571429);
if ( !ctrl_vrtc )
ctrl_vrtc = 2;
}
else
{
if ( !(unsigned int)stateload_table("INT3", &suspend_intr_work3) )
{
v2 = stateload_table("INT4", &suspend_intr_work4);
result = 1LL;
if ( !v2 )
return result;
puts("stateload : Statefile is old. (ver 0.6.2?)");
LABEL_19:
boost = 1;
return 1LL;
}
puts("stateload : Statefile is old. (ver 0.6.1?)");
}
if ( !sound_FLAG_A || (v3 = 1, !sound2_EN_TA) )
{
if ( !sound_FLAG_B || (v3 = 1, !sound2_EN_TB) )
{
if ( !sound2_FLAG_BRDY || (v3 = 1, !sound2_EN_BRDY) )
{
v3 = sound2_FLAG_EOS;
if ( sound2_FLAG_EOS )
v3 = sound2_EN_EOS != 0;
}
}
}
SOUND_level = v3;
SOUND_edge = 0;
goto LABEL_19;
}
return result;
}

canonical_decompiled_code:
__int64 func20()
{
int v0; // edx
__int64 result; // rax
int v2; // edx
int v3; // eax

boost_cnt = 0;
v0 = stateload_table("INTR", &suspend_intr_work);
result = 0LL;
if ( !v0 )
{
if ( (unsigned int)stateload_table("INT2", &suspend_intr_work2) )
{
puts("stateload : Statefile is old. (ver 0.6.0?)");
vrtc_base2 = (int)((double)vsync_intr_base * 0.8928571428571429);
if ( !ctrl_vrtc )
ctrl_vrtc = 2;
}
else
{
if ( !(unsigned int)stateload_table("INT3", &suspend_intr_work3) )
{
v2 = stateload_table("INT4", &suspend_intr_work4);
result = 1LL;
if ( !v2 )
return result;
puts("stateload : Statefile is old. (ver 0.6.2?)");
LABEL_19:
boost = 1;
return 1LL;
}
puts("stateload : Statefile is old. (ver 0.6.1?)");
}
if ( !sound_FLAG_A || (v3 = 1, !sound2_EN_TA) )
{
if ( !sound_FLAG_B || (v3 = 1, !sound2_EN_TB) )
{
if ( !sound2_FLAG_BRDY || (v3 = 1, !sound2_EN_BRDY) )
{
v3 = sound2_FLAG_EOS;
if ( sound2_FLAG_EOS )
v3 = sound2_EN_EOS != 0;
}
}
}
SOUND_level = v3;
SOUND_edge = 0;
goto LABEL_19;
}
return result;
}

original_code:
int stateload_intr( void )
{
  boost_cnt = 0;
  if( stateload_table( "INTR", suspend_intr_work ) != (0) ) return (0);
  if( stateload_table( "INT2", suspend_intr_work2 ) != (0) ){
    printf( "stateload : Statefile is old. (ver 0.6.0?)\n" );
    goto NOT_HAVE_SID2;
  }
  if( stateload_table( "INT3", suspend_intr_work3 ) != (0) ){
    printf( "stateload : Statefile is old. (ver 0.6.1?)\n" );
    goto NOT_HAVE_SID3;
  }
  if( stateload_table( "INT4", suspend_intr_work4 ) != (0) ){
    printf( "stateload : Statefile is old. (ver 0.6.2?)\n" );
    goto NOT_HAVE_SID4;
  }
  return (1);
 NOT_HAVE_SID2:
  vrtc_base2 = vsync_intr_base * (( 400.0 ) /448.0);
  if( ctrl_vrtc == 0 ) ctrl_vrtc = 2;
 NOT_HAVE_SID3:
  if( ( sound_FLAG_A && sound2_EN_TA ) ||
      ( sound_FLAG_B && sound2_EN_TB ) ||
      ( sound2_FLAG_BRDY && sound2_EN_BRDY ) ||
      ( sound2_FLAG_EOS && sound2_EN_EOS ) ){
    SOUND_level = (1);
  }else{
    SOUND_level = (0);
  }
  SOUND_edge = (0);
 NOT_HAVE_SID4:
  boost = 1;
  return (1);
}

canonical_original_code:
int stateload_intr()
{
  boost_cnt = 0;
  if( stateload_table( "INTR", suspend_intr_work ) != (0) ) return (0);
  if( stateload_table( "INT2", suspend_intr_work2 ) != (0) ){
    printf( "stateload : Statefile is old. (ver 0.6.0?)\n" );
    goto NOT_HAVE_SID2;
  }
  if( stateload_table( "INT3", suspend_intr_work3 ) != (0) ){
    printf( "stateload : Statefile is old. (ver 0.6.1?)\n" );
    goto NOT_HAVE_SID3;
  }
  if( stateload_table( "INT4", suspend_intr_work4 ) != (0) ){
    printf( "stateload : Statefile is old. (ver 0.6.2?)\n" );
    goto NOT_HAVE_SID4;
  }
  return (1);
 NOT_HAVE_SID2:
  vrtc_base2 = vsync_intr_base * (( 400.0 ) /448.0);
  if( ctrl_vrtc == 0 ) ctrl_vrtc = 2;
 NOT_HAVE_SID3:
  if( ( sound_FLAG_A && sound2_EN_TA ) ||
      ( sound_FLAG_B && sound2_EN_TB ) ||
      ( sound2_FLAG_BRDY && sound2_EN_BRDY ) ||
      ( sound2_FLAG_EOS && sound2_EN_EOS ) ){
    SOUND_level = (1);
  }else{
    SOUND_level = (0);
  }
  SOUND_edge = (0);
 NOT_HAVE_SID4:
  boost = 1;
  return (1);
}


decompiled_code:
__int64 __fastcall YM2608UpdateRequest(int a1)
{
return stream_update((unsigned int)stream[a1], 100LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
return stream_update((unsigned int)stream[a1], 100LL);
}

original_code:
void YM2608UpdateRequest(int chip)
{
 stream_update(stream[chip],100);
}

variable_types: chip int

return_type: void


decompiled_code:
_BOOL8 __fastcall YM2608_sh_start(__int64 a1, __int64 a2)
{
unsigned int v2; // er13
_BOOL4 v3; // edx
int v6; // eax
__int64 v7; // rax
__int64 v8; // rdi
__int64 v9; // rbp
unsigned int v10; // er12
const char *v11; // rax
const char *v12; // rax
int v13[2]; // [rsp+8h] [rbp-C0h] BYREF
__int64 v14[3]; // [rsp+10h] [rbp-B8h] BYREF
int v15[2]; // [rsp+28h] [rbp-A0h] BYREF
__int64 v16[2]; // [rsp+30h] [rbp-98h] BYREF
char s[40]; // [rsp+40h] [rbp-88h] BYREF
char v18[96]; // [rsp+68h] [rbp-60h] BYREF

v2 = sample_rate;
intf = *(_QWORD *)(a1 + 8);
v3 = 1;
if ( *(int *)intf <= 2 )
{
v6 = AY8910_sh_start_ym(a1, a2, 1LL);
v3 = 1;
if ( !v6 )
{
v7 = intf;
v8 = *(unsigned int *)intf;
if ( (int)v8 > 0 )
{
v9 = 0LL;
do
{
v10 = *(_DWORD *)(v7 + 4LL * (int)v9 + 240);
v16[0] = (__int64)s;
v15[0] = (unsigned __int16)v10;
v11 = (const char *)sound_name(a1);
sprintf(s, "%s #%d Ch%d", v11, (unsigned int)v9, 1LL);
v16[1] = (__int64)v18;
v15[1] = HIWORD(v10);
v12 = (const char *)sound_name(a1);
sprintf(v18, "%s #%d Ch%d", v12, (unsigned int)v9, 2LL);
stream[v9] = stream_init_multi(2LL, v16, v15, v2, (unsigned int)v9, &YM2608UpdateOne);
if ( !sound2_adpcm )
sound2_adpcm = malloc(0x40000uLL);
v14[v9] = sound2_adpcm;
v13[v9] = 0x40000;
v7 = intf;
v8 = *(unsigned int *)intf;
++v9;
}
while ( (int)v8 > (int)v9 );
}
v3 = YM2608Init(v8, *(unsigned int *)(v7 + 4), v2, v14, v13, 0LL, 0LL) != 0;
}
}
return v3;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1, __int64 a2)
{
unsigned int v2; // er13
_BOOL4 v3; // edx
int v6; // eax
__int64 v7; // rax
__int64 v8; // rdi
__int64 v9; // rbp
unsigned int v10; // er12
const char *v11; // rax
const char *v12; // rax
int v13[2]; // [rsp+8h] [rbp-C0h] BYREF
__int64 v14[3]; // [rsp+10h] [rbp-B8h] BYREF
int v15[2]; // [rsp+28h] [rbp-A0h] BYREF
__int64 v16[2]; // [rsp+30h] [rbp-98h] BYREF
char s[40]; // [rsp+40h] [rbp-88h] BYREF
char v18[96]; // [rsp+68h] [rbp-60h] BYREF

v2 = sample_rate;
intf = *(_QWORD *)(a1 + 8);
v3 = 1;
if ( *(int *)intf <= 2 )
{
v6 = AY8910_sh_start_ym(a1, a2, 1LL);
v3 = 1;
if ( !v6 )
{
v7 = intf;
v8 = *(unsigned int *)intf;
if ( (int)v8 > 0 )
{
v9 = 0LL;
do
{
v10 = *(_DWORD *)(v7 + 4LL * (int)v9 + 240);
v16[0] = (__int64)s;
v15[0] = (unsigned __int16)v10;
v11 = (const char *)sound_name(a1);
sprintf(s, "%s #%d Ch%d", v11, (unsigned int)v9, 1LL);
v16[1] = (__int64)v18;
v15[1] = HIWORD(v10);
v12 = (const char *)sound_name(a1);
sprintf(v18, "%s #%d Ch%d", v12, (unsigned int)v9, 2LL);
stream[v9] = stream_init_multi(2LL, v16, v15, v2, (unsigned int)v9, &YM2608UpdateOne);
if ( !sound2_adpcm )
sound2_adpcm = malloc(0x40000uLL);
v14[v9] = sound2_adpcm;
v13[v9] = 0x40000;
v7 = intf;
v8 = *(unsigned int *)intf;
++v9;
}
while ( (int)v8 > (int)v9 );
}
v3 = YM2608Init(v8, *(unsigned int *)(v7 + 4), v2, v14, v13, 0LL, 0LL) != 0;
}
}
return v3;
}

original_code:
int YM2608_sh_start(const struct MachineSound *msound)
{
 int i,j;
 int rate = sample_rate;
 char buf[2][40];
 const char *name[2];
 int mixed_vol,vol[2];
 void *pcmbufa[2];
 int pcmsizea[2];
 intf = msound->sound_interface;
 if( intf->num > (2) ) return 1;
 if (AY8910_sh_start_ym(msound)) return 1;
 FMTimerInit();
 for (i = 0;i < intf->num;i++)
 {
  mixed_vol = intf->volumeFM[i];
  for (j = 0 ; j < 2 ; j++)
  {
   name[j]=buf[j];
   vol[j] = mixed_vol & 0xffff;
   mixed_vol>>=16;
   sprintf(buf[j],"%s #%d Ch%d",sound_name(msound),i,j+1);
  }
  stream[i] = stream_init_multi(2,name,vol,rate,i,YM2608UpdateOne);
  if( sound2_adpcm==((void *)0) ){
    sound2_adpcm = (byte *)malloc( 256 * 1024 * sizeof(char) );
  }
  pcmbufa[i] = sound2_adpcm;
  pcmsizea[i] = 256 * 1024;
 }
 if (YM2608Init(intf->num,intf->baseclock,rate,
             pcmbufa,pcmsizea,
             0,0) == 0)
  return 0;
 return 1;
}

canonical_original_code:
int YM2608_sh_start(struct MachineSound *msound)
{
 int i; int j;
 int rate = sample_rate;
 char buf[2][40];
 char *name[2];
 int mixed_vol; int vol[2];
 void *pcmbufa[2];
 int pcmsizea[2];
 intf = msound->sound_interface;
 if( intf->num > (2) ) return 1;
 if (AY8910_sh_start_ym(msound)) return 1;
 FMTimerInit();
 for (i = 0;i < intf->num;i++)
 {
  mixed_vol = intf->volumeFM[i];
  for (j = 0 ; j < 2 ; j++)
  {
   name[j]=buf[j];
   vol[j] = mixed_vol & 0xffff;
   mixed_vol>>=16;
   sprintf(buf[j],"%s #%d Ch%d",sound_name(msound),i,j+1);
  }
  stream[i] = stream_init_multi(2,name,vol,rate,i,YM2608UpdateOne);
  if( sound2_adpcm==((void *)0) ){
    sound2_adpcm = (unsigned char *)malloc( 256 * 1024 * sizeof(char) );
  }
  pcmbufa[i] = sound2_adpcm;
  pcmsizea[i] = 256 * 1024;
 }
 if (YM2608Init(intf->num,intf->baseclock,rate,
             pcmbufa,pcmsizea,
             0,0) == 0)
  return 0;
 return 1;
}

variable_types: struct MachineSound { int sound_type; void *sound_interface; char *tag; } *

variable_types: i int

variable_types: j int

variable_types: rate int

variable_types:
buf
char [2][40]

variable_types:
name
char *[2]

variable_types:
vol
int [2]

variable_types:
pcmbufa
void *[2]

variable_types:
pcmsizea
int [2]

return_type: int


decompiled_code:
__int64 YM2608_sh_stop()
{
YM2608Shutdown();
return AY8910_sh_stop_ym();
}

canonical_decompiled_code:
__int64 func3()
{
YM2608Shutdown();
return AY8910_sh_stop_ym();
}

original_code:
void YM2608_sh_stop(void)
{
 YM2608Shutdown();
 AY8910_sh_stop_ym();
}

canonical_original_code:
void YM2608_sh_stop()
{
 YM2608Shutdown();
 AY8910_sh_stop_ym();
}


decompiled_code:
__int64 YM2608_sh_reset()
{
__int64 result; // rax
unsigned int v1; // ebx

result = intf;
if ( *(int *)intf > 0 )
{
v1 = 0;
do
{
YM2608ResetChip(v1++);
result = intf;
}
while ( *(_DWORD *)intf > (signed int)v1 );
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 result; // rax
unsigned int v1; // ebx

result = intf;
if ( *(int *)intf > 0 )
{
v1 = 0;
do
{
YM2608ResetChip(v1++);
result = intf;
}
while ( *(_DWORD *)intf > (signed int)v1 );
}
return result;
}

original_code:
void YM2608_sh_reset(void)
{
 int i;
 for (i = 0;i < intf->num;i++)
  YM2608ResetChip(i);
}

canonical_original_code:
void YM2608_sh_reset()
{
 int i;
 for (i = 0;i < intf->num;i++)
  YM2608ResetChip(i);
}


decompiled_code:
__int64 YM2608_status_port_0_A_r()
{
return YM2608Read(0LL, 0LL);
}

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

original_code:
data8_t YM2608_status_port_0_A_r(__attribute__((__unused__)) offs_t offset)
{
 return YM2608Read(0,0);
}

canonical_original_code:
unsigned char YM2608_status_port_0_A_r(unsigned int offset)
{
 return YM2608Read(0,0);
}

variable_types:
offset
unsigned int

return_type: unsigned char


decompiled_code:
__int64 YM2608_status_port_0_B_r()
{
return YM2608Read(0LL, 2LL);
}

canonical_decompiled_code:
__int64 func6()
{
return YM2608Read(0LL, 2LL);
}

original_code:
data8_t YM2608_status_port_0_B_r(__attribute__((__unused__)) offs_t offset)
{
 return YM2608Read(0,2);
}

canonical_original_code:
unsigned char YM2608_status_port_0_B_r(unsigned int offset)
{
 return YM2608Read(0,2);
}


decompiled_code:
__int64 YM2608_status_port_1_A_r()
{
return YM2608Read(1LL, 0LL);
}

canonical_decompiled_code:
__int64 func7()
{
return YM2608Read(1LL, 0LL);
}

original_code:
data8_t YM2608_status_port_1_A_r(__attribute__((__unused__)) offs_t offset) {
 return YM2608Read(1,0);
}

canonical_original_code:
unsigned char YM2608_status_port_1_A_r(unsigned int offset) {
 return YM2608Read(1,0);
}


decompiled_code:
__int64 YM2608_status_port_1_B_r()
{
return YM2608Read(1LL, 2LL);
}

canonical_decompiled_code:
__int64 func8()
{
return YM2608Read(1LL, 2LL);
}

original_code:
data8_t YM2608_status_port_1_B_r(__attribute__((__unused__)) offs_t offset) {
 return YM2608Read(1,2);
}

canonical_original_code:
unsigned char YM2608_status_port_1_B_r(unsigned int offset) {
 return YM2608Read(1,2);
}


decompiled_code:
__int64 YM2608_read_port_0_r()
{
return YM2608Read(0LL, 1LL);
}

canonical_decompiled_code:
__int64 func9()
{
return YM2608Read(0LL, 1LL);
}

original_code:
data8_t YM2608_read_port_0_r(__attribute__((__unused__)) offs_t offset){
 return YM2608Read(0,1);
}

canonical_original_code:
unsigned char YM2608_read_port_0_r(unsigned int offset){
 return YM2608Read(0,1);
}


decompiled_code:
__int64 YM2608_read_port_1_r()
{
return YM2608Read(1LL, 1LL);
}

canonical_decompiled_code:
__int64 func10()
{
return YM2608Read(1LL, 1LL);
}

original_code:
data8_t YM2608_read_port_1_r(__attribute__((__unused__)) offs_t offset){
 return YM2608Read(1,1);
}

canonical_original_code:
unsigned char YM2608_read_port_1_r(unsigned int offset){
 return YM2608Read(1,1);
}


decompiled_code:
__int64 __fastcall YM2608_control_port_0_A_w(__int64 a1, unsigned __int8 a2)
{
return YM2608Write(0LL, 0LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, unsigned __int8 a2)
{
return YM2608Write(0LL, 0LL, a2);
}

original_code:
void YM2608_control_port_0_A_w(__attribute__((__unused__)) offs_t offset, __attribute__((__unused__)) data8_t data)
{
 YM2608Write(0,0,data);
}

canonical_original_code:
void YM2608_control_port_0_A_w(unsigned int offset, unsigned char data)
{
 YM2608Write(0,0,data);
}

variable_types:
data
unsigned char


decompiled_code:
__int64 __fastcall YM2608_control_port_0_B_w(__int64 a1, unsigned __int8 a2)
{
return YM2608Write(0LL, 2LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, unsigned __int8 a2)
{
return YM2608Write(0LL, 2LL, a2);
}

original_code:
void YM2608_control_port_0_B_w(__attribute__((__unused__)) offs_t offset, __attribute__((__unused__)) data8_t data)
{
 YM2608Write(0,2,data);
}

canonical_original_code:
void YM2608_control_port_0_B_w(unsigned int offset, unsigned char data)
{
 YM2608Write(0,2,data);
}


decompiled_code:
__int64 __fastcall YM2608_control_port_1_A_w(__int64 a1, unsigned __int8 a2)
{
return YM2608Write(1LL, 0LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, unsigned __int8 a2)
{
return YM2608Write(1LL, 0LL, a2);
}

original_code:
void YM2608_control_port_1_A_w(__attribute__((__unused__)) offs_t offset, __attribute__((__unused__)) data8_t data){
 YM2608Write(1,0,data);
}

canonical_original_code:
void YM2608_control_port_1_A_w(unsigned int offset, unsigned char data){
 YM2608Write(1,0,data);
}


decompiled_code:
__int64 __fastcall YM2608_control_port_1_B_w(__int64 a1, unsigned __int8 a2)
{
return YM2608Write(1LL, 2LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, unsigned __int8 a2)
{
return YM2608Write(1LL, 2LL, a2);
}

original_code:
void YM2608_control_port_1_B_w(__attribute__((__unused__)) offs_t offset, __attribute__((__unused__)) data8_t data){
 YM2608Write(1,2,data);
}

canonical_original_code:
void YM2608_control_port_1_B_w(unsigned int offset, unsigned char data){
 YM2608Write(1,2,data);
}


decompiled_code:
__int64 __fastcall YM2608_data_port_0_A_w(__int64 a1, unsigned __int8 a2)
{
return YM2608Write(0LL, 1LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, unsigned __int8 a2)
{
return YM2608Write(0LL, 1LL, a2);
}

original_code:
void YM2608_data_port_0_A_w(__attribute__((__unused__)) offs_t offset, __attribute__((__unused__)) data8_t data)
{
 YM2608Write(0,1,data);
}

canonical_original_code:
void YM2608_data_port_0_A_w(unsigned int offset, unsigned char data)
{
 YM2608Write(0,1,data);
}


decompiled_code:
__int64 __fastcall YM2608_data_port_0_B_w(__int64 a1, unsigned __int8 a2)
{
return YM2608Write(0LL, 3LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, unsigned __int8 a2)
{
return YM2608Write(0LL, 3LL, a2);
}

original_code:
void YM2608_data_port_0_B_w(__attribute__((__unused__)) offs_t offset, __attribute__((__unused__)) data8_t data)
{
 YM2608Write(0,3,data);
}

canonical_original_code:
void YM2608_data_port_0_B_w(unsigned int offset, unsigned char data)
{
 YM2608Write(0,3,data);
}


decompiled_code:
__int64 __fastcall YM2608_data_port_1_A_w(__int64 a1, unsigned __int8 a2)
{
return YM2608Write(1LL, 1LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, unsigned __int8 a2)
{
return YM2608Write(1LL, 1LL, a2);
}

original_code:
void YM2608_data_port_1_A_w(__attribute__((__unused__)) offs_t offset, __attribute__((__unused__)) data8_t data){
 YM2608Write(1,1,data);
}

canonical_original_code:
void YM2608_data_port_1_A_w(unsigned int offset, unsigned char data){
 YM2608Write(1,1,data);
}


decompiled_code:
__int64 __fastcall YM2608_data_port_1_B_w(__int64 a1, unsigned __int8 a2)
{
return YM2608Write(1LL, 3LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1, unsigned __int8 a2)
{
return YM2608Write(1LL, 3LL, a2);
}

original_code:
void YM2608_data_port_1_B_w(__attribute__((__unused__)) offs_t offset, __attribute__((__unused__)) data8_t data){
 YM2608Write(1,3,data);
}

canonical_original_code:
void YM2608_data_port_1_B_w(unsigned int offset, unsigned char data){
 YM2608Write(1,3,data);
}


original_code:
void pio_init( void )
{
  int side;
  for( side=0; side<2; side++ ){
    pio_AB[ side ][ (0) ].type = (0);
    pio_AB[ side ][ (0) ].exist = (0);
    pio_AB[ side ][ (0) ].data = 0x00;
    pio_AB[ side ][ (1) ].type = (1);
    pio_AB[ side ][ (1) ].exist = (0);
    pio_AB[ side ][ (1) ].data = 0x00;
    pio_C[ side ][ (0) ].type = (1);
    pio_C[ side ][ (0) ].cont_f = 1;
    pio_C[ side ][ (0) ].data = 0x00;
    pio_C[ side ][ (1) ].type = (0);
    pio_C[ side ][ (1) ].cont_f = 1;
    pio_C[ side ][ (1) ].data = 0x00;
  }
}

canonical_original_code:
void pio_init()
{
  int side;
  for( side=0; side<2; side++ ){
    pio_AB[ side ][ (0) ].type = (0);
    pio_AB[ side ][ (0) ].exist = (0);
    pio_AB[ side ][ (0) ].data = 0x00;
    pio_AB[ side ][ (1) ].type = (1);
    pio_AB[ side ][ (1) ].exist = (0);
    pio_AB[ side ][ (1) ].data = 0x00;
    pio_C[ side ][ (0) ].type = (1);
    pio_C[ side ][ (0) ].cont_f = 1;
    pio_C[ side ][ (0) ].data = 0x00;
    pio_C[ side ][ (1) ].type = (0);
    pio_C[ side ][ (1) ].cont_f = 1;
    pio_C[ side ][ (1) ].data = 0x00;
  }
}

variable_types: side int


decompiled_code:
__int64 __fastcall pio_read_AB(int a1, int a2)
{
int v3; // er12
int v4; // er13
__int16 *v5; // rdx
__int16 *v6; // rsi
__int16 *v8; // rdx
__int16 *v9; // rsi
__int16 *v10; // rdx
__int16 *v11; // rsi

v3 = a1 ^ 1;
v4 = a2 ^ 1;
if ( pio_AB[8 * (a1 ^ 1) + 4 * (a2 ^ 1)] )
{
LABEL_8:
if ( pio_AB[8 * a1 + 4 * a2] != 1 )
goto LABEL_9;
if ( verbose_pio )
{
v8 = aAbms;
if ( a2 )
v8 = &aAbms[1];
v9 = &aAbms[2];
if ( a1 )
v9 = &aAbms[3];
printf("PIO Read from WRITE-PORT : side = %s : port = %s\n", (const char *)v9, (const char *)v8);
}
return LOBYTE(pio_AB[8 * a1 + 3 + 4 * a2]);
}
if ( verbose_pio )
{
v5 = aAbms;
if ( a2 )
v5 = &aAbms[1];
v6 = &aAbms[2];
if ( a1 )
v6 = &aAbms[3];
printf("PIO AB READ PORT Mismatch : side = %s : port = %s\n", (const char *)v6, (const char *)v5);
goto LABEL_8;
}
if ( pio_AB[8 * a1 + 4 * a2] != 1 )
{
LABEL_9:
if ( pio_AB[8 * v3 + 1 + 4 * v4] != 1 )
{
if ( cpu_timing == 1 )
{
if ( !a1 )
{
dual_cpu_count = CPU_1_COUNT;
z80_state_intchk = 0;
z80_state_goal = 1;
}
}
else if ( (cpu_timing & 0xFFFFFFFD) != 0 )
{
return LOBYTE(pio_AB[8 * v3 + 3 + 4 * v4]);
}
if ( verbose_pio )
{
v10 = aAbms;
if ( a2 )
v10 = &aAbms[1];
v11 = &aAbms[2];
if ( a1 )
v11 = &aAbms[3];
printf("PIO Read continuously : side = %s : port = %s\n", (const char *)v11, (const char *)v10);
}
return LOBYTE(pio_AB[8 * v3 + 3 + 4 * v4]);
}
pio_AB[8 * v3 + 1 + 4 * v4] = 0;
return LOBYTE(pio_AB[8 * v3 + 3 + 4 * v4]);
}
return LOBYTE(pio_AB[8 * a1 + 3 + 4 * a2]);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2)
{
int v3; // er12
int v4; // er13
__int16 *v5; // rdx
__int16 *v6; // rsi
__int16 *v8; // rdx
__int16 *v9; // rsi
__int16 *v10; // rdx
__int16 *v11; // rsi

v3 = a1 ^ 1;
v4 = a2 ^ 1;
if ( pio_AB[8 * (a1 ^ 1) + 4 * (a2 ^ 1)] )
{
LABEL_8:
if ( pio_AB[8 * a1 + 4 * a2] != 1 )
goto LABEL_9;
if ( verbose_pio )
{
v8 = aAbms;
if ( a2 )
v8 = &aAbms[1];
v9 = &aAbms[2];
if ( a1 )
v9 = &aAbms[3];
printf("PIO Read from WRITE-PORT : side = %s : port = %s\n", (const char *)v9, (const char *)v8);
}
return LOBYTE(pio_AB[8 * a1 + 3 + 4 * a2]);
}
if ( verbose_pio )
{
v5 = aAbms;
if ( a2 )
v5 = &aAbms[1];
v6 = &aAbms[2];
if ( a1 )
v6 = &aAbms[3];
printf("PIO AB READ PORT Mismatch : side = %s : port = %s\n", (const char *)v6, (const char *)v5);
goto LABEL_8;
}
if ( pio_AB[8 * a1 + 4 * a2] != 1 )
{
LABEL_9:
if ( pio_AB[8 * v3 + 1 + 4 * v4] != 1 )
{
if ( cpu_timing == 1 )
{
if ( !a1 )
{
dual_cpu_count = CPU_1_COUNT;
z80_state_intchk = 0;
z80_state_goal = 1;
}
}
else if ( (cpu_timing & 0xFFFFFFFD) != 0 )
{
return LOBYTE(pio_AB[8 * v3 + 3 + 4 * v4]);
}
if ( verbose_pio )
{
v10 = aAbms;
if ( a2 )
v10 = &aAbms[1];
v11 = &aAbms[2];
if ( a1 )
v11 = &aAbms[3];
printf("PIO Read continuously : side = %s : port = %s\n", (const char *)v11, (const char *)v10);
}
return LOBYTE(pio_AB[8 * v3 + 3 + 4 * v4]);
}
pio_AB[8 * v3 + 1 + 4 * v4] = 0;
return LOBYTE(pio_AB[8 * v3 + 3 + 4 * v4]);
}
return LOBYTE(pio_AB[8 * a1 + 3 + 4 * a2]);
}

original_code:
byte pio_read_AB( int side, int port )
{
  if( pio_AB[ side^1 ][ port^1 ].type == (0) ){
    if( verbose_pio ) printf( "PIO AB READ PORT Mismatch" " : side = %s : port = %s\n", (side==(0))?"M":"S", (port==(0))?"A":"B" );
  }
  if( pio_AB[ side ][ port ].type == (1) ){
    if( verbose_pio ) printf( "PIO Read from WRITE-PORT" " : side = %s : port = %s\n", (side==(0))?"M":"S", (port==(0))?"A":"B" );
    return (pio_AB[ side ][ port ].data);
  }
  if( pio_AB[ side^1 ][ port^1 ].exist == (1) ){
    pio_AB[ side^1 ][ port^1 ].exist = (0);
  }else{
    switch( cpu_timing ){
    case 1:
      if( side==(0) ){
 dual_cpu_count = CPU_1_COUNT;
 do{ z80_state_intchk = 0; z80_state_goal = 1; }while(0);
      }
    case 0:
    case 2:
      if( verbose_pio ) printf( "PIO Read continuously" " : side = %s : port = %s\n", (side==(0))?"M":"S", (port==(0))?"A":"B" );
      break;
    }
  }
  return (pio_AB[ side^1 ][ port^1 ].data);
}

canonical_original_code:
unsigned char pio_read_AB(int side, int port)
{
  if( pio_AB[ side^1 ][ port^1 ].type == (0) ){
    if( verbose_pio ) printf( "PIO AB READ PORT Mismatch" " : side = %s : port = %s\n", (side==(0))?"M":"S", (port==(0))?"A":"B" );
  }
  if( pio_AB[ side ][ port ].type == (1) ){
    if( verbose_pio ) printf( "PIO Read from WRITE-PORT" " : side = %s : port = %s\n", (side==(0))?"M":"S", (port==(0))?"A":"B" );
    return (pio_AB[ side ][ port ].data);
  }
  if( pio_AB[ side^1 ][ port^1 ].exist == (1) ){
    pio_AB[ side^1 ][ port^1 ].exist = (0);
  }else{
    switch( cpu_timing ){
    case 1:
      if( side==(0) ){
 dual_cpu_count = CPU_1_COUNT;
 do{ z80_state_intchk = 0; z80_state_goal = 1; }while(0);
      }
    case 0:
    case 2:
      if( verbose_pio ) printf( "PIO Read continuously" " : side = %s : port = %s\n", (side==(0))?"M":"S", (port==(0))?"A":"B" );
      break;
    }
  }
  return (pio_AB[ side^1 ][ port^1 ].data);
}

variable_types: port int


decompiled_code:
__int64 __fastcall pio_write_AB(int a1, int a2, char a3)
{
__int16 *v5; // rdx
__int16 *v6; // rsi
__int64 result; // rax
__int16 *v8; // rdx
__int16 *v9; // rsi
__int16 *v10; // rdx
__int16 *v11; // rsi

if ( pio_AB[8 * (a1 ^ 1) + 4 * (a2 ^ 1)] == 1 )
{
if ( !verbose_pio )
goto LABEL_9;
v8 = aAbms;
if ( a2 )
v8 = &aAbms[1];
v9 = &aAbms[2];
if ( a1 )
v9 = &aAbms[3];
printf("PIO AB Write PORT Mismatch : side = %s : port = %s\n", (const char *)v9, (const char *)v8);
}
if ( !pio_AB[8 * a1 + 4 * a2] && verbose_pio )
{
v5 = aAbms;
if ( a2 )
v5 = &aAbms[1];
v6 = &aAbms[2];
if ( a1 )
v6 = &aAbms[3];
printf("PIO Write to READ-PORT : side = %s : port = %s\n", (const char *)v6, (const char *)v5);
}
LABEL_9:
if ( !pio_AB[8 * a1 + 1 + 4 * a2] )
{
result = 16 * (a2 + 2LL * a1);
*(int *)((char *)&pio_AB[1] + result) = 1;
*((_BYTE *)&pio_AB[3] + result) = a3;
return result;
}
result = cpu_timing;
if ( cpu_timing == 1 )
{
if ( !a1 )
{
dual_cpu_count = CPU_1_COUNT;
z80_state_intchk = 0;
z80_state_goal = 1;
}
}
else if ( (cpu_timing & 0xFFFFFFFD) != 0 )
{
return result;
}
if ( verbose_pio )
{
v10 = aAbms;
if ( a2 )
v10 = &aAbms[1];
v11 = &aAbms[2];
if ( a1 )
v11 = &aAbms[3];
printf("PIO Write continuously : side = %s : port = %s\n", (const char *)v11, (const char *)v10);
}
result = 16 * (a2 + 2LL * a1);
*((_BYTE *)&pio_AB[3] + result) = a3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2, char a3)
{
__int16 *v5; // rdx
__int16 *v6; // rsi
__int64 result; // rax
__int16 *v8; // rdx
__int16 *v9; // rsi
__int16 *v10; // rdx
__int16 *v11; // rsi

if ( pio_AB[8 * (a1 ^ 1) + 4 * (a2 ^ 1)] == 1 )
{
if ( !verbose_pio )
goto LABEL_9;
v8 = aAbms;
if ( a2 )
v8 = &aAbms[1];
v9 = &aAbms[2];
if ( a1 )
v9 = &aAbms[3];
printf("PIO AB Write PORT Mismatch : side = %s : port = %s\n", (const char *)v9, (const char *)v8);
}
if ( !pio_AB[8 * a1 + 4 * a2] && verbose_pio )
{
v5 = aAbms;
if ( a2 )
v5 = &aAbms[1];
v6 = &aAbms[2];
if ( a1 )
v6 = &aAbms[3];
printf("PIO Write to READ-PORT : side = %s : port = %s\n", (const char *)v6, (const char *)v5);
}
LABEL_9:
if ( !pio_AB[8 * a1 + 1 + 4 * a2] )
{
result = 16 * (a2 + 2LL * a1);
*(int *)((char *)&pio_AB[1] + result) = 1;
*((_BYTE *)&pio_AB[3] + result) = a3;
return result;
}
result = cpu_timing;
if ( cpu_timing == 1 )
{
if ( !a1 )
{
dual_cpu_count = CPU_1_COUNT;
z80_state_intchk = 0;
z80_state_goal = 1;
}
}
else if ( (cpu_timing & 0xFFFFFFFD) != 0 )
{
return result;
}
if ( verbose_pio )
{
v10 = aAbms;
if ( a2 )
v10 = &aAbms[1];
v11 = &aAbms[2];
if ( a1 )
v11 = &aAbms[3];
printf("PIO Write continuously : side = %s : port = %s\n", (const char *)v11, (const char *)v10);
}
result = 16 * (a2 + 2LL * a1);
*((_BYTE *)&pio_AB[3] + result) = a3;
return result;
}

original_code:
void pio_write_AB( int side, int port, byte data )
{
  if( pio_AB[ side^1 ][ port^1 ].type == (1) ){
    if( verbose_pio ) printf( "PIO AB Write PORT Mismatch" " : side = %s : port = %s\n", (side==(0))?"M":"S", (port==(0))?"A":"B" );
  }
  if( pio_AB[ side ][ port ].type == (0) ){
    if( verbose_pio ) printf( "PIO Write to READ-PORT" " : side = %s : port = %s\n", (side==(0))?"M":"S", (port==(0))?"A":"B" );
  }
  if( pio_AB[ side ][ port ].exist == (0) ){
    pio_AB[ side ][ port ].exist = (1);
    pio_AB[ side ][ port ].data = data;
  }else{
    switch( cpu_timing ){
    case 1:
      if( side==(0) ){
 dual_cpu_count = CPU_1_COUNT;
 do{ z80_state_intchk = 0; z80_state_goal = 1; }while(0);
      }
    case 0:
    case 2:
      if( verbose_pio ) printf( "PIO Write continuously" " : side = %s : port = %s\n", (side==(0))?"M":"S", (port==(0))?"A":"B" );
      pio_AB[ side ][ port ].data = data;
      break;
    }
  }
  return;
}

canonical_original_code:
void pio_write_AB(int side, int port, unsigned char data)
{
  if( pio_AB[ side^1 ][ port^1 ].type == (1) ){
    if( verbose_pio ) printf( "PIO AB Write PORT Mismatch" " : side = %s : port = %s\n", (side==(0))?"M":"S", (port==(0))?"A":"B" );
  }
  if( pio_AB[ side ][ port ].type == (0) ){
    if( verbose_pio ) printf( "PIO Write to READ-PORT" " : side = %s : port = %s\n", (side==(0))?"M":"S", (port==(0))?"A":"B" );
  }
  if( pio_AB[ side ][ port ].exist == (0) ){
    pio_AB[ side ][ port ].exist = (1);
    pio_AB[ side ][ port ].data = data;
  }else{
    switch( cpu_timing ){
    case 1:
      if( side==(0) ){
 dual_cpu_count = CPU_1_COUNT;
 do{ z80_state_intchk = 0; z80_state_goal = 1; }while(0);
      }
    case 0:
    case 2:
      if( verbose_pio ) printf( "PIO Write continuously" " : side = %s : port = %s\n", (side==(0))?"M":"S", (port==(0))?"A":"B" );
      pio_AB[ side ][ port ].data = data;
      break;
    }
  }
  return;
}


decompiled_code:
__int64 __fastcall pio_read_C(int a1)
{
int v1; // ebp
__int16 *v2; // rsi
unsigned int v3; // edx
__int64 v4; // rax
int v5; // ecx
__int16 *v7; // rsi

v1 = a1 ^ 1;
if ( !pio_C[8 * (a1 ^ 1)] && !pio_C[8 * v1 + 4] && verbose_pio )
{
v2 = &aAbms[2];
if ( a1 )
v2 = &aAbms[3];
printf("PIO C READ PORT Mismatch : side = %s\n", (const char *)v2);
}
if ( pio_C[8 * a1] == 1 )
{
if ( pio_C[8 * a1 + 4] != 1 || !verbose_pio )
goto LABEL_17;
v7 = &aAbms[2];
if ( a1 )
v7 = &aAbms[3];
printf("PIO C Read from WRITE-PORT : side = %s\n", (const char *)v7);
}
if ( !pio_C[8 * a1] )
{
v3 = 16 * LOBYTE(pio_C[8 * v1 + 7]);
goto LABEL_10;
}
LABEL_17:
v3 = 16 * LOBYTE(pio_C[8 * a1 + 3]);
LABEL_10:
if ( pio_C[8 * a1 + 4] )
LOBYTE(v3) = LOBYTE(pio_C[8 * a1 + 7]) | v3;
else
LOBYTE(v3) = LOBYTE(pio_C[8 * v1 + 3]) | v3;
v4 = 8LL * a1;
v5 = pio_C[v4 + 6];
pio_C[v4 + 6] = v5 ^ 1;
if ( v5 == 1 )
{
if ( cpu_timing )
{
if ( cpu_timing == 1 && !a1 )
{
dual_cpu_count = CPU_1_COUNT;
z80_state_intchk = 0;
z80_state_goal = 1;
}
}
else
{
select_main_cpu ^= 1u;
z80_state_intchk = 0;
z80_state_goal = 1;
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
int v1; // ebp
__int16 *v2; // rsi
unsigned int v3; // edx
__int64 v4; // rax
int v5; // ecx
__int16 *v7; // rsi

v1 = a1 ^ 1;
if ( !pio_C[8 * (a1 ^ 1)] && !pio_C[8 * v1 + 4] && verbose_pio )
{
v2 = &aAbms[2];
if ( a1 )
v2 = &aAbms[3];
printf("PIO C READ PORT Mismatch : side = %s\n", (const char *)v2);
}
if ( pio_C[8 * a1] == 1 )
{
if ( pio_C[8 * a1 + 4] != 1 || !verbose_pio )
goto LABEL_17;
v7 = &aAbms[2];
if ( a1 )
v7 = &aAbms[3];
printf("PIO C Read from WRITE-PORT : side = %s\n", (const char *)v7);
}
if ( !pio_C[8 * a1] )
{
v3 = 16 * LOBYTE(pio_C[8 * v1 + 7]);
goto LABEL_10;
}
LABEL_17:
v3 = 16 * LOBYTE(pio_C[8 * a1 + 3]);
LABEL_10:
if ( pio_C[8 * a1 + 4] )
LOBYTE(v3) = LOBYTE(pio_C[8 * a1 + 7]) | v3;
else
LOBYTE(v3) = LOBYTE(pio_C[8 * v1 + 3]) | v3;
v4 = 8LL * a1;
v5 = pio_C[v4 + 6];
pio_C[v4 + 6] = v5 ^ 1;
if ( v5 == 1 )
{
if ( cpu_timing )
{
if ( cpu_timing == 1 && !a1 )
{
dual_cpu_count = CPU_1_COUNT;
z80_state_intchk = 0;
z80_state_goal = 1;
}
}
else
{
select_main_cpu ^= 1u;
z80_state_intchk = 0;
z80_state_goal = 1;
}
}
return v3;
}

original_code:
byte pio_read_C( int side )
{
  byte data;
  if( pio_C[ side^1 ][ (0) ].type == (0) &&
      pio_C[ side^1 ][ (1) ].type == (0) ){
    if( verbose_pio ) printf( "PIO C READ PORT Mismatch" " : side = %s\n", (side==(0))?"M":"S" );
  }
  if( pio_C[ side ][ (0) ].type == (1) &&
      pio_C[ side ][ (1) ].type == (1) ){
    if( verbose_pio ) printf( "PIO C Read from WRITE-PORT" " : side = %s\n", (side==(0))?"M":"S" );
  }
  if( pio_C[ side ][ (0) ].type == (0) ){
    data = pio_C[ side^1 ][ (1) ].data << 4;
  }else{
    data = pio_C[ side ][ (0) ].data << 4;
  }
  if( pio_C[ side ][ (1) ].type == (0) ){
    data |= pio_C[ side^1 ][ (0) ].data;
  }else{
    data |= pio_C[ side ][ (1) ].data;
  }
  pio_C[ side ][ (1) ].cont_f ^= 1;
  if( pio_C[ side ][ (1) ].cont_f == 0 ){
    switch( cpu_timing ){
    case 0:
      select_main_cpu ^= 1;
      do{ z80_state_intchk = 0; z80_state_goal = 1; }while(0);
      break;
    case 1:
      if( side==(0) ){
 dual_cpu_count = CPU_1_COUNT;
 do{ z80_state_intchk = 0; z80_state_goal = 1; }while(0);
      }
      break;
    case 2:
      break;
    }
  }
  return data;
}

canonical_original_code:
unsigned char pio_read_C(int side)
{
  unsigned char data;
  if( pio_C[ side^1 ][ (0) ].type == (0) &&
      pio_C[ side^1 ][ (1) ].type == (0) ){
    if( verbose_pio ) printf( "PIO C READ PORT Mismatch" " : side = %s\n", (side==(0))?"M":"S" );
  }
  if( pio_C[ side ][ (0) ].type == (1) &&
      pio_C[ side ][ (1) ].type == (1) ){
    if( verbose_pio ) printf( "PIO C Read from WRITE-PORT" " : side = %s\n", (side==(0))?"M":"S" );
  }
  if( pio_C[ side ][ (0) ].type == (0) ){
    data = pio_C[ side^1 ][ (1) ].data << 4;
  }else{
    data = pio_C[ side ][ (0) ].data << 4;
  }
  if( pio_C[ side ][ (1) ].type == (0) ){
    data |= pio_C[ side^1 ][ (0) ].data;
  }else{
    data |= pio_C[ side ][ (1) ].data;
  }
  pio_C[ side ][ (1) ].cont_f ^= 1;
  if( pio_C[ side ][ (1) ].cont_f == 0 ){
    switch( cpu_timing ){
    case 0:
      select_main_cpu ^= 1;
      do{ z80_state_intchk = 0; z80_state_goal = 1; }while(0);
      break;
    case 1:
      if( side==(0) ){
 dual_cpu_count = CPU_1_COUNT;
 do{ z80_state_intchk = 0; z80_state_goal = 1; }while(0);
      }
      break;
    case 2:
      break;
    }
  }
  return data;
}


decompiled_code:
char __fastcall pio_write_C(int a1, char a2)
{
_BOOL4 v3; // ebp
unsigned __int8 v4; // r13
__int16 *v5; // rsi
char result; // al
__int16 *v7; // rsi

v3 = (a2 & 8) == 0;
v4 = a2 & 7;
if ( pio_C[8 * (a1 ^ 1) + 4 * ((a2 & 8) != 0)] == 1 )
{
if ( !verbose_pio )
goto LABEL_7;
v7 = &aAbms[2];
if ( a1 )
v7 = &aAbms[3];
printf("PIO C Write PORT Mismatch : side = %s\n", (const char *)v7);
}
if ( !pio_C[8 * a1 + 4 * v3] && verbose_pio )
{
v5 = &aAbms[2];
if ( a1 )
v5 = &aAbms[3];
printf("PIO C Write to READ-PORT : side = %s\n", (const char *)v5);
}
LABEL_7:
if ( (a2 & 1) != 0 )
result = LOBYTE(pio_C[8 * a1 + 3 + 4 * v3]) | (1 << (v4 >> 1));
else
result = LOBYTE(pio_C[8 * a1 + 3 + 4 * v3]) & ~(1 << (v4 >> 1));
LOBYTE(pio_C[8 * a1 + 3 + 4 * v3]) = result;
if ( cpu_timing == 1 && !a1 )
{
result = CPU_1_COUNT;
dual_cpu_count = CPU_1_COUNT;
z80_state_intchk = 0;
z80_state_goal = 1;
}
return result;
}

canonical_decompiled_code:
char __fastcall func4(int a1, char a2)
{
_BOOL4 v3; // ebp
unsigned __int8 v4; // r13
__int16 *v5; // rsi
char result; // al
__int16 *v7; // rsi

v3 = (a2 & 8) == 0;
v4 = a2 & 7;
if ( pio_C[8 * (a1 ^ 1) + 4 * ((a2 & 8) != 0)] == 1 )
{
if ( !verbose_pio )
goto LABEL_7;
v7 = &aAbms[2];
if ( a1 )
v7 = &aAbms[3];
printf("PIO C Write PORT Mismatch : side = %s\n", (const char *)v7);
}
if ( !pio_C[8 * a1 + 4 * v3] && verbose_pio )
{
v5 = &aAbms[2];
if ( a1 )
v5 = &aAbms[3];
printf("PIO C Write to READ-PORT : side = %s\n", (const char *)v5);
}
LABEL_7:
if ( (a2 & 1) != 0 )
result = LOBYTE(pio_C[8 * a1 + 3 + 4 * v3]) | (1 << (v4 >> 1));
else
result = LOBYTE(pio_C[8 * a1 + 3 + 4 * v3]) & ~(1 << (v4 >> 1));
LOBYTE(pio_C[8 * a1 + 3 + 4 * v3]) = result;
if ( cpu_timing == 1 && !a1 )
{
result = CPU_1_COUNT;
dual_cpu_count = CPU_1_COUNT;
z80_state_intchk = 0;
z80_state_goal = 1;
}
return result;
}

original_code:
void pio_write_C( int side, byte data )
{
  int port;
  if( data & 0x08 ) port = (0);
  else port = (1);
  data &= 0x07;
  if( pio_C[ side^1 ][ port^1 ].type == (1) ){
    if( verbose_pio ) printf( "PIO C Write PORT Mismatch" " : side = %s\n", (side==(0))?"M":"S" );
  }
  if( pio_C[ side ][ port ].type == (0) ){
    if( verbose_pio ) printf( "PIO C Write to READ-PORT" " : side = %s\n", (side==(0))?"M":"S" );
  }
  if( data & 0x01 ) pio_C[ side ][ port ].data |= ( 1 << (data>>1) );
  else pio_C[ side ][ port ].data &= ~( 1 << (data>>1) );
  switch( cpu_timing ){
  case 0:
  case 2:
    break;
  case 1:
    if( side==(0) ){
      dual_cpu_count = CPU_1_COUNT;
      do{ z80_state_intchk = 0; z80_state_goal = 1; }while(0);
    }
    break;
  }
  return;
}

canonical_original_code:
void pio_write_C(int side, unsigned char data)
{
  int port;
  if( data & 0x08 ) port = (0);
  else port = (1);
  data &= 0x07;
  if( pio_C[ side^1 ][ port^1 ].type == (1) ){
    if( verbose_pio ) printf( "PIO C Write PORT Mismatch" " : side = %s\n", (side==(0))?"M":"S" );
  }
  if( pio_C[ side ][ port ].type == (0) ){
    if( verbose_pio ) printf( "PIO C Write to READ-PORT" " : side = %s\n", (side==(0))?"M":"S" );
  }
  if( data & 0x01 ) pio_C[ side ][ port ].data |= ( 1 << (data>>1) );
  else pio_C[ side ][ port ].data &= ~( 1 << (data>>1) );
  switch( cpu_timing ){
  case 0:
  case 2:
    break;
  case 1:
    if( side==(0) ){
      dual_cpu_count = CPU_1_COUNT;
      do{ z80_state_intchk = 0; z80_state_goal = 1; }while(0);
    }
    break;
  }
  return;
}


decompiled_code:
__int64 __fastcall pio_write_C_direct(int a1, unsigned __int8 a2)
{
__int16 *v3; // rsi
__int64 result; // rax
__int16 *v5; // rsi

if ( pio_C[8 * (a1 ^ 1)] == 1 && pio_C[8 * (a1 ^ 1) + 4] == 1 && verbose_pio )
{
v5 = &aAbms[2];
if ( a1 )
v5 = &aAbms[3];
printf("PIO C WRITE PORT Mismatch : side = %s\n", (const char *)v5);
}
if ( !pio_C[8 * a1] && !pio_C[8 * a1 + 4] && verbose_pio )
{
v3 = &aAbms[2];
if ( a1 )
v3 = &aAbms[3];
printf("PIO C Write to READ-PORT : side = %s\n", (const char *)v3);
}
result = 32LL * a1;
*((_BYTE *)&pio_C[3] + result) = a2 >> 4;
*((_BYTE *)&pio_C[7] + result) = a2 & 0xF;
if ( cpu_timing == 1 && !a1 )
{
result = CPU_1_COUNT;
dual_cpu_count = CPU_1_COUNT;
z80_state_intchk = 0;
z80_state_goal = 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, unsigned __int8 a2)
{
__int16 *v3; // rsi
__int64 result; // rax
__int16 *v5; // rsi

if ( pio_C[8 * (a1 ^ 1)] == 1 && pio_C[8 * (a1 ^ 1) + 4] == 1 && verbose_pio )
{
v5 = &aAbms[2];
if ( a1 )
v5 = &aAbms[3];
printf("PIO C WRITE PORT Mismatch : side = %s\n", (const char *)v5);
}
if ( !pio_C[8 * a1] && !pio_C[8 * a1 + 4] && verbose_pio )
{
v3 = &aAbms[2];
if ( a1 )
v3 = &aAbms[3];
printf("PIO C Write to READ-PORT : side = %s\n", (const char *)v3);
}
result = 32LL * a1;
*((_BYTE *)&pio_C[3] + result) = a2 >> 4;
*((_BYTE *)&pio_C[7] + result) = a2 & 0xF;
if ( cpu_timing == 1 && !a1 )
{
result = CPU_1_COUNT;
dual_cpu_count = CPU_1_COUNT;
z80_state_intchk = 0;
z80_state_goal = 1;
}
return result;
}

original_code:
void pio_write_C_direct( int side, byte data )
{
  if( pio_C[ side^1 ][ (0) ].type == (1) &&
      pio_C[ side^1 ][ (1) ].type == (1) ){
    if( verbose_pio ) printf( "PIO C WRITE PORT Mismatch" " : side = %s\n", (side==(0))?"M":"S" );
  }
  if( pio_C[ side ][ (0) ].type == (0) &&
      pio_C[ side ][ (1) ].type == (0) ){
    if( verbose_pio ) printf( "PIO C Write to READ-PORT" " : side = %s\n", (side==(0))?"M":"S" );
  }
  pio_C[ side ][ (0) ].data = data >> 4;
  pio_C[ side ][ (1) ].data = data & 0x0f;
  switch( cpu_timing ){
  case 0:
  case 2:
    break;
  case 1:
    if( side==(0) ){
      dual_cpu_count = CPU_1_COUNT;
      do{ z80_state_intchk = 0; z80_state_goal = 1; }while(0);
    }
    break;
  }
  return;
}

canonical_original_code:
void pio_write_C_direct(int side, unsigned char data)
{
  if( pio_C[ side^1 ][ (0) ].type == (1) &&
      pio_C[ side^1 ][ (1) ].type == (1) ){
    if( verbose_pio ) printf( "PIO C WRITE PORT Mismatch" " : side = %s\n", (side==(0))?"M":"S" );
  }
  if( pio_C[ side ][ (0) ].type == (0) &&
      pio_C[ side ][ (1) ].type == (0) ){
    if( verbose_pio ) printf( "PIO C Write to READ-PORT" " : side = %s\n", (side==(0))?"M":"S" );
  }
  pio_C[ side ][ (0) ].data = data >> 4;
  pio_C[ side ][ (1) ].data = data & 0x0f;
  switch( cpu_timing ){
  case 0:
  case 2:
    break;
  case 1:
    if( side==(0) ){
      dual_cpu_count = CPU_1_COUNT;
      do{ z80_state_intchk = 0; z80_state_goal = 1; }while(0);
    }
    break;
  }
  return;
}


decompiled_code:
_BOOL8 statesave_pio()
{
return (unsigned int)statesave_table("PIO ", &suspend_pio_work) == 0;
}

canonical_decompiled_code:
_BOOL8 func7()
{
return (unsigned int)statesave_table("PIO ", &suspend_pio_work) == 0;
}

original_code:
int statesave_pio( void )
{
  if( statesave_table( "PIO ", suspend_pio_work ) == (0) ) return (1);
  else return (0);
}

canonical_original_code:
int statesave_pio()
{
  if( statesave_table( "PIO ", suspend_pio_work ) == (0) ) return (1);
  else return (0);
}


decompiled_code:
_BOOL8 stateload_pio()
{
return (unsigned int)stateload_table("PIO ", &suspend_pio_work) == 0;
}

canonical_decompiled_code:
_BOOL8 func8()
{
return (unsigned int)stateload_table("PIO ", &suspend_pio_work) == 0;
}

original_code:
int stateload_pio( void )
{
  if( stateload_table( "PIO ", suspend_pio_work ) == (0) ) return (1);
  else return (0);
}

canonical_original_code:
int stateload_pio()
{
  if( stateload_table( "PIO ", suspend_pio_work ) == (0) ) return (1);
  else return (0);
}


decompiled_code:
__int64 __fastcall sub_fetch(unsigned __int16 a1)
{
if ( memory_wait && a1 <= 0x3FFFu )
++z80sub_cpu[10];
return *(unsigned __int8 *)(sub_romram + (a1 & 0x7FFF));
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int16 a1)
{
if ( memory_wait && a1 <= 0x3FFFu )
++z80sub_cpu[10];
return *(unsigned __int8 *)(sub_romram + (a1 & 0x7FFF));
}

original_code:
byte sub_fetch( word addr )
{
  if( memory_wait ){
    if( addr < 0x4000 )
      z80sub_cpu.state0 += 1;
  }
  return sub_romram[ addr & 0x7fff ];
}

canonical_original_code:
unsigned char sub_fetch(unsigned short addr)
{
  if( memory_wait ){
    if( addr < 0x4000 )
      z80sub_cpu.state0 += 1;
  }
  return sub_romram[ addr & 0x7fff ];
}

variable_types:
addr
unsigned short


decompiled_code:
__int64 __fastcall sub_mem_read(__int16 a1)
{
return *(unsigned __int8 *)(sub_romram + (a1 & 0x7FFF));
}

canonical_decompiled_code:
__int64 __fastcall func1(__int16 a1)
{
return *(unsigned __int8 *)(sub_romram + (a1 & 0x7FFF));
}

original_code:
byte sub_mem_read( word addr )
{
  return sub_romram[ addr & 0x7fff ];
}

canonical_original_code:
unsigned char sub_mem_read(unsigned short addr)
{
  return sub_romram[ addr & 0x7fff ];
}


decompiled_code:
__int64 sub_INT_chk()
{
z80sub_cpu[8] = 0;
return (unsigned int)-(FDC_flag == 0);
}

canonical_decompiled_code:
__int64 func2()
{
z80sub_cpu[8] = 0;
return (unsigned int)-(FDC_flag == 0);
}

original_code:
int sub_INT_chk( void )
{
  z80sub_cpu.INT_active = (0);
  if( FDC_flag ) return 0;
  else return -1;
}

canonical_original_code:
int sub_INT_chk()
{
  z80sub_cpu.INT_active = (0);
  if( FDC_flag ) return 0;
  else return -1;
}


decompiled_code:
__int16 __fastcall sub_mem_write(unsigned __int16 a1, char a2)
{
__int16 result; // ax

result = a1 & 0xC000;
if ( (a1 & 0xC000) == 0x4000 )
{
result = sub_romram;
*(_BYTE *)(sub_romram + (a1 & 0x7FFF)) = a2;
}
else
{
if ( verbose_io )
result = printf("SUB Memory Write BAD %04x\n", a1);
if ( (a1 & 0x4000) != 0 )
{
result = sub_romram;
*(_BYTE *)(sub_romram + (a1 & 0x7FFF)) = a2;
}
}
return result;
}

canonical_decompiled_code:
__int16 __fastcall func3(unsigned __int16 a1, char a2)
{
__int16 result; // ax

result = a1 & 0xC000;
if ( (a1 & 0xC000) == 0x4000 )
{
result = sub_romram;
*(_BYTE *)(sub_romram + (a1 & 0x7FFF)) = a2;
}
else
{
if ( verbose_io )
result = printf("SUB Memory Write BAD %04x\n", a1);
if ( (a1 & 0x4000) != 0 )
{
result = sub_romram;
*(_BYTE *)(sub_romram + (a1 & 0x7FFF)) = a2;
}
}
return result;
}

original_code:
void sub_mem_write( word addr, byte data )
{
  if( (addr & 0xc000) == 0x4000 ){
    sub_romram[ addr & 0x7fff ] = data;
  }else{
    if( verbose_io ) printf("SUB Memory Write BAD %04x\n",addr);
    if( (addr & 0x4000 ) == 0x4000 ){
      sub_romram[ addr & 0x7fff ] = data;
    }
  }
}

canonical_original_code:
void sub_mem_write(unsigned short addr, unsigned char data)
{
  if( (addr & 0xc000) == 0x4000 ){
    sub_romram[ addr & 0x7fff ] = data;
  }else{
    if( verbose_io ) printf("SUB Memory Write BAD %04x\n",addr);
    if( (addr & 0x4000 ) == 0x4000 ){
      sub_romram[ addr & 0x7fff ] = data;
    }
  }
}


decompiled_code:
int __fastcall sub_io_out(unsigned __int8 a1, unsigned __int8 a2)
{
int result; // eax

if ( a1 < 0xF4u )
{
LABEL_11:
if ( verbose_io )
result = printf("SUB OUT data %02X to undecoeded port %02XH\n", a2, a1);
}
else
{
result = (unsigned __int8)(a1 + 12);
switch ( a1 )
{
case 0xF4:
case 0xF7:
case 0xF8:
return result;
case 0xF5:
case 0xF6:
case 0xF9:
case 0xFA:
goto LABEL_11;
case 0xFB:
result = fdc_write(a2);
z80_state_intchk = 0;
break;
case 0xFC:
result = pio_write_AB(1LL, 0LL, a2);
break;
case 0xFD:
result = pio_write_AB(1LL, 1LL, a2);
break;
case 0xFE:
result = pio_write_C_direct(1LL, a2);
break;
case 0xFF:
if ( (a2 & 0x80u) != 0 )
result = pio_set_mode(1LL, a2);
else
result = pio_write_C(1LL, a2);
break;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(unsigned __int8 a1, unsigned __int8 a2)
{
int result; // eax

if ( a1 < 0xF4u )
{
LABEL_11:
if ( verbose_io )
result = printf("SUB OUT data %02X to undecoeded port %02XH\n", a2, a1);
}
else
{
result = (unsigned __int8)(a1 + 12);
switch ( a1 )
{
case 0xF4:
case 0xF7:
case 0xF8:
return result;
case 0xF5:
case 0xF6:
case 0xF9:
case 0xFA:
goto LABEL_11;
case 0xFB:
result = fdc_write(a2);
z80_state_intchk = 0;
break;
case 0xFC:
result = pio_write_AB(1LL, 0LL, a2);
break;
case 0xFD:
result = pio_write_AB(1LL, 1LL, a2);
break;
case 0xFE:
result = pio_write_C_direct(1LL, a2);
break;
case 0xFF:
if ( (a2 & 0x80u) != 0 )
result = pio_set_mode(1LL, a2);
else
result = pio_write_C(1LL, a2);
break;
}
}
return result;
}

original_code:
void sub_io_out( byte port, byte data )
{
  switch( port ){
  case 0xf4:
    return;
  case 0xf7:
    return;
  case 0xf8:
    return;
  case 0xfb:
    fdc_write( data );
    do{ z80_state_intchk = 0; }while(0);
    return;
  case 0xfc:
    if(1){}else printf("   <==%02x\n",data);
    pio_write_AB( (1), (0), data );
    return;
  case 0xfd:
    if(1){}else printf("   <--%02x\n",data);
    pio_write_AB( (1), (1), data );
    return;
  case 0xfe:
    pio_write_C_direct( (1), data );
    return;
  case 0xff:
    if( data & 0x80 ) pio_set_mode( (1), data );
    else pio_write_C( (1), data );
    return;
  }
  if( verbose_io ) printf("SUB OUT data %02X to undecoeded port %02XH\n",data,port);
}

canonical_original_code:
void sub_io_out(unsigned char port, unsigned char data)
{
  switch( port ){
  case 0xf4:
    return;
  case 0xf7:
    return;
  case 0xf8:
    return;
  case 0xfb:
    fdc_write( data );
    do{ z80_state_intchk = 0; }while(0);
    return;
  case 0xfc:
    if(1){}else printf("   <==%02x\n",data);
    pio_write_AB( (1), (0), data );
    return;
  case 0xfd:
    if(1){}else printf("   <--%02x\n",data);
    pio_write_AB( (1), (1), data );
    return;
  case 0xfe:
    pio_write_C_direct( (1), data );
    return;
  case 0xff:
    if( data & 0x80 ) pio_set_mode( (1), data );
    else pio_write_C( (1), data );
    return;
  }
  if( verbose_io ) printf("SUB OUT data %02X to undecoeded port %02XH\n",data,port);
}

variable_types:
port
unsigned char


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

switch ( a1 )
{
case 0xF8:
z80_state_intchk = 0;
fdc_TC();
result = 0xFFFFFFFFLL;
break;
case 0xFA:
z80_state_intchk = 0;
result = fdc_status();
break;
case 0xFB:
z80_state_intchk = 0;
result = fdc_read();
break;
case 0xFC:
result = pio_read_AB(1LL, 0LL);
break;
case 0xFD:
result = pio_read_AB(1LL, 1LL);
break;
case 0xFE:
result = pio_read_C(1LL);
break;
default:
result = 0xFFFFFFFFLL;
if ( verbose_io )
{
printf("SUB IN from undecoeded port %02XH\n", a1);
result = 0xFFFFFFFFLL;
}
break;
}
return result;
}

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

switch ( a1 )
{
case 0xF8:
z80_state_intchk = 0;
fdc_TC();
result = 0xFFFFFFFFLL;
break;
case 0xFA:
z80_state_intchk = 0;
result = fdc_status();
break;
case 0xFB:
z80_state_intchk = 0;
result = fdc_read();
break;
case 0xFC:
result = pio_read_AB(1LL, 0LL);
break;
case 0xFD:
result = pio_read_AB(1LL, 1LL);
break;
case 0xFE:
result = pio_read_C(1LL);
break;
default:
result = 0xFFFFFFFFLL;
if ( verbose_io )
{
printf("SUB IN from undecoeded port %02XH\n", a1);
result = 0xFFFFFFFFLL;
}
break;
}
return result;
}

original_code:
byte sub_io_in( byte port )
{
  switch( port ){
  case 0xf8:
    do{ z80_state_intchk = 0; }while(0);
    fdc_TC();
    return 0xff;
  case 0xfa:
    do{ z80_state_intchk = 0; }while(0);
    return fdc_status();
  case 0xfb:
    do{ z80_state_intchk = 0; }while(0);
    return fdc_read();
  case 0xfc:
    {
      byte data = pio_read_AB( (1), (0) );
      if(1){}else printf("   ==>%02x\n",data);
      return data;
    }
  case 0xfd:
    {
      byte data = pio_read_AB( (1), (1) );
      if(1){}else printf("   -->%02x\n",data);
      return data;
    }
  case 0xfe:
    return pio_read_C( (1) );
  }
  if( verbose_io ) printf("SUB IN        from undecoeded port %02XH\n",port);
  return 0xff;
}

canonical_original_code:
unsigned char sub_io_in(unsigned char port)
{
  switch( port ){
  case 0xf8:
    do{ z80_state_intchk = 0; }while(0);
    fdc_TC();
    return 0xff;
  case 0xfa:
    do{ z80_state_intchk = 0; }while(0);
    return fdc_status();
  case 0xfb:
    do{ z80_state_intchk = 0; }while(0);
    return fdc_read();
  case 0xfc:
    {
      unsigned char data = pio_read_AB( (1), (0) );
      if(1){}else printf("   ==>%02x\n",data);
      return data;
    }
  case 0xfd:
    {
      unsigned char data = pio_read_AB( (1), (1) );
      if(1){}else printf("   -->%02x\n",data);
      return data;
    }
  case 0xfe:
    return pio_read_C( (1) );
  }
  if( verbose_io ) printf("SUB IN        from undecoeded port %02XH\n",port);
  return 0xff;
}


decompiled_code:
__int64 __fastcall sub_INT_update(__int64 a1, __int64 a2)
{
__int64 v2; // rdi
int v3; // ebx
__int64 result; // rax
__int64 v5; // rdx

v2 = (unsigned int)z80sub_cpu[10];
v3 = fdc_ctrl(v2);
z80sub_cpu[8] = FDC_flag != 0;
if ( sub_load_rate )
{
if ( cpu_timing <= 1 )
{
sub_total_state_0 += z80sub_cpu[10];
v5 = (unsigned int)(sub_total_state_0 >> 31);
if ( sub_total_state_0 / sub_load_rate >= state_of_vsync )
{
LODWORD(v5) = sub_total_state_0 % sub_load_rate;
event_handle(v2, a2, v5);
draw_screen();
sub_total_state_0 = 0;
}
}
}
if ( v3 < 0 )
v3 = 999999;
z80sub_cpu[9] = v3;
result = next_emu_mode();
if ( (_DWORD)result )
{
z80_state_intchk = 0;
z80_state_goal = 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
__int64 v2; // rdi
int v3; // ebx
__int64 result; // rax
__int64 v5; // rdx

v2 = (unsigned int)z80sub_cpu[10];
v3 = fdc_ctrl(v2);
z80sub_cpu[8] = FDC_flag != 0;
if ( sub_load_rate )
{
if ( cpu_timing <= 1 )
{
sub_total_state_0 += z80sub_cpu[10];
v5 = (unsigned int)(sub_total_state_0 >> 31);
if ( sub_total_state_0 / sub_load_rate >= state_of_vsync )
{
LODWORD(v5) = sub_total_state_0 % sub_load_rate;
event_handle(v2, a2, v5);
draw_screen();
sub_total_state_0 = 0;
}
}
}
if ( v3 < 0 )
v3 = 999999;
z80sub_cpu[9] = v3;
result = next_emu_mode();
if ( (_DWORD)result )
{
z80_state_intchk = 0;
z80_state_goal = 1;
}
return result;
}

original_code:
void sub_INT_update( void )
{
  static int sub_total_state = 0;
  int icount;
  icount = fdc_ctrl( z80sub_cpu.state0 );
  if( FDC_flag ){ z80sub_cpu.INT_active = (1); }
  else { z80sub_cpu.INT_active = (0); }
  if( sub_load_rate && cpu_timing < 2 ){
    sub_total_state += z80sub_cpu.state0;
    if( sub_total_state/sub_load_rate >= state_of_vsync ){
      event_handle();
      draw_screen();
      sub_total_state = 0;
    }
  }
  z80sub_cpu.icount = (icount<0) ? 999999 : icount;
  if( next_emu_mode() != EXEC ) do{ z80_state_intchk = 0; z80_state_goal = 1; }while(0);
}

canonical_original_code:
void sub_INT_update()
{
  static int sub_total_state = 0;
  int icount;
  icount = fdc_ctrl( z80sub_cpu.state0 );
  if( FDC_flag ){ z80sub_cpu.INT_active = (1); }
  else { z80sub_cpu.INT_active = (0); }
  if( sub_load_rate && cpu_timing < 2 ){
    sub_total_state += z80sub_cpu.state0;
    if( sub_total_state/sub_load_rate >= state_of_vsync ){
      event_handle();
      draw_screen();
      sub_total_state = 0;
    }
  }
  z80sub_cpu.icount = (icount<0) ? 999999 : icount;
  if( next_emu_mode() != EXEC ) do{ z80_state_intchk = 0; z80_state_goal = 1; }while(0);
}

variable_types: icount int


decompiled_code:
void sub_INT_init()
{
FDC_flag = 0;
}

canonical_decompiled_code:
void func8()
{
FDC_flag = 0;
}

original_code:
void sub_INT_init( void )
{
  FDC_flag = (0);
}

canonical_original_code:
void sub_INT_init()
{
  FDC_flag = (0);
}


decompiled_code:
void pc88sub_term()
{
;
}

canonical_decompiled_code:
void func9()
{
;
}

original_code:
void pc88sub_term( void )
{
}

canonical_original_code:
void pc88sub_term()
{
}


decompiled_code:
__int64 __fastcall sub_fetch_with_BP(unsigned __int16 a1)
{
check_break_point(2, a1, "FETCH from");
return sub_fetch(a1);
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned __int16 a1)
{
func7(2, a1, "FETCH from");
return func0(a1);
}

original_code:
byte sub_fetch_with_BP( word addr )
{
  check_break_point( BP_READ, addr, "FETCH from" );
  return sub_fetch( addr );
}

canonical_original_code:
unsigned char sub_fetch_with_BP(unsigned short addr)
{
  check_break_point( BP_READ, addr, "FETCH from" );
  return sub_fetch( addr );
}


decompiled_code:
__int64 __fastcall sub_mem_read_with_BP(__int16 a1)
{
check_break_point(2, a1, "READ from");
return sub_mem_read(a1);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int16 a1)
{
func7(2, a1, "READ from");
return func1(a1);
}

original_code:
byte sub_mem_read_with_BP( word addr )
{
  check_break_point( BP_READ, addr, "READ from" );
  return sub_mem_read( addr );
}

canonical_original_code:
unsigned char sub_mem_read_with_BP(unsigned short addr)
{
  check_break_point( BP_READ, addr, "READ from" );
  return sub_mem_read( addr );
}


decompiled_code:
__int16 __fastcall sub_mem_write_with_BP(unsigned __int16 a1, char a2)
{
check_break_point(3, a1, "WRITE to");
return sub_mem_write(a1, a2);
}

canonical_decompiled_code:
__int16 __fastcall func12(unsigned __int16 a1, char a2)
{
func7(3, a1, "WRITE to");
return func3(a1, a2);
}

original_code:
void sub_mem_write_with_BP( word addr, byte data )
{
  check_break_point( BP_WRITE, addr, "WRITE to" );
  sub_mem_write( addr, data );
}

canonical_original_code:
void sub_mem_write_with_BP(unsigned short addr, unsigned char data)
{
  check_break_point( BP_WRITE, addr, "WRITE to" );
  sub_mem_write( addr, data );
}


decompiled_code:
__int64 __fastcall sub_io_in_with_BP(unsigned __int8 a1)
{
check_break_point(4, a1, "IN from");
return sub_io_in(a1);
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned __int8 a1)
{
func7(4, a1, "IN from");
return func5(a1);
}

original_code:
byte sub_io_in_with_BP( byte port )
{
  check_break_point( BP_IN, port, "IN from" );
  return sub_io_in( port );
}

canonical_original_code:
unsigned char sub_io_in_with_BP(unsigned char port)
{
  check_break_point( BP_IN, port, "IN from" );
  return sub_io_in( port );
}


decompiled_code:
int __fastcall sub_io_out_with_BP(unsigned __int8 a1, unsigned __int8 a2)
{
check_break_point(5, a1, "OUT to");
return sub_io_out(a1, a2);
}

canonical_decompiled_code:
int __fastcall func14(unsigned __int8 a1, unsigned __int8 a2)
{
func7(5, a1, "OUT to");
return func4(a1, a2);
}

original_code:
void sub_io_out_with_BP( byte port, byte data )
{
  check_break_point( BP_OUT, port, "OUT to" );
  sub_io_out( port, data );
}

canonical_original_code:
void sub_io_out_with_BP(unsigned char port, unsigned char data)
{
  check_break_point( BP_OUT, port, "OUT to" );
  sub_io_out( port, data );
}


decompiled_code:
void *pc88sub_bus_setup()
{
void *result; // rax

result = sub_fetch;
if ( !memory_wait )
result = sub_mem_read;
*(_QWORD *)&z80sub_cpu[14] = result;
*(_QWORD *)&z80sub_cpu[16] = sub_mem_read;
*(_QWORD *)&z80sub_cpu[18] = sub_mem_write;
*(_QWORD *)&z80sub_cpu[20] = sub_io_in;
*(_QWORD *)&z80sub_cpu[22] = sub_io_out;
return result;
}

canonical_decompiled_code:
void *func15()
{
void *result; // rax

result = sub_fetch;
if ( !memory_wait )
result = sub_mem_read;
*(_QWORD *)&z80sub_cpu[14] = result;
*(_QWORD *)&z80sub_cpu[16] = sub_mem_read;
*(_QWORD *)&z80sub_cpu[18] = sub_mem_write;
*(_QWORD *)&z80sub_cpu[20] = sub_io_in;
*(_QWORD *)&z80sub_cpu[22] = sub_io_out;
return result;
}

original_code:
void pc88sub_bus_setup( void )
{
  if( memory_wait ){
    z80sub_cpu.fetch = sub_fetch;
  }else{
    z80sub_cpu.fetch = sub_mem_read;
  }
  z80sub_cpu.mem_read = sub_mem_read;
  z80sub_cpu.mem_write = sub_mem_write;
  z80sub_cpu.io_read = sub_io_in;
  z80sub_cpu.io_write = sub_io_out;
}

canonical_original_code:
void pc88sub_bus_setup()
{
  if( memory_wait ){
    z80sub_cpu.fetch = sub_fetch;
  }else{
    z80sub_cpu.fetch = sub_mem_read;
  }
  z80sub_cpu.mem_read = sub_mem_read;
  z80sub_cpu.mem_write = sub_mem_write;
  z80sub_cpu.io_read = sub_io_in;
  z80sub_cpu.io_write = sub_io_out;
}


decompiled_code:
void __fastcall pc88sub_init(unsigned int a1)
{
if ( a1 <= 1 )
{
z80_reset(z80sub_cpu);
pc88sub_bus_setup();
*(_QWORD *)&z80sub_cpu[24] = sub_INT_update;
*(_QWORD *)&z80sub_cpu[26] = sub_INT_chk;
BYTE1(z80sub_cpu[12]) = 1;
LOWORD(z80sub_cpu[28]) = z80sub_cpu[3];
LOBYTE(z80sub_cpu[12]) = 0;
sub_INT_init();
}
else
{
pc88sub_bus_setup();
*(_QWORD *)&z80sub_cpu[24] = sub_INT_update;
*(_QWORD *)&z80sub_cpu[26] = sub_INT_chk;
BYTE1(z80sub_cpu[12]) = 1;
LOWORD(z80sub_cpu[28]) = z80sub_cpu[3];
LOBYTE(z80sub_cpu[12]) = 0;
}
}

canonical_decompiled_code:
void __fastcall func16(unsigned int a1)
{
if ( a1 <= 1 )
{
z80_reset(z80sub_cpu);
func15();
*(_QWORD *)&z80sub_cpu[24] = sub_INT_update;
*(_QWORD *)&z80sub_cpu[26] = sub_INT_chk;
BYTE1(z80sub_cpu[12]) = 1;
LOWORD(z80sub_cpu[28]) = z80sub_cpu[3];
LOBYTE(z80sub_cpu[12]) = 0;
func8();
}
else
{
func15();
*(_QWORD *)&z80sub_cpu[24] = sub_INT_update;
*(_QWORD *)&z80sub_cpu[26] = sub_INT_chk;
BYTE1(z80sub_cpu[12]) = 1;
LOWORD(z80sub_cpu[28]) = z80sub_cpu[3];
LOBYTE(z80sub_cpu[12]) = 0;
}
}

original_code:
void pc88sub_init( int init )
{
  if( init == (0) || init == (1) ){
    z80_reset( &z80sub_cpu );
  }
  pc88sub_bus_setup();
  z80sub_cpu.intr_update = sub_INT_update;
  z80sub_cpu.intr_ack = sub_INT_chk;
  z80sub_cpu.break_if_halt = (1);
  z80sub_cpu.PC_prev = z80sub_cpu.PC;
  z80sub_cpu.log = (0);
  if( init == (0) || init == (1) ){
    sub_INT_init();
  }
}

canonical_original_code:
void pc88sub_init(int init)
{
  if( init == (0) || init == (1) ){
    z80_reset( &z80sub_cpu );
  }
  pc88sub_bus_setup();
  z80sub_cpu.intr_update = sub_INT_update;
  z80sub_cpu.intr_ack = sub_INT_chk;
  z80sub_cpu.break_if_halt = (1);
  z80sub_cpu.PC_prev = z80sub_cpu.PC;
  z80sub_cpu.log = (0);
  if( init == (0) || init == (1) ){
    sub_INT_init();
  }
}

variable_types: init int


decompiled_code:
_BOOL8 statesave_pc88sub()
{
return (unsigned int)statesave_table("SUB ", &suspend_pc88sub_work) == 0;
}

canonical_decompiled_code:
_BOOL8 func17()
{
return (unsigned int)statesave_table("SUB ", &suspend_pc88sub_work) == 0;
}

original_code:
int statesave_pc88sub( void )
{
  if( statesave_table( "SUB ", suspend_pc88sub_work ) == (0) ) return (1);
  else return (0);
}

canonical_original_code:
int statesave_pc88sub()
{
  if( statesave_table( "SUB ", suspend_pc88sub_work ) == (0) ) return (1);
  else return (0);
}


decompiled_code:
_BOOL8 stateload_pc88sub()
{
return (unsigned int)stateload_table("SUB ", &suspend_pc88sub_work) == 0;
}

canonical_decompiled_code:
_BOOL8 func18()
{
return (unsigned int)stateload_table("SUB ", &suspend_pc88sub_work) == 0;
}

original_code:
int stateload_pc88sub( void )
{
  if( stateload_table( "SUB ", suspend_pc88sub_work ) == (0) ) return (1);
  else return (0);
}

canonical_original_code:
int stateload_pc88sub()
{
  if( stateload_table( "SUB ", suspend_pc88sub_work ) == (0) ) return (1);
  else return (0);
}


decompiled_code:
__int64 __fastcall check_break_point(int a1, unsigned __int16 a2, const char *a3)
{
__int64 result; // rax

result = get_emu_mode();
if ( (_DWORD)result != 5 )
{
result = 0LL;
while ( break_point[2 * result + 20] != a1 || break_point[2 * result + 21] != a2 )
{
if ( ++result == 10 )
return result;
}
printf("*** Break at %04x *** ( SUB[#%d] : %s %04x )\n", LOWORD(z80sub_cpu[3]), (unsigned int)(result + 1), a3, a2);
result = set_emu_mode(5LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, unsigned __int16 a2, const char *a3)
{
__int64 result; // rax

result = get_emu_mode();
if ( (_DWORD)result != 5 )
{
result = 0LL;
while ( break_point[2 * result + 20] != a1 || break_point[2 * result + 21] != a2 )
{
if ( ++result == 10 )
return result;
}
printf("*** Break at %04x *** ( SUB[#%d] : %s %04x )\n", LOWORD(z80sub_cpu[3]), (unsigned int)(result + 1), a3, a2);
result = set_emu_mode(5LL);
}
return result;
}

original_code:
static __inline__ void check_break_point( int type, word addr, char *str )
{
  int i;
  if ( get_emu_mode() == MONITOR ) return;
  for( i=0; i<(10); i++ ){
    if( break_point[BP_SUB][i].type == type &&
        break_point[BP_SUB][i].addr == addr ){
      printf( "*** Break at %04x *** ( SUB[#%d] : %s %04x )\n",
       z80sub_cpu.PC.W, i+1, str, addr );
      set_emu_mode( MONITOR );
      break;
    }
  }
}

canonical_original_code:
static __inline__ void check_break_point(int type, unsigned short addr, char *str)
{
  int i;
  if ( get_emu_mode() == MONITOR ) return;
  for( i=0; i<(10); i++ ){
    if( break_point[BP_SUB][i].type == type &&
        break_point[BP_SUB][i].addr == addr ){
      printf( "*** Break at %04x *** ( SUB[#%d] : %s %04x )\n",
       z80sub_cpu.PC.W, i+1, str, addr );
      set_emu_mode( MONITOR );
      break;
    }
  }
}

variable_types: type int

variable_types:
str
char *


decompiled_code:
void *filter_alloc()
{
return malloc(0x6CuLL);
}

canonical_decompiled_code:
void *func0()
{
return malloc(0x6CuLL);
}

original_code:
static filter* filter_alloc(void) {
 filter* f = malloc(sizeof(filter));
 return f;
}

canonical_original_code:
static struct filter_struct *filter_alloc() {
 struct filter_struct *f = malloc(sizeof(filter));
 return f;
}

variable_types: struct filter_struct { int xcoeffs[-1]; unsigned int order; } *


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

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

original_code:
void filter_free(filter* f) {
 free(f);
}

canonical_original_code:
void filter_free(struct filter_struct *f) {
 free(f);
}

user_defined_types: struct filter_struct { int xcoeffs[-1]; unsigned int order; }


decompiled_code:
void __fastcall filter_state_reset(__int64 a1, _DWORD *a2)
{
__int64 v2; // rax

*a2 = 0;
if ( *(_DWORD *)(a1 + 104) )
{
v2 = 0LL;
do
a2[++v2] = 0;
while ( *(_DWORD *)(a1 + 104) > (unsigned int)v2 );
}
}

original_code:
void filter_state_reset(filter* f, filter_state* s) {
 int i;
 s->prev_mac = 0;
 for(i=0;i<f->order;++i) {
  s->xprev[i] = 0;
 }
}

canonical_original_code:
void filter_state_reset(struct filter_struct *f, struct filter_state_struct *s) {
 int i;
 s->prev_mac = 0;
 for(i=0;i<f->order;++i) {
  s->xprev[i] = 0;
 }
}

variable_types: struct filter_state_struct { unsigned int prev_mac; int xprev[51]; } *

variable_types: i int


decompiled_code:
_DWORD *filter_state_alloc()
{
_DWORD *v0; // rcx
_DWORD *v1; // rax

v0 = malloc(0xD0uLL);
*v0 = 0;
v1 = v0 + 1;
do
*v1++ = 0;
while ( v1 != v0 + 52 );
return v0;
}

canonical_decompiled_code:
_DWORD *func3()
{
_DWORD *v0; // rcx
_DWORD *v1; // rax

v0 = malloc(0xD0uLL);
*v0 = 0;
v1 = v0 + 1;
do
*v1++ = 0;
while ( v1 != v0 + 52 );
return v0;
}

original_code:
filter_state* filter_state_alloc(void) {
 int i;
        filter_state* s = malloc(sizeof(filter_state));
 s->prev_mac = 0;
 for(i=0;i<51;++i)
  s->xprev[i] = 0;
 return s;
}

canonical_original_code:
struct filter_state_struct *filter_state_alloc() {
 int i;
        struct filter_state_struct *s = malloc(sizeof(filter_state));
 s->prev_mac = 0;
 for(i=0;i<51;++i)
  s->xprev[i] = 0;
 return s;
}

return_type: struct filter_state_struct { unsigned int prev_mac; int xprev[51]; } *


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

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

original_code:
void filter_state_free(filter_state* s) {
 free(s);
}

canonical_original_code:
void filter_state_free(struct filter_state_struct *s) {
 free(s);
}

user_defined_types: struct filter_state_struct { unsigned int prev_mac; int xprev[51]; }


decompiled_code:
__int64 __fastcall filter_compute(_DWORD *a1, unsigned int *a2)
{
unsigned int v4; // ebx
unsigned int v5; // er9
unsigned int v6; // ecx
unsigned int v7; // eax
unsigned int v8; // esi
int v9; // er8

v4 = a1[26];
v5 = v4 >> 1;
v6 = *a2;
v7 = *a2 + 1;
if ( v4 == v7 )
v7 = 0;
if ( v4 <= 1 )
{
v9 = 0;
}
else
{
v8 = 0;
v9 = 0;
do
{
v9 += a1[v5 - v8] * (a2[v6 + 1] + a2[++v7]);
if ( v4 == v7 )
v7 = 0;
if ( v6-- == 0 )
v6 = v4 - 1;
++v8;
}
while ( v5 > v8 );
}
return (unsigned int)((int)(v9 + a2[v6 + 1] * *a1) >> 15);
}

canonical_decompiled_code:
__int64 __fastcall func5(_DWORD *a1, unsigned int *a2)
{
unsigned int v4; // ebx
unsigned int v5; // er9
unsigned int v6; // ecx
unsigned int v7; // eax
unsigned int v8; // esi
int v9; // er8

v4 = a1[26];
v5 = v4 >> 1;
v6 = *a2;
v7 = *a2 + 1;
if ( v4 == v7 )
v7 = 0;
if ( v4 <= 1 )
{
v9 = 0;
}
else
{
v8 = 0;
v9 = 0;
do
{
v9 += a1[v5 - v8] * (a2[v6 + 1] + a2[++v7]);
if ( v4 == v7 )
v7 = 0;
if ( v6-- == 0 )
v6 = v4 - 1;
++v8;
}
while ( v5 > v8 );
}
return (unsigned int)((int)(v9 + a2[v6 + 1] * *a1) >> 15);
}

original_code:
filter_real filter_compute(filter* f, filter_state* s) {
 unsigned order = f->order;
 unsigned midorder = f->order / 2;
 filter_real y = 0;
 unsigned i,j,k;
 i = s->prev_mac;
 j = i + 1;
 if (j == order)
  j = 0;
 for(k=0;k<midorder;++k) {
  y += f->xcoeffs[midorder-k] * (s->xprev[i] + s->xprev[j]);
  ++j;
  if (j == order)
   j = 0;
  if (i == 0)
   i = order - 1;
  else
   --i;
 }
 y += f->xcoeffs[0] * s->xprev[i];
 return y >> 15;
}

canonical_original_code:
int filter_compute(struct filter_struct *f, struct filter_state_struct *s) {
 unsigned int order = f->order;
 unsigned int midorder = f->order / 2;
 int y = 0;
 unsigned int i; unsigned int j; unsigned int k;
 i = s->prev_mac;
 j = i + 1;
 if (j == order)
  j = 0;
 for(k=0;k<midorder;++k) {
  y += f->xcoeffs[midorder-k] * (s->xprev[i] + s->xprev[j]);
  ++j;
  if (j == order)
   j = 0;
  if (i == 0)
   i = order - 1;
  else
   --i;
 }
 y += f->xcoeffs[0] * s->xprev[i];
 return y >> 15;
}

variable_types:
order
unsigned int

variable_types:
midorder
unsigned int

variable_types: y int

variable_types:
i
unsigned int

variable_types:
j
unsigned int

variable_types:
k
unsigned int


decompiled_code:
__int64 statefile_revision()
{
return (unsigned int)statefile_rev;
}

canonical_decompiled_code:
__int64 func22()
{
return (unsigned int)statefile_rev;
}

original_code:
int statefile_revision( void )
{
  return statefile_rev;
}

canonical_original_code:
int statefile_revision()
{
  return statefile_rev;
}


statesave

decompiled_code:
__int64 statesave()
{
unsigned int v0; // ebx

if ( file_state )
{
if ( verbose_suspend )
printf("statesave : %s\n", &file_state);
statesave_fp = osd_fopen(13LL, &file_state, "wb");
v0 = 0;
if ( statesave_fp )
{
if ( !(unsigned int)statesave_header() )
{
v0 = statesave_emu();
if ( v0 )
{
v0 = statesave_memory();
if ( v0 )
{
v0 = statesave_pc88main();
if ( v0 )
{
v0 = statesave_crtcdmac();
if ( v0 )
{
v0 = statesave_sound();
if ( v0 )
{
v0 = statesave_pio();
if ( v0 )
{
v0 = statesave_screen();
if ( v0 )
{
v0 = statesave_intr();
if ( v0 )
{
v0 = statesave_keyboard();
if ( v0 )
{
v0 = statesave_pc88sub();
if ( v0 )
{
v0 = statesave_fdc();
if ( v0 )
v0 = statesave_system() != 0;
}
}
}
}
}
}
}
}
}
}
}
osd_fclose(statesave_fp);
}
}
else
{
puts("state-file name not defined");
v0 = 0;
}
return v0;
}

canonical_decompiled_code:
__int64 func24()
{
unsigned int v0; // ebx

if ( file_state )
{
if ( verbose_suspend )
printf("statesave : %s\n", &file_state);
statesave_fp = osd_fopen(13LL, &file_state, "wb");
v0 = 0;
if ( statesave_fp )
{
if ( !(unsigned int)func17() )
{
v0 = statesave_emu();
if ( v0 )
{
v0 = statesave_memory();
if ( v0 )
{
v0 = statesave_pc88main();
if ( v0 )
{
v0 = statesave_crtcdmac();
if ( v0 )
{
v0 = statesave_sound();
if ( v0 )
{
v0 = statesave_pio();
if ( v0 )
{
v0 = statesave_screen();
if ( v0 )
{
v0 = statesave_intr();
if ( v0 )
{
v0 = statesave_keyboard();
if ( v0 )
{
v0 = statesave_pc88sub();
if ( v0 )
{
v0 = statesave_fdc();
if ( v0 )
v0 = statesave_system() != 0;
}
}
}
}
}
}
}
}
}
}
}
osd_fclose(statesave_fp);
}
}
else
{
puts("state-file name not defined");
v0 = 0;
}
return v0;
}

original_code:
int statesave( void )
{
  int success = (0);
  if( file_state[0] == '\0' ){
    printf( "state-file name not defined\n" );
    return (0);
  }
  if( verbose_suspend )
    printf( "statesave : %s\n", file_state );
  if( (statesave_fp = osd_fopen( FTYPE_STATE_SAVE, file_state, "wb" )) ){
    if( statesave_header() == (0) ){
      do{
 if( statesave_emu() == (0) ) break;
 if( statesave_memory() == (0) ) break;
 if( statesave_pc88main() == (0) ) break;
 if( statesave_crtcdmac() == (0) ) break;
 if( statesave_sound() == (0) ) break;
 if( statesave_pio() == (0) ) break;
 if( statesave_screen() == (0) ) break;
 if( statesave_intr() == (0) ) break;
 if( statesave_keyboard() == (0) ) break;
 if( statesave_pc88sub() == (0) ) break;
 if( statesave_fdc() == (0) ) break;
 if( statesave_system() == (0) ) break;
 success = (1);
      }while(0);
    }
    osd_fclose( statesave_fp );
  }
  return success;
}

canonical_original_code:
int statesave()
{
  int success = (0);
  if( file_state[0] == '\0' ){
    printf( "state-file name not defined\n" );
    return (0);
  }
  if( verbose_suspend )
    printf( "statesave : %s\n", file_state );
  if( (statesave_fp = osd_fopen( FTYPE_STATE_SAVE, file_state, "wb" )) ){
    if( statesave_header() == (0) ){
      do{
 if( statesave_emu() == (0) ) break;
 if( statesave_memory() == (0) ) break;
 if( statesave_pc88main() == (0) ) break;
 if( statesave_crtcdmac() == (0) ) break;
 if( statesave_sound() == (0) ) break;
 if( statesave_pio() == (0) ) break;
 if( statesave_screen() == (0) ) break;
 if( statesave_intr() == (0) ) break;
 if( statesave_keyboard() == (0) ) break;
 if( statesave_pc88sub() == (0) ) break;
 if( statesave_fdc() == (0) ) break;
 if( statesave_system() == (0) ) break;
 success = (1);
      }while(0);
    }
    osd_fclose( statesave_fp );
  }
  return success;
}

variable_types: success int


decompiled_code:
__int64 stateload_check()
{
unsigned int v0; // ebx
int v2; // ebp
const char *v3; // rsi

if ( file_state && (stateload_fp = osd_fopen(12LL, &file_state, "rb")) != 0 )
{
v2 = stateload_header();
v0 = v2 == 0;
osd_fclose(stateload_fp);
if ( verbose_suspend )
{
v3 = "OK";
if ( v2 )
v3 = "FAILED";
if ( !v2 )
v0 = 1;
goto LABEL_10;
}
}
else
{
v0 = verbose_suspend;
if ( verbose_suspend )
{
v0 = 0;
v3 = "FAILED";
LABEL_10:
printf("stateload: file check ... %s\n", v3);
return v0;
}
}
return v0;
}

canonical_decompiled_code:
__int64 func25()
{
unsigned int v0; // ebx
int v2; // ebp
const char *v3; // rsi

if ( file_state && (stateload_fp = osd_fopen(12LL, &file_state, "rb")) != 0 )
{
v2 = func16();
v0 = v2 == 0;
osd_fclose(stateload_fp);
if ( verbose_suspend )
{
v3 = "OK";
if ( v2 )
v3 = "FAILED";
if ( !v2 )
v0 = 1;
goto LABEL_10;
}
}
else
{
v0 = verbose_suspend;
if ( verbose_suspend )
{
v0 = 0;
v3 = "FAILED";
LABEL_10:
printf("stateload: file check ... %s\n", v3);
return v0;
}
}
return v0;
}

original_code:
int stateload_check( void )
{
  int success = (0);
  if( file_state[0] &&
      (stateload_fp = osd_fopen( FTYPE_STATE_LOAD, file_state, "rb" )) ){
    if( stateload_header() == (0) ){
      success = (1);
    }
    osd_fclose( stateload_fp );
  }
  if( verbose_suspend ){
    printf( "stateload: file check ... %s\n", (success)?"OK":"FAILED" );
  }
  return success;
}

canonical_original_code:
int stateload_check()
{
  int success = (0);
  if( file_state[0] &&
      (stateload_fp = osd_fopen( FTYPE_STATE_LOAD, file_state, "rb" )) ){
    if( stateload_header() == (0) ){
      success = (1);
    }
    osd_fclose( stateload_fp );
  }
  if( verbose_suspend ){
    printf( "stateload: file check ... %s\n", (success)?"OK":"FAILED" );
  }
  return success;
}


stateload

decompiled_code:
__int64 stateload()
{
unsigned int v0; // ebx

if ( file_state )
{
if ( verbose_suspend )
printf("stateload: %s\n", &file_state);
stateload_fp = osd_fopen(12LL, &file_state, "rb");
v0 = 0;
if ( stateload_fp )
{
if ( !(unsigned int)stateload_header() )
{
v0 = stateload_emu();
if ( v0 )
{
v0 = stateload_sound();
if ( v0 )
{
v0 = stateload_memory();
if ( v0 )
{
v0 = stateload_pc88main();
if ( v0 )
{
v0 = stateload_crtcdmac();
if ( v0 )
{
v0 = stateload_pio();
if ( v0 )
{
v0 = stateload_screen();
if ( v0 )
{
v0 = stateload_intr();
if ( v0 )
{
v0 = stateload_keyboard();
if ( v0 )
{
v0 = stateload_pc88sub();
if ( v0 )
{
v0 = stateload_fdc();
if ( v0 )
v0 = stateload_system() != 0;
}
}
}
}
}
}
}
}
}
}
}
osd_fclose(stateload_fp);
}
}
else
{
puts("state-file name not defined");
v0 = 0;
}
return v0;
}

canonical_decompiled_code:
__int64 func26()
{
unsigned int v0; // ebx

if ( file_state )
{
if ( verbose_suspend )
printf("stateload: %s\n", &file_state);
stateload_fp = osd_fopen(12LL, &file_state, "rb");
v0 = 0;
if ( stateload_fp )
{
if ( !(unsigned int)func16() )
{
v0 = stateload_emu();
if ( v0 )
{
v0 = stateload_sound();
if ( v0 )
{
v0 = stateload_memory();
if ( v0 )
{
v0 = stateload_pc88main();
if ( v0 )
{
v0 = stateload_crtcdmac();
if ( v0 )
{
v0 = stateload_pio();
if ( v0 )
{
v0 = stateload_screen();
if ( v0 )
{
v0 = stateload_intr();
if ( v0 )
{
v0 = stateload_keyboard();
if ( v0 )
{
v0 = stateload_pc88sub();
if ( v0 )
{
v0 = stateload_fdc();
if ( v0 )
v0 = stateload_system() != 0;
}
}
}
}
}
}
}
}
}
}
}
osd_fclose(stateload_fp);
}
}
else
{
puts("state-file name not defined");
v0 = 0;
}
return v0;
}

original_code:
int stateload( void )
{
  int success = (0);
  if( file_state[0] == '\0' ){
    printf( "state-file name not defined\n" );
    return (0);
  }
  if( verbose_suspend )
    printf( "stateload: %s\n", file_state );
  if( (stateload_fp = osd_fopen( FTYPE_STATE_LOAD, file_state, "rb" )) ){
    if( stateload_header() == (0) ){
      do{
 if( stateload_emu() == (0) ) break;
 if( stateload_sound() == (0) ) break;
 if( stateload_memory() == (0) ) break;
 if( stateload_pc88main() == (0) ) break;
 if( stateload_crtcdmac() == (0) ) break;
 if( stateload_pio() == (0) ) break;
 if( stateload_screen() == (0) ) break;
 if( stateload_intr() == (0) ) break;
 if( stateload_keyboard() == (0) ) break;
 if( stateload_pc88sub() == (0) ) break;
 if( stateload_fdc() == (0) ) break;
 if( stateload_system() == (0) ) break;
 success = (1);
      }while(0);
    }
    osd_fclose( stateload_fp );
  }
  return success;
}

canonical_original_code:
int stateload()
{
  int success = (0);
  if( file_state[0] == '\0' ){
    printf( "state-file name not defined\n" );
    return (0);
  }
  if( verbose_suspend )
    printf( "stateload: %s\n", file_state );
  if( (stateload_fp = osd_fopen( FTYPE_STATE_LOAD, file_state, "rb" )) ){
    if( stateload_header() == (0) ){
      do{
 if( stateload_emu() == (0) ) break;
 if( stateload_sound() == (0) ) break;
 if( stateload_memory() == (0) ) break;
 if( stateload_pc88main() == (0) ) break;
 if( stateload_crtcdmac() == (0) ) break;
 if( stateload_pio() == (0) ) break;
 if( stateload_screen() == (0) ) break;
 if( stateload_intr() == (0) ) break;
 if( stateload_keyboard() == (0) ) break;
 if( stateload_pc88sub() == (0) ) break;
 if( stateload_fdc() == (0) ) break;
 if( stateload_system() == (0) ) break;
 success = (1);
      }while(0);
    }
    osd_fclose( stateload_fp );
  }
  return success;
}


decompiled_code:
void stateload_init()
{
if ( (!file_state || resume_flag && !resume_file) && !(unsigned int)set_state_filename(1LL) )
{
puts("stateload: Intarnal err...");
resume_flag = 0;
}
}

canonical_decompiled_code:
void func27()
{
if ( (!file_state || resume_flag && !resume_file) && !(unsigned int)set_state_filename(1LL) )
{
puts("stateload: Intarnal err...");
resume_flag = 0;
}
}

original_code:
void stateload_init( void )
{
  if( file_state[0] == '\0' ||
      ( resume_flag && resume_file == (0) ) ){
    if( set_state_filename( (1) ) == (0) ){
      printf( "stateload: Intarnal err...\n" );
      resume_flag = (0);
    }
  }
}

canonical_original_code:
void stateload_init()
{
  if( file_state[0] == '\0' ||
      ( resume_flag && resume_file == (0) ) ){
    if( set_state_filename( (1) ) == (0) ){
      printf( "stateload: Intarnal err...\n" );
      resume_flag = (0);
    }
  }
}


decompiled_code:
__int64 sysdep_mixer_list_plugins()
{
fwrite("Sound mixer plugins:\n\n", 1uLL, 0x16uLL, stdout);
plugin_manager_list_plugins(sysdep_mixer_plugin_manager, stdout);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func0()
{
fwrite("Sound mixer plugins:\n\n", 1uLL, 0x16uLL, stdout);
plugin_manager_list_plugins(sysdep_mixer_plugin_manager, stdout);
return 0xFFFFFFFFLL;
}

original_code:
static int sysdep_mixer_list_plugins(struct rc_option *option,
   const char *arg, int priority)
{
   fprintf(stdout, "Sound mixer plugins:\n\n");
   plugin_manager_list_plugins(sysdep_mixer_plugin_manager, stdout);
   return -1;
}

canonical_original_code:
static int sysdep_mixer_list_plugins(struct rc_option *option, char *arg, int priority)
{
   fprintf(stdout, "Sound mixer plugins:\n\n");
   plugin_manager_list_plugins(sysdep_mixer_plugin_manager, stdout);
   return -1;
}

variable_types: struct rc_option { char *name; char *shortname; int type; void *dest; char *deflt; float min; float max; int (*func)(struct rc_option *option, char *arg, int priority); char *help; int priority; } *

variable_types:
arg
char *

variable_types: priority int


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

if ( sysdep_mixer_plugin_manager )
{
result = plugin_manager_destroy();
sysdep_mixer_plugin_manager = 0LL;
}
if ( sysdep_mixer_rc )
{
result = rc_unregister(sysdep_mixer_rc, &sysdep_mixer_opts);
sysdep_mixer_rc = 0LL;
}
return result;
}

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

if ( sysdep_mixer_plugin_manager )
{
result = plugin_manager_destroy();
sysdep_mixer_plugin_manager = 0LL;
}
if ( sysdep_mixer_rc )
{
result = rc_unregister(sysdep_mixer_rc, &sysdep_mixer_opts);
sysdep_mixer_rc = 0LL;
}
return result;
}

original_code:
void sysdep_mixer_exit(void)
{
   if(sysdep_mixer_plugin_manager)
   {
      plugin_manager_destroy(sysdep_mixer_plugin_manager);
      sysdep_mixer_plugin_manager = ((void *)0);
   }
   if(sysdep_mixer_rc)
   {
      rc_unregister(sysdep_mixer_rc, sysdep_mixer_opts);
      sysdep_mixer_rc = ((void *)0);
   }
}

canonical_original_code:
void sysdep_mixer_exit()
{
   if(sysdep_mixer_plugin_manager)
   {
      plugin_manager_destroy(sysdep_mixer_plugin_manager);
      sysdep_mixer_plugin_manager = ((void *)0);
   }
   if(sysdep_mixer_rc)
   {
      rc_unregister(sysdep_mixer_rc, sysdep_mixer_opts);
      sysdep_mixer_rc = ((void *)0);
   }
}


decompiled_code:
__int64 __fastcall sysdep_mixer_channel_available(__int64 a1, int a2)
{
return (unsigned int)*(char *)(a2 + a1 + 4);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
return (unsigned int)*(char *)(a2 + a1 + 4);
}

original_code:
int sysdep_mixer_channel_available(struct sysdep_mixer_struct *mixer,
   int channel)
{
   return mixer->channel_available[channel];
}

variable_types: struct sysdep_mixer_struct { int flags; char channel_available[10]; char restore_channel[10]; int cache_left[10]; int cache_right[10]; int orig_left[10]; int orig_right[10]; void *_priv; int (*set)(struct sysdep_mixer_struct *mixer, int channel, int left, int right); int (*get)(struct sysdep_mixer_struct *mixer, int channel, int *left, int *right); void (*destroy)(struct sysdep_mixer_struct *mixer); } *

variable_types: channel int


decompiled_code:
__int64 __fastcall sysdep_mixer_set(__int64 a1, int a2, int a3, int a4)
{
__int64 result; // rax

if ( !*(_BYTE *)(a1 + a2 + 4) )
return 0xFFFFFFFFLL;
if ( (*(unsigned int (**)(void))(a1 + 192))() )
return 0xFFFFFFFFLL;
*(_DWORD *)(a1 + 4LL * a2 + 24) = a3;
*(_DWORD *)(a1 + 4LL * a2 + 64) = a4;
result = *(_DWORD *)a1 & 1;
if ( (*(_DWORD *)a1 & 1) != 0 )
{
*(_BYTE *)(a1 + a2 + 14) = 1;
result = 0LL;
}
return result;
}

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

if ( !*(_BYTE *)(a1 + a2 + 4) )
return 0xFFFFFFFFLL;
if ( (*(unsigned int (**)(void))(a1 + 192))() )
return 0xFFFFFFFFLL;
*(_DWORD *)(a1 + 4LL * a2 + 24) = a3;
*(_DWORD *)(a1 + 4LL * a2 + 64) = a4;
result = *(_DWORD *)a1 & 1;
if ( (*(_DWORD *)a1 & 1) != 0 )
{
*(_BYTE *)(a1 + a2 + 14) = 1;
result = 0LL;
}
return result;
}

original_code:
int sysdep_mixer_set(struct sysdep_mixer_struct *mixer, int channel,
   int left, int right)
{
   if(!mixer->channel_available[channel])
      return -1;
   if(mixer->set(mixer, channel, left, right))
      return -1;
   mixer->cache_left[channel] = left;
   mixer->cache_right[channel] = right;
   if(mixer->flags & 0x01)
      mixer->restore_channel[channel] = 1;
   return 0;
}

variable_types: left int

variable_types: right int

user_defined_types: struct sysdep_mixer_struct { int flags; char channel_available[10]; char restore_channel[10]; int cache_left[10]; int cache_right[10]; int orig_left[10]; int orig_right[10]; void *_priv; int (*set)(struct sysdep_mixer_struct *mixer, int channel, int left, int right); int (*get)(struct sysdep_mixer_struct *mixer, int channel, int *left, int *right); void (*destroy)(struct sysdep_mixer_struct *mixer); }


original_code:
int sysdep_mixer_get(struct sysdep_mixer_struct *mixer, int channel,
   int *left, int *right)
{
   if(!mixer->channel_available[channel])
      return -1;
   if(mixer->get(mixer, channel, left, right))
      return -1;
   if((*left >= (mixer->cache_left[channel] - 5)) &&
      (*left <= (mixer->cache_left[channel] + 5)) &&
      (*right >= (mixer->cache_right[channel] - 5)) &&
      (*right <= (mixer->cache_right[channel] + 5)))
   {
      *left = mixer->cache_left[channel];
      *right = mixer->cache_right[channel];
   }
   else
   {
      mixer->restore_channel[channel] = 0;
      mixer->cache_left[channel] = *left;
      mixer->cache_right[channel] = *right;
      mixer->orig_left[channel] = *left;
      mixer->orig_right[channel] = *right;
   }
   return 0;
}

variable_types:
left
int *

variable_types:
right
int *


decompiled_code:
__int64 __fastcall sysdep_mixer_destroy(__int64 a1)
{
__int64 i; // rbx
int v3; // [rsp+8h] [rbp-20h] BYREF
int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

for ( i = 0LL; i != 10; ++i )
{
sysdep_mixer_get(a1, i, v4, &v3);
if ( *(_BYTE *)(a1 + i + 14) )
sysdep_mixer_set(a1, i, *(_DWORD *)(a1 + 4 * i + 104), *(_DWORD *)(a1 + 4 * i + 144));
}
return (*(__int64 (__fastcall **)(__int64))(a1 + 208))(a1);
}

original_code:
void sysdep_mixer_destroy(struct sysdep_mixer_struct *mixer)
{
   int i, left, right;
   for(i = 0; i < 10; i++)
   {
      sysdep_mixer_get(mixer, i, &left, &right);
      if(mixer->restore_channel[i])
      {
         sysdep_mixer_set(mixer, i, mixer->orig_left[i],
            mixer->orig_right[i]);
      }
   }
   mixer->destroy(mixer);
}

canonical_original_code:
void sysdep_mixer_destroy(struct sysdep_mixer_struct *mixer)
{
   int i; int left; int right;
   for(i = 0; i < 10; i++)
   {
      sysdep_mixer_get(mixer, i, &left, &right);
      if(mixer->restore_channel[i])
      {
         sysdep_mixer_set(mixer, i, mixer->orig_left[i],
            mixer->orig_right[i]);
      }
   }
   mixer->destroy(mixer);
}

variable_types: i int


decompiled_code:
__int64 __fastcall sysdep_mixer_create(__int64 a1, __int64 a2, int a3)
{
__int64 v4; // rax
__int64 v5; // r12
_DWORD *v6; // rbx
__int64 i; // rbp
__int64 v9[6]; // [rsp+8h] [rbp-30h] BYREF

v9[0] = a2;
if ( !a1 )
a1 = sysdep_mixer_plugin;
v4 = plugin_manager_create_instance(sysdep_mixer_plugin_manager, a1, v9);
v5 = v4;
if ( v4 )
{
v6 = (_DWORD *)(v4 + 24);
for ( i = 0LL; i != 10; ++i )
{
if ( *(_BYTE *)(v5 + i + 4) )
{
if ( (*(unsigned int (__fastcall **)(__int64, _QWORD, _DWORD *, _DWORD *))(v5 + 200))(
v5,
(unsigned int)i,
v6,
v6 + 10) )
{
sysdep_mixer_destroy(v5);
return 0LL;
}
v6[20] = *v6;
v6[30] = v6[10];
}
++v6;
}
*(_DWORD *)v5 = a3;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, int a3)
{
__int64 v4; // rax
__int64 v5; // r12
_DWORD *v6; // rbx
__int64 i; // rbp
__int64 v9[6]; // [rsp+8h] [rbp-30h] BYREF

v9[0] = a2;
if ( !a1 )
a1 = sysdep_mixer_plugin;
v4 = plugin_manager_create_instance(sysdep_mixer_plugin_manager, a1, v9);
v5 = v4;
if ( v4 )
{
v6 = (_DWORD *)(v4 + 24);
for ( i = 0LL; i != 10; ++i )
{
if ( *(_BYTE *)(v5 + i + 4) )
{
if ( (*(unsigned int (__fastcall **)(__int64, _QWORD, _DWORD *, _DWORD *))(v5 + 200))(
v5,
(unsigned int)i,
v6,
v6 + 10) )
{
func6(v5);
return 0LL;
}
v6[20] = *v6;
v6[30] = v6[10];
}
++v6;
}
*(_DWORD *)v5 = a3;
}
return v5;
}

original_code:
struct sysdep_mixer_struct *sysdep_mixer_create(const char *plugin,
   const char *device, int flags)
{
   int i;
   struct sysdep_mixer_struct *mixer = ((void *)0);
   struct sysdep_mixer_create_params params;
   params.device = device;
   if(!(mixer = plugin_manager_create_instance(sysdep_mixer_plugin_manager,
      plugin? plugin:sysdep_mixer_plugin, &params)))
      return ((void *)0);
   for(i = 0; i < 10; i++)
   {
      if(mixer->channel_available[i])
      {
         if(mixer->get(mixer, i, &mixer->cache_left[i],
            &mixer->cache_right[i]))
         {
            sysdep_mixer_destroy(mixer);
            return ((void *)0);
         }
         mixer->orig_left[i] = mixer->cache_left[i];
         mixer->orig_right[i] = mixer->cache_right[i];
      }
   }
   mixer->flags = flags;
   return mixer;
}

canonical_original_code:
struct sysdep_mixer_struct *sysdep_mixer_create(char *plugin, char *device, int flags)
{
   int i;
   struct sysdep_mixer_struct *mixer = ((void *)0);
   struct sysdep_mixer_create_params params;
   params.device = device;
   if(!(mixer = plugin_manager_create_instance(sysdep_mixer_plugin_manager,
      plugin? plugin:sysdep_mixer_plugin, &params)))
      return ((void *)0);
   for(i = 0; i < 10; i++)
   {
      if(mixer->channel_available[i])
      {
         if(mixer->get(mixer, i, &mixer->cache_left[i],
            &mixer->cache_right[i]))
         {
            sysdep_mixer_destroy(mixer);
            return ((void *)0);
         }
         mixer->orig_left[i] = mixer->cache_left[i];
         mixer->orig_right[i] = mixer->cache_right[i];
      }
   }
   mixer->flags = flags;
   return mixer;
}

variable_types:
plugin
char *

variable_types:
device
char *

variable_types: flags int

variable_types: struct sysdep_mixer_create_params { char *device; }

return_type: struct sysdep_mixer_struct { int flags; char channel_available[10]; char restore_channel[10]; int cache_left[10]; int cache_right[10]; int orig_left[10]; int orig_right[10]; void *_priv; int (*set)(struct sysdep_mixer_struct *mixer, int channel, int left, int right); int (*get)(struct sysdep_mixer_struct *mixer, int channel, int *left, int *right); void (*destroy)(struct sysdep_mixer_struct *mixer); } *


original_code: static __inline__ int sample_buf_fifo_get(struct sample_buf_fifo_struct *fifo, struct sound_stream_sample_buf * *data) { if(!fifo->in_use) return -1; *data = fifo->buffer[fifo->head]; fifo->head = (fifo->head + 1) % fifo->size; fifo->in_use--; return 0; }

canonical_original_code: static __inline__ int sample_buf_fifo_get(struct sample_buf_fifo_struct *fifo, struct sound_stream_sample_buf **data) { if(!fifo->in_use) return -1; *data = fifo->buffer[fifo->head]; fifo->head = (fifo->head + 1) % fifo->size; fifo->in_use--; return 0; }

variable_types: struct sample_buf_fifo_struct { int size; int head; int in_use; struct sound_stream_sample_buf { int length; int pos; unsigned char *data; } **buffer; } *

variable_types:
data
struct sound_stream_sample_buf **

user_defined_types: struct sample_buf_fifo_struct { int size; int head; int in_use; struct sound_stream_sample_buf **buffer; }


decompiled_code:
__int64 __fastcall sample_buf_fifo_peek(__int64 a1, _QWORD *a2)
{
if ( !*(_DWORD *)(a1 + 8) )
return 0xFFFFFFFFLL;
*a2 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * *(int *)(a1 + 4));
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, _QWORD *a2)
{
if ( !*(_DWORD *)(a1 + 8) )
return 0xFFFFFFFFLL;
*a2 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * *(int *)(a1 + 4));
return 0LL;
}

original_code: static __inline__ int sample_buf_fifo_peek(struct sample_buf_fifo_struct *fifo, struct sound_stream_sample_buf * *data) { if(!fifo->in_use) return -1; *data = fifo->buffer[fifo->head]; return 0; }

canonical_original_code: static __inline__ int sample_buf_fifo_peek(struct sample_buf_fifo_struct *fifo, struct sound_stream_sample_buf **data) { if(!fifo->in_use) return -1; *data = fifo->buffer[fifo->head]; return 0; }

user_defined_types: struct sound_stream_sample_buf { int length; int pos; unsigned char *data; }


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

v2 = (void *)*((_QWORD *)ptr + 2);
if ( v2 )
free(v2);
free(ptr);
}

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

v2 = (void *)*((_QWORD *)ptr + 2);
if ( v2 )
free(v2);
free(ptr);
}

original_code: static __inline__ void sample_buf_fifo_destroy(struct sample_buf_fifo_struct *fifo) { if(fifo->buffer) free(fifo->buffer); free(fifo); }


decompiled_code:
__int64 __fastcall oss_dsp_get_freespace(__int64 a1)
{
_DWORD v2[6]; // [rsp+0h] [rbp-18h] BYREF

if ( ioctl(**(_DWORD **)(a1 + 40), 0x8010500CuLL, v2) >= 0 )
return (unsigned int)(v2[3] / oss_dsp_bytes_per_sample[*(int *)(a1 + 4)]);
perror("error: SNDCTL_DSP_GETOSPACE");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
_DWORD v2[6]; // [rsp+0h] [rbp-18h] BYREF

if ( ioctl(**(_DWORD **)(a1 + 40), 0x8010500CuLL, v2) >= 0 )
return (unsigned int)(v2[3] / oss_dsp_bytes_per_sample[*(int *)(a1 + 4)]);
perror("error: SNDCTL_DSP_GETOSPACE");
return 0xFFFFFFFFLL;
}

original_code:
static int oss_dsp_get_freespace(struct sysdep_dsp_struct *dsp)
{
   audio_buf_info info;
   struct oss_dsp_priv_data *priv = dsp->_priv;
   if (ioctl(priv->fd, (((2U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((12)) << 0) | ((((sizeof(audio_buf_info)))) << ((0 +8)+8))), &info) < 0)
   {
      perror("error: SNDCTL_DSP_GETOSPACE");
      return -1;
   }
   return info.bytes / oss_dsp_bytes_per_sample[dsp->hw_info.type];
}

canonical_original_code:
static int oss_dsp_get_freespace(struct sysdep_dsp_struct *dsp)
{
   struct audio_buf_info info;
   struct oss_dsp_priv_data *priv = dsp->_priv;
   if (ioctl(priv->fd, (((2U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((12)) << 0) | ((((sizeof(audio_buf_info)))) << ((0 +8)+8))), &info) < 0)
   {
      perror("error: SNDCTL_DSP_GETOSPACE");
      return -1;
   }
   return info.bytes / oss_dsp_bytes_per_sample[dsp->hw_info.type];
}

variable_types: struct sysdep_dsp_struct { struct sysdep_dsp_info { int samplerate; int type; int bufsize; } hw_info; struct sysdep_dsp_info emu_info; unsigned char *convert_buf; long last_update; void *_priv; int (*get_freespace)(struct sysdep_dsp_struct *dsp); int (*write)(struct sysdep_dsp_struct *dsp, unsigned char *data, int count); void (*destroy)(struct sysdep_dsp_struct *dsp); } *

variable_types: struct audio_buf_info { int fragments; int fragstotal; int fragsize; int bytes; }

variable_types:
priv
struct oss_dsp_priv_data { int fd; } *

user_defined_types: struct sysdep_dsp_struct { struct sysdep_dsp_info hw_info; struct sysdep_dsp_info emu_info; unsigned char *convert_buf; long last_update; void *_priv; int (*get_freespace)(struct sysdep_dsp_struct *dsp); int (*write)(struct sysdep_dsp_struct *dsp, unsigned char *data, int count); void (*destroy)(struct sysdep_dsp_struct *dsp); }


decompiled_code:
__int64 __fastcall oss_dsp_write(__int64 a1, const void *a2, int a3)
{
int v3; // eax
__int64 result; // rax

v3 = write(**(_DWORD **)(a1 + 40), a2, oss_dsp_bytes_per_sample[*(int *)(a1 + 4)] * a3);
if ( v3 < 0 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)(v3 / oss_dsp_bytes_per_sample[*(int *)(a1 + 4)]);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const void *a2, int a3)
{
int v3; // eax
__int64 result; // rax

v3 = write(**(_DWORD **)(a1 + 40), a2, oss_dsp_bytes_per_sample[*(int *)(a1 + 4)] * a3);
if ( v3 < 0 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)(v3 / oss_dsp_bytes_per_sample[*(int *)(a1 + 4)]);
return result;
}

original_code:
static int oss_dsp_write(struct sysdep_dsp_struct *dsp, unsigned char *data,
   int count)
{
   int result;
   struct oss_dsp_priv_data *priv = dsp->_priv;
   result = write(priv->fd, data, count *
      oss_dsp_bytes_per_sample[dsp->hw_info.type]);
   if (result < 0)
      return -1;
   return result / oss_dsp_bytes_per_sample[dsp->hw_info.type];
}

variable_types:
data
unsigned char *

variable_types: count int

variable_types: result int

user_defined_types: struct sysdep_dsp_info { int samplerate; int type; int bufsize; }


decompiled_code:
void __fastcall oss_dsp_destroy(void *ptr)
{
int *v1; // rbp

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

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

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

original_code:
static void oss_dsp_destroy(struct sysdep_dsp_struct *dsp)
{
   struct oss_dsp_priv_data *priv = dsp->_priv;
   if (priv)
   {
      if (priv->fd >= 0)
         close(priv->fd);
      free(priv);
   }
   free(dsp);
}


decompiled_code:
__int64 the_end()
{
xmame_system_term();
return x11_system_term();
}

canonical_decompiled_code:
__int64 func0()
{
xmame_system_term();
return x11_system_term();
}

original_code:
static void the_end( void )
{
  xmame_system_term();
  x11_system_term();
}

canonical_original_code:
static void the_end()
{
  xmame_system_term();
  x11_system_term();
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__uid_t v3; // eax
int v4; // ebx

x11_system_init(argc, argv, envp);
v3 = getuid();
if ( setuid(v3) )
{
fprintf(stderr, "%s : setuid error\n", *argv);
x11_system_term();
v4 = -1;
}
else
{
v4 = 0;
if ( !getuid() )
snapshot_cmd_enable = 0;
xmame_system_init();
quasi88_atexit(the_end);
if ( (unsigned int)osd_environment() && (unsigned int)config_init((unsigned int)argc, argv) )
quasi88();
xmame_system_term();
x11_system_term();
}
return v4;
}

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


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

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

original_code:
int stateload_system( void )
{
  return (1);
}

canonical_original_code:
int stateload_system()
{
  return (1);
}


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

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

original_code:
int statesave_system( void )
{
  return (1);
}

canonical_original_code:
int statesave_system()
{
  return (1);
}


decompiled_code:
__int64 __fastcall about_msg_init(int a1)
{
about_lang = a1 != 0;
about_line = 0;
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
about_lang = a1 != 0;
about_line = 0;
return 0xFFFFFFFFLL;
}

original_code:
int about_msg_init( int japanese )
{
  about_lang = ( japanese ) ? 1 : 0;
  about_line = 0;
  return -1;
}

canonical_original_code:
int about_msg_init(int japanese)
{
  about_lang = ( japanese ) ? 1 : 0;
  about_line = 0;
  return -1;
}

variable_types: japanese int


decompiled_code:
_BOOL8 xmame_system_init()
{
__int64 v0; // rdi
_BOOL8 result; // rax
int v2; // edx
int v3; // edx

v0 = rc_create();
rc = v0;
result = 1LL;
if ( v0 )
{
v2 = sysdep_dsp_init(v0, 0LL);
result = 1LL;
if ( !v2 )
{
v3 = sysdep_mixer_init(rc, 0LL);
result = 1LL;
if ( !v3 )
result = (unsigned int)rc_register(rc, &sound_opts) != 0;
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 func0()
{
__int64 v0; // rdi
_BOOL8 result; // rax
int v2; // edx
int v3; // edx

v0 = rc_create();
rc = v0;
result = 1LL;
if ( v0 )
{
v2 = sysdep_dsp_init(v0, 0LL);
result = 1LL;
if ( !v2 )
{
v3 = sysdep_mixer_init(rc, 0LL);
result = 1LL;
if ( !v3 )
result = (unsigned int)rc_register(rc, &sound_opts) != 0;
}
}
return result;
}

original_code:
int xmame_system_init( void )
{
   if (!(rc = rc_create()))
      return (1);
   if(sysdep_dsp_init(rc, ((void *)0)))
      return (1);
   if(sysdep_mixer_init(rc, ((void *)0)))
      return (1);
   if(rc_register(rc, sound_opts))
      return (1);
   return (0);
}

canonical_original_code:
int xmame_system_init()
{
   if (!(rc = rc_create()))
      return (1);
   if(sysdep_dsp_init(rc, ((void *)0)))
      return (1);
   if(sysdep_mixer_init(rc, ((void *)0)))
      return (1);
   if(rc_register(rc, sound_opts))
      return (1);
   return (0);
}


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

if ( rc )
{
sysdep_mixer_exit();
sysdep_dsp_exit();
result = rc_destroy(rc);
}
return result;
}

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

if ( rc )
{
sysdep_mixer_exit();
sysdep_dsp_exit();
result = rc_destroy(rc);
}
return result;
}

original_code:
void xmame_system_term( void )
{
   if(rc)
   {
      sysdep_mixer_exit();
      sysdep_dsp_exit();
      rc_destroy(rc);
   }
}

canonical_original_code:
void xmame_system_term()
{
   if(rc)
   {
      sysdep_mixer_exit();
      sysdep_dsp_exit();
      rc_destroy(rc);
   }
}


decompiled_code:
__int64 __fastcall xmame_check_option(__int64 a1, __int64 a2, unsigned int a3)
{
return rc_quasi88(rc, a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, unsigned int a3)
{
return rc_quasi88(rc, a1, a2, a3);
}

original_code:
int xmame_check_option( char *arg1, char *arg2, int priority )
{
  return rc_quasi88( rc, arg1, arg2, priority );
}

canonical_original_code:
int xmame_check_option(char *arg1, char *arg2, int priority)
{
  return rc_quasi88( rc, arg1, arg2, priority );
}

variable_types: priority int