WfaRcvVOCyclic

decompiled_code:
__int64 __fastcall WfaRcvVOCyclic(__int64 a1)
{
__int64 v2; // r14
int v3; // edi

if ( *(_DWORD *)(a1 + 40) != 42 )
return 0LL;
v2 = *((int *)&wmmps_info + 10);
pthread_mutex_lock((pthread_mutex_t *)&wmm_thr[50 * v2 + 40]);
while ( !wmm_thr[50 * v2 + 1] )
pthread_cond_wait((pthread_cond_t *)&wmm_thr[50 * v2 + 18], (pthread_mutex_t *)&wmm_thr[50 * v2 + 40]);
pthread_mutex_unlock((pthread_mutex_t *)&wmm_thr[50 * v2 + 40]);
v3 = psSockfd;
gtgWmmPS = 0;
wmm_thr[50 * v2 + 1] = 0;
close(v3);
psSockfd = -1;
signal(14, (__sighandler_t)((char *)WfaRcvStop + 1));
sleep(1u);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v2; // r14
int v3; // edi

if ( *(_DWORD *)(a1 + 40) != 42 )
return 0LL;
v2 = *((int *)&wmmps_info + 10);
pthread_mutex_lock((pthread_mutex_t *)&wmm_thr[50 * v2 + 40]);
while ( !wmm_thr[50 * v2 + 1] )
pthread_cond_wait((pthread_cond_t *)&wmm_thr[50 * v2 + 18], (pthread_mutex_t *)&wmm_thr[50 * v2 + 40]);
pthread_mutex_unlock((pthread_mutex_t *)&wmm_thr[50 * v2 + 40]);
v3 = psSockfd;
gtgWmmPS = 0;
wmm_thr[50 * v2 + 1] = 0;
close(v3);
psSockfd = -1;
signal(14, (__sighandler_t)((char *)WfaRcvStop + 1));
sleep(1u);
return 0LL;
}

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

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

variable_types: r int

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

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


repo: wfapf/TDLS

decompiled_code:
char *__fastcall create_apts_msg(int a1, __int64 a2, int a3)
{
int v3; // eax
__int64 v4; // rax

*(_DWORD *)a2 = *(_DWORD *)&wmmps_info.sa_data[6];
v3 = *((_DWORD *)&wmmps_info + 12);
*(_QWORD *)(a2 + 8) = 0LL;
*(_DWORD *)(a2 + 4) = v3;
v4 = 4LL * a1;
*(_QWORD *)(a2 + 16) = 0LL;
*(_DWORD *)(a2 + 36) = a3;
*(_DWORD *)(a2 + 40) = apts_msgs[v4 + 1];
return strcpy((char *)(a2 + 44), (const char *)apts_msgs[v4]);
}

canonical_decompiled_code:
char *__fastcall func3(int a1, __int64 a2, int a3)
{
int v3; // eax
__int64 v4; // rax

*(_DWORD *)a2 = *(_DWORD *)&wmmps_info.sa_data[6];
v3 = *((_DWORD *)&wmmps_info + 12);
*(_QWORD *)(a2 + 8) = 0LL;
*(_DWORD *)(a2 + 4) = v3;
v4 = 4LL * a1;
*(_QWORD *)(a2 + 16) = 0LL;
*(_DWORD *)(a2 + 36) = a3;
*(_DWORD *)(a2 + 40) = apts_msgs[v4 + 1];
return strcpy((char *)(a2 + 44), (const char *)apts_msgs[v4]);
}

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

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

variable_types: msg int

variable_types:
txbuf
unsigned int []

variable_types: id int

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

return_type: void


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

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

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

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

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

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

variable_types:
buf
char *

variable_types: len int

variable_types: i int


mpx

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

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

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

variable_types:
m
char *


WfaRcvProc

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

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

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

v4 = *(_DWORD *)(a1 + 40);
num_hello = 0;
v5 = *((_DWORD *)&wmmps_info + 10);
func5("STA recv\n", a1, 64);
if ( (unsigned int)(v4 - 1) > 0x24 )
return 0xFFFFFFFFLL;
*((_DWORD *)&wmmps_info + 5) = *(_DWORD *)(a1 + 40);
*(_DWORD *)&wmmps_info.sa_family = *(_DWORD *)(a1 + 36);
v6 = 50LL * v5;
pthread_mutex_lock((pthread_mutex_t *)&wmm_thr[v6 + 30]);
wmm_thr[v6] = *((_DWORD *)&wmmps_info + 14);
pthread_mutex_unlock((pthread_mutex_t *)&wmm_thr[v6 + 30]);
++*a3;
return 0LL;
}

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

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

variable_types:
rmsg
unsigned int *

variable_types: length int

variable_types:
state
int *

variable_types: usedThread int

return_type: int


receiver

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

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

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

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

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

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

variable_types: tos int

variable_types:
type
unsigned int


WfaStaResetAll

decompiled_code:
int WfaStaResetAll()
{
size_t v0; // rdx
int v1; // edi
int result; // eax

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

canonical_decompiled_code:
int func8()
{
size_t v0; // rdx
int v1; // edi
int result; // eax

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

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

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


WfaRcvNotCare

decompiled_code:
__int64 __fastcall WfaRcvNotCare(__int64 a1)
{
_DWORD *v1; // rcx

if ( (int)receiver_constprop_0(a1, 38) < 0 )
WfaStaResetAll();
else
++*v1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
_DWORD *v1; // rcx

if ( (int)func2(a1, 38) < 0 )
func8();
else
++*v1;
return 0LL;
}

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

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


WfaRcvVO

decompiled_code:
__int64 __fastcall WfaRcvVO(__int64 a1)
{
_DWORD *v1; // rcx

if ( (int)receiver_constprop_0(a1, 38) < 0 )
WfaStaResetAll();
else
++*v1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
_DWORD *v1; // rcx

if ( (int)func2(a1, 38) < 0 )
func8();
else
++*v1;
return 0LL;
}

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

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


WfaRcvVI

decompiled_code:
__int64 __fastcall WfaRcvVI(__int64 a1)
{
_DWORD *v1; // rcx

if ( (int)receiver_constprop_0(a1, 38) >= 0 )
++*v1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
_DWORD *v1; // rcx

if ( (int)func2(a1, 38) >= 0 )
++*v1;
return 0LL;
}

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

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


WfaRcvBE

decompiled_code:
__int64 __fastcall WfaRcvBE(__int64 a1)
{
_DWORD *v1; // rcx

if ( (int)receiver_constprop_0(a1, 38) >= 0 )
++*v1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
_DWORD *v1; // rcx

if ( (int)func2(a1, 38) >= 0 )
++*v1;
return 0LL;
}

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

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


WfaRcvBK

decompiled_code:
__int64 __fastcall WfaRcvBK(__int64 a1)
{
_DWORD *v1; // rcx

if ( (int)receiver_constprop_0(a1, 38) >= 0 )
++*v1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
_DWORD *v1; // rcx

if ( (int)func2(a1, 38) >= 0 )
++*v1;
return 0LL;
}

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

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


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

variable_types:
txbuf
unsigned long *

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


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

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

canonical_decompiled_code:
__int64 __fastcall func15(int a1)
{
int v1; // eax
int v2; // ecx
bool v3; // zf
int v4; // edx
__int64 result; // rax

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

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


wfaSetDUTPwrMgmt

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

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

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

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

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

variable_types: mode int

variable_types:
iface
char [32]


wfaWmmPowerSaveProcess

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

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

canonical_decompiled_code:
__int64 __fastcall func17(int a1)
{
int v1; // eax
int v2; // ebp
unsigned int v3; // ebx
int v4; // eax
__int64 v5; // rcx
__int64 result; // rax
unsigned int v7; // [rsp+Ch] [rbp-3Ch]
socklen_t addr_len; // [rsp+1Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-28h] BYREF

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

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

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

variable_types: sockfd int

variable_types: rbytes int

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

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


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int16 v3; // r12
FILE *v4; // rdi
int v5; // er13
__int64 v6; // rbx
int v7; // edi
int v8; // eax
int v9; // edx
int v10; // eax
char v11; // al
unsigned __int64 v12; // r13
unsigned int v13; // er8
int v14; // er15
size_t v15; // rax
__int64 v16; // r13
socklen_t v17; // edx
const __m128i *v18; // rax
unsigned __int64 v19; // r13
int v20; // er15
ssize_t v21; // rax
int v23; // eax
__int64 v24; // r15
void (__fastcall *v25)(__int16 *); // rax
__int64 v26; // rdx
size_t v27; // rax
int v28; // eax
size_t v29; // rax
char *v30; // rax
const char *v31; // rbp
int v32; // eax
__int64 v33; // rcx
socklen_t v34; // edx
int v35; // eax
__int64 v36; // rcx
__int64 v37; // [rsp+0h] [rbp-2718h]
unsigned int *v38; // [rsp+8h] [rbp-2710h]
const char *cp; // [rsp+10h] [rbp-2708h]
signed int v40; // [rsp+18h] [rbp-2700h]
__int16 v41; // [rsp+1Eh] [rbp-26FAh]
int v42; // [rsp+24h] [rbp-26F4h] BYREF
char *save_ptr; // [rsp+28h] [rbp-26F0h] BYREF
struct sockaddr v44; // [rsp+30h] [rbp-26E8h] BYREF
char s2[16]; // [rsp+40h] [rbp-26D8h] BYREF
__m128i v46; // [rsp+50h] [rbp-26C8h]
fd_set readfds; // [rsp+60h] [rbp-26B8h] BYREF
char s[512]; // [rsp+E0h] [rbp-2638h] BYREF
char buf[1024]; // [rsp+2E0h] [rbp-2438h] BYREF
char v50[4096]; // [rsp+6E0h] [rbp-2038h] BYREF
__int16 v51[2076]; // [rsp+16E0h] [rbp-1038h] BYREF

v42 = 1024;
save_ptr = 0LL;
if ( argc <= 2 )
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_ca.c", 136LL);
fprintf(stderr, "Usage: %s <control interface> <local control agent port>\n", *argv);
goto LABEL_91;
}
v3 = atoi(argv[2]);
if ( argc != 3 )
{
if ( argc != 4 )
{
cp = argv[3];
if ( (unsigned int)isIpV4Addr(cp) != 1 && (unsigned int)isNumber(argv[4]) != 1 )
{
v41 = atoi(argv[4]);
if ( argc != 5 )
{
v4 = fopen(argv[5], "a");
if ( v4 )
{
v5 = fileno(v4);
if ( (wfa_defined_debug & 2) != 0 )
fprintf(stdout, "redirecting the output to %s\n", argv[5]);
dup2(v5, 1);
dup2(v5, 2);
}
else
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_ca.c", 170LL);
fwrite("Cant open the log file continuing without redirecting\n", 1uLL, 0x36uLL, stderr);
}
}
goto LABEL_11;
}
return 1;
}
fprintf(stderr, "File %s, Line %ld: ", "wfa_ca.c", 147LL);
fprintf(stderr, "Usage: %s <control interface> <local control agent port> <DUT IP ADDRESS> <DUT PORT>\n", *argv);
LABEL_91:
exit(1);
}
cp = getenv("WFA_ENV_AGENT_IPADDR");
if ( !cp )
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_ca.c", 178LL);
fwrite("Environment variable WFA_ENV_AGENT_IPADDR not set or specify DUT IP/PORT\n", 1uLL, 0x49uLL, stderr);
exit(1);
}
if ( (unsigned int)isIpV4Addr(cp) != 1 )
{
v30 = getenv("WFA_ENV_AGENT_PORT");
v31 = v30;
if ( !v30 )
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_ca.c", 186LL);
fwrite("Environment variable WFA_ENV_AGENT_PORT not set or specify DUT IP/PORT\n", 1uLL, 0x47uLL, stderr);
exit(1);
}
if ( (unsigned int)isNumber(v30) != 1 )
{
v41 = atoi(v31);
LABEL_11:
v40 = wfaCreateTCPServSock(v3);
memset(&readfds, 0, sizeof(readfds));
v38 = (unsigned int *)_errno_location();
if ( gSock == -1 )
{
v32 = socket(2, 1, 6);
v33 = 203LL;
gSock = v32;
if ( v32 < 0 )
{
LABEL_87:
fprintf(stderr, "File %s, Line %ld: ", "wfa_ca.c", v33);
fprintf(stderr, "socket() failed: %i", *v38);
goto LABEL_88;
}
v44 = 0LL;
v44.sa_family = 2;
*(_DWORD *)&v44.sa_data[2] = inet_addr(cp);
*(_WORD *)v44.sa_data = _bswap_16(v41);
v35 = connect(gSock, &v44, v34);
v36 = 214LL;
if ( v35 < 0 )
goto LABEL_85;
}
v6 = v40 / 64;
v37 = 1LL << (v40 % 64);
while ( 1 )
{
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[v6] |= v37;
v7 = v40 + 1;
v8 = gCaSockfd;
if ( gCaSockfd != -1 )
{
v9 = gCaSockfd + 63;
v7 = gCaSockfd + 1;
if ( gCaSockfd >= 0 )
v9 = gCaSockfd;
readfds.fds_bits[v9 >> 6] |= 1LL << (gCaSockfd % 64);
if ( v8 <= v40 + 1 )
v7 = v40 + 1;
}
v10 = gSock;
if ( gSock != -1 )
{
readfds.fds_bits[gSock / 64] |= 1LL << (gSock % 64);
if ( v10 > v7 )
v7 = v10 + 1;
}
if ( select(v7, &readfds, 0LL, 0LL, 0LL) >= 0 )
goto LABEL_22;
v26 = *v38;
if ( (_DWORD)v26 != 4 )
{
v11 = wfa_defined_debug;
if ( (wfa_defined_debug & 4) == 0 )
goto LABEL_23;
fprintf(stdout, "select error %i", v26);
LABEL_22:
v11 = wfa_defined_debug;
LABEL_23:
if ( (v11 & 2) != 0 )
{
fwrite("new event \n", 1uLL, 0xBuLL, stdout);
v12 = readfds.fds_bits[v6] & v37;
if ( !v12 )
goto LABEL_25;
LABEL_61:
gCaSockfd = wfaAcceptTCPConn((unsigned int)v40);
if ( (wfa_defined_debug & 2) != 0 )
fwrite("accept new connection\n", 1uLL, 0x16uLL, stdout);
}
else
{
v12 = readfds.fds_bits[v6] & v37;
if ( v12 )
goto LABEL_61;
LABEL_25:
v13 = gCaSockfd;
if ( gCaSockfd <= 0 || (readfds.fds_bits[gCaSockfd >> 6] & (1LL << gCaSockfd)) == 0 )
goto LABEL_48;
memset64(v50, v12, 0x200uLL);
gRespStr[0] = 0LL;
gRespStr[63] = 0LL;
memset64(
(void *)(((_DWORD)gRespStr + 8) & 0xFFFFFFF8),
v12,
((unsigned int)gRespStr - (((_DWORD)gRespStr + 8) & 0xFFFFFFF8) + 512) >> 3);
v14 = wfaCtrlRecv(v13, v50);
if ( v14 <= 0 )
{
shutdown(gCaSockfd, 1);
close(gCaSockfd);
gCaSockfd = -1;
}
else
{
memset64(&s[16], v12, 0xEuLL);
*(__m128i *)s = _mm_load_si128((const __m128i *)&LC29);
v15 = strlen(s);
wfaCtrlSend((unsigned int)gCaSockfd, s, v15);
if ( (wfa_defined_debug & 2) != 0 && (fprintf(stdout, "%s\n", s), (wfa_defined_debug & 2) != 0) )
{
fprintf(stdout, "message %s %i\n", v50, (unsigned int)v14);
v28 = strlen(v50);
v16 = v28 - 3;
if ( (wfa_defined_debug & 2) != 0 )
fprintf(
stdout,
"last %x last-1 %x last-2 %x last-3 %x\n",
(unsigned int)s2[v28],
(unsigned int)s2[v28 - 1],
(unsigned int)s2[v28 - 2],
(unsigned int)s2[v16]);
}
else
{
v16 = (int)(strlen(v50) - 3);
}
v50[v16] = 0;
if ( gSock == -1 )
{
gSock = socket(2, 1, 6);
if ( gSock < 0 )
{
v33 = 290LL;
goto LABEL_87;
}
v44 = 0LL;
v44.sa_family = 2;
*(_DWORD *)&v44.sa_data[2] = inet_addr(cp);
*(_WORD *)v44.sa_data = _bswap_16(v41);
if ( connect(gSock, &v44, v17) < 0 )
{
v36 = 301LL;
LABEL_85:
fprintf(stderr, "File %s, Line %ld: ", "wfa_ca.c", v36);
fprintf(stderr, "connect() failed: %i", *v38);
LABEL_88:
exit(1);
}
}
v18 = (const __m128i *)strtok_r(v50, ",", &save_ptr);
*(__m128i *)s2 = _mm_loadu_si128(v18);
v46 = _mm_loadu_si128(v18 + 1);
if ( *(_DWORD *)&nameStr == -1 )
{
LABEL_63:
if ( (wfa_defined_debug & 2) != 0 )
fprintf(stdout, "%s\n", s2);
sleep(1u);
s[16] = 0;
*(__m128i *)s = _mm_load_si128((const __m128i *)&LC30);
v27 = strlen(s);
wfaCtrlSend((unsigned int)gCaSockfd, s, v27);
if ( (wfa_defined_debug & 4) != 0 )
fwrite("Command not valid, check the name\n", 1uLL, 0x22uLL, stdout);
}
else
{
v19 = (unsigned int)((_DWORD)&nameStr + 4);
v20 = 0;
while ( strcmp((const char *)v19, s2) )
{
v19 += 48LL;
++v20;
if ( *(_DWORD *)(v19 - 4) == -1 )
goto LABEL_63;
}
if ( (wfa_defined_debug & 2) != 0 )
fprintf(stdout, "%s\n", s2);
memset(buf, 0, sizeof(buf));
if ( (*((unsigned int (__fastcall **)(char *, char *, int *))&nameStr + 6 * v20 + 5))(
save_ptr,
buf,
&v42) == 1 )
{
sleep(1u);
s[16] = 0;
*(__m128i *)s = _mm_load_si128((const __m128i *)&LC30);
v29 = strlen(s);
wfaCtrlSend((unsigned int)gCaSockfd, s, v29);
if ( (wfa_defined_debug & 4) != 0 )
fwrite("Incorrect command syntax\n", 1uLL, 0x19uLL, stdout);
}
else
{
v21 = send(gSock, buf, v42, 0);
if ( v21 == v42 )
{
if ( (wfa_defined_debug & 2) != 0 )
fwrite("sent to DUT\n", 1uLL, 0xCuLL, stdout);
LABEL_48:
if ( gSock > 0 && (readfds.fds_bits[gSock >> 6] & (1LL << gSock)) != 0 )
{
if ( (wfa_defined_debug & 2) != 0 )
fwrite("received from DUT\n", 1uLL, 0x12uLL, stdout);
sleep(1u);
memset(s, 0, 0x80uLL);
memset(v51, 0, 0x1000uLL);
v23 = recv(gSock, v51, 0x1000uLL, 0);
if ( v23 <= 0 )
{
if ( (wfa_defined_debug & 4) != 0 )
fwrite("recv() failed or connection closed prematurely", 1uLL, 0x2EuLL, stdout);
}
else
{
v24 = (unsigned __int16)v51[0];
if ( (wfa_defined_debug & 2) != 0 )
{
fprintf(
stdout,
"bytes=%i, %i,%i,%x %x %x %x \n",
(unsigned int)v23,
(unsigned __int16)v51[0],
(unsigned __int16)v51[1],
LOBYTE(v51[2]),
HIBYTE(v51[2]),
LOBYTE(v51[3]),
HIBYTE(v51[3]));
if ( (wfa_defined_debug & 2) != 0 )
fprintf(stdout, "tag %i \n", (unsigned int)v24);
}
if ( (_DWORD)v24
&& (v25 = (void (__fastcall *)(__int16 *))*(&wfaCmdRespProcFuncTbl + v24)) != 0LL )
{
v25(v51);
}
else if ( (wfa_defined_debug & 4) != 0 )
{
fwrite("function not defined\n", 1uLL, 0x15uLL, stdout);
}
}
}
}
else if ( (wfa_defined_debug & 4) != 0 )
{
fwrite("Incorrect sending ...\n", 1uLL, 0x16uLL, stdout);
}
}
}
}
}
}
}
}
}
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int16 v3; // r12
FILE *v4; // rdi
int v5; // er13
__int64 v6; // rbx
int v7; // edi
int v8; // eax
int v9; // edx
int v10; // eax
char v11; // al
unsigned __int64 v12; // r13
unsigned int v13; // er8
int v14; // er15
size_t v15; // rax
__int64 v16; // r13
socklen_t v17; // edx
const __m128i *v18; // rax
unsigned __int64 v19; // r13
int v20; // er15
ssize_t v21; // rax
int v23; // eax
__int64 v24; // r15
void (__fastcall *v25)(__int16 *); // rax
__int64 v26; // rdx
size_t v27; // rax
int v28; // eax
size_t v29; // rax
char *v30; // rax
const char *v31; // rbp
int v32; // eax
__int64 v33; // rcx
socklen_t v34; // edx
int v35; // eax
__int64 v36; // rcx
__int64 v37; // [rsp+0h] [rbp-2718h]
unsigned int *v38; // [rsp+8h] [rbp-2710h]
const char *cp; // [rsp+10h] [rbp-2708h]
signed int v40; // [rsp+18h] [rbp-2700h]
__int16 v41; // [rsp+1Eh] [rbp-26FAh]
int v42; // [rsp+24h] [rbp-26F4h] BYREF
char *save_ptr; // [rsp+28h] [rbp-26F0h] BYREF
struct sockaddr v44; // [rsp+30h] [rbp-26E8h] BYREF
char s2[16]; // [rsp+40h] [rbp-26D8h] BYREF
__m128i v46; // [rsp+50h] [rbp-26C8h]
fd_set readfds; // [rsp+60h] [rbp-26B8h] BYREF
char s[512]; // [rsp+E0h] [rbp-2638h] BYREF
char buf[1024]; // [rsp+2E0h] [rbp-2438h] BYREF
char v50[4096]; // [rsp+6E0h] [rbp-2038h] BYREF
__int16 v51[2076]; // [rsp+16E0h] [rbp-1038h] BYREF

v42 = 1024;
save_ptr = 0LL;
if ( argc <= 2 )
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_ca.c", 136LL);
fprintf(stderr, "Usage: %s <control interface> <local control agent port>\n", *argv);
goto LABEL_91;
}
v3 = atoi(argv[2]);
if ( argc != 3 )
{
if ( argc != 4 )
{
cp = argv[3];
if ( (unsigned int)isIpV4Addr(cp) != 1 && (unsigned int)isNumber(argv[4]) != 1 )
{
v41 = atoi(argv[4]);
if ( argc != 5 )
{
v4 = fopen(argv[5], "a");
if ( v4 )
{
v5 = fileno(v4);
if ( (wfa_defined_debug & 2) != 0 )
fprintf(stdout, "redirecting the output to %s\n", argv[5]);
dup2(v5, 1);
dup2(v5, 2);
}
else
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_ca.c", 170LL);
fwrite("Cant open the log file continuing without redirecting\n", 1uLL, 0x36uLL, stderr);
}
}
goto LABEL_11;
}
return 1;
}
fprintf(stderr, "File %s, Line %ld: ", "wfa_ca.c", 147LL);
fprintf(stderr, "Usage: %s <control interface> <local control agent port> <DUT IP ADDRESS> <DUT PORT>\n", *argv);
LABEL_91:
exit(1);
}
cp = getenv("WFA_ENV_AGENT_IPADDR");
if ( !cp )
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_ca.c", 178LL);
fwrite("Environment variable WFA_ENV_AGENT_IPADDR not set or specify DUT IP/PORT\n", 1uLL, 0x49uLL, stderr);
exit(1);
}
if ( (unsigned int)isIpV4Addr(cp) != 1 )
{
v30 = getenv("WFA_ENV_AGENT_PORT");
v31 = v30;
if ( !v30 )
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_ca.c", 186LL);
fwrite("Environment variable WFA_ENV_AGENT_PORT not set or specify DUT IP/PORT\n", 1uLL, 0x47uLL, stderr);
exit(1);
}
if ( (unsigned int)isNumber(v30) != 1 )
{
v41 = atoi(v31);
LABEL_11:
v40 = wfaCreateTCPServSock(v3);
memset(&readfds, 0, sizeof(readfds));
v38 = (unsigned int *)_errno_location();
if ( gSock == -1 )
{
v32 = socket(2, 1, 6);
v33 = 203LL;
gSock = v32;
if ( v32 < 0 )
{
LABEL_87:
fprintf(stderr, "File %s, Line %ld: ", "wfa_ca.c", v33);
fprintf(stderr, "socket() failed: %i", *v38);
goto LABEL_88;
}
v44 = 0LL;
v44.sa_family = 2;
*(_DWORD *)&v44.sa_data[2] = inet_addr(cp);
*(_WORD *)v44.sa_data = func0(v41);
v35 = connect(gSock, &v44, v34);
v36 = 214LL;
if ( v35 < 0 )
goto LABEL_85;
}
v6 = v40 / 64;
v37 = 1LL << (v40 % 64);
while ( 1 )
{
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[v6] |= v37;
v7 = v40 + 1;
v8 = gCaSockfd;
if ( gCaSockfd != -1 )
{
v9 = gCaSockfd + 63;
v7 = gCaSockfd + 1;
if ( gCaSockfd >= 0 )
v9 = gCaSockfd;
readfds.fds_bits[v9 >> 6] |= 1LL << (gCaSockfd % 64);
if ( v8 <= v40 + 1 )
v7 = v40 + 1;
}
v10 = gSock;
if ( gSock != -1 )
{
readfds.fds_bits[gSock / 64] |= 1LL << (gSock % 64);
if ( v10 > v7 )
v7 = v10 + 1;
}
if ( select(v7, &readfds, 0LL, 0LL, 0LL) >= 0 )
goto LABEL_22;
v26 = *v38;
if ( (_DWORD)v26 != 4 )
{
v11 = wfa_defined_debug;
if ( (wfa_defined_debug & 4) == 0 )
goto LABEL_23;
fprintf(stdout, "select error %i", v26);
LABEL_22:
v11 = wfa_defined_debug;
LABEL_23:
if ( (v11 & 2) != 0 )
{
fwrite("new event \n", 1uLL, 0xBuLL, stdout);
v12 = readfds.fds_bits[v6] & v37;
if ( !v12 )
goto LABEL_25;
LABEL_61:
gCaSockfd = wfaAcceptTCPConn((unsigned int)v40);
if ( (wfa_defined_debug & 2) != 0 )
fwrite("accept new connection\n", 1uLL, 0x16uLL, stdout);
}
else
{
v12 = readfds.fds_bits[v6] & v37;
if ( v12 )
goto LABEL_61;
LABEL_25:
v13 = gCaSockfd;
if ( gCaSockfd <= 0 || (readfds.fds_bits[gCaSockfd >> 6] & (1LL << gCaSockfd)) == 0 )
goto LABEL_48;
memset64(v50, v12, 0x200uLL);
gRespStr[0] = 0LL;
gRespStr[63] = 0LL;
memset64(
(void *)(((_DWORD)gRespStr + 8) & 0xFFFFFFF8),
v12,
((unsigned int)gRespStr - (((_DWORD)gRespStr + 8) & 0xFFFFFFF8) + 512) >> 3);
v14 = wfaCtrlRecv(v13, v50);
if ( v14 <= 0 )
{
shutdown(gCaSockfd, 1);
close(gCaSockfd);
gCaSockfd = -1;
}
else
{
memset64(&s[16], v12, 0xEuLL);
*(__m128i *)s = _mm_load_si128((const __m128i *)&LC29);
v15 = strlen(s);
wfaCtrlSend((unsigned int)gCaSockfd, s, v15);
if ( (wfa_defined_debug & 2) != 0 && (fprintf(stdout, "%s\n", s), (wfa_defined_debug & 2) != 0) )
{
fprintf(stdout, "message %s %i\n", v50, (unsigned int)v14);
v28 = strlen(v50);
v16 = v28 - 3;
if ( (wfa_defined_debug & 2) != 0 )
fprintf(
stdout,
"last %x last-1 %x last-2 %x last-3 %x\n",
(unsigned int)s2[v28],
(unsigned int)s2[v28 - 1],
(unsigned int)s2[v28 - 2],
(unsigned int)s2[v16]);
}
else
{
v16 = (int)(strlen(v50) - 3);
}
v50[v16] = 0;
if ( gSock == -1 )
{
gSock = socket(2, 1, 6);
if ( gSock < 0 )
{
v33 = 290LL;
goto LABEL_87;
}
v44 = 0LL;
v44.sa_family = 2;
*(_DWORD *)&v44.sa_data[2] = inet_addr(cp);
*(_WORD *)v44.sa_data = func0(v41);
if ( connect(gSock, &v44, v17) < 0 )
{
v36 = 301LL;
LABEL_85:
fprintf(stderr, "File %s, Line %ld: ", "wfa_ca.c", v36);
fprintf(stderr, "connect() failed: %i", *v38);
LABEL_88:
exit(1);
}
}
v18 = (const __m128i *)strtok_r(v50, ",", &save_ptr);
*(__m128i *)s2 = _mm_loadu_si128(v18);
v46 = _mm_loadu_si128(v18 + 1);
if ( *(_DWORD *)&nameStr == -1 )
{
LABEL_63:
if ( (wfa_defined_debug & 2) != 0 )
fprintf(stdout, "%s\n", s2);
sleep(1u);
s[16] = 0;
*(__m128i *)s = _mm_load_si128((const __m128i *)&LC30);
v27 = strlen(s);
wfaCtrlSend((unsigned int)gCaSockfd, s, v27);
if ( (wfa_defined_debug & 4) != 0 )
fwrite("Command not valid, check the name\n", 1uLL, 0x22uLL, stdout);
}
else
{
v19 = (unsigned int)((_DWORD)&nameStr + 4);
v20 = 0;
while ( strcmp((const char *)v19, s2) )
{
v19 += 48LL;
++v20;
if ( *(_DWORD *)(v19 - 4) == -1 )
goto LABEL_63;
}
if ( (wfa_defined_debug & 2) != 0 )
fprintf(stdout, "%s\n", s2);
memset(buf, 0, sizeof(buf));
if ( (*((unsigned int (__fastcall **)(char *, char *, int *))&nameStr + 6 * v20 + 5))(
save_ptr,
buf,
&v42) == 1 )
{
sleep(1u);
s[16] = 0;
*(__m128i *)s = _mm_load_si128((const __m128i *)&LC30);
v29 = strlen(s);
wfaCtrlSend((unsigned int)gCaSockfd, s, v29);
if ( (wfa_defined_debug & 4) != 0 )
fwrite("Incorrect command syntax\n", 1uLL, 0x19uLL, stdout);
}
else
{
v21 = send(gSock, buf, v42, 0);
if ( v21 == v42 )
{
if ( (wfa_defined_debug & 2) != 0 )
fwrite("sent to DUT\n", 1uLL, 0xCuLL, stdout);
LABEL_48:
if ( gSock > 0 && (readfds.fds_bits[gSock >> 6] & (1LL << gSock)) != 0 )
{
if ( (wfa_defined_debug & 2) != 0 )
fwrite("received from DUT\n", 1uLL, 0x12uLL, stdout);
sleep(1u);
memset(s, 0, 0x80uLL);
memset(v51, 0, 0x1000uLL);
v23 = recv(gSock, v51, 0x1000uLL, 0);
if ( v23 <= 0 )
{
if ( (wfa_defined_debug & 4) != 0 )
fwrite("recv() failed or connection closed prematurely", 1uLL, 0x2EuLL, stdout);
}
else
{
v24 = (unsigned __int16)v51[0];
if ( (wfa_defined_debug & 2) != 0 )
{
fprintf(
stdout,
"bytes=%i, %i,%i,%x %x %x %x \n",
(unsigned int)v23,
(unsigned __int16)v51[0],
(unsigned __int16)v51[1],
LOBYTE(v51[2]),
HIBYTE(v51[2]),
LOBYTE(v51[3]),
HIBYTE(v51[3]));
if ( (wfa_defined_debug & 2) != 0 )
fprintf(stdout, "tag %i \n", (unsigned int)v24);
}
if ( (_DWORD)v24
&& (v25 = (void (__fastcall *)(__int16 *))*(&wfaCmdRespProcFuncTbl + v24)) != 0LL )
{
v25(v51);
}
else if ( (wfa_defined_debug & 4) != 0 )
{
fwrite("function not defined\n", 1uLL, 0x15uLL, stdout);
}
}
}
}
else if ( (wfa_defined_debug & 4) != 0 )
{
fwrite("Incorrect sending ...\n", 1uLL, 0x16uLL, stdout);
}
}
}
}
}
}
}
}
}
return 1;
}

original_code:
int
main(int argc, char **argv)
{
    int nfds, maxfdn1 = -1, nbytes = 0, cmdLen = 0, isExit = 1;
    int respLen;
    WORD locPortNo = 0;
    fd_set sockSet;
    BYTE *xcCmdBuf=((void *)0), *parmsVal=((void *)0);
    struct timeval *toutvalp=((void *)0), *tovalp;
    WORD xcCmdTag;
    struct sockfds fds;
    tgThrData_t tdata[8];
    int i = 0;
    pthread_attr_t ptAttr;
    int ptPolicy;
    struct sched_param ptSchedParam;
    if (argc < 3)
    {
        fprintf(stderr, "File %s, Line %ld: ", "wfa_dut.c", (long)163); fprintf(stderr, "Usage:  %s <command interface> <Local Control Port> \n", argv[0]);
        exit(1);
    }
    if(isString(argv[1]) == WFA_FAILURE)
    {
        fprintf(stderr, "File %s, Line %ld: ", "wfa_dut.c", (long)189); fprintf(stderr, "incorrect network interface\n");
        exit(1);
    }
    strncpy(gnetIf, argv[1], 31);
    if(isNumber(argv[2]) == WFA_FAILURE)
    {
        fprintf(stderr, "File %s, Line %ld: ", "wfa_dut.c", (long)197); fprintf(stderr, "incorrect port number\n");
        exit(1);
    }
    locPortNo = atoi(argv[2]);
    adj_latency = wfa_estimate_timer_latency() + 4000;
    if(adj_latency > 500000)
    {
        printf("****************** WARNING  **********************\n");
        printf("!!!THE SLEEP TIMER LATENCY IS TOO HIGH!!!!!!!!!!!!\n");
        printf("**************************************************\n");
        adj_latency = 500000;
    }
    wfa_dut_init(&trafficBuf, &respBuf, &parmsVal, &xcCmdBuf, &toutvalp);
    gagtSockfd = wfaCreateTCPServSock(locPortNo);
    if(gagtSockfd == -1)
    {
       fprintf(stderr, "File %s, Line %ld: ", "wfa_dut.c", (long)222); fprintf(stderr, "Failed to open socket\n");
       exit(1);
    }
    pthread_attr_init(&ptAttr);
    ptSchedParam.sched_priority = 10;
    pthread_attr_setschedparam(&ptAttr, &ptSchedParam);
    pthread_attr_getschedpolicy(&ptAttr, &ptPolicy);
    pthread_attr_setschedpolicy(&ptAttr, 2);
    pthread_attr_getschedpolicy(&ptAttr, &ptPolicy);
    for(i = 0; i< 8; i++)
    {
        tdata[i].tid = i;
        pthread_mutex_init(&wmm_thr[i].thr_flag_mutex, ((void *)0));
        pthread_cond_init(&wmm_thr[i].thr_flag_cond, ((void *)0));
        wmm_thr[i].thr_id = pthread_create(&wmm_thr[i].thr,
                       &ptAttr, wfa_wmm_thread, &tdata[i]);
    }
    for(i = 0; i < 8; i++)
       tgSockfds[i] = -1;
    maxfdn1 = gagtSockfd + 1;
    while (isExit)
    {
        fds.agtfd = &gagtSockfd;
        fds.cafd = &gxcSockfd;
        fds.tgfd = &btSockfd;
        fds.wmmfds = tgSockfds;
        fds.psfd = &psSockfd;
        wfaSetSockFiDesc(&sockSet, &maxfdn1, &fds);
        tovalp = ((void *)0);
        if(gtimeOut != 0)
        {
          tovalp = wfaSetTimer(0, gtimeOut*1000, toutvalp);
        }
        nfds = 0;
        if ( (nfds = select(maxfdn1, &sockSet, ((void *)0), ((void *)0), tovalp)) < 0)
        {
            if ((*__errno_location ()) == 4)
                continue;
     else
                if(wfa_defined_debug & 0x0004) fprintf(stdout, "Warning: select()-%i", (*__errno_location ()));
        }
        if(nfds == 0)
        {
            if(gtgWmmPS != 0 && psSockfd != -1)
            {
                wfaSetDUTPwrMgmt(0);
                wfaTGSetPrio(psSockfd, 0);
                BUILD_APTS_MSG(((37 + 0x01) + 0x01), psTxMsg);
                wfaTrafficSendTo(psSockfd, (char *)psTxMsg, sizeof(psTxMsg), (struct sockaddr *) &wmmps_info.psToAddr);
                wmmps_info.sta_state = 0;
                wmmps_info.wait_state = WFA_WAIT_STAUT_00;
                continue;
            }
        }
        if (((((&sockSet)->__fds_bits)[((gagtSockfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((gagtSockfd) % (8 * (int) sizeof (__fd_mask)))))) != 0))
        {
            gxcSockfd = wfaAcceptTCPConn(gagtSockfd);
            if(gxcSockfd == -1)
            {
               fprintf(stderr, "File %s, Line %ld: ", "wfa_dut.c", (long)309); fprintf(stderr, "Failed to open control link socket\n");
               exit(1);
            }
        }
        if(gxcSockfd >= 0 && ((((&sockSet)->__fds_bits)[((gxcSockfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((gxcSockfd) % (8 * (int) sizeof (__fd_mask)))))) != 0))
        {
            memset(xcCmdBuf, 0, 1024);
            nbytes = wfaCtrlRecv(gxcSockfd, xcCmdBuf);
            if(nbytes <=0)
            {
                shutdown(gxcSockfd, SHUT_WR);
                close(gxcSockfd);
                gxcSockfd = -1;
            }
            else
            {
               wfaDecodeTLV(xcCmdBuf, nbytes, &xcCmdTag, &cmdLen, parmsVal);
               memset(respBuf, 0, 1024);
               respLen = 0;
               memset(gCmdStr, 0, 512);
               memset(&gGenericResp, 0, sizeof(dutCmdResponse_t));
               if(xcCmdTag != 0 && gWfaCmdFuncTbl[xcCmdTag] != ((void *)0))
               {
     gWfaCmdFuncTbl[xcCmdTag](cmdLen, parmsVal, &respLen, (BYTE *)respBuf);
               }
               else
               {
     gWfaCmdFuncTbl[0](cmdLen, parmsVal, &respLen, (BYTE *)respBuf);
               }
               if(gxcSockfd != -1)
               if(wfaCtrlSend(gxcSockfd, (BYTE *)respBuf, respLen) != respLen)
               {
                   if(wfa_defined_debug & 0x0004) fprintf(stdout, "wfa-wfaCtrlSend Error\n");
               }
            }
        }
        if(psSockfd != -1 && ((((&sockSet)->__fds_bits)[((psSockfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((psSockfd) % (8 * (int) sizeof (__fd_mask)))))) != 0))
        {
            wfaWmmPowerSaveProcess(psSockfd);
            continue;
        }
    }
    free(trafficBuf);;
    free(toutvalp);;
    free(respBuf);;
    free(xcCmdBuf);;
    free(parmsVal);;
    close(gagtSockfd);;
    close(gxcSockfd);;
    close(btSockfd);;
    for(i= 0; i< 8; i++)
    {
       if(tgSockfds[i] != -1)
       {
         close(tgSockfds[i]);;
         tgSockfds[i] = -1;
       }
    }
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    int nfds; int maxfdn1 = -1; int nbytes = 0; int cmdLen = 0; int isExit = 1;
    int respLen;
    unsigned short locPortNo = 0;
    struct fd_set sockSet;
    unsigned char *xcCmdBuf = ((void *)0); unsigned char *parmsVal = ((void *)0);
    struct timeval *toutvalp = ((void *)0); struct timeval *tovalp;
    unsigned short xcCmdTag;
    struct sockfds fds;
    struct _tg_thr_data tdata[8];
    int i = 0;
    union pthread_attr_t ptAttr;
    int ptPolicy;
    struct sched_param ptSchedParam;
    if (argc < 3)
    {
        fprintf(stderr, "File %s, Line %ld: ", "wfa_dut.c", (long)163); fprintf(stderr, "Usage:  %s <command interface> <Local Control Port> \n", argv[0]);
        exit(1);
    }
    if(isString(argv[1]) == WFA_FAILURE)
    {
        fprintf(stderr, "File %s, Line %ld: ", "wfa_dut.c", (long)189); fprintf(stderr, "incorrect network interface\n");
        exit(1);
    }
    strncpy(gnetIf, argv[1], 31);
    if(isNumber(argv[2]) == WFA_FAILURE)
    {
        fprintf(stderr, "File %s, Line %ld: ", "wfa_dut.c", (long)197); fprintf(stderr, "incorrect port number\n");
        exit(1);
    }
    locPortNo = atoi(argv[2]);
    adj_latency = wfa_estimate_timer_latency() + 4000;
    if(adj_latency > 500000)
    {
        printf("****************** WARNING  **********************\n");
        printf("!!!THE SLEEP TIMER LATENCY IS TOO HIGH!!!!!!!!!!!!\n");
        printf("**************************************************\n");
        adj_latency = 500000;
    }
    wfa_dut_init(&trafficBuf, &respBuf, &parmsVal, &xcCmdBuf, &toutvalp);
    gagtSockfd = wfaCreateTCPServSock(locPortNo);
    if(gagtSockfd == -1)
    {
       fprintf(stderr, "File %s, Line %ld: ", "wfa_dut.c", (long)222); fprintf(stderr, "Failed to open socket\n");
       exit(1);
    }
    pthread_attr_init(&ptAttr);
    ptSchedParam.sched_priority = 10;
    pthread_attr_setschedparam(&ptAttr, &ptSchedParam);
    pthread_attr_getschedpolicy(&ptAttr, &ptPolicy);
    pthread_attr_setschedpolicy(&ptAttr, 2);
    pthread_attr_getschedpolicy(&ptAttr, &ptPolicy);
    for(i = 0; i< 8; i++)
    {
        tdata[i].tid = i;
        pthread_mutex_init(&wmm_thr[i].thr_flag_mutex, ((void *)0));
        pthread_cond_init(&wmm_thr[i].thr_flag_cond, ((void *)0));
        wmm_thr[i].thr_id = pthread_create(&wmm_thr[i].thr,
                       &ptAttr, wfa_wmm_thread, &tdata[i]);
    }
    for(i = 0; i < 8; i++)
       tgSockfds[i] = -1;
    maxfdn1 = gagtSockfd + 1;
    while (isExit)
    {
        fds.agtfd = &gagtSockfd;
        fds.cafd = &gxcSockfd;
        fds.tgfd = &btSockfd;
        fds.wmmfds = tgSockfds;
        fds.psfd = &psSockfd;
        wfaSetSockFiDesc(&sockSet, &maxfdn1, &fds);
        tovalp = ((void *)0);
        if(gtimeOut != 0)
        {
          tovalp = wfaSetTimer(0, gtimeOut*1000, toutvalp);
        }
        nfds = 0;
        if ( (nfds = select(maxfdn1, &sockSet, ((void *)0), ((void *)0), tovalp)) < 0)
        {
            if ((*__errno_location ()) == 4)
                continue;
     else
                if(wfa_defined_debug & 0x0004) fprintf(stdout, "Warning: select()-%i", (*__errno_location ()));
        }
        if(nfds == 0)
        {
            if(gtgWmmPS != 0 && psSockfd != -1)
            {
                wfaSetDUTPwrMgmt(0);
                wfaTGSetPrio(psSockfd, 0);
                BUILD_APTS_MSG(((37 + 0x01) + 0x01), psTxMsg);
                wfaTrafficSendTo(psSockfd, (char *)psTxMsg, sizeof(psTxMsg), (struct sockaddr *) &wmmps_info.psToAddr);
                wmmps_info.sta_state = 0;
                wmmps_info.wait_state = WFA_WAIT_STAUT_00;
                continue;
            }
        }
        if (((((&sockSet)->__fds_bits)[((gagtSockfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((gagtSockfd) % (8 * (int) sizeof (__fd_mask)))))) != 0))
        {
            gxcSockfd = wfaAcceptTCPConn(gagtSockfd);
            if(gxcSockfd == -1)
            {
               fprintf(stderr, "File %s, Line %ld: ", "wfa_dut.c", (long)309); fprintf(stderr, "Failed to open control link socket\n");
               exit(1);
            }
        }
        if(gxcSockfd >= 0 && ((((&sockSet)->__fds_bits)[((gxcSockfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((gxcSockfd) % (8 * (int) sizeof (__fd_mask)))))) != 0))
        {
            memset(xcCmdBuf, 0, 1024);
            nbytes = wfaCtrlRecv(gxcSockfd, xcCmdBuf);
            if(nbytes <=0)
            {
                shutdown(gxcSockfd, SHUT_WR);
                close(gxcSockfd);
                gxcSockfd = -1;
            }
            else
            {
               wfaDecodeTLV(xcCmdBuf, nbytes, &xcCmdTag, &cmdLen, parmsVal);
               memset(respBuf, 0, 1024);
               respLen = 0;
               memset(gCmdStr, 0, 512);
               memset(&gGenericResp, 0, sizeof(dutCmdResponse_t));
               if(xcCmdTag != 0 && gWfaCmdFuncTbl[xcCmdTag] != ((void *)0))
               {
     gWfaCmdFuncTbl[xcCmdTag](cmdLen, parmsVal, &respLen, (unsigned char *)respBuf);
               }
               else
               {
     gWfaCmdFuncTbl[0](cmdLen, parmsVal, &respLen, (unsigned char *)respBuf);
               }
               if(gxcSockfd != -1)
               if(wfaCtrlSend(gxcSockfd, (unsigned char *)respBuf, respLen) != respLen)
               {
                   if(wfa_defined_debug & 0x0004) fprintf(stdout, "wfa-wfaCtrlSend Error\n");
               }
            }
        }
        if(psSockfd != -1 && ((((&sockSet)->__fds_bits)[((psSockfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((psSockfd) % (8 * (int) sizeof (__fd_mask)))))) != 0))
        {
            wfaWmmPowerSaveProcess(psSockfd);
            continue;
        }
    }
    free(trafficBuf);;
    free(toutvalp);;
    free(respBuf);;
    free(xcCmdBuf);;
    free(parmsVal);;
    close(gagtSockfd);;
    close(gxcSockfd);;
    close(btSockfd);;
    for(i= 0; i< 8; i++)
    {
       if(tgSockfds[i] != -1)
       {
         close(tgSockfds[i]);;
         tgSockfds[i] = -1;
       }
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: nfds int

variable_types: nbytes int

variable_types: cmdLen int

variable_types: isExit int

variable_types: respLen int

variable_types:
locPortNo
unsigned short

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

variable_types:
xcCmdBuf
unsigned char *

variable_types:
parmsVal
unsigned char *

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

variable_types:
xcCmdTag
unsigned short

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

variable_types: struct _tg_thr_data { int tid; struct station_state_table { int (*statefunc)(char, int, int *); char pw_offon; int sleep_period; } *state; int state_num; } [8]

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

variable_types: ptPolicy int

variable_types: struct sched_param { int sched_priority; }

user_defined_types: struct _tg_thr_data { int tid; struct station_state_table *state; int state_num; }


decompiled_code:
int init_thr_flag()
{
pthread_mutex_t *v0; // rbx
pthread_cond_t *v1; // rbp
pthread_mutex_t *v2; // rdi
int result; // eax

v0 = (pthread_mutex_t *)(unsigned int)((_DWORD)&wmm_thr + 120);
do
{
v1 = (pthread_cond_t *)(&v0[-3].__align + 3);
pthread_mutex_init(v0, 0LL);
pthread_cond_init((pthread_cond_t *)(&v0[-3].__align + 3), 0LL);
v2 = v0;
v0 += 5;
pthread_mutex_init(v2, 0LL);
result = pthread_cond_init(v1, 0LL);
v0[-8].__lock = 0;
v0[-8].__count = 0;
}
while ( (pthread_mutex_t *)(unsigned int)((_DWORD)&wmm_thr + 1720) != v0 );
return result;
}

canonical_decompiled_code:
int func0()
{
pthread_mutex_t *v0; // rbx
pthread_cond_t *v1; // rbp
pthread_mutex_t *v2; // rdi
int result; // eax

v0 = (pthread_mutex_t *)(unsigned int)((_DWORD)&wmm_thr + 120);
do
{
v1 = (pthread_cond_t *)(&v0[-3].__align + 3);
pthread_mutex_init(v0, 0LL);
pthread_cond_init((pthread_cond_t *)(&v0[-3].__align + 3), 0LL);
v2 = v0;
v0 += 5;
pthread_mutex_init(v2, 0LL);
result = pthread_cond_init(v1, 0LL);
v0[-8].__lock = 0;
v0[-8].__count = 0;
}
while ( (pthread_mutex_t *)(unsigned int)((_DWORD)&wmm_thr + 1720) != v0 );
return result;
}

original_code:
void init_thr_flag()
{
    int i = 0;
    for(i=0; i< 8; i++)
    {
        pthread_mutex_init(&wmm_thr[i].thr_flag_mutex, ((void *)0));
        pthread_cond_init(&wmm_thr[i].thr_flag_cond, ((void *)0));
 pthread_mutex_init(&wmm_thr[i].thr_flag_mutex, ((void *)0));
        pthread_cond_init(&wmm_thr[i].thr_flag_cond, ((void *)0));
        wmm_thr[i].thr_flag = 0;
        wmm_thr[i].stop_flag = 0;
    }
}

variable_types: i int


decompiled_code:
void *__fastcall wfa_dut_init(_QWORD *a1, _QWORD *a2, _QWORD *a3, _QWORD *a4, _QWORD *a5)
{
void *v8; // rax
void *v9; // rax
void *v10; // rax
void *v11; // rax
void *result; // rax

gStreams = malloc(0x480uLL);
if ( !gStreams )
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_dut_init.c", 98LL);
fwrite("Failed to malloc theStreams\n", 1uLL, 0x1CuLL, stderr);
exit(1);
}
v8 = malloc(0x801uLL);
*a1 = v8;
if ( !v8 )
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_dut_init.c", 106LL);
fwrite("Failed to malloc traffic buffer\n", 1uLL, 0x20uLL, stderr);
exit(1);
}
v9 = malloc(0x400uLL);
*a2 = v9;
if ( !v9 )
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_dut_init.c", 114LL);
fwrite("Failed to malloc response buffer\n", 1uLL, 0x21uLL, stderr);
exit(1);
}
v10 = malloc(0x10uLL);
*a5 = v10;
if ( !v10 )
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_dut_init.c", 122LL);
fwrite("Failed to malloc timer val\n", 1uLL, 0x1BuLL, stderr);
exit(1);
}
v11 = malloc(0x400uLL);
*a4 = v11;
if ( !v11 )
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_dut_init.c", 130LL);
fwrite("Failed to malloc control command buf\n", 1uLL, 0x25uLL, stderr);
exit(1);
}
result = malloc(0x280uLL);
*a3 = result;
if ( !result )
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_dut_init.c", 138LL);
fwrite("Failed to malloc parms value buff\n", 1uLL, 0x22uLL, stderr);
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(_QWORD *a1, _QWORD *a2, _QWORD *a3, _QWORD *a4, _QWORD *a5)
{
void *v8; // rax
void *v9; // rax
void *v10; // rax
void *v11; // rax
void *result; // rax

gStreams = malloc(0x480uLL);
if ( !gStreams )
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_dut_init.c", 98LL);
fwrite("Failed to malloc theStreams\n", 1uLL, 0x1CuLL, stderr);
exit(1);
}
v8 = malloc(0x801uLL);
*a1 = v8;
if ( !v8 )
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_dut_init.c", 106LL);
fwrite("Failed to malloc traffic buffer\n", 1uLL, 0x20uLL, stderr);
exit(1);
}
v9 = malloc(0x400uLL);
*a2 = v9;
if ( !v9 )
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_dut_init.c", 114LL);
fwrite("Failed to malloc response buffer\n", 1uLL, 0x21uLL, stderr);
exit(1);
}
v10 = malloc(0x10uLL);
*a5 = v10;
if ( !v10 )
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_dut_init.c", 122LL);
fwrite("Failed to malloc timer val\n", 1uLL, 0x1BuLL, stderr);
exit(1);
}
v11 = malloc(0x400uLL);
*a4 = v11;
if ( !v11 )
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_dut_init.c", 130LL);
fwrite("Failed to malloc control command buf\n", 1uLL, 0x25uLL, stderr);
exit(1);
}
result = malloc(0x280uLL);
*a3 = result;
if ( !result )
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_dut_init.c", 138LL);
fwrite("Failed to malloc parms value buff\n", 1uLL, 0x22uLL, stderr);
exit(1);
}
return result;
}

original_code:
void wfa_dut_init(BYTE **tBuf, BYTE **rBuf, BYTE **paBuf, BYTE **cBuf, struct timeval **timerp)
{
    gStreams = (tgStream_t *) malloc(8*sizeof(tgStream_t));
    if(gStreams == ((void *)0))
    {
        fprintf(stderr, "File %s, Line %ld: ", "wfa_dut_init.c", (long)98); fprintf(stderr, "Failed to malloc theStreams\n");
        exit(1);
    }
    *tBuf = (BYTE *) malloc(2048 +1);
    if(*tBuf == ((void *)0))
    {
        fprintf(stderr, "File %s, Line %ld: ", "wfa_dut_init.c", (long)106); fprintf(stderr, "Failed to malloc traffic buffer\n");
        exit(1);
    }
    *rBuf = (BYTE *)malloc(1024);
    if(*rBuf == ((void *)0))
    {
        fprintf(stderr, "File %s, Line %ld: ", "wfa_dut_init.c", (long)114); fprintf(stderr, "Failed to malloc response buffer\n");
        exit(1);
    }
    *timerp = malloc(sizeof(struct timeval));
    if(*timerp == ((void *)0))
    {
        fprintf(stderr, "File %s, Line %ld: ", "wfa_dut_init.c", (long)122); fprintf(stderr, "Failed to malloc timer val\n");
        exit(1);
    }
    *cBuf = malloc(1024);
    if(*cBuf == ((void *)0))
    {
        fprintf(stderr, "File %s, Line %ld: ", "wfa_dut_init.c", (long)130); fprintf(stderr, "Failed to malloc control command buf\n");
        exit(1);
    }
    *paBuf = malloc(640);
    if(*paBuf == ((void *)0))
    {
        fprintf(stderr, "File %s, Line %ld: ", "wfa_dut_init.c", (long)138); fprintf(stderr, "Failed to malloc parms value buff\n");
        exit(1);
    }
}

canonical_original_code:
void wfa_dut_init(unsigned char **tBuf, unsigned char **rBuf, unsigned char **paBuf, unsigned char **cBuf, struct timeval **timerp)
{
    gStreams = (struct _tg_stream *) malloc(8*sizeof(tgStream_t));
    if(gStreams == ((void *)0))
    {
        fprintf(stderr, "File %s, Line %ld: ", "wfa_dut_init.c", (long)98); fprintf(stderr, "Failed to malloc theStreams\n");
        exit(1);
    }
    *tBuf = (unsigned char *) malloc(2048 +1);
    if(*tBuf == ((void *)0))
    {
        fprintf(stderr, "File %s, Line %ld: ", "wfa_dut_init.c", (long)106); fprintf(stderr, "Failed to malloc traffic buffer\n");
        exit(1);
    }
    *rBuf = (unsigned char *)malloc(1024);
    if(*rBuf == ((void *)0))
    {
        fprintf(stderr, "File %s, Line %ld: ", "wfa_dut_init.c", (long)114); fprintf(stderr, "Failed to malloc response buffer\n");
        exit(1);
    }
    *timerp = malloc(sizeof(struct timeval));
    if(*timerp == ((void *)0))
    {
        fprintf(stderr, "File %s, Line %ld: ", "wfa_dut_init.c", (long)122); fprintf(stderr, "Failed to malloc timer val\n");
        exit(1);
    }
    *cBuf = malloc(1024);
    if(*cBuf == ((void *)0))
    {
        fprintf(stderr, "File %s, Line %ld: ", "wfa_dut_init.c", (long)130); fprintf(stderr, "Failed to malloc control command buf\n");
        exit(1);
    }
    *paBuf = malloc(640);
    if(*paBuf == ((void *)0))
    {
        fprintf(stderr, "File %s, Line %ld: ", "wfa_dut_init.c", (long)138); fprintf(stderr, "Failed to malloc parms value buff\n");
        exit(1);
    }
}

variable_types:
tBuf
unsigned char **

variable_types:
rBuf
unsigned char **

variable_types:
paBuf
unsigned char **

variable_types:
cBuf
unsigned char **

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

user_defined_types: struct _tg_stream { int id; int sockfd; int tblidx; int lastPktSN; int fmInterval; int rxTimeLast; int state; struct _tg_profile profile; struct _tg_stats stats; }

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

user_defined_types: struct _tg_stats { unsigned int txFrames; unsigned int rxFrames; unsigned long long txPayloadBytes; unsigned long long rxPayloadBytes; unsigned int outOfSequenceFrames; unsigned int lostPkts; unsigned long jitter; }


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((data+4), (BYTE *)the_value, the_len);
   return WFA_SUCCESS;
}

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((data+4), (unsigned char *)the_value, the_len);
   return WFA_SUCCESS;
}

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, _WORD *a3, _DWORD *a4, _QWORD *a5)
{
unsigned int v5; // er9
__int64 v6; // rdx
__int64 result; // rax
__int64 v8; // rsi

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

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2, _WORD *a3, _DWORD *a4, _QWORD *a5)
{
unsigned int v5; // er9
__int64 v6; // rdx
__int64 result; // rax
__int64 v8; // rsi

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

original_code:
BOOL wfaDecodeTLV(BYTE *tlv_data, int tlv_len, WORD *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)121); fprintf(stderr, "Parm buf invalid\n");
       return WFA_FAILURE;
   }
   *ptag = data->tag;
   *pval_len = data->len;
   if(tlv_len < *pval_len)
       return WFA_FAILURE;
   if(*pval_len != 0 && *pval_len < 640)
   {
      memcpy(pvalue, tlv_data+4, *pval_len);
   }
   return WFA_SUCCESS;
}

canonical_original_code:
int wfaDecodeTLV(unsigned char *tlv_data, int tlv_len, unsigned short *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)121); fprintf(stderr, "Parm buf invalid\n");
       return WFA_FAILURE;
   }
   *ptag = data->tag;
   *pval_len = data->len;
   if(tlv_len < *pval_len)
       return WFA_FAILURE;
   if(*pval_len != 0 && *pval_len < 640)
   {
      memcpy(pvalue, tlv_data+4, *pval_len);
   }
   return WFA_SUCCESS;
}

variable_types:
ptag
unsigned short *

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

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

return_type: unsigned short


wfaSetTLVTag

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

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

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

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


wfaGetTLVLen

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

if ( a1 )
result = *(unsigned __int16 *)(a1 + 2);
else
result = 1LL;
return result;
}

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

if ( a1 )
result = *(unsigned __int16 *)(a1 + 2);
else
result = 1LL;
return result;
}

original_code:
WORD wfaGetTLVLen(BYTE *tlv_data)
{
   wfaTLV *ptlv = (wfaTLV *)tlv_data;
   if(tlv_data == ((void *)0))
     return WFA_FAILURE;
   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 WFA_FAILURE;
   return ptlv->len;
}


wfaGetTLVvalue

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

canonical_decompiled_code:
__int64 __fastcall func5(int a1, __int64 a2, void *a3)
{
if ( !a2 )
return 1LL;
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 WFA_FAILURE;
    memcpy(pvalue, tlv_data+1+2, value_len);
    return WFA_SUCCESS;
}

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


printProfile

decompiled_code:
int __fastcall printProfile(const char *a1)
{
return printf(
"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 int *)a1 + 6),
a1 + 28,
*((unsigned int *)a1 + 11),
*((unsigned int *)a1 + 12),
*((unsigned int *)a1 + 13),
*((unsigned int *)a1 + 14));
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
return printf(
"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 int *)a1 + 6),
a1 + 28,
*((unsigned int *)a1 + 11),
*((unsigned int *)a1 + 12),
*((unsigned int *)a1 + 13),
*((unsigned int *)a1 + 14));
}

original_code:
void printProfile(tgProfile_t *pf)
{
    printf("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)
{
    printf("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]; int dport; char sipaddr[16]; int sport; int rate; int duration; int pksize; short trafficClass; int startdelay; int maxcnt; } *


isString

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

result = 1LL;
if ( *a1 )
result = (unsigned __int8)(*a1 - 66) > 0x17u && (unsigned __int8)(*a1 - 97) > 0x19u;
return result;
}

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

result = 1LL;
if ( *a1 )
result = (unsigned __int8)(*a1 - 66) > 0x17u && (unsigned __int8)(*a1 - 97) > 0x19u;
return result;
}

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

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 WFA_FAILURE;
    if (str[0] >= '0' && str[0] <= '9')
       return WFA_SUCCESS;
    else
       return WFA_FAILURE;
}


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

variable_types: dots int

variable_types:
tmpstr
char *


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: struct timeval { long tv_sec; long tv_usec; } *

variable_types: dtime int

variable_types: sec int

variable_types: usec int


decompiled_code:
__int64 __fastcall bigEndianBuff2Int(unsigned int *a1)
{
return _byteswap_ulong(*a1);
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int *a1)
{
return _byteswap_ulong(*a1);
}

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: val int

variable_types:
strval
char *


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

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

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

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

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


wfaCreateUDPSock

decompiled_code:
__int64 __fastcall wfaCreateUDPSock(__int64 a1, unsigned __int16 a2)
{
int v2; // eax
unsigned int v3; // er12
socklen_t v4; // edx
__int64 result; // rax
struct sockaddr v6[2]; // [rsp+0h] [rbp-28h] BYREF

v2 = socket(2, 2, 17);
if ( v2 < 0 )
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_sock.c", 162LL);
fwrite("createUDPSock socket() failed", 1uLL, 0x1DuLL, stderr);
result = 1LL;
}
else
{
v3 = v2;
*(_QWORD *)&v6[0].sa_data[6] = 0LL;
v6[0].sa_family = 2;
*(_QWORD *)&v6[0].sa_data[2] = (unsigned int)_bswap_32_constprop_0(a2, v6, 16LL);
*(_WORD *)v6[0].sa_data = _bswap_16(a2);
bind(v3, v6, v4);
result = v3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned __int16 a2)
{
int v2; // eax
unsigned int v3; // er12
socklen_t v4; // edx
__int64 result; // rax
struct sockaddr v6[2]; // [rsp+0h] [rbp-28h] BYREF

v2 = socket(2, 2, 17);
if ( v2 < 0 )
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_sock.c", 162LL);
fwrite("createUDPSock socket() failed", 1uLL, 0x1DuLL, stderr);
result = 1LL;
}
else
{
v3 = v2;
*(_QWORD *)&v6[0].sa_data[6] = 0LL;
v6[0].sa_family = 2;
*(_QWORD *)&v6[0].sa_data[2] = (unsigned int)func1(a2, v6, 16LL);
*(_WORD *)v6[0].sa_data = func0(a2);
bind(v3, v6, v4);
result = v3;
}
return result;
}

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)162); fprintf(stderr, "createUDPSock socket() failed");
        return WFA_FAILURE;
    }
    bzero(&servAddr, sizeof(servAddr));
    servAddr.sin_family = 2;
    servAddr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
    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)162); fprintf(stderr, "createUDPSock socket() failed");
        return WFA_FAILURE;
    }
    bzero(&servAddr, sizeof(servAddr));
    servAddr.sin_family = 2;
    servAddr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
    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]; }


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(unsigned int a1, const char *a2)
{
int v2; // edx
const void *v3; // rcx
socklen_t v4; // er8

inet_addr(a2);
_bswap_32_constprop_0(a1, 0LL, 35LL);
return setsockopt(a1, 0, v2, v3, v4);
}

canonical_decompiled_code:
int __fastcall func4(unsigned int a1, const char *a2)
{
int v2; // edx
const void *v3; // rcx
socklen_t v4; // er8

inet_addr(a2);
func1(a1, 0LL, 35LL);
return setsockopt(a1, 0, v2, v3, v4);
}

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)
{
socklen_t v4; // edx
struct sockaddr v6[2]; // [rsp+0h] [rbp-28h] BYREF

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

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

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

original_code:
int wfaConnectUDPPeer(int mysock, char *daddr, int 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 int


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", 228LL);
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", 228LL);
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)228); 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 != -1)
    {
         ((void) (((fdset)->__fds_bits)[((*fds->tgfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((*fds->tgfd) % (8 * (int) sizeof (__fd_mask)))))));
         *maxfdn1 = ((*maxfdn1-1) > (*fds->tgfd) ? (*maxfdn1-1) : (*fds->tgfd)) + 1;
    }
    if(*fds->cafd != -1)
    {
         ((void) (((fdset)->__fds_bits)[((*fds->cafd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((*fds->cafd) % (8 * (int) sizeof (__fd_mask)))))));
         *maxfdn1 = ((*maxfdn1-1) > (*fds->cafd) ? (*maxfdn1-1) : (*fds->cafd)) + 1;
    }
    if(*fds->psfd != -1)
    {
         ((void) (((fdset)->__fds_bits)[((*fds->psfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((*fds->psfd) % (8 * (int) sizeof (__fd_mask)))))));
         *maxfdn1 = ((*maxfdn1-1) > (*fds->psfd) ? (*maxfdn1-1) : (*fds->psfd)) + 1;
    }
    for(i = 0; i < 8; i++)
    {
        if(fds->wmmfds[i] != -1)
        {
            ((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) > (fds->wmmfds[i]) ? (*maxfdn1-1) : (fds->wmmfds[i])) +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 != -1)
    {
         ((void) (((fdset)->__fds_bits)[((*fds->tgfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((*fds->tgfd) % (8 * (int) sizeof (__fd_mask)))))));
         *maxfdn1 = ((*maxfdn1-1) > (*fds->tgfd) ? (*maxfdn1-1) : (*fds->tgfd)) + 1;
    }
    if(*fds->cafd != -1)
    {
         ((void) (((fdset)->__fds_bits)[((*fds->cafd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((*fds->cafd) % (8 * (int) sizeof (__fd_mask)))))));
         *maxfdn1 = ((*maxfdn1-1) > (*fds->cafd) ? (*maxfdn1-1) : (*fds->cafd)) + 1;
    }
    if(*fds->psfd != -1)
    {
         ((void) (((fdset)->__fds_bits)[((*fds->psfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((*fds->psfd) % (8 * (int) sizeof (__fd_mask)))))));
         *maxfdn1 = ((*maxfdn1-1) > (*fds->psfd) ? (*maxfdn1-1) : (*fds->psfd)) + 1;
    }
    for(i = 0; i < 8; i++)
    {
        if(fds->wmmfds[i] != -1)
        {
            ((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) > (fds->wmmfds[i]) ? (*maxfdn1-1) : (fds->wmmfds[i])) +1;
        }
    }
    return;
}

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

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

variable_types: i int


wfaCtrlSend

decompiled_code:
__int64 __fastcall wfaCtrlSend(int a1, const void *a2, int a3)
{
unsigned int v3; // er12

v3 = 1;
if ( a3 )
{
v3 = send(a1, a2, 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 a1, const void *a2, int a3)
{
unsigned int v3; // er12

v3 = 1;
if ( a3 )
{
v3 = send(a1, a2, 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 WFA_FAILURE;
    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, 0, 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, 0, a4, 0x10u);
}

original_code:
int wfaTrafficSendTo(int sock, char *buf, int bufLen, struct sockaddr *to)
{
   int bytesSent;
   bytesSent = sendto(sock, buf, bufLen, 0, 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 a1, void *a2)
{
return recv(a1, a2, 0x800uLL, 0);
}

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

original_code:
int wfaTrafficRecv(int sock, char *buf, struct sockaddr *from)
{
   int bytesRecvd =0;
   bytesRecvd = recv(sock, buf, 2048, 0);
   return bytesRecvd;
}

canonical_original_code:
int wfaTrafficRecv(int sock, char *buf, struct sockaddr *from)
{
   int bytesRecvd = 0;
   bytesRecvd = recv(sock, buf, 2048, 0);
   return bytesRecvd;
}


wfaGetifAddr

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

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

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

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

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)385); fprintf(stderr, "socket open error\n");
       return WFA_FAILURE;
    }
    strcpy(ifr.ifr_ifrn.ifrn_name, 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 WFA_FAILURE;
    }
    close(fd);;
    return WFA_FAILURE;
}

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

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