decompiled_code:
__int64 __fastcall p8_cec_tx(unsigned int a1, char a2, __int64 a3, unsigned __int64 *a4)
{
unsigned __int64 v5; // rdx
unsigned __int64 v6; // r14
unsigned __int64 v8; // r15
unsigned __int64 v9; // rax
unsigned __int64 v10; // rdx
_QWORD *v11; // r13
unsigned __int64 v12; // rax
__int64 v13; // rdx
unsigned __int64 v14; // rdx
unsigned __int64 v15; // rax
unsigned __int64 v16; // rdx
unsigned __int64 v17; // rax
char *v19; // [rsp+0h] [rbp-198h]
unsigned int v20; // [rsp+8h] [rbp-190h]
int v21; // [rsp+Ch] [rbp-18Ch]
__int64 v22[2]; // [rsp+10h] [rbp-188h] BYREF
char v23[112]; // [rsp+20h] [rbp-178h] BYREF
__int64 v24[8]; // [rsp+90h] [rbp-108h] BYREF
char *v25; // [rsp+D0h] [rbp-C8h] BYREF
char *v26; // [rsp+D8h] [rbp-C0h]
char v27[120]; // [rsp+E0h] [rbp-B8h] BYREF
int v28; // [rsp+158h] [rbp-40h] BYREF
int v29; // [rsp+15Ch] [rbp-3Ch] BYREF

v29 = 0;
v28 = 0;
v5 = *(_QWORD *)(a3 + 8);
v6 = a3 + 20;
if ( v5 < a3 + 20 || (v8 = a3 + 128, v5 > a3 + 128) )
_assert_fail(
"(cec_oframe)->f_end >= (cec_oframe)->f_buf && (cec_oframe)->f_end <= (cec_oframe)->f_buf + COUNT_OF((cec_oframe)->f_buf)",
"p8_cec_tx.c",
0x7Au,
"p8_cec_tx");
v9 = *(_QWORD *)a3;
if ( v8 < *(_QWORD *)a3 || v6 > v9 )
_assert_fail(
"(cec_oframe)->f_sta >= (cec_oframe)->f_buf && (cec_oframe)->f_sta <= (cec_oframe)->f_buf + COUNT_OF((cec_oframe)->f_buf)",
"p8_cec_tx.c",
0x7Au,
"p8_cec_tx");
if ( v5 < v9 )
_assert_fail("(cec_oframe)->f_sta <= (cec_oframe)->f_end", "p8_cec_tx.c", 0x7Au, "p8_cec_tx");
v10 = a4[1];
v19 = (char *)a4 + 20;
if ( v10 < (unsigned __int64)a4 + 20 || (v11 = a4 + 16, v10 > (unsigned __int64)(a4 + 16)) )
_assert_fail(
"(cec_iframe)->f_end >= (cec_iframe)->f_buf && (cec_iframe)->f_end <= (cec_iframe)->f_buf + COUNT_OF((cec_iframe)->f_buf)",
"p8_cec_tx.c",
0x7Bu,
"p8_cec_tx");
v12 = *a4;
if ( (unsigned __int64)v11 < *a4 || (unsigned __int64)v19 > v12 )
_assert_fail(
"(cec_iframe)->f_sta >= (cec_iframe)->f_buf && (cec_iframe)->f_sta <= (cec_iframe)->f_buf + COUNT_OF((cec_iframe)->f_buf)",
"p8_cec_tx.c",
0x7Bu,
"p8_cec_tx");
if ( v10 < v12 )
_assert_fail("(cec_iframe)->f_sta <= (cec_iframe)->f_end", "p8_cec_tx.c", 0x7Bu, "p8_cec_tx");
memset(v27, 0, 0x70uLL);
v25 = &v27[4];
v26 = &v27[4];
v24[0] = 0LL;
v24[7] = 0LL;
v24[1] = (__int64)a4;
v24[2] = (__int64)a4;
v24[3] = (__int64)&v29;
v24[4] = (__int64)&v28;
v24[5] = a3;
v24[6] = a3;
LOBYTE(v22[0]) = a2;
p8_encode_cmd(&v25, 13LL, v22, 1LL);
++v29;
for ( ; *(_QWORD *)a3 < (unsigned __int64)(*(_QWORD *)(a3 + 8) - 1LL); ++v29 )
p8_encode_tx(&v25, 11LL, a3);
p8_encode_tx(&v25, 12LL, a3);
v13 = (unsigned int)++v29;
*(_DWORD *)(a3 + 16) = -1;
printf("CEC TX: Writing %ld bytes, waiting for %d acks\n", v26 - v25, v13);
v20 = p8_write(a1, &v25, "\b", v24);
if ( v20 )
{
cec_tx_error(4294967294LL, a3);
}
else
{
memset(v23, 0, sizeof(v23));
v22[0] = (__int64)&v23[4];
v22[1] = (__int64)&v23[4];
v21 = v28;
if ( !v28 )
{
while ( *(_DWORD *)(a3 + 16) == -1 )
{
puts("CEC TX: Processing input");
p8_read_and_dispatch(a1, v22, "\b", v24);
if ( v28 )
goto LABEL_17;
}
}
if ( v29 | v21 )
LABEL_17:
cec_tx_error(4294967294LL, a3);
v14 = *(_QWORD *)(a3 + 8);
if ( v8 < v14 || v6 > v14 )
_assert_fail(
"(cec_oframe)->f_end >= (cec_oframe)->f_buf && (cec_oframe)->f_end <= (cec_oframe)->f_buf + COUNT_OF((cec_oframe)->f_buf)",
"p8_cec_tx.c",
0xB5u,
"p8_cec_tx");
v15 = *(_QWORD *)a3;
if ( v8 < *(_QWORD *)a3 || v6 > v15 )
_assert_fail(
"(cec_oframe)->f_sta >= (cec_oframe)->f_buf && (cec_oframe)->f_sta <= (cec_oframe)->f_buf + COUNT_OF((cec_oframe)->f_buf)",
"p8_cec_tx.c",
0xB5u,
"p8_cec_tx");
if ( v14 < v15 )
_assert_fail("(cec_oframe)->f_sta <= (cec_oframe)->f_end", "p8_cec_tx.c", 0xB5u, "p8_cec_tx");
v16 = a4[1];
if ( (unsigned __int64)v11 < v16 || (unsigned __int64)v19 > v16 )
_assert_fail(
"(cec_iframe)->f_end >= (cec_iframe)->f_buf && (cec_iframe)->f_end <= (cec_iframe)->f_buf + COUNT_OF((cec_iframe)->f_buf)",
"p8_cec_tx.c",
0xB6u,
"p8_cec_tx");
v17 = *a4;
if ( (unsigned __int64)v11 < *a4 || (unsigned __int64)v19 > v17 )
_assert_fail(
"(cec_iframe)->f_sta >= (cec_iframe)->f_buf && (cec_iframe)->f_sta <= (cec_iframe)->f_buf + COUNT_OF((cec_iframe)->f_buf)",
"p8_cec_tx.c",
0xB6u,
"p8_cec_tx");
if ( v16 < v17 )
_assert_fail("(cec_iframe)->f_sta <= (cec_iframe)->f_end", "p8_cec_tx.c", 0xB6u, "p8_cec_tx");
}
return v20;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, char a2, __int64 a3, unsigned __int64 *a4)
{
unsigned __int64 v5; // rdx
unsigned __int64 v6; // r14
unsigned __int64 v8; // r15
unsigned __int64 v9; // rax
unsigned __int64 v10; // rdx
_QWORD *v11; // r13
unsigned __int64 v12; // rax
__int64 v13; // rdx
unsigned __int64 v14; // rdx
unsigned __int64 v15; // rax
unsigned __int64 v16; // rdx
unsigned __int64 v17; // rax
char *v19; // [rsp+0h] [rbp-198h]
unsigned int v20; // [rsp+8h] [rbp-190h]
int v21; // [rsp+Ch] [rbp-18Ch]
__int64 v22[2]; // [rsp+10h] [rbp-188h] BYREF
char v23[112]; // [rsp+20h] [rbp-178h] BYREF
__int64 v24[8]; // [rsp+90h] [rbp-108h] BYREF
char *v25; // [rsp+D0h] [rbp-C8h] BYREF
char *v26; // [rsp+D8h] [rbp-C0h]
char v27[120]; // [rsp+E0h] [rbp-B8h] BYREF
int v28; // [rsp+158h] [rbp-40h] BYREF
int v29; // [rsp+15Ch] [rbp-3Ch] BYREF

v29 = 0;
v28 = 0;
v5 = *(_QWORD *)(a3 + 8);
v6 = a3 + 20;
if ( v5 < a3 + 20 || (v8 = a3 + 128, v5 > a3 + 128) )
_assert_fail(
"(cec_oframe)->f_end >= (cec_oframe)->f_buf && (cec_oframe)->f_end <= (cec_oframe)->f_buf + COUNT_OF((cec_oframe)->f_buf)",
"p8_cec_tx.c",
0x7Au,
"p8_cec_tx");
v9 = *(_QWORD *)a3;
if ( v8 < *(_QWORD *)a3 || v6 > v9 )
_assert_fail(
"(cec_oframe)->f_sta >= (cec_oframe)->f_buf && (cec_oframe)->f_sta <= (cec_oframe)->f_buf + COUNT_OF((cec_oframe)->f_buf)",
"p8_cec_tx.c",
0x7Au,
"p8_cec_tx");
if ( v5 < v9 )
_assert_fail("(cec_oframe)->f_sta <= (cec_oframe)->f_end", "p8_cec_tx.c", 0x7Au, "p8_cec_tx");
v10 = a4[1];
v19 = (char *)a4 + 20;
if ( v10 < (unsigned __int64)a4 + 20 || (v11 = a4 + 16, v10 > (unsigned __int64)(a4 + 16)) )
_assert_fail(
"(cec_iframe)->f_end >= (cec_iframe)->f_buf && (cec_iframe)->f_end <= (cec_iframe)->f_buf + COUNT_OF((cec_iframe)->f_buf)",
"p8_cec_tx.c",
0x7Bu,
"p8_cec_tx");
v12 = *a4;
if ( (unsigned __int64)v11 < *a4 || (unsigned __int64)v19 > v12 )
_assert_fail(
"(cec_iframe)->f_sta >= (cec_iframe)->f_buf && (cec_iframe)->f_sta <= (cec_iframe)->f_buf + COUNT_OF((cec_iframe)->f_buf)",
"p8_cec_tx.c",
0x7Bu,
"p8_cec_tx");
if ( v10 < v12 )
_assert_fail("(cec_iframe)->f_sta <= (cec_iframe)->f_end", "p8_cec_tx.c", 0x7Bu, "p8_cec_tx");
memset(v27, 0, 0x70uLL);
v25 = &v27[4];
v26 = &v27[4];
v24[0] = 0LL;
v24[7] = 0LL;
v24[1] = (__int64)a4;
v24[2] = (__int64)a4;
v24[3] = (__int64)&v29;
v24[4] = (__int64)&v28;
v24[5] = a3;
v24[6] = a3;
LOBYTE(v22[0]) = a2;
p8_encode_cmd(&v25, 13LL, v22, 1LL);
++v29;
for ( ; *(_QWORD *)a3 < (unsigned __int64)(*(_QWORD *)(a3 + 8) - 1LL); ++v29 )
p8_encode_tx(&v25, 11LL, a3);
p8_encode_tx(&v25, 12LL, a3);
v13 = (unsigned int)++v29;
*(_DWORD *)(a3 + 16) = -1;
printf("CEC TX: Writing %ld bytes, waiting for %d acks\n", v26 - v25, v13);
v20 = p8_write(a1, &v25, "\b", v24);
if ( v20 )
{
cec_tx_error(4294967294LL, a3);
}
else
{
memset(v23, 0, sizeof(v23));
v22[0] = (__int64)&v23[4];
v22[1] = (__int64)&v23[4];
v21 = v28;
if ( !v28 )
{
while ( *(_DWORD *)(a3 + 16) == -1 )
{
puts("CEC TX: Processing input");
p8_read_and_dispatch(a1, v22, "\b", v24);
if ( v28 )
goto LABEL_17;
}
}
if ( v29 | v21 )
LABEL_17:
cec_tx_error(4294967294LL, a3);
v14 = *(_QWORD *)(a3 + 8);
if ( v8 < v14 || v6 > v14 )
_assert_fail(
"(cec_oframe)->f_end >= (cec_oframe)->f_buf && (cec_oframe)->f_end <= (cec_oframe)->f_buf + COUNT_OF((cec_oframe)->f_buf)",
"p8_cec_tx.c",
0xB5u,
"p8_cec_tx");
v15 = *(_QWORD *)a3;
if ( v8 < *(_QWORD *)a3 || v6 > v15 )
_assert_fail(
"(cec_oframe)->f_sta >= (cec_oframe)->f_buf && (cec_oframe)->f_sta <= (cec_oframe)->f_buf + COUNT_OF((cec_oframe)->f_buf)",
"p8_cec_tx.c",
0xB5u,
"p8_cec_tx");
if ( v14 < v15 )
_assert_fail("(cec_oframe)->f_sta <= (cec_oframe)->f_end", "p8_cec_tx.c", 0xB5u, "p8_cec_tx");
v16 = a4[1];
if ( (unsigned __int64)v11 < v16 || (unsigned __int64)v19 > v16 )
_assert_fail(
"(cec_iframe)->f_end >= (cec_iframe)->f_buf && (cec_iframe)->f_end <= (cec_iframe)->f_buf + COUNT_OF((cec_iframe)->f_buf)",
"p8_cec_tx.c",
0xB6u,
"p8_cec_tx");
v17 = *a4;
if ( (unsigned __int64)v11 < *a4 || (unsigned __int64)v19 > v17 )
_assert_fail(
"(cec_iframe)->f_sta >= (cec_iframe)->f_buf && (cec_iframe)->f_sta <= (cec_iframe)->f_buf + COUNT_OF((cec_iframe)->f_buf)",
"p8_cec_tx.c",
0xB6u,
"p8_cec_tx");
if ( v16 < v17 )
_assert_fail("(cec_iframe)->f_sta <= (cec_iframe)->f_end", "p8_cec_tx.c", 0xB6u, "p8_cec_tx");
}
return v20;
}

original_code:
int
p8_cec_tx(int fd, cec_signal_free_time_t idletime,
          cec_tx_frame_t *cec_oframe, cec_rx_frame_t *cec_iframe) {
    int ack_count = 0, nack_count = 0;
    ((void) sizeof (((cec_oframe)->f_end >= (cec_oframe)->f_buf && (cec_oframe)->f_end <= (cec_oframe)->f_buf + ((sizeof((cec_oframe)->f_buf)/sizeof(0[(cec_oframe)->f_buf])) / ((unsigned int)(!(sizeof((cec_oframe)->f_buf) % sizeof(0[(cec_oframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((cec_oframe)->f_end >= (cec_oframe)->f_buf && (cec_oframe)->f_end <= (cec_oframe)->f_buf + ((sizeof((cec_oframe)->f_buf)/sizeof(0[(cec_oframe)->f_buf])) / ((unsigned int)(!(sizeof((cec_oframe)->f_buf) % sizeof(0[(cec_oframe)->f_buf])))))) ; else __assert_fail ("(cec_oframe)->f_end >= (cec_oframe)->f_buf && (cec_oframe)->f_end <= (cec_oframe)->f_buf + COUNT_OF((cec_oframe)->f_buf)", "p8_cec_tx.c", 122, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((cec_oframe)->f_sta >= (cec_oframe)->f_buf && (cec_oframe)->f_sta <= (cec_oframe)->f_buf + ((sizeof((cec_oframe)->f_buf)/sizeof(0[(cec_oframe)->f_buf])) / ((unsigned int)(!(sizeof((cec_oframe)->f_buf) % sizeof(0[(cec_oframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((cec_oframe)->f_sta >= (cec_oframe)->f_buf && (cec_oframe)->f_sta <= (cec_oframe)->f_buf + ((sizeof((cec_oframe)->f_buf)/sizeof(0[(cec_oframe)->f_buf])) / ((unsigned int)(!(sizeof((cec_oframe)->f_buf) % sizeof(0[(cec_oframe)->f_buf])))))) ; else __assert_fail ("(cec_oframe)->f_sta >= (cec_oframe)->f_buf && (cec_oframe)->f_sta <= (cec_oframe)->f_buf + COUNT_OF((cec_oframe)->f_buf)", "p8_cec_tx.c", 122, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((cec_oframe)->f_sta <= (cec_oframe)->f_end) ? 1 : 0), __extension__ ({ if ((cec_oframe)->f_sta <= (cec_oframe)->f_end) ; else __assert_fail ("(cec_oframe)->f_sta <= (cec_oframe)->f_end", "p8_cec_tx.c", 122, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof (((cec_iframe)->f_end >= (cec_iframe)->f_buf && (cec_iframe)->f_end <= (cec_iframe)->f_buf + ((sizeof((cec_iframe)->f_buf)/sizeof(0[(cec_iframe)->f_buf])) / ((unsigned int)(!(sizeof((cec_iframe)->f_buf) % sizeof(0[(cec_iframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((cec_iframe)->f_end >= (cec_iframe)->f_buf && (cec_iframe)->f_end <= (cec_iframe)->f_buf + ((sizeof((cec_iframe)->f_buf)/sizeof(0[(cec_iframe)->f_buf])) / ((unsigned int)(!(sizeof((cec_iframe)->f_buf) % sizeof(0[(cec_iframe)->f_buf])))))) ; else __assert_fail ("(cec_iframe)->f_end >= (cec_iframe)->f_buf && (cec_iframe)->f_end <= (cec_iframe)->f_buf + COUNT_OF((cec_iframe)->f_buf)", "p8_cec_tx.c", 123, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((cec_iframe)->f_sta >= (cec_iframe)->f_buf && (cec_iframe)->f_sta <= (cec_iframe)->f_buf + ((sizeof((cec_iframe)->f_buf)/sizeof(0[(cec_iframe)->f_buf])) / ((unsigned int)(!(sizeof((cec_iframe)->f_buf) % sizeof(0[(cec_iframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((cec_iframe)->f_sta >= (cec_iframe)->f_buf && (cec_iframe)->f_sta <= (cec_iframe)->f_buf + ((sizeof((cec_iframe)->f_buf)/sizeof(0[(cec_iframe)->f_buf])) / ((unsigned int)(!(sizeof((cec_iframe)->f_buf) % sizeof(0[(cec_iframe)->f_buf])))))) ; else __assert_fail ("(cec_iframe)->f_sta >= (cec_iframe)->f_buf && (cec_iframe)->f_sta <= (cec_iframe)->f_buf + COUNT_OF((cec_iframe)->f_buf)", "p8_cec_tx.c", 123, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((cec_iframe)->f_sta <= (cec_iframe)->f_end) ? 1 : 0), __extension__ ({ if ((cec_iframe)->f_sta <= (cec_iframe)->f_end) ; else __assert_fail ("(cec_iframe)->f_sta <= (cec_iframe)->f_end", "p8_cec_tx.c", 123, __extension__ __PRETTY_FUNCTION__); }));
    p8_frame_t p8frame = {
        .f_sta = p8frame.f_buf,
        .f_end = p8frame.f_buf,
    };
    proto_callback_arg_t cba_table[((sizeof(p8_cec_tx_callbacks)/sizeof(0[p8_cec_tx_callbacks])) / ((unsigned int)(!(sizeof(p8_cec_tx_callbacks) % sizeof(0[p8_cec_tx_callbacks])))))] = {
        { .cba_int = 0 },
        { .cba_frame = cec_iframe },
        { .cba_frame = cec_iframe },
        { .cba_intp = &ack_count },
        { .cba_intp = &nack_count },
        { .cba_frame = cec_oframe },
        { .cba_frame = cec_oframe },
        { .cba_int = 0 },
    };
    {
        proto_char_t idle = idletime;
        p8_encode_cmd(&p8frame, P8_CMD_TX_SET_IDLE, &idle, 1);
        ack_count++;
        while (cec_oframe->f_sta < cec_oframe->f_end - 1) {
            p8_encode_tx(&p8frame, P8_CMD_TX, cec_oframe);
            ack_count++;
        }
        p8_encode_tx(&p8frame, P8_CMD_TX_EOM, cec_oframe);
        ack_count++;
        cec_oframe->f_status = CEC_TX_UNKNOWN;
        printf("CEC TX: Writing %ld bytes, waiting for %d acks\n", p8frame.f_end - p8frame.f_sta, ack_count);
        int rv = p8_write(fd, &p8frame, &p8_cec_tx_dt, cba_table);
        if (rv) {
            cec_tx_error(CEC_TX_ERROR, cec_oframe);
            return rv;
        }
    }
    {
        p8_frame_t p8frame = {
            .f_sta = p8frame.f_buf,
            .f_end = p8frame.f_buf,
        };
        while (nack_count == 0 && cec_oframe->f_status == CEC_TX_UNKNOWN) {
            printf("CEC TX: Processing input\n");
            p8_read_and_dispatch(fd, &p8frame, &p8_cec_tx_dt, cba_table);
        }
    }
    if (ack_count != 0 || nack_count != 0) {
        cec_tx_error(CEC_TX_ERROR, cec_oframe);
    }
    ((void) sizeof (((cec_oframe)->f_end >= (cec_oframe)->f_buf && (cec_oframe)->f_end <= (cec_oframe)->f_buf + ((sizeof((cec_oframe)->f_buf)/sizeof(0[(cec_oframe)->f_buf])) / ((unsigned int)(!(sizeof((cec_oframe)->f_buf) % sizeof(0[(cec_oframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((cec_oframe)->f_end >= (cec_oframe)->f_buf && (cec_oframe)->f_end <= (cec_oframe)->f_buf + ((sizeof((cec_oframe)->f_buf)/sizeof(0[(cec_oframe)->f_buf])) / ((unsigned int)(!(sizeof((cec_oframe)->f_buf) % sizeof(0[(cec_oframe)->f_buf])))))) ; else __assert_fail ("(cec_oframe)->f_end >= (cec_oframe)->f_buf && (cec_oframe)->f_end <= (cec_oframe)->f_buf + COUNT_OF((cec_oframe)->f_buf)", "p8_cec_tx.c", 181, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((cec_oframe)->f_sta >= (cec_oframe)->f_buf && (cec_oframe)->f_sta <= (cec_oframe)->f_buf + ((sizeof((cec_oframe)->f_buf)/sizeof(0[(cec_oframe)->f_buf])) / ((unsigned int)(!(sizeof((cec_oframe)->f_buf) % sizeof(0[(cec_oframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((cec_oframe)->f_sta >= (cec_oframe)->f_buf && (cec_oframe)->f_sta <= (cec_oframe)->f_buf + ((sizeof((cec_oframe)->f_buf)/sizeof(0[(cec_oframe)->f_buf])) / ((unsigned int)(!(sizeof((cec_oframe)->f_buf) % sizeof(0[(cec_oframe)->f_buf])))))) ; else __assert_fail ("(cec_oframe)->f_sta >= (cec_oframe)->f_buf && (cec_oframe)->f_sta <= (cec_oframe)->f_buf + COUNT_OF((cec_oframe)->f_buf)", "p8_cec_tx.c", 181, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((cec_oframe)->f_sta <= (cec_oframe)->f_end) ? 1 : 0), __extension__ ({ if ((cec_oframe)->f_sta <= (cec_oframe)->f_end) ; else __assert_fail ("(cec_oframe)->f_sta <= (cec_oframe)->f_end", "p8_cec_tx.c", 181, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof (((cec_iframe)->f_end >= (cec_iframe)->f_buf && (cec_iframe)->f_end <= (cec_iframe)->f_buf + ((sizeof((cec_iframe)->f_buf)/sizeof(0[(cec_iframe)->f_buf])) / ((unsigned int)(!(sizeof((cec_iframe)->f_buf) % sizeof(0[(cec_iframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((cec_iframe)->f_end >= (cec_iframe)->f_buf && (cec_iframe)->f_end <= (cec_iframe)->f_buf + ((sizeof((cec_iframe)->f_buf)/sizeof(0[(cec_iframe)->f_buf])) / ((unsigned int)(!(sizeof((cec_iframe)->f_buf) % sizeof(0[(cec_iframe)->f_buf])))))) ; else __assert_fail ("(cec_iframe)->f_end >= (cec_iframe)->f_buf && (cec_iframe)->f_end <= (cec_iframe)->f_buf + COUNT_OF((cec_iframe)->f_buf)", "p8_cec_tx.c", 182, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((cec_iframe)->f_sta >= (cec_iframe)->f_buf && (cec_iframe)->f_sta <= (cec_iframe)->f_buf + ((sizeof((cec_iframe)->f_buf)/sizeof(0[(cec_iframe)->f_buf])) / ((unsigned int)(!(sizeof((cec_iframe)->f_buf) % sizeof(0[(cec_iframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((cec_iframe)->f_sta >= (cec_iframe)->f_buf && (cec_iframe)->f_sta <= (cec_iframe)->f_buf + ((sizeof((cec_iframe)->f_buf)/sizeof(0[(cec_iframe)->f_buf])) / ((unsigned int)(!(sizeof((cec_iframe)->f_buf) % sizeof(0[(cec_iframe)->f_buf])))))) ; else __assert_fail ("(cec_iframe)->f_sta >= (cec_iframe)->f_buf && (cec_iframe)->f_sta <= (cec_iframe)->f_buf + COUNT_OF((cec_iframe)->f_buf)", "p8_cec_tx.c", 182, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((cec_iframe)->f_sta <= (cec_iframe)->f_end) ? 1 : 0), __extension__ ({ if ((cec_iframe)->f_sta <= (cec_iframe)->f_end) ; else __assert_fail ("(cec_iframe)->f_sta <= (cec_iframe)->f_end", "p8_cec_tx.c", 182, __extension__ __PRETTY_FUNCTION__); }));
    return 0;
}

canonical_original_code:
int p8_cec_tx(int fd, enum cec_signal_free_time idletime, struct proto_frame *cec_oframe, struct proto_frame *cec_iframe) {
    int ack_count = 0; int nack_count = 0;
    ((void) sizeof (((cec_oframe)->f_end >= (cec_oframe)->f_buf && (cec_oframe)->f_end <= (cec_oframe)->f_buf + ((sizeof((cec_oframe)->f_buf)/sizeof(0[(cec_oframe)->f_buf])) / ((unsigned int)(!(sizeof((cec_oframe)->f_buf) % sizeof(0[(cec_oframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((cec_oframe)->f_end >= (cec_oframe)->f_buf && (cec_oframe)->f_end <= (cec_oframe)->f_buf + ((sizeof((cec_oframe)->f_buf)/sizeof(0[(cec_oframe)->f_buf])) / ((unsigned int)(!(sizeof((cec_oframe)->f_buf) % sizeof(0[(cec_oframe)->f_buf])))))) ; else __assert_fail ("(cec_oframe)->f_end >= (cec_oframe)->f_buf && (cec_oframe)->f_end <= (cec_oframe)->f_buf + COUNT_OF((cec_oframe)->f_buf)", "p8_cec_tx.c", 122, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((cec_oframe)->f_sta >= (cec_oframe)->f_buf && (cec_oframe)->f_sta <= (cec_oframe)->f_buf + ((sizeof((cec_oframe)->f_buf)/sizeof(0[(cec_oframe)->f_buf])) / ((unsigned int)(!(sizeof((cec_oframe)->f_buf) % sizeof(0[(cec_oframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((cec_oframe)->f_sta >= (cec_oframe)->f_buf && (cec_oframe)->f_sta <= (cec_oframe)->f_buf + ((sizeof((cec_oframe)->f_buf)/sizeof(0[(cec_oframe)->f_buf])) / ((unsigned int)(!(sizeof((cec_oframe)->f_buf) % sizeof(0[(cec_oframe)->f_buf])))))) ; else __assert_fail ("(cec_oframe)->f_sta >= (cec_oframe)->f_buf && (cec_oframe)->f_sta <= (cec_oframe)->f_buf + COUNT_OF((cec_oframe)->f_buf)", "p8_cec_tx.c", 122, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((cec_oframe)->f_sta <= (cec_oframe)->f_end) ? 1 : 0), __extension__ ({ if ((cec_oframe)->f_sta <= (cec_oframe)->f_end) ; else __assert_fail ("(cec_oframe)->f_sta <= (cec_oframe)->f_end", "p8_cec_tx.c", 122, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof (((cec_iframe)->f_end >= (cec_iframe)->f_buf && (cec_iframe)->f_end <= (cec_iframe)->f_buf + ((sizeof((cec_iframe)->f_buf)/sizeof(0[(cec_iframe)->f_buf])) / ((unsigned int)(!(sizeof((cec_iframe)->f_buf) % sizeof(0[(cec_iframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((cec_iframe)->f_end >= (cec_iframe)->f_buf && (cec_iframe)->f_end <= (cec_iframe)->f_buf + ((sizeof((cec_iframe)->f_buf)/sizeof(0[(cec_iframe)->f_buf])) / ((unsigned int)(!(sizeof((cec_iframe)->f_buf) % sizeof(0[(cec_iframe)->f_buf])))))) ; else __assert_fail ("(cec_iframe)->f_end >= (cec_iframe)->f_buf && (cec_iframe)->f_end <= (cec_iframe)->f_buf + COUNT_OF((cec_iframe)->f_buf)", "p8_cec_tx.c", 123, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((cec_iframe)->f_sta >= (cec_iframe)->f_buf && (cec_iframe)->f_sta <= (cec_iframe)->f_buf + ((sizeof((cec_iframe)->f_buf)/sizeof(0[(cec_iframe)->f_buf])) / ((unsigned int)(!(sizeof((cec_iframe)->f_buf) % sizeof(0[(cec_iframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((cec_iframe)->f_sta >= (cec_iframe)->f_buf && (cec_iframe)->f_sta <= (cec_iframe)->f_buf + ((sizeof((cec_iframe)->f_buf)/sizeof(0[(cec_iframe)->f_buf])) / ((unsigned int)(!(sizeof((cec_iframe)->f_buf) % sizeof(0[(cec_iframe)->f_buf])))))) ; else __assert_fail ("(cec_iframe)->f_sta >= (cec_iframe)->f_buf && (cec_iframe)->f_sta <= (cec_iframe)->f_buf + COUNT_OF((cec_iframe)->f_buf)", "p8_cec_tx.c", 123, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((cec_iframe)->f_sta <= (cec_iframe)->f_end) ? 1 : 0), __extension__ ({ if ((cec_iframe)->f_sta <= (cec_iframe)->f_end) ; else __assert_fail ("(cec_iframe)->f_sta <= (cec_iframe)->f_end", "p8_cec_tx.c", 123, __extension__ __PRETTY_FUNCTION__); }));
    struct proto_frame p8frame = {
        .f_sta = p8frame.f_buf,
        .f_end = p8frame.f_buf,
    };
    union proto_callback_arg_t cba_table[-1] = {
        { .cba_int = 0 },
        { .cba_frame = cec_iframe },
        { .cba_frame = cec_iframe },
        { .cba_intp = &ack_count },
        { .cba_intp = &nack_count },
        { .cba_frame = cec_oframe },
        { .cba_frame = cec_oframe },
        { .cba_int = 0 },
    };
    {
        unsigned char idle = idletime;
        p8_encode_cmd(&p8frame, P8_CMD_TX_SET_IDLE, &idle, 1);
        ack_count++;
        while (cec_oframe->f_sta < cec_oframe->f_end - 1) {
            p8_encode_tx(&p8frame, P8_CMD_TX, cec_oframe);
            ack_count++;
        }
        p8_encode_tx(&p8frame, P8_CMD_TX_EOM, cec_oframe);
        ack_count++;
        cec_oframe->f_status = CEC_TX_UNKNOWN;
        printf("CEC TX: Writing %ld bytes, waiting for %d acks\n", p8frame.f_end - p8frame.f_sta, ack_count);
        int rv = p8_write(fd, &p8frame, &p8_cec_tx_dt, cba_table);
        if (rv) {
            cec_tx_error(CEC_TX_ERROR, cec_oframe);
            return rv;
        }
    }
    {
        struct proto_frame p8frame = {
            .f_sta = p8frame.f_buf,
            .f_end = p8frame.f_buf,
        };
        while (nack_count == 0 && cec_oframe->f_status == CEC_TX_UNKNOWN) {
            printf("CEC TX: Processing input\n");
            p8_read_and_dispatch(fd, &p8frame, &p8_cec_tx_dt, cba_table);
        }
    }
    if (ack_count != 0 || nack_count != 0) {
        cec_tx_error(CEC_TX_ERROR, cec_oframe);
    }
    ((void) sizeof (((cec_oframe)->f_end >= (cec_oframe)->f_buf && (cec_oframe)->f_end <= (cec_oframe)->f_buf + ((sizeof((cec_oframe)->f_buf)/sizeof(0[(cec_oframe)->f_buf])) / ((unsigned int)(!(sizeof((cec_oframe)->f_buf) % sizeof(0[(cec_oframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((cec_oframe)->f_end >= (cec_oframe)->f_buf && (cec_oframe)->f_end <= (cec_oframe)->f_buf + ((sizeof((cec_oframe)->f_buf)/sizeof(0[(cec_oframe)->f_buf])) / ((unsigned int)(!(sizeof((cec_oframe)->f_buf) % sizeof(0[(cec_oframe)->f_buf])))))) ; else __assert_fail ("(cec_oframe)->f_end >= (cec_oframe)->f_buf && (cec_oframe)->f_end <= (cec_oframe)->f_buf + COUNT_OF((cec_oframe)->f_buf)", "p8_cec_tx.c", 181, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((cec_oframe)->f_sta >= (cec_oframe)->f_buf && (cec_oframe)->f_sta <= (cec_oframe)->f_buf + ((sizeof((cec_oframe)->f_buf)/sizeof(0[(cec_oframe)->f_buf])) / ((unsigned int)(!(sizeof((cec_oframe)->f_buf) % sizeof(0[(cec_oframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((cec_oframe)->f_sta >= (cec_oframe)->f_buf && (cec_oframe)->f_sta <= (cec_oframe)->f_buf + ((sizeof((cec_oframe)->f_buf)/sizeof(0[(cec_oframe)->f_buf])) / ((unsigned int)(!(sizeof((cec_oframe)->f_buf) % sizeof(0[(cec_oframe)->f_buf])))))) ; else __assert_fail ("(cec_oframe)->f_sta >= (cec_oframe)->f_buf && (cec_oframe)->f_sta <= (cec_oframe)->f_buf + COUNT_OF((cec_oframe)->f_buf)", "p8_cec_tx.c", 181, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((cec_oframe)->f_sta <= (cec_oframe)->f_end) ? 1 : 0), __extension__ ({ if ((cec_oframe)->f_sta <= (cec_oframe)->f_end) ; else __assert_fail ("(cec_oframe)->f_sta <= (cec_oframe)->f_end", "p8_cec_tx.c", 181, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof (((cec_iframe)->f_end >= (cec_iframe)->f_buf && (cec_iframe)->f_end <= (cec_iframe)->f_buf + ((sizeof((cec_iframe)->f_buf)/sizeof(0[(cec_iframe)->f_buf])) / ((unsigned int)(!(sizeof((cec_iframe)->f_buf) % sizeof(0[(cec_iframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((cec_iframe)->f_end >= (cec_iframe)->f_buf && (cec_iframe)->f_end <= (cec_iframe)->f_buf + ((sizeof((cec_iframe)->f_buf)/sizeof(0[(cec_iframe)->f_buf])) / ((unsigned int)(!(sizeof((cec_iframe)->f_buf) % sizeof(0[(cec_iframe)->f_buf])))))) ; else __assert_fail ("(cec_iframe)->f_end >= (cec_iframe)->f_buf && (cec_iframe)->f_end <= (cec_iframe)->f_buf + COUNT_OF((cec_iframe)->f_buf)", "p8_cec_tx.c", 182, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((cec_iframe)->f_sta >= (cec_iframe)->f_buf && (cec_iframe)->f_sta <= (cec_iframe)->f_buf + ((sizeof((cec_iframe)->f_buf)/sizeof(0[(cec_iframe)->f_buf])) / ((unsigned int)(!(sizeof((cec_iframe)->f_buf) % sizeof(0[(cec_iframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((cec_iframe)->f_sta >= (cec_iframe)->f_buf && (cec_iframe)->f_sta <= (cec_iframe)->f_buf + ((sizeof((cec_iframe)->f_buf)/sizeof(0[(cec_iframe)->f_buf])) / ((unsigned int)(!(sizeof((cec_iframe)->f_buf) % sizeof(0[(cec_iframe)->f_buf])))))) ; else __assert_fail ("(cec_iframe)->f_sta >= (cec_iframe)->f_buf && (cec_iframe)->f_sta <= (cec_iframe)->f_buf + COUNT_OF((cec_iframe)->f_buf)", "p8_cec_tx.c", 182, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((cec_iframe)->f_sta <= (cec_iframe)->f_end) ? 1 : 0), __extension__ ({ if ((cec_iframe)->f_sta <= (cec_iframe)->f_end) ; else __assert_fail ("(cec_iframe)->f_sta <= (cec_iframe)->f_end", "p8_cec_tx.c", 182, __extension__ __PRETTY_FUNCTION__); }));
    return 0;
}

variable_types: enum cec_signal_free_time { CEC_SIGNAL_FREE_LARGE=7, CEC_SIGNAL_FREE_NEW=5, CEC_SIGNAL_FREE_RETRY=3 }

variable_types:
idle
unsigned char


repo: pekkanikander/MacCEC

decompiled_code:
__int64 __fastcall proto_dispatch(unsigned __int8 a1, unsigned __int64 *a2, __int64 a3, __int64 a4)
{
unsigned __int64 v5; // rax
char *v6; // rcx
_QWORD *v9; // rsi
unsigned __int64 v10; // rdx
unsigned __int8 v11; // r14

v5 = a2[1];
v6 = (char *)a2 + 20;
if ( v5 < (unsigned __int64)a2 + 20 || (v9 = a2 + 16, v5 > (unsigned __int64)v9) )
_assert_fail(
"(frame)->f_end >= (frame)->f_buf && (frame)->f_end <= (frame)->f_buf + COUNT_OF((frame)->f_buf)",
"proto_dispatch.c",
0x1Cu,
"proto_dispatch");
v10 = *a2;
if ( (unsigned __int64)v9 < *a2 || (unsigned __int64)v6 > v10 )
_assert_fail(
"(frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + COUNT_OF((frame)->f_buf)",
"proto_dispatch.c",
0x1Cu,
"proto_dispatch");
if ( v5 < v10 )
_assert_fail("(frame)->f_sta <= (frame)->f_end", "proto_dispatch.c", 0x1Cu, "proto_dispatch");
v11 = *(_BYTE *)(a3 + a1 + 1);
if ( *(_BYTE *)a3 <= v11 )
(*(void (__fastcall **)(_QWORD, unsigned __int64 *, _QWORD))(a3 + 264))(a1, a2, *(_QWORD *)(a4 + 8LL * v11));
return (*(__int64 (__fastcall **)(_QWORD, unsigned __int64 *, _QWORD))(*(_QWORD *)(a3 + 272) + 8LL * v11))(
a1,
a2,
*(_QWORD *)(a4 + 8LL * v11));
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 a1, unsigned __int64 *a2, __int64 a3, __int64 a4)
{
unsigned __int64 v5; // rax
char *v6; // rcx
_QWORD *v9; // rsi
unsigned __int64 v10; // rdx
unsigned __int8 v11; // r14

v5 = a2[1];
v6 = (char *)a2 + 20;
if ( v5 < (unsigned __int64)a2 + 20 || (v9 = a2 + 16, v5 > (unsigned __int64)v9) )
_assert_fail(
"(frame)->f_end >= (frame)->f_buf && (frame)->f_end <= (frame)->f_buf + COUNT_OF((frame)->f_buf)",
"proto_dispatch.c",
0x1Cu,
"proto_dispatch");
v10 = *a2;
if ( (unsigned __int64)v9 < *a2 || (unsigned __int64)v6 > v10 )
_assert_fail(
"(frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + COUNT_OF((frame)->f_buf)",
"proto_dispatch.c",
0x1Cu,
"proto_dispatch");
if ( v5 < v10 )
_assert_fail("(frame)->f_sta <= (frame)->f_end", "proto_dispatch.c", 0x1Cu, "proto_dispatch");
v11 = *(_BYTE *)(a3 + a1 + 1);
if ( *(_BYTE *)a3 <= v11 )
(*(void (__fastcall **)(_QWORD, unsigned __int64 *, _QWORD))(a3 + 264))(a1, a2, *(_QWORD *)(a4 + 8LL * v11));
return (*(__int64 (__fastcall **)(_QWORD, unsigned __int64 *, _QWORD))(*(_QWORD *)(a3 + 272) + 8LL * v11))(
a1,
a2,
*(_QWORD *)(a4 + 8LL * v11));
}

original_code:
int
proto_dispatch(const proto_char_t code,
               const proto_frame_t *frame,
               const proto_dispatch_table_t *dt,
               proto_callback_arg_t *cba_table) {
    ((void) sizeof (((frame)->f_end >= (frame)->f_buf && (frame)->f_end <= (frame)->f_buf + ((sizeof((frame)->f_buf)/sizeof(0[(frame)->f_buf])) / ((unsigned int)(!(sizeof((frame)->f_buf) % sizeof(0[(frame)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((frame)->f_end >= (frame)->f_buf && (frame)->f_end <= (frame)->f_buf + ((sizeof((frame)->f_buf)/sizeof(0[(frame)->f_buf])) / ((unsigned int)(!(sizeof((frame)->f_buf) % sizeof(0[(frame)->f_buf])))))) ; else __assert_fail ("(frame)->f_end >= (frame)->f_buf && (frame)->f_end <= (frame)->f_buf + COUNT_OF((frame)->f_buf)", "proto_dispatch.c", 28, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + ((sizeof((frame)->f_buf)/sizeof(0[(frame)->f_buf])) / ((unsigned int)(!(sizeof((frame)->f_buf) % sizeof(0[(frame)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + ((sizeof((frame)->f_buf)/sizeof(0[(frame)->f_buf])) / ((unsigned int)(!(sizeof((frame)->f_buf) % sizeof(0[(frame)->f_buf])))))) ; else __assert_fail ("(frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + COUNT_OF((frame)->f_buf)", "proto_dispatch.c", 28, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((frame)->f_sta <= (frame)->f_end) ? 1 : 0), __extension__ ({ if ((frame)->f_sta <= (frame)->f_end) ; else __assert_fail ("(frame)->f_sta <= (frame)->f_end", "proto_dispatch.c", 28, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((sizeof(*frame) == 128) ? 1 : 0), __extension__ ({ if (sizeof(*frame) == 128) ; else __assert_fail ("sizeof(*frame) == PROTO_FRAME_SIZE", "proto_dispatch.c", 31, __extension__ __PRETTY_FUNCTION__); }));
    proto_dispatch_index_t index = dt->dt_indices[code];
    if (index >= dt->dt_number) {
        dt->dt_error(code, frame, cba_table[index]);
    }
    return dt->dt_callbacks[index](code, frame, cba_table[index]);
}

canonical_original_code:
int proto_dispatch(unsigned char code, struct proto_frame *frame, struct proto_dispatch_table *dt, union proto_callback_arg_t *cba_table) {
    ((void) sizeof (((frame)->f_end >= (frame)->f_buf && (frame)->f_end <= (frame)->f_buf + ((sizeof((frame)->f_buf)/sizeof(0[(frame)->f_buf])) / ((unsigned int)(!(sizeof((frame)->f_buf) % sizeof(0[(frame)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((frame)->f_end >= (frame)->f_buf && (frame)->f_end <= (frame)->f_buf + ((sizeof((frame)->f_buf)/sizeof(0[(frame)->f_buf])) / ((unsigned int)(!(sizeof((frame)->f_buf) % sizeof(0[(frame)->f_buf])))))) ; else __assert_fail ("(frame)->f_end >= (frame)->f_buf && (frame)->f_end <= (frame)->f_buf + COUNT_OF((frame)->f_buf)", "proto_dispatch.c", 28, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + ((sizeof((frame)->f_buf)/sizeof(0[(frame)->f_buf])) / ((unsigned int)(!(sizeof((frame)->f_buf) % sizeof(0[(frame)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + ((sizeof((frame)->f_buf)/sizeof(0[(frame)->f_buf])) / ((unsigned int)(!(sizeof((frame)->f_buf) % sizeof(0[(frame)->f_buf])))))) ; else __assert_fail ("(frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + COUNT_OF((frame)->f_buf)", "proto_dispatch.c", 28, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((frame)->f_sta <= (frame)->f_end) ? 1 : 0), __extension__ ({ if ((frame)->f_sta <= (frame)->f_end) ; else __assert_fail ("(frame)->f_sta <= (frame)->f_end", "proto_dispatch.c", 28, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((sizeof(*frame) == 128) ? 1 : 0), __extension__ ({ if (sizeof(*frame) == 128) ; else __assert_fail ("sizeof(*frame) == PROTO_FRAME_SIZE", "proto_dispatch.c", 31, __extension__ __PRETTY_FUNCTION__); }));
    unsigned char index = dt->dt_indices[code];
    if (index >= dt->dt_number) {
        dt->dt_error(code, frame, cba_table[index]);
    }
    return dt->dt_callbacks[index](code, frame, cba_table[index]);
}

variable_types:
code
unsigned char

variable_types: struct proto_frame { unsigned char *f_sta; unsigned char *f_end; int f_status; unsigned char f_buf[-1]; } *

variable_types: struct proto_dispatch_table { unsigned char dt_number; unsigned char dt_indices[256]; int (*dt_error)(unsigned char code, struct proto_frame *frame, union proto_callback_arg_t { int cba_int; int *cba_intp; struct proto_frame *cba_frame; } cb_arg); int (**dt_callbacks)(unsigned char code, struct proto_frame *frame, union proto_callback_arg_t cb_arg); } *

variable_types:
index
unsigned char

return_type: int

user_defined_types: struct proto_dispatch_table { unsigned char dt_number; unsigned char dt_indices[256]; int (*dt_error)(unsigned char code, struct proto_frame *frame, union proto_callback_arg_t cb_arg); int (**dt_callbacks)(unsigned char code, struct proto_frame *frame, union proto_callback_arg_t cb_arg); }


decompiled_code:
__int64 __fastcall p8_error(unsigned __int8 a1, unsigned __int8 **a2, const void *a3)
{
unsigned __int64 v4; // rcx
char *v5; // rdx
unsigned __int8 *v7; // rsi
unsigned __int8 *v8; // rax
__int64 v9; // rcx
unsigned __int8 *i; // rbx

v4 = (unsigned __int64)a2[1];
v5 = (char *)a2 + 20;
if ( v4 < (unsigned __int64)a2 + 20 || (v7 = (unsigned __int8 *)(a2 + 16), v4 > (unsigned __int64)v7) )
_assert_fail(
"(frame)->f_end >= (frame)->f_buf && (frame)->f_end <= (frame)->f_buf + COUNT_OF((frame)->f_buf)",
"p8_error.c",
0x17u,
"p8_error");
v8 = *a2;
if ( v7 < *a2 || v5 > (char *)v8 )
_assert_fail(
"(frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + COUNT_OF((frame)->f_buf)",
"p8_error.c",
0x17u,
"p8_error");
if ( v4 < (unsigned __int64)v8 )
_assert_fail("(frame)->f_sta <= (frame)->f_end", "p8_error.c", 0x17u, "p8_error");
if ( (unsigned int)a1 >= P8_CODE_TYPE_COUNT )
_assert_fail("(code) < P8_CODE_TYPE_COUNT", "p8_error.c", 0x18u, "p8_error");
if ( (*((_BYTE *)&p8_code_types + 5 * a1) & 2) == 0 )
_assert_fail("p8_code_types[(code)].ct_type & P8_CT_A2H", "p8_error.c", 0x18u, "p8_error");
v9 = v4 - (_QWORD)v8;
if ( v9 < *((unsigned __int8 *)&p8_code_types + 5 * a1 + 3) )
_assert_fail(
"((frame)->f_end - (frame)->f_sta) >= p8_code_types[(code)].ct_a2h_min_plen",
"p8_error.c",
0x18u,
"p8_error");
if ( v9 > *((unsigned __int8 *)&p8_code_types + 5 * a1 + 4) )
_assert_fail(
"((frame)->f_end - (frame)->f_sta) <= p8_code_types[(code)].ct_a2h_max_plen",
"p8_error.c",
0x18u,
"p8_error");
fprintf(stderr, "P8 PROTOCOL ERROR: code=0x%02.2x, param_len=%ld", a1, v9);
for ( i = *a2; a2[1] > i; ++i )
fprintf(stderr, ", 0x%02.2x", *i);
fprintf(stderr, "; cb_arg=0x%p\n", a3);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 a1, unsigned __int8 **a2, const void *a3)
{
unsigned __int64 v4; // rcx
char *v5; // rdx
unsigned __int8 *v7; // rsi
unsigned __int8 *v8; // rax
__int64 v9; // rcx
unsigned __int8 *i; // rbx

v4 = (unsigned __int64)a2[1];
v5 = (char *)a2 + 20;
if ( v4 < (unsigned __int64)a2 + 20 || (v7 = (unsigned __int8 *)(a2 + 16), v4 > (unsigned __int64)v7) )
_assert_fail(
"(frame)->f_end >= (frame)->f_buf && (frame)->f_end <= (frame)->f_buf + COUNT_OF((frame)->f_buf)",
"p8_error.c",
0x17u,
"p8_error");
v8 = *a2;
if ( v7 < *a2 || v5 > (char *)v8 )
_assert_fail(
"(frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + COUNT_OF((frame)->f_buf)",
"p8_error.c",
0x17u,
"p8_error");
if ( v4 < (unsigned __int64)v8 )
_assert_fail("(frame)->f_sta <= (frame)->f_end", "p8_error.c", 0x17u, "p8_error");
if ( (unsigned int)a1 >= P8_CODE_TYPE_COUNT )
_assert_fail("(code) < P8_CODE_TYPE_COUNT", "p8_error.c", 0x18u, "p8_error");
if ( (*((_BYTE *)&p8_code_types + 5 * a1) & 2) == 0 )
_assert_fail("p8_code_types[(code)].ct_type & P8_CT_A2H", "p8_error.c", 0x18u, "p8_error");
v9 = v4 - (_QWORD)v8;
if ( v9 < *((unsigned __int8 *)&p8_code_types + 5 * a1 + 3) )
_assert_fail(
"((frame)->f_end - (frame)->f_sta) >= p8_code_types[(code)].ct_a2h_min_plen",
"p8_error.c",
0x18u,
"p8_error");
if ( v9 > *((unsigned __int8 *)&p8_code_types + 5 * a1 + 4) )
_assert_fail(
"((frame)->f_end - (frame)->f_sta) <= p8_code_types[(code)].ct_a2h_max_plen",
"p8_error.c",
0x18u,
"p8_error");
fprintf(stderr, "P8 PROTOCOL ERROR: code=0x%02.2x, param_len=%ld", a1, v9);
for ( i = *a2; a2[1] > i; ++i )
fprintf(stderr, ", 0x%02.2x", *i);
fprintf(stderr, "; cb_arg=0x%p\n", a3);
return 0xFFFFFFFFLL;
}

original_code:
extern int
p8_error(proto_char_t code,
         const p8_frame_t *frame,
         proto_callback_arg_t cb_arg) {
    ((void) sizeof (((frame)->f_end >= (frame)->f_buf && (frame)->f_end <= (frame)->f_buf + ((sizeof((frame)->f_buf)/sizeof(0[(frame)->f_buf])) / ((unsigned int)(!(sizeof((frame)->f_buf) % sizeof(0[(frame)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((frame)->f_end >= (frame)->f_buf && (frame)->f_end <= (frame)->f_buf + ((sizeof((frame)->f_buf)/sizeof(0[(frame)->f_buf])) / ((unsigned int)(!(sizeof((frame)->f_buf) % sizeof(0[(frame)->f_buf])))))) ; else __assert_fail ("(frame)->f_end >= (frame)->f_buf && (frame)->f_end <= (frame)->f_buf + COUNT_OF((frame)->f_buf)", "p8_error.c", 23, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + ((sizeof((frame)->f_buf)/sizeof(0[(frame)->f_buf])) / ((unsigned int)(!(sizeof((frame)->f_buf) % sizeof(0[(frame)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + ((sizeof((frame)->f_buf)/sizeof(0[(frame)->f_buf])) / ((unsigned int)(!(sizeof((frame)->f_buf) % sizeof(0[(frame)->f_buf])))))) ; else __assert_fail ("(frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + COUNT_OF((frame)->f_buf)", "p8_error.c", 23, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((frame)->f_sta <= (frame)->f_end) ? 1 : 0), __extension__ ({ if ((frame)->f_sta <= (frame)->f_end) ; else __assert_fail ("(frame)->f_sta <= (frame)->f_end", "p8_error.c", 23, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof (((code) < P8_CODE_TYPE_COUNT) ? 1 : 0), __extension__ ({ if ((code) < P8_CODE_TYPE_COUNT) ; else __assert_fail ("(code) < P8_CODE_TYPE_COUNT", "p8_error.c", 24, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof ((p8_code_types[(code)].ct_type & 0x02) ? 1 : 0), __extension__ ({ if (p8_code_types[(code)].ct_type & 0x02) ; else __assert_fail ("p8_code_types[(code)].ct_type & P8_CT_A2H", "p8_error.c", 24, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof ((((frame)->f_end - (frame)->f_sta) >= p8_code_types[(code)].ct_a2h_min_plen) ? 1 : 0), __extension__ ({ if (((frame)->f_end - (frame)->f_sta) >= p8_code_types[(code)].ct_a2h_min_plen) ; else __assert_fail ("((frame)->f_end - (frame)->f_sta) >= p8_code_types[(code)].ct_a2h_min_plen", "p8_error.c", 24, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof ((((frame)->f_end - (frame)->f_sta) <= p8_code_types[(code)].ct_a2h_max_plen) ? 1 : 0), __extension__ ({ if (((frame)->f_end - (frame)->f_sta) <= p8_code_types[(code)].ct_a2h_max_plen) ; else __assert_fail ("((frame)->f_end - (frame)->f_sta) <= p8_code_types[(code)].ct_a2h_max_plen", "p8_error.c", 24, __extension__ __PRETTY_FUNCTION__); }));
    fprintf(stderr, "P8 PROTOCOL ERROR: code=0x%02.2x, param_len=%ld", code, frame->f_end - frame->f_sta);
    for (proto_char_t *p = frame->f_sta; p < frame->f_end; p++)
        fprintf(stderr, ", 0x%02.2x", *p);
    fprintf(stderr, "; cb_arg=0x%p\n", cb_arg.cba_intp);
    return -1;
}

canonical_original_code:
extern int p8_error(unsigned char code, struct proto_frame *frame, union proto_callback_arg_t cb_arg) {
    ((void) sizeof (((frame)->f_end >= (frame)->f_buf && (frame)->f_end <= (frame)->f_buf + ((sizeof((frame)->f_buf)/sizeof(0[(frame)->f_buf])) / ((unsigned int)(!(sizeof((frame)->f_buf) % sizeof(0[(frame)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((frame)->f_end >= (frame)->f_buf && (frame)->f_end <= (frame)->f_buf + ((sizeof((frame)->f_buf)/sizeof(0[(frame)->f_buf])) / ((unsigned int)(!(sizeof((frame)->f_buf) % sizeof(0[(frame)->f_buf])))))) ; else __assert_fail ("(frame)->f_end >= (frame)->f_buf && (frame)->f_end <= (frame)->f_buf + COUNT_OF((frame)->f_buf)", "p8_error.c", 23, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + ((sizeof((frame)->f_buf)/sizeof(0[(frame)->f_buf])) / ((unsigned int)(!(sizeof((frame)->f_buf) % sizeof(0[(frame)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + ((sizeof((frame)->f_buf)/sizeof(0[(frame)->f_buf])) / ((unsigned int)(!(sizeof((frame)->f_buf) % sizeof(0[(frame)->f_buf])))))) ; else __assert_fail ("(frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + COUNT_OF((frame)->f_buf)", "p8_error.c", 23, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((frame)->f_sta <= (frame)->f_end) ? 1 : 0), __extension__ ({ if ((frame)->f_sta <= (frame)->f_end) ; else __assert_fail ("(frame)->f_sta <= (frame)->f_end", "p8_error.c", 23, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof (((code) < P8_CODE_TYPE_COUNT) ? 1 : 0), __extension__ ({ if ((code) < P8_CODE_TYPE_COUNT) ; else __assert_fail ("(code) < P8_CODE_TYPE_COUNT", "p8_error.c", 24, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof ((p8_code_types[(code)].ct_type & 0x02) ? 1 : 0), __extension__ ({ if (p8_code_types[(code)].ct_type & 0x02) ; else __assert_fail ("p8_code_types[(code)].ct_type & P8_CT_A2H", "p8_error.c", 24, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof ((((frame)->f_end - (frame)->f_sta) >= p8_code_types[(code)].ct_a2h_min_plen) ? 1 : 0), __extension__ ({ if (((frame)->f_end - (frame)->f_sta) >= p8_code_types[(code)].ct_a2h_min_plen) ; else __assert_fail ("((frame)->f_end - (frame)->f_sta) >= p8_code_types[(code)].ct_a2h_min_plen", "p8_error.c", 24, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof ((((frame)->f_end - (frame)->f_sta) <= p8_code_types[(code)].ct_a2h_max_plen) ? 1 : 0), __extension__ ({ if (((frame)->f_end - (frame)->f_sta) <= p8_code_types[(code)].ct_a2h_max_plen) ; else __assert_fail ("((frame)->f_end - (frame)->f_sta) <= p8_code_types[(code)].ct_a2h_max_plen", "p8_error.c", 24, __extension__ __PRETTY_FUNCTION__); }));
    fprintf(stderr, "P8 PROTOCOL ERROR: code=0x%02.2x, param_len=%ld", code, frame->f_end - frame->f_sta);
    for (unsigned char *p = frame->f_sta; p < frame->f_end; p++)
        fprintf(stderr, ", 0x%02.2x", *p);
    fprintf(stderr, "; cb_arg=0x%p\n", cb_arg.cba_intp);
    return -1;
}

variable_types: union proto_callback_arg_t { int cba_int; int *cba_intp; struct proto_frame *cba_frame; }

variable_types:
p
unsigned char *

user_defined_types: struct proto_frame { unsigned char *f_sta; unsigned char *f_end; int f_status; unsigned char f_buf[-1]; }


decompiled_code:
__int64 __fastcall p8_frame_error(unsigned int a1, unsigned __int8 **a2)
{
unsigned __int64 v3; // rcx
char *v4; // rsi
unsigned __int8 *v5; // rax
unsigned __int8 *i; // rbx

v3 = (unsigned __int64)a2[1];
v4 = (char *)a2 + 20;
if ( v3 < (unsigned __int64)v4 || v3 > (unsigned __int64)(a2 + 16) )
_assert_fail(
"(frame)->f_end >= (frame)->f_buf && (frame)->f_end <= (frame)->f_buf + COUNT_OF((frame)->f_buf)",
"p8_frame_error.c",
0x1Cu,
"p8_frame_error");
v5 = *a2;
if ( a2 + 16 < (unsigned __int8 **)*a2 || v4 > (char *)v5 )
_assert_fail(
"(frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + COUNT_OF((frame)->f_buf)",
"p8_frame_error.c",
0x1Cu,
"p8_frame_error");
if ( v3 < (unsigned __int64)v5 )
_assert_fail("(frame)->f_sta <= (frame)->f_end", "p8_frame_error.c", 0x1Cu, "p8_frame_error");
fprintf(stderr, "P8 frame error: type=%d, len=%ld:", a1, v3 - (_QWORD)v5);
for ( i = *a2; a2[1] > i; ++i )
fprintf(stderr, " 0x%02.2x", *i);
fputc(10, stderr);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, unsigned __int8 **a2)
{
unsigned __int64 v3; // rcx
char *v4; // rsi
unsigned __int8 *v5; // rax
unsigned __int8 *i; // rbx

v3 = (unsigned __int64)a2[1];
v4 = (char *)a2 + 20;
if ( v3 < (unsigned __int64)v4 || v3 > (unsigned __int64)(a2 + 16) )
_assert_fail(
"(frame)->f_end >= (frame)->f_buf && (frame)->f_end <= (frame)->f_buf + COUNT_OF((frame)->f_buf)",
"p8_frame_error.c",
0x1Cu,
"p8_frame_error");
v5 = *a2;
if ( a2 + 16 < (unsigned __int8 **)*a2 || v4 > (char *)v5 )
_assert_fail(
"(frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + COUNT_OF((frame)->f_buf)",
"p8_frame_error.c",
0x1Cu,
"p8_frame_error");
if ( v3 < (unsigned __int64)v5 )
_assert_fail("(frame)->f_sta <= (frame)->f_end", "p8_frame_error.c", 0x1Cu, "p8_frame_error");
fprintf(stderr, "P8 frame error: type=%d, len=%ld:", a1, v3 - (_QWORD)v5);
for ( i = *a2; a2[1] > i; ++i )
fprintf(stderr, " 0x%02.2x", *i);
fputc(10, stderr);
return 0xFFFFFFFFLL;
}

original_code:
int
p8_frame_error(enum p8_frame_error type, const p8_frame_t *frame) {
    ((void) sizeof (((frame)->f_end >= (frame)->f_buf && (frame)->f_end <= (frame)->f_buf + ((sizeof((frame)->f_buf)/sizeof(0[(frame)->f_buf])) / ((unsigned int)(!(sizeof((frame)->f_buf) % sizeof(0[(frame)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((frame)->f_end >= (frame)->f_buf && (frame)->f_end <= (frame)->f_buf + ((sizeof((frame)->f_buf)/sizeof(0[(frame)->f_buf])) / ((unsigned int)(!(sizeof((frame)->f_buf) % sizeof(0[(frame)->f_buf])))))) ; else __assert_fail ("(frame)->f_end >= (frame)->f_buf && (frame)->f_end <= (frame)->f_buf + COUNT_OF((frame)->f_buf)", "p8_frame_error.c", 28, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + ((sizeof((frame)->f_buf)/sizeof(0[(frame)->f_buf])) / ((unsigned int)(!(sizeof((frame)->f_buf) % sizeof(0[(frame)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + ((sizeof((frame)->f_buf)/sizeof(0[(frame)->f_buf])) / ((unsigned int)(!(sizeof((frame)->f_buf) % sizeof(0[(frame)->f_buf])))))) ; else __assert_fail ("(frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + COUNT_OF((frame)->f_buf)", "p8_frame_error.c", 28, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((frame)->f_sta <= (frame)->f_end) ? 1 : 0), __extension__ ({ if ((frame)->f_sta <= (frame)->f_end) ; else __assert_fail ("(frame)->f_sta <= (frame)->f_end", "p8_frame_error.c", 28, __extension__ __PRETTY_FUNCTION__); }));
    fprintf(stderr, "P8 frame error: type=%d, len=%ld:", type,
            frame->f_end - frame->f_sta);
    for (proto_char_t *p = frame->f_sta; p < frame->f_end; p++) {
        fprintf(stderr, " 0x%02.2x", *p);
    }
    fprintf(stderr, "\n");
    return -1;
}

canonical_original_code:
int p8_frame_error(enum p8_frame_error type, struct proto_frame *frame) {
    ((void) sizeof (((frame)->f_end >= (frame)->f_buf && (frame)->f_end <= (frame)->f_buf + ((sizeof((frame)->f_buf)/sizeof(0[(frame)->f_buf])) / ((unsigned int)(!(sizeof((frame)->f_buf) % sizeof(0[(frame)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((frame)->f_end >= (frame)->f_buf && (frame)->f_end <= (frame)->f_buf + ((sizeof((frame)->f_buf)/sizeof(0[(frame)->f_buf])) / ((unsigned int)(!(sizeof((frame)->f_buf) % sizeof(0[(frame)->f_buf])))))) ; else __assert_fail ("(frame)->f_end >= (frame)->f_buf && (frame)->f_end <= (frame)->f_buf + COUNT_OF((frame)->f_buf)", "p8_frame_error.c", 28, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + ((sizeof((frame)->f_buf)/sizeof(0[(frame)->f_buf])) / ((unsigned int)(!(sizeof((frame)->f_buf) % sizeof(0[(frame)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + ((sizeof((frame)->f_buf)/sizeof(0[(frame)->f_buf])) / ((unsigned int)(!(sizeof((frame)->f_buf) % sizeof(0[(frame)->f_buf])))))) ; else __assert_fail ("(frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + COUNT_OF((frame)->f_buf)", "p8_frame_error.c", 28, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((frame)->f_sta <= (frame)->f_end) ? 1 : 0), __extension__ ({ if ((frame)->f_sta <= (frame)->f_end) ; else __assert_fail ("(frame)->f_sta <= (frame)->f_end", "p8_frame_error.c", 28, __extension__ __PRETTY_FUNCTION__); }));
    fprintf(stderr, "P8 frame error: type=%d, len=%ld:", type,
            frame->f_end - frame->f_sta);
    for (unsigned char *p = frame->f_sta; p < frame->f_end; p++) {
        fprintf(stderr, " 0x%02.2x", *p);
    }
    fprintf(stderr, "\n");
    return -1;
}

variable_types: enum p8_frame_error { P8_ERROR_FRAME_INCOMPLETE=0, P8_ERROR_FRAME_BEGIN_MISSING=1, P8_ERROR_SPURIOUS_START=2, P8_ERROR_FRAME_MALFORMED=3 }


disasm

repo: pelrun/Dispel

decompiled_code:
__int64 __fastcall disasm(unsigned __int8 *a1, int a2, _BYTE *a3, char *a4, char a5)
{
unsigned __int8 v6; // al
unsigned __int8 v7; // cl
__int16 v8; // ax
unsigned int v9; // er15
int v10; // eax
unsigned __int8 *v11; // rbx
char *v12; // rbp
__int64 v13; // rax
char v16[9]; // [rsp+17h] [rbp-61h] BYREF
char s[2]; // [rsp+20h] [rbp-58h] BYREF
char v18[61]; // [rsp+3Bh] [rbp-3Dh] BYREF

v6 = *a1;
switch ( *a1 )
{
case 0u:
strcpy(v18, "brk");
goto LABEL_24;
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:
strcpy(v18, "ora");
goto LABEL_3;
case 2u:
strcpy(v18, "cop");
goto LABEL_24;
case 4u:
case 0xCu:
strcpy(v18, "tsb");
goto LABEL_3;
case 6u:
case 0xAu:
case 0xEu:
case 0x16u:
case 0x1Eu:
strcpy(v18, "asl");
goto LABEL_3;
case 8u:
strcpy(v18, "php");
goto LABEL_26;
case 0xBu:
strcpy(v18, "phd");
goto LABEL_26;
case 0x10u:
strcpy(v18, "bpl");
goto LABEL_7;
case 0x14u:
case 0x1Cu:
strcpy(v18, "trb");
goto LABEL_3;
case 0x18u:
strcpy(v18, "clc");
goto LABEL_26;
case 0x1Au:
case 0xE6u:
case 0xEEu:
case 0xF6u:
case 0xFEu:
strcpy(v18, "inc");
goto LABEL_3;
case 0x1Bu:
strcpy(v18, "tcs");
goto LABEL_26;
case 0x20u:
case 0x22u:
case 0xFCu:
strcpy(v18, "jsr");
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:
strcpy(v18, "and");
goto LABEL_3;
case 0x24u:
case 0x2Cu:
case 0x34u:
case 0x3Cu:
case 0x89u:
strcpy(v18, "bit");
goto LABEL_3;
case 0x26u:
case 0x2Au:
case 0x2Eu:
case 0x36u:
case 0x3Eu:
strcpy(v18, "rol");
goto LABEL_3;
case 0x28u:
strcpy(v18, "plp");
goto LABEL_26;
case 0x2Bu:
strcpy(v18, "pld");
goto LABEL_26;
case 0x30u:
strcpy(v18, "bmi");
goto LABEL_7;
case 0x38u:
strcpy(v18, "sec");
goto LABEL_26;
case 0x3Au:
case 0xC6u:
case 0xCEu:
case 0xD6u:
case 0xDEu:
strcpy(v18, "dec");
goto LABEL_3;
case 0x3Bu:
strcpy(v18, "tsc");
goto LABEL_26;
case 0x40u:
strcpy(v18, "rti");
if ( (a5 & 2) != 0 )
goto LABEL_81;
goto LABEL_26;
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:
strcpy(v18, "eor");
goto LABEL_3;
case 0x42u:
strcpy(v18, "wdm");
LABEL_24:
sprintf(s, "$%02X", a1[1]);
v9 = 2;
goto LABEL_109;
case 0x44u:
strcpy(v18, "mvp");
goto LABEL_51;
case 0x46u:
case 0x4Au:
case 0x4Eu:
case 0x56u:
case 0x5Eu:
strcpy(v18, "lsr");
goto LABEL_3;
case 0x48u:
strcpy(v18, "pha");
goto LABEL_26;
case 0x4Bu:
strcpy(v18, "phk");
goto LABEL_26;
case 0x4Cu:
case 0x5Cu:
case 0x6Cu:
case 0x7Cu:
case 0xDCu:
strcpy(v18, "jmp");
goto LABEL_3;
case 0x50u:
strcpy(v18, "bvc");
goto LABEL_7;
case 0x54u:
strcpy(v18, "mvn");
LABEL_51:
sprintf(s, "$%02X,$%02X", a1[1], a1[2]);
v9 = 3;
goto LABEL_109;
case 0x58u:
strcpy(v18, "cli");
goto LABEL_26;
case 0x5Au:
strcpy(v18, "phy");
goto LABEL_26;
case 0x5Bu:
strcpy(v18, "tcd");
goto LABEL_26;
case 0x60u:
strcpy(v18, "rts");
if ( (a5 & 2) != 0 )
goto LABEL_81;
goto LABEL_26;
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:
strcpy(v18, "adc");
goto LABEL_3;
case 0x62u:
strcpy(v18, "per");
goto LABEL_19;
case 0x64u:
case 0x74u:
case 0x9Cu:
case 0x9Eu:
strcpy(v18, "stz");
goto LABEL_3;
case 0x66u:
case 0x6Au:
case 0x6Eu:
case 0x76u:
case 0x7Eu:
strcpy(v18, "ror");
goto LABEL_3;
case 0x68u:
strcpy(v18, "pla");
goto LABEL_26;
case 0x6Bu:
strcpy(v18, "rtl");
if ( (a5 & 2) != 0 )
LABEL_81:
*(_WORD *)&v18[strlen(v18)] = 10;
goto LABEL_26;
case 0x70u:
strcpy(v18, "bvs");
goto LABEL_7;
case 0x78u:
strcpy(v18, "sei");
goto LABEL_26;
case 0x7Au:
strcpy(v18, "ply");
goto LABEL_26;
case 0x7Bu:
strcpy(v18, "tdc");
goto LABEL_26;
case 0x80u:
strcpy(v18, "bra");
goto LABEL_7;
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:
strcpy(v18, "sta");
goto LABEL_3;
case 0x82u:
strcpy(v18, "brl");
LABEL_19:
v10 = a1[1] + (a1[2] << 8);
if ( v10 > 0x7FFF )
LOWORD(v10) = a1[1] + (a1[2] << 8);
sprintf(s, "$%04lX", (unsigned __int16)(a2 + v10 + 3));
v9 = 3;
goto LABEL_109;
case 0x84u:
case 0x8Cu:
case 0x94u:
strcpy(v18, "sty");
goto LABEL_3;
case 0x86u:
case 0x8Eu:
case 0x96u:
strcpy(v18, "stx");
goto LABEL_3;
case 0x88u:
strcpy(v18, "dey");
goto LABEL_26;
case 0x8Au:
strcpy(v18, "txa");
goto LABEL_26;
case 0x8Bu:
strcpy(v18, "phb");
goto LABEL_26;
case 0x90u:
strcpy(v18, "bcc");
goto LABEL_7;
case 0x98u:
strcpy(v18, "tya");
goto LABEL_26;
case 0x9Au:
strcpy(v18, "txs");
goto LABEL_26;
case 0x9Bu:
strcpy(v18, "txy");
goto LABEL_26;
case 0xA0u:
case 0xA4u:
case 0xACu:
case 0xB4u:
case 0xBCu:
strcpy(v18, "ldy");
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:
strcpy(v18, "lda");
goto LABEL_3;
case 0xA2u:
case 0xA6u:
case 0xAEu:
case 0xB6u:
case 0xBEu:
strcpy(v18, "ldx");
goto LABEL_3;
case 0xA8u:
strcpy(v18, "tay");
goto LABEL_26;
case 0xAAu:
strcpy(v18, "tax");
goto LABEL_26;
case 0xABu:
strcpy(v18, "plb");
goto LABEL_26;
case 0xB0u:
strcpy(v18, "bcs");
goto LABEL_7;
case 0xB8u:
strcpy(v18, "clv");
goto LABEL_26;
case 0xBAu:
strcpy(v18, "tsx");
goto LABEL_26;
case 0xBBu:
strcpy(v18, "tyx");
goto LABEL_26;
case 0xC0u:
case 0xC4u:
case 0xCCu:
strcpy(v18, "cpy");
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:
strcpy(v18, "cmp");
goto LABEL_3;
case 0xC2u:
strcpy(v18, "rep");
LABEL_73:
*a3 &= ~a1[1];
sprintf(s, "#$%02X", a1[1]);
v9 = 2;
goto LABEL_109;
case 0xC8u:
strcpy(v18, "iny");
goto LABEL_26;
case 0xCAu:
strcpy(v18, "dex");
goto LABEL_26;
case 0xCBu:
strcpy(v18, "wai");
goto LABEL_26;
case 0xD0u:
strcpy(v18, "bne");
goto LABEL_7;
case 0xD4u:
strcpy(v18, "pei");
LABEL_57:
sprintf(s, "($%02X)", a1[1]);
v9 = 2;
goto LABEL_109;
case 0xD8u:
strcpy(v18, "cld");
goto LABEL_26;
case 0xDAu:
strcpy(v18, "phx");
goto LABEL_26;
case 0xDBu:
strcpy(v18, "stp");
goto LABEL_26;
case 0xE0u:
case 0xE4u:
case 0xECu:
strcpy(v18, "cpx");
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:
strcpy(v18, "sbc");
LABEL_3:
switch ( v6 )
{
case 0u:
case 2u:
case 4u:
case 5u:
case 6u:
case 0x14u:
case 0x24u:
case 0x25u:
case 0x26u:
case 0x42u:
case 0x45u:
case 0x46u:
case 0x64u:
case 0x65u:
case 0x66u:
case 0x84u:
case 0x85u:
case 0x86u:
case 0xA4u:
case 0xA5u:
case 0xA6u:
case 0xC4u:
case 0xC5u:
case 0xC6u:
case 0xE4u:
case 0xE5u:
case 0xE6u:
goto LABEL_24;
case 1u:
case 0x21u:
case 0x41u:
case 0x61u:
case 0x81u:
case 0xA1u:
case 0xC1u:
case 0xE1u:
sprintf(s, "($%02X,X)", a1[1]);
v9 = 2;
goto LABEL_109;
case 3u:
case 0x23u:
case 0x43u:
case 0x63u:
case 0x83u:
case 0xA3u:
case 0xC3u:
case 0xE3u:
sprintf(s, "$%02X,S", a1[1]);
v9 = 2;
goto LABEL_109;
case 7u:
case 0x27u:
case 0x47u:
case 0x67u:
case 0x87u:
case 0xA7u:
case 0xC7u:
case 0xE7u:
sprintf(s, "[$%02X]", a1[1]);
v9 = 2;
goto LABEL_109;
case 8u:
case 0xBu:
case 0x18u:
case 0x1Bu:
case 0x28u:
case 0x2Bu:
case 0x38u:
case 0x3Bu:
case 0x40u:
case 0x48u:
case 0x4Bu:
case 0x58u:
case 0x5Au:
case 0x5Bu:
case 0x60u:
case 0x68u:
case 0x6Bu:
case 0x78u:
case 0x7Au:
case 0x7Bu:
case 0x88u:
case 0x8Au:
case 0x8Bu:
case 0x98u:
case 0x9Au:
case 0x9Bu:
case 0xA8u:
case 0xAAu:
case 0xABu:
case 0xB8u:
case 0xBAu:
case 0xBBu:
case 0xC8u:
case 0xCAu:
case 0xCBu:
case 0xD8u:
case 0xDAu:
case 0xDBu:
case 0xE8u:
case 0xEAu:
case 0xEBu:
case 0xF8u:
case 0xFAu:
case 0xFBu:
goto LABEL_26;
case 9u:
case 0x29u:
case 0x49u:
case 0x69u:
case 0x89u:
case 0xA9u:
case 0xC9u:
case 0xE9u:
if ( (*a3 & 0x20) != 0 )
goto LABEL_134;
goto LABEL_137;
case 0xAu:
case 0x1Au:
case 0x2Au:
case 0x3Au:
case 0x4Au:
case 0x6Au:
strcpy(s, "A");
v9 = 1;
goto LABEL_109;
case 0xCu:
case 0xDu:
case 0xEu:
case 0x1Cu:
case 0x20u:
case 0x2Cu:
case 0x2Du:
case 0x2Eu:
case 0x4Cu:
case 0x4Du:
case 0x4Eu:
case 0x6Du:
case 0x6Eu:
case 0x8Cu:
case 0x8Du:
case 0x8Eu:
case 0x9Cu:
case 0xACu:
case 0xADu:
case 0xAEu:
case 0xCCu:
case 0xCDu:
case 0xCEu:
case 0xECu:
case 0xEDu:
case 0xEEu:
case 0xF4u:
goto LABEL_108;
case 0xFu:
case 0x22u:
case 0x2Fu:
case 0x4Fu:
case 0x5Cu:
case 0x6Fu:
case 0x8Fu:
case 0xAFu:
case 0xCFu:
case 0xEFu:
sprintf(s, "$%06X", (a1[3] << 16) + a1[1] + (a1[2] << 8));
v9 = 4;
goto LABEL_109;
case 0x10u:
case 0x30u:
case 0x50u:
case 0x70u:
case 0x80u:
case 0x90u:
case 0xB0u:
case 0xD0u:
case 0xF0u:
goto LABEL_7;
case 0x11u:
case 0x31u:
case 0x51u:
case 0x71u:
case 0x91u:
case 0xB1u:
case 0xD1u:
case 0xF1u:
sprintf(s, "($%02X),Y", a1[1]);
v9 = 2;
goto LABEL_109;
case 0x12u:
case 0x32u:
case 0x52u:
case 0x72u:
case 0x92u:
case 0xB2u:
case 0xD2u:
case 0xD4u:
case 0xF2u:
goto LABEL_57;
case 0x13u:
case 0x33u:
case 0x53u:
case 0x73u:
case 0x93u:
case 0xB3u:
case 0xD3u:
case 0xF3u:
sprintf(s, "($%02X,S),Y", a1[1]);
v9 = 2;
goto LABEL_109;
case 0x15u:
case 0x16u:
case 0x34u:
case 0x35u:
case 0x36u:
case 0x55u:
case 0x56u:
case 0x74u:
case 0x75u:
case 0x76u:
case 0x94u:
case 0x95u:
case 0xB4u:
case 0xB5u:
case 0xD5u:
case 0xD6u:
case 0xF5u:
case 0xF6u:
sprintf(s, "$%02X,X", a1[1]);
v9 = 2;
goto LABEL_109;
case 0x17u:
case 0x37u:
case 0x57u:
case 0x77u:
case 0x97u:
case 0xB7u:
case 0xD7u:
case 0xF7u:
sprintf(s, "[$%02X],Y", a1[1]);
v9 = 2;
goto LABEL_109;
case 0x19u:
case 0x39u:
case 0x59u:
case 0x79u:
case 0x99u:
case 0xB9u:
case 0xBEu:
case 0xD9u:
case 0xF9u:
sprintf(s, "$%04X,Y", a1[1] + (a1[2] << 8));
v9 = 3;
goto LABEL_109;
case 0x1Du:
case 0x1Eu:
case 0x3Cu:
case 0x3Du:
case 0x3Eu:
case 0x5Du:
case 0x5Eu:
case 0x7Du:
case 0x7Eu:
case 0x9Du:
case 0x9Eu:
case 0xBCu:
case 0xBDu:
case 0xDDu:
case 0xDEu:
case 0xFDu:
case 0xFEu:
sprintf(s, "$%04X,X", a1[1] + (a1[2] << 8));
v9 = 3;
goto LABEL_109;
case 0x1Fu:
case 0x3Fu:
case 0x5Fu:
case 0x7Fu:
case 0x9Fu:
case 0xBFu:
case 0xDFu:
case 0xFFu:
sprintf(s, "$%06X,X", (a1[3] << 16) + a1[1] + (a1[2] << 8));
v9 = 4;
goto LABEL_109;
case 0x44u:
case 0x54u:
goto LABEL_51;
case 0x62u:
case 0x82u:
goto LABEL_19;
case 0x6Cu:
sprintf(s, "($%04X)", a1[1] + (a1[2] << 8));
v9 = 3;
goto LABEL_109;
case 0x7Cu:
case 0xFCu:
sprintf(s, "($%04X,X)", a1[1] + (a1[2] << 8));
v9 = 3;
goto LABEL_109;
case 0x96u:
case 0xB6u:
sprintf(s, "$%02X,Y", a1[1]);
v9 = 2;
goto LABEL_109;
case 0xA0u:
case 0xA2u:
case 0xC0u:
case 0xE0u:
if ( (*a3 & 0x10) != 0 )
{
LABEL_134:
sprintf(s, "#$%02X", a1[1]);
v9 = 2;
}
else
{
LABEL_137:
sprintf(s, "#$%04X", a1[1] + (a1[2] << 8));
v9 = 3;
}
break;
case 0xC2u:
goto LABEL_73;
case 0xDCu:
sprintf(s, "[$%04X]", a1[1] + (a1[2] << 8));
v9 = 3;
break;
case 0xE2u:
goto LABEL_84;
}
goto LABEL_109;
case 0xE2u:
strcpy(v18, "sep");
LABEL_84:
*a3 |= a1[1];
sprintf(s, "#$%02X", a1[1]);
v9 = 2;
goto LABEL_109;
case 0xE8u:
strcpy(v18, "inx");
goto LABEL_26;
case 0xEAu:
strcpy(v18, "nop");
goto LABEL_26;
case 0xEBu:
strcpy(v18, "xba");
goto LABEL_26;
case 0xF0u:
strcpy(v18, "beq");
LABEL_7:
v7 = a1[1];
v8 = v7;
if ( (v7 & 0x80u) != 0 )
v8 = v7 - 256;
sprintf(s, "$%04lX", (unsigned __int16)(a2 + v8 + 2));
v9 = 2;
goto LABEL_109;
case 0xF4u:
strcpy(v18, "pea");
LABEL_108:
sprintf(s, "$%04X", a1[1] + (a1[2] << 8));
v9 = 3;
goto LABEL_109;
case 0xF8u:
strcpy(v18, "sed");
goto LABEL_26;
case 0xFAu:
strcpy(v18, "plx");
goto LABEL_26;
case 0xFBu:
strcpy(v18, "xce");
LABEL_26:
s[0] = 0;
v9 = 1;
LABEL_109:
v11 = a1;
v12 = v16;
do
{
sprintf(v12, "%02X", *v11++);
v12 += 2;
}
while ( v11 != &a1[v9] );
LODWORD(v13) = 2 * v9;
if ( (int)(2 * v9) <= 7 )
{
v13 = (int)v13;
do
v16[v13++] = 32;
while ( (int)v13 <= 7 );
}
v16[8] = 0;
if ( (a5 & 1) != 0 )
sprintf(a4, "%s %s", v18, s);
else
sprintf(a4, "%02lX/%04lX:\t%s\t%s %s", BYTE2(a2), (unsigned __int16)a2, v16, v18, s);
return v9;
}
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1, int a2, _BYTE *a3, char *a4, char a5)
{
unsigned __int8 v6; // al
unsigned __int8 v7; // cl
__int16 v8; // ax
unsigned int v9; // er15
int v10; // eax
unsigned __int8 *v11; // rbx
char *v12; // rbp
__int64 v13; // rax
char v16[9]; // [rsp+17h] [rbp-61h] BYREF
char s[2]; // [rsp+20h] [rbp-58h] BYREF
char v18[61]; // [rsp+3Bh] [rbp-3Dh] BYREF

v6 = *a1;
switch ( *a1 )
{
case 0u:
strcpy(v18, "brk");
goto LABEL_24;
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:
strcpy(v18, "ora");
goto LABEL_3;
case 2u:
strcpy(v18, "cop");
goto LABEL_24;
case 4u:
case 0xCu:
strcpy(v18, "tsb");
goto LABEL_3;
case 6u:
case 0xAu:
case 0xEu:
case 0x16u:
case 0x1Eu:
strcpy(v18, "asl");
goto LABEL_3;
case 8u:
strcpy(v18, "php");
goto LABEL_26;
case 0xBu:
strcpy(v18, "phd");
goto LABEL_26;
case 0x10u:
strcpy(v18, "bpl");
goto LABEL_7;
case 0x14u:
case 0x1Cu:
strcpy(v18, "trb");
goto LABEL_3;
case 0x18u:
strcpy(v18, "clc");
goto LABEL_26;
case 0x1Au:
case 0xE6u:
case 0xEEu:
case 0xF6u:
case 0xFEu:
strcpy(v18, "inc");
goto LABEL_3;
case 0x1Bu:
strcpy(v18, "tcs");
goto LABEL_26;
case 0x20u:
case 0x22u:
case 0xFCu:
strcpy(v18, "jsr");
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:
strcpy(v18, "and");
goto LABEL_3;
case 0x24u:
case 0x2Cu:
case 0x34u:
case 0x3Cu:
case 0x89u:
strcpy(v18, "bit");
goto LABEL_3;
case 0x26u:
case 0x2Au:
case 0x2Eu:
case 0x36u:
case 0x3Eu:
strcpy(v18, "rol");
goto LABEL_3;
case 0x28u:
strcpy(v18, "plp");
goto LABEL_26;
case 0x2Bu:
strcpy(v18, "pld");
goto LABEL_26;
case 0x30u:
strcpy(v18, "bmi");
goto LABEL_7;
case 0x38u:
strcpy(v18, "sec");
goto LABEL_26;
case 0x3Au:
case 0xC6u:
case 0xCEu:
case 0xD6u:
case 0xDEu:
strcpy(v18, "dec");
goto LABEL_3;
case 0x3Bu:
strcpy(v18, "tsc");
goto LABEL_26;
case 0x40u:
strcpy(v18, "rti");
if ( (a5 & 2) != 0 )
goto LABEL_81;
goto LABEL_26;
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:
strcpy(v18, "eor");
goto LABEL_3;
case 0x42u:
strcpy(v18, "wdm");
LABEL_24:
sprintf(s, "$%02X", a1[1]);
v9 = 2;
goto LABEL_109;
case 0x44u:
strcpy(v18, "mvp");
goto LABEL_51;
case 0x46u:
case 0x4Au:
case 0x4Eu:
case 0x56u:
case 0x5Eu:
strcpy(v18, "lsr");
goto LABEL_3;
case 0x48u:
strcpy(v18, "pha");
goto LABEL_26;
case 0x4Bu:
strcpy(v18, "phk");
goto LABEL_26;
case 0x4Cu:
case 0x5Cu:
case 0x6Cu:
case 0x7Cu:
case 0xDCu:
strcpy(v18, "jmp");
goto LABEL_3;
case 0x50u:
strcpy(v18, "bvc");
goto LABEL_7;
case 0x54u:
strcpy(v18, "mvn");
LABEL_51:
sprintf(s, "$%02X,$%02X", a1[1], a1[2]);
v9 = 3;
goto LABEL_109;
case 0x58u:
strcpy(v18, "cli");
goto LABEL_26;
case 0x5Au:
strcpy(v18, "phy");
goto LABEL_26;
case 0x5Bu:
strcpy(v18, "tcd");
goto LABEL_26;
case 0x60u:
strcpy(v18, "rts");
if ( (a5 & 2) != 0 )
goto LABEL_81;
goto LABEL_26;
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:
strcpy(v18, "adc");
goto LABEL_3;
case 0x62u:
strcpy(v18, "per");
goto LABEL_19;
case 0x64u:
case 0x74u:
case 0x9Cu:
case 0x9Eu:
strcpy(v18, "stz");
goto LABEL_3;
case 0x66u:
case 0x6Au:
case 0x6Eu:
case 0x76u:
case 0x7Eu:
strcpy(v18, "ror");
goto LABEL_3;
case 0x68u:
strcpy(v18, "pla");
goto LABEL_26;
case 0x6Bu:
strcpy(v18, "rtl");
if ( (a5 & 2) != 0 )
LABEL_81:
*(_WORD *)&v18[strlen(v18)] = 10;
goto LABEL_26;
case 0x70u:
strcpy(v18, "bvs");
goto LABEL_7;
case 0x78u:
strcpy(v18, "sei");
goto LABEL_26;
case 0x7Au:
strcpy(v18, "ply");
goto LABEL_26;
case 0x7Bu:
strcpy(v18, "tdc");
goto LABEL_26;
case 0x80u:
strcpy(v18, "bra");
goto LABEL_7;
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:
strcpy(v18, "sta");
goto LABEL_3;
case 0x82u:
strcpy(v18, "brl");
LABEL_19:
v10 = a1[1] + (a1[2] << 8);
if ( v10 > 0x7FFF )
LOWORD(v10) = a1[1] + (a1[2] << 8);
sprintf(s, "$%04lX", (unsigned __int16)(a2 + v10 + 3));
v9 = 3;
goto LABEL_109;
case 0x84u:
case 0x8Cu:
case 0x94u:
strcpy(v18, "sty");
goto LABEL_3;
case 0x86u:
case 0x8Eu:
case 0x96u:
strcpy(v18, "stx");
goto LABEL_3;
case 0x88u:
strcpy(v18, "dey");
goto LABEL_26;
case 0x8Au:
strcpy(v18, "txa");
goto LABEL_26;
case 0x8Bu:
strcpy(v18, "phb");
goto LABEL_26;
case 0x90u:
strcpy(v18, "bcc");
goto LABEL_7;
case 0x98u:
strcpy(v18, "tya");
goto LABEL_26;
case 0x9Au:
strcpy(v18, "txs");
goto LABEL_26;
case 0x9Bu:
strcpy(v18, "txy");
goto LABEL_26;
case 0xA0u:
case 0xA4u:
case 0xACu:
case 0xB4u:
case 0xBCu:
strcpy(v18, "ldy");
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:
strcpy(v18, "lda");
goto LABEL_3;
case 0xA2u:
case 0xA6u:
case 0xAEu:
case 0xB6u:
case 0xBEu:
strcpy(v18, "ldx");
goto LABEL_3;
case 0xA8u:
strcpy(v18, "tay");
goto LABEL_26;
case 0xAAu:
strcpy(v18, "tax");
goto LABEL_26;
case 0xABu:
strcpy(v18, "plb");
goto LABEL_26;
case 0xB0u:
strcpy(v18, "bcs");
goto LABEL_7;
case 0xB8u:
strcpy(v18, "clv");
goto LABEL_26;
case 0xBAu:
strcpy(v18, "tsx");
goto LABEL_26;
case 0xBBu:
strcpy(v18, "tyx");
goto LABEL_26;
case 0xC0u:
case 0xC4u:
case 0xCCu:
strcpy(v18, "cpy");
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:
strcpy(v18, "cmp");
goto LABEL_3;
case 0xC2u:
strcpy(v18, "rep");
LABEL_73:
*a3 &= ~a1[1];
sprintf(s, "#$%02X", a1[1]);
v9 = 2;
goto LABEL_109;
case 0xC8u:
strcpy(v18, "iny");
goto LABEL_26;
case 0xCAu:
strcpy(v18, "dex");
goto LABEL_26;
case 0xCBu:
strcpy(v18, "wai");
goto LABEL_26;
case 0xD0u:
strcpy(v18, "bne");
goto LABEL_7;
case 0xD4u:
strcpy(v18, "pei");
LABEL_57:
sprintf(s, "($%02X)", a1[1]);
v9 = 2;
goto LABEL_109;
case 0xD8u:
strcpy(v18, "cld");
goto LABEL_26;
case 0xDAu:
strcpy(v18, "phx");
goto LABEL_26;
case 0xDBu:
strcpy(v18, "stp");
goto LABEL_26;
case 0xE0u:
case 0xE4u:
case 0xECu:
strcpy(v18, "cpx");
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:
strcpy(v18, "sbc");
LABEL_3:
switch ( v6 )
{
case 0u:
case 2u:
case 4u:
case 5u:
case 6u:
case 0x14u:
case 0x24u:
case 0x25u:
case 0x26u:
case 0x42u:
case 0x45u:
case 0x46u:
case 0x64u:
case 0x65u:
case 0x66u:
case 0x84u:
case 0x85u:
case 0x86u:
case 0xA4u:
case 0xA5u:
case 0xA6u:
case 0xC4u:
case 0xC5u:
case 0xC6u:
case 0xE4u:
case 0xE5u:
case 0xE6u:
goto LABEL_24;
case 1u:
case 0x21u:
case 0x41u:
case 0x61u:
case 0x81u:
case 0xA1u:
case 0xC1u:
case 0xE1u:
sprintf(s, "($%02X,X)", a1[1]);
v9 = 2;
goto LABEL_109;
case 3u:
case 0x23u:
case 0x43u:
case 0x63u:
case 0x83u:
case 0xA3u:
case 0xC3u:
case 0xE3u:
sprintf(s, "$%02X,S", a1[1]);
v9 = 2;
goto LABEL_109;
case 7u:
case 0x27u:
case 0x47u:
case 0x67u:
case 0x87u:
case 0xA7u:
case 0xC7u:
case 0xE7u:
sprintf(s, "[$%02X]", a1[1]);
v9 = 2;
goto LABEL_109;
case 8u:
case 0xBu:
case 0x18u:
case 0x1Bu:
case 0x28u:
case 0x2Bu:
case 0x38u:
case 0x3Bu:
case 0x40u:
case 0x48u:
case 0x4Bu:
case 0x58u:
case 0x5Au:
case 0x5Bu:
case 0x60u:
case 0x68u:
case 0x6Bu:
case 0x78u:
case 0x7Au:
case 0x7Bu:
case 0x88u:
case 0x8Au:
case 0x8Bu:
case 0x98u:
case 0x9Au:
case 0x9Bu:
case 0xA8u:
case 0xAAu:
case 0xABu:
case 0xB8u:
case 0xBAu:
case 0xBBu:
case 0xC8u:
case 0xCAu:
case 0xCBu:
case 0xD8u:
case 0xDAu:
case 0xDBu:
case 0xE8u:
case 0xEAu:
case 0xEBu:
case 0xF8u:
case 0xFAu:
case 0xFBu:
goto LABEL_26;
case 9u:
case 0x29u:
case 0x49u:
case 0x69u:
case 0x89u:
case 0xA9u:
case 0xC9u:
case 0xE9u:
if ( (*a3 & 0x20) != 0 )
goto LABEL_134;
goto LABEL_137;
case 0xAu:
case 0x1Au:
case 0x2Au:
case 0x3Au:
case 0x4Au:
case 0x6Au:
strcpy(s, "A");
v9 = 1;
goto LABEL_109;
case 0xCu:
case 0xDu:
case 0xEu:
case 0x1Cu:
case 0x20u:
case 0x2Cu:
case 0x2Du:
case 0x2Eu:
case 0x4Cu:
case 0x4Du:
case 0x4Eu:
case 0x6Du:
case 0x6Eu:
case 0x8Cu:
case 0x8Du:
case 0x8Eu:
case 0x9Cu:
case 0xACu:
case 0xADu:
case 0xAEu:
case 0xCCu:
case 0xCDu:
case 0xCEu:
case 0xECu:
case 0xEDu:
case 0xEEu:
case 0xF4u:
goto LABEL_108;
case 0xFu:
case 0x22u:
case 0x2Fu:
case 0x4Fu:
case 0x5Cu:
case 0x6Fu:
case 0x8Fu:
case 0xAFu:
case 0xCFu:
case 0xEFu:
sprintf(s, "$%06X", (a1[3] << 16) + a1[1] + (a1[2] << 8));
v9 = 4;
goto LABEL_109;
case 0x10u:
case 0x30u:
case 0x50u:
case 0x70u:
case 0x80u:
case 0x90u:
case 0xB0u:
case 0xD0u:
case 0xF0u:
goto LABEL_7;
case 0x11u:
case 0x31u:
case 0x51u:
case 0x71u:
case 0x91u:
case 0xB1u:
case 0xD1u:
case 0xF1u:
sprintf(s, "($%02X),Y", a1[1]);
v9 = 2;
goto LABEL_109;
case 0x12u:
case 0x32u:
case 0x52u:
case 0x72u:
case 0x92u:
case 0xB2u:
case 0xD2u:
case 0xD4u:
case 0xF2u:
goto LABEL_57;
case 0x13u:
case 0x33u:
case 0x53u:
case 0x73u:
case 0x93u:
case 0xB3u:
case 0xD3u:
case 0xF3u:
sprintf(s, "($%02X,S),Y", a1[1]);
v9 = 2;
goto LABEL_109;
case 0x15u:
case 0x16u:
case 0x34u:
case 0x35u:
case 0x36u:
case 0x55u:
case 0x56u:
case 0x74u:
case 0x75u:
case 0x76u:
case 0x94u:
case 0x95u:
case 0xB4u:
case 0xB5u:
case 0xD5u:
case 0xD6u:
case 0xF5u:
case 0xF6u:
sprintf(s, "$%02X,X", a1[1]);
v9 = 2;
goto LABEL_109;
case 0x17u:
case 0x37u:
case 0x57u:
case 0x77u:
case 0x97u:
case 0xB7u:
case 0xD7u:
case 0xF7u:
sprintf(s, "[$%02X],Y", a1[1]);
v9 = 2;
goto LABEL_109;
case 0x19u:
case 0x39u:
case 0x59u:
case 0x79u:
case 0x99u:
case 0xB9u:
case 0xBEu:
case 0xD9u:
case 0xF9u:
sprintf(s, "$%04X,Y", a1[1] + (a1[2] << 8));
v9 = 3;
goto LABEL_109;
case 0x1Du:
case 0x1Eu:
case 0x3Cu:
case 0x3Du:
case 0x3Eu:
case 0x5Du:
case 0x5Eu:
case 0x7Du:
case 0x7Eu:
case 0x9Du:
case 0x9Eu:
case 0xBCu:
case 0xBDu:
case 0xDDu:
case 0xDEu:
case 0xFDu:
case 0xFEu:
sprintf(s, "$%04X,X", a1[1] + (a1[2] << 8));
v9 = 3;
goto LABEL_109;
case 0x1Fu:
case 0x3Fu:
case 0x5Fu:
case 0x7Fu:
case 0x9Fu:
case 0xBFu:
case 0xDFu:
case 0xFFu:
sprintf(s, "$%06X,X", (a1[3] << 16) + a1[1] + (a1[2] << 8));
v9 = 4;
goto LABEL_109;
case 0x44u:
case 0x54u:
goto LABEL_51;
case 0x62u:
case 0x82u:
goto LABEL_19;
case 0x6Cu:
sprintf(s, "($%04X)", a1[1] + (a1[2] << 8));
v9 = 3;
goto LABEL_109;
case 0x7Cu:
case 0xFCu:
sprintf(s, "($%04X,X)", a1[1] + (a1[2] << 8));
v9 = 3;
goto LABEL_109;
case 0x96u:
case 0xB6u:
sprintf(s, "$%02X,Y", a1[1]);
v9 = 2;
goto LABEL_109;
case 0xA0u:
case 0xA2u:
case 0xC0u:
case 0xE0u:
if ( (*a3 & 0x10) != 0 )
{
LABEL_134:
sprintf(s, "#$%02X", a1[1]);
v9 = 2;
}
else
{
LABEL_137:
sprintf(s, "#$%04X", a1[1] + (a1[2] << 8));
v9 = 3;
}
break;
case 0xC2u:
goto LABEL_73;
case 0xDCu:
sprintf(s, "[$%04X]", a1[1] + (a1[2] << 8));
v9 = 3;
break;
case 0xE2u:
goto LABEL_84;
}
goto LABEL_109;
case 0xE2u:
strcpy(v18, "sep");
LABEL_84:
*a3 |= a1[1];
sprintf(s, "#$%02X", a1[1]);
v9 = 2;
goto LABEL_109;
case 0xE8u:
strcpy(v18, "inx");
goto LABEL_26;
case 0xEAu:
strcpy(v18, "nop");
goto LABEL_26;
case 0xEBu:
strcpy(v18, "xba");
goto LABEL_26;
case 0xF0u:
strcpy(v18, "beq");
LABEL_7:
v7 = a1[1];
v8 = v7;
if ( (v7 & 0x80u) != 0 )
v8 = v7 - 256;
sprintf(s, "$%04lX", (unsigned __int16)(a2 + v8 + 2));
v9 = 2;
goto LABEL_109;
case 0xF4u:
strcpy(v18, "pea");
LABEL_108:
sprintf(s, "$%04X", a1[1] + (a1[2] << 8));
v9 = 3;
goto LABEL_109;
case 0xF8u:
strcpy(v18, "sed");
goto LABEL_26;
case 0xFAu:
strcpy(v18, "plx");
goto LABEL_26;
case 0xFBu:
strcpy(v18, "xce");
LABEL_26:
s[0] = 0;
v9 = 1;
LABEL_109:
v11 = a1;
v12 = v16;
do
{
sprintf(v12, "%02X", *v11++);
v12 += 2;
}
while ( v11 != &a1[v9] );
LODWORD(v13) = 2 * v9;
if ( (int)(2 * v9) <= 7 )
{
v13 = (int)v13;
do
v16[v13++] = 32;
while ( (int)v13 <= 7 );
}
v16[8] = 0;
if ( (a5 & 1) != 0 )
sprintf(a4, "%s %s", v18, s);
else
sprintf(a4, "%02lX/%04lX:\t%s\t%s %s", BYTE2(a2), (unsigned __int16)a2, v16, v18, s);
return v9;
}
}

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