decompiled_code:
char *test_fseek()
{
int v0; // eax
int v1; // ebp
int buf; // [rsp+Ch] [rbp-Ch] BYREF

if ( writeFile() < 0 )
return build_failure_message("error in creating file");
v0 = open("input.bin", 0);
v1 = v0;
if ( v0 < 0 )
return build_failure_message("error in opening file");
buf = 0;
lseek(v0, 3LL, 0);
if ( read(v1, &buf, 4uLL) != 4 )
return build_failure_message("error in reading file");
printf(
"buffer content %i %i %i %i\n",
(unsigned int)(char)buf,
(unsigned int)SBYTE1(buf),
(unsigned int)SBYTE2(buf),
(unsigned int)SHIBYTE(buf));
if ( (_WORD)buf != 1281 || !BYTE2(buf) || !HIBYTE(buf) )
return build_failure_message("wrong content");
close(v1);
return 0LL;
}

canonical_decompiled_code:
char *func9()
{
int v0; // eax
int v1; // ebp
int buf; // [rsp+Ch] [rbp-Ch] BYREF

if ( func7() < 0 )
return func8("error in creating file");
v0 = open("input.bin", 0);
v1 = v0;
if ( v0 < 0 )
return func8("error in opening file");
buf = 0;
lseek(v0, 3LL, 0);
if ( read(v1, &buf, 4uLL) != 4 )
return func8("error in reading file");
printf(
"buffer content %i %i %i %i\n",
(unsigned int)(char)buf,
(unsigned int)SBYTE1(buf),
(unsigned int)SBYTE2(buf),
(unsigned int)SHIBYTE(buf));
if ( (_WORD)buf != 1281 || !BYTE2(buf) || !HIBYTE(buf) )
return func8("wrong content");
close(v1);
return 0LL;
}

original_code:
static char * test_fseek() {
     do { if (!(writeFile()>=0)) return build_failure_message("error in creating file"); } while (0);
     int fileDescr=open("input.bin", 00);
     do { if (!(fileDescr>=0)) return build_failure_message("error in opening file"); } while (0);
     char buffer[4];
     bzero(buffer, 4);
     lseek(fileDescr,3, 0);
     ssize_t bytesRead=read(fileDescr, buffer, 4);
     do { if (!(bytesRead==4)) return build_failure_message("error in reading file"); } while (0);
printf("buffer content %i %i %i %i\n", buffer[0], buffer[1], buffer[2],
buffer[3]);
do { if (!(buffer[0]==1 && buffer[1]==5 && buffer[2] && buffer[3])) return build_failure_message("wrong content"); } while (0);
     close(fileDescr);
     return 0;
 }

canonical_original_code:
static char *test_fseek() {
     do { if (!(writeFile()>=0)) return build_failure_message("error in creating file"); } while (0);
     int fileDescr = open("input.bin", 00);
     do { if (!(fileDescr>=0)) return build_failure_message("error in opening file"); } while (0);
     char buffer[4];
     bzero(buffer, 4);
     lseek(fileDescr,3, 0);
     long bytesRead = read(fileDescr, buffer, 4);
     do { if (!(bytesRead==4)) return build_failure_message("error in reading file"); } while (0);
printf("buffer content %i %i %i %i\n", buffer[0], buffer[1], buffer[2],
buffer[3]);
do { if (!(buffer[0]==1 && buffer[1]==5 && buffer[2] && buffer[3])) return build_failure_message("wrong content"); } while (0);
     close(fileDescr);
     return 0;
 }

variable_types:
buffer
char [4]

variable_types: bytesRead long


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rax
const char *v4; // rbx

v3 = (const char *)all_tests(argc, argv, envp);
v4 = v3;
if ( v3 )
puts(v3);
else
puts("ALL TESTS PASSED");
printf("Tests run: %d\n", (unsigned int)tests_run);
return v4 != 0LL;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rax
const char *v4; // rbx

v3 = (const char *)func10(argc, argv, envp);
v4 = v3;
if ( v3 )
puts(v3);
else
puts("ALL TESTS PASSED");
printf("Tests run: %d\n", (unsigned int)tests_run);
return v4 != 0LL;
}

original_code:
int main(int argc, char **argv) {
     char *result = all_tests();
     if (result != 0) {
         printf("%s\n", result);
     }
     else {
         printf("ALL TESTS PASSED\n");
     }
     printf("Tests run: %d\n", tests_run);
     return result != 0;
 }

variable_types: argc int

variable_types:
argv
char **

variable_types:
result
char *

return_type: int


decompiled_code:
char *all_tests()
{
char *result; // rax

result = test_fseek();
++tests_run;
return result;
}

canonical_decompiled_code:
char *func10()
{
char *result; // rax

result = func9();
++tests_run;
return result;
}

original_code:
static char * all_tests() {
     do { char *message = test_fseek(); tests_run++; if (message) return message; } while (0);
     return 0;
 }

canonical_original_code:
static char *all_tests() {
     do { char *message = test_fseek(); tests_run++; if (message) return message; } while (0);
     return 0;
 }

variable_types:
message
char *

return_type: char *


decompiled_code:
const char *test_foo()
{
const char *result; // rax

result = "error, foo != 7";
if ( foo == 7 )
result = 0LL;
return result;
}

canonical_decompiled_code:
const char *func7()
{
const char *result; // rax

result = "error, foo != 7";
if ( foo == 7 )
result = 0LL;
return result;
}

original_code:
static char * test_foo() {
     do { if (!(foo == 7)) return "error, foo != 7"; } while (0);
     return 0;
 }

canonical_original_code:
static char *test_foo() {
     do { if (!(foo == 7)) return "error, foo != 7"; } while (0);
     return 0;
 }


decompiled_code:
const char *test_bar()
{
const char *result; // rax

result = "error, bar != 5";
if ( bar == 5 )
result = 0LL;
return result;
}

canonical_decompiled_code:
const char *func8()
{
const char *result; // rax

result = "error, bar != 5";
if ( bar == 5 )
result = 0LL;
return result;
}

original_code:
static char * test_bar() {
     do { if (!(bar == 5)) return "error, bar != 5"; } while (0);
     return 0;
 }

canonical_original_code:
static char *test_bar() {
     do { if (!(bar == 5)) return "error, bar != 5"; } while (0);
     return 0;
 }


canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rax
const char *v4; // rbx

v3 = (const char *)func9(argc, argv, envp);
v4 = v3;
if ( v3 )
puts(v3);
else
puts("ALL TESTS PASSED");
printf("Tests run: %d\n", (unsigned int)tests_run);
return v4 != 0LL;
}

canonical_original_code:
int main(int argc, char **argv) {
     char *result = all_tests();
     if (result != 0) {
         printf("%s\n", result);
     }
     else {
         printf("ALL TESTS PASSED\n");
     }
     printf("Tests run: %d\n", tests_run);
     return result != 0;
 }


decompiled_code:
const char *all_tests()
{
const char *result; // rax
int v1; // ecx

result = test_foo();
++tests_run;
if ( !result )
{
result = test_bar();
tests_run = v1 + 2;
}
return result;
}

canonical_decompiled_code:
const char *func9()
{
const char *result; // rax
int v1; // ecx

result = func7();
++tests_run;
if ( !result )
{
result = func8();
tests_run = v1 + 2;
}
return result;
}

original_code:
static char * all_tests() {
     do { char *message = test_foo(); tests_run++; if (message) return message; } while (0);
     do { char *message = test_bar(); tests_run++; if (message) return message; } while (0);
     return 0;
 }

canonical_original_code:
static char *all_tests() {
     do { char *message = test_foo(); tests_run++; if (message) return message; } while (0);
     do { char *message = test_bar(); tests_run++; if (message) return message; } while (0);
     return 0;
 }


decompiled_code:
const char *__fastcall get_string(const char *a1)
{
return "get_string\n";
}

canonical_decompiled_code:
const char *__fastcall func7(const char *a1)
{
return "get_string\n";
}

original_code:
char* get_string()
{
  return "get_string\n";
}

canonical_original_code:
char *get_string()
{
  return "get_string\n";
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
char v5[72]; // [rsp+0h] [rbp-48h] BYREF

puts("Ciao");
v3 = (const char *)get_string("%s", (const char *)argv);
printf("%s", v3);
strcpy(v5, v3);
printf("%s", v5);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
char v5[72]; // [rsp+0h] [rbp-48h] BYREF

puts("Ciao");
v3 = (const char *)func7("%s", (const char *)argv);
printf("%s", v3);
strcpy(v5, v3);
printf("%s", v5);
return 0;
}

original_code:
int main(int argc, char **argv) {
  printf("Ciao\n");
  printf("%s", get_string());
  char fmt[50];
  sprintf(fmt, "%s",get_string());
  printf("%s",fmt);
  return 0;
 }

variable_types:
fmt
char [50]


repo: eeezyy/FileTransfer

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er14
__int16 v4; // ax
__int16 v5; // ax
const char *v6; // rdi
char *v7; // rax
int v8; // eax
size_t v9; // rdx
char *v10; // rax
char *v11; // rax
int v12; // eax
int v13; // ebp
size_t v14; // rax
char *v15; // rsi
size_t v16; // rax
int v17; // eax
__int64 v18; // rax
__int64 v19; // rbx
size_t v21; // rax
size_t v22; // rax
char *v23; // rsi
bool v24; // zf
__off_t v25; // rbx
size_t v26; // rax
int v27; // er12
int v28; // er14
double v29; // xmm0_8
double v30; // xmm1_8
double v31; // xmm0_8
__int64 v32; // rbx
int v33; // er13
int v34; // er13
int v35; // eax
int v36; // er12
int v37; // er13
int v38; // er14
double v39; // xmm0_8
int v40; // eax
int v41; // er12
size_t v42; // rax
int i; // er13
int v44; // eax
int v45; // er12
int v46; // er14
int v47; // [rsp+Ch] [rbp-310Ch]
__off_t v48; // [rsp+10h] [rbp-3108h]
int v49; // [rsp+10h] [rbp-3108h]
__off_t v50; // [rsp+18h] [rbp-3100h]
FILE *v51; // [rsp+18h] [rbp-3100h]
FILE *stream; // [rsp+20h] [rbp-30F8h]
int v53; // [rsp+28h] [rbp-30F0h]
int v54; // [rsp+28h] [rbp-30F0h]
int fd; // [rsp+2Ch] [rbp-30ECh]
int v56; // [rsp+38h] [rbp-30E0h]
struct sockaddr addr; // [rsp+40h] [rbp-30D8h] BYREF
struct stat v58; // [rsp+50h] [rbp-30C8h] BYREF
char v59[1024]; // [rsp+E0h] [rbp-3038h] BYREF
char file[8]; // [rsp+4E0h] [rbp-2C38h] BYREF
__int64 v61; // [rsp+4E8h] [rbp-2C30h]
char v62[1008]; // [rsp+4F0h] [rbp-2C28h] BYREF
int buf[512]; // [rsp+8E0h] [rbp-2838h] BYREF
char nptr[2048]; // [rsp+10E0h] [rbp-2038h] BYREF
char s[2048]; // [rsp+18E0h] [rbp-1838h] BYREF
char filename[8]; // [rsp+20E0h] [rbp-1038h] BYREF
__int64 v67; // [rsp+20E8h] [rbp-1030h]
char v68[1008]; // [rsp+20F0h] [rbp-1028h] BYREF
char dest[16]; // [rsp+28E0h] [rbp-838h] BYREF
char v70[2032]; // [rsp+28F0h] [rbp-828h] BYREF

if ( argc <= 2 )
{
fprintf(stderr, "Usage: %s IP-Adresse Port-Nummer\n", *argv);
exit(1);
}
v3 = socket(2, 1, 0);
if ( v3 == -1 )
{
perror("Socket error");
return 1;
}
v4 = strtol(argv[2], 0LL, 10);
addr = 0LL;
addr.sa_family = 2;
v5 = _bswap_16(v4);
v6 = argv[1];
*(_WORD *)addr.sa_data = v5;
inet_aton(v6, (struct in_addr *)&addr.sa_data[2]);
v47 = connect(v3, &addr, 0x10u);
if ( v47 )
{
perror("Connect error - no server available");
return 1;
}
v7 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
printf("Connection with server(%s) established\n", v7);
v8 = recv(v3, buf, 0x7FFuLL, 0);
if ( v8 > 0 )
{
*((_BYTE *)buf + v8) = 0;
printf("%s", (const char *)buf);
}
printf("Username: ");
fgets((char *)buf, 2047, stdin);
v9 = strlen((const char *)buf);
if ( v9 <= 1 )
{
strcpy((char *)buf, "null");
send(v3, buf, 4uLL, 0);
v21 = strlen((const char *)buf);
send(v3, buf, v21, 0);
close(v3);
fwrite("User invalid\n", 1uLL, 0xDuLL, stderr);
return 1;
}
send(v3, buf, v9, 0);
v10 = getpass("Password: ");
v11 = stpcpy((char *)buf, v10);
if ( !LOBYTE(buf[0]) )
{
strcpy((char *)buf, "null");
send(v3, buf, 4uLL, 0);
close(v3);
fwrite("User or password invalid\n", 1uLL, 0x19uLL, stderr);
return 1;
}
send(v3, buf, v11 - (char *)buf, 0);
v12 = recv(v3, buf, 0x7FFuLL, 0);
if ( v12 > 0 )
{
*((_BYTE *)buf + v12) = 0;
puts((const char *)buf);
}
if ( !strcmp((const char *)buf, "Username or password invalid\n") || !strcmp((const char *)buf, "User is blocked!\n") )
goto LABEL_26;
LABEL_12:
while ( 2 )
{
while ( 2 )
{
while ( 2 )
{
while ( 2 )
{
printf("Send command: ");
fgets((char *)buf, 2047, stdin);
if ( !memcmp(buf, "list", 4uLL) )
{
v13 = 1;
}
else if ( LOBYTE(buf[0]) == 103 && *(_WORD *)((char *)buf + 1) == 29797 )
{
v13 = 2;
*(_OWORD *)dest = 0LL;
memset(v70, 0, sizeof(v70));
v14 = strlen((const char *)buf);
if ( v14 != 3 )
{
strncpy(dest, (const char *)buf + 3, v14 - 3);
v15 = strtok(dest, " \n\r");
if ( !v15 )
continue;
v13 = 2;
strcpy(v59, v15);
}
}
else if ( !memcmp(buf, "send", 4uLL) )
{
v13 = 3;
*(_OWORD *)dest = 0LL;
memset(v70, 0, sizeof(v70));
v22 = strlen((const char *)buf);
if ( v22 != 4 )
{
strncpy(dest, (const char *)&buf[1], v22 - 4);
v23 = strtok(dest, " \n\r");
if ( !v23 )
continue;
v13 = 3;
strcpy(v59, v23);
}
}
else if ( !memcmp(buf, "blocklist", 9uLL) )
{
v13 = 4;
}
else
{
v24 = memcmp(buf, "quit", 4uLL) == 0;
v13 = !v24;
if ( !v24 )
continue;
}
break;
}
v16 = strlen((const char *)buf);
send(v3, buf, v16, 0);
v17 = recv(v3, nptr, 0x7FFuLL, 0);
if ( v17 > 0 )
nptr[v17] = 0;
v18 = strtol(nptr, 0LL, 10);
v19 = v18;
if ( v18 == -1 )
{
if ( v13 != 2 )
goto LABEL_25;
LABEL_39:
puts("File not found!");
continue;
}
break;
}
switch ( v13 )
{
case 1:
send(v3, buf, 1uLL, 0);
if ( v19 <= 0 )
goto LABEL_69;
v34 = 0;
while ( 1 )
{
v35 = recv(v3, buf, 0x7FFuLL, 0);
v36 = v35;
if ( v35 <= 0 )
{
if ( !v35 )
{
LABEL_68:
puts("connect to socket failed");
goto LABEL_69;
}
if ( v35 == -1 )
puts("error in socket");
}
else
{
*((_BYTE *)buf + v35) = 0;
printf("%s", (const char *)buf);
fflush(stdout);
}
v34 += v36;
if ( v34 >= v19 )
goto LABEL_69;
}
case 2:
printf("Size of selected File is %ld bytes\nDo you want to download the file? (y/n)", v18);
while ( 1 )
{
fgets((char *)buf, 2047, stdin);
if ( LOBYTE(buf[0]) == 121 )
break;
if ( LOBYTE(buf[0]) == 110 )
{
LOWORD(buf[0]) = 110;
send(v3, buf, 1uLL, 0);
goto LABEL_12;
}
printf("Invalid input. (y/n) ");
}
LOWORD(buf[0]) = 121;
v37 = v19;
send(v3, buf, 1uLL, 0);
*(_QWORD *)filename = 12078LL;
v67 = 0LL;
memset(v68, 0, sizeof(v68));
strcpy(&filename[2], v59);
v49 = 0;
v51 = fopen(filename, "wb");
v54 = v3;
while ( 1 )
{
if ( v37 <= 0 )
{
v3 = v54;
goto LABEL_106;
}
*(_OWORD *)dest = 0LL;
memset(v70, 0, sizeof(v70));
v40 = recv(v54, dest, 0x7FFuLL, 0);
v41 = v40;
if ( v40 <= 0 )
{
if ( !v40 )
{
v3 = v54;
puts("connect to socket failed");
goto LABEL_106;
}
if ( v40 == -1 )
{
v3 = v54;
puts("error in socket");
LABEL_106:
putchar(10);
fclose(v51);
goto LABEL_12;
}
v38 = v40;
}
else
{
v38 = v40;
fwrite(dest, 1uLL, v40, v51);
}
v39 = (double)(v38 + (int)v19 - v37) / (double)(int)v19 * 20.0;
if ( (int)v39 - v49 >= 0 )
{
if ( (int)v39 != v49 )
{
v46 = 0;
do
{
++v46;
putchar(35);
fflush(stdout);
}
while ( (int)v39 - v49 != v46 );
v49 = (int)v39;
}
if ( v49 == 20 )
puts("!");
}
v37 -= v41;
}
case 3:
*(_QWORD *)file = 12078LL;
memset(v62, 0, sizeof(v62));
v61 = 0LL;
strcpy(&file[2], v59);
if ( stat(file, &v58) != -1 )
{
v25 = v58.st_size;
v50 = v58.st_size;
sprintf(s, "%ld", v58.st_size);
v26 = strlen(s);
send(v3, s, v26, 0);
recv(v3, filename, 1uLL, 0);
stream = fopen(file, "rb");
if ( stream )
{
v27 = v25;
if ( (int)v25 > 0 )
{
fd = v3;
v48 = v25 - (int)v25;
v28 = 2047;
v53 = 0;
v56 = v25 & 1;
do
{
if ( v27 <= 2046 )
v28 = v27;
fread(dest, v28, 1uLL, stream);
send(fd, dest, v28, 0);
v32 = v48 + v28;
if ( v32 >= 0 )
v29 = (double)(int)v32;
else
v29 = (double)(int)(v32 & 1 | ((unsigned __int64)v32 >> 1))
+ (double)(int)(v32 & 1 | ((unsigned __int64)v32 >> 1));
if ( v50 < 0 )
v30 = (double)(int)(v56 | ((unsigned __int64)v50 >> 1))
+ (double)(int)(v56 | ((unsigned __int64)v50 >> 1));
else
v30 = (double)(int)v50;
v31 = v29 / v30 * 20.0;
if ( (int)v31 - v53 >= 0 )
{
if ( (int)v31 != v53 )
{
v33 = 0;
do
{
++v33;
putchar(35);
fflush(stdout);
}
while ( (int)v31 - v53 != v33 );
v53 = (int)v31;
}
if ( v53 == 20 )
puts("!");
}
v48 += 2047LL;
v27 -= 2047;
}
while ( v27 > 0 );
v3 = fd;
}
putchar(10);
fclose(stream);
}
else
{
puts("can't open file");
}
continue;
}
sprintf(s, "%ld", -1LL);
v42 = strlen(s);
send(v3, s, v42, 0);
goto LABEL_39;
case 4:
send(v3, buf, 1uLL, 0);
if ( v19 > 0 )
{
for ( i = 0; i < v19; i += v45 )
{
v44 = recv(v3, buf, 0x7FFuLL, 0);
v45 = v44;
if ( v44 <= 0 )
{
if ( !v44 )
goto LABEL_68;
if ( v44 == -1 )
puts("error in socket");
}
else
{
*((_BYTE *)buf + v44) = 0;
printf("%s", (const char *)buf);
fflush(stdout);
}
}
}
LABEL_69:
putchar(10);
break;
}
break;
}
LABEL_25:
if ( v13 )
continue;
break;
}
LABEL_26:
close(v3);
return v47;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er14
__int16 v4; // ax
__int16 v5; // ax
const char *v6; // rdi
char *v7; // rax
int v8; // eax
size_t v9; // rdx
char *v10; // rax
char *v11; // rax
int v12; // eax
int v13; // ebp
size_t v14; // rax
char *v15; // rsi
size_t v16; // rax
int v17; // eax
__int64 v18; // rax
__int64 v19; // rbx
size_t v21; // rax
size_t v22; // rax
char *v23; // rsi
bool v24; // zf
__off_t v25; // rbx
size_t v26; // rax
int v27; // er12
int v28; // er14
double v29; // xmm0_8
double v30; // xmm1_8
double v31; // xmm0_8
__int64 v32; // rbx
int v33; // er13
int v34; // er13
int v35; // eax
int v36; // er12
int v37; // er13
int v38; // er14
double v39; // xmm0_8
int v40; // eax
int v41; // er12
size_t v42; // rax
int i; // er13
int v44; // eax
int v45; // er12
int v46; // er14
int v47; // [rsp+Ch] [rbp-310Ch]
__off_t v48; // [rsp+10h] [rbp-3108h]
int v49; // [rsp+10h] [rbp-3108h]
__off_t v50; // [rsp+18h] [rbp-3100h]
FILE *v51; // [rsp+18h] [rbp-3100h]
FILE *stream; // [rsp+20h] [rbp-30F8h]
int v53; // [rsp+28h] [rbp-30F0h]
int v54; // [rsp+28h] [rbp-30F0h]
int fd; // [rsp+2Ch] [rbp-30ECh]
int v56; // [rsp+38h] [rbp-30E0h]
struct sockaddr addr; // [rsp+40h] [rbp-30D8h] BYREF
struct stat v58; // [rsp+50h] [rbp-30C8h] BYREF
char v59[1024]; // [rsp+E0h] [rbp-3038h] BYREF
char file[8]; // [rsp+4E0h] [rbp-2C38h] BYREF
__int64 v61; // [rsp+4E8h] [rbp-2C30h]
char v62[1008]; // [rsp+4F0h] [rbp-2C28h] BYREF
int buf[512]; // [rsp+8E0h] [rbp-2838h] BYREF
char nptr[2048]; // [rsp+10E0h] [rbp-2038h] BYREF
char s[2048]; // [rsp+18E0h] [rbp-1838h] BYREF
char filename[8]; // [rsp+20E0h] [rbp-1038h] BYREF
__int64 v67; // [rsp+20E8h] [rbp-1030h]
char v68[1008]; // [rsp+20F0h] [rbp-1028h] BYREF
char dest[16]; // [rsp+28E0h] [rbp-838h] BYREF
char v70[2032]; // [rsp+28F0h] [rbp-828h] BYREF

if ( argc <= 2 )
{
fprintf(stderr, "Usage: %s IP-Adresse Port-Nummer\n", *argv);
exit(1);
}
v3 = socket(2, 1, 0);
if ( v3 == -1 )
{
perror("Socket error");
return 1;
}
v4 = strtol(argv[2], 0LL, 10);
addr = 0LL;
addr.sa_family = 2;
v5 = func0(v4);
v6 = argv[1];
*(_WORD *)addr.sa_data = v5;
inet_aton(v6, (struct in_addr *)&addr.sa_data[2]);
v47 = connect(v3, &addr, 0x10u);
if ( v47 )
{
perror("Connect error - no server available");
return 1;
}
v7 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
printf("Connection with server(%s) established\n", v7);
v8 = recv(v3, buf, 0x7FFuLL, 0);
if ( v8 > 0 )
{
*((_BYTE *)buf + v8) = 0;
printf("%s", (const char *)buf);
}
printf("Username: ");
fgets((char *)buf, 2047, stdin);
v9 = strlen((const char *)buf);
if ( v9 <= 1 )
{
strcpy((char *)buf, "null");
send(v3, buf, 4uLL, 0);
v21 = strlen((const char *)buf);
send(v3, buf, v21, 0);
close(v3);
fwrite("User invalid\n", 1uLL, 0xDuLL, stderr);
return 1;
}
send(v3, buf, v9, 0);
v10 = getpass("Password: ");
v11 = stpcpy((char *)buf, v10);
if ( !LOBYTE(buf[0]) )
{
strcpy((char *)buf, "null");
send(v3, buf, 4uLL, 0);
close(v3);
fwrite("User or password invalid\n", 1uLL, 0x19uLL, stderr);
return 1;
}
send(v3, buf, v11 - (char *)buf, 0);
v12 = recv(v3, buf, 0x7FFuLL, 0);
if ( v12 > 0 )
{
*((_BYTE *)buf + v12) = 0;
puts((const char *)buf);
}
if ( !strcmp((const char *)buf, "Username or password invalid\n") || !strcmp((const char *)buf, "User is blocked!\n") )
goto LABEL_26;
LABEL_12:
while ( 2 )
{
while ( 2 )
{
while ( 2 )
{
while ( 2 )
{
printf("Send command: ");
fgets((char *)buf, 2047, stdin);
if ( !memcmp(buf, "list", 4uLL) )
{
v13 = 1;
}
else if ( LOBYTE(buf[0]) == 103 && *(_WORD *)((char *)buf + 1) == 29797 )
{
v13 = 2;
*(_OWORD *)dest = 0LL;
memset(v70, 0, sizeof(v70));
v14 = strlen((const char *)buf);
if ( v14 != 3 )
{
strncpy(dest, (const char *)buf + 3, v14 - 3);
v15 = strtok(dest, " \n\r");
if ( !v15 )
continue;
v13 = 2;
strcpy(v59, v15);
}
}
else if ( !memcmp(buf, "send", 4uLL) )
{
v13 = 3;
*(_OWORD *)dest = 0LL;
memset(v70, 0, sizeof(v70));
v22 = strlen((const char *)buf);
if ( v22 != 4 )
{
strncpy(dest, (const char *)&buf[1], v22 - 4);
v23 = strtok(dest, " \n\r");
if ( !v23 )
continue;
v13 = 3;
strcpy(v59, v23);
}
}
else if ( !memcmp(buf, "blocklist", 9uLL) )
{
v13 = 4;
}
else
{
v24 = memcmp(buf, "quit", 4uLL) == 0;
v13 = !v24;
if ( !v24 )
continue;
}
break;
}
v16 = strlen((const char *)buf);
send(v3, buf, v16, 0);
v17 = recv(v3, nptr, 0x7FFuLL, 0);
if ( v17 > 0 )
nptr[v17] = 0;
v18 = strtol(nptr, 0LL, 10);
v19 = v18;
if ( v18 == -1 )
{
if ( v13 != 2 )
goto LABEL_25;
LABEL_39:
puts("File not found!");
continue;
}
break;
}
switch ( v13 )
{
case 1:
send(v3, buf, 1uLL, 0);
if ( v19 <= 0 )
goto LABEL_69;
v34 = 0;
while ( 1 )
{
v35 = recv(v3, buf, 0x7FFuLL, 0);
v36 = v35;
if ( v35 <= 0 )
{
if ( !v35 )
{
LABEL_68:
puts("connect to socket failed");
goto LABEL_69;
}
if ( v35 == -1 )
puts("error in socket");
}
else
{
*((_BYTE *)buf + v35) = 0;
printf("%s", (const char *)buf);
fflush(stdout);
}
v34 += v36;
if ( v34 >= v19 )
goto LABEL_69;
}
case 2:
printf("Size of selected File is %ld bytes\nDo you want to download the file? (y/n)", v18);
while ( 1 )
{
fgets((char *)buf, 2047, stdin);
if ( LOBYTE(buf[0]) == 121 )
break;
if ( LOBYTE(buf[0]) == 110 )
{
LOWORD(buf[0]) = 110;
send(v3, buf, 1uLL, 0);
goto LABEL_12;
}
printf("Invalid input. (y/n) ");
}
LOWORD(buf[0]) = 121;
v37 = v19;
send(v3, buf, 1uLL, 0);
*(_QWORD *)filename = 12078LL;
v67 = 0LL;
memset(v68, 0, sizeof(v68));
strcpy(&filename[2], v59);
v49 = 0;
v51 = fopen(filename, "wb");
v54 = v3;
while ( 1 )
{
if ( v37 <= 0 )
{
v3 = v54;
goto LABEL_106;
}
*(_OWORD *)dest = 0LL;
memset(v70, 0, sizeof(v70));
v40 = recv(v54, dest, 0x7FFuLL, 0);
v41 = v40;
if ( v40 <= 0 )
{
if ( !v40 )
{
v3 = v54;
puts("connect to socket failed");
goto LABEL_106;
}
if ( v40 == -1 )
{
v3 = v54;
puts("error in socket");
LABEL_106:
putchar(10);
fclose(v51);
goto LABEL_12;
}
v38 = v40;
}
else
{
v38 = v40;
fwrite(dest, 1uLL, v40, v51);
}
v39 = (double)(v38 + (int)v19 - v37) / (double)(int)v19 * 20.0;
if ( (int)v39 - v49 >= 0 )
{
if ( (int)v39 != v49 )
{
v46 = 0;
do
{
++v46;
putchar(35);
fflush(stdout);
}
while ( (int)v39 - v49 != v46 );
v49 = (int)v39;
}
if ( v49 == 20 )
puts("!");
}
v37 -= v41;
}
case 3:
*(_QWORD *)file = 12078LL;
memset(v62, 0, sizeof(v62));
v61 = 0LL;
strcpy(&file[2], v59);
if ( stat(file, &v58) != -1 )
{
v25 = v58.st_size;
v50 = v58.st_size;
sprintf(s, "%ld", v58.st_size);
v26 = strlen(s);
send(v3, s, v26, 0);
recv(v3, filename, 1uLL, 0);
stream = fopen(file, "rb");
if ( stream )
{
v27 = v25;
if ( (int)v25 > 0 )
{
fd = v3;
v48 = v25 - (int)v25;
v28 = 2047;
v53 = 0;
v56 = v25 & 1;
do
{
if ( v27 <= 2046 )
v28 = v27;
fread(dest, v28, 1uLL, stream);
send(fd, dest, v28, 0);
v32 = v48 + v28;
if ( v32 >= 0 )
v29 = (double)(int)v32;
else
v29 = (double)(int)(v32 & 1 | ((unsigned __int64)v32 >> 1))
+ (double)(int)(v32 & 1 | ((unsigned __int64)v32 >> 1));
if ( v50 < 0 )
v30 = (double)(int)(v56 | ((unsigned __int64)v50 >> 1))
+ (double)(int)(v56 | ((unsigned __int64)v50 >> 1));
else
v30 = (double)(int)v50;
v31 = v29 / v30 * 20.0;
if ( (int)v31 - v53 >= 0 )
{
if ( (int)v31 != v53 )
{
v33 = 0;
do
{
++v33;
putchar(35);
fflush(stdout);
}
while ( (int)v31 - v53 != v33 );
v53 = (int)v31;
}
if ( v53 == 20 )
puts("!");
}
v48 += 2047LL;
v27 -= 2047;
}
while ( v27 > 0 );
v3 = fd;
}
putchar(10);
fclose(stream);
}
else
{
puts("can't open file");
}
continue;
}
sprintf(s, "%ld", -1LL);
v42 = strlen(s);
send(v3, s, v42, 0);
goto LABEL_39;
case 4:
send(v3, buf, 1uLL, 0);
if ( v19 > 0 )
{
for ( i = 0; i < v19; i += v45 )
{
v44 = recv(v3, buf, 0x7FFuLL, 0);
v45 = v44;
if ( v44 <= 0 )
{
if ( !v44 )
goto LABEL_68;
if ( v44 == -1 )
puts("error in socket");
}
else
{
*((_BYTE *)buf + v44) = 0;
printf("%s", (const char *)buf);
fflush(stdout);
}
}
}
LABEL_69:
putchar(10);
break;
}
break;
}
LABEL_25:
if ( v13 )
continue;
break;
}
LABEL_26:
close(v3);
return v47;
}

original_code:
int main(int argc, char **argv) {
 int sockFd, connFd;
 socklen_t addrlen;
 struct sockaddr_in address, cliaddress;
 long port;
 struct thrdData* data;
 pthread_t socketThread;
 if(argc < 2) {
  fprintf(stderr, "USAGE: %s PORT Directory\n", argv[0]);
  return 1;
 }
 if(argc == 3) {
  strcpy(dirname, argv[2]);
  if(opendir(dirname) == ((void *)0)) {
   fprintf(stderr, "%s: %s is not a directory!\n", argv[0], argv[2]);
   return 1;
  }
 } else {
  getcwd(dirname, sizeof(dirname));
 }
 port = strtol(argv[1], ((void *)0), 10);
 sockFd = socket(2, SOCK_STREAM, 0);
 memset(&address,0,sizeof(address));
 address.sin_family = 2;
 address.sin_addr.s_addr = ((in_addr_t) 0x00000000);
 address.sin_port = htons(port);
 if(bind( sockFd,(struct sockaddr *) &address, sizeof(address)) != 0) {
  perror("bind error");
  return 1;
 }
 listen(sockFd, 5);
 addrlen = sizeof(struct sockaddr_in);
 while(1) {
  printf("Waiting for connections...\n");
  connFd = accept( sockFd,(struct sockaddr *) &cliaddress, &addrlen );
  if(connFd > 0) {
   printf("Client connected from %s:%d...\n", inet_ntoa(cliaddress.sin_addr),ntohs(cliaddress.sin_port));
   data =(struct thrdData*)malloc(sizeof(struct thrdData));
   strcpy(data->ipAddress,inet_ntoa(cliaddress.sin_addr));
   data->socket = connFd;
   pthread_create(&socketThread,((void *)0),session,(void*)data);
   }
   else {
   printf("Error with accept \n");
   return 1;
  }
 }
 close(sockFd);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 int sockFd; int connFd;
 unsigned int addrlen;
 struct sockaddr_in address; struct sockaddr_in cliaddress;
 long port;
 struct thrdData *data;
 unsigned long socketThread;
 if(argc < 2) {
  fprintf(stderr, "USAGE: %s PORT Directory\n", argv[0]);
  return 1;
 }
 if(argc == 3) {
  strcpy(dirname, argv[2]);
  if(opendir(dirname) == ((void *)0)) {
   fprintf(stderr, "%s: %s is not a directory!\n", argv[0], argv[2]);
   return 1;
  }
 } else {
  getcwd(dirname, sizeof(dirname));
 }
 port = strtol(argv[1], ((void *)0), 10);
 sockFd = socket(2, SOCK_STREAM, 0);
 memset(&address,0,sizeof(address));
 address.sin_family = 2;
 address.sin_addr.s_addr = ((unsigned int) 0x00000000);
 address.sin_port = htons(port);
 if(bind( sockFd,(struct sockaddr *) &address, sizeof(address)) != 0) {
  perror("bind error");
  return 1;
 }
 listen(sockFd, 5);
 addrlen = sizeof(struct sockaddr_in);
 while(1) {
  printf("Waiting for connections...\n");
  connFd = accept( sockFd,(struct sockaddr *) &cliaddress, &addrlen );
  if(connFd > 0) {
   printf("Client connected from %s:%d...\n", inet_ntoa(cliaddress.sin_addr),ntohs(cliaddress.sin_port));
   data =(struct thrdData *)malloc(sizeof(struct thrdData));
   strcpy(data->ipAddress,inet_ntoa(cliaddress.sin_addr));
   data->socket = connFd;
   pthread_create(&socketThread,((void *)0),session,(void *)data);
   }
   else {
   printf("Error with accept \n");
   return 1;
  }
 }
 close(sockFd);
 return 0;
}

variable_types: sockFd int

variable_types: connFd int

variable_types:
addrlen
unsigned 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: port long

variable_types: struct thrdData { char ipAddress[16]; int socket; } *

variable_types:
socketThread
unsigned long

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


repo: eerpini/N-way-Pipe

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v4; // rsp
int *v5; // r13
int *v6; // r12
int *v7; // rbx
__int64 v8; // rsi
__int64 v9; // r12
const char *v10; // rdi
__int64 v11; // rsi
int *v12; // r14
int *v13; // r12
int v14; // edi
unsigned __int64 v15; // rbx
int v16; // edi
int *v17; // rbx
__int64 *v18; // r12
int v19; // edi
int v20; // edi
int *v22; // r14
int v23; // edi
int v24; // [rsp+0h] [rbp-70h] BYREF
__int64 v25; // [rsp+8h] [rbp-68h] BYREF
unsigned __int64 v26; // [rsp+10h] [rbp-60h] BYREF
char **argva; // [rsp+18h] [rbp-58h]
__int64 v28; // [rsp+20h] [rbp-50h]
int v29; // [rsp+2Ch] [rbp-44h]
char buf; // [rsp+37h] [rbp-39h] BYREF
unsigned int v31; // [rsp+38h] [rbp-38h] BYREF
__WAIT_STATUS stat_loc; // [rsp+3Ch] [rbp-34h] BYREF

v29 = argc;
if ( argc <= 2 )
{
fwrite("Invalid args\n", 1uLL, 0xDuLL, _bss_start);
return 1;
}
v31 = 0;
LODWORD(stat_loc.__uptr) = 0;
buf = 0;
LODWORD(v28) = v29 - 1;
v4 = alloca(8LL * (v29 - 1));
v5 = &v24;
v6 = &v24;
v26 = ((unsigned __int64)&v24 + 3) >> 2;
v7 = &v24 + 2 * (unsigned int)(v29 - 1);
do
{
if ( pipe(v6) < 0 )
{
perror("pipe");
exit(1);
}
v6 += 2;
}
while ( v6 != v7 );
v8 = break_by_spaces(argv[1], &v31);
if ( !v8 )
{
LABEL_24:
fwrite("Cannot exec program specified as first arg\n", 1uLL, 0x2BuLL, _bss_start);
return 1;
}
argva = (char **)build_argv(argv[1], v8, v31);
if ( !fork() )
{
if ( dup2(*(_DWORD *)(4 * v26 + 4), 1) != -1 )
{
v15 = v26;
close(*(_DWORD *)(4 * v26));
v16 = *(_DWORD *)(4 * v15 + 4);
v17 = (int *)&v25;
close(v16);
v18 = (__int64 *)(&v26 + (unsigned int)(v29 - 3));
do
{
v19 = *v17;
v17 += 2;
close(v19);
close(*(v17 - 1));
}
while ( v17 != (int *)v18 );
if ( execvp(*argva, argva) != -1 )
exit(1);
LABEL_30:
perror("execvp");
exit(1);
}
LABEL_32:
perror("dup2");
exit(1);
}
v9 = 1LL;
v25 = (unsigned int)(v29 - 3);
v28 = (unsigned int)v28;
while ( 1 )
{
v10 = argv[v9 + 1];
v29 = v9;
v31 = 0;
v11 = break_by_spaces(v10, &v31);
if ( !v11 )
goto LABEL_24;
argva = (char **)build_argv(argv[v9 + 1], v11, v31);
if ( !fork() )
break;
if ( ++v9 == v28 )
goto LABEL_11;
}
if ( dup2(*(&v24 + 2 * v29), 0) == -1 )
goto LABEL_32;
v22 = &v24;
do
{
v23 = *v22;
v22 += 2;
close(v23);
close(*(v22 - 1));
}
while ( v22 != v7 );
if ( execvp(*argva, argva) == -1 )
goto LABEL_30;
LABEL_11:
close(*(_DWORD *)(4 * v26 + 4));
v29 += 2;
v12 = &v24 + 2 * v25 + 5;
while ( (unsigned int)read(v24, &buf, 1uLL) )
{
v13 = (int *)&v25 + 1;
do
{
v14 = *v13;
v13 += 2;
write(v14, &buf, 1uLL);
}
while ( v13 != v12 );
}
do
{
v20 = *v5;
v5 += 2;
close(v20);
close(*(v5 - 1));
}
while ( v5 != v7 );
do
{
wait((__WAIT_STATUS)&stat_loc);
--v29;
}
while ( v29 );
return v29;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v4; // rsp
int *v5; // r13
int *v6; // r12
int *v7; // rbx
__int64 v8; // rsi
__int64 v9; // r12
const char *v10; // rdi
__int64 v11; // rsi
int *v12; // r14
int *v13; // r12
int v14; // edi
unsigned __int64 v15; // rbx
int v16; // edi
int *v17; // rbx
__int64 *v18; // r12
int v19; // edi
int v20; // edi
int *v22; // r14
int v23; // edi
int v24; // [rsp+0h] [rbp-70h] BYREF
__int64 v25; // [rsp+8h] [rbp-68h] BYREF
unsigned __int64 v26; // [rsp+10h] [rbp-60h] BYREF
char **argva; // [rsp+18h] [rbp-58h]
__int64 v28; // [rsp+20h] [rbp-50h]
int v29; // [rsp+2Ch] [rbp-44h]
char buf; // [rsp+37h] [rbp-39h] BYREF
unsigned int v31; // [rsp+38h] [rbp-38h] BYREF
__WAIT_STATUS stat_loc; // [rsp+3Ch] [rbp-34h] BYREF

v29 = argc;
if ( argc <= 2 )
{
fwrite("Invalid args\n", 1uLL, 0xDuLL, _bss_start);
return 1;
}
v31 = 0;
LODWORD(stat_loc.__uptr) = 0;
buf = 0;
LODWORD(v28) = v29 - 1;
v4 = alloca(8LL * (v29 - 1));
v5 = &v24;
v6 = &v24;
v26 = ((unsigned __int64)&v24 + 3) >> 2;
v7 = &v24 + 2 * (unsigned int)(v29 - 1);
do
{
if ( pipe(v6) < 0 )
{
perror("pipe");
exit(1);
}
v6 += 2;
}
while ( v6 != v7 );
v8 = break_by_spaces(argv[1], &v31);
if ( !v8 )
{
LABEL_24:
fwrite("Cannot exec program specified as first arg\n", 1uLL, 0x2BuLL, _bss_start);
return 1;
}
argva = (char **)func7(argv[1], v8, v31);
if ( !fork() )
{
if ( dup2(*(_DWORD *)(4 * v26 + 4), 1) != -1 )
{
v15 = v26;
close(*(_DWORD *)(4 * v26));
v16 = *(_DWORD *)(4 * v15 + 4);
v17 = (int *)&v25;
close(v16);
v18 = (__int64 *)(&v26 + (unsigned int)(v29 - 3));
do
{
v19 = *v17;
v17 += 2;
close(v19);
close(*(v17 - 1));
}
while ( v17 != (int *)v18 );
if ( execvp(*argva, argva) != -1 )
exit(1);
LABEL_30:
perror("execvp");
exit(1);
}
LABEL_32:
perror("dup2");
exit(1);
}
v9 = 1LL;
v25 = (unsigned int)(v29 - 3);
v28 = (unsigned int)v28;
while ( 1 )
{
v10 = argv[v9 + 1];
v29 = v9;
v31 = 0;
v11 = break_by_spaces(v10, &v31);
if ( !v11 )
goto LABEL_24;
argva = (char **)func7(argv[v9 + 1], v11, v31);
if ( !fork() )
break;
if ( ++v9 == v28 )
goto LABEL_11;
}
if ( dup2(*(&v24 + 2 * v29), 0) == -1 )
goto LABEL_32;
v22 = &v24;
do
{
v23 = *v22;
v22 += 2;
close(v23);
close(*(v22 - 1));
}
while ( v22 != v7 );
if ( execvp(*argva, argva) == -1 )
goto LABEL_30;
LABEL_11:
close(*(_DWORD *)(4 * v26 + 4));
v29 += 2;
v12 = &v24 + 2 * v25 + 5;
while ( (unsigned int)read(v24, &buf, 1uLL) )
{
v13 = (int *)&v25 + 1;
do
{
v14 = *v13;
v13 += 2;
write(v14, &buf, 1uLL);
}
while ( v13 != v12 );
}
do
{
v20 = *v5;
v5 += 2;
close(v20);
close(*(v5 - 1));
}
while ( v5 != v7 );
do
{
wait((__WAIT_STATUS)&stat_loc);
--v29;
}
while ( v29 );
return v29;
}

original_code:
int main(int argc, char *argv[]){
        char buf = 0;
        if(argc == 1){
                while(read(0, &buf, 1)){
                        write(1, &buf, 1);
                }
        }
        else{
                if(argc > 2){
                        fprintf(stderr, "Usage : %s [filename]\n", argv[0]);
                }
                int fd = open(argv[1], 0100|02, 0400|0200|(0400 >> 3)|(0200 >> 3));
                while(read(0, &buf, 1)){
                        write(fd, &buf, 1);
                }
                close(fd);
        }
        return 0;
}

variable_types:
argv
char *[]

variable_types: buf char

variable_types: fd int


getfile

repo: efficient/ffbf

decompiled_code:
__int64 __fastcall getfile(char *s, __off_t *a2)
{
int v2; // eax
unsigned int v3; // er12
struct stat v5; // [rsp+0h] [rbp-A8h] BYREF

v2 = open(s, 0);
if ( v2 < 0 )
{
perror(s);
exit(-1);
}
v3 = v2;
if ( fstat(v2, &v5) < 0 )
{
perror("fstat");
exit(-1);
}
*a2 = v5.st_size;
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s, __off_t *a2)
{
int v2; // eax
unsigned int v3; // er12
struct stat v5; // [rsp+0h] [rbp-A8h] BYREF

v2 = open(s, 0);
if ( v2 < 0 )
{
perror(s);
exit(-1);
}
v3 = v2;
if ( fstat(v2, &v5) < 0 )
{
perror("fstat");
exit(-1);
}
*a2 = v5.st_size;
return v3;
}

original_code:
int getfile(char *infile, size_t *filesize) {
    int f;
    if ((f = open(infile, 00)) < 0) {
      perror(infile);
      exit(-1);
    }
    struct stat sb;
    if (fstat(f, &sb) < 0) {
      perror("fstat");
      exit(-1);
    }
    *filesize = sb.st_size;
    return f;
}

canonical_original_code:
int getfile(char *infile, unsigned long *filesize) {
    int f;
    if ((f = open(infile, 00)) < 0) {
      perror(infile);
      exit(-1);
    }
    struct stat sb;
    if (fstat(f, &sb) < 0) {
      perror("fstat");
      exit(-1);
    }
    *filesize = sb.st_size;
    return f;
}

variable_types:
infile
char *

variable_types:
filesize
unsigned long *

variable_types: f int

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


repo: efficios/memleak-finder

decompiled_code:
int print_stats_init()
{
int result; // eax
struct sigaction vars0; // [rsp+0h] [rbp+0h] BYREF

vars0.sa_handler = (__sighandler_t)sighandler;
vars0.sa_flags = 268435460;
sigemptyset(&vars0.sa_mask);
result = sigaction(12, &vars0, 0LL);
if ( result )
__assert_fail("!ret", "malloc-stats.c", 0x30u, "print_stats_init");
return result;
}

canonical_decompiled_code:
int func2()
{
int result; // eax
struct sigaction vars0; // [rsp+0h] [rbp+0h] BYREF

vars0.sa_handler = (__sighandler_t)sighandler;
vars0.sa_flags = 268435460;
sigemptyset(&vars0.sa_mask);
result = sigaction(12, &vars0, 0LL);
if ( result )
__assert_fail("!ret", "malloc-stats.c", 0x30u, "print_stats_init");
return result;
}

original_code:
static __attribute__((constructor))
void print_stats_init(void)
{
 struct sigaction act;
 int ret;
 act.__sigaction_handler.sa_sigaction = sighandler;
 act.sa_flags = 4 | 0x10000000;
 sigemptyset(&act.sa_mask);
 ret = sigaction(12, &act, ((void *)0));
 ((void) sizeof ((!ret) ? 1 : 0), __extension__ ({ if (!ret) ; else __assert_fail ("!ret", "malloc-stats.c", 48, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
static void print_stats_init()
{
 struct sigaction act;
 int ret;
 act.__sigaction_handler.sa_sigaction = sighandler;
 act.sa_flags = 4 | 0x10000000;
 sigemptyset(&act.sa_mask);
 ret = sigaction(12, &act, ((void *)0));
 ((void) sizeof ((!ret) ? 1 : 0), __extension__ ({ if (!ret) ; else __assert_fail ("!ret", "malloc-stats.c", 48, __extension__ __PRETTY_FUNCTION__); }));
}

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

variable_types: ret int

return_type: void

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


sighandler

decompiled_code:
// attributes: thunk
void sighandler(void)
{
malloc_stats();
}

canonical_decompiled_code:
void func7(void)
{
malloc_stats();
}

original_code:
static void sighandler(int signo, siginfo_t *siginfo, void *context)
{
 malloc_stats();
}

canonical_original_code:
static void sighandler(int signo, struct siginfo_t *siginfo, void *context)
{
 malloc_stats();
}

variable_types: signo int

variable_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *

variable_types:
context
void *


getch

repo: efficios/urcu-tutorial

decompiled_code:
__int64 __fastcall getch(_BYTE *a1)
{
ssize_t v1; // rax
unsigned int v3; // er12
char buf; // [rsp+1h] [rbp-59h] BYREF
struct termios termios_p; // [rsp+2h] [rbp-58h] BYREF

buf = 0;
*(_QWORD *)&termios_p.c_cc[31] = 0LL;
termios_p.c_ospeed = 0;
*(_OWORD *)&termios_p.c_iflag = 0LL;
*(_OWORD *)&termios_p.c_line = 0LL;
*(_OWORD *)&termios_p.c_cc[15] = 0LL;
if ( tcgetattr(0, &termios_p) < 0 )
{
v3 = -1;
perror("tcsetattr()");
}
else
{
termios_p.c_lflag &= 0xFFFFFFF5;
*(_WORD *)&termios_p.c_cc[5] = 256;
if ( tcsetattr(0, 0, &termios_p) >= 0 )
{
do
{
v1 = read(0, &buf, 1uLL);
if ( v1 >= 0 )
{
v3 = -(v1 == 0);
goto LABEL_7;
}
}
while ( *_errno_location() == 4 );
v3 = -1;
perror("read()");
LABEL_7:
termios_p.c_lflag |= 0xAu;
if ( tcsetattr(0, 1, &termios_p) < 0 )
{
v3 = -1;
perror("tcsetattr ~ICANON");
}
*a1 = buf;
}
else
{
v3 = -1;
perror("tcsetattr ICANON");
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
ssize_t v1; // rax
unsigned int v3; // er12
char buf; // [rsp+1h] [rbp-59h] BYREF
struct termios termios_p; // [rsp+2h] [rbp-58h] BYREF

buf = 0;
*(_QWORD *)&termios_p.c_cc[31] = 0LL;
termios_p.c_ospeed = 0;
*(_OWORD *)&termios_p.c_iflag = 0LL;
*(_OWORD *)&termios_p.c_line = 0LL;
*(_OWORD *)&termios_p.c_cc[15] = 0LL;
if ( tcgetattr(0, &termios_p) < 0 )
{
v3 = -1;
perror("tcsetattr()");
}
else
{
termios_p.c_lflag &= 0xFFFFFFF5;
*(_WORD *)&termios_p.c_cc[5] = 256;
if ( tcsetattr(0, 0, &termios_p) >= 0 )
{
do
{
v1 = read(0, &buf, 1uLL);
if ( v1 >= 0 )
{
v3 = -(v1 == 0);
goto LABEL_7;
}
}
while ( *_errno_location() == 4 );
v3 = -1;
perror("read()");
LABEL_7:
termios_p.c_lflag |= 0xAu;
if ( tcsetattr(0, 1, &termios_p) < 0 )
{
v3 = -1;
perror("tcsetattr ~ICANON");
}
*a1 = buf;
}
else
{
v3 = -1;
perror("tcsetattr ICANON");
}
}
return v3;
}

original_code:
static
int getch(char *_key)
{
 char key = 0;
 struct termios old = { 0 };
 ssize_t len;
 int ret = 0;
 if (tcgetattr(0, &old) < 0) {
  perror("tcsetattr()");
  ret = -1;
  goto end;
 }
 old.c_lflag &= ~0000002;
 old.c_lflag &= ~0000010;
 old.c_cc[6] = 1;
 old.c_cc[5] = 0;
 if (tcsetattr(0, 0, &old) < 0) {
  perror("tcsetattr ICANON");
  ret = -1;
  goto end;
 }
 do {
  len = read(0, &key, sizeof(key));
 } while (len < 0 && (*__errno_location ()) == 4);
 if (len < 0) {
  perror("read()");
  ret = -1;
 }
 if (len == 0) {
  ret = -1;
 }
 old.c_lflag |= 0000002;
 old.c_lflag |= 0000010;
 if (tcsetattr(0, 1, &old) < 0) {
  perror("tcsetattr ~ICANON");
  ret = -1;
 }
 *_key = key;
end:
 return ret;
}

canonical_original_code:
static int getch(char *_key)
{
 char key = 0;
 struct termios old = { 0 };
 long len;
 int ret = 0;
 if (tcgetattr(0, &old) < 0) {
  perror("tcsetattr()");
  ret = -1;
  goto end;
 }
 old.c_lflag &= ~0000002;
 old.c_lflag &= ~0000010;
 old.c_cc[6] = 1;
 old.c_cc[5] = 0;
 if (tcsetattr(0, 0, &old) < 0) {
  perror("tcsetattr ICANON");
  ret = -1;
  goto end;
 }
 do {
  len = read(0, &key, sizeof(key));
 } while (len < 0 && (*__errno_location ()) == 4);
 if (len < 0) {
  perror("read()");
  ret = -1;
 }
 if (len == 0) {
  ret = -1;
 }
 old.c_lflag |= 0000002;
 old.c_lflag |= 0000010;
 if (tcsetattr(0, 1, &old) < 0) {
  perror("tcsetattr ~ICANON");
  ret = -1;
 }
 *_key = key;
end:
 return ret;
}

variable_types: key char

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }

variable_types: len long


decompiled_code:
__int64 wait_for_key()
{
char v1[9]; // [rsp+Fh] [rbp-9h] BYREF

puts("Press any key to continue...");
return getch(v1);
}

canonical_decompiled_code:
__int64 func1()
{
char v1[9]; // [rsp+Fh] [rbp-9h] BYREF

puts("Press any key to continue...");
return func0(v1);
}

original_code:
static
void wait_for_key(void)
{
 char key;
 printf("Press any key to continue...\n");
 (void) getch(&key);
}

canonical_original_code:
static void wait_for_key()
{
 char key;
 printf("Press any key to continue...\n");
 (void) getch(&key);
}


decompiled_code:
int clear_screen()
{
int result; // eax

putchar(10);
result = clear_screen_enable;
if ( clear_screen_enable )
result = printf("%c[2J%c[;H", 27LL, 27LL);
return result;
}

canonical_decompiled_code:
int func2()
{
int result; // eax

putchar(10);
result = clear_screen_enable;
if ( clear_screen_enable )
result = printf("%c[2J%c[;H", 27LL, 27LL);
return result;
}

original_code:
static inline
void clear_screen(void)
{
 printf("\n");
 if (clear_screen_enable)
  printf("%c[2J%c[;H", (char) 27, (char) 27);
}

canonical_original_code:
static inline void clear_screen()
{
 printf("\n");
 if (clear_screen_enable)
  printf("%c[2J%c[;H", (char) 27, (char) 27);
}


decompiled_code:
int show_menu()
{
clear_screen();
puts("[ root ]");
puts(" key\tDescription");
puts("---------------------------------");
puts(" c\tConfiguration menu");
puts(" g\tPlay god");
return puts(" x\tExit root menu");
}

canonical_decompiled_code:
int func3()
{
func2();
puts("[ root ]");
puts(" key\tDescription");
puts("---------------------------------");
puts(" c\tConfiguration menu");
puts(" g\tPlay god");
return puts(" x\tExit root menu");
}

original_code:
static
void show_menu(void)
{
 clear_screen();
 printf("[ root ]\n");
 printf(" key	Description\n");
 printf("---------------------------------\n");
 printf("  c	Configuration menu\n");
 printf("  g	Play god\n");
 printf("  x	Exit root menu\n");
}

canonical_original_code:
static void show_menu()
{
 clear_screen();
 printf("[ root ]\n");
 printf(" key	Description\n");
 printf("---------------------------------\n");
 printf("  c	Configuration menu\n");
 printf("  g	Play god\n");
 printf("  x	Exit root menu\n");
}


decompiled_code:
__int64 __fastcall get_config_entry_uint64(const char *a1, _QWORD *a2)
{
int *v2; // rax
int *v3; // rbx
__int64 result; // rax
__int64 v5; // [rsp+8h] [rbp-1020h] BYREF
char v6[4120]; // [rsp+10h] [rbp-1018h] BYREF

fflush(stdin);
printf("Enter new %s\n", a1);
if ( (int)readline_unbuf_constprop_0(v6) >= 0 )
{
v2 = _errno_location();
*v2 = 0;
v3 = v2;
if ( (unsigned int)_isoc99_sscanf(v6, "%lu", &v5) == 1 && !*v3 )
{
result = v5;
*a2 = v5;
return result;
}
perror("fscanf");
}
fprintf(stderr, "Error: expected digital input for %s\n", a1);
return wait_for_key();
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1, _QWORD *a2)
{
int *v2; // rax
int *v3; // rbx
__int64 result; // rax
__int64 v5; // [rsp+8h] [rbp-1020h] BYREF
char v6[4120]; // [rsp+10h] [rbp-1018h] BYREF

fflush(stdin);
printf("Enter new %s\n", a1);
if ( (int)func4(v6) >= 0 )
{
v2 = _errno_location();
*v2 = 0;
v3 = v2;
if ( (unsigned int)_isoc99_sscanf(v6, "%lu", &v5) == 1 && !*v3 )
{
result = v5;
*a2 = v5;
return result;
}
perror("fscanf");
}
fprintf(stderr, "Error: expected digital input for %s\n", a1);
return func1();
}

original_code:
static
void get_config_entry_uint64(const char *name,
  uint64_t *value)
{
 uint64_t new_size;
 char read_buf[4096];
 int ret;
 fflush(stdin);
 printf("Enter new %s\n", name);
 ret = readline_unbuf(0, read_buf, sizeof(read_buf));
 if (ret < 0) {
  fprintf(stderr, "Error: expected digital input for %s\n",
   name);
  wait_for_key();
  return;
 }
 (*__errno_location ()) = 0;
 ret = sscanf(read_buf, "%" "l" "u", &new_size);
 if (ret != 1 || (*__errno_location ()) != 0) {
  perror("fscanf");
  fprintf(stderr, "Error: expected digital input for %s\n",
   name);
  wait_for_key();
  return;
 }
 *value = new_size;
}

canonical_original_code:
static void get_config_entry_uint64(char *name, unsigned long *value)
{
 unsigned long new_size;
 char read_buf[4096];
 int ret;
 fflush(stdin);
 printf("Enter new %s\n", name);
 ret = readline_unbuf(0, read_buf, sizeof(read_buf));
 if (ret < 0) {
  fprintf(stderr, "Error: expected digital input for %s\n",
   name);
  wait_for_key();
  return;
 }
 (*__errno_location ()) = 0;
 ret = sscanf(read_buf, "%" "l" "u", &new_size);
 if (ret != 1 || (*__errno_location ()) != 0) {
  perror("fscanf");
  fprintf(stderr, "Error: expected digital input for %s\n",
   name);
  wait_for_key();
  return;
 }
 *value = new_size;
}

variable_types:
name
char *

variable_types:
value
unsigned long *


decompiled_code:
__int64 do_config()
{
__int64 v0; // rax
__int64 v1; // rbp
__int64 result; // rax
__int64 v3; // rsi
char v4; // al
char v5; // [rsp+7h] [rbp-21h] BYREF
__int64 v6[4]; // [rsp+8h] [rbp-20h] BYREF

v0 = urcu_game_config_update_begin();
if ( !v0 )
do_config_cold();
v1 = v0;
while ( 1 )
{
clear_screen();
puts("[ root > configuration ]");
puts("Enter the config field you wish to update:");
puts(" key\tDescription");
puts("---------------------------------");
puts(" q\tCancel update");
puts(" x\tSave update and exit configuration menu");
printf(" i\tIsland size (%lu)\n", *(_QWORD *)v1);
printf(" d\tStep delay (%d ms)\n", *(unsigned int *)(v1 + 8));
printf(" g\tGerbil max birth stamina (%lu)\n", *(_QWORD *)(v1 + 16));
printf(" c\tCat max birth stamina (%lu)\n", *(_QWORD *)(v1 + 40));
printf(" s\tSnake max birth stamina (%lu)\n", *(_QWORD *)(v1 + 64));
result = getch(&v5);
if ( (int)result < 0 )
return result;
if ( !verbose )
{
v3 = (unsigned int)v5;
v4 = v5 - 99;
LABEL_6:
switch ( v4 )
{
case 0:
get_config_entry_uint64("cat stamina", (_QWORD *)(v1 + 40));
continue;
case 1:
get_config_entry_uint64("step delay (ms)", v6);
if ( v6[0] >= 0x80000000uLL )
{
puts("Error: delay specified is too large.");
wait_for_key();
}
else
{
*(_DWORD *)(v1 + 8) = v6[0];
}
continue;
case 4:
get_config_entry_uint64("gerbil stamina", (_QWORD *)(v1 + 16));
continue;
case 6:
get_config_entry_uint64("island size (increase only)", v6);
if ( *(_QWORD *)v1 >= v6[0] )
puts("Error: Island size can only be increased.");
else
*(_QWORD *)v1 = v6[0];
continue;
case 14:
puts("Configuration update cancelled.");
urcu_game_config_update_abort(v1);
result = wait_for_key();
break;
case 16:
get_config_entry_uint64("snake stamina", (_QWORD *)(v1 + 64));
continue;
case 21:
puts("Configuration saved.");
urcu_game_config_update_end(v1);
result = wait_for_key();
break;
default:
goto LABEL_8;
}
return result;
}
printf("[debug %s()@user-input.c:%d] User input: '%c'\n", "do_config", 184LL, (unsigned int)v5);
v3 = (unsigned int)v5;
v4 = v5 - 99;
if ( (unsigned __int8)(v5 - 99) <= 0x15u )
goto LABEL_6;
LABEL_8:
printf("Unknown key: '%c'\n", v3);
wait_for_key();
}
}

canonical_decompiled_code:
__int64 func6()
{
__int64 v0; // rax
__int64 v1; // rbp
__int64 result; // rax
__int64 v3; // rsi
char v4; // al
char v5; // [rsp+7h] [rbp-21h] BYREF
__int64 v6[4]; // [rsp+8h] [rbp-20h] BYREF

v0 = urcu_game_config_update_begin();
if ( !v0 )
func12();
v1 = v0;
while ( 1 )
{
func2();
puts("[ root > configuration ]");
puts("Enter the config field you wish to update:");
puts(" key\tDescription");
puts("---------------------------------");
puts(" q\tCancel update");
puts(" x\tSave update and exit configuration menu");
printf(" i\tIsland size (%lu)\n", *(_QWORD *)v1);
printf(" d\tStep delay (%d ms)\n", *(unsigned int *)(v1 + 8));
printf(" g\tGerbil max birth stamina (%lu)\n", *(_QWORD *)(v1 + 16));
printf(" c\tCat max birth stamina (%lu)\n", *(_QWORD *)(v1 + 40));
printf(" s\tSnake max birth stamina (%lu)\n", *(_QWORD *)(v1 + 64));
result = func0(&v5);
if ( (int)result < 0 )
return result;
if ( !verbose )
{
v3 = (unsigned int)v5;
v4 = v5 - 99;
LABEL_6:
switch ( v4 )
{
case 0:
func5("cat stamina", (_QWORD *)(v1 + 40));
continue;
case 1:
func5("step delay (ms)", v6);
if ( v6[0] >= 0x80000000uLL )
{
puts("Error: delay specified is too large.");
func1();
}
else
{
*(_DWORD *)(v1 + 8) = v6[0];
}
continue;
case 4:
func5("gerbil stamina", (_QWORD *)(v1 + 16));
continue;
case 6:
func5("island size (increase only)", v6);
if ( *(_QWORD *)v1 >= v6[0] )
puts("Error: Island size can only be increased.");
else
*(_QWORD *)v1 = v6[0];
continue;
case 14:
puts("Configuration update cancelled.");
urcu_game_config_update_abort(v1);
result = func1();
break;
case 16:
func5("snake stamina", (_QWORD *)(v1 + 64));
continue;
case 21:
puts("Configuration saved.");
urcu_game_config_update_end(v1);
result = func1();
break;
default:
goto LABEL_8;
}
return result;
}
printf("[debug %s()@user-input.c:%d] User input: '%c'\n", "do_config", 184LL, (unsigned int)v5);
v3 = (unsigned int)v5;
v4 = v5 - 99;
if ( (unsigned __int8)(v5 - 99) <= 0x15u )
goto LABEL_6;
LABEL_8:
printf("Unknown key: '%c'\n", v3);
func1();
}
}

original_code:
static
void do_config(void)
{
 struct urcu_game_config *new_config;
 char key;
 int ret;
 new_config = urcu_game_config_update_begin();
 if (!new_config)
  abort();
 for (;;) {
  clear_screen();
  printf("[ root > configuration ]\n");
  printf("Enter the config field you wish to update:\n");
  printf(" key	Description\n");
  printf("---------------------------------\n");
  printf("  q	Cancel update\n");
  printf("  x	Save update and exit configuration menu\n");
  printf("  i	Island size (%" "l" "u" ")\n", new_config->island_size);
  printf("  d	Step delay (%d ms)\n", new_config->step_delay);
  printf("  g	Gerbil max birth stamina (%" "l" "u" ")\n",
    new_config->gerbil.max_birth_stamina);
  printf("  c	Cat max birth stamina (%" "l" "u" ")\n",
    new_config->cat.max_birth_stamina);
  printf("  s	Snake max birth stamina (%" "l" "u" ")\n",
    new_config->snake.max_birth_stamina);
  ret = getch(&key);
  if (ret < 0)
   goto end;
  do { if (verbose) printf("[debug %s()@" "user-input.c" ":%d] " "User input: \'%c\'" "\n", __func__, 184, key); } while (0);
  switch(key) {
  case 'x':
   printf("Configuration saved.\n");
   urcu_game_config_update_end(new_config);
   wait_for_key();
   goto end;
  case 'q':
   printf("Configuration update cancelled.\n");
   urcu_game_config_update_abort(new_config);
   wait_for_key();
   goto end;
  case 'i':
  {
   uint64_t new_size;
   get_config_entry_uint64("island size (increase only)",
    &new_size);
   if (new_size <= new_config->island_size) {
    printf("Error: Island size can only be increased.\n");
    break;
   }
   new_config->island_size = new_size;
   break;
  }
  case 'd':
  {
   uint64_t new_delay;
   get_config_entry_uint64("step delay (ms)",
    &new_delay);
   if (new_delay > 0x7fffffff) {
    printf("Error: delay specified is too large.\n");
    wait_for_key();
    break;
   }
   new_config->step_delay = (int) new_delay;
   break;
  }
  case 'g':
   get_config_entry_uint64("gerbil stamina",
    &new_config->gerbil.max_birth_stamina);
   break;
  case 'c':
   get_config_entry_uint64("cat stamina",
    &new_config->cat.max_birth_stamina);
   break;
  case 's':
   get_config_entry_uint64("snake stamina",
    &new_config->snake.max_birth_stamina);
   break;
  default:
   printf("Unknown key: \'%c\'\n", key);
   wait_for_key();
   break;
  }
 }
end:
 return;
}

canonical_original_code:
static void do_config()
{
 struct urcu_game_config *new_config;
 char key;
 int ret;
 new_config = urcu_game_config_update_begin();
 if (!new_config)
  abort();
 for (;;) {
  clear_screen();
  printf("[ root > configuration ]\n");
  printf("Enter the config field you wish to update:\n");
  printf(" key	Description\n");
  printf("---------------------------------\n");
  printf("  q	Cancel update\n");
  printf("  x	Save update and exit configuration menu\n");
  printf("  i	Island size (%" "l" "u" ")\n", new_config->island_size);
  printf("  d	Step delay (%d ms)\n", new_config->step_delay);
  printf("  g	Gerbil max birth stamina (%" "l" "u" ")\n",
    new_config->gerbil.max_birth_stamina);
  printf("  c	Cat max birth stamina (%" "l" "u" ")\n",
    new_config->cat.max_birth_stamina);
  printf("  s	Snake max birth stamina (%" "l" "u" ")\n",
    new_config->snake.max_birth_stamina);
  ret = getch(&key);
  if (ret < 0)
   goto end;
  do { if (verbose) printf("[debug %s()@" "user-input.c" ":%d] " "User input: \'%c\'" "\n", __func__, 184, key); } while (0);
  switch(key) {
  case 'x':
   printf("Configuration saved.\n");
   urcu_game_config_update_end(new_config);
   wait_for_key();
   goto end;
  case 'q':
   printf("Configuration update cancelled.\n");
   urcu_game_config_update_abort(new_config);
   wait_for_key();
   goto end;
  case 'i':
  {
   unsigned long new_size;
   get_config_entry_uint64("island size (increase only)",
    &new_size);
   if (new_size <= new_config->island_size) {
    printf("Error: Island size can only be increased.\n");
    break;
   }
   new_config->island_size = new_size;
   break;
  }
  case 'd':
  {
   unsigned long new_delay;
   get_config_entry_uint64("step delay (ms)",
    &new_delay);
   if (new_delay > 0x7fffffff) {
    printf("Error: delay specified is too large.\n");
    wait_for_key();
    break;
   }
   new_config->step_delay = (int) new_delay;
   break;
  }
  case 'g':
   get_config_entry_uint64("gerbil stamina",
    &new_config->gerbil.max_birth_stamina);
   break;
  case 'c':
   get_config_entry_uint64("cat stamina",
    &new_config->cat.max_birth_stamina);
   break;
  case 's':
   get_config_entry_uint64("snake stamina",
    &new_config->snake.max_birth_stamina);
   break;
  default:
   printf("Unknown key: \'%c\'\n", key);
   wait_for_key();
   break;
  }
 }
end:
 return;
}

variable_types: struct urcu_game_config { unsigned long island_size; unsigned int step_delay; struct animal_kind { unsigned long max_birth_stamina; unsigned long max_pregnant; enum animal_types { GERBIL=0, CAT=1, SNAKE=2 } animal; unsigned int diet; } gerbil; struct animal_kind cat; struct animal_kind snake; } *

user_defined_types: struct urcu_game_config { unsigned long island_size; unsigned int step_delay; struct animal_kind gerbil; struct animal_kind cat; struct animal_kind snake; }

user_defined_types: struct animal_kind { unsigned long max_birth_stamina; unsigned long max_pregnant; enum animal_types animal; unsigned int diet; }


decompiled_code:
__int64 do_god()
{
__int64 result; // rax
char v1; // [rsp+7h] [rbp-11h] BYREF
__int64 v2[2]; // [rsp+8h] [rbp-10h] BYREF

while ( 2 )
{
clear_screen();
puts("[ root > god ]");
puts("Enter the animal or vegetation you wish to modify:");
puts("Modifications take effect immediately.");
puts(" key\tDescription");
puts("---------------------------------");
puts(" x\tExit menu");
puts(" f\tNumber of flowers");
puts(" t\tNumber of trees");
puts(" g\tCreate gerbils");
puts(" c\tCreate cats");
puts(" s\tCreate snakes");
result = getch(&v1);
if ( (int)result >= 0 )
{
if ( verbose )
printf("[debug %s()@user-input.c:%d] User input: '%c'\n", "do_god", 270LL, (unsigned int)v1);
result = (unsigned __int8)(v1 - 99);
switch ( v1 )
{
case 'c':
get_config_entry_uint64("amount of cats to try creating", v2);
create_animals(1LL, v2[0]);
continue;
case 'f':
get_config_entry_uint64("number of flowers", v2);
pthread_mutex_lock((pthread_mutex_t *)(unsigned int)((_DWORD)&vegetation + 16));
vegetation.__align = v2[0];
pthread_mutex_unlock((pthread_mutex_t *)(unsigned int)((_DWORD)&vegetation + 16));
continue;
case 'g':
get_config_entry_uint64("amount of gerbils to try creating", v2);
create_animals(0LL, v2[0]);
continue;
case 's':
get_config_entry_uint64("amount of snakes to try creating", v2);
create_animals(2LL, v2[0]);
continue;
case 't':
get_config_entry_uint64("number of trees", v2);
pthread_mutex_lock((pthread_mutex_t *)(unsigned int)((_DWORD)&vegetation + 16));
*(&vegetation.__align + 1) = v2[0];
pthread_mutex_unlock((pthread_mutex_t *)(unsigned int)((_DWORD)&vegetation + 16));
continue;
case 'x':
return result;
default:
printf("Unknown key: '%c'\n", (unsigned int)v1);
wait_for_key();
continue;
}
}
break;
}
return result;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 result; // rax
char v1; // [rsp+7h] [rbp-11h] BYREF
__int64 v2[2]; // [rsp+8h] [rbp-10h] BYREF

while ( 2 )
{
func2();
puts("[ root > god ]");
puts("Enter the animal or vegetation you wish to modify:");
puts("Modifications take effect immediately.");
puts(" key\tDescription");
puts("---------------------------------");
puts(" x\tExit menu");
puts(" f\tNumber of flowers");
puts(" t\tNumber of trees");
puts(" g\tCreate gerbils");
puts(" c\tCreate cats");
puts(" s\tCreate snakes");
result = func0(&v1);
if ( (int)result >= 0 )
{
if ( verbose )
printf("[debug %s()@user-input.c:%d] User input: '%c'\n", "do_god", 270LL, (unsigned int)v1);
result = (unsigned __int8)(v1 - 99);
switch ( v1 )
{
case 'c':
func5("amount of cats to try creating", v2);
create_animals(1LL, v2[0]);
continue;
case 'f':
func5("number of flowers", v2);
pthread_mutex_lock((pthread_mutex_t *)(unsigned int)((_DWORD)&vegetation + 16));
vegetation.__align = v2[0];
pthread_mutex_unlock((pthread_mutex_t *)(unsigned int)((_DWORD)&vegetation + 16));
continue;
case 'g':
func5("amount of gerbils to try creating", v2);
create_animals(0LL, v2[0]);
continue;
case 's':
func5("amount of snakes to try creating", v2);
create_animals(2LL, v2[0]);
continue;
case 't':
func5("number of trees", v2);
pthread_mutex_lock((pthread_mutex_t *)(unsigned int)((_DWORD)&vegetation + 16));
*(&vegetation.__align + 1) = v2[0];
pthread_mutex_unlock((pthread_mutex_t *)(unsigned int)((_DWORD)&vegetation + 16));
continue;
case 'x':
return result;
default:
printf("Unknown key: '%c'\n", (unsigned int)v1);
func1();
continue;
}
}
break;
}
return result;
}

original_code:
static
void do_god(void)
{
 char key;
 int ret;
 for (;;) {
  clear_screen();
  printf("[ root > god ]\n");
  printf("Enter the animal or vegetation you wish to modify:\n");
  printf("Modifications take effect immediately.\n");
  printf(" key	Description\n");
  printf("---------------------------------\n");
  printf("  x	Exit menu\n");
  printf("  f	Number of flowers\n");
  printf("  t	Number of trees\n");
  printf("  g	Create gerbils\n");
  printf("  c	Create cats\n");
  printf("  s	Create snakes\n");
  ret = getch(&key);
  if (ret < 0)
   goto end;
  do { if (verbose) printf("[debug %s()@" "user-input.c" ":%d] " "User input: \'%c\'" "\n", __func__, 270, key); } while (0);
  switch(key) {
  case 'x':
   goto end;
  case 'f':
  {
   uint64_t value;
   get_config_entry_uint64("number of flowers",
    &value);
   pthread_mutex_lock(&vegetation.lock);
   vegetation.flowers = value;
   pthread_mutex_unlock(&vegetation.lock);
   break;
  }
  case 't':
  {
   uint64_t value;
   get_config_entry_uint64("number of trees",
    &value);
   pthread_mutex_lock(&vegetation.lock);
   vegetation.trees = value;
   pthread_mutex_unlock(&vegetation.lock);
   break;
  }
  case 'g':
  {
   uint64_t value;
   get_config_entry_uint64("amount of gerbils to try creating",
    &value);
   create_animals(GERBIL, value);
   break;
  }
  case 'c':
  {
   uint64_t value;
   get_config_entry_uint64("amount of cats to try creating",
    &value);
   create_animals(CAT, value);
   break;
  }
  case 's':
  {
   uint64_t value;
   get_config_entry_uint64("amount of snakes to try creating",
    &value);
   create_animals(SNAKE, value);
   break;
  }
  default:
   printf("Unknown key: \'%c\'\n", key);
   wait_for_key();
   break;
  }
 }
end:
 return;
}

canonical_original_code:
static void do_god()
{
 char key;
 int ret;
 for (;;) {
  clear_screen();
  printf("[ root > god ]\n");
  printf("Enter the animal or vegetation you wish to modify:\n");
  printf("Modifications take effect immediately.\n");
  printf(" key	Description\n");
  printf("---------------------------------\n");
  printf("  x	Exit menu\n");
  printf("  f	Number of flowers\n");
  printf("  t	Number of trees\n");
  printf("  g	Create gerbils\n");
  printf("  c	Create cats\n");
  printf("  s	Create snakes\n");
  ret = getch(&key);
  if (ret < 0)
   goto end;
  do { if (verbose) printf("[debug %s()@" "user-input.c" ":%d] " "User input: \'%c\'" "\n", __func__, 270, key); } while (0);
  switch(key) {
  case 'x':
   goto end;
  case 'f':
  {
   unsigned long value;
   get_config_entry_uint64("number of flowers",
    &value);
   pthread_mutex_lock(&vegetation.lock);
   vegetation.flowers = value;
   pthread_mutex_unlock(&vegetation.lock);
   break;
  }
  case 't':
  {
   unsigned long value;
   get_config_entry_uint64("number of trees",
    &value);
   pthread_mutex_lock(&vegetation.lock);
   vegetation.trees = value;
   pthread_mutex_unlock(&vegetation.lock);
   break;
  }
  case 'g':
  {
   unsigned long value;
   get_config_entry_uint64("amount of gerbils to try creating",
    &value);
   create_animals(GERBIL, value);
   break;
  }
  case 'c':
  {
   unsigned long value;
   get_config_entry_uint64("amount of cats to try creating",
    &value);
   create_animals(CAT, value);
   break;
  }
  case 's':
  {
   unsigned long value;
   get_config_entry_uint64("amount of snakes to try creating",
    &value);
   create_animals(SNAKE, value);
   break;
  }
  default:
   printf("Unknown key: \'%c\'\n", key);
   wait_for_key();
   break;
  }
 }
end:
 return;
}

variable_types:
value
unsigned long


decompiled_code:
__int64 create_input_thread()
{
if ( pthread_create(&input_thread_id, 0LL, input_thread_fct, 0LL) )
create_input_thread_cold();
return 0LL;
}

canonical_decompiled_code:
__int64 func10()
{
if ( pthread_create(&input_thread_id, 0LL, input_thread_fct, 0LL) )
func13();
return 0LL;
}

original_code:
int create_input_thread(void)
{
 int err;
 err = pthread_create(&input_thread_id, ((void *)0),
  input_thread_fct, ((void *)0));
 if (err)
  abort();
 return 0;
}

canonical_original_code:
int create_input_thread()
{
 int err;
 err = pthread_create(&input_thread_id, ((void *)0),
  input_thread_fct, ((void *)0));
 if (err)
  abort();
 return 0;
}

variable_types: err int


decompiled_code:
__int64 join_input_thread()
{
void *thread_return; // [rsp+8h] [rbp-10h] BYREF

if ( pthread_join(input_thread_id, &thread_return) )
join_input_thread_cold();
return 0LL;
}

canonical_decompiled_code:
__int64 func11()
{
void *thread_return; // [rsp+8h] [rbp-10h] BYREF

if ( pthread_join(input_thread_id, &thread_return) )
func14();
return 0LL;
}

original_code:
int join_input_thread(void)
{
 int ret;
 void *tret;
 ret = pthread_join(input_thread_id, &tret);
 if (ret)
  abort();
 return 0;
}

canonical_original_code:
int join_input_thread()
{
 int ret;
 void *tret;
 ret = pthread_join(input_thread_id, &tret);
 if (ret)
  abort();
 return 0;
}

variable_types:
tret
void *


decompiled_code:
int __fastcall show_usage(__int64 a1, const char **a2)
{
printf("Usage: %s <OPTIONS>\n", *a2);
puts("OPTIONS:");
puts(" [-v] Verbose output.");
puts(" [-c] Disable clear screen.");
puts(" [-w nr_threads] Number of worker threads.");
puts(" [-h] Show this help.");
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, const char **a2)
{
printf("Usage: %s <OPTIONS>\n", *a2);
puts("OPTIONS:");
puts(" [-v] Verbose output.");
puts(" [-c] Disable clear screen.");
puts(" [-w nr_threads] Number of worker threads.");
puts(" [-h] Show this help.");
return putchar(10);
}

original_code:
void show_usage(int argc, char **argv)
{
 printf("Usage: %s <OPTIONS>\n", argv[0]);
 printf("OPTIONS:\n");
        printf("        [-v]             Verbose output.\n");
        printf("        [-c]             Disable clear screen.\n");
        printf("        [-w nr_threads]  Number of worker threads.\n");
 printf("        [-h]             Show this help.\n");
 printf("\n");
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
__int64 __fastcall parse_args(int a1, const char **a2)
{
int v3; // ebx
const char *v4; // rsi
__int64 v5; // rdx
char v6; // al
unsigned int v7; // er13

if ( a1 <= 1 )
return 0;
v3 = 1;
while ( 1 )
{
v4 = a2[v3];
v5 = v3;
if ( *v4 != 45 )
{
LABEL_19:
v7 = -1;
goto LABEL_9;
}
v6 = v4[1];
if ( v6 == 118 )
{
verbose = 1;
goto LABEL_14;
}
if ( v6 <= 118 )
{
if ( v6 != 99 )
{
if ( v6 == 104 )
{
v7 = 1;
goto LABEL_9;
}
LABEL_16:
v7 = -1;
printf("Unrecognised option %s\n", v4);
goto LABEL_9;
}
clear_screen_enable = 0;
goto LABEL_14;
}
if ( v6 != 119 )
goto LABEL_16;
if ( ++v3 >= a1 )
goto LABEL_19;
nr_worker_threads = atol(a2[v5 + 1]);
if ( nr_worker_threads <= 0 )
break;
LABEL_14:
if ( a1 <= ++v3 )
return 0;
}
v7 = -1;
puts("Please specify a positive and non-zero number of worker threads.");
LABEL_9:
show_usage((unsigned int)a1, a2);
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, const char **a2)
{
int v3; // ebx
const char *v4; // rsi
__int64 v5; // rdx
char v6; // al
unsigned int v7; // er13

if ( a1 <= 1 )
return 0;
v3 = 1;
while ( 1 )
{
v4 = a2[v3];
v5 = v3;
if ( *v4 != 45 )
{
LABEL_19:
v7 = -1;
goto LABEL_9;
}
v6 = v4[1];
if ( v6 == 118 )
{
verbose = 1;
goto LABEL_14;
}
if ( v6 <= 118 )
{
if ( v6 != 99 )
{
if ( v6 == 104 )
{
v7 = 1;
goto LABEL_9;
}
LABEL_16:
v7 = -1;
printf("Unrecognised option %s\n", v4);
goto LABEL_9;
}
clear_screen_enable = 0;
goto LABEL_14;
}
if ( v6 != 119 )
goto LABEL_16;
if ( ++v3 >= a1 )
goto LABEL_19;
nr_worker_threads = atol(a2[v5 + 1]);
if ( nr_worker_threads <= 0 )
break;
LABEL_14:
if ( a1 <= ++v3 )
return 0;
}
v7 = -1;
puts("Please specify a positive and non-zero number of worker threads.");
LABEL_9:
func1((unsigned int)a1, a2);
return v7;
}

original_code:
int parse_args(int argc, char **argv)
{
 int i, err = 0;
 for (i = 1; i < argc; i++) {
  if (argv[i][0] != '-') {
   err = -1;
   goto end;
  }
  switch(argv[i][1]) {
  case 'w':
   if (argc < i + 2) {
    err = -1;
    goto end;
   }
   nr_worker_threads = atol(argv[++i]);
   if (nr_worker_threads <= 0) {
    printf("Please specify a positive and non-zero number of worker threads.\n");
    err = -1;
    goto end;
   }
   break;
  case 'v':
   verbose = 1;
   break;
  case 'c':
   clear_screen_enable = 0;
   break;
  case 'h':
   err = 1;
   goto end;
  default:
   printf("Unrecognised option %s\n", argv[i]);
   err = -1;
   goto end;
  }
 }
end:
 if (err)
  show_usage(argc, argv);
 return err;
}

canonical_original_code:
int parse_args(int argc, char **argv)
{
 int i; int err = 0;
 for (i = 1; i < argc; i++) {
  if (argv[i][0] != '-') {
   err = -1;
   goto end;
  }
  switch(argv[i][1]) {
  case 'w':
   if (argc < i + 2) {
    err = -1;
    goto end;
   }
   nr_worker_threads = atol(argv[++i]);
   if (nr_worker_threads <= 0) {
    printf("Please specify a positive and non-zero number of worker threads.\n");
    err = -1;
    goto end;
   }
   break;
  case 'v':
   verbose = 1;
   break;
  case 'c':
   clear_screen_enable = 0;
   break;
  case 'h':
   err = 1;
   goto end;
  default:
   printf("Unrecognised option %s\n", argv[i]);
   err = -1;
   goto end;
  }
 }
end:
 if (err)
  show_usage(argc, argv);
 return err;
}

variable_types: i int


main

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

rcu_register_thread_memb(argc, argv, envp);
v3 = parse_args(argc, argv);
if ( v3 >= 0 )
{
if ( v3 )
goto LABEL_21;
puts("Welcome to the Island of RCU\n");
printf("Spawning %ld worker threads.\n", nr_worker_threads);
init_game_config();
live_animals[4] = time(0LL);
v4 = cds_lfht_new_constprop_0();
live_animals[3] = v4;
if ( !v4
|| (live_animals[0] = cds_lfht_new_constprop_0()) == 0
|| (v5 = cds_lfht_new_constprop_0(), (live_animals[1] = v5) == 0)
|| (v6 = cds_lfht_new_constprop_0(), (live_animals[2] = v6) == 0) )
{
main_cold();
}
if ( !(unsigned int)create_worker_threads(nr_worker_threads)
&& !(unsigned int)create_input_thread()
&& !(unsigned int)create_output_thread()
&& !(unsigned int)create_dispatch_thread()
&& !(unsigned int)join_dispatch_thread()
&& !(unsigned int)join_output_thread()
&& !(unsigned int)join_input_thread()
&& !(unsigned int)join_worker_threads() )
{
apocalypse();
if ( !(unsigned int)cds_lfht_destroy(live_animals[2], 0LL)
&& !(unsigned int)cds_lfht_destroy(live_animals[1], 0LL)
&& !(unsigned int)cds_lfht_destroy(live_animals[0], 0LL)
&& !(unsigned int)cds_lfht_destroy(live_animals[3], 0LL) )
{
rcu_barrier_memb();
puts("Goodbye!");
LABEL_21:
rcu_unregister_thread_memb();
exit(0);
}
}
}
rcu_unregister_thread_memb();
fwrite("Something went wrong!\n", 1uLL, 0x16uLL, stderr);
exit(1);
}

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

rcu_register_thread_memb(argc, argv, envp);
v3 = func2(argc, argv);
if ( v3 >= 0 )
{
if ( v3 )
goto LABEL_21;
puts("Welcome to the Island of RCU\n");
printf("Spawning %ld worker threads.\n", nr_worker_threads);
init_game_config();
live_animals[4] = time(0LL);
v4 = func0();
live_animals[3] = v4;
if ( !v4
|| (live_animals[0] = func0()) == 0
|| (v5 = func0(), (live_animals[1] = v5) == 0)
|| (v6 = func0(), (live_animals[2] = v6) == 0) )
{
func3();
}
if ( !(unsigned int)create_worker_threads(nr_worker_threads)
&& !(unsigned int)create_input_thread()
&& !(unsigned int)create_output_thread()
&& !(unsigned int)create_dispatch_thread()
&& !(unsigned int)join_dispatch_thread()
&& !(unsigned int)join_output_thread()
&& !(unsigned int)join_input_thread()
&& !(unsigned int)join_worker_threads() )
{
apocalypse();
if ( !(unsigned int)cds_lfht_destroy(live_animals[2], 0LL)
&& !(unsigned int)cds_lfht_destroy(live_animals[1], 0LL)
&& !(unsigned int)cds_lfht_destroy(live_animals[0], 0LL)
&& !(unsigned int)cds_lfht_destroy(live_animals[3], 0LL) )
{
rcu_barrier_memb();
puts("Goodbye!");
LABEL_21:
rcu_unregister_thread_memb();
exit(0);
}
}
}
rcu_unregister_thread_memb();
fwrite("Something went wrong!\n", 1uLL, 0x16uLL, stderr);
exit(1);
}

original_code:
int main(int argc, char **argv)
{
 int err;
 rcu_register_thread_memb();
 err = parse_args(argc, argv);
 if (err < 0)
  goto end;
 else if (err > 0) {
  err = 0;
  goto end;
 }
 printf("Welcome to the Island of RCU\n\n");
 printf("Spawning %ld worker threads.\n",
  nr_worker_threads);
 init_game_config();
 live_animals.ht_seed = time(((void *)0));
 live_animals.all = cds_lfht_new(4096, 1, 0,
  CDS_LFHT_AUTO_RESIZE | CDS_LFHT_ACCOUNTING, ((void *)0));
 if (!live_animals.all)
  abort();
 live_animals.gerbil = cds_lfht_new(4096, 1, 0,
  CDS_LFHT_AUTO_RESIZE | CDS_LFHT_ACCOUNTING, ((void *)0));
 if (!live_animals.gerbil)
  abort();
 live_animals.cat = cds_lfht_new(4096, 1, 0,
  CDS_LFHT_AUTO_RESIZE | CDS_LFHT_ACCOUNTING, ((void *)0));
 if (!live_animals.cat)
  abort();
 live_animals.snake = cds_lfht_new(4096, 1, 0,
  CDS_LFHT_AUTO_RESIZE | CDS_LFHT_ACCOUNTING, ((void *)0));
 if (!live_animals.snake)
  abort();
 err = create_worker_threads(nr_worker_threads);
 if (err)
  goto end;
 err = create_input_thread();
 if (err)
  goto end;
 err = create_output_thread();
 if (err)
  goto end;
 err = create_dispatch_thread();
 if (err)
  goto end;
 err = join_dispatch_thread();
 if (err)
  goto end;
 err = join_output_thread();
 if (err)
  goto end;
 err = join_input_thread();
 if (err)
  goto end;
 err = join_worker_threads();
 if (err)
  goto end;
 apocalypse();
 err = cds_lfht_destroy(live_animals.snake, ((void *)0));
 if (err)
  goto end;
 err = cds_lfht_destroy(live_animals.cat, ((void *)0));
 if (err)
  goto end;
 err = cds_lfht_destroy(live_animals.gerbil, ((void *)0));
 if (err)
  goto end;
 err = cds_lfht_destroy(live_animals.all, ((void *)0));
 if (err)
  goto end;
 rcu_barrier_memb();
 printf("Goodbye!\n");
end:
 rcu_unregister_thread_memb();
 if (err) {
  fprintf(stderr, "Something went wrong!\n");
  exit(1);
 } else {
  exit(0);
 }
}


decompiled_code:
__int64 __fastcall do_work(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // rax
__int64 v3; // r12

if ( !*(_DWORD *)(a1 + 24) )
{
if ( verbose )
printf(
"[debug %s()@worker-thread.c:%d] do work: key1 %lu, key2 %lu\n",
"do_work",
49LL,
*(_QWORD *)(a1 + 8),
*(_QWORD *)(a1 + 16));
rcu_read_lock_memb();
v1 = find_animal(*(_QWORD *)(a1 + 8));
v2 = find_animal(*(_QWORD *)(a1 + 16));
v3 = v2;
if ( !v1 )
{
if ( !v2 )
{
LABEL_12:
rcu_read_unlock_memb();
return 0LL;
}
v1 = v2;
v3 = 0LL;
}
if ( (unsigned int)try_birth(v1, *(_QWORD *)(a1 + 16), 0LL) && verbose )
printf("[debug %s()@worker-thread.c:%d] birth success\n", "do_work", 73LL);
if ( (unsigned int)try_eat(v1, v3) && verbose )
printf("[debug %s()@worker-thread.c:%d] eat success\n", "do_work", 75LL);
if ( (unsigned int)try_mate(v1, v3) )
{
if ( verbose )
printf("[debug %s()@worker-thread.c:%d] mate success\n", "do_work", 77LL);
}
goto LABEL_12;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // rax
__int64 v3; // r12

if ( !*(_DWORD *)(a1 + 24) )
{
if ( verbose )
printf(
"[debug %s()@worker-thread.c:%d] do work: key1 %lu, key2 %lu\n",
"do_work",
49LL,
*(_QWORD *)(a1 + 8),
*(_QWORD *)(a1 + 16));
rcu_read_lock_memb();
v1 = find_animal(*(_QWORD *)(a1 + 8));
v2 = find_animal(*(_QWORD *)(a1 + 16));
v3 = v2;
if ( !v1 )
{
if ( !v2 )
{
LABEL_12:
rcu_read_unlock_memb();
return 0LL;
}
v1 = v2;
v3 = 0LL;
}
if ( (unsigned int)try_birth(v1, *(_QWORD *)(a1 + 16), 0LL) && verbose )
printf("[debug %s()@worker-thread.c:%d] birth success\n", "do_work", 73LL);
if ( (unsigned int)try_eat(v1, v3) && verbose )
printf("[debug %s()@worker-thread.c:%d] eat success\n", "do_work", 75LL);
if ( (unsigned int)try_mate(v1, v3) )
{
if ( verbose )
printf("[debug %s()@worker-thread.c:%d] mate success\n", "do_work", 77LL);
}
goto LABEL_12;
}
return 1LL;
}

original_code:
static
int do_work(struct urcu_game_work *work)
{
 struct animal *first, *second;
 if (work->exit_thread)
  return 1;
 do { if (verbose) printf("[debug %s()@" "worker-thread.c" ":%d] " "do work: key1 %" "l" "u" ", key2 %" "l" "u" "\n", __func__, 49, work->first_key, work->second_key); } while (0);
 rcu_read_lock_memb();
 first = find_animal(work->first_key);
 second = find_animal(work->second_key);
 if (!first) {
  first = second;
  if (!first)
   goto end;
  if (first == second) {
   second = ((void *)0);
  }
 }
 if (try_birth(first, work->second_key, 0))
  do { if (verbose) printf("[debug %s()@" "worker-thread.c" ":%d] " "birth success" "\n", __func__, 73); } while (0);
 if (try_eat(first, second))
  do { if (verbose) printf("[debug %s()@" "worker-thread.c" ":%d] " "eat success" "\n", __func__, 75); } while (0);
 if (try_mate(first, second))
  do { if (verbose) printf("[debug %s()@" "worker-thread.c" ":%d] " "mate success" "\n", __func__, 77); } while (0);
end:
 rcu_read_unlock_memb();
 return 0;
}

canonical_original_code:
static int do_work(struct urcu_game_work *work)
{
 struct animal *first; struct animal *second;
 if (work->exit_thread)
  return 1;
 do { if (verbose) printf("[debug %s()@" "worker-thread.c" ":%d] " "do work: key1 %" "l" "u" ", key2 %" "l" "u" "\n", __func__, 49, work->first_key, work->second_key); } while (0);
 rcu_read_lock_memb();
 first = find_animal(work->first_key);
 second = find_animal(work->second_key);
 if (!first) {
  first = second;
  if (!first)
   goto end;
  if (first == second) {
   second = ((void *)0);
  }
 }
 if (try_birth(first, work->second_key, 0))
  do { if (verbose) printf("[debug %s()@" "worker-thread.c" ":%d] " "birth success" "\n", __func__, 73); } while (0);
 if (try_eat(first, second))
  do { if (verbose) printf("[debug %s()@" "worker-thread.c" ":%d] " "eat success" "\n", __func__, 75); } while (0);
 if (try_mate(first, second))
  do { if (verbose) printf("[debug %s()@" "worker-thread.c" ":%d] " "mate success" "\n", __func__, 77); } while (0);
end:
 rcu_read_unlock_memb();
 return 0;
}

variable_types: struct urcu_game_work { struct cds_wfcq_node { struct cds_wfcq_node *next; } q_node; unsigned long first_key; unsigned long second_key; int exit_thread; } *

variable_types: struct animal { struct animal_kind { unsigned long max_birth_stamina; unsigned long max_pregnant; enum animal_types { GERBIL=0, CAT=1, SNAKE=2 } animal; unsigned int diet; } kind; enum animal_sex { ANIMAL_MALE=0, ANIMAL_FEMALE=1 } animal_sex; unsigned long key; unsigned long stamina; unsigned long nr_pregnant; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; struct cds_lfht_node { struct cds_lfht_node *next; unsigned long reverse_hash; } kind_node; struct cds_lfht_node all_node; struct rcu_head { struct cds_wfcq_node { struct cds_wfcq_node *next; } next; void (*func)(struct rcu_head *head); } rcu_head; } *

user_defined_types: struct urcu_game_work { struct cds_wfcq_node q_node; unsigned long first_key; unsigned long second_key; int exit_thread; }

user_defined_types: struct animal { struct animal_kind kind; enum animal_sex animal_sex; unsigned long key; unsigned long stamina; unsigned long nr_pregnant; union pthread_mutex_t lock; struct cds_lfht_node kind_node; struct cds_lfht_node all_node; struct rcu_head rcu_head; }

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

user_defined_types: struct rcu_head { struct cds_wfcq_node next; void (*func)(struct rcu_head *head); }

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:
__int64 get_nr_worker_threads()
{
return nr_worker_threads;
}

canonical_decompiled_code:
__int64 func2()
{
return nr_worker_threads;
}

original_code:
unsigned long get_nr_worker_threads(void)
{
 return nr_worker_threads;
}

canonical_original_code:
unsigned long get_nr_worker_threads()
{
 return nr_worker_threads;
}

return_type: unsigned long


decompiled_code:
__int64 __fastcall create_worker_threads(size_t a1)
{
char *v1; // rax
char *v2; // r12
pthread_t v3; // rbx
pthread_t *v4; // r12

v1 = (char *)calloc(a1, 0x80uLL);
worker_threads = v1;
if ( !v1 )
return 0xFFFFFFFFLL;
if ( a1 )
{
v2 = v1;
v3 = 0LL;
while ( 1 )
{
v4 = (pthread_t *)&v2[128 * v3];
cds_wfcq_init(v4 + 1, v4);
v4[8] = v3;
if ( pthread_create(v4 + 9, 0LL, worker_thread_fct, v4) )
create_worker_threads_cold();
if ( a1 == ++v3 )
break;
v2 = (char *)worker_threads;
}
}
nr_worker_threads = a1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(size_t a1)
{
char *v1; // rax
char *v2; // r12
pthread_t v3; // rbx
pthread_t *v4; // r12

v1 = (char *)calloc(a1, 0x80uLL);
worker_threads = v1;
if ( !v1 )
return 0xFFFFFFFFLL;
if ( a1 )
{
v2 = v1;
v3 = 0LL;
while ( 1 )
{
v4 = (pthread_t *)&v2[128 * v3];
cds_wfcq_init(v4 + 1, v4);
v4[8] = v3;
if ( pthread_create(v4 + 9, 0LL, worker_thread_fct, v4) )
func8();
if ( a1 == ++v3 )
break;
v2 = (char *)worker_threads;
}
}
nr_worker_threads = a1;
return 0LL;
}

original_code:
int create_worker_threads(unsigned long nr_threads)
{
 unsigned long i;
 int err;
 worker_threads = calloc(nr_threads, sizeof(*worker_threads));
 if (!worker_threads)
  return -1;
 for (i = 0; i < nr_threads; i++) {
  struct worker_thread *worker;
  worker = &worker_threads[i];
  cds_wfcq_init(&worker->q_head, &worker->q_tail);
  worker->id = i;
  err = pthread_create(&worker->thread_id, ((void *)0),
   worker_thread_fct, worker);
  if (err)
   abort();
 }
 nr_worker_threads = nr_threads;
 return 0;
}

variable_types:
i
unsigned long

variable_types: struct worker_thread { struct cds_wfcq_tail { struct cds_wfcq_node { struct cds_wfcq_node *next; } *p; } q_tail; struct cds_wfcq_head { struct cds_wfcq_node node; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; } q_head; unsigned long q_len; unsigned long id; unsigned long thread_id; } *

user_defined_types: struct worker_thread { struct cds_wfcq_tail q_tail; struct cds_wfcq_head q_head; unsigned long q_len; unsigned long id; unsigned long thread_id; }

user_defined_types: struct cds_wfcq_tail { struct cds_wfcq_node *p; }

user_defined_types: struct cds_wfcq_head { struct cds_wfcq_node node; union pthread_mutex_t lock; }


decompiled_code:
__int64 join_worker_threads()
{
unsigned __int64 v0; // rbx
void *thread_return; // [rsp+8h] [rbp-10h] BYREF

if ( nr_worker_threads )
{
v0 = 0LL;
do
{
if ( pthread_join(*((_QWORD *)worker_threads + 16 * v0 + 9), &thread_return) )
join_worker_threads_cold();
++v0;
}
while ( nr_worker_threads > v0 );
}
free(worker_threads);
return 0LL;
}

canonical_decompiled_code:
__int64 func4()
{
unsigned __int64 v0; // rbx
void *thread_return; // [rsp+8h] [rbp-10h] BYREF

if ( nr_worker_threads )
{
v0 = 0LL;
do
{
if ( pthread_join(*((_QWORD *)worker_threads + 16 * v0 + 9), &thread_return) )
func9();
++v0;
}
while ( nr_worker_threads > v0 );
}
free(worker_threads);
return 0LL;
}

original_code:
int join_worker_threads(void)
{
 unsigned long i;
 for (i = 0; i < nr_worker_threads; i++) {
  struct worker_thread *worker;
  void *tret;
  int ret;
  worker = &worker_threads[i];
  ret = pthread_join(worker->thread_id, &tret);
  if (ret)
   abort();
 }
 free(worker_threads);
 return 0;
}

canonical_original_code:
int join_worker_threads()
{
 unsigned long i;
 for (i = 0; i < nr_worker_threads; i++) {
  struct worker_thread *worker;
  void *tret;
  int ret;
  worker = &worker_threads[i];
  ret = pthread_join(worker->thread_id, &tret);
  if (ret)
   abort();
 }
 free(worker_threads);
 return 0;
}

variable_types: ret int

user_defined_types: struct cds_wfcq_node { struct cds_wfcq_node *next; }

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


decompiled_code:
__int64 __fastcall stop_thread(__int64 a1)
{
_DWORD *v1; // rax
__int64 result; // rax

v1 = calloc(1uLL, 0x80uLL);
if ( !v1 || (v1[6] = 1, result = enqueue_work(*(_QWORD *)(a1 + 64), (__int64)v1), (_DWORD)result) )
stop_thread_cold();
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
_DWORD *v1; // rax
__int64 result; // rax

v1 = calloc(1uLL, 0x80uLL);
if ( !v1 || (v1[6] = 1, result = func5(*(_QWORD *)(a1 + 64), (__int64)v1), (_DWORD)result) )
func10();
return result;
}

original_code:
static
void stop_thread(struct worker_thread *thread)
{
 struct urcu_game_work *work;
 int ret;
 work = calloc(1, sizeof(*work));
 if (!work)
  abort();
 work->exit_thread = 1;
 ret = enqueue_work(thread->id, work);
 if (ret)
  abort();
}


decompiled_code:
__int64 stop_worker_threads()
{
unsigned __int64 v0; // rbx
unsigned __int64 v1; // rdi
__int64 result; // rax

if ( nr_worker_threads )
{
v0 = 0LL;
do
{
v1 = v0++;
result = stop_thread((__int64)worker_threads + 128 * v1);
}
while ( nr_worker_threads > v0 );
}
return result;
}

canonical_decompiled_code:
__int64 func7()
{
unsigned __int64 v0; // rbx
unsigned __int64 v1; // rdi
__int64 result; // rax

if ( nr_worker_threads )
{
v0 = 0LL;
do
{
v1 = v0++;
result = func6((__int64)worker_threads + 128 * v1);
}
while ( nr_worker_threads > v0 );
}
return result;
}

original_code:
void stop_worker_threads(void)
{
 unsigned long i;
 for (i = 0; i < nr_worker_threads; i++) {
  struct worker_thread *worker;
  worker = &worker_threads[i];
  stop_thread(worker);
 }
}

canonical_original_code:
void stop_worker_threads()
{
 unsigned long i;
 for (i = 0; i < nr_worker_threads; i++) {
  struct worker_thread *worker;
  worker = &worker_threads[i];
  stop_thread(worker);
 }
}


decompiled_code:
__m128i *urcu_game_config_update_begin()
{
__m128i *v0; // r12
const __m128i *v1; // rax

v0 = (__m128i *)malloc(0x58uLL);
if ( !v0 )
return v0;
pthread_mutex_lock(&config_mutex);
v1 = (const __m128i *)current_config;
if ( current_config )
{
*v0 = _mm_loadu_si128((const __m128i *)current_config);
v0[1] = _mm_loadu_si128(v1 + 1);
v0[2] = _mm_loadu_si128(v1 + 2);
v0[3] = _mm_loadu_si128(v1 + 3);
v0[4] = _mm_loadu_si128(v1 + 4);
v0[5].m128i_i64[0] = v1[5].m128i_i64[0];
return v0;
}
memset64(v0, (unsigned __int64)current_config, 0xBuLL);
return v0;
}

canonical_decompiled_code:
__m128i *func1()
{
__m128i *v0; // r12
const __m128i *v1; // rax

v0 = (__m128i *)malloc(0x58uLL);
if ( !v0 )
return v0;
pthread_mutex_lock(&config_mutex);
v1 = (const __m128i *)current_config;
if ( current_config )
{
*v0 = _mm_loadu_si128((const __m128i *)current_config);
v0[1] = _mm_loadu_si128(v1 + 1);
v0[2] = _mm_loadu_si128(v1 + 2);
v0[3] = _mm_loadu_si128(v1 + 3);
v0[4] = _mm_loadu_si128(v1 + 4);
v0[5].m128i_i64[0] = v1[5].m128i_i64[0];
return v0;
}
memset64(v0, (unsigned __int64)current_config, 0xBuLL);
return v0;
}

original_code:
struct urcu_game_config *urcu_game_config_update_begin(void)
{
 struct urcu_game_config *new_config;
 new_config = malloc(sizeof(*new_config));
 if (!new_config) {
  return ((void *)0);
 }
 pthread_mutex_lock(&config_mutex);
 if (current_config)
  memcpy(new_config, current_config, sizeof(*new_config));
 else
  memset(new_config, 0, sizeof(*new_config));
 return new_config;
}

canonical_original_code:
struct urcu_game_config *urcu_game_config_update_begin()
{
 struct urcu_game_config *new_config;
 new_config = malloc(sizeof(*new_config));
 if (!new_config) {
  return ((void *)0);
 }
 pthread_mutex_lock(&config_mutex);
 if (current_config)
  memcpy(new_config, current_config, sizeof(*new_config));
 else
  memset(new_config, 0, sizeof(*new_config));
 return new_config;
}

return_type: struct urcu_game_config { unsigned long island_size; unsigned int step_delay; struct animal_kind { unsigned long max_birth_stamina; unsigned long max_pregnant; enum animal_types { GERBIL=0, CAT=1, SNAKE=2 } animal; unsigned int diet; } gerbil; struct animal_kind cat; struct animal_kind snake; } *


decompiled_code:
void __fastcall urcu_game_config_update_end(__int64 a1)
{
void *v1; // rbp

v1 = current_config;
rcu_set_pointer_sym(&current_config, a1);
pthread_mutex_unlock(&config_mutex);
if ( v1 )
{
synchronize_rcu_memb();
free(v1);
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
void *v1; // rbp

v1 = current_config;
rcu_set_pointer_sym(&current_config, a1);
pthread_mutex_unlock(&config_mutex);
if ( v1 )
{
synchronize_rcu_memb();
free(v1);
}
}

original_code:
void urcu_game_config_update_end(struct urcu_game_config *new_config)
{
 struct urcu_game_config *old_config;
 old_config = current_config;
 do { __typeof__(*(&current_config)) _________pv = (new_config); (void) rcu_set_pointer_sym(((void **) (&current_config)), _________pv); } while (0);
 pthread_mutex_unlock(&config_mutex);
 if (old_config) {
  synchronize_rcu_memb();
  free(old_config);
 }
}

user_defined_types: enum animal_types { GERBIL=0, CAT=1, SNAKE=2 }


decompiled_code:
void __fastcall urcu_game_config_update_abort(void *ptr)
{
pthread_mutex_unlock(&config_mutex);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
pthread_mutex_unlock(&config_mutex);
free(ptr);
}

original_code:
void urcu_game_config_update_abort(struct urcu_game_config *new_config)
{
 pthread_mutex_unlock(&config_mutex);
 free(new_config);
}


original_code:
void init_game_config(void)
{
 struct urcu_game_config *new_config;
 new_config = urcu_game_config_update_begin();
 new_config->island_size = 2 * (1000 + 200);
 new_config->step_delay = 1000;
 new_config->gerbil.max_birth_stamina =
   70;
 new_config->gerbil.animal = GERBIL;
 new_config->gerbil.diet = DIET_FLOWERS | DIET_TREES;
 new_config->gerbil.max_pregnant = 10;
 new_config->cat.max_birth_stamina =
   80;
 new_config->cat.animal = CAT;
 new_config->cat.diet = DIET_GERBIL | DIET_FLOWERS;
 new_config->cat.max_pregnant = 4;
 new_config->snake.max_birth_stamina =
   30;
 new_config->snake.animal = SNAKE;
 new_config->snake.diet = DIET_GERBIL | DIET_CAT;
 new_config->snake.max_pregnant = 1;
 urcu_game_config_update_end(new_config);
}

canonical_original_code:
void init_game_config()
{
 struct urcu_game_config *new_config;
 new_config = urcu_game_config_update_begin();
 new_config->island_size = 2 * (1000 + 200);
 new_config->step_delay = 1000;
 new_config->gerbil.max_birth_stamina =
   70;
 new_config->gerbil.animal = GERBIL;
 new_config->gerbil.diet = DIET_FLOWERS | DIET_TREES;
 new_config->gerbil.max_pregnant = 10;
 new_config->cat.max_birth_stamina =
   80;
 new_config->cat.animal = CAT;
 new_config->cat.diet = DIET_GERBIL | DIET_FLOWERS;
 new_config->cat.max_pregnant = 4;
 new_config->snake.max_birth_stamina =
   30;
 new_config->snake.animal = SNAKE;
 new_config->snake.diet = DIET_GERBIL | DIET_CAT;
 new_config->snake.max_pregnant = 1;
 urcu_game_config_update_end(new_config);
}


decompiled_code:
int clear_screen()
{
int result; // eax

putchar(10);
result = clear_screen_enable;
if ( clear_screen_enable )
result = printf("%c[2J%c[;H", 27LL, 27LL);
return result;
}

canonical_decompiled_code:
int func0()
{
int result; // eax

putchar(10);
result = clear_screen_enable;
if ( clear_screen_enable )
result = printf("%c[2J%c[;H", 27LL, 27LL);
return result;
}

original_code:
static inline
void clear_screen(void)
{
 printf("\n");
 if (clear_screen_enable)
  printf("%c[2J%c[;H", (char) 27, (char) 27);
}


decompiled_code:
__int64 create_output_thread()
{
if ( pthread_create(&output_thread_id, 0LL, output_thread_fct, 0LL) )
create_output_thread_cold();
return 0LL;
}

canonical_decompiled_code:
__int64 func4()
{
if ( pthread_create(&output_thread_id, 0LL, output_thread_fct, 0LL) )
func6();
return 0LL;
}

original_code:
int create_output_thread(void)
{
 int err;
 err = pthread_create(&output_thread_id, ((void *)0),
  output_thread_fct, ((void *)0));
 if (err)
  abort();
 return 0;
}

canonical_original_code:
int create_output_thread()
{
 int err;
 err = pthread_create(&output_thread_id, ((void *)0),
  output_thread_fct, ((void *)0));
 if (err)
  abort();
 return 0;
}


decompiled_code:
__int64 join_output_thread()
{
void *thread_return; // [rsp+8h] [rbp-10h] BYREF

if ( pthread_join(output_thread_id, &thread_return) )
join_output_thread_cold();
return 0LL;
}

canonical_decompiled_code:
__int64 func5()
{
void *thread_return; // [rsp+8h] [rbp-10h] BYREF

if ( pthread_join(output_thread_id, &thread_return) )
func7();
return 0LL;
}

original_code:
int join_output_thread(void)
{
 int ret;
 void *tret;
 ret = pthread_join(output_thread_id, &tret);
 if (ret)
  abort();
 return 0;
}

canonical_original_code:
int join_output_thread()
{
 int ret;
 void *tret;
 ret = pthread_join(output_thread_id, &tret);
 if (ret)
  abort();
 return 0;
}


decompiled_code:
__int64 do_dispatch()
{
unsigned __int64 v0; // rbx
__int64 result; // rax
__int64 v2; // r13
__int64 i; // r12
_QWORD *v4; // rbp
unsigned int *v5; // r14

rcu_read_lock_memb();
v0 = *(_QWORD *)urcu_game_config_get();
rcu_read_unlock_memb();
result = get_nr_worker_threads();
if ( result )
{
v2 = result;
for ( i = 0LL; i != v2; ++i )
{
v4 = calloc(1uLL, 0x80uLL);
if ( v4 )
{
v5 = (unsigned int *)((char *)&thread_rand_seed + __readfsqword(0));
v4[1] = rand_r(v5) % v0;
v4[2] = rand_r(v5) % v0;
result = enqueue_work(i, v4);
if ( !(_DWORD)result )
continue;
}
do_dispatch_cold();
}
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned __int64 v0; // rbx
__int64 result; // rax
__int64 v2; // r13
__int64 i; // r12
_QWORD *v4; // rbp
unsigned int *v5; // r14

rcu_read_lock_memb();
v0 = *(_QWORD *)urcu_game_config_get();
rcu_read_unlock_memb();
result = get_nr_worker_threads();
if ( result )
{
v2 = result;
for ( i = 0LL; i != v2; ++i )
{
v4 = calloc(1uLL, 0x80uLL);
if ( v4 )
{
v5 = (unsigned int *)((char *)&thread_rand_seed + __readfsqword(0));
v4[1] = rand_r(v5) % v0;
v4[2] = rand_r(v5) % v0;
result = enqueue_work(i, v4);
if ( !(_DWORD)result )
continue;
}
func4();
}
}
return result;
}

original_code:
static
void do_dispatch(void)
{
 struct urcu_game_config *config;
 unsigned long i, nr_threads;
 uint64_t island_size;
 int ret;
 rcu_read_lock_memb();
 config = urcu_game_config_get();
 island_size = config->island_size;
 rcu_read_unlock_memb();
 nr_threads = get_nr_worker_threads();
 for (i = 0; i < nr_threads; i++) {
  struct urcu_game_work *work;
  work = calloc(1, sizeof(*work));
  if (!work)
   abort();
  work->first_key = rand_r(&thread_rand_seed) % island_size;
  work->second_key = rand_r(&thread_rand_seed) % island_size;
  ret = enqueue_work(i, work);
  if (ret)
   abort();
 }
}

canonical_original_code:
static void do_dispatch()
{
 struct urcu_game_config *config;
 unsigned long i; unsigned long nr_threads;
 unsigned long island_size;
 int ret;
 rcu_read_lock_memb();
 config = urcu_game_config_get();
 island_size = config->island_size;
 rcu_read_unlock_memb();
 nr_threads = get_nr_worker_threads();
 for (i = 0; i < nr_threads; i++) {
  struct urcu_game_work *work;
  work = calloc(1, sizeof(*work));
  if (!work)
   abort();
  work->first_key = rand_r(&thread_rand_seed) % island_size;
  work->second_key = rand_r(&thread_rand_seed) % island_size;
  ret = enqueue_work(i, work);
  if (ret)
   abort();
 }
}


decompiled_code:
__int64 create_dispatch_thread()
{
if ( pthread_create(&dispatch_thread_id, 0LL, dispatch_thread_fct, 0LL) )
create_dispatch_thread_cold();
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
if ( pthread_create(&dispatch_thread_id, 0LL, dispatch_thread_fct, 0LL) )
func5();
return 0LL;
}

original_code:
int create_dispatch_thread(void)
{
 int err;
 err = pthread_create(&dispatch_thread_id, ((void *)0),
  dispatch_thread_fct, ((void *)0));
 if (err)
  abort();
 return 0;
}

canonical_original_code:
int create_dispatch_thread()
{
 int err;
 err = pthread_create(&dispatch_thread_id, ((void *)0),
  dispatch_thread_fct, ((void *)0));
 if (err)
  abort();
 return 0;
}


decompiled_code:
__int64 join_dispatch_thread()
{
void *thread_return; // [rsp+8h] [rbp-10h] BYREF

if ( pthread_join(dispatch_thread_id, &thread_return) )
join_dispatch_thread_cold();
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
void *thread_return; // [rsp+8h] [rbp-10h] BYREF

if ( pthread_join(dispatch_thread_id, &thread_return) )
func6();
return 0LL;
}

original_code:
int join_dispatch_thread(void)
{
 int ret;
 void *tret;
 ret = pthread_join(dispatch_thread_id, &tret);
 if (ret)
  abort();
 return 0;
}

canonical_original_code:
int join_dispatch_thread()
{
 int ret;
 void *tret;
 ret = pthread_join(dispatch_thread_id, &tret);
 if (ret)
  abort();
 return 0;
}