#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 SIGTERM;
int atoi(int /*<<< orphan*/);
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int getopt(int, char **, char *);
int /*<<< orphan*/ optarg;
int optind;
int /*<<< orphan*/ perror(char *);
int prctl(int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int usage_error = 0;
  int signal = SIGTERM;
  int flag;
  while ((flag = getopt(argc, argv, "+s:")) != -1) {
    switch (flag) {
    case 's':
      signal = atoi(optarg);
      break;
    default:
      usage_error = 1;
    }
  }
  if (usage_error || signal <= 0 || argc - optind < 1) {
    fprintf(stderr, "Usage: %s [-s SIGNUM] PROGRAM [ARGS...]\n", argv[0]);
    return 2;
  }
  if (prctl(PR_SET_PDEATHSIG, signal) == -1) {
    perror("prctl");
  }
  execvp(argv[optind], argv + optind);
  perror(argv[optind]);
  return 127;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    0x2e5c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe69(%rip),%rdx
call   1060 <getopt@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
je     11db <main+0x7b>
mov    -0x1c(%rbp),%eax
sub    $0x73,%eax
jne    11cf <main+0x6f>
jmp    11b9 <main+0x59>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
call   1080 <atoi@plt>
mov    %eax,-0x18(%rbp)
jmp    11d6 <main+0x76>
movl   $0x1,-0x14(%rbp)
jmp    1189 <main+0x29>
cmpl   $0x0,-0x14(%rbp)
jne    1204 <main+0xa4>
cmpl   $0x0,-0x18(%rbp)
jle    1204 <main+0xa4>
mov    -0x8(%rbp),%eax
mov    0x2ddf(%rip),%rcx
sub    (%rcx),%eax
cmp    $0x1,%eax
jge    122c <main+0xcc>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xde9(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    129c <main+0x13c>
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%esi
call   1040 <prctl@plt>
cmp    $0xffffffff,%eax
jne    1252 <main+0xf2>
lea    0xde0(%rip),%rdi
call   1050 <perror@plt>
mov    -0x10(%rbp),%rax
mov    0x2d7b(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x10(%rbp),%rsi
mov    0x2d69(%rip),%rax
movslq (%rax),%rax
shl    $0x3,%rax
add    %rax,%rsi
call   1070 <execvp@plt>
mov    -0x10(%rbp),%rax
mov    0x2d4f(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
call   1050 <perror@plt>
movl   $0x7f,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebp
mov    0x2e69(%rip),%rax
mov    (%rax),%ebx
mov    $0x1,%r12b
lea    0xe7d(%rip),%r15
mov    0x2e6e(%rip),%r13
jmp    119b <main+0x3b>
nopl   0x0(%rax)
mov    0x0(%r13),%edi
call   1080 <atoi@plt>
mov    %eax,%ebx
mov    %ebp,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1060 <getopt@plt>
cmp    $0x73,%eax
je     1190 <main+0x30>
cmp    $0xffffffff,%eax
je     11b7 <main+0x57>
xor    %r12d,%r12d
jmp    119b <main+0x3b>
test   %ebx,%ebx
setg   %al
and    %al,%r12b
cmp    $0x1,%r12b
jne    11d1 <main+0x71>
mov    0x2e0c(%rip),%r15
cmp    %ebp,(%r15)
jl     11fd <main+0x9d>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xe20(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x2,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
mov    %ebx,%esi
call   1040 <prctl@plt>
cmp    $0xffffffff,%eax
jne    121e <main+0xbe>
lea    0xe14(%rip),%rdi
call   1050 <perror@plt>
movslq (%r15),%rax
lea    (%r14,%rax,8),%rsi
mov    (%r14,%rax,8),%rdi
call   1070 <execvp@plt>
movslq (%r15),%rax
mov    (%r14,%rax,8),%rdi
call   1050 <perror@plt>
mov    $0x7f,%eax
jmp    11ee <main+0x8e>

LLVM IR (-O0):
@SIGTERM = global i32 0
@.str = [4 x i8] c"+s:\00"
@optarg = global i32 0
@optind = global i32 0
@stderr = global i32 0
@.str.1 = [41 x i8] c"Usage: %s [-s SIGNUM] PROGRAM [ARGS...]\0A\00"
@PR_SET_PDEATHSIG = global i32 0
@.str.2 = [6 x i8] c"prctl\00"
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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%9 = load i32, i32* @SIGTERM
store i32 %9, i32* %7
br label %10
10: ; preds = %21, %2
%11 = load i32, i32* %4
%12 = load i8**, i8*** %5
%13 = call i32 @getopt(i32 %11, i8** %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 %13, i32* %8
%14 = icmp ne i32 %13, -1
br i1 %14, label %15, label %22
15: ; preds = %10
%16 = load i32, i32* %8
switch i32 %16, label %20 [
i32 115, label %17
]
17: ; preds = %15
%18 = load i32, i32* @optarg
%19 = call i32 @atoi(i32 %18)
store i32 %19, i32* %7
br label %21
20: ; preds = %15
store i32 1, i32* %6
br label %21
21: ; preds = %20, %17
br label %10
22: ; preds = %10
%23 = load i32, i32* %6
%24 = icmp ne i32 %23, 0
br i1 %24, label %33, label %25
25: ; preds = %22
%26 = load i32, i32* %7
%27 = icmp sle i32 %26, 0
br i1 %27, label %33, label %28
28: ; preds = %25
%29 = load i32, i32* %4
%30 = load i32, i32* @optind
%31 = sub nsw i32 %29, %30
%32 = icmp slt i32 %31, 1
br i1 %32, label %33, label %39
33: ; preds = %28, %25, %22
%34 = load i32, i32* @stderr
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 0
%37 = load i8*, i8** %36
%38 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i8* %37)
store i32 2, i32* %3
br label %63
39: ; preds = %28
%40 = load i32, i32* @PR_SET_PDEATHSIG
%41 = load i32, i32* %7
%42 = call i32 @prctl(i32 %40, i32 %41)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %46
44: ; preds = %39
%45 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %46
46: ; preds = %44, %39
%47 = load i8**, i8*** %5
%48 = load i32, i32* @optind
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8*, i8** %47, i64 %49
%51 = load i8*, i8** %50
%52 = load i8**, i8*** %5
%53 = load i32, i32* @optind
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8*, i8** %52, i64 %54
%56 = call i32 @execvp(i8* %51, i8** %55)
%57 = load i8**, i8*** %5
%58 = load i32, i32* @optind
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8*, i8** %57, i64 %59
%61 = load i8*, i8** %60
%62 = call i32 @perror(i8* %61)
store i32 127, i32* %3
br label %63
63: ; preds = %46, %33
%64 = load i32, i32* %3
ret i32 %64
}

LLVM IR (-O2):
@SIGTERM = global i32 0
@.str = [4 x i8] c"+s:\00"
@optarg = global i32 0
@optind = global i32 0
@stderr = global i32 0
@.str.1 = [41 x i8] c"Usage: %s [-s SIGNUM] PROGRAM [ARGS...]\0A\00"
@PR_SET_PDEATHSIG = global i32 0
@.str.2 = [6 x i8] c"prctl\00"
define i32 @main(i32 %0, i8** %1) {
%3 = load i32, i32* @SIGTERM
br label %4
4: ; preds = %7, %2
%5 = phi i1 [ true, %2 ], [ false, %7 ]
%6 = phi i32 [ %3, %2 ], [ %8, %7 ]
br label %7
7: ; preds = %4, %10
%8 = phi i32 [ %12, %10 ], [ %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 %4 [
i32 -1, label %13
i32 115, label %10
]
10: ; preds = %7
%11 = load i32, i32* @optarg
%12 = tail call i32 @atoi(i32 %11)
br label %7
13: ; preds = %7
%14 = icmp sgt i32 %8, 0
%15 = select i1 %5, i1 %14, i1 false
%16 = load i32, i32* @optind
%17 = icmp slt i32 %16, %0
%18 = select i1 %15, i1 %17, i1 false
br i1 %18, label %23, label %19
19: ; preds = %13
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %1
%22 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i8* %21)
br label %40
23: ; preds = %13
%24 = load i32, i32* @PR_SET_PDEATHSIG
%25 = tail call i32 @prctl(i32 %24, i32 %8)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %27, %23
%30 = load i32, i32* @optind
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %1, i64 %31
%33 = load i8*, i8** %32
%34 = tail call i32 @execvp(i8* %33, i8** %32)
%35 = load i32, i32* @optind
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8*, i8** %1, i64 %36
%38 = load i8*, i8** %37
%39 = tail call i32 @perror(i8* %38)
br label %40
40: ; preds = %29, %19
%41 = phi i32 [ 2, %19 ], [ 127, %29 ]
ret i32 %41
}