decompiled_code:
__int64 pad_do_prompt()
{
__int64 v1; // rdi
unsigned __int8 v2; // al
__int64 v3; // [rsp+0h] [rbp-28h] BYREF
char v4; // [rsp+8h] [rbp-20h]

scan_key(&v3, 17LL);
if ( (_DWORD)v3 == 1953066601 && !BYTE4(v3) )
{
pad_init();
return 1LL;
}
if ( (_DWORD)v3 == 1953719668 && !BYTE4(v3) )
{
if ( (unsigned __int8)pad_ping() )
goto LABEL_18;
goto LABEL_14;
}
if ( (_DWORD)v3 == 1735289200 && !BYTE4(v3) )
{
if ( !(unsigned __int8)pad_ping() )
{
LABEL_14:
print_err_nl();
return 1LL;
}
LABEL_18:
print_ok_nl();
return 1LL;
}
if ( (_DWORD)v3 == 1952543859 && WORD2(v3) == 101 )
{
v2 = pad_state();
if ( v2 == 0xFF )
goto LABEL_14;
goto LABEL_26;
}
if ( (_DWORD)v3 != 6579564 )
{
if ( (_DWORD)v3 == 1684368498 && !BYTE4(v3) )
{
pad_remote_led();
return 1LL;
}
if ( (_DWORD)v3 != 1684104562 || BYTE4(v3) )
{
if ( (_DWORD)v3 != 1953067639 || WORD2(v3) != 101 )
{
if ( v3 == 0x646165726F747561LL && !v4 )
pad_autoread();
return 1LL;
}
v1 = (unsigned __int8)scan_uint8();
if ( !(unsigned __int8)pad_write(v1) )
goto LABEL_14;
goto LABEL_18;
}
v2 = pad_read();
LABEL_26:
print_hb(0LL, v2);
print_nl();
return 1LL;
}
pad_led();
return 1LL;
}

original_code:
uint8_t pad_do_prompt() {
        char cmd[17];
        scan_key(cmd,17);
        if (strcmp(cmd,"init")==0) {
            pad_init();
            return 1;
        }
        if ((strcmp(cmd,"test")==0) || (strcmp(cmd,"ping")==0)) {
            if (pad_ping()) {
                print_ok_nl();
            } else {
                print_err_nl();
            }
            return 1;
        }
        if (strcmp(cmd,"state")==0) {
            uint8_t d = pad_state();
            if (d == 0xff) {
                print_err_nl();
            } else {
          print_hb(0,d);
                print_nl();
            }
            return 1;
        }
        if (strcmp(cmd,"led")==0) {
            pad_led();
            return 1;
        }
        if (strcmp(cmd,"rled")==0) {
            pad_remote_led();
            return 1;
        }
        if (strcmp(cmd,"read")==0) {
            uint8_t d = pad_read();
      print_hb(0,d);
            print_nl();
            return 1;
        }
        if (strcmp(cmd,"write")==0) {
      uint8_t v0 = scan_uint8();
            if (pad_write(v0)) {
                print_ok_nl();
            } else {
                print_err_nl();
            }
            return 1;
        }
        if (strcmp(cmd,"autoread")==0) {
            pad_autoread();
            return 1;
        }
        return 1;
}

canonical_original_code:
unsigned char pad_do_prompt() {
        char cmd[17];
        scan_key(cmd,17);
        if (strcmp(cmd,"init")==0) {
            pad_init();
            return 1;
        }
        if ((strcmp(cmd,"test")==0) || (strcmp(cmd,"ping")==0)) {
            if (pad_ping()) {
                print_ok_nl();
            } else {
                print_err_nl();
            }
            return 1;
        }
        if (strcmp(cmd,"state")==0) {
            unsigned char d = pad_state();
            if (d == 0xff) {
                print_err_nl();
            } else {
          print_hb(0,d);
                print_nl();
            }
            return 1;
        }
        if (strcmp(cmd,"led")==0) {
            pad_led();
            return 1;
        }
        if (strcmp(cmd,"rled")==0) {
            pad_remote_led();
            return 1;
        }
        if (strcmp(cmd,"read")==0) {
            unsigned char d = pad_read();
      print_hb(0,d);
            print_nl();
            return 1;
        }
        if (strcmp(cmd,"write")==0) {
      unsigned char v0 = scan_uint8();
            if (pad_write(v0)) {
                print_ok_nl();
            } else {
                print_err_nl();
            }
            return 1;
        }
        if (strcmp(cmd,"autoread")==0) {
            pad_autoread();
            return 1;
        }
        return 1;
}


repo: prcek/RFPad

decompiled_code:
__int64 scan_get_last_error()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 0LL;
}

original_code:
uint8_t scan_get_last_error() {
 return last_error;
}

canonical_original_code:
unsigned char scan_get_last_error() {
 return last_error;
}

return_type: unsigned char


decompiled_code:
int scan_gc()
{
int result; // eax

result = fgetc(stdin);
last_char = result;
return result;
}

canonical_decompiled_code:
int func1()
{
int result; // eax

result = fgetc(stdin);
last_char = result;
return result;
}

original_code:
uint8_t scan_gc() {
 last_char = fgetc(stdin);
 return last_char;
}

canonical_original_code:
unsigned char scan_gc() {
 last_char = fgetc(stdin);
 return last_char;
}


decompiled_code:
int scan_ungc()
{
return ungetc((unsigned __int8)last_char, stdin);
}

canonical_decompiled_code:
int func2()
{
return ungetc((unsigned __int8)last_char, stdin);
}

original_code:
void scan_ungc() {
 ungetc(last_char,stdin);
}

return_type: void


decompiled_code:
__int64 __fastcall scan_key(unsigned __int8 *a1, int a2)
{
const unsigned __int16 **v3; // r12
unsigned __int8 v4; // al
unsigned int v5; // er13
unsigned int v6; // ebp

v3 = _ctype_b_loc();
do
v4 = scan_gc();
while ( ((*v3)[v4] & 0x2000) != 0 );
v5 = a2 - 1;
v6 = 0;
while ( (_BYTE)v6 != (_BYTE)v5 )
{
*a1 = v4;
++v6;
++a1;
v4 = scan_gc();
if ( ((*v3)[v4] & 0x2000) != 0 )
{
v5 = v6;
scan_ungc();
break;
}
}
*a1 = 0;
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int8 *a1, int a2)
{
const unsigned __int16 **v3; // r12
unsigned __int8 v4; // al
unsigned int v5; // er13
unsigned int v6; // ebp

v3 = _ctype_b_loc();
do
v4 = func1();
while ( ((*v3)[v4] & 0x2000) != 0 );
v5 = a2 - 1;
v6 = 0;
while ( (_BYTE)v6 != (_BYTE)v5 )
{
*a1 = v4;
++v6;
++a1;
v4 = func1();
if ( ((*v3)[v4] & 0x2000) != 0 )
{
v5 = v6;
func2();
break;
}
}
*a1 = 0;
return v5;
}

original_code:
uint8_t scan_key(char *str, uint8_t max_len) {
 uint8_t c;
 uint8_t r = 0;
 do {
  c = scan_gc();
 } while(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISspace));
 while(--max_len) {
  r++;
  *str = c;
  str++;
  c = scan_gc();
  if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISspace)) {
   scan_ungc();
   break;
  }
 }
 *str = 0;
 return r;
}

canonical_original_code:
unsigned char scan_key(char *str, unsigned char max_len) {
 unsigned char c;
 unsigned char r = 0;
 do {
  c = scan_gc();
 } while(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISspace));
 while(--max_len) {
  r++;
  *str = c;
  str++;
  c = scan_gc();
  if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISspace)) {
   scan_ungc();
   break;
  }
 }
 *str = 0;
 return r;
}

variable_types:
str
char *

variable_types:
c
unsigned char

variable_types:
r
unsigned char


decompiled_code:
__int64 __fastcall is_hexdigit(int a1)
{
__int64 result; // rax
unsigned __int8 v2; // al
unsigned int v3; // edi
bool v4; // cf

result = (unsigned int)(a1 - 48);
if ( (unsigned __int8)(a1 - 48) > 9u )
{
if ( (unsigned __int8)(a1 - 97) <= 5u )
{
result = (unsigned int)(a1 - 87);
}
else
{
v2 = a1 - 65;
v3 = a1 - 55;
v4 = v2 < 6u;
result = 0xFFFFFFFFLL;
if ( v4 )
result = v3;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
__int64 result; // rax
unsigned __int8 v2; // al
unsigned int v3; // edi
bool v4; // cf

result = (unsigned int)(a1 - 48);
if ( (unsigned __int8)(a1 - 48) > 9u )
{
if ( (unsigned __int8)(a1 - 97) <= 5u )
{
result = (unsigned int)(a1 - 87);
}
else
{
v2 = a1 - 65;
v3 = a1 - 55;
v4 = v2 < 6u;
result = 0xFFFFFFFFLL;
if ( v4 )
result = v3;
}
}
return result;
}


decompiled_code:
__int64 scan_uint8()
{
const unsigned __int16 **v0; // rbx
int v1; // eax
unsigned __int16 v2; // dx
unsigned int v3; // er12
bool v4; // dl
unsigned __int8 i; // al
int v7; // eax

v0 = _ctype_b_loc();
do
{
v1 = scan_gc();
v2 = (*v0)[(unsigned __int8)v1];
}
while ( (v2 & 0x2000) != 0 );
if ( (v2 & 0x800) != 0 )
{
v3 = 0;
do
{
v3 = v1 + 10 * v3 - 48;
v1 = scan_gc();
}
while ( ((*v0)[(unsigned __int8)v1] & 0x800) != 0 );
v4 = (_BYTE)v3 == 0;
}
else
{
v4 = 1;
v3 = 0;
}
if ( (_BYTE)v1 == 120 && v4 )
{
v3 = 0;
for ( i = scan_gc(); ; i = scan_gc() )
{
v7 = is_hexdigit(i);
if ( (_BYTE)v7 == 0xFF )
break;
v3 = v7 + 16 * v3;
}
}
scan_ungc();
return v3;
}

original_code:
uint8_t scan_uint8() {
 uint8_t c;
 uint8_t r = 0;
 do {
  c = scan_gc();
 } while(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISspace));
 while(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISdigit)) {
  r = r*10+(c - '0');
  c = scan_gc();
 }
 if ((c=='x') && (r == 0)) {
  c = scan_gc();
  while( (c=is_hexdigit(c))!=255 ) {
   r = r*16+c;
   c = scan_gc();
  }
 }
 scan_ungc();
 return r;
}

canonical_original_code:
unsigned char scan_uint8() {
 unsigned char c;
 unsigned char r = 0;
 do {
  c = scan_gc();
 } while(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISspace));
 while(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISdigit)) {
  r = r*10+(c - '0');
  c = scan_gc();
 }
 if ((c=='x') && (r == 0)) {
  c = scan_gc();
  while( (c=is_hexdigit(c))!=255 ) {
   r = r*16+c;
   c = scan_gc();
  }
 }
 scan_ungc();
 return r;
}


decompiled_code:
__int64 scan_uint16()
{
const unsigned __int16 **v0; // rbx
unsigned __int8 v1; // al
unsigned int v2; // er12
bool v3; // dl
unsigned __int8 i; // al
unsigned __int8 v6; // al

v0 = _ctype_b_loc();
do
{
v1 = scan_gc();
v2 = (*v0)[v1];
}
while ( (v2 & 0x2000) != 0 );
LOWORD(v2) = v2 & 0x800;
if ( (_WORD)v2 )
{
v2 = 0;
do
{
v2 = v1 + 10 * v2 - 48;
v1 = scan_gc();
}
while ( ((*v0)[v1] & 0x800) != 0 );
v3 = (_WORD)v2 == 0;
}
else
{
v3 = 1;
}
if ( v1 == 120 && v3 )
{
v2 = 0;
for ( i = scan_gc(); ; i = scan_gc() )
{
v6 = is_hexdigit(i);
if ( v6 == 0xFF )
break;
v2 = v6 + 16 * v2;
}
}
scan_ungc();
return v2;
}

original_code:
uint16_t scan_uint16() {
 uint8_t c;
 uint16_t r = 0;
 do {
  c = scan_gc();
 } while(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISspace));
 while(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISdigit)) {
  r = r*10+(c - '0');
  c = scan_gc();
 }
 if ((c=='x') && (r == 0)) {
  c = scan_gc();
  while( (c=is_hexdigit(c))!=255 ) {
   r = r*16+c;
   c = scan_gc();
  }
 }
 scan_ungc();
 return r;
}

canonical_original_code:
unsigned short scan_uint16() {
 unsigned char c;
 unsigned short r = 0;
 do {
  c = scan_gc();
 } while(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISspace));
 while(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISdigit)) {
  r = r*10+(c - '0');
  c = scan_gc();
 }
 if ((c=='x') && (r == 0)) {
  c = scan_gc();
  while( (c=is_hexdigit(c))!=255 ) {
   r = r*16+c;
   c = scan_gc();
  }
 }
 scan_ungc();
 return r;
}

variable_types:
r
unsigned short

return_type: unsigned short


decompiled_code:
__int64 scan_test()
{
unsigned __int8 v0; // al
unsigned __int8 v1; // al
unsigned __int16 v2; // ax
unsigned __int16 v3; // ax

print("scan test, type 123: ");
v0 = scan_uint8();
print_db("value = ", v0);
print_nl();
print("type 0xff: ");
v1 = scan_uint8();
print_hb("value = ", v1);
print_nl();
print("type 12345: ");
v2 = scan_uint16();
print_dw("value = ", v2);
print_nl();
print("type 0x55AA: ");
v3 = scan_uint16();
print_hw("value = ", v3);
print_nl();
return print("ok, end of scan test\r\n");
}

canonical_decompiled_code:
__int64 func7()
{
unsigned __int8 v0; // al
unsigned __int8 v1; // al
unsigned __int16 v2; // ax
unsigned __int16 v3; // ax

print("scan test, type 123: ");
v0 = func5();
print_db("value = ", v0);
print_nl();
print("type 0xff: ");
v1 = func5();
print_hb("value = ", v1);
print_nl();
print("type 12345: ");
v2 = func6();
print_dw("value = ", v2);
print_nl();
print("type 0x55AA: ");
v3 = func6();
print_hw("value = ", v3);
print_nl();
return print("ok, end of scan test\r\n");
}

original_code:
void scan_test() {
 print("scan test, type 123: ");
 uint8_t v0 = scan_uint8();
 print_db("value = ", v0);
 print_nl();
 print("type 0xff: ");
 v0 = scan_uint8();
 print_hb("value = ", v0);
 print_nl();
 print("type 12345: ");
 uint16_t v1 = scan_uint16();
 print_dw("value = ", v1);
 print_nl();
 print("type 0x55AA: ");
 v1 = scan_uint16();
 print_hw("value = ", v1);
 print_nl();
 print("ok, end of scan test\r\n");
}

canonical_original_code:
void scan_test() {
 print("scan test, type 123: ");
 unsigned char v0 = scan_uint8();
 print_db("value = ", v0);
 print_nl();
 print("type 0xff: ");
 v0 = scan_uint8();
 print_hb("value = ", v0);
 print_nl();
 print("type 12345: ");
 unsigned short v1 = scan_uint16();
 print_dw("value = ", v1);
 print_nl();
 print("type 0x55AA: ");
 v1 = scan_uint16();
 print_hw("value = ", v1);
 print_nl();
 print("ok, end of scan test\r\n");
}


decompiled_code:
__int64 client_init()
{
char v0; // al
unsigned __int8 v1; // al

dbg_mode = 1;
cfg_client_id = eerd_b(21LL);
eerd_b(24LL);
v0 = eerd_b(25LL);
DDRC &= 0xC0u;
cfg_slot_rf_timeout = v0;
v1 = eerd_b(22LL);
cc_slot_set_len(v1);
cc_slot_set_top(18LL);
return cc_slot_set(0LL);
}

canonical_decompiled_code:
__int64 func0()
{
char v0; // al
unsigned __int8 v1; // al

dbg_mode = 1;
cfg_client_id = eerd_b(21LL);
eerd_b(24LL);
v0 = eerd_b(25LL);
DDRC &= 0xC0u;
cfg_slot_rf_timeout = v0;
v1 = eerd_b(22LL);
cc_slot_set_len(v1);
cc_slot_set_top(18LL);
return cc_slot_set(0LL);
}

original_code:
void client_init() {
 dbg_mode = 1;
 cfg_client_id = eerd_b(21);
 cfg_slot_rest_delay = eerd_b(24);
 cfg_slot_rf_timeout = eerd_b(25);
 DDRC &=~0x3f;
 cc_slot_set_len(eerd_b(22));
 cc_slot_set_top((2u+16u +1u)-1);
        cc_slot_set(0);
}


decompiled_code:
__int64 client_read_pad()
{
return PINC & 0x3F;
}

canonical_decompiled_code:
__int64 func1()
{
return PINC & 0x3F;
}

original_code:
uint8_t client_read_pad() {
 return PINC &0x3f;
}

canonical_original_code:
unsigned char client_read_pad() {
 return PINC &0x3f;
}


decompiled_code:
__int64 client_loop()
{
__int64 result; // rax
char v1; // bl
char v2; // bl
unsigned __int8 v3; // al
__int64 v4; // rsi

rf_prepare_for_recv();
if ( connected_2 )
{
if ( dbg_mode )
print_char(91LL);
cc_slot_wait(0LL);
result = rf_recv_packet((unsigned __int8)cfg_slot_rf_timeout);
v2 = result;
if ( dbg_mode )
{
result = print_char((unsigned __int8)(result + 48));
if ( v2 != 1 )
goto LABEL_12;
}
else if ( (_BYTE)result != 1 )
{
LABEL_12:
connected_2 = 0;
if ( !dbg_mode )
return result;
result = print_char(100LL);
goto LABEL_14;
}
result = rf_get_packet_v0();
if ( (_BYTE)result )
goto LABEL_31;
if ( dbg_mode )
print_char(115LL);
connected_2 = 1;
rf_get_packet_v1();
connected_2 = 1;
result = cc_slot_set(1LL);
LABEL_14:
if ( !connected_2 )
return result;
if ( !dbg_mode )
goto LABEL_21;
LABEL_16:
print_char(58LL);
LABEL_21:
rf_prepare_for_send();
cc_slot_wait((unsigned __int8)(cfg_client_id + 2));
v3 = client_read_pad();
v4 = (unsigned __int8)client_seq_0++;
rf_send_packet((unsigned __int8)(cfg_client_id + 0x80), v4, v3, (unsigned __int8)~v3);
if ( (unsigned __int8)cc_slot_get() != (unsigned __int8)cfg_client_id + 2 && dbg_mode )
print_char(94LL);
result = cc_slot_wait(18LL);
if ( dbg_mode )
result = print_char(93LL);
return result;
}
if ( dbg_mode )
print_char(63LL);
result = rf_recv_packet((unsigned __int16)(19 * (unsigned __int8)cfg_slot_rf_timeout));
v1 = result;
if ( dbg_mode )
result = print_char((unsigned __int8)(result + 48));
if ( v1 == 1 )
{
result = rf_get_packet_v0();
if ( !(_BYTE)result )
{
if ( dbg_mode )
print_char(115LL);
connected_2 = 1;
rf_get_packet_v1();
connected_2 = 1;
cc_slot_set(1LL);
if ( !dbg_mode )
goto LABEL_21;
goto LABEL_16;
}
LABEL_31:
if ( dbg_mode )
result = print_char(110LL);
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 result; // rax
char v1; // bl
char v2; // bl
unsigned __int8 v3; // al
__int64 v4; // rsi

rf_prepare_for_recv();
if ( connected_2 )
{
if ( dbg_mode )
print_char(91LL);
cc_slot_wait(0LL);
result = rf_recv_packet((unsigned __int8)cfg_slot_rf_timeout);
v2 = result;
if ( dbg_mode )
{
result = print_char((unsigned __int8)(result + 48));
if ( v2 != 1 )
goto LABEL_12;
}
else if ( (_BYTE)result != 1 )
{
LABEL_12:
connected_2 = 0;
if ( !dbg_mode )
return result;
result = print_char(100LL);
goto LABEL_14;
}
result = rf_get_packet_v0();
if ( (_BYTE)result )
goto LABEL_31;
if ( dbg_mode )
print_char(115LL);
connected_2 = 1;
rf_get_packet_v1();
connected_2 = 1;
result = cc_slot_set(1LL);
LABEL_14:
if ( !connected_2 )
return result;
if ( !dbg_mode )
goto LABEL_21;
LABEL_16:
print_char(58LL);
LABEL_21:
rf_prepare_for_send();
cc_slot_wait((unsigned __int8)(cfg_client_id + 2));
v3 = func1();
v4 = (unsigned __int8)client_seq_0++;
rf_send_packet((unsigned __int8)(cfg_client_id + 0x80), v4, v3, (unsigned __int8)~v3);
if ( (unsigned __int8)cc_slot_get() != (unsigned __int8)cfg_client_id + 2 && dbg_mode )
print_char(94LL);
result = cc_slot_wait(18LL);
if ( dbg_mode )
result = print_char(93LL);
return result;
}
if ( dbg_mode )
print_char(63LL);
result = rf_recv_packet((unsigned __int16)(19 * (unsigned __int8)cfg_slot_rf_timeout));
v1 = result;
if ( dbg_mode )
result = print_char((unsigned __int8)(result + 48));
if ( v1 == 1 )
{
result = rf_get_packet_v0();
if ( !(_BYTE)result )
{
if ( dbg_mode )
print_char(115LL);
connected_2 = 1;
rf_get_packet_v1();
connected_2 = 1;
cc_slot_set(1LL);
if ( !dbg_mode )
goto LABEL_21;
goto LABEL_16;
}
LABEL_31:
if ( dbg_mode )
result = print_char(110LL);
}
return result;
}

original_code:
void client_loop() {
 static uint8_t connected = 0;
 static uint8_t last_seq = 0;
 static uint8_t client_seq = 0;
 rf_prepare_for_recv();
 if (!connected) {
  if (dbg_mode) { print_char('?');};
  uint8_t rc = rf_recv_packet((2u+16u +1u)*cfg_slot_rf_timeout);
  if (dbg_mode) { print_char('0'+rc);};
  if (rc == 1) {
   if (rf_get_packet_v0()!=0) {
    if (dbg_mode) { print_char('n');};
    return;
   }
   if (dbg_mode) { print_char('s');};
   connected = 1;
   last_seq = rf_get_packet_v1();
   connected = 1;
   uint8_t srd = cfg_slot_rest_delay;
   while(srd--) {
   ;
   }
   cc_slot_set(1);
  } else {
   return;
  }
 } else {
  if (dbg_mode) { print_char('[');};
  cc_slot_wait(0);
  uint8_t rc = rf_recv_packet(cfg_slot_rf_timeout);
  if (dbg_mode) { print_char('0'+rc);};
  if (rc == 1) {
   if (rf_get_packet_v0()!=0) {
    if (dbg_mode) { print_char('n');};
    return;
   }
   if (dbg_mode) { print_char('s');};
   connected = 1;
   last_seq = rf_get_packet_v1();
   connected = 1;
   uint8_t srd = cfg_slot_rest_delay;
   while(srd--) {
   ;
   }
   cc_slot_set(1);
  } else {
   connected = 0;
   if (dbg_mode) { print_char('d');};
  }
  if (!connected) return;
 }
 if (dbg_mode) { print_char(':');};
 rf_prepare_for_send();
 cc_slot_wait(2u +cfg_client_id);
 uint8_t client_data0 = client_read_pad();
 uint8_t client_data1 = ~client_data0;
 rf_send_packet(0x80+cfg_client_id,client_seq++, client_data0, client_data1);
 if (cc_slot_get()!=(2u +cfg_client_id)) {
  if (dbg_mode) { print_char('^');};
 }
 cc_slot_wait(2u +16u);
 if (dbg_mode) { print_char(']');};
}

canonical_original_code:
void client_loop() {
 static unsigned char connected = 0;
 static unsigned char last_seq = 0;
 static unsigned char client_seq = 0;
 rf_prepare_for_recv();
 if (!connected) {
  if (dbg_mode) { print_char('?');};
  unsigned char rc = rf_recv_packet((2u+16u +1u)*cfg_slot_rf_timeout);
  if (dbg_mode) { print_char('0'+rc);};
  if (rc == 1) {
   if (rf_get_packet_v0()!=0) {
    if (dbg_mode) { print_char('n');};
    return;
   }
   if (dbg_mode) { print_char('s');};
   connected = 1;
   last_seq = rf_get_packet_v1();
   connected = 1;
   unsigned char srd = cfg_slot_rest_delay;
   while(srd--) {
   ;
   }
   cc_slot_set(1);
  } else {
   return;
  }
 } else {
  if (dbg_mode) { print_char('[');};
  cc_slot_wait(0);
  unsigned char rc = rf_recv_packet(cfg_slot_rf_timeout);
  if (dbg_mode) { print_char('0'+rc);};
  if (rc == 1) {
   if (rf_get_packet_v0()!=0) {
    if (dbg_mode) { print_char('n');};
    return;
   }
   if (dbg_mode) { print_char('s');};
   connected = 1;
   last_seq = rf_get_packet_v1();
   connected = 1;
   unsigned char srd = cfg_slot_rest_delay;
   while(srd--) {
   ;
   }
   cc_slot_set(1);
  } else {
   connected = 0;
   if (dbg_mode) { print_char('d');};
  }
  if (!connected) return;
 }
 if (dbg_mode) { print_char(':');};
 rf_prepare_for_send();
 cc_slot_wait(2u +cfg_client_id);
 unsigned char client_data0 = client_read_pad();
 unsigned char client_data1 = ~client_data0;
 rf_send_packet(0x80+cfg_client_id,client_seq++, client_data0, client_data1);
 if (cc_slot_get()!=(2u +cfg_client_id)) {
  if (dbg_mode) { print_char('^');};
 }
 cc_slot_wait(2u +16u);
 if (dbg_mode) { print_char(']');};
}

variable_types:
connected
unsigned char

variable_types:
rc
unsigned char

variable_types:
srd
unsigned char


decompiled_code:
__int64 __fastcall client_check_for_server(unsigned __int8 a1)
{
char v1; // bp
char v2; // bl
unsigned int v3; // er12
char v4; // al

v1 = 0;
v2 = 0;
rf_tune_channel(a1);
while ( 1 )
{
v3 = rf_recv_packet(30LL);
if ( (_BYTE)v3 != 1 )
break;
v4 = rf_get_packet_v2();
if ( v2 )
{
if ( v4 != v1 )
return 0LL;
++v2;
++v1;
if ( v2 == 100 )
return v3;
}
else
{
v1 = v4 + 1;
v2 = 1;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int8 a1)
{
char v1; // bp
char v2; // bl
unsigned int v3; // er12
char v4; // al

v1 = 0;
v2 = 0;
rf_tune_channel(a1);
while ( 1 )
{
v3 = rf_recv_packet(30LL);
if ( (_BYTE)v3 != 1 )
break;
v4 = rf_get_packet_v2();
if ( v2 )
{
if ( v4 != v1 )
return 0LL;
++v2;
++v1;
if ( v2 == 100 )
return v3;
}
else
{
v1 = v4 + 1;
v2 = 1;
}
}
return 0LL;
}

original_code:
uint8_t client_check_for_server(uint8_t c) {
 rf_tune_channel(c);
 uint8_t it = 100;
 uint8_t ok = 0;
 uint8_t next_seq = 0;
 while(it--) {
  uint8_t rc = rf_recv_packet(30);
  if (rc == 1) {
   uint8_t seq = rf_get_packet_v2();
   if (ok==0) {
    next_seq = seq;
   } else if (next_seq!=seq) {
    return 0;
   }
   ok++;
   next_seq++;
  } else {
   return 0;
  }
 }
 return 1;
}

canonical_original_code:
unsigned char client_check_for_server(unsigned char c) {
 rf_tune_channel(c);
 unsigned char it = 100;
 unsigned char ok = 0;
 unsigned char next_seq = 0;
 while(it--) {
  unsigned char rc = rf_recv_packet(30);
  if (rc == 1) {
   unsigned char seq = rf_get_packet_v2();
   if (ok==0) {
    next_seq = seq;
   } else if (next_seq!=seq) {
    return 0;
   }
   ok++;
   next_seq++;
  } else {
   return 0;
  }
 }
 return 1;
}

variable_types:
it
unsigned char

variable_types:
ok
unsigned char

variable_types:
seq
unsigned char


decompiled_code:
__int64 client_autotune()
{
unsigned __int8 v0; // r12
const char *v1; // rdi
__int64 v2; // r13
__int64 v3; // rsi
unsigned int v4; // ebx
unsigned __int16 v5; // bp

v0 = rf_cfg_get_channel_count();
print_hw("autotune channels=");
v1 = ", bw = ";
v2 = (unsigned __int8)rf_cfg_get_channel_bw();
v3 = v2;
print_hb(", bw = ", v2);
print_nl();
rf_scan_start();
if ( v0 )
{
v4 = 0;
do
{
while ( 1 )
{
v5 = rf_scan_get_signal_level_at_channel(v4);
print_hb("channel ", v4);
rf_cfg_get_channel_f0(v4, (unsigned int)v2);
print_hw(", freq ");
v3 = v5;
v1 = " - sig_level ";
print_hw(" - sig_level ");
if ( v5 )
break;
++v4;
print_nl();
if ( v0 <= (unsigned __int8)v4 )
return rf_scan_stop(v1, v3);
}
rf_scan_stop(" - sig_level ", v5);
if ( (unsigned __int8)client_check_for_server(v4) )
{
v1 = " server detected";
print(" server detected");
}
else
{
v1 = " no server";
print(" no server");
}
++v4;
rf_scan_start();
print_nl();
}
while ( v0 > (unsigned __int8)v4 );
}
return rf_scan_stop(v1, v3);
}

canonical_decompiled_code:
__int64 func4()
{
unsigned __int8 v0; // r12
const char *v1; // rdi
__int64 v2; // r13
__int64 v3; // rsi
unsigned int v4; // ebx
unsigned __int16 v5; // bp

v0 = rf_cfg_get_channel_count();
print_hw("autotune channels=");
v1 = ", bw = ";
v2 = (unsigned __int8)rf_cfg_get_channel_bw();
v3 = v2;
print_hb(", bw = ", v2);
print_nl();
rf_scan_start();
if ( v0 )
{
v4 = 0;
do
{
while ( 1 )
{
v5 = rf_scan_get_signal_level_at_channel(v4);
print_hb("channel ", v4);
rf_cfg_get_channel_f0(v4, (unsigned int)v2);
print_hw(", freq ");
v3 = v5;
v1 = " - sig_level ";
print_hw(" - sig_level ");
if ( v5 )
break;
++v4;
print_nl();
if ( v0 <= (unsigned __int8)v4 )
return rf_scan_stop(v1, v3);
}
rf_scan_stop(" - sig_level ", v5);
if ( (unsigned __int8)func3(v4) )
{
v1 = " server detected";
print(" server detected");
}
else
{
v1 = " no server";
print(" no server");
}
++v4;
rf_scan_start();
print_nl();
}
while ( v0 > (unsigned __int8)v4 );
}
return rf_scan_stop(v1, v3);
}

original_code:
void client_autotune() {
 uint8_t channels = rf_cfg_get_channel_count();
 print_hw("autotune channels=", channels);
 uint8_t bw = rf_cfg_get_channel_bw();
 print_hb(", bw = ", bw);
 print_nl();
 rf_scan_start();
 uint8_t c;
 for(c=0; c<channels; c++) {
  uint16_t v = rf_scan_get_signal_level_at_channel(c);
  print_hb("channel ",c);
  uint16_t f = rf_cfg_get_channel_f0(c, bw);
  print_hw(", freq ",f);
  print_hw(" - sig_level ",v);
  if (v > 0) {
   rf_scan_stop();
   if (client_check_for_server(c)) {
    print(" server detected");
   } else {
    print(" no server");
   }
   rf_scan_start();
  }
  print_nl();
 }
 rf_scan_stop();
}

canonical_original_code:
void client_autotune() {
 unsigned char channels = rf_cfg_get_channel_count();
 print_hw("autotune channels=", channels);
 unsigned char bw = rf_cfg_get_channel_bw();
 print_hb(", bw = ", bw);
 print_nl();
 rf_scan_start();
 unsigned char c;
 for(c=0; c<channels; c++) {
  unsigned short v = rf_scan_get_signal_level_at_channel(c);
  print_hb("channel ",c);
  unsigned short f = rf_cfg_get_channel_f0(c, bw);
  print_hw(", freq ",f);
  print_hw(" - sig_level ",v);
  if (v > 0) {
   rf_scan_stop();
   if (client_check_for_server(c)) {
    print(" server detected");
   } else {
    print(" no server");
   }
   rf_scan_start();
  }
  print_nl();
 }
 rf_scan_stop();
}

variable_types:
channels
unsigned char

variable_types:
bw
unsigned char

variable_types:
v
unsigned short

variable_types:
f
unsigned short


decompiled_code:
__int64 __fastcall client_select_channel(unsigned __int8 a1)
{
unsigned __int8 v1; // r12
char v2; // bp
char v3; // bl
unsigned __int8 v4; // al
unsigned __int8 v5; // al
unsigned __int8 v6; // al
__int64 v7; // rsi

v1 = 0;
print_hb("setting channel ", a1);
v2 = 10;
rf_tune_channel(a1);
print_nl();
print("listening for server packet...");
do
{
v3 = rf_recv_packet(50LL);
print_char((unsigned __int8)(v3 + 48));
v4 = rf_get_packet_v0();
print_hb(" v0:", v4);
v5 = rf_get_packet_v1();
print_hb(" v1:", v5);
v6 = rf_get_packet_v2();
print_hb(" v2:", v6);
v7 = (unsigned __int8)rf_get_packet_v3();
print_hb(" v3:", v7);
print_nl();
v1 += v3 == 1;
--v2;
}
while ( v2 );
print_nl();
print_hb("result = ", v1);
return print_nl();
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int8 a1)
{
unsigned __int8 v1; // r12
char v2; // bp
char v3; // bl
unsigned __int8 v4; // al
unsigned __int8 v5; // al
unsigned __int8 v6; // al
__int64 v7; // rsi

v1 = 0;
print_hb("setting channel ", a1);
v2 = 10;
rf_tune_channel(a1);
print_nl();
print("listening for server packet...");
do
{
v3 = rf_recv_packet(50LL);
print_char((unsigned __int8)(v3 + 48));
v4 = rf_get_packet_v0();
print_hb(" v0:", v4);
v5 = rf_get_packet_v1();
print_hb(" v1:", v5);
v6 = rf_get_packet_v2();
print_hb(" v2:", v6);
v7 = (unsigned __int8)rf_get_packet_v3();
print_hb(" v3:", v7);
print_nl();
v1 += v3 == 1;
--v2;
}
while ( v2 );
print_nl();
print_hb("result = ", v1);
return print_nl();
}

original_code:
void client_select_channel(uint8_t c) {
 print_hb("setting channel ", c);
 rf_tune_channel(c);
 print_nl();
 print("listening for server packet...");
 uint8_t it = 10;
 uint8_t ok = 0;
 while(it--) {
  uint8_t rc = rf_recv_packet(50);
  print_char('0'+rc);
  print_hb(" v0:", rf_get_packet_v0());
  print_hb(" v1:", rf_get_packet_v1());
  print_hb(" v2:", rf_get_packet_v2());
  print_hb(" v3:", rf_get_packet_v3());
  print_nl();
  if (rc == 1) {
   ok++;
  }
 }
 print_nl();
 print_hb("result = ",ok);
 print_nl();
}

canonical_original_code:
void client_select_channel(unsigned char c) {
 print_hb("setting channel ", c);
 rf_tune_channel(c);
 print_nl();
 print("listening for server packet...");
 unsigned char it = 10;
 unsigned char ok = 0;
 while(it--) {
  unsigned char rc = rf_recv_packet(50);
  print_char('0'+rc);
  print_hb(" v0:", rf_get_packet_v0());
  print_hb(" v1:", rf_get_packet_v1());
  print_hb(" v2:", rf_get_packet_v2());
  print_hb(" v3:", rf_get_packet_v3());
  print_nl();
  if (rc == 1) {
   ok++;
  }
 }
 print_nl();
 print_hb("result = ",ok);
 print_nl();
}


decompiled_code:
void __noreturn client_autorun()
{
print("client autorun\n\r");
rf_client_hack();
client_init();
while ( 1 )
client_loop();
}

canonical_decompiled_code:
void __noreturn func6()
{
print("client autorun\n\r");
rf_client_hack();
func0();
while ( 1 )
func2();
}

original_code:
void client_autorun() {
 print("client autorun\n\r");
 rf_client_hack();
 client_init();
 while(!0) {
         client_loop();
        }
}


decompiled_code:
__int64 client_do_prompt()
{
int v1; // eax
int v2; // ebx
const char *v3; // rdi
__int64 v4; // rbp
unsigned __int8 v5; // al
unsigned __int8 v6; // al
unsigned __int8 v7; // al
__int64 v8; // [rsp+0h] [rbp-38h] BYREF
int v9; // [rsp+8h] [rbp-30h]

scan_key(&v8, 17LL);
if ( (_DWORD)v8 == 1953066601 && !BYTE4(v8) )
{
client_init();
print_ok_nl();
return 1LL;
}
if ( (_DWORD)v8 == 1886351212 && !BYTE4(v8) )
{
v1 = scan_uint16();
v2 = v1 - 1;
if ( !(_WORD)v1 )
{
print("client loop....");
while ( 1 )
client_loop();
}
do
{
--v2;
print_char(46LL);
client_loop();
}
while ( (_WORD)v2 != 0xFFFF );
return 1LL;
}
if ( v8 == 0x656E75746F747561LL && !(_BYTE)v9 )
{
client_autotune();
return 1LL;
}
if ( v8 != 0x6C656E6E616863LL )
{
if ( (_DWORD)v8 == 1667590243 && WORD2(v8) == 107 )
{
v6 = scan_uint8();
if ( (unsigned __int8)client_check_for_server(v6) )
print("ok\r\n");
else
print("fail\r\n");
}
else
{
if ( (_DWORD)v8 == 6578544 )
{
v3 = 0LL;
v4 = (unsigned __int8)client_read_pad(0LL);
print_hb(0LL, v4);
while ( 1 )
{
v5 = client_read_pad(v3);
while ( (_BYTE)v4 == v5 )
;
v3 = " ";
LOBYTE(v4) = v5;
print_hb(" ", v5);
}
}
if ( v8 == 0x74735F7465736572LL && v9 == 7566433 )
{
stats_ok = 0;
stats_inv_seq = 0;
stats_bad_crc = 0;
stats_timeout = 0;
print("stat reset ok");
}
else if ( (_DWORD)v8 == 1952543859 && WORD2(v8) == 115 )
{
print_dw("ok: ", (unsigned __int16)stats_ok);
print_dw(" inv_seq: ", (unsigned __int16)stats_inv_seq);
print_dw(" bad_crc: ", (unsigned __int16)stats_bad_crc);
print_dw(" timeout: ", (unsigned __int16)stats_timeout);
print_nl();
}
}
return 1LL;
}
v7 = scan_uint8();
client_select_channel(v7);
return 1LL;
}

canonical_decompiled_code:
__int64 func7()
{
int v1; // eax
int v2; // ebx
const char *v3; // rdi
__int64 v4; // rbp
unsigned __int8 v5; // al
unsigned __int8 v6; // al
unsigned __int8 v7; // al
__int64 v8; // [rsp+0h] [rbp-38h] BYREF
int v9; // [rsp+8h] [rbp-30h]

scan_key(&v8, 17LL);
if ( (_DWORD)v8 == 1953066601 && !BYTE4(v8) )
{
func0();
print_ok_nl();
return 1LL;
}
if ( (_DWORD)v8 == 1886351212 && !BYTE4(v8) )
{
v1 = scan_uint16();
v2 = v1 - 1;
if ( !(_WORD)v1 )
{
print("client loop....");
while ( 1 )
func2();
}
do
{
--v2;
print_char(46LL);
func2();
}
while ( (_WORD)v2 != 0xFFFF );
return 1LL;
}
if ( v8 == 0x656E75746F747561LL && !(_BYTE)v9 )
{
func4();
return 1LL;
}
if ( v8 != 0x6C656E6E616863LL )
{
if ( (_DWORD)v8 == 1667590243 && WORD2(v8) == 107 )
{
v6 = scan_uint8();
if ( (unsigned __int8)func3(v6) )
print("ok\r\n");
else
print("fail\r\n");
}
else
{
if ( (_DWORD)v8 == 6578544 )
{
v3 = 0LL;
v4 = (unsigned __int8)func1(0LL);
print_hb(0LL, v4);
while ( 1 )
{
v5 = func1(v3);
while ( (_BYTE)v4 == v5 )
;
v3 = " ";
LOBYTE(v4) = v5;
print_hb(" ", v5);
}
}
if ( v8 == 0x74735F7465736572LL && v9 == 7566433 )
{
stats_ok = 0;
stats_inv_seq = 0;
stats_bad_crc = 0;
stats_timeout = 0;
print("stat reset ok");
}
else if ( (_DWORD)v8 == 1952543859 && WORD2(v8) == 115 )
{
print_dw("ok: ", (unsigned __int16)stats_ok);
print_dw(" inv_seq: ", (unsigned __int16)stats_inv_seq);
print_dw(" bad_crc: ", (unsigned __int16)stats_bad_crc);
print_dw(" timeout: ", (unsigned __int16)stats_timeout);
print_nl();
}
}
return 1LL;
}
v7 = scan_uint8();
func5(v7);
return 1LL;
}

original_code:
uint8_t client_do_prompt() {
        char cmd[17];
        scan_key(cmd,17);
        if (strcmp(cmd,"init")==0) {
                        client_init();
   print_ok_nl();
                        return 1;
        }
        if (strcmp(cmd,"loop")==0) {
                        uint16_t count = scan_uint16();
                        if (count == 0) {
                                print("client loop....");
                                while(!0) {
                                        client_loop();
                                }
                                print("   end\n\r");
                        } else {
                                while(count--) {
                                        print_char('.');
                                        client_loop();
                                }
                        }
                        return 1;
        }
 if (strcmp(cmd,"autotune")==0) {
   client_autotune();
   return 1;
 }
 if (strcmp(cmd,"channel")==0) {
   uint8_t c = scan_uint8();
   client_select_channel(c);
   return 1;
 }
 if (strcmp(cmd,"check")==0) {
   uint8_t c = scan_uint8();
   if (client_check_for_server(c)) {
    print("ok\r\n");
   } else {
    print("fail\r\n");
   }
   return 1;
 }
 if (strcmp(cmd,"pad")==0) {
  uint8_t l = client_read_pad();
  print_hb(0,l);
  while(!0) {
   uint8_t d = client_read_pad();
   if (d!=l) {
    l = d;
    print_hb(" ", d);
   }
  }
  return 1;
 }
 if (strcmp(cmd,"reset_stats")==0) {
  stats_ok = 0;
  stats_inv_seq = 0;
  stats_bad_crc = 0;
  stats_timeout = 0;
  print("stat reset ok");
  return 1;
 }
 if (strcmp(cmd,"stats")==0) {
  print_dw("ok: ", stats_ok);
  print_dw(" inv_seq: ", stats_inv_seq);
  print_dw(" bad_crc: ", stats_bad_crc);
  print_dw(" timeout: ", stats_timeout);
  print_nl();
  return 1;
 }
        return 1;
}

canonical_original_code:
unsigned char client_do_prompt() {
        char cmd[17];
        scan_key(cmd,17);
        if (strcmp(cmd,"init")==0) {
                        client_init();
   print_ok_nl();
                        return 1;
        }
        if (strcmp(cmd,"loop")==0) {
                        unsigned short count = scan_uint16();
                        if (count == 0) {
                                print("client loop....");
                                while(!0) {
                                        client_loop();
                                }
                                print("   end\n\r");
                        } else {
                                while(count--) {
                                        print_char('.');
                                        client_loop();
                                }
                        }
                        return 1;
        }
 if (strcmp(cmd,"autotune")==0) {
   client_autotune();
   return 1;
 }
 if (strcmp(cmd,"channel")==0) {
   unsigned char c = scan_uint8();
   client_select_channel(c);
   return 1;
 }
 if (strcmp(cmd,"check")==0) {
   unsigned char c = scan_uint8();
   if (client_check_for_server(c)) {
    print("ok\r\n");
   } else {
    print("fail\r\n");
   }
   return 1;
 }
 if (strcmp(cmd,"pad")==0) {
  unsigned char l = client_read_pad();
  print_hb(0,l);
  while(!0) {
   unsigned char d = client_read_pad();
   if (d!=l) {
    l = d;
    print_hb(" ", d);
   }
  }
  return 1;
 }
 if (strcmp(cmd,"reset_stats")==0) {
  stats_ok = 0;
  stats_inv_seq = 0;
  stats_bad_crc = 0;
  stats_timeout = 0;
  print("stat reset ok");
  return 1;
 }
 if (strcmp(cmd,"stats")==0) {
  print_dw("ok: ", stats_ok);
  print_dw(" inv_seq: ", stats_inv_seq);
  print_dw(" bad_crc: ", stats_bad_crc);
  print_dw(" timeout: ", stats_timeout);
  print_nl();
  return 1;
 }
        return 1;
}

variable_types:
cmd
char [17]

variable_types:
count
unsigned short

variable_types:
l
unsigned char

variable_types:
d
unsigned char


decompiled_code:
__int64 set_print_info()
{
unsigned __int8 v0; // al
unsigned __int8 v1; // al
unsigned __int8 v2; // al
unsigned __int8 v3; // al
unsigned __int8 v4; // al
unsigned __int8 v5; // al

v0 = eerd_b(20LL);
print_hb("auto mode (0:client, 1:server) = ", v0);
print_nl();
v1 = eerd_b(22LL);
print_hb("slot_size (in ms) = ", v1);
print_nl();
v2 = eerd_b(23LL);
print_hb("slot_count (clients = slots-3) = ", v2);
print_nl();
v3 = eerd_b(24LL);
print_hb("slot_rest_delay (in 50us) = ", v3);
print_nl();
v4 = eerd_b(25LL);
print_hb("slot_rf_timeout (in 20us) = ", v4);
print_nl();
v5 = eerd_b(21LL);
print_hb("client_id = ", v5);
return print_nl();
}

canonical_decompiled_code:
__int64 func0()
{
unsigned __int8 v0; // al
unsigned __int8 v1; // al
unsigned __int8 v2; // al
unsigned __int8 v3; // al
unsigned __int8 v4; // al
unsigned __int8 v5; // al

v0 = eerd_b(20LL);
print_hb("auto mode (0:client, 1:server) = ", v0);
print_nl();
v1 = eerd_b(22LL);
print_hb("slot_size (in ms) = ", v1);
print_nl();
v2 = eerd_b(23LL);
print_hb("slot_count (clients = slots-3) = ", v2);
print_nl();
v3 = eerd_b(24LL);
print_hb("slot_rest_delay (in 50us) = ", v3);
print_nl();
v4 = eerd_b(25LL);
print_hb("slot_rf_timeout (in 20us) = ", v4);
print_nl();
v5 = eerd_b(21LL);
print_hb("client_id = ", v5);
return print_nl();
}

original_code:
void set_print_info() {
 uint8_t mode = eerd_b(20);
 print_hb("auto mode (0:client, 1:server) = ",mode);
 print_nl();
 uint8_t slot_size = eerd_b(22);
 print_hb("slot_size (in ms) = ",slot_size);
 print_nl();
 uint8_t slot_count = eerd_b(23);
 print_hb("slot_count (clients = slots-3) = ",slot_count);
 print_nl();
 uint8_t slot_rest_delay = eerd_b(24);
 print_hb("slot_rest_delay (in 50us) = ",slot_rest_delay);
 print_nl();
 uint8_t slot_rf_timeout = eerd_b(25);
 print_hb("slot_rf_timeout (in 20us) = ",slot_rf_timeout);
 print_nl();
 uint8_t cid = eerd_b(21);
 print_hb("client_id = ",cid);
 print_nl();
}

canonical_original_code:
void set_print_info() {
 unsigned char mode = eerd_b(20);
 print_hb("auto mode (0:client, 1:server) = ",mode);
 print_nl();
 unsigned char slot_size = eerd_b(22);
 print_hb("slot_size (in ms) = ",slot_size);
 print_nl();
 unsigned char slot_count = eerd_b(23);
 print_hb("slot_count (clients = slots-3) = ",slot_count);
 print_nl();
 unsigned char slot_rest_delay = eerd_b(24);
 print_hb("slot_rest_delay (in 50us) = ",slot_rest_delay);
 print_nl();
 unsigned char slot_rf_timeout = eerd_b(25);
 print_hb("slot_rf_timeout (in 20us) = ",slot_rf_timeout);
 print_nl();
 unsigned char cid = eerd_b(21);
 print_hb("client_id = ",cid);
 print_nl();
}

variable_types:
mode
unsigned char

variable_types:
cid
unsigned char


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


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


decompiled_code:
char do_prompt()
{
char result; // al
int v1; // [rsp+6h] [rbp-12h] BYREF
__int16 v2; // [rsp+Ah] [rbp-Eh]
char v3; // [rsp+Ch] [rbp-Ch]

print(">");
scan_key(&v1, 10LL);
if ( (_WORD)v1 == 26226 && !BYTE2(v1) )
return rf_do_prompt();
if ( (_WORD)v1 == 28521 && !BYTE2(v1) )
return io_do_prompt();
if ( v1 != 1953719668 || (_BYTE)v2 )
{
if ( v1 == 1701669236 && v2 == 114 )
{
result = timer_do_prompt();
}
else if ( v1 == 1987208563 && v2 == 29285 && !v3 )
{
result = server_do_prompt();
}
else if ( v1 == 1701407843 && v2 == 29806 && !v3 )
{
result = client_do_prompt();
}
else if ( v1 == 7628147 )
{
result = set_do_prompt();
}
else if ( v1 == 6578544 )
{
result = pad_do_prompt();
}
else
{
result = (_WORD)v1 != 46;
}
}
else
{
print_test();
scan_test();
result = 1;
}
return result;
}

canonical_decompiled_code:
char func3()
{
char result; // al
int v1; // [rsp+6h] [rbp-12h] BYREF
__int16 v2; // [rsp+Ah] [rbp-Eh]
char v3; // [rsp+Ch] [rbp-Ch]

print(">");
scan_key(&v1, 10LL);
if ( (_WORD)v1 == 26226 && !BYTE2(v1) )
return rf_do_prompt();
if ( (_WORD)v1 == 28521 && !BYTE2(v1) )
return io_do_prompt();
if ( v1 != 1953719668 || (_BYTE)v2 )
{
if ( v1 == 1701669236 && v2 == 114 )
{
result = timer_do_prompt();
}
else if ( v1 == 1987208563 && v2 == 29285 && !v3 )
{
result = server_do_prompt();
}
else if ( v1 == 1701407843 && v2 == 29806 && !v3 )
{
result = client_do_prompt();
}
else if ( v1 == 7628147 )
{
result = func1();
}
else if ( v1 == 6578544 )
{
result = pad_do_prompt();
}
else
{
result = (_WORD)v1 != 46;
}
}
else
{
print_test();
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]


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(':');
 }
}


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

v0 = 2;
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);
do
{
cc_slot_wait(v0);
server_read_client(v0 - 2);
if ( (unsigned __int8)cc_slot_get() != (_BYTE)v0 )
print_char(94LL);
++v0;
}
while ( v0 != 18 );
cc_slot_wait(18LL);
return print_char(93LL);
}

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

v0 = 2;
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);
do
{
cc_slot_wait(v0);
func1(v0 - 2);
if ( (unsigned __int8)cc_slot_get() != (_BYTE)v0 )
print_char(94LL);
++v0;
}
while ( v0 != 18 );
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()
{
__int64 result; // rax
int v1; // eax
int v2; // ebx
int v3; // [rsp+0h] [rbp-28h] BYREF
char v4; // [rsp+4h] [rbp-24h]

scan_key(&v3, 17LL);
if ( v3 != 1953066601 || v4 )
{
if ( v3 == 1886351212 && !v4 )
{
v1 = scan_uint16();
v2 = v1 - 1;
if ( !(_WORD)v1 )
{
timer_get_sec();
print("server loop....");
while ( 1 )
server_loop();
}
do
{
--v2;
print_char(46LL);
server_loop();
}
while ( (_WORD)v2 != 0xFFFF );
}
result = 1LL;
}
else
{
server_init();
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 result; // rax
int v1; // eax
int v2; // ebx
int v3; // [rsp+0h] [rbp-28h] BYREF
char v4; // [rsp+4h] [rbp-24h]

scan_key(&v3, 17LL);
if ( v3 != 1953066601 || v4 )
{
if ( v3 == 1886351212 && !v4 )
{
v1 = scan_uint16();
v2 = v1 - 1;
if ( !(_WORD)v1 )
{
timer_get_sec();
print("server loop....");
while ( 1 )
func2();
}
do
{
--v2;
print_char(46LL);
func2();
}
while ( (_WORD)v2 != 0xFFFF );
}
result = 1LL;
}
else
{
func0();
result = 1LL;
}
return result;
}

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


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 *v4; // rsi
int v5; // eax
const char *v7; // rsi

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

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

func0(argc, 1, "need at least the command name");
v4 = argv[1];
v5 = *(unsigned __int8 *)v4;
if ( v5 == 99 && v4[1] == 102 && !v4[2] )
{
func0(argc, 2, "cf 'feature branch name'");
createFeatureBranch(argv[2]);
func1();
}
if ( v5 == 109 && v4[1] == 102 && !v4[2] )
{
func0(argc, 2, "mf 'feature branch name'");
mergeFeatureBranch(argv[2]);
func1();
}
if ( v5 == 99 && v4[1] == 114 && !v4[2] )
{
func0(argc, 3, "cr 'release version name' 'version bump script'");
createReleaseBranch(argv[2], argv[3]);
func1();
}
if ( v5 == 109 && v4[1] == 114 && !v4[2] )
{
func0(argc, 2, "mr 'release version name'");
mergeReleaseBranch(argv[2]);
func1();
}
if ( v5 == 99 && v4[1] == 104 && !v4[2] )
{
func0(argc, 3, "mr 'hotfix version name' 'version bump script'");
createHotfixBranch(argv[2], argv[3]);
func1();
}
if ( v5 == 109 && v4[1] == 104 && !v4[2] )
{
func0(argc, 2, "mh 'hotfix version name' ['release version name']");
v7 = 0LL;
if ( argc == 4 )
v7 = argv[3];
mergeHotfixBranch(argv[2], v7);
func1();
}
printf("unknown command '%s'\n", v4);
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)
{
char v3[1008]; // [rsp+0h] [rbp-7F8h] BYREF
char v4[1032]; // [rsp+3F0h] [rbp-408h] BYREF

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

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

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

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


main

repo: priitj/whitedb

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
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",
(const char *)argv,
envp);
if ( (unsigned int)__isoc99_sscanf() == 3 )
errhalt("nonnumeric or zero port given", "http://%99[^:]:%i/%999[^\n]");
errhalt("could not parse the url", "http://%99[^:]:%i/%999[^\n]");
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
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",
(const char *)argv,
envp);
if ( (unsigned int)__isoc99_sscanf() == 3 )
func10("nonnumeric or zero port given", "http://%99[^:]:%i/%999[^\n]");
func10("could not parse the url", "http://%99[^:]:%i/%999[^\n]");
}

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


readn

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;
v5 = n;
if ( n )
{
while ( 1 )
{
while ( 1 )
{
v6 = recv(fd, buf, v5, 0);
if ( v6 >= 0 )
break;
if ( *__errno_location() != 4 )
return -1LL;
}
if ( !v6 )
break;
buf = (char *)buf + v6;
v5 -= v6;
if ( !v5 )
return v3;
}
v3 -= v5;
}
return v3;
}

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;
v5 = n;
if ( n )
{
while ( 1 )
{
while ( 1 )
{
v6 = recv(fd, buf, v5, 0);
if ( v6 >= 0 )
break;
if ( *__errno_location() != 4 )
return -1LL;
}
if ( !v6 )
break;
buf = (char *)buf + v6;
v5 -= v6;
if ( !v5 )
return v3;
}
v3 -= v5;
}
return v3;
}

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, const char *a2)
{
printf("Error: %s\n", a1);
exit(-1);
}

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

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

variable_types:
str
char *