#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 */
typedef int pid_t;

/* Variables and functions */
scalar_t__ ECHILD;
int EX_OSERR;
int EX_SOFTWARE;
int EX_UNAVAILABLE;
int EX_USAGE;
int /*<<< orphan*/ PR_SET_CHILD_SUBREAPER;
scalar_t__ errno;
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ explain_exit(int, int);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int getopt(int, char **, char *);
int optind;
int /*<<< orphan*/ perror(char *);
int prctl(int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
int wait(int *);
int main(int argc, char *argv[]) {
  int opt, quiet = 0, opt_x = 0;
  while ((opt = getopt(argc, argv, "+qx")) != -1) {
    switch (opt) {
    case 'q':
      quiet = 1;
      break;
    case 'x':
      opt_x = 1;
      break;
    default:
      goto usage;
    }
  }
  if (optind >= argc)
    goto usage;
  int erc = prctl(PR_SET_CHILD_SUBREAPER, 1);
  if (erc != 0) {
    perror("set child subreaper failed");
    return EX_OSERR;
  }
  pid_t first_kid = opt_x ? 0 : fork();
  if (first_kid == -1) {
    perror("fork failed");
    return EX_OSERR;
  } else if (first_kid == 0) {
    execvp(argv[optind], argv + optind);
    perror("exec failed");
    return EX_UNAVAILABLE;
  }
  int status;
  pid_t reap_kid;
  while ((reap_kid = wait(&status)) > 0) {
    if (!quiet)
      explain_exit(reap_kid, status);
  }
  if (reap_kid == -1 && errno == ECHILD) {
    return 0;
  }
  return EX_SOFTWARE;
usage:
  fprintf(stderr, "usage: %s [-qx] <command>\n", argv[0]);
  return EX_USAGE;
}


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)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe4e(%rip),%rdx
call   1060 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     120a <main+0x8a>
mov    -0x14(%rbp),%eax
mov    %eax,-0x30(%rbp)
sub    $0x71,%eax
je     11e8 <main+0x68>
jmp    11d7 <main+0x57>
mov    -0x30(%rbp),%eax
sub    $0x78,%eax
je     11f4 <main+0x74>
jmp    1200 <main+0x80>
movl   $0x1,-0x18(%rbp)
jmp    1205 <main+0x85>
movl   $0x1,-0x1c(%rbp)
jmp    1205 <main+0x85>
jmp    1376 <main+0x1f6>
jmp    11a4 <main+0x24>
mov    0x2dcf(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jl     1221 <main+0xa1>
jmp    1376 <main+0x1f6>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
mov    $0x1,%esi
call   1040 <prctl@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     125e <main+0xde>
lea    0xdbc(%rip),%rdi
call   1050 <perror@plt>
mov    0x2d64(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    139e <main+0x21e>
cmpl   $0x0,-0x1c(%rbp)
je     1272 <main+0xf2>
xor    %eax,%eax
mov    %eax,-0x34(%rbp)
jmp    127c <main+0xfc>
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    12a9 <main+0x129>
lea    0xd8c(%rip),%rdi
call   1050 <perror@plt>
mov    0x2d19(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    139e <main+0x21e>
cmpl   $0x0,-0x24(%rbp)
jne    12fc <main+0x17c>
mov    -0x10(%rbp),%rax
mov    0x2d22(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x10(%rbp),%rsi
mov    0x2d10(%rip),%rax
movslq (%rax),%rax
shl    $0x3,%rax
add    %rax,%rsi
call   1070 <execvp@plt>
lea    0xd45(%rip),%rdi
call   1050 <perror@plt>
mov    0x2cb6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    139e <main+0x21e>
jmp    1301 <main+0x181>
jmp    1306 <main+0x186>
lea    -0x28(%rbp),%rdi
call   1090 <wait@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jle    1335 <main+0x1b5>
cmpl   $0x0,-0x18(%rbp)
jne    1330 <main+0x1b0>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%esi
call   1080 <explain_exit@plt>
jmp    1306 <main+0x186>
cmpl   $0xffffffff,-0x2c(%rbp)
jne    1365 <main+0x1e5>
mov    0x2c82(%rip),%rax
mov    (%rax),%rax
mov    0x2c70(%rip),%rcx
cmp    (%rcx),%rax
jne    1365 <main+0x1e5>
movl   $0x0,-0x4(%rbp)
jmp    139e <main+0x21e>
mov    0x2c34(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    139e <main+0x21e>
mov    0x2c53(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xcaa(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2c4f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r15
mov    %edi,%ebp
xor    %ebx,%ebx
mov    $0x1,%r12b
lea    0xe63(%rip),%r14
mov    %ebx,%ecx
nop
mov    %ecx,%ebx
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r14,%rdx
call   1060 <getopt@plt>
mov    $0x1,%ecx
cmp    $0x71,%eax
je     11a0 <main+0x20>
cmp    $0x78,%eax
jne    11c3 <main+0x43>
xor    %r12d,%r12d
jmp    119d <main+0x1d>
cmp    $0xffffffff,%eax
jne    124d <main+0xcd>
mov    0x2e0d(%rip),%r14
cmp    %ebp,(%r14)
jge    124d <main+0xcd>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
mov    $0x1,%esi
call   1040 <prctl@plt>
test   %eax,%eax
jne    12c6 <main+0x146>
test   $0x1,%r12b
je     12a1 <main+0x121>
xor    %eax,%eax
call   10a0 <fork@plt>
cmp    $0xffffffff,%eax
je     12cf <main+0x14f>
test   %eax,%eax
je     12a1 <main+0x121>
lea    0xc(%rsp),%rdi
call   1090 <wait@plt>
test   %eax,%eax
jle    127b <main+0xfb>
lea    0xc(%rsp),%rbp
jmp    123c <main+0xbc>
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1090 <wait@plt>
test   %eax,%eax
jle    127b <main+0xfb>
test   %ebx,%ebx
jne    1230 <main+0xb0>
mov    0xc(%rsp),%esi
mov    %eax,%edi
call   1080 <explain_exit@plt>
jmp    1230 <main+0xb0>
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rdx
lea    0xdd7(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2d7c(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
cmp    $0xffffffff,%eax
jne    1298 <main+0x118>
mov    0x2d41(%rip),%rax
mov    (%rax),%rcx
mov    0x2d2f(%rip),%rdx
xor    %eax,%eax
cmp    (%rdx),%rcx
je     126e <main+0xee>
mov    0x2d01(%rip),%rax
jmp    126c <main+0xec>
movslq (%r14),%rax
lea    (%r15,%rax,8),%rsi
mov    (%r15,%rax,8),%rdi
call   1070 <execvp@plt>
lea    0xd73(%rip),%rdi
call   1050 <perror@plt>
mov    0x2ce4(%rip),%rax
jmp    126c <main+0xec>
lea    0xd37(%rip),%rdi
jmp    12d6 <main+0x156>
lea    0xd49(%rip),%rdi
call   1050 <perror@plt>
mov    0x2cd6(%rip),%rax
jmp    126c <main+0xec>

LLVM IR (-O0):
@.str = [4 x i8] c"+qx\00"
@optind = global i32 0
@PR_SET_CHILD_SUBREAPER = global i32 0
@.str.1 = [27 x i8] c"set child subreaper failed\00"
@EX_OSERR = global i32 0
@.str.2 = [12 x i8] c"fork failed\00"
@.str.3 = [12 x i8] c"exec failed\00"
@EX_UNAVAILABLE = global i32 0
@errno = global i64 0
@ECHILD = global i64 0
@EX_SOFTWARE = global i32 0
@stderr = global i32 0
@.str.4 = [27 x i8] c"usage: %s [-qx] <command>\0A\00"
@EX_USAGE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 0, i32* %8
br label %13
13: ; preds = %23, %2
%14 = load i32, i32* %4
%15 = load i8**, i8*** %5
%16 = call i32 @getopt(i32 %14, i8** %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 %16, i32* %6
%17 = icmp ne i32 %16, -1
br i1 %17, label %18, label %24
18: ; preds = %13
%19 = load i32, i32* %6
switch i32 %19, label %22 [
i32 113, label %20
i32 120, label %21
]
20: ; preds = %18
store i32 1, i32* %7
br label %23
21: ; preds = %18
store i32 1, i32* %8
br label %23
22: ; preds = %18
br label %89
23: ; preds = %21, %20
br label %13
24: ; preds = %13
%25 = load i32, i32* @optind
%26 = load i32, i32* %4
%27 = icmp sge i32 %25, %26
br i1 %27, label %28, label %29
28: ; preds = %24
br label %89
29: ; preds = %24
%30 = load i32, i32* @PR_SET_CHILD_SUBREAPER
%31 = call i32 @prctl(i32 %30, i32 1)
store i32 %31, i32* %9
%32 = load i32, i32* %9
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %29
%35 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%36 = load i32, i32* @EX_OSERR
store i32 %36, i32* %3
br label %96
37: ; preds = %29
%38 = load i32, i32* %8
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %37
br label %43
41: ; preds = %37
%42 = call i32 (...) @fork()
br label %43
43: ; preds = %41, %40
%44 = phi i32 [ 0, %40 ], [ %42, %41 ]
store i32 %44, i32* %10
%45 = load i32, i32* %10
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %50
47: ; preds = %43
%48 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%49 = load i32, i32* @EX_OSERR
store i32 %49, i32* %3
br label %96
50: ; preds = %43
%51 = load i32, i32* %10
%52 = icmp eq i32 %51, 0
br i1 %52, label %53, label %66
53: ; preds = %50
%54 = load i8**, i8*** %5
%55 = load i32, i32* @optind
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8*, i8** %54, i64 %56
%58 = load i8*, i8** %57
%59 = load i8**, i8*** %5
%60 = load i32, i32* @optind
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8*, i8** %59, i64 %61
%63 = call i32 @execvp(i8* %58, i8** %62)
%64 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%65 = load i32, i32* @EX_UNAVAILABLE
store i32 %65, i32* %3
br label %96
66: ; preds = %50
br label %67
67: ; preds = %66
br label %68
68: ; preds = %78, %67
%69 = call i32 @wait(i32* %11)
store i32 %69, i32* %12
%70 = icmp sgt i32 %69, 0
br i1 %70, label %71, label %79
71: ; preds = %68
%72 = load i32, i32* %7
%73 = icmp ne i32 %72, 0
br i1 %73, label %78, label %74
74: ; preds = %71
%75 = load i32, i32* %12
%76 = load i32, i32* %11
%77 = call i32 @explain_exit(i32 %75, i32 %76)
br label %78
78: ; preds = %74, %71
br label %68
79: ; preds = %68
%80 = load i32, i32* %12
%81 = icmp eq i32 %80, -1
br i1 %81, label %82, label %87
82: ; preds = %79
%83 = load i64, i64* @errno
%84 = load i64, i64* @ECHILD
%85 = icmp eq i64 %83, %84
br i1 %85, label %86, label %87
86: ; preds = %82
store i32 0, i32* %3
br label %96
87: ; preds = %82, %79
%88 = load i32, i32* @EX_SOFTWARE
store i32 %88, i32* %3
br label %96
89: ; preds = %28, %22
%90 = load i32, i32* @stderr
%91 = load i8**, i8*** %5
%92 = getelementptr inbounds i8*, i8** %91, i64 0
%93 = load i8*, i8** %92
%94 = call i32 @fprintf(i32 %90, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %93)
%95 = load i32, i32* @EX_USAGE
store i32 %95, i32* %3
br label %96
96: ; preds = %89, %87, %86, %53, %47, %34
%97 = load i32, i32* %3
ret i32 %97
}

LLVM IR (-O2):
@.str = [4 x i8] c"+qx\00"
@optind = global i32 0
@PR_SET_CHILD_SUBREAPER = global i32 0
@.str.1 = [27 x i8] c"set child subreaper failed\00"
@EX_OSERR = global i32 0
@.str.2 = [12 x i8] c"fork failed\00"
@.str.3 = [12 x i8] c"exec failed\00"
@EX_UNAVAILABLE = global i32 0
@errno = global i64 0
@ECHILD = global i64 0
@EX_SOFTWARE = global i32 0
@stderr = global i32 0
@.str.4 = [27 x i8] c"usage: %s [-qx] <command>\0A\00"
@EX_USAGE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
br label %4
4: ; preds = %7, %2
%5 = phi i1 [ true, %2 ], [ false, %7 ]
%6 = phi i32 [ 0, %2 ], [ %8, %7 ]
br label %7
7: ; preds = %4, %7
%8 = phi i32 [ 1, %7 ], [ %6, %4 ]
%9 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
switch i32 %9, label %56 [
i32 -1, label %10
i32 113, label %7
i32 120, label %4
]
10: ; preds = %7
%11 = load i32, i32* @optind
%12 = icmp slt i32 %11, %0
br i1 %12, label %13, label %56
13: ; preds = %10
%14 = load i32, i32* @PR_SET_CHILD_SUBREAPER
%15 = tail call i32 @prctl(i32 %14, i32 1)
%16 = icmp eq i32 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %13
%18 = tail call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%19 = load i32, i32* @EX_OSERR
br label %61
20: ; preds = %13
br i1 %5, label %21, label %31
21: ; preds = %20
%22 = tail call i32 (...) @fork()
switch i32 %22, label %23 [
i32 -1, label %28
i32 0, label %31
]
23: ; preds = %21
%24 = call i32 @wait(i32* %3)
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %47
26: ; preds = %23
%27 = icmp eq i32 %8, 0
br label %39
28: ; preds = %21
%29 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%30 = load i32, i32* @EX_OSERR
br label %61
31: ; preds = %20, %21
%32 = load i32, i32* @optind
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8*, i8** %1, i64 %33
%35 = load i8*, i8** %34
%36 = tail call i32 @execvp(i8* %35, i8** %34)
%37 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%38 = load i32, i32* @EX_UNAVAILABLE
br label %61
39: ; preds = %26, %44
%40 = phi i32 [ %24, %26 ], [ %45, %44 ]
br i1 %27, label %41, label %44
41: ; preds = %39
%42 = load i32, i32* %3
%43 = call i32 @explain_exit(i32 %40, i32 %42)
br label %44
44: ; preds = %41, %39
%45 = call i32 @wait(i32* %3)
%46 = icmp sgt i32 %45, 0
br i1 %46, label %39, label %47
47: ; preds = %44, %23
%48 = phi i32 [ %24, %23 ], [ %45, %44 ]
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %54
50: ; preds = %47
%51 = load i64, i64* @errno
%52 = load i64, i64* @ECHILD
%53 = icmp eq i64 %51, %52
br i1 %53, label %61, label %54
54: ; preds = %50, %47
%55 = load i32, i32* @EX_SOFTWARE
br label %61
56: ; preds = %7, %10
%57 = load i32, i32* @stderr
%58 = load i8*, i8** %1
%59 = tail call i32 @fprintf(i32 %57, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %58)
%60 = load i32, i32* @EX_USAGE
br label %61
61: ; preds = %50, %56, %54, %31, %28, %17
%62 = phi i32 [ %60, %56 ], [ %19, %17 ], [ %30, %28 ], [ %38, %31 ], [ %55, %54 ], [ 0, %50 ]
ret i32 %62
}