routine

repo: scoiatael/OpSysProgramming

decompiled_code:
void *__fastcall routine(void *a1)
{
pthread_t v1; // rax

if ( !a1 )
__assert_fail("barrier!=NULL", "10.c", 7u, "routine");
v1 = pthread_self();
printf(" thread id: %lld\n", v1);
if ( (unsigned int)(pthread_barrier_wait((pthread_barrier_t *)a1) + 1) > 1 )
puts("pthread_barrier_wait failed");
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func7(void *a1)
{
pthread_t v1; // rax

if ( !a1 )
__assert_fail("barrier!=NULL", "10.c", 7u, "routine");
v1 = pthread_self();
printf(" thread id: %lld\n", v1);
if ( (unsigned int)(pthread_barrier_wait((pthread_barrier_t *)a1) + 1) > 1 )
puts("pthread_barrier_wait failed");
return 0LL;
}

original_code:
void* routine(void* barrier)
{
  ((void) sizeof ((barrier!=((void *)0)) ? 1 : 0), __extension__ ({ if (barrier!=((void *)0)) ; else __assert_fail ("barrier!=NULL", "10.c", 7, __extension__ __PRETTY_FUNCTION__); }));
  printf(" thread id: %lld\n", (long long int)pthread_self());
  int r;
  r = pthread_barrier_wait((pthread_barrier_t*) barrier);
  if(r != -1 && r != 0)
  {
    printf("pthread_barrier_wait failed\n");
  }
  return ((void *)0);
}

canonical_original_code:
void *routine(void *barrier)
{
  ((void) sizeof ((barrier!=((void *)0)) ? 1 : 0), __extension__ ({ if (barrier!=((void *)0)) ; else __assert_fail ("barrier!=NULL", "10.c", 7, __extension__ __PRETTY_FUNCTION__); }));
  printf(" thread id: %lld\n", (long long)pthread_self());
  int r;
  r = pthread_barrier_wait((union pthread_barrier_t *) barrier);
  if(r != -1 && r != 0)
  {
    printf("pthread_barrier_wait failed\n");
  }
  return ((void *)0);
}

variable_types:
barrier
void *

variable_types: r int

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


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
pthread_t *v4; // rbp
unsigned int v5; // eax
pthread_barrier_t v7; // [rsp+0h] [rbp-98h] BYREF
pthread_t newthread; // [rsp+20h] [rbp-78h] BYREF
char s[88]; // [rsp+40h] [rbp-58h] BYREF

v3 = 0;
v4 = &newthread;
pthread_barrier_init(&v7, 0LL, 5u);
do
{
sprintf(s, "thread nr %d creation failed", v3);
if ( pthread_create(v4, 0LL, routine, &v7) )
perror(s);
++v3;
++v4;
}
while ( v3 != 4 );
v5 = getpid();
sprintf(s, "ps -T -%d", v5);
system(s);
pthread_barrier_wait(&v7);
return 0;
}

original_code:
int main(void)
{
  char str[64];
  pthread_barrier_t barrier;
  pthread_barrier_init(&barrier, ((void *)0), 4 +1);
  pthread_t threads[4];
  for (int i = 0; i < 4; i++) {
    sprintf(str, "thread nr %d creation failed", i);
    { if(pthread_create(&threads[i],((void *)0),&routine, (void*) &barrier) != 0) { perror(str); } };
  }
  sprintf(str, "ps -T -%d", getpid());
  system(str);
  pthread_barrier_wait(&barrier);
  return 0;
}

canonical_original_code:
int main()
{
  char str[64];
  union pthread_barrier_t barrier;
  pthread_barrier_init(&barrier, ((void *)0), 4 +1);
  unsigned long threads[4];
  for (int i = 0; i < 4; i++) {
    sprintf(str, "thread nr %d creation failed", i);
    { if(pthread_create(&threads[i],((void *)0),&routine, (void *) &barrier) != 0) { perror(str); } };
  }
  sprintf(str, "ps -T -%d", getpid());
  system(str);
  pthread_barrier_wait(&barrier);
  return 0;
}

variable_types:
str
char [64]

variable_types: union pthread_barrier_t { char __size[32]; long __align; }

variable_types:
threads
unsigned long [4]

variable_types: i int

return_type: int


decompiled_code:
int atexit_function()
{
return printf("pid %d: atexit function called.\n", (unsigned int)pid);
}

canonical_decompiled_code:
int func8()
{
return printf("pid %d: atexit function called.\n", (unsigned int)pid);
}

original_code:
void atexit_function()
{
  printf("pid %d: atexit function called.\n", pid);
}

return_type: void


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
bool v5; // cf
bool v6; // zf
const char *v7; // rsi
const char *v8; // rdi
__int64 v9; // rcx
__pid_t v10; // eax
int v11; // ebp
const char *v12; // rbp
int v13; // eax
int v14; // eax

pid = getpid();
v5 = argc == 0;
v6 = argc == 1;
if ( argc > 1 )
{
v7 = argv[1];
v8 = "help";
v9 = 5LL;
do
{
if ( !v9 )
break;
v5 = *v7 < (unsigned int)*v8;
v6 = *v7++ == *v8++;
--v9;
}
while ( v6 );
if ( (!v5 && !v6) == v5 )
{
desc(v8, v7);
return 0;
}
}
if ( (unsigned int)atexit(atexit_function) )
perror("atexit failed");
v10 = fork();
v11 = v10;
if ( v10 == -1 )
{
perror("fork failed");
}
else if ( v10 > 0 )
{
printf("ppid: %d, child id:%d\n", (unsigned int)pid, (unsigned int)v10);
pid = v11;
}
if ( argc <= 1 )
return 0;
v12 = argv[1];
if ( !strcmp(v12, "abort") )
main_cold();
v13 = strcmp(v12, "exit");
if ( !v13 )
{
if ( argc != 2 )
v13 = atoi(argv[2]);
exit(v13);
}
v14 = strcmp(v12, "_exit");
if ( !v14 )
{
if ( argc != 2 )
v14 = atoi(argv[2]);
_exit(v14);
}
if ( strcmp(v12, "signal") )
return atoi(v12);
pause();
return atoi(argv[1]);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
bool v5; // cf
bool v6; // zf
const char *v7; // rsi
const char *v8; // rdi
__int64 v9; // rcx
__pid_t v10; // eax
int v11; // ebp
const char *v12; // rbp
int v13; // eax
int v14; // eax

pid = getpid();
v5 = argc == 0;
v6 = argc == 1;
if ( argc > 1 )
{
v7 = argv[1];
v8 = "help";
v9 = 5LL;
do
{
if ( !v9 )
break;
v5 = *v7 < (unsigned int)*v8;
v6 = *v7++ == *v8++;
--v9;
}
while ( v6 );
if ( (!v5 && !v6) == v5 )
{
func9(v8, v7);
return 0;
}
}
if ( (unsigned int)func12(atexit_function) )
perror("atexit failed");
v10 = fork();
v11 = v10;
if ( v10 == -1 )
{
perror("fork failed");
}
else if ( v10 > 0 )
{
printf("ppid: %d, child id:%d\n", (unsigned int)pid, (unsigned int)v10);
pid = v11;
}
if ( argc <= 1 )
return 0;
v12 = argv[1];
if ( !strcmp(v12, "abort") )
func1();
v13 = strcmp(v12, "exit");
if ( !v13 )
{
if ( argc != 2 )
v13 = atoi(argv[2]);
exit(v13);
}
v14 = strcmp(v12, "_exit");
if ( !v14 )
{
if ( argc != 2 )
v14 = atoi(argv[2]);
_exit(v14);
}
if ( strcmp(v12, "signal") )
return atoi(v12);
pause();
return atoi(argv[1]);
}

original_code:
int main(int argc, const char *argv[])
{
  pid = getpid();
  if(argc > 1) { if(strcmp(argv[1],"help")==0) {desc(); return 0;}; }
  { if(atexit(&atexit_function) != 0) { perror("atexit failed"); } };
  pid_t p;
  { { if((p=fork()) == -1) { perror("fork failed"); } } };
  if(p > 0) {
    printf("ppid: %d, child id:%d\n", pid, p);
    pid = p;
  }
  if(argc>1) {
    if(strcmp(argv[1],"abort")==0) {abort();};
    if(strcmp(argv[1],"exit")==0) {int ret = 0; if (argc > 2) { ret = atoi(argv[2]); } exit(ret);};
    if(strcmp(argv[1],"_exit")==0) {int ret = 0; if (argc > 2) { ret = atoi(argv[2]); } _exit(ret);};
    if(strcmp(argv[1],"signal")==0) {pause();};
  }
  int ret = 0;
  if(argc > 1) {
    ret = atoi(argv[1]);
  }
  return ret;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  pid = getpid();
  if(argc > 1) { if(strcmp(argv[1],"help")==0) {desc(); return 0;}; }
  { if(atexit(&atexit_function) != 0) { perror("atexit failed"); } };
  int p;
  { { if((p=fork()) == -1) { perror("fork failed"); } } };
  if(p > 0) {
    printf("ppid: %d, child id:%d\n", pid, p);
    pid = p;
  }
  if(argc>1) {
    if(strcmp(argv[1],"abort")==0) {abort();};
    if(strcmp(argv[1],"exit")==0) {int ret = 0; if (argc > 2) { ret = atoi(argv[2]); } exit(ret);};
    if(strcmp(argv[1],"_exit")==0) {int ret = 0; if (argc > 2) { ret = atoi(argv[2]); } _exit(ret);};
    if(strcmp(argv[1],"signal")==0) {pause();};
  }
  int ret = 0;
  if(argc > 1) {
    ret = atoi(argv[1]);
  }
  return ret;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: p int

variable_types: ret int


desc

decompiled_code:
__int64 desc()
{
puts(
"./5 { help | signal | exit {VAL{ | _exit {VAL} | pause | VAL }\n"
" VAL specifies value returned by program with exit/_exit/return");
return 1LL;
}

canonical_decompiled_code:
__int64 func9()
{
puts(
"./5 { help | signal | exit {VAL{ | _exit {VAL} | pause | VAL }\n"
" VAL specifies value returned by program with exit/_exit/return");
return 1LL;
}

original_code:
int desc()
{
  printf("./5 { help | signal | exit {VAL{ | _exit {VAL} | pause | VAL }\n VAL specifies value returned by program with exit/_exit/return\n");
  return 1;
}


decompiled_code:
int printEd_Wd()
{
char *v0; // rsi
char buf[1032]; // [rsp+10h] [rbp-408h] BYREF

v0 = getenv("EDITOR");
if ( !v0 )
{
perror("getenv failed");
v0 = 0LL;
}
printf(" EDITOR=%s\n", v0);
if ( !getcwd(buf, 0x400uLL) )
perror("getcwd failed");
return printf(" cwd=%s\n", buf);
}

canonical_decompiled_code:
int func7()
{
char *v0; // rsi
char buf[1032]; // [rsp+10h] [rbp-408h] BYREF

v0 = getenv("EDITOR");
if ( !v0 )
{
perror("getenv failed");
v0 = 0LL;
}
printf(" EDITOR=%s\n", v0);
if ( !getcwd(buf, 0x400uLL) )
perror("getcwd failed");
return printf(" cwd=%s\n", buf);
}

original_code:
void printEd_Wd()
{
  char* bufE = getenv("EDITOR");
  { if(bufE==((void *)0)) { perror("getenv failed"); } };
  printf(" EDITOR=%s\n", bufE);
  char bufCWD[1024];
  { if(getcwd(bufCWD, 1024)==((void *)0)) { perror("getcwd failed"); } };
  printf(" cwd=%s\n", bufCWD);
}

canonical_original_code:
void printEd_Wd()
{
  char *bufE = getenv("EDITOR");
  { if(bufE==((void *)0)) { perror("getenv failed"); } };
  printf(" EDITOR=%s\n", bufE);
  char bufCWD[1024];
  { if(getcwd(bufCWD, 1024)==((void *)0)) { perror("getcwd failed"); } };
  printf(" cwd=%s\n", bufCWD);
}

variable_types:
bufE
char *

variable_types:
bufCWD
char [1024]


funPEW

decompiled_code:
int __fastcall funPEW(int a1)
{
int result; // eax

if ( a1 == 1 )
result = printEd_Wd();
else
result = puts("Error");
return result;
}

canonical_decompiled_code:
int __fastcall func8(int a1)
{
int result; // eax

if ( a1 == 1 )
result = func7();
else
result = puts("Error");
return result;
}

original_code:
void funPEW(int sig)
{
  if(sig==1)
    printEd_Wd();
  else
    printf("Error\n");
}

variable_types: sig int


decompiled_code:
int __fastcall print_env(int a1, const char **a2, const char **a3)
{
const char **v4; // rbx
__int64 v5; // r12
const char *v6; // rsi
const char *v7; // rsi
const char **v8; // rbp

printf("%s args and environment:\n", *a2);
if ( a1 > 1 )
{
v4 = a2 + 1;
v5 = (__int64)&a2[(unsigned int)(a1 - 2) + 2];
do
{
v6 = *v4++;
printf(" %s\n", v6);
}
while ( v4 != (const char **)v5 );
}
v7 = *a3;
if ( *a3 )
{
v8 = a3 + 1;
do
{
++v8;
printf(" %s \n", v7);
v7 = *(v8 - 1);
}
while ( v7 );
}
return printEd_Wd();
}

canonical_decompiled_code:
int __fastcall func9(int a1, const char **a2, const char **a3)
{
const char **v4; // rbx
__int64 v5; // r12
const char *v6; // rsi
const char *v7; // rsi
const char **v8; // rbp

printf("%s args and environment:\n", *a2);
if ( a1 > 1 )
{
v4 = a2 + 1;
v5 = (__int64)&a2[(unsigned int)(a1 - 2) + 2];
do
{
v6 = *v4++;
printf(" %s\n", v6);
}
while ( v4 != (const char **)v5 );
}
v7 = *a3;
if ( *a3 )
{
v8 = a3 + 1;
do
{
++v8;
printf(" %s \n", v7);
v7 = *(v8 - 1);
}
while ( v7 );
}
return func7();
}

original_code:
void print_env(int argc, char* argv[], char* envp[])
{
  printf("%s args and environment:\n", argv[0]);
  for(int i=1; i< argc; i++) {
    printf(" %s\n", argv[i]);
  }
  for(int i=0; envp[i] != ((void *)0); i++) {
    printf(" %s \n", envp[i]);
  }
  printEd_Wd();
}

canonical_original_code:
void print_env(int argc, char *argv[], char *envp[])
{
  printf("%s args and environment:\n", argv[0]);
  for(int i = 1; i< argc; i++) {
    printf(" %s\n", argv[i]);
  }
  for(int i = 0; envp[i] != ((void *)0); i++) {
    printf(" %s \n", envp[i]);
  }
  printEd_Wd();
}

variable_types:
envp
char *[]


decompiled_code:
void __fastcall setEd_Wd(char *value, char *path)
{
if ( setenv("EDITOR", value, 1) != -1 )
{
if ( chdir(path) != -1 )
return;
LABEL_5:
perror("chdir failed");
return;
}
perror("setenv failed");
if ( chdir(path) == -1 )
goto LABEL_5;
}

canonical_decompiled_code:
void __fastcall func10(char *value, char *path)
{
if ( setenv("EDITOR", value, 1) != -1 )
{
if ( chdir(path) != -1 )
return;
LABEL_5:
perror("chdir failed");
return;
}
perror("setenv failed");
if ( chdir(path) == -1 )
goto LABEL_5;
}

original_code:
void setEd_Wd(const char* Ed, const char* Wd)
{
  { { if((setenv("EDITOR",Ed,1)) == -1) { perror("setenv failed"); } } };
  { { if((chdir(Wd)) == -1) { perror("chdir failed"); } } };
}

canonical_original_code:
void setEd_Wd(char *Ed, char *Wd)
{
  { { if((setenv("EDITOR",Ed,1)) == -1) { perror("setenv failed"); } } };
  { { if((chdir(Wd)) == -1) { perror("chdir failed"); } } };
}

variable_types:
Ed
char *

variable_types:
Wd
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdi
__pid_t v4; // eax
__pid_t v5; // ebp
struct sigaction v7; // [rsp+0h] [rbp-A8h] BYREF

v7.sa_handler = (__sighandler_t)printEd_Wd;
memset(&v7.sa_mask, 0, 0x90uLL);
v3 = 1LL;
if ( sigaction(1, &v7, 0LL) == -1 )
{
v3 = (__int64)"signal set failed";
perror("signal set failed");
}
printEd_Wd(v3);
setEd_Wd("vim", "/home");
v4 = fork();
v5 = v4;
if ( v4 == -1 )
{
perror("fork failed");
}
else if ( v4 )
{
if ( v4 > 0 )
{
system("sleep 1");
setEd_Wd("nano", "/");
printEd_Wd("nano");
kill(v5, 1);
}
}
else
{
pause();
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdi
__pid_t v4; // eax
__pid_t v5; // ebp
struct sigaction v7; // [rsp+0h] [rbp-A8h] BYREF

v7.sa_handler = (__sighandler_t)printEd_Wd;
memset(&v7.sa_mask, 0, 0x90uLL);
v3 = 1LL;
if ( sigaction(1, &v7, 0LL) == -1 )
{
v3 = (__int64)"signal set failed";
perror("signal set failed");
}
func7(v3);
func10("vim", "/home");
v4 = fork();
v5 = v4;
if ( v4 == -1 )
{
perror("fork failed");
}
else if ( v4 )
{
if ( v4 > 0 )
{
system("sleep 1");
func10("nano", "/");
func7("nano");
kill(v5, 1);
}
}
else
{
pause();
}
return 0;
}

original_code:
int main(void)
{
  struct sigaction act;
  memset(&act, 0, sizeof(act));
  act.__sigaction_handler.sa_handler=&printEd_Wd;
  { { if((sigaction(1,&act,((void *)0))) == -1) { perror("signal set failed"); } } };;
  printEd_Wd();
  setEd_Wd("vim","/home");
  pid_t p;
  { { if((p=fork()) == -1) { perror("fork failed"); } } };
  if(p==0){
    pause();
  } else if(p>0){
    system("sleep 1");
    setEd_Wd("nano","/");
    printEd_Wd();
    kill(p,1);
  }
  return 0;
}

canonical_original_code:
int main()
{
  struct sigaction act;
  memset(&act, 0, sizeof(act));
  act.__sigaction_handler.sa_handler=&printEd_Wd;
  { { if((sigaction(1,&act,((void *)0))) == -1) { perror("signal set failed"); } } };;
  printEd_Wd();
  setEd_Wd("vim","/home");
  int p;
  { { if((p=fork()) == -1) { perror("fork failed"); } } };
  if(p==0){
    pause();
  } else if(p>0){
    system("sleep 1");
    setEd_Wd("nano","/");
    printEd_Wd();
    kill(p,1);
  }
  return 0;
}

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

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


badArgs

decompiled_code:
__int64 badArgs()
{
puts("Usage: <command> arg where arg is either no-limit or limited");
return 1LL;
}

canonical_decompiled_code:
__int64 func7()
{
puts("Usage: <command> arg where arg is either no-limit or limited");
return 1LL;
}

original_code:
int badArgs()
{
  printf("Usage: <command> arg where arg is either no-limit or limited\n");
  return 1;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r8
const char *v4; // rdi
__int64 v5; // rdx
int v6; // er12
__pid_t v7; // ebp
__int64 v8; // r13
__pid_t v9; // eax
__pid_t v10; // ebx
char v12[64]; // [rsp-40h] [rbp-A8h] BYREF
struct rlimit rlimits; // [rsp+0h] [rbp-68h] BYREF

if ( argc == 1 )
return badArgs(1, argv, envp);
v3 = argv[1];
if ( !strcmp(v3, "limited") )
{
rlimits.rlim_cur = 50LL;
rlimits.rlim_max = 50LL;
if ( setrlimit(__RLIMIT_NPROC, &rlimits) == -1 )
perror("setrlimit failed");
}
else
{
v4 = v3;
if ( strcmp(v3, "no-limit") )
return badArgs(v4, "no-limit", v5);
}
if ( setpgid(0, 0) == -1 )
perror("setpgid failed ");
v6 = 0;
v7 = getpid();
v8 = (unsigned int)getpgid(0);
printf("PGID=%d\n", v8);
puts("forking..");
do
{
++v6;
putchar(61);
fflush(_bss_start);
v9 = fork();
v10 = v9;
}
while ( v6 <= 99 && v9 > 0 );
if ( v9 )
{
puts(" done.");
sprintf(v12, "ps f -o pgrp,pid,command --ppid %d", (unsigned int)v8);
if ( system(v12) == -1 )
perror("'system' call failed ");
if ( v10 == -1 )
{
sprintf((char *)&rlimits, "Fork failed (created %d processes) ", (unsigned int)v6);
perror((const char *)&rlimits);
}
else if ( system("sleep 5") == -1 )
{
perror("'system' call failed ");
}
killpg(v7, 2);
}
else
{
pause();
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r8
const char *v4; // rdi
__int64 v5; // rdx
int v6; // er12
__pid_t v7; // ebp
__int64 v8; // r13
__pid_t v9; // eax
__pid_t v10; // ebx
char v12[64]; // [rsp-40h] [rbp-A8h] BYREF
struct rlimit rlimits; // [rsp+0h] [rbp-68h] BYREF

if ( argc == 1 )
return func7(1, argv, envp);
v3 = argv[1];
if ( !strcmp(v3, "limited") )
{
rlimits.rlim_cur = 50LL;
rlimits.rlim_max = 50LL;
if ( setrlimit(__RLIMIT_NPROC, &rlimits) == -1 )
perror("setrlimit failed");
}
else
{
v4 = v3;
if ( strcmp(v3, "no-limit") )
return func7(v4, "no-limit", v5);
}
if ( setpgid(0, 0) == -1 )
perror("setpgid failed ");
v6 = 0;
v7 = getpid();
v8 = (unsigned int)getpgid(0);
printf("PGID=%d\n", v8);
puts("forking..");
do
{
++v6;
putchar(61);
fflush(_bss_start);
v9 = fork();
v10 = v9;
}
while ( v6 <= 99 && v9 > 0 );
if ( v9 )
{
puts(" done.");
sprintf(v12, "ps f -o pgrp,pid,command --ppid %d", (unsigned int)v8);
if ( system(v12) == -1 )
perror("'system' call failed ");
if ( v10 == -1 )
{
sprintf((char *)&rlimits, "Fork failed (created %d processes) ", (unsigned int)v6);
perror((const char *)&rlimits);
}
else if ( system("sleep 5") == -1 )
{
perror("'system' call failed ");
}
killpg(v7, 2);
}
else
{
pause();
}
return 0;
}

original_code:
int main(int argc, const char *argv[])
{
  if(argc == 1) {
    return badArgs();
  }
  int gdarg=0;
  if(strcmp(argv[1],"limited")==0)
  {
    gdarg++;
    struct rlimit limit;
    memset(&limit, 0, sizeof(limit));
    limit.rlim_cur=50;
    limit.rlim_max=50;
    { { if((setrlimit(__RLIMIT_NPROC, &limit)) == -1) { perror("setrlimit failed"); } } };
  }
  if(strcmp(argv[1],"no-limit")==0)
  {
    gdarg++;
  }
  if(gdarg==0)
  {
    return badArgs();
  }
  if( setpgid(0, 0) == -1)
    perror("setpgid failed ");
  pid_t pid = getpid();
  pid_t pgid = getpgid(0);
  printf("PGID=%d\n", pgid);
  int parent = 1;
  printf("forking..\n");
  int i;
  for(i = 0; (i<100) && (parent > 0); i++) {
    putchar('=');
    fflush(stdout);
    parent = fork();
  }
  if(parent == 0) {
    pause();
    return 0;
  }
  printf(" done.\n");
  char cmd[64];
  sprintf(cmd,"ps f -o pgrp,pid,command --ppid %d", pgid);
  { { if((system(cmd)) == -1) { perror("'system' call failed "); } } };;
  if(parent == -1) {
    char desc[64];
    sprintf(desc, "Fork failed (created %d processes) ", i);
    perror(desc);
  } else {
    { { if((system("sleep 5")) == -1) { perror("'system' call failed "); } } };;
  }
  killpg(pid,2);
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  if(argc == 1) {
    return badArgs();
  }
  int gdarg = 0;
  if(strcmp(argv[1],"limited")==0)
  {
    gdarg++;
    struct rlimit limit;
    memset(&limit, 0, sizeof(limit));
    limit.rlim_cur=50;
    limit.rlim_max=50;
    { { if((setrlimit(__RLIMIT_NPROC, &limit)) == -1) { perror("setrlimit failed"); } } };
  }
  if(strcmp(argv[1],"no-limit")==0)
  {
    gdarg++;
  }
  if(gdarg==0)
  {
    return badArgs();
  }
  if( setpgid(0, 0) == -1)
    perror("setpgid failed ");
  int pid = getpid();
  int pgid = getpgid(0);
  printf("PGID=%d\n", pgid);
  int parent = 1;
  printf("forking..\n");
  int i;
  for(i = 0; (i<100) && (parent > 0); i++) {
    putchar('=');
    fflush(stdout);
    parent = fork();
  }
  if(parent == 0) {
    pause();
    return 0;
  }
  printf(" done.\n");
  char cmd[64];
  sprintf(cmd,"ps f -o pgrp,pid,command --ppid %d", pgid);
  { { if((system(cmd)) == -1) { perror("'system' call failed "); } } };;
  if(parent == -1) {
    char desc[64];
    sprintf(desc, "Fork failed (created %d processes) ", i);
    perror(desc);
  } else {
    { { if((system("sleep 5")) == -1) { perror("'system' call failed "); } } };;
  }
  killpg(pid,2);
  return 0;
}

variable_types: gdarg int

variable_types: struct rlimit { unsigned long rlim_cur; unsigned long rlim_max; }

variable_types: pid int

variable_types: pgid int

variable_types: parent int

variable_types:
cmd
char [64]

variable_types:
desc
char [64]


id

decompiled_code:
__int64 id()
{
__uid_t v0; // er12
struct passwd *v1; // rbx
__gid_t v2; // er13
void *v3; // rbp
struct group *v4; // rax
__int64 v5; // rbx
__gid_t v6; // edi
struct group *v7; // rax
int ngroups[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v0 = getuid();
v1 = getpwuid(v0);
ngroups[0] = 0;
v2 = getgid();
v3 = malloc(0x80uLL);
if ( getgrouplist(v1->pw_name, v1->pw_gid, (__gid_t *)v3, ngroups) == -1 )
{
free(v3);
v3 = malloc(4LL * (ngroups[0] + 1));
getgrouplist(v1->pw_name, v1->pw_gid, (__gid_t *)v3, ngroups);
}
v4 = getgrgid(v2);
printf("user=%s(%d) grp=%s(%d)\ngroups= ", v1->pw_name, v0, v4->gr_name, v2);
if ( ngroups[0] > 0 )
{
v5 = 0LL;
do
{
v6 = *((_DWORD *)v3 + v5++);
v7 = getgrgid(v6);
printf("%s(%d) ", v7->gr_name, v7->gr_gid);
}
while ( ngroups[0] > (int)v5 );
}
putchar(10);
free(v3);
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
__uid_t v0; // er12
struct passwd *v1; // rbx
__gid_t v2; // er13
void *v3; // rbp
struct group *v4; // rax
__int64 v5; // rbx
__gid_t v6; // edi
struct group *v7; // rax
int ngroups[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v0 = getuid();
v1 = getpwuid(v0);
ngroups[0] = 0;
v2 = getgid();
v3 = malloc(0x80uLL);
if ( getgrouplist(v1->pw_name, v1->pw_gid, (__gid_t *)v3, ngroups) == -1 )
{
free(v3);
v3 = malloc(4LL * (ngroups[0] + 1));
getgrouplist(v1->pw_name, v1->pw_gid, (__gid_t *)v3, ngroups);
}
v4 = getgrgid(v2);
printf("user=%s(%d) grp=%s(%d)\ngroups= ", v1->pw_name, v0, v4->gr_name, v2);
if ( ngroups[0] > 0 )
{
v5 = 0LL;
do
{
v6 = *((_DWORD *)v3 + v5++);
v7 = getgrgid(v6);
printf("%s(%d) ", v7->gr_name, v7->gr_gid);
}
while ( ngroups[0] > (int)v5 );
}
putchar(10);
free(v3);
return 0LL;
}

original_code:
int id()
{
  uid_t uid = getuid();
  struct passwd* pwuid = getpwuid(uid);
  gid_t gid = getgid();
  int grpNr=0;
  gid_t* groups = malloc(32*sizeof(gid));;
  int r = getgrouplist(pwuid->pw_name,pwuid->pw_gid, groups, &grpNr);
  if(r==-1) {
    free(groups);
    groups = malloc((grpNr+1) * sizeof(gid_t));
    r = getgrouplist(pwuid->pw_name,pwuid->pw_gid, groups, &grpNr);
  }
  struct group* grp = getgrgid(gid);
  printf("user=%s(%d) grp=%s(%d)\ngroups= ", pwuid->pw_name, uid, grp->gr_name, gid);
  for(int i=0; i< grpNr;i++) {
    grp = getgrgid(groups[i]);
    printf("%s(%d) ", grp->gr_name, grp->gr_gid);
  }
  putchar('\n');
  free(groups);
  return 0;
}

canonical_original_code:
int id()
{
  unsigned int uid = getuid();
  struct passwd *pwuid = getpwuid(uid);
  unsigned int gid = getgid();
  int grpNr = 0;
  unsigned int *groups = malloc(32*sizeof(gid));;
  int r = getgrouplist(pwuid->pw_name,pwuid->pw_gid, groups, &grpNr);
  if(r==-1) {
    free(groups);
    groups = malloc((grpNr+1) * sizeof(gid_t));
    r = getgrouplist(pwuid->pw_name,pwuid->pw_gid, groups, &grpNr);
  }
  struct group *grp = getgrgid(gid);
  printf("user=%s(%d) grp=%s(%d)\ngroups= ", pwuid->pw_name, uid, grp->gr_name, gid);
  for(int i = 0; i< grpNr;i++) {
    grp = getgrgid(groups[i]);
    printf("%s(%d) ", grp->gr_name, grp->gr_gid);
  }
  putchar('\n');
  free(groups);
  return 0;
}

variable_types:
uid
unsigned int

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

variable_types:
gid
unsigned int

variable_types: grpNr int

variable_types:
groups
unsigned int *

variable_types: r int

variable_types: struct group { char *gr_name; char *gr_passwd; unsigned int gr_gid; char **gr_mem; } *

variable_types: i int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
return id(argc, argv, envp);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
return func7(argc, argv, envp);
}

original_code:
int main()
{
  return id();
}

canonical_original_code:
int main()
{
  return id();
}


decompiled_code:
__int64 __fastcall get1B(char *a1)
{
return (unsigned int)*a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1)
{
return (unsigned int)*a1;
}

original_code:
int get1B(char* mem)
{
  return (int) * mem;
}

canonical_original_code:
int get1B(char *mem)
{
  return (int) * mem;
}

variable_types:
mem
char *


decompiled_code:
__int64 __fastcall set1BTrue(_BYTE *a1)
{
*a1 = 1;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1)
{
*a1 = 1;
return 1LL;
}

original_code:
int set1BTrue(char* mem)
{
  return (*mem = (1>0));
}

canonical_original_code:
int set1BTrue(char *mem)
{
  return (*mem = (1>0));
}


decompiled_code:
__int64 __fastcall set1BFalse(_BYTE *a1)
{
*a1 = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(_BYTE *a1)
{
*a1 = 0;
return 0LL;
}

original_code:
int set1BFalse(char* mem)
{
  return (*mem = (1<0));
}

canonical_original_code:
int set1BFalse(char *mem)
{
  return (*mem = (1<0));
}


printPid

decompiled_code:
void __noreturn printPid()
{
fprintf(stderr, "-->pid %d closing\n", (unsigned int)pid);
exit(1);
}

canonical_decompiled_code:
void __noreturn func3()
{
fprintf(stderr, "-->pid %d closing\n", (unsigned int)pid);
exit(1);
}

original_code:
void printPid(int sig __attribute__((unused)))
{
  fprintf(stderr, "-->pid %d closing\n", pid);
  _exit(1);
}

canonical_original_code:
void printPid(int sig)
{
  fprintf(stderr, "-->pid %d closing\n", pid);
  _exit(1);
}

variable_types: sig int


delay

decompiled_code:
void __fastcall delay(int a1, int a2)
{
int v2; // edx
struct timespec v3; // [rsp+0h] [rbp-28h] BYREF

v2 = a2 + rand() % (a1 - a2);
v3.tv_sec = v2 / 1000000000;
v3.tv_nsec = v2 % 1000000000;
if ( nanosleep(&v3, &v3) == -1 )
perror("nanosleep");
}

canonical_decompiled_code:
void __fastcall func4(int a1, int a2)
{
int v2; // edx
struct timespec v3; // [rsp+0h] [rbp-28h] BYREF

v2 = a2 + rand() % (a1 - a2);
v3.tv_sec = v2 / 1000000000;
v3.tv_nsec = v2 % 1000000000;
if ( nanosleep(&v3, &v3) == -1 )
perror("nanosleep");
}

original_code:
void delay(int r, int m)
{
  struct timespec nSleepTime;
  memset(&nSleepTime, 0, sizeof(struct timespec));
  int t = rand() % (r-m) + m;
  nSleepTime.tv_nsec = t % (1000000000);
  nSleepTime.tv_sec = t / (1000000000);
  { { if((nanosleep(&nSleepTime, &nSleepTime)) == -1) { perror("nanosleep"); } } };
}

variable_types: m int

variable_types: struct timespec { long tv_sec; long tv_nsec; }

variable_types: t int


qinit

decompiled_code:
__int64 __fastcall qinit(pthread_mutex_t *mutex)
{
int v1; // ebx
int v2; // er14
int v3; // er13
int v4; // er12
pthread_mutexattr_t attr; // [rsp+Ch] [rbp-2Ch] BYREF

v1 = pthread_mutexattr_init(&attr);
if ( v1 == -1 )
perror("attr init");
v2 = pthread_mutexattr_setpshared(&attr, 1);
if ( v2 == -1 )
perror("attr set");
v3 = pthread_mutex_init(mutex, &attr);
if ( v3 == -1 )
perror("mutex init failed");
v4 = sem_init((sem_t *)(&mutex[1].__align + 1), 1, 0);
if ( v4 == -1 )
perror("sem init failed");
mutex[1].__lock = 0;
return v4 | v3 | v2 | (unsigned int)v1;
}

canonical_decompiled_code:
__int64 __fastcall func5(pthread_mutex_t *mutex)
{
int v1; // ebx
int v2; // er14
int v3; // er13
int v4; // er12
pthread_mutexattr_t attr; // [rsp+Ch] [rbp-2Ch] BYREF

v1 = pthread_mutexattr_init(&attr);
if ( v1 == -1 )
perror("attr init");
v2 = pthread_mutexattr_setpshared(&attr, 1);
if ( v2 == -1 )
perror("attr set");
v3 = pthread_mutex_init(mutex, &attr);
if ( v3 == -1 )
perror("mutex init failed");
v4 = sem_init((sem_t *)(&mutex[1].__align + 1), 1, 0);
if ( v4 == -1 )
perror("sem init failed");
mutex[1].__lock = 0;
return v4 | v3 | v2 | (unsigned int)v1;
}

original_code:
int qinit(queue_t* q)
{
  int r1, r2, r3, r4;
  pthread_mutexattr_t p;
  { { if((r1 = pthread_mutexattr_init(&p)) == -1) { perror("attr init"); } } };
  { { if((r2 = pthread_mutexattr_setpshared(&p, PTHREAD_PROCESS_SHARED)) == -1) { perror("attr set"); } } };
  { { if((r3 = pthread_mutex_init(&q->prot, &p)) == -1) { perror("mutex init failed"); } } };
  { { if((r4 = sem_init(&q->sem, 1, 0)) == -1) { perror("sem init failed"); } } };
  q->count = 0;
  return (r1 | r2 | r3 | r4);
}

canonical_original_code:
int qinit(struct queue *q)
{
  int r1; int r2; int r3; int r4;
  union pthread_mutexattr_t p;
  { { if((r1 = pthread_mutexattr_init(&p)) == -1) { perror("attr init"); } } };
  { { if((r2 = pthread_mutexattr_setpshared(&p, PTHREAD_PROCESS_SHARED)) == -1) { perror("attr set"); } } };
  { { if((r3 = pthread_mutex_init(&q->prot, &p)) == -1) { perror("mutex init failed"); } } };
  { { if((r4 = sem_init(&q->sem, 1, 0)) == -1) { perror("sem init failed"); } } };
  q->count = 0;
  return (r1 | r2 | r3 | r4);
}

variable_types: struct queue { 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; } prot; int count; union sem_t { char __size[32]; long __align; } sem; } *

variable_types: union pthread_mutexattr_t { char __size[4]; int __align; }

user_defined_types: struct queue { union pthread_mutex_t prot; int count; union sem_t sem; }

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

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


qrelease

decompiled_code:
__int64 __fastcall qrelease(pthread_mutex_t *mutex, char a2)
{
int v2; // er13
int v3; // er14
int v4; // er15
int v5; // eax

if ( a2 )
{
v4 = mutex[1].__lock;
if ( v4 > 0 )
goto LABEL_6;
return v3 | (unsigned int)v2;
}
v3 = pthread_mutex_lock(mutex);
if ( v3 == -1 )
perror("qmutex lck");
v4 = mutex[1].__lock;
if ( v4 <= 0 )
{
LABEL_13:
v2 = pthread_mutex_unlock(mutex);
if ( v2 == -1 )
perror(&::mutex.__size[11]);
return v3 | (unsigned int)v2;
}
LABEL_6:
while ( 1 )
{
v5 = sem_post((sem_t *)(&mutex[1].__align + 1));
if ( v5 == -1 )
break;
if ( --v4 <= 0 || v5 )
goto LABEL_8;
}
perror((const char *)&::mutex);
LABEL_8:
if ( !a2 )
goto LABEL_13;
return v3 | (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(pthread_mutex_t *mutex, char a2)
{
int v2; // er13
int v3; // er14
int v4; // er15
int v5; // eax

if ( a2 )
{
v4 = mutex[1].__lock;
if ( v4 > 0 )
goto LABEL_6;
return v3 | (unsigned int)v2;
}
v3 = pthread_mutex_lock(mutex);
if ( v3 == -1 )
perror("qmutex lck");
v4 = mutex[1].__lock;
if ( v4 <= 0 )
{
LABEL_13:
v2 = pthread_mutex_unlock(mutex);
if ( v2 == -1 )
perror(&::mutex.__size[11]);
return v3 | (unsigned int)v2;
}
LABEL_6:
while ( 1 )
{
v5 = sem_post((sem_t *)(&mutex[1].__align + 1));
if ( v5 == -1 )
break;
if ( --v4 <= 0 || v5 )
goto LABEL_8;
}
perror((const char *)&::mutex);
LABEL_8:
if ( !a2 )
goto LABEL_13;
return v3 | (unsigned int)v2;
}

original_code:
int qrelease(queue_t* q, char has_lock)
{
  int r1, r2, r3 = 0;
  if(!has_lock) {
    { { if((r1 = pthread_mutex_lock(&q->prot)) == -1) { perror("qmutex lck"); } } };
  }
  for(int i = q->count ; i > 0 && r3 == 0; i = i - 1) {
    { { if((r3 = sem_post(&q->sem)) == -1) { perror("qmutex pst"); } } };
  }
  if(!has_lock) {
    { { if((r2 = pthread_mutex_unlock(&q->prot)) == -1) { perror("qmutex ulck"); } } };
  }
  return (r1 | r2);
}

canonical_original_code:
int qrelease(struct queue *q, char has_lock)
{
  int r1; int r2; int r3 = 0;
  if(!has_lock) {
    { { if((r1 = pthread_mutex_lock(&q->prot)) == -1) { perror("qmutex lck"); } } };
  }
  for(int i = q->count; i > 0 && r3 == 0; i = i - 1) {
    { { if((r3 = sem_post(&q->sem)) == -1) { perror("qmutex pst"); } } };
  }
  if(!has_lock) {
    { { if((r2 = pthread_mutex_unlock(&q->prot)) == -1) { perror("qmutex ulck"); } } };
  }
  return (r1 | r2);
}

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

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


qdestroy

decompiled_code:
__int64 __fastcall qdestroy(pthread_mutex_t *mutex)
{
unsigned int v1; // ebx
int v2; // er12
int v3; // ebp

v1 = qrelease(mutex, 0);
v2 = pthread_mutex_destroy(mutex);
if ( v2 == -1 )
{
perror(&::mutex.__size[23]);
v3 = sem_destroy((sem_t *)(&mutex[1].__align + 1));
if ( v3 != -1 )
return v3 | v2 | v1;
}
else
{
v3 = sem_destroy((sem_t *)(&mutex[1].__align + 1));
if ( v3 != -1 )
return v3 | v2 | v1;
}
perror(&::mutex.__size[33]);
return v3 | v2 | v1;
}

canonical_decompiled_code:
__int64 __fastcall func7(pthread_mutex_t *mutex)
{
unsigned int v1; // ebx
int v2; // er12
int v3; // ebp

v1 = func6(mutex, 0);
v2 = pthread_mutex_destroy(mutex);
if ( v2 == -1 )
{
perror(&::mutex.__size[23]);
v3 = sem_destroy((sem_t *)(&mutex[1].__align + 1));
if ( v3 != -1 )
return v3 | v2 | v1;
}
else
{
v3 = sem_destroy((sem_t *)(&mutex[1].__align + 1));
if ( v3 != -1 )
return v3 | v2 | v1;
}
perror(&::mutex.__size[33]);
return v3 | v2 | v1;
}

original_code:
int qdestroy(queue_t* q)
{
  int r1, r2,r3;
  r3 = qrelease(q, (1<0));
  { { if((r1 = pthread_mutex_destroy(&q->prot)) == -1) { perror("qmtx dstr"); } } };
  { { if((r2 = sem_destroy(&q->sem)) == -1) { perror("qsem dstr"); } } };
  return (r1 | r2 | r3);
}

canonical_original_code:
int qdestroy(struct queue *q)
{
  int r1; int r2; int r3;
  r3 = qrelease(q, (1<0));
  { { if((r1 = pthread_mutex_destroy(&q->prot)) == -1) { perror("qmtx dstr"); } } };
  { { if((r2 = sem_destroy(&q->sem)) == -1) { perror("qsem dstr"); } } };
  return (r1 | r2 | r3);
}


qwait

decompiled_code:
__int64 __fastcall qwait(pthread_mutex_t *mutex)
{
int v1; // ebx
int v2; // er14
int v3; // er13
int v4; // er12
int v5; // ebp

v1 = pthread_mutex_lock(mutex);
if ( v1 == -1 )
perror("qmutex lck");
++mutex[1].__lock;
v2 = pthread_mutex_unlock(mutex);
if ( v2 == -1 )
perror(&::mutex.__size[11]);
v3 = sem_wait((sem_t *)(&mutex[1].__align + 1));
if ( v3 == -1 )
perror("qsem wt");
v4 = pthread_mutex_lock(mutex);
if ( v4 == -1 )
perror("qmutex lck");
--mutex[1].__lock;
v5 = pthread_mutex_unlock(mutex);
if ( v5 == -1 )
perror(&::mutex.__size[11]);
return v5 | v4 | v3 | v2 | (unsigned int)v1;
}

canonical_decompiled_code:
__int64 __fastcall func8(pthread_mutex_t *mutex)
{
int v1; // ebx
int v2; // er14
int v3; // er13
int v4; // er12
int v5; // ebp

v1 = pthread_mutex_lock(mutex);
if ( v1 == -1 )
perror("qmutex lck");
++mutex[1].__lock;
v2 = pthread_mutex_unlock(mutex);
if ( v2 == -1 )
perror(&::mutex.__size[11]);
v3 = sem_wait((sem_t *)(&mutex[1].__align + 1));
if ( v3 == -1 )
perror("qsem wt");
v4 = pthread_mutex_lock(mutex);
if ( v4 == -1 )
perror("qmutex lck");
--mutex[1].__lock;
v5 = pthread_mutex_unlock(mutex);
if ( v5 == -1 )
perror(&::mutex.__size[11]);
return v5 | v4 | v3 | v2 | (unsigned int)v1;
}

original_code:
int qwait(queue_t* q)
{
  int r1, r2, r3, r4, r5;
  { { if((r1 = pthread_mutex_lock(&q->prot)) == -1) { perror("qmutex lck"); } } };
  q->count++;
  { { if((r2 = pthread_mutex_unlock(&q->prot)) == -1) { perror("qmutex ulck"); } } };
  { { if((r3 = sem_wait(&q->sem)) == -1) { perror("qsem wt"); } } };
  { { if((r4 = pthread_mutex_lock(&q->prot)) == -1) { perror("qmutex lck"); } } };
  q->count = q->count - 1;
  { { if((r5 = pthread_mutex_unlock(&q->prot)) == -1) { perror("qmutex ulck"); } } };
  return (r1 | r2 | r3 | r4 | r5);
}

canonical_original_code:
int qwait(struct queue *q)
{
  int r1; int r2; int r3; int r4; int r5;
  { { if((r1 = pthread_mutex_lock(&q->prot)) == -1) { perror("qmutex lck"); } } };
  q->count++;
  { { if((r2 = pthread_mutex_unlock(&q->prot)) == -1) { perror("qmutex ulck"); } } };
  { { if((r3 = sem_wait(&q->sem)) == -1) { perror("qsem wt"); } } };
  { { if((r4 = pthread_mutex_lock(&q->prot)) == -1) { perror("qmutex lck"); } } };
  q->count = q->count - 1;
  { { if((r5 = pthread_mutex_unlock(&q->prot)) == -1) { perror("qmutex ulck"); } } };
  return (r1 | r2 | r3 | r4 | r5);
}


qincr

decompiled_code:
__int64 __fastcall qincr(pthread_mutex_t *mutex)
{
int v1; // ebx
int v2; // eax

v1 = pthread_mutex_lock(mutex);
if ( v1 == -1 )
perror("qmutex lck");
++mutex[1].__lock;
v2 = pthread_mutex_unlock(mutex);
if ( v2 != -1 )
return v1 | (unsigned int)v2;
perror(&::mutex.__size[11]);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func9(pthread_mutex_t *mutex)
{
int v1; // ebx
int v2; // eax

v1 = pthread_mutex_lock(mutex);
if ( v1 == -1 )
perror("qmutex lck");
++mutex[1].__lock;
v2 = pthread_mutex_unlock(mutex);
if ( v2 != -1 )
return v1 | (unsigned int)v2;
perror(&::mutex.__size[11]);
return 0xFFFFFFFFLL;
}

original_code:
int qincr(queue_t* q)
{
  int r1, r2;
  { { if((r1 = pthread_mutex_lock(&q->prot)) == -1) { perror("qmutex lck"); } } };
  q->count++;
  { { if((r2 = pthread_mutex_unlock(&q->prot)) == -1) { perror("qmutex ulck"); } } };
  return (r1 | r2);
}

canonical_original_code:
int qincr(struct queue *q)
{
  int r1; int r2;
  { { if((r1 = pthread_mutex_lock(&q->prot)) == -1) { perror("qmutex lck"); } } };
  q->count++;
  { { if((r2 = pthread_mutex_unlock(&q->prot)) == -1) { perror("qmutex ulck"); } } };
  return (r1 | r2);
}


qdecr

decompiled_code:
__int64 __fastcall qdecr(pthread_mutex_t *mutex)
{
int v1; // ebx
int v2; // eax

v1 = pthread_mutex_lock(mutex);
if ( v1 == -1 )
perror("qmutex lck");
--mutex[1].__lock;
v2 = pthread_mutex_unlock(mutex);
if ( v2 != -1 )
return v1 | (unsigned int)v2;
perror(&::mutex.__size[11]);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func10(pthread_mutex_t *mutex)
{
int v1; // ebx
int v2; // eax

v1 = pthread_mutex_lock(mutex);
if ( v1 == -1 )
perror("qmutex lck");
--mutex[1].__lock;
v2 = pthread_mutex_unlock(mutex);
if ( v2 != -1 )
return v1 | (unsigned int)v2;
perror(&::mutex.__size[11]);
return 0xFFFFFFFFLL;
}

original_code:
int qdecr(queue_t* q)
{
  int r1, r2;
  { { if((r1 = pthread_mutex_lock(&q->prot)) == -1) { perror("qmutex lck"); } } };
  q->count = q->count - 1;
  { { if((r2 = pthread_mutex_unlock(&q->prot)) == -1) { perror("qmutex ulck"); } } };
  return (r1 | r2);
}

canonical_original_code:
int qdecr(struct queue *q)
{
  int r1; int r2;
  { { if((r1 = pthread_mutex_lock(&q->prot)) == -1) { perror("qmutex lck"); } } };
  q->count = q->count - 1;
  { { if((r2 = pthread_mutex_unlock(&q->prot)) == -1) { perror("qmutex ulck"); } } };
  return (r1 | r2);
}


decompiled_code:
__int64 __fastcall qget_count(pthread_mutex_t *mutex)
{
int v1; // eax
unsigned int v2; // er12
int v3; // ebx
int v4; // eax
int v5; // ebx

v1 = pthread_mutex_lock(mutex);
if ( v1 == -1 )
{
v2 = -1;
perror("qmutex lck");
if ( pthread_mutex_unlock(mutex) != -1 )
return v2;
}
else
{
v2 = mutex[1].__lock;
v3 = v1;
v4 = pthread_mutex_unlock(mutex);
if ( v4 != -1 )
{
v5 = v4 | v3;
if ( v5 )
v2 = v5;
return v2;
}
}
perror(&::mutex.__size[11]);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func11(pthread_mutex_t *mutex)
{
int v1; // eax
unsigned int v2; // er12
int v3; // ebx
int v4; // eax
int v5; // ebx

v1 = pthread_mutex_lock(mutex);
if ( v1 == -1 )
{
v2 = -1;
perror("qmutex lck");
if ( pthread_mutex_unlock(mutex) != -1 )
return v2;
}
else
{
v2 = mutex[1].__lock;
v3 = v1;
v4 = pthread_mutex_unlock(mutex);
if ( v4 != -1 )
{
v5 = v4 | v3;
if ( v5 )
v2 = v5;
return v2;
}
}
perror(&::mutex.__size[11]);
return 0xFFFFFFFFLL;
}

original_code:
int qget_count(queue_t* q)
{
  int c, r1, r2;
  { { if((r1 = pthread_mutex_lock(&q->prot)) == -1) { perror("qmutex lck"); } } };
  c = q->count;
  { { if((r2 = pthread_mutex_unlock(&q->prot)) == -1) { perror("qmutex ulck"); } } };
  r1 = r1 | r2;
  return (r1 == 0) ? c : r1;
}

canonical_original_code:
int qget_count(struct queue *q)
{
  int c; int r1; int r2;
  { { if((r1 = pthread_mutex_lock(&q->prot)) == -1) { perror("qmutex lck"); } } };
  c = q->count;
  { { if((r2 = pthread_mutex_unlock(&q->prot)) == -1) { perror("qmutex ulck"); } } };
  r1 = r1 | r2;
  return (r1 == 0) ? c : r1;
}

variable_types: c int


qreset

decompiled_code:
__int64 __fastcall qreset(pthread_mutex_t *mutex, char a2)
{
int v2; // er13
int v3; // er14

if ( !a2 )
{
v3 = pthread_mutex_lock(mutex);
if ( v3 == -1 )
perror("qmutex lck");
}
while ( sem_trywait((sem_t *)(&mutex[1].__align + 1)) != -1 )
;
if ( !a2 )
{
v2 = pthread_mutex_unlock(mutex);
if ( v2 == -1 )
perror(&::mutex.__size[11]);
}
return v3 | (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func12(pthread_mutex_t *mutex, char a2)
{
int v2; // er13
int v3; // er14

if ( !a2 )
{
v3 = pthread_mutex_lock(mutex);
if ( v3 == -1 )
perror("qmutex lck");
}
while ( sem_trywait((sem_t *)(&mutex[1].__align + 1)) != -1 )
;
if ( !a2 )
{
v2 = pthread_mutex_unlock(mutex);
if ( v2 == -1 )
perror(&::mutex.__size[11]);
}
return v3 | (unsigned int)v2;
}

original_code:
int qreset(queue_t* q, char has_lock)
{
  int r1, r2, r3 = 0;
  if(!has_lock) {
    { { if((r1 = pthread_mutex_lock(&q->prot)) == -1) { perror("qmutex lck"); } } };
  }
  do {
    r3 = sem_trywait(&q->sem);
  } while(r3 != -1);
  if(!has_lock) {
    { { if((r2 = pthread_mutex_unlock(&q->prot)) == -1) { perror("qmutex ulck"); } } };
  }
  return (r1 | r2);
}

canonical_original_code:
int qreset(struct queue *q, char has_lock)
{
  int r1; int r2; int r3 = 0;
  if(!has_lock) {
    { { if((r1 = pthread_mutex_lock(&q->prot)) == -1) { perror("qmutex lck"); } } };
  }
  do {
    r3 = sem_trywait(&q->sem);
  } while(r3 != -1);
  if(!has_lock) {
    { { if((r2 = pthread_mutex_unlock(&q->prot)) == -1) { perror("qmutex ulck"); } } };
  }
  return (r1 | r2);
}


decompiled_code:
int __fastcall protmem_init(__int64 a1, __int64 a2)
{
int result; // eax
pthread_mutexattr_t attr; // [rsp+1Ch] [rbp-1Ch] BYREF

if ( pthread_mutexattr_init(&attr) == -1 )
perror("attr init");
if ( pthread_mutexattr_setpshared(&attr, 1) == -1 )
perror("attr set");
result = pthread_mutex_init((pthread_mutex_t *)(a1 + 8), &attr);
if ( result == -1 )
{
perror("mutex init failed");
*(_QWORD *)a1 = a2;
result = -1;
}
else
{
*(_QWORD *)a1 = a2;
}
return result;
}

canonical_decompiled_code:
int __fastcall func13(__int64 a1, __int64 a2)
{
int result; // eax
pthread_mutexattr_t attr; // [rsp+1Ch] [rbp-1Ch] BYREF

if ( pthread_mutexattr_init(&attr) == -1 )
perror("attr init");
if ( pthread_mutexattr_setpshared(&attr, 1) == -1 )
perror("attr set");
result = pthread_mutex_init((pthread_mutex_t *)(a1 + 8), &attr);
if ( result == -1 )
{
perror("mutex init failed");
*(_QWORD *)a1 = a2;
result = -1;
}
else
{
*(_QWORD *)a1 = a2;
}
return result;
}

original_code:
int protmem_init(protmem_t* pr, char* m)
{
  int r1;
  pthread_mutexattr_t p;
  { { if((pthread_mutexattr_init(&p)) == -1) { perror("attr init"); } } };
  { { if((pthread_mutexattr_setpshared(&p, PTHREAD_PROCESS_SHARED)) == -1) { perror("attr set"); } } };
  { { if((r1 = pthread_mutex_init(&pr->prot, &p)) == -1) { perror("mutex init failed"); } } };
  pr->mem = m;
  return r1;
}

canonical_original_code:
int protmem_init(struct protmem *pr, char *m)
{
  int r1;
  union pthread_mutexattr_t p;
  { { if((pthread_mutexattr_init(&p)) == -1) { perror("attr init"); } } };
  { { if((pthread_mutexattr_setpshared(&p, PTHREAD_PROCESS_SHARED)) == -1) { perror("attr set"); } } };
  { { if((r1 = pthread_mutex_init(&pr->prot, &p)) == -1) { perror("mutex init failed"); } } };
  pr->mem = m;
  return r1;
}

variable_types: struct protmem { char *mem; 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; } prot; } *

variable_types:
m
char *

user_defined_types: union pthread_mutexattr_t { char __size[4]; int __align; }

user_defined_types: struct protmem { char *mem; union pthread_mutex_t prot; }


decompiled_code:
__int64 __fastcall protmem_f(_QWORD *a1, void (__fastcall *a2)(_QWORD))
{
pthread_mutex_t *v2; // r13
int v3; // eax
int v4; // ebx
unsigned int v5; // er12
int v6; // eax
int v7; // ebx

v2 = (pthread_mutex_t *)(a1 + 1);
v3 = pthread_mutex_lock((pthread_mutex_t *)(a1 + 1));
if ( v3 == -1 )
{
perror("qmutex lck");
v5 = -1;
a2(*a1);
if ( pthread_mutex_unlock(v2) != -1 )
return v5;
}
else
{
v4 = v3;
v5 = ((__int64 (__fastcall *)(_QWORD))a2)(*a1);
v6 = pthread_mutex_unlock(v2);
if ( v6 != -1 )
{
v7 = v6 | v4;
if ( v7 )
v5 = v7;
return v5;
}
}
perror(&mutex.__size[11]);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func14(_QWORD *a1, void (__fastcall *a2)(_QWORD))
{
pthread_mutex_t *v2; // r13
int v3; // eax
int v4; // ebx
unsigned int v5; // er12
int v6; // eax
int v7; // ebx

v2 = (pthread_mutex_t *)(a1 + 1);
v3 = pthread_mutex_lock((pthread_mutex_t *)(a1 + 1));
if ( v3 == -1 )
{
perror("qmutex lck");
v5 = -1;
a2(*a1);
if ( pthread_mutex_unlock(v2) != -1 )
return v5;
}
else
{
v4 = v3;
v5 = ((__int64 (__fastcall *)(_QWORD))a2)(*a1);
v6 = pthread_mutex_unlock(v2);
if ( v6 != -1 )
{
v7 = v6 | v4;
if ( v7 )
v5 = v7;
return v5;
}
}
perror(&mutex.__size[11]);
return 0xFFFFFFFFLL;
}

original_code:
int protmem_f(protmem_t* p, int (*f) (char*))
{
  int r, r1, r2;
  { { if((r1 = pthread_mutex_lock(&p->prot)) == -1) { perror("qmutex lck"); } } };
  r = (*f)(p->mem);
  { { if((r2 = pthread_mutex_unlock(&p->prot)) == -1) { perror("qmutex ulck"); } } };
  r1 = r1 | r2;
  return (r1 == 0) ? r : r1;
}

canonical_original_code:
int protmem_f(struct protmem *p, int (*f)(char *))
{
  int r; int r1; int r2;
  { { if((r1 = pthread_mutex_lock(&p->prot)) == -1) { perror("qmutex lck"); } } };
  r = (*f)(p->mem);
  { { if((r2 = pthread_mutex_unlock(&p->prot)) == -1) { perror("qmutex ulck"); } } };
  r1 = r1 | r2;
  return (r1 == 0) ? r : r1;
}

variable_types:
f
int (*)(char *)


decompiled_code:
int __fastcall protmem_destroy(__int64 a1)
{
int result; // eax

result = pthread_mutex_destroy((pthread_mutex_t *)(a1 + 8));
if ( result == -1 )
{
perror("protmem dstr");
result = -1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func15(__int64 a1)
{
int result; // eax

result = pthread_mutex_destroy((pthread_mutex_t *)(a1 + 8));
if ( result == -1 )
{
perror("protmem dstr");
result = -1;
}
return result;
}

original_code:
int protmem_destroy(protmem_t* p)
{
  int r;
  { { if((r = pthread_mutex_destroy(&p->prot)) == -1) { perror("protmem dstr"); } } };
  return r;
}

canonical_original_code:
int protmem_destroy(struct protmem *p)
{
  int r;
  { { if((r = pthread_mutex_destroy(&p->prot)) == -1) { perror("protmem dstr"); } } };
  return r;
}


openSharedMem

decompiled_code:
__int64 __fastcall openSharedMem(char *name, int *a2, _BYTE *a3)
{
int v4; // eax
unsigned int v5; // er12
int v6; // eax

v4 = shm_open(name, 194, 0x180u);
*a2 = v4;
v5 = v4;
if ( v4 == -1 )
{
if ( *_errno_location() == 17 )
{
if ( a3 )
*a3 = 1;
v6 = shm_open(name, 2, 0x180u);
*a2 = v6;
v5 = v6;
}
return v5;
}
if ( !a3 )
return v5;
*a3 = 0;
return (unsigned int)*a2;
}

canonical_decompiled_code:
__int64 __fastcall func16(char *name, int *a2, _BYTE *a3)
{
int v4; // eax
unsigned int v5; // er12
int v6; // eax

v4 = shm_open(name, 194, 0x180u);
*a2 = v4;
v5 = v4;
if ( v4 == -1 )
{
if ( *_errno_location() == 17 )
{
if ( a3 )
*a3 = 1;
v6 = shm_open(name, 2, 0x180u);
*a2 = v6;
v5 = v6;
}
return v5;
}
if ( !a3 )
return v5;
*a3 = 0;
return (unsigned int)*a2;
}

original_code:
int openSharedMem(const char* name, int* fd, char* existed)
{
  int flags = 0200 | 0400;
  (*fd) = shm_open(name, 02 | 0100 | 0200, flags);
  if((*fd) == -1) {
    if((*__errno_location ()) == 17) {
      if(existed != ((void *)0)) {
        (*existed) = 1 > 0;
      }
      (*fd) = shm_open(name, 02, flags);
      return (*fd);
    } else {
      { { if((1 > 0) == -1) { perror("shm_open failed"); } } };
      return (*fd);
    }
  } else {
    if(existed != ((void *)0)) {
      (*existed) = 1 < 0;
    }
    return (*fd);
  }
}

canonical_original_code:
int openSharedMem(char *name, int *fd, char *existed)
{
  int flags = 0200 | 0400;
  (*fd) = shm_open(name, 02 | 0100 | 0200, flags);
  if((*fd) == -1) {
    if((*__errno_location ()) == 17) {
      if(existed != ((void *)0)) {
        (*existed) = 1 > 0;
      }
      (*fd) = shm_open(name, 02, flags);
      return (*fd);
    } else {
      { { if((1 > 0) == -1) { perror("shm_open failed"); } } };
      return (*fd);
    }
  } else {
    if(existed != ((void *)0)) {
      (*existed) = 1 < 0;
    }
    return (*fd);
  }
}

variable_types:
name
char *

variable_types:
fd
int *

variable_types:
existed
char *

variable_types: flags int


bopen

decompiled_code:
__int64 bopen()
{
__int64 v0; // r12
char v2; // [rsp+Bh] [rbp-Dh] BYREF
int fd[3]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = -1LL;
if ( (unsigned int)openSharedMem("/my_barrier", fd, &v2) == -1 )
return v0;
if ( v2 )
return (__int64)mmap(0LL, 0x228uLL, 3, 1, fd[0], 0LL);
*_errno_location() = 2;
shm_unlink("/my_barrier");
return -1LL;
}

canonical_decompiled_code:
__int64 func17()
{
__int64 v0; // r12
char v2; // [rsp+Bh] [rbp-Dh] BYREF
int fd[3]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = -1LL;
if ( (unsigned int)func16("/my_barrier", fd, &v2) == -1 )
return v0;
if ( v2 )
return (__int64)mmap(0LL, 0x228uLL, 3, 1, fd[0], 0LL);
*_errno_location() = 2;
shm_unlink("/my_barrier");
return -1LL;
}

original_code:
barrier_t* bopen()
{
  int fd;
  char existed;
  if(openSharedMem("/my_barrier", &fd, &existed) == -1) {
    return (barrier_t*) - 1;
  }
  if(!existed) {
    (*__errno_location ()) = 2;
    shm_unlink("/my_barrier");
    return (barrier_t*) - 1;
  }
  barrier_t *mem = (barrier_t*) mmap(((void *)0), sizeof(barrier_t), 0x1 | 0x2, 0x01, fd, 0);
  return mem;
}

canonical_original_code:
struct barrier *bopen()
{
  int fd;
  char existed;
  if(openSharedMem("/my_barrier", &fd, &existed) == -1) {
    return (struct barrier *) - 1;
  }
  if(!existed) {
    (*__errno_location ()) = 2;
    shm_unlink("/my_barrier");
    return (struct barrier *) - 1;
  }
  struct barrier *mem = (barrier_t*) mmap(((void *)0), sizeof(barrier_t), 0x1 | 0x2, 0x01, fd, 0);
  return mem;
}

variable_types: fd int

variable_types: existed char

variable_types: struct barrier { int max_val; char name[256]; char _m; struct protmem { char *mem; 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; } prot; } releasing; struct queue { union pthread_mutex_t prot; int count; union sem_t { char __size[32]; long __align; } sem; } entrance; struct queue exit; struct queue critical; } *

user_defined_types: struct barrier { int max_val; char name[256]; char _m; struct protmem releasing; struct queue entrance; struct queue exit; struct queue critical; }


binit

decompiled_code:
__int64 __fastcall binit(int a1)
{
char *v2; // rax
char *v3; // r12
char v4; // [rsp+Bh] [rbp-1Dh] BYREF
int fd[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( (unsigned int)openSharedMem("/my_barrier", fd, &v4) == -1 || v4 )
return -1LL;
ftruncate(fd[0], 552LL);
v2 = (char *)mmap(0LL, 0x228uLL, 3, 1, fd[0], 0LL);
v3 = v2;
if ( v2 == (char *)-1LL )
{
perror("mmap failed");
return -1LL;
}
if ( (unsigned int)qinit((pthread_mutex_t *)(v2 + 312)) == -1 )
perror("qinit entr");
if ( (unsigned int)qinit((pthread_mutex_t *)(v3 + 392)) == -1 )
perror("qinit exit");
if ( (unsigned int)qinit((pthread_mutex_t *)(v3 + 472)) == -1 )
perror("qinit critical");
if ( protmem_init((__int64)(v3 + 264), (__int64)(v3 + 260)) == -1 )
perror("protmem r");
*(_DWORD *)v3 = a1;
strcpy(v3 + 4, "/my_barrier");
return (__int64)v3;
}

canonical_decompiled_code:
__int64 __fastcall func18(int a1)
{
char *v2; // rax
char *v3; // r12
char v4; // [rsp+Bh] [rbp-1Dh] BYREF
int fd[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( (unsigned int)func16("/my_barrier", fd, &v4) == -1 || v4 )
return -1LL;
ftruncate(fd[0], 552LL);
v2 = (char *)mmap(0LL, 0x228uLL, 3, 1, fd[0], 0LL);
v3 = v2;
if ( v2 == (char *)-1LL )
{
perror("mmap failed");
return -1LL;
}
if ( (unsigned int)func5((pthread_mutex_t *)(v2 + 312)) == -1 )
perror("qinit entr");
if ( (unsigned int)func5((pthread_mutex_t *)(v3 + 392)) == -1 )
perror("qinit exit");
if ( (unsigned int)func5((pthread_mutex_t *)(v3 + 472)) == -1 )
perror("qinit critical");
if ( func13((__int64)(v3 + 264), (__int64)(v3 + 260)) == -1 )
perror("protmem r");
*(_DWORD *)v3 = a1;
strcpy(v3 + 4, "/my_barrier");
return (__int64)v3;
}

original_code:
barrier_t* binit(unsigned int count)
{
  int fd;
  char existed;
  if(openSharedMem("/my_barrier", &fd, &existed) == -1) {
    return (barrier_t*) - 1;
  }
  if(existed) {
    return (barrier_t*) - 1;
  }
  ftruncate(fd, sizeof(struct barrier));
  barrier_t *mem = (barrier_t*) mmap(((void *)0), sizeof(barrier_t), 0x1 | 0x2, 0x01, fd, 0);
  { { if(((long long)mem) == -1) { perror("mmap failed"); } } };
  if(mem == (void*) - 1) {
    return (void*) - 1;
  }
  { { if((qinit(&mem->entrance)) == -1) { perror("qinit entr"); } } };
  { { if((qinit(&mem->exit)) == -1) { perror("qinit exit"); } } };
  { { if((qinit(&mem->critical)) == -1) { perror("qinit critical"); } } };
  { { if((protmem_init(&mem->releasing, &mem->_m)) == -1) { perror("protmem r"); } } };
  mem->max_val = count;
  strcpy(mem->name, "/my_barrier");
  return mem;
}

canonical_original_code:
struct barrier *binit(unsigned int count)
{
  int fd;
  char existed;
  if(openSharedMem("/my_barrier", &fd, &existed) == -1) {
    return (struct barrier *) - 1;
  }
  if(existed) {
    return (struct barrier *) - 1;
  }
  ftruncate(fd, sizeof(struct barrier));
  struct barrier *mem = (barrier_t*) mmap(((void *)0), sizeof(barrier_t), 0x1 | 0x2, 0x01, fd, 0);
  { { if(((long long)mem) == -1) { perror("mmap failed"); } } };
  if(mem == (void *) - 1) {
    return (void *) - 1;
  }
  { { if((qinit(&mem->entrance)) == -1) { perror("qinit entr"); } } };
  { { if((qinit(&mem->exit)) == -1) { perror("qinit exit"); } } };
  { { if((qinit(&mem->critical)) == -1) { perror("qinit critical"); } } };
  { { if((protmem_init(&mem->releasing, &mem->_m)) == -1) { perror("protmem r"); } } };
  mem->max_val = count;
  strcpy(mem->name, "/my_barrier");
  return mem;
}

variable_types:
count
unsigned int

return_type: struct barrier { int max_val; char name[256]; char _m; struct protmem { char *mem; 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; } prot; } releasing; struct queue { union pthread_mutex_t prot; int count; union sem_t { char __size[32]; long __align; } sem; } entrance; struct queue exit; struct queue critical; } *


bwait

decompiled_code:
__int64 __fastcall bwait(__int64 a1)
{
_QWORD *v1; // rbp

v1 = (_QWORD *)(a1 + 264);
while ( (unsigned int)protmem_f(v1, (void (__fastcall *)(_QWORD))get1B) == 1 )
qwait((pthread_mutex_t *)(a1 + 312));
qincr((pthread_mutex_t *)(a1 + 472));
if ( (unsigned int)qget_count((pthread_mutex_t *)(a1 + 472)) == *(_DWORD *)a1 )
{
protmem_f(v1, (void (__fastcall *)(_QWORD))set1BTrue);
qrelease((pthread_mutex_t *)(a1 + 392), 0);
}
else
{
while ( !(unsigned int)protmem_f(v1, (void (__fastcall *)(_QWORD))get1B) )
qwait((pthread_mutex_t *)(a1 + 392));
}
qdecr((pthread_mutex_t *)(a1 + 472));
if ( !(unsigned int)qget_count((pthread_mutex_t *)(a1 + 472)) )
{
protmem_f(v1, (void (__fastcall *)(_QWORD))set1BFalse);
qrelease((pthread_mutex_t *)(a1 + 312), 0);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1)
{
_QWORD *v1; // rbp

v1 = (_QWORD *)(a1 + 264);
while ( (unsigned int)func14(v1, (void (__fastcall *)(_QWORD))get1B) == 1 )
func8((pthread_mutex_t *)(a1 + 312));
func9((pthread_mutex_t *)(a1 + 472));
if ( (unsigned int)func11((pthread_mutex_t *)(a1 + 472)) == *(_DWORD *)a1 )
{
func14(v1, (void (__fastcall *)(_QWORD))set1BTrue);
func6((pthread_mutex_t *)(a1 + 392), 0);
}
else
{
while ( !(unsigned int)func14(v1, (void (__fastcall *)(_QWORD))get1B) )
func8((pthread_mutex_t *)(a1 + 392));
}
func10((pthread_mutex_t *)(a1 + 472));
if ( !(unsigned int)func11((pthread_mutex_t *)(a1 + 472)) )
{
func14(v1, (void (__fastcall *)(_QWORD))set1BFalse);
func6((pthread_mutex_t *)(a1 + 312), 0);
}
return 0LL;
}

original_code:
int bwait(barrier_t* b)
{
  while(protmem_f(&b->releasing, &get1B) == (int) (1>0) ) {
    qwait(&b->entrance);
  }
  qincr(&b->critical);
  if(qget_count(&b->critical) == b->max_val) {
    protmem_f(&b->releasing, &set1BTrue);
    qrelease(&b->exit, (1<0));
  } else {
    while(protmem_f(&b->releasing, &get1B) == (int) (1<0)) {
      qwait(&b->exit);
    }
  }
  qdecr(&b->critical);
  if(qget_count(&b->critical) == 0) {
    protmem_f(&b->releasing, &set1BFalse);
    qrelease(&b->entrance, (1<0));
  }
  return 0;
}

canonical_original_code:
int bwait(struct barrier *b)
{
  while(protmem_f(&b->releasing, &get1B) == (int) (1>0) ) {
    qwait(&b->entrance);
  }
  qincr(&b->critical);
  if(qget_count(&b->critical) == b->max_val) {
    protmem_f(&b->releasing, &set1BTrue);
    qrelease(&b->exit, (1<0));
  } else {
    while(protmem_f(&b->releasing, &get1B) == (int) (1<0)) {
      qwait(&b->exit);
    }
  }
  qdecr(&b->critical);
  if(qget_count(&b->critical) == 0) {
    protmem_f(&b->releasing, &set1BFalse);
    qrelease(&b->entrance, (1<0));
  }
  return 0;
}


bdestroy

decompiled_code:
__int64 __fastcall bdestroy(void *addr)
{
char v2[264]; // [rsp+0h] [rbp-108h] BYREF

if ( (unsigned int)qdestroy((pthread_mutex_t *)((char *)addr + 312)) == -1 )
perror("bdstr entr");
if ( (unsigned int)qdestroy((pthread_mutex_t *)((char *)addr + 392)) == -1 )
perror("bdstr exit");
if ( protmem_destroy((__int64)addr + 264) == -1 )
perror("bdstr rel");
strcpy(v2, (const char *)addr + 4);
if ( munmap(addr, 0x228uLL) == -1 )
perror("bdstr munmap");
if ( shm_unlink(v2) == -1 )
perror("bdstr shm_unlink");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func20(void *addr)
{
char v2[264]; // [rsp+0h] [rbp-108h] BYREF

if ( (unsigned int)func7((pthread_mutex_t *)((char *)addr + 312)) == -1 )
perror("bdstr entr");
if ( (unsigned int)func7((pthread_mutex_t *)((char *)addr + 392)) == -1 )
perror("bdstr exit");
if ( func15((__int64)addr + 264) == -1 )
perror("bdstr rel");
strcpy(v2, (const char *)addr + 4);
if ( munmap(addr, 0x228uLL) == -1 )
perror("bdstr munmap");
if ( shm_unlink(v2) == -1 )
perror("bdstr shm_unlink");
return 0LL;
}

original_code:
int bdestroy(barrier_t* b)
{
  { { if((qdestroy(&b->entrance)) == -1) { perror("bdstr entr"); } } };
  { { if((qdestroy(&b->exit)) == -1) { perror("bdstr exit"); } } };
  { { if((protmem_destroy(&b->releasing)) == -1) { perror("bdstr rel"); } } };
  char buf[256];
  strcpy(buf, b->name);
  { { if((munmap((void*) b, sizeof(struct barrier))) == -1) { perror("bdstr munmap"); } } };
  { { if((shm_unlink(buf)) == -1) { perror("bdstr shm_unlink"); } } };
  return 0;
}

canonical_original_code:
int bdestroy(struct barrier *b)
{
  { { if((qdestroy(&b->entrance)) == -1) { perror("bdstr entr"); } } };
  { { if((qdestroy(&b->exit)) == -1) { perror("bdstr exit"); } } };
  { { if((protmem_destroy(&b->releasing)) == -1) { perror("bdstr rel"); } } };
  char buf[256];
  strcpy(buf, b->name);
  { { if((munmap((void *) b, sizeof(struct barrier))) == -1) { perror("bdstr munmap"); } } };
  { { if((shm_unlink(buf)) == -1) { perror("bdstr shm_unlink"); } } };
  return 0;
}

variable_types:
buf
char [256]


tidyUp

decompiled_code:
void __fastcall __noreturn tidyUp(unsigned int a1)
{
__int64 v1; // rbx
int v2; // esi

fprintf(stderr, "Caught %d, clearing shared mem..\n", a1);
if ( n > 0 )
{
v1 = 0LL;
do
{
v2 = *(_DWORD *)(children + 4 * v1++);
kill(2, v2);
}
while ( n > (int)v1 );
}
bdestroy(b);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func21(unsigned int a1)
{
__int64 v1; // rbx
int v2; // esi

fprintf(stderr, "Caught %d, clearing shared mem..\n", a1);
if ( n > 0 )
{
v1 = 0LL;
do
{
v2 = *(_DWORD *)(children + 4 * v1++);
kill(2, v2);
}
while ( n > (int)v1 );
}
func20(b);
exit(1);
}

original_code:
void tidyUp(int sig)
{
  fprintf(stderr, "Caught %d, clearing shared mem..\n", sig);
  for (int i = 0; i < n; i++) {
    kill(2, children[i]);
  }
  bdestroy(b);
  _exit(1);
}

variable_types: sig int

variable_types: i int


delay

decompiled_code:
void __fastcall delay(int a1, int a2)
{
int v2; // edx
struct timespec v3; // [rsp+0h] [rbp-28h] BYREF

v2 = a2 + rand() % (a1 - a2);
v3.tv_sec = v2 / 1000000000;
v3.tv_nsec = v2 % 1000000000;
if ( nanosleep(&v3, &v3) == -1 )
perror("nanosleep");
}

canonical_decompiled_code:
void __fastcall func7(int a1, int a2)
{
int v2; // edx
struct timespec v3; // [rsp+0h] [rbp-28h] BYREF

v2 = a2 + rand() % (a1 - a2);
v3.tv_sec = v2 / 1000000000;
v3.tv_nsec = v2 % 1000000000;
if ( nanosleep(&v3, &v3) == -1 )
perror("nanosleep");
}

original_code:
void delay(int r, int m)
{
  struct timespec nSleepTime;
  memset(&nSleepTime, 0, sizeof(struct timespec));
  int t = rand() % (r-m) + m;
  nSleepTime.tv_nsec = t % (1000000000);
  nSleepTime.tv_sec = t / (1000000000);
  { { if((nanosleep(&nSleepTime, &nSleepTime)) == -1) { perror("nanosleep"); } } };
}

variable_types: r int

variable_types: m int

variable_types: struct timespec { long tv_sec; long tv_nsec; }

variable_types: t int


itoa

original_code:
int itoa(int i, char b[])
{
  char const digit[] = "0123456789";
  char* p = b;
  int shifter = i, r = 0;
  do {
    ++p;
    ++r;
    shifter = shifter / 10;
  } while(shifter);
  *p = '\0';
  do {
    *--p = digit[i % 10];
    i = i / 10;
  } while(i);
  return r;
}

canonical_original_code:
int itoa(int i, char b[])
{
  char digit[] = "0123456789";
  char *p = b;
  int shifter = i; int r = 0;
  do {
    ++p;
    ++r;
    shifter = shifter / 10;
  } while(shifter);
  *p = '\0';
  do {
    *--p = digit[i % 10];
    i = i / 10;
  } while(i);
  return r;
}

variable_types:
b
char []

variable_types:
digit
char []

variable_types:
p
char *

variable_types: shifter int


decompiled_code:
void __fastcall print_int(int a1, char *a2)
{
size_t v2; // rax
ssize_t v3; // rbx

itoa(a1, a2);
v2 = strlen(a2);
v3 = write(1, a2, v2);
if ( v3 != strlen(a2) )
perror("write failed");
}

canonical_decompiled_code:
void __fastcall func9(int a1, char *a2)
{
size_t v2; // rax
ssize_t v3; // rbx

func8(a1, a2);
v2 = strlen(a2);
v3 = write(1, a2, v2);
if ( v3 != strlen(a2) )
perror("write failed");
}

original_code:
void print_int(int i, char* buf)
{
  itoa(i,buf);
  { if(write(1, buf, strlen(buf)) != (ssize_t)strlen(buf)) { perror("write failed"); } };
}

canonical_original_code:
void print_int(int i, char *buf)
{
  itoa(i,buf);
  { if(write(1, buf, strlen(buf)) != (long)strlen(buf)) { perror("write failed"); } };
}

variable_types:
buf
char *


decompiled_code:
ssize_t __fastcall print_str(void *buf)
{
size_t v1; // rax

v1 = strlen((const char *)buf);
return write(1, buf, v1);
}

canonical_decompiled_code:
ssize_t __fastcall func10(void *buf)
{
size_t v1; // rax

v1 = strlen((const char *)buf);
return write(1, buf, v1);
}

original_code:
void print_str(const char* buf)
{
  write(1, buf, strlen(buf));
}

canonical_original_code:
void print_str(char *buf)
{
  write(1, buf, strlen(buf));
}


backend

decompiled_code:
ssize_t __fastcall backend(const char *a1, int a2)
{
int v2; // ebx
int v3; // eax
ssize_t result; // rax
ssize_t v5; // [rsp+8h] [rbp-D0h]
__int64 v6[2]; // [rsp+10h] [rbp-C8h] BYREF
struct msghdr message; // [rsp+20h] [rbp-B8h] BYREF
__int64 buf[2]; // [rsp+60h] [rbp-78h] BYREF
int v9; // [rsp+70h] [rbp-68h]
int v10; // [rsp+74h] [rbp-64h]

v2 = open(a1, 0);
print_str("backend (pid: ");
v3 = getpid();
print_int(v3, (char *)buf);
print_str(") read: ");
if ( read(v2, buf, 8uLL) != 8 )
perror("read failed");
if ( write(1, buf, 8uLL) != 8 )
perror("write failed");
print_str("\n");
message.msg_iov = (iovec *)v6;
v10 = 0;
v6[0] = (__int64)"OK";
v6[1] = 2LL;
*(_QWORD *)&message.msg_flags = 0LL;
message.msg_iovlen = 1LL;
message.msg_control = buf;
buf[0] = 20LL;
buf[1] = 0x100000001LL;
v9 = v2;
message.msg_controllen = 20LL;
*(_OWORD *)&message.msg_name = 0LL;
result = sendmsg(a2, &message, 0);
if ( (_DWORD)result == -1 )
{
v5 = result;
perror("sendmsg");
result = v5;
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func11(const char *a1, int a2)
{
int v2; // ebx
int v3; // eax
ssize_t result; // rax
ssize_t v5; // [rsp+8h] [rbp-D0h]
__int64 v6[2]; // [rsp+10h] [rbp-C8h] BYREF
struct msghdr message; // [rsp+20h] [rbp-B8h] BYREF
__int64 buf[2]; // [rsp+60h] [rbp-78h] BYREF
int v9; // [rsp+70h] [rbp-68h]
int v10; // [rsp+74h] [rbp-64h]

v2 = open(a1, 0);
func10("backend (pid: ");
v3 = getpid();
func9(v3, (char *)buf);
func10(") read: ");
if ( read(v2, buf, 8uLL) != 8 )
perror("read failed");
if ( write(1, buf, 8uLL) != 8 )
perror("write failed");
func10("\n");
message.msg_iov = (iovec *)v6;
v10 = 0;
v6[0] = (__int64)"OK";
v6[1] = 2LL;
*(_QWORD *)&message.msg_flags = 0LL;
message.msg_iovlen = 1LL;
message.msg_control = buf;
buf[0] = 20LL;
buf[1] = 0x100000001LL;
v9 = v2;
message.msg_controllen = 20LL;
*(_OWORD *)&message.msg_name = 0LL;
result = sendmsg(a2, &message, 0);
if ( (_DWORD)result == -1 )
{
v5 = result;
perror("sendmsg");
result = v5;
}
return result;
}

original_code:
int backend(const char* fn, int backend_fd)
{
  int fd = open(fn, 00);
  ssize_t msgsize = ((((sizeof(int)) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)) + (((sizeof (struct cmsghdr)) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)));
  char buf[msgsize + 64];
  print_str("backend (pid: ");
  print_int(getpid(), buf);
  print_str(") read: ");
  { if(read(fd, buf, 8) != 8) { perror("read failed"); } };
  { if(write(1, buf, 8) != 8) { perror("write failed"); } };
  print_str("\n");
  memset(buf, 0, msgsize);
  struct iovec iov;
  iov.iov_base = "OK";
  iov.iov_len = 2;
  struct msghdr mhdr;
  memset(&mhdr, 0, sizeof(struct msghdr));
  mhdr.msg_iov = &iov;
  mhdr.msg_iovlen = 1;
  mhdr.msg_control = buf;
  mhdr.msg_controllen = msgsize;
  struct cmsghdr* cmsg = ((size_t) (&mhdr)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (&mhdr)->msg_control : (struct cmsghdr *) 0);
  cmsg->cmsg_level = 1;
  cmsg->cmsg_type = SCM_RIGHTS;
  cmsg->cmsg_len = ((((sizeof (struct cmsghdr)) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)) + (sizeof(int)));
  *(int*)((cmsg)->__cmsg_data) = fd;
  mhdr.msg_controllen = cmsg->cmsg_len;
  int ret = 0;
  { { if((ret = sendmsg(backend_fd, &mhdr, 0)) == -1) { perror("sendmsg"); } } };
  return ret;
}

canonical_original_code:
int backend(char *fn, int backend_fd)
{
  int fd = open(fn, 00);
  long msgsize = ((((sizeof(int)) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)) + (((sizeof (struct cmsghdr)) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)));
  char buf[-1];
  print_str("backend (pid: ");
  print_int(getpid(), buf);
  print_str(") read: ");
  { if(read(fd, buf, 8) != 8) { perror("read failed"); } };
  { if(write(1, buf, 8) != 8) { perror("write failed"); } };
  print_str("\n");
  memset(buf, 0, msgsize);
  struct iovec iov;
  iov.iov_base = "OK";
  iov.iov_len = 2;
  struct msghdr mhdr;
  memset(&mhdr, 0, sizeof(struct msghdr));
  mhdr.msg_iov = &iov;
  mhdr.msg_iovlen = 1;
  mhdr.msg_control = buf;
  mhdr.msg_controllen = msgsize;
  struct cmsghdr *cmsg = ((size_t) (&mhdr)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (&mhdr)->msg_control : (struct cmsghdr *) 0);
  cmsg->cmsg_level = 1;
  cmsg->cmsg_type = SCM_RIGHTS;
  cmsg->cmsg_len = ((((sizeof (struct cmsghdr)) + sizeof (unsigned long) - 1) & (unsigned long) ~(sizeof (unsigned long) - 1)) + (sizeof(int)));
  *(int *)((cmsg)->__cmsg_data) = fd;
  mhdr.msg_controllen = cmsg->cmsg_len;
  int ret = 0;
  { { if((ret = sendmsg(backend_fd, &mhdr, 0)) == -1) { perror("sendmsg"); } } };
  return ret;
}

variable_types:
fn
char *

variable_types: msgsize long

variable_types:
buf
char [-1]

variable_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec { void *iov_base; unsigned long iov_len; } *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; }

variable_types: struct cmsghdr { unsigned long cmsg_len; int cmsg_level; int cmsg_type; unsigned char __cmsg_data[]; } *

variable_types: ret int

user_defined_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; }


frontend

decompiled_code:
__int64 __fastcall frontend(int a1)
{
unsigned int v1; // eax
unsigned int v2; // er12
int v3; // er13
int v4; // eax
__int64 v6[2]; // [rsp+0h] [rbp-1D8h] BYREF
__int128 v7[2]; // [rsp+10h] [rbp-1C8h] BYREF
__int16 v8; // [rsp+30h] [rbp-1A8h]
struct msghdr message; // [rsp+40h] [rbp-198h] BYREF
__int128 buf[4]; // [rsp+80h] [rbp-158h] BYREF
__int128 v11[17]; // [rsp+C0h] [rbp-118h] BYREF

v8 = 0;
message.msg_iov = (iovec *)v6;
v6[0] = (__int64)buf;
v6[1] = 63LL;
*(_QWORD *)&message.msg_flags = 0LL;
message.msg_iovlen = 1LL;
message.msg_control = v7;
message.msg_controllen = 34LL;
buf[0] = 0LL;
buf[1] = 0LL;
buf[2] = 0LL;
buf[3] = 0LL;
v7[0] = 0LL;
v7[1] = 0LL;
*(_OWORD *)&message.msg_name = 0LL;
v1 = recvmsg(a1, &message, 0);
v2 = v1;
if ( v1 == -1 )
{
perror("recvmsg");
}
else if ( !v1 )
{
LABEL_10:
v11[0] = (__int128)_mm_load_si128((const __m128i *)&xmmword_4020C0);
v11[1] = 0LL;
v11[2] = 0LL;
v11[3] = 0LL;
v11[4] = 0LL;
v11[5] = 0LL;
v11[6] = 0LL;
v11[7] = 0LL;
v11[8] = 0LL;
v11[9] = 0LL;
v11[10] = 0LL;
v11[11] = 0LL;
v11[12] = 0LL;
v11[13] = 0LL;
v11[14] = 0LL;
v11[15] = 0LL;
write(2, v11, 0x100uLL);
return 1LL;
}
if ( message.msg_controllen <= 0xF || !message.msg_control )
goto LABEL_10;
v3 = *((unsigned __int8 *)message.msg_control + 16);
print_str("frontend (pid: ");
v4 = getpid();
print_int(v4, (char *)buf);
print_str(") read: ");
if ( read(v3, buf, 8uLL) != 8 )
perror("read failed");
if ( write(1, buf, 8uLL) != 8 )
perror("write failed");
print_str("\n");
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1)
{
unsigned int v1; // eax
unsigned int v2; // er12
int v3; // er13
int v4; // eax
__int64 v6[2]; // [rsp+0h] [rbp-1D8h] BYREF
__int128 v7[2]; // [rsp+10h] [rbp-1C8h] BYREF
__int16 v8; // [rsp+30h] [rbp-1A8h]
struct msghdr message; // [rsp+40h] [rbp-198h] BYREF
__int128 buf[4]; // [rsp+80h] [rbp-158h] BYREF
__int128 v11[17]; // [rsp+C0h] [rbp-118h] BYREF

v8 = 0;
message.msg_iov = (iovec *)v6;
v6[0] = (__int64)buf;
v6[1] = 63LL;
*(_QWORD *)&message.msg_flags = 0LL;
message.msg_iovlen = 1LL;
message.msg_control = v7;
message.msg_controllen = 34LL;
buf[0] = 0LL;
buf[1] = 0LL;
buf[2] = 0LL;
buf[3] = 0LL;
v7[0] = 0LL;
v7[1] = 0LL;
*(_OWORD *)&message.msg_name = 0LL;
v1 = recvmsg(a1, &message, 0);
v2 = v1;
if ( v1 == -1 )
{
perror("recvmsg");
}
else if ( !v1 )
{
LABEL_10:
v11[0] = (__int128)_mm_load_si128((const __m128i *)&xmmword_4020C0);
v11[1] = 0LL;
v11[2] = 0LL;
v11[3] = 0LL;
v11[4] = 0LL;
v11[5] = 0LL;
v11[6] = 0LL;
v11[7] = 0LL;
v11[8] = 0LL;
v11[9] = 0LL;
v11[10] = 0LL;
v11[11] = 0LL;
v11[12] = 0LL;
v11[13] = 0LL;
v11[14] = 0LL;
v11[15] = 0LL;
write(2, v11, 0x100uLL);
return 1LL;
}
if ( message.msg_controllen <= 0xF || !message.msg_control )
goto LABEL_10;
v3 = *((unsigned __int8 *)message.msg_control + 16);
func10("frontend (pid: ");
v4 = getpid();
func9(v4, (char *)buf);
func10(") read: ");
if ( read(v3, buf, 8uLL) != 8 )
perror("read failed");
if ( write(1, buf, 8uLL) != 8 )
perror("write failed");
func10("\n");
return v2;
}

original_code:
int frontend(int frontend_fd)
{
  char control[10 + ((((sizeof(int)) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)) + (((sizeof (struct cmsghdr)) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)))], data[64];
  memset(data, 0, sizeof(data));
  memset(control, 0, sizeof(control));
  struct iovec iov;
  iov.iov_base = data;
  iov.iov_len = sizeof(data)-1;
  struct msghdr mhdr;
  memset(&mhdr, 0, sizeof(mhdr));
  mhdr.msg_iov = &iov;
  mhdr.msg_iovlen = 1;
  mhdr.msg_control = control;
  mhdr.msg_controllen = sizeof(control);
  int ret = 0;
  { { if((ret = recvmsg(frontend_fd, &mhdr, 0)) == -1) { perror("recvmsg"); } } };
  if ((mhdr.msg_flags & MSG_TRUNC) || (mhdr.msg_flags & MSG_CTRUNC)) {
    { { if((1 > 0) == -1) { perror("msg trunc"); } } };
  }
  if(ret == 0 || ((size_t) (&mhdr)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (&mhdr)->msg_control : (struct cmsghdr *) 0) == ((void *)0)) {
    char error[256] = "CMSG error\n";
    write(2, error, sizeof(error));
    return 1;
  }
  int fd = ((((size_t) (&mhdr)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (&mhdr)->msg_control : (struct cmsghdr *) 0))->__cmsg_data)[0];
  print_str("frontend (pid: ");
  print_int(getpid(), data);
  print_str(") read: ");
  { if(read(fd, data, 8) != 8) { perror("read failed"); } };
  { if(write(1, data, 8) != 8) { perror("write failed"); } };
  print_str("\n");
  return ret;
}

canonical_original_code:
int frontend(int frontend_fd)
{
  char control[-1]; char data[64];
  memset(data, 0, sizeof(data));
  memset(control, 0, sizeof(control));
  struct iovec iov;
  iov.iov_base = data;
  iov.iov_len = sizeof(data)-1;
  struct msghdr mhdr;
  memset(&mhdr, 0, sizeof(mhdr));
  mhdr.msg_iov = &iov;
  mhdr.msg_iovlen = 1;
  mhdr.msg_control = control;
  mhdr.msg_controllen = sizeof(control);
  int ret = 0;
  { { if((ret = recvmsg(frontend_fd, &mhdr, 0)) == -1) { perror("recvmsg"); } } };
  if ((mhdr.msg_flags & MSG_TRUNC) || (mhdr.msg_flags & MSG_CTRUNC)) {
    { { if((1 > 0) == -1) { perror("msg trunc"); } } };
  }
  if(ret == 0 || ((unsigned long) (&mhdr)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (&mhdr)->msg_control : (struct cmsghdr *) 0) == ((void *)0)) {
    char error[256] = "CMSG error\n";
    write(2, error, sizeof(error));
    return 1;
  }
  int fd = ((((size_t) (&mhdr)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (&mhdr)->msg_control : (struct cmsghdr *) 0))->__cmsg_data)[0];
  print_str("frontend (pid: ");
  print_int(getpid(), data);
  print_str(") read: ");
  { if(read(fd, data, 8) != 8) { perror("read failed"); } };
  { if(write(1, data, 8) != 8) { perror("write failed"); } };
  print_str("\n");
  return ret;
}

variable_types:
control
char [-1]

variable_types:
data
char [64]

variable_types: struct iovec { void *iov_base; unsigned long iov_len; }

variable_types:
error
char [256]

variable_types: fd int

user_defined_types: struct cmsghdr { unsigned long cmsg_len; int cmsg_level; int cmsg_type; unsigned char __cmsg_data[]; }


isReader

decompiled_code:
__int64 __fastcall isReader(_BYTE *a1)
{
return *a1 & 1;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
return *a1 & 1;
}

original_code:
char isReader(struct thFlags* f)
{
  return f->data & 1;
}

canonical_original_code:
char isReader(struct thFlags *f)
{
  return f->data & 1;
}

variable_types:
f
struct thFlags { char data; } *

return_type: char


isWriter

decompiled_code:
__int64 __fastcall isWriter(_BYTE *a1)
{
return *a1 & 2;
}

canonical_decompiled_code:
__int64 __fastcall func2(_BYTE *a1)
{
return *a1 & 2;
}

original_code:
char isWriter(struct thFlags* f)
{
  return f->data & 2;
}

canonical_original_code:
char isWriter(struct thFlags *f)
{
  return f->data & 2;
}


writeIfHigher

decompiled_code:
void __fastcall writeIfHigher(int a1, _DWORD *a2, pthread_mutex_t *a3)
{
if ( pthread_mutex_lock(a3) )
perror("wIH sem lock failed");
if ( *a2 < a1 )
*a2 = a1;
if ( pthread_mutex_unlock(a3) )
perror("wiH sem unlock failed");
}

canonical_decompiled_code:
void __fastcall func5(int a1, _DWORD *a2, pthread_mutex_t *a3)
{
if ( pthread_mutex_lock(a3) )
perror("wIH sem lock failed");
if ( *a2 < a1 )
*a2 = a1;
if ( pthread_mutex_unlock(a3) )
perror("wiH sem unlock failed");
}

original_code:
void writeIfHigher(int val, int* where, pthread_mutex_t* sem)
{
  { if(pthread_mutex_lock(sem) != 0) { perror("wIH sem lock failed"); } };
  if(*where < val) {
    *where = val;
  }
  { if(pthread_mutex_unlock(sem) != 0) { perror("wiH sem unlock failed"); } };
}

canonical_original_code:
void writeIfHigher(int val, int *where, union pthread_mutex_t *sem)
{
  { if(pthread_mutex_lock(sem) != 0) { perror("wIH sem lock failed"); } };
  if(*where < val) {
    *where = val;
  }
  { if(pthread_mutex_unlock(sem) != 0) { perror("wiH sem unlock failed"); } };
}

variable_types: val int

variable_types:
where
int *

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


Writer

decompiled_code:
void __fastcall Writer(__int64 a1)
{
if ( pthread_mutex_lock(*(pthread_mutex_t **)(a1 + 32)) )
{
perror("r2Sem lock failed");
if ( !pthread_mutex_lock(*(pthread_mutex_t **)(a1 + 8)) )
goto LABEL_3;
}
else if ( !pthread_mutex_lock(*(pthread_mutex_t **)(a1 + 8)) )
{
goto LABEL_3;
}
perror("wSem lock failed");
LABEL_3:
delay(100LL, 10LL);
if ( pthread_mutex_unlock(*(pthread_mutex_t **)(a1 + 8)) )
perror("wSem unlock failed");
if ( pthread_mutex_unlock(*(pthread_mutex_t **)(a1 + 32)) )
perror("r2Sem lock failed");
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1)
{
if ( pthread_mutex_lock(*(pthread_mutex_t **)(a1 + 32)) )
{
perror("r2Sem lock failed");
if ( !pthread_mutex_lock(*(pthread_mutex_t **)(a1 + 8)) )
goto LABEL_3;
}
else if ( !pthread_mutex_lock(*(pthread_mutex_t **)(a1 + 8)) )
{
goto LABEL_3;
}
perror("wSem lock failed");
LABEL_3:
delay(100LL, 10LL);
if ( pthread_mutex_unlock(*(pthread_mutex_t **)(a1 + 8)) )
perror("wSem unlock failed");
if ( pthread_mutex_unlock(*(pthread_mutex_t **)(a1 + 32)) )
perror("r2Sem lock failed");
}

original_code:
void Writer(struct thInfo* t)
{
  { if(pthread_mutex_lock(t->r2Sem) != 0) { perror("r2Sem lock failed"); } };
  { if(pthread_mutex_lock(t->wSem) != 0) { perror("wSem lock failed"); } };
  delay(100,10);
  { if(pthread_mutex_unlock(t->wSem) != 0) { perror("wSem unlock failed"); } };
  { if(pthread_mutex_unlock(t->r2Sem) != 0) { perror("r2Sem lock failed"); } };
}

canonical_original_code:
void Writer(struct thInfo *t)
{
  { if(pthread_mutex_lock(t->r2Sem) != 0) { perror("r2Sem lock failed"); } };
  { if(pthread_mutex_lock(t->wSem) != 0) { perror("wSem lock failed"); } };
  delay(100,10);
  { if(pthread_mutex_unlock(t->wSem) != 0) { perror("wSem unlock failed"); } };
  { if(pthread_mutex_unlock(t->r2Sem) != 0) { perror("r2Sem lock failed"); } };
}

variable_types: struct thInfo { struct thFlags { char data; } flags; 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; } *wSem; int *readerNr; union pthread_mutex_t *rSem; union pthread_mutex_t *r2Sem; int *readerMaxWait; union pthread_mutex_t *rmSem; int *writerMaxWait; union pthread_mutex_t *wmSem; } *

user_defined_types: struct thInfo { struct thFlags flags; union pthread_mutex_t *wSem; int *readerNr; union pthread_mutex_t *rSem; union pthread_mutex_t *r2Sem; int *readerMaxWait; union pthread_mutex_t *rmSem; int *writerMaxWait; union pthread_mutex_t *wmSem; }


Reader

decompiled_code:
void __fastcall Reader(__int64 a1)
{
int *v1; // rdx
int v2; // eax
_DWORD *v3; // rdx
bool v4; // zf
int *v5; // rdx
int v6; // eax

if ( pthread_mutex_lock(*(pthread_mutex_t **)(a1 + 32)) )
{
perror("r2Sem lock failed");
if ( !pthread_mutex_unlock(*(pthread_mutex_t **)(a1 + 32)) )
{
LABEL_3:
if ( !pthread_mutex_lock(*(pthread_mutex_t **)(a1 + 24)) )
goto LABEL_4;
LABEL_14:
perror("rSem lock failed");
v5 = *(int **)(a1 + 16);
v6 = *v5 + 1;
*v5 = v6;
if ( v6 != 1 )
goto LABEL_5;
goto LABEL_15;
}
}
else if ( !pthread_mutex_unlock(*(pthread_mutex_t **)(a1 + 32)) )
{
goto LABEL_3;
}
perror("r2Sem lock failed");
if ( pthread_mutex_lock(*(pthread_mutex_t **)(a1 + 24)) )
goto LABEL_14;
LABEL_4:
v1 = *(int **)(a1 + 16);
v2 = *v1 + 1;
*v1 = v2;
if ( v2 != 1 )
goto LABEL_5;
LABEL_15:
if ( pthread_mutex_lock(*(pthread_mutex_t **)(a1 + 8)) )
perror("wSem lock failed");
LABEL_5:
if ( pthread_mutex_unlock(*(pthread_mutex_t **)(a1 + 24)) )
perror("rSem unlock failed");
delay(1000LL, 10LL);
if ( pthread_mutex_lock(*(pthread_mutex_t **)(a1 + 24)) )
perror("rSem lock failed");
v3 = *(_DWORD **)(a1 + 16);
v4 = (*v3)-- == 1;
if ( v4 && pthread_mutex_unlock(*(pthread_mutex_t **)(a1 + 8)) )
perror("wSem unlock failed");
if ( pthread_mutex_unlock(*(pthread_mutex_t **)(a1 + 24)) )
perror("rSem unlock failed");
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1)
{
int *v1; // rdx
int v2; // eax
_DWORD *v3; // rdx
bool v4; // zf
int *v5; // rdx
int v6; // eax

if ( pthread_mutex_lock(*(pthread_mutex_t **)(a1 + 32)) )
{
perror("r2Sem lock failed");
if ( !pthread_mutex_unlock(*(pthread_mutex_t **)(a1 + 32)) )
{
LABEL_3:
if ( !pthread_mutex_lock(*(pthread_mutex_t **)(a1 + 24)) )
goto LABEL_4;
LABEL_14:
perror("rSem lock failed");
v5 = *(int **)(a1 + 16);
v6 = *v5 + 1;
*v5 = v6;
if ( v6 != 1 )
goto LABEL_5;
goto LABEL_15;
}
}
else if ( !pthread_mutex_unlock(*(pthread_mutex_t **)(a1 + 32)) )
{
goto LABEL_3;
}
perror("r2Sem lock failed");
if ( pthread_mutex_lock(*(pthread_mutex_t **)(a1 + 24)) )
goto LABEL_14;
LABEL_4:
v1 = *(int **)(a1 + 16);
v2 = *v1 + 1;
*v1 = v2;
if ( v2 != 1 )
goto LABEL_5;
LABEL_15:
if ( pthread_mutex_lock(*(pthread_mutex_t **)(a1 + 8)) )
perror("wSem lock failed");
LABEL_5:
if ( pthread_mutex_unlock(*(pthread_mutex_t **)(a1 + 24)) )
perror("rSem unlock failed");
delay(1000LL, 10LL);
if ( pthread_mutex_lock(*(pthread_mutex_t **)(a1 + 24)) )
perror("rSem lock failed");
v3 = *(_DWORD **)(a1 + 16);
v4 = (*v3)-- == 1;
if ( v4 && pthread_mutex_unlock(*(pthread_mutex_t **)(a1 + 8)) )
perror("wSem unlock failed");
if ( pthread_mutex_unlock(*(pthread_mutex_t **)(a1 + 24)) )
perror("rSem unlock failed");
}

original_code:
void Reader(struct thInfo* t)
{
  { if(pthread_mutex_lock(t->r2Sem) != 0) { perror("r2Sem lock failed"); } };
  { if(pthread_mutex_unlock(t->r2Sem) != 0) { perror("r2Sem lock failed"); } };
  { if(pthread_mutex_lock(t->rSem) != 0) { perror("rSem lock failed"); } };
  (*t->readerNr)++;
  if(*t->readerNr == 1) {
    { if(pthread_mutex_lock(t->wSem) != 0) { perror("wSem lock failed"); } };
  }
  { if(pthread_mutex_unlock(t->rSem) != 0) { perror("rSem unlock failed"); } };
  delay(1000,10);
  { if(pthread_mutex_lock(t->rSem) != 0) { perror("rSem lock failed"); } };
  (*t->readerNr) = (*t->readerNr) - 1;
  if(*t->readerNr == 0) {
    { if(pthread_mutex_unlock(t->wSem) != 0) { perror("wSem unlock failed"); } };
  }
  { if(pthread_mutex_unlock(t->rSem) != 0) { perror("rSem unlock failed"); } };
}

canonical_original_code:
void Reader(struct thInfo *t)
{
  { if(pthread_mutex_lock(t->r2Sem) != 0) { perror("r2Sem lock failed"); } };
  { if(pthread_mutex_unlock(t->r2Sem) != 0) { perror("r2Sem lock failed"); } };
  { if(pthread_mutex_lock(t->rSem) != 0) { perror("rSem lock failed"); } };
  (*t->readerNr)++;
  if(*t->readerNr == 1) {
    { if(pthread_mutex_lock(t->wSem) != 0) { perror("wSem lock failed"); } };
  }
  { if(pthread_mutex_unlock(t->rSem) != 0) { perror("rSem unlock failed"); } };
  delay(1000,10);
  { if(pthread_mutex_lock(t->rSem) != 0) { perror("rSem lock failed"); } };
  (*t->readerNr) = (*t->readerNr) - 1;
  if(*t->readerNr == 0) {
    { if(pthread_mutex_unlock(t->wSem) != 0) { perror("wSem unlock failed"); } };
  }
  { if(pthread_mutex_unlock(t->rSem) != 0) { perror("rSem unlock failed"); } };
}


delay

canonical_decompiled_code:
void __fastcall func0(int a1, int a2)
{
int v2; // edx
struct timespec v3; // [rsp+0h] [rbp-28h] BYREF

v2 = a2 + rand() % (a1 - a2);
v3.tv_sec = v2 / 1000000000;
v3.tv_nsec = v2 % 1000000000;
if ( nanosleep(&v3, &v3) == -1 )
perror("nanosleep");
}

canonical_original_code:
void delay(int r, int m)
{
  struct timespec nSleepTime;
  memset(&nSleepTime, 0, sizeof(struct timespec));
  int t = rand() % (r-m) + m;
  nSleepTime.tv_nsec = t % (1000000000);
  nSleepTime.tv_sec = t / (1000000000);
  { { if((nanosleep(&nSleepTime, &nSleepTime)) == -1) { perror("nanosleep"); } } };
}

variable_types: r int

variable_types: m int

variable_types: struct timespec { long tv_sec; long tv_nsec; }

variable_types: t int


CriticalAdd

decompiled_code:
int __fastcall CriticalAdd(pthread_mutex_t *mutex, _DWORD *a2, int a3)
{
pthread_mutex_lock(mutex);
*a2 += a3;
return pthread_mutex_unlock(mutex);
}

canonical_decompiled_code:
int __fastcall func1(pthread_mutex_t *mutex, _DWORD *a2, int a3)
{
pthread_mutex_lock(mutex);
*a2 += a3;
return pthread_mutex_unlock(mutex);
}

original_code:
void CriticalAdd(pthread_mutex_t* m, int* crit, int amount)
{
  { { if((pthread_mutex_lock(m) != 0) == -1) { perror("mutex lock failed"); } } };
  (*crit) = (*crit) + amount;
  { { if((pthread_mutex_unlock(m) != 0) == -1) { perror("mutex unlock failed"); } } };
}

canonical_original_code:
void CriticalAdd(union pthread_mutex_t *m, int *crit, int amount)
{
  { { if((pthread_mutex_lock(m) != 0) == -1) { perror("mutex lock failed"); } } };
  (*crit) = (*crit) + amount;
  { { if((pthread_mutex_unlock(m) != 0) == -1) { perror("mutex unlock failed"); } } };
}

variable_types:
crit
int *

variable_types: amount int


isConsumer

decompiled_code:
__int64 __fastcall isConsumer(_BYTE *a1)
{
return *a1 & 0x80;
}

canonical_decompiled_code:
__int64 __fastcall func2(_BYTE *a1)
{
return *a1 & 0x80;
}

original_code:
char isConsumer(struct thFlags* f)
{
  return f->data & 128;
}

canonical_original_code:
char isConsumer(struct thFlags *f)
{
  return f->data & 128;
}


isProducer

decompiled_code:
__int64 __fastcall isProducer(_BYTE *a1)
{
return *a1 & 0x40;
}

canonical_decompiled_code:
__int64 __fastcall func4(_BYTE *a1)
{
return *a1 & 0x40;
}

original_code:
char isProducer(struct thFlags* f)
{
  return f->data & 64;
}

canonical_original_code:
char isProducer(struct thFlags *f)
{
  return f->data & 64;
}


getAmount

decompiled_code:
__int64 __fastcall getAmount(_BYTE *a1)
{
return *a1 & 0x3F;
}

canonical_decompiled_code:
__int64 __fastcall func6(_BYTE *a1)
{
return *a1 & 0x3F;
}

original_code:
unsigned char getAmount(struct thFlags* f)
{
  return f->data & 63;
}

canonical_original_code:
unsigned char getAmount(struct thFlags *f)
{
  return f->data & 63;
}

return_type: unsigned char


ConsumerAction

decompiled_code:
int __fastcall ConsumerAction(__int64 a1)
{
FILE *v1; // rsi
char v2; // al
int result; // eax

delay(100, 10);
v1 = stderr;
--*(_DWORD *)(*(_QWORD *)(a1 + 8) + 4LL);
fputc(45, v1);
fflush(stderr);
v2 = getAmount((_BYTE *)a1);
setAmount((_BYTE *)a1, v2 - 1);
result = getAmount((_BYTE *)a1);
if ( !(_BYTE)result )
{
fprintf(stderr, "&(%d)", (unsigned int)cCount);
result = fflush(stderr);
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1)
{
FILE *v1; // rsi
char v2; // al
int result; // eax

func0(100, 10);
v1 = stderr;
--*(_DWORD *)(*(_QWORD *)(a1 + 8) + 4LL);
fputc(45, v1);
fflush(stderr);
v2 = func6((_BYTE *)a1);
func7((_BYTE *)a1, v2 - 1);
result = func6((_BYTE *)a1);
if ( !(_BYTE)result )
{
fprintf(stderr, "&(%d)", (unsigned int)cCount);
result = fflush(stderr);
}
return result;
}

original_code:
void ConsumerAction(void* info)
{
  struct thInfo* thinfo = (struct thInfo*) info;
  delay(100,10);
  thinfo->persist->itemCount = thinfo->persist->itemCount - 1;
  fprintf(stderr,"-");
  fflush(stderr);
  setAmount(&thinfo->flags, getAmount(&thinfo->flags) - 1);
  if(getAmount(&thinfo->flags) == 0) {
    fprintf(stderr,"&(%d)", cCount);
    fflush(stderr);
  }
}

canonical_original_code:
void ConsumerAction(void *info)
{
  struct thInfo *thinfo = (struct thInfo*) info;
  delay(100,10);
  thinfo->persist->itemCount = thinfo->persist->itemCount - 1;
  fprintf(stderr,"-");
  fflush(stderr);
  setAmount(&thinfo->flags, getAmount(&thinfo->flags) - 1);
  if(getAmount(&thinfo->flags) == 0) {
    fprintf(stderr,"&(%d)", cCount);
    fflush(stderr);
  }
}

variable_types:
info
void *

variable_types: struct thInfo { struct thFlags { char data; } flags; struct thInfoPersist { int maxItems; int itemCount; 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; } buffer; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } notEmpty; union pthread_cond_t notFull; } *persist; } *

user_defined_types: struct thInfo { struct thFlags flags; struct thInfoPersist *persist; }

user_defined_types: struct thInfoPersist { int maxItems; int itemCount; union pthread_mutex_t buffer; union pthread_cond_t notEmpty; union pthread_cond_t notFull; }

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


ProducerAction

decompiled_code:
int __fastcall ProducerAction(__int64 a1)
{
FILE *v1; // rsi
char v2; // al
int result; // eax

delay(100, 10);
v1 = stderr;
++*(_DWORD *)(*(_QWORD *)(a1 + 8) + 4LL);
fputc(43, v1);
fflush(stderr);
v2 = getAmount((_BYTE *)a1);
setAmount((_BYTE *)a1, v2 - 1);
result = getAmount((_BYTE *)a1);
if ( !(_BYTE)result )
{
fprintf(stderr, "$(%d)", (unsigned int)pCount);
result = fflush(stderr);
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1)
{
FILE *v1; // rsi
char v2; // al
int result; // eax

func0(100, 10);
v1 = stderr;
++*(_DWORD *)(*(_QWORD *)(a1 + 8) + 4LL);
fputc(43, v1);
fflush(stderr);
v2 = func6((_BYTE *)a1);
func7((_BYTE *)a1, v2 - 1);
result = func6((_BYTE *)a1);
if ( !(_BYTE)result )
{
fprintf(stderr, "$(%d)", (unsigned int)pCount);
result = fflush(stderr);
}
return result;
}

original_code:
void ProducerAction(void* info)
{
  struct thInfo* thinfo = (struct thInfo*) info;
  delay(100,10);
  thinfo->persist->itemCount = thinfo->persist->itemCount + 1;
  fprintf(stderr,"+");
  fflush(stderr);
  setAmount(&thinfo->flags, getAmount(&thinfo->flags) - 1);
  if(getAmount(&thinfo->flags) == 0) {
    fprintf(stderr,"$(%d)", pCount);
    fflush(stderr);
  }
}

canonical_original_code:
void ProducerAction(void *info)
{
  struct thInfo *thinfo = (struct thInfo*) info;
  delay(100,10);
  thinfo->persist->itemCount = thinfo->persist->itemCount + 1;
  fprintf(stderr,"+");
  fflush(stderr);
  setAmount(&thinfo->flags, getAmount(&thinfo->flags) - 1);
  if(getAmount(&thinfo->flags) == 0) {
    fprintf(stderr,"$(%d)", pCount);
    fflush(stderr);
  }
}

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