original_code:
size_t modp_dtoa(double value, char* str, int prec)
{
    if (! (value == value)) {
        str[0] = 'n'; str[1] = 'a'; str[2] = 'n'; str[3] = '\0';
        return (size_t)3;
    }
    const double thres_max = (double)(0x7FFFFFFF);
    double diff = 0.0;
    char* wstr = str;
    if (prec < 0) {
        prec = 0;
    } else if (prec > 9) {
        prec = 9;
    }
    int neg = 0;
    if (value < 0) {
        neg = 1;
        value = -value;
    }
    int whole = (int) value;
    double tmp = (value - whole) * powers_of_10[prec];
    uint32_t frac = (uint32_t)(tmp);
    diff = tmp - frac;
    if (diff > 0.5) {
        ++frac;
        if (frac >= powers_of_10[prec]) {
            frac = 0;
            ++whole;
        }
    } else if (diff == 0.5 && ((frac == 0) || (frac & 1))) {
        ++frac;
    }
    if (value > thres_max) {
        sprintf(str, "%e", neg ? -value : value);
        return strlen(str);
    }
    if (prec == 0) {
        diff = value - whole;
        if (diff > 0.5) {
            ++whole;
        } else if (diff == 0.5 && (whole & 1)) {
            ++whole;
        }
    } else {
        int count = prec;
        do {
            --count;
            *wstr++ = (char)(48 + (frac % 10));
        } while (frac /= 10);
        while (count-- > 0) *wstr++ = '0';
        *wstr++ = '.';
    }
    do *wstr++ = (char)(48 + (whole % 10)); while (whole /= 10);
    if (neg) {
        *wstr++ = '-';
    }
    *wstr='\0';
    strreverse(str, wstr-1);
    return (size_t)(wstr - str);
}

canonical_original_code:
unsigned long modp_dtoa(double value, char *str, int prec)
{
    if (! (value == value)) {
        str[0] = 'n'; str[1] = 'a'; str[2] = 'n'; str[3] = '\0';
        return (unsigned long)3;
    }
    double thres_max = (double)(0x7FFFFFFF);
    double diff = 0.0;
    char *wstr = str;
    if (prec < 0) {
        prec = 0;
    } else if (prec > 9) {
        prec = 9;
    }
    int neg = 0;
    if (value < 0) {
        neg = 1;
        value = -value;
    }
    int whole = (int) value;
    double tmp = (value - whole) * powers_of_10[prec];
    unsigned int frac = (uint32_t)(tmp);
    diff = tmp - frac;
    if (diff > 0.5) {
        ++frac;
        if (frac >= powers_of_10[prec]) {
            frac = 0;
            ++whole;
        }
    } else if (diff == 0.5 && ((frac == 0) || (frac & 1))) {
        ++frac;
    }
    if (value > thres_max) {
        sprintf(str, "%e", neg ? -value : value);
        return strlen(str);
    }
    if (prec == 0) {
        diff = value - whole;
        if (diff > 0.5) {
            ++whole;
        } else if (diff == 0.5 && (whole & 1)) {
            ++whole;
        }
    } else {
        int count = prec;
        do {
            --count;
            *wstr++ = (char)(48 + (frac % 10));
        } while (frac /= 10);
        while (count-- > 0) *wstr++ = '0';
        *wstr++ = '.';
    }
    do *wstr++ = (char)(48 + (whole % 10)); while (whole /= 10);
    if (neg) {
        *wstr++ = '-';
    }
    *wstr='\0';
    strreverse(str, wstr-1);
    return (unsigned long)(wstr - str);
}

variable_types: value double

variable_types: prec int

variable_types: diff double

variable_types: neg int

variable_types: whole int

variable_types: tmp double

variable_types:
frac
unsigned int


repo: libtrading/libtrading

original_code:
size_t modp_dtoa2(double value, char* str, int prec)
{
    if (! (value == value)) {
        str[0] = 'n'; str[1] = 'a'; str[2] = 'n'; str[3] = '\0';
        return (size_t) 3;
    }
    const double thres_max = (double)(0x7FFFFFFF);
    int count;
    double diff = 0.0;
    char* wstr = str;
    if (prec < 0) {
        prec = 0;
    } else if (prec > 9) {
        prec = 9;
    }
    int neg = 0;
    if (value < 0) {
        neg = 1;
        value = -value;
    }
    int whole = (int) value;
    double tmp = (value - whole) * powers_of_10[prec];
    uint32_t frac = (uint32_t)(tmp);
    diff = tmp - frac;
    if (diff > 0.5) {
        ++frac;
        if (frac >= powers_of_10[prec]) {
            frac = 0;
            ++whole;
        }
    } else if (diff == 0.5 && ((frac == 0) || (frac & 1))) {
        ++frac;
    }
    if (value > thres_max) {
        sprintf(str, "%e", neg ? -value : value);
        return strlen(str);
    }
    if (prec == 0) {
        diff = value - whole;
        if (diff > 0.5) {
            ++whole;
        } else if (diff == 0.5 && (whole & 1)) {
            ++whole;
        }
    } else if (frac) {
        count = prec;
        while (!(frac % 10)) {
            --count;
            frac /= 10;
        }
        do {
            --count;
            *wstr++ = (char)(48 + (frac % 10));
        } while (frac /= 10);
        while (count-- > 0) *wstr++ = '0';
        *wstr++ = '.';
    }
    do *wstr++ = (char)(48 + (whole % 10)); while (whole /= 10);
    if (neg) {
        *wstr++ = '-';
    }
    *wstr='\0';
    strreverse(str, wstr-1);
    return (size_t)(wstr - str);
}

canonical_original_code:
unsigned long modp_dtoa2(double value, char *str, int prec)
{
    if (! (value == value)) {
        str[0] = 'n'; str[1] = 'a'; str[2] = 'n'; str[3] = '\0';
        return (unsigned long) 3;
    }
    double thres_max = (double)(0x7FFFFFFF);
    int count;
    double diff = 0.0;
    char *wstr = str;
    if (prec < 0) {
        prec = 0;
    } else if (prec > 9) {
        prec = 9;
    }
    int neg = 0;
    if (value < 0) {
        neg = 1;
        value = -value;
    }
    int whole = (int) value;
    double tmp = (value - whole) * powers_of_10[prec];
    unsigned int frac = (uint32_t)(tmp);
    diff = tmp - frac;
    if (diff > 0.5) {
        ++frac;
        if (frac >= powers_of_10[prec]) {
            frac = 0;
            ++whole;
        }
    } else if (diff == 0.5 && ((frac == 0) || (frac & 1))) {
        ++frac;
    }
    if (value > thres_max) {
        sprintf(str, "%e", neg ? -value : value);
        return strlen(str);
    }
    if (prec == 0) {
        diff = value - whole;
        if (diff > 0.5) {
            ++whole;
        } else if (diff == 0.5 && (whole & 1)) {
            ++whole;
        }
    } else if (frac) {
        count = prec;
        while (!(frac % 10)) {
            --count;
            frac /= 10;
        }
        do {
            --count;
            *wstr++ = (char)(48 + (frac % 10));
        } while (frac /= 10);
        while (count-- > 0) *wstr++ = '0';
        *wstr++ = '.';
    }
    do *wstr++ = (char)(48 + (whole % 10)); while (whole /= 10);
    if (neg) {
        *wstr++ = '-';
    }
    *wstr='\0';
    strreverse(str, wstr-1);
    return (unsigned long)(wstr - str);
}

variable_types:
str
char *

variable_types: count int

variable_types:
wstr
char *

return_type: unsigned long


original_code:
static inline struct trader *trader_new(struct market *market)
{
 struct trader *traders = market->traders;
 struct trader *trader;
 if (market->traders_num >= 100)
  return ((void *)0);
 trader = traders + market->traders_num;
 trader->id = market->traders_num++;
 trader->active = 0;
 return trader;
}

variable_types: struct market { struct trader traders[100]; unsigned long traders_num; struct order_book { struct level { struct order { unsigned long trader; unsigned long level; struct order *next; struct order *prev; unsigned long side; unsigned long size; } *head; struct order *tail; } levels[-1]; struct order orders[10000]; unsigned long orders_num; unsigned long best_ask; unsigned long best_bid; unsigned long book_id; char code[32]; } book; } *

variable_types: struct trader { struct fix_session { struct fix_dialect { enum fix_version { FIX_4_0=0, FIX_4_1=1, FIX_4_2=2, FIX_4_3=3, FIX_4_4=4, FIX_5_0=5, FIXT_1_1=6 } version; enum fix_type { FIX_TYPE_INT=0, FIX_TYPE_FLOAT=1, FIX_TYPE_CHAR=2, FIX_TYPE_STRING=3, FIX_TYPE_CHECKSUM=4, FIX_TYPE_MSGSEQNUM=5, FIX_TYPE_STRING_8=6 } (*tag_type)(int tag); } *dialect; int sockfd; _Bool active; char *password; char *begin_string; char *sender_comp_id; char *target_comp_id; unsigned long in_msg_seq_num; unsigned long out_msg_seq_num; struct buffer { unsigned long start; unsigned long end; unsigned long capacity; char *data; } *rx_buffer; struct buffer *tx_head_buffer; struct buffer *tx_body_buffer; struct fix_message { enum fix_msg_type { FIX_MSG_TYPE_HEARTBEAT=0, FIX_MSG_TYPE_TEST_REQUEST=1, FIX_MSG_TYPE_RESEND_REQUEST=2, FIX_MSG_TYPE_REJECT=3, FIX_MSG_TYPE_SEQUENCE_RESET=4, FIX_MSG_TYPE_LOGOUT=5, FIX_MSG_TYPE_EXECUTION_REPORT=6, FIX_MSG_TYPE_LOGON=7, FIX_MSG_TYPE_NEW_ORDER_SINGLE=8, FIX_MSG_TYPE_SNAPSHOT_REFRESH=9, FIX_MSG_TYPE_INCREMENT_REFRESH=10, FIX_MSG_TYPE_SESSION_STATUS=11, FIX_MSG_TYPE_SECURITY_STATUS=12, FIX_MSG_ORDER_CANCEL_REPLACE=13, FIX_MSG_ORDER_CANCEL_REJECT=14, FIX_MSG_ORDER_CANCEL_REQUEST=15, FIX_MSG_ORDER_MASS_CANCEL_REQUEST=16, FIX_MSG_ORDER_MASS_CANCEL_REPORT=17, FIX_MSG_QUOTE_REQUEST=18, FIX_MSG_SECURITY_DEFINITION_REQUEST=19, FIX_MSG_NEW_ORDER_CROSS=20, FIX_MSG_MASS_QUOTE=21, FIX_MSG_QUOTE_CANCEL=22, FIX_MSG_SECURITY_DEFINITION=23, FIX_MSG_QUOTE_ACKNOWLEDGEMENT=24, FIX_MSG_ORDER_MASS_STATUS_REQUEST=25, FIX_MSG_ORDER_MASS_ACTION_REQUEST=26, FIX_MSG_ORDER_MASS_ACTION_REPORT=27, FIX_MSG_TYPE_MAX=28, FIX_MSG_TYPE_UNKNOWN=expr } type; char *begin_string; unsigned long body_length; char *msg_type; char *sender_comp_id; char *target_comp_id; unsigned long msg_seq_num; char *check_sum; char *str_now; struct buffer *head_buf; struct buffer *body_buf; unsigned long nr_fields; struct fix_field { int tag; enum fix_type { FIX_TYPE_INT=0, FIX_TYPE_FLOAT=1, FIX_TYPE_CHAR=2, FIX_TYPE_STRING=3, FIX_TYPE_CHECKSUM=4, FIX_TYPE_MSGSEQNUM=5, FIX_TYPE_STRING_8=6 } type; union { long int_value; double float_value; char char_value; char *string_value; char string_8_value[8]; }; } *fields; struct iovec { void *iov_base; unsigned long iov_len; } iov[2]; } *rx_message; int heartbtint; struct timespec { long tv_sec; long tv_nsec; } now; char str_now[64]; struct timespec rx_timestamp; struct timespec tx_timestamp; char testreqid[64]; struct timespec tr_timestamp; int tr_pending; enum fix_failure_reason { FIX_SUCCESS=0, FIX_FAILURE_CONN_CLOSED=1, FIX_FAILURE_RECV_ZERO_B=2, FIX_FAILURE_SYSTEM=3, FIX_FAILURE_GARBLED=4 } failure_reason; void *user_data; } *session; unsigned long id; char name[32]; _Bool active; } *

user_defined_types: struct market { struct trader traders[100]; unsigned long traders_num; struct order_book book; }

user_defined_types: struct trader { struct fix_session *session; unsigned long id; char name[32]; _Bool active; }

user_defined_types: struct order_book { struct level levels[-1]; struct order orders[10000]; unsigned long orders_num; unsigned long best_ask; unsigned long best_bid; unsigned long book_id; char code[32]; }

user_defined_types: struct fix_session { struct fix_dialect *dialect; int sockfd; _Bool active; char *password; char *begin_string; char *sender_comp_id; char *target_comp_id; unsigned long in_msg_seq_num; unsigned long out_msg_seq_num; struct buffer *rx_buffer; struct buffer *tx_head_buffer; struct buffer *tx_body_buffer; struct fix_message *rx_message; int heartbtint; struct timespec now; char str_now[64]; struct timespec rx_timestamp; struct timespec tx_timestamp; char testreqid[64]; struct timespec tr_timestamp; int tr_pending; enum fix_failure_reason failure_reason; void *user_data; }

user_defined_types: struct level { struct order *head; struct order *tail; }

user_defined_types: struct fix_dialect { enum fix_version version; enum fix_type (*tag_type)(int tag); }

user_defined_types: struct fix_message { enum fix_msg_type type; char *begin_string; unsigned long body_length; char *msg_type; char *sender_comp_id; char *target_comp_id; unsigned long msg_seq_num; char *check_sum; char *str_now; struct buffer *head_buf; struct buffer *body_buf; unsigned long nr_fields; struct fix_field *fields; struct iovec iov[2]; }

user_defined_types: struct fix_field { int tag; enum fix_type type; union { long int_value; double float_value; char char_value; char *string_value; char string_8_value[8]; }; }


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

if ( a1 )
{
if ( *(_QWORD *)a1 )
result = fix_session_free();
*(_QWORD *)a1 = 0LL;
*(_BYTE *)(a1 + 48) = 0;
}
return result;
}

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

if ( a1 )
{
if ( *(_QWORD *)a1 )
result = fix_session_free();
*(_QWORD *)a1 = 0LL;
*(_BYTE *)(a1 + 48) = 0;
}
return result;
}

original_code:
static inline void trader_free(struct trader *trader)
{
 if (!trader)
  goto done;
 if (trader->session)
  fix_session_free(trader->session);
 trader->session = ((void *)0);
 trader->active = 0;
done:
 return;
}

return_type: void

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }

user_defined_types: enum fix_failure_reason { FIX_SUCCESS=0, FIX_FAILURE_CONN_CLOSED=1, FIX_FAILURE_RECV_ZERO_B=2, FIX_FAILURE_SYSTEM=3, FIX_FAILURE_GARBLED=4 }

user_defined_types: struct buffer { unsigned long start; unsigned long end; unsigned long capacity; char *data; }

user_defined_types: enum fix_msg_type { FIX_MSG_TYPE_HEARTBEAT=0, FIX_MSG_TYPE_TEST_REQUEST=1, FIX_MSG_TYPE_RESEND_REQUEST=2, FIX_MSG_TYPE_REJECT=3, FIX_MSG_TYPE_SEQUENCE_RESET=4, FIX_MSG_TYPE_LOGOUT=5, FIX_MSG_TYPE_EXECUTION_REPORT=6, FIX_MSG_TYPE_LOGON=7, FIX_MSG_TYPE_NEW_ORDER_SINGLE=8, FIX_MSG_TYPE_SNAPSHOT_REFRESH=9, FIX_MSG_TYPE_INCREMENT_REFRESH=10, FIX_MSG_TYPE_SESSION_STATUS=11, FIX_MSG_TYPE_SECURITY_STATUS=12, FIX_MSG_ORDER_CANCEL_REPLACE=13, FIX_MSG_ORDER_CANCEL_REJECT=14, FIX_MSG_ORDER_CANCEL_REQUEST=15, FIX_MSG_ORDER_MASS_CANCEL_REQUEST=16, FIX_MSG_ORDER_MASS_CANCEL_REPORT=17, FIX_MSG_QUOTE_REQUEST=18, FIX_MSG_SECURITY_DEFINITION_REQUEST=19, FIX_MSG_NEW_ORDER_CROSS=20, FIX_MSG_MASS_QUOTE=21, FIX_MSG_QUOTE_CANCEL=22, FIX_MSG_SECURITY_DEFINITION=23, FIX_MSG_QUOTE_ACKNOWLEDGEMENT=24, FIX_MSG_ORDER_MASS_STATUS_REQUEST=25, FIX_MSG_ORDER_MASS_ACTION_REQUEST=26, FIX_MSG_ORDER_MASS_ACTION_REPORT=27, FIX_MSG_TYPE_MAX=28, FIX_MSG_TYPE_UNKNOWN=expr }

user_defined_types: struct iovec { void *iov_base; unsigned long iov_len; }

user_defined_types: enum fix_type { FIX_TYPE_INT=0, FIX_TYPE_FLOAT=1, FIX_TYPE_CHAR=2, FIX_TYPE_STRING=3, FIX_TYPE_CHECKSUM=4, FIX_TYPE_MSGSEQNUM=5, FIX_TYPE_STRING_8=6 }


decompiled_code:
__int64 __fastcall do_income(_QWORD *a1, int a2)
{
__int64 *v3; // rax
__int64 v4; // rdi
__int64 v5; // rbp
bool v6; // zf
const char **v7; // rax
__int64 v8; // rdi
__int64 v10; // rdi
__int64 v11; // rax
__int64 v12; // rbp
_DWORD *v13; // rax
char v14; // al
double *v15; // rax
double v16; // xmm0_8
double *v17; // rax
double v18; // xmm0_8
__int64 v19; // rax
__int64 v20; // [rsp+8h] [rbp-180h] BYREF
__int64 v21; // [rsp+10h] [rbp-178h] BYREF
__int64 v22; // [rsp+18h] [rbp-170h]
__int64 v23; // [rsp+30h] [rbp-158h]
__int64 v24; // [rsp+38h] [rbp-150h]
__int64 v25[18]; // [rsp+40h] [rbp-148h] BYREF
_QWORD v26[2]; // [rsp+D0h] [rbp-B8h] BYREF
__int128 v27; // [rsp+E0h] [rbp-A8h]
__int64 v28; // [rsp+F0h] [rbp-98h]
__int64 v29; // [rsp+F8h] [rbp-90h]
__int128 v30; // [rsp+100h] [rbp-88h]
__int64 v31; // [rsp+138h] [rbp-50h]
int v32; // [rsp+140h] [rbp-48h]

fix_session_cfg_init(v26);
v3 = trader_by_sock(a1, a2);
if ( v3 )
{
v4 = *v3;
v5 = (__int64)v3;
}
else
{
v5 = trader_new((__int64)a1);
if ( !v5 )
return 0xFFFFFFFFLL;
v26[0] = 0x454449534C4C4553LL;
v26[1] = 0LL;
v27 = 0LL;
v28 = 0x45444953595542LL;
v29 = 0LL;
v32 = a2;
v31 = (__int64)&fix_dialects + 64;
v30 = 0LL;
v19 = fix_session_new(v26);
*(_QWORD *)v5 = v19;
v4 = v19;
if ( !v19 )
return 0xFFFFFFFFLL;
}
if ( (int)fix_session_recv(v4, &v20, 0LL) <= 0 )
return 0LL;
v6 = *(_BYTE *)(v5 + 48) == 0;
v25[11] = 0LL;
if ( v6 )
{
if ( (unsigned __int8)fix_message_type_is(v20, 7LL) )
{
v7 = (const char **)fix_field_by_tag(v20, 49);
if ( v7 )
{
strncpy((char *)(v5 + 16), v7[1], 0x20uLL);
*(_BYTE *)(v5 + 48) = 1;
v8 = *(_QWORD *)v5;
v25[0] = 7LL;
fix_session_send(v8, v25, 0LL);
return 0LL;
}
}
LABEL_8:
v10 = *(_QWORD *)v5;
v25[0] = 5LL;
fix_session_send(v10, v25, 0LL);
trader_free(v5);
close(a2);
return 0LL;
}
if ( (unsigned __int8)fix_session_admin(*(_QWORD *)v5, v20) )
return 0LL;
if ( (unsigned __int8)fix_message_type_is(v20, 5LL) )
goto LABEL_8;
if ( !(unsigned __int8)fix_message_type_is(v20, 8LL) )
return 0LL;
v11 = *(_QWORD *)(v5 + 8);
v12 = v20;
v21 = v11;
v13 = fix_field_by_tag(v20, 54);
if ( !v13 )
return 0LL;
v14 = **((_BYTE **)v13 + 1);
if ( v14 == 49 )
{
v23 = 0LL;
}
else
{
if ( v14 != 50 )
return 0LL;
v23 = 1LL;
}
v15 = (double *)fix_field_by_tag(v12, 44);
if ( !v15 )
return 0LL;
v16 = round(v15[1]);
if ( v16 >= 9.223372036854776e18 )
{
v22 = (unsigned int)(int)(v16 - 9.223372036854776e18);
v22 ^= 0x8000000000000000LL;
}
else
{
v22 = (unsigned int)(int)v16;
}
v17 = (double *)fix_field_by_tag(v12, 38);
if ( !v17 )
return 0LL;
v18 = round(v17[1]);
if ( v18 >= 9.223372036854776e18 )
{
v24 = (unsigned int)(int)(v18 - 9.223372036854776e18);
v24 ^= 0x8000000000000000LL;
}
else
{
v24 = (unsigned int)(int)v18;
}
do_limit(a1 + 701, &v21);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, int a2)
{
__int64 *v3; // rax
__int64 v4; // rdi
__int64 v5; // rbp
bool v6; // zf
const char **v7; // rax
__int64 v8; // rdi
__int64 v10; // rdi
__int64 v11; // rax
__int64 v12; // rbp
_DWORD *v13; // rax
char v14; // al
double *v15; // rax
double v16; // xmm0_8
double *v17; // rax
double v18; // xmm0_8
__int64 v19; // rax
__int64 v20; // [rsp+8h] [rbp-180h] BYREF
__int64 v21; // [rsp+10h] [rbp-178h] BYREF
__int64 v22; // [rsp+18h] [rbp-170h]
__int64 v23; // [rsp+30h] [rbp-158h]
__int64 v24; // [rsp+38h] [rbp-150h]
__int64 v25[18]; // [rsp+40h] [rbp-148h] BYREF
_QWORD v26[2]; // [rsp+D0h] [rbp-B8h] BYREF
__int128 v27; // [rsp+E0h] [rbp-A8h]
__int64 v28; // [rsp+F0h] [rbp-98h]
__int64 v29; // [rsp+F8h] [rbp-90h]
__int128 v30; // [rsp+100h] [rbp-88h]
__int64 v31; // [rsp+138h] [rbp-50h]
int v32; // [rsp+140h] [rbp-48h]

fix_session_cfg_init(v26);
v3 = trader_by_sock(a1, a2);
if ( v3 )
{
v4 = *v3;
v5 = (__int64)v3;
}
else
{
v5 = func0((__int64)a1);
if ( !v5 )
return 0xFFFFFFFFLL;
v26[0] = 0x454449534C4C4553LL;
v26[1] = 0LL;
v27 = 0LL;
v28 = 0x45444953595542LL;
v29 = 0LL;
v32 = a2;
v31 = (__int64)&fix_dialects + 64;
v30 = 0LL;
v19 = fix_session_new(v26);
*(_QWORD *)v5 = v19;
v4 = v19;
if ( !v19 )
return 0xFFFFFFFFLL;
}
if ( (int)fix_session_recv(v4, &v20, 0LL) <= 0 )
return 0LL;
v6 = *(_BYTE *)(v5 + 48) == 0;
v25[11] = 0LL;
if ( v6 )
{
if ( (unsigned __int8)fix_message_type_is(v20, 7LL) )
{
v7 = (const char **)fix_field_by_tag(v20, 49);
if ( v7 )
{
strncpy((char *)(v5 + 16), v7[1], 0x20uLL);
*(_BYTE *)(v5 + 48) = 1;
v8 = *(_QWORD *)v5;
v25[0] = 7LL;
fix_session_send(v8, v25, 0LL);
return 0LL;
}
}
LABEL_8:
v10 = *(_QWORD *)v5;
v25[0] = 5LL;
fix_session_send(v10, v25, 0LL);
func3(v5);
close(a2);
return 0LL;
}
if ( (unsigned __int8)fix_session_admin(*(_QWORD *)v5, v20) )
return 0LL;
if ( (unsigned __int8)fix_message_type_is(v20, 5LL) )
goto LABEL_8;
if ( !(unsigned __int8)fix_message_type_is(v20, 8LL) )
return 0LL;
v11 = *(_QWORD *)(v5 + 8);
v12 = v20;
v21 = v11;
v13 = fix_field_by_tag(v20, 54);
if ( !v13 )
return 0LL;
v14 = **((_BYTE **)v13 + 1);
if ( v14 == 49 )
{
v23 = 0LL;
}
else
{
if ( v14 != 50 )
return 0LL;
v23 = 1LL;
}
v15 = (double *)fix_field_by_tag(v12, 44);
if ( !v15 )
return 0LL;
v16 = round(v15[1]);
if ( v16 >= 9.223372036854776e18 )
{
v22 = (unsigned int)(int)(v16 - 9.223372036854776e18);
v22 ^= 0x8000000000000000LL;
}
else
{
v22 = (unsigned int)(int)v16;
}
v17 = (double *)fix_field_by_tag(v12, 38);
if ( !v17 )
return 0LL;
v18 = round(v17[1]);
if ( v18 >= 9.223372036854776e18 )
{
v24 = (unsigned int)(int)(v18 - 9.223372036854776e18);
v24 ^= 0x8000000000000000LL;
}
else
{
v24 = (unsigned int)(int)v18;
}
do_limit(a1 + 701, &v21);
return 0LL;
}

original_code:
static int do_income(struct market *market, int sockfd)
{
 struct fix_message *recv_msg;
 struct fix_message send_msg;
 struct fix_session_cfg cfg;
 struct fix_field *field;
 struct trader *trader;
 struct order order;
 fix_session_cfg_init(&cfg);
 trader = trader_by_sock(market, sockfd);
 if (!trader) {
  trader = trader_new(market);
  if (!trader)
   goto fail;
  strncpy(cfg.sender_comp_id, "SELLSIDE",
    (sizeof(cfg.sender_comp_id) / sizeof((cfg.sender_comp_id)[0])));
  strncpy(cfg.target_comp_id, "BUYSIDE",
    (sizeof(cfg.target_comp_id) / sizeof((cfg.target_comp_id)[0])));
  cfg.dialect = &fix_dialects[FIX_4_4];
  cfg.sockfd = sockfd;
  trader->session = fix_session_new(&cfg);
  if (!trader->session)
   goto fail;
 }
 if (fix_session_recv(trader->session, &recv_msg, 0) <= 0)
  goto done;
 send_msg.nr_fields = 0;
 if (!trader->active) {
  if (!fix_message_type_is(recv_msg, FIX_MSG_TYPE_LOGON))
   goto logout;
  field = fix_field_by_tag(recv_msg, SenderCompID);
  if (!field)
   goto logout;
  strncpy(trader->name, field->string_value, 32);
  trader->active = 1;
  send_msg.type = FIX_MSG_TYPE_LOGON;
  fix_session_send(trader->session, &send_msg, 0);
  goto done;
 }
 if (fix_session_admin(trader->session, recv_msg))
  goto done;
 if (fix_message_type_is(recv_msg, FIX_MSG_TYPE_LOGOUT)) {
  goto logout;
 } else if (fix_message_type_is(recv_msg, FIX_MSG_TYPE_NEW_ORDER_SINGLE)) {
  order.trader = trader->id;
  field = fix_field_by_tag(recv_msg, Side);
  if (!field)
   goto done;
  if (field->string_value[0] == '1')
   order.side = 0;
  else if (field->string_value[0] == '2')
   order.side = 1;
  else
   goto done;
  field = fix_field_by_tag(recv_msg, Price);
  if (!field)
   goto done;
  order.level = round(field->float_value);
  field = fix_field_by_tag(recv_msg, OrderQty);
  if (!field)
   goto done;
  order.size = round(field->float_value);
  if (do_limit(&market->book, &order))
   goto done;
 }
done:
 return 0;
fail:
 return -1;
logout:
 send_msg.type = FIX_MSG_TYPE_LOGOUT;
 fix_session_send(trader->session, &send_msg, 0);
 trader_free(trader);
 close(sockfd);
 return 0;
}

variable_types: struct market { struct trader { struct fix_session { struct fix_dialect { enum fix_version { FIX_4_0=0, FIX_4_1=1, FIX_4_2=2, FIX_4_3=3, FIX_4_4=4, FIX_5_0=5, FIXT_1_1=6 } version; enum fix_type { FIX_TYPE_INT=0, FIX_TYPE_FLOAT=1, FIX_TYPE_CHAR=2, FIX_TYPE_STRING=3, FIX_TYPE_CHECKSUM=4, FIX_TYPE_MSGSEQNUM=5, FIX_TYPE_STRING_8=6 } (*tag_type)(int tag); } *dialect; int sockfd; _Bool active; char *password; char *begin_string; char *sender_comp_id; char *target_comp_id; unsigned long in_msg_seq_num; unsigned long out_msg_seq_num; struct buffer { unsigned long start; unsigned long end; unsigned long capacity; char *data; } *rx_buffer; struct buffer *tx_head_buffer; struct buffer *tx_body_buffer; struct fix_message { enum fix_msg_type { FIX_MSG_TYPE_HEARTBEAT=0, FIX_MSG_TYPE_TEST_REQUEST=1, FIX_MSG_TYPE_RESEND_REQUEST=2, FIX_MSG_TYPE_REJECT=3, FIX_MSG_TYPE_SEQUENCE_RESET=4, FIX_MSG_TYPE_LOGOUT=5, FIX_MSG_TYPE_EXECUTION_REPORT=6, FIX_MSG_TYPE_LOGON=7, FIX_MSG_TYPE_NEW_ORDER_SINGLE=8, FIX_MSG_TYPE_SNAPSHOT_REFRESH=9, FIX_MSG_TYPE_INCREMENT_REFRESH=10, FIX_MSG_TYPE_SESSION_STATUS=11, FIX_MSG_TYPE_SECURITY_STATUS=12, FIX_MSG_ORDER_CANCEL_REPLACE=13, FIX_MSG_ORDER_CANCEL_REJECT=14, FIX_MSG_ORDER_CANCEL_REQUEST=15, FIX_MSG_ORDER_MASS_CANCEL_REQUEST=16, FIX_MSG_ORDER_MASS_CANCEL_REPORT=17, FIX_MSG_QUOTE_REQUEST=18, FIX_MSG_SECURITY_DEFINITION_REQUEST=19, FIX_MSG_NEW_ORDER_CROSS=20, FIX_MSG_MASS_QUOTE=21, FIX_MSG_QUOTE_CANCEL=22, FIX_MSG_SECURITY_DEFINITION=23, FIX_MSG_QUOTE_ACKNOWLEDGEMENT=24, FIX_MSG_ORDER_MASS_STATUS_REQUEST=25, FIX_MSG_ORDER_MASS_ACTION_REQUEST=26, FIX_MSG_ORDER_MASS_ACTION_REPORT=27, FIX_MSG_TYPE_MAX=28, FIX_MSG_TYPE_UNKNOWN=expr } type; char *begin_string; unsigned long body_length; char *msg_type; char *sender_comp_id; char *target_comp_id; unsigned long msg_seq_num; char *check_sum; char *str_now; struct buffer *head_buf; struct buffer *body_buf; unsigned long nr_fields; struct fix_field { int tag; enum fix_type { FIX_TYPE_INT=0, FIX_TYPE_FLOAT=1, FIX_TYPE_CHAR=2, FIX_TYPE_STRING=3, FIX_TYPE_CHECKSUM=4, FIX_TYPE_MSGSEQNUM=5, FIX_TYPE_STRING_8=6 } type; union { long int_value; double float_value; char char_value; char *string_value; char string_8_value[8]; }; } *fields; struct iovec { void *iov_base; unsigned long iov_len; } iov[2]; } *rx_message; int heartbtint; struct timespec { long tv_sec; long tv_nsec; } now; char str_now[64]; struct timespec rx_timestamp; struct timespec tx_timestamp; char testreqid[64]; struct timespec tr_timestamp; int tr_pending; enum fix_failure_reason { FIX_SUCCESS=0, FIX_FAILURE_CONN_CLOSED=1, FIX_FAILURE_RECV_ZERO_B=2, FIX_FAILURE_SYSTEM=3, FIX_FAILURE_GARBLED=4 } failure_reason; void *user_data; } *session; unsigned long id; char name[32]; _Bool active; } traders[100]; unsigned long traders_num; struct order_book { struct level { struct order { unsigned long trader; unsigned long level; struct order *next; struct order *prev; unsigned long side; unsigned long size; } *head; struct order *tail; } levels[-1]; struct order orders[10000]; unsigned long orders_num; unsigned long best_ask; unsigned long best_bid; unsigned long book_id; char code[32]; } book; } *

variable_types: sockfd int

variable_types: struct fix_message { enum fix_msg_type { FIX_MSG_TYPE_HEARTBEAT=0, FIX_MSG_TYPE_TEST_REQUEST=1, FIX_MSG_TYPE_RESEND_REQUEST=2, FIX_MSG_TYPE_REJECT=3, FIX_MSG_TYPE_SEQUENCE_RESET=4, FIX_MSG_TYPE_LOGOUT=5, FIX_MSG_TYPE_EXECUTION_REPORT=6, FIX_MSG_TYPE_LOGON=7, FIX_MSG_TYPE_NEW_ORDER_SINGLE=8, FIX_MSG_TYPE_SNAPSHOT_REFRESH=9, FIX_MSG_TYPE_INCREMENT_REFRESH=10, FIX_MSG_TYPE_SESSION_STATUS=11, FIX_MSG_TYPE_SECURITY_STATUS=12, FIX_MSG_ORDER_CANCEL_REPLACE=13, FIX_MSG_ORDER_CANCEL_REJECT=14, FIX_MSG_ORDER_CANCEL_REQUEST=15, FIX_MSG_ORDER_MASS_CANCEL_REQUEST=16, FIX_MSG_ORDER_MASS_CANCEL_REPORT=17, FIX_MSG_QUOTE_REQUEST=18, FIX_MSG_SECURITY_DEFINITION_REQUEST=19, FIX_MSG_NEW_ORDER_CROSS=20, FIX_MSG_MASS_QUOTE=21, FIX_MSG_QUOTE_CANCEL=22, FIX_MSG_SECURITY_DEFINITION=23, FIX_MSG_QUOTE_ACKNOWLEDGEMENT=24, FIX_MSG_ORDER_MASS_STATUS_REQUEST=25, FIX_MSG_ORDER_MASS_ACTION_REQUEST=26, FIX_MSG_ORDER_MASS_ACTION_REPORT=27, FIX_MSG_TYPE_MAX=28, FIX_MSG_TYPE_UNKNOWN=expr } type; char *begin_string; unsigned long body_length; char *msg_type; char *sender_comp_id; char *target_comp_id; unsigned long msg_seq_num; char *check_sum; char *str_now; struct buffer { unsigned long start; unsigned long end; unsigned long capacity; char *data; } *head_buf; struct buffer *body_buf; unsigned long nr_fields; struct fix_field { int tag; enum fix_type { FIX_TYPE_INT=0, FIX_TYPE_FLOAT=1, FIX_TYPE_CHAR=2, FIX_TYPE_STRING=3, FIX_TYPE_CHECKSUM=4, FIX_TYPE_MSGSEQNUM=5, FIX_TYPE_STRING_8=6 } type; union { long int_value; double float_value; char char_value; char *string_value; char string_8_value[8]; }; } *fields; struct iovec { void *iov_base; unsigned long iov_len; } iov[2]; } *

variable_types: struct fix_session_cfg { char sender_comp_id[32]; char target_comp_id[32]; char password[32]; int heartbtint; struct fix_dialect { enum fix_version { FIX_4_0=0, FIX_4_1=1, FIX_4_2=2, FIX_4_3=3, FIX_4_4=4, FIX_5_0=5, FIXT_1_1=6 } version; enum fix_type { FIX_TYPE_INT=0, FIX_TYPE_FLOAT=1, FIX_TYPE_CHAR=2, FIX_TYPE_STRING=3, FIX_TYPE_CHECKSUM=4, FIX_TYPE_MSGSEQNUM=5, FIX_TYPE_STRING_8=6 } (*tag_type)(int tag); } *dialect; int sockfd; unsigned long in_msg_seq_num; unsigned long out_msg_seq_num; void *user_data; }

return_type: int

user_defined_types: struct fix_session_cfg { char sender_comp_id[32]; char target_comp_id[32]; char password[32]; int heartbtint; struct fix_dialect *dialect; int sockfd; unsigned long in_msg_seq_num; unsigned long out_msg_seq_num; void *user_data; }


decompiled_code:
int __fastcall ev_cb(int fd, __int64 a2, _QWORD *a3)
{
int result; // eax

result = do_income(a3, fd);
if ( result )
result = close(fd);
return result;
}

canonical_decompiled_code:
int __fastcall func5(int fd, __int64 a2, _QWORD *a3)
{
int result; // eax

result = func4(a3, fd);
if ( result )
result = close(fd);
return result;
}

original_code:
static void ev_cb(int sockfd, short events, void *arg)
{
 if (do_income(arg, sockfd))
  close(sockfd);
 return;
}

variable_types: events short

variable_types:
arg
void *


decompiled_code:
__int64 __fastcall market_init(void *a1)
{
char *v1; // rax

v1 = (char *)memset(a1, 0, 0x76F88uLL);
return order_book_init(v1 + 5608);
}

canonical_decompiled_code:
__int64 __fastcall func7(void *a1)
{
char *v1; // rax

v1 = (char *)memset(a1, 0, 0x76F88uLL);
return order_book_init(v1 + 5608);
}

original_code:
static void market_init(struct market *market)
{
 memset(market, 0, sizeof(struct market));
 order_book_init(&market->book);
 return;
}

user_defined_types: struct order { unsigned long trader; unsigned long level; struct order *next; struct order *prev; unsigned long side; unsigned long size; }


usage

decompiled_code:
void __noreturn usage()
{
fprintf(stderr, "\n usage: %s -p port\n\n", (const char *)program);
exit(1);
}

canonical_decompiled_code:
void __noreturn func6()
{
fprintf(stderr, "\n usage: %s -p port\n\n", (const char *)program);
exit(1);
}

original_code:
static void usage(void)
{
 fprintf(stderr, "\n usage: %s -p port\n\n", program);
 exit(1);
}

canonical_original_code:
static void usage()
{
 fprintf(stderr, "\n usage: %s -p port\n\n", program);
 exit(1);
}


original_code:
static unsigned long fix_execution_report_fields(struct fix_field *fields)
{
 unsigned long nr = 0;
 fields[nr++] = (struct fix_field) { .tag = OrderID, .type = FIX_TYPE_STRING, { .string_value = "OrderID" }, };
 fields[nr++] = (struct fix_field) { .tag = Symbol, .type = FIX_TYPE_STRING, { .string_value = "Symbol" }, };
 fields[nr++] = (struct fix_field) { .tag = ExecID, .type = FIX_TYPE_STRING, { .string_value = "ExecID" }, };
 fields[nr++] = (struct fix_field) { .tag = OrdStatus, .type = FIX_TYPE_STRING, { .string_value = "2" }, };
 fields[nr++] = (struct fix_field) { .tag = ExecType, .type = FIX_TYPE_STRING, { .string_value = "0" }, };
 fields[nr++] = (struct fix_field) { .tag = LeavesQty, .type = FIX_TYPE_FLOAT, { .float_value = 0 }, };
 fields[nr++] = (struct fix_field) { .tag = CumQty, .type = FIX_TYPE_FLOAT, { .float_value = 100 }, };
 fields[nr++] = (struct fix_field) { .tag = AvgPx, .type = FIX_TYPE_FLOAT, { .float_value = 100 }, };
 fields[nr++] = (struct fix_field) { .tag = Side, .type = FIX_TYPE_STRING, { .string_value = "1" }, };
 return nr;
}

variable_types: struct fix_field { int tag; enum fix_type { FIX_TYPE_INT=0, FIX_TYPE_FLOAT=1, FIX_TYPE_CHAR=2, FIX_TYPE_STRING=3, FIX_TYPE_CHECKSUM=4, FIX_TYPE_MSGSEQNUM=5, FIX_TYPE_STRING_8=6 } type; union { long int_value; double float_value; char char_value; char *string_value; char string_8_value[8]; }; } *

variable_types:
nr
unsigned long


decompiled_code:
__int64 __fastcall fix_server_logon(__int64 a1)
{
unsigned int v1; // er12
__int64 v3; // [rsp+8h] [rbp-B0h] BYREF
__int64 v4; // [rsp+10h] [rbp-A8h] BYREF
char v5[128]; // [rsp+18h] [rbp-A0h] BYREF

while ( (int)fix_session_recv(a1, &v3, 0x10000LL) <= 0 )
;
v1 = fix_message_type_is(v3, 7LL);
if ( (_BYTE)v1 )
{
memset(v5, 0, sizeof(v5));
v4 = 7LL;
fix_session_send(a1, &v4, 0LL);
*(_BYTE *)(a1 + 12) = 1;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
unsigned int v1; // er12
__int64 v3; // [rsp+8h] [rbp-B0h] BYREF
__int64 v4; // [rsp+10h] [rbp-A8h] BYREF
char v5[128]; // [rsp+18h] [rbp-A0h] BYREF

while ( (int)fix_session_recv(a1, &v3, 0x10000LL) <= 0 )
;
v1 = fix_message_type_is(v3, 7LL);
if ( (_BYTE)v1 )
{
memset(v5, 0, sizeof(v5));
v4 = 7LL;
fix_session_send(a1, &v4, 0LL);
*(_BYTE *)(a1 + 12) = 1;
}
return v1;
}

original_code:
static _Bool fix_server_logon(struct fix_session *session)
{
 struct fix_message logon_msg;
 struct fix_message *msg;
retry:
 if (fix_session_recv(session, &msg, FIX_RECV_FLAG_MSG_DONTWAIT) <= 0)
  goto retry;
 if (!fix_message_type_is(msg, FIX_MSG_TYPE_LOGON))
  return 0;
 logon_msg = (struct fix_message) {
  .type = FIX_MSG_TYPE_LOGON,
 };
 fix_session_send(session, &logon_msg, 0);
 session->active = 1;
 return 1;
}

variable_types: struct fix_session { struct fix_dialect { enum fix_version { FIX_4_0=0, FIX_4_1=1, FIX_4_2=2, FIX_4_3=3, FIX_4_4=4, FIX_5_0=5, FIXT_1_1=6 } version; enum fix_type { FIX_TYPE_INT=0, FIX_TYPE_FLOAT=1, FIX_TYPE_CHAR=2, FIX_TYPE_STRING=3, FIX_TYPE_CHECKSUM=4, FIX_TYPE_MSGSEQNUM=5, FIX_TYPE_STRING_8=6 } (*tag_type)(int tag); } *dialect; int sockfd; _Bool active; char *password; char *begin_string; char *sender_comp_id; char *target_comp_id; unsigned long in_msg_seq_num; unsigned long out_msg_seq_num; struct buffer { unsigned long start; unsigned long end; unsigned long capacity; char *data; } *rx_buffer; struct buffer *tx_head_buffer; struct buffer *tx_body_buffer; struct fix_message { enum fix_msg_type { FIX_MSG_TYPE_HEARTBEAT=0, FIX_MSG_TYPE_TEST_REQUEST=1, FIX_MSG_TYPE_RESEND_REQUEST=2, FIX_MSG_TYPE_REJECT=3, FIX_MSG_TYPE_SEQUENCE_RESET=4, FIX_MSG_TYPE_LOGOUT=5, FIX_MSG_TYPE_EXECUTION_REPORT=6, FIX_MSG_TYPE_LOGON=7, FIX_MSG_TYPE_NEW_ORDER_SINGLE=8, FIX_MSG_TYPE_SNAPSHOT_REFRESH=9, FIX_MSG_TYPE_INCREMENT_REFRESH=10, FIX_MSG_TYPE_SESSION_STATUS=11, FIX_MSG_TYPE_SECURITY_STATUS=12, FIX_MSG_ORDER_CANCEL_REPLACE=13, FIX_MSG_ORDER_CANCEL_REJECT=14, FIX_MSG_ORDER_CANCEL_REQUEST=15, FIX_MSG_ORDER_MASS_CANCEL_REQUEST=16, FIX_MSG_ORDER_MASS_CANCEL_REPORT=17, FIX_MSG_QUOTE_REQUEST=18, FIX_MSG_SECURITY_DEFINITION_REQUEST=19, FIX_MSG_NEW_ORDER_CROSS=20, FIX_MSG_MASS_QUOTE=21, FIX_MSG_QUOTE_CANCEL=22, FIX_MSG_SECURITY_DEFINITION=23, FIX_MSG_QUOTE_ACKNOWLEDGEMENT=24, FIX_MSG_ORDER_MASS_STATUS_REQUEST=25, FIX_MSG_ORDER_MASS_ACTION_REQUEST=26, FIX_MSG_ORDER_MASS_ACTION_REPORT=27, FIX_MSG_TYPE_MAX=28, FIX_MSG_TYPE_UNKNOWN=expr } type; char *begin_string; unsigned long body_length; char *msg_type; char *sender_comp_id; char *target_comp_id; unsigned long msg_seq_num; char *check_sum; char *str_now; struct buffer *head_buf; struct buffer *body_buf; unsigned long nr_fields; struct fix_field { int tag; enum fix_type { FIX_TYPE_INT=0, FIX_TYPE_FLOAT=1, FIX_TYPE_CHAR=2, FIX_TYPE_STRING=3, FIX_TYPE_CHECKSUM=4, FIX_TYPE_MSGSEQNUM=5, FIX_TYPE_STRING_8=6 } type; union { long int_value; double float_value; char char_value; char *string_value; char string_8_value[8]; }; } *fields; struct iovec { void *iov_base; unsigned long iov_len; } iov[2]; } *rx_message; int heartbtint; struct timespec { long tv_sec; long tv_nsec; } now; char str_now[64]; struct timespec rx_timestamp; struct timespec tx_timestamp; char testreqid[64]; struct timespec tr_timestamp; int tr_pending; enum fix_failure_reason { FIX_SUCCESS=0, FIX_FAILURE_CONN_CLOSED=1, FIX_FAILURE_RECV_ZERO_B=2, FIX_FAILURE_SYSTEM=3, FIX_FAILURE_GARBLED=4 } failure_reason; void *user_data; } *

variable_types: struct fix_message { enum fix_msg_type { FIX_MSG_TYPE_HEARTBEAT=0, FIX_MSG_TYPE_TEST_REQUEST=1, FIX_MSG_TYPE_RESEND_REQUEST=2, FIX_MSG_TYPE_REJECT=3, FIX_MSG_TYPE_SEQUENCE_RESET=4, FIX_MSG_TYPE_LOGOUT=5, FIX_MSG_TYPE_EXECUTION_REPORT=6, FIX_MSG_TYPE_LOGON=7, FIX_MSG_TYPE_NEW_ORDER_SINGLE=8, FIX_MSG_TYPE_SNAPSHOT_REFRESH=9, FIX_MSG_TYPE_INCREMENT_REFRESH=10, FIX_MSG_TYPE_SESSION_STATUS=11, FIX_MSG_TYPE_SECURITY_STATUS=12, FIX_MSG_ORDER_CANCEL_REPLACE=13, FIX_MSG_ORDER_CANCEL_REJECT=14, FIX_MSG_ORDER_CANCEL_REQUEST=15, FIX_MSG_ORDER_MASS_CANCEL_REQUEST=16, FIX_MSG_ORDER_MASS_CANCEL_REPORT=17, FIX_MSG_QUOTE_REQUEST=18, FIX_MSG_SECURITY_DEFINITION_REQUEST=19, FIX_MSG_NEW_ORDER_CROSS=20, FIX_MSG_MASS_QUOTE=21, FIX_MSG_QUOTE_CANCEL=22, FIX_MSG_SECURITY_DEFINITION=23, FIX_MSG_QUOTE_ACKNOWLEDGEMENT=24, FIX_MSG_ORDER_MASS_STATUS_REQUEST=25, FIX_MSG_ORDER_MASS_ACTION_REQUEST=26, FIX_MSG_ORDER_MASS_ACTION_REPORT=27, FIX_MSG_TYPE_MAX=28, FIX_MSG_TYPE_UNKNOWN=expr } type; char *begin_string; unsigned long body_length; char *msg_type; char *sender_comp_id; char *target_comp_id; unsigned long msg_seq_num; char *check_sum; char *str_now; struct buffer { unsigned long start; unsigned long end; unsigned long capacity; char *data; } *head_buf; struct buffer *body_buf; unsigned long nr_fields; struct fix_field { int tag; enum fix_type { FIX_TYPE_INT=0, FIX_TYPE_FLOAT=1, FIX_TYPE_CHAR=2, FIX_TYPE_STRING=3, FIX_TYPE_CHECKSUM=4, FIX_TYPE_MSGSEQNUM=5, FIX_TYPE_STRING_8=6 } type; union { long int_value; double float_value; char char_value; char *string_value; char string_8_value[8]; }; } *fields; struct iovec { void *iov_base; unsigned long iov_len; } iov[2]; }


decompiled_code:
__int64 __fastcall fix_server_logout(__int64 a1)
{
unsigned int v2; // er12
__int64 v3; // [rsp+8h] [rbp-B0h] BYREF
__int64 v4; // [rsp+10h] [rbp-A8h] BYREF
char v5[128]; // [rsp+18h] [rbp-A0h] BYREF

do
{
if ( !*(_BYTE *)(a1 + 12) )
return 1LL;
}
while ( (int)fix_session_recv(a1, &v3, 0x10000LL) <= 0 );
v2 = fix_message_type_is(v3, 5LL);
v4 = 5LL;
memset(v5, 0, sizeof(v5));
fix_session_send(a1, &v4, 0LL);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
unsigned int v2; // er12
__int64 v3; // [rsp+8h] [rbp-B0h] BYREF
__int64 v4; // [rsp+10h] [rbp-A8h] BYREF
char v5[128]; // [rsp+18h] [rbp-A0h] BYREF

do
{
if ( !*(_BYTE *)(a1 + 12) )
return 1LL;
}
while ( (int)fix_session_recv(a1, &v3, 0x10000LL) <= 0 );
v2 = fix_message_type_is(v3, 5LL);
v4 = 5LL;
memset(v5, 0, sizeof(v5));
fix_session_send(a1, &v4, 0LL);
return v2;
}

original_code:
static _Bool fix_server_logout(struct fix_session *session)
{
 struct fix_message logout_msg;
 struct fix_message *msg;
 _Bool ret = 1;
retry:
 if (!session->active)
  goto exit;
 if (fix_session_recv(session, &msg, FIX_RECV_FLAG_MSG_DONTWAIT) <= 0)
  goto retry;
 if (!fix_message_type_is(msg, FIX_MSG_TYPE_LOGOUT))
  ret = 0;
 logout_msg = (struct fix_message) {
  .type = FIX_MSG_TYPE_LOGOUT,
 };
 fix_session_send(session, &logout_msg, 0);
exit:
 return ret;
}


decompiled_code:
__int64 fix_server_session()
{
__int64 v0; // rax
__int64 v1; // rbp
_QWORD *v2; // rax
void *v3; // r12
__int64 v4; // r13
unsigned int v5; // er13
__int64 v7; // [rsp+8h] [rbp-150h] BYREF
__int64 v8; // [rsp+10h] [rbp-148h] BYREF
char v9[128]; // [rsp+18h] [rbp-140h] BYREF
__int64 v10; // [rsp+A0h] [rbp-B8h] BYREF
char v11[128]; // [rsp+A8h] [rbp-B0h] BYREF

v0 = fix_session_new();
v1 = v0;
if ( v0
&& (fix_session_recv(v0, &v7, 0x10000LL),
v8 = 7LL,
memset(v9, 0, sizeof(v9)),
fix_session_send(v1, &v8, 0LL),
v2 = calloc(0x30uLL, 0x10uLL),
(v3 = v2) != 0LL) )
{
v4 = fix_execution_report_fields(v2);
do
{
while ( 1 )
{
while ( (int)fix_session_recv(v1, &v7, 0x10000LL) <= 0 )
;
if ( !(unsigned __int8)fix_message_type_is(v7, 8LL) )
break;
fix_session_execution_report(v1, v3, v4);
}
}
while ( !(unsigned __int8)fix_message_type_is(v7, 5LL) );
v5 = 0;
v10 = 5LL;
memset(v11, 0, sizeof(v11));
fix_session_send(v1, &v10, 0LL);
}
else
{
v5 = -1;
v3 = 0LL;
}
fix_session_free(v1);
free(v3);
return v5;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rax
__int64 v1; // rbp
_QWORD *v2; // rax
void *v3; // r12
__int64 v4; // r13
unsigned int v5; // er13
__int64 v7; // [rsp+8h] [rbp-150h] BYREF
__int64 v8; // [rsp+10h] [rbp-148h] BYREF
char v9[128]; // [rsp+18h] [rbp-140h] BYREF
__int64 v10; // [rsp+A0h] [rbp-B8h] BYREF
char v11[128]; // [rsp+A8h] [rbp-B0h] BYREF

v0 = fix_session_new();
v1 = v0;
if ( v0
&& (fix_session_recv(v0, &v7, 0x10000LL),
v8 = 7LL,
memset(v9, 0, sizeof(v9)),
fix_session_send(v1, &v8, 0LL),
v2 = calloc(0x30uLL, 0x10uLL),
(v3 = v2) != 0LL) )
{
v4 = func0(v2);
do
{
while ( 1 )
{
while ( (int)fix_session_recv(v1, &v7, 0x10000LL) <= 0 )
;
if ( !(unsigned __int8)fix_message_type_is(v7, 8LL) )
break;
fix_session_execution_report(v1, v3, v4);
}
}
while ( !(unsigned __int8)fix_message_type_is(v7, 5LL) );
v5 = 0;
v10 = 5LL;
memset(v11, 0, sizeof(v11));
fix_session_send(v1, &v10, 0LL);
}
else
{
v5 = -1;
v3 = 0LL;
}
fix_session_free(v1);
free(v3);
return v5;
}

original_code:
static int fix_server_session(struct fix_session_cfg *cfg, struct fix_server_arg *arg)
{
 struct fix_session *session = ((void *)0);
 struct fix_field *fields = ((void *)0);
 struct fix_message logon_msg;
 struct fix_message *msg;
 unsigned long nr;
 int ret = -1;
 session = fix_session_new(cfg);
 if (!session)
  goto exit;
 fix_session_recv(session, &msg, FIX_RECV_FLAG_MSG_DONTWAIT);
 logon_msg = (struct fix_message) {
  .type = FIX_MSG_TYPE_LOGON,
 };
 fix_session_send(session, &logon_msg, 0);
 fields = calloc(48, sizeof(struct fix_field));
 if (!fields)
  goto exit;
 nr = fix_execution_report_fields(fields);
 for (;;) {
  struct fix_message logout_msg;
  if (fix_session_recv(session, &msg, FIX_RECV_FLAG_MSG_DONTWAIT) <= 0)
   continue;
  else if (fix_message_type_is(msg, FIX_MSG_TYPE_NEW_ORDER_SINGLE)) {
   fix_session_execution_report(session, fields, nr);
   continue;
  } else if (!fix_message_type_is(msg, FIX_MSG_TYPE_LOGOUT))
   continue;
  logout_msg = (struct fix_message) {
   .type = FIX_MSG_TYPE_LOGOUT,
  };
  fix_session_send(session, &logout_msg, 0);
  break;
 }
 ret = 0;
exit:
 fix_session_free(session);
 free(fields);
 return ret;
}

variable_types: struct fix_session_cfg { char sender_comp_id[32]; char target_comp_id[32]; char password[32]; int heartbtint; struct fix_dialect { enum fix_version { FIX_4_0=0, FIX_4_1=1, FIX_4_2=2, FIX_4_3=3, FIX_4_4=4, FIX_5_0=5, FIXT_1_1=6 } version; enum fix_type { FIX_TYPE_INT=0, FIX_TYPE_FLOAT=1, FIX_TYPE_CHAR=2, FIX_TYPE_STRING=3, FIX_TYPE_CHECKSUM=4, FIX_TYPE_MSGSEQNUM=5, FIX_TYPE_STRING_8=6 } (*tag_type)(int tag); } *dialect; int sockfd; unsigned long in_msg_seq_num; unsigned long out_msg_seq_num; void *user_data; } *

variable_types: struct fix_server_arg { char *script; } *

variable_types: ret int


strversion

decompiled_code:
__int64 __fastcall strversion(const char *a1)
{
unsigned int v1; // er8

v1 = 2;
if ( strcmp(a1, "fix42") )
v1 = 3 - ((strcmp(a1, "fix43") == 0) - 1);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1)
{
unsigned int v1; // er8

v1 = 2;
if ( strcmp(a1, "fix42") )
v1 = 3 - ((strcmp(a1, "fix43") == 0) - 1);
return v1;
}

original_code:
static enum fix_version strversion(const char *dialect)
{
 if (!strcmp(dialect, "fix42"))
  return FIX_4_2;
 else if (!strcmp(dialect, "fix43"))
  return FIX_4_3;
 else if (!strcmp(dialect, "fix44"))
  return FIX_4_4;
 return FIX_4_4;
}

canonical_original_code:
static enum fix_version strversion(char *dialect)
{
 if (!strcmp(dialect, "fix42"))
  return FIX_4_2;
 else if (!strcmp(dialect, "fix43"))
  return FIX_4_3;
 else if (!strcmp(dialect, "fix44"))
  return FIX_4_4;
 return FIX_4_4;
}

variable_types:
dialect
char *


strservermode

decompiled_code:
__int64 __fastcall strservermode(char *s)
{
unsigned int v1; // er9
unsigned int v3; // er9
unsigned int v4; // [rsp+0h] [rbp-Ch] BYREF

v1 = 1;
if ( !strcmp(s, "session") )
return v1;
v1 = 0;
if ( !strcmp(s, "script") )
return v1;
if ( sscanf(s, "%u", &v4) != 1 || (v3 = v4, v4 > 1) )
v3 = 0;
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *s)
{
unsigned int v1; // er9
unsigned int v3; // er9
unsigned int v4; // [rsp+0h] [rbp-Ch] BYREF

v1 = 1;
if ( !strcmp(s, "session") )
return v1;
v1 = 0;
if ( !strcmp(s, "script") )
return v1;
if ( sscanf(s, "%u", &v4) != 1 || (v3 = v4, v4 > 1) )
v3 = 0;
return v3;
}

original_code:
static enum fix_server_mode strservermode(const char *mode)
{
 enum fix_server_mode m;
 if (!strcmp(mode, "session"))
  return FIX_SERVER_SESSION;
 else if (!strcmp(mode, "script"))
  return FIX_SERVER_SCRIPT;
 if (sscanf(mode, "%u", &m) != 1)
  return FIX_SERVER_SCRIPT;
 switch (m) {
  case FIX_SERVER_SESSION:
  case FIX_SERVER_SCRIPT:
   return m;
  default:
   break;
 }
 return FIX_SERVER_SCRIPT;
}

canonical_original_code:
static enum fix_server_mode strservermode(char *mode)
{
 enum fix_server_mode m;
 if (!strcmp(mode, "session"))
  return FIX_SERVER_SESSION;
 else if (!strcmp(mode, "script"))
  return FIX_SERVER_SCRIPT;
 if (sscanf(mode, "%u", &m) != 1)
  return FIX_SERVER_SCRIPT;
 switch (m) {
  case FIX_SERVER_SESSION:
  case FIX_SERVER_SCRIPT:
   return m;
  default:
   break;
 }
 return FIX_SERVER_SCRIPT;
}

variable_types:
mode
char *

variable_types: enum fix_server_mode { FIX_SERVER_SCRIPT=0, FIX_SERVER_SESSION=1 }


decompiled_code:
__int64 __fastcall buffer_put(__int64 a1, char a2)
{
__int64 result; // rax
__int64 v3; // rdx

result = *(_QWORD *)(a1 + 8);
v3 = *(_QWORD *)(a1 + 24);
*(_QWORD *)(a1 + 8) = result + 1;
*(_BYTE *)(v3 + result) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, char a2)
{
__int64 result; // rax
__int64 v3; // rdx

result = *(_QWORD *)(a1 + 8);
v3 = *(_QWORD *)(a1 + 24);
*(_QWORD *)(a1 + 8) = result + 1;
*(_BYTE *)(v3 + result) = a2;
return result;
}

original_code:
static inline void buffer_put(struct buffer *self, char byte)
{
 self->data[self->end++] = byte;
}

variable_types: struct buffer { unsigned long start; unsigned long end; unsigned long capacity; char *data; } *

variable_types: byte char


decompiled_code:
__int64 __fastcall fix_field_unparse_zpad(unsigned int *a1, unsigned int a2, __int64 a3)
{
__int64 v4; // rax
__int64 v5; // r12
char *v7; // r8
char v8; // si
char *v9; // r8

v4 = buffer_end_isra_0(*(_QWORD *)(a3 + 8), *(_QWORD *)(a3 + 24));
*(_QWORD *)(a3 + 8) += (int)uitoa(*a1, v4);
buffer_put(a3, 61);
v5 = buffer_end_isra_0(*(_QWORD *)(a3 + 8), *(_QWORD *)(a3 + 24));
switch ( a1[1] )
{
case 0u:
*(_QWORD *)(a3 + 8) += modp_litoa10_zpad(*((_QWORD *)a1 + 1), a2, v5);
break;
case 1u:
*(_QWORD *)(a3 + 8) += modp_dtoa2(v5, 7LL, *((double *)a1 + 1));
break;
case 2u:
buffer_put(a3, *((_BYTE *)a1 + 8));
break;
case 3u:
v8 = **((_BYTE **)a1 + 1);
if ( v8 )
{
do
{
buffer_put(a3, v8);
v8 = *v9;
}
while ( *v9 );
}
break;
case 4u:
*(_QWORD *)(a3 + 8) += (int)checksumtoa(*((_QWORD *)a1 + 1), v5);
break;
case 6u:
v7 = (char *)(a1 + 2);
do
{
if ( !*v7 )
break;
buffer_put(a3, *v7);
}
while ( v7 != (char *)(a1 + 4) );
break;
default:
break;
}
buffer_put(a3, 1);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int *a1, unsigned int a2, __int64 a3)
{
__int64 v4; // rax
__int64 v5; // r12
char *v7; // r8
char v8; // si
char *v9; // r8

v4 = func1(*(_QWORD *)(a3 + 8), *(_QWORD *)(a3 + 24));
*(_QWORD *)(a3 + 8) += (int)uitoa(*a1, v4);
func0(a3, 61);
v5 = func1(*(_QWORD *)(a3 + 8), *(_QWORD *)(a3 + 24));
switch ( a1[1] )
{
case 0u:
*(_QWORD *)(a3 + 8) += modp_litoa10_zpad(*((_QWORD *)a1 + 1), a2, v5);
break;
case 1u:
*(_QWORD *)(a3 + 8) += modp_dtoa2(v5, 7LL, *((double *)a1 + 1));
break;
case 2u:
func0(a3, *((_BYTE *)a1 + 8));
break;
case 3u:
v8 = **((_BYTE **)a1 + 1);
if ( v8 )
{
do
{
func0(a3, v8);
v8 = *v9;
}
while ( *v9 );
}
break;
case 4u:
*(_QWORD *)(a3 + 8) += (int)checksumtoa(*((_QWORD *)a1 + 1), v5);
break;
case 6u:
v7 = (char *)(a1 + 2);
do
{
if ( !*v7 )
break;
func0(a3, *v7);
}
while ( v7 != (char *)(a1 + 4) );
break;
default:
break;
}
func0(a3, 1);
return v5;
}

original_code:
char *fix_field_unparse_zpad(struct fix_field *self, int zpad, struct buffer *buffer)
{
 char *marker = ((void *)0);
 buffer->end += uitoa(self->tag, buffer_end(buffer));
 buffer_put(buffer, '=');
 marker = buffer_end(buffer);
 switch (self->type) {
 case FIX_TYPE_STRING: {
  const char *p = self->string_value;
  while (*p) {
   buffer_put(buffer, *p++);
  }
  break;
 }
 case FIX_TYPE_STRING_8: {
  for (int i = 0; i < sizeof(self->string_8_value) && self->string_8_value[i]; ++i) {
   buffer_put(buffer, self->string_8_value[i]);
  }
  break;
 }
 case FIX_TYPE_CHAR: {
  buffer_put(buffer, self->char_value);
  break;
 }
 case FIX_TYPE_FLOAT: {
  buffer->end += modp_dtoa2(self->float_value, buffer_end(buffer), 7);
  break;
 }
 case FIX_TYPE_INT: {
  buffer->end += modp_litoa10_zpad(self->int_value, zpad, buffer_end(buffer));
  break;
 }
 case FIX_TYPE_CHECKSUM: {
  buffer->end += checksumtoa(self->int_value, buffer_end(buffer));
  break;
 }
 default:
  break;
 };
 buffer_put(buffer, 0x01);
 return marker;
}

canonical_original_code:
char *fix_field_unparse_zpad(struct fix_field *self, int zpad, struct buffer *buffer)
{
 char *marker = ((void *)0);
 buffer->end += uitoa(self->tag, buffer_end(buffer));
 buffer_put(buffer, '=');
 marker = buffer_end(buffer);
 switch (self->type) {
 case FIX_TYPE_STRING: {
  char *p = self->string_value;
  while (*p) {
   buffer_put(buffer, *p++);
  }
  break;
 }
 case FIX_TYPE_STRING_8: {
  for (int i = 0; i < sizeof(self->string_8_value) && self->string_8_value[i]; ++i) {
   buffer_put(buffer, self->string_8_value[i]);
  }
  break;
 }
 case FIX_TYPE_CHAR: {
  buffer_put(buffer, self->char_value);
  break;
 }
 case FIX_TYPE_FLOAT: {
  buffer->end += modp_dtoa2(self->float_value, buffer_end(buffer), 7);
  break;
 }
 case FIX_TYPE_INT: {
  buffer->end += modp_litoa10_zpad(self->int_value, zpad, buffer_end(buffer));
  break;
 }
 case FIX_TYPE_CHECKSUM: {
  buffer->end += checksumtoa(self->int_value, buffer_end(buffer));
  break;
 }
 default:
  break;
 };
 buffer_put(buffer, 0x01);
 return marker;
}

variable_types: zpad int

variable_types:
marker
char *

variable_types:
p
char *

variable_types: i int

return_type: char *


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

result = calloc(1uLL, 0x790uLL);
if ( result )
{
result[11] = 1024LL;
result[12] = result + 13;
result[238] = 0x40000000ALL;
result[239] = 0LL;
}
return result;
}

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

result = calloc(1uLL, 0x790uLL);
if ( result )
{
result[11] = 1024LL;
result[12] = result + 13;
result[238] = 0x40000000ALL;
result[239] = 0LL;
}
return result;
}

original_code:
struct fix_template *fix_template_new(void)
{
 struct fix_template *self = calloc(1, sizeof *self);
 if (!self)
  return ((void *)0);
 self->marker_transact_time = ((void *)0);
 self->buf.start = 0;
 self->buf.end = 0;
 self->buf.capacity = 1024UL;
 self->buf.data = &self->tx_data[0];
 self->csum_field = (struct fix_field) { .tag = CheckSum, .type = FIX_TYPE_CHECKSUM, { .int_value = 0 }, };
 return self;
}

canonical_original_code:
struct fix_template *fix_template_new()
{
 struct fix_template *self = calloc(1, sizeof *self);
 if (!self)
  return ((void *)0);
 self->marker_transact_time = ((void *)0);
 self->buf.start = 0;
 self->buf.end = 0;
 self->buf.capacity = 1024UL;
 self->buf.data = &self->tx_data[0];
 self->csum_field = (struct fix_field) { .tag = CheckSum, .type = FIX_TYPE_CHECKSUM, { .int_value = 0 }, };
 return self;
}

variable_types: struct fix_template { char *marker_body_length; char *marker_msg_seq_num; char *marker_sender_comp_id; char *marker_sending_time; char *marker_transact_time; char *marker_const_start; char *marker_const_end; unsigned long sender_comp_id_len; unsigned char const_csum; struct buffer { unsigned long start; unsigned long end; unsigned long capacity; char *data; } buf; char tx_data[1024]; unsigned long nr_fields; struct fix_field { int tag; enum fix_type { FIX_TYPE_INT=0, FIX_TYPE_FLOAT=1, FIX_TYPE_CHAR=2, FIX_TYPE_STRING=3, FIX_TYPE_CHECKSUM=4, FIX_TYPE_MSGSEQNUM=5, FIX_TYPE_STRING_8=6 } type; union { long int_value; double float_value; char char_value; char *string_value; char string_8_value[8]; }; } fields[48]; struct fix_field csum_field; struct iovec { void *iov_base; unsigned long iov_len; } iov[1]; } *

user_defined_types: struct fix_template { char *marker_body_length; char *marker_msg_seq_num; char *marker_sender_comp_id; char *marker_sending_time; char *marker_transact_time; char *marker_const_start; char *marker_const_end; unsigned long sender_comp_id_len; unsigned char const_csum; struct buffer buf; char tx_data[1024]; unsigned long nr_fields; struct fix_field fields[48]; struct fix_field csum_field; struct iovec iov[1]; }


decompiled_code:
void __fastcall fix_template_free(void *a1)
{
if ( a1 )
free(a1);
}

canonical_decompiled_code:
void __fastcall func4(void *a1)
{
if ( a1 )
free(a1);
}

original_code:
void fix_template_free(struct fix_template *self)
{
 if (!self)
  return;
 free(self);
}


original_code:
void fix_template_prepare(struct fix_template *self, struct fix_template_cfg *cfg)
{
 int i;
 fix_field_unparse(&(struct fix_field) { .tag = BeginString, .type = FIX_TYPE_STRING, { .string_value = cfg->begin_string }, }, &self->buf);
 self->marker_body_length = fix_field_unparse_zpad(&(struct fix_field) { .tag = BodyLength, .type = FIX_TYPE_INT, { .int_value = 0 }, }, 4UL, &self->buf);
 fix_field_unparse(&(struct fix_field) { .tag = MsgType, .type = FIX_TYPE_STRING, { .string_value = fix_msg_types[cfg->msg_type] }, }, &self->buf);
 self->marker_msg_seq_num = fix_field_unparse_zpad(&(struct fix_field) { .tag = MsgSeqNum, .type = FIX_TYPE_INT, { .int_value = 0 }, }, 6UL, &self->buf);
 self->marker_sender_comp_id = fix_field_unparse_zpad(&(struct fix_field) { .tag = SenderCompID, .type = FIX_TYPE_STRING, { .string_value = cfg->sender_comp_id }, }, 0, &self->buf);
 self->sender_comp_id_len = strlen(cfg->sender_comp_id);
 self->marker_sending_time = fix_field_unparse_zpad(&(struct fix_field) { .tag = SendingTime, .type = FIX_TYPE_STRING, { .string_value = "YYYYMMDD-HH:MM:SS.sss" }, }, 0, &self->buf);
 fix_field_unparse(&(struct fix_field) { .tag = TargetCompID, .type = FIX_TYPE_STRING, { .string_value = cfg->target_comp_id }, }, &self->buf);
 if (cfg->manage_transact_time)
  self->marker_transact_time = fix_field_unparse_zpad(&(struct fix_field) { .tag = TransactTime, .type = FIX_TYPE_STRING, { .string_value = "YYYYMMDD-HH:MM:SS.sss" }, }, 0, &self->buf);
 self->marker_const_start = buffer_end(&self->buf);
 for (i = 0; i < cfg->nr_const_fields; i++)
  fix_field_unparse(&cfg->const_fields[i], &self->buf);
 self->marker_const_end = buffer_end(&self->buf);
 self->const_csum = buffer_sum_range(self->marker_const_start, self->marker_const_end) +
       buffer_sum_range(self->buf.data, self->marker_body_length);
 ((void) sizeof ((self->marker_body_length != ((void *)0)) ? 1 : 0), __extension__ ({ if (self->marker_body_length != ((void *)0)) ; else __assert_fail ("self->marker_body_length != NULL", "lib/proto/fix_template.c", 116, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((self->marker_msg_seq_num != ((void *)0)) ? 1 : 0), __extension__ ({ if (self->marker_msg_seq_num != ((void *)0)) ; else __assert_fail ("self->marker_msg_seq_num != NULL", "lib/proto/fix_template.c", 117, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((self->marker_sender_comp_id != ((void *)0)) ? 1 : 0), __extension__ ({ if (self->marker_sender_comp_id != ((void *)0)) ; else __assert_fail ("self->marker_sender_comp_id != NULL", "lib/proto/fix_template.c", 118, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((self->marker_sending_time != ((void *)0)) ? 1 : 0), __extension__ ({ if (self->marker_sending_time != ((void *)0)) ; else __assert_fail ("self->marker_sending_time != NULL", "lib/proto/fix_template.c", 119, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((self->marker_const_start != ((void *)0)) ? 1 : 0), __extension__ ({ if (self->marker_const_start != ((void *)0)) ; else __assert_fail ("self->marker_const_start != NULL", "lib/proto/fix_template.c", 120, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((self->marker_const_end != ((void *)0)) ? 1 : 0), __extension__ ({ if (self->marker_const_end != ((void *)0)) ; else __assert_fail ("self->marker_const_end != NULL", "lib/proto/fix_template.c", 121, __extension__ __PRETTY_FUNCTION__); }));
}

variable_types: struct fix_template_cfg { char *begin_string; enum fix_msg_type { FIX_MSG_TYPE_HEARTBEAT=0, FIX_MSG_TYPE_TEST_REQUEST=1, FIX_MSG_TYPE_RESEND_REQUEST=2, FIX_MSG_TYPE_REJECT=3, FIX_MSG_TYPE_SEQUENCE_RESET=4, FIX_MSG_TYPE_LOGOUT=5, FIX_MSG_TYPE_EXECUTION_REPORT=6, FIX_MSG_TYPE_LOGON=7, FIX_MSG_TYPE_NEW_ORDER_SINGLE=8, FIX_MSG_TYPE_SNAPSHOT_REFRESH=9, FIX_MSG_TYPE_INCREMENT_REFRESH=10, FIX_MSG_TYPE_SESSION_STATUS=11, FIX_MSG_TYPE_SECURITY_STATUS=12, FIX_MSG_ORDER_CANCEL_REPLACE=13, FIX_MSG_ORDER_CANCEL_REJECT=14, FIX_MSG_ORDER_CANCEL_REQUEST=15, FIX_MSG_ORDER_MASS_CANCEL_REQUEST=16, FIX_MSG_ORDER_MASS_CANCEL_REPORT=17, FIX_MSG_QUOTE_REQUEST=18, FIX_MSG_SECURITY_DEFINITION_REQUEST=19, FIX_MSG_NEW_ORDER_CROSS=20, FIX_MSG_MASS_QUOTE=21, FIX_MSG_QUOTE_CANCEL=22, FIX_MSG_SECURITY_DEFINITION=23, FIX_MSG_QUOTE_ACKNOWLEDGEMENT=24, FIX_MSG_ORDER_MASS_STATUS_REQUEST=25, FIX_MSG_ORDER_MASS_ACTION_REQUEST=26, FIX_MSG_ORDER_MASS_ACTION_REPORT=27, FIX_MSG_TYPE_MAX=28, FIX_MSG_TYPE_UNKNOWN=expr } msg_type; char *sender_comp_id; char *target_comp_id; _Bool manage_transact_time; unsigned long nr_const_fields; struct fix_field const_fields[48]; } *

user_defined_types: struct fix_template_cfg { char *begin_string; enum fix_msg_type msg_type; char *sender_comp_id; char *target_comp_id; _Bool manage_transact_time; unsigned long nr_const_fields; struct fix_field const_fields[48]; }


original_code:
void fix_template_unparse(struct fix_template *self, struct fix_session *session)
{
 int i;
 self->buf.start = 0;
 self->buf.end = (self->marker_const_end - self->buf.data);
 for (i = 0; i < self->nr_fields; i++)
  fix_field_unparse(&self->fields[i], &self->buf);
 memcpy(self->marker_sender_comp_id, session->sender_comp_id, self->sender_comp_id_len);
 modp_litoa10_zpad(session->out_msg_seq_num, 6UL, self->marker_msg_seq_num);
 modp_litoa10_zpad(self->buf.end - (self->marker_body_length - self->buf.data + 4UL + 1),
     4UL, self->marker_body_length);
 self->csum_field.int_value = (buffer_sum_range(self->marker_body_length, self->marker_const_start) +
          self->const_csum +
          buffer_sum_range(self->marker_const_end, buffer_end(&self->buf))) % 256;
 fix_field_unparse(&self->csum_field, &self->buf);
 self->iov[0].iov_base = &self->tx_data[0];
 self->iov[0].iov_len = self->buf.end;
}

variable_types: struct fix_session { struct fix_dialect { enum fix_version { FIX_4_0=0, FIX_4_1=1, FIX_4_2=2, FIX_4_3=3, FIX_4_4=4, FIX_5_0=5, FIXT_1_1=6 } version; enum fix_type { FIX_TYPE_INT=0, FIX_TYPE_FLOAT=1, FIX_TYPE_CHAR=2, FIX_TYPE_STRING=3, FIX_TYPE_CHECKSUM=4, FIX_TYPE_MSGSEQNUM=5, FIX_TYPE_STRING_8=6 } (*tag_type)(int tag); } *dialect; int sockfd; _Bool active; char *password; char *begin_string; char *sender_comp_id; char *target_comp_id; unsigned long in_msg_seq_num; unsigned long out_msg_seq_num; struct buffer *rx_buffer; struct buffer *tx_head_buffer; struct buffer *tx_body_buffer; struct fix_message { enum fix_msg_type { FIX_MSG_TYPE_HEARTBEAT=0, FIX_MSG_TYPE_TEST_REQUEST=1, FIX_MSG_TYPE_RESEND_REQUEST=2, FIX_MSG_TYPE_REJECT=3, FIX_MSG_TYPE_SEQUENCE_RESET=4, FIX_MSG_TYPE_LOGOUT=5, FIX_MSG_TYPE_EXECUTION_REPORT=6, FIX_MSG_TYPE_LOGON=7, FIX_MSG_TYPE_NEW_ORDER_SINGLE=8, FIX_MSG_TYPE_SNAPSHOT_REFRESH=9, FIX_MSG_TYPE_INCREMENT_REFRESH=10, FIX_MSG_TYPE_SESSION_STATUS=11, FIX_MSG_TYPE_SECURITY_STATUS=12, FIX_MSG_ORDER_CANCEL_REPLACE=13, FIX_MSG_ORDER_CANCEL_REJECT=14, FIX_MSG_ORDER_CANCEL_REQUEST=15, FIX_MSG_ORDER_MASS_CANCEL_REQUEST=16, FIX_MSG_ORDER_MASS_CANCEL_REPORT=17, FIX_MSG_QUOTE_REQUEST=18, FIX_MSG_SECURITY_DEFINITION_REQUEST=19, FIX_MSG_NEW_ORDER_CROSS=20, FIX_MSG_MASS_QUOTE=21, FIX_MSG_QUOTE_CANCEL=22, FIX_MSG_SECURITY_DEFINITION=23, FIX_MSG_QUOTE_ACKNOWLEDGEMENT=24, FIX_MSG_ORDER_MASS_STATUS_REQUEST=25, FIX_MSG_ORDER_MASS_ACTION_REQUEST=26, FIX_MSG_ORDER_MASS_ACTION_REPORT=27, FIX_MSG_TYPE_MAX=28, FIX_MSG_TYPE_UNKNOWN=expr } type; char *begin_string; unsigned long body_length; char *msg_type; char *sender_comp_id; char *target_comp_id; unsigned long msg_seq_num; char *check_sum; char *str_now; struct buffer *head_buf; struct buffer *body_buf; unsigned long nr_fields; struct fix_field *fields; struct iovec iov[2]; } *rx_message; int heartbtint; struct timespec { long tv_sec; long tv_nsec; } now; char str_now[64]; struct timespec rx_timestamp; struct timespec tx_timestamp; char testreqid[64]; struct timespec tr_timestamp; int tr_pending; enum fix_failure_reason { FIX_SUCCESS=0, FIX_FAILURE_CONN_CLOSED=1, FIX_FAILURE_RECV_ZERO_B=2, FIX_FAILURE_SYSTEM=3, FIX_FAILURE_GARBLED=4 } failure_reason; void *user_data; } *


decompiled_code:
__int64 __fastcall fix_template_send(__int64 a1, unsigned int a2, unsigned int a3)
{
__int64 result; // rax

result = io_sendmsg(a2, a1 + 1920, 1LL, a3);
if ( (int)result >= 0 )
result = (unsigned int)iov_byte_length(a1 + 1920, 1LL) - (unsigned int)result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, unsigned int a2, unsigned int a3)
{
__int64 result; // rax

result = io_sendmsg(a2, a1 + 1920, 1LL, a3);
if ( (int)result >= 0 )
result = (unsigned int)iov_byte_length(a1 + 1920, 1LL) - (unsigned int)result;
return result;
}

original_code:
int fix_template_send(struct fix_template *self, int sockfd, int flags)
{
 int ret = 0;
 ;
 if ((ret = io_sendmsg(sockfd, self->iov, (sizeof(self->iov) / sizeof((self->iov)[0])), flags)) < 0) {
  return ret;
 }
 ;
 return iov_byte_length(self->iov, (sizeof(self->iov) / sizeof((self->iov)[0]))) - ret;
}

variable_types: sockfd int

variable_types: flags int


decompiled_code:
__int64 __fastcall order_insert(_QWORD *a1, __int64 a2)
{
__int64 result; // rax

if ( *a1 )
{
result = a1[1];
*(_QWORD *)(result + 16) = a2;
*(_QWORD *)(a2 + 24) = result;
}
else
{
*a1 = a2;
*(_QWORD *)(a2 + 24) = 0LL;
}
a1[1] = a2;
*(_QWORD *)(a2 + 16) = 0LL;
return result;
}

original_code:
static void order_insert(struct level *level, struct order *order)
{
 if (level->head != ((void *)0)) {
  level->tail->next = order;
  order->prev = level->tail;
 } else {
  level->head = order;
  order->prev = ((void *)0);
 }
 level->tail = order;
 order->next = ((void *)0);
 return;
}

variable_types: struct level { struct order { unsigned long trader; unsigned long level; struct order *next; struct order *prev; unsigned long side; unsigned long size; } *head; struct order *tail; } *

variable_types:
order
struct order *


match

original_code:
static int match(struct order_book *book, struct order *order)
{
 struct level *level;
 struct order *head;
 if (order->side == 0) {
  level = book->levels + order->level;
  while (order->level >= book->best_ask) {
   level = book->levels + book->best_ask;
   head = level->head;
   while (head != ((void *)0)) {
    if (head->size < order->size) {
     do_trade(order->trader, head->trader, book->best_ask, head->size);
     order->size -= head->size;
     head->size = 0;
    } else {
     do_trade(order->trader, head->trader, book->best_ask, order->size);
     head->size -= order->size;
     order->size = 0;
    }
    if (!head->size) {
     order_remove(level, head);
     head = level->head;
    }
    if (!order->size)
     goto done;
   }
   book->best_ask++;
  }
  if (order->level > book->best_bid)
   book->best_bid = order->level;
 } else {
  level = book->levels + order->level;
  while (order->level <= book->best_bid) {
   level = book->levels + book->best_bid;
   head = level->head;
   while (head != ((void *)0)) {
    if (head->size < order->size) {
     do_trade(head->trader, order->trader, book->best_bid, head->size);
     order->size -= head->size;
     head->size = 0;
    } else {
     do_trade(head->trader, order->trader, book->best_bid, order->size);
     head->size -= order->size;
     order->size = 0;
    }
    if (!head->size) {
     order_remove(level, head);
     head = level->head;
    }
    if (!order->size)
     goto done;
   }
   book->best_bid--;
  }
  if (order->level < book->best_ask)
   book->best_ask = order->level;
 }
 order_insert(level, order);
done:
 return 0;
}

variable_types: struct order_book { struct level { struct order { unsigned long trader; unsigned long level; struct order *next; struct order *prev; unsigned long side; unsigned long size; } *head; struct order *tail; } levels[-1]; struct order orders[10000]; unsigned long orders_num; unsigned long best_ask; unsigned long best_bid; unsigned long book_id; char code[32]; } *


original_code:
int do_limit(struct order_book *book, struct order *limit)
{
 struct order *order;
 if (book->orders_num >= 10000)
  goto reject;
 if (limit->level > 100 || limit->level < 1)
  goto reject;
 if (!limit->size)
  goto reject;
 order = book->orders + book->orders_num;
 memcpy(order, limit, sizeof(struct order));
 book->orders_num++;
 return match(book, order);
reject:
 return -1;
}

variable_types:
limit
struct order *

variable_types: struct order { unsigned long trader; unsigned long level; struct order *next; struct order *prev; unsigned long side; unsigned long size; } *


original_code:
int do_cancel(struct order_book *book, unsigned long id)
{
 struct order *order = book->orders + id;
 struct level *level;
 if (!book->orders_num || id >= book->orders_num)
  goto reject;
 if (!order->size)
  goto reject;
 level = book->levels + order->level;
 order_remove(level, order);
 order->size = 0;
 return 0;
reject:
 return -1;
}

variable_types:
id
unsigned long


decompiled_code:
__int64 __fastcall g_uint_compare(unsigned int a1, unsigned int a2)
{
__int64 result; // rax

result = a1 > a2;
if ( a1 < a2 )
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, unsigned int a2)
{
__int64 result; // rax

result = a1 > a2;
if ( a1 < a2 )
result = 0xFFFFFFFFLL;
return result;
}

original_code:
static inline gint g_uint_compare(gconstpointer pa, gconstpointer pb)
{
 unsigned int a = ((guint) (gulong) (pa));
 unsigned int b = ((guint) (gulong) (pb));
 gint ret = 0;
 if (a < b)
  ret = -1;
 else if (a > b)
  ret = 1;
 return ret;
}

canonical_original_code:
static inline int g_uint_compare(void *pa, void *pb)
{
 unsigned int a = ((guint) (gulong) (pa));
 unsigned int b = ((guint) (gulong) (pb));
 int ret = 0;
 if (a < b)
  ret = -1;
 else if (a > b)
  ret = 1;
 return ret;
}

variable_types:
pa
void *

variable_types:
pb
void *

variable_types:
a
unsigned int

variable_types:
b
unsigned int

variable_types: ret int


decompiled_code:
__int64 __fastcall g_level_compare(__int64 a1, __int64 a2)
{
unsigned __int64 v2; // rax
bool v3; // cf
__int64 result; // rax

v2 = *(_QWORD *)(a2 + 8);
v3 = *(_QWORD *)(a1 + 8) < v2;
result = *(_QWORD *)(a1 + 8) > v2;
if ( v3 )
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
unsigned __int64 v2; // rax
bool v3; // cf
__int64 result; // rax

v2 = *(_QWORD *)(a2 + 8);
v3 = *(_QWORD *)(a1 + 8) < v2;
result = *(_QWORD *)(a1 + 8) > v2;
if ( v3 )
result = 0xFFFFFFFFLL;
return result;
}

original_code:
static inline gint g_level_compare(gconstpointer pa, gconstpointer pb)
{
 const struct ob_level *la = pa;
 const struct ob_level *lb = pb;
 gint ret = 0;
 if (la->price < lb->price)
  ret = -1;
 else if (la->price > lb->price)
  ret = 1;
 return ret;
}

canonical_original_code:
static inline int g_level_compare(void *pa, void *pb)
{
 struct ob_level *la = pa;
 struct ob_level *lb = pb;
 int ret = 0;
 if (la->price < lb->price)
  ret = -1;
 else if (la->price > lb->price)
  ret = 1;
 return ret;
}

variable_types: struct ob_level { unsigned long seq_num; unsigned long price; unsigned long size; } *


decompiled_code:
// attributes: thunk
__int64 buffer_nread0()
{
return buffer_nread();
}

canonical_decompiled_code:
__int64 func1()
{
return buffer_nread();
}

original_code:
static ssize_t buffer_nread0(struct buffer *buf, int fd, size_t size, int flags)
{
 return buffer_nread(buf, fd, size);
}

canonical_original_code:
static long buffer_nread0(struct buffer *buf, int fd, unsigned long size, int flags)
{
 return buffer_nread(buf, fd, size);
}

variable_types: struct buffer { unsigned long start; unsigned long end; unsigned long capacity; char *data; } *

variable_types: fd int

variable_types:
size
unsigned long

return_type: long


decompiled_code:
__int64 __fastcall xwritev0(__int64 a1, __int64 a2)
{
return xwritev(a1, *(_QWORD *)(a2 + 16), *(_QWORD *)(a2 + 24));
}

original_code:
static ssize_t xwritev0(int fd, const struct msghdr *msg, int flags)
{
 return xwritev(fd, msg->msg_iov, msg->msg_iovlen);
}

canonical_original_code:
static long xwritev0(int fd, struct msghdr *msg, int flags)
{
 return xwritev(fd, msg->msg_iov, msg->msg_iovlen);
}

variable_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec { void *iov_base; unsigned long iov_len; } *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; } *

user_defined_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; }


decompiled_code:
__int64 __fastcall translate_recv_flags(unsigned __int64 a1)
{
return (a1 >> 10) & 0x40;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int64 a1)
{
return (a1 >> 10) & 0x40;
}

original_code:
static int translate_recv_flags(unsigned long flags)
{
 return flags & FIX_RECV_FLAG_MSG_DONTWAIT ? MSG_DONTWAIT : 0;
}

variable_types:
flags
unsigned long


decompiled_code:
__int64 __fastcall fix_session_cfg_init(_QWORD *a1)
{
int v1; // ecx
unsigned __int64 v2; // rdi
__int64 result; // rax

*a1 = 0LL;
v1 = (int)a1;
v2 = (unsigned __int64)(a1 + 1);
result = 0LL;
*(_QWORD *)(v2 + 128) = 0LL;
memset((void *)(v2 & 0xFFFFFFFFFFFFFFF8LL), 0, 8 * ((v1 - (v2 & 0xFFFFFFF8) + 144) >> 3));
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1)
{
int v1; // ecx
unsigned __int64 v2; // rdi
__int64 result; // rax

*a1 = 0LL;
v1 = (int)a1;
v2 = (unsigned __int64)(a1 + 1);
result = 0LL;
*(_QWORD *)(v2 + 128) = 0LL;
memset((void *)(v2 & 0xFFFFFFFFFFFFFFF8LL), 0, 8 * ((v1 - (v2 & 0xFFFFFFF8) + 144) >> 3));
return result;
}

original_code:
void fix_session_cfg_init(struct fix_session_cfg *cfg)
{
 memset(cfg, 0, sizeof(*cfg));
}

variable_types: struct fix_session_cfg { char sender_comp_id[32]; char target_comp_id[32]; char password[32]; int heartbtint; struct fix_dialect { enum fix_version { FIX_4_0=0, FIX_4_1=1, FIX_4_2=2, FIX_4_3=3, FIX_4_4=4, FIX_5_0=5, FIXT_1_1=6 } version; enum fix_type { FIX_TYPE_INT=0, FIX_TYPE_FLOAT=1, FIX_TYPE_CHAR=2, FIX_TYPE_STRING=3, FIX_TYPE_CHECKSUM=4, FIX_TYPE_MSGSEQNUM=5, FIX_TYPE_STRING_8=6 } (*tag_type)(int tag); } *dialect; int sockfd; unsigned long in_msg_seq_num; unsigned long out_msg_seq_num; void *user_data; } *


decompiled_code:
char *__fastcall fix_session_cfg_new(char *src, char *a2, int a3, const char *a4, int a5)
{
char *v8; // r12
char *v9; // rax
char *result; // rax

v8 = (char *)calloc(1uLL, 0x90uLL);
strncpy(v8, src, 0x20uLL);
strncpy(v8 + 32, a2, 0x20uLL);
*((_DWORD *)v8 + 24) = a3;
if ( !strcmp(a4, "fixt-1.1") )
{
v9 = (char *)&fix_dialects + 96;
}
else if ( !strcmp(a4, "fix-4.0") )
{
v9 = (char *)&fix_dialects;
}
else if ( !strcmp(a4, "fix-4.1") )
{
v9 = (char *)&fix_dialects + 16;
}
else if ( !strcmp(a4, "fix-4.2") )
{
v9 = (char *)&fix_dialects + 32;
}
else if ( !strcmp(a4, "fix-4.3") )
{
v9 = (char *)&fix_dialects + 48;
}
else
{
v9 = (char *)&fix_dialects + 64;
}
*((_QWORD *)v8 + 13) = v9;
result = v8;
*((_DWORD *)v8 + 28) = a5;
return result;
}

canonical_decompiled_code:
char *__fastcall func5(char *src, char *a2, int a3, const char *a4, int a5)
{
char *v8; // r12
char *v9; // rax
char *result; // rax

v8 = (char *)calloc(1uLL, 0x90uLL);
strncpy(v8, src, 0x20uLL);
strncpy(v8 + 32, a2, 0x20uLL);
*((_DWORD *)v8 + 24) = a3;
if ( !strcmp(a4, "fixt-1.1") )
{
v9 = (char *)&fix_dialects + 96;
}
else if ( !strcmp(a4, "fix-4.0") )
{
v9 = (char *)&fix_dialects;
}
else if ( !strcmp(a4, "fix-4.1") )
{
v9 = (char *)&fix_dialects + 16;
}
else if ( !strcmp(a4, "fix-4.2") )
{
v9 = (char *)&fix_dialects + 32;
}
else if ( !strcmp(a4, "fix-4.3") )
{
v9 = (char *)&fix_dialects + 48;
}
else
{
v9 = (char *)&fix_dialects + 64;
}
*((_QWORD *)v8 + 13) = v9;
result = v8;
*((_DWORD *)v8 + 28) = a5;
return result;
}

original_code:
struct fix_session_cfg *fix_session_cfg_new(
 const char *sender_comp_id,
 const char *target_comp_id,
 int heartbtint,
 const char *dialect,
 int sockfd
) {
 struct fix_session_cfg *cfg;
 enum fix_version version;
 cfg = calloc(1, sizeof(struct fix_session_cfg));
 strncpy(cfg->sender_comp_id, sender_comp_id, sizeof(cfg->sender_comp_id));
 strncpy(cfg->target_comp_id, target_comp_id, sizeof(cfg->target_comp_id));
 cfg->heartbtint = heartbtint;
 version =
  !strcmp(dialect, "fixt-1.1") ? FIXT_1_1 :
  !strcmp(dialect, "fix-4.0") ? FIX_4_0 :
  !strcmp(dialect, "fix-4.1") ? FIX_4_1 :
  !strcmp(dialect, "fix-4.2") ? FIX_4_2 :
  !strcmp(dialect, "fix-4.3") ? FIX_4_3 : FIX_4_4;
 cfg->dialect = &fix_dialects[version];
 cfg->sockfd = sockfd;
 return cfg;
}

canonical_original_code:
struct fix_session_cfg *fix_session_cfg_new(char *sender_comp_id, char *target_comp_id, int heartbtint, char *dialect, int sockfd) {
 struct fix_session_cfg *cfg;
 enum fix_version version;
 cfg = calloc(1, sizeof(struct fix_session_cfg));
 strncpy(cfg->sender_comp_id, sender_comp_id, sizeof(cfg->sender_comp_id));
 strncpy(cfg->target_comp_id, target_comp_id, sizeof(cfg->target_comp_id));
 cfg->heartbtint = heartbtint;
 version =
  !strcmp(dialect, "fixt-1.1") ? FIXT_1_1 :
  !strcmp(dialect, "fix-4.0") ? FIX_4_0 :
  !strcmp(dialect, "fix-4.1") ? FIX_4_1 :
  !strcmp(dialect, "fix-4.2") ? FIX_4_2 :
  !strcmp(dialect, "fix-4.3") ? FIX_4_3 : FIX_4_4;
 cfg->dialect = &fix_dialects[version];
 cfg->sockfd = sockfd;
 return cfg;
}

variable_types: heartbtint int

variable_types:
dialect
char *

variable_types: sockfd int

return_type: struct fix_session_cfg { char sender_comp_id[32]; char target_comp_id[32]; char password[32]; int heartbtint; struct fix_dialect { enum fix_version { FIX_4_0=0, FIX_4_1=1, FIX_4_2=2, FIX_4_3=3, FIX_4_4=4, FIX_5_0=5, FIXT_1_1=6 } version; enum fix_type { FIX_TYPE_INT=0, FIX_TYPE_FLOAT=1, FIX_TYPE_CHAR=2, FIX_TYPE_STRING=3, FIX_TYPE_CHECKSUM=4, FIX_TYPE_MSGSEQNUM=5, FIX_TYPE_STRING_8=6 } (*tag_type)(int tag); } *dialect; int sockfd; unsigned long in_msg_seq_num; unsigned long out_msg_seq_num; void *user_data; } *


decompiled_code:
void __fastcall fix_session_free(void *ptr)
{
if ( ptr )
{
buffer_delete(*((_QWORD *)ptr + 8));
buffer_delete(*((_QWORD *)ptr + 9));
buffer_delete(*((_QWORD *)ptr + 10));
fix_message_free(*((_QWORD *)ptr + 11));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
if ( ptr )
{
buffer_delete(*((_QWORD *)ptr + 8));
buffer_delete(*((_QWORD *)ptr + 9));
buffer_delete(*((_QWORD *)ptr + 10));
fix_message_free(*((_QWORD *)ptr + 11));
free(ptr);
}
}

original_code:
void fix_session_free(struct fix_session *self)
{
 if (!self)
  return;
 buffer_delete(self->rx_buffer);
 buffer_delete(self->tx_head_buffer);
 buffer_delete(self->tx_body_buffer);
 fix_message_free(self->rx_message);
 free(self);
}

variable_types: struct fix_session { struct fix_dialect { enum fix_version { FIX_4_0=0, FIX_4_1=1, FIX_4_2=2, FIX_4_3=3, FIX_4_4=4, FIX_5_0=5, FIXT_1_1=6 } version; enum fix_type { FIX_TYPE_INT=0, FIX_TYPE_FLOAT=1, FIX_TYPE_CHAR=2, FIX_TYPE_STRING=3, FIX_TYPE_CHECKSUM=4, FIX_TYPE_MSGSEQNUM=5, FIX_TYPE_STRING_8=6 } (*tag_type)(int tag); } *dialect; int sockfd; _Bool active; char *password; char *begin_string; char *sender_comp_id; char *target_comp_id; unsigned long in_msg_seq_num; unsigned long out_msg_seq_num; struct buffer { unsigned long start; unsigned long end; unsigned long capacity; char *data; } *rx_buffer; struct buffer *tx_head_buffer; struct buffer *tx_body_buffer; struct fix_message { enum fix_msg_type { FIX_MSG_TYPE_HEARTBEAT=0, FIX_MSG_TYPE_TEST_REQUEST=1, FIX_MSG_TYPE_RESEND_REQUEST=2, FIX_MSG_TYPE_REJECT=3, FIX_MSG_TYPE_SEQUENCE_RESET=4, FIX_MSG_TYPE_LOGOUT=5, FIX_MSG_TYPE_EXECUTION_REPORT=6, FIX_MSG_TYPE_LOGON=7, FIX_MSG_TYPE_NEW_ORDER_SINGLE=8, FIX_MSG_TYPE_SNAPSHOT_REFRESH=9, FIX_MSG_TYPE_INCREMENT_REFRESH=10, FIX_MSG_TYPE_SESSION_STATUS=11, FIX_MSG_TYPE_SECURITY_STATUS=12, FIX_MSG_ORDER_CANCEL_REPLACE=13, FIX_MSG_ORDER_CANCEL_REJECT=14, FIX_MSG_ORDER_CANCEL_REQUEST=15, FIX_MSG_ORDER_MASS_CANCEL_REQUEST=16, FIX_MSG_ORDER_MASS_CANCEL_REPORT=17, FIX_MSG_QUOTE_REQUEST=18, FIX_MSG_SECURITY_DEFINITION_REQUEST=19, FIX_MSG_NEW_ORDER_CROSS=20, FIX_MSG_MASS_QUOTE=21, FIX_MSG_QUOTE_CANCEL=22, FIX_MSG_SECURITY_DEFINITION=23, FIX_MSG_QUOTE_ACKNOWLEDGEMENT=24, FIX_MSG_ORDER_MASS_STATUS_REQUEST=25, FIX_MSG_ORDER_MASS_ACTION_REQUEST=26, FIX_MSG_ORDER_MASS_ACTION_REPORT=27, FIX_MSG_TYPE_MAX=28, FIX_MSG_TYPE_UNKNOWN=expr } type; char *begin_string; unsigned long body_length; char *msg_type; char *sender_comp_id; char *target_comp_id; unsigned long msg_seq_num; char *check_sum; char *str_now; struct buffer *head_buf; struct buffer *body_buf; unsigned long nr_fields; struct fix_field { int tag; enum fix_type { FIX_TYPE_INT=0, FIX_TYPE_FLOAT=1, FIX_TYPE_CHAR=2, FIX_TYPE_STRING=3, FIX_TYPE_CHECKSUM=4, FIX_TYPE_MSGSEQNUM=5, FIX_TYPE_STRING_8=6 } type; union { long int_value; double float_value; char char_value; char *string_value; char string_8_value[8]; }; } *fields; struct iovec { void *iov_base; unsigned long iov_len; } iov[2]; } *rx_message; int heartbtint; struct timespec { long tv_sec; long tv_nsec; } now; char str_now[64]; struct timespec rx_timestamp; struct timespec tx_timestamp; char testreqid[64]; struct timespec tr_timestamp; int tr_pending; enum fix_failure_reason { FIX_SUCCESS=0, FIX_FAILURE_CONN_CLOSED=1, FIX_FAILURE_RECV_ZERO_B=2, FIX_FAILURE_SYSTEM=3, FIX_FAILURE_GARBLED=4 } failure_reason; void *user_data; } *


decompiled_code:
__int64 __fastcall fix_session_time_update_monotonic(__int64 a1, const __m128i *a2)
{
__int64 result; // rax

result = 0LL;
*(__m128i *)(a1 + 104) = _mm_loadu_si128(a2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, const __m128i *a2)
{
__int64 result; // rax

result = 0LL;
*(__m128i *)(a1 + 104) = _mm_loadu_si128(a2);
return result;
}

original_code:
int fix_session_time_update_monotonic(struct fix_session *self, struct timespec *monotonic)
{
 self->now = *monotonic;
 return 0;
}

variable_types:
monotonic
struct timespec *


decompiled_code:
__int64 __fastcall fix_session_time_update_realtime(__int64 a1, time_t *a2)
{
time_t v2; // rcx
struct tm *v3; // rax
time_t v5; // [rsp+0h] [rbp-68h] BYREF
time_t v6; // [rsp+8h] [rbp-60h]
char s[88]; // [rsp+10h] [rbp-58h] BYREF

v2 = a2[1];
v5 = *a2;
v6 = v2 / 1000;
v3 = gmtime(&v5);
if ( !v3 )
return 0xFFFFFFFFLL;
strftime(s, 0x40uLL, "%Y%m%d-%H:%M:%S", v3);
snprintf((char *)(a1 + 120), 0x40uLL, "%s.%03ld", s, v6 / 1000);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, time_t *a2)
{
time_t v2; // rcx
struct tm *v3; // rax
time_t v5; // [rsp+0h] [rbp-68h] BYREF
time_t v6; // [rsp+8h] [rbp-60h]
char s[88]; // [rsp+10h] [rbp-58h] BYREF

v2 = a2[1];
v5 = *a2;
v6 = v2 / 1000;
v3 = gmtime(&v5);
if ( !v3 )
return 0xFFFFFFFFLL;
strftime(s, 0x40uLL, "%Y%m%d-%H:%M:%S", v3);
snprintf((char *)(a1 + 120), 0x40uLL, "%s.%03ld", s, v6 / 1000);
return 0LL;
}

original_code:
int fix_session_time_update_realtime(struct fix_session *self, struct timespec *realtime)
{
 struct timeval tv;
 struct tm *tm;
 char fmt[64];
 { (&tv)->tv_sec = (realtime)->tv_sec; (&tv)->tv_usec = (realtime)->tv_nsec / 1000; };
 tm = gmtime(&tv.tv_sec);
 if (!tm)
  goto fail;
 strftime(fmt, sizeof(fmt), "%Y%m%d-%H:%M:%S", tm);
 snprintf(self->str_now, sizeof(self->str_now), "%s.%03ld", fmt, (long)tv.tv_usec / 1000);
 return 0;
fail:
 return -1;
}

variable_types:
realtime
struct timespec *

variable_types: struct timeval { long tv_sec; long tv_usec; }

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *

variable_types:
fmt
char [64]


decompiled_code:
__int64 __fastcall fix_session_time_update(__int64 a1)
{
__int64 result; // rax
__m128i v2[2]; // [rsp+0h] [rbp-28h] BYREF

if ( clock_gettime(1, (struct timespec *)v2)
|| (unsigned int)fix_session_time_update_monotonic(a1, v2)
|| clock_gettime(0, (struct timespec *)v2) )
{
result = 0xFFFFFFFFLL;
}
else
{
result = fix_session_time_update_realtime(a1, (time_t *)v2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
__int64 result; // rax
__m128i v2[2]; // [rsp+0h] [rbp-28h] BYREF

if ( clock_gettime(1, (struct timespec *)v2)
|| (unsigned int)func7(a1, v2)
|| clock_gettime(0, (struct timespec *)v2) )
{
result = 0xFFFFFFFFLL;
}
else
{
result = func8(a1, (time_t *)v2);
}
return result;
}

original_code:
int fix_session_time_update(struct fix_session *self)
{
 struct timespec ts;
 if (clock_gettime(1, &ts))
  goto fail;
 if (fix_session_time_update_monotonic(self, &ts))
  goto fail;
 if (clock_gettime(0, &ts))
  goto fail;
 return fix_session_time_update_realtime(self, &ts);
fail:
 return -1;
}

variable_types: struct timespec { long tv_sec; long tv_nsec; }


original_code:
int fix_session_send(struct fix_session *self, struct fix_message *msg, unsigned long flags)
{
 msg->begin_string = self->begin_string;
 msg->sender_comp_id = self->sender_comp_id;
 msg->target_comp_id = self->target_comp_id;
 if (!(flags && FIX_SEND_FLAG_PRESERVE_MSG_NUM))
  msg->msg_seq_num = self->out_msg_seq_num++;
 msg->head_buf = self->tx_head_buffer;
 buffer_reset(msg->head_buf);
 msg->body_buf = self->tx_body_buffer;
 buffer_reset(msg->body_buf);
 self->tx_timestamp = self->now;
 msg->str_now = self->str_now;
 return fix_message_send(msg, self->sockfd, flags);
}

variable_types:
msg
struct fix_message *


decompiled_code:
__int64 __fastcall fix_session_recv(_QWORD *a1, _QWORD *a2, unsigned __int64 a3)
{
__int64 v4; // r12
__int64 v5; // r14
unsigned int v6; // eax
__int64 v7; // rdx
__int64 v8; // rax
int v9; // er8
__int64 result; // rax

v4 = a1[8];
*((_DWORD *)a1 + 75) = 0;
v5 = a1[11];
if ( !(unsigned int)fix_message_parse(v5, *a1, v4, a3) )
{
*(__m128i *)(a1 + 23) = _mm_loadu_si128((const __m128i *)(a1 + 13));
if ( (a3 & 0x20000) != 0 )
{
LABEL_10:
result = 1LL;
*a2 = v5;
return result;
}
LABEL_9:
++a1[6];
goto LABEL_10;
}
if ( fix_session_buffer_full_isra_0(a1[8]) )
buffer_compact(v4);
if ( (unsigned __int64)buffer_remaining_isra_0(*(_QWORD *)(v4 + 8), *(_QWORD *)(v4 + 16)) > 0x500 )
{
v6 = translate_recv_flags(a3);
v8 = buffer_recv(v4, *((unsigned int *)a1 + 2), v7, v6);
if ( v8 <= 0 )
{
*((_DWORD *)a1 + 75) = v8 == 0 ? 1 : 3;
return 0xFFFFFFFFLL;
}
}
v9 = fix_message_parse(v5, *a1, v4, a3);
result = 0LL;
if ( !v9 )
{
*(__m128i *)(a1 + 23) = _mm_loadu_si128((const __m128i *)(a1 + 13));
if ( (a3 & 0x20000) != 0 )
goto LABEL_10;
goto LABEL_9;
}
return result;
}

original_code:
int fix_session_recv(struct fix_session *self, struct fix_message **res, unsigned long flags)
{
 struct fix_message *msg = self->rx_message;
 struct buffer *buffer = self->rx_buffer;
 self->failure_reason = FIX_SUCCESS;
 size_t size;
 ;
 if (!fix_message_parse(msg, self->dialect, buffer, flags)) {
  self->rx_timestamp = self->now;
  if (!(flags & FIX_RECV_KEEP_IN_MSGSEQNUM)) self->in_msg_seq_num++;
  goto parsed;
 }
 if (fix_session_buffer_full(self))
  buffer_compact(buffer);
 size = buffer_remaining(buffer);
 if (size > (256UL + 1024UL)) {
  ssize_t nr;
  size -= (256UL + 1024UL);
  nr = buffer_recv(buffer, self->sockfd, size, translate_recv_flags(flags));
  if (nr <= 0) {
   self->failure_reason = nr == 0 ? FIX_FAILURE_CONN_CLOSED : FIX_FAILURE_SYSTEM;
   return -1;
  }
 }
 if (!fix_message_parse(msg, self->dialect, buffer, flags)) {
  self->rx_timestamp = self->now;
  if (!(flags & FIX_RECV_KEEP_IN_MSGSEQNUM)) self->in_msg_seq_num++;
  goto parsed;
 }
 ;
 return 0;
parsed:
 ;
 *res = msg;
 return 1;
}

canonical_original_code:
int fix_session_recv(struct fix_session *self, struct fix_message **res, unsigned long flags)
{
 struct fix_message *msg = self->rx_message;
 struct buffer *buffer = self->rx_buffer;
 self->failure_reason = FIX_SUCCESS;
 unsigned long size;
 ;
 if (!fix_message_parse(msg, self->dialect, buffer, flags)) {
  self->rx_timestamp = self->now;
  if (!(flags & FIX_RECV_KEEP_IN_MSGSEQNUM)) self->in_msg_seq_num++;
  goto parsed;
 }
 if (fix_session_buffer_full(self))
  buffer_compact(buffer);
 size = buffer_remaining(buffer);
 if (size > (256UL + 1024UL)) {
  long nr;
  size -= (256UL + 1024UL);
  nr = buffer_recv(buffer, self->sockfd, size, translate_recv_flags(flags));
  if (nr <= 0) {
   self->failure_reason = nr == 0 ? FIX_FAILURE_CONN_CLOSED : FIX_FAILURE_SYSTEM;
   return -1;
  }
 }
 if (!fix_message_parse(msg, self->dialect, buffer, flags)) {
  self->rx_timestamp = self->now;
  if (!(flags & FIX_RECV_KEEP_IN_MSGSEQNUM)) self->in_msg_seq_num++;
  goto parsed;
 }
 ;
 return 0;
parsed:
 ;
 *res = msg;
 return 1;
}

variable_types:
res
struct fix_message **

variable_types: struct fix_message { enum fix_msg_type { FIX_MSG_TYPE_HEARTBEAT=0, FIX_MSG_TYPE_TEST_REQUEST=1, FIX_MSG_TYPE_RESEND_REQUEST=2, FIX_MSG_TYPE_REJECT=3, FIX_MSG_TYPE_SEQUENCE_RESET=4, FIX_MSG_TYPE_LOGOUT=5, FIX_MSG_TYPE_EXECUTION_REPORT=6, FIX_MSG_TYPE_LOGON=7, FIX_MSG_TYPE_NEW_ORDER_SINGLE=8, FIX_MSG_TYPE_SNAPSHOT_REFRESH=9, FIX_MSG_TYPE_INCREMENT_REFRESH=10, FIX_MSG_TYPE_SESSION_STATUS=11, FIX_MSG_TYPE_SECURITY_STATUS=12, FIX_MSG_ORDER_CANCEL_REPLACE=13, FIX_MSG_ORDER_CANCEL_REJECT=14, FIX_MSG_ORDER_CANCEL_REQUEST=15, FIX_MSG_ORDER_MASS_CANCEL_REQUEST=16, FIX_MSG_ORDER_MASS_CANCEL_REPORT=17, FIX_MSG_QUOTE_REQUEST=18, FIX_MSG_SECURITY_DEFINITION_REQUEST=19, FIX_MSG_NEW_ORDER_CROSS=20, FIX_MSG_MASS_QUOTE=21, FIX_MSG_QUOTE_CANCEL=22, FIX_MSG_SECURITY_DEFINITION=23, FIX_MSG_QUOTE_ACKNOWLEDGEMENT=24, FIX_MSG_ORDER_MASS_STATUS_REQUEST=25, FIX_MSG_ORDER_MASS_ACTION_REQUEST=26, FIX_MSG_ORDER_MASS_ACTION_REPORT=27, FIX_MSG_TYPE_MAX=28, FIX_MSG_TYPE_UNKNOWN=expr } type; char *begin_string; unsigned long body_length; char *msg_type; char *sender_comp_id; char *target_comp_id; unsigned long msg_seq_num; char *check_sum; char *str_now; struct buffer { unsigned long start; unsigned long end; unsigned long capacity; char *data; } *head_buf; struct buffer *body_buf; unsigned long nr_fields; struct fix_field { int tag; enum fix_type { FIX_TYPE_INT=0, FIX_TYPE_FLOAT=1, FIX_TYPE_CHAR=2, FIX_TYPE_STRING=3, FIX_TYPE_CHECKSUM=4, FIX_TYPE_MSGSEQNUM=5, FIX_TYPE_STRING_8=6 } type; union { long int_value; double float_value; char char_value; char *string_value; char string_8_value[8]; }; } *fields; struct iovec { void *iov_base; unsigned long iov_len; } iov[2]; } *

variable_types: nr long


decompiled_code:
int __fastcall print_stat(const char *a1, unsigned __int8 a2)
{
__int64 v2; // rsi
__int64 v3; // rax
double v4; // xmm0_8
__int64 v6; // rcx

v2 = a2 - 65;
v3 = stats[v2];
if ( v3 < 0 )
{
v6 = stats[v2] & 1LL | (stats[v2] >> 1);
v4 = (double)(int)v6 + (double)(int)v6;
}
else
{
v4 = (double)(int)v3;
}
return fprintf(stdout, "%'14.0f %s\n", v4, a1);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1, unsigned __int8 a2)
{
__int64 v2; // rsi
__int64 v3; // rax
double v4; // xmm0_8
__int64 v6; // rcx

v2 = a2 - 65;
v3 = stats[v2];
if ( v3 < 0 )
{
v6 = stats[v2] & 1LL | (stats[v2] >> 1);
v4 = (double)(int)v6 + (double)(int)v6;
}
else
{
v4 = (double)(int)v3;
}
return fprintf(stdout, "%'14.0f %s\n", v4, a1);
}

original_code:
static void print_stat(const char *name, u8 msg_type)
{
 fprintf(stdout, "%'14.0f  %s\n", (double) stats[msg_type - 'A'], name);
}

canonical_original_code:
static void print_stat(char *name, unsigned char msg_type)
{
 fprintf(stdout, "%'14.0f  %s\n", (double) stats[msg_type - 'A'], name);
}

variable_types:
name
char *


decompiled_code:
char *__fastcall parse_args(int argc, char **argv)
{
int v2; // eax
__int64 *v3; // rdx
char *result; // rax

while ( 1 )
{
v2 = getopt_long(argc, argv, "v", &options, 0LL);
if ( v2 == -1 )
break;
if ( v2 != 118 )
goto LABEL_7;
verbose = 1;
show_progress = 0;
}
v3 = (__int64 *)&argv[optind];
if ( argc - optind != 1 )
LABEL_7:
usage((unsigned int)argc, argv, v3);
result = (char *)*v3;
filename = (char *)*v3;
return result;
}

canonical_decompiled_code:
char *__fastcall func2(int argc, char **argv)
{
int v2; // eax
__int64 *v3; // rdx
char *result; // rax

while ( 1 )
{
v2 = getopt_long(argc, argv, "v", &options, 0LL);
if ( v2 == -1 )
break;
if ( v2 != 118 )
goto LABEL_7;
verbose = 1;
show_progress = 0;
}
v3 = (__int64 *)&argv[optind];
if ( argc - optind != 1 )
LABEL_7:
func1((unsigned int)argc, argv, v3);
result = (char *)*v3;
filename = (char *)*v3;
return result;
}

original_code:
static void parse_args(int argc, char *argv[])
{
 int opt;
 while ((opt = getopt_long(argc, argv, "v", options, ((void *)0))) != -1) {
  switch (opt) {
  case 'v':
   verbose = 1;
   show_progress = 0;
   break;
  default:
   usage();
   break;
  }
 }
 argc -= optind;
 argv += optind;
 if (argc != 1)
  usage();
 filename = argv[0];
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: opt int


die

decompiled_code:
void __noreturn die(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
vfprintf(stderr, format, arg);
exit(1);
}

canonical_decompiled_code:
void __noreturn func3(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
vfprintf(stderr, format, arg);
exit(1);
}

original_code:
static void die(const char *fmt, ...)
{
 va_list ap;
 __builtin_va_start(ap,fmt);
 vfprintf(stderr, fmt, ap);
 __builtin_va_end(ap);
 exit(1);
}

canonical_original_code:
static void die(char *fmt, ...)
{
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 vfprintf(stderr, fmt, ap);
 __builtin_va_end(ap);
 exit(1);
}

variable_types:
fmt
char *


decompiled_code:
int print_stats()
{
printf(" Message type stats for '%s':\n\n", filename);
print_stat("Timestamp - Seconds", 0x54u);
print_stat("System Event", 0x53u);
print_stat("Stock Directory", 0x52u);
print_stat("Stock Trading Action", 0x48u);
print_stat("REG SHO Restriction", 0x59u);
print_stat("Market Participant Position", 0x4Cu);
print_stat("Add Order", 0x41u);
print_stat("Add Order - MPID Attribution", 0x46u);
print_stat("Order Executed", 0x45u);
print_stat("Order Executed With Price", 0x43u);
print_stat("Order Cancel", 0x58u);
print_stat("Order Delete", 0x44u);
print_stat("Order Replace", 0x55u);
print_stat("Trade (non-cross)", 0x50u);
print_stat("Cross Trade", 0x51u);
print_stat("Broken Trade", 0x42u);
print_stat("NOII", 0x49u);
print_stat("RPII", 0x4Eu);
return putchar(10);
}

canonical_decompiled_code:
int func6()
{
printf(" Message type stats for '%s':\n\n", filename);
func0("Timestamp - Seconds", 0x54u);
func0("System Event", 0x53u);
func0("Stock Directory", 0x52u);
func0("Stock Trading Action", 0x48u);
func0("REG SHO Restriction", 0x59u);
func0("Market Participant Position", 0x4Cu);
func0("Add Order", 0x41u);
func0("Add Order - MPID Attribution", 0x46u);
func0("Order Executed", 0x45u);
func0("Order Executed With Price", 0x43u);
func0("Order Cancel", 0x58u);
func0("Order Delete", 0x44u);
func0("Order Replace", 0x55u);
func0("Trade (non-cross)", 0x50u);
func0("Cross Trade", 0x51u);
func0("Broken Trade", 0x42u);
func0("NOII", 0x49u);
func0("RPII", 0x4Eu);
return putchar(10);
}

original_code:
static void print_stats(void)
{
 printf(" Message type stats for '%s':\n\n", filename);
 print_stat("Timestamp - Seconds", ITCH41_MSG_TIMESTAMP_SECONDS);
 print_stat("System Event", ITCH41_MSG_SYSTEM_EVENT);
 print_stat("Stock Directory", ITCH41_MSG_STOCK_DIRECTORY);
 print_stat("Stock Trading Action", ITCH41_MSG_STOCK_TRADING_ACTION);
 print_stat("REG SHO Restriction", ITCH41_MSG_REG_SHO_RESTRICTION);
 print_stat("Market Participant Position", ITCH41_MSG_MARKET_PARTICIPANT_POS);
 print_stat("Add Order", ITCH41_MSG_ADD_ORDER);
 print_stat("Add Order - MPID Attribution", ITCH41_MSG_ADD_ORDER_MPID);
 print_stat("Order Executed", ITCH41_MSG_ORDER_EXECUTED);
 print_stat("Order Executed With Price", ITCH41_MSG_ORDER_EXECUTED_WITH_PRICE);
 print_stat("Order Cancel", ITCH41_MSG_ORDER_CANCEL);
 print_stat("Order Delete", ITCH41_MSG_ORDER_DELETE);
 print_stat("Order Replace", ITCH41_MSG_ORDER_REPLACE);
 print_stat("Trade (non-cross)", ITCH41_MSG_TRADE);
 print_stat("Cross Trade", ITCH41_MSG_CROSS_TRADE);
 print_stat("Broken Trade", ITCH41_MSG_BROKEN_TRADE);
 print_stat("NOII", ITCH41_MSG_NOII);
 print_stat("RPII", ITCH41_MSG_RPII);
 printf("\n");
}

canonical_original_code:
static void print_stats()
{
 printf(" Message type stats for '%s':\n\n", filename);
 print_stat("Timestamp - Seconds", ITCH41_MSG_TIMESTAMP_SECONDS);
 print_stat("System Event", ITCH41_MSG_SYSTEM_EVENT);
 print_stat("Stock Directory", ITCH41_MSG_STOCK_DIRECTORY);
 print_stat("Stock Trading Action", ITCH41_MSG_STOCK_TRADING_ACTION);
 print_stat("REG SHO Restriction", ITCH41_MSG_REG_SHO_RESTRICTION);
 print_stat("Market Participant Position", ITCH41_MSG_MARKET_PARTICIPANT_POS);
 print_stat("Add Order", ITCH41_MSG_ADD_ORDER);
 print_stat("Add Order - MPID Attribution", ITCH41_MSG_ADD_ORDER_MPID);
 print_stat("Order Executed", ITCH41_MSG_ORDER_EXECUTED);
 print_stat("Order Executed With Price", ITCH41_MSG_ORDER_EXECUTED_WITH_PRICE);
 print_stat("Order Cancel", ITCH41_MSG_ORDER_CANCEL);
 print_stat("Order Delete", ITCH41_MSG_ORDER_DELETE);
 print_stat("Order Replace", ITCH41_MSG_ORDER_REPLACE);
 print_stat("Trade (non-cross)", ITCH41_MSG_TRADE);
 print_stat("Cross Trade", ITCH41_MSG_CROSS_TRADE);
 print_stat("Broken Trade", ITCH41_MSG_BROKEN_TRADE);
 print_stat("NOII", ITCH41_MSG_NOII);
 print_stat("RPII", ITCH41_MSG_RPII);
 printf("\n");
}


decompiled_code:
__int64 __fastcall mbt_quote_message_payload(__int64 a1)
{
return a1 + 1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return a1 + 1;
}

original_code:
static inline void *mbt_quote_message_payload(struct mbt_quote_message *msg)
{
 return (void *) msg + sizeof(struct mbt_quote_message);
}

variable_types: struct mbt_quote_message { char Type; } *

return_type: void *


original_code:
static inline u8 buffer_get_8(struct buffer *self)
{
 return self->data[self->start++];
}

canonical_original_code:
static inline unsigned char buffer_get_8(struct buffer *self)
{
 return self->data[self->start++];
}

variable_types: struct buffer { unsigned long start; unsigned long end; unsigned long capacity; char *data; } *

return_type: unsigned char


decompiled_code:
// attributes: thunk
__int64 __fastcall buffer_get_char(__int64 *a1)
{
return buffer_get_8(a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 *a1)
{
return func1(a1);
}

original_code:
static inline char buffer_get_char(struct buffer *self)
{
 return buffer_get_8(self);
}

return_type: char


decompiled_code:
char *__fastcall mbt_quote_decode_field(__int64 *a1)
{
_QWORD *v1; // rcx
__int64 *v2; // rcx
__int64 v3; // rdi
__int64 v4; // rsi
char v5; // al
__int64 v6; // rcx
__int64 v8; // r8
__int64 v9; // r9
const char *v10; // rax
__int64 v11; // rdx

if ( !buffer_find_constprop_0(a1) )
return 0LL;
while ( 1 )
{
buffer_advance_constprop_0(v1);
v3 = *v2;
v4 = v2[3];
v5 = buffer_peek_8_isra_0(*v2, v4);
if ( v5 == 59 || v5 == 10 )
break;
if ( !buffer_remaining_isra_0(*(_QWORD *)(v6 + 8), *(_QWORD *)(v6 + 16)) )
return 0LL;
}
if ( !buffer_start_isra_0(v3, v4) )
return 0LL;
v10 = (const char *)buffer_start_isra_0(v8, v9);
return strndup(v10, v11 - (_QWORD)v10);
}

canonical_decompiled_code:
char *__fastcall func9(__int64 *a1)
{
_QWORD *v1; // rcx
__int64 *v2; // rcx
__int64 v3; // rdi
__int64 v4; // rsi
char v5; // al
__int64 v6; // rcx
__int64 v8; // r8
__int64 v9; // r9
const char *v10; // rax
__int64 v11; // rdx

if ( !func8(a1) )
return 0LL;
while ( 1 )
{
func3(v1);
v3 = *v2;
v4 = v2[3];
v5 = func7(*v2, v4);
if ( v5 == 59 || v5 == 10 )
break;
if ( !func4(*(_QWORD *)(v6 + 8), *(_QWORD *)(v6 + 16)) )
return 0LL;
}
if ( !func6(v3, v4) )
return 0LL;
v10 = (const char *)func6(v8, v9);
return strndup(v10, v11 - (_QWORD)v10);
}

original_code:
static char *mbt_quote_decode_field(struct buffer *buf)
{
 char *start, *end;
 if (!buffer_find(buf, '='))
  return ((void *)0);
 buffer_advance(buf, 1);
 start = buffer_start(buf);
 for (;;) {
  char ch;
  ch = buffer_peek_8(buf);
  if (ch == ';' || ch == '\n')
   break;
  if (!buffer_remaining(buf))
   return ((void *)0);
  buffer_advance(buf, 1);
 }
 end = buffer_start(buf);
 if (!end)
  return ((void *)0);
 return strndup(start, end-start);
}

canonical_original_code:
static char *mbt_quote_decode_field(struct buffer *buf)
{
 char *start; char *end;
 if (!buffer_find(buf, '='))
  return ((void *)0);
 buffer_advance(buf, 1);
 start = buffer_start(buf);
 for (;;) {
  char ch;
  ch = buffer_peek_8(buf);
  if (ch == ';' || ch == '\n')
   break;
  if (!buffer_remaining(buf))
   return ((void *)0);
  buffer_advance(buf, 1);
 }
 end = buffer_start(buf);
 if (!end)
  return ((void *)0);
 return strndup(start, end-start);
}

variable_types:
start
char *

variable_types:
end
char *

variable_types: ch char


decompiled_code:
void __fastcall mbt_quote_message_delete(void *ptr)
{
__int64 v1; // rbx

if ( *(_BYTE *)ptr == 76 )
{
v1 = mbt_quote_message_payload((__int64)ptr);
free(*(void **)(v1 + 8));
free(*(void **)(v1 + 16));
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func10(void *ptr)
{
__int64 v1; // rbx

if ( *(_BYTE *)ptr == 76 )
{
v1 = func0((__int64)ptr);
free(*(void **)(v1 + 8));
free(*(void **)(v1 + 16));
}
free(ptr);
}

original_code:
void mbt_quote_message_delete(struct mbt_quote_message *msg)
{
 switch (msg->Type) {
 case MBT_QUOTE_LOGGING_ON: {
  struct mbt_quote_logging_on *logon = mbt_quote_message_payload(msg);
  free(logon->UserName);
  free(logon->Password);
  break;
 }
 default:
  break;
 }
 free(msg);
}

variable_types: struct mbt_quote_logging_on { char Type; char *UserName; char *Password; } *


decompiled_code:
ssize_t __fastcall sys_sendmsg(int a1, struct iovec *a2, size_t a3, int a4)
{
struct msghdr v5; // [rsp+0h] [rbp-48h] BYREF

v5.msg_iov = a2;
*(_QWORD *)&v5.msg_flags = 0LL;
v5.msg_iovlen = a3;
*(_OWORD *)&v5.msg_name = 0LL;
*(_OWORD *)&v5.msg_control = 0LL;
return sendmsg(a1, &v5, a4);
}

canonical_decompiled_code:
ssize_t __fastcall func0(int a1, struct iovec *a2, size_t a3, int a4)
{
struct msghdr v5; // [rsp+0h] [rbp-48h] BYREF

v5.msg_iov = a2;
*(_QWORD *)&v5.msg_flags = 0LL;
v5.msg_iovlen = a3;
*(_OWORD *)&v5.msg_name = 0LL;
*(_OWORD *)&v5.msg_control = 0LL;
return sendmsg(a1, &v5, a4);
}

original_code:
ssize_t sys_sendmsg(int fd, struct iovec *iov, size_t length, int flags)
{
 struct msghdr msg = (struct msghdr) {
  .msg_iov = iov,
  .msg_iovlen = length,
 };
 return sendmsg(fd, &msg, flags);
}

canonical_original_code:
long sys_sendmsg(int fd, struct iovec *iov, unsigned long length, int flags)
{
 struct msghdr msg = (struct msghdr) {
  .msg_iov = iov,
  .msg_iovlen = length,
 };
 return sendmsg(fd, &msg, flags);
}

variable_types: fd int

variable_types:
length
unsigned long

variable_types: flags int

variable_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec { void *iov_base; unsigned long iov_len; } *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; }


decompiled_code:
__int64 __fastcall iov_byte_length(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rdx

if ( !a2 )
return 0LL;
result = 0LL;
v3 = a1 + 16 * a2;
do
{
result += *(_QWORD *)(a1 + 8);
a1 += 16LL;
}
while ( a1 != v3 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rdx

if ( !a2 )
return 0LL;
result = 0LL;
v3 = a1 + 16 * a2;
do
{
result += *(_QWORD *)(a1 + 8);
a1 += 16LL;
}
while ( a1 != v3 );
return result;
}

original_code:
size_t iov_byte_length(struct iovec *iov, size_t iov_len)
{
 size_t len = 0;
 size_t i;
 for (i = 0; i < iov_len; ++i)
  len += iov[i].iov_len;
 return len;
}

canonical_original_code:
unsigned long iov_byte_length(struct iovec *iov, unsigned long iov_len)
{
 unsigned long len = 0;
 unsigned long i;
 for (i = 0; i < iov_len; ++i)
  len += iov[i].iov_len;
 return len;
}

variable_types: struct iovec { void *iov_base; unsigned long iov_len; } *

variable_types:
len
unsigned long

variable_types:
i
unsigned long