decompiled_code:
__int64 __fastcall p8_cec_tx_callback(unsigned __int8 a1, unsigned __int64 *a2, __int64 a3)
{
char *v3; // r8
unsigned __int64 v4; // rax
unsigned __int64 v6; // rdx
__int64 v7; // rdi
char *v8; // rdi
_QWORD *v9; // rsi

if ( (unsigned int)a1 >= P8_CODE_TYPE_COUNT )
_assert_fail("(code) < P8_CODE_TYPE_COUNT", "p8_cec_tx.c", 0x3Du, "p8_cec_tx_callback");
v3 = (char *)&p8_code_types + 5 * a1;
if ( (*v3 & 2) == 0 )
_assert_fail("p8_code_types[(code)].ct_type & P8_CT_A2H", "p8_cec_tx.c", 0x3Du, "p8_cec_tx_callback");
v4 = a2[1];
v6 = *a2;
v7 = v4 - *a2;
if ( v7 < (unsigned __int8)v3[3] )
_assert_fail(
"((frame)->f_end - (frame)->f_sta) >= p8_code_types[(code)].ct_a2h_min_plen",
"p8_cec_tx.c",
0x3Du,
"p8_cec_tx_callback");
if ( v7 > (unsigned __int8)v3[4] )
_assert_fail(
"((frame)->f_end - (frame)->f_sta) <= p8_code_types[(code)].ct_a2h_max_plen",
"p8_cec_tx.c",
0x3Du,
"p8_cec_tx_callback");
v8 = (char *)a2 + 20;
if ( v4 < (unsigned __int64)a2 + 20 || (v9 = a2 + 16, v4 > (unsigned __int64)v9) )
_assert_fail(
"(frame)->f_end >= (frame)->f_buf && (frame)->f_end <= (frame)->f_buf + COUNT_OF((frame)->f_buf)",
"p8_cec_tx.c",
0x3Eu,
"p8_cec_tx_callback");
if ( v6 < (unsigned __int64)v8 || v6 > (unsigned __int64)v9 )
_assert_fail(
"(frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + COUNT_OF((frame)->f_buf)",
"p8_cec_tx.c",
0x3Eu,
"p8_cec_tx_callback");
if ( v4 < v6 )
_assert_fail("(frame)->f_sta <= (frame)->f_end", "p8_cec_tx.c", 0x3Eu, "p8_cec_tx_callback");
if ( v4 != v6 )
_assert_fail("(frame)->f_sta == (frame)->f_end", "p8_cec_tx.c", 0x3Fu, "p8_cec_tx_callback");
*(_DWORD *)(a3 + 16) = 0;
puts("CEC TX: SUCCEEDED");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int8 a1, unsigned __int64 *a2, __int64 a3)
{
char *v3; // r8
unsigned __int64 v4; // rax
unsigned __int64 v6; // rdx
__int64 v7; // rdi
char *v8; // rdi
_QWORD *v9; // rsi

if ( (unsigned int)a1 >= P8_CODE_TYPE_COUNT )
_assert_fail("(code) < P8_CODE_TYPE_COUNT", "p8_cec_tx.c", 0x3Du, "p8_cec_tx_callback");
v3 = (char *)&p8_code_types + 5 * a1;
if ( (*v3 & 2) == 0 )
_assert_fail("p8_code_types[(code)].ct_type & P8_CT_A2H", "p8_cec_tx.c", 0x3Du, "p8_cec_tx_callback");
v4 = a2[1];
v6 = *a2;
v7 = v4 - *a2;
if ( v7 < (unsigned __int8)v3[3] )
_assert_fail(
"((frame)->f_end - (frame)->f_sta) >= p8_code_types[(code)].ct_a2h_min_plen",
"p8_cec_tx.c",
0x3Du,
"p8_cec_tx_callback");
if ( v7 > (unsigned __int8)v3[4] )
_assert_fail(
"((frame)->f_end - (frame)->f_sta) <= p8_code_types[(code)].ct_a2h_max_plen",
"p8_cec_tx.c",
0x3Du,
"p8_cec_tx_callback");
v8 = (char *)a2 + 20;
if ( v4 < (unsigned __int64)a2 + 20 || (v9 = a2 + 16, v4 > (unsigned __int64)v9) )
_assert_fail(
"(frame)->f_end >= (frame)->f_buf && (frame)->f_end <= (frame)->f_buf + COUNT_OF((frame)->f_buf)",
"p8_cec_tx.c",
0x3Eu,
"p8_cec_tx_callback");
if ( v6 < (unsigned __int64)v8 || v6 > (unsigned __int64)v9 )
_assert_fail(
"(frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + COUNT_OF((frame)->f_buf)",
"p8_cec_tx.c",
0x3Eu,
"p8_cec_tx_callback");
if ( v4 < v6 )
_assert_fail("(frame)->f_sta <= (frame)->f_end", "p8_cec_tx.c", 0x3Eu, "p8_cec_tx_callback");
if ( v4 != v6 )
_assert_fail("(frame)->f_sta == (frame)->f_end", "p8_cec_tx.c", 0x3Fu, "p8_cec_tx_callback");
*(_DWORD *)(a3 + 16) = 0;
puts("CEC TX: SUCCEEDED");
return 0LL;
}

original_code:
int
p8_cec_tx_callback(proto_char_t code,
                   const p8_frame_t *frame,
                   proto_callback_arg_t cba) {
    cec_tx_frame_t * const oframe = cba.cba_frame;
    ((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_cec_tx.c", 61, __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_cec_tx.c", 61, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof ((((frame)->f_end - (frame)->f_sta) >= p8_code_types[(code)].ct_a2h_min_plen) ? 1 : 0), __extension__ ({ if (((frame)->f_end - (frame)->f_sta) >= p8_code_types[(code)].ct_a2h_min_plen) ; else __assert_fail ("((frame)->f_end - (frame)->f_sta) >= p8_code_types[(code)].ct_a2h_min_plen", "p8_cec_tx.c", 61, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof ((((frame)->f_end - (frame)->f_sta) <= p8_code_types[(code)].ct_a2h_max_plen) ? 1 : 0), __extension__ ({ if (((frame)->f_end - (frame)->f_sta) <= p8_code_types[(code)].ct_a2h_max_plen) ; else __assert_fail ("((frame)->f_end - (frame)->f_sta) <= p8_code_types[(code)].ct_a2h_max_plen", "p8_cec_tx.c", 61, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof (((frame)->f_end >= (frame)->f_buf && (frame)->f_end <= (frame)->f_buf + ((sizeof((frame)->f_buf)/sizeof(0[(frame)->f_buf])) / ((unsigned int)(!(sizeof((frame)->f_buf) % sizeof(0[(frame)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((frame)->f_end >= (frame)->f_buf && (frame)->f_end <= (frame)->f_buf + ((sizeof((frame)->f_buf)/sizeof(0[(frame)->f_buf])) / ((unsigned int)(!(sizeof((frame)->f_buf) % sizeof(0[(frame)->f_buf])))))) ; else __assert_fail ("(frame)->f_end >= (frame)->f_buf && (frame)->f_end <= (frame)->f_buf + COUNT_OF((frame)->f_buf)", "p8_cec_tx.c", 62, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + ((sizeof((frame)->f_buf)/sizeof(0[(frame)->f_buf])) / ((unsigned int)(!(sizeof((frame)->f_buf) % sizeof(0[(frame)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + ((sizeof((frame)->f_buf)/sizeof(0[(frame)->f_buf])) / ((unsigned int)(!(sizeof((frame)->f_buf) % sizeof(0[(frame)->f_buf])))))) ; else __assert_fail ("(frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + COUNT_OF((frame)->f_buf)", "p8_cec_tx.c", 62, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((frame)->f_sta <= (frame)->f_end) ? 1 : 0), __extension__ ({ if ((frame)->f_sta <= (frame)->f_end) ; else __assert_fail ("(frame)->f_sta <= (frame)->f_end", "p8_cec_tx.c", 62, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof (((frame)->f_sta == (frame)->f_end) ? 1 : 0), __extension__ ({ if ((frame)->f_sta == (frame)->f_end) ; else __assert_fail ("(frame)->f_sta == (frame)->f_end", "p8_cec_tx.c", 63, __extension__ __PRETTY_FUNCTION__); }));
    oframe->f_status = CEC_TX_SUCCEEDED;
    printf("CEC TX: SUCCEEDED\n");
    return 0;
}

canonical_original_code:
int p8_cec_tx_callback(unsigned char code, struct proto_frame *frame, union proto_callback_arg_t cba) {
    struct proto_frame *oframe = cba.cba_frame;
    ((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_cec_tx.c", 61, __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_cec_tx.c", 61, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof ((((frame)->f_end - (frame)->f_sta) >= p8_code_types[(code)].ct_a2h_min_plen) ? 1 : 0), __extension__ ({ if (((frame)->f_end - (frame)->f_sta) >= p8_code_types[(code)].ct_a2h_min_plen) ; else __assert_fail ("((frame)->f_end - (frame)->f_sta) >= p8_code_types[(code)].ct_a2h_min_plen", "p8_cec_tx.c", 61, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof ((((frame)->f_end - (frame)->f_sta) <= p8_code_types[(code)].ct_a2h_max_plen) ? 1 : 0), __extension__ ({ if (((frame)->f_end - (frame)->f_sta) <= p8_code_types[(code)].ct_a2h_max_plen) ; else __assert_fail ("((frame)->f_end - (frame)->f_sta) <= p8_code_types[(code)].ct_a2h_max_plen", "p8_cec_tx.c", 61, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof (((frame)->f_end >= (frame)->f_buf && (frame)->f_end <= (frame)->f_buf + ((sizeof((frame)->f_buf)/sizeof(0[(frame)->f_buf])) / ((unsigned int)(!(sizeof((frame)->f_buf) % sizeof(0[(frame)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((frame)->f_end >= (frame)->f_buf && (frame)->f_end <= (frame)->f_buf + ((sizeof((frame)->f_buf)/sizeof(0[(frame)->f_buf])) / ((unsigned int)(!(sizeof((frame)->f_buf) % sizeof(0[(frame)->f_buf])))))) ; else __assert_fail ("(frame)->f_end >= (frame)->f_buf && (frame)->f_end <= (frame)->f_buf + COUNT_OF((frame)->f_buf)", "p8_cec_tx.c", 62, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + ((sizeof((frame)->f_buf)/sizeof(0[(frame)->f_buf])) / ((unsigned int)(!(sizeof((frame)->f_buf) % sizeof(0[(frame)->f_buf])))))) ? 1 : 0), __extension__ ({ if ((frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + ((sizeof((frame)->f_buf)/sizeof(0[(frame)->f_buf])) / ((unsigned int)(!(sizeof((frame)->f_buf) % sizeof(0[(frame)->f_buf])))))) ; else __assert_fail ("(frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + COUNT_OF((frame)->f_buf)", "p8_cec_tx.c", 62, __extension__ __PRETTY_FUNCTION__); })), ((void) sizeof (((frame)->f_sta <= (frame)->f_end) ? 1 : 0), __extension__ ({ if ((frame)->f_sta <= (frame)->f_end) ; else __assert_fail ("(frame)->f_sta <= (frame)->f_end", "p8_cec_tx.c", 62, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof (((frame)->f_sta == (frame)->f_end) ? 1 : 0), __extension__ ({ if ((frame)->f_sta == (frame)->f_end) ; else __assert_fail ("(frame)->f_sta == (frame)->f_end", "p8_cec_tx.c", 63, __extension__ __PRETTY_FUNCTION__); }));
    oframe->f_status = CEC_TX_SUCCEEDED;
    printf("CEC TX: SUCCEEDED\n");
    return 0;
}


repo: pekkanikander/MacCEC

decompiled_code:
__int64 __fastcall p8_cec_tx(unsigned int a1, char a2, __int64 a3, unsigned __int64 *a4)
{
unsigned __int64 v5; // rax
unsigned __int64 v6; // rdx
unsigned __int64 v7; // r13
unsigned __int64 v8; // rax
unsigned __int64 v9; // rdx
char *v10; // r14
_QWORD *v12; // r15
unsigned __int64 v13; // rax
__int64 v14; // rax
int v15; // eax
char *v16; // rsi
unsigned __int64 v17; // rdx
unsigned __int64 v18; // rax
unsigned __int64 v19; // rdx
unsigned __int64 v20; // rax
unsigned __int64 v22; // [rsp+0h] [rbp-198h]
unsigned int v23; // [rsp+Ch] [rbp-18Ch]
int v24; // [rsp+18h] [rbp-180h] BYREF
int v25; // [rsp+1Ch] [rbp-17Ch] BYREF
__int128 v26; // [rsp+20h] [rbp-178h] BYREF
unsigned __int64 *v27; // [rsp+30h] [rbp-168h]
int *v28; // [rsp+38h] [rbp-160h]
int *v29; // [rsp+40h] [rbp-158h]
__int64 v30; // [rsp+48h] [rbp-150h]
__int128 v31; // [rsp+50h] [rbp-148h]
char *v32; // [rsp+60h] [rbp-138h] BYREF
char *v33; // [rsp+68h] [rbp-130h]
char v34[112]; // [rsp+70h] [rbp-128h] BYREF
__int64 v35[2]; // [rsp+E0h] [rbp-B8h] BYREF
char v36[168]; // [rsp+F0h] [rbp-A8h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, char a2, __int64 a3, unsigned __int64 *a4)
{
unsigned __int64 v5; // rax
unsigned __int64 v6; // rdx
unsigned __int64 v7; // r13
unsigned __int64 v8; // rax
unsigned __int64 v9; // rdx
char *v10; // r14
_QWORD *v12; // r15
unsigned __int64 v13; // rax
__int64 v14; // rax
int v15; // eax
char *v16; // rsi
unsigned __int64 v17; // rdx
unsigned __int64 v18; // rax
unsigned __int64 v19; // rdx
unsigned __int64 v20; // rax
unsigned __int64 v22; // [rsp+0h] [rbp-198h]
unsigned int v23; // [rsp+Ch] [rbp-18Ch]
int v24; // [rsp+18h] [rbp-180h] BYREF
int v25; // [rsp+1Ch] [rbp-17Ch] BYREF
__int128 v26; // [rsp+20h] [rbp-178h] BYREF
unsigned __int64 *v27; // [rsp+30h] [rbp-168h]
int *v28; // [rsp+38h] [rbp-160h]
int *v29; // [rsp+40h] [rbp-158h]
__int64 v30; // [rsp+48h] [rbp-150h]
__int128 v31; // [rsp+50h] [rbp-148h]
char *v32; // [rsp+60h] [rbp-138h] BYREF
char *v33; // [rsp+68h] [rbp-130h]
char v34[112]; // [rsp+70h] [rbp-128h] BYREF
__int64 v35[2]; // [rsp+E0h] [rbp-B8h] BYREF
char v36[168]; // [rsp+F0h] [rbp-A8h] BYREF

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

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

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

variable_types: fd int

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

variable_types: union proto_callback_arg_t { int cba_int; int *cba_intp; struct proto_frame { unsigned char *f_sta; unsigned char *f_end; int f_status; unsigned char f_buf[-1]; } *cba_frame; } [-1]

variable_types:
idle
unsigned char

variable_types: rv int

return_type: int

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


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

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

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

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

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

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

variable_types:
code
unsigned char

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

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

variable_types:
index
unsigned char

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


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

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

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

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

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

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

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

variable_types:
p
unsigned char *

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


decompiled_code:
__int64 __fastcall p8_frame_error(unsigned int a1, unsigned __int64 *a2)
{
__int64 v2; // rdx
char *v3; // rdi
unsigned __int64 v4; // rcx
_QWORD *v6; // rsi
unsigned __int64 v7; // rax
unsigned __int8 *v8; // rbx
__int64 v9; // rdx

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

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, unsigned __int64 *a2)
{
__int64 v2; // rdx
char *v3; // rdi
unsigned __int64 v4; // rcx
_QWORD *v6; // rsi
unsigned __int64 v7; // rax
unsigned __int8 *v8; // rbx
__int64 v9; // rdx

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

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

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

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