#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ PR_SET_PDEATHSIG;
int /*<<< orphan*/ SIGKILL;
int /*<<< orphan*/ SIGTERM;
int /*<<< orphan*/ errmsgf(char *, ...);
int execvp(char const *, char **);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getpid();
int getppid();
int parent_main(int);
int prctl(int /*<<< orphan*/, int /*<<< orphan*/);
int set_affinities(int, long);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
long strtol(char *, char **, int);
int main(int argc, char **argv) {
  if (argc < 2) {
    fprintf(stderr, "Usage: safeexec [OPTIONS] COMMAND [COMMAND_ARG...]\n");
    fprintf(stderr, "Options\n");
    fprintf(stderr, "  --cpu CPU_MASK : Run process on the set of CPUs be "
                    "eligible to run.\n");
    fprintf(stderr, "                   CPU_MASK determines the set of CPUs be "
                    "eligible to run and is specified by hex(e.g. 0x01).\n");
    return 1;
  }
  {
    long cpuids = -1;
    argc--;
    argv++;
    while (argc > 1) {
      if (strcmp(argv[0], "--cpu") == 0) {
        if (argc < 2) {
          {
            errmsgf("--cpu option needs CPU_MASK");
            exit(1);
          };
        }
        char *endptr = NULL;
        cpuids = strtol(argv[1], &endptr, 16);
        if (*endptr != '\0') {
          fprintf(stderr, "CPU_MASK must be specified by hex(e.g. 0x01)\n");
          return 1;
        }
        argc -= 2;
        argv += 2;
      } else {
        break;
      }
    }
    if (argc < 1) {
      {
        errmsgf("COMMAND path is not found");
        exit(1);
      };
    }
    const char *command_path = argv[0];
    char **command_args = &argv[0];
    int ret;
    int ppid = getpid();
    ret = fork();
    if (ret == -1) {
      {
        errmsgf("fork() failed");
        exit(1);
      };
    }
    if (ret > 0) {
      if (prctl(PR_SET_PDEATHSIG, SIGTERM) == -1) {
        {
          errmsgf("parent prctl() failed");
          exit(1);
        };
      }
      return parent_main(ret);
    } else {
      if (prctl(PR_SET_PDEATHSIG, SIGKILL) == -1) {
        {
          errmsgf("child prctl() failed");
          exit(1);
        };
      }
      if (ppid != getppid()) {
        {
          errmsgf("parent process(%d) has been dead", ppid);
          exit(1);
        };
      }
      if (set_affinities(getpid(), cpuids) == -1) {
        {
          errmsgf("set_affinity() failed");
          exit(1);
        };
      }
      if (execvp(command_path, command_args) == -1) {
        {
          errmsgf("execvp() failed [command = %s]", command_path);
          exit(1);
        };
      };
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1240 <main+0x80>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
lea    0xe10(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
lea    0xe2f(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
lea    0xe23(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
lea    0xe55(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14b8 <main+0x2f8>
movq   $0xffffffffffffffff,-0x18(%rbp)
ff
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    131d <main+0x15d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe7e(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1313 <main+0x153>
cmpl   $0x2,-0x8(%rbp)
jge    12a6 <main+0xe6>
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   10c0 <errmsgf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x10,%edx
call   1060 <strtol@plt>
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     12f9 <main+0x139>
mov    0x2cf1(%rip),%rax
mov    (%rax),%edi
lea    0xe2d(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14b8 <main+0x2f8>
mov    -0x8(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x10(%rbp)
jmp    1318 <main+0x158>
jmp    131d <main+0x15d>
jmp    125d <main+0x9d>
cmpl   $0x1,-0x8(%rbp)
jge    133f <main+0x17f>
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   10c0 <errmsgf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x38(%rbp)
mov    $0x0,%al
call   10e0 <fork@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
jne    1388 <main+0x1c8>
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   10c0 <errmsgf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
cmpl   $0x0,-0x34(%rbp)
jle    13da <main+0x21a>
mov    0x2c3f(%rip),%rax
mov    (%rax),%edi
mov    0x2c46(%rip),%rax
mov    (%rax),%esi
call   1070 <prctl@plt>
cmp    $0xffffffff,%eax
jne    13ca <main+0x20a>
lea    0xdb2(%rip),%rdi
mov    $0x0,%al
call   10c0 <errmsgf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x34(%rbp),%edi
call   1080 <parent_main@plt>
mov    %eax,-0x4(%rbp)
jmp    14b8 <main+0x2f8>
mov    0x2bf7(%rip),%rax
mov    (%rax),%edi
mov    0x2bde(%rip),%rax
mov    (%rax),%esi
call   1070 <prctl@plt>
cmp    $0xffffffff,%eax
jne    1412 <main+0x252>
lea    0xd80(%rip),%rdi
mov    $0x0,%al
call   10c0 <errmsgf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    $0x0,%al
call   10a0 <getppid@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
cmp    %ecx,%eax
je     1447 <main+0x287>
mov    -0x38(%rbp),%esi
lea    0xd60(%rip),%rdi
mov    $0x0,%al
call   10c0 <errmsgf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%edi
mov    -0x18(%rbp),%rsi
call   10d0 <set_affinities@plt>
cmp    $0xffffffff,%eax
jne    147a <main+0x2ba>
lea    0xd4e(%rip),%rdi
mov    $0x0,%al
call   10c0 <errmsgf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1090 <execvp@plt>
cmp    $0xffffffff,%eax
jne    14ac <main+0x2ec>
mov    -0x28(%rbp),%rsi
lea    0xd32(%rip),%rdi
mov    $0x0,%al
call   10c0 <errmsgf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    14b1 <main+0x2f1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x1,%edi
jg     1219 <main+0x59>
mov    0x2df9(%rip),%rbx
mov    (%rbx),%edi
lea    0xe20(%rip),%rsi
call   1050 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe46(%rip),%rsi
call   1050 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe41(%rip),%rsi
call   1050 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe7a(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%ebx
jmp    12f5 <main+0x135>
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0x8(%rsi),%r12
mov    $0xffffffffffffffff,%r14
cmp    $0x2,%edi
je     1247 <main+0x87>
mov    (%r12),%rdi
lea    0xeba(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1306 <main+0x146>
mov    (%r12),%r15
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   10e0 <fork@plt>
cmp    $0xffffffff,%eax
je     138f <main+0x1cf>
mov    %eax,%ebp
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
test   %ebp,%ebp
jle    129f <main+0xdf>
mov    0x2d6e(%rip),%rax
mov    (%rax),%esi
call   1070 <prctl@plt>
cmp    $0xffffffff,%eax
je     1398 <main+0x1d8>
mov    %ebp,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <parent_main@plt>
mov    0x2d22(%rip),%rax
mov    (%rax),%esi
call   1070 <prctl@plt>
cmp    $0xffffffff,%eax
je     13a1 <main+0x1e1>
xor    %eax,%eax
call   10a0 <getppid@plt>
cmp    %eax,%ebx
jne    13aa <main+0x1ea>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%edi
mov    %r14,%rsi
call   10d0 <set_affinities@plt>
cmp    $0xffffffff,%eax
je     13c4 <main+0x204>
mov    %r15,%rdi
mov    %r12,%rsi
call   1090 <execvp@plt>
cmp    $0xffffffff,%eax
je     13dc <main+0x21c>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
add    $0xffffffff,%ebp
add    $0x18,%rbx
mov    %rsp,%r15
lea    0xddc(%rip),%r13
nopw   0x0(%rax,%rax,1)
mov    %rbx,%r12
movq   $0x0,(%rsp)
mov    -0x8(%rbx),%rdi
mov    %r15,%rsi
mov    $0x10,%edx
call   1060 <strtol@plt>
mov    %rax,%r14
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
jne    136b <main+0x1ab>
cmp    $0x3,%ebp
jle    1380 <main+0x1c0>
mov    (%r12),%rdi
mov    %r13,%rsi
call   1040 <strcmp@plt>
lea    0x10(%r12),%rbx
add    $0xfffffffe,%ebp
test   %rax,%rax
je     1320 <main+0x160>
jmp    1247 <main+0x87>
mov    0x2c5e(%rip),%rax
mov    (%rax),%edi
lea    0xd7e(%rip),%rsi
jmp    120a <main+0x4a>
je     1247 <main+0x87>
lea    0xd9a(%rip),%rdi
jmp    13cb <main+0x20b>
lea    0xdab(%rip),%rdi
jmp    13cb <main+0x20b>
lea    0xdb0(%rip),%rdi
jmp    13cb <main+0x20b>
lea    0xdbd(%rip),%rdi
jmp    13cb <main+0x20b>
lea    0xdc9(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   10c0 <errmsgf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xdd0(%rip),%rdi
xor    %eax,%eax
call   10c0 <errmsgf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xdce(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   10c0 <errmsgf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [52 x i8] c"Usage: safeexec [OPTIONS] COMMAND [COMMAND_ARG...]\0A\00"
@.str.1 = [9 x i8] c"Options\0A\00"
@.str.2 = [71 x i8] c" --cpu CPU_MASK : Run process on the set of CPUs be eligible to run.\0A\00"
@.str.3 = [111 x i8] c" CPU_MASK determines the set of CPUs be eligible to run and is specified by hex(e.g. 0x01).\0A\00"
@.str.4 = [6 x i8] c"--cpu\00"
@.str.5 = [28 x i8] c"--cpu option needs CPU_MASK\00"
@.str.6 = [46 x i8] c"CPU_MASK must be specified by hex(e.g. 0x01)\0A\00"
@.str.7 = [26 x i8] c"COMMAND path is not found\00"
@.str.8 = [14 x i8] c"fork() failed\00"
@PR_SET_PDEATHSIG = global i32 0
@SIGTERM = global i32 0
@.str.9 = [22 x i8] c"parent prctl() failed\00"
@SIGKILL = global i32 0
@.str.10 = [21 x i8] c"child prctl() failed\00"
@.str.11 = [33 x i8] c"parent process(%d) has been dead\00"
@.str.12 = [22 x i8] c"set_affinity() failed\00"
@.str.13 = [31 x i8] c"execvp() failed [command = %s]\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8**
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %23
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.2, i64 0, i64 0))
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([111 x i8], [111 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %130
23: ; preds = %2
store i64 -1, i64* %6
%24 = load i32, i32* %4
%25 = add nsw i32 %24, -1
store i32 %25, i32* %4
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i32 1
store i8** %27, i8*** %5
br label %28
28: ; preds = %61, %23
%29 = load i32, i32* %4
%30 = icmp sgt i32 %29, 1
br i1 %30, label %31, label %62
31: ; preds = %28
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 0
%34 = load i8*, i8** %33
%35 = call i64 @strcmp(i8* %34, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %60
37: ; preds = %31
%38 = load i32, i32* %4
%39 = icmp slt i32 %38, 2
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = call i32 (i8*, ...) @errmsgf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %37
store i8* null, i8** %7
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 1
%46 = load i8*, i8** %45
%47 = call i64 @strtol(i8* %46, i8** %7, i32 16)
store i64 %47, i64* %6
%48 = load i8*, i8** %7
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %43
%53 = load i32, i32* @stderr
%54 = call i32 @fprintf(i32 %53, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %3
br label %130
55: ; preds = %43
%56 = load i32, i32* %4
%57 = sub nsw i32 %56, 2
store i32 %57, i32* %4
%58 = load i8**, i8*** %5
%59 = getelementptr inbounds i8*, i8** %58, i64 2
store i8** %59, i8*** %5
br label %61
60: ; preds = %31
br label %62
61: ; preds = %55
br label %28
62: ; preds = %60, %28
%63 = load i32, i32* %4
%64 = icmp slt i32 %63, 1
br i1 %64, label %65, label %68
65: ; preds = %62
%66 = call i32 (i8*, ...) @errmsgf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0))
%67 = call i32 @exit(i32 1)
unreachable
68: ; preds = %62
%69 = load i8**, i8*** %5
%70 = getelementptr inbounds i8*, i8** %69, i64 0
%71 = load i8*, i8** %70
store i8* %71, i8** %8
%72 = load i8**, i8*** %5
%73 = getelementptr inbounds i8*, i8** %72, i64 0
store i8** %73, i8*** %9
%74 = call i32 (...) @getpid()
store i32 %74, i32* %11
%75 = call i32 (...) @fork()
store i32 %75, i32* %10
%76 = load i32, i32* %10
%77 = icmp eq i32 %76, -1
br i1 %77, label %78, label %81
78: ; preds = %68
%79 = call i32 (i8*, ...) @errmsgf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0))
%80 = call i32 @exit(i32 1)
unreachable
81: ; preds = %68
%82 = load i32, i32* %10
%83 = icmp sgt i32 %82, 0
br i1 %83, label %84, label %95
84: ; preds = %81
%85 = load i32, i32* @PR_SET_PDEATHSIG
%86 = load i32, i32* @SIGTERM
%87 = call i32 @prctl(i32 %85, i32 %86)
%88 = icmp eq i32 %87, -1
br i1 %88, label %89, label %92
89: ; preds = %84
%90 = call i32 (i8*, ...) @errmsgf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0))
%91 = call i32 @exit(i32 1)
unreachable
92: ; preds = %84
%93 = load i32, i32* %10
%94 = call i32 @parent_main(i32 %93)
store i32 %94, i32* %3
br label %130
95: ; preds = %81
%96 = load i32, i32* @PR_SET_PDEATHSIG
%97 = load i32, i32* @SIGKILL
%98 = call i32 @prctl(i32 %96, i32 %97)
%99 = icmp eq i32 %98, -1
br i1 %99, label %100, label %103
100: ; preds = %95
%101 = call i32 (i8*, ...) @errmsgf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.10, i64 0, i64 0))
%102 = call i32 @exit(i32 1)
unreachable
103: ; preds = %95
%104 = load i32, i32* %11
%105 = call i32 (...) @getppid()
%106 = icmp ne i32 %104, %105
br i1 %106, label %107, label %111
107: ; preds = %103
%108 = load i32, i32* %11
%109 = call i32 (i8*, ...) @errmsgf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.11, i64 0, i64 0), i32 %108)
%110 = call i32 @exit(i32 1)
unreachable
111: ; preds = %103
%112 = call i32 (...) @getpid()
%113 = load i64, i64* %6
%114 = call i32 @set_affinities(i32 %112, i64 %113)
%115 = icmp eq i32 %114, -1
br i1 %115, label %116, label %119
116: ; preds = %111
%117 = call i32 (i8*, ...) @errmsgf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.12, i64 0, i64 0))
%118 = call i32 @exit(i32 1)
unreachable
119: ; preds = %111
%120 = load i8*, i8** %8
%121 = load i8**, i8*** %9
%122 = call i32 @execvp(i8* %120, i8** %121)
%123 = icmp eq i32 %122, -1
br i1 %123, label %124, label %128
124: ; preds = %119
%125 = load i8*, i8** %8
%126 = call i32 (i8*, ...) @errmsgf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.13, i64 0, i64 0), i8* %125)
%127 = call i32 @exit(i32 1)
unreachable
128: ; preds = %119
br label %129
129: ; preds = %128
store i32 0, i32* %3
br label %130
130: ; preds = %129, %92, %52, %14
%131 = load i32, i32* %3
ret i32 %131
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [52 x i8] c"Usage: safeexec [OPTIONS] COMMAND [COMMAND_ARG...]\0A\00"
@.str.1 = [9 x i8] c"Options\0A\00"
@.str.2 = [71 x i8] c" --cpu CPU_MASK : Run process on the set of CPUs be eligible to run.\0A\00"
@.str.3 = [111 x i8] c" CPU_MASK determines the set of CPUs be eligible to run and is specified by hex(e.g. 0x01).\0A\00"
@.str.4 = [6 x i8] c"--cpu\00"
@.str.6 = [46 x i8] c"CPU_MASK must be specified by hex(e.g. 0x01)\0A\00"
@.str.7 = [26 x i8] c"COMMAND path is not found\00"
@.str.8 = [14 x i8] c"fork() failed\00"
@PR_SET_PDEATHSIG = global i32 0
@SIGTERM = global i32 0
@.str.9 = [22 x i8] c"parent prctl() failed\00"
@SIGKILL = global i32 0
@.str.10 = [21 x i8] c"child prctl() failed\00"
@.str.11 = [33 x i8] c"parent process(%d) has been dead\00"
@.str.12 = [22 x i8] c"set_affinity() failed\00"
@.str.13 = [31 x i8] c"execvp() failed [command = %s]\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i8*
%4 = icmp slt i32 %0, 2
br i1 %4, label %5, label %14
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.2, i64 0, i64 0))
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([111 x i8], [111 x i8]* @.str.3, i64 0, i64 0))
br label %97
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = icmp eq i32 %0, 2
br i1 %16, label %49, label %17
17: ; preds = %14
%18 = bitcast i8** %3 to i8*
%19 = load i8*, i8** %15
%20 = tail call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %49
22: ; preds = %17
%23 = add nsw i32 %0, -1
br label %28
24: ; preds = %40
%25 = load i8*, i8** %42
%26 = tail call i64 @strcmp(i8* %25, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %49
28: ; preds = %22, %24
%29 = phi i8** [ %15, %22 ], [ %42, %24 ]
%30 = phi i32 [ %23, %22 ], [ %41, %24 ]
store i8* null, i8** %3
%31 = getelementptr inbounds i8*, i8** %29, i64 1
%32 = load i8*, i8** %31
%33 = call i64 @strtol(i8* %32, i8** %3, i32 16)
%34 = load i8*, i8** %3
%35 = load i8, i8* %34
%36 = icmp eq i8 %35, 0
br i1 %36, label %40, label %37
37: ; preds = %28
%38 = load i32, i32* @stderr
%39 = tail call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.6, i64 0, i64 0))
br label %97
40: ; preds = %28
%41 = add nsw i32 %30, -2
%42 = getelementptr inbounds i8*, i8** %29, i64 2
%43 = icmp sgt i32 %30, 3
br i1 %43, label %24, label %44
44: ; preds = %40
%45 = icmp eq i32 %41, 1
br i1 %45, label %49, label %46
46: ; preds = %44
%47 = tail call i32 (i8*, ...) @errmsgf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0))
%48 = tail call i32 @exit(i32 1)
unreachable
49: ; preds = %24, %17, %14, %44
%50 = phi i64 [ %33, %44 ], [ -1, %14 ], [ -1, %17 ], [ %33, %24 ]
%51 = phi i8** [ %42, %44 ], [ %15, %14 ], [ %15, %17 ], [ %42, %24 ]
%52 = load i8*, i8** %51
%53 = tail call i32 (...) @getpid()
%54 = tail call i32 (...) @fork()
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %59
56: ; preds = %49
%57 = tail call i32 (i8*, ...) @errmsgf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0))
%58 = tail call i32 @exit(i32 1)
unreachable
59: ; preds = %49
%60 = icmp sgt i32 %54, 0
%61 = load i32, i32* @PR_SET_PDEATHSIG
br i1 %60, label %62, label %71
62: ; preds = %59
%63 = load i32, i32* @SIGTERM
%64 = tail call i32 @prctl(i32 %61, i32 %63)
%65 = icmp eq i32 %64, -1
br i1 %65, label %66, label %69
66: ; preds = %62
%67 = tail call i32 (i8*, ...) @errmsgf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0))
%68 = tail call i32 @exit(i32 1)
unreachable
69: ; preds = %62
%70 = tail call i32 @parent_main(i32 %54)
br label %97
71: ; preds = %59
%72 = load i32, i32* @SIGKILL
%73 = tail call i32 @prctl(i32 %61, i32 %72)
%74 = icmp eq i32 %73, -1
br i1 %74, label %75, label %78
75: ; preds = %71
%76 = tail call i32 (i8*, ...) @errmsgf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.10, i64 0, i64 0))
%77 = tail call i32 @exit(i32 1)
unreachable
78: ; preds = %71
%79 = tail call i32 (...) @getppid()
%80 = icmp eq i32 %53, %79
br i1 %80, label %84, label %81
81: ; preds = %78
%82 = tail call i32 (i8*, ...) @errmsgf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.11, i64 0, i64 0), i32 %53)
%83 = tail call i32 @exit(i32 1)
unreachable
84: ; preds = %78
%85 = tail call i32 (...) @getpid()
%86 = tail call i32 @set_affinities(i32 %85, i64 %50)
%87 = icmp eq i32 %86, -1
br i1 %87, label %88, label %91
88: ; preds = %84
%89 = tail call i32 (i8*, ...) @errmsgf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.12, i64 0, i64 0))
%90 = tail call i32 @exit(i32 1)
unreachable
91: ; preds = %84
%92 = tail call i32 @execvp(i8* %52, i8** %51)
%93 = icmp eq i32 %92, -1
br i1 %93, label %94, label %97
94: ; preds = %91
%95 = tail call i32 (i8*, ...) @errmsgf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.13, i64 0, i64 0), i8* %52)
%96 = tail call i32 @exit(i32 1)
unreachable
97: ; preds = %37, %69, %91, %5
%98 = phi i32 [ 1, %5 ], [ 0, %91 ], [ 1, %37 ], [ %70, %69 ]
ret i32 %98
}