showMatrix

decompiled_code:
int __fastcall showMatrix(_QWORD *a1)
{
__int64 v1; // r13
__int64 i; // rbx
__int64 v3; // rsi
int result; // eax

if ( (__int64)a1[1] > 0 )
{
v1 = 0LL;
do
{
for ( i = 0LL; a1[2] > i; ++i )
{
v3 = (unsigned int)*(char *)(*(_QWORD *)(*a1 + 8 * v1) + i);
printf("%c ", v3);
}
++v1;
result = puts(&byte_8E7);
}
while ( a1[1] > v1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(_QWORD *a1)
{
__int64 v1; // r13
__int64 i; // rbx
__int64 v3; // rsi
int result; // eax

if ( (__int64)a1[1] > 0 )
{
v1 = 0LL;
do
{
for ( i = 0LL; a1[2] > i; ++i )
{
v3 = (unsigned int)*(char *)(*(_QWORD *)(*a1 + 8 * v1) + i);
printf("%c ", v3);
}
++v1;
result = puts(&byte_8E7);
}
while ( a1[1] > v1 );
}
return result;
}

original_code:
void showMatrix(Matrix *matriz){
  int i,j;
  for(i=0; i< matriz->rows; i++){
    for(j=0; j< matriz->columns; j++){
      printf("%c ", matriz->matrix[i][j]);
    }
    puts("");
  }
}

canonical_original_code:
void showMatrix(struct Matrix *matriz){
  int i; int j;
  for(i=0; i< matriz->rows; i++){
    for(j=0; j< matriz->columns; j++){
      printf("%c ", matriz->matrix[i][j]);
    }
    puts("");
  }
}

variable_types: struct Matrix { char **matrix; long long rows; long long columns; } *

variable_types: i int

variable_types: j int


showCubic

repo: Pupilo/CubiX

decompiled_code:
int __fastcall showCubic(_QWORD **a1)
{
puts("\n\nMatriz A");
showMatrix(*a1);
puts("\n\nMatriz B");
showMatrix(a1[1]);
puts("\n\nMatriz C");
showMatrix(a1[2]);
puts("\n\nMatriz D");
showMatrix(a1[3]);
puts("\n\nMatriz E");
showMatrix(a1[4]);
puts("\n\nMatriz F");
return showMatrix(a1[5]);
}

canonical_decompiled_code:
int __fastcall func4(_QWORD **a1)
{
puts("\n\nMatriz A");
func3(*a1);
puts("\n\nMatriz B");
func3(a1[1]);
puts("\n\nMatriz C");
func3(a1[2]);
puts("\n\nMatriz D");
func3(a1[3]);
puts("\n\nMatriz E");
func3(a1[4]);
puts("\n\nMatriz F");
return func3(a1[5]);
}

original_code:
void showCubic(Cubic *cubicRF){
    printf("\n\nMatriz A\n");
    showMatrix(cubicRF->Side_A);
    printf("\n\nMatriz B\n");
    showMatrix(cubicRF->Side_B);
    printf("\n\nMatriz C\n");
    showMatrix(cubicRF->Side_C);
    printf("\n\nMatriz D\n");
    showMatrix(cubicRF->Side_D);
    printf("\n\nMatriz E\n");
    showMatrix(cubicRF->Side_E);
    printf("\n\nMatriz F\n");
    showMatrix(cubicRF->Side_F);
}

canonical_original_code:
void showCubic(struct Cubic *cubicRF){
    printf("\n\nMatriz A\n");
    showMatrix(cubicRF->Side_A);
    printf("\n\nMatriz B\n");
    showMatrix(cubicRF->Side_B);
    printf("\n\nMatriz C\n");
    showMatrix(cubicRF->Side_C);
    printf("\n\nMatriz D\n");
    showMatrix(cubicRF->Side_D);
    printf("\n\nMatriz E\n");
    showMatrix(cubicRF->Side_E);
    printf("\n\nMatriz F\n");
    showMatrix(cubicRF->Side_F);
}

variable_types: struct Cubic { struct Matrix { char **matrix; long long rows; long long columns; } *Side_A; struct Matrix *Side_B; struct Matrix *Side_C; struct Matrix *Side_D; struct Matrix *Side_E; struct Matrix *Side_F; } *

return_type: void

user_defined_types: struct Cubic { struct Matrix *Side_A; struct Matrix *Side_B; struct Matrix *Side_C; struct Matrix *Side_D; struct Matrix *Side_E; struct Matrix *Side_F; }


banner

original_code:
void banner(){
 printf("##########################################################################\n");
 printf("Prototipo de criptografia Rubik versao 0.1								  \n");
    printf("Defesa do Bacharelado de Ciencia da computaçao, Faculdade Ruy Barbosa     \n");
 printf("Idealizador:\n");
 printf("Willian.A.Mayan\n\n");
 printf("Desenvolvedores:\n");
 printf("Jerffeson\n");
 printf("Willian.A.Mayan\n");
 printf("##########################################################################\n\n");
}


help

decompiled_code:
int help()
{
puts("##########################################################################");
puts(aOp);
puts("d - Criptografa o arquivo passado como argumento");
puts("c - Decriptografar o arquivo passado como argumento\n");
puts("[EXEMPLOS]\n");
puts("./CubiX -c arquivo_texto_puro");
puts("./CubiX -d arquivo_texto_cifrado");
return puts("./CubiX -h help");
}

canonical_decompiled_code:
int func1()
{
puts("##########################################################################");
puts(aOp);
puts("d - Criptografa o arquivo passado como argumento");
puts("c - Decriptografar o arquivo passado como argumento\n");
puts("[EXEMPLOS]\n");
puts("./CubiX -c arquivo_texto_puro");
puts("./CubiX -d arquivo_texto_cifrado");
return puts("./CubiX -h help");
}

original_code:
void help(){
 printf("##########################################################################\n");
 printf("[OPÇOES]\n\n");
 printf("d - Criptografa o arquivo passado como argumento\n");
 printf("c - Decriptografar o arquivo passado como argumento\n\n");
 printf("[EXEMPLOS]\n\n");
 printf("./CubiX -c arquivo_texto_puro\n");
 printf("./CubiX -d arquivo_texto_cifrado\n");
 printf("./CubiX -h help\n");
}


WfaRcvVOCyclic

decompiled_code:
__int64 __fastcall WfaRcvVOCyclic(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // r14
__int64 v4; // rdi

if ( *(_DWORD *)(a1 + 40) == 38 )
{
v3 = wmmps_info[10];
pthread_mutex_lock(&wmm_thr + 5 * v3 + 4);
while ( !*(&wmm_thr.__count + 50 * v3) )
pthread_cond_wait((pthread_cond_t *)((char *)&wmm_thr + 200 * v3 + 72), &wmm_thr + 5 * v3 + 4);
pthread_mutex_unlock(&wmm_thr + 5 * v3 + 4);
v4 = psSockfd;
gtgWmmPS = 0;
*(&wmm_thr.__count + 50 * v3) = 0;
asd_closeSocket(v4);
psSockfd = -1;
signal(14, (__sighandler_t)((char *)WfaRcvVOCyclic + 1));
wfaSetDUTPwrMgmt(0LL);
uapsd_sleep(1LL);
result = 0LL;
}
else
{
receiver(a1, a2, 208LL, 34LL);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // r14
__int64 v4; // rdi

if ( *(_DWORD *)(a1 + 40) == 38 )
{
v3 = wmmps_info[10];
pthread_mutex_lock(&wmm_thr + 5 * v3 + 4);
while ( !*(&wmm_thr.__count + 50 * v3) )
pthread_cond_wait((pthread_cond_t *)((char *)&wmm_thr + 200 * v3 + 72), &wmm_thr + 5 * v3 + 4);
pthread_mutex_unlock(&wmm_thr + 5 * v3 + 4);
v4 = psSockfd;
gtgWmmPS = 0;
*(&wmm_thr.__count + 50 * v3) = 0;
asd_closeSocket(v4);
psSockfd = -1;
signal(14, (__sighandler_t)((char *)WfaRcvVOCyclic + 1));
wfaSetDUTPwrMgmt(0LL);
uapsd_sleep(1LL);
result = 0LL;
}
else
{
receiver(a1, a2, 208LL, 34LL);
result = 0LL;
}
return result;
}

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] != (((((33 + 0x01) + 0x01) + 0x01) + 0x01) + 0x01))
 {
  if ((r=receiver(rmsg,length,0xD0,(33 + 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;
  asd_closeSocket(psSockfd);
  psSockfd = -1;
  signal(14, ((__sighandler_t) 1));
  wfaSetDUTPwrMgmt(0);
  uapsd_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] != (((((33 + 0x01) + 0x01) + 0x01) + 0x01) + 0x01))
 {
  if ((r=receiver(rmsg,length,0xD0,(33 + 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;
  asd_closeSocket(psSockfd);
  psSockfd = -1;
  signal(14, ((void (*)(int)) 1));
  wfaSetDUTPwrMgmt(0);
  uapsd_sleep(1);
 }
 return 0;
}

variable_types:
rmsg
unsigned int *

variable_types: length int

variable_types:
state
int *

variable_types: r int

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

return_type: int

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

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

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

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


WfaRcvStop

decompiled_code:
__int64 __fastcall WfaRcvStop(__int64 a1)
{
__int64 v1; // r12
__int64 v2; // rbx
pthread_mutex_t *v3; // rbp
pthread_mutex_t *v5; // r13
pthread_cond_t *v6; // rbx
__int64 v7; // rdi

v1 = wmmps_info[10];
v2 = 200 * v1;
v3 = &wmm_thr + 5 * v1;
v3->__count = 0;
if ( *(_DWORD *)(a1 + 40) != 38 )
return 0LL;
v5 = (pthread_mutex_t *)((char *)&wmm_thr + v2 + 160);
v6 = (pthread_cond_t *)((char *)&wmm_thr + v2 + 72);
pthread_mutex_lock(v5);
while ( !v3->__count )
{
puts("\r\n stuck");
pthread_cond_wait(v6, v5);
}
num_stops = 0;
pthread_mutex_unlock(v5);
v7 = psSockfd;
gtgWmmPS = 0;
*(&wmm_thr.__count + 50 * v1) = 0;
asd_closeSocket(v7);
psSockfd = -1;
signal(14, (__sighandler_t)((char *)WfaRcvVOCyclic + 1));
wfaSetDUTPwrMgmt(0LL);
uapsd_sleep(1LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // r12
__int64 v2; // rbx
pthread_mutex_t *v3; // rbp
pthread_mutex_t *v5; // r13
pthread_cond_t *v6; // rbx
__int64 v7; // rdi

v1 = wmmps_info[10];
v2 = 200 * v1;
v3 = &wmm_thr + 5 * v1;
v3->__count = 0;
if ( *(_DWORD *)(a1 + 40) != 38 )
return 0LL;
v5 = (pthread_mutex_t *)((char *)&wmm_thr + v2 + 160);
v6 = (pthread_cond_t *)((char *)&wmm_thr + v2 + 72);
pthread_mutex_lock(v5);
while ( !v3->__count )
{
puts("\r\n stuck");
pthread_cond_wait(v6, v5);
}
num_stops = 0;
pthread_mutex_unlock(v5);
v7 = psSockfd;
gtgWmmPS = 0;
*(&wmm_thr.__count + 50 * v1) = 0;
asd_closeSocket(v7);
psSockfd = -1;
signal(14, (__sighandler_t)((char *)WfaRcvVOCyclic + 1));
wfaSetDUTPwrMgmt(0LL);
uapsd_sleep(1LL);
return 0LL;
}

original_code:
int WfaRcvStop(unsigned int *rmsg,int length,int *state)
{
 tgWMM_t *my_wmm = &wmm_thr[wmmps_info.ps_thread];
 my_wmm->stop_flag = 0;
 ;;
 if(rmsg[10] != (((((33 + 0x01) + 0x01) + 0x01) + 0x01) + 0x01))
 {
 }
 else
 {
  pthread_mutex_lock(&my_wmm->thr_stop_mutex);
  while(!my_wmm->stop_flag)
  {
   printf("\r\n stuck\n");
   pthread_cond_wait(&my_wmm->thr_stop_cond, &my_wmm->thr_stop_mutex);
  }
  num_stops=0;
  pthread_mutex_unlock(&my_wmm->thr_stop_mutex);
  my_wmm->stop_flag = 0;
  gtgWmmPS = 0;
  asd_closeSocket(psSockfd);
  psSockfd = -1;
  signal(14, ((__sighandler_t) 1));
  wfaSetDUTPwrMgmt(0);
  uapsd_sleep(1);
 }
 return 0;
}

canonical_original_code:
int WfaRcvStop(unsigned int *rmsg, int length, int *state)
{
 struct _tg_wmm *my_wmm = &wmm_thr[wmmps_info.ps_thread];
 my_wmm->stop_flag = 0;
 ;;
 if(rmsg[10] != (((((33 + 0x01) + 0x01) + 0x01) + 0x01) + 0x01))
 {
 }
 else
 {
  pthread_mutex_lock(&my_wmm->thr_stop_mutex);
  while(!my_wmm->stop_flag)
  {
   printf("\r\n stuck\n");
   pthread_cond_wait(&my_wmm->thr_stop_cond, &my_wmm->thr_stop_mutex);
  }
  num_stops=0;
  pthread_mutex_unlock(&my_wmm->thr_stop_mutex);
  my_wmm->stop_flag = 0;
  gtgWmmPS = 0;
  asd_closeSocket(psSockfd);
  psSockfd = -1;
  signal(14, ((void (*)(int)) 1));
  wfaSetDUTPwrMgmt(0);
  uapsd_sleep(1);
 }
 return 0;
}

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


WfaStaSndHello

decompiled_code:
__int64 __fastcall WfaStaSndHello(__int64 a1, unsigned int a2, _DWORD *a3)
{
int v3; // eax
int v5; // ebx
__int64 v6; // rbx

v3 = num_hello;
v5 = wmmps_info[10];
++num_hello;
if ( !v3 )
create_apts_msg(35LL, &psTxMsg, 0LL);
wfaTrafficSendTo(psSockfd, &psTxMsg, msgsize, (unsigned int)((_DWORD)wmmps_info + 72));
uapsd_sleep(a2);
v6 = 200LL * v5;
pthread_mutex_lock((pthread_mutex_t *)((char *)&wmm_thr + v6 + 120));
if ( *(int *)((char *)&wmm_thr.__lock + v6) )
{
++*a3;
num_hello = 0;
*(int *)((char *)&wmm_thr.__lock + v6) = 0;
}
pthread_mutex_unlock((pthread_mutex_t *)((char *)&wmm_thr + v6 + 120));
if ( num_hello > 20 )
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_wmmps_linux.c", 144LL);
fwrite("Too many Hellos sent\n", 1uLL, 0x15uLL, stderr);
gtgWmmPS = 0;
num_hello = 0;
asd_closeSocket(psSockfd);
psSockfd = -1;
signal(14, (__sighandler_t)((char *)WfaRcvVOCyclic + 1));
}
return 0LL;
}

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

v3 = num_hello;
v5 = wmmps_info[10];
++num_hello;
if ( !v3 )
create_apts_msg(35LL, &psTxMsg, 0LL);
wfaTrafficSendTo(psSockfd, &psTxMsg, msgsize, (unsigned int)((_DWORD)wmmps_info + 72));
uapsd_sleep(a2);
v6 = 200LL * v5;
pthread_mutex_lock((pthread_mutex_t *)((char *)&wmm_thr + v6 + 120));
if ( *(int *)((char *)&wmm_thr.__lock + v6) )
{
++*a3;
num_hello = 0;
*(int *)((char *)&wmm_thr.__lock + v6) = 0;
}
pthread_mutex_unlock((pthread_mutex_t *)((char *)&wmm_thr + v6 + 120));
if ( num_hello > 20 )
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_wmmps_linux.c", 144LL);
fwrite("Too many Hellos sent\n", 1uLL, 0x15uLL, stderr);
gtgWmmPS = 0;
num_hello = 0;
asd_closeSocket(psSockfd);
psSockfd = -1;
signal(14, (__sighandler_t)((char *)WfaRcvVOCyclic + 1));
}
return 0LL;
}

original_code:
int WfaStaSndHello(char psave,int sleep_period,int *state)
{
 int r;
 tgWMM_t *my_wmm = &wmm_thr[wmmps_info.ps_thread];
 if(!(num_hello++))
  create_apts_msg(((33 + 0x01) + 0x01), psTxMsg,0);
 r = wfaTrafficSendTo(psSockfd, (char *)psTxMsg, msgsize, (struct sockaddr *)&wmmps_info.psToAddr);
 uapsd_sleep(sleep_period);
 pthread_mutex_lock(&my_wmm->thr_flag_mutex);
 if(my_wmm->thr_flag)
 {
  (*state)++;
  num_hello=0;
  my_wmm->thr_flag=0;
 }
 pthread_mutex_unlock(&my_wmm->thr_flag_mutex);
 if(num_hello > 20)
 {
  fprintf(stderr, "File %s, Line %ld: ", "wfa_wmmps_linux.c", (long)144); fprintf(stderr, "Too many Hellos sent\n");
  gtgWmmPS = 0;
  num_hello=0;
  asd_closeSocket(psSockfd);
  psSockfd = -1;
  signal(14, ((__sighandler_t) 1));
 }
 return 0;
}

canonical_original_code:
int WfaStaSndHello(char psave, int sleep_period, int *state)
{
 int r;
 struct _tg_wmm *my_wmm = &wmm_thr[wmmps_info.ps_thread];
 if(!(num_hello++))
  create_apts_msg(((33 + 0x01) + 0x01), psTxMsg,0);
 r = wfaTrafficSendTo(psSockfd, (char *)psTxMsg, msgsize, (struct sockaddr *)&wmmps_info.psToAddr);
 uapsd_sleep(sleep_period);
 pthread_mutex_lock(&my_wmm->thr_flag_mutex);
 if(my_wmm->thr_flag)
 {
  (*state)++;
  num_hello=0;
  my_wmm->thr_flag=0;
 }
 pthread_mutex_unlock(&my_wmm->thr_flag_mutex);
 if(num_hello > 20)
 {
  fprintf(stderr, "File %s, Line %ld: ", "wfa_wmmps_linux.c", (long)144); fprintf(stderr, "Too many Hellos sent\n");
  gtgWmmPS = 0;
  num_hello=0;
  asd_closeSocket(psSockfd);
  psSockfd = -1;
  signal(14, ((void (*)(int)) 1));
 }
 return 0;
}

variable_types: psave char

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


WfaStaWaitStop

decompiled_code:
__int64 __fastcall WfaStaWaitStop(char a1, unsigned int a2)
{
int v2; // ebx
int v3; // eax
__int64 v4; // rbx

v2 = wmmps_info[10];
uapsd_sleep(a2);
v3 = num_stops;
if ( !num_stops )
{
wfaSetDUTPwrMgmt((unsigned int)a1);
wfaTGSetPrio(psSockfd, 1LL);
v3 = num_stops;
}
num_stops = v3 + 1;
create_apts_msg(38LL, &psTxMsg, (unsigned int)wmmps_info[0]);
wfaTrafficSendTo(psSockfd, &psTxMsg, msgsize, (unsigned int)((_DWORD)wmmps_info + 72));
mpx("STA msg", &psTxMsg, 64LL);
v4 = 200LL * v2;
*(unsigned int *)((char *)&wmm_thr.__count + v4) = 1;
pthread_mutex_lock((pthread_mutex_t *)((char *)&wmm_thr + v4 + 160));
pthread_cond_signal((pthread_cond_t *)((char *)&wmm_thr + v4 + 72));
pthread_mutex_unlock((pthread_mutex_t *)((char *)&wmm_thr + v4 + 160));
if ( num_stops > 10 )
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_wmmps_linux.c", 183LL);
fwrite("Too many stops sent\n", 1uLL, 0x14uLL, stderr);
gtgWmmPS = 0;
asd_closeSocket(psSockfd);
psSockfd = -1;
signal(14, (__sighandler_t)((char *)WfaRcvVOCyclic + 1));
}
wfaSetDUTPwrMgmt(0LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(char a1, unsigned int a2)
{
int v2; // ebx
int v3; // eax
__int64 v4; // rbx

v2 = wmmps_info[10];
uapsd_sleep(a2);
v3 = num_stops;
if ( !num_stops )
{
wfaSetDUTPwrMgmt((unsigned int)a1);
wfaTGSetPrio(psSockfd, 1LL);
v3 = num_stops;
}
num_stops = v3 + 1;
create_apts_msg(38LL, &psTxMsg, (unsigned int)wmmps_info[0]);
wfaTrafficSendTo(psSockfd, &psTxMsg, msgsize, (unsigned int)((_DWORD)wmmps_info + 72));
mpx("STA msg", &psTxMsg, 64LL);
v4 = 200LL * v2;
*(unsigned int *)((char *)&wmm_thr.__count + v4) = 1;
pthread_mutex_lock((pthread_mutex_t *)((char *)&wmm_thr + v4 + 160));
pthread_cond_signal((pthread_cond_t *)((char *)&wmm_thr + v4 + 72));
pthread_mutex_unlock((pthread_mutex_t *)((char *)&wmm_thr + v4 + 160));
if ( num_stops > 10 )
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_wmmps_linux.c", 183LL);
fwrite("Too many stops sent\n", 1uLL, 0x14uLL, stderr);
gtgWmmPS = 0;
asd_closeSocket(psSockfd);
psSockfd = -1;
signal(14, (__sighandler_t)((char *)WfaRcvVOCyclic + 1));
}
wfaSetDUTPwrMgmt(0LL);
return 0LL;
}

original_code:
int WfaStaWaitStop(char psave,int sleep_period,int *state)
{
 int r;
 int myid=wmmps_info.ps_thread;
 ;;
 uapsd_sleep(sleep_period);
 if(!num_stops)
 {
  wfaSetDUTPwrMgmt(psave);
  wfaTGSetPrio(psSockfd, 1);
 }
 num_stops++;
 create_apts_msg((((((33 + 0x01) + 0x01) + 0x01) + 0x01) + 0x01), psTxMsg,wmmps_info.my_sta_id);
 r = wfaTrafficSendTo(psSockfd, (char *)psTxMsg, msgsize, (struct sockaddr *)&wmmps_info.psToAddr);
 mpx("STA msg",psTxMsg,64);
 wmm_thr[myid].stop_flag = 1;
 pthread_mutex_lock(&wmm_thr[myid].thr_stop_mutex);
 pthread_cond_signal(&wmm_thr[myid].thr_stop_cond);
 pthread_mutex_unlock(&wmm_thr[myid].thr_stop_mutex);
 if(num_stops > 10)
 {
  fprintf(stderr, "File %s, Line %ld: ", "wfa_wmmps_linux.c", (long)183); fprintf(stderr, "Too many stops sent\n");
  gtgWmmPS = 0;
  asd_closeSocket(psSockfd);
  psSockfd = -1;
  signal(14, ((__sighandler_t) 1));
 }
 wfaSetDUTPwrMgmt(0);
 return 0;
}

canonical_original_code:
int WfaStaWaitStop(char psave, int sleep_period, int *state)
{
 int r;
 int myid = wmmps_info.ps_thread;
 ;;
 uapsd_sleep(sleep_period);
 if(!num_stops)
 {
  wfaSetDUTPwrMgmt(psave);
  wfaTGSetPrio(psSockfd, 1);
 }
 num_stops++;
 create_apts_msg((((((33 + 0x01) + 0x01) + 0x01) + 0x01) + 0x01), psTxMsg,wmmps_info.my_sta_id);
 r = wfaTrafficSendTo(psSockfd, (char *)psTxMsg, msgsize, (struct sockaddr *)&wmmps_info.psToAddr);
 mpx("STA msg",psTxMsg,64);
 wmm_thr[myid].stop_flag = 1;
 pthread_mutex_lock(&wmm_thr[myid].thr_stop_mutex);
 pthread_cond_signal(&wmm_thr[myid].thr_stop_cond);
 pthread_mutex_unlock(&wmm_thr[myid].thr_stop_mutex);
 if(num_stops > 10)
 {
  fprintf(stderr, "File %s, Line %ld: ", "wfa_wmmps_linux.c", (long)183); fprintf(stderr, "Too many stops sent\n");
  gtgWmmPS = 0;
  asd_closeSocket(psSockfd);
  psSockfd = -1;
  signal(14, ((void (*)(int)) 1));
 }
 wfaSetDUTPwrMgmt(0);
 return 0;
}

variable_types: myid int


decompiled_code:
unsigned int init_thr_flag()
{
_DWORD *v0; // r12
int v1; // ebp
pthread_mutex_t *v2; // rbx
pthread_t *v3; // rdi
void *v4; // rcx
unsigned int result; // eax
int policy; // [rsp+8h] [rbp-60h] BYREF
struct sched_param param; // [rsp+Ch] [rbp-5Ch] BYREF
pthread_attr_t attr; // [rsp+10h] [rbp-58h] BYREF

v0 = &tdata;
v1 = 0;
v2 = (pthread_mutex_t *)(unsigned int)((_DWORD)&wmm_thr + 120);
pthread_attr_init(&attr);
param.__sched_priority = 10;
pthread_attr_setschedparam(&attr, &param);
pthread_attr_getschedpolicy(&attr, &policy);
pthread_attr_setschedpolicy(&attr, 2);
pthread_attr_getschedpolicy(&attr, &policy);
do
{
*v0 = v1++;
pthread_mutex_init(v2, 0LL);
pthread_cond_init((pthread_cond_t *)(&v2[-3].__align + 3), 0LL);
v3 = (pthread_t *)(&v2[-3].__align + 2);
v4 = v0;
v0 += 6;
v2 += 5;
v2[-8].__owner = pthread_create(v3, &attr, wfa_wmm_thread, v4);
result = sleep(1u);
v2[-8].__lock = 0;
}
while ( v1 != 6 );
return result;
}

canonical_decompiled_code:
unsigned int func4()
{
_DWORD *v0; // r12
int v1; // ebp
pthread_mutex_t *v2; // rbx
pthread_t *v3; // rdi
void *v4; // rcx
unsigned int result; // eax
int policy; // [rsp+8h] [rbp-60h] BYREF
struct sched_param param; // [rsp+Ch] [rbp-5Ch] BYREF
pthread_attr_t attr; // [rsp+10h] [rbp-58h] BYREF

v0 = &tdata;
v1 = 0;
v2 = (pthread_mutex_t *)(unsigned int)((_DWORD)&wmm_thr + 120);
pthread_attr_init(&attr);
param.__sched_priority = 10;
pthread_attr_setschedparam(&attr, &param);
pthread_attr_getschedpolicy(&attr, &policy);
pthread_attr_setschedpolicy(&attr, 2);
pthread_attr_getschedpolicy(&attr, &policy);
do
{
*v0 = v1++;
pthread_mutex_init(v2, 0LL);
pthread_cond_init((pthread_cond_t *)(&v2[-3].__align + 3), 0LL);
v3 = (pthread_t *)(&v2[-3].__align + 2);
v4 = v0;
v0 += 6;
v2 += 5;
v2[-8].__owner = pthread_create(v3, &attr, wfa_wmm_thread, v4);
result = sleep(1u);
v2[-8].__lock = 0;
}
while ( v1 != 6 );
return result;
}

original_code:
void init_thr_flag()
{
 int cntThr = 0;
 pthread_attr_t ptAttr;
 int ptPolicy;
 struct sched_param ptSchedParam;
 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(cntThr = 0; cntThr< 6; cntThr++)
 {
  tdata[cntThr].tid = cntThr;
  pthread_mutex_init(&wmm_thr[cntThr].thr_flag_mutex, ((void *)0));
  pthread_cond_init(&wmm_thr[cntThr].thr_flag_cond, ((void *)0));
  wmm_thr[cntThr].thr_id = pthread_create(&wmm_thr[cntThr].thr,
   &ptAttr, wfa_wmm_thread, &tdata[cntThr]);
  sleep(1);
  wmm_thr[cntThr].thr_flag = 0;
 }
}

canonical_original_code:
void init_thr_flag()
{
 int cntThr = 0;
 union pthread_attr_t ptAttr;
 int ptPolicy;
 struct sched_param ptSchedParam;
 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(cntThr = 0; cntThr< 6; cntThr++)
 {
  tdata[cntThr].tid = cntThr;
  pthread_mutex_init(&wmm_thr[cntThr].thr_flag_mutex, ((void *)0));
  pthread_cond_init(&wmm_thr[cntThr].thr_flag_cond, ((void *)0));
  wmm_thr[cntThr].thr_id = pthread_create(&wmm_thr[cntThr].thr,
   &ptAttr, wfa_wmm_thread, &tdata[cntThr]);
  sleep(1);
  wmm_thr[cntThr].thr_flag = 0;
 }
}

variable_types: cntThr int

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

variable_types: ptPolicy int

variable_types: struct sched_param { int sched_priority; }


wfaSetThreadPrio

decompiled_code:
int __fastcall wfaSetThreadPrio(__int64 a1, int a2)
{
struct sched_param param; // [rsp+Ch] [rbp-4Ch] BYREF
pthread_attr_t attr; // [rsp+10h] [rbp-48h] BYREF

pthread_attr_init(&attr);
pthread_attr_setschedpolicy(&attr, 2);
if ( a2 == 3 )
{
param.__sched_priority = 69;
}
else if ( a2 > 3 )
{
if ( a2 == 4 )
param.__sched_priority = 70;
}
else if ( a2 == 1 )
{
param.__sched_priority = 68;
}
else if ( a2 == 2 )
{
param.__sched_priority = 67;
}
return pthread_attr_setschedparam(&attr, &param);
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1, int a2)
{
struct sched_param param; // [rsp+Ch] [rbp-4Ch] BYREF
pthread_attr_t attr; // [rsp+10h] [rbp-48h] BYREF

pthread_attr_init(&attr);
pthread_attr_setschedpolicy(&attr, 2);
if ( a2 == 3 )
{
param.__sched_priority = 69;
}
else if ( a2 > 3 )
{
if ( a2 == 4 )
param.__sched_priority = 70;
}
else if ( a2 == 1 )
{
param.__sched_priority = 68;
}
else if ( a2 == 2 )
{
param.__sched_priority = 67;
}
return pthread_attr_setschedparam(&attr, &param);
}

original_code:
void wfaSetThreadPrio(int tid, int class)
{
 struct sched_param tschedParam;
 pthread_attr_t tattr;
 pthread_attr_init(&tattr);
 pthread_attr_setschedpolicy(&tattr, 2);
 switch(class)
 {
 case 2:
  tschedParam.sched_priority = 70-3;
  break;
 case 3:
  tschedParam.sched_priority = 70-1;
  break;
 case 4:
  tschedParam.sched_priority = 70;
  break;
 case 1:
  tschedParam.sched_priority = 70-2;
 default:
  ;
 }
 pthread_attr_setschedparam(&tattr, &tschedParam);
}

canonical_original_code:
void wfaSetThreadPrio(int tid, int class)
{
 struct sched_param tschedParam;
 union pthread_attr_t tattr;
 pthread_attr_init(&tattr);
 pthread_attr_setschedpolicy(&tattr, 2);
 switch(class)
 {
 case 2:
  tschedParam.sched_priority = 70-3;
  break;
 case 3:
  tschedParam.sched_priority = 70-1;
  break;
 case 4:
  tschedParam.sched_priority = 70;
  break;
 case 1:
  tschedParam.sched_priority = 70-2;
 default:
  ;
 }
 pthread_attr_setschedparam(&tattr, &tschedParam);
}

variable_types: tid int

variable_types: class int

user_defined_types: struct sched_param { int sched_priority; }

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


decompiled_code:
void __fastcall __noreturn wfa_wmm_thread(void *a1)
{
signed int v1; // ebx
__int64 v2; // rbx
unsigned int v3; // er13
__int64 v4; // r15
int v5; // eax
unsigned int v6; // eax
__int64 v7; // r14
__int64 v8; // rdi
int v9; // eax
int v10; // ecx
__int64 v11; // rcx
char *v12; // rax
unsigned int v13; // [rsp+Ch] [rbp-49Ch]
char *v15; // [rsp+18h] [rbp-490h]
char v16[4]; // [rsp+2Ch] [rbp-47Ch] BYREF
pthread_attr_t attr; // [rsp+30h] [rbp-478h] BYREF
char v18[1080]; // [rsp+70h] [rbp-438h] BYREF

v1 = *(_DWORD *)a1;
v13 = *(_DWORD *)a1;
pthread_attr_init(&attr);
pthread_attr_setschedpolicy(&attr, 2);
v15 = (char *)a1 + 16;
v2 = 200LL * v1;
while ( 1 )
{
pthread_mutex_lock((pthread_mutex_t *)((char *)&wmm_thr + v2 + 120));
while ( !*(int *)((char *)&wmm_thr.__lock + v2) )
pthread_cond_wait((pthread_cond_t *)&wmm_thr.__size[v2 + 24], (pthread_mutex_t *)((char *)&wmm_thr + v2 + 120));
sleep(2u);
pthread_mutex_unlock((pthread_mutex_t *)((char *)&wmm_thr + v2 + 120));
v3 = *(int *)((char *)&wmm_thr.__lock + v2);
*(int *)((char *)&wmm_thr.__lock + v2) = 0;
v4 = findStreamProfile(v3);
v5 = *(_DWORD *)(v4 + 32);
if ( v5 == 1 )
{
v6 = wfaCreateUDPSock(v4 + 54, *(unsigned __int16 *)(v4 + 70));
v7 = (unsigned int)wfaConnectUDPPeer(v6, v4 + 36, *(unsigned __int16 *)(v4 + 52));
wfaTGSetPrio(v7, (unsigned int)*(__int16 *)(v4 + 84));
wfaSetThreadPrio(v13, *(__int16 *)(v4 + 84));
if ( (unsigned int)(*(_DWORD *)(v4 + 88) - 1) <= 0x30 )
asd_sleep();
signal(14, (__sighandler_t)&tmout_stop_send);
alarm(*(_DWORD *)(v4 + 76));
if ( *(_DWORD *)(v4 + 72) )
wfaSendLongFile((unsigned int)v7, v3, v18, v16);
else
wfaImprovePerfSendLongFile((unsigned int)v7, v3, v18, v16);
memset(v18, 0, 0x400uLL);
if ( (_DWORD)v7 != -1 )
asd_closeSocket((unsigned int)v7);
if ( !v13 )
printf("respBuf = %s sent from thr\n", v18);
}
else if ( v5 == 2 )
{
if ( *(_DWORD *)(v4 + 28) == 7 )
{
wmmps_info[5] = 1;
wmmps_info[11] = 0;
v8 = psSockfd;
wmmps_info[10] = v13;
*(_QWORD *)&wmmps_info[16] = a1;
v9 = wfaTGSetPrio(v8, 1LL);
v10 = gtgWmmPS;
wmmps_info[12] = v9;
*((_DWORD *)a1 + 4) = 0;
if ( v10 > 0 )
{
do
{
if ( resetsnd )
{
*((_DWORD *)a1 + 4) = 0;
v11 = 0LL;
resetsnd = 0;
}
else
{
v11 = 16LL * *((int *)a1 + 4);
}
v12 = (char *)&stationProcStatetbl + 176 * wmmps_info[5];
*((_QWORD *)a1 + 1) = v12;
(*(void (__fastcall **)(_QWORD, _QWORD, char *))&v12[v11])(
(unsigned int)v12[v11 + 8],
*(unsigned int *)&v12[v11 + 12],
v15);
}
while ( gtgWmmPS > 0 );
}
}
}
else
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_wmmps_linux.c", 323LL);
fwrite("Unknown covered case\n", 1uLL, 0x15uLL, stderr);
}
}
}

canonical_decompiled_code:
void __fastcall __noreturn func6(void *a1)
{
signed int v1; // ebx
__int64 v2; // rbx
unsigned int v3; // er13
__int64 v4; // r15
int v5; // eax
unsigned int v6; // eax
__int64 v7; // r14
__int64 v8; // rdi
int v9; // eax
int v10; // ecx
__int64 v11; // rcx
char *v12; // rax
unsigned int v13; // [rsp+Ch] [rbp-49Ch]
char *v15; // [rsp+18h] [rbp-490h]
char v16[4]; // [rsp+2Ch] [rbp-47Ch] BYREF
pthread_attr_t attr; // [rsp+30h] [rbp-478h] BYREF
char v18[1080]; // [rsp+70h] [rbp-438h] BYREF

v1 = *(_DWORD *)a1;
v13 = *(_DWORD *)a1;
pthread_attr_init(&attr);
pthread_attr_setschedpolicy(&attr, 2);
v15 = (char *)a1 + 16;
v2 = 200LL * v1;
while ( 1 )
{
pthread_mutex_lock((pthread_mutex_t *)((char *)&wmm_thr + v2 + 120));
while ( !*(int *)((char *)&wmm_thr.__lock + v2) )
pthread_cond_wait((pthread_cond_t *)&wmm_thr.__size[v2 + 24], (pthread_mutex_t *)((char *)&wmm_thr + v2 + 120));
sleep(2u);
pthread_mutex_unlock((pthread_mutex_t *)((char *)&wmm_thr + v2 + 120));
v3 = *(int *)((char *)&wmm_thr.__lock + v2);
*(int *)((char *)&wmm_thr.__lock + v2) = 0;
v4 = findStreamProfile(v3);
v5 = *(_DWORD *)(v4 + 32);
if ( v5 == 1 )
{
v6 = wfaCreateUDPSock(v4 + 54, *(unsigned __int16 *)(v4 + 70));
v7 = (unsigned int)wfaConnectUDPPeer(v6, v4 + 36, *(unsigned __int16 *)(v4 + 52));
wfaTGSetPrio(v7, (unsigned int)*(__int16 *)(v4 + 84));
func5(v13, *(__int16 *)(v4 + 84));
if ( (unsigned int)(*(_DWORD *)(v4 + 88) - 1) <= 0x30 )
asd_sleep();
signal(14, (__sighandler_t)&tmout_stop_send);
alarm(*(_DWORD *)(v4 + 76));
if ( *(_DWORD *)(v4 + 72) )
wfaSendLongFile((unsigned int)v7, v3, v18, v16);
else
wfaImprovePerfSendLongFile((unsigned int)v7, v3, v18, v16);
memset(v18, 0, 0x400uLL);
if ( (_DWORD)v7 != -1 )
asd_closeSocket((unsigned int)v7);
if ( !v13 )
printf("respBuf = %s sent from thr\n", v18);
}
else if ( v5 == 2 )
{
if ( *(_DWORD *)(v4 + 28) == 7 )
{
wmmps_info[5] = 1;
wmmps_info[11] = 0;
v8 = psSockfd;
wmmps_info[10] = v13;
*(_QWORD *)&wmmps_info[16] = a1;
v9 = wfaTGSetPrio(v8, 1LL);
v10 = gtgWmmPS;
wmmps_info[12] = v9;
*((_DWORD *)a1 + 4) = 0;
if ( v10 > 0 )
{
do
{
if ( resetsnd )
{
*((_DWORD *)a1 + 4) = 0;
v11 = 0LL;
resetsnd = 0;
}
else
{
v11 = 16LL * *((int *)a1 + 4);
}
v12 = (char *)&stationProcStatetbl + 176 * wmmps_info[5];
*((_QWORD *)a1 + 1) = v12;
(*(void (__fastcall **)(_QWORD, _QWORD, char *))&v12[v11])(
(unsigned int)v12[v11 + 8],
*(unsigned int *)&v12[v11 + 12],
v15);
}
while ( gtgWmmPS > 0 );
}
}
}
else
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_wmmps_linux.c", 323LL);
fwrite("Unknown covered case\n", 1uLL, 0x15uLL, stderr);
}
}
}

original_code:
void * wfa_wmm_thread(void *thr_param)
{
 int myId = ((tgThrData_t *)thr_param)->tid;
 tgWMM_t *my_wmm = &wmm_thr[myId];
 tgStream_t *myStream = ((void *)0);
 tgThrData_t *tdata =(tgThrData_t *) thr_param;
 int myStreamId;
 int mySock = -1;
 int status, respLen;
 tgProfile_t *myProfile;
 StationProcStatetbl_t curr_state;
 BYTE respBuf[1024];
 pthread_attr_t tattr;
 pthread_attr_init(&tattr);
 pthread_attr_setschedpolicy(&tattr, 2);
 while(1)
 {
  pthread_mutex_lock(&my_wmm->thr_flag_mutex);
  while(!my_wmm->thr_flag)
  {
   pthread_cond_wait(&my_wmm->thr_flag_cond, &my_wmm->thr_flag_mutex);
  }
  sleep(2);
  pthread_mutex_unlock(&my_wmm->thr_flag_mutex);
  myStreamId = my_wmm->thr_flag;
  my_wmm->thr_flag = 0;
  myStream = findStreamProfile(myStreamId);
  myProfile = &myStream->profile;
  if(myProfile == ((void *)0))
  {
   status = STATUS_INVALID;
   wfaEncodeTLV((((((((((((((((((((((((((((((((((((((0x01 + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01), 4, (BYTE *)&status, respBuf);
   respLen = sizeof(wfaTLV)+4;
   continue;
  }
  switch(myProfile->direction)
  {
  case 1:
   mySock = wfaCreateUDPSock(myProfile->sipaddr, myProfile->sport);
   mySock = wfaConnectUDPPeer(mySock, myProfile->dipaddr, myProfile->dport);
   wfaTGSetPrio(mySock, myProfile->trafficClass);
   wfaSetThreadPrio(myId, myProfile->trafficClass);
   if(myProfile->startdelay > 0 && myProfile->startdelay < 50)
   {
    asd_sleep(myProfile->startdelay);
   }
   signal(14, tmout_stop_send);
   alarm(myProfile->duration);
   if (myProfile->rate != 0)
    wfaSendLongFile(mySock, myStreamId, respBuf, &respLen );
   else
    wfaImprovePerfSendLongFile(mySock, myStreamId, respBuf, &respLen );
   memset(respBuf, 0, 1024);
   if (mySock != -1) {
    asd_closeSocket(mySock);
    mySock = -1;
   }
   if(myId == 0) {
    printf("respBuf = %s    sent from thr\n", respBuf);
   }
   break;
  case 2:
   if(myProfile->profile == 7)
   {
    wmmps_info.sta_test = 1;
    wmmps_info.ps_thread = myId;
    wmmps_info.rcv_state = 0;
    wmmps_info.tdata = tdata;
    wmmps_info.dscp = wfaTGSetPrio(psSockfd, 1);
    tdata->state_num=0;
    while(gtgWmmPS>0)
    {
     if(resetsnd)
     {
      tdata->state_num = 0;
      resetsnd = 0;
     }
     tdata->state = stationProcStatetbl[wmmps_info.sta_test];
     curr_state = tdata->state[tdata->state_num];
     curr_state.statefunc(curr_state.pw_offon,curr_state.sleep_period,&(tdata->state_num));
    }
   }
   break;
  default:
   fprintf(stderr, "File %s, Line %ld: ", "wfa_wmmps_linux.c", (long)323); fprintf(stderr, "Unknown covered case\n");
  }
 }
}

canonical_original_code:
void *wfa_wmm_thread(void *thr_param)
{
 int myId = ((tgThrData_t *)thr_param)->tid;
 struct _tg_wmm *my_wmm = &wmm_thr[myId];
 struct _tg_stream *myStream = ((void *)0);
 struct _tg_thr_data *tdata = (tgThrData_t *) thr_param;
 int myStreamId;
 int mySock = -1;
 int status; int respLen;
 struct _tg_profile *myProfile;
 struct station_state_table curr_state;
 unsigned char respBuf[1024];
 union pthread_attr_t tattr;
 pthread_attr_init(&tattr);
 pthread_attr_setschedpolicy(&tattr, 2);
 while(1)
 {
  pthread_mutex_lock(&my_wmm->thr_flag_mutex);
  while(!my_wmm->thr_flag)
  {
   pthread_cond_wait(&my_wmm->thr_flag_cond, &my_wmm->thr_flag_mutex);
  }
  sleep(2);
  pthread_mutex_unlock(&my_wmm->thr_flag_mutex);
  myStreamId = my_wmm->thr_flag;
  my_wmm->thr_flag = 0;
  myStream = findStreamProfile(myStreamId);
  myProfile = &myStream->profile;
  if(myProfile == ((void *)0))
  {
   status = STATUS_INVALID;
   wfaEncodeTLV((((((((((((((((((((((((((((((((((((((0x01 + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01), 4, (unsigned char *)&status, respBuf);
   respLen = sizeof(wfaTLV)+4;
   continue;
  }
  switch(myProfile->direction)
  {
  case 1:
   mySock = wfaCreateUDPSock(myProfile->sipaddr, myProfile->sport);
   mySock = wfaConnectUDPPeer(mySock, myProfile->dipaddr, myProfile->dport);
   wfaTGSetPrio(mySock, myProfile->trafficClass);
   wfaSetThreadPrio(myId, myProfile->trafficClass);
   if(myProfile->startdelay > 0 && myProfile->startdelay < 50)
   {
    asd_sleep(myProfile->startdelay);
   }
   signal(14, tmout_stop_send);
   alarm(myProfile->duration);
   if (myProfile->rate != 0)
    wfaSendLongFile(mySock, myStreamId, respBuf, &respLen );
   else
    wfaImprovePerfSendLongFile(mySock, myStreamId, respBuf, &respLen );
   memset(respBuf, 0, 1024);
   if (mySock != -1) {
    asd_closeSocket(mySock);
    mySock = -1;
   }
   if(myId == 0) {
    printf("respBuf = %s    sent from thr\n", respBuf);
   }
   break;
  case 2:
   if(myProfile->profile == 7)
   {
    wmmps_info.sta_test = 1;
    wmmps_info.ps_thread = myId;
    wmmps_info.rcv_state = 0;
    wmmps_info.tdata = tdata;
    wmmps_info.dscp = wfaTGSetPrio(psSockfd, 1);
    tdata->state_num=0;
    while(gtgWmmPS>0)
    {
     if(resetsnd)
     {
      tdata->state_num = 0;
      resetsnd = 0;
     }
     tdata->state = stationProcStatetbl[wmmps_info.sta_test];
     curr_state = tdata->state[tdata->state_num];
     curr_state.statefunc(curr_state.pw_offon,curr_state.sleep_period,&(tdata->state_num));
    }
   }
   break;
  default:
   fprintf(stderr, "File %s, Line %ld: ", "wfa_wmmps_linux.c", (long)323); fprintf(stderr, "Unknown covered case\n");
  }
 }
}

variable_types: myId int

variable_types: struct _tg_stream { int id; int sockfd; int tblidx; int lastPktSN; int rxTimeLast; int fmInterval; int state; struct _tg_profile { int profile; int direction; char dipaddr[16]; unsigned short dport; char sipaddr[16]; unsigned short sport; int rate; int duration; int pksize; short trafficClass; int startdelay; } profile; struct _tg_stats { int txFrames; int rxFrames; int txPayloadBytes; int rxPayloadBytes; int outOfSequenceFrames; int lostPkts; unsigned long jitter; } stats; } *

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

variable_types: myStreamId int

variable_types: mySock int

variable_types: status int

variable_types: respLen int

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

variable_types:
respBuf
unsigned char [1024]

return_type: void *

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

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


WmmpsTrafficRecv

decompiled_code:
ssize_t __fastcall WmmpsTrafficRecv(int a1, void *a2, struct sockaddr *a3)
{
socklen_t addr_len[3]; // [rsp+Ch] [rbp-Ch] BYREF

return recvfrom(a1, a2, 0x800uLL, 0, a3, addr_len);
}

canonical_decompiled_code:
ssize_t __fastcall func7(int a1, void *a2, struct sockaddr *a3)
{
socklen_t addr_len[3]; // [rsp+Ch] [rbp-Ch] BYREF

return recvfrom(a1, a2, 0x800uLL, 0, a3, addr_len);
}

original_code:
int WmmpsTrafficRecv(int sock, char *buf, struct sockaddr *from)
{
 int bytesRecvd;
 socklen_t addrLen;
 bytesRecvd = recvfrom(sock, buf, 2048, 0, from, &addrLen);
 return bytesRecvd;
}

canonical_original_code:
int WmmpsTrafficRecv(int sock, char *buf, struct sockaddr *from)
{
 int bytesRecvd;
 unsigned int addrLen;
 bytesRecvd = recvfrom(sock, buf, 2048, 0, from, &addrLen);
 return bytesRecvd;
}

variable_types: sock int

variable_types:
buf
char *

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

variable_types: bytesRecvd int

variable_types:
addrLen
unsigned int


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

v3 = 4LL * a1;
*(_DWORD *)a2 = wmmps_info[2];
v4 = wmmps_info[12];
*(_DWORD *)(a2 + 36) = a3;
*(_DWORD *)(a2 + 4) = v4;
*(_QWORD *)(a2 + 8) = 0LL;
*(_QWORD *)(a2 + 16) = 0LL;
*(_DWORD *)(a2 + 40) = apts_msgs[v3 + 1];
strcpy((char *)(a2 + 44), (const char *)apts_msgs[v3]);
return printf("create_apts_msg (%s) %d\n", (const char *)apts_msgs[v3], LODWORD(apts_msgs[v3 + 1]));
}

canonical_decompiled_code:
int __fastcall func0(int a1, __int64 a2, int a3)
{
__int64 v3; // rbx
int v4; // eax

v3 = 4LL * a1;
*(_DWORD *)a2 = wmmps_info[2];
v4 = wmmps_info[12];
*(_DWORD *)(a2 + 36) = a3;
*(_DWORD *)(a2 + 4) = v4;
*(_QWORD *)(a2 + 8) = 0LL;
*(_QWORD *)(a2 + 16) = 0LL;
*(_DWORD *)(a2 + 40) = apts_msgs[v3 + 1];
strcpy((char *)(a2 + 44), (const char *)apts_msgs[v3]);
return printf("create_apts_msg (%s) %d\n", (const char *)apts_msgs[v3], LODWORD(apts_msgs[v3 + 1]));
}

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);
 printf("create_apts_msg (%s) %d\n", t->name,t->cmd);
}

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);
 printf("create_apts_msg (%s) %d\n", t->name,t->cmd);
}

variable_types: msg int

variable_types:
txbuf
unsigned int []

variable_types: id int

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


decompiled_code:
int __fastcall print_hex_string(unsigned __int8 *a1, int a2)
{
__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 func1(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: 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 func2(const char *a1, __int64 a2, int a3)
{
printf("%s MSG: %s\n ", a1, (const char *)(a2 + 44));
return func1((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; // ebp
int v5; // er13
__int64 v6; // rbx

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

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

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

original_code:
int WfaRcvProc(unsigned int *rmsg,int length,int *state)
{
 int sta_test;
 int usedThread = wmmps_info.ps_thread;
 num_hello=0;
 sta_test = wmmps_info.sta_test = rmsg[10];
 mpx("STA recv\n", rmsg, 64);
 if(!((sta_test >=1)&&(sta_test <= 33)))
  return -1;
 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 = wmmps_info.sta_test = rmsg[10];
 mpx("STA recv\n", rmsg, 64);
 if(!((sta_test >=1)&&(sta_test <= 33)))
  return -1;
 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


receiver

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

v4 = *(unsigned int *)(a1 + 4);
v6 = *(unsigned int *)(a1 + 40);
if ( (_DWORD)v4 != a3 || (result = 1LL, a4 != (_DWORD)v6) )
{
printf("\r\n dscp recd is %d msg type is %d\n", v4, v6);
result = 4294967290LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, int a3, int a4)
{
__int64 v4; // rsi
__int64 v6; // rdx
__int64 result; // rax

v4 = *(unsigned int *)(a1 + 4);
v6 = *(unsigned int *)(a1 + 40);
if ( (_DWORD)v4 != a3 || (result = 1LL, a4 != (_DWORD)v6) )
{
printf("\r\n dscp recd is %d msg type is %d\n", v4, v6);
result = 4294967290LL;
}
return result;
}

original_code:
int receiver(unsigned int *rmsg,int length,int tos,unsigned int type)
{
 int r=1;
 int new_dscp=rmsg[1];
 if((new_dscp != tos)||(rmsg[10] != type)) {
  printf("\r\n dscp recd is %d msg type is %d\n",new_dscp,rmsg[10]);
  r=-6;
 }
 return r;
}

canonical_original_code:
int receiver(unsigned int *rmsg, int length, int tos, unsigned int type)
{
 int r = 1;
 int new_dscp = rmsg[1];
 if((new_dscp != tos)||(rmsg[10] != type)) {
  printf("\r\n dscp recd is %d msg type is %d\n",new_dscp,rmsg[10]);
  r=-6;
 }
 return r;
}

variable_types: tos int

variable_types:
type
unsigned int

variable_types: r int


WfaRcvVO

decompiled_code:
__int64 __fastcall WfaRcvVO(__int64 a1, __int64 a2, _DWORD *a3)
{
int v4; // eax

v4 = receiver(a1, a2, 208, 34);
if ( v4 < 0 )
printf("\nBAD REC in VO%d\n", (unsigned int)v4);
else
++*a3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, _DWORD *a3)
{
int v4; // eax

v4 = func4(a1, a2, 208, 34);
if ( v4 < 0 )
printf("\nBAD REC in VO%d\n", (unsigned int)v4);
else
++*a3;
return 0LL;
}

original_code:
int WfaRcvVO(unsigned int *rmsg,int length,int *state)
{
    int r;
 if ((r=receiver(rmsg,length,0xD0,(33 + 0x01)))>=0)
        (*state)++;
    else
    {
        printf("\nBAD REC in VO%d\n",r);
    }
    return 0;
}

canonical_original_code:
int WfaRcvVO(unsigned int *rmsg, int length, int *state)
{
    int r;
 if ((r=receiver(rmsg,length,0xD0,(33 + 0x01)))>=0)
        (*state)++;
    else
    {
        printf("\nBAD REC in VO%d\n",r);
    }
    return 0;
}


WfaRcvVI

decompiled_code:
__int64 __fastcall WfaRcvVI(__int64 a1, __int64 a2, _DWORD *a3)
{
int v4; // eax

v4 = receiver(a1, a2, 160, 34);
if ( v4 < 0 )
printf("\nBAD REC in VI%d\n", (unsigned int)v4);
else
++*a3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, _DWORD *a3)
{
int v4; // eax

v4 = func4(a1, a2, 160, 34);
if ( v4 < 0 )
printf("\nBAD REC in VI%d\n", (unsigned int)v4);
else
++*a3;
return 0LL;
}

original_code:
int WfaRcvVI(unsigned int *rmsg,int length,int *state)
{
    int r;
    if ((r=receiver(rmsg,length,0xA0,(33 + 0x01)))>=0)
        (*state)++;
    else
        printf("\nBAD REC in VI%d\n",r);
    return 0;
}

canonical_original_code:
int WfaRcvVI(unsigned int *rmsg, int length, int *state)
{
    int r;
    if ((r=receiver(rmsg,length,0xA0,(33 + 0x01)))>=0)
        (*state)++;
    else
        printf("\nBAD REC in VI%d\n",r);
    return 0;
}


WfaRcvBE

decompiled_code:
__int64 __fastcall WfaRcvBE(__int64 a1, __int64 a2, _DWORD *a3)
{
int v4; // eax

v4 = receiver(a1, a2, 0, 34);
if ( v4 < 0 )
printf("\nBAD REC in BE%d\n", (unsigned int)v4);
else
++*a3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, _DWORD *a3)
{
int v4; // eax

v4 = func4(a1, a2, 0, 34);
if ( v4 < 0 )
printf("\nBAD REC in BE%d\n", (unsigned int)v4);
else
++*a3;
return 0LL;
}

original_code:
int WfaRcvBE(unsigned int *rmsg,int length,int *state)
{
    int r;
    if ((r=receiver(rmsg,length,0x00,(33 + 0x01)))>=0)
        (*state)++;
    else
    {
        printf("\nBAD REC in BE%d\n",r);
    }
    return 0;
}

canonical_original_code:
int WfaRcvBE(unsigned int *rmsg, int length, int *state)
{
    int r;
    if ((r=receiver(rmsg,length,0x00,(33 + 0x01)))>=0)
        (*state)++;
    else
    {
        printf("\nBAD REC in BE%d\n",r);
    }
    return 0;
}


WfaRcvBK

decompiled_code:
__int64 __fastcall WfaRcvBK(__int64 a1, __int64 a2, _DWORD *a3)
{
int v4; // eax

v4 = receiver(a1, a2, 32, 34);
if ( v4 < 0 )
printf("\nBAD REC in BK%d\n", (unsigned int)v4);
else
++*a3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2, _DWORD *a3)
{
int v4; // eax

v4 = func4(a1, a2, 32, 34);
if ( v4 < 0 )
printf("\nBAD REC in BK%d\n", (unsigned int)v4);
else
++*a3;
return 0LL;
}

original_code:
int WfaRcvBK(unsigned int *rmsg,int length,int *state)
{
    int r;
    if ((r=receiver(rmsg,length,0x20,(33 + 0x01)))>=0)
        (*state)++;
    else
        printf("\nBAD REC in BK%d\n",r);
    return 0;
}

canonical_original_code:
int WfaRcvBK(unsigned int *rmsg, int length, int *state)
{
    int r;
    if ((r=receiver(rmsg,length,0x20,(33 + 0x01)))>=0)
        (*state)++;
    else
        printf("\nBAD REC in BK%d\n",r);
    return 0;
}


WfaStaResetAll

decompiled_code:
int WfaStaResetAll()
{
int result; // eax
__int64 v1; // rdx
__int64 v2; // rdi

puts("Entering Reset");
if ( ++num_retry > 3 )
{
create_apts_msg(45, (__int64)&psTxMsg, wmmps_info[0]);
wfaTGSetPrio(psSockfd, 1LL);
wfaTrafficSendTo(psSockfd, &psTxMsg, msgsize, (unsigned int)((_DWORD)wmmps_info + 72));
mpx("STA msg", (__int64)&psTxMsg, 64);
puts("Too many retries");
exit(-8);
}
if ( reset_recd )
{
create_apts_msg(44, (__int64)&psTxMsg, wmmps_info[0]);
wfaTGSetPrio(psSockfd, 1LL);
wfaTrafficSendTo(psSockfd, &psTxMsg, msgsize, (unsigned int)((_DWORD)wmmps_info + 72));
result = mpx("STA msg", (__int64)&psTxMsg, 64);
reset_recd = 0;
}
else
{
create_apts_msg(43, (__int64)&psTxMsg, wmmps_info[0]);
wfaTGSetPrio(psSockfd, 1LL);
v1 = msgsize;
v2 = psSockfd;
*((_DWORD *)&psTxMsg + 1) = 0;
wfaTrafficSendTo(v2, &psTxMsg, v1, (unsigned int)((_DWORD)wmmps_info + 72));
result = mpx("STA msg", (__int64)&psTxMsg, 64);
}
resetsnd = 1;
resetrcv = 1;
return result;
}

canonical_decompiled_code:
int func9()
{
int result; // eax
__int64 v1; // rdx
__int64 v2; // rdi

puts("Entering Reset");
if ( ++num_retry > 3 )
{
func0(45, (__int64)&psTxMsg, wmmps_info[0]);
wfaTGSetPrio(psSockfd, 1LL);
wfaTrafficSendTo(psSockfd, &psTxMsg, msgsize, (unsigned int)((_DWORD)wmmps_info + 72));
func2("STA msg", (__int64)&psTxMsg, 64);
puts("Too many retries");
exit(-8);
}
if ( reset_recd )
{
func0(44, (__int64)&psTxMsg, wmmps_info[0]);
wfaTGSetPrio(psSockfd, 1LL);
wfaTrafficSendTo(psSockfd, &psTxMsg, msgsize, (unsigned int)((_DWORD)wmmps_info + 72));
result = func2("STA msg", (__int64)&psTxMsg, 64);
reset_recd = 0;
}
else
{
func0(43, (__int64)&psTxMsg, wmmps_info[0]);
wfaTGSetPrio(psSockfd, 1LL);
v1 = msgsize;
v2 = psSockfd;
*((_DWORD *)&psTxMsg + 1) = 0;
wfaTrafficSendTo(v2, &psTxMsg, v1, (unsigned int)((_DWORD)wmmps_info + 72));
result = func2("STA msg", (__int64)&psTxMsg, 64);
}
resetsnd = 1;
resetrcv = 1;
return result;
}

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


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

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

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

variable_types:
txbuf
unsigned long *

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


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

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

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

v1 = 0;
if ( a1 >= 0 )
v1 = wfaTGSetPrio(psSockfd, (unsigned int)a1);
*((_DWORD *)&psTxMsg + 1) = v1;
v2 = wmmps_info[9];
v3 = *((_DWORD *)&psTxMsg + 10) == 34;
*((_QWORD *)&psTxMsg + 1) = *(_QWORD *)&wmmps_info[1];
v4 = v2 + 1;
psTxMsg = v2;
*((_DWORD *)&psTxMsg + 4) = wmmps_info[0];
wmmps_info[9] = v2 + 1;
if ( v3 )
*((_DWORD *)&psTxMsg + 13) = v4 % 10 + 538976304;
result = wfaTrafficSendTo(psSockfd, &psTxMsg, (unsigned int)(v4 % 200 + 200), (unsigned int)((_DWORD)wmmps_info + 72));
++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] == (33 + 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:
__int64 __fastcall wfaSetDUTPwrMgmt(unsigned int a1)
{
__int64 result; // rax
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2[0] = a1;
if ( curr_mode_0 != a1 )
{
wl_set(g_wl_handle, 86LL, v2, 4LL);
result = v2[0];
curr_mode_0 = v2[0];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned int a1)
{
__int64 result; // rax
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2[0] = a1;
if ( curr_mode_0 != a1 )
{
wl_set(g_wl_handle, 86LL, v2, 4LL);
result = v2[0];
curr_mode_0 = v2[0];
}
return result;
}

original_code:
void wfaSetDUTPwrMgmt(int mode)
{
 static int curr_mode;
 if(curr_mode == mode)
 {
  return;
 }
 wl_set (g_wl_handle,86,&mode,sizeof(int));
 curr_mode = mode;
}

variable_types: mode int


wfaWmmPowerSaveProcess

decompiled_code:
__int64 __fastcall wfaWmmPowerSaveProcess(__int64 a1)
{
int v1; // er12
int v2; // eax
__int64 v3; // rcx
__int64 v4; // rsi
unsigned int v5; // er12
__int64 v7; // [rsp+0h] [rbp-18h] BYREF

v1 = WmmpsTrafficRecv(a1, psRxMsg, &v7);
if ( v1 >= 0 )
{
if ( wmmps_info[5] == 8 )
{
v2 = psRxMsg[10];
if ( v2 != 38 )
goto LABEL_4;
}
else
{
mpx("RX msg", (__int64)psRxMsg, 64);
v2 = psRxMsg[10];
if ( v2 != 38 )
goto LABEL_4;
}
puts("\r\n stop recd");
v2 = psRxMsg[10];
LABEL_4:
if ( v2 == 43 )
{
reset_recd = 1;
v5 = 0;
WfaStaResetAll();
return v5;
}
if ( resetrcv )
{
wmmps_info[11] = 0;
if ( !reset_recd && v2 != 44 )
return 0;
resetrcv = 0;
v3 = 0LL;
reset_recd = 0;
}
else
{
v3 = 8LL * (int)wmmps_info[11];
}
v4 = (unsigned int)v1;
v5 = 1;
wmmps_info[2] = psRxMsg[0];
(*(void (__fastcall **)(_DWORD *, __int64, _QWORD))((char *)&stationRecvProcStatetbl + 48 * wmmps_info[5] + v3))(
psRxMsg,
v4,
(unsigned int)((_DWORD)wmmps_info + 44));
return v5;
}
p_error("receive error");
return (unsigned int)v1;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
int v1; // er12
int v2; // eax
__int64 v3; // rcx
__int64 v4; // rsi
unsigned int v5; // er12
__int64 v7; // [rsp+0h] [rbp-18h] BYREF

v1 = WmmpsTrafficRecv(a1, psRxMsg, &v7);
if ( v1 >= 0 )
{
if ( wmmps_info[5] == 8 )
{
v2 = psRxMsg[10];
if ( v2 != 38 )
goto LABEL_4;
}
else
{
func2("RX msg", (__int64)psRxMsg, 64);
v2 = psRxMsg[10];
if ( v2 != 38 )
goto LABEL_4;
}
puts("\r\n stop recd");
v2 = psRxMsg[10];
LABEL_4:
if ( v2 == 43 )
{
reset_recd = 1;
v5 = 0;
func9();
return v5;
}
if ( resetrcv )
{
wmmps_info[11] = 0;
if ( !reset_recd && v2 != 44 )
return 0;
resetrcv = 0;
v3 = 0LL;
reset_recd = 0;
}
else
{
v3 = 8LL * (int)wmmps_info[11];
}
v4 = (unsigned int)v1;
v5 = 1;
wmmps_info[2] = psRxMsg[0];
(*(void (__fastcall **)(_DWORD *, __int64, _QWORD))((char *)&stationRecvProcStatetbl + 48 * wmmps_info[5] + v3))(
psRxMsg,
v4,
(unsigned int)((_DWORD)wmmps_info + 44));
return v5;
}
p_error("receive error");
return (unsigned int)v1;
}

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 = WmmpsTrafficRecv(sockfd,(char *)psRxMsg, (struct sockaddr *)&from);
 if(rbytes < 0)
 {
  p_error("receive error");
  return rbytes;
 }
 sta_test = wmmps_info.sta_test;
 if(sta_test != 8)
  mpx("RX msg",psRxMsg,64);
 if(psRxMsg[10] == (((((33 + 0x01) + 0x01) + 0x01) + 0x01) + 0x01))
  printf("\r\n stop recd\n");
 if(psRxMsg[10] == ((((((((((33 + 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] != (((((((((((33 + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01)))
   return 0;
  else
  {
   resetrcv = 0;
   reset_recd = 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 1;
}

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 = WmmpsTrafficRecv(sockfd,(char *)psRxMsg, (struct sockaddr *)&from);
 if(rbytes < 0)
 {
  p_error("receive error");
  return rbytes;
 }
 sta_test = wmmps_info.sta_test;
 if(sta_test != 8)
  mpx("RX msg",psRxMsg,64);
 if(psRxMsg[10] == (((((33 + 0x01) + 0x01) + 0x01) + 0x01) + 0x01))
  printf("\r\n stop recd\n");
 if(psRxMsg[10] == ((((((((((33 + 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] != (((((((((((33 + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01) + 0x01)))
   return 0;
  else
  {
   resetrcv = 0;
   reset_recd = 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 1;
}

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


decompiled_code:
int wmmps_wait_state_proc()
{
int result; // eax
__int64 v1; // rdx
__int64 v2; // rax
unsigned int v3; // ebp
unsigned int *v4; // rbx
int v5; // ecx
_BYTE v6[12]; // [rsp+0h] [rbp-28h] BYREF
int v7; // [rsp+Ch] [rbp-1Ch]

*(_QWORD *)&v6[4] = 0xFF000000FFLL;
v7 = 255;
result = wmmps_info[6];
switch ( result )
{
case 0:
v3 = -1;
goto LABEL_10;
case 1:
wmmps_info[6] = 0;
return result;
case 2:
result = wfaTrafficSendTo(
psSockfd,
&psTxMsg,
(unsigned int)(wmmps_info[9] % 200 + 200),
(unsigned int)((_DWORD)wmmps_info + 72));
wmmps_info[7] = 1000000;
return result;
case 4:
wmmps_info[7] = 1000000;
return result;
case 6:
*(_DWORD *)&v6[4] = 208;
v3 = 0;
goto LABEL_10;
case 7:
*(_DWORD *)&v6[4] = 208;
v3 = 208;
goto LABEL_10;
case 8:
v3 = 208;
goto LABEL_10;
case 9:
v1 = (int)wmmps_info[8];
if ( (unsigned int)v1 > 0x18 )
{
v2 = (int)wmmps_info[5];
wmmps_info[8] = 0;
if ( (_DWORD)v2 != 9 )
{
v1 = 0LL;
if ( (_DWORD)v2 != 14 )
goto LABEL_19;
goto LABEL_5;
}
v1 = 0LL;
goto LABEL_27;
}
v5 = wmmps_info[5];
v2 = v5;
if ( v5 == 9 )
{
if ( (_DWORD)v1 != 3 )
goto LABEL_28;
}
else
{
if ( v5 != 14 )
goto LABEL_19;
if ( (v1 & 0xFFFFFFFD) != 1 && (_DWORD)v1 != 5 )
{
LABEL_24:
if ( (((_DWORD)v1 - 2) & 0xFFFFFFFD) != 0 )
{
LABEL_5:
v2 = 14LL;
goto LABEL_19;
}
goto LABEL_25;
}
}
wfaSetDUTPwrMgmt(0);
v2 = (int)wmmps_info[5];
wmmps_info[7] = 100000;
v1 = (int)wmmps_info[8];
if ( (_DWORD)v2 != 9 )
{
if ( (_DWORD)v2 != 14 )
goto LABEL_19;
goto LABEL_24;
}
LABEL_28:
if ( (_DWORD)v1 == 4 )
{
LABEL_25:
wfaSetDUTPwrMgmt(1u);
v2 = (int)wmmps_info[5];
wmmps_info[7] = 100000;
v1 = (int)wmmps_info[8];
goto LABEL_19;
}
LABEL_27:
v2 = 9LL;
LABEL_19:
v3 = ac_seq[6 * v2 + v1];
result = printf("ttypes 0x%x\n", v3);
wmmps_info[7] = 1000000;
if ( v3 != 255 )
{
LABEL_10:
v4 = (unsigned int *)v6;
do
{
++v4;
result = send_txmsg(v3);
v3 = *v4;
}
while ( *v4 != 255 );
}
return result;
default:
return puts("unknown wait state");
}
}

canonical_decompiled_code:
int func14()
{
int result; // eax
__int64 v1; // rdx
__int64 v2; // rax
unsigned int v3; // ebp
unsigned int *v4; // rbx
int v5; // ecx
_BYTE v6[12]; // [rsp+0h] [rbp-28h] BYREF
int v7; // [rsp+Ch] [rbp-1Ch]

*(_QWORD *)&v6[4] = 0xFF000000FFLL;
v7 = 255;
result = wmmps_info[6];
switch ( result )
{
case 0:
v3 = -1;
goto LABEL_10;
case 1:
wmmps_info[6] = 0;
return result;
case 2:
result = wfaTrafficSendTo(
psSockfd,
&psTxMsg,
(unsigned int)(wmmps_info[9] % 200 + 200),
(unsigned int)((_DWORD)wmmps_info + 72));
wmmps_info[7] = 1000000;
return result;
case 4:
wmmps_info[7] = 1000000;
return result;
case 6:
*(_DWORD *)&v6[4] = 208;
v3 = 0;
goto LABEL_10;
case 7:
*(_DWORD *)&v6[4] = 208;
v3 = 208;
goto LABEL_10;
case 8:
v3 = 208;
goto LABEL_10;
case 9:
v1 = (int)wmmps_info[8];
if ( (unsigned int)v1 > 0x18 )
{
v2 = (int)wmmps_info[5];
wmmps_info[8] = 0;
if ( (_DWORD)v2 != 9 )
{
v1 = 0LL;
if ( (_DWORD)v2 != 14 )
goto LABEL_19;
goto LABEL_5;
}
v1 = 0LL;
goto LABEL_27;
}
v5 = wmmps_info[5];
v2 = v5;
if ( v5 == 9 )
{
if ( (_DWORD)v1 != 3 )
goto LABEL_28;
}
else
{
if ( v5 != 14 )
goto LABEL_19;
if ( (v1 & 0xFFFFFFFD) != 1 && (_DWORD)v1 != 5 )
{
LABEL_24:
if ( (((_DWORD)v1 - 2) & 0xFFFFFFFD) != 0 )
{
LABEL_5:
v2 = 14LL;
goto LABEL_19;
}
goto LABEL_25;
}
}
func12(0);
v2 = (int)wmmps_info[5];
wmmps_info[7] = 100000;
v1 = (int)wmmps_info[8];
if ( (_DWORD)v2 != 9 )
{
if ( (_DWORD)v2 != 14 )
goto LABEL_19;
goto LABEL_24;
}
LABEL_28:
if ( (_DWORD)v1 == 4 )
{
LABEL_25:
func12(1u);
v2 = (int)wmmps_info[5];
wmmps_info[7] = 100000;
v1 = (int)wmmps_info[8];
goto LABEL_19;
}
LABEL_27:
v2 = 9LL;
LABEL_19:
v3 = ac_seq[6 * v2 + v1];
result = printf("ttypes 0x%x\n", v3);
wmmps_info[7] = 1000000;
if ( v3 != 255 )
{
LABEL_10:
v4 = (unsigned int *)v6;
do
{
++v4;
result = func11(v3);
v3 = *v4;
}
while ( *v4 != 255 );
}
return result;
default:
return puts("unknown wait state");
}
}

original_code:
void wmmps_wait_state_proc()
{
 int ttypes[4], i, rbytes;
 for(i = 0; i<4; i++)
 {
  ttypes[i] = 0xFF;
 }
 switch(wmmps_info.wait_state)
 {
 case WFA_WAIT_NEXT_CODEC:
  ttypes[0] = -1;
  wmmps_info.wait_state = WFA_WAIT_NEXT_CODEC;
  break;
 case WFA_WAIT_FOR_AP_RESPONSE:
  wmmps_info.wait_state = WFA_WAIT_NEXT_CODEC;
  break;
 case WFA_WAIT_STAUT_00:
  rbytes = wfaTrafficSendTo(psSockfd, (char *)psTxMsg, 200+(wmmps_info.msgno%200), (struct sockaddr *)&wmmps_info.psToAddr);
  wmmps_info.nextsleep = 1000000;
  break;
 case WFA_WAIT_STAUT_02:
  ttypes[0] = 0xD0;
  wmmps_info.nextsleep = 1000000;
  return;
  break;
 case WFA_WAIT_STAUT_04:
  ttypes[0] = 0x00;
  ttypes[1] = 0xD0;
  break;
 case WFA_WAIT_STAUT_0E:
  ttypes[0] = 0xD0;
  ttypes[1] = 0xD0;
  break;
 case WFA_WAIT_STAUT_VOLOAD:
  ttypes[0] = 0xD0;
  break;
 case WFA_WAIT_STAUT_SEQ:
  if( wmmps_info.nsent < 0 || wmmps_info.nsent > sizeof(ac_seq[wmmps_info.sta_test]) )
   wmmps_info.nsent = 0;
  if(( wmmps_info.sta_test == 9 && wmmps_info.nsent == 3)
   || (wmmps_info.sta_test == 14 && wmmps_info.nsent == 1)
   || (wmmps_info.sta_test == 14 && wmmps_info.nsent == 3)
   || (wmmps_info.sta_test == 14 && wmmps_info.nsent == 5))
  {
   wfaSetDUTPwrMgmt(0);
   wmmps_info.nextsleep = 100000;
  }
  if((wmmps_info.sta_test == 9 && wmmps_info.nsent == 4)
   || (wmmps_info.sta_test == 14 && wmmps_info.nsent == 2)
   || (wmmps_info.sta_test == 14 && wmmps_info.nsent == 4))
  {
   wfaSetDUTPwrMgmt(1);
   wmmps_info.nextsleep = 100000;
  }
  ttypes[0] = ac_seq[wmmps_info.sta_test][wmmps_info.nsent];
  printf("ttypes 0x%x\n", ttypes[0]);
  wmmps_info.nextsleep = 1000000;
  break;
 default:
  printf("unknown wait state\n");
 }
 i=0;
 while(ttypes[i] != 0xFF)
  send_txmsg(ttypes[i++]);
}

canonical_original_code:
void wmmps_wait_state_proc()
{
 int ttypes[4]; int i; int rbytes;
 for(i = 0; i<4; i++)
 {
  ttypes[i] = 0xFF;
 }
 switch(wmmps_info.wait_state)
 {
 case WFA_WAIT_NEXT_CODEC:
  ttypes[0] = -1;
  wmmps_info.wait_state = WFA_WAIT_NEXT_CODEC;
  break;
 case WFA_WAIT_FOR_AP_RESPONSE:
  wmmps_info.wait_state = WFA_WAIT_NEXT_CODEC;
  break;
 case WFA_WAIT_STAUT_00:
  rbytes = wfaTrafficSendTo(psSockfd, (char *)psTxMsg, 200+(wmmps_info.msgno%200), (struct sockaddr *)&wmmps_info.psToAddr);
  wmmps_info.nextsleep = 1000000;
  break;
 case WFA_WAIT_STAUT_02:
  ttypes[0] = 0xD0;
  wmmps_info.nextsleep = 1000000;
  return;
  break;
 case WFA_WAIT_STAUT_04:
  ttypes[0] = 0x00;
  ttypes[1] = 0xD0;
  break;
 case WFA_WAIT_STAUT_0E:
  ttypes[0] = 0xD0;
  ttypes[1] = 0xD0;
  break;
 case WFA_WAIT_STAUT_VOLOAD:
  ttypes[0] = 0xD0;
  break;
 case WFA_WAIT_STAUT_SEQ:
  if( wmmps_info.nsent < 0 || wmmps_info.nsent > sizeof(ac_seq[wmmps_info.sta_test]) )
   wmmps_info.nsent = 0;
  if(( wmmps_info.sta_test == 9 && wmmps_info.nsent == 3)
   || (wmmps_info.sta_test == 14 && wmmps_info.nsent == 1)
   || (wmmps_info.sta_test == 14 && wmmps_info.nsent == 3)
   || (wmmps_info.sta_test == 14 && wmmps_info.nsent == 5))
  {
   wfaSetDUTPwrMgmt(0);
   wmmps_info.nextsleep = 100000;
  }
  if((wmmps_info.sta_test == 9 && wmmps_info.nsent == 4)
   || (wmmps_info.sta_test == 14 && wmmps_info.nsent == 2)
   || (wmmps_info.sta_test == 14 && wmmps_info.nsent == 4))
  {
   wfaSetDUTPwrMgmt(1);
   wmmps_info.nextsleep = 100000;
  }
  ttypes[0] = ac_seq[wmmps_info.sta_test][wmmps_info.nsent];
  printf("ttypes 0x%x\n", ttypes[0]);
  wmmps_info.nextsleep = 1000000;
  break;
 default:
  printf("unknown wait state\n");
 }
 i=0;
 while(ttypes[i] != 0xFF)
  send_txmsg(ttypes[i++]);
}

variable_types:
ttypes
int [4]


wfaTGSetPrio

decompiled_code:
__int64 __fastcall wfaTGSetPrio(__int64 a1, int a2)
{
int v2; // eax
__int64 result; // rax
unsigned int v4; // [rsp+8h] [rbp-20h] BYREF
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v5[0] = 4;
wfaGetSockOpt(a1, &v4, v5);
if ( a2 == 4 )
{
v4 = 192;
v2 = 192;
}
else
{
if ( a2 > 4 )
{
if ( a2 == 5 )
{
v4 = 136;
v2 = 136;
goto LABEL_6;
}
goto LABEL_13;
}
if ( a2 != 2 )
{
if ( a2 == 3 )
{
v4 = 160;
v2 = 160;
goto LABEL_6;
}
LABEL_13:
v4 = 0;
v2 = 0;
goto LABEL_6;
}
v4 = 32;
v2 = 32;
}
LABEL_6:
psTxMsg[1] = v2;
if ( (unsigned int)wfaSetSockOpt((unsigned int)a1, &v4, 4LL) )
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_thr.c", 186LL);
fwrite("Failed to set IP_TOS\n", 1uLL, 0x15uLL, stderr);
}
result = v4;
if ( v4 == 224 )
result = 216LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
int v2; // eax
__int64 result; // rax
unsigned int v4; // [rsp+8h] [rbp-20h] BYREF
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v5[0] = 4;
wfaGetSockOpt(a1, &v4, v5);
if ( a2 == 4 )
{
v4 = 192;
v2 = 192;
}
else
{
if ( a2 > 4 )
{
if ( a2 == 5 )
{
v4 = 136;
v2 = 136;
goto LABEL_6;
}
goto LABEL_13;
}
if ( a2 != 2 )
{
if ( a2 == 3 )
{
v4 = 160;
v2 = 160;
goto LABEL_6;
}
LABEL_13:
v4 = 0;
v2 = 0;
goto LABEL_6;
}
v4 = 32;
v2 = 32;
}
LABEL_6:
psTxMsg[1] = v2;
if ( (unsigned int)wfaSetSockOpt((unsigned int)a1, &v4, 4LL) )
{
fprintf(stderr, "File %s, Line %ld: ", "wfa_thr.c", 186LL);
fwrite("Failed to set IP_TOS\n", 1uLL, 0x15uLL, stderr);
}
result = v4;
if ( v4 == 224 )
result = 216LL;
return result;
}

original_code:
int wfaTGSetPrio(int sockfd, int tgClass)
{
 int tosval;
 socklen_t size = sizeof(tosval);
 wfaGetSockOpt(sockfd, &tosval, &size);
 switch(tgClass)
 {
 case 2:
  tosval = 0x20;
  break;
 case 3:
  tosval = 0xA0;
  break;
 case 5:
  tosval = 0x88;
  break;
 case 4:
  tosval = 0xC0;
  break;
 case 1:
  tosval = 0x00;
 default:
  tosval = 0x00;
  ;
 }
 psTxMsg[1] = tosval;
 if(wfaSetSockOpt(sockfd, &tosval, sizeof(tosval)) != 0)
 {
  fprintf(stderr, "File %s, Line %ld: ", "wfa_thr.c", (long)186); fprintf(stderr, "Failed to set IP_TOS\n");
 }
 return (tosval == 0xE0)?0xD8:tosval;
}

canonical_original_code:
int wfaTGSetPrio(int sockfd, int tgClass)
{
 int tosval;
 unsigned int size = sizeof(tosval);
 wfaGetSockOpt(sockfd, &tosval, &size);
 switch(tgClass)
 {
 case 2:
  tosval = 0x20;
  break;
 case 3:
  tosval = 0xA0;
  break;
 case 5:
  tosval = 0x88;
  break;
 case 4:
  tosval = 0xC0;
  break;
 case 1:
  tosval = 0x00;
 default:
  tosval = 0x00;
  ;
 }
 psTxMsg[1] = tosval;
 if(wfaSetSockOpt(sockfd, &tosval, sizeof(tosval)) != 0)
 {
  fprintf(stderr, "File %s, Line %ld: ", "wfa_thr.c", (long)186); fprintf(stderr, "Failed to set IP_TOS\n");
 }
 return (tosval == 0xE0)?0xD8:tosval;
}

variable_types: tgClass int

variable_types: tosval int

variable_types:
size
unsigned int


sender

decompiled_code:
__int64 __fastcall sender(char a1, __int64 a2, unsigned int a3)
{
printf("\nsleeping for %d", a2);
wfaSetDUTPwrMgmt((unsigned int)a1);
uapsd_sleep((unsigned int)a2);
printf("\nAfter create sending %d\n", a3);
create_apts_msg(34LL, psTxMsg, wmmps_info);
wfaTGSetPrio(psSockfd, a3);
printf("\nAfter create");
printf("\nlock met");
return wfaTrafficSendTo(psSockfd, psTxMsg, (unsigned int)msgsize, (unsigned int)((_DWORD)&wmmps_info + 72));
}

canonical_decompiled_code:
__int64 __fastcall func1(char a1, __int64 a2, unsigned int a3)
{
printf("\nsleeping for %d", a2);
wfaSetDUTPwrMgmt((unsigned int)a1);
uapsd_sleep((unsigned int)a2);
printf("\nAfter create sending %d\n", a3);
create_apts_msg(34LL, psTxMsg, wmmps_info);
func0(psSockfd, a3);
printf("\nAfter create");
printf("\nlock met");
return wfaTrafficSendTo(psSockfd, psTxMsg, (unsigned int)msgsize, (unsigned int)((_DWORD)&wmmps_info + 72));
}

original_code:
int sender(char psave,int sleep_period,int dsc)
{
   int r;
   printf("\nsleeping for %d",sleep_period);
   wfaSetDUTPwrMgmt(psave);
   uapsd_sleep(sleep_period);
   printf("\nAfter create sending %d\n",dsc);
   create_apts_msg((33 + 0x01), psTxMsg,wmmps_info.my_sta_id);
   wfaTGSetPrio(psSockfd, dsc);
   printf("\nAfter create");
   printf("\nlock met");
   r = wfaTrafficSendTo(psSockfd, (char *)psTxMsg, msgsize, (struct sockaddr *)&wmmps_info.psToAddr);
   return r;
}

canonical_original_code:
int sender(char psave, int sleep_period, int dsc)
{
   int r;
   printf("\nsleeping for %d",sleep_period);
   wfaSetDUTPwrMgmt(psave);
   uapsd_sleep(sleep_period);
   printf("\nAfter create sending %d\n",dsc);
   create_apts_msg((33 + 0x01), psTxMsg,wmmps_info.my_sta_id);
   wfaTGSetPrio(psSockfd, dsc);
   printf("\nAfter create");
   printf("\nlock met");
   r = wfaTrafficSendTo(psSockfd, (char *)psTxMsg, msgsize, (struct sockaddr *)&wmmps_info.psToAddr);
   return r;
}

variable_types: psave char

variable_types: dsc int


WfaStaSndConfirm

decompiled_code:
__int64 __fastcall WfaStaSndConfirm(char a1, __int64 a2, _DWORD *a3)
{
wfaSetDUTPwrMgmt((unsigned int)a1);
create_apts_msg(37LL, psTxMsg, 0LL);
wfaTrafficSendTo(psSockfd, psTxMsg, (unsigned int)msgsize, (unsigned int)((_DWORD)&wmmps_info + 72));
++*a3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(char a1, __int64 a2, _DWORD *a3)
{
wfaSetDUTPwrMgmt((unsigned int)a1);
create_apts_msg(37LL, psTxMsg, 0LL);
wfaTrafficSendTo(psSockfd, psTxMsg, (unsigned int)msgsize, (unsigned int)((_DWORD)&wmmps_info + 72));
++*a3;
return 0LL;
}

original_code:
int WfaStaSndConfirm(char psave,int sleep_period,int *state)
{
   int r;
   static int num_hello=0;
   wfaSetDUTPwrMgmt(psave);
   if(!num_hello)
      create_apts_msg(((((33 + 0x01) + 0x01) + 0x01) + 0x01), psTxMsg,0);
   r = wfaTrafficSendTo(psSockfd, (char *)psTxMsg, msgsize, (struct sockaddr *)&wmmps_info.psToAddr);
   (*state)++;
   return 0;
}

canonical_original_code:
int WfaStaSndConfirm(char psave, int sleep_period, int *state)
{
   int r;
   static int num_hello = 0;
   wfaSetDUTPwrMgmt(psave);
   if(!num_hello)
      create_apts_msg(((((33 + 0x01) + 0x01) + 0x01) + 0x01), psTxMsg,0);
   r = wfaTrafficSendTo(psSockfd, (char *)psTxMsg, msgsize, (struct sockaddr *)&wmmps_info.psToAddr);
   (*state)++;
   return 0;
}

variable_types:
state
int *


WfaStaSndVO

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

v4 = (unsigned int)en_5++;
printf("\r\nEnterring WfastasndVO %d", v4);
if ( (int)sender(a1, a2, 4u) < 0 )
puts("\r\nError");
else
++*a3;
return 0LL;
}

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

v4 = (unsigned int)en_5++;
printf("\r\nEnterring WfastasndVO %d", v4);
if ( (int)func1(a1, a2, 4u) < 0 )
puts("\r\nError");
else
++*a3;
return 0LL;
}

original_code:
int WfaStaSndVO(char psave,int sleep_period,int *state)
{
   int r;
   static int en=1;
   printf("\r\nEnterring WfastasndVO %d",en++);
   if ((r=sender(psave,sleep_period,4))>=0)
      (*state)++;
   else
      printf("\r\nError\n");
   return 0;
}

canonical_original_code:
int WfaStaSndVO(char psave, int sleep_period, int *state)
{
   int r;
   static int en = 1;
   printf("\r\nEnterring WfastasndVO %d",en++);
   if ((r=sender(psave,sleep_period,4))>=0)
      (*state)++;
   else
      printf("\r\nError\n");
   return 0;
}

variable_types: en int


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

v4 = (unsigned int)en_4++;
printf("\r\nEnterring WfastasndVO %d", v4);
if ( (int)sender(a1, a2, 4u) < 0 )
{
puts("\r\nError");
}
else
{
wfaTrafficSendTo(psSockfd, psTxMsg, (unsigned int)msgsize, (unsigned int)((_DWORD)&wmmps_info + 72));
mpx("STA msg", psTxMsg, 64LL);
++*a3;
}
return 0LL;
}

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

v4 = (unsigned int)en_4++;
printf("\r\nEnterring WfastasndVO %d", v4);
if ( (int)func1(a1, a2, 4u) < 0 )
{
puts("\r\nError");
}
else
{
wfaTrafficSendTo(psSockfd, psTxMsg, (unsigned int)msgsize, (unsigned int)((_DWORD)&wmmps_info + 72));
mpx("STA msg", psTxMsg, 64LL);
++*a3;
}
return 0LL;
}

original_code:
int WfaStaSnd2VO(char psave,int sleep_period,int *state)
{
   int r;
   static int en=1;
   printf("\r\nEnterring WfastasndVO %d",en++);
   if ((r=sender(psave,sleep_period,4))>=0)
   {
    r = wfaTrafficSendTo(psSockfd, (char *)psTxMsg, msgsize, (struct sockaddr *)&wmmps_info.psToAddr);
       mpx("STA msg",psTxMsg,64);
       (*state)++;
   }
   else
      printf("\r\nError\n");
   return 0;
}

canonical_original_code:
int WfaStaSnd2VO(char psave, int sleep_period, int *state)
{
   int r;
   static int en = 1;
   printf("\r\nEnterring WfastasndVO %d",en++);
   if ((r=sender(psave,sleep_period,4))>=0)
   {
    r = wfaTrafficSendTo(psSockfd, (char *)psTxMsg, msgsize, (struct sockaddr *)&wmmps_info.psToAddr);
       mpx("STA msg",psTxMsg,64);
       (*state)++;
   }
   else
      printf("\r\nError\n");
   return 0;
}


WfaStaSndVI

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

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

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

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

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

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


WfaStaSndBE

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

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

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

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

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

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


WfaStaSndBK

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

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

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

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

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

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


WfaStaSndVOCyclic

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

for ( i = 0; i != 3000; ++i )
{
while ( 1 )
{
v6 = (unsigned int)en_0++;
printf("\r\nEnterring WfastasndVOCyclic %d", v6);
sender(a1, a2, 4u);
if ( __ROR4__(-1030792151 * i, 1) <= 0x51EB851u )
break;
if ( ++i == 3000 )
goto LABEL_5;
}
putchar(46);
fflush(stdout);
}
LABEL_5:
++*a3;
return 0LL;
}

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

for ( i = 0; i != 3000; ++i )
{
while ( 1 )
{
v6 = (unsigned int)en_0++;
printf("\r\nEnterring WfastasndVOCyclic %d", v6);
func1(a1, a2, 4u);
if ( __ROR4__(-1030792151 * i, 1) <= 0x51EB851u )
break;
if ( ++i == 3000 )
goto LABEL_5;
}
putchar(46);
fflush(stdout);
}
LABEL_5:
++*a3;
return 0LL;
}

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

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

variable_types: i int


decompiled_code:
// attributes: thunk
unsigned int asd_sleep(unsigned int seconds)
{
return sleep(seconds);
}

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

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

variable_types: SleepTime int


decompiled_code:
// attributes: thunk
int uapsd_sleep(__useconds_t useconds)
{
return usleep(useconds);
}

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

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


decompiled_code:
// attributes: thunk
int asd_closeSocket(int fd)
{
return close(fd);
}

canonical_decompiled_code:
int func2(int fd)
{
return close(fd);
}

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


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

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

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

variable_types: Sockfd int


decompiled_code:
// attributes: thunk
int exec_process(const char *command)
{
return system(command);
}

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

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

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

variable_types:
command
char *


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

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

original_code:
int
Start_Socket_Service()
{
 return 0;
}


decompiled_code:
__int64 Stop_Socket_Service()
{
return Start_Socket_Service();
}

canonical_decompiled_code:
__int64 func6()
{
return func5();
}

original_code:
int
Stop_Socket_Service()
{
 return 0;
}

canonical_original_code:
int Stop_Socket_Service()
{
 return 0;
}


wfaGetSockOpt

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

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

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

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

variable_types:
tosval
int *

variable_types:
size
unsigned int *


wfaSetSockOpt

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

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

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

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

variable_types: sockfd int

variable_types: size int

variable_types: sockOpt int


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 func9()
{
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


GetWirelessAdapter

decompiled_code:
void __fastcall GetWirelessAdapter(char *dest)
{
int v1; // eax
int v2; // er12
char *v3; // rbp
unsigned __int64 v4; // rdx
char *v5; // rbx
int v6; // [rsp+0h] [rbp-5C8h] BYREF
char *src; // [rsp+8h] [rbp-5C0h]
struct utsname name; // [rsp+10h] [rbp-5B8h] BYREF
char v9; // [rsp+1A0h] [rbp-428h] BYREF

uname(&name);
if ( *(_DWORD *)name.machine != 909652841 || name.machine[4] )
{
if ( *(_DWORD *)name.machine == 909653609 )
{
if ( !name.machine[4] )
goto LABEL_6;
}
else if ( *(_DWORD *)name.machine == 909653353 && !name.machine[4] )
{
goto LABEL_6;
}
*(_QWORD *)dest = 828929125LL;
*((_DWORD *)dest + 2) = 0;
*((_WORD *)dest + 6) = 0;
dest[14] = 0;
return;
}
LABEL_6:
v1 = socket(2, 2, 0);
v2 = v1;
if ( v1 < 0 )
{
perror("socket");
}
else
{
src = &v9;
v6 = 1024;
if ( ioctl(v1, 0x8912uLL, &v6) < 0 )
{
perror("ioctl(SIOCGIFCONF)");
close(v2);
}
else
{
v3 = src;
v4 = v6 / 0x28uLL;
if ( (int)v4 <= 0 )
{
LABEL_13:
close(v2);
}
else
{
v5 = &src[40 * (unsigned int)(v4 - 1) + 40];
while ( ioctl(v2, 0x8B01uLL, v3) )
{
v3 += 40;
if ( v3 == v5 )
goto LABEL_13;
}
strncpy(dest, v3, 0x10uLL);
close(v2);
}
}
}
}

canonical_decompiled_code:
void __fastcall func10(char *dest)
{
int v1; // eax
int v2; // er12
char *v3; // rbp
unsigned __int64 v4; // rdx
char *v5; // rbx
int v6; // [rsp+0h] [rbp-5C8h] BYREF
char *src; // [rsp+8h] [rbp-5C0h]
struct utsname name; // [rsp+10h] [rbp-5B8h] BYREF
char v9; // [rsp+1A0h] [rbp-428h] BYREF

uname(&name);
if ( *(_DWORD *)name.machine != 909652841 || name.machine[4] )
{
if ( *(_DWORD *)name.machine == 909653609 )
{
if ( !name.machine[4] )
goto LABEL_6;
}
else if ( *(_DWORD *)name.machine == 909653353 && !name.machine[4] )
{
goto LABEL_6;
}
*(_QWORD *)dest = 828929125LL;
*((_DWORD *)dest + 2) = 0;
*((_WORD *)dest + 6) = 0;
dest[14] = 0;
return;
}
LABEL_6:
v1 = socket(2, 2, 0);
v2 = v1;
if ( v1 < 0 )
{
perror("socket");
}
else
{
src = &v9;
v6 = 1024;
if ( ioctl(v1, 0x8912uLL, &v6) < 0 )
{
perror("ioctl(SIOCGIFCONF)");
close(v2);
}
else
{
v3 = src;
v4 = v6 / 0x28uLL;
if ( (int)v4 <= 0 )
{
LABEL_13:
close(v2);
}
else
{
v5 = &src[40 * (unsigned int)(v4 - 1) + 40];
while ( ioctl(v2, 0x8B01uLL, v3) )
{
v3 += 40;
if ( v3 == v5 )
goto LABEL_13;
}
strncpy(dest, v3, 0x10uLL);
close(v2);
}
}
}
}

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

variable_types:
buf
char [1024]

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

variable_types: sck int

variable_types: nInterfaces int

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

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

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

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


decompiled_code:
// attributes: thunk
void p_error(const char *s)
{
perror(s);
}

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

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

variable_types:
errorString
char *


wfaEncodeTLV

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

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

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

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

variable_types:
data
void *

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