decompiled_code:
__int64 __fastcall parse_opt_ulong(const char *a1, unsigned __int64 *a2)
{
__int64 result; // rax
char *endptr; // [rsp+0h] [rbp-10h] BYREF

if ( !a1 || !*a1 )
return 4294967274LL;
*a2 = strtoul(a1, &endptr, 0);
if ( *endptr )
result = 4294967274LL;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1, unsigned __int64 *a2)
{
__int64 result; // rax
char *endptr; // [rsp+0h] [rbp-10h] BYREF

if ( !a1 || !*a1 )
return 4294967274LL;
*a2 = strtoul(a1, &endptr, 0);
if ( *endptr )
result = 4294967274LL;
else
result = 0LL;
return result;
}

original_code:
int parse_opt_ulong(char *param, void *arg)
{
 char *tail;
 if (param == ((void *)0) || param[0] == '\0')
  return -22;
 * (unsigned long *) arg = strtoul(param, &tail, 0);
 if (tail[0] != '\0')
  return -22;
 return 0;
}


repo: OSLL/pmover

decompiled_code:
__int64 __fastcall parse_opt_string(_BYTE *a1, _QWORD *a2)
{
if ( !a1 || !*a1 )
return 4294967274LL;
*a2 = a1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(_BYTE *a1, _QWORD *a2)
{
if ( !a1 || !*a1 )
return 4294967274LL;
*a2 = a1;
return 0LL;
}

original_code:
int parse_opt_string(char *param, void *arg)
{
 if (param == ((void *)0) || param[0] == '\0')
  return -22;
 * (char **) arg = param;
 return 0;
}

variable_types:
param
char *

variable_types:
arg
void *

return_type: int


parseargs

decompiled_code:
__int64 __fastcall parseargs(int a1, __int64 a2)
{
const char **v2; // r14
const char *v3; // r13
char *v4; // rax
__int64 v5; // r15
char *v6; // rax
char *v7; // r12
size_t v8; // rbp
__int64 result; // rax

if ( a1 > 1 )
{
v2 = (const char **)(a2 + 8);
do
{
v3 = *v2;
if ( strlen(*v2) <= 1 || *v3 != 45 || v3[1] != 45 )
{
fprintf(stderr, "%s: options should start with --\n", v3);
helpexit();
}
v4 = strchr(v3 + 2, 61);
v5 = opt_head;
v6 = &v4[-(v4 == 0LL) + 1];
v7 = v6;
if ( !opt_head )
{
LABEL_18:
fprintf(stderr, "%s: unknown option\n", v3);
helpexit();
}
v8 = v6 - (v3 + 2) - 1;
while ( strncmp(v3 + 2, *(const char **)v5, v8) )
{
v5 = *(_QWORD *)(v5 + 48);
if ( !v5 )
goto LABEL_18;
}
if ( (*(unsigned int (__fastcall **)(char *, _QWORD))(v5 + 32))(v7, *(_QWORD *)(v5 + 40)) )
{
fprintf(stderr, "%s: failed to parse\n", *v2);
helpexit();
}
*(_DWORD *)(v5 + 24) = -*(_DWORD *)(v5 + 24);
++v2;
}
while ( v2 != (const char **)(a2 + 8LL * (unsigned int)(a1 - 2) + 16) );
}
if ( help )
{
prdoc();
helpexit();
}
for ( result = opt_head; result; result = *(_QWORD *)(result + 48) )
{
if ( *(int *)(result + 24) > 0 )
{
fprintf(stderr, "mandatory flag --%s not given\n", *(const char **)result);
helpexit();
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, __int64 a2)
{
const char **v2; // r14
const char *v3; // r13
char *v4; // rax
__int64 v5; // r15
char *v6; // rax
char *v7; // r12
size_t v8; // rbp
__int64 result; // rax

if ( a1 > 1 )
{
v2 = (const char **)(a2 + 8);
do
{
v3 = *v2;
if ( strlen(*v2) <= 1 || *v3 != 45 || v3[1] != 45 )
{
fprintf(stderr, "%s: options should start with --\n", v3);
func3();
}
v4 = strchr(v3 + 2, 61);
v5 = opt_head;
v6 = &v4[-(v4 == 0LL) + 1];
v7 = v6;
if ( !opt_head )
{
LABEL_18:
fprintf(stderr, "%s: unknown option\n", v3);
func3();
}
v8 = v6 - (v3 + 2) - 1;
while ( strncmp(v3 + 2, *(const char **)v5, v8) )
{
v5 = *(_QWORD *)(v5 + 48);
if ( !v5 )
goto LABEL_18;
}
if ( (*(unsigned int (__fastcall **)(char *, _QWORD))(v5 + 32))(v7, *(_QWORD *)(v5 + 40)) )
{
fprintf(stderr, "%s: failed to parse\n", *v2);
func3();
}
*(_DWORD *)(v5 + 24) = -*(_DWORD *)(v5 + 24);
++v2;
}
while ( v2 != (const char **)(a2 + 8LL * (unsigned int)(a1 - 2) + 16) );
}
if ( help )
{
func1();
func3();
}
for ( result = opt_head; result; result = *(_QWORD *)(result + 48) )
{
if ( *(int *)(result + 24) > 0 )
{
fprintf(stderr, "mandatory flag --%s not given\n", *(const char **)result);
func3();
}
}
return result;
}

original_code:
void parseargs(int argc, char ** argv)
{
 int i;
 struct long_opt *opt;
 for (i = 1; i < argc; i++) {
  char *name, *value;
  if (strlen(argv[i]) < 2 || strncmp(argv[i], "--", 2)) {
   fprintf(stderr, "%s: options should start with --\n", argv[i]);
   helpexit();
  }
  name = argv[i] + 2;
  value = strchr(name, '=');
  if (value)
   value++;
  for (opt = opt_head; opt; opt = opt->next)
   if (!strncmp(name, opt->name, value - name - 1)) {
    if (opt->parse_opt(value, opt->value)) {
     fprintf(stderr, "%s: failed to parse\n", argv[i]);
     helpexit();
    }
    else
     opt->is_required = - opt->is_required;
    break;
   }
  if (!opt) {
   fprintf(stderr, "%s: unknown option\n", argv[i]);
   helpexit();
  }
 }
 if (help) {
  prdoc();
  helpexit();
 }
 for (opt = opt_head; opt; opt = opt->next)
  if (opt->is_required > 0) {
   fprintf(stderr, "mandatory flag --%s not given\n", opt->name);
   helpexit();
  }
}

canonical_original_code:
void parseargs(int argc, char **argv)
{
 int i;
 struct long_opt *opt;
 for (i = 1; i < argc; i++) {
  char *name; char *value;
  if (strlen(argv[i]) < 2 || strncmp(argv[i], "--", 2)) {
   fprintf(stderr, "%s: options should start with --\n", argv[i]);
   helpexit();
  }
  name = argv[i] + 2;
  value = strchr(name, '=');
  if (value)
   value++;
  for (opt = opt_head; opt; opt = opt->next)
   if (!strncmp(name, opt->name, value - name - 1)) {
    if (opt->parse_opt(value, opt->value)) {
     fprintf(stderr, "%s: failed to parse\n", argv[i]);
     helpexit();
    }
    else
     opt->is_required = - opt->is_required;
    break;
   }
  if (!opt) {
   fprintf(stderr, "%s: unknown option\n", argv[i]);
   helpexit();
  }
 }
 if (help) {
  prdoc();
  helpexit();
 }
 for (opt = opt_head; opt; opt = opt->next)
  if (opt->is_required > 0) {
   fprintf(stderr, "mandatory flag --%s not given\n", opt->name);
   helpexit();
  }
}

variable_types: argc int

variable_types:
argv
char **

variable_types: i int

variable_types: struct long_opt { char *name; char *type; char *doc; int is_required; int (*parse_opt)(char *arg, void *value); void *value; struct long_opt *next; } *

variable_types:
name
char *

variable_types:
value
char *

return_type: void


decompiled_code:
__int64 signal_handler_io()
{
__int64 result; // rax

result = shared;
++*(_DWORD *)shared;
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax

result = shared;
++*(_DWORD *)shared;
return result;
}

original_code:
static void signal_handler_io(int status)
{
 shared->sigio++;
}

variable_types: status int


decompiled_code:
__int64 __fastcall cmp_pipe_params(_DWORD *a1, _DWORD *a2)
{
unsigned int v2; // ebx
unsigned int v3; // ebp
unsigned int v4; // ebx
unsigned int v5; // ebp
unsigned int v6; // ebx
unsigned int v7; // ebp
unsigned int v8; // er12
unsigned int v9; // er12
__int64 result; // rax
unsigned int v11; // er12
int *v12; // rax
int *v13; // rax
int *v14; // rax

v2 = a1[1];
v3 = a2[1];
if ( v3 != v2 )
{
v8 = 0;
goto LABEL_9;
}
v4 = a1[3];
v5 = a2[3];
if ( v5 != v4 )
{
v9 = 0;
goto LABEL_11;
}
v6 = a1[5];
v7 = a2[5];
if ( v7 != v6 )
{
v11 = 0;
goto LABEL_13;
}
v2 = a1[2];
v3 = a2[2];
v8 = 1;
if ( v2 != v3 )
{
LABEL_9:
v12 = _errno_location();
test_msg(
"FAIL: %s:%d: pipe flags failed [%d] expected %08o got %08o\n (errno = %d)\n",
"file_fown.c",
69LL,
v8,
v2,
v3,
(unsigned int)*v12);
return 0xFFFFFFFFLL;
}
v4 = a1[4];
v5 = a2[4];
v9 = 1;
if ( v4 != v5 )
{
LABEL_11:
v13 = _errno_location();
test_msg(
"FAIL: %s:%d: pipe pid failed [%d] expected %d got %d\n (errno = %d)\n",
"file_fown.c",
74LL,
v9,
v4,
v5,
(unsigned int)*v13);
return 0xFFFFFFFFLL;
}
v6 = a1[6];
v7 = a2[6];
result = 0LL;
v11 = 1;
if ( v6 != v7 )
{
LABEL_13:
v14 = _errno_location();
test_msg(
"FAIL: %s:%d: pipe sig failed [%d] expected %d got %d\n (errno = %d)\n",
"file_fown.c",
79LL,
v11,
v6,
v7,
(unsigned int)*v14);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_DWORD *a1, _DWORD *a2)
{
unsigned int v2; // ebx
unsigned int v3; // ebp
unsigned int v4; // ebx
unsigned int v5; // ebp
unsigned int v6; // ebx
unsigned int v7; // ebp
unsigned int v8; // er12
unsigned int v9; // er12
__int64 result; // rax
unsigned int v11; // er12
int *v12; // rax
int *v13; // rax
int *v14; // rax

v2 = a1[1];
v3 = a2[1];
if ( v3 != v2 )
{
v8 = 0;
goto LABEL_9;
}
v4 = a1[3];
v5 = a2[3];
if ( v5 != v4 )
{
v9 = 0;
goto LABEL_11;
}
v6 = a1[5];
v7 = a2[5];
if ( v7 != v6 )
{
v11 = 0;
goto LABEL_13;
}
v2 = a1[2];
v3 = a2[2];
v8 = 1;
if ( v2 != v3 )
{
LABEL_9:
v12 = _errno_location();
test_msg(
"FAIL: %s:%d: pipe flags failed [%d] expected %08o got %08o\n (errno = %d)\n",
"file_fown.c",
69LL,
v8,
v2,
v3,
(unsigned int)*v12);
return 0xFFFFFFFFLL;
}
v4 = a1[4];
v5 = a2[4];
v9 = 1;
if ( v4 != v5 )
{
LABEL_11:
v13 = _errno_location();
test_msg(
"FAIL: %s:%d: pipe pid failed [%d] expected %d got %d\n (errno = %d)\n",
"file_fown.c",
74LL,
v9,
v4,
v5,
(unsigned int)*v13);
return 0xFFFFFFFFLL;
}
v6 = a1[6];
v7 = a2[6];
result = 0LL;
v11 = 1;
if ( v6 != v7 )
{
LABEL_13:
v14 = _errno_location();
test_msg(
"FAIL: %s:%d: pipe sig failed [%d] expected %d got %d\n (errno = %d)\n",
"file_fown.c",
79LL,
v11,
v6,
v7,
(unsigned int)*v14);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static int cmp_pipe_params(struct params *p1, struct params *p2)
{
 int i;
 for (i = 0; i < 2; i++) {
  if (p1->pipe_flags[i] != p2->pipe_flags[i]) {
   test_msg("FAIL: %s:%d: " "pipe flags failed [%d] expected %08o got %08o\n" " (errno = %d)\n", "file_fown.c", 69, i, p1->pipe_flags[i], p2->pipe_flags[i], (*__errno_location ()));
   return -1;
  }
  if (p1->pipe_pid[i] != p2->pipe_pid[i]) {
   test_msg("FAIL: %s:%d: " "pipe pid failed [%d] expected %d got %d\n" " (errno = %d)\n", "file_fown.c", 74, i, p1->pipe_pid[i], p2->pipe_pid[i], (*__errno_location ()));
   return -1;
  }
  if (p1->pipe_sig[i] != p2->pipe_sig[i]) {
   test_msg("FAIL: %s:%d: " "pipe sig failed [%d] expected %d got %d\n" " (errno = %d)\n", "file_fown.c", 79, i, p1->pipe_sig[i], p2->pipe_sig[i], (*__errno_location ()));
   return -1;
  }
 }
 return 0;
}

variable_types: struct params { int sigio; int pipe_flags[2]; int pipe_pid[2]; int pipe_sig[2]; } *


decompiled_code:
int __fastcall fill_pipe_params(_DWORD *a1, int *a2)
{
int v3; // eax
__int64 v4; // rsi
int result; // eax

a1[1] = fcntl(*a2, 3);
v3 = fcntl(a2[1], 3);
BYTE1(v3) &= 0x7Fu;
v4 = a1[1] & 0xFFFF7FFF;
a1[2] = v3;
a1[1] = v4;
test_msg("pipe_flags0 %08o\n", v4);
test_msg("pipe_flags1 %08o\n", (unsigned int)a1[2]);
a1[3] = fcntl(*a2, 9);
a1[4] = fcntl(a2[1], 9);
a1[5] = fcntl(*a2, 11);
result = fcntl(a2[1], 11);
a1[6] = result;
return result;
}

canonical_decompiled_code:
int __fastcall func2(_DWORD *a1, int *a2)
{
int v3; // eax
__int64 v4; // rsi
int result; // eax

a1[1] = fcntl(*a2, 3);
v3 = fcntl(a2[1], 3);
BYTE1(v3) &= 0x7Fu;
v4 = a1[1] & 0xFFFF7FFF;
a1[2] = v3;
a1[1] = v4;
test_msg("pipe_flags0 %08o\n", v4);
test_msg("pipe_flags1 %08o\n", (unsigned int)a1[2]);
a1[3] = fcntl(*a2, 9);
a1[4] = fcntl(a2[1], 9);
a1[5] = fcntl(*a2, 11);
result = fcntl(a2[1], 11);
a1[6] = result;
return result;
}

original_code:
static void fill_pipe_params(struct params *p, int *pipes)
{
 p->pipe_flags[0] = fcntl(pipes[0], 3);
 p->pipe_flags[1] = fcntl(pipes[1], 3);
 p->pipe_flags[0] &= ~00100000;
 p->pipe_flags[1] &= ~00100000;
 test_msg("pipe_flags0 %08o\n", p->pipe_flags[0]);
 test_msg("pipe_flags1 %08o\n", p->pipe_flags[1]);
 p->pipe_pid[0] = fcntl(pipes[0], 9);
 p->pipe_pid[1] = fcntl(pipes[1], 9);
 p->pipe_sig[0] = fcntl(pipes[0], 11);
 p->pipe_sig[1] = fcntl(pipes[1], 11);
}

variable_types:
pipes
int *

user_defined_types: struct params { int sigio; int pipe_flags[2]; int pipe_pid[2]; int pipe_sig[2]; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
int v7; // eax
__pid_t v8; // er12
_DWORD *v9; // rdi
unsigned int v10; // er13
int *v12; // rdi
__int64 i; // rcx
unsigned int v14; // eax
int *v15; // rax
int *v16; // rax
__int64 v17; // rdx
__int64 v18; // rcx
int *v19; // rax
int *v20; // rax
int *v21; // rax
int *v22; // rax
int *v23; // rax
int *v24; // rax
int *v25; // rax
int *v26; // rax
int *v27; // rax
int *v28; // rax
int *v29; // rax
__uid_t ruid; // [rsp+0h] [rbp-10Ch] BYREF
__uid_t euid; // [rsp+4h] [rbp-108h] BYREF
__uid_t suid; // [rsp+8h] [rbp-104h] BYREF
int pipedes[2]; // [rsp+Ch] [rbp-100h] BYREF
__int128 buf; // [rsp+14h] [rbp-F8h] BYREF
__int64 v35; // [rsp+24h] [rbp-E8h]
int v36; // [rsp+2Ch] [rbp-E0h]
int stat_loc[8]; // [rsp+34h] [rbp-D8h] BYREF
struct sigaction v38; // [rsp+54h] [rbp-B8h] BYREF

buf = 0LL;
v36 = 0;
memset(&v38, 0, sizeof(v38));
v35 = 0LL;
test_init((unsigned int)argc, argv, envp);
shared = (__int64)mmap(0LL, 0x1000uLL, 3, 33, -1, 0LL);
if ( shared == -1 )
{
v24 = _errno_location();
test_msg("FAIL: %s:%d: mmap failed (errno = %d)\n", "file_fown.c", 100LL, (unsigned int)*v24);
exit(1);
}
if ( getresuid(&ruid, &euid, &suid) )
{
v23 = _errno_location();
test_msg("FAIL: %s:%d: getresuid failed\n (errno = %d)\n", "file_fown.c", 105LL, (unsigned int)*v23);
exit(1);
}
if ( pipe(pipedes) )
{
v22 = _errno_location();
test_msg("ERR: %s:%d: Can't create pipe: %m\n (errno = %d)\n", "file_fown.c", 110LL, (unsigned int)*v22);
exit(1);
}
v38.sa_handler = (__sighandler_t)signal_handler_io;
v38.sa_flags = 0x10000000;
if ( sigaction(29, &v38, 0LL) )
{
v21 = _errno_location();
test_msg("FAIL: %s:%d: sigaction failed\n (errno = %d)\n", "file_fown.c", 117LL, (unsigned int)*v21);
exit(1);
}
if ( setresuid(0xFFFFFFFF, 1u, 0xFFFFFFFF) )
{
v16 = _errno_location();
v17 = 122LL;
v18 = (unsigned int)*v16;
goto LABEL_27;
}
v3 = getpid();
if ( fcntl(pipedes[0], 8, v3)
|| (v4 = getpid(), fcntl(pipedes[1], 8, v4))
|| fcntl(pipedes[0], 10, 29LL)
|| fcntl(pipedes[1], 10, 29LL)
|| (v5 = fcntl(pipedes[0], 3), BYTE1(v5) |= 0x20u, fcntl(pipedes[0], 4, v5))
|| (v6 = fcntl(pipedes[1], 3), BYTE1(v6) |= 0x20u, fcntl(pipedes[1], 4, v6)) )
{
v15 = _errno_location();
test_msg("FAIL: %s:%d: fcntl failed\n (errno = %d)\n", "file_fown.c", 132LL, (unsigned int)*v15);
exit(1);
}
fill_pipe_params((_DWORD *)shared, pipedes);
if ( setresuid(0xFFFFFFFF, euid, 0xFFFFFFFF) )
{
v20 = _errno_location();
v17 = 141LL;
v18 = (unsigned int)*v20;
LABEL_27:
test_msg("FAIL: %s:%d: setresuid failed\n (errno = %d)\n", "file_fown.c", v17, v18);
exit(1);
}
v7 = test_fork_id(0xFFFFFFFFLL);
v8 = v7;
if ( v7 < 0 )
{
v19 = _errno_location();
test_msg("ERR: %s:%d: can't fork %m (errno = %d)\n", "file_fown.c", 147LL, (unsigned int)*v19);
exit(1);
}
if ( !v7 )
{
v12 = stat_loc;
for ( i = 7LL; i; --i )
*v12++ = 0;
test_waitsig(v12);
v14 = getpid();
fcntl(pipedes[1], 8, v14);
fill_pipe_params(stat_loc, pipedes);
if ( write(pipedes[1], stat_loc, 0x1CuLL) == 28 )
exit(0);
v29 = _errno_location();
test_msg("FAIL: %s:%d: write failed\n (errno = %d)\n", "file_fown.c", 160LL, (unsigned int)*v29);
exit(1);
}
test_daemon();
test_waitsig(0xFFFFFFFFLL);
kill(v8, 15);
if ( waitpid(v8, stat_loc, 0) == -1 )
{
v25 = _errno_location();
test_msg("FAIL: %s:%d: waitpid failed\n (errno = %d)\n", "file_fown.c", 172LL, (unsigned int)*v25);
exit(1);
}
if ( read(pipedes[0], &buf, 0x1CuLL) != 28 )
{
v26 = _errno_location();
test_msg("FAIL: %s:%d: read failed\n (errno = %d)\n", "file_fown.c", 177LL, (unsigned int)*v26);
exit(1);
}
v9 = (_DWORD *)shared;
v10 = *(_DWORD *)shared;
if ( *(int *)shared <= 0 )
{
v27 = _errno_location();
test_msg(
"FAIL: %s:%d: shared->sigio = %d (> 0 expected)\n (errno = %d)\n",
"file_fown.c",
182LL,
v10,
(unsigned int)*v27);
exit(1);
}
*(_DWORD *)(shared + 16) = v8;
if ( (unsigned int)cmp_pipe_params(v9, &buf) )
{
v28 = _errno_location();
test_msg("FAIL: %s:%d: params comparison failed\n (errno = %d)\n", "file_fown.c", 189LL, (unsigned int)*v28);
exit(1);
}
test_msg("PASS\n");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
int v7; // eax
__pid_t v8; // er12
_DWORD *v9; // rdi
unsigned int v10; // er13
int *v12; // rdi
__int64 i; // rcx
unsigned int v14; // eax
int *v15; // rax
int *v16; // rax
__int64 v17; // rdx
__int64 v18; // rcx
int *v19; // rax
int *v20; // rax
int *v21; // rax
int *v22; // rax
int *v23; // rax
int *v24; // rax
int *v25; // rax
int *v26; // rax
int *v27; // rax
int *v28; // rax
int *v29; // rax
__uid_t ruid; // [rsp+0h] [rbp-10Ch] BYREF
__uid_t euid; // [rsp+4h] [rbp-108h] BYREF
__uid_t suid; // [rsp+8h] [rbp-104h] BYREF
int pipedes[2]; // [rsp+Ch] [rbp-100h] BYREF
__int128 buf; // [rsp+14h] [rbp-F8h] BYREF
__int64 v35; // [rsp+24h] [rbp-E8h]
int v36; // [rsp+2Ch] [rbp-E0h]
int stat_loc[8]; // [rsp+34h] [rbp-D8h] BYREF
struct sigaction v38; // [rsp+54h] [rbp-B8h] BYREF

buf = 0LL;
v36 = 0;
memset(&v38, 0, sizeof(v38));
v35 = 0LL;
test_init((unsigned int)argc, argv, envp);
shared = (__int64)mmap(0LL, 0x1000uLL, 3, 33, -1, 0LL);
if ( shared == -1 )
{
v24 = _errno_location();
test_msg("FAIL: %s:%d: mmap failed (errno = %d)\n", "file_fown.c", 100LL, (unsigned int)*v24);
exit(1);
}
if ( getresuid(&ruid, &euid, &suid) )
{
v23 = _errno_location();
test_msg("FAIL: %s:%d: getresuid failed\n (errno = %d)\n", "file_fown.c", 105LL, (unsigned int)*v23);
exit(1);
}
if ( pipe(pipedes) )
{
v22 = _errno_location();
test_msg("ERR: %s:%d: Can't create pipe: %m\n (errno = %d)\n", "file_fown.c", 110LL, (unsigned int)*v22);
exit(1);
}
v38.sa_handler = (__sighandler_t)signal_handler_io;
v38.sa_flags = 0x10000000;
if ( sigaction(29, &v38, 0LL) )
{
v21 = _errno_location();
test_msg("FAIL: %s:%d: sigaction failed\n (errno = %d)\n", "file_fown.c", 117LL, (unsigned int)*v21);
exit(1);
}
if ( setresuid(0xFFFFFFFF, 1u, 0xFFFFFFFF) )
{
v16 = _errno_location();
v17 = 122LL;
v18 = (unsigned int)*v16;
goto LABEL_27;
}
v3 = getpid();
if ( fcntl(pipedes[0], 8, v3)
|| (v4 = getpid(), fcntl(pipedes[1], 8, v4))
|| fcntl(pipedes[0], 10, 29LL)
|| fcntl(pipedes[1], 10, 29LL)
|| (v5 = fcntl(pipedes[0], 3), BYTE1(v5) |= 0x20u, fcntl(pipedes[0], 4, v5))
|| (v6 = fcntl(pipedes[1], 3), BYTE1(v6) |= 0x20u, fcntl(pipedes[1], 4, v6)) )
{
v15 = _errno_location();
test_msg("FAIL: %s:%d: fcntl failed\n (errno = %d)\n", "file_fown.c", 132LL, (unsigned int)*v15);
exit(1);
}
func2((_DWORD *)shared, pipedes);
if ( setresuid(0xFFFFFFFF, euid, 0xFFFFFFFF) )
{
v20 = _errno_location();
v17 = 141LL;
v18 = (unsigned int)*v20;
LABEL_27:
test_msg("FAIL: %s:%d: setresuid failed\n (errno = %d)\n", "file_fown.c", v17, v18);
exit(1);
}
v7 = test_fork_id(0xFFFFFFFFLL);
v8 = v7;
if ( v7 < 0 )
{
v19 = _errno_location();
test_msg("ERR: %s:%d: can't fork %m (errno = %d)\n", "file_fown.c", 147LL, (unsigned int)*v19);
exit(1);
}
if ( !v7 )
{
v12 = stat_loc;
for ( i = 7LL; i; --i )
*v12++ = 0;
test_waitsig(v12);
v14 = getpid();
fcntl(pipedes[1], 8, v14);
func2(stat_loc, pipedes);
if ( write(pipedes[1], stat_loc, 0x1CuLL) == 28 )
exit(0);
v29 = _errno_location();
test_msg("FAIL: %s:%d: write failed\n (errno = %d)\n", "file_fown.c", 160LL, (unsigned int)*v29);
exit(1);
}
test_daemon();
test_waitsig(0xFFFFFFFFLL);
kill(v8, 15);
if ( waitpid(v8, stat_loc, 0) == -1 )
{
v25 = _errno_location();
test_msg("FAIL: %s:%d: waitpid failed\n (errno = %d)\n", "file_fown.c", 172LL, (unsigned int)*v25);
exit(1);
}
if ( read(pipedes[0], &buf, 0x1CuLL) != 28 )
{
v26 = _errno_location();
test_msg("FAIL: %s:%d: read failed\n (errno = %d)\n", "file_fown.c", 177LL, (unsigned int)*v26);
exit(1);
}
v9 = (_DWORD *)shared;
v10 = *(_DWORD *)shared;
if ( *(int *)shared <= 0 )
{
v27 = _errno_location();
test_msg(
"FAIL: %s:%d: shared->sigio = %d (> 0 expected)\n (errno = %d)\n",
"file_fown.c",
182LL,
v10,
(unsigned int)*v27);
exit(1);
}
*(_DWORD *)(shared + 16) = v8;
if ( (unsigned int)func1(v9, &buf) )
{
v28 = _errno_location();
test_msg("FAIL: %s:%d: params comparison failed\n (errno = %d)\n", "file_fown.c", 189LL, (unsigned int)*v28);
exit(1);
}
test_msg("PASS\n");
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 struct sigaction saio = { };
 struct params obtained = { };
 uid_t ruid, euid, suid;
 int status, pipes[2];
 pid_t pid;
 test_init(argc, argv);
 shared = (void *)mmap(((void *)0), 4096, 0x1 | 0x2, 0x01 | 0x20, -1, 0);
 if ((void *)shared == ((void *) -1)) {
  test_msg("FAIL: %s:%d: " "mmap failed" " (errno = %d)\n", "file_fown.c", 100, (*__errno_location ()));
  exit(1);
 }
 if (getresuid(&ruid, &euid, &suid)) {
  test_msg("FAIL: %s:%d: " "getresuid failed\n" " (errno = %d)\n", "file_fown.c", 105, (*__errno_location ()));
  exit(1);
 }
 if (pipe(pipes)) {
  test_msg("ERR: %s:%d: " "Can't create pipe: %m\n" " (errno = %d)\n", "file_fown.c", 110, (*__errno_location ()));
  exit(1);
 }
 saio.__sigaction_handler.sa_handler = (sig_t)signal_handler_io;
 saio.sa_flags = 0x10000000;
 if (sigaction(29, &saio, 0)) {
  test_msg("FAIL: %s:%d: " "sigaction failed\n" " (errno = %d)\n", "file_fown.c", 117, (*__errno_location ()));
  exit(1);
 }
 if (setresuid(-1, 1, -1)) {
  test_msg("FAIL: %s:%d: " "setresuid failed\n" " (errno = %d)\n", "file_fown.c", 122, (*__errno_location ()));
  exit(1);
 }
 if (fcntl(pipes[0], 8, getpid()) ||
     fcntl(pipes[1], 8, getpid()) ||
     fcntl(pipes[0], 10, 29) ||
     fcntl(pipes[1], 10, 29) ||
     fcntl(pipes[0], 4, fcntl(pipes[0], 3) | 020000) ||
     fcntl(pipes[1], 4, fcntl(pipes[1], 3) | 020000)) {
  test_msg("FAIL: %s:%d: " "fcntl failed\n" " (errno = %d)\n", "file_fown.c", 132, (*__errno_location ()));
  exit(1);
 }
 asm volatile ("" :::);
 fill_pipe_params(shared, pipes);
 if (setresuid(-1, euid, -1)) {
  test_msg("FAIL: %s:%d: " "setresuid failed\n" " (errno = %d)\n", "file_fown.c", 141, (*__errno_location ()));
  exit(1);
 }
 pid = test_fork_id(-1);
 if (pid < 0) {
  test_msg("ERR: %s:%d: " "can't fork %m" " (errno = %d)\n", "file_fown.c", 147, (*__errno_location ()));
  exit(1);
 }
 if (pid == 0) {
  struct params p = { };
  test_waitsig();
  fcntl(pipes[1], 8, getpid());
  fill_pipe_params(&p, pipes);
  if (write(pipes[1], &p, sizeof(p)) != sizeof(p)) {
   test_msg("FAIL: %s:%d: " "write failed\n" " (errno = %d)\n", "file_fown.c", 160, (*__errno_location ()));
   exit(1);
  }
  exit(0);
 }
 test_daemon();
 test_waitsig();
 kill(pid, 15);
 if (waitpid(pid, &status, P_ALL) == -1) {
  test_msg("FAIL: %s:%d: " "waitpid failed\n" " (errno = %d)\n", "file_fown.c", 172, (*__errno_location ()));
  exit(1);
 }
 if (read(pipes[0], &obtained, sizeof(obtained)) != sizeof(obtained)) {
  test_msg("FAIL: %s:%d: " "read failed\n" " (errno = %d)\n", "file_fown.c", 177, (*__errno_location ()));
  exit(1);
 }
 if (shared->sigio < 1) {
  test_msg("FAIL: %s:%d: " "shared->sigio = %d (> 0 expected)\n" " (errno = %d)\n", "file_fown.c", 182, shared->sigio, (*__errno_location ()));
  exit(1);
 }
 shared->pipe_pid[1] = pid;
 if (cmp_pipe_params(shared, &obtained)) {
  test_msg("FAIL: %s:%d: " "params comparison failed\n" " (errno = %d)\n", "file_fown.c", 189, (*__errno_location ()));
  exit(1);
 }
 test_msg("PASS\n");
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 struct sigaction saio = { };
 struct params obtained = { };
 unsigned int ruid; unsigned int euid; unsigned int suid;
 int status; int pipes[2];
 int pid;
 test_init(argc, argv);
 shared = (void *)mmap(((void *)0), 4096, 0x1 | 0x2, 0x01 | 0x20, -1, 0);
 if ((void *)shared == ((void *) -1)) {
  test_msg("FAIL: %s:%d: " "mmap failed" " (errno = %d)\n", "file_fown.c", 100, (*__errno_location ()));
  exit(1);
 }
 if (getresuid(&ruid, &euid, &suid)) {
  test_msg("FAIL: %s:%d: " "getresuid failed\n" " (errno = %d)\n", "file_fown.c", 105, (*__errno_location ()));
  exit(1);
 }
 if (pipe(pipes)) {
  test_msg("ERR: %s:%d: " "Can't create pipe: %m\n" " (errno = %d)\n", "file_fown.c", 110, (*__errno_location ()));
  exit(1);
 }
 saio.__sigaction_handler.sa_handler = (void (*)(int))signal_handler_io;
 saio.sa_flags = 0x10000000;
 if (sigaction(29, &saio, 0)) {
  test_msg("FAIL: %s:%d: " "sigaction failed\n" " (errno = %d)\n", "file_fown.c", 117, (*__errno_location ()));
  exit(1);
 }
 if (setresuid(-1, 1, -1)) {
  test_msg("FAIL: %s:%d: " "setresuid failed\n" " (errno = %d)\n", "file_fown.c", 122, (*__errno_location ()));
  exit(1);
 }
 if (fcntl(pipes[0], 8, getpid()) ||
     fcntl(pipes[1], 8, getpid()) ||
     fcntl(pipes[0], 10, 29) ||
     fcntl(pipes[1], 10, 29) ||
     fcntl(pipes[0], 4, fcntl(pipes[0], 3) | 020000) ||
     fcntl(pipes[1], 4, fcntl(pipes[1], 3) | 020000)) {
  test_msg("FAIL: %s:%d: " "fcntl failed\n" " (errno = %d)\n", "file_fown.c", 132, (*__errno_location ()));
  exit(1);
 }
 asm volatile ("" :::);
 fill_pipe_params(shared, pipes);
 if (setresuid(-1, euid, -1)) {
  test_msg("FAIL: %s:%d: " "setresuid failed\n" " (errno = %d)\n", "file_fown.c", 141, (*__errno_location ()));
  exit(1);
 }
 pid = test_fork_id(-1);
 if (pid < 0) {
  test_msg("ERR: %s:%d: " "can't fork %m" " (errno = %d)\n", "file_fown.c", 147, (*__errno_location ()));
  exit(1);
 }
 if (pid == 0) {
  struct params p = { };
  test_waitsig();
  fcntl(pipes[1], 8, getpid());
  fill_pipe_params(&p, pipes);
  if (write(pipes[1], &p, sizeof(p)) != sizeof(p)) {
   test_msg("FAIL: %s:%d: " "write failed\n" " (errno = %d)\n", "file_fown.c", 160, (*__errno_location ()));
   exit(1);
  }
  exit(0);
 }
 test_daemon();
 test_waitsig();
 kill(pid, 15);
 if (waitpid(pid, &status, P_ALL) == -1) {
  test_msg("FAIL: %s:%d: " "waitpid failed\n" " (errno = %d)\n", "file_fown.c", 172, (*__errno_location ()));
  exit(1);
 }
 if (read(pipes[0], &obtained, sizeof(obtained)) != sizeof(obtained)) {
  test_msg("FAIL: %s:%d: " "read failed\n" " (errno = %d)\n", "file_fown.c", 177, (*__errno_location ()));
  exit(1);
 }
 if (shared->sigio < 1) {
  test_msg("FAIL: %s:%d: " "shared->sigio = %d (> 0 expected)\n" " (errno = %d)\n", "file_fown.c", 182, shared->sigio, (*__errno_location ()));
  exit(1);
 }
 shared->pipe_pid[1] = pid;
 if (cmp_pipe_params(shared, &obtained)) {
  test_msg("FAIL: %s:%d: " "params comparison failed\n" " (errno = %d)\n", "file_fown.c", 189, (*__errno_location ()));
  exit(1);
 }
 test_msg("PASS\n");
 return 0;
}

variable_types:
argv
char *[]

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

variable_types: struct params { int sigio; int pipe_flags[2]; int pipe_pid[2]; int pipe_sig[2]; }

variable_types:
ruid
unsigned int

variable_types:
euid
unsigned int

variable_types:
suid
unsigned int

variable_types:
pipes
int [2]

variable_types: pid int

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

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


decompiled_code:
void __fastcall timer_tick(int a1)
{
__int64 v1; // rax
char *v2; // rax

if ( a1 == dword_204 )
{
v1 = 0LL;
}
else if ( a1 == dword_210 )
{
v1 = 1LL;
}
else
{
v1 = 2LL;
if ( a1 != dword_21C )
return;
}
v2 = (char *)&timer_tests + 12 * v1;
if ( *((int *)v2 + 2) <= 9 )
++*((_DWORD *)v2 + 2);
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
__int64 v1; // rax
char *v2; // rax

if ( a1 == dword_204 )
{
v1 = 0LL;
}
else if ( a1 == dword_210 )
{
v1 = 1LL;
}
else
{
v1 = 2LL;
if ( a1 != dword_21C )
return;
}
v2 = (char *)&timer_tests + 12 * v1;
if ( *((int *)v2 + 2) <= 9 )
++*((_DWORD *)v2 + 2);
}

original_code:
static void timer_tick(int sig)
{
 int i;
 for (i = 0; i < (sizeof(timer_tests) / sizeof(timer_tests[0])); i++)
  if (timer_tests[i].signal == sig) {
   if (timer_tests[i].count < 10)
    timer_tests[i].count++;
   break;
  }
}

variable_types: sig int


decompiled_code:
__int64 check_timers()
{
unsigned int v0; // er12
int *v2; // rax
int v3; // [rsp+Ch] [rbp-Ch]

dword_208 = 0;
dword_214 = 0;
dword_220 = 0;
v3 = 1;
do
{
if ( dword_208 > 9 )
break;
++v3;
}
while ( v3 );
v0 = dword_208;
if ( dword_208 )
{
if ( dword_214 )
{
if ( dword_220 )
return test_msg("PASS\n");
v0 = 2;
}
else
{
v0 = 1;
}
}
v2 = _errno_location();
return test_msg("FAIL: %s:%d: timer %d stuck (errno = %d)\n", "timers.c", 76LL, v0, (unsigned int)*v2);
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int v0; // er12
int *v2; // rax
int v3; // [rsp+Ch] [rbp-Ch]

dword_208 = 0;
dword_214 = 0;
dword_220 = 0;
v3 = 1;
do
{
if ( dword_208 > 9 )
break;
++v3;
}
while ( v3 );
v0 = dword_208;
if ( dword_208 )
{
if ( dword_214 )
{
if ( dword_220 )
return test_msg("PASS\n");
v0 = 2;
}
else
{
v0 = 1;
}
}
v2 = _errno_location();
return test_msg("FAIL: %s:%d: timer %d stuck (errno = %d)\n", "timers.c", 76LL, v0, (unsigned int)*v2);
}

original_code:
static void check_timers(void)
{
 int i;
 volatile unsigned int j;
 for (i = 0; i < (sizeof(timer_tests) / sizeof(timer_tests[0])); i++)
  timer_tests[i].count = 0;
 for (j = 1; j && timer_tests[0].count < 10; j++);
 for (i = 0; i < (sizeof(timer_tests) / sizeof(timer_tests[0])); i++)
  if (!timer_tests[i].count) {
   test_msg("FAIL: %s:%d: " "timer %d stuck" " (errno = %d)\n", "timers.c", 76, i, (*__errno_location ()));
   return;
  }
 test_msg("PASS\n");
}

canonical_original_code:
static void check_timers()
{
 int i;
 unsigned int j;
 for (i = 0; i < (sizeof(timer_tests) / sizeof(timer_tests[0])); i++)
  timer_tests[i].count = 0;
 for (j = 1; j && timer_tests[0].count < 10; j++);
 for (i = 0; i < (sizeof(timer_tests) / sizeof(timer_tests[0])); i++)
  if (!timer_tests[i].count) {
   test_msg("FAIL: %s:%d: " "timer %d stuck" " (errno = %d)\n", "timers.c", 76, i, (*__errno_location ()));
   return;
  }
 test_msg("PASS\n");
}

variable_types:
j
unsigned int


decompiled_code:
int setup_timers()
{
unsigned int v0; // er12
__itimer_which_t *v1; // rbx
int result; // eax
int *v3; // rax
int *v4; // rax
struct itimerval v5; // [rsp+0h] [rbp-38h] BYREF

v0 = 0;
v1 = (__itimer_which_t *)&timer_tests;
v5.it_interval.tv_sec = 0LL;
v5.it_interval.tv_usec = 100000LL;
v5.it_value.tv_sec = 0LL;
v5.it_value.tv_usec = 100LL;
do
{
if ( signal(*((_DWORD *)v1 + 1), timer_tick) == (__sighandler_t)-1LL )
{
v3 = _errno_location();
test_msg("ERR: %s:%d: can't set signal handler %d (errno = %d)\n", "timers.c", 51LL, v0, (unsigned int)*v3);
exit(1);
}
result = setitimer(*v1, &v5, 0LL);
if ( result < 0 )
{
v4 = _errno_location();
test_msg("ERR: %s:%d: can't set timer %d (errno = %d)\n", "timers.c", 56LL, v0, (unsigned int)*v4);
exit(1);
}
++v0;
v1 += 3;
}
while ( v0 != 3 );
return result;
}

canonical_decompiled_code:
int func2()
{
unsigned int v0; // er12
__itimer_which_t *v1; // rbx
int result; // eax
int *v3; // rax
int *v4; // rax
struct itimerval v5; // [rsp+0h] [rbp-38h] BYREF

v0 = 0;
v1 = (__itimer_which_t *)&timer_tests;
v5.it_interval.tv_sec = 0LL;
v5.it_interval.tv_usec = 100000LL;
v5.it_value.tv_sec = 0LL;
v5.it_value.tv_usec = 100LL;
do
{
if ( signal(*((_DWORD *)v1 + 1), timer_tick) == (__sighandler_t)-1LL )
{
v3 = _errno_location();
test_msg("ERR: %s:%d: can't set signal handler %d (errno = %d)\n", "timers.c", 51LL, v0, (unsigned int)*v3);
exit(1);
}
result = setitimer(*v1, &v5, 0LL);
if ( result < 0 )
{
v4 = _errno_location();
test_msg("ERR: %s:%d: can't set timer %d (errno = %d)\n", "timers.c", 56LL, v0, (unsigned int)*v4);
exit(1);
}
++v0;
v1 += 3;
}
while ( v0 != 3 );
return result;
}

original_code:
static void setup_timers(void)
{
 int i;
 struct itimerval tv = {
  .it_interval = {
   .tv_sec = 0,
   .tv_usec = 100000
  },
  .it_value = {
   .tv_sec = 0,
   .tv_usec = 100
  },
 };
 for (i = 0; i < (sizeof(timer_tests) / sizeof(timer_tests[0])); i++) {
  if (signal(timer_tests[i].signal, timer_tick) == ((__sighandler_t) -1)) {
   test_msg("ERR: %s:%d: " "can't set signal handler %d" " (errno = %d)\n", "timers.c", 51, i, (*__errno_location ()));
   exit(1);
  }
  if (setitimer(timer_tests[i].timer_type, &tv, ((void *)0)) < 0) {
   test_msg("ERR: %s:%d: " "can't set timer %d" " (errno = %d)\n", "timers.c", 56, i, (*__errno_location ()));
   exit(1);
  }
 }
}

canonical_original_code:
static void setup_timers()
{
 int i;
 struct itimerval tv = {
  .it_interval = {
   .tv_sec = 0,
   .tv_usec = 100000
  },
  .it_value = {
   .tv_sec = 0,
   .tv_usec = 100
  },
 };
 for (i = 0; i < (sizeof(timer_tests) / sizeof(timer_tests[0])); i++) {
  if (signal(timer_tests[i].signal, timer_tick) == ((__sighandler_t) -1)) {
   test_msg("ERR: %s:%d: " "can't set signal handler %d" " (errno = %d)\n", "timers.c", 51, i, (*__errno_location ()));
   exit(1);
  }
  if (setitimer(timer_tests[i].timer_type, &tv, ((void *)0)) < 0) {
   test_msg("ERR: %s:%d: " "can't set timer %d" " (errno = %d)\n", "timers.c", 56, i, (*__errno_location ()));
   exit(1);
  }
 }
}

variable_types: i int

variable_types: struct itimerval { struct timeval { long tv_sec; long tv_usec; } it_interval; struct timeval it_value; }

user_defined_types: struct itimerval { struct timeval it_interval; struct timeval it_value; }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
test_init(argc, argv, envp);
setup_timers();
test_daemon();
test_waitsig();
check_timers();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
test_init(argc, argv, envp);
func2();
test_daemon();
test_waitsig();
func1();
return 0;
}

original_code:
int main(int argc, char **argv)
{
 test_init(argc, argv);
 setup_timers();
 test_daemon();
 test_waitsig();
 check_timers();
 return 0;
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
__int64 __fastcall ns_exec(void *arg)
{
__int64 result; // rax

close(*((_DWORD *)arg + 1028));
setsid();
system("ip link set up dev lo");
if ( dup2(*((_DWORD *)arg + 1029), 255) < 0 )
{
fprintf(stderr, "dup2() failed: %m\n");
result = 0xFFFFFFFFLL;
}
else
{
close(*((_DWORD *)arg + 1029));
if ( !(unsigned int)prepare_mntns() )
{
setenv("ZDTM_EXE", "1", 0);
execvp(**((const char ***)arg + 513), *((char *const **)arg + 513));
fprintf(stderr, "exec(%s) failed: %m\n", **((const char ***)arg + 513));
}
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *arg)
{
__int64 result; // rax

close(*((_DWORD *)arg + 1028));
setsid();
system("ip link set up dev lo");
if ( dup2(*((_DWORD *)arg + 1029), 255) < 0 )
{
fprintf(stderr, "dup2() failed: %m\n");
result = 0xFFFFFFFFLL;
}
else
{
close(*((_DWORD *)arg + 1029));
if ( !(unsigned int)func0() )
{
setenv("ZDTM_EXE", "1", 0);
execvp(**((const char ***)arg + 513), *((char *const **)arg + 513));
fprintf(stderr, "exec(%s) failed: %m\n", **((const char ***)arg + 513));
}
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int ns_exec(void *_arg)
{
 struct ns_exec_args *args = (struct ns_exec_args *) _arg;
 int ret;
 close(args->status_pipe[0]);
 setsid();
 system("ip link set up dev lo");
 ret = dup2(args->status_pipe[1], 255);
 if (ret < 0) {
  fprintf(stderr, "dup2() failed: %m\n");
  return -1;
 }
 close(args->status_pipe[1]);
 if (prepare_mntns())
  return -1;
 setenv("ZDTM_EXE", "1", 0);
 execvp(args->argv[0], args->argv);
 fprintf(stderr, "exec(%s) failed: %m\n", args->argv[0]);
 return -1;
}

variable_types: struct ns_exec_args { char stack[4096]; char stack_ptr[]; int argc; char **argv; int status_pipe[2]; } *

variable_types: ret int


decompiled_code:
unsigned int __fastcall ns_sig_hand(int a1)
{
unsigned int result; // eax
size_t v2; // rdx
int v3; // eax
int stat_loc; // [rsp+0h] [rbp-9Ch] BYREF
__m128i buf; // [rsp+4h] [rbp-98h] BYREF
__int128 v6[8]; // [rsp+14h] [rbp-88h] BYREF

buf = 0LL;
v6[0] = 0LL;
v6[1] = 0LL;
v6[2] = 0LL;
v6[3] = 0LL;
v6[4] = 0LL;
v6[5] = 0LL;
v6[6] = 0LL;
if ( a1 == 15 )
{
sig_received = 15;
*(_QWORD *)&v6[0] = 0xA6B6365686320LL;
buf = _mm_load_si128((const __m128i *)&LC31);
LABEL_11:
v2 = 128LL;
LABEL_12:
result = write(2, &buf, v2);
}
else
{
while ( 1 )
{
result = waitpid(-1, &stat_loc, 1);
if ( !result )
break;
if ( result == -1 )
{
if ( *_errno_location() != 10 )
{
v3 = snprintf(buf.m128i_i8, 0x80uLL, "wait() failed: %m\n");
if ( (unsigned int)v3 <= 0x80 )
v2 = 128LL;
else
v2 = v3;
goto LABEL_12;
}
result = sig_received;
if ( sig_received )
return result;
sig_received = a1;
strcpy((char *)v6, "es exited\n");
buf = _mm_load_si128((const __m128i *)&LC32);
goto LABEL_11;
}
if ( stat_loc )
fprintf(stderr, "%d return %d\n", result, (unsigned int)stat_loc);
}
}
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func2(int a1)
{
unsigned int result; // eax
size_t v2; // rdx
int v3; // eax
int stat_loc; // [rsp+0h] [rbp-9Ch] BYREF
__m128i buf; // [rsp+4h] [rbp-98h] BYREF
__int128 v6[8]; // [rsp+14h] [rbp-88h] BYREF

buf = 0LL;
v6[0] = 0LL;
v6[1] = 0LL;
v6[2] = 0LL;
v6[3] = 0LL;
v6[4] = 0LL;
v6[5] = 0LL;
v6[6] = 0LL;
if ( a1 == 15 )
{
sig_received = 15;
*(_QWORD *)&v6[0] = 0xA6B6365686320LL;
buf = _mm_load_si128((const __m128i *)&LC31);
LABEL_11:
v2 = 128LL;
LABEL_12:
result = write(2, &buf, v2);
}
else
{
while ( 1 )
{
result = waitpid(-1, &stat_loc, 1);
if ( !result )
break;
if ( result == -1 )
{
if ( *_errno_location() != 10 )
{
v3 = snprintf(buf.m128i_i8, 0x80uLL, "wait() failed: %m\n");
if ( (unsigned int)v3 <= 0x80 )
v2 = 128LL;
else
v2 = v3;
goto LABEL_12;
}
result = sig_received;
if ( sig_received )
return result;
sig_received = a1;
strcpy((char *)v6, "es exited\n");
buf = _mm_load_si128((const __m128i *)&LC32);
goto LABEL_11;
}
if ( stat_loc )
fprintf(stderr, "%d return %d\n", result, (unsigned int)stat_loc);
}
}
return result;
}

original_code:
static void ns_sig_hand(int signo)
{
 int status, len = 0;
 pid_t pid;
 char buf[128] = "";
 if (signo == 15) {
  sig_received = signo;
  len = snprintf(buf, sizeof(buf), "Time to stop and check\n");
  goto write_out;
 }
 while (1) {
  pid = waitpid(-1, &status, 1);
  if (pid == 0)
   return;
  if (pid == -1) {
   if ((*__errno_location ()) == 10) {
    if (sig_received)
     return;
    sig_received = signo;
    len = snprintf(buf, sizeof(buf),
      "All test processes exited\n");
   } else {
    len = snprintf(buf, sizeof(buf),
      "wait() failed: %m\n");
   }
    goto write_out;
  }
  if (status)
   fprintf(stderr, "%d return %d\n", pid, status);
 }
 return;
write_out:
 write(2, buf, (((len)>(sizeof(buf)))?(len):(sizeof(buf))));
}

canonical_original_code:
static void ns_sig_hand(int signo)
{
 int status; int len = 0;
 int pid;
 char buf[128] = "";
 if (signo == 15) {
  sig_received = signo;
  len = snprintf(buf, sizeof(buf), "Time to stop and check\n");
  goto write_out;
 }
 while (1) {
  pid = waitpid(-1, &status, 1);
  if (pid == 0)
   return;
  if (pid == -1) {
   if ((*__errno_location ()) == 10) {
    if (sig_received)
     return;
    sig_received = signo;
    len = snprintf(buf, sizeof(buf),
      "All test processes exited\n");
   } else {
    len = snprintf(buf, sizeof(buf),
      "wait() failed: %m\n");
   }
    goto write_out;
  }
  if (status)
   fprintf(stderr, "%d return %d\n", pid, status);
 }
 return;
write_out:
 write(2, buf, (((len)>(sizeof(buf)))?(len):(sizeof(buf))));
}

variable_types: signo int

variable_types: status int

variable_types: len int

variable_types:
buf
char [128]


decompiled_code:
__int64 __fastcall ns_init(__int64 a1, const char **a2)
{
int v2; // eax
__int64 result; // rax
int v4; // edi
int v5; // eax
const char *v6; // rsi
__int64 v7; // rbp
int v8; // eax
const char *v9; // rdx
int stat_loc; // [rsp+Ch] [rbp-13Ch] BYREF
char buf[128]; // [rsp+10h] [rbp-138h] BYREF
struct sigaction v12; // [rsp+90h] [rbp-B8h] BYREF

v12.sa_handler = (__sighandler_t)ns_sig_hand;
memset(&v12.sa_mask, 0, 0x90uLL);
v12.sa_flags = 0x10000000;
stat_loc = fcntl(255, 2, 1LL);
if ( stat_loc == -1 )
{
v6 = "fcntl failed %m\n";
LABEL_16:
fprintf(stderr, v6);
goto LABEL_17;
}
sigemptyset(&v12.sa_mask);
sigaddset(&v12.sa_mask, 15);
sigaddset(&v12.sa_mask, 17);
if ( sigaction(15, &v12, 0LL) )
{
fprintf(stderr, "Can't set SIGTERM handler: %m\n");
LABEL_17:
exit(1);
}
if ( sigaction(17, &v12, 0LL) )
{
fprintf(stderr, "Can't set SIGCHLD handler: %m\n");
goto LABEL_17;
}
v2 = fork();
if ( v2 < 0 )
{
fprintf(stderr, "fork() failed: %m\n");
goto LABEL_17;
}
if ( v2 )
{
stat_loc = 1;
waitpid(v2, &stat_loc, 0);
write(255, &stat_loc, 4uLL);
close(255);
result = (unsigned int)stat_loc;
if ( !stat_loc )
{
test_waitsig();
v4 = open(pidfile, 0);
if ( v4 == -1 )
{
fprintf(stderr, "open(%s) failed: %m\n", pidfile);
exit(1);
}
v5 = read(v4, buf, 0x7FuLL);
v6 = "read() failed: %m\n";
stat_loc = v5;
buf[v5] = 0;
if ( v5 != -1 )
{
v7 = (unsigned int)atoi(buf);
fprintf(stderr, "kill(%d, SIGTERM)\n", v7);
if ( (int)v7 > 0 )
kill(v7, 15);
for ( stat_loc = 0; stat_loc != -1; stat_loc = wait(0LL) )
;
exit(1);
}
goto LABEL_16;
}
}
else
{
v8 = execvp(*a2, (char *const *)a2);
v9 = *a2;
stat_loc = v8;
fprintf(stderr, "exec(%s) failed: %m\n", v9);
result = (unsigned int)stat_loc;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const char **a2)
{
int v2; // eax
__int64 result; // rax
int v4; // edi
int v5; // eax
const char *v6; // rsi
__int64 v7; // rbp
int v8; // eax
const char *v9; // rdx
int stat_loc; // [rsp+Ch] [rbp-13Ch] BYREF
char buf[128]; // [rsp+10h] [rbp-138h] BYREF
struct sigaction v12; // [rsp+90h] [rbp-B8h] BYREF

v12.sa_handler = (__sighandler_t)ns_sig_hand;
memset(&v12.sa_mask, 0, 0x90uLL);
v12.sa_flags = 0x10000000;
stat_loc = fcntl(255, 2, 1LL);
if ( stat_loc == -1 )
{
v6 = "fcntl failed %m\n";
LABEL_16:
fprintf(stderr, v6);
goto LABEL_17;
}
sigemptyset(&v12.sa_mask);
sigaddset(&v12.sa_mask, 15);
sigaddset(&v12.sa_mask, 17);
if ( sigaction(15, &v12, 0LL) )
{
fprintf(stderr, "Can't set SIGTERM handler: %m\n");
LABEL_17:
exit(1);
}
if ( sigaction(17, &v12, 0LL) )
{
fprintf(stderr, "Can't set SIGCHLD handler: %m\n");
goto LABEL_17;
}
v2 = fork();
if ( v2 < 0 )
{
fprintf(stderr, "fork() failed: %m\n");
goto LABEL_17;
}
if ( v2 )
{
stat_loc = 1;
waitpid(v2, &stat_loc, 0);
write(255, &stat_loc, 4uLL);
close(255);
result = (unsigned int)stat_loc;
if ( !stat_loc )
{
test_waitsig();
v4 = open(pidfile, 0);
if ( v4 == -1 )
{
fprintf(stderr, "open(%s) failed: %m\n", pidfile);
exit(1);
}
v5 = read(v4, buf, 0x7FuLL);
v6 = "read() failed: %m\n";
stat_loc = v5;
buf[v5] = 0;
if ( v5 != -1 )
{
v7 = (unsigned int)atoi(buf);
fprintf(stderr, "kill(%d, SIGTERM)\n", v7);
if ( (int)v7 > 0 )
kill(v7, 15);
for ( stat_loc = 0; stat_loc != -1; stat_loc = wait(0LL) )
;
exit(1);
}
goto LABEL_16;
}
}
else
{
v8 = execvp(*a2, (char *const *)a2);
v9 = *a2;
stat_loc = v8;
fprintf(stderr, "exec(%s) failed: %m\n", v9);
result = (unsigned int)stat_loc;
}
return result;
}

original_code:
int ns_init(int argc, char **argv)
{
 struct sigaction sa = {
  .__sigaction_handler.sa_handler = ns_sig_hand,
  .sa_flags = 0x10000000,
 };
 int ret, fd, status_pipe = 255;
 char buf[128];
 pid_t pid;
 ret = fcntl(status_pipe, 2, 1);
 if (ret == -1) {
  fprintf(stderr, "fcntl failed %m\n");
  exit(1);
 }
 sigemptyset(&sa.sa_mask);
 sigaddset(&sa.sa_mask, 15);
 sigaddset(&sa.sa_mask, 17);
 if (sigaction(15, &sa, ((void *)0))) {
  fprintf(stderr, "Can't set SIGTERM handler: %m\n");
  exit(1);
 }
 if (sigaction(17, &sa, ((void *)0))) {
  fprintf(stderr, "Can't set SIGCHLD handler: %m\n");
  exit(1);
 }
 pid = fork();
 if (pid < 0) {
  fprintf(stderr, "fork() failed: %m\n");
  exit(1);
 } else if (pid == 0) {
  ret = execvp(argv[0], argv);
  fprintf(stderr, "exec(%s) failed: %m\n", argv[0]);
  return ret;
 }
 ret = 1;
 waitpid(pid, &ret, 0);
 write(status_pipe, &ret, sizeof(ret));
 close(status_pipe);
 if (ret)
  return ret;
 test_waitsig();
 fd = open(pidfile, 00);
 if (fd == -1) {
  fprintf(stderr, "open(%s) failed: %m\n", pidfile);
  exit(1);
 }
 ret = read(fd, buf, sizeof(buf) - 1);
 buf[ret] = '\0';
 if (ret == -1) {
  fprintf(stderr, "read() failed: %m\n");
  exit(1);
 }
 pid = atoi(buf);
 fprintf(stderr, "kill(%d, SIGTERM)\n", pid);
 if (pid > 0)
  kill(pid, 15);
 ret = 0;
 while (ret != -1)
  ret = wait(((void *)0));
 exit(1);
}

canonical_original_code:
int ns_init(int argc, char **argv)
{
 struct sigaction sa = {
  .__sigaction_handler.sa_handler = ns_sig_hand,
  .sa_flags = 0x10000000,
 };
 int ret; int fd; int status_pipe = 255;
 char buf[128];
 int pid;
 ret = fcntl(status_pipe, 2, 1);
 if (ret == -1) {
  fprintf(stderr, "fcntl failed %m\n");
  exit(1);
 }
 sigemptyset(&sa.sa_mask);
 sigaddset(&sa.sa_mask, 15);
 sigaddset(&sa.sa_mask, 17);
 if (sigaction(15, &sa, ((void *)0))) {
  fprintf(stderr, "Can't set SIGTERM handler: %m\n");
  exit(1);
 }
 if (sigaction(17, &sa, ((void *)0))) {
  fprintf(stderr, "Can't set SIGCHLD handler: %m\n");
  exit(1);
 }
 pid = fork();
 if (pid < 0) {
  fprintf(stderr, "fork() failed: %m\n");
  exit(1);
 } else if (pid == 0) {
  ret = execvp(argv[0], argv);
  fprintf(stderr, "exec(%s) failed: %m\n", argv[0]);
  return ret;
 }
 ret = 1;
 waitpid(pid, &ret, 0);
 write(status_pipe, &ret, sizeof(ret));
 close(status_pipe);
 if (ret)
  return ret;
 test_waitsig();
 fd = open(pidfile, 00);
 if (fd == -1) {
  fprintf(stderr, "open(%s) failed: %m\n", pidfile);
  exit(1);
 }
 ret = read(fd, buf, sizeof(buf) - 1);
 buf[ret] = '\0';
 if (ret == -1) {
  fprintf(stderr, "read() failed: %m\n");
  exit(1);
 }
 pid = atoi(buf);
 fprintf(stderr, "kill(%d, SIGTERM)\n", pid);
 if (pid > 0)
  kill(pid, 15);
 ret = 0;
 while (ret != -1)
  ret = wait(((void *)0));
 exit(1);
}

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

variable_types: fd int


decompiled_code:
void __fastcall __noreturn ns_create(int a1, __int64 a2)
{
const char *v2; // rsi
int v3; // er12
int v4; // eax
int v5; // ebp
int buf; // [rsp+Ch] [rbp-103Ch] BYREF
char arg[4096]; // [rsp+10h] [rbp-1038h] BYREF
int child_stack; // [rsp+1010h] [rbp-38h] BYREF
__int64 v9; // [rsp+1018h] [rbp-30h]
int pipedes[2]; // [rsp+1020h] [rbp-28h] BYREF

child_stack = a1;
v9 = a2;
v2 = "Pipe() failed %m\n";
if ( !pipe(pipedes) )
{
v3 = clone((int (*)(void *))ns_exec, &child_stack, 1812070417, arg);
if ( v3 >= 0 )
{
close(pipedes[1]);
buf = 1;
if ( (unsigned int)read(pipedes[0], &buf, 4uLL) == 4 && !buf && !(unsigned int)read(pipedes[0], &buf, 4uLL) )
{
pidfile = getenv("ZDTM_PIDFILE");
if ( pidfile )
{
v4 = open(pidfile, 193, 438LL);
v5 = v4;
if ( v4 == -1 )
{
fprintf(stderr, "Can't create the file %s: %m\n", pidfile);
}
else
{
if ( dprintf(v4, "%d", (unsigned int)v3) != -1 )
{
close(v5);
exit(0);
}
fprintf(stderr, "Can't write in the file %s: %m\n", pidfile);
}
}
}
LABEL_12:
exit(1);
}
v2 = "clone() failed: %m\n";
}
fprintf(stderr, v2);
goto LABEL_12;
}

canonical_decompiled_code:
void __fastcall __noreturn func4(int a1, __int64 a2)
{
const char *v2; // rsi
int v3; // er12
int v4; // eax
int v5; // ebp
int buf; // [rsp+Ch] [rbp-103Ch] BYREF
char arg[4096]; // [rsp+10h] [rbp-1038h] BYREF
int child_stack; // [rsp+1010h] [rbp-38h] BYREF
__int64 v9; // [rsp+1018h] [rbp-30h]
int pipedes[2]; // [rsp+1020h] [rbp-28h] BYREF

child_stack = a1;
v9 = a2;
v2 = "Pipe() failed %m\n";
if ( !pipe(pipedes) )
{
v3 = clone((int (*)(void *))ns_exec, &child_stack, 1812070417, arg);
if ( v3 >= 0 )
{
close(pipedes[1]);
buf = 1;
if ( (unsigned int)read(pipedes[0], &buf, 4uLL) == 4 && !buf && !(unsigned int)read(pipedes[0], &buf, 4uLL) )
{
pidfile = getenv("ZDTM_PIDFILE");
if ( pidfile )
{
v4 = open(pidfile, 193, 438LL);
v5 = v4;
if ( v4 == -1 )
{
fprintf(stderr, "Can't create the file %s: %m\n", pidfile);
}
else
{
if ( dprintf(v4, "%d", (unsigned int)v3) != -1 )
{
close(v5);
exit(0);
}
fprintf(stderr, "Can't write in the file %s: %m\n", pidfile);
}
}
}
LABEL_12:
exit(1);
}
v2 = "clone() failed: %m\n";
}
fprintf(stderr, v2);
goto LABEL_12;
}

original_code:
void ns_create(int argc, char **argv)
{
 pid_t pid;
 int ret, status;
 struct ns_exec_args args;
 int fd;
 args.argc = argc;
 args.argv = argv;
 ret = pipe(args.status_pipe);
 if (ret) {
  fprintf(stderr, "Pipe() failed %m\n");
  exit(1);
 }
 pid = clone(ns_exec, args.stack_ptr,
   0x20000000 | 0x00020000 | 0x04000000 |
   0x40000000 | 0x08000000 | 17, &args);
 if (pid < 0) {
  fprintf(stderr, "clone() failed: %m\n");
  exit(1);
 }
 close(args.status_pipe[1]);
 status = 1;
 ret = read(args.status_pipe[0], &status, sizeof(status));
 if (ret != sizeof(status) || status)
  exit(1);
 ret = read(args.status_pipe[0], &status, sizeof(status));
 if (ret != 0)
  exit(1);
 pidfile = getenv("ZDTM_PIDFILE");
 if (pidfile == ((void *)0))
  exit(1);
 fd = open(pidfile, 0100 | 0200 | 01, 0666);
 if (fd == -1) {
  fprintf(stderr, "Can't create the file %s: %m\n", pidfile);
  exit(1);
 }
 if (dprintf(fd, "%d", pid) == -1) {
  fprintf(stderr, "Can't write in the file %s: %m\n", pidfile);
  exit(1);
 }
 close(fd);
 exit(0);
}

canonical_original_code:
void ns_create(int argc, char **argv)
{
 int pid;
 int ret; int status;
 struct ns_exec_args args;
 int fd;
 args.argc = argc;
 args.argv = argv;
 ret = pipe(args.status_pipe);
 if (ret) {
  fprintf(stderr, "Pipe() failed %m\n");
  exit(1);
 }
 pid = clone(ns_exec, args.stack_ptr,
   0x20000000 | 0x00020000 | 0x04000000 |
   0x40000000 | 0x08000000 | 17, &args);
 if (pid < 0) {
  fprintf(stderr, "clone() failed: %m\n");
  exit(1);
 }
 close(args.status_pipe[1]);
 status = 1;
 ret = read(args.status_pipe[0], &status, sizeof(status));
 if (ret != sizeof(status) || status)
  exit(1);
 ret = read(args.status_pipe[0], &status, sizeof(status));
 if (ret != 0)
  exit(1);
 pidfile = getenv("ZDTM_PIDFILE");
 if (pidfile == ((void *)0))
  exit(1);
 fd = open(pidfile, 0100 | 0200 | 01, 0666);
 if (fd == -1) {
  fprintf(stderr, "Can't create the file %s: %m\n", pidfile);
  exit(1);
 }
 if (dprintf(fd, "%d", pid) == -1) {
  fprintf(stderr, "Can't write in the file %s: %m\n", pidfile);
  exit(1);
 }
 close(fd);
 exit(0);
}

variable_types: struct ns_exec_args { char stack[4096]; char stack_ptr[]; int argc; char **argv; int status_pipe[2]; }


decompiled_code:
int __fastcall set_nonblock(int fd, int a2)
{
int result; // eax
__int64 v3; // rdx

result = fcntl(fd, 3, 0LL);
if ( result >= 0 )
{
v3 = (unsigned int)result;
BYTE1(result) &= 0xF7u;
BYTE1(v3) |= 8u;
if ( !a2 )
v3 = (unsigned int)result;
result = fcntl(fd, 4, v3);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(int fd, int a2)
{
int result; // eax
__int64 v3; // rdx

result = fcntl(fd, 3, 0LL);
if ( result >= 0 )
{
v3 = (unsigned int)result;
BYTE1(result) &= 0xF7u;
BYTE1(v3) |= 8u;
if ( !a2 )
v3 = (unsigned int)result;
result = fcntl(fd, 4, v3);
}
return result;
}

original_code:
int set_nonblock(int fd, int on)
{
 int flag;
 flag = fcntl(fd, 3, 0);
 if (flag < 0)
  return flag;
 if (on)
  flag |= 04000;
 else
  flag &= ~04000;
 return fcntl(fd, 4, flag);
}

variable_types: on int

variable_types: flag int


decompiled_code:
__int64 __fastcall pipe_in2out(int fd, int a2, void *buf, int a4)
{
size_t v4; // r12
int v6; // eax
int v7; // er14
char *v8; // r15
int v9; // eax
unsigned int v10; // er8

v4 = a4;
LABEL_2:
v6 = read(fd, buf, v4);
v7 = v6;
if ( v6 <= 0 )
return (unsigned int)v6;
v8 = (char *)buf;
while ( 1 )
{
v9 = write(a2, v8, v7);
v10 = v9;
if ( v9 < 0 )
break;
v7 -= v9;
v8 += v9;
if ( v7 <= 0 )
goto LABEL_2;
}
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd, int a2, void *buf, int a4)
{
size_t v4; // r12
int v6; // eax
int v7; // er14
char *v8; // r15
int v9; // eax
unsigned int v10; // er8

v4 = a4;
LABEL_2:
v6 = read(fd, buf, v4);
v7 = v6;
if ( v6 <= 0 )
return (unsigned int)v6;
v8 = (char *)buf;
while ( 1 )
{
v9 = write(a2, v8, v7);
v10 = v9;
if ( v9 < 0 )
break;
v7 -= v9;
v8 += v9;
if ( v7 <= 0 )
goto LABEL_2;
}
return v10;
}

original_code:
int pipe_in2out(int infd, int outfd, uint8_t *buffer, int length)
{
 uint8_t *buf;
 int rlen, wlen;
 while (1) {
  rlen = read(infd, buffer, length);
  if (rlen <= 0)
   return rlen;
  for (buf = buffer; rlen > 0; buf += wlen, rlen -= wlen) {
   wlen = write(outfd, buf, rlen);
   if (wlen < 0)
    return wlen;
  }
 }
}

canonical_original_code:
int pipe_in2out(int infd, int outfd, unsigned char *buffer, int length)
{
 unsigned char *buf;
 int rlen; int wlen;
 while (1) {
  rlen = read(infd, buffer, length);
  if (rlen <= 0)
   return rlen;
  for (buf = buffer; rlen > 0; buf += wlen, rlen -= wlen) {
   wlen = write(outfd, buf, rlen);
   if (wlen < 0)
    return wlen;
  }
 }
}

variable_types: infd int

variable_types: outfd int

variable_types:
buffer
unsigned char *

variable_types: length int

variable_types:
buf
unsigned char *

variable_types: rlen int

variable_types: wlen int


decompiled_code:
__int64 chk_proc_sse2()
{
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 & 0x4000000;
}

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 & 0x4000000;
}

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

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

variable_types:
eax
unsigned int

variable_types:
ebx
unsigned int

variable_types:
ecx
unsigned int

variable_types:
edx
unsigned int


decompiled_code:
__int64 __fastcall tcp_init_server(unsigned int *a1)
{
int v2; // eax
unsigned int v3; // er12
int i; // edi
socklen_t v5; // edx
__int64 v6; // rcx
int *v8; // rax
int *v9; // rax
int *v10; // rax
int optval; // [rsp+0h] [rbp-2Ch] BYREF
struct sockaddr v12; // [rsp+4h] [rbp-28h] BYREF

v12 = 0LL;
optval = 1;
v12.sa_family = 2;
*(_DWORD *)&v12.sa_data[2] = inet_addr("0.0.0.0");
v2 = socket(2, 1, 6);
v3 = v2;
if ( v2 == -1 )
{
v9 = _errno_location();
test_msg("ERR: %s:%d: socket() failed %m (errno = %d)\n", "tcp.c", 18LL, (unsigned int)*v9);
}
else if ( setsockopt(v2, 1, 2, &optval, 4u) == -1 )
{
v10 = _errno_location();
v3 = -1;
test_msg("ERR: %s:%d: setsockopt() error (errno = %d)\n", "tcp.c", 23LL, (unsigned int)*v10);
}
else
{
for ( i = *a1; ; *a1 = i )
{
*(_WORD *)v12.sa_data = _bswap_16(i);
if ( bind(v3, &v12, v5) != -1 )
break;
v6 = (unsigned int)*_errno_location();
if ( (_DWORD)v6 != 98 )
{
test_msg("ERR: %s:%d: bind() failed %m (errno = %d)\n", "tcp.c", 41LL, v6);
return (unsigned int)-1;
}
test_msg("The port %d is already in use.\n", *a1);
i = *a1 + 1;
}
if ( listen(v3, 1) == -1 )
{
v8 = _errno_location();
v3 = -1;
test_msg("ERR: %s:%d: listen() failed %m (errno = %d)\n", "tcp.c", 46LL, (unsigned int)*v8);
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int *a1)
{
int v2; // eax
unsigned int v3; // er12
int i; // edi
socklen_t v5; // edx
__int64 v6; // rcx
int *v8; // rax
int *v9; // rax
int *v10; // rax
int optval; // [rsp+0h] [rbp-2Ch] BYREF
struct sockaddr v12; // [rsp+4h] [rbp-28h] BYREF

v12 = 0LL;
optval = 1;
v12.sa_family = 2;
*(_DWORD *)&v12.sa_data[2] = inet_addr("0.0.0.0");
v2 = socket(2, 1, 6);
v3 = v2;
if ( v2 == -1 )
{
v9 = _errno_location();
test_msg("ERR: %s:%d: socket() failed %m (errno = %d)\n", "tcp.c", 18LL, (unsigned int)*v9);
}
else if ( setsockopt(v2, 1, 2, &optval, 4u) == -1 )
{
v10 = _errno_location();
v3 = -1;
test_msg("ERR: %s:%d: setsockopt() error (errno = %d)\n", "tcp.c", 23LL, (unsigned int)*v10);
}
else
{
for ( i = *a1; ; *a1 = i )
{
*(_WORD *)v12.sa_data = func0(i);
if ( bind(v3, &v12, v5) != -1 )
break;
v6 = (unsigned int)*_errno_location();
if ( (_DWORD)v6 != 98 )
{
test_msg("ERR: %s:%d: bind() failed %m (errno = %d)\n", "tcp.c", 41LL, v6);
return (unsigned int)-1;
}
test_msg("The port %d is already in use.\n", *a1);
i = *a1 + 1;
}
if ( listen(v3, 1) == -1 )
{
v8 = _errno_location();
v3 = -1;
test_msg("ERR: %s:%d: listen() failed %m (errno = %d)\n", "tcp.c", 46LL, (unsigned int)*v8);
}
}
return v3;
}

original_code:
int tcp_init_server(int *port)
{
 struct sockaddr_in addr;
 int sock;
 int yes = 1, ret;
 memset(&addr,0,sizeof(addr));
 addr.sin_family = 2;
 addr.sin_addr.s_addr = inet_addr("0.0.0.0");
 sock = socket(2, SOCK_STREAM, IPPROTO_TCP);
 if (sock == -1) {
  test_msg("ERR: %s:%d: " "socket() failed %m" " (errno = %d)\n", "tcp.c", 18, (*__errno_location ()));
  return -1;
 }
 if (setsockopt(sock, 1, 2, &yes, sizeof(int)) == -1 ) {
  test_msg("ERR: %s:%d: " "setsockopt() error" " (errno = %d)\n", "tcp.c", 23, (*__errno_location ()));
  return -1;
 }
 while (1) {
  addr.sin_port = htons(*port);
  ret = bind(sock, (struct sockaddr *) &addr, sizeof(addr));
  if (ret == -1 && (*__errno_location ()) == 98) {
   test_msg("The port %d is already in use.\n", *port);
   (*port)++;
   continue;
  }
  break;
 }
 if (ret == -1) {
  test_msg("ERR: %s:%d: " "bind() failed %m" " (errno = %d)\n", "tcp.c", 41, (*__errno_location ()));
  return -1;
 }
 if (listen(sock, 1) == -1) {
  test_msg("ERR: %s:%d: " "listen() failed %m" " (errno = %d)\n", "tcp.c", 46, (*__errno_location ()));
  return -1;
 }
 return sock;
}

canonical_original_code:
int tcp_init_server(int *port)
{
 struct sockaddr_in addr;
 int sock;
 int yes = 1; int ret;
 memset(&addr,0,sizeof(addr));
 addr.sin_family = 2;
 addr.sin_addr.s_addr = inet_addr("0.0.0.0");
 sock = socket(2, SOCK_STREAM, IPPROTO_TCP);
 if (sock == -1) {
  test_msg("ERR: %s:%d: " "socket() failed %m" " (errno = %d)\n", "tcp.c", 18, (*__errno_location ()));
  return -1;
 }
 if (setsockopt(sock, 1, 2, &yes, sizeof(int)) == -1 ) {
  test_msg("ERR: %s:%d: " "setsockopt() error" " (errno = %d)\n", "tcp.c", 23, (*__errno_location ()));
  return -1;
 }
 while (1) {
  addr.sin_port = htons(*port);
  ret = bind(sock, (struct sockaddr *) &addr, sizeof(addr));
  if (ret == -1 && (*__errno_location ()) == 98) {
   test_msg("The port %d is already in use.\n", *port);
   (*port)++;
   continue;
  }
  break;
 }
 if (ret == -1) {
  test_msg("ERR: %s:%d: " "bind() failed %m" " (errno = %d)\n", "tcp.c", 41, (*__errno_location ()));
  return -1;
 }
 if (listen(sock, 1) == -1) {
  test_msg("ERR: %s:%d: " "listen() failed %m" " (errno = %d)\n", "tcp.c", 46, (*__errno_location ()));
  return -1;
 }
 return sock;
}

variable_types:
port
int *

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

variable_types: sock int

variable_types: yes int

variable_types: ret int

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

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


decompiled_code:
__int64 __fastcall tcp_accept_server(int a1)
{
unsigned int v1; // er12
int *v3; // rax
socklen_t addr_len; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

addr_len = 16;
v1 = accept(a1, &addr, &addr_len);
if ( v1 == -1 )
{
v3 = _errno_location();
test_msg("ERR: %s:%d: accept() failed %m (errno = %d)\n", "tcp.c", 64LL, (unsigned int)*v3);
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
unsigned int v1; // er12
int *v3; // rax
socklen_t addr_len; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

addr_len = 16;
v1 = accept(a1, &addr, &addr_len);
if ( v1 == -1 )
{
v3 = _errno_location();
test_msg("ERR: %s:%d: accept() failed %m (errno = %d)\n", "tcp.c", 64LL, (unsigned int)*v3);
}
return v1;
}

original_code:
int tcp_accept_server(int sock)
{
 struct sockaddr_in maddr;
 int sock2;
 socklen_t addrlen;
 addrlen = sizeof(maddr);
 sock2 = accept(sock,(struct sockaddr *) &maddr, &addrlen);
 if (sock2 == -1) {
  test_msg("ERR: %s:%d: " "accept() failed %m" " (errno = %d)\n", "tcp.c", 64, (*__errno_location ()));
  return -1;
 }
 return sock2;
}

canonical_original_code:
int tcp_accept_server(int sock)
{
 struct sockaddr_in maddr;
 int sock2;
 unsigned int addrlen;
 addrlen = sizeof(maddr);
 sock2 = accept(sock,(struct sockaddr *) &maddr, &addrlen);
 if (sock2 == -1) {
  test_msg("ERR: %s:%d: " "accept() failed %m" " (errno = %d)\n", "tcp.c", 64, (*__errno_location ()));
  return -1;
 }
 return sock2;
}

variable_types:
addrlen
unsigned int


decompiled_code:
__int64 __fastcall tcp_init_client(char *cp, __int16 a2)
{
int v2; // eax
unsigned int v3; // er12
socklen_t v4; // edx
int *v6; // rax
int *v7; // rax
struct sockaddr v8; // [rsp+0h] [rbp-28h] BYREF

v2 = socket(2, 1, 6);
if ( v2 < 0 )
{
v6 = _errno_location();
v3 = -1;
test_msg("ERR: %s:%d: can't create socket %m (errno = %d)\n", "tcp.c", 80LL, (unsigned int)*v6);
}
else
{
v3 = v2;
v8 = 0LL;
v8.sa_family = 2;
*(_DWORD *)&v8.sa_data[2] = inet_addr(cp);
*(_WORD *)v8.sa_data = _bswap_16(a2);
if ( connect(v3, &v8, v4) < 0 )
{
v7 = _errno_location();
v3 = -1;
test_msg("ERR: %s:%d: can't connect to server %m (errno = %d)\n", "tcp.c", 89LL, (unsigned int)*v7);
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *cp, __int16 a2)
{
int v2; // eax
unsigned int v3; // er12
socklen_t v4; // edx
int *v6; // rax
int *v7; // rax
struct sockaddr v8; // [rsp+0h] [rbp-28h] BYREF

v2 = socket(2, 1, 6);
if ( v2 < 0 )
{
v6 = _errno_location();
v3 = -1;
test_msg("ERR: %s:%d: can't create socket %m (errno = %d)\n", "tcp.c", 80LL, (unsigned int)*v6);
}
else
{
v3 = v2;
v8 = 0LL;
v8.sa_family = 2;
*(_DWORD *)&v8.sa_data[2] = inet_addr(cp);
*(_WORD *)v8.sa_data = func0(a2);
if ( connect(v3, &v8, v4) < 0 )
{
v7 = _errno_location();
v3 = -1;
test_msg("ERR: %s:%d: can't connect to server %m (errno = %d)\n", "tcp.c", 89LL, (unsigned int)*v7);
}
}
return v3;
}

original_code:
int tcp_init_client(char *servIP, unsigned short servPort)
{
 int sock;
 struct sockaddr_in servAddr;
 if ((sock = socket(2, SOCK_STREAM, IPPROTO_TCP)) < 0) {
  test_msg("ERR: %s:%d: " "can't create socket %m" " (errno = %d)\n", "tcp.c", 80, (*__errno_location ()));
  return -1;
 }
 memset(&servAddr, 0, sizeof(servAddr));
 servAddr.sin_family = 2;
 servAddr.sin_addr.s_addr = inet_addr(servIP);
 servAddr.sin_port = htons(servPort);
 if (connect(sock, (struct sockaddr *) &servAddr, sizeof(servAddr)) < 0) {
  test_msg("ERR: %s:%d: " "can't connect to server %m" " (errno = %d)\n", "tcp.c", 89, (*__errno_location ()));
  return -1;
 }
 return sock;
}

variable_types:
servIP
char *

variable_types:
servPort
unsigned short


decompiled_code:
__int64 form_request_del()
{
int v0; // eax

memset(&req, 0, 0x201CuLL);
LODWORD(req) = 28;
rtap = (__int64)&req + 28;
*((_DWORD *)&req + 7) = 65544;
inet_pton(2, dsts, (void *)(unsigned int)((_DWORD)&req + 32));
v0 = *(unsigned __int16 *)rtap;
*((_BYTE *)&req + 16) = 2;
HIDWORD(req) = 67436569;
*((_DWORD *)&req + 5) = 16778494;
LODWORD(req) = ((v0 + 3) & 0xFFFFFFFC) + ((req + 3) & 0xFFFFFFFC);
*((_BYTE *)&req + 17) = pn;
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // eax

memset(&req, 0, 0x201CuLL);
LODWORD(req) = 28;
rtap = (__int64)&req + 28;
*((_DWORD *)&req + 7) = 65544;
inet_pton(2, dsts, (void *)(unsigned int)((_DWORD)&req + 32));
v0 = *(unsigned __int16 *)rtap;
*((_BYTE *)&req + 16) = 2;
HIDWORD(req) = 67436569;
*((_DWORD *)&req + 5) = 16778494;
LODWORD(req) = ((v0 + 3) & 0xFFFFFFFC) + ((req + 3) & 0xFFFFFFFC);
*((_BYTE *)&req + 17) = pn;
return 0LL;
}

original_code:
int form_request_del()
{
 bzero(&req, sizeof(req));
 req.nl.nlmsg_len = ((sizeof(struct rtmsg)) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) )));
 rtap = ((struct rtattr *) (((void *) (&req.nl)) + ( (((&req.nl)->nlmsg_len)+4U -1) & ~(4U -1) )));
 rtap->rta_type = RTA_DST;
 rtap->rta_len = (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (4));
 inet_pton(2, dsts,
   ((char *)rtap) + sizeof(struct rtattr));
 req.nl.nlmsg_len = ( ((req.nl.nlmsg_len)+4U -1) & ~(4U -1) ) + ( ((rtap->rta_len)+4U -1) & ~(4U -1) );
 req.nl.nlmsg_flags = 0x400 | 0x04 | 0x01;
 req.nl.nlmsg_type = RTM_DELROUTE;
 req.rt.rtm_family = 2;
 req.rt.rtm_table = RT_TABLE_MAIN;
 req.rt.rtm_protocol = 4;
 req.rt.rtm_scope = RT_SCOPE_UNIVERSE;
 req.rt.rtm_type = RTN_UNICAST;
 req.rt.rtm_dst_len = pn;
 return 0;
}

user_defined_types: struct rtmsg { unsigned char rtm_family; unsigned char rtm_dst_len; unsigned char rtm_src_len; unsigned char rtm_tos; unsigned char rtm_table; unsigned char rtm_protocol; unsigned char rtm_scope; unsigned char rtm_type; unsigned int rtm_flags; }

user_defined_types: struct nlmsghdr { unsigned int nlmsg_len; unsigned short nlmsg_type; unsigned short nlmsg_flags; unsigned int nlmsg_seq; unsigned int nlmsg_pid; }

user_defined_types: struct rtattr { unsigned short rta_len; unsigned short rta_type; }


decompiled_code:
__int64 form_request_add()
{
_QWORD *v0; // rdx
int v1; // eax

memset(&req, 0, 0x201CuLL);
LODWORD(req) = 28;
rtap = (__int64)&req + 28;
*((_DWORD *)&req + 7) = 65544;
inet_pton(2, dsts, (void *)(unsigned int)((_DWORD)&req + 32));
LODWORD(req) = ((*(unsigned __int16 *)rtap + 3) & 0xFFFFFFFC) + ((req + 3) & 0xFFFFFFFC);
v0 = (__int64 *)((char *)&req + (unsigned int)req);
*v0 = 0x100040008LL;
rtap = (__int64)v0;
v1 = req + 3;
HIDWORD(req) = 67436568;
*((_BYTE *)&req + 16) = 2;
*((_DWORD *)&req + 5) = 16778494;
LODWORD(req) = (v1 & 0xFFFFFFFC) + 8;
*((_BYTE *)&req + 17) = pn;
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
_QWORD *v0; // rdx
int v1; // eax

memset(&req, 0, 0x201CuLL);
LODWORD(req) = 28;
rtap = (__int64)&req + 28;
*((_DWORD *)&req + 7) = 65544;
inet_pton(2, dsts, (void *)(unsigned int)((_DWORD)&req + 32));
LODWORD(req) = ((*(unsigned __int16 *)rtap + 3) & 0xFFFFFFFC) + ((req + 3) & 0xFFFFFFFC);
v0 = (__int64 *)((char *)&req + (unsigned int)req);
*v0 = 0x100040008LL;
rtap = (__int64)v0;
v1 = req + 3;
HIDWORD(req) = 67436568;
*((_BYTE *)&req + 16) = 2;
*((_DWORD *)&req + 5) = 16778494;
LODWORD(req) = (v1 & 0xFFFFFFFC) + 8;
*((_BYTE *)&req + 17) = pn;
return 0LL;
}

original_code:
int form_request_add()
{
 int ifcn = 1;
 bzero(&req, sizeof(req));
 req.nl.nlmsg_len = ((sizeof(struct rtmsg)) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) )));
 rtap = ((struct rtattr *) (((void *) (&req.nl)) + ( (((&req.nl)->nlmsg_len)+4U -1) & ~(4U -1) )));
 rtap->rta_type = RTA_DST;
 rtap->rta_len = (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (4));
 inet_pton(2, dsts,
   ((char *)rtap) + sizeof(struct rtattr));
 req.nl.nlmsg_len = ( ((req.nl.nlmsg_len)+4U -1) & ~(4U -1) ) + ( ((rtap->rta_len)+4U -1) & ~(4U -1) );
 rtap = ((struct rtattr *) (((void *) (&req.nl)) + ( (((&req.nl)->nlmsg_len)+4U -1) & ~(4U -1) )));;
 rtap->rta_type = RTA_OIF;
 rtap->rta_len = (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (sizeof(int)));
 memcpy(((char *)rtap) + sizeof(struct rtattr),
   &ifcn, sizeof(int));
 req.nl.nlmsg_len = ( ((req.nl.nlmsg_len)+4U -1) & ~(4U -1) ) + ( ((rtap->rta_len)+4U -1) & ~(4U -1) );
 req.nl.nlmsg_flags = 0x01 | 0x400 | 0x04;
 req.nl.nlmsg_type = RTM_NEWROUTE;
 req.rt.rtm_family = 2;
 req.rt.rtm_table = RT_TABLE_MAIN;
 req.rt.rtm_protocol = 4;
 req.rt.rtm_scope = RT_SCOPE_UNIVERSE;
 req.rt.rtm_type = RTN_UNICAST;
 req.rt.rtm_dst_len = pn;
 return 0;
}

variable_types: ifcn int


decompiled_code:
__int64 send_request()
{
int v0; // edi
__int64 v1; // rax
int *v3; // rax

v0 = *(_DWORD *)&la.sa_data[10];
pa = 16LL;
v1 = (unsigned int)req;
*(_OWORD *)&msg.msg_namelen = 0LL;
*(_OWORD *)&msg.msg_iovlen = 0LL;
*((_DWORD *)&pa + 2) = 0;
msg.msg_name = &pa;
msg.msg_namelen = 12;
iov = (__int64)&req;
*(&iov + 1) = v1;
msg.msg_iov = (iovec *)&iov;
msg.msg_iovlen = 1LL;
*(_OWORD *)&msg.msg_controllen = 0LL;
rtn = sendmsg(v0, &msg, 0);
if ( rtn >= 0 )
return 0LL;
v3 = _errno_location();
test_msg("ERR: %s:%d: sendmsg failed: %m (errno = %d)\n", "netlink00.c", 143LL, (unsigned int)*v3);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // edi
__int64 v1; // rax
int *v3; // rax

v0 = *(_DWORD *)&la.sa_data[10];
pa = 16LL;
v1 = (unsigned int)req;
*(_OWORD *)&msg.msg_namelen = 0LL;
*(_OWORD *)&msg.msg_iovlen = 0LL;
*((_DWORD *)&pa + 2) = 0;
msg.msg_name = &pa;
msg.msg_namelen = 12;
iov = (__int64)&req;
*(&iov + 1) = v1;
msg.msg_iov = (iovec *)&iov;
msg.msg_iovlen = 1LL;
*(_OWORD *)&msg.msg_controllen = 0LL;
rtn = sendmsg(v0, &msg, 0);
if ( rtn >= 0 )
return 0LL;
v3 = _errno_location();
test_msg("ERR: %s:%d: sendmsg failed: %m (errno = %d)\n", "netlink00.c", 143LL, (unsigned int)*v3);
return 0xFFFFFFFFLL;
}

original_code:
int send_request()
{
 bzero(&pa, sizeof(pa));
 pa.nl_family = 16;
 bzero(&msg, sizeof(msg));
 msg.msg_name = (void *) &pa;
 msg.msg_namelen = sizeof(pa);
 iov.iov_base = (void *) &req.nl;
 iov.iov_len = req.nl.nlmsg_len;
 msg.msg_iov = &iov;
 msg.msg_iovlen = 1;
 rtn = sendmsg(fd, &msg, 0);
 if (rtn<0){
  test_msg("ERR: %s:%d: " "sendmsg failed: %m" " (errno = %d)\n", "netlink00.c", 143, (*__errno_location ()));
  return -1;
 }
 return 0;
}


decompiled_code:
__int64 recv_reply()
{
int v0; // eax
char *v1; // rbx
__int16 v2; // dx
__int64 v3; // rdx
int v4; // eax
int *v5; // rax
int *v7; // rax
int *v8; // rax
int v9; // ebx

v0 = 0;
v1 = (char *)&buf;
nll = 0;
memset(&buf, 0, 0x2000uLL);
while ( 1 )
{
v4 = recv(*(int *)&la.sa_data[10], v1, 0x2000LL - v0, 0);
rtn = v4;
if ( v4 < 0 )
{
v5 = _errno_location();
test_msg("ERR: %s:%d: recv failed: %m (errno = %d)\n", "netlink00.c", 161LL, (unsigned int)*v5);
return 0xFFFFFFFFLL;
}
if ( !v4 )
{
v7 = _errno_location();
test_msg("ERR: %s:%d: EOF on netlink\n (errno = %d)\n", "netlink00.c", 166LL, (unsigned int)*v7);
return 0xFFFFFFFFLL;
}
v2 = *((_WORD *)v1 + 2);
nlp = (__int64)v1;
if ( v2 == 3 )
return 0LL;
if ( v2 == 2 )
break;
v3 = v4;
v0 = nll + v4;
nll = v0;
v1 += v3;
if ( (la.sa_data[6] & 0x40) != 0 )
return 0LL;
}
v8 = _errno_location();
v9 = *((_DWORD *)v1 + 4);
*v8 = -v9;
return (unsigned int)-(v9 != 0);
}

canonical_decompiled_code:
__int64 func3()
{
int v0; // eax
char *v1; // rbx
__int16 v2; // dx
__int64 v3; // rdx
int v4; // eax
int *v5; // rax
int *v7; // rax
int *v8; // rax
int v9; // ebx

v0 = 0;
v1 = (char *)&buf;
nll = 0;
memset(&buf, 0, 0x2000uLL);
while ( 1 )
{
v4 = recv(*(int *)&la.sa_data[10], v1, 0x2000LL - v0, 0);
rtn = v4;
if ( v4 < 0 )
{
v5 = _errno_location();
test_msg("ERR: %s:%d: recv failed: %m (errno = %d)\n", "netlink00.c", 161LL, (unsigned int)*v5);
return 0xFFFFFFFFLL;
}
if ( !v4 )
{
v7 = _errno_location();
test_msg("ERR: %s:%d: EOF on netlink\n (errno = %d)\n", "netlink00.c", 166LL, (unsigned int)*v7);
return 0xFFFFFFFFLL;
}
v2 = *((_WORD *)v1 + 2);
nlp = (__int64)v1;
if ( v2 == 3 )
return 0LL;
if ( v2 == 2 )
break;
v3 = v4;
v0 = nll + v4;
nll = v0;
v1 += v3;
if ( (la.sa_data[6] & 0x40) != 0 )
return 0LL;
}
v8 = _errno_location();
v9 = *((_DWORD *)v1 + 4);
*v8 = -v9;
return (unsigned int)-(v9 != 0);
}

original_code:
int recv_reply()
{
 char *p;
 bzero(buf, sizeof(buf));
 p = buf;
 nll = 0;
 while(1) {
  rtn = recv(fd, p, sizeof(buf) - nll, 0);
  if (rtn < 0) {
   test_msg("ERR: %s:%d: " "recv failed: %m" " (errno = %d)\n", "netlink00.c", 161, (*__errno_location ()));
   return -1;
  }
  if (rtn == 0) {
   test_msg("ERR: %s:%d: " "EOF on netlink\n" " (errno = %d)\n", "netlink00.c", 166, (*__errno_location ()));
   return -1;
  }
  nlp = (struct nlmsghdr *) p;
  if(nlp->nlmsg_type == 0x3)
   return 0;
  if (nlp->nlmsg_type == 0x2) {
   struct nlmsgerr *err = (struct nlmsgerr*)((void*)(((char*)nlp) + ((0) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) )))));
   (*__errno_location ())=-err->error;
   if ((*__errno_location ())) {
    return -1;
   }
   return 0;
  }
  p += rtn;
  nll += rtn;
  if((la.nl_groups & 0x40)
    == 0x40)
   break;
 }
 return 0;
}

variable_types:
p
char *

variable_types: struct nlmsgerr { int error; struct nlmsghdr { unsigned int nlmsg_len; unsigned short nlmsg_type; unsigned short nlmsg_flags; unsigned int nlmsg_seq; unsigned int nlmsg_pid; } msg; } *

user_defined_types: struct nlmsgerr { int error; struct nlmsghdr msg; }


decompiled_code:
__int64 read_reply()
{
char *v0; // rax
signed int v1; // edx
__int64 v2; // rcx
bool v3; // zf
unsigned __int16 *v4; // rsi
int v5; // edx
unsigned __int16 v6; // dx
int v7; // eax
__int128 v9; // [rsp+0h] [rbp-78h] BYREF
char v10[16]; // [rsp+10h] [rbp-68h] BYREF
__int64 v11; // [rsp+20h] [rbp-58h]
char buf[16]; // [rsp+30h] [rbp-48h] BYREF
__int64 v13; // [rsp+40h] [rbp-38h]
char s[16]; // [rsp+50h] [rbp-28h] BYREF
__int64 v15; // [rsp+60h] [rbp-18h]

nlp = (__int64)::buf;
if ( nll <= 15 )
return 0LL;
v0 = (char *)::buf;
if ( ::buf[0] <= 0xFu || ::buf[0] > (unsigned int)nll )
return 0LL;
do
{
v2 = (__int64)(v0 + 16);
v3 = v0[20] == -2;
rtp = (__int64)(v0 + 16);
if ( v3 )
{
v4 = (unsigned __int16 *)(v0 + 28);
v11 = 0LL;
v13 = 0LL;
v15 = 0LL;
rtap = (__int64)(v0 + 28);
*(_OWORD *)v10 = 0LL;
*(_OWORD *)buf = 0LL;
v9 = 0LL;
*(_OWORD *)s = 0LL;
v5 = *(_DWORD *)v0 - 28;
rtl = v5;
if ( v5 > 3 )
{
do
{
v7 = *v4;
if ( (unsigned __int16)v7 <= 3u || v7 > v5 )
break;
v6 = v4[1];
switch ( v6 )
{
case 4u:
sprintf((char *)&v9, "%d", *((unsigned int *)v4 + 1));
v4 = (unsigned __int16 *)rtap;
v7 = *(unsigned __int16 *)rtap;
break;
case 5u:
inet_ntop(2, v4 + 2, buf, 0x18u);
v4 = (unsigned __int16 *)rtap;
v7 = *(unsigned __int16 *)rtap;
break;
case 1u:
inet_ntop(2, v4 + 2, v10, 0x18u);
v4 = (unsigned __int16 *)rtap;
v7 = *(unsigned __int16 *)rtap;
break;
}
v5 = rtl - ((v7 + 3) & 0xFFFFFFFC);
rtl = v5;
v4 = (unsigned __int16 *)((char *)v4 + ((*v4 + 3) & 0x1FFFC));
rtap = (__int64)v4;
}
while ( v5 > 3 );
v2 = rtp;
}
sprintf(s, "%d", *(unsigned __int8 *)(v2 + 1));
test_msg("dst %s/%s gw %s if %s\n", v10, s, buf, (const char *)&v9);
v0 = (char *)nlp;
}
v1 = nll - ((*(_DWORD *)v0 + 3) & 0xFFFFFFFC);
nll = v1;
v0 += (*(_DWORD *)v0 + 3) & 0xFFFFFFFC;
nlp = (__int64)v0;
}
while ( v1 > 15 && *(_DWORD *)v0 > 0xFu && *(_DWORD *)v0 <= (unsigned int)v1 );
return 0LL;
}

canonical_decompiled_code:
__int64 func4()
{
char *v0; // rax
signed int v1; // edx
__int64 v2; // rcx
bool v3; // zf
unsigned __int16 *v4; // rsi
int v5; // edx
unsigned __int16 v6; // dx
int v7; // eax
__int128 v9; // [rsp+0h] [rbp-78h] BYREF
char v10[16]; // [rsp+10h] [rbp-68h] BYREF
__int64 v11; // [rsp+20h] [rbp-58h]
char buf[16]; // [rsp+30h] [rbp-48h] BYREF
__int64 v13; // [rsp+40h] [rbp-38h]
char s[16]; // [rsp+50h] [rbp-28h] BYREF
__int64 v15; // [rsp+60h] [rbp-18h]

nlp = (__int64)::buf;
if ( nll <= 15 )
return 0LL;
v0 = (char *)::buf;
if ( ::buf[0] <= 0xFu || ::buf[0] > (unsigned int)nll )
return 0LL;
do
{
v2 = (__int64)(v0 + 16);
v3 = v0[20] == -2;
rtp = (__int64)(v0 + 16);
if ( v3 )
{
v4 = (unsigned __int16 *)(v0 + 28);
v11 = 0LL;
v13 = 0LL;
v15 = 0LL;
rtap = (__int64)(v0 + 28);
*(_OWORD *)v10 = 0LL;
*(_OWORD *)buf = 0LL;
v9 = 0LL;
*(_OWORD *)s = 0LL;
v5 = *(_DWORD *)v0 - 28;
rtl = v5;
if ( v5 > 3 )
{
do
{
v7 = *v4;
if ( (unsigned __int16)v7 <= 3u || v7 > v5 )
break;
v6 = v4[1];
switch ( v6 )
{
case 4u:
sprintf((char *)&v9, "%d", *((unsigned int *)v4 + 1));
v4 = (unsigned __int16 *)rtap;
v7 = *(unsigned __int16 *)rtap;
break;
case 5u:
inet_ntop(2, v4 + 2, buf, 0x18u);
v4 = (unsigned __int16 *)rtap;
v7 = *(unsigned __int16 *)rtap;
break;
case 1u:
inet_ntop(2, v4 + 2, v10, 0x18u);
v4 = (unsigned __int16 *)rtap;
v7 = *(unsigned __int16 *)rtap;
break;
}
v5 = rtl - ((v7 + 3) & 0xFFFFFFFC);
rtl = v5;
v4 = (unsigned __int16 *)((char *)v4 + ((*v4 + 3) & 0x1FFFC));
rtap = (__int64)v4;
}
while ( v5 > 3 );
v2 = rtp;
}
sprintf(s, "%d", *(unsigned __int8 *)(v2 + 1));
test_msg("dst %s/%s gw %s if %s\n", v10, s, buf, (const char *)&v9);
v0 = (char *)nlp;
}
v1 = nll - ((*(_DWORD *)v0 + 3) & 0xFFFFFFFC);
nll = v1;
v0 += (*(_DWORD *)v0 + 3) & 0xFFFFFFFC;
nlp = (__int64)v0;
}
while ( v1 > 15 && *(_DWORD *)v0 > 0xFu && *(_DWORD *)v0 <= (unsigned int)v1 );
return 0LL;
}

original_code:
int read_reply()
{
 char dsts[24], gws[24], ifs[16], ms[24];
 nlp = (struct nlmsghdr *) buf;
 for(; ((nll) >= (int)sizeof(struct nlmsghdr) && (nlp)->nlmsg_len >= sizeof(struct nlmsghdr) && (nlp)->nlmsg_len <= (nll)); nlp = ((nll) -= ( (((nlp)->nlmsg_len)+4U -1) & ~(4U -1) ), (struct nlmsghdr*)(((char*)(nlp)) + ( (((nlp)->nlmsg_len)+4U -1) & ~(4U -1) ))))
 {
  rtp = (struct rtmsg *) ((void*)(((char*)nlp) + ((0) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) )))));
  if(rtp->rtm_table != RT_TABLE_MAIN)
   continue;
  bzero(dsts, sizeof(dsts));
  bzero(gws, sizeof(gws));
  bzero(ifs, sizeof(ifs));
  bzero(ms, sizeof(ms));
  rtap = (struct rtattr *) ((struct rtattr*)(((char*)(rtp)) + ( ((sizeof(struct rtmsg))+4U -1) & ~(4U -1) )));
  rtl = ((nlp)->nlmsg_len - ( (((((sizeof(struct rtmsg))) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) ))))+4U -1) & ~(4U -1) ));
  for( ; ((rtl) >= (int)sizeof(struct rtattr) && (rtap)->rta_len >= sizeof(struct rtattr) && (rtap)->rta_len <= (rtl)); rtap = ((rtl) -= ( (((rtap)->rta_len)+4U -1) & ~(4U -1) ), (struct rtattr*)(((char*)(rtap)) + ( (((rtap)->rta_len)+4U -1) & ~(4U -1) ))))
  {
   switch(rtap->rta_type)
   {
    case RTA_DST:
     inet_ntop(2, ((void*)(((char*)(rtap)) + (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (0)))),
       dsts, 24);
     break;
    case RTA_GATEWAY:
     inet_ntop(2, ((void*)(((char*)(rtap)) + (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (0)))),
       gws, 24);
     break;
    case RTA_OIF:
     sprintf(ifs, "%d",
       *((int *) ((void*)(((char*)(rtap)) + (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (0))))));
    default:
     break;
   }
  }
  sprintf(ms, "%d", rtp->rtm_dst_len);
  test_msg("dst %s/%s gw %s if %s\n",
    dsts, ms, gws, ifs);
 }
 return 0;
}

canonical_original_code:
int read_reply()
{
 char dsts[24]; char gws[24]; char ifs[16]; char ms[24];
 nlp = (struct nlmsghdr *) buf;
 for(; ((nll) >= (int)sizeof(struct nlmsghdr) && (nlp)->nlmsg_len >= sizeof(struct nlmsghdr) && (nlp)->nlmsg_len <= (nll)); nlp = ((nll) -= ( (((nlp)->nlmsg_len)+4U -1) & ~(4U -1) ), (struct nlmsghdr *)(((char *)(nlp)) + ( (((nlp)->nlmsg_len)+4U -1) & ~(4U -1) ))))
 {
  rtp = (struct rtmsg *) ((void *)(((char *)nlp) + ((0) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) )))));
  if(rtp->rtm_table != RT_TABLE_MAIN)
   continue;
  bzero(dsts, sizeof(dsts));
  bzero(gws, sizeof(gws));
  bzero(ifs, sizeof(ifs));
  bzero(ms, sizeof(ms));
  rtap = (struct rtattr *) ((struct rtattr *)(((char *)(rtp)) + ( ((sizeof(struct rtmsg))+4U -1) & ~(4U -1) )));
  rtl = ((nlp)->nlmsg_len - ( (((((sizeof(struct rtmsg))) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) ))))+4U -1) & ~(4U -1) ));
  for( ; ((rtl) >= (int)sizeof(struct rtattr) && (rtap)->rta_len >= sizeof(struct rtattr) && (rtap)->rta_len <= (rtl)); rtap = ((rtl) -= ( (((rtap)->rta_len)+4U -1) & ~(4U -1) ), (struct rtattr *)(((char *)(rtap)) + ( (((rtap)->rta_len)+4U -1) & ~(4U -1) ))))
  {
   switch(rtap->rta_type)
   {
    case RTA_DST:
     inet_ntop(2, ((void *)(((char *)(rtap)) + (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (0)))),
       dsts, 24);
     break;
    case RTA_GATEWAY:
     inet_ntop(2, ((void *)(((char *)(rtap)) + (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (0)))),
       gws, 24);
     break;
    case RTA_OIF:
     sprintf(ifs, "%d",
       *((int *) ((void *)(((char *)(rtap)) + (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (0))))));
    default:
     break;
   }
  }
  sprintf(ms, "%d", rtp->rtm_dst_len);
  test_msg("dst %s/%s gw %s if %s\n",
    dsts, ms, gws, ifs);
 }
 return 0;
}

variable_types:
dsts
char [24]

variable_types:
gws
char [24]

variable_types:
ifs
char [16]

variable_types:
ms
char [24]


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__pid_t v3; // eax
int v4; // edi
int *v5; // rax
int *v7; // rax
int *v8; // rax
int *v9; // rax

test_init(argc, argv, envp);
*(_DWORD *)&la.sa_data[10] = socket(16, 3, 0);
if ( *(int *)&la.sa_data[10] < 0 )
{
v7 = _errno_location();
test_msg("ERR: %s:%d: socket: %m (errno = %d)\n", "netlink00.c", 77LL, (unsigned int)*v7);
}
else
{
*(_QWORD *)&la.sa_family = 0LL;
*(_DWORD *)&la.sa_data[6] = 0;
la.sa_family = 16;
v3 = getpid();
v4 = *(_DWORD *)&la.sa_data[10];
*(_DWORD *)&la.sa_data[2] = v3;
if ( bind(v4, &la, 0xCu) )
{
v5 = _errno_location();
test_msg("ERR: %s:%d: bind failed: %m (errno = %d)\n", "netlink00.c", 86LL, (unsigned int)*v5);
}
else
{
form_request_del();
send_request();
recv_reply();
test_daemon();
do
{
if ( !(unsigned int)test_go() )
{
test_msg("PASS\n");
return 0;
}
cmd();
if ( (int)send_request() >= 0 )
{
if ( (int)recv_reply() < 0 )
break;
(*(&cmd + 1))();
if ( (int)send_request() >= 0 )
continue;
}
v8 = _errno_location();
test_msg("FAIL: %s:%d: send_request failed (errno = %d)\n", "netlink00.c", 100LL, (unsigned int)*v8);
return 0;
}
while ( (int)recv_reply() >= 0 );
v9 = _errno_location();
test_msg("FAIL: %s:%d: RTNETLINK answers: %m (errno = %d)\n", "netlink00.c", 104LL, (unsigned int)*v9);
}
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__pid_t v3; // eax
int v4; // edi
int *v5; // rax
int *v7; // rax
int *v8; // rax
int *v9; // rax

test_init(argc, argv, envp);
*(_DWORD *)&la.sa_data[10] = socket(16, 3, 0);
if ( *(int *)&la.sa_data[10] < 0 )
{
v7 = _errno_location();
test_msg("ERR: %s:%d: socket: %m (errno = %d)\n", "netlink00.c", 77LL, (unsigned int)*v7);
}
else
{
*(_QWORD *)&la.sa_family = 0LL;
*(_DWORD *)&la.sa_data[6] = 0;
la.sa_family = 16;
v3 = getpid();
v4 = *(_DWORD *)&la.sa_data[10];
*(_DWORD *)&la.sa_data[2] = v3;
if ( bind(v4, &la, 0xCu) )
{
v5 = _errno_location();
test_msg("ERR: %s:%d: bind failed: %m (errno = %d)\n", "netlink00.c", 86LL, (unsigned int)*v5);
}
else
{
func0();
func2();
func3();
test_daemon();
do
{
if ( !(unsigned int)test_go() )
{
test_msg("PASS\n");
return 0;
}
cmd();
if ( (int)func2() >= 0 )
{
if ( (int)func3() < 0 )
break;
(*(&cmd + 1))();
if ( (int)func2() >= 0 )
continue;
}
v8 = _errno_location();
test_msg("FAIL: %s:%d: send_request failed (errno = %d)\n", "netlink00.c", 100LL, (unsigned int)*v8);
return 0;
}
while ( (int)func3() >= 0 );
v9 = _errno_location();
test_msg("FAIL: %s:%d: RTNETLINK answers: %m (errno = %d)\n", "netlink00.c", 104LL, (unsigned int)*v9);
}
}
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 int i;
 test_init(argc, argv);
 fd = socket(16, SOCK_RAW, 0);
 if (fd<0){
  test_msg("ERR: %s:%d: " "socket: %m " " (errno = %d)\n", "netlink00.c", 77, (*__errno_location ()));
  goto out;
 }
 bzero(&la, sizeof(la));
 la.nl_family = 16;
 la.nl_pid = getpid();
 if (bind(fd, (struct sockaddr*) &la, sizeof(la))){
  test_msg("ERR: %s:%d: " "bind failed: %m " " (errno = %d)\n", "netlink00.c", 86, (*__errno_location ()));
  goto out;
 }
 form_request_del();
 send_request();
 recv_reply();
 test_daemon();
 while (test_go()){
  for (i=0; i < 2; i++){
   cmd[i]();
   if (send_request() < 0){
    test_msg("FAIL: %s:%d: " "send_request failed" " (errno = %d)\n", "netlink00.c", 100, (*__errno_location ()));
    goto out;
   };
   if (recv_reply() < 0){
    test_msg("FAIL: %s:%d: " "RTNETLINK answers: %m" " (errno = %d)\n", "netlink00.c", 104, (*__errno_location ()));
    goto out;
   };
  }
 }
 test_msg("PASS\n");
out:
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int i;
 test_init(argc, argv);
 fd = socket(16, SOCK_RAW, 0);
 if (fd<0){
  test_msg("ERR: %s:%d: " "socket: %m " " (errno = %d)\n", "netlink00.c", 77, (*__errno_location ()));
  goto out;
 }
 bzero(&la, sizeof(la));
 la.nl_family = 16;
 la.nl_pid = getpid();
 if (bind(fd, (struct sockaddr *) &la, sizeof(la))){
  test_msg("ERR: %s:%d: " "bind failed: %m " " (errno = %d)\n", "netlink00.c", 86, (*__errno_location ()));
  goto out;
 }
 form_request_del();
 send_request();
 recv_reply();
 test_daemon();
 while (test_go()){
  for (i=0; i < 2; i++){
   cmd[i]();
   if (send_request() < 0){
    test_msg("FAIL: %s:%d: " "send_request failed" " (errno = %d)\n", "netlink00.c", 100, (*__errno_location ()));
    goto out;
   };
   if (recv_reply() < 0){
    test_msg("FAIL: %s:%d: " "RTNETLINK answers: %m" " (errno = %d)\n", "netlink00.c", 104, (*__errno_location ()));
    goto out;
   };
  }
 }
 test_msg("PASS\n");
out:
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: i int


decompiled_code:
void sighup_handler()
{
test_msg("SIGHUP is here\n");
sighup = 1;
}

canonical_decompiled_code:
void func0()
{
test_msg("SIGHUP is here\n");
sighup = 1;
}

original_code:
static void sighup_handler(int signo)
{
 test_msg("SIGHUP is here\n");
 sighup = 1;
}

variable_types: signo int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebp
signed int v5; // ebx
int v6; // eax
__pid_t v7; // er12
int v8; // er13
int result; // eax
unsigned int v10; // er12
unsigned int v11; // ebx
int *v12; // rax
int *v13; // rax
int *v14; // rax
int *v15; // rax
int *v16; // rax
int *v17; // rax
int *v18; // rax
int stat_loc; // [rsp+Ch] [rbp-2Ch] BYREF

test_init(argc, argv, envp);
v3 = open("/dev/ptmx", 2);
if ( v3 == -1 )
{
v13 = _errno_location();
test_msg("ERR: %s:%d: Can't open a master pseudoterminal (errno = %d)\n", "tty00.c", 33LL, (unsigned int)*v13);
return 1;
}
v4 = v3;
grantpt(v3);
unlockpt(v4);
v5 = (unsigned int)ptsname(v4);
v6 = test_fork_id(0xFFFFFFFFLL);
v7 = v6;
if ( v6 < 0 )
{
v14 = _errno_location();
test_msg("ERR: %s:%d: fork() failed (errno = %d)\n", "tty00.c", 43LL, (unsigned int)*v14);
return 1;
}
if ( v6 )
{
test_daemon();
test_waitsig();
close(v4);
if ( kill(v7, 15) == -1 )
{
v12 = _errno_location();
test_msg("ERR: %s:%d: kill failed (errno = %d)\n", "tty00.c", 81LL, (unsigned int)*v12);
}
else if ( waitpid(v7, &stat_loc, 0) >= 0 )
{
v10 = stat_loc & 0x7F;
if ( (stat_loc & 0x7F) != 0 )
{
v15 = _errno_location();
test_msg("ERR: %s:%d: The child has been killed by %d (errno = %d)\n", "tty00.c", 95LL, v10, (unsigned int)*v15);
}
else
{
v11 = BYTE1(stat_loc);
if ( BYTE1(stat_loc) )
{
v18 = _errno_location();
test_msg("FAIL: %s:%d: The child returned %d (errno = %d)\n", "tty00.c", 91LL, v11, (unsigned int)*v18);
return 1;
}
}
test_msg("PASS\n");
return 0;
}
return 1;
}
close(v4);
_sysv_signal(1, (__sighandler_t)sighup_handler);
if ( setsid() == -1 )
return 1;
v8 = open((const char *)v5, 2);
if ( v8 == -1 )
{
v16 = _errno_location();
test_msg(
"ERR: %s:%d: Can't open a slave pseudoterminal %s (errno = %d)\n",
"tty00.c",
57LL,
(const char *)v5,
(unsigned int)*v16);
result = 1;
}
else if ( ioctl(v4, 0x540EuLL, 1LL) < 0 )
{
v17 = _errno_location();
test_msg("ERR: %s:%d: Can't setup a controlling terminal (errno = %d)\n", "tty00.c", 62LL, (unsigned int)*v17);
result = 1;
}
else
{
close(v8);
test_waitsig();
result = sighup == 0;
}
return result;
}

original_code:
int main(int argc, char ** argv)
{
 int fdm, fds, status;
 char *slavename;
 pid_t pid;
 test_init(argc, argv);
 fdm = open("/dev/ptmx", 02);
 if (fdm == -1) {
  test_msg("ERR: %s:%d: " "Can't open a master pseudoterminal" " (errno = %d)\n", "tty00.c", 33, (*__errno_location ()));
  return 1;
 }
 grantpt(fdm);
 unlockpt(fdm);
 slavename = ptsname(fdm);
 pid = test_fork_id(-1);
 if (pid < 0) {
  test_msg("ERR: %s:%d: " "fork() failed" " (errno = %d)\n", "tty00.c", 43, (*__errno_location ()));
  return 1;
 }
 if (pid == 0) {
  close(fdm);
  signal(1, sighup_handler);
  if (setsid() == -1)
   return 1;
  fds = open(slavename, 02);
  if (fds == -1) {
   test_msg("ERR: %s:%d: " "Can't open a slave pseudoterminal %s" " (errno = %d)\n", "tty00.c", 57, slavename, (*__errno_location ()));
   return 1;
  }
  if (ioctl(fdm, 0x540E, 1) < 0) {
   test_msg("ERR: %s:%d: " "Can't setup a controlling terminal" " (errno = %d)\n", "tty00.c", 62, (*__errno_location ()));
   return 1;
  }
  close(fds);
  test_waitsig();
  if (sighup)
   return 0;
  return 1;
 }
 test_daemon();
 test_waitsig();
 close(fdm);
 if (kill(pid, 15) == -1) {
  test_msg("ERR: %s:%d: " "kill failed" " (errno = %d)\n", "tty00.c", 81, (*__errno_location ()));
  return 1;
 }
 pid = waitpid(pid, &status, 0);
 if (pid < 0)
  return 1;
 if ((((status) & 0x7f) == 0)) {
  if ((((status) & 0xff00) >> 8)) {
   test_msg("FAIL: %s:%d: " "The child returned %d" " (errno = %d)\n", "tty00.c", 91, (((status) & 0xff00) >> 8), (*__errno_location ()));
   return 1;
  }
 } else
  test_msg("ERR: %s:%d: " "The child has been killed by %d" " (errno = %d)\n", "tty00.c", 95, ((status) & 0x7f), (*__errno_location ()));
 test_msg("PASS\n");
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int fdm; int fds; int status;
 char *slavename;
 int pid;
 test_init(argc, argv);
 fdm = open("/dev/ptmx", 02);
 if (fdm == -1) {
  test_msg("ERR: %s:%d: " "Can't open a master pseudoterminal" " (errno = %d)\n", "tty00.c", 33, (*__errno_location ()));
  return 1;
 }
 grantpt(fdm);
 unlockpt(fdm);
 slavename = ptsname(fdm);
 pid = test_fork_id(-1);
 if (pid < 0) {
  test_msg("ERR: %s:%d: " "fork() failed" " (errno = %d)\n", "tty00.c", 43, (*__errno_location ()));
  return 1;
 }
 if (pid == 0) {
  close(fdm);
  signal(1, sighup_handler);
  if (setsid() == -1)
   return 1;
  fds = open(slavename, 02);
  if (fds == -1) {
   test_msg("ERR: %s:%d: " "Can't open a slave pseudoterminal %s" " (errno = %d)\n", "tty00.c", 57, slavename, (*__errno_location ()));
   return 1;
  }
  if (ioctl(fdm, 0x540E, 1) < 0) {
   test_msg("ERR: %s:%d: " "Can't setup a controlling terminal" " (errno = %d)\n", "tty00.c", 62, (*__errno_location ()));
   return 1;
  }
  close(fds);
  test_waitsig();
  if (sighup)
   return 0;
  return 1;
 }
 test_daemon();
 test_waitsig();
 close(fdm);
 if (kill(pid, 15) == -1) {
  test_msg("ERR: %s:%d: " "kill failed" " (errno = %d)\n", "tty00.c", 81, (*__errno_location ()));
  return 1;
 }
 pid = waitpid(pid, &status, 0);
 if (pid < 0)
  return 1;
 if ((((status) & 0x7f) == 0)) {
  if ((((status) & 0xff00) >> 8)) {
   test_msg("FAIL: %s:%d: " "The child returned %d" " (errno = %d)\n", "tty00.c", 91, (((status) & 0xff00) >> 8), (*__errno_location ()));
   return 1;
  }
 } else
  test_msg("ERR: %s:%d: " "The child has been killed by %d" " (errno = %d)\n", "tty00.c", 95, ((status) & 0x7f), (*__errno_location ()));
 test_msg("PASS\n");
 return 0;
}

variable_types:
argv
char **

variable_types: fdm int

variable_types: fds int

variable_types: status int

variable_types:
slavename
char *

variable_types: pid int


decompiled_code:
__int64 test_func()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 1LL;
}

original_code:
int test_func()
{
 return 1;
}

canonical_original_code:
int test_func()
{
 return 1;
}


decompiled_code:
__int64 __fastcall make_map(__int64 a1)
{
int v2; // ecx
__int64 v3; // r8
const char *v4; // r12
int v5; // eax
void *v6; // rax
void *v7; // rdi
__int64 result; // rax
int *v9; // rax
int *v10; // rax
int *v11; // rax
int *v12; // rax
int v13; // [rsp+Ch] [rbp-201Ch] BYREF
char buf[8216]; // [rsp+10h] [rbp-2018h] BYREF

v2 = *(_DWORD *)(a1 + 8);
if ( (v2 & 0x20) == 0 )
{
v3 = (unsigned int)i_0;
v4 = (const char *)(a1 + 12);
++i_0;
if ( (unsigned int)snprintf((char *)(a1 + 12), 0x100uLL, "%s-%02d", (const char *)filename, v3) > 0xFF )
{
v9 = _errno_location();
test_msg(
"ERR: %s:%d: filename %s is too long\n (errno = %d)\n",
"maps00.c",
80LL,
(const char *)filename,
(unsigned int)*v9);
return 0xFFFFFFFFLL;
}
v5 = open(v4, 66, 384LL);
*(_DWORD *)(a1 + 268) = v5;
if ( v5 < 0 )
{
v11 = _errno_location();
test_msg("ERR: %s:%d: can't open %s: %m\n (errno = %d)\n", "maps00.c", 86LL, v4, (unsigned int)*v11);
return 0xFFFFFFFFLL;
}
v13 = -1;
datagen(buf, 0x2000LL, &v13);
if ( write(*(_DWORD *)(a1 + 268), buf, 0x2000uLL) != 0x2000 )
{
v10 = _errno_location();
test_msg("ERR: %s:%d: failed to write %s: %m\n (errno = %d)\n", "maps00.c", 93LL, v4, (unsigned int)*v10);
return 0xFFFFFFFFLL;
}
v2 = *(_DWORD *)(a1 + 8);
}
v6 = mmap(0LL, 0x2000uLL, *(_DWORD *)a1, v2, *(_DWORD *)(a1 + 268), 0LL);
*(_QWORD *)(a1 + 272) = v6;
v7 = v6;
if ( v6 == (void *)-1LL )
{
v12 = _errno_location();
test_msg("ERR: %s:%d: can't create mapping: %m\n (errno = %d)\n", "maps00.c", 100LL, (unsigned int)*v12);
result = 0xFFFFFFFFLL;
}
else
{
result = *(_DWORD *)(a1 + 8) & 0x20;
if ( (*(_DWORD *)(a1 + 8) & 0x20) != 0 )
{
result = *(_DWORD *)a1 & 2;
if ( (*(_DWORD *)a1 & 2) != 0 )
{
v13 = -1;
datagen(v7, 0x2000LL, &v13);
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
int v2; // ecx
__int64 v3; // r8
const char *v4; // r12
int v5; // eax
void *v6; // rax
void *v7; // rdi
__int64 result; // rax
int *v9; // rax
int *v10; // rax
int *v11; // rax
int *v12; // rax
int v13; // [rsp+Ch] [rbp-201Ch] BYREF
char buf[8216]; // [rsp+10h] [rbp-2018h] BYREF

v2 = *(_DWORD *)(a1 + 8);
if ( (v2 & 0x20) == 0 )
{
v3 = (unsigned int)i_0;
v4 = (const char *)(a1 + 12);
++i_0;
if ( (unsigned int)snprintf((char *)(a1 + 12), 0x100uLL, "%s-%02d", (const char *)filename, v3) > 0xFF )
{
v9 = _errno_location();
test_msg(
"ERR: %s:%d: filename %s is too long\n (errno = %d)\n",
"maps00.c",
80LL,
(const char *)filename,
(unsigned int)*v9);
return 0xFFFFFFFFLL;
}
v5 = open(v4, 66, 384LL);
*(_DWORD *)(a1 + 268) = v5;
if ( v5 < 0 )
{
v11 = _errno_location();
test_msg("ERR: %s:%d: can't open %s: %m\n (errno = %d)\n", "maps00.c", 86LL, v4, (unsigned int)*v11);
return 0xFFFFFFFFLL;
}
v13 = -1;
datagen(buf, 0x2000LL, &v13);
if ( write(*(_DWORD *)(a1 + 268), buf, 0x2000uLL) != 0x2000 )
{
v10 = _errno_location();
test_msg("ERR: %s:%d: failed to write %s: %m\n (errno = %d)\n", "maps00.c", 93LL, v4, (unsigned int)*v10);
return 0xFFFFFFFFLL;
}
v2 = *(_DWORD *)(a1 + 8);
}
v6 = mmap(0LL, 0x2000uLL, *(_DWORD *)a1, v2, *(_DWORD *)(a1 + 268), 0LL);
*(_QWORD *)(a1 + 272) = v6;
v7 = v6;
if ( v6 == (void *)-1LL )
{
v12 = _errno_location();
test_msg("ERR: %s:%d: can't create mapping: %m\n (errno = %d)\n", "maps00.c", 100LL, (unsigned int)*v12);
result = 0xFFFFFFFFLL;
}
else
{
result = *(_DWORD *)(a1 + 8) & 0x20;
if ( (*(_DWORD *)(a1 + 8) & 0x20) != 0 )
{
result = *(_DWORD *)a1 & 2;
if ( (*(_DWORD *)a1 & 2) != 0 )
{
v13 = -1;
datagen(v7, 0x2000LL, &v13);
result = 0LL;
}
}
}
return result;
}

original_code:
static int make_map(struct map *map)
{
 uint32_t crc;
 uint8_t buf[0x2000];
 static int i = 0;
 if (!(map->flag & 0x20)) {
  if (snprintf(map->filename, sizeof(map->filename),
      "%s-%02d", filename, i++) >= sizeof(map->filename)) {
   test_msg("ERR: %s:%d: " "filename %s is too long\n" " (errno = %d)\n", "maps00.c", 80, filename, (*__errno_location ()));
   return -1;
  }
  map->fd = open(map->filename, 02 | 0100, 0600);
  if (map->fd < 0) {
   test_msg("ERR: %s:%d: " "can't open %s: %m\n" " (errno = %d)\n", "maps00.c", 86, map->filename, (*__errno_location ()));
   return -1;
  }
  crc = ~0;
  datagen(buf, sizeof(buf), &crc);
  if (write(map->fd, buf, sizeof(buf)) != sizeof(buf)) {
   test_msg("ERR: %s:%d: " "failed to write %s: %m\n" " (errno = %d)\n", "maps00.c", 93, map->filename, (*__errno_location ()));
   return -1;
  }
 }
 map->ptr = mmap(((void *)0), 0x2000, map->prot, map->flag, map->fd, 0);
 if (map->ptr == ((void *) -1)) {
  test_msg("ERR: %s:%d: " "can't create mapping: %m\n" " (errno = %d)\n", "maps00.c", 100, (*__errno_location ()));
  return -1;
 }
 if ((map->flag & 0x20) && (map->prot & 0x2)) {
  crc = ~0;
  datagen(map->ptr, 0x2000, &crc);
 }
 return 0;
}

canonical_original_code:
static int make_map(struct map *map)
{
 unsigned int crc;
 unsigned char buf[8192];
 static int i = 0;
 if (!(map->flag & 0x20)) {
  if (snprintf(map->filename, sizeof(map->filename),
      "%s-%02d", filename, i++) >= sizeof(map->filename)) {
   test_msg("ERR: %s:%d: " "filename %s is too long\n" " (errno = %d)\n", "maps00.c", 80, filename, (*__errno_location ()));
   return -1;
  }
  map->fd = open(map->filename, 02 | 0100, 0600);
  if (map->fd < 0) {
   test_msg("ERR: %s:%d: " "can't open %s: %m\n" " (errno = %d)\n", "maps00.c", 86, map->filename, (*__errno_location ()));
   return -1;
  }
  crc = ~0;
  datagen(buf, sizeof(buf), &crc);
  if (write(map->fd, buf, sizeof(buf)) != sizeof(buf)) {
   test_msg("ERR: %s:%d: " "failed to write %s: %m\n" " (errno = %d)\n", "maps00.c", 93, map->filename, (*__errno_location ()));
   return -1;
  }
 }
 map->ptr = mmap(((void *)0), 0x2000, map->prot, map->flag, map->fd, 0);
 if (map->ptr == ((void *) -1)) {
  test_msg("ERR: %s:%d: " "can't create mapping: %m\n" " (errno = %d)\n", "maps00.c", 100, (*__errno_location ()));
  return -1;
 }
 if ((map->flag & 0x20) && (map->prot & 0x2)) {
  crc = ~0;
  datagen(map->ptr, 0x2000, &crc);
 }
 return 0;
}

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

variable_types:
crc
unsigned int

variable_types:
buf
unsigned char [8192]