main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int16 v3; // r12
int v4; // er15
__int64 v5; // r14
FILE *v6; // rdi
int v7; // ebx
char *v8; // rax
const char *v9; // rbx
int *v10; // rax
int *v11; // rax
__int64 v12; // rdx
int v13; // eax
int v14; // edi
int v15; // eax
unsigned int v16; // edx
int v17; // ebx
size_t v18; // rax
int v19; // ebx
const __m128i *v20; // rax
unsigned __int64 v21; // rbx
int v22; // ebp
size_t v23; // rax
int v24; // eax
int *v25; // rax
int *v26; // rax
size_t v27; // rax
ssize_t v28; // rax
int v29; // eax
unsigned int v30; // ebx
void (__fastcall *v31)(__int16 *); // rax
const char *cp; // [rsp+0h] [rbp-2718h]
signed int v34; // [rsp+8h] [rbp-2710h]
__int16 v35; // [rsp+Eh] [rbp-270Ah]
char s[520]; // [rsp+10h] [rbp-2708h] BYREF
char *save_ptr; // [rsp+218h] [rbp-2500h] BYREF
char buf[1024]; // [rsp+220h] [rbp-24F8h] BYREF
__int16 v39[2048]; // [rsp+620h] [rbp-20F8h] BYREF
char v40[4108]; // [rsp+1620h] [rbp-10F8h] BYREF
int v41; // [rsp+262Ch] [rbp-ECh] BYREF
char s2[16]; // [rsp+2630h] [rbp-E8h] BYREF
__m128i v43; // [rsp+2640h] [rbp-D8h]
fd_set readfds; // [rsp+2650h] [rbp-C8h] BYREF
struct sockaddr addr; // [rsp+26D0h] [rbp-48h] BYREF

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

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int16 v3; // r12
int v4; // er15
__int64 v5; // r14
FILE *v6; // rdi
int v7; // ebx
char *v8; // rax
const char *v9; // rbx
int *v10; // rax
int *v11; // rax
__int64 v12; // rdx
int v13; // eax
int v14; // edi
int v15; // eax
unsigned int v16; // edx
int v17; // ebx
size_t v18; // rax
int v19; // ebx
const __m128i *v20; // rax
unsigned __int64 v21; // rbx
int v22; // ebp
size_t v23; // rax
int v24; // eax
int *v25; // rax
int *v26; // rax
size_t v27; // rax
ssize_t v28; // rax
int v29; // eax
unsigned int v30; // ebx
void (__fastcall *v31)(__int16 *); // rax
const char *cp; // [rsp+0h] [rbp-2718h]
signed int v34; // [rsp+8h] [rbp-2710h]
__int16 v35; // [rsp+Eh] [rbp-270Ah]
char s[520]; // [rsp+10h] [rbp-2708h] BYREF
char *save_ptr; // [rsp+218h] [rbp-2500h] BYREF
char buf[1024]; // [rsp+220h] [rbp-24F8h] BYREF
__int16 v39[2048]; // [rsp+620h] [rbp-20F8h] BYREF
char v40[4108]; // [rsp+1620h] [rbp-10F8h] BYREF
int v41; // [rsp+262Ch] [rbp-ECh] BYREF
char s2[16]; // [rsp+2630h] [rbp-E8h] BYREF
__m128i v43; // [rsp+2640h] [rbp-D8h]
fd_set readfds; // [rsp+2650h] [rbp-C8h] BYREF
struct sockaddr addr; // [rsp+26D0h] [rbp-48h] BYREF

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

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

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

variable_types: argc int

variable_types:
argv
char **

variable_types: nfds int

variable_types: nbytes int

variable_types: cmdLen int

variable_types: isExit int

variable_types: respLen int

variable_types:
locPortNo
unsigned short

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

variable_types:
xcCmdBuf
unsigned char *

variable_types:
parmsVal
unsigned char *

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

variable_types:
xcCmdTag
unsigned short

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

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

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

variable_types: ptPolicy int

variable_types: struct sched_param { int sched_priority; }

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


repo: wfapf/TDLS

decompiled_code:
int init_thr_flag()
{
pthread_mutex_t *v0; // rbx
int result; // eax

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

canonical_decompiled_code:
int func0()
{
pthread_mutex_t *v0; // rbx
int result; // eax

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

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

variable_types: i int

return_type: void


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

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

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

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

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

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

variable_types:
tBuf
unsigned char **

variable_types:
rBuf
unsigned char **

variable_types:
paBuf
unsigned char **

variable_types:
cBuf
unsigned char **

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

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

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

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


wfaEncodeTLV

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

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

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

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

variable_types:
data
void *

return_type: int

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


wfaDecodeTLV

decompiled_code:
__int64 __fastcall wfaDecodeTLV(__int64 a1, int a2, _WORD *a3, _DWORD *a4, _QWORD *a5)
{
unsigned __int16 v5; // dx
__int64 result; // rax
__int64 v7; // rsi

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

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2, _WORD *a3, _DWORD *a4, _QWORD *a5)
{
unsigned __int16 v5; // dx
__int64 result; // rax
__int64 v7; // rsi

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

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

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

variable_types:
ptag
unsigned short *

variable_types:
pvalue
unsigned char *

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


wfaGetTLVTag

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

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

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

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

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

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

return_type: unsigned short


wfaSetTLVTag

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

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

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

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


wfaGetTLVLen

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

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

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

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

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

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


wfaGetTLVvalue

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

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

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

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


printProfile

decompiled_code:
int __fastcall printProfile(const char *a1)
{
return printf(
"profile type %i direction %i Dest ipAddr %s Dest port %i So ipAddr %s So port %i rate %i duration %i pksize %i\n",
*(unsigned int *)a1,
*((unsigned int *)a1 + 1),
a1 + 8,
*((unsigned int *)a1 + 6),
a1 + 28,
*((unsigned int *)a1 + 11),
*((unsigned int *)a1 + 12),
*((unsigned int *)a1 + 13),
*((unsigned int *)a1 + 14));
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
return printf(
"profile type %i direction %i Dest ipAddr %s Dest port %i So ipAddr %s So port %i rate %i duration %i pksize %i\n",
*(unsigned int *)a1,
*((unsigned int *)a1 + 1),
a1 + 8,
*((unsigned int *)a1 + 6),
a1 + 28,
*((unsigned int *)a1 + 11),
*((unsigned int *)a1 + 12),
*((unsigned int *)a1 + 13),
*((unsigned int *)a1 + 14));
}

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

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

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


isString

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

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

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

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

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

variable_types:
str
char *


isNumber

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

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

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


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

v1 = *a1;
v2 = 1;
if ( *a1 )
{
v3 = 0;
do
{
v3 += v1 == 46;
v1 = *++a1;
}
while ( *a1 );
v2 = v3 <= 2;
}
return v2;
}

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

variable_types: dots int

variable_types:
tmpstr
char *


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

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

variable_types: dtime int

variable_types: sec int

variable_types: usec int


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

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

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

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

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

variable_types:
buff
char *

variable_types: val int

variable_types:
strval
char *


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

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

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

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

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

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

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

variable_types: sleep int

variable_types: latency int


wfaCreateUDPSock

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

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

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

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

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

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

variable_types:
ipaddr
char *

variable_types:
port
unsigned short

variable_types: udpsock int

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

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

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


wfaSetSockMcastSendOpt

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

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

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

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

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

variable_types: sockfd int

variable_types:
ttlval
unsigned char


wfaSetSockMcastRecvOpt

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

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

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

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

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

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

variable_types:
mcastgroup
char *

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

variable_types: so int

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


wfaConnectUDPPeer

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

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

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

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

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

variable_types: mysock int

variable_types:
daddr
char *

variable_types: dport int


wfaAcceptTCPConn

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

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

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

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

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

variable_types: servSock int

variable_types: clntSock int

variable_types:
clntLen
unsigned int


wfaSetSockFiDesc

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

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

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

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

variable_types: i int


wfaCtrlSend

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

v3 = 1;
if ( a3 )
{
v3 = send(a1, a2, a3, 0);
if ( v3 == -1 && (wfa_defined_debug & 4) != 0 )
fwrite("Error sending tcp packet\n", 1uLL, 0x19uLL, stdout);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, const void *a2, int a3)
{
unsigned int v3; // ebx

v3 = 1;
if ( a3 )
{
v3 = send(a1, a2, a3, 0);
if ( v3 == -1 && (wfa_defined_debug & 4) != 0 )
fwrite("Error sending tcp packet\n", 1uLL, 0x19uLL, stdout);
}
return v3;
}

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

variable_types: sock int

variable_types:
buf
unsigned char *

variable_types: bufLen int

variable_types: bytesSent int


wfaCtrlRecv

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

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

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

variable_types: bytesRecvd int


wfaTrafficSendTo

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

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

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

variable_types:
buf
char *

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


wfaTrafficRecv

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

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

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

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


wfaGetifAddr

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

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

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

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

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

variable_types:
ifname
char *

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

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

variable_types: fd int

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

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


wfaCreateTCPServSock

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

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

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

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

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

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

variable_types:
port
unsigned short

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

variable_types: on int


wfaSetProcPriority

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

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

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

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

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

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

variable_types: set int

variable_types: maxprio int

variable_types: currprio int

variable_types: struct sched_param { int sched_priority; }


NotDefinedYet

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

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

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

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

variable_types: len int

variable_types:
params
unsigned char *

variable_types:
respLen
int *

variable_types:
respBuf
unsigned char *


cname

repo: wfeldt/parti

original_code:
char *cname(void *buf, int len)
{
  static char name[1024];
  int i;
  char *n;
  if(len > sizeof name - 1) len = sizeof name - 1;
  memcpy(name, buf, len);
  name[len] = 0;
  for(n = name, i = len - 1; i >= 0; i--) {
    if(n[i] == 0 || n[i] == 0x20 || n[i] == 0x09 || n[i] == 0x0a) {
      n[i] = 0;
    }
    else {
      break;
    }
  }
  return name;
}

variable_types:
buf
void *

variable_types:
name
char [1024]

variable_types: i int

variable_types:
n
char *

return_type: char *


decompiled_code:
__int64 __fastcall read_qword_le(unsigned __int8 *a1)
{
__int64 v1; // rbx

v1 = (unsigned int)read_dword_le(a1 + 4);
return (v1 << 32) + (unsigned int)read_dword_le(a1);
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int8 *a1)
{
__int64 v1; // rbx

v1 = (unsigned int)func4(a1 + 4);
return (v1 << 32) + (unsigned int)func4(a1);
}

original_code:
uint64_t read_qword_le(void *buf)
{
  return ((uint64_t) read_dword_le(buf + 4) << 32) + read_dword_le(buf);
}

canonical_original_code:
unsigned long read_qword_le(void *buf)
{
  return ((unsigned long) read_dword_le(buf + 4) << 32) + read_dword_le(buf);
}

return_type: unsigned long


decompiled_code:
__int64 __fastcall read_qword_be(unsigned __int8 *a1)
{
__int64 v1; // rbx

v1 = (unsigned int)read_dword_be(a1);
return (v1 << 32) + (unsigned int)read_dword_be(a1 + 4);
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned __int8 *a1)
{
__int64 v1; // rbx

v1 = (unsigned int)func5(a1);
return (v1 << 32) + (unsigned int)func5(a1 + 4);
}

original_code:
uint64_t read_qword_be(void *buf)
{
  return ((uint64_t) read_dword_be(buf) << 32) + read_dword_be(buf + 4);
}

canonical_original_code:
unsigned long read_qword_be(void *buf)
{
  return ((unsigned long) read_dword_be(buf) << 32) + read_dword_be(buf + 4);
}


decompiled_code:
int log_info(char *format, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

if ( (opt[16] & 1) == 0 )
{
va_start(arg, format);
result = vfprintf(stdout, format, arg);
}
return result;
}

canonical_decompiled_code:
int func8(char *format, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

if ( (opt[16] & 1) == 0 )
{
va_start(arg, format);
result = vfprintf(stdout, format, arg);
}
return result;
}

original_code:
void log_info(const char *format, ...)
{
  if(opt.json) return;
  va_list args;
  __builtin_va_start(args,format);
  vfprintf(stdout, format, args);
  __builtin_va_end(args);
}

canonical_original_code:
void log_info(char *format, ...)
{
  if(opt.json) return;
  __builtin_va_list args;
  __builtin_va_start(args,format);
  vfprintf(stdout, format, args);
  __builtin_va_end(args);
}

variable_types:
format
char *


cmpuid

decompiled_code:
_BOOL8 __fastcall cmpuid(__int64 a1, _DWORD *a2)
{
return *a2 == *(_DWORD *)(a1 + 16);
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(__int64 a1, _DWORD *a2)
{
return *a2 == *(_DWORD *)(a1 + 16);
}

original_code:
static inline int cmpuid(void *d1, void *d2)
{
 struct passwd *pw = (struct passwd *) d1;
 uid_t *uid = (uid_t *) d2;
 return (*uid == pw->pw_uid);
}

canonical_original_code:
static inline int cmpuid(void *d1, void *d2)
{
 struct passwd *pw = (struct passwd *) d1;
 unsigned int *uid = (uid_t *) d2;
 return (*uid == pw->pw_uid);
}

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *

variable_types:
uid
unsigned int *


decompiled_code:
__int64 __fastcall internal_getpwent(struct passwd *resultbuf, char *a2, size_t a3, _DWORD *a4, __int64 a5, __int64 (__fastcall *a6)(struct passwd *, __int64))
{
__int64 v9; // rax
int v10; // ebx
struct passwd *result; // [rsp+18h] [rbp-40h] BYREF

if ( fpwent && !a5 || (v9 = internal_setent(&fpwent), (_DWORD)v9 == 1) )
{
while ( 1 )
{
v10 = fgetpwent_r(fpwent, resultbuf, a2, a3, &result);
if ( !a6 )
break;
v9 = a6(resultbuf, a5);
if ( (_DWORD)v9 )
break;
if ( v10 )
{
if ( v10 != 34 )
return v9;
goto LABEL_8;
}
}
if ( v10 == 34 )
{
LABEL_8:
*a4 = 34;
return 4294967294LL;
}
v9 = v10 == 0;
}
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func7(struct passwd *resultbuf, char *a2, size_t a3, _DWORD *a4, __int64 a5, __int64 (__fastcall *a6)(struct passwd *, __int64))
{
__int64 v9; // rax
int v10; // ebx
struct passwd *result; // [rsp+18h] [rbp-40h] BYREF

if ( fpwent && !a5 || (v9 = func16(&fpwent), (_DWORD)v9 == 1) )
{
while ( 1 )
{
v10 = fgetpwent_r(fpwent, resultbuf, a2, a3, &result);
if ( !a6 )
break;
v9 = a6(resultbuf, a5);
if ( (_DWORD)v9 )
break;
if ( v10 )
{
if ( v10 != 34 )
return v9;
goto LABEL_8;
}
}
if ( v10 == 34 )
{
LABEL_8:
*a4 = 34;
return 4294967294LL;
}
v9 = v10 == 0;
}
return v9;
}

original_code:
static enum nss_status internal_getpwent(struct passwd *pw, char *buffer,
      size_t buflen, int *errnop,
      void *cmpdata,
      int (*cmpFunc)(void *, void *))
{
 struct passwd *pwp;
 int r = 0;
 enum nss_status result = NSS_STATUS_SUCCESS;
 if ((fpwent.stream == ((void *)0)) || (cmpdata != ((void *)0)))
  result = internal_setent(&fpwent);
 if (result != NSS_STATUS_SUCCESS)
  return result;
 while (!r) {
  r = fgetpwent_r(fpwent.stream, pw, buffer, buflen, &pwp);
  if ( (cmpFunc == ((void *)0)) ||
       (cmpFunc(pw, cmpdata)))
   break;
 }
 if (r == 34) {
  *errnop = 34;
  return NSS_STATUS_TRYAGAIN;
 }
 if (r)
  return NSS_STATUS_NOTFOUND;
 return result;
}

canonical_original_code:
static enum nss_status internal_getpwent(struct passwd *pw, char *buffer, unsigned long buflen, int *errnop, void *cmpdata, int (*cmpFunc)(void *, void *))
{
 struct passwd *pwp;
 int r = 0;
 enum nss_status result = NSS_STATUS_SUCCESS;
 if ((fpwent.stream == ((void *)0)) || (cmpdata != ((void *)0)))
  result = internal_setent(&fpwent);
 if (result != NSS_STATUS_SUCCESS)
  return result;
 while (!r) {
  r = fgetpwent_r(fpwent.stream, pw, buffer, buflen, &pwp);
  if ( (cmpFunc == ((void *)0)) ||
       (cmpFunc(pw, cmpdata)))
   break;
 }
 if (r == 34) {
  *errnop = 34;
  return NSS_STATUS_TRYAGAIN;
 }
 if (r)
  return NSS_STATUS_NOTFOUND;
 return result;
}

variable_types:
buffer
char *

variable_types:
buflen
unsigned long

variable_types:
errnop
int *

variable_types:
cmpdata
void *

variable_types:
cmpFunc
int (*)(void *, void *)

variable_types: r int

variable_types: enum nss_status { NSS_STATUS_TRYAGAIN=-2, NSS_STATUS_UNAVAIL=-1, NSS_STATUS_NOTFOUND=0, NSS_STATUS_SUCCESS=1, NSS_STATUS_RETURN=2 }

user_defined_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; }


putlog

repo: wgjtyu/xmbot

decompiled_code:
int __fastcall putlog(const char *a1, unsigned int a2, const char *a3)
{
log = fopen("/tmp/xmbot.log", "a");
fprintf(log, "(%3d)%s:%s\n", a2, a1, a3);
return fclose(log);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1, unsigned int a2, const char *a3)
{
log = fopen("/tmp/xmbot.log", "a");
fprintf(log, "(%3d)%s:%s\n", a2, a1, a3);
return fclose(log);
}

original_code:
void putlog(const char *func,int line,const char *detail){
    log=fopen("/tmp/xmbot.log","a");
    fprintf(log,"(%3d)%s:%s\n",line,func,detail);
    fclose(log);
}

canonical_original_code:
void putlog(char *func, int line, char *detail){
    log=fopen("/tmp/xmbot.log","a");
    fprintf(log,"(%3d)%s:%s\n",line,func,detail);
    fclose(log);
}

variable_types:
func
char *

variable_types: line int

variable_types:
detail
char *


decompiled_code:
void __fastcall __noreturn j_error(const char *a1)
{
log = fopen("/tmp/xmbot.log", "a");
fprintf(stderr, "xmbot: %s\n", a1);
fprintf(log, "xmbot: %s\n", a1);
fclose(log);
exit(2);
}

canonical_decompiled_code:
void __fastcall __noreturn func6(const char *a1)
{
log = fopen("/tmp/xmbot.log", "a");
fprintf(stderr, "xmbot: %s\n", a1);
fprintf(log, "xmbot: %s\n", a1);
fclose(log);
exit(2);
}

original_code:
void j_error (char *msg)
{
    log=fopen("/tmp/xmbot.log","a");
    fprintf (stderr, "xmbot: %s\n", msg);
    fprintf(log,"xmbot: %s\n",msg);
    fclose(log);
    exit (2);
}

canonical_original_code:
void j_error(char *msg)
{
    log=fopen("/tmp/xmbot.log","a");
    fprintf (stderr, "xmbot: %s\n", msg);
    fprintf(log,"xmbot: %s\n",msg);
    fclose(log);
    exit (2);
}

variable_types:
msg
char *


decompiled_code:
void __fastcall sig_handler(unsigned int a1)
{
printf("I get %d signal, I will stop\n", a1);
server_run = 0;
}

canonical_decompiled_code:
void __fastcall func7(unsigned int a1)
{
printf("I get %d signal, I will stop\n", a1);
server_run = 0;
}

original_code:
void sig_handler(int signum) {
    printf("I get %d signal, I will stop\n", signum);
    server_run = 0;
}

variable_types: signum int


decompiled_code:
void __fastcall __noreturn client_thread(void *a1)
{
int v1; // ebx
int *v2; // rax
__int64 v3; // r12
char *v4; // rax
int v5; // eax
int v6; // eax
int *v7; // rax
__int64 v8; // r12
char *v9; // rax
int *v10; // rax
__int64 v11; // r12
char *v12; // rax
int *v13; // rax
__int64 v14; // rbx
char *v15; // rax
struct pollfd fds; // [rsp+8h] [rbp-40h] BYREF
__int64 buf[2]; // [rsp+10h] [rbp-38h] BYREF
int v18; // [rsp+20h] [rbp-28h]
int retval[7]; // [rsp+2Ch] [rbp-1Ch] BYREF

v1 = *((_DWORD *)a1 + 1);
retval[0] = 0;
while ( 1 )
{
fds.fd = v1;
fds.events = 1;
v5 = poll(&fds, 1uLL, 3500);
buf[0] = 0LL;
buf[1] = 0LL;
v18 = 0;
if ( v5 == -1 )
{
v2 = __errno_location();
v3 = (unsigned int)*v2;
v4 = strerror(*v2);
fprintf(stderr, "%s:%d, *%s* %s '%s'[%d]\n", "server.c", 155LL, "client_thread", "Poll", v4, v3);
retval[0] = 1;
}
else if ( v5 && (fds.revents & 1) != 0 )
{
v6 = recv(v1, buf, 0x14uLL, 256);
if ( v6 == -1 )
{
v7 = __errno_location();
v8 = (unsigned int)*v7;
v9 = strerror(*v7);
fprintf(stderr, "%s:%d, *%s* %s '%s'[%d]\n", "server.c", 164LL, "client_thread", "Recv", v9, v8);
retval[0] = 2;
}
else if ( v6 <= 19 )
{
v10 = __errno_location();
v11 = (unsigned int)*v10;
v12 = strerror(*v10);
fprintf(
stderr,
"%s:%d, *%s* %s '%s'[%d]\n",
"server.c",
167LL,
"client_thread",
"Recv, not full data",
v12,
v11);
retval[0] = 3;
}
else if ( LOBYTE(buf[0]) )
{
fprintf(stderr, "%s:%d, *%s* %s\n", "server.c", 183LL, "client_thread", "Incorrect command");
retval[0] = 1;
}
else
{
puts("Headbeat command");
}
}
if ( retval[0] )
{
if ( close(v1) )
{
v13 = __errno_location();
v14 = (unsigned int)*v13;
v15 = strerror(*v13);
fprintf(stderr, "%s:%d, *%s* %s '%s'[%d]\n", "server.c", 232LL, "client_thread", "Close socket", v15, v14);
}
pthread_mutex_lock((pthread_mutex_t *)((char *)a1 + 24));
*((_DWORD *)a1 + 16) = 0;
pthread_mutex_unlock((pthread_mutex_t *)((char *)a1 + 24));
pthread_exit(retval);
}
}
}

canonical_decompiled_code:
void __fastcall __noreturn func10(void *a1)
{
int v1; // ebx
int *v2; // rax
__int64 v3; // r12
char *v4; // rax
int v5; // eax
int v6; // eax
int *v7; // rax
__int64 v8; // r12
char *v9; // rax
int *v10; // rax
__int64 v11; // r12
char *v12; // rax
int *v13; // rax
__int64 v14; // rbx
char *v15; // rax
struct pollfd fds; // [rsp+8h] [rbp-40h] BYREF
__int64 buf[2]; // [rsp+10h] [rbp-38h] BYREF
int v18; // [rsp+20h] [rbp-28h]
int retval[7]; // [rsp+2Ch] [rbp-1Ch] BYREF

v1 = *((_DWORD *)a1 + 1);
retval[0] = 0;
while ( 1 )
{
fds.fd = v1;
fds.events = 1;
v5 = poll(&fds, 1uLL, 3500);
buf[0] = 0LL;
buf[1] = 0LL;
v18 = 0;
if ( v5 == -1 )
{
v2 = __errno_location();
v3 = (unsigned int)*v2;
v4 = strerror(*v2);
fprintf(stderr, "%s:%d, *%s* %s '%s'[%d]\n", "server.c", 155LL, "client_thread", "Poll", v4, v3);
retval[0] = 1;
}
else if ( v5 && (fds.revents & 1) != 0 )
{
v6 = recv(v1, buf, 0x14uLL, 256);
if ( v6 == -1 )
{
v7 = __errno_location();
v8 = (unsigned int)*v7;
v9 = strerror(*v7);
fprintf(stderr, "%s:%d, *%s* %s '%s'[%d]\n", "server.c", 164LL, "client_thread", "Recv", v9, v8);
retval[0] = 2;
}
else if ( v6 <= 19 )
{
v10 = __errno_location();
v11 = (unsigned int)*v10;
v12 = strerror(*v10);
fprintf(
stderr,
"%s:%d, *%s* %s '%s'[%d]\n",
"server.c",
167LL,
"client_thread",
"Recv, not full data",
v12,
v11);
retval[0] = 3;
}
else if ( LOBYTE(buf[0]) )
{
fprintf(stderr, "%s:%d, *%s* %s\n", "server.c", 183LL, "client_thread", "Incorrect command");
retval[0] = 1;
}
else
{
puts("Headbeat command");
}
}
if ( retval[0] )
{
if ( close(v1) )
{
v13 = __errno_location();
v14 = (unsigned int)*v13;
v15 = strerror(*v13);
fprintf(stderr, "%s:%d, *%s* %s '%s'[%d]\n", "server.c", 232LL, "client_thread", "Close socket", v15, v14);
}
pthread_mutex_lock((pthread_mutex_t *)((char *)a1 + 24));
*((_DWORD *)a1 + 16) = 0;
pthread_mutex_unlock((pthread_mutex_t *)((char *)a1 + 24));
pthread_exit(retval);
}
}
}

original_code:
void *client_thread(void *ptr) {
    struct thread_conf *my_conf = (struct thread_conf *) ptr;
    int sockfd = my_conf->sockfd;
    int command_loop = 1;
    int skip = 0;
    while(command_loop && !skip) {
        struct pollfd client;
        client.fd = sockfd;
        client.events = 0x001;
        int ret = poll(&client, 1, 3500);
        int parse_comm = 0;
        char com[20];
        memset(com, 0, 20);
        if (-1 == ret) {
            if (1) { int myerr = (*__errno_location ()); fprintf(stderr, "%s:%d, *%s* %s '%s'[%d]\n", "server.c", 155, __FUNCTION__, "Poll", strerror(myerr), myerr); };
            skip = 1;
        } else if(0 == ret) {
            continue;
        } else {
            int bytes = 0;
            if (client.revents & 0x001) {
                bytes = recv(sockfd, com, 20, MSG_WAITALL);
                if (-1 == bytes) {
                    if (1) { int myerr = (*__errno_location ()); fprintf(stderr, "%s:%d, *%s* %s '%s'[%d]\n", "server.c", 164, __FUNCTION__, "Recv", strerror(myerr), myerr); };
                    skip = 2;
                } else if (bytes < 20) {
                    if (1) { int myerr = (*__errno_location ()); fprintf(stderr, "%s:%d, *%s* %s '%s'[%d]\n", "server.c", 167, __FUNCTION__, "Recv, not full data", strerror(myerr), myerr); };
                    skip = 3;
                } else {
                    parse_comm = 1;
                }
            }
            ret = bytes;
        }
        if (parse_comm) {
            switch(com[0]) {
            case 0:
                printf("Headbeat command\n");
                break;
            default:
                if (1) { fprintf(stderr, "%s:%d, *%s* %s\n", "server.c", 183, __FUNCTION__, "Incorrect command"); };
                skip = 1;
            }
        }
    }
 if (close(sockfd)) {
        if (1) { int myerr = (*__errno_location ()); fprintf(stderr, "%s:%d, *%s* %s '%s'[%d]\n", "server.c", 232, __FUNCTION__, "Close socket", strerror(myerr), myerr); };
    }
    pthread_mutex_lock(&(my_conf->lock));
    my_conf->status = 0;
    pthread_mutex_unlock(&(my_conf->lock));
    pthread_exit(&skip);
}

variable_types:
ptr
void *

variable_types: struct thread_conf { int id; int sockfd; int iret; unsigned long thread; 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; } lock; int status; } *

variable_types: sockfd int

variable_types: skip int

variable_types: struct pollfd { int fd; short events; short revents; }

variable_types: ret int

variable_types:
com
char [20]

variable_types: myerr int

variable_types: bytes int

return_type: void *

user_defined_types: struct thread_conf { int id; int sockfd; int iret; unsigned long thread; union pthread_mutex_t lock; int status; }

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