decompiled_code:
__int64 __fastcall operate8051(int *a1)
{
int v2; // ebp
char v3; // al
char v4; // dl
char v5; // al
char v6; // al
char v7; // dl
char v8; // al
unsigned __int8 v9; // al
unsigned __int8 v10; // si
unsigned __int8 v11; // al
unsigned __int8 v12; // dl
unsigned __int8 v13; // al
unsigned __int8 v14; // si
char v15; // r11
unsigned __int8 v16; // al
unsigned __int8 v17; // dl
int v18; // edi
unsigned __int8 v19; // si
int v20; // eax
unsigned __int8 v21; // si
int v22; // eax
int v23; // eax
int v24; // eax
char v25; // cl
unsigned __int8 v26; // si
int v27; // edx
unsigned __int8 v28; // cl
int v29; // edx
int v30; // eax
__int64 result; // rax
__int16 v32; // dx
int v33; // eax
int v34; // edx
char v35; // si
int v36; // er9
unsigned __int8 v37; // di
int v38; // edx
char v39; // al
char v40; // al
char v41; // al

v2 = *a1;
v3 = *((_BYTE *)a1 + 268);
if ( (v3 & 1) == 0 )
{
v4 = v3 | 2;
v5 = v3 & 0xFD;
if ( (a1[77] & 4) == 0 )
v5 = v4;
*((_BYTE *)a1 + 268) = v5;
}
v6 = *((_BYTE *)a1 + 268);
if ( (v6 & 4) == 0 )
{
v7 = v6 | 8;
v8 = v6 & 0xF7;
if ( (a1[77] & 8) == 0 )
v8 = v7;
*((_BYTE *)a1 + 268) = v8;
}
v9 = *((_BYTE *)a1 + 131460);
if ( (v9 & 8) != 0 )
{
v10 = v9 & 7;
v11 = v9 & 0xF0;
if ( v11 == 0x80 )
{
inst_mov_Rn_to_direct(a1, v10, *((unsigned __int8 *)a1 + 131461));
}
else if ( v11 > 0x80u )
{
if ( v11 == 0xC0 )
{
inst_xch_Rn(a1, v10);
}
else if ( v11 <= 0xC0u )
{
switch ( v11 )
{
case 0xA0:
inst_mov_direct_to_Rn(a1, v10, *((unsigned __int8 *)a1 + 131461));
break;
case 0xB0:
inst_cjne_data_with_Rn(a1, v10, *((unsigned __int8 *)a1 + 131461), *((unsigned __int8 *)a1 + 131462));
break;
case 0x90:
inst_subb_Rn(a1, v10);
break;
}
}
else
{
switch ( v11 )
{
case 0xE0:
inst_mov_Rn(a1, v10);
break;
case 0xF0:
inst_mov_to_Rn(a1, v10);
break;
case 0xD0:
inst_djnz_Rn(a1, v10, *((unsigned __int8 *)a1 + 131461));
break;
}
}
}
else if ( v11 == 64 )
{
inst_orl_Rn(a1, v10);
}
else if ( v11 <= 0x40u )
{
if ( v11 == 32 )
{
inst_add_Rn(a1, v10);
}
else if ( v11 <= 0x20u )
{
if ( v11 )
{
if ( v11 == 16 )
inst_dec_Rn(a1, v10);
}
else
{
inst_inc_Rn(a1, v10);
}
}
else if ( v11 == 48 )
{
inst_addc_Rn(a1, v10);
}
}
else
{
switch ( v11 )
{
case '`':
inst_xrl_Rn(a1, v10);
break;
case 'p':
inst_mov_data_to_Rn(a1, v10, *((unsigned __int8 *)a1 + 131461));
break;
case 'P':
inst_anl_Rn(a1, v10);
break;
}
}
}
else if ( (v9 & 6) == 6 )
{
v12 = v9 & 1;
v13 = v9 & 0xF0;
if ( v13 == 0x80 )
{
inst_mov_atRi_to_direct(a1, v12, *((unsigned __int8 *)a1 + 131461));
}
else if ( v13 > 0x80u )
{
if ( v13 == 0xC0 )
{
inst_xch_atRi(a1, v12);
}
else if ( v13 <= 0xC0u )
{
switch ( v13 )
{
case 0xA0:
inst_mov_direct_to_atRi(a1, v12, *((unsigned __int8 *)a1 + 131461));
break;
case 0xB0:
inst_cjne_data_with_atRi(a1, v12, *((unsigned __int8 *)a1 + 131461), *((unsigned __int8 *)a1 + 131462));
break;
case 0x90:
inst_subb_atRi(a1, v12);
break;
}
}
else
{
switch ( v13 )
{
case 0xE0:
inst_mov_atRi(a1, v12);
break;
case 0xF0:
inst_mov_to_atRi(a1, v12);
break;
case 0xD0:
inst_xchd_atRi(a1, v12);
break;
}
}
}
else if ( v13 == 64 )
{
inst_orl_atRi(a1, v12);
}
else if ( v13 <= 0x40u )
{
if ( v13 == 32 )
{
inst_add_atRi(a1, v12);
}
else if ( v13 <= 0x20u )
{
if ( v13 )
{
if ( v13 == 16 )
inst_dec_atRi(a1, v12);
}
else
{
inst_inc_atRi(a1, v12);
}
}
else if ( v13 == 48 )
{
inst_addc_atRi(a1, v12);
}
}
else
{
switch ( v13 )
{
case '`':
inst_xrl_atRi(a1, v12);
break;
case 'p':
inst_mov_data_to_atRi(a1, v12, *((unsigned __int8 *)a1 + 131461));
break;
case 'P':
inst_anl_atRi(a1, v12);
break;
}
}
}
else if ( (v9 & 0xF) == 1 )
{
v14 = v9 >> 5;
if ( (v9 & 0x10) != 0 )
inst_acall(a1, v14, *((unsigned __int8 *)a1 + 131461));
else
inst_ajmp(a1, v14, *((unsigned __int8 *)a1 + 131461));
}
else if ( (v9 & 0xEE) == 0xE2 )
{
v21 = v9 & 1;
if ( (v9 & 0x10) != 0 )
inst_movx_to_atRi(a1, v21);
else
inst_movx_atRi(a1, v21);
}
else
{
switch ( v9 )
{
case 0u:
inst_nop(a1);
break;
case 2u:
inst_ljmp(a1, *((unsigned __int8 *)a1 + 131461), *((unsigned __int8 *)a1 + 131462));
break;
case 3u:
inst_rr(a1);
break;
case 4u:
inst_inc(a1);
break;
case 5u:
inst_inc_direct(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x10u:
inst_jbc(a1, *((unsigned __int8 *)a1 + 131461), *((unsigned __int8 *)a1 + 131462));
break;
case 0x12u:
inst_lcall(a1, *((unsigned __int8 *)a1 + 131461), *((unsigned __int8 *)a1 + 131462));
break;
case 0x13u:
inst_rrc(a1);
break;
case 0x14u:
inst_dec(a1);
break;
case 0x15u:
inst_dec_direct(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x20u:
inst_jb(a1, *((unsigned __int8 *)a1 + 131461), *((unsigned __int8 *)a1 + 131462));
break;
case 0x22u:
inst_ret(a1);
break;
case 0x23u:
inst_rl(a1);
break;
case 0x24u:
inst_add_data(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x25u:
inst_add_direct(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x30u:
inst_jnb(a1, *((unsigned __int8 *)a1 + 131461), *((unsigned __int8 *)a1 + 131462));
break;
case 0x32u:
inst_reti(a1);
break;
case 0x33u:
inst_rlc(a1);
break;
case 0x34u:
inst_addc_data(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x35u:
inst_addc_direct(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x40u:
inst_jc(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x42u:
inst_orl_to_direct(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x43u:
inst_orl_data_to_direct(a1, *((unsigned __int8 *)a1 + 131461), *((unsigned __int8 *)a1 + 131462));
break;
case 0x44u:
inst_orl_data(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x45u:
inst_orl_direct(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x50u:
inst_jnc(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x52u:
inst_anl_to_direct(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x53u:
inst_anl_data_to_direct(a1, *((unsigned __int8 *)a1 + 131461), *((unsigned __int8 *)a1 + 131462));
break;
case 0x54u:
inst_anl_data(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x55u:
inst_anl_direct(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x60u:
inst_jz(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x62u:
inst_xrl_to_direct(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x63u:
inst_xrl_data_to_direct(a1, *((unsigned __int8 *)a1 + 131461), *((unsigned __int8 *)a1 + 131462));
break;
case 0x64u:
inst_xrl_data(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x65u:
inst_xrl_direct(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x70u:
inst_jnz(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x72u:
inst_orl_bit(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x73u:
inst_jmp_DPTR(a1);
break;
case 0x74u:
inst_mov_data(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x75u:
inst_mov_data_to_direct(a1, *((unsigned __int8 *)a1 + 131461), *((unsigned __int8 *)a1 + 131462));
break;
case 0x80u:
inst_sjmp(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x82u:
inst_anl_bit(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x83u:
inst_movc_PC(a1);
break;
case 0x84u:
inst_div(a1);
break;
case 0x85u:
inst_mov_direct_to_direct(a1, *((unsigned __int8 *)a1 + 131461), *((unsigned __int8 *)a1 + 131462));
break;
case 0x90u:
inst_mov_to_DPTR(a1, *((unsigned __int8 *)a1 + 131461), *((unsigned __int8 *)a1 + 131462));
break;
case 0x92u:
inst_mov_to_bit(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x93u:
inst_movc_DPTR(a1);
break;
case 0x94u:
inst_subb_data(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x95u:
inst_subb_direct(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0xA0u:
inst_orl_not_bit(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0xA2u:
inst_mov_bit(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0xA3u:
inst_inc_DPTR(a1);
break;
case 0xA4u:
inst_mul(a1);
break;
case 0xB0u:
inst_anl_not_bit(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0xB2u:
inst_cpl_bit(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0xB3u:
inst_cpl_C(a1);
break;
case 0xB4u:
inst_cjne_data(a1, *((unsigned __int8 *)a1 + 131461), *((unsigned __int8 *)a1 + 131462));
break;
case 0xB5u:
inst_cjne_direct(a1, *((unsigned __int8 *)a1 + 131461), *((unsigned __int8 *)a1 + 131462));
break;
case 0xC0u:
inst_push(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0xC2u:
inst_clr_bit(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0xC3u:
inst_clr_C(a1);
break;
case 0xC4u:
inst_swap(a1);
break;
case 0xC5u:
inst_xch_direct(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0xD0u:
inst_pop(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0xD2u:
inst_setb_bit(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0xD3u:
inst_setb_C(a1);
break;
case 0xD4u:
inst_da(a1);
break;
case 0xD5u:
inst_djnz_direct(a1, *((unsigned __int8 *)a1 + 131461), *((unsigned __int8 *)a1 + 131462));
break;
case 0xE0u:
inst_movx_atDPTR(a1);
break;
case 0xE4u:
inst_clr(a1);
break;
case 0xE5u:
inst_mov_direct(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0xF0u:
inst_movx_to_atDPTR(a1);
break;
case 0xF4u:
inst_cpl(a1);
break;
case 0xF5u:
inst_mov_to_direct(a1, *((unsigned __int8 *)a1 + 131461));
break;
default:
if ( v9 != 0xA5 )
_assert_fail("IR[0] == 0xA5", "vm/lib8051.c", 0x24Fu, "operate8051");
return result;
}
}
operate_coprocessors(a1);
v15 = *((_BYTE *)a1 + 268);
if ( (v15 & 0x10) == 0 )
{
v17 = *((_BYTE *)a1 + 269);
v24 = v17;
if ( (v17 & 3) != 3 )
goto LABEL_197;
LABEL_186:
v25 = *((_BYTE *)a1 + 268);
if ( (v25 & 0x40) != 0 )
{
v26 = *((_BYTE *)a1 + 272);
if ( (v17 & 0x40) == 0 )
{
v27 = *a1 + v26 - v2;
*((_BYTE *)a1 + 272) = *(_BYTE *)a1 + v26 - v2;
if ( (v27 & 0x100) != 0 )
*((_BYTE *)a1 + 268) = v25 | 0x80;
}
}
v28 = *((_BYTE *)a1 + 271);
goto LABEL_191;
}
v16 = *((_BYTE *)a1 + 270);
v17 = *((_BYTE *)a1 + 269);
if ( (v17 & 4) != 0 )
{
v18 = v16;
v19 = v17 & 3;
if ( (v17 & 3) == 2 )
{
*((_BYTE *)a1 + 270) = v16;
LABEL_182:
v24 = v17;
goto LABEL_197;
}
}
else
{
v22 = *a1 + v16 - v2;
v18 = v22;
v19 = v17 & 3;
if ( (v17 & 3) == 2 )
{
*((_BYTE *)a1 + 270) = v22;
if ( (v22 & 0x100) != 0 )
{
*((_BYTE *)a1 + 270) = *((_BYTE *)a1 + 272) + v22;
*((_BYTE *)a1 + 268) = v15 | 0x20;
}
goto LABEL_182;
}
}
if ( v19 > 2u )
{
*((_BYTE *)a1 + 270) = v18;
if ( (v18 & 0x100) != 0 )
*((_BYTE *)a1 + 268) = v15 | 0x20;
v24 = v17;
goto LABEL_186;
}
if ( !v19 )
{
v23 = v18 + 32 * *((unsigned __int8 *)a1 + 272);
*((_BYTE *)a1 + 270) = v18 & 0x1F;
*((_BYTE *)a1 + 272) = v23 >> 5;
if ( (v23 & 0x2000) != 0 )
*((_BYTE *)a1 + 268) = v15 | 0x20;
goto LABEL_182;
}
if ( v19 == 1 )
{
v20 = v18 + (*((unsigned __int8 *)a1 + 272) << 8);
*((_BYTE *)a1 + 270) = v18;
*((_BYTE *)a1 + 272) = BYTE1(v20);
if ( (v20 & 0x10000) != 0 )
*((_BYTE *)a1 + 268) = v15 | 0x20;
goto LABEL_182;
}
v17 = *((_BYTE *)a1 + 269);
v24 = v17;
LABEL_197:
if ( (a1[67] & 0x40) == 0 )
goto LABEL_194;
v28 = *((_BYTE *)a1 + 271);
if ( (v17 & 0x40) != 0 )
{
v29 = v28;
v30 = (v24 >> 4) & 3;
if ( v30 == 1 )
{
v32 = (*((unsigned __int8 *)a1 + 273) << 8) + v28;
*((_BYTE *)a1 + 271) = v28;
*((_BYTE *)a1 + 273) = HIBYTE(v32);
goto LABEL_194;
}
goto LABEL_192;
}
LABEL_191:
v29 = v28 + *a1 - v2;
v30 = (v24 >> 4) & 3;
if ( v30 != 1 )
{
LABEL_192:
if ( v30 == 2 )
{
*((_BYTE *)a1 + 271) = v29;
if ( (v29 & 0x100) != 0 )
{
*((_BYTE *)a1 + 271) = *((_BYTE *)a1 + 273) + v29;
*((_BYTE *)a1 + 268) |= 0x80u;
}
}
else if ( !v30 )
{
v33 = v29 + 32 * *((unsigned __int8 *)a1 + 273);
*((_BYTE *)a1 + 271) = v29 & 0x1F;
*((_BYTE *)a1 + 273) = v33 >> 5;
if ( (v33 & 0x2000) != 0 )
*((_BYTE *)a1 + 268) |= 0x80u;
}
goto LABEL_194;
}
v34 = (*((unsigned __int8 *)a1 + 273) << 8) + v29;
*((_BYTE *)a1 + 271) = v34;
*((_BYTE *)a1 + 273) = BYTE1(v34);
if ( (v34 & 0x10000) != 0 )
*((_BYTE *)a1 + 268) |= 0x80u;
LABEL_194:
result = *((unsigned __int8 *)a1 + 300);
if ( (result & 0x80u) == 0LL )
goto LABEL_195;
v35 = *((_BYTE *)a1 + 131466);
if ( (v35 & 2) != 0 || *((_BYTE *)a1 + 131467) )
goto LABEL_195;
v36 = *((unsigned __int8 *)a1 + 316);
v37 = *((_BYTE *)a1 + 268);
v38 = v36 & result & ((16 * (*((_BYTE *)a1 + 284) | ((int)*((unsigned __int8 *)a1 + 284) >> 1))) & 0x10 | (2 * ((int)v37 >> 5)) & 2 | (4 * ((int)v37 >> 3)) & 4 | ((int)v37 >> 1) & 1 | (8 * (v37 >> 7)));
if ( (result & 1) != 0 && (v37 & 2) != 0 && (!v35 || (v36 & 1) != 0) && (v38 & 0x1E) == 0 )
{
if ( (v37 & 1) != 0 )
*((_BYTE *)a1 + 268) = v37 & 0xFD;
*((_BYTE *)a1 + 131466) = ((v36 & 1) + 1) | v35;
result = inst_lcall(a1, 0LL, 3LL);
goto LABEL_195;
}
if ( (result & 2) != 0 && (v37 & 0x20) != 0 )
{
if ( v35 )
{
if ( (v36 & 2) != 0 && (v38 & 0x1D) == 0 )
{
*((_BYTE *)a1 + 268) = v37 & 0xDF;
v39 = 2;
goto LABEL_231;
}
}
else if ( (v38 & 0x1D) == 0 )
{
*((_BYTE *)a1 + 268) = v37 & 0xDF;
v35 = 0;
v39 = 2 - ((v36 & 2) == 0);
LABEL_231:
*((_BYTE *)a1 + 131466) = v35 | v39;
result = inst_lcall(a1, 0LL, 11LL);
goto LABEL_195;
}
}
if ( (result & 4) != 0 && (v37 & 8) != 0 && (!v35 || (v36 & 4) != 0) && (v38 & 0x1B) == 0 )
{
if ( (v37 & 4) != 0 )
*((_BYTE *)a1 + 268) = v37 & 0xF7;
*((_BYTE *)a1 + 131466) = (((v36 & 4) != 0) + 1) | v35;
result = inst_lcall(a1, 0LL, 19LL);
goto LABEL_195;
}
if ( (result & 8) != 0 && (v37 & 0x80u) != 0 )
{
if ( v35 )
{
if ( (v36 & 8) == 0 || (v38 & 0x17) != 0 )
goto LABEL_234;
*((_BYTE *)a1 + 268) = v37 & 0x7F;
v41 = 2;
}
else
{
if ( (v38 & 0x17) != 0 )
goto LABEL_234;
*((_BYTE *)a1 + 268) = v37 & 0x7F;
v35 = 0;
v41 = 2 - ((v36 & 8) == 0);
}
*((_BYTE *)a1 + 131466) = v35 | v41;
result = inst_lcall(a1, 0LL, 27LL);
goto LABEL_195;
}
LABEL_234:
if ( (result & 0x10) != 0 && ((*((_BYTE *)a1 + 284) | ((int)*((unsigned __int8 *)a1 + 284) >> 1)) & 1) != 0 )
{
if ( v35 )
{
if ( (v36 & 0x10) == 0 || (v38 & 0xF) != 0 )
goto LABEL_195;
v40 = 2;
}
else
{
if ( (v38 & 0xF) != 0 )
goto LABEL_195;
v35 = 0;
v40 = 2 - ((v36 & 0x10) == 0);
}
*((_BYTE *)a1 + 131466) = v35 | v40;
result = inst_lcall(a1, 0LL, 35LL);
}
LABEL_195:
*((_BYTE *)a1 + 131467) = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int *a1)
{
int v2; // ebp
char v3; // al
char v4; // dl
char v5; // al
char v6; // al
char v7; // dl
char v8; // al
unsigned __int8 v9; // al
unsigned __int8 v10; // si
unsigned __int8 v11; // al
unsigned __int8 v12; // dl
unsigned __int8 v13; // al
unsigned __int8 v14; // si
char v15; // r11
unsigned __int8 v16; // al
unsigned __int8 v17; // dl
int v18; // edi
unsigned __int8 v19; // si
int v20; // eax
unsigned __int8 v21; // si
int v22; // eax
int v23; // eax
int v24; // eax
char v25; // cl
unsigned __int8 v26; // si
int v27; // edx
unsigned __int8 v28; // cl
int v29; // edx
int v30; // eax
__int64 result; // rax
__int16 v32; // dx
int v33; // eax
int v34; // edx
char v35; // si
int v36; // er9
unsigned __int8 v37; // di
int v38; // edx
char v39; // al
char v40; // al
char v41; // al

v2 = *a1;
v3 = *((_BYTE *)a1 + 268);
if ( (v3 & 1) == 0 )
{
v4 = v3 | 2;
v5 = v3 & 0xFD;
if ( (a1[77] & 4) == 0 )
v5 = v4;
*((_BYTE *)a1 + 268) = v5;
}
v6 = *((_BYTE *)a1 + 268);
if ( (v6 & 4) == 0 )
{
v7 = v6 | 8;
v8 = v6 & 0xF7;
if ( (a1[77] & 8) == 0 )
v8 = v7;
*((_BYTE *)a1 + 268) = v8;
}
v9 = *((_BYTE *)a1 + 131460);
if ( (v9 & 8) != 0 )
{
v10 = v9 & 7;
v11 = v9 & 0xF0;
if ( v11 == 0x80 )
{
inst_mov_Rn_to_direct(a1, v10, *((unsigned __int8 *)a1 + 131461));
}
else if ( v11 > 0x80u )
{
if ( v11 == 0xC0 )
{
inst_xch_Rn(a1, v10);
}
else if ( v11 <= 0xC0u )
{
switch ( v11 )
{
case 0xA0:
inst_mov_direct_to_Rn(a1, v10, *((unsigned __int8 *)a1 + 131461));
break;
case 0xB0:
inst_cjne_data_with_Rn(a1, v10, *((unsigned __int8 *)a1 + 131461), *((unsigned __int8 *)a1 + 131462));
break;
case 0x90:
inst_subb_Rn(a1, v10);
break;
}
}
else
{
switch ( v11 )
{
case 0xE0:
inst_mov_Rn(a1, v10);
break;
case 0xF0:
inst_mov_to_Rn(a1, v10);
break;
case 0xD0:
inst_djnz_Rn(a1, v10, *((unsigned __int8 *)a1 + 131461));
break;
}
}
}
else if ( v11 == 64 )
{
inst_orl_Rn(a1, v10);
}
else if ( v11 <= 0x40u )
{
if ( v11 == 32 )
{
inst_add_Rn(a1, v10);
}
else if ( v11 <= 0x20u )
{
if ( v11 )
{
if ( v11 == 16 )
inst_dec_Rn(a1, v10);
}
else
{
inst_inc_Rn(a1, v10);
}
}
else if ( v11 == 48 )
{
inst_addc_Rn(a1, v10);
}
}
else
{
switch ( v11 )
{
case '`':
inst_xrl_Rn(a1, v10);
break;
case 'p':
inst_mov_data_to_Rn(a1, v10, *((unsigned __int8 *)a1 + 131461));
break;
case 'P':
inst_anl_Rn(a1, v10);
break;
}
}
}
else if ( (v9 & 6) == 6 )
{
v12 = v9 & 1;
v13 = v9 & 0xF0;
if ( v13 == 0x80 )
{
inst_mov_atRi_to_direct(a1, v12, *((unsigned __int8 *)a1 + 131461));
}
else if ( v13 > 0x80u )
{
if ( v13 == 0xC0 )
{
inst_xch_atRi(a1, v12);
}
else if ( v13 <= 0xC0u )
{
switch ( v13 )
{
case 0xA0:
inst_mov_direct_to_atRi(a1, v12, *((unsigned __int8 *)a1 + 131461));
break;
case 0xB0:
inst_cjne_data_with_atRi(a1, v12, *((unsigned __int8 *)a1 + 131461), *((unsigned __int8 *)a1 + 131462));
break;
case 0x90:
inst_subb_atRi(a1, v12);
break;
}
}
else
{
switch ( v13 )
{
case 0xE0:
inst_mov_atRi(a1, v12);
break;
case 0xF0:
inst_mov_to_atRi(a1, v12);
break;
case 0xD0:
inst_xchd_atRi(a1, v12);
break;
}
}
}
else if ( v13 == 64 )
{
inst_orl_atRi(a1, v12);
}
else if ( v13 <= 0x40u )
{
if ( v13 == 32 )
{
inst_add_atRi(a1, v12);
}
else if ( v13 <= 0x20u )
{
if ( v13 )
{
if ( v13 == 16 )
inst_dec_atRi(a1, v12);
}
else
{
inst_inc_atRi(a1, v12);
}
}
else if ( v13 == 48 )
{
inst_addc_atRi(a1, v12);
}
}
else
{
switch ( v13 )
{
case '`':
inst_xrl_atRi(a1, v12);
break;
case 'p':
inst_mov_data_to_atRi(a1, v12, *((unsigned __int8 *)a1 + 131461));
break;
case 'P':
inst_anl_atRi(a1, v12);
break;
}
}
}
else if ( (v9 & 0xF) == 1 )
{
v14 = v9 >> 5;
if ( (v9 & 0x10) != 0 )
inst_acall(a1, v14, *((unsigned __int8 *)a1 + 131461));
else
inst_ajmp(a1, v14, *((unsigned __int8 *)a1 + 131461));
}
else if ( (v9 & 0xEE) == 0xE2 )
{
v21 = v9 & 1;
if ( (v9 & 0x10) != 0 )
inst_movx_to_atRi(a1, v21);
else
inst_movx_atRi(a1, v21);
}
else
{
switch ( v9 )
{
case 0u:
inst_nop(a1);
break;
case 2u:
inst_ljmp(a1, *((unsigned __int8 *)a1 + 131461), *((unsigned __int8 *)a1 + 131462));
break;
case 3u:
inst_rr(a1);
break;
case 4u:
inst_inc(a1);
break;
case 5u:
inst_inc_direct(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x10u:
inst_jbc(a1, *((unsigned __int8 *)a1 + 131461), *((unsigned __int8 *)a1 + 131462));
break;
case 0x12u:
inst_lcall(a1, *((unsigned __int8 *)a1 + 131461), *((unsigned __int8 *)a1 + 131462));
break;
case 0x13u:
inst_rrc(a1);
break;
case 0x14u:
inst_dec(a1);
break;
case 0x15u:
inst_dec_direct(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x20u:
inst_jb(a1, *((unsigned __int8 *)a1 + 131461), *((unsigned __int8 *)a1 + 131462));
break;
case 0x22u:
inst_ret(a1);
break;
case 0x23u:
inst_rl(a1);
break;
case 0x24u:
inst_add_data(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x25u:
inst_add_direct(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x30u:
inst_jnb(a1, *((unsigned __int8 *)a1 + 131461), *((unsigned __int8 *)a1 + 131462));
break;
case 0x32u:
inst_reti(a1);
break;
case 0x33u:
inst_rlc(a1);
break;
case 0x34u:
inst_addc_data(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x35u:
inst_addc_direct(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x40u:
inst_jc(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x42u:
inst_orl_to_direct(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x43u:
inst_orl_data_to_direct(a1, *((unsigned __int8 *)a1 + 131461), *((unsigned __int8 *)a1 + 131462));
break;
case 0x44u:
inst_orl_data(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x45u:
inst_orl_direct(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x50u:
inst_jnc(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x52u:
inst_anl_to_direct(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x53u:
inst_anl_data_to_direct(a1, *((unsigned __int8 *)a1 + 131461), *((unsigned __int8 *)a1 + 131462));
break;
case 0x54u:
inst_anl_data(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x55u:
inst_anl_direct(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x60u:
inst_jz(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x62u:
inst_xrl_to_direct(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x63u:
inst_xrl_data_to_direct(a1, *((unsigned __int8 *)a1 + 131461), *((unsigned __int8 *)a1 + 131462));
break;
case 0x64u:
inst_xrl_data(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x65u:
inst_xrl_direct(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x70u:
inst_jnz(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x72u:
inst_orl_bit(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x73u:
inst_jmp_DPTR(a1);
break;
case 0x74u:
inst_mov_data(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x75u:
inst_mov_data_to_direct(a1, *((unsigned __int8 *)a1 + 131461), *((unsigned __int8 *)a1 + 131462));
break;
case 0x80u:
inst_sjmp(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x82u:
inst_anl_bit(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x83u:
inst_movc_PC(a1);
break;
case 0x84u:
inst_div(a1);
break;
case 0x85u:
inst_mov_direct_to_direct(a1, *((unsigned __int8 *)a1 + 131461), *((unsigned __int8 *)a1 + 131462));
break;
case 0x90u:
inst_mov_to_DPTR(a1, *((unsigned __int8 *)a1 + 131461), *((unsigned __int8 *)a1 + 131462));
break;
case 0x92u:
inst_mov_to_bit(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x93u:
inst_movc_DPTR(a1);
break;
case 0x94u:
inst_subb_data(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0x95u:
inst_subb_direct(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0xA0u:
inst_orl_not_bit(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0xA2u:
inst_mov_bit(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0xA3u:
inst_inc_DPTR(a1);
break;
case 0xA4u:
inst_mul(a1);
break;
case 0xB0u:
inst_anl_not_bit(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0xB2u:
inst_cpl_bit(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0xB3u:
inst_cpl_C(a1);
break;
case 0xB4u:
inst_cjne_data(a1, *((unsigned __int8 *)a1 + 131461), *((unsigned __int8 *)a1 + 131462));
break;
case 0xB5u:
inst_cjne_direct(a1, *((unsigned __int8 *)a1 + 131461), *((unsigned __int8 *)a1 + 131462));
break;
case 0xC0u:
inst_push(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0xC2u:
inst_clr_bit(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0xC3u:
inst_clr_C(a1);
break;
case 0xC4u:
inst_swap(a1);
break;
case 0xC5u:
inst_xch_direct(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0xD0u:
inst_pop(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0xD2u:
inst_setb_bit(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0xD3u:
inst_setb_C(a1);
break;
case 0xD4u:
inst_da(a1);
break;
case 0xD5u:
inst_djnz_direct(a1, *((unsigned __int8 *)a1 + 131461), *((unsigned __int8 *)a1 + 131462));
break;
case 0xE0u:
inst_movx_atDPTR(a1);
break;
case 0xE4u:
inst_clr(a1);
break;
case 0xE5u:
inst_mov_direct(a1, *((unsigned __int8 *)a1 + 131461));
break;
case 0xF0u:
inst_movx_to_atDPTR(a1);
break;
case 0xF4u:
inst_cpl(a1);
break;
case 0xF5u:
inst_mov_to_direct(a1, *((unsigned __int8 *)a1 + 131461));
break;
default:
if ( v9 != 0xA5 )
_assert_fail("IR[0] == 0xA5", "vm/lib8051.c", 0x24Fu, "operate8051");
return result;
}
}
operate_coprocessors(a1);
v15 = *((_BYTE *)a1 + 268);
if ( (v15 & 0x10) == 0 )
{
v17 = *((_BYTE *)a1 + 269);
v24 = v17;
if ( (v17 & 3) != 3 )
goto LABEL_197;
LABEL_186:
v25 = *((_BYTE *)a1 + 268);
if ( (v25 & 0x40) != 0 )
{
v26 = *((_BYTE *)a1 + 272);
if ( (v17 & 0x40) == 0 )
{
v27 = *a1 + v26 - v2;
*((_BYTE *)a1 + 272) = *(_BYTE *)a1 + v26 - v2;
if ( (v27 & 0x100) != 0 )
*((_BYTE *)a1 + 268) = v25 | 0x80;
}
}
v28 = *((_BYTE *)a1 + 271);
goto LABEL_191;
}
v16 = *((_BYTE *)a1 + 270);
v17 = *((_BYTE *)a1 + 269);
if ( (v17 & 4) != 0 )
{
v18 = v16;
v19 = v17 & 3;
if ( (v17 & 3) == 2 )
{
*((_BYTE *)a1 + 270) = v16;
LABEL_182:
v24 = v17;
goto LABEL_197;
}
}
else
{
v22 = *a1 + v16 - v2;
v18 = v22;
v19 = v17 & 3;
if ( (v17 & 3) == 2 )
{
*((_BYTE *)a1 + 270) = v22;
if ( (v22 & 0x100) != 0 )
{
*((_BYTE *)a1 + 270) = *((_BYTE *)a1 + 272) + v22;
*((_BYTE *)a1 + 268) = v15 | 0x20;
}
goto LABEL_182;
}
}
if ( v19 > 2u )
{
*((_BYTE *)a1 + 270) = v18;
if ( (v18 & 0x100) != 0 )
*((_BYTE *)a1 + 268) = v15 | 0x20;
v24 = v17;
goto LABEL_186;
}
if ( !v19 )
{
v23 = v18 + 32 * *((unsigned __int8 *)a1 + 272);
*((_BYTE *)a1 + 270) = v18 & 0x1F;
*((_BYTE *)a1 + 272) = v23 >> 5;
if ( (v23 & 0x2000) != 0 )
*((_BYTE *)a1 + 268) = v15 | 0x20;
goto LABEL_182;
}
if ( v19 == 1 )
{
v20 = v18 + (*((unsigned __int8 *)a1 + 272) << 8);
*((_BYTE *)a1 + 270) = v18;
*((_BYTE *)a1 + 272) = BYTE1(v20);
if ( (v20 & 0x10000) != 0 )
*((_BYTE *)a1 + 268) = v15 | 0x20;
goto LABEL_182;
}
v17 = *((_BYTE *)a1 + 269);
v24 = v17;
LABEL_197:
if ( (a1[67] & 0x40) == 0 )
goto LABEL_194;
v28 = *((_BYTE *)a1 + 271);
if ( (v17 & 0x40) != 0 )
{
v29 = v28;
v30 = (v24 >> 4) & 3;
if ( v30 == 1 )
{
v32 = (*((unsigned __int8 *)a1 + 273) << 8) + v28;
*((_BYTE *)a1 + 271) = v28;
*((_BYTE *)a1 + 273) = HIBYTE(v32);
goto LABEL_194;
}
goto LABEL_192;
}
LABEL_191:
v29 = v28 + *a1 - v2;
v30 = (v24 >> 4) & 3;
if ( v30 != 1 )
{
LABEL_192:
if ( v30 == 2 )
{
*((_BYTE *)a1 + 271) = v29;
if ( (v29 & 0x100) != 0 )
{
*((_BYTE *)a1 + 271) = *((_BYTE *)a1 + 273) + v29;
*((_BYTE *)a1 + 268) |= 0x80u;
}
}
else if ( !v30 )
{
v33 = v29 + 32 * *((unsigned __int8 *)a1 + 273);
*((_BYTE *)a1 + 271) = v29 & 0x1F;
*((_BYTE *)a1 + 273) = v33 >> 5;
if ( (v33 & 0x2000) != 0 )
*((_BYTE *)a1 + 268) |= 0x80u;
}
goto LABEL_194;
}
v34 = (*((unsigned __int8 *)a1 + 273) << 8) + v29;
*((_BYTE *)a1 + 271) = v34;
*((_BYTE *)a1 + 273) = BYTE1(v34);
if ( (v34 & 0x10000) != 0 )
*((_BYTE *)a1 + 268) |= 0x80u;
LABEL_194:
result = *((unsigned __int8 *)a1 + 300);
if ( (result & 0x80u) == 0LL )
goto LABEL_195;
v35 = *((_BYTE *)a1 + 131466);
if ( (v35 & 2) != 0 || *((_BYTE *)a1 + 131467) )
goto LABEL_195;
v36 = *((unsigned __int8 *)a1 + 316);
v37 = *((_BYTE *)a1 + 268);
v38 = v36 & result & ((16 * (*((_BYTE *)a1 + 284) | ((int)*((unsigned __int8 *)a1 + 284) >> 1))) & 0x10 | (2 * ((int)v37 >> 5)) & 2 | (4 * ((int)v37 >> 3)) & 4 | ((int)v37 >> 1) & 1 | (8 * (v37 >> 7)));
if ( (result & 1) != 0 && (v37 & 2) != 0 && (!v35 || (v36 & 1) != 0) && (v38 & 0x1E) == 0 )
{
if ( (v37 & 1) != 0 )
*((_BYTE *)a1 + 268) = v37 & 0xFD;
*((_BYTE *)a1 + 131466) = ((v36 & 1) + 1) | v35;
result = inst_lcall(a1, 0LL, 3LL);
goto LABEL_195;
}
if ( (result & 2) != 0 && (v37 & 0x20) != 0 )
{
if ( v35 )
{
if ( (v36 & 2) != 0 && (v38 & 0x1D) == 0 )
{
*((_BYTE *)a1 + 268) = v37 & 0xDF;
v39 = 2;
goto LABEL_231;
}
}
else if ( (v38 & 0x1D) == 0 )
{
*((_BYTE *)a1 + 268) = v37 & 0xDF;
v35 = 0;
v39 = 2 - ((v36 & 2) == 0);
LABEL_231:
*((_BYTE *)a1 + 131466) = v35 | v39;
result = inst_lcall(a1, 0LL, 11LL);
goto LABEL_195;
}
}
if ( (result & 4) != 0 && (v37 & 8) != 0 && (!v35 || (v36 & 4) != 0) && (v38 & 0x1B) == 0 )
{
if ( (v37 & 4) != 0 )
*((_BYTE *)a1 + 268) = v37 & 0xF7;
*((_BYTE *)a1 + 131466) = (((v36 & 4) != 0) + 1) | v35;
result = inst_lcall(a1, 0LL, 19LL);
goto LABEL_195;
}
if ( (result & 8) != 0 && (v37 & 0x80u) != 0 )
{
if ( v35 )
{
if ( (v36 & 8) == 0 || (v38 & 0x17) != 0 )
goto LABEL_234;
*((_BYTE *)a1 + 268) = v37 & 0x7F;
v41 = 2;
}
else
{
if ( (v38 & 0x17) != 0 )
goto LABEL_234;
*((_BYTE *)a1 + 268) = v37 & 0x7F;
v35 = 0;
v41 = 2 - ((v36 & 8) == 0);
}
*((_BYTE *)a1 + 131466) = v35 | v41;
result = inst_lcall(a1, 0LL, 27LL);
goto LABEL_195;
}
LABEL_234:
if ( (result & 0x10) != 0 && ((*((_BYTE *)a1 + 284) | ((int)*((unsigned __int8 *)a1 + 284) >> 1)) & 1) != 0 )
{
if ( v35 )
{
if ( (v36 & 0x10) == 0 || (v38 & 0xF) != 0 )
goto LABEL_195;
v40 = 2;
}
else
{
if ( (v38 & 0xF) != 0 )
goto LABEL_195;
v35 = 0;
v40 = 2 - ((v36 & 0x10) == 0);
}
*((_BYTE *)a1 + 131466) = v35 | v40;
result = inst_lcall(a1, 0LL, 35LL);
}
LABEL_195:
*((_BYTE *)a1 + 131467) = 0;
return result;
}

original_code:
void operate8051 (struct vm8051 *vm)
{
  uint8_t n;
  int32_t timer;
  uint32_t cycles_prev = vm->cycles;
  if (!((vm->_sfr[0x88 ^ 0x80] & 0x01) >> 0))
    {
      if (vm->_sfr[0xB0 ^ 0x80] & (1<<2))
        {
          vm->_sfr[0x88 ^ 0x80] &= ~(0x01 << 1);
                                  ;
        }
      else
        vm->_sfr[0x88 ^ 0x80] |= (0x01 << 1);
    }
  if (!((vm->_sfr[0x88 ^ 0x80] & 0x04) >> 2))
    {
      if (vm->_sfr[0xB0 ^ 0x80] & (1<<3))
        {
          vm->_sfr[0x88 ^ 0x80] &= ~(0x01 << 3);
                                  ;
        }
      else
        vm->_sfr[0x88 ^ 0x80] |= (0x01 << 3);
    }
  if (vm->IR[0] & 0x08)
    {
      n = vm->IR[0] & 0x07;
      switch (vm->IR[0] & 0xF0)
        {
        case 0x00:
          inst_inc_Rn (vm, n);
          break;
        case 0x10:
          inst_dec_Rn (vm, n);
          break;
        case 0x20:
          inst_add_Rn (vm, n);
          break;
        case 0x30:
          inst_addc_Rn (vm, n);
          break;
        case 0x40:
          inst_orl_Rn (vm, n);
          break;
        case 0x50:
          inst_anl_Rn (vm, n);
          break;
        case 0x60:
          inst_xrl_Rn (vm, n);
          break;
        case 0x70:
          inst_mov_data_to_Rn (vm, n, vm->IR[1]);
          break;
        case 0x80:
          inst_mov_Rn_to_direct (vm, n, vm->IR[1]);
          break;
        case 0x90:
          inst_subb_Rn (vm, n);
          break;
        case 0xA0:
          inst_mov_direct_to_Rn (vm, n, vm->IR[1]);
          break;
        case 0xB0:
          inst_cjne_data_with_Rn (vm, n, vm->IR[1], vm->IR[2]);
          break;
        case 0xC0:
          inst_xch_Rn (vm, n);
          break;
        case 0xD0:
          inst_djnz_Rn (vm, n, vm->IR[1]);
          break;
        case 0xE0:
          inst_mov_Rn (vm, n);
          break;
        case 0xF0:
          inst_mov_to_Rn (vm, n);
          break;
        }
    }
  else if ((vm->IR[0] & 0x06) == 0x06)
    {
      n = vm->IR[0] & 0x01;
      switch (vm->IR[0] & 0xF0)
        {
        case 0x00:
          inst_inc_atRi (vm, n);
          break;
        case 0x10:
          inst_dec_atRi (vm, n);
          break;
        case 0x20:
          inst_add_atRi (vm, n);
          break;
        case 0x30:
          inst_addc_atRi (vm, n);
          break;
        case 0x40:
          inst_orl_atRi (vm, n);
          break;
        case 0x50:
          inst_anl_atRi (vm, n);
          break;
        case 0x60:
          inst_xrl_atRi (vm, n);
          break;
        case 0x70:
          inst_mov_data_to_atRi (vm, n, vm->IR[1]);
          break;
        case 0x80:
          inst_mov_atRi_to_direct (vm, n, vm->IR[1]);
          break;
        case 0x90:
          inst_subb_atRi (vm, n);
          break;
        case 0xA0:
          inst_mov_direct_to_atRi (vm, n, vm->IR[1]);
          break;
        case 0xB0:
          inst_cjne_data_with_atRi (vm, n, vm->IR[1], vm->IR[2]);
          break;
        case 0xC0:
          inst_xch_atRi (vm, n);
          break;
        case 0xD0:
          inst_xchd_atRi (vm, n);
          break;
        case 0xE0:
          inst_mov_atRi (vm, n);
          break;
        case 0xF0:
          inst_mov_to_atRi (vm, n);
          break;
        }
    }
  else if ((vm->IR[0] & 0x0F) == 0x01)
    {
      n = (vm->IR[0] & 0xE0) >> 5;
      if (vm->IR[0] & 0x10)
        inst_acall (vm, n, vm->IR[1]);
      else
        inst_ajmp (vm, n, vm->IR[1]);
    }
  else if ((vm->IR[0] & 0xEE) == 0xE2)
    {
      n = vm->IR[0] & 0x01;
      if (vm->IR[0] & 0x10)
        inst_movx_to_atRi (vm, n);
      else
        inst_movx_atRi (vm, n);
    }
  else
    {
      switch (vm->IR[0])
        {
        case 0x00:
          inst_nop (vm);
          break;
        case 0x10:
          inst_jbc (vm, vm->IR[1], vm->IR[2]);
          break;
        case 0x20:
          inst_jb (vm, vm->IR[1], vm->IR[2]);
          break;
        case 0x30:
          inst_jnb (vm, vm->IR[1], vm->IR[2]);
          break;
        case 0x40:
          inst_jc (vm, vm->IR[1]);
          break;
        case 0x50:
          inst_jnc (vm, vm->IR[1]);
          break;
        case 0x60:
          inst_jz (vm, vm->IR[1]);
          break;
        case 0x70:
          inst_jnz (vm, vm->IR[1]);
          break;
        case 0x80:
          inst_sjmp (vm, vm->IR[1]);
          break;
        case 0x90:
          inst_mov_to_DPTR (vm, vm->IR[1], vm->IR[2]);
          break;
        case 0xA0:
          inst_orl_not_bit (vm, vm->IR[1]);
          break;
        case 0xB0:
          inst_anl_not_bit (vm, vm->IR[1]);
          break;
        case 0xC0:
          inst_push (vm, vm->IR[1]);
          break;
        case 0xD0:
          inst_pop (vm, vm->IR[1]);
          break;
        case 0xE0:
          inst_movx_atDPTR (vm);
          break;
        case 0xF0:
          inst_movx_to_atDPTR (vm);
          break;
        case 0x02:
          inst_ljmp (vm, vm->IR[1], vm->IR[2]);
          break;
        case 0x12:
          inst_lcall (vm, vm->IR[1], vm->IR[2]);
          break;
        case 0x22:
          inst_ret (vm);
          break;
        case 0x32:
          inst_reti (vm);
          break;
        case 0x42:
          inst_orl_to_direct (vm, vm->IR[1]);
          break;
        case 0x52:
          inst_anl_to_direct (vm, vm->IR[1]);
          break;
        case 0x62:
          inst_xrl_to_direct (vm, vm->IR[1]);
          break;
        case 0x72:
          inst_orl_bit (vm, vm->IR[1]);
          break;
        case 0x82:
          inst_anl_bit (vm, vm->IR[1]);
          break;
        case 0x92:
          inst_mov_to_bit (vm, vm->IR[1]);
          break;
        case 0xA2:
          inst_mov_bit (vm, vm->IR[1]);
          break;
        case 0xB2:
          inst_cpl_bit (vm, vm->IR[1]);
          break;
        case 0xC2:
          inst_clr_bit (vm, vm->IR[1]);
          break;
        case 0xD2:
          inst_setb_bit (vm, vm->IR[1]);
          break;
        case 0x03:
          inst_rr (vm);
          break;
        case 0x13:
          inst_rrc (vm);
          break;
        case 0x23:
          inst_rl (vm);
          break;
        case 0x33:
          inst_rlc (vm);
          break;
        case 0x43:
          inst_orl_data_to_direct (vm, vm->IR[1], vm->IR[2]);
          break;
        case 0x53:
          inst_anl_data_to_direct (vm, vm->IR[1], vm->IR[2]);
          break;
        case 0x63:
          inst_xrl_data_to_direct (vm, vm->IR[1], vm->IR[2]);
          break;
        case 0x73:
          inst_jmp_DPTR (vm);
          break;
        case 0x83:
          inst_movc_PC (vm);
          break;
        case 0x93:
          inst_movc_DPTR (vm);
          break;
        case 0xA3:
          inst_inc_DPTR (vm);
          break;
        case 0xB3:
          inst_cpl_C (vm);
          break;
        case 0xC3:
          inst_clr_C (vm);
          break;
        case 0xD3:
          inst_setb_C (vm);
          break;
        case 0x04:
          inst_inc (vm);
          break;
        case 0x14:
          inst_dec (vm);
          break;
        case 0x24:
          inst_add_data (vm, vm->IR[1]);
          break;
        case 0x34:
          inst_addc_data (vm, vm->IR[1]);
          break;
        case 0x44:
          inst_orl_data (vm, vm->IR[1]);
          break;
        case 0x54:
          inst_anl_data (vm, vm->IR[1]);
          break;
        case 0x64:
          inst_xrl_data (vm, vm->IR[1]);
          break;
        case 0x74:
          inst_mov_data (vm, vm->IR[1]);
          break;
        case 0x84:
          inst_div (vm);
          break;
        case 0x94:
          inst_subb_data (vm, vm->IR[1]);
          break;
        case 0xA4:
          inst_mul (vm);
          break;
        case 0xB4:
          inst_cjne_data (vm, vm->IR[1], vm->IR[2]);
          break;
        case 0xC4:
          inst_swap (vm);
          break;
        case 0xD4:
          inst_da (vm);
          break;
        case 0xE4:
          inst_clr (vm);
          break;
        case 0xF4:
          inst_cpl (vm);
          break;
        case 0x05:
          inst_inc_direct (vm, vm->IR[1]);
          break;
        case 0x15:
          inst_dec_direct (vm, vm->IR[1]);
          break;
        case 0x25:
          inst_add_direct (vm, vm->IR[1]);
          break;
        case 0x35:
          inst_addc_direct (vm, vm->IR[1]);
          break;
        case 0x45:
          inst_orl_direct (vm, vm->IR[1]);
          break;
        case 0x55:
          inst_anl_direct (vm, vm->IR[1]);
          break;
        case 0x65:
          inst_xrl_direct (vm, vm->IR[1]);
          break;
        case 0x75:
          inst_mov_data_to_direct (vm, vm->IR[1], vm->IR[2]);
          break;
        case 0x85:
          inst_mov_direct_to_direct (vm, vm->IR[1], vm->IR[2]);
          break;
        case 0x95:
          inst_subb_direct (vm, vm->IR[1]);
          break;
        case 0xB5:
          inst_cjne_direct (vm, vm->IR[1], vm->IR[2]);
          break;
        case 0xC5:
          inst_xch_direct (vm, vm->IR[1]);
          break;
        case 0xD5:
          inst_djnz_direct (vm, vm->IR[1], vm->IR[2]);
          break;
        case 0xE5:
          inst_mov_direct (vm, vm->IR[1]);
          break;
        case 0xF5:
          inst_mov_to_direct (vm, vm->IR[1]);
          break;
        default:
          ((vm->IR[0] == 0xA5) ? (void) (0) : __assert_fail ("IR[0] == 0xA5", "vm/lib8051.c", 591, __extension__ __PRETTY_FUNCTION__));
          break;
        }
    }
  operate_coprocessors (vm);
  if (((vm->_sfr[0x88 ^ 0x80] & 0x10) >> 4))
    {
      timer = vm->_sfr[0x8A ^ 0x80];
      if ((vm->_sfr[0x89 ^ 0x80] & 0x04))
                            ;
      else
        timer += vm->cycles - cycles_prev;
      switch (vm->_sfr[0x89 ^ 0x80] & 0x03)
        {
        case 0:
          timer += vm->_sfr[0x8C ^ 0x80] << 5;
          vm->_sfr[0x8A ^ 0x80] = timer & 0x1F;
          vm->_sfr[0x8C ^ 0x80] = (timer & 0x1FE0) >> 5;
          if (timer & 0x2000)
            vm->_sfr[0x88 ^ 0x80] |= (0x01 << 5);
          break;
        case 1:
          timer += vm->_sfr[0x8C ^ 0x80] << 8;
          vm->_sfr[0x8A ^ 0x80] = timer & 0xFF;
          vm->_sfr[0x8C ^ 0x80] = (timer & 0xFF00) >> 8;
          if (timer & 0x10000)
            vm->_sfr[0x88 ^ 0x80] |= (0x01 << 5);
          break;
        case 2:
          vm->_sfr[0x8A ^ 0x80] = timer & 0xFF;
          if (timer & 0x100)
            {
              vm->_sfr[0x8A ^ 0x80] += vm->_sfr[0x8C ^ 0x80];
              vm->_sfr[0x88 ^ 0x80] |= (0x01 << 5);
            }
          break;
        case 3:
          vm->_sfr[0x8A ^ 0x80] = timer & 0xFF;
          if (timer & 0x100)
            vm->_sfr[0x88 ^ 0x80] |= (0x01 << 5);
          break;
        }
    }
  if (((vm->_sfr[0x89 ^ 0x80] & 0x03) == 0x03) && ((vm->_sfr[0x88 ^ 0x80] & 0x40) >> 6))
    {
      timer = vm->_sfr[0x8C ^ 0x80];
      if ((vm->_sfr[0x89 ^ 0x80] & 0x40))
                            ;
      else
        timer += vm->cycles - cycles_prev;
      vm->_sfr[0x8C ^ 0x80] = timer & 0xFF;
      if (timer & 0x100)
        vm->_sfr[0x88 ^ 0x80] |= (0x01 << 7);
    }
  if (((vm->_sfr[0x89 ^ 0x80] & 0x03) == 0x03) || ((vm->_sfr[0x88 ^ 0x80] & 0x40) >> 6))
    {
      timer = vm->_sfr[0x8B ^ 0x80];
      if ((vm->_sfr[0x89 ^ 0x80] & 0x03) != 0x03 && (vm->_sfr[0x89 ^ 0x80] & 0x40))
        ;
      else
        timer += vm->cycles - cycles_prev;
      switch ((vm->_sfr[0x89 ^ 0x80] & 0x30) >> 4)
        {
        case 0:
          timer += vm->_sfr[0x8D ^ 0x80] << 5;
          vm->_sfr[0x8B ^ 0x80] = timer & 0x1F;
          vm->_sfr[0x8D ^ 0x80] = (timer & 0x1FE0) >> 5;
          if (timer & 0x2000)
            vm->_sfr[0x88 ^ 0x80] |= (0x01 << 7);
          break;
        case 1:
          timer += vm->_sfr[0x8D ^ 0x80] << 8;
          vm->_sfr[0x8B ^ 0x80] = timer & 0xFF;
          vm->_sfr[0x8D ^ 0x80] = (timer & 0xFF00) >> 8;
          if (timer & 0x10000)
            vm->_sfr[0x88 ^ 0x80] |= (0x01 << 7);
          break;
        case 2:
          vm->_sfr[0x8B ^ 0x80] = timer & 0xFF;
          if (timer & 0x100)
            {
              vm->_sfr[0x8B ^ 0x80] += vm->_sfr[0x8D ^ 0x80];
              vm->_sfr[0x88 ^ 0x80] |= (0x01 << 7);
            }
          break;
        case 3:
          break;
        }
    }
  if (((vm->_sfr[0xA8 ^ 0x80] & 0x80) >> 7) && !(vm->interrupted & (1 << 1)) && !(vm->interrupts_blocked))
    {
      uint8_t prioritary = vm->_sfr[0xA8 ^ 0x80] & vm->_sfr[0xB8 ^ 0x80] &
        (((((vm->_sfr[0x98 ^ 0x80] & 0x01) >> 0)|((vm->_sfr[0x98 ^ 0x80] & 0x02) >> 1)) << 4) | (((vm->_sfr[0x88 ^ 0x80] & 0x80) >> 7) << 3) | (((vm->_sfr[0x88 ^ 0x80] & 0x08) >> 3) << 2) | (((vm->_sfr[0x88 ^ 0x80] & 0x20) >> 5) << 1) | (((vm->_sfr[0x88 ^ 0x80] & 0x02) >> 1) << 0));
      if (((((vm->_sfr[0xA8 ^ 0x80] & 0x01) >> 0)) && (((vm->_sfr[0x88 ^ 0x80] & 0x02) >> 1)) && (!vm->interrupted || (((vm->_sfr[0xB8 ^ 0x80] & 0x01) >> 0)))) && !(prioritary & 0x1E))
        {
          if (((vm->_sfr[0x88 ^ 0x80] & 0x01) >> 0))
            vm->_sfr[0x88 ^ 0x80] &= ~(0x01 << 1);
          vm->interrupted |= ((vm->_sfr[0xB8 ^ 0x80] & 0x01) >> 0) ? (1 << 1) : (1 << 0);
          inst_lcall (vm, 0x00, 0x03);
        }
      else if (((((vm->_sfr[0xA8 ^ 0x80] & 0x02) >> 1)) && (((vm->_sfr[0x88 ^ 0x80] & 0x20) >> 5)) && (!vm->interrupted || (((vm->_sfr[0xB8 ^ 0x80] & 0x02) >> 1)))) && !(prioritary & 0x1D))
        {
          vm->_sfr[0x88 ^ 0x80] &= ~(0x01 << 5);
          vm->interrupted |= ((vm->_sfr[0xB8 ^ 0x80] & 0x02) >> 1) ? (1 << 1) : (1 << 0);
          inst_lcall (vm, 0x00, 0x0B);
        }
      else if (((((vm->_sfr[0xA8 ^ 0x80] & 0x04) >> 2)) && (((vm->_sfr[0x88 ^ 0x80] & 0x08) >> 3)) && (!vm->interrupted || (((vm->_sfr[0xB8 ^ 0x80] & 0x04) >> 2)))) && !(prioritary & 0x1B))
        {
          if (((vm->_sfr[0x88 ^ 0x80] & 0x04) >> 2))
            vm->_sfr[0x88 ^ 0x80] &= ~(0x01 << 3);
          vm->interrupted |= ((vm->_sfr[0xB8 ^ 0x80] & 0x04) >> 2) ? (1 << 1) : (1 << 0);
          inst_lcall (vm, 0x00, 0x13);
        }
      else if (((((vm->_sfr[0xA8 ^ 0x80] & 0x08) >> 3)) && (((vm->_sfr[0x88 ^ 0x80] & 0x80) >> 7)) && (!vm->interrupted || (((vm->_sfr[0xB8 ^ 0x80] & 0x08) >> 3)))) && !(prioritary & 0x17))
        {
          vm->_sfr[0x88 ^ 0x80] &= ~(0x01 << 7);
          vm->interrupted |= ((vm->_sfr[0xB8 ^ 0x80] & 0x08) >> 3) ? (1 << 1) : (1 << 0);
          inst_lcall (vm, 0x00, 0x1B);
        }
      else if (((((vm->_sfr[0xA8 ^ 0x80] & 0x10) >> 4)) && (((vm->_sfr[0x98 ^ 0x80] & 0x01) >> 0)|((vm->_sfr[0x98 ^ 0x80] & 0x02) >> 1)) && (!vm->interrupted || (((vm->_sfr[0xB8 ^ 0x80] & 0x10) >> 4)))) && !(prioritary & 0x0F))
        {
          vm->interrupted |= ((vm->_sfr[0xB8 ^ 0x80] & 0x10) >> 4) ? (1 << 1) : (1 << 0);
          inst_lcall (vm, 0x00, 0x23);
        }
    }
  vm->interrupts_blocked = 0;
}

canonical_original_code:
void operate8051(struct vm8051 *vm)
{
  unsigned char n;
  int timer;
  unsigned int cycles_prev = vm->cycles;
  if (!((vm->_sfr[0x88 ^ 0x80] & 0x01) >> 0))
    {
      if (vm->_sfr[0xB0 ^ 0x80] & (1<<2))
        {
          vm->_sfr[0x88 ^ 0x80] &= ~(0x01 << 1);
                                  ;
        }
      else
        vm->_sfr[0x88 ^ 0x80] |= (0x01 << 1);
    }
  if (!((vm->_sfr[0x88 ^ 0x80] & 0x04) >> 2))
    {
      if (vm->_sfr[0xB0 ^ 0x80] & (1<<3))
        {
          vm->_sfr[0x88 ^ 0x80] &= ~(0x01 << 3);
                                  ;
        }
      else
        vm->_sfr[0x88 ^ 0x80] |= (0x01 << 3);
    }
  if (vm->IR[0] & 0x08)
    {
      n = vm->IR[0] & 0x07;
      switch (vm->IR[0] & 0xF0)
        {
        case 0x00:
          inst_inc_Rn (vm, n);
          break;
        case 0x10:
          inst_dec_Rn (vm, n);
          break;
        case 0x20:
          inst_add_Rn (vm, n);
          break;
        case 0x30:
          inst_addc_Rn (vm, n);
          break;
        case 0x40:
          inst_orl_Rn (vm, n);
          break;
        case 0x50:
          inst_anl_Rn (vm, n);
          break;
        case 0x60:
          inst_xrl_Rn (vm, n);
          break;
        case 0x70:
          inst_mov_data_to_Rn (vm, n, vm->IR[1]);
          break;
        case 0x80:
          inst_mov_Rn_to_direct (vm, n, vm->IR[1]);
          break;
        case 0x90:
          inst_subb_Rn (vm, n);
          break;
        case 0xA0:
          inst_mov_direct_to_Rn (vm, n, vm->IR[1]);
          break;
        case 0xB0:
          inst_cjne_data_with_Rn (vm, n, vm->IR[1], vm->IR[2]);
          break;
        case 0xC0:
          inst_xch_Rn (vm, n);
          break;
        case 0xD0:
          inst_djnz_Rn (vm, n, vm->IR[1]);
          break;
        case 0xE0:
          inst_mov_Rn (vm, n);
          break;
        case 0xF0:
          inst_mov_to_Rn (vm, n);
          break;
        }
    }
  else if ((vm->IR[0] & 0x06) == 0x06)
    {
      n = vm->IR[0] & 0x01;
      switch (vm->IR[0] & 0xF0)
        {
        case 0x00:
          inst_inc_atRi (vm, n);
          break;
        case 0x10:
          inst_dec_atRi (vm, n);
          break;
        case 0x20:
          inst_add_atRi (vm, n);
          break;
        case 0x30:
          inst_addc_atRi (vm, n);
          break;
        case 0x40:
          inst_orl_atRi (vm, n);
          break;
        case 0x50:
          inst_anl_atRi (vm, n);
          break;
        case 0x60:
          inst_xrl_atRi (vm, n);
          break;
        case 0x70:
          inst_mov_data_to_atRi (vm, n, vm->IR[1]);
          break;
        case 0x80:
          inst_mov_atRi_to_direct (vm, n, vm->IR[1]);
          break;
        case 0x90:
          inst_subb_atRi (vm, n);
          break;
        case 0xA0:
          inst_mov_direct_to_atRi (vm, n, vm->IR[1]);
          break;
        case 0xB0:
          inst_cjne_data_with_atRi (vm, n, vm->IR[1], vm->IR[2]);
          break;
        case 0xC0:
          inst_xch_atRi (vm, n);
          break;
        case 0xD0:
          inst_xchd_atRi (vm, n);
          break;
        case 0xE0:
          inst_mov_atRi (vm, n);
          break;
        case 0xF0:
          inst_mov_to_atRi (vm, n);
          break;
        }
    }
  else if ((vm->IR[0] & 0x0F) == 0x01)
    {
      n = (vm->IR[0] & 0xE0) >> 5;
      if (vm->IR[0] & 0x10)
        inst_acall (vm, n, vm->IR[1]);
      else
        inst_ajmp (vm, n, vm->IR[1]);
    }
  else if ((vm->IR[0] & 0xEE) == 0xE2)
    {
      n = vm->IR[0] & 0x01;
      if (vm->IR[0] & 0x10)
        inst_movx_to_atRi (vm, n);
      else
        inst_movx_atRi (vm, n);
    }
  else
    {
      switch (vm->IR[0])
        {
        case 0x00:
          inst_nop (vm);
          break;
        case 0x10:
          inst_jbc (vm, vm->IR[1], vm->IR[2]);
          break;
        case 0x20:
          inst_jb (vm, vm->IR[1], vm->IR[2]);
          break;
        case 0x30:
          inst_jnb (vm, vm->IR[1], vm->IR[2]);
          break;
        case 0x40:
          inst_jc (vm, vm->IR[1]);
          break;
        case 0x50:
          inst_jnc (vm, vm->IR[1]);
          break;
        case 0x60:
          inst_jz (vm, vm->IR[1]);
          break;
        case 0x70:
          inst_jnz (vm, vm->IR[1]);
          break;
        case 0x80:
          inst_sjmp (vm, vm->IR[1]);
          break;
        case 0x90:
          inst_mov_to_DPTR (vm, vm->IR[1], vm->IR[2]);
          break;
        case 0xA0:
          inst_orl_not_bit (vm, vm->IR[1]);
          break;
        case 0xB0:
          inst_anl_not_bit (vm, vm->IR[1]);
          break;
        case 0xC0:
          inst_push (vm, vm->IR[1]);
          break;
        case 0xD0:
          inst_pop (vm, vm->IR[1]);
          break;
        case 0xE0:
          inst_movx_atDPTR (vm);
          break;
        case 0xF0:
          inst_movx_to_atDPTR (vm);
          break;
        case 0x02:
          inst_ljmp (vm, vm->IR[1], vm->IR[2]);
          break;
        case 0x12:
          inst_lcall (vm, vm->IR[1], vm->IR[2]);
          break;
        case 0x22:
          inst_ret (vm);
          break;
        case 0x32:
          inst_reti (vm);
          break;
        case 0x42:
          inst_orl_to_direct (vm, vm->IR[1]);
          break;
        case 0x52:
          inst_anl_to_direct (vm, vm->IR[1]);
          break;
        case 0x62:
          inst_xrl_to_direct (vm, vm->IR[1]);
          break;
        case 0x72:
          inst_orl_bit (vm, vm->IR[1]);
          break;
        case 0x82:
          inst_anl_bit (vm, vm->IR[1]);
          break;
        case 0x92:
          inst_mov_to_bit (vm, vm->IR[1]);
          break;
        case 0xA2:
          inst_mov_bit (vm, vm->IR[1]);
          break;
        case 0xB2:
          inst_cpl_bit (vm, vm->IR[1]);
          break;
        case 0xC2:
          inst_clr_bit (vm, vm->IR[1]);
          break;
        case 0xD2:
          inst_setb_bit (vm, vm->IR[1]);
          break;
        case 0x03:
          inst_rr (vm);
          break;
        case 0x13:
          inst_rrc (vm);
          break;
        case 0x23:
          inst_rl (vm);
          break;
        case 0x33:
          inst_rlc (vm);
          break;
        case 0x43:
          inst_orl_data_to_direct (vm, vm->IR[1], vm->IR[2]);
          break;
        case 0x53:
          inst_anl_data_to_direct (vm, vm->IR[1], vm->IR[2]);
          break;
        case 0x63:
          inst_xrl_data_to_direct (vm, vm->IR[1], vm->IR[2]);
          break;
        case 0x73:
          inst_jmp_DPTR (vm);
          break;
        case 0x83:
          inst_movc_PC (vm);
          break;
        case 0x93:
          inst_movc_DPTR (vm);
          break;
        case 0xA3:
          inst_inc_DPTR (vm);
          break;
        case 0xB3:
          inst_cpl_C (vm);
          break;
        case 0xC3:
          inst_clr_C (vm);
          break;
        case 0xD3:
          inst_setb_C (vm);
          break;
        case 0x04:
          inst_inc (vm);
          break;
        case 0x14:
          inst_dec (vm);
          break;
        case 0x24:
          inst_add_data (vm, vm->IR[1]);
          break;
        case 0x34:
          inst_addc_data (vm, vm->IR[1]);
          break;
        case 0x44:
          inst_orl_data (vm, vm->IR[1]);
          break;
        case 0x54:
          inst_anl_data (vm, vm->IR[1]);
          break;
        case 0x64:
          inst_xrl_data (vm, vm->IR[1]);
          break;
        case 0x74:
          inst_mov_data (vm, vm->IR[1]);
          break;
        case 0x84:
          inst_div (vm);
          break;
        case 0x94:
          inst_subb_data (vm, vm->IR[1]);
          break;
        case 0xA4:
          inst_mul (vm);
          break;
        case 0xB4:
          inst_cjne_data (vm, vm->IR[1], vm->IR[2]);
          break;
        case 0xC4:
          inst_swap (vm);
          break;
        case 0xD4:
          inst_da (vm);
          break;
        case 0xE4:
          inst_clr (vm);
          break;
        case 0xF4:
          inst_cpl (vm);
          break;
        case 0x05:
          inst_inc_direct (vm, vm->IR[1]);
          break;
        case 0x15:
          inst_dec_direct (vm, vm->IR[1]);
          break;
        case 0x25:
          inst_add_direct (vm, vm->IR[1]);
          break;
        case 0x35:
          inst_addc_direct (vm, vm->IR[1]);
          break;
        case 0x45:
          inst_orl_direct (vm, vm->IR[1]);
          break;
        case 0x55:
          inst_anl_direct (vm, vm->IR[1]);
          break;
        case 0x65:
          inst_xrl_direct (vm, vm->IR[1]);
          break;
        case 0x75:
          inst_mov_data_to_direct (vm, vm->IR[1], vm->IR[2]);
          break;
        case 0x85:
          inst_mov_direct_to_direct (vm, vm->IR[1], vm->IR[2]);
          break;
        case 0x95:
          inst_subb_direct (vm, vm->IR[1]);
          break;
        case 0xB5:
          inst_cjne_direct (vm, vm->IR[1], vm->IR[2]);
          break;
        case 0xC5:
          inst_xch_direct (vm, vm->IR[1]);
          break;
        case 0xD5:
          inst_djnz_direct (vm, vm->IR[1], vm->IR[2]);
          break;
        case 0xE5:
          inst_mov_direct (vm, vm->IR[1]);
          break;
        case 0xF5:
          inst_mov_to_direct (vm, vm->IR[1]);
          break;
        default:
          ((vm->IR[0] == 0xA5) ? (void) (0) : __assert_fail ("IR[0] == 0xA5", "vm/lib8051.c", 591, __extension__ __PRETTY_FUNCTION__));
          break;
        }
    }
  operate_coprocessors (vm);
  if (((vm->_sfr[0x88 ^ 0x80] & 0x10) >> 4))
    {
      timer = vm->_sfr[0x8A ^ 0x80];
      if ((vm->_sfr[0x89 ^ 0x80] & 0x04))
                            ;
      else
        timer += vm->cycles - cycles_prev;
      switch (vm->_sfr[0x89 ^ 0x80] & 0x03)
        {
        case 0:
          timer += vm->_sfr[0x8C ^ 0x80] << 5;
          vm->_sfr[0x8A ^ 0x80] = timer & 0x1F;
          vm->_sfr[0x8C ^ 0x80] = (timer & 0x1FE0) >> 5;
          if (timer & 0x2000)
            vm->_sfr[0x88 ^ 0x80] |= (0x01 << 5);
          break;
        case 1:
          timer += vm->_sfr[0x8C ^ 0x80] << 8;
          vm->_sfr[0x8A ^ 0x80] = timer & 0xFF;
          vm->_sfr[0x8C ^ 0x80] = (timer & 0xFF00) >> 8;
          if (timer & 0x10000)
            vm->_sfr[0x88 ^ 0x80] |= (0x01 << 5);
          break;
        case 2:
          vm->_sfr[0x8A ^ 0x80] = timer & 0xFF;
          if (timer & 0x100)
            {
              vm->_sfr[0x8A ^ 0x80] += vm->_sfr[0x8C ^ 0x80];
              vm->_sfr[0x88 ^ 0x80] |= (0x01 << 5);
            }
          break;
        case 3:
          vm->_sfr[0x8A ^ 0x80] = timer & 0xFF;
          if (timer & 0x100)
            vm->_sfr[0x88 ^ 0x80] |= (0x01 << 5);
          break;
        }
    }
  if (((vm->_sfr[0x89 ^ 0x80] & 0x03) == 0x03) && ((vm->_sfr[0x88 ^ 0x80] & 0x40) >> 6))
    {
      timer = vm->_sfr[0x8C ^ 0x80];
      if ((vm->_sfr[0x89 ^ 0x80] & 0x40))
                            ;
      else
        timer += vm->cycles - cycles_prev;
      vm->_sfr[0x8C ^ 0x80] = timer & 0xFF;
      if (timer & 0x100)
        vm->_sfr[0x88 ^ 0x80] |= (0x01 << 7);
    }
  if (((vm->_sfr[0x89 ^ 0x80] & 0x03) == 0x03) || ((vm->_sfr[0x88 ^ 0x80] & 0x40) >> 6))
    {
      timer = vm->_sfr[0x8B ^ 0x80];
      if ((vm->_sfr[0x89 ^ 0x80] & 0x03) != 0x03 && (vm->_sfr[0x89 ^ 0x80] & 0x40))
        ;
      else
        timer += vm->cycles - cycles_prev;
      switch ((vm->_sfr[0x89 ^ 0x80] & 0x30) >> 4)
        {
        case 0:
          timer += vm->_sfr[0x8D ^ 0x80] << 5;
          vm->_sfr[0x8B ^ 0x80] = timer & 0x1F;
          vm->_sfr[0x8D ^ 0x80] = (timer & 0x1FE0) >> 5;
          if (timer & 0x2000)
            vm->_sfr[0x88 ^ 0x80] |= (0x01 << 7);
          break;
        case 1:
          timer += vm->_sfr[0x8D ^ 0x80] << 8;
          vm->_sfr[0x8B ^ 0x80] = timer & 0xFF;
          vm->_sfr[0x8D ^ 0x80] = (timer & 0xFF00) >> 8;
          if (timer & 0x10000)
            vm->_sfr[0x88 ^ 0x80] |= (0x01 << 7);
          break;
        case 2:
          vm->_sfr[0x8B ^ 0x80] = timer & 0xFF;
          if (timer & 0x100)
            {
              vm->_sfr[0x8B ^ 0x80] += vm->_sfr[0x8D ^ 0x80];
              vm->_sfr[0x88 ^ 0x80] |= (0x01 << 7);
            }
          break;
        case 3:
          break;
        }
    }
  if (((vm->_sfr[0xA8 ^ 0x80] & 0x80) >> 7) && !(vm->interrupted & (1 << 1)) && !(vm->interrupts_blocked))
    {
      unsigned char prioritary = vm->_sfr[0xA8 ^ 0x80] & vm->_sfr[0xB8 ^ 0x80] &
        (((((vm->_sfr[0x98 ^ 0x80] & 0x01) >> 0)|((vm->_sfr[0x98 ^ 0x80] & 0x02) >> 1)) << 4) | (((vm->_sfr[0x88 ^ 0x80] & 0x80) >> 7) << 3) | (((vm->_sfr[0x88 ^ 0x80] & 0x08) >> 3) << 2) | (((vm->_sfr[0x88 ^ 0x80] & 0x20) >> 5) << 1) | (((vm->_sfr[0x88 ^ 0x80] & 0x02) >> 1) << 0));
      if (((((vm->_sfr[0xA8 ^ 0x80] & 0x01) >> 0)) && (((vm->_sfr[0x88 ^ 0x80] & 0x02) >> 1)) && (!vm->interrupted || (((vm->_sfr[0xB8 ^ 0x80] & 0x01) >> 0)))) && !(prioritary & 0x1E))
        {
          if (((vm->_sfr[0x88 ^ 0x80] & 0x01) >> 0))
            vm->_sfr[0x88 ^ 0x80] &= ~(0x01 << 1);
          vm->interrupted |= ((vm->_sfr[0xB8 ^ 0x80] & 0x01) >> 0) ? (1 << 1) : (1 << 0);
          inst_lcall (vm, 0x00, 0x03);
        }
      else if (((((vm->_sfr[0xA8 ^ 0x80] & 0x02) >> 1)) && (((vm->_sfr[0x88 ^ 0x80] & 0x20) >> 5)) && (!vm->interrupted || (((vm->_sfr[0xB8 ^ 0x80] & 0x02) >> 1)))) && !(prioritary & 0x1D))
        {
          vm->_sfr[0x88 ^ 0x80] &= ~(0x01 << 5);
          vm->interrupted |= ((vm->_sfr[0xB8 ^ 0x80] & 0x02) >> 1) ? (1 << 1) : (1 << 0);
          inst_lcall (vm, 0x00, 0x0B);
        }
      else if (((((vm->_sfr[0xA8 ^ 0x80] & 0x04) >> 2)) && (((vm->_sfr[0x88 ^ 0x80] & 0x08) >> 3)) && (!vm->interrupted || (((vm->_sfr[0xB8 ^ 0x80] & 0x04) >> 2)))) && !(prioritary & 0x1B))
        {
          if (((vm->_sfr[0x88 ^ 0x80] & 0x04) >> 2))
            vm->_sfr[0x88 ^ 0x80] &= ~(0x01 << 3);
          vm->interrupted |= ((vm->_sfr[0xB8 ^ 0x80] & 0x04) >> 2) ? (1 << 1) : (1 << 0);
          inst_lcall (vm, 0x00, 0x13);
        }
      else if (((((vm->_sfr[0xA8 ^ 0x80] & 0x08) >> 3)) && (((vm->_sfr[0x88 ^ 0x80] & 0x80) >> 7)) && (!vm->interrupted || (((vm->_sfr[0xB8 ^ 0x80] & 0x08) >> 3)))) && !(prioritary & 0x17))
        {
          vm->_sfr[0x88 ^ 0x80] &= ~(0x01 << 7);
          vm->interrupted |= ((vm->_sfr[0xB8 ^ 0x80] & 0x08) >> 3) ? (1 << 1) : (1 << 0);
          inst_lcall (vm, 0x00, 0x1B);
        }
      else if (((((vm->_sfr[0xA8 ^ 0x80] & 0x10) >> 4)) && (((vm->_sfr[0x98 ^ 0x80] & 0x01) >> 0)|((vm->_sfr[0x98 ^ 0x80] & 0x02) >> 1)) && (!vm->interrupted || (((vm->_sfr[0xB8 ^ 0x80] & 0x10) >> 4)))) && !(prioritary & 0x0F))
        {
          vm->interrupted |= ((vm->_sfr[0xB8 ^ 0x80] & 0x10) >> 4) ? (1 << 1) : (1 << 0);
          inst_lcall (vm, 0x00, 0x23);
        }
    }
  vm->interrupts_blocked = 0;
}

variable_types:
n
unsigned char

variable_types: timer int

variable_types:
prioritary
unsigned char


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

do
{
fetch8051(a1);
result = operate8051((int *)a1);
}
while ( *(_WORD *)(a1 + 131464) != a2 && *(_DWORD *)a1 < a3 );
return result;
}

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

do
{
func3(a1);
result = func4((int *)a1);
}
while ( *(_WORD *)(a1 + 131464) != a2 && *(_DWORD *)a1 < a3 );
return result;
}

original_code:
void sim8051 (struct vm8051 *vm, uint16_t address, unsigned int ncy)
{
  do
    {
      fetch8051 (vm);
      operate8051 (vm);
    }
  while (vm->PC != address && vm->cycles < ncy);
}

canonical_original_code:
void sim8051(struct vm8051 *vm, unsigned short address, unsigned int ncy)
{
  do
    {
      fetch8051 (vm);
      operate8051 (vm);
    }
  while (vm->PC != address && vm->cycles < ncy);
}

variable_types: struct vm8051 { unsigned int cycles; unsigned char _data[256]; unsigned char _sfr[128]; unsigned char _xdata[65536]; unsigned char _code[65536]; unsigned char IR[4]; unsigned short PC; unsigned char interrupted; unsigned char interrupts_blocked; void *coprocessors; } *

variable_types:
address
unsigned short

variable_types:
ncy
unsigned int

return_type: void


decompiled_code:
int __fastcall print_copro_RNG(__int64 a1, _DWORD *a2)
{
printf("copro RNG: \tstatus: ");
if ( *a2 )
printf("generating (%u cy left)\n", (unsigned int)(*a2 - *(_DWORD *)a1 + 10));
else
printf("available (0x%02X)\n", *(unsigned __int8 *)(a1 + 325));
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, _DWORD *a2)
{
printf("copro RNG: \tstatus: ");
if ( *a2 )
printf("generating (%u cy left)\n", (unsigned int)(*a2 - *(_DWORD *)a1 + 10));
else
printf("available (0x%02X)\n", *(unsigned __int8 *)(a1 + 325));
return putchar(10);
}

original_code:
void print_copro_RNG (struct vm8051 *vm, void *copro)
{
  struct copro_RNG *rng = copro;
  printf ("copro RNG:              \tstatus: ");
  if (!rng->cycles_start)
    printf ("available (0x%02X)\n", vm->_sfr[0xC1 ^ 0x80]);
  else
    printf ("generating (%u cy left)\n",
            10 - (vm->cycles - rng->cycles_start));
  printf ("\n");
}

canonical_original_code:
void print_copro_RNG(struct vm8051 *vm, void *copro)
{
  struct copro_RNG *rng = copro;
  printf ("copro RNG:              \tstatus: ");
  if (!rng->cycles_start)
    printf ("available (0x%02X)\n", vm->_sfr[0xC1 ^ 0x80]);
  else
    printf ("generating (%u cy left)\n",
            10 - (vm->cycles - rng->cycles_start));
  printf ("\n");
}

variable_types:
copro
void *

variable_types: struct copro_RNG { unsigned int cycles_start; } *

user_defined_types: struct vm8051 { unsigned int cycles; unsigned char _data[256]; unsigned char _sfr[128]; unsigned char _xdata[65536]; unsigned char _code[65536]; unsigned char IR[4]; unsigned short PC; unsigned char interrupted; unsigned char interrupts_blocked; void *coprocessors; }


original_code:
void operate_copro_RNG (struct vm8051 *vm, void *copro)
{
  struct copro_RNG *rng = copro;
  if (rng->cycles_start)
    vm->_sfr[0xC0 ^ 0x80] |= 0x01;
  if ((vm->_sfr[0xC0 ^ 0x80] & 0x01) && !rng->cycles_start)
    rng->cycles_start = vm->cycles;
  if (rng->cycles_start)
    {
      if (vm->cycles - rng->cycles_start >= 10)
        {
          vm->_sfr[0xC1 ^ 0x80] = (uint8_t) rand ();
          rng->cycles_start = 0;
        }
    }
  if (!rng->cycles_start)
    vm->_sfr[0xC0 ^ 0x80] &= ~0x01;
}

canonical_original_code:
void operate_copro_RNG(struct vm8051 *vm, void *copro)
{
  struct copro_RNG *rng = copro;
  if (rng->cycles_start)
    vm->_sfr[0xC0 ^ 0x80] |= 0x01;
  if ((vm->_sfr[0xC0 ^ 0x80] & 0x01) && !rng->cycles_start)
    rng->cycles_start = vm->cycles;
  if (rng->cycles_start)
    {
      if (vm->cycles - rng->cycles_start >= 10)
        {
          vm->_sfr[0xC1 ^ 0x80] = (unsigned char) rand ();
          rng->cycles_start = 0;
        }
    }
  if (!rng->cycles_start)
    vm->_sfr[0xC0 ^ 0x80] &= ~0x01;
}

user_defined_types: struct copro_RNG { unsigned int cycles_start; }


decompiled_code:
__int64 __fastcall add_copro_RNG(__int64 a1)
{
unsigned int v1; // eax
_DWORD *v2; // rax

v1 = time(0LL);
srand(v1);
v2 = malloc(4uLL);
*v2 = 0;
operate_copro_table = operate_copro_RNG;
print_copro_table = print_copro_RNG;
return add_coprocessor(a1, v2, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
unsigned int v1; // eax
_DWORD *v2; // rax

v1 = time(0LL);
srand(v1);
v2 = malloc(4uLL);
*v2 = 0;
operate_copro_table = operate_copro_RNG;
print_copro_table = print_copro_RNG;
return add_coprocessor(a1, v2, 0LL);
}

original_code:
void add_copro_RNG (struct vm8051 *vm)
{
  struct copro_RNG *rng;
  srand (time (((void *)0)));
  rng = malloc (sizeof (struct copro_RNG));
  rng->cycles_start = 0;
  operate_copro_table[0] = &operate_copro_RNG;
  print_copro_table[0] = &print_copro_RNG;
  add_coprocessor (vm, rng, 0);
}

canonical_original_code:
void add_copro_RNG(struct vm8051 *vm)
{
  struct copro_RNG *rng;
  srand (time (((void *)0)));
  rng = malloc (sizeof (struct copro_RNG));
  rng->cycles_start = 0;
  operate_copro_table[0] = &operate_copro_RNG;
  print_copro_table[0] = &print_copro_RNG;
  add_coprocessor (vm, rng, 0);
}


decompiled_code:
void __fastcall operate_coprocessors(__int64 a1)
{
unsigned int *i; // rbx
void (__fastcall *v2)(__int64, _QWORD); // rax

for ( i = *(unsigned int **)(a1 + 131472); i; i = (unsigned int *)*((_QWORD *)i + 2) )
{
v2 = (void (__fastcall *)(__int64, _QWORD))operate_copro_table[*i];
if ( !v2 )
_assert_fail(
"operate_copro_table[copros->index] != NULL",
"vm/lib8051coprocessors.c",
0x42u,
"operate_coprocessors");
v2(a1, *((_QWORD *)i + 1));
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
unsigned int *i; // rbx
void (__fastcall *v2)(__int64, _QWORD); // rax

for ( i = *(unsigned int **)(a1 + 131472); i; i = (unsigned int *)*((_QWORD *)i + 2) )
{
v2 = (void (__fastcall *)(__int64, _QWORD))operate_copro_table[*i];
if ( !v2 )
_assert_fail(
"operate_copro_table[copros->index] != NULL",
"vm/lib8051coprocessors.c",
0x42u,
"operate_coprocessors");
v2(a1, *((_QWORD *)i + 1));
}
}

original_code:
void operate_coprocessors (struct vm8051 *vm)
{
  struct copro8051 *copros;
  copros = vm->coprocessors;
  while (copros)
    {
      ((operate_copro_table[copros->index] != ((void *)0)) ? (void) (0) : __assert_fail ("operate_copro_table[copros->index] != NULL", "vm/lib8051coprocessors.c", 66, __extension__ __PRETTY_FUNCTION__));
      operate_copro_table[copros->index] (vm, copros->contents);
      copros = copros->next;
    }
}

canonical_original_code:
void operate_coprocessors(struct vm8051 *vm)
{
  struct copro8051 *copros;
  copros = vm->coprocessors;
  while (copros)
    {
      ((operate_copro_table[copros->index] != ((void *)0)) ? (void) (0) : __assert_fail ("operate_copro_table[copros->index] != NULL", "vm/lib8051coprocessors.c", 66, __extension__ __PRETTY_FUNCTION__));
      operate_copro_table[copros->index] (vm, copros->contents);
      copros = copros->next;
    }
}

variable_types: struct copro8051 { unsigned int index; void *contents; struct copro8051 *next; } *


decompiled_code:
void __fastcall print_coprocessors(__int64 a1)
{
unsigned int *i; // rbx
void (__fastcall *v2)(__int64, _QWORD); // rax

for ( i = *(unsigned int **)(a1 + 131472); i; i = (unsigned int *)*((_QWORD *)i + 2) )
{
v2 = (void (__fastcall *)(__int64, _QWORD))print_copro_table[*i];
if ( !v2 )
_assert_fail("print_copro_table[copros->index] != NULL", "vm/lib8051coprocessors.c", 0x53u, "print_coprocessors");
v2(a1, *((_QWORD *)i + 1));
}
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
unsigned int *i; // rbx
void (__fastcall *v2)(__int64, _QWORD); // rax

for ( i = *(unsigned int **)(a1 + 131472); i; i = (unsigned int *)*((_QWORD *)i + 2) )
{
v2 = (void (__fastcall *)(__int64, _QWORD))print_copro_table[*i];
if ( !v2 )
_assert_fail("print_copro_table[copros->index] != NULL", "vm/lib8051coprocessors.c", 0x53u, "print_coprocessors");
v2(a1, *((_QWORD *)i + 1));
}
}

original_code:
void print_coprocessors (struct vm8051 *vm)
{
  struct copro8051 *copros;
  copros = vm->coprocessors;
  while (copros)
    {
      ((print_copro_table[copros->index] != ((void *)0)) ? (void) (0) : __assert_fail ("print_copro_table[copros->index] != NULL", "vm/lib8051coprocessors.c", 83, __extension__ __PRETTY_FUNCTION__));
      print_copro_table[copros->index] (vm, copros->contents);
      copros = copros->next;
    }
}

canonical_original_code:
void print_coprocessors(struct vm8051 *vm)
{
  struct copro8051 *copros;
  copros = vm->coprocessors;
  while (copros)
    {
      ((print_copro_table[copros->index] != ((void *)0)) ? (void) (0) : __assert_fail ("print_copro_table[copros->index] != NULL", "vm/lib8051coprocessors.c", 83, __extension__ __PRETTY_FUNCTION__));
      print_copro_table[copros->index] (vm, copros->contents);
      copros = copros->next;
    }
}

user_defined_types: struct copro8051 { unsigned int index; void *contents; struct copro8051 *next; }


original_code:
void free_coprocessors (struct vm8051 *vm)
{
  struct copro8051 *copros;
  copros = vm->coprocessors;
  while (copros)
    {
      free (copros->contents);
      copros = copros->next;
      free (vm->coprocessors);
      vm->coprocessors = copros;
    }
}

canonical_original_code:
void free_coprocessors(struct vm8051 *vm)
{
  struct copro8051 *copros;
  copros = vm->coprocessors;
  while (copros)
    {
      free (copros->contents);
      copros = copros->next;
      free (vm->coprocessors);
      vm->coprocessors = copros;
    }
}


mfcreate

repo: lukesalisbury/meg

decompiled_code:
__int64 __fastcall mfcreate(__int64 a1)
{
return memfile_creat(a1, 4096LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return memfile_creat(a1, 4096LL);
}

original_code:
memfile_t *mfcreate(const char *filename)
{
  return memfile_creat(filename, 4096);
}

canonical_original_code:
struct memfile_s *mfcreate(char *filename)
{
  return memfile_creat(filename, 4096);
}

variable_types:
filename
char *

return_type: struct memfile_s { char *name; char *base; unsigned long offs; unsigned long usedoffs; unsigned long size; } *


mfclose

decompiled_code:
__int64 mfclose()
{
return memfile_destroy();
}

canonical_decompiled_code:
__int64 func1()
{
return memfile_destroy();
}

original_code:
void mfclose(memfile_t *mf)
{
  memfile_destroy(mf);
}

canonical_original_code:
void mfclose(struct memfile_s *mf)
{
  memfile_destroy(mf);
}

variable_types: struct memfile_s { char *name; char *base; unsigned long offs; unsigned long usedoffs; unsigned long size; } *


mflength

decompiled_code:
__int64 __fastcall mflength(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

original_code:
size_t mflength(const memfile_t *mf)
{
  return mf->usedoffs;
}

canonical_original_code:
unsigned long mflength(struct memfile_s *mf)
{
  return mf->usedoffs;
}

return_type: unsigned long

user_defined_types: struct memfile_s { char *name; char *base; unsigned long offs; unsigned long usedoffs; unsigned long size; }


mfseek

decompiled_code:
__int64 __fastcall mfseek(__int64 a1, __int64 a2, int a3)
{
__int64 result; // rax
__int64 v4; // rbx
__int64 v6; // rax
__int64 v7; // rbp

result = *(_QWORD *)(a1 + 24);
if ( result )
{
v4 = a2;
v6 = mflength(a1);
if ( a3 == 1 )
{
v4 = *(_QWORD *)(a1 + 16) + a2;
}
else if ( a3 == 2 )
{
v4 = a2 + v6;
}
v7 = 0LL;
if ( v4 >= 0 )
{
if ( v4 <= v6 )
v6 = v4;
v7 = v6;
}
memfile_seek(a1, v7);
result = v7;
}
return result;
}

original_code:
size_t mfseek(memfile_t *mf,long offset,int whence)
{
  long length;
  ((void) (0));
  if (mf->usedoffs == 0)
    return 0L;
  length=(long)mflength(mf);
  switch (whence) {
  case 0:
    break;
  case 1:
    offset+=(long)mf->offs;
    break;
  case 2:
    ((void) (0));
    offset+=(long)length;
    break;
  }
  if (offset<0)
    offset=0;
  else if (offset>length)
    offset=length;
  memfile_seek(mf, (size_t)offset);
  return offset;
}

canonical_original_code:
unsigned long mfseek(struct memfile_s *mf, long offset, int whence)
{
  long length;
  ((void) (0));
  if (mf->usedoffs == 0)
    return 0L;
  length=(long)mflength(mf);
  switch (whence) {
  case 0:
    break;
  case 1:
    offset+=(long)mf->offs;
    break;
  case 2:
    ((void) (0));
    offset+=(long)length;
    break;
  }
  if (offset<0)
    offset=0;
  else if (offset>length)
    offset=length;
  memfile_seek(mf, (unsigned long)offset);
  return offset;
}

variable_types: offset long

variable_types: whence int

variable_types: length long


mfwrite

decompiled_code:
__int64 __fastcall mfwrite(__int64 a1, __int64 a2, __int64 a3)
{
if ( !(unsigned int)memfile_write() )
a3 = 0LL;
return a3;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, __int64 a3)
{
if ( !(unsigned int)memfile_write() )
a3 = 0LL;
return a3;
}

original_code:
size_t mfwrite(memfile_t *mf,const unsigned char *buffer,size_t size)
{
  return (memfile_write(mf, buffer, size) ? size : 0);
}

canonical_original_code:
unsigned long mfwrite(struct memfile_s *mf, unsigned char *buffer, unsigned long size)
{
  return (memfile_write(mf, buffer, size) ? size : 0);
}

variable_types:
buffer
unsigned char *

variable_types:
size
unsigned long


mfread

decompiled_code:
__int64 mfread()
{
return memfile_read();
}

canonical_decompiled_code:
__int64 func6()
{
return memfile_read();
}

original_code:
size_t mfread(memfile_t *mf,unsigned char *buffer,size_t size)
{
  return memfile_read(mf, buffer, size);
}

canonical_original_code:
unsigned long mfread(struct memfile_s *mf, unsigned char *buffer, unsigned long size)
{
  return memfile_read(mf, buffer, size);
}


mfgets

decompiled_code:
const char *__fastcall mfgets(__int64 a1, const char *a2, unsigned __int64 a3)
{
const char *v3; // r12
unsigned __int64 v5; // rax
unsigned __int64 v6; // rbx
char *v7; // rax
unsigned __int64 v8; // rax
__int64 v9; // rsi

v3 = a2;
v5 = mfread();
if ( !v5 )
return 0LL;
v6 = v5;
if ( a3 <= v5 )
{
a2[a3 - 1] = 0;
v7 = strchr(a2, 10);
if ( !v7 )
{
v9 = -1LL;
goto LABEL_8;
}
LABEL_4:
v7[1] = 0;
v8 = v7 - a2 - v6;
v9 = v8 + 1;
if ( v8 == -1LL )
return v3;
LABEL_8:
mfseek(a1, v9, 1);
return v3;
}
a2[v5] = 0;
v7 = strchr(a2, 10);
if ( v7 )
goto LABEL_4;
return v3;
}

canonical_decompiled_code:
const char *__fastcall func7(__int64 a1, const char *a2, unsigned __int64 a3)
{
const char *v3; // r12
unsigned __int64 v5; // rax
unsigned __int64 v6; // rbx
char *v7; // rax
unsigned __int64 v8; // rax
__int64 v9; // rsi

v3 = a2;
v5 = func6();
if ( !v5 )
return 0LL;
v6 = v5;
if ( a3 <= v5 )
{
a2[a3 - 1] = 0;
v7 = strchr(a2, 10);
if ( !v7 )
{
v9 = -1LL;
goto LABEL_8;
}
LABEL_4:
v7[1] = 0;
v8 = v7 - a2 - v6;
v9 = v8 + 1;
if ( v8 == -1LL )
return v3;
LABEL_8:
func4(a1, v9, 1);
return v3;
}
a2[v5] = 0;
v7 = strchr(a2, 10);
if ( v7 )
goto LABEL_4;
return v3;
}

original_code:
char *mfgets(memfile_t *mf,char *string,size_t size)
{
  char *ptr;
  size_t read;
  long seek;
  ((void) (0));
  read=mfread(mf,(unsigned char *)string,size);
  if (read==0)
    return ((void *)0);
  seek=0L;
  ((void) (0));
  if (read<size) {
    string[read]='\0';
  } else {
    string[size-1]='\0';
    seek=-1;
  }
  ptr=strchr(string,'\n');
  if (ptr!=((void *)0)) {
    *(ptr+1)='\0';
    seek=(long)(ptr-string)+1-(long)read;
  }
  ((void) (0));
  if (seek!=0)
    mfseek(mf,seek,1);
  return string;
}

canonical_original_code:
char *mfgets(struct memfile_s *mf, char *string, unsigned long size)
{
  char *ptr;
  unsigned long read;
  long seek;
  ((void) (0));
  read=mfread(mf,(unsigned char *)string,size);
  if (read==0)
    return ((void *)0);
  seek=0L;
  ((void) (0));
  if (read<size) {
    string[read]='\0';
  } else {
    string[size-1]='\0';
    seek=-1;
  }
  ptr=strchr(string,'\n');
  if (ptr!=((void *)0)) {
    *(ptr+1)='\0';
    seek=(long)(ptr-string)+1-(long)read;
  }
  ((void) (0));
  if (seek!=0)
    mfseek(mf,seek,1);
  return string;
}

variable_types:
string
char *

variable_types:
ptr
char *

variable_types:
read
unsigned long

variable_types: seek long

return_type: char *


mfputs

decompiled_code:
_BOOL8 __fastcall mfputs(__int64 a1, const char *a2)
{
__int64 v2; // rbx

v2 = strlen(a2);
return v2 == mfwrite(a1, (__int64)a2, v2);
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(__int64 a1, const char *a2)
{
__int64 v2; // rbx

v2 = strlen(a2);
return v2 == func5(a1, (__int64)a2, v2);
}

original_code:
int mfputs(memfile_t *mf,const char *string)
{
  size_t written,length;
  ((void) (0));
  length=strlen(string);
  written=mfwrite(mf,(unsigned char *)string,length);
  return written==length;
}

canonical_original_code:
int mfputs(struct memfile_s *mf, char *string)
{
  unsigned long written; unsigned long length;
  ((void) (0));
  length=strlen(string);
  written=mfwrite(mf,(unsigned char *)string,length);
  return written==length;
}

variable_types:
written
unsigned long

variable_types:
length
unsigned long

return_type: int


decompiled_code:
__int64 __fastcall read_file(__int64 a1)
{
_QWORD *v1; // rbp
__int64 v2; // rax
__int64 v3; // rbx
__int64 v4; // r12
__int64 v5; // r12
__int64 v6; // r12
__int64 v7; // rax
__int64 v8; // r12
__int64 v10[4]; // [rsp+8h] [rbp-20h] BYREF

v10[0] = 0LL;
v1 = (_QWORD *)g_strsplit(a1, &unk_360, 2LL);
v2 = g_path_get_basename(*v1);
v3 = g_utf8_strup(v2, -1LL);
g_file_get_contents(a1, v10, 0LL, 0LL);
if ( title_replace )
{
v4 = replace_string((__int64)"%BUILDHEADER_GUI_TITLE%", v10[0], title_replace);
g_free(v10[0]);
v10[0] = v4;
}
if ( descript_replace )
{
v5 = replace_string((__int64)"%BUILDHEADER_GUI_DESCRIPT%", v10[0], descript_replace);
g_free(v10[0]);
v10[0] = v5;
}
if ( icon_replace )
{
v6 = replace_string((__int64)"%BUILDHEADER_GUI_ICON%", v10[0], icon_replace);
g_free(v10[0]);
v10[0] = v6;
}
v7 = g_strescape(v10[0], 0LL);
v8 = g_strconcat("#define GUI_", v3, " \"", v7, "\" \n", 0LL);
g_strfreev(v1);
g_free(v10[0]);
g_free(v3);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
_QWORD *v1; // rbp
__int64 v2; // rax
__int64 v3; // rbx
__int64 v4; // r12
__int64 v5; // r12
__int64 v6; // r12
__int64 v7; // rax
__int64 v8; // r12
__int64 v10[4]; // [rsp+8h] [rbp-20h] BYREF

v10[0] = 0LL;
v1 = (_QWORD *)g_strsplit(a1, &unk_360, 2LL);
v2 = g_path_get_basename(*v1);
v3 = g_utf8_strup(v2, -1LL);
g_file_get_contents(a1, v10, 0LL, 0LL);
if ( title_replace )
{
v4 = func0((__int64)"%BUILDHEADER_GUI_TITLE%", v10[0], title_replace);
g_free(v10[0]);
v10[0] = v4;
}
if ( descript_replace )
{
v5 = func0((__int64)"%BUILDHEADER_GUI_DESCRIPT%", v10[0], descript_replace);
g_free(v10[0]);
v10[0] = v5;
}
if ( icon_replace )
{
v6 = func0((__int64)"%BUILDHEADER_GUI_ICON%", v10[0], icon_replace);
g_free(v10[0]);
v10[0] = v6;
}
v7 = g_strescape(v10[0], 0LL);
v8 = g_strconcat("#define GUI_", v3, " \"", v7, "\" \n", 0LL);
g_strfreev(v1);
g_free(v10[0]);
g_free(v3);
return v8;
}

original_code:
gchar * read_file( const gchar * file_name )
{
 gchar * new_content = ((void *)0);
 gchar * content = ((void *)0);
 gchar * new_define = ((void *)0);
 gchar ** f = g_strsplit( file_name, ".", 2 );
 new_define = g_utf8_strup( g_path_get_basename( f[0] ), -1);
 g_file_get_contents( file_name, &content, ((void *)0), ((void *)0));
 if ( title_replace )
 {
  gchar * temp = replace_string( "%BUILDHEADER_GUI_TITLE%", content, title_replace );
  g_free(content);
  content = temp;
 }
 if ( descript_replace )
 {
  gchar * temp = replace_string( "%BUILDHEADER_GUI_DESCRIPT%", content, descript_replace );
  g_free(content);
  content = temp;
 }
 if ( icon_replace )
 {
  gchar * temp = replace_string( "%BUILDHEADER_GUI_ICON%", content, icon_replace );
  g_free(content);
  content = temp;
 }
 new_content = g_strconcat( "#define GUI_", new_define, " \"", g_strescape(content, ((void *)0)), "\" \n", ((void *)0) );
 g_strfreev(f);
 g_free(content);
 g_free(new_define);
 return new_content;
}

canonical_original_code:
char *read_file(char *file_name)
{
 char *new_content = ((void *)0);
 char *content = ((void *)0);
 char *new_define = ((void *)0);
 char **f = g_strsplit( file_name, ".", 2 );
 new_define = g_utf8_strup( g_path_get_basename( f[0] ), -1);
 g_file_get_contents( file_name, &content, ((void *)0), ((void *)0));
 if ( title_replace )
 {
  char *temp = replace_string( "%BUILDHEADER_GUI_TITLE%", content, title_replace );
  g_free(content);
  content = temp;
 }
 if ( descript_replace )
 {
  char *temp = replace_string( "%BUILDHEADER_GUI_DESCRIPT%", content, descript_replace );
  g_free(content);
  content = temp;
 }
 if ( icon_replace )
 {
  char *temp = replace_string( "%BUILDHEADER_GUI_ICON%", content, icon_replace );
  g_free(content);
  content = temp;
 }
 new_content = g_strconcat( "#define GUI_", new_define, " \"", g_strescape(content, ((void *)0)), "\" \n", ((void *)0) );
 g_strfreev(f);
 g_free(content);
 g_free(new_define);
 return new_content;
}

variable_types:
content
char *

variable_types:
f
char **

variable_types:
temp
char *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm0_8
__int64 v4; // r13
const char *v5; // r12
_QWORD *v6; // rbx

if ( argc <= 1 )
{
g_print("buildheaderfile.exe - missing argument", argv, envp);
}
else
{
v4 = g_timer_new(argc, argv, envp);
if ( argc > 2 )
{
title_replace = (__int64)argv[3];
if ( argc > 3 )
descript_replace = (__int64)argv[4];
if ( argc > 4 )
icon_replace = (__int64)argv[5];
}
v5 = (const char *)g_strdup(argv[2]);
v6 = (_QWORD *)scan_files((__int64)argv[1]);
if ( v6 )
{
g_timer_elapsed(v4, 0LL);
g_print("Writing %d header to %s. Time Taken: %f\n", (unsigned int)header_count, v5, v3);
g_file_set_contents(v5, *v6, -1LL, 0LL);
}
g_free(v5);
g_string_free(v6, 1LL);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm0_8
__int64 v4; // r13
const char *v5; // r12
_QWORD *v6; // rbx

if ( argc <= 1 )
{
g_print("buildheaderfile.exe - missing argument", argv, envp);
}
else
{
v4 = g_timer_new(argc, argv, envp);
if ( argc > 2 )
{
title_replace = (__int64)argv[3];
if ( argc > 3 )
descript_replace = (__int64)argv[4];
if ( argc > 4 )
icon_replace = (__int64)argv[5];
}
v5 = (const char *)g_strdup(argv[2]);
v6 = (_QWORD *)func2((__int64)argv[1]);
if ( v6 )
{
g_timer_elapsed(v4, 0LL);
g_print("Writing %d header to %s. Time Taken: %f\n", (unsigned int)header_count, v5, v3);
g_file_set_contents(v5, *v6, -1LL, 0LL);
}
g_free(v5);
g_string_free(v6, 1LL);
}
return 0;
}

original_code:
int main( int argc, char *argv[] )
{
 int arg_c = 6;
 char * arg_v[7];
 program_directory = g_path_get_dirname(argv[0]);
 arg_v[0] = g_strdup(argv[0]);
 include_directory = get_global_include_path();
 if ( !include_directory )
 {
  include_directory = g_strdup(".");
 }
 main_args(argc, argv);
 if ( !source_filepath )
 {
  g_print("Mokoi Pawn Compiler\n");
  g_print("Headers located at %s\n", get_global_include_path() );
  g_print("No file given\n");
  g_print("\n");
  return 0;
 }
 if ( temporary_filepath )
 {
  filename = temporary_filepath;
 }
 else
 {
  filename = source_filepath;
 }
 output_filename = strip_file_extension( source_filename );
 if ( project_directory )
 {
  if ( g_str_has_prefix( source_filepath, project_directory ) )
  {
   char * dir = source_directory + strlen(project_directory);
   output_directory = g_build_path("/", project_directory, "c", dir, ((void *)0));
  }
  else if (source_directory)
  {
   output_directory = g_build_path("/", project_directory, "c", source_directory, ((void *)0));
  }
  else
  {
   output_directory = g_strdup(project_directory);
  }
 }
 else
 {
  output_directory = g_strdup(source_directory);
 }
 g_mkdir_with_parents( output_directory, 0755 );
 output_filename_64 = g_strdup_printf( "%s.amx64", output_filename );
 output_filename_32 = g_strdup_printf( "%s.amx", output_filename );
 if ( xml_output )
 {
  xml_content = g_string_new("");
  g_string_printf(xml_content, "<results file=\"%s\">\n", source_filename);
 }
 else
 {
  g_print( "Saving to %s %s\n", output_directory, output_filename_32 );
 }
 arg_v[1] = g_strdup( filename );
 arg_v[2] = g_strconcat( "-i", include_directory, ((void *)0) );
 arg_v[3] = g_strconcat( "-i", routines_directory, ((void *)0) );
 if ( routines_global_directory )
 {
  arg_c++;
  arg_v[6] = g_strconcat( "-i", routines_global_directory, ((void *)0) );
 }
 arg_v[4] = g_strconcat( "-o", output_directory, "/", output_filename_32, ((void *)0) );
 arg_v[5] = g_strdup("-C32");
 compiler_main(arg_c, arg_v, handling_error_code);
 g_free(arg_v[4]);
 g_free(arg_v[5]);
 if ( !fatal_error_count )
 {
  arg_v[4] = g_strconcat( "-o", output_directory, "/", output_filename_64, ((void *)0) );
  arg_v[5] = g_strdup("-C64");
  compiler_main(arg_c, arg_v, handling_error_code);
  g_free(arg_v[4]);
  g_free(arg_v[5]);
 }
 if ( xml_output )
 {
  xml_content = g_string_append(xml_content, "</results>\n");
  if ( xml_content )
   g_print( "%s", xml_content->str );
  else
   g_print("<error source=\"%s\"/>\n", source_filepath);
 }
 g_free(arg_v[0]);
 g_free(arg_v[1]);
 g_free(arg_v[2]);
 g_free(arg_v[3]);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int arg_c = 6;
 char *arg_v[7];
 program_directory = g_path_get_dirname(argv[0]);
 arg_v[0] = g_strdup(argv[0]);
 include_directory = get_global_include_path();
 if ( !include_directory )
 {
  include_directory = g_strdup(".");
 }
 main_args(argc, argv);
 if ( !source_filepath )
 {
  g_print("Mokoi Pawn Compiler\n");
  g_print("Headers located at %s\n", get_global_include_path() );
  g_print("No file given\n");
  g_print("\n");
  return 0;
 }
 if ( temporary_filepath )
 {
  filename = temporary_filepath;
 }
 else
 {
  filename = source_filepath;
 }
 output_filename = strip_file_extension( source_filename );
 if ( project_directory )
 {
  if ( g_str_has_prefix( source_filepath, project_directory ) )
  {
   char *dir = source_directory + strlen(project_directory);
   output_directory = g_build_path("/", project_directory, "c", dir, ((void *)0));
  }
  else if (source_directory)
  {
   output_directory = g_build_path("/", project_directory, "c", source_directory, ((void *)0));
  }
  else
  {
   output_directory = g_strdup(project_directory);
  }
 }
 else
 {
  output_directory = g_strdup(source_directory);
 }
 g_mkdir_with_parents( output_directory, 0755 );
 output_filename_64 = g_strdup_printf( "%s.amx64", output_filename );
 output_filename_32 = g_strdup_printf( "%s.amx", output_filename );
 if ( xml_output )
 {
  xml_content = g_string_new("");
  g_string_printf(xml_content, "<results file=\"%s\">\n", source_filename);
 }
 else
 {
  g_print( "Saving to %s %s\n", output_directory, output_filename_32 );
 }
 arg_v[1] = g_strdup( filename );
 arg_v[2] = g_strconcat( "-i", include_directory, ((void *)0) );
 arg_v[3] = g_strconcat( "-i", routines_directory, ((void *)0) );
 if ( routines_global_directory )
 {
  arg_c++;
  arg_v[6] = g_strconcat( "-i", routines_global_directory, ((void *)0) );
 }
 arg_v[4] = g_strconcat( "-o", output_directory, "/", output_filename_32, ((void *)0) );
 arg_v[5] = g_strdup("-C32");
 compiler_main(arg_c, arg_v, handling_error_code);
 g_free(arg_v[4]);
 g_free(arg_v[5]);
 if ( !fatal_error_count )
 {
  arg_v[4] = g_strconcat( "-o", output_directory, "/", output_filename_64, ((void *)0) );
  arg_v[5] = g_strdup("-C64");
  compiler_main(arg_c, arg_v, handling_error_code);
  g_free(arg_v[4]);
  g_free(arg_v[5]);
 }
 if ( xml_output )
 {
  xml_content = g_string_append(xml_content, "</results>\n");
  if ( xml_content )
   g_print( "%s", xml_content->str );
  else
   g_print("<error source=\"%s\"/>\n", source_filepath);
 }
 g_free(arg_v[0]);
 g_free(arg_v[1]);
 g_free(arg_v[2]);
 g_free(arg_v[3]);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
dir
char *


minimum

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

if ( a2 > a3 )
a2 = a3;
result = a1;
if ( a2 <= (int)a1 )
result = (unsigned int)a2;
return result;
}

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

if ( a2 > a3 )
a2 = a3;
result = a1;
if ( a2 <= (int)a1 )
result = (unsigned int)a2;
return result;
}

original_code:
static int minimum(int a,int b,int c)
{
  int min=a;
  if(b<min)
    min=b;
  if(c<min)
    min=c;
  return min;
}

canonical_original_code:
static int minimum(int a, int b, int c)
{
  int min = a;
  if(b<min)
    min=b;
  if(c<min)
    min=c;
  return min;
}

variable_types: a int

variable_types: b int

variable_types: c int

variable_types: min int


errorset

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

switch ( a1 )
{
case 0:
errflag = 0;
break;
case 1:
errflag = 1;
break;
case 2:
result = (unsigned int)fline;
errstart = fline;
break;
case 3:
errstart = -1;
errline = -1;
errfile = -1;
break;
case 4:
errstart = -1;
errline = a2;
break;
case 5:
errfile = a2;
break;
default:
return result;
}
return result;
}

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

switch ( a1 )
{
case 0:
errflag = 0;
break;
case 1:
errflag = 1;
break;
case 2:
result = (unsigned int)fline;
errstart = fline;
break;
case 3:
errstart = -1;
errline = -1;
errfile = -1;
break;
case 4:
errstart = -1;
errline = a2;
break;
case 5:
errfile = a2;
break;
default:
return result;
}
return result;
}

original_code:
void errorset(int code,int line)
{
  switch (code) {
  case 0:
    errflag=0;
    break;
  case 1:
    errflag=1;
    break;
  case 2:
    errstart=fline;
    break;
  case 3:
    errstart=-1;
    errline=-1;
    errfile=-1;
    break;
  case 4:
    errstart=-1;
    errline=line;
    break;
  case 5:
    errfile=line;
    break;
  }
}

canonical_original_code:
void errorset(int code, int line)
{
  switch (code) {
  case 0:
    errflag=0;
    break;
  case 1:
    errflag=1;
    break;
  case 2:
    errstart=fline;
    break;
  case 3:
    errstart=-1;
    errline=-1;
    errfile=-1;
    break;
  case 4:
    errstart=-1;
    errline=line;
    break;
  case 5:
    errfile=line;
    break;
  }
}

variable_types: code int

variable_types: line int


decompiled_code:
__int64 __fastcall pc_enablewarning(int a1, int a2)
{
unsigned int v2; // er8
int v3; // edi
int v4; // eax
int v5; // edx

v2 = 0;
if ( a1 > 199 )
{
v3 = a1 - 200;
if ( (unsigned int)v3 <= 0x26 )
{
v4 = v3 >> 3;
v5 = 1 << (v3 % 8);
if ( a2 == 1 )
{
warndisable[v4] &= ~(_BYTE)v5;
v2 = 1;
}
else if ( a2 == 2 )
{
warndisable[v4] ^= v5;
v2 = 1;
}
else
{
v2 = 1;
if ( !a2 )
warndisable[v4] |= v5;
}
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, int a2)
{
unsigned int v2; // er8
int v3; // edi
int v4; // eax
int v5; // edx

v2 = 0;
if ( a1 > 199 )
{
v3 = a1 - 200;
if ( (unsigned int)v3 <= 0x26 )
{
v4 = v3 >> 3;
v5 = 1 << (v3 % 8);
if ( a2 == 1 )
{
warndisable[v4] &= ~(_BYTE)v5;
v2 = 1;
}
else if ( a2 == 2 )
{
warndisable[v4] ^= v5;
v2 = 1;
}
else
{
v2 = 1;
if ( !a2 )
warndisable[v4] |= v5;
}
}
}
return v2;
}

original_code:
int pc_enablewarning(int number,int enable)
{
  int index;
  unsigned char mask;
  if (number<200)
    return 0;
  number -= 200;
  if (number>=(sizeof warnmsg / sizeof warnmsg[0]))
    return 0;
  index=number/8;
  mask=(unsigned char)(1 << (number%8));
  switch (enable) {
  case 0:
    warndisable[index] |= mask;
    break;
  case 1:
    warndisable[index] &= (unsigned char)~mask;
    break;
  case 2:
    warndisable[index] ^= mask;
    break;
  }
  return 1;
}

canonical_original_code:
int pc_enablewarning(int number, int enable)
{
  int index;
  unsigned char mask;
  if (number<200)
    return 0;
  number -= 200;
  if (number>=(sizeof warnmsg / sizeof warnmsg[0]))
    return 0;
  index=number/8;
  mask=(unsigned char)(1 << (number%8));
  switch (enable) {
  case 0:
    warndisable[index] |= mask;
    break;
  case 1:
    warndisable[index] &= (unsigned char)~mask;
    break;
  case 2:
    warndisable[index] ^= mask;
    break;
  }
  return 1;
}

variable_types: number int

variable_types: enable int

variable_types: index int

variable_types:
mask
unsigned char


original_code:
int levenshtein_distance(const char *s,const char*t)
{
  int k,i,j,cost,distance;
  int *d;
  int n=(int)strlen(s);
  int m=(int)strlen(t);
  ((void) (0));
  d=(int*)malloc((sizeof(int))*(m+1)*(n+1));
  m++;
  n++;
  for (k=0;k<n;k++)
    d[k]=k;
  for (k=0;k<m;k++)
    d[k*n]=k;
  for (i=1;i<n;i++) {
    for (j=1;j<m;j++) {
      cost= (tolower(s[i-1])!=tolower(t[j-1]));
      d[j*n+i]=minimum(d[(j-1)*n+i]+1,d[j*n+i-1]+1,d[(j-1)*n+i-1]+cost);
    }
  }
  distance=d[n*m-1];
  free(d);
  return distance;
}

canonical_original_code:
int levenshtein_distance(char *s, char *t)
{
  int k; int i; int j; int cost; int distance;
  int *d;
  int n = (int)strlen(s);
  int m = (int)strlen(t);
  ((void) (0));
  d=(int *)malloc((sizeof(int))*(m+1)*(n+1));
  m++;
  n++;
  for (k=0;k<n;k++)
    d[k]=k;
  for (k=0;k<m;k++)
    d[k*n]=k;
  for (i=1;i<n;i++) {
    for (j=1;j<m;j++) {
      cost= (tolower(s[i-1])!=tolower(t[j-1]));
      d[j*n+i]=minimum(d[(j-1)*n+i]+1,d[j*n+i-1]+1,d[(j-1)*n+i-1]+cost);
    }
  }
  distance=d[n*m-1];
  free(d);
  return distance;
}

variable_types:
s
char *

variable_types:
t
char *

variable_types: k int

variable_types: i int

variable_types: j int

variable_types: cost int

variable_types: distance int

variable_types:
d
int *

variable_types: n int

variable_types: m int


decompiled_code:
__int64 __fastcall error_suggest_list(int a1, const char *a2, const char **a3)
{
const char *v4; // rbx
int v5; // er12
const char *v6; // r14
int v7; // eax
const char *v8; // r14

if ( sc_status != 2 )
return 0LL;
if ( !*a2 )
goto LABEL_15;
v4 = *a3;
if ( !*a3 )
goto LABEL_15;
v5 = 0x7FFFFFFF;
v6 = 0LL;
do
{
v7 = levenshtein_distance(v4 + 8, a2);
if ( v7 < v5 )
{
if ( v7 <= 2 )
v5 = v7;
if ( v7 <= 2 )
v6 = v4;
}
v4 = *(const char **)v4;
}
while ( v4 );
if ( v6 && (v8 = v6 + 8, strcmp(a2, v8)) )
error_localalias(a1 | 0x100000000LL, a2, v8);
else
LABEL_15:
error_localalias(a1, a2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, const char *a2, const char **a3)
{
const char *v4; // rbx
int v5; // er12
const char *v6; // r14
int v7; // eax
const char *v8; // r14

if ( sc_status != 2 )
return 0LL;
if ( !*a2 )
goto LABEL_15;
v4 = *a3;
if ( !*a3 )
goto LABEL_15;
v5 = 0x7FFFFFFF;
v6 = 0LL;
do
{
v7 = func4(v4 + 8, a2);
if ( v7 < v5 )
{
if ( v7 <= 2 )
v5 = v7;
if ( v7 <= 2 )
v6 = v4;
}
v4 = *(const char **)v4;
}
while ( v4 );
if ( v6 && (v8 = v6 + 8, strcmp(a2, v8)) )
func1(a1 | 0x100000000LL, a2, v8);
else
LABEL_15:
func1(a1, a2);
return 0LL;
}

original_code:
int error_suggest_list(int number,const char *name,constvalue *list)
{
  ((void) (0));
  ((void) (0));
  if (sc_status==statWRITE) {
    constvalue *closest=((void *)0);
    if (strlen(name)>0) {
      int dist,closestdist=0x7fffffff;
      while (list->next!=((void *)0)) {
        list=list->next;
        dist=levenshtein_distance(list->name,name);
        if (dist<closestdist && dist<=2) {
          closest=list;
          closestdist=dist;
        }
      }
    }
    if (closest!=((void *)0) && strcmp(name,closest->name)!=0)
      error(((long)(number) | ((long)(1) << (sizeof(long)*4))),name,closest->name);
    else
      error(number,name);
  }
  return 0;
}

canonical_original_code:
int error_suggest_list(int number, char *name, struct s_constvalue *list)
{
  ((void) (0));
  ((void) (0));
  if (sc_status==statWRITE) {
    struct s_constvalue *closest = ((void *)0);
    if (strlen(name)>0) {
      int dist; int closestdist = 0x7fffffff;
      while (list->next!=((void *)0)) {
        list=list->next;
        dist=levenshtein_distance(list->name,name);
        if (dist<closestdist && dist<=2) {
          closest=list;
          closestdist=dist;
        }
      }
    }
    if (closest!=((void *)0) && strcmp(name,closest->name)!=0)
      error(((long)(number) | ((long)(1) << (sizeof(long)*4))),name,closest->name);
    else
      error(number,name);
  }
  return 0;
}

variable_types:
name
char *

variable_types: struct s_constvalue { struct s_constvalue *next; char name[-1]; long value; int index; char usage; } *

variable_types: dist int

variable_types: closestdist int


decompiled_code:
__int64 __fastcall find_closestsymbol(const char *a1, int a2)
{
__int64 result; // rax
int v3; // ebx
__int64 v4; // [rsp+0h] [rbp-28h] BYREF
__int64 v5[4]; // [rsp+8h] [rbp-20h] BYREF

if ( sc_status == 1 )
return 0LL;
result = 0LL;
if ( *a1 )
{
v3 = find_closestsymbol_table(a1, &loctab, a2, v5);
if ( v3 <= (int)find_closestsymbol_table(a1, &glbtab, a2, &v4) )
result = v5[0];
else
result = v4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1, int a2)
{
__int64 result; // rax
int v3; // ebx
__int64 v4; // [rsp+0h] [rbp-28h] BYREF
__int64 v5[4]; // [rsp+8h] [rbp-20h] BYREF

if ( sc_status == 1 )
return 0LL;
result = 0LL;
if ( *a1 )
{
v3 = func6(a1, &loctab, a2, v5);
if ( v3 <= (int)func6(a1, &glbtab, a2, &v4) )
result = v5[0];
else
result = v4;
}
return result;
}

original_code:
symbol *find_closestsymbol(const char *name,int symboltype)
{
  symbol *symloc,*symglb;
  int distloc,distglb;
  if (sc_status==statFIRST)
    return ((void *)0);
  ((void) (0));
  if (strlen(name)==0)
    return ((void *)0);
  distloc=find_closestsymbol_table(name,&loctab,symboltype,&symloc);
  distglb=find_closestsymbol_table(name,&glbtab,symboltype,&symglb);
  return (distglb<distloc) ? symglb : symloc;
}

canonical_original_code:
struct s_symbol *find_closestsymbol(char *name, int symboltype)
{
  struct s_symbol *symloc; struct s_symbol *symglb;
  int distloc; int distglb;
  if (sc_status==statFIRST)
    return ((void *)0);
  ((void) (0));
  if (strlen(name)==0)
    return ((void *)0);
  distloc=find_closestsymbol_table(name,&loctab,symboltype,&symloc);
  distglb=find_closestsymbol_table(name,&glbtab,symboltype,&symglb);
  return (distglb<distloc) ? symglb : symloc;
}

variable_types: symboltype int

variable_types: struct s_symbol { struct s_symbol *next; struct s_symbol *parent; char name[-1]; unsigned int hash; long addr; long codeaddr; int index; char vclass; char ident; short usage; char flags; int compound; int tag; union { int declared; struct s_constvalue { struct s_constvalue *next; char name[-1]; long value; int index; char usage; } *lib; long stacksize; int enumlist; } x; union { struct s_arginfo { char name[-1]; char ident; char usage; int *tags; int numtags; int dim[3]; struct s_constvalue *dimnames[3]; int numdim; unsigned char hasdefault; union { long val; struct { char *symname; short level; } size; struct { long *data; int size; int arraysize; long addr; } array; } defvalue; int defvalue_tag; } *arglist; struct { long length; short level; struct s_constvalue *names; } array; } dim; struct s_statelist { struct s_statelist *next; int label; long addr; long endaddr; int id; } *states; int fvisible; int fnumber; int lnumber; struct s_symbol **refer; int numrefers; char *documentation; } *

variable_types: distloc int

variable_types: distglb int

user_defined_types: struct s_symbol { struct s_symbol *next; struct s_symbol *parent; char name[-1]; unsigned int hash; long addr; long codeaddr; int index; char vclass; char ident; short usage; char flags; int compound; int tag; union { int declared; struct s_constvalue *lib; long stacksize; int enumlist; } x; union { struct s_arginfo *arglist; struct { long length; short level; struct s_constvalue *names; } array; } dim; struct s_statelist *states; int fvisible; int fnumber; int lnumber; struct s_symbol **refer; int numrefers; char *documentation; }


decompiled_code:
__int64 __fastcall error_suggest(int a1, const char *a2, int a3)
{
__int64 v3; // rax
__int64 v4; // r12

v3 = find_closestsymbol(a2, a3);
if ( v3 && (v4 = v3 + 16, strcmp(a2, (const char *)(v3 + 16))) )
error_localalias(a1 | 0x100000000LL, a2, v4);
else
error_localalias(a1, a2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, const char *a2, int a3)
{
__int64 v3; // rax
__int64 v4; // r12

v3 = func7(a2, a3);
if ( v3 && (v4 = v3 + 16, strcmp(a2, (const char *)(v3 + 16))) )
func1(a1 | 0x100000000LL, a2, v4);
else
func1(a1, a2);
return 0LL;
}

original_code:
int error_suggest(int number,const char *name,int ident)
{
  symbol *closestsym=find_closestsymbol(name,ident);
  if (closestsym!=((void *)0) && strcmp(name,closestsym->name)!=0)
    error(((long)(number) | ((long)(1) << (sizeof(long)*4))),name,closestsym->name);
  else
    error(number,name);
  return 0;
}

canonical_original_code:
int error_suggest(int number, char *name, int ident)
{
  struct s_symbol *closestsym = find_closestsymbol(name,ident);
  if (closestsym!=((void *)0) && strcmp(name,closestsym->name)!=0)
    error(((long)(number) | ((long)(1) << (sizeof(long)*4))),name,closestsym->name);
  else
    error(number,name);
  return 0;
}

variable_types: number int

variable_types: ident int

user_defined_types: struct s_statelist { struct s_statelist *next; int label; long addr; long endaddr; int id; }

user_defined_types: struct s_constvalue { struct s_constvalue *next; char name[-1]; long value; int index; char usage; }

user_defined_types: struct s_arginfo { char name[-1]; char ident; char usage; int *tags; int numtags; int dim[3]; struct s_constvalue *dimnames[3]; int numdim; unsigned char hasdefault; union { long val; struct { char *symname; short level; } size; struct { long *data; int size; int arraysize; long addr; } array; } defvalue; int defvalue_tag; }


original_code:
static void delete_stringpairtable(stringpair *root)
{
  stringpair *cur, *next;
  ((void) (0));
  cur=root->next;
  while (cur!=((void *)0)) {
    next=cur->next;
    ((void) (0));
    ((void) (0));
    free(cur->first);
    free(cur->second);
    free(cur);
    cur=next;
  }
  memset(root,0,sizeof(stringpair));
}

canonical_original_code:
static void delete_stringpairtable(struct s_stringpair *root)
{
  struct s_stringpair *cur; struct s_stringpair *next;
  ((void) (0));
  cur=root->next;
  while (cur!=((void *)0)) {
    next=cur->next;
    ((void) (0));
    ((void) (0));
    free(cur->first);
    free(cur->second);
    free(cur);
    cur=next;
  }
  memset(root,0,sizeof(stringpair));
}

variable_types: struct s_stringpair { struct s_stringpair *next; char *first; char *second; int matchlength; } *