decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbx
struct hostent *v4; // rbx
int v5; // ebp
char *v6; // rbx
int v7; // edx
int v8; // er8
int v9; // er9
bool v10; // zf
unsigned int v11; // ebx
int v12; // ebx
char *v13; // r12
int v14; // edx
int v15; // er8
int v16; // er9
char *v17; // r14
char *v18; // r13
char *v19; // r12
int v20; // edx
int v21; // er8
int v22; // er9
__time_t v23; // rsi
__suseconds_t v24; // rdx
char *v25; // rdx
int v26; // er8
int v27; // er9
char *v28; // rax
char *v29; // rbx
int v30; // edx
int v31; // er8
int v32; // er9
char *v33; // rbx
char *v34; // r12
int v35; // edx
int v36; // er8
int v37; // er9
char *v38; // rbx
char *v39; // rax
char *v40; // rbx
char *v41; // rax
char *v42; // rax
char *v43; // r13
char *v44; // r12
char *v45; // r14
int v46; // edx
int v47; // er8
int v48; // er9
char *v49; // r14
char *v50; // r12
FILE *v51; // rax
FILE *v52; // r13
unsigned __int64 v53; // r15
int v54; // er12
char *v55; // r13
char *v56; // r12
int v57; // edx
int v58; // er8
int v59; // er9
unsigned __int64 v60; // r13
FILE *v61; // r12
__int16 v62[128]; // [rsp-110h] [rbp-B38h] BYREF
int v63; // [rsp-10h] [rbp-A38h]
int fd; // [rsp+4h] [rbp-A24h]
char *src; // [rsp+8h] [rbp-A20h]
char v66[9]; // [rsp+18h] [rbp-A10h] BYREF
char v67[15]; // [rsp+21h] [rbp-A07h] BYREF
char filename[64]; // [rsp+30h] [rbp-9F8h] BYREF
__int16 v69; // [rsp+70h] [rbp-9B8h] BYREF
unsigned __int8 v70; // [rsp+72h] [rbp-9B6h]
unsigned __int8 v71; // [rsp+73h] [rbp-9B5h]
char dest[248]; // [rsp+74h] [rbp-9B4h] BYREF
__int64 v73; // [rsp+16Ch] [rbp-8BCh]
unsigned int buf; // [rsp+17Ch] [rbp-8ACh] BYREF
char v75[2048]; // [rsp+180h] [rbp-8A8h] BYREF
struct timeval tv; // [rsp+980h] [rbp-A8h] BYREF
struct timeval v77; // [rsp+990h] [rbp-98h] BYREF
int v78; // [rsp+9A8h] [rbp-80h] BYREF
int v79; // [rsp+9ACh] [rbp-7Ch]
struct sockaddr addr; // [rsp+9B0h] [rbp-78h] BYREF
int v81[22]; // [rsp+9CEh] [rbp-5Ah] BYREF

buf = getpid();
if ( argc != 2 )
die_with_error("Usage: did_client <hostname of server>");
v3 = argv[1];
fd = socket(2, 1, 6);
if ( fd < 0 )
die_with_error("socket() failed!");
v4 = gethostbyname(v3);
if ( !v4 )
die_with_error("Could not resolve hostname!");
*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_QWORD *)&addr.sa_data[2] = **(unsigned int **)v4->h_addr_list;
*(_WORD *)addr.sa_data = _bswap_16(4516);
if ( connect(fd, &addr, 0x10u) < 0 )
die_with_error("connect() failed!");
memset(v75, 0, sizeof(v75));
if ( send(fd, &buf, 4uLL, 0) != 4 )
die_with_error("Error sending PID to server!");
printf("Client started with PID %d\n", buf);
create_layer_stack((unsigned int)fd, buf, &v78);
sleep(1u);
usleep(0x64u);
v5 = 0;
while ( 1 )
{
while ( 1 )
{
do
{
fwrite("DID Client: ", 1uLL, 0xCuLL, stdout);
fflush(stdout);
fgets((char *)v81 + 2, 32, stdin);
}
while ( BYTE2(v81[0]) == 10 );
gettimeofday(&v77, 0LL);
v25 = strtok((char *)v81 + 2, " \n");
memset(&v69, 0, 0x100uLL);
HIDWORD(v73) = 0;
if ( !v5 )
break;
if ( !strcmp(v25, "quit") )
goto LABEL_68;
if ( !strcmp(v25, "create") )
{
v17 = strtok(0LL, " \n");
v18 = strtok(0LL, " \n");
v19 = strtok(0LL, " \n");
v70 = 2;
strcpy(dest, v17);
*(_WORD *)&dest[strlen(dest)] = 44;
strcat(dest, v18);
*(_WORD *)&dest[strlen(dest)] = 44;
strcat(dest, v19);
v71 = strlen(dest);
qmemcpy(v62, &v69, sizeof(v62));
v63 = HIDWORD(v73);
send_packet((__int64)&v78, (__int16 *)v81, v20, 0, v21, v22, v62[0]);
receive_packet(&v78, &v69);
if ( v70 == 5 )
printf("\tRecord created with ID: %s\n", dest);
else
printf("\tRecord creation failed, error code: %d\n", v70);
goto LABEL_27;
}
if ( !strcmp(v25, "query") )
{
v28 = strtok(0LL, " \n");
if ( !strcmp(v28, "name") )
{
v33 = strtok(0LL, " \n");
v34 = strtok(0LL, " \n");
v70 = 3;
strcpy(dest, "NAME:");
strcat(dest, v33);
*(_WORD *)&dest[strlen(dest)] = 44;
strcat(dest, v34);
v71 = strlen(dest);
qmemcpy(v62, &v69, sizeof(v62));
v63 = HIDWORD(v73);
send_packet((__int64)&v78, (__int16 *)v81, v35, 0, v36, v37, v62[0]);
receive_packet(&v78, &v69);
if ( v70 != 5 )
goto LABEL_39;
printf("\tResults for name: %s %s\n", v33, v34);
v38 = strtok(dest, ",");
while ( v38 )
{
strcpy(v67, v38);
v39 = strtok(0LL, ",");
strcpy(filename, v39);
v38 = strtok(0LL, ",");
printf("\t\tRecordID: %s\tLocation: %s\n", v67, filename);
}
}
else
{
if ( strcmp(v28, "location") )
goto LABEL_27;
v29 = strtok(0LL, " \n");
v70 = 3;
strcpy(dest, "LOCATION:");
strcat(dest, v29);
v71 = strlen(dest);
qmemcpy(v62, &v69, sizeof(v62));
v63 = HIDWORD(v73);
send_packet((__int64)&v78, (__int16 *)v81, v30, 0, v31, v32, v62[0]);
receive_packet(&v78, &v69);
if ( v70 != 5 )
{
LABEL_39:
printf("\tQuery failed, error code: %d\n", v70);
goto LABEL_27;
}
printf("\tResults for location: %s\n", v29);
v40 = strtok(dest, ",");
while ( v40 )
{
strcpy(v66, v40);
v41 = strtok(0LL, ",");
strcpy(v67, v41);
v42 = strtok(0LL, ",");
strcpy(filename, v42);
v40 = strtok(0LL, ",");
printf("\t\tRecordID: %s\tName: %s, %s\n", v66, filename, v67);
}
}
}
else if ( !strcmp(v25, "update") )
{
v43 = strtok(0LL, " \n");
v44 = strtok(0LL, " \n");
v45 = strtok(0LL, " \n");
v70 = 4;
strcpy(dest, v43);
*(_WORD *)&dest[strlen(dest)] = 44;
strcat(dest, v44);
*(_WORD *)&dest[strlen(dest)] = 44;
strcat(dest, v45);
v71 = strlen(dest);
qmemcpy(v62, &v69, sizeof(v62));
v63 = HIDWORD(v73);
send_packet((__int64)&v78, (__int16 *)v81, v46, 0, v47, v48, v62[0]);
receive_packet(&v78, &v69);
if ( v70 == 5 )
puts("\tRecord Updated!");
else
printf("\tUpdate failed, error code: %d\n", v70);
}
else
{
v10 = strcmp(v25, "add") == 0;
v11 = !v10;
if ( v10 )
{
puts("\tSending picture to server...");
v49 = strtok(0LL, " \n");
src = strtok(0LL, " \n");
v50 = strtok(0LL, " \n");
v51 = fopen(v50, "rb");
v52 = v51;
if ( v51 )
{
fseek(v51, 0LL, 2);
v53 = ftell(v52);
fseek(v52, 0LL, 0);
sprintf(filename, "%lu", v53);
strcpy(dest, v49);
*(_WORD *)&dest[strlen(dest)] = 44;
strcat(dest, src);
*(_WORD *)&dest[strlen(dest)] = 44;
strcat(dest, filename);
v71 = strlen(dest);
v70 = 5;
v69 = LOWORD(v81[0])++;
write(v79, &v69, v71 + 4LL);
if ( v53 )
{
while ( 1 )
{
*(_QWORD *)dest = 0LL;
v73 = 0LL;
memset(&dest[4], 0, 8LL * (((unsigned int)dest - (unsigned int)&dest[4] + 256) >> 3));
v54 = fread(dest, 1uLL, 0xFCuLL, v52);
if ( ferror(v52) )
break;
v69 = LOWORD(v81[0])++;
v71 = v54;
v11 += v54;
write(v79, &v69, 0x104uLL);
if ( (int)v11 >= v53 )
goto LABEL_57;
}
printf("\tError sending picture!");
}
LABEL_57:
fclose(v52);
printf("Successfully sent photo of %d total bytes\n", v11);
receive_packet(&v78, &v69);
if ( v70 == 5 )
printf("\tPictured added with pictureID: %s\n", dest);
else
printf("\tAdd picture failed, error code: %d\n", v70);
}
else
{
printf("\tCould not open %s!\n", v50);
}
}
else if ( !strcmp(v25, "connect") )
{
v55 = strtok(0LL, " \n");
v56 = strtok(0LL, " \n");
v70 = 6;
strcpy(dest, v55);
*(_WORD *)&dest[strlen(dest)] = 44;
strcat(dest, v56);
v71 = strlen(dest);
qmemcpy(v62, &v69, sizeof(v62));
v63 = HIDWORD(v73);
send_packet((__int64)&v78, (__int16 *)v81, v57, 0, v58, v59, v62[0]);
if ( v70 == 5 )
puts("\tPicture succesfully connected to record!");
else
printf("Connect picture failed, error code: %d\n", v70);
}
else if ( !strcmp(v25, "logout") )
{
v70 = 7;
qmemcpy(v62, &v69, sizeof(v62));
v63 = HIDWORD(v73);
send_packet((__int64)&v78, (__int16 *)v81, (int)v25, 0, v26, v27, v62[0]);
v5 = 0;
}
else
{
v10 = strcmp(v25, "download") == 0;
v12 = !v10;
if ( v10 )
{
v13 = strtok(0LL, " \n");
v70 = 8;
strcpy(dest, v13);
v71 = strlen(dest);
qmemcpy(v62, &v69, sizeof(v62));
v63 = HIDWORD(v73);
send_packet((__int64)&v78, (__int16 *)v81, v14, 0, v15, v16, v62[0]);
receive_packet(&v78, &v69);
if ( v70 == 5 )
{
v60 = atol(dest);
strcpy(filename, v13);
strcat(filename, ".jpg");
v61 = fopen(filename, "w");
if ( v60 )
{
do
{
receive_packet(&v78, &v69);
fwrite(dest, 1uLL, v71, v61);
v12 += v71;
}
while ( v12 < v60 );
}
fclose(v61);
puts("\tPicture succesfully downloaded!");
}
else
{
printf("\tPicture download failed, error code: %d\n", v70);
}
}
else
{
fwrite("Invalid Command!\n", 1uLL, 0x11uLL, stdout);
}
}
}
LABEL_27:
gettimeofday(&tv, 0LL);
v23 = tv.tv_sec - v77.tv_sec;
v24 = tv.tv_usec - v77.tv_usec;
if ( tv.tv_usec - v77.tv_usec < 0 )
{
--v23;
v24 += 1000000LL;
}
printf("Total command processing time: %ld.%06ld s\n\n", v23, v24);
}
if ( strcmp(v25, "login") )
{
if ( !strcmp(v25, "quit") )
{
LABEL_68:
puts("DID Client: Done.");
close(fd);
exit(0);
}
puts("Only 'login' request may be done now.");
goto LABEL_27;
}
v6 = strtok(0LL, "\n");
v70 = 1;
v71 = strlen(v6);
strcpy(dest, v6);
qmemcpy(v62, &v69, sizeof(v62));
v63 = HIDWORD(v73);
send_packet((__int64)&v78, (__int16 *)v81, v7, 0, v8, v9, v62[0]);
receive_packet(&v78, &v69);
if ( v70 == 5 )
{
puts("DID Client: Succesfully logged in!");
v5 = 1;
goto LABEL_27;
}
puts("DID Client: Invalid login... try again.");
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbx
struct hostent *v4; // rbx
int v5; // ebp
char *v6; // rbx
int v7; // edx
int v8; // er8
int v9; // er9
bool v10; // zf
unsigned int v11; // ebx
int v12; // ebx
char *v13; // r12
int v14; // edx
int v15; // er8
int v16; // er9
char *v17; // r14
char *v18; // r13
char *v19; // r12
int v20; // edx
int v21; // er8
int v22; // er9
__time_t v23; // rsi
__suseconds_t v24; // rdx
char *v25; // rdx
int v26; // er8
int v27; // er9
char *v28; // rax
char *v29; // rbx
int v30; // edx
int v31; // er8
int v32; // er9
char *v33; // rbx
char *v34; // r12
int v35; // edx
int v36; // er8
int v37; // er9
char *v38; // rbx
char *v39; // rax
char *v40; // rbx
char *v41; // rax
char *v42; // rax
char *v43; // r13
char *v44; // r12
char *v45; // r14
int v46; // edx
int v47; // er8
int v48; // er9
char *v49; // r14
char *v50; // r12
FILE *v51; // rax
FILE *v52; // r13
unsigned __int64 v53; // r15
int v54; // er12
char *v55; // r13
char *v56; // r12
int v57; // edx
int v58; // er8
int v59; // er9
unsigned __int64 v60; // r13
FILE *v61; // r12
__int16 v62[128]; // [rsp-110h] [rbp-B38h] BYREF
int v63; // [rsp-10h] [rbp-A38h]
int fd; // [rsp+4h] [rbp-A24h]
char *src; // [rsp+8h] [rbp-A20h]
char v66[9]; // [rsp+18h] [rbp-A10h] BYREF
char v67[15]; // [rsp+21h] [rbp-A07h] BYREF
char filename[64]; // [rsp+30h] [rbp-9F8h] BYREF
__int16 v69; // [rsp+70h] [rbp-9B8h] BYREF
unsigned __int8 v70; // [rsp+72h] [rbp-9B6h]
unsigned __int8 v71; // [rsp+73h] [rbp-9B5h]
char dest[248]; // [rsp+74h] [rbp-9B4h] BYREF
__int64 v73; // [rsp+16Ch] [rbp-8BCh]
unsigned int buf; // [rsp+17Ch] [rbp-8ACh] BYREF
char v75[2048]; // [rsp+180h] [rbp-8A8h] BYREF
struct timeval tv; // [rsp+980h] [rbp-A8h] BYREF
struct timeval v77; // [rsp+990h] [rbp-98h] BYREF
int v78; // [rsp+9A8h] [rbp-80h] BYREF
int v79; // [rsp+9ACh] [rbp-7Ch]
struct sockaddr addr; // [rsp+9B0h] [rbp-78h] BYREF
int v81[22]; // [rsp+9CEh] [rbp-5Ah] BYREF

buf = getpid();
if ( argc != 2 )
die_with_error("Usage: did_client <hostname of server>");
v3 = argv[1];
fd = socket(2, 1, 6);
if ( fd < 0 )
die_with_error("socket() failed!");
v4 = gethostbyname(v3);
if ( !v4 )
die_with_error("Could not resolve hostname!");
*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_QWORD *)&addr.sa_data[2] = **(unsigned int **)v4->h_addr_list;
*(_WORD *)addr.sa_data = func0(4516);
if ( connect(fd, &addr, 0x10u) < 0 )
die_with_error("connect() failed!");
memset(v75, 0, sizeof(v75));
if ( send(fd, &buf, 4uLL, 0) != 4 )
die_with_error("Error sending PID to server!");
printf("Client started with PID %d\n", buf);
create_layer_stack((unsigned int)fd, buf, &v78);
sleep(1u);
usleep(0x64u);
v5 = 0;
while ( 1 )
{
while ( 1 )
{
do
{
fwrite("DID Client: ", 1uLL, 0xCuLL, stdout);
fflush(stdout);
fgets((char *)v81 + 2, 32, stdin);
}
while ( BYTE2(v81[0]) == 10 );
gettimeofday(&v77, 0LL);
v25 = strtok((char *)v81 + 2, " \n");
memset(&v69, 0, 0x100uLL);
HIDWORD(v73) = 0;
if ( !v5 )
break;
if ( !strcmp(v25, "quit") )
goto LABEL_68;
if ( !strcmp(v25, "create") )
{
v17 = strtok(0LL, " \n");
v18 = strtok(0LL, " \n");
v19 = strtok(0LL, " \n");
v70 = 2;
strcpy(dest, v17);
*(_WORD *)&dest[strlen(dest)] = 44;
strcat(dest, v18);
*(_WORD *)&dest[strlen(dest)] = 44;
strcat(dest, v19);
v71 = strlen(dest);
qmemcpy(v62, &v69, sizeof(v62));
v63 = HIDWORD(v73);
func1((__int64)&v78, (__int16 *)v81, v20, 0, v21, v22, v62[0]);
func2(&v78, &v69);
if ( v70 == 5 )
printf("\tRecord created with ID: %s\n", dest);
else
printf("\tRecord creation failed, error code: %d\n", v70);
goto LABEL_27;
}
if ( !strcmp(v25, "query") )
{
v28 = strtok(0LL, " \n");
if ( !strcmp(v28, "name") )
{
v33 = strtok(0LL, " \n");
v34 = strtok(0LL, " \n");
v70 = 3;
strcpy(dest, "NAME:");
strcat(dest, v33);
*(_WORD *)&dest[strlen(dest)] = 44;
strcat(dest, v34);
v71 = strlen(dest);
qmemcpy(v62, &v69, sizeof(v62));
v63 = HIDWORD(v73);
func1((__int64)&v78, (__int16 *)v81, v35, 0, v36, v37, v62[0]);
func2(&v78, &v69);
if ( v70 != 5 )
goto LABEL_39;
printf("\tResults for name: %s %s\n", v33, v34);
v38 = strtok(dest, ",");
while ( v38 )
{
strcpy(v67, v38);
v39 = strtok(0LL, ",");
strcpy(filename, v39);
v38 = strtok(0LL, ",");
printf("\t\tRecordID: %s\tLocation: %s\n", v67, filename);
}
}
else
{
if ( strcmp(v28, "location") )
goto LABEL_27;
v29 = strtok(0LL, " \n");
v70 = 3;
strcpy(dest, "LOCATION:");
strcat(dest, v29);
v71 = strlen(dest);
qmemcpy(v62, &v69, sizeof(v62));
v63 = HIDWORD(v73);
func1((__int64)&v78, (__int16 *)v81, v30, 0, v31, v32, v62[0]);
func2(&v78, &v69);
if ( v70 != 5 )
{
LABEL_39:
printf("\tQuery failed, error code: %d\n", v70);
goto LABEL_27;
}
printf("\tResults for location: %s\n", v29);
v40 = strtok(dest, ",");
while ( v40 )
{
strcpy(v66, v40);
v41 = strtok(0LL, ",");
strcpy(v67, v41);
v42 = strtok(0LL, ",");
strcpy(filename, v42);
v40 = strtok(0LL, ",");
printf("\t\tRecordID: %s\tName: %s, %s\n", v66, filename, v67);
}
}
}
else if ( !strcmp(v25, "update") )
{
v43 = strtok(0LL, " \n");
v44 = strtok(0LL, " \n");
v45 = strtok(0LL, " \n");
v70 = 4;
strcpy(dest, v43);
*(_WORD *)&dest[strlen(dest)] = 44;
strcat(dest, v44);
*(_WORD *)&dest[strlen(dest)] = 44;
strcat(dest, v45);
v71 = strlen(dest);
qmemcpy(v62, &v69, sizeof(v62));
v63 = HIDWORD(v73);
func1((__int64)&v78, (__int16 *)v81, v46, 0, v47, v48, v62[0]);
func2(&v78, &v69);
if ( v70 == 5 )
puts("\tRecord Updated!");
else
printf("\tUpdate failed, error code: %d\n", v70);
}
else
{
v10 = strcmp(v25, "add") == 0;
v11 = !v10;
if ( v10 )
{
puts("\tSending picture to server...");
v49 = strtok(0LL, " \n");
src = strtok(0LL, " \n");
v50 = strtok(0LL, " \n");
v51 = fopen(v50, "rb");
v52 = v51;
if ( v51 )
{
fseek(v51, 0LL, 2);
v53 = ftell(v52);
fseek(v52, 0LL, 0);
sprintf(filename, "%lu", v53);
strcpy(dest, v49);
*(_WORD *)&dest[strlen(dest)] = 44;
strcat(dest, src);
*(_WORD *)&dest[strlen(dest)] = 44;
strcat(dest, filename);
v71 = strlen(dest);
v70 = 5;
v69 = LOWORD(v81[0])++;
write(v79, &v69, v71 + 4LL);
if ( v53 )
{
while ( 1 )
{
*(_QWORD *)dest = 0LL;
v73 = 0LL;
memset(&dest[4], 0, 8LL * (((unsigned int)dest - (unsigned int)&dest[4] + 256) >> 3));
v54 = fread(dest, 1uLL, 0xFCuLL, v52);
if ( ferror(v52) )
break;
v69 = LOWORD(v81[0])++;
v71 = v54;
v11 += v54;
write(v79, &v69, 0x104uLL);
if ( (int)v11 >= v53 )
goto LABEL_57;
}
printf("\tError sending picture!");
}
LABEL_57:
fclose(v52);
printf("Successfully sent photo of %d total bytes\n", v11);
func2(&v78, &v69);
if ( v70 == 5 )
printf("\tPictured added with pictureID: %s\n", dest);
else
printf("\tAdd picture failed, error code: %d\n", v70);
}
else
{
printf("\tCould not open %s!\n", v50);
}
}
else if ( !strcmp(v25, "connect") )
{
v55 = strtok(0LL, " \n");
v56 = strtok(0LL, " \n");
v70 = 6;
strcpy(dest, v55);
*(_WORD *)&dest[strlen(dest)] = 44;
strcat(dest, v56);
v71 = strlen(dest);
qmemcpy(v62, &v69, sizeof(v62));
v63 = HIDWORD(v73);
func1((__int64)&v78, (__int16 *)v81, v57, 0, v58, v59, v62[0]);
if ( v70 == 5 )
puts("\tPicture succesfully connected to record!");
else
printf("Connect picture failed, error code: %d\n", v70);
}
else if ( !strcmp(v25, "logout") )
{
v70 = 7;
qmemcpy(v62, &v69, sizeof(v62));
v63 = HIDWORD(v73);
func1((__int64)&v78, (__int16 *)v81, (int)v25, 0, v26, v27, v62[0]);
v5 = 0;
}
else
{
v10 = strcmp(v25, "download") == 0;
v12 = !v10;
if ( v10 )
{
v13 = strtok(0LL, " \n");
v70 = 8;
strcpy(dest, v13);
v71 = strlen(dest);
qmemcpy(v62, &v69, sizeof(v62));
v63 = HIDWORD(v73);
func1((__int64)&v78, (__int16 *)v81, v14, 0, v15, v16, v62[0]);
func2(&v78, &v69);
if ( v70 == 5 )
{
v60 = atol(dest);
strcpy(filename, v13);
strcat(filename, ".jpg");
v61 = fopen(filename, "w");
if ( v60 )
{
do
{
func2(&v78, &v69);
fwrite(dest, 1uLL, v71, v61);
v12 += v71;
}
while ( v12 < v60 );
}
fclose(v61);
puts("\tPicture succesfully downloaded!");
}
else
{
printf("\tPicture download failed, error code: %d\n", v70);
}
}
else
{
fwrite("Invalid Command!\n", 1uLL, 0x11uLL, stdout);
}
}
}
LABEL_27:
gettimeofday(&tv, 0LL);
v23 = tv.tv_sec - v77.tv_sec;
v24 = tv.tv_usec - v77.tv_usec;
if ( tv.tv_usec - v77.tv_usec < 0 )
{
--v23;
v24 += 1000000LL;
}
printf("Total command processing time: %ld.%06ld s\n\n", v23, v24);
}
if ( strcmp(v25, "login") )
{
if ( !strcmp(v25, "quit") )
{
LABEL_68:
puts("DID Client: Done.");
close(fd);
exit(0);
}
puts("Only 'login' request may be done now.");
goto LABEL_27;
}
v6 = strtok(0LL, "\n");
v70 = 1;
v71 = strlen(v6);
strcpy(dest, v6);
qmemcpy(v62, &v69, sizeof(v62));
v63 = HIDWORD(v73);
func1((__int64)&v78, (__int16 *)v81, v7, 0, v8, v9, v62[0]);
func2(&v78, &v69);
if ( v70 == 5 )
{
puts("DID Client: Succesfully logged in!");
v5 = 1;
goto LABEL_27;
}
puts("DID Client: Invalid login... try again.");
}
}

user_defined_types: struct client_handler_data { unsigned long thread; int sock; }


main

canonical_name: main

repo: nebososo/ethernet-gamepad

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // eax
int result; // eax
unsigned int v6; // eax
unsigned int v7; // er12
int v8; // eax
int v9; // edi
__int64 *v10; // rdx
__int64 v11; // rsi
int v12; // eax
int v13; // eax
int v14; // eax
int v15; // edi
int v16; // eax
int v17; // edi
int v18; // er14
__int64 i; // rax
__int64 j; // rax
__int64 v21; // rcx
_DWORD *v22; // rdi
fd_set v23; // [rsp+0h] [rbp-C8h] BYREF
struct sockaddr addr; // [rsp+80h] [rbp-48h] BYREF
int optval[11]; // [rsp+9Ch] [rbp-2Ch] BYREF

optval[0] = 0;
v3 = 0;
while ( 1 )
{
v4 = open((&uinputFileNames)[v3], 2049, envp);
s = v4;
if ( v4 >= 0 )
break;
v3 = optval[0] + 1;
optval[0] = v3;
if ( v3 > 2 )
{
fwrite("Failed to open the uinput device, is the module loaded?\n", 1uLL, 0x38uLL, stderr);
return 1;
}
}
close(v4);
signal(2, (__sighandler_t)cleanup2);
signal(15, (__sighandler_t)cleanup2);
signal(6, (__sighandler_t)cleanup2);
v7 = 3185;
if ( argc > 1 )
{
v6 = strtoul(argv[1], 0LL, 0);
v7 = 3185;
if ( v6 )
v7 = v6;
}
v17 = socket(2, 1, 6);
s = v17;
if ( v17 < 0 )
{
fwrite("Failed to open a socket.\n", 1uLL, 0x19uLL, stderr);
result = 2;
}
else
{
optval[0] = 1;
setsockopt(v17, 6, 1, optval, 4u);
setsockopt(s, 6, 12, optval, 4u);
addr.sa_family = 2;
*(_WORD *)addr.sa_data = _bswap_16(v7);
*(_DWORD *)&addr.sa_data[2] = _bswap_32(0);
addr.sa_data[6] = 0;
addr.sa_data[7] = 0;
addr.sa_data[8] = 0;
addr.sa_data[9] = 0;
addr.sa_data[10] = 0;
addr.sa_data[11] = 0;
addr.sa_data[12] = 0;
addr.sa_data[13] = 0;
optval[0] = 8;
if ( bind(s, &addr, 0x10u) )
{
fprintf(stderr, "Failed bind the socket to port %d\n", v7);
cleanup();
result = 3;
}
else
{
v18 = listen(s, 32);
if ( v18 )
{
fprintf(stderr, "Failed listen to port %d\n", v7);
cleanup();
result = 4;
}
else
{
printf("Server running on port %d\n", v7);
for ( i = 256LL; i != 319; ++i )
*(_DWORD *)(4 * i + 0x403D20) = i;
for ( j = 704LL; j != 744; ++j )
*(_DWORD *)(4 * j + 0x403718) = j;
optval[0] = 744;
dword_4042BC = 0;
buffer = 1;
dword_4042C4 = 0;
dword_4042C8 = 1;
v21 = 6LL;
v22 = &event;
while ( v21 )
{
*v22++ = 0;
--v21;
}
do
{
LABEL_13:
while ( 2 )
{
while ( 2 )
{
memset(&v23, 0, sizeof(v23));
optval[0] = 0;
v9 = nUsers;
if ( nUsers > 0 )
{
v10 = &users;
v11 = 1124LL * (unsigned int)(nUsers - 1) + 4213572;
do
{
v12 = *(_DWORD *)v10 + 63;
if ( *(int *)v10 >= 0 )
v12 = *(_DWORD *)v10;
v23.fds_bits[v12 >> 6] |= 1LL << (*(_DWORD *)v10 % 64);
v10 = (__int64 *)((char *)v10 + 1124);
}
while ( v10 != (__int64 *)v11 );
optval[0] = v9;
}
v23.fds_bits[s / 64] |= 1LL << (s % 64);
if ( !select(1024, &v23, 0LL, 0LL, 0LL) )
{
cleanup();
return 5;
}
if ( (v23.fds_bits[s / 64] & (1LL << (s % 64))) == 0 )
{
optval[0] = 0;
if ( nUsers <= 0 )
continue;
v14 = v18;
while ( 1 )
{
v15 = *((_DWORD *)&users + 281 * v14);
if ( (v23.fds_bits[v15 / 64] & (1LL << (v15 % 64))) != 0 )
{
v16 = recv(v15, &buffer, 0x400uLL, 0);
if ( v16 <= 0 )
{
puts("A client left");
removeUser(optval[0]);
goto LABEL_13;
}
process(optval[0], v16);
}
v14 = optval[0] + 1;
optval[0] = v14;
if ( v14 >= nUsers )
goto LABEL_13;
}
}
break;
}
if ( nUsers > 31 )
{
v8 = accept(s, 0LL, 0LL);
close(v8);
continue;
}
break;
}
puts("New connection.");
v13 = accept(s, 0LL, 0LL);
}
while ( !(unsigned int)addUser(v13) );
fwrite("Failed to open the uinput device, is the module loaded?\n", 1uLL, 0x38uLL, stderr);
cleanup();
result = 1;
}
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // eax
int result; // eax
unsigned int v6; // eax
unsigned int v7; // er12
int v8; // eax
int v9; // edi
__int64 *v10; // rdx
__int64 v11; // rsi
int v12; // eax
int v13; // eax
int v14; // eax
int v15; // edi
int v16; // eax
int v17; // edi
int v18; // er14
__int64 i; // rax
__int64 j; // rax
__int64 v21; // rcx
_DWORD *v22; // rdi
fd_set v23; // [rsp+0h] [rbp-C8h] BYREF
struct sockaddr addr; // [rsp+80h] [rbp-48h] BYREF
int optval[11]; // [rsp+9Ch] [rbp-2Ch] BYREF

optval[0] = 0;
v3 = 0;
while ( 1 )
{
v4 = open((&uinputFileNames)[v3], 2049, envp);
s = v4;
if ( v4 >= 0 )
break;
v3 = optval[0] + 1;
optval[0] = v3;
if ( v3 > 2 )
{
fwrite("Failed to open the uinput device, is the module loaded?\n", 1uLL, 0x38uLL, stderr);
return 1;
}
}
close(v4);
signal(2, (__sighandler_t)cleanup2);
signal(15, (__sighandler_t)cleanup2);
signal(6, (__sighandler_t)cleanup2);
v7 = 3185;
if ( argc > 1 )
{
v6 = strtoul(argv[1], 0LL, 0);
v7 = 3185;
if ( v6 )
v7 = v6;
}
v17 = socket(2, 1, 6);
s = v17;
if ( v17 < 0 )
{
fwrite("Failed to open a socket.\n", 1uLL, 0x19uLL, stderr);
result = 2;
}
else
{
optval[0] = 1;
setsockopt(v17, 6, 1, optval, 4u);
setsockopt(s, 6, 12, optval, 4u);
addr.sa_family = 2;
*(_WORD *)addr.sa_data = func8(v7);
*(_DWORD *)&addr.sa_data[2] = func9(0);
addr.sa_data[6] = 0;
addr.sa_data[7] = 0;
addr.sa_data[8] = 0;
addr.sa_data[9] = 0;
addr.sa_data[10] = 0;
addr.sa_data[11] = 0;
addr.sa_data[12] = 0;
addr.sa_data[13] = 0;
optval[0] = 8;
if ( bind(s, &addr, 0x10u) )
{
fprintf(stderr, "Failed bind the socket to port %d\n", v7);
func10();
result = 3;
}
else
{
v18 = listen(s, 32);
if ( v18 )
{
fprintf(stderr, "Failed listen to port %d\n", v7);
func10();
result = 4;
}
else
{
printf("Server running on port %d\n", v7);
for ( i = 256LL; i != 319; ++i )
*(_DWORD *)(4 * i + 0x403D20) = i;
for ( j = 704LL; j != 744; ++j )
*(_DWORD *)(4 * j + 0x403718) = j;
optval[0] = 744;
dword_4042BC = 0;
buffer = 1;
dword_4042C4 = 0;
dword_4042C8 = 1;
v21 = 6LL;
v22 = &event;
while ( v21 )
{
*v22++ = 0;
--v21;
}
do
{
LABEL_13:
while ( 2 )
{
while ( 2 )
{
memset(&v23, 0, sizeof(v23));
optval[0] = 0;
v9 = nUsers;
if ( nUsers > 0 )
{
v10 = &users;
v11 = 1124LL * (unsigned int)(nUsers - 1) + 4213572;
do
{
v12 = *(_DWORD *)v10 + 63;
if ( *(int *)v10 >= 0 )
v12 = *(_DWORD *)v10;
v23.fds_bits[v12 >> 6] |= 1LL << (*(_DWORD *)v10 % 64);
v10 = (__int64 *)((char *)v10 + 1124);
}
while ( v10 != (__int64 *)v11 );
optval[0] = v9;
}
v23.fds_bits[s / 64] |= 1LL << (s % 64);
if ( !select(1024, &v23, 0LL, 0LL, 0LL) )
{
func10();
return 5;
}
if ( (v23.fds_bits[s / 64] & (1LL << (s % 64))) == 0 )
{
optval[0] = 0;
if ( nUsers <= 0 )
continue;
v14 = v18;
while ( 1 )
{
v15 = *((_DWORD *)&users + 281 * v14);
if ( (v23.fds_bits[v15 / 64] & (1LL << (v15 % 64))) != 0 )
{
v16 = recv(v15, &buffer, 0x400uLL, 0);
if ( v16 <= 0 )
{
puts("A client left");
func11(optval[0]);
goto LABEL_13;
}
func13(optval[0], v16);
}
v14 = optval[0] + 1;
optval[0] = v14;
if ( v14 >= nUsers )
goto LABEL_13;
}
}
break;
}
if ( nUsers > 31 )
{
v8 = accept(s, 0LL, 0LL);
close(v8);
continue;
}
break;
}
puts("New connection.");
v13 = accept(s, 0LL, 0LL);
}
while ( !(unsigned int)func12(v13) );
fwrite("Failed to open the uinput device, is the module loaded?\n", 1uLL, 0x38uLL, stderr);
func10();
result = 1;
}
}
}
return result;
}

original_code:
int main(int argc, char *argv[]){
    int i;
    int port;
    struct sockaddr_in sAddr;
    int len;
    fd_set set;
    for(i = 0; i < 3; i++){
        s = open(uinputFileNames[i], 01 | 04000);
        if(s >= 0){
            break;
        }
    }
    if(s < 0){
        fprintf(stderr, "Failed to open the uinput device, "
            "is the module loaded?\n");
        return 1;
    }
    close(s);
    signal(2, cleanup2);
    signal(15, cleanup2);
    signal(6, cleanup2);
    if(argc < 2 || !(port = strtoul(argv[1], ((void *)0), 0))){
        port = 3185;
    }
    s = socket(2, SOCK_STREAM, IPPROTO_TCP);
    if(s < 0){
        fprintf(stderr, "Failed to open a socket.\n");
        return 2;
    }
    i = 1;
    setsockopt(s, IPPROTO_TCP, 1, &i, sizeof(i));
    setsockopt(s, IPPROTO_TCP, 12, &i, sizeof(i));
    sAddr.sin_family = 2;
    sAddr.sin_port = htons(port);
    sAddr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
    for(i = 0; i < sizeof(sAddr.sin_zero); i++){
        sAddr.sin_zero[i] = 0;
    }
    if(bind(s, (struct sockaddr *) &sAddr, sizeof(struct sockaddr_in))){
        fprintf(stderr, "Failed bind the socket to port %d\n", port);
        cleanup();
        return 3;
    }
    if(listen(s, 32)){
        fprintf(stderr, "Failed listen to port %d\n", port);
        cleanup();
        return 4;
    }
    printf("Server running on port %d\n", port);
    for(i = 0x100; i <= 0x13e; i++){
        translation[i - 0x100] = i;
    }
    for(i = 0x2c0; i <= 0x2e7; i++){
        translation[i + 62 - 0x2c0] = i;
    }
    translation[103] = 0x00;
    translation[104] = 0x01;
    translation[105] = 0x00;
    translation[106] = 0x01;
    memset(&event, 0, sizeof(event));
    for(;;){
        do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&set)->fds_bits)[0]) : "memory"); } while (0);
        for(i = 0; i < nUsers; i++){
            ((void) (((&set)->fds_bits)[((users[i].s) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((users[i].s) % (8 * (int) sizeof (__fd_mask)))))));
        }
        ((void) (((&set)->fds_bits)[((s) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((s) % (8 * (int) sizeof (__fd_mask)))))));
        if(!select(1024, &set, ((void *)0), ((void *)0), ((void *)0))){
            cleanup();
            return 5;
        }
        if(((((&set)->fds_bits)[((s) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((s) % (8 * (int) sizeof (__fd_mask)))))) != 0)){
            if(nUsers < 32){
                printf("New connection.\n");
                if(addUser(accept(s, ((void *)0), 0))){
                    fprintf(stderr, "Failed to open the uinput device, "
                        "is the module loaded?\n");
                    cleanup();
                    return 1;
                }
            }
            else {
                close(accept(s, ((void *)0), 0));
            }
            continue;
        }
        for(i = 0; i < nUsers; i++){
            if(!(((((&set)->fds_bits)[((users[i].s) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((users[i].s) % (8 * (int) sizeof (__fd_mask)))))) != 0))){
                continue;
            }
            len = recv(users[i].s, buffer, 1024, 0);
            if(len <= 0){
                printf("A client left\n");
                removeUser(i);
                break;
            }
            process(i, len);
        }
    }
    cleanup();
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[]){
    int i;
    int port;
    struct sockaddr_in sAddr;
    int len;
    struct fd_set set;
    for(i = 0; i < 3; i++){
        s = open(uinputFileNames[i], 01 | 04000);
        if(s >= 0){
            break;
        }
    }
    if(s < 0){
        fprintf(stderr, "Failed to open the uinput device, "
            "is the module loaded?\n");
        return 1;
    }
    close(s);
    signal(2, cleanup2);
    signal(15, cleanup2);
    signal(6, cleanup2);
    if(argc < 2 || !(port = strtoul(argv[1], ((void *)0), 0))){
        port = 3185;
    }
    s = socket(2, SOCK_STREAM, IPPROTO_TCP);
    if(s < 0){
        fprintf(stderr, "Failed to open a socket.\n");
        return 2;
    }
    i = 1;
    setsockopt(s, IPPROTO_TCP, 1, &i, sizeof(i));
    setsockopt(s, IPPROTO_TCP, 12, &i, sizeof(i));
    sAddr.sin_family = 2;
    sAddr.sin_port = htons(port);
    sAddr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
    for(i = 0; i < sizeof(sAddr.sin_zero); i++){
        sAddr.sin_zero[i] = 0;
    }
    if(bind(s, (struct sockaddr *) &sAddr, sizeof(struct sockaddr_in))){
        fprintf(stderr, "Failed bind the socket to port %d\n", port);
        cleanup();
        return 3;
    }
    if(listen(s, 32)){
        fprintf(stderr, "Failed listen to port %d\n", port);
        cleanup();
        return 4;
    }
    printf("Server running on port %d\n", port);
    for(i = 0x100; i <= 0x13e; i++){
        translation[i - 0x100] = i;
    }
    for(i = 0x2c0; i <= 0x2e7; i++){
        translation[i + 62 - 0x2c0] = i;
    }
    translation[103] = 0x00;
    translation[104] = 0x01;
    translation[105] = 0x00;
    translation[106] = 0x01;
    memset(&event, 0, sizeof(event));
    for(;;){
        do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&set)->fds_bits)[0]) : "memory"); } while (0);
        for(i = 0; i < nUsers; i++){
            ((void) (((&set)->fds_bits)[((users[i].s) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((users[i].s) % (8 * (int) sizeof (__fd_mask)))))));
        }
        ((void) (((&set)->fds_bits)[((s) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((s) % (8 * (int) sizeof (__fd_mask)))))));
        if(!select(1024, &set, ((void *)0), ((void *)0), ((void *)0))){
            cleanup();
            return 5;
        }
        if(((((&set)->fds_bits)[((s) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((s) % (8 * (int) sizeof (__fd_mask)))))) != 0)){
            if(nUsers < 32){
                printf("New connection.\n");
                if(addUser(accept(s, ((void *)0), 0))){
                    fprintf(stderr, "Failed to open the uinput device, "
                        "is the module loaded?\n");
                    cleanup();
                    return 1;
                }
            }
            else {
                close(accept(s, ((void *)0), 0));
            }
            continue;
        }
        for(i = 0; i < nUsers; i++){
            if(!(((((&set)->fds_bits)[((users[i].s) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((users[i].s) % (8 * (int) sizeof (__fd_mask)))))) != 0))){
                continue;
            }
            len = recv(users[i].s, buffer, 1024, 0);
            if(len <= 0){
                printf("A client left\n");
                removeUser(i);
                break;
            }
            process(i, len);
        }
    }
    cleanup();
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: i int

variable_types: port 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]; }

variable_types: len int

variable_types:
set
struct fd_set { long fds_bits[-1]; }

return_type: int

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


worker

decompiled_code:
void *__fastcall worker(void *a1)
{
printf("%d\n", *(unsigned int *)a1);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func7(void *a1)
{
printf("%d\n", *(unsigned int *)a1);
return 0LL;
}

original_code:
void * worker (void * arg){
  int * i = arg;
  printf ("%d\n", *i);
  return ((void *)0);
}

canonical_original_code:
void *worker(void *arg){
  int *i = arg;
  printf ("%d\n", *i);
  return ((void *)0);
}

variable_types:
arg
void *

variable_types:
i
int *

return_type: void *


decompiled_code:
int __fastcall queue_init(__int64 a1)
{
*(_DWORD *)(a1 + 128) = 0;
*(_DWORD *)(a1 + 132) = 0;
sem_init((sem_t *)(a1 + 216), 0, 0x10u);
sem_init((sem_t *)(a1 + 248), 0, 0);
pthread_mutex_init((pthread_mutex_t *)(a1 + 136), 0LL);
return pthread_mutex_init((pthread_mutex_t *)(a1 + 176), 0LL);
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1)
{
*(_DWORD *)(a1 + 128) = 0;
*(_DWORD *)(a1 + 132) = 0;
sem_init((sem_t *)(a1 + 216), 0, 0x10u);
sem_init((sem_t *)(a1 + 248), 0, 0);
pthread_mutex_init((pthread_mutex_t *)(a1 + 136), 0LL);
return pthread_mutex_init((pthread_mutex_t *)(a1 + 176), 0LL);
}

original_code:
void queue_init (queue_t * queue) {
  queue->tail = 0;
  queue->head = 0;
  sem_init (&(queue->full_sem),0,sizeof (queue->tasks)/sizeof (queue->tasks[0]));
  sem_init (&(queue->empty_sem),0,0);
  pthread_mutex_init (&(queue->tail_mutex), ((void *)0));
  pthread_mutex_init (&(queue->head_mutex), ((void *)0));
}

canonical_original_code:
void queue_init(struct queue_t *queue) {
  queue->tail = 0;
  queue->head = 0;
  sem_init (&(queue->full_sem),0,sizeof (queue->tasks)/sizeof (queue->tasks[0]));
  sem_init (&(queue->empty_sem),0,0);
  pthread_mutex_init (&(queue->tail_mutex), ((void *)0));
  pthread_mutex_init (&(queue->head_mutex), ((void *)0));
}

variable_types: struct queue_t { struct task_t { char pswd[-1]; char *hash; } *tasks[-1]; int tail; int head; 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; } tail_mutex; union pthread_mutex_t head_mutex; union sem_t { char __size[32]; long __align; } full_sem; union sem_t empty_sem; } *

return_type: void

user_defined_types: struct queue_t { struct task_t *tasks[-1]; int tail; int head; union pthread_mutex_t tail_mutex; union pthread_mutex_t head_mutex; union sem_t full_sem; union sem_t empty_sem; }

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


decompiled_code:
int __fastcall queue_push(__int64 a1, __int64 a2)
{
int v2; // edx
int v3; // eax

sem_wait((sem_t *)(a1 + 216));
pthread_mutex_lock((pthread_mutex_t *)(a1 + 136));
v2 = *(_DWORD *)(a1 + 128);
*(_QWORD *)(a1 + 8LL * v2) = a2;
v3 = v2 + 1;
if ( v2 == 15 )
v3 = 0;
*(_DWORD *)(a1 + 128) = v3;
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 136));
return sem_post((sem_t *)(a1 + 248));
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1, __int64 a2)
{
int v2; // edx
int v3; // eax

sem_wait((sem_t *)(a1 + 216));
pthread_mutex_lock((pthread_mutex_t *)(a1 + 136));
v2 = *(_DWORD *)(a1 + 128);
*(_QWORD *)(a1 + 8LL * v2) = a2;
v3 = v2 + 1;
if ( v2 == 15 )
v3 = 0;
*(_DWORD *)(a1 + 128) = v3;
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 136));
return sem_post((sem_t *)(a1 + 248));
}

original_code:
void queue_push (queue_t * queue, task_t * task) {
  sem_wait (&(queue-> full_sem));
  pthread_mutex_lock (&(queue-> tail_mutex));
  queue-> tasks[queue-> tail] = task;
  queue-> tail++;
  if (queue-> tail == sizeof (queue-> tasks)/sizeof (queue-> tasks[0])) {
    queue-> tail=0;
  }
  pthread_mutex_unlock (&(queue-> tail_mutex));
  sem_post (&(queue-> empty_sem));
}

canonical_original_code:
void queue_push(struct queue_t *queue, struct task_t *task) {
  sem_wait (&(queue-> full_sem));
  pthread_mutex_lock (&(queue-> tail_mutex));
  queue-> tasks[queue-> tail] = task;
  queue-> tail++;
  if (queue-> tail == sizeof (queue-> tasks)/sizeof (queue-> tasks[0])) {
    queue-> tail=0;
  }
  pthread_mutex_unlock (&(queue-> tail_mutex));
  sem_post (&(queue-> empty_sem));
}

variable_types:
task
struct task_t *

user_defined_types: union sem_t { char __size[32]; long __align; }

user_defined_types: struct task_t { char pswd[-1]; char *hash; }

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


decompiled_code:
__int64 __fastcall queue_pop(__int64 a1)
{
int v1; // edx
__int64 v2; // rbp
int v3; // eax

sem_wait((sem_t *)(a1 + 248));
pthread_mutex_lock((pthread_mutex_t *)(a1 + 176));
v1 = *(_DWORD *)(a1 + 132);
v2 = *(_QWORD *)(a1 + 8LL * v1);
v3 = v1 + 1;
if ( v1 == 15 )
v3 = 0;
*(_DWORD *)(a1 + 132) = v3;
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 176));
sem_post((sem_t *)(a1 + 216));
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
int v1; // edx
__int64 v2; // rbp
int v3; // eax

sem_wait((sem_t *)(a1 + 248));
pthread_mutex_lock((pthread_mutex_t *)(a1 + 176));
v1 = *(_DWORD *)(a1 + 132);
v2 = *(_QWORD *)(a1 + 8LL * v1);
v3 = v1 + 1;
if ( v1 == 15 )
v3 = 0;
*(_DWORD *)(a1 + 132) = v3;
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 176));
sem_post((sem_t *)(a1 + 216));
return v2;
}

original_code:
task_t * queue_pop (queue_t * queue) {
  task_t * task;
  sem_wait (&(queue-> empty_sem));
  pthread_mutex_lock (&(queue-> head_mutex));
  task = queue-> tasks[queue-> head];
  queue-> head++;
  if (queue-> head == sizeof (queue-> tasks)/sizeof (queue-> tasks[0])) {
    queue->head = 0;
  }
  pthread_mutex_unlock (&(queue-> head_mutex));
  sem_post (&(queue-> full_sem));
  return task;
}

canonical_original_code:
struct task_t *queue_pop(struct queue_t *queue) {
  struct task_t *task;
  sem_wait (&(queue-> empty_sem));
  pthread_mutex_lock (&(queue-> head_mutex));
  task = queue-> tasks[queue-> head];
  queue-> head++;
  if (queue-> head == sizeof (queue-> tasks)/sizeof (queue-> tasks[0])) {
    queue->head = 0;
  }
  pthread_mutex_unlock (&(queue-> head_mutex));
  sem_post (&(queue-> full_sem));
  return task;
}

variable_types: struct queue_t { struct task_t *tasks[-1]; int tail; int head; 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; } tail_mutex; union pthread_mutex_t head_mutex; union sem_t { char __size[32]; long __align; } full_sem; union sem_t empty_sem; } *

variable_types: struct task_t { char pswd[-1]; char *hash; } *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
void *v4; // rsp
int i; // eax
int j; // eax
_BYTE v8[12]; // [rsp+0h] [rbp-20h] BYREF
int arg[5]; // [rsp+Ch] [rbp-14h] BYREF

v3 = sysconf(84) + 2;
v4 = alloca(8LL * v3);
printf("ncpu = %d\n", (unsigned int)v3);
arg[0] = 0;
if ( v3 > 0 )
{
for ( i = 0; i < v3; arg[0] = i )
{
pthread_create((pthread_t *)&v8[8 * i], 0LL, worker, arg);
i = arg[0] + 1;
}
arg[0] = 0;
for ( j = 0; j < v3; arg[0] = j )
{
pthread_join(*(_QWORD *)&v8[8 * j], 0LL);
j = arg[0] + 1;
}
}
return 0;
}

original_code:
int main (int argc, char *argv[]) {
  int i;
  int ncpu = 2 + (long)sysconf (_SC_NPROCESSORS_ONLN);
  pthread_t ids[ncpu];
  printf ("ncpu = %d\n", ncpu);
  for (i = 0; i < ncpu; ++i) {
    pthread_create (&ids[i], ((void *)0), worker, &i);
  }
  for (i = 0; i < ncpu; ++i)
    pthread_join (ids[i], ((void *)0));
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
  int i;
  int ncpu = 2 + (long)sysconf (_SC_NPROCESSORS_ONLN);
  unsigned long ids[-1];
  printf ("ncpu = %d\n", ncpu);
  for (i = 0; i < ncpu; ++i) {
    pthread_create (&ids[i], ((void *)0), worker, &i);
  }
  for (i = 0; i < ncpu; ++i)
    pthread_join (ids[i], ((void *)0));
  return 0;
}

variable_types: ncpu int

variable_types:
ids
unsigned long [-1]


judyCountBits

repo: neesenk/JudyL

original_code:
static inline uint32_t judyCountBits(uint32_t word)
{
 word = (word & 0x55555555) + ((word & 0xAAAAAAAA) >> 1);
 word = (word & 0x33333333) + ((word & 0xCCCCCCCC) >> 2);
 word = (word & 0x0F0F0F0F) + ((word & 0xF0F0F0F0) >> 4);
 word = (word & 0x00FF00FF) + ((word & 0xFF00FF00) >> 8);
 word = (word & 0x0000FFFF) + ((word & 0xFFFF0000) >> 16);
 return (word);
}

canonical_original_code:
static inline unsigned int judyCountBits(unsigned int word)
{
 word = (word & 0x55555555) + ((word & 0xAAAAAAAA) >> 1);
 word = (word & 0x33333333) + ((word & 0xCCCCCCCC) >> 2);
 word = (word & 0x0F0F0F0F) + ((word & 0xF0F0F0F0) >> 4);
 word = (word & 0x00FF00FF) + ((word & 0xFF00FF00) >> 8);
 word = (word & 0x0000FFFF) + ((word & 0xFFFF0000) >> 16);
 return (word);
}

variable_types:
word
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall judySearchLeaf1(__int64 a1, unsigned __int64 a2, unsigned __int8 a3)
{
unsigned __int8 v3; // r8
__int64 v5; // rdx
unsigned __int64 v6; // rax
__int64 result; // rax

v3 = a3;
v5 = -1LL;
while ( a2 - v5 > 1 )
{
v6 = (a2 + v5) >> 1;
if ( *(_BYTE *)(a1 + v6) <= a3 )
v5 = (a2 + v5) >> 1;
if ( *(_BYTE *)(a1 + v6) > a3 )
a2 = v6;
}
if ( v5 == -1 || (result = (unsigned int)v5, *(_BYTE *)(a1 + v5) != v3) )
result = (unsigned int)~(_DWORD)a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned __int64 a2, unsigned __int8 a3)
{
unsigned __int8 v3; // r8
__int64 v5; // rdx
unsigned __int64 v6; // rax
__int64 result; // rax

v3 = a3;
v5 = -1LL;
while ( a2 - v5 > 1 )
{
v6 = (a2 + v5) >> 1;
if ( *(_BYTE *)(a1 + v6) <= a3 )
v5 = (a2 + v5) >> 1;
if ( *(_BYTE *)(a1 + v6) > a3 )
a2 = v6;
}
if ( v5 == -1 || (result = (unsigned int)v5, *(_BYTE *)(a1 + v5) != v3) )
result = (unsigned int)~(_DWORD)a2;
return result;
}

original_code:
static inline int judySearchLeaf1(Pjll_t Pjll, Word_t LeafPop1, Word_t Index)
{
 uint8_t *P_leaf = (uint8_t *)(Pjll); uint8_t I_ndex = (uint8_t)Index; Word_t l_ow = (~0UL); Word_t m_id; Word_t h_igh = LeafPop1; while ((h_igh - l_ow) > 1UL) { m_id = (h_igh + l_ow) / 2; if (P_leaf[m_id] > I_ndex) h_igh = m_id; else l_ow = m_id; } if (l_ow == (~0UL) || P_leaf[l_ow] != I_ndex) return(~h_igh); return(l_ow);
}

canonical_original_code:
static inline int judySearchLeaf1(void *Pjll, unsigned long LeafPop1, unsigned long Index)
{
 unsigned char *P_leaf = (uint8_t *)(Pjll); unsigned char I_ndex = (uint8_t)Index; unsigned long l_ow = (~0UL); unsigned long m_id; unsigned long h_igh = LeafPop1; while ((h_igh - l_ow) > 1UL) { m_id = (h_igh + l_ow) / 2; if (P_leaf[m_id] > I_ndex) h_igh = m_id; else l_ow = m_id; } if (l_ow == (~0UL) || P_leaf[l_ow] != I_ndex) return(~h_igh); return(l_ow);
}

variable_types:
Pjll
void *

variable_types:
Index
unsigned long


decompiled_code:
__int64 __fastcall judySearchLeaf2(__int64 a1, unsigned __int64 a2, unsigned __int16 a3)
{
unsigned __int16 v3; // r9
__int64 v5; // rdx
unsigned __int64 v6; // r8
unsigned __int64 v7; // rax
__int64 result; // rax

v3 = a3;
v5 = -1LL;
while ( a2 - v5 > 1 )
{
v6 = (a2 + v5) >> 1;
v7 = (a2 + v5) & 0xFFFFFFFFFFFFFFFELL;
if ( *(_WORD *)(a1 + v7) <= a3 )
v5 = (a2 + v5) >> 1;
if ( *(_WORD *)(a1 + v7) > a3 )
a2 = v6;
}
if ( v5 == -1 || (result = (unsigned int)v5, *(_WORD *)(a1 + 2 * v5) != v3) )
result = (unsigned int)~(_DWORD)a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned __int64 a2, unsigned __int16 a3)
{
unsigned __int16 v3; // r9
__int64 v5; // rdx
unsigned __int64 v6; // r8
unsigned __int64 v7; // rax
__int64 result; // rax

v3 = a3;
v5 = -1LL;
while ( a2 - v5 > 1 )
{
v6 = (a2 + v5) >> 1;
v7 = (a2 + v5) & 0xFFFFFFFFFFFFFFFELL;
if ( *(_WORD *)(a1 + v7) <= a3 )
v5 = (a2 + v5) >> 1;
if ( *(_WORD *)(a1 + v7) > a3 )
a2 = v6;
}
if ( v5 == -1 || (result = (unsigned int)v5, *(_WORD *)(a1 + 2 * v5) != v3) )
result = (unsigned int)~(_DWORD)a2;
return result;
}

original_code:
static inline int judySearchLeaf2(Pjll_t Pjll, Word_t LeafPop1, Word_t Index)
{
 uint16_t *P_leaf = (uint16_t *)(Pjll); uint16_t I_ndex = (uint16_t)Index; Word_t l_ow = (~0UL); Word_t m_id; Word_t h_igh = LeafPop1; while ((h_igh - l_ow) > 1UL) { m_id = (h_igh + l_ow) / 2; if (P_leaf[m_id] > I_ndex) h_igh = m_id; else l_ow = m_id; } if (l_ow == (~0UL) || P_leaf[l_ow] != I_ndex) return(~h_igh); return(l_ow);
}

canonical_original_code:
static inline int judySearchLeaf2(void *Pjll, unsigned long LeafPop1, unsigned long Index)
{
 unsigned short *P_leaf = (uint16_t *)(Pjll); unsigned short I_ndex = (uint16_t)Index; unsigned long l_ow = (~0UL); unsigned long m_id; unsigned long h_igh = LeafPop1; while ((h_igh - l_ow) > 1UL) { m_id = (h_igh + l_ow) / 2; if (P_leaf[m_id] > I_ndex) h_igh = m_id; else l_ow = m_id; } if (l_ow == (~0UL) || P_leaf[l_ow] != I_ndex) return(~h_igh); return(l_ow);
}


decompiled_code:
__int64 __fastcall judySearchLeaf3(__int64 a1, unsigned __int64 a2, int a3)
{
unsigned __int64 v3; // r10
__int64 v4; // rdx
unsigned __int64 v5; // rcx
unsigned __int64 v6; // rax
__int64 result; // rax

v3 = a3 & 0xFFFFFF;
v4 = -1LL;
while ( a2 - v4 > 1 )
{
v5 = (a2 + v4) >> 1;
v6 = *(unsigned __int8 *)(a1 + v5 + ((a2 + v4) & 0xFFFFFFFFFFFFFFFELL) + 2)
+ ((unsigned __int64)*(unsigned __int8 *)(a1 + v5 + ((a2 + v4) & 0xFFFFFFFFFFFFFFFELL)) << 16)
+ ((unsigned __int64)*(unsigned __int8 *)(a1 + v5 + ((a2 + v4) & 0xFFFFFFFFFFFFFFFELL) + 1) << 8);
if ( v3 >= v6 )
v4 = (a2 + v4) >> 1;
if ( v3 < v6 )
a2 = v5;
}
if ( v4 == -1 )
return (unsigned int)~(_DWORD)a2;
result = (unsigned int)~(_DWORD)a2;
if ( v3 == *(unsigned __int8 *)(a1 + 3 * v4 + 2)
+ ((unsigned __int64)*(unsigned __int8 *)(a1 + 3 * v4) << 16)
+ ((unsigned __int64)*(unsigned __int8 *)(a1 + 3 * v4 + 1) << 8) )
result = (unsigned int)v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned __int64 a2, int a3)
{
unsigned __int64 v3; // r10
__int64 v4; // rdx
unsigned __int64 v5; // rcx
unsigned __int64 v6; // rax
__int64 result; // rax

v3 = a3 & 0xFFFFFF;
v4 = -1LL;
while ( a2 - v4 > 1 )
{
v5 = (a2 + v4) >> 1;
v6 = *(unsigned __int8 *)(a1 + v5 + ((a2 + v4) & 0xFFFFFFFFFFFFFFFELL) + 2)
+ ((unsigned __int64)*(unsigned __int8 *)(a1 + v5 + ((a2 + v4) & 0xFFFFFFFFFFFFFFFELL)) << 16)
+ ((unsigned __int64)*(unsigned __int8 *)(a1 + v5 + ((a2 + v4) & 0xFFFFFFFFFFFFFFFELL) + 1) << 8);
if ( v3 >= v6 )
v4 = (a2 + v4) >> 1;
if ( v3 < v6 )
a2 = v5;
}
if ( v4 == -1 )
return (unsigned int)~(_DWORD)a2;
result = (unsigned int)~(_DWORD)a2;
if ( v3 == *(unsigned __int8 *)(a1 + 3 * v4 + 2)
+ ((unsigned __int64)*(unsigned __int8 *)(a1 + 3 * v4) << 16)
+ ((unsigned __int64)*(unsigned __int8 *)(a1 + 3 * v4 + 1) << 8) )
result = (unsigned int)v4;
return result;
}

original_code:
static inline int judySearchLeaf3(Pjll_t Pjll, Word_t LeafPop1, Word_t Index)
{
 uint8_t *P_leaf = (uint8_t *)(Pjll); Word_t l_ow = (~0UL); Word_t m_id; Word_t h_igh = LeafPop1; Word_t I_ndex = (((Index)) & ((0x100UL << (0x8 * (((3)) - 1))) - 1)); Word_t i_ndex; I_ndex = (((Index)) & ((0x100UL << (0x8 * (((3)) - 1))) - 1)); while ((h_igh - l_ow) > 1UL) { m_id = (h_igh + l_ow) / 2; i_ndex = (Word_t)(&P_leaf[m_id * (3)])[0] << 16; i_ndex += (Word_t)(&P_leaf[m_id * (3)])[1] << 8; i_ndex += (Word_t)(&P_leaf[m_id * (3)])[2]; if (i_ndex > I_ndex) h_igh = m_id; else l_ow = m_id; } if (l_ow == (~0UL)) return(~h_igh); i_ndex = (Word_t)(&P_leaf[l_ow * (3)])[0] << 16; i_ndex += (Word_t)(&P_leaf[l_ow * (3)])[1] << 8; i_ndex += (Word_t)(&P_leaf[l_ow * (3)])[2]; if (i_ndex != I_ndex) return(~h_igh); return(l_ow);
}

canonical_original_code:
static inline int judySearchLeaf3(void *Pjll, unsigned long LeafPop1, unsigned long Index)
{
 unsigned char *P_leaf = (uint8_t *)(Pjll); unsigned long l_ow = (~0UL); unsigned long m_id; unsigned long h_igh = LeafPop1; unsigned long I_ndex = (((Index)) & ((0x100UL << (0x8 * (((3)) - 1))) - 1)); unsigned long i_ndex; I_ndex = (((Index)) & ((0x100UL << (0x8 * (((3)) - 1))) - 1)); while ((h_igh - l_ow) > 1UL) { m_id = (h_igh + l_ow) / 2; i_ndex = (Word_t)(&P_leaf[m_id * (3)])[0] << 16; i_ndex += (Word_t)(&P_leaf[m_id * (3)])[1] << 8; i_ndex += (Word_t)(&P_leaf[m_id * (3)])[2]; if (i_ndex > I_ndex) h_igh = m_id; else l_ow = m_id; } if (l_ow == (~0UL)) return(~h_igh); i_ndex = (Word_t)(&P_leaf[l_ow * (3)])[0] << 16; i_ndex += (Word_t)(&P_leaf[l_ow * (3)])[1] << 8; i_ndex += (Word_t)(&P_leaf[l_ow * (3)])[2]; if (i_ndex != I_ndex) return(~h_igh); return(l_ow);
}


JudyLFirst

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

if ( a2 )
{
result = JudyLGet(a1, *a2);
if ( result != -1 && !result )
result = JudyLNext(a1, a2);
}
else
{
*_errno_location() = 4;
result = -1LL;
}
return result;
}

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

if ( a2 )
{
result = func5(a1, *a2);
if ( result != -1 && !result )
result = JudyLNext(a1, a2);
}
else
{
*_errno_location() = 4;
result = -1LL;
}
return result;
}

original_code:
void **JudyLFirst(const void *PArray, uint32_t *PIndex)
{
 void **PValue;
 if (PIndex == ((void *)0)) {
  do { ((void) sizeof (((JLE_NULLPINDEX) != JLE_OVERRUN) ? 1 : 0), __extension__ ({ if ((JLE_NULLPINDEX) != JLE_OVERRUN) ; else __assert_fail ("(JLE_NULLPINDEX) != JLE_OVERRUN", "JudyLGet.c", 7, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof (((JLE_NULLPINDEX) != JLE_CORRUPT) ? 1 : 0), __extension__ ({ if ((JLE_NULLPINDEX) != JLE_CORRUPT) ; else __assert_fail ("(JLE_NULLPINDEX) != JLE_CORRUPT", "JudyLGet.c", 7, __extension__ __PRETTY_FUNCTION__); })); (*__errno_location ()) = (JLE_NULLPINDEX); } while (0);
  return ((void **)(~0UL));
 }
 if ((PValue = JudyLGet(PArray, *PIndex)) == ((void **)(~0UL)))
  return ((void **)(~0UL));
 if (PValue != ((void *)0))
  return PValue;
 return JudyLNext(PArray, PIndex);
}

canonical_original_code:
void **JudyLFirst(void *PArray, unsigned int *PIndex)
{
 void **PValue;
 if (PIndex == ((void *)0)) {
  do { ((void) sizeof (((JLE_NULLPINDEX) != JLE_OVERRUN) ? 1 : 0), __extension__ ({ if ((JLE_NULLPINDEX) != JLE_OVERRUN) ; else __assert_fail ("(JLE_NULLPINDEX) != JLE_OVERRUN", "JudyLGet.c", 7, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof (((JLE_NULLPINDEX) != JLE_CORRUPT) ? 1 : 0), __extension__ ({ if ((JLE_NULLPINDEX) != JLE_CORRUPT) ; else __assert_fail ("(JLE_NULLPINDEX) != JLE_CORRUPT", "JudyLGet.c", 7, __extension__ __PRETTY_FUNCTION__); })); (*__errno_location ()) = (JLE_NULLPINDEX); } while (0);
  return ((void **)(~0UL));
 }
 if ((PValue = JudyLGet(PArray, *PIndex)) == ((void **)(~0UL)))
  return ((void **)(~0UL));
 if (PValue != ((void *)0))
  return PValue;
 return JudyLNext(PArray, PIndex);
}

variable_types:
PArray
void *

variable_types:
PIndex
unsigned int *

variable_types:
PValue
void **

return_type: void **


JudyLLast

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

if ( a2 )
{
result = JudyLGet(a1, *a2);
if ( result != -1 && !result )
result = JudyLPrev(a1, a2);
}
else
{
*_errno_location() = 4;
result = -1LL;
}
return result;
}

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

if ( a2 )
{
result = func5(a1, *a2);
if ( result != -1 && !result )
result = JudyLPrev(a1, a2);
}
else
{
*_errno_location() = 4;
result = -1LL;
}
return result;
}

original_code:
void **JudyLLast(const void *PArray, uint32_t *PIndex)
{
 void **PValue;
 if (PIndex == ((void *)0)) {
  do { ((void) sizeof (((JLE_NULLPINDEX) != JLE_OVERRUN) ? 1 : 0), __extension__ ({ if ((JLE_NULLPINDEX) != JLE_OVERRUN) ; else __assert_fail ("(JLE_NULLPINDEX) != JLE_OVERRUN", "JudyLGet.c", 22, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof (((JLE_NULLPINDEX) != JLE_CORRUPT) ? 1 : 0), __extension__ ({ if ((JLE_NULLPINDEX) != JLE_CORRUPT) ; else __assert_fail ("(JLE_NULLPINDEX) != JLE_CORRUPT", "JudyLGet.c", 22, __extension__ __PRETTY_FUNCTION__); })); (*__errno_location ()) = (JLE_NULLPINDEX); } while (0);
  return ((void **)(~0UL));
 }
 if ((PValue = JudyLGet(PArray, *PIndex)) == ((void **)(~0UL)))
  return ((void **)(~0UL));
 if (PValue != ((void *)0))
  return PValue;
 return JudyLPrev(PArray, PIndex);
}

canonical_original_code:
void **JudyLLast(void *PArray, unsigned int *PIndex)
{
 void **PValue;
 if (PIndex == ((void *)0)) {
  do { ((void) sizeof (((JLE_NULLPINDEX) != JLE_OVERRUN) ? 1 : 0), __extension__ ({ if ((JLE_NULLPINDEX) != JLE_OVERRUN) ; else __assert_fail ("(JLE_NULLPINDEX) != JLE_OVERRUN", "JudyLGet.c", 22, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof (((JLE_NULLPINDEX) != JLE_CORRUPT) ? 1 : 0), __extension__ ({ if ((JLE_NULLPINDEX) != JLE_CORRUPT) ; else __assert_fail ("(JLE_NULLPINDEX) != JLE_CORRUPT", "JudyLGet.c", 22, __extension__ __PRETTY_FUNCTION__); })); (*__errno_location ()) = (JLE_NULLPINDEX); } while (0);
  return ((void **)(~0UL));
 }
 if ((PValue = JudyLGet(PArray, *PIndex)) == ((void **)(~0UL)))
  return ((void **)(~0UL));
 if (PValue != ((void *)0))
  return PValue;
 return JudyLPrev(PArray, PIndex);
}


JudyLFirstEmpty

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

if ( a2 )
{
v2 = JudyLGet(a1, *a2);
if ( v2 == -1 )
{
v3 = -1;
}
else
{
v3 = 1;
if ( v2 )
v3 = JudyLNextEmpty(a1, a2, 1LL);
}
}
else
{
*_errno_location() = 4;
v3 = -1;
}
return v3;
}

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

if ( a2 )
{
v2 = func5(a1, *a2);
if ( v2 == -1 )
{
v3 = -1;
}
else
{
v3 = 1;
if ( v2 )
v3 = JudyLNextEmpty(a1, a2, 1LL);
}
}
else
{
*_errno_location() = 4;
v3 = -1;
}
return v3;
}

original_code:
int JudyLFirstEmpty(const void *PArray, uint32_t *PIndex)
{
 void **PValue;
 if (PIndex == ((void *)0)) {
  do { ((void) sizeof (((JLE_NULLPINDEX) != JLE_OVERRUN) ? 1 : 0), __extension__ ({ if ((JLE_NULLPINDEX) != JLE_OVERRUN) ; else __assert_fail ("(JLE_NULLPINDEX) != JLE_OVERRUN", "JudyLGet.c", 37, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof (((JLE_NULLPINDEX) != JLE_CORRUPT) ? 1 : 0), __extension__ ({ if ((JLE_NULLPINDEX) != JLE_CORRUPT) ; else __assert_fail ("(JLE_NULLPINDEX) != JLE_CORRUPT", "JudyLGet.c", 37, __extension__ __PRETTY_FUNCTION__); })); (*__errno_location ()) = (JLE_NULLPINDEX); } while (0);
  return (-1);
 }
 if ((PValue = JudyLGet(PArray, *PIndex)) == ((void **)(~0UL)))
  return (-1);
 if (PValue == ((void *)0))
  return 1;
 return JudyLNextEmpty(PArray, PIndex);
}

canonical_original_code:
int JudyLFirstEmpty(void *PArray, unsigned int *PIndex)
{
 void **PValue;
 if (PIndex == ((void *)0)) {
  do { ((void) sizeof (((JLE_NULLPINDEX) != JLE_OVERRUN) ? 1 : 0), __extension__ ({ if ((JLE_NULLPINDEX) != JLE_OVERRUN) ; else __assert_fail ("(JLE_NULLPINDEX) != JLE_OVERRUN", "JudyLGet.c", 37, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof (((JLE_NULLPINDEX) != JLE_CORRUPT) ? 1 : 0), __extension__ ({ if ((JLE_NULLPINDEX) != JLE_CORRUPT) ; else __assert_fail ("(JLE_NULLPINDEX) != JLE_CORRUPT", "JudyLGet.c", 37, __extension__ __PRETTY_FUNCTION__); })); (*__errno_location ()) = (JLE_NULLPINDEX); } while (0);
  return (-1);
 }
 if ((PValue = JudyLGet(PArray, *PIndex)) == ((void **)(~0UL)))
  return (-1);
 if (PValue == ((void *)0))
  return 1;
 return JudyLNextEmpty(PArray, PIndex);
}


JudyLLastEmpty

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

if ( a2 )
{
v2 = JudyLGet(a1, *a2);
if ( v2 == -1 )
{
v3 = -1;
}
else
{
v3 = 1;
if ( v2 )
v3 = JudyLPrevEmpty(a1, a2, 1LL);
}
}
else
{
*_errno_location() = 4;
v3 = -1;
}
return v3;
}

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

if ( a2 )
{
v2 = func5(a1, *a2);
if ( v2 == -1 )
{
v3 = -1;
}
else
{
v3 = 1;
if ( v2 )
v3 = JudyLPrevEmpty(a1, a2, 1LL);
}
}
else
{
*_errno_location() = 4;
v3 = -1;
}
return v3;
}

original_code:
int JudyLLastEmpty(const void *PArray, uint32_t *PIndex)
{
 void **PValue;
 if (PIndex == ((void *)0)) {
  do { ((void) sizeof (((JLE_NULLPINDEX) != JLE_OVERRUN) ? 1 : 0), __extension__ ({ if ((JLE_NULLPINDEX) != JLE_OVERRUN) ; else __assert_fail ("(JLE_NULLPINDEX) != JLE_OVERRUN", "JudyLGet.c", 52, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof (((JLE_NULLPINDEX) != JLE_CORRUPT) ? 1 : 0), __extension__ ({ if ((JLE_NULLPINDEX) != JLE_CORRUPT) ; else __assert_fail ("(JLE_NULLPINDEX) != JLE_CORRUPT", "JudyLGet.c", 52, __extension__ __PRETTY_FUNCTION__); })); (*__errno_location ()) = (JLE_NULLPINDEX); } while (0);
  return (-1);
 }
 if ((PValue = JudyLGet(PArray, *PIndex)) == ((void **)(~0UL)))
  return (-1);
 if (PValue == ((void *)0))
  return 1;
 return JudyLPrevEmpty(PArray, PIndex);
}

canonical_original_code:
int JudyLLastEmpty(void *PArray, unsigned int *PIndex)
{
 void **PValue;
 if (PIndex == ((void *)0)) {
  do { ((void) sizeof (((JLE_NULLPINDEX) != JLE_OVERRUN) ? 1 : 0), __extension__ ({ if ((JLE_NULLPINDEX) != JLE_OVERRUN) ; else __assert_fail ("(JLE_NULLPINDEX) != JLE_OVERRUN", "JudyLGet.c", 52, __extension__ __PRETTY_FUNCTION__); })); ((void) sizeof (((JLE_NULLPINDEX) != JLE_CORRUPT) ? 1 : 0), __extension__ ({ if ((JLE_NULLPINDEX) != JLE_CORRUPT) ; else __assert_fail ("(JLE_NULLPINDEX) != JLE_CORRUPT", "JudyLGet.c", 52, __extension__ __PRETTY_FUNCTION__); })); (*__errno_location ()) = (JLE_NULLPINDEX); } while (0);
  return (-1);
 }
 if ((PValue = JudyLGet(PArray, *PIndex)) == ((void **)(~0UL)))
  return (-1);
 if (PValue == ((void *)0))
  return 1;
 return JudyLPrevEmpty(PArray, PIndex);
}


decompiled_code:
__int64 __fastcall str2int(unsigned __int8 *a1, unsigned __int64 a2)
{
int v2; // edx
int v3; // edx
__int64 result; // rax
int v5; // eax

if ( a2 == 3 )
{
v5 = 0;
goto LABEL_12;
}
if ( a2 <= 3 )
{
if ( a2 == 1 )
{
v3 = 0;
return v3 + (unsigned int)*a1;
}
if ( a2 != 2 )
return 0LL;
v2 = 0;
LABEL_6:
v3 = (a1[1] << 8) + v2;
return v3 + (unsigned int)*a1;
}
result = 0LL;
if ( a2 == 4 )
{
v5 = a1[3] << 24;
LABEL_12:
v2 = v5 + (a1[2] << 16);
goto LABEL_6;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1, unsigned __int64 a2)
{
int v2; // edx
int v3; // edx
__int64 result; // rax
int v5; // eax

if ( a2 == 3 )
{
v5 = 0;
goto LABEL_12;
}
if ( a2 <= 3 )
{
if ( a2 == 1 )
{
v3 = 0;
return v3 + (unsigned int)*a1;
}
if ( a2 != 2 )
return 0LL;
v2 = 0;
LABEL_6:
v3 = (a1[1] << 8) + v2;
return v3 + (unsigned int)*a1;
}
result = 0LL;
if ( a2 == 4 )
{
v5 = a1[3] << 24;
LABEL_12:
v2 = v5 + (a1[2] << 16);
goto LABEL_6;
}
return result;
}

original_code:
static inline uint32_t str2int(uint8_t *str, size_t len)
{
 uint32_t ret = 0;
 switch (len) {
 case 4: ret += ((uint32_t)str[3]) << 24;
 case 3: ret += ((uint32_t)str[2]) << 16;
 case 2: ret += ((uint32_t)str[1]) << 8;
 case 1: ret += ((uint32_t)str[0]);
 }
 return ret;
}

canonical_original_code:
static inline unsigned int str2int(unsigned char *str, unsigned long len)
{
 unsigned int ret = 0;
 switch (len) {
 case 4: ret += ((unsigned int)str[3]) << 24;
 case 3: ret += ((unsigned int)str[2]) << 16;
 case 2: ret += ((unsigned int)str[1]) << 8;
 case 1: ret += ((unsigned int)str[0]);
 }
 return ret;
}

variable_types:
str
unsigned char *

variable_types:
len
unsigned long

variable_types:
ret
unsigned int


JudyHtbFreeArray

decompiled_code:
void __fastcall JudyHtbFreeArray(_QWORD *a1)
{
_QWORD *i; // rbp
unsigned __int64 v3; // rbx
void **k; // rax
void **j; // rax
unsigned __int64 v6; // rdi
int v7; // [rsp+4h] [rbp-44h] BYREF
int v8; // [rsp+8h] [rbp-40h] BYREF
int v9[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v9[0] = 0;
v8 = 0;
v7 = 0;
if ( a1 )
{
for ( i = (_QWORD *)JudyLFirst(*a1, v9);
(unsigned __int64)i - 1 <= 0xFFFFFFFFFFFFFFFDLL;
i = (_QWORD *)JudyLNext(*a1, v9) )
{
if ( v9[0] > 4u )
{
v8 = 0;
for ( j = (void **)JudyLFirst(*i, &v8);
(unsigned __int64)j - 1 <= 0xFFFFFFFFFFFFFFFDLL;
j = (void **)JudyLNext(*i, &v8) )
{
v6 = (unsigned __int64)*j;
if ( ((unsigned __int8)*j & 1) != 0 )
{
v3 = v6 & 0xFFFFFFFFFFFFFFFELL;
v7 = 0;
for ( k = (void **)JudyLFirst(v6 & 0xFFFFFFFFFFFFFFFELL, &v7);
(unsigned __int64)k - 1 <= 0xFFFFFFFFFFFFFFFDLL;
k = (void **)JudyLNext(v3, &v7) )
{
free(*k);
}
JudyLFreeArray(v3);
}
else
{
free((void *)v6);
}
}
}
JudyLFreeArray(i);
}
JudyLFreeArray(a1);
}
}

canonical_decompiled_code:
void __fastcall func5(_QWORD *a1)
{
_QWORD *i; // rbp
unsigned __int64 v3; // rbx
void **k; // rax
void **j; // rax
unsigned __int64 v6; // rdi
int v7; // [rsp+4h] [rbp-44h] BYREF
int v8; // [rsp+8h] [rbp-40h] BYREF
int v9[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v9[0] = 0;
v8 = 0;
v7 = 0;
if ( a1 )
{
for ( i = (_QWORD *)JudyLFirst(*a1, v9);
(unsigned __int64)i - 1 <= 0xFFFFFFFFFFFFFFFDLL;
i = (_QWORD *)JudyLNext(*a1, v9) )
{
if ( v9[0] > 4u )
{
v8 = 0;
for ( j = (void **)JudyLFirst(*i, &v8);
(unsigned __int64)j - 1 <= 0xFFFFFFFFFFFFFFFDLL;
j = (void **)JudyLNext(*i, &v8) )
{
v6 = (unsigned __int64)*j;
if ( ((unsigned __int8)*j & 1) != 0 )
{
v3 = v6 & 0xFFFFFFFFFFFFFFFELL;
v7 = 0;
for ( k = (void **)JudyLFirst(v6 & 0xFFFFFFFFFFFFFFFELL, &v7);
(unsigned __int64)k - 1 <= 0xFFFFFFFFFFFFFFFDLL;
k = (void **)JudyLNext(v3, &v7) )
{
free(*k);
}
JudyLFreeArray(v3);
}
else
{
free((void *)v6);
}
}
}
JudyLFreeArray(i);
}
JudyLFreeArray(a1);
}
}

original_code:
void JudyHtbFreeArray(void **judy)
{
 uint32_t len = 0, idx = 0, hidx = 0;
 void **htb, **slot, **item;
 if (judy == ((void *)0))
  return;
 for ((len)=0,(htb)=JudyLFirst(*judy,&(len));(htb)!=((void *)0)&&(htb)!=((void **)(~0UL));(htb)=JudyLNext(*judy,&(len))) {
  if (len > (sizeof(uint32_t))) {
   for ((idx)=0,(slot)=JudyLFirst(*htb,&(idx));(slot)!=((void *)0)&&(slot)!=((void **)(~0UL));(slot)=JudyLNext(*htb,&(idx))) {
    if ((((unsigned long)*slot) & 0x1)) {
     void *nj = (void *)(((unsigned long)*slot) & ~0x1UL);
     for ((hidx)=0,(item)=JudyLFirst(nj,&(hidx));(item)!=((void *)0)&&(item)!=((void **)(~0UL));(item)=JudyLNext(nj,&(hidx))) {
      free(*item);
     }
     JudyLFreeArray(nj);
    } else {
     free(*slot);
    }
   }
  }
  JudyLFreeArray(htb);
 }
 JudyLFreeArray(judy);
}

canonical_original_code:
void JudyHtbFreeArray(void **judy)
{
 unsigned int len = 0; unsigned int idx = 0; unsigned int hidx = 0;
 void **htb; void **slot; void **item;
 if (judy == ((void *)0))
  return;
 for ((len)=0,(htb)=JudyLFirst(*judy,&(len));(htb)!=((void *)0)&&(htb)!=((void **)(~0UL));(htb)=JudyLNext(*judy,&(len))) {
  if (len > (sizeof(unsigned int))) {
   for ((idx)=0,(slot)=JudyLFirst(*htb,&(idx));(slot)!=((void *)0)&&(slot)!=((void **)(~0UL));(slot)=JudyLNext(*htb,&(idx))) {
    if ((((unsigned long)*slot) & 0x1)) {
     void *nj = (void *)(((unsigned long)*slot) & ~0x1UL);
     for ((hidx)=0,(item)=JudyLFirst(nj,&(hidx));(item)!=((void *)0)&&(item)!=((void **)(~0UL));(item)=JudyLNext(nj,&(hidx))) {
      free(*item);
     }
     JudyLFreeArray(nj);
    } else {
     free(*slot);
    }
   }
  }
  JudyLFreeArray(htb);
 }
 JudyLFreeArray(judy);
}

variable_types:
judy
void **

variable_types:
len
unsigned int

variable_types:
idx
unsigned int

variable_types:
hidx
unsigned int

variable_types:
htb
void **

variable_types:
slot
void **

variable_types:
item
void **

variable_types:
nj
void *


judyCountBits

variable_types:
word
unsigned int


summ

repo: neesenk/coro

original_code:
static void summ(unsigned long long t)
{
    if (t <= 1000)
        tootm[0]++;
    else if (t <= 2000)
        tootm[1]++;
    else if (t <= 5000)
        tootm[2]++;
    else if (t <= 10000)
        tootm[3]++;
    else if (t <= 50000)
        tootm[4]++;
    else if (t <=100000)
        tootm[5]++;
    else if (t <= 500000)
        tootm[6]++;
    else if (t <= 1000000)
        tootm[7]++;
    else
        tootm[8]++;
}

variable_types:
t
unsigned long long


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

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

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

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

original_code:
static uint64_t st_mstime(void)
{
    struct timeval tv;
    (void)gettimeofday(&tv, ((void *)0));
    return (uint64_t)tv.tv_sec * 1000000LL + tv.tv_usec;
}

canonical_original_code:
static unsigned long st_mstime()
{
    struct timeval tv;
    (void)gettimeofday(&tv, ((void *)0));
    return (unsigned long)tv.tv_sec * 1000000LL + tv.tv_usec;
}

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

return_type: unsigned long


decompiled_code:
__int64 __fastcall init_scokaddr(__int64 a1, const char *a2, __int16 a3)
{
in_addr_t v3; // eax
unsigned int v4; // edx
struct hostent *v6; // rax

*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_WORD *)a1 = 2;
*(_WORD *)(a1 + 2) = _bswap_16(a3);
v3 = inet_addr(a2);
*(_DWORD *)(a1 + 4) = v3;
v4 = 0;
if ( v3 == -1 )
{
v6 = gethostbyname(a2);
if ( v6 )
{
memcpy((void *)(a1 + 4), *(const void **)v6->h_addr_list, v6->h_length);
v4 = 0;
}
else
{
v4 = -1;
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const char *a2, __int16 a3)
{
in_addr_t v3; // eax
unsigned int v4; // edx
struct hostent *v6; // rax

*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_WORD *)a1 = 2;
*(_WORD *)(a1 + 2) = func1(a3);
v3 = inet_addr(a2);
*(_DWORD *)(a1 + 4) = v3;
v4 = 0;
if ( v3 == -1 )
{
v6 = gethostbyname(a2);
if ( v6 )
{
memcpy((void *)(a1 + 4), *(const void **)v6->h_addr_list, v6->h_length);
v4 = 0;
}
else
{
v4 = -1;
}
}
return v4;
}

original_code:
int init_scokaddr(struct sockaddr_in *sockaddr, const char *addr, unsigned port)
{
    memset(sockaddr, 0, sizeof(*sockaddr));
 sockaddr->sin_family = 2;
 sockaddr->sin_port = htons(port);
 sockaddr->sin_addr.s_addr = inet_addr(addr);
 if (sockaddr->sin_addr.s_addr == ((in_addr_t) 0xffffffff)) {
        struct hostent *hp = gethostbyname(addr);
        if (hp == ((void *)0))
            return -1;
        memcpy(&sockaddr->sin_addr, hp->h_addr_list[0], hp->h_length);
 }
    return 0;
}

canonical_original_code:
int init_scokaddr(struct sockaddr_in *sockaddr, char *addr, unsigned int port)
{
    memset(sockaddr, 0, sizeof(*sockaddr));
 sockaddr->sin_family = 2;
 sockaddr->sin_port = htons(port);
 sockaddr->sin_addr.s_addr = inet_addr(addr);
 if (sockaddr->sin_addr.s_addr == ((unsigned int) 0xffffffff)) {
        struct hostent *hp = gethostbyname(addr);
        if (hp == ((void *)0))
            return -1;
        memcpy(&sockaddr->sin_addr, hp->h_addr_list[0], hp->h_length);
 }
    return 0;
}

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:
addr
char *

variable_types:
port
unsigned int

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *


decompiled_code:
__int64 __fastcall set_nonblock(int fd)
{
int v1; // eax

v1 = fcntl(fd, 3, 0LL);
if ( v1 < 0 )
return 0xFFFFFFFFLL;
BYTE1(v1) |= 8u;
return (unsigned int)(fcntl(fd, 4, (unsigned int)v1) >> 31);
}

canonical_decompiled_code:
__int64 __fastcall func4(int fd)
{
int v1; // eax

v1 = fcntl(fd, 3, 0LL);
if ( v1 < 0 )
return 0xFFFFFFFFLL;
BYTE1(v1) |= 8u;
return (unsigned int)(fcntl(fd, 4, (unsigned int)v1) >> 31);
}

original_code:
int set_nonblock(int fd)
{
    int f = 0;
    if ((f = fcntl(fd, 3, 0)) < 0 || fcntl(fd, 4, f|04000) < 0)
        return -1;
    return 0;
}

variable_types: fd int

variable_types: f int


decompiled_code:
__int64 __fastcall create_listener(const char *a1, __int16 a2)
{
int v2; // eax
unsigned int v3; // ebx
struct sockaddr v5; // [rsp+0h] [rbp-28h] BYREF
int optval[3]; // [rsp+1Ch] [rbp-Ch] BYREF

optval[0] = 1;
if ( (unsigned int)init_scokaddr((__int64)&v5, a1, a2) )
return (unsigned int)-1;
v2 = socket(2, 1, 0);
v3 = v2;
if ( v2 < 0 )
return (unsigned int)-1;
if ( (int)set_nonblock(v2) < 0
|| setsockopt(v3, 1, 2, optval, 4u) < 0
|| bind(v3, &v5, 0x10u) < 0
|| listen(v3, 12800) < 0 )
{
close(v3);
v3 = -1;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1, __int16 a2)
{
int v2; // eax
unsigned int v3; // ebx
struct sockaddr v5; // [rsp+0h] [rbp-28h] BYREF
int optval[3]; // [rsp+1Ch] [rbp-Ch] BYREF

optval[0] = 1;
if ( (unsigned int)func3((__int64)&v5, a1, a2) )
return (unsigned int)-1;
v2 = socket(2, 1, 0);
v3 = v2;
if ( v2 < 0 )
return (unsigned int)-1;
if ( (int)func4(v2) < 0
|| setsockopt(v3, 1, 2, optval, 4u) < 0
|| bind(v3, &v5, 0x10u) < 0
|| listen(v3, 12800) < 0 )
{
close(v3);
v3 = -1;
}
return v3;
}

original_code:
int create_listener(const char *addr, unsigned port)
{
    int sock = 0, n = 1;
 struct sockaddr_in serv_addr;
    if (init_scokaddr(&serv_addr, addr, port) != 0)
        return -1;
    if ((sock = socket(2, SOCK_STREAM, 0)) < 0)
        return -1;
    if (set_nonblock(sock) < 0)
        goto ERROR;
    if (setsockopt(sock, 1, 2, (char *)&n, sizeof(n)) < 0)
        goto ERROR;
 if (bind(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
        goto ERROR;
 if (listen(sock, 12800) < 0)
        goto ERROR;
    return sock;
ERROR:
    close(sock);
    return -1;
}

canonical_original_code:
int create_listener(char *addr, unsigned int port)
{
    int sock = 0; int n = 1;
 struct sockaddr_in serv_addr;
    if (init_scokaddr(&serv_addr, addr, port) != 0)
        return -1;
    if ((sock = socket(2, SOCK_STREAM, 0)) < 0)
        return -1;
    if (set_nonblock(sock) < 0)
        goto ERROR;
    if (setsockopt(sock, 1, 2, (char *)&n, sizeof(n)) < 0)
        goto ERROR;
 if (bind(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
        goto ERROR;
 if (listen(sock, 12800) < 0)
        goto ERROR;
    return sock;
ERROR:
    close(sock);
    return -1;
}

variable_types: sock int

variable_types: n 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]; }


decompiled_code:
__int64 __fastcall create_connecter(const char *a1, __int16 a2)
{
int v2; // eax
unsigned int v3; // ebx
int *v5; // rbp
char *v6; // rax
_BYTE v7[28]; // [rsp+0h] [rbp-38h] BYREF
int optval[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

optval[0] = 1;
if ( (unsigned int)init_scokaddr((__int64)v7, a1, a2) )
return (unsigned int)-1;
v2 = socket(2, 1, 0);
v3 = v2;
if ( v2 < 0 )
return (unsigned int)-1;
if ( setsockopt(v2, 1, 2, optval, 4u) < 0 || (int)set_nonblock(v3) < 0 || (int)coro_connect(v3, v7, 16LL) < 0 )
{
v5 = _errno_location();
v6 = strerror(*v5);
printf("errno = %d, errmsg = %s\n", (unsigned int)*v5, v6);
close(v3);
v3 = -1;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1, __int16 a2)
{
int v2; // eax
unsigned int v3; // ebx
int *v5; // rbp
char *v6; // rax
_BYTE v7[28]; // [rsp+0h] [rbp-38h] BYREF
int optval[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

optval[0] = 1;
if ( (unsigned int)func3((__int64)v7, a1, a2) )
return (unsigned int)-1;
v2 = socket(2, 1, 0);
v3 = v2;
if ( v2 < 0 )
return (unsigned int)-1;
if ( setsockopt(v2, 1, 2, optval, 4u) < 0 || (int)func4(v3) < 0 || (int)coro_connect(v3, v7, 16LL) < 0 )
{
v5 = _errno_location();
v6 = strerror(*v5);
printf("errno = %d, errmsg = %s\n", (unsigned int)*v5, v6);
close(v3);
v3 = -1;
}
return v3;
}

original_code:
int create_connecter(const char *addr, unsigned port)
{
    int sock = 0, n = 1;
 struct sockaddr_in serv_addr;
    if (init_scokaddr(&serv_addr, addr, port) != 0)
        return -1;
    if ((sock = socket(2, SOCK_STREAM, 0)) < 0)
        return -1;
    if (setsockopt(sock, 1, 2, (char *)&n, sizeof(n)) < 0)
        goto ERROR;
    if (set_nonblock(sock) < 0)
        goto ERROR;
 if (coro_connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
        goto ERROR;
    return sock;
ERROR:
    printf("errno = %d, errmsg = %s\n", (*__errno_location ()), strerror((*__errno_location ())));
    close(sock);
    return -1;
}

canonical_original_code:
int create_connecter(char *addr, unsigned int port)
{
    int sock = 0; int n = 1;
 struct sockaddr_in serv_addr;
    if (init_scokaddr(&serv_addr, addr, port) != 0)
        return -1;
    if ((sock = socket(2, SOCK_STREAM, 0)) < 0)
        return -1;
    if (setsockopt(sock, 1, 2, (char *)&n, sizeof(n)) < 0)
        goto ERROR;
    if (set_nonblock(sock) < 0)
        goto ERROR;
 if (coro_connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
        goto ERROR;
    return sock;
ERROR:
    printf("errno = %d, errmsg = %s\n", (*__errno_location ()), strerror((*__errno_location ())));
    close(sock);
    return -1;
}


decompiled_code:
int client_main()
{
int *v0; // rbx
char *v1; // rax
unsigned int v2; // ebp
char *v3; // rax
__suseconds_t v4; // rax
__suseconds_t v5; // rax
__int64 v6; // rax
unsigned int v7; // ebx
unsigned __int64 v8; // rdi
int result; // eax
__suseconds_t v10; // rax
__suseconds_t v11; // [rsp+8h] [rbp-850h]
int *v12; // [rsp+10h] [rbp-848h]
int v13; // [rsp+1Ch] [rbp-83Ch]
__int64 s1[8]; // [rsp+20h] [rbp-838h] BYREF
char v15[960]; // [rsp+60h] [rbp-7F8h] BYREF
char s2[1080]; // [rsp+420h] [rbp-438h] BYREF

v13 = 100000;
do
{
v2 = create_connecter("127.0.0.1", port);
if ( (v2 & 0x80000000) == 0 )
{
while ( 1 )
{
strcpy((char *)s1, "+PING xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
s1[7] = 0LL;
memset(v15, 0, sizeof(v15));
v11 = st_mstime();
if ( coro_write(v2, s1, 1024LL) != 1024 )
{
v0 = _errno_location();
v1 = strerror(*v0);
printf("errno = %d, errmsg = %s\n", (unsigned int)*v0, v1);
printf("%d write failed close\n", v2);
close(v2);
goto LABEL_3;
}
v6 = coro_read_fully(v2, s2, 1024LL);
v7 = v6;
if ( v6 < 0 )
break;
if ( !v6 )
goto LABEL_7;
if ( memcmp(s1, s2, 0x400uLL) )
_assert_fail("memcmp(msg, buff, 1024) == 0", "main.c", 0xF4u, "client_main");
++total;
v8 = st_mstime() - v11;
summ(v8);
sptime += v8;
if ( total == 100000 * (total / 100000) )
{
v5 = st_mstime();
printf(
"client: rec = %d, totl = %llu, avg = %llu, sp = %llu, asp = %llu, poll = %d,%d\n",
(unsigned int)total,
v5 - beg,
(v5 - beg) / (unsigned __int64)total,
sptime,
sptime / (unsigned __int64)total,
(unsigned int)pollnum,
(unsigned int)pollnum2);
printf(
"summ: %d %d %d %d %d %d %d %d %d\n",
(unsigned int)tootm[0],
(unsigned int)tootm[1],
(unsigned int)tootm[2],
(unsigned int)tootm[3],
(unsigned int)tootm[4],
(unsigned int)tootm[5],
(unsigned int)tootm[6],
(unsigned int)tootm[7],
(unsigned int)tootm[8]);
}
coro_yield();
}
v12 = _errno_location();
v3 = strerror(*v12);
printf("errno = %d, errmsg = %s\n", (unsigned int)*v12, v3);
v4 = st_mstime();
printf("%d read failed close %llu, %d %d\n", v2, v4 - v11, v7, 1024LL);
LABEL_7:
close(v2);
}
else
{
puts("connect failed");
coro_yield();
}
LABEL_3:
--v13;
}
while ( v13 );
result = 100000 * (total / 100000);
if ( total == result )
{
v10 = st_mstime();
printf(
"client: rec = %d, totl = %llu, avg = %llu, pollnum = %d\n",
(unsigned int)total,
v10 - beg,
(v10 - beg) / (unsigned __int64)total,
(unsigned int)pollnum);
result = printf(
"summ: %d %d %d %d %d %d %d %d %d\n",
(unsigned int)tootm[0],
(unsigned int)tootm[1],
(unsigned int)tootm[2],
(unsigned int)tootm[3],
(unsigned int)tootm[4],
(unsigned int)tootm[5],
(unsigned int)tootm[6],
(unsigned int)tootm[7],
(unsigned int)tootm[8]);
}
return result;
}

canonical_decompiled_code:
int func7()
{
int *v0; // rbx
char *v1; // rax
unsigned int v2; // ebp
char *v3; // rax
__suseconds_t v4; // rax
__suseconds_t v5; // rax
__int64 v6; // rax
unsigned int v7; // ebx
unsigned __int64 v8; // rdi
int result; // eax
__suseconds_t v10; // rax
__suseconds_t v11; // [rsp+8h] [rbp-850h]
int *v12; // [rsp+10h] [rbp-848h]
int v13; // [rsp+1Ch] [rbp-83Ch]
__int64 s1[8]; // [rsp+20h] [rbp-838h] BYREF
char v15[960]; // [rsp+60h] [rbp-7F8h] BYREF
char s2[1080]; // [rsp+420h] [rbp-438h] BYREF

v13 = 100000;
do
{
v2 = func6("127.0.0.1", port);
if ( (v2 & 0x80000000) == 0 )
{
while ( 1 )
{
strcpy((char *)s1, "+PING xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
s1[7] = 0LL;
memset(v15, 0, sizeof(v15));
v11 = func2();
if ( coro_write(v2, s1, 1024LL) != 1024 )
{
v0 = _errno_location();
v1 = strerror(*v0);
printf("errno = %d, errmsg = %s\n", (unsigned int)*v0, v1);
printf("%d write failed close\n", v2);
close(v2);
goto LABEL_3;
}
v6 = coro_read_fully(v2, s2, 1024LL);
v7 = v6;
if ( v6 < 0 )
break;
if ( !v6 )
goto LABEL_7;
if ( memcmp(s1, s2, 0x400uLL) )
_assert_fail("memcmp(msg, buff, 1024) == 0", "main.c", 0xF4u, "client_main");
++total;
v8 = func2() - v11;
func0(v8);
sptime += v8;
if ( total == 100000 * (total / 100000) )
{
v5 = func2();
printf(
"client: rec = %d, totl = %llu, avg = %llu, sp = %llu, asp = %llu, poll = %d,%d\n",
(unsigned int)total,
v5 - beg,
(v5 - beg) / (unsigned __int64)total,
sptime,
sptime / (unsigned __int64)total,
(unsigned int)pollnum,
(unsigned int)pollnum2);
printf(
"summ: %d %d %d %d %d %d %d %d %d\n",
(unsigned int)tootm[0],
(unsigned int)tootm[1],
(unsigned int)tootm[2],
(unsigned int)tootm[3],
(unsigned int)tootm[4],
(unsigned int)tootm[5],
(unsigned int)tootm[6],
(unsigned int)tootm[7],
(unsigned int)tootm[8]);
}
coro_yield();
}
v12 = _errno_location();
v3 = strerror(*v12);
printf("errno = %d, errmsg = %s\n", (unsigned int)*v12, v3);
v4 = func2();
printf("%d read failed close %llu, %d %d\n", v2, v4 - v11, v7, 1024LL);
LABEL_7:
close(v2);
}
else
{
puts("connect failed");
coro_yield();
}
LABEL_3:
--v13;
}
while ( v13 );
result = 100000 * (total / 100000);
if ( total == result )
{
v10 = func2();
printf(
"client: rec = %d, totl = %llu, avg = %llu, pollnum = %d\n",
(unsigned int)total,
v10 - beg,
(v10 - beg) / (unsigned __int64)total,
(unsigned int)pollnum);
result = printf(
"summ: %d %d %d %d %d %d %d %d %d\n",
(unsigned int)tootm[0],
(unsigned int)tootm[1],
(unsigned int)tootm[2],
(unsigned int)tootm[3],
(unsigned int)tootm[4],
(unsigned int)tootm[5],
(unsigned int)tootm[6],
(unsigned int)tootm[7],
(unsigned int)tootm[8]);
}
return result;
}

original_code:
void client_main(void *argv)
{
    int i = 0;
    for (i = 0; i < 100000; i++) {
        int fd = create_connecter("127.0.0.1", port);
        if (fd < 0) {
            printf("connect failed\n");
            coro_yield();
            continue;
        }
        for (;;) {
            char msg[1024] = "+PING xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
            char buff[1024];
            unsigned long long st = st_mstime();
            unsigned long long et = 0;
            ssize_t w = coro_write(fd, msg, 1024);
            ssize_t r = 0;
            if (w != 1024) {
                printf("errno = %d, errmsg = %s\n", (*__errno_location ()), strerror((*__errno_location ())));
                printf("%d write failed close\n", fd);
                close(fd);
                break;
            }
            r = coro_read_fully(fd, buff, w);
            if (r < 0) {
                printf("errno = %d, errmsg = %s\n", (*__errno_location ()), strerror((*__errno_location ())));
                printf("%d read failed close %llu, %d %d\n", fd, st_mstime() - st, (int)r, (int)w);
            }
            if (r <= 0) {
                close(fd);
                break;
            }
            ((void) sizeof ((memcmp(msg, buff, 1024) == 0) ? 1 : 0), __extension__ ({ if (memcmp(msg, buff, 1024) == 0) ; else __assert_fail ("memcmp(msg, buff, 1024) == 0", "main.c", 244, __extension__ __PRETTY_FUNCTION__); }));
            total++;
            et = st_mstime();
            summ(et - st);
            sptime += et - st;
            if (total % 100000 == 0) {
                unsigned long long t = st_mstime() - beg;
                printf("client: rec = %d, totl = %llu, avg = %llu, sp = %llu, asp = %llu, poll = %d,%d\n", total, t, t / total, sptime, sptime / total, pollnum,pollnum2);
                printf("summ: %d %d %d %d %d %d %d %d %d\n", tootm[0], tootm[1], tootm[2], tootm[3], tootm[4], tootm[5],tootm[6],tootm[7],tootm[8]);
            }
            coro_yield();
        }
    }
    if (total % 100000 == 0) {
        unsigned long long t = st_mstime() - beg;
        printf("client: rec = %d, totl = %llu, avg = %llu, pollnum = %d\n", total, t, t / total, pollnum);
        printf("summ: %d %d %d %d %d %d %d %d %d\n", tootm[0], tootm[1], tootm[2], tootm[3], tootm[4], tootm[5],tootm[6],tootm[7],tootm[8]);
    }
}

canonical_original_code:
void client_main(void *argv)
{
    int i = 0;
    for (i = 0; i < 100000; i++) {
        int fd = create_connecter("127.0.0.1", port);
        if (fd < 0) {
            printf("connect failed\n");
            coro_yield();
            continue;
        }
        for (;;) {
            char msg[1024] = "+PING xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
            char buff[1024];
            unsigned long long st = st_mstime();
            unsigned long long et = 0;
            long w = coro_write(fd, msg, 1024);
            long r = 0;
            if (w != 1024) {
                printf("errno = %d, errmsg = %s\n", (*__errno_location ()), strerror((*__errno_location ())));
                printf("%d write failed close\n", fd);
                close(fd);
                break;
            }
            r = coro_read_fully(fd, buff, w);
            if (r < 0) {
                printf("errno = %d, errmsg = %s\n", (*__errno_location ()), strerror((*__errno_location ())));
                printf("%d read failed close %llu, %d %d\n", fd, st_mstime() - st, (int)r, (int)w);
            }
            if (r <= 0) {
                close(fd);
                break;
            }
            ((void) sizeof ((memcmp(msg, buff, 1024) == 0) ? 1 : 0), __extension__ ({ if (memcmp(msg, buff, 1024) == 0) ; else __assert_fail ("memcmp(msg, buff, 1024) == 0", "main.c", 244, __extension__ __PRETTY_FUNCTION__); }));
            total++;
            et = st_mstime();
            summ(et - st);
            sptime += et - st;
            if (total % 100000 == 0) {
                unsigned long long t = st_mstime() - beg;
                printf("client: rec = %d, totl = %llu, avg = %llu, sp = %llu, asp = %llu, poll = %d,%d\n", total, t, t / total, sptime, sptime / total, pollnum,pollnum2);
                printf("summ: %d %d %d %d %d %d %d %d %d\n", tootm[0], tootm[1], tootm[2], tootm[3], tootm[4], tootm[5],tootm[6],tootm[7],tootm[8]);
            }
            coro_yield();
        }
    }
    if (total % 100000 == 0) {
        unsigned long long t = st_mstime() - beg;
        printf("client: rec = %d, totl = %llu, avg = %llu, pollnum = %d\n", total, t, t / total, pollnum);
        printf("summ: %d %d %d %d %d %d %d %d %d\n", tootm[0], tootm[1], tootm[2], tootm[3], tootm[4], tootm[5],tootm[6],tootm[7],tootm[8]);
    }
}

variable_types:
argv
void *

variable_types: i int

variable_types:
msg
char [1024]

variable_types:
buff
char [1024]

variable_types:
st
unsigned long long

variable_types:
et
unsigned long long

variable_types: w long

variable_types: r long


decompiled_code:
int __fastcall server_lim(__int64 a1)
{
unsigned int v1; // ebp
int v2; // ebx
int *v3; // rbx
char *v4; // rax
int *v6; // rbx
char *v7; // rax
__suseconds_t v8; // rax
__suseconds_t v9; // r13
__int64 v10; // rax
unsigned __int64 v11; // rdi
_BYTE v12[1064]; // [rsp+0h] [rbp-428h] BYREF

v1 = *(_DWORD *)(a1 + 20);
v2 = 10000000;
do
{
v9 = st_mstime();
v10 = coro_read_fully(v1, v12, 1024LL);
if ( v10 <= 0 )
{
v3 = _errno_location();
v4 = strerror(*v3);
printf("errno = %d, errmsg = %s\n", (unsigned int)*v3, v4);
printf("%d read err, close\n", v1);
return close(v1);
}
if ( v10 != coro_write(v1, v12, v10) )
{
v6 = _errno_location();
v7 = strerror(*v6);
printf("errno = %d, errmsg = %s\n", (unsigned int)*v6, v7);
printf("%d write err, close\n", v1);
return close(v1);
}
++total;
v11 = st_mstime() - v9;
sptime += v11;
summ(v11);
if ( total == 100000 * (total / 100000) )
{
v8 = st_mstime();
printf(
"server: rec = %d, totl = %llu, avg = %llu, sp = %llu, asp = %llu, poll = %d,%d\n",
(unsigned int)total,
v8 - beg,
(v8 - beg) / (unsigned __int64)total,
sptime,
sptime / (unsigned __int64)total,
(unsigned int)pollnum,
(unsigned int)pollnum2);
printf(
"summ: %d %d %d %d %d %d %d %d %d\n",
(unsigned int)tootm[0],
(unsigned int)tootm[1],
(unsigned int)tootm[2],
(unsigned int)tootm[3],
(unsigned int)tootm[4],
(unsigned int)tootm[5],
(unsigned int)tootm[6],
(unsigned int)tootm[7],
(unsigned int)tootm[8]);
}
coro_yield();
--v2;
}
while ( v2 );
return close(v1);
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1)
{
unsigned int v1; // ebp
int v2; // ebx
int *v3; // rbx
char *v4; // rax
int *v6; // rbx
char *v7; // rax
__suseconds_t v8; // rax
__suseconds_t v9; // r13
__int64 v10; // rax
unsigned __int64 v11; // rdi
_BYTE v12[1064]; // [rsp+0h] [rbp-428h] BYREF

v1 = *(_DWORD *)(a1 + 20);
v2 = 10000000;
do
{
v9 = func2();
v10 = coro_read_fully(v1, v12, 1024LL);
if ( v10 <= 0 )
{
v3 = _errno_location();
v4 = strerror(*v3);
printf("errno = %d, errmsg = %s\n", (unsigned int)*v3, v4);
printf("%d read err, close\n", v1);
return close(v1);
}
if ( v10 != coro_write(v1, v12, v10) )
{
v6 = _errno_location();
v7 = strerror(*v6);
printf("errno = %d, errmsg = %s\n", (unsigned int)*v6, v7);
printf("%d write err, close\n", v1);
return close(v1);
}
++total;
v11 = func2() - v9;
sptime += v11;
func0(v11);
if ( total == 100000 * (total / 100000) )
{
v8 = func2();
printf(
"server: rec = %d, totl = %llu, avg = %llu, sp = %llu, asp = %llu, poll = %d,%d\n",
(unsigned int)total,
v8 - beg,
(v8 - beg) / (unsigned __int64)total,
sptime,
sptime / (unsigned __int64)total,
(unsigned int)pollnum,
(unsigned int)pollnum2);
printf(
"summ: %d %d %d %d %d %d %d %d %d\n",
(unsigned int)tootm[0],
(unsigned int)tootm[1],
(unsigned int)tootm[2],
(unsigned int)tootm[3],
(unsigned int)tootm[4],
(unsigned int)tootm[5],
(unsigned int)tootm[6],
(unsigned int)tootm[7],
(unsigned int)tootm[8]);
}
coro_yield();
--v2;
}
while ( v2 );
return close(v1);
}

original_code:
void server_lim(struct client *n)
{
    int fd = n->fd;
    char buff[1024];
    int i = 0;
    for (i = 0; i < 10000000; i++) {
        unsigned long long s = st_mstime();
        unsigned long long e = 0;
        ssize_t r = coro_read_fully(fd, buff, 1024);
        ssize_t w = 0;
        if (r <= 0) {
            printf("errno = %d, errmsg = %s\n", (*__errno_location ()), strerror((*__errno_location ())));
            printf("%d read err, close\n", fd);
            close(fd);
            return;
        }
        w = coro_write(fd, buff, r);
        if (w != r) {
            printf("errno = %d, errmsg = %s\n", (*__errno_location ()), strerror((*__errno_location ())));
            printf("%d write err, close\n", fd);
            close(fd);
            return;
        }
        total++;
        e = st_mstime();
        sptime += e - s;
        summ(e - s);
        if (total % 100000 == 0) {
            unsigned long long t = st_mstime() - beg;
            printf("server: rec = %d, totl = %llu, avg = %llu, sp = %llu, asp = %llu, poll = %d,%d\n", total, t, t / total, sptime, sptime / total, pollnum,pollnum2);
            printf("summ: %d %d %d %d %d %d %d %d %d\n", tootm[0], tootm[1], tootm[2], tootm[3], tootm[4], tootm[5],tootm[6],tootm[7],tootm[8]);
        }
        coro_yield();
    }
    close(fd);
}

canonical_original_code:
void server_lim(struct client *n)
{
    int fd = n->fd;
    char buff[1024];
    int i = 0;
    for (i = 0; i < 10000000; i++) {
        unsigned long long s = st_mstime();
        unsigned long long e = 0;
        long r = coro_read_fully(fd, buff, 1024);
        long w = 0;
        if (r <= 0) {
            printf("errno = %d, errmsg = %s\n", (*__errno_location ()), strerror((*__errno_location ())));
            printf("%d read err, close\n", fd);
            close(fd);
            return;
        }
        w = coro_write(fd, buff, r);
        if (w != r) {
            printf("errno = %d, errmsg = %s\n", (*__errno_location ()), strerror((*__errno_location ())));
            printf("%d write err, close\n", fd);
            close(fd);
            return;
        }
        total++;
        e = st_mstime();
        sptime += e - s;
        summ(e - s);
        if (total % 100000 == 0) {
            unsigned long long t = st_mstime() - beg;
            printf("server: rec = %d, totl = %llu, avg = %llu, sp = %llu, asp = %llu, poll = %d,%d\n", total, t, t / total, sptime, sptime / total, pollnum,pollnum2);
            printf("summ: %d %d %d %d %d %d %d %d %d\n", tootm[0], tootm[1], tootm[2], tootm[3], tootm[4], tootm[5],tootm[6],tootm[7],tootm[8]);
        }
        coro_yield();
    }
    close(fd);
}

variable_types: struct client { 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]; } addr; unsigned int addr_len; int fd; } *

variable_types:
s
unsigned long long

variable_types:
e
unsigned long long

variable_types:
t
unsigned long long

user_defined_types: struct client { struct sockaddr_in addr; unsigned int addr_len; int fd; }


decompiled_code:
void __noreturn server_main()
{
_BYTE v0[16]; // [rsp+0h] [rbp-28h] BYREF
int v1; // [rsp+10h] [rbp-18h] BYREF
int v2; // [rsp+14h] [rbp-14h]

while ( 1 )
{
v1 = 16;
v2 = coro_accept((unsigned int)listfd, v0, &v1);
if ( v2 >= 0 )
{
++accnum;
coro_create(server_main, 0LL);
server_lim((__int64)v0);
}
else
{
coro_yield();
}
}
}

canonical_decompiled_code:
void __noreturn func9()
{
_BYTE v0[16]; // [rsp+0h] [rbp-28h] BYREF
int v1; // [rsp+10h] [rbp-18h] BYREF
int v2; // [rsp+14h] [rbp-14h]

while ( 1 )
{
v1 = 16;
v2 = coro_accept((unsigned int)listfd, v0, &v1);
if ( v2 >= 0 )
{
++accnum;
coro_create(server_main, 0LL);
func8((__int64)v0);
}
else
{
coro_yield();
}
}
}

original_code:
void server_main(void)
{
    for (;;) {
        struct client client;
        client.addr_len = sizeof(client.addr);
        client.fd = coro_accept(listfd, (struct sockaddr *)&client.addr, &client.addr_len);
        if (client.fd >= 0) {
            accnum++;
            coro_create((void (*)(void *))server_main, ((void *)0));
            server_lim(&client);
        } else {
            coro_yield();
        }
    }
}

canonical_original_code:
void server_main()
{
    for (;;) {
        struct client client;
        client.addr_len = sizeof(client.addr);
        client.fd = coro_accept(listfd, (struct sockaddr *)&client.addr, &client.addr_len);
        if (client.fd >= 0) {
            accnum++;
            coro_create((void (*)(void *))server_main, ((void *)0));
            server_lim(&client);
        } else {
            coro_yield();
        }
    }
}

variable_types: struct client { 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]; } addr; unsigned int addr_len; int fd; }


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebx
int v5; // ebx
int *v6; // rbx
char *v7; // rax

coro_init(0x2000LL, argv, envp);
beg = st_mstime();
v3 = atoi(argv[2]);
port = v3;
v4 = 200;
if ( !strcmp(argv[1], "client") )
{
do
{
coro_create(client_main, 0LL);
--v4;
}
while ( v4 );
}
else
{
listfd = create_listener("127.0.0.1", v3);
v5 = 50;
if ( listfd == -1 )
{
v6 = _errno_location();
v7 = strerror(*v6);
printf("listen failed: %d, %s\n", (unsigned int)*v6, v7);
exit(1);
}
do
{
coro_create(server_main, 0LL);
--v5;
}
while ( v5 );
}
while ( 1 )
coro_yield();
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebx
int v5; // ebx
int *v6; // rbx
char *v7; // rax

coro_init(0x2000LL, argv, envp);
beg = func2();
v3 = atoi(argv[2]);
port = v3;
v4 = 200;
if ( !strcmp(argv[1], "client") )
{
do
{
coro_create(client_main, 0LL);
--v4;
}
while ( v4 );
}
else
{
listfd = func5("127.0.0.1", v3);
v5 = 50;
if ( listfd == -1 )
{
v6 = _errno_location();
v7 = strerror(*v6);
printf("listen failed: %d, %s\n", (unsigned int)*v6, v7);
exit(1);
}
do
{
coro_create(server_main, 0LL);
--v5;
}
while ( v5 );
}
while ( 1 )
coro_yield();
}

original_code:
int main(int argc, char *argv[])
{
    int i = 0;
    coro_init(8 * 1024);
    beg = st_mstime();
    port = atoi(argv[2]);
    if (strcmp(argv[1], "client") != 0) {
        listfd = create_listener("127.0.0.1", port);
        if (listfd == -1) {
            printf("listen failed: %d, %s\n", (*__errno_location ()), strerror((*__errno_location ())));
            exit(1);
        }
        for (i = 0; i < 50; i++)
            coro_create((void (*)(void *))server_main, ((void *)0));
    } else {
        for (i = 0; i < 200; i++) {
            coro_create(client_main, ((void *)0));
        }
    }
    for (;;) {
        coro_yield();
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


repo: neilalexander/sigmavpn

original_code:
size_t hex2bin(uint8_t* dest, const char* src, size_t count)
{
    size_t i;
    for (i = 0; i < count; i++)
    {
        if (*src >= '0' && *src <= '9') *dest = *src - '0';
        else if (*src >= 'a' && * src <='f') *dest = *src - 'a' + 10;
        else if (*src >= 'A' && * src <='F') *dest = *src - 'A' + 10;
        else break;
        src++; *dest = *dest << 4;
        if (*src >= '0' && *src <= '9') *dest += *src - '0';
        else if (*src >= 'a' && *src <= 'f') *dest += *src - 'a' + 10;
        else if (*src >= 'A' && *src <= 'F') *dest += *src - 'A' + 10;
        else break;
        src++; dest++;
    }
    return i;
}

canonical_original_code:
unsigned long hex2bin(unsigned char *dest, char *src, unsigned long count)
{
    unsigned long i;
    for (i = 0; i < count; i++)
    {
        if (*src >= '0' && *src <= '9') *dest = *src - '0';
        else if (*src >= 'a' && * src <='f') *dest = *src - 'a' + 10;
        else if (*src >= 'A' && * src <='F') *dest = *src - 'A' + 10;
        else break;
        src++; *dest = *dest << 4;
        if (*src >= '0' && *src <= '9') *dest += *src - '0';
        else if (*src >= 'a' && *src <= 'f') *dest += *src - 'a' + 10;
        else if (*src >= 'A' && *src <= 'F') *dest += *src - 'A' + 10;
        else break;
        src++; dest++;
    }
    return i;
}

variable_types:
dest
unsigned char *

variable_types:
src
char *

variable_types:
count
unsigned long

variable_types:
i
unsigned long


decompiled_code:
void __fastcall u32_pack(_DWORD *a1, unsigned int a2)
{
*a1 = _byteswap_ulong(a2);
}

canonical_decompiled_code:
void __fastcall func13(_DWORD *a1, unsigned int a2)
{
*a1 = _byteswap_ulong(a2);
}

original_code:
void u32_pack(uint8_t * buf, uint32_t val)
{
        asm(
            "bswap %0\n"
            "mov %0, (%1)\n"
            :
            :"r"(val), "r"(buf)
        );
}

canonical_original_code:
void u32_pack(unsigned char *buf, unsigned int val)
{
        asm(
            "bswap %0\n"
            "mov %0, (%1)\n"
            :
            :"r"(val), "r"(buf)
        );
}

variable_types:
buf
unsigned char *

variable_types:
val
unsigned int


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

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

original_code:
uint32_t u32_unpack(const uint8_t * buf)
{
    uint32_t val;
        asm(
            "mov (%1), %0\n"
            "bswap %0\n"
            :"=r"(val)
            :"r"(buf)
        );
    return val;
}

canonical_original_code:
unsigned int u32_unpack(unsigned char *buf)
{
    unsigned int val;
        asm(
            "mov (%1), %0\n"
            "bswap %0\n"
            :"=r"(val)
            :"r"(buf)
        );
    return val;
}


decompiled_code:
void __fastcall u64_pack(_QWORD *a1, unsigned __int64 a2)
{
*a1 = _byteswap_uint64(a2);
}

canonical_decompiled_code:
void __fastcall func15(_QWORD *a1, unsigned __int64 a2)
{
*a1 = _byteswap_uint64(a2);
}

original_code:
void u64_pack(uint8_t * buf, uint64_t val)
{
        asm(
            "bswap %0\n"
            "mov %0, (%1)\n"
            :
            :"r"(val), "r"(buf)
        );
}

canonical_original_code:
void u64_pack(unsigned char *buf, unsigned long val)
{
        asm(
            "bswap %0\n"
            "mov %0, (%1)\n"
            :
            :"r"(val), "r"(buf)
        );
}

variable_types:
val
unsigned long


decompiled_code:
unsigned __int64 __fastcall u64_unpack(unsigned __int64 *a1)
{
return _byteswap_uint64(*a1);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func16(unsigned __int64 *a1)
{
return _byteswap_uint64(*a1);
}

original_code:
uint64_t u64_unpack(const uint8_t * buf)
{
    uint64_t val;
        asm(
            "mov (%1), %0\n"
            "bswap %0\n"
            :"=r"(val)
            :"r"(buf)
        );
    return val;
}

canonical_original_code:
unsigned long u64_unpack(unsigned char *buf)
{
    unsigned long val;
        asm(
            "mov (%1), %0\n"
            "bswap %0\n"
            :"=r"(val)
            :"r"(buf)
        );
    return val;
}


decompiled_code:
__int64 __fastcall taia_pack(__int64 a1, __int64 a2)
{
u64_pack(a1, *(_QWORD *)a2);
u32_pack(a1 + 8, *(unsigned int *)(a2 + 8));
return u32_pack(a1 + 12, *(unsigned int *)(a2 + 12));
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, __int64 a2)
{
func15(a1, *(_QWORD *)a2);
func13(a1 + 8, *(unsigned int *)(a2 + 8));
return func13(a1 + 12, *(unsigned int *)(a2 + 12));
}

original_code:
void taia_pack(uint8_t *s, const struct taia *t)
{
    u64_pack(s, t->sec);
    u32_pack(s + 8, t->nano);
    u32_pack(s + 12, t->atto);
}

canonical_original_code:
void taia_pack(unsigned char *s, struct taia *t)
{
    u64_pack(s, t->sec);
    u32_pack(s + 8, t->nano);
    u32_pack(s + 12, t->atto);
}

variable_types:
s
unsigned char *

variable_types: struct taia { unsigned long sec; unsigned int nano; unsigned int atto; } *


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

*(_QWORD *)a2 = u64_unpack();
*(_DWORD *)(a2 + 8) = u32_unpack(a1 + 8);
result = u32_unpack(a1 + 12);
*(_DWORD *)(a2 + 12) = result;
return result;
}

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

*(_QWORD *)a2 = func16();
*(_DWORD *)(a2 + 8) = func14(a1 + 8);
result = func14(a1 + 12);
*(_DWORD *)(a2 + 12) = result;
return result;
}

original_code:
void taia_unpack(const uint8_t *s, struct taia *t)
{
    t->sec = u64_unpack(s);
    t->nano = u32_unpack(s + 8);
    t->atto = u32_unpack(s + 12);
}

canonical_original_code:
void taia_unpack(unsigned char *s, struct taia *t)
{
    t->sec = u64_unpack(s);
    t->nano = u32_unpack(s + 8);
    t->atto = u32_unpack(s + 12);
}

user_defined_types: struct taia { unsigned long sec; unsigned int nano; unsigned int atto; }