decompiled_code:
__int64 __fastcall ouch42_in_message_decode(_QWORD *a1, void *a2)
{
const void *v2; // r13
unsigned __int8 v3; // al
__int64 v4; // rax
__int64 v5; // rbp

v2 = (const void *)buffer_start(a1);
v3 = buffer_get_8(a1);
v4 = ouch42_in_message_size(v3);
if ( !v4 )
return 0xFFFFFFFFLL;
v5 = v4;
memcpy(a2, v2, v4);
buffer_advance(a1, v5);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1, void *a2)
{
const void *v2; // r13
unsigned __int8 v3; // al
__int64 v4; // rax
__int64 v5; // rbp

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

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 ouch42_message { char MessageType; } *

variable_types:
start
void *

variable_types:
size
unsigned long

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


repo: libtrading/libtrading

decompiled_code:
__int64 __fastcall ouch42_out_message_decode(_QWORD *a1, void *a2)
{
const void *v2; // r13
char v3; // al
__int64 v4; // rax
__int64 v5; // rbp

v2 = (const void *)buffer_start(a1);
v3 = buffer_get_8(a1);
v4 = ouch42_out_message_size(v3);
if ( !v4 )
return 0xFFFFFFFFLL;
v5 = v4;
memcpy(a2, v2, v4);
buffer_advance(a1, v5);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1, void *a2)
{
const void *v2; // r13
char v3; // al
__int64 v4; // rax
__int64 v5; // rbp

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

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

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

variable_types:
type
unsigned char

return_type: int

user_defined_types: struct ouch42_message { char MessageType; }


decompiled_code:
__int64 __fastcall nyse_taq_msg_decode(_QWORD *a1, unsigned __int64 a2)
{
__int64 v2; // r12

v2 = 0LL;
if ( buffer_size(a1) >= a2 )
{
v2 = buffer_start(a1);
buffer_advance(a1, a2);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1, unsigned __int64 a2)
{
__int64 v2; // r12

v2 = 0LL;
if ( func2(a1) >= a2 )
{
v2 = func0(a1);
func1(a1, a2);
}
return v2;
}

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 func1(__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; }; } *

return_type: void

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)
{
__int64 result; // rax

switch ( a1 )
{
case 'A':
result = 36LL;
break;
case 'B':
result = 10LL;
break;
case 'C':
result = 47LL;
break;
case 'D':
result = 10LL;
break;
case 'E':
result = 36LL;
break;
case 'F':
result = 40LL;
break;
case 'H':
result = 13LL;
break;
case 'I':
result = 75LL;
break;
case 'M':
result = 4LL;
break;
case 'O':
result = 5LL;
break;
case 'P':
result = 53LL;
break;
case 'Q':
result = 46LL;
break;
case 'R':
result = 65LL;
break;
case 'S':
result = 2LL;
break;
case 'T':
result = 6LL;
break;
case 'X':
result = 19LL;
break;
default:
result = 0LL;
break;
}
return result;
}

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

switch ( a1 )
{
case 'A':
result = 36LL;
break;
case 'B':
result = 10LL;
break;
case 'C':
result = 47LL;
break;
case 'D':
result = 10LL;
break;
case 'E':
result = 36LL;
break;
case 'F':
result = 40LL;
break;
case 'H':
result = 13LL;
break;
case 'I':
result = 75LL;
break;
case 'M':
result = 4LL;
break;
case 'O':
result = 5LL;
break;
case 'P':
result = 53LL;
break;
case 'Q':
result = 46LL;
break;
case 'R':
result = 65LL;
break;
case 'S':
result = 2LL;
break;
case 'T':
result = 6LL;
break;
case 'X':
result = 19LL;
break;
default:
result = 0LL;
break;
}
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;
}

return_type: unsigned long

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:
__int64 __fastcall omx_itch186_message_decode(_QWORD *a1)
{
__int64 v1; // rax
__int64 v2; // r13
unsigned __int64 v3; // rbp
char v4; // al
unsigned __int64 v5; // rax
__int64 v6; // r12

v1 = buffer_size(a1);
v2 = 0LL;
if ( v1 )
{
v3 = v1;
v4 = buffer_peek_8(a1);
v5 = omx_itch186_message_size(v4);
v6 = v5;
if ( v3 >= v5 && v5 )
{
v2 = buffer_start(a1);
buffer_advance(a1, v6);
}
else
{
v2 = 0LL;
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1)
{
__int64 v1; // rax
__int64 v2; // r13
unsigned __int64 v3; // rbp
char v4; // al
unsigned __int64 v5; // rax
__int64 v6; // r12

v1 = func3(a1);
v2 = 0LL;
if ( v1 )
{
v3 = v1;
v4 = func0(a1);
v5 = func4(v4);
v6 = v5;
if ( v3 >= v5 && v5 )
{
v2 = func1(a1);
func2(a1, v6);
}
else
{
v2 = 0LL;
}
}
return v2;
}

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)
{
__int64 result; // rax

switch ( a1 )
{
case 'A':
result = 30LL;
break;
case 'B':
result = 13LL;
break;
case 'C':
result = 30LL;
break;
case 'D':
result = 13LL;
break;
case 'E':
result = 25LL;
break;
case 'F':
result = 34LL;
break;
case 'H':
result = 19LL;
break;
case 'I':
result = 44LL;
break;
case 'L':
result = 20LL;
break;
case 'N':
result = 14LL;
break;
case 'P':
result = 38LL;
break;
case 'Q':
result = 34LL;
break;
case 'R':
result = 20LL;
break;
case 'S':
result = 6LL;
break;
case 'T':
result = 5LL;
break;
case 'U':
result = 29LL;
break;
case 'X':
result = 17LL;
break;
case 'Y':
result = 14LL;
break;
default:
result = 0LL;
break;
}
return result;
}

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

switch ( a1 )
{
case 'A':
result = 30LL;
break;
case 'B':
result = 13LL;
break;
case 'C':
result = 30LL;
break;
case 'D':
result = 13LL;
break;
case 'E':
result = 25LL;
break;
case 'F':
result = 34LL;
break;
case 'H':
result = 19LL;
break;
case 'I':
result = 44LL;
break;
case 'L':
result = 20LL;
break;
case 'N':
result = 14LL;
break;
case 'P':
result = 38LL;
break;
case 'Q':
result = 34LL;
break;
case 'R':
result = 20LL;
break;
case 'S':
result = 6LL;
break;
case 'T':
result = 5LL;
break;
case 'U':
result = 29LL;
break;
case 'X':
result = 17LL;
break;
case 'Y':
result = 14LL;
break;
default:
result = 0LL;
break;
}
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:
__int64 __fastcall itch41_message_decode(_QWORD *a1)
{
__int64 v1; // rax
unsigned __int64 v2; // rbp
char v3; // al
unsigned __int64 v4; // rax
__int64 v5; // r12
__int64 v6; // rbp

v1 = buffer_size(a1);
if ( !v1 )
return 0LL;
v2 = v1;
v3 = buffer_peek_8(a1);
v4 = itch41_message_size(v3);
v5 = v4;
if ( v2 < v4 || !v4 )
return 0LL;
v6 = buffer_start(a1);
buffer_advance(a1, v5);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1)
{
__int64 v1; // rax
unsigned __int64 v2; // rbp
char v3; // al
unsigned __int64 v4; // rax
__int64 v5; // r12
__int64 v6; // rbp

v1 = func3(a1);
if ( !v1 )
return 0LL;
v2 = v1;
v3 = func0(a1);
v4 = func4(v3);
v5 = v4;
if ( v2 < v4 || !v4 )
return 0LL;
v6 = func1(a1);
func2(a1, v5);
return v6;
}

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 )
usage();
v3 = get_builtin_cmd(argv[1]);
if ( !v3 )
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 )
func1();
v3 = func0(argv[1]);
if ( !v3 )
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[]); }


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

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

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

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

return_type: unsigned char


decompiled_code:
__int64 __fastcall buffer_get_le16(_QWORD *a1)
{
unsigned __int8 v1; // bl

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

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
unsigned __int8 v1; // bl

v1 = 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

return_type: unsigned short


decompiled_code:
__int64 __fastcall boe_message_decode(_QWORD *a1, void *a2, unsigned __int64 a3)
{
const void *v4; // r14
__int64 v5; // rbp
size_t v6; // rdx

v4 = (const void *)buffer_start(a1);
if ( (unsigned __int16)buffer_get_le16(a1) != 0xBABA )
return 0xFFFFFFFFLL;
v5 = (unsigned __int16)buffer_get_le16(a1);
v6 = v5 + 2;
if ( v5 + 2 > a3 )
v6 = a3;
memcpy(a2, v4, v6);
buffer_advance(a1, v5 - 2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, void *a2, unsigned __int64 a3)
{
const void *v4; // r14
__int64 v5; // rbp
size_t v6; // rdx

v4 = (const void *)func2(a1);
if ( (unsigned __int16)func1(a1) != 0xBABA )
return 0xFFFFFFFFLL;
v5 = (unsigned __int16)func1(a1);
v6 = v5 + 2;
if ( v5 + 2 > a3 )
v6 = a3;
memcpy(a2, v4, v6);
func3(a1, v5 - 2);
return 0LL;
}

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; // rbp
unsigned int v2; // er12
_DWORD *v3; // rbx
double v5; // xmm0_8
double v6; // xmm0_8
int v7; // [rsp+Ch] [rbp-3Ch] BYREF
double v8; // [rsp+10h] [rbp-38h] BYREF
double v9[6]; // [rsp+18h] [rbp-30h] BYREF

v0 = fix_session_new();
v1 = v0;
if ( !v0 )
{
fwrite("FIX session cannot be created\n", 1uLL, 0x1EuLL, stderr);
v3 = 0LL;
v2 = -1;
goto LABEL_12;
}
v2 = fix_session_logon(v0);
if ( v2 )
{
fwrite("Trader Logon failed\n", 1uLL, 0x14uLL, stderr);
v3 = 0LL;
goto LABEL_12;
}
fwrite("Trader Logged on\n", 1uLL, 0x11uLL, stdout);
v3 = calloc(0x20uLL, 0x10uLL);
if ( !v3 )
{
fwrite("Cannot allocate memory\n", 1uLL, 0x17uLL, stderr);
goto LABEL_12;
}
do
{
while ( 1 )
{
do
fwrite("Buy/Sell/Quit (1/2/0): ", 1uLL, 0x17uLL, stdout);
while ( scanf("%d", &v7) != 1 );
if ( v7 == 1 )
{
*v3 = 54;
v3[1] = 3;
*((_QWORD *)v3 + 1) = "1";
goto LABEL_15;
}
if ( v7 != 2 )
break;
*v3 = 54;
v3[1] = 3;
*((_QWORD *)v3 + 1) = "2";
LABEL_15:
fwrite("Price: ", 1uLL, 7uLL, stdout);
if ( scanf("%lf", v9) == 1 )
{
v5 = v9[0];
if ( v9[0] > 0.0 )
{
v3[4] = 44;
v3[5] = 1;
*((double *)v3 + 3) = v5;
fwrite("Quantity: ", 1uLL, 0xAuLL, stdout);
if ( scanf("%lf", &v8) == 1 )
{
v6 = v8;
if ( v8 > 0.0 )
{
v3[8] = 38;
v3[9] = 1;
*((double *)v3 + 5) = v6;
fix_session_new_order_single(v1, v3, 3LL);
}
}
}
}
}
}
while ( v7 );
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_12:
fix_session_free(v1);
free(v3);
return v2;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rax
__int64 v1; // rbp
unsigned int v2; // er12
_DWORD *v3; // rbx
double v5; // xmm0_8
double v6; // xmm0_8
int v7; // [rsp+Ch] [rbp-3Ch] BYREF
double v8; // [rsp+10h] [rbp-38h] BYREF
double v9[6]; // [rsp+18h] [rbp-30h] BYREF

v0 = fix_session_new();
v1 = v0;
if ( !v0 )
{
fwrite("FIX session cannot be created\n", 1uLL, 0x1EuLL, stderr);
v3 = 0LL;
v2 = -1;
goto LABEL_12;
}
v2 = fix_session_logon(v0);
if ( v2 )
{
fwrite("Trader Logon failed\n", 1uLL, 0x14uLL, stderr);
v3 = 0LL;
goto LABEL_12;
}
fwrite("Trader Logged on\n", 1uLL, 0x11uLL, stdout);
v3 = calloc(0x20uLL, 0x10uLL);
if ( !v3 )
{
fwrite("Cannot allocate memory\n", 1uLL, 0x17uLL, stderr);
goto LABEL_12;
}
do
{
while ( 1 )
{
do
fwrite("Buy/Sell/Quit (1/2/0): ", 1uLL, 0x17uLL, stdout);
while ( scanf("%d", &v7) != 1 );
if ( v7 == 1 )
{
*v3 = 54;
v3[1] = 3;
*((_QWORD *)v3 + 1) = "1";
goto LABEL_15;
}
if ( v7 != 2 )
break;
*v3 = 54;
v3[1] = 3;
*((_QWORD *)v3 + 1) = "2";
LABEL_15:
fwrite("Price: ", 1uLL, 7uLL, stdout);
if ( scanf("%lf", v9) == 1 )
{
v5 = v9[0];
if ( v9[0] > 0.0 )
{
v3[4] = 44;
v3[5] = 1;
*((double *)v3 + 3) = v5;
fwrite("Quantity: ", 1uLL, 0xAuLL, stdout);
if ( scanf("%lf", &v8) == 1 )
{
v6 = v8;
if ( v8 > 0.0 )
{
v3[8] = 38;
v3[9] = 1;
*((double *)v3 + 5) = v6;
fix_session_new_order_single(v1, v3, 3LL);
}
}
}
}
}
}
while ( v7 );
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_12:
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);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
char *v4; // r14
const void **v5; // r13
int v6; // eax
struct hostent *v7; // rax
struct hostent *v8; // r12
int v9; // er14
int v10; // ebp
int v11; // er15
__int16 v12; // ax
int v13; // ebx
int *v15; // rax
const char *v16; // rax
int v17; // eax
const char *v18; // rdx
struct sockaddr dest; // [rsp+0h] [rbp-D8h] BYREF
__int64 v20[14]; // [rsp+10h] [rbp-C8h] BYREF
int fd; // [rsp+80h] [rbp-58h]

program = (__int64)_xpg_basename((char *)*argv);
v3 = 0;
v4 = 0LL;
v5 = (const void **)"h:p:";
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "h:p:");
if ( v6 == -1 )
break;
if ( v6 == 104 )
{
v4 = optarg;
}
else
{
if ( v6 != 112 )
usage();
v3 = atoi(optarg);
}
}
if ( !v3 || !v4 )
usage();
fix_session_cfg_init(v20);
v20[4] = 0x454449534C4C4553LL;
v20[5] = 0LL;
v20[6] = 0LL;
v20[7] = 0LL;
v20[0] = 0x45444953595542LL;
v20[1] = 0LL;
v20[2] = 0LL;
v20[3] = 0LL;
v20[13] = (__int64)&fix_dialects + 64;
v7 = gethostbyname(v4);
v8 = v7;
if ( !v7 )
{
v15 = _h_errno_location();
v16 = hstrerror(*v15);
error((int)"Unable to look up %s (%s)", (int)v4, v16);
goto LABEL_21;
}
v5 = (const void **)v7->h_addr_list;
if ( *v5 )
{
v9 = 0;
do
{
v10 = socket(v8->h_addrtype, 1, 6);
fd = v10;
if ( v10 < 0 )
{
LABEL_21:
v9 = *_errno_location();
}
else
{
v11 = v8->h_addrtype;
v12 = _bswap_16(v3);
*(_QWORD *)&dest.sa_data[6] = 0LL;
*(_QWORD *)&dest.sa_family = (unsigned __int16)v11;
*(_WORD *)dest.sa_data = v12;
memcpy(&dest.sa_data[2], *v5, v8->h_length);
if ( connect(v10, &dest, 0x10u) >= 0 )
break;
v9 = *_errno_location();
close(fd);
fd = -1;
}
++v5;
}
while ( *v5 );
}
else
{
v9 = 0;
}
if ( fd < 0 )
{
v17 = (unsigned int)strerror(v9);
error((int)"Unable to connect to a socket (%s)", v17, v18);
goto LABEL_27;
}
if ( socket_setopt(fd, 6, 1, 1) < 0 )
{
LABEL_27:
do_die("%s: cannot set socket option TCP_NODELAY", "main");
goto LABEL_28;
}
v13 = do_trader(v20);
shutdown(fd, 2);
if ( close(fd) < 0 )
{
LABEL_28:
do_die("%s: close", "main");
JUMPOUT(0x5E2LL);
}
return v13;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
char *v4; // r14
const void **v5; // r13
int v6; // eax
struct hostent *v7; // rax
struct hostent *v8; // r12
int v9; // er14
int v10; // ebp
int v11; // er15
__int16 v12; // ax
int v13; // ebx
int *v15; // rax
const char *v16; // rax
int v17; // eax
const char *v18; // rdx
struct sockaddr dest; // [rsp+0h] [rbp-D8h] BYREF
__int64 v20[14]; // [rsp+10h] [rbp-C8h] BYREF
int fd; // [rsp+80h] [rbp-58h]

program = (__int64)_xpg_basename((char *)*argv);
v3 = 0;
v4 = 0LL;
v5 = (const void **)"h:p:";
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "h:p:");
if ( v6 == -1 )
break;
if ( v6 == 104 )
{
v4 = optarg;
}
else
{
if ( v6 != 112 )
func0();
v3 = atoi(optarg);
}
}
if ( !v3 || !v4 )
func0();
fix_session_cfg_init(v20);
v20[4] = 0x454449534C4C4553LL;
v20[5] = 0LL;
v20[6] = 0LL;
v20[7] = 0LL;
v20[0] = 0x45444953595542LL;
v20[1] = 0LL;
v20[2] = 0LL;
v20[3] = 0LL;
v20[13] = (__int64)&fix_dialects + 64;
v7 = gethostbyname(v4);
v8 = v7;
if ( !v7 )
{
v15 = _h_errno_location();
v16 = hstrerror(*v15);
error((int)"Unable to look up %s (%s)", (int)v4, v16);
goto LABEL_21;
}
v5 = (const void **)v7->h_addr_list;
if ( *v5 )
{
v9 = 0;
do
{
v10 = socket(v8->h_addrtype, 1, 6);
fd = v10;
if ( v10 < 0 )
{
LABEL_21:
v9 = *_errno_location();
}
else
{
v11 = v8->h_addrtype;
v12 = func1(v3);
*(_QWORD *)&dest.sa_data[6] = 0LL;
*(_QWORD *)&dest.sa_family = (unsigned __int16)v11;
*(_WORD *)dest.sa_data = v12;
memcpy(&dest.sa_data[2], *v5, v8->h_length);
if ( connect(v10, &dest, 0x10u) >= 0 )
break;
v9 = *_errno_location();
close(fd);
fd = -1;
}
++v5;
}
while ( *v5 );
}
else
{
v9 = 0;
}
if ( fd < 0 )
{
v17 = (unsigned int)strerror(v9);
error((int)"Unable to connect to a socket (%s)", v17, v18);
goto LABEL_27;
}
if ( func2(fd, 6, 1, 1) < 0 )
{
LABEL_27:
do_die("%s: cannot set socket option TCP_NODELAY", "main");
goto LABEL_28;
}
v13 = func3(v20);
shutdown(fd, 2);
if ( close(fd) < 0 )
{
LABEL_28:
do_die("%s: close", "main");
JUMPOUT(0x5E2LL);
}
return v13;
}

original_code:
int main(int argc, char *argv[])
{
 struct fix_session_cfg cfg;
 const char *host = ((void *)0);
 struct sockaddr_in sa;
 int saved_errno = 0;
 struct hostent *he;
 int port = 0;
 int ret = 0;
 char **ap;
 int opt;
 program = __xpg_basename(argv[0]);
 while ((opt = getopt(argc, argv, "h:p:")) != -1) {
  switch (opt) {
  case 'p':
   port = atoi(optarg);
   break;
  case 'h':
   host = optarg;
   break;
  default:
   usage();
  }
 }
 if (!port || !host)
  usage();
 fix_session_cfg_init(&cfg);
 strncpy(cfg.target_comp_id, "SELLSIDE", (sizeof(cfg.target_comp_id) / sizeof((cfg.target_comp_id)[0])));
 strncpy(cfg.sender_comp_id, "BUYSIDE", (sizeof(cfg.sender_comp_id) / sizeof((cfg.sender_comp_id)[0])));
 cfg.dialect = &fix_dialects[FIX_4_4];
 he = gethostbyname(host);
 if (!he)
  error("Unable to look up %s (%s)", host, hstrerror((*__h_errno_location ())));
 for (ap = he->h_addr_list; *ap; ap++) {
  cfg.sockfd = socket(he->h_addrtype, SOCK_STREAM, IPPROTO_TCP);
  if (cfg.sockfd < 0) {
   saved_errno = (*__errno_location ());
   continue;
  }
  sa = (struct sockaddr_in) {
   .sin_family = he->h_addrtype,
   .sin_port = htons(port),
  };
  memcpy(&sa.sin_addr, *ap, he->h_length);
  if (connect(cfg.sockfd, (const struct sockaddr *)&sa, sizeof(struct sockaddr_in)) < 0) {
   saved_errno = (*__errno_location ());
   close(cfg.sockfd);
   cfg.sockfd = -1;
   continue;
  }
  break;
 }
 if (cfg.sockfd < 0)
  error("Unable to connect to a socket (%s)", strerror(saved_errno));
 if (socket_setopt(cfg.sockfd, IPPROTO_TCP, 1, 1) < 0)
  do_die("%s: " "cannot set socket option TCP_NODELAY", __func__);
 ret = do_trader(&cfg);
 shutdown(cfg.sockfd, SHUT_RDWR);
 if (close(cfg.sockfd) < 0)
  do_die("%s: " "close", __func__);
 return ret;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 struct fix_session_cfg cfg;
 char *host = ((void *)0);
 struct sockaddr_in sa;
 int saved_errno = 0;
 struct hostent *he;
 int port = 0;
 int ret = 0;
 char **ap;
 int opt;
 program = __xpg_basename(argv[0]);
 while ((opt = getopt(argc, argv, "h:p:")) != -1) {
  switch (opt) {
  case 'p':
   port = atoi(optarg);
   break;
  case 'h':
   host = optarg;
   break;
  default:
   usage();
  }
 }
 if (!port || !host)
  usage();
 fix_session_cfg_init(&cfg);
 strncpy(cfg.target_comp_id, "SELLSIDE", (sizeof(cfg.target_comp_id) / sizeof((cfg.target_comp_id)[0])));
 strncpy(cfg.sender_comp_id, "BUYSIDE", (sizeof(cfg.sender_comp_id) / sizeof((cfg.sender_comp_id)[0])));
 cfg.dialect = &fix_dialects[FIX_4_4];
 he = gethostbyname(host);
 if (!he)
  error("Unable to look up %s (%s)", host, hstrerror((*__h_errno_location ())));
 for (ap = he->h_addr_list; *ap; ap++) {
  cfg.sockfd = socket(he->h_addrtype, SOCK_STREAM, IPPROTO_TCP);
  if (cfg.sockfd < 0) {
   saved_errno = (*__errno_location ());
   continue;
  }
  sa = (struct sockaddr_in) {
   .sin_family = he->h_addrtype,
   .sin_port = htons(port),
  };
  memcpy(&sa.sin_addr, *ap, he->h_length);
  if (connect(cfg.sockfd, (struct sockaddr *)&sa, sizeof(struct sockaddr_in)) < 0) {
   saved_errno = (*__errno_location ());
   close(cfg.sockfd);
   cfg.sockfd = -1;
   continue;
  }
  break;
 }
 if (cfg.sockfd < 0)
  error("Unable to connect to a socket (%s)", strerror(saved_errno));
 if (socket_setopt(cfg.sockfd, IPPROTO_TCP, 1, 1) < 0)
  do_die("%s: " "cannot set socket option TCP_NODELAY", __func__);
 ret = do_trader(&cfg);
 shutdown(cfg.sockfd, SHUT_RDWR);
 if (close(cfg.sockfd) < 0)
  do_die("%s: " "close", __func__);
 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:
host
char *

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 hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

variable_types: port int

variable_types:
ap
char **

variable_types: opt int

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 sockaddr { unsigned short sa_family; char sa_data[14]; }


decompiled_code:
void __fastcall buffer_munmap(void *ptr)
{
munmap(*((void **)ptr + 3), *((_QWORD *)ptr + 2));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
munmap(*((void **)ptr + 3), *((_QWORD *)ptr + 2));
free(ptr);
}

original_code:
void buffer_munmap(struct buffer *buf)
{
 munmap(buf->data, buf->capacity);
 free(buf);
}

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


decompiled_code:
__int64 __fastcall xdp_message_decode(_QWORD *a1, void *a2, size_t a3)
{
size_t v4; // r13
const void *v5; // rax

if ( !buffer_size(a1) )
return 0xFFFFFFFFLL;
v4 = (unsigned __int16)buffer_peek_le16(a1);
if ( v4 > a3 )
return 0xFFFFFFFFLL;
v5 = (const void *)buffer_start(a1);
memcpy(a2, v5, v4);
buffer_advance(a1, v4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, void *a2, size_t a3)
{
size_t v4; // r13
const void *v5; // rax

if ( !func3(a1) )
return 0xFFFFFFFFLL;
v4 = (unsigned __int16)func0(a1);
if ( v4 > a3 )
return 0xFFFFFFFFLL;
v5 = (const void *)func1(a1);
memcpy(a2, v5, v4);
func2(a1, v4);
return 0LL;
}

original_code:
int xdp_message_decode(struct buffer *buf, struct xdp_message *msg, size_t size)
{
 size_t available;
 u16 msg_size;
 available = buffer_size(buf);
 if (!available)
  return -1;
 msg_size = buffer_peek_le16(buf);
 if (msg_size > size)
  return -1;
 memcpy(msg, buffer_start(buf), msg_size);
 buffer_advance(buf, msg_size);
 return 0;
}

canonical_original_code:
int xdp_message_decode(struct buffer *buf, struct xdp_message *msg, unsigned long size)
{
 unsigned long available;
 unsigned short msg_size;
 available = buffer_size(buf);
 if (!available)
  return -1;
 msg_size = buffer_peek_le16(buf);
 if (msg_size > size)
  return -1;
 memcpy(msg, buffer_start(buf), msg_size);
 buffer_advance(buf, msg_size);
 return 0;
}

variable_types: struct xdp_message { unsigned short MsgSize; unsigned short MsgType; } *

variable_types:
size
unsigned long

variable_types:
available
unsigned long


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

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

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

variable_types: signum int


DEBUG

repo: licko/mywork

decompiled_code:
int DEBUG(char *format, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-1D0h] BYREF
char s[256]; // [rsp+20h] [rbp-1B8h] BYREF

if ( g_iDebug > 0 )
{
memset(s, 0, sizeof(s));
va_start(arg, format);
vsnprintf(s, 0xFFuLL, format, arg);
result = printf("%s", s);
}
return result;
}

canonical_decompiled_code:
int func0(char *format, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-1D0h] BYREF
char s[256]; // [rsp+20h] [rbp-1B8h] BYREF

if ( g_iDebug > 0 )
{
memset(s, 0, sizeof(s));
va_start(arg, format);
vsnprintf(s, 0xFFuLL, format, arg);
result = printf("%s", s);
}
return result;
}

original_code:
static inline void DEBUG(char *str, ...)
{
 if(g_iDebug > 0)
 {
  va_list va;
  char szBuff[256];
  memset(szBuff, 0, sizeof(szBuff));
  __builtin_va_start(va,str);
  vsnprintf(szBuff, sizeof(szBuff)-1, str, va);
  __builtin_va_end(va);
  printf("%s", szBuff);
 }
    return ;
}

canonical_original_code:
static inline void DEBUG(char *str, ...)
{
 if(g_iDebug > 0)
 {
  __builtin_va_list va;
  char szBuff[256];
  memset(szBuff, 0, sizeof(szBuff));
  __builtin_va_start(va,str);
  vsnprintf(szBuff, sizeof(szBuff)-1, str, va);
  __builtin_va_end(va);
  printf("%s", szBuff);
 }
    return ;
}

variable_types:
str
char *

variable_types:
szBuff
char [256]


decompiled_code:
void __fastcall __noreturn monitor_debug(int msqid)
{
__int64 v2; // r12
int v3; // er15
int v4; // ebp
int v5; // eax
int v6; // ebx
key_t v7; // ebx
int v8; // er15
int i; // er15
int v10; // eax
FILE *v11; // rax
int j; // er15
FILE *v13; // rax
__int64 v14; // [rsp+0h] [rbp-88h] BYREF
char file[8]; // [rsp+8h] [rbp-80h] BYREF
__int64 v16; // [rsp+10h] [rbp-78h]
__int64 v17; // [rsp+18h] [rbp-70h]
__int64 v18; // [rsp+20h] [rbp-68h]
__int64 v19; // [rsp+28h] [rbp-60h]
__int64 v20; // [rsp+30h] [rbp-58h]
__int16 v21; // [rsp+38h] [rbp-50h]
char nptr[8]; // [rsp+3Ah] [rbp-4Eh] BYREF
__int16 v23; // [rsp+42h] [rbp-46h]

v2 = (unsigned int)getpid();
printf("pid = %d\n", v2);
*(_QWORD *)nptr = 0LL;
v23 = 0;
*(_QWORD *)file = 0LL;
v16 = 0LL;
v17 = 0LL;
v18 = 0LL;
v19 = 0LL;
v20 = 0LL;
v21 = 0;
if ( dup(1) < 0 )
DEBUG("PID = %d :fd_stdout dup", (unsigned int)v2);
if ( dup(2) < 0 )
DEBUG("PID = %d :fd_stderr dup", (unsigned int)v2);
v3 = 0;
v4 = -1;
while ( 1 )
{
do
{
while ( msgrcv(msqid, &v14, 0x3CuLL, (int)v2, 0) >= 0 )
{
v5 = atoi(nptr);
v6 = v5;
if ( v5 == 1 )
{
g_iDebug = 1;
v8 = 0;
if ( file[0] )
{
while ( 1 )
{
v10 = open(file, 1090);
v4 = v10;
if ( v8 > 4 || v10 >= 0 )
break;
DEBUG("PID = %d :flie open", (unsigned int)v2);
++v8;
}
if ( dup2(v10, 1) < 0 )
DEBUG("PID = %d :fd to STDOUT_FILENO dup2", (unsigned int)v2);
if ( dup2(v4, 2) < 0 )
DEBUG("PID = %d :fd to STDOUT_FILENO dup2", (unsigned int)v2);
setbuf(stdout, 0LL);
setbuf(stderr, 0LL);
}
else
{
close(1);
close(2);
for ( i = 0; ; ++i )
{
v11 = freopen("/dev/tty", "w", stdout);
if ( i > 4 || v11 )
break;
DEBUG("PID = %d :freopen stdout\n", (unsigned int)v2);
}
for ( j = 0; ; ++j )
{
v13 = freopen("/dev/tty", "w", stderr);
if ( j > 4 || v13 )
break;
DEBUG("PID = %d :freopen stderr\n", (unsigned int)v2);
}
}
DEBUG("*****************PID = %d debug*********************\n", (unsigned int)v2);
v3 = v6;
}
else if ( !v5 && v3 )
{
g_iDebug = 0;
close(v4);
v3 = 0;
if ( msgctl(msqid, 0, 0LL) < 0 )
DEBUG("PID = %d :msgctl", (unsigned int)v2);
}
}
DEBUG("PID = %d :msgrcv", (unsigned int)v2);
}
while ( *_errno_location() != 43 );
v7 = ftok("/root", 97);
if ( v7 == -1 )
DEBUG("PID = %d :fork", (unsigned int)v2);
msqid = msgget(v7, 950);
if ( msqid == -1 )
DEBUG("PID = %d :msgget", (unsigned int)v2);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func1(int msqid)
{
__int64 v2; // r12
int v3; // er15
int v4; // ebp
int v5; // eax
int v6; // ebx
key_t v7; // ebx
int v8; // er15
int i; // er15
int v10; // eax
FILE *v11; // rax
int j; // er15
FILE *v13; // rax
__int64 v14; // [rsp+0h] [rbp-88h] BYREF
char file[8]; // [rsp+8h] [rbp-80h] BYREF
__int64 v16; // [rsp+10h] [rbp-78h]
__int64 v17; // [rsp+18h] [rbp-70h]
__int64 v18; // [rsp+20h] [rbp-68h]
__int64 v19; // [rsp+28h] [rbp-60h]
__int64 v20; // [rsp+30h] [rbp-58h]
__int16 v21; // [rsp+38h] [rbp-50h]
char nptr[8]; // [rsp+3Ah] [rbp-4Eh] BYREF
__int16 v23; // [rsp+42h] [rbp-46h]

v2 = (unsigned int)getpid();
printf("pid = %d\n", v2);
*(_QWORD *)nptr = 0LL;
v23 = 0;
*(_QWORD *)file = 0LL;
v16 = 0LL;
v17 = 0LL;
v18 = 0LL;
v19 = 0LL;
v20 = 0LL;
v21 = 0;
if ( dup(1) < 0 )
func0("PID = %d :fd_stdout dup", (unsigned int)v2);
if ( dup(2) < 0 )
func0("PID = %d :fd_stderr dup", (unsigned int)v2);
v3 = 0;
v4 = -1;
while ( 1 )
{
do
{
while ( msgrcv(msqid, &v14, 0x3CuLL, (int)v2, 0) >= 0 )
{
v5 = atoi(nptr);
v6 = v5;
if ( v5 == 1 )
{
g_iDebug = 1;
v8 = 0;
if ( file[0] )
{
while ( 1 )
{
v10 = open(file, 1090);
v4 = v10;
if ( v8 > 4 || v10 >= 0 )
break;
func0("PID = %d :flie open", (unsigned int)v2);
++v8;
}
if ( dup2(v10, 1) < 0 )
func0("PID = %d :fd to STDOUT_FILENO dup2", (unsigned int)v2);
if ( dup2(v4, 2) < 0 )
func0("PID = %d :fd to STDOUT_FILENO dup2", (unsigned int)v2);
setbuf(stdout, 0LL);
setbuf(stderr, 0LL);
}
else
{
close(1);
close(2);
for ( i = 0; ; ++i )
{
v11 = freopen("/dev/tty", "w", stdout);
if ( i > 4 || v11 )
break;
func0("PID = %d :freopen stdout\n", (unsigned int)v2);
}
for ( j = 0; ; ++j )
{
v13 = freopen("/dev/tty", "w", stderr);
if ( j > 4 || v13 )
break;
func0("PID = %d :freopen stderr\n", (unsigned int)v2);
}
}
func0("*****************PID = %d debug*********************\n", (unsigned int)v2);
v3 = v6;
}
else if ( !v5 && v3 )
{
g_iDebug = 0;
close(v4);
v3 = 0;
if ( msgctl(msqid, 0, 0LL) < 0 )
func0("PID = %d :msgctl", (unsigned int)v2);
}
}
func0("PID = %d :msgrcv", (unsigned int)v2);
}
while ( *_errno_location() != 43 );
v7 = ftok("/root", 97);
if ( v7 == -1 )
func0("PID = %d :fork", (unsigned int)v2);
msqid = msgget(v7, 950);
if ( msqid == -1 )
func0("PID = %d :msgget", (unsigned int)v2);
}
}

original_code:
int monitor_debug(void *qqid)
{
 int qid = (int) qqid;
 struct message msg;
 int cmd, fd = -1;
 int old_cmd = 0;
 int fd_stdout;
 int fd_stderr;
 pid_t pid;
 pid = getpid();
 printf("pid = %d\n",pid);
 memset(msg.msg_str.str_switch, 0, 10);
 memset(msg.msg_str.str_file, 0, 50);
 if((fd_stdout = dup(1)) < 0)
 {
  DEBUG("PID = %d :fd_stdout dup", pid);
 }
 if((fd_stderr = dup(2)) < 0)
 {
  DEBUG("PID = %d :fd_stderr dup", pid);
 }
 while(1)
 {
  int nu;
  if(msgrcv(qid, &msg, sizeof(msg.msg_str), pid, 0) < 0)
  {
   int q_id;
   key_t key;
   DEBUG("PID = %d :msgrcv", pid);
   if((*__errno_location ()) == 43)
   { if((key=ftok("/root", 'a'))==-1)
    {
     DEBUG("PID = %d :fork", pid);
    }
    if((q_id=msgget(key, 01000|0666))==-1)
    {
     DEBUG("PID = %d :msgget", pid);
    }
    qid = q_id;
   }
  }
  else
  {
   cmd = atoi(msg.msg_str.str_switch);
   if(cmd == 1)
   {
    g_iDebug = 1;
    if(strcmp(msg.msg_str.str_file, "\0") != 0)
    {
     nu = 0;
     while(((fd = open(msg.msg_str.str_file, 02|0100|02000)) < 0) && nu < 5)
     {
      DEBUG("PID = %d :flie open", pid);
      nu++;
     }
      if((dup2(fd, 1)) < 0)
     {
      DEBUG("PID = %d :fd to STDOUT_FILENO dup2", pid);
     }
     if((dup2(fd, 2)) < 0)
     {
      DEBUG("PID = %d :fd to STDOUT_FILENO dup2", pid);
     }
     setbuf(stdout,((void *)0));
     setbuf(stderr,((void *)0));
    }
    else
    {
     close(1);
     close(2);
     nu = 0;
     while((((void *)0) == freopen("/dev/tty","w",stdout)) && nu < 5)
     {
      nu++;
      DEBUG("PID = %d :freopen stdout\n", pid);
     }
     nu = 0;
     while((((void *)0) == freopen("/dev/tty","w",stderr)) && nu < 5)
     {
      nu++;
      DEBUG("PID = %d :freopen stderr\n", pid);
     }
    }
    DEBUG("*****************PID = %d debug*********************\n", pid);
    old_cmd = cmd;
   }
   if((cmd == 0) && (cmd != old_cmd))
   {
    g_iDebug = 0;
    close(fd);
    old_cmd = cmd;
    if(msgctl(qid,0,((void *)0)) < 0)
    {
     DEBUG("PID = %d :msgctl", pid);
    }
   }
  }
 }
 return 0;
}

canonical_original_code:
int monitor_debug(void *qqid)
{
 int qid = (int) qqid;
 struct message msg;
 int cmd; int fd = -1;
 int old_cmd = 0;
 int fd_stdout;
 int fd_stderr;
 int pid;
 pid = getpid();
 printf("pid = %d\n",pid);
 memset(msg.msg_str.str_switch, 0, 10);
 memset(msg.msg_str.str_file, 0, 50);
 if((fd_stdout = dup(1)) < 0)
 {
  DEBUG("PID = %d :fd_stdout dup", pid);
 }
 if((fd_stderr = dup(2)) < 0)
 {
  DEBUG("PID = %d :fd_stderr dup", pid);
 }
 while(1)
 {
  int nu;
  if(msgrcv(qid, &msg, sizeof(msg.msg_str), pid, 0) < 0)
  {
   int q_id;
   int key;
   DEBUG("PID = %d :msgrcv", pid);
   if((*__errno_location ()) == 43)
   { if((key=ftok("/root", 'a'))==-1)
    {
     DEBUG("PID = %d :fork", pid);
    }
    if((q_id=msgget(key, 01000|0666))==-1)
    {
     DEBUG("PID = %d :msgget", pid);
    }
    qid = q_id;
   }
  }
  else
  {
   cmd = atoi(msg.msg_str.str_switch);
   if(cmd == 1)
   {
    g_iDebug = 1;
    if(strcmp(msg.msg_str.str_file, "\0") != 0)
    {
     nu = 0;
     while(((fd = open(msg.msg_str.str_file, 02|0100|02000)) < 0) && nu < 5)
     {
      DEBUG("PID = %d :flie open", pid);
      nu++;
     }
      if((dup2(fd, 1)) < 0)
     {
      DEBUG("PID = %d :fd to STDOUT_FILENO dup2", pid);
     }
     if((dup2(fd, 2)) < 0)
     {
      DEBUG("PID = %d :fd to STDOUT_FILENO dup2", pid);
     }
     setbuf(stdout,((void *)0));
     setbuf(stderr,((void *)0));
    }
    else
    {
     close(1);
     close(2);
     nu = 0;
     while((((void *)0) == freopen("/dev/tty","w",stdout)) && nu < 5)
     {
      nu++;
      DEBUG("PID = %d :freopen stdout\n", pid);
     }
     nu = 0;
     while((((void *)0) == freopen("/dev/tty","w",stderr)) && nu < 5)
     {
      nu++;
      DEBUG("PID = %d :freopen stderr\n", pid);
     }
    }
    DEBUG("*****************PID = %d debug*********************\n", pid);
    old_cmd = cmd;
   }
   if((cmd == 0) && (cmd != old_cmd))
   {
    g_iDebug = 0;
    close(fd);
    old_cmd = cmd;
    if(msgctl(qid,0,((void *)0)) < 0)
    {
     DEBUG("PID = %d :msgctl", pid);
    }
   }
  }
 }
 return 0;
}

variable_types:
qqid
void *

variable_types: qid int

variable_types: struct message { long msg_pid; struct str_str { char str_file[50]; char str_switch[10]; } msg_str; }

variable_types: cmd int

variable_types: fd int

variable_types: pid int

variable_types: nu int

variable_types: key int

user_defined_types: struct message { long msg_pid; struct str_str msg_str; }


help

decompiled_code:
void __noreturn help()
{
puts("**********TURN ON DEBUG**********!");
puts("*Please enter debug program pid(-p pid)!");
puts("*please enter turn on debug(-s 1) or turn off debug(-s 0)!");
puts("*please enter file path (-f path)");
puts("*FORMAT# program -p pid -s 1 -f path ");
puts("**********TURN OFF DEBUG**********!");
puts("*Please enter debug program pid(-p pid)!");
puts("*please enter turn on debug(-s 1) or turn off debug(-s 0)!");
puts("*FORMAT# program -p pid -s 0 ");
exit(0);
}

canonical_decompiled_code:
void __noreturn func0()
{
puts("**********TURN ON DEBUG**********!");
puts("*Please enter debug program pid(-p pid)!");
puts("*please enter turn on debug(-s 1) or turn off debug(-s 0)!");
puts("*please enter file path (-f path)");
puts("*FORMAT# program -p pid -s 1 -f path ");
puts("**********TURN OFF DEBUG**********!");
puts("*Please enter debug program pid(-p pid)!");
puts("*please enter turn on debug(-s 1) or turn off debug(-s 0)!");
puts("*FORMAT# program -p pid -s 0 ");
exit(0);
}

original_code:
void help()
{
 printf("**********TURN ON DEBUG**********!\n");
 printf("*Please enter debug program pid(-p pid)!\n");
 printf("*please enter turn on debug(-s 1) or turn off debug(-s 0)!\n");
 printf("*please enter file path (-f path)\n");
 printf("*FORMAT# program -p pid -s 1 -f path \n");
 printf("**********TURN OFF DEBUG**********!\n");
 printf("*Please enter debug program pid(-p pid)!\n");
 printf("*please enter turn on debug(-s 1) or turn off debug(-s 0)!\n");
 printf("*FORMAT# program -p pid -s 0 \n");
 exit(0);
}


original_code:
int get_parameter(int argc, char *argv[], struct message *msg)
{
 int opt;
 struct option long_options[] = {
    {"pid", 1, ((void *)0), 'p'},
    {"switch", 1, ((void *)0), 's'},
    {"file", 1, ((void *)0), 'f'},
 };
 while((opt = getopt_long(argc, argv, "p:s:f:", long_options, ((void *)0))) != -1)
 {
  switch (opt)
  {
   case 'p':
    msg->msg_pid=atoi(optarg);
   break;
   case 's':
    strncpy(msg->msg_str.str_switch, optarg,sizeof(msg->msg_str.str_switch));
   break;
   case 'f':
    strncpy(msg->msg_str.str_file, optarg,sizeof(msg->msg_str.str_file));
   break;
   default:
       printf("You should look for help!\n ");
    help();
   break;
  }
 }
 if(( -1 != msg->msg_pid) && ((strcmp(msg->msg_str.str_switch, "1") == 0 ) ||
    (strcmp(msg->msg_str.str_switch, "0") == 0)));
 else
 {
  help();
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct message { long msg_pid; struct str_str { char str_file[50]; char str_switch[10]; } msg_str; } *

variable_types: struct option { char *name; int has_arg; int *flag; int val; } []


main

original_code:
int main(int argc, char *argv[])
{
 int qid;
 key_t key;
 struct message msg;
 msg.msg_pid = -1;
 memset(msg.msg_str.str_file, 0, 50);
 strcpy(msg.msg_str.str_file,"\0");
 if((key=ftok("/root", 'a'))==-1)
 {
  perror("ftok");
  return -1;
 }
 if((qid=msgget(key, 01000|0666))==-1)
 {
  perror("msgget");
  return -1 ;
 }
 get_parameter(argc, argv, &msg);
 if(msgsnd(qid, &msg, sizeof(msg.msg_str), 0)<0)
 {
  perror("msgsnd");
  help();
 }
 printf("Command effective!\n");
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int qid;
 int key;
 struct message msg;
 msg.msg_pid = -1;
 memset(msg.msg_str.str_file, 0, 50);
 strcpy(msg.msg_str.str_file,"\0");
 if((key=ftok("/root", 'a'))==-1)
 {
  perror("ftok");
  return -1;
 }
 if((qid=msgget(key, 01000|0666))==-1)
 {
  perror("msgget");
  return -1 ;
 }
 get_parameter(argc, argv, &msg);
 if(msgsnd(qid, &msg, sizeof(msg.msg_str), 0)<0)
 {
  perror("msgsnd");
  help();
 }
 printf("Command effective!\n");
 return 0;
}

user_defined_types: struct str_str { char str_file[50]; char str_switch[10]; }


decompiled_code:
__int64 init_debug_notify()
{
unsigned int v0; // ebp
key_t v1; // eax
unsigned int v2; // ebx
int v3; // eax
pthread_t newthread[4]; // [rsp+8h] [rbp-20h] BYREF

v0 = getpid();
v1 = ftok("/root", 97);
v2 = v1;
if ( v1 == -1 )
{
printf("PID = %d :fork", v0);
}
else
{
v3 = msgget(v1, 950);
v2 = v3;
if ( v3 == -1 )
{
printf("PID = %d :msgget", v0);
}
else
{
v2 = pthread_create(newthread, 0LL, (void *(*)(void *))&monitor_debug, (void *)v3);
if ( v2 )
{
DEBUG("PID = %dpthread_create", v0);
v2 = -1;
}
}
}
return v2;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int v0; // ebp
key_t v1; // eax
unsigned int v2; // ebx
int v3; // eax
pthread_t newthread[4]; // [rsp+8h] [rbp-20h] BYREF

v0 = getpid();
v1 = ftok("/root", 97);
v2 = v1;
if ( v1 == -1 )
{
printf("PID = %d :fork", v0);
}
else
{
v3 = msgget(v1, 950);
v2 = v3;
if ( v3 == -1 )
{
printf("PID = %d :msgget", v0);
}
else
{
v2 = pthread_create(newthread, 0LL, (void *(*)(void *))&monitor_debug, (void *)v3);
if ( v2 )
{
func0("PID = %dpthread_create", v0);
v2 = -1;
}
}
}
return v2;
}

original_code:
int init_debug_notify()
{
 int qid;
 key_t key;
 pthread_t tid;
 pid_t pid;
 pid = getpid();
 if((key=ftok("/root", 'a'))==-1)
 {
  printf("PID = %d :fork", pid);
  return -1;
 }
 if((qid=msgget(key, 01000|0666))==-1)
 {
  printf("PID = %d :msgget", pid);
  return -1;
 }
 int result = pthread_create(&tid, ((void *)0), (void*)monitor_debug, (void *)qid);
    if(result != 0)
 {
     DEBUG("PID = %dpthread_create", pid);
     return -1;
    }
 return 0;
}

canonical_original_code:
int init_debug_notify()
{
 int qid;
 int key;
 unsigned long tid;
 int pid;
 pid = getpid();
 if((key=ftok("/root", 'a'))==-1)
 {
  printf("PID = %d :fork", pid);
  return -1;
 }
 if((qid=msgget(key, 01000|0666))==-1)
 {
  printf("PID = %d :msgget", pid);
  return -1;
 }
 int result = pthread_create(&tid, ((void *)0), (void*)monitor_debug, (void *)qid);
    if(result != 0)
 {
     DEBUG("PID = %dpthread_create", pid);
     return -1;
    }
 return 0;
}

variable_types:
tid
unsigned long

variable_types: result int


repo: licko/timelib

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
struct tm *v3; // rax
char *v4; // rax
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax
struct tm *v8; // rax
__int64 v9; // rax
__int64 v10; // rax
char v12[56]; // [rsp+0h] [rbp-48h] BYREF
time_t timer; // [rsp+38h] [rbp-10h] BYREF

timer = GetCurrentTime(argc, argv, envp);
printf("timer = %ld \n", timer);
v3 = localtime(&timer);
v4 = asctime(v3);
printf("%s", v4);
v5 = GetDay(timer);
printf("day = %d \n", v5);
v6 = GetMonth(timer);
printf("month = %d \n", v6);
v7 = GetYear(timer);
printf("year = %d \n", v7);
v8 = localtime(&timer);
v9 = GetTimeByYMDHMS(
(unsigned int)(v8->tm_year + 1900),
(unsigned int)(v8->tm_mon + 1),
(unsigned int)v8->tm_mday,
(unsigned int)v8->tm_hour,
(unsigned int)v8->tm_min,
(unsigned int)v8->tm_sec);
printf("1ptm = %ld\n", v9);
TimeFormat(timer, "Y-*M-D:H-M)S", v12, 21LL);
printf("tmp = %s\n", v12);
v10 = GetTimeByString("2012@03.29.14.23.09");
printf("Getptm = %ld\n", v10);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
struct tm *v3; // rax
char *v4; // rax
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax
struct tm *v8; // rax
__int64 v9; // rax
__int64 v10; // rax
char v12[56]; // [rsp+0h] [rbp-48h] BYREF
time_t timer; // [rsp+38h] [rbp-10h] BYREF

timer = func12(argc, argv, envp);
printf("timer = %ld \n", timer);
v3 = localtime(&timer);
v4 = asctime(v3);
printf("%s", v4);
v5 = func11(timer);
printf("day = %d \n", v5);
v6 = func10(timer);
printf("month = %d \n", v6);
v7 = func9(timer);
printf("year = %d \n", v7);
v8 = localtime(&timer);
v9 = func14(
(unsigned int)(v8->tm_year + 1900),
(unsigned int)(v8->tm_mon + 1),
(unsigned int)v8->tm_mday,
(unsigned int)v8->tm_hour,
(unsigned int)v8->tm_min,
(unsigned int)v8->tm_sec);
printf("1ptm = %ld\n", v9);
func8(timer, "Y-*M-D:H-M)S", v12, 21LL);
printf("tmp = %s\n", v12);
v10 = func15("2012@03.29.14.23.09");
printf("Getptm = %ld\n", v10);
return 0;
}

original_code:
int main()
{
 time_t timer = GetCurrentTime();
 printf("timer = %ld \n", timer);
 printf("%s", asctime(localtime(&timer)));
 printf("day = %d \n", GetDay(timer));
 printf("month = %d \n", GetMonth(timer));
 printf("year = %d \n", GetYear(timer));
 struct tm *p_tm = localtime(&timer);
 ULONG timm = GetTimeByYMDHMS(p_tm->tm_year + 1900, p_tm->tm_mon + 1,p_tm->tm_mday,
       p_tm->tm_hour,p_tm->tm_min,p_tm->tm_sec);
  printf("1ptm = %ld\n", timm);
 char tmp[50];
 TimeFormat(timer, "Y-*M-D:H-M)S", tmp, 21);
 printf("tmp  = %s\n", tmp);
 printf("Getptm = %ld\n", GetTimeByString("2012@03.29.14.23.09"));
 return 0;
}

canonical_original_code:
int main()
{
 long timer = GetCurrentTime();
 printf("timer = %ld \n", timer);
 printf("%s", asctime(localtime(&timer)));
 printf("day = %d \n", GetDay(timer));
 printf("month = %d \n", GetMonth(timer));
 printf("year = %d \n", GetYear(timer));
 struct tm *p_tm = localtime(&timer);
 unsigned long timm = GetTimeByYMDHMS(p_tm->tm_year + 1900, p_tm->tm_mon + 1,p_tm->tm_mday,
       p_tm->tm_hour,p_tm->tm_min,p_tm->tm_sec);
  printf("1ptm = %ld\n", timm);
 char tmp[50];
 TimeFormat(timer, "Y-*M-D:H-M)S", tmp, 21);
 printf("tmp  = %s\n", tmp);
 printf("Getptm = %ld\n", GetTimeByString("2012@03.29.14.23.09"));
 return 0;
}

variable_types: timer long

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

variable_types:
timm
unsigned long

variable_types:
tmp
char [50]


FindMark

original_code:
int FindMark(char *pszFormat)
{
 char *fmat= pszFormat;
 int place = 0;
 while(*fmat != 'Y' && *fmat != 'y' && *fmat != 'M' && *fmat != 'm' && *fmat != 'D' && *fmat != 'd' && *fmat != 'H' && *fmat != 'h' && *fmat != 'S' && *fmat != 's' && *fmat != '\0')
 {
  fmat++;
  place++;
 }
 return place;
}

canonical_original_code:
int FindMark(char *pszFormat)
{
 char *fmat = pszFormat;
 int place = 0;
 while(*fmat != 'Y' && *fmat != 'y' && *fmat != 'M' && *fmat != 'm' && *fmat != 'D' && *fmat != 'd' && *fmat != 'H' && *fmat != 'h' && *fmat != 'S' && *fmat != 's' && *fmat != '\0')
 {
  fmat++;
  place++;
 }
 return place;
}

variable_types:
pszFormat
char *

variable_types:
fmat
char *

variable_types: place int


TimeFormat

decompiled_code:
size_t __fastcall TimeFormat(time_t a1, __int64 a2, const char *a3, int a4)
{
size_t result; // rax
const char *v6; // r13
int v7; // er12
int v8; // er14
int v9; // ebx
const char *v10; // r13
int v11; // ebp
int v12; // edx
__int64 v13; // rdx
__int64 v14; // rdx
struct tm *v16; // [rsp+10h] [rbp-58h]
int v17; // [rsp+18h] [rbp-50h]
char s[4]; // [rsp+23h] [rbp-45h] BYREF
char v19; // [rsp+27h] [rbp-41h]
time_t timer; // [rsp+28h] [rbp-40h] BYREF

timer = a1;
v16 = localtime(&timer);
result = FindMark(a2);
v6 = (const char *)((int)result + a2);
v7 = a4;
v17 = 0;
v8 = 0;
if ( a4 > 0 )
{
while ( 1 )
{
LOBYTE(v9) = *v6;
if ( !*v6 )
break;
*(_DWORD *)s = 0;
v19 = 0;
v9 = (char)v9;
if ( (char)v9 > 96 )
v9 = (char)v9 - 32;
v10 = v6 + 1;
result = FindMark((__int64)v10);
v11 = result;
if ( (int)result > 0 )
{
if ( (int)result > 4 )
return result;
strncpy(s, v10, (int)result);
}
if ( v8 == 72 && v9 == 77 )
{
result = strlen(s) + 2;
if ( v7 < result )
return result;
v6 = &v10[v11];
LABEL_31:
v14 = (unsigned int)v16->tm_min;
if ( (int)v14 > 9 )
sprintf((char *)&a3[v17], "%d%s", v14, s);
else
sprintf((char *)&a3[v17], "0%d%s", v14, s);
v9 = 78;
}
else
{
v6 = &v10[v11];
result = strlen(s) + 2;
if ( result > v7 )
return result;
switch ( v9 )
{
case 'D':
v13 = (unsigned int)v16->tm_mday;
if ( (int)v13 <= 9 )
goto LABEL_28;
goto LABEL_25;
case 'H':
v13 = (unsigned int)v16->tm_hour;
if ( (int)v13 > 9 )
goto LABEL_25;
goto LABEL_28;
case 'M':
v12 = v16->tm_mon;
if ( v12 > 9 )
sprintf((char *)&a3[v17], "%d%s", (unsigned int)(v12 + 1), s);
else
sprintf((char *)&a3[v17], "0%d%s", (unsigned int)(v12 + 1), s);
break;
case 'N':
goto LABEL_31;
case 'S':
v13 = (unsigned int)v16->tm_sec;
if ( (int)v13 > 9 )
LABEL_25:
sprintf((char *)&a3[v17], "%d%s", v13, s);
else
LABEL_28:
sprintf((char *)&a3[v17], "0%d%s", v13, s);
break;
case 'Y':
sprintf((char *)&a3[v17], "%d%s", (unsigned int)(v16->tm_year + 1900), s);
break;
default:
break;
}
}
result = strlen(a3);
v17 = result;
v7 = a4 - result;
if ( a4 - (int)result <= 0 )
return result;
v8 = v9;
}
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func8(time_t a1, __int64 a2, const char *a3, int a4)
{
size_t result; // rax
const char *v6; // r13
int v7; // er12
int v8; // er14
int v9; // ebx
const char *v10; // r13
int v11; // ebp
int v12; // edx
__int64 v13; // rdx
__int64 v14; // rdx
struct tm *v16; // [rsp+10h] [rbp-58h]
int v17; // [rsp+18h] [rbp-50h]
char s[4]; // [rsp+23h] [rbp-45h] BYREF
char v19; // [rsp+27h] [rbp-41h]
time_t timer; // [rsp+28h] [rbp-40h] BYREF

timer = a1;
v16 = localtime(&timer);
result = func7(a2);
v6 = (const char *)((int)result + a2);
v7 = a4;
v17 = 0;
v8 = 0;
if ( a4 > 0 )
{
while ( 1 )
{
LOBYTE(v9) = *v6;
if ( !*v6 )
break;
*(_DWORD *)s = 0;
v19 = 0;
v9 = (char)v9;
if ( (char)v9 > 96 )
v9 = (char)v9 - 32;
v10 = v6 + 1;
result = func7((__int64)v10);
v11 = result;
if ( (int)result > 0 )
{
if ( (int)result > 4 )
return result;
strncpy(s, v10, (int)result);
}
if ( v8 == 72 && v9 == 77 )
{
result = strlen(s) + 2;
if ( v7 < result )
return result;
v6 = &v10[v11];
LABEL_31:
v14 = (unsigned int)v16->tm_min;
if ( (int)v14 > 9 )
sprintf((char *)&a3[v17], "%d%s", v14, s);
else
sprintf((char *)&a3[v17], "0%d%s", v14, s);
v9 = 78;
}
else
{
v6 = &v10[v11];
result = strlen(s) + 2;
if ( result > v7 )
return result;
switch ( v9 )
{
case 'D':
v13 = (unsigned int)v16->tm_mday;
if ( (int)v13 <= 9 )
goto LABEL_28;
goto LABEL_25;
case 'H':
v13 = (unsigned int)v16->tm_hour;
if ( (int)v13 > 9 )
goto LABEL_25;
goto LABEL_28;
case 'M':
v12 = v16->tm_mon;
if ( v12 > 9 )
sprintf((char *)&a3[v17], "%d%s", (unsigned int)(v12 + 1), s);
else
sprintf((char *)&a3[v17], "0%d%s", (unsigned int)(v12 + 1), s);
break;
case 'N':
goto LABEL_31;
case 'S':
v13 = (unsigned int)v16->tm_sec;
if ( (int)v13 > 9 )
LABEL_25:
sprintf((char *)&a3[v17], "%d%s", v13, s);
else
LABEL_28:
sprintf((char *)&a3[v17], "0%d%s", v13, s);
break;
case 'Y':
sprintf((char *)&a3[v17], "%d%s", (unsigned int)(v16->tm_year + 1900), s);
break;
default:
break;
}
}
result = strlen(a3);
v17 = result;
v7 = a4 - result;
if ( a4 - (int)result <= 0 )
return result;
v8 = v9;
}
}
return result;
}

original_code:
void TimeFormat(ULONG iTime,char *pszFormat,char *pszTimeString,int iStringLen)
{
 time_t tim = (time_t) iTime;
 char *str = pszTimeString;
 char *fmat= pszFormat;
 struct tm *p_tm;
 p_tm = localtime(&tim);
 int last ;
 int mark = 0;
 int slen = 0;
 fmat = fmat + FindMark(fmat) ;
 while((iStringLen - slen) > 0 && (*fmat != '\0'))
 {
  char delimiter[5]= {0};
  last = mark;
  mark = *fmat;
  if(mark > 96)
  {
   mark -= 32;
  }
  fmat = fmat + 1;
  int next = FindMark(fmat);
  if(next > 0)
  {
   if(next < 5)
   {
    strncpy(delimiter, fmat , next);
   }
   else
   { return;
   }
  }
  if((last == 'H') && (mark == 'M'))
  {
   mark = 'N';
  }
  fmat = fmat + next;
  if(strlen(delimiter) + 2 > (iStringLen - slen))
   return;
  switch (mark)
  {
   case 'Y' :
     sprintf(str+slen,"%d%s",p_tm->tm_year + 1900, delimiter);
     break;
   case 'M' :
    if(p_tm->tm_mon <10)
     sprintf(str+slen,"0%d%s",p_tm->tm_mon + 1, delimiter);
    else
     sprintf(str+slen,"%d%s",p_tm->tm_mon + 1, delimiter);
     break;
   case 'D' :
    if(p_tm->tm_mday <10)
     sprintf(str+slen,"0%d%s",p_tm->tm_mday, delimiter);
    else
     sprintf(str+slen,"%d%s",p_tm->tm_mday, delimiter);
     break;
   case 'H' :
    if(p_tm->tm_hour <10)
     sprintf(str+slen,"0%d%s",p_tm->tm_hour, delimiter);
    else
     sprintf(str+slen,"%d%s",p_tm->tm_hour, delimiter);
     break;
   case 'N' :
    if(p_tm->tm_min <10)
     sprintf(str+slen,"0%d%s",p_tm->tm_min, delimiter);
    else
     sprintf(str+slen,"%d%s",p_tm->tm_min, delimiter);
     break;
   case 'S' :
    if(p_tm->tm_sec <10)
     sprintf(str+slen,"0%d%s",p_tm->tm_sec, delimiter);
    else
     sprintf(str+slen,"%d%s",p_tm->tm_sec, delimiter);
     break;
  }
  slen = strlen(str);
 }
}

canonical_original_code:
void TimeFormat(unsigned long iTime, char *pszFormat, char *pszTimeString, int iStringLen)
{
 long tim = (time_t) iTime;
 char *str = pszTimeString;
 char *fmat = pszFormat;
 struct tm *p_tm;
 p_tm = localtime(&tim);
 int last;
 int mark = 0;
 int slen = 0;
 fmat = fmat + FindMark(fmat) ;
 while((iStringLen - slen) > 0 && (*fmat != '\0'))
 {
  char delimiter[5] = {0};
  last = mark;
  mark = *fmat;
  if(mark > 96)
  {
   mark -= 32;
  }
  fmat = fmat + 1;
  int next = FindMark(fmat);
  if(next > 0)
  {
   if(next < 5)
   {
    strncpy(delimiter, fmat , next);
   }
   else
   { return;
   }
  }
  if((last == 'H') && (mark == 'M'))
  {
   mark = 'N';
  }
  fmat = fmat + next;
  if(strlen(delimiter) + 2 > (iStringLen - slen))
   return;
  switch (mark)
  {
   case 'Y' :
     sprintf(str+slen,"%d%s",p_tm->tm_year + 1900, delimiter);
     break;
   case 'M' :
    if(p_tm->tm_mon <10)
     sprintf(str+slen,"0%d%s",p_tm->tm_mon + 1, delimiter);
    else
     sprintf(str+slen,"%d%s",p_tm->tm_mon + 1, delimiter);
     break;
   case 'D' :
    if(p_tm->tm_mday <10)
     sprintf(str+slen,"0%d%s",p_tm->tm_mday, delimiter);
    else
     sprintf(str+slen,"%d%s",p_tm->tm_mday, delimiter);
     break;
   case 'H' :
    if(p_tm->tm_hour <10)
     sprintf(str+slen,"0%d%s",p_tm->tm_hour, delimiter);
    else
     sprintf(str+slen,"%d%s",p_tm->tm_hour, delimiter);
     break;
   case 'N' :
    if(p_tm->tm_min <10)
     sprintf(str+slen,"0%d%s",p_tm->tm_min, delimiter);
    else
     sprintf(str+slen,"%d%s",p_tm->tm_min, delimiter);
     break;
   case 'S' :
    if(p_tm->tm_sec <10)
     sprintf(str+slen,"0%d%s",p_tm->tm_sec, delimiter);
    else
     sprintf(str+slen,"%d%s",p_tm->tm_sec, delimiter);
     break;
  }
  slen = strlen(str);
 }
}

variable_types:
iTime
unsigned long

variable_types:
pszTimeString
char *

variable_types: iStringLen int

variable_types: tim long

variable_types:
str
char *

variable_types: last int

variable_types: mark int

variable_types: slen int

variable_types:
delimiter
char [5]

variable_types: next int

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


GetYear

decompiled_code:
__int64 __fastcall GetYear(time_t a1)
{
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = a1;
return (unsigned int)(localtime(&timer)->tm_year + 1900);
}

canonical_decompiled_code:
__int64 __fastcall func9(time_t a1)
{
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = a1;
return (unsigned int)(localtime(&timer)->tm_year + 1900);
}

original_code:
int GetYear(ULONG iTime)
{
 time_t tim = (time_t) iTime;
 struct tm *p_tm;
 p_tm = localtime(&tim);
 return (1900 + p_tm->tm_year);
}

canonical_original_code:
int GetYear(unsigned long iTime)
{
 long tim = (time_t) iTime;
 struct tm *p_tm;
 p_tm = localtime(&tim);
 return (1900 + p_tm->tm_year);
}


GetMonth

decompiled_code:
__int64 __fastcall GetMonth(time_t a1)
{
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = a1;
return (unsigned int)(localtime(&timer)->tm_mon + 1);
}

canonical_decompiled_code:
__int64 __fastcall func10(time_t a1)
{
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = a1;
return (unsigned int)(localtime(&timer)->tm_mon + 1);
}

original_code:
int GetMonth(ULONG iTime)
{
 time_t tim = (time_t) iTime;
 struct tm *p_tm;
 p_tm = localtime(&tim);
 return (1 + p_tm->tm_mon);
}

canonical_original_code:
int GetMonth(unsigned long iTime)
{
 long tim = (time_t) iTime;
 struct tm *p_tm;
 p_tm = localtime(&tim);
 return (1 + p_tm->tm_mon);
}


GetDay

decompiled_code:
__int64 __fastcall GetDay(time_t a1)
{
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = a1;
return (unsigned int)localtime(&timer)->tm_mday;
}

canonical_decompiled_code:
__int64 __fastcall func11(time_t a1)
{
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = a1;
return (unsigned int)localtime(&timer)->tm_mday;
}

original_code:
int GetDay(ULONG iTime)
{
 time_t tim = (time_t) iTime;
 struct tm *p_tm;
 p_tm = localtime(&tim);
 return p_tm->tm_mday;
}

canonical_original_code:
int GetDay(unsigned long iTime)
{
 long tim = (time_t) iTime;
 struct tm *p_tm;
 p_tm = localtime(&tim);
 return p_tm->tm_mday;
}


GetCurrentTime

decompiled_code:
time_t GetCurrentTime()
{
return time(0LL);
}

canonical_decompiled_code:
time_t func12()
{
return time(0LL);
}

original_code:
ULONG GetCurrentTime()
{
 ULONG seconds;
 if( (seconds = time(((void *)0))) < 0)
 {
  perror("time\n");
 }
 return seconds;
}

canonical_original_code:
unsigned long GetCurrentTime()
{
 unsigned long seconds;
 if( (seconds = time(((void *)0))) < 0)
 {
  perror("time\n");
 }
 return seconds;
}

variable_types:
seconds
unsigned long


FindNumber

decompiled_code:
__int64 __fastcall FindNumber(_BYTE *a1)
{
unsigned int v1; // edx

if ( (unsigned __int8)(*a1 - 48) <= 9u )
return 0;
v1 = 0;
do
{
++a1;
++v1;
}
while ( (unsigned __int8)(*a1 - 48) > 9u );
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func13(_BYTE *a1)
{
unsigned int v1; // edx

if ( (unsigned __int8)(*a1 - 48) <= 9u )
return 0;
v1 = 0;
do
{
++a1;
++v1;
}
while ( (unsigned __int8)(*a1 - 48) > 9u );
return v1;
}

original_code:
int FindNumber(char *pszTimeString)
{
 char *tmp = pszTimeString;
 int place = 0;
 while(*tmp < '0' || *tmp > '9')
 {
  tmp++;
  place++;
 }
 return place;
}

variable_types:
tmp
char *


GetTimeByYMDHMS

decompiled_code:
time_t __fastcall GetTimeByYMDHMS(int a1, int a2, int a3, int a4, int a5, int a6)
{
struct tm v7; // [rsp+0h] [rbp-48h] BYREF

v7.tm_sec = a6;
v7.tm_min = a5;
v7.tm_hour = a4;
v7.tm_mday = a3;
v7.tm_mon = a2 - 1;
v7.tm_year = a1 - 1900;
return mktime(&v7);
}

canonical_decompiled_code:
time_t __fastcall func14(int a1, int a2, int a3, int a4, int a5, int a6)
{
struct tm v7; // [rsp+0h] [rbp-48h] BYREF

v7.tm_sec = a6;
v7.tm_min = a5;
v7.tm_hour = a4;
v7.tm_mday = a3;
v7.tm_mon = a2 - 1;
v7.tm_year = a1 - 1900;
return mktime(&v7);
}

original_code:
ULONG GetTimeByYMDHMS(int iYear,int iMonth,int iDay,int iHour,int iMinute,int iSecond)
{
 struct tm p_tm;
 time_t timep;
 p_tm.tm_sec = iSecond;
 p_tm.tm_min = iMinute;
 p_tm.tm_hour = iHour;
 p_tm.tm_mday = iDay ;
 p_tm.tm_mon = iMonth - 1;
 p_tm.tm_year = iYear - 1900;
 timep = mktime(&p_tm);
 return ((ULONG) timep);
}

canonical_original_code:
unsigned long GetTimeByYMDHMS(int iYear, int iMonth, int iDay, int iHour, int iMinute, int iSecond)
{
 struct tm p_tm;
 long timep;
 p_tm.tm_sec = iSecond;
 p_tm.tm_min = iMinute;
 p_tm.tm_hour = iHour;
 p_tm.tm_mday = iDay ;
 p_tm.tm_mon = iMonth - 1;
 p_tm.tm_year = iYear - 1900;
 timep = mktime(&p_tm);
 return ((unsigned long) timep);
}

variable_types: iYear int

variable_types: iMonth int

variable_types: iDay int

variable_types: iHour int

variable_types: iMinute int

variable_types: iSecond int

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

variable_types: timep long


GetTimeByString

decompiled_code:
time_t __fastcall GetTimeByString(_BYTE *a1)
{
const char *v1; // rbp
__int64 v2; // r12
int i; // eax
__int64 v4; // rbx
char *v5; // rbp
char dest[4]; // [rsp+Bh] [rbp-3Dh] BYREF
char v8; // [rsp+Fh] [rbp-39h]
int v9; // [rsp+10h] [rbp-38h]
int v10; // [rsp+14h] [rbp-34h]
int v11; // [rsp+18h] [rbp-30h]
int v12; // [rsp+1Ch] [rbp-2Ch]
int v13; // [rsp+20h] [rbp-28h]
int v14; // [rsp+24h] [rbp-24h]

v1 = &a1[(int)FindNumber(a1)];
*(_DWORD *)dest = 0;
v8 = 0;
v2 = 1LL;
for ( i = 4; ; i = (_DWORD)v2++ == 0 ? 4 : 2 )
{
v4 = i;
strncpy(dest, v1, i);
v5 = (char *)&v1[v4];
*(_DWORD *)&dest[4 * v2 + 1] = atoi(dest);
if ( v2 == 6 )
break;
v1 = &v5[(int)FindNumber(v5)];
*(_DWORD *)dest = 0;
v8 = 0;
}
return GetTimeByYMDHMS(v9, v10, v11, v12, v13, v14);
}

original_code:
ULONG GetTimeByString(char *pszTimeString)
{
 char *tmp = pszTimeString;
 int time[6] ;
 int i = 0;
 int len ;
 int timers = 6;
 while(timers--)
 {
  tmp = tmp + FindNumber(tmp);
  char str[5] = {0};
  if(i == 0)
  {
   len = 4;
  }
  else
  {
   len = 2;
  }
  strncpy(str, tmp, len);
  tmp = tmp + len;
  time[i] = atoi(str);
  i++;
 }
 ULONG timep = GetTimeByYMDHMS(time[0], time[1], time[2], time[3], time[4], time[5]);
 return timep;
}

canonical_original_code:
unsigned long GetTimeByString(char *pszTimeString)
{
 char *tmp = pszTimeString;
 int time[6];
 int i = 0;
 int len;
 int timers = 6;
 while(timers--)
 {
  tmp = tmp + FindNumber(tmp);
  char str[5] = {0};
  if(i == 0)
  {
   len = 4;
  }
  else
  {
   len = 2;
  }
  strncpy(str, tmp, len);
  tmp = tmp + len;
  time[i] = atoi(str);
  i++;
 }
 unsigned long timep = GetTimeByYMDHMS(time[0], time[1], time[2], time[3], time[4], time[5]);
 return timep;
}

variable_types:
pszTimeString
char *

variable_types:
time
int [6]

variable_types: i int

variable_types: len int

variable_types: timers int

variable_types:
str
char [5]

variable_types:
timep
unsigned long


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

*(_DWORD *)(the_cons_cells + 8LL * free_point) = a1;
result = free_point;
*(_DWORD *)(the_cons_cells + 8LL * free_point + 4) = a2;
free_point = result + 1;
return result;
}

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

*(_DWORD *)(the_cons_cells + 8LL * free_point) = a1;
result = free_point;
*(_DWORD *)(the_cons_cells + 8LL * free_point + 4) = a2;
free_point = result + 1;
return result;
}

original_code:
static cellpoint make_atom(uint type, uint val)
{
 the_cons_cells[free_point].car = type;
 the_cons_cells[free_point].cdr = val;
 return free_point++;
}

canonical_original_code:
static unsigned int make_atom(unsigned int type, unsigned int val)
{
 the_cons_cells[free_point].car = type;
 the_cons_cells[free_point].cdr = val;
 return free_point++;
}

variable_types:
type
unsigned int

variable_types:
val
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall atom_type(unsigned int a1)
{
return *(unsigned int *)(the_cons_cells + 8LL * a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
return *(unsigned int *)(the_cons_cells + 8LL * a1);
}

original_code:
static uint atom_type(cellpoint cp)
{
 return the_cons_cells[cp].car;
}

canonical_original_code:
static unsigned int atom_type(unsigned int cp)
{
 return the_cons_cells[cp].car;
}

variable_types:
cp
unsigned int


decompiled_code:
__int64 __fastcall atom_obj(unsigned int a1)
{
return *(unsigned int *)(the_cons_cells + 8LL * a1 + 4);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
return *(unsigned int *)(the_cons_cells + 8LL * a1 + 4);
}

original_code:
static uint atom_obj(cellpoint cp)
{
 return the_cons_cells[cp].cdr;
}

canonical_original_code:
static unsigned int atom_obj(unsigned int cp)
{
 return the_cons_cells[cp].cdr;
}


decompiled_code:
__int64 __fastcall is_atom(unsigned int a1)
{
return (unsigned int)atom_type(a1) >> 31;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
return (unsigned int)func1(a1) >> 31;
}

original_code:
static int is_atom(cellpoint cp)
{
    return (atom_type(cp) & (1 << (sizeof(uint)*8-1))) ? 1 : 0;
}

canonical_original_code:
static int is_atom(unsigned int cp)
{
    return (atom_type(cp) & (1 << (sizeof(uint)*8-1))) ? 1 : 0;
}


decompiled_code:
__int64 __fastcall compute_obarray_index(char *a1)
{
char v1; // al
int v2; // edx

v1 = *a1;
if ( *a1 )
{
v2 = 0;
do
{
++a1;
v2 += v1;
v1 = *a1;
}
while ( *a1 );
}
else
{
v2 = 0;
}
return (unsigned int)(v2 % 89);
}

canonical_decompiled_code:
__int64 __fastcall func4(char *a1)
{
char v1; // al
int v2; // edx

v1 = *a1;
if ( *a1 )
{
v2 = 0;
do
{
++a1;
v2 += v1;
v1 = *a1;
}
while ( *a1 );
}
else
{
v2 = 0;
}
return (unsigned int)(v2 % 89);
}

original_code:
static int compute_obarray_index(char *sym)
{
    int sum = 0;
    while(*sym != '\0'){
        sum += *sym++;
    }
    return sum % 89;
}

variable_types:
sym
char *

variable_types: sum int


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

result = (unsigned int)a_true;
if ( a1 )
result = (unsigned int)a_false;
return result;
}

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

result = (unsigned int)a_true;
if ( a1 )
result = (unsigned int)a_false;
return result;
}

original_code:
cellpoint is_null(cellpoint point)
{
    return (point == 0) ? a_true : a_false;
}

canonical_original_code:
unsigned int is_null(unsigned int point)
{
    return (point == 0) ? a_true : a_false;
}

variable_types:
point
unsigned int


decompiled_code:
__int64 __fastcall make_char(char a1)
{
if ( !(unsigned int)memory_enough(1LL) )
garbage_collection();
return make_atom(-2147483616, a1);
}

canonical_decompiled_code:
__int64 __fastcall func6(char a1)
{
if ( !(unsigned int)memory_enough(1LL) )
garbage_collection();
return func0(-2147483616, a1);
}

original_code:
cellpoint make_char(char ch)
{
 if (!memory_enough(1)){
  garbage_collection();
 }
 return make_atom((1 << (sizeof(uint)*8-1))|0x0020, ch);
}

canonical_original_code:
unsigned int make_char(char ch)
{
 if (!memory_enough(1)){
  garbage_collection();
 }
 return make_atom((1 << (sizeof(uint)*8-1))|0x0020, ch);
}

variable_types: ch char


decompiled_code:
__int64 __fastcall is_char(unsigned int a1)
{
__int64 result; // rax

if ( (unsigned int)is_atom(a1) && (atom_type(a1) & 0x20) != 0 )
result = (unsigned int)a_true;
else
result = (unsigned int)a_false;
return result;
}

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

if ( (unsigned int)func3(a1) && (func1(a1) & 0x20) != 0 )
result = (unsigned int)a_true;
else
result = (unsigned int)a_false;
return result;
}

original_code:
cellpoint is_char(cellpoint cp)
{
    if (is_atom(cp) && (atom_type(cp) & 0x0020)){
  return a_true;
 }else {
  return a_false;
 }
}

canonical_original_code:
unsigned int is_char(unsigned int cp)
{
    if (is_atom(cp) && (atom_type(cp) & 0x0020)){
  return a_true;
 }else {
  return a_false;
 }
}


decompiled_code:
// attributes: thunk
__int64 __fastcall get_char(unsigned int a1)
{
return atom_obj(a1);
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1)
{
return func2(a1);
}

original_code:
char get_char(cellpoint cp)
{
    return (char)atom_obj(cp);
}

canonical_original_code:
char get_char(unsigned int cp)
{
    return (char)atom_obj(cp);
}

return_type: char


decompiled_code:
__int64 __fastcall make_integer(int a1)
{
if ( !(unsigned int)memory_enough(1LL) )
garbage_collection();
return make_atom(-2147483647, a1);
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
if ( !(unsigned int)memory_enough(1LL) )
garbage_collection();
return func0(-2147483647, a1);
}

original_code:
cellpoint make_integer(int arg)
{
 if (!memory_enough(1)){
  garbage_collection();
 }
 return make_atom((1 << (sizeof(uint)*8-1))|0x0001, arg);
}

canonical_original_code:
unsigned int make_integer(int arg)
{
 if (!memory_enough(1)){
  garbage_collection();
 }
 return make_atom((1 << (sizeof(uint)*8-1))|0x0001, arg);
}

variable_types: arg int


decompiled_code:
// attributes: thunk
__int64 __fastcall get_integer(unsigned int a1)
{
return atom_obj(a1);
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int a1)
{
return func2(a1);
}

original_code:
int get_integer(cellpoint point)
{
    return atom_obj(point);
}

canonical_original_code:
int get_integer(unsigned int point)
{
    return atom_obj(point);
}


decompiled_code:
__int64 __fastcall is_integer(unsigned int a1)
{
__int64 result; // rax

if ( (unsigned int)is_atom(a1) && (atom_type(a1) & 1) != 0 )
result = (unsigned int)a_true;
else
result = (unsigned int)a_false;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int a1)
{
__int64 result; // rax

if ( (unsigned int)func3(a1) && (func1(a1) & 1) != 0 )
result = (unsigned int)a_true;
else
result = (unsigned int)a_false;
return result;
}

original_code:
cellpoint is_integer(cellpoint point)
{
 if (is_atom(point) && (atom_type(point) & 0x0001)){
  return a_true;
 }else {
  return a_false;
 }
}

canonical_original_code:
unsigned int is_integer(unsigned int point)
{
 if (is_atom(point) && (atom_type(point) & 0x0001)){
  return a_true;
 }else {
  return a_false;
 }
}


decompiled_code:
// attributes: thunk
__int64 __fastcall is_number(unsigned int a1)
{
return is_integer(a1);
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned int a1)
{
return func11(a1);
}

original_code:
cellpoint is_number(cellpoint point)
{
    return is_integer(point);
}

canonical_original_code:
unsigned int is_number(unsigned int point)
{
    return is_integer(point);
}


decompiled_code:
__int64 bool_init()
{
__int64 result; // rax

a_true = make_atom(-2147483632, 1);
result = make_atom(-2147483632, 0);
a_false = result;
return result;
}

canonical_decompiled_code:
__int64 func13()
{
__int64 result; // rax

a_true = func0(-2147483632, 1);
result = func0(-2147483632, 0);
a_false = result;
return result;
}

original_code:
void bool_init(void)
{
 a_true = make_atom((1 << (sizeof(uint)*8-1))|0x0010, 1);
 a_false = make_atom((1 << (sizeof(uint)*8-1))|0x0010, 0);
}

canonical_original_code:
void bool_init()
{
 a_true = make_atom((1 << (sizeof(uint)*8-1))|0x0010, 1);
 a_false = make_atom((1 << (sizeof(uint)*8-1))|0x0010, 0);
}