disasm

repo: pelrun/Dispel

decompiled_code:
__int64 __fastcall disasm(unsigned __int8 *a1, int a2, _BYTE *a3, char *a4, char a5)
{
unsigned __int8 *v5; // rbp
__int64 v6; // rax
__int64 v7; // rcx
unsigned int v8; // er14
unsigned int v9; // eax
__int64 v10; // rsi
__int64 v12; // rdx
const char *v13; // rsi
char *v14; // r12
__int64 v15; // rdx
char *v16; // rdi
const char *v17; // rsi
__int64 v18; // rdx
const char *v19; // rsi
__int64 v20; // rdx
__int16 v21; // ax
unsigned int v22; // er8
int v23; // eax
int v24; // [rsp+8h] [rbp-80h]
char v28[5]; // [rsp+22h] [rbp-66h] BYREF
char s[8]; // [rsp+27h] [rbp-61h] BYREF
char v30; // [rsp+2Fh] [rbp-59h]
char v31[88]; // [rsp+30h] [rbp-58h] BYREF

v5 = a1;
v6 = *a1;
v7 = v6;
switch ( *a1 )
{
case 0u:
*(_DWORD *)v28 = 7041634;
goto LABEL_13;
case 1u:
case 3u:
case 5u:
case 7u:
case 9u:
case 0xDu:
case 0xFu:
case 0x11u:
case 0x12u:
case 0x13u:
case 0x15u:
case 0x17u:
case 0x19u:
case 0x1Du:
case 0x1Fu:
*(_DWORD *)v28 = 6386287;
goto LABEL_3;
case 2u:
*(_DWORD *)v28 = 7368547;
goto LABEL_13;
case 4u:
case 0xCu:
*(_DWORD *)v28 = 6452084;
goto LABEL_3;
case 6u:
case 0xAu:
case 0xEu:
case 0x16u:
case 0x1Eu:
*(_DWORD *)v28 = 7107425;
goto LABEL_3;
case 8u:
*(_DWORD *)v28 = 7366768;
goto LABEL_5;
case 0xBu:
*(_DWORD *)v28 = 6580336;
goto LABEL_5;
case 0x10u:
*(_DWORD *)v28 = 7106658;
goto LABEL_37;
case 0x14u:
case 0x1Cu:
*(_DWORD *)v28 = 6451828;
goto LABEL_3;
case 0x18u:
*(_DWORD *)v28 = 6515811;
goto LABEL_5;
case 0x1Au:
case 0xE6u:
case 0xEEu:
case 0xF6u:
case 0xFEu:
*(_DWORD *)v28 = 6516329;
goto LABEL_3;
case 0x1Bu:
*(_DWORD *)v28 = 7562100;
goto LABEL_5;
case 0x20u:
case 0x22u:
case 0xFCu:
*(_DWORD *)v28 = 7500650;
goto LABEL_3;
case 0x21u:
case 0x23u:
case 0x25u:
case 0x27u:
case 0x29u:
case 0x2Du:
case 0x2Fu:
case 0x31u:
case 0x32u:
case 0x33u:
case 0x35u:
case 0x37u:
case 0x39u:
case 0x3Du:
case 0x3Fu:
*(_DWORD *)v28 = 6581857;
goto LABEL_3;
case 0x24u:
case 0x2Cu:
case 0x34u:
case 0x3Cu:
case 0x89u:
*(_DWORD *)v28 = 7629154;
goto LABEL_3;
case 0x26u:
case 0x2Au:
case 0x2Eu:
case 0x36u:
case 0x3Eu:
*(_DWORD *)v28 = 7106418;
goto LABEL_3;
case 0x28u:
*(_DWORD *)v28 = 7367792;
goto LABEL_5;
case 0x2Bu:
*(_DWORD *)v28 = 6581360;
goto LABEL_5;
case 0x30u:
*(_DWORD *)v28 = 6909282;
goto LABEL_37;
case 0x38u:
*(_DWORD *)v28 = 6514035;
goto LABEL_5;
case 0x3Au:
case 0xC6u:
case 0xCEu:
case 0xD6u:
case 0xDEu:
*(_DWORD *)v28 = 6514020;
goto LABEL_3;
case 0x3Bu:
*(_DWORD *)v28 = 6517620;
goto LABEL_5;
case 0x40u:
*(_DWORD *)v28 = 6911090;
if ( (a5 & 2) != 0 )
goto LABEL_105;
goto LABEL_5;
case 0x41u:
case 0x43u:
case 0x45u:
case 0x47u:
case 0x49u:
case 0x4Du:
case 0x4Fu:
case 0x51u:
case 0x52u:
case 0x53u:
case 0x55u:
case 0x57u:
case 0x59u:
case 0x5Du:
case 0x5Fu:
*(_DWORD *)v28 = 7499621;
goto LABEL_3;
case 0x42u:
*(_DWORD *)v28 = 7169143;
LABEL_13:
v12 = a1[1];
v13 = "$%02X";
goto LABEL_14;
case 0x44u:
*(_DWORD *)v28 = 7370349;
goto LABEL_79;
case 0x46u:
case 0x4Au:
case 0x4Eu:
case 0x56u:
case 0x5Eu:
*(_DWORD *)v28 = 7500652;
goto LABEL_3;
case 0x48u:
*(_DWORD *)v28 = 6383728;
goto LABEL_5;
case 0x4Bu:
*(_DWORD *)v28 = 7039088;
goto LABEL_5;
case 0x4Cu:
case 0x5Cu:
case 0x6Cu:
case 0x7Cu:
case 0xDCu:
*(_DWORD *)v28 = 7368042;
goto LABEL_3;
case 0x50u:
*(_DWORD *)v28 = 6518370;
goto LABEL_37;
case 0x54u:
*(_DWORD *)v28 = 7239277;
LABEL_79:
v8 = 3;
sprintf(v31, "$%02X,$%02X", a1[1], a1[2]);
v24 = 6;
goto LABEL_15;
case 0x58u:
*(_DWORD *)v28 = 6909027;
goto LABEL_5;
case 0x5Au:
*(_DWORD *)v28 = 7956592;
goto LABEL_5;
case 0x5Bu:
*(_DWORD *)v28 = 6579060;
goto LABEL_5;
case 0x60u:
*(_DWORD *)v28 = 7566450;
if ( (a5 & 2) != 0 )
goto LABEL_105;
goto LABEL_5;
case 0x61u:
case 0x63u:
case 0x65u:
case 0x67u:
case 0x69u:
case 0x6Du:
case 0x6Fu:
case 0x71u:
case 0x72u:
case 0x73u:
case 0x75u:
case 0x77u:
case 0x79u:
case 0x7Du:
case 0x7Fu:
*(_DWORD *)v28 = 6513761;
goto LABEL_3;
case 0x62u:
*(_DWORD *)v28 = 7497072;
goto LABEL_73;
case 0x64u:
case 0x74u:
case 0x9Cu:
case 0x9Eu:
*(_DWORD *)v28 = 8025203;
goto LABEL_3;
case 0x66u:
case 0x6Au:
case 0x6Eu:
case 0x76u:
case 0x7Eu:
*(_DWORD *)v28 = 7499634;
goto LABEL_3;
case 0x68u:
*(_DWORD *)v28 = 6384752;
goto LABEL_5;
case 0x6Bu:
*(_DWORD *)v28 = 7107698;
if ( (a5 & 2) != 0 )
LABEL_105:
*(_WORD *)&v28[3] = 10;
goto LABEL_5;
case 0x70u:
*(_DWORD *)v28 = 7566946;
goto LABEL_37;
case 0x78u:
*(_DWORD *)v28 = 6907251;
goto LABEL_5;
case 0x7Au:
*(_DWORD *)v28 = 7957616;
goto LABEL_5;
case 0x7Bu:
*(_DWORD *)v28 = 6513780;
goto LABEL_5;
case 0x80u:
*(_DWORD *)v28 = 6386274;
goto LABEL_37;
case 0x81u:
case 0x83u:
case 0x85u:
case 0x87u:
case 0x8Du:
case 0x8Fu:
case 0x91u:
case 0x92u:
case 0x93u:
case 0x95u:
case 0x97u:
case 0x99u:
case 0x9Du:
case 0x9Fu:
*(_DWORD *)v28 = 6386803;
goto LABEL_3;
case 0x82u:
*(_DWORD *)v28 = 7107170;
LABEL_73:
v8 = 3;
v23 = a1[1] + (a1[2] << 8);
if ( v23 > 0x7FFF )
LOWORD(v23) = a1[1] + (a1[2] << 8);
sprintf(v31, "$%04lX", (unsigned __int16)(a2 + v23 + 3), v7);
v24 = 6;
goto LABEL_15;
case 0x84u:
case 0x8Cu:
case 0x94u:
*(_DWORD *)v28 = 7959667;
goto LABEL_3;
case 0x86u:
case 0x8Eu:
case 0x96u:
*(_DWORD *)v28 = 7894131;
goto LABEL_3;
case 0x88u:
*(_DWORD *)v28 = 7955812;
goto LABEL_5;
case 0x8Au:
*(_DWORD *)v28 = 6387828;
goto LABEL_5;
case 0x8Bu:
*(_DWORD *)v28 = 6449264;
goto LABEL_5;
case 0x90u:
*(_DWORD *)v28 = 6513506;
goto LABEL_37;
case 0x98u:
*(_DWORD *)v28 = 6388084;
goto LABEL_5;
case 0x9Au:
*(_DWORD *)v28 = 7567476;
goto LABEL_5;
case 0x9Bu:
*(_DWORD *)v28 = 7960692;
goto LABEL_5;
case 0xA0u:
case 0xA4u:
case 0xACu:
case 0xB4u:
case 0xBCu:
*(_DWORD *)v28 = 7955564;
goto LABEL_3;
case 0xA1u:
case 0xA3u:
case 0xA5u:
case 0xA7u:
case 0xA9u:
case 0xADu:
case 0xAFu:
case 0xB1u:
case 0xB2u:
case 0xB3u:
case 0xB5u:
case 0xB7u:
case 0xB9u:
case 0xBDu:
case 0xBFu:
*(_DWORD *)v28 = 6382700;
goto LABEL_3;
case 0xA2u:
case 0xA6u:
case 0xAEu:
case 0xB6u:
case 0xBEu:
*(_DWORD *)v28 = 7890028;
goto LABEL_3;
case 0xA8u:
*(_DWORD *)v28 = 7954804;
goto LABEL_5;
case 0xAAu:
*(_DWORD *)v28 = 7889268;
goto LABEL_5;
case 0xABu:
*(_DWORD *)v28 = 6450288;
goto LABEL_5;
case 0xB0u:
*(_DWORD *)v28 = 7562082;
goto LABEL_37;
case 0xB8u:
*(_DWORD *)v28 = 7760995;
goto LABEL_5;
case 0xBAu:
*(_DWORD *)v28 = 7893876;
goto LABEL_5;
case 0xBBu:
*(_DWORD *)v28 = 7895412;
goto LABEL_5;
case 0xC0u:
case 0xC4u:
case 0xCCu:
*(_DWORD *)v28 = 7958627;
goto LABEL_3;
case 0xC1u:
case 0xC3u:
case 0xC5u:
case 0xC7u:
case 0xC9u:
case 0xCDu:
case 0xCFu:
case 0xD1u:
case 0xD2u:
case 0xD3u:
case 0xD5u:
case 0xD7u:
case 0xD9u:
case 0xDDu:
case 0xDFu:
*(_DWORD *)v28 = 7368035;
goto LABEL_3;
case 0xC2u:
*(_DWORD *)v28 = 7366002;
LABEL_127:
*a3 &= ~a1[1];
v12 = a1[1];
goto LABEL_45;
case 0xC8u:
*(_DWORD *)v28 = 7958121;
goto LABEL_5;
case 0xCAu:
*(_DWORD *)v28 = 7890276;
goto LABEL_5;
case 0xCBu:
*(_DWORD *)v28 = 6906231;
goto LABEL_5;
case 0xD0u:
*(_DWORD *)v28 = 6647394;
goto LABEL_37;
case 0xD4u:
*(_DWORD *)v28 = 6907248;
LABEL_35:
v12 = a1[1];
v13 = "($%02X)";
goto LABEL_14;
case 0xD8u:
*(_DWORD *)v28 = 6581347;
goto LABEL_5;
case 0xDAu:
*(_DWORD *)v28 = 7891056;
goto LABEL_5;
case 0xDBu:
*(_DWORD *)v28 = 7369843;
goto LABEL_5;
case 0xE0u:
case 0xE4u:
case 0xECu:
*(_DWORD *)v28 = 7893091;
goto LABEL_3;
case 0xE1u:
case 0xE3u:
case 0xE5u:
case 0xE7u:
case 0xE9u:
case 0xEDu:
case 0xEFu:
case 0xF1u:
case 0xF2u:
case 0xF3u:
case 0xF5u:
case 0xF7u:
case 0xF9u:
case 0xFDu:
case 0xFFu:
*(_DWORD *)v28 = 6513267;
LABEL_3:
switch ( v6 )
{
case 0LL:
case 2LL:
case 4LL:
case 5LL:
case 6LL:
case 20LL:
case 36LL:
case 37LL:
case 38LL:
case 66LL:
case 69LL:
case 70LL:
case 100LL:
case 101LL:
case 102LL:
case 132LL:
case 133LL:
case 134LL:
case 164LL:
case 165LL:
case 166LL:
case 196LL:
case 197LL:
case 198LL:
case 228LL:
case 229LL:
case 230LL:
goto LABEL_13;
case 1LL:
case 33LL:
case 65LL:
case 97LL:
case 129LL:
case 161LL:
case 193LL:
case 225LL:
v12 = a1[1];
v13 = "($%02X,X)";
goto LABEL_14;
case 3LL:
case 35LL:
case 67LL:
case 99LL:
case 131LL:
case 163LL:
case 195LL:
case 227LL:
v12 = a1[1];
v13 = "$%02X,S";
goto LABEL_14;
case 7LL:
case 39LL:
case 71LL:
case 103LL:
case 135LL:
case 167LL:
case 199LL:
case 231LL:
v12 = a1[1];
v13 = "[$%02X]";
goto LABEL_14;
case 8LL:
case 11LL:
case 24LL:
case 27LL:
case 40LL:
case 43LL:
case 56LL:
case 59LL:
case 64LL:
case 72LL:
case 75LL:
case 88LL:
case 90LL:
case 91LL:
case 96LL:
case 104LL:
case 107LL:
case 120LL:
case 122LL:
case 123LL:
case 136LL:
case 138LL:
case 139LL:
case 152LL:
case 154LL:
case 155LL:
case 168LL:
case 170LL:
case 171LL:
case 184LL:
case 186LL:
case 187LL:
case 200LL:
case 202LL:
case 203LL:
case 216LL:
case 218LL:
case 219LL:
case 232LL:
case 234LL:
case 235LL:
case 248LL:
case 250LL:
case 251LL:
goto LABEL_5;
case 9LL:
case 41LL:
case 73LL:
case 105LL:
case 137LL:
case 169LL:
case 201LL:
case 233LL:
v22 = a1[1];
if ( (*a3 & 0x20) != 0 )
goto LABEL_44;
goto LABEL_64;
case 10LL:
case 26LL:
case 42LL:
case 58LL:
case 74LL:
case 106LL:
strcpy(v31, "A");
goto LABEL_6;
case 12LL:
case 13LL:
case 14LL:
case 28LL:
case 32LL:
case 44LL:
case 45LL:
case 46LL:
case 76LL:
case 77LL:
case 78LL:
case 109LL:
case 110LL:
case 140LL:
case 141LL:
case 142LL:
case 156LL:
case 172LL:
case 173LL:
case 174LL:
case 204LL:
case 205LL:
case 206LL:
case 236LL:
case 237LL:
case 238LL:
case 244LL:
goto LABEL_21;
case 15LL:
case 34LL:
case 47LL:
case 79LL:
case 92LL:
case 111LL:
case 143LL:
case 175LL:
case 207LL:
case 239LL:
v19 = "$%06X";
v20 = a1[1] + (a1[2] << 8) + (a1[3] << 16);
goto LABEL_33;
case 16LL:
case 48LL:
case 80LL:
case 112LL:
case 128LL:
case 144LL:
case 176LL:
case 208LL:
case 240LL:
goto LABEL_37;
case 17LL:
case 49LL:
case 81LL:
case 113LL:
case 145LL:
case 177LL:
case 209LL:
case 241LL:
v12 = a1[1];
v13 = "($%02X),Y";
goto LABEL_14;
case 18LL:
case 50LL:
case 82LL:
case 114LL:
case 146LL:
case 178LL:
case 210LL:
case 212LL:
case 242LL:
goto LABEL_35;
case 19LL:
case 51LL:
case 83LL:
case 115LL:
case 147LL:
case 179LL:
case 211LL:
case 243LL:
v12 = a1[1];
v13 = "($%02X,S),Y";
goto LABEL_14;
case 21LL:
case 22LL:
case 52LL:
case 53LL:
case 54LL:
case 85LL:
case 86LL:
case 116LL:
case 117LL:
case 118LL:
case 148LL:
case 149LL:
case 180LL:
case 181LL:
case 213LL:
case 214LL:
case 245LL:
case 246LL:
v12 = a1[1];
v13 = "$%02X,X";
goto LABEL_14;
case 23LL:
case 55LL:
case 87LL:
case 119LL:
case 151LL:
case 183LL:
case 215LL:
case 247LL:
v12 = a1[1];
v13 = "[$%02X],Y";
goto LABEL_14;
case 25LL:
case 57LL:
case 89LL:
case 121LL:
case 153LL:
case 185LL:
case 190LL:
case 217LL:
case 249LL:
v17 = "$%04X,Y";
v18 = a1[1] + (a1[2] << 8);
goto LABEL_22;
case 29LL:
case 30LL:
case 60LL:
case 61LL:
case 62LL:
case 93LL:
case 94LL:
case 125LL:
case 126LL:
case 157LL:
case 158LL:
case 188LL:
case 189LL:
case 221LL:
case 222LL:
case 253LL:
case 254LL:
v17 = "$%04X,X";
v18 = a1[1] + (a1[2] << 8);
goto LABEL_22;
case 31LL:
case 63LL:
case 95LL:
case 127LL:
case 159LL:
case 191LL:
case 223LL:
case 255LL:
v19 = "$%06X,X";
v20 = a1[1] + (a1[2] << 8) + (a1[3] << 16);
LABEL_33:
v8 = 4;
sprintf(v31, v19, v20, v6);
v24 = 8;
goto LABEL_15;
case 68LL:
case 84LL:
goto LABEL_79;
case 98LL:
case 130LL:
goto LABEL_73;
case 108LL:
v17 = "($%04X)";
v18 = a1[1] + (a1[2] << 8);
goto LABEL_22;
case 124LL:
case 252LL:
v17 = "($%04X,X)";
v18 = a1[1] + (a1[2] << 8);
goto LABEL_22;
case 150LL:
case 182LL:
v12 = a1[1];
v13 = "$%02X,Y";
goto LABEL_14;
case 160LL:
case 162LL:
case 192LL:
case 224LL:
v22 = a1[1];
if ( (*a3 & 0x10) != 0 )
{
LABEL_44:
v12 = v22;
goto LABEL_45;
}
LABEL_64:
v17 = "#$%04X";
v18 = (a1[2] << 8) + v22;
break;
case 194LL:
goto LABEL_127;
case 220LL:
v17 = "[$%04X]";
v18 = a1[1] + (a1[2] << 8);
goto LABEL_22;
case 226LL:
goto LABEL_94;
}
goto LABEL_22;
case 0xE2u:
*(_DWORD *)v28 = 7366003;
LABEL_94:
*a3 |= a1[1];
v12 = a1[1];
LABEL_45:
v13 = "#$%02X";
LABEL_14:
v8 = 2;
sprintf(v31, v13, v12, v6);
v24 = 4;
goto LABEL_15;
case 0xE8u:
*(_DWORD *)v28 = 7892585;
goto LABEL_5;
case 0xEAu:
*(_DWORD *)v28 = 7368558;
goto LABEL_5;
case 0xEBu:
*(_DWORD *)v28 = 6382200;
goto LABEL_5;
case 0xF0u:
*(_DWORD *)v28 = 7431522;
LABEL_37:
v21 = a1[1];
v8 = 2;
if ( (v21 & 0x80u) != 0 )
v21 = a1[1] | 0xFF00;
sprintf(v31, "$%04lX", (unsigned __int16)(a2 + v21 + 2));
v24 = 4;
goto LABEL_15;
case 0xF4u:
*(_DWORD *)v28 = 6382960;
LABEL_21:
v17 = "$%04X";
v18 = a1[1] + (a1[2] << 8);
LABEL_22:
v8 = 3;
sprintf(v31, v17, v18, v6);
v24 = 6;
LABEL_15:
v14 = s;
do
{
v15 = *v5;
v16 = v14;
v14 += 2;
++v5;
sprintf(v16, "%02X", v15);
}
while ( &s[2 * v8] != v14 );
if ( v24 != 8 )
goto LABEL_7;
v30 = 0;
if ( (a5 & 1) != 0 )
goto LABEL_19;
goto LABEL_10;
case 0xF8u:
*(_DWORD *)v28 = 6579571;
goto LABEL_5;
case 0xFAu:
*(_DWORD *)v28 = 7892080;
goto LABEL_5;
case 0xFBu:
*(_DWORD *)v28 = 6644600;
LABEL_5:
v31[0] = 0;
LABEL_6:
v8 = 1;
sprintf(s, "%02X", (unsigned __int8)v6);
v24 = 2;
LABEL_7:
v9 = 0;
do
{
v10 = v9++;
s[v24 + v10] = 32;
}
while ( v9 < 8 - v24 );
v30 = 0;
if ( (a5 & 1) != 0 )
LABEL_19:
sprintf(a4, "%s %s", v28, v31);
else
LABEL_10:
sprintf(a4, "%02lX/%04lX:\t%s\t%s %s", BYTE2(a2), (unsigned __int16)a2, s, v28, v31);
return v8;
}
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1, int a2, _BYTE *a3, char *a4, char a5)
{
unsigned __int8 *v5; // rbp
__int64 v6; // rax
__int64 v7; // rcx
unsigned int v8; // er14
unsigned int v9; // eax
__int64 v10; // rsi
__int64 v12; // rdx
const char *v13; // rsi
char *v14; // r12
__int64 v15; // rdx
char *v16; // rdi
const char *v17; // rsi
__int64 v18; // rdx
const char *v19; // rsi
__int64 v20; // rdx
__int16 v21; // ax
unsigned int v22; // er8
int v23; // eax
int v24; // [rsp+8h] [rbp-80h]
char v28[5]; // [rsp+22h] [rbp-66h] BYREF
char s[8]; // [rsp+27h] [rbp-61h] BYREF
char v30; // [rsp+2Fh] [rbp-59h]
char v31[88]; // [rsp+30h] [rbp-58h] BYREF

v5 = a1;
v6 = *a1;
v7 = v6;
switch ( *a1 )
{
case 0u:
*(_DWORD *)v28 = 7041634;
goto LABEL_13;
case 1u:
case 3u:
case 5u:
case 7u:
case 9u:
case 0xDu:
case 0xFu:
case 0x11u:
case 0x12u:
case 0x13u:
case 0x15u:
case 0x17u:
case 0x19u:
case 0x1Du:
case 0x1Fu:
*(_DWORD *)v28 = 6386287;
goto LABEL_3;
case 2u:
*(_DWORD *)v28 = 7368547;
goto LABEL_13;
case 4u:
case 0xCu:
*(_DWORD *)v28 = 6452084;
goto LABEL_3;
case 6u:
case 0xAu:
case 0xEu:
case 0x16u:
case 0x1Eu:
*(_DWORD *)v28 = 7107425;
goto LABEL_3;
case 8u:
*(_DWORD *)v28 = 7366768;
goto LABEL_5;
case 0xBu:
*(_DWORD *)v28 = 6580336;
goto LABEL_5;
case 0x10u:
*(_DWORD *)v28 = 7106658;
goto LABEL_37;
case 0x14u:
case 0x1Cu:
*(_DWORD *)v28 = 6451828;
goto LABEL_3;
case 0x18u:
*(_DWORD *)v28 = 6515811;
goto LABEL_5;
case 0x1Au:
case 0xE6u:
case 0xEEu:
case 0xF6u:
case 0xFEu:
*(_DWORD *)v28 = 6516329;
goto LABEL_3;
case 0x1Bu:
*(_DWORD *)v28 = 7562100;
goto LABEL_5;
case 0x20u:
case 0x22u:
case 0xFCu:
*(_DWORD *)v28 = 7500650;
goto LABEL_3;
case 0x21u:
case 0x23u:
case 0x25u:
case 0x27u:
case 0x29u:
case 0x2Du:
case 0x2Fu:
case 0x31u:
case 0x32u:
case 0x33u:
case 0x35u:
case 0x37u:
case 0x39u:
case 0x3Du:
case 0x3Fu:
*(_DWORD *)v28 = 6581857;
goto LABEL_3;
case 0x24u:
case 0x2Cu:
case 0x34u:
case 0x3Cu:
case 0x89u:
*(_DWORD *)v28 = 7629154;
goto LABEL_3;
case 0x26u:
case 0x2Au:
case 0x2Eu:
case 0x36u:
case 0x3Eu:
*(_DWORD *)v28 = 7106418;
goto LABEL_3;
case 0x28u:
*(_DWORD *)v28 = 7367792;
goto LABEL_5;
case 0x2Bu:
*(_DWORD *)v28 = 6581360;
goto LABEL_5;
case 0x30u:
*(_DWORD *)v28 = 6909282;
goto LABEL_37;
case 0x38u:
*(_DWORD *)v28 = 6514035;
goto LABEL_5;
case 0x3Au:
case 0xC6u:
case 0xCEu:
case 0xD6u:
case 0xDEu:
*(_DWORD *)v28 = 6514020;
goto LABEL_3;
case 0x3Bu:
*(_DWORD *)v28 = 6517620;
goto LABEL_5;
case 0x40u:
*(_DWORD *)v28 = 6911090;
if ( (a5 & 2) != 0 )
goto LABEL_105;
goto LABEL_5;
case 0x41u:
case 0x43u:
case 0x45u:
case 0x47u:
case 0x49u:
case 0x4Du:
case 0x4Fu:
case 0x51u:
case 0x52u:
case 0x53u:
case 0x55u:
case 0x57u:
case 0x59u:
case 0x5Du:
case 0x5Fu:
*(_DWORD *)v28 = 7499621;
goto LABEL_3;
case 0x42u:
*(_DWORD *)v28 = 7169143;
LABEL_13:
v12 = a1[1];
v13 = "$%02X";
goto LABEL_14;
case 0x44u:
*(_DWORD *)v28 = 7370349;
goto LABEL_79;
case 0x46u:
case 0x4Au:
case 0x4Eu:
case 0x56u:
case 0x5Eu:
*(_DWORD *)v28 = 7500652;
goto LABEL_3;
case 0x48u:
*(_DWORD *)v28 = 6383728;
goto LABEL_5;
case 0x4Bu:
*(_DWORD *)v28 = 7039088;
goto LABEL_5;
case 0x4Cu:
case 0x5Cu:
case 0x6Cu:
case 0x7Cu:
case 0xDCu:
*(_DWORD *)v28 = 7368042;
goto LABEL_3;
case 0x50u:
*(_DWORD *)v28 = 6518370;
goto LABEL_37;
case 0x54u:
*(_DWORD *)v28 = 7239277;
LABEL_79:
v8 = 3;
sprintf(v31, "$%02X,$%02X", a1[1], a1[2]);
v24 = 6;
goto LABEL_15;
case 0x58u:
*(_DWORD *)v28 = 6909027;
goto LABEL_5;
case 0x5Au:
*(_DWORD *)v28 = 7956592;
goto LABEL_5;
case 0x5Bu:
*(_DWORD *)v28 = 6579060;
goto LABEL_5;
case 0x60u:
*(_DWORD *)v28 = 7566450;
if ( (a5 & 2) != 0 )
goto LABEL_105;
goto LABEL_5;
case 0x61u:
case 0x63u:
case 0x65u:
case 0x67u:
case 0x69u:
case 0x6Du:
case 0x6Fu:
case 0x71u:
case 0x72u:
case 0x73u:
case 0x75u:
case 0x77u:
case 0x79u:
case 0x7Du:
case 0x7Fu:
*(_DWORD *)v28 = 6513761;
goto LABEL_3;
case 0x62u:
*(_DWORD *)v28 = 7497072;
goto LABEL_73;
case 0x64u:
case 0x74u:
case 0x9Cu:
case 0x9Eu:
*(_DWORD *)v28 = 8025203;
goto LABEL_3;
case 0x66u:
case 0x6Au:
case 0x6Eu:
case 0x76u:
case 0x7Eu:
*(_DWORD *)v28 = 7499634;
goto LABEL_3;
case 0x68u:
*(_DWORD *)v28 = 6384752;
goto LABEL_5;
case 0x6Bu:
*(_DWORD *)v28 = 7107698;
if ( (a5 & 2) != 0 )
LABEL_105:
*(_WORD *)&v28[3] = 10;
goto LABEL_5;
case 0x70u:
*(_DWORD *)v28 = 7566946;
goto LABEL_37;
case 0x78u:
*(_DWORD *)v28 = 6907251;
goto LABEL_5;
case 0x7Au:
*(_DWORD *)v28 = 7957616;
goto LABEL_5;
case 0x7Bu:
*(_DWORD *)v28 = 6513780;
goto LABEL_5;
case 0x80u:
*(_DWORD *)v28 = 6386274;
goto LABEL_37;
case 0x81u:
case 0x83u:
case 0x85u:
case 0x87u:
case 0x8Du:
case 0x8Fu:
case 0x91u:
case 0x92u:
case 0x93u:
case 0x95u:
case 0x97u:
case 0x99u:
case 0x9Du:
case 0x9Fu:
*(_DWORD *)v28 = 6386803;
goto LABEL_3;
case 0x82u:
*(_DWORD *)v28 = 7107170;
LABEL_73:
v8 = 3;
v23 = a1[1] + (a1[2] << 8);
if ( v23 > 0x7FFF )
LOWORD(v23) = a1[1] + (a1[2] << 8);
sprintf(v31, "$%04lX", (unsigned __int16)(a2 + v23 + 3), v7);
v24 = 6;
goto LABEL_15;
case 0x84u:
case 0x8Cu:
case 0x94u:
*(_DWORD *)v28 = 7959667;
goto LABEL_3;
case 0x86u:
case 0x8Eu:
case 0x96u:
*(_DWORD *)v28 = 7894131;
goto LABEL_3;
case 0x88u:
*(_DWORD *)v28 = 7955812;
goto LABEL_5;
case 0x8Au:
*(_DWORD *)v28 = 6387828;
goto LABEL_5;
case 0x8Bu:
*(_DWORD *)v28 = 6449264;
goto LABEL_5;
case 0x90u:
*(_DWORD *)v28 = 6513506;
goto LABEL_37;
case 0x98u:
*(_DWORD *)v28 = 6388084;
goto LABEL_5;
case 0x9Au:
*(_DWORD *)v28 = 7567476;
goto LABEL_5;
case 0x9Bu:
*(_DWORD *)v28 = 7960692;
goto LABEL_5;
case 0xA0u:
case 0xA4u:
case 0xACu:
case 0xB4u:
case 0xBCu:
*(_DWORD *)v28 = 7955564;
goto LABEL_3;
case 0xA1u:
case 0xA3u:
case 0xA5u:
case 0xA7u:
case 0xA9u:
case 0xADu:
case 0xAFu:
case 0xB1u:
case 0xB2u:
case 0xB3u:
case 0xB5u:
case 0xB7u:
case 0xB9u:
case 0xBDu:
case 0xBFu:
*(_DWORD *)v28 = 6382700;
goto LABEL_3;
case 0xA2u:
case 0xA6u:
case 0xAEu:
case 0xB6u:
case 0xBEu:
*(_DWORD *)v28 = 7890028;
goto LABEL_3;
case 0xA8u:
*(_DWORD *)v28 = 7954804;
goto LABEL_5;
case 0xAAu:
*(_DWORD *)v28 = 7889268;
goto LABEL_5;
case 0xABu:
*(_DWORD *)v28 = 6450288;
goto LABEL_5;
case 0xB0u:
*(_DWORD *)v28 = 7562082;
goto LABEL_37;
case 0xB8u:
*(_DWORD *)v28 = 7760995;
goto LABEL_5;
case 0xBAu:
*(_DWORD *)v28 = 7893876;
goto LABEL_5;
case 0xBBu:
*(_DWORD *)v28 = 7895412;
goto LABEL_5;
case 0xC0u:
case 0xC4u:
case 0xCCu:
*(_DWORD *)v28 = 7958627;
goto LABEL_3;
case 0xC1u:
case 0xC3u:
case 0xC5u:
case 0xC7u:
case 0xC9u:
case 0xCDu:
case 0xCFu:
case 0xD1u:
case 0xD2u:
case 0xD3u:
case 0xD5u:
case 0xD7u:
case 0xD9u:
case 0xDDu:
case 0xDFu:
*(_DWORD *)v28 = 7368035;
goto LABEL_3;
case 0xC2u:
*(_DWORD *)v28 = 7366002;
LABEL_127:
*a3 &= ~a1[1];
v12 = a1[1];
goto LABEL_45;
case 0xC8u:
*(_DWORD *)v28 = 7958121;
goto LABEL_5;
case 0xCAu:
*(_DWORD *)v28 = 7890276;
goto LABEL_5;
case 0xCBu:
*(_DWORD *)v28 = 6906231;
goto LABEL_5;
case 0xD0u:
*(_DWORD *)v28 = 6647394;
goto LABEL_37;
case 0xD4u:
*(_DWORD *)v28 = 6907248;
LABEL_35:
v12 = a1[1];
v13 = "($%02X)";
goto LABEL_14;
case 0xD8u:
*(_DWORD *)v28 = 6581347;
goto LABEL_5;
case 0xDAu:
*(_DWORD *)v28 = 7891056;
goto LABEL_5;
case 0xDBu:
*(_DWORD *)v28 = 7369843;
goto LABEL_5;
case 0xE0u:
case 0xE4u:
case 0xECu:
*(_DWORD *)v28 = 7893091;
goto LABEL_3;
case 0xE1u:
case 0xE3u:
case 0xE5u:
case 0xE7u:
case 0xE9u:
case 0xEDu:
case 0xEFu:
case 0xF1u:
case 0xF2u:
case 0xF3u:
case 0xF5u:
case 0xF7u:
case 0xF9u:
case 0xFDu:
case 0xFFu:
*(_DWORD *)v28 = 6513267;
LABEL_3:
switch ( v6 )
{
case 0LL:
case 2LL:
case 4LL:
case 5LL:
case 6LL:
case 20LL:
case 36LL:
case 37LL:
case 38LL:
case 66LL:
case 69LL:
case 70LL:
case 100LL:
case 101LL:
case 102LL:
case 132LL:
case 133LL:
case 134LL:
case 164LL:
case 165LL:
case 166LL:
case 196LL:
case 197LL:
case 198LL:
case 228LL:
case 229LL:
case 230LL:
goto LABEL_13;
case 1LL:
case 33LL:
case 65LL:
case 97LL:
case 129LL:
case 161LL:
case 193LL:
case 225LL:
v12 = a1[1];
v13 = "($%02X,X)";
goto LABEL_14;
case 3LL:
case 35LL:
case 67LL:
case 99LL:
case 131LL:
case 163LL:
case 195LL:
case 227LL:
v12 = a1[1];
v13 = "$%02X,S";
goto LABEL_14;
case 7LL:
case 39LL:
case 71LL:
case 103LL:
case 135LL:
case 167LL:
case 199LL:
case 231LL:
v12 = a1[1];
v13 = "[$%02X]";
goto LABEL_14;
case 8LL:
case 11LL:
case 24LL:
case 27LL:
case 40LL:
case 43LL:
case 56LL:
case 59LL:
case 64LL:
case 72LL:
case 75LL:
case 88LL:
case 90LL:
case 91LL:
case 96LL:
case 104LL:
case 107LL:
case 120LL:
case 122LL:
case 123LL:
case 136LL:
case 138LL:
case 139LL:
case 152LL:
case 154LL:
case 155LL:
case 168LL:
case 170LL:
case 171LL:
case 184LL:
case 186LL:
case 187LL:
case 200LL:
case 202LL:
case 203LL:
case 216LL:
case 218LL:
case 219LL:
case 232LL:
case 234LL:
case 235LL:
case 248LL:
case 250LL:
case 251LL:
goto LABEL_5;
case 9LL:
case 41LL:
case 73LL:
case 105LL:
case 137LL:
case 169LL:
case 201LL:
case 233LL:
v22 = a1[1];
if ( (*a3 & 0x20) != 0 )
goto LABEL_44;
goto LABEL_64;
case 10LL:
case 26LL:
case 42LL:
case 58LL:
case 74LL:
case 106LL:
strcpy(v31, "A");
goto LABEL_6;
case 12LL:
case 13LL:
case 14LL:
case 28LL:
case 32LL:
case 44LL:
case 45LL:
case 46LL:
case 76LL:
case 77LL:
case 78LL:
case 109LL:
case 110LL:
case 140LL:
case 141LL:
case 142LL:
case 156LL:
case 172LL:
case 173LL:
case 174LL:
case 204LL:
case 205LL:
case 206LL:
case 236LL:
case 237LL:
case 238LL:
case 244LL:
goto LABEL_21;
case 15LL:
case 34LL:
case 47LL:
case 79LL:
case 92LL:
case 111LL:
case 143LL:
case 175LL:
case 207LL:
case 239LL:
v19 = "$%06X";
v20 = a1[1] + (a1[2] << 8) + (a1[3] << 16);
goto LABEL_33;
case 16LL:
case 48LL:
case 80LL:
case 112LL:
case 128LL:
case 144LL:
case 176LL:
case 208LL:
case 240LL:
goto LABEL_37;
case 17LL:
case 49LL:
case 81LL:
case 113LL:
case 145LL:
case 177LL:
case 209LL:
case 241LL:
v12 = a1[1];
v13 = "($%02X),Y";
goto LABEL_14;
case 18LL:
case 50LL:
case 82LL:
case 114LL:
case 146LL:
case 178LL:
case 210LL:
case 212LL:
case 242LL:
goto LABEL_35;
case 19LL:
case 51LL:
case 83LL:
case 115LL:
case 147LL:
case 179LL:
case 211LL:
case 243LL:
v12 = a1[1];
v13 = "($%02X,S),Y";
goto LABEL_14;
case 21LL:
case 22LL:
case 52LL:
case 53LL:
case 54LL:
case 85LL:
case 86LL:
case 116LL:
case 117LL:
case 118LL:
case 148LL:
case 149LL:
case 180LL:
case 181LL:
case 213LL:
case 214LL:
case 245LL:
case 246LL:
v12 = a1[1];
v13 = "$%02X,X";
goto LABEL_14;
case 23LL:
case 55LL:
case 87LL:
case 119LL:
case 151LL:
case 183LL:
case 215LL:
case 247LL:
v12 = a1[1];
v13 = "[$%02X],Y";
goto LABEL_14;
case 25LL:
case 57LL:
case 89LL:
case 121LL:
case 153LL:
case 185LL:
case 190LL:
case 217LL:
case 249LL:
v17 = "$%04X,Y";
v18 = a1[1] + (a1[2] << 8);
goto LABEL_22;
case 29LL:
case 30LL:
case 60LL:
case 61LL:
case 62LL:
case 93LL:
case 94LL:
case 125LL:
case 126LL:
case 157LL:
case 158LL:
case 188LL:
case 189LL:
case 221LL:
case 222LL:
case 253LL:
case 254LL:
v17 = "$%04X,X";
v18 = a1[1] + (a1[2] << 8);
goto LABEL_22;
case 31LL:
case 63LL:
case 95LL:
case 127LL:
case 159LL:
case 191LL:
case 223LL:
case 255LL:
v19 = "$%06X,X";
v20 = a1[1] + (a1[2] << 8) + (a1[3] << 16);
LABEL_33:
v8 = 4;
sprintf(v31, v19, v20, v6);
v24 = 8;
goto LABEL_15;
case 68LL:
case 84LL:
goto LABEL_79;
case 98LL:
case 130LL:
goto LABEL_73;
case 108LL:
v17 = "($%04X)";
v18 = a1[1] + (a1[2] << 8);
goto LABEL_22;
case 124LL:
case 252LL:
v17 = "($%04X,X)";
v18 = a1[1] + (a1[2] << 8);
goto LABEL_22;
case 150LL:
case 182LL:
v12 = a1[1];
v13 = "$%02X,Y";
goto LABEL_14;
case 160LL:
case 162LL:
case 192LL:
case 224LL:
v22 = a1[1];
if ( (*a3 & 0x10) != 0 )
{
LABEL_44:
v12 = v22;
goto LABEL_45;
}
LABEL_64:
v17 = "#$%04X";
v18 = (a1[2] << 8) + v22;
break;
case 194LL:
goto LABEL_127;
case 220LL:
v17 = "[$%04X]";
v18 = a1[1] + (a1[2] << 8);
goto LABEL_22;
case 226LL:
goto LABEL_94;
}
goto LABEL_22;
case 0xE2u:
*(_DWORD *)v28 = 7366003;
LABEL_94:
*a3 |= a1[1];
v12 = a1[1];
LABEL_45:
v13 = "#$%02X";
LABEL_14:
v8 = 2;
sprintf(v31, v13, v12, v6);
v24 = 4;
goto LABEL_15;
case 0xE8u:
*(_DWORD *)v28 = 7892585;
goto LABEL_5;
case 0xEAu:
*(_DWORD *)v28 = 7368558;
goto LABEL_5;
case 0xEBu:
*(_DWORD *)v28 = 6382200;
goto LABEL_5;
case 0xF0u:
*(_DWORD *)v28 = 7431522;
LABEL_37:
v21 = a1[1];
v8 = 2;
if ( (v21 & 0x80u) != 0 )
v21 = a1[1] | 0xFF00;
sprintf(v31, "$%04lX", (unsigned __int16)(a2 + v21 + 2));
v24 = 4;
goto LABEL_15;
case 0xF4u:
*(_DWORD *)v28 = 6382960;
LABEL_21:
v17 = "$%04X";
v18 = a1[1] + (a1[2] << 8);
LABEL_22:
v8 = 3;
sprintf(v31, v17, v18, v6);
v24 = 6;
LABEL_15:
v14 = s;
do
{
v15 = *v5;
v16 = v14;
v14 += 2;
++v5;
sprintf(v16, "%02X", v15);
}
while ( &s[2 * v8] != v14 );
if ( v24 != 8 )
goto LABEL_7;
v30 = 0;
if ( (a5 & 1) != 0 )
goto LABEL_19;
goto LABEL_10;
case 0xF8u:
*(_DWORD *)v28 = 6579571;
goto LABEL_5;
case 0xFAu:
*(_DWORD *)v28 = 7892080;
goto LABEL_5;
case 0xFBu:
*(_DWORD *)v28 = 6644600;
LABEL_5:
v31[0] = 0;
LABEL_6:
v8 = 1;
sprintf(s, "%02X", (unsigned __int8)v6);
v24 = 2;
LABEL_7:
v9 = 0;
do
{
v10 = v9++;
s[v24 + v10] = 32;
}
while ( v9 < 8 - v24 );
v30 = 0;
if ( (a5 & 1) != 0 )
LABEL_19:
sprintf(a4, "%s %s", v28, v31);
else
LABEL_10:
sprintf(a4, "%02lX/%04lX:\t%s\t%s %s", BYTE2(a2), (unsigned __int16)a2, s, v28, v31);
return v8;
}
}

original_code:
int disasm(unsigned char *mem, unsigned long pos, unsigned char *flag, char *inst, unsigned char tsrc)
{
 char ibuf[5],pbuf[20],hbuf[9];
 int offset,sval,i;
 switch (mem[0])
 {
 case 0x69:
 case 0x6D:
 case 0x6F:
 case 0x65:
 case 0x72:
 case 0x67:
 case 0x7D:
 case 0x7F:
 case 0x79:
 case 0x75:
 case 0x61:
 case 0x71:
 case 0x77:
 case 0x63:
 case 0x73:
  strcpy(ibuf,"adc");
  break;
 case 0x29:
 case 0x2D:
 case 0x2F:
 case 0x25:
 case 0x32:
 case 0x27:
 case 0x3D:
 case 0x3F:
 case 0x39:
 case 0x35:
 case 0x21:
 case 0x31:
 case 0x37:
 case 0x23:
 case 0x33:
  strcpy(ibuf,"and");
  break;
 case 0x0A:
 case 0x0E:
 case 0x06:
 case 0x1E:
 case 0x16:
  strcpy(ibuf,"asl");
  break;
 case 0x90:
  strcpy(ibuf,"bcc");
  break;
 case 0xB0:
  strcpy(ibuf,"bcs");
  break;
 case 0xF0:
  strcpy(ibuf,"beq");
  break;
 case 0xD0:
  strcpy(ibuf,"bne");
  break;
 case 0x30:
  strcpy(ibuf,"bmi");
  break;
 case 0x10:
  strcpy(ibuf,"bpl");
  break;
 case 0x50:
  strcpy(ibuf,"bvc");
  break;
 case 0x70:
  strcpy(ibuf,"bvs");
  break;
 case 0x80:
  strcpy(ibuf,"bra");
  break;
 case 0x82:
  strcpy(ibuf,"brl");
  break;
 case 0x89:
 case 0x2C:
 case 0x24:
 case 0x3C:
 case 0x34:
  strcpy(ibuf,"bit");
  break;
 case 0x00:
  strcpy(ibuf,"brk");
  break;
 case 0x18:
  strcpy(ibuf,"clc");
  break;
 case 0xD8:
  strcpy(ibuf,"cld");
  break;
 case 0x58:
  strcpy(ibuf,"cli");
  break;
 case 0xB8:
  strcpy(ibuf,"clv");
  break;
 case 0x38:
  strcpy(ibuf,"sec");
  break;
 case 0xF8:
  strcpy(ibuf,"sed");
  break;
 case 0x78:
  strcpy(ibuf,"sei");
  break;
 case 0xC9:
 case 0xCD:
 case 0xCF:
 case 0xC5:
 case 0xD2:
 case 0xC7:
 case 0xDD:
 case 0xDF:
 case 0xD9:
 case 0xD5:
 case 0xC1:
 case 0xD1:
 case 0xD7:
 case 0xC3:
 case 0xD3:
  strcpy(ibuf,"cmp");
  break;
 case 0x02:
  strcpy(ibuf,"cop");
  break;
 case 0xE0:
 case 0xEC:
 case 0xE4:
  strcpy(ibuf,"cpx");
  break;
 case 0xC0:
 case 0xCC:
 case 0xC4:
  strcpy(ibuf,"cpy");
  break;
 case 0x3A:
 case 0xCE:
 case 0xC6:
 case 0xDE:
 case 0xD6:
  strcpy(ibuf,"dec");
  break;
 case 0xCA:
  strcpy(ibuf,"dex");
  break;
 case 0x88:
  strcpy(ibuf,"dey");
  break;
 case 0x49:
 case 0x4D:
 case 0x4F:
 case 0x45:
 case 0x52:
 case 0x47:
 case 0x5D:
 case 0x5F:
 case 0x59:
 case 0x55:
 case 0x41:
 case 0x51:
 case 0x57:
 case 0x43:
 case 0x53:
  strcpy(ibuf,"eor");
  break;
 case 0x1A:
 case 0xEE:
 case 0xE6:
 case 0xFE:
 case 0xF6:
  strcpy(ibuf,"inc");
  break;
 case 0xE8:
  strcpy(ibuf,"inx");
  break;
 case 0xC8:
  strcpy(ibuf,"iny");
  break;
 case 0x4C:
 case 0x6C:
 case 0x7C:
 case 0x5C:
 case 0xDC:
  strcpy(ibuf,"jmp");
  break;
 case 0x22:
 case 0x20:
 case 0xFC:
  strcpy(ibuf,"jsr");
  break;
 case 0xA9:
 case 0xAD:
 case 0xAF:
 case 0xA5:
 case 0xB2:
 case 0xA7:
 case 0xBD:
 case 0xBF:
 case 0xB9:
 case 0xB5:
 case 0xA1:
 case 0xB1:
 case 0xB7:
 case 0xA3:
 case 0xB3:
  strcpy(ibuf,"lda");
  break;
 case 0xA2:
 case 0xAE:
 case 0xA6:
 case 0xBE:
 case 0xB6:
  strcpy(ibuf,"ldx");
  break;
 case 0xA0:
 case 0xAC:
 case 0xA4:
 case 0xBC:
 case 0xB4:
  strcpy(ibuf,"ldy");
  break;
 case 0x4A:
 case 0x4E:
 case 0x46:
 case 0x5E:
 case 0x56:
  strcpy(ibuf,"lsr");
  break;
 case 0x54:
  strcpy(ibuf,"mvn");
  break;
 case 0x44:
  strcpy(ibuf,"mvp");
  break;
 case 0xEA:
  strcpy(ibuf,"nop");
  break;
 case 0x09:
 case 0x0D:
 case 0x0F:
 case 0x05:
 case 0x12:
 case 0x07:
 case 0x1D:
 case 0x1F:
 case 0x19:
 case 0x15:
 case 0x01:
 case 0x11:
 case 0x17:
 case 0x03:
 case 0x13:
  strcpy(ibuf,"ora");
  break;
 case 0xF4:
  strcpy(ibuf,"pea");
  break;
 case 0xD4:
  strcpy(ibuf,"pei");
  break;
 case 0x62:
  strcpy(ibuf,"per");
  break;
 case 0x48:
  strcpy(ibuf,"pha");
  break;
 case 0x08:
  strcpy(ibuf,"php");
  break;
 case 0xDA:
  strcpy(ibuf,"phx");
  break;
 case 0x5A:
  strcpy(ibuf,"phy");
  break;
 case 0x68:
  strcpy(ibuf,"pla");
  break;
 case 0x28:
  strcpy(ibuf,"plp");
  break;
 case 0xFA:
  strcpy(ibuf,"plx");
  break;
 case 0x7A:
  strcpy(ibuf,"ply");
  break;
 case 0x8B:
  strcpy(ibuf,"phb");
  break;
 case 0x0B:
  strcpy(ibuf,"phd");
  break;
 case 0x4B:
  strcpy(ibuf,"phk");
  break;
 case 0xAB:
  strcpy(ibuf,"plb");
  break;
 case 0x2B:
  strcpy(ibuf,"pld");
  break;
 case 0xC2:
  strcpy(ibuf,"rep");
  break;
 case 0x2A:
 case 0x2E:
 case 0x26:
 case 0x3E:
 case 0x36:
  strcpy(ibuf,"rol");
  break;
 case 0x6A:
 case 0x6E:
 case 0x66:
 case 0x7E:
 case 0x76:
  strcpy(ibuf,"ror");
  break;
 case 0x40:
  strcpy(ibuf,"rti");
  if(tsrc&0x2)
   strcat(ibuf,"\n");
  break;
 case 0x6B:
  strcpy(ibuf,"rtl");
  if(tsrc&0x2)
   strcat(ibuf,"\n");
  break;
 case 0x60:
  strcpy(ibuf,"rts");
  if(tsrc&0x2)
   strcat(ibuf,"\n");
  break;
 case 0xE9:
 case 0xED:
 case 0xEF:
 case 0xE5:
 case 0xF2:
 case 0xE7:
 case 0xFD:
 case 0xFF:
 case 0xF9:
 case 0xF5:
 case 0xE1:
 case 0xF1:
 case 0xF7:
 case 0xE3:
 case 0xF3:
  strcpy(ibuf,"sbc");
  break;
 case 0xE2:
  strcpy(ibuf,"sep");
  break;
 case 0x8D:
 case 0x8F:
 case 0x85:
 case 0x92:
 case 0x87:
 case 0x9D:
 case 0x9F:
 case 0x99:
 case 0x95:
 case 0x81:
 case 0x91:
 case 0x97:
 case 0x83:
 case 0x93:
  strcpy(ibuf,"sta");
  break;
 case 0xDB:
  strcpy(ibuf,"stp");
  break;
 case 0x8E:
 case 0x86:
 case 0x96:
  strcpy(ibuf,"stx");
  break;
 case 0x8C:
 case 0x84:
 case 0x94:
  strcpy(ibuf,"sty");
  break;
 case 0x9C:
 case 0x64:
 case 0x9E:
 case 0x74:
  strcpy(ibuf,"stz");
  break;
 case 0xAA:
  strcpy(ibuf,"tax");
  break;
 case 0xA8:
  strcpy(ibuf,"tay");
  break;
 case 0x8A:
  strcpy(ibuf,"txa");
  break;
 case 0x98:
  strcpy(ibuf,"tya");
  break;
 case 0xBA:
  strcpy(ibuf,"tsx");
  break;
 case 0x9A:
  strcpy(ibuf,"txs");
  break;
 case 0x9B:
  strcpy(ibuf,"txy");
  break;
 case 0xBB:
  strcpy(ibuf,"tyx");
  break;
 case 0x5B:
  strcpy(ibuf,"tcd");
  break;
 case 0x7B:
  strcpy(ibuf,"tdc");
  break;
 case 0x1B:
  strcpy(ibuf,"tcs");
  break;
 case 0x3B:
  strcpy(ibuf,"tsc");
  break;
 case 0x1C:
 case 0x14:
  strcpy(ibuf,"trb");
  break;
 case 0x0C:
 case 0x04:
  strcpy(ibuf,"tsb");
  break;
 case 0xCB:
  strcpy(ibuf,"wai");
  break;
 case 0x42:
  strcpy(ibuf,"wdm");
  break;
 case 0xEB:
  strcpy(ibuf,"xba");
  break;
 case 0xFB:
  strcpy(ibuf,"xce");
  break;
 default:
  printf("Unhandled instruction: %02X\n",mem[0]);
  exit(1);
 };
 switch(mem[0]){
 case 0x0C:
 case 0x0D:
 case 0x0E:
 case 0x1C:
 case 0x20:
 case 0x2C:
 case 0x2D:
 case 0x2E:
 case 0x4C:
 case 0x4D:
 case 0x4E:
 case 0x6D:
 case 0x6E:
 case 0x8C:
 case 0x8D:
 case 0x8E:
 case 0x9C:
 case 0xAC:
 case 0xAD:
 case 0xAE:
 case 0xCC:
 case 0xCD:
 case 0xCE:
 case 0xEC:
 case 0xED:
 case 0xEE:
  sprintf(pbuf,"$%04X",mem[1]+mem[2]*256);
  offset=3;
  break;
 case 0x7C:
 case 0xFC:
  sprintf(pbuf,"($%04X,X)",mem[1]+mem[2]*256);
  offset=3;
  break;
 case 0x1D:
 case 0x1E:
 case 0x3C:
 case 0x3D:
 case 0x3E:
 case 0x5D:
 case 0x5E:
 case 0x7D:
 case 0x7E:
 case 0x9D:
 case 0x9E:
 case 0xBC:
 case 0xBD:
 case 0xDD:
 case 0xDE:
 case 0xFD:
 case 0xFE:
  sprintf(pbuf,"$%04X,X",mem[1]+mem[2]*256);
  offset=3;
  break;
 case 0x19:
 case 0x39:
 case 0x59:
 case 0x79:
 case 0x99:
 case 0xB9:
 case 0xBE:
 case 0xD9:
 case 0xF9:
  sprintf(pbuf,"$%04X,Y",mem[1]+mem[2]*256);
  offset=3;
  break;
 case 0x6C:
  sprintf(pbuf,"($%04X)",mem[1]+mem[2]*256);
  offset=3;
  break;
 case 0xDC:
  sprintf(pbuf,"[$%04X]",mem[1]+mem[2]*256);
  offset=3;
  break;
 case 0x0F:
 case 0x22:
 case 0x2F:
 case 0x4F:
 case 0x5C:
 case 0x6F:
 case 0x8F:
 case 0xAF:
 case 0xCF:
 case 0xEF:
  sprintf(pbuf,"$%06X",mem[1]+mem[2]*256+mem[3]*65536);
  offset=4;
  break;
 case 0x1F:
 case 0x3F:
 case 0x5F:
 case 0x7F:
 case 0x9F:
 case 0xBF:
 case 0xDF:
 case 0xFF:
  sprintf(pbuf,"$%06X,X",mem[1]+mem[2]*256+mem[3]*65536);
  offset=4;
  break;
 case 0x0A:
 case 0x1A:
 case 0x2A:
 case 0x3A:
 case 0x4A:
 case 0x6A:
  sprintf(pbuf,"A");
  offset=1;
  break;
 case 0x44:
 case 0x54:
  sprintf(pbuf,"$%02X,$%02X",mem[1],mem[2]);
  offset=3;
  break;
 case 0x04:
 case 0x05:
 case 0x06:
 case 0x14:
 case 0x24:
 case 0x25:
 case 0x26:
 case 0x45:
 case 0x46:
 case 0x64:
 case 0x65:
 case 0x66:
 case 0x84:
 case 0x85:
 case 0x86:
 case 0xA4:
 case 0xA5:
 case 0xA6:
 case 0xC4:
 case 0xC5:
 case 0xC6:
 case 0xE4:
 case 0xE5:
 case 0xE6:
  sprintf(pbuf,"$%02X",mem[1]);
  offset=2;
  break;
 case 0x15:
 case 0x16:
 case 0x34:
 case 0x35:
 case 0x36:
 case 0x55:
 case 0x56:
 case 0x74:
 case 0x75:
 case 0x76:
 case 0x94:
 case 0x95:
 case 0xB4:
 case 0xB5:
 case 0xD5:
 case 0xD6:
 case 0xF5:
 case 0xF6:
  sprintf(pbuf,"$%02X,X",mem[1]);
  offset=2;
  break;
 case 0x96:
 case 0xB6:
  sprintf(pbuf,"$%02X,Y",mem[1]);
  offset=2;
  break;
 case 0x12:
 case 0x32:
 case 0x52:
 case 0x72:
 case 0x92:
 case 0xB2:
 case 0xD2:
 case 0xF2:
  sprintf(pbuf,"($%02X)",mem[1]);
  offset=2;
  break;
 case 0x07:
 case 0x27:
 case 0x47:
 case 0x67:
 case 0x87:
 case 0xA7:
 case 0xC7:
 case 0xE7:
  sprintf(pbuf,"[$%02X]",mem[1]);
  offset=2;
  break;
 case 0x01:
 case 0x21:
 case 0x41:
 case 0x61:
 case 0x81:
 case 0xA1:
 case 0xC1:
 case 0xE1:
  sprintf(pbuf,"($%02X,X)",mem[1]);
  offset=2;
  break;
 case 0x11:
 case 0x31:
 case 0x51:
 case 0x71:
 case 0x91:
 case 0xB1:
 case 0xD1:
 case 0xF1:
  sprintf(pbuf,"($%02X),Y",mem[1]);
  offset=2;
  break;
 case 0x17:
 case 0x37:
 case 0x57:
 case 0x77:
 case 0x97:
 case 0xB7:
 case 0xD7:
 case 0xF7:
  sprintf(pbuf,"[$%02X],Y",mem[1]);
  offset=2;
  break;
 case 0x28:
 case 0x2B:
 case 0x68:
 case 0x7A:
 case 0xAB:
 case 0xFA:
 case 0x08:
 case 0x0B:
 case 0x48:
 case 0x4B:
 case 0x5A:
 case 0x8B:
 case 0xDA:
 case 0x6B:
 case 0x60:
 case 0x40:
 case 0x18:
 case 0x1B:
 case 0x38:
 case 0x3B:
 case 0x58:
 case 0x5B:
 case 0x78:
 case 0x7B:
 case 0x88:
 case 0x8A:
 case 0x98:
 case 0x9A:
 case 0x9B:
 case 0xA8:
 case 0xAA:
 case 0xB8:
 case 0xBA:
 case 0xBB:
 case 0xC8:
 case 0xCA:
 case 0xCB:
 case 0xD8:
 case 0xDB:
 case 0xE8:
 case 0xEA:
 case 0xEB:
 case 0xF8:
 case 0xFB:
  pbuf[0] = 0;
  offset = 1;
  break;
 case 0x10:
 case 0x30:
 case 0x50:
 case 0x70:
 case 0x80:
 case 0x90:
 case 0xB0:
 case 0xD0:
 case 0xF0:
  sval = (mem[1]>127) ? (mem[1]-256) : mem[1];
  sprintf(pbuf, "$%04lX", (pos+sval+2) & 0xFFFF);
  offset = 2;
  break;
 case 0x62:
 case 0x82:
  sval = mem[1] + mem[2]*256;
  sval = (sval>32767) ? (sval-65536) : sval;
  sprintf(pbuf, "$%04lX", (pos+sval+3) & 0xFFFF);
  offset = 3;
  break;
 case 0x13:
 case 0x33:
 case 0x53:
 case 0x73:
 case 0x93:
 case 0xB3:
 case 0xD3:
 case 0xF3:
  sprintf(pbuf, "($%02X,S),Y", mem[1]);
  offset = 2;
  break;
 case 0xF4:
  sprintf(pbuf, "$%04X", mem[1] + mem[2]*256);
  offset = 3;
  break;
 case 0xD4:
  sprintf(pbuf,"($%02X)",mem[1]);
  offset = 2;
  break;
  offset = 3;
  break;
 case 0x03:
 case 0x23:
 case 0x43:
 case 0x63:
 case 0x83:
 case 0xA3:
 case 0xC3:
 case 0xE3:
  sprintf(pbuf,"$%02X,S",mem[1]);
  offset = 2;
  break;
 case 0x42:
 case 0x00:
 case 0x02:
  sprintf(pbuf,"$%02X",mem[1]);
  offset = 2;
  break;
 case 0xC2:
  *flag=*flag&~mem[1];
  sprintf(pbuf,"#$%02X",mem[1]);
  offset = 2;
  break;
 case 0xE2:
  *flag = *flag|mem[1];
  sprintf(pbuf, "#$%02X", mem[1]);
  offset = 2;
  break;
 case 0x09:
 case 0x29:
 case 0x49:
 case 0x69:
 case 0x89:
 case 0xA9:
 case 0xC9:
 case 0xE9:
  if (*flag & 0x20)
  {
   sprintf(pbuf, "#$%02X", mem[1]);
   offset = 2;
  }
  else
  {
   sprintf(pbuf,"#$%04X",mem[1]+mem[2]*256);
   offset = 3;
  }
  break;
 case 0xA0:
 case 0xA2:
 case 0xC0:
 case 0xE0:
  if ((*flag) & 0x10)
  {
   sprintf(pbuf,"#$%02X",mem[1]);
   offset = 2;
  }
  else
  {
   sprintf(pbuf,"#$%04X",mem[1]+mem[2]*256);
   offset = 3;
  }
  break;
 default:
  printf("Unhandled Addressing Mode: %02X\n",mem[0]);
  exit(1);
 };
 for (i=0; i<offset; i++)
 {
  sprintf(hbuf+i*2,"%02X",mem[i]);
 }
 for (i=offset*2; i<8; i++)
 {
  hbuf[i]=0x20;
 }
 hbuf[8]=0;
 if(!(tsrc & 1))
 {
  sprintf(inst, "%02lX/%04lX:\t%s\t%s %s", (pos >> 16) & 0xFF, pos&0xFFFF, hbuf, ibuf, pbuf);
 }
 else
 {
  sprintf(inst, "%s %s", ibuf, pbuf);
 }
 return offset;
}

canonical_original_code:
int disasm(unsigned char *mem, unsigned long pos, unsigned char *flag, char *inst, unsigned char tsrc)
{
 char ibuf[5]; char pbuf[20]; char hbuf[9];
 int offset; int sval; int i;
 switch (mem[0])
 {
 case 0x69:
 case 0x6D:
 case 0x6F:
 case 0x65:
 case 0x72:
 case 0x67:
 case 0x7D:
 case 0x7F:
 case 0x79:
 case 0x75:
 case 0x61:
 case 0x71:
 case 0x77:
 case 0x63:
 case 0x73:
  strcpy(ibuf,"adc");
  break;
 case 0x29:
 case 0x2D:
 case 0x2F:
 case 0x25:
 case 0x32:
 case 0x27:
 case 0x3D:
 case 0x3F:
 case 0x39:
 case 0x35:
 case 0x21:
 case 0x31:
 case 0x37:
 case 0x23:
 case 0x33:
  strcpy(ibuf,"and");
  break;
 case 0x0A:
 case 0x0E:
 case 0x06:
 case 0x1E:
 case 0x16:
  strcpy(ibuf,"asl");
  break;
 case 0x90:
  strcpy(ibuf,"bcc");
  break;
 case 0xB0:
  strcpy(ibuf,"bcs");
  break;
 case 0xF0:
  strcpy(ibuf,"beq");
  break;
 case 0xD0:
  strcpy(ibuf,"bne");
  break;
 case 0x30:
  strcpy(ibuf,"bmi");
  break;
 case 0x10:
  strcpy(ibuf,"bpl");
  break;
 case 0x50:
  strcpy(ibuf,"bvc");
  break;
 case 0x70:
  strcpy(ibuf,"bvs");
  break;
 case 0x80:
  strcpy(ibuf,"bra");
  break;
 case 0x82:
  strcpy(ibuf,"brl");
  break;
 case 0x89:
 case 0x2C:
 case 0x24:
 case 0x3C:
 case 0x34:
  strcpy(ibuf,"bit");
  break;
 case 0x00:
  strcpy(ibuf,"brk");
  break;
 case 0x18:
  strcpy(ibuf,"clc");
  break;
 case 0xD8:
  strcpy(ibuf,"cld");
  break;
 case 0x58:
  strcpy(ibuf,"cli");
  break;
 case 0xB8:
  strcpy(ibuf,"clv");
  break;
 case 0x38:
  strcpy(ibuf,"sec");
  break;
 case 0xF8:
  strcpy(ibuf,"sed");
  break;
 case 0x78:
  strcpy(ibuf,"sei");
  break;
 case 0xC9:
 case 0xCD:
 case 0xCF:
 case 0xC5:
 case 0xD2:
 case 0xC7:
 case 0xDD:
 case 0xDF:
 case 0xD9:
 case 0xD5:
 case 0xC1:
 case 0xD1:
 case 0xD7:
 case 0xC3:
 case 0xD3:
  strcpy(ibuf,"cmp");
  break;
 case 0x02:
  strcpy(ibuf,"cop");
  break;
 case 0xE0:
 case 0xEC:
 case 0xE4:
  strcpy(ibuf,"cpx");
  break;
 case 0xC0:
 case 0xCC:
 case 0xC4:
  strcpy(ibuf,"cpy");
  break;
 case 0x3A:
 case 0xCE:
 case 0xC6:
 case 0xDE:
 case 0xD6:
  strcpy(ibuf,"dec");
  break;
 case 0xCA:
  strcpy(ibuf,"dex");
  break;
 case 0x88:
  strcpy(ibuf,"dey");
  break;
 case 0x49:
 case 0x4D:
 case 0x4F:
 case 0x45:
 case 0x52:
 case 0x47:
 case 0x5D:
 case 0x5F:
 case 0x59:
 case 0x55:
 case 0x41:
 case 0x51:
 case 0x57:
 case 0x43:
 case 0x53:
  strcpy(ibuf,"eor");
  break;
 case 0x1A:
 case 0xEE:
 case 0xE6:
 case 0xFE:
 case 0xF6:
  strcpy(ibuf,"inc");
  break;
 case 0xE8:
  strcpy(ibuf,"inx");
  break;
 case 0xC8:
  strcpy(ibuf,"iny");
  break;
 case 0x4C:
 case 0x6C:
 case 0x7C:
 case 0x5C:
 case 0xDC:
  strcpy(ibuf,"jmp");
  break;
 case 0x22:
 case 0x20:
 case 0xFC:
  strcpy(ibuf,"jsr");
  break;
 case 0xA9:
 case 0xAD:
 case 0xAF:
 case 0xA5:
 case 0xB2:
 case 0xA7:
 case 0xBD:
 case 0xBF:
 case 0xB9:
 case 0xB5:
 case 0xA1:
 case 0xB1:
 case 0xB7:
 case 0xA3:
 case 0xB3:
  strcpy(ibuf,"lda");
  break;
 case 0xA2:
 case 0xAE:
 case 0xA6:
 case 0xBE:
 case 0xB6:
  strcpy(ibuf,"ldx");
  break;
 case 0xA0:
 case 0xAC:
 case 0xA4:
 case 0xBC:
 case 0xB4:
  strcpy(ibuf,"ldy");
  break;
 case 0x4A:
 case 0x4E:
 case 0x46:
 case 0x5E:
 case 0x56:
  strcpy(ibuf,"lsr");
  break;
 case 0x54:
  strcpy(ibuf,"mvn");
  break;
 case 0x44:
  strcpy(ibuf,"mvp");
  break;
 case 0xEA:
  strcpy(ibuf,"nop");
  break;
 case 0x09:
 case 0x0D:
 case 0x0F:
 case 0x05:
 case 0x12:
 case 0x07:
 case 0x1D:
 case 0x1F:
 case 0x19:
 case 0x15:
 case 0x01:
 case 0x11:
 case 0x17:
 case 0x03:
 case 0x13:
  strcpy(ibuf,"ora");
  break;
 case 0xF4:
  strcpy(ibuf,"pea");
  break;
 case 0xD4:
  strcpy(ibuf,"pei");
  break;
 case 0x62:
  strcpy(ibuf,"per");
  break;
 case 0x48:
  strcpy(ibuf,"pha");
  break;
 case 0x08:
  strcpy(ibuf,"php");
  break;
 case 0xDA:
  strcpy(ibuf,"phx");
  break;
 case 0x5A:
  strcpy(ibuf,"phy");
  break;
 case 0x68:
  strcpy(ibuf,"pla");
  break;
 case 0x28:
  strcpy(ibuf,"plp");
  break;
 case 0xFA:
  strcpy(ibuf,"plx");
  break;
 case 0x7A:
  strcpy(ibuf,"ply");
  break;
 case 0x8B:
  strcpy(ibuf,"phb");
  break;
 case 0x0B:
  strcpy(ibuf,"phd");
  break;
 case 0x4B:
  strcpy(ibuf,"phk");
  break;
 case 0xAB:
  strcpy(ibuf,"plb");
  break;
 case 0x2B:
  strcpy(ibuf,"pld");
  break;
 case 0xC2:
  strcpy(ibuf,"rep");
  break;
 case 0x2A:
 case 0x2E:
 case 0x26:
 case 0x3E:
 case 0x36:
  strcpy(ibuf,"rol");
  break;
 case 0x6A:
 case 0x6E:
 case 0x66:
 case 0x7E:
 case 0x76:
  strcpy(ibuf,"ror");
  break;
 case 0x40:
  strcpy(ibuf,"rti");
  if(tsrc&0x2)
   strcat(ibuf,"\n");
  break;
 case 0x6B:
  strcpy(ibuf,"rtl");
  if(tsrc&0x2)
   strcat(ibuf,"\n");
  break;
 case 0x60:
  strcpy(ibuf,"rts");
  if(tsrc&0x2)
   strcat(ibuf,"\n");
  break;
 case 0xE9:
 case 0xED:
 case 0xEF:
 case 0xE5:
 case 0xF2:
 case 0xE7:
 case 0xFD:
 case 0xFF:
 case 0xF9:
 case 0xF5:
 case 0xE1:
 case 0xF1:
 case 0xF7:
 case 0xE3:
 case 0xF3:
  strcpy(ibuf,"sbc");
  break;
 case 0xE2:
  strcpy(ibuf,"sep");
  break;
 case 0x8D:
 case 0x8F:
 case 0x85:
 case 0x92:
 case 0x87:
 case 0x9D:
 case 0x9F:
 case 0x99:
 case 0x95:
 case 0x81:
 case 0x91:
 case 0x97:
 case 0x83:
 case 0x93:
  strcpy(ibuf,"sta");
  break;
 case 0xDB:
  strcpy(ibuf,"stp");
  break;
 case 0x8E:
 case 0x86:
 case 0x96:
  strcpy(ibuf,"stx");
  break;
 case 0x8C:
 case 0x84:
 case 0x94:
  strcpy(ibuf,"sty");
  break;
 case 0x9C:
 case 0x64:
 case 0x9E:
 case 0x74:
  strcpy(ibuf,"stz");
  break;
 case 0xAA:
  strcpy(ibuf,"tax");
  break;
 case 0xA8:
  strcpy(ibuf,"tay");
  break;
 case 0x8A:
  strcpy(ibuf,"txa");
  break;
 case 0x98:
  strcpy(ibuf,"tya");
  break;
 case 0xBA:
  strcpy(ibuf,"tsx");
  break;
 case 0x9A:
  strcpy(ibuf,"txs");
  break;
 case 0x9B:
  strcpy(ibuf,"txy");
  break;
 case 0xBB:
  strcpy(ibuf,"tyx");
  break;
 case 0x5B:
  strcpy(ibuf,"tcd");
  break;
 case 0x7B:
  strcpy(ibuf,"tdc");
  break;
 case 0x1B:
  strcpy(ibuf,"tcs");
  break;
 case 0x3B:
  strcpy(ibuf,"tsc");
  break;
 case 0x1C:
 case 0x14:
  strcpy(ibuf,"trb");
  break;
 case 0x0C:
 case 0x04:
  strcpy(ibuf,"tsb");
  break;
 case 0xCB:
  strcpy(ibuf,"wai");
  break;
 case 0x42:
  strcpy(ibuf,"wdm");
  break;
 case 0xEB:
  strcpy(ibuf,"xba");
  break;
 case 0xFB:
  strcpy(ibuf,"xce");
  break;
 default:
  printf("Unhandled instruction: %02X\n",mem[0]);
  exit(1);
 };
 switch(mem[0]){
 case 0x0C:
 case 0x0D:
 case 0x0E:
 case 0x1C:
 case 0x20:
 case 0x2C:
 case 0x2D:
 case 0x2E:
 case 0x4C:
 case 0x4D:
 case 0x4E:
 case 0x6D:
 case 0x6E:
 case 0x8C:
 case 0x8D:
 case 0x8E:
 case 0x9C:
 case 0xAC:
 case 0xAD:
 case 0xAE:
 case 0xCC:
 case 0xCD:
 case 0xCE:
 case 0xEC:
 case 0xED:
 case 0xEE:
  sprintf(pbuf,"$%04X",mem[1]+mem[2]*256);
  offset=3;
  break;
 case 0x7C:
 case 0xFC:
  sprintf(pbuf,"($%04X,X)",mem[1]+mem[2]*256);
  offset=3;
  break;
 case 0x1D:
 case 0x1E:
 case 0x3C:
 case 0x3D:
 case 0x3E:
 case 0x5D:
 case 0x5E:
 case 0x7D:
 case 0x7E:
 case 0x9D:
 case 0x9E:
 case 0xBC:
 case 0xBD:
 case 0xDD:
 case 0xDE:
 case 0xFD:
 case 0xFE:
  sprintf(pbuf,"$%04X,X",mem[1]+mem[2]*256);
  offset=3;
  break;
 case 0x19:
 case 0x39:
 case 0x59:
 case 0x79:
 case 0x99:
 case 0xB9:
 case 0xBE:
 case 0xD9:
 case 0xF9:
  sprintf(pbuf,"$%04X,Y",mem[1]+mem[2]*256);
  offset=3;
  break;
 case 0x6C:
  sprintf(pbuf,"($%04X)",mem[1]+mem[2]*256);
  offset=3;
  break;
 case 0xDC:
  sprintf(pbuf,"[$%04X]",mem[1]+mem[2]*256);
  offset=3;
  break;
 case 0x0F:
 case 0x22:
 case 0x2F:
 case 0x4F:
 case 0x5C:
 case 0x6F:
 case 0x8F:
 case 0xAF:
 case 0xCF:
 case 0xEF:
  sprintf(pbuf,"$%06X",mem[1]+mem[2]*256+mem[3]*65536);
  offset=4;
  break;
 case 0x1F:
 case 0x3F:
 case 0x5F:
 case 0x7F:
 case 0x9F:
 case 0xBF:
 case 0xDF:
 case 0xFF:
  sprintf(pbuf,"$%06X,X",mem[1]+mem[2]*256+mem[3]*65536);
  offset=4;
  break;
 case 0x0A:
 case 0x1A:
 case 0x2A:
 case 0x3A:
 case 0x4A:
 case 0x6A:
  sprintf(pbuf,"A");
  offset=1;
  break;
 case 0x44:
 case 0x54:
  sprintf(pbuf,"$%02X,$%02X",mem[1],mem[2]);
  offset=3;
  break;
 case 0x04:
 case 0x05:
 case 0x06:
 case 0x14:
 case 0x24:
 case 0x25:
 case 0x26:
 case 0x45:
 case 0x46:
 case 0x64:
 case 0x65:
 case 0x66:
 case 0x84:
 case 0x85:
 case 0x86:
 case 0xA4:
 case 0xA5:
 case 0xA6:
 case 0xC4:
 case 0xC5:
 case 0xC6:
 case 0xE4:
 case 0xE5:
 case 0xE6:
  sprintf(pbuf,"$%02X",mem[1]);
  offset=2;
  break;
 case 0x15:
 case 0x16:
 case 0x34:
 case 0x35:
 case 0x36:
 case 0x55:
 case 0x56:
 case 0x74:
 case 0x75:
 case 0x76:
 case 0x94:
 case 0x95:
 case 0xB4:
 case 0xB5:
 case 0xD5:
 case 0xD6:
 case 0xF5:
 case 0xF6:
  sprintf(pbuf,"$%02X,X",mem[1]);
  offset=2;
  break;
 case 0x96:
 case 0xB6:
  sprintf(pbuf,"$%02X,Y",mem[1]);
  offset=2;
  break;
 case 0x12:
 case 0x32:
 case 0x52:
 case 0x72:
 case 0x92:
 case 0xB2:
 case 0xD2:
 case 0xF2:
  sprintf(pbuf,"($%02X)",mem[1]);
  offset=2;
  break;
 case 0x07:
 case 0x27:
 case 0x47:
 case 0x67:
 case 0x87:
 case 0xA7:
 case 0xC7:
 case 0xE7:
  sprintf(pbuf,"[$%02X]",mem[1]);
  offset=2;
  break;
 case 0x01:
 case 0x21:
 case 0x41:
 case 0x61:
 case 0x81:
 case 0xA1:
 case 0xC1:
 case 0xE1:
  sprintf(pbuf,"($%02X,X)",mem[1]);
  offset=2;
  break;
 case 0x11:
 case 0x31:
 case 0x51:
 case 0x71:
 case 0x91:
 case 0xB1:
 case 0xD1:
 case 0xF1:
  sprintf(pbuf,"($%02X),Y",mem[1]);
  offset=2;
  break;
 case 0x17:
 case 0x37:
 case 0x57:
 case 0x77:
 case 0x97:
 case 0xB7:
 case 0xD7:
 case 0xF7:
  sprintf(pbuf,"[$%02X],Y",mem[1]);
  offset=2;
  break;
 case 0x28:
 case 0x2B:
 case 0x68:
 case 0x7A:
 case 0xAB:
 case 0xFA:
 case 0x08:
 case 0x0B:
 case 0x48:
 case 0x4B:
 case 0x5A:
 case 0x8B:
 case 0xDA:
 case 0x6B:
 case 0x60:
 case 0x40:
 case 0x18:
 case 0x1B:
 case 0x38:
 case 0x3B:
 case 0x58:
 case 0x5B:
 case 0x78:
 case 0x7B:
 case 0x88:
 case 0x8A:
 case 0x98:
 case 0x9A:
 case 0x9B:
 case 0xA8:
 case 0xAA:
 case 0xB8:
 case 0xBA:
 case 0xBB:
 case 0xC8:
 case 0xCA:
 case 0xCB:
 case 0xD8:
 case 0xDB:
 case 0xE8:
 case 0xEA:
 case 0xEB:
 case 0xF8:
 case 0xFB:
  pbuf[0] = 0;
  offset = 1;
  break;
 case 0x10:
 case 0x30:
 case 0x50:
 case 0x70:
 case 0x80:
 case 0x90:
 case 0xB0:
 case 0xD0:
 case 0xF0:
  sval = (mem[1]>127) ? (mem[1]-256) : mem[1];
  sprintf(pbuf, "$%04lX", (pos+sval+2) & 0xFFFF);
  offset = 2;
  break;
 case 0x62:
 case 0x82:
  sval = mem[1] + mem[2]*256;
  sval = (sval>32767) ? (sval-65536) : sval;
  sprintf(pbuf, "$%04lX", (pos+sval+3) & 0xFFFF);
  offset = 3;
  break;
 case 0x13:
 case 0x33:
 case 0x53:
 case 0x73:
 case 0x93:
 case 0xB3:
 case 0xD3:
 case 0xF3:
  sprintf(pbuf, "($%02X,S),Y", mem[1]);
  offset = 2;
  break;
 case 0xF4:
  sprintf(pbuf, "$%04X", mem[1] + mem[2]*256);
  offset = 3;
  break;
 case 0xD4:
  sprintf(pbuf,"($%02X)",mem[1]);
  offset = 2;
  break;
  offset = 3;
  break;
 case 0x03:
 case 0x23:
 case 0x43:
 case 0x63:
 case 0x83:
 case 0xA3:
 case 0xC3:
 case 0xE3:
  sprintf(pbuf,"$%02X,S",mem[1]);
  offset = 2;
  break;
 case 0x42:
 case 0x00:
 case 0x02:
  sprintf(pbuf,"$%02X",mem[1]);
  offset = 2;
  break;
 case 0xC2:
  *flag=*flag&~mem[1];
  sprintf(pbuf,"#$%02X",mem[1]);
  offset = 2;
  break;
 case 0xE2:
  *flag = *flag|mem[1];
  sprintf(pbuf, "#$%02X", mem[1]);
  offset = 2;
  break;
 case 0x09:
 case 0x29:
 case 0x49:
 case 0x69:
 case 0x89:
 case 0xA9:
 case 0xC9:
 case 0xE9:
  if (*flag & 0x20)
  {
   sprintf(pbuf, "#$%02X", mem[1]);
   offset = 2;
  }
  else
  {
   sprintf(pbuf,"#$%04X",mem[1]+mem[2]*256);
   offset = 3;
  }
  break;
 case 0xA0:
 case 0xA2:
 case 0xC0:
 case 0xE0:
  if ((*flag) & 0x10)
  {
   sprintf(pbuf,"#$%02X",mem[1]);
   offset = 2;
  }
  else
  {
   sprintf(pbuf,"#$%04X",mem[1]+mem[2]*256);
   offset = 3;
  }
  break;
 default:
  printf("Unhandled Addressing Mode: %02X\n",mem[0]);
  exit(1);
 };
 for (i=0; i<offset; i++)
 {
  sprintf(hbuf+i*2,"%02X",mem[i]);
 }
 for (i=offset*2; i<8; i++)
 {
  hbuf[i]=0x20;
 }
 hbuf[8]=0;
 if(!(tsrc & 1))
 {
  sprintf(inst, "%02lX/%04lX:\t%s\t%s %s", (pos >> 16) & 0xFF, pos&0xFFFF, hbuf, ibuf, pbuf);
 }
 else
 {
  sprintf(inst, "%s %s", ibuf, pbuf);
 }
 return offset;
}

variable_types:
mem
unsigned char *

variable_types:
pos
unsigned long

variable_types:
flag
unsigned char *

variable_types:
inst
char *

variable_types:
tsrc
unsigned char

variable_types:
ibuf
char [5]

variable_types:
pbuf
char [20]

variable_types:
hbuf
char [9]

variable_types: offset int

variable_types: sval int

variable_types: i int


usage

decompiled_code:
int usage()
{
return puts(
"\n"
"DisPel v1 by James Churchill/pelrun (C)2001-2011\n"
"65816/SNES Disassembler\n"
"Usage: dispel [-n] [-t] [-h] [-l] [-s] [-i] [-a] [-x] [-e] [-p]\n"
" [-b <bank>|-r <startaddr>-<endaddr>] [-g <origin>]\n"
" [-d <width>] [-o <outfile>] <infile>\n"
"\n"
"Options: (numbers are hex-only, no prefixes)\n"
" -n Skip $200 byte SMC header\n"
" -t Don't output addresses/hex dump.\n"
" -h/-l Force HiROM/LoROM memory mapping.\n"
" -s/-i Force enable/disable shadow ROM addresses (see readme.)\n"
" -a Start in 8-bit accumulator mode. Default is 16-bit.\n"
" -x Start in 8-bit X/Y mode. Default is 16-bit.\n"
" -e Turn off bank-boundary enforcement. (see readme.)\n"
" -p Split subroutines by placing blank lines after RTS,RTL,RTI\n"
" -b <bank> Disassemble bank <bank> only. Overrides -r.\n"
" -r <start>-<end> Disassemble block from <start> to <end>.\n"
" Omit -<end> to disassemble to end of file.\n"
" -g <origin> Set origin of disassembled code (see readme.)\n"
" -d <width> No disassembly - produce a hexdump with <width> bytes/line.\n"
" -o <outfile> Set file to redirect output to. Default is stdout.\n"
" <infile> File to disassemble.");
}

canonical_decompiled_code:
int func0()
{
return puts(
"\n"
"DisPel v1 by James Churchill/pelrun (C)2001-2011\n"
"65816/SNES Disassembler\n"
"Usage: dispel [-n] [-t] [-h] [-l] [-s] [-i] [-a] [-x] [-e] [-p]\n"
" [-b <bank>|-r <startaddr>-<endaddr>] [-g <origin>]\n"
" [-d <width>] [-o <outfile>] <infile>\n"
"\n"
"Options: (numbers are hex-only, no prefixes)\n"
" -n Skip $200 byte SMC header\n"
" -t Don't output addresses/hex dump.\n"
" -h/-l Force HiROM/LoROM memory mapping.\n"
" -s/-i Force enable/disable shadow ROM addresses (see readme.)\n"
" -a Start in 8-bit accumulator mode. Default is 16-bit.\n"
" -x Start in 8-bit X/Y mode. Default is 16-bit.\n"
" -e Turn off bank-boundary enforcement. (see readme.)\n"
" -p Split subroutines by placing blank lines after RTS,RTL,RTI\n"
" -b <bank> Disassemble bank <bank> only. Overrides -r.\n"
" -r <start>-<end> Disassemble block from <start> to <end>.\n"
" Omit -<end> to disassemble to end of file.\n"
" -g <origin> Set origin of disassembled code (see readme.)\n"
" -d <width> No disassembly - produce a hexdump with <width> bytes/line.\n"
" -o <outfile> Set file to redirect output to. Default is stdout.\n"
" <infile> File to disassemble.");
}

original_code:
void usage(void)
{
 printf("\nDisPel v1 by James Churchill/pelrun (C)2001-2011\n"
  "65816/SNES Disassembler\n"
  "Usage: dispel [-n] [-t] [-h] [-l] [-s] [-i] [-a] [-x] [-e] [-p]\n"
  "              [-b <bank>|-r <startaddr>-<endaddr>] [-g <origin>]\n"
  "              [-d <width>] [-o <outfile>] <infile>\n\n"
  "Options: (numbers are hex-only, no prefixes)\n"
  " -n                Skip $200 byte SMC header\n"
  " -t                Don't output addresses/hex dump.\n"
  " -h/-l             Force HiROM/LoROM memory mapping.\n"
  " -s/-i             Force enable/disable shadow ROM addresses (see readme.)\n"
  " -a                Start in 8-bit accumulator mode. Default is 16-bit.\n"
  " -x                Start in 8-bit X/Y mode. Default is 16-bit.\n"
  " -e                Turn off bank-boundary enforcement. (see readme.)\n"
  " -p                Split subroutines by placing blank lines after RTS,RTL,RTI\n"
  " -b <bank>         Disassemble bank <bank> only. Overrides -r.\n"
  " -r <start>-<end>  Disassemble block from <start> to <end>.\n"
  "                     Omit -<end> to disassemble to end of file.\n"
  " -g <origin>       Set origin of disassembled code (see readme.)\n"
  " -d <width>        No disassembly - produce a hexdump with <width> bytes/line.\n"
  " -o <outfile>      Set file to redirect output to. Default is stdout.\n"
  " <infile>          File to disassemble.\n");
}

canonical_original_code:
void usage()
{
 printf("\nDisPel v1 by James Churchill/pelrun (C)2001-2011\n"
  "65816/SNES Disassembler\n"
  "Usage: dispel [-n] [-t] [-h] [-l] [-s] [-i] [-a] [-x] [-e] [-p]\n"
  "              [-b <bank>|-r <startaddr>-<endaddr>] [-g <origin>]\n"
  "              [-d <width>] [-o <outfile>] <infile>\n\n"
  "Options: (numbers are hex-only, no prefixes)\n"
  " -n                Skip $200 byte SMC header\n"
  " -t                Don't output addresses/hex dump.\n"
  " -h/-l             Force HiROM/LoROM memory mapping.\n"
  " -s/-i             Force enable/disable shadow ROM addresses (see readme.)\n"
  " -a                Start in 8-bit accumulator mode. Default is 16-bit.\n"
  " -x                Start in 8-bit X/Y mode. Default is 16-bit.\n"
  " -e                Turn off bank-boundary enforcement. (see readme.)\n"
  " -p                Split subroutines by placing blank lines after RTS,RTL,RTI\n"
  " -b <bank>         Disassemble bank <bank> only. Overrides -r.\n"
  " -r <start>-<end>  Disassemble block from <start> to <end>.\n"
  "                     Omit -<end> to disassemble to end of file.\n"
  " -g <origin>       Set origin of disassembled code (see readme.)\n"
  " -d <width>        No disassembly - produce a hexdump with <width> bytes/line.\n"
  " -o <outfile>      Set file to redirect output to. Default is stdout.\n"
  " <infile>          File to disassemble.\n");
}

return_type: void


AllASCII

decompiled_code:
__int64 __fastcall AllASCII(_BYTE *a1, int a2)
{
__int64 v2; // rdx

if ( a2 <= 0 )
return 1LL;
v2 = (__int64)&a1[a2 - 1 + 1];
while ( (unsigned __int8)(*a1 - 32) <= 0x5Eu )
{
if ( ++a1 == (_BYTE *)v2 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1, int a2)
{
__int64 v2; // rdx

if ( a2 <= 0 )
return 1LL;
v2 = (__int64)&a1[a2 - 1 + 1];
while ( (unsigned __int8)(*a1 - 32) <= 0x5Eu )
{
if ( ++a1 == (_BYTE *)v2 )
return 1LL;
}
return 0LL;
}

original_code:
int AllASCII(unsigned char *b, int size)
{
 int i;
 for (i = 0; i < size; i++)
 {
  if (b[i] < 32 || b[i] > 126)
  {
   return 0;
  }
 }
 return 1;
}

variable_types:
b
unsigned char *

variable_types: size int

return_type: int


ScoreHiROM

decompiled_code:
unsigned __int64 __fastcall ScoreHiROM(__int64 a1)
{
__int64 v1; // r8
unsigned int v2; // eax
unsigned int v3; // er9

AllASCII((_BYTE *)(a1 + 65456), 6);
v2 = AllASCII((_BYTE *)(v1 + 65472), 20);
return (__PAIR64__(v3, v2) - 1) >> 32;
}

original_code:
int ScoreHiROM(unsigned char *data)
{
 int score = 0;
 if ((data[0xFFDC] + data[0xFFDD]*256 + data[0xFFDE] + data[0xFFDF]*256) == 0xFFFF)
 {
  score += 2;
 }
 if (data[0xFFDA] == 0x33)
 {
  score += 2;
 }
 if ((data[0xFFD5] & 0xf) < 4)
 {
  score += 2;
 }
 if (!(data[0xFFFD] & 0x80))
 {
  score -= 4;
 }
 if ((1 << (data[0xFFD7] - 7)) > 48)
 {
  score -= 1;
 }
 if (!AllASCII(&data[0xFFB0], 6))
 {
  score -= 1;
 }
 if (!AllASCII(&data[0xFFC0], 20))
 {
  score -= 1;
 }
 return (score);
}

variable_types:
data
unsigned char *

variable_types: score int


ScoreLoROM

decompiled_code:
unsigned __int64 __fastcall ScoreLoROM(__int64 a1)
{
__int64 v1; // r8
unsigned int v2; // eax
unsigned int v3; // er9

AllASCII((_BYTE *)(a1 + 32688), 6);
v2 = AllASCII((_BYTE *)(v1 + 32704), 20);
return (__PAIR64__(v3, v2) - 1) >> 32;
}

original_code:
int ScoreLoROM(unsigned char *data)
{
 int score = 0;
 if ((data[0x7FDC] + data[0x7FDD]*256 + data[0x7FDE] + data[0x7FDF]*256) == 0xFFFF)
 {
  score += 2;
 }
 if (data[0x7FDA] == 0x33)
 {
  score += 2;
 }
 if ((data[0x7FD5] & 0xf) < 4)
 {
  score += 2;
 }
 if (!(data[0x7FFD] & 0x80))
 {
  score -= 4;
 }
 if ((1 << (data[0x7FD7] - 7)) > 48)
 {
  score -= 1;
 }
 if (!AllASCII(&data[0x7FB0], 6))
 {
  score -= 1;
 }
 if (!AllASCII(&data[0x7FC0], 20))
 {
  score -= 1;
 }
 return (score);
}


hexdump

decompiled_code:
__int64 __fastcall hexdump(__int64 a1, int a2, unsigned __int64 a3, unsigned __int64 a4, char *a5, unsigned __int8 a6)
{
unsigned __int8 *v10; // rbx
char *v11; // rbp
unsigned __int8 *v12; // r13
unsigned __int8 *v13; // r14

sprintf(a5, "%02lX/%04lX:\t", BYTE2(a2), (unsigned __int16)a2);
if ( a6 && a3 < a4 )
{
v10 = (unsigned __int8 *)(a1 + a3);
v11 = a5 + 9;
v12 = (unsigned __int8 *)(a1 + a4);
v13 = &v10[a6 - 1];
do
{
sprintf(v11, "%02X", *v10);
if ( v10 == v13 )
break;
++v10;
v11 += 2;
}
while ( v10 != v12 );
}
return a6;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2, unsigned __int64 a3, unsigned __int64 a4, char *a5, unsigned __int8 a6)
{
unsigned __int8 *v10; // rbx
char *v11; // rbp
unsigned __int8 *v12; // r13
unsigned __int8 *v13; // r14

sprintf(a5, "%02lX/%04lX:\t", BYTE2(a2), (unsigned __int16)a2);
if ( a6 && a3 < a4 )
{
v10 = (unsigned __int8 *)(a1 + a3);
v11 = a5 + 9;
v12 = (unsigned __int8 *)(a1 + a4);
v13 = &v10[a6 - 1];
do
{
sprintf(v11, "%02X", *v10);
if ( v10 == v13 )
break;
++v10;
v11 += 2;
}
while ( v10 != v12 );
}
return a6;
}

original_code:
int hexdump(unsigned char *data,unsigned long pos,unsigned long rpos,
   unsigned long len,char *inst, unsigned char dwidth)
{
 int i;
 sprintf(inst, "%02lX/%04lX:\t", (pos >> 16) & 0xFF, pos & 0xFFFF);
 for(i=0; i<dwidth && i+rpos<len; i++)
 {
  sprintf(inst + i*2 + 9, "%02X", data[rpos+i]);
 }
 return dwidth;
}

canonical_original_code:
int hexdump(unsigned char *data, unsigned long pos, unsigned long rpos, unsigned long len, char *inst, unsigned char dwidth)
{
 int i;
 sprintf(inst, "%02lX/%04lX:\t", (pos >> 16) & 0xFF, pos & 0xFFFF);
 for(i=0; i<dwidth && i+rpos<len; i++)
 {
  sprintf(inst + i*2 + 9, "%02X", data[rpos+i]);
 }
 return dwidth;
}

variable_types:
rpos
unsigned long

variable_types:
len
unsigned long

variable_types:
dwidth
unsigned char


repo: pengjianzhang/simple-interpreter

decompiled_code:
int __fastcall interpreter_err(const char *a1)
{
return printf("line %d:%s\n", (unsigned int)interpreter_line_num, a1);
}

canonical_decompiled_code:
int __fastcall func7(const char *a1)
{
return printf("line %d:%s\n", (unsigned int)interpreter_line_num, a1);
}

original_code:
void interpreter_err(char * msg)
{
 printf("line %d:%s\n", interpreter_line_num,msg);
}

canonical_original_code:
void interpreter_err(char *msg)
{
 printf("line %d:%s\n", interpreter_line_num,msg);
}

variable_types:
msg
char *


decompiled_code:
__int64 __fastcall new_expression_node(int a1, int *a2, int *a3)
{
unsigned int v3; // er8
void *v4; // rbp

if ( a2
&& (a3 || operation_is_unitary(a1))
&& expression_vtype_eq_isra_0(*a2, *a3)
&& (unsigned int)operation_match(v3) )
{
v4 = malloc(0x18uLL);
if ( v4 )
{
interpreter_err("expression type not match");
free(v4);
return 0LL;
}
}
else
{
interpreter_err("expression type not match");
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, int *a2, int *a3)
{
unsigned int v3; // er8
void *v4; // rbp

if ( a2
&& (a3 || func4(a1))
&& func6(*a2, *a3)
&& (unsigned int)func5(v3) )
{
v4 = malloc(0x18uLL);
if ( v4 )
{
func7("expression type not match");
free(v4);
return 0LL;
}
}
else
{
func7("expression type not match");
}
return 0LL;
}

original_code:
struct expression_node * new_expression_node(enum operation_type opt, struct expression_node * en1, struct expression_node * en2)
{
 struct expression * e = ((void *)0);
 if(en1 == ((void *)0))
  goto err;
 else if((en2 == ((void *)0)) && (!_operation_is_unitary(opt)))
   goto err;
 else if(!expression_vtype_eq(en1,en2))
  goto err;
 if(!_operation_match(opt,en1->vtype)) goto err;
 e = (struct expression *)malloc(sizeof(struct expression));
 if(e == ((void *)0)) return ((void *)0);
 if(_operation_is_arithmetic(opt,2)){
 }
 else if( _operation_is_relation(opt,2)){
 }
 else if( _operation_is_logic(opt,2)){
 }
 else if( _operation_is_logic(opt,1)){
 }
 else
 {
  goto err;
 }
err:
 interpreter_err("expression type not match");
 if(e) free(e);
 return ((void *)0);
}

canonical_original_code:
struct expression_node *new_expression_node(enum operation_type opt, struct expression_node *en1, struct expression_node *en2)
{
 struct expression *e = ((void *)0);
 if(en1 == ((void *)0))
  goto err;
 else if((en2 == ((void *)0)) && (!_operation_is_unitary(opt)))
   goto err;
 else if(!expression_vtype_eq(en1,en2))
  goto err;
 if(!_operation_match(opt,en1->vtype)) goto err;
 e = (struct expression *)malloc(sizeof(struct expression));
 if(e == ((void *)0)) return ((void *)0);
 if(_operation_is_arithmetic(opt,2)){
 }
 else if( _operation_is_relation(opt,2)){
 }
 else if( _operation_is_logic(opt,2)){
 }
 else if( _operation_is_logic(opt,1)){
 }
 else
 {
  goto err;
 }
err:
 interpreter_err("expression type not match");
 if(e) free(e);
 return ((void *)0);
}

variable_types: struct expression { struct expression_node { enum value_type { INTEGER=0, BOOLEAN=1, STRING=2 } vtype; enum operation_type { ADD=0, SUB=1, MUL=2, DIV=3, REM=4, GT=5, LT=6, GE=7, LE=8, EQ=9, NE=10, AND=11, OR=12, NOT=13, CALL=14, NO_OP=15 } optype; } enode; struct expression_node *op[2]; } *

return_type: struct expression_node { enum value_type { INTEGER=0, BOOLEAN=1, STRING=2 } vtype; enum operation_type { ADD=0, SUB=1, MUL=2, DIV=3, REM=4, GT=5, LT=6, GE=7, LE=8, EQ=9, NE=10, AND=11, OR=12, NOT=13, CALL=14, NO_OP=15 } optype; } *

user_defined_types: struct expression { struct expression_node enode; struct expression_node *op[2]; }

user_defined_types: struct expression_node { enum value_type vtype; enum operation_type optype; }


decompiled_code:
void interpreter_read_file()
{
;
}

canonical_decompiled_code:
void func11()
{
;
}

original_code:
struct script * interpreter_read_file(char * filename)
{
}

canonical_original_code:
struct script *interpreter_read_file(char *filename)
{
}

variable_types:
filename
char *

return_type: struct script { char name[64]; struct list_head { struct list_head *next; } stmt; struct variable { struct expression_node { enum value_type { INTEGER=0, BOOLEAN=1, STRING=2 } vtype; enum operation_type { ADD=0, SUB=1, MUL=2, DIV=3, REM=4, GT=5, LT=6, GE=7, LE=8, EQ=9, NE=10, AND=11, OR=12, NOT=13, CALL=14, NO_OP=15 } optype; } enode; union { struct bg_string { char *str; int len; unsigned char cflag; } str; long integer; unsigned int boolean; } v; } varspace[]; } *

user_defined_types: struct script { char name[64]; struct list_head stmt; struct variable varspace[]; }

user_defined_types: struct variable { struct expression_node enode; union { struct bg_string str; long integer; unsigned int boolean; } v; }


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

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

original_code:
int interpreter_run(struct script * s)
{
 return 1;
}

canonical_original_code:
int interpreter_run(struct script *s)
{
 return 1;
}

variable_types: struct script { char name[64]; struct list_head { struct list_head *next; } stmt; struct variable { struct expression_node { enum value_type { INTEGER=0, BOOLEAN=1, STRING=2 } vtype; enum operation_type { ADD=0, SUB=1, MUL=2, DIV=3, REM=4, GT=5, LT=6, GE=7, LE=8, EQ=9, NE=10, AND=11, OR=12, NOT=13, CALL=14, NO_OP=15 } optype; } enode; union { struct bg_string { char *str; int len; unsigned char cflag; } str; long integer; unsigned int boolean; } v; } varspace[]; } *


decompiled_code:
void sound_use()
{
++sound_use_count;
}

canonical_decompiled_code:
void func0()
{
++sound_use_count;
}

original_code:
static void sound_use(void)
{
 sound_use_count++;
}

canonical_original_code:
static void sound_use()
{
 sound_use_count++;
}


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

if ( !--sound_use_count )
result = snd_config_update_free_global();
return result;
}

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

if ( !--sound_use_count )
result = snd_config_update_free_global();
return result;
}

original_code:
static void sound_unuse(void)
{
 if (--sound_use_count == 0)
  snd_config_update_free_global();
}

canonical_original_code:
static void sound_unuse()
{
 if (--sound_use_count == 0)
  snd_config_update_free_global();
}


COORD

decompiled_code:
__int64 __fastcall COORD(unsigned int a1, __int64 a2)
{
return (a2 << 32) | a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, __int64 a2)
{
return (a2 << 32) | a1;
}

original_code:
static inline struct coord COORD(int x, int y) {
 return (struct coord){ .x = x, .y = y };
}

variable_types: x int

variable_types: y int

return_type: struct coord { union { int x; }; union { int y; }; }


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

if ( a1 == 1 )
{
result = *(unsigned int *)(view + 24);
scroll_offset_start = *(_DWORD *)(view + 24);
}
else if ( a1 == 2 )
{
zooming = 1;
result = **(_QWORD **)(view + 16);
thumb_dim_start = result;
}
return result;
}

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

if ( a1 == 1 )
{
result = *(unsigned int *)(view + 24);
scroll_offset_start = *(_DWORD *)(view + 24);
}
else if ( a1 == 2 )
{
zooming = 1;
result = **(_QWORD **)(view + 16);
thumb_dim_start = result;
}
return result;
}

original_code:
static void eh_drag_start(int button, struct coord start) {
 if (button == 1) {
  scroll_offset_start = view->scroll_offset;
 } else if (button == 2) {
  zooming = 1;
  thumb_dim_start = view->frame->thumb_dim;
 }
}

variable_types: button int

variable_types: struct coord { union { int x; }; union { int y; }; }


decompiled_code:
void __fastcall eh_drag_stop(int a1)
{
if ( a1 == 2 )
zooming = 0;
}

canonical_decompiled_code:
void __fastcall func2(int a1)
{
if ( a1 == 2 )
zooming = 0;
}

original_code:
static void eh_drag_stop(int button) {
 if (button == 2) {
  zooming = 0;
 }
}


decompiled_code:
__int64 __fastcall eh_drag_update(int a1, __int64 a2, __int64 a3)
{
__int64 v3; // rcx
__int64 result; // rax
__int64 v5; // rax
__int64 v6; // r10
__int64 v7; // rbx
__int64 v8; // r9
__int64 v9; // rsi
int v10; // edx

v3 = a2 >> 32;
result = a3 >> 32;
if ( a1 == 1 )
{
v9 = view;
result = (unsigned int)(HIDWORD(a3) - v3);
v10 = scroll_offset_start - result;
*(_DWORD *)(view + 28) = 1;
*(_DWORD *)(v9 + 24) = v10;
}
else if ( a1 == 2 )
{
v5 = COORD(
(int)a3 - (int)a2 + (int)thumb_dim_start,
(unsigned int)(HIDWORD(thumb_dim_start) + HIDWORD(a3) - HIDWORD(a2)));
v7 = *(_QWORD *)(v6 + 8);
*(_QWORD *)v8 = v5;
*(_QWORD *)(v7 + 16) = (*(__int64 (__fastcall **)(__int64))(v8 + 24))(v8);
layout_recompute(*(_QWORD *)(view + 8));
result = view;
*(_DWORD *)(view + 28) = 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, __int64 a2, __int64 a3)
{
__int64 v3; // rcx
__int64 result; // rax
__int64 v5; // rax
__int64 v6; // r10
__int64 v7; // rbx
__int64 v8; // r9
__int64 v9; // rsi
int v10; // edx

v3 = a2 >> 32;
result = a3 >> 32;
if ( a1 == 1 )
{
v9 = view;
result = (unsigned int)(HIDWORD(a3) - v3);
v10 = scroll_offset_start - result;
*(_DWORD *)(view + 28) = 1;
*(_DWORD *)(v9 + 24) = v10;
}
else if ( a1 == 2 )
{
v5 = func0(
(int)a3 - (int)a2 + (int)thumb_dim_start,
(unsigned int)(HIDWORD(thumb_dim_start) + HIDWORD(a3) - HIDWORD(a2)));
v7 = *(_QWORD *)(v6 + 8);
*(_QWORD *)v8 = v5;
*(_QWORD *)(v7 + 16) = (*(__int64 (__fastcall **)(__int64))(v8 + 24))(v8);
layout_recompute(*(_QWORD *)(view + 8));
result = view;
*(_DWORD *)(view + 28) = 1;
}
return result;
}

original_code:
static void eh_drag_update(int button, struct coord start, struct coord pointer) {
 if (button == 1) {
  view->scroll_offset = scroll_offset_start - (pointer.y - start.y);
  view->dirty = 1;
 } else if (button == 2) {
  view->frame->thumb_dim = COORD(
   thumb_dim_start.width + (pointer.x - start.x),
   thumb_dim_start.height + (pointer.y - start.y)
  );
  view->layout->frame = view->frame->frame_size(view->frame);
  layout_recompute(view->layout);
  view->dirty = 1;
 }
}

variable_types:
pointer
struct coord

user_defined_types: struct coord { union { int x; }; union { int y; }; }


decompiled_code:
__pid_t __fastcall eh_click(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rdx
__pid_t result; // eax
__int64 v5; // rbx
int v6; // er13
__int64 v7; // r14
char **v8; // rax
const char ***v9; // r12
char **v10; // rbp
const char **v11; // r15
__int64 v12; // rax
struct stat v13; // [rsp+0h] [rbp-C8h] BYREF

v2 = COORD(a2, (unsigned int)(*(_DWORD *)(view + 24) + HIDWORD(a2)));
result = layout_frame_number_by_coord(*(_QWORD *)(v3 + 8), v2);
v5 = result;
if ( result != -1 )
{
result = fork();
if ( !result )
{
if ( fork() )
exit(0);
v6 = 3;
v7 = 3LL;
v8 = (char **)malloc(8LL * (*(_DWORD *)(*(_QWORD *)(view + 8) + 24LL) + 4));
v9 = (const char ***)thumbnails;
v10 = v8;
while ( 1 )
{
v11 = (const char **)&v10[v7];
if ( !*v9 )
break;
stat(**v9, &v13);
if ( (v13.st_mode & 0xF000) == 0x8000 )
{
v7 = ++v6;
*v11 = **v9;
}
++v9;
}
v12 = thumbnails;
*v10 = "feh";
v10[1] = "--start-at";
v10[2] = **(char ***)(v12 + 8 * v5);
*v11 = 0LL;
execvp("feh", v10);
perror("exec");
exit(1);
}
}
return result;
}

canonical_decompiled_code:
__pid_t __fastcall func4(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rdx
__pid_t result; // eax
__int64 v5; // rbx
int v6; // er13
__int64 v7; // r14
char **v8; // rax
const char ***v9; // r12
char **v10; // rbp
const char **v11; // r15
__int64 v12; // rax
struct stat v13; // [rsp+0h] [rbp-C8h] BYREF

v2 = func0(a2, (unsigned int)(*(_DWORD *)(view + 24) + HIDWORD(a2)));
result = layout_frame_number_by_coord(*(_QWORD *)(v3 + 8), v2);
v5 = result;
if ( result != -1 )
{
result = fork();
if ( !result )
{
if ( fork() )
exit(0);
v6 = 3;
v7 = 3LL;
v8 = (char **)malloc(8LL * (*(_DWORD *)(*(_QWORD *)(view + 8) + 24LL) + 4));
v9 = (const char ***)thumbnails;
v10 = v8;
while ( 1 )
{
v11 = (const char **)&v10[v7];
if ( !*v9 )
break;
stat(**v9, &v13);
if ( (v13.st_mode & 0xF000) == 0x8000 )
{
v7 = ++v6;
*v11 = **v9;
}
++v9;
}
v12 = thumbnails;
*v10 = "feh";
v10[1] = "--start-at";
v10[2] = **(char ***)(v12 + 8 * v5);
*v11 = 0LL;
execvp("feh", v10);
perror("exec");
exit(1);
}
}
return result;
}

original_code:
static void eh_click(int button, struct coord pos) {
 int n = layout_frame_number_by_coord(view->layout, COORD(pos.x, pos.y + view->scroll_offset));
 if (n == -1) {
 } else {
  if (!fork()) {
   if (!fork()) {
    char **varg = malloc(sizeof(char*) * (view->layout->frame_count + 4));
    int va = 3;
    struct thumbnail **p = thumbnails;
    while (*p != ((void *)0)) {
     struct stat s;
     stat((*p)->filename, &s);
     if (((((s.st_mode)) & 0170000) == (0100000))) {
      varg[va] = (*p)->filename;
      va++;
     }
     p++;
    }
    varg[0] = "feh";
    varg[1] = "--start-at";
    varg[2] = thumbnails[n]->filename;
    varg[va] = ((void *)0);
    execvp("feh", varg);
    perror("exec");
    exit(1);
   }
   exit(0);
  }
 }
}

variable_types: n int

variable_types:
varg
char **

variable_types: va int

variable_types: struct thumbnail { char *filename; void *imlib; struct coord { union { int x; }; union { int y; }; } thumb_dim; int size; int failed; } **

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct thumbnail { char *filename; void *imlib; struct coord thumb_dim; int size; int failed; }


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 *v3; // rbx
__int64 v4; // rax
__int64 v5; // rdi
__int64 v6; // rbx
__int64 v7; // rax
const char *v8; // rdx
int v9; // er15
__int64 i; // rbp
__int64 v11; // r14
char **v12; // rax
const char *v13; // rdx
char **v14; // rbx
struct dirent **v15; // rax
struct dirent *v16; // rdi
__int64 v17; // rbx
__int64 v18; // rbx
__int64 v19; // rax
__int64 *v20; // rdx
__int64 v21; // rax
__int64 v22; // rdx
__int64 *v23; // rbx
__int64 v24; // rdx
__int64 v25; // rdi
size_t v26; // [rsp+8h] [rbp-50h]
struct dirent **namelist; // [rsp+18h] [rbp-40h] BYREF

if ( argc != 2 )
{
fwrite("thumbnail must be invoked with a single argument specifying the directory to load\n", 1uLL, 0x52uLL, stderr);
exit(1);
}
x11 = x11_connect(argc, argv, envp);
x11_setup_imlib(x11);
input_set_click_handler(eh_click);
input_set_drag_handlers(eh_drag_start, eh_drag_stop, eh_drag_update);
v3 = (__int64 *)view_new();
view = (__int64)v3;
v4 = surface_new();
v5 = x11;
*v3 = v4;
v6 = *(_QWORD *)view;
**(_QWORD **)view = v5;
v7 = x11_make_window();
v8 = argv[1];
*(_QWORD *)(v6 + 8) = v7;
XStoreName(*(Display **)x11, *(_QWORD *)(*(_QWORD *)view + 8LL), v8);
XFlush(*(Display **)x11);
v9 = scandir(argv[1], &namelist, 0LL, (int (*)(const struct dirent **, const struct dirent **))&alphasort);
v26 = 8LL * (v9 + 1);
thumbnails = malloc(v26);
if ( v9 > 0 )
{
for ( i = 0LL; i != v9; ++i )
{
v11 = thumbnails;
v12 = (char **)malloc(0x20uLL);
v13 = argv[1];
v14 = v12;
*(_QWORD *)(i * 8 + v11) = v12;
asprintf(v12, "%s/%s", v13, namelist[i]->d_name);
v15 = namelist;
v14[1] = 0LL;
*((_DWORD *)v14 + 7) = 0;
v16 = v15[i];
free(v16);
}
}
free(namelist);
v17 = view;
*(_QWORD *)(thumbnails + v26 - 8) = 0LL;
*(_QWORD *)(v17 + 16) = frame_new_symbols();
v18 = view;
v19 = COORD(0xC8u, 150LL);
*v20 = v19;
v21 = layout_new();
v22 = view;
*(_QWORD *)(v18 + 8) = v21;
v23 = *(__int64 **)(v22 + 8);
*v23 = COORD(0, 0LL);
v23[1] = COORD(0x14u, 20LL);
v23[2] = (*(__int64 (__fastcall **)(_QWORD))(*(_QWORD *)(v24 + 16) + 24LL))(*(_QWORD *)(v24 + 16));
v25 = *(_QWORD *)(view + 8);
*(_DWORD *)(v25 + 24) = v9;
layout_recompute(v25);
must_update = 1;
event_loop_constprop_0(*(Display **)x11);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 *v3; // rbx
__int64 v4; // rax
__int64 v5; // rdi
__int64 v6; // rbx
__int64 v7; // rax
const char *v8; // rdx
int v9; // er15
__int64 i; // rbp
__int64 v11; // r14
char **v12; // rax
const char *v13; // rdx
char **v14; // rbx
struct dirent **v15; // rax
struct dirent *v16; // rdi
__int64 v17; // rbx
__int64 v18; // rbx
__int64 v19; // rax
__int64 *v20; // rdx
__int64 v21; // rax
__int64 v22; // rdx
__int64 *v23; // rbx
__int64 v24; // rdx
__int64 v25; // rdi
size_t v26; // [rsp+8h] [rbp-50h]
struct dirent **namelist; // [rsp+18h] [rbp-40h] BYREF

if ( argc != 2 )
{
fwrite("thumbnail must be invoked with a single argument specifying the directory to load\n", 1uLL, 0x52uLL, stderr);
exit(1);
}
x11 = x11_connect(argc, argv, envp);
x11_setup_imlib(x11);
input_set_click_handler(eh_click);
input_set_drag_handlers(eh_drag_start, eh_drag_stop, eh_drag_update);
v3 = (__int64 *)view_new();
view = (__int64)v3;
v4 = surface_new();
v5 = x11;
*v3 = v4;
v6 = *(_QWORD *)view;
**(_QWORD **)view = v5;
v7 = x11_make_window();
v8 = argv[1];
*(_QWORD *)(v6 + 8) = v7;
XStoreName(*(Display **)x11, *(_QWORD *)(*(_QWORD *)view + 8LL), v8);
XFlush(*(Display **)x11);
v9 = scandir(argv[1], &namelist, 0LL, (int (*)(const struct dirent **, const struct dirent **))&alphasort);
v26 = 8LL * (v9 + 1);
thumbnails = malloc(v26);
if ( v9 > 0 )
{
for ( i = 0LL; i != v9; ++i )
{
v11 = thumbnails;
v12 = (char **)malloc(0x20uLL);
v13 = argv[1];
v14 = v12;
*(_QWORD *)(i * 8 + v11) = v12;
asprintf(v12, "%s/%s", v13, namelist[i]->d_name);
v15 = namelist;
v14[1] = 0LL;
*((_DWORD *)v14 + 7) = 0;
v16 = v15[i];
free(v16);
}
}
free(namelist);
v17 = view;
*(_QWORD *)(thumbnails + v26 - 8) = 0LL;
*(_QWORD *)(v17 + 16) = frame_new_symbols();
v18 = view;
v19 = func0(0xC8u, 150LL);
*v20 = v19;
v21 = layout_new();
v22 = view;
*(_QWORD *)(v18 + 8) = v21;
v23 = *(__int64 **)(v22 + 8);
*v23 = func0(0, 0LL);
v23[1] = func0(0x14u, 20LL);
v23[2] = (*(__int64 (__fastcall **)(_QWORD))(*(_QWORD *)(v24 + 16) + 24LL))(*(_QWORD *)(v24 + 16));
v25 = *(_QWORD *)(view + 8);
*(_DWORD *)(v25 + 24) = v9;
layout_recompute(v25);
must_update = 1;
func6(*(Display **)x11);
}

original_code:
int main(int argc, char *argv[]) {
 if (argc != 2) {
  fputs("thumbnail must be invoked with a single argument specifying the directory to load\n", stderr);
  exit(1);
 }
 x11 = x11_connect();
 x11_setup_imlib(x11);
 input_set_click_handler(eh_click);
 input_set_drag_handlers(eh_drag_start, eh_drag_stop, eh_drag_update);
 view = view_new();
 view->surface = surface_new();
 view->surface->x11 = x11;
 view->surface->window = x11_make_window(x11);
 XStoreName(x11->display, view->surface->window, argv[1]);
 XFlush(x11->display);
 struct dirent **dir_entries;
 int dir_count = scandir(argv[1], &dir_entries, ((void *)0), alphasort);
 thumbnails = malloc(sizeof(struct thumbnail *) * (dir_count + 1));
 for (int i = 0; i < dir_count; i++) {
  thumbnails[i] = malloc(sizeof(struct thumbnail));
  struct thumbnail *t = thumbnails[i];
  char *fn = dir_entries[i]->d_name;
  asprintf(&t->filename, "%s/%s", argv[1], fn);
  t->failed = 0;
  t->imlib = ((void *)0);
  free(dir_entries[i]);
 }
 free(dir_entries);
 thumbnails[dir_count] = ((void *)0);
 view->frame = frame_new_symbols();
 view->frame->thumb_dim = COORD(200, 150);
 view->layout = layout_new();
 view->layout->window = COORD(0, 0);
 view->layout->spacing = COORD(20, 20);
 view->layout->frame = view->frame->frame_size(view->frame);
 view->layout->frame_count = dir_count;
 layout_recompute(view->layout);
 must_update = 1;
 event_loop(x11->display, 0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct dirent { unsigned long d_ino; long d_off; unsigned short d_reclen; unsigned char d_type; char d_name[256]; } **

variable_types: i int

variable_types: struct thumbnail { char *filename; void *imlib; struct coord { union { int x; }; union { int y; }; } thumb_dim; int size; int failed; } *

variable_types:
fn
char *


COORD

canonical_original_code:
static inline struct coord COORD(int x, int y) {
 return (struct coord){ .x = x, .y = y };
}


decompiled_code:
__int64 __fastcall symbols_frame_size(unsigned int *a1)
{
return COORD(*a1, a1[1] + 12);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int *a1)
{
return func0(*a1, a1[1] + 12);
}

original_code:
static struct coord symbols_frame_size(struct frame *frame) {
 return COORD(frame->thumb_dim.width, frame->thumb_dim.height + 12);
}

variable_types: struct frame { struct coord thumb_dim; void *font; void (*render)(struct frame *, struct thumbnail { char *filename; void *imlib; struct coord thumb_dim; int size; int failed; } *, struct rect { struct coord tl; struct coord dim; }); struct coord (*frame_size)(struct frame *); } *

user_defined_types: struct frame { struct coord thumb_dim; void *font; void (*render)(struct frame *, struct thumbnail *, struct rect); struct coord (*frame_size)(struct frame *); }


decompiled_code:
void __fastcall symbols_render(unsigned int *a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 v4; // r14
int v5; // er13
__int64 v7; // rax
__int64 v8; // rcx
const char *v9; // r15
char *v10; // rax
void *v11; // r12
__int64 v12; // rax
__int64 v13; // rax
size_t n; // [rsp+8h] [rbp-50h]
int v15; // [rsp+18h] [rbp-40h] BYREF
char v16[60]; // [rsp+1Ch] [rbp-3Ch] BYREF

v4 = a3 >> 32;
v5 = a3;
v7 = symbols_frame_size(a1);
if ( v7 != __PAIR64__(v8, a4) )
fprintf(
stderr,
"[-] target frame size %dx%d does not match configured one %dx%d\n",
a4,
v8,
(unsigned int)v7,
v7 >> 32);
if ( *(_QWORD *)(a2 + 8) && !*(_DWORD *)(a2 + 28) )
{
v12 = coord_scale_to_fit(*(_QWORD *)(a2 + 16), *(_QWORD *)a1);
imlib_blend_image_onto_image(
*(_QWORD *)(a2 + 8),
1LL,
0LL,
0LL,
*(unsigned int *)(a2 + 16),
*(unsigned int *)(a2 + 20),
(unsigned int)(v5 + (int)(*a1 - v12) / 2),
(unsigned int)(v4 + (int)(a1[1] - HIDWORD(v12)) / 2),
v12,
v12 >> 32);
if ( *((_QWORD *)a1 + 1) )
goto LABEL_6;
LABEL_10:
imlib_add_path_to_font_path("/usr/share/fonts/truetype/ttf-dejavu");
v13 = imlib_load_font("DejaVuSans/10");
*((_QWORD *)a1 + 1) = v13;
if ( !v13 )
return;
goto LABEL_6;
}
if ( !*((_QWORD *)a1 + 1) )
goto LABEL_10;
LABEL_6:
imlib_context_set_font();
imlib_context_set_color(255LL, 255LL, 255LL, 255LL);
v9 = *(const char **)a2;
v10 = strrchr(*(const char **)a2, 47);
if ( v10 )
v9 = v10 + 1;
n = strlen(v9) + 1;
v11 = malloc(n);
memcpy(v11, v9, n);
imlib_get_text_size(v11, &v15, v16);
imlib_text_draw((unsigned int)((int)(a4 - v15) / 2 + v5), (unsigned int)v4 + a1[1], v11);
free(v11);
}

canonical_decompiled_code:
void __fastcall func2(unsigned int *a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 v4; // r14
int v5; // er13
__int64 v7; // rax
__int64 v8; // rcx
const char *v9; // r15
char *v10; // rax
void *v11; // r12
__int64 v12; // rax
__int64 v13; // rax
size_t n; // [rsp+8h] [rbp-50h]
int v15; // [rsp+18h] [rbp-40h] BYREF
char v16[60]; // [rsp+1Ch] [rbp-3Ch] BYREF

v4 = a3 >> 32;
v5 = a3;
v7 = func1(a1);
if ( v7 != __PAIR64__(v8, a4) )
fprintf(
stderr,
"[-] target frame size %dx%d does not match configured one %dx%d\n",
a4,
v8,
(unsigned int)v7,
v7 >> 32);
if ( *(_QWORD *)(a2 + 8) && !*(_DWORD *)(a2 + 28) )
{
v12 = coord_scale_to_fit(*(_QWORD *)(a2 + 16), *(_QWORD *)a1);
imlib_blend_image_onto_image(
*(_QWORD *)(a2 + 8),
1LL,
0LL,
0LL,
*(unsigned int *)(a2 + 16),
*(unsigned int *)(a2 + 20),
(unsigned int)(v5 + (int)(*a1 - v12) / 2),
(unsigned int)(v4 + (int)(a1[1] - HIDWORD(v12)) / 2),
v12,
v12 >> 32);
if ( *((_QWORD *)a1 + 1) )
goto LABEL_6;
LABEL_10:
imlib_add_path_to_font_path("/usr/share/fonts/truetype/ttf-dejavu");
v13 = imlib_load_font("DejaVuSans/10");
*((_QWORD *)a1 + 1) = v13;
if ( !v13 )
return;
goto LABEL_6;
}
if ( !*((_QWORD *)a1 + 1) )
goto LABEL_10;
LABEL_6:
imlib_context_set_font();
imlib_context_set_color(255LL, 255LL, 255LL, 255LL);
v9 = *(const char **)a2;
v10 = strrchr(*(const char **)a2, 47);
if ( v10 )
v9 = v10 + 1;
n = strlen(v9) + 1;
v11 = malloc(n);
memcpy(v11, v9, n);
imlib_get_text_size(v11, &v15, v16);
imlib_text_draw((unsigned int)((int)(a4 - v15) / 2 + v5), (unsigned int)v4 + a1[1], v11);
free(v11);
}

original_code:
static void symbols_render(struct frame *frame, struct thumbnail *t, struct rect target) {
 struct coord _rc1 = symbols_frame_size(frame);
 struct coord _rc2 = target.dim;
 if (_rc1.x != _rc2.x || _rc1.y != _rc2.y) {
  fprintf(stderr, "[-] target frame size %dx%d does not match configured one %dx%d\n",
   _rc2.x, _rc2.y, _rc1.x, _rc1.y
  );
 }
 if (t->imlib != ((void *)0) && !t->failed) {
  struct coord render_dim = coord_scale_to_fit(
   t->thumb_dim,
   frame->thumb_dim
  );
  imlib_blend_image_onto_image(t->imlib, 1,
               0, 0, t->thumb_dim.width, t->thumb_dim.height,
    target.tl.x + (frame->thumb_dim.width - render_dim.width ) / 2,
    target.tl.y + (frame->thumb_dim.height - render_dim.height) / 2,
    render_dim.width, render_dim.height
  );
 }
 if (frame->font == ((void *)0)) {
  imlib_add_path_to_font_path("/usr/share/fonts/truetype/ttf-dejavu");
  frame->font = imlib_load_font("DejaVuSans/10");
 }
 if (frame->font != ((void *)0)) {
  imlib_context_set_font(frame->font);
  imlib_context_set_color(255, 255, 255, 255);
  char *basename = strrchr(t->filename, '/');
  if (basename == ((void *)0)) {
   basename = t->filename;
  } else {
   basename++;
  }
  char *text = malloc(sizeof(char) * (strlen(basename) + 1));
  strcpy(text, basename);
  int textwidth, textheight;
  imlib_get_text_size(text, &textwidth, &textheight);
  int tx, ty;
  tx = target.tl.x + (target.dim.width - textwidth) / 2;
  ty = target.tl.y + frame->thumb_dim.height;
  imlib_text_draw(tx, ty, text);
  free(text);
 }
}

canonical_original_code:
static void symbols_render(struct frame *frame, struct thumbnail *t, struct rect target) {
 struct coord _rc1 = symbols_frame_size(frame);
 struct coord _rc2 = target.dim;
 if (_rc1.x != _rc2.x || _rc1.y != _rc2.y) {
  fprintf(stderr, "[-] target frame size %dx%d does not match configured one %dx%d\n",
   _rc2.x, _rc2.y, _rc1.x, _rc1.y
  );
 }
 if (t->imlib != ((void *)0) && !t->failed) {
  struct coord render_dim = coord_scale_to_fit(
   t->thumb_dim,
   frame->thumb_dim
  );
  imlib_blend_image_onto_image(t->imlib, 1,
               0, 0, t->thumb_dim.width, t->thumb_dim.height,
    target.tl.x + (frame->thumb_dim.width - render_dim.width ) / 2,
    target.tl.y + (frame->thumb_dim.height - render_dim.height) / 2,
    render_dim.width, render_dim.height
  );
 }
 if (frame->font == ((void *)0)) {
  imlib_add_path_to_font_path("/usr/share/fonts/truetype/ttf-dejavu");
  frame->font = imlib_load_font("DejaVuSans/10");
 }
 if (frame->font != ((void *)0)) {
  imlib_context_set_font(frame->font);
  imlib_context_set_color(255, 255, 255, 255);
  char *basename = strrchr(t->filename, '/');
  if (basename == ((void *)0)) {
   basename = t->filename;
  } else {
   basename++;
  }
  char *text = malloc(sizeof(char) * (strlen(basename) + 1));
  strcpy(text, basename);
  int textwidth; int textheight;
  imlib_get_text_size(text, &textwidth, &textheight);
  int tx; int ty;
  tx = target.tl.x + (target.dim.width - textwidth) / 2;
  ty = target.tl.y + frame->thumb_dim.height;
  imlib_text_draw(tx, ty, text);
  free(text);
 }
}

variable_types: struct frame { struct coord { union { int x; }; union { int y; }; } thumb_dim; void *font; void (*render)(struct frame *, struct thumbnail { char *filename; void *imlib; struct coord thumb_dim; int size; int failed; } *, struct rect { struct coord tl; struct coord dim; }); struct coord (*frame_size)(struct frame *); } *

variable_types:
t
struct thumbnail *

variable_types:
target
struct rect

variable_types:
basename
char *

variable_types:
text
char *

variable_types: textwidth int

variable_types: textheight int

variable_types: tx int

variable_types: ty int


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

result = malloc(0x20uLL);
result[3] = symbols_frame_size;
result[2] = symbols_render;
result[1] = 0LL;
return result;
}

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

result = malloc(0x20uLL);
result[3] = symbols_frame_size;
result[2] = symbols_render;
result[1] = 0LL;
return result;
}

original_code:
struct frame *frame_new_symbols() {
 struct frame *f = malloc(sizeof(struct frame));
 f->frame_size = symbols_frame_size;
 f->render = symbols_render;
 f->font = ((void *)0);
 return f;
}

return_type: struct frame { struct coord { union { int x; }; union { int y; }; } thumb_dim; void *font; void (*render)(struct frame *, struct thumbnail { char *filename; void *imlib; struct coord thumb_dim; int size; int failed; } *, struct rect { struct coord tl; struct coord dim; }); struct coord (*frame_size)(struct frame *); } *


reaper

repo: beghbali/StackOverflowExploit

decompiled_code:
void reaper()
{
signal(17, reaper);
if ( verbose )
write(2, "reaper: ", 8uLL);
if ( wait(0LL) > 0 )
{
++servers_allowed;
if ( !verbose )
return;
write(2, ".", 1uLL);
}
if ( verbose )
write(2, " reaped\n", 8uLL);
}

canonical_decompiled_code:
void func0()
{
signal(17, reaper);
if ( verbose )
write(2, "reaper: ", 8uLL);
if ( wait(0LL) > 0 )
{
++servers_allowed;
if ( !verbose )
return;
write(2, ".", 1uLL);
}
if ( verbose )
write(2, " reaped\n", 8uLL);
}

original_code:
void reaper(void)
{
 (void) signal(17,(void (*)(int)) reaper);
 if (verbose) write(2,"reaper: ",8);
 if (wait((int *) 0) > 0) {
  ++servers_allowed;
  if (verbose) write(2,".",1);
 }
 if (verbose) write(2," reaped\n",8);
}

canonical_original_code:
void reaper()
{
 (void) signal(17,(void (*)(int)) reaper);
 if (verbose) write(2,"reaper: ",8);
 if (wait((int *) 0) > 0) {
  ++servers_allowed;
  if (verbose) write(2,".",1);
 }
 if (verbose) write(2," reaped\n",8);
}


usage

decompiled_code:
int usage()
{
return fprintf(
stderr,
"Usage: %s [-dlv] [-p port] [-c count-to-exit] [-s server-count-limit] [-D descriptor-num]\n",
(const char *)me);
}

canonical_decompiled_code:
int func2()
{
return fprintf(
stderr,
"Usage: %s [-dlv] [-p port] [-c count-to-exit] [-s server-count-limit] [-D descriptor-num]\n",
(const char *)me);
}

original_code:
void usage(void)
{
 fprintf(stderr,"Usage:  %s [-dlv] [-p port] [-c count-to-exit] [-s server-count-limit] [-D descriptor-num]\n",me);
}

canonical_original_code:
void usage()
{
 fprintf(stderr,"Usage:  %s [-dlv] [-p port] [-c count-to-exit] [-s server-count-limit] [-D descriptor-num]\n",me);
}