decompiled_code:
__int64 set_do_prompt()
{
bool v0; // al
bool v1; // cf
bool v2; // zf
char *v3; // rsi
const char *v4; // rdi
__int64 v5; // rcx
char v6; // al
bool v7; // cf
bool v8; // zf
char *v9; // rsi
const char *v10; // rdi
__int64 v11; // rcx
char v12; // al
bool v13; // cf
bool v14; // zf
char *v15; // rsi
const char *v16; // rdi
__int64 v17; // rcx
char v18; // al
bool v19; // cf
bool v20; // zf
char *v21; // rsi
const char *v22; // rdi
__int64 v23; // rcx
char v24; // al
bool v25; // cf
bool v26; // zf
char *v27; // rsi
const char *v28; // rdi
__int64 v29; // rcx
char v30; // al
bool v31; // cf
bool v32; // zf
char *v33; // rsi
const char *v34; // rdi
__int64 v35; // rcx
unsigned __int8 v37; // al
unsigned __int8 v38; // al
unsigned __int8 v39; // al
unsigned __int8 v40; // al
unsigned __int8 v41; // al
char v42[40]; // [rsp+0h] [rbp-28h] BYREF

scan_key(v42, 17LL);
if ( !strcmp(v42, "auto_client") )
{
eewr_b(20LL, 0LL);
print_ok_nl();
}
else
{
v0 = strcmp(v42, "auto_server") != 0;
v1 = 0;
v2 = !v0;
if ( v0 )
{
v3 = v42;
v4 = "client_id";
v5 = 10LL;
do
{
if ( !v5 )
break;
v1 = (unsigned __int8)*v3 < (unsigned int)*v4;
v2 = *v3++ == *v4++;
--v5;
}
while ( v2 );
v6 = (!v1 && !v2) - v1;
v7 = 0;
v8 = v6 == 0;
if ( v6 )
{
v9 = v42;
v10 = "slot_size";
v11 = 10LL;
do
{
if ( !v11 )
break;
v7 = (unsigned __int8)*v9 < (unsigned int)*v10;
v8 = *v9++ == *v10++;
--v11;
}
while ( v8 );
v12 = (!v7 && !v8) - v7;
v13 = 0;
v14 = v12 == 0;
if ( v12 )
{
v15 = v42;
v16 = "slot_count";
v17 = 11LL;
do
{
if ( !v17 )
break;
v13 = (unsigned __int8)*v15 < (unsigned int)*v16;
v14 = *v15++ == *v16++;
--v17;
}
while ( v14 );
v18 = (!v13 && !v14) - v13;
v19 = 0;
v20 = v18 == 0;
if ( v18 )
{
v21 = v42;
v22 = "slot_rest_delay";
v23 = 16LL;
do
{
if ( !v23 )
break;
v19 = (unsigned __int8)*v21 < (unsigned int)*v22;
v20 = *v21++ == *v22++;
--v23;
}
while ( v20 );
v24 = (!v19 && !v20) - v19;
v25 = 0;
v26 = v24 == 0;
if ( v24 )
{
v27 = v42;
v28 = "slot_rf_timeout";
v29 = 16LL;
do
{
if ( !v29 )
break;
v25 = (unsigned __int8)*v27 < (unsigned int)*v28;
v26 = *v27++ == *v28++;
--v29;
}
while ( v26 );
v30 = (!v25 && !v26) - v25;
v31 = 0;
v32 = v30 == 0;
if ( v30 )
{
v33 = v42;
v34 = "info";
v35 = 5LL;
do
{
if ( !v35 )
break;
v31 = (unsigned __int8)*v33 < (unsigned int)*v34;
v32 = *v33++ == *v34++;
--v35;
}
while ( v32 );
if ( (!v31 && !v32) == v31 )
set_print_info(v34, v33);
}
else
{
v41 = scan_uint8(v28, v27);
eewr_b(25LL, v41);
print_ok_nl();
}
}
else
{
v40 = scan_uint8(v22, v21);
eewr_b(24LL, v40);
print_ok_nl();
}
}
else
{
v39 = scan_uint8(v16, v15);
eewr_b(23LL, v39);
print_ok_nl();
}
}
else
{
v38 = scan_uint8(v10, v9);
eewr_b(22LL, v38);
print_ok_nl();
}
}
else
{
v37 = scan_uint8(v4, v3);
eewr_b(21LL, v37);
print_ok_nl();
}
}
else
{
eewr_b(20LL, 1LL);
print_ok_nl();
}
}
return 1LL;
}

canonical_decompiled_code:
__int64 func1()
{
bool v0; // al
bool v1; // cf
bool v2; // zf
char *v3; // rsi
const char *v4; // rdi
__int64 v5; // rcx
char v6; // al
bool v7; // cf
bool v8; // zf
char *v9; // rsi
const char *v10; // rdi
__int64 v11; // rcx
char v12; // al
bool v13; // cf
bool v14; // zf
char *v15; // rsi
const char *v16; // rdi
__int64 v17; // rcx
char v18; // al
bool v19; // cf
bool v20; // zf
char *v21; // rsi
const char *v22; // rdi
__int64 v23; // rcx
char v24; // al
bool v25; // cf
bool v26; // zf
char *v27; // rsi
const char *v28; // rdi
__int64 v29; // rcx
char v30; // al
bool v31; // cf
bool v32; // zf
char *v33; // rsi
const char *v34; // rdi
__int64 v35; // rcx
unsigned __int8 v37; // al
unsigned __int8 v38; // al
unsigned __int8 v39; // al
unsigned __int8 v40; // al
unsigned __int8 v41; // al
char v42[40]; // [rsp+0h] [rbp-28h] BYREF

scan_key(v42, 17LL);
if ( !strcmp(v42, "auto_client") )
{
eewr_b(20LL, 0LL);
print_ok_nl();
}
else
{
v0 = strcmp(v42, "auto_server") != 0;
v1 = 0;
v2 = !v0;
if ( v0 )
{
v3 = v42;
v4 = "client_id";
v5 = 10LL;
do
{
if ( !v5 )
break;
v1 = (unsigned __int8)*v3 < (unsigned int)*v4;
v2 = *v3++ == *v4++;
--v5;
}
while ( v2 );
v6 = (!v1 && !v2) - v1;
v7 = 0;
v8 = v6 == 0;
if ( v6 )
{
v9 = v42;
v10 = "slot_size";
v11 = 10LL;
do
{
if ( !v11 )
break;
v7 = (unsigned __int8)*v9 < (unsigned int)*v10;
v8 = *v9++ == *v10++;
--v11;
}
while ( v8 );
v12 = (!v7 && !v8) - v7;
v13 = 0;
v14 = v12 == 0;
if ( v12 )
{
v15 = v42;
v16 = "slot_count";
v17 = 11LL;
do
{
if ( !v17 )
break;
v13 = (unsigned __int8)*v15 < (unsigned int)*v16;
v14 = *v15++ == *v16++;
--v17;
}
while ( v14 );
v18 = (!v13 && !v14) - v13;
v19 = 0;
v20 = v18 == 0;
if ( v18 )
{
v21 = v42;
v22 = "slot_rest_delay";
v23 = 16LL;
do
{
if ( !v23 )
break;
v19 = (unsigned __int8)*v21 < (unsigned int)*v22;
v20 = *v21++ == *v22++;
--v23;
}
while ( v20 );
v24 = (!v19 && !v20) - v19;
v25 = 0;
v26 = v24 == 0;
if ( v24 )
{
v27 = v42;
v28 = "slot_rf_timeout";
v29 = 16LL;
do
{
if ( !v29 )
break;
v25 = (unsigned __int8)*v27 < (unsigned int)*v28;
v26 = *v27++ == *v28++;
--v29;
}
while ( v26 );
v30 = (!v25 && !v26) - v25;
v31 = 0;
v32 = v30 == 0;
if ( v30 )
{
v33 = v42;
v34 = "info";
v35 = 5LL;
do
{
if ( !v35 )
break;
v31 = (unsigned __int8)*v33 < (unsigned int)*v34;
v32 = *v33++ == *v34++;
--v35;
}
while ( v32 );
if ( (!v31 && !v32) == v31 )
func0(v34, v33);
}
else
{
v41 = scan_uint8(v28, v27);
eewr_b(25LL, v41);
print_ok_nl();
}
}
else
{
v40 = scan_uint8(v22, v21);
eewr_b(24LL, v40);
print_ok_nl();
}
}
else
{
v39 = scan_uint8(v16, v15);
eewr_b(23LL, v39);
print_ok_nl();
}
}
else
{
v38 = scan_uint8(v10, v9);
eewr_b(22LL, v38);
print_ok_nl();
}
}
else
{
v37 = scan_uint8(v4, v3);
eewr_b(21LL, v37);
print_ok_nl();
}
}
else
{
eewr_b(20LL, 1LL);
print_ok_nl();
}
}
return 1LL;
}

original_code:
uint8_t set_do_prompt() {
        char cmd[17];
        scan_key(cmd,17);
        if (strcmp(cmd,"auto_client")==0) {
  eewr_b(20,0);
  print_ok_nl();
  return 1;
        }
  if (strcmp(cmd,"auto_server")==0) {
  eewr_b(20,1);
  print_ok_nl();
        return 1;
        }
 if (strcmp(cmd,"client_id")==0) {
  uint8_t cid = scan_uint8();
  eewr_b(21,cid);
  print_ok_nl();
  return 1;
 }
 if (strcmp(cmd,"slot_size")==0) {
  uint8_t slot_size = scan_uint8();
  eewr_b(22,slot_size);
  print_ok_nl();
  return 1;
 }
 if (strcmp(cmd,"slot_count")==0) {
  uint8_t slot_count = scan_uint8();
  eewr_b(23,slot_count);
  print_ok_nl();
  return 1;
 }
 if (strcmp(cmd,"slot_rest_delay")==0) {
  uint8_t slot_rest_delay = scan_uint8();
  eewr_b(24,slot_rest_delay);
  print_ok_nl();
  return 1;
 }
 if (strcmp(cmd,"slot_rf_timeout")==0) {
  uint8_t slot_rf_timeout = scan_uint8();
  eewr_b(25,slot_rf_timeout);
  print_ok_nl();
  return 1;
 }
 if (strcmp(cmd,"info")==0) {
  set_print_info();
  return 1;
 }
 return 1;
}

canonical_original_code:
unsigned char set_do_prompt() {
        char cmd[17];
        scan_key(cmd,17);
        if (strcmp(cmd,"auto_client")==0) {
  eewr_b(20,0);
  print_ok_nl();
  return 1;
        }
  if (strcmp(cmd,"auto_server")==0) {
  eewr_b(20,1);
  print_ok_nl();
        return 1;
        }
 if (strcmp(cmd,"client_id")==0) {
  unsigned char cid = scan_uint8();
  eewr_b(21,cid);
  print_ok_nl();
  return 1;
 }
 if (strcmp(cmd,"slot_size")==0) {
  unsigned char slot_size = scan_uint8();
  eewr_b(22,slot_size);
  print_ok_nl();
  return 1;
 }
 if (strcmp(cmd,"slot_count")==0) {
  unsigned char slot_count = scan_uint8();
  eewr_b(23,slot_count);
  print_ok_nl();
  return 1;
 }
 if (strcmp(cmd,"slot_rest_delay")==0) {
  unsigned char slot_rest_delay = scan_uint8();
  eewr_b(24,slot_rest_delay);
  print_ok_nl();
  return 1;
 }
 if (strcmp(cmd,"slot_rf_timeout")==0) {
  unsigned char slot_rf_timeout = scan_uint8();
  eewr_b(25,slot_rf_timeout);
  print_ok_nl();
  return 1;
 }
 if (strcmp(cmd,"info")==0) {
  set_print_info();
  return 1;
 }
 return 1;
}


repo: prcek/RFPad

decompiled_code:
__int64 do_autorun()
{
char v0; // al

v0 = eerd_b(20LL);
if ( !v0 )
return client_autorun();
if ( v0 == 1 )
return server_autorun();
return print("autorun mode error\n\r");
}

canonical_decompiled_code:
__int64 func2()
{
char v0; // al

v0 = eerd_b(20LL);
if ( !v0 )
return client_autorun();
if ( v0 == 1 )
return server_autorun();
return print("autorun mode error\n\r");
}

original_code:
void do_autorun() {
 uint8_t mode = eerd_b(20);
 if (mode == 0) {
  client_autorun();
 } else if (mode == 1) {
  server_autorun();
 } else {
  print("autorun mode error\n\r");
 }
}

canonical_original_code:
void do_autorun() {
 unsigned char mode = eerd_b(20);
 if (mode == 0) {
  client_autorun();
 } else if (mode == 1) {
  server_autorun();
 } else {
  print("autorun mode error\n\r");
 }
}

variable_types:
mode
unsigned char

return_type: void


decompiled_code:
char do_prompt()
{
bool v0; // cf
bool v1; // zf
const char *v2; // rdi
__int64 v3; // rcx
char *v4; // rsi
char v5; // al
bool v6; // cf
bool v7; // zf
char *v8; // rsi
const char *v9; // rdi
__int64 v10; // rcx
char v11; // al
bool v12; // cf
bool v13; // zf
char *v14; // rsi
const char *v15; // rdi
__int64 v16; // rcx
char v17; // al
bool v18; // cf
bool v19; // zf
char *v20; // rsi
const char *v21; // rdi
__int64 v22; // rcx
char v23; // al
bool v24; // cf
bool v25; // zf
char *v26; // rsi
const char *v27; // rdi
__int64 v28; // rcx
char v29; // al
bool v30; // cf
bool v31; // zf
char *v32; // rsi
const char *v33; // rdi
__int64 v34; // rcx
char v35; // al
bool v36; // cf
bool v37; // zf
char *v38; // rsi
const char *v39; // rdi
__int64 v40; // rcx
char v41; // al
bool v42; // cf
bool v43; // zf
char *v44; // rsi
const char *v45; // rdi
__int64 v46; // rcx
char result; // al
char v48[18]; // [rsp+6h] [rbp-12h] BYREF

print(">");
scan_key(v48, 10LL);
v2 = "rf";
v3 = 3LL;
v4 = v48;
do
{
if ( !v3 )
break;
v0 = (unsigned __int8)*v4 < (unsigned int)*v2;
v1 = *v4++ == *v2++;
--v3;
}
while ( v1 );
v5 = (!v0 && !v1) - v0;
v6 = 0;
v7 = v5 == 0;
if ( !v5 )
return rf_do_prompt(v2, v4);
v8 = v48;
v9 = "io";
v10 = 3LL;
do
{
if ( !v10 )
break;
v6 = (unsigned __int8)*v8 < (unsigned int)*v9;
v7 = *v8++ == *v9++;
--v10;
}
while ( v7 );
v11 = (!v6 && !v7) - v6;
v12 = 0;
v13 = v11 == 0;
if ( !v11 )
return io_do_prompt(v9, v8);
v14 = v48;
v15 = "test";
v16 = 5LL;
do
{
if ( !v16 )
break;
v12 = (unsigned __int8)*v14 < (unsigned int)*v15;
v13 = *v14++ == *v15++;
--v16;
}
while ( v13 );
v17 = (!v12 && !v13) - v12;
v18 = 0;
v19 = v17 == 0;
if ( v17 )
{
v20 = v48;
v21 = "timer";
v22 = 6LL;
do
{
if ( !v22 )
break;
v18 = (unsigned __int8)*v20 < (unsigned int)*v21;
v19 = *v20++ == *v21++;
--v22;
}
while ( v19 );
v23 = (!v18 && !v19) - v18;
v24 = 0;
v25 = v23 == 0;
if ( v23 )
{
v26 = v48;
v27 = "server";
v28 = 7LL;
do
{
if ( !v28 )
break;
v24 = (unsigned __int8)*v26 < (unsigned int)*v27;
v25 = *v26++ == *v27++;
--v28;
}
while ( v25 );
v29 = (!v24 && !v25) - v24;
v30 = 0;
v31 = v29 == 0;
if ( v29 )
{
v32 = v48;
v33 = "client";
v34 = 7LL;
do
{
if ( !v34 )
break;
v30 = (unsigned __int8)*v32 < (unsigned int)*v33;
v31 = *v32++ == *v33++;
--v34;
}
while ( v31 );
v35 = (!v30 && !v31) - v30;
v36 = 0;
v37 = v35 == 0;
if ( v35 )
{
v38 = v48;
v39 = "set";
v40 = 4LL;
do
{
if ( !v40 )
break;
v36 = (unsigned __int8)*v38 < (unsigned int)*v39;
v37 = *v38++ == *v39++;
--v40;
}
while ( v37 );
v41 = (!v36 && !v37) - v36;
v42 = 0;
v43 = v41 == 0;
if ( v41 )
{
v44 = v48;
v45 = "pad";
v46 = 4LL;
do
{
if ( !v46 )
break;
v42 = (unsigned __int8)*v44 < (unsigned int)*v45;
v43 = *v44++ == *v45++;
--v46;
}
while ( v43 );
if ( (!v42 && !v43) == v42 )
result = pad_do_prompt(v45, v44);
else
result = strcmp(v48, ".") != 0;
}
else
{
result = set_do_prompt(v39, v38);
}
}
else
{
result = client_do_prompt(v33, v32);
}
}
else
{
result = server_do_prompt(v27, v26);
}
}
else
{
result = timer_do_prompt(v21, v20);
}
}
else
{
print_test(v15, v14);
scan_test();
result = 1;
}
return result;
}

canonical_decompiled_code:
char func3()
{
bool v0; // cf
bool v1; // zf
const char *v2; // rdi
__int64 v3; // rcx
char *v4; // rsi
char v5; // al
bool v6; // cf
bool v7; // zf
char *v8; // rsi
const char *v9; // rdi
__int64 v10; // rcx
char v11; // al
bool v12; // cf
bool v13; // zf
char *v14; // rsi
const char *v15; // rdi
__int64 v16; // rcx
char v17; // al
bool v18; // cf
bool v19; // zf
char *v20; // rsi
const char *v21; // rdi
__int64 v22; // rcx
char v23; // al
bool v24; // cf
bool v25; // zf
char *v26; // rsi
const char *v27; // rdi
__int64 v28; // rcx
char v29; // al
bool v30; // cf
bool v31; // zf
char *v32; // rsi
const char *v33; // rdi
__int64 v34; // rcx
char v35; // al
bool v36; // cf
bool v37; // zf
char *v38; // rsi
const char *v39; // rdi
__int64 v40; // rcx
char v41; // al
bool v42; // cf
bool v43; // zf
char *v44; // rsi
const char *v45; // rdi
__int64 v46; // rcx
char result; // al
char v48[18]; // [rsp+6h] [rbp-12h] BYREF

print(">");
scan_key(v48, 10LL);
v2 = "rf";
v3 = 3LL;
v4 = v48;
do
{
if ( !v3 )
break;
v0 = (unsigned __int8)*v4 < (unsigned int)*v2;
v1 = *v4++ == *v2++;
--v3;
}
while ( v1 );
v5 = (!v0 && !v1) - v0;
v6 = 0;
v7 = v5 == 0;
if ( !v5 )
return rf_do_prompt(v2, v4);
v8 = v48;
v9 = "io";
v10 = 3LL;
do
{
if ( !v10 )
break;
v6 = (unsigned __int8)*v8 < (unsigned int)*v9;
v7 = *v8++ == *v9++;
--v10;
}
while ( v7 );
v11 = (!v6 && !v7) - v6;
v12 = 0;
v13 = v11 == 0;
if ( !v11 )
return io_do_prompt(v9, v8);
v14 = v48;
v15 = "test";
v16 = 5LL;
do
{
if ( !v16 )
break;
v12 = (unsigned __int8)*v14 < (unsigned int)*v15;
v13 = *v14++ == *v15++;
--v16;
}
while ( v13 );
v17 = (!v12 && !v13) - v12;
v18 = 0;
v19 = v17 == 0;
if ( v17 )
{
v20 = v48;
v21 = "timer";
v22 = 6LL;
do
{
if ( !v22 )
break;
v18 = (unsigned __int8)*v20 < (unsigned int)*v21;
v19 = *v20++ == *v21++;
--v22;
}
while ( v19 );
v23 = (!v18 && !v19) - v18;
v24 = 0;
v25 = v23 == 0;
if ( v23 )
{
v26 = v48;
v27 = "server";
v28 = 7LL;
do
{
if ( !v28 )
break;
v24 = (unsigned __int8)*v26 < (unsigned int)*v27;
v25 = *v26++ == *v27++;
--v28;
}
while ( v25 );
v29 = (!v24 && !v25) - v24;
v30 = 0;
v31 = v29 == 0;
if ( v29 )
{
v32 = v48;
v33 = "client";
v34 = 7LL;
do
{
if ( !v34 )
break;
v30 = (unsigned __int8)*v32 < (unsigned int)*v33;
v31 = *v32++ == *v33++;
--v34;
}
while ( v31 );
v35 = (!v30 && !v31) - v30;
v36 = 0;
v37 = v35 == 0;
if ( v35 )
{
v38 = v48;
v39 = "set";
v40 = 4LL;
do
{
if ( !v40 )
break;
v36 = (unsigned __int8)*v38 < (unsigned int)*v39;
v37 = *v38++ == *v39++;
--v40;
}
while ( v37 );
v41 = (!v36 && !v37) - v36;
v42 = 0;
v43 = v41 == 0;
if ( v41 )
{
v44 = v48;
v45 = "pad";
v46 = 4LL;
do
{
if ( !v46 )
break;
v42 = (unsigned __int8)*v44 < (unsigned int)*v45;
v43 = *v44++ == *v45++;
--v46;
}
while ( v43 );
if ( (!v42 && !v43) == v42 )
result = pad_do_prompt(v45, v44);
else
result = strcmp(v48, ".") != 0;
}
else
{
result = func1(v39, v38);
}
}
else
{
result = client_do_prompt(v33, v32);
}
}
else
{
result = server_do_prompt(v27, v26);
}
}
else
{
result = timer_do_prompt(v21, v20);
}
}
else
{
print_test(v15, v14);
scan_test();
result = 1;
}
return result;
}

original_code:
uint8_t do_prompt() {
 print(">");
 char group[10];
 scan_key(group,10);
 if (strcmp(group,"rf")==0) {
  return rf_do_prompt();
 } else if (strcmp(group,"io")==0) {
  return io_do_prompt();
 } else if (strcmp(group,"test")==0) {
  print_test();
  scan_test();
 } else if (strcmp(group,"timer")==0) {
  return timer_do_prompt();
 } else if (strcmp(group,"server")==0) {
  return server_do_prompt();
 } else if (strcmp(group,"client")==0) {
  return client_do_prompt();
 } else if (strcmp(group,"set")==0) {
  return set_do_prompt();
    } else if (strcmp(group,"pad")==0) {
        return pad_do_prompt();
 } else if (strcmp(group,".")==0) {
  return 0;
 }
 return 1;
}

canonical_original_code:
unsigned char do_prompt() {
 print(">");
 char group[10];
 scan_key(group,10);
 if (strcmp(group,"rf")==0) {
  return rf_do_prompt();
 } else if (strcmp(group,"io")==0) {
  return io_do_prompt();
 } else if (strcmp(group,"test")==0) {
  print_test();
  scan_test();
 } else if (strcmp(group,"timer")==0) {
  return timer_do_prompt();
 } else if (strcmp(group,"server")==0) {
  return server_do_prompt();
 } else if (strcmp(group,"client")==0) {
  return client_do_prompt();
 } else if (strcmp(group,"set")==0) {
  return set_do_prompt();
    } else if (strcmp(group,"pad")==0) {
        return pad_do_prompt();
 } else if (strcmp(group,".")==0) {
  return 0;
 }
 return 1;
}

variable_types:
group
char [10]

return_type: unsigned char


decompiled_code:
__int64 server_init()
{
unsigned __int8 v0; // al
__int64 result; // rax

server_seq = 0;
v0 = eerd_b(22LL);
cc_slot_set_len(v0);
cc_slot_set_top(18LL);
cc_slot_set(0LL);
result = eerd_b(25LL);
cfg_slot_rf_timeout = result;
return result;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned __int8 v0; // al
__int64 result; // rax

server_seq = 0;
v0 = eerd_b(22LL);
cc_slot_set_len(v0);
cc_slot_set_top(18LL);
cc_slot_set(0LL);
result = eerd_b(25LL);
cfg_slot_rf_timeout = result;
return result;
}

original_code:
void server_init() {
 server_seq = 0;
 cc_slot_set_len(eerd_b(22));
 cc_slot_set_top((2u+16u +1u)-1);
 cc_slot_set(0);
 cfg_slot_rf_timeout = eerd_b(25);
}


decompiled_code:
__int64 server_read_client()
{
char v0; // al
unsigned __int8 v2; // bl

v0 = rf_recv_packet((unsigned __int8)cfg_slot_rf_timeout);
if ( v0 == 1 )
{
rf_get_packet_v0();
v2 = rf_get_packet_v2();
rf_get_packet_v3();
print_hex(v2);
}
else if ( !v0 )
{
return print_char(46LL);
}
return print_char(58LL);
}

canonical_decompiled_code:
__int64 func1()
{
char v0; // al
unsigned __int8 v2; // bl

v0 = rf_recv_packet((unsigned __int8)cfg_slot_rf_timeout);
if ( v0 == 1 )
{
rf_get_packet_v0();
v2 = rf_get_packet_v2();
rf_get_packet_v3();
print_hex(v2);
}
else if ( !v0 )
{
return print_char(46LL);
}
return print_char(58LL);
}

original_code:
void server_read_client(uint8_t cid) {
 uint8_t rc = rf_recv_packet(cfg_slot_rf_timeout);
 if (rc==1) {
  uint8_t cid = rf_get_packet_v0();
  uint8_t data0 = rf_get_packet_v2();
  uint8_t data1 = rf_get_packet_v3();
  print_hex(data0);
 } if (rc==0) {
  print_char('.');
 } else {
  print_char(':');
 }
}

canonical_original_code:
void server_read_client(unsigned char cid) {
 unsigned char rc = rf_recv_packet(cfg_slot_rf_timeout);
 if (rc==1) {
  unsigned char cid = rf_get_packet_v0();
  unsigned char data0 = rf_get_packet_v2();
  unsigned char data1 = rf_get_packet_v3();
  print_hex(data0);
 } if (rc==0) {
  print_char('.');
 } else {
  print_char(':');
 }
}

variable_types:
cid
unsigned char

variable_types:
rc
unsigned char


decompiled_code:
__int64 server_loop()
{
unsigned int i; // ebx

rf_prepare_for_send();
cc_slot_wait(0LL);
rf_send_packet(0LL, (unsigned __int8)server_seq, 0LL, 0LL);
++server_seq;
cc_slot_wait(1LL);
rf_prepare_for_recv();
print_char(91LL);
for ( i = 2; i != 18; ++i )
{
cc_slot_wait(i);
server_read_client(i - 2);
if ( (unsigned __int8)cc_slot_get() != i )
print_char(94LL);
}
cc_slot_wait(18LL);
return print_char(93LL);
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int i; // ebx

rf_prepare_for_send();
cc_slot_wait(0LL);
rf_send_packet(0LL, (unsigned __int8)server_seq, 0LL, 0LL);
++server_seq;
cc_slot_wait(1LL);
rf_prepare_for_recv();
print_char(91LL);
for ( i = 2; i != 18; ++i )
{
cc_slot_wait(i);
func1(i - 2);
if ( (unsigned __int8)cc_slot_get() != i )
print_char(94LL);
}
cc_slot_wait(18LL);
return print_char(93LL);
}

original_code:
void server_loop() {
 rf_prepare_for_send();
 cc_slot_wait(0u);
 rf_send_packet(0x0,server_seq, 0, 0);
 server_seq++;
 cc_slot_wait(0u +1);
 rf_prepare_for_recv();
 uint8_t c;
 print_char('[');
 for(c=0; c<16u; c++) {
  cc_slot_wait(2u +c);
  server_read_client(c);
  if (cc_slot_get()!=(2u +c)) {
   print_char('^');
  }
 }
 cc_slot_wait(2u +16u);
 print_char(']');
}

canonical_original_code:
void server_loop() {
 rf_prepare_for_send();
 cc_slot_wait(0u);
 rf_send_packet(0x0,server_seq, 0, 0);
 server_seq++;
 cc_slot_wait(0u +1);
 rf_prepare_for_recv();
 unsigned char c;
 print_char('[');
 for(c=0; c<16u; c++) {
  cc_slot_wait(2u +c);
  server_read_client(c);
  if (cc_slot_get()!=(2u +c)) {
   print_char('^');
  }
 }
 cc_slot_wait(2u +16u);
 print_char(']');
}

variable_types:
c
unsigned char


decompiled_code:
void __noreturn server_autorun()
{
print("server autorun\n\r");
server_init();
while ( 1 )
server_loop();
}

canonical_decompiled_code:
void __noreturn func3()
{
print("server autorun\n\r");
func0();
while ( 1 )
func2();
}

original_code:
void server_autorun() {
 print("server autorun\n\r");
 server_init();
 while(!0) {
         server_loop();
        }
}


decompiled_code:
__int64 server_do_prompt()
{
bool v0; // cf
bool v1; // zf
const char *v2; // rdi
__int64 v3; // rcx
const char *v4; // rsi
char v5; // al
bool v6; // cf
bool v7; // zf
const char *v8; // rsi
const char *v9; // rdi
__int64 v10; // rcx
int v12; // eax
int v13; // ebx
_BYTE v14[40]; // [rsp+0h] [rbp-28h] BYREF

scan_key(v14, 17LL);
v2 = "init";
v3 = 5LL;
v4 = v14;
do
{
if ( !v3 )
break;
v0 = *v4 < (unsigned int)*v2;
v1 = *v4++ == *v2++;
--v3;
}
while ( v1 );
v5 = (!v0 && !v1) - v0;
v6 = 0;
v7 = v5 == 0;
if ( v5 )
{
v8 = v14;
v9 = "loop";
v10 = 5LL;
do
{
if ( !v10 )
break;
v6 = *v8 < (unsigned int)*v9;
v7 = *v8++ == *v9++;
--v10;
}
while ( v7 );
if ( (!v6 && !v7) == v6 )
{
v12 = scan_uint16(v9, v8);
v13 = v12 - 1;
if ( !(_WORD)v12 )
{
timer_get_sec();
print("server loop....");
while ( 1 )
server_loop();
}
do
{
print_char(46LL);
server_loop();
--v13;
}
while ( (_WORD)v13 != 0xFFFF );
}
}
else
{
server_init(v2, v4);
}
return 1LL;
}

canonical_decompiled_code:
__int64 func4()
{
bool v0; // cf
bool v1; // zf
const char *v2; // rdi
__int64 v3; // rcx
const char *v4; // rsi
char v5; // al
bool v6; // cf
bool v7; // zf
const char *v8; // rsi
const char *v9; // rdi
__int64 v10; // rcx
int v12; // eax
int v13; // ebx
_BYTE v14[40]; // [rsp+0h] [rbp-28h] BYREF

scan_key(v14, 17LL);
v2 = "init";
v3 = 5LL;
v4 = v14;
do
{
if ( !v3 )
break;
v0 = *v4 < (unsigned int)*v2;
v1 = *v4++ == *v2++;
--v3;
}
while ( v1 );
v5 = (!v0 && !v1) - v0;
v6 = 0;
v7 = v5 == 0;
if ( v5 )
{
v8 = v14;
v9 = "loop";
v10 = 5LL;
do
{
if ( !v10 )
break;
v6 = *v8 < (unsigned int)*v9;
v7 = *v8++ == *v9++;
--v10;
}
while ( v7 );
if ( (!v6 && !v7) == v6 )
{
v12 = scan_uint16(v9, v8);
v13 = v12 - 1;
if ( !(_WORD)v12 )
{
timer_get_sec();
print("server loop....");
while ( 1 )
func2();
}
do
{
print_char(46LL);
func2();
--v13;
}
while ( (_WORD)v13 != 0xFFFF );
}
}
else
{
func0(v2, v4);
}
return 1LL;
}

original_code:
uint8_t server_do_prompt() {
        char cmd[17];
        scan_key(cmd,17);
        if (strcmp(cmd,"init")==0) {
                        server_init();
                        return 1;
        }
        if (strcmp(cmd,"loop")==0) {
   uint16_t count = scan_uint16();
   if (count == 0) {
    uint16_t last_s = timer_get_sec();
    uint8_t last_seq = server_seq;
    print("server loop....");
    while(!0) {
     server_loop();
    }
    print("   end\n\r");
   } else {
    while(count--) {
     print_char('.');
                          server_loop();
    }
   }
                        return 1;
        }
        return 1;
}

canonical_original_code:
unsigned char server_do_prompt() {
        char cmd[17];
        scan_key(cmd,17);
        if (strcmp(cmd,"init")==0) {
                        server_init();
                        return 1;
        }
        if (strcmp(cmd,"loop")==0) {
   unsigned short count = scan_uint16();
   if (count == 0) {
    unsigned short last_s = timer_get_sec();
    unsigned char last_seq = server_seq;
    print("server loop....");
    while(!0) {
     server_loop();
    }
    print("   end\n\r");
   } else {
    while(count--) {
     print_char('.');
                          server_loop();
    }
   }
                        return 1;
        }
        return 1;
}

variable_types:
cmd
char [17]

variable_types:
count
unsigned short


decompiled_code:
__int64 __fastcall eeprom_read_byte(int a1)
{
return (unsigned __int8)ee_data[a1];
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
return (unsigned __int8)ee_data[a1];
}

original_code:
uint8_t eeprom_read_byte(const uint8_t *p) {
 const uint8_t *base=0;
 int r = (int)(p-base);
 return ee_data[r];
}

canonical_original_code:
unsigned char eeprom_read_byte(unsigned char *p) {
 unsigned char *base = 0;
 int r = (int)(p-base);
 return ee_data[r];
}

variable_types:
p
unsigned char *

variable_types:
base
unsigned char *

variable_types: r int


decompiled_code:
void __fastcall eeprom_write_byte(int a1, char a2)
{
ee_data[a1] = a2;
}

canonical_decompiled_code:
void __fastcall func1(int a1, char a2)
{
ee_data[a1] = a2;
}

original_code:
void eeprom_write_byte(uint8_t *p, uint8_t v) {
 uint8_t *base=0;
 int r = (int)(p-base);
 ee_data[r]=v;
}

canonical_original_code:
void eeprom_write_byte(unsigned char *p, unsigned char v) {
 unsigned char *base = 0;
 int r = (int)(p-base);
 ee_data[r]=v;
}

variable_types:
v
unsigned char


main

canonical_name: main

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

rf_config_init(argc, argv, envp);
print("TEST MODE\r\n");
do
result = do_prompt();
while ( result );
return result;
}

original_code:
int main(int nargs, char **args) {
 rf_config_init();
 print("TEST MODE\r\n");
 while(do_prompt()) {
 }
 return 0;
}

variable_types: nargs int

variable_types:
args
char **

return_type: int


validateArgCount

repo: pretorh/git-branching-helper

decompiled_code:
void __fastcall validateArgCount(int a1, int a2, const char *a3)
{
if ( a1 <= a2 )
{
printf("missing arguments: %s\n", a3);
exit(1);
}
}

canonical_decompiled_code:
void __fastcall func0(int a1, int a2, const char *a3)
{
if ( a1 <= a2 )
{
printf("missing arguments: %s\n", a3);
exit(1);
}
}

original_code:
void validateArgCount(int actual, int wanted, const char *detail) {
    if (actual <= wanted) {
        printf("missing arguments: %s\n", detail);
        exit(1);
    }
}

canonical_original_code:
void validateArgCount(int actual, int wanted, char *detail) {
    if (actual <= wanted) {
        printf("missing arguments: %s\n", detail);
        exit(1);
    }
}

variable_types: actual int

variable_types: wanted int

variable_types:
detail
char *


notYetImplemented

decompiled_code:
void __noreturn notYetImplemented()
{
puts("\nNot yet implemented");
exit(2);
}

canonical_decompiled_code:
void __noreturn func1()
{
puts("\nNot yet implemented");
exit(2);
}

original_code:
void notYetImplemented() {
    printf("\nNot yet implemented\n");
    exit(2);
}


main

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

validateArgCount(argc, 1, "need at least the command name");
if ( !strcmp("cf", argv[1]) )
{
validateArgCount(argc, 2, "cf 'feature branch name'");
createFeatureBranch(argv[2]);
notYetImplemented();
}
if ( !strcmp("mf", argv[1]) )
{
validateArgCount(argc, 2, "mf 'feature branch name'");
mergeFeatureBranch(argv[2]);
notYetImplemented();
}
if ( !strcmp("cr", argv[1]) )
{
validateArgCount(argc, 3, "cr 'release version name' 'version bump script'");
createReleaseBranch(argv[2], argv[3]);
notYetImplemented();
}
if ( !strcmp("mr", argv[1]) )
{
validateArgCount(argc, 2, "mr 'release version name'");
mergeReleaseBranch(argv[2]);
notYetImplemented();
}
if ( !strcmp("ch", argv[1]) )
{
validateArgCount(argc, 3, "mr 'hotfix version name' 'version bump script'");
createHotfixBranch(argv[2], argv[3]);
notYetImplemented();
}
if ( !strcmp("mh", argv[1]) )
{
validateArgCount(argc, 2, "mh 'hotfix version name' ['release version name']");
v5 = 0LL;
if ( argc == 4 )
v5 = argv[3];
mergeHotfixBranch(argv[2], v5);
notYetImplemented();
}
printf("unknown command '%s'\n", argv[1]);
return 1;
}

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

func0(argc, 1, "need at least the command name");
if ( !strcmp("cf", argv[1]) )
{
func0(argc, 2, "cf 'feature branch name'");
createFeatureBranch(argv[2]);
func1();
}
if ( !strcmp("mf", argv[1]) )
{
func0(argc, 2, "mf 'feature branch name'");
mergeFeatureBranch(argv[2]);
func1();
}
if ( !strcmp("cr", argv[1]) )
{
func0(argc, 3, "cr 'release version name' 'version bump script'");
createReleaseBranch(argv[2], argv[3]);
func1();
}
if ( !strcmp("mr", argv[1]) )
{
func0(argc, 2, "mr 'release version name'");
mergeReleaseBranch(argv[2]);
func1();
}
if ( !strcmp("ch", argv[1]) )
{
func0(argc, 3, "mr 'hotfix version name' 'version bump script'");
createHotfixBranch(argv[2], argv[3]);
func1();
}
if ( !strcmp("mh", argv[1]) )
{
func0(argc, 2, "mh 'hotfix version name' ['release version name']");
v5 = 0LL;
if ( argc == 4 )
v5 = argv[3];
mergeHotfixBranch(argv[2], v5);
func1();
}
printf("unknown command '%s'\n", argv[1]);
return 1;
}

original_code:
int main(int argc, const char **argv) {
    validateArgCount(argc, 1, "need at least the command name");
    if (0 == strcmp("cf", argv[1])) {
        validateArgCount(argc, 2, "cf 'feature branch name'");
        createFeatureBranch(argv[2]);
        notYetImplemented();
    } else if (0 == strcmp("mf", argv[1])) {
        validateArgCount(argc, 2, "mf 'feature branch name'");
        mergeFeatureBranch(argv[2]);
        notYetImplemented();
    } else if (0 == strcmp("cr", argv[1])) {
        validateArgCount(argc, 3, "cr 'release version name' 'version bump script'");
        createReleaseBranch(argv[2], argv[3]);
        notYetImplemented();
    } else if (0 == strcmp("mr", argv[1])) {
        validateArgCount(argc, 2, "mr 'release version name'");
        mergeReleaseBranch(argv[2]);
        notYetImplemented();
    } else if (0 == strcmp("ch", argv[1])) {
        validateArgCount(argc, 3, "mr 'hotfix version name' 'version bump script'");
        createHotfixBranch(argv[2], argv[3]);
        notYetImplemented();
    } else if (0 == strcmp("mh", argv[1])) {
        validateArgCount(argc, 2, "mh 'hotfix version name' ['release version name']");
        mergeHotfixBranch(argv[2], argc == 4 ? argv[3] : ((void *)0));
        notYetImplemented();
    } else {
        printf("unknown command '%s'\n", argv[1]);
        return 1;
    }
    printf("bye\n");
    return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
    validateArgCount(argc, 1, "need at least the command name");
    if (0 == strcmp("cf", argv[1])) {
        validateArgCount(argc, 2, "cf 'feature branch name'");
        createFeatureBranch(argv[2]);
        notYetImplemented();
    } else if (0 == strcmp("mf", argv[1])) {
        validateArgCount(argc, 2, "mf 'feature branch name'");
        mergeFeatureBranch(argv[2]);
        notYetImplemented();
    } else if (0 == strcmp("cr", argv[1])) {
        validateArgCount(argc, 3, "cr 'release version name' 'version bump script'");
        createReleaseBranch(argv[2], argv[3]);
        notYetImplemented();
    } else if (0 == strcmp("mr", argv[1])) {
        validateArgCount(argc, 2, "mr 'release version name'");
        mergeReleaseBranch(argv[2]);
        notYetImplemented();
    } else if (0 == strcmp("ch", argv[1])) {
        validateArgCount(argc, 3, "mr 'hotfix version name' 'version bump script'");
        createHotfixBranch(argv[2], argv[3]);
        notYetImplemented();
    } else if (0 == strcmp("mh", argv[1])) {
        validateArgCount(argc, 2, "mh 'hotfix version name' ['release version name']");
        mergeHotfixBranch(argv[2], argc == 4 ? argv[3] : ((void *)0));
        notYetImplemented();
    } else {
        printf("unknown command '%s'\n", argv[1]);
        return 1;
    }
    printf("bye\n");
    return 0;
}

variable_types: argc int

variable_types:
argv
char **


createHotfixBranch

decompiled_code:
__int64 __fastcall createHotfixBranch(const char *a1, const char *a2)
{
_BYTE v3[112]; // [rsp+0h] [rbp-478h] BYREF
char v4[1032]; // [rsp+70h] [rbp-408h] BYREF

buildBranchName(v4, "hotfix", a1);
buildVersionBumpMessage(v3, a1);
printf("Create branch %s for hotfix version %s\n", v4, a1);
createBranchAndSwitch(v4, "master");
printf("./%s \"%s\"\n", a2, a1);
commit(v3);
return pushToOrigin(v4);
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, const char *a2)
{
_BYTE v3[112]; // [rsp+0h] [rbp-478h] BYREF
char v4[1032]; // [rsp+70h] [rbp-408h] BYREF

buildBranchName(v4, "hotfix", a1);
buildVersionBumpMessage(v3, a1);
printf("Create branch %s for hotfix version %s\n", v4, a1);
createBranchAndSwitch(v4, "master");
printf("./%s \"%s\"\n", a2, a1);
commit(v3);
return pushToOrigin(v4);
}

original_code:
void createHotfixBranch(const char *version, const char *bumpScript) {
    char hotfixName[1000];
    buildBranchName(hotfixName, "hotfix", version);
    char message[100];
    buildVersionBumpMessage(message, version);
    printf("Create branch %s for hotfix version %s\n", hotfixName, version);
    createBranchAndSwitch(hotfixName, "master");
    printf("./%s \"%s\"\n", bumpScript, version);
    commit(message);
    pushToOrigin(hotfixName);
}

canonical_original_code:
void createHotfixBranch(char *version, char *bumpScript) {
    char hotfixName[1000];
    buildBranchName(hotfixName, "hotfix", version);
    char message[100];
    buildVersionBumpMessage(message, version);
    printf("Create branch %s for hotfix version %s\n", hotfixName, version);
    createBranchAndSwitch(hotfixName, "master");
    printf("./%s \"%s\"\n", bumpScript, version);
    commit(message);
    pushToOrigin(hotfixName);
}

variable_types:
version
char *

variable_types:
bumpScript
char *

variable_types:
hotfixName
char [1000]

variable_types:
message
char [100]


mergeHotfixBranch

decompiled_code:
__int64 __fastcall mergeHotfixBranch(const char *a1, __int64 a2)
{
_BYTE v3[1008]; // [rsp+0h] [rbp-7F8h] BYREF
char v4[1032]; // [rsp+3F0h] [rbp-408h] BYREF

buildBranchName(v4, "hotfix", a1);
printf("Merge branch %s for hotfix version %s\n", v4, a1);
mergeIntoAndPush(v4, "master", "hotfix");
mergeIntoAndPush(v4, DEV_BRANCH, "hotfix");
if ( a2 )
{
buildBranchName(v3, "release", a2);
mergeIntoAndPush(v4, v3, "hotfix");
}
tag(a1);
return deleteBranch(v4);
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, __int64 a2)
{
_BYTE v3[1008]; // [rsp+0h] [rbp-7F8h] BYREF
char v4[1032]; // [rsp+3F0h] [rbp-408h] BYREF

buildBranchName(v4, "hotfix", a1);
printf("Merge branch %s for hotfix version %s\n", v4, a1);
mergeIntoAndPush(v4, "master", "hotfix");
mergeIntoAndPush(v4, DEV_BRANCH, "hotfix");
if ( a2 )
{
buildBranchName(v3, "release", a2);
mergeIntoAndPush(v4, v3, "hotfix");
}
tag(a1);
return deleteBranch(v4);
}

original_code:
void mergeHotfixBranch(const char *version, const char *releaseVersion) {
    char hotfixName[1000];
    buildBranchName(hotfixName, "hotfix", version);
    printf("Merge branch %s for hotfix version %s\n", hotfixName, version);
    mergeIntoAndPush(hotfixName, "master", "hotfix");
    mergeIntoAndPush(hotfixName, DEV_BRANCH, "hotfix");
    if (releaseVersion) {
        char releaseName[1000];
        buildBranchName(releaseName, "release", releaseVersion);
        mergeIntoAndPush(hotfixName, releaseName, "hotfix");
    }
    tag(version);
    deleteBranch(hotfixName);
}

canonical_original_code:
void mergeHotfixBranch(char *version, char *releaseVersion) {
    char hotfixName[1000];
    buildBranchName(hotfixName, "hotfix", version);
    printf("Merge branch %s for hotfix version %s\n", hotfixName, version);
    mergeIntoAndPush(hotfixName, "master", "hotfix");
    mergeIntoAndPush(hotfixName, DEV_BRANCH, "hotfix");
    if (releaseVersion) {
        char releaseName[1000];
        buildBranchName(releaseName, "release", releaseVersion);
        mergeIntoAndPush(hotfixName, releaseName, "hotfix");
    }
    tag(version);
    deleteBranch(hotfixName);
}

variable_types:
releaseVersion
char *

variable_types:
releaseName
char [1000]


createBranchAndSwitch

decompiled_code:
int __fastcall createBranchAndSwitch(const char *a1, const char *a2)
{
return printf("git checkout -b %s %s\n", a1, a2);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1, const char *a2)
{
return printf("git checkout -b %s %s\n", a1, a2);
}

original_code:
void createBranchAndSwitch(const char *branchName, const char* offFromBranch) {
    printf("git checkout -b %s %s\n", branchName, offFromBranch);
}

canonical_original_code:
void createBranchAndSwitch(char *branchName, char *offFromBranch) {
    printf("git checkout -b %s %s\n", branchName, offFromBranch);
}

variable_types:
branchName
char *

variable_types:
offFromBranch
char *


pushToOrigin

decompiled_code:
int __fastcall pushToOrigin(const char *a1)
{
return printf("git push origin %s\n", a1);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1)
{
return printf("git push origin %s\n", a1);
}

original_code:
void pushToOrigin(const char *branchName) {
    printf("git push origin %s\n", branchName);
}

canonical_original_code:
void pushToOrigin(char *branchName) {
    printf("git push origin %s\n", branchName);
}


checkoutBranch

decompiled_code:
int __fastcall checkoutBranch(const char *a1)
{
return printf("git checkout %s\n", a1);
}

canonical_decompiled_code:
int __fastcall func2(const char *a1)
{
return printf("git checkout %s\n", a1);
}

original_code:
void checkoutBranch(const char *branchName) {
    printf("git checkout %s\n", branchName);
}

canonical_original_code:
void checkoutBranch(char *branchName) {
    printf("git checkout %s\n", branchName);
}


deleteBranch

decompiled_code:
int __fastcall deleteBranch(const char *a1)
{
printf("git branch -d %s\n", a1);
return printf("git push origin --delete %s\n", a1);
}

canonical_decompiled_code:
int __fastcall func3(const char *a1)
{
printf("git branch -d %s\n", a1);
return printf("git push origin --delete %s\n", a1);
}

original_code:
void deleteBranch(const char *branchName) {
    printf("git branch -d %s\n", branchName);
    printf("git push origin --delete %s\n", branchName);
}

canonical_original_code:
void deleteBranch(char *branchName) {
    printf("git branch -d %s\n", branchName);
    printf("git push origin --delete %s\n", branchName);
}


mergeBranch

decompiled_code:
int __fastcall mergeBranch(const char *a1, const char *a2, const char *a3)
{
return printf("git merge --no-ff %s -m \"Merge %s branch '%s' into '%s'\"\n", a1, a2, a1, a3);
}

canonical_decompiled_code:
int __fastcall func4(const char *a1, const char *a2, const char *a3)
{
return printf("git merge --no-ff %s -m \"Merge %s branch '%s' into '%s'\"\n", a1, a2, a1, a3);
}

original_code:
void mergeBranch(const char *branchName, const char *type, const char *into) {
    printf("git merge --no-ff %s -m \"Merge %s branch '%s' into '%s'\"\n", branchName, type, branchName, into);
}

canonical_original_code:
void mergeBranch(char *branchName, char *type, char *into) {
    printf("git merge --no-ff %s -m \"Merge %s branch '%s' into '%s'\"\n", branchName, type, branchName, into);
}

variable_types:
type
char *

variable_types:
into
char *


commit

decompiled_code:
int __fastcall commit(const char *a1)
{
return printf("git commit -a -m \"%s\"\n", a1);
}

canonical_decompiled_code:
int __fastcall func5(const char *a1)
{
return printf("git commit -a -m \"%s\"\n", a1);
}

original_code:
void commit(const char *message) {
    printf("git commit -a -m \"%s\"\n", message);
}

canonical_original_code:
void commit(char *message) {
    printf("git commit -a -m \"%s\"\n", message);
}

variable_types:
message
char *


tag

decompiled_code:
int __fastcall tag(const char *a1)
{
printf("git tag -a %s -m \"%s\"\n", a1, a1);
return printf("git push origin %s\n", a1);
}

canonical_decompiled_code:
int __fastcall func6(const char *a1)
{
printf("git tag -a %s -m \"%s\"\n", a1, a1);
return printf("git push origin %s\n", a1);
}

original_code:
void tag(const char *tagName) {
    printf("git tag -a %s -m \"%s\"\n", tagName, tagName);
    printf("git push origin %s\n", tagName);
}

canonical_original_code:
void tag(char *tagName) {
    printf("git tag -a %s -m \"%s\"\n", tagName, tagName);
    printf("git push origin %s\n", tagName);
}

variable_types:
tagName
char *


createFeatureBranch

decompiled_code:
__int64 __fastcall createFeatureBranch(const char *a1)
{
char v2[1016]; // [rsp+0h] [rbp-3F8h] BYREF

buildBranchName(v2, "feat", a1);
printf("Create branch %s for feature %s\n", v2, a1);
createBranchAndSwitch(v2, DEV_BRANCH);
return pushToOrigin(v2);
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
char v2[1016]; // [rsp+0h] [rbp-3F8h] BYREF

buildBranchName(v2, "feat", a1);
printf("Create branch %s for feature %s\n", v2, a1);
createBranchAndSwitch(v2, DEV_BRANCH);
return pushToOrigin(v2);
}

original_code:
void createFeatureBranch(const char *name) {
    char featName[1000];
    buildBranchName(featName, "feat", name);
    printf("Create branch %s for feature %s\n", featName, name);
    createBranchAndSwitch(featName, DEV_BRANCH);
    pushToOrigin(featName);
}

canonical_original_code:
void createFeatureBranch(char *name) {
    char featName[1000];
    buildBranchName(featName, "feat", name);
    printf("Create branch %s for feature %s\n", featName, name);
    createBranchAndSwitch(featName, DEV_BRANCH);
    pushToOrigin(featName);
}

variable_types:
name
char *

variable_types:
featName
char [1000]


mergeFeatureBranch

decompiled_code:
__int64 __fastcall mergeFeatureBranch(const char *a1)
{
char v2[1016]; // [rsp+0h] [rbp-3F8h] BYREF

buildBranchName(v2, "feat", a1);
printf("Merge branch %s for feature %s\n", v2, a1);
mergeIntoAndPush(v2, DEV_BRANCH, "feature");
return deleteBranch(v2);
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
char v2[1016]; // [rsp+0h] [rbp-3F8h] BYREF

buildBranchName(v2, "feat", a1);
printf("Merge branch %s for feature %s\n", v2, a1);
mergeIntoAndPush(v2, DEV_BRANCH, "feature");
return deleteBranch(v2);
}

original_code:
void mergeFeatureBranch(const char *name) {
    char featName[1000];
    buildBranchName(featName, "feat", name);
    printf("Merge branch %s for feature %s\n", featName, name);
    mergeIntoAndPush(featName, DEV_BRANCH, "feature");
    deleteBranch(featName);
}

canonical_original_code:
void mergeFeatureBranch(char *name) {
    char featName[1000];
    buildBranchName(featName, "feat", name);
    printf("Merge branch %s for feature %s\n", featName, name);
    mergeIntoAndPush(featName, DEV_BRANCH, "feature");
    deleteBranch(featName);
}


mergeIntoAndPush

decompiled_code:
__int64 __fastcall mergeIntoAndPush(__int64 a1, __int64 a2, __int64 a3)
{
checkoutBranch(a2);
mergeBranch(a1, a3, a2);
return pushToOrigin(a2);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
checkoutBranch(a2);
mergeBranch(a1, a3, a2);
return pushToOrigin(a2);
}

original_code:
void mergeIntoAndPush(const char *from, const char *into, const char *type) {
    checkoutBranch(into);
    mergeBranch(from, type, into);
    pushToOrigin(into);
}

canonical_original_code:
void mergeIntoAndPush(char *from, char *into, char *type) {
    checkoutBranch(into);
    mergeBranch(from, type, into);
    pushToOrigin(into);
}

variable_types:
from
char *


buildBranchName

decompiled_code:
int __fastcall buildBranchName(char *a1, const char *a2, const char *a3)
{
return sprintf(a1, "%s-%s", a2, a3);
}

canonical_decompiled_code:
int __fastcall func1(char *a1, const char *a2, const char *a3)
{
return sprintf(a1, "%s-%s", a2, a3);
}

original_code:
void buildBranchName(char *into, const char *type, const char *name) {
    sprintf(into, "%s-%s", type, name);
}

canonical_original_code:
void buildBranchName(char *into, char *type, char *name) {
    sprintf(into, "%s-%s", type, name);
}


buildVersionBumpMessage

decompiled_code:
int __fastcall buildVersionBumpMessage(char *a1, const char *a2)
{
return sprintf(a1, "version bump %s", a2);
}

canonical_decompiled_code:
int __fastcall func2(char *a1, const char *a2)
{
return sprintf(a1, "version bump %s", a2);
}

original_code:
void buildVersionBumpMessage(char *into, const char *version) {
    sprintf(into, "version bump %s", version);
}

canonical_original_code:
void buildVersionBumpMessage(char *into, char *version) {
    sprintf(into, "version bump %s", version);
}


createReleaseBranch

decompiled_code:
__int64 __fastcall createReleaseBranch(const char *a1, const char *a2)
{
_BYTE v3[112]; // [rsp+0h] [rbp-478h] BYREF
char v4[1032]; // [rsp+70h] [rbp-408h] BYREF

buildBranchName(v4, "release", a1);
buildVersionBumpMessage(v3, a1);
printf("Create branch %s for release version %s\n", v4, a1);
createBranchAndSwitch(v4, DEV_BRANCH);
printf("./%s \"%s\"\n", a2, a1);
commit(v3);
return pushToOrigin(v4);
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, const char *a2)
{
_BYTE v3[112]; // [rsp+0h] [rbp-478h] BYREF
char v4[1032]; // [rsp+70h] [rbp-408h] BYREF

buildBranchName(v4, "release", a1);
buildVersionBumpMessage(v3, a1);
printf("Create branch %s for release version %s\n", v4, a1);
createBranchAndSwitch(v4, DEV_BRANCH);
printf("./%s \"%s\"\n", a2, a1);
commit(v3);
return pushToOrigin(v4);
}

original_code:
void createReleaseBranch(const char *version, const char *bumpScript) {
    char releaseName[1000];
    buildBranchName(releaseName, "release", version);
    char message[100];
    buildVersionBumpMessage(message, version);
    printf("Create branch %s for release version %s\n", releaseName, version);
    createBranchAndSwitch(releaseName, DEV_BRANCH);
    printf("./%s \"%s\"\n", bumpScript, version);
    commit(message);
    pushToOrigin(releaseName);
}

canonical_original_code:
void createReleaseBranch(char *version, char *bumpScript) {
    char releaseName[1000];
    buildBranchName(releaseName, "release", version);
    char message[100];
    buildVersionBumpMessage(message, version);
    printf("Create branch %s for release version %s\n", releaseName, version);
    createBranchAndSwitch(releaseName, DEV_BRANCH);
    printf("./%s \"%s\"\n", bumpScript, version);
    commit(message);
    pushToOrigin(releaseName);
}


mergeReleaseBranch

decompiled_code:
__int64 __fastcall mergeReleaseBranch(const char *a1)
{
char v2[1016]; // [rsp+0h] [rbp-3F8h] BYREF

buildBranchName(v2, "release", a1);
printf("Merge branch %s for release version %s\n", v2, a1);
mergeIntoAndPush(v2, "master", "release");
mergeIntoAndPush(v2, DEV_BRANCH, "release");
tag(a1);
return deleteBranch(v2);
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
char v2[1016]; // [rsp+0h] [rbp-3F8h] BYREF

buildBranchName(v2, "release", a1);
printf("Merge branch %s for release version %s\n", v2, a1);
mergeIntoAndPush(v2, "master", "release");
mergeIntoAndPush(v2, DEV_BRANCH, "release");
tag(a1);
return deleteBranch(v2);
}

original_code:
void mergeReleaseBranch(const char *version) {
    char releaseName[1000];
    buildBranchName(releaseName, "release", version);
    printf("Merge branch %s for release version %s\n", releaseName, version);
    mergeIntoAndPush(releaseName, "master", "release");
    mergeIntoAndPush(releaseName, DEV_BRANCH, "release");
    tag(version);
    deleteBranch(releaseName);
}

canonical_original_code:
void mergeReleaseBranch(char *version) {
    char releaseName[1000];
    buildBranchName(releaseName, "release", version);
    printf("Merge branch %s for release version %s\n", releaseName, version);
    mergeIntoAndPush(releaseName, "master", "release");
    mergeIntoAndPush(releaseName, DEV_BRANCH, "release");
    tag(version);
    deleteBranch(releaseName);
}


readn

repo: priitj/whitedb

decompiled_code:
size_t __fastcall readn(int fd, void *buf, size_t n)
{
size_t v3; // r13
size_t v5; // rbx
ssize_t v6; // rax

v3 = n;
if ( n )
{
v5 = n;
while ( 1 )
{
v6 = recv(fd, buf, v5, 0);
if ( v6 < 0 )
{
if ( *__errno_location() != 4 )
return -1LL;
v6 = 0LL;
}
else if ( !v6 )
{
return v3 - v5;
}
buf = (char *)buf + v6;
v5 -= v6;
if ( !v5 )
return v3 - v5;
}
}
v5 = 0LL;
return v3 - v5;
}

canonical_decompiled_code:
size_t __fastcall func8(int fd, void *buf, size_t n)
{
size_t v3; // r13
size_t v5; // rbx
ssize_t v6; // rax

v3 = n;
if ( n )
{
v5 = n;
while ( 1 )
{
v6 = recv(fd, buf, v5, 0);
if ( v6 < 0 )
{
if ( *__errno_location() != 4 )
return -1LL;
v6 = 0LL;
}
else if ( !v6 )
{
return v3 - v5;
}
buf = (char *)buf + v6;
v5 -= v6;
if ( !v5 )
return v3 - v5;
}
}
v5 = 0LL;
return v3 - v5;
}

original_code:
static ssize_t readn(int fd, void *usrbuf, size_t n) {
  size_t nleft = n;
  ssize_t nread;
  char *bufp = usrbuf;
  while (nleft>0) {
    if ((nread=recv(fd, bufp, nleft, 0)) < 0) {
        if ((*__errno_location ())==4) nread=0;
        else {
          return -1;
        }
    } else if (nread==0) break;
    nleft -= nread;
    bufp += nread;
  }
  return (n-nleft);
}

canonical_original_code:
static long readn(int fd, void *usrbuf, unsigned long n) {
  unsigned long nleft = n;
  long nread;
  char *bufp = usrbuf;
  while (nleft>0) {
    if ((nread=recv(fd, bufp, nleft, 0)) < 0) {
        if ((*__errno_location ())==4) nread=0;
        else {
          return -1;
        }
    } else if (nread==0) break;
    nleft -= nread;
    bufp += nread;
  }
  return (n-nleft);
}

variable_types: fd int

variable_types:
usrbuf
void *

variable_types:
n
unsigned long

variable_types:
nleft
unsigned long

variable_types: nread long

variable_types:
bufp
char *

return_type: long


decompiled_code:
void __fastcall __noreturn err_exit(int fd, void *ptr, int a3)
{
shutdown(fd, 2);
close(fd);
if ( ptr )
free(ptr);
pthread_exit((void *)a3);
}

canonical_decompiled_code:
void __fastcall __noreturn func9(int fd, void *ptr, int a3)
{
shutdown(fd, 2);
close(fd);
if ( ptr )
free(ptr);
pthread_exit((void *)a3);
}

original_code:
void err_exit(int sockfd, char *buffer, int tid) {
  shutdown(sockfd,SHUT_RDWR);
  close(sockfd);
  if (buffer!=((void *)0)) free(buffer);
  pthread_exit((void*) tid);
}

canonical_original_code:
void err_exit(int sockfd, char *buffer, int tid) {
  shutdown(sockfd,SHUT_RDWR);
  close(sockfd);
  if (buffer!=((void *)0)) free(buffer);
  pthread_exit((void *) tid);
}

variable_types: sockfd int

variable_types:
buffer
char *

variable_types: tid int


errhalt

decompiled_code:
void __fastcall __noreturn errhalt(const char *a1)
{
printf("Error: %s\n", a1);
exit(-1);
}

canonical_decompiled_code:
void __fastcall __noreturn func10(const char *a1)
{
printf("Error: %s\n", a1);
exit(-1);
}

original_code:
void errhalt(char *str) {
  printf("Error: %s\n",str);
  exit(-1);
}

variable_types:
str
char *


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // [rsp+4460Ch] [rbp-86Ch]

v3 = 0;
if ( argc <= 3 )
errhalt(
"three obligatory args - url, threads, iter - like: 'http://127.0.0.1:8080/dserve?op=search' 2 3 - plus one optio"
"nal: string to look for in results");
if ( (unsigned int)__isoc99_sscanf() == 3 )
errhalt("nonnumeric or zero port given");
errhalt("could not parse the url");
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // [rsp+4460Ch] [rbp-86Ch]

v3 = 0;
if ( argc <= 3 )
func10(
"three obligatory args - url, threads, iter - like: 'http://127.0.0.1:8080/dserve?op=search' 2 3 - plus one optio"
"nal: string to look for in results");
if ( (unsigned int)__isoc99_sscanf() == 3 )
func10("nonnumeric or zero port given");
func10("could not parse the url");
}

original_code:
int main(int argc, char **argv) {
  int i,tmax,iter,maxiter,rc;
  char ip[100], urlpart[2000];
  int portnr=0;
  pthread_t threads[5000];
  pthread_attr_t attr;
  struct thread_data tdata[5000];
  long tid;
  char* verify=((void *)0);
  if (argc<4)
    errhalt("three obligatory args - url, threads, iter - like:  'http://127.0.0.1:8080/dserve?op=search' 2 3  - plus one optional: string to look for in results");
  if (sscanf(argv[1], "http://%99[^:]:%i/%999[^\n]", ip, &portnr, urlpart) != 3) {
    errhalt("could not parse the url");
  }
  if (!portnr) errhalt("nonnumeric or zero port given");
  tmax=atoi(argv[2]);
  if (!tmax) errhalt("nonnumeric or zero thread count given");
  maxiter=atoi(argv[3]);
  if (!maxiter) errhalt("nonnumeric or zero iteration count given");
  if (tmax>=5000) errhalt("too many threads to be created");
  if (argc==5) {
    verify=argv[4];
    printf ("first line must contain 200 and the body must contain %s\n",verify);
  } else {
    verify=((void *)0);
    printf("no result verification to be done except 200 check in the first line  \n");
  }
  printf("starting %d threads to run %d iterations each\n",tmax,maxiter);
  pthread_attr_init(&attr);
  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
  for(iter=0; iter<1; iter++) {
    for(tid=0;tid<tmax;tid++) {
      tdata[tid].thread_id=tid;
      tdata[tid].maxiter=maxiter;
      tdata[tid].ip=ip;
      tdata[tid].port=portnr;
      tdata[tid].urlpart=urlpart;
      tdata[tid].verify=verify;
      tdata[tid].res=0;
      rc=pthread_create(&threads[tid], &attr, process, (void *) &tdata[tid]);
    }
    for(tid=0;tid<tmax;tid++) {
      pthread_join(threads[tid],((void *)0));
    }
  }
  printf("\nall iterations finished\n");
  pthread_exit(((void *)0));
  return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
  int i; int tmax; int iter; int maxiter; int rc;
  char ip[100]; char urlpart[2000];
  int portnr = 0;
  unsigned long threads[5000];
  union pthread_attr_t attr;
  struct thread_data tdata[5000];
  long tid;
  char *verify = ((void *)0);
  if (argc<4)
    errhalt("three obligatory args - url, threads, iter - like:  'http://127.0.0.1:8080/dserve?op=search' 2 3  - plus one optional: string to look for in results");
  if (sscanf(argv[1], "http://%99[^:]:%i/%999[^\n]", ip, &portnr, urlpart) != 3) {
    errhalt("could not parse the url");
  }
  if (!portnr) errhalt("nonnumeric or zero port given");
  tmax=atoi(argv[2]);
  if (!tmax) errhalt("nonnumeric or zero thread count given");
  maxiter=atoi(argv[3]);
  if (!maxiter) errhalt("nonnumeric or zero iteration count given");
  if (tmax>=5000) errhalt("too many threads to be created");
  if (argc==5) {
    verify=argv[4];
    printf ("first line must contain 200 and the body must contain %s\n",verify);
  } else {
    verify=((void *)0);
    printf("no result verification to be done except 200 check in the first line  \n");
  }
  printf("starting %d threads to run %d iterations each\n",tmax,maxiter);
  pthread_attr_init(&attr);
  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
  for(iter=0; iter<1; iter++) {
    for(tid=0;tid<tmax;tid++) {
      tdata[tid].thread_id=tid;
      tdata[tid].maxiter=maxiter;
      tdata[tid].ip=ip;
      tdata[tid].port=portnr;
      tdata[tid].urlpart=urlpart;
      tdata[tid].verify=verify;
      tdata[tid].res=0;
      rc=pthread_create(&threads[tid], &attr, process, (void *) &tdata[tid]);
    }
    for(tid=0;tid<tmax;tid++) {
      pthread_join(threads[tid],((void *)0));
    }
  }
  printf("\nall iterations finished\n");
  pthread_exit(((void *)0));
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: i int

variable_types: tmax int

variable_types: iter int

variable_types: maxiter int

variable_types: rc int

variable_types:
ip
char [100]

variable_types:
urlpart
char [2000]

variable_types: portnr int

variable_types:
threads
unsigned long [5000]

variable_types: union pthread_attr_t { char __size[56]; long __align; }

variable_types: struct thread_data { int thread_id; int maxiter; char *ip; int port; char *urlpart; char *verify; int res; } [5000]

variable_types: tid long

variable_types:
verify
char *


process

decompiled_code:
void __fastcall __noreturn process(void *a1)
{
char *v1; // r14
int v2; // ebx
char *v3; // r15
char *v4; // rax
__int64 v5; // rbx
char *v6; // rax
char *v7; // rax
unsigned int v8; // ebp
size_t v9; // rax
__useconds_t v10; // er15
int v11; // er13
unsigned int v12; // ebx
int v13; // er12
unsigned int i; // [rsp+0h] [rbp-88h]
unsigned int v15; // [rsp+10h] [rbp-78h]
int v16; // [rsp+14h] [rbp-74h]
struct timespec remaining; // [rsp+20h] [rbp-68h] BYREF
struct timespec requested_time; // [rsp+30h] [rbp-58h] BYREF
struct sockaddr addr; // [rsp+40h] [rbp-48h] BYREF

requested_time.tv_sec = 0LL;
requested_time.tv_nsec = 100000LL;
v15 = *(_DWORD *)a1;
printf(
"thread %d starts, ip %s portnr %d url %s \n",
*(unsigned int *)a1,
*((const char **)a1 + 1),
*((unsigned int *)a1 + 4),
*((const char **)a1 + 3));
v1 = (char *)malloc(0x3E8uLL);
v16 = *((_DWORD *)a1 + 1);
if ( v16 > 0 )
{
for ( i = 0; i != v16; ++i )
{
v13 = socket(2, 1, 0);
if ( v13 < 0 )
errhalt("Socket");
*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_WORD *)addr.sa_data = _bswap_16(*((_WORD *)a1 + 8));
if ( !inet_addr(*((const char **)a1 + 1)) )
errhalt("inet_addr problem");
v8 = 0;
while ( 1 )
{
v12 = connect(v13, &addr, 0x10u);
if ( !v12 )
break;
nanosleep(&requested_time, &remaining);
if ( ++v8 == 100 )
errhalt("connect problem");
}
sprintf(v1, "GET /%s HTTP/1.0\n\n", *((const char **)a1 + 3));
v9 = strlen(v1);
send(v13, v1, v9, 0);
if ( *((_QWORD *)a1 + 4) )
{
v10 = 0;
while ( 1 )
{
v11 = readn(v13, v1, 0x3DEuLL);
if ( v11 > 0 )
break;
usleep(v10);
printf("thread %d read try %d at iter %d\n", v15, v12++, i);
v10 += 100;
if ( v12 == 10 )
{
if ( v11 < 0 )
{
printf("thread %d did not succeed to read at all at iter %d, exiting\n", v15, i);
err_exit(v13, v1, v15);
}
LABEL_33:
v1[v11] = 0;
goto LABEL_34;
}
}
if ( v11 <= 989 )
goto LABEL_33;
v3 = &v1[v11];
*v3 = 0;
v4 = strstr(v1, "Content-Length: ");
if ( !v4 )
{
v4 = strstr(v1, "content-length: ");
if ( !v4 )
{
printf("thread %d did not find Content-Length at iter %d, exiting\n", v15, i);
err_exit(v13, v1, v15);
}
}
v5 = (unsigned int)atoi(v4 + 16);
printf("len %d\n", v5);
if ( (int)v5 <= 0 )
{
printf("thread %d got a zero or less Content-Length at iter %d, exiting\n", v15, i);
err_exit(v13, v1, v15);
}
if ( (int)v5 > 99999500 )
{
printf("thread %d got a too big Content-Length at iter %d, exiting\n", v15, i);
err_exit(v13, v1, v15);
}
if ( (int)v5 > 500 )
{
v7 = (char *)realloc(v1, (int)v5 + 500);
v1 = v7;
if ( !v7 )
{
printf("thread %d failed to alloc enough memory at iter %d, exiting\n", v15, i);
err_exit(v13, 0LL, v15);
}
v3 = &v7[v11];
v8 = v11;
}
v6 = strstr(v1, "\r\n\r\n");
if ( !v6 )
{
printf("thread %d did not find empty line at iter %d, exiting\n", v15, i);
err_exit(v13, v1, v15);
}
v3[(int)readn(v13, v3, (int)v5 - v11 + (int)v6 - (int)v1 + 4)] = 0;
LABEL_34:
if ( !strstr(v1, "200") )
{
printf("thread %d received a non-200 http result at iter %d, exiting\n", v15, i);
printf("j %d buffer:\n----\n%s\n----\n", v8, v1);
err_exit(v13, v1, v15);
}
if ( !strstr(v1, *((const char **)a1 + 4)) )
{
printf("thread %d received a non-verified http result at iter %d, exiting\n", v15, i);
err_exit(v13, v1, v15);
}
}
else
{
do
v2 = read(v13, v1, 0x14uLL);
while ( v2 < 0 && *__errno_location() == 4 );
v1[v2] = 0;
if ( !strstr(v1, "200") )
{
printf("thread %d received a non-200 http result at iter %d, exiting\n", v15, i);
err_exit(v13, v1, v15);
}
}
shutdown(v13, 2);
close(v13);
}
}
*((_DWORD *)a1 + 10) = 0;
free(v1);
pthread_exit((void *)(int)v15);
}

canonical_decompiled_code:
void __fastcall __noreturn func11(void *a1)
{
char *v1; // r14
int v2; // ebx
char *v3; // r15
char *v4; // rax
__int64 v5; // rbx
char *v6; // rax
char *v7; // rax
unsigned int v8; // ebp
size_t v9; // rax
__useconds_t v10; // er15
int v11; // er13
unsigned int v12; // ebx
int v13; // er12
unsigned int i; // [rsp+0h] [rbp-88h]
unsigned int v15; // [rsp+10h] [rbp-78h]
int v16; // [rsp+14h] [rbp-74h]
struct timespec remaining; // [rsp+20h] [rbp-68h] BYREF
struct timespec requested_time; // [rsp+30h] [rbp-58h] BYREF
struct sockaddr addr; // [rsp+40h] [rbp-48h] BYREF

requested_time.tv_sec = 0LL;
requested_time.tv_nsec = 100000LL;
v15 = *(_DWORD *)a1;
printf(
"thread %d starts, ip %s portnr %d url %s \n",
*(unsigned int *)a1,
*((const char **)a1 + 1),
*((unsigned int *)a1 + 4),
*((const char **)a1 + 3));
v1 = (char *)malloc(0x3E8uLL);
v16 = *((_DWORD *)a1 + 1);
if ( v16 > 0 )
{
for ( i = 0; i != v16; ++i )
{
v13 = socket(2, 1, 0);
if ( v13 < 0 )
func10("Socket");
*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_WORD *)addr.sa_data = func7(*((_WORD *)a1 + 8));
if ( !inet_addr(*((const char **)a1 + 1)) )
func10("inet_addr problem");
v8 = 0;
while ( 1 )
{
v12 = connect(v13, &addr, 0x10u);
if ( !v12 )
break;
nanosleep(&requested_time, &remaining);
if ( ++v8 == 100 )
func10("connect problem");
}
sprintf(v1, "GET /%s HTTP/1.0\n\n", *((const char **)a1 + 3));
v9 = strlen(v1);
send(v13, v1, v9, 0);
if ( *((_QWORD *)a1 + 4) )
{
v10 = 0;
while ( 1 )
{
v11 = func8(v13, v1, 0x3DEuLL);
if ( v11 > 0 )
break;
usleep(v10);
printf("thread %d read try %d at iter %d\n", v15, v12++, i);
v10 += 100;
if ( v12 == 10 )
{
if ( v11 < 0 )
{
printf("thread %d did not succeed to read at all at iter %d, exiting\n", v15, i);
func9(v13, v1, v15);
}
LABEL_33:
v1[v11] = 0;
goto LABEL_34;
}
}
if ( v11 <= 989 )
goto LABEL_33;
v3 = &v1[v11];
*v3 = 0;
v4 = strstr(v1, "Content-Length: ");
if ( !v4 )
{
v4 = strstr(v1, "content-length: ");
if ( !v4 )
{
printf("thread %d did not find Content-Length at iter %d, exiting\n", v15, i);
func9(v13, v1, v15);
}
}
v5 = (unsigned int)atoi(v4 + 16);
printf("len %d\n", v5);
if ( (int)v5 <= 0 )
{
printf("thread %d got a zero or less Content-Length at iter %d, exiting\n", v15, i);
func9(v13, v1, v15);
}
if ( (int)v5 > 99999500 )
{
printf("thread %d got a too big Content-Length at iter %d, exiting\n", v15, i);
func9(v13, v1, v15);
}
if ( (int)v5 > 500 )
{
v7 = (char *)realloc(v1, (int)v5 + 500);
v1 = v7;
if ( !v7 )
{
printf("thread %d failed to alloc enough memory at iter %d, exiting\n", v15, i);
func9(v13, 0LL, v15);
}
v3 = &v7[v11];
v8 = v11;
}
v6 = strstr(v1, "\r\n\r\n");
if ( !v6 )
{
printf("thread %d did not find empty line at iter %d, exiting\n", v15, i);
func9(v13, v1, v15);
}
v3[(int)func8(v13, v3, (int)v5 - v11 + (int)v6 - (int)v1 + 4)] = 0;
LABEL_34:
if ( !strstr(v1, "200") )
{
printf("thread %d received a non-200 http result at iter %d, exiting\n", v15, i);
printf("j %d buffer:\n----\n%s\n----\n", v8, v1);
func9(v13, v1, v15);
}
if ( !strstr(v1, *((const char **)a1 + 4)) )
{
printf("thread %d received a non-verified http result at iter %d, exiting\n", v15, i);
func9(v13, v1, v15);
}
}
else
{
do
v2 = read(v13, v1, 0x14uLL);
while ( v2 < 0 && *__errno_location() == 4 );
v1[v2] = 0;
if ( !strstr(v1, "200") )
{
printf("thread %d received a non-200 http result at iter %d, exiting\n", v15, i);
func9(v13, v1, v15);
}
}
shutdown(v13, 2);
close(v13);
}
}
*((_DWORD *)a1 + 10) = 0;
free(v1);
pthread_exit((void *)(int)v15);
}

original_code:
void *process(void *targ) {
  struct thread_data *tdata;
  int i,j,k,tid,iter,maxiter,len,clenheader_len,toread,nread;
  int sockfd, bytes_read, ok;
  struct sockaddr_in dest;
  char *buffer, *bufp, *tp;
  char *loc,*clenheader;
  struct timespec tim, tim2;
  tim.tv_sec = 0;
  tim.tv_nsec = 100000;
  tdata=(struct thread_data *) targ;
  tid=tdata->thread_id;
  printf("thread %d starts, ip %s portnr %d url %s \n",tid,tdata->ip,tdata->port,tdata->urlpart);
  buffer=malloc(1000);
  maxiter=tdata->maxiter;
  clenheader="Content-Length:";
  clenheader_len=strlen(clenheader);
  for(iter=0; iter<maxiter; iter++) {
    i=0;
    if ( (sockfd = socket(2, SOCK_STREAM, 0)) < 0 ) {
      errhalt("Socket");
    }
    memset(&dest,0,sizeof(dest));
    dest.sin_family = 2;
    dest.sin_port = htons(tdata->port);
    if (inet_addr(tdata->ip, &dest.sin_addr.s_addr)==0)
        errhalt("inet_addr problem");
    ok=0;
    for(j=0;j<100;j++) {
      if ( connect(sockfd, (struct sockaddr*)&dest, sizeof(dest)) != 0 ) {
        nanosleep(&tim , &tim2);
      } else {
        ok=1;
        break;
      }
    }
    if (!ok) { errhalt("connect problem"); }
    sprintf(buffer, "GET /%s HTTP/1.0\n\n", tdata->urlpart);
    send(sockfd, buffer, strlen(buffer),0);
    len=0;
    if (tdata->verify==((void *)0)) {
      bufp=buffer;
      while (1) {
        if ((nread=read(sockfd, bufp, 20)) < 0) {
          if ((*__errno_location ())==4) nread=0;
          else break;
        } else {
          break;
        }
      }
      *(bufp+nread)='\0';
      if (strstr(buffer,"200")==((void *)0)) {
        printf("thread %d received a non-200 http result at iter %d, exiting\n",tid,iter);
        err_exit(sockfd,buffer,tid);
      }
    } else {
      bufp=buffer;
      toread=1000 -10;
      for(k=0;k<10;k++) {
        nread=readn(sockfd, bufp, toread);
        if (nread>0) break;
        usleep(k*100);
        printf("thread %d read try %d at iter %d\n",tid,k,iter);
      }
      if (nread<0) {
        printf("thread %d did not succeed to read at all at iter %d, exiting\n",tid,iter);
        err_exit(sockfd,buffer,tid);
      } else if (nread<toread) {
        bufp+=nread;
        *bufp='\0';
      } else {
        bufp+=nread;
        *bufp='\0';
        loc=strstr(buffer,"Content-Length: ");
        if (loc==((void *)0)) loc=strstr(buffer,"content-length: ");
        if (loc==((void *)0)) {
          printf("thread %d did not find Content-Length at iter %d, exiting\n",tid,iter);
          err_exit(sockfd,buffer,tid);
        }
        tp=loc+strlen("Content-length: ");
        len=atoi(tp);
        printf("len %d\n",len);
        if (len<=0) {
          printf("thread %d got a zero or less Content-Length at iter %d, exiting\n",tid,iter);
          err_exit(sockfd,buffer,tid);
        }
        if (len+500>100000000) {
          printf("thread %d got a too big Content-Length at iter %d, exiting\n",tid,iter);
          err_exit(sockfd,buffer,tid);
        }
        if (len>(1000 -500)) {
          j=bufp-buffer;
          buffer=realloc(buffer,len+500);
          if (buffer==((void *)0)) {
            printf("thread %d failed to alloc enough memory at iter %d, exiting\n",tid,iter);
            err_exit(sockfd,buffer,tid);
          }
          bufp=buffer+j;
        }
        loc=strstr(buffer,"\r\n\r\n");
        if (loc==((void *)0)) {
          printf("thread %d did not find empty line at iter %d, exiting\n",tid,iter);
          err_exit(sockfd,buffer,tid);
        }
        toread=len+((loc-buffer)+4)-nread;
        nread=readn(sockfd, bufp, toread);
        *(bufp+nread)='\0';
      }
      if (strstr(buffer,"200")==((void *)0)) {
        printf("thread %d received a non-200 http result at iter %d, exiting\n",tid,iter);
        printf("j %d buffer:\n----\n%s\n----\n",j,buffer);
        err_exit(sockfd,buffer,tid);
      }
      if (strstr(buffer,tdata->verify)==((void *)0)) {
        printf("thread %d received a non-verified http result at iter %d, exiting\n",tid,iter);
        err_exit(sockfd,buffer,tid);
      }
    }
    shutdown(sockfd,SHUT_RDWR);
    close(sockfd);
  }
  tdata->res=i;
  free(buffer);
  pthread_exit((void*) tid);
  return ((void *)0);
}

canonical_original_code:
void *process(void *targ) {
  struct thread_data *tdata;
  int i; int j; int k; int tid; int iter; int maxiter; int len; int clenheader_len; int toread; int nread;
  int sockfd; int bytes_read; int ok;
  struct sockaddr_in dest;
  char *buffer; char *bufp; char *tp;
  char *loc; char *clenheader;
  struct timespec tim; struct timespec tim2;
  tim.tv_sec = 0;
  tim.tv_nsec = 100000;
  tdata=(struct thread_data *) targ;
  tid=tdata->thread_id;
  printf("thread %d starts, ip %s portnr %d url %s \n",tid,tdata->ip,tdata->port,tdata->urlpart);
  buffer=malloc(1000);
  maxiter=tdata->maxiter;
  clenheader="Content-Length:";
  clenheader_len=strlen(clenheader);
  for(iter=0; iter<maxiter; iter++) {
    i=0;
    if ( (sockfd = socket(2, SOCK_STREAM, 0)) < 0 ) {
      errhalt("Socket");
    }
    memset(&dest,0,sizeof(dest));
    dest.sin_family = 2;
    dest.sin_port = htons(tdata->port);
    if (inet_addr(tdata->ip, &dest.sin_addr.s_addr)==0)
        errhalt("inet_addr problem");
    ok=0;
    for(j=0;j<100;j++) {
      if ( connect(sockfd, (struct sockaddr *)&dest, sizeof(dest)) != 0 ) {
        nanosleep(&tim , &tim2);
      } else {
        ok=1;
        break;
      }
    }
    if (!ok) { errhalt("connect problem"); }
    sprintf(buffer, "GET /%s HTTP/1.0\n\n", tdata->urlpart);
    send(sockfd, buffer, strlen(buffer),0);
    len=0;
    if (tdata->verify==((void *)0)) {
      bufp=buffer;
      while (1) {
        if ((nread=read(sockfd, bufp, 20)) < 0) {
          if ((*__errno_location ())==4) nread=0;
          else break;
        } else {
          break;
        }
      }
      *(bufp+nread)='\0';
      if (strstr(buffer,"200")==((void *)0)) {
        printf("thread %d received a non-200 http result at iter %d, exiting\n",tid,iter);
        err_exit(sockfd,buffer,tid);
      }
    } else {
      bufp=buffer;
      toread=1000 -10;
      for(k=0;k<10;k++) {
        nread=readn(sockfd, bufp, toread);
        if (nread>0) break;
        usleep(k*100);
        printf("thread %d read try %d at iter %d\n",tid,k,iter);
      }
      if (nread<0) {
        printf("thread %d did not succeed to read at all at iter %d, exiting\n",tid,iter);
        err_exit(sockfd,buffer,tid);
      } else if (nread<toread) {
        bufp+=nread;
        *bufp='\0';
      } else {
        bufp+=nread;
        *bufp='\0';
        loc=strstr(buffer,"Content-Length: ");
        if (loc==((void *)0)) loc=strstr(buffer,"content-length: ");
        if (loc==((void *)0)) {
          printf("thread %d did not find Content-Length at iter %d, exiting\n",tid,iter);
          err_exit(sockfd,buffer,tid);
        }
        tp=loc+strlen("Content-length: ");
        len=atoi(tp);
        printf("len %d\n",len);
        if (len<=0) {
          printf("thread %d got a zero or less Content-Length at iter %d, exiting\n",tid,iter);
          err_exit(sockfd,buffer,tid);
        }
        if (len+500>100000000) {
          printf("thread %d got a too big Content-Length at iter %d, exiting\n",tid,iter);
          err_exit(sockfd,buffer,tid);
        }
        if (len>(1000 -500)) {
          j=bufp-buffer;
          buffer=realloc(buffer,len+500);
          if (buffer==((void *)0)) {
            printf("thread %d failed to alloc enough memory at iter %d, exiting\n",tid,iter);
            err_exit(sockfd,buffer,tid);
          }
          bufp=buffer+j;
        }
        loc=strstr(buffer,"\r\n\r\n");
        if (loc==((void *)0)) {
          printf("thread %d did not find empty line at iter %d, exiting\n",tid,iter);
          err_exit(sockfd,buffer,tid);
        }
        toread=len+((loc-buffer)+4)-nread;
        nread=readn(sockfd, bufp, toread);
        *(bufp+nread)='\0';
      }
      if (strstr(buffer,"200")==((void *)0)) {
        printf("thread %d received a non-200 http result at iter %d, exiting\n",tid,iter);
        printf("j %d buffer:\n----\n%s\n----\n",j,buffer);
        err_exit(sockfd,buffer,tid);
      }
      if (strstr(buffer,tdata->verify)==((void *)0)) {
        printf("thread %d received a non-verified http result at iter %d, exiting\n",tid,iter);
        err_exit(sockfd,buffer,tid);
      }
    }
    shutdown(sockfd,SHUT_RDWR);
    close(sockfd);
  }
  tdata->res=i;
  free(buffer);
  pthread_exit((void *) tid);
  return ((void *)0);
}

variable_types:
targ
void *

variable_types: struct thread_data { int thread_id; int maxiter; char *ip; int port; char *urlpart; char *verify; int res; } *

variable_types: j int

variable_types: k int

variable_types: tid int

variable_types: len int

variable_types: toread int

variable_types: nread int

variable_types: sockfd int

variable_types: ok int

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:
buffer
char *

variable_types:
bufp
char *

variable_types:
tp
char *

variable_types:
loc
char *

variable_types:
clenheader
char *

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

return_type: void *

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


dropq

repo: println/scheduler

decompiled_code:
void __fastcall dropq(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi

v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[1];
free(v3);
}
while ( v2 );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi

v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[1];
free(v3);
}
while ( v2 );
}
free(ptr);
}

original_code:
void dropq(TQueue * q){
  TNode * acc = q->begin, * temp;
  while(acc){
    temp = acc;
    acc = acc->next;
    temp->info = ((void *)0);
    free(temp);
  }
  free(q);
}

canonical_original_code:
void dropq(struct queue *q){
  struct node *acc = q->begin; struct node *temp;
  while(acc){
    temp = acc;
    acc = acc->next;
    temp->info = ((void *)0);
    free(temp);
  }
  free(q);
}

variable_types: struct queue { struct node { struct task { struct user { char id[80]; struct prioritylist { struct prio { int priority; struct queue *tasks; struct prio *next; } *priorities; } *waiting; struct queue *done; struct user *next; } *owner; unsigned int pid; int priority; char cmd[80]; } *info; struct node *next; } *begin; struct node *end; } *

variable_types: struct node { struct task { struct user { char id[80]; struct prioritylist { struct prio { int priority; struct queue { struct node *begin; struct node *end; } *tasks; struct prio *next; } *priorities; } *waiting; struct queue *done; struct user *next; } *owner; unsigned int pid; int priority; char cmd[80]; } *info; struct node *next; } *

user_defined_types: struct node { struct task *info; struct node *next; }

user_defined_types: struct task { struct user *owner; unsigned int pid; int priority; char cmd[80]; }

user_defined_types: struct user { char id[80]; struct prioritylist *waiting; struct queue *done; struct user *next; }

user_defined_types: struct prioritylist { struct prio *priorities; }


releaseq

decompiled_code:
void __fastcall releaseq(void *ptr)
{
__int64 v1; // rbx
void **v2; // rbp

v1 = *(_QWORD *)ptr;
while ( v1 )
{
v2 = (void **)v1;
v1 = *(_QWORD *)(v1 + 8);
free(*v2);
free(v2);
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
__int64 v1; // rbx
void **v2; // rbp

v1 = *(_QWORD *)ptr;
while ( v1 )
{
v2 = (void **)v1;
v1 = *(_QWORD *)(v1 + 8);
free(*v2);
free(v2);
}
free(ptr);
}

original_code:
void releaseq(TQueue * q){
  TNode * acc = q->begin, * temp;
  while(acc){
    temp = acc;
    acc = acc->next;
    free(temp->info);
    free(temp);
  }
  free(q);
}

canonical_original_code:
void releaseq(struct queue *q){
  struct node *acc = q->begin; struct node *temp;
  while(acc){
    temp = acc;
    acc = acc->next;
    free(temp->info);
    free(temp);
  }
  free(q);
}

user_defined_types: struct queue { struct node *begin; struct node *end; }

user_defined_types: struct prio { int priority; struct queue *tasks; struct prio *next; }


initializeq

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

result = malloc(0x10uLL);
result[1] = 0LL;
*result = 0LL;
return result;
}

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

result = malloc(0x10uLL);
result[1] = 0LL;
*result = 0LL;
return result;
}

original_code:
TQueue * initializeq(void){
  TQueue * q = (TQueue *)malloc(sizeof(TQueue));
  q->begin = q->end = ((void *)0);
  return q;
}

canonical_original_code:
struct queue *initializeq(){
  struct queue *q = (TQueue *)malloc(sizeof(TQueue));
  q->begin = q->end = ((void *)0);
  return q;
}

return_type: struct queue { struct node { struct task { struct user { char id[80]; struct prioritylist { struct prio { int priority; struct queue *tasks; struct prio *next; } *priorities; } *waiting; struct queue *done; struct user *next; } *owner; unsigned int pid; int priority; char cmd[80]; } *info; struct node *next; } *begin; struct node *end; } *


emptyq

decompiled_code:
_BOOL8 __fastcall emptyq(_QWORD *a1)
{
return *a1 == 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(_QWORD *a1)
{
return *a1 == 0LL;
}

original_code:
int emptyq(TQueue * q){
  return (q->begin == ((void *)0));
}

canonical_original_code:
int emptyq(struct queue *q){
  return (q->begin == ((void *)0));
}


printq

decompiled_code:
int __fastcall printq(_QWORD *a1)
{
int result; // eax
_QWORD *v2; // rbx

result = emptyq(a1);
if ( !result )
{
v2 = (_QWORD *)*a1;
if ( *a1 )
{
while ( 1 )
{
result = printf(
"%d:%d:%s",
*(unsigned int *)(*v2 + 8LL),
*(unsigned int *)(*v2 + 12LL),
(const char *)(*v2 + 16LL));
v2 = (_QWORD *)v2[1];
if ( !v2 )
break;
printf(" - ");
}
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(_QWORD *a1)
{
int result; // eax
_QWORD *v2; // rbx

result = func3(a1);
if ( !result )
{
v2 = (_QWORD *)*a1;
if ( *a1 )
{
while ( 1 )
{
result = printf(
"%d:%d:%s",
*(unsigned int *)(*v2 + 8LL),
*(unsigned int *)(*v2 + 12LL),
(const char *)(*v2 + 16LL));
v2 = (_QWORD *)v2[1];
if ( !v2 )
break;
printf(" - ");
}
}
}
return result;
}

original_code:
void printq(TQueue * q){
  if(emptyq(q))
    return;
  TNode * acc = q->begin;
  while(acc){
    Task * task = acc->info;
    printf("%d:%d:%s", task->pid,task->priority,task->cmd);
    acc = acc->next;
    if(acc)
      printf(" - ");
  }
}

canonical_original_code:
void printq(struct queue *q){
  if(emptyq(q))
    return;
  struct node *acc = q->begin;
  while(acc){
    struct task *task = acc->info;
    printf("%d:%d:%s", task->pid,task->priority,task->cmd);
    acc = acc->next;
    if(acc)
      printf(" - ");
  }
}

variable_types: struct task { struct user { char id[80]; struct prioritylist { struct prio { int priority; struct queue { struct node { struct task *info; struct node *next; } *begin; struct node *end; } *tasks; struct prio *next; } *priorities; } *waiting; struct queue *done; struct user *next; } *owner; unsigned int pid; int priority; char cmd[80]; } *


pop

original_code:
Task * pop(TQueue * q){
  if(emptyq(q))
    exit(1);
  TNode * n = q->begin;
  q->begin = n->next;
  if(!q->begin)
    q->end = ((void *)0);
  Task * t = n->info;
  free(n);
  return t;
}

canonical_original_code:
struct task *pop(struct queue *q){
  if(emptyq(q))
    exit(1);
  struct node *n = q->begin;
  q->begin = n->next;
  if(!q->begin)
    q->end = ((void *)0);
  struct task *t = n->info;
  free(n);
  return t;
}

variable_types:
q
struct queue *

return_type: struct task { struct user { char id[80]; struct prioritylist { struct prio { int priority; struct queue { struct node { struct task *info; struct node *next; } *begin; struct node *end; } *tasks; struct prio *next; } *priorities; } *waiting; struct queue *done; struct user *next; } *owner; unsigned int pid; int priority; char cmd[80]; } *


decompiled_code:
int run_help()
{
system("clear");
puts("+++ HELP +++");
puts("[usuario:prioridade:comando]\t\tcria nova tarefa");
puts("file nome_arquivo\t\t\tcarrega arquivo de tarefas");
puts("print [fu,fe,ftr,user [nome],users]\timprime");
puts("make\t\t\t\t\tcarrega FU e FTR de FE");
puts("run\t\t\t\t\texecuta UMA tarefa de FTR ou FU");
puts("runall\t\t\t\t\texecuta TODAS as tarefas de FTR e FU");
puts("clear\t\t\t\t\tlimpa a tela");
puts("exit\t\t\t\t\tsai do programa");
return puts("+++ end +++\n");
}

canonical_decompiled_code:
int func0()
{
system("clear");
puts("+++ HELP +++");
puts("[usuario:prioridade:comando]\t\tcria nova tarefa");
puts("file nome_arquivo\t\t\tcarrega arquivo de tarefas");
puts("print [fu,fe,ftr,user [nome],users]\timprime");
puts("make\t\t\t\t\tcarrega FU e FTR de FE");
puts("run\t\t\t\t\texecuta UMA tarefa de FTR ou FU");
puts("runall\t\t\t\t\texecuta TODAS as tarefas de FTR e FU");
puts("clear\t\t\t\t\tlimpa a tela");
puts("exit\t\t\t\t\tsai do programa");
return puts("+++ end +++\n");
}

original_code:
void run_help(){
    system("clear");
    printf("+++ HELP +++\n");
    printf("[usuario:prioridade:comando]\t\tcria nova tarefa\n");
    printf("file nome_arquivo\t\t\tcarrega arquivo de tarefas\n");
    printf("print [fu,fe,ftr,user [nome],users]\timprime\n");
    printf("make\t\t\t\t\tcarrega FU e FTR de FE\n");
    printf("run\t\t\t\t\texecuta UMA tarefa de FTR ou FU\n");
    printf("runall\t\t\t\t\texecuta TODAS as tarefas de FTR e FU\n");
    printf("clear\t\t\t\t\tlimpa a tela\n");
    printf("exit\t\t\t\t\tsai do programa\n");
    printf("+++ end +++\n\n");
}


original_code:
void run_print(TBase * base, char * cmd) {
    char command[120];
    char arg[120];
    char ex[120];
    sscanf(cmd, "%[^ ] %[^ ] %[^ ] ", ex, command, arg);
    if (!strcmp("ftr", command))
        print_ftr(base);
    else if (!strcmp("fu", command))
        print_fu(base);
    else if (!strcmp("fpso", command))
        print_fpso(base);
    else if (!strcmp("fe", command))
        print_fe(base);
    else if (!strcmp("users", command))
        print_users(base);
    else if (!strcmp("user", command)) {
        TUser * user = finduser(base->users, arg);
        if (user)
            print_user(user);
    }
}

canonical_original_code:
void run_print(struct base *base, char *cmd) {
    char command[120];
    char arg[120];
    char ex[120];
    sscanf(cmd, "%[^ ] %[^ ] %[^ ] ", ex, command, arg);
    if (!strcmp("ftr", command))
        print_ftr(base);
    else if (!strcmp("fu", command))
        print_fu(base);
    else if (!strcmp("fpso", command))
        print_fpso(base);
    else if (!strcmp("fe", command))
        print_fe(base);
    else if (!strcmp("users", command))
        print_users(base);
    else if (!strcmp("user", command)) {
        struct user *user = finduser(base->users, arg);
        if (user)
            print_user(user);
    }
}

variable_types: struct base { unsigned int pid; struct user { char id[80]; struct prioritylist { struct prio { int priority; struct queue { struct node { struct task { struct user *owner; unsigned int pid; int priority; char cmd[80]; } *info; struct node *next; } *begin; struct node *end; } *tasks; struct prio *next; } *priorities; } *waiting; struct queue *done; struct user *next; } *users; struct queue *FE; struct prioritylist *FU; struct queue *FTR; struct queue *FPSO; } *

variable_types:
cmd
char *

variable_types:
command
char [120]

variable_types:
arg
char [120]

variable_types:
ex
char [120]

user_defined_types: struct base { unsigned int pid; struct user *users; struct queue *FE; struct prioritylist *FU; struct queue *FTR; struct queue *FPSO; }


decompiled_code:
__int64 __fastcall run_exec(_QWORD *a1)
{
__int64 v1; // rbp
__int64 result; // rax
int v3; // edx

if ( (unsigned int)emptyq(a1[4]) )
{
v3 = emptyp(a1[3]);
result = 0LL;
if ( v3 )
return result;
v1 = toptask(a1[3]);
}
else
{
v1 = pop(a1[4]);
}
result = 0LL;
if ( v1 )
{
push(a1[5], v1);
result = execute(v1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
__int64 v1; // rbp
__int64 result; // rax
int v3; // edx

if ( (unsigned int)emptyq(a1[4]) )
{
v3 = emptyp(a1[3]);
result = 0LL;
if ( v3 )
return result;
v1 = toptask(a1[3]);
}
else
{
v1 = pop(a1[4]);
}
result = 0LL;
if ( v1 )
{
push(a1[5], v1);
result = execute(v1);
}
return result;
}

original_code:
int run_exec(TBase * base) {
    Task * task = ((void *)0);
    if (!emptyq(base->FTR))
        task = pop(base->FTR);
    else if (!emptyp(base->FU))
        task = toptask(base->FU);
    if (task){
        push(base->FPSO,task);
        return execute(task);
    }
    return 0;
}

canonical_original_code:
int run_exec(struct base *base) {
    struct task *task = ((void *)0);
    if (!emptyq(base->FTR))
        task = pop(base->FTR);
    else if (!emptyp(base->FU))
        task = toptask(base->FU);
    if (task){
        push(base->FPSO,task);
        return execute(task);
    }
    return 0;
}


decompiled_code:
__int64 __fastcall run_execall(_QWORD *a1)
{
__int64 result; // rax

while ( 1 )
{
if ( (unsigned int)emptyq(a1[4]) )
{
result = emptyp(a1[3]);
if ( (_DWORD)result )
break;
}
run_exec(a1);
}
return result;
}

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

while ( 1 )
{
if ( (unsigned int)emptyq(a1[4]) )
{
result = emptyp(a1[3]);
if ( (_DWORD)result )
break;
}
func2(a1);
}
return result;
}

original_code:
void run_execall(TBase * base) {
    while (!emptyq(base->FTR) || !emptyp(base->FU))
        run_exec(base);
}

canonical_original_code:
void run_execall(struct base *base) {
    while (!emptyq(base->FTR) || !emptyp(base->FU))
        run_exec(base);
}


decompiled_code:
__int64 run_prepare()
{
return arrange();
}

canonical_decompiled_code:
__int64 func4()
{
return arrange();
}

original_code:
void run_prepare(TBase * base) {
    arrange(base);
}

canonical_original_code:
void run_prepare(struct base *base) {
    arrange(base);
}


original_code:
int run_usercmd(TBase * base, char * cmd) {
    int i, j, value = 0;
    char end = '\0';
    char u[120] = "", p[120] = "", c[120] = "";
    for (i = 0, j = 0; cmd[i] != end; i++, j++) {
        if (cmd[i] == ':' && value < 2) {
            value++;
            j = -1;
        } else {
            if (value == 0) {
                u[j] = cmd[i];
                u[j + 1] = end;
            }
            if (value == 1) {
                p[j] = cmd[i];
                p[j + 1] = end;
            }
            if (value == 2) {
                c[j] = cmd[i];
                c[j + 1] = end;
            }
        }
    }
    if (value != 2 || u[0] == '\0' || p[0] == '\0' || c[0] == '\0')
        return 0;
    for (j = 0; p[j] != end; j++) {
        if (p[j] == '-' || p[j] < '0' || p[j] > '9') {
            printf("somente prioridade inteira positiva!\n");
            return 0;
        }
    }
    if (!base)
        return 1;
    int priority;
    sscanf(p, "%i", &priority);
    unsigned int pid = newtask(base, u, priority, c);
    printf("ID: %d\n", pid);
    return 1;
}

canonical_original_code:
int run_usercmd(struct base *base, char *cmd) {
    int i; int j; int value = 0;
    char end = '\0';
    char u[120] = ""; char p[120] = ""; char c[120] = "";
    for (i = 0, j = 0; cmd[i] != end; i++, j++) {
        if (cmd[i] == ':' && value < 2) {
            value++;
            j = -1;
        } else {
            if (value == 0) {
                u[j] = cmd[i];
                u[j + 1] = end;
            }
            if (value == 1) {
                p[j] = cmd[i];
                p[j + 1] = end;
            }
            if (value == 2) {
                c[j] = cmd[i];
                c[j + 1] = end;
            }
        }
    }
    if (value != 2 || u[0] == '\0' || p[0] == '\0' || c[0] == '\0')
        return 0;
    for (j = 0; p[j] != end; j++) {
        if (p[j] == '-' || p[j] < '0' || p[j] > '9') {
            printf("somente prioridade inteira positiva!\n");
            return 0;
        }
    }
    if (!base)
        return 1;
    int priority;
    sscanf(p, "%i", &priority);
    unsigned int pid = newtask(base, u, priority, c);
    printf("ID: %d\n", pid);
    return 1;
}

variable_types: i int

variable_types: j int

variable_types: value int

variable_types: end char

variable_types:
u
char [120]

variable_types:
p
char [120]

variable_types:
c
char [120]

variable_types: priority int

variable_types:
pid
unsigned int


decompiled_code:
__int64 __fastcall check_user_cmd(char *a1)
{
return run_usercmd(0LL, a1);
}

canonical_decompiled_code:
__int64 __fastcall func6(char *a1)
{
return func5(0LL, a1);
}

original_code:
int check_user_cmd(char * cmd) {
    return run_usercmd(((void *)0), cmd);
}

canonical_original_code:
int check_user_cmd(char *cmd) {
    return run_usercmd(((void *)0), cmd);
}


command

decompiled_code:
_BOOL8 __fastcall command(char *a1, _QWORD *a2)
{
bool v4; // al
bool v5; // cf
bool v6; // zf
char *v7; // rdi
const char *v8; // rsi
__int64 v9; // rcx
_BOOL8 result; // rax
char v11[128]; // [rsp+0h] [rbp-118h] BYREF
char v12[152]; // [rsp+80h] [rbp-98h] BYREF

_isoc99_sscanf(a1, "%[^ ] %s", v12, v11);
v4 = strcmp("file", v12) != 0;
v5 = 0;
v6 = !v4;
if ( v4 )
{
v7 = v12;
v8 = "make";
v9 = 5LL;
do
{
if ( !v9 )
break;
v5 = (unsigned int)*v8 < (unsigned __int8)*v7;
v6 = *v8++ == (unsigned __int8)*v7++;
--v9;
}
while ( v6 );
if ( (!v5 && !v6) == v5 )
{
run_prepare(a2, v8);
result = 1LL;
}
else if ( !strcmp("run", v12) )
{
run_exec(a2);
result = 1LL;
}
else if ( !strcmp("runall", v12) )
{
run_execall(a2);
result = 1LL;
}
else
{
v6 = strcmp("exit", v12) == 0;
result = !v6;
if ( !v6 )
{
if ( !strcmp("help", v12) )
{
run_help();
result = 1LL;
}
else if ( !strcmp("clear", v12) )
{
system("clear");
result = 1LL;
}
else if ( !strcmp("print", v12) )
{
run_print((__int64)a2, (__int64)a1);
result = 1LL;
}
else
{
if ( (unsigned int)check_user_cmd(a1) )
run_usercmd((__int64)a2, a1);
else
puts("comando inexistente");
result = 1LL;
}
}
}
}
else
{
run_file((__int64)a2, v11);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(char *a1, _QWORD *a2)
{
bool v4; // al
bool v5; // cf
bool v6; // zf
char *v7; // rdi
const char *v8; // rsi
__int64 v9; // rcx
_BOOL8 result; // rax
char v11[128]; // [rsp+0h] [rbp-118h] BYREF
char v12[152]; // [rsp+80h] [rbp-98h] BYREF

_isoc99_sscanf(a1, "%[^ ] %s", v12, v11);
v4 = strcmp("file", v12) != 0;
v5 = 0;
v6 = !v4;
if ( v4 )
{
v7 = v12;
v8 = "make";
v9 = 5LL;
do
{
if ( !v9 )
break;
v5 = (unsigned int)*v8 < (unsigned __int8)*v7;
v6 = *v8++ == (unsigned __int8)*v7++;
--v9;
}
while ( v6 );
if ( (!v5 && !v6) == v5 )
{
func4(a2, v8);
result = 1LL;
}
else if ( !strcmp("run", v12) )
{
func2(a2);
result = 1LL;
}
else if ( !strcmp("runall", v12) )
{
func3(a2);
result = 1LL;
}
else
{
v6 = strcmp("exit", v12) == 0;
result = !v6;
if ( !v6 )
{
if ( !strcmp("help", v12) )
{
func0();
result = 1LL;
}
else if ( !strcmp("clear", v12) )
{
system("clear");
result = 1LL;
}
else if ( !strcmp("print", v12) )
{
func1((__int64)a2, (__int64)a1);
result = 1LL;
}
else
{
if ( (unsigned int)func6(a1) )
func5((__int64)a2, a1);
else
puts("comando inexistente");
result = 1LL;
}
}
}
}
else
{
func7((__int64)a2, v11);
result = 1LL;
}
return result;
}

original_code:
int command(char * cmd, TBase * base) {
    char command[120];
    char arg[120];
    sscanf(cmd, "%[^ ] %s", command, arg);
    if (!strcmp("file", command))
        run_file(base,arg);
    else if (!strcmp("make", command)) {
        run_prepare(base);
    } else if (!strcmp("run", command)) {
        run_exec(base);
    } else if (!strcmp("runall", command)) {
        run_execall(base);
    } else if (!strcmp("exit", command)) {
        return 0;
    } else if (!strcmp("help", command)) {
        run_help();
    } else if (!strcmp("clear", command)) {
        system("clear");
    } else if (!strcmp("print", command)) {
        run_print(base, cmd);
    } else if (check_user_cmd(cmd))
        run_usercmd(base, cmd);
    else
        printf("comando inexistente\n");
    return 1;
}

canonical_original_code:
int command(char *cmd, struct base *base) {
    char command[120];
    char arg[120];
    sscanf(cmd, "%[^ ] %s", command, arg);
    if (!strcmp("file", command))
        run_file(base,arg);
    else if (!strcmp("make", command)) {
        run_prepare(base);
    } else if (!strcmp("run", command)) {
        run_exec(base);
    } else if (!strcmp("runall", command)) {
        run_execall(base);
    } else if (!strcmp("exit", command)) {
        return 0;
    } else if (!strcmp("help", command)) {
        run_help();
    } else if (!strcmp("clear", command)) {
        system("clear");
    } else if (!strcmp("print", command)) {
        run_print(base, cmd);
    } else if (check_user_cmd(cmd))
        run_usercmd(base, cmd);
    else
        printf("comando inexistente\n");
    return 1;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_QWORD *v3; // rbx
char v5[136]; // [rsp+0h] [rbp-88h] BYREF

v3 = (_QWORD *)start_base(argc, argv, envp);
run_help();
do
_isoc99_scanf(" %[^\n]s", v5);
while ( command(v5, v3) );
putchar(10);
print_users(v3, v3);
print_fe(v3, v3);
print_ftr(v3, v3);
print_fu(v3, v3);
print_fpso(v3, v3);
freebase(v3);
free(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_QWORD *v3; // rbx
char v5[136]; // [rsp+0h] [rbp-88h] BYREF

v3 = (_QWORD *)start_base(argc, argv, envp);
func0();
do
_isoc99_scanf(" %[^\n]s", v5);
while ( func8(v5, v3) );
putchar(10);
print_users(v3, v3);
print_fe(v3, v3);
print_ftr(v3, v3);
print_fu(v3, v3);
print_fpso(v3, v3);
freebase(v3);
free(v3);
return 0;
}

original_code:
int main(void) {
    TBase * base = start_base();
    char input[120];
    int loop = 1;
    run_help();
    while (loop) {
        scanf(" %[^\n]s", input);
        loop = command(input, base);
    }
    printf("\n");
    print_users(base);
    print_fe(base);
    print_ftr(base);
    print_fu(base);
    print_fpso(base);
    freebase(base);
    free(base);
    return (0);
}

canonical_original_code:
int main() {
    struct base *base = start_base();
    char input[120];
    int loop = 1;
    run_help();
    while (loop) {
        scanf(" %[^\n]s", input);
        loop = command(input, base);
    }
    printf("\n");
    print_users(base);
    print_fe(base);
    print_ftr(base);
    print_fu(base);
    print_fpso(base);
    freebase(base);
    free(base);
    return (0);
}

variable_types:
input
char [120]

variable_types: loop int


initializep

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

result = malloc(8uLL);
*result = 0LL;
return result;
}

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

result = malloc(8uLL);
*result = 0LL;
return result;
}

original_code:
PriorityList * initializep(void) {
    PriorityList * pl = (PriorityList*) malloc(sizeof (PriorityList));
    pl->priorities = ((void *)0);
    return pl;
}

canonical_original_code:
struct prioritylist *initializep() {
    struct prioritylist *pl = (PriorityList*) malloc(sizeof (PriorityList));
    pl->priorities = ((void *)0);
    return pl;
}

variable_types: struct prioritylist { struct prio { int priority; struct queue { struct node { struct task { struct user { char id[80]; struct prioritylist *waiting; struct queue *done; struct user *next; } *owner; unsigned int pid; int priority; char cmd[80]; } *info; struct node *next; } *begin; struct node *end; } *tasks; struct prio *next; } *priorities; } *


emptyp

decompiled_code:
_BOOL8 __fastcall emptyp(_QWORD *a1)
{
return *a1 == 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(_QWORD *a1)
{
return *a1 == 0LL;
}

original_code:
int emptyp(PriorityList * plist) {
    return (plist->priorities == ((void *)0));
}

canonical_original_code:
int emptyp(struct prioritylist *plist) {
    return (plist->priorities == ((void *)0));
}


addtask

decompiled_code:
__int64 __fastcall addtask(__int64 *a1, __int64 a2)
{
return insert(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 *a1, __int64 a2)
{
return func1(a1, a2);
}

original_code:
void addtask(PriorityList * plist, Task * task) {
    _insert(plist, task);
}

canonical_original_code:
void addtask(struct prioritylist *plist, struct task *task) {
    _insert(plist, task);
}

variable_types:
task
struct task *


toptask

decompiled_code:
__int64 __fastcall toptask(char *filename)
{
__int64 v1; // rbp
int v2; // eax

if ( !filename )
return 0LL;
v1 = *(_QWORD *)filename;
if ( *(_QWORD *)filename )
{
v2 = emptyq(*(_QWORD *)(v1 + 8));
v1 = 0LL;
if ( !v2 )
{
v1 = pop(*(_QWORD *)(*(_QWORD *)filename + 8LL));
remove(filename);
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *filename)
{
__int64 v1; // rbp
int v2; // eax

if ( !filename )
return 0LL;
v1 = *(_QWORD *)filename;
if ( *(_QWORD *)filename )
{
v2 = emptyq(*(_QWORD *)(v1 + 8));
v1 = 0LL;
if ( !v2 )
{
v1 = pop(*(_QWORD *)(*(_QWORD *)filename + 8LL));
func4(filename);
}
}
return v1;
}

original_code:
Task * toptask(PriorityList * plist) {
    if (plist && plist->priorities && !emptyq(plist->priorities->tasks)) {
        Task * task = pop(plist->priorities->tasks);
        _remove(plist, task);
        return task;
    }
    return ((void *)0);
}

canonical_original_code:
struct task *toptask(struct prioritylist *plist) {
    if (plist && plist->priorities && !emptyq(plist->priorities->tasks)) {
        struct task *task = pop(plist->priorities->tasks);
        _remove(plist, task);
        return task;
    }
    return ((void *)0);
}

variable_types:
plist
struct prioritylist *

variable_types: struct task { struct user { char id[80]; struct prioritylist { struct prio { int priority; struct queue { struct node { struct task *info; struct node *next; } *begin; struct node *end; } *tasks; struct prio *next; } *priorities; } *waiting; struct queue *done; struct user *next; } *owner; unsigned int pid; int priority; char cmd[80]; } *


dropp

decompiled_code:
void __fastcall dropp(void *a1)
{
destroy(a1, 0);
}

canonical_decompiled_code:
void __fastcall func9(void *a1)
{
func2(a1, 0);
}

original_code:
void dropp(PriorityList * plist) {
    _destroy(plist,0);
}

canonical_original_code:
void dropp(struct prioritylist *plist) {
    _destroy(plist,0);
}


releasep

decompiled_code:
void __fastcall releasep(void *a1)
{
destroy(a1, 1);
}

canonical_decompiled_code:
void __fastcall func10(void *a1)
{
func2(a1, 1);
}

original_code:
void releasep(PriorityList * plist) {
    _destroy(plist,1);
}

canonical_original_code:
void releasep(struct prioritylist *plist) {
    _destroy(plist,1);
}


finduser

decompiled_code:
char *__fastcall finduser(char *s2, char *s1)
{
char *v2; // rbx

if ( !s1 )
return 0LL;
v2 = s2;
if ( !s2 )
return 0LL;
while ( strcmp(s1, v2) )
{
v2 = (char *)*((_QWORD *)v2 + 12);
if ( !v2 )
return 0LL;
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func1(char *s2, char *s1)
{
char *v2; // rbx

if ( !s1 )
return 0LL;
v2 = s2;
if ( !s2 )
return 0LL;
while ( strcmp(s1, v2) )
{
v2 = (char *)*((_QWORD *)v2 + 12);
if ( !v2 )
return 0LL;
}
return v2;
}

original_code:
TUser * finduser( TUser *ulist, char *name){
  if(!name)
    return ((void *)0);
  TUser * tmp = ulist;
  while(tmp){
    if(!strcmp(name,tmp->id))
      return tmp;
    tmp = tmp->next;
  }
  return ((void *)0);
}

canonical_original_code:
struct user *finduser(struct user *ulist, char *name){
  if(!name)
    return ((void *)0);
  struct user *tmp = ulist;
  while(tmp){
    if(!strcmp(name,tmp->id))
      return tmp;
    tmp = tmp->next;
  }
  return ((void *)0);
}

variable_types:
ulist
struct user *

variable_types:
name
char *

variable_types: struct user { char id[80]; struct prioritylist { struct prio { int priority; struct queue { struct node { struct task { struct user *owner; unsigned int pid; int priority; char cmd[80]; } *info; struct node *next; } *begin; struct node *end; } *tasks; struct prio *next; } *priorities; } *waiting; struct queue *done; struct user *next; } *