xread

decompiled_code:
ssize_t __fastcall xread(int fd, void *buf, size_t nbytes)
{
ssize_t v4; // r12
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; // r12
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

repo: libtrading/libtrading

decompiled_code:
ssize_t __fastcall xwrite(int fd, void *buf, size_t n)
{
ssize_t v4; // r12
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; // r12
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;
}

variable_types: fd int

return_type: long


xwritev

decompiled_code:
ssize_t __fastcall xwritev(int fd, struct iovec *iovec, int count)
{
ssize_t v4; // r12
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; // r12
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: struct iovec { void *iov_base; unsigned long iov_len; } *

variable_types: iovcnt int


itoa

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 *

return_type: int


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)
{
unsigned __int8 v1; // di
__int64 result; // rax

v1 = a1 - 65;
result = 0LL;
if ( v1 <= 0x32u )
result = CSWTCH_6[v1];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char a1)
{
unsigned __int8 v1; // di
__int64 result; // rax

v1 = a1 - 65;
result = 0LL;
if ( v1 <= 0x32u )
result = CSWTCH_6[v1];
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

return_type: unsigned long

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:
void __fastcall pitch_message_decode(__int64 *a1)
{
__int64 v2; // rdi
__int64 v3; // r8
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rdx
unsigned __int64 v7; // rcx
_QWORD *v8; // r8

v2 = *a1;
if ( (unsigned __int64)buffer_size_isra_0(v2, a1[1]) > 8 )
{
v4 = buffer_start_isra_0(v2, *(_QWORD *)(v3 + 24));
v5 = pitch_message_size(*(_BYTE *)(v4 + 8));
if ( v5 )
{
if ( v5 + v6 <= v7 )
buffer_advance(v8, v5);
}
}
}

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


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

return_type: unsigned char

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


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

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

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

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:
void __fastcall soupbin3_packet_decode(__int64 *a1, unsigned __int16 a2)
{
__int64 v2; // rax
size_t v3; // rdx
void *v4; // r8

v2 = buffer_start_isra_0(*a1, a1[3]);
memcpy(v4, (const void *)(v2 - 2), v3);
buffer_advance(a1, a2);
}

canonical_decompiled_code:
void __fastcall func7(__int64 *a1, unsigned __int16 a2)
{
__int64 v2; // rax
size_t v3; // rdx
void *v4; // r8

v2 = func6(*a1, a1[3]);
memcpy(v4, (const void *)(v2 - 2), v3);
func2(a1, a2);
}

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

return_type: void

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


decompiled_code:
void __fastcall soupbin3_session_recv(unsigned int *a1)
{
__int64 *v1; // r8
unsigned __int64 v2; // rax
unsigned __int16 v3; // dx
__int64 *v4; // r8

if ( !buffer_size_isra_0(**((_QWORD **)a1 + 1), *(_QWORD *)(*((_QWORD *)a1 + 1) + 8LL)) )
{
buffer_reset(v1);
if ( buffer_xread(*((_QWORD *)a1 + 1), *a1) <= 0 )
return;
v1 = (__int64 *)*((_QWORD *)a1 + 1);
}
buffer_get_be16(v1);
v2 = buffer_remaining_isra_0(*(_QWORD *)(*((_QWORD *)a1 + 1) + 8LL), *(_QWORD *)(*((_QWORD *)a1 + 1) + 16LL));
if ( v2 < v3 )
_assert_fail("0", "lib/proto/soupbin3_session.c", 0x46u, "soupbin3_session_recv");
soupbin3_packet_decode(v4, v3);
}

canonical_decompiled_code:
void __fastcall func9(unsigned int *a1)
{
__int64 *v1; // r8
unsigned __int64 v2; // rax
unsigned __int16 v3; // dx
__int64 *v4; // r8

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

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:
void __fastcall lse_itch_message_decode(__int64 *a1)
{
__int64 v2; // rdi
__int64 v3; // r9
__int64 v4; // rsi
unsigned __int8 v5; // al
unsigned __int64 v6; // rdx
char *v7; // rax
_QWORD *v8; // rcx
__int64 v9; // r8
_QWORD *v10; // r9

v2 = *a1;
if ( buffer_size_isra_0(v2, a1[1]) )
{
v4 = *(_QWORD *)(v3 + 24);
v5 = buffer_peek_8_isra_0(v2, v4);
if ( v6 >= v5 )
{
v7 = (char *)buffer_start_isra_0(v2, v4);
if ( (unsigned int)v9 >= 8 )
{
*v8 = *(_QWORD *)v7;
*(_QWORD *)((char *)v8 + v9 - 8) = *(_QWORD *)&v7[v9 - 8];
qmemcpy(
(void *)((unsigned __int64)(v8 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(v7 - ((char *)v8 - ((unsigned __int64)(v8 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)v9 + (_DWORD)v8 - (((_DWORD)v8 + 8) & 0xFFFFFFF8)) >> 3));
}
else if ( (v9 & 4) != 0 )
{
*(_DWORD *)v8 = *(_DWORD *)v7;
*(_DWORD *)((char *)v8 + v9 - 4) = *(_DWORD *)&v7[v9 - 4];
}
else if ( (_DWORD)v9 )
{
*(_BYTE *)v8 = *v7;
if ( (v9 & 2) != 0 )
*(_WORD *)((char *)v8 + v9 - 2) = *(_WORD *)&v7[v9 - 2];
}
buffer_advance(v10, v9);
}
}
}

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


decompiled_code:
__int64 __fastcall itch40_message_size(char a1)
{
unsigned __int8 v1; // di
__int64 result; // rax

v1 = a1 - 65;
result = 0LL;
if ( v1 <= 0x17u )
result = CSWTCH_7[v1];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char a1)
{
unsigned __int8 v1; // di
__int64 result; // rax

v1 = a1 - 65;
result = 0LL;
if ( v1 <= 0x17u )
result = CSWTCH_7[v1];
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:
void __fastcall itch40_message_decode(__int64 *a1)
{
__int64 v2; // rsi
__int64 v3; // rdi
__int64 v4; // rsi
char v5; // al
unsigned __int64 v6; // rax
unsigned __int64 v7; // rdx
__int64 v8; // r9
__int64 v9; // r12
const void *v10; // rax
size_t v11; // rdx
void *v12; // r8

v2 = a1[1];
v3 = *a1;
if ( buffer_size_isra_0(v3, v2) )
{
v4 = a1[3];
v5 = buffer_peek_8_isra_0(v3, v4);
v6 = itch40_message_size(v5);
v9 = v6;
if ( v6 )
{
if ( v7 >= v6 )
{
v10 = (const void *)buffer_start_isra_0(v8, v4);
memcpy(v12, v10, v11);
buffer_advance(a1, v9);
}
}
}
}

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 func0(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)
{
char **v1; // r8

v1 = &protocols;
if ( strcmp("raw", a1) )
{
v1 = &protocols + 2;
if ( strcmp("fast", a1) )
v1 = 0LL;
}
return v1;
}

canonical_decompiled_code:
char **__fastcall func1(const char *a1)
{
char **v1; // r8

v1 = &protocols;
if ( strcmp("raw", a1) )
{
v1 = &protocols + 2;
if ( strcmp("fast", a1) )
v1 = 0LL;
}
return v1;
}

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; // eax
int v4; // er13
unsigned int v5; // er14
int v6; // eax
int v7; // eax
int *v8; // rax
char *v9; // rax
int *v11; // rax
char *v12; // rax
int *v13; // rax
char *v14; // rax
int *v15; // rax
char *v16; // rax
fd_set v17; // [rsp+0h] [rbp-8A8h] BYREF
char buf[2088]; // [rsp+80h] [rbp-828h] BYREF

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

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

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

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; // er12
unsigned int v8; // eax
__int16 v9; // ax
sa_family_t v10; // dx
in_addr_t v11; // eax
socklen_t v12; // er8
int v13; // edx
in_addr_t v15; // eax
int *v16; // rax
const char *v17; // rsi
char *v18; // rdx
int *v19; // rax
int *v20; // rax
int *v21; // rax
int *v22; // rax
in_addr_t optval; // [rsp+4h] [rbp-44h] BYREF
in_addr_t v24; // [rsp+8h] [rbp-40h]
in_addr_t v25; // [rsp+Ch] [rbp-3Ch]
struct sockaddr addr; // [rsp+10h] [rbp-38h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func6(char *cp, char *a2, char *a3, __int16 a4)
{
int v6; // eax
unsigned int v7; // er12
unsigned int v8; // eax
__int16 v9; // ax
sa_family_t v10; // dx
in_addr_t v11; // eax
socklen_t v12; // er8
int v13; // edx
in_addr_t v15; // eax
int *v16; // rax
const char *v17; // rsi
char *v18; // rdx
int *v19; // rax
int *v20; // rax
int *v21; // rax
int *v22; // rax
in_addr_t optval; // [rsp+4h] [rbp-44h] BYREF
in_addr_t v24; // [rsp+8h] [rbp-40h]
in_addr_t v25; // [rsp+Ch] [rbp-3Ch]
struct sockaddr addr; // [rsp+10h] [rbp-38h] BYREF

v6 = socket(2, 2, 0);
if ( v6 < 0 )
{
v16 = _errno_location();
v17 = "Parser: Unable to open a socket (%s)\n";
v18 = strerror(*v16);
LABEL_11:
v7 = -1;
fprintf(stderr, v17, v18);
return v7;
}
v7 = v6;
v8 = fcntl(v6, 3);
BYTE1(v8) |= 8u;
if ( fcntl(v7, 4, v8) < 0 )
{
v20 = _errno_location();
v17 = "Parser: Unable to make a socket nonblocking (%s)\n";
v18 = strerror(*v20);
goto LABEL_11;
}
if ( func5(v7) < 0 )
{
v19 = _errno_location();
v17 = "Parser: Unable to set opt (%s)\n";
v18 = strerror(*v19);
goto LABEL_11;
}
v9 = func3(a4);
addr = 0LL;
addr.sa_family = v10;
*(_WORD *)addr.sa_data = v9;
if ( bind(v7, &addr, 0x10u) < 0 )
{
v21 = _errno_location();
v17 = "Parser: Unable to bind (%s)\n";
v18 = strerror(*v21);
goto LABEL_11;
}
optval = inet_addr(cp);
if ( a3 )
{
v24 = inet_addr(a2);
v11 = inet_addr(a3);
v12 = 12;
v13 = 39;
v25 = v11;
}
else
{
v15 = inet_addr(a2);
v12 = 8;
v13 = 35;
v24 = v15;
}
if ( setsockopt(v7, 0, v13, &optval, v12) < 0 )
{
v22 = _errno_location();
v17 = "Parser: Unable to join a group (%s)\n";
v18 = strerror(*v22);
goto LABEL_11;
}
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 v3; // rcx
__int64 i; // rax
unsigned int v5; // er8
unsigned __int8 v6; // dl

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

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rcx
__int64 i; // rax
unsigned int v5; // er8
unsigned __int8 v6; // dl

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

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

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

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 ouch42_in_message_size(char a1)
{
unsigned __int8 v1; // di
__int64 result; // rax

v1 = a1 - 77;
result = 0LL;
if ( v1 <= 0xBu )
result = CSWTCH_7[v1];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char a1)
{
unsigned __int8 v1; // di
__int64 result; // rax

v1 = a1 - 77;
result = 0LL;
if ( v1 <= 0xBu )
result = CSWTCH_7[v1];
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)
{
unsigned __int8 v1; // di
__int64 result; // rax

v1 = a1 - 65;
result = 0LL;
if ( v1 <= 0x14u )
result = CSWTCH_9[v1];
return result;
}

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

v1 = a1 - 65;
result = 0LL;
if ( v1 <= 0x14u )
result = CSWTCH_9[v1];
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; }


decompiled_code:
void __fastcall ouch42_in_message_decode(__int64 *a1)
{
const void *v1; // rsi
char v2; // al
__int64 v3; // rax
void *v4; // r8
__int64 v5; // r12

v1 = (const void *)buffer_start_isra_0(*a1, a1[3]);
v2 = buffer_get_8(a1);
v3 = ouch42_in_message_size(v2);
if ( v3 )
{
v5 = v3;
memcpy(v4, v1, v3);
buffer_advance(a1, v5);
}
}

canonical_decompiled_code:
void __fastcall func5(__int64 *a1)
{
const void *v1; // rsi
char v2; // al
__int64 v3; // rax
void *v4; // r8
__int64 v5; // r12

v1 = (const void *)func4(*a1, a1[3]);
v2 = func0(a1);
v3 = func2(v2);
if ( v3 )
{
v5 = v3;
memcpy(v4, v1, v3);
func1(a1, v5);
}
}

original_code:
int ouch42_in_message_decode(struct buffer *buf, struct ouch42_message *msg)
{
 void *start;
 size_t size;
 u8 type;
 start = buffer_start(buf);
 type = buffer_get_8(buf);
 size = ouch42_in_message_size(type);
 if (!size)
  return -1;
 memcpy(msg, start, size);
 buffer_advance(buf, size);
 return 0;
}

canonical_original_code:
int ouch42_in_message_decode(struct buffer *buf, struct ouch42_message *msg)
{
 void *start;
 unsigned long size;
 unsigned char type;
 start = buffer_start(buf);
 type = buffer_get_8(buf);
 size = ouch42_in_message_size(type);
 if (!size)
  return -1;
 memcpy(msg, start, size);
 buffer_advance(buf, size);
 return 0;
}

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

variable_types: struct ouch42_message { char MessageType; } *

variable_types:
start
void *

variable_types:
size
unsigned long


decompiled_code:
void __fastcall ouch42_out_message_decode(__int64 *a1)
{
const void *v1; // rsi
char v2; // al
__int64 v3; // rax
void *v4; // r8
__int64 v5; // r12

v1 = (const void *)buffer_start_isra_0(*a1, a1[3]);
v2 = buffer_get_8(a1);
v3 = ouch42_out_message_size(v2);
if ( v3 )
{
v5 = v3;
memcpy(v4, v1, v3);
buffer_advance(a1, v5);
}
}

canonical_decompiled_code:
void __fastcall func6(__int64 *a1)
{
const void *v1; // rsi
char v2; // al
__int64 v3; // rax
void *v4; // r8
__int64 v5; // r12

v1 = (const void *)func4(*a1, a1[3]);
v2 = func0(a1);
v3 = func3(v2);
if ( v3 )
{
v5 = v3;
memcpy(v4, v1, v3);
func1(a1, v5);
}
}

original_code:
int ouch42_out_message_decode(struct buffer *buf, struct ouch42_message *msg)
{
 void *start;
 size_t size;
 u8 type;
 start = buffer_start(buf);
 type = buffer_get_8(buf);
 size = ouch42_out_message_size(type);
 if (!size)
  return -1;
 memcpy(msg, start, size);
 buffer_advance(buf, size);
 return 0;
}

canonical_original_code:
int ouch42_out_message_decode(struct buffer *buf, struct ouch42_message *msg)
{
 void *start;
 unsigned long size;
 unsigned char type;
 start = buffer_start(buf);
 type = buffer_get_8(buf);
 size = ouch42_out_message_size(type);
 if (!size)
  return -1;
 memcpy(msg, start, size);
 buffer_advance(buf, size);
 return 0;
}

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

user_defined_types: struct ouch42_message { char MessageType; }


decompiled_code:
void __fastcall nyse_taq_msg_decode(__int64 *a1)
{
__int64 v2; // rdi
__int64 v3; // r8
unsigned __int64 v4; // r10
unsigned __int64 v5; // r9
_QWORD *v6; // r8
__int64 v7; // r9

v2 = *a1;
v4 = buffer_size_isra_0(v2, a1[1]);
if ( v4 >= v5 )
{
buffer_start_isra_0(v2, *(_QWORD *)(v3 + 24));
buffer_advance(v6, v7);
}
}

original_code:
void *nyse_taq_msg_decode(struct buffer *buf, size_t size)
{
 void *msg;
 if (buffer_size(buf) < size)
  return ((void *)0);
 msg = buffer_start(buf);
 buffer_advance(buf, size);
 return msg;
}

canonical_original_code:
void *nyse_taq_msg_decode(struct buffer *buf, unsigned long size)
{
 void *msg;
 if (buffer_size(buf) < size)
  return ((void *)0);
 msg = buffer_start(buf);
 buffer_advance(buf, size);
 return msg;
}

variable_types:
msg
void *

return_type: void *


decompiled_code:
void __fastcall field_set_empty(__int64 a1)
{
*(_DWORD *)(a1 + 12) = 2;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
*(_DWORD *)(a1 + 12) = 2;
}

original_code:
static inline void field_set_empty(struct fast_field *field)
{
 field->state = FAST_STATE_EMPTY;
}

variable_types: struct fast_field { enum fast_presence { FAST_PRESENCE_OPTIONAL=0, FAST_PRESENCE_MANDATORY=1 } presence; enum fast_type { FAST_TYPE_INT=0, FAST_TYPE_UINT=1, FAST_TYPE_STRING=2, FAST_TYPE_VECTOR=3, FAST_TYPE_DECIMAL=4, FAST_TYPE_SEQUENCE=5 } type; enum fast_op { FAST_OP_NONE=0, FAST_OP_COPY=1, FAST_OP_INCR=2, FAST_OP_DELTA=3, FAST_OP_DEFAULT=4, FAST_OP_CONSTANT=5 } op; enum fast_state { FAST_STATE_UNDEFINED=0, FAST_STATE_ASSIGNED=1, FAST_STATE_EMPTY=2 } state; enum fast_state { FAST_STATE_UNDEFINED=0, FAST_STATE_ASSIGNED=1, FAST_STATE_EMPTY=2 } state_previous; _Bool has_reset; int flags; char name[32]; int id; union { long int_value; unsigned long uint_value; void *ptr_value; char string_value[256]; char vector_value[256]; struct fast_decimal { struct fast_field *fields; long exp; long mnt; } decimal_value; }; union { long int_reset; unsigned long uint_reset; void *ptr_reset; char string_reset[256]; char vector_reset[256]; struct fast_decimal decimal_reset; }; union { long int_previous; unsigned long uint_previous; void *ptr_previous; char string_previous[256]; char vector_previous[256]; struct fast_decimal decimal_previous; }; } *

user_defined_types: struct fast_field { enum fast_presence presence; enum fast_type type; enum fast_op op; enum fast_state state; enum fast_state state_previous; _Bool has_reset; int flags; char name[32]; int id; union { long int_value; unsigned long uint_value; void *ptr_value; char string_value[256]; char vector_value[256]; struct fast_decimal decimal_value; }; union { long int_reset; unsigned long uint_reset; void *ptr_reset; char string_reset[256]; char vector_reset[256]; struct fast_decimal decimal_reset; }; union { long int_previous; unsigned long uint_previous; void *ptr_previous; char string_previous[256]; char vector_previous[256]; struct fast_decimal decimal_previous; }; }


decompiled_code:
__int64 __fastcall omx_itch186_message_size(char a1)
{
unsigned __int8 v1; // di
__int64 result; // rax

v1 = a1 - 65;
result = 0LL;
if ( v1 <= 0x17u )
result = CSWTCH_7[v1];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(char a1)
{
unsigned __int8 v1; // di
__int64 result; // rax

v1 = a1 - 65;
result = 0LL;
if ( v1 <= 0x17u )
result = CSWTCH_7[v1];
return result;
}

original_code:
unsigned long omx_itch186_message_size(u8 type)
{
 switch (type) {
        case OMX_ITCH186_MSG_SECONDS:
  return sizeof(struct omx_itch186_msg_seconds);
        case OMX_ITCH186_MSG_MILLISECONDS:
  return sizeof(struct omx_itch186_msg_milliseconds);
        case OMX_ITCH186_MSG_SYSTEM_EVENT:
  return sizeof(struct omx_itch186_msg_system_event);
 case OMX_ITCH186_MSG_MARKET_SEGMENT_STATE:
  return sizeof(struct omx_itch186_msg_market_segment_state);
        case OMX_ITCH186_MSG_ORDER_BOOK_DIRECTORY:
  return sizeof(struct omx_itch186_msg_order_book_directory);
        case OMX_ITCH186_MSG_ORDER_BOOK_TRADING_ACTION:
  return sizeof(struct omx_itch186_msg_order_book_trading_action);
        case OMX_ITCH186_MSG_ADD_ORDER:
  return sizeof(struct omx_itch186_msg_add_order);
        case OMX_ITCH186_MSG_ADD_ORDER_MPID:
  return sizeof(struct omx_itch186_msg_add_order_mpid);
        case OMX_ITCH186_MSG_ORDER_EXECUTED:
  return sizeof(struct omx_itch186_msg_order_executed);
        case OMX_ITCH186_MSG_ORDER_EXECUTED_WITH_PRICE:
  return sizeof(struct omx_itch186_msg_order_executed_with_price);
        case OMX_ITCH186_MSG_ORDER_CANCEL:
  return sizeof(struct omx_itch186_msg_order_cancel);
        case OMX_ITCH186_MSG_ORDER_DELETE:
  return sizeof(struct omx_itch186_msg_order_delete);
        case OMX_ITCH186_MSG_TRADE:
  return sizeof(struct omx_itch186_msg_trade);
        case OMX_ITCH186_MSG_CROSS_TRADE:
  return sizeof(struct omx_itch186_msg_cross_trade);
        case OMX_ITCH186_MSG_BROKEN_TRADE:
  return sizeof(struct omx_itch186_msg_broken_trade);
        case OMX_ITCH186_MSG_NOII:
  return sizeof(struct omx_itch186_msg_noii);
 default:
  break;
 };
 return 0;
}

canonical_original_code:
unsigned long omx_itch186_message_size(unsigned char type)
{
 switch (type) {
        case OMX_ITCH186_MSG_SECONDS:
  return sizeof(struct omx_itch186_msg_seconds);
        case OMX_ITCH186_MSG_MILLISECONDS:
  return sizeof(struct omx_itch186_msg_milliseconds);
        case OMX_ITCH186_MSG_SYSTEM_EVENT:
  return sizeof(struct omx_itch186_msg_system_event);
 case OMX_ITCH186_MSG_MARKET_SEGMENT_STATE:
  return sizeof(struct omx_itch186_msg_market_segment_state);
        case OMX_ITCH186_MSG_ORDER_BOOK_DIRECTORY:
  return sizeof(struct omx_itch186_msg_order_book_directory);
        case OMX_ITCH186_MSG_ORDER_BOOK_TRADING_ACTION:
  return sizeof(struct omx_itch186_msg_order_book_trading_action);
        case OMX_ITCH186_MSG_ADD_ORDER:
  return sizeof(struct omx_itch186_msg_add_order);
        case OMX_ITCH186_MSG_ADD_ORDER_MPID:
  return sizeof(struct omx_itch186_msg_add_order_mpid);
        case OMX_ITCH186_MSG_ORDER_EXECUTED:
  return sizeof(struct omx_itch186_msg_order_executed);
        case OMX_ITCH186_MSG_ORDER_EXECUTED_WITH_PRICE:
  return sizeof(struct omx_itch186_msg_order_executed_with_price);
        case OMX_ITCH186_MSG_ORDER_CANCEL:
  return sizeof(struct omx_itch186_msg_order_cancel);
        case OMX_ITCH186_MSG_ORDER_DELETE:
  return sizeof(struct omx_itch186_msg_order_delete);
        case OMX_ITCH186_MSG_TRADE:
  return sizeof(struct omx_itch186_msg_trade);
        case OMX_ITCH186_MSG_CROSS_TRADE:
  return sizeof(struct omx_itch186_msg_cross_trade);
        case OMX_ITCH186_MSG_BROKEN_TRADE:
  return sizeof(struct omx_itch186_msg_broken_trade);
        case OMX_ITCH186_MSG_NOII:
  return sizeof(struct omx_itch186_msg_noii);
 default:
  break;
 };
 return 0;
}

user_defined_types: struct omx_itch186_msg_seconds { unsigned char MessageType; char Second[5]; }

user_defined_types: struct omx_itch186_msg_milliseconds { unsigned char MessageType; char Millisecond[3]; }

user_defined_types: struct omx_itch186_msg_system_event { unsigned char MessageType; char EventCode; }

user_defined_types: struct omx_itch186_msg_market_segment_state { unsigned char MessageType; char MarketSegmentID[3]; char EventCode; }

user_defined_types: struct omx_itch186_msg_order_book_directory { unsigned char MessageType; char OrderBook[6]; char Symbol[16]; char ISIN[12]; char FinancialProduct[3]; char TradingCurrency[3]; char MIC[4]; char MarketSegmentID[3]; char NoteCodes[8]; char RoundLotSize[9]; }

user_defined_types: struct omx_itch186_msg_order_book_trading_action { unsigned char MessageType; char OrderBook[6]; char TradingState; char Reserved; char Reason[4]; }

user_defined_types: struct omx_itch186_msg_add_order { unsigned char MessageType; char OrderReferenceNumber[9]; char BuySellIndicator; char Quantity[9]; char OrderBook[6]; char Price[10]; }

user_defined_types: struct omx_itch186_msg_add_order_mpid { unsigned char MessageType; char OrderReferenceNumber[9]; char BuySellIndicator; char Quantity[9]; char OrderBook[6]; char Price[10]; char Attribution[4]; }

user_defined_types: struct omx_itch186_msg_order_executed { unsigned char MessageType; char OrderReferenceNumber[9]; char ExecutedQuantity[9]; char MatchNumber[9]; char OwnerParticipantID[4]; char CounterpartyParticipantID[4]; }

user_defined_types: struct omx_itch186_msg_order_executed_with_price { unsigned char MessageType; char OrderReferenceNumber[9]; char ExecutedQuantity[9]; char MatchNumber[9]; char Printable; char TradePrice[10]; char OwnerParticipantID[4]; char CounterpartyParticipantID[4]; }

user_defined_types: struct omx_itch186_msg_order_cancel { unsigned char MessageType; char OrderReferenceNumber[9]; char CanceledQuantity[9]; }

user_defined_types: struct omx_itch186_msg_order_delete { unsigned char MessageType; char OrderReferenceNumber[9]; }

user_defined_types: struct omx_itch186_msg_trade { unsigned char MessageType; char OrderReferenceNumber[9]; char TradeType; char Quantity[9]; char OrderBook[6]; char MatchNumber[9]; char TradePrice[10]; char BuyerParticipantID[4]; char SellerParticipantID[4]; }

user_defined_types: struct omx_itch186_msg_cross_trade { unsigned char MessageType; char Quantity[9]; char OrderBook[6]; char CrossPrice[10]; char MatchNumber[9]; char CrossType; char NumberOfTrades[10]; }

user_defined_types: struct omx_itch186_msg_broken_trade { unsigned char MessageType; char MatchNumber[9]; }

user_defined_types: struct omx_itch186_msg_noii { unsigned char MessageType; char PairedQuantity[9]; char ImbalanceQuantity[9]; char ImbalanceDirection; char OrderBook[6]; char EquilibriumPrice[10]; char CrossType; char BestBidPrice[10]; char BestBidQuantity[9]; char BestAskPrice[10]; char BestAskQuantity[9]; }


decompiled_code:
void __fastcall omx_itch186_message_decode(__int64 *a1)
{
__int64 v2; // rdi
__int64 v3; // rax
unsigned __int64 v4; // rbx
char v5; // al
unsigned __int64 v6; // rax
__int64 v7; // r8

v2 = *a1;
v3 = buffer_size_isra_0(v2, a1[1]);
if ( v3 )
{
v4 = v3;
v5 = buffer_peek_8_isra_0(v2, a1[3]);
v6 = omx_itch186_message_size(v5);
if ( v6 )
{
if ( v4 >= v6 )
{
buffer_start_isra_0(*a1, a1[3]);
buffer_advance(a1, v7);
}
}
}
}

original_code:
struct omx_itch186_message *omx_itch186_message_decode(struct buffer *buf)
{
 size_t available;
 size_t size;
 void *start;
 u8 type;
 available = buffer_size(buf);
 if (!available)
  return ((void *)0);
 type = buffer_peek_8(buf);
 size = omx_itch186_message_size(type);
 if (!size)
  return ((void *)0);
 if (available < size)
  return ((void *)0);
 start = buffer_start(buf);
 buffer_advance(buf, size);
 return start;
}

canonical_original_code:
struct omx_itch186_message *omx_itch186_message_decode(struct buffer *buf)
{
 unsigned long available;
 unsigned long size;
 void *start;
 unsigned char type;
 available = buffer_size(buf);
 if (!available)
  return ((void *)0);
 type = buffer_peek_8(buf);
 size = omx_itch186_message_size(type);
 if (!size)
  return ((void *)0);
 if (available < size)
  return ((void *)0);
 start = buffer_start(buf);
 buffer_advance(buf, size);
 return start;
}

variable_types:
available
unsigned long

return_type: struct omx_itch186_message { unsigned char MessageType; } *

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


decompiled_code:
__int64 __fastcall itch41_message_size(char a1)
{
unsigned __int8 v1; // di
__int64 result; // rax

v1 = a1 - 65;
result = 0LL;
if ( v1 <= 0x18u )
result = CSWTCH_7[v1];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char a1)
{
unsigned __int8 v1; // di
__int64 result; // rax

v1 = a1 - 65;
result = 0LL;
if ( v1 <= 0x18u )
result = CSWTCH_7[v1];
return result;
}

original_code:
static unsigned long itch41_message_size(u8 type)
{
 switch (type) {
        case ITCH41_MSG_TIMESTAMP_SECONDS:
  return sizeof(struct itch41_msg_timestamp_seconds);
        case ITCH41_MSG_SYSTEM_EVENT:
  return sizeof(struct itch41_msg_system_event);
        case ITCH41_MSG_STOCK_DIRECTORY:
  return sizeof(struct itch41_msg_stock_directory);
        case ITCH41_MSG_STOCK_TRADING_ACTION:
  return sizeof(struct itch41_msg_stock_trading_action);
        case ITCH41_MSG_REG_SHO_RESTRICTION:
  return sizeof(struct itch41_msg_reg_sho_restriction);
        case ITCH41_MSG_MARKET_PARTICIPANT_POS:
  return sizeof(struct itch41_msg_market_participant_pos);
        case ITCH41_MSG_ADD_ORDER:
  return sizeof(struct itch41_msg_add_order);
        case ITCH41_MSG_ADD_ORDER_MPID:
  return sizeof(struct itch41_msg_add_order_mpid);
        case ITCH41_MSG_ORDER_EXECUTED:
  return sizeof(struct itch41_msg_order_executed);
        case ITCH41_MSG_ORDER_EXECUTED_WITH_PRICE:
  return sizeof(struct itch41_msg_order_executed_with_price);
        case ITCH41_MSG_ORDER_CANCEL:
  return sizeof(struct itch41_msg_order_cancel);
        case ITCH41_MSG_ORDER_DELETE:
  return sizeof(struct itch41_msg_order_delete);
        case ITCH41_MSG_ORDER_REPLACE:
  return sizeof(struct itch41_msg_order_replace);
        case ITCH41_MSG_TRADE:
  return sizeof(struct itch41_msg_trade);
        case ITCH41_MSG_CROSS_TRADE:
  return sizeof(struct itch41_msg_cross_trade);
        case ITCH41_MSG_BROKEN_TRADE:
  return sizeof(struct itch41_msg_broken_trade);
        case ITCH41_MSG_NOII:
  return sizeof(struct itch41_msg_noii);
 case ITCH41_MSG_RPII:
  return sizeof(struct itch41_msg_rpii);
 default:
  break;
 };
 return 0;
}

canonical_original_code:
static unsigned long itch41_message_size(unsigned char type)
{
 switch (type) {
        case ITCH41_MSG_TIMESTAMP_SECONDS:
  return sizeof(struct itch41_msg_timestamp_seconds);
        case ITCH41_MSG_SYSTEM_EVENT:
  return sizeof(struct itch41_msg_system_event);
        case ITCH41_MSG_STOCK_DIRECTORY:
  return sizeof(struct itch41_msg_stock_directory);
        case ITCH41_MSG_STOCK_TRADING_ACTION:
  return sizeof(struct itch41_msg_stock_trading_action);
        case ITCH41_MSG_REG_SHO_RESTRICTION:
  return sizeof(struct itch41_msg_reg_sho_restriction);
        case ITCH41_MSG_MARKET_PARTICIPANT_POS:
  return sizeof(struct itch41_msg_market_participant_pos);
        case ITCH41_MSG_ADD_ORDER:
  return sizeof(struct itch41_msg_add_order);
        case ITCH41_MSG_ADD_ORDER_MPID:
  return sizeof(struct itch41_msg_add_order_mpid);
        case ITCH41_MSG_ORDER_EXECUTED:
  return sizeof(struct itch41_msg_order_executed);
        case ITCH41_MSG_ORDER_EXECUTED_WITH_PRICE:
  return sizeof(struct itch41_msg_order_executed_with_price);
        case ITCH41_MSG_ORDER_CANCEL:
  return sizeof(struct itch41_msg_order_cancel);
        case ITCH41_MSG_ORDER_DELETE:
  return sizeof(struct itch41_msg_order_delete);
        case ITCH41_MSG_ORDER_REPLACE:
  return sizeof(struct itch41_msg_order_replace);
        case ITCH41_MSG_TRADE:
  return sizeof(struct itch41_msg_trade);
        case ITCH41_MSG_CROSS_TRADE:
  return sizeof(struct itch41_msg_cross_trade);
        case ITCH41_MSG_BROKEN_TRADE:
  return sizeof(struct itch41_msg_broken_trade);
        case ITCH41_MSG_NOII:
  return sizeof(struct itch41_msg_noii);
 case ITCH41_MSG_RPII:
  return sizeof(struct itch41_msg_rpii);
 default:
  break;
 };
 return 0;
}

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

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

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

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

user_defined_types: struct itch41_msg_reg_sho_restriction { unsigned char MessageType; unsigned int TimestampNanoseconds; char Stock[8]; char RegSHOAction; }

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

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

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

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

user_defined_types: struct itch41_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 itch41_msg_order_cancel { unsigned char MessageType; unsigned int TimestampNanoseconds; unsigned long OrderReferenceNumber; unsigned int CanceledShares; }

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

user_defined_types: struct itch41_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 itch41_msg_trade { unsigned char MessageType; unsigned int TimestampNanoseconds; unsigned long OrderReferenceNumber; char BuySellIndicator; unsigned int Shares; char Stock[8]; unsigned int Price; unsigned long MatchNumber; }

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

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

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

user_defined_types: struct itch41_msg_rpii { unsigned char MessageType; unsigned int TimestampNanoseconds; char Stock[8]; char InterestFlag; }


decompiled_code:
void __fastcall itch41_message_decode(__int64 *a1)
{
__int64 v1; // rsi
__int64 v2; // rdi
__int64 v3; // r8
__int64 v4; // rsi
char v5; // al
unsigned __int64 v6; // rax
unsigned __int64 v7; // rdx
__int64 v8; // r10
_QWORD *v9; // r8
__int64 v10; // r9

v1 = a1[1];
v2 = *a1;
if ( buffer_size_isra_0(v2, v1) )
{
v4 = *(_QWORD *)(v3 + 24);
v5 = buffer_peek_8_isra_0(v2, v4);
v6 = itch41_message_size(v5);
if ( v6 )
{
if ( v7 >= v6 )
{
buffer_start_isra_0(v8, v4);
buffer_advance(v9, v10);
}
}
}
}

original_code:
struct itch41_message *itch41_message_decode(struct buffer *buf)
{
 size_t available;
 size_t size;
 void *start;
 u8 type;
 available = buffer_size(buf);
 if (!available)
  return ((void *)0);
 type = buffer_peek_8(buf);
 size = itch41_message_size(type);
 if (!size)
  return ((void *)0);
 if (available < size)
  return ((void *)0);
 start = buffer_start(buf);
 buffer_advance(buf, size);
 return start;
}

canonical_original_code:
struct itch41_message *itch41_message_decode(struct buffer *buf)
{
 unsigned long available;
 unsigned long size;
 void *start;
 unsigned char type;
 available = buffer_size(buf);
 if (!available)
  return ((void *)0);
 type = buffer_peek_8(buf);
 size = itch41_message_size(type);
 if (!size)
  return ((void *)0);
 if (available < size)
  return ((void *)0);
 start = buffer_start(buf);
 buffer_advance(buf, size);
 return start;
}

return_type: struct itch41_message { unsigned char MessageType; } *

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


decompiled_code:
char **__fastcall get_builtin_cmd(const char *a1)
{
bool v1; // zf
char **result; // rax

v1 = strcmp(a1, builtins) == 0;
result = &builtins;
if ( !v1 )
result = 0LL;
return result;
}

canonical_decompiled_code:
char **__fastcall func0(const char *a1)
{
bool v1; // zf
char **result; // rax

v1 = strcmp(a1, builtins) == 0;
result = &builtins;
if ( !v1 )
result = 0LL;
return result;
}

original_code:
static struct builtin_cmd *get_builtin_cmd(const char *name)
{
 unsigned int i;
 for (i = 0; i < (sizeof(builtins) / sizeof((builtins)[0])); i++) {
  struct builtin_cmd *cmd = &builtins[i];
  if (strcmp(name, cmd->name) == 0)
   return cmd;
 }
 return ((void *)0);
}

canonical_original_code:
static struct builtin_cmd *get_builtin_cmd(char *name)
{
 unsigned int i;
 for (i = 0; i < (sizeof(builtins) / sizeof((builtins)[0])); i++) {
  struct builtin_cmd *cmd = &builtins[i];
  if (strcmp(name, cmd->name) == 0)
   return cmd;
 }
 return ((void *)0);
}

variable_types:
name
char *

variable_types:
i
unsigned int

variable_types: struct builtin_cmd { char *name; int (*cmd_fn)(int argc, char *argv[]); } *


usage

decompiled_code:
void __noreturn usage()
{
fprintf(stderr, "\n usage: %s COMMAND [ARGS]\n\n The commands are:\n check Check market data file\n\n", program);
exit(1);
}

canonical_decompiled_code:
void __noreturn func1()
{
fprintf(stderr, "\n usage: %s COMMAND [ARGS]\n\n The commands are:\n check Check market data file\n\n", program);
exit(1);
}

original_code:
static void usage(void)
{
 fprintf(stderr, "\n usage: %s COMMAND [ARGS]\n" "\n The commands are:\n" "   check     Check market data file\n" "\n", program);
 exit(1);
}

canonical_original_code:
static void usage()
{
 fprintf(stderr, "\n usage: %s COMMAND [ARGS]\n" "\n The commands are:\n" "   check     Check market data file\n" "\n", program);
 exit(1);
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char **v3; // rax

program = _xpg_basename((char *)*argv);
if ( argc <= 1 || (v3 = get_builtin_cmd(argv[1])) == 0LL )
usage();
return ((__int64 (__fastcall *)(_QWORD, const char **))v3[1])((unsigned int)(argc - 1), argv + 1);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char **v3; // rax

program = _xpg_basename((char *)*argv);
if ( argc <= 1 || (v3 = func0(argv[1])) == 0LL )
func1();
return ((__int64 (__fastcall *)(_QWORD, const char **))v3[1])((unsigned int)(argc - 1), argv + 1);
}

original_code:
int main(int argc, char *argv[])
{
 struct builtin_cmd *cmd;
 program = __xpg_basename(argv[0]);
 if (argc < 2)
  usage();
 cmd = get_builtin_cmd(argv[1]);
 if (!cmd)
  usage();
 return cmd->cmd_fn(argc - 1, argv + 1);
}

variable_types: argc int

variable_types:
argv
char *[]

user_defined_types: struct builtin_cmd { char *name; int (*cmd_fn)(int argc, char *argv[]); }


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


decompiled_code:
__int64 __fastcall buffer_get_le16(__int64 *a1)
{
int v1; // esi

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

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

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

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

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

variable_types:
x
unsigned short


decompiled_code:
void __fastcall boe_message_decode(__int64 *a1)
{
__int64 v1; // rbx
unsigned __int64 v2; // r8
void *v3; // r9
const void *v4; // r10
size_t v5; // rdx

buffer_start_isra_0(*a1, a1[3]);
if ( (unsigned __int16)buffer_get_le16(a1) == 0xBABA )
{
v1 = (unsigned __int16)buffer_get_le16(a1);
v5 = v1 + 2;
if ( v1 + 2 > v2 )
v5 = v2;
memcpy(v3, v4, v5);
buffer_advance(a1, v1 - 2);
}
}

canonical_decompiled_code:
void __fastcall func4(__int64 *a1)
{
__int64 v1; // rbx
unsigned __int64 v2; // r8
void *v3; // r9
const void *v4; // r10
size_t v5; // rdx

func3(*a1, a1[3]);
if ( (unsigned __int16)func1(a1) == 0xBABA )
{
v1 = (unsigned __int16)func1(a1);
v5 = v1 + 2;
if ( v1 + 2 > v2 )
v5 = v2;
memcpy(v3, v4, v5);
func2(a1, v1 - 2);
}
}

original_code:
int boe_message_decode(struct buffer *buf, struct boe_message *msg, size_t size)
{
 u16 magic, len;
 void *start;
 size_t count;
 start = buffer_start(buf);
 magic = buffer_get_le16(buf);
 if (magic != 0xBABA)
  return -1;
 len = buffer_get_le16(buf);
 count = sizeof(u16) + len;
 if (count > size)
  count = size;
 memcpy(msg, start, count);
 buffer_advance(buf, len - sizeof(u16));
 return 0;
}

canonical_original_code:
int boe_message_decode(struct buffer *buf, struct boe_message *msg, unsigned long size)
{
 unsigned short magic; unsigned short len;
 void *start;
 unsigned long count;
 start = buffer_start(buf);
 magic = buffer_get_le16(buf);
 if (magic != 0xBABA)
  return -1;
 len = buffer_get_le16(buf);
 count = sizeof(u16) + len;
 if (count > size)
  count = size;
 memcpy(msg, start, count);
 buffer_advance(buf, len - sizeof(u16));
 return 0;
}

variable_types: struct boe_message { struct boe_header { unsigned short StartOfMessage; unsigned short MessageLength; unsigned char MessageType; unsigned char MatchingUnit; unsigned int SequenceNumber; } header; } *

variable_types:
magic
unsigned short

variable_types:
len
unsigned short

variable_types:
count
unsigned long

user_defined_types: struct boe_message { struct boe_header header; }


decompiled_code:
__int64 do_trader()
{
__int64 v0; // rax
__int64 v1; // r13
unsigned int v2; // er12
double *v3; // rbp
FILE *v5; // rcx
int v6; // [rsp+Ch] [rbp-4Ch] BYREF
double v7; // [rsp+10h] [rbp-48h] BYREF
double v8[8]; // [rsp+18h] [rbp-40h] BYREF

v0 = fix_session_new();
v1 = v0;
if ( !v0 )
{
v3 = 0LL;
v2 = -1;
fwrite("FIX session cannot be created\n", 1uLL, 0x1EuLL, stderr);
goto LABEL_10;
}
v2 = fix_session_logon(v0);
if ( v2 )
{
v3 = 0LL;
fwrite("Trader Logon failed\n", 1uLL, 0x14uLL, stderr);
goto LABEL_10;
}
fwrite("Trader Logged on\n", 1uLL, 0x11uLL, stdout);
v3 = (double *)calloc(0x20uLL, 0x10uLL);
if ( !v3 )
{
fwrite("Cannot allocate memory\n", 1uLL, 0x17uLL, stderr);
goto LABEL_10;
}
do
{
while ( 1 )
{
do
fwrite("Buy/Sell/Quit (1/2/0): ", 1uLL, 0x17uLL, stdout);
while ( scanf("%d", &v6) != 1 );
if ( v6 == 1 )
{
*(_QWORD *)v3 = 0x300000036LL;
*((_QWORD *)v3 + 1) = "1";
goto LABEL_12;
}
if ( v6 != 2 )
break;
*(_QWORD *)v3 = 0x300000036LL;
*((_QWORD *)v3 + 1) = "2";
LABEL_12:
fwrite("Price: ", 1uLL, 7uLL, stdout);
if ( scanf("%lf", &v7) == 1 && v7 > 0.0 )
{
v5 = stdout;
v3[3] = v7;
*((_QWORD *)v3 + 2) = 0x10000002CLL;
fwrite("Quantity: ", 1uLL, 0xAuLL, v5);
if ( scanf("%lf", v8) == 1 && v8[0] > 0.0 )
{
v3[5] = v8[0];
*((_QWORD *)v3 + 4) = 0x100000026LL;
fix_session_new_order_single(v1, v3, 3LL);
}
}
}
}
while ( v6 );
v2 = fix_session_logout(v1, 0LL);
if ( v2 )
fwrite("Trader logout failed\n", 1uLL, 0x15uLL, stderr);
else
fwrite("Trader logged out\n", 1uLL, 0x12uLL, stdout);
LABEL_10:
fix_session_free(v1);
free(v3);
return v2;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rax
__int64 v1; // r13
unsigned int v2; // er12
double *v3; // rbp
FILE *v5; // rcx
int v6; // [rsp+Ch] [rbp-4Ch] BYREF
double v7; // [rsp+10h] [rbp-48h] BYREF
double v8[8]; // [rsp+18h] [rbp-40h] BYREF

v0 = fix_session_new();
v1 = v0;
if ( !v0 )
{
v3 = 0LL;
v2 = -1;
fwrite("FIX session cannot be created\n", 1uLL, 0x1EuLL, stderr);
goto LABEL_10;
}
v2 = fix_session_logon(v0);
if ( v2 )
{
v3 = 0LL;
fwrite("Trader Logon failed\n", 1uLL, 0x14uLL, stderr);
goto LABEL_10;
}
fwrite("Trader Logged on\n", 1uLL, 0x11uLL, stdout);
v3 = (double *)calloc(0x20uLL, 0x10uLL);
if ( !v3 )
{
fwrite("Cannot allocate memory\n", 1uLL, 0x17uLL, stderr);
goto LABEL_10;
}
do
{
while ( 1 )
{
do
fwrite("Buy/Sell/Quit (1/2/0): ", 1uLL, 0x17uLL, stdout);
while ( scanf("%d", &v6) != 1 );
if ( v6 == 1 )
{
*(_QWORD *)v3 = 0x300000036LL;
*((_QWORD *)v3 + 1) = "1";
goto LABEL_12;
}
if ( v6 != 2 )
break;
*(_QWORD *)v3 = 0x300000036LL;
*((_QWORD *)v3 + 1) = "2";
LABEL_12:
fwrite("Price: ", 1uLL, 7uLL, stdout);
if ( scanf("%lf", &v7) == 1 && v7 > 0.0 )
{
v5 = stdout;
v3[3] = v7;
*((_QWORD *)v3 + 2) = 0x10000002CLL;
fwrite("Quantity: ", 1uLL, 0xAuLL, v5);
if ( scanf("%lf", v8) == 1 && v8[0] > 0.0 )
{
v3[5] = v8[0];
*((_QWORD *)v3 + 4) = 0x100000026LL;
fix_session_new_order_single(v1, v3, 3LL);
}
}
}
}
while ( v6 );
v2 = fix_session_logout(v1, 0LL);
if ( v2 )
fwrite("Trader logout failed\n", 1uLL, 0x15uLL, stderr);
else
fwrite("Trader logged out\n", 1uLL, 0x12uLL, stdout);
LABEL_10:
fix_session_free(v1);
free(v3);
return v2;
}

original_code:
static int do_trader(struct fix_session_cfg *cfg)
{
 struct fix_session *session = ((void *)0);
 struct fix_field *fields = ((void *)0);
 double price, qty;
 int ret = -1;
 int nr = 0;
 int side;
 session = fix_session_new(cfg);
 if (!session) {
  fprintf(stderr, "FIX session cannot be created\n");
  goto exit;
 }
 ret = fix_session_logon(session);
 if (ret) {
  fprintf(stderr, "Trader Logon failed\n");
  goto exit;
 }
 fprintf(stdout, "Trader Logged on\n");
 fields = calloc(32, sizeof(struct fix_field));
 if (!fields) {
  fprintf(stderr, "Cannot allocate memory\n");
  goto exit;
 }
 while (1) {
  nr = 0;
  fprintf(stdout, "Buy/Sell/Quit (1/2/0): ");
  if (scanf("%d", &side) != 1)
   continue;
  if (side == 1)
   fields[nr++] = (struct fix_field) { .tag = Side, .type = FIX_TYPE_STRING, { .string_value = "1" }, };
  else if (side == 2)
   fields[nr++] = (struct fix_field) { .tag = Side, .type = FIX_TYPE_STRING, { .string_value = "2" }, };
  else if (side == 0)
   break;
  else
   continue;
  fprintf(stdout, "Price: ");
  if (scanf("%lf", &price) != 1)
   continue;
  if (price <= 0)
   continue;
  fields[nr++] = (struct fix_field) { .tag = Price, .type = FIX_TYPE_FLOAT, { .float_value = price }, };
  fprintf(stdout, "Quantity: ");
  if (scanf("%lf", &qty) != 1)
   continue;
  if (qty <= 0)
   continue;
  fields[nr++] = (struct fix_field) { .tag = OrderQty, .type = FIX_TYPE_FLOAT, { .float_value = qty }, };
  fix_session_new_order_single(session, fields, nr);
 }
 ret = fix_session_logout(session, ((void *)0));
 if (!ret)
  fprintf(stdout, "Trader logged out\n");
 else
  fprintf(stderr, "Trader logout failed\n");
exit:
 fix_session_free(session);
 free(fields);
 return ret;
}

canonical_original_code:
static int do_trader(struct fix_session_cfg *cfg)
{
 struct fix_session *session = ((void *)0);
 struct fix_field *fields = ((void *)0);
 double price; double qty;
 int ret = -1;
 int nr = 0;
 int side;
 session = fix_session_new(cfg);
 if (!session) {
  fprintf(stderr, "FIX session cannot be created\n");
  goto exit;
 }
 ret = fix_session_logon(session);
 if (ret) {
  fprintf(stderr, "Trader Logon failed\n");
  goto exit;
 }
 fprintf(stdout, "Trader Logged on\n");
 fields = calloc(32, sizeof(struct fix_field));
 if (!fields) {
  fprintf(stderr, "Cannot allocate memory\n");
  goto exit;
 }
 while (1) {
  nr = 0;
  fprintf(stdout, "Buy/Sell/Quit (1/2/0): ");
  if (scanf("%d", &side) != 1)
   continue;
  if (side == 1)
   fields[nr++] = (struct fix_field) { .tag = Side, .type = FIX_TYPE_STRING, { .string_value = "1" }, };
  else if (side == 2)
   fields[nr++] = (struct fix_field) { .tag = Side, .type = FIX_TYPE_STRING, { .string_value = "2" }, };
  else if (side == 0)
   break;
  else
   continue;
  fprintf(stdout, "Price: ");
  if (scanf("%lf", &price) != 1)
   continue;
  if (price <= 0)
   continue;
  fields[nr++] = (struct fix_field) { .tag = Price, .type = FIX_TYPE_FLOAT, { .float_value = price }, };
  fprintf(stdout, "Quantity: ");
  if (scanf("%lf", &qty) != 1)
   continue;
  if (qty <= 0)
   continue;
  fields[nr++] = (struct fix_field) { .tag = OrderQty, .type = FIX_TYPE_FLOAT, { .float_value = qty }, };
  fix_session_new_order_single(session, fields, nr);
 }
 ret = fix_session_logout(session, ((void *)0));
 if (!ret)
  fprintf(stdout, "Trader logged out\n");
 else
  fprintf(stderr, "Trader logout failed\n");
exit:
 fix_session_free(session);
 free(fields);
 return ret;
}

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

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

variable_types: price double

variable_types: qty double

variable_types: ret int

variable_types: nr int

variable_types: side int

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

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_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_dialect { enum fix_version version; enum fix_type (*tag_type)(int tag); }

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


usage

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

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

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

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