decompiled_code:
__int64 __fastcall p8_command(unsigned int a1, __int64 a2, __int64 a3, unsigned int a4, unsigned __int64 *a5)
{
char *v5; // rbp
unsigned __int64 v6; // rax
_QWORD *v7; // r12
unsigned __int64 v10; // rcx
unsigned __int64 v11; // rax
unsigned __int64 v12; // rdx
unsigned int v14; // [rsp+Ch] [rbp-ECh] BYREF
__int128 v15; // [rsp+10h] [rbp-E8h] BYREF
unsigned __int64 *v16; // [rsp+20h] [rbp-D8h]
unsigned int *v17; // [rsp+28h] [rbp-D0h]
__int128 v18; // [rsp+30h] [rbp-C8h]
__int128 v19; // [rsp+40h] [rbp-B8h]
__int64 v20[2]; // [rsp+50h] [rbp-A8h] BYREF
char v21[152]; // [rsp+60h] [rbp-98h] BYREF

v5 = (char *)a5 + 20;
v6 = a5[1];
if ( v6 < (unsigned __int64)a5 + 20 || (v7 = a5 + 16, v6 > (unsigned __int64)(a5 + 16)) )
_assert_fail(
"(iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_command.c",
0x47u,
"p8_command");
v10 = *a5;
if ( (unsigned __int64)v5 > *a5 || (unsigned __int64)v7 < v10 )
_assert_fail(
"(iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_command.c",
0x47u,
"p8_command");
if ( v6 < v10 )
_assert_fail("(iframe)->f_sta <= (iframe)->f_end", "p8_command.c", 0x47u, "p8_command");
memset(v21, 0, 0x70uLL);
v20[0] = (__int64)&v21[4];
v20[1] = (__int64)&v21[4];
p8_encode_cmd(v20, a2, a3, a4);
*((_QWORD *)&v18 + 1) = 0LL;
*(_QWORD *)&v15 = 0LL;
v14 = -1;
*((_QWORD *)&v15 + 1) = a5;
v16 = a5;
v17 = &v14;
*(_QWORD *)&v18 = &v14;
v19 = 0LL;
if ( (int)p8_write(a1, v20, "\b", &v15) < 0 )
v14 = -1;
v11 = a5[1];
if ( (unsigned __int64)v7 < v11 || (unsigned __int64)v5 > v11 )
_assert_fail(
"(iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_command.c",
0x62u,
"p8_command");
v12 = *a5;
if ( (unsigned __int64)v5 > *a5 || (unsigned __int64)v7 < v12 )
_assert_fail(
"(iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_command.c",
0x62u,
"p8_command");
if ( v11 < v12 )
_assert_fail("(iframe)->f_sta <= (iframe)->f_end", "p8_command.c", 0x62u, "p8_command");
return v14;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, __int64 a2, __int64 a3, unsigned int a4, unsigned __int64 *a5)
{
char *v5; // rbp
unsigned __int64 v6; // rax
_QWORD *v7; // r12
unsigned __int64 v10; // rcx
unsigned __int64 v11; // rax
unsigned __int64 v12; // rdx
unsigned int v14; // [rsp+Ch] [rbp-ECh] BYREF
__int128 v15; // [rsp+10h] [rbp-E8h] BYREF
unsigned __int64 *v16; // [rsp+20h] [rbp-D8h]
unsigned int *v17; // [rsp+28h] [rbp-D0h]
__int128 v18; // [rsp+30h] [rbp-C8h]
__int128 v19; // [rsp+40h] [rbp-B8h]
__int64 v20[2]; // [rsp+50h] [rbp-A8h] BYREF
char v21[152]; // [rsp+60h] [rbp-98h] BYREF

v5 = (char *)a5 + 20;
v6 = a5[1];
if ( v6 < (unsigned __int64)a5 + 20 || (v7 = a5 + 16, v6 > (unsigned __int64)(a5 + 16)) )
_assert_fail(
"(iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_command.c",
0x47u,
"p8_command");
v10 = *a5;
if ( (unsigned __int64)v5 > *a5 || (unsigned __int64)v7 < v10 )
_assert_fail(
"(iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_command.c",
0x47u,
"p8_command");
if ( v6 < v10 )
_assert_fail("(iframe)->f_sta <= (iframe)->f_end", "p8_command.c", 0x47u, "p8_command");
memset(v21, 0, 0x70uLL);
v20[0] = (__int64)&v21[4];
v20[1] = (__int64)&v21[4];
p8_encode_cmd(v20, a2, a3, a4);
*((_QWORD *)&v18 + 1) = 0LL;
*(_QWORD *)&v15 = 0LL;
v14 = -1;
*((_QWORD *)&v15 + 1) = a5;
v16 = a5;
v17 = &v14;
*(_QWORD *)&v18 = &v14;
v19 = 0LL;
if ( (int)p8_write(a1, v20, "\b", &v15) < 0 )
v14 = -1;
v11 = a5[1];
if ( (unsigned __int64)v7 < v11 || (unsigned __int64)v5 > v11 )
_assert_fail(
"(iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_command.c",
0x62u,
"p8_command");
v12 = *a5;
if ( (unsigned __int64)v5 > *a5 || (unsigned __int64)v7 < v12 )
_assert_fail(
"(iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_command.c",
0x62u,
"p8_command");
if ( v11 < v12 )
_assert_fail("(iframe)->f_sta <= (iframe)->f_end", "p8_command.c", 0x62u, "p8_command");
return v14;
}

original_code:
int
p8_command(int fd, p8_code_t code,
           proto_char_t *params, proto_len_t len,
           cec_rx_frame_t *iframe) {
    ((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_command.c", 71, __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_command.c", 71, __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_command.c", 71, __extension__ __PRETTY_FUNCTION__); }));
    p8s_frame_t oframe = {
        .f_sta = oframe.f_buf,
        .f_end = oframe.f_buf,
        .f_status = 0,
    };
    p8_encode_cmd(&oframe, code, params, len);
    int status = P8_ERROR;
    proto_callback_arg_t cba_table[((sizeof(p8_command_callbacks)/sizeof(0[p8_command_callbacks])) / ((unsigned int)(!(sizeof(p8_command_callbacks) % sizeof(0[p8_command_callbacks])))))] = {
        { .cba_int = 0 },
        { .cba_frame = iframe },
        { .cba_frame = iframe },
        { .cba_intp = &status },
        { .cba_intp = &status },
        { .cba_int = 0 },
        { .cba_int = 0 },
        { .cba_int = 0 },
    };
    if (p8_write(fd, &oframe, &p8_command_dt, cba_table) < 0) {
        status = P8_ERROR;
    }
    ((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_command.c", 98, __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_command.c", 98, __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_command.c", 98, __extension__ __PRETTY_FUNCTION__); }));
    return status;
}

canonical_original_code:
int p8_command(int fd, enum p8_code code, unsigned char *params, unsigned int len, struct proto_frame *iframe) {
    ((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_command.c", 71, __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_command.c", 71, __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_command.c", 71, __extension__ __PRETTY_FUNCTION__); }));
    struct proto_frame oframe = {
        .f_sta = oframe.f_buf,
        .f_end = oframe.f_buf,
        .f_status = 0,
    };
    p8_encode_cmd(&oframe, code, params, len);
    int status = P8_ERROR;
    union proto_callback_arg_t cba_table[-1] = {
        { .cba_int = 0 },
        { .cba_frame = iframe },
        { .cba_frame = iframe },
        { .cba_intp = &status },
        { .cba_intp = &status },
        { .cba_int = 0 },
        { .cba_int = 0 },
        { .cba_int = 0 },
    };
    if (p8_write(fd, &oframe, &p8_command_dt, cba_table) < 0) {
        status = P8_ERROR;
    }
    ((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_command.c", 98, __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_command.c", 98, __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_command.c", 98, __extension__ __PRETTY_FUNCTION__); }));
    return status;
}

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:
len
unsigned int

variable_types: status int

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]


repo: pekkanikander/MacCEC

decompiled_code:
__int64 __fastcall p8_command1(unsigned int a1, __int64 a2, char a3, unsigned __int64 *a4)
{
char v5[9]; // [rsp+Fh] [rbp-9h] BYREF

v5[0] = a3;
return p8_command(a1, a2, (__int64)v5, 1u, a4);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, __int64 a2, char a3, unsigned __int64 *a4)
{
char v5[9]; // [rsp+Fh] [rbp-9h] BYREF

v5[0] = a3;
return func2(a1, a2, (__int64)v5, 1u, a4);
}

original_code:
int
p8_command1(int fd, enum p8_code code, proto_char_t param,
            proto_frame_t *iframe) {
    proto_char_t c = param;
    return p8_command(fd, code, &c, 1, iframe);
}

canonical_original_code:
int p8_command1(int fd, enum p8_code code, unsigned char param, struct proto_frame *iframe) {
    unsigned char c = param;
    return p8_command(fd, code, &c, 1, iframe);
}

variable_types: fd int

variable_types:
param
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:
c
unsigned char

return_type: int

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_cec_rx_error_cb(char a1, unsigned __int64 *a2, __int64 a3)
{
char *v3; // rcx
unsigned __int64 v4; // rax
unsigned __int8 **v6; // rsi
unsigned __int64 v8; // rdx
unsigned int v9; // er12

v3 = (char *)a2 + 20;
v4 = a2[1];
if ( v4 < (unsigned __int64)a2 + 20 || (v6 = (unsigned __int8 **)(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_cec_rx.c",
0x2Bu,
"p8_cec_rx_error_cb");
v8 = *a2;
if ( (unsigned __int64)v3 > *a2 || (unsigned __int64)v6 < v8 )
_assert_fail(
"(frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + COUNT_OF((frame)->f_buf)",
"p8_cec_rx.c",
0x2Bu,
"p8_cec_rx_error_cb");
if ( v4 < v8 )
_assert_fail("(frame)->f_sta <= (frame)->f_end", "p8_cec_rx.c", 0x2Bu, "p8_cec_rx_error_cb");
v9 = (a1 >> 6) & 2 | ((int)(unsigned __int8)a1 >> 6) & 1;
printf("CEC RX: error callback 0x%02.2x %s\n", (unsigned __int8)a1, (const char *)*(&CEC_FLAGS_TO_STRING + v9));
return cec_rx_error(4LL, *(unsigned __int8 *)*a2, v9, a3);
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1, unsigned __int64 *a2, __int64 a3)
{
char *v3; // rcx
unsigned __int64 v4; // rax
unsigned __int8 **v6; // rsi
unsigned __int64 v8; // rdx
unsigned int v9; // er12

v3 = (char *)a2 + 20;
v4 = a2[1];
if ( v4 < (unsigned __int64)a2 + 20 || (v6 = (unsigned __int8 **)(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_cec_rx.c",
0x2Bu,
"p8_cec_rx_error_cb");
v8 = *a2;
if ( (unsigned __int64)v3 > *a2 || (unsigned __int64)v6 < v8 )
_assert_fail(
"(frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + COUNT_OF((frame)->f_buf)",
"p8_cec_rx.c",
0x2Bu,
"p8_cec_rx_error_cb");
if ( v4 < v8 )
_assert_fail("(frame)->f_sta <= (frame)->f_end", "p8_cec_rx.c", 0x2Bu, "p8_cec_rx_error_cb");
v9 = (a1 >> 6) & 2 | ((int)(unsigned __int8)a1 >> 6) & 1;
printf("CEC RX: error callback 0x%02.2x %s\n", (unsigned __int8)a1, (const char *)*(&CEC_FLAGS_TO_STRING + v9));
return cec_rx_error(4LL, *(unsigned __int8 *)*a2, v9, a3);
}

original_code:
int
p8_cec_rx_error_cb(proto_char_t code,
                   const p8_frame_t *frame,
                   proto_callback_arg_t cba) {
    ((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_rx.c", 43, __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_rx.c", 43, __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_rx.c", 43, __extension__ __PRETTY_FUNCTION__); }));
    cec_flags_t flags = ((((code) & 0x40)? CEC_ACK: 0) | (((code) & 0x80)? CEC_EOM: 0));
    cec_rx_frame_t * const iframe = cba.cba_frame;
    printf("CEC RX: error callback 0x%02.2x %s\n", code, CEC_FLAGS_TO_STRING[flags]);
    return cec_rx_error(CEC_RX_ERROR, frame->f_sta[0], flags, iframe);
}

canonical_original_code:
int p8_cec_rx_error_cb(unsigned char code, struct proto_frame *frame, union proto_callback_arg_t cba) {
    ((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_rx.c", 43, __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_rx.c", 43, __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_rx.c", 43, __extension__ __PRETTY_FUNCTION__); }));
    enum cec_flags flags = ((((code) & 0x40)? CEC_ACK: 0) | (((code) & 0x80)? CEC_EOM: 0));
    struct proto_frame *iframe = cba.cba_frame;
    printf("CEC RX: error callback 0x%02.2x %s\n", code, CEC_FLAGS_TO_STRING[flags]);
    return cec_rx_error(CEC_RX_ERROR, frame->f_sta[0], flags, iframe);
}

variable_types:
code
unsigned char

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

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

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_cec_rx_callback(char a1, unsigned __int8 **a2, __int64 a3)
{
char *v4; // r12
unsigned __int64 v5; // rdx
unsigned __int8 **v6; // r13
unsigned __int8 *v8; // rax
__int64 v9; // rsi
unsigned __int8 v11; // di
__int64 v12; // rbp
unsigned __int8 *v13; // rax
unsigned __int8 *v14; // rdx

v4 = (char *)a2 + 20;
v5 = (unsigned __int64)a2[1];
if ( v5 < (unsigned __int64)a2 + 20 || (v6 = a2 + 16, 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_cec_rx.c",
0x3Eu,
"p8_cec_rx_callback");
v8 = *a2;
if ( v4 > (char *)*a2 || v6 < (unsigned __int8 **)v8 )
_assert_fail(
"(frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + COUNT_OF((frame)->f_buf)",
"p8_cec_rx.c",
0x3Eu,
"p8_cec_rx_callback");
if ( v5 < (unsigned __int64)v8 )
_assert_fail("(frame)->f_sta <= (frame)->f_end", "p8_cec_rx.c", 0x3Eu, "p8_cec_rx_callback");
v9 = (unsigned __int8)a1;
v11 = a1 & 0x3F;
v12 = (a1 >> 6) & 2 | ((int)v9 >> 6) & 1u;
if ( v11 == 5 )
{
LODWORD(v12) = v12 | 4;
}
else if ( v11 != 6 )
{
printf("CEC RX: error code 0x%02.2x %s, swcode = 0x%02.2x\n", v9, (const char *)*(&CEC_FLAGS_TO_STRING + v12), v11);
_assert_fail("0", "p8_cec_rx.c", 0x4Eu, "p8_cec_rx_callback");
}
printf("CEC RX: char 0x%02.2x %s\n", *v8, (const char *)*(&CEC_FLAGS_TO_STRING + (unsigned int)v12));
cec_rx_char_cb(**a2, (unsigned int)v12, a3);
v13 = a2[1];
if ( v6 < (unsigned __int8 **)v13 || v4 > (char *)v13 )
_assert_fail(
"(frame)->f_end >= (frame)->f_buf && (frame)->f_end <= (frame)->f_buf + COUNT_OF((frame)->f_buf)",
"p8_cec_rx.c",
0x51u,
"p8_cec_rx_callback");
v14 = *a2;
if ( v4 > (char *)*a2 || v6 < (unsigned __int8 **)v14 )
_assert_fail(
"(frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + COUNT_OF((frame)->f_buf)",
"p8_cec_rx.c",
0x51u,
"p8_cec_rx_callback");
if ( v13 < v14 )
_assert_fail("(frame)->f_sta <= (frame)->f_end", "p8_cec_rx.c", 0x51u, "p8_cec_rx_callback");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char a1, unsigned __int8 **a2, __int64 a3)
{
char *v4; // r12
unsigned __int64 v5; // rdx
unsigned __int8 **v6; // r13
unsigned __int8 *v8; // rax
__int64 v9; // rsi
unsigned __int8 v11; // di
__int64 v12; // rbp
unsigned __int8 *v13; // rax
unsigned __int8 *v14; // rdx

v4 = (char *)a2 + 20;
v5 = (unsigned __int64)a2[1];
if ( v5 < (unsigned __int64)a2 + 20 || (v6 = a2 + 16, 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_cec_rx.c",
0x3Eu,
"p8_cec_rx_callback");
v8 = *a2;
if ( v4 > (char *)*a2 || v6 < (unsigned __int8 **)v8 )
_assert_fail(
"(frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + COUNT_OF((frame)->f_buf)",
"p8_cec_rx.c",
0x3Eu,
"p8_cec_rx_callback");
if ( v5 < (unsigned __int64)v8 )
_assert_fail("(frame)->f_sta <= (frame)->f_end", "p8_cec_rx.c", 0x3Eu, "p8_cec_rx_callback");
v9 = (unsigned __int8)a1;
v11 = a1 & 0x3F;
v12 = (a1 >> 6) & 2 | ((int)v9 >> 6) & 1u;
if ( v11 == 5 )
{
LODWORD(v12) = v12 | 4;
}
else if ( v11 != 6 )
{
printf("CEC RX: error code 0x%02.2x %s, swcode = 0x%02.2x\n", v9, (const char *)*(&CEC_FLAGS_TO_STRING + v12), v11);
_assert_fail("0", "p8_cec_rx.c", 0x4Eu, "p8_cec_rx_callback");
}
printf("CEC RX: char 0x%02.2x %s\n", *v8, (const char *)*(&CEC_FLAGS_TO_STRING + (unsigned int)v12));
cec_rx_char_cb(**a2, (unsigned int)v12, a3);
v13 = a2[1];
if ( v6 < (unsigned __int8 **)v13 || v4 > (char *)v13 )
_assert_fail(
"(frame)->f_end >= (frame)->f_buf && (frame)->f_end <= (frame)->f_buf + COUNT_OF((frame)->f_buf)",
"p8_cec_rx.c",
0x51u,
"p8_cec_rx_callback");
v14 = *a2;
if ( v4 > (char *)*a2 || v6 < (unsigned __int8 **)v14 )
_assert_fail(
"(frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + COUNT_OF((frame)->f_buf)",
"p8_cec_rx.c",
0x51u,
"p8_cec_rx_callback");
if ( v13 < v14 )
_assert_fail("(frame)->f_sta <= (frame)->f_end", "p8_cec_rx.c", 0x51u, "p8_cec_rx_callback");
return 0LL;
}

original_code:
int
p8_cec_rx_callback(proto_char_t code,
                   const p8_frame_t *frame,
                   proto_callback_arg_t cba) {
    ((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_rx.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_rx.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_rx.c", 62, __extension__ __PRETTY_FUNCTION__); }));
    cec_flags_t flags = ((((code) & 0x40)? CEC_ACK: 0) | (((code) & 0x80)? CEC_EOM: 0));
    cec_rx_frame_t * const iframe = cba.cba_frame;
    const int swcode = (code & 0x3F);
    switch (swcode) {
    case P8_IND_RX_START:
        flags |= CEC_START;
    case P8_IND_RX_NEXT:
        printf("CEC RX: char 0x%02.2x %s\n", frame->f_sta[0], CEC_FLAGS_TO_STRING[flags]);
        cec_rx_char_cb(frame->f_sta[0], flags, iframe);
        break;
    default:
        printf("CEC RX: error code 0x%02.2x %s, swcode = 0x%02.2x\n", code, CEC_FLAGS_TO_STRING[flags], swcode);
        ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "p8_cec_rx.c", 78, __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_rx.c", 81, __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_rx.c", 81, __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_rx.c", 81, __extension__ __PRETTY_FUNCTION__); }));
    return 0;
}

canonical_original_code:
int p8_cec_rx_callback(unsigned char code, struct proto_frame *frame, union proto_callback_arg_t cba) {
    ((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_rx.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_rx.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_rx.c", 62, __extension__ __PRETTY_FUNCTION__); }));
    enum cec_flags flags = ((((code) & 0x40)? CEC_ACK: 0) | (((code) & 0x80)? CEC_EOM: 0));
    struct proto_frame *iframe = cba.cba_frame;
    int swcode = (code & 0x3F);
    switch (swcode) {
    case P8_IND_RX_START:
        flags |= CEC_START;
    case P8_IND_RX_NEXT:
        printf("CEC RX: char 0x%02.2x %s\n", frame->f_sta[0], CEC_FLAGS_TO_STRING[flags]);
        cec_rx_char_cb(frame->f_sta[0], flags, iframe);
        break;
    default:
        printf("CEC RX: error code 0x%02.2x %s, swcode = 0x%02.2x\n", code, CEC_FLAGS_TO_STRING[flags], swcode);
        ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "p8_cec_rx.c", 78, __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_rx.c", 81, __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_rx.c", 81, __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_rx.c", 81, __extension__ __PRETTY_FUNCTION__); }));
    return 0;
}

variable_types: swcode int

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

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


decompiled_code:
__int64 __fastcall p8_cec_rx(unsigned int a1, __int64 a2)
{
unsigned __int64 v2; // rdx
unsigned __int64 v3; // r15
unsigned __int64 v4; // rax
__int64 result; // rax
unsigned __int64 v6; // rcx
unsigned __int64 v7; // rdx
unsigned __int64 v8; // [rsp+8h] [rbp-D0h]
__int64 v9[2]; // [rsp+10h] [rbp-C8h] BYREF
__int64 v10[2]; // [rsp+20h] [rbp-B8h] BYREF
char v11[168]; // [rsp+30h] [rbp-A8h] BYREF

v2 = *(_QWORD *)(a2 + 8);
v8 = a2 + 20;
if ( v2 < a2 + 20 || (v3 = a2 + 128, v2 > a2 + 128) )
_assert_fail(
"(iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_cec_rx.c",
0x66u,
"p8_cec_rx");
v4 = *(_QWORD *)a2;
if ( v3 < *(_QWORD *)a2 || v8 > v4 )
_assert_fail(
"(iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_cec_rx.c",
0x66u,
"p8_cec_rx");
if ( v2 < v4 )
_assert_fail("(iframe)->f_sta <= (iframe)->f_end", "p8_cec_rx.c", 0x66u, "p8_cec_rx");
if ( v2 != v4 )
_assert_fail("(iframe)->f_sta == (iframe)->f_end", "p8_cec_rx.c", 0x67u, "p8_cec_rx");
if ( *(_DWORD *)(a2 + 16) )
_assert_fail("iframe->f_status == CEC_RX_EMPTY", "p8_cec_rx.c", 0x68u, "p8_cec_rx");
while ( 1 )
{
v10[0] = (__int64)&v11[4];
memset(v11, 0, 0x70uLL);
v10[1] = (__int64)&v11[4];
v9[0] = a2;
v9[1] = a2;
puts("CEC RX: Processing input");
result = p8_read_and_dispatch(a1, v10, &p8_cec_rx_dt, v9);
if ( (_DWORD)result )
break;
v6 = *(_QWORD *)(a2 + 8);
v7 = *(_QWORD *)a2;
if ( v6 != *(_QWORD *)a2 && *(_DWORD *)(a2 + 16) != 1 )
{
if ( v8 > v6 || v3 < v6 )
_assert_fail(
"(iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_cec_rx.c",
0x7Eu,
"p8_cec_rx");
if ( v3 < v7 || v8 > v7 )
_assert_fail(
"(iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_cec_rx.c",
0x7Eu,
"p8_cec_rx");
if ( v6 < v7 )
_assert_fail("(iframe)->f_sta <= (iframe)->f_end", "p8_cec_rx.c", 0x7Eu, "p8_cec_rx");
return result;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, __int64 a2)
{
unsigned __int64 v2; // rdx
unsigned __int64 v3; // r15
unsigned __int64 v4; // rax
__int64 result; // rax
unsigned __int64 v6; // rcx
unsigned __int64 v7; // rdx
unsigned __int64 v8; // [rsp+8h] [rbp-D0h]
__int64 v9[2]; // [rsp+10h] [rbp-C8h] BYREF
__int64 v10[2]; // [rsp+20h] [rbp-B8h] BYREF
char v11[168]; // [rsp+30h] [rbp-A8h] BYREF

v2 = *(_QWORD *)(a2 + 8);
v8 = a2 + 20;
if ( v2 < a2 + 20 || (v3 = a2 + 128, v2 > a2 + 128) )
_assert_fail(
"(iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_cec_rx.c",
0x66u,
"p8_cec_rx");
v4 = *(_QWORD *)a2;
if ( v3 < *(_QWORD *)a2 || v8 > v4 )
_assert_fail(
"(iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_cec_rx.c",
0x66u,
"p8_cec_rx");
if ( v2 < v4 )
_assert_fail("(iframe)->f_sta <= (iframe)->f_end", "p8_cec_rx.c", 0x66u, "p8_cec_rx");
if ( v2 != v4 )
_assert_fail("(iframe)->f_sta == (iframe)->f_end", "p8_cec_rx.c", 0x67u, "p8_cec_rx");
if ( *(_DWORD *)(a2 + 16) )
_assert_fail("iframe->f_status == CEC_RX_EMPTY", "p8_cec_rx.c", 0x68u, "p8_cec_rx");
while ( 1 )
{
v10[0] = (__int64)&v11[4];
memset(v11, 0, 0x70uLL);
v10[1] = (__int64)&v11[4];
v9[0] = a2;
v9[1] = a2;
puts("CEC RX: Processing input");
result = p8_read_and_dispatch(a1, v10, &p8_cec_rx_dt, v9);
if ( (_DWORD)result )
break;
v6 = *(_QWORD *)(a2 + 8);
v7 = *(_QWORD *)a2;
if ( v6 != *(_QWORD *)a2 && *(_DWORD *)(a2 + 16) != 1 )
{
if ( v8 > v6 || v3 < v6 )
_assert_fail(
"(iframe)->f_end >= (iframe)->f_buf && (iframe)->f_end <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_cec_rx.c",
0x7Eu,
"p8_cec_rx");
if ( v3 < v7 || v8 > v7 )
_assert_fail(
"(iframe)->f_sta >= (iframe)->f_buf && (iframe)->f_sta <= (iframe)->f_buf + COUNT_OF((iframe)->f_buf)",
"p8_cec_rx.c",
0x7Eu,
"p8_cec_rx");
if ( v6 < v7 )
_assert_fail("(iframe)->f_sta <= (iframe)->f_end", "p8_cec_rx.c", 0x7Eu, "p8_cec_rx");
return result;
}
}
return result;
}

original_code:
extern int
p8_cec_rx(int fd, cec_rx_frame_t *iframe) {
    ((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_cec_rx.c", 102, __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_cec_rx.c", 102, __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_cec_rx.c", 102, __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_cec_rx.c", 103, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((iframe->f_status == CEC_RX_EMPTY) ? 1 : 0), __extension__ ({ if (iframe->f_status == CEC_RX_EMPTY) ; else __assert_fail ("iframe->f_status == CEC_RX_EMPTY", "p8_cec_rx.c", 104, __extension__ __PRETTY_FUNCTION__); }));
    do {
        p8_frame_t p8frame = {
            .f_sta = p8frame.f_buf,
            .f_end = p8frame.f_buf,
        };
        int rv;
        proto_callback_arg_t cba_table[((sizeof(p8_cec_rx_callbacks)/sizeof(0[p8_cec_rx_callbacks])) / ((unsigned int)(!(sizeof(p8_cec_rx_callbacks) % sizeof(0[p8_cec_rx_callbacks])))))] = {
            { .cba_frame = iframe },
            { .cba_frame = iframe },
        };
        printf("CEC RX: Processing input\n");
        rv = p8_read_and_dispatch(fd, &p8frame, &p8_cec_rx_dt, cba_table);
        if (rv) return rv;
    } while (iframe->f_end == iframe->f_sta || iframe->f_status == CEC_RX_PROGRESS);
    ((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_cec_rx.c", 126, __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_cec_rx.c", 126, __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_cec_rx.c", 126, __extension__ __PRETTY_FUNCTION__); }));
    return 0;
}

canonical_original_code:
extern int p8_cec_rx(int fd, struct proto_frame *iframe) {
    ((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_cec_rx.c", 102, __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_cec_rx.c", 102, __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_cec_rx.c", 102, __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_cec_rx.c", 103, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((iframe->f_status == CEC_RX_EMPTY) ? 1 : 0), __extension__ ({ if (iframe->f_status == CEC_RX_EMPTY) ; else __assert_fail ("iframe->f_status == CEC_RX_EMPTY", "p8_cec_rx.c", 104, __extension__ __PRETTY_FUNCTION__); }));
    do {
        struct proto_frame p8frame = {
            .f_sta = p8frame.f_buf,
            .f_end = p8frame.f_buf,
        };
        int rv;
        union proto_callback_arg_t cba_table[-1] = {
            { .cba_frame = iframe },
            { .cba_frame = iframe },
        };
        printf("CEC RX: Processing input\n");
        rv = p8_read_and_dispatch(fd, &p8frame, &p8_cec_rx_dt, cba_table);
        if (rv) return rv;
    } while (iframe->f_end == iframe->f_sta || iframe->f_status == CEC_RX_PROGRESS);
    ((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_cec_rx.c", 126, __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_cec_rx.c", 126, __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_cec_rx.c", 126, __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: rv int


decompiled_code:
int __fastcall cec_tx_error(unsigned int a1, __int64 a2)
{
unsigned __int64 v2; // rcx
unsigned __int64 v3; // rax
unsigned __int64 v5; // rsi
unsigned __int64 v6; // rdx
int result; // eax

v2 = a2 + 20;
v3 = *(_QWORD *)(a2 + 8);
if ( v3 < a2 + 20 || (v5 = a2 + 128, v3 > v5) )
_assert_fail(
"(frame)->f_end >= (frame)->f_buf && (frame)->f_end <= (frame)->f_buf + COUNT_OF((frame)->f_buf)",
"cec_tx_error.c",
0x1Du,
"cec_tx_error");
v6 = *(_QWORD *)a2;
if ( v2 > *(_QWORD *)a2 || v5 < v6 )
_assert_fail(
"(frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + COUNT_OF((frame)->f_buf)",
"cec_tx_error.c",
0x1Du,
"cec_tx_error");
if ( v3 < v6 )
_assert_fail("(frame)->f_sta <= (frame)->f_end", "cec_tx_error.c", 0x1Du, "cec_tx_error");
result = fprintf(stderr, "CEC TX ERROR: status=%d, frame->status=%d\n", a1, *(unsigned int *)(a2 + 16));
*(_DWORD *)(a2 + 16) = a1;
return result;
}

canonical_decompiled_code:
int __fastcall func0(unsigned int a1, __int64 a2)
{
unsigned __int64 v2; // rcx
unsigned __int64 v3; // rax
unsigned __int64 v5; // rsi
unsigned __int64 v6; // rdx
int result; // eax

v2 = a2 + 20;
v3 = *(_QWORD *)(a2 + 8);
if ( v3 < a2 + 20 || (v5 = a2 + 128, v3 > v5) )
_assert_fail(
"(frame)->f_end >= (frame)->f_buf && (frame)->f_end <= (frame)->f_buf + COUNT_OF((frame)->f_buf)",
"cec_tx_error.c",
0x1Du,
"cec_tx_error");
v6 = *(_QWORD *)a2;
if ( v2 > *(_QWORD *)a2 || v5 < v6 )
_assert_fail(
"(frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + COUNT_OF((frame)->f_buf)",
"cec_tx_error.c",
0x1Du,
"cec_tx_error");
if ( v3 < v6 )
_assert_fail("(frame)->f_sta <= (frame)->f_end", "cec_tx_error.c", 0x1Du, "cec_tx_error");
result = fprintf(stderr, "CEC TX ERROR: status=%d, frame->status=%d\n", a1, *(unsigned int *)(a2 + 16));
*(_DWORD *)(a2 + 16) = a1;
return result;
}

original_code:
void
cec_tx_error(cec_tx_status_t status, cec_tx_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)", "cec_tx_error.c", 29, __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)", "cec_tx_error.c", 29, __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", "cec_tx_error.c", 29, __extension__ __PRETTY_FUNCTION__); }));
    fprintf(stderr, "CEC TX ERROR: status=%d, frame->status=%d\n", status, frame->f_status);
    frame->f_status = status;
}

canonical_original_code:
void cec_tx_error(enum cec_tx_status status, 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)", "cec_tx_error.c", 29, __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)", "cec_tx_error.c", 29, __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", "cec_tx_error.c", 29, __extension__ __PRETTY_FUNCTION__); }));
    fprintf(stderr, "CEC TX ERROR: status=%d, frame->status=%d\n", status, frame->f_status);
    frame->f_status = status;
}

variable_types: enum cec_tx_status { CEC_TX_ERROR=-2, CEC_TX_UNKNOWN=-1, CEC_TX_SUCCEEDED=0, CEC_TX_NO_ACK=1, CEC_TX_TIMEOUT=2 }

return_type: void


decompiled_code:
unsigned __int8 *__fastcall cec_rx_char_cb(unsigned __int8 a1, unsigned int a2, __int64 a3)
{
unsigned __int8 *result; // rax
unsigned __int64 v4; // r8
unsigned __int64 v6; // rsi
unsigned __int64 v8; // rdx
unsigned int v9; // er8

result = *(unsigned __int8 **)(a3 + 8);
v4 = a3 + 20;
if ( (unsigned __int64)result < a3 + 20 || (v6 = a3 + 128, (unsigned __int64)result > a3 + 128) )
_assert_fail(
"(frame)->f_end >= (frame)->f_buf && (frame)->f_end <= (frame)->f_buf + COUNT_OF((frame)->f_buf)",
"cec_rx_char_cb.c",
0x13u,
"cec_rx_char_cb");
v8 = *(_QWORD *)a3;
if ( v6 < v8 || v4 > v8 )
_assert_fail(
"(frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + COUNT_OF((frame)->f_buf)",
"cec_rx_char_cb.c",
0x13u,
"cec_rx_char_cb");
if ( (unsigned __int64)result < v8 )
_assert_fail("(frame)->f_sta <= (frame)->f_end", "cec_rx_char_cb.c", 0x13u, "cec_rx_char_cb");
v9 = *(_DWORD *)(a3 + 16);
if ( v9 != 1 )
{
if ( v9 == 2 )
{
LABEL_10:
*(_DWORD *)(a3 + 16) = 3;
return (unsigned __int8 *)cec_rx_error(v9, a1, a2);
}
if ( v9 )
return (unsigned __int8 *)cec_rx_error(v9, a1, a2);
if ( (a2 & 4) == 0 )
return (unsigned __int8 *)cec_rx_error(0LL, a1, a2);
*(_DWORD *)(a3 + 16) = 1;
}
*(_QWORD *)(a3 + 8) = result + 1;
*result = a1;
if ( (a2 & 2) != 0 )
*(_DWORD *)(a3 + 16) = 2;
if ( v6 < *(_QWORD *)(a3 + 8) )
goto LABEL_10;
return result;
}

canonical_decompiled_code:
unsigned __int8 *__fastcall func0(unsigned __int8 a1, unsigned int a2, __int64 a3)
{
unsigned __int8 *result; // rax
unsigned __int64 v4; // r8
unsigned __int64 v6; // rsi
unsigned __int64 v8; // rdx
unsigned int v9; // er8

result = *(unsigned __int8 **)(a3 + 8);
v4 = a3 + 20;
if ( (unsigned __int64)result < a3 + 20 || (v6 = a3 + 128, (unsigned __int64)result > a3 + 128) )
_assert_fail(
"(frame)->f_end >= (frame)->f_buf && (frame)->f_end <= (frame)->f_buf + COUNT_OF((frame)->f_buf)",
"cec_rx_char_cb.c",
0x13u,
"cec_rx_char_cb");
v8 = *(_QWORD *)a3;
if ( v6 < v8 || v4 > v8 )
_assert_fail(
"(frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + COUNT_OF((frame)->f_buf)",
"cec_rx_char_cb.c",
0x13u,
"cec_rx_char_cb");
if ( (unsigned __int64)result < v8 )
_assert_fail("(frame)->f_sta <= (frame)->f_end", "cec_rx_char_cb.c", 0x13u, "cec_rx_char_cb");
v9 = *(_DWORD *)(a3 + 16);
if ( v9 != 1 )
{
if ( v9 == 2 )
{
LABEL_10:
*(_DWORD *)(a3 + 16) = 3;
return (unsigned __int8 *)cec_rx_error(v9, a1, a2);
}
if ( v9 )
return (unsigned __int8 *)cec_rx_error(v9, a1, a2);
if ( (a2 & 4) == 0 )
return (unsigned __int8 *)cec_rx_error(0LL, a1, a2);
*(_DWORD *)(a3 + 16) = 1;
}
*(_QWORD *)(a3 + 8) = result + 1;
*result = a1;
if ( (a2 & 2) != 0 )
*(_DWORD *)(a3 + 16) = 2;
if ( v6 < *(_QWORD *)(a3 + 8) )
goto LABEL_10;
return result;
}

original_code:
void
cec_rx_char_cb(cec_char_t c, cec_flags_t f, cec_rx_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)", "cec_rx_char_cb.c", 19, __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)", "cec_rx_char_cb.c", 19, __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", "cec_rx_char_cb.c", 19, __extension__ __PRETTY_FUNCTION__); }));
    cec_rx_frame_state_t state = frame->f_status;
    switch (state) {
    case CEC_RX_EMPTY:
        if (!(f & CEC_START)) {
            cec_rx_error(state, c, f, frame);
            return;
        }
        frame->f_status = CEC_RX_PROGRESS;
    case CEC_RX_PROGRESS:
        *frame->f_end++ = c;
        if (f & CEC_EOM)
            frame->f_status = CEC_RX_EOM;
        if (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]))))))
            break;
    case CEC_RX_EOM:
        frame->f_status = CEC_RX_OVF;
    case CEC_RX_OVF:
    case CEC_RX_ERROR:
    default:
        cec_rx_error(state, c, f, frame);
    }
}

canonical_original_code:
void cec_rx_char_cb(unsigned char c, enum cec_flags f, 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)", "cec_rx_char_cb.c", 19, __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)", "cec_rx_char_cb.c", 19, __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", "cec_rx_char_cb.c", 19, __extension__ __PRETTY_FUNCTION__); }));
    enum cec_rx_frame_state state = frame->f_status;
    switch (state) {
    case CEC_RX_EMPTY:
        if (!(f & CEC_START)) {
            cec_rx_error(state, c, f, frame);
            return;
        }
        frame->f_status = CEC_RX_PROGRESS;
    case CEC_RX_PROGRESS:
        *frame->f_end++ = c;
        if (f & CEC_EOM)
            frame->f_status = CEC_RX_EOM;
        if (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]))))))
            break;
    case CEC_RX_EOM:
        frame->f_status = CEC_RX_OVF;
    case CEC_RX_OVF:
    case CEC_RX_ERROR:
    default:
        cec_rx_error(state, c, f, frame);
    }
}

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 }


decompiled_code:
__int64 cec_open()
{
unsigned int v0; // er12
__int64 v2[2]; // [rsp+0h] [rbp-88h] BYREF
char v3[120]; // [rsp+10h] [rbp-78h] BYREF

v0 = p8_open();
if ( (v0 & 0x80000000) == 0 )
{
memset(v3, 0, 0x70uLL);
v2[0] = (__int64)&v3[4];
v2[1] = (__int64)&v3[4];
if ( (unsigned int)p8_command(v0, 1LL, 0LL, 0LL, v2) )
_assert_fail("rv == 0", "cec_open.c", 0x24u, "cec_open");
if ( (unsigned int)p8_command1(v0, 24LL, 1LL, v2) )
_assert_fail("rv == 0", "cec_open.c", 0x27u, "cec_open");
}
return v0;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // er12
__int64 v2[2]; // [rsp+0h] [rbp-88h] BYREF
char v3[120]; // [rsp+10h] [rbp-78h] BYREF

v0 = p8_open();
if ( (v0 & 0x80000000) == 0 )
{
memset(v3, 0, 0x70uLL);
v2[0] = (__int64)&v3[4];
v2[1] = (__int64)&v3[4];
if ( (unsigned int)p8_command(v0, 1LL, 0LL, 0LL, v2) )
_assert_fail("rv == 0", "cec_open.c", 0x24u, "cec_open");
if ( (unsigned int)p8_command1(v0, 24LL, 1LL, v2) )
_assert_fail("rv == 0", "cec_open.c", 0x27u, "cec_open");
}
return v0;
}

original_code:
int
cec_open(void) {
    int fd, rv;
    fd = p8_open();
    if (fd < 0) return fd;
    cec_rx_frame_t iframe = {
        .f_sta = iframe.f_buf,
        .f_end = iframe.f_buf,
        .f_status = CEC_RX_EMPTY,
    };
    rv = p8_command (fd, P8_CMD_PING, ((void *)0), 0, &iframe);
    ((void) sizeof ((rv == 0) ? 1 : 0), __extension__ ({ if (rv == 0) ; else __assert_fail ("rv == 0", "cec_open.c", 36, __extension__ __PRETTY_FUNCTION__); }));
    rv = p8_command1(fd, P8_SET_CONTROLLED, 1, &iframe);
    ((void) sizeof ((rv == 0) ? 1 : 0), __extension__ ({ if (rv == 0) ; else __assert_fail ("rv == 0", "cec_open.c", 39, __extension__ __PRETTY_FUNCTION__); }));
    return fd;
}

canonical_original_code:
int cec_open() {
    int fd; int rv;
    fd = p8_open();
    if (fd < 0) return fd;
    struct proto_frame iframe = {
        .f_sta = iframe.f_buf,
        .f_end = iframe.f_buf,
        .f_status = CEC_RX_EMPTY,
    };
    rv = p8_command (fd, P8_CMD_PING, ((void *)0), 0, &iframe);
    ((void) sizeof ((rv == 0) ? 1 : 0), __extension__ ({ if (rv == 0) ; else __assert_fail ("rv == 0", "cec_open.c", 36, __extension__ __PRETTY_FUNCTION__); }));
    rv = p8_command1(fd, P8_SET_CONTROLLED, 1, &iframe);
    ((void) sizeof ((rv == 0) ? 1 : 0), __extension__ ({ if (rv == 0) ; else __assert_fail ("rv == 0", "cec_open.c", 39, __extension__ __PRETTY_FUNCTION__); }));
    return fd;
}


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

if ( (unsigned int)a1 >= P8_CODE_TYPE_COUNT )
_assert_fail("(code) < P8_CODE_TYPE_COUNT", "p8_cec_tx.c", 0x58u, "p8_cec_tx_nack");
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", 0x58u, "p8_cec_tx_nack");
v4 = a2[1];
v5 = *a2;
v6 = v4 - *a2;
if ( v6 < (unsigned __int8)v3[3] )
_assert_fail(
"((frame)->f_end - (frame)->f_sta) >= p8_code_types[(code)].ct_a2h_min_plen",
"p8_cec_tx.c",
0x58u,
"p8_cec_tx_nack");
if ( v6 > (unsigned __int8)v3[4] )
_assert_fail(
"((frame)->f_end - (frame)->f_sta) <= p8_code_types[(code)].ct_a2h_max_plen",
"p8_cec_tx.c",
0x58u,
"p8_cec_tx_nack");
v7 = (char *)a2 + 20;
if ( v4 < (unsigned __int64)a2 + 20 || (v8 = a2 + 16, v4 > (unsigned __int64)v8) )
_assert_fail(
"(frame)->f_end >= (frame)->f_buf && (frame)->f_end <= (frame)->f_buf + COUNT_OF((frame)->f_buf)",
"p8_cec_tx.c",
0x59u,
"p8_cec_tx_nack");
if ( v5 < (unsigned __int64)v7 || v5 > (unsigned __int64)v8 )
_assert_fail(
"(frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + COUNT_OF((frame)->f_buf)",
"p8_cec_tx.c",
0x59u,
"p8_cec_tx_nack");
if ( v4 < v5 )
_assert_fail("(frame)->f_sta <= (frame)->f_end", "p8_cec_tx.c", 0x59u, "p8_cec_tx_nack");
if ( v4 != v5 )
_assert_fail("(frame)->f_sta == (frame)->f_end", "p8_cec_tx.c", 0x5Au, "p8_cec_tx_nack");
v9 = (unsigned int)(*a3 + 1);
*a3 = v9;
printf("CEC TX: NACK received: %d", v9);
return 0LL;
}

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

if ( (unsigned int)a1 >= P8_CODE_TYPE_COUNT )
_assert_fail("(code) < P8_CODE_TYPE_COUNT", "p8_cec_tx.c", 0x58u, "p8_cec_tx_nack");
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", 0x58u, "p8_cec_tx_nack");
v4 = a2[1];
v5 = *a2;
v6 = v4 - *a2;
if ( v6 < (unsigned __int8)v3[3] )
_assert_fail(
"((frame)->f_end - (frame)->f_sta) >= p8_code_types[(code)].ct_a2h_min_plen",
"p8_cec_tx.c",
0x58u,
"p8_cec_tx_nack");
if ( v6 > (unsigned __int8)v3[4] )
_assert_fail(
"((frame)->f_end - (frame)->f_sta) <= p8_code_types[(code)].ct_a2h_max_plen",
"p8_cec_tx.c",
0x58u,
"p8_cec_tx_nack");
v7 = (char *)a2 + 20;
if ( v4 < (unsigned __int64)a2 + 20 || (v8 = a2 + 16, v4 > (unsigned __int64)v8) )
_assert_fail(
"(frame)->f_end >= (frame)->f_buf && (frame)->f_end <= (frame)->f_buf + COUNT_OF((frame)->f_buf)",
"p8_cec_tx.c",
0x59u,
"p8_cec_tx_nack");
if ( v5 < (unsigned __int64)v7 || v5 > (unsigned __int64)v8 )
_assert_fail(
"(frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + COUNT_OF((frame)->f_buf)",
"p8_cec_tx.c",
0x59u,
"p8_cec_tx_nack");
if ( v4 < v5 )
_assert_fail("(frame)->f_sta <= (frame)->f_end", "p8_cec_tx.c", 0x59u, "p8_cec_tx_nack");
if ( v4 != v5 )
_assert_fail("(frame)->f_sta == (frame)->f_end", "p8_cec_tx.c", 0x5Au, "p8_cec_tx_nack");
v9 = (unsigned int)(*a3 + 1);
*a3 = v9;
printf("CEC TX: NACK received: %d", v9);
return 0LL;
}

original_code:
static int
p8_cec_tx_nack(proto_char_t code,
               const p8_frame_t *frame,
               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_cec_tx.c", 88, __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", 88, __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", 88, __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", 88, __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", 89, __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", 89, __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", 89, __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", 90, __extension__ __PRETTY_FUNCTION__); }));
    int *countp = cba.cba_intp;
    (*countp)++;
    printf("CEC TX: NACK received: %d", *countp);
    return 0;
}

canonical_original_code:
static int p8_cec_tx_nack(unsigned char code, struct proto_frame *frame, 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_cec_tx.c", 88, __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", 88, __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", 88, __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", 88, __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", 89, __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", 89, __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", 89, __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", 90, __extension__ __PRETTY_FUNCTION__); }));
    int *countp = cba.cba_intp;
    (*countp)++;
    printf("CEC TX: NACK received: %d", *countp);
    return 0;
}

variable_types:
countp
int *


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

if ( (unsigned int)a1 >= P8_CODE_TYPE_COUNT )
_assert_fail("(code) < P8_CODE_TYPE_COUNT", "p8_cec_tx.c", 0x4Au, "p8_cec_tx_ack");
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", 0x4Au, "p8_cec_tx_ack");
v4 = a2[1];
v5 = *a2;
v6 = v4 - *a2;
if ( v6 < (unsigned __int8)v3[3] )
_assert_fail(
"((frame)->f_end - (frame)->f_sta) >= p8_code_types[(code)].ct_a2h_min_plen",
"p8_cec_tx.c",
0x4Au,
"p8_cec_tx_ack");
if ( v6 > (unsigned __int8)v3[4] )
_assert_fail(
"((frame)->f_end - (frame)->f_sta) <= p8_code_types[(code)].ct_a2h_max_plen",
"p8_cec_tx.c",
0x4Au,
"p8_cec_tx_ack");
v7 = (char *)a2 + 20;
if ( v4 < (unsigned __int64)a2 + 20 || (v8 = a2 + 16, v4 > (unsigned __int64)v8) )
_assert_fail(
"(frame)->f_end >= (frame)->f_buf && (frame)->f_end <= (frame)->f_buf + COUNT_OF((frame)->f_buf)",
"p8_cec_tx.c",
0x4Bu,
"p8_cec_tx_ack");
if ( v5 < (unsigned __int64)v7 || v5 > (unsigned __int64)v8 )
_assert_fail(
"(frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + COUNT_OF((frame)->f_buf)",
"p8_cec_tx.c",
0x4Bu,
"p8_cec_tx_ack");
if ( v4 < v5 )
_assert_fail("(frame)->f_sta <= (frame)->f_end", "p8_cec_tx.c", 0x4Bu, "p8_cec_tx_ack");
if ( v4 != v5 )
_assert_fail("(frame)->f_sta == (frame)->f_end", "p8_cec_tx.c", 0x4Cu, "p8_cec_tx_ack");
v9 = (unsigned int)(*a3 - 1);
*a3 = v9;
printf("CEC TX: ACK received, %d to go\n", v9);
return 0LL;
}

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

if ( (unsigned int)a1 >= P8_CODE_TYPE_COUNT )
_assert_fail("(code) < P8_CODE_TYPE_COUNT", "p8_cec_tx.c", 0x4Au, "p8_cec_tx_ack");
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", 0x4Au, "p8_cec_tx_ack");
v4 = a2[1];
v5 = *a2;
v6 = v4 - *a2;
if ( v6 < (unsigned __int8)v3[3] )
_assert_fail(
"((frame)->f_end - (frame)->f_sta) >= p8_code_types[(code)].ct_a2h_min_plen",
"p8_cec_tx.c",
0x4Au,
"p8_cec_tx_ack");
if ( v6 > (unsigned __int8)v3[4] )
_assert_fail(
"((frame)->f_end - (frame)->f_sta) <= p8_code_types[(code)].ct_a2h_max_plen",
"p8_cec_tx.c",
0x4Au,
"p8_cec_tx_ack");
v7 = (char *)a2 + 20;
if ( v4 < (unsigned __int64)a2 + 20 || (v8 = a2 + 16, v4 > (unsigned __int64)v8) )
_assert_fail(
"(frame)->f_end >= (frame)->f_buf && (frame)->f_end <= (frame)->f_buf + COUNT_OF((frame)->f_buf)",
"p8_cec_tx.c",
0x4Bu,
"p8_cec_tx_ack");
if ( v5 < (unsigned __int64)v7 || v5 > (unsigned __int64)v8 )
_assert_fail(
"(frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + COUNT_OF((frame)->f_buf)",
"p8_cec_tx.c",
0x4Bu,
"p8_cec_tx_ack");
if ( v4 < v5 )
_assert_fail("(frame)->f_sta <= (frame)->f_end", "p8_cec_tx.c", 0x4Bu, "p8_cec_tx_ack");
if ( v4 != v5 )
_assert_fail("(frame)->f_sta == (frame)->f_end", "p8_cec_tx.c", 0x4Cu, "p8_cec_tx_ack");
v9 = (unsigned int)(*a3 - 1);
*a3 = v9;
printf("CEC TX: ACK received, %d to go\n", v9);
return 0LL;
}

original_code:
static int
p8_cec_tx_ack(proto_char_t code,
              const p8_frame_t *frame,
              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_cec_tx.c", 74, __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", 74, __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", 74, __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", 74, __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", 75, __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", 75, __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", 75, __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", 76, __extension__ __PRETTY_FUNCTION__); }));
    int *countp = cba.cba_intp;
    (*countp)--;
    printf("CEC TX: ACK received, %d to go\n", *countp);
    return 0;
}

canonical_original_code:
static int p8_cec_tx_ack(unsigned char code, struct proto_frame *frame, 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_cec_tx.c", 74, __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", 74, __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", 74, __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", 74, __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", 75, __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", 75, __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", 75, __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", 76, __extension__ __PRETTY_FUNCTION__); }));
    int *countp = cba.cba_intp;
    (*countp)--;
    printf("CEC TX: ACK received, %d to go\n", *countp);
    return 0;
}


decompiled_code:
__int64 __fastcall p8_cec_tx_error_cb(unsigned __int8 a1, unsigned __int64 *a2, __int64 a3)
{
unsigned __int64 v3; // rax
unsigned __int64 v5; // rdx
char *v6; // rsi
__int64 v7; // rax
__int64 result; // rax

v3 = a2[1];
if ( v3 < (unsigned __int64)a2 + 20 || v3 > (unsigned __int64)(a2 + 16) )
_assert_fail(
"(frame)->f_end >= (frame)->f_buf && (frame)->f_end <= (frame)->f_buf + COUNT_OF((frame)->f_buf)",
"p8_cec_tx.c",
0x1Fu,
"p8_cec_tx_error_cb");
v5 = *a2;
if ( (unsigned __int64)a2 + 20 > *a2 || (unsigned __int64)(a2 + 16) < v5 )
_assert_fail(
"(frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + COUNT_OF((frame)->f_buf)",
"p8_cec_tx.c",
0x1Fu,
"p8_cec_tx_error_cb");
if ( v3 < v5 )
_assert_fail("(frame)->f_sta <= (frame)->f_end", "p8_cec_tx.c", 0x1Fu, "p8_cec_tx_error_cb");
if ( (unsigned int)a1 >= P8_CODE_TYPE_COUNT )
_assert_fail("(code) < P8_CODE_TYPE_COUNT", "p8_cec_tx.c", 0x20u, "p8_cec_tx_error_cb");
v6 = (char *)&p8_code_types + 5 * a1;
if ( (*v6 & 2) == 0 )
_assert_fail("p8_code_types[(code)].ct_type & P8_CT_A2H", "p8_cec_tx.c", 0x20u, "p8_cec_tx_error_cb");
v7 = v3 - v5;
if ( v7 < (unsigned __int8)v6[3] )
_assert_fail(
"((frame)->f_end - (frame)->f_sta) >= p8_code_types[(code)].ct_a2h_min_plen",
"p8_cec_tx.c",
0x20u,
"p8_cec_tx_error_cb");
if ( v7 > (unsigned __int8)v6[4] )
_assert_fail(
"((frame)->f_end - (frame)->f_sta) <= p8_code_types[(code)].ct_a2h_max_plen",
"p8_cec_tx.c",
0x20u,
"p8_cec_tx_error_cb");
printf("CEC_TX: ERROR: p8_tx_error: code=0x%02.2x\n", a1);
if ( a1 == 18 )
{
*(_DWORD *)(a3 + 16) = 1;
result = 0xFFFFFFFFLL;
}
else
{
if ( a1 > 0x12u )
{
if ( (unsigned __int8)(a1 - 19) <= 1u )
{
cec_tx_error(2LL, a3);
return 0xFFFFFFFFLL;
}
LABEL_19:
printf("Unrecognized TX failure code 0x%02.2x\n", a1);
_assert_fail("0", "p8_cec_tx.c", 0x32u, "p8_cec_tx_error_cb");
}
if ( a1 != 17 )
goto LABEL_19;
cec_tx_error(4294967294LL, a3);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int8 a1, unsigned __int64 *a2, __int64 a3)
{
unsigned __int64 v3; // rax
unsigned __int64 v5; // rdx
char *v6; // rsi
__int64 v7; // rax
__int64 result; // rax

v3 = a2[1];
if ( v3 < (unsigned __int64)a2 + 20 || v3 > (unsigned __int64)(a2 + 16) )
_assert_fail(
"(frame)->f_end >= (frame)->f_buf && (frame)->f_end <= (frame)->f_buf + COUNT_OF((frame)->f_buf)",
"p8_cec_tx.c",
0x1Fu,
"p8_cec_tx_error_cb");
v5 = *a2;
if ( (unsigned __int64)a2 + 20 > *a2 || (unsigned __int64)(a2 + 16) < v5 )
_assert_fail(
"(frame)->f_sta >= (frame)->f_buf && (frame)->f_sta <= (frame)->f_buf + COUNT_OF((frame)->f_buf)",
"p8_cec_tx.c",
0x1Fu,
"p8_cec_tx_error_cb");
if ( v3 < v5 )
_assert_fail("(frame)->f_sta <= (frame)->f_end", "p8_cec_tx.c", 0x1Fu, "p8_cec_tx_error_cb");
if ( (unsigned int)a1 >= P8_CODE_TYPE_COUNT )
_assert_fail("(code) < P8_CODE_TYPE_COUNT", "p8_cec_tx.c", 0x20u, "p8_cec_tx_error_cb");
v6 = (char *)&p8_code_types + 5 * a1;
if ( (*v6 & 2) == 0 )
_assert_fail("p8_code_types[(code)].ct_type & P8_CT_A2H", "p8_cec_tx.c", 0x20u, "p8_cec_tx_error_cb");
v7 = v3 - v5;
if ( v7 < (unsigned __int8)v6[3] )
_assert_fail(
"((frame)->f_end - (frame)->f_sta) >= p8_code_types[(code)].ct_a2h_min_plen",
"p8_cec_tx.c",
0x20u,
"p8_cec_tx_error_cb");
if ( v7 > (unsigned __int8)v6[4] )
_assert_fail(
"((frame)->f_end - (frame)->f_sta) <= p8_code_types[(code)].ct_a2h_max_plen",
"p8_cec_tx.c",
0x20u,
"p8_cec_tx_error_cb");
printf("CEC_TX: ERROR: p8_tx_error: code=0x%02.2x\n", a1);
if ( a1 == 18 )
{
*(_DWORD *)(a3 + 16) = 1;
result = 0xFFFFFFFFLL;
}
else
{
if ( a1 > 0x12u )
{
if ( (unsigned __int8)(a1 - 19) <= 1u )
{
cec_tx_error(2LL, a3);
return 0xFFFFFFFFLL;
}
LABEL_19:
printf("Unrecognized TX failure code 0x%02.2x\n", a1);
_assert_fail("0", "p8_cec_tx.c", 0x32u, "p8_cec_tx_error_cb");
}
if ( a1 != 17 )
goto LABEL_19;
cec_tx_error(4294967294LL, a3);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
p8_cec_tx_error_cb(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 (((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", 31, __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", 31, __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", 31, __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_cec_tx.c", 32, __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", 32, __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", 32, __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", 32, __extension__ __PRETTY_FUNCTION__); }));
    printf("CEC_TX: ERROR: p8_tx_error: code=0x%02.2x\n", code);
    switch (code) {
    case P8_IND_TX_FAIL_ACK:
        oframe->f_status = CEC_TX_NO_ACK;
        break;
    case P8_IND_TX_FAIL_LINE:
        cec_tx_error(CEC_TX_ERROR, oframe);
        break;
    case P8_IND_TX_TIMEOUT_D:
    case P8_IND_TX_TIMEOUT_L:
        cec_tx_error(CEC_TX_TIMEOUT, oframe);
        break;
    default:
        printf("Unrecognized TX failure code 0x%02.2x\n", code);
        ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "p8_cec_tx.c", 50, __extension__ __PRETTY_FUNCTION__); }));
    }
    return -1;
}

canonical_original_code:
int p8_cec_tx_error_cb(unsigned char code, struct proto_frame *frame, union proto_callback_arg_t cba) {
    struct proto_frame *oframe = cba.cba_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_cec_tx.c", 31, __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", 31, __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", 31, __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_cec_tx.c", 32, __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", 32, __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", 32, __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", 32, __extension__ __PRETTY_FUNCTION__); }));
    printf("CEC_TX: ERROR: p8_tx_error: code=0x%02.2x\n", code);
    switch (code) {
    case P8_IND_TX_FAIL_ACK:
        oframe->f_status = CEC_TX_NO_ACK;
        break;
    case P8_IND_TX_FAIL_LINE:
        cec_tx_error(CEC_TX_ERROR, oframe);
        break;
    case P8_IND_TX_TIMEOUT_D:
    case P8_IND_TX_TIMEOUT_L:
        cec_tx_error(CEC_TX_TIMEOUT, oframe);
        break;
    default:
        printf("Unrecognized TX failure code 0x%02.2x\n", code);
        ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "p8_cec_tx.c", 50, __extension__ __PRETTY_FUNCTION__); }));
    }
    return -1;
}