decompiled_code:
unsigned __int8 *__fastcall p8_encode_cmd(_QWORD *a1, unsigned int a2, unsigned __int8 *a3, unsigned int a4)
{
_BYTE *v4; // rax
unsigned __int8 *v5; // r9
unsigned __int8 *v6; // r10
unsigned __int64 v8; // rdi
char *v9; // rdi
unsigned __int8 *v10; // rdi
unsigned __int8 *v11; // rcx
unsigned __int8 *result; // rax
unsigned __int64 v13; // rdx

v4 = (_BYTE *)a1[1];
v5 = (unsigned __int8 *)a1 + 20;
if ( v4 < (_BYTE *)a1 + 20 || (v6 = (unsigned __int8 *)(a1 + 16), v4 > (_BYTE *)a1 + 128) )
_assert_fail(
"(oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)",
"p8_frame_encode.c",
0x21u,
"p8_encode_cmd");
v8 = *a1;
if ( (unsigned __int64)v6 < v8 || (unsigned __int64)v5 > v8 )
_assert_fail(
"(oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)",
"p8_frame_encode.c",
0x21u,
"p8_encode_cmd");
if ( (unsigned __int64)v4 < v8 )
_assert_fail("(oframe)->f_sta <= (oframe)->f_end", "p8_frame_encode.c", 0x21u, "p8_encode_cmd");
if ( a4 > 0x6B )
_assert_fail("len < COUNT_OF(oframe->f_buf)", "p8_frame_encode.c", 0x22u, "p8_encode_cmd");
if ( P8_CODE_TYPE_COUNT <= a2 )
_assert_fail("(code) < P8_CODE_TYPE_COUNT", "p8_frame_encode.c", 0x23u, "p8_encode_cmd");
v9 = (char *)&p8_code_types + 5 * a2;
if ( (*v9 & 1) == 0 )
_assert_fail("p8_code_types[(code)].ct_type & P8_CT_H2A", "p8_frame_encode.c", 0x23u, "p8_encode_cmd");
if ( (unsigned __int8)v9[1] > a4 )
_assert_fail("(len) >= p8_code_types[(code)].ct_h2a_min_plen", "p8_frame_encode.c", 0x23u, "p8_encode_cmd");
if ( (unsigned __int8)v9[2] < a4 )
_assert_fail("(len) <= p8_code_types[(code)].ct_h2a_max_plen", "p8_frame_encode.c", 0x23u, "p8_encode_cmd");
*v4 = -1;
v10 = v4 + 2;
v4[1] = a2;
if ( a4 )
{
do
v10 = encode_char(v10, *a3);
while ( v11 != a3 );
}
result = v10 + 1;
*v10 = -2;
a1[1] = v10 + 1;
if ( (unsigned __int64)(v10 + 1 - v5) > 0x6B )
_assert_fail("p - oframe->f_buf < COUNT_OF(oframe->f_buf)", "p8_frame_encode.c", 0x30u, "p8_encode_cmd");
if ( v5 > result || v6 < result )
_assert_fail(
"(oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)",
"p8_frame_encode.c",
0x32u,
"p8_encode_cmd");
v13 = *a1;
if ( (unsigned __int64)v6 < *a1 || (unsigned __int64)v5 > v13 )
_assert_fail(
"(oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)",
"p8_frame_encode.c",
0x32u,
"p8_encode_cmd");
if ( v13 > (unsigned __int64)result )
_assert_fail("(oframe)->f_sta <= (oframe)->f_end", "p8_frame_encode.c", 0x32u, "p8_encode_cmd");
return result;
}

canonical_decompiled_code:
unsigned __int8 *__fastcall func1(_QWORD *a1, unsigned int a2, unsigned __int8 *a3, unsigned int a4)
{
_BYTE *v4; // rax
unsigned __int8 *v5; // r9
unsigned __int8 *v6; // r10
unsigned __int64 v8; // rdi
char *v9; // rdi
unsigned __int8 *v10; // rdi
unsigned __int8 *v11; // rcx
unsigned __int8 *result; // rax
unsigned __int64 v13; // rdx

v4 = (_BYTE *)a1[1];
v5 = (unsigned __int8 *)a1 + 20;
if ( v4 < (_BYTE *)a1 + 20 || (v6 = (unsigned __int8 *)(a1 + 16), v4 > (_BYTE *)a1 + 128) )
_assert_fail(
"(oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)",
"p8_frame_encode.c",
0x21u,
"p8_encode_cmd");
v8 = *a1;
if ( (unsigned __int64)v6 < v8 || (unsigned __int64)v5 > v8 )
_assert_fail(
"(oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)",
"p8_frame_encode.c",
0x21u,
"p8_encode_cmd");
if ( (unsigned __int64)v4 < v8 )
_assert_fail("(oframe)->f_sta <= (oframe)->f_end", "p8_frame_encode.c", 0x21u, "p8_encode_cmd");
if ( a4 > 0x6B )
_assert_fail("len < COUNT_OF(oframe->f_buf)", "p8_frame_encode.c", 0x22u, "p8_encode_cmd");
if ( P8_CODE_TYPE_COUNT <= a2 )
_assert_fail("(code) < P8_CODE_TYPE_COUNT", "p8_frame_encode.c", 0x23u, "p8_encode_cmd");
v9 = (char *)&p8_code_types + 5 * a2;
if ( (*v9 & 1) == 0 )
_assert_fail("p8_code_types[(code)].ct_type & P8_CT_H2A", "p8_frame_encode.c", 0x23u, "p8_encode_cmd");
if ( (unsigned __int8)v9[1] > a4 )
_assert_fail("(len) >= p8_code_types[(code)].ct_h2a_min_plen", "p8_frame_encode.c", 0x23u, "p8_encode_cmd");
if ( (unsigned __int8)v9[2] < a4 )
_assert_fail("(len) <= p8_code_types[(code)].ct_h2a_max_plen", "p8_frame_encode.c", 0x23u, "p8_encode_cmd");
*v4 = -1;
v10 = v4 + 2;
v4[1] = a2;
if ( a4 )
{
do
v10 = func0(v10, *a3);
while ( v11 != a3 );
}
result = v10 + 1;
*v10 = -2;
a1[1] = v10 + 1;
if ( (unsigned __int64)(v10 + 1 - v5) > 0x6B )
_assert_fail("p - oframe->f_buf < COUNT_OF(oframe->f_buf)", "p8_frame_encode.c", 0x30u, "p8_encode_cmd");
if ( v5 > result || v6 < result )
_assert_fail(
"(oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)",
"p8_frame_encode.c",
0x32u,
"p8_encode_cmd");
v13 = *a1;
if ( (unsigned __int64)v6 < *a1 || (unsigned __int64)v5 > v13 )
_assert_fail(
"(oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)",
"p8_frame_encode.c",
0x32u,
"p8_encode_cmd");
if ( v13 > (unsigned __int64)result )
_assert_fail("(oframe)->f_sta <= (oframe)->f_end", "p8_frame_encode.c", 0x32u, "p8_encode_cmd");
return result;
}

original_code:
void
p8_encode_cmd(p8s_frame_t *oframe, p8_code_t code, proto_char_t *params, proto_len_t len) {
    ((void) sizeof (((oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ; else __assert_fail ("(oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)", "p8_frame_encode.c", 33, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ; else __assert_fail ("(oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)", "p8_frame_encode.c", 33, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((oframe)->f_sta <= (oframe)->f_end) ? 1 : 0), __extension__ ({ if ((oframe)->f_sta <= (oframe)->f_end) ; else __assert_fail ("(oframe)->f_sta <= (oframe)->f_end", "p8_frame_encode.c", 33, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((len < ((sizeof(oframe->f_buf)/sizeof(0[oframe->f_buf])) / ((unsigned int)(!(sizeof(oframe->f_buf) % sizeof(0[oframe->f_buf])))))) ? 1 : 0), __extension__ ({ if (len < ((sizeof(oframe->f_buf)/sizeof(0[oframe->f_buf])) / ((unsigned int)(!(sizeof(oframe->f_buf) % sizeof(0[oframe->f_buf])))))) ; else __assert_fail ("len < COUNT_OF(oframe->f_buf)", "p8_frame_encode.c", 34, __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_frame_encode.c", 35, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof ((p8_code_types[(code)].ct_type & 0x01) ? 1 : 0), __extension__ ({ if (p8_code_types[(code)].ct_type & 0x01) ; else __assert_fail ("p8_code_types[(code)].ct_type & P8_CT_H2A", "p8_frame_encode.c", 35, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((len) >= p8_code_types[(code)].ct_h2a_min_plen) ? 1 : 0), __extension__ ({ if ((len) >= p8_code_types[(code)].ct_h2a_min_plen) ; else __assert_fail ("(len) >= p8_code_types[(code)].ct_h2a_min_plen", "p8_frame_encode.c", 35, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((len) <= p8_code_types[(code)].ct_h2a_max_plen) ? 1 : 0), __extension__ ({ if ((len) <= p8_code_types[(code)].ct_h2a_max_plen) ; else __assert_fail ("(len) <= p8_code_types[(code)].ct_h2a_max_plen", "p8_frame_encode.c", 35, __extension__ __PRETTY_FUNCTION__); }));
    proto_char_t *p = oframe->f_end;
    *p++ = P8_FRAME_BEGIN;
    *p++ = code;
    while (len-- > 0) {
        p = encode_char(p, *params++);
    }
    *p++ = P8_FRAME_END;
    oframe->f_end = p;
    ((void) sizeof ((p - oframe->f_buf < ((sizeof(oframe->f_buf)/sizeof(0[oframe->f_buf])) / ((unsigned int)(!(sizeof(oframe->f_buf) % sizeof(0[oframe->f_buf])))))) ? 1 : 0), __extension__ ({ if (p - oframe->f_buf < ((sizeof(oframe->f_buf)/sizeof(0[oframe->f_buf])) / ((unsigned int)(!(sizeof(oframe->f_buf) % sizeof(0[oframe->f_buf])))))) ; else __assert_fail ("p - oframe->f_buf < COUNT_OF(oframe->f_buf)", "p8_frame_encode.c", 48, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof (((oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ; else __assert_fail ("(oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)", "p8_frame_encode.c", 50, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ; else __assert_fail ("(oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)", "p8_frame_encode.c", 50, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((oframe)->f_sta <= (oframe)->f_end) ? 1 : 0), __extension__ ({ if ((oframe)->f_sta <= (oframe)->f_end) ; else __assert_fail ("(oframe)->f_sta <= (oframe)->f_end", "p8_frame_encode.c", 50, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
void p8_encode_cmd(struct proto_frame *oframe, enum p8_code code, unsigned char *params, unsigned int len) {
    ((void) sizeof (((oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ; else __assert_fail ("(oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)", "p8_frame_encode.c", 33, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ; else __assert_fail ("(oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)", "p8_frame_encode.c", 33, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((oframe)->f_sta <= (oframe)->f_end) ? 1 : 0), __extension__ ({ if ((oframe)->f_sta <= (oframe)->f_end) ; else __assert_fail ("(oframe)->f_sta <= (oframe)->f_end", "p8_frame_encode.c", 33, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((len < ((sizeof(oframe->f_buf)/sizeof(0[oframe->f_buf])) / ((unsigned int)(!(sizeof(oframe->f_buf) % sizeof(0[oframe->f_buf])))))) ? 1 : 0), __extension__ ({ if (len < ((sizeof(oframe->f_buf)/sizeof(0[oframe->f_buf])) / ((unsigned int)(!(sizeof(oframe->f_buf) % sizeof(0[oframe->f_buf])))))) ; else __assert_fail ("len < COUNT_OF(oframe->f_buf)", "p8_frame_encode.c", 34, __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_frame_encode.c", 35, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof ((p8_code_types[(code)].ct_type & 0x01) ? 1 : 0), __extension__ ({ if (p8_code_types[(code)].ct_type & 0x01) ; else __assert_fail ("p8_code_types[(code)].ct_type & P8_CT_H2A", "p8_frame_encode.c", 35, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((len) >= p8_code_types[(code)].ct_h2a_min_plen) ? 1 : 0), __extension__ ({ if ((len) >= p8_code_types[(code)].ct_h2a_min_plen) ; else __assert_fail ("(len) >= p8_code_types[(code)].ct_h2a_min_plen", "p8_frame_encode.c", 35, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((len) <= p8_code_types[(code)].ct_h2a_max_plen) ? 1 : 0), __extension__ ({ if ((len) <= p8_code_types[(code)].ct_h2a_max_plen) ; else __assert_fail ("(len) <= p8_code_types[(code)].ct_h2a_max_plen", "p8_frame_encode.c", 35, __extension__ __PRETTY_FUNCTION__); }));
    unsigned char *p = oframe->f_end;
    *p++ = P8_FRAME_BEGIN;
    *p++ = code;
    while (len-- > 0) {
        p = encode_char(p, *params++);
    }
    *p++ = P8_FRAME_END;
    oframe->f_end = p;
    ((void) sizeof ((p - oframe->f_buf < ((sizeof(oframe->f_buf)/sizeof(0[oframe->f_buf])) / ((unsigned int)(!(sizeof(oframe->f_buf) % sizeof(0[oframe->f_buf])))))) ? 1 : 0), __extension__ ({ if (p - oframe->f_buf < ((sizeof(oframe->f_buf)/sizeof(0[oframe->f_buf])) / ((unsigned int)(!(sizeof(oframe->f_buf) % sizeof(0[oframe->f_buf])))))) ; else __assert_fail ("p - oframe->f_buf < COUNT_OF(oframe->f_buf)", "p8_frame_encode.c", 48, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof (((oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ; else __assert_fail ("(oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)", "p8_frame_encode.c", 50, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ; else __assert_fail ("(oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)", "p8_frame_encode.c", 50, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((oframe)->f_sta <= (oframe)->f_end) ? 1 : 0), __extension__ ({ if ((oframe)->f_sta <= (oframe)->f_end) ; else __assert_fail ("(oframe)->f_sta <= (oframe)->f_end", "p8_frame_encode.c", 50, __extension__ __PRETTY_FUNCTION__); }));
}

variable_types: enum p8_code { P8_CMD_NONE=0, P8_CMD_PING=1, P8_IND_ERROR_TIMEOUT=2, P8_IND_ERROR_HIGH=3, P8_IND_ERROR_LOW=4, P8_IND_RX_START=5, P8_IND_RX_NEXT=6, P8_IND_RX_FAILED=7, P8_IND_ACK=8, P8_IND_NACK=9, P8_CMD_SET_ACK_MASK=10, P8_CMD_TX=11, P8_CMD_TX_EOM=12, P8_CMD_TX_SET_IDLE=13, P8_CMD_TX_SET_ACK_P=14, P8_CMD_TX_SET_TIMEOUT=15, P8_IND_TX_SUCCEEDED=16, P8_IND_TX_FAIL_LINE=17, P8_IND_TX_FAIL_ACK=18, P8_IND_TX_TIMEOUT_D=19, P8_IND_TX_TIMEOUT_L=20, P8_QRY_FIRMWARE=21, P8_SET_CONTROLLED=24 }

variable_types:
params
unsigned char *

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


repo: pekkanikander/MacCEC

decompiled_code:
unsigned __int8 *__fastcall p8_encode_tx(_QWORD *a1, unsigned int a2, __int64 a3)
{
unsigned __int64 v3; // r9
unsigned __int8 *v4; // rax
_BYTE *v7; // rsi
unsigned __int8 *v8; // rbx
unsigned __int64 v9; // rbp
char *v10; // rbp
unsigned __int64 *v11; // rdx
unsigned __int64 *v12; // rcx
unsigned __int8 *v13; // rsi
unsigned __int64 v14; // r8
unsigned __int64 v15; // r9
unsigned __int64 v16; // r10
unsigned __int64 v17; // r11
unsigned __int8 *result; // rax
unsigned __int64 v19; // rdx
unsigned __int64 v20; // rdx

v3 = *(_QWORD *)(a3 + 8);
v4 = *(unsigned __int8 **)a3;
if ( v3 < a3 + 20 || v3 > a3 + 128 )
_assert_fail(
"(iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_frame_encode.c",
0x3Cu,
"p8_encode_tx");
if ( a3 + 20 > (unsigned __int64)v4 || a3 + 128 < (unsigned __int64)v4 )
_assert_fail(
"(iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_frame_encode.c",
0x3Cu,
"p8_encode_tx");
if ( v3 < (unsigned __int64)v4 )
_assert_fail("(iframe)->f_sta <= (iframe)->f_end", "p8_frame_encode.c", 0x3Cu, "p8_encode_tx");
v7 = (_BYTE *)a1[1];
if ( v7 < (_BYTE *)a1 + 20 || (v8 = (unsigned __int8 *)(a1 + 16), v7 > (_BYTE *)a1 + 128) )
_assert_fail(
"(oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)",
"p8_frame_encode.c",
0x3Du,
"p8_encode_tx");
v9 = *a1;
if ( (unsigned __int64)v8 < *a1 || (unsigned __int64)a1 + 20 > v9 )
_assert_fail(
"(oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)",
"p8_frame_encode.c",
0x3Du,
"p8_encode_tx");
if ( (unsigned __int64)v7 < v9 )
_assert_fail("(oframe)->f_sta <= (oframe)->f_end", "p8_frame_encode.c", 0x3Du, "p8_encode_tx");
if ( v3 <= (unsigned __int64)v4 )
_assert_fail("(iframe)->f_sta < (iframe)->f_end", "p8_frame_encode.c", 0x3Eu, "p8_encode_tx");
if ( P8_CODE_TYPE_COUNT <= a2 )
_assert_fail("(code) < P8_CODE_TYPE_COUNT", "p8_frame_encode.c", 0x40u, "p8_encode_tx");
v10 = (char *)&p8_code_types + 5 * a2;
if ( (*v10 & 1) == 0 )
_assert_fail("p8_code_types[(code)].ct_type & P8_CT_H2A", "p8_frame_encode.c", 0x40u, "p8_encode_tx");
if ( (unsigned __int8)v10[1] > 1u )
_assert_fail("(1) >= p8_code_types[(code)].ct_h2a_min_plen", "p8_frame_encode.c", 0x40u, "p8_encode_tx");
if ( !v10[2] )
_assert_fail("(1) <= p8_code_types[(code)].ct_h2a_max_plen", "p8_frame_encode.c", 0x40u, "p8_encode_tx");
v7[1] = a2;
*v7 = -1;
v13 = encode_char(v7 + 2, *v4);
result = v13 + 1;
*v13 = -2;
v12[1] = (unsigned __int64)(v13 + 1);
*v11 = v15;
if ( (unsigned __int64)&v13[-v14 + 1] > 0x6B )
_assert_fail("p - oframe->f_buf < COUNT_OF(oframe->f_buf)", "p8_frame_encode.c", 0x4Cu, "p8_encode_tx");
v19 = v11[1];
if ( v16 > v19 || v17 < v19 )
_assert_fail(
"(iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_frame_encode.c",
0x4Eu,
"p8_encode_tx");
if ( v17 < v15 || v16 > v15 )
_assert_fail(
"(iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_frame_encode.c",
0x4Eu,
"p8_encode_tx");
if ( v19 < v15 )
_assert_fail("(iframe)->f_sta <= (iframe)->f_end", "p8_frame_encode.c", 0x4Eu, "p8_encode_tx");
if ( v8 < result || v14 > (unsigned __int64)result )
_assert_fail(
"(oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)",
"p8_frame_encode.c",
0x4Fu,
"p8_encode_tx");
v20 = *v12;
if ( (unsigned __int64)v8 < *v12 || v14 > v20 )
_assert_fail(
"(oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)",
"p8_frame_encode.c",
0x4Fu,
"p8_encode_tx");
if ( v20 > (unsigned __int64)result )
_assert_fail("(oframe)->f_sta <= (oframe)->f_end", "p8_frame_encode.c", 0x4Fu, "p8_encode_tx");
return result;
}

canonical_decompiled_code:
unsigned __int8 *__fastcall func2(_QWORD *a1, unsigned int a2, __int64 a3)
{
unsigned __int64 v3; // r9
unsigned __int8 *v4; // rax
_BYTE *v7; // rsi
unsigned __int8 *v8; // rbx
unsigned __int64 v9; // rbp
char *v10; // rbp
unsigned __int64 *v11; // rdx
unsigned __int64 *v12; // rcx
unsigned __int8 *v13; // rsi
unsigned __int64 v14; // r8
unsigned __int64 v15; // r9
unsigned __int64 v16; // r10
unsigned __int64 v17; // r11
unsigned __int8 *result; // rax
unsigned __int64 v19; // rdx
unsigned __int64 v20; // rdx

v3 = *(_QWORD *)(a3 + 8);
v4 = *(unsigned __int8 **)a3;
if ( v3 < a3 + 20 || v3 > a3 + 128 )
_assert_fail(
"(iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_frame_encode.c",
0x3Cu,
"p8_encode_tx");
if ( a3 + 20 > (unsigned __int64)v4 || a3 + 128 < (unsigned __int64)v4 )
_assert_fail(
"(iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_frame_encode.c",
0x3Cu,
"p8_encode_tx");
if ( v3 < (unsigned __int64)v4 )
_assert_fail("(iframe)->f_sta <= (iframe)->f_end", "p8_frame_encode.c", 0x3Cu, "p8_encode_tx");
v7 = (_BYTE *)a1[1];
if ( v7 < (_BYTE *)a1 + 20 || (v8 = (unsigned __int8 *)(a1 + 16), v7 > (_BYTE *)a1 + 128) )
_assert_fail(
"(oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)",
"p8_frame_encode.c",
0x3Du,
"p8_encode_tx");
v9 = *a1;
if ( (unsigned __int64)v8 < *a1 || (unsigned __int64)a1 + 20 > v9 )
_assert_fail(
"(oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)",
"p8_frame_encode.c",
0x3Du,
"p8_encode_tx");
if ( (unsigned __int64)v7 < v9 )
_assert_fail("(oframe)->f_sta <= (oframe)->f_end", "p8_frame_encode.c", 0x3Du, "p8_encode_tx");
if ( v3 <= (unsigned __int64)v4 )
_assert_fail("(iframe)->f_sta < (iframe)->f_end", "p8_frame_encode.c", 0x3Eu, "p8_encode_tx");
if ( P8_CODE_TYPE_COUNT <= a2 )
_assert_fail("(code) < P8_CODE_TYPE_COUNT", "p8_frame_encode.c", 0x40u, "p8_encode_tx");
v10 = (char *)&p8_code_types + 5 * a2;
if ( (*v10 & 1) == 0 )
_assert_fail("p8_code_types[(code)].ct_type & P8_CT_H2A", "p8_frame_encode.c", 0x40u, "p8_encode_tx");
if ( (unsigned __int8)v10[1] > 1u )
_assert_fail("(1) >= p8_code_types[(code)].ct_h2a_min_plen", "p8_frame_encode.c", 0x40u, "p8_encode_tx");
if ( !v10[2] )
_assert_fail("(1) <= p8_code_types[(code)].ct_h2a_max_plen", "p8_frame_encode.c", 0x40u, "p8_encode_tx");
v7[1] = a2;
*v7 = -1;
v13 = func0(v7 + 2, *v4);
result = v13 + 1;
*v13 = -2;
v12[1] = (unsigned __int64)(v13 + 1);
*v11 = v15;
if ( (unsigned __int64)&v13[-v14 + 1] > 0x6B )
_assert_fail("p - oframe->f_buf < COUNT_OF(oframe->f_buf)", "p8_frame_encode.c", 0x4Cu, "p8_encode_tx");
v19 = v11[1];
if ( v16 > v19 || v17 < v19 )
_assert_fail(
"(iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_frame_encode.c",
0x4Eu,
"p8_encode_tx");
if ( v17 < v15 || v16 > v15 )
_assert_fail(
"(iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_frame_encode.c",
0x4Eu,
"p8_encode_tx");
if ( v19 < v15 )
_assert_fail("(iframe)->f_sta <= (iframe)->f_end", "p8_frame_encode.c", 0x4Eu, "p8_encode_tx");
if ( v8 < result || v14 > (unsigned __int64)result )
_assert_fail(
"(oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)",
"p8_frame_encode.c",
0x4Fu,
"p8_encode_tx");
v20 = *v12;
if ( (unsigned __int64)v8 < *v12 || v14 > v20 )
_assert_fail(
"(oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)",
"p8_frame_encode.c",
0x4Fu,
"p8_encode_tx");
if ( v20 > (unsigned __int64)result )
_assert_fail("(oframe)->f_sta <= (oframe)->f_end", "p8_frame_encode.c", 0x4Fu, "p8_encode_tx");
return result;
}

original_code:
void
p8_encode_tx(p8s_frame_t *oframe, p8_code_t code, p8_frame_t *iframe) {
    proto_char_t *params = iframe->f_sta;
    ((void) sizeof (((iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ; else __assert_fail ("(iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)", "p8_frame_encode.c", 60, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ; else __assert_fail ("(iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)", "p8_frame_encode.c", 60, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((iframe)->f_sta <= (iframe)->f_end) ? 1 : 0), __extension__ ({ if ((iframe)->f_sta <= (iframe)->f_end) ; else __assert_fail ("(iframe)->f_sta <= (iframe)->f_end", "p8_frame_encode.c", 60, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof (((oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ; else __assert_fail ("(oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)", "p8_frame_encode.c", 61, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ; else __assert_fail ("(oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)", "p8_frame_encode.c", 61, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((oframe)->f_sta <= (oframe)->f_end) ? 1 : 0), __extension__ ({ if ((oframe)->f_sta <= (oframe)->f_end) ; else __assert_fail ("(oframe)->f_sta <= (oframe)->f_end", "p8_frame_encode.c", 61, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof (((iframe)->f_sta < (iframe)->f_end) ? 1 : 0), __extension__ ({ if ((iframe)->f_sta < (iframe)->f_end) ; else __assert_fail ("(iframe)->f_sta < (iframe)->f_end", "p8_frame_encode.c", 62, __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_frame_encode.c", 64, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof ((p8_code_types[(code)].ct_type & 0x01) ? 1 : 0), __extension__ ({ if (p8_code_types[(code)].ct_type & 0x01) ; else __assert_fail ("p8_code_types[(code)].ct_type & P8_CT_H2A", "p8_frame_encode.c", 64, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((1) >= p8_code_types[(code)].ct_h2a_min_plen) ? 1 : 0), __extension__ ({ if ((1) >= p8_code_types[(code)].ct_h2a_min_plen) ; else __assert_fail ("(1) >= p8_code_types[(code)].ct_h2a_min_plen", "p8_frame_encode.c", 64, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((1) <= p8_code_types[(code)].ct_h2a_max_plen) ? 1 : 0), __extension__ ({ if ((1) <= p8_code_types[(code)].ct_h2a_max_plen) ; else __assert_fail ("(1) <= p8_code_types[(code)].ct_h2a_max_plen", "p8_frame_encode.c", 64, __extension__ __PRETTY_FUNCTION__); }));
    proto_char_t *p = oframe->f_end;
    *p++ = P8_FRAME_BEGIN;
    *p++ = code;
    p = encode_char(p, *params++);
    *p++ = P8_FRAME_END;
    oframe->f_end = p;
    iframe->f_sta = params;
    ((void) sizeof ((p - oframe->f_buf < ((sizeof(oframe->f_buf)/sizeof(0[oframe->f_buf])) / ((unsigned int)(!(sizeof(oframe->f_buf) % sizeof(0[oframe->f_buf])))))) ? 1 : 0), __extension__ ({ if (p - oframe->f_buf < ((sizeof(oframe->f_buf)/sizeof(0[oframe->f_buf])) / ((unsigned int)(!(sizeof(oframe->f_buf) % sizeof(0[oframe->f_buf])))))) ; else __assert_fail ("p - oframe->f_buf < COUNT_OF(oframe->f_buf)", "p8_frame_encode.c", 76, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof (((iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ; else __assert_fail ("(iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)", "p8_frame_encode.c", 78, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ; else __assert_fail ("(iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)", "p8_frame_encode.c", 78, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((iframe)->f_sta <= (iframe)->f_end) ? 1 : 0), __extension__ ({ if ((iframe)->f_sta <= (iframe)->f_end) ; else __assert_fail ("(iframe)->f_sta <= (iframe)->f_end", "p8_frame_encode.c", 78, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof (((oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ; else __assert_fail ("(oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)", "p8_frame_encode.c", 79, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ; else __assert_fail ("(oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)", "p8_frame_encode.c", 79, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((oframe)->f_sta <= (oframe)->f_end) ? 1 : 0), __extension__ ({ if ((oframe)->f_sta <= (oframe)->f_end) ; else __assert_fail ("(oframe)->f_sta <= (oframe)->f_end", "p8_frame_encode.c", 79, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
void p8_encode_tx(struct proto_frame *oframe, enum p8_code code, struct proto_frame *iframe) {
    unsigned char *params = iframe->f_sta;
    ((void) sizeof (((iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ; else __assert_fail ("(iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)", "p8_frame_encode.c", 60, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ; else __assert_fail ("(iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)", "p8_frame_encode.c", 60, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((iframe)->f_sta <= (iframe)->f_end) ? 1 : 0), __extension__ ({ if ((iframe)->f_sta <= (iframe)->f_end) ; else __assert_fail ("(iframe)->f_sta <= (iframe)->f_end", "p8_frame_encode.c", 60, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof (((oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ; else __assert_fail ("(oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)", "p8_frame_encode.c", 61, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ; else __assert_fail ("(oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)", "p8_frame_encode.c", 61, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((oframe)->f_sta <= (oframe)->f_end) ? 1 : 0), __extension__ ({ if ((oframe)->f_sta <= (oframe)->f_end) ; else __assert_fail ("(oframe)->f_sta <= (oframe)->f_end", "p8_frame_encode.c", 61, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof (((iframe)->f_sta < (iframe)->f_end) ? 1 : 0), __extension__ ({ if ((iframe)->f_sta < (iframe)->f_end) ; else __assert_fail ("(iframe)->f_sta < (iframe)->f_end", "p8_frame_encode.c", 62, __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_frame_encode.c", 64, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof ((p8_code_types[(code)].ct_type & 0x01) ? 1 : 0), __extension__ ({ if (p8_code_types[(code)].ct_type & 0x01) ; else __assert_fail ("p8_code_types[(code)].ct_type & P8_CT_H2A", "p8_frame_encode.c", 64, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((1) >= p8_code_types[(code)].ct_h2a_min_plen) ? 1 : 0), __extension__ ({ if ((1) >= p8_code_types[(code)].ct_h2a_min_plen) ; else __assert_fail ("(1) >= p8_code_types[(code)].ct_h2a_min_plen", "p8_frame_encode.c", 64, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((1) <= p8_code_types[(code)].ct_h2a_max_plen) ? 1 : 0), __extension__ ({ if ((1) <= p8_code_types[(code)].ct_h2a_max_plen) ; else __assert_fail ("(1) <= p8_code_types[(code)].ct_h2a_max_plen", "p8_frame_encode.c", 64, __extension__ __PRETTY_FUNCTION__); }));
    unsigned char *p = oframe->f_end;
    *p++ = P8_FRAME_BEGIN;
    *p++ = code;
    p = encode_char(p, *params++);
    *p++ = P8_FRAME_END;
    oframe->f_end = p;
    iframe->f_sta = params;
    ((void) sizeof ((p - oframe->f_buf < ((sizeof(oframe->f_buf)/sizeof(0[oframe->f_buf])) / ((unsigned int)(!(sizeof(oframe->f_buf) % sizeof(0[oframe->f_buf])))))) ? 1 : 0), __extension__ ({ if (p - oframe->f_buf < ((sizeof(oframe->f_buf)/sizeof(0[oframe->f_buf])) / ((unsigned int)(!(sizeof(oframe->f_buf) % sizeof(0[oframe->f_buf])))))) ; else __assert_fail ("p - oframe->f_buf < COUNT_OF(oframe->f_buf)", "p8_frame_encode.c", 76, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof (((iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ; else __assert_fail ("(iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)", "p8_frame_encode.c", 78, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ; else __assert_fail ("(iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)", "p8_frame_encode.c", 78, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((iframe)->f_sta <= (iframe)->f_end) ? 1 : 0), __extension__ ({ if ((iframe)->f_sta <= (iframe)->f_end) ; else __assert_fail ("(iframe)->f_sta <= (iframe)->f_end", "p8_frame_encode.c", 78, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof (((oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ; else __assert_fail ("(oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)", "p8_frame_encode.c", 79, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ; else __assert_fail ("(oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)", "p8_frame_encode.c", 79, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((oframe)->f_sta <= (oframe)->f_end) ? 1 : 0), __extension__ ({ if ((oframe)->f_sta <= (oframe)->f_end) ; else __assert_fail ("(oframe)->f_sta <= (oframe)->f_end", "p8_frame_encode.c", 79, __extension__ __PRETTY_FUNCTION__); }));
}

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

variable_types:
iframe
struct proto_frame *

variable_types:
p
unsigned char *

return_type: void

user_defined_types: enum p8_code { P8_CMD_NONE=0, P8_CMD_PING=1, P8_IND_ERROR_TIMEOUT=2, P8_IND_ERROR_HIGH=3, P8_IND_ERROR_LOW=4, P8_IND_RX_START=5, P8_IND_RX_NEXT=6, P8_IND_RX_FAILED=7, P8_IND_ACK=8, P8_IND_NACK=9, P8_CMD_SET_ACK_MASK=10, P8_CMD_TX=11, P8_CMD_TX_EOM=12, P8_CMD_TX_SET_IDLE=13, P8_CMD_TX_SET_ACK_P=14, P8_CMD_TX_SET_TIMEOUT=15, P8_IND_TX_SUCCEEDED=16, P8_IND_TX_FAIL_LINE=17, P8_IND_TX_FAIL_ACK=18, P8_IND_TX_TIMEOUT_D=19, P8_IND_TX_TIMEOUT_L=20, P8_QRY_FIRMWARE=21, P8_SET_CONTROLLED=24 }


decompiled_code:
__int64 __fastcall p8_read_and_dispatch(__int64 a1, unsigned __int64 *a2, __int64 a3, __int64 a4)
{
char *v4; // r14
unsigned __int64 v6; // rdx
_QWORD *v7; // r15
unsigned __int64 v8; // rax
unsigned int v10; // er13
unsigned int v11; // eax
unsigned __int64 v12; // rax
unsigned __int64 v13; // rdx

v4 = (char *)a2 + 20;
v6 = a2[1];
if ( v6 < (unsigned __int64)a2 + 20 || (v7 = a2 + 16, v6 > (unsigned __int64)(a2 + 16)) )
_assert_fail(
"(iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_io.c",
0x18u,
"p8_read_and_dispatch");
v8 = *a2;
if ( (unsigned __int64)v7 < *a2 || (unsigned __int64)v4 > v8 )
_assert_fail(
"(iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_io.c",
0x18u,
"p8_read_and_dispatch");
if ( v6 < v8 )
_assert_fail("(iframe)->f_sta <= (iframe)->f_end", "p8_io.c", 0x18u, "p8_read_and_dispatch");
v10 = p8_read();
if ( !v10 )
{
while ( 1 )
{
v12 = a2[1];
v13 = *a2;
if ( v12 <= *a2 )
break;
v11 = p8_dispatch(a2, a3, a4);
if ( v11 )
return v11;
}
if ( (unsigned __int64)v4 > v12 || (unsigned __int64)v7 < v12 )
_assert_fail(
"(iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_io.c",
0x25u,
"p8_read_and_dispatch");
if ( (unsigned __int64)v4 > v13 || (unsigned __int64)v7 < v13 )
_assert_fail(
"(iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_io.c",
0x25u,
"p8_read_and_dispatch");
if ( v12 != v13 )
_assert_fail("(iframe)->f_sta <= (iframe)->f_end", "p8_io.c", 0x25u, "p8_read_and_dispatch");
}
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned __int64 *a2, __int64 a3, __int64 a4)
{
char *v4; // r14
unsigned __int64 v6; // rdx
_QWORD *v7; // r15
unsigned __int64 v8; // rax
unsigned int v10; // er13
unsigned int v11; // eax
unsigned __int64 v12; // rax
unsigned __int64 v13; // rdx

v4 = (char *)a2 + 20;
v6 = a2[1];
if ( v6 < (unsigned __int64)a2 + 20 || (v7 = a2 + 16, v6 > (unsigned __int64)(a2 + 16)) )
_assert_fail(
"(iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_io.c",
0x18u,
"p8_read_and_dispatch");
v8 = *a2;
if ( (unsigned __int64)v7 < *a2 || (unsigned __int64)v4 > v8 )
_assert_fail(
"(iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_io.c",
0x18u,
"p8_read_and_dispatch");
if ( v6 < v8 )
_assert_fail("(iframe)->f_sta <= (iframe)->f_end", "p8_io.c", 0x18u, "p8_read_and_dispatch");
v10 = p8_read();
if ( !v10 )
{
while ( 1 )
{
v12 = a2[1];
v13 = *a2;
if ( v12 <= *a2 )
break;
v11 = p8_dispatch(a2, a3, a4);
if ( v11 )
return v11;
}
if ( (unsigned __int64)v4 > v12 || (unsigned __int64)v7 < v12 )
_assert_fail(
"(iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_io.c",
0x25u,
"p8_read_and_dispatch");
if ( (unsigned __int64)v4 > v13 || (unsigned __int64)v7 < v13 )
_assert_fail(
"(iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_io.c",
0x25u,
"p8_read_and_dispatch");
if ( v12 != v13 )
_assert_fail("(iframe)->f_sta <= (iframe)->f_end", "p8_io.c", 0x25u, "p8_read_and_dispatch");
}
return v10;
}

original_code:
int
p8_read_and_dispatch(int fd, p8s_frame_t *iframe,
        const struct proto_dispatch_table *dt, proto_callback_arg_t *cba_table) {
    ((void) sizeof (((iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ; else __assert_fail ("(iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)", "p8_io.c", 24, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ; else __assert_fail ("(iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)", "p8_io.c", 24, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((iframe)->f_sta <= (iframe)->f_end) ? 1 : 0), __extension__ ({ if ((iframe)->f_sta <= (iframe)->f_end) ; else __assert_fail ("(iframe)->f_sta <= (iframe)->f_end", "p8_io.c", 24, __extension__ __PRETTY_FUNCTION__); }));
    int rv;
    rv = p8_read(fd, iframe);
    if (rv) return rv;
    while (iframe->f_end > iframe->f_sta) {
        rv = p8_dispatch(iframe, dt, cba_table);
        if (rv) return rv;
    }
    ((void) sizeof (((iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ; else __assert_fail ("(iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)", "p8_io.c", 37, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ; else __assert_fail ("(iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)", "p8_io.c", 37, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((iframe)->f_sta <= (iframe)->f_end) ? 1 : 0), __extension__ ({ if ((iframe)->f_sta <= (iframe)->f_end) ; else __assert_fail ("(iframe)->f_sta <= (iframe)->f_end", "p8_io.c", 37, __extension__ __PRETTY_FUNCTION__); }));
    return 0;
}

canonical_original_code:
int p8_read_and_dispatch(int fd, struct proto_frame *iframe, struct proto_dispatch_table *dt, union proto_callback_arg_t *cba_table) {
    ((void) sizeof (((iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ; else __assert_fail ("(iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)", "p8_io.c", 24, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ; else __assert_fail ("(iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)", "p8_io.c", 24, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((iframe)->f_sta <= (iframe)->f_end) ? 1 : 0), __extension__ ({ if ((iframe)->f_sta <= (iframe)->f_end) ; else __assert_fail ("(iframe)->f_sta <= (iframe)->f_end", "p8_io.c", 24, __extension__ __PRETTY_FUNCTION__); }));
    int rv;
    rv = p8_read(fd, iframe);
    if (rv) return rv;
    while (iframe->f_end > iframe->f_sta) {
        rv = p8_dispatch(iframe, dt, cba_table);
        if (rv) return rv;
    }
    ((void) sizeof (((iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ; else __assert_fail ("(iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)", "p8_io.c", 37, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ; else __assert_fail ("(iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)", "p8_io.c", 37, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((iframe)->f_sta <= (iframe)->f_end) ? 1 : 0), __extension__ ({ if ((iframe)->f_sta <= (iframe)->f_end) ; else __assert_fail ("(iframe)->f_sta <= (iframe)->f_end", "p8_io.c", 37, __extension__ __PRETTY_FUNCTION__); }));
    return 0;
}

variable_types: fd int

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: rv int

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_write(int fd, __int64 a2, __int64 a3, __int64 a4)
{
unsigned __int64 v5; // r12
unsigned __int64 v6; // rdx
unsigned __int64 v7; // r13
const void *v9; // rsi
__int64 result; // rax
unsigned __int64 v11; // rdx
const void *v12; // rcx
unsigned __int64 v14[2]; // [rsp+10h] [rbp-B8h] BYREF
char v15[168]; // [rsp+20h] [rbp-A8h] BYREF

v5 = a2 + 20;
v6 = *(_QWORD *)(a2 + 8);
if ( v6 < a2 + 20 || (v7 = a2 + 128, v6 > a2 + 128) )
_assert_fail(
"(oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)",
"p8_io.c",
0x2Eu,
"p8_write");
v9 = *(const void **)a2;
if ( v5 > (unsigned __int64)v9 || v7 < (unsigned __int64)v9 )
_assert_fail(
"(oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)",
"p8_io.c",
0x2Eu,
"p8_write");
if ( v6 < (unsigned __int64)v9 )
_assert_fail("(oframe)->f_sta <= (oframe)->f_end", "p8_io.c", 0x2Eu, "p8_write");
memset(v15, 0, 0x70uLL);
v14[0] = (unsigned __int64)&v15[4];
v14[1] = (unsigned __int64)&v15[4];
if ( (_DWORD)v6 - (_DWORD)v9 != write(fd, v9, (int)v6 - (int)v9) )
return 0xFFFFFFFFLL;
result = p8_read_and_dispatch((unsigned int)fd, v14, a3, a4);
if ( !(_DWORD)result )
{
v11 = *(_QWORD *)(a2 + 8);
if ( v5 > v11 || v7 < v11 )
_assert_fail(
"(oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)",
"p8_io.c",
0x3Fu,
"p8_write");
v12 = *(const void **)a2;
if ( v7 < *(_QWORD *)a2 || v5 > (unsigned __int64)v12 )
_assert_fail(
"(oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)",
"p8_io.c",
0x3Fu,
"p8_write");
if ( v11 < (unsigned __int64)v12 )
_assert_fail("(oframe)->f_sta <= (oframe)->f_end", "p8_io.c", 0x3Fu, "p8_write");
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd, __int64 a2, __int64 a3, __int64 a4)
{
unsigned __int64 v5; // r12
unsigned __int64 v6; // rdx
unsigned __int64 v7; // r13
const void *v9; // rsi
__int64 result; // rax
unsigned __int64 v11; // rdx
const void *v12; // rcx
unsigned __int64 v14[2]; // [rsp+10h] [rbp-B8h] BYREF
char v15[168]; // [rsp+20h] [rbp-A8h] BYREF

v5 = a2 + 20;
v6 = *(_QWORD *)(a2 + 8);
if ( v6 < a2 + 20 || (v7 = a2 + 128, v6 > a2 + 128) )
_assert_fail(
"(oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)",
"p8_io.c",
0x2Eu,
"p8_write");
v9 = *(const void **)a2;
if ( v5 > (unsigned __int64)v9 || v7 < (unsigned __int64)v9 )
_assert_fail(
"(oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)",
"p8_io.c",
0x2Eu,
"p8_write");
if ( v6 < (unsigned __int64)v9 )
_assert_fail("(oframe)->f_sta <= (oframe)->f_end", "p8_io.c", 0x2Eu, "p8_write");
memset(v15, 0, 0x70uLL);
v14[0] = (unsigned __int64)&v15[4];
v14[1] = (unsigned __int64)&v15[4];
if ( (_DWORD)v6 - (_DWORD)v9 != write(fd, v9, (int)v6 - (int)v9) )
return 0xFFFFFFFFLL;
result = func0((unsigned int)fd, v14, a3, a4);
if ( !(_DWORD)result )
{
v11 = *(_QWORD *)(a2 + 8);
if ( v5 > v11 || v7 < v11 )
_assert_fail(
"(oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)",
"p8_io.c",
0x3Fu,
"p8_write");
v12 = *(const void **)a2;
if ( v7 < *(_QWORD *)a2 || v5 > (unsigned __int64)v12 )
_assert_fail(
"(oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)",
"p8_io.c",
0x3Fu,
"p8_write");
if ( v11 < (unsigned __int64)v12 )
_assert_fail("(oframe)->f_sta <= (oframe)->f_end", "p8_io.c", 0x3Fu, "p8_write");
}
return result;
}

original_code:
int
p8_write(int fd, p8s_frame_t *oframe,
         const struct proto_dispatch_table *dt, proto_callback_arg_t *cba_table) {
    ((void) sizeof (((oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ; else __assert_fail ("(oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)", "p8_io.c", 46, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ; else __assert_fail ("(oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)", "p8_io.c", 46, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((oframe)->f_sta <= (oframe)->f_end) ? 1 : 0), __extension__ ({ if ((oframe)->f_sta <= (oframe)->f_end) ; else __assert_fail ("(oframe)->f_sta <= (oframe)->f_end", "p8_io.c", 46, __extension__ __PRETTY_FUNCTION__); }));
    p8s_frame_t iframe = {
        .f_sta = iframe.f_buf,
        .f_end = iframe.f_buf,
    };
    int slen = oframe->f_end - oframe->f_sta;
    if (slen != write(fd, oframe->f_sta, slen)) {
        return -1;
    }
    int rv;
    rv = p8_read_and_dispatch(fd, &iframe, dt, cba_table);
    if (rv) return rv;
    ((void) sizeof (((oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ; else __assert_fail ("(oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)", "p8_io.c", 63, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ; else __assert_fail ("(oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)", "p8_io.c", 63, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((oframe)->f_sta <= (oframe)->f_end) ? 1 : 0), __extension__ ({ if ((oframe)->f_sta <= (oframe)->f_end) ; else __assert_fail ("(oframe)->f_sta <= (oframe)->f_end", "p8_io.c", 63, __extension__ __PRETTY_FUNCTION__); }));
    return 0;
}

canonical_original_code:
int p8_write(int fd, struct proto_frame *oframe, struct proto_dispatch_table *dt, union proto_callback_arg_t *cba_table) {
    ((void) sizeof (((oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ; else __assert_fail ("(oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)", "p8_io.c", 46, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ; else __assert_fail ("(oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)", "p8_io.c", 46, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((oframe)->f_sta <= (oframe)->f_end) ? 1 : 0), __extension__ ({ if ((oframe)->f_sta <= (oframe)->f_end) ; else __assert_fail ("(oframe)->f_sta <= (oframe)->f_end", "p8_io.c", 46, __extension__ __PRETTY_FUNCTION__); }));
    struct proto_frame iframe = {
        .f_sta = iframe.f_buf,
        .f_end = iframe.f_buf,
    };
    int slen = oframe->f_end - oframe->f_sta;
    if (slen != write(fd, oframe->f_sta, slen)) {
        return -1;
    }
    int rv;
    rv = p8_read_and_dispatch(fd, &iframe, dt, cba_table);
    if (rv) return rv;
    ((void) sizeof (((oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ; else __assert_fail ("(oframe)->f_end >= (oframe)->f_buf && (oframe)->f_end <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)", "p8_io.c", 63, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + ((sizeof((oframe)->f_buf)/sizeof(0[(oframe)->f_buf])) / ((unsigned int)(!(sizeof((oframe)->f_buf) % sizeof(0[(oframe)->f_buf])))))) ; else __assert_fail ("(oframe)->f_sta >= (oframe)->f_buf && (oframe)->f_sta <= (oframe)->f_buf + COUNT_OF((oframe)->f_buf)", "p8_io.c", 63, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((oframe)->f_sta <= (oframe)->f_end) ? 1 : 0), __extension__ ({ if ((oframe)->f_sta <= (oframe)->f_end) ; else __assert_fail ("(oframe)->f_sta <= (oframe)->f_end", "p8_io.c", 63, __extension__ __PRETTY_FUNCTION__); }));
    return 0;
}

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

variable_types: slen int

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


decompiled_code:
__int64 __fastcall p8_dispatch(unsigned __int64 *a1, __int64 a2, __int64 a3)
{
char *v3; // rbp
unsigned __int64 v4; // rax
_QWORD *v5; // r12
unsigned __int64 v7; // rdx
__int64 result; // rax
unsigned __int64 v9; // rcx
unsigned __int64 v10; // rdx
__int64 v11[2]; // [rsp+0h] [rbp-A8h] BYREF
char v12[152]; // [rsp+10h] [rbp-98h] BYREF

v3 = (char *)a1 + 20;
v4 = a1[1];
if ( v4 < (unsigned __int64)a1 + 20 || (v5 = a1 + 16, v4 > (unsigned __int64)(a1 + 16)) )
_assert_fail(
"(iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_dispatch.c",
0x17u,
"p8_dispatch");
v7 = *a1;
if ( (unsigned __int64)v3 > *a1 || (unsigned __int64)v5 < v7 )
_assert_fail(
"(iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_dispatch.c",
0x17u,
"p8_dispatch");
if ( v4 < v7 )
_assert_fail("(iframe)->f_sta <= (iframe)->f_end", "p8_dispatch.c", 0x17u, "p8_dispatch");
memset(v12, 0, 0x70uLL);
v11[0] = (__int64)&v12[4];
v11[1] = (__int64)&v12[4];
result = p8_decode(a1, v11);
if ( (int)result >= 0 )
{
v9 = a1[1];
if ( (unsigned __int64)v5 < v9 || (unsigned __int64)v3 > v9 )
_assert_fail(
"(iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_dispatch.c",
0x24u,
"p8_dispatch");
v10 = *a1;
if ( (unsigned __int64)v5 < *a1 || (unsigned __int64)v3 > v10 )
_assert_fail(
"(iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_dispatch.c",
0x24u,
"p8_dispatch");
if ( v9 < v10 )
_assert_fail("(iframe)->f_sta <= (iframe)->f_end", "p8_dispatch.c", 0x24u, "p8_dispatch");
result = proto_dispatch((unsigned __int8)result, v11, a2, a3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int64 *a1, __int64 a2, __int64 a3)
{
char *v3; // rbp
unsigned __int64 v4; // rax
_QWORD *v5; // r12
unsigned __int64 v7; // rdx
__int64 result; // rax
unsigned __int64 v9; // rcx
unsigned __int64 v10; // rdx
__int64 v11[2]; // [rsp+0h] [rbp-A8h] BYREF
char v12[152]; // [rsp+10h] [rbp-98h] BYREF

v3 = (char *)a1 + 20;
v4 = a1[1];
if ( v4 < (unsigned __int64)a1 + 20 || (v5 = a1 + 16, v4 > (unsigned __int64)(a1 + 16)) )
_assert_fail(
"(iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_dispatch.c",
0x17u,
"p8_dispatch");
v7 = *a1;
if ( (unsigned __int64)v3 > *a1 || (unsigned __int64)v5 < v7 )
_assert_fail(
"(iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_dispatch.c",
0x17u,
"p8_dispatch");
if ( v4 < v7 )
_assert_fail("(iframe)->f_sta <= (iframe)->f_end", "p8_dispatch.c", 0x17u, "p8_dispatch");
memset(v12, 0, 0x70uLL);
v11[0] = (__int64)&v12[4];
v11[1] = (__int64)&v12[4];
result = p8_decode(a1, v11);
if ( (int)result >= 0 )
{
v9 = a1[1];
if ( (unsigned __int64)v5 < v9 || (unsigned __int64)v3 > v9 )
_assert_fail(
"(iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_dispatch.c",
0x24u,
"p8_dispatch");
v10 = *a1;
if ( (unsigned __int64)v5 < *a1 || (unsigned __int64)v3 > v10 )
_assert_fail(
"(iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_dispatch.c",
0x24u,
"p8_dispatch");
if ( v9 < v10 )
_assert_fail("(iframe)->f_sta <= (iframe)->f_end", "p8_dispatch.c", 0x24u, "p8_dispatch");
result = proto_dispatch((unsigned __int8)result, v11, a2, a3);
}
return result;
}

original_code:
int
p8_dispatch(p8s_frame_t *iframe,
            const proto_dispatch_table_t *dt,
            proto_callback_arg_t *cba_table) {
    ((void) sizeof (((iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ; else __assert_fail ("(iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)", "p8_dispatch.c", 23, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ; else __assert_fail ("(iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)", "p8_dispatch.c", 23, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((iframe)->f_sta <= (iframe)->f_end) ? 1 : 0), __extension__ ({ if ((iframe)->f_sta <= (iframe)->f_end) ; else __assert_fail ("(iframe)->f_sta <= (iframe)->f_end", "p8_dispatch.c", 23, __extension__ __PRETTY_FUNCTION__); }));
    p8_frame_t oframe = {
        .f_sta = oframe.f_buf,
        .f_end = oframe.f_buf,
    };
    const int rv = p8_decode(iframe, &oframe);
    if (rv < 0) return rv;
    const proto_char_t code = rv;
    ((void) sizeof (((iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ; else __assert_fail ("(iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)", "p8_dispatch.c", 36, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ; else __assert_fail ("(iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)", "p8_dispatch.c", 36, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((iframe)->f_sta <= (iframe)->f_end) ? 1 : 0), __extension__ ({ if ((iframe)->f_sta <= (iframe)->f_end) ; else __assert_fail ("(iframe)->f_sta <= (iframe)->f_end", "p8_dispatch.c", 36, __extension__ __PRETTY_FUNCTION__); }));
    return proto_dispatch(code, &oframe, dt, cba_table);
}

canonical_original_code:
int p8_dispatch(struct proto_frame *iframe, struct proto_dispatch_table *dt, union proto_callback_arg_t *cba_table) {
    ((void) sizeof (((iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ; else __assert_fail ("(iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)", "p8_dispatch.c", 23, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ; else __assert_fail ("(iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)", "p8_dispatch.c", 23, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((iframe)->f_sta <= (iframe)->f_end) ? 1 : 0), __extension__ ({ if ((iframe)->f_sta <= (iframe)->f_end) ; else __assert_fail ("(iframe)->f_sta <= (iframe)->f_end", "p8_dispatch.c", 23, __extension__ __PRETTY_FUNCTION__); }));
    struct proto_frame oframe = {
        .f_sta = oframe.f_buf,
        .f_end = oframe.f_buf,
    };
    int rv = p8_decode(iframe, &oframe);
    if (rv < 0) return rv;
    unsigned char code = rv;
    ((void) sizeof (((iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ; else __assert_fail ("(iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)", "p8_dispatch.c", 36, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + ((sizeof((iframe)->f_buf)/sizeof(0[(iframe)->f_buf])) / ((unsigned int)(!(sizeof((iframe)->f_buf) % sizeof(0[(iframe)->f_buf])))))) ; else __assert_fail ("(iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)", "p8_dispatch.c", 36, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((iframe)->f_sta <= (iframe)->f_end) ? 1 : 0), __extension__ ({ if ((iframe)->f_sta <= (iframe)->f_end) ; else __assert_fail ("(iframe)->f_sta <= (iframe)->f_end", "p8_dispatch.c", 36, __extension__ __PRETTY_FUNCTION__); }));
    return proto_dispatch(code, &oframe, dt, cba_table);
}

variable_types:
code
unsigned char


decompiled_code:
__int64 __fastcall cec_rx_error(unsigned int a1, unsigned __int8 a2, unsigned int a3, __int64 a4)
{
fprintf(stderr, "CEC RX ERROR: state=%d, char=0x%02.2x, flags=0x%02.2x\n", a1, a2, a3);
*(_DWORD *)(a4 + 16) = 4;
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, unsigned __int8 a2, unsigned int a3, __int64 a4)
{
fprintf(stderr, "CEC RX ERROR: state=%d, char=0x%02.2x, flags=0x%02.2x\n", a1, a2, a3);
*(_DWORD *)(a4 + 16) = 4;
return 0xFFFFFFFFLL;
}

original_code:
int
cec_rx_error(cec_rx_frame_state_t state, cec_char_t c, cec_flags_t f, cec_rx_frame_t *frame) {
    fprintf(stderr, "CEC RX ERROR: state=%d, char=0x%02.2x, flags=0x%02.2x\n",
            state, c, f);
    frame->f_status = CEC_RX_ERROR;
    return -1;
}

canonical_original_code:
int cec_rx_error(enum cec_rx_frame_state state, unsigned char c, enum cec_flags f, struct proto_frame *frame) {
    fprintf(stderr, "CEC RX ERROR: state=%d, char=0x%02.2x, flags=0x%02.2x\n",
            state, c, f);
    frame->f_status = CEC_RX_ERROR;
    return -1;
}

variable_types: enum cec_rx_frame_state { CEC_RX_EMPTY=0, CEC_RX_PROGRESS=1, CEC_RX_EOM=2, CEC_RX_OVF=3, CEC_RX_ERROR=4 }

variable_types:
c
unsigned char

variable_types: enum cec_flags { CEC_ACK=1, CEC_EOM=2, CEC_START=4 }


decompiled_code:
int p8_open()
{
char v1[4104]; // [rsp+0h] [rbp-1008h] BYREF

if ( p8_detect_path(v1) )
return open(v1, 2);
*_errno_location() = 2;
return -1;
}

canonical_decompiled_code:
int func0()
{
char v1[4104]; // [rsp+0h] [rbp-1008h] BYREF

if ( p8_detect_path(v1) )
return open(v1, 2);
*_errno_location() = 2;
return -1;
}

original_code:
int
p8_open(void) {
    char path[4096];
    if (!p8_detect_path(path)) {
        (*__errno_location ()) = 2;
        return -1;
    }
    return open(path, 02);
}

canonical_original_code:
int p8_open() {
    char path[4096];
    if (!p8_detect_path(path)) {
        (*__errno_location ()) = 2;
        return -1;
    }
    return open(path, 02);
}

variable_types:
path
char [4096]


decompiled_code:
// attributes: thunk
int p8_close(int fd)
{
return close(fd);
}

canonical_decompiled_code:
int func1(int fd)
{
return close(fd);
}


original_code:
int
p8_read(int fd, p8s_frame_t *f) {
    const proto_char_t *max_end = f->f_buf + ((sizeof(f->f_buf)/sizeof(0[f->f_buf])) / ((unsigned int)(!(sizeof(f->f_buf) % sizeof(0[f->f_buf])))));
    ((void) sizeof (((f)->f_end >= (f)->f_buf && (f)->f_end <= (f)->f_buf + ((sizeof((f)->f_buf)/sizeof(0[(f)->f_buf])) / ((unsigned int)(!(sizeof((f)->f_buf) % sizeof(0[(f)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((f)->f_end >= (f)->f_buf && (f)->f_end <= (f)->f_buf + ((sizeof((f)->f_buf)/sizeof(0[(f)->f_buf])) / ((unsigned int)(!(sizeof((f)->f_buf) % sizeof(0[(f)->f_buf])))))) ; else __assert_fail ("(f)->f_end >= (f)->f_buf && (f)->f_end <= (f)->f_buf + COUNT_OF((f)->f_buf)", "p8_io_unix.c", 66, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((f)->f_sta >= (f)->f_buf && (f)->f_sta <= (f)->f_buf + ((sizeof((f)->f_buf)/sizeof(0[(f)->f_buf])) / ((unsigned int)(!(sizeof((f)->f_buf) % sizeof(0[(f)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((f)->f_sta >= (f)->f_buf && (f)->f_sta <= (f)->f_buf + ((sizeof((f)->f_buf)/sizeof(0[(f)->f_buf])) / ((unsigned int)(!(sizeof((f)->f_buf) % sizeof(0[(f)->f_buf])))))) ; else __assert_fail ("(f)->f_sta >= (f)->f_buf && (f)->f_sta <= (f)->f_buf + COUNT_OF((f)->f_buf)", "p8_io_unix.c", 66, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((f)->f_sta <= (f)->f_end) ? 1 : 0), __extension__ ({ if ((f)->f_sta <= (f)->f_end) ; else __assert_fail ("(f)->f_sta <= (f)->f_end", "p8_io_unix.c", 66, __extension__ __PRETTY_FUNCTION__); }));
    if (f->f_sta == f->f_end) {
        f->f_sta = f->f_end = f->f_buf;
    }
    if (f->f_end > f->f_buf + ((sizeof(f->f_buf)/sizeof(0[f->f_buf])) / ((unsigned int)(!(sizeof(f->f_buf) % sizeof(0[f->f_buf]))))) / 2 &&
        f->f_sta > f->f_buf + ((sizeof(f->f_buf)/sizeof(0[f->f_buf])) / ((unsigned int)(!(sizeof(f->f_buf) % sizeof(0[f->f_buf]))))) / 4) {
        memmove(f->f_buf, f->f_sta, f->f_end - f->f_sta);
        f->f_end -= f->f_sta - f->f_buf;
        f->f_sta = f->f_buf;
    }
    ((void) sizeof (((f)->f_end >= (f)->f_buf && (f)->f_end <= (f)->f_buf + ((sizeof((f)->f_buf)/sizeof(0[(f)->f_buf])) / ((unsigned int)(!(sizeof((f)->f_buf) % sizeof(0[(f)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((f)->f_end >= (f)->f_buf && (f)->f_end <= (f)->f_buf + ((sizeof((f)->f_buf)/sizeof(0[(f)->f_buf])) / ((unsigned int)(!(sizeof((f)->f_buf) % sizeof(0[(f)->f_buf])))))) ; else __assert_fail ("(f)->f_end >= (f)->f_buf && (f)->f_end <= (f)->f_buf + COUNT_OF((f)->f_buf)", "p8_io_unix.c", 79, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((f)->f_sta >= (f)->f_buf && (f)->f_sta <= (f)->f_buf + ((sizeof((f)->f_buf)/sizeof(0[(f)->f_buf])) / ((unsigned int)(!(sizeof((f)->f_buf) % sizeof(0[(f)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((f)->f_sta >= (f)->f_buf && (f)->f_sta <= (f)->f_buf + ((sizeof((f)->f_buf)/sizeof(0[(f)->f_buf])) / ((unsigned int)(!(sizeof((f)->f_buf) % sizeof(0[(f)->f_buf])))))) ; else __assert_fail ("(f)->f_sta >= (f)->f_buf && (f)->f_sta <= (f)->f_buf + COUNT_OF((f)->f_buf)", "p8_io_unix.c", 79, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((f)->f_sta <= (f)->f_end) ? 1 : 0), __extension__ ({ if ((f)->f_sta <= (f)->f_end) ; else __assert_fail ("(f)->f_sta <= (f)->f_end", "p8_io_unix.c", 79, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((f->f_end < max_end) ? 1 : 0), __extension__ ({ if (f->f_end < max_end) ; else __assert_fail ("f->f_end < max_end", "p8_io_unix.c", 81, __extension__ __PRETTY_FUNCTION__); }));
    for (;;) {
        ((void) sizeof (((f)->f_end >= (f)->f_buf && (f)->f_end <= (f)->f_buf + ((sizeof((f)->f_buf)/sizeof(0[(f)->f_buf])) / ((unsigned int)(!(sizeof((f)->f_buf) % sizeof(0[(f)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((f)->f_end >= (f)->f_buf && (f)->f_end <= (f)->f_buf + ((sizeof((f)->f_buf)/sizeof(0[(f)->f_buf])) / ((unsigned int)(!(sizeof((f)->f_buf) % sizeof(0[(f)->f_buf])))))) ; else __assert_fail ("(f)->f_end >= (f)->f_buf && (f)->f_end <= (f)->f_buf + COUNT_OF((f)->f_buf)", "p8_io_unix.c", 85, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((f)->f_sta >= (f)->f_buf && (f)->f_sta <= (f)->f_buf + ((sizeof((f)->f_buf)/sizeof(0[(f)->f_buf])) / ((unsigned int)(!(sizeof((f)->f_buf) % sizeof(0[(f)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((f)->f_sta >= (f)->f_buf && (f)->f_sta <= (f)->f_buf + ((sizeof((f)->f_buf)/sizeof(0[(f)->f_buf])) / ((unsigned int)(!(sizeof((f)->f_buf) % sizeof(0[(f)->f_buf])))))) ; else __assert_fail ("(f)->f_sta >= (f)->f_buf && (f)->f_sta <= (f)->f_buf + COUNT_OF((f)->f_buf)", "p8_io_unix.c", 85, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((f)->f_sta <= (f)->f_end) ? 1 : 0), __extension__ ({ if ((f)->f_sta <= (f)->f_end) ; else __assert_fail ("(f)->f_sta <= (f)->f_end", "p8_io_unix.c", 85, __extension__ __PRETTY_FUNCTION__); }));
        ((void) sizeof ((f->f_end < max_end) ? 1 : 0), __extension__ ({ if (f->f_end < max_end) ; else __assert_fail ("f->f_end < max_end", "p8_io_unix.c", 86, __extension__ __PRETTY_FUNCTION__); }));
        int rv = read(fd, f->f_end, max_end - f->f_end);
        if (rv <= 0) {
            return rv;
        }
        f->f_end += rv;
        ((void) sizeof (((f)->f_end >= (f)->f_buf && (f)->f_end <= (f)->f_buf + ((sizeof((f)->f_buf)/sizeof(0[(f)->f_buf])) / ((unsigned int)(!(sizeof((f)->f_buf) % sizeof(0[(f)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((f)->f_end >= (f)->f_buf && (f)->f_end <= (f)->f_buf + ((sizeof((f)->f_buf)/sizeof(0[(f)->f_buf])) / ((unsigned int)(!(sizeof((f)->f_buf) % sizeof(0[(f)->f_buf])))))) ; else __assert_fail ("(f)->f_end >= (f)->f_buf && (f)->f_end <= (f)->f_buf + COUNT_OF((f)->f_buf)", "p8_io_unix.c", 97, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((f)->f_sta >= (f)->f_buf && (f)->f_sta <= (f)->f_buf + ((sizeof((f)->f_buf)/sizeof(0[(f)->f_buf])) / ((unsigned int)(!(sizeof((f)->f_buf) % sizeof(0[(f)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((f)->f_sta >= (f)->f_buf && (f)->f_sta <= (f)->f_buf + ((sizeof((f)->f_buf)/sizeof(0[(f)->f_buf])) / ((unsigned int)(!(sizeof((f)->f_buf) % sizeof(0[(f)->f_buf])))))) ; else __assert_fail ("(f)->f_sta >= (f)->f_buf && (f)->f_sta <= (f)->f_buf + COUNT_OF((f)->f_buf)", "p8_io_unix.c", 97, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((f)->f_sta <= (f)->f_end) ? 1 : 0), __extension__ ({ if ((f)->f_sta <= (f)->f_end) ; else __assert_fail ("(f)->f_sta <= (f)->f_end", "p8_io_unix.c", 97, __extension__ __PRETTY_FUNCTION__); }));
        ((void) sizeof (((f)->f_sta < (f)->f_end) ? 1 : 0), __extension__ ({ if ((f)->f_sta < (f)->f_end) ; else __assert_fail ("(f)->f_sta < (f)->f_end", "p8_io_unix.c", 98, __extension__ __PRETTY_FUNCTION__); }));
        if (f->f_end == max_end || f->f_end[-1] == P8_FRAME_END) {
            return 0;
        }
    }
}

canonical_original_code:
int p8_read(int fd, struct proto_frame *f) {
    unsigned char *max_end = f->f_buf + ((sizeof(f->f_buf)/sizeof(0[f->f_buf])) / ((unsigned int)(!(sizeof(f->f_buf) % sizeof(0[f->f_buf])))));
    ((void) sizeof (((f)->f_end >= (f)->f_buf && (f)->f_end <= (f)->f_buf + ((sizeof((f)->f_buf)/sizeof(0[(f)->f_buf])) / ((unsigned int)(!(sizeof((f)->f_buf) % sizeof(0[(f)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((f)->f_end >= (f)->f_buf && (f)->f_end <= (f)->f_buf + ((sizeof((f)->f_buf)/sizeof(0[(f)->f_buf])) / ((unsigned int)(!(sizeof((f)->f_buf) % sizeof(0[(f)->f_buf])))))) ; else __assert_fail ("(f)->f_end >= (f)->f_buf && (f)->f_end <= (f)->f_buf + COUNT_OF((f)->f_buf)", "p8_io_unix.c", 66, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((f)->f_sta >= (f)->f_buf && (f)->f_sta <= (f)->f_buf + ((sizeof((f)->f_buf)/sizeof(0[(f)->f_buf])) / ((unsigned int)(!(sizeof((f)->f_buf) % sizeof(0[(f)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((f)->f_sta >= (f)->f_buf && (f)->f_sta <= (f)->f_buf + ((sizeof((f)->f_buf)/sizeof(0[(f)->f_buf])) / ((unsigned int)(!(sizeof((f)->f_buf) % sizeof(0[(f)->f_buf])))))) ; else __assert_fail ("(f)->f_sta >= (f)->f_buf && (f)->f_sta <= (f)->f_buf + COUNT_OF((f)->f_buf)", "p8_io_unix.c", 66, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((f)->f_sta <= (f)->f_end) ? 1 : 0), __extension__ ({ if ((f)->f_sta <= (f)->f_end) ; else __assert_fail ("(f)->f_sta <= (f)->f_end", "p8_io_unix.c", 66, __extension__ __PRETTY_FUNCTION__); }));
    if (f->f_sta == f->f_end) {
        f->f_sta = f->f_end = f->f_buf;
    }
    if (f->f_end > f->f_buf + ((sizeof(f->f_buf)/sizeof(0[f->f_buf])) / ((unsigned int)(!(sizeof(f->f_buf) % sizeof(0[f->f_buf]))))) / 2 &&
        f->f_sta > f->f_buf + ((sizeof(f->f_buf)/sizeof(0[f->f_buf])) / ((unsigned int)(!(sizeof(f->f_buf) % sizeof(0[f->f_buf]))))) / 4) {
        memmove(f->f_buf, f->f_sta, f->f_end - f->f_sta);
        f->f_end -= f->f_sta - f->f_buf;
        f->f_sta = f->f_buf;
    }
    ((void) sizeof (((f)->f_end >= (f)->f_buf && (f)->f_end <= (f)->f_buf + ((sizeof((f)->f_buf)/sizeof(0[(f)->f_buf])) / ((unsigned int)(!(sizeof((f)->f_buf) % sizeof(0[(f)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((f)->f_end >= (f)->f_buf && (f)->f_end <= (f)->f_buf + ((sizeof((f)->f_buf)/sizeof(0[(f)->f_buf])) / ((unsigned int)(!(sizeof((f)->f_buf) % sizeof(0[(f)->f_buf])))))) ; else __assert_fail ("(f)->f_end >= (f)->f_buf && (f)->f_end <= (f)->f_buf + COUNT_OF((f)->f_buf)", "p8_io_unix.c", 79, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((f)->f_sta >= (f)->f_buf && (f)->f_sta <= (f)->f_buf + ((sizeof((f)->f_buf)/sizeof(0[(f)->f_buf])) / ((unsigned int)(!(sizeof((f)->f_buf) % sizeof(0[(f)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((f)->f_sta >= (f)->f_buf && (f)->f_sta <= (f)->f_buf + ((sizeof((f)->f_buf)/sizeof(0[(f)->f_buf])) / ((unsigned int)(!(sizeof((f)->f_buf) % sizeof(0[(f)->f_buf])))))) ; else __assert_fail ("(f)->f_sta >= (f)->f_buf && (f)->f_sta <= (f)->f_buf + COUNT_OF((f)->f_buf)", "p8_io_unix.c", 79, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((f)->f_sta <= (f)->f_end) ? 1 : 0), __extension__ ({ if ((f)->f_sta <= (f)->f_end) ; else __assert_fail ("(f)->f_sta <= (f)->f_end", "p8_io_unix.c", 79, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((f->f_end < max_end) ? 1 : 0), __extension__ ({ if (f->f_end < max_end) ; else __assert_fail ("f->f_end < max_end", "p8_io_unix.c", 81, __extension__ __PRETTY_FUNCTION__); }));
    for (;;) {
        ((void) sizeof (((f)->f_end >= (f)->f_buf && (f)->f_end <= (f)->f_buf + ((sizeof((f)->f_buf)/sizeof(0[(f)->f_buf])) / ((unsigned int)(!(sizeof((f)->f_buf) % sizeof(0[(f)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((f)->f_end >= (f)->f_buf && (f)->f_end <= (f)->f_buf + ((sizeof((f)->f_buf)/sizeof(0[(f)->f_buf])) / ((unsigned int)(!(sizeof((f)->f_buf) % sizeof(0[(f)->f_buf])))))) ; else __assert_fail ("(f)->f_end >= (f)->f_buf && (f)->f_end <= (f)->f_buf + COUNT_OF((f)->f_buf)", "p8_io_unix.c", 85, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((f)->f_sta >= (f)->f_buf && (f)->f_sta <= (f)->f_buf + ((sizeof((f)->f_buf)/sizeof(0[(f)->f_buf])) / ((unsigned int)(!(sizeof((f)->f_buf) % sizeof(0[(f)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((f)->f_sta >= (f)->f_buf && (f)->f_sta <= (f)->f_buf + ((sizeof((f)->f_buf)/sizeof(0[(f)->f_buf])) / ((unsigned int)(!(sizeof((f)->f_buf) % sizeof(0[(f)->f_buf])))))) ; else __assert_fail ("(f)->f_sta >= (f)->f_buf && (f)->f_sta <= (f)->f_buf + COUNT_OF((f)->f_buf)", "p8_io_unix.c", 85, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((f)->f_sta <= (f)->f_end) ? 1 : 0), __extension__ ({ if ((f)->f_sta <= (f)->f_end) ; else __assert_fail ("(f)->f_sta <= (f)->f_end", "p8_io_unix.c", 85, __extension__ __PRETTY_FUNCTION__); }));
        ((void) sizeof ((f->f_end < max_end) ? 1 : 0), __extension__ ({ if (f->f_end < max_end) ; else __assert_fail ("f->f_end < max_end", "p8_io_unix.c", 86, __extension__ __PRETTY_FUNCTION__); }));
        int rv = read(fd, f->f_end, max_end - f->f_end);
        if (rv <= 0) {
            return rv;
        }
        f->f_end += rv;
        ((void) sizeof (((f)->f_end >= (f)->f_buf && (f)->f_end <= (f)->f_buf + ((sizeof((f)->f_buf)/sizeof(0[(f)->f_buf])) / ((unsigned int)(!(sizeof((f)->f_buf) % sizeof(0[(f)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((f)->f_end >= (f)->f_buf && (f)->f_end <= (f)->f_buf + ((sizeof((f)->f_buf)/sizeof(0[(f)->f_buf])) / ((unsigned int)(!(sizeof((f)->f_buf) % sizeof(0[(f)->f_buf])))))) ; else __assert_fail ("(f)->f_end >= (f)->f_buf && (f)->f_end <= (f)->f_buf + COUNT_OF((f)->f_buf)", "p8_io_unix.c", 97, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((f)->f_sta >= (f)->f_buf && (f)->f_sta <= (f)->f_buf + ((sizeof((f)->f_buf)/sizeof(0[(f)->f_buf])) / ((unsigned int)(!(sizeof((f)->f_buf) % sizeof(0[(f)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((f)->f_sta >= (f)->f_buf && (f)->f_sta <= (f)->f_buf + ((sizeof((f)->f_buf)/sizeof(0[(f)->f_buf])) / ((unsigned int)(!(sizeof((f)->f_buf) % sizeof(0[(f)->f_buf])))))) ; else __assert_fail ("(f)->f_sta >= (f)->f_buf && (f)->f_sta <= (f)->f_buf + COUNT_OF((f)->f_buf)", "p8_io_unix.c", 97, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((f)->f_sta <= (f)->f_end) ? 1 : 0), __extension__ ({ if ((f)->f_sta <= (f)->f_end) ; else __assert_fail ("(f)->f_sta <= (f)->f_end", "p8_io_unix.c", 97, __extension__ __PRETTY_FUNCTION__); }));
        ((void) sizeof (((f)->f_sta < (f)->f_end) ? 1 : 0), __extension__ ({ if ((f)->f_sta < (f)->f_end) ; else __assert_fail ("(f)->f_sta < (f)->f_end", "p8_io_unix.c", 98, __extension__ __PRETTY_FUNCTION__); }));
        if (f->f_end == max_end || f->f_end[-1] == P8_FRAME_END) {
            return 0;
        }
    }
}


decompiled_code:
__int64 __fastcall p8_command_nack(unsigned __int8 a1, _QWORD *a2, _DWORD *a3)
{
char *v3; // rcx
__int64 v4; // rax

if ( (unsigned int)a1 >= P8_CODE_TYPE_COUNT )
_assert_fail("(code) < P8_CODE_TYPE_COUNT", "p8_command.c", 0x29u, "p8_command_nack");
v3 = (char *)&p8_code_types + 5 * a1;
if ( (*v3 & 2) == 0 )
_assert_fail("p8_code_types[(code)].ct_type & P8_CT_A2H", "p8_command.c", 0x29u, "p8_command_nack");
v4 = a2[1] - *a2;
if ( v4 < (unsigned __int8)v3[3] )
_assert_fail(
"((params)->f_end - (params)->f_sta) >= p8_code_types[(code)].ct_a2h_min_plen",
"p8_command.c",
0x29u,
"p8_command_nack");
if ( v4 > (unsigned __int8)v3[4] )
_assert_fail(
"((params)->f_end - (params)->f_sta) <= p8_code_types[(code)].ct_a2h_max_plen",
"p8_command.c",
0x29u,
"p8_command_nack");
*a3 = 1;
puts("NACK received");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 a1, _QWORD *a2, _DWORD *a3)
{
char *v3; // rcx
__int64 v4; // rax

if ( (unsigned int)a1 >= P8_CODE_TYPE_COUNT )
_assert_fail("(code) < P8_CODE_TYPE_COUNT", "p8_command.c", 0x29u, "p8_command_nack");
v3 = (char *)&p8_code_types + 5 * a1;
if ( (*v3 & 2) == 0 )
_assert_fail("p8_code_types[(code)].ct_type & P8_CT_A2H", "p8_command.c", 0x29u, "p8_command_nack");
v4 = a2[1] - *a2;
if ( v4 < (unsigned __int8)v3[3] )
_assert_fail(
"((params)->f_end - (params)->f_sta) >= p8_code_types[(code)].ct_a2h_min_plen",
"p8_command.c",
0x29u,
"p8_command_nack");
if ( v4 > (unsigned __int8)v3[4] )
_assert_fail(
"((params)->f_end - (params)->f_sta) <= p8_code_types[(code)].ct_a2h_max_plen",
"p8_command.c",
0x29u,
"p8_command_nack");
*a3 = 1;
puts("NACK received");
return 0LL;
}

original_code:
static int
p8_command_nack(proto_char_t code,
                const p8_frame_t *params,
                proto_callback_arg_t cba) {
    ((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_command.c", 41, __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_command.c", 41, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof ((((params)->f_end - (params)->f_sta) >= p8_code_types[(code)].ct_a2h_min_plen) ? 1 : 0), __extension__ ({ if (((params)->f_end - (params)->f_sta) >= p8_code_types[(code)].ct_a2h_min_plen) ; else __assert_fail ("((params)->f_end - (params)->f_sta) >= p8_code_types[(code)].ct_a2h_min_plen", "p8_command.c", 41, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof ((((params)->f_end - (params)->f_sta) <= p8_code_types[(code)].ct_a2h_max_plen) ? 1 : 0), __extension__ ({ if (((params)->f_end - (params)->f_sta) <= p8_code_types[(code)].ct_a2h_max_plen) ; else __assert_fail ("((params)->f_end - (params)->f_sta) <= p8_code_types[(code)].ct_a2h_max_plen", "p8_command.c", 41, __extension__ __PRETTY_FUNCTION__); }));
    int *statusp = cba.cba_intp;
    *statusp = P8_NACK;
    printf("NACK received\n");
    return 0;
}

canonical_original_code:
static int p8_command_nack(unsigned char code, struct proto_frame *params, union proto_callback_arg_t cba) {
    ((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_command.c", 41, __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_command.c", 41, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof ((((params)->f_end - (params)->f_sta) >= p8_code_types[(code)].ct_a2h_min_plen) ? 1 : 0), __extension__ ({ if (((params)->f_end - (params)->f_sta) >= p8_code_types[(code)].ct_a2h_min_plen) ; else __assert_fail ("((params)->f_end - (params)->f_sta) >= p8_code_types[(code)].ct_a2h_min_plen", "p8_command.c", 41, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof ((((params)->f_end - (params)->f_sta) <= p8_code_types[(code)].ct_a2h_max_plen) ? 1 : 0), __extension__ ({ if (((params)->f_end - (params)->f_sta) <= p8_code_types[(code)].ct_a2h_max_plen) ; else __assert_fail ("((params)->f_end - (params)->f_sta) <= p8_code_types[(code)].ct_a2h_max_plen", "p8_command.c", 41, __extension__ __PRETTY_FUNCTION__); }));
    int *statusp = cba.cba_intp;
    *statusp = P8_NACK;
    printf("NACK received\n");
    return 0;
}

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

variable_types:
statusp
int *


decompiled_code:
__int64 __fastcall p8_command_ack(unsigned __int8 a1, _QWORD *a2, _DWORD *a3)
{
char *v3; // rcx
__int64 v4; // rax

if ( (unsigned int)a1 >= P8_CODE_TYPE_COUNT )
_assert_fail("(code) < P8_CODE_TYPE_COUNT", "p8_command.c", 0x1Eu, "p8_command_ack");
v3 = (char *)&p8_code_types + 5 * a1;
if ( (*v3 & 2) == 0 )
_assert_fail("p8_code_types[(code)].ct_type & P8_CT_A2H", "p8_command.c", 0x1Eu, "p8_command_ack");
v4 = a2[1] - *a2;
if ( v4 < (unsigned __int8)v3[3] )
_assert_fail(
"((params)->f_end - (params)->f_sta) >= p8_code_types[(code)].ct_a2h_min_plen",
"p8_command.c",
0x1Eu,
"p8_command_ack");
if ( v4 > (unsigned __int8)v3[4] )
_assert_fail(
"((params)->f_end - (params)->f_sta) <= p8_code_types[(code)].ct_a2h_max_plen",
"p8_command.c",
0x1Eu,
"p8_command_ack");
*a3 = 0;
puts("ACK received");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 a1, _QWORD *a2, _DWORD *a3)
{
char *v3; // rcx
__int64 v4; // rax

if ( (unsigned int)a1 >= P8_CODE_TYPE_COUNT )
_assert_fail("(code) < P8_CODE_TYPE_COUNT", "p8_command.c", 0x1Eu, "p8_command_ack");
v3 = (char *)&p8_code_types + 5 * a1;
if ( (*v3 & 2) == 0 )
_assert_fail("p8_code_types[(code)].ct_type & P8_CT_A2H", "p8_command.c", 0x1Eu, "p8_command_ack");
v4 = a2[1] - *a2;
if ( v4 < (unsigned __int8)v3[3] )
_assert_fail(
"((params)->f_end - (params)->f_sta) >= p8_code_types[(code)].ct_a2h_min_plen",
"p8_command.c",
0x1Eu,
"p8_command_ack");
if ( v4 > (unsigned __int8)v3[4] )
_assert_fail(
"((params)->f_end - (params)->f_sta) <= p8_code_types[(code)].ct_a2h_max_plen",
"p8_command.c",
0x1Eu,
"p8_command_ack");
*a3 = 0;
puts("ACK received");
return 0LL;
}

original_code:
static int
p8_command_ack(proto_char_t code,
               const p8_frame_t *params,
               proto_callback_arg_t cba) {
    ((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_command.c", 30, __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_command.c", 30, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof ((((params)->f_end - (params)->f_sta) >= p8_code_types[(code)].ct_a2h_min_plen) ? 1 : 0), __extension__ ({ if (((params)->f_end - (params)->f_sta) >= p8_code_types[(code)].ct_a2h_min_plen) ; else __assert_fail ("((params)->f_end - (params)->f_sta) >= p8_code_types[(code)].ct_a2h_min_plen", "p8_command.c", 30, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof ((((params)->f_end - (params)->f_sta) <= p8_code_types[(code)].ct_a2h_max_plen) ? 1 : 0), __extension__ ({ if (((params)->f_end - (params)->f_sta) <= p8_code_types[(code)].ct_a2h_max_plen) ; else __assert_fail ("((params)->f_end - (params)->f_sta) <= p8_code_types[(code)].ct_a2h_max_plen", "p8_command.c", 30, __extension__ __PRETTY_FUNCTION__); }));
    int *statusp = cba.cba_intp;
    *statusp = P8_ACK;
    printf("ACK received\n");
    return 0;
}

canonical_original_code:
static int p8_command_ack(unsigned char code, struct proto_frame *params, union proto_callback_arg_t cba) {
    ((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_command.c", 30, __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_command.c", 30, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof ((((params)->f_end - (params)->f_sta) >= p8_code_types[(code)].ct_a2h_min_plen) ? 1 : 0), __extension__ ({ if (((params)->f_end - (params)->f_sta) >= p8_code_types[(code)].ct_a2h_min_plen) ; else __assert_fail ("((params)->f_end - (params)->f_sta) >= p8_code_types[(code)].ct_a2h_min_plen", "p8_command.c", 30, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof ((((params)->f_end - (params)->f_sta) <= p8_code_types[(code)].ct_a2h_max_plen) ? 1 : 0), __extension__ ({ if (((params)->f_end - (params)->f_sta) <= p8_code_types[(code)].ct_a2h_max_plen) ; else __assert_fail ("((params)->f_end - (params)->f_sta) <= p8_code_types[(code)].ct_a2h_max_plen", "p8_command.c", 30, __extension__ __PRETTY_FUNCTION__); }));
    int *statusp = cba.cba_intp;
    *statusp = P8_ACK;
    printf("ACK received\n");
    return 0;
}