decompiled_code:
__int64 __fastcall test_fn(__int64 a1, const char **a2)
{
key_t v2; // eax
key_t v3; // er13
int v4; // ebp
int v5; // er12
int v6; // eax
int *v8; // rax
unsigned int *v9; // rax
unsigned int *v10; // rax
int *v11; // rax
int *v12; // rax
int *v13; // rax
int *v14; // rax
int *v15; // rax

v2 = ftok(*a2, 822155666);
if ( v2 == -1 )
{
v15 = _errno_location();
v5 = -1;
test_msg("ERR: %s:%d: Can't make key (errno = %d)\n", "shm.c", 112LL, (unsigned int)*v15);
return (unsigned int)v5;
}
v3 = v2;
v4 = prepare_shm_constprop_0(v2);
if ( v4 == -1 )
{
v14 = _errno_location();
v5 = -1;
test_msg("ERR: %s:%d: Can't prepare shm (1) (errno = %d)\n", "shm.c", 118LL, (unsigned int)*v14);
return (unsigned int)v5;
}
test_daemon();
test_waitsig();
if ( (int)check_shm_id(v4, shmem_size) < 0 )
{
v8 = _errno_location();
test_msg("FAIL: %s:%d: ID check (1) failed\n (errno = %d)\n", "shm.c", 127LL, (unsigned int)*v8);
goto LABEL_12;
}
if ( (int)check_shm_key(v3, (unsigned int)shmem_size) < 0 )
{
v11 = _errno_location();
test_msg("FAIL: %s:%d: KEY check failed\n (errno = %d)\n", "shm.c", 134LL, (unsigned int)*v11);
goto LABEL_12;
}
v5 = shmctl(v4, 0, 0LL);
if ( v5 < 0 )
{
v10 = (unsigned int *)_errno_location();
test_msg("FAIL: %s:%d: Failed (1) to destroy segment: %d\n (errno = %d)\n", "shm.c", 141LL, -*v10, *v10);
goto LABEL_12;
}
v6 = prepare_shm_constprop_0(v3);
v4 = v6;
if ( v6 == -1 )
{
v12 = _errno_location();
test_msg("FAIL: %s:%d: Can't prepare shm (2) (errno = %d)\n", "shm.c", 151LL, (unsigned int)*v12);
return (unsigned int)v5;
}
if ( (int)check_shm_id(v6, shmem_size) < 0 )
{
v13 = _errno_location();
test_msg("FAIL: %s:%d: ID check (2) failed\n (errno = %d)\n", "shm.c", 158LL, (unsigned int)*v13);
LABEL_12:
v5 = shmctl(v4, 0, 0LL);
if ( v5 >= 0 )
return (unsigned int)v5;
goto LABEL_13;
}
v5 = shmctl(v4, 0, 0LL);
if ( v5 >= 0 )
{
test_msg("PASS\n");
return (unsigned int)v5;
}
LABEL_13:
v9 = (unsigned int *)_errno_location();
test_msg("FAIL: %s:%d: Failed (2) to destroy segment: %d\n (errno = %d)\n", "shm.c", 166LL, -*v9, *v9);
return (unsigned int)v5;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, const char **a2)
{
key_t v2; // eax
key_t v3; // er13
int v4; // ebp
int v5; // er12
int v6; // eax
int *v8; // rax
unsigned int *v9; // rax
unsigned int *v10; // rax
int *v11; // rax
int *v12; // rax
int *v13; // rax
int *v14; // rax
int *v15; // rax

v2 = ftok(*a2, 822155666);
if ( v2 == -1 )
{
v15 = _errno_location();
v5 = -1;
test_msg("ERR: %s:%d: Can't make key (errno = %d)\n", "shm.c", 112LL, (unsigned int)*v15);
return (unsigned int)v5;
}
v3 = v2;
v4 = func4(v2);
if ( v4 == -1 )
{
v14 = _errno_location();
v5 = -1;
test_msg("ERR: %s:%d: Can't prepare shm (1) (errno = %d)\n", "shm.c", 118LL, (unsigned int)*v14);
return (unsigned int)v5;
}
test_daemon();
test_waitsig();
if ( (int)func2(v4, shmem_size) < 0 )
{
v8 = _errno_location();
test_msg("FAIL: %s:%d: ID check (1) failed\n (errno = %d)\n", "shm.c", 127LL, (unsigned int)*v8);
goto LABEL_12;
}
if ( (int)func3(v3, (unsigned int)shmem_size) < 0 )
{
v11 = _errno_location();
test_msg("FAIL: %s:%d: KEY check failed\n (errno = %d)\n", "shm.c", 134LL, (unsigned int)*v11);
goto LABEL_12;
}
v5 = shmctl(v4, 0, 0LL);
if ( v5 < 0 )
{
v10 = (unsigned int *)_errno_location();
test_msg("FAIL: %s:%d: Failed (1) to destroy segment: %d\n (errno = %d)\n", "shm.c", 141LL, -*v10, *v10);
goto LABEL_12;
}
v6 = func4(v3);
v4 = v6;
if ( v6 == -1 )
{
v12 = _errno_location();
test_msg("FAIL: %s:%d: Can't prepare shm (2) (errno = %d)\n", "shm.c", 151LL, (unsigned int)*v12);
return (unsigned int)v5;
}
if ( (int)func2(v6, shmem_size) < 0 )
{
v13 = _errno_location();
test_msg("FAIL: %s:%d: ID check (2) failed\n (errno = %d)\n", "shm.c", 158LL, (unsigned int)*v13);
LABEL_12:
v5 = shmctl(v4, 0, 0LL);
if ( v5 >= 0 )
return (unsigned int)v5;
goto LABEL_13;
}
v5 = shmctl(v4, 0, 0LL);
if ( v5 >= 0 )
{
test_msg("PASS\n");
return (unsigned int)v5;
}
LABEL_13:
v9 = (unsigned int *)_errno_location();
test_msg("FAIL: %s:%d: Failed (2) to destroy segment: %d\n (errno = %d)\n", "shm.c", 166LL, -*v9, *v9);
return (unsigned int)v5;
}

original_code:
static int test_fn(int argc, char **argv)
{
 key_t key;
 int shm;
 int fail_count = 0;
 int ret = -1;
 key = ftok(argv[0], 822155666);
 if (key == -1) {
  test_msg("ERR: %s:%d: " "Can't make key" " (errno = %d)\n", "shm.c", 112, (*__errno_location ()));
  goto out;
 }
 shm = prepare_shm(key, shmem_size);
 if (shm == -1) {
  test_msg("ERR: %s:%d: " "Can't prepare shm (1)" " (errno = %d)\n", "shm.c", 118, (*__errno_location ()));
  goto out;
 }
 test_daemon();
 test_waitsig();
 ret = check_shm_id(shm, shmem_size);
 if (ret < 0) {
  test_msg("FAIL: %s:%d: " "ID check (1) failed\n" " (errno = %d)\n", "shm.c", 127, (*__errno_location ()));
  fail_count++;
  goto out_shm;
 }
 ret = check_shm_key(key, shmem_size);
 if (ret < 0) {
  test_msg("FAIL: %s:%d: " "KEY check failed\n" " (errno = %d)\n", "shm.c", 134, (*__errno_location ()));
  fail_count++;
  goto out_shm;
 }
 ret = shmctl(shm, 0, ((void *)0));
 if (ret < 0) {
  test_msg("FAIL: %s:%d: " "Failed (1) to destroy segment: %d\n" " (errno = %d)\n", "shm.c", 141, -(*__errno_location ()), (*__errno_location ()));
  fail_count++;
  goto out_shm;
 }
 shm = prepare_shm(key, shmem_size);
 if (shm == -1) {
  test_msg("FAIL: %s:%d: " "Can't prepare shm (2)" " (errno = %d)\n", "shm.c", 151, (*__errno_location ()));
  fail_count++;
  goto out;
 }
 ret = check_shm_id(shm, shmem_size);
 if (ret < 0) {
  test_msg("FAIL: %s:%d: " "ID check (2) failed\n" " (errno = %d)\n", "shm.c", 158, (*__errno_location ()));
  fail_count++;
  goto out_shm;
 }
out_shm:
 ret = shmctl(shm, 0, ((void *)0));
 if (ret < 0) {
  test_msg("FAIL: %s:%d: " "Failed (2) to destroy segment: %d\n" " (errno = %d)\n", "shm.c", 166, -(*__errno_location ()), (*__errno_location ()));
  fail_count++;
 }
 if (fail_count == 0)
  test_msg("PASS\n");
out:
 return ret;
}

canonical_original_code:
static int test_fn(int argc, char **argv)
{
 int key;
 int shm;
 int fail_count = 0;
 int ret = -1;
 key = ftok(argv[0], 822155666);
 if (key == -1) {
  test_msg("ERR: %s:%d: " "Can't make key" " (errno = %d)\n", "shm.c", 112, (*__errno_location ()));
  goto out;
 }
 shm = prepare_shm(key, shmem_size);
 if (shm == -1) {
  test_msg("ERR: %s:%d: " "Can't prepare shm (1)" " (errno = %d)\n", "shm.c", 118, (*__errno_location ()));
  goto out;
 }
 test_daemon();
 test_waitsig();
 ret = check_shm_id(shm, shmem_size);
 if (ret < 0) {
  test_msg("FAIL: %s:%d: " "ID check (1) failed\n" " (errno = %d)\n", "shm.c", 127, (*__errno_location ()));
  fail_count++;
  goto out_shm;
 }
 ret = check_shm_key(key, shmem_size);
 if (ret < 0) {
  test_msg("FAIL: %s:%d: " "KEY check failed\n" " (errno = %d)\n", "shm.c", 134, (*__errno_location ()));
  fail_count++;
  goto out_shm;
 }
 ret = shmctl(shm, 0, ((void *)0));
 if (ret < 0) {
  test_msg("FAIL: %s:%d: " "Failed (1) to destroy segment: %d\n" " (errno = %d)\n", "shm.c", 141, -(*__errno_location ()), (*__errno_location ()));
  fail_count++;
  goto out_shm;
 }
 shm = prepare_shm(key, shmem_size);
 if (shm == -1) {
  test_msg("FAIL: %s:%d: " "Can't prepare shm (2)" " (errno = %d)\n", "shm.c", 151, (*__errno_location ()));
  fail_count++;
  goto out;
 }
 ret = check_shm_id(shm, shmem_size);
 if (ret < 0) {
  test_msg("FAIL: %s:%d: " "ID check (2) failed\n" " (errno = %d)\n", "shm.c", 158, (*__errno_location ()));
  fail_count++;
  goto out_shm;
 }
out_shm:
 ret = shmctl(shm, 0, ((void *)0));
 if (ret < 0) {
  test_msg("FAIL: %s:%d: " "Failed (2) to destroy segment: %d\n" " (errno = %d)\n", "shm.c", 166, -(*__errno_location ()), (*__errno_location ()));
  fail_count++;
 }
 if (fail_count == 0)
  test_msg("PASS\n");
out:
 return ret;
}

variable_types: shm int


main

canonical_name: main

repo: OSLL/pmover

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

variable_types: argc int

variable_types:
argv
char **

return_type: int


decompiled_code:
__int64 __fastcall test_sockaddr(unsigned int a1, __int16 *a2, __int16 *a3)
{
unsigned __int16 v3; // bx
unsigned __int16 v4; // bp
unsigned __int16 v5; // bx
unsigned __int16 v6; // bp
unsigned int v7; // ebx
unsigned int v8; // ebp
__int64 result; // rax
int *v10; // rax
int *v11; // rax
int *v12; // rax

v3 = *a2;
v4 = *a3;
if ( *a2 == *a3 )
{
v5 = a2[1];
v6 = a3[1];
if ( v5 == v6 )
{
v7 = *((_DWORD *)a2 + 1);
v8 = *((_DWORD *)a3 + 1);
result = 0LL;
if ( v7 != v8 )
{
v12 = _errno_location();
test_msg(
"FAIL: %s:%d: %d Index mismatch %d/%d (errno = %d)\n",
"packet_sock.c",
49LL,
a1,
v7,
v8,
(unsigned int)*v12);
result = 1LL;
}
}
else
{
v10 = _errno_location();
test_msg(
"FAIL: %s:%d: %d Proto mismatch %d/%d (errno = %d)\n",
"packet_sock.c",
43LL,
a1,
v5,
v6,
(unsigned int)*v10);
result = 1LL;
}
}
else
{
v11 = _errno_location();
test_msg(
"FAIL: %s:%d: %d Family mismatch %d/%d (errno = %d)\n",
"packet_sock.c",
37LL,
a1,
v3,
v4,
(unsigned int)*v11);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, __int16 *a2, __int16 *a3)
{
unsigned __int16 v3; // bx
unsigned __int16 v4; // bp
unsigned __int16 v5; // bx
unsigned __int16 v6; // bp
unsigned int v7; // ebx
unsigned int v8; // ebp
__int64 result; // rax
int *v10; // rax
int *v11; // rax
int *v12; // rax

v3 = *a2;
v4 = *a3;
if ( *a2 == *a3 )
{
v5 = a2[1];
v6 = a3[1];
if ( v5 == v6 )
{
v7 = *((_DWORD *)a2 + 1);
v8 = *((_DWORD *)a3 + 1);
result = 0LL;
if ( v7 != v8 )
{
v12 = _errno_location();
test_msg(
"FAIL: %s:%d: %d Index mismatch %d/%d (errno = %d)\n",
"packet_sock.c",
49LL,
a1,
v7,
v8,
(unsigned int)*v12);
result = 1LL;
}
}
else
{
v10 = _errno_location();
test_msg(
"FAIL: %s:%d: %d Proto mismatch %d/%d (errno = %d)\n",
"packet_sock.c",
43LL,
a1,
v5,
v6,
(unsigned int)*v10);
result = 1LL;
}
}
else
{
v11 = _errno_location();
test_msg(
"FAIL: %s:%d: %d Family mismatch %d/%d (errno = %d)\n",
"packet_sock.c",
37LL,
a1,
v3,
v4,
(unsigned int)*v11);
result = 1LL;
}
return result;
}

original_code:
static int test_sockaddr(int n, struct sockaddr_ll *have, struct sockaddr_ll *want)
{
 if (have->sll_family != want->sll_family) {
  test_msg("FAIL: %s:%d: " "%d Family mismatch %d/%d" " (errno = %d)\n", "packet_sock.c", 37, n, (int)have->sll_family, (int)want->sll_family, (*__errno_location ()));
  return 1;
 }
 if (have->sll_protocol != want->sll_protocol) {
  test_msg("FAIL: %s:%d: " "%d Proto mismatch %d/%d" " (errno = %d)\n", "packet_sock.c", 43, n, (int)have->sll_protocol, (int)want->sll_protocol, (*__errno_location ()));
  return 1;
 }
 if (have->sll_ifindex != want->sll_ifindex) {
  test_msg("FAIL: %s:%d: " "%d Index mismatch %d/%d" " (errno = %d)\n", "packet_sock.c", 49, n, have->sll_ifindex, want->sll_ifindex, (*__errno_location ()));
  return 1;
 }
 return 0;
}

variable_types: n int

variable_types: struct sockaddr_ll { unsigned short sll_family; unsigned short sll_protocol; int sll_ifindex; unsigned short sll_hatype; unsigned char sll_pkttype; unsigned char sll_halen; unsigned char sll_addr[8]; } *

variable_types:
want
struct sockaddr_ll *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebp
unsigned __int16 v5; // ax
int v6; // er12
__int64 v7; // rcx
struct sockaddr *v8; // rdi
__int64 v9; // rcx
char *v10; // rdi
__int64 v11; // rcx
__int64 *v12; // rdi
__int64 v13; // rcx
char *v14; // rdi
__int64 v15; // rcx
char *v16; // rdi
unsigned int v17; // er15
int *v18; // rax
__int64 v19; // rcx
int v20; // er15
int *v21; // rax
int *v23; // rax
int *v24; // rax
int *v25; // rax
int *v26; // rax
int *v27; // rax
int *v28; // rax
int *v29; // rax
int *v30; // rax
int *v31; // rax
int *v32; // rax
int *v33; // rax
int *v34; // rax
int *v35; // rax
int *v36; // rax
int *v37; // rax
int *v38; // rax
__int64 v39; // rcx
__int64 *v40; // rdi
unsigned int v41; // ebx
int v42; // ebx
unsigned int v43; // er13
int *v44; // rax
int *v45; // rax
int *v46; // rax
int *v47; // rax
int *v48; // rax
int *v49; // rax
int *v50; // rax
__int64 v51; // rcx
char *v52; // rdi
unsigned int v53; // er12
int *v54; // rax
int *v55; // rax
int *v56; // rax
int *v57; // rax
int *v58; // rax
socklen_t v59; // [rsp+0h] [rbp-F8h] BYREF
unsigned int optval; // [rsp+4h] [rbp-F4h] BYREF
unsigned int v61; // [rsp+8h] [rbp-F0h] BYREF
int v62; // [rsp+Ch] [rbp-ECh] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-E8h] BYREF
struct sockaddr v64; // [rsp+30h] [rbp-C8h] BYREF
struct sockaddr v65; // [rsp+50h] [rbp-A8h] BYREF
__int64 v66; // [rsp+70h] [rbp-88h] BYREF
__int64 v67; // [rsp+78h] [rbp-80h]
char v68[16]; // [rsp+80h] [rbp-78h] BYREF
__int64 v69; // [rsp+90h] [rbp-68h] BYREF
char v70[96]; // [rsp+98h] [rbp-60h] BYREF

test_init(argc, argv, envp);
v3 = socket(17, 3, 0);
if ( v3 < 0 )
{
v21 = _errno_location();
v20 = 1;
test_msg("ERR: %s:%d: Can't create socket 1 (errno = %d)\n", "packet_sock.c", 98LL, (unsigned int)*v21);
return v20;
}
v4 = v3;
v5 = _bswap_16_constprop_0(17LL, 2LL);
v6 = socket(17, 2, v5);
if ( v6 < 0 )
{
v25 = _errno_location();
v20 = 1;
test_msg("ERR: %s:%d: Can't create socket 2 (errno = %d)\n", "packet_sock.c", 104LL, (unsigned int)*v25);
return v20;
}
v7 = 5LL;
v8 = &addr;
while ( v7 )
{
*(_DWORD *)&v8->sa_family = 0;
v8 = (struct sockaddr *)((char *)v8 + 4);
--v7;
}
addr.sa_family = 17;
*(_DWORD *)&addr.sa_data[2] = 1;
if ( bind(v6, &addr, 0x14u) < 0 )
{
v23 = _errno_location();
v20 = 1;
test_msg("ERR: %s:%d: Can't bind socket %m (errno = %d)\n", "packet_sock.c", 112LL, (unsigned int)*v23);
return v20;
}
v59 = 20;
if ( getsockname(v4, &v64, &v59) < 0 )
{
v26 = _errno_location();
v20 = 1;
test_msg("ERR: %s:%d: Can't get sockname 1 (errno = %d)\n", "packet_sock.c", 118LL, (unsigned int)*v26);
return v20;
}
v59 = 20;
if ( getsockname(v6, &v65, &v59) < 0 )
{
v27 = _errno_location();
v20 = 1;
test_msg("ERR: %s:%d: Can't get sockname 2 (errno = %d)\n", "packet_sock.c", 124LL, (unsigned int)*v27);
return v20;
}
optval = 1;
if ( setsockopt(v4, 263, 10, &optval, 4u) < 0 )
{
v24 = _errno_location();
v20 = 1;
test_msg("ERR: %s:%d: Can't set version %m (errno = %d)\n", "packet_sock.c", 130LL, (unsigned int)*v24);
return v20;
}
v62 = 1;
if ( setsockopt(v4, 263, 8, &v62, 4u) < 0 )
{
v29 = _errno_location();
v20 = 1;
test_msg("ERR: %s:%d: Can't set auxdata %m (errno = %d)\n", "packet_sock.c", 136LL, (unsigned int)*v29);
return v20;
}
v9 = 3LL;
v10 = v68;
while ( v9 )
{
*(_DWORD *)v10 = 0;
v10 += 4;
--v9;
}
v66 = 0x100001000LL;
v67 = 0x400000400LL;
if ( setsockopt(v4, 263, 5, &v66, 0x1Cu) < 0 )
{
v30 = _errno_location();
v20 = 1;
test_msg("ERR: %s:%d: Can't set rx ring %m (errno = %d)\n", "packet_sock.c", 146LL, (unsigned int)*v30);
return v20;
}
v61 = 8;
if ( setsockopt(v6, 263, 12, &v61, 4u) < 0 )
{
v31 = _errno_location();
v20 = 1;
test_msg("ERR: %s:%d: Can't set reserve %m (errno = %d)\n", "packet_sock.c", 152LL, (unsigned int)*v31);
return v20;
}
v62 = 1;
if ( setsockopt(v6, 263, 9, &v62, 4u) < 0 )
{
v28 = _errno_location();
v20 = 1;
test_msg("ERR: %s:%d: Can't set origdev %m (errno = %d)\n", "packet_sock.c", 158LL, (unsigned int)*v28);
return v20;
}
v62 = 13;
if ( setsockopt(v6, 263, 18, &v62, 4u) < 0 )
{
v32 = _errno_location();
v20 = 1;
test_msg("ERR: %s:%d: Can't configure fanout %m (errno = %d)\n", "packet_sock.c", 164LL, (unsigned int)*v32);
return v20;
}
v11 = 10LL;
v12 = &v69;
while ( v11 )
{
*(_DWORD *)v12 = 0;
v12 = (__int64 *)((char *)v12 + 4);
--v11;
}
LODWORD(v69) = 1;
WORD2(v69) = 1;
if ( setsockopt(v4, 263, 1, &v69, 0x28u) < 0 )
{
v33 = _errno_location();
v20 = 1;
test_msg("ERR: %s:%d: Can't add promisc member %m (errno = %d)\n", "packet_sock.c", 172LL, (unsigned int)*v33);
return v20;
}
v13 = 8LL;
v14 = v70;
while ( v13 )
{
*(_DWORD *)v14 = 0;
v14 += 4;
--v13;
}
v69 = 0x6000300000001LL;
if ( setsockopt(v6, 263, 1, &v69, 0x28u) < 0 )
{
v34 = _errno_location();
v20 = 1;
test_msg("ERR: %s:%d: Can't add ucast member %m (errno = %d)\n", "packet_sock.c", 181LL, (unsigned int)*v34);
return v20;
}
v15 = 3LL;
v16 = v68;
while ( v15 )
{
*(_DWORD *)v16 = 0;
v16 += 4;
--v15;
}
v66 = 0x100001000LL;
v67 = 0x400000400LL;
if ( setsockopt(v6, 263, 13, &v66, 0x1Cu) < 0 )
{
v36 = _errno_location();
v20 = 1;
test_msg("ERR: %s:%d: Can't set tx ring %m (errno = %d)\n", "packet_sock.c", 191LL, (unsigned int)*v36);
return v20;
}
test_daemon();
test_waitsig();
v59 = 20;
if ( getsockname(v4, &addr, &v59) < 0 )
{
v37 = _errno_location();
v20 = 1;
test_msg("FAIL: %s:%d: Can't get sockname 1 rst (errno = %d)\n", "packet_sock.c", 200LL, (unsigned int)*v37);
return v20;
}
if ( (unsigned int)test_sockaddr(1u, (__int16 *)&addr, (__int16 *)&v64) )
return 1;
v59 = 4;
if ( getsockopt(v4, 263, 10, &optval, &v59) < 0 )
{
v45 = _errno_location();
v20 = 1;
test_msg("FAIL: %s:%d: Can't get sockopt ver %m (errno = %d)\n", "packet_sock.c", 209LL, (unsigned int)*v45);
return v20;
}
v17 = optval;
if ( optval != 1 )
{
v18 = _errno_location();
v19 = v17;
v20 = 1;
test_msg(
"FAIL: %s:%d: Version mismatch have %d, want %d\n (errno = %d)\n",
"packet_sock.c",
214LL,
v19,
1LL,
(unsigned int)*v18);
return v20;
}
v59 = 4;
if ( getsockopt(v4, 263, 8, &v62, &v59) < 0 )
{
v46 = _errno_location();
v20 = 1;
test_msg("FAIL: %s:%d: Can't get sockopt auxdata %m (errno = %d)\n", "packet_sock.c", 220LL, (unsigned int)*v46);
return v20;
}
v20 = v62;
if ( v62 != 1 )
{
v38 = _errno_location();
v20 = 1;
test_msg("FAIL: %s:%d: Auxdata not ON (errno = %d)\n", "packet_sock.c", 225LL, (unsigned int)*v38);
return v20;
}
v39 = 10LL;
v40 = &v69;
while ( v39 )
{
*(_DWORD *)v40 = 0;
v40 = (__int64 *)((char *)v40 + 4);
--v39;
}
LODWORD(v69) = 1;
WORD2(v69) = 1;
if ( setsockopt(v4, 263, 2, &v69, 0x28u) < 0 )
{
v48 = _errno_location();
test_msg("FAIL: %s:%d: Promisc member not kept (errno = %d)\n", "packet_sock.c", 233LL, (unsigned int)*v48);
return v20;
}
v59 = 4;
if ( getsockopt(v4, 263, 18, &v62, &v59) < 0 )
{
v50 = _errno_location();
test_msg("FAIL: %s:%d: Can't read fanout back %m (errno = %d)\n", "packet_sock.c", 239LL, (unsigned int)*v50);
return v20;
}
v41 = v62;
if ( v62 )
{
v47 = _errno_location();
test_msg("FAIL: %s:%d: Fanout screwed up to %x (errno = %d)\n", "packet_sock.c", 244LL, v41, (unsigned int)*v47);
return v20;
}
v59 = 20;
if ( getsockname(v6, &addr, &v59) < 0 )
{
v49 = _errno_location();
test_msg("FAIL: %s:%d: Can't get sockname 2 rst (errno = %d)\n", "packet_sock.c", 250LL, (unsigned int)*v49);
return v20;
}
v42 = test_sockaddr(2u, (__int16 *)&addr, (__int16 *)&v65);
if ( v42 )
return 1;
v59 = 4;
if ( getsockopt(v6, 263, 12, &v61, &v59) < 0 )
{
v58 = _errno_location();
test_msg("FAIL: %s:%d: Can't get sockopt rsv %m (errno = %d)\n", "packet_sock.c", 259LL, (unsigned int)*v58);
return v20;
}
v59 = 4;
if ( getsockopt(v6, 263, 9, &v62, &v59) < 0 )
{
v57 = _errno_location();
test_msg("FAIL: %s:%d: Can't get sockopt origdev %m (errno = %d)\n", "packet_sock.c", 265LL, (unsigned int)*v57);
return v20;
}
if ( v62 != 1 )
{
v55 = _errno_location();
test_msg("FAIL: %s:%d: OrigDev not ON (errno = %d)\n", "packet_sock.c", 270LL, (unsigned int)*v55);
return v20;
}
v43 = v61;
if ( v61 != 8 )
{
v44 = _errno_location();
v20 = 1;
test_msg(
"FAIL: %s:%d: Reserve mismatch have %d, want %d\n (errno = %d)\n",
"packet_sock.c",
275LL,
v43,
8LL,
(unsigned int)*v44);
return v20;
}
v51 = 8LL;
v52 = v70;
while ( v51 )
{
*(_DWORD *)v52 = v42;
v52 += 4;
--v51;
}
v69 = 0x6000300000001LL;
if ( setsockopt(v6, 263, 2, &v69, 0x28u) < 0 )
{
v56 = _errno_location();
v20 = 1;
test_msg("FAIL: %s:%d: Ucast member not kept (errno = %d)\n", "packet_sock.c", 284LL, (unsigned int)*v56);
return v20;
}
v59 = 4;
if ( getsockopt(v6, 263, 18, &v62, &v59) < 0 )
{
v35 = _errno_location();
test_msg("FAIL: %s:%d: Can't read fanout2 back %m (errno = %d)\n", "packet_sock.c", 290LL, (unsigned int)*v35);
return 1;
}
v53 = v62;
if ( v62 == 13 )
{
v20 = 0;
test_msg("PASS\n");
}
else
{
v54 = _errno_location();
v20 = 1;
test_msg("FAIL: %s:%d: Fanout2 screwed up to %x (errno = %d)\n", "packet_sock.c", 295LL, v53, (unsigned int)*v54);
}
return v20;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebp
unsigned __int16 v5; // ax
int v6; // er12
__int64 v7; // rcx
struct sockaddr *v8; // rdi
__int64 v9; // rcx
char *v10; // rdi
__int64 v11; // rcx
__int64 *v12; // rdi
__int64 v13; // rcx
char *v14; // rdi
__int64 v15; // rcx
char *v16; // rdi
unsigned int v17; // er15
int *v18; // rax
__int64 v19; // rcx
int v20; // er15
int *v21; // rax
int *v23; // rax
int *v24; // rax
int *v25; // rax
int *v26; // rax
int *v27; // rax
int *v28; // rax
int *v29; // rax
int *v30; // rax
int *v31; // rax
int *v32; // rax
int *v33; // rax
int *v34; // rax
int *v35; // rax
int *v36; // rax
int *v37; // rax
int *v38; // rax
__int64 v39; // rcx
__int64 *v40; // rdi
unsigned int v41; // ebx
int v42; // ebx
unsigned int v43; // er13
int *v44; // rax
int *v45; // rax
int *v46; // rax
int *v47; // rax
int *v48; // rax
int *v49; // rax
int *v50; // rax
__int64 v51; // rcx
char *v52; // rdi
unsigned int v53; // er12
int *v54; // rax
int *v55; // rax
int *v56; // rax
int *v57; // rax
int *v58; // rax
socklen_t v59; // [rsp+0h] [rbp-F8h] BYREF
unsigned int optval; // [rsp+4h] [rbp-F4h] BYREF
unsigned int v61; // [rsp+8h] [rbp-F0h] BYREF
int v62; // [rsp+Ch] [rbp-ECh] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-E8h] BYREF
struct sockaddr v64; // [rsp+30h] [rbp-C8h] BYREF
struct sockaddr v65; // [rsp+50h] [rbp-A8h] BYREF
__int64 v66; // [rsp+70h] [rbp-88h] BYREF
__int64 v67; // [rsp+78h] [rbp-80h]
char v68[16]; // [rsp+80h] [rbp-78h] BYREF
__int64 v69; // [rsp+90h] [rbp-68h] BYREF
char v70[96]; // [rsp+98h] [rbp-60h] BYREF

test_init(argc, argv, envp);
v3 = socket(17, 3, 0);
if ( v3 < 0 )
{
v21 = _errno_location();
v20 = 1;
test_msg("ERR: %s:%d: Can't create socket 1 (errno = %d)\n", "packet_sock.c", 98LL, (unsigned int)*v21);
return v20;
}
v4 = v3;
v5 = func1(17LL, 2LL);
v6 = socket(17, 2, v5);
if ( v6 < 0 )
{
v25 = _errno_location();
v20 = 1;
test_msg("ERR: %s:%d: Can't create socket 2 (errno = %d)\n", "packet_sock.c", 104LL, (unsigned int)*v25);
return v20;
}
v7 = 5LL;
v8 = &addr;
while ( v7 )
{
*(_DWORD *)&v8->sa_family = 0;
v8 = (struct sockaddr *)((char *)v8 + 4);
--v7;
}
addr.sa_family = 17;
*(_DWORD *)&addr.sa_data[2] = 1;
if ( bind(v6, &addr, 0x14u) < 0 )
{
v23 = _errno_location();
v20 = 1;
test_msg("ERR: %s:%d: Can't bind socket %m (errno = %d)\n", "packet_sock.c", 112LL, (unsigned int)*v23);
return v20;
}
v59 = 20;
if ( getsockname(v4, &v64, &v59) < 0 )
{
v26 = _errno_location();
v20 = 1;
test_msg("ERR: %s:%d: Can't get sockname 1 (errno = %d)\n", "packet_sock.c", 118LL, (unsigned int)*v26);
return v20;
}
v59 = 20;
if ( getsockname(v6, &v65, &v59) < 0 )
{
v27 = _errno_location();
v20 = 1;
test_msg("ERR: %s:%d: Can't get sockname 2 (errno = %d)\n", "packet_sock.c", 124LL, (unsigned int)*v27);
return v20;
}
optval = 1;
if ( setsockopt(v4, 263, 10, &optval, 4u) < 0 )
{
v24 = _errno_location();
v20 = 1;
test_msg("ERR: %s:%d: Can't set version %m (errno = %d)\n", "packet_sock.c", 130LL, (unsigned int)*v24);
return v20;
}
v62 = 1;
if ( setsockopt(v4, 263, 8, &v62, 4u) < 0 )
{
v29 = _errno_location();
v20 = 1;
test_msg("ERR: %s:%d: Can't set auxdata %m (errno = %d)\n", "packet_sock.c", 136LL, (unsigned int)*v29);
return v20;
}
v9 = 3LL;
v10 = v68;
while ( v9 )
{
*(_DWORD *)v10 = 0;
v10 += 4;
--v9;
}
v66 = 0x100001000LL;
v67 = 0x400000400LL;
if ( setsockopt(v4, 263, 5, &v66, 0x1Cu) < 0 )
{
v30 = _errno_location();
v20 = 1;
test_msg("ERR: %s:%d: Can't set rx ring %m (errno = %d)\n", "packet_sock.c", 146LL, (unsigned int)*v30);
return v20;
}
v61 = 8;
if ( setsockopt(v6, 263, 12, &v61, 4u) < 0 )
{
v31 = _errno_location();
v20 = 1;
test_msg("ERR: %s:%d: Can't set reserve %m (errno = %d)\n", "packet_sock.c", 152LL, (unsigned int)*v31);
return v20;
}
v62 = 1;
if ( setsockopt(v6, 263, 9, &v62, 4u) < 0 )
{
v28 = _errno_location();
v20 = 1;
test_msg("ERR: %s:%d: Can't set origdev %m (errno = %d)\n", "packet_sock.c", 158LL, (unsigned int)*v28);
return v20;
}
v62 = 13;
if ( setsockopt(v6, 263, 18, &v62, 4u) < 0 )
{
v32 = _errno_location();
v20 = 1;
test_msg("ERR: %s:%d: Can't configure fanout %m (errno = %d)\n", "packet_sock.c", 164LL, (unsigned int)*v32);
return v20;
}
v11 = 10LL;
v12 = &v69;
while ( v11 )
{
*(_DWORD *)v12 = 0;
v12 = (__int64 *)((char *)v12 + 4);
--v11;
}
LODWORD(v69) = 1;
WORD2(v69) = 1;
if ( setsockopt(v4, 263, 1, &v69, 0x28u) < 0 )
{
v33 = _errno_location();
v20 = 1;
test_msg("ERR: %s:%d: Can't add promisc member %m (errno = %d)\n", "packet_sock.c", 172LL, (unsigned int)*v33);
return v20;
}
v13 = 8LL;
v14 = v70;
while ( v13 )
{
*(_DWORD *)v14 = 0;
v14 += 4;
--v13;
}
v69 = 0x6000300000001LL;
if ( setsockopt(v6, 263, 1, &v69, 0x28u) < 0 )
{
v34 = _errno_location();
v20 = 1;
test_msg("ERR: %s:%d: Can't add ucast member %m (errno = %d)\n", "packet_sock.c", 181LL, (unsigned int)*v34);
return v20;
}
v15 = 3LL;
v16 = v68;
while ( v15 )
{
*(_DWORD *)v16 = 0;
v16 += 4;
--v15;
}
v66 = 0x100001000LL;
v67 = 0x400000400LL;
if ( setsockopt(v6, 263, 13, &v66, 0x1Cu) < 0 )
{
v36 = _errno_location();
v20 = 1;
test_msg("ERR: %s:%d: Can't set tx ring %m (errno = %d)\n", "packet_sock.c", 191LL, (unsigned int)*v36);
return v20;
}
test_daemon();
test_waitsig();
v59 = 20;
if ( getsockname(v4, &addr, &v59) < 0 )
{
v37 = _errno_location();
v20 = 1;
test_msg("FAIL: %s:%d: Can't get sockname 1 rst (errno = %d)\n", "packet_sock.c", 200LL, (unsigned int)*v37);
return v20;
}
if ( (unsigned int)func0(1u, (__int16 *)&addr, (__int16 *)&v64) )
return 1;
v59 = 4;
if ( getsockopt(v4, 263, 10, &optval, &v59) < 0 )
{
v45 = _errno_location();
v20 = 1;
test_msg("FAIL: %s:%d: Can't get sockopt ver %m (errno = %d)\n", "packet_sock.c", 209LL, (unsigned int)*v45);
return v20;
}
v17 = optval;
if ( optval != 1 )
{
v18 = _errno_location();
v19 = v17;
v20 = 1;
test_msg(
"FAIL: %s:%d: Version mismatch have %d, want %d\n (errno = %d)\n",
"packet_sock.c",
214LL,
v19,
1LL,
(unsigned int)*v18);
return v20;
}
v59 = 4;
if ( getsockopt(v4, 263, 8, &v62, &v59) < 0 )
{
v46 = _errno_location();
v20 = 1;
test_msg("FAIL: %s:%d: Can't get sockopt auxdata %m (errno = %d)\n", "packet_sock.c", 220LL, (unsigned int)*v46);
return v20;
}
v20 = v62;
if ( v62 != 1 )
{
v38 = _errno_location();
v20 = 1;
test_msg("FAIL: %s:%d: Auxdata not ON (errno = %d)\n", "packet_sock.c", 225LL, (unsigned int)*v38);
return v20;
}
v39 = 10LL;
v40 = &v69;
while ( v39 )
{
*(_DWORD *)v40 = 0;
v40 = (__int64 *)((char *)v40 + 4);
--v39;
}
LODWORD(v69) = 1;
WORD2(v69) = 1;
if ( setsockopt(v4, 263, 2, &v69, 0x28u) < 0 )
{
v48 = _errno_location();
test_msg("FAIL: %s:%d: Promisc member not kept (errno = %d)\n", "packet_sock.c", 233LL, (unsigned int)*v48);
return v20;
}
v59 = 4;
if ( getsockopt(v4, 263, 18, &v62, &v59) < 0 )
{
v50 = _errno_location();
test_msg("FAIL: %s:%d: Can't read fanout back %m (errno = %d)\n", "packet_sock.c", 239LL, (unsigned int)*v50);
return v20;
}
v41 = v62;
if ( v62 )
{
v47 = _errno_location();
test_msg("FAIL: %s:%d: Fanout screwed up to %x (errno = %d)\n", "packet_sock.c", 244LL, v41, (unsigned int)*v47);
return v20;
}
v59 = 20;
if ( getsockname(v6, &addr, &v59) < 0 )
{
v49 = _errno_location();
test_msg("FAIL: %s:%d: Can't get sockname 2 rst (errno = %d)\n", "packet_sock.c", 250LL, (unsigned int)*v49);
return v20;
}
v42 = func0(2u, (__int16 *)&addr, (__int16 *)&v65);
if ( v42 )
return 1;
v59 = 4;
if ( getsockopt(v6, 263, 12, &v61, &v59) < 0 )
{
v58 = _errno_location();
test_msg("FAIL: %s:%d: Can't get sockopt rsv %m (errno = %d)\n", "packet_sock.c", 259LL, (unsigned int)*v58);
return v20;
}
v59 = 4;
if ( getsockopt(v6, 263, 9, &v62, &v59) < 0 )
{
v57 = _errno_location();
test_msg("FAIL: %s:%d: Can't get sockopt origdev %m (errno = %d)\n", "packet_sock.c", 265LL, (unsigned int)*v57);
return v20;
}
if ( v62 != 1 )
{
v55 = _errno_location();
test_msg("FAIL: %s:%d: OrigDev not ON (errno = %d)\n", "packet_sock.c", 270LL, (unsigned int)*v55);
return v20;
}
v43 = v61;
if ( v61 != 8 )
{
v44 = _errno_location();
v20 = 1;
test_msg(
"FAIL: %s:%d: Reserve mismatch have %d, want %d\n (errno = %d)\n",
"packet_sock.c",
275LL,
v43,
8LL,
(unsigned int)*v44);
return v20;
}
v51 = 8LL;
v52 = v70;
while ( v51 )
{
*(_DWORD *)v52 = v42;
v52 += 4;
--v51;
}
v69 = 0x6000300000001LL;
if ( setsockopt(v6, 263, 2, &v69, 0x28u) < 0 )
{
v56 = _errno_location();
v20 = 1;
test_msg("FAIL: %s:%d: Ucast member not kept (errno = %d)\n", "packet_sock.c", 284LL, (unsigned int)*v56);
return v20;
}
v59 = 4;
if ( getsockopt(v6, 263, 18, &v62, &v59) < 0 )
{
v35 = _errno_location();
test_msg("FAIL: %s:%d: Can't read fanout2 back %m (errno = %d)\n", "packet_sock.c", 290LL, (unsigned int)*v35);
return 1;
}
v53 = v62;
if ( v62 == 13 )
{
v20 = 0;
test_msg("PASS\n");
}
else
{
v54 = _errno_location();
v20 = 1;
test_msg("FAIL: %s:%d: Fanout2 screwed up to %x (errno = %d)\n", "packet_sock.c", 295LL, v53, (unsigned int)*v54);
}
return v20;
}

original_code:
int main(int argc, char **argv)
{
 int sk1, sk2;
 struct sockaddr_ll addr, addr1, addr2;
 socklen_t alen;
 int ver, rsv, yes;
 struct packet_mreq_max mreq;
 struct tpacket_req3 ring;
 test_init(argc, argv);
 sk1 = socket(17, SOCK_RAW, 0);
 if (sk1 < 0) {
  test_msg("ERR: %s:%d: " "Can't create socket 1" " (errno = %d)\n", "packet_sock.c", 98, (*__errno_location ()));
  return 1;
 }
 sk2 = socket(17, SOCK_DGRAM, htons(0x0800));
 if (sk2 < 0) {
  test_msg("ERR: %s:%d: " "Can't create socket 2" " (errno = %d)\n", "packet_sock.c", 104, (*__errno_location ()));
  return 1;
 }
 memset(&addr, 0, sizeof(addr));
 addr.sll_family = 17;
 addr.sll_ifindex = 1;
 if (bind(sk2, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
  test_msg("ERR: %s:%d: " "Can't bind socket %m" " (errno = %d)\n", "packet_sock.c", 112, (*__errno_location ()));
  return 1;
 }
 alen = sizeof(addr1);
 if (getsockname(sk1, (struct sockaddr *)&addr1, &alen) < 0) {
  test_msg("ERR: %s:%d: " "Can't get sockname 1" " (errno = %d)\n", "packet_sock.c", 118, (*__errno_location ()));
  return 1;
 }
 alen = sizeof(addr2);
 if (getsockname(sk2, (struct sockaddr *)&addr2, &alen) < 0) {
  test_msg("ERR: %s:%d: " "Can't get sockname 2" " (errno = %d)\n", "packet_sock.c", 124, (*__errno_location ()));
  return 1;
 }
 ver = TPACKET_V2;
 if (setsockopt(sk1, 263, 10, &ver, sizeof(ver)) < 0) {
  test_msg("ERR: %s:%d: " "Can't set version %m" " (errno = %d)\n", "packet_sock.c", 130, (*__errno_location ()));
  return 1;
 }
 yes = 1;
 if (setsockopt(sk1, 263, 8, &yes, sizeof(yes)) < 0) {
  test_msg("ERR: %s:%d: " "Can't set auxdata %m" " (errno = %d)\n", "packet_sock.c", 136, (*__errno_location ()));
  return 1;
 }
 memset(&ring, 0, sizeof(ring));
 ring.tp_block_size = 4096;
 ring.tp_block_nr = 1;
 ring.tp_frame_size = 1024;
 ring.tp_frame_nr = 4;
 if (setsockopt(sk1, 263, 5, &ring, sizeof(ring)) < 0) {
  test_msg("ERR: %s:%d: " "Can't set rx ring %m" " (errno = %d)\n", "packet_sock.c", 146, (*__errno_location ()));
  return 1;
 }
 rsv = 8;
 if (setsockopt(sk2, 263, 12, &rsv, sizeof(rsv)) < 0) {
  test_msg("ERR: %s:%d: " "Can't set reserve %m" " (errno = %d)\n", "packet_sock.c", 152, (*__errno_location ()));
  return 1;
 }
 yes = 1;
 if (setsockopt(sk2, 263, 9, &yes, sizeof(yes)) < 0) {
  test_msg("ERR: %s:%d: " "Can't set origdev %m" " (errno = %d)\n", "packet_sock.c", 158, (*__errno_location ()));
  return 1;
 }
 yes = 13;
 if (setsockopt(sk2, 263, 18, &yes, sizeof(yes)) < 0) {
  test_msg("ERR: %s:%d: " "Can't configure fanout %m" " (errno = %d)\n", "packet_sock.c", 164, (*__errno_location ()));
  return 1;
 }
 memset(&mreq, 0, sizeof(mreq));
 mreq.mr_ifindex = 1;
 mreq.mr_type = 1;
 if (setsockopt(sk1, 263, 1, &mreq, sizeof(mreq)) < 0) {
  test_msg("ERR: %s:%d: " "Can't add promisc member %m" " (errno = %d)\n", "packet_sock.c", 172, (*__errno_location ()));
  return 1;
 }
 memset(&mreq, 0, sizeof(mreq));
 mreq.mr_ifindex = 1;
 mreq.mr_type = 3;
 mreq.mr_alen = 6;
 if (setsockopt(sk2, 263, 1, &mreq, sizeof(mreq)) < 0) {
  test_msg("ERR: %s:%d: " "Can't add ucast member %m" " (errno = %d)\n", "packet_sock.c", 181, (*__errno_location ()));
  return 1;
 }
 memset(&ring, 0, sizeof(ring));
 ring.tp_block_size = 4096;
 ring.tp_block_nr = 1;
 ring.tp_frame_size = 1024;
 ring.tp_frame_nr = 4;
 if (setsockopt(sk2, 263, 13, &ring, sizeof(ring)) < 0) {
  test_msg("ERR: %s:%d: " "Can't set tx ring %m" " (errno = %d)\n", "packet_sock.c", 191, (*__errno_location ()));
  return 1;
 }
 test_daemon();
 test_waitsig();
 alen = sizeof(addr);
 if (getsockname(sk1, (struct sockaddr *)&addr, &alen) < 0) {
  test_msg("FAIL: %s:%d: " "Can't get sockname 1 rst" " (errno = %d)\n", "packet_sock.c", 200, (*__errno_location ()));
  return 1;
 }
 if (test_sockaddr(1, &addr, &addr1))
  return 1;
 alen = sizeof(ver);
 if (getsockopt(sk1, 263, 10, &ver, &alen) < 0) {
  test_msg("FAIL: %s:%d: " "Can't get sockopt ver %m" " (errno = %d)\n", "packet_sock.c", 209, (*__errno_location ()));
  return 1;
 }
 if (ver != TPACKET_V2) {
  test_msg("FAIL: %s:%d: " "Version mismatch have %d, want %d\n" " (errno = %d)\n", "packet_sock.c", 214, ver, TPACKET_V2, (*__errno_location ()));
  return 1;
 }
 alen = sizeof(yes);
 if (getsockopt(sk1, 263, 8, &yes, &alen) < 0) {
  test_msg("FAIL: %s:%d: " "Can't get sockopt auxdata %m" " (errno = %d)\n", "packet_sock.c", 220, (*__errno_location ()));
  return 1;
 }
 if (yes != 1) {
  test_msg("FAIL: %s:%d: " "Auxdata not ON" " (errno = %d)\n", "packet_sock.c", 225, (*__errno_location ()));
  return 1;
 }
 memset(&mreq, 0, sizeof(mreq));
 mreq.mr_ifindex = 1;
 mreq.mr_type = 1;
 if (setsockopt(sk1, 263, 2, &mreq, sizeof(mreq)) < 0) {
  test_msg("FAIL: %s:%d: " "Promisc member not kept" " (errno = %d)\n", "packet_sock.c", 233, (*__errno_location ()));
  return 1;
 }
 alen = sizeof(yes);
 if (getsockopt(sk1, 263, 18, &yes, &alen) < 0) {
  test_msg("FAIL: %s:%d: " "Can't read fanout back %m" " (errno = %d)\n", "packet_sock.c", 239, (*__errno_location ()));
  return 1;
 }
 if (yes != 0) {
  test_msg("FAIL: %s:%d: " "Fanout screwed up to %x" " (errno = %d)\n", "packet_sock.c", 244, yes, (*__errno_location ()));
  return 1;
 }
 alen = sizeof(addr);
 if (getsockname(sk2, (struct sockaddr *)&addr, &alen) < 0) {
  test_msg("FAIL: %s:%d: " "Can't get sockname 2 rst" " (errno = %d)\n", "packet_sock.c", 250, (*__errno_location ()));
  return 1;
 }
 if (test_sockaddr(2, &addr, &addr2))
  return 1;
 alen = sizeof(rsv);
 if (getsockopt(sk2, 263, 12, &rsv, &alen) < 0) {
  test_msg("FAIL: %s:%d: " "Can't get sockopt rsv %m" " (errno = %d)\n", "packet_sock.c", 259, (*__errno_location ()));
  return 1;
 }
 alen = sizeof(yes);
 if (getsockopt(sk2, 263, 9, &yes, &alen) < 0) {
  test_msg("FAIL: %s:%d: " "Can't get sockopt origdev %m" " (errno = %d)\n", "packet_sock.c", 265, (*__errno_location ()));
  return 1;
 }
 if (yes != 1) {
  test_msg("FAIL: %s:%d: " "OrigDev not ON" " (errno = %d)\n", "packet_sock.c", 270, (*__errno_location ()));
  return 1;
 }
 if (rsv != 8) {
  test_msg("FAIL: %s:%d: " "Reserve mismatch have %d, want %d\n" " (errno = %d)\n", "packet_sock.c", 275, rsv, 8, (*__errno_location ()));
  return 1;
 }
 memset(&mreq, 0, sizeof(mreq));
 mreq.mr_ifindex = 1;
 mreq.mr_type = 3;
 mreq.mr_alen = 6;
 if (setsockopt(sk2, 263, 2, &mreq, sizeof(mreq)) < 0) {
  test_msg("FAIL: %s:%d: " "Ucast member not kept" " (errno = %d)\n", "packet_sock.c", 284, (*__errno_location ()));
  return 1;
 }
 alen = sizeof(yes);
 if (getsockopt(sk2, 263, 18, &yes, &alen) < 0) {
  test_msg("FAIL: %s:%d: " "Can't read fanout2 back %m" " (errno = %d)\n", "packet_sock.c", 290, (*__errno_location ()));
  return 1;
 }
 if (yes != 13) {
  test_msg("FAIL: %s:%d: " "Fanout2 screwed up to %x" " (errno = %d)\n", "packet_sock.c", 295, yes, (*__errno_location ()));
  return 1;
 }
 test_msg("PASS\n");
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int sk1; int sk2;
 struct sockaddr_ll addr; struct sockaddr_ll addr1; struct sockaddr_ll addr2;
 unsigned int alen;
 int ver; int rsv; int yes;
 struct packet_mreq_max mreq;
 struct tpacket_req3 ring;
 test_init(argc, argv);
 sk1 = socket(17, SOCK_RAW, 0);
 if (sk1 < 0) {
  test_msg("ERR: %s:%d: " "Can't create socket 1" " (errno = %d)\n", "packet_sock.c", 98, (*__errno_location ()));
  return 1;
 }
 sk2 = socket(17, SOCK_DGRAM, htons(0x0800));
 if (sk2 < 0) {
  test_msg("ERR: %s:%d: " "Can't create socket 2" " (errno = %d)\n", "packet_sock.c", 104, (*__errno_location ()));
  return 1;
 }
 memset(&addr, 0, sizeof(addr));
 addr.sll_family = 17;
 addr.sll_ifindex = 1;
 if (bind(sk2, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
  test_msg("ERR: %s:%d: " "Can't bind socket %m" " (errno = %d)\n", "packet_sock.c", 112, (*__errno_location ()));
  return 1;
 }
 alen = sizeof(addr1);
 if (getsockname(sk1, (struct sockaddr *)&addr1, &alen) < 0) {
  test_msg("ERR: %s:%d: " "Can't get sockname 1" " (errno = %d)\n", "packet_sock.c", 118, (*__errno_location ()));
  return 1;
 }
 alen = sizeof(addr2);
 if (getsockname(sk2, (struct sockaddr *)&addr2, &alen) < 0) {
  test_msg("ERR: %s:%d: " "Can't get sockname 2" " (errno = %d)\n", "packet_sock.c", 124, (*__errno_location ()));
  return 1;
 }
 ver = TPACKET_V2;
 if (setsockopt(sk1, 263, 10, &ver, sizeof(ver)) < 0) {
  test_msg("ERR: %s:%d: " "Can't set version %m" " (errno = %d)\n", "packet_sock.c", 130, (*__errno_location ()));
  return 1;
 }
 yes = 1;
 if (setsockopt(sk1, 263, 8, &yes, sizeof(yes)) < 0) {
  test_msg("ERR: %s:%d: " "Can't set auxdata %m" " (errno = %d)\n", "packet_sock.c", 136, (*__errno_location ()));
  return 1;
 }
 memset(&ring, 0, sizeof(ring));
 ring.tp_block_size = 4096;
 ring.tp_block_nr = 1;
 ring.tp_frame_size = 1024;
 ring.tp_frame_nr = 4;
 if (setsockopt(sk1, 263, 5, &ring, sizeof(ring)) < 0) {
  test_msg("ERR: %s:%d: " "Can't set rx ring %m" " (errno = %d)\n", "packet_sock.c", 146, (*__errno_location ()));
  return 1;
 }
 rsv = 8;
 if (setsockopt(sk2, 263, 12, &rsv, sizeof(rsv)) < 0) {
  test_msg("ERR: %s:%d: " "Can't set reserve %m" " (errno = %d)\n", "packet_sock.c", 152, (*__errno_location ()));
  return 1;
 }
 yes = 1;
 if (setsockopt(sk2, 263, 9, &yes, sizeof(yes)) < 0) {
  test_msg("ERR: %s:%d: " "Can't set origdev %m" " (errno = %d)\n", "packet_sock.c", 158, (*__errno_location ()));
  return 1;
 }
 yes = 13;
 if (setsockopt(sk2, 263, 18, &yes, sizeof(yes)) < 0) {
  test_msg("ERR: %s:%d: " "Can't configure fanout %m" " (errno = %d)\n", "packet_sock.c", 164, (*__errno_location ()));
  return 1;
 }
 memset(&mreq, 0, sizeof(mreq));
 mreq.mr_ifindex = 1;
 mreq.mr_type = 1;
 if (setsockopt(sk1, 263, 1, &mreq, sizeof(mreq)) < 0) {
  test_msg("ERR: %s:%d: " "Can't add promisc member %m" " (errno = %d)\n", "packet_sock.c", 172, (*__errno_location ()));
  return 1;
 }
 memset(&mreq, 0, sizeof(mreq));
 mreq.mr_ifindex = 1;
 mreq.mr_type = 3;
 mreq.mr_alen = 6;
 if (setsockopt(sk2, 263, 1, &mreq, sizeof(mreq)) < 0) {
  test_msg("ERR: %s:%d: " "Can't add ucast member %m" " (errno = %d)\n", "packet_sock.c", 181, (*__errno_location ()));
  return 1;
 }
 memset(&ring, 0, sizeof(ring));
 ring.tp_block_size = 4096;
 ring.tp_block_nr = 1;
 ring.tp_frame_size = 1024;
 ring.tp_frame_nr = 4;
 if (setsockopt(sk2, 263, 13, &ring, sizeof(ring)) < 0) {
  test_msg("ERR: %s:%d: " "Can't set tx ring %m" " (errno = %d)\n", "packet_sock.c", 191, (*__errno_location ()));
  return 1;
 }
 test_daemon();
 test_waitsig();
 alen = sizeof(addr);
 if (getsockname(sk1, (struct sockaddr *)&addr, &alen) < 0) {
  test_msg("FAIL: %s:%d: " "Can't get sockname 1 rst" " (errno = %d)\n", "packet_sock.c", 200, (*__errno_location ()));
  return 1;
 }
 if (test_sockaddr(1, &addr, &addr1))
  return 1;
 alen = sizeof(ver);
 if (getsockopt(sk1, 263, 10, &ver, &alen) < 0) {
  test_msg("FAIL: %s:%d: " "Can't get sockopt ver %m" " (errno = %d)\n", "packet_sock.c", 209, (*__errno_location ()));
  return 1;
 }
 if (ver != TPACKET_V2) {
  test_msg("FAIL: %s:%d: " "Version mismatch have %d, want %d\n" " (errno = %d)\n", "packet_sock.c", 214, ver, TPACKET_V2, (*__errno_location ()));
  return 1;
 }
 alen = sizeof(yes);
 if (getsockopt(sk1, 263, 8, &yes, &alen) < 0) {
  test_msg("FAIL: %s:%d: " "Can't get sockopt auxdata %m" " (errno = %d)\n", "packet_sock.c", 220, (*__errno_location ()));
  return 1;
 }
 if (yes != 1) {
  test_msg("FAIL: %s:%d: " "Auxdata not ON" " (errno = %d)\n", "packet_sock.c", 225, (*__errno_location ()));
  return 1;
 }
 memset(&mreq, 0, sizeof(mreq));
 mreq.mr_ifindex = 1;
 mreq.mr_type = 1;
 if (setsockopt(sk1, 263, 2, &mreq, sizeof(mreq)) < 0) {
  test_msg("FAIL: %s:%d: " "Promisc member not kept" " (errno = %d)\n", "packet_sock.c", 233, (*__errno_location ()));
  return 1;
 }
 alen = sizeof(yes);
 if (getsockopt(sk1, 263, 18, &yes, &alen) < 0) {
  test_msg("FAIL: %s:%d: " "Can't read fanout back %m" " (errno = %d)\n", "packet_sock.c", 239, (*__errno_location ()));
  return 1;
 }
 if (yes != 0) {
  test_msg("FAIL: %s:%d: " "Fanout screwed up to %x" " (errno = %d)\n", "packet_sock.c", 244, yes, (*__errno_location ()));
  return 1;
 }
 alen = sizeof(addr);
 if (getsockname(sk2, (struct sockaddr *)&addr, &alen) < 0) {
  test_msg("FAIL: %s:%d: " "Can't get sockname 2 rst" " (errno = %d)\n", "packet_sock.c", 250, (*__errno_location ()));
  return 1;
 }
 if (test_sockaddr(2, &addr, &addr2))
  return 1;
 alen = sizeof(rsv);
 if (getsockopt(sk2, 263, 12, &rsv, &alen) < 0) {
  test_msg("FAIL: %s:%d: " "Can't get sockopt rsv %m" " (errno = %d)\n", "packet_sock.c", 259, (*__errno_location ()));
  return 1;
 }
 alen = sizeof(yes);
 if (getsockopt(sk2, 263, 9, &yes, &alen) < 0) {
  test_msg("FAIL: %s:%d: " "Can't get sockopt origdev %m" " (errno = %d)\n", "packet_sock.c", 265, (*__errno_location ()));
  return 1;
 }
 if (yes != 1) {
  test_msg("FAIL: %s:%d: " "OrigDev not ON" " (errno = %d)\n", "packet_sock.c", 270, (*__errno_location ()));
  return 1;
 }
 if (rsv != 8) {
  test_msg("FAIL: %s:%d: " "Reserve mismatch have %d, want %d\n" " (errno = %d)\n", "packet_sock.c", 275, rsv, 8, (*__errno_location ()));
  return 1;
 }
 memset(&mreq, 0, sizeof(mreq));
 mreq.mr_ifindex = 1;
 mreq.mr_type = 3;
 mreq.mr_alen = 6;
 if (setsockopt(sk2, 263, 2, &mreq, sizeof(mreq)) < 0) {
  test_msg("FAIL: %s:%d: " "Ucast member not kept" " (errno = %d)\n", "packet_sock.c", 284, (*__errno_location ()));
  return 1;
 }
 alen = sizeof(yes);
 if (getsockopt(sk2, 263, 18, &yes, &alen) < 0) {
  test_msg("FAIL: %s:%d: " "Can't read fanout2 back %m" " (errno = %d)\n", "packet_sock.c", 290, (*__errno_location ()));
  return 1;
 }
 if (yes != 13) {
  test_msg("FAIL: %s:%d: " "Fanout2 screwed up to %x" " (errno = %d)\n", "packet_sock.c", 295, yes, (*__errno_location ()));
  return 1;
 }
 test_msg("PASS\n");
 return 0;
}

variable_types: struct sockaddr_ll { unsigned short sll_family; unsigned short sll_protocol; int sll_ifindex; unsigned short sll_hatype; unsigned char sll_pkttype; unsigned char sll_halen; unsigned char sll_addr[8]; }

variable_types:
alen
unsigned int

variable_types: ver int

variable_types: rsv int

variable_types: yes int

variable_types: struct packet_mreq_max { int mr_ifindex; unsigned short mr_type; unsigned short mr_alen; unsigned char mr_address[32]; }

variable_types: struct tpacket_req3 { unsigned int tp_block_size; unsigned int tp_block_nr; unsigned int tp_frame_size; unsigned int tp_frame_nr; unsigned int tp_retire_blk_tov; unsigned int tp_sizeof_priv; unsigned int tp_feature_req_word; }

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


decompiled_code:
__int64 __fastcall fill_sock_name(__int64 a1, const char *a2)
{
if ( strlen(a2) > 0x6B )
return 0xFFFFFFFFLL;
*(_WORD *)a1 = 1;
strcpy((char *)(a1 + 2), a2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, const char *a2)
{
if ( strlen(a2) > 0x6B )
return 0xFFFFFFFFLL;
*(_WORD *)a1 = 1;
strcpy((char *)(a1 + 2), a2);
return 0LL;
}

original_code:
static int fill_sock_name(struct sockaddr_un *name, const char *filename)
{
 if (strlen(filename) >= sizeof(name->sun_path))
  return -1;
 name->sun_family = 1;
 strcpy(name->sun_path, filename);
 return 0;
}

canonical_original_code:
static int fill_sock_name(struct sockaddr_un *name, char *filename)
{
 if (strlen(filename) >= sizeof(name->sun_path))
  return -1;
 name->sun_family = 1;
 strcpy(name->sun_path, filename);
 return 0;
}

variable_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; } *

variable_types:
filename
char *


decompiled_code:
__int64 __fastcall accept_one_conn(int fd)
{
int v1; // eax
int *v2; // rax
int v3; // er12
__int64 result; // rax
int *v5; // rax
int *v6; // rax
struct timeval v7; // [rsp+0h] [rbp-A8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-98h] BYREF

v7.tv_sec = 100LL;
v7.tv_usec = 0LL;
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[fd / 64] |= 1LL << (fd % 64);
v1 = select(1024, &readfds, 0LL, 0LL, &v7);
if ( v1 )
{
if ( v1 == 1 )
{
v3 = accept(fd, 0LL, 0LL);
if ( v3 < 0 )
{
v6 = _errno_location();
test_msg("ERR: %s:%d: error accepting a connection: %m (errno = %d)\n", "unix_sock.c", 102LL, (unsigned int)*v6);
}
}
else
{
v2 = _errno_location();
v3 = -1;
test_msg(
"ERR: %s:%d: error while waiting for a connection: %m (errno = %d)\n",
"unix_sock.c",
96LL,
(unsigned int)*v2);
}
result = (unsigned int)v3;
}
else
{
v5 = _errno_location();
test_msg("ERR: %s:%d: timeout accepting a connection (errno = %d)\n", "unix_sock.c", 93LL, (unsigned int)*v5);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int fd)
{
int v1; // eax
int *v2; // rax
int v3; // er12
__int64 result; // rax
int *v5; // rax
int *v6; // rax
struct timeval v7; // [rsp+0h] [rbp-A8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-98h] BYREF

v7.tv_sec = 100LL;
v7.tv_usec = 0LL;
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[fd / 64] |= 1LL << (fd % 64);
v1 = select(1024, &readfds, 0LL, 0LL, &v7);
if ( v1 )
{
if ( v1 == 1 )
{
v3 = accept(fd, 0LL, 0LL);
if ( v3 < 0 )
{
v6 = _errno_location();
test_msg("ERR: %s:%d: error accepting a connection: %m (errno = %d)\n", "unix_sock.c", 102LL, (unsigned int)*v6);
}
}
else
{
v2 = _errno_location();
v3 = -1;
test_msg(
"ERR: %s:%d: error while waiting for a connection: %m (errno = %d)\n",
"unix_sock.c",
96LL,
(unsigned int)*v2);
}
result = (unsigned int)v3;
}
else
{
v5 = _errno_location();
test_msg("ERR: %s:%d: timeout accepting a connection (errno = %d)\n", "unix_sock.c", 93LL, (unsigned int)*v5);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static int accept_one_conn(int sock)
{
 int acc_sock;
 fd_set fds;
 struct timeval timeout = {
  .tv_sec = 100,
 };
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&fds)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))));
 switch (select(1024, &fds, ((void *)0), ((void *)0), &timeout)) {
 case 1:
  break;
 case 0:
  test_msg("ERR: %s:%d: " "timeout accepting a connection" " (errno = %d)\n", "unix_sock.c", 93, (*__errno_location ()));
  return -1;
 default:
  test_msg("ERR: %s:%d: " "error while waiting for a connection: %m" " (errno = %d)\n", "unix_sock.c", 96, (*__errno_location ()));
  return -1;
 }
 acc_sock = accept(sock, ((void *)0), ((void *)0));
 if (acc_sock < 0)
  test_msg("ERR: %s:%d: " "error accepting a connection: %m" " (errno = %d)\n", "unix_sock.c", 102, (*__errno_location ()));
 return acc_sock;
}

canonical_original_code:
static int accept_one_conn(int sock)
{
 int acc_sock;
 struct fd_set fds;
 struct timeval timeout = {
  .tv_sec = 100,
 };
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&fds)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))));
 switch (select(1024, &fds, ((void *)0), ((void *)0), &timeout)) {
 case 1:
  break;
 case 0:
  test_msg("ERR: %s:%d: " "timeout accepting a connection" " (errno = %d)\n", "unix_sock.c", 93, (*__errno_location ()));
  return -1;
 default:
  test_msg("ERR: %s:%d: " "error while waiting for a connection: %m" " (errno = %d)\n", "unix_sock.c", 96, (*__errno_location ()));
  return -1;
 }
 acc_sock = accept(sock, ((void *)0), ((void *)0));
 if (acc_sock < 0)
  test_msg("ERR: %s:%d: " "error accepting a connection: %m" " (errno = %d)\n", "unix_sock.c", 102, (*__errno_location ()));
 return acc_sock;
}

variable_types: sock int

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

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


child

decompiled_code:
__int64 child()
{
int v0; // ebp
unsigned int v1; // er12
int v3; // er12
int *v4; // rax
bool v5; // zf
int v6; // [rsp+Ch] [rbp-40Ch] BYREF
char buf[1032]; // [rsp+10h] [rbp-408h] BYREF

v6 = -1;
v0 = setup_clnt_sock();
v1 = -v0;
if ( v0 >= 0 )
{
signal(13, handler);
while ( 1 )
{
v1 = test_go();
if ( !v1 )
break;
datagen(buf, 1000LL, &v6);
if ( write(v0, buf, 0x3E8uLL) < 0 )
{
v3 = test_go();
v4 = _errno_location();
v5 = v3 == 0;
v1 = *v4;
if ( !v5 || v1 != 32 && v1 != 4 && v1 != 104 )
{
test_msg("FAIL: %s:%d: child write: %m\n (errno = %d)\n", "unix_sock.c", 159LL, v1);
break;
}
}
}
}
close(v0);
return v1;
}

canonical_decompiled_code:
__int64 func3()
{
int v0; // ebp
unsigned int v1; // er12
int v3; // er12
int *v4; // rax
bool v5; // zf
int v6; // [rsp+Ch] [rbp-40Ch] BYREF
char buf[1032]; // [rsp+10h] [rbp-408h] BYREF

v6 = -1;
v0 = func2();
v1 = -v0;
if ( v0 >= 0 )
{
signal(13, handler);
while ( 1 )
{
v1 = test_go();
if ( !v1 )
break;
datagen(buf, 1000LL, &v6);
if ( write(v0, buf, 0x3E8uLL) < 0 )
{
v3 = test_go();
v4 = _errno_location();
v5 = v3 == 0;
v1 = *v4;
if ( !v5 || v1 != 32 && v1 != 4 && v1 != 104 )
{
test_msg("FAIL: %s:%d: child write: %m\n (errno = %d)\n", "unix_sock.c", 159LL, v1);
break;
}
}
}
}
close(v0);
return v1;
}

original_code:
static int child(void)
{
 int ret = 1;
 uint8_t buf[1000];
 uint32_t crc = ~0;
 int sock = setup_clnt_sock();
 if (sock < 0) {
  ret = -sock;
  goto out;
 }
 signal(13, ((__sighandler_t) 1));
 while (test_go()) {
  datagen(buf, sizeof(buf), &crc);
  if (write(sock, buf, sizeof(buf)) < 0 &&
   (test_go() ||
    ((*__errno_location ()) != 4 && (*__errno_location ()) != 32 && (*__errno_location ()) != 104))) {
   ret = (*__errno_location ());
   test_msg("FAIL: %s:%d: " "child write: %m\n" " (errno = %d)\n", "unix_sock.c", 159, (*__errno_location ()));
   goto out;
  }
 }
 ret = 0;
out:
 close(sock);
 return ret;
}

canonical_original_code:
static int child()
{
 int ret = 1;
 unsigned char buf[1000];
 unsigned int crc = ~0;
 int sock = setup_clnt_sock();
 if (sock < 0) {
  ret = -sock;
  goto out;
 }
 signal(13, ((void (*)(int)) 1));
 while (test_go()) {
  datagen(buf, sizeof(buf), &crc);
  if (write(sock, buf, sizeof(buf)) < 0 &&
   (test_go() ||
    ((*__errno_location ()) != 4 && (*__errno_location ()) != 32 && (*__errno_location ()) != 104))) {
   ret = (*__errno_location ());
   test_msg("FAIL: %s:%d: " "child write: %m\n" " (errno = %d)\n", "unix_sock.c", 159, (*__errno_location ()));
   goto out;
  }
 }
 ret = 0;
out:
 close(sock);
 return ret;
}

variable_types: ret int

variable_types:
buf
unsigned char [1000]

variable_types:
crc
unsigned int


decompiled_code:
__int64 __fastcall read_data(int fd, __int64 a2, int a3)
{
int i; // ebx
int v5; // eax

if ( !a3 )
return 0LL;
for ( i = 0; i != a3; i += v5 )
{
v5 = read(fd, (void *)(a2 + i), a3 - i);
if ( v5 <= 0 )
return 0xFFFFFFFFLL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd, __int64 a2, int a3)
{
int i; // ebx
int v5; // eax

if ( !a3 )
return 0LL;
for ( i = 0; i != a3; i += v5 )
{
v5 = read(fd, (void *)(a2 + i), a3 - i);
if ( v5 <= 0 )
return 0xFFFFFFFFLL;
}
return 0LL;
}

original_code:
int read_data(int fd, unsigned char *buf, int size)
{
 int cur = 0;
 int ret;
 while (cur != size) {
  ret = read(fd, buf + cur, size - cur);
  if (ret <= 0)
   return -1;
  cur += ret;
 }
 return 0;
}

variable_types: fd int

variable_types:
buf
unsigned char *

variable_types: size int

variable_types: cur int


decompiled_code:
__int64 __fastcall write_data(int fd, __int64 a2, int a3)
{
int i; // ebx
int v5; // eax

if ( !a3 )
return 0LL;
for ( i = 0; i != a3; i += v5 )
{
v5 = write(fd, (const void *)(a2 + i), a3 - i);
if ( v5 <= 0 )
return 0xFFFFFFFFLL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd, __int64 a2, int a3)
{
int i; // ebx
int v5; // eax

if ( !a3 )
return 0LL;
for ( i = 0; i != a3; i += v5 )
{
v5 = write(fd, (const void *)(a2 + i), a3 - i);
if ( v5 <= 0 )
return 0xFFFFFFFFLL;
}
return 0LL;
}

original_code:
int write_data(int fd, const unsigned char *buf, int size)
{
 int cur = 0;
 int ret;
 while (cur != size) {
  ret = write(fd, buf + cur, size - cur);
  if (ret <= 0)
   return -1;
  cur += ret;
 }
 return 0;
}

canonical_original_code:
int write_data(int fd, unsigned char *buf, int size)
{
 int cur = 0;
 int ret;
 while (cur != size) {
  ret = write(fd, buf + cur, size - cur);
  if (ret <= 0)
   return -1;
  cur += ret;
 }
 return 0;
}


decompiled_code:
int __fastcall read_from_proc(const char *a1, __int64 a2, unsigned __int64 a3)
{
int v4; // eax
int v5; // er13
unsigned __int64 v6; // rbx
ssize_t v7; // rax
int *v9; // rax

v4 = open(a1, 0);
if ( v4 < 0 )
{
v9 = _errno_location();
test_msg("FAIL: %s:%d: Can't open cmdline\n (errno = %d)\n", "cmdlinenv00.c", 29LL, (unsigned int)*v9);
exit(1);
}
v5 = v4;
v6 = 0LL;
do
{
v7 = read(v5, (void *)(a2 + v6), a3 - v6);
if ( !v7 )
break;
v6 += v7;
}
while ( a3 > v6 );
return close(v5);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1, __int64 a2, unsigned __int64 a3)
{
int v4; // eax
int v5; // er13
unsigned __int64 v6; // rbx
ssize_t v7; // rax
int *v9; // rax

v4 = open(a1, 0);
if ( v4 < 0 )
{
v9 = _errno_location();
test_msg("FAIL: %s:%d: Can't open cmdline\n (errno = %d)\n", "cmdlinenv00.c", 29LL, (unsigned int)*v9);
exit(1);
}
v5 = v4;
v6 = 0LL;
do
{
v7 = read(v5, (void *)(a2 + v6), a3 - v6);
if ( !v7 )
break;
v6 += v7;
}
while ( a3 > v6 );
return close(v5);
}

original_code:
static void read_from_proc(const char *path, char *buf, size_t size)
{
 size_t r = 0, ret;
 int fd;
 fd = open(path, 00);
 if (fd < 0) {
  test_msg("FAIL: %s:%d: " "Can't open cmdline\n" " (errno = %d)\n", "cmdlinenv00.c", 29, (*__errno_location ()));
  exit(1);
 }
 while (r < size) {
  ret = read(fd, buf + r, size - r);
  if (ret < 0) {
   test_msg("ERR: %s:%d: " "Read failed" " (errno = %d)\n", "cmdlinenv00.c", 36, (*__errno_location ()));
   exit(1);
  } else if (ret == 0) {
   break;
  }
  r += ret;
 }
 close(fd);
}

canonical_original_code:
static void read_from_proc(char *path, char *buf, unsigned long size)
{
 unsigned long r = 0; unsigned long ret;
 int fd;
 fd = open(path, 00);
 if (fd < 0) {
  test_msg("FAIL: %s:%d: " "Can't open cmdline\n" " (errno = %d)\n", "cmdlinenv00.c", 29, (*__errno_location ()));
  exit(1);
 }
 while (r < size) {
  ret = read(fd, buf + r, size - r);
  if (ret < 0) {
   test_msg("ERR: %s:%d: " "Read failed" " (errno = %d)\n", "cmdlinenv00.c", 36, (*__errno_location ()));
   exit(1);
  } else if (ret == 0) {
   break;
  }
  r += ret;
 }
 close(fd);
}

variable_types:
path
char *

variable_types:
buf
char *

variable_types:
size
unsigned long

variable_types:
r
unsigned long

variable_types:
ret
unsigned long

return_type: void


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int *v4; // rax
int *v5; // rax
int *v6; // rax
_BYTE v7[1024]; // [rsp+0h] [rbp-4838h] BYREF
char v8[1024]; // [rsp+400h] [rbp-4438h] BYREF
char s1[4096]; // [rsp+800h] [rbp-4038h] BYREF
char s2[4096]; // [rsp+1800h] [rbp-3038h] BYREF
char v11[4096]; // [rsp+2800h] [rbp-2038h] BYREF
char v12[4152]; // [rsp+3800h] [rbp-1038h] BYREF

memset(s1, 0, sizeof(s1));
memset(s2, 0, sizeof(s2));
memset(v11, 0, sizeof(v11));
memset(v12, 0, 0x1000uLL);
memset(v7, 0, sizeof(v7));
memset(v8, 0, sizeof(v8));
test_init((unsigned int)argc, argv, envp);
read_from_proc("/proc/self/cmdline", (__int64)s1, 0x1000uLL);
read_from_proc("/proc/self/environ", (__int64)v11, 0x1000uLL);
read_from_proc("/proc/self/auxv", (__int64)v7, 0x400uLL);
test_msg("old cmdline: %s\n", s1);
test_msg("old environ: %s\n", v11);
test_daemon();
test_waitsig();
read_from_proc("/proc/self/cmdline", (__int64)s2, 0x1000uLL);
read_from_proc("/proc/self/environ", (__int64)v12, 0x1000uLL);
read_from_proc("/proc/self/auxv", (__int64)v8, 0x400uLL);
test_msg("new cmdline: %s\n", s2);
test_msg("new environ: %s\n", v12);
if ( strncmp(s1, s2, 0x1000uLL) )
{
v4 = _errno_location();
test_msg("FAIL: %s:%d: cmdline corrupted on restore (errno = %d)\n", "cmdlinenv00.c", 83LL, (unsigned int)*v4);
exit(1);
}
if ( strncmp(v11, v12, 0x1000uLL) )
{
v6 = _errno_location();
test_msg("FAIL: %s:%d: envirion corrupted on restore (errno = %d)\n", "cmdlinenv00.c", 88LL, (unsigned int)*v6);
exit(1);
}
if ( memcmp(v7, v8, 0x400uLL) )
{
v5 = _errno_location();
test_msg("FAIL: %s:%d: auxv corrupted on restore (errno = %d)\n", "cmdlinenv00.c", 93LL, (unsigned int)*v5);
exit(1);
}
test_msg("PASS\n");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int *v4; // rax
int *v5; // rax
int *v6; // rax
_BYTE v7[1024]; // [rsp+0h] [rbp-4838h] BYREF
char v8[1024]; // [rsp+400h] [rbp-4438h] BYREF
char s1[4096]; // [rsp+800h] [rbp-4038h] BYREF
char s2[4096]; // [rsp+1800h] [rbp-3038h] BYREF
char v11[4096]; // [rsp+2800h] [rbp-2038h] BYREF
char v12[4152]; // [rsp+3800h] [rbp-1038h] BYREF

memset(s1, 0, sizeof(s1));
memset(s2, 0, sizeof(s2));
memset(v11, 0, sizeof(v11));
memset(v12, 0, 0x1000uLL);
memset(v7, 0, sizeof(v7));
memset(v8, 0, sizeof(v8));
test_init((unsigned int)argc, argv, envp);
func0("/proc/self/cmdline", (__int64)s1, 0x1000uLL);
func0("/proc/self/environ", (__int64)v11, 0x1000uLL);
func0("/proc/self/auxv", (__int64)v7, 0x400uLL);
test_msg("old cmdline: %s\n", s1);
test_msg("old environ: %s\n", v11);
test_daemon();
test_waitsig();
func0("/proc/self/cmdline", (__int64)s2, 0x1000uLL);
func0("/proc/self/environ", (__int64)v12, 0x1000uLL);
func0("/proc/self/auxv", (__int64)v8, 0x400uLL);
test_msg("new cmdline: %s\n", s2);
test_msg("new environ: %s\n", v12);
if ( strncmp(s1, s2, 0x1000uLL) )
{
v4 = _errno_location();
test_msg("FAIL: %s:%d: cmdline corrupted on restore (errno = %d)\n", "cmdlinenv00.c", 83LL, (unsigned int)*v4);
exit(1);
}
if ( strncmp(v11, v12, 0x1000uLL) )
{
v6 = _errno_location();
test_msg("FAIL: %s:%d: envirion corrupted on restore (errno = %d)\n", "cmdlinenv00.c", 88LL, (unsigned int)*v6);
exit(1);
}
if ( memcmp(v7, v8, 0x400uLL) )
{
v5 = _errno_location();
test_msg("FAIL: %s:%d: auxv corrupted on restore (errno = %d)\n", "cmdlinenv00.c", 93LL, (unsigned int)*v5);
exit(1);
}
test_msg("PASS\n");
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 char cmdline_orig[4096];
 char cmdline[4096];
 char env_orig[4096];
 char env[4096];
 char auxv_orig[1024];
 char auxv[1024];
 memset(cmdline_orig, 0, sizeof(cmdline_orig));
 memset(cmdline, 0, sizeof(cmdline));
 memset(env_orig, 0, sizeof(env_orig));
 memset(env, 0, sizeof(env));
 memset(auxv_orig, 0, sizeof(auxv_orig));
 memset(auxv, 0, sizeof(auxv));
 test_init(argc, argv);
 read_from_proc("/proc/self/cmdline", cmdline_orig, sizeof(cmdline_orig));
 read_from_proc("/proc/self/environ", env_orig, sizeof(env_orig));
 read_from_proc("/proc/self/auxv", auxv_orig, sizeof(auxv_orig));
 test_msg("old cmdline: %s\n", cmdline_orig);
 test_msg("old environ: %s\n", env_orig);
 test_daemon();
 test_waitsig();
 read_from_proc("/proc/self/cmdline", cmdline, sizeof(cmdline));
 read_from_proc("/proc/self/environ", env, sizeof(env));
 read_from_proc("/proc/self/auxv", auxv, sizeof(auxv));
 test_msg("new cmdline: %s\n", cmdline);
 test_msg("new environ: %s\n", env);
 if (strncmp(cmdline_orig, cmdline, sizeof(cmdline_orig))) {
  test_msg("FAIL: %s:%d: " "cmdline corrupted on restore" " (errno = %d)\n", "cmdlinenv00.c", 83, (*__errno_location ()));
  exit(1);
 }
 if (strncmp(env_orig, env, sizeof(env_orig))) {
  test_msg("FAIL: %s:%d: " "envirion corrupted on restore" " (errno = %d)\n", "cmdlinenv00.c", 88, (*__errno_location ()));
  exit(1);
 }
 if (memcmp(auxv_orig, auxv, sizeof(auxv_orig))) {
  test_msg("FAIL: %s:%d: " "auxv corrupted on restore" " (errno = %d)\n", "cmdlinenv00.c", 93, (*__errno_location ()));
  exit(1);
 }
 test_msg("PASS\n");
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
cmdline
char [4096]

variable_types:
env
char [4096]

variable_types:
auxv
char [1024]


decompiled_code:
__int64 __fastcall fork_child(int a1)
{
unsigned int v1; // er12
__pid_t v2; // eax
int v3; // eax
int v4; // eax
int *v5; // rax
int v7; // ebp
unsigned int v8; // er13
__int64 v9; // rbx
int *v10; // rax
__pid_t v11; // edx
__pid_t v12; // eax
int *v13; // rax
int *v14; // rbx
__pid_t v15; // edi
__pid_t v16; // eax
int *v17; // rax
int *v18; // rax
int *v19; // rax
int *v20; // rax
__int64 v21; // rdx
__int64 v22; // rcx
int *v23; // rax
int *v24; // rax
int *v25; // rax
__pid_t pid; // [rsp+0h] [rbp-38h] BYREF
__WAIT_STATUS stat_loc; // [rsp+4h] [rbp-34h] BYREF
int v28; // [rsp+Ch] [rbp-2Ch]

if ( pipe((int *)&stat_loc.__iptr + 1) )
{
v5 = _errno_location();
v1 = 1;
test_msg("ERR: %s:%d: pipe() failed (errno = %d)\n", "session00.c", 52LL, (unsigned int)*v5);
}
else
{
v1 = 0;
v2 = test_fork_id(0xFFFFFFFFLL);
pid = v2;
if ( v2 < 0 )
{
v13 = _errno_location();
v1 = 1;
test_msg("ERR: %s:%d: Can't fork (errno = %d)\n", "session00.c", 58LL, (unsigned int)*v13);
}
else
{
if ( !v2 )
{
v3 = testcases[3 * a1];
if ( (v3 & 2) != 0 )
{
LODWORD(stat_loc.__uptr) = setsid();
if ( LODWORD(stat_loc.__uptr) == -1 )
{
v20 = _errno_location();
v21 = 66LL;
v22 = (unsigned int)*v20;
goto LABEL_36;
}
v3 = testcases[3 * a1];
v11 = pid;
if ( (v3 & 5) == 0 )
{
LABEL_20:
if ( v11 )
{
if ( (v3 & 4) == 0 )
goto LABEL_24;
LODWORD(stat_loc.__uptr) = setsid();
if ( LODWORD(stat_loc.__uptr) != -1 )
{
wait(0LL);
v12 = getpid();
if ( getsid(v12) != LODWORD(stat_loc.__uptr) )
{
v24 = _errno_location();
test_msg(
"FAIL: %s:%d: The process %d (%x) has SID=%d (expected %d) (errno = %d)\n",
"session00.c",
93LL,
(unsigned int)pid,
(unsigned int)testcases[3 * a1],
LODWORD(stat_loc.__uptr),
(unsigned int)dword_3E8[3 * a1],
(unsigned int)*v24);
LABEL_31:
exit(1);
}
LABEL_24:
exit(0);
}
v25 = _errno_location();
v21 = 86LL;
v22 = (unsigned int)*v25;
LABEL_36:
test_msg("ERR: %s:%d: setsid failed (errno = %d)\n", "session00.c", v21, v22);
write(v28, &stat_loc, 4uLL);
exit(1);
}
goto LABEL_6;
}
}
else if ( (v3 & 5) == 0 )
{
LABEL_6:
if ( (v3 & 8) == 0 )
{
LABEL_9:
pid = getpid();
write(v28, &pid, 4uLL);
close(v28);
test_waitsig();
test_msg("PASS\n");
goto LABEL_24;
}
v4 = fork();
pid = v4;
if ( v4 >= 0 )
{
if ( !v4 )
goto LABEL_9;
LODWORD(stat_loc.__uptr) = setsid();
if ( LODWORD(stat_loc.__uptr) != -1 )
{
wait(0LL);
v16 = getpid();
if ( getsid(v16) != LODWORD(stat_loc.__uptr) )
{
v17 = _errno_location();
test_msg(
"FAIL: %s:%d: The process %d (%x) has SID=%d (expected %d) (errno = %d)\n",
"session00.c",
119LL,
(unsigned int)pid,
(unsigned int)testcases[3 * a1],
LODWORD(stat_loc.__uptr),
(unsigned int)dword_3E8[3 * a1],
(unsigned int)*v17);
goto LABEL_31;
}
goto LABEL_24;
}
v23 = _errno_location();
v21 = 112LL;
v22 = (unsigned int)*v23;
goto LABEL_36;
}
LABEL_34:
write(v28, &pid, 4uLL);
exit(1);
}
pid = test_fork_id(0xFFFFFFFFLL);
v11 = pid;
if ( pid < 0 )
goto LABEL_34;
v3 = testcases[3 * a1];
goto LABEL_20;
}
close(v28);
v7 = testcases[3 * a1] & 1;
if ( v7 && (v8 = wait((__WAIT_STATUS)&stat_loc), pid != v8) )
{
v18 = _errno_location();
v1 = v7;
test_msg(
"ERR: %s:%d: wait return %d instead of %d (errno = %d)\n",
"session00.c",
142LL,
v8,
(unsigned int)pid,
(unsigned int)*v18);
kill(pid, 9);
}
else
{
v9 = 3LL * a1;
if ( (unsigned int)read(SHIDWORD(stat_loc.__iptr), (char *)&unk_3E4 + v9 * 4, 4uLL) == 4 )
{
v14 = &testcases[v9];
close(SHIDWORD(stat_loc.__iptr));
v15 = v14[1];
if ( v15 < 0 )
{
v19 = _errno_location();
v1 = 1;
test_msg("ERR: %s:%d: child failed (errno = %d)\n", "session00.c", 157LL, (unsigned int)*v19);
}
else
{
v14[2] = getsid(v15);
}
}
else
{
v10 = _errno_location();
v1 = 1;
test_msg("ERR: %s:%d: read failed (errno = %d)\n", "session00.c", 150LL, (unsigned int)*v10);
}
}
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
unsigned int v1; // er12
__pid_t v2; // eax
int v3; // eax
int v4; // eax
int *v5; // rax
int v7; // ebp
unsigned int v8; // er13
__int64 v9; // rbx
int *v10; // rax
__pid_t v11; // edx
__pid_t v12; // eax
int *v13; // rax
int *v14; // rbx
__pid_t v15; // edi
__pid_t v16; // eax
int *v17; // rax
int *v18; // rax
int *v19; // rax
int *v20; // rax
__int64 v21; // rdx
__int64 v22; // rcx
int *v23; // rax
int *v24; // rax
int *v25; // rax
__pid_t pid; // [rsp+0h] [rbp-38h] BYREF
__WAIT_STATUS stat_loc; // [rsp+4h] [rbp-34h] BYREF
int v28; // [rsp+Ch] [rbp-2Ch]

if ( pipe((int *)&stat_loc.__iptr + 1) )
{
v5 = _errno_location();
v1 = 1;
test_msg("ERR: %s:%d: pipe() failed (errno = %d)\n", "session00.c", 52LL, (unsigned int)*v5);
}
else
{
v1 = 0;
v2 = test_fork_id(0xFFFFFFFFLL);
pid = v2;
if ( v2 < 0 )
{
v13 = _errno_location();
v1 = 1;
test_msg("ERR: %s:%d: Can't fork (errno = %d)\n", "session00.c", 58LL, (unsigned int)*v13);
}
else
{
if ( !v2 )
{
v3 = testcases[3 * a1];
if ( (v3 & 2) != 0 )
{
LODWORD(stat_loc.__uptr) = setsid();
if ( LODWORD(stat_loc.__uptr) == -1 )
{
v20 = _errno_location();
v21 = 66LL;
v22 = (unsigned int)*v20;
goto LABEL_36;
}
v3 = testcases[3 * a1];
v11 = pid;
if ( (v3 & 5) == 0 )
{
LABEL_20:
if ( v11 )
{
if ( (v3 & 4) == 0 )
goto LABEL_24;
LODWORD(stat_loc.__uptr) = setsid();
if ( LODWORD(stat_loc.__uptr) != -1 )
{
wait(0LL);
v12 = getpid();
if ( getsid(v12) != LODWORD(stat_loc.__uptr) )
{
v24 = _errno_location();
test_msg(
"FAIL: %s:%d: The process %d (%x) has SID=%d (expected %d) (errno = %d)\n",
"session00.c",
93LL,
(unsigned int)pid,
(unsigned int)testcases[3 * a1],
LODWORD(stat_loc.__uptr),
(unsigned int)dword_3E8[3 * a1],
(unsigned int)*v24);
LABEL_31:
exit(1);
}
LABEL_24:
exit(0);
}
v25 = _errno_location();
v21 = 86LL;
v22 = (unsigned int)*v25;
LABEL_36:
test_msg("ERR: %s:%d: setsid failed (errno = %d)\n", "session00.c", v21, v22);
write(v28, &stat_loc, 4uLL);
exit(1);
}
goto LABEL_6;
}
}
else if ( (v3 & 5) == 0 )
{
LABEL_6:
if ( (v3 & 8) == 0 )
{
LABEL_9:
pid = getpid();
write(v28, &pid, 4uLL);
close(v28);
test_waitsig();
test_msg("PASS\n");
goto LABEL_24;
}
v4 = fork();
pid = v4;
if ( v4 >= 0 )
{
if ( !v4 )
goto LABEL_9;
LODWORD(stat_loc.__uptr) = setsid();
if ( LODWORD(stat_loc.__uptr) != -1 )
{
wait(0LL);
v16 = getpid();
if ( getsid(v16) != LODWORD(stat_loc.__uptr) )
{
v17 = _errno_location();
test_msg(
"FAIL: %s:%d: The process %d (%x) has SID=%d (expected %d) (errno = %d)\n",
"session00.c",
119LL,
(unsigned int)pid,
(unsigned int)testcases[3 * a1],
LODWORD(stat_loc.__uptr),
(unsigned int)dword_3E8[3 * a1],
(unsigned int)*v17);
goto LABEL_31;
}
goto LABEL_24;
}
v23 = _errno_location();
v21 = 112LL;
v22 = (unsigned int)*v23;
goto LABEL_36;
}
LABEL_34:
write(v28, &pid, 4uLL);
exit(1);
}
pid = test_fork_id(0xFFFFFFFFLL);
v11 = pid;
if ( pid < 0 )
goto LABEL_34;
v3 = testcases[3 * a1];
goto LABEL_20;
}
close(v28);
v7 = testcases[3 * a1] & 1;
if ( v7 && (v8 = wait((__WAIT_STATUS)&stat_loc), pid != v8) )
{
v18 = _errno_location();
v1 = v7;
test_msg(
"ERR: %s:%d: wait return %d instead of %d (errno = %d)\n",
"session00.c",
142LL,
v8,
(unsigned int)pid,
(unsigned int)*v18);
kill(pid, 9);
}
else
{
v9 = 3LL * a1;
if ( (unsigned int)read(SHIDWORD(stat_loc.__iptr), (char *)&unk_3E4 + v9 * 4, 4uLL) == 4 )
{
v14 = &testcases[v9];
close(SHIDWORD(stat_loc.__iptr));
v15 = v14[1];
if ( v15 < 0 )
{
v19 = _errno_location();
v1 = 1;
test_msg("ERR: %s:%d: child failed (errno = %d)\n", "session00.c", 157LL, (unsigned int)*v19);
}
else
{
v14[2] = getsid(v15);
}
}
else
{
v10 = _errno_location();
v1 = 1;
test_msg("ERR: %s:%d: read failed (errno = %d)\n", "session00.c", 150LL, (unsigned int)*v10);
}
}
}
}
return v1;
}

original_code:
static int fork_child(int i)
{
 int p[2];
 int status, ret;
 pid_t pid, sid;
 ret = pipe(p);
 if (ret) {
  test_msg("ERR: %s:%d: " "pipe() failed" " (errno = %d)\n", "session00.c", 52, (*__errno_location ()));
  return 1;
 }
 pid = test_fork_id(-1);
 if (pid < 0) {
  test_msg("ERR: %s:%d: " "Can't fork" " (errno = %d)\n", "session00.c", 58, (*__errno_location ()));
  return 1;
 }
 if (pid == 0) {
  if (testcases[i].flags & 2) {
   sid = setsid();
   if (sid == -1) {
    test_msg("ERR: %s:%d: " "setsid failed" " (errno = %d)\n", "session00.c", 66, (*__errno_location ()));
    write(p[1], &sid, sizeof(sid));
    exit(1);
   }
  }
  if (testcases[i].flags & (1 | 4)) {
   pid = test_fork_id(-1);
   if (pid < 0) {
    write(p[1], &pid, sizeof(pid));
    exit(1);
   }
  }
  if (pid != 0) {
   if (!(testcases[i].flags & 4))
    exit(0);
   sid = setsid();
   if (sid == -1) {
    test_msg("ERR: %s:%d: " "setsid failed" " (errno = %d)\n", "session00.c", 86, (*__errno_location ()));
    write(p[1], &sid, sizeof(sid));
    exit(1);
   }
   wait(((void *)0));
   if (getsid(getpid()) != sid) {
    test_msg("FAIL: %s:%d: " "The process %d (%x) has SID=%d (expected %d)" " (errno = %d)\n", "session00.c", 93, pid, testcases[i].flags, sid, testcases[i].sid, (*__errno_location ()));
    exit(1);
   }
   exit(0);
  }
  if (testcases[i].flags & 8) {
   pid = fork();
   if (pid < 0) {
    write(p[1], &pid, sizeof(pid));
    exit(1);
   }
   if (pid == 0)
    goto child;
   sid = setsid();
   if (sid == -1) {
    test_msg("ERR: %s:%d: " "setsid failed" " (errno = %d)\n", "session00.c", 112, (*__errno_location ()));
    write(p[1], &sid, sizeof(sid));
    exit(1);
   }
   wait(((void *)0));
   if (getsid(getpid()) != sid) {
    test_msg("FAIL: %s:%d: " "The process %d (%x) has SID=%d (expected %d)" " (errno = %d)\n", "session00.c", 119, pid, testcases[i].flags, sid, testcases[i].sid, (*__errno_location ()));
    exit(1);
   }
   exit(0);
  }
child:
  pid = getpid();
  write(p[1], &pid, sizeof(pid));
  close(p[1]);
  test_waitsig();
  test_msg("PASS\n");
  exit(0);
 }
 close(p[1]);
 if (testcases[i].flags & 1) {
  pid_t ret;
  ret = wait(&status);
  if (ret != pid) {
   test_msg("ERR: %s:%d: " "wait return %d instead of %d" " (errno = %d)\n", "session00.c", 142, ret, pid, (*__errno_location ()));
   kill(pid, 9);
   return 1;
  }
 }
 ret = read(p[0], &testcases[i].pid, sizeof(pid));
 if (ret != sizeof(ret)) {
  test_msg("ERR: %s:%d: " "read failed" " (errno = %d)\n", "session00.c", 150, (*__errno_location ()));
  return 1;
 }
 close(p[0]);
 if (testcases[i].pid < 0) {
  test_msg("ERR: %s:%d: " "child failed" " (errno = %d)\n", "session00.c", 157, (*__errno_location ()));
  return 1;
 }
 testcases[i].sid = getsid(testcases[i].pid);
 return 0;
}

canonical_original_code:
static int fork_child(int i)
{
 int p[2];
 int status; int ret;
 int pid; int sid;
 ret = pipe(p);
 if (ret) {
  test_msg("ERR: %s:%d: " "pipe() failed" " (errno = %d)\n", "session00.c", 52, (*__errno_location ()));
  return 1;
 }
 pid = test_fork_id(-1);
 if (pid < 0) {
  test_msg("ERR: %s:%d: " "Can't fork" " (errno = %d)\n", "session00.c", 58, (*__errno_location ()));
  return 1;
 }
 if (pid == 0) {
  if (testcases[i].flags & 2) {
   sid = setsid();
   if (sid == -1) {
    test_msg("ERR: %s:%d: " "setsid failed" " (errno = %d)\n", "session00.c", 66, (*__errno_location ()));
    write(p[1], &sid, sizeof(sid));
    exit(1);
   }
  }
  if (testcases[i].flags & (1 | 4)) {
   pid = test_fork_id(-1);
   if (pid < 0) {
    write(p[1], &pid, sizeof(pid));
    exit(1);
   }
  }
  if (pid != 0) {
   if (!(testcases[i].flags & 4))
    exit(0);
   sid = setsid();
   if (sid == -1) {
    test_msg("ERR: %s:%d: " "setsid failed" " (errno = %d)\n", "session00.c", 86, (*__errno_location ()));
    write(p[1], &sid, sizeof(sid));
    exit(1);
   }
   wait(((void *)0));
   if (getsid(getpid()) != sid) {
    test_msg("FAIL: %s:%d: " "The process %d (%x) has SID=%d (expected %d)" " (errno = %d)\n", "session00.c", 93, pid, testcases[i].flags, sid, testcases[i].sid, (*__errno_location ()));
    exit(1);
   }
   exit(0);
  }
  if (testcases[i].flags & 8) {
   pid = fork();
   if (pid < 0) {
    write(p[1], &pid, sizeof(pid));
    exit(1);
   }
   if (pid == 0)
    goto child;
   sid = setsid();
   if (sid == -1) {
    test_msg("ERR: %s:%d: " "setsid failed" " (errno = %d)\n", "session00.c", 112, (*__errno_location ()));
    write(p[1], &sid, sizeof(sid));
    exit(1);
   }
   wait(((void *)0));
   if (getsid(getpid()) != sid) {
    test_msg("FAIL: %s:%d: " "The process %d (%x) has SID=%d (expected %d)" " (errno = %d)\n", "session00.c", 119, pid, testcases[i].flags, sid, testcases[i].sid, (*__errno_location ()));
    exit(1);
   }
   exit(0);
  }
child:
  pid = getpid();
  write(p[1], &pid, sizeof(pid));
  close(p[1]);
  test_waitsig();
  test_msg("PASS\n");
  exit(0);
 }
 close(p[1]);
 if (testcases[i].flags & 1) {
  int ret;
  ret = wait(&status);
  if (ret != pid) {
   test_msg("ERR: %s:%d: " "wait return %d instead of %d" " (errno = %d)\n", "session00.c", 142, ret, pid, (*__errno_location ()));
   kill(pid, 9);
   return 1;
  }
 }
 ret = read(p[0], &testcases[i].pid, sizeof(pid));
 if (ret != sizeof(ret)) {
  test_msg("ERR: %s:%d: " "read failed" " (errno = %d)\n", "session00.c", 150, (*__errno_location ()));
  return 1;
 }
 close(p[0]);
 if (testcases[i].pid < 0) {
  test_msg("ERR: %s:%d: " "child failed" " (errno = %d)\n", "session00.c", 157, (*__errno_location ()));
  return 1;
 }
 testcases[i].sid = getsid(testcases[i].pid);
 return 0;
}

variable_types: i int

variable_types:
p
int [2]

variable_types: status int

variable_types: ret int

variable_types: pid int

variable_types: sid int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
int v4; // ebx
unsigned int *v5; // rbp
unsigned int *v6; // r13
unsigned int v7; // er12
__int64 v8; // r9
__int64 v9; // rax
unsigned int v10; // er12
__int64 v11; // r8
__int64 v12; // rax
__pid_t *v13; // rbx
__pid_t *v14; // rbp
__pid_t v15; // edi
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-2Ch] BYREF

v3 = 0;
test_init(argc, argv, envp);
while ( 1 )
{
v4 = fork_child(v3);
if ( v4 )
break;
if ( ++v3 == 6 )
{
test_daemon();
v5 = (unsigned int *)testcases;
test_waitsig();
v6 = (unsigned int *)_errno_location();
do
{
v7 = v5[1];
v8 = (unsigned int)getsid(v7);
v9 = v5[2];
if ( (_DWORD)v9 != (_DWORD)v8 )
{
++v4;
test_msg(
"FAIL: %s:%d: The process %d (%x) has SID=%d (expected %d) (errno = %d)\n",
"session00.c",
193LL,
v7,
*v5,
v8,
v9,
*v6);
}
if ( kill(v7, 9) == -1 )
{
++v4;
test_msg("ERR: %s:%d: kill failed (errno = %d)\n", "session00.c", 200LL, *v6);
}
waitpid(v7, 0LL, 0);
if ( (*(_BYTE *)v5 & 4) != 0 )
{
v10 = wait((__WAIT_STATUS)&stat_loc);
if ( v10 == -1 )
{
++v4;
test_msg("ERR: %s:%d: wait() failed (errno = %d)\n", "session00.c", 208LL, *v6);
}
if ( (__int64)stat_loc.__uptr & 0x7F | BYTE1(stat_loc.__uptr) )
{
++v4;
test_msg(
"FAIL: %s:%d: The process with pid %d returns %d\n (errno = %d)\n",
"session00.c",
212LL,
v10,
LODWORD(stat_loc.__uptr),
*v6);
}
}
v5 += 3;
}
while ( &test_author != (char **)v5 );
if ( wait((__WAIT_STATUS)&stat_loc) == -1 && *v6 == 10 )
{
if ( !v4 )
test_msg("PASS\n");
}
else
{
++v4;
test_msg("ERR: %s:%d: %d isn't waited (errno = %d)\n", "session00.c", 220LL, *v6, v11);
}
return v4 > 0;
}
}
if ( v3 )
{
v13 = (__pid_t *)&unk_3E4;
v14 = (__pid_t *)((char *)&unk_3F0 + 12 * (unsigned int)(v3 - 1));
do
{
v15 = *v13;
v13 += 3;
kill(v15, 15);
}
while ( v14 != v13 );
}
LODWORD(v12) = 1;
return v12;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
int v4; // ebx
unsigned int *v5; // rbp
unsigned int *v6; // r13
unsigned int v7; // er12
__int64 v8; // r9
__int64 v9; // rax
unsigned int v10; // er12
__int64 v11; // r8
__int64 v12; // rax
__pid_t *v13; // rbx
__pid_t *v14; // rbp
__pid_t v15; // edi
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-2Ch] BYREF

v3 = 0;
test_init(argc, argv, envp);
while ( 1 )
{
v4 = func0(v3);
if ( v4 )
break;
if ( ++v3 == 6 )
{
test_daemon();
v5 = (unsigned int *)testcases;
test_waitsig();
v6 = (unsigned int *)_errno_location();
do
{
v7 = v5[1];
v8 = (unsigned int)getsid(v7);
v9 = v5[2];
if ( (_DWORD)v9 != (_DWORD)v8 )
{
++v4;
test_msg(
"FAIL: %s:%d: The process %d (%x) has SID=%d (expected %d) (errno = %d)\n",
"session00.c",
193LL,
v7,
*v5,
v8,
v9,
*v6);
}
if ( kill(v7, 9) == -1 )
{
++v4;
test_msg("ERR: %s:%d: kill failed (errno = %d)\n", "session00.c", 200LL, *v6);
}
waitpid(v7, 0LL, 0);
if ( (*(_BYTE *)v5 & 4) != 0 )
{
v10 = wait((__WAIT_STATUS)&stat_loc);
if ( v10 == -1 )
{
++v4;
test_msg("ERR: %s:%d: wait() failed (errno = %d)\n", "session00.c", 208LL, *v6);
}
if ( (__int64)stat_loc.__uptr & 0x7F | BYTE1(stat_loc.__uptr) )
{
++v4;
test_msg(
"FAIL: %s:%d: The process with pid %d returns %d\n (errno = %d)\n",
"session00.c",
212LL,
v10,
LODWORD(stat_loc.__uptr),
*v6);
}
}
v5 += 3;
}
while ( &test_author != (char **)v5 );
if ( wait((__WAIT_STATUS)&stat_loc) == -1 && *v6 == 10 )
{
if ( !v4 )
test_msg("PASS\n");
}
else
{
++v4;
test_msg("ERR: %s:%d: %d isn't waited (errno = %d)\n", "session00.c", 220LL, *v6, v11);
}
return v4 > 0;
}
}
if ( v3 )
{
v13 = (__pid_t *)&unk_3E4;
v14 = (__pid_t *)((char *)&unk_3F0 + 12 * (unsigned int)(v3 - 1));
do
{
v15 = *v13;
v13 += 3;
kill(v15, 15);
}
while ( v14 != v13 );
}
LODWORD(v12) = 1;
return v12;
}

original_code:
int main(int argc, char ** argv)
{
 int i, ret, err = 0, status;
 pid_t pid;
 test_init(argc, argv);
 for (i = 0; i < (sizeof(testcases) / sizeof(struct testcase)); i++)
  if (fork_child(i))
   break;
 if (i != (sizeof(testcases) / sizeof(struct testcase))) {
  int j;
  for (j = 0; j < i; j++)
   kill(testcases[j].pid, 15);
  return 1;
 }
 test_daemon();
 test_waitsig();
 for (i = 0; i < (sizeof(testcases) / sizeof(struct testcase)); i++) {
  pid_t pid = testcases[i].pid;
  pid_t sid = getsid(pid);
  if (sid != testcases[i].sid) {
   test_msg("FAIL: %s:%d: " "The process %d (%x) has SID=%d (expected %d)" " (errno = %d)\n", "session00.c", 193, pid, testcases[i].flags, sid, testcases[i].sid, (*__errno_location ()));
   err++;
  }
  ret = kill(pid, 9);
  if (ret == -1) {
   test_msg("ERR: %s:%d: " "kill failed" " (errno = %d)\n", "session00.c", 200, (*__errno_location ()));
   err++;
  }
  waitpid(pid, ((void *)0), 0);
  if (testcases[i].flags & 4) {
   pid = wait(&status);
   if (pid == -1) {
    test_msg("ERR: %s:%d: " "wait() failed" " (errno = %d)\n", "session00.c", 208, (*__errno_location ()));
    err++;
   }
   if (!(((status) & 0x7f) == 0) || (((status) & 0xff00) >> 8)) {
    test_msg("FAIL: %s:%d: " "The process with pid %d returns %d\n" " (errno = %d)\n", "session00.c", 212, pid, status, (*__errno_location ()));
    err++;
   }
  }
 }
 pid = wait(&status);
 if (pid != -1 || (*__errno_location ()) != 10) {
  test_msg("ERR: %s:%d: " "%d isn't waited" " (errno = %d)\n", "session00.c", 220, (*__errno_location ()));
  err++;
 }
 if (!err)
  test_msg("PASS\n");
 return err > 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int i; int ret; int err = 0; int status;
 int pid;
 test_init(argc, argv);
 for (i = 0; i < (sizeof(testcases) / sizeof(struct testcase)); i++)
  if (fork_child(i))
   break;
 if (i != (sizeof(testcases) / sizeof(struct testcase))) {
  int j;
  for (j = 0; j < i; j++)
   kill(testcases[j].pid, 15);
  return 1;
 }
 test_daemon();
 test_waitsig();
 for (i = 0; i < (sizeof(testcases) / sizeof(struct testcase)); i++) {
  int pid = testcases[i].pid;
  int sid = getsid(pid);
  if (sid != testcases[i].sid) {
   test_msg("FAIL: %s:%d: " "The process %d (%x) has SID=%d (expected %d)" " (errno = %d)\n", "session00.c", 193, pid, testcases[i].flags, sid, testcases[i].sid, (*__errno_location ()));
   err++;
  }
  ret = kill(pid, 9);
  if (ret == -1) {
   test_msg("ERR: %s:%d: " "kill failed" " (errno = %d)\n", "session00.c", 200, (*__errno_location ()));
   err++;
  }
  waitpid(pid, ((void *)0), 0);
  if (testcases[i].flags & 4) {
   pid = wait(&status);
   if (pid == -1) {
    test_msg("ERR: %s:%d: " "wait() failed" " (errno = %d)\n", "session00.c", 208, (*__errno_location ()));
    err++;
   }
   if (!(((status) & 0x7f) == 0) || (((status) & 0xff00) >> 8)) {
    test_msg("FAIL: %s:%d: " "The process with pid %d returns %d\n" " (errno = %d)\n", "session00.c", 212, pid, status, (*__errno_location ()));
    err++;
   }
  }
 }
 pid = wait(&status);
 if (pid != -1 || (*__errno_location ()) != 10) {
  test_msg("ERR: %s:%d: " "%d isn't waited" " (errno = %d)\n", "session00.c", 220, (*__errno_location ()));
  err++;
 }
 if (!err)
  test_msg("PASS\n");
 return err > 0;
}

variable_types:
argv
char **

variable_types: err int

variable_types: j int

user_defined_types: struct testcase { int flags; int pid; int sid; }


thread

decompiled_code:
void __fastcall __noreturn thread(void *a1)
{
*(_DWORD *)a1 = syscall(186LL);
while ( 1 )
sleep(1u);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(void *a1)
{
*(_DWORD *)a1 = syscall(186LL);
while ( 1 )
sleep(1u);
}

original_code:
static void *thread(void *arg)
{
 *(int *)arg = syscall(186);
 while (1)
  sleep(1);
 return ((void *)0);
}

variable_types:
arg
void *

return_type: void *


decompiled_code:
void do_stop()
{
stop = 1;
}

canonical_decompiled_code:
void func0()
{
stop = 1;
}

original_code:
static void do_stop(int sig)
{
 stop = 1;
}

variable_types: sig int


decompiled_code:
void __fastcall __noreturn run_child(int a1)
{
int v1; // er14
__int64 v2; // r13
int v3; // edi
int v4; // ebx
__int64 v5; // rcx
_BYTE v6[524]; // [rsp+0h] [rbp-250h] BYREF
int v7; // [rsp+20Ch] [rbp-44h] BYREF
struct timeval tv; // [rsp+210h] [rbp-40h] BYREF
struct timespec requested_time; // [rsp+220h] [rbp-30h] BYREF

v1 = 1;
v2 = a1;
v3 = fds[2 * a1];
v7 = -1;
v4 = dword_224[2 * v2];
close(v3);
datagen(v6, 512LL, &v7);
if ( gettimeofday(&tv, 0LL) >= 0 )
{
srand(LODWORD(tv.tv_sec) + LODWORD(tv.tv_usec));
requested_time.tv_sec = 0LL;
while ( !stop )
{
requested_time.tv_nsec = rand() % 999999999;
nanosleep(&requested_time, &requested_time);
if ( write(v4, v6, 0x200uLL) < 0 )
{
v5 = (unsigned int)*_errno_location();
if ( !stop || (_DWORD)v5 != 4 && (_DWORD)v5 != 32 )
{
test_msg("FAIL: %s:%d: child write: %m\n (errno = %d)\n", "epoll.c", 85LL, v5);
v1 = 2;
goto LABEL_9;
}
}
}
v1 = 0;
}
LABEL_9:
close(dword_224[2 * v2]);
exit(v1);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(int a1)
{
int v1; // er14
__int64 v2; // r13
int v3; // edi
int v4; // ebx
__int64 v5; // rcx
_BYTE v6[524]; // [rsp+0h] [rbp-250h] BYREF
int v7; // [rsp+20Ch] [rbp-44h] BYREF
struct timeval tv; // [rsp+210h] [rbp-40h] BYREF
struct timespec requested_time; // [rsp+220h] [rbp-30h] BYREF

v1 = 1;
v2 = a1;
v3 = fds[2 * a1];
v7 = -1;
v4 = dword_224[2 * v2];
close(v3);
datagen(v6, 512LL, &v7);
if ( gettimeofday(&tv, 0LL) >= 0 )
{
srand(LODWORD(tv.tv_sec) + LODWORD(tv.tv_usec));
requested_time.tv_sec = 0LL;
while ( !stop )
{
requested_time.tv_nsec = rand() % 999999999;
nanosleep(&requested_time, &requested_time);
if ( write(v4, v6, 0x200uLL) < 0 )
{
v5 = (unsigned int)*_errno_location();
if ( !stop || (_DWORD)v5 != 4 && (_DWORD)v5 != 32 )
{
test_msg("FAIL: %s:%d: child write: %m\n (errno = %d)\n", "epoll.c", 85LL, v5);
v1 = 2;
goto LABEL_9;
}
}
}
v1 = 0;
}
LABEL_9:
close(dword_224[2 * v2]);
exit(v1);
}

original_code:
static void run_child(int num)
{
 int fd = fds[num][1];
 uint32_t crc = ~0;
 size_t buf_size=512;
 uint8_t buf[buf_size];
 struct timeval tv;
 struct timespec ts;
 int rv;
 close(fds[num][0]);
 datagen(buf, sizeof(buf), &crc);
 if (gettimeofday(&tv, ((void *)0)) < 0) {
  rv = GETTIMEOFDAYERROR;
  goto out;
 }
 srand(tv.tv_sec + tv.tv_usec);
 ts.tv_sec = 0;
 while (!stop) {
  ts.tv_nsec = rand() % 999999999;
  nanosleep(&ts, &ts);
  if (write(fd, buf, buf_size) < 0 &&
   (!stop ||
    ((*__errno_location ()) != 4 && (*__errno_location ()) != 32))) {
   test_msg("FAIL: %s:%d: " "child write: %m\n" " (errno = %d)\n", "epoll.c", 85, (*__errno_location ()));
   rv = WRITEERROR;
   goto out;
  }
 }
 rv = SUCCESS;
out: close(fds[num][1]);
 exit(rv);
}

canonical_original_code:
static void run_child(int num)
{
 int fd = fds[num][1];
 unsigned int crc = ~0;
 unsigned long buf_size = 512;
 unsigned char buf[-1];
 struct timeval tv;
 struct timespec ts;
 int rv;
 close(fds[num][0]);
 datagen(buf, sizeof(buf), &crc);
 if (gettimeofday(&tv, ((void *)0)) < 0) {
  rv = GETTIMEOFDAYERROR;
  goto out;
 }
 srand(tv.tv_sec + tv.tv_usec);
 ts.tv_sec = 0;
 while (!stop) {
  ts.tv_nsec = rand() % 999999999;
  nanosleep(&ts, &ts);
  if (write(fd, buf, buf_size) < 0 &&
   (!stop ||
    ((*__errno_location ()) != 4 && (*__errno_location ()) != 32))) {
   test_msg("FAIL: %s:%d: " "child write: %m\n" " (errno = %d)\n", "epoll.c", 85, (*__errno_location ()));
   rv = WRITEERROR;
   goto out;
  }
 }
 rv = SUCCESS;
out: close(fds[num][1]);
 exit(rv);
}

variable_types: num int

variable_types: fd int

variable_types:
crc
unsigned int

variable_types:
buf
unsigned char [-1]

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

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

variable_types: rv int


decompiled_code:
__int64 chk_proc_fpu()
{
_RAX = 1LL;
__asm { cpuid }
return _RDX & 1;
}

canonical_decompiled_code:
__int64 func2()
{
_RAX = 1LL;
__asm { cpuid }
return _RDX & 1;
}

original_code:
int chk_proc_fpu(void)
{
 unsigned long fi;
 __asm__ volatile (
   "mov $1, %%eax\n"
   "cpuid\n"
   : "=d" (fi) : : "eax"
  );
 return fi & (1 << 0);
}

canonical_original_code:
int chk_proc_fpu()
{
 unsigned long fi;
 __asm__ volatile (
   "mov $1, %%eax\n"
   "cpuid\n"
   : "=d" (fi) : : "eax"
  );
 return fi & (1 << 0);
}

variable_types:
fi
unsigned long


start

decompiled_code:
long double __fastcall start(float a1, float a2, float a3, float a4)
{
return (a1 + a2) * (a3 + a4);
}

canonical_decompiled_code:
long double __fastcall func0(float a1, float a2, float a3, float a4)
{
return (a1 + a2) * (a3 + a4);
}

original_code:
void start(float a, float b, float c, float d)
{
 __asm__ volatile (
     "fld	%0\n"
     "fadd	%1\n"
     "fld	%2\n"
     "fadd	%3\n"
     "fmulp %%st(1)\n"
     :
     : "m" (a), "m" (b), "m" (c), "m" (d)
    );
}

variable_types: a float

variable_types: b float

variable_types: c float

variable_types: d float


finish

decompiled_code:
float __fastcall finish()
{
long double v0; // fst7

return v0;
}

canonical_decompiled_code:
float __fastcall func1()
{
long double v0; // fst7

return v0;
}

original_code:
float finish(void)
{
 float res;
 __asm__ volatile (
     "fstp	%0\n"
     : "=m" (res)
    );
 return res;
}

canonical_original_code:
float finish()
{
 float res;
 __asm__ volatile (
     "fstp	%0\n"
     : "=m" (res)
    );
 return res;
}

variable_types: res float

return_type: float


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
float v3; // xmm5_4
float v4; // xmm1_4
float v5; // xmm2_4
float v6; // xmm3_4
int v7; // xmm5_4^4
float v8; // xmm5_4
double v9; // xmm0_8
int result; // eax
int *v11; // rax
float v12; // [rsp+4h] [rbp-14h]
float v13; // [rsp+Ch] [rbp-Ch]

test_init(argc, argv, envp);
if ( (unsigned int)chk_proc_fpu() )
{
v3 = drand48();
v13 = v3;
v4 = drand48();
v5 = drand48();
v6 = drand48();
start(v13, v4, v5, v6);
v12 = finish();
HIDWORD(v9) = v7;
start(v8, v4, v5, v6);
test_daemon();
test_waitsig();
*(float *)&v9 = finish();
if ( v12 == *(float *)&v9 )
{
test_msg("PASS\n", v9, v9);
}
else
{
v11 = _errno_location();
test_msg("FAIL: %s:%d: %f != %f\n (errno = %d)\n", "fpu00.c", 76LL, v12, *(float *)&v9, (unsigned int)*v11);
}
result = 0;
}
else
{
test_msg("SKIP: %s:%d: FPU not supported\n", "fpu00.c", 55LL);
result = 1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
float v3; // xmm5_4
float v4; // xmm1_4
float v5; // xmm2_4
float v6; // xmm3_4
int v7; // xmm5_4^4
float v8; // xmm5_4
double v9; // xmm0_8
int result; // eax
int *v11; // rax
float v12; // [rsp+4h] [rbp-14h]
float v13; // [rsp+Ch] [rbp-Ch]

test_init(argc, argv, envp);
if ( (unsigned int)func2() )
{
v3 = drand48();
v13 = v3;
v4 = drand48();
v5 = drand48();
v6 = drand48();
func0(v13, v4, v5, v6);
v12 = func1();
HIDWORD(v9) = v7;
func0(v8, v4, v5, v6);
test_daemon();
test_waitsig();
*(float *)&v9 = func1();
if ( v12 == *(float *)&v9 )
{
test_msg("PASS\n", v9, v9);
}
else
{
v11 = _errno_location();
test_msg("FAIL: %s:%d: %f != %f\n (errno = %d)\n", "fpu00.c", 76LL, v12, *(float *)&v9, (unsigned int)*v11);
}
result = 0;
}
else
{
test_msg("SKIP: %s:%d: FPU not supported\n", "fpu00.c", 55LL);
result = 1;
}
return result;
}

original_code:
int main(int argc, char ** argv)
{
 float a, b, c, d;
 float res1, res2;
 test_init(argc, argv);
 if (!chk_proc_fpu()) {
  test_msg("SKIP: %s:%d: " "FPU not supported" "\n", "fpu00.c", 55);
  return 1;
 }
 a = drand48();
 b = drand48();
 c = drand48();
 d = drand48();
 start(a, b, c, d);
 res1 = finish();
 start(a, b, c, d);
 test_daemon();
 test_waitsig();
 res2 = finish();
 if (res1 != res2)
  test_msg("FAIL: %s:%d: " "%f != %f\n" " (errno = %d)\n", "fpu00.c", 76, res1, res2, (*__errno_location ()));
 else
  test_msg("PASS\n");
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 float a; float b; float c; float d;
 float res1; float res2;
 test_init(argc, argv);
 if (!chk_proc_fpu()) {
  test_msg("SKIP: %s:%d: " "FPU not supported" "\n", "fpu00.c", 55);
  return 1;
 }
 a = drand48();
 b = drand48();
 c = drand48();
 d = drand48();
 start(a, b, c, d);
 res1 = finish();
 start(a, b, c, d);
 test_daemon();
 test_waitsig();
 res2 = finish();
 if (res1 != res2)
  test_msg("FAIL: %s:%d: " "%f != %f\n" " (errno = %d)\n", "fpu00.c", 76, res1, res2, (*__errno_location ()));
 else
  test_msg("PASS\n");
 return 0;
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
__int64 chk_proc_mmx()
{
int v1; // [rsp+0h] [rbp-10h] BYREF
int v2; // [rsp+4h] [rbp-Ch] BYREF
int v3; // [rsp+8h] [rbp-8h] BYREF
int v4; // [rsp+Ch] [rbp-4h] BYREF

cpuid_constprop_0(&v1, &v2, &v3, &v4);
return v4 & 0x800000;
}

canonical_decompiled_code:
__int64 func3()
{
int v1; // [rsp+0h] [rbp-10h] BYREF
int v2; // [rsp+4h] [rbp-Ch] BYREF
int v3; // [rsp+8h] [rbp-8h] BYREF
int v4; // [rsp+Ch] [rbp-4h] BYREF

func0(&v1, &v2, &v3, &v4);
return v4 & 0x800000;
}

original_code:
int chk_proc_mmx(void)
{
 unsigned int eax, ebx, ecx, edx;
 cpuid(1, &eax, &ebx, &ecx, &edx);
 return edx & (1 << 23);
}

canonical_original_code:
int chk_proc_mmx()
{
 unsigned int eax; unsigned int ebx; unsigned int ecx; unsigned int edx;
 cpuid(1, &eax, &ebx, &ecx, &edx);
 return edx & (1 << 23);
}

variable_types:
eax
unsigned int

variable_types:
ebx
unsigned int

variable_types:
ecx
unsigned int

variable_types:
edx
unsigned int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__m128i *v3; // rbx
int result; // eax
int *v5; // rax
int *v6; // rax
__int64 v7; // [rsp+0h] [rbp-78h] BYREF
__int64 v8; // [rsp+8h] [rbp-70h] BYREF
__int64 v9; // [rsp+10h] [rbp-68h] BYREF
__int64 v10; // [rsp+18h] [rbp-60h] BYREF
__m128i v11; // [rsp+20h] [rbp-58h] BYREF
__m128i v12; // [rsp+30h] [rbp-48h] BYREF
__m128i v13; // [rsp+40h] [rbp-38h] BYREF
__m128i v14; // [rsp+50h] [rbp-28h] BYREF
char v15; // [rsp+60h] [rbp-18h] BYREF

test_init(argc, argv, envp);
v3 = &v13;
if ( (unsigned int)chk_proc_mmx() )
{
do
{
v3 = (__m128i *)((char *)v3 + 4);
v3[-1].m128i_i32[3] = mrand48();
}
while ( v3 != (__m128i *)&v15 );
v11 = _mm_loadu_si128(&v13);
v12 = _mm_loadu_si128(&v14);
start();
finish(&v9, &v7);
start();
test_daemon(&v11, &v12);
test_waitsig();
finish(&v10, &v8);
if ( v10 == v9 )
{
if ( v7 == v8 )
{
test_msg("PASS\n");
}
else
{
v5 = _errno_location();
test_msg("FAIL: %s:%d: word op mismatch\n (errno = %d)\n", "mmx00.c", 90LL, (unsigned int)*v5);
}
result = 0;
}
else
{
v6 = _errno_location();
test_msg("FAIL: %s:%d: byte op mismatch\n (errno = %d)\n", "mmx00.c", 88LL, (unsigned int)*v6);
result = 0;
}
}
else
{
test_msg("SKIP: %s:%d: MMX not supported\n", "mmx00.c", 67LL);
result = 1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__m128i *v3; // rbx
int result; // eax
int *v5; // rax
int *v6; // rax
__int64 v7; // [rsp+0h] [rbp-78h] BYREF
__int64 v8; // [rsp+8h] [rbp-70h] BYREF
__int64 v9; // [rsp+10h] [rbp-68h] BYREF
__int64 v10; // [rsp+18h] [rbp-60h] BYREF
__m128i v11; // [rsp+20h] [rbp-58h] BYREF
__m128i v12; // [rsp+30h] [rbp-48h] BYREF
__m128i v13; // [rsp+40h] [rbp-38h] BYREF
__m128i v14; // [rsp+50h] [rbp-28h] BYREF
char v15; // [rsp+60h] [rbp-18h] BYREF

test_init(argc, argv, envp);
v3 = &v13;
if ( (unsigned int)func3() )
{
do
{
v3 = (__m128i *)((char *)v3 + 4);
v3[-1].m128i_i32[3] = mrand48();
}
while ( v3 != (__m128i *)&v15 );
v11 = _mm_loadu_si128(&v13);
v12 = _mm_loadu_si128(&v14);
func1();
func2(&v9, &v7);
func1();
test_daemon(&v11, &v12);
test_waitsig();
func2(&v10, &v8);
if ( v10 == v9 )
{
if ( v7 == v8 )
{
test_msg("PASS\n");
}
else
{
v5 = _errno_location();
test_msg("FAIL: %s:%d: word op mismatch\n (errno = %d)\n", "mmx00.c", 90LL, (unsigned int)*v5);
}
result = 0;
}
else
{
v6 = _errno_location();
test_msg("FAIL: %s:%d: byte op mismatch\n (errno = %d)\n", "mmx00.c", 88LL, (unsigned int)*v6);
result = 0;
}
}
else
{
test_msg("SKIP: %s:%d: MMX not supported\n", "mmx00.c", 67LL);
result = 1;
}
return result;
}

original_code:
int main(int argc, char **argv)
{
 uint8_t bytes[16];
 uint16_t words[8];
 uint32_t rnd[8];
 int i;
 uint8_t resbytes1[8], resbytes2[8];
 uint16_t reswords1[4], reswords2[4];
 test_init(argc, argv);
 if (!chk_proc_mmx()) {
  test_msg("SKIP: %s:%d: " "MMX not supported" "\n", "mmx00.c", 67);
  return 1;
 }
 for (i = 0; i < (sizeof(bytes) + sizeof(words)) / 4; i++)
  rnd[i] = mrand48();
 memcpy((uint8_t *) bytes, (uint8_t *) rnd, sizeof(bytes));
 memcpy((uint8_t *) words, (uint8_t *) rnd + sizeof(bytes), sizeof(words));
 start(bytes, words);
 finish(resbytes1, reswords1);
 start(bytes, words);
 test_daemon();
 test_waitsig();
 finish(resbytes2, reswords2);
 if (memcmp((uint8_t *) resbytes1, (uint8_t *) resbytes2, sizeof(resbytes1)))
  test_msg("FAIL: %s:%d: " "byte op mismatch\n" " (errno = %d)\n", "mmx00.c", 88, (*__errno_location ()));
 else if (memcmp((uint8_t *) reswords1, (uint8_t *) reswords2, sizeof(reswords2)))
  test_msg("FAIL: %s:%d: " "word op mismatch\n" " (errno = %d)\n", "mmx00.c", 90, (*__errno_location ()));
 else
  test_msg("PASS\n");
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 unsigned char bytes[16];
 unsigned short words[8];
 unsigned int rnd[8];
 int i;
 unsigned char resbytes1[8]; unsigned char resbytes2[8];
 unsigned short reswords1[4]; unsigned short reswords2[4];
 test_init(argc, argv);
 if (!chk_proc_mmx()) {
  test_msg("SKIP: %s:%d: " "MMX not supported" "\n", "mmx00.c", 67);
  return 1;
 }
 for (i = 0; i < (sizeof(bytes) + sizeof(words)) / 4; i++)
  rnd[i] = mrand48();
 memcpy((unsigned char *) bytes, (unsigned char *) rnd, sizeof(bytes));
 memcpy((unsigned char *) words, (unsigned char *) rnd + sizeof(bytes), sizeof(words));
 start(bytes, words);
 finish(resbytes1, reswords1);
 start(bytes, words);
 test_daemon();
 test_waitsig();
 finish(resbytes2, reswords2);
 if (memcmp((unsigned char *) resbytes1, (unsigned char *) resbytes2, sizeof(resbytes1)))
  test_msg("FAIL: %s:%d: " "byte op mismatch\n" " (errno = %d)\n", "mmx00.c", 88, (*__errno_location ()));
 else if (memcmp((unsigned char *) reswords1, (unsigned char *) reswords2, sizeof(reswords2)))
  test_msg("FAIL: %s:%d: " "word op mismatch\n" " (errno = %d)\n", "mmx00.c", 90, (*__errno_location ()));
 else
  test_msg("PASS\n");
 return 0;
}

variable_types:
bytes
unsigned char [16]

variable_types:
words
unsigned short [8]

variable_types:
rnd
unsigned int [8]

variable_types: i int


decompiled_code:
void *__fastcall thread_fn(void *a1)
{
pthread_mutex_lock((pthread_mutex_t *)a1);
++kid_passed;
pthread_mutex_unlock((pthread_mutex_t *)a1);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1)
{
pthread_mutex_lock((pthread_mutex_t *)a1);
++kid_passed;
pthread_mutex_unlock((pthread_mutex_t *)a1);
return 0LL;
}

original_code:
void *thread_fn(void *lock)
{
 pthread_mutex_t *mutex;
 mutex = (pthread_mutex_t *)lock;
 pthread_mutex_lock(mutex);
 kid_passed++;
 pthread_mutex_unlock(mutex);
 return ((void *)0);
}

canonical_original_code:
void *thread_fn(void *lock)
{
 union pthread_mutex_t *mutex;
 mutex = (union pthread_mutex_t *)lock;
 pthread_mutex_lock(mutex);
 kid_passed++;
 pthread_mutex_unlock(mutex);
 return ((void *)0);
}

variable_types:
lock
void *

variable_types: union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *

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

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