WfaStaSndVI

decompiled_code:
__int64 __fastcall WfaStaSndVI(char a1, unsigned int a2, _DWORD *a3)
{
__int64 v5; // rsi

v5 = (unsigned int)en_3++;
printf("\r\nEnterring WfastasndVI %d", v5);
if ( (int)sender(a1, a2, 3u) >= 0 )
++*a3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(char a1, unsigned int a2, _DWORD *a3)
{
__int64 v5; // rsi

v5 = (unsigned int)en_3++;
printf("\r\nEnterring WfastasndVI %d", v5);
if ( (int)func1(a1, a2, 3u) >= 0 )
++*a3;
return 0LL;
}

original_code:
int WfaStaSndVI(char psave,int sleep_period,int *state)
{
   int r;
   static int en=1;
   printf("\r\nEnterring WfastasndVI %d",en++);
   if ((r=sender(psave,sleep_period,3))>=0)
      (*state)++;
   return 0;
}

canonical_original_code:
int WfaStaSndVI(char psave, int sleep_period, int *state)
{
   int r;
   static int en = 1;
   printf("\r\nEnterring WfastasndVI %d",en++);
   if ((r=sender(psave,sleep_period,3))>=0)
      (*state)++;
   return 0;
}


WfaStaSndBE

decompiled_code:
__int64 __fastcall WfaStaSndBE(char a1, unsigned int a2, _DWORD *a3)
{
__int64 v5; // rsi

v5 = (unsigned int)en_2++;
printf("\r\nEnterring WfastasndBE %d", v5);
if ( (int)sender(a1, a2, 1u) >= 0 )
++*a3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(char a1, unsigned int a2, _DWORD *a3)
{
__int64 v5; // rsi

v5 = (unsigned int)en_2++;
printf("\r\nEnterring WfastasndBE %d", v5);
if ( (int)func1(a1, a2, 1u) >= 0 )
++*a3;
return 0LL;
}

original_code:
int WfaStaSndBE(char psave,int sleep_period,int *state)
{
   int r;
   static int en=1;
   printf("\r\nEnterring WfastasndBE %d",en++);
   if ((r=sender(psave,sleep_period,1))>=0)
      (*state)++;
   return 0;
}

canonical_original_code:
int WfaStaSndBE(char psave, int sleep_period, int *state)
{
   int r;
   static int en = 1;
   printf("\r\nEnterring WfastasndBE %d",en++);
   if ((r=sender(psave,sleep_period,1))>=0)
      (*state)++;
   return 0;
}

variable_types: psave char

variable_types:
state
int *

variable_types: r int

variable_types: en int

return_type: int


WfaStaSndBK

decompiled_code:
__int64 __fastcall WfaStaSndBK(char a1, unsigned int a2, _DWORD *a3)
{
__int64 v5; // rsi

v5 = (unsigned int)en_1++;
printf("\r\nEnterring WfastasndBK %d", v5);
if ( (int)sender(a1, a2, 2u) >= 0 )
++*a3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(char a1, unsigned int a2, _DWORD *a3)
{
__int64 v5; // rsi

v5 = (unsigned int)en_1++;
printf("\r\nEnterring WfastasndBK %d", v5);
if ( (int)func1(a1, a2, 2u) >= 0 )
++*a3;
return 0LL;
}

original_code:
int WfaStaSndBK(char psave,int sleep_period,int *state)
{
   int r;
   static int en=1;
   printf("\r\nEnterring WfastasndBK %d",en++);
   if ((r=sender(psave,sleep_period,2))>=0)
      (*state)++;
   return 0;
}

canonical_original_code:
int WfaStaSndBK(char psave, int sleep_period, int *state)
{
   int r;
   static int en = 1;
   printf("\r\nEnterring WfastasndBK %d",en++);
   if ((r=sender(psave,sleep_period,2))>=0)
      (*state)++;
   return 0;
}


WfaStaSndVOCyclic

decompiled_code:
__int64 __fastcall WfaStaSndVOCyclic(char a1, unsigned int a2, _DWORD *a3)
{
int i; // ebx
__int64 v6; // rsi

for ( i = 0; i != 3000; ++i )
{
v6 = (unsigned int)en_0++;
printf("\r\nEnterring WfastasndVOCyclic %d", v6);
sender(a1, a2, 4u);
if ( i == 50 * (i / 50) )
{
putchar(46);
fflush(stdout);
}
}
++*a3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(char a1, unsigned int a2, _DWORD *a3)
{
int i; // ebx
__int64 v6; // rsi

for ( i = 0; i != 3000; ++i )
{
v6 = (unsigned int)en_0++;
printf("\r\nEnterring WfastasndVOCyclic %d", v6);
func1(a1, a2, 4u);
if ( i == 50 * (i / 50) )
{
putchar(46);
fflush(stdout);
}
}
++*a3;
return 0LL;
}

original_code:
int WfaStaSndVOCyclic(char psave,int sleep_period,int *state)
{
   int i;
   static int en=1;
   for(i=0;i<3000;i++)
   {
       printf("\r\nEnterring WfastasndVOCyclic %d",en++);
       sender(psave,sleep_period,4);
       if(!(i%50))
       {
         printf(".");
         fflush(stdout);
       }
   }
   (*state)++;
   return 0;
}

canonical_original_code:
int WfaStaSndVOCyclic(char psave, int sleep_period, int *state)
{
   int i;
   static int en = 1;
   for(i=0;i<3000;i++)
   {
       printf("\r\nEnterring WfastasndVOCyclic %d",en++);
       sender(psave,sleep_period,4);
       if(!(i%50))
       {
         printf(".");
         fflush(stdout);
       }
   }
   (*state)++;
   return 0;
}

variable_types: i int


decompiled_code:
unsigned int __fastcall asd_sleep(unsigned int a1)
{
return sleep(a1);
}

canonical_decompiled_code:
unsigned int __fastcall func0(unsigned int a1)
{
return sleep(a1);
}

original_code:
void
asd_sleep(int SleepTime)
{
 sleep(SleepTime);
}

variable_types: SleepTime int

return_type: void


decompiled_code:
int __fastcall uapsd_sleep(__useconds_t a1)
{
return usleep(a1);
}

canonical_decompiled_code:
int __fastcall func1(__useconds_t a1)
{
return usleep(a1);
}

original_code:
void
uapsd_sleep(int SleepTime)
{
 usleep(SleepTime);
}


decompiled_code:
int __fastcall asd_closeSocket(int a1)
{
return close(a1);
}

canonical_decompiled_code:
int __fastcall func2(int a1)
{
return close(a1);
}

original_code:
void
asd_closeSocket(int sockfd)
{
 close(sockfd);
}

variable_types: sockfd int


decompiled_code:
int __fastcall asd_shutDown(int a1)
{
return shutdown(a1, 1);
}

canonical_decompiled_code:
int __fastcall func3(int a1)
{
return shutdown(a1, 1);
}

original_code:
void
asd_shutDown(int Sockfd)
{
 shutdown(Sockfd, SHUT_WR);
}

variable_types: Sockfd int


decompiled_code:
int __fastcall exec_process(const char *a1)
{
return system(a1);
}

canonical_decompiled_code:
int __fastcall func4(const char *a1)
{
return system(a1);
}

original_code:
void
exec_process(char* command)
{
 system(command);
}

canonical_original_code:
void exec_process(char *command)
{
 system(command);
}

variable_types:
command
char *


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

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

original_code:
int
Start_Socket_Service()
{
 return 0;
}


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

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

original_code:
int
Stop_Socket_Service()
{
 return 0;
}

canonical_original_code:
int Stop_Socket_Service()
{
 return 0;
}


wfaGetSockOpt

decompiled_code:
int __fastcall wfaGetSockOpt(int a1, void *a2, socklen_t *a3)
{
return getsockopt(a1, 0, 1, a2, a3);
}

canonical_decompiled_code:
int __fastcall func7(int a1, void *a2, socklen_t *a3)
{
return getsockopt(a1, 0, 1, a2, a3);
}

original_code:
void
wfaGetSockOpt(int sockfd, int* tosval, socklen_t* size)
{
 getsockopt(sockfd, IPPROTO_IP, 1, tosval, size);
}

canonical_original_code:
void wfaGetSockOpt(int sockfd, int *tosval, unsigned int *size)
{
 getsockopt(sockfd, IPPROTO_IP, 1, tosval, size);
}

variable_types:
tosval
int *

variable_types:
size
unsigned int *


wfaSetSockOpt

decompiled_code:
int __fastcall wfaSetSockOpt(int a1, const void *a2, socklen_t a3)
{
return setsockopt(a1, 0, 1, a2, a3);
}

canonical_decompiled_code:
int __fastcall func8(int a1, const void *a2, socklen_t a3)
{
return setsockopt(a1, 0, 1, a2, a3);
}

original_code:
int
wfaSetSockOpt(int sockfd, int* tosval, int size)
{
 int sockOpt;
 sockOpt = setsockopt(sockfd, IPPROTO_IP, 1, tosval, size);
 return sockOpt;
}

canonical_original_code:
int wfaSetSockOpt(int sockfd, int *tosval, int size)
{
 int sockOpt;
 sockOpt = setsockopt(sockfd, IPPROTO_IP, 1, tosval, size);
 return sockOpt;
}

variable_types: size int

variable_types: sockOpt int


decompiled_code:
__int64 wfa_estimate_timer_latency()
{
int v0; // edx
int v1; // ecx
struct timeval v3; // [rsp+0h] [rbp-28h] BYREF
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

gettimeofday(&tv, 0LL);
usleep(0x4E20u);
gettimeofday(&v3, 0LL);
v0 = LODWORD(tv.tv_usec) + 20000;
if ( tv.tv_usec + 20000 <= 999999 )
{
v1 = tv.tv_sec;
}
else
{
v1 = LODWORD(tv.tv_sec) + 1;
v0 = LODWORD(tv.tv_usec) - 980000;
}
return (unsigned int)(LODWORD(v3.tv_usec) + 1000000 * (LODWORD(v3.tv_sec) - v1) - v0);
}

canonical_decompiled_code:
__int64 func9()
{
int v0; // edx
int v1; // ecx
struct timeval v3; // [rsp+0h] [rbp-28h] BYREF
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

gettimeofday(&tv, 0LL);
usleep(0x4E20u);
gettimeofday(&v3, 0LL);
v0 = LODWORD(tv.tv_usec) + 20000;
if ( tv.tv_usec + 20000 <= 999999 )
{
v1 = tv.tv_sec;
}
else
{
v1 = LODWORD(tv.tv_sec) + 1;
v0 = LODWORD(tv.tv_usec) - 980000;
}
return (unsigned int)(LODWORD(v3.tv_usec) + 1000000 * (LODWORD(v3.tv_sec) - v1) - v0);
}

original_code:
int
wfa_estimate_timer_latency()
{
 struct timeval t1, t2, tp2;
 int sleep=20000;
 int latency =0;
 gettimeofday(&t1, ((void *)0));
 usleep(sleep);
 gettimeofday(&t2, ((void *)0));
 tp2.tv_usec = t1.tv_usec + 20000;
 if( tp2.tv_usec >= 1000000)
 {
  tp2.tv_sec = t1.tv_sec +1;
  tp2.tv_usec -= 1000000;
 }
 else
  tp2.tv_sec = t1.tv_sec;
 return latency = (t2.tv_sec - tp2.tv_sec) * 1000000 + (t2.tv_usec - tp2.tv_usec);
}

canonical_original_code:
int wfa_estimate_timer_latency()
{
 struct timeval t1; struct timeval t2; struct timeval tp2;
 int sleep = 20000;
 int latency = 0;
 gettimeofday(&t1, ((void *)0));
 usleep(sleep);
 gettimeofday(&t2, ((void *)0));
 tp2.tv_usec = t1.tv_usec + 20000;
 if( tp2.tv_usec >= 1000000)
 {
  tp2.tv_sec = t1.tv_sec +1;
  tp2.tv_usec -= 1000000;
 }
 else
  tp2.tv_sec = t1.tv_sec;
 return latency = (t2.tv_sec - tp2.tv_sec) * 1000000 + (t2.tv_usec - tp2.tv_usec);
}

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

variable_types: sleep int

variable_types: latency int


GetWirelessAdapter

decompiled_code:
void __fastcall GetWirelessAdapter(char *dest)
{
int v1; // eax
int v2; // ebp
char *v3; // rcx
unsigned __int64 v4; // rdx
char *v5; // rbx
char *v6; // r13
struct utsname v7; // [rsp+0h] [rbp-5C8h] BYREF
int v8; // [rsp+190h] [rbp-438h] BYREF
char *src; // [rsp+198h] [rbp-430h]
char v10; // [rsp+1A0h] [rbp-428h] BYREF

uname(&v7);
if ( !strcmp(v7.machine, "i386") || !strcmp(v7.machine, "i686") || !strcmp(v7.machine, "i586") )
{
v1 = socket(2, 2, 0);
v2 = v1;
if ( v1 < 0 )
{
perror("socket");
}
else
{
v8 = 1024;
src = &v10;
if ( ioctl(v1, 0x8912uLL, &v8) < 0 )
{
perror("ioctl(SIOCGIFCONF)");
close(v2);
}
else
{
v3 = src;
v4 = v8 / 0x28uLL;
if ( (int)v4 <= 0 )
{
LABEL_10:
close(v2);
}
else
{
v5 = src;
v6 = &src[40 * (unsigned int)(v4 - 1) + 40];
while ( ioctl(v2, 0x8B01uLL, v5, v3) )
{
v5 += 40;
if ( v5 == v6 )
goto LABEL_10;
}
strncpy(dest, v5, 0x10uLL);
close(v2);
}
}
}
}
else
{
*(_QWORD *)dest = 828929125LL;
*((_DWORD *)dest + 2) = 0;
*((_WORD *)dest + 6) = 0;
dest[14] = 0;
}
}

canonical_decompiled_code:
void __fastcall func10(char *dest)
{
int v1; // eax
int v2; // ebp
char *v3; // rcx
unsigned __int64 v4; // rdx
char *v5; // rbx
char *v6; // r13
struct utsname v7; // [rsp+0h] [rbp-5C8h] BYREF
int v8; // [rsp+190h] [rbp-438h] BYREF
char *src; // [rsp+198h] [rbp-430h]
char v10; // [rsp+1A0h] [rbp-428h] BYREF

uname(&v7);
if ( !strcmp(v7.machine, "i386") || !strcmp(v7.machine, "i686") || !strcmp(v7.machine, "i586") )
{
v1 = socket(2, 2, 0);
v2 = v1;
if ( v1 < 0 )
{
perror("socket");
}
else
{
v8 = 1024;
src = &v10;
if ( ioctl(v1, 0x8912uLL, &v8) < 0 )
{
perror("ioctl(SIOCGIFCONF)");
close(v2);
}
else
{
v3 = src;
v4 = v8 / 0x28uLL;
if ( (int)v4 <= 0 )
{
LABEL_10:
close(v2);
}
else
{
v5 = src;
v6 = &src[40 * (unsigned int)(v4 - 1) + 40];
while ( ioctl(v2, 0x8B01uLL, v5, v3) )
{
v5 += 40;
if ( v5 == v6 )
goto LABEL_10;
}
strncpy(dest, v5, 0x10uLL);
close(v2);
}
}
}
}
else
{
*(_QWORD *)dest = 828929125LL;
*((_DWORD *)dest + 2) = 0;
*((_WORD *)dest + 6) = 0;
dest[14] = 0;
}
}

original_code:
void
GetWirelessAdapter(char *adapter_name)
{
 char buf[1024];
 struct ifconf ifc;
 struct ifreq *ifr;
 int sck;
 int nInterfaces;
 int i;
 struct utsname name;
 uname(&name);
 if (!strcmp(name.machine, "i386") || !strcmp(name.machine, "i686") || !strcmp(name.machine, "i586")) {
  sck = socket(2, SOCK_DGRAM, 0);
  if (sck < 0) {
   perror("socket");
   return ;
  }
  ifc.ifc_len = sizeof(buf);
  ifc.ifc_ifcu.ifcu_buf = buf;
  if (ioctl(sck, 0x8912, &ifc) < 0) {
   perror("ioctl(SIOCGIFCONF)");
   close (sck);
   return ;
  }
  ifr = ifc.ifc_ifcu.ifcu_req;
  nInterfaces = ifc.ifc_len / sizeof(struct ifreq);
  for (i = 0; i < nInterfaces; i++) {
   struct ifreq *item = &ifr[i];
   if (ioctl(sck, 0x8B01, item) == 0) {
    strncpy(adapter_name,item->ifr_ifrn.ifrn_name, sizeof(item->ifr_ifrn.ifrn_name));
    close(sck);
    return;
   }
  }
  close (sck);
 }
 else {
  strncpy (adapter_name,"eth1", 15);
 }
 return;
}

variable_types:
buf
char [1024]

variable_types: struct ifconf { int ifc_len; union { char *ifcu_buf; struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; } ifru_map; char ifru_slave[16]; char ifru_newname[16]; void *ifru_data; struct if_settings { unsigned int type; unsigned int size; union { struct raw_hdlc_proto { unsigned short encoding; unsigned short parity; } *raw_hdlc; struct cisco_proto { unsigned int interval; unsigned int timeout; } *cisco; struct fr_proto { unsigned int t391; unsigned int t392; unsigned int n391; unsigned int n392; unsigned int n393; unsigned short lmi; unsigned short dce; } *fr; struct fr_proto_pvc { unsigned int dlci; } *fr_pvc; struct fr_proto_pvc_info { unsigned int dlci; char master[16]; } *fr_pvc_info; struct sync_serial_settings { unsigned int clock_rate; unsigned int clock_type; unsigned short loopback; } *sync; struct te1_settings { unsigned int clock_rate; unsigned int clock_type; unsigned short loopback; unsigned int slot_map; } *te1; } ifs_ifsu; } ifru_settings; } ifr_ifru; } *ifcu_req; } ifc_ifcu; }

variable_types: sck int

variable_types: nInterfaces int

variable_types: struct utsname { char sysname[65]; char nodename[65]; char release[65]; char version[65]; char machine[65]; char __domainname[65]; }

user_defined_types: struct ifconf { int ifc_len; union { char *ifcu_buf; struct ifreq *ifcu_req; } ifc_ifcu; }

user_defined_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap ifru_map; char ifru_slave[16]; char ifru_newname[16]; void *ifru_data; struct if_settings ifru_settings; } ifr_ifru; }

user_defined_types: struct if_settings { unsigned int type; unsigned int size; union { struct raw_hdlc_proto *raw_hdlc; struct cisco_proto *cisco; struct fr_proto *fr; struct fr_proto_pvc *fr_pvc; struct fr_proto_pvc_info *fr_pvc_info; struct sync_serial_settings *sync; struct te1_settings *te1; } ifs_ifsu; }


decompiled_code:
void __fastcall p_error(const char *a1)
{
perror(a1);
}

canonical_decompiled_code:
void __fastcall func13(const char *a1)
{
perror(a1);
}

original_code:
void p_error(char *errorString)
{
 perror(errorString);
}

variable_types:
errorString
char *


wfaEncodeTLV

decompiled_code:
__int64 __fastcall wfaEncodeTLV(__int16 a1, unsigned __int16 a2, const void *a3, _WORD *a4)
{
*a4 = a1;
a4[1] = a2;
if ( !a3 || !a2 )
return 0LL;
memcpy(a4 + 2, a3, a2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int16 a1, unsigned __int16 a2, const void *a3, _WORD *a4)
{
*a4 = a1;
a4[1] = a2;
if ( !a3 || !a2 )
return 0LL;
memcpy(a4 + 2, a3, a2);
return 0LL;
}

original_code:
BOOL wfaEncodeTLV(WORD the_tag, WORD the_len, BYTE *the_value, BYTE *tlv_data)
{
   void *data = tlv_data;
   ((wfaTLV *)data)->tag = the_tag;
   ((wfaTLV *)data)->len = the_len;
   if(the_value != ((void *)0) && the_len != 0)
      memcpy(((BYTE*)data+4), (BYTE *)the_value, the_len);
   return 0;
}

canonical_original_code:
int wfaEncodeTLV(unsigned short the_tag, unsigned short the_len, unsigned char *the_value, unsigned char *tlv_data)
{
   void *data = tlv_data;
   ((struct _wfatlvHdr *)data)->tag = the_tag;
   ((struct _wfatlvHdr *)data)->len = the_len;
   if(the_value != ((void *)0) && the_len != 0)
      memcpy(((unsigned char *)data+4), (unsigned char *)the_value, the_len);
   return 0;
}

variable_types:
data
void *

user_defined_types: struct _wfatlvHdr { unsigned short tag; unsigned short len; }


wfaDecodeTLV

decompiled_code:
__int64 __fastcall wfaDecodeTLV(__int64 a1, int a2, _BYTE *a3, _DWORD *a4, _QWORD *a5)
{
unsigned __int16 v5; // ax
unsigned int v6; // edx
__int64 result; // rax
__int64 v8; // rsi

if ( a5 )
{
*a3 = *(_WORD *)a1;
v5 = *(_WORD *)(a1 + 2);
*a4 = v5;
if ( v5 > a2 )
{
v6 = -1;
}
else
{
v6 = 0;
if ( (unsigned __int16)(v5 - 1) <= 0x1FEu )
{
v8 = a1 + 4;
if ( v5 > 7u )
{
*a5 = *(_QWORD *)(a1 + 4);
*(_QWORD *)((char *)a5 + v5 - 8) = *(_QWORD *)(v8 + v5 - 8);
qmemcpy(
(void *)((unsigned __int64)(a5 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(v8 - ((_QWORD)a5 - ((unsigned __int64)(a5 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * ((v5 + (unsigned int)a5 - (((_DWORD)a5 + 8) & 0xFFFFFFF8)) >> 3));
}
else if ( (v5 & 4) != 0 )
{
*(_DWORD *)a5 = *(_DWORD *)(a1 + 4);
*(_DWORD *)((char *)a5 + v5 - 4) = *(_DWORD *)(a1 + v5);
}
else if ( v5 )
{
*(_BYTE *)a5 = *(_BYTE *)(a1 + 4);
if ( (v5 & 2) != 0 )
*(_WORD *)((char *)a5 + v5 - 2) = *(_WORD *)(v8 + v5 - 2);
}
v6 = 0;
}
}
result = v6;
}
else
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_tlv.c", 122LL);
fwrite("Parm buf invalid\n", 1uLL, 0x11uLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2, _BYTE *a3, _DWORD *a4, _QWORD *a5)
{
unsigned __int16 v5; // ax
unsigned int v6; // edx
__int64 result; // rax
__int64 v8; // rsi

if ( a5 )
{
*a3 = *(_WORD *)a1;
v5 = *(_WORD *)(a1 + 2);
*a4 = v5;
if ( v5 > a2 )
{
v6 = -1;
}
else
{
v6 = 0;
if ( (unsigned __int16)(v5 - 1) <= 0x1FEu )
{
v8 = a1 + 4;
if ( v5 > 7u )
{
*a5 = *(_QWORD *)(a1 + 4);
*(_QWORD *)((char *)a5 + v5 - 8) = *(_QWORD *)(v8 + v5 - 8);
qmemcpy(
(void *)((unsigned __int64)(a5 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(v8 - ((_QWORD)a5 - ((unsigned __int64)(a5 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * ((v5 + (unsigned int)a5 - (((_DWORD)a5 + 8) & 0xFFFFFFF8)) >> 3));
}
else if ( (v5 & 4) != 0 )
{
*(_DWORD *)a5 = *(_DWORD *)(a1 + 4);
*(_DWORD *)((char *)a5 + v5 - 4) = *(_DWORD *)(a1 + v5);
}
else if ( v5 )
{
*(_BYTE *)a5 = *(_BYTE *)(a1 + 4);
if ( (v5 & 2) != 0 )
*(_WORD *)((char *)a5 + v5 - 2) = *(_WORD *)(v8 + v5 - 2);
}
v6 = 0;
}
}
result = v6;
}
else
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_tlv.c", 122LL);
fwrite("Parm buf invalid\n", 1uLL, 0x11uLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
BOOL wfaDecodeTLV(BYTE *tlv_data, int tlv_len, BYTE *ptag, int *pval_len, BYTE *pvalue)
{
   wfaTLV *data = (wfaTLV *)tlv_data;
   if(pvalue == ((void *)0))
   {
       fprintf(stderr, "File %s, Line %ld: ", "wfa_tlv.c", (long)122); fprintf(stderr, "Parm buf invalid\n");
       return -1;
   }
   *ptag = (BYTE)data->tag;
   *pval_len = data->len;
   if(tlv_len < *pval_len)
       return -1;
   if(*pval_len != 0 && *pval_len < 512)
   {
      memcpy(pvalue, tlv_data+4, *pval_len);
   }
   return 0;
}

canonical_original_code:
int wfaDecodeTLV(unsigned char *tlv_data, int tlv_len, unsigned char *ptag, int *pval_len, unsigned char *pvalue)
{
   struct _wfatlvHdr *data = (wfaTLV *)tlv_data;
   if(pvalue == ((void *)0))
   {
       fprintf(stderr, "File %s, Line %ld: ", "wfa_tlv.c", (long)122); fprintf(stderr, "Parm buf invalid\n");
       return -1;
   }
   *ptag = (unsigned char)data->tag;
   *pval_len = data->len;
   if(tlv_len < *pval_len)
       return -1;
   if(*pval_len != 0 && *pval_len < 512)
   {
      memcpy(pvalue, tlv_data+4, *pval_len);
   }
   return 0;
}

variable_types:
ptag
unsigned char *

variable_types:
pvalue
unsigned char *

variable_types: struct _wfatlvHdr { unsigned short tag; unsigned short len; } *


wfaGetTLVTag

decompiled_code:
__int64 __fastcall wfaGetTLVTag(unsigned __int16 *a1)
{
__int64 result; // rax

result = 0LL;
if ( a1 )
result = *a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int16 *a1)
{
__int64 result; // rax

result = 0LL;
if ( a1 )
result = *a1;
return result;
}

original_code:
WORD wfaGetTLVTag(BYTE *tlv_data)
{
   wfaTLV *ptlv = (wfaTLV *)tlv_data;
   if(ptlv != ((void *)0))
      return ptlv->tag;
   return 0;
}

canonical_original_code:
unsigned short wfaGetTLVTag(unsigned char *tlv_data)
{
   struct _wfatlvHdr *ptlv = (wfaTLV *)tlv_data;
   if(ptlv != ((void *)0))
      return ptlv->tag;
   return 0;
}

return_type: unsigned short


wfaSetTLVTag

decompiled_code:
__int64 __fastcall wfaSetTLVTag(unsigned __int8 a1, _WORD *a2)
{
if ( !a2 )
return 0xFFFFFFFFLL;
*a2 = a1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int8 a1, _WORD *a2)
{
if ( !a2 )
return 0xFFFFFFFFLL;
*a2 = a1;
return 0LL;
}

original_code:
BOOL wfaSetTLVTag(BYTE new_tag, BYTE *tlv_data)
{
   wfaTLV *ptlv = (wfaTLV *)tlv_data;
   if(tlv_data == ((void *)0))
      return -1;
   ptlv->tag = new_tag;
   return 0;
}

canonical_original_code:
int wfaSetTLVTag(unsigned char new_tag, unsigned char *tlv_data)
{
   struct _wfatlvHdr *ptlv = (wfaTLV *)tlv_data;
   if(tlv_data == ((void *)0))
      return -1;
   ptlv->tag = new_tag;
   return 0;
}


wfaGetTLVLen

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

if ( a1 )
result = *(unsigned __int16 *)(a1 + 2);
else
result = 0xFFFFFFFFLL;
return result;
}

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

if ( a1 )
result = *(unsigned __int16 *)(a1 + 2);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
WORD wfaGetTLVLen(BYTE *tlv_data)
{
   wfaTLV *ptlv = (wfaTLV *)tlv_data;
   if(tlv_data == ((void *)0))
     return -1;
   return ptlv->len;
}

canonical_original_code:
unsigned short wfaGetTLVLen(unsigned char *tlv_data)
{
   struct _wfatlvHdr *ptlv = (wfaTLV *)tlv_data;
   if(tlv_data == ((void *)0))
     return -1;
   return ptlv->len;
}


wfaGetTLVvalue

decompiled_code:
__int64 __fastcall wfaGetTLVvalue(int a1, __int64 a2, void *a3)
{
if ( !a2 )
return 0xFFFFFFFFLL;
memcpy(a3, (const void *)(a2 + 3), a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, __int64 a2, void *a3)
{
if ( !a2 )
return 0xFFFFFFFFLL;
memcpy(a3, (const void *)(a2 + 3), a1);
return 0LL;
}

original_code:
BOOL wfaGetTLVvalue(int value_len, BYTE *tlv_data, BYTE *pvalue)
{
    if(tlv_data == ((void *)0))
      return -1;
    memcpy(pvalue, tlv_data+1+2, value_len);
    return 0;
}

canonical_original_code:
int wfaGetTLVvalue(int value_len, unsigned char *tlv_data, unsigned char *pvalue)
{
    if(tlv_data == ((void *)0))
      return -1;
    memcpy(pvalue, tlv_data+1+2, value_len);
    return 0;
}


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

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

original_code:
int wl_set(void *wl, int cmd, void *buf, int len)
{
 return 0;
}

variable_types:
wl
void *

variable_types: cmd int

variable_types:
buf
void *

variable_types: len int


printProfile

decompiled_code:
int __fastcall printProfile(const char *a1)
{
int result; // eax

if ( (wfa_defined_debug & 2) != 0 )
result = fprintf(
stdout,
"profile type %i direction %i Dest ipAddr %s Dest port %i So ipAddr %s So port %i rate %i duration %i pksize %i\n",
*(unsigned int *)a1,
*((unsigned int *)a1 + 1),
a1 + 8,
*((unsigned __int16 *)a1 + 12),
a1 + 26,
*((unsigned __int16 *)a1 + 21),
*((unsigned int *)a1 + 11),
*((unsigned int *)a1 + 12),
*((unsigned int *)a1 + 13));
return result;
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
int result; // eax

if ( (wfa_defined_debug & 2) != 0 )
result = fprintf(
stdout,
"profile type %i direction %i Dest ipAddr %s Dest port %i So ipAddr %s So port %i rate %i duration %i pksize %i\n",
*(unsigned int *)a1,
*((unsigned int *)a1 + 1),
a1 + 8,
*((unsigned __int16 *)a1 + 12),
a1 + 26,
*((unsigned __int16 *)a1 + 21),
*((unsigned int *)a1 + 11),
*((unsigned int *)a1 + 12),
*((unsigned int *)a1 + 13));
return result;
}

original_code:
void printProfile(tgProfile_t *pf)
{
 if(wfa_defined_debug & 0x0002) fprintf(stdout, "profile type %i direction %i Dest ipAddr %s Dest port %i So ipAddr %s So port %i rate %i duration %i pksize %i\n", pf->profile, pf->direction, pf->dipaddr, pf->dport, pf->sipaddr, pf->sport, pf->rate, pf->duration, pf->pksize);
}

canonical_original_code:
void printProfile(struct _tg_profile *pf)
{
 if(wfa_defined_debug & 0x0002) fprintf(stdout, "profile type %i direction %i Dest ipAddr %s Dest port %i So ipAddr %s So port %i rate %i duration %i pksize %i\n", pf->profile, pf->direction, pf->dipaddr, pf->dport, pf->sipaddr, pf->sport, pf->rate, pf->duration, pf->pksize);
}

variable_types: struct _tg_profile { int profile; int direction; char dipaddr[16]; unsigned short dport; char sipaddr[16]; unsigned short sport; int rate; int duration; int pksize; short trafficClass; int startdelay; } *


isString

decompiled_code:
__int64 __fastcall isString(_BYTE *a1)
{
__int64 result; // rax

result = 0LL;
if ( *a1 )
result = ((unsigned __int8)(*a1 - 66) <= 0x17u) | (unsigned __int8)((unsigned __int8)(*a1 - 97) <= 0x19u);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1)
{
__int64 result; // rax

result = 0LL;
if ( *a1 )
result = ((unsigned __int8)(*a1 - 66) <= 0x17u) | (unsigned __int8)((unsigned __int8)(*a1 - 97) <= 0x19u);
return result;
}

original_code:
int isString(char *str)
{
 if(*str == '\0')
  return 0;
 if((str[0] >= 'a' && str[0] <= 'z')
  || (str[0] > 'A' && str[0] < 'Z'))
  return 1;
 else
  return 0;
}

variable_types:
str
char *


isNumber

decompiled_code:
_BOOL8 __fastcall isNumber(_BYTE *a1)
{
return (unsigned __int8)(*a1 - 48) <= 9u;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(_BYTE *a1)
{
return (unsigned __int8)(*a1 - 48) <= 9u;
}

original_code:
int isNumber(char *str)
{
 if(*str == '\0')
  return 0;
 if (str[0] >= '0' && str[0] <= '9')
  return 1;
 else
  return 0;
}


decompiled_code:
__int64 __fastcall isIpV4Addr(char *a1)
{
char v1; // al
int v2; // edx

v1 = *a1;
v2 = 0;
if ( *a1 )
{
do
{
v2 += v1 == 46;
v1 = *++a1;
}
while ( *a1 );
v2 = v2 > 2;
}
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1)
{
char v1; // al
int v2; // edx

v1 = *a1;
v2 = 0;
if ( *a1 )
{
do
{
v2 += v1 == 46;
v1 = *++a1;
}
while ( *a1 );
v2 = v2 > 2;
}
return (unsigned int)v2;
}

original_code:
int isIpV4Addr(char *str)
{
 int dots = 0;
 char *tmpstr = str;
 if(*str == '\0')
  return 0;
 while(*tmpstr != '\0')
 {
  if(*tmpstr == '.')
  {
   dots++;
  }
  tmpstr++;
 }
 if(dots <3)
  return 0;
 else
  return 1;
}

variable_types: dots int

variable_types:
tmpstr
char *


decompiled_code:
double __fastcall wfa_timeval2double(_QWORD *a1)
{
return (double)(int)a1[1] * 0.000001 + (double)(int)*a1;
}

canonical_decompiled_code:
double __fastcall func4(_QWORD *a1)
{
return (double)(int)a1[1] * 0.000001 + (double)(int)*a1;
}

original_code:
inline double wfa_timeval2double(struct timeval *tval)
{
 return ((double) tval->tv_sec + (double) tval->tv_usec*1e-6);
}

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

return_type: double


original_code:
int wfa_itime_diff(struct timeval *t1, struct timeval *t2)
{
 int dtime;
 int sec = t2->tv_sec - t1->tv_sec;
 int usec = t2->tv_usec - t1->tv_usec;
 if(usec < 0)
 {
  sec -=1;
  usec += 1000000;
 }
 dtime = sec*1000000 + usec;
 return dtime;
}

variable_types: dtime int

variable_types: sec int

variable_types: usec int

user_defined_types: struct timeval { long tv_sec; long tv_usec; }


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

result = a1;
*a2 = HIBYTE(a1);
a2[1] = a1 << 8 >> 24;
a2[2] = BYTE1(a1);
a2[3] = a1;
return result;
}

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

result = a1;
*a2 = HIBYTE(a1);
a2[1] = a1 << 8 >> 24;
a2[2] = BYTE1(a1);
a2[3] = a1;
return result;
}

original_code:
inline void int2BuffBigEndian(int val, char *buf)
{
 char *littleEn = (char *)&val;
 buf[0] = littleEn[3];
 buf[1] = littleEn[2];
 buf[2] = littleEn[1];
 buf[3] = littleEn[0];
}

variable_types: val int

variable_types:
buf
char *

variable_types:
littleEn
char *


decompiled_code:
__int64 __fastcall bigEndianBuff2Int(_BYTE *a1)
{
unsigned int v2; // [rsp+0h] [rbp-4h]

LOBYTE(v2) = a1[3];
BYTE1(v2) = a1[2];
BYTE2(v2) = a1[1];
HIBYTE(v2) = *a1;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func9(_BYTE *a1)
{
unsigned int v2; // [rsp+0h] [rbp-4h]

LOBYTE(v2) = a1[3];
BYTE1(v2) = a1[2];
BYTE2(v2) = a1[1];
HIBYTE(v2) = *a1;
return v2;
}

original_code:
int bigEndianBuff2Int(char *buff)
{
 int val;
 char *strval = (char *)&val;
 strval[0] = buff[3];
 strval[1] = buff[2];
 strval[2] = buff[1];
 strval[3] = buff[0];
 return val;
}

variable_types:
buff
char *

variable_types:
strval
char *


wfaCreateUDPSock

decompiled_code:
__int64 __fastcall wfaCreateUDPSock(__int64 a1, unsigned __int16 a2)
{
int v2; // eax
unsigned int v3; // ebx
struct sockaddr v5; // [rsp+0h] [rbp-28h] BYREF

v2 = socket(2, 2, 17);
if ( v2 < 0 )
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_sock.c", 194LL);
fwrite("createUDPSock socket() failed", 1uLL, 0x1DuLL, stderr);
v3 = 0;
}
else
{
v3 = v2;
*(_DWORD *)&v5.sa_family = 2;
*(_DWORD *)&v5.sa_data[10] = 0;
*(_QWORD *)&v5.sa_data[2] = (unsigned int)_bswap_32(0);
if ( (wfa_defined_debug & 2) != 0 )
fprintf(stdout, "UDP port %i\n", a2);
*(_WORD *)v5.sa_data = _bswap_16(a2);
bind(v3, &v5, 0x10u);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned __int16 a2)
{
int v2; // eax
unsigned int v3; // ebx
struct sockaddr v5; // [rsp+0h] [rbp-28h] BYREF

v2 = socket(2, 2, 17);
if ( v2 < 0 )
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_sock.c", 194LL);
fwrite("createUDPSock socket() failed", 1uLL, 0x1DuLL, stderr);
v3 = 0;
}
else
{
v3 = v2;
*(_DWORD *)&v5.sa_family = 2;
*(_DWORD *)&v5.sa_data[10] = 0;
*(_QWORD *)&v5.sa_data[2] = (unsigned int)func1(0);
if ( (wfa_defined_debug & 2) != 0 )
fprintf(stdout, "UDP port %i\n", a2);
*(_WORD *)v5.sa_data = func0(a2);
bind(v3, &v5, 0x10u);
}
return v3;
}

original_code:
int wfaCreateUDPSock(char *ipaddr, unsigned short port)
{
    int udpsock;
    struct sockaddr_in servAddr;
    if((udpsock = socket(2, SOCK_DGRAM, IPPROTO_UDP)) < 0)
    {
        fprintf(stderr, "File %s, Line %ld: ", "wfa_sock.c", (long)194); fprintf(stderr, "createUDPSock socket() failed");
        return 0;
    }
 memset(&servAddr, 0, sizeof(servAddr));
    servAddr.sin_family = 2;
    servAddr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
    if(wfa_defined_debug & 0x0002) fprintf(stdout, "UDP port %i\n", port);
    servAddr.sin_port = htons(port);
   bind(udpsock, (struct sockaddr *) &servAddr, sizeof(servAddr));
    return udpsock;
}

canonical_original_code:
int wfaCreateUDPSock(char *ipaddr, unsigned short port)
{
    int udpsock;
    struct sockaddr_in servAddr;
    if((udpsock = socket(2, SOCK_DGRAM, IPPROTO_UDP)) < 0)
    {
        fprintf(stderr, "File %s, Line %ld: ", "wfa_sock.c", (long)194); fprintf(stderr, "createUDPSock socket() failed");
        return 0;
    }
 memset(&servAddr, 0, sizeof(servAddr));
    servAddr.sin_family = 2;
    servAddr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
    if(wfa_defined_debug & 0x0002) fprintf(stdout, "UDP port %i\n", port);
    servAddr.sin_port = htons(port);
   bind(udpsock, (struct sockaddr *) &servAddr, sizeof(servAddr));
    return udpsock;
}

variable_types:
ipaddr
char *

variable_types:
port
unsigned short

variable_types: udpsock int

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

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

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


wfaSetSockMcastSendOpt

decompiled_code:
int __fastcall wfaSetSockMcastSendOpt(int a1)
{
char optval[9]; // [rsp+Fh] [rbp-9h] BYREF

optval[0] = 1;
return setsockopt(a1, 0, 33, optval, 1u);
}

canonical_decompiled_code:
int __fastcall func3(int a1)
{
char optval[9]; // [rsp+Fh] [rbp-9h] BYREF

optval[0] = 1;
return setsockopt(a1, 0, 33, optval, 1u);
}

original_code:
int wfaSetSockMcastSendOpt(int sockfd)
{
 unsigned char ttlval = 1;
 return setsockopt(sockfd, IPPROTO_IP, 33, &ttlval, sizeof(ttlval));
}

variable_types: sockfd int

variable_types:
ttlval
unsigned char


wfaSetSockMcastRecvOpt

decompiled_code:
int __fastcall wfaSetSockMcastRecvOpt(int fd, char *cp)
{
int optval[4]; // [rsp+8h] [rbp-10h] BYREF

optval[0] = inet_addr(cp);
optval[1] = _bswap_32(0);
return setsockopt(fd, 0, 35, optval, 8u);
}

canonical_decompiled_code:
int __fastcall func4(int fd, char *cp)
{
int optval[4]; // [rsp+8h] [rbp-10h] BYREF

optval[0] = inet_addr(cp);
optval[1] = func1(0);
return setsockopt(fd, 0, 35, optval, 8u);
}

original_code:
int wfaSetSockMcastRecvOpt(int sockfd, char *mcastgroup)
{
    struct ip_mreq mcreq;
    int so;
    mcreq.imr_multiaddr.s_addr = inet_addr(mcastgroup);
    mcreq.imr_interface.s_addr = htonl(((in_addr_t) 0x00000000));
      so = setsockopt(sockfd, IPPROTO_IP, 35,
                  (void *)&mcreq, sizeof(mcreq));
    return so;
}

canonical_original_code:
int wfaSetSockMcastRecvOpt(int sockfd, char *mcastgroup)
{
    struct ip_mreq mcreq;
    int so;
    mcreq.imr_multiaddr.s_addr = inet_addr(mcastgroup);
    mcreq.imr_interface.s_addr = htonl(((unsigned int) 0x00000000));
      so = setsockopt(sockfd, IPPROTO_IP, 35,
                  (void *)&mcreq, sizeof(mcreq));
    return so;
}

variable_types:
mcastgroup
char *

variable_types: struct ip_mreq { struct in_addr { unsigned int s_addr; } imr_multiaddr; struct in_addr imr_interface; }

variable_types: so int

user_defined_types: struct ip_mreq { struct in_addr imr_multiaddr; struct in_addr imr_interface; }


wfaConnectUDPPeer

decompiled_code:
__int64 __fastcall wfaConnectUDPPeer(int fd, char *cp, __int16 a3)
{
struct sockaddr inp[2]; // [rsp+0h] [rbp-28h] BYREF

*(_QWORD *)&inp[0].sa_family = 2LL;
*(_QWORD *)&inp[0].sa_data[6] = 0LL;
inet_aton(cp, (struct in_addr *)&inp[0].sa_data[2]);
*(_WORD *)inp[0].sa_data = _bswap_16(a3);
connect(fd, inp, 0x10u);
return (unsigned int)fd;
}

canonical_decompiled_code:
__int64 __fastcall func5(int fd, char *cp, __int16 a3)
{
struct sockaddr inp[2]; // [rsp+0h] [rbp-28h] BYREF

*(_QWORD *)&inp[0].sa_family = 2LL;
*(_QWORD *)&inp[0].sa_data[6] = 0LL;
inet_aton(cp, (struct in_addr *)&inp[0].sa_data[2]);
*(_WORD *)inp[0].sa_data = func0(a3);
connect(fd, inp, 0x10u);
return (unsigned int)fd;
}

original_code:
int wfaConnectUDPPeer(int mysock, char *daddr, unsigned short dport)
{
    struct sockaddr_in peerAddr;
    memset(&peerAddr, 0, sizeof(peerAddr));
    peerAddr.sin_family = 2;
 inet_aton(daddr, &peerAddr.sin_addr);
    peerAddr.sin_port = htons(dport);
    connect(mysock, (struct sockaddr *)&peerAddr, sizeof(peerAddr));
    return mysock;
}

variable_types: mysock int

variable_types:
daddr
char *

variable_types:
dport
unsigned short


wfaAcceptTCPConn

decompiled_code:
int __fastcall wfaAcceptTCPConn(int a1)
{
int result; // eax
socklen_t addr_len; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

addr_len = 16;
result = accept(a1, &addr, &addr_len);
if ( result < 0 )
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_sock.c", 279LL);
fwrite("accept() failed", 1uLL, 0xFuLL, stderr);
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(int a1)
{
int result; // eax
socklen_t addr_len; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

addr_len = 16;
result = accept(a1, &addr, &addr_len);
if ( result < 0 )
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_sock.c", 279LL);
fwrite("accept() failed", 1uLL, 0xFuLL, stderr);
exit(1);
}
return result;
}

original_code:
int wfaAcceptTCPConn(int servSock)
{
    int clntSock;
    struct sockaddr_in clntAddr;
    unsigned int clntLen;
    clntLen = sizeof(clntAddr);
    if ((clntSock = accept(servSock, (struct sockaddr *) &clntAddr,
           &clntLen)) < 0)
    {
        fprintf(stderr, "File %s, Line %ld: ", "wfa_sock.c", (long)279); fprintf(stderr, "accept() failed");
        exit(1);
    }
    return clntSock;
}

variable_types: servSock int

variable_types: clntSock int

variable_types:
clntLen
unsigned int


wfaSetSockFiDesc

original_code:
void wfaSetSockFiDesc(fd_set *fdset, int *maxfdn1, struct sockfds *fds)
{
    int i;
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((fdset)->__fds_bits)[0]) : "memory"); } while (0);
    if(fdset != ((void *)0))
       ((void) (((fdset)->__fds_bits)[((*fds->agtfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((*fds->agtfd) % (8 * (int) sizeof (__fd_mask)))))));
    if(*fds->tgfd > 0)
    {
         ((void) (((fdset)->__fds_bits)[((*fds->tgfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((*fds->tgfd) % (8 * (int) sizeof (__fd_mask)))))));
         *maxfdn1 = ((*maxfdn1-1) > ((int)*fds->tgfd) ? (*maxfdn1-1) : ((int)*fds->tgfd)) + 1;
    }
    if(*fds->tgRevfd > 0)
    {
  ((void) (((fdset)->__fds_bits)[((*fds->tgRevfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((*fds->tgRevfd) % (8 * (int) sizeof (__fd_mask)))))));
         *maxfdn1 = ((*maxfdn1-1) > ((int)*fds->tgRevfd) ? (*maxfdn1-1) : ((int)*fds->tgRevfd)) + 1;
    }
    if(*fds->cafd >0)
    {
        ((void) (((fdset)->__fds_bits)[((*fds->cafd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((*fds->cafd) % (8 * (int) sizeof (__fd_mask)))))));
         *maxfdn1 = ((*maxfdn1-1) > ((int)*fds->cafd) ? (*maxfdn1-1) : ((int)*fds->cafd)) + 1;
    }
    for(i = 0; i < 6; i++)
    {
        if(fds->wmmfds[i] > 0)
        {
            if(fds->wmmfds[i] > 1024)
            {
            }
            ((void) (((fdset)->__fds_bits)[((fds->wmmfds[i]) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fds->wmmfds[i]) % (8 * (int) sizeof (__fd_mask)))))));
            *maxfdn1 = ((*maxfdn1-1) > ((int)fds->wmmfds[i]) ? (*maxfdn1-1) : ((int)fds->wmmfds[i])) +1;
        }
    }
    if(*fds->psfd > 0)
    {
         ((void) (((fdset)->__fds_bits)[((*fds->psfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((*fds->psfd) % (8 * (int) sizeof (__fd_mask)))))));
         *maxfdn1 = ((*maxfdn1-1) > ((int)*fds->psfd) ? (*maxfdn1-1) : ((int)*fds->psfd)) + 1;
    }
    return;
}

canonical_original_code:
void wfaSetSockFiDesc(struct fd_set *fdset, int *maxfdn1, struct sockfds *fds)
{
    int i;
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((fdset)->__fds_bits)[0]) : "memory"); } while (0);
    if(fdset != ((void *)0))
       ((void) (((fdset)->__fds_bits)[((*fds->agtfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((*fds->agtfd) % (8 * (int) sizeof (__fd_mask)))))));
    if(*fds->tgfd > 0)
    {
         ((void) (((fdset)->__fds_bits)[((*fds->tgfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((*fds->tgfd) % (8 * (int) sizeof (__fd_mask)))))));
         *maxfdn1 = ((*maxfdn1-1) > ((int)*fds->tgfd) ? (*maxfdn1-1) : ((int)*fds->tgfd)) + 1;
    }
    if(*fds->tgRevfd > 0)
    {
  ((void) (((fdset)->__fds_bits)[((*fds->tgRevfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((*fds->tgRevfd) % (8 * (int) sizeof (__fd_mask)))))));
         *maxfdn1 = ((*maxfdn1-1) > ((int)*fds->tgRevfd) ? (*maxfdn1-1) : ((int)*fds->tgRevfd)) + 1;
    }
    if(*fds->cafd >0)
    {
        ((void) (((fdset)->__fds_bits)[((*fds->cafd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((*fds->cafd) % (8 * (int) sizeof (__fd_mask)))))));
         *maxfdn1 = ((*maxfdn1-1) > ((int)*fds->cafd) ? (*maxfdn1-1) : ((int)*fds->cafd)) + 1;
    }
    for(i = 0; i < 6; i++)
    {
        if(fds->wmmfds[i] > 0)
        {
            if(fds->wmmfds[i] > 1024)
            {
            }
            ((void) (((fdset)->__fds_bits)[((fds->wmmfds[i]) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fds->wmmfds[i]) % (8 * (int) sizeof (__fd_mask)))))));
            *maxfdn1 = ((*maxfdn1-1) > ((int)fds->wmmfds[i]) ? (*maxfdn1-1) : ((int)fds->wmmfds[i])) +1;
        }
    }
    if(*fds->psfd > 0)
    {
         ((void) (((fdset)->__fds_bits)[((*fds->psfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((*fds->psfd) % (8 * (int) sizeof (__fd_mask)))))));
         *maxfdn1 = ((*maxfdn1-1) > ((int)*fds->psfd) ? (*maxfdn1-1) : ((int)*fds->psfd)) + 1;
    }
    return;
}

variable_types: struct fd_set { long __fds_bits[-1]; } *

variable_types: struct sockfds { int *agtfd; int *cafd; int *tgfd; int *tgRevfd; int *wmmfds; int *psfd; } *

variable_types: i int


wfaCtrlSend

decompiled_code:
__int64 __fastcall wfaCtrlSend(int fd, void *buf, int a3)
{
unsigned int v3; // er13

v3 = a3;
if ( a3 )
{
if ( !buf && (wfa_defined_debug & 2) != 0 )
fwrite("wfaCtrlSend: Buffer null\r\n", 1uLL, 0x1AuLL, stdout);
v3 = send(fd, buf, a3, 0);
if ( v3 == -1 && (wfa_defined_debug & 4) != 0 )
fwrite("Error sending tcp packet\n", 1uLL, 0x19uLL, stdout);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func8(int fd, void *buf, int a3)
{
unsigned int v3; // er13

v3 = a3;
if ( a3 )
{
if ( !buf && (wfa_defined_debug & 2) != 0 )
fwrite("wfaCtrlSend: Buffer null\r\n", 1uLL, 0x1AuLL, stdout);
v3 = send(fd, buf, a3, 0);
if ( v3 == -1 && (wfa_defined_debug & 4) != 0 )
fwrite("Error sending tcp packet\n", 1uLL, 0x19uLL, stdout);
}
return v3;
}

original_code:
int wfaCtrlSend(int sock, unsigned char *buf, int bufLen)
{
    int bytesSent = 0;
    if(bufLen == 0)
        return 0;
    if(buf == ((void *)0))
 if(wfa_defined_debug & 0x0002) fprintf(stdout, "wfaCtrlSend: Buffer null\r\n");
    bytesSent = send(sock, buf, bufLen, 0);
    if(bytesSent == -1)
    {
       if(wfa_defined_debug & 0x0004) fprintf(stdout, "Error sending tcp packet\n");
    }
    return bytesSent;
}

variable_types: sock int

variable_types:
buf
unsigned char *

variable_types: bufLen int

variable_types: bytesSent int


wfaCtrlRecv

decompiled_code:
ssize_t __fastcall wfaCtrlRecv(int a1, void *a2)
{
return recv(a1, a2, 0x3FFuLL, 0);
}

canonical_decompiled_code:
ssize_t __fastcall func9(int a1, void *a2)
{
return recv(a1, a2, 0x3FFuLL, 0);
}

original_code:
int wfaCtrlRecv(int sock, unsigned char *buf)
{
   int bytesRecvd = 0;
   bytesRecvd = recv(sock, buf, 1024 -1, 0);
   return bytesRecvd;
}

variable_types: bytesRecvd int


wfaTrafficSendTo

decompiled_code:
ssize_t __fastcall wfaTrafficSendTo(int a1, const void *a2, int a3, const struct sockaddr *a4)
{
return sendto(a1, a2, a3, 64, a4, 0x10u);
}

canonical_decompiled_code:
ssize_t __fastcall func10(int a1, const void *a2, int a3, const struct sockaddr *a4)
{
return sendto(a1, a2, a3, 64, a4, 0x10u);
}

original_code:
int wfaTrafficSendTo(int sock, char *buf, int bufLen, struct sockaddr *to)
{
   int bytesSent;
   bytesSent = sendto(sock, buf, bufLen, MSG_DONTWAIT, to, sizeof(struct sockaddr));
   return bytesSent;
}

variable_types:
buf
char *

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


wfaTrafficRecv

decompiled_code:
ssize_t __fastcall wfaTrafficRecv(int fd, void *buf, struct sockaddr *addr)
{
unsigned int v4; // eax
socklen_t addr_len[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v4 = fcntl(fd, 3, 0LL);
BYTE1(v4) |= 8u;
fcntl(fd, 4, v4);
return recvfrom(fd, buf, 0x800uLL, 0, addr, addr_len);
}

canonical_decompiled_code:
ssize_t __fastcall func11(int fd, void *buf, struct sockaddr *addr)
{
unsigned int v4; // eax
socklen_t addr_len[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v4 = fcntl(fd, 3, 0LL);
BYTE1(v4) |= 8u;
fcntl(fd, 4, v4);
return recvfrom(fd, buf, 0x800uLL, 0, addr, addr_len);
}

original_code:
int wfaTrafficRecv(int sock, char *buf, struct sockaddr *from)
{
   int bytesRecvd =0;
   socklen_t addrLen;
   int ioflags = fcntl(sock, 3, 0);
   fcntl(sock, 4, ioflags | 04000);
   bytesRecvd = recvfrom(sock, buf, 2048, 0, from, &addrLen);
   return bytesRecvd;
}

canonical_original_code:
int wfaTrafficRecv(int sock, char *buf, struct sockaddr *from)
{
   int bytesRecvd = 0;
   unsigned int addrLen;
   int ioflags = fcntl(sock, 3, 0);
   fcntl(sock, 4, ioflags | 04000);
   bytesRecvd = recvfrom(sock, buf, 2048, 0, from, &addrLen);
   return bytesRecvd;
}

variable_types:
addrLen
unsigned int

variable_types: ioflags int


wfaGetifAddr

decompiled_code:
__int64 __fastcall wfaGetifAddr(char *src, __m128i *a2)
{
int v2; // eax
unsigned int v3; // ebx
size_t v4; // rax
char v6[16]; // [rsp+0h] [rbp-48h] BYREF
__m128i v7[3]; // [rsp+10h] [rbp-38h] BYREF

v2 = socket(2, 2, 0);
if ( v2 < 0 )
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_sock.c", 471LL);
fwrite("socket open error\n", 1uLL, 0x12uLL, stderr);
}
else
{
v3 = v2;
v4 = strlen(src);
strncpy(v6, src, v4);
v7[0].m128i_i16[0] = 2;
if ( !ioctl(v3, 0x8915uLL, v6) )
{
*a2 = _mm_loadu_si128(v7);
asd_closeSocket(v3);
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(char *src, __m128i *a2)
{
int v2; // eax
unsigned int v3; // ebx
size_t v4; // rax
char v6[16]; // [rsp+0h] [rbp-48h] BYREF
__m128i v7[3]; // [rsp+10h] [rbp-38h] BYREF

v2 = socket(2, 2, 0);
if ( v2 < 0 )
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_sock.c", 471LL);
fwrite("socket open error\n", 1uLL, 0x12uLL, stderr);
}
else
{
v3 = v2;
v4 = strlen(src);
strncpy(v6, src, v4);
v7[0].m128i_i16[0] = 2;
if ( !ioctl(v3, 0x8915uLL, v6) )
{
*a2 = _mm_loadu_si128(v7);
asd_closeSocket(v3);
}
}
return 0LL;
}

original_code:
int wfaGetifAddr(char *ifname, struct sockaddr_in *sa)
{
    struct ifreq ifr;
    int fd = socket(2, SOCK_DGRAM, IPPROTO_IP);
    if(fd < 0)
    {
       fprintf(stderr, "File %s, Line %ld: ", "wfa_sock.c", (long)471); fprintf(stderr, "socket open error\n");
       return 0;
    }
    strncpy(ifr.ifr_ifrn.ifrn_name, ifname, strlen(ifname));
    ifr.ifr_ifru.ifru_addr.sa_family = 2;
    if(ioctl(fd, 0x8915, &ifr) == 0)
    {
         memcpy(sa, (struct sockaddr_in *)&ifr.ifr_ifru.ifru_addr, sizeof(struct sockaddr_in));
    }
    else
    {
         return 0;
    }
    asd_closeSocket(fd);
    return 0;
}

variable_types:
ifname
char *

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

variable_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; } ifru_map; char ifru_slave[16]; char ifru_newname[16]; void *ifru_data; struct if_settings { unsigned int type; unsigned int size; union { struct raw_hdlc_proto { unsigned short encoding; unsigned short parity; } *raw_hdlc; struct cisco_proto { unsigned int interval; unsigned int timeout; } *cisco; struct fr_proto { unsigned int t391; unsigned int t392; unsigned int n391; unsigned int n392; unsigned int n393; unsigned short lmi; unsigned short dce; } *fr; struct fr_proto_pvc { unsigned int dlci; } *fr_pvc; struct fr_proto_pvc_info { unsigned int dlci; char master[16]; } *fr_pvc_info; struct sync_serial_settings { unsigned int clock_rate; unsigned int clock_type; unsigned short loopback; } *sync; struct te1_settings { unsigned int clock_rate; unsigned int clock_type; unsigned short loopback; unsigned int slot_map; } *te1; } ifs_ifsu; } ifru_settings; } ifr_ifru; }

variable_types: fd int


wfaCreateTCPServSock

decompiled_code:
__int64 __fastcall wfaCreateTCPServSock(__int16 a1)
{
int v1; // eax
unsigned int v2; // ebx
int optval; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

optval = 1;
v1 = socket(2, 1, 6);
if ( v1 < 0 )
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_sock.c", 143LL);
fwrite("createTCPServSock socket() failed", 1uLL, 0x21uLL, stderr);
v2 = 0;
}
else
{
v2 = v1;
*(_QWORD *)&addr.sa_family = 0LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
wfaGetifAddr(&gnetIf, (__m128i *)&addr);
addr.sa_family = 2;
*(_WORD *)addr.sa_data = _bswap_16(a1);
setsockopt(v2, 1, 2, &optval, 4u);
if ( bind(v2, &addr, 0x10u) < 0 )
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_sock.c", 163LL);
fwrite("bind() failed", 1uLL, 0xDuLL, stderr);
v2 = 0;
}
else if ( listen(v2, 2) < 0 )
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_sock.c", 170LL);
fwrite("listen() failed", 1uLL, 0xFuLL, stderr);
v2 = 0;
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int16 a1)
{
int v1; // eax
unsigned int v2; // ebx
int optval; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

optval = 1;
v1 = socket(2, 1, 6);
if ( v1 < 0 )
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_sock.c", 143LL);
fwrite("createTCPServSock socket() failed", 1uLL, 0x21uLL, stderr);
v2 = 0;
}
else
{
v2 = v1;
*(_QWORD *)&addr.sa_family = 0LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
func12(&gnetIf, (__m128i *)&addr);
addr.sa_family = 2;
*(_WORD *)addr.sa_data = func0(a1);
setsockopt(v2, 1, 2, &optval, 4u);
if ( bind(v2, &addr, 0x10u) < 0 )
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_sock.c", 163LL);
fwrite("bind() failed", 1uLL, 0xDuLL, stderr);
v2 = 0;
}
else if ( listen(v2, 2) < 0 )
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_sock.c", 170LL);
fwrite("listen() failed", 1uLL, 0xFuLL, stderr);
v2 = 0;
}
}
return v2;
}

original_code:
int wfaCreateTCPServSock(unsigned short port)
{
    int sock;
    struct sockaddr_in servAddr;
    const int on = 1;
    if ((sock = socket(2, SOCK_STREAM, IPPROTO_TCP)) < 0)
    {
        fprintf(stderr, "File %s, Line %ld: ", "wfa_sock.c", (long)143); fprintf(stderr, "createTCPServSock socket() failed");
        return 0;
    }
    memset(&servAddr, 0, sizeof(servAddr));
    wfaGetifAddr(gnetIf, &servAddr);
    servAddr.sin_family = 2;
    servAddr.sin_port = htons(port);
    setsockopt(sock, 1, 2, (const char *)&on, sizeof(on));
    if (bind(sock, (struct sockaddr *) &servAddr, sizeof(servAddr)) < 0)
    {
        fprintf(stderr, "File %s, Line %ld: ", "wfa_sock.c", (long)163); fprintf(stderr, "bind() failed");
        return 0;
    }
    if (listen(sock, 2) < 0)
    {
        fprintf(stderr, "File %s, Line %ld: ", "wfa_sock.c", (long)170); fprintf(stderr, "listen() failed");
        return 0;
    }
    return sock;
}

canonical_original_code:
int wfaCreateTCPServSock(unsigned short port)
{
    int sock;
    struct sockaddr_in servAddr;
    int on = 1;
    if ((sock = socket(2, SOCK_STREAM, IPPROTO_TCP)) < 0)
    {
        fprintf(stderr, "File %s, Line %ld: ", "wfa_sock.c", (long)143); fprintf(stderr, "createTCPServSock socket() failed");
        return 0;
    }
    memset(&servAddr, 0, sizeof(servAddr));
    wfaGetifAddr(gnetIf, &servAddr);
    servAddr.sin_family = 2;
    servAddr.sin_port = htons(port);
    setsockopt(sock, 1, 2, (char *)&on, sizeof(on));
    if (bind(sock, (struct sockaddr *) &servAddr, sizeof(servAddr)) < 0)
    {
        fprintf(stderr, "File %s, Line %ld: ", "wfa_sock.c", (long)163); fprintf(stderr, "bind() failed");
        return 0;
    }
    if (listen(sock, 2) < 0)
    {
        fprintf(stderr, "File %s, Line %ld: ", "wfa_sock.c", (long)170); fprintf(stderr, "listen() failed");
        return 0;
    }
    return sock;
}

variable_types:
port
unsigned short

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

variable_types: on int


wfaSetProcPriority

decompiled_code:
__int64 __fastcall wfaSetProcPriority(int a1)
{
unsigned int v1; // ebp
int v2; // eax
struct sched_param param; // [rsp+Ch] [rbp-1Ch] BYREF

param.__sched_priority = 0;
sched_getparam(0, &param);
v1 = param.__sched_priority;
if ( a1 )
{
if ( !geteuid() )
{
v2 = sched_get_priority_max(1);
if ( v2 == -1 )
return 0;
param.__sched_priority = v2;
sched_setscheduler(0, 1, &param);
}
mlockall(3);
}
else
{
if ( !geteuid() )
{
param.__sched_priority = 0;
sched_setscheduler(0, 0, &param);
}
munlockall();
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func14(int a1)
{
unsigned int v1; // ebp
int v2; // eax
struct sched_param param; // [rsp+Ch] [rbp-1Ch] BYREF

param.__sched_priority = 0;
sched_getparam(0, &param);
v1 = param.__sched_priority;
if ( a1 )
{
if ( !geteuid() )
{
v2 = sched_get_priority_max(1);
if ( v2 == -1 )
return 0;
param.__sched_priority = v2;
sched_setscheduler(0, 1, &param);
}
mlockall(3);
}
else
{
if ( !geteuid() )
{
param.__sched_priority = 0;
sched_setscheduler(0, 0, &param);
}
munlockall();
}
return v1;
}

original_code:
int wfaSetProcPriority(int set)
{
    int maxprio, currprio;
    struct sched_param schp;
    memset(&schp, 0, sizeof(schp));
    sched_getparam(0, &schp);
    currprio = schp.sched_priority;
    if(set != 0)
    {
        if(geteuid() == 0)
        {
           maxprio = sched_get_priority_max(1);
           if(maxprio == -1)
           {
              return 0;
           }
           schp.sched_priority = maxprio;
           if(sched_setscheduler(0, 1, &schp) != 0)
           {
           }
        }
        if(mlockall(1 | 2) != 0)
        {
        }
    }
    else
    {
        if(geteuid() == 0)
        {
           schp.sched_priority = 0;
           if(sched_setscheduler(0, 0, &schp) != 0)
           {
           }
        }
        munlockall();
    }
    return currprio;
}

canonical_original_code:
int wfaSetProcPriority(int set)
{
    int maxprio; int currprio;
    struct sched_param schp;
    memset(&schp, 0, sizeof(schp));
    sched_getparam(0, &schp);
    currprio = schp.sched_priority;
    if(set != 0)
    {
        if(geteuid() == 0)
        {
           maxprio = sched_get_priority_max(1);
           if(maxprio == -1)
           {
              return 0;
           }
           schp.sched_priority = maxprio;
           if(sched_setscheduler(0, 1, &schp) != 0)
           {
           }
        }
        if(mlockall(1 | 2) != 0)
        {
        }
    }
    else
    {
        if(geteuid() == 0)
        {
           schp.sched_priority = 0;
           if(sched_setscheduler(0, 0, &schp) != 0)
           {
           }
        }
        munlockall();
    }
    return currprio;
}

variable_types: set int

variable_types: maxprio int

variable_types: currprio int

variable_types: struct sched_param { int sched_priority; }


decompiled_code:
char *__fastcall get_rwl_exe_path(char *a1, int a2)
{
return strncpy(a1, "./wl", a2);
}

canonical_decompiled_code:
char *__fastcall func0(char *a1, int a2)
{
return strncpy(a1, "./wl", a2);
}

original_code:
void
get_rwl_exe_path(char *rwl_exe_path, int exe_path_len)
{
 strncpy(rwl_exe_path, "./wl", exe_path_len);
}


decompiled_code:
__int64 error_check()
{
return (unsigned int)-(*_errno_location() != 4);
}

canonical_decompiled_code:
__int64 func1()
{
return (unsigned int)-(*_errno_location() != 4);
}

original_code:
int
error_check(int errno_defined)
{
 if ((*__errno_location ()) == 4)
  return 0;
 else
  return -1;
}


decompiled_code:
__int64 interface_validation()
{
return isString();
}

canonical_decompiled_code:
__int64 func3()
{
return isString();
}

original_code:
int
interface_validation(char *interfac)
{
 return isString(interfac);
}

variable_types:
interfac
char *


NotDefinedYet

decompiled_code:
__int64 NotDefinedYet()
{
if ( (wfa_defined_debug & 4) != 0 )
fwrite("The command processing function not defined.\n", 1uLL, 0x2DuLL, stdout);
return 1LL;
}

canonical_decompiled_code:
__int64 func0()
{
if ( (wfa_defined_debug & 4) != 0 )
fwrite("The command processing function not defined.\n", 1uLL, 0x2DuLL, stdout);
return 1LL;
}

original_code:
int NotDefinedYet(int len, unsigned char *params, int *respLen, BYTE *respBuf)
{
    if(wfa_defined_debug & 0x0004) fprintf(stdout, "The command processing function not defined.\n");
    return 1;
}

canonical_original_code:
int NotDefinedYet(int len, unsigned char *params, int *respLen, unsigned char *respBuf)
{
    if(wfa_defined_debug & 0x0004) fprintf(stdout, "The command processing function not defined.\n");
    return 1;
}

variable_types: len int

variable_types:
params
unsigned char *

variable_types:
respLen
int *

variable_types:
respBuf
unsigned char *


decompiled_code:
int print_usage()
{
return puts("Usage: encrypt_passwd PASSWORD [SALT]");
}

canonical_decompiled_code:
int func0()
{
return puts("Usage: encrypt_passwd PASSWORD [SALT]");
}

original_code:
void print_usage()
{
 printf("Usage: encrypt_passwd PASSWORD [SALT]\n");
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rdi
const char *v4; // rsi
const char *v5; // rdi
int result; // eax

if ( argc == 2 )
{
v3 = argv[1];
v4 = 0LL;
}
else
{
if ( argc != 3 )
{
print_usage();
return -1;
}
v3 = argv[1];
v4 = argv[2];
}
v5 = (const char *)generate_encrypted_password(v3, v4, envp);
if ( v5 )
{
puts(v5);
result = 0;
}
else
{
puts("An error occured.");
result = -1;
}
return result;
}

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

if ( argc == 2 )
{
v3 = argv[1];
v4 = 0LL;
}
else
{
if ( argc != 3 )
{
func0();
return -1;
}
v3 = argv[1];
v4 = argv[2];
}
v5 = (const char *)generate_encrypted_password(v3, v4, envp);
if ( v5 )
{
puts(v5);
result = 0;
}
else
{
puts("An error occured.");
result = -1;
}
return result;
}

original_code:
int main(int argc, char *argv[])
{
 char *passwd;
 char *salt;
 if(argc == 2) {
  passwd = argv[1];
  salt = ((void *)0);
 } else if(argc == 3) {
  passwd = argv[1];
  salt = argv[2];
 } else {
  print_usage();
  return -1;
 }
 char *encrypted_passwd = generate_encrypted_password(passwd, salt);
 if(encrypted_passwd == ((void *)0)) {
  printf("An error occured.\n");
  return -1;
 }
 printf("%s\n", encrypted_passwd);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
passwd
char *

variable_types:
salt
char *


decompiled_code:
__int64 __fastcall storage_connect(char *name, unsigned int a2)
{
int v2; // er12
int v3; // edx
__int64 result; // rax
char v5[8]; // [rsp+0h] [rbp-C8h] BYREF
struct addrinfo *pai; // [rsp+8h] [rbp-C0h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-B8h] BYREF
char s[136]; // [rsp+40h] [rbp-88h] BYREF

if ( !name || (unsigned int)my_strvalidate(name, 3LL) )
{
*_errno_location() = 1;
result = 0LL;
}
else
{
sprintf(s, "Attempting to connect to server '%s'\n", name);
v2 = socket(2, 1, 0);
if ( v2 < 0 )
{
*_errno_location() = 1;
result = 0LL;
}
else
{
*(_QWORD *)&req.ai_flags = 0LL;
*(_QWORD *)&req.ai_socktype = 1LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
snprintf(v5, 8uLL, "%d", a2);
if ( getaddrinfo(name, v5, &req, &pai) )
{
*_errno_location() = 1;
result = 0LL;
}
else
{
v3 = connect(v2, pai->ai_addr, pai->ai_addrlen);
result = v2;
if ( v3 )
{
*_errno_location() = 2;
result = 0LL;
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *name, unsigned int a2)
{
int v2; // er12
int v3; // edx
__int64 result; // rax
char v5[8]; // [rsp+0h] [rbp-C8h] BYREF
struct addrinfo *pai; // [rsp+8h] [rbp-C0h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-B8h] BYREF
char s[136]; // [rsp+40h] [rbp-88h] BYREF

if ( !name || (unsigned int)my_strvalidate(name, 3LL) )
{
*_errno_location() = 1;
result = 0LL;
}
else
{
sprintf(s, "Attempting to connect to server '%s'\n", name);
v2 = socket(2, 1, 0);
if ( v2 < 0 )
{
*_errno_location() = 1;
result = 0LL;
}
else
{
*(_QWORD *)&req.ai_flags = 0LL;
*(_QWORD *)&req.ai_socktype = 1LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
snprintf(v5, 8uLL, "%d", a2);
if ( getaddrinfo(name, v5, &req, &pai) )
{
*_errno_location() = 1;
result = 0LL;
}
else
{
v3 = connect(v2, pai->ai_addr, pai->ai_addrlen);
result = v2;
if ( v3 )
{
*_errno_location() = 2;
result = 0LL;
}
}
}
}
return result;
}

original_code:
void* storage_connect(const char *hostname, const int port)
{
 char buff[100];
 if (hostname == ((void *)0)) {
  (*__errno_location ()) = 1;
  return ((void *)0);
 }
 if (my_strvalidate(hostname, 3)) {
  (*__errno_location ())=1;
  return ((void *)0);
 }
 sprintf(buff, "Attempting to connect to server '%s'\n",
   hostname);
 if (0 == 1) logger(stdout, buff);
 else if (0 == 2) logger(file, buff);
 int sock = socket(2, SOCK_STREAM, 0);
 if (sock < 0){
  (*__errno_location ())=1;
  return ((void *)0);
 }
 struct addrinfo serveraddr, *res;
 memset(&serveraddr, 0, sizeof serveraddr);
 serveraddr.ai_family = 0;
 serveraddr.ai_socktype = SOCK_STREAM;
 char portstr[8];
 snprintf(portstr, sizeof portstr, "%d", port);
 int status = getaddrinfo(hostname, portstr, &serveraddr, &res);
 if (status != 0){
  (*__errno_location ())=1;
  return ((void *)0);
 }
 status = connect(sock, res->ai_addr, res->ai_addrlen);
 if (status != 0){
  (*__errno_location ())=2;
  return ((void *)0);
 }
 return (void*) sock;
}

canonical_original_code:
void *storage_connect(char *hostname, int port)
{
 char buff[100];
 if (hostname == ((void *)0)) {
  (*__errno_location ()) = 1;
  return ((void *)0);
 }
 if (my_strvalidate(hostname, 3)) {
  (*__errno_location ())=1;
  return ((void *)0);
 }
 sprintf(buff, "Attempting to connect to server '%s'\n",
   hostname);
 if (0 == 1) logger(stdout, buff);
 else if (0 == 2) logger(file, buff);
 int sock = socket(2, SOCK_STREAM, 0);
 if (sock < 0){
  (*__errno_location ())=1;
  return ((void *)0);
 }
 struct addrinfo serveraddr; struct addrinfo *res;
 memset(&serveraddr, 0, sizeof serveraddr);
 serveraddr.ai_family = 0;
 serveraddr.ai_socktype = SOCK_STREAM;
 char portstr[8];
 snprintf(portstr, sizeof portstr, "%d", port);
 int status = getaddrinfo(hostname, portstr, &serveraddr, &res);
 if (status != 0){
  (*__errno_location ())=1;
  return ((void *)0);
 }
 status = connect(sock, res->ai_addr, res->ai_addrlen);
 if (status != 0){
  (*__errno_location ())=2;
  return ((void *)0);
 }
 return (void *) sock;
}

variable_types:
hostname
char *

variable_types: port int

variable_types:
buff
char [100]

variable_types: sock int

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

variable_types:
portstr
char [8]

variable_types: status int

return_type: void *

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


decompiled_code:
__int64 __fastcall storage_auth(const char *a1, __int64 a2, __int64 a3)
{
unsigned int v3; // ebp
const char *v4; // rax
size_t v5; // rax
__int64 result; // rax
char v7[8192]; // [rsp+0h] [rbp-2098h] BYREF
char s[152]; // [rsp+2000h] [rbp-98h] BYREF

if ( a3 )
{
v3 = a3;
if ( a1 && a2 )
{
sprintf(s, "Attempting to Login with username '%s'\n", a1);
memset(v7, 0, sizeof(v7));
v4 = (const char *)generate_encrypted_password(a2, 0LL);
snprintf(v7, 0x2000uLL, "AUTH %s %s\n", a1, v4);
v5 = strlen(v7);
if ( (unsigned int)sendall(v3, v7, v5)
|| (result = recvline(v3, v7, 0x2000LL), (_DWORD)result)
|| !strcmp(v7, "-1") )
{
auth = 0;
*_errno_location() = 4;
result = 0xFFFFFFFFLL;
}
else
{
auth = 1;
}
}
else
{
*_errno_location() = 1;
result = 0xFFFFFFFFLL;
}
}
else
{
*_errno_location() = 2;
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, __int64 a2, __int64 a3)
{
unsigned int v3; // ebp
const char *v4; // rax
size_t v5; // rax
__int64 result; // rax
char v7[8192]; // [rsp+0h] [rbp-2098h] BYREF
char s[152]; // [rsp+2000h] [rbp-98h] BYREF

if ( a3 )
{
v3 = a3;
if ( a1 && a2 )
{
sprintf(s, "Attempting to Login with username '%s'\n", a1);
memset(v7, 0, sizeof(v7));
v4 = (const char *)generate_encrypted_password(a2, 0LL);
snprintf(v7, 0x2000uLL, "AUTH %s %s\n", a1, v4);
v5 = strlen(v7);
if ( (unsigned int)sendall(v3, v7, v5)
|| (result = recvline(v3, v7, 0x2000LL), (_DWORD)result)
|| !strcmp(v7, "-1") )
{
auth = 0;
*_errno_location() = 4;
result = 0xFFFFFFFFLL;
}
else
{
auth = 1;
}
}
else
{
*_errno_location() = 1;
result = 0xFFFFFFFFLL;
}
}
else
{
*_errno_location() = 2;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int storage_auth(const char *username, const char *passwd, void *conn)
{
 if (!conn) {
  (*__errno_location ()) = 2;
  return -1;
 }
 if (username == ((void *)0)) {
  (*__errno_location ()) = 1;
  return -1;
 }
 if (passwd == ((void *)0)) {
  (*__errno_location ()) = 1;
  return -1;
 }
 char buff[100];
 sprintf(buff, "Attempting to Login with username  '%s'\n",username);
 if (0 == 1) logger(stdout, buff);
 else if (0 == 2) logger(file, buff);
 int sock = (int)conn;
 char buf[(1024 * 8)];
 memset(buf, 0, sizeof buf);
 char *encrypted_passwd = generate_encrypted_password(passwd, ((void *)0));
 snprintf(buf, sizeof buf, "AUTH %s %s\n", username, encrypted_passwd);
 if (sendall(sock, buf, strlen(buf)) == 0 && recvline(sock, buf, sizeof buf) == 0) {
  if (strcmp (buf, "-1") == 0) {
   auth = 0;
   (*__errno_location ()) = 4;
   return -1;
  }
  auth=1;
  return 0;
 }
 auth=0;
 (*__errno_location ())=4;
 return -1;
}

canonical_original_code:
int storage_auth(char *username, char *passwd, void *conn)
{
 if (!conn) {
  (*__errno_location ()) = 2;
  return -1;
 }
 if (username == ((void *)0)) {
  (*__errno_location ()) = 1;
  return -1;
 }
 if (passwd == ((void *)0)) {
  (*__errno_location ()) = 1;
  return -1;
 }
 char buff[100];
 sprintf(buff, "Attempting to Login with username  '%s'\n",username);
 if (0 == 1) logger(stdout, buff);
 else if (0 == 2) logger(file, buff);
 int sock = (int)conn;
 char buf[-1];
 memset(buf, 0, sizeof buf);
 char *encrypted_passwd = generate_encrypted_password(passwd, ((void *)0));
 snprintf(buf, sizeof buf, "AUTH %s %s\n", username, encrypted_passwd);
 if (sendall(sock, buf, strlen(buf)) == 0 && recvline(sock, buf, sizeof buf) == 0) {
  if (strcmp (buf, "-1") == 0) {
   auth = 0;
   (*__errno_location ()) = 4;
   return -1;
  }
  auth=1;
  return 0;
 }
 auth=0;
 (*__errno_location ())=4;
 return -1;
}

variable_types:
username
char *

variable_types:
conn
void *

variable_types:
buf
char [-1]


decompiled_code:
__int64 __fastcall storage_disconnect(__int64 a1)
{
unsigned int v1; // ebx

if ( a1 && (int)a1 >= 0 )
{
auth = 0;
v1 = close(a1);
if ( v1 == -1 )
*_errno_location() = 7;
else
v1 = 0;
}
else
{
*_errno_location() = 1;
v1 = -1;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
unsigned int v1; // ebx

if ( a1 && (int)a1 >= 0 )
{
auth = 0;
v1 = close(a1);
if ( v1 == -1 )
*_errno_location() = 7;
else
v1 = 0;
}
else
{
*_errno_location() = 1;
v1 = -1;
}
return v1;
}

original_code:
int storage_disconnect(void *conn)
{
 if (!conn) {
  (*__errno_location ()) = 1;
  return -1;
 }
 int sock = (int)conn;
 if (sock < 0){
  (*__errno_location ())=1;
  return -1;
 }
 auth = 0;
 int status = close(sock);
 if (status == -1) {
  (*__errno_location ()) = 7;
  return -1;
 }
 return 0;
}


repo: QCaudron/iterated-inference-pipeline

decompiled_code:
__int64 __fastcall send_par(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 v6; // rbx
__int64 result; // rax

if ( *(int *)a2 > 0 )
{
v6 = 0LL;
do
{
result = zmq_send(
a1,
*(_QWORD *)(*(_QWORD *)(a2 + 8) + 8 * v6),
8LL * *(int *)(*(_QWORD *)(*(_QWORD *)(a3 + 80) + 8 * v6) + 4LL),
a4);
++v6;
}
while ( *(_DWORD *)a2 > (int)v6 );
}
return result;
}

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

if ( *(int *)a2 > 0 )
{
v6 = 0LL;
do
{
result = zmq_send(
a1,
*(_QWORD *)(*(_QWORD *)(a2 + 8) + 8 * v6),
8LL * *(int *)(*(_QWORD *)(*(_QWORD *)(a3 + 80) + 8 * v6) + 4LL),
a4);
++v6;
}
while ( *(_DWORD *)a2 > (int)v6 );
}
return result;
}

original_code:
void send_par(void *socket, const struct s_par *p_par, struct s_data *p_data, int zmq_options)
{
    int i;
    for(i=0; i< p_par->size_natural; i++) {
 zmq_send(socket, p_par->natural[i], p_data->routers[i]->n_gp *sizeof (double), zmq_options);
    }
}

canonical_original_code:
void send_par(void *socket, struct s_par *p_par, struct s_data *p_data, int zmq_options)
{
    int i;
    for(i=0; i< p_par->size_natural; i++) {
 zmq_send(socket, p_par->natural[i], p_data->routers[i]->n_gp *sizeof (double), zmq_options);
    }
}

variable_types:
socket
void *

variable_types: struct s_par { int size_natural; double **natural; } *

variable_types: struct s_data { char **ts_name; char **cac_name; char *remainder_name; char u_data[2]; enum plom_implementations { PLOM_ODE=0, PLOM_SDE=1, PLOM_PSR=2 } implementation; enum plom_noises_off { PLOM_NO_DEM_STO=expr, PLOM_NO_ENV_STO=expr, PLOM_NO_DRIFT=expr } noises_off; double **data; unsigned int *indn_data_nonan; unsigned int *times; struct s_data_ind { int n_nonan; unsigned int *ind_nonan; } **data_ind; struct s_obs2ts { int n_ts_unique; unsigned int *n_stream; unsigned int *n_cac; unsigned int ***cac; int offset; } **obs2ts; struct s_router { int p; int n_gp; unsigned int *map; char *name; char **group_name; double (**f)(double, double, double); double (**f_inv)(double, double, double); double (**f_scale)(double); double (**f_derivative)(double, double, double); double (**f_inv_derivative)(double, double, double); double multiplier; int is_duration; double *min; double *max; double *min_z; double *max_z; } **routers; struct s_drift { int ind_par_Xdrift_applied; int ind_volatility_Xdrift; int offset; } **drift; struct s_iterator { int length; unsigned int *ind; unsigned int *offset; int nbtot; } *p_it_all; struct s_iterator *p_it_only_drift; struct s_iterator *p_it_par_sv; struct s_iterator *p_it_all_no_drift; struct s_iterator *p_it_par_proc_par_obs_no_drift; struct s_iterator *p_it_par_sv_and_drift; struct s_iterator *p_it_noise; struct s_iterator *p_it_all_no_theta_remainder; struct s_iterator *p_it_theta_remainder; int nb_obs; int nb_obs_nonan; unsigned int *n_terms; double *prop_school; double ***school_terms; double **waifw; void *method_specific_data; } *

variable_types: i int

user_defined_types: struct s_data { char **ts_name; char **cac_name; char *remainder_name; char u_data[2]; enum plom_implementations implementation; enum plom_noises_off noises_off; double **data; unsigned int *indn_data_nonan; unsigned int *times; struct s_data_ind **data_ind; struct s_obs2ts **obs2ts; struct s_router **routers; struct s_drift **drift; struct s_iterator *p_it_all; struct s_iterator *p_it_only_drift; struct s_iterator *p_it_par_sv; struct s_iterator *p_it_all_no_drift; struct s_iterator *p_it_par_proc_par_obs_no_drift; struct s_iterator *p_it_par_sv_and_drift; struct s_iterator *p_it_noise; struct s_iterator *p_it_all_no_theta_remainder; struct s_iterator *p_it_theta_remainder; int nb_obs; int nb_obs_nonan; unsigned int *n_terms; double *prop_school; double ***school_terms; double **waifw; void *method_specific_data; }


original_code:
void recv_par(struct s_par *p_par, struct s_data *p_data, void *socket)
{
    int i;
    for(i=0; i< p_par->size_natural; i++) {
 zmq_recv(socket, p_par->natural[i], p_data->routers[i]->n_gp * sizeof (double), 0);
    }
}

user_defined_types: struct s_par { int size_natural; double **natural; }

user_defined_types: enum plom_implementations { PLOM_ODE=0, PLOM_SDE=1, PLOM_PSR=2 }

user_defined_types: enum plom_noises_off { PLOM_NO_DEM_STO=expr, PLOM_NO_ENV_STO=expr, PLOM_NO_DRIFT=expr }

user_defined_types: struct s_iterator { int length; unsigned int *ind; unsigned int *offset; int nbtot; }

user_defined_types: struct s_data_ind { int n_nonan; unsigned int *ind_nonan; }

user_defined_types: struct s_obs2ts { int n_ts_unique; unsigned int *n_stream; unsigned int *n_cac; unsigned int ***cac; int offset; }

user_defined_types: struct s_router { int p; int n_gp; unsigned int *map; char *name; char **group_name; double (**f)(double, double, double); double (**f_inv)(double, double, double); double (**f_scale)(double); double (**f_derivative)(double, double, double); double (**f_inv_derivative)(double, double, double); double multiplier; int is_duration; double *min; double *max; double *min_z; double *max_z; }

user_defined_types: struct s_drift { int ind_par_Xdrift_applied; int ind_volatility_Xdrift; int offset; }


decompiled_code:
__int64 __fastcall send_X(__int64 a1, _QWORD *a2, __int64 a3, unsigned int a4)
{
int v5; // ebx

v5 = N_TS_INC_UNIQUE + *(_DWORD *)(*(_QWORD *)(a3 + 104) + 24LL) + N_CAC * N_PAR_SV;
zmq_send(a1, a2 + 2, 8LL, 2LL);
zmq_send(a1, a2[1], 8LL * N_TS, 2LL);
return zmq_send(a1, *a2, 8LL * v5, a4);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, _QWORD *a2, __int64 a3, unsigned int a4)
{
int v5; // ebx

v5 = N_TS_INC_UNIQUE + *(_DWORD *)(*(_QWORD *)(a3 + 104) + 24LL) + N_CAC * N_PAR_SV;
zmq_send(a1, a2 + 2, 8LL, 2LL);
zmq_send(a1, a2[1], 8LL * N_TS, 2LL);
return zmq_send(a1, *a2, 8LL * v5, a4);
}

original_code:
void send_X(void *socket, const struct s_X *p_X, struct s_data *p_data, int zmq_options)
{
    int size_proj = N_PAR_SV*N_CAC + p_data->p_it_only_drift->nbtot + N_TS_INC_UNIQUE;
    zmq_send(socket, &(p_X->dt), sizeof (double), 2);
    zmq_send(socket, p_X->obs, N_TS * sizeof (double), 2);
    zmq_send(socket, p_X->proj, size_proj * sizeof (double), zmq_options);
}

canonical_original_code:
void send_X(void *socket, struct s_X *p_X, struct s_data *p_data, int zmq_options)
{
    int size_proj = N_PAR_SV*N_CAC + p_data->p_it_only_drift->nbtot + N_TS_INC_UNIQUE;
    zmq_send(socket, &(p_X->dt), sizeof (double), 2);
    zmq_send(socket, p_X->obs, N_TS * sizeof (double), 2);
    zmq_send(socket, p_X->proj, size_proj * sizeof (double), zmq_options);
}

variable_types: struct s_X { double *proj; double *obs; double dt; double dt0; } *


decompiled_code:
__int64 __fastcall recv_X(_QWORD *a1, __int64 a2, __int64 a3)
{
int v4; // ebx

v4 = N_TS_INC_UNIQUE + *(_DWORD *)(*(_QWORD *)(a2 + 104) + 24LL) + N_CAC * N_PAR_SV;
zmq_recv(a3, a1 + 2, 8LL, 0LL);
zmq_recv(a3, a1[1], 8LL * N_TS, 0LL);
return zmq_recv(a3, *a1, 8LL * v4, 0LL);
}

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

v4 = N_TS_INC_UNIQUE + *(_DWORD *)(*(_QWORD *)(a2 + 104) + 24LL) + N_CAC * N_PAR_SV;
zmq_recv(a3, a1 + 2, 8LL, 0LL);
zmq_recv(a3, a1[1], 8LL * N_TS, 0LL);
return zmq_recv(a3, *a1, 8LL * v4, 0LL);
}

original_code:
void recv_X(struct s_X *p_X, struct s_data *p_data, void *socket)
{
    int size_proj = N_PAR_SV*N_CAC + p_data->p_it_only_drift->nbtot + N_TS_INC_UNIQUE;
    zmq_recv(socket, &(p_X->dt), sizeof (double), 0);
    zmq_recv(socket, p_X->obs, N_TS * sizeof (double), 0);
    zmq_recv(socket, p_X->proj, size_proj * sizeof (double), 0);
}

user_defined_types: struct s_X { double *proj; double *obs; double dt; double dt0; }


decompiled_code:
__time_t s_clock()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return 1000 * v1.tv_sec + v1.tv_usec / 1000;
}

canonical_decompiled_code:
__time_t func0()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return 1000 * v1.tv_sec + v1.tv_usec / 1000;
}

original_code:
int64_t s_clock (void)
{
    struct timeval tv;
    gettimeofday (&tv, ((void *)0));
    return (int64_t) (tv.tv_sec * 1000 + tv.tv_usec / 1000);
}

canonical_original_code:
long s_clock()
{
    struct timeval tv;
    gettimeofday (&tv, ((void *)0));
    return (long) (tv.tv_sec * 1000 + tv.tv_usec / 1000);
}

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

return_type: long


original_code:
struct s_duration time_exec(int64_t s1, int64_t s2)
{
    struct s_duration t_exec;
    double duration = ((double) (s2 - s1) / 1000.0);
    t_exec.d = (unsigned int) floor(duration / 86400.0);
    duration -= t_exec.d * 86400.0;
    t_exec.h = (unsigned int) floor(duration / 3600.0);
    duration -= t_exec.h * 3600.0;
    t_exec.m = (unsigned int) floor(duration / 60.0);
    t_exec.s = duration - t_exec.m * 60.0;
    return t_exec;
}

canonical_original_code:
struct s_duration time_exec(long s1, long s2)
{
    struct s_duration t_exec;
    double duration = ((double) (s2 - s1) / 1000.0);
    t_exec.d = (unsigned int) floor(duration / 86400.0);
    duration -= t_exec.d * 86400.0;
    t_exec.h = (unsigned int) floor(duration / 3600.0);
    duration -= t_exec.h * 3600.0;
    t_exec.m = (unsigned int) floor(duration / 60.0);
    t_exec.s = duration - t_exec.m * 60.0;
    return t_exec;
}

variable_types: struct s_duration { unsigned int d; unsigned int h; unsigned int m; double s; }

variable_types: duration double


decompiled_code:
__int64 __fastcall sum1u(_DWORD *a1, int a2)
{
_DWORD *v2; // rax
unsigned int v3; // edx

if ( a2 <= 0 )
return 0;
v2 = a1;
v3 = 0;
do
v3 += *v2++;
while ( v2 != &a1[a2 - 1 + 1] );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1, int a2)
{
_DWORD *v2; // rax
unsigned int v3; // edx

if ( a2 <= 0 )
return 0;
v2 = a1;
v3 = 0;
do
v3 += *v2++;
while ( v2 != &a1[a2 - 1 + 1] );
return v3;
}

original_code:
unsigned int sum1u(unsigned int *tab, int length_tab)
{
    int i;
    unsigned int res;
    res=0;
    for(i=0; i< length_tab ; i++)
        res+=tab[i];
    return res;
}

variable_types:
tab
unsigned int *

variable_types:
res
unsigned int

return_type: unsigned int


original_code:
void online_mean_var(double *x, int N_x, double *mean, double *var)
{
    int k;
    double n=0.0;
    *mean=0.0;
    double M2=0.0;
    double delta;
    for(k=0;k<N_x;k++)
        {
            n = n + 1.0;
            delta = x[k] - *mean;
            *mean += delta/n;
            M2 += delta*(x[k] - *mean);
        }
    *var = M2/(n - 1.0);
}

canonical_original_code:
void online_mean_var(double *x, int N_x, double *mean, double *var)
{
    int k;
    double n = 0.0;
    *mean=0.0;
    double M2 = 0.0;
    double delta;
    for(k=0;k<N_x;k++)
        {
            n = n + 1.0;
            delta = x[k] - *mean;
            *mean += delta/n;
            M2 += delta*(x[k] - *mean);
        }
    *var = M2/(n - 1.0);
}

variable_types:
x
double *

variable_types:
mean
double *

variable_types:
var
double *

variable_types: k int

variable_types: n double

variable_types: delta double


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

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

original_code:
int get_thread_id(void)
{
    int thread_id;
    thread_id=0;
    return thread_id;
}

canonical_original_code:
int get_thread_id()
{
    int thread_id;
    thread_id=0;
    return thread_id;
}


decompiled_code:
__int64 __fastcall get_min_u(unsigned int *a1, int a2)
{
unsigned int v2; // edx
unsigned int *v3; // rax
__int64 v4; // rsi

v2 = *a1;
if ( a2 > 0 )
{
v3 = a1;
v4 = (__int64)&a1[a2 - 1 + 1];
do
{
if ( *v3 < v2 )
v2 = *v3;
++v3;
}
while ( v3 != (unsigned int *)v4 );
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int *a1, int a2)
{
unsigned int v2; // edx
unsigned int *v3; // rax
__int64 v4; // rsi

v2 = *a1;
if ( a2 > 0 )
{
v3 = a1;
v4 = (__int64)&a1[a2 - 1 + 1];
do
{
if ( *v3 < v2 )
v2 = *v3;
++v3;
}
while ( v3 != (unsigned int *)v4 );
}
return v2;
}

original_code:
int get_min_u(unsigned int *tab, int length_tab)
{
    int i;
    int min=tab[0];
    for (i=0 ; i<length_tab ;i++){
        if (tab[i]<min) {
            min=tab[i];
        }
    }
    return (min);
}

canonical_original_code:
int get_min_u(unsigned int *tab, int length_tab)
{
    int i;
    int min = tab[0];
    for (i=0 ; i<length_tab ;i++){
        if (tab[i]<min) {
            min=tab[i];
        }
    }
    return (min);
}

variable_types: min int


decompiled_code:
__int64 __fastcall get_max_u(unsigned int *a1, int a2)
{
unsigned int v2; // edx
unsigned int *v3; // rax
__int64 v4; // rsi

v2 = *a1;
if ( a2 > 0 )
{
v3 = a1;
v4 = (__int64)&a1[a2 - 1 + 1];
do
{
if ( *v3 > v2 )
v2 = *v3;
++v3;
}
while ( v3 != (unsigned int *)v4 );
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int *a1, int a2)
{
unsigned int v2; // edx
unsigned int *v3; // rax
__int64 v4; // rsi

v2 = *a1;
if ( a2 > 0 )
{
v3 = a1;
v4 = (__int64)&a1[a2 - 1 + 1];
do
{
if ( *v3 > v2 )
v2 = *v3;
++v3;
}
while ( v3 != (unsigned int *)v4 );
}
return v2;
}

original_code:
int get_max_u(unsigned int *tab, int length_tab)
{
    int i;
    int max=tab[0];
    for (i=0 ; i<length_tab ;i++){
        if (tab[i]>max){
            max=tab[i];
        }
    }
    return (max);
}

canonical_original_code:
int get_max_u(unsigned int *tab, int length_tab)
{
    int i;
    int max = tab[0];
    for (i=0 ; i<length_tab ;i++){
        if (tab[i]>max){
            max=tab[i];
        }
    }
    return (max);
}

variable_types: max int


original_code:
void update_to_be_estimated(struct s_best *p_best)
{
    int k;
    p_best->n_to_be_estimated = 0;
    for(k=0; k<p_best->length; k++) {
        if( (gsl_matrix_get(p_best->var, k, k) > 0.0) && (p_best->is_follower[k] == 0) ) {
            p_best->to_be_estimated[ p_best->n_to_be_estimated ] = k;
            p_best->is_estimated[k] = 1;
            p_best->n_to_be_estimated++;
        } else {
            gsl_matrix_set(p_best->var, k, k, 0.0);
            p_best->is_estimated[k] = 0;
        }
    }
}

variable_types: struct s_best { int length; struct gsl_vector { unsigned long size; unsigned long stride; double *data; struct gsl_block_struct { unsigned long size; double *data; } *block; int owner; } *mean; struct gsl_vector *proposed; struct gsl_matrix { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_struct *block; int owner; } *var; int n_to_be_estimated; unsigned int *to_be_estimated; unsigned int *is_estimated; int n_follow; unsigned int *follower; unsigned int *follow; unsigned int *is_follower; double *mean_sampling; struct gsl_matrix *var_sampling; double **par_prior; double (**prior)(double x, double a, double b); } *

user_defined_types: struct s_best { int length; struct gsl_vector *mean; struct gsl_vector *proposed; struct gsl_matrix *var; int n_to_be_estimated; unsigned int *to_be_estimated; unsigned int *is_estimated; int n_follow; unsigned int *follower; unsigned int *follow; unsigned int *is_follower; double *mean_sampling; struct gsl_matrix *var_sampling; double **par_prior; double (**prior)(double x, double a, double b); }

user_defined_types: struct gsl_vector { unsigned long size; unsigned long stride; double *data; struct gsl_block_struct *block; int owner; }


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

result = a1;
if ( (int)a1 > (int)a2 )
{
print_warning("N_TREADS > J, N_THREADS has been set to J");
result = a2;
}
return result;
}

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

result = a1;
if ( (int)a1 > (int)a2 )
{
print_warning("N_TREADS > J, N_THREADS has been set to J");
result = a2;
}
return result;
}

original_code:
int sanitize_n_threads(int n_threads, int J)
{
    if(n_threads > J){
        print_warning("N_TREADS > J, N_THREADS has been set to J");
        return J;
    } else {
        return n_threads;
    }
}

variable_types: J int


decompiled_code:
__int64 __fastcall in_u(int a1, _DWORD *a2, int a3)
{
_DWORD *v3; // rax
__int64 v4; // rdx

if ( a3 <= 0 )
return 0LL;
v3 = a2;
v4 = (__int64)&a2[a3 - 1 + 1];
while ( *v3 != a1 )
{
if ( ++v3 == (_DWORD *)v4 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, _DWORD *a2, int a3)
{
_DWORD *v3; // rax
__int64 v4; // rdx

if ( a3 <= 0 )
return 0LL;
v3 = a2;
v4 = (__int64)&a2[a3 - 1 + 1];
while ( *v3 != a1 )
{
if ( ++v3 == (_DWORD *)v4 )
return 0LL;
}
return 1LL;
}

original_code:
int in_u(int i, unsigned int *tab, int length){
    int k;
    for (k=0 ; k< length; k++) {
        if (tab[k] == i) {
            return 1;
        }
    }
    return 0;
}

variable_types: i int

variable_types: length int


decompiled_code:
__int64 __fastcall in_drift(int a1, _DWORD **a2)
{
_DWORD **i; // rax

if ( N_DRIFT <= 0 )
return 0LL;
for ( i = a2; **i != a1; ++i )
{
if ( i == &a2[N_DRIFT - 1] )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, _DWORD **a2)
{
_DWORD **i; // rax

if ( N_DRIFT <= 0 )
return 0LL;
for ( i = a2; **i != a1; ++i )
{
if ( i == &a2[N_DRIFT - 1] )
return 0LL;
}
return 1LL;
}

original_code:
int in_drift(int i, struct s_drift **drift){
    int k;
    for (k=0; k< N_DRIFT; k++) {
        if (drift[k]->ind_par_Xdrift_applied == i) {
            return 1;
        }
    }
    return 0;
}

variable_types: struct s_drift { int ind_par_Xdrift_applied; int ind_volatility_Xdrift; int offset; } **


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

result = (unsigned int)a2;
if ( a1 >= 0 && a2 > a1 )
result = (unsigned int)a1;
return result;
}

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

result = (unsigned int)a2;
if ( a1 >= 0 && a2 > a1 )
result = (unsigned int)a1;
return result;
}

original_code:
int plom_sanitize_nb_obs(int nb_obs, int n_data){
    if(nb_obs >= 0){
 return (nb_obs < n_data) ? nb_obs : n_data;
    }
    return n_data;
}


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

if ( a1 )
{
result = *(_QWORD *)(a1 + 8);
if ( result != -1 )
{
result = _InterlockedExchangeAdd64((volatile signed __int64 *)(a1 + 8), 0xFFFFFFFFFFFFFFFFLL);
if ( result == 1 )
result = json_delete();
}
}
return result;
}

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

if ( a1 )
{
result = *(_QWORD *)(a1 + 8);
if ( result != -1 )
{
result = _InterlockedExchangeAdd64((volatile signed __int64 *)(a1 + 8), 0xFFFFFFFFFFFFFFFFLL);
if ( result == 1 )
result = json_delete();
}
}
return result;
}

original_code:
static inline
void json_decref(json_t *json)
{
    if(json && json->refcount != (size_t)-1 && __atomic_sub_fetch(&json->refcount, 1, 3) == 0)
        json_delete(json);
}

canonical_original_code:
static inline void json_decref(struct json_t *json)
{
    if(json && json->refcount != (unsigned long)-1 && __atomic_sub_fetch(&json->refcount, 1, 3) == 0)
        json_delete(json);
}

variable_types: struct json_t { enum json_type { JSON_OBJECT=0, JSON_ARRAY=1, JSON_STRING=2, JSON_INTEGER=3, JSON_REAL=4, JSON_TRUE=5, JSON_FALSE=6, JSON_NULL=7 } type; unsigned long refcount; } *

user_defined_types: struct json_t { enum json_type type; unsigned long refcount; }


decompiled_code:
__int64 ask_update()
{
__int64 v0; // rbx

v0 = json_pack("{s,s}", "flag", &unk_2A8);
json_dumpf(v0, stderr, 0LL);
fputc(10, stderr);
fflush(stderr);
return json_decref(v0);
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rbx

v0 = json_pack("{s,s}", "flag", &unk_2A8);
json_dumpf(v0, stderr, 0LL);
fputc(10, stderr);
fflush(stderr);
return func0(v0);
}

original_code:
void ask_update()
{
    json_t *root;
    root = json_pack("{s,s}", "flag", "upd");
    json_dumpf(root, stderr, 0); fprintf(stderr, "\n");
    fflush(stderr);
    json_decref(root);
}

canonical_original_code:
void ask_update()
{
    struct json_t *root;
    root = json_pack("{s,s}", "flag", "upd");
    json_dumpf(root, stderr, 0); fprintf(stderr, "\n");
    fflush(stderr);
    json_decref(root);
}

user_defined_types: enum json_type { JSON_OBJECT=0, JSON_ARRAY=1, JSON_STRING=2, JSON_INTEGER=3, JSON_REAL=4, JSON_TRUE=5, JSON_FALSE=6, JSON_NULL=7 }


block

decompiled_code:
char *block()
{
char s[12]; // [rsp+Ch] [rbp-Ch] BYREF

ask_update();
return fgets(s, 4, stdin);
}

canonical_decompiled_code:
char *func2()
{
char s[12]; // [rsp+Ch] [rbp-Ch] BYREF

func1();
return fgets(s, 4, stdin);
}

original_code:
void block()
{
    ask_update();
    char tmp[4];
    fgets(tmp, 4, stdin);
}

variable_types:
tmp
char [4]


decompiled_code:
__int64 __fastcall update_walk_rates(__int64 a1, __int64 a2)
{
__int64 v2; // rbx

ask_update();
fflush(stderr);
v2 = load_json();
if ( json_object_size(v2) )
{
load_best(a1, a2, v2, 0LL);
print_err("data integrated");
}
return json_decref(v2);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int64 v2; // rbx

func1();
fflush(stderr);
v2 = load_json();
if ( json_object_size(v2) )
{
load_best(a1, a2, v2, 0LL);
print_err("data integrated");
}
return func0(v2);
}

original_code:
void update_walk_rates(struct s_best *p_best, struct s_data *p_data)
{
    ask_update();
    fflush(stderr);
    json_t *theta = load_json();
    if(json_object_size(theta)) {
        load_best(p_best, p_data, theta, 0);
        print_err("data integrated");
    }
    json_decref(theta);
}

canonical_original_code:
void update_walk_rates(struct s_best *p_best, struct s_data *p_data)
{
    ask_update();
    fflush(stderr);
    struct json_t *theta = load_json();
    if(json_object_size(theta)) {
        load_best(p_best, p_data, theta, 0);
        print_err("data integrated");
    }
    json_decref(theta);
}

variable_types: struct s_data { char **ts_name; char **cac_name; char *remainder_name; char u_data[2]; enum plom_implementations { PLOM_ODE=0, PLOM_SDE=1, PLOM_PSR=2 } implementation; enum plom_noises_off { PLOM_NO_DEM_STO=expr, PLOM_NO_ENV_STO=expr, PLOM_NO_DRIFT=expr } noises_off; double **data; unsigned int *indn_data_nonan; unsigned int *times; struct s_data_ind { int n_nonan; unsigned int *ind_nonan; } **data_ind; struct s_obs2ts { int n_ts_unique; unsigned int *n_stream; unsigned int *n_cac; unsigned int ***cac; int offset; } **obs2ts; struct s_router { int p; int n_gp; unsigned int *map; char *name; char **group_name; double (**f)(double, double, double); double (**f_inv)(double, double, double); double (**f_scale)(double); double (**f_derivative)(double, double, double); double (**f_inv_derivative)(double, double, double); double multiplier; int is_duration; double *min; double *max; double *min_z; double *max_z; } **routers; struct s_drift { int ind_par_Xdrift_applied; int ind_volatility_Xdrift; int offset; } **drift; struct s_iterator { int length; unsigned int *ind; unsigned int *offset; int nbtot; } *p_it_all; struct s_iterator *p_it_only_drift; struct s_iterator *p_it_par_sv; struct s_iterator *p_it_all_no_drift; struct s_iterator *p_it_par_proc_par_obs_no_drift; struct s_iterator *p_it_par_sv_and_drift; struct s_iterator *p_it_noise; struct s_iterator *p_it_all_no_theta_remainder; struct s_iterator *p_it_theta_remainder; int nb_obs; int nb_obs_nonan; unsigned int *n_terms; double *prop_school; double ***school_terms; double **waifw; void *method_specific_data; } *

user_defined_types: struct gsl_matrix { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_struct *block; int owner; }

user_defined_types: struct gsl_block_struct { unsigned long size; double *data; }