decompiled_code:
__int64 run_commands()
{
unsigned int v0; // ebp
__int64 result; // rax
__int64 v2; // rdi
unsigned int v3; // eax
const char *v4; // rax
void *v5; // rdi
__int64 v6; // rdi
unsigned int v7; // eax
unsigned __int16 v8; // ax
__int16 v9; // ax
unsigned __int8 v10; // al
unsigned __int8 v11; // al
__int16 v12; // ax
unsigned __int8 v13; // al
unsigned __int8 v14; // al
__int16 v15; // ax
__int16 v16; // ax
__int16 v17; // ax
unsigned __int8 v18; // al
unsigned __int8 v19; // al
unsigned __int8 v20; // al
__int64 v21; // rax
__int16 v22; // ax
int v23; // eax
__int16 v24; // ax
__int16 v25; // ax
__int16 v26; // ax
__int16 v27; // ax
__int16 v28; // ax
__int16 v29; // ax
__int16 v30; // ax
__int16 v31; // ax
__int16 v32; // ax
__int16 v33; // ax
__int16 v34; // ax
__int16 v35; // ax
unsigned __int8 v36; // al
__int16 v37; // ax
__int16 v38; // ax
const char *v39; // rax
bool v40; // zf
__int16 v41; // ax
const char *v42; // rax
__int16 v43; // [rsp+0h] [rbp-128h] BYREF
void *v44; // [rsp+8h] [rbp-120h]
char v45[280]; // [rsp+10h] [rbp-118h] BYREF

v0 = cfgphase;
while ( 1 )
{
switch ( v0 )
{
case 0u:
show_idle_menu();
result = (unsigned __int8)(get_command_char() - 67);
switch ( (char)result )
{
case 0:
if ( context )
goto LABEL_9;
cfgphase = 1;
v0 = 1;
continue;
case 1:
if ( context )
goto LABEL_32;
goto LABEL_9;
case 2:
cfgphase = 2;
v0 = 2;
continue;
case 3:
cfgphase = 3;
v0 = 3;
continue;
case 10:
goto LABEL_10;
case 12:
if ( !context )
goto LABEL_9;
show_opstat();
v0 = cfgphase;
continue;
case 13:
v2 = context;
if ( !context )
goto LABEL_9;
if ( *((_WORD *)&configstruc + 507) )
*((_BYTE *)&configstruc + 496) = 0;
v3 = lib_unregistered_ping(v2, (unsigned int)((_DWORD)&configstruc + 488));
*((_DWORD *)&configstruc + 108) = v3;
if ( !v3 )
goto LABEL_9;
v4 = (const char *)lib_get_errstr(v3, v45);
printf("Error Pinging Station: %s\n", v4);
v0 = cfgphase;
continue;
case 14:
if ( poc_context )
{
puts("POC Receiver Stopped");
result = lib_poc_stop(poc_context);
}
if ( context )
result = lib_destroy_context(&context);
return result;
case 16:
v6 = context;
if ( !context )
goto LABEL_9;
if ( *((_WORD *)&configstruc + 507) )
*((_BYTE *)&configstruc + 496) = 0;
v7 = lib_register(v6, (unsigned int)((_DWORD)&configstruc + 488));
if ( v7 )
{
v39 = (const char *)lib_get_errstr(v7, v45);
printf("Error Starting Connection: %s\n", v39);
v0 = cfgphase;
}
else
{
cfgphase = 4;
v0 = 4;
}
continue;
case 17:
v5 = (void *)context;
if ( context )
{
lib_change_state(context, 1LL, 27LL);
v0 = cfgphase;
}
else
{
v40 = *((_WORD *)&configstruc + 518) == 0;
*((_QWORD *)&configstruc + 55) = &sen_state_callback;
*((_QWORD *)&configstruc + 56) = &msgs_callback;
if ( !v40 )
v5 = &amini_callback;
v40 = *((_WORD *)&configstruc + 517) == 0;
*((_QWORD *)&configstruc + 59) = 0LL;
*((_QWORD *)&configstruc + 51) = 0LL;
fowner[0] = &sen_file_callback;
fowner[1] = 0LL;
*((_QWORD *)&configstruc + 60) = fowner;
*((_QWORD *)&configstruc + 52) = &mini_callback;
*((_QWORD *)&configstruc + 53) = v5;
if ( v40 )
mseed_file = -1LL;
else
mseed_file = lib_file_open(0LL, "seneca.mseed", 9LL);
if ( *((_WORD *)&configstruc + 516) )
{
*((_QWORD *)&configstruc + 57) = &onesec_callback;
onesec_file = lib_file_open(0LL, "seneca.sec", 9LL);
}
else
{
*((_QWORD *)&configstruc + 57) = 0LL;
onesec_file = -1LL;
}
lib_create_context(&context, (unsigned int)((_DWORD)&configstruc + 8));
v0 = *((_DWORD *)&configstruc + 108);
if ( v0 )
{
context = 0LL;
v42 = (const char *)lib_get_errstr(v0, v45);
printf("Error creating station thread: %s\n", v42);
v0 = cfgphase;
}
else
{
puts("Station Thread Created");
v41 = *((_WORD *)&configstruc + 520);
cfgphase = 0;
if ( v41 )
{
v43 = v41;
v44 = &poc_handler;
poc_context = lib_poc_start(&v43);
puts("POC Receiver Started");
v0 = cfgphase;
}
}
}
continue;
default:
goto LABEL_9;
}
case 1u:
show_create_pars();
switch ( (unsigned __int8)get_command_char() )
{
case 'A':
get_t64("Serial number: ", (unsigned int)((_DWORD)&configstruc + 8));
v0 = cfgphase;
break;
case 'B':
v24 = get_word("Data port (1-4): ");
v0 = cfgphase;
*((_WORD *)&configstruc + 8) = v24 - 1;
break;
case 'C':
get_string("Station name (3-5 characters): ", 5LL, (unsigned int)((_DWORD)&configstruc + 18));
lib330_upper((unsigned int)((_DWORD)&configstruc + 18));
v0 = cfgphase;
break;
case 'D':
v23 = get_integer("Timezone offset in seconds: ");
v0 = cfgphase;
*((_DWORD *)&configstruc + 6) = v23;
break;
case 'E':
get_string("Host software name: ", 95LL, (unsigned int)((_DWORD)&configstruc + 28));
v0 = cfgphase;
break;
case 'F':
get_string("Continuity file name (Null to disable): ", 250LL, (unsigned int)((_DWORD)&configstruc + 124));
v0 = cfgphase;
break;
case 'G':
v22 = get_verbosity();
v0 = cfgphase;
*((_WORD *)&configstruc + 187) = v22;
break;
case 'H':
v21 = get_frequency("Highest frequency for incremental update: ");
v0 = cfgphase;
*((_QWORD *)&configstruc + 49) = v21;
break;
case 'I':
v20 = get_yesno("Embed blockettes (Y/n): ", 1LL);
v0 = cfgphase;
*((_WORD *)&configstruc + 200) = v20;
break;
case 'J':
v19 = get_yesno("Separate blockettes (y/N): ", 0LL);
v0 = cfgphase;
*((_WORD *)&configstruc + 201) = v19;
break;
case 'K':
v18 = get_yesno("Calculate host timezone automatically (Y/n): ", 1LL);
v0 = cfgphase;
*((_WORD *)&configstruc + 188) = v18;
break;
case 'L':
v17 = get_onesec_filter();
v0 = cfgphase;
*((_WORD *)&configstruc + 189) = v17;
break;
case 'M':
v16 = get_seed_filter("512 byte MiniSeed data filter: ");
v0 = cfgphase;
*((_WORD *)&configstruc + 192) = v16;
break;
case 'N':
v15 = get_seed_filter("Archival MiniSeed data filter: ");
v0 = cfgphase;
*((_WORD *)&configstruc + 193) = v15;
break;
case 'S':
goto LABEL_53;
case 'X':
goto LABEL_43;
default:
goto LABEL_9;
}
break;
case 2u:
show_register_pars();
switch ( (unsigned __int8)get_command_char() )
{
case 'A':
get_t64("Authentication code: ", (unsigned int)((_DWORD)&configstruc + 488));
v0 = cfgphase;
break;
case 'B':
get_string("Q330 IP address: ", 250LL, (unsigned int)((_DWORD)&configstruc + 496));
v0 = cfgphase;
break;
case 'C':
v30 = get_word("Q330 base port: ");
v0 = cfgphase;
*((_WORD *)&configstruc + 373) = v30;
break;
case 'E':
get_string("Host interface: ", 250LL, (unsigned int)((_DWORD)&configstruc + 752));
v0 = cfgphase;
break;
case 'F':
v29 = get_timeout("Host minimum command timeout: ");
v0 = cfgphase;
*((_WORD *)&configstruc + 501) = v29;
break;
case 'G':
v28 = get_timeout("Host maximum command timeout: ");
v0 = cfgphase;
*((_WORD *)&configstruc + 502) = v28;
break;
case 'H':
v38 = get_word("Host control port (0 for automatic): ");
v0 = cfgphase;
*((_WORD *)&configstruc + 503) = v38;
break;
case 'I':
v37 = get_word("Host data port (0 for automatic): ");
v0 = cfgphase;
*((_WORD *)&configstruc + 504) = v37;
break;
case 'J':
v36 = get_yesno("Q330 has dynamic IP address (y/N): ", 0LL);
v0 = cfgphase;
*((_WORD *)&configstruc + 507) = v36;
break;
case 'K':
v35 = get_word("Hibernate time in minutes: ");
v0 = cfgphase;
*((_WORD *)&configstruc + 508) = v35;
break;
case 'L':
v34 = get_word("Maximum connection time in minutes: ");
v0 = cfgphase;
*((_WORD *)&configstruc + 509) = v34;
break;
case 'M':
v33 = get_word("Connection wait time in minutes: ");
v0 = cfgphase;
*((_WORD *)&configstruc + 510) = v33;
break;
case 'N':
v32 = get_word("Maximum registration attempts before hibernation: ");
v0 = cfgphase;
*((_WORD *)&configstruc + 511) = v32;
break;
case 'O':
v31 = get_word("Dynamic IP address expiration in minutes: ");
v0 = cfgphase;
*((_WORD *)&configstruc + 512) = v31;
break;
case 'P':
v27 = get_word("Buffer level to stop connection: ");
v0 = cfgphase;
*((_WORD *)&configstruc + 513) = v27;
break;
case 'Q':
v26 = get_word("Minutes before writing Q330 continuity to file: ");
v0 = cfgphase;
*((_WORD *)&configstruc + 514) = v26;
break;
case 'R':
v25 = get_word("Maximum DSS memory in KB: ");
v0 = cfgphase;
*((_WORD *)&configstruc + 515) = v25;
break;
case 'S':
goto LABEL_53;
case 'X':
goto LABEL_43;
default:
goto LABEL_9;
}
break;
case 3u:
show_file_menu();
switch ( (unsigned __int8)get_command_char() )
{
case 'A':
v14 = get_yesno("Enable writing one second data to seneca.sec (y/N): ", 0LL);
v0 = cfgphase;
*((_WORD *)&configstruc + 516) = v14;
break;
case 'B':
v11 = get_yesno("Enable writing 512 byte MiniSeed to seneca.mseed (y/N): ", 0LL);
v0 = cfgphase;
*((_WORD *)&configstruc + 517) = v11;
break;
case 'C':
v10 = get_yesno("Enable writing 4096 byte MiniSeed to individual files (y/N): ", 0LL);
v0 = cfgphase;
*((_WORD *)&configstruc + 518) = v10;
break;
case 'D':
v13 = get_yesno("Enable NetServer if configured in tokens (y/N): ", 0LL);
v0 = cfgphase;
*((_WORD *)&configstruc + 519) = v13;
break;
case 'E':
v12 = get_word("POC Receiver port (zero to disable, standard is 2254): ");
v0 = cfgphase;
*((_WORD *)&configstruc + 520) = v12;
break;
case 'S':
LABEL_53:
save_configuration();
v0 = cfgphase;
break;
case 'X':
goto LABEL_43;
default:
goto LABEL_9;
}
break;
case 4u:
show_run_menu();
result = (unsigned __int8)(get_command_char() - 65);
switch ( (char)result )
{
case 0:
arp_status();
v0 = cfgphase;
continue;
case 2:
lib_abort_command(context);
v0 = cfgphase;
continue;
case 3:
LABEL_32:
dump_messages();
v0 = cfgphase;
continue;
case 5:
if ( current_state != 10 )
goto LABEL_9;
lib_flush_data(context);
v0 = cfgphase;
break;
case 6:
send_tunneled_request();
v0 = cfgphase;
continue;
case 7:
if ( current_state != 10 )
goto LABEL_9;
show_detectors();
v0 = cfgphase;
break;
case 8:
if ( current_state != 10 )
goto LABEL_9;
lib_set_freeze_timer(context, 30LL);
v0 = cfgphase;
break;
case 11:
show_lcqs();
v0 = cfgphase;
continue;
case 12:
LABEL_10:
show_modules();
v0 = cfgphase;
continue;
case 14:
screen_busy = 1;
show_opstat();
screen_busy = 0;
v0 = cfgphase;
continue;
case 15:
pingreq = 0LL;
lib_ping_request(context, &pingreq);
v0 = cfgphase;
continue;
case 16:
if ( context )
goto LABEL_9;
if ( poc_context )
{
puts("POC Receiver Stopped");
result = lib_poc_stop(poc_context);
}
return result;
case 18:
lib_change_state(context, 0LL, 27LL);
LABEL_43:
cfgphase = 0;
v0 = 0;
continue;
case 20:
screen_busy = 1;
printf("Message: ");
get_line(&line);
lib_send_usermessage(context, &line);
screen_busy = 0;
v0 = cfgphase;
continue;
case 21:
screen_busy = 1;
v8 = get_verbosity();
v9 = lib_change_verbosity(context, v8);
screen_busy = 0;
v0 = cfgphase;
*((_WORD *)&configstruc + 187) = v9;
continue;
default:
LABEL_9:
v0 = cfgphase;
break;
}
break;
default:
continue;
}
}
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int v0; // ebp
__int64 result; // rax
__int64 v2; // rdi
unsigned int v3; // eax
const char *v4; // rax
void *v5; // rdi
__int64 v6; // rdi
unsigned int v7; // eax
unsigned __int16 v8; // ax
__int16 v9; // ax
unsigned __int8 v10; // al
unsigned __int8 v11; // al
__int16 v12; // ax
unsigned __int8 v13; // al
unsigned __int8 v14; // al
__int16 v15; // ax
__int16 v16; // ax
__int16 v17; // ax
unsigned __int8 v18; // al
unsigned __int8 v19; // al
unsigned __int8 v20; // al
__int64 v21; // rax
__int16 v22; // ax
int v23; // eax
__int16 v24; // ax
__int16 v25; // ax
__int16 v26; // ax
__int16 v27; // ax
__int16 v28; // ax
__int16 v29; // ax
__int16 v30; // ax
__int16 v31; // ax
__int16 v32; // ax
__int16 v33; // ax
__int16 v34; // ax
__int16 v35; // ax
unsigned __int8 v36; // al
__int16 v37; // ax
__int16 v38; // ax
const char *v39; // rax
bool v40; // zf
__int16 v41; // ax
const char *v42; // rax
__int16 v43; // [rsp+0h] [rbp-128h] BYREF
void *v44; // [rsp+8h] [rbp-120h]
char v45[280]; // [rsp+10h] [rbp-118h] BYREF

v0 = cfgphase;
while ( 1 )
{
switch ( v0 )
{
case 0u:
show_idle_menu();
result = (unsigned __int8)(func0() - 67);
switch ( (char)result )
{
case 0:
if ( context )
goto LABEL_9;
cfgphase = 1;
v0 = 1;
continue;
case 1:
if ( context )
goto LABEL_32;
goto LABEL_9;
case 2:
cfgphase = 2;
v0 = 2;
continue;
case 3:
cfgphase = 3;
v0 = 3;
continue;
case 10:
goto LABEL_10;
case 12:
if ( !context )
goto LABEL_9;
show_opstat();
v0 = cfgphase;
continue;
case 13:
v2 = context;
if ( !context )
goto LABEL_9;
if ( *((_WORD *)&configstruc + 507) )
*((_BYTE *)&configstruc + 496) = 0;
v3 = lib_unregistered_ping(v2, (unsigned int)((_DWORD)&configstruc + 488));
*((_DWORD *)&configstruc + 108) = v3;
if ( !v3 )
goto LABEL_9;
v4 = (const char *)lib_get_errstr(v3, v45);
printf("Error Pinging Station: %s\n", v4);
v0 = cfgphase;
continue;
case 14:
if ( poc_context )
{
puts("POC Receiver Stopped");
result = lib_poc_stop(poc_context);
}
if ( context )
result = lib_destroy_context(&context);
return result;
case 16:
v6 = context;
if ( !context )
goto LABEL_9;
if ( *((_WORD *)&configstruc + 507) )
*((_BYTE *)&configstruc + 496) = 0;
v7 = lib_register(v6, (unsigned int)((_DWORD)&configstruc + 488));
if ( v7 )
{
v39 = (const char *)lib_get_errstr(v7, v45);
printf("Error Starting Connection: %s\n", v39);
v0 = cfgphase;
}
else
{
cfgphase = 4;
v0 = 4;
}
continue;
case 17:
v5 = (void *)context;
if ( context )
{
lib_change_state(context, 1LL, 27LL);
v0 = cfgphase;
}
else
{
v40 = *((_WORD *)&configstruc + 518) == 0;
*((_QWORD *)&configstruc + 55) = &sen_state_callback;
*((_QWORD *)&configstruc + 56) = &msgs_callback;
if ( !v40 )
v5 = &amini_callback;
v40 = *((_WORD *)&configstruc + 517) == 0;
*((_QWORD *)&configstruc + 59) = 0LL;
*((_QWORD *)&configstruc + 51) = 0LL;
fowner[0] = &sen_file_callback;
fowner[1] = 0LL;
*((_QWORD *)&configstruc + 60) = fowner;
*((_QWORD *)&configstruc + 52) = &mini_callback;
*((_QWORD *)&configstruc + 53) = v5;
if ( v40 )
mseed_file = -1LL;
else
mseed_file = lib_file_open(0LL, "seneca.mseed", 9LL);
if ( *((_WORD *)&configstruc + 516) )
{
*((_QWORD *)&configstruc + 57) = &onesec_callback;
onesec_file = lib_file_open(0LL, "seneca.sec", 9LL);
}
else
{
*((_QWORD *)&configstruc + 57) = 0LL;
onesec_file = -1LL;
}
lib_create_context(&context, (unsigned int)((_DWORD)&configstruc + 8));
v0 = *((_DWORD *)&configstruc + 108);
if ( v0 )
{
context = 0LL;
v42 = (const char *)lib_get_errstr(v0, v45);
printf("Error creating station thread: %s\n", v42);
v0 = cfgphase;
}
else
{
puts("Station Thread Created");
v41 = *((_WORD *)&configstruc + 520);
cfgphase = 0;
if ( v41 )
{
v43 = v41;
v44 = &poc_handler;
poc_context = lib_poc_start(&v43);
puts("POC Receiver Started");
v0 = cfgphase;
}
}
}
continue;
default:
goto LABEL_9;
}
case 1u:
show_create_pars();
switch ( (unsigned __int8)func0() )
{
case 'A':
get_t64("Serial number: ", (unsigned int)((_DWORD)&configstruc + 8));
v0 = cfgphase;
break;
case 'B':
v24 = get_word("Data port (1-4): ");
v0 = cfgphase;
*((_WORD *)&configstruc + 8) = v24 - 1;
break;
case 'C':
get_string("Station name (3-5 characters): ", 5LL, (unsigned int)((_DWORD)&configstruc + 18));
lib330_upper((unsigned int)((_DWORD)&configstruc + 18));
v0 = cfgphase;
break;
case 'D':
v23 = get_integer("Timezone offset in seconds: ");
v0 = cfgphase;
*((_DWORD *)&configstruc + 6) = v23;
break;
case 'E':
get_string("Host software name: ", 95LL, (unsigned int)((_DWORD)&configstruc + 28));
v0 = cfgphase;
break;
case 'F':
get_string("Continuity file name (Null to disable): ", 250LL, (unsigned int)((_DWORD)&configstruc + 124));
v0 = cfgphase;
break;
case 'G':
v22 = get_verbosity();
v0 = cfgphase;
*((_WORD *)&configstruc + 187) = v22;
break;
case 'H':
v21 = get_frequency("Highest frequency for incremental update: ");
v0 = cfgphase;
*((_QWORD *)&configstruc + 49) = v21;
break;
case 'I':
v20 = get_yesno("Embed blockettes (Y/n): ", 1LL);
v0 = cfgphase;
*((_WORD *)&configstruc + 200) = v20;
break;
case 'J':
v19 = get_yesno("Separate blockettes (y/N): ", 0LL);
v0 = cfgphase;
*((_WORD *)&configstruc + 201) = v19;
break;
case 'K':
v18 = get_yesno("Calculate host timezone automatically (Y/n): ", 1LL);
v0 = cfgphase;
*((_WORD *)&configstruc + 188) = v18;
break;
case 'L':
v17 = get_onesec_filter();
v0 = cfgphase;
*((_WORD *)&configstruc + 189) = v17;
break;
case 'M':
v16 = get_seed_filter("512 byte MiniSeed data filter: ");
v0 = cfgphase;
*((_WORD *)&configstruc + 192) = v16;
break;
case 'N':
v15 = get_seed_filter("Archival MiniSeed data filter: ");
v0 = cfgphase;
*((_WORD *)&configstruc + 193) = v15;
break;
case 'S':
goto LABEL_53;
case 'X':
goto LABEL_43;
default:
goto LABEL_9;
}
break;
case 2u:
show_register_pars();
switch ( (unsigned __int8)func0() )
{
case 'A':
get_t64("Authentication code: ", (unsigned int)((_DWORD)&configstruc + 488));
v0 = cfgphase;
break;
case 'B':
get_string("Q330 IP address: ", 250LL, (unsigned int)((_DWORD)&configstruc + 496));
v0 = cfgphase;
break;
case 'C':
v30 = get_word("Q330 base port: ");
v0 = cfgphase;
*((_WORD *)&configstruc + 373) = v30;
break;
case 'E':
get_string("Host interface: ", 250LL, (unsigned int)((_DWORD)&configstruc + 752));
v0 = cfgphase;
break;
case 'F':
v29 = get_timeout("Host minimum command timeout: ");
v0 = cfgphase;
*((_WORD *)&configstruc + 501) = v29;
break;
case 'G':
v28 = get_timeout("Host maximum command timeout: ");
v0 = cfgphase;
*((_WORD *)&configstruc + 502) = v28;
break;
case 'H':
v38 = get_word("Host control port (0 for automatic): ");
v0 = cfgphase;
*((_WORD *)&configstruc + 503) = v38;
break;
case 'I':
v37 = get_word("Host data port (0 for automatic): ");
v0 = cfgphase;
*((_WORD *)&configstruc + 504) = v37;
break;
case 'J':
v36 = get_yesno("Q330 has dynamic IP address (y/N): ", 0LL);
v0 = cfgphase;
*((_WORD *)&configstruc + 507) = v36;
break;
case 'K':
v35 = get_word("Hibernate time in minutes: ");
v0 = cfgphase;
*((_WORD *)&configstruc + 508) = v35;
break;
case 'L':
v34 = get_word("Maximum connection time in minutes: ");
v0 = cfgphase;
*((_WORD *)&configstruc + 509) = v34;
break;
case 'M':
v33 = get_word("Connection wait time in minutes: ");
v0 = cfgphase;
*((_WORD *)&configstruc + 510) = v33;
break;
case 'N':
v32 = get_word("Maximum registration attempts before hibernation: ");
v0 = cfgphase;
*((_WORD *)&configstruc + 511) = v32;
break;
case 'O':
v31 = get_word("Dynamic IP address expiration in minutes: ");
v0 = cfgphase;
*((_WORD *)&configstruc + 512) = v31;
break;
case 'P':
v27 = get_word("Buffer level to stop connection: ");
v0 = cfgphase;
*((_WORD *)&configstruc + 513) = v27;
break;
case 'Q':
v26 = get_word("Minutes before writing Q330 continuity to file: ");
v0 = cfgphase;
*((_WORD *)&configstruc + 514) = v26;
break;
case 'R':
v25 = get_word("Maximum DSS memory in KB: ");
v0 = cfgphase;
*((_WORD *)&configstruc + 515) = v25;
break;
case 'S':
goto LABEL_53;
case 'X':
goto LABEL_43;
default:
goto LABEL_9;
}
break;
case 3u:
show_file_menu();
switch ( (unsigned __int8)func0() )
{
case 'A':
v14 = get_yesno("Enable writing one second data to seneca.sec (y/N): ", 0LL);
v0 = cfgphase;
*((_WORD *)&configstruc + 516) = v14;
break;
case 'B':
v11 = get_yesno("Enable writing 512 byte MiniSeed to seneca.mseed (y/N): ", 0LL);
v0 = cfgphase;
*((_WORD *)&configstruc + 517) = v11;
break;
case 'C':
v10 = get_yesno("Enable writing 4096 byte MiniSeed to individual files (y/N): ", 0LL);
v0 = cfgphase;
*((_WORD *)&configstruc + 518) = v10;
break;
case 'D':
v13 = get_yesno("Enable NetServer if configured in tokens (y/N): ", 0LL);
v0 = cfgphase;
*((_WORD *)&configstruc + 519) = v13;
break;
case 'E':
v12 = get_word("POC Receiver port (zero to disable, standard is 2254): ");
v0 = cfgphase;
*((_WORD *)&configstruc + 520) = v12;
break;
case 'S':
LABEL_53:
save_configuration();
v0 = cfgphase;
break;
case 'X':
goto LABEL_43;
default:
goto LABEL_9;
}
break;
case 4u:
show_run_menu();
result = (unsigned __int8)(func0() - 65);
switch ( (char)result )
{
case 0:
arp_status();
v0 = cfgphase;
continue;
case 2:
lib_abort_command(context);
v0 = cfgphase;
continue;
case 3:
LABEL_32:
dump_messages();
v0 = cfgphase;
continue;
case 5:
if ( current_state != 10 )
goto LABEL_9;
lib_flush_data(context);
v0 = cfgphase;
break;
case 6:
send_tunneled_request();
v0 = cfgphase;
continue;
case 7:
if ( current_state != 10 )
goto LABEL_9;
show_detectors();
v0 = cfgphase;
break;
case 8:
if ( current_state != 10 )
goto LABEL_9;
lib_set_freeze_timer(context, 30LL);
v0 = cfgphase;
break;
case 11:
show_lcqs();
v0 = cfgphase;
continue;
case 12:
LABEL_10:
show_modules();
v0 = cfgphase;
continue;
case 14:
screen_busy = 1;
show_opstat();
screen_busy = 0;
v0 = cfgphase;
continue;
case 15:
pingreq = 0LL;
lib_ping_request(context, &pingreq);
v0 = cfgphase;
continue;
case 16:
if ( context )
goto LABEL_9;
if ( poc_context )
{
puts("POC Receiver Stopped");
result = lib_poc_stop(poc_context);
}
return result;
case 18:
lib_change_state(context, 0LL, 27LL);
LABEL_43:
cfgphase = 0;
v0 = 0;
continue;
case 20:
screen_busy = 1;
printf("Message: ");
get_line(&line);
lib_send_usermessage(context, &line);
screen_busy = 0;
v0 = cfgphase;
continue;
case 21:
screen_busy = 1;
v8 = get_verbosity();
v9 = lib_change_verbosity(context, v8);
screen_busy = 0;
v0 = cfgphase;
*((_WORD *)&configstruc + 187) = v9;
continue;
default:
LABEL_9:
v0 = cfgphase;
break;
}
break;
default:
continue;
}
}
}

original_code:
void run_commands (void)
{
  tpoc_par poc_par ;
  string s ;
  uint16_t newverb ;
  enum tliberr err ;
  tpar_register *preg ;
  tpar_create *pcret ;
  uint16_t w ;
  preg = &(configstruc.par_register) ;
  pcret = &(configstruc.par_create) ;
  do {
    switch (cfgphase) {
      case CFG_IDLE :
        show_idle_menu () ;
        switch (get_command_char()) {
          case 'C' :
            if (context == 0)

                cfgphase = CFG_CREATE ;
            break ;
          case 'D' :
            if (context)

                dump_messages () ;
            break ;
          case 'E' :
            cfgphase = CFG_REG ;
            break ;
          case 'F' :
            cfgphase = CFG_FILE ;
            break ;
          case 'M' :
            show_modules () ;
            break ;
          case 'O' :
            if (context)

                show_opstat () ;
            break ;
          case 'P' :
            if (context)

                {
                  if (preg->opt_dynamic_ip)

                      preg->q330id_address[0] = 0 ;
                  pcret->resp_err = lib_unregistered_ping (context, preg) ;
                  if (pcret->resp_err != LIBERR_NOERR)

                      printf ("Error Pinging Station: %s\n", lib_get_errstr(pcret->resp_err, &(s))) ;
                }
            break ;
          case 'Q' :
            if (poc_context)

                {
                  printf ("POC Receiver Stopped\n") ;
                  lib_poc_stop (poc_context) ;
                }
            if (context)

                lib_destroy_context (&(context)) ;
            return ;
          case 'S' :
            if (context)

                {
                  if (preg->opt_dynamic_ip)

                      preg->q330id_address[0] = 0 ;
                  err = lib_register (context, preg) ;
                  if (err == LIBERR_NOERR)

                      cfgphase = CFG_RUN ;
                    else
                      printf ("Error Starting Connection: %s\n", lib_get_errstr(err, &(s))) ;
                }
            break ;
          case 'T' :
            if (context == 0)

                {
                  pcret->call_state = sen_state_callback ;
                  pcret->call_messages = msgs_callback ;
                  pcret->call_baler = 0 ;
                  pcret->mini_firchain = 0 ;
                  fowner.call_fileacc = sen_file_callback ;
                  fowner.station_ptr = 0 ;
                  pcret->file_owner = &(fowner) ;
                  pcret->call_minidata = mini_callback ;
                  if (configstruc.write_archive)

                      pcret->call_aminidata = amini_callback ;
                    else
                      pcret->call_aminidata = 0 ;
                  if (configstruc.write_mseed)

                      mseed_file = lib_file_open (0, "seneca.mseed", 1 | 8) ;
                    else
                      mseed_file = -1 ;
                  if (configstruc.write_1sec)

                      {
                        pcret->call_secdata = onesec_callback ;
                        onesec_file = lib_file_open (0, "seneca.sec", 1 | 8) ;
                      }
                    else
                      {
                        pcret->call_secdata = 0 ;
                        onesec_file = -1 ;
                      }
                  lib_create_context (&(context), pcret) ;
                  if (pcret->resp_err == LIBERR_NOERR)

                      {
                        printf ("Station Thread Created\n") ;
                        cfgphase = CFG_IDLE ;
                        if (configstruc.poc_port)

                            {
                              poc_par.poc_port = configstruc.poc_port ;
                              poc_par.poc_callback = poc_handler ;
                              poc_context = lib_poc_start (&(poc_par)) ;
                              printf ("POC Receiver Started\n") ;
                            }
                      }
                    else
                      {
                        context = 0 ;
                        printf ("Error creating station thread: %s\n", lib_get_errstr(pcret->resp_err, &(s))) ;
                      }
                }
              else
                lib_change_state (context, LIBSTATE_TERM, LIBERR_CLOSED) ;
            break ;
        }
        break ;
      case CFG_CREATE :
        show_create_pars () ;
        switch (get_command_char()) {
          case 'A' :
            get_t64 ("Serial number: ", &(pcret->q330id_serial)) ;
            break ;
          case 'B' :
            w = get_word ("Data port (1-4): ") ;
            w = w - 1 ;
            pcret->q330id_dataport = w ;
            break ;
          case 'C' :
            get_string("Station name (3-5 characters): ", 5, &(pcret->q330id_station)) ;
            lib330_upper(&(pcret->q330id_station)) ;
            break ;
          case 'D' :
            pcret->host_timezone = get_integer ("Timezone offset in seconds: ") ;
            break ;
          case 'E' :
            get_string("Host software name: ", 95, &(pcret->host_software)) ;
            break ;
          case 'F' :
            get_string("Continuity file name (Null to disable): ", 250, &(pcret->opt_contfile)) ;
            break ;
          case 'G' :
            pcret->opt_verbose = get_verbosity () ;
            break ;
          case 'H' :
            pcret->amini_512highest = get_frequency ("Highest frequency for incremental update: ") ;
            break ;
          case 'I' :
            pcret->mini_embed = get_yesno("Embed blockettes (Y/n): ", 1) ;
            break ;
          case 'J' :
            pcret->mini_separate = get_yesno("Separate blockettes (y/N): ", 0) ;
            break ;
          case 'K' :
            pcret->opt_zoneadjust = get_yesno("Calculate host timezone automatically (Y/n): ", 1) ;
            break ;
          case 'L' : pcret->opt_secfilter = get_onesec_filter () ;
            break ;
          case 'M' :
            pcret->opt_minifilter = get_seed_filter ("512 byte MiniSeed data filter: ") ;
            break ;
          case 'N' :
            pcret->opt_aminifilter = get_seed_filter ("Archival MiniSeed data filter: ") ;
            break ;
          case 'S' :
            save_configuration () ;
            break ;
          case 'X' :
            cfgphase = CFG_IDLE ;
            break ;
        }
        break ;
      case CFG_REG :
        show_register_pars () ;
        switch (get_command_char()) {
          case 'A' :
            get_t64("Authentication code: ", &(preg->q330id_auth)) ;
            break ;
          case 'B' :
            get_string("Q330 IP address: ", 250, &(preg->q330id_address)) ;
            break ;
          case 'C' :
            preg->q330id_baseport = get_word ("Q330 base port: ") ;
            break ;
          case 'E' :
            get_string("Host interface: ", 250, &(preg->host_interface)) ;
            break ;
          case 'F' :
            preg->host_mincmdretry = get_timeout("Host minimum command timeout: ") ;
            break ;
          case 'G' :
            preg->host_maxcmdretry = get_timeout("Host maximum command timeout: ") ;
            break ;
          case 'H' :
            preg->host_ctrlport = get_word("Host control port (0 for automatic): ") ;
            break ;
          case 'I' :
            preg->host_dataport = get_word("Host data port (0 for automatic): ") ;
            break ;
          case 'J' :
            preg->opt_dynamic_ip = get_yesno("Q330 has dynamic IP address (y/N): ", 0) ;
            break ;
          case 'K' :
            preg->opt_hibertime = get_word("Hibernate time in minutes: ") ;
            break ;
          case 'L' :
            preg->opt_conntime = get_word("Maximum connection time in minutes: ") ;
            break ;
          case 'M' :
            preg->opt_connwait = get_word("Connection wait time in minutes: ") ;
            break ;
          case 'N' :
            preg->opt_regattempts = get_word("Maximum registration attempts before hibernation: ") ;
            break ;
          case 'O' :
            preg->opt_ipexpire = get_word("Dynamic IP address expiration in minutes: ") ;
            break ;
          case 'P' :
            preg->opt_buflevel = get_word("Buffer level to stop connection: ") ;
            break ;
          case 'Q' :
            preg->opt_q330_cont = get_word("Minutes before writing Q330 continuity to file: ") ;
            break ;
          case 'R' :
            preg->opt_dss_memory = get_word("Maximum DSS memory in KB: ") ;
            break ;
          case 'S' :
            save_configuration () ;
            break ;
          case 'X' :
            cfgphase = CFG_IDLE ;
            break ;
        }
        break ;
      case CFG_FILE :
        show_file_menu () ;
        switch (get_command_char()) {
          case 'A' :
            configstruc.write_1sec = get_yesno("Enable writing one second data to seneca.sec (y/N): ", 0) ;
            break ;
          case 'B' :
            configstruc.write_mseed = get_yesno("Enable writing 512 byte MiniSeed to seneca.mseed (y/N): ", 0) ;
            break ;
          case 'C' :
            configstruc.write_archive = get_yesno("Enable writing 4096 byte MiniSeed to individual files (y/N): ", 0) ;
            break ;
          case 'D' :
            configstruc.run_netserver = get_yesno("Enable NetServer if configured in tokens (y/N): ", 0) ;
            break ;
          case 'E' :
            configstruc.poc_port = get_word("POC Receiver port (zero to disable, standard is 2254): ") ;
            break ;
          case 'S' :
            save_configuration () ;
            break ;
          case 'X' :
            cfgphase = CFG_IDLE ;
            break ;
        }
        break ;
      case CFG_RUN :
        show_run_menu () ;
        switch (get_command_char()) {
          case 'A' :
            arp_status () ;
            break ;
          case 'C' :
            lib_abort_command (context) ;
            break ;
          case 'D' :
            dump_messages () ;
            break ;
          case 'G' :
            send_tunneled_request () ;
            break ;
          case 'F' :
            if (current_state == LIBSTATE_RUN)

                lib_flush_data (context) ;
            break ;
          case 'H' :
            if (current_state == LIBSTATE_RUN)

                show_detectors () ;
            break ;
          case 'I' :
            if (current_state == LIBSTATE_RUN)

                lib_set_freeze_timer (context, 30) ;
            break ;
          case 'L' :
            show_lcqs () ;
            break ;
          case 'M' :
            show_modules () ;
            break ;
          case 'O' :
            screen_busy = 1 ;
            show_opstat () ;
            screen_busy = 0 ;
            break ;
          case 'P' :
            pingreq.pingtype = 0 ;
            pingreq.pingopt = 0 ;
            pingreq.pingreqmap = 0 ;
            lib_ping_request (context, &(pingreq)) ;
            break ;
          case 'Q' :
            if (context == 0)

                {
                  if (poc_context)

                      {
                        printf ("POC Receiver Stopped\n") ;
                        lib_poc_stop (poc_context) ;
                      }
                  return ;
                }
            break ;
          case 'S' :
            lib_change_state (context, LIBSTATE_IDLE, LIBERR_CLOSED) ;
            cfgphase = CFG_IDLE ;
            break ;
          case 'U' :
            screen_busy = 1 ;
            printf ("Message: ") ;
            get_line(line) ;
            lib_send_usermessage (context, &(line)) ;
            screen_busy = 0 ;
            break ;
          case 'V' :
            screen_busy = 1 ;
            newverb = get_verbosity () ;
            configstruc.par_create.opt_verbose = lib_change_verbosity (context, newverb) ;
            screen_busy = 0 ;
            break ;
        }
        break ;
    }
  } while (! 0) ;
}

canonical_original_code:
void run_commands()
{
  struct tpoc_par poc_par;
  char s[256];
  unsigned short newverb;
  enum tliberr err;
  struct tpar_register *preg;
  struct tpar_create *pcret;
  unsigned short w;
  preg = &(configstruc.par_register) ;
  pcret = &(configstruc.par_create) ;
  do {
    switch (cfgphase) {
      case CFG_IDLE :
        show_idle_menu () ;
        switch (get_command_char()) {
          case 'C' :
            if (context == 0)

                cfgphase = CFG_CREATE ;
            break ;
          case 'D' :
            if (context)

                dump_messages () ;
            break ;
          case 'E' :
            cfgphase = CFG_REG ;
            break ;
          case 'F' :
            cfgphase = CFG_FILE ;
            break ;
          case 'M' :
            show_modules () ;
            break ;
          case 'O' :
            if (context)

                show_opstat () ;
            break ;
          case 'P' :
            if (context)

                {
                  if (preg->opt_dynamic_ip)

                      preg->q330id_address[0] = 0 ;
                  pcret->resp_err = lib_unregistered_ping (context, preg) ;
                  if (pcret->resp_err != LIBERR_NOERR)

                      printf ("Error Pinging Station: %s\n", lib_get_errstr(pcret->resp_err, &(s))) ;
                }
            break ;
          case 'Q' :
            if (poc_context)

                {
                  printf ("POC Receiver Stopped\n") ;
                  lib_poc_stop (poc_context) ;
                }
            if (context)

                lib_destroy_context (&(context)) ;
            return ;
          case 'S' :
            if (context)

                {
                  if (preg->opt_dynamic_ip)

                      preg->q330id_address[0] = 0 ;
                  err = lib_register (context, preg) ;
                  if (err == LIBERR_NOERR)

                      cfgphase = CFG_RUN ;
                    else
                      printf ("Error Starting Connection: %s\n", lib_get_errstr(err, &(s))) ;
                }
            break ;
          case 'T' :
            if (context == 0)

                {
                  pcret->call_state = sen_state_callback ;
                  pcret->call_messages = msgs_callback ;
                  pcret->call_baler = 0 ;
                  pcret->mini_firchain = 0 ;
                  fowner.call_fileacc = sen_file_callback ;
                  fowner.station_ptr = 0 ;
                  pcret->file_owner = &(fowner) ;
                  pcret->call_minidata = mini_callback ;
                  if (configstruc.write_archive)

                      pcret->call_aminidata = amini_callback ;
                    else
                      pcret->call_aminidata = 0 ;
                  if (configstruc.write_mseed)

                      mseed_file = lib_file_open (0, "seneca.mseed", 1 | 8) ;
                    else
                      mseed_file = -1 ;
                  if (configstruc.write_1sec)

                      {
                        pcret->call_secdata = onesec_callback ;
                        onesec_file = lib_file_open (0, "seneca.sec", 1 | 8) ;
                      }
                    else
                      {
                        pcret->call_secdata = 0 ;
                        onesec_file = -1 ;
                      }
                  lib_create_context (&(context), pcret) ;
                  if (pcret->resp_err == LIBERR_NOERR)

                      {
                        printf ("Station Thread Created\n") ;
                        cfgphase = CFG_IDLE ;
                        if (configstruc.poc_port)

                            {
                              poc_par.poc_port = configstruc.poc_port ;
                              poc_par.poc_callback = poc_handler ;
                              poc_context = lib_poc_start (&(poc_par)) ;
                              printf ("POC Receiver Started\n") ;
                            }
                      }
                    else
                      {
                        context = 0 ;
                        printf ("Error creating station thread: %s\n", lib_get_errstr(pcret->resp_err, &(s))) ;
                      }
                }
              else
                lib_change_state (context, LIBSTATE_TERM, LIBERR_CLOSED) ;
            break ;
        }
        break ;
      case CFG_CREATE :
        show_create_pars () ;
        switch (get_command_char()) {
          case 'A' :
            get_t64 ("Serial number: ", &(pcret->q330id_serial)) ;
            break ;
          case 'B' :
            w = get_word ("Data port (1-4): ") ;
            w = w - 1 ;
            pcret->q330id_dataport = w ;
            break ;
          case 'C' :
            get_string("Station name (3-5 characters): ", 5, &(pcret->q330id_station)) ;
            lib330_upper(&(pcret->q330id_station)) ;
            break ;
          case 'D' :
            pcret->host_timezone = get_integer ("Timezone offset in seconds: ") ;
            break ;
          case 'E' :
            get_string("Host software name: ", 95, &(pcret->host_software)) ;
            break ;
          case 'F' :
            get_string("Continuity file name (Null to disable): ", 250, &(pcret->opt_contfile)) ;
            break ;
          case 'G' :
            pcret->opt_verbose = get_verbosity () ;
            break ;
          case 'H' :
            pcret->amini_512highest = get_frequency ("Highest frequency for incremental update: ") ;
            break ;
          case 'I' :
            pcret->mini_embed = get_yesno("Embed blockettes (Y/n): ", 1) ;
            break ;
          case 'J' :
            pcret->mini_separate = get_yesno("Separate blockettes (y/N): ", 0) ;
            break ;
          case 'K' :
            pcret->opt_zoneadjust = get_yesno("Calculate host timezone automatically (Y/n): ", 1) ;
            break ;
          case 'L' : pcret->opt_secfilter = get_onesec_filter () ;
            break ;
          case 'M' :
            pcret->opt_minifilter = get_seed_filter ("512 byte MiniSeed data filter: ") ;
            break ;
          case 'N' :
            pcret->opt_aminifilter = get_seed_filter ("Archival MiniSeed data filter: ") ;
            break ;
          case 'S' :
            save_configuration () ;
            break ;
          case 'X' :
            cfgphase = CFG_IDLE ;
            break ;
        }
        break ;
      case CFG_REG :
        show_register_pars () ;
        switch (get_command_char()) {
          case 'A' :
            get_t64("Authentication code: ", &(preg->q330id_auth)) ;
            break ;
          case 'B' :
            get_string("Q330 IP address: ", 250, &(preg->q330id_address)) ;
            break ;
          case 'C' :
            preg->q330id_baseport = get_word ("Q330 base port: ") ;
            break ;
          case 'E' :
            get_string("Host interface: ", 250, &(preg->host_interface)) ;
            break ;
          case 'F' :
            preg->host_mincmdretry = get_timeout("Host minimum command timeout: ") ;
            break ;
          case 'G' :
            preg->host_maxcmdretry = get_timeout("Host maximum command timeout: ") ;
            break ;
          case 'H' :
            preg->host_ctrlport = get_word("Host control port (0 for automatic): ") ;
            break ;
          case 'I' :
            preg->host_dataport = get_word("Host data port (0 for automatic): ") ;
            break ;
          case 'J' :
            preg->opt_dynamic_ip = get_yesno("Q330 has dynamic IP address (y/N): ", 0) ;
            break ;
          case 'K' :
            preg->opt_hibertime = get_word("Hibernate time in minutes: ") ;
            break ;
          case 'L' :
            preg->opt_conntime = get_word("Maximum connection time in minutes: ") ;
            break ;
          case 'M' :
            preg->opt_connwait = get_word("Connection wait time in minutes: ") ;
            break ;
          case 'N' :
            preg->opt_regattempts = get_word("Maximum registration attempts before hibernation: ") ;
            break ;
          case 'O' :
            preg->opt_ipexpire = get_word("Dynamic IP address expiration in minutes: ") ;
            break ;
          case 'P' :
            preg->opt_buflevel = get_word("Buffer level to stop connection: ") ;
            break ;
          case 'Q' :
            preg->opt_q330_cont = get_word("Minutes before writing Q330 continuity to file: ") ;
            break ;
          case 'R' :
            preg->opt_dss_memory = get_word("Maximum DSS memory in KB: ") ;
            break ;
          case 'S' :
            save_configuration () ;
            break ;
          case 'X' :
            cfgphase = CFG_IDLE ;
            break ;
        }
        break ;
      case CFG_FILE :
        show_file_menu () ;
        switch (get_command_char()) {
          case 'A' :
            configstruc.write_1sec = get_yesno("Enable writing one second data to seneca.sec (y/N): ", 0) ;
            break ;
          case 'B' :
            configstruc.write_mseed = get_yesno("Enable writing 512 byte MiniSeed to seneca.mseed (y/N): ", 0) ;
            break ;
          case 'C' :
            configstruc.write_archive = get_yesno("Enable writing 4096 byte MiniSeed to individual files (y/N): ", 0) ;
            break ;
          case 'D' :
            configstruc.run_netserver = get_yesno("Enable NetServer if configured in tokens (y/N): ", 0) ;
            break ;
          case 'E' :
            configstruc.poc_port = get_word("POC Receiver port (zero to disable, standard is 2254): ") ;
            break ;
          case 'S' :
            save_configuration () ;
            break ;
          case 'X' :
            cfgphase = CFG_IDLE ;
            break ;
        }
        break ;
      case CFG_RUN :
        show_run_menu () ;
        switch (get_command_char()) {
          case 'A' :
            arp_status () ;
            break ;
          case 'C' :
            lib_abort_command (context) ;
            break ;
          case 'D' :
            dump_messages () ;
            break ;
          case 'G' :
            send_tunneled_request () ;
            break ;
          case 'F' :
            if (current_state == LIBSTATE_RUN)

                lib_flush_data (context) ;
            break ;
          case 'H' :
            if (current_state == LIBSTATE_RUN)

                show_detectors () ;
            break ;
          case 'I' :
            if (current_state == LIBSTATE_RUN)

                lib_set_freeze_timer (context, 30) ;
            break ;
          case 'L' :
            show_lcqs () ;
            break ;
          case 'M' :
            show_modules () ;
            break ;
          case 'O' :
            screen_busy = 1 ;
            show_opstat () ;
            screen_busy = 0 ;
            break ;
          case 'P' :
            pingreq.pingtype = 0 ;
            pingreq.pingopt = 0 ;
            pingreq.pingreqmap = 0 ;
            lib_ping_request (context, &(pingreq)) ;
            break ;
          case 'Q' :
            if (context == 0)

                {
                  if (poc_context)

                      {
                        printf ("POC Receiver Stopped\n") ;
                        lib_poc_stop (poc_context) ;
                      }
                  return ;
                }
            break ;
          case 'S' :
            lib_change_state (context, LIBSTATE_IDLE, LIBERR_CLOSED) ;
            cfgphase = CFG_IDLE ;
            break ;
          case 'U' :
            screen_busy = 1 ;
            printf ("Message: ") ;
            get_line(line) ;
            lib_send_usermessage (context, &(line)) ;
            screen_busy = 0 ;
            break ;
          case 'V' :
            screen_busy = 1 ;
            newverb = get_verbosity () ;
            configstruc.par_create.opt_verbose = lib_change_verbosity (context, newverb) ;
            screen_busy = 0 ;
            break ;
        }
        break ;
    }
  } while (! 0) ;
}

variable_types: struct tpoc_par { unsigned short poc_port; void (*poc_callback)(enum tpocstate { PS_NEWPOC=0, PS_CONNRESET=1 } pocstate, struct tpoc_recvd { unsigned int serial_number[2]; unsigned int ip_address; unsigned short base_port; unsigned short data_port; } *poc_recv); }

variable_types:
newverb
unsigned short

variable_types: struct tpar_register { unsigned int q330id_auth[2]; char q330id_address[250]; unsigned short q330id_baseport; enum thost_mode { HOST_ETH=0, HOST_SER=1, HOST_TCP=2 } host_mode; char host_interface[250]; unsigned short host_mincmdretry; unsigned short host_maxcmdretry; unsigned short host_ctrlport; unsigned short host_dataport; unsigned short opt_latencytarget; unsigned short opt_closedloop; unsigned short opt_dynamic_ip; unsigned short opt_hibertime; unsigned short opt_conntime; unsigned short opt_connwait; unsigned short opt_regattempts; unsigned short opt_ipexpire; unsigned short opt_buflevel; unsigned short opt_q330_cont; unsigned short opt_dss_memory; } *

variable_types: struct tpar_create { unsigned int q330id_serial[2]; unsigned short q330id_dataport; char q330id_station[6]; int host_timezone; char host_software[96]; char opt_contfile[250]; unsigned short opt_verbose; unsigned short opt_zoneadjust; unsigned short opt_secfilter; unsigned short opt_client_msgs; unsigned short opt_compat; unsigned short opt_minifilter; unsigned short opt_aminifilter; unsigned short amini_exponent; long amini_512highest; unsigned short mini_embed; unsigned short mini_separate; struct tfilter { struct tfilter *link; char fname[-1]; unsigned char fir_num; double coef[400]; int len; double gain; double dly; int dec; } *mini_firchain; void (*call_minidata)(void *p); void (*call_aminidata)(void *p); enum tliberr { LIBERR_NOERR=0, LIBERR_PERM=1, LIBERR_TMSERV=2, LIBERR_NOTR=3, LIBERR_INVREG=4, LIBERR_PAR=5, LIBERR_SNV=6, LIBERR_CTRL=7, LIBERR_SPEC=8, LIBERR_MEM=9, LIBERR_CIP=10, LIBERR_DNA=11, LIBERR_DB9=12, LIBERR_MEMEW=13, LIBERR_THREADERR=14, LIBERR_BADDIR=15, LIBERR_REGTO=16, LIBERR_STATTO=17, LIBERR_DATATO=18, LIBERR_NOSTAT=19, LIBERR_INVSTAT=20, LIBERR_CFGWAIT=21, LIBERR_INVCFG=22, LIBERR_TOKENS_CHANGE=23, LIBERR_INVAL_TOKENS=24, LIBERR_BUFSHUT=25, LIBERR_CONNSHUT=26, LIBERR_CLOSED=27, LIBERR_NETFAIL=28, LIBERR_TUNBUSY=29, LIBERR_INVCTX=30 } resp_err; void (*call_state)(void *p); void (*call_messages)(void *p); void (*call_secdata)(void *p); void (*call_lowlatency)(void *p); void (*call_baler)(void *p); struct tfile_owner { void (*call_fileacc)(void *p); void *station_ptr; } *file_owner; } *

variable_types:
w
unsigned short

user_defined_types: struct tpoc_par { unsigned short poc_port; void (*poc_callback)(enum tpocstate pocstate, struct tpoc_recvd *poc_recv); }

user_defined_types: struct tpar_register { unsigned int q330id_auth[2]; char q330id_address[250]; unsigned short q330id_baseport; enum thost_mode host_mode; char host_interface[250]; unsigned short host_mincmdretry; unsigned short host_maxcmdretry; unsigned short host_ctrlport; unsigned short host_dataport; unsigned short opt_latencytarget; unsigned short opt_closedloop; unsigned short opt_dynamic_ip; unsigned short opt_hibertime; unsigned short opt_conntime; unsigned short opt_connwait; unsigned short opt_regattempts; unsigned short opt_ipexpire; unsigned short opt_buflevel; unsigned short opt_q330_cont; unsigned short opt_dss_memory; }

user_defined_types: struct tpar_create { unsigned int q330id_serial[2]; unsigned short q330id_dataport; char q330id_station[6]; int host_timezone; char host_software[96]; char opt_contfile[250]; unsigned short opt_verbose; unsigned short opt_zoneadjust; unsigned short opt_secfilter; unsigned short opt_client_msgs; unsigned short opt_compat; unsigned short opt_minifilter; unsigned short opt_aminifilter; unsigned short amini_exponent; long amini_512highest; unsigned short mini_embed; unsigned short mini_separate; struct tfilter *mini_firchain; void (*call_minidata)(void *p); void (*call_aminidata)(void *p); enum tliberr resp_err; void (*call_state)(void *p); void (*call_messages)(void *p); void (*call_secdata)(void *p); void (*call_lowlatency)(void *p); void (*call_baler)(void *p); struct tfile_owner *file_owner; }


Upcase

repo: joeledwards/asl-station-processor

decompiled_code:
void __fastcall Upcase(char *a1)
{
_BYTE *v1; // rbx
int v2; // edi

v1 = a1;
v2 = *a1;
if ( (_BYTE)v2 )
{
do
{
*v1++ = toupper(v2);
v2 = (char)*v1;
}
while ( *v1 );
}
}

canonical_decompiled_code:
void __fastcall func8(char *a1)
{
_BYTE *v1; // rbx
int v2; // edi

v1 = a1;
v2 = *a1;
if ( (_BYTE)v2 )
{
do
{
*v1++ = toupper(v2);
v2 = (char)*v1;
}
while ( *v1 );
}
}

original_code:
void Upcase(char *msg)
{
  int i;
  for (i=0; msg[i] != 0; i++)
    msg[i] = (char)toupper(msg[i]);
}

variable_types:
msg
char *

variable_types: i int

return_type: void


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int16 v3; // bp
struct hostent *v4; // r13
int v5; // er12
socklen_t v6; // edx
__int64 v7; // rax
size_t v8; // rax
int v9; // ebp
int v10; // eax
struct sockaddr v12; // [rsp+0h] [rbp-518h] BYREF
char dest[112]; // [rsp+10h] [rbp-508h] BYREF
char v14[112]; // [rsp+80h] [rbp-498h] BYREF
char name[512]; // [rsp+F0h] [rbp-428h] BYREF
char s[552]; // [rsp+2F0h] [rbp-228h] BYREF

if ( argc != 8 )
{
fprintf(stderr, "Usage: %s host port DATREQ station.[location-]channel yyyy/mm/dd hh:mm:ss duration(secs)\n", *argv);
exit(10);
}
strcpy(dest, argv[3]);
Upcase(dest);
strcpy(v14, argv[4]);
Upcase(v14);
strcpy(name, argv[1]);
v3 = atoi(argv[2]);
v4 = gethostbyname(name);
if ( !v4 )
{
fprintf(stderr, "%s: unknown host\n", name);
exit(1);
}
v5 = socket(2, 1, 0);
if ( v5 < 0 )
{
perror("socket");
exit(1);
}
memmove(&v12.sa_data[2], *(const void **)v4->h_addr_list, v4->h_length);
v12.sa_family = 2;
*(_WORD *)v12.sa_data = _bswap_16(v3, &v12, 16LL);
if ( connect(v5, &v12, v6) < 0 )
{
perror("connect");
exit(1);
}
LODWORD(v7) = atoi(argv[7]);
sprintf(s, "%s %s %s %s %d\n", dest, v14, argv[5], argv[6], v7);
fprintf(stderr, "Command: %s\n", s);
v8 = strlen(s);
if ( (_DWORD)v8 != (unsigned int)write(v5, s, v8) )
{
perror("Net write");
exit(1);
}
v9 = 0;
while ( 1 )
{
v10 = read(v5, s, 0x200uLL);
if ( v10 < 0 )
{
perror("network read");
exit(1);
}
v9 += v10;
if ( !v10 )
break;
if ( v10 != (unsigned int)write(1, s, v10) )
{
perror("Terminal write");
exit(1);
}
}
fwrite("Exit on read 0 bytes\n", 1uLL, 0x15uLL, stderr);
fprintf(stderr, "Read %d records\n", (unsigned int)(v9 >> 9));
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int16 v3; // bp
struct hostent *v4; // r13
int v5; // er12
socklen_t v6; // edx
__int64 v7; // rax
size_t v8; // rax
int v9; // ebp
int v10; // eax
struct sockaddr v12; // [rsp+0h] [rbp-518h] BYREF
char dest[112]; // [rsp+10h] [rbp-508h] BYREF
char v14[112]; // [rsp+80h] [rbp-498h] BYREF
char name[512]; // [rsp+F0h] [rbp-428h] BYREF
char s[552]; // [rsp+2F0h] [rbp-228h] BYREF

if ( argc != 8 )
{
fprintf(stderr, "Usage: %s host port DATREQ station.[location-]channel yyyy/mm/dd hh:mm:ss duration(secs)\n", *argv);
exit(10);
}
strcpy(dest, argv[3]);
func8(dest);
strcpy(v14, argv[4]);
func8(v14);
strcpy(name, argv[1]);
v3 = atoi(argv[2]);
v4 = gethostbyname(name);
if ( !v4 )
{
fprintf(stderr, "%s: unknown host\n", name);
exit(1);
}
v5 = socket(2, 1, 0);
if ( v5 < 0 )
{
perror("socket");
exit(1);
}
memmove(&v12.sa_data[2], *(const void **)v4->h_addr_list, v4->h_length);
v12.sa_family = 2;
*(_WORD *)v12.sa_data = func7(v3, &v12, 16LL);
if ( connect(v5, &v12, v6) < 0 )
{
perror("connect");
exit(1);
}
LODWORD(v7) = atoi(argv[7]);
sprintf(s, "%s %s %s %s %d\n", dest, v14, argv[5], argv[6], v7);
fprintf(stderr, "Command: %s\n", s);
v8 = strlen(s);
if ( (_DWORD)v8 != (unsigned int)write(v5, s, v8) )
{
perror("Net write");
exit(1);
}
v9 = 0;
while ( 1 )
{
v10 = read(v5, s, 0x200uLL);
if ( v10 < 0 )
{
perror("network read");
exit(1);
}
v9 += v10;
if ( !v10 )
break;
if ( v10 != (unsigned int)write(1, s, v10) )
{
perror("Terminal write");
exit(1);
}
}
fwrite("Exit on read 0 bytes\n", 1uLL, 0x15uLL, stderr);
fprintf(stderr, "Read %d records\n", (unsigned int)(v9 >> 9));
return 0;
}

original_code:
int main(int argc,char **argv)
{
  struct sockaddr_in sin;
  struct hostent *hp, *gethostbyname();
  char host[512];
  int fd, count, wcount;
  char buf[512];
  char savebuf[512];
  int port;
  int total=0;
  char cmd[100];
  char chan[100];
  if (argc!=8)
  {
    fprintf(stderr,"Usage: %s host port DATREQ station.[location-]channel yyyy/mm/dd hh:mm:ss duration(secs)\n",argv[0]);
    exit(10);
  }
  strcpy(cmd,argv[3]);
  Upcase(cmd);
  strcpy(chan,argv[4]);
  Upcase(chan);
  strcpy(host,argv[1]);
  port = atoi(argv[2]);
  hp = gethostbyname(host);
  if(hp == 0) {
    fprintf(stderr, "%s: unknown host\n",host);
    exit(1);
  }
  fd = socket(2, SOCK_STREAM, 0);
  if(fd < 0) {
    perror("socket");
    exit(1);
  }
  bcopy(hp->h_addr_list[0], (char *)&sin.sin_addr, hp->h_length);
  sin.sin_family = 2;
  sin.sin_port = htons(port);
  if(connect(fd, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
    perror("connect");
    exit(1);
  }
  sprintf(buf,"%s %s %s %s %d\n",
   cmd,chan,argv[5],argv[6],atoi(argv[7]));
  fprintf(stderr,"Command: %s\n",buf);
  count = strlen(buf);
  wcount = write(fd, buf, count);
  if(wcount != count) {
    perror("Net write");
    exit(1);
  }
  while (1) {
    count = read(fd, buf, sizeof(buf));
    if(count < 0)
    {
      perror("network read");
      exit(1);
    }
    total += count;
    if (count==0)
    {
      fprintf(stderr, "Exit on read 0 bytes\n");
      break;
    }
    memcpy(savebuf, buf, sizeof(buf));
    wcount = write(1, buf, count);
    if(wcount != count) {
      perror("Terminal write");
      exit(1);
    }
  }
  fprintf(stderr,"Read %d records\n",
          total/512);
  return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
  struct sockaddr_in sin;
  struct hostent *hp; struct hostent *gethostbyname();
  char host[512];
  int fd; int count; int wcount;
  char buf[512];
  char savebuf[512];
  int port;
  int total = 0;
  char cmd[100];
  char chan[100];
  if (argc!=8)
  {
    fprintf(stderr,"Usage: %s host port DATREQ station.[location-]channel yyyy/mm/dd hh:mm:ss duration(secs)\n",argv[0]);
    exit(10);
  }
  strcpy(cmd,argv[3]);
  Upcase(cmd);
  strcpy(chan,argv[4]);
  Upcase(chan);
  strcpy(host,argv[1]);
  port = atoi(argv[2]);
  hp = gethostbyname(host);
  if(hp == 0) {
    fprintf(stderr, "%s: unknown host\n",host);
    exit(1);
  }
  fd = socket(2, SOCK_STREAM, 0);
  if(fd < 0) {
    perror("socket");
    exit(1);
  }
  bcopy(hp->h_addr_list[0], (char *)&sin.sin_addr, hp->h_length);
  sin.sin_family = 2;
  sin.sin_port = htons(port);
  if(connect(fd, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
    perror("connect");
    exit(1);
  }
  sprintf(buf,"%s %s %s %s %d\n",
   cmd,chan,argv[5],argv[6],atoi(argv[7]));
  fprintf(stderr,"Command: %s\n",buf);
  count = strlen(buf);
  wcount = write(fd, buf, count);
  if(wcount != count) {
    perror("Net write");
    exit(1);
  }
  while (1) {
    count = read(fd, buf, sizeof(buf));
    if(count < 0)
    {
      perror("network read");
      exit(1);
    }
    total += count;
    if (count==0)
    {
      fprintf(stderr, "Exit on read 0 bytes\n");
      break;
    }
    memcpy(savebuf, buf, sizeof(buf));
    wcount = write(1, buf, count);
    if(wcount != count) {
      perror("Terminal write");
      exit(1);
    }
  }
  fprintf(stderr,"Read %d records\n",
          total/512);
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

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

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *()

variable_types:
host
char [512]

variable_types: fd int

variable_types: count int

variable_types: wcount int

variable_types:
buf
char [512]

variable_types:
savebuf
char [512]

variable_types: port int

variable_types: total int

variable_types:
cmd
char [100]

variable_types:
chan
char [100]

return_type: int

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

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


gpsInit

decompiled_code:
__int64 gpsInit()
{
__int64 v0; // rax

v0 = bcStartPci();
hBC_PCI = v0;
if ( !v0 )
return 0xFFFFFFFFLL;
bcSetMode(v0, 6LL);
bcSetTimeFormat(hBC_PCI, 1LL);
bcSetGpsTmFmt(hBC_PCI, 0LL);
bcSetYearAutoIncFlag(hBC_PCI, 1LL);
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rax

v0 = bcStartPci();
hBC_PCI = v0;
if ( !v0 )
return 0xFFFFFFFFLL;
bcSetMode(v0, 6LL);
bcSetTimeFormat(hBC_PCI, 1LL);
bcSetGpsTmFmt(hBC_PCI, 0LL);
bcSetYearAutoIncFlag(hBC_PCI, 1LL);
return 0LL;
}

original_code:
int gpsInit()
{
  hBC_PCI = bcStartPci();
  if (!hBC_PCI)
    return -1;
  bcSetMode(hBC_PCI, MODE_GPS);
  bcSetTimeFormat(hBC_PCI, FORMAT_BINARY);
  bcSetGpsTmFmt(hBC_PCI, UTC_TIME_FMT);
  bcSetYearAutoIncFlag(hBC_PCI, YEAR_AUTO_ENA);
  return 0;
}


gpsTime

decompiled_code:
__int64 __fastcall gpsTime(_QWORD *a1, _BYTE *a2)
{
char v3; // [rsp+Dh] [rbp-2Bh] BYREF
char v4[2]; // [rsp+Eh] [rbp-2Ah] BYREF
__int64 v5; // [rsp+10h] [rbp-28h] BYREF
__int64 v6[4]; // [rsp+18h] [rbp-20h] BYREF

if ( !bcReadBinTimeEx(hBC_PCI, &v5, v6, v4, &v3) )
return 0xFFFFFFFFLL;
*a2 = v3;
*a1 = v5;
a1[1] = v6[0];
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, _BYTE *a2)
{
char v3; // [rsp+Dh] [rbp-2Bh] BYREF
char v4[2]; // [rsp+Eh] [rbp-2Ah] BYREF
__int64 v5; // [rsp+10h] [rbp-28h] BYREF
__int64 v6[4]; // [rsp+18h] [rbp-20h] BYREF

if ( !bcReadBinTimeEx(hBC_PCI, &v5, v6, v4, &v3) )
return 0xFFFFFFFFLL;
*a2 = v3;
*a1 = v5;
a1[1] = v6[0];
return 0LL;
}

original_code:
int gpsTime(
        struct timeval *uxtime,
 unsigned char *status)
{
  DWORD maj, minor;
  WORD nano;
  BYTE stat;
  time_t *movetime;
  if ( bcReadBinTimeEx (hBC_PCI, &maj, &minor, &nano, &stat) == 0 )
  {
    return -1;
  }
  *status = stat;
  uxtime->tv_sec = maj;
  uxtime->tv_usec = minor;
  return 0;
}

canonical_original_code:
int gpsTime(struct timeval *uxtime, unsigned char *status)
{
  unsigned long maj; unsigned long minor;
  unsigned short nano;
  unsigned char stat;
  long *movetime;
  if ( bcReadBinTimeEx (hBC_PCI, &maj, &minor, &nano, &stat) == 0 )
  {
    return -1;
  }
  *status = stat;
  uxtime->tv_sec = maj;
  uxtime->tv_usec = minor;
  return 0;
}

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

variable_types:
status
unsigned char *

variable_types:
maj
unsigned long

variable_types:
minor
unsigned long

variable_types:
nano
unsigned short

variable_types:
stat
unsigned char

variable_types:
movetime
long *


decompiled_code:
int print_memory_info()
{
struct rusage v1; // [rsp+0h] [rbp-98h] BYREF

getrusage(RUSAGE_SELF, &v1);
puts("Memory Usage Statistics:");
printf(" User time used ---------------- %li.%06lli sec.\n", v1.ru_utime.tv_sec, v1.ru_utime.tv_usec % 1000000);
printf(" System time used -------------- %li.%06lli sec.\n", v1.ru_stime.tv_sec, v1.ru_stime.tv_usec % 1000000);
printf(" Maximum resident set size ----- %li\n", v1.ru_maxrss);
printf(" Integral shared memory size --- %li\n", v1.ru_ixrss);
printf(" Integral unshared data size --- %li\n", v1.ru_idrss);
printf(" Integral unshared stack size -- %li\n", v1.ru_isrss);
printf(" Page reclaims ----------------- %li\n", v1.ru_minflt);
printf(" Page faults ------------------- %li\n", v1.ru_majflt);
printf(" Swaps ------------------------- %li\n", v1.ru_nswap);
printf(" Block input operations -------- %li\n", v1.ru_inblock);
printf(" Block output operations ------- %li\n", v1.ru_oublock);
printf(" Messages sent ----------------- %li\n", v1.ru_msgsnd);
printf(" Messages received ------------- %li\n", v1.ru_msgrcv);
printf(" Signals received -------------- %li\n", v1.ru_nsignals);
printf(" Voluntary context switches ---- %li\n", v1.ru_nvcsw);
return printf(" Involuntary context switches -- %li\n", v1.ru_nivcsw);
}

canonical_decompiled_code:
int func2()
{
struct rusage v1; // [rsp+0h] [rbp-98h] BYREF

getrusage(RUSAGE_SELF, &v1);
puts("Memory Usage Statistics:");
printf(" User time used ---------------- %li.%06lli sec.\n", v1.ru_utime.tv_sec, v1.ru_utime.tv_usec % 1000000);
printf(" System time used -------------- %li.%06lli sec.\n", v1.ru_stime.tv_sec, v1.ru_stime.tv_usec % 1000000);
printf(" Maximum resident set size ----- %li\n", v1.ru_maxrss);
printf(" Integral shared memory size --- %li\n", v1.ru_ixrss);
printf(" Integral unshared data size --- %li\n", v1.ru_idrss);
printf(" Integral unshared stack size -- %li\n", v1.ru_isrss);
printf(" Page reclaims ----------------- %li\n", v1.ru_minflt);
printf(" Page faults ------------------- %li\n", v1.ru_majflt);
printf(" Swaps ------------------------- %li\n", v1.ru_nswap);
printf(" Block input operations -------- %li\n", v1.ru_inblock);
printf(" Block output operations ------- %li\n", v1.ru_oublock);
printf(" Messages sent ----------------- %li\n", v1.ru_msgsnd);
printf(" Messages received ------------- %li\n", v1.ru_msgrcv);
printf(" Signals received -------------- %li\n", v1.ru_nsignals);
printf(" Voluntary context switches ---- %li\n", v1.ru_nvcsw);
return printf(" Involuntary context switches -- %li\n", v1.ru_nivcsw);
}

original_code:
void print_memory_info() {
    struct rusage mem_usage;
    getrusage( RUSAGE_SELF, &mem_usage );
    printf( "Memory Usage Statistics:\n" );
    printf( "  User time used ---------------- %li.%06lli sec.\n",
            mem_usage.ru_utime.tv_sec,
            mem_usage.ru_utime.tv_usec % 1000000LL );
    printf( "  System time used -------------- %li.%06lli sec.\n",
            mem_usage.ru_stime.tv_sec,
            mem_usage.ru_stime.tv_usec % 1000000LL );
    printf( "  Maximum resident set size ----- %li\n", mem_usage.ru_maxrss );
    printf( "  Integral shared memory size --- %li\n", mem_usage.ru_ixrss );
    printf( "  Integral unshared data size --- %li\n", mem_usage.ru_idrss );
    printf( "  Integral unshared stack size -- %li\n", mem_usage.ru_isrss );
    printf( "  Page reclaims ----------------- %li\n", mem_usage.ru_minflt );
    printf( "  Page faults ------------------- %li\n", mem_usage.ru_majflt );
    printf( "  Swaps ------------------------- %li\n", mem_usage.ru_nswap );
    printf( "  Block input operations -------- %li\n", mem_usage.ru_inblock );
    printf( "  Block output operations ------- %li\n", mem_usage.ru_oublock );
    printf( "  Messages sent ----------------- %li\n", mem_usage.ru_msgsnd );
    printf( "  Messages received ------------- %li\n", mem_usage.ru_msgrcv );
    printf( "  Signals received -------------- %li\n", mem_usage.ru_nsignals );
    printf( "  Voluntary context switches ---- %li\n", mem_usage.ru_nvcsw );
    printf( "  Involuntary context switches -- %li\n", mem_usage.ru_nivcsw );
}

variable_types: struct rusage { struct timeval { long tv_sec; long tv_usec; } ru_utime; struct timeval ru_stime; union { long ru_maxrss; long __ru_maxrss_word; }; union { long ru_ixrss; long __ru_ixrss_word; }; union { long ru_idrss; long __ru_idrss_word; }; union { long ru_isrss; long __ru_isrss_word; }; union { long ru_minflt; long __ru_minflt_word; }; union { long ru_majflt; long __ru_majflt_word; }; union { long ru_nswap; long __ru_nswap_word; }; union { long ru_inblock; long __ru_inblock_word; }; union { long ru_oublock; long __ru_oublock_word; }; union { long ru_msgsnd; long __ru_msgsnd_word; }; union { long ru_msgrcv; long __ru_msgrcv_word; }; union { long ru_nsignals; long __ru_nsignals_word; }; union { long ru_nvcsw; long __ru_nvcsw_word; }; union { long ru_nivcsw; long __ru_nivcsw_word; }; }

user_defined_types: struct rusage { struct timeval ru_utime; struct timeval ru_stime; union { long ru_maxrss; long __ru_maxrss_word; }; union { long ru_ixrss; long __ru_ixrss_word; }; union { long ru_idrss; long __ru_idrss_word; }; union { long ru_isrss; long __ru_isrss_word; }; union { long ru_minflt; long __ru_minflt_word; }; union { long ru_majflt; long __ru_majflt_word; }; union { long ru_nswap; long __ru_nswap_word; }; union { long ru_inblock; long __ru_inblock_word; }; union { long ru_oublock; long __ru_oublock_word; }; union { long ru_msgsnd; long __ru_msgsnd_word; }; union { long ru_msgrcv; long __ru_msgrcv_word; }; union { long ru_nsignals; long __ru_nsignals_word; }; union { long ru_nvcsw; long __ru_nvcsw_word; }; union { long ru_nivcsw; long __ru_nivcsw_word; }; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v3; // r13
const char *v4; // r12
int v5; // eax
size_t v6; // r14
__int64 v7; // r12
__int64 v8; // rbp
__int64 v9; // r12
__int16 *v10; // rbx
__int16 v11; // r15
__int16 v12; // dx
const char *v14; // rdx
__int64 v15; // rax
char v16; // dl
void *ptr; // [rsp+0h] [rbp-2A8h]
char v18; // [rsp+Bh] [rbp-29Dh]
unsigned int v19; // [rsp+Ch] [rbp-29Ch]
FILE *stream; // [rsp+10h] [rbp-298h]
char v21; // [rsp+18h] [rbp-290h]
char v22; // [rsp+19h] [rbp-28Fh]
char v23; // [rsp+1Ah] [rbp-28Eh]
char v24; // [rsp+1Bh] [rbp-28Dh]
char v25; // [rsp+1Ch] [rbp-28Ch]
char v26; // [rsp+1Dh] [rbp-28Bh]
unsigned __int8 v27; // [rsp+1Eh] [rbp-28Ah]
char v28; // [rsp+1Fh] [rbp-289h]
char v29[6]; // [rsp+22h] [rbp-286h] BYREF
__int64 v30; // [rsp+28h] [rbp-280h] BYREF
__int16 v31[2]; // [rsp+30h] [rbp-278h] BYREF
unsigned __int16 v32; // [rsp+34h] [rbp-274h]
unsigned __int16 v33; // [rsp+36h] [rbp-272h]
unsigned int v34; // [rsp+38h] [rbp-270h]
char v35; // [rsp+3Ch] [rbp-26Ch]
unsigned __int8 v36; // [rsp+3Dh] [rbp-26Bh]
char v37; // [rsp+3Fh] [rbp-269h]
char v38; // [rsp+40h] [rbp-268h]
__int128 v39[2]; // [rsp+50h] [rbp-258h] BYREF
__int128 v40; // [rsp+70h] [rbp-238h]
char v41[64]; // [rsp+80h] [rbp-228h] BYREF
char v42[58]; // [rsp+C0h] [rbp-1E8h] BYREF
__int16 v43; // [rsp+FAh] [rbp-1AEh]
char v44[160]; // [rsp+110h] [rbp-198h] BYREF
char v45[248]; // [rsp+1B0h] [rbp-F8h] BYREF

v30 = 0LL;
v39[0] = 0LL;
v39[1] = 0LL;
v40 = 0LL;
if ( argc <= 1 )
{
print_usage(argv, 0LL);
return 0;
}
v19 = 0;
v3 = 0;
v28 = 0;
v4 = argv[argc - 1];
v22 = 0;
v26 = 0;
v27 = 0;
v23 = 0;
v18 = 0;
v25 = 0;
v24 = 0;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "fghlmrCcTtw");
if ( v5 == -1 )
break;
switch ( v5 )
{
case 'C':
v26 = 1;
break;
case 'T':
v23 = 1;
break;
case 'c':
v27 = 1;
break;
case 'f':
v25 = 1;
break;
case 'g':
v24 = 1;
break;
case 'h':
v3 = 1;
break;
case 'l':
v18 = 1;
break;
case 'm':
v28 = 1;
break;
case 'r':
v22 = 1;
break;
case 't':
BYTE8(v40) = 1;
v23 = 1;
break;
case 'w':
v19 = 1;
break;
default:
fwrite("Got Filename\n", 1uLL, 0xDuLL, stderr);
break;
}
}
ptr = malloc(0x2000uLL);
if ( !ptr )
{
fwrite("Could not allocate memory for read buffer.\n", 1uLL, 0x2BuLL, stderr);
return 0;
}
stream = fopen(v4, "rb");
if ( !stream )
{
fprintf(stderr, "Unable to open file '%s' for reading.\n", v4);
goto LABEL_36;
}
do
{
v6 = fread(ptr, 0x200uLL, 0x10uLL, stream);
v7 = ftell(stream);
fprintf(stdout, "Read %d record(s)\n", v6);
fprintf(stdout, "File position is %ld\n", v7);
if ( feof(stream) || ferror(stream) )
{
fwrite("EOF reached\n", 1uLL, 0xCuLL, stdout);
v21 = 1;
if ( !v22 )
goto LABEL_20;
}
else
{
v21 = 0;
if ( !v22 )
goto LABEL_20;
}
fwrite("Raw Data:\n", 1uLL, 0xAuLL, stdout);
dump_hex(ptr, v6 << 9, 16LL, 32LL);
LABEL_20:
v8 = (__int64)ptr;
v9 = 0LL;
if ( v6 )
{
while ( 1 )
{
v30 = v8;
loadseedhdr(&v30, v42, 0LL);
v10 = (__int16 *)(v8 + v43);
if ( v43 )
break;
LABEL_31:
++v9;
v8 += 512LL;
if ( v6 == v9 )
goto LABEL_32;
}
while ( 1 )
{
_bswap_16(*v10);
v11 = _bswap_16(v10[1]);
if ( v12 != 2000 )
goto LABEL_23;
v30 = (__int64)v10;
loadopaquehdr(&v30, v31);
if ( v3 )
{
puts("Found an opaque blockette:");
jprintf(1LL, "Blockette type: %lu\n", (unsigned __int16)v31[0]);
jprintf(1LL, "Next blockette: %lu\n", (unsigned __int16)v31[1]);
jprintf(1LL, "Blockette length: %lu\n", v32);
jprintf(1LL, "Data offset: %lu\n", v33);
jprintf(1LL, "Record number: %lu\n", v34);
v14 = "Big Endian";
if ( !v35 )
v14 = "Little Endian";
jprintf(1LL, "Data word order: %s\n", v14);
jprintf(1LL, "Opaque data flags: 0x%02lx\n", v36);
v15 = 0LL;
while ( 1 )
{
v16 = *(&v37 + v15);
v29[v15++] = v16;
if ( v16 == 126 || !v16 )
break;
if ( v15 == 5 )
{
v15 = 6LL;
break;
}
}
v29[v15] = 0;
jprintf(1LL, "Record type: %s\n", v29);
jprintf(1LL, "========== RECORD DATA ========== \n");
}
v30 = (__int64)v10 + v33;
if ( v37 == 71 )
{
if ( v38 == 76 )
{
loadglob(&v30, v44);
if ( v24 )
{
jprintf(2LL, "Global Config:\n");
print_global(v44, 3LL, v19);
}
}
goto LABEL_23;
}
if ( v37 != 70 )
{
if ( v37 == 76 )
{
loadlog(&v30, v41);
if ( v18 )
{
jprintf(2LL, "Log Config:\n");
print_log(v41, 3LL, v19);
}
}
else if ( v37 == 84 )
{
append_tokens(v39, (char *)v10 + v33, v32 - (unsigned __int64)v33, v36);
if ( (unsigned __int8)tokens_complete(v39) )
{
if ( v23 )
{
jprintf(2LL, "Token Config:\n");
print_tokens(v39, 3LL, v19);
}
else if ( v26 )
{
jprintf(2LL, "Token Config (manual):\n");
parse_tokens(v39, v27, 3LL);
}
else if ( v27 )
{
jprintf(2LL, "Token Config (raw):\n");
dump_tokens(v39);
}
}
}
goto LABEL_23;
}
if ( v38 == 88 && (loadfix(&v30, v45), v25) )
{
jprintf(2LL, "Fixed Config:\n");
v10 = (__int16 *)(v8 + v11);
print_fixed(v45, 3LL, v19);
if ( !v11 )
goto LABEL_31;
}
else
{
LABEL_23:
v10 = (__int16 *)(v8 + v11);
if ( !v11 )
goto LABEL_31;
}
}
}
LABEL_32:
;
}
while ( !v21 );
if ( v28 )
print_memory_info();
fclose(stream);
LABEL_36:
free(ptr);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v3; // r13
const char *v4; // r12
int v5; // eax
size_t v6; // r14
__int64 v7; // r12
__int64 v8; // rbp
__int64 v9; // r12
__int16 *v10; // rbx
__int16 v11; // r15
__int16 v12; // dx
const char *v14; // rdx
__int64 v15; // rax
char v16; // dl
void *ptr; // [rsp+0h] [rbp-2A8h]
char v18; // [rsp+Bh] [rbp-29Dh]
unsigned int v19; // [rsp+Ch] [rbp-29Ch]
FILE *stream; // [rsp+10h] [rbp-298h]
char v21; // [rsp+18h] [rbp-290h]
char v22; // [rsp+19h] [rbp-28Fh]
char v23; // [rsp+1Ah] [rbp-28Eh]
char v24; // [rsp+1Bh] [rbp-28Dh]
char v25; // [rsp+1Ch] [rbp-28Ch]
char v26; // [rsp+1Dh] [rbp-28Bh]
unsigned __int8 v27; // [rsp+1Eh] [rbp-28Ah]
char v28; // [rsp+1Fh] [rbp-289h]
char v29[6]; // [rsp+22h] [rbp-286h] BYREF
__int64 v30; // [rsp+28h] [rbp-280h] BYREF
__int16 v31[2]; // [rsp+30h] [rbp-278h] BYREF
unsigned __int16 v32; // [rsp+34h] [rbp-274h]
unsigned __int16 v33; // [rsp+36h] [rbp-272h]
unsigned int v34; // [rsp+38h] [rbp-270h]
char v35; // [rsp+3Ch] [rbp-26Ch]
unsigned __int8 v36; // [rsp+3Dh] [rbp-26Bh]
char v37; // [rsp+3Fh] [rbp-269h]
char v38; // [rsp+40h] [rbp-268h]
__int128 v39[2]; // [rsp+50h] [rbp-258h] BYREF
__int128 v40; // [rsp+70h] [rbp-238h]
char v41[64]; // [rsp+80h] [rbp-228h] BYREF
char v42[58]; // [rsp+C0h] [rbp-1E8h] BYREF
__int16 v43; // [rsp+FAh] [rbp-1AEh]
char v44[160]; // [rsp+110h] [rbp-198h] BYREF
char v45[248]; // [rsp+1B0h] [rbp-F8h] BYREF

v30 = 0LL;
v39[0] = 0LL;
v39[1] = 0LL;
v40 = 0LL;
if ( argc <= 1 )
{
func1(argv, 0LL);
return 0;
}
v19 = 0;
v3 = 0;
v28 = 0;
v4 = argv[argc - 1];
v22 = 0;
v26 = 0;
v27 = 0;
v23 = 0;
v18 = 0;
v25 = 0;
v24 = 0;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "fghlmrCcTtw");
if ( v5 == -1 )
break;
switch ( v5 )
{
case 'C':
v26 = 1;
break;
case 'T':
v23 = 1;
break;
case 'c':
v27 = 1;
break;
case 'f':
v25 = 1;
break;
case 'g':
v24 = 1;
break;
case 'h':
v3 = 1;
break;
case 'l':
v18 = 1;
break;
case 'm':
v28 = 1;
break;
case 'r':
v22 = 1;
break;
case 't':
BYTE8(v40) = 1;
v23 = 1;
break;
case 'w':
v19 = 1;
break;
default:
fwrite("Got Filename\n", 1uLL, 0xDuLL, stderr);
break;
}
}
ptr = malloc(0x2000uLL);
if ( !ptr )
{
fwrite("Could not allocate memory for read buffer.\n", 1uLL, 0x2BuLL, stderr);
return 0;
}
stream = fopen(v4, "rb");
if ( !stream )
{
fprintf(stderr, "Unable to open file '%s' for reading.\n", v4);
goto LABEL_36;
}
do
{
v6 = fread(ptr, 0x200uLL, 0x10uLL, stream);
v7 = ftell(stream);
fprintf(stdout, "Read %d record(s)\n", v6);
fprintf(stdout, "File position is %ld\n", v7);
if ( feof(stream) || ferror(stream) )
{
fwrite("EOF reached\n", 1uLL, 0xCuLL, stdout);
v21 = 1;
if ( !v22 )
goto LABEL_20;
}
else
{
v21 = 0;
if ( !v22 )
goto LABEL_20;
}
fwrite("Raw Data:\n", 1uLL, 0xAuLL, stdout);
dump_hex(ptr, v6 << 9, 16LL, 32LL);
LABEL_20:
v8 = (__int64)ptr;
v9 = 0LL;
if ( v6 )
{
while ( 1 )
{
v30 = v8;
loadseedhdr(&v30, v42, 0LL);
v10 = (__int16 *)(v8 + v43);
if ( v43 )
break;
LABEL_31:
++v9;
v8 += 512LL;
if ( v6 == v9 )
goto LABEL_32;
}
while ( 1 )
{
func0(*v10);
v11 = func0(v10[1]);
if ( v12 != 2000 )
goto LABEL_23;
v30 = (__int64)v10;
loadopaquehdr(&v30, v31);
if ( v3 )
{
puts("Found an opaque blockette:");
jprintf(1LL, "Blockette type: %lu\n", (unsigned __int16)v31[0]);
jprintf(1LL, "Next blockette: %lu\n", (unsigned __int16)v31[1]);
jprintf(1LL, "Blockette length: %lu\n", v32);
jprintf(1LL, "Data offset: %lu\n", v33);
jprintf(1LL, "Record number: %lu\n", v34);
v14 = "Big Endian";
if ( !v35 )
v14 = "Little Endian";
jprintf(1LL, "Data word order: %s\n", v14);
jprintf(1LL, "Opaque data flags: 0x%02lx\n", v36);
v15 = 0LL;
while ( 1 )
{
v16 = *(&v37 + v15);
v29[v15++] = v16;
if ( v16 == 126 || !v16 )
break;
if ( v15 == 5 )
{
v15 = 6LL;
break;
}
}
v29[v15] = 0;
jprintf(1LL, "Record type: %s\n", v29);
jprintf(1LL, "========== RECORD DATA ========== \n");
}
v30 = (__int64)v10 + v33;
if ( v37 == 71 )
{
if ( v38 == 76 )
{
loadglob(&v30, v44);
if ( v24 )
{
jprintf(2LL, "Global Config:\n");
print_global(v44, 3LL, v19);
}
}
goto LABEL_23;
}
if ( v37 != 70 )
{
if ( v37 == 76 )
{
loadlog(&v30, v41);
if ( v18 )
{
jprintf(2LL, "Log Config:\n");
print_log(v41, 3LL, v19);
}
}
else if ( v37 == 84 )
{
append_tokens(v39, (char *)v10 + v33, v32 - (unsigned __int64)v33, v36);
if ( (unsigned __int8)tokens_complete(v39) )
{
if ( v23 )
{
jprintf(2LL, "Token Config:\n");
print_tokens(v39, 3LL, v19);
}
else if ( v26 )
{
jprintf(2LL, "Token Config (manual):\n");
parse_tokens(v39, v27, 3LL);
}
else if ( v27 )
{
jprintf(2LL, "Token Config (raw):\n");
dump_tokens(v39);
}
}
}
goto LABEL_23;
}
if ( v38 == 88 && (loadfix(&v30, v45), v25) )
{
jprintf(2LL, "Fixed Config:\n");
v10 = (__int16 *)(v8 + v11);
print_fixed(v45, 3LL, v19);
if ( !v11 )
goto LABEL_31;
}
else
{
LABEL_23:
v10 = (__int16 *)(v8 + v11);
if ( !v11 )
goto LABEL_31;
}
}
}
LABEL_32:
;
}
while ( !v21 );
if ( v28 )
func2();
fclose(stream);
LABEL_36:
free(ptr);
return 0;
}

original_code:
int main ( int argc, char **argv )
{
    int file_times;
    int c = 0;
    bool single_file = 0;
    int verbosity = 0;
    if ( argc < 3 ) {
        print_usage( argv, ((void *)0) );
        goto clean;
    }
    while ((c = getopt( argc, argv, "sv" )) != -1) {
        switch (c) {
            case 's':
                single_file = 1;
                break;
            case 'v':
                verbosity++;
                break;
            default:
                fprintf( stderr, "Got Filename\n" );
                break;
        }
    }
    if ( single_file ) {
        diff_in_file( argv[argc - 1], verbosity );
    } else {
        diff_files( argv[argc - 1], argv[argc - 2], verbosity );
    }
clean:
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    int file_times;
    int c = 0;
    unsigned char single_file = 0;
    int verbosity = 0;
    if ( argc < 3 ) {
        print_usage( argv, ((void *)0) );
        goto clean;
    }
    while ((c = getopt( argc, argv, "sv" )) != -1) {
        switch (c) {
            case 's':
                single_file = 1;
                break;
            case 'v':
                verbosity++;
                break;
            default:
                fprintf( stderr, "Got Filename\n" );
                break;
        }
    }
    if ( single_file ) {
        diff_in_file( argv[argc - 1], verbosity );
    } else {
        diff_files( argv[argc - 1], argv[argc - 2], verbosity );
    }
clean:
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: c int

variable_types: verbosity int


decompiled_code:
__int64 __fastcall get_page(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
__int64 v3; // rax

v2 = url_resource_new();
v3 = url_new();
*(_QWORD *)v2 = v3;
url_init(v3, a1);
*(_BYTE *)(v2 + 40) |= 0x14u;
http_transfer(v2, a2);
url_resource_destroy(v2);
buffer_seek_end(a2);
return buffer_terminate(a2);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
__int64 v3; // rax

v2 = url_resource_new();
v3 = url_new();
*(_QWORD *)v2 = v3;
url_init(v3, a1);
*(_BYTE *)(v2 + 40) |= 0x14u;
http_transfer(v2, a2);
url_resource_destroy(v2);
buffer_seek_end(a2);
return buffer_terminate(a2);
}

original_code:
void get_page( char* url_str, buffer_t* buf )
{
    UrlResource* rsc;
    rsc = (UrlResource*)url_resource_new();
    rsc->url = (Url*)url_new();
    url_init(rsc->url, url_str);
    rsc->options |= (1 << 4) | (1 << 2);
    http_transfer(rsc, buf);
    url_resource_destroy(rsc);
    rsc = ((void *)0);
    buffer_seek_end(buf);
    buffer_terminate(buf);
}

canonical_original_code:
void get_page(char *url_str, struct _buffer *buf)
{
    struct _UrlResource *rsc;
    rsc = (struct _UrlResource *)url_resource_new();
    rsc->url = (struct _Url *)url_new();
    url_init(rsc->url, url_str);
    rsc->options |= (1 << 4) | (1 << 2);
    http_transfer(rsc, buf);
    url_resource_destroy(rsc);
    rsc = ((void *)0);
    buffer_seek_end(buf);
    buffer_terminate(buf);
}

variable_types: struct _buffer { unsigned char *content; unsigned long length; unsigned long capacity; unsigned long offset; } *

variable_types: struct _UrlResource { struct _Url { char *full_url; int service_type; char *username; char *password; char *host; int port; char *path; char *file; } *url; char *outfile; char *proxy; char *proxy_username; char *proxy_password; unsigned char options; long outfile_size; long outfile_offset; } *

user_defined_types: struct _UrlResource { struct _Url *url; char *outfile; char *proxy; char *proxy_username; char *proxy_password; unsigned char options; long outfile_size; long outfile_offset; }


WildMatch

original_code:
int WildMatch(char *pattern, char *target)
{
 int link[1025];
 register int first, last;
 register int here, next;
 char lowch;
 first = last = 0;
 link[0] = -1;
 for (; *target; ++target)
 {
  lowch = tolower(*target);
  last = -1;
  for (here = first; here >= 0; here = next)
  {
   next = link[here];
   switch (pattern[here])
   {
   case '*':
    if (next != here + 1)
    {
     link[here + 1] = next;
     next = here + 1;
    }
    break;
   default:
    if (tolower(pattern[here]) != lowch)
     continue;
   case '?':
    ++here;
    break;
   }
   if (last < 0)
    first = here;
   else
    link[last] = here;
   last = here;
  }
  if (last == -1) return(0);
  link[last] = -1;
 }
 while (pattern[last] == '*')
  ++last;
 return(pattern[last] == '\0');
}

canonical_original_code:
int WildMatch(char *pattern, char *target)
{
 int link[1025];
 register int first; register int last;
 register int here; register int next;
 char lowch;
 first = last = 0;
 link[0] = -1;
 for (; *target; ++target)
 {
  lowch = tolower(*target);
  last = -1;
  for (here = first; here >= 0; here = next)
  {
   next = link[here];
   switch (pattern[here])
   {
   case '*':
    if (next != here + 1)
    {
     link[here + 1] = next;
     next = here + 1;
    }
    break;
   default:
    if (tolower(pattern[here]) != lowch)
     continue;
   case '?':
    ++here;
    break;
   }
   if (last < 0)
    first = here;
   else
    link[last] = here;
   last = here;
  }
  if (last == -1) return(0);
  link[last] = -1;
 }
 while (pattern[last] == '*')
  ++last;
 return(pattern[last] == '\0');
}

variable_types:
pattern
char *

variable_types:
target
char *

variable_types:
link
int [1025]

variable_types: first int

variable_types: last int

variable_types: here int

variable_types: next int

variable_types: lowch char


decompiled_code:
char *__fastcall ST_PrintDate2(__int64 a1, __int16 a2, char a3)
{
__int64 v3; // r12
__int64 v4; // rcx
__int64 v6; // rdx
char s[48]; // [rsp+28h] [rbp-30h] BYREF

v3 = (unsigned int)SBYTE6(a1);
v4 = (unsigned int)((int)a1 >> 16);
if ( a3 )
{
sprintf(
odata_0,
"%04d,%03d,%02d:%02d:%02d.%04d",
(unsigned int)(__int16)a1,
v4,
(unsigned int)SBYTE4(a1),
(unsigned int)SBYTE5(a1),
v3,
(unsigned int)a2);
}
else
{
if ( a2 )
{
v6 = (unsigned int)a2;
if ( __ROR8__(0x1CAC083126E978D5LL * a2 + 0x10624DD2F1A9FB8LL, 3) <= 0x4189374BC6A7EEuLL )
{
sprintf(s, ".%01d", (unsigned int)((int)v6 / 1000));
v4 = (unsigned int)((int)a1 >> 16);
}
else if ( __ROR8__(0x51EB851EB851EB8LL - 0x70A3D70A3D70A3D7LL * a2, 2) <= 0x28F5C28F5C28F5CuLL )
{
sprintf(s, ".%02d", (unsigned int)((int)v6 / 100));
v4 = (unsigned int)((int)a1 >> 16);
}
else
{
if ( __ROR8__(0xCCCCCCCCCCCCCCCDLL * a2 + 0x1999999999999998LL, 1) > 0x1999999999999998uLL )
sprintf(s, ".%04d", v6);
else
sprintf(s, ".%03d", (unsigned int)((int)v6 / 10));
v4 = (unsigned int)((int)a1 >> 16);
}
}
else
{
s[0] = 0;
}
sprintf(
odata_0,
"%d,%d,%d:%02d:%02d%s",
(unsigned int)(__int16)a1,
v4,
(unsigned int)SBYTE4(a1),
(unsigned int)SBYTE5(a1),
v3,
s);
}
return odata_0;
}

canonical_decompiled_code:
char *__fastcall func0(__int64 a1, __int16 a2, char a3)
{
__int64 v3; // r12
__int64 v4; // rcx
__int64 v6; // rdx
char s[48]; // [rsp+28h] [rbp-30h] BYREF

v3 = (unsigned int)SBYTE6(a1);
v4 = (unsigned int)((int)a1 >> 16);
if ( a3 )
{
sprintf(
odata_0,
"%04d,%03d,%02d:%02d:%02d.%04d",
(unsigned int)(__int16)a1,
v4,
(unsigned int)SBYTE4(a1),
(unsigned int)SBYTE5(a1),
v3,
(unsigned int)a2);
}
else
{
if ( a2 )
{
v6 = (unsigned int)a2;
if ( __ROR8__(0x1CAC083126E978D5LL * a2 + 0x10624DD2F1A9FB8LL, 3) <= 0x4189374BC6A7EEuLL )
{
sprintf(s, ".%01d", (unsigned int)((int)v6 / 1000));
v4 = (unsigned int)((int)a1 >> 16);
}
else if ( __ROR8__(0x51EB851EB851EB8LL - 0x70A3D70A3D70A3D7LL * a2, 2) <= 0x28F5C28F5C28F5CuLL )
{
sprintf(s, ".%02d", (unsigned int)((int)v6 / 100));
v4 = (unsigned int)((int)a1 >> 16);
}
else
{
if ( __ROR8__(0xCCCCCCCCCCCCCCCDLL * a2 + 0x1999999999999998LL, 1) > 0x1999999999999998uLL )
sprintf(s, ".%04d", v6);
else
sprintf(s, ".%03d", (unsigned int)((int)v6 / 10));
v4 = (unsigned int)((int)a1 >> 16);
}
}
else
{
s[0] = 0;
}
sprintf(
odata_0,
"%d,%d,%d:%02d:%02d%s",
(unsigned int)(__int16)a1,
v4,
(unsigned int)SBYTE4(a1),
(unsigned int)SBYTE5(a1),
v3,
s);
}
return odata_0;
}

original_code:
UBYTE *ST_PrintDate2(STDTIME2 odate, BOOL fixfmt) {
  static UBYTE _odata[60];
  long tenth_ms;
  UBYTE msprt[8];
  if (fixfmt) {
    sprintf(_odata,"%04d,%03d,%02d:%02d:%02d.%04d",
     (int) odate.year,
     (int) odate.day,
     (int) odate.hour,
     (int) odate.minute,
     (int) odate.second,
     (int) odate.tenth_msec);
    return(_odata);
  }
  tenth_ms = odate.tenth_msec;
  if (tenth_ms == 0)
    msprt[0] = '\0';
  else
    if (tenth_ms%1000 == 0)
      sprintf(msprt,".%01d", (int)tenth_ms/1000);
    else
      if (tenth_ms%100 == 0)
        sprintf(msprt,".%02d", (int) tenth_ms/100);
      else
        if (tenth_ms%10 == 0)
          sprintf(msprt,".%03d", (int) tenth_ms/10);
        else
          sprintf(msprt,".%04d", (int) tenth_ms);
  sprintf(_odata,"%d,%d,%d:%02d:%02d%s",
   (int) odate.year,
   (int) odate.day,
   (int) odate.hour,
   (int) odate.minute,
   (int) odate.second,
   msprt);
  return(_odata);
}

canonical_original_code:
unsigned char *ST_PrintDate2(struct __sjtim2 odate, unsigned char fixfmt) {
  static unsigned char _odata[60];
  long tenth_ms;
  unsigned char msprt[8];
  if (fixfmt) {
    sprintf(_odata,"%04d,%03d,%02d:%02d:%02d.%04d",
     (int) odate.year,
     (int) odate.day,
     (int) odate.hour,
     (int) odate.minute,
     (int) odate.second,
     (int) odate.tenth_msec);
    return(_odata);
  }
  tenth_ms = odate.tenth_msec;
  if (tenth_ms == 0)
    msprt[0] = '\0';
  else
    if (tenth_ms%1000 == 0)
      sprintf(msprt,".%01d", (int)tenth_ms/1000);
    else
      if (tenth_ms%100 == 0)
        sprintf(msprt,".%02d", (int) tenth_ms/100);
      else
        if (tenth_ms%10 == 0)
          sprintf(msprt,".%03d", (int) tenth_ms/10);
        else
          sprintf(msprt,".%04d", (int) tenth_ms);
  sprintf(_odata,"%d,%d,%d:%02d:%02d%s",
   (int) odate.year,
   (int) odate.day,
   (int) odate.hour,
   (int) odate.minute,
   (int) odate.second,
   msprt);
  return(_odata);
}

variable_types: struct __sjtim2 { short year; short day; char hour; char minute; char second; short tenth_msec; }

variable_types:
fixfmt
unsigned char

variable_types:
msprt
unsigned char [8]

return_type: unsigned char *


push

decompiled_code:
int __fastcall push(double a1)
{
int result; // eax

result = dword_404380;
if ( dword_404380 > 99 )
return printf("error: stack full, can't push %g\n", a1);
val[dword_404380] = a1;
dword_404380 = result + 1;
return result;
}

canonical_decompiled_code:
int __fastcall func7(double a1)
{
int result; // eax

result = dword_404380;
if ( dword_404380 > 99 )
return printf("error: stack full, can't push %g\n", a1);
val[dword_404380] = a1;
dword_404380 = result + 1;
return result;
}

original_code:
void push(double f)
{
 if(sp < 100){
  val[sp++] = f;
 }
 else{
  printf("error: stack full, can't push %g\n",f);
 }
}

variable_types: f double


pop

decompiled_code:
double pop()
{
int v0; // eax
double result; // xmm0_8

v0 = dword_404380;
if ( dword_404380 <= 0 )
{
puts("error: stack empty");
result = 0.0;
}
else
{
--dword_404380;
result = val[v0 - 1];
}
return result;
}

canonical_decompiled_code:
double func8()
{
int v0; // eax
double result; // xmm0_8

v0 = dword_404380;
if ( dword_404380 <= 0 )
{
puts("error: stack empty");
result = 0.0;
}
else
{
--dword_404380;
result = val[v0 - 1];
}
return result;
}

original_code:
double pop()
{
 if(sp > 0){
  return val[--sp];
 }
 else {
  printf("error: stack empty\n");
  return 0.0;
 }
}

return_type: double


peek

decompiled_code:
double peek()
{
if ( dword_404380 > 0 )
return val[dword_404380 - 1];
puts("error: stack empty");
return 0.0;
}

canonical_decompiled_code:
double func9()
{
if ( dword_404380 > 0 )
return val[dword_404380 - 1];
puts("error: stack empty");
return 0.0;
}

original_code:
double peek()
{
 if(sp > 0){
  return val[sp-1];
 }
 else {
  printf("error: stack empty\n");
  return 0.0;
 }
}


switchtoptwo

decompiled_code:
int switchtoptwo()
{
int result; // eax
double v1; // xmm0_8

if ( dword_404380 <= 1 )
return puts("error: insufficient number of elements in stack. ");
result = dword_404380 - 2;
v1 = val[dword_404380 - 1];
val[dword_404380 - 1] = val[dword_404380 - 2];
val[result] = v1;
return result;
}

canonical_decompiled_code:
int func10()
{
int result; // eax
double v1; // xmm0_8

if ( dword_404380 <= 1 )
return puts("error: insufficient number of elements in stack. ");
result = dword_404380 - 2;
v1 = val[dword_404380 - 1];
val[dword_404380 - 1] = val[dword_404380 - 2];
val[result] = v1;
return result;
}

original_code:
void switchtoptwo()
{
 double temp;
 if(sp > 1){
  temp = val[sp -1];
  val[sp -1] = val[sp -2];
  val[sp -2] = temp;
 }
 else{
  printf("error: insufficient number of elements in stack. \n");
 }
}

variable_types: temp double


clearstack

decompiled_code:
void clearstack()
{
dword_404380 = 0;
}

original_code:
void clearstack()
{
 sp = 0;
}

canonical_original_code:
void clearstack()
{
 sp = 0;
}


ungets

decompiled_code:
int __fastcall ungets(const char *a1)
{
int result; // eax
char *v2; // rbx
__int64 v3; // rbp
char v4; // di

result = strlen(a1);
if ( result > 0 )
{
v2 = (char *)&a1[result - 1];
v3 = (__int64)&a1[result - 2 - (result - 1)];
do
{
v4 = *v2--;
result = ungetch(v4);
}
while ( v2 != (char *)v3 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(const char *a1)
{
int result; // eax
char *v2; // rbx
__int64 v3; // rbp
char v4; // di

result = strlen(a1);
if ( result > 0 )
{
v2 = (char *)&a1[result - 1];
v3 = (__int64)&a1[result - 2 - (result - 1)];
do
{
v4 = *v2--;
result = func8(v4);
}
while ( v2 != (char *)v3 );
}
return result;
}

original_code:
void ungets(char s[])
{
 int i = strlen(s);
 while(i-- > 0){
  ungetch(s[i]);
 }
}

variable_types:
s
char []

variable_types: i int


getch

decompiled_code:
int getch()
{
int v0; // eax

v0 = bufp;
if ( bufp <= 0 )
return getchar();
--bufp;
return buf[v0 - 1];
}

canonical_decompiled_code:
int func7()
{
int v0; // eax

v0 = bufp;
if ( bufp <= 0 )
return getchar();
--bufp;
return buf[v0 - 1];
}

original_code:
int getch()
{
 return (bufp > 0)? buf[--bufp]: getchar();
}


ungetch

decompiled_code:
int __fastcall ungetch(char a1)
{
int result; // eax

result = bufp;
if ( bufp > 99 )
return puts("ungetch: too many characters!");
buf[bufp] = a1;
bufp = result + 1;
return result;
}

canonical_decompiled_code:
int __fastcall func8(char a1)
{
int result; // eax

result = bufp;
if ( bufp > 99 )
return puts("ungetch: too many characters!");
buf[bufp] = a1;
bufp = result + 1;
return result;
}

original_code:
void ungetch(int c)
{
 if(bufp >= 100){
  printf("ungetch: too many characters!\n");
 }
 else{
  buf[bufp++] = c;
 }
}

variable_types: c int


push

decompiled_code:
int __fastcall push(double a1)
{
int result; // eax

result = dword_4044A0;
if ( dword_4044A0 > 99 )
return printf("error: stack full, can't push %g\n", a1);
val[dword_4044A0] = a1;
dword_4044A0 = result + 1;
return result;
}

canonical_decompiled_code:
int __fastcall func7(double a1)
{
int result; // eax

result = dword_4044A0;
if ( dword_4044A0 > 99 )
return printf("error: stack full, can't push %g\n", a1);
val[dword_4044A0] = a1;
dword_4044A0 = result + 1;
return result;
}

canonical_original_code:
void push(double f)
{
 if(sp < 100){
  val[sp++] = f;
 }
 else{
  printf("error: stack full, can't push %g\n",f);
 }
}


pop

decompiled_code:
double pop()
{
int v0; // eax
double result; // xmm0_8

v0 = dword_4044A0;
if ( dword_4044A0 <= 0 )
{
puts("error: stack empty");
result = 0.0;
}
else
{
--dword_4044A0;
result = val[v0 - 1];
}
return result;
}

canonical_decompiled_code:
double func8()
{
int v0; // eax
double result; // xmm0_8

v0 = dword_4044A0;
if ( dword_4044A0 <= 0 )
{
puts("error: stack empty");
result = 0.0;
}
else
{
--dword_4044A0;
result = val[v0 - 1];
}
return result;
}

canonical_original_code:
double pop()
{
 if(sp > 0){
  return val[--sp];
 }
 else {
  printf("error: stack empty\n");
  return 0.0;
 }
}


mathfunctions

decompiled_code:
void __fastcall mathfunctions(const char *a1)
{
double v1; // xmm1_8
double v2; // xmm0_8
double v3; // xmm0_8
double v4; // xmm0_8
double v5; // xmm0_8
double v6; // xmm0_8
double v7; // xmm0_8
double v8; // xmm1_8
double v9; // xmm0_8
double v10; // xmm0_8
double v11; // xmm0_8
double v12; // xmm0_8
double v13; // xmm1_8
double x; // [rsp+8h] [rbp-10h]

if ( !strcmp(a1, "sin") )
{
v2 = pop();
sin(v2);
return;
}
if ( !strcmp(a1, "cos") )
{
v4 = pop();
cos(v4);
return;
}
if ( !strcmp(a1, "tan") )
{
v5 = pop();
tan(v5);
return;
}
if ( !strcmp(a1, "asin") )
{
v3 = pop();
if ( v3 <= 1.0 && v3 >= -1.0 )
{
asin(v3);
return;
}
LABEL_25:
printf("Input outside of function range");
return;
}
if ( !strcmp(a1, "acos") )
{
v6 = pop();
if ( v6 <= 1.0 && v6 >= -1.0 )
{
acos(v6);
return;
}
goto LABEL_25;
}
if ( !strcmp(a1, "atan") )
{
v7 = pop();
atan(v7);
return;
}
if ( !strcmp(a1, "sinh") )
{
v9 = pop();
sinh(v9);
return;
}
if ( !strcmp(a1, "cosh") )
{
v10 = pop();
cosh(v10);
return;
}
if ( !strcmp(a1, "tanh") )
{
v11 = pop();
tanh(v11);
return;
}
if ( !strcmp(a1, "exp") )
{
v12 = pop();
exp(v12);
return;
}
if ( !strcmp(a1, "log") )
{
v8 = pop();
if ( v8 > 0.0 )
{
log(v8);
return;
}
goto LABEL_39;
}
if ( !strcmp(a1, "log10") )
{
v13 = pop();
if ( v13 > 0.0 )
{
log10(v13);
return;
}
LABEL_39:
printf("Input must be greater than zero");
return;
}
if ( !strcmp(a1, "sqrt") )
{
if ( pop() < 0.0 )
printf("Input must be equal or greater than zero");
}
else if ( strcmp(a1, "ceil") && strcmp(a1, "floor") )
{
if ( !strcmp(a1, "pow") )
{
x = pop();
v1 = pop();
if ( x == 0.0 && v1 < 0.0 || x <= 0.0 && v1 - (double)(int)v1 != 0.0 )
printf("Domain error");
else
pow(x, v1);
}
else
{
printf("error: unkown command %s\n", a1);
}
}
}

canonical_decompiled_code:
void __fastcall func12(const char *a1)
{
double v1; // xmm1_8
double v2; // xmm0_8
double v3; // xmm0_8
double v4; // xmm0_8
double v5; // xmm0_8
double v6; // xmm0_8
double v7; // xmm0_8
double v8; // xmm1_8
double v9; // xmm0_8
double v10; // xmm0_8
double v11; // xmm0_8
double v12; // xmm0_8
double v13; // xmm1_8
double x; // [rsp+8h] [rbp-10h]

if ( !strcmp(a1, "sin") )
{
v2 = func8();
sin(v2);
return;
}
if ( !strcmp(a1, "cos") )
{
v4 = func8();
cos(v4);
return;
}
if ( !strcmp(a1, "tan") )
{
v5 = func8();
tan(v5);
return;
}
if ( !strcmp(a1, "asin") )
{
v3 = func8();
if ( v3 <= 1.0 && v3 >= -1.0 )
{
asin(v3);
return;
}
LABEL_25:
printf("Input outside of function range");
return;
}
if ( !strcmp(a1, "acos") )
{
v6 = func8();
if ( v6 <= 1.0 && v6 >= -1.0 )
{
acos(v6);
return;
}
goto LABEL_25;
}
if ( !strcmp(a1, "atan") )
{
v7 = func8();
atan(v7);
return;
}
if ( !strcmp(a1, "sinh") )
{
v9 = func8();
sinh(v9);
return;
}
if ( !strcmp(a1, "cosh") )
{
v10 = func8();
cosh(v10);
return;
}
if ( !strcmp(a1, "tanh") )
{
v11 = func8();
tanh(v11);
return;
}
if ( !strcmp(a1, "exp") )
{
v12 = func8();
exp(v12);
return;
}
if ( !strcmp(a1, "log") )
{
v8 = func8();
if ( v8 > 0.0 )
{
log(v8);
return;
}
goto LABEL_39;
}
if ( !strcmp(a1, "log10") )
{
v13 = func8();
if ( v13 > 0.0 )
{
log10(v13);
return;
}
LABEL_39:
printf("Input must be greater than zero");
return;
}
if ( !strcmp(a1, "sqrt") )
{
if ( func8() < 0.0 )
printf("Input must be equal or greater than zero");
}
else if ( strcmp(a1, "ceil") && strcmp(a1, "floor") )
{
if ( !strcmp(a1, "pow") )
{
x = func8();
v1 = func8();
if ( x == 0.0 && v1 < 0.0 || x <= 0.0 && v1 - (double)(int)v1 != 0.0 )
printf("Domain error");
else
pow(x, v1);
}
else
{
printf("error: unkown command %s\n", a1);
}
}
}

original_code:
double mathfunctions(char s[])
{
 double pop(void);
 double op1,op2;
 op1 = op2 = 0;
 if(strcmp(s,"sin")== 0){
  return sin(pop());
 }
 else if(strcmp(s,"cos")==0){
  return cos(pop());
 }
 else if(strcmp(s,"tan")==0){
  return tan(pop());
 }
 else if(strcmp(s,"asin")==0){
  op1 = pop();
  if(op1 <= 1.0 && op1 >= -1.0){
   return asin(op1);
  }
  else{
   printf("Input outside of function range");
   return 0.0;
  }
 }
 else if(strcmp(s,"acos")==0){
  op1 = pop();
  if(op1 <= 1.0 && op1 >= -1.0){
   return acos(op1);
  }
  else{
   printf("Input outside of function range");
  }
 }
 else if(strcmp(s,"atan")==0){
  return atan(pop());
 }
 else if(strcmp(s,"sinh")==0){
  return sinh(pop());
 }
 else if(strcmp(s,"cosh")==0){
  return cosh(pop());
 }
 else if(strcmp(s,"tanh")==0){
  return tanh(pop());
 }
 else if(strcmp(s,"exp")==0){
  return exp(pop());
 }
 else if(strcmp(s,"log")==0){
  op1 = pop();
  if(op1 >0){
   return log(op1);
  }
  else{
   printf("Input must be greater than zero");
   return 0.0;
  }
 }
 else if(strcmp(s,"log10")==0){
  op1 = pop();
  if(op1 >0){
   return log10(op1);
  }
  else{
   printf("Input must be greater than zero");
   return 0.0;
  }
 }
 else if(strcmp(s,"sqrt")==0){
  op1 = pop();
  if(op1 >=0){
   return sqrt(op1);
  }
  else{
   printf("Input must be equal or greater than zero");
   return 0.0;
  }
 }
 else if(strcmp(s,"ceil")==0){
  return ceil(op1);
 }
 else if(strcmp(s,"floor")==0){
  return floor(op1);
 }
 else if(strcmp(s,"pow")==0){
  op1 = pop();
  op2 = pop();
  if((op1 != 0 || op2 >= 0)&&(op1>0||(op2 -(int)op2)==0.0)){
   return pow(op1,op2);
  }
  else{
   printf("Domain error");
  }
 }
 else{
  printf("error: unkown command %s\n",s);
 }
 return 0.0;
}

canonical_original_code:
double mathfunctions(char s[])
{
 double pop();
 double op1; double op2;
 op1 = op2 = 0;
 if(strcmp(s,"sin")== 0){
  return sin(pop());
 }
 else if(strcmp(s,"cos")==0){
  return cos(pop());
 }
 else if(strcmp(s,"tan")==0){
  return tan(pop());
 }
 else if(strcmp(s,"asin")==0){
  op1 = pop();
  if(op1 <= 1.0 && op1 >= -1.0){
   return asin(op1);
  }
  else{
   printf("Input outside of function range");
   return 0.0;
  }
 }
 else if(strcmp(s,"acos")==0){
  op1 = pop();
  if(op1 <= 1.0 && op1 >= -1.0){
   return acos(op1);
  }
  else{
   printf("Input outside of function range");
  }
 }
 else if(strcmp(s,"atan")==0){
  return atan(pop());
 }
 else if(strcmp(s,"sinh")==0){
  return sinh(pop());
 }
 else if(strcmp(s,"cosh")==0){
  return cosh(pop());
 }
 else if(strcmp(s,"tanh")==0){
  return tanh(pop());
 }
 else if(strcmp(s,"exp")==0){
  return exp(pop());
 }
 else if(strcmp(s,"log")==0){
  op1 = pop();
  if(op1 >0){
   return log(op1);
  }
  else{
   printf("Input must be greater than zero");
   return 0.0;
  }
 }
 else if(strcmp(s,"log10")==0){
  op1 = pop();
  if(op1 >0){
   return log10(op1);
  }
  else{
   printf("Input must be greater than zero");
   return 0.0;
  }
 }
 else if(strcmp(s,"sqrt")==0){
  op1 = pop();
  if(op1 >=0){
   return sqrt(op1);
  }
  else{
   printf("Input must be equal or greater than zero");
   return 0.0;
  }
 }
 else if(strcmp(s,"ceil")==0){
  return ceil(op1);
 }
 else if(strcmp(s,"floor")==0){
  return floor(op1);
 }
 else if(strcmp(s,"pow")==0){
  op1 = pop();
  op2 = pop();
  if((op1 != 0 || op2 >= 0)&&(op1>0||(op2 -(int)op2)==0.0)){
   return pow(op1,op2);
  }
  else{
   printf("Domain error");
  }
 }
 else{
  printf("error: unkown command %s\n",s);
 }
 return 0.0;
}

variable_types:
pop
double ()