decompiled_code:
__int64 __fastcall check_map(__int64 a1)
{
int *v1; // rax
int *v2; // rax
int *v3; // rax
int v5; // eax
int *v6; // rax
int *v7; // rax
int *v8; // rax
unsigned int v9; // [rsp+4h] [rbp-34h]
int v10[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

v9 = 7;
if ( signal(11, segfault) == (__sighandler_t)-1LL )
{
v3 = _errno_location();
test_msg("FAIL: %s:%d: setting SIGSEGV handler failed: %m\n (errno = %d)\n", "maps00.c", 133LL, (unsigned int)*v3);
goto LABEL_19;
}
if ( _sigsetjmp(segv_ret, 1) )
{
v9 = 6;
}
else
{
v10[0] = -1;
if ( (unsigned int)datachk(*(_QWORD *)(a1 + 272), 0x2000LL, v10)
&& ((*(_BYTE *)(a1 + 8) & 0x20) == 0 || (*(_BYTE *)a1 & 2) != 0) )
{
v2 = _errno_location();
test_msg("FAIL: %s:%d: CRC mismatch\n (errno = %d)\n", "maps00.c", 142LL, (unsigned int)*v2);
return (unsigned int)-1;
}
}
if ( signal(11, segfault) == (__sighandler_t)-1LL )
{
v6 = _errno_location();
test_msg("FAIL: %s:%d: setting SIGSEGV handler failed: %m\n (errno = %d)\n", "maps00.c", 153LL, (unsigned int)*v6);
goto LABEL_19;
}
if ( _sigsetjmp(segv_ret, 1) )
v9 &= 5u;
else
**(_DWORD **)(a1 + 272) = 1234;
if ( signal(11, segfault) == (__sighandler_t)-1LL )
{
v7 = _errno_location();
test_msg("FAIL: %s:%d: restoring SIGSEGV handler failed: %m\n (errno = %d)\n", "maps00.c", 165LL, (unsigned int)*v7);
goto LABEL_19;
}
if ( _sigsetjmp(segv_ret, 1) )
goto LABEL_11;
if ( (*(_BYTE *)a1 & 2) != 0 )
{
v5 = getpagesize();
memcpy(*(void **)(a1 + 272), test_func, v5);
}
else
{
if ( (*(_BYTE *)(a1 + 8) & 0x20) != 0 )
{
LABEL_11:
v9 &= 3u;
goto LABEL_12;
}
lseek(*(_DWORD *)(a1 + 268), 0LL, 0);
if ( (char *)check_map - (char *)test_func > write(
*(_DWORD *)(a1 + 268),
test_func,
(char *)check_map - (char *)test_func) )
{
v8 = _errno_location();
test_msg(
"ERR: %s:%d: failed to write %s: %m\n (errno = %d)\n",
"maps00.c",
177LL,
(const char *)(a1 + 12),
(unsigned int)*v8);
goto LABEL_19;
}
}
if ( (*(_BYTE *)(a1 + 8) & 0x20) != 0 && (*(_BYTE *)a1 & 2) == 0 )
goto LABEL_11;
(*(void (**)(void))(a1 + 272))();
LABEL_12:
if ( signal(11, 0LL) == (__sighandler_t)-1LL )
{
v1 = _errno_location();
test_msg("FAIL: %s:%d: restoring SIGSEGV handler failed: %m\n (errno = %d)\n", "maps00.c", 195LL, (unsigned int)*v1);
LABEL_19:
v9 = -1;
}
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
int *v1; // rax
int *v2; // rax
int *v3; // rax
int v5; // eax
int *v6; // rax
int *v7; // rax
int *v8; // rax
unsigned int v9; // [rsp+4h] [rbp-34h]
int v10[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

v9 = 7;
if ( signal(11, segfault) == (__sighandler_t)-1LL )
{
v3 = _errno_location();
test_msg("FAIL: %s:%d: setting SIGSEGV handler failed: %m\n (errno = %d)\n", "maps00.c", 133LL, (unsigned int)*v3);
goto LABEL_19;
}
if ( _sigsetjmp(segv_ret, 1) )
{
v9 = 6;
}
else
{
v10[0] = -1;
if ( (unsigned int)datachk(*(_QWORD *)(a1 + 272), 0x2000LL, v10)
&& ((*(_BYTE *)(a1 + 8) & 0x20) == 0 || (*(_BYTE *)a1 & 2) != 0) )
{
v2 = _errno_location();
test_msg("FAIL: %s:%d: CRC mismatch\n (errno = %d)\n", "maps00.c", 142LL, (unsigned int)*v2);
return (unsigned int)-1;
}
}
if ( signal(11, segfault) == (__sighandler_t)-1LL )
{
v6 = _errno_location();
test_msg("FAIL: %s:%d: setting SIGSEGV handler failed: %m\n (errno = %d)\n", "maps00.c", 153LL, (unsigned int)*v6);
goto LABEL_19;
}
if ( _sigsetjmp(segv_ret, 1) )
v9 &= 5u;
else
**(_DWORD **)(a1 + 272) = 1234;
if ( signal(11, segfault) == (__sighandler_t)-1LL )
{
v7 = _errno_location();
test_msg("FAIL: %s:%d: restoring SIGSEGV handler failed: %m\n (errno = %d)\n", "maps00.c", 165LL, (unsigned int)*v7);
goto LABEL_19;
}
if ( _sigsetjmp(segv_ret, 1) )
goto LABEL_11;
if ( (*(_BYTE *)a1 & 2) != 0 )
{
v5 = getpagesize();
memcpy(*(void **)(a1 + 272), test_func, v5);
}
else
{
if ( (*(_BYTE *)(a1 + 8) & 0x20) != 0 )
{
LABEL_11:
v9 &= 3u;
goto LABEL_12;
}
lseek(*(_DWORD *)(a1 + 268), 0LL, 0);
if ( (char *)check_map - (char *)test_func > write(
*(_DWORD *)(a1 + 268),
test_func,
(char *)check_map - (char *)test_func) )
{
v8 = _errno_location();
test_msg(
"ERR: %s:%d: failed to write %s: %m\n (errno = %d)\n",
"maps00.c",
177LL,
(const char *)(a1 + 12),
(unsigned int)*v8);
goto LABEL_19;
}
}
if ( (*(_BYTE *)(a1 + 8) & 0x20) != 0 && (*(_BYTE *)a1 & 2) == 0 )
goto LABEL_11;
(*(void (**)(void))(a1 + 272))();
LABEL_12:
if ( signal(11, 0LL) == (__sighandler_t)-1LL )
{
v1 = _errno_location();
test_msg("FAIL: %s:%d: restoring SIGSEGV handler failed: %m\n (errno = %d)\n", "maps00.c", 195LL, (unsigned int)*v1);
LABEL_19:
v9 = -1;
}
return v9;
}

original_code:
static int check_map(struct map *map)
{
 int prot = 0x2 | 0x1 | 0x4;
 if (signal(11, segfault) == ((__sighandler_t) -1))
 {
  test_msg("FAIL: %s:%d: " "setting SIGSEGV handler failed: %m\n" " (errno = %d)\n", "maps00.c", 133, (*__errno_location ()));
  return -1;
 }
 if (!__sigsetjmp (segv_ret, 1))
 {
  uint32_t crc = ~0;
  if (datachk(map->ptr, 0x2000, &crc))
   if (!(map->flag & 0x20) ||
     (map->prot & 0x2)) {
    test_msg("FAIL: %s:%d: " "CRC mismatch\n" " (errno = %d)\n", "maps00.c", 142, (*__errno_location ()));
    return -1;
   }
 } else
  prot &= 0x2 | !0x1 | 0x4;
 if (signal(11, segfault) == ((__sighandler_t) -1))
 {
  test_msg("FAIL: %s:%d: " "setting SIGSEGV handler failed: %m\n" " (errno = %d)\n", "maps00.c", 153, (*__errno_location ()));
  return -1;
 }
 if (!__sigsetjmp (segv_ret, 1))
 {
  * (int *) (map->ptr) = 1234;
 } else
  prot &= !0x2 | 0x1 | 0x4;
 if (signal(11, segfault) == ((__sighandler_t) -1))
 {
  test_msg("FAIL: %s:%d: " "restoring SIGSEGV handler failed: %m\n" " (errno = %d)\n", "maps00.c", 165, (*__errno_location ()));
  return -1;
 }
 if (!__sigsetjmp (segv_ret, 1))
 {
  if (map->prot & 0x2) {
   memcpy(map->ptr,test_func, getpagesize());
  } else {
   if (!(map->flag & 0x20)) {
    lseek(map->fd,0,0);
    if (write(map->fd,test_func,check_map - test_func)<check_map - test_func) {
     test_msg("ERR: %s:%d: " "failed to write %s: %m\n" " (errno = %d)\n", "maps00.c", 177, map->filename, (*__errno_location ()));
     return -1;
    }
   }
  }
  if (!(map->flag & 0x20) || map->prot & 0x2)
   ((int (*)())map->ptr)();
  else
   prot &= 0x2 | 0x1 | !0x4;
 } else
  prot &= 0x2 | 0x1 | !0x4;
 if (signal(11, ((__sighandler_t) 0)) == ((__sighandler_t) -1))
 {
  test_msg("FAIL: %s:%d: " "restoring SIGSEGV handler failed: %m\n" " (errno = %d)\n", "maps00.c", 195, (*__errno_location ()));
  return -1;
 }
 return prot;
}

canonical_original_code:
static int check_map(struct map *map)
{
 int prot = 0x2 | 0x1 | 0x4;
 if (signal(11, segfault) == ((__sighandler_t) -1))
 {
  test_msg("FAIL: %s:%d: " "setting SIGSEGV handler failed: %m\n" " (errno = %d)\n", "maps00.c", 133, (*__errno_location ()));
  return -1;
 }
 if (!__sigsetjmp (segv_ret, 1))
 {
  unsigned int crc = ~0;
  if (datachk(map->ptr, 0x2000, &crc))
   if (!(map->flag & 0x20) ||
     (map->prot & 0x2)) {
    test_msg("FAIL: %s:%d: " "CRC mismatch\n" " (errno = %d)\n", "maps00.c", 142, (*__errno_location ()));
    return -1;
   }
 } else
  prot &= 0x2 | !0x1 | 0x4;
 if (signal(11, segfault) == ((__sighandler_t) -1))
 {
  test_msg("FAIL: %s:%d: " "setting SIGSEGV handler failed: %m\n" " (errno = %d)\n", "maps00.c", 153, (*__errno_location ()));
  return -1;
 }
 if (!__sigsetjmp (segv_ret, 1))
 {
  * (int *) (map->ptr) = 1234;
 } else
  prot &= !0x2 | 0x1 | 0x4;
 if (signal(11, segfault) == ((__sighandler_t) -1))
 {
  test_msg("FAIL: %s:%d: " "restoring SIGSEGV handler failed: %m\n" " (errno = %d)\n", "maps00.c", 165, (*__errno_location ()));
  return -1;
 }
 if (!__sigsetjmp (segv_ret, 1))
 {
  if (map->prot & 0x2) {
   memcpy(map->ptr,test_func, getpagesize());
  } else {
   if (!(map->flag & 0x20)) {
    lseek(map->fd,0,0);
    if (write(map->fd,test_func,check_map - test_func)<check_map - test_func) {
     test_msg("ERR: %s:%d: " "failed to write %s: %m\n" " (errno = %d)\n", "maps00.c", 177, map->filename, (*__errno_location ()));
     return -1;
    }
   }
  }
  if (!(map->flag & 0x20) || map->prot & 0x2)
   ((int (*)())map->ptr)();
  else
   prot &= 0x2 | 0x1 | !0x4;
 } else
  prot &= 0x2 | 0x1 | !0x4;
 if (signal(11, ((void (*)(int)) 0)) == ((__sighandler_t) -1))
 {
  test_msg("FAIL: %s:%d: " "restoring SIGSEGV handler failed: %m\n" " (errno = %d)\n", "maps00.c", 195, (*__errno_location ()));
  return -1;
 }
 return prot;
}

variable_types: prot int

user_defined_types: struct map { int prot; int prot_real; int flag; char filename[256]; int fd; void *ptr; }


segfault

repo: OSLL/pmover

decompiled_code:
void __noreturn segfault()
{
siglongjmp(segv_ret, 1);
}

canonical_decompiled_code:
void __noreturn func4()
{
siglongjmp(segv_ret, 1);
}

original_code:
static void segfault(int signo)
{
 siglongjmp(segv_ret, 1);
}

variable_types: signo int

return_type: void


decompiled_code:
int __fastcall destroy_map(__int64 a1)
{
int result; // eax
int v3; // edi

result = munmap(*(void **)(a1 + 272), 0x2000uLL);
v3 = *(_DWORD *)(a1 + 268);
if ( v3 >= 0 )
{
close(v3);
result = unlink((const char *)(a1 + 12));
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1)
{
int result; // eax
int v3; // edi

result = munmap(*(void **)(a1 + 272), 0x2000uLL);
v3 = *(_DWORD *)(a1 + 268);
if ( v3 >= 0 )
{
close(v3);
result = unlink((const char *)(a1 + 12));
}
return result;
}

original_code:
static void destroy_map(struct map *map)
{
 munmap(map->ptr, 0x2000);
 if (map->fd >= 0)
 {
  close(map->fd);
  unlink(map->filename);
 }
}

variable_types: struct map { int prot; int prot_real; int flag; char filename[256]; int fd; void *ptr; } *


decompiled_code:
__int64 __fastcall check_buf(int fd, __int64 a2, unsigned int a3)
{
__int64 v4; // rbp
int v5; // ebx
int v6; // eax
__int64 v8; // rsi

v4 = (int)a3;
printf("Checking for %d bytes\n", a3);
if ( (int)v4 <= 0 )
return 0LL;
v5 = 0;
do
{
v6 = read(fd, (void *)(v5 + 4211872LL), (int)v4 - v5);
if ( !v6 )
{
puts("Unexpected EOF");
return 1LL;
}
if ( v6 < 0 )
{
perror("Can't read buf");
return 1LL;
}
v5 += v6;
}
while ( (int)v4 > v5 );
v8 = 0LL;
while ( *(_BYTE *)(a2 + v8) == rbuf[v8] )
{
if ( ++v8 == v4 )
return 0LL;
}
printf("Mismatch on %d byte %d != %d\n", v8, (unsigned int)*(char *)(a2 + v8), (unsigned int)rbuf[v8]);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(int fd, __int64 a2, unsigned int a3)
{
__int64 v4; // rbp
int v5; // ebx
int v6; // eax
__int64 v8; // rsi

v4 = (int)a3;
printf("Checking for %d bytes\n", a3);
if ( (int)v4 <= 0 )
return 0LL;
v5 = 0;
do
{
v6 = read(fd, (void *)(v5 + 4211872LL), (int)v4 - v5);
if ( !v6 )
{
puts("Unexpected EOF");
return 1LL;
}
if ( v6 < 0 )
{
perror("Can't read buf");
return 1LL;
}
v5 += v6;
}
while ( (int)v4 > v5 );
v8 = 0LL;
while ( *(_BYTE *)(a2 + v8) == rbuf[v8] )
{
if ( ++v8 == v4 )
return 0LL;
}
printf("Mismatch on %d byte %d != %d\n", v8, (unsigned int)*(char *)(a2 + v8), (unsigned int)rbuf[v8]);
return 1LL;
}

original_code:
static int check_buf(int sk, char *buf, int count)
{
 int rd, i;
 printf("Checking for %d bytes\n", count);
 rd = 0;
 while (rd < count) {
  int r;
  r = read(sk, rbuf + rd, count - rd);
  if (r == 0) {
   printf("Unexpected EOF\n");
   return 1;
  }
  if (r < 0) {
   perror("Can't read buf");
   return 1;
  }
  rd += r;
 }
 for (i = 0; i < count; i++)
  if (buf[i] != rbuf[i]) {
   printf("Mismatch on %d byte %d != %d\n",
     i, (int)buf[i], (int)rbuf[i]);
   return 1;
  }
 return 0;
}

canonical_original_code:
static int check_buf(int sk, char *buf, int count)
{
 int rd; int i;
 printf("Checking for %d bytes\n", count);
 rd = 0;
 while (rd < count) {
  int r;
  r = read(sk, rbuf + rd, count - rd);
  if (r == 0) {
   printf("Unexpected EOF\n");
   return 1;
  }
  if (r < 0) {
   perror("Can't read buf");
   return 1;
  }
  rd += r;
 }
 for (i = 0; i < count; i++)
  if (buf[i] != rbuf[i]) {
   printf("Mismatch on %d byte %d != %d\n",
     i, (int)buf[i], (int)rbuf[i]);
   return 1;
  }
 return 0;
}

variable_types: sk int

variable_types:
buf
char *

variable_types: count int

variable_types: rd int

variable_types: i int

variable_types: r int

return_type: int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
__int64 v4; // rbx
const char *v5; // rdi
socklen_t v6; // edx
int result; // eax
struct sockaddr v8[2]; // [rsp+0h] [rbp-28h] BYREF

if ( argc <= 2 )
{
puts("Need addr, port and iters");
result = -1;
}
else
{
v3 = socket(2, 1, 6);
if ( v3 < 0 )
{
perror("Can't create socket");
result = -1;
}
else
{
v4 = (unsigned int)atoi(argv[2]);
printf("Connecting to %s:%d\n", argv[1], v4);
v5 = argv[1];
v8[0] = 0LL;
v8[0].sa_family = 2;
if ( inet_aton(v5, (struct in_addr *)&v8[0].sa_data[2]) < 0 )
{
perror("Can't convert addr");
result = -1;
}
else
{
*(_WORD *)v8[0].sa_data = _bswap_16((unsigned __int16)v4, v8, 16LL);
if ( connect(v3, v8, v6) < 0 )
{
perror("Can't connect");
result = -1;
}
else
{
result = serve_new_conn_constprop_0(v3);
}
}
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
__int64 v4; // rbx
const char *v5; // rdi
socklen_t v6; // edx
int result; // eax
struct sockaddr v8[2]; // [rsp+0h] [rbp-28h] BYREF

if ( argc <= 2 )
{
puts("Need addr, port and iters");
result = -1;
}
else
{
v3 = socket(2, 1, 6);
if ( v3 < 0 )
{
perror("Can't create socket");
result = -1;
}
else
{
v4 = (unsigned int)atoi(argv[2]);
printf("Connecting to %s:%d\n", argv[1], v4);
v5 = argv[1];
v8[0] = 0LL;
v8[0].sa_family = 2;
if ( inet_aton(v5, (struct in_addr *)&v8[0].sa_data[2]) < 0 )
{
perror("Can't convert addr");
result = -1;
}
else
{
*(_WORD *)v8[0].sa_data = func7((unsigned __int16)v4, v8, 16LL);
if ( connect(v3, v8, v6) < 0 )
{
perror("Can't connect");
result = -1;
}
else
{
result = func9(v3);
}
}
}
}
return result;
}

original_code:
int main(int argc, char **argv)
{
 int sk, port, ret;
 struct sockaddr_in addr;
 if (argc < 3) {
  printf("Need addr, port and iters\n");
  return -1;
 }
 sk = socket(2, SOCK_STREAM, IPPROTO_TCP);
 if (sk < 0) {
  perror("Can't create socket");
  return -1;
 }
 port = atoi(argv[2]);
 printf("Connecting to %s:%d\n", argv[1], port);
 memset(&addr, 0, sizeof(addr));
 addr.sin_family = 2;
 ret = inet_aton(argv[1], &addr.sin_addr);
 if (ret < 0) {
  perror("Can't convert addr");
  return -1;
 }
 addr.sin_port = htons(port);
 ret = connect(sk, (struct sockaddr *)&addr, sizeof(addr));
 if (ret < 0) {
  perror("Can't connect");
  return -1;
 }
 return serve_new_conn(0, sk);
}

canonical_original_code:
int main(int argc, char **argv)
{
 int sk; int port; int ret;
 struct sockaddr_in addr;
 if (argc < 3) {
  printf("Need addr, port and iters\n");
  return -1;
 }
 sk = socket(2, SOCK_STREAM, IPPROTO_TCP);
 if (sk < 0) {
  perror("Can't create socket");
  return -1;
 }
 port = atoi(argv[2]);
 printf("Connecting to %s:%d\n", argv[1], port);
 memset(&addr, 0, sizeof(addr));
 addr.sin_family = 2;
 ret = inet_aton(argv[1], &addr.sin_addr);
 if (ret < 0) {
  perror("Can't convert addr");
  return -1;
 }
 addr.sin_port = htons(port);
 ret = connect(sk, (struct sockaddr *)&addr, sizeof(addr));
 if (ret < 0) {
  perror("Can't connect");
  return -1;
 }
 return serve_new_conn(0, sk);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: port int

variable_types: ret int

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

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

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


decompiled_code:
void *__fastcall poison_area(void *a1)
{
return memset(a1, 172, (unsigned int)shmem_size);
}

canonical_decompiled_code:
void *__fastcall func1(void *a1)
{
return memset(a1, 172, (unsigned int)shmem_size);
}

original_code:
static inline void poison_area(int *mem)
{
 memset(mem, 0xac, shmem_size);
}

variable_types:
mem
int *


child

decompiled_code:
__int64 __fastcall child(key_t key)
{
int v1; // eax
int v2; // ebp
int v3; // edi
void *v4; // r13
unsigned int v5; // er12
int *v6; // rax
__int64 v7; // rcx
int *v8; // rbx
int *v10; // rax
__int64 v11; // rcx
int *v12; // rbx
int v13[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v1 = semget(key, 1, 511);
if ( v1 == -1 )
return (unsigned int)-1;
v2 = v1;
v3 = shmget(key, (unsigned int)shmem_size, 511);
if ( v3 == -1 )
return (unsigned int)-2;
v4 = shmat(v3, 0LL, 0);
if ( v4 == (void *)-1LL )
return (unsigned int)-3;
while ( 1 )
{
v5 = test_go();
if ( !v5 )
break;
if ( semop(v2, &lock, 1uLL) )
{
v6 = _errno_location();
v7 = (unsigned int)*v6;
v8 = v6;
if ( (_DWORD)v7 != 4 )
{
test_msg("FAIL: %s:%d: Error in semop lock (errno = %d)\n", "ipc.c", 66LL, v7);
v5 = *v8;
break;
}
}
else
{
v13[0] = -1;
datagen(v4, (unsigned int)shmem_size, v13);
while ( semop(v2, &unlock, 1uLL) )
{
v10 = _errno_location();
v11 = (unsigned int)*v10;
v12 = v10;
if ( (_DWORD)v11 != 4 )
{
test_msg("FAIL: %s:%d: Error in semop unlock (errno = %d)\n", "ipc.c", 74LL, v11);
v5 = *v12;
goto LABEL_8;
}
}
}
}
LABEL_8:
shmdt(v4);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(key_t key)
{
int v1; // eax
int v2; // ebp
int v3; // edi
void *v4; // r13
unsigned int v5; // er12
int *v6; // rax
__int64 v7; // rcx
int *v8; // rbx
int *v10; // rax
__int64 v11; // rcx
int *v12; // rbx
int v13[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v1 = semget(key, 1, 511);
if ( v1 == -1 )
return (unsigned int)-1;
v2 = v1;
v3 = shmget(key, (unsigned int)shmem_size, 511);
if ( v3 == -1 )
return (unsigned int)-2;
v4 = shmat(v3, 0LL, 0);
if ( v4 == (void *)-1LL )
return (unsigned int)-3;
while ( 1 )
{
v5 = test_go();
if ( !v5 )
break;
if ( semop(v2, &lock, 1uLL) )
{
v6 = _errno_location();
v7 = (unsigned int)*v6;
v8 = v6;
if ( (_DWORD)v7 != 4 )
{
test_msg("FAIL: %s:%d: Error in semop lock (errno = %d)\n", "ipc.c", 66LL, v7);
v5 = *v8;
break;
}
}
else
{
v13[0] = -1;
datagen(v4, (unsigned int)shmem_size, v13);
while ( semop(v2, &unlock, 1uLL) )
{
v10 = _errno_location();
v11 = (unsigned int)*v10;
v12 = v10;
if ( (_DWORD)v11 != 4 )
{
test_msg("FAIL: %s:%d: Error in semop unlock (errno = %d)\n", "ipc.c", 74LL, v11);
v5 = *v12;
goto LABEL_8;
}
}
}
}
LABEL_8:
shmdt(v4);
return v5;
}

original_code:
static int child(key_t key)
{
 int sem, shm, ret, res = 0;
 uint8_t *mem;
 uint32_t crc;
 sem = semget(key, 1, 0777);
 if (sem == -1)
  return -1;
 shm = shmget(key, shmem_size, 0777);
 if (shm == -1)
  return -2;
 mem = shmat(shm, ((void *)0), 0);
 if (mem == (uint8_t *)-1)
  return -3;
 while (test_go()) {
  ret = semop(sem, &lock, 1);
  if (ret) {
   if ((*__errno_location ()) == 4)
    continue;
   test_msg("FAIL: %s:%d: " "Error in semop lock" " (errno = %d)\n", "ipc.c", 66, (*__errno_location ()));
   res = (*__errno_location ());
   break;
  }
  crc = (~0);
  datagen(mem, shmem_size, &crc);
  while ((ret = semop(sem, &unlock, 1)) && ((*__errno_location ()) == 4));
  if (ret) {
   test_msg("FAIL: %s:%d: " "Error in semop unlock" " (errno = %d)\n", "ipc.c", 74, (*__errno_location ()));
   res = (*__errno_location ());
   break;
  }
 }
 shmdt(mem);
 return res;
}

canonical_original_code:
static int child(int key)
{
 int sem; int shm; int ret; int res = 0;
 unsigned char *mem;
 unsigned int crc;
 sem = semget(key, 1, 0777);
 if (sem == -1)
  return -1;
 shm = shmget(key, shmem_size, 0777);
 if (shm == -1)
  return -2;
 mem = shmat(shm, ((void *)0), 0);
 if (mem == (unsigned char *)-1)
  return -3;
 while (test_go()) {
  ret = semop(sem, &lock, 1);
  if (ret) {
   if ((*__errno_location ()) == 4)
    continue;
   test_msg("FAIL: %s:%d: " "Error in semop lock" " (errno = %d)\n", "ipc.c", 66, (*__errno_location ()));
   res = (*__errno_location ());
   break;
  }
  crc = (~0);
  datagen(mem, shmem_size, &crc);
  while ((ret = semop(sem, &unlock, 1)) && ((*__errno_location ()) == 4));
  if (ret) {
   test_msg("FAIL: %s:%d: " "Error in semop unlock" " (errno = %d)\n", "ipc.c", 74, (*__errno_location ()));
   res = (*__errno_location ());
   break;
  }
 }
 shmdt(mem);
 return res;
}

variable_types: key int

variable_types: sem int

variable_types: shm int

variable_types: res int

variable_types:
mem
unsigned char *

variable_types:
crc
unsigned int


decompiled_code:
__int64 __fastcall test_fn(__int64 a1, const char **a2)
{
key_t v2; // eax
key_t v3; // ebx
int v4; // eax
int v5; // ebp
int v6; // eax
int v7; // er13
_BYTE *v8; // rax
_BYTE *v9; // r12
__pid_t v10; // eax
__pid_t v11; // er14
__pid_t v12; // eax
__pid_t v13; // er15
int v14; // ebx
__int64 v15; // rcx
__int64 v16; // rcx
int *v17; // rax
int *v19; // rax
int *v20; // rax
int *v21; // rax
int *v22; // rax
int *v23; // rax
int *v24; // rax
int *v25; // rax
int *v26; // rax
int *v27; // rax
int *v28; // rax
int *v29; // rax
int v30; // eax
int v31; // [rsp+18h] [rbp-40h] BYREF
int stat_loc[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v2 = ftok(*a2, 822155650);
if ( v2 == -1 )
{
v17 = _errno_location();
test_msg("ERR: %s:%d: Can't make key (errno = %d)\n", "ipc.c", 94LL, (unsigned int)*v17);
return 0LL;
}
v3 = v2;
v4 = semget(v2, 1, 2047);
v5 = v4;
if ( v4 == -1 )
{
v21 = _errno_location();
test_msg("ERR: %s:%d: Can't get sem (errno = %d)\n", "ipc.c", 100LL, (unsigned int)*v21);
return 0LL;
}
if ( semctl(v4, 0, 16, 1LL) == -1 )
{
v19 = _errno_location();
test_msg("ERR: %s:%d: Can't init sem (errno = %d)\n", "ipc.c", 105LL, (unsigned int)*v19);
LABEL_31:
semctl(v5, 1, 0);
return 0LL;
}
v6 = shmget(v3, (unsigned int)shmem_size, 2047);
v7 = v6;
if ( v6 == -1 )
{
v22 = _errno_location();
test_msg("ERR: %s:%d: Can't get shm (errno = %d)\n", "ipc.c", 112LL, (unsigned int)*v22);
goto LABEL_31;
}
v8 = shmat(v6, 0LL, 0);
v9 = v8;
if ( v8 == (_BYTE *)-1LL )
{
v24 = _errno_location();
test_msg("ERR: %s:%d: Can't attach shm (errno = %d)\n", "ipc.c", 119LL, (unsigned int)*v24);
goto LABEL_37;
}
poison_area(v8);
v10 = test_fork_id(0xFFFFFFFFLL);
v11 = v10;
if ( v10 == -1 )
{
v27 = _errno_location();
test_msg("ERR: %s:%d: Can't fork 1st time (errno = %d)\n", "ipc.c", 128LL, (unsigned int)*v27);
shmdt(v9);
shmctl(v7, 0, 0LL);
semctl(v5, 1, 0);
goto LABEL_21;
}
if ( !v10 )
goto LABEL_43;
v12 = test_fork_id(0xFFFFFFFFLL);
v13 = v12;
if ( v12 == -1 )
{
v28 = _errno_location();
v14 = 1;
test_msg("ERR: %s:%d: Can't fork 2nd time (errno = %d)\n", "ipc.c", 135LL, (unsigned int)*v28);
goto LABEL_18;
}
if ( !v12 )
{
LABEL_43:
v30 = child(v3);
exit(v30);
}
test_daemon();
while ( 1 )
{
v14 = test_go();
if ( !v14 )
break;
stat_loc[0] = semop(v5, &lock, 1uLL);
if ( stat_loc[0] )
{
v15 = (unsigned int)*_errno_location();
if ( (_DWORD)v15 != 4 )
{
test_msg("FAIL: %s:%d: Error in semop lock (errno = %d)\n", "ipc.c", 148LL, v15);
v14 = 1;
break;
}
}
else
{
if ( *v9 == 0xAC )
goto LABEL_23;
v31 = -1;
if ( (unsigned int)datachk(v9, (unsigned int)shmem_size, &v31) )
{
v29 = _errno_location();
v14 = 1;
test_msg(
"FAIL: %s:%d: Semaphore protection is broken or shmem pages are messed (errno = %d)\n",
"ipc.c",
155LL,
(unsigned int)*v29);
semop(v5, &unlock, 1uLL);
break;
}
poison_area(v9);
LABEL_23:
while ( 1 )
{
stat_loc[0] = semop(v5, &unlock, 1uLL);
if ( !stat_loc[0] )
break;
v16 = (unsigned int)*_errno_location();
if ( (_DWORD)v16 != 4 )
{
test_msg("FAIL: %s:%d: Error in semop unlock (errno = %d)\n", "ipc.c", 165LL, v16);
v14 = 1;
goto LABEL_15;
}
}
}
}
LABEL_15:
test_waitsig();
kill(v13, 15);
waitpid(v13, stat_loc, 0);
if ( (stat_loc[0] & 0x7F) != 0 )
{
v20 = _errno_location();
++v14;
test_msg("ERR: %s:%d: Child 2 was killed (errno = %d)\n", "ipc.c", 175LL, (unsigned int)*v20);
}
else if ( BYTE1(stat_loc[0]) )
{
v26 = _errno_location();
++v14;
test_msg("ERR: %s:%d: Child 2 couldn't inititalise (errno = %d)\n", "ipc.c", 178LL, (unsigned int)*v26);
}
LABEL_18:
kill(v11, 15);
waitpid(v11, stat_loc, 0);
if ( (stat_loc[0] & 0x7F) != 0 )
{
v23 = _errno_location();
test_msg("ERR: %s:%d: Child 1 was killed (errno = %d)\n", "ipc.c", 185LL, (unsigned int)*v23);
LABEL_36:
shmdt(v9);
LABEL_37:
shmctl(v7, 0, 0LL);
goto LABEL_31;
}
if ( BYTE1(stat_loc[0]) )
{
v25 = _errno_location();
test_msg("ERR: %s:%d: Child 1 couldn't inititalise (errno = %d)\n", "ipc.c", 188LL, (unsigned int)*v25);
goto LABEL_36;
}
shmdt(v9);
shmctl(v7, 0, 0LL);
semctl(v5, 1, 0);
if ( !v14 )
LABEL_21:
test_msg("PASS\n");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char **a2)
{
key_t v2; // eax
key_t v3; // ebx
int v4; // eax
int v5; // ebp
int v6; // eax
int v7; // er13
_BYTE *v8; // rax
_BYTE *v9; // r12
__pid_t v10; // eax
__pid_t v11; // er14
__pid_t v12; // eax
__pid_t v13; // er15
int v14; // ebx
__int64 v15; // rcx
__int64 v16; // rcx
int *v17; // rax
int *v19; // rax
int *v20; // rax
int *v21; // rax
int *v22; // rax
int *v23; // rax
int *v24; // rax
int *v25; // rax
int *v26; // rax
int *v27; // rax
int *v28; // rax
int *v29; // rax
int v30; // eax
int v31; // [rsp+18h] [rbp-40h] BYREF
int stat_loc[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v2 = ftok(*a2, 822155650);
if ( v2 == -1 )
{
v17 = _errno_location();
test_msg("ERR: %s:%d: Can't make key (errno = %d)\n", "ipc.c", 94LL, (unsigned int)*v17);
return 0LL;
}
v3 = v2;
v4 = semget(v2, 1, 2047);
v5 = v4;
if ( v4 == -1 )
{
v21 = _errno_location();
test_msg("ERR: %s:%d: Can't get sem (errno = %d)\n", "ipc.c", 100LL, (unsigned int)*v21);
return 0LL;
}
if ( semctl(v4, 0, 16, 1LL) == -1 )
{
v19 = _errno_location();
test_msg("ERR: %s:%d: Can't init sem (errno = %d)\n", "ipc.c", 105LL, (unsigned int)*v19);
LABEL_31:
semctl(v5, 1, 0);
return 0LL;
}
v6 = shmget(v3, (unsigned int)shmem_size, 2047);
v7 = v6;
if ( v6 == -1 )
{
v22 = _errno_location();
test_msg("ERR: %s:%d: Can't get shm (errno = %d)\n", "ipc.c", 112LL, (unsigned int)*v22);
goto LABEL_31;
}
v8 = shmat(v6, 0LL, 0);
v9 = v8;
if ( v8 == (_BYTE *)-1LL )
{
v24 = _errno_location();
test_msg("ERR: %s:%d: Can't attach shm (errno = %d)\n", "ipc.c", 119LL, (unsigned int)*v24);
goto LABEL_37;
}
func1(v8);
v10 = test_fork_id(0xFFFFFFFFLL);
v11 = v10;
if ( v10 == -1 )
{
v27 = _errno_location();
test_msg("ERR: %s:%d: Can't fork 1st time (errno = %d)\n", "ipc.c", 128LL, (unsigned int)*v27);
shmdt(v9);
shmctl(v7, 0, 0LL);
semctl(v5, 1, 0);
goto LABEL_21;
}
if ( !v10 )
goto LABEL_43;
v12 = test_fork_id(0xFFFFFFFFLL);
v13 = v12;
if ( v12 == -1 )
{
v28 = _errno_location();
v14 = 1;
test_msg("ERR: %s:%d: Can't fork 2nd time (errno = %d)\n", "ipc.c", 135LL, (unsigned int)*v28);
goto LABEL_18;
}
if ( !v12 )
{
LABEL_43:
v30 = func0(v3);
exit(v30);
}
test_daemon();
while ( 1 )
{
v14 = test_go();
if ( !v14 )
break;
stat_loc[0] = semop(v5, &lock, 1uLL);
if ( stat_loc[0] )
{
v15 = (unsigned int)*_errno_location();
if ( (_DWORD)v15 != 4 )
{
test_msg("FAIL: %s:%d: Error in semop lock (errno = %d)\n", "ipc.c", 148LL, v15);
v14 = 1;
break;
}
}
else
{
if ( *v9 == 0xAC )
goto LABEL_23;
v31 = -1;
if ( (unsigned int)datachk(v9, (unsigned int)shmem_size, &v31) )
{
v29 = _errno_location();
v14 = 1;
test_msg(
"FAIL: %s:%d: Semaphore protection is broken or shmem pages are messed (errno = %d)\n",
"ipc.c",
155LL,
(unsigned int)*v29);
semop(v5, &unlock, 1uLL);
break;
}
func1(v9);
LABEL_23:
while ( 1 )
{
stat_loc[0] = semop(v5, &unlock, 1uLL);
if ( !stat_loc[0] )
break;
v16 = (unsigned int)*_errno_location();
if ( (_DWORD)v16 != 4 )
{
test_msg("FAIL: %s:%d: Error in semop unlock (errno = %d)\n", "ipc.c", 165LL, v16);
v14 = 1;
goto LABEL_15;
}
}
}
}
LABEL_15:
test_waitsig();
kill(v13, 15);
waitpid(v13, stat_loc, 0);
if ( (stat_loc[0] & 0x7F) != 0 )
{
v20 = _errno_location();
++v14;
test_msg("ERR: %s:%d: Child 2 was killed (errno = %d)\n", "ipc.c", 175LL, (unsigned int)*v20);
}
else if ( BYTE1(stat_loc[0]) )
{
v26 = _errno_location();
++v14;
test_msg("ERR: %s:%d: Child 2 couldn't inititalise (errno = %d)\n", "ipc.c", 178LL, (unsigned int)*v26);
}
LABEL_18:
kill(v11, 15);
waitpid(v11, stat_loc, 0);
if ( (stat_loc[0] & 0x7F) != 0 )
{
v23 = _errno_location();
test_msg("ERR: %s:%d: Child 1 was killed (errno = %d)\n", "ipc.c", 185LL, (unsigned int)*v23);
LABEL_36:
shmdt(v9);
LABEL_37:
shmctl(v7, 0, 0LL);
goto LABEL_31;
}
if ( BYTE1(stat_loc[0]) )
{
v25 = _errno_location();
test_msg("ERR: %s:%d: Child 1 couldn't inititalise (errno = %d)\n", "ipc.c", 188LL, (unsigned int)*v25);
goto LABEL_36;
}
shmdt(v9);
shmctl(v7, 0, 0LL);
semctl(v5, 1, 0);
if ( !v14 )
LABEL_21:
test_msg("PASS\n");
return 0LL;
}

original_code:
static int test_fn(int argc, char **argv)
{
 key_t key;
 int sem, shm, pid1, pid2;
 int fail_count = 0;
 uint8_t *mem;
 uint32_t crc;
 int ret;
 key = ftok(argv[0], 822155650);
 if (key == -1) {
  test_msg("ERR: %s:%d: " "Can't make key" " (errno = %d)\n", "ipc.c", 94, (*__errno_location ()));
  goto out;
 }
 sem = semget(key, 1, 0777 | 01000 | 02000);
 if (sem == -1) {
  test_msg("ERR: %s:%d: " "Can't get sem" " (errno = %d)\n", "ipc.c", 100, (*__errno_location ()));
  goto out;
 }
 if (semctl(sem, 0, 16, 1) == -1) {
  test_msg("ERR: %s:%d: " "Can't init sem" " (errno = %d)\n", "ipc.c", 105, (*__errno_location ()));
  fail_count++;
  goto out_sem;
 }
 shm = shmget(key, shmem_size, 0777 | 01000 | 02000);
 if (shm == -1) {
  test_msg("ERR: %s:%d: " "Can't get shm" " (errno = %d)\n", "ipc.c", 112, (*__errno_location ()));
  fail_count++;
  goto out_sem;
 }
 mem = shmat(shm, ((void *)0), 0);
 if (mem == (void *)-1) {
  test_msg("ERR: %s:%d: " "Can't attach shm" " (errno = %d)\n", "ipc.c", 119, (*__errno_location ()));
  fail_count++;
  goto out_shm;
 }
 poison_area((int *)mem);
 pid1 = test_fork_id(-1);
 if (pid1 == -1) {
  test_msg("ERR: %s:%d: " "Can't fork 1st time" " (errno = %d)\n", "ipc.c", 128, (*__errno_location ()));
  goto out_shdt;
 } else if (pid1 == 0)
  exit(child(key));
 pid2 = test_fork_id(-1);
 if (pid2 == -1) {
  test_msg("ERR: %s:%d: " "Can't fork 2nd time" " (errno = %d)\n", "ipc.c", 135, (*__errno_location ()));
  fail_count++;
  goto out_child;
 } else if (pid2 == 0)
  exit(child(key));
 test_daemon();
 while (test_go()) {
  ret = semop(sem, &lock, 1);
  if (ret) {
   if ((*__errno_location ()) == 4)
    continue;
   fail_count++;
   test_msg("FAIL: %s:%d: " "Error in semop lock" " (errno = %d)\n", "ipc.c", 148, (*__errno_location ()));
   break;
  }
  if (mem[0] != 0xac) {
   crc = (~0);
   if (datachk(mem, shmem_size, &crc)) {
    fail_count++;
    test_msg("FAIL: %s:%d: " "Semaphore protection is broken or " "shmem pages are messed" " (errno = %d)\n", "ipc.c", 155, (*__errno_location ()));
    semop(sem, &unlock, 1);
    break;
   }
   poison_area((int *)mem);
  }
  while ((ret = semop(sem, &unlock, 1)) && ((*__errno_location ()) == 4));
  if (ret) {
   fail_count++;
   test_msg("FAIL: %s:%d: " "Error in semop unlock" " (errno = %d)\n", "ipc.c", 165, (*__errno_location ()));
   break;
  }
 }
 test_waitsig();
 kill(pid2, 15);
 waitpid(pid2, &ret, 0);
 if (!(((ret) & 0x7f) == 0)) {
  fail_count++;
  test_msg("ERR: %s:%d: " "Child 2 was killed" " (errno = %d)\n", "ipc.c", 175, (*__errno_location ()));
 } else if ((((ret) & 0xff00) >> 8)) {
  fail_count++;
  test_msg("ERR: %s:%d: " "Child 2 couldn't inititalise" " (errno = %d)\n", "ipc.c", 178, (*__errno_location ()));
 }
out_child:
 kill(pid1, 15);
 waitpid(pid1, &ret, 0);
 if (!(((ret) & 0x7f) == 0)) {
  fail_count++;
  test_msg("ERR: %s:%d: " "Child 1 was killed" " (errno = %d)\n", "ipc.c", 185, (*__errno_location ()));
 } else if ((((ret) & 0xff00) >> 8)) {
  fail_count++;
  test_msg("ERR: %s:%d: " "Child 1 couldn't inititalise" " (errno = %d)\n", "ipc.c", 188, (*__errno_location ()));
 }
out_shdt:
 shmdt(mem);
out_shm:
 shmctl(shm, 0, ((void *)0));
out_sem:
 semctl(sem, 1, 0);
 if (fail_count == 0)
  test_msg("PASS\n");
out:
 return 0;
}

canonical_original_code:
static int test_fn(int argc, char **argv)
{
 int key;
 int sem; int shm; int pid1; int pid2;
 int fail_count = 0;
 unsigned char *mem;
 unsigned int crc;
 int ret;
 key = ftok(argv[0], 822155650);
 if (key == -1) {
  test_msg("ERR: %s:%d: " "Can't make key" " (errno = %d)\n", "ipc.c", 94, (*__errno_location ()));
  goto out;
 }
 sem = semget(key, 1, 0777 | 01000 | 02000);
 if (sem == -1) {
  test_msg("ERR: %s:%d: " "Can't get sem" " (errno = %d)\n", "ipc.c", 100, (*__errno_location ()));
  goto out;
 }
 if (semctl(sem, 0, 16, 1) == -1) {
  test_msg("ERR: %s:%d: " "Can't init sem" " (errno = %d)\n", "ipc.c", 105, (*__errno_location ()));
  fail_count++;
  goto out_sem;
 }
 shm = shmget(key, shmem_size, 0777 | 01000 | 02000);
 if (shm == -1) {
  test_msg("ERR: %s:%d: " "Can't get shm" " (errno = %d)\n", "ipc.c", 112, (*__errno_location ()));
  fail_count++;
  goto out_sem;
 }
 mem = shmat(shm, ((void *)0), 0);
 if (mem == (void *)-1) {
  test_msg("ERR: %s:%d: " "Can't attach shm" " (errno = %d)\n", "ipc.c", 119, (*__errno_location ()));
  fail_count++;
  goto out_shm;
 }
 poison_area((int *)mem);
 pid1 = test_fork_id(-1);
 if (pid1 == -1) {
  test_msg("ERR: %s:%d: " "Can't fork 1st time" " (errno = %d)\n", "ipc.c", 128, (*__errno_location ()));
  goto out_shdt;
 } else if (pid1 == 0)
  exit(child(key));
 pid2 = test_fork_id(-1);
 if (pid2 == -1) {
  test_msg("ERR: %s:%d: " "Can't fork 2nd time" " (errno = %d)\n", "ipc.c", 135, (*__errno_location ()));
  fail_count++;
  goto out_child;
 } else if (pid2 == 0)
  exit(child(key));
 test_daemon();
 while (test_go()) {
  ret = semop(sem, &lock, 1);
  if (ret) {
   if ((*__errno_location ()) == 4)
    continue;
   fail_count++;
   test_msg("FAIL: %s:%d: " "Error in semop lock" " (errno = %d)\n", "ipc.c", 148, (*__errno_location ()));
   break;
  }
  if (mem[0] != 0xac) {
   crc = (~0);
   if (datachk(mem, shmem_size, &crc)) {
    fail_count++;
    test_msg("FAIL: %s:%d: " "Semaphore protection is broken or " "shmem pages are messed" " (errno = %d)\n", "ipc.c", 155, (*__errno_location ()));
    semop(sem, &unlock, 1);
    break;
   }
   poison_area((int *)mem);
  }
  while ((ret = semop(sem, &unlock, 1)) && ((*__errno_location ()) == 4));
  if (ret) {
   fail_count++;
   test_msg("FAIL: %s:%d: " "Error in semop unlock" " (errno = %d)\n", "ipc.c", 165, (*__errno_location ()));
   break;
  }
 }
 test_waitsig();
 kill(pid2, 15);
 waitpid(pid2, &ret, 0);
 if (!(((ret) & 0x7f) == 0)) {
  fail_count++;
  test_msg("ERR: %s:%d: " "Child 2 was killed" " (errno = %d)\n", "ipc.c", 175, (*__errno_location ()));
 } else if ((((ret) & 0xff00) >> 8)) {
  fail_count++;
  test_msg("ERR: %s:%d: " "Child 2 couldn't inititalise" " (errno = %d)\n", "ipc.c", 178, (*__errno_location ()));
 }
out_child:
 kill(pid1, 15);
 waitpid(pid1, &ret, 0);
 if (!(((ret) & 0x7f) == 0)) {
  fail_count++;
  test_msg("ERR: %s:%d: " "Child 1 was killed" " (errno = %d)\n", "ipc.c", 185, (*__errno_location ()));
 } else if ((((ret) & 0xff00) >> 8)) {
  fail_count++;
  test_msg("ERR: %s:%d: " "Child 1 couldn't inititalise" " (errno = %d)\n", "ipc.c", 188, (*__errno_location ()));
 }
out_shdt:
 shmdt(mem);
out_shm:
 shmctl(shm, 0, ((void *)0));
out_sem:
 semctl(sem, 1, 0);
 if (fail_count == 0)
  test_msg("PASS\n");
out:
 return 0;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
test_init_ns(argc, argv, 0x8000000LL, test_fn);
return 0;
}

original_code:
int main(int argc, char **argv)
{
 test_init_ns(argc, argv, 0x08000000, test_fn);
 return 0;
}


decompiled_code:
void *__fastcall f2(void *a1)
{
int v1; // eax
unsigned int v2; // er13
int v3; // eax
int v5; // eax
int *v6; // rax
int v7; // [rsp+0h] [rbp-38h] BYREF
__int64 v8[6]; // [rsp+6h] [rbp-32h] BYREF

qmemcpy(v8, "wasdfrdgdc", 10);
__writefsqword((unsigned int)&tls_data, 0x6764726664736177uLL);
__writefsword((unsigned int)&word_A08, 0x6364u);
v1 = test_fork_id(0xFFFFFFFFLL);
if ( v1 < 0 )
{
v6 = _errno_location();
test_msg("FAIL: %s:%d: Failed to test_fork()\n (errno = %d)\n", "pthread00.c", 177LL, (unsigned int)*v6);
exit(1);
}
if ( !v1 )
{
*(_DWORD *)a1 |= 1u;
while ( 1 )
{
pthread_mutex_lock(&mtx);
if ( __readfsqword((unsigned int)&tls_data) == v8[0] && __readfsword((unsigned int)&word_A08) == LOWORD(v8[1]) )
{
pthread_mutex_unlock(&mtx);
if ( (*(_DWORD *)a1 & 2) != 0 )
{
*(_DWORD *)a1 |= 4u;
exit(0);
}
}
else
{
pthread_mutex_unlock(&mtx);
if ( (*(_DWORD *)a1 & 2) != 0 )
{
*(_DWORD *)a1 |= 8u;
exit(0);
}
}
sleep(1u);
}
}
*((_DWORD *)a1 + 1) |= 1u;
v2 = v1;
while ( 1 )
{
pthread_mutex_lock(&mtx);
if ( __readfsqword((unsigned int)&tls_data) != v8[0] || __readfsword((unsigned int)&word_A08) != LOWORD(v8[1]) )
break;
pthread_mutex_unlock(&mtx);
v5 = *((_DWORD *)a1 + 1);
*((_DWORD *)a1 + 1) = v5 | 4;
if ( (v5 & 2) != 0 )
goto LABEL_7;
LABEL_17:
sleep(1u);
}
pthread_mutex_unlock(&mtx);
v3 = *((_DWORD *)a1 + 1);
if ( (v3 & 2) == 0 )
goto LABEL_17;
*((_DWORD *)a1 + 1) = v3 | 8;
LABEL_7:
test_msg("Waiting for %d\n", v2);
waitpid(v2, &v7, 0);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1)
{
int v1; // eax
unsigned int v2; // er13
int v3; // eax
int v5; // eax
int *v6; // rax
int v7; // [rsp+0h] [rbp-38h] BYREF
__int64 v8[6]; // [rsp+6h] [rbp-32h] BYREF

qmemcpy(v8, "wasdfrdgdc", 10);
__writefsqword((unsigned int)&tls_data, 0x6764726664736177uLL);
__writefsword((unsigned int)&word_A08, 0x6364u);
v1 = test_fork_id(0xFFFFFFFFLL);
if ( v1 < 0 )
{
v6 = _errno_location();
test_msg("FAIL: %s:%d: Failed to test_fork()\n (errno = %d)\n", "pthread00.c", 177LL, (unsigned int)*v6);
exit(1);
}
if ( !v1 )
{
*(_DWORD *)a1 |= 1u;
while ( 1 )
{
pthread_mutex_lock(&mtx);
if ( __readfsqword((unsigned int)&tls_data) == v8[0] && __readfsword((unsigned int)&word_A08) == LOWORD(v8[1]) )
{
pthread_mutex_unlock(&mtx);
if ( (*(_DWORD *)a1 & 2) != 0 )
{
*(_DWORD *)a1 |= 4u;
exit(0);
}
}
else
{
pthread_mutex_unlock(&mtx);
if ( (*(_DWORD *)a1 & 2) != 0 )
{
*(_DWORD *)a1 |= 8u;
exit(0);
}
}
sleep(1u);
}
}
*((_DWORD *)a1 + 1) |= 1u;
v2 = v1;
while ( 1 )
{
pthread_mutex_lock(&mtx);
if ( __readfsqword((unsigned int)&tls_data) != v8[0] || __readfsword((unsigned int)&word_A08) != LOWORD(v8[1]) )
break;
pthread_mutex_unlock(&mtx);
v5 = *((_DWORD *)a1 + 1);
*((_DWORD *)a1 + 1) = v5 | 4;
if ( (v5 & 2) != 0 )
goto LABEL_7;
LABEL_17:
sleep(1u);
}
pthread_mutex_unlock(&mtx);
v3 = *((_DWORD *)a1 + 1);
if ( (v3 & 2) == 0 )
goto LABEL_17;
*((_DWORD *)a1 + 1) = v3 | 8;
LABEL_7:
test_msg("Waiting for %d\n", v2);
waitpid(v2, &v7, 0);
return 0LL;
}

original_code:
static void *f2(void *map)
{
 char __tls_data[10] = "wasdfrdgdc";
 pid_t pid;
 int status;
 memcpy(tls_data, __tls_data, sizeof(tls_data));
 pid = test_fork_id(-1);
 if (pid < 0) {
  test_msg("FAIL: %s:%d: " "Failed to test_fork()\n" " (errno = %d)\n", "pthread00.c", 177, (*__errno_location ()));
  exit(1);
 } else if (pid == 0) {
  (((int *)map)[0]) |= 1;
  while (1) {
   int ret = 0;
   pthread_mutex_lock(&mtx);
   if (memcmp(tls_data, __tls_data, sizeof(tls_data)))
    ret = 1;
   pthread_mutex_unlock(&mtx);
   if (ret) {
    if (((((int *)map)[0]) & 2)) {
     (((int *)map)[0]) |= 8;
     exit(0);
    }
   } else {
    if (((((int *)map)[0]) & 2)) {
     (((int *)map)[0]) |= 4;
     exit(0);
    }
   }
   sleep(1);
  }
 }
 (((int *)map)[1]) |= 1;
 while (1) {
  int ret = 0;
  pthread_mutex_lock(&mtx);
  if (memcmp(tls_data, __tls_data, sizeof(tls_data)))
   ret = 1;
  pthread_mutex_unlock(&mtx);
  if (ret) {
   if (((((int *)map)[1]) & 2))
    (((int *)map)[1]) |= 8;
  } else {
    (((int *)map)[1]) |= 4;
  }
  if (((((int *)map)[1]) & 2))
   break;
  sleep(1);
 }
 test_msg("Waiting for %d\n", pid);
 waitpid(pid, &status, P_ALL);
 return ((void *)0);
}

canonical_original_code:
static void *f2(void *map)
{
 char __tls_data[10] = "wasdfrdgdc";
 int pid;
 int status;
 memcpy(tls_data, __tls_data, sizeof(tls_data));
 pid = test_fork_id(-1);
 if (pid < 0) {
  test_msg("FAIL: %s:%d: " "Failed to test_fork()\n" " (errno = %d)\n", "pthread00.c", 177, (*__errno_location ()));
  exit(1);
 } else if (pid == 0) {
  (((int *)map)[0]) |= 1;
  while (1) {
   int ret = 0;
   pthread_mutex_lock(&mtx);
   if (memcmp(tls_data, __tls_data, sizeof(tls_data)))
    ret = 1;
   pthread_mutex_unlock(&mtx);
   if (ret) {
    if (((((int *)map)[0]) & 2)) {
     (((int *)map)[0]) |= 8;
     exit(0);
    }
   } else {
    if (((((int *)map)[0]) & 2)) {
     (((int *)map)[0]) |= 4;
     exit(0);
    }
   }
   sleep(1);
  }
 }
 (((int *)map)[1]) |= 1;
 while (1) {
  int ret = 0;
  pthread_mutex_lock(&mtx);
  if (memcmp(tls_data, __tls_data, sizeof(tls_data)))
   ret = 1;
  pthread_mutex_unlock(&mtx);
  if (ret) {
   if (((((int *)map)[1]) & 2))
    (((int *)map)[1]) |= 8;
  } else {
    (((int *)map)[1]) |= 4;
  }
  if (((((int *)map)[1]) & 2))
   break;
  sleep(1);
 }
 test_msg("Waiting for %d\n", pid);
 waitpid(pid, &status, P_ALL);
 return ((void *)0);
}

variable_types:
map
void *

variable_types: pid int

variable_types: status int

return_type: void *


decompiled_code:
void *__fastcall ff1(void *a1)
{
int v1; // eax
unsigned int v2; // er13
int v3; // eax
int v5; // eax
int v6; // eax
int v7; // eax
int v8; // [rsp+0h] [rbp-38h] BYREF
__int64 v9[6]; // [rsp+6h] [rbp-32h] BYREF

qmemcpy(v9, "1122334455", 10);
__writefsqword((unsigned int)&tls_data, 0x3434333332323131uLL);
__writefsword((unsigned int)&word_A08, 0x3535u);
v1 = test_fork_id(0xFFFFFFFFLL);
if ( v1 < 0 )
exit(1);
if ( !v1 )
{
*((_DWORD *)a1 + 4) |= 1u;
while ( 1 )
{
pthread_mutex_lock(&mtx);
if ( __readfsqword((unsigned int)&tls_data) == v9[0] && __readfsword((unsigned int)&word_A08) == LOWORD(v9[1]) )
{
pthread_mutex_unlock(&mtx);
v6 = *((_DWORD *)a1 + 4);
if ( (v6 & 2) != 0 )
{
*((_DWORD *)a1 + 4) = v6 | 4;
exit(4);
}
}
else
{
pthread_mutex_unlock(&mtx);
v5 = *((_DWORD *)a1 + 4);
if ( (v5 & 2) != 0 )
{
*((_DWORD *)a1 + 4) = v5 | 8;
exit(4);
}
}
sleep(1u);
}
}
*((_DWORD *)a1 + 5) |= 1u;
v2 = v1;
while ( 1 )
{
pthread_mutex_lock(&mtx);
if ( __readfsqword((unsigned int)&tls_data) != v9[0] || __readfsword((unsigned int)&word_A08) != LOWORD(v9[1]) )
break;
pthread_mutex_unlock(&mtx);
v7 = *((_DWORD *)a1 + 5);
*((_DWORD *)a1 + 5) = v7 | 4;
if ( (v7 & 2) != 0 )
goto LABEL_7;
LABEL_17:
sleep(1u);
}
pthread_mutex_unlock(&mtx);
v3 = *((_DWORD *)a1 + 5);
if ( (v3 & 2) == 0 )
goto LABEL_17;
*((_DWORD *)a1 + 5) = v3 | 8;
LABEL_7:
test_msg("Waiting for %d\n", v2);
waitpid(v2, &v8, 0);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func1(void *a1)
{
int v1; // eax
unsigned int v2; // er13
int v3; // eax
int v5; // eax
int v6; // eax
int v7; // eax
int v8; // [rsp+0h] [rbp-38h] BYREF
__int64 v9[6]; // [rsp+6h] [rbp-32h] BYREF

qmemcpy(v9, "1122334455", 10);
__writefsqword((unsigned int)&tls_data, 0x3434333332323131uLL);
__writefsword((unsigned int)&word_A08, 0x3535u);
v1 = test_fork_id(0xFFFFFFFFLL);
if ( v1 < 0 )
exit(1);
if ( !v1 )
{
*((_DWORD *)a1 + 4) |= 1u;
while ( 1 )
{
pthread_mutex_lock(&mtx);
if ( __readfsqword((unsigned int)&tls_data) == v9[0] && __readfsword((unsigned int)&word_A08) == LOWORD(v9[1]) )
{
pthread_mutex_unlock(&mtx);
v6 = *((_DWORD *)a1 + 4);
if ( (v6 & 2) != 0 )
{
*((_DWORD *)a1 + 4) = v6 | 4;
exit(4);
}
}
else
{
pthread_mutex_unlock(&mtx);
v5 = *((_DWORD *)a1 + 4);
if ( (v5 & 2) != 0 )
{
*((_DWORD *)a1 + 4) = v5 | 8;
exit(4);
}
}
sleep(1u);
}
}
*((_DWORD *)a1 + 5) |= 1u;
v2 = v1;
while ( 1 )
{
pthread_mutex_lock(&mtx);
if ( __readfsqword((unsigned int)&tls_data) != v9[0] || __readfsword((unsigned int)&word_A08) != LOWORD(v9[1]) )
break;
pthread_mutex_unlock(&mtx);
v7 = *((_DWORD *)a1 + 5);
*((_DWORD *)a1 + 5) = v7 | 4;
if ( (v7 & 2) != 0 )
goto LABEL_7;
LABEL_17:
sleep(1u);
}
pthread_mutex_unlock(&mtx);
v3 = *((_DWORD *)a1 + 5);
if ( (v3 & 2) == 0 )
goto LABEL_17;
*((_DWORD *)a1 + 5) = v3 | 8;
LABEL_7:
test_msg("Waiting for %d\n", v2);
waitpid(v2, &v8, 0);
return 0LL;
}

original_code:
static void *ff1(void *map)
{
 char __tls_data[10] = "1122334455";
 pid_t pid;
 int status;
 memcpy(tls_data, __tls_data, sizeof(tls_data));
 pid = test_fork_id(-1);
 if (pid < 0) {
  exit(1);
 } else if (pid == 0) {
  (((int *)map)[4]) |= 1;
  while (1) {
   int ret = 0;
   pthread_mutex_lock(&mtx);
   if (memcmp(tls_data, __tls_data, sizeof(tls_data)))
    ret = 1;
   pthread_mutex_unlock(&mtx);
   if (ret) {
    if (((((int *)map)[4]) & 2)) {
     (((int *)map)[4]) |= 8;
     exit(4);
    }
   } else {
    if (((((int *)map)[4]) & 2)) {
     (((int *)map)[4]) |= 4;
     exit(4);
    }
   }
   sleep(1);
  }
 }
 (((int *)map)[5]) |= 1;
 while (1) {
  int ret = 0;
  pthread_mutex_lock(&mtx);
  if (memcmp(tls_data, __tls_data, sizeof(tls_data)))
   ret = 1;
  pthread_mutex_unlock(&mtx);
  if (ret) {
   if (((((int *)map)[5]) & 2))
    (((int *)map)[5]) |= 8;
  } else {
    (((int *)map)[5]) |= 4;
  }
  if (((((int *)map)[5]) & 2))
   break;
  sleep(1);
 }
 test_msg("Waiting for %d\n", pid);
 waitpid(pid, &status, P_ALL);
 return ((void *)0);
}

canonical_original_code:
static void *ff1(void *map)
{
 char __tls_data[10] = "1122334455";
 int pid;
 int status;
 memcpy(tls_data, __tls_data, sizeof(tls_data));
 pid = test_fork_id(-1);
 if (pid < 0) {
  exit(1);
 } else if (pid == 0) {
  (((int *)map)[4]) |= 1;
  while (1) {
   int ret = 0;
   pthread_mutex_lock(&mtx);
   if (memcmp(tls_data, __tls_data, sizeof(tls_data)))
    ret = 1;
   pthread_mutex_unlock(&mtx);
   if (ret) {
    if (((((int *)map)[4]) & 2)) {
     (((int *)map)[4]) |= 8;
     exit(4);
    }
   } else {
    if (((((int *)map)[4]) & 2)) {
     (((int *)map)[4]) |= 4;
     exit(4);
    }
   }
   sleep(1);
  }
 }
 (((int *)map)[5]) |= 1;
 while (1) {
  int ret = 0;
  pthread_mutex_lock(&mtx);
  if (memcmp(tls_data, __tls_data, sizeof(tls_data)))
   ret = 1;
  pthread_mutex_unlock(&mtx);
  if (ret) {
   if (((((int *)map)[5]) & 2))
    (((int *)map)[5]) |= 8;
  } else {
    (((int *)map)[5]) |= 4;
  }
  if (((((int *)map)[5]) & 2))
   break;
  sleep(1);
 }
 test_msg("Waiting for %d\n", pid);
 waitpid(pid, &status, P_ALL);
 return ((void *)0);
}


decompiled_code:
void *__fastcall f1(void *a1)
{
int v1; // eax
unsigned int v2; // er13
int v3; // eax
int v5; // eax
int v6; // eax
int v7; // eax
int *v8; // rax
int stat_loc; // [rsp+4h] [rbp-44h] BYREF
pthread_t newthread; // [rsp+8h] [rbp-40h] BYREF
__int64 v11[6]; // [rsp+16h] [rbp-32h] BYREF

qmemcpy(v11, "3122131212", 10);
__writefsword((unsigned int)&word_A08, 0x3231u);
__writefsqword((unsigned int)&tls_data, 0x3231333132323133uLL);
if ( pthread_create(&newthread, 0LL, ff1, a1) )
perror("Cant create thread");
v1 = test_fork_id(0xFFFFFFFFLL);
v2 = v1;
if ( v1 < 0 )
{
v8 = _errno_location();
test_msg("FAIL: %s:%d: Failed to test_fork()\n (errno = %d)\n", "pthread00.c", 117LL, (unsigned int)*v8);
exit(1);
}
if ( !v1 )
{
*((_DWORD *)a1 + 2) |= 1u;
while ( 1 )
{
pthread_mutex_lock(&mtx);
if ( __readfsqword((unsigned int)&tls_data) == v11[0] && __readfsword((unsigned int)&word_A08) == LOWORD(v11[1]) )
{
pthread_mutex_unlock(&mtx);
v6 = *((_DWORD *)a1 + 2);
if ( (v6 & 2) != 0 )
{
*((_DWORD *)a1 + 2) = v6 | 4;
exit(2);
}
}
else
{
pthread_mutex_unlock(&mtx);
v5 = *((_DWORD *)a1 + 2);
if ( (v5 & 2) != 0 )
{
*((_DWORD *)a1 + 2) = v5 | 8;
exit(2);
}
}
sleep(1u);
}
}
*((_DWORD *)a1 + 3) |= 1u;
while ( 1 )
{
pthread_mutex_lock(&mtx);
if ( __readfsqword((unsigned int)&tls_data) != v11[0] || __readfsword((unsigned int)&word_A08) != LOWORD(v11[1]) )
break;
pthread_mutex_unlock(&mtx);
v7 = *((_DWORD *)a1 + 3);
*((_DWORD *)a1 + 3) = v7 | 4;
if ( (v7 & 2) != 0 )
goto LABEL_9;
LABEL_19:
sleep(1u);
}
pthread_mutex_unlock(&mtx);
v3 = *((_DWORD *)a1 + 3);
if ( (v3 & 2) == 0 )
goto LABEL_19;
*((_DWORD *)a1 + 3) = v3 | 8;
LABEL_9:
pthread_join(newthread, 0LL);
test_msg("Waiting for %d\n", v2);
waitpid(v2, &stat_loc, 0);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func2(void *a1)
{
int v1; // eax
unsigned int v2; // er13
int v3; // eax
int v5; // eax
int v6; // eax
int v7; // eax
int *v8; // rax
int stat_loc; // [rsp+4h] [rbp-44h] BYREF
pthread_t newthread; // [rsp+8h] [rbp-40h] BYREF
__int64 v11[6]; // [rsp+16h] [rbp-32h] BYREF

qmemcpy(v11, "3122131212", 10);
__writefsword((unsigned int)&word_A08, 0x3231u);
__writefsqword((unsigned int)&tls_data, 0x3231333132323133uLL);
if ( pthread_create(&newthread, 0LL, ff1, a1) )
perror("Cant create thread");
v1 = test_fork_id(0xFFFFFFFFLL);
v2 = v1;
if ( v1 < 0 )
{
v8 = _errno_location();
test_msg("FAIL: %s:%d: Failed to test_fork()\n (errno = %d)\n", "pthread00.c", 117LL, (unsigned int)*v8);
exit(1);
}
if ( !v1 )
{
*((_DWORD *)a1 + 2) |= 1u;
while ( 1 )
{
pthread_mutex_lock(&mtx);
if ( __readfsqword((unsigned int)&tls_data) == v11[0] && __readfsword((unsigned int)&word_A08) == LOWORD(v11[1]) )
{
pthread_mutex_unlock(&mtx);
v6 = *((_DWORD *)a1 + 2);
if ( (v6 & 2) != 0 )
{
*((_DWORD *)a1 + 2) = v6 | 4;
exit(2);
}
}
else
{
pthread_mutex_unlock(&mtx);
v5 = *((_DWORD *)a1 + 2);
if ( (v5 & 2) != 0 )
{
*((_DWORD *)a1 + 2) = v5 | 8;
exit(2);
}
}
sleep(1u);
}
}
*((_DWORD *)a1 + 3) |= 1u;
while ( 1 )
{
pthread_mutex_lock(&mtx);
if ( __readfsqword((unsigned int)&tls_data) != v11[0] || __readfsword((unsigned int)&word_A08) != LOWORD(v11[1]) )
break;
pthread_mutex_unlock(&mtx);
v7 = *((_DWORD *)a1 + 3);
*((_DWORD *)a1 + 3) = v7 | 4;
if ( (v7 & 2) != 0 )
goto LABEL_9;
LABEL_19:
sleep(1u);
}
pthread_mutex_unlock(&mtx);
v3 = *((_DWORD *)a1 + 3);
if ( (v3 & 2) == 0 )
goto LABEL_19;
*((_DWORD *)a1 + 3) = v3 | 8;
LABEL_9:
pthread_join(newthread, 0LL);
test_msg("Waiting for %d\n", v2);
waitpid(v2, &stat_loc, 0);
return 0LL;
}

original_code:
static void *f1(void *map)
{
 char __tls_data[10] = "3122131212";
 pthread_t th;
 pid_t pid;
 int status;
 memcpy(tls_data, __tls_data, sizeof(tls_data));
 if (pthread_create(&th, ((void *)0), &ff1, map))
  perror("Cant create thread");
 pid = test_fork_id(-1);
 if (pid < 0) {
  test_msg("FAIL: %s:%d: " "Failed to test_fork()\n" " (errno = %d)\n", "pthread00.c", 117, (*__errno_location ()));
  exit(1);
 } else if (pid == 0) {
  (((int *)map)[2]) |= 1;
  while (1) {
   int ret = 0;
   pthread_mutex_lock(&mtx);
   if (memcmp(tls_data, __tls_data, sizeof(tls_data)))
    ret = 1;
   pthread_mutex_unlock(&mtx);
   if (ret) {
    if (((((int *)map)[2]) & 2)) {
     (((int *)map)[2]) |= 8;
     exit(2);
    }
   } else {
    if (((((int *)map)[2]) & 2)) {
     (((int *)map)[2]) |= 4;
     exit(2);
    }
   }
   sleep(1);
  }
 }
 (((int *)map)[3]) |= 1;
 while (1) {
  int ret = 0;
  pthread_mutex_lock(&mtx);
  if (memcmp(tls_data, __tls_data, sizeof(tls_data)))
   ret = 1;
  pthread_mutex_unlock(&mtx);
  if (ret) {
   if (((((int *)map)[3]) & 2))
    (((int *)map)[3]) |= 8;
  } else {
    (((int *)map)[3]) |= 4;
  }
  if (((((int *)map)[3]) & 2))
   break;
  sleep(1);
 }
 pthread_join(th, ((void *)0));
 test_msg("Waiting for %d\n", pid);
 waitpid(pid, &status, P_ALL);
 return ((void *)0);
}

canonical_original_code:
static void *f1(void *map)
{
 char __tls_data[10] = "3122131212";
 unsigned long th;
 int pid;
 int status;
 memcpy(tls_data, __tls_data, sizeof(tls_data));
 if (pthread_create(&th, ((void *)0), &ff1, map))
  perror("Cant create thread");
 pid = test_fork_id(-1);
 if (pid < 0) {
  test_msg("FAIL: %s:%d: " "Failed to test_fork()\n" " (errno = %d)\n", "pthread00.c", 117, (*__errno_location ()));
  exit(1);
 } else if (pid == 0) {
  (((int *)map)[2]) |= 1;
  while (1) {
   int ret = 0;
   pthread_mutex_lock(&mtx);
   if (memcmp(tls_data, __tls_data, sizeof(tls_data)))
    ret = 1;
   pthread_mutex_unlock(&mtx);
   if (ret) {
    if (((((int *)map)[2]) & 2)) {
     (((int *)map)[2]) |= 8;
     exit(2);
    }
   } else {
    if (((((int *)map)[2]) & 2)) {
     (((int *)map)[2]) |= 4;
     exit(2);
    }
   }
   sleep(1);
  }
 }
 (((int *)map)[3]) |= 1;
 while (1) {
  int ret = 0;
  pthread_mutex_lock(&mtx);
  if (memcmp(tls_data, __tls_data, sizeof(tls_data)))
   ret = 1;
  pthread_mutex_unlock(&mtx);
  if (ret) {
   if (((((int *)map)[3]) & 2))
    (((int *)map)[3]) |= 8;
  } else {
    (((int *)map)[3]) |= 4;
  }
  if (((((int *)map)[3]) & 2))
   break;
  sleep(1);
 }
 pthread_join(th, ((void *)0));
 test_msg("Waiting for %d\n", pid);
 waitpid(pid, &status, P_ALL);
 return ((void *)0);
}

variable_types:
th
unsigned long


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
_BYTE *v4; // rax
_BYTE *v5; // rbx
int v6; // ebp
__int64 v7; // rdx
__int64 v8; // rax
int *v9; // rax
int *v11; // rax
int *v12; // rax
pthread_t th; // [rsp+0h] [rbp-28h] BYREF
pthread_t newthread[4]; // [rsp+8h] [rbp-20h] BYREF

test_init(argc, argv, envp);
v3 = getpid();
test_msg("%s pid %d\n", *argv, v3);
v4 = mmap(0LL, 0x400uLL, 3, 33, -1, 0LL);
if ( v4 == (_BYTE *)-1LL )
{
v12 = _errno_location();
test_msg("FAIL: %s:%d: Can't map (errno = %d)\n", "pthread00.c", 237LL, (unsigned int)*v12);
exit(1);
}
v5 = v4;
v6 = pthread_create(&th, 0LL, f1, v4);
if ( pthread_create(newthread, 0LL, f2, v5) | v6 )
{
v11 = _errno_location();
test_msg("FAIL: %s:%d: Can't pthread_create (errno = %d)\n", "pthread00.c", 245LL, (unsigned int)*v11);
exit(1);
}
test_msg("Waiting until all threads are created\n");
while ( 1 )
{
if ( (*v5 & 1) != 0 && (v5[4] & 1) != 0 && (v5[8] & 1) != 0 && (v5[12] & 1) != 0 && (v5[16] & 1) != 0 )
{
v7 = *((_QWORD *)v5 + 1) | 0x200000002LL;
v8 = *((_QWORD *)v5 + 2) | 0x200000002LL;
if ( (v5[20] & 1) != 0 )
break;
}
sleep(1u);
}
*(_QWORD *)v5 |= 0x200000002uLL;
*((_QWORD *)v5 + 1) = v7;
*((_QWORD *)v5 + 2) = v8;
test_daemon();
test_waitsig();
test_msg("Waiting while all threads are joined\n");
pthread_join(th, 0LL);
pthread_join(newthread[0], 0LL);
if ( (*v5 & 4) != 0
&& (v5[4] & 4) != 0
&& (v5[8] & 4) != 0
&& (v5[12] & 4) != 0
&& (v5[16] & 4) != 0
&& (v5[20] & 4) != 0 )
{
test_msg("PASS\n");
}
else
{
v9 = _errno_location();
test_msg("FAIL: %s:%d: (errno = %d)\n", "pthread00.c", 283LL, (unsigned int)*v9);
}
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 pthread_t th1, th2;
 int rc1, rc2;
 void *map;
 test_init(argc, argv);
 test_msg("%s pid %d\n", argv[0], getpid());
 map = mmap(((void *)0), 1024, 0x1 | 0x2, 0x01 | 0x20, -1, 0);
 if (map == ((void *) -1)) {
  test_msg("FAIL: %s:%d: " "Can't map" " (errno = %d)\n", "pthread00.c", 237, (*__errno_location ()));
  exit(1);
 }
 rc1 = pthread_create(&th1, ((void *)0), &f1, map);
 rc2 = pthread_create(&th2, ((void *)0), &f2, map);
 if (rc1 | rc2) {
  test_msg("FAIL: %s:%d: " "Can't pthread_create" " (errno = %d)\n", "pthread00.c", 245, (*__errno_location ()));
  exit(1);
 }
 test_msg("Waiting until all threads are created\n");
 for (;;) {
  if (((((int *)map)[0]) & 1) &&
      ((((int *)map)[1]) & 1) &&
      ((((int *)map)[2]) & 1) &&
      ((((int *)map)[3]) & 1) &&
      ((((int *)map)[4]) & 1) &&
      ((((int *)map)[5]) & 1))
   break;
  sleep(1);
 }
 (((int *)map)[0]) |= 2;
 (((int *)map)[1]) |= 2;
 (((int *)map)[2]) |= 2;
 (((int *)map)[3]) |= 2;
 (((int *)map)[4]) |= 2;
 (((int *)map)[5]) |= 2;
 test_daemon();
 test_waitsig();
 test_msg("Waiting while all threads are joined\n");
 pthread_join(th1, ((void *)0));
 pthread_join(th2, ((void *)0));
 if (((((int *)map)[0]) & 4) &&
     ((((int *)map)[1]) & 4) &&
     ((((int *)map)[2]) & 4) &&
     ((((int *)map)[3]) & 4) &&
     ((((int *)map)[4]) & 4) &&
     ((((int *)map)[5]) & 4))
  test_msg("PASS\n");
 else
  test_msg("FAIL: %s:%d: " " (errno = %d)\n", "pthread00.c", 283, (*__errno_location ()));
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 unsigned long th1; unsigned long th2;
 int rc1; int rc2;
 void *map;
 test_init(argc, argv);
 test_msg("%s pid %d\n", argv[0], getpid());
 map = mmap(((void *)0), 1024, 0x1 | 0x2, 0x01 | 0x20, -1, 0);
 if (map == ((void *) -1)) {
  test_msg("FAIL: %s:%d: " "Can't map" " (errno = %d)\n", "pthread00.c", 237, (*__errno_location ()));
  exit(1);
 }
 rc1 = pthread_create(&th1, ((void *)0), &f1, map);
 rc2 = pthread_create(&th2, ((void *)0), &f2, map);
 if (rc1 | rc2) {
  test_msg("FAIL: %s:%d: " "Can't pthread_create" " (errno = %d)\n", "pthread00.c", 245, (*__errno_location ()));
  exit(1);
 }
 test_msg("Waiting until all threads are created\n");
 for (;;) {
  if (((((int *)map)[0]) & 1) &&
      ((((int *)map)[1]) & 1) &&
      ((((int *)map)[2]) & 1) &&
      ((((int *)map)[3]) & 1) &&
      ((((int *)map)[4]) & 1) &&
      ((((int *)map)[5]) & 1))
   break;
  sleep(1);
 }
 (((int *)map)[0]) |= 2;
 (((int *)map)[1]) |= 2;
 (((int *)map)[2]) |= 2;
 (((int *)map)[3]) |= 2;
 (((int *)map)[4]) |= 2;
 (((int *)map)[5]) |= 2;
 test_daemon();
 test_waitsig();
 test_msg("Waiting while all threads are joined\n");
 pthread_join(th1, ((void *)0));
 pthread_join(th2, ((void *)0));
 if (((((int *)map)[0]) & 4) &&
     ((((int *)map)[1]) & 4) &&
     ((((int *)map)[2]) & 4) &&
     ((((int *)map)[3]) & 4) &&
     ((((int *)map)[4]) & 4) &&
     ((((int *)map)[5]) & 4))
  test_msg("PASS\n");
 else
  test_msg("FAIL: %s:%d: " " (errno = %d)\n", "pthread00.c", 283, (*__errno_location ()));
 return 0;
}

variable_types:
argv
char *[]


decompiled_code:
int test_msg(const char *a1, ...)
{
struct tm *v2; // rcx
int v3; // ebx
char *v4; // rdi
int v5; // ebx
unsigned int v6; // eax
int v7; // eax
int *v9; // rax
int v10; // er8
int v11; // er9
struct timeval v12; // [rsp+0h] [rbp-10F8h] BYREF
gcc_va_list arg; // [rsp+18h] [rbp-10E0h] BYREF
char s[4096]; // [rsp+30h] [rbp-10C8h] BYREF

gettimeofday(&v12, 0LL);
v2 = localtime(&v12.tv_sec);
if ( v2 )
{
v3 = strftime(s, 0x1000uLL, "%H:%M:%S", v2);
v4 = &s[v3];
}
else
{
v9 = _errno_location();
v3 = 0;
test_msg(
(unsigned int)"ERR: %s:%d: localtime() failed (errno = %d)\n",
(unsigned int)"msg.c",
48,
*v9,
v10,
v11,
v12.tv_sec);
v4 = s;
}
v5 = sprintf(v4, ".%.3ld: ", v12.tv_usec / 1000) + v3;
v6 = getpid();
v7 = sprintf(&s[v5], "%5d: ", v6);
va_start(arg, a1);
vsnprintf(&s[v7 + v5], 4096LL - (v7 + v5), a1, arg);
return fprintf(stderr, s);
}

canonical_decompiled_code:
int func0(const char *a1, ...)
{
struct tm *v2; // rcx
int v3; // ebx
char *v4; // rdi
int v5; // ebx
unsigned int v6; // eax
int v7; // eax
int *v9; // rax
int v10; // er8
int v11; // er9
struct timeval v12; // [rsp+0h] [rbp-10F8h] BYREF
gcc_va_list arg; // [rsp+18h] [rbp-10E0h] BYREF
char s[4096]; // [rsp+30h] [rbp-10C8h] BYREF

gettimeofday(&v12, 0LL);
v2 = localtime(&v12.tv_sec);
if ( v2 )
{
v3 = strftime(s, 0x1000uLL, "%H:%M:%S", v2);
v4 = &s[v3];
}
else
{
v9 = _errno_location();
v3 = 0;
func0(
(unsigned int)"ERR: %s:%d: localtime() failed (errno = %d)\n",
(unsigned int)"msg.c",
48,
*v9,
v10,
v11,
v12.tv_sec);
v4 = s;
}
v5 = sprintf(v4, ".%.3ld: ", v12.tv_usec / 1000) + v3;
v6 = getpid();
v7 = sprintf(&s[v5], "%5d: ", v6);
va_start(arg, a1);
vsnprintf(&s[v7 + v5], 4096LL - (v7 + v5), a1, arg);
return fprintf(stderr, s);
}

original_code:
void test_msg(const char *format, ...)
{
 va_list arg;
 int off = 0;
 char buf[(1UL << 12)];
 struct timeval tv;
 struct tm *tm;
 gettimeofday(&tv, ((void *)0));
 tm = localtime(&tv.tv_sec);
 if (tm == ((void *)0)) {
  test_msg("ERR: %s:%d: " "localtime() failed" " (errno = %d)\n", "msg.c", 48, (*__errno_location ()));
 } else {
  off += strftime(buf, sizeof(buf), "%H:%M:%S", tm);
 }
 off += sprintf(buf + off, ".%.3ld: ", tv.tv_usec / 1000);
 off += sprintf(buf + off, "%5d: ", getpid());
 __builtin_va_start(arg,format);
 off += vsnprintf(buf + off, sizeof(buf) - off, format, arg);
 __builtin_va_end(arg);
 fprintf(stderr, buf);
}

canonical_original_code:
void test_msg(char *format, ...)
{
 __builtin_va_list arg;
 int off = 0;
 char buf[-1];
 struct timeval tv;
 struct tm *tm;
 gettimeofday(&tv, ((void *)0));
 tm = localtime(&tv.tv_sec);
 if (tm == ((void *)0)) {
  test_msg("ERR: %s:%d: " "localtime() failed" " (errno = %d)\n", "msg.c", 48, (*__errno_location ()));
 } else {
  off += strftime(buf, sizeof(buf), "%H:%M:%S", tm);
 }
 off += sprintf(buf + off, ".%.3ld: ", tv.tv_usec / 1000);
 off += sprintf(buf + off, "%5d: ", getpid());
 __builtin_va_start(arg,format);
 off += vsnprintf(buf + off, sizeof(buf) - off, format, arg);
 __builtin_va_end(arg);
 fprintf(stderr, buf);
}

variable_types:
format
char *

variable_types: off int

variable_types:
buf
char [-1]

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

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *


decompiled_code:
__int64 __fastcall test_log_init(const char *a1, const char *a2)
{
int v2; // eax
int v3; // ebp
__int64 result; // rax
int *v5; // rax
char v6[4120]; // [rsp+0h] [rbp-1018h] BYREF

snprintf(v6, 0x1000uLL, "%s%s", a1, a2);
v2 = open(v6, 1217, 420LL);
if ( v2 < 0 )
{
v5 = _errno_location();
test_msg("ERR: %s:%d: Can't open file %s (errno = %d)\n", "msg.c", 22LL, a1, (unsigned int)*v5);
result = 0xFFFFFFFFLL;
}
else
{
v3 = v2;
dup2(v2, 2);
dup2(v3, 1);
close(v3);
setbuf(stdout, 0LL);
setbuf(stderr, 0LL);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, const char *a2)
{
int v2; // eax
int v3; // ebp
__int64 result; // rax
int *v5; // rax
char v6[4120]; // [rsp+0h] [rbp-1018h] BYREF

snprintf(v6, 0x1000uLL, "%s%s", a1, a2);
v2 = open(v6, 1217, 420LL);
if ( v2 < 0 )
{
v5 = _errno_location();
func0("ERR: %s:%d: Can't open file %s (errno = %d)\n", "msg.c", 22LL, a1, (unsigned int)*v5);
result = 0xFFFFFFFFLL;
}
else
{
v3 = v2;
dup2(v2, 2);
dup2(v3, 1);
close(v3);
setbuf(stdout, 0LL);
setbuf(stderr, 0LL);
result = 0LL;
}
return result;
}

original_code:
int test_log_init(const char *fname, const char *suffix)
{
 char path[4096];
 int logfd;
 snprintf(path, sizeof(path), "%s%s", fname, suffix);
 logfd = open(path, 01 | 0200 | 0100 | 02000, 0644);
 if (logfd < 0) {
  test_msg("ERR: %s:%d: " "Can't open file %s" " (errno = %d)\n", "msg.c", 22, fname, (*__errno_location ()));
  return -1;
 }
 dup2(logfd, 2);
 dup2(logfd, 1);
 close(logfd);
 setbuf(stdout, ((void *)0));
 setbuf(stderr, ((void *)0));
 return 0;
}

canonical_original_code:
int test_log_init(char *fname, char *suffix)
{
 char path[4096];
 int logfd;
 snprintf(path, sizeof(path), "%s%s", fname, suffix);
 logfd = open(path, 01 | 0200 | 0100 | 02000, 0644);
 if (logfd < 0) {
  test_msg("ERR: %s:%d: " "Can't open file %s" " (errno = %d)\n", "msg.c", 22, fname, (*__errno_location ()));
  return -1;
 }
 dup2(logfd, 2);
 dup2(logfd, 1);
 close(logfd);
 setbuf(stdout, ((void *)0));
 setbuf(stderr, ((void *)0));
 return 0;
}

variable_types:
fname
char *

variable_types:
suffix
char *

variable_types:
path
char [4096]

variable_types: logfd int


decompiled_code:
__int64 __fastcall crc32_le8(int a1, unsigned __int8 a2)
{
int v2; // edx
__int64 result; // rax
unsigned int v4; // esi
bool v5; // zf

v2 = 8;
LODWORD(result) = a1 ^ a2;
do
{
v4 = ((unsigned int)result >> 1) ^ 0xEDB88320;
v5 = (result & 1) == 0;
result = (unsigned int)result >> 1;
if ( !v5 )
result = v4;
--v2;
}
while ( v2 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, unsigned __int8 a2)
{
int v2; // edx
__int64 result; // rax
unsigned int v4; // esi
bool v5; // zf

v2 = 8;
LODWORD(result) = a1 ^ a2;
do
{
v4 = ((unsigned int)result >> 1) ^ 0xEDB88320;
v5 = (result & 1) == 0;
result = (unsigned int)result >> 1;
if ( !v5 )
result = v4;
--v2;
}
while ( v2 );
return result;
}

original_code:
static inline uint32_t crc32_le8(uint32_t crc, uint8_t datum)
{
 int i;
 crc ^= datum;
 for (i = 0; i < 8; i++)
  crc = (crc >> 1) ^ ((crc & 1) ? 0xedb88320 : 0);
 return crc;
}

canonical_original_code:
static inline unsigned int crc32_le8(unsigned int crc, unsigned char datum)
{
 int i;
 crc ^= datum;
 for (i = 0; i < 8; i++)
  crc = (crc >> 1) ^ ((crc & 1) ? 0xedb88320 : 0);
 return crc;
}

variable_types:
datum
unsigned char

variable_types: i int

return_type: unsigned int


datagen

original_code:
void datagen(uint8_t *buffer, unsigned length, uint32_t *crc)
{
 uint32_t rnd = 0;
 unsigned shift;
 for (shift = 0; length-- > 4; buffer++, shift--, rnd >>= 8) {
  if (!shift) {
   shift = 4;
   rnd = mrand48();
  }
  *buffer = rnd;
  if (crc)
   *crc = crc32_le8(*crc, *buffer);
 }
 if (crc) {
  *buffer++ = *crc;
  *buffer++ = *crc >> 8;
  *buffer++ = *crc >> 16;
  *buffer++ = *crc >> 24;
 }
}

canonical_original_code:
void datagen(unsigned char *buffer, unsigned int length, unsigned int *crc)
{
 unsigned int rnd = 0;
 unsigned int shift;
 for (shift = 0; length-- > 4; buffer++, shift--, rnd >>= 8) {
  if (!shift) {
   shift = 4;
   rnd = mrand48();
  }
  *buffer = rnd;
  if (crc)
   *crc = crc32_le8(*crc, *buffer);
 }
 if (crc) {
  *buffer++ = *crc;
  *buffer++ = *crc >> 8;
  *buffer++ = *crc >> 16;
  *buffer++ = *crc >> 24;
 }
}

variable_types:
buffer
unsigned char *

variable_types:
length
unsigned int

variable_types:
crc
unsigned int *

variable_types:
rnd
unsigned int

variable_types:
shift
unsigned int


datachk

decompiled_code:
__int64 __fastcall datachk(unsigned __int8 *a1, unsigned int a2, unsigned int *a3)
{
unsigned int v4; // edi
unsigned int v5; // eax
unsigned __int8 *v6; // r10
unsigned int *v7; // r9
__int64 v8; // rsi
__int64 result; // rax

v4 = *a3;
if ( a2 <= 4 )
{
v6 = a1;
}
else
{
do
{
v5 = crc32_le8(v4, *a1);
*v7 = v5;
v4 = v5;
}
while ( v6 != a1 );
}
v8 = *(unsigned int *)v6;
result = 0LL;
if ( (_DWORD)v8 != v4 )
{
test_msg("Read: %x, Expected: %x\n", v8, v4);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int8 *a1, unsigned int a2, unsigned int *a3)
{
unsigned int v4; // edi
unsigned int v5; // eax
unsigned __int8 *v6; // r10
unsigned int *v7; // r9
__int64 v8; // rsi
__int64 result; // rax

v4 = *a3;
if ( a2 <= 4 )
{
v6 = a1;
}
else
{
do
{
v5 = func0(v4, *a1);
*v7 = v5;
v4 = v5;
}
while ( v6 != a1 );
}
v8 = *(unsigned int *)v6;
result = 0LL;
if ( (_DWORD)v8 != v4 )
{
test_msg("Read: %x, Expected: %x\n", v8, v4);
result = 1LL;
}
return result;
}

original_code:
int datachk(const uint8_t *buffer, unsigned length, uint32_t *crc)
{
 uint32_t read_crc;
 for (; length-- > 4; buffer++)
  *crc = crc32_le8(*crc, *buffer);
 read_crc = buffer[0] |
  buffer[1] << 8 |
  buffer[2] << 16 |
  buffer[3] << 24;
 if (read_crc != *crc) {
  test_msg("Read: %x, Expected: %x\n", read_crc, *crc);
  return 1;
 }
 return 0;
}

canonical_original_code:
int datachk(unsigned char *buffer, unsigned int length, unsigned int *crc)
{
 unsigned int read_crc;
 for (; length-- > 4; buffer++)
  *crc = crc32_le8(*crc, *buffer);
 read_crc = buffer[0] |
  buffer[1] << 8 |
  buffer[2] << 16 |
  buffer[3] << 24;
 if (read_crc != *crc) {
  test_msg("Read: %x, Expected: %x\n", read_crc, *crc);
  return 1;
 }
 return 0;
}


decompiled_code:
void __fastcall sig_chld_handler(unsigned int a1)
{
test_msg("Receive signal %d\n", a1);
}

canonical_decompiled_code:
void __fastcall func0(unsigned int a1)
{
test_msg("Receive signal %d\n", a1);
}

original_code:
void sig_chld_handler(int signo)
{
 test_msg("Receive signal %d\n", signo);
}

variable_types: signo int


decompiled_code:
ssize_t __fastcall sig_handler(unsigned int a1, __int64 a2)
{
ssize_t result; // rax
int *v3; // rax
int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

test_msg("receive signal sig=%d from pid=%d\n", a1, *(unsigned int *)(a2 + 16));
buf[0] = *(_DWORD *)(a2 + 16);
result = write(child_fd, buf, 4uLL);
if ( (_DWORD)result != 4 )
{
v3 = _errno_location();
result = test_msg("ERR: %s:%d: write (errno = %d)\n", "ptrace_sig.c", 24LL, (unsigned int)*v3);
}
child_exit = 1;
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func1(unsigned int a1, __int64 a2)
{
ssize_t result; // rax
int *v3; // rax
int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

test_msg("receive signal sig=%d from pid=%d\n", a1, *(unsigned int *)(a2 + 16));
buf[0] = *(_DWORD *)(a2 + 16);
result = write(child_fd, buf, 4uLL);
if ( (_DWORD)result != 4 )
{
v3 = _errno_location();
result = test_msg("ERR: %s:%d: write (errno = %d)\n", "ptrace_sig.c", 24LL, (unsigned int)*v3);
}
child_exit = 1;
return result;
}

original_code:
void sig_handler(int signo, siginfo_t *siginfo, void *data)
{
 int pid, ret;
 test_msg("receive signal sig=%d from pid=%d\n", signo, siginfo->_sifields._kill.si_pid);
 pid = siginfo->_sifields._kill.si_pid;
 ret = write(child_fd, &pid, sizeof(pid));
 if (ret != sizeof(pid))
  test_msg("ERR: %s:%d: " "write" " (errno = %d)\n", "ptrace_sig.c", 24, (*__errno_location ()));
 child_exit = 1;
}

canonical_original_code:
void sig_handler(int signo, struct siginfo_t *siginfo, void *data)
{
 int pid; int ret;
 test_msg("receive signal sig=%d from pid=%d\n", signo, siginfo->_sifields._kill.si_pid);
 pid = siginfo->_sifields._kill.si_pid;
 ret = write(child_fd, &pid, sizeof(pid));
 if (ret != sizeof(pid))
  test_msg("ERR: %s:%d: " "write" " (errno = %d)\n", "ptrace_sig.c", 24, (*__errno_location ()));
 child_exit = 1;
}

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

variable_types:
data
void *

variable_types: pid int

variable_types: ret int

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


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
unsigned int v4; // er13
int v5; // eax
unsigned int v6; // er12
int *v7; // rax
int *v9; // rax
__int64 v10; // rdx
__int64 v11; // rcx
int *v12; // rax
int *v13; // rax
int *v14; // rax
__pid_t v15; // eax
unsigned int v16; // ebp
unsigned __int8 v17; // dh
char v18; // al
unsigned int v19; // ebx
int *v20; // rax
unsigned int v21; // er14
int *v22; // rax
int *v23; // rax
int *v24; // rax
int *v25; // rax
__int64 v26; // rcx
int *v27; // rax
int *v28; // rax
int *v29; // rax
int *v30; // rax
unsigned int buf; // [rsp+Ch] [rbp-BCh] BYREF
int v32[2]; // [rsp+10h] [rbp-B8h] BYREF
int pipedes[2]; // [rsp+18h] [rbp-B0h] BYREF
char v34[16]; // [rsp+20h] [rbp-A8h] BYREF
unsigned int v35; // [rsp+30h] [rbp-98h]

buf = 0;
test_init(argc, argv, envp);
if ( pipe(pipedes) < 0 )
{
v9 = _errno_location();
v10 = 75LL;
v11 = (unsigned int)*v9;
goto LABEL_13;
}
v3 = test_fork_id(0xFFFFFFFFLL);
v4 = v3;
if ( v3 < 0 )
{
v13 = _errno_location();
v6 = 1;
test_msg("ERR: %s:%d: fork failed (errno = %d)\n", "ptrace_sig.c", 81LL, (unsigned int)*v13);
return v6;
}
if ( !v3 )
{
close(pipedes[0]);
return child(pipedes[1]);
}
close(pipedes[1]);
if ( pipe(v32) < 0 )
{
v14 = _errno_location();
v10 = 92LL;
v11 = (unsigned int)*v14;
LABEL_13:
test_msg("ERR: %s:%d: pipe failed (errno = %d)\n", "ptrace_sig.c", v10, v11);
return 1;
}
v5 = test_fork_id(0xFFFFFFFFLL);
v6 = v5;
if ( v5 < 0 )
{
v24 = _errno_location();
v6 = 1;
test_msg("ERR: %s:%d: Can't fork signal process (errno = %d)\n", "ptrace_sig.c", 98LL, (unsigned int)*v24);
return v6;
}
if ( v5 )
{
close(v32[0]);
if ( signal(17, (__sighandler_t)sig_chld_handler) == (__sighandler_t)-1LL )
{
v25 = _errno_location();
v6 = 1;
test_msg("ERR: %s:%d: signal failed (errno = %d)\n", "ptrace_sig.c", 118LL, (unsigned int)*v25);
return v6;
}
test_msg("wait while child initialized");
if ( (unsigned int)read(pipedes[0], &buf, 4uLL) != 4 )
{
v7 = _errno_location();
v6 = 1;
test_msg("ERR: %s:%d: read from child process failed\n (errno = %d)\n", "ptrace_sig.c", 125LL, (unsigned int)*v7);
return v6;
}
if ( (unsigned int)write(v32[1], &buf, 4uLL) != 4 )
{
v22 = _errno_location();
test_msg("ERR: %s:%d: write to signal process failed (errno = %d)\n", "ptrace_sig.c", 131LL, (unsigned int)*v22);
}
close(v32[1]);
test_daemon();
test_waitsig();
while ( 1 )
{
while ( 1 )
{
test_msg("waiting...\n");
v15 = wait((__WAIT_STATUS)&buf);
v16 = v15;
if ( v15 < 0 )
{
v26 = (unsigned int)*_errno_location();
if ( (_DWORD)v26 != 10 )
test_msg("ERR: %s:%d: wait (errno = %d)\n", "ptrace_sig.c", 143LL, v26);
return 0;
}
v17 = BYTE1(buf);
if ( (_BYTE)buf == 127 )
break;
if ( (buf & 0x7F) == 0 )
goto LABEL_25;
}
test_msg("pid=%d stopsig=%d\n", (unsigned int)v15, BYTE1(buf));
if ( (int)ptrace(PTRACE_GETSIGINFO, v16, 0LL, v34) < 0 )
{
v28 = _errno_location();
test_msg("ERR: %s:%d: ptrace failed (errno = %d)\n", "ptrace_sig.c", 154LL, (unsigned int)*v28);
return 1;
}
test_msg("pid=%d sends signal\n", v35);
if ( (int)ptrace(PTRACE_CONT, v16, 0LL, BYTE1(buf)) < 0 )
{
v23 = _errno_location();
test_msg("ERR: %s:%d: ptrace failed (errno = %d)\n", "ptrace_sig.c", 161LL, (unsigned int)*v23);
}
if ( (unsigned int)read(pipedes[0], &buf, 4uLL) != 4 )
{
v29 = _errno_location();
test_msg("ERR: %s:%d: read (errno = %d)\n", "ptrace_sig.c", 165LL, (unsigned int)*v29);
return 1;
}
v19 = v35;
if ( v35 == v6 )
{
v21 = buf;
if ( buf != v6 )
{
v30 = _errno_location();
test_msg("FAIL: %s:%d: %d!=%d (errno = %d)\n", "ptrace_sig.c", 174LL, v21, v6, (unsigned int)*v30);
return 1;
}
test_msg("PASS\n");
}
else
{
v20 = _errno_location();
test_msg("FAIL: %s:%d: %d!=%d (errno = %d)\n", "ptrace_sig.c", 170LL, v4, v19, (unsigned int)*v20);
}
v18 = buf;
v17 = BYTE1(buf);
if ( (buf & 0x7F) == 0 )
{
LABEL_25:
test_msg("pid = %d status = %d\n", v16, v17);
v18 = buf;
if ( BYTE1(buf) )
return 1;
}
if ( v18 == 127 )
{
test_msg("pid = %d signal = %d\n", v16, 127LL);
return 1;
}
}
}
close(v32[1]);
if ( (unsigned int)read(v32[0], &buf, 4uLL) == 4 )
{
test_msg("send signal to %d\n", v4);
if ( kill(v4, 12) >= 0 )
return 0;
v27 = _errno_location();
test_msg("ERR: %s:%d: kill failed (errno = %d)\n", "ptrace_sig.c", 110LL, (unsigned int)*v27);
}
else
{
v12 = _errno_location();
v6 = 1;
test_msg("ERR: %s:%d: read (errno = %d)\n", "ptrace_sig.c", 104LL, (unsigned int)*v12);
}
return v6;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
unsigned int v4; // er13
int v5; // eax
unsigned int v6; // er12
int *v7; // rax
int *v9; // rax
__int64 v10; // rdx
__int64 v11; // rcx
int *v12; // rax
int *v13; // rax
int *v14; // rax
__pid_t v15; // eax
unsigned int v16; // ebp
unsigned __int8 v17; // dh
char v18; // al
unsigned int v19; // ebx
int *v20; // rax
unsigned int v21; // er14
int *v22; // rax
int *v23; // rax
int *v24; // rax
int *v25; // rax
__int64 v26; // rcx
int *v27; // rax
int *v28; // rax
int *v29; // rax
int *v30; // rax
unsigned int buf; // [rsp+Ch] [rbp-BCh] BYREF
int v32[2]; // [rsp+10h] [rbp-B8h] BYREF
int pipedes[2]; // [rsp+18h] [rbp-B0h] BYREF
char v34[16]; // [rsp+20h] [rbp-A8h] BYREF
unsigned int v35; // [rsp+30h] [rbp-98h]

buf = 0;
test_init(argc, argv, envp);
if ( pipe(pipedes) < 0 )
{
v9 = _errno_location();
v10 = 75LL;
v11 = (unsigned int)*v9;
goto LABEL_13;
}
v3 = test_fork_id(0xFFFFFFFFLL);
v4 = v3;
if ( v3 < 0 )
{
v13 = _errno_location();
v6 = 1;
test_msg("ERR: %s:%d: fork failed (errno = %d)\n", "ptrace_sig.c", 81LL, (unsigned int)*v13);
return v6;
}
if ( !v3 )
{
close(pipedes[0]);
return func2(pipedes[1]);
}
close(pipedes[1]);
if ( pipe(v32) < 0 )
{
v14 = _errno_location();
v10 = 92LL;
v11 = (unsigned int)*v14;
LABEL_13:
test_msg("ERR: %s:%d: pipe failed (errno = %d)\n", "ptrace_sig.c", v10, v11);
return 1;
}
v5 = test_fork_id(0xFFFFFFFFLL);
v6 = v5;
if ( v5 < 0 )
{
v24 = _errno_location();
v6 = 1;
test_msg("ERR: %s:%d: Can't fork signal process (errno = %d)\n", "ptrace_sig.c", 98LL, (unsigned int)*v24);
return v6;
}
if ( v5 )
{
close(v32[0]);
if ( signal(17, (__sighandler_t)sig_chld_handler) == (__sighandler_t)-1LL )
{
v25 = _errno_location();
v6 = 1;
test_msg("ERR: %s:%d: signal failed (errno = %d)\n", "ptrace_sig.c", 118LL, (unsigned int)*v25);
return v6;
}
test_msg("wait while child initialized");
if ( (unsigned int)read(pipedes[0], &buf, 4uLL) != 4 )
{
v7 = _errno_location();
v6 = 1;
test_msg("ERR: %s:%d: read from child process failed\n (errno = %d)\n", "ptrace_sig.c", 125LL, (unsigned int)*v7);
return v6;
}
if ( (unsigned int)write(v32[1], &buf, 4uLL) != 4 )
{
v22 = _errno_location();
test_msg("ERR: %s:%d: write to signal process failed (errno = %d)\n", "ptrace_sig.c", 131LL, (unsigned int)*v22);
}
close(v32[1]);
test_daemon();
test_waitsig();
while ( 1 )
{
while ( 1 )
{
test_msg("waiting...\n");
v15 = wait((__WAIT_STATUS)&buf);
v16 = v15;
if ( v15 < 0 )
{
v26 = (unsigned int)*_errno_location();
if ( (_DWORD)v26 != 10 )
test_msg("ERR: %s:%d: wait (errno = %d)\n", "ptrace_sig.c", 143LL, v26);
return 0;
}
v17 = BYTE1(buf);
if ( (_BYTE)buf == 127 )
break;
if ( (buf & 0x7F) == 0 )
goto LABEL_25;
}
test_msg("pid=%d stopsig=%d\n", (unsigned int)v15, BYTE1(buf));
if ( (int)ptrace(PTRACE_GETSIGINFO, v16, 0LL, v34) < 0 )
{
v28 = _errno_location();
test_msg("ERR: %s:%d: ptrace failed (errno = %d)\n", "ptrace_sig.c", 154LL, (unsigned int)*v28);
return 1;
}
test_msg("pid=%d sends signal\n", v35);
if ( (int)ptrace(PTRACE_CONT, v16, 0LL, BYTE1(buf)) < 0 )
{
v23 = _errno_location();
test_msg("ERR: %s:%d: ptrace failed (errno = %d)\n", "ptrace_sig.c", 161LL, (unsigned int)*v23);
}
if ( (unsigned int)read(pipedes[0], &buf, 4uLL) != 4 )
{
v29 = _errno_location();
test_msg("ERR: %s:%d: read (errno = %d)\n", "ptrace_sig.c", 165LL, (unsigned int)*v29);
return 1;
}
v19 = v35;
if ( v35 == v6 )
{
v21 = buf;
if ( buf != v6 )
{
v30 = _errno_location();
test_msg("FAIL: %s:%d: %d!=%d (errno = %d)\n", "ptrace_sig.c", 174LL, v21, v6, (unsigned int)*v30);
return 1;
}
test_msg("PASS\n");
}
else
{
v20 = _errno_location();
test_msg("FAIL: %s:%d: %d!=%d (errno = %d)\n", "ptrace_sig.c", 170LL, v4, v19, (unsigned int)*v20);
}
v18 = buf;
v17 = BYTE1(buf);
if ( (buf & 0x7F) == 0 )
{
LABEL_25:
test_msg("pid = %d status = %d\n", v16, v17);
v18 = buf;
if ( BYTE1(buf) )
return 1;
}
if ( v18 == 127 )
{
test_msg("pid = %d signal = %d\n", v16, 127LL);
return 1;
}
}
}
close(v32[1]);
if ( (unsigned int)read(v32[0], &buf, 4uLL) == 4 )
{
test_msg("send signal to %d\n", v4);
if ( kill(v4, 12) >= 0 )
return 0;
v27 = _errno_location();
test_msg("ERR: %s:%d: kill failed (errno = %d)\n", "ptrace_sig.c", 110LL, (unsigned int)*v27);
}
else
{
v12 = _errno_location();
v6 = 1;
test_msg("ERR: %s:%d: read (errno = %d)\n", "ptrace_sig.c", 104LL, (unsigned int)*v12);
}
return v6;
}

original_code:
int main(int argc, char ** argv)
{
 int ret, status = 0;
 pid_t pid, spid, cpid;
 sighandler_t sh;
 int signal_pipe[2];
 int child_pipe[2];
 test_init(argc, argv);
 ret = pipe(child_pipe);
 if (ret < 0) {
  test_msg("ERR: %s:%d: " "pipe failed" " (errno = %d)\n", "ptrace_sig.c", 75, (*__errno_location ()));
  return 1;
 }
 cpid = test_fork_id(-1);
 if (cpid < 0) {
  test_msg("ERR: %s:%d: " "fork failed" " (errno = %d)\n", "ptrace_sig.c", 81, (*__errno_location ()));
  return 1;
 }
 else if (cpid == 0) {
  close(child_pipe[0]);
  return child(child_pipe[1]);
 }
 close(child_pipe[1]);
 ret = pipe(signal_pipe);
 if (ret < 0) {
  test_msg("ERR: %s:%d: " "pipe failed" " (errno = %d)\n", "ptrace_sig.c", 92, (*__errno_location ()));
  return 1;
 }
 spid = test_fork_id(-1);
 if (spid < 0) {
  test_msg("ERR: %s:%d: " "Can't fork signal process" " (errno = %d)\n", "ptrace_sig.c", 98, (*__errno_location ()));
  return 1;
 } else if (spid == 0) {
  close(signal_pipe[1]);
  ret = read(signal_pipe[0], &status, sizeof(status));
  if (ret != sizeof(status)) {
   test_msg("ERR: %s:%d: " "read" " (errno = %d)\n", "ptrace_sig.c", 104, (*__errno_location ()));
   return 1;
  }
  test_msg("send signal to %d\n", cpid);
  ret = kill(cpid, 12);
  if (ret < 0) {
   test_msg("ERR: %s:%d: " "kill failed" " (errno = %d)\n", "ptrace_sig.c", 110, (*__errno_location ()));
  }
  return 0;
 }
 close(signal_pipe[0]);
 sh = signal(17, sig_chld_handler);
 if (sh == ((__sighandler_t) -1)) {
  test_msg("ERR: %s:%d: " "signal failed" " (errno = %d)\n", "ptrace_sig.c", 118, (*__errno_location ()));
  return 1;
 }
 test_msg("wait while child initialized");
 ret = read(child_pipe[0], &status, sizeof(status));
 if (ret != sizeof(status)) {
  test_msg("ERR: %s:%d: " "read from child process failed\n" " (errno = %d)\n", "ptrace_sig.c", 125, (*__errno_location ()));
  return 1;
 }
 ret = write(signal_pipe[1], &status, sizeof(status));
 if (ret != sizeof(status)) {
  test_msg("ERR: %s:%d: " "write to signal process failed" " (errno = %d)\n", "ptrace_sig.c", 131, (*__errno_location ()));
 }
 close(signal_pipe[1]);
 test_daemon();
 test_waitsig();
 while (1) {
  test_msg("waiting...\n");
  pid = wait(&status);
  if (pid < 0) {
   if ((*__errno_location ()) != 10)
    test_msg("ERR: %s:%d: " "wait" " (errno = %d)\n", "ptrace_sig.c", 143, (*__errno_location ()));
   break;
  }
  if ((((status) & 0xff) == 0x7f)) {
   siginfo_t siginfo;
   test_msg("pid=%d stopsig=%d\n", pid, (((status) & 0xff00) >> 8));
   ret = ptrace(PTRACE_GETSIGINFO, pid, 0, &siginfo);
   if (ret < 0) {
    test_msg("ERR: %s:%d: " "ptrace failed" " (errno = %d)\n", "ptrace_sig.c", 154, (*__errno_location ()));
    return 1;
   } else
    test_msg("pid=%d sends signal\n", siginfo._sifields._kill.si_pid);
   ret = ptrace(PTRACE_CONT, pid, 0, (((status) & 0xff00) >> 8));
   if (ret < 0)
    test_msg("ERR: %s:%d: " "ptrace failed" " (errno = %d)\n", "ptrace_sig.c", 161, (*__errno_location ()));
   ret = read(child_pipe[0], &status, sizeof(status));
   if (ret != sizeof(status)) {
    test_msg("ERR: %s:%d: " "read" " (errno = %d)\n", "ptrace_sig.c", 165, (*__errno_location ()));
    return 1;
   }
   if (spid != siginfo._sifields._kill.si_pid)
    test_msg("FAIL: %s:%d: " "%d!=%d" " (errno = %d)\n", "ptrace_sig.c", 170, cpid, siginfo._sifields._kill.si_pid, (*__errno_location ()));
   else if (status == siginfo._sifields._kill.si_pid)
    test_msg("PASS\n");
   else {
    test_msg("FAIL: %s:%d: " "%d!=%d" " (errno = %d)\n", "ptrace_sig.c", 174, status, siginfo._sifields._kill.si_pid, (*__errno_location ()));
    return 1;
   }
  }
  if ((((status) & 0x7f) == 0)) {
   test_msg("pid = %d status = %d\n", pid, (((status) & 0xff00) >> 8));
   if ((((status) & 0xff00) >> 8))
    return 1;
  }
  if ((((status) & 0xff) == 0x7f)) {
   test_msg("pid = %d signal = %d\n", pid, ((status) & 0x7f));
   return 1;
  }
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int ret; int status = 0;
 int pid; int spid; int cpid;
 void (*sh)(int);
 int signal_pipe[2];
 int child_pipe[2];
 test_init(argc, argv);
 ret = pipe(child_pipe);
 if (ret < 0) {
  test_msg("ERR: %s:%d: " "pipe failed" " (errno = %d)\n", "ptrace_sig.c", 75, (*__errno_location ()));
  return 1;
 }
 cpid = test_fork_id(-1);
 if (cpid < 0) {
  test_msg("ERR: %s:%d: " "fork failed" " (errno = %d)\n", "ptrace_sig.c", 81, (*__errno_location ()));
  return 1;
 }
 else if (cpid == 0) {
  close(child_pipe[0]);
  return child(child_pipe[1]);
 }
 close(child_pipe[1]);
 ret = pipe(signal_pipe);
 if (ret < 0) {
  test_msg("ERR: %s:%d: " "pipe failed" " (errno = %d)\n", "ptrace_sig.c", 92, (*__errno_location ()));
  return 1;
 }
 spid = test_fork_id(-1);
 if (spid < 0) {
  test_msg("ERR: %s:%d: " "Can't fork signal process" " (errno = %d)\n", "ptrace_sig.c", 98, (*__errno_location ()));
  return 1;
 } else if (spid == 0) {
  close(signal_pipe[1]);
  ret = read(signal_pipe[0], &status, sizeof(status));
  if (ret != sizeof(status)) {
   test_msg("ERR: %s:%d: " "read" " (errno = %d)\n", "ptrace_sig.c", 104, (*__errno_location ()));
   return 1;
  }
  test_msg("send signal to %d\n", cpid);
  ret = kill(cpid, 12);
  if (ret < 0) {
   test_msg("ERR: %s:%d: " "kill failed" " (errno = %d)\n", "ptrace_sig.c", 110, (*__errno_location ()));
  }
  return 0;
 }
 close(signal_pipe[0]);
 sh = signal(17, sig_chld_handler);
 if (sh == ((__sighandler_t) -1)) {
  test_msg("ERR: %s:%d: " "signal failed" " (errno = %d)\n", "ptrace_sig.c", 118, (*__errno_location ()));
  return 1;
 }
 test_msg("wait while child initialized");
 ret = read(child_pipe[0], &status, sizeof(status));
 if (ret != sizeof(status)) {
  test_msg("ERR: %s:%d: " "read from child process failed\n" " (errno = %d)\n", "ptrace_sig.c", 125, (*__errno_location ()));
  return 1;
 }
 ret = write(signal_pipe[1], &status, sizeof(status));
 if (ret != sizeof(status)) {
  test_msg("ERR: %s:%d: " "write to signal process failed" " (errno = %d)\n", "ptrace_sig.c", 131, (*__errno_location ()));
 }
 close(signal_pipe[1]);
 test_daemon();
 test_waitsig();
 while (1) {
  test_msg("waiting...\n");
  pid = wait(&status);
  if (pid < 0) {
   if ((*__errno_location ()) != 10)
    test_msg("ERR: %s:%d: " "wait" " (errno = %d)\n", "ptrace_sig.c", 143, (*__errno_location ()));
   break;
  }
  if ((((status) & 0xff) == 0x7f)) {
   struct siginfo_t siginfo;
   test_msg("pid=%d stopsig=%d\n", pid, (((status) & 0xff00) >> 8));
   ret = ptrace(PTRACE_GETSIGINFO, pid, 0, &siginfo);
   if (ret < 0) {
    test_msg("ERR: %s:%d: " "ptrace failed" " (errno = %d)\n", "ptrace_sig.c", 154, (*__errno_location ()));
    return 1;
   } else
    test_msg("pid=%d sends signal\n", siginfo._sifields._kill.si_pid);
   ret = ptrace(PTRACE_CONT, pid, 0, (((status) & 0xff00) >> 8));
   if (ret < 0)
    test_msg("ERR: %s:%d: " "ptrace failed" " (errno = %d)\n", "ptrace_sig.c", 161, (*__errno_location ()));
   ret = read(child_pipe[0], &status, sizeof(status));
   if (ret != sizeof(status)) {
    test_msg("ERR: %s:%d: " "read" " (errno = %d)\n", "ptrace_sig.c", 165, (*__errno_location ()));
    return 1;
   }
   if (spid != siginfo._sifields._kill.si_pid)
    test_msg("FAIL: %s:%d: " "%d!=%d" " (errno = %d)\n", "ptrace_sig.c", 170, cpid, siginfo._sifields._kill.si_pid, (*__errno_location ()));
   else if (status == siginfo._sifields._kill.si_pid)
    test_msg("PASS\n");
   else {
    test_msg("FAIL: %s:%d: " "%d!=%d" " (errno = %d)\n", "ptrace_sig.c", 174, status, siginfo._sifields._kill.si_pid, (*__errno_location ()));
    return 1;
   }
  }
  if ((((status) & 0x7f) == 0)) {
   test_msg("pid = %d status = %d\n", pid, (((status) & 0xff00) >> 8));
   if ((((status) & 0xff00) >> 8))
    return 1;
  }
  if ((((status) & 0xff) == 0x7f)) {
   test_msg("pid = %d signal = %d\n", pid, ((status) & 0x7f));
   return 1;
  }
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: status int

variable_types: spid int

variable_types: cpid int

variable_types:
sh
void (*)(int)

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


decompiled_code:
__int64 __fastcall get_shm_seg(key_t a1, size_t a2, int a3)
{
unsigned int v3; // er12
unsigned int *v5; // rax

v3 = shmget(a1, a2, a3 | 0x1FF);
if ( v3 == -1 )
{
v5 = (unsigned int *)_errno_location();
test_msg("ERR: %s:%d: Can't get shm: %d\n (errno = %d)\n", "shm.c", 52LL, -*v5, *v5);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(key_t a1, size_t a2, int a3)
{
unsigned int v3; // er12
unsigned int *v5; // rax

v3 = shmget(a1, a2, a3 | 0x1FF);
if ( v3 == -1 )
{
v5 = (unsigned int *)_errno_location();
test_msg("ERR: %s:%d: Can't get shm: %d\n (errno = %d)\n", "shm.c", 52LL, -*v5, *v5);
}
return v3;
}

original_code:
static int get_shm_seg(int key, size_t size, unsigned int flags)
{
 int id;
 id = shmget(key, size, 0777 | flags);
 if (id == -1) {
  test_msg("ERR: %s:%d: " "Can't get shm: %d\n" " (errno = %d)\n", "shm.c", 52, -(*__errno_location ()), (*__errno_location ()));
  return -1;
 }
 return id;
}

canonical_original_code:
static int get_shm_seg(int key, unsigned long size, unsigned int flags)
{
 int id;
 id = shmget(key, size, 0777 | flags);
 if (id == -1) {
  test_msg("ERR: %s:%d: " "Can't get shm: %d\n" " (errno = %d)\n", "shm.c", 52, -(*__errno_location ()), (*__errno_location ()));
  return -1;
 }
 return id;
}

variable_types: key int

variable_types:
size
unsigned long

variable_types:
flags
unsigned int

variable_types: id int


decompiled_code:
__int64 __fastcall fill_shm_seg(int a1, unsigned int a2)
{
void *v2; // rax
const void *v3; // rbp
__int64 result; // rax
unsigned int *v5; // rax
unsigned int *v6; // rax
int v7[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v7[0] = -1;
v2 = shmat(a1, 0LL, 0);
if ( v2 == (void *)-1LL )
{
v5 = (unsigned int *)_errno_location();
test_msg("ERR: %s:%d: Can't attach shm: %d\n (errno = %d)\n", "shm.c", 33LL, -*v5, *v5);
result = 0xFFFFFFFFLL;
}
else
{
v3 = v2;
datagen(v2, a2, v7);
if ( shmdt(v3) < 0 )
{
v6 = (unsigned int *)_errno_location();
test_msg("ERR: %s:%d: Can't detach shm: %d\n (errno = %d)\n", "shm.c", 40LL, -*v6, *v6);
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, unsigned int a2)
{
void *v2; // rax
const void *v3; // rbp
__int64 result; // rax
unsigned int *v5; // rax
unsigned int *v6; // rax
int v7[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v7[0] = -1;
v2 = shmat(a1, 0LL, 0);
if ( v2 == (void *)-1LL )
{
v5 = (unsigned int *)_errno_location();
test_msg("ERR: %s:%d: Can't attach shm: %d\n (errno = %d)\n", "shm.c", 33LL, -*v5, *v5);
result = 0xFFFFFFFFLL;
}
else
{
v3 = v2;
datagen(v2, a2, v7);
if ( shmdt(v3) < 0 )
{
v6 = (unsigned int *)_errno_location();
test_msg("ERR: %s:%d: Can't detach shm: %d\n (errno = %d)\n", "shm.c", 40LL, -*v6, *v6);
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
static int fill_shm_seg(int id, size_t size)
{
 uint8_t *mem;
 uint32_t crc = (~0);
 mem = shmat(id, ((void *)0), 0);
 if (mem == (void *)-1) {
  test_msg("ERR: %s:%d: " "Can't attach shm: %d\n" " (errno = %d)\n", "shm.c", 33, -(*__errno_location ()), (*__errno_location ()));
  return -1;
 }
 datagen(mem, size, &crc);
 if (shmdt(mem) < 0) {
  test_msg("ERR: %s:%d: " "Can't detach shm: %d\n" " (errno = %d)\n", "shm.c", 40, -(*__errno_location ()), (*__errno_location ()));
  return -1;
 }
 return 0;
}

canonical_original_code:
static int fill_shm_seg(int id, unsigned long size)
{
 unsigned char *mem;
 unsigned int crc = (~0);
 mem = shmat(id, ((void *)0), 0);
 if (mem == (void *)-1) {
  test_msg("ERR: %s:%d: " "Can't attach shm: %d\n" " (errno = %d)\n", "shm.c", 33, -(*__errno_location ()), (*__errno_location ()));
  return -1;
 }
 datagen(mem, size, &crc);
 if (shmdt(mem) < 0) {
  test_msg("ERR: %s:%d: " "Can't detach shm: %d\n" " (errno = %d)\n", "shm.c", 40, -(*__errno_location ()), (*__errno_location ()));
  return -1;
 }
 return 0;
}

variable_types:
mem
unsigned char *

variable_types:
crc
unsigned int


decompiled_code:
__int64 __fastcall check_shm_id(int a1, unsigned int a2)
{
void *v2; // rax
const void *v3; // rbp
unsigned int v4; // er12
int *v6; // rax
unsigned int *v7; // rax
unsigned int *v8; // rax
int v9[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v9[0] = -1;
v2 = shmat(a1, 0LL, 0);
if ( v2 == (void *)-1LL )
{
v7 = (unsigned int *)_errno_location();
v4 = -1;
test_msg("ERR: %s:%d: Can't attach shm: %d\n (errno = %d)\n", "shm.c", 78LL, -*v7, *v7);
}
else
{
v3 = v2;
v9[0] = -1;
v4 = datachk(v2, a2, v9);
if ( v4 )
{
v6 = _errno_location();
v4 = -1;
test_msg("FAIL: %s:%d: shmem data are corrupted (errno = %d)\n", "shm.c", 83LL, (unsigned int)*v6);
}
else if ( shmdt(v3) < 0 )
{
v8 = (unsigned int *)_errno_location();
v4 = -1;
test_msg("ERR: %s:%d: Can't detach shm: %d\n (errno = %d)\n", "shm.c", 87LL, -*v8, *v8);
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, unsigned int a2)
{
void *v2; // rax
const void *v3; // rbp
unsigned int v4; // er12
int *v6; // rax
unsigned int *v7; // rax
unsigned int *v8; // rax
int v9[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v9[0] = -1;
v2 = shmat(a1, 0LL, 0);
if ( v2 == (void *)-1LL )
{
v7 = (unsigned int *)_errno_location();
v4 = -1;
test_msg("ERR: %s:%d: Can't attach shm: %d\n (errno = %d)\n", "shm.c", 78LL, -*v7, *v7);
}
else
{
v3 = v2;
v9[0] = -1;
v4 = datachk(v2, a2, v9);
if ( v4 )
{
v6 = _errno_location();
v4 = -1;
test_msg("FAIL: %s:%d: shmem data are corrupted (errno = %d)\n", "shm.c", 83LL, (unsigned int)*v6);
}
else if ( shmdt(v3) < 0 )
{
v8 = (unsigned int *)_errno_location();
v4 = -1;
test_msg("ERR: %s:%d: Can't detach shm: %d\n (errno = %d)\n", "shm.c", 87LL, -*v8, *v8);
}
}
return v4;
}

original_code:
static int check_shm_id(int id, size_t size)
{
 uint8_t *mem;
 uint32_t crc = (~0);
 mem = shmat(id, ((void *)0), 0);
 if (mem == (void *)-1) {
  test_msg("ERR: %s:%d: " "Can't attach shm: %d\n" " (errno = %d)\n", "shm.c", 78, -(*__errno_location ()), (*__errno_location ()));
  return -1;
 }
 crc = (~0);
 if (datachk(mem, size, &crc)) {
  test_msg("FAIL: %s:%d: " "shmem data are corrupted" " (errno = %d)\n", "shm.c", 83, (*__errno_location ()));
  return -1;
 }
 if (shmdt(mem) < 0) {
  test_msg("ERR: %s:%d: " "Can't detach shm: %d\n" " (errno = %d)\n", "shm.c", 87, -(*__errno_location ()), (*__errno_location ()));
  return -1;
 }
 return 0;
}

canonical_original_code:
static int check_shm_id(int id, unsigned long size)
{
 unsigned char *mem;
 unsigned int crc = (~0);
 mem = shmat(id, ((void *)0), 0);
 if (mem == (void *)-1) {
  test_msg("ERR: %s:%d: " "Can't attach shm: %d\n" " (errno = %d)\n", "shm.c", 78, -(*__errno_location ()), (*__errno_location ()));
  return -1;
 }
 crc = (~0);
 if (datachk(mem, size, &crc)) {
  test_msg("FAIL: %s:%d: " "shmem data are corrupted" " (errno = %d)\n", "shm.c", 83, (*__errno_location ()));
  return -1;
 }
 if (shmdt(mem) < 0) {
  test_msg("ERR: %s:%d: " "Can't detach shm: %d\n" " (errno = %d)\n", "shm.c", 87, -(*__errno_location ()), (*__errno_location ()));
  return -1;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall check_shm_key(key_t a1, size_t a2)
{
int v2; // eax
__int64 result; // rax

v2 = get_shm_seg(a1, a2, 0);
if ( v2 < 0 )
result = 0xFFFFFFFFLL;
else
result = check_shm_id(v2, a2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(key_t a1, size_t a2)
{
int v2; // eax
__int64 result; // rax

v2 = func0(a1, a2, 0);
if ( v2 < 0 )
result = 0xFFFFFFFFLL;
else
result = func2(v2, a2);
return result;
}

original_code:
static int check_shm_key(int key, size_t size)
{
 int id;
 id = get_shm_seg(key, size, 0);
 if (id < 0)
  return -1;
 return check_shm_id(id, size);
}

canonical_original_code:
static int check_shm_key(int key, unsigned long size)
{
 int id;
 id = get_shm_seg(key, size, 0);
 if (id < 0)
  return -1;
 return check_shm_id(id, size);
}