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


repo: libtrading/libtrading

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 *

return_type: void

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


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]; } *

return_type: int

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]; }


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

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


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

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

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

result = 0xFFFFFFFFLL;
if ( a1 >= a2 )
result = a1 > a2;
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; // rcx
unsigned __int64 v3; // rdx
__int64 result; // rax

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

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

v2 = *(_QWORD *)(a1 + 8);
v3 = *(_QWORD *)(a2 + 8);
result = 0xFFFFFFFFLL;
if ( v2 >= v3 )
result = v2 > v3;
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:
__int64 buffer_nread0()
{
return buffer_nread();
}

canonical_decompiled_code:
__int64 func2()
{
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 func3(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)
{
__int64 result; // rax

*a1 = 0LL;
a1[17] = 0LL;
result = 0LL;
memset(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 144) >> 3));
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1)
{
__int64 result; // rax

*a1 = 0LL;
a1[17] = 0LL;
result = 0LL;
memset(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 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; } *

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; }

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


decompiled_code:
char *__fastcall fix_session_cfg_new(char *src, char *a2, int a3, const char *a4, int a5)
{
char *v8; // rbx
unsigned int v9; // eax

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

canonical_decompiled_code:
char *__fastcall func5(char *src, char *a2, int a3, const char *a4, int a5)
{
char *v8; // rbx
unsigned int v9; // eax

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

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; } *

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 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 fix_session_time_update_monotonic(__int64 a1, const __m128i *a2)
{
*(__m128i *)(a1 + 104) = _mm_loadu_si128(a2);
return 0LL;
}

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 *

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 fix_session_time_update_realtime(__int64 a1, time_t *a2)
{
struct tm *v2; // rax
char v4[64]; // [rsp+0h] [rbp-68h] BYREF
time_t timer; // [rsp+40h] [rbp-28h] BYREF
time_t v6; // [rsp+48h] [rbp-20h]

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

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, time_t *a2)
{
struct tm *v2; // rax
char v4[64]; // [rsp+0h] [rbp-68h] BYREF
time_t timer; // [rsp+40h] [rbp-28h] BYREF
time_t v6; // [rsp+48h] [rbp-20h]

timer = *a2;
v6 = a2[1] / 1000;
v2 = gmtime(&timer);
if ( !v2 )
return 0xFFFFFFFFLL;
strftime(v4, 0x40uLL, "%Y%m%d-%H:%M:%S", v2);
snprintf((char *)(a1 + 120), 0x40uLL, "%s.%03ld", v4, 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)
{
__m128i v2; // [rsp+0h] [rbp-18h] BYREF

if ( clock_gettime(1, (struct timespec *)&v2) )
return 0xFFFFFFFFLL;
if ( (unsigned int)fix_session_time_update_monotonic(a1, &v2) )
return 0xFFFFFFFFLL;
if ( clock_gettime(0, (struct timespec *)&v2) )
return 0xFFFFFFFFLL;
return fix_session_time_update_realtime(a1, v2.m128i_i64);
}

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

if ( clock_gettime(1, (struct timespec *)&v2) )
return 0xFFFFFFFFLL;
if ( (unsigned int)func7(a1, &v2) )
return 0xFFFFFFFFLL;
if ( clock_gettime(0, (struct timespec *)&v2) )
return 0xFFFFFFFFLL;
return func8(a1, v2.m128i_i64);
}

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; // r15
__int64 v5; // r12
unsigned __int64 v6; // r13
unsigned int v7; // eax
__int64 v8; // rax
int v9; // edx
__int64 result; // rax

v4 = a1[11];
v5 = a1[8];
*((_DWORD *)a1 + 75) = 0;
if ( !(unsigned int)fix_message_parse(v4, *a1, v5, a3) )
{
*(__m128i *)(a1 + 23) = _mm_loadu_si128((const __m128i *)(a1 + 13));
if ( (a3 & 0x20000) == 0 )
++a1[6];
goto LABEL_11;
}
if ( fix_session_buffer_full((__int64)a1) )
buffer_compact(v5);
v6 = buffer_remaining(v5);
if ( v6 > 0x500 )
{
v7 = translate_recv_flags(a3);
v8 = buffer_recv(v5, *((unsigned int *)a1 + 2), v6 - 1280, v7);
if ( v8 <= 0 )
{
*((_DWORD *)a1 + 75) = v8 == 0 ? 1 : 3;
return 0xFFFFFFFFLL;
}
}
v9 = fix_message_parse(v4, *a1, v5, a3);
result = 0LL;
if ( !v9 )
{
*(__m128i *)(a1 + 23) = _mm_loadu_si128((const __m128i *)(a1 + 13));
if ( (a3 & 0x20000) == 0 )
++a1[6];
LABEL_11:
*a2 = v4;
result = 1LL;
}
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 | ((unsigned __int64)v3 >> 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 func3(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 | ((unsigned __int64)v3 >> 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
__int64 *v4; // rdx
char *result; // rax

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

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

while ( 1 )
{
v2 = getopt_long(argc, argv, "v", &options, 0LL);
if ( v2 == -1 )
break;
if ( v2 != 118 )
func4((unsigned int)argc, argv, v3);
verbose = 1;
show_progress = 0;
}
v4 = (__int64 *)&argv[optind];
if ( argc - optind != 1 )
func4((unsigned int)argc, argv, v4);
result = (char *)*v4;
filename = (char *)*v4;
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(const char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

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

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

va_start(arg, a1);
vfprintf(stderr, a1, 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 func10()
{
printf(" Message type stats for '%s':\n\n", filename);
func3("Timestamp - Seconds", 0x54u);
func3("System Event", 0x53u);
func3("Stock Directory", 0x52u);
func3("Stock Trading Action", 0x48u);
func3("REG SHO Restriction", 0x59u);
func3("Market Participant Position", 0x4Cu);
func3("Add Order", 0x41u);
func3("Add Order - MPID Attribution", 0x46u);
func3("Order Executed", 0x45u);
func3("Order Executed With Price", 0x43u);
func3("Order Cancel", 0x58u);
func3("Order Delete", 0x44u);
func3("Order Replace", 0x55u);
func3("Trade (non-cross)", 0x50u);
func3("Cross Trade", 0x51u);
func3("Broken Trade", 0x42u);
func3("NOII", 0x49u);
func3("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 *


decompiled_code:
__int64 __fastcall buffer_get_8(_QWORD *a1)
{
__int64 v1; // rdx
__int64 v2; // rax

v1 = a1[3];
v2 = (*a1)++;
return *(unsigned __int8 *)(v1 + v2);
}

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(_QWORD *a1)
{
return buffer_get_8(a1);
}

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

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

return_type: char


decompiled_code:
__int64 __fastcall mbt_quote_decode_field(_QWORD *a1)
{
__int64 result; // rax
const char *v2; // rbp
char v3; // al

result = buffer_find(a1, 61);
if ( result )
{
buffer_advance(a1, 1LL);
v2 = (const char *)buffer_start(a1);
while ( 1 )
{
v3 = buffer_peek_8(a1);
if ( v3 == 59 || v3 == 10 )
break;
if ( !buffer_remaining((__int64)a1) )
return 0LL;
buffer_advance(a1, 1LL);
}
result = buffer_start(a1);
if ( result )
result = (__int64)strndup(v2, result - (_QWORD)v2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1)
{
__int64 result; // rax
const char *v2; // rbp
char v3; // al

result = func8(a1, 61);
if ( result )
{
func5(a1, 1LL);
v2 = (const char *)func4(a1);
while ( 1 )
{
v3 = func1(a1);
if ( v3 == 59 || v3 == 10 )
break;
if ( !func7((__int64)a1) )
return 0LL;
func5(a1, 1LL);
}
result = func4(a1);
if ( result )
result = (__int64)strndup(v2, result - (_QWORD)v2);
}
return result;
}

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

return_type: char *


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

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; // rbp

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_name = 0LL;
*(_QWORD *)&v5.msg_namelen = 0LL;
v5.msg_control = 0LL;
v5.msg_controllen = 0LL;
*(_QWORD *)&v5.msg_flags = 0LL;
v5.msg_iov = a2;
v5.msg_iovlen = a3;
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_name = 0LL;
*(_QWORD *)&v5.msg_namelen = 0LL;
v5.msg_control = 0LL;
v5.msg_controllen = 0LL;
*(_QWORD *)&v5.msg_flags = 0LL;
v5.msg_iov = a2;
v5.msg_iovlen = a3;
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; }


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

return_type: unsigned long


xread

decompiled_code:
ssize_t __fastcall xread(int fd, void *buf, size_t nbytes)
{
ssize_t v4; // rbx
int v5; // eax

do
{
v4 = read(fd, buf, nbytes);
if ( v4 >= 0 )
break;
v5 = *_errno_location();
}
while ( v5 == 11 || v5 == 4 );
return v4;
}

canonical_decompiled_code:
ssize_t __fastcall func2(int fd, void *buf, size_t nbytes)
{
ssize_t v4; // rbx
int v5; // eax

do
{
v4 = read(fd, buf, nbytes);
if ( v4 >= 0 )
break;
v5 = *_errno_location();
}
while ( v5 == 11 || v5 == 4 );
return v4;
}

original_code:
ssize_t xread(int fd, void *buf, size_t count)
{
 ssize_t nr;
restart:
 nr = read(fd, buf, count);
 if ((nr < 0) && (((*__errno_location ()) == 11) || ((*__errno_location ()) == 4)))
  goto restart;
 return nr;
}

canonical_original_code:
long xread(int fd, void *buf, unsigned long count)
{
 long nr;
restart:
 nr = read(fd, buf, count);
 if ((nr < 0) && (((*__errno_location ()) == 11) || ((*__errno_location ()) == 4)))
  goto restart;
 return nr;
}

variable_types:
buf
void *

variable_types:
count
unsigned long

variable_types: nr long


xwrite

decompiled_code:
ssize_t __fastcall xwrite(int fd, void *buf, size_t n)
{
ssize_t v4; // rbx
int v5; // eax

do
{
v4 = write(fd, buf, n);
if ( v4 >= 0 )
break;
v5 = *_errno_location();
}
while ( v5 == 11 || v5 == 4 );
return v4;
}

canonical_decompiled_code:
ssize_t __fastcall func3(int fd, void *buf, size_t n)
{
ssize_t v4; // rbx
int v5; // eax

do
{
v4 = write(fd, buf, n);
if ( v4 >= 0 )
break;
v5 = *_errno_location();
}
while ( v5 == 11 || v5 == 4 );
return v4;
}

original_code:
ssize_t xwrite(int fd, const void *buf, size_t count)
{
 ssize_t nr;
restart:
 nr = write(fd, buf, count);
 if ((nr < 0) && (((*__errno_location ()) == 11) || ((*__errno_location ()) == 4)))
  goto restart;
 return nr;
}

canonical_original_code:
long xwrite(int fd, void *buf, unsigned long count)
{
 long nr;
restart:
 nr = write(fd, buf, count);
 if ((nr < 0) && (((*__errno_location ()) == 11) || ((*__errno_location ()) == 4)))
  goto restart;
 return nr;
}


xwritev

decompiled_code:
ssize_t __fastcall xwritev(int fd, struct iovec *iovec, int count)
{
ssize_t v4; // rbx
int v5; // eax

do
{
v4 = writev(fd, iovec, count);
if ( v4 >= 0 )
break;
v5 = *_errno_location();
}
while ( v5 == 11 || v5 == 4 );
return v4;
}

canonical_decompiled_code:
ssize_t __fastcall func4(int fd, struct iovec *iovec, int count)
{
ssize_t v4; // rbx
int v5; // eax

do
{
v4 = writev(fd, iovec, count);
if ( v4 >= 0 )
break;
v5 = *_errno_location();
}
while ( v5 == 11 || v5 == 4 );
return v4;
}

original_code:
ssize_t xwritev(int fd, const struct iovec *iov, int iovcnt)
{
 ssize_t nr;
restart:
 nr = writev(fd, iov, iovcnt);
 if ((nr < 0) && (((*__errno_location ()) == 11) || ((*__errno_location ()) == 4)))
  goto restart;
 return nr;
}

canonical_original_code:
long xwritev(int fd, struct iovec *iov, int iovcnt)
{
 long nr;
restart:
 nr = writev(fd, iov, iovcnt);
 if ((nr < 0) && (((*__errno_location ()) == 11) || ((*__errno_location ()) == 4)))
  goto restart;
 return nr;
}

variable_types: iovcnt int


itoa

decompiled_code:
signed __int64 __fastcall itoa(signed int a1, char *a2)
{
char *v2; // rbx

v2 = a2;
if ( a1 < 0 )
{
v2 = a2 + 1;
*a2 = 45;
a1 = -a1;
}
return &v2[(int)uitoa(a1, v2)] - a2;
}

canonical_decompiled_code:
signed __int64 __fastcall func4(signed int a1, char *a2)
{
char *v2; // rbx

v2 = a2;
if ( a1 < 0 )
{
v2 = a2 + 1;
*a2 = 45;
a1 = -a1;
}
return &v2[(int)func3(a1, v2)] - a2;
}

original_code:
int itoa(int n, char *s)
{
 unsigned int un = n;
 char *p = s;
 if (n < 0) {
  *p++ = '-';
  un = -n;
 }
 return uitoa(un, p) + p - s;
}

variable_types: n int

variable_types:
s
char *

variable_types:
un
unsigned int

variable_types:
p
char *


decompiled_code:
int __fastcall i64toa(__int64 a1, char *a2)
{
int result; // eax

if ( (unsigned __int64)(a1 + 0x80000000LL) <= 0xFFFFFFFF )
result = itoa(a1, a2);
else
result = sprintf(a2, "%ld", a1);
return result;
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1, char *a2)
{
int result; // eax

if ( (unsigned __int64)(a1 + 0x80000000LL) <= 0xFFFFFFFF )
result = func4(a1, a2);
else
result = sprintf(a2, "%ld", a1);
return result;
}

original_code:
int i64toa(int64_t n, char *s)
{
 if (n > 0x7fffffff || n < (-0x7fffffff - 1))
  return sprintf(s, "%" "l" "d", n);
 else
  return itoa(n, s);
}

canonical_original_code:
int i64toa(long n, char *s)
{
 if (n > 0x7fffffff || n < (-0x7fffffff - 1))
  return sprintf(s, "%" "l" "d", n);
 else
  return itoa(n, s);
}

variable_types: n long


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

switch ( a1 )
{
case 'A':
result = 45LL;
break;
case 'B':
result = 21LL;
break;
case 'E':
result = 39LL;
break;
case 'H':
result = 21LL;
break;
case 'I':
result = 68LL;
break;
case 'J':
result = 38LL;
break;
case 'P':
result = 56LL;
break;
case 'X':
result = 27LL;
break;
case 'd':
result = 51LL;
break;
case 'r':
result = 58LL;
break;
case 's':
result = 17LL;
break;
default:
result = 0LL;
break;
}
return result;
}

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

switch ( a1 )
{
case 'A':
result = 45LL;
break;
case 'B':
result = 21LL;
break;
case 'E':
result = 39LL;
break;
case 'H':
result = 21LL;
break;
case 'I':
result = 68LL;
break;
case 'J':
result = 38LL;
break;
case 'P':
result = 56LL;
break;
case 'X':
result = 27LL;
break;
case 'd':
result = 51LL;
break;
case 'r':
result = 58LL;
break;
case 's':
result = 17LL;
break;
default:
result = 0LL;
break;
}
return result;
}

original_code:
static unsigned long pitch_message_size(u8 type)
{
 switch (type) {
 case PITCH_MSG_SYMBOL_CLEAR:
  return sizeof(struct pitch_msg_symbol_clear);
 case PITCH_MSG_ADD_ORDER_SHORT:
  return sizeof(struct pitch_msg_add_order_short);
 case PITCH_MSG_ADD_ORDER_LONG:
  return sizeof(struct pitch_msg_add_order_long);
 case PITCH_MSG_ORDER_EXECUTED:
  return sizeof(struct pitch_msg_order_executed);
 case PITCH_MSG_ORDER_CANCEL:
  return sizeof(struct pitch_msg_order_cancel);
 case PITCH_MSG_TRADE_SHORT:
  return sizeof(struct pitch_msg_trade_short);
 case PITCH_MSG_TRADE_LONG:
  return sizeof(struct pitch_msg_trade_long);
 case PITCH_MSG_TRADE_BREAK:
  return sizeof(struct pitch_msg_trade_break);
 case PITCH_MSG_TRADING_STATUS:
  return sizeof(struct pitch_msg_trading_status);
 case PITCH_MSG_AUCTION_UPDATE:
  return sizeof(struct pitch_msg_auction_update);
 case PITCH_MSG_AUCTION_SUMMARY:
  return sizeof(struct pitch_msg_auction_summary);
 default:
  break;
 };
 return 0;
}

canonical_original_code:
static unsigned long pitch_message_size(unsigned char type)
{
 switch (type) {
 case PITCH_MSG_SYMBOL_CLEAR:
  return sizeof(struct pitch_msg_symbol_clear);
 case PITCH_MSG_ADD_ORDER_SHORT:
  return sizeof(struct pitch_msg_add_order_short);
 case PITCH_MSG_ADD_ORDER_LONG:
  return sizeof(struct pitch_msg_add_order_long);
 case PITCH_MSG_ORDER_EXECUTED:
  return sizeof(struct pitch_msg_order_executed);
 case PITCH_MSG_ORDER_CANCEL:
  return sizeof(struct pitch_msg_order_cancel);
 case PITCH_MSG_TRADE_SHORT:
  return sizeof(struct pitch_msg_trade_short);
 case PITCH_MSG_TRADE_LONG:
  return sizeof(struct pitch_msg_trade_long);
 case PITCH_MSG_TRADE_BREAK:
  return sizeof(struct pitch_msg_trade_break);
 case PITCH_MSG_TRADING_STATUS:
  return sizeof(struct pitch_msg_trading_status);
 case PITCH_MSG_AUCTION_UPDATE:
  return sizeof(struct pitch_msg_auction_update);
 case PITCH_MSG_AUCTION_SUMMARY:
  return sizeof(struct pitch_msg_auction_summary);
 default:
  break;
 };
 return 0;
}

variable_types:
type
unsigned char

user_defined_types: struct pitch_msg_symbol_clear { char Timestamp[8]; unsigned char MessageType; char StockSymbol[8]; }

user_defined_types: struct pitch_msg_add_order_short { char Timestamp[8]; unsigned char MessageType; char OrderID[12]; char SideIndicator; char Shares[6]; char StockSymbol[6]; char Price[10]; char Display; }

user_defined_types: struct pitch_msg_add_order_long { char Timestamp[8]; unsigned char MessageType; char OrderID[12]; char SideIndicator; char Shares[6]; char StockSymbol[8]; char Price[10]; char Display; char ParticipantID[4]; }

user_defined_types: struct pitch_msg_order_executed { char Timestamp[8]; unsigned char MessageType; char OrderID[12]; char ExecutedShares[6]; char ExecutionID[12]; }

user_defined_types: struct pitch_msg_order_cancel { char Timestamp[8]; unsigned char MessageType; char OrderID[12]; char CanceledShares[6]; }

user_defined_types: struct pitch_msg_trade_short { char Timestamp[8]; unsigned char MessageType; char OrderID[12]; char SideIndicator; char Shares[6]; char StockSymbol[6]; char Price[10]; char ExecutionID[12]; }

user_defined_types: struct pitch_msg_trade_long { char Timestamp[8]; unsigned char MessageType; char OrderID[12]; char SideIndicator; char Shares[6]; char StockSymbol[8]; char Price[10]; char ExecutionID[12]; }

user_defined_types: struct pitch_msg_trade_break { char Timestamp[8]; unsigned char MessageType; char ExecutionID[12]; }

user_defined_types: struct pitch_msg_trading_status { char Timestamp[8]; unsigned char MessageType; char StockSymbol[8]; char HaltStatus; char RegSHOAction; char Reserved1; char Reserved2; }

user_defined_types: struct pitch_msg_auction_update { char Timestamp[8]; unsigned char MessageType; char StockSymbol[8]; char AuctionType; char ReferencePrice[10]; char BuyShares[10]; char SellShares[10]; char IndicativePrice[10]; char AuctionOnlyPrice[10]; }

user_defined_types: struct pitch_msg_auction_summary { char Timestamp[8]; unsigned char MessageType; char StockSymbol[8]; char AuctionType; char Price[10]; char Shares[10]; }


decompiled_code:
__int64 __fastcall pitch_message_decode(_QWORD *a1, __int64 a2)
{
unsigned __int64 v2; // rax
unsigned __int64 v3; // r13
__int64 v4; // r12
__int64 v5; // rax

v2 = buffer_size(a1);
if ( v2 <= 8 )
return 0LL;
v3 = v2;
v4 = buffer_start(a1);
v5 = pitch_message_size(*(_BYTE *)(v4 + 8));
if ( !v5 )
return 0LL;
if ( v5 + a2 > v3 )
return 0LL;
buffer_advance(a1, v5);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, __int64 a2)
{
unsigned __int64 v2; // rax
unsigned __int64 v3; // r13
__int64 v4; // r12
__int64 v5; // rax

v2 = func2(a1);
if ( v2 <= 8 )
return 0LL;
v3 = v2;
v4 = func0(a1);
v5 = func3(*(_BYTE *)(v4 + 8));
if ( !v5 )
return 0LL;
if ( v5 + a2 > v3 )
return 0LL;
func1(a1, v5);
return v4;
}

original_code:
struct pitch_message *pitch_message_decode(struct buffer *buf, unsigned long extra)
{
 struct pitch_message *msg;
 size_t available;
 size_t size;
 available = buffer_size(buf);
 if (available < sizeof(*msg))
  return ((void *)0);
 msg = (void *) buffer_start(buf);
 size = pitch_message_size(msg->MessageType);
 if (!size)
  return ((void *)0);
 if (available < size + extra)
  return ((void *)0);
 buffer_advance(buf, size);
 return msg;
}

canonical_original_code:
struct pitch_message *pitch_message_decode(struct buffer *buf, unsigned long extra)
{
 struct pitch_message *msg;
 unsigned long available;
 unsigned long size;
 available = buffer_size(buf);
 if (available < sizeof(*msg))
  return ((void *)0);
 msg = (void *) buffer_start(buf);
 size = pitch_message_size(msg->MessageType);
 if (!size)
  return ((void *)0);
 if (available < size + extra)
  return ((void *)0);
 buffer_advance(buf, size);
 return msg;
}

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

variable_types:
extra
unsigned long

variable_types: struct pitch_message { char Timestamp[8]; unsigned char MessageType; } *

variable_types:
available
unsigned long

variable_types:
size
unsigned long


decompiled_code:
__int64 __fastcall buffer_get_be16(_QWORD *a1)
{
int v1; // ebx

v1 = (unsigned __int8)buffer_get_8(a1) << 8;
return v1 | (unsigned int)(unsigned __int8)buffer_get_8(a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
int v1; // ebx

v1 = (unsigned __int8)func0(a1) << 8;
return v1 | (unsigned int)(unsigned __int8)func0(a1);
}

original_code:
static inline u16 buffer_get_be16(struct buffer *self)
{
 u16 x = 0;
 x |= (u16)buffer_get_8(self) << 8;
 x |= (u16)buffer_get_8(self);
 return x;
}

canonical_original_code:
static inline unsigned short buffer_get_be16(struct buffer *self)
{
 unsigned short x = 0;
 x |= (unsigned short)buffer_get_8(self) << 8;
 x |= (unsigned short)buffer_get_8(self);
 return x;
}

variable_types:
x
unsigned short

return_type: unsigned short


decompiled_code:
__int64 __fastcall soupbin3_packet_decode(_QWORD *a1, unsigned __int16 a2, void *a3)
{
__int64 v4; // rax

v4 = buffer_start(a1);
memcpy(a3, (const void *)(v4 - 2), a2 + 2LL);
buffer_advance(a1, a2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1, unsigned __int16 a2, void *a3)
{
__int64 v4; // rax

v4 = func2(a1);
memcpy(a3, (const void *)(v4 - 2), a2 + 2LL);
func3(a1, a2);
return 0LL;
}

original_code:
static int soupbin3_packet_decode(struct buffer *buf, u16 len, struct soupbin3_packet *packet)
{
 size_t size;
 void *start;
 start = buffer_start(buf);
 size = sizeof(u16) + len;
 memcpy(packet, start - sizeof(u16), size);
 buffer_advance(buf, len);
 return 0;
}

canonical_original_code:
static int soupbin3_packet_decode(struct buffer *buf, unsigned short len, struct soupbin3_packet *packet)
{
 unsigned long size;
 void *start;
 start = buffer_start(buf);
 size = sizeof(u16) + len;
 memcpy(packet, start - sizeof(u16), size);
 buffer_advance(buf, len);
 return 0;
}

variable_types:
len
unsigned short

variable_types: struct soupbin3_packet { unsigned short PacketLength; char PacketType; } *

variable_types:
start
void *


decompiled_code:
void __fastcall soupbin3_session_delete(void *ptr)
{
buffer_delete(*((_QWORD *)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func8(void *ptr)
{
buffer_delete(*((_QWORD *)ptr + 1));
free(ptr);
}

original_code:
void soupbin3_session_delete(struct soupbin3_session *session)
{
 buffer_delete(session->rx_buffer);
 free(session);
}

variable_types: struct soupbin3_session { int sockfd; struct buffer { unsigned long start; unsigned long end; unsigned long capacity; char *data; } *rx_buffer; } *

user_defined_types: struct soupbin3_session { int sockfd; struct buffer *rx_buffer; }


decompiled_code:
__int64 __fastcall soupbin3_session_recv(unsigned int *a1, void *a2)
{
_QWORD *v2; // rbx
unsigned __int16 v3; // bx
_QWORD *v4; // rbp

v2 = (_QWORD *)*((_QWORD *)a1 + 1);
if ( !buffer_size(v2) )
{
buffer_reset(v2);
if ( buffer_xread(*((_QWORD *)a1 + 1), *a1) <= 0 )
return 0xFFFFFFFFLL;
}
v3 = buffer_get_be16(*((_QWORD **)a1 + 1));
v4 = (_QWORD *)*((_QWORD *)a1 + 1);
if ( buffer_remaining((__int64)v4) < (unsigned __int64)v3 )
_assert_fail("0", "lib/proto/soupbin3_session.c", 0x46u, "soupbin3_session_recv");
return soupbin3_packet_decode(v4, v3, a2);
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int *a1, void *a2)
{
_QWORD *v2; // rbx
unsigned __int16 v3; // bx
_QWORD *v4; // rbp

v2 = (_QWORD *)*((_QWORD *)a1 + 1);
if ( !func4(v2) )
{
func6(v2);
if ( buffer_xread(*((_QWORD *)a1 + 1), *a1) <= 0 )
return 0xFFFFFFFFLL;
}
v3 = func1(*((_QWORD **)a1 + 1));
v4 = (_QWORD *)*((_QWORD *)a1 + 1);
if ( func5((__int64)v4) < (unsigned __int64)v3 )
_assert_fail("0", "lib/proto/soupbin3_session.c", 0x46u, "soupbin3_session_recv");
return func7(v4, v3, a2);
}

original_code:
int soupbin3_session_recv(struct soupbin3_session *session, struct soupbin3_packet *packet)
{
 u16 len;
 ssize_t nr;
 if (buffer_size(session->rx_buffer) > 0)
  goto decode;
 buffer_reset(session->rx_buffer);
 nr = buffer_xread(session->rx_buffer, session->sockfd);
 if (nr <= 0)
  return -1;
decode:
 len = buffer_get_be16(session->rx_buffer);
 if (buffer_remaining(session->rx_buffer) < len)
  ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "lib/proto/soupbin3_session.c", 70, __extension__ __PRETTY_FUNCTION__); }));
 return soupbin3_packet_decode(session->rx_buffer, len, packet);
}

canonical_original_code:
int soupbin3_session_recv(struct soupbin3_session *session, struct soupbin3_packet *packet)
{
 unsigned short len;
 long nr;
 if (buffer_size(session->rx_buffer) > 0)
  goto decode;
 buffer_reset(session->rx_buffer);
 nr = buffer_xread(session->rx_buffer, session->sockfd);
 if (nr <= 0)
  return -1;
decode:
 len = buffer_get_be16(session->rx_buffer);
 if (buffer_remaining(session->rx_buffer) < len)
  ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "lib/proto/soupbin3_session.c", 70, __extension__ __PRETTY_FUNCTION__); }));
 return soupbin3_packet_decode(session->rx_buffer, len, packet);
}

variable_types: nr long

user_defined_types: struct soupbin3_packet { unsigned short PacketLength; char PacketType; }


decompiled_code:
__int64 __fastcall lse_itch_message_decode(_QWORD *a1, _QWORD *a2)
{
__int64 v2; // rax
unsigned __int64 v3; // r14
unsigned __int8 v4; // r12
char *v5; // rax

v2 = buffer_size(a1);
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = v2;
v4 = buffer_peek_8(a1);
if ( v3 < v4 )
return 0xFFFFFFFFLL;
v5 = (char *)buffer_start(a1);
if ( v4 >= 8u )
{
*a2 = *(_QWORD *)v5;
*(_QWORD *)((char *)a2 + v4 - 8) = *(_QWORD *)&v5[v4 - 8];
qmemcpy(
(void *)((unsigned __int64)(a2 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(v5 - ((char *)a2 - ((unsigned __int64)(a2 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * ((v4 + (unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8)) >> 3));
}
else if ( (v4 & 4) != 0 )
{
*(_DWORD *)a2 = *(_DWORD *)v5;
*(_DWORD *)((char *)a2 + v4 - 4) = *(_DWORD *)&v5[v4 - 4];
}
else if ( v4 )
{
*(_BYTE *)a2 = *v5;
if ( (v4 & 2) != 0 )
*(_WORD *)((char *)a2 + v4 - 2) = *(_WORD *)&v5[v4 - 2];
}
buffer_advance(a1, v4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, _QWORD *a2)
{
__int64 v2; // rax
unsigned __int64 v3; // r14
unsigned __int8 v4; // r12
char *v5; // rax

v2 = func3(a1);
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = v2;
v4 = func0(a1);
if ( v3 < v4 )
return 0xFFFFFFFFLL;
v5 = (char *)func1(a1);
if ( v4 >= 8u )
{
*a2 = *(_QWORD *)v5;
*(_QWORD *)((char *)a2 + v4 - 8) = *(_QWORD *)&v5[v4 - 8];
qmemcpy(
(void *)((unsigned __int64)(a2 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(v5 - ((char *)a2 - ((unsigned __int64)(a2 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * ((v4 + (unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8)) >> 3));
}
else if ( (v4 & 4) != 0 )
{
*(_DWORD *)a2 = *(_DWORD *)v5;
*(_DWORD *)((char *)a2 + v4 - 4) = *(_DWORD *)&v5[v4 - 4];
}
else if ( v4 )
{
*(_BYTE *)a2 = *v5;
if ( (v4 & 2) != 0 )
*(_WORD *)((char *)a2 + v4 - 2) = *(_WORD *)&v5[v4 - 2];
}
func2(a1, v4);
return 0LL;
}

original_code:
int lse_itch_message_decode(struct buffer *buf, struct lse_itch_message *msg)
{
 size_t available;
 size_t size;
 available = buffer_size(buf);
 if (!available)
  return -1;
 size = buffer_peek_8(buf);
 if (available < size)
  return -1;
 memcpy(msg, buffer_start(buf), size);
 buffer_advance(buf, size);
 return 0;
}

canonical_original_code:
int lse_itch_message_decode(struct buffer *buf, struct lse_itch_message *msg)
{
 unsigned long available;
 unsigned long size;
 available = buffer_size(buf);
 if (!available)
  return -1;
 size = buffer_peek_8(buf);
 if (available < size)
  return -1;
 memcpy(msg, buffer_start(buf), size);
 buffer_advance(buf, size);
 return 0;
}

variable_types: struct lse_itch_message { unsigned char Length; unsigned char MessageType; } *

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


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

switch ( a1 )
{
case 'A':
result = 28LL;
break;
case 'B':
result = 13LL;
break;
case 'C':
result = 30LL;
break;
case 'D':
result = 13LL;
break;
case 'E':
result = 25LL;
break;
case 'F':
result = 32LL;
break;
case 'H':
result = 17LL;
break;
case 'I':
result = 42LL;
break;
case 'L':
result = 18LL;
break;
case 'P':
result = 36LL;
break;
case 'Q':
result = 32LL;
break;
case 'R':
result = 18LL;
break;
case 'S':
result = 6LL;
break;
case 'T':
result = 5LL;
break;
case 'U':
result = 29LL;
break;
case 'X':
result = 17LL;
break;
default:
result = 0LL;
break;
}
return result;
}

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

switch ( a1 )
{
case 'A':
result = 28LL;
break;
case 'B':
result = 13LL;
break;
case 'C':
result = 30LL;
break;
case 'D':
result = 13LL;
break;
case 'E':
result = 25LL;
break;
case 'F':
result = 32LL;
break;
case 'H':
result = 17LL;
break;
case 'I':
result = 42LL;
break;
case 'L':
result = 18LL;
break;
case 'P':
result = 36LL;
break;
case 'Q':
result = 32LL;
break;
case 'R':
result = 18LL;
break;
case 'S':
result = 6LL;
break;
case 'T':
result = 5LL;
break;
case 'U':
result = 29LL;
break;
case 'X':
result = 17LL;
break;
default:
result = 0LL;
break;
}
return result;
}

original_code:
static unsigned long itch40_message_size(u8 type)
{
 switch (type) {
        case ITCH40_MSG_TIMESTAMP_SECONDS:
  return sizeof(struct itch40_msg_timestamp_seconds);
        case ITCH40_MSG_SYSTEM_EVENT:
  return sizeof(struct itch40_msg_system_event);
        case ITCH40_MSG_STOCK_DIRECTORY:
  return sizeof(struct itch40_msg_stock_directory);
        case ITCH40_MSG_STOCK_TRADING_ACTION:
  return sizeof(struct itch40_msg_stock_trading_action);
        case ITCH40_MSG_MARKET_PARTICIPANT_POS:
  return sizeof(struct itch40_msg_market_participant_pos);
        case ITCH40_MSG_ADD_ORDER:
  return sizeof(struct itch40_msg_add_order);
        case ITCH40_MSG_ADD_ORDER_MPID:
  return sizeof(struct itch40_msg_add_order_mpid);
        case ITCH40_MSG_ORDER_EXECUTED:
  return sizeof(struct itch40_msg_order_executed);
        case ITCH40_MSG_ORDER_EXECUTED_WITH_PRICE:
  return sizeof(struct itch40_msg_order_executed_with_price);
        case ITCH40_MSG_ORDER_CANCEL:
  return sizeof(struct itch40_msg_order_cancel);
        case ITCH40_MSG_ORDER_DELETE:
  return sizeof(struct itch40_msg_order_delete);
        case ITCH40_MSG_ORDER_REPLACE:
  return sizeof(struct itch40_msg_order_replace);
        case ITCH40_MSG_TRADE:
  return sizeof(struct itch40_msg_trade);
        case ITCH40_MSG_CROSS_TRADE:
  return sizeof(struct itch40_msg_cross_trade);
        case ITCH40_MSG_BROKEN_TRADE:
  return sizeof(struct itch40_msg_broken_trade);
        case ITCH40_MSG_NOII:
  return sizeof(struct itch40_msg_noii);
 default:
  break;
 };
 return 0;
}

canonical_original_code:
static unsigned long itch40_message_size(unsigned char type)
{
 switch (type) {
        case ITCH40_MSG_TIMESTAMP_SECONDS:
  return sizeof(struct itch40_msg_timestamp_seconds);
        case ITCH40_MSG_SYSTEM_EVENT:
  return sizeof(struct itch40_msg_system_event);
        case ITCH40_MSG_STOCK_DIRECTORY:
  return sizeof(struct itch40_msg_stock_directory);
        case ITCH40_MSG_STOCK_TRADING_ACTION:
  return sizeof(struct itch40_msg_stock_trading_action);
        case ITCH40_MSG_MARKET_PARTICIPANT_POS:
  return sizeof(struct itch40_msg_market_participant_pos);
        case ITCH40_MSG_ADD_ORDER:
  return sizeof(struct itch40_msg_add_order);
        case ITCH40_MSG_ADD_ORDER_MPID:
  return sizeof(struct itch40_msg_add_order_mpid);
        case ITCH40_MSG_ORDER_EXECUTED:
  return sizeof(struct itch40_msg_order_executed);
        case ITCH40_MSG_ORDER_EXECUTED_WITH_PRICE:
  return sizeof(struct itch40_msg_order_executed_with_price);
        case ITCH40_MSG_ORDER_CANCEL:
  return sizeof(struct itch40_msg_order_cancel);
        case ITCH40_MSG_ORDER_DELETE:
  return sizeof(struct itch40_msg_order_delete);
        case ITCH40_MSG_ORDER_REPLACE:
  return sizeof(struct itch40_msg_order_replace);
        case ITCH40_MSG_TRADE:
  return sizeof(struct itch40_msg_trade);
        case ITCH40_MSG_CROSS_TRADE:
  return sizeof(struct itch40_msg_cross_trade);
        case ITCH40_MSG_BROKEN_TRADE:
  return sizeof(struct itch40_msg_broken_trade);
        case ITCH40_MSG_NOII:
  return sizeof(struct itch40_msg_noii);
 default:
  break;
 };
 return 0;
}

user_defined_types: struct itch40_msg_timestamp_seconds { unsigned char MessageType; unsigned int Second; }

user_defined_types: struct itch40_msg_system_event { unsigned char MessageType; unsigned int Timestamp; char EventCode; }

user_defined_types: struct itch40_msg_stock_directory { unsigned char MessageType; unsigned int TimestampNanoseconds; char Stock[6]; char MarketCategory; char FinancialStatusIndicator; unsigned int RoundLotSize; char RoundLotsOnly; }

user_defined_types: struct itch40_msg_stock_trading_action { unsigned char MessageType; unsigned int TimestampNanoseconds; char Stock[6]; char TradingState; char Reserved; char Reason[4]; }

user_defined_types: struct itch40_msg_market_participant_pos { unsigned char MessageType; unsigned int TimestampNanoseconds; char MPID[4]; char Stock[6]; char PrimaryMarketMaker; char MarketMakerMode; char MarketParticipantState; }

user_defined_types: struct itch40_msg_add_order { unsigned char MessageType; unsigned int TimestampNanoseconds; unsigned long OrderReferenceNumber; char BuySellIndicator; unsigned int Shares; char Stock[6]; unsigned int Price; }

user_defined_types: struct itch40_msg_add_order_mpid { unsigned char MessageType; unsigned int TimestampNanoseconds; unsigned long OrderReferenceNumber; char BuySellIndicator; unsigned int Shares; char Stock[6]; unsigned int Price; char Attribution[4]; }

user_defined_types: struct itch40_msg_order_executed { unsigned char MessageType; unsigned int TimestampNanoseconds; unsigned long OrderReferenceNumber; unsigned int ExecutedShares; unsigned long MatchNumber; }

user_defined_types: struct itch40_msg_order_executed_with_price { unsigned char MessageType; unsigned int TimestampNanoseconds; unsigned long OrderReferenceNumber; unsigned int ExecutedShares; unsigned long MatchNumber; char Printable; unsigned int ExecutionPrice; }

user_defined_types: struct itch40_msg_order_cancel { unsigned char MessageType; unsigned int TimestampNanoseconds; unsigned long OrderReferenceNumber; unsigned int CanceledShares; }

user_defined_types: struct itch40_msg_order_delete { unsigned char MessageType; unsigned int TimestampNanoseconds; unsigned long OrderReferenceNumber; }

user_defined_types: struct itch40_msg_order_replace { unsigned char MessageType; unsigned int TimestampNanoseconds; unsigned long OriginalOrderReferenceNumber; unsigned long NewOrderReferenceNumber; unsigned int Shares; unsigned int Price; }

user_defined_types: struct itch40_msg_trade { unsigned char MessageType; unsigned int TimestampNanoseconds; unsigned long OrderReferenceNumber; char BuySellIndicator; unsigned int Shares; char Stock[6]; unsigned int Price; unsigned long MatchNumber; }

user_defined_types: struct itch40_msg_cross_trade { unsigned char MessageType; unsigned int TimestampNanoseconds; unsigned long Shares; char Stock[6]; unsigned int CrossPrice; unsigned long MatchNumber; char CrossType; }

user_defined_types: struct itch40_msg_broken_trade { unsigned char MessageType; unsigned int TimestampNanoseconds; unsigned long MatchNumber; }

user_defined_types: struct itch40_msg_noii { unsigned char MessageType; unsigned int TimestampNanoseconds; unsigned long PairedShares; unsigned long ImbalanceShares; char ImbalanceDirection; char Stock[6]; unsigned int FarPrice; unsigned int NearPrice; unsigned int CurrentReferencePrice; char CrossType; char PriceVariationIndicator; }


decompiled_code:
__int64 __fastcall itch40_message_decode(_QWORD *a1, void *a2)
{
__int64 v2; // rax
unsigned __int64 v3; // r12
char v4; // al
unsigned __int64 v5; // rax
size_t v6; // rbp
const void *v7; // rax

v2 = buffer_size(a1);
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = v2;
v4 = buffer_peek_8(a1);
v5 = itch40_message_size(v4);
v6 = v5;
if ( v3 < v5 || !v5 )
return 0xFFFFFFFFLL;
v7 = (const void *)buffer_start(a1);
memcpy(a2, v7, v6);
buffer_advance(a1, v6);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1, void *a2)
{
__int64 v2; // rax
unsigned __int64 v3; // r12
char v4; // al
unsigned __int64 v5; // rax
size_t v6; // rbp
const void *v7; // rax

v2 = func3(a1);
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = v2;
v4 = func0(a1);
v5 = func4(v4);
v6 = v5;
if ( v3 < v5 || !v5 )
return 0xFFFFFFFFLL;
v7 = (const void *)func1(a1);
memcpy(a2, v7, v6);
func2(a1, v6);
return 0LL;
}

original_code:
int itch40_message_decode(struct buffer *buf, struct itch40_message *msg)
{
 size_t available;
 size_t size;
 u8 type;
 available = buffer_size(buf);
 if (!available)
  return -1;
 type = buffer_peek_8(buf);
 size = itch40_message_size(type);
 if (!size)
  return -1;
 if (available < size)
  return -1;
 memcpy(msg, buffer_start(buf), size);
 buffer_advance(buf, size);
 return 0;
}

canonical_original_code:
int itch40_message_decode(struct buffer *buf, struct itch40_message *msg)
{
 unsigned long available;
 unsigned long size;
 unsigned char type;
 available = buffer_size(buf);
 if (!available)
  return -1;
 type = buffer_peek_8(buf);
 size = itch40_message_size(type);
 if (!size)
  return -1;
 if (available < size)
  return -1;
 memcpy(msg, buffer_start(buf), size);
 buffer_advance(buf, size);
 return 0;
}

variable_types: struct itch40_message { unsigned char MessageType; } *

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


decompiled_code:
void __fastcall signal_handler(int a1)
{
if ( a1 == 2 )
stop = 1;
}

canonical_decompiled_code:
void __fastcall func1(int a1)
{
if ( a1 == 2 )
stop = 1;
}

original_code:
static void signal_handler(int signum)
{
 if (signum == 2)
  stop = 1;
}

variable_types: signum int


decompiled_code:
char **__fastcall lookup_protocol_info(const char *a1)
{
bool v1; // zf
_BOOL4 v2; // eax
char **result; // rax

v1 = strcmp("raw", a1) == 0;
v2 = !v1;
if ( !v1 )
{
result = 0LL;
if ( strcmp("fast", a1) )
return result;
v2 = 1;
}
return &(&protocols)[2 * v2];
}

canonical_decompiled_code:
char **__fastcall func2(const char *a1)
{
bool v1; // zf
_BOOL4 v2; // eax
char **result; // rax

v1 = strcmp("raw", a1) == 0;
v2 = !v1;
if ( !v1 )
{
result = 0LL;
if ( strcmp("fast", a1) )
return result;
v2 = 1;
}
return &(&protocols)[2 * v2];
}

original_code:
static const struct protocol_info *lookup_protocol_info(const char *name)
{
 int i;
 for (i = 0; i < (sizeof(protocols) / sizeof((protocols)[0])); i++) {
  const struct protocol_info *proto_info = &protocols[i];
  if (!strcmp(proto_info->name, name))
   return proto_info;
 }
 return ((void *)0);
}

canonical_original_code:
static struct protocol_info *lookup_protocol_info(char *name)
{
 int i;
 for (i = 0; i < (sizeof(protocols) / sizeof((protocols)[0])); i++) {
  struct protocol_info *proto_info = &protocols[i];
  if (!strcmp(proto_info->name, name))
   return proto_info;
 }
 return ((void *)0);
}

variable_types:
name
char *

variable_types: i int

variable_types: struct protocol_info { char *name; int (*session_initiate)(struct fast_session_cfg { int preamble_bytes; int sockfd; _Bool reset; } *, char *); } *

user_defined_types: struct protocol_info { char *name; int (*session_initiate)(struct fast_session_cfg *, char *); }


decompiled_code:
__int64 __fastcall raw_session_initiate(__int64 a1, const char *a2)
{
int v2; // eax
int v3; // er12
unsigned int v4; // ebx
int *v6; // rax
char *v7; // rax
int *v8; // rax
char *v9; // rax
int v10; // eax
int v11; // eax
int *v12; // rax
char *v13; // rax
int *v14; // rax
char *v15; // rax
fd_set v16; // [rsp+0h] [rbp-8A8h] BYREF
char buf[2088]; // [rsp+80h] [rbp-828h] BYREF

memset(&v16, 0, sizeof(v16));
v16.fds_bits[*(_DWORD *)(a1 + 4) / 64] |= 1LL << (*(_DWORD *)(a1 + 4) % 64);
v2 = open(a2, 578, 420LL);
if ( v2 < 0 )
{
v6 = _errno_location();
v7 = strerror(*v6);
fprintf(stderr, "Parser: Cannot open a file (%s)\n", v7);
return 1;
}
v3 = v2;
v4 = 1;
while ( !stop )
{
v11 = select(*(_DWORD *)(a1 + 4) + 1, &v16, 0LL, 0LL, 0LL);
v4 = v11;
if ( v11 < 0 )
{
v8 = _errno_location();
v9 = strerror(*v8);
fprintf(stderr, "Parser: Select failed (%s)\n", v9);
}
else if ( !v11 )
{
continue;
}
v10 = read(*(_DWORD *)(a1 + 4), buf, 0x800uLL);
v4 = v10;
if ( v10 < 0 )
{
v12 = _errno_location();
v13 = strerror(*v12);
fprintf(stderr, "Parser: Cannot read data (%s)\n", v13);
return v4;
}
v4 = write(v3, buf, v10);
if ( (v4 & 0x80000000) != 0 )
{
v14 = _errno_location();
v15 = strerror(*v14);
fprintf(stderr, "Parser: Cannot write data (%s)\n", v15);
return v4;
}
}
close(v3);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const char *a2)
{
int v2; // eax
int v3; // er12
unsigned int v4; // ebx
int *v6; // rax
char *v7; // rax
int *v8; // rax
char *v9; // rax
int v10; // eax
int v11; // eax
int *v12; // rax
char *v13; // rax
int *v14; // rax
char *v15; // rax
fd_set v16; // [rsp+0h] [rbp-8A8h] BYREF
char buf[2088]; // [rsp+80h] [rbp-828h] BYREF

memset(&v16, 0, sizeof(v16));
v16.fds_bits[*(_DWORD *)(a1 + 4) / 64] |= 1LL << (*(_DWORD *)(a1 + 4) % 64);
v2 = open(a2, 578, 420LL);
if ( v2 < 0 )
{
v6 = _errno_location();
v7 = strerror(*v6);
fprintf(stderr, "Parser: Cannot open a file (%s)\n", v7);
return 1;
}
v3 = v2;
v4 = 1;
while ( !stop )
{
v11 = select(*(_DWORD *)(a1 + 4) + 1, &v16, 0LL, 0LL, 0LL);
v4 = v11;
if ( v11 < 0 )
{
v8 = _errno_location();
v9 = strerror(*v8);
fprintf(stderr, "Parser: Select failed (%s)\n", v9);
}
else if ( !v11 )
{
continue;
}
v10 = read(*(_DWORD *)(a1 + 4), buf, 0x800uLL);
v4 = v10;
if ( v10 < 0 )
{
v12 = _errno_location();
v13 = strerror(*v12);
fprintf(stderr, "Parser: Cannot read data (%s)\n", v13);
return v4;
}
v4 = write(v3, buf, v10);
if ( (v4 & 0x80000000) != 0 )
{
v14 = _errno_location();
v15 = strerror(*v14);
fprintf(stderr, "Parser: Cannot write data (%s)\n", v15);
return v4;
}
}
close(v3);
return v4;
}

original_code:
static int raw_session_initiate(struct fast_session_cfg *cfg, const char *out)
{
 unsigned char buf[2048];
 int ret = 1;
 fd_set fds;
 int outfd;
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&fds)->fds_bits)[((cfg->sockfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((cfg->sockfd) % (8 * (int) sizeof (__fd_mask)))))));
 outfd = open(out, 02 | 0100 | 01000, 0644);
 if (outfd < 0) {
  fprintf(stderr, "Parser: Cannot open a file (%s)\n", strerror((*__errno_location ())));
  goto exit;
 }
 while (!stop) {
  ret = select(cfg->sockfd + 1, &fds, ((void *)0), ((void *)0), ((void *)0));
  if (ret < 0)
   fprintf(stderr, "Parser: Select failed (%s)\n", strerror((*__errno_location ())));
  else if (ret < 1)
   continue;
  ret = read(cfg->sockfd, buf, 2048);
  if (ret < 0) {
   fprintf(stderr, "Parser: Cannot read data (%s)\n", strerror((*__errno_location ())));
   goto exit;
  }
  ret = write(outfd, buf, ret);
  if (ret < 0) {
   fprintf(stderr, "Parser: Cannot write data (%s)\n", strerror((*__errno_location ())));
   goto exit;
  }
 }
 close(outfd);
exit:
 return ret;
}

canonical_original_code:
static int raw_session_initiate(struct fast_session_cfg *cfg, char *out)
{
 unsigned char buf[2048];
 int ret = 1;
 struct fd_set fds;
 int outfd;
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&fds)->fds_bits)[((cfg->sockfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((cfg->sockfd) % (8 * (int) sizeof (__fd_mask)))))));
 outfd = open(out, 02 | 0100 | 01000, 0644);
 if (outfd < 0) {
  fprintf(stderr, "Parser: Cannot open a file (%s)\n", strerror((*__errno_location ())));
  goto exit;
 }
 while (!stop) {
  ret = select(cfg->sockfd + 1, &fds, ((void *)0), ((void *)0), ((void *)0));
  if (ret < 0)
   fprintf(stderr, "Parser: Select failed (%s)\n", strerror((*__errno_location ())));
  else if (ret < 1)
   continue;
  ret = read(cfg->sockfd, buf, 2048);
  if (ret < 0) {
   fprintf(stderr, "Parser: Cannot read data (%s)\n", strerror((*__errno_location ())));
   goto exit;
  }
  ret = write(outfd, buf, ret);
  if (ret < 0) {
   fprintf(stderr, "Parser: Cannot write data (%s)\n", strerror((*__errno_location ())));
   goto exit;
  }
 }
 close(outfd);
exit:
 return ret;
}

variable_types: struct fast_session_cfg { int preamble_bytes; int sockfd; _Bool reset; } *

variable_types:
out
char *

variable_types:
buf
unsigned char [2048]

variable_types: ret int

variable_types:
fds
struct fd_set { long fds_bits[-1]; }

variable_types: outfd int


msocket

decompiled_code:
__int64 __fastcall msocket(char *cp, char *a2, char *a3, __int16 a4)
{
int v6; // eax
unsigned int v7; // ebx
unsigned int v8; // eax
int *v10; // rax
char *v11; // rax
int *v12; // rax
char *v13; // rax
int *v14; // rax
char *v15; // rax
int *v16; // rax
char *v17; // rax
int *v18; // rax
char *v19; // rax
int *v20; // rax
char *v21; // rax
int v22[2]; // [rsp+8h] [rbp-50h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-48h] BYREF
int optval[13]; // [rsp+24h] [rbp-34h] BYREF

v6 = socket(2, 2, 0);
if ( v6 < 0 )
{
v10 = _errno_location();
v11 = strerror(*v10);
fprintf(stderr, "Parser: Unable to open a socket (%s)\n", v11);
v7 = -1;
}
else
{
v7 = v6;
v8 = fcntl(v6, 3);
BYTE1(v8) |= 8u;
if ( fcntl(v7, 4, v8) < 0 )
{
v12 = _errno_location();
v13 = strerror(*v12);
fprintf(stderr, "Parser: Unable to make a socket nonblocking (%s)\n", v13);
v7 = -1;
}
else if ( socket_setopt(v7, 1, 2, 1) < 0 )
{
v14 = _errno_location();
v15 = strerror(*v14);
fprintf(stderr, "Parser: Unable to set opt (%s)\n", v15);
v7 = -1;
}
else
{
*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_WORD *)addr.sa_data = _bswap_16(a4);
if ( bind(v7, &addr, 0x10u) < 0 )
{
v16 = _errno_location();
v17 = strerror(*v16);
fprintf(stderr, "Parser: Unable to bind (%s)\n", v17);
v7 = -1;
}
else if ( a3 )
{
optval[0] = inet_addr(cp);
optval[1] = inet_addr(a2);
optval[2] = inet_addr(a3);
if ( setsockopt(v7, 0, 39, optval, 0xCu) < 0 )
{
v20 = _errno_location();
v21 = strerror(*v20);
fprintf(stderr, "Parser: Unable to join a group (%s)\n", v21);
v7 = -1;
}
}
else
{
v22[0] = inet_addr(cp);
v22[1] = inet_addr(a2);
if ( setsockopt(v7, 0, 35, v22, 8u) < 0 )
{
v18 = _errno_location();
v19 = strerror(*v18);
fprintf(stderr, "Parser: Unable to join a group (%s)\n", v19);
v7 = -1;
}
}
}
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *cp, char *a2, char *a3, __int16 a4)
{
int v6; // eax
unsigned int v7; // ebx
unsigned int v8; // eax
int *v10; // rax
char *v11; // rax
int *v12; // rax
char *v13; // rax
int *v14; // rax
char *v15; // rax
int *v16; // rax
char *v17; // rax
int *v18; // rax
char *v19; // rax
int *v20; // rax
char *v21; // rax
int v22[2]; // [rsp+8h] [rbp-50h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-48h] BYREF
int optval[13]; // [rsp+24h] [rbp-34h] BYREF

v6 = socket(2, 2, 0);
if ( v6 < 0 )
{
v10 = _errno_location();
v11 = strerror(*v10);
fprintf(stderr, "Parser: Unable to open a socket (%s)\n", v11);
v7 = -1;
}
else
{
v7 = v6;
v8 = fcntl(v6, 3);
BYTE1(v8) |= 8u;
if ( fcntl(v7, 4, v8) < 0 )
{
v12 = _errno_location();
v13 = strerror(*v12);
fprintf(stderr, "Parser: Unable to make a socket nonblocking (%s)\n", v13);
v7 = -1;
}
else if ( func5(v7, 1, 2, 1) < 0 )
{
v14 = _errno_location();
v15 = strerror(*v14);
fprintf(stderr, "Parser: Unable to set opt (%s)\n", v15);
v7 = -1;
}
else
{
*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_WORD *)addr.sa_data = func6(a4);
if ( bind(v7, &addr, 0x10u) < 0 )
{
v16 = _errno_location();
v17 = strerror(*v16);
fprintf(stderr, "Parser: Unable to bind (%s)\n", v17);
v7 = -1;
}
else if ( a3 )
{
optval[0] = inet_addr(cp);
optval[1] = inet_addr(a2);
optval[2] = inet_addr(a3);
if ( setsockopt(v7, 0, 39, optval, 0xCu) < 0 )
{
v20 = _errno_location();
v21 = strerror(*v20);
fprintf(stderr, "Parser: Unable to join a group (%s)\n", v21);
v7 = -1;
}
}
else
{
v22[0] = inet_addr(cp);
v22[1] = inet_addr(a2);
if ( setsockopt(v7, 0, 35, v22, 8u) < 0 )
{
v18 = _errno_location();
v19 = strerror(*v18);
fprintf(stderr, "Parser: Unable to join a group (%s)\n", v19);
v7 = -1;
}
}
}
}
return v7;
}

original_code:
static int msocket(const char *ip, const char *lip, const char *sip, int port)
{
 struct ip_mreq_source group_src;
 struct sockaddr_in sa;
 struct ip_mreq group;
 int sockfd;
 sockfd = socket(2, SOCK_DGRAM, 0);
 if (sockfd < 0) {
  fprintf(stderr, "Parser: Unable to open a socket (%s)\n", strerror((*__errno_location ())));
  goto fail;
 }
 if (fcntl(sockfd, 4, fcntl(sockfd, 3) | 04000) < 0) {
  fprintf(stderr, "Parser: Unable to make a socket nonblocking (%s)\n", strerror((*__errno_location ())));
  goto fail;
 }
 if (socket_setopt(sockfd, 1, 2, 1) < 0) {
  fprintf(stderr, "Parser: Unable to set opt (%s)\n", strerror((*__errno_location ())));
  goto fail;
 }
 sa = (struct sockaddr_in) {
  .sin_family = 2,
  .sin_port = htons(port),
  .sin_addr = (struct in_addr) {
   .s_addr = ((in_addr_t) 0x00000000),
  },
 };
 if (bind(sockfd, (const struct sockaddr *)&sa, sizeof(struct sockaddr_in)) < 0) {
  fprintf(stderr, "Parser: Unable to bind (%s)\n", strerror((*__errno_location ())));
  goto fail;
 }
 if (!sip) {
  group.imr_multiaddr.s_addr = inet_addr(ip);
  group.imr_interface.s_addr = inet_addr(lip);
  if (setsockopt(sockfd, IPPROTO_IP, 35, (char *)&group, sizeof(group)) < 0) {
   fprintf(stderr, "Parser: Unable to join a group (%s)\n", strerror((*__errno_location ())));
   goto fail;
  }
 } else {
  group_src.imr_multiaddr.s_addr = inet_addr(ip);
  group_src.imr_interface.s_addr = inet_addr(lip);
  group_src.imr_sourceaddr.s_addr = inet_addr(sip);
  if (setsockopt(sockfd, IPPROTO_IP, 39, (char *)&group_src, sizeof(group_src)) < 0) {
   fprintf(stderr, "Parser: Unable to join a group (%s)\n", strerror((*__errno_location ())));
   goto fail;
  }
 }
 return sockfd;
fail:
 return -1;
}

canonical_original_code:
static int msocket(char *ip, char *lip, char *sip, int port)
{
 struct ip_mreq_source group_src;
 struct sockaddr_in sa;
 struct ip_mreq group;
 int sockfd;
 sockfd = socket(2, SOCK_DGRAM, 0);
 if (sockfd < 0) {
  fprintf(stderr, "Parser: Unable to open a socket (%s)\n", strerror((*__errno_location ())));
  goto fail;
 }
 if (fcntl(sockfd, 4, fcntl(sockfd, 3) | 04000) < 0) {
  fprintf(stderr, "Parser: Unable to make a socket nonblocking (%s)\n", strerror((*__errno_location ())));
  goto fail;
 }
 if (socket_setopt(sockfd, 1, 2, 1) < 0) {
  fprintf(stderr, "Parser: Unable to set opt (%s)\n", strerror((*__errno_location ())));
  goto fail;
 }
 sa = (struct sockaddr_in) {
  .sin_family = 2,
  .sin_port = htons(port),
  .sin_addr = (struct in_addr) {
   .s_addr = ((unsigned int) 0x00000000),
  },
 };
 if (bind(sockfd, (struct sockaddr *)&sa, sizeof(struct sockaddr_in)) < 0) {
  fprintf(stderr, "Parser: Unable to bind (%s)\n", strerror((*__errno_location ())));
  goto fail;
 }
 if (!sip) {
  group.imr_multiaddr.s_addr = inet_addr(ip);
  group.imr_interface.s_addr = inet_addr(lip);
  if (setsockopt(sockfd, IPPROTO_IP, 35, (char *)&group, sizeof(group)) < 0) {
   fprintf(stderr, "Parser: Unable to join a group (%s)\n", strerror((*__errno_location ())));
   goto fail;
  }
 } else {
  group_src.imr_multiaddr.s_addr = inet_addr(ip);
  group_src.imr_interface.s_addr = inet_addr(lip);
  group_src.imr_sourceaddr.s_addr = inet_addr(sip);
  if (setsockopt(sockfd, IPPROTO_IP, 39, (char *)&group_src, sizeof(group_src)) < 0) {
   fprintf(stderr, "Parser: Unable to join a group (%s)\n", strerror((*__errno_location ())));
   goto fail;
  }
 }
 return sockfd;
fail:
 return -1;
}

variable_types:
ip
char *

variable_types:
lip
char *

variable_types:
sip
char *

variable_types: port int

variable_types: struct ip_mreq_source { struct in_addr { unsigned int s_addr; } imr_multiaddr; struct in_addr imr_interface; struct in_addr imr_sourceaddr; }

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

variable_types: struct ip_mreq { struct in_addr { unsigned int s_addr; } imr_multiaddr; struct in_addr imr_interface; }

variable_types: sockfd int

user_defined_types: struct ip_mreq_source { struct in_addr imr_multiaddr; struct in_addr imr_interface; struct in_addr imr_sourceaddr; }

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct ip_mreq { struct in_addr imr_multiaddr; struct in_addr imr_interface; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


fstrncpy

decompiled_code:
__int64 __fastcall fstrncpy(__int64 a1, __int64 a2, int a3)
{
__int64 v5; // rsi
__int64 i; // rax
unsigned int v7; // ecx
unsigned __int8 v8; // dl

if ( a3 <= 0 )
return 0;
v5 = (unsigned int)a3;
for ( i = 0LL; i != v5; ++i )
{
v7 = i;
v8 = *(_BYTE *)(a2 + i);
if ( v8 <= 1u )
break;
*(_BYTE *)(a1 + i) = v8;
v7 = i + 1;
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, int a3)
{
__int64 v5; // rsi
__int64 i; // rax
unsigned int v7; // ecx
unsigned __int8 v8; // dl

if ( a3 <= 0 )
return 0;
v5 = (unsigned int)a3;
for ( i = 0LL; i != v5; ++i )
{
v7 = i;
v8 = *(_BYTE *)(a2 + i);
if ( v8 <= 1u )
break;
*(_BYTE *)(a1 + i) = v8;
v7 = i + 1;
}
return v7;
}

original_code:
static int fstrncpy(char *dest, const char *src, int n)
{
 int i;
 for (i = 0; i < n && src[i] != 0x00 && src[i] != 0x01; i++)
  dest[i] = src[i];
 return i;
}

canonical_original_code:
static int fstrncpy(char *dest, char *src, int n)
{
 int i;
 for (i = 0; i < n && src[i] != 0x00 && src[i] != 0x01; i++)
  dest[i] = src[i];
 return i;
}

variable_types:
dest
char *

variable_types:
src
char *

variable_types: n int


fstrcmp

decompiled_code:
_BOOL8 __fastcall fstrcmp(char *s1, char *s2)
{
size_t v2; // rdx
_BOOL8 result; // rax

if ( !s1 )
return 0LL;
v2 = strlen(s1);
result = 1LL;
if ( s2[v2] == 1 )
result = strncmp(s1, s2, v2) != 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(char *s1, char *s2)
{
size_t v2; // rdx
_BOOL8 result; // rax

if ( !s1 )
return 0LL;
v2 = strlen(s1);
result = 1LL;
if ( s2[v2] == 1 )
result = strncmp(s1, s2, v2) != 0;
return result;
}

original_code:
static int fstrcmp(const char *expected, const char *actual)
{
 const char *delim;
 if (!expected)
  return 0;
 delim = actual + strlen(expected);
 if (*delim != 0x01)
  return 1;
 return strncmp(expected, actual, strlen(expected)) != 0;
}

canonical_original_code:
static int fstrcmp(char *expected, char *actual)
{
 char *delim;
 if (!expected)
  return 0;
 delim = actual + strlen(expected);
 if (*delim != 0x01)
  return 1;
 return strncmp(expected, actual, strlen(expected)) != 0;
}

variable_types:
expected
char *

variable_types:
actual
char *

variable_types:
delim
char *


fstrcasecmp

decompiled_code:
_BOOL8 __fastcall fstrcasecmp(char *s1, char *s2)
{
size_t v2; // rdx
_BOOL8 result; // rax

if ( !s1 )
return 0LL;
v2 = strlen(s1);
result = 1LL;
if ( s2[v2] == 1 )
result = strncasecmp(s1, s2, v2) != 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(char *s1, char *s2)
{
size_t v2; // rdx
_BOOL8 result; // rax

if ( !s1 )
return 0LL;
v2 = strlen(s1);
result = 1LL;
if ( s2[v2] == 1 )
result = strncasecmp(s1, s2, v2) != 0;
return result;
}

original_code:
static int fstrcasecmp(const char *expected, const char *actual)
{
 const char *delim;
 if (!expected)
  return 0;
 delim = actual + strlen(expected);
 if (*delim != 0x01)
  return 1;
 return strncasecmp(expected, actual, strlen(expected)) != 0;
}

canonical_original_code:
static int fstrcasecmp(char *expected, char *actual)
{
 char *delim;
 if (!expected)
  return 0;
 delim = actual + strlen(expected);
 if (*delim != 0x01)
  return 1;
 return strncasecmp(expected, actual, strlen(expected)) != 0;
}


decompiled_code:
__int64 __fastcall buffer_get_8(_QWORD *a1)
{
__int64 v1; // rdx
__int64 v2; // rax

v1 = a1[3];
v2 = (*a1)++;
return *(unsigned __int8 *)(v1 + v2);
}

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; } *


decompiled_code:
__int64 __fastcall ouch42_in_message_size(unsigned __int8 a1)
{
__int64 result; // rax

if ( a1 == 85 )
return 47LL;
if ( a1 > 0x55u )
{
result = 0LL;
if ( a1 == 88 )
result = 19LL;
}
else
{
result = 20LL;
if ( a1 != 77 )
{
result = 0LL;
if ( a1 == 79 )
result = 48LL;
}
}
return result;
}

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

if ( a1 == 85 )
return 47LL;
if ( a1 > 0x55u )
{
result = 0LL;
if ( a1 == 88 )
result = 19LL;
}
else
{
result = 20LL;
if ( a1 != 77 )
{
result = 0LL;
if ( a1 == 79 )
result = 48LL;
}
}
return result;
}

original_code:
static unsigned long ouch42_in_message_size(u8 type)
{
 switch (type) {
 case OUCH42_MSG_ENTER_ORDER:
  return sizeof (struct ouch42_msg_enter_order);
 case OUCH42_MSG_REPLACE_ORDER:
  return sizeof (struct ouch42_msg_replace_order);
 case OUCH42_MSG_CANCEL_ORDER:
  return sizeof (struct ouch42_msg_cancel_order);
 case OUCH42_MSG_MODIFY_ORDER:
  return sizeof (struct ouch42_msg_modify_order);
 default:
  break;
 };
 return 0;
}

canonical_original_code:
static unsigned long ouch42_in_message_size(unsigned char type)
{
 switch (type) {
 case OUCH42_MSG_ENTER_ORDER:
  return sizeof (struct ouch42_msg_enter_order);
 case OUCH42_MSG_REPLACE_ORDER:
  return sizeof (struct ouch42_msg_replace_order);
 case OUCH42_MSG_CANCEL_ORDER:
  return sizeof (struct ouch42_msg_cancel_order);
 case OUCH42_MSG_MODIFY_ORDER:
  return sizeof (struct ouch42_msg_modify_order);
 default:
  break;
 };
 return 0;
}

variable_types:
type
unsigned char

user_defined_types: struct ouch42_msg_enter_order { char MessageType; char OrderToken[14]; char BuySellIndicator; unsigned int Shares; char Stock[8]; unsigned int Price; unsigned int TimeInForce; char Firm[4]; char Display; char Capacity; char IntermarketSweepEligibility; unsigned int MinimumQuantity; char CrossType; }

user_defined_types: struct ouch42_msg_replace_order { unsigned char MessageType; char ExistingOrderToken[14]; char ReplacementOrderToken[14]; unsigned int Shares; unsigned int Price; unsigned int TimeInForce; char Display; char IntermarketSweepEligibility; unsigned int MinimumQuantity; }

user_defined_types: struct ouch42_msg_cancel_order { unsigned char MessageType; char OrderToken[14]; unsigned int Shares; }

user_defined_types: struct ouch42_msg_modify_order { unsigned char MessageType; char OrderToken[14]; char BuySellIndicator; unsigned int Shares; }


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

switch ( a1 )
{
case 'A':
result = 66LL;
break;
case 'B':
result = 32LL;
break;
case 'C':
result = 28LL;
break;
case 'D':
result = 37LL;
break;
case 'E':
result = 40LL;
break;
case 'I':
result = 23LL;
break;
case 'J':
result = 24LL;
break;
case 'M':
result = 28LL;
break;
case 'P':
result = 23LL;
break;
case 'S':
result = 10LL;
break;
case 'T':
result = 36LL;
break;
case 'U':
result = 80LL;
break;
default:
result = 0LL;
break;
}
return result;
}

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

switch ( a1 )
{
case 'A':
result = 66LL;
break;
case 'B':
result = 32LL;
break;
case 'C':
result = 28LL;
break;
case 'D':
result = 37LL;
break;
case 'E':
result = 40LL;
break;
case 'I':
result = 23LL;
break;
case 'J':
result = 24LL;
break;
case 'M':
result = 28LL;
break;
case 'P':
result = 23LL;
break;
case 'S':
result = 10LL;
break;
case 'T':
result = 36LL;
break;
case 'U':
result = 80LL;
break;
default:
result = 0LL;
break;
}
return result;
}

original_code:
static unsigned long ouch42_out_message_size(u8 type)
{
 switch (type) {
 case OUCH42_MSG_SYSTEM_EVENT:
  return sizeof (struct ouch42_msg_system_event);
 case OUCH42_MSG_ACCEPTED:
  return sizeof (struct ouch42_msg_accepted);
 case OUCH42_MSG_REPLACED:
  return sizeof (struct ouch42_msg_replaced);
 case OUCH42_MSG_CANCELED:
  return sizeof (struct ouch42_msg_canceled);
 case OUCH42_MSG_AIQ_CANCELED:
  return sizeof (struct ouch42_msg_aiq_canceled);
 case OUCH42_MSG_EXECUTED:
  return sizeof (struct ouch42_msg_executed);
 case OUCH42_MSG_BROKEN_TRADE:
  return sizeof (struct ouch42_msg_broken_trade);
 case OUCH42_MSG_REJECTED:
  return sizeof (struct ouch42_msg_rejected);
 case OUCH42_MSG_CANCEL_PENDING:
  return sizeof (struct ouch42_msg_cancel_pending);
 case OUCH42_MSG_CANCEL_REJECT:
  return sizeof (struct ouch42_msg_cancel_reject);
 case OUCH42_MSG_ORDER_PRIO_UPDATE:
  return sizeof (struct ouch42_msg_order_prio_update);
 case OUCH42_MSG_ORDER_MODIFIED:
  return sizeof (struct ouch42_msg_order_modified);
 default:
  break;
 };
 return 0;
}

canonical_original_code:
static unsigned long ouch42_out_message_size(unsigned char type)
{
 switch (type) {
 case OUCH42_MSG_SYSTEM_EVENT:
  return sizeof (struct ouch42_msg_system_event);
 case OUCH42_MSG_ACCEPTED:
  return sizeof (struct ouch42_msg_accepted);
 case OUCH42_MSG_REPLACED:
  return sizeof (struct ouch42_msg_replaced);
 case OUCH42_MSG_CANCELED:
  return sizeof (struct ouch42_msg_canceled);
 case OUCH42_MSG_AIQ_CANCELED:
  return sizeof (struct ouch42_msg_aiq_canceled);
 case OUCH42_MSG_EXECUTED:
  return sizeof (struct ouch42_msg_executed);
 case OUCH42_MSG_BROKEN_TRADE:
  return sizeof (struct ouch42_msg_broken_trade);
 case OUCH42_MSG_REJECTED:
  return sizeof (struct ouch42_msg_rejected);
 case OUCH42_MSG_CANCEL_PENDING:
  return sizeof (struct ouch42_msg_cancel_pending);
 case OUCH42_MSG_CANCEL_REJECT:
  return sizeof (struct ouch42_msg_cancel_reject);
 case OUCH42_MSG_ORDER_PRIO_UPDATE:
  return sizeof (struct ouch42_msg_order_prio_update);
 case OUCH42_MSG_ORDER_MODIFIED:
  return sizeof (struct ouch42_msg_order_modified);
 default:
  break;
 };
 return 0;
}

user_defined_types: struct ouch42_msg_system_event { unsigned char MessageType; unsigned long Timestamp; char EventCode; }

user_defined_types: struct ouch42_msg_accepted { unsigned char MessageType; unsigned long Timestamp; char OrderToken[14]; char BuySellIndicator; unsigned int Shares; char Stock[8]; unsigned int Price; unsigned int TimeInForce; char Firm[4]; char Display; unsigned long OrderReferenceNumber; char Capacity; char IntermarketSweepEligibility; unsigned int MinimumQuantity; char CrossType; char OrderState; char BBOWeightIndicator; }

user_defined_types: struct ouch42_msg_replaced { unsigned char MessageType; unsigned long Timestamp; char ReplacementOrderToken[14]; char BuySellIndicator; unsigned int Shares; char Stock[8]; unsigned int Price; unsigned int TimeInForce; char Firm[4]; char Display; unsigned long OrderReferenceNumber; char Capacity; char IntermarketSweepEligibility; unsigned int MinimumQuantity; char CrossType; char OrderState; char PreviousOrderToken[14]; char BBOWeightIndicator; }

user_defined_types: struct ouch42_msg_canceled { unsigned char MessageType; unsigned long Timestamp; char OrderToken[14]; unsigned int DecrementShares; char Reason; }

user_defined_types: struct ouch42_msg_aiq_canceled { unsigned char MessageType; unsigned long Timestamp; char OrderToken[14]; unsigned int DecrementShares; char Reason; unsigned int QuantityPreventedFromTrading; unsigned int ExecutionPrice; char LiquidityFlag; }

user_defined_types: struct ouch42_msg_executed { unsigned char MessageType; unsigned long Timestamp; char OrderToken[14]; unsigned int ExecutedShares; unsigned int ExecutionPrice; char LiquidityFlag; unsigned long MatchNumber; }

user_defined_types: struct ouch42_msg_broken_trade { unsigned char MessageType; unsigned long Timestamp; char OrderToken[14]; unsigned long MatchNumber; char Reason; }

user_defined_types: struct ouch42_msg_rejected { unsigned char MessageType; unsigned long Timestamp; char OrderToken[14]; char Reason; }

user_defined_types: struct ouch42_msg_cancel_pending { unsigned char MessageType; unsigned long Timestamp; char OrderToken[14]; }

user_defined_types: struct ouch42_msg_cancel_reject { unsigned char MessageType; unsigned long Timestamp; char OrderToken[14]; }

user_defined_types: struct ouch42_msg_order_prio_update { unsigned char MessageType; unsigned long Timestamp; char OrderToken[14]; unsigned int Price; char Display; unsigned long OrderReferenceNumber; }

user_defined_types: struct ouch42_msg_order_modified { unsigned char MessageType; unsigned long Timestamp; char OrderToken[14]; char BuySellIndicator; unsigned int Shares; }