original_code:
void pooyan_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  int bit0,bit1,bit2;
  bit0 = (*color_prom >> 0) & 0x01;
  bit1 = (*color_prom >> 1) & 0x01;
  bit2 = (*color_prom >> 2) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = (*color_prom >> 3) & 0x01;
  bit1 = (*color_prom >> 4) & 0x01;
  bit2 = (*color_prom >> 5) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = 0;
  bit1 = (*color_prom >> 6) & 0x01;
  bit2 = (*color_prom >> 7) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  color_prom++;
 }
 for (i = 0;i < (Machine->gfx[1]->total_colors * Machine->gfx[1]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i]) = *(color_prom++) & 0x0f;
 for (i = 0;i < (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i]) = (*(color_prom++) & 0x0f) + 0x10;
}

canonical_original_code:
void pooyan_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  int bit0; int bit1; int bit2;
  bit0 = (*color_prom >> 0) & 0x01;
  bit1 = (*color_prom >> 1) & 0x01;
  bit2 = (*color_prom >> 2) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = (*color_prom >> 3) & 0x01;
  bit1 = (*color_prom >> 4) & 0x01;
  bit2 = (*color_prom >> 5) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = 0;
  bit1 = (*color_prom >> 6) & 0x01;
  bit2 = (*color_prom >> 7) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  color_prom++;
 }
 for (i = 0;i < (Machine->gfx[1]->total_colors * Machine->gfx[1]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i]) = *(color_prom++) & 0x0f;
 for (i = 0;i < (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i]) = (*(color_prom++) & 0x0f) + 0x10;
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int


decompiled_code:
void *__fastcall pooyan_flipscreen_w(__int64 a1, char a2)
{
void *result; // rax

result = (void *)(a2 & 1);
if ( (_DWORD)result != flipscreen )
{
flipscreen = a2 & 1;
result = memset(dirtybuffer, 1, videoram_size);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(__int64 a1, char a2)
{
void *result; // rax

result = (void *)(a2 & 1);
if ( (_DWORD)result != flipscreen )
{
flipscreen = a2 & 1;
result = memset(dirtybuffer, 1, videoram_size);
}
return result;
}

original_code:
void pooyan_flipscreen_w(offs_t offset,data_t data)
{
 if (flipscreen != (data & 1))
 {
  flipscreen = data & 1;
  memset(dirtybuffer,1,videoram_size);
 }
}

canonical_original_code:
void pooyan_flipscreen_w(unsigned int offset, unsigned int data)
{
 if (flipscreen != (data & 1))
 {
  flipscreen = data & 1;
  memset(dirtybuffer,1,videoram_size);
 }
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int

return_type: void


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

if ( lastdata_0 != a2 )
{
osd_led_w(0LL, ~((a2 >> 4) & 1));
osd_led_w(1LL, ~((a2 >> 5) & 1));
coin_counter_w(0LL, a2 & 1);
result = coin_counter_w(1LL, a2 & 2);
lastdata_0 = a2;
}
return result;
}

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

if ( lastdata_0 != a2 )
{
osd_led_w(0LL, ~((a2 >> 4) & 1));
osd_led_w(1LL, ~((a2 >> 5) & 1));
coin_counter_w(0LL, a2 & 1);
result = coin_counter_w(1LL, a2 & 2);
lastdata_0 = a2;
}
return result;
}

original_code:
void bwidow_misc_w(offs_t offset,data_t data)
{
 static int lastdata;
 if (data == lastdata) return;
 osd_led_w (0, ~((data & 0x10) >> 4));
 osd_led_w (1, ~((data & 0x20) >> 5));
 coin_counter_w (0, data & 0x01);
 coin_counter_w (1, data & 0x02);
 lastdata = data;
}

canonical_original_code:
void bwidow_misc_w(unsigned int offset, unsigned int data)
{
 static int lastdata;
 if (data == lastdata) return;
 osd_led_w (0, ~((data & 0x10) >> 4));
 osd_led_w (1, ~((data & 0x20) >> 5));
 coin_counter_w (0, data & 0x01);
 coin_counter_w (1, data & 0x02);
 lastdata = data;
}

variable_types: lastdata int


decompiled_code:
__int64 __fastcall spacduel_IN3_r(char a1)
{
char v1; // bp
char v2; // dl
__int64 result; // rax

v1 = readinputport(3LL);
v2 = readinputport(4LL);
switch ( a1 & 7 )
{
case 0:
result = v1 & 8;
if ( (v1 & 8) != 0 )
result = 128LL;
if ( (v1 & 4) != 0 )
result = (unsigned int)result | 0x40;
break;
case 1:
result = v2 & 8;
if ( (v2 & 8) != 0 )
result = 128LL;
if ( (v2 & 4) != 0 )
result = (unsigned int)result | 0x40;
break;
case 2:
result = v1 & 1;
if ( (v1 & 1) != 0 )
result = 128LL;
if ( (v1 & 2) != 0 )
result = (unsigned int)result | 0x40;
break;
case 3:
result = v2 & 1;
if ( (v2 & 1) != 0 )
result = 128LL;
if ( (v2 & 2) != 0 )
result = (unsigned int)result | 0x40;
break;
case 4:
result = v1 & 0x10;
if ( (v1 & 0x10) != 0 )
result = 128LL;
if ( (v1 & 0x20) != 0 )
result = (unsigned int)result | 0x40;
break;
case 5:
result = v2 & 0x10;
if ( (v2 & 0x10) != 0 )
result = 128LL;
break;
case 6:
result = v1 & 0x40;
if ( (v1 & 0x40) != 0 )
result = 128LL;
break;
default:
result = 0LL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char a1)
{
char v1; // bp
char v2; // dl
__int64 result; // rax

v1 = readinputport(3LL);
v2 = readinputport(4LL);
switch ( a1 & 7 )
{
case 0:
result = v1 & 8;
if ( (v1 & 8) != 0 )
result = 128LL;
if ( (v1 & 4) != 0 )
result = (unsigned int)result | 0x40;
break;
case 1:
result = v2 & 8;
if ( (v2 & 8) != 0 )
result = 128LL;
if ( (v2 & 4) != 0 )
result = (unsigned int)result | 0x40;
break;
case 2:
result = v1 & 1;
if ( (v1 & 1) != 0 )
result = 128LL;
if ( (v1 & 2) != 0 )
result = (unsigned int)result | 0x40;
break;
case 3:
result = v2 & 1;
if ( (v2 & 1) != 0 )
result = 128LL;
if ( (v2 & 2) != 0 )
result = (unsigned int)result | 0x40;
break;
case 4:
result = v1 & 0x10;
if ( (v1 & 0x10) != 0 )
result = 128LL;
if ( (v1 & 0x20) != 0 )
result = (unsigned int)result | 0x40;
break;
case 5:
result = v2 & 0x10;
if ( (v2 & 0x10) != 0 )
result = 128LL;
break;
case 6:
result = v1 & 0x40;
if ( (v1 & 0x40) != 0 )
result = 128LL;
break;
default:
result = 0LL;
break;
}
return result;
}

original_code:
static data_t spacduel_IN3_r(offs_t offset) {
 int res;
 int res1;
 int res2;
 res1 = readinputport(3);
 res2 = readinputport(4);
 res = 0x00;
 switch (offset & 0x07) {
  case 0:
   if (res1 & (1 << 3)) res |= 0x80;
   if (res1 & (1 << 2)) res |= 0x40;
   break;
  case 1:
   if (res2 & (1 << 3)) res |= 0x80;
   if (res2 & (1 << 2)) res |= 0x40;
   break;
  case 2:
   if (res1 & (1 << 0)) res |= 0x80;
   if (res1 & (1 << 1)) res |= 0x40;
   break;
  case 3:
   if (res2 & (1 << 0)) res |= 0x80;
   if (res2 & (1 << 1)) res |= 0x40;
   break;
  case 4:
   if (res1 & (1 << 4)) res |= 0x80;
   if (res1 & (1 << 5)) res |= 0x40;
   break;
  case 5:
   if (res2 & (1 << 4)) res |= 0x80;
   break;
  case 6:
   if (res1 & (1 << 6)) res |= 0x80;
   break;
  case 7:
   res = (0x00 | (0 & 0x40));
   break;
  }
 return res;
 }

canonical_original_code:
static unsigned int spacduel_IN3_r(unsigned int offset) {
 int res;
 int res1;
 int res2;
 res1 = readinputport(3);
 res2 = readinputport(4);
 res = 0x00;
 switch (offset & 0x07) {
  case 0:
   if (res1 & (1 << 3)) res |= 0x80;
   if (res1 & (1 << 2)) res |= 0x40;
   break;
  case 1:
   if (res2 & (1 << 3)) res |= 0x80;
   if (res2 & (1 << 2)) res |= 0x40;
   break;
  case 2:
   if (res1 & (1 << 0)) res |= 0x80;
   if (res1 & (1 << 1)) res |= 0x40;
   break;
  case 3:
   if (res2 & (1 << 0)) res |= 0x80;
   if (res2 & (1 << 1)) res |= 0x40;
   break;
  case 4:
   if (res1 & (1 << 4)) res |= 0x80;
   if (res1 & (1 << 5)) res |= 0x40;
   break;
  case 5:
   if (res2 & (1 << 4)) res |= 0x80;
   break;
  case 6:
   if (res1 & (1 << 6)) res |= 0x80;
   break;
  case 7:
   res = (0x00 | (0 & 0x40));
   break;
  }
 return res;
 }

variable_types: res int

return_type: unsigned int


decompiled_code:
__int64 __fastcall coin_2_w(__int64 a1, char a2)
{
return coin_counter_w(1LL, a2 & 1);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, char a2)
{
return coin_counter_w(1LL, a2 & 1);
}

original_code:
static void coin_2_w(offs_t offset,data_t data)
{
 coin_counter_w(1,data & 1);
}

canonical_original_code:
static void coin_2_w(unsigned int offset, unsigned int data)
{
 coin_counter_w(1,data & 1);
}


decompiled_code:
__int64 __fastcall coin_1_w(__int64 a1, char a2)
{
return coin_counter_w(0LL, a2 & 1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, char a2)
{
return coin_counter_w(0LL, a2 & 1);
}

original_code:
static void coin_1_w(offs_t offset,data_t data)
{
 coin_counter_w(0,data & 1);
}

canonical_original_code:
static void coin_1_w(unsigned int offset, unsigned int data)
{
 coin_counter_w(0,data & 1);
}


repo: libtrading/libtrading

original_code:
static unsigned long fix_new_order_single_const_fields(struct fix_field *fields)
{
 unsigned long nr = 0;
 fields[nr++] = (struct fix_field) { .tag = 50, .type = FIX_TYPE_STRING, { .string_value = "AAA" }, };
 fields[nr++] = (struct fix_field) { .tag = 57, .type = FIX_TYPE_STRING, { .string_value = "CME" }, };
 fields[nr++] = (struct fix_field) { .tag = 142, .type = FIX_TYPE_STRING, { .string_value = "CH" }, };
 fields[nr++] = (struct fix_field) { .tag = Account, .type = FIX_TYPE_STRING, { .string_value = "1234567" }, };
 fields[nr++] = (struct fix_field) { .tag = 21, .type = FIX_TYPE_CHAR, { .char_value = 'Y' }, };
 fields[nr++] = (struct fix_field) { .tag = OrdType, .type = FIX_TYPE_CHAR, { .char_value = '2' }, };
 fields[nr++] = (struct fix_field) { .tag = 1028, .type = FIX_TYPE_CHAR, { .char_value = 'Y' }, };
 fields[nr++] = (struct fix_field) { .tag = 1091, .type = FIX_TYPE_CHAR, { .char_value = 'N' }, };
 fields[nr++] = (struct fix_field) { .tag = 167, .type = FIX_TYPE_STRING, { .string_value = "FUT" }, };
 fields[nr++] = (struct fix_field) { .tag = 204, .type = FIX_TYPE_CHAR, { .char_value = '0' }, };
 fields[nr++] = (struct fix_field) { .tag = 9702, .type = FIX_TYPE_CHAR, { .char_value = '4' }, };
 return nr;
}

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

variable_types:
nr
unsigned long

return_type: unsigned long

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


original_code:
static unsigned long fix_new_order_single_variable_fields(struct fix_field *fields)
{
 unsigned long nr = 0;
 fields[nr++] = (struct fix_field) { .tag = Side, .type = FIX_TYPE_CHAR, { .char_value = '1' }, };
 fields[nr++] = (struct fix_field) { .tag = Symbol, .type = FIX_TYPE_STRING, { .string_value = "ES" }, };
 fields[nr++] = (struct fix_field) { .tag = 107, .type = FIX_TYPE_STRING, { .string_value = "ESM5" }, };
 fields[nr++] = (struct fix_field) { .tag = ClOrdID, .type = FIX_TYPE_STRING, { .string_value = "ClOrdID" }, };
 fields[nr++] = (struct fix_field) { .tag = 9717, .type = FIX_TYPE_STRING, { .string_value = "ClOrdID" }, };
 fields[nr++] = (struct fix_field) { .tag = OrderQty, .type = FIX_TYPE_FLOAT, { .float_value = 1 }, };
 fields[nr++] = (struct fix_field) { .tag = Price, .type = FIX_TYPE_FLOAT, { .float_value = 10000 }, };
 return nr;
}

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


decompiled_code:
_QWORD *new_order_single_message()
{
void *v0; // rdi
__int64 v1; // rbp
_QWORD *result; // rax
char v3[88]; // [rsp+0h] [rbp-58h] BYREF

strcpy(v3, "20121227-11:20:43.000");
v0 = calloc(0x30uLL, 0x10uLL);
v1 = fix_new_order_single_fields((__int64)v0, (__int64)v3);
result = (_QWORD *)fix_message_new();
result[1] = "FIX.4.2";
*result = 8LL;
result[4] = "DLD_TEX";
result[5] = "TEX_DLD";
result[6] = 499650LL;
result[8] = v3;
result[12] = v0;
result[11] = v1;
return result;
}

canonical_decompiled_code:
_QWORD *func7()
{
void *v0; // rdi
__int64 v1; // rbp
_QWORD *result; // rax
char v3[88]; // [rsp+0h] [rbp-58h] BYREF

strcpy(v3, "20121227-11:20:43.000");
v0 = calloc(0x30uLL, 0x10uLL);
v1 = func4((__int64)v0, (__int64)v3);
result = (_QWORD *)fix_message_new();
result[1] = "FIX.4.2";
*result = 8LL;
result[4] = "DLD_TEX";
result[5] = "TEX_DLD";
result[6] = 499650LL;
result[8] = v3;
result[12] = v0;
result[11] = v1;
return result;
}

original_code:
static struct fix_message *new_order_single_message(void)
{
 struct fix_field *fields = ((void *)0);
 struct fix_message *msg;
 char now[64];
 size_t nr;
 snprintf(now, 64, "20121227-11:20:43.000");
 fields = calloc(48, sizeof(struct fix_field));
 nr = fix_new_order_single_fields(fields, now);
 msg = fix_message_new();
 msg->begin_string = "FIX.4.2";
 msg->type = FIX_MSG_TYPE_NEW_ORDER_SINGLE;
 msg->sender_comp_id = "DLD_TEX";
 msg->target_comp_id = "TEX_DLD";
 msg->msg_seq_num = 499650;
 msg->str_now = now;
 msg->fields = fields;
 msg->nr_fields = nr;
 return msg;
}

canonical_original_code:
static struct fix_message *new_order_single_message()
{
 struct fix_field *fields = ((void *)0);
 struct fix_message *msg;
 char now[64];
 unsigned long nr;
 snprintf(now, 64, "20121227-11:20:43.000");
 fields = calloc(48, sizeof(struct fix_field));
 nr = fix_new_order_single_fields(fields, now);
 msg = fix_message_new();
 msg->begin_string = "FIX.4.2";
 msg->type = FIX_MSG_TYPE_NEW_ORDER_SINGLE;
 msg->sender_comp_id = "DLD_TEX";
 msg->target_comp_id = "TEX_DLD";
 msg->msg_seq_num = 499650;
 msg->str_now = now;
 msg->fields = fields;
 msg->nr_fields = nr;
 return msg;
}

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

variable_types:
now
char [64]

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


decompiled_code:
__int64 __fastcall fix_message_unparse_benchmark(int a1, __int64 a2, __int64 a3)
{
_QWORD *v4; // rbx
int i; // ebp
__int64 v6; // rax
double v7; // xmm0_8
struct timespec v9; // [rsp+0h] [rbp-48h] BYREF
struct timespec tp; // [rsp+10h] [rbp-38h] BYREF

v4 = new_order_single_message();
v4[9] = a2;
v4[10] = a3;
clock_gettime(1, &tp);
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
{
buffer_reset((_QWORD *)v4[9]);
buffer_reset((_QWORD *)v4[10]);
fix_message_unparse(v4);
}
}
clock_gettime(1, &v9);
v6 = timespec_delta(&tp, &v9);
if ( v6 < 0 )
v7 = (double)(int)(v6 & 1 | ((unsigned __int64)v6 >> 1)) + (double)(int)(v6 & 1 | ((unsigned __int64)v6 >> 1));
else
v7 = (double)(int)v6;
printf(LC15, "format ", (unsigned int)a1, v7 / (double)a1 / 1000.0);
return fix_message_free(v4);
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, __int64 a2, __int64 a3)
{
_QWORD *v4; // rbx
int i; // ebp
__int64 v6; // rax
double v7; // xmm0_8
struct timespec v9; // [rsp+0h] [rbp-48h] BYREF
struct timespec tp; // [rsp+10h] [rbp-38h] BYREF

v4 = func7();
v4[9] = a2;
v4[10] = a3;
clock_gettime(1, &tp);
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
{
func2((_QWORD *)v4[9]);
func2((_QWORD *)v4[10]);
fix_message_unparse(v4);
}
}
clock_gettime(1, &v9);
v6 = func3(&tp, &v9);
if ( v6 < 0 )
v7 = (double)(int)(v6 & 1 | ((unsigned __int64)v6 >> 1)) + (double)(int)(v6 & 1 | ((unsigned __int64)v6 >> 1));
else
v7 = (double)(int)v6;
printf(LC15, "format ", (unsigned int)a1, v7 / (double)a1 / 1000.0);
return fix_message_free(v4);
}

original_code:
static void fix_message_unparse_benchmark(const int count, struct buffer *head_buf, struct buffer *body_buf)
{
 struct timespec start, end;
 struct fix_message *msg;
 uint64_t elapsed_nsec;
 int i;
 msg = new_order_single_message();
 msg->head_buf = head_buf;
 msg->body_buf = body_buf;
 clock_gettime(1, &start);
 for (i = 0; i < count; i++) {
  buffer_reset(msg->head_buf);
  buffer_reset(msg->body_buf);
  fix_message_unparse(msg);
 }
 clock_gettime(1, &end);
 elapsed_nsec = timespec_delta(&start, &end);
 printf("%-10s %d %f µs/message\n", "format      ", count, (double)elapsed_nsec/(double)count/1000.0);
 fix_message_free(msg);
}

canonical_original_code:
static void fix_message_unparse_benchmark(int count, struct buffer *head_buf, struct buffer *body_buf)
{
 struct timespec start; struct timespec end;
 struct fix_message *msg;
 unsigned long elapsed_nsec;
 int i;
 msg = new_order_single_message();
 msg->head_buf = head_buf;
 msg->body_buf = body_buf;
 clock_gettime(1, &start);
 for (i = 0; i < count; i++) {
  buffer_reset(msg->head_buf);
  buffer_reset(msg->body_buf);
  fix_message_unparse(msg);
 }
 clock_gettime(1, &end);
 elapsed_nsec = timespec_delta(&start, &end);
 printf("%-10s %d %f µs/message\n", "format      ", count, (double)elapsed_nsec/(double)count/1000.0);
 fix_message_free(msg);
}

variable_types: count int

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

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

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

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


decompiled_code:
int __fastcall fix_message_parse_benchmark(int a1, _QWORD *a2, __int64 a3, int a4)
{
int i; // ebx
__int64 v7; // rax
double v8; // xmm0_8
double v9; // xmm0_8
const char *v10; // rsi
struct timespec v12; // [rsp+0h] [rbp-58h] BYREF
struct timespec tp; // [rsp+10h] [rbp-48h] BYREF

*a2 = 0LL;
clock_gettime(1, &tp);
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
{
*a2 = 0LL;
fix_message_parse(a3, (char *)&fix_dialects + 32, a2, a4);
}
}
clock_gettime(1, &v12);
v7 = timespec_delta(&tp, &v12);
if ( v7 < 0 )
v8 = (double)(int)(v7 & 1 | ((unsigned __int64)v7 >> 1)) + (double)(int)(v7 & 1 | ((unsigned __int64)v7 >> 1));
else
v8 = (double)(int)v7;
v9 = v8 / (double)a1 / 1000.0;
v10 = "parse/fast ";
if ( (a4 & 1) == 0 )
v10 = "parse ";
return printf(LC15, v10, (unsigned int)a1, v9);
}

canonical_decompiled_code:
int __fastcall func9(int a1, _QWORD *a2, __int64 a3, int a4)
{
int i; // ebx
__int64 v7; // rax
double v8; // xmm0_8
double v9; // xmm0_8
const char *v10; // rsi
struct timespec v12; // [rsp+0h] [rbp-58h] BYREF
struct timespec tp; // [rsp+10h] [rbp-48h] BYREF

*a2 = 0LL;
clock_gettime(1, &tp);
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
{
*a2 = 0LL;
fix_message_parse(a3, (char *)&fix_dialects + 32, a2, a4);
}
}
clock_gettime(1, &v12);
v7 = func3(&tp, &v12);
if ( v7 < 0 )
v8 = (double)(int)(v7 & 1 | ((unsigned __int64)v7 >> 1)) + (double)(int)(v7 & 1 | ((unsigned __int64)v7 >> 1));
else
v8 = (double)(int)v7;
v9 = v8 / (double)a1 / 1000.0;
v10 = "parse/fast ";
if ( (a4 & 1) == 0 )
v10 = "parse ";
return printf(LC15, v10, (unsigned int)a1, v9);
}

original_code:
static void fix_message_parse_benchmark(const int count, struct buffer *rx_buf, struct fix_message *rx_msg, int flags)
{
 struct timespec start, end;
 uint64_t elapsed_nsec;
 int i;
 rx_buf->start = 0;
 clock_gettime(1, &start);
 for (i = 0; i < count; i++) {
  rx_buf->start = 0;
  fix_message_parse(rx_msg, &fix_dialects[FIX_4_2], rx_buf, flags);
 }
 clock_gettime(1, &end);
 elapsed_nsec = timespec_delta(&start, &end);
 printf("%-10s %d %f µs/message\n", (flags & FIX_PARSE_FLAG_NO_CSUM ? "parse/fast  " : "parse       "), count, (double)elapsed_nsec/(double)count/1000.0);
}

canonical_original_code:
static void fix_message_parse_benchmark(int count, struct buffer *rx_buf, struct fix_message *rx_msg, int flags)
{
 struct timespec start; struct timespec end;
 unsigned long elapsed_nsec;
 int i;
 rx_buf->start = 0;
 clock_gettime(1, &start);
 for (i = 0; i < count; i++) {
  rx_buf->start = 0;
  fix_message_parse(rx_msg, &fix_dialects[FIX_4_2], rx_buf, flags);
 }
 clock_gettime(1, &end);
 elapsed_nsec = timespec_delta(&start, &end);
 printf("%-10s %d %f µs/message\n", (flags & FIX_PARSE_FLAG_NO_CSUM ? "parse/fast  " : "parse       "), count, (double)elapsed_nsec/(double)count/1000.0);
}

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

variable_types: flags int

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

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


decompiled_code:
__int64 __fastcall fix_template_unparse_benchmark(int a1, __int64 a2, __int64 a3)
{
__int64 v4; // rbp
int i; // ebx
__int64 v6; // rax
double v7; // xmm0_8
const char *v8; // rbx
int v9; // eax
unsigned int v10; // eax
struct timespec v12; // [rsp+0h] [rbp-198h] BYREF
struct timespec tp; // [rsp+10h] [rbp-188h] BYREF
char v14[32]; // [rsp+20h] [rbp-178h] BYREF
const char *v15; // [rsp+40h] [rbp-158h]
__int64 v16; // [rsp+58h] [rbp-140h]
char v17[24]; // [rsp+98h] [rbp-100h] BYREF
__int64 v18; // [rsp+B0h] [rbp-E8h]
__int64 v19; // [rsp+B8h] [rbp-E0h]
__int64 v20; // [rsp+C0h] [rbp-D8h]
__int64 v21; // [rsp+C8h] [rbp-D0h]
__int64 v22; // [rsp+D0h] [rbp-C8h]

v4 = new_order_single_template(v17);
strcpy(v17, "20121227-11:20:43.000");
v18 = 0LL;
v19 = 0LL;
v20 = 0LL;
v21 = 0LL;
v22 = 0LL;
fix_template_update_time(v4, v17);
v16 = 499650LL;
v15 = "ABC_DEF";
clock_gettime(1, &tp);
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
{
++v16;
fix_template_unparse(v4, v14);
}
}
clock_gettime(1, &v12);
v6 = timespec_delta(&tp, &v12);
if ( v6 < 0 )
v7 = (double)(int)(v6 & 1 | ((unsigned __int64)v6 >> 1)) + (double)(int)(v6 & 1 | ((unsigned __int64)v6 >> 1));
else
v7 = (double)(int)v6;
printf(LC15, "format/templ", (unsigned int)a1, v7 / (double)a1 / 1000.0);
v8 = (const char *)buffer_start((_QWORD *)(v4 + 72));
v9 = buffer_size((_QWORD *)(v4 + 72));
buffer_printf(a2, "%.*s", v9, v8);
v10 = fix_message_parse(a3, (char *)&fix_dialects + 32, a2, 0LL);
printf("template unparse status: %i\n", v10);
return fix_template_free(v4);
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1, __int64 a2, __int64 a3)
{
__int64 v4; // rbp
int i; // ebx
__int64 v6; // rax
double v7; // xmm0_8
const char *v8; // rbx
int v9; // eax
unsigned int v10; // eax
struct timespec v12; // [rsp+0h] [rbp-198h] BYREF
struct timespec tp; // [rsp+10h] [rbp-188h] BYREF
char v14[32]; // [rsp+20h] [rbp-178h] BYREF
const char *v15; // [rsp+40h] [rbp-158h]
__int64 v16; // [rsp+58h] [rbp-140h]
char v17[24]; // [rsp+98h] [rbp-100h] BYREF
__int64 v18; // [rsp+B0h] [rbp-E8h]
__int64 v19; // [rsp+B8h] [rbp-E0h]
__int64 v20; // [rsp+C0h] [rbp-D8h]
__int64 v21; // [rsp+C8h] [rbp-D0h]
__int64 v22; // [rsp+D0h] [rbp-C8h]

v4 = func10(v17);
strcpy(v17, "20121227-11:20:43.000");
v18 = 0LL;
v19 = 0LL;
v20 = 0LL;
v21 = 0LL;
v22 = 0LL;
fix_template_update_time(v4, v17);
v16 = 499650LL;
v15 = "ABC_DEF";
clock_gettime(1, &tp);
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
{
++v16;
fix_template_unparse(v4, v14);
}
}
clock_gettime(1, &v12);
v6 = func3(&tp, &v12);
if ( v6 < 0 )
v7 = (double)(int)(v6 & 1 | ((unsigned __int64)v6 >> 1)) + (double)(int)(v6 & 1 | ((unsigned __int64)v6 >> 1));
else
v7 = (double)(int)v6;
printf(LC15, "format/templ", (unsigned int)a1, v7 / (double)a1 / 1000.0);
v8 = (const char *)func0((_QWORD *)(v4 + 72));
v9 = func1((_QWORD *)(v4 + 72));
buffer_printf(a2, "%.*s", v9, v8);
v10 = fix_message_parse(a3, (char *)&fix_dialects + 32, a2, 0LL);
printf("template unparse status: %i\n", v10);
return fix_template_free(v4);
}

original_code:
static void fix_template_unparse_benchmark(const int count, struct buffer *rx_buf, struct fix_message *rx_msg)
{
 struct fix_template *template;
 struct fix_session session;
 struct timespec start, end;
 uint64_t elapsed_nsec;
 int templ_parse;
 int i;
 template = new_order_single_template(session.str_now);
 strncpy(session.str_now, "20121227-11:20:43.000", 64);
 fix_template_update_time(template, session.str_now);
 session.out_msg_seq_num = 499650;
 session.sender_comp_id = "ABC_DEF";
 clock_gettime(1, &start);
 for (i = 0; i < count; i++) {
  session.out_msg_seq_num++;
  fix_template_unparse(template, &session);
 }
 clock_gettime(1, &end);
 elapsed_nsec = timespec_delta(&start, &end);
 printf("%-10s %d %f µs/message\n", "format/templ", count, (double)elapsed_nsec/(double)count/1000.0);
 buffer_printf(rx_buf, "%.*s", (int)buffer_size(&template->buf), buffer_start(&template->buf));
 templ_parse = fix_message_parse(rx_msg, &fix_dialects[FIX_4_2], rx_buf, 0);
 printf("template unparse status: %i\n", templ_parse);
 fix_template_free(template);
}

canonical_original_code:
static void fix_template_unparse_benchmark(int count, struct buffer *rx_buf, struct fix_message *rx_msg)
{
 struct fix_template *template;
 struct fix_session session;
 struct timespec start; struct timespec end;
 unsigned long elapsed_nsec;
 int templ_parse;
 int i;
 template = new_order_single_template(session.str_now);
 strncpy(session.str_now, "20121227-11:20:43.000", 64);
 fix_template_update_time(template, session.str_now);
 session.out_msg_seq_num = 499650;
 session.sender_comp_id = "ABC_DEF";
 clock_gettime(1, &start);
 for (i = 0; i < count; i++) {
  session.out_msg_seq_num++;
  fix_template_unparse(template, &session);
 }
 clock_gettime(1, &end);
 elapsed_nsec = timespec_delta(&start, &end);
 printf("%-10s %d %f µs/message\n", "format/templ", count, (double)elapsed_nsec/(double)count/1000.0);
 buffer_printf(rx_buf, "%.*s", (int)buffer_size(&template->buf), buffer_start(&template->buf));
 templ_parse = fix_message_parse(rx_msg, &fix_dialects[FIX_4_2], rx_buf, 0);
 printf("template unparse status: %i\n", templ_parse);
 fix_template_free(template);
}

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

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

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

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

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


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

va_start(arg, a1);
vprintf(a1, arg);
putchar(10);
exit(1);
}

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

va_start(arg, a1);
vprintf(a1, arg);
putchar(10);
exit(1);
}

original_code:
void do_die(const char *format, ...)
{
 va_list ap;
 __builtin_va_start(ap,format);
 vprintf(format, ap);
 __builtin_va_end(ap);
 printf("\n");
 exit(1);
}

canonical_original_code:
void do_die(char *format, ...)
{
 __builtin_va_list ap;
 __builtin_va_start(ap,format);
 vprintf(format, ap);
 __builtin_va_end(ap);
 printf("\n");
 exit(1);
}

variable_types:
format
char *


error

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

va_start(arg, format);
printf("error: ");
vprintf(format, arg);
putchar(10);
exit(1);
}

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

va_start(arg, format);
printf("error: ");
vprintf(format, arg);
putchar(10);
exit(1);
}

original_code:
void error(const char *format, ...)
{
 va_list ap;
 printf("error: ");
 __builtin_va_start(ap,format);
 vprintf(format, ap);
 __builtin_va_end(ap);
 printf("\n");
 exit(1);
}

canonical_original_code:
void error(char *format, ...)
{
 __builtin_va_list ap;
 printf("error: ");
 __builtin_va_start(ap,format);
 vprintf(format, ap);
 __builtin_va_end(ap);
 printf("\n");
 exit(1);
}


decompiled_code:
signed __int64 __fastcall modp_itoa10(int a1, unsigned __int8 *a2)
{
unsigned int v2; // edx
unsigned __int8 *v3; // rbx
unsigned __int8 *v4; // r8
unsigned int v5; // ecx

v2 = abs32(a1);
v3 = a2;
do
{
v4 = v3++;
*(v3 - 1) = v2 % 0xA + 48;
v5 = v2;
v2 /= 0xAu;
}
while ( v5 > 9 );
if ( a1 < 0 )
{
*v3 = 45;
v3 = v4 + 2;
}
*v3 = 0;
strreverse(a2, v3 - 1);
return v3 - a2;
}

canonical_decompiled_code:
signed __int64 __fastcall func1(int a1, unsigned __int8 *a2)
{
unsigned int v2; // edx
unsigned __int8 *v3; // rbx
unsigned __int8 *v4; // r8
unsigned int v5; // ecx

v2 = abs32(a1);
v3 = a2;
do
{
v4 = v3++;
*(v3 - 1) = v2 % 0xA + 48;
v5 = v2;
v2 /= 0xAu;
}
while ( v5 > 9 );
if ( a1 < 0 )
{
*v3 = 45;
v3 = v4 + 2;
}
*v3 = 0;
func0(a2, v3 - 1);
return v3 - a2;
}

original_code:
size_t modp_itoa10(int32_t value, char* str)
{
    char* wstr=str;
    uint32_t uvalue = (value < 0) ? (uint32_t)(-value) : (uint32_t)(value);
    do *wstr++ = (char)(48 + (uvalue % 10)); while(uvalue /= 10);
    if (value < 0) *wstr++ = '-';
    *wstr='\0';
    strreverse(str,wstr-1);
    return (size_t)(wstr - str);
}

canonical_original_code:
unsigned long modp_itoa10(int value, char *str)
{
    char *wstr = str;
    unsigned int uvalue = (value < 0) ? (uint32_t)(-value) : (uint32_t)(value);
    do *wstr++ = (char)(48 + (uvalue % 10)); while(uvalue /= 10);
    if (value < 0) *wstr++ = '-';
    *wstr='\0';
    strreverse(str,wstr-1);
    return (unsigned long)(wstr - str);
}

variable_types: value int

variable_types:
str
char *

variable_types:
wstr
char *

variable_types:
uvalue
unsigned int


decompiled_code:
signed __int64 __fastcall modp_uitoa10(unsigned int a1, unsigned __int8 *a2)
{
unsigned __int8 *v2; // rbp
unsigned __int8 *v3; // rbx
unsigned __int8 *v4; // rsi
unsigned int v5; // edx

v2 = a2;
v3 = a2;
do
{
v4 = v3++;
*(v3 - 1) = a1 % 0xA + 48;
v5 = a1;
a1 /= 0xAu;
}
while ( v5 > 9 );
*v3 = 0;
strreverse(v2, v4);
return v3 - v2;
}

canonical_decompiled_code:
signed __int64 __fastcall func2(unsigned int a1, unsigned __int8 *a2)
{
unsigned __int8 *v2; // rbp
unsigned __int8 *v3; // rbx
unsigned __int8 *v4; // rsi
unsigned int v5; // edx

v2 = a2;
v3 = a2;
do
{
v4 = v3++;
*(v3 - 1) = a1 % 0xA + 48;
v5 = a1;
a1 /= 0xAu;
}
while ( v5 > 9 );
*v3 = 0;
func0(v2, v4);
return v3 - v2;
}

original_code:
size_t modp_uitoa10(uint32_t value, char* str)
{
    char* wstr=str;
    do *wstr++ = (char)(48 + (value % 10)); while (value /= 10);
    *wstr='\0';
    strreverse(str, wstr-1);
    return (size_t)(wstr - str);
}

canonical_original_code:
unsigned long modp_uitoa10(unsigned int value, char *str)
{
    char *wstr = str;
    do *wstr++ = (char)(48 + (value % 10)); while (value /= 10);
    *wstr='\0';
    strreverse(str, wstr-1);
    return (unsigned long)(wstr - str);
}

variable_types:
value
unsigned int


decompiled_code:
signed __int64 __fastcall modp_litoa10(__int64 a1, unsigned __int8 *a2)
{
unsigned __int64 v2; // rcx
unsigned __int8 *v3; // rbx
unsigned __int8 *v4; // r9
unsigned __int64 v5; // rax

v2 = abs64(a1);
v3 = a2;
do
{
v4 = v3++;
*(v3 - 1) = v2 % 0xA + 48;
v5 = v2;
v2 /= 0xAuLL;
}
while ( v5 > 9 );
if ( a1 < 0 )
{
*v3 = 45;
v3 = v4 + 2;
}
*v3 = 0;
strreverse(a2, v3 - 1);
return v3 - a2;
}

canonical_decompiled_code:
signed __int64 __fastcall func3(__int64 a1, unsigned __int8 *a2)
{
unsigned __int64 v2; // rcx
unsigned __int8 *v3; // rbx
unsigned __int8 *v4; // r9
unsigned __int64 v5; // rax

v2 = abs64(a1);
v3 = a2;
do
{
v4 = v3++;
*(v3 - 1) = v2 % 0xA + 48;
v5 = v2;
v2 /= 0xAuLL;
}
while ( v5 > 9 );
if ( a1 < 0 )
{
*v3 = 45;
v3 = v4 + 2;
}
*v3 = 0;
func0(a2, v3 - 1);
return v3 - a2;
}

original_code:
size_t modp_litoa10(int64_t value, char* str)
{
    char* wstr=str;
    uint64_t uvalue = (value < 0) ? (uint64_t)(-value) : (uint64_t)(value);
    do *wstr++ = (char)(48 + (uvalue % 10)); while(uvalue /= 10);
    if (value < 0) *wstr++ = '-';
    *wstr='\0';
    strreverse(str,wstr-1);
    return (size_t)(wstr - str);
}

canonical_original_code:
unsigned long modp_litoa10(long value, char *str)
{
    char *wstr = str;
    unsigned long uvalue = (value < 0) ? (uint64_t)(-value) : (uint64_t)(value);
    do *wstr++ = (char)(48 + (uvalue % 10)); while(uvalue /= 10);
    if (value < 0) *wstr++ = '-';
    *wstr='\0';
    strreverse(str,wstr-1);
    return (unsigned long)(wstr - str);
}

variable_types: value long

variable_types:
uvalue
unsigned long


decompiled_code:
signed __int64 __fastcall modp_ulitoa10(unsigned __int64 a1, unsigned __int8 *a2)
{
unsigned __int8 *v2; // rbp
unsigned __int8 *v3; // rbx
unsigned __int8 *v4; // rsi
unsigned __int64 v5; // rax

v2 = a2;
v3 = a2;
do
{
v4 = v3++;
*(v3 - 1) = a1 % 0xA + 48;
v5 = a1;
a1 /= 0xAuLL;
}
while ( v5 > 9 );
*v3 = 0;
strreverse(v2, v4);
return v3 - v2;
}

canonical_decompiled_code:
signed __int64 __fastcall func4(unsigned __int64 a1, unsigned __int8 *a2)
{
unsigned __int8 *v2; // rbp
unsigned __int8 *v3; // rbx
unsigned __int8 *v4; // rsi
unsigned __int64 v5; // rax

v2 = a2;
v3 = a2;
do
{
v4 = v3++;
*(v3 - 1) = a1 % 0xA + 48;
v5 = a1;
a1 /= 0xAuLL;
}
while ( v5 > 9 );
*v3 = 0;
func0(v2, v4);
return v3 - v2;
}

original_code:
size_t modp_ulitoa10(uint64_t value, char* str)
{
    char* wstr=str;
    do *wstr++ = (char)(48 + (value % 10)); while (value /= 10);
    *wstr='\0';
    strreverse(str, wstr-1);
    return (size_t)(wstr - str);
}

canonical_original_code:
unsigned long modp_ulitoa10(unsigned long value, char *str)
{
    char *wstr = str;
    do *wstr++ = (char)(48 + (value % 10)); while (value /= 10);
    *wstr='\0';
    strreverse(str, wstr-1);
    return (unsigned long)(wstr - str);
}

variable_types:
value
unsigned long


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

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

variable_types: value double

variable_types: prec int

variable_types: diff double

variable_types: neg int

variable_types: whole int

variable_types: tmp double

variable_types:
frac
unsigned int


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

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

variable_types: count int


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

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

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

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

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

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

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


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

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

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

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

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

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


decompiled_code:
__int64 __fastcall do_income(_QWORD *a1, int a2)
{
char *v2; // rbx
int v3; // edx
__int64 result; // rax
const char **v5; // rax
__int64 v6; // rax
char v7; // dl
char v8; // dl
__int64 v9; // rbx
_DWORD *v10; // rax
char v11; // dl
double *v12; // rax
double v13; // xmm0_8
double *v14; // rdx
double v15; // xmm0_8
__int64 v16; // [rsp+0h] [rbp-168h] BYREF
unsigned __int64 v17; // [rsp+8h] [rbp-160h]
__int64 v18; // [rsp+20h] [rbp-148h]
unsigned __int64 v19; // [rsp+28h] [rbp-140h]
__int64 v20[14]; // [rsp+30h] [rbp-138h] BYREF
int v21; // [rsp+A0h] [rbp-C8h]
__int64 v22[17]; // [rsp+C0h] [rbp-A8h] BYREF
__int64 v23[4]; // [rsp+148h] [rbp-20h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, int a2)
{
char *v2; // rbx
int v3; // edx
__int64 result; // rax
const char **v5; // rax
__int64 v6; // rax
char v7; // dl
char v8; // dl
__int64 v9; // rbx
_DWORD *v10; // rax
char v11; // dl
double *v12; // rax
double v13; // xmm0_8
double *v14; // rdx
double v15; // xmm0_8
__int64 v16; // [rsp+0h] [rbp-168h] BYREF
unsigned __int64 v17; // [rsp+8h] [rbp-160h]
__int64 v18; // [rsp+20h] [rbp-148h]
unsigned __int64 v19; // [rsp+28h] [rbp-140h]
__int64 v20[14]; // [rsp+30h] [rbp-138h] BYREF
int v21; // [rsp+A0h] [rbp-C8h]
__int64 v22[17]; // [rsp+C0h] [rbp-A8h] BYREF
__int64 v23[4]; // [rsp+148h] [rbp-20h] BYREF

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

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

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

variable_types: sockfd int

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

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

return_type: int

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


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

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

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

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

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

variable_types: events short

variable_types:
arg
void *


decompiled_code:
__int64 __fastcall market_init(char *a1)
{
memset(a1, 0, 0x76F88uLL);
return order_book_init(a1 + 5608);
}

canonical_decompiled_code:
__int64 __fastcall func7(char *a1)
{
memset(a1, 0, 0x76F88uLL);
return order_book_init(a1 + 5608);
}

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

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


usage

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

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

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

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


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

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

variable_types:
nr
unsigned long

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


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

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

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

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

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

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

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


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

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

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

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

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

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


decompiled_code:
__int64 fix_server_session()
{
__int64 v0; // rax
__int64 v1; // rbx
void *v2; // rax
void *v3; // rbp
__int64 v4; // r13
unsigned int v5; // er12
__int64 v7; // [rsp+0h] [rbp-148h] BYREF
char v8[128]; // [rsp+8h] [rbp-140h] BYREF
__int64 v9; // [rsp+88h] [rbp-C0h] BYREF
__int64 v10; // [rsp+90h] [rbp-B8h] BYREF
char v11[128]; // [rsp+98h] [rbp-B0h] BYREF

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

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rax
__int64 v1; // rbx
void *v2; // rax
void *v3; // rbp
__int64 v4; // r13
unsigned int v5; // er12
__int64 v7; // [rsp+0h] [rbp-148h] BYREF
char v8[128]; // [rsp+8h] [rbp-140h] BYREF
__int64 v9; // [rsp+88h] [rbp-C0h] BYREF
__int64 v10; // [rsp+90h] [rbp-B8h] BYREF
char v11[128]; // [rsp+98h] [rbp-B0h] BYREF

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

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

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

variable_types: struct fix_server_arg { char *script; } *

variable_types: ret int

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


strversion

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

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

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

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

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

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

variable_types:
dialect
char *


strservermode

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

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

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

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

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

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

variable_types:
mode
char *

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


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

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

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

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

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

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

variable_types: byte char


decompiled_code:
__int64 __fastcall fix_field_unparse_zpad(unsigned int *a1, unsigned int a2, __int64 a3)
{
__int64 v4; // rax
__int64 v5; // r12
char *v6; // r13
char *v7; // rbp
char i; // si

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

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int *a1, unsigned int a2, __int64 a3)
{
__int64 v4; // rax
__int64 v5; // r12
char *v6; // r13
char *v7; // rbp
char i; // si

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

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

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

variable_types: zpad int

variable_types:
marker
char *

variable_types:
p
char *

variable_types: i int

return_type: char *


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

result = calloc(1uLL, 0x790uLL);
if ( result )
{
result[11] = 1024LL;
result[12] = result + 13;
*((_DWORD *)result + 476) = 10;
*((_DWORD *)result + 477) = 4;
result[239] = 0LL;
}
return result;
}

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

result = calloc(1uLL, 0x790uLL);
if ( result )
{
result[11] = 1024LL;
result[12] = result + 13;
*((_DWORD *)result + 476) = 10;
*((_DWORD *)result + 477) = 4;
result[239] = 0LL;
}
return result;
}

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

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

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


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

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

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


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

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

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


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

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

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