decompiled_code:
__int64 __fastcall bt_serial_close(const struct termios *a1)
{
__int64 result; // rax

if ( tcsetattr(a1[8].c_ospeed, 2, a1 + 9) < 0 )
{
error_str("Could not restore TTY settings");
close(a1[8].c_ospeed);
result = 0LL;
}
else
{
close(a1[8].c_ospeed);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const struct termios *a1)
{
__int64 result; // rax

if ( tcsetattr(a1[8].c_ospeed, 2, a1 + 9) < 0 )
{
error_str("Could not restore TTY settings");
close(a1[8].c_ospeed);
result = 0LL;
}
else
{
close(a1[8].c_ospeed);
result = 1LL;
}
return result;
}

original_code:
int bt_serial_close(bt_dev_t *dev) {
   if (tcsetattr(dev->ttyfd, 2, &dev->save_termios) < 0) {
      error_str(("Could not restore TTY settings"));
      close(dev->ttyfd);
      return 0;
   }
   close(dev->ttyfd);
   return 1;
}

canonical_original_code:
int bt_serial_close(struct bt_dev_s *dev) {
   if (tcsetattr(dev->ttyfd, 2, &dev->save_termios) < 0) {
      error_str(("Could not restore TTY settings"));
      close(dev->ttyfd);
      return 0;
   }
   close(dev->ttyfd);
   return 1;
}


repo: wesen/avr-bt-stack

decompiled_code:
__int64 __fastcall bt_serial_send(__int64 a1, unsigned __int8 *a2, int a3)
{
unsigned __int8 *v4; // rbx
int v5; // ebx
int v6; // eax

printf("Send to serial: ");
if ( a3 <= 0 )
{
putchar(10);
v5 = 0;
}
else
{
v4 = a2;
do
printf("%x, ", *v4++);
while ( v4 != &a2[a3 - 1 + 1] );
putchar(10);
v5 = 0;
while ( 1 )
{
v6 = write(*(_DWORD *)(a1 + 536), &a2[v5], 1uLL);
if ( v6 < 0 )
break;
v5 += v6;
if ( a3 <= v5 )
return (unsigned int)v5;
}
v5 = -1;
}
return (unsigned int)v5;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned __int8 *a2, int a3)
{
unsigned __int8 *v4; // rbx
int v5; // ebx
int v6; // eax

printf("Send to serial: ");
if ( a3 <= 0 )
{
putchar(10);
v5 = 0;
}
else
{
v4 = a2;
do
printf("%x, ", *v4++);
while ( v4 != &a2[a3 - 1 + 1] );
putchar(10);
v5 = 0;
while ( 1 )
{
v6 = write(*(_DWORD *)(a1 + 536), &a2[v5], 1uLL);
if ( v6 < 0 )
break;
v5 += v6;
if ( a3 <= v5 )
return (unsigned int)v5;
}
v5 = -1;
}
return (unsigned int)v5;
}

original_code:
int bt_serial_send(bt_dev_t *dev, unsigned char *buf, int len) {
   int tlen = 0, wlen;
   int i;
   printf("Send to serial: ");
   for (i = 0; i < len; i++) {
      printf("%x, ", buf[i]);
   }
   printf("\n");
   while (tlen < len) {
      if ((wlen = write(dev->ttyfd, (void *)(buf + tlen), 1)) < 0)
         return -1;
      tlen += wlen;
   }
   return tlen;
}

canonical_original_code:
int bt_serial_send(struct bt_dev_s *dev, unsigned char *buf, int len) {
   int tlen = 0; int wlen;
   int i;
   printf("Send to serial: ");
   for (i = 0; i < len; i++) {
      printf("%x, ", buf[i]);
   }
   printf("\n");
   while (tlen < len) {
      if ((wlen = write(dev->ttyfd, (void *)(buf + tlen), 1)) < 0)
         return -1;
      tlen += wlen;
   }
   return tlen;
}

variable_types: struct bt_dev_s { unsigned char state; unsigned char ncmds; unsigned char buf[256]; char name[32]; unsigned short pkt_type; struct bt_peer_s { unsigned char state; unsigned char bd_addr[6]; unsigned short clock_offset; unsigned char pscan_rep_mode; } peers[3]; struct bt_acl_s { unsigned char state; unsigned short handle; unsigned short pkt_types; unsigned char max_slots; unsigned char encrypt_mode; struct bt_peer_s *peer; } acls[3]; char tty[128]; int ttyfd; struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; } save_termios; } *

variable_types:
buf
unsigned char *

variable_types: len int

variable_types: tlen int

variable_types: wlen int

variable_types: i int

return_type: int

user_defined_types: struct bt_dev_s { unsigned char state; unsigned char ncmds; unsigned char buf[256]; char name[32]; unsigned short pkt_type; struct bt_peer_s peers[3]; struct bt_acl_s acls[3]; char tty[128]; int ttyfd; struct termios save_termios; }


decompiled_code:
__int64 __fastcall bt_serial_read(__int64 a1, __int64 a2, int a3)
{
int v4; // er12
int v5; // ebx

printf("Read from serial: ");
if ( a3 <= 0 )
{
v4 = 0;
LABEL_5:
putchar(10);
}
else
{
v4 = 0;
while ( 1 )
{
v5 = read(*(_DWORD *)(a1 + 536), (void *)(a2 + v4), 1uLL);
if ( v5 <= 0 )
break;
printf("%x, ", *(unsigned __int8 *)(a2 + v4));
v4 += v5;
if ( a3 <= v4 )
goto LABEL_5;
}
v4 = -1;
}
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, int a3)
{
int v4; // er12
int v5; // ebx

printf("Read from serial: ");
if ( a3 <= 0 )
{
v4 = 0;
LABEL_5:
putchar(10);
}
else
{
v4 = 0;
while ( 1 )
{
v5 = read(*(_DWORD *)(a1 + 536), (void *)(a2 + v4), 1uLL);
if ( v5 <= 0 )
break;
printf("%x, ", *(unsigned __int8 *)(a2 + v4));
v4 += v5;
if ( a3 <= v4 )
goto LABEL_5;
}
v4 = -1;
}
return (unsigned int)v4;
}

original_code:
int bt_serial_read(bt_dev_t *dev, unsigned char *buf, int len) {
   int tlen = 0, rlen;
   printf("Read from serial: ");
   while (tlen < len) {
      if ((rlen = read(dev->ttyfd, (void *)(buf + tlen), 1)) <= 0)
         return -1;
      printf("%x, ", buf[tlen]);
      tlen += rlen;
   }
    printf("\n");
   return tlen;
}

canonical_original_code:
int bt_serial_read(struct bt_dev_s *dev, unsigned char *buf, int len) {
   int tlen = 0; int rlen;
   printf("Read from serial: ");
   while (tlen < len) {
      if ((rlen = read(dev->ttyfd, (void *)(buf + tlen), 1)) <= 0)
         return -1;
      printf("%x, ", buf[tlen]);
      tlen += rlen;
   }
    printf("\n");
   return tlen;
}

variable_types: rlen int

user_defined_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }

user_defined_types: struct bt_peer_s { unsigned char state; unsigned char bd_addr[6]; unsigned short clock_offset; unsigned char pscan_rep_mode; }

user_defined_types: struct bt_acl_s { unsigned char state; unsigned short handle; unsigned short pkt_types; unsigned char max_slots; unsigned char encrypt_mode; struct bt_peer_s *peer; }


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

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

original_code:
void io_str(char *s) {
   printf("DEBUG: %s\n", s);
}

variable_types:
s
char *

return_type: void


decompiled_code:
int __fastcall io_int(unsigned int a1)
{
return printf("DEBUG: 0x%x\n", a1);
}

canonical_decompiled_code:
int __fastcall func1(unsigned int a1)
{
return printf("DEBUG: 0x%x\n", a1);
}

original_code:
void io_int(int d) {
   printf("DEBUG: 0x%x\n", d);
}

variable_types: d int


decompiled_code:
int __fastcall error_str(const char *a1)
{
return fprintf(stderr, "ERROR: %s\n", a1);
}

canonical_decompiled_code:
int __fastcall func2(const char *a1)
{
return fprintf(stderr, "ERROR: %s\n", a1);
}

original_code:
void error_str(char *s) {
   fprintf(stderr, "ERROR: %s\n", s);
}


original_code:
void io_bd_addr(unsigned char *bd_addr) {
   printf("%x:%x:%x:%x:%x:%x\n",
         bd_addr[0], bd_addr[1], bd_addr[2],
         bd_addr[3], bd_addr[4], bd_addr[5]);
}


decompiled_code:
__int64 __fastcall bt_l2cap_unpack_cmd(__int64 a1)
{
char *v1; // rax
char v2; // bp
char v3; // r12
unsigned __int16 v4; // ax
__int64 result; // rax

v1 = *(char **)(a1 + 264);
*(_QWORD *)(a1 + 264) = v1 + 1;
v2 = *v1;
*(_QWORD *)(a1 + 264) = v1 + 2;
v3 = v1[1];
v4 = uint16_unpack__(a1 + 264);
switch ( v2 )
{
case 1:
if ( v3 == 1 )
{
result = v4 < 2u ? 18 : 1;
}
else if ( v3 == 2 )
{
result = v4 < 4u ? 18 : 2;
}
else
{
result = v3 != 0 ? 0x12 : 0;
}
break;
case 2:
result = v4 < 4u ? 18 : 3;
break;
case 3:
result = v4 < 8u ? 18 : 4;
break;
case 4:
result = v4 < 4u ? 18 : 5;
break;
case 5:
result = v4 < 8u ? 18 : 6;
break;
case 6:
result = v4 < 4u ? 18 : 7;
break;
case 7:
result = v4 < 4u ? 18 : 8;
break;
case 8:
bt_l2cap_pack_cmd(a1, 9, v3, 0);
bt_dev_flush_hci(a1);
result = 9LL;
break;
case 9:
result = 10LL;
break;
case 10:
result = v4 < 2u ? 18 : 11;
break;
case 11:
result = v4 < 4u ? 18 : 12;
break;
default:
result = 18LL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
char *v1; // rax
char v2; // bp
char v3; // r12
unsigned __int16 v4; // ax
__int64 result; // rax

v1 = *(char **)(a1 + 264);
*(_QWORD *)(a1 + 264) = v1 + 1;
v2 = *v1;
*(_QWORD *)(a1 + 264) = v1 + 2;
v3 = v1[1];
v4 = uint16_unpack__(a1 + 264);
switch ( v2 )
{
case 1:
if ( v3 == 1 )
{
result = v4 < 2u ? 18 : 1;
}
else if ( v3 == 2 )
{
result = v4 < 4u ? 18 : 2;
}
else
{
result = v3 != 0 ? 0x12 : 0;
}
break;
case 2:
result = v4 < 4u ? 18 : 3;
break;
case 3:
result = v4 < 8u ? 18 : 4;
break;
case 4:
result = v4 < 4u ? 18 : 5;
break;
case 5:
result = v4 < 8u ? 18 : 6;
break;
case 6:
result = v4 < 4u ? 18 : 7;
break;
case 7:
result = v4 < 4u ? 18 : 8;
break;
case 8:
bt_l2cap_pack_cmd(a1, 9, v3, 0);
bt_dev_flush_hci(a1);
result = 9LL;
break;
case 9:
result = 10LL;
break;
case 10:
result = v4 < 2u ? 18 : 11;
break;
case 11:
result = v4 < 4u ? 18 : 12;
break;
default:
result = 18LL;
break;
}
return result;
}

original_code:
bt_l2cap_evt_e bt_l2cap_unpack_cmd(bt_dev_t *dev) {
   unsigned char code, id;
   unsigned short len;
   code = (*(dev->ptr++));
   id = (*(dev->ptr++));
   len = uint16_unpack__(&dev->ptr);
   switch (code) {
      case 0x01:
         switch (id) {
            case 0:
               return l2cap_evt_cmd_rej_not_understood;
            case 1:
               if (len < 2) {
                  return l2cap_evt_garbage;
               } else {
                  return l2cap_evt_cmd_rej_mtu_exceeded;
               }
            case 2:
               if (len < 4) {
                  return l2cap_evt_garbage;
               } else {
                  return l2cap_evt_cmd_rej_cid_invalid;
               }
            default:
               return l2cap_evt_garbage;
         }
      case 0x02:
         if (len < 4) {
            return l2cap_evt_garbage;
         } else {
            return l2cap_evt_conn_req;
         }
      case 0x03:
         if (len < 8) {
            return l2cap_evt_garbage;
         } else {
            return l2cap_evt_conn_rsp;
         }
      case 0x04:
         if (len < 4) {
            return l2cap_evt_garbage;
         } else {
            return l2cap_evt_conf_req;
         }
      case 0x05:
         if (len < 8) {
            return l2cap_evt_garbage;
         } else {
            return l2cap_evt_conf_rsp;
         }
      case 0x06:
         if (len < 4) {
            return l2cap_evt_garbage;
         } else {
            return l2cap_evt_disconn_req;
         }
      case 0x07:
         if (len < 4) {
            return l2cap_evt_garbage;
         } else {
            return l2cap_evt_disconn_rsp;
         }
      case 0x08:
         bt_l2cap_pack_cmd(dev, 0x09, id, 0);
         bt_dev_flush_hci(dev);
         return l2cap_evt_echo_req;
      case 0x09:
         return l2cap_evt_echo_rsp;
      case 0x0a:
         if (len < 2) {
            return l2cap_evt_garbage;
         } else {
            return l2cap_evt_info_req;
         }
      case 0x0b:
         if (len < 4) {
            return l2cap_evt_garbage;
         } else {
            return l2cap_evt_info_rsp;
         }
      default:
         return l2cap_evt_garbage;
   }
}

canonical_original_code:
enum bt_l2cap_evt_e bt_l2cap_unpack_cmd(struct bt_dev_s *dev) {
   unsigned char code; unsigned char id;
   unsigned short len;
   code = (*(dev->ptr++));
   id = (*(dev->ptr++));
   len = uint16_unpack__(&dev->ptr);
   switch (code) {
      case 0x01:
         switch (id) {
            case 0:
               return l2cap_evt_cmd_rej_not_understood;
            case 1:
               if (len < 2) {
                  return l2cap_evt_garbage;
               } else {
                  return l2cap_evt_cmd_rej_mtu_exceeded;
               }
            case 2:
               if (len < 4) {
                  return l2cap_evt_garbage;
               } else {
                  return l2cap_evt_cmd_rej_cid_invalid;
               }
            default:
               return l2cap_evt_garbage;
         }
      case 0x02:
         if (len < 4) {
            return l2cap_evt_garbage;
         } else {
            return l2cap_evt_conn_req;
         }
      case 0x03:
         if (len < 8) {
            return l2cap_evt_garbage;
         } else {
            return l2cap_evt_conn_rsp;
         }
      case 0x04:
         if (len < 4) {
            return l2cap_evt_garbage;
         } else {
            return l2cap_evt_conf_req;
         }
      case 0x05:
         if (len < 8) {
            return l2cap_evt_garbage;
         } else {
            return l2cap_evt_conf_rsp;
         }
      case 0x06:
         if (len < 4) {
            return l2cap_evt_garbage;
         } else {
            return l2cap_evt_disconn_req;
         }
      case 0x07:
         if (len < 4) {
            return l2cap_evt_garbage;
         } else {
            return l2cap_evt_disconn_rsp;
         }
      case 0x08:
         bt_l2cap_pack_cmd(dev, 0x09, id, 0);
         bt_dev_flush_hci(dev);
         return l2cap_evt_echo_req;
      case 0x09:
         return l2cap_evt_echo_rsp;
      case 0x0a:
         if (len < 2) {
            return l2cap_evt_garbage;
         } else {
            return l2cap_evt_info_req;
         }
      case 0x0b:
         if (len < 4) {
            return l2cap_evt_garbage;
         } else {
            return l2cap_evt_info_rsp;
         }
      default:
         return l2cap_evt_garbage;
   }
}

variable_types:
code
unsigned char

variable_types:
id
unsigned char

variable_types:
len
unsigned short

return_type: enum bt_l2cap_evt_e { l2cap_evt_cmd_rej_not_understood=0, l2cap_evt_cmd_rej_mtu_exceeded=1, l2cap_evt_cmd_rej_cid_invalid=2, l2cap_evt_conn_req=3, l2cap_evt_conn_rsp=4, l2cap_evt_conf_req=5, l2cap_evt_conf_rsp=6, l2cap_evt_disconn_req=7, l2cap_evt_disconn_rsp=8, l2cap_evt_echo_req=9, l2cap_evt_echo_rsp=10, l2cap_evt_info_req=11, l2cap_evt_info_rsp=12, l2cap_evt_conn_data=13, l2cap_evt_connless_data=14, l2cap_evt_conf_mtu=15, l2cap_evt_conf_flush=16, l2cap_evt_conf_qos=17, l2cap_evt_garbage=18 }


decompiled_code:
__int64 __fastcall bt_l2cap_unpack(__int64 a1)
{
unsigned __int16 v1; // bp
unsigned __int16 v2; // ax
int v3; // edx
__int64 result; // rax

v1 = uint16_unpack__(a1 + 264);
v2 = uint16_unpack__(a1 + 264);
if ( v2 == 1 )
{
result = 18LL;
if ( v1 > 3u )
result = bt_l2cap_unpack_cmd(a1);
}
else
{
v3 = v2;
result = 14LL;
if ( v3 != 2 )
result = v3 == 0 ? 18 : 13;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
unsigned __int16 v1; // bp
unsigned __int16 v2; // ax
int v3; // edx
__int64 result; // rax

v1 = uint16_unpack__(a1 + 264);
v2 = uint16_unpack__(a1 + 264);
if ( v2 == 1 )
{
result = 18LL;
if ( v1 > 3u )
result = func0(a1);
}
else
{
v3 = v2;
result = 14LL;
if ( v3 != 2 )
result = v3 == 0 ? 18 : 13;
}
return result;
}

original_code:
bt_l2cap_evt_e bt_l2cap_unpack(bt_dev_t *dev) {
   unsigned short cid, len;
   len = uint16_unpack__(&dev->ptr);
   cid = uint16_unpack__(&dev->ptr);
   switch (cid) {
      case 0:
         return l2cap_evt_garbage;
      case 1:
         if (len < 4) {
            return l2cap_evt_garbage;
         } else {
            return bt_l2cap_unpack_cmd(dev);
         }
      case 2:
         return l2cap_evt_connless_data;
      default:
         return l2cap_evt_conn_data;
   }
}

canonical_original_code:
enum bt_l2cap_evt_e bt_l2cap_unpack(struct bt_dev_s *dev) {
   unsigned short cid; unsigned short len;
   len = uint16_unpack__(&dev->ptr);
   cid = uint16_unpack__(&dev->ptr);
   switch (cid) {
      case 0:
         return l2cap_evt_garbage;
      case 1:
         if (len < 4) {
            return l2cap_evt_garbage;
         } else {
            return bt_l2cap_unpack_cmd(dev);
         }
      case 2:
         return l2cap_evt_connless_data;
      default:
         return l2cap_evt_conn_data;
   }
}

variable_types:
cid
unsigned short

user_defined_types: enum bt_l2cap_evt_e { l2cap_evt_cmd_rej_not_understood=0, l2cap_evt_cmd_rej_mtu_exceeded=1, l2cap_evt_cmd_rej_cid_invalid=2, l2cap_evt_conn_req=3, l2cap_evt_conn_rsp=4, l2cap_evt_conf_req=5, l2cap_evt_conf_rsp=6, l2cap_evt_disconn_req=7, l2cap_evt_disconn_rsp=8, l2cap_evt_echo_req=9, l2cap_evt_echo_rsp=10, l2cap_evt_info_req=11, l2cap_evt_info_rsp=12, l2cap_evt_conn_data=13, l2cap_evt_connless_data=14, l2cap_evt_conf_mtu=15, l2cap_evt_conf_flush=16, l2cap_evt_conf_qos=17, l2cap_evt_garbage=18 }


decompiled_code:
__int64 __fastcall bt_l2cap_unpack_conf_option(__int64 a1)
{
char *v1; // rax
char v2; // dl
unsigned __int8 v3; // cl
__int64 result; // rax

v1 = *(char **)(a1 + 264);
*(_QWORD *)(a1 + 264) = v1 + 1;
v2 = *v1;
*(_QWORD *)(a1 + 264) = v1 + 2;
v3 = v1[1];
if ( v2 == 2 )
return v3 < 2u ? 18 : 16;
if ( v2 == 3 )
return (unsigned int)(v3 < 0x16u) + 17;
result = 18LL;
if ( v2 == 1 )
result = v3 < 2u ? 18 : 15;
return result;
}

original_code:
bt_l2cap_evt_e bt_l2cap_unpack_conf_option(bt_dev_t *dev) {
   unsigned char type, len;
   type = (*(dev->ptr++));
   len = (*(dev->ptr++));
   switch (type) {
      case 0x01:
         if (len < 2) {
            return l2cap_evt_garbage;
         } else {
            return l2cap_evt_conf_mtu;
         }
      case 0x02:
         if (len < 2) {
            return l2cap_evt_garbage;
         } else {
            return l2cap_evt_conf_flush;
         }
      case 0x03:
         if (len < 22) {
            return l2cap_evt_garbage;
         } else {
            return l2cap_evt_conf_qos;
         }
      default:
         return l2cap_evt_garbage;
   }
}

canonical_original_code:
enum bt_l2cap_evt_e bt_l2cap_unpack_conf_option(struct bt_dev_s *dev) {
   unsigned char type; unsigned char len;
   type = (*(dev->ptr++));
   len = (*(dev->ptr++));
   switch (type) {
      case 0x01:
         if (len < 2) {
            return l2cap_evt_garbage;
         } else {
            return l2cap_evt_conf_mtu;
         }
      case 0x02:
         if (len < 2) {
            return l2cap_evt_garbage;
         } else {
            return l2cap_evt_conf_flush;
         }
      case 0x03:
         if (len < 22) {
            return l2cap_evt_garbage;
         } else {
            return l2cap_evt_conf_qos;
         }
      default:
         return l2cap_evt_garbage;
   }
}

variable_types:
type
unsigned char

variable_types:
len
unsigned char


decompiled_code:
__int64 __fastcall uint16_unpack__(_QWORD *a1)
{
unsigned __int8 *v1; // rdx
int v2; // ecx

v1 = (unsigned __int8 *)(*a1)++;
v2 = *v1;
*a1 = v1 + 2;
return v2 | (v1[1] << 8);
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1)
{
unsigned __int8 *v1; // rdx
int v2; // ecx

v1 = (unsigned __int8 *)(*a1)++;
v2 = *v1;
*a1 = v1 + 2;
return v2 | (v1[1] << 8);
}

original_code:
unsigned int uint16_unpack__(unsigned char **ptr) {
   int i = *((*ptr)++);
   return (i |= *((*ptr)++) << 8);
}

variable_types:
ptr
unsigned char **

return_type: unsigned int


main

canonical_name: main

repo: wesgarland/gpsee

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
__int64 v5[2]; // [rsp+8h] [rbp-10h] BYREF

html_header(argc, argv, envp);
html_begin("Query Results");
v3 = read_cgi_input(v5);
printf("
Status = %d
\n", v3);
h1("Query results");
print_entries(v5[0]);
html_end();
list_clear(v5);
return 0;
}

original_code:
int main()
{
  llist entries;
  int status;
  html_header();
  html_begin("Query Results");
  status = read_cgi_input(&entries);
  printf("
Status = %d
\n",status);
  h1("Query results");
  print_entries(entries);
  html_end();
  list_clear(&entries);
  return 0;
}

canonical_original_code:
int main()
{
  struct llist entries;
  int status;
  html_header();
  html_begin("Query Results");
  status = read_cgi_input(&entries);
  printf("
Status = %d
\n",status);
  h1("Query results");
  print_entries(entries);
  html_end();
  list_clear(&entries);
  return 0;
}

variable_types: struct llist { struct _node { struct entrytype { char *name; char *value; } entry; struct _node *next; } *head; }

variable_types: status int

user_defined_types: struct _node { struct entrytype entry; struct _node *next; }


decompiled_code:
int html_header()
{
return puts("Content-type: text/html\n");
}

canonical_decompiled_code:
int func0()
{
return puts("Content-type: text/html\n");
}

original_code:
void html_header(void)
{
  printf("Content-type: text/html\n\n");
}

canonical_original_code:
void html_header()
{
  printf("Content-type: text/html\n\n");
}


decompiled_code:
int __fastcall mime_header(const char *a1)
{
return printf("Content-type: %s\n\n", a1);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1)
{
return printf("Content-type: %s\n\n", a1);
}

original_code:
void mime_header(char *mime)
{
  printf("Content-type: %s\n\n",mime);
}

variable_types:
mime
char *


decompiled_code:
int __fastcall nph_header(const char *a1)
{
printf("HTTP/1.0 %s\n", a1);
return puts("Server: CGI using cgihtml");
}

canonical_decompiled_code:
int __fastcall func2(const char *a1)
{
printf("HTTP/1.0 %s\n", a1);
return puts("Server: CGI using cgihtml");
}

original_code:
void nph_header(char *status)
{
  printf("HTTP/1.0 %s\n",status);
  printf("Server: CGI using cgihtml\n");
}

variable_types:
status
char *


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

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

original_code:
void show_html_page(char *loc)
{
  printf("Location: %s\n\n",loc);
}

variable_types:
loc
char *


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

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

original_code:
void http_status(char *status)
{
  printf("Status: %s\n",status);
}


pragma

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

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

original_code:
void pragma(char *msg)
{
  printf("Pragma: %s\n",msg);
}

variable_types:
msg
char *


decompiled_code:
int __fastcall set_cookie(const char *a1, const char *a2, const char *a3, const char *a4, const char *a5, __int16 a6)
{
printf("Set-Cookie: %s=%s;", a1, a2);
if ( a3 )
printf(" EXPIRES=%s;", a3);
if ( a4 )
printf(" PATH=%s;", a4);
if ( a5 )
printf(" DOMAIN=%s;", a5);
if ( a6 )
printf(" SECURE");
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func6(const char *a1, const char *a2, const char *a3, const char *a4, const char *a5, __int16 a6)
{
printf("Set-Cookie: %s=%s;", a1, a2);
if ( a3 )
printf(" EXPIRES=%s;", a3);
if ( a4 )
printf(" PATH=%s;", a4);
if ( a5 )
printf(" DOMAIN=%s;", a5);
if ( a6 )
printf(" SECURE");
return putchar(10);
}

original_code:
void set_cookie(char *name, char *value, char *expires, char *path,
  char *domain, short secure)
{
  printf("Set-Cookie: %s=%s;",name,value);
  if (expires != ((void *)0))
    printf(" EXPIRES=%s;",expires);
  if (path != ((void *)0))
    printf(" PATH=%s;",path);
  if (domain != ((void *)0))
    printf(" DOMAIN=%s;",domain);
  if (secure)
    printf(" SECURE");
  printf("\n");
}

variable_types:
name
char *

variable_types:
value
char *

variable_types:
expires
char *

variable_types:
path
char *

variable_types:
domain
char *

variable_types: secure short


decompiled_code:
int __fastcall html_begin(const char *a1)
{
puts("<html> <head>");
printf("<title>%s</title>\n", a1);
puts("</head>\n");
return puts("<body>");
}

canonical_decompiled_code:
int __fastcall func7(const char *a1)
{
puts("<html> <head>");
printf("<title>%s</title>\n", a1);
puts("</head>\n");
return puts("<body>");
}

original_code:
void html_begin(char *title)
{
  printf("<html> <head>\n");
  printf("<title>%s</title>\n",title);
  printf("</head>\n\n");
  printf("<body>\n");
}

variable_types:
title
char *


decompiled_code:
int html_end()
{
return puts("</body> </html>");
}

canonical_decompiled_code:
int func8()
{
return puts("</body> </html>");
}

original_code:
void html_end(void)
{
  printf("</body> </html>\n");
}

canonical_original_code:
void html_end()
{
  printf("</body> </html>\n");
}


decompiled_code:
int __fastcall h1(const char *a1)
{
return printf("<h1>%s</h1>\n", a1);
}

canonical_decompiled_code:
int __fastcall func9(const char *a1)
{
return printf("<h1>%s</h1>\n", a1);
}

original_code:
void h1(char *header)
{
  printf("<h1>%s</h1>\n",header);
}

variable_types:
header
char *


decompiled_code:
int __fastcall h2(const char *a1)
{
return printf("<h2>%s</h2>\n", a1);
}

canonical_decompiled_code:
int __fastcall func10(const char *a1)
{
return printf("<h2>%s</h2>\n", a1);
}

original_code:
void h2(char *header)
{
  printf("<h2>%s</h2>\n",header);
}


decompiled_code:
int __fastcall h3(const char *a1)
{
return printf("<h3>%s</h3>\n", a1);
}

canonical_decompiled_code:
int __fastcall func11(const char *a1)
{
return printf("<h3>%s</h3>\n", a1);
}

original_code:
void h3(char *header)
{
  printf("<h3>%s</h3>\n",header);
}


decompiled_code:
int __fastcall h4(const char *a1)
{
return printf("<h4>%s</h4>\n", a1);
}

canonical_decompiled_code:
int __fastcall func12(const char *a1)
{
return printf("<h4>%s</h4>\n", a1);
}

original_code:
void h4(char *header)
{
  printf("<h4>%s</h4>\n",header);
}


decompiled_code:
int __fastcall h5(const char *a1)
{
return printf("<h5>%s</h5>\n", a1);
}

canonical_decompiled_code:
int __fastcall func13(const char *a1)
{
return printf("<h5>%s</h5>\n", a1);
}

original_code:
void h5(char *header)
{
  printf("<h5>%s</h5>\n",header);
}


decompiled_code:
int __fastcall h6(const char *a1)
{
return printf("<h6>%s</h6>\n", a1);
}

canonical_decompiled_code:
int __fastcall func14(const char *a1)
{
return printf("<h6>%s</h6>\n", a1);
}

original_code:
void h6(char *header)
{
  printf("<h6>%s</h6>\n",header);
}


hidden

decompiled_code:
int __fastcall hidden(const char *a1, const char *a2)
{
return printf("<input type=hidden name=\"%s\" value=\"%s\">\n", a1, a2);
}

canonical_decompiled_code:
int __fastcall func15(const char *a1, const char *a2)
{
return printf("<input type=hidden name=\"%s\" value=\"%s\">\n", a1, a2);
}

original_code:
void hidden(char *name, char *value)
{
  printf("<input type=hidden name=\"%s\" value=\"%s\">\n",name,value);
}


decompiled_code:
__int64 __fastcall list_next(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

original_code:
node* list_next(node* w)
{
  return w->next;
}

canonical_original_code:
struct _node *list_next(struct _node *w)
{
  return w->next;
}

variable_types:
w
struct _node *

return_type: struct _node { struct entrytype { char *name; char *value; } entry; struct _node *next; } *


decompiled_code:
_BOOL8 __fastcall on_list(__int64 a1, __int64 a2)
{
return a2 != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1, __int64 a2)
{
return a2 != 0;
}

original_code:
short on_list(llist *l, node* w)
{
  return (w != 0);
}

canonical_original_code:
short on_list(struct llist *l, struct _node *w)
{
  return (w != 0);
}

variable_types: struct llist { struct _node { struct entrytype { char *name; char *value; } entry; struct _node *next; } *head; } *

return_type: short


original_code:
short on_list_debug(llist *l, node* w)
{
  node* current;
  if (w == 0)
    return 0;
  else {
    current = l->head;
    while ( (current != w) && (current != 0) )
      current = current->next;
    if (current == w)
      return 1;
    else
      return 0;
  }
}

canonical_original_code:
short on_list_debug(struct llist *l, struct _node *w)
{
  struct _node *current;
  if (w == 0)
    return 0;
  else {
    current = l->head;
    while ( (current != w) && (current != 0) )
      current = current->next;
    if (current == w)
      return 1;
    else
      return 0;
  }
}

variable_types: struct _node { struct entrytype { char *name; char *value; } entry; struct _node *next; } *


original_code:
void list_clear(llist* l)
{
  node* nextnode;
  node* current;
  current = l->head;
  while (current) {
    nextnode=current->next;
    if (current->entry.name)
      free(current->entry.name);
    if (current->entry.value)
      free(current->entry.value);
    free(current);
    current=nextnode;
  }
}

canonical_original_code:
void list_clear(struct llist *l)
{
  struct _node *nextnode;
  struct _node *current;
  current = l->head;
  while (current) {
    nextnode=current->next;
    if (current->entry.name)
      free(current->entry.name);
    if (current->entry.value)
      free(current->entry.value);
    free(current);
    current=nextnode;
  }
}

user_defined_types: struct entrytype { char *name; char *value; }


newstr

decompiled_code:
char *__fastcall newstr(char *src)
{
size_t v1; // rax
char *v2; // rax
char *v3; // rbx

v1 = strlen(src);
v2 = (char *)malloc(v1 + 1);
v3 = v2;
if ( v2 )
strcpy(v2, src);
return v3;
}

canonical_decompiled_code:
char *__fastcall func0(char *src)
{
size_t v1; // rax
char *v2; // rax
char *v3; // rbx

v1 = strlen(src);
v2 = (char *)malloc(v1 + 1);
v3 = v2;
if ( v2 )
strcpy(v2, src);
return v3;
}

original_code:
char *newstr(char *str)
{
  char *tempstr = (char *)malloc(sizeof(char) * strlen(str) + 1);
  if (tempstr != ((void *)0))
    strcpy(tempstr,str);
  return tempstr;
}

variable_types:
str
char *

variable_types:
tempstr
char *

return_type: char *


repo: wessels/pcap-tools

original_code:
int
tv_cmp(struct timeval *a, struct timeval *b)
{
    return (a->tv_sec == b->tv_sec) ? (a->tv_usec<b->tv_usec?-1:(a->tv_usec>b->tv_usec?1:0)) : (a->tv_sec<b->tv_sec?-1:(a->tv_sec>b->tv_sec?1:0));
}

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

variable_types:
b
struct timeval *


flush

decompiled_code:
void *__fastcall flush(int a1)
{
void *result; // rax

if ( a1 )
result = memmove(tvals, (char *)tvals + 16 * (count - (__int64)a1), 16LL * a1);
count = a1;
return result;
}

canonical_decompiled_code:
void *__fastcall func8(int a1)
{
void *result; // rax

if ( a1 )
result = memmove(tvals, (char *)tvals + 16 * (count - (__int64)a1), 16LL * a1);
count = a1;
return result;
}

original_code:
void
flush(int keep)
{
    if (keep)
 memmove(tvals, tvals + count - keep, keep * sizeof(*tvals));
    count = keep;
}

variable_types: keep int


push

decompiled_code:
int __fastcall push(const __m128i *a1)
{
int result; // eax
__int64 v2; // rax
_QWORD *v3; // rbx
_QWORD *v4; // rbp

if ( count >= ARRAYSZ )
__assert_fail("count < ARRAYSZ", "pcap-find-misordered.c", 0x28u, "push");
*((__m128i *)tvals + count) = _mm_loadu_si128(a1);
result = count + 1;
count = result;
if ( result > 1 )
{
v2 = 16LL * result;
v3 = (char *)tvals + v2 - 32;
v4 = (char *)tvals + v2 - 16;
result = tv_cmp(v4, v3);
if ( result < 0 )
{
result = printf("timestamp went from %10lld.%06ld to %10lld.%06ld\n", *v3, v3[1], *v4, v4[1]);
++misordered;
}
}
return result;
}

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

if ( count >= ARRAYSZ )
__assert_fail("count < ARRAYSZ", "pcap-find-misordered.c", 0x28u, "push");
*((__m128i *)tvals + count) = _mm_loadu_si128(a1);
result = count + 1;
count = result;
if ( result > 1 )
{
v2 = 16LL * result;
v3 = (char *)tvals + v2 - 32;
v4 = (char *)tvals + v2 - 16;
result = func7(v4, v3);
if ( result < 0 )
{
result = printf("timestamp went from %10lld.%06ld to %10lld.%06ld\n", *v3, v3[1], *v4, v4[1]);
++misordered;
}
}
return result;
}

original_code:
void
push(struct pcap_pkthdr *hdr, const u_char * data)
{
    ((void) sizeof ((count < ARRAYSZ) ? 1 : 0), __extension__ ({ if (count < ARRAYSZ) ; else __assert_fail ("count < ARRAYSZ", "pcap-find-misordered.c", 40, __extension__ __PRETTY_FUNCTION__); }));
    *(tvals + count) = hdr->ts;
    count++;
    if (count < 2)
 return;
    if (0 > tv_cmp(tvals + count - 1, tvals + count - 2)) {
 printf("timestamp went from %10lld.%06ld to %10lld.%06ld\n",
     (long long int) (tvals + count - 2)->tv_sec,
     (tvals + count - 2)->tv_usec, (long long int) (tvals + count - 1)->tv_sec, (tvals + count - 1)->tv_usec);
 misordered++;
    }
}

canonical_original_code:
void push(struct pcap_pkthdr *hdr, unsigned char *data)
{
    ((void) sizeof ((count < ARRAYSZ) ? 1 : 0), __extension__ ({ if (count < ARRAYSZ) ; else __assert_fail ("count < ARRAYSZ", "pcap-find-misordered.c", 40, __extension__ __PRETTY_FUNCTION__); }));
    *(tvals + count) = hdr->ts;
    count++;
    if (count < 2)
 return;
    if (0 > tv_cmp(tvals + count - 1, tvals + count - 2)) {
 printf("timestamp went from %10lld.%06ld to %10lld.%06ld\n",
     (long long) (tvals + count - 2)->tv_sec,
     (tvals + count - 2)->tv_usec, (long long) (tvals + count - 1)->tv_sec, (tvals + count - 1)->tv_usec);
 misordered++;
    }
}

variable_types: struct pcap_pkthdr { struct timeval { long tv_sec; long tv_usec; } ts; unsigned int caplen; unsigned int len; } *

variable_types:
data
unsigned char *

user_defined_types: struct pcap_pkthdr { struct timeval ts; unsigned int caplen; unsigned int len; }


decompiled_code:
int __fastcall qsort_strcmp(const void *a1, const void *a2)
{
return strcmp(*(const char **)a1, *(const char **)a2);
}

canonical_decompiled_code:
int __fastcall func0(const void *a1, const void *a2)
{
return strcmp(*(const char **)a1, *(const char **)a2);
}

original_code:
int
qsort_strcmp(const void *a, const void *b)
{
    return strcmp(*((char **) a), *((char **) b));
}

canonical_original_code:
int qsort_strcmp(void *a, void *b)
{
    return strcmp(*((char **) a), *((char **) b));
}

variable_types:
a
void *

variable_types:
b
void *


decompiled_code:
time_t __fastcall parse_timestamp(char *string)
{
const char *v1; // r14
__int64 *v2; // rbx
unsigned int v3; // er12
regex_t *v4; // rax
time_t result; // rax
struct tm v6; // [rsp+0h] [rbp-B8h] BYREF
regmatch_t v7; // [rsp+40h] [rbp-78h] BYREF

v1 = (const char *)time_patterns[1];
if ( v1 )
{
v2 = time_patterns;
v3 = 0;
while ( 1 )
{
if ( !v2[3] )
{
v4 = (regex_t *)calloc(1uLL, 0x40uLL);
v2[3] = (__int64)v4;
if ( regcomp(v4, v1, 1) )
{
fprintf(stderr, "regcomp '%s' failed\n", (const char *)time_patterns[4 * v3 + 1]);
exit(1);
}
}
if ( !regexec((const regex_t *)v2[3], string, *(int *)v2, &v7, 0) )
{
if ( v7.rm_so < 0 )
_assert_fail("pmatch[0].rm_so > -1", "pcap-join.c", 0x62u, "parse_timestamp");
if ( (unsigned int)strptime(&string[v7.rm_so], (const char *)v2[2], &v6) )
break;
}
++v3;
v2 += 4;
v1 = (const char *)v2[1];
if ( !v1 )
goto LABEL_12;
}
result = timegm(&v6);
}
else
{
LABEL_12:
fprintf(stderr, "no time patterns matched '%s'\n", string);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
time_t __fastcall func2(char *string)
{
const char *v1; // r14
__int64 *v2; // rbx
unsigned int v3; // er12
regex_t *v4; // rax
time_t result; // rax
struct tm v6; // [rsp+0h] [rbp-B8h] BYREF
regmatch_t v7; // [rsp+40h] [rbp-78h] BYREF

v1 = (const char *)time_patterns[1];
if ( v1 )
{
v2 = time_patterns;
v3 = 0;
while ( 1 )
{
if ( !v2[3] )
{
v4 = (regex_t *)calloc(1uLL, 0x40uLL);
v2[3] = (__int64)v4;
if ( regcomp(v4, v1, 1) )
{
fprintf(stderr, "regcomp '%s' failed\n", (const char *)time_patterns[4 * v3 + 1]);
exit(1);
}
}
if ( !regexec((const regex_t *)v2[3], string, *(int *)v2, &v7, 0) )
{
if ( v7.rm_so < 0 )
_assert_fail("pmatch[0].rm_so > -1", "pcap-join.c", 0x62u, "parse_timestamp");
if ( (unsigned int)strptime(&string[v7.rm_so], (const char *)v2[2], &v6) )
break;
}
++v3;
v2 += 4;
v1 = (const char *)v2[1];
if ( !v1 )
goto LABEL_12;
}
result = timegm(&v6);
}
else
{
LABEL_12:
fprintf(stderr, "no time patterns matched '%s'\n", string);
result = 0LL;
}
return result;
}

original_code:
time_t
parse_timestamp(const char *s)
{
    regmatch_t pmatch[10];
    struct tm tm;
    unsigned int k;
    for (k = 0; time_patterns[k].pat; k++) {
 if (0 == time_patterns[k].re) {
     time_patterns[k].re = calloc(1, sizeof(*time_patterns[k].re));
     if (0 != regcomp(time_patterns[k].re, time_patterns[k].pat, 1)) {
  fprintf(stderr, "regcomp '%s' failed\n", time_patterns[k].pat);
  exit(1);
     }
 }
 if (0 != regexec(time_patterns[k].re, s, time_patterns[k].nmatch, pmatch, 0)) {
     continue;
 }
 ((void) sizeof ((pmatch[0].rm_so > -1) ? 1 : 0), __extension__ ({ if (pmatch[0].rm_so > -1) ; else __assert_fail ("pmatch[0].rm_so > -1", "pcap-join.c", 98, __extension__ __PRETTY_FUNCTION__); }));
 if (0 == strptime(s + pmatch[0].rm_so, time_patterns[k].fmt, &tm))
     continue;
 return timegm(&tm);
    }
    fprintf(stderr, "no time patterns matched '%s'\n", s);
    return 0;
}

canonical_original_code:
long parse_timestamp(char *s)
{
    struct regmatch_t pmatch[10];
    struct tm tm;
    unsigned int k;
    for (k = 0; time_patterns[k].pat; k++) {
 if (0 == time_patterns[k].re) {
     time_patterns[k].re = calloc(1, sizeof(*time_patterns[k].re));
     if (0 != regcomp(time_patterns[k].re, time_patterns[k].pat, 1)) {
  fprintf(stderr, "regcomp '%s' failed\n", time_patterns[k].pat);
  exit(1);
     }
 }
 if (0 != regexec(time_patterns[k].re, s, time_patterns[k].nmatch, pmatch, 0)) {
     continue;
 }
 ((void) sizeof ((pmatch[0].rm_so > -1) ? 1 : 0), __extension__ ({ if (pmatch[0].rm_so > -1) ; else __assert_fail ("pmatch[0].rm_so > -1", "pcap-join.c", 98, __extension__ __PRETTY_FUNCTION__); }));
 if (0 == strptime(s + pmatch[0].rm_so, time_patterns[k].fmt, &tm))
     continue;
 return timegm(&tm);
    }
    fprintf(stderr, "no time patterns matched '%s'\n", s);
    return 0;
}

variable_types:
s
char *

variable_types: struct regmatch_t { int rm_so; int rm_eo; } [10]

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

variable_types:
k
unsigned int

return_type: long


decompiled_code:
__int64 __fastcall qsort_strptime(const void *a1, const void *a2)
{
time_t v2; // rbx

v2 = parse_timestamp(*(char **)a1);
return 2 * (unsigned int)(v2 > parse_timestamp(*(char **)a2)) - 1;
}

canonical_decompiled_code:
__int64 __fastcall func3(const void *a1, const void *a2)
{
time_t v2; // rbx

v2 = func2(*(char **)a1);
return 2 * (unsigned int)(v2 > func2(*(char **)a2)) - 1;
}

original_code:
int
qsort_strptime(const void *a, const void *b)
{
    time_t time_a = parse_timestamp(*((char **) a));
    time_t time_b = parse_timestamp(*((char **) b));
    if (time_a < time_b)
 return -1;
    if (time_a > time_b)
 return 1;
    return -1;
}

canonical_original_code:
int qsort_strptime(void *a, void *b)
{
    long time_a = parse_timestamp(*((char **) a));
    long time_b = parse_timestamp(*((char **) b));
    if (time_a < time_b)
 return -1;
    if (time_a > time_b)
 return 1;
    return -1;
}


decompiled_code:
_DWORD *filelist_init()
{
_DWORD *v0; // rbx

v0 = calloc(1uLL, 0x10uLL);
*v0 = 64;
v0[1] = 0;
*((_QWORD *)v0 + 1) = calloc(0x40uLL, 8uLL);
return v0;
}

canonical_decompiled_code:
_DWORD *func5()
{
_DWORD *v0; // rbx

v0 = calloc(1uLL, 0x10uLL);
*v0 = 64;
v0[1] = 0;
*((_QWORD *)v0 + 1) = calloc(0x40uLL, 8uLL);
return v0;
}

original_code:
filelist *
filelist_init(void)
{
    filelist *fl;
    fl = calloc(1, sizeof(*fl));
    fl->size = 64;
    fl->cnt = 0;
    fl->files = calloc(fl->size, sizeof(char *));
    return fl;
}

canonical_original_code:
struct filelist *filelist_init()
{
    struct filelist *fl;
    fl = calloc(1, sizeof(*fl));
    fl->size = 64;
    fl->cnt = 0;
    fl->files = calloc(fl->size, sizeof(char *));
    return fl;
}

variable_types: struct filelist { unsigned int size; unsigned int cnt; char **files; } *


decompiled_code:
char *__fastcall filelist_add(unsigned int *a1, const char *a2)
{
unsigned int v2; // ebp
__int64 v3; // r13
unsigned int v4; // ebp
char *result; // rax
void *v6; // r13
void *v7; // r14

v2 = *a1;
if ( a1[1] == *a1 )
{
v6 = calloc(2 * v2, 8uLL);
v7 = (void *)*((_QWORD *)a1 + 1);
memcpy(v6, v7, 8LL * v2);
free(v7);
*((_QWORD *)a1 + 1) = v6;
*a1 *= 2;
}
v3 = *((_QWORD *)a1 + 1);
v4 = a1[1];
a1[1] = v4 + 1;
result = strdup(a2);
*(_QWORD *)(v3 + 8LL * v4) = result;
return result;
}

canonical_decompiled_code:
char *__fastcall func6(unsigned int *a1, const char *a2)
{
unsigned int v2; // ebp
__int64 v3; // r13
unsigned int v4; // ebp
char *result; // rax
void *v6; // r13
void *v7; // r14

v2 = *a1;
if ( a1[1] == *a1 )
{
v6 = calloc(2 * v2, 8uLL);
v7 = (void *)*((_QWORD *)a1 + 1);
memcpy(v6, v7, 8LL * v2);
free(v7);
*((_QWORD *)a1 + 1) = v6;
*a1 *= 2;
}
v3 = *((_QWORD *)a1 + 1);
v4 = a1[1];
a1[1] = v4 + 1;
result = strdup(a2);
*(_QWORD *)(v3 + 8LL * v4) = result;
return result;
}

original_code:
void
filelist_add(filelist * fl, const char *file)
{
    if (fl->cnt == fl->size) {
 char **tmp = calloc(fl->size << 1, sizeof(char *));
 memcpy(tmp, fl->files, fl->size * sizeof(char *));
 free(fl->files);
 fl->files = tmp;
 fl->size <<= 1;
    }
    fl->files[fl->cnt++] = strdup(file);
}

canonical_original_code:
void filelist_add(struct filelist *fl, char *file)
{
    if (fl->cnt == fl->size) {
 char **tmp = calloc(fl->size << 1, sizeof(char *));
 memcpy(tmp, fl->files, fl->size * sizeof(char *));
 free(fl->files);
 fl->files = tmp;
 fl->size <<= 1;
    }
    fl->files[fl->cnt++] = strdup(file);
}

variable_types:
file
char *

variable_types:
tmp
char **

user_defined_types: struct filelist { unsigned int size; unsigned int cnt; char **files; }


usage

decompiled_code:
void __noreturn usage()
{
fwrite("usage: pcap-join [options] pcapfiles ...\n", 1uLL, 0x29uLL, stderr);
fwrite(" pcap-join [options] directory\n", 1uLL, 0x25uLL, stderr);
fwrite(" pcap-join [options] (reads files from stdin)\n", 1uLL, 0x34uLL, stderr);
fwrite("options:\n", 1uLL, 9uLL, stderr);
fwrite(" -v verbose\n", 1uLL, 0x1CuLL, stderr);
fwrite(" -b filter apply pcap filter\n", 1uLL, 0x26uLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func4()
{
fwrite("usage: pcap-join [options] pcapfiles ...\n", 1uLL, 0x29uLL, stderr);
fwrite(" pcap-join [options] directory\n", 1uLL, 0x25uLL, stderr);
fwrite(" pcap-join [options] (reads files from stdin)\n", 1uLL, 0x34uLL, stderr);
fwrite("options:\n", 1uLL, 9uLL, stderr);
fwrite(" -v verbose\n", 1uLL, 0x1CuLL, stderr);
fwrite(" -b filter apply pcap filter\n", 1uLL, 0x26uLL, stderr);
exit(1);
}

original_code:
void
usage(void)
{
    fprintf(stderr, "usage: pcap-join [options] pcapfiles ...\n");
    fprintf(stderr, "       pcap-join [options] directory\n");
    fprintf(stderr, "       pcap-join [options] (reads files from stdin)\n");
    fprintf(stderr, "options:\n");
    fprintf(stderr, "       -v           verbose\n");
    fprintf(stderr, "       -b filter    apply pcap filter\n");
    exit(1);
}

canonical_original_code:
void usage()
{
    fprintf(stderr, "usage: pcap-join [options] pcapfiles ...\n");
    fprintf(stderr, "       pcap-join [options] directory\n");
    fprintf(stderr, "       pcap-join [options] (reads files from stdin)\n");
    fprintf(stderr, "options:\n");
    fprintf(stderr, "       -v           verbose\n");
    fprintf(stderr, "       -b filter    apply pcap filter\n");
    exit(1);
}


decompiled_code:
_BOOL8 __fastcall is_dupe(const __m128i *a1, const void *a2)
{
_BOOL4 v2; // er12

MD5_Init();
MD5_Update();
MD5_Final();
v2 = 0;
if ( *a1 == lasthdr_2 && a1[1].m128i_i64[0] == qword_405160 )
v2 = memcmp(&thisdigest_3, &lastdigest_1, 0x10uLL) == 0;
lastdigest_1 = (__int128)_mm_load_si128((const __m128i *)&thisdigest_3);
lasthdr_2 = (__int128)_mm_loadu_si128(a1);
qword_405160 = a1[1].m128i_i64[0];
memcpy(&lastdata_0, a2, a1[1].m128i_u32[1]);
return v2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(const __m128i *a1, const void *a2)
{
_BOOL4 v2; // er12

MD5_Init();
MD5_Update();
MD5_Final();
v2 = 0;
if ( *a1 == lasthdr_2 && a1[1].m128i_i64[0] == qword_405160 )
v2 = memcmp(&thisdigest_3, &lastdigest_1, 0x10uLL) == 0;
lastdigest_1 = (__int128)_mm_load_si128((const __m128i *)&thisdigest_3);
lasthdr_2 = (__int128)_mm_loadu_si128(a1);
qword_405160 = a1[1].m128i_i64[0];
memcpy(&lastdata_0, a2, a1[1].m128i_u32[1]);
return v2;
}

original_code:
int
is_dupe(struct pcap_pkthdr *thishdr, const u_char * thisdata)
{
    static struct pcap_pkthdr lasthdr;
    static char lastdata[4096];
    MD5_CTX md5;
    static unsigned int thisdigest[4];
    static unsigned int lastdigest[4];
    int rc = 0;
    MD5_Init(&md5);
    MD5_Update(&md5, thisdata, thishdr->len);
    MD5_Final((u_char *) thisdigest, &md5);
    if (thishdr->ts.tv_usec != lasthdr.ts.tv_usec)
 (void) 0;
    else if (thishdr->ts.tv_sec != lasthdr.ts.tv_sec)
 (void) 0;
    else if (thishdr->caplen != lasthdr.caplen)
 (void) 0;
    else if (thishdr->len != lasthdr.len)
 (void) 0;
    else {
 if (memcmp(thisdigest, lastdigest, 16) == 0)
     rc = 1;
    }
    memcpy(lastdigest, thisdigest, 16);
    lasthdr = *thishdr;
    memcpy(lastdata, thisdata, thishdr->len);
    return rc;
}

canonical_original_code:
int is_dupe(struct pcap_pkthdr *thishdr, unsigned char *thisdata)
{
    static struct pcap_pkthdr lasthdr;
    static char lastdata[4096];
    struct MD5state_st md5;
    static unsigned int thisdigest[4];
    static unsigned int lastdigest[4];
    int rc = 0;
    MD5_Init(&md5);
    MD5_Update(&md5, thisdata, thishdr->len);
    MD5_Final((unsigned char *) thisdigest, &md5);
    if (thishdr->ts.tv_usec != lasthdr.ts.tv_usec)
 (void) 0;
    else if (thishdr->ts.tv_sec != lasthdr.ts.tv_sec)
 (void) 0;
    else if (thishdr->caplen != lasthdr.caplen)
 (void) 0;
    else if (thishdr->len != lasthdr.len)
 (void) 0;
    else {
 if (memcmp(thisdigest, lastdigest, 16) == 0)
     rc = 1;
    }
    memcpy(lastdigest, thisdigest, 16);
    lasthdr = *thishdr;
    memcpy(lastdata, thisdata, thishdr->len);
    return rc;
}

variable_types:
thisdata
unsigned char *

variable_types: struct pcap_pkthdr { struct timeval { long tv_sec; long tv_usec; } ts; unsigned int caplen; unsigned int len; }

variable_types:
lastdata
char [4096]

variable_types: struct MD5state_st { unsigned int A; unsigned int Nl; unsigned int data[-1]; unsigned int num; }

variable_types:
thisdigest
unsigned int [4]

variable_types:
lastdigest
unsigned int [4]

variable_types: rc int


help

decompiled_code:
int help()
{
fprintf(stderr, "%s\n", "pcap-split");
return fprintf(
stderr,
"\n"
"options:\n"
"\t-? or -h print these instructions and exit\n"
"\t-B YYYY-MM-DD HH:MM:SS select packets starting on that date\n"
"\t-E YYYY-MM-DD HH:MM:SS select packets until this time/date\n"
"\t-t <interval> each <interval> seconds since\n"
"\t the start time indicated by '-B'\n"
"\t will close the old destination file\n"
"\t and create a new one.\n"
"\t-n <count> make new output file every <count> packets\n"
"\t-f <format> receives a format accepted by\n"
"\t strftime to name the files created.\n"
"\t Default %%s (UNIX timestamp)\n"
"\t-k <kick command> After closing an old destination\n"
"\t file, will execute this command with\n"
"\t the file name as first parameter\n"
"\t-v produce slightly more verbose output\n"
"\t-z automatcially compress each pcap\n"
"\t with gzip\n");
}

canonical_decompiled_code:
int func0()
{
fprintf(stderr, "%s\n", "pcap-split");
return fprintf(
stderr,
"\n"
"options:\n"
"\t-? or -h print these instructions and exit\n"
"\t-B YYYY-MM-DD HH:MM:SS select packets starting on that date\n"
"\t-E YYYY-MM-DD HH:MM:SS select packets until this time/date\n"
"\t-t <interval> each <interval> seconds since\n"
"\t the start time indicated by '-B'\n"
"\t will close the old destination file\n"
"\t and create a new one.\n"
"\t-n <count> make new output file every <count> packets\n"
"\t-f <format> receives a format accepted by\n"
"\t strftime to name the files created.\n"
"\t Default %%s (UNIX timestamp)\n"
"\t-k <kick command> After closing an old destination\n"
"\t file, will execute this command with\n"
"\t the file name as first parameter\n"
"\t-v produce slightly more verbose output\n"
"\t-z automatcially compress each pcap\n"
"\t with gzip\n");
}

original_code:
static void
help(void)
{
    fprintf(stderr, "%s\n", ProgramName);
    fprintf(stderr,
 "\noptions:\n"
 "\t-? or -h  print these instructions and exit\n"
 "\t-B YYYY-MM-DD HH:MM:SS        select packets starting on that date\n"
 "\t-E YYYY-MM-DD HH:MM:SS        select packets until this time/date\n"
 "\t-t <interval>                 each <interval> seconds since\n"
 "\t                              the start time indicated by '-B'\n"
 "\t                              will close the old destination file\n"
 "\t                              and create a new one.\n"
 "\t-n <count>                    make new output file every <count> packets\n"
 "\t-f <format>                   receives a format accepted by\n"
 "\t                              strftime to name the files created.\n"
 "\t                              Default %%s (UNIX timestamp)\n"
 "\t-k <kick command>             After closing an old destination\n"
 "\t                              file, will execute this command with\n"
 "\t                              the file name as first parameter\n"
 "\t-v                            produce slightly more verbose output\n"
 "\t-z                            automatcially compress each pcap\n"
 "\t                              with gzip\n");
}

canonical_original_code:
static void help()
{
    fprintf(stderr, "%s\n", ProgramName);
    fprintf(stderr,
 "\noptions:\n"
 "\t-? or -h  print these instructions and exit\n"
 "\t-B YYYY-MM-DD HH:MM:SS        select packets starting on that date\n"
 "\t-E YYYY-MM-DD HH:MM:SS        select packets until this time/date\n"
 "\t-t <interval>                 each <interval> seconds since\n"
 "\t                              the start time indicated by '-B'\n"
 "\t                              will close the old destination file\n"
 "\t                              and create a new one.\n"
 "\t-n <count>                    make new output file every <count> packets\n"
 "\t-f <format>                   receives a format accepted by\n"
 "\t                              strftime to name the files created.\n"
 "\t                              Default %%s (UNIX timestamp)\n"
 "\t-k <kick command>             After closing an old destination\n"
 "\t                              file, will execute this command with\n"
 "\t                              the file name as first parameter\n"
 "\t-v                            produce slightly more verbose output\n"
 "\t-z                            automatcially compress each pcap\n"
 "\t                              with gzip\n");
}


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
fprintf(stderr, "%s: usage error: %s\n", "pcap-split", a1);
fputc(10, stderr);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(const char *a1)
{
fprintf(stderr, "%s: usage error: %s\n", "pcap-split", a1);
fputc(10, stderr);
exit(1);
}

original_code:
static void
usage(const char *msg)
{
    fprintf(stderr, "%s: usage error: %s\n", ProgramName, msg);
    fprintf(stderr, "\n");
    exit(1);
}

canonical_original_code:
static void usage(char *msg)
{
    fprintf(stderr, "%s: usage error: %s\n", ProgramName, msg);
    fprintf(stderr, "\n");
    exit(1);
}

variable_types:
msg
char *


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

result = 1LL;
if ( *(_DWORD *)(a1 + 16) <= 0xFFFFu )
result = *(_DWORD *)(a1 + 20) > 0xFFFFu;
return result;
}

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

result = 1LL;
if ( *(_DWORD *)(a1 + 16) <= 0xFFFFu )
result = *(_DWORD *)(a1 + 20) > 0xFFFFu;
return result;
}

original_code:
int
is_bogus(struct pcap_pkthdr *thishdr, const u_char * thisdata)
{
    if (thishdr->caplen > 65535)
 return 1;
    if (thishdr->len > 65535)
 return 1;
    return 0;
}

canonical_original_code:
int is_bogus(struct pcap_pkthdr *thishdr, unsigned char *thisdata)
{
    if (thishdr->caplen > 65535)
 return 1;
    if (thishdr->len > 65535)
 return 1;
    return 0;
}

variable_types: struct pcap_pkthdr { struct timeval { long tv_sec; long tv_usec; } ts; unsigned int caplen; unsigned int len; } *


WfaRcvStop

repo: wfapf/TDLS

decompiled_code:
__int64 __fastcall WfaRcvStop(__int64 a1)
{
int v1; // ebx
__int64 v3; // r13
__int64 v4; // r14
__int64 v5; // rbp
pthread_mutex_t *v6; // r12
__int64 v7; // r13
pthread_cond_t *v8; // rbp
char *v9; // r13

v1 = *((_DWORD *)&wmmps_info + 10);
*((_DWORD *)&wmm_thr + 50 * v1 + 1) = 0;
if ( *(_DWORD *)(a1 + 40) == 42 )
{
v3 = 5LL * v1;
v4 = 20LL * v1;
v5 = 8 * (v3 + v4);
v6 = (pthread_mutex_t *)((char *)&wmm_thr + v5 + 160);
pthread_mutex_lock(v6);
v7 = v4 + v3;
if ( !*((_DWORD *)&wmm_thr + 2 * v7 + 1) )
{
v8 = (pthread_cond_t *)((char *)&wmm_thr + v5 + 72);
v9 = (char *)&wmm_thr + 8 * v7;
do
pthread_cond_wait(v8, v6);
while ( !*((_DWORD *)v9 + 1) );
}
num_stops = 0;
pthread_mutex_unlock(v6);
*((_DWORD *)&wmm_thr + 50 * v1 + 1) = 0;
gtgWmmPS = 0;
close(psSockfd);
psSockfd = -1;
signal(14, (__sighandler_t)((char *)WfaRcvStop + 1));
sleep(1u);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
int v1; // ebx
__int64 v3; // r13
__int64 v4; // r14
__int64 v5; // rbp
pthread_mutex_t *v6; // r12
__int64 v7; // r13
pthread_cond_t *v8; // rbp
char *v9; // r13

v1 = *((_DWORD *)&wmmps_info + 10);
*((_DWORD *)&wmm_thr + 50 * v1 + 1) = 0;
if ( *(_DWORD *)(a1 + 40) == 42 )
{
v3 = 5LL * v1;
v4 = 20LL * v1;
v5 = 8 * (v3 + v4);
v6 = (pthread_mutex_t *)((char *)&wmm_thr + v5 + 160);
pthread_mutex_lock(v6);
v7 = v4 + v3;
if ( !*((_DWORD *)&wmm_thr + 2 * v7 + 1) )
{
v8 = (pthread_cond_t *)((char *)&wmm_thr + v5 + 72);
v9 = (char *)&wmm_thr + 8 * v7;
do
pthread_cond_wait(v8, v6);
while ( !*((_DWORD *)v9 + 1) );
}
num_stops = 0;
pthread_mutex_unlock(v6);
*((_DWORD *)&wmm_thr + 50 * v1 + 1) = 0;
gtgWmmPS = 0;
close(psSockfd);
psSockfd = -1;
signal(14, (__sighandler_t)((char *)WfaRcvStop + 1));
sleep(1u);
}
return 0LL;
}

original_code:
int WfaRcvStop(unsigned int *rmsg,int length,int *state)
{
   tgWMM_t *my_wmm = &wmm_thr[wmmps_info.ps_thread];
   my_wmm->stop_flag = 0;
   ;;
   if(rmsg[10] != (((((37 + 0x01) + 0x01) + 0x01) + 0x01) + 0x01))
   {
      ;;
   }
   else
   {
      pthread_mutex_lock(&my_wmm->thr_stop_mutex);
      while(!my_wmm->stop_flag)
      {
         pthread_cond_wait(&my_wmm->thr_stop_cond, &my_wmm->thr_stop_mutex);
      }
      num_stops=0;
      pthread_mutex_unlock(&my_wmm->thr_stop_mutex);
      my_wmm->stop_flag = 0;
      gtgWmmPS = 0;
      close(psSockfd);
      psSockfd = -1;
      signal(14, ((__sighandler_t) 1));
      sleep(1);
   }
   return 0;
}

canonical_original_code:
int WfaRcvStop(unsigned int *rmsg, int length, int *state)
{
   struct _tg_wmm *my_wmm = &wmm_thr[wmmps_info.ps_thread];
   my_wmm->stop_flag = 0;
   ;;
   if(rmsg[10] != (((((37 + 0x01) + 0x01) + 0x01) + 0x01) + 0x01))
   {
      ;;
   }
   else
   {
      pthread_mutex_lock(&my_wmm->thr_stop_mutex);
      while(!my_wmm->stop_flag)
      {
         pthread_cond_wait(&my_wmm->thr_stop_cond, &my_wmm->thr_stop_mutex);
      }
      num_stops=0;
      pthread_mutex_unlock(&my_wmm->thr_stop_mutex);
      my_wmm->stop_flag = 0;
      gtgWmmPS = 0;
      close(psSockfd);
      psSockfd = -1;
      signal(14, ((void (*)(int)) 1));
      sleep(1);
   }
   return 0;
}

variable_types:
rmsg
unsigned int *

variable_types: length int

variable_types:
state
int *

variable_types: struct _tg_wmm { int thr_flag; int stop_flag; unsigned long thr; int thr_id; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } thr_flag_cond; union pthread_cond_t thr_stop_cond; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } thr_flag_mutex; union pthread_mutex_t thr_stop_mutex; } *

user_defined_types: struct _tg_wmm { int thr_flag; int stop_flag; unsigned long thr; int thr_id; union pthread_cond_t thr_flag_cond; union pthread_cond_t thr_stop_cond; union pthread_mutex_t thr_flag_mutex; union pthread_mutex_t thr_stop_mutex; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


WfaRcvVOCyclic

decompiled_code:
__int64 __fastcall WfaRcvVOCyclic(__int64 a1)
{
int v2; // er13
__int64 v3; // r12
__int64 v4; // r14
__int64 v5; // rbx
pthread_mutex_t *v6; // rbp
__int64 v7; // r12
pthread_cond_t *v8; // rbx
char *v9; // r12

if ( *(_DWORD *)(a1 + 40) != 42 )
return 0LL;
v2 = *((_DWORD *)&wmmps_info + 10);
v3 = 5LL * v2;
v4 = 20LL * v2;
v5 = 8 * (v3 + v4);
v6 = (pthread_mutex_t *)((char *)&wmm_thr + v5 + 160);
pthread_mutex_lock(v6);
v7 = v4 + v3;
if ( !*((_DWORD *)&wmm_thr + 2 * v7 + 1) )
{
v8 = (pthread_cond_t *)((char *)&wmm_thr + v5 + 72);
v9 = (char *)&wmm_thr + 8 * v7;
do
pthread_cond_wait(v8, v6);
while ( !*((_DWORD *)v9 + 1) );
}
pthread_mutex_unlock(v6);
*((_DWORD *)&wmm_thr + 50 * v2 + 1) = 0;
gtgWmmPS = 0;
close(psSockfd);
psSockfd = -1;
signal(14, (__sighandler_t)((char *)WfaRcvStop + 1));
sleep(1u);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
int v2; // er13
__int64 v3; // r12
__int64 v4; // r14
__int64 v5; // rbx
pthread_mutex_t *v6; // rbp
__int64 v7; // r12
pthread_cond_t *v8; // rbx
char *v9; // r12

if ( *(_DWORD *)(a1 + 40) != 42 )
return 0LL;
v2 = *((_DWORD *)&wmmps_info + 10);
v3 = 5LL * v2;
v4 = 20LL * v2;
v5 = 8 * (v3 + v4);
v6 = (pthread_mutex_t *)((char *)&wmm_thr + v5 + 160);
pthread_mutex_lock(v6);
v7 = v4 + v3;
if ( !*((_DWORD *)&wmm_thr + 2 * v7 + 1) )
{
v8 = (pthread_cond_t *)((char *)&wmm_thr + v5 + 72);
v9 = (char *)&wmm_thr + 8 * v7;
do
pthread_cond_wait(v8, v6);
while ( !*((_DWORD *)v9 + 1) );
}
pthread_mutex_unlock(v6);
*((_DWORD *)&wmm_thr + 50 * v2 + 1) = 0;
gtgWmmPS = 0;
close(psSockfd);
psSockfd = -1;
signal(14, (__sighandler_t)((char *)WfaRcvStop + 1));
sleep(1u);
return 0LL;
}

original_code:
int WfaRcvVOCyclic(unsigned int *rmsg,int length,int *state)
{
    int r;
    tgWMM_t *my_wmm = &wmm_thr[wmmps_info.ps_thread];
    if(rmsg[10] != (((((37 + 0x01) + 0x01) + 0x01) + 0x01) + 0x01))
    {
        if ((r=receiver(rmsg,length,0xD0,(37 + 0x01)))>=0)
            ;
        else
            ;;
    }
    else
    {
        pthread_mutex_lock(&my_wmm->thr_stop_mutex);
        while(!my_wmm->stop_flag)
        {
            pthread_cond_wait(&my_wmm->thr_stop_cond, &my_wmm->thr_stop_mutex);
        }
        pthread_mutex_unlock(&my_wmm->thr_stop_mutex);
        my_wmm->stop_flag = 0;
        gtgWmmPS = 0;
        close(psSockfd);;
        psSockfd = -1;
        signal(14, ((__sighandler_t) 1));
        sleep(1);
    }
    return 0;
}

canonical_original_code:
int WfaRcvVOCyclic(unsigned int *rmsg, int length, int *state)
{
    int r;
    struct _tg_wmm *my_wmm = &wmm_thr[wmmps_info.ps_thread];
    if(rmsg[10] != (((((37 + 0x01) + 0x01) + 0x01) + 0x01) + 0x01))
    {
        if ((r=receiver(rmsg,length,0xD0,(37 + 0x01)))>=0)
            ;
        else
            ;;
    }
    else
    {
        pthread_mutex_lock(&my_wmm->thr_stop_mutex);
        while(!my_wmm->stop_flag)
        {
            pthread_cond_wait(&my_wmm->thr_stop_cond, &my_wmm->thr_stop_mutex);
        }
        pthread_mutex_unlock(&my_wmm->thr_stop_mutex);
        my_wmm->stop_flag = 0;
        gtgWmmPS = 0;
        close(psSockfd);;
        psSockfd = -1;
        signal(14, ((void (*)(int)) 1));
        sleep(1);
    }
    return 0;
}

variable_types: r int

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


original_code:
void create_apts_msg(int msg, unsigned int txbuf[],int id)
{
   struct apts_msg *t;
   t = &apts_msgs[msg];
   txbuf[ 0] = wmmps_info.my_cookie;
   txbuf[ 1] = wmmps_info.dscp;
   txbuf[ 2] = 0;
   txbuf[ 3] = 0;
   txbuf[ 4] = 0;
   txbuf[ 5] = 0;
   txbuf[ 9] = id;
   txbuf[ 10] = t->cmd;
   strcpy((char *)&txbuf[11], t->name);
   ;;
}

canonical_original_code:
void create_apts_msg(int msg, unsigned int txbuf[], int id)
{
   struct apts_msg *t;
   t = &apts_msgs[msg];
   txbuf[ 0] = wmmps_info.my_cookie;
   txbuf[ 1] = wmmps_info.dscp;
   txbuf[ 2] = 0;
   txbuf[ 3] = 0;
   txbuf[ 4] = 0;
   txbuf[ 5] = 0;
   txbuf[ 9] = id;
   txbuf[ 10] = t->cmd;
   strcpy((char *)&txbuf[11], t->name);
   ;;
}

variable_types: msg int

variable_types:
txbuf
unsigned int []

variable_types: id int

variable_types: struct apts_msg { char *name; int cmd; int param0; int param1; int param2; int param3; } *


decompiled_code:
int __fastcall print_hex_string(unsigned __int8 *a1, int a2)
{
int result; // eax
__int64 i; // rbx

if ( !a2 )
return printf("<empty string>");
if ( a2 > 0 )
{
result = printf("%02x ", *a1);
for ( i = 1LL; a2 != i; ++i )
{
printf("%02x ", a1[i]);
result = i & 0xF;
if ( result == 15 )
result = printf("\n ");
}
if ( (a2 & 0xF) != 0 )
result = putchar(10);
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(unsigned __int8 *a1, int a2)
{
int result; // eax
__int64 i; // rbx

if ( !a2 )
return printf("<empty string>");
if ( a2 > 0 )
{
result = printf("%02x ", *a1);
for ( i = 1LL; a2 != i; ++i )
{
printf("%02x ", a1[i]);
result = i & 0xF;
if ( result == 15 )
result = printf("\n ");
}
if ( (a2 & 0xF) != 0 )
result = putchar(10);
}
return result;
}

original_code:
void print_hex_string(char* buf, int len)
{
   int i;
   if (len==0)
   {
      printf("<empty string>"); return;
   }
   for (i = 0; i < len; i++)
   {
      printf("%02x ", *((unsigned char *)buf + i));
      if ((i&0xf)==15)
         printf("\n   ");
   }
   if ((i&0xf))
      printf("\n");
}

canonical_original_code:
void print_hex_string(char *buf, int len)
{
   int i;
   if (len==0)
   {
      printf("<empty string>"); return;
   }
   for (i = 0; i < len; i++)
   {
      printf("%02x ", *((unsigned char *)buf + i));
      if ((i&0xf)==15)
         printf("\n   ");
   }
   if ((i&0xf))
      printf("\n");
}

variable_types:
buf
char *

variable_types: len int

variable_types: i int


mpx

decompiled_code:
int __fastcall mpx(const char *a1, __int64 a2, int a3)
{
printf("%s MSG: %s\n ", a1, (const char *)(a2 + 44));
return print_hex_string((unsigned __int8 *)a2, a3);
}

canonical_decompiled_code:
int __fastcall func4(const char *a1, __int64 a2, int a3)
{
printf("%s MSG: %s\n ", a1, (const char *)(a2 + 44));
return func3((unsigned __int8 *)a2, a3);
}

original_code:
void mpx(char *m, void *buf_v, int len)
{
   char *buf = buf_v;
   printf("%s   MSG: %s\n   ", m, &buf[44] );
   print_hex_string(buf, len);
}

variable_types:
m
char *


WfaRcvProc

decompiled_code:
__int64 __fastcall WfaRcvProc(__int64 a1, __int64 a2, _DWORD *a3)
{
int v4; // er12
int v5; // er13
__int64 v6; // rbx
__int64 v7; // r13

v4 = *((_DWORD *)&wmmps_info + 10);
num_hello = 0;
v5 = *(_DWORD *)(a1 + 40);
mpx("STA recv\n", a1, 64);
if ( (unsigned int)(v5 - 1) > 0x24 )
return 0xFFFFFFFFLL;
*((_DWORD *)&wmmps_info + 5) = *(_DWORD *)(a1 + 40);
*(_DWORD *)&wmmps_info.sa_family = *(_DWORD *)(a1 + 36);
v6 = 5LL * v4;
v7 = 20LL * v4;
pthread_mutex_lock((pthread_mutex_t *)((char *)&wmm_thr + 8 * v6 + 8 * v7 + 120));
*((_DWORD *)&wmm_thr + 2 * v7 + 2 * v6) = *((_DWORD *)&wmmps_info + 14);
pthread_mutex_unlock((pthread_mutex_t *)((char *)&wmm_thr + 8 * v6 + 8 * v7 + 120));
++*a3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, _DWORD *a3)
{
int v4; // er12
int v5; // er13
__int64 v6; // rbx
__int64 v7; // r13

v4 = *((_DWORD *)&wmmps_info + 10);
num_hello = 0;
v5 = *(_DWORD *)(a1 + 40);
func4("STA recv\n", a1, 64);
if ( (unsigned int)(v5 - 1) > 0x24 )
return 0xFFFFFFFFLL;
*((_DWORD *)&wmmps_info + 5) = *(_DWORD *)(a1 + 40);
*(_DWORD *)&wmmps_info.sa_family = *(_DWORD *)(a1 + 36);
v6 = 5LL * v4;
v7 = 20LL * v4;
pthread_mutex_lock((pthread_mutex_t *)((char *)&wmm_thr + 8 * v6 + 8 * v7 + 120));
*((_DWORD *)&wmm_thr + 2 * v7 + 2 * v6) = *((_DWORD *)&wmmps_info + 14);
pthread_mutex_unlock((pthread_mutex_t *)((char *)&wmm_thr + 8 * v6 + 8 * v7 + 120));
++*a3;
return 0LL;
}

original_code:
int WfaRcvProc(unsigned int *rmsg,int length,int *state)
{
    int sta_test;
    int usedThread = wmmps_info.ps_thread;
    num_hello=0;
    sta_test = rmsg[10];
    mpx("STA recv\n", rmsg, 64);
    if(!((sta_test >=1)&&(sta_test <= 37)))
    {
   return -1;
    }
    wmmps_info.sta_test = rmsg[10];
    wmmps_info.my_sta_id = rmsg[9];
    pthread_mutex_lock(&wmm_thr[usedThread].thr_flag_mutex);
    wmm_thr[usedThread].thr_flag = wmmps_info.streamid;
    pthread_mutex_unlock(&wmm_thr[usedThread].thr_flag_mutex);
    (*state)++;
    return 0;
}

canonical_original_code:
int WfaRcvProc(unsigned int *rmsg, int length, int *state)
{
    int sta_test;
    int usedThread = wmmps_info.ps_thread;
    num_hello=0;
    sta_test = rmsg[10];
    mpx("STA recv\n", rmsg, 64);
    if(!((sta_test >=1)&&(sta_test <= 37)))
    {
   return -1;
    }
    wmmps_info.sta_test = rmsg[10];
    wmmps_info.my_sta_id = rmsg[9];
    pthread_mutex_lock(&wmm_thr[usedThread].thr_flag_mutex);
    wmm_thr[usedThread].thr_flag = wmmps_info.streamid;
    pthread_mutex_unlock(&wmm_thr[usedThread].thr_flag_mutex);
    (*state)++;
    return 0;
}

variable_types: usedThread int


receiver

decompiled_code:
__int64 __fastcall receiver(__int64 a1, __int64 a2, __int64 a3, int a4)
{
__int64 result; // rax

result = 1LL;
if ( *(_DWORD *)(a1 + 40) != a4 )
result = 4294967290LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3, int a4)
{
__int64 result; // rax

result = 1LL;
if ( *(_DWORD *)(a1 + 40) != a4 )
result = 4294967290LL;
return result;
}

original_code:
int receiver(unsigned int *rmsg,int length,int tos,unsigned int type)
{
   int r=1;
   if(rmsg[10] != type)
   {
      ;;
      r=-6;
   }
   return r;
}

canonical_original_code:
int receiver(unsigned int *rmsg, int length, int tos, unsigned int type)
{
   int r = 1;
   if(rmsg[10] != type)
   {
      ;;
      r=-6;
   }
   return r;
}

variable_types: tos int

variable_types:
type
unsigned int


WfaStaResetAll

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

if ( ++num_retry > 3 )
{
create_apts_msg(49, (__int64)&psTxMsg, *(int *)&wmmps_info.sa_family);
((void (__fastcall *)(_QWORD, __int64))wfaTGSetPrio.__align)((unsigned int)psSockfd, 1LL);
sendto(psSockfd, &psTxMsg, msgsize, 0, (const struct sockaddr *)(unsigned int)((_DWORD)&wmmps_info + 72), 0x10u);
mpx("STA msg", (__int64)&psTxMsg, 64);
puts("Too many retries");
}
if ( reset_recd )
{
create_apts_msg(48, (__int64)&psTxMsg, *(int *)&wmmps_info.sa_family);
((void (__fastcall *)(_QWORD, __int64))wfaTGSetPrio.__align)((unsigned int)psSockfd, 1LL);
sendto(psSockfd, &psTxMsg, msgsize, 0, (const struct sockaddr *)(unsigned int)((_DWORD)&wmmps_info + 72), 0x10u);
result = mpx("STA msg", (__int64)&psTxMsg, 64);
reset_recd = 0;
}
else
{
create_apts_msg(47, (__int64)&psTxMsg, *(int *)&wmmps_info.sa_family);
((void (__fastcall *)(_QWORD, __int64))wfaTGSetPrio.__align)((unsigned int)psSockfd, 1LL);
*((_DWORD *)&psTxMsg + 1) = 0;
sendto(psSockfd, &psTxMsg, msgsize, 0, (const struct sockaddr *)(unsigned int)((_DWORD)&wmmps_info + 72), 0x10u);
result = mpx("STA msg", (__int64)&psTxMsg, 64);
}
resetsnd = 1;
resetrcv = 1;
return result;
}

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

if ( ++num_retry > 3 )
{
func2(49, (__int64)&psTxMsg, *(int *)&wmmps_info.sa_family);
((void (__fastcall *)(_QWORD, __int64))wfaTGSetPrio.__align)((unsigned int)psSockfd, 1LL);
sendto(psSockfd, &psTxMsg, msgsize, 0, (const struct sockaddr *)(unsigned int)((_DWORD)&wmmps_info + 72), 0x10u);
func4("STA msg", (__int64)&psTxMsg, 64);
puts("Too many retries");
}
if ( reset_recd )
{
func2(48, (__int64)&psTxMsg, *(int *)&wmmps_info.sa_family);
((void (__fastcall *)(_QWORD, __int64))wfaTGSetPrio.__align)((unsigned int)psSockfd, 1LL);
sendto(psSockfd, &psTxMsg, msgsize, 0, (const struct sockaddr *)(unsigned int)((_DWORD)&wmmps_info + 72), 0x10u);
result = func4("STA msg", (__int64)&psTxMsg, 64);
reset_recd = 0;
}
else
{
func2(47, (__int64)&psTxMsg, *(int *)&wmmps_info.sa_family);
((void (__fastcall *)(_QWORD, __int64))wfaTGSetPrio.__align)((unsigned int)psSockfd, 1LL);
*((_DWORD *)&psTxMsg + 1) = 0;
sendto(psSockfd, &psTxMsg, msgsize, 0, (const struct sockaddr *)(unsigned int)((_DWORD)&wmmps_info + 72), 0x10u);
result = func4("STA msg", (__int64)&psTxMsg, 64);
}
resetsnd = 1;
resetrcv = 1;
return result;
}

original_code:
void WfaStaResetAll()
{
    int r;
    ;;
    num_retry++;
    if(num_retry > 3)
    {
        create_apts_msg(((((((((((((37 + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01), psTxMsg,wmmps_info.my_sta_id);
        wfaTGSetPrio(psSockfd, 1);
        r = sendto(psSockfd, psTxMsg, msgsize, 0, (struct sockaddr *)&wmmps_info.psToAddr, sizeof(struct sockaddr));
        mpx("STA msg",psTxMsg,64);
        printf("Too many retries\n");
    }
    if(!reset_recd)
    {
        create_apts_msg(((((((((((37 + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01), psTxMsg,wmmps_info.my_sta_id);
        wfaTGSetPrio(psSockfd, 1);
        psTxMsg[1] = 0x00;
        r = sendto(psSockfd, psTxMsg, msgsize, 0, (struct sockaddr *)&wmmps_info.psToAddr, sizeof(struct sockaddr));
        mpx("STA msg",psTxMsg,64);
    }
    else
    {
        create_apts_msg((((((((((((37 + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01), psTxMsg,wmmps_info.my_sta_id);
        wfaTGSetPrio(psSockfd, 1);
        r = sendto(psSockfd, psTxMsg, msgsize, 0, (struct sockaddr *)&wmmps_info.psToAddr, sizeof(struct sockaddr));
        mpx("STA msg",psTxMsg,64);
        reset_recd=0;
    }
    resetsnd=1;
    resetrcv=1;
}

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


WfaRcvNotCare

decompiled_code:
__int64 __fastcall WfaRcvNotCare(__int64 a1, __int64 a2, _DWORD *a3)
{
if ( (int)receiver(a1, a2, 208LL, 38) >= 0
|| (int)receiver(a1, (unsigned int)a2, 160LL, 38) >= 0
|| (int)receiver(a1, (unsigned int)a2, 0LL, 38) >= 0
|| (int)receiver(a1, (unsigned int)a2, 32LL, 38) >= 0 )
{
++*a3;
}
else
{
WfaStaResetAll();
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2, _DWORD *a3)
{
if ( (int)func6(a1, a2, 208LL, 38) >= 0
|| (int)func6(a1, (unsigned int)a2, 160LL, 38) >= 0
|| (int)func6(a1, (unsigned int)a2, 0LL, 38) >= 0
|| (int)func6(a1, (unsigned int)a2, 32LL, 38) >= 0 )
{
++*a3;
}
else
{
func7();
}
return 0LL;
}

original_code:
int WfaRcvNotCare(unsigned int *rmsg,int length,int *state)
{
    int r;
    if ((r=receiver(rmsg,length,0xD0,(37 + 0x01)))>=0 ||
          (r=receiver(rmsg,length,0xA0,(37 + 0x01)))>=0 ||
   (r=receiver(rmsg,length,0x00,(37 + 0x01)))>=0 ||
   (r=receiver(rmsg,length,0x20,(37 + 0x01)))>=0 )
    {
        (*state)++;
    }
    else
    {
        ;;
        WfaStaResetAll();
    }
    return 0;
}

canonical_original_code:
int WfaRcvNotCare(unsigned int *rmsg, int length, int *state)
{
    int r;
    if ((r=receiver(rmsg,length,0xD0,(37 + 0x01)))>=0 ||
          (r=receiver(rmsg,length,0xA0,(37 + 0x01)))>=0 ||
   (r=receiver(rmsg,length,0x00,(37 + 0x01)))>=0 ||
   (r=receiver(rmsg,length,0x20,(37 + 0x01)))>=0 )
    {
        (*state)++;
    }
    else
    {
        ;;
        WfaStaResetAll();
    }
    return 0;
}


WfaRcvVO

decompiled_code:
__int64 __fastcall WfaRcvVO(__int64 a1, __int64 a2, _DWORD *a3)
{
if ( (int)receiver(a1, a2, 208LL, 38) < 0 )
WfaStaResetAll();
else
++*a3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, _DWORD *a3)
{
if ( (int)func6(a1, a2, 208LL, 38) < 0 )
func7();
else
++*a3;
return 0LL;
}

original_code:
int WfaRcvVO(unsigned int *rmsg,int length,int *state)
{
    int r;
    if ((r=receiver(rmsg,length,0xD0,(37 + 0x01)))>=0)
        (*state)++;
    else
    {
        ;;
        WfaStaResetAll();
    }
    return 0;
}

canonical_original_code:
int WfaRcvVO(unsigned int *rmsg, int length, int *state)
{
    int r;
    if ((r=receiver(rmsg,length,0xD0,(37 + 0x01)))>=0)
        (*state)++;
    else
    {
        ;;
        WfaStaResetAll();
    }
    return 0;
}


WfaRcvVI

decompiled_code:
__int64 __fastcall WfaRcvVI(__int64 a1, __int64 a2, _DWORD *a3)
{
if ( (int)receiver(a1, a2, 160LL, 38) >= 0 )
++*a3;
return 0LL;
}

original_code:
int WfaRcvVI(unsigned int *rmsg,int length,int *state)
{
    int r;
    if ((r=receiver(rmsg,length,0xA0,(37 + 0x01)))>=0)
        (*state)++;
    else
        ;;
    return 0;
}

canonical_original_code:
int WfaRcvVI(unsigned int *rmsg, int length, int *state)
{
    int r;
    if ((r=receiver(rmsg,length,0xA0,(37 + 0x01)))>=0)
        (*state)++;
    else
        ;;
    return 0;
}


WfaRcvBE

decompiled_code:
__int64 __fastcall WfaRcvBE(__int64 a1, __int64 a2, _DWORD *a3)
{
if ( (int)receiver(a1, a2, 0LL, 38) >= 0 )
++*a3;
return 0LL;
}

original_code:
int WfaRcvBE(unsigned int *rmsg,int length,int *state)
{
    int r;
    if ((r=receiver(rmsg,length,0x00,(37 + 0x01)))>=0)
        (*state)++;
    else
    {
        ;;
    }
    return 0;
}

canonical_original_code:
int WfaRcvBE(unsigned int *rmsg, int length, int *state)
{
    int r;
    if ((r=receiver(rmsg,length,0x00,(37 + 0x01)))>=0)
        (*state)++;
    else
    {
        ;;
    }
    return 0;
}


WfaRcvBK

decompiled_code:
__int64 __fastcall WfaRcvBK(__int64 a1, __int64 a2, _DWORD *a3)
{
if ( (int)receiver(a1, a2, 32LL, 38) >= 0 )
++*a3;
return 0LL;
}

original_code:
int WfaRcvBK(unsigned int *rmsg,int length,int *state)
{
    int r;
    if ((r=receiver(rmsg,length,0x20,(37 + 0x01)))>=0)
        (*state)++;
    else
        ;;
    return 0;
}

canonical_original_code:
int WfaRcvBK(unsigned int *rmsg, int length, int *state)
{
    int r;
    if ((r=receiver(rmsg,length,0x20,(37 + 0x01)))>=0)
        (*state)++;
    else
        ;;
    return 0;
}


decompiled_code:
char *__fastcall BUILD_APTS_MSG(int a1, __int64 a2)
{
int v2; // eax
__int64 v3; // rax

v2 = *((_DWORD *)&wmmps_info + 9);
*((_DWORD *)&wmmps_info + 9) = v2 + 1;
*(_QWORD *)a2 = v2;
*(_QWORD *)(a2 + 8) = 0LL;
*(_QWORD *)(a2 + 16) = 0LL;
*(_QWORD *)(a2 + 24) = 0LL;
*(_QWORD *)(a2 + 32) = 0LL;
*(_QWORD *)(a2 + 40) = 0LL;
v3 = 4LL * a1;
*(_QWORD *)(a2 + 48) = SHIDWORD(apts_msgs[v3 + 1]);
*(_QWORD *)(a2 + 56) = SLODWORD(apts_msgs[v3 + 2]);
*(_QWORD *)(a2 + 64) = SHIDWORD(apts_msgs[v3 + 2]);
*(_QWORD *)(a2 + 72) = SLODWORD(apts_msgs[v3 + 3]);
*(_QWORD *)(a2 + 80) = SLODWORD(apts_msgs[v3 + 1]);
return strcpy((char *)(a2 + 88), (const char *)apts_msgs[v3]);
}

canonical_decompiled_code:
char *__fastcall func13(int a1, __int64 a2)
{
int v2; // eax
__int64 v3; // rax

v2 = *((_DWORD *)&wmmps_info + 9);
*((_DWORD *)&wmmps_info + 9) = v2 + 1;
*(_QWORD *)a2 = v2;
*(_QWORD *)(a2 + 8) = 0LL;
*(_QWORD *)(a2 + 16) = 0LL;
*(_QWORD *)(a2 + 24) = 0LL;
*(_QWORD *)(a2 + 32) = 0LL;
*(_QWORD *)(a2 + 40) = 0LL;
v3 = 4LL * a1;
*(_QWORD *)(a2 + 48) = SHIDWORD(apts_msgs[v3 + 1]);
*(_QWORD *)(a2 + 56) = SLODWORD(apts_msgs[v3 + 2]);
*(_QWORD *)(a2 + 64) = SHIDWORD(apts_msgs[v3 + 2]);
*(_QWORD *)(a2 + 72) = SLODWORD(apts_msgs[v3 + 3]);
*(_QWORD *)(a2 + 80) = SLODWORD(apts_msgs[v3 + 1]);
return strcpy((char *)(a2 + 88), (const char *)apts_msgs[v3]);
}

original_code:
void BUILD_APTS_MSG(int msg, unsigned long *txbuf)
{
   struct apts_msg *t;
   t = &apts_msgs[msg];
   txbuf[0] = wmmps_info.msgno++;
   txbuf[1] = 0;
   txbuf[2] = 0;
   txbuf[3] = 0;
   txbuf[4] = 0;
   txbuf[5] = 0;
   txbuf[6] = t->param0;
   txbuf[7] = t->param1;
   txbuf[8] = t->param2;
   txbuf[9] = t->param3;
   txbuf[10] = t->cmd;
   strcpy((char *)&txbuf[11], t->name);
}

variable_types:
txbuf
unsigned long *

user_defined_types: struct apts_msg { char *name; int cmd; int param0; int param1; int param2; int param3; }


decompiled_code:
__int64 __fastcall send_txmsg(int a1)
{
int v1; // eax
int v2; // ecx
int v3; // edx
__int64 result; // rax

v1 = 0;
if ( a1 >= 0 )
v1 = ((__int64 (__fastcall *)(_QWORD, _QWORD))wfaTGSetPrio.__align)((unsigned int)psSockfd, (unsigned int)a1);
v2 = *((_DWORD *)&wmmps_info + 9);
v3 = v2 + 1;
*((_DWORD *)&wmmps_info + 9) = v2 + 1;
psTxMsg[0] = v2;
psTxMsg[1] = v1;
psTxMsg[2] = *(_DWORD *)&wmmps_info.sa_data[2];
psTxMsg[3] = *(_DWORD *)&wmmps_info.sa_data[6];
psTxMsg[4] = *(_DWORD *)&wmmps_info.sa_family;
if ( psTxMsg[10] == 38 )
psTxMsg[13] = v3 % 10 + 538976304;
result = wfaTrafficSendTo(
(unsigned int)psSockfd,
psTxMsg,
(unsigned int)(v3 % 200 + 200),
(unsigned int)((_DWORD)&wmmps_info + 72));
++*((_DWORD *)&wmmps_info + 8);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(int a1)
{
int v1; // eax
int v2; // ecx
int v3; // edx
__int64 result; // rax

v1 = 0;
if ( a1 >= 0 )
v1 = ((__int64 (__fastcall *)(_QWORD, _QWORD))wfaTGSetPrio.__align)((unsigned int)psSockfd, (unsigned int)a1);
v2 = *((_DWORD *)&wmmps_info + 9);
v3 = v2 + 1;
*((_DWORD *)&wmmps_info + 9) = v2 + 1;
psTxMsg[0] = v2;
psTxMsg[1] = v1;
psTxMsg[2] = *(_DWORD *)&wmmps_info.sa_data[2];
psTxMsg[3] = *(_DWORD *)&wmmps_info.sa_data[6];
psTxMsg[4] = *(_DWORD *)&wmmps_info.sa_family;
if ( psTxMsg[10] == 38 )
psTxMsg[13] = v3 % 10 + 538976304;
result = wfaTrafficSendTo(
(unsigned int)psSockfd,
psTxMsg,
(unsigned int)(v3 % 200 + 200),
(unsigned int)((_DWORD)&wmmps_info + 72));
++*((_DWORD *)&wmmps_info + 8);
return result;
}

original_code:
void send_txmsg(int new_prio_class)
{
   int r;
   int new_dscp = 0;
   if(new_prio_class > -1)
      new_dscp = wfaTGSetPrio(psSockfd, new_prio_class);
   psTxMsg[0] = wmmps_info.msgno++;
   psTxMsg[1] = new_dscp;
   psTxMsg[2] = wmmps_info.my_group_cookie;
   psTxMsg[3] = wmmps_info.my_cookie;
   psTxMsg[4] = wmmps_info.my_sta_id;
   if(psTxMsg[10] == (37 + 0x01))
   {
      psTxMsg[13] = (wmmps_info.msgno%10) + 0x20202030;
   }
   r = wfaTrafficSendTo(psSockfd, (char *)psTxMsg, 200+(wmmps_info.msgno%200), (struct sockaddr *) &wmmps_info.psToAddr);
   wmmps_info.nsent++;
}


wfaSetDUTPwrMgmt

decompiled_code:
int __fastcall wfaSetDUTPwrMgmt(int a1)
{
int result; // eax
__int64 v2[3]; // [rsp+0h] [rbp-28h] BYREF
int v3; // [rsp+18h] [rbp-10h]
__int16 v4; // [rsp+1Ch] [rbp-Ch]
char v5; // [rsp+1Eh] [rbp-Ah]

result = 1851878519;
v2[0] = 0x306E616C77LL;
v2[1] = 0LL;
v2[2] = 0LL;
v3 = 0;
v4 = 0;
v5 = 0;
if ( curr_mode_0 != a1 )
{
if ( a1 )
{
sprintf(gCmdStr, "iwconfig %s power on", (const char *)v2);
if ( system(gCmdStr) < 0 )
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_wmmps.c", 823LL);
result = fwrite("Cant Set PS ON\n", 1uLL, 0xFuLL, stderr);
}
else
{
result = puts("\r\n STA PS ON ");
}
}
else
{
sprintf(gCmdStr, "iwconfig %s power off", (const char *)v2);
if ( system(gCmdStr) < 0 )
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_wmmps.c", 812LL);
result = fwrite("Cant Set PS OFF\n", 1uLL, 0x10uLL, stderr);
}
else
{
result = puts("\r\n STA PS OFF ");
}
}
curr_mode_0 = a1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func15(int a1)
{
int result; // eax
__int64 v2[3]; // [rsp+0h] [rbp-28h] BYREF
int v3; // [rsp+18h] [rbp-10h]
__int16 v4; // [rsp+1Ch] [rbp-Ch]
char v5; // [rsp+1Eh] [rbp-Ah]

result = 1851878519;
v2[0] = 0x306E616C77LL;
v2[1] = 0LL;
v2[2] = 0LL;
v3 = 0;
v4 = 0;
v5 = 0;
if ( curr_mode_0 != a1 )
{
if ( a1 )
{
sprintf(gCmdStr, "iwconfig %s power on", (const char *)v2);
if ( system(gCmdStr) < 0 )
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_wmmps.c", 823LL);
result = fwrite("Cant Set PS ON\n", 1uLL, 0xFuLL, stderr);
}
else
{
result = puts("\r\n STA PS ON ");
}
}
else
{
sprintf(gCmdStr, "iwconfig %s power off", (const char *)v2);
if ( system(gCmdStr) < 0 )
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_wmmps.c", 812LL);
result = fwrite("Cant Set PS OFF\n", 1uLL, 0x10uLL, stderr);
}
else
{
result = puts("\r\n STA PS OFF ");
}
}
curr_mode_0 = a1;
}
return result;
}

original_code:
void wfaSetDUTPwrMgmt(int mode)
{
   static int curr_mode = -1;
   char iface[32];
   strncpy(iface, "wlan0", 31);
   if(curr_mode == mode)
   {
      return;
   }
   if(mode == 0)
   {
      sprintf(gCmdStr, "iwconfig %s power off", iface);
      if( system(gCmdStr) < 0)
      {
         fprintf(stderr, "File %s, Line %ld: ", "wfa_wmmps.c", (long)812); fprintf(stderr, "Cant Set PS OFF\n");
      }
      else
         printf("\r\n STA PS OFF \n");
   }
   else
   {
      sprintf(gCmdStr, "iwconfig %s power on", iface);
      if( system(gCmdStr) < 0)
      {
         fprintf(stderr, "File %s, Line %ld: ", "wfa_wmmps.c", (long)823); fprintf(stderr, "Cant Set PS ON\n");
      }
      else
      {
         printf("\r\n STA PS ON \n");
      }
   }
   curr_mode = mode;
}

variable_types: mode int

variable_types:
iface
char [32]


wfaWmmPowerSaveProcess

decompiled_code:
__int64 __fastcall wfaWmmPowerSaveProcess(int a1)
{
int v1; // eax
unsigned int v2; // ebx
int v3; // er12
int v4; // eax
unsigned int v5; // ebp
socklen_t addr_len; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

addr_len = 16;
v1 = recvfrom(a1, psRxMsg, 0x800uLL, 0, &addr, &addr_len);
if ( v1 < 0 )
{
v5 = v1;
perror("receive error");
return v5;
}
v2 = v1;
v3 = *((_DWORD *)&wmmps_info + 5);
if ( v3 != 8 )
mpx("RX msg", (__int64)psRxMsg, 64);
v4 = psRxMsg[10];
if ( v4 == 47 )
{
reset_recd = 1;
WfaStaResetAll();
return 0;
}
if ( resetrcv )
{
*((_DWORD *)&wmmps_info + 11) = 0;
if ( !reset_recd )
{
v5 = 0;
if ( v4 != 48 )
return v5;
}
resetrcv = 0;
reset_recd = 0;
}
v5 = 0;
if ( v3 <= 37 )
{
*(_DWORD *)&wmmps_info.sa_data[6] = psRxMsg[0];
((void (__fastcall *)(_DWORD *, _QWORD, _QWORD))*(&stationRecvProcStatetbl[6 * *((int *)&wmmps_info + 5)]
+ *((int *)&wmmps_info + 11)))(
psRxMsg,
v2,
(unsigned int)((_DWORD)&wmmps_info + 44));
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func16(int a1)
{
int v1; // eax
unsigned int v2; // ebx
int v3; // er12
int v4; // eax
unsigned int v5; // ebp
socklen_t addr_len; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

addr_len = 16;
v1 = recvfrom(a1, psRxMsg, 0x800uLL, 0, &addr, &addr_len);
if ( v1 < 0 )
{
v5 = v1;
perror("receive error");
return v5;
}
v2 = v1;
v3 = *((_DWORD *)&wmmps_info + 5);
if ( v3 != 8 )
func4("RX msg", (__int64)psRxMsg, 64);
v4 = psRxMsg[10];
if ( v4 == 47 )
{
reset_recd = 1;
func7();
return 0;
}
if ( resetrcv )
{
*((_DWORD *)&wmmps_info + 11) = 0;
if ( !reset_recd )
{
v5 = 0;
if ( v4 != 48 )
return v5;
}
resetrcv = 0;
reset_recd = 0;
}
v5 = 0;
if ( v3 <= 37 )
{
*(_DWORD *)&wmmps_info.sa_data[6] = psRxMsg[0];
((void (__fastcall *)(_DWORD *, _QWORD, _QWORD))*(&stationRecvProcStatetbl[6 * *((int *)&wmmps_info + 5)]
+ *((int *)&wmmps_info + 11)))(
psRxMsg,
v2,
(unsigned int)((_DWORD)&wmmps_info + 44));
}
return v5;
}

original_code:
int wfaWmmPowerSaveProcess(int sockfd)
{
   int rbytes = 0;
   int sta_test;
   struct sockaddr from;
   int len;
   StationRecvProcStatetbl_t *rcvstatarray;
   StationRecvProcStatetbl_t func;
   int *rcv_state;
   len=sizeof(from);
   rbytes = recvfrom(sockfd, (char *)psRxMsg, 2048, 0, &from, (socklen_t *)&len);
   if(rbytes < 0)
   {
      perror("receive error");
      return rbytes;
   }
   sta_test = wmmps_info.sta_test;
   if(sta_test != 8)
   mpx("RX msg",psRxMsg,64);
   if(psRxMsg[10] == (((((37 + 0x01) + 0x01) + 0x01) + 0x01) + 0x01))
      ;;
   if(psRxMsg[10] == ((((((((((37 + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01))
   {
      reset_recd=1;
      WfaStaResetAll();
      return 0;
   }
   if(resetrcv)
   {
      wmmps_info.rcv_state = 0;
      if((!reset_recd)&&(psRxMsg[10] != (((((((((((37 + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01)))
         return 0;
      else
      {
         resetrcv = 0;
         reset_recd = 0;
      }
   }
   if(sta_test > 37)
   {
      return 0;
   }
   sta_test = wmmps_info.sta_test;
   wmmps_info.my_cookie = psRxMsg[0];
   rcv_state = &(wmmps_info.rcv_state);
   rcvstatarray = stationRecvProcStatetbl[sta_test];
   func = rcvstatarray[*(rcv_state)];
   func.statefunc(psRxMsg,rbytes,rcv_state);
   return WFA_SUCCESS;
}

canonical_original_code:
int wfaWmmPowerSaveProcess(int sockfd)
{
   int rbytes = 0;
   int sta_test;
   struct sockaddr from;
   int len;
   struct console_rcv_state_table *rcvstatarray;
   struct console_rcv_state_table func;
   int *rcv_state;
   len=sizeof(from);
   rbytes = recvfrom(sockfd, (char *)psRxMsg, 2048, 0, &from, (unsigned int *)&len);
   if(rbytes < 0)
   {
      perror("receive error");
      return rbytes;
   }
   sta_test = wmmps_info.sta_test;
   if(sta_test != 8)
   mpx("RX msg",psRxMsg,64);
   if(psRxMsg[10] == (((((37 + 0x01) + 0x01) + 0x01) + 0x01) + 0x01))
      ;;
   if(psRxMsg[10] == ((((((((((37 + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01))
   {
      reset_recd=1;
      WfaStaResetAll();
      return 0;
   }
   if(resetrcv)
   {
      wmmps_info.rcv_state = 0;
      if((!reset_recd)&&(psRxMsg[10] != (((((((((((37 + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01)))
         return 0;
      else
      {
         resetrcv = 0;
         reset_recd = 0;
      }
   }
   if(sta_test > 37)
   {
      return 0;
   }
   sta_test = wmmps_info.sta_test;
   wmmps_info.my_cookie = psRxMsg[0];
   rcv_state = &(wmmps_info.rcv_state);
   rcvstatarray = stationRecvProcStatetbl[sta_test];
   func = rcvstatarray[*(rcv_state)];
   func.statefunc(psRxMsg,rbytes,rcv_state);
   return WFA_SUCCESS;
}

variable_types: sockfd int

variable_types: rbytes int

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

variable_types: struct console_rcv_state_table { int (*statefunc)(unsigned int *, int, int *); } *