#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 */
struct sigaction {
  scalar_t__ sa_flags;
  int /*<<< orphan*/ sa_mask;
  int /*<<< orphan*/ sa_handler;
};

/* Variables and functions */
#define ELOOP 131
#define ENAMETOOLONG 130
#define ENOENT 129
#define ENOTDIR 128
int /*<<< orphan*/ SIGHUP;
int /*<<< orphan*/ SIG_IGN;
int errno;
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ print_usage(char *);
scalar_t__ redirect_tty();
scalar_t__ sigaction(int /*<<< orphan*/, struct sigaction *,
                     int /*<<< orphan*/ *);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  struct sigaction sa;
  if (argc < 2) {
    print_usage(argv[0]);
    return 127;
  }
  sa.sa_handler = SIG_IGN;
  sigemptyset(&sa.sa_mask);
  sa.sa_flags = 0;
  if (sigaction(SIGHUP, &sa, NULL) < 0) {
    perror("cannot ignore SIGHUP");
    return 127;
  }
  if (redirect_tty() < 0)
    return 127;
  execvp(argv[1], argv + 1);
  perror("cannot execute");
  switch (errno) {
  case ELOOP:
  case ENAMETOOLONG:
  case ENOENT:
  case ENOTDIR:
    return 127;
  default:
    return 126;
  }
}


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)
cmpl   $0x2,-0x8(%rbp)
jge    1198 <main+0x38>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1080 <print_usage@plt>
movl   $0x7f,-0x4(%rbp)
jmp    125b <main+0xfb>
mov    0x2e41(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
lea    -0x20(%rbp),%rdi
add    $0x8,%rdi
call   1040 <sigemptyset@plt>
movq   $0x0,-0x20(%rbp)
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
cmp    $0x0,%rax
jge    11f1 <main+0x91>
lea    0xe20(%rip),%rdi
call   1060 <perror@plt>
movl   $0x7f,-0x4(%rbp)
jmp    125b <main+0xfb>
mov    $0x0,%al
call   1050 <redirect_tty@plt>
cmp    $0x0,%rax
jge    120e <main+0xae>
movl   $0x7f,-0x4(%rbp)
jmp    125b <main+0xfb>
mov    -0x10(%rbp),%rax
mov    %rax,%rsi
add    $0x8,%rsi
mov    0x8(%rax),%rdi
call   1070 <execvp@plt>
lea    0xdec(%rip),%rdi
call   1060 <perror@plt>
mov    0x2d9b(%rip),%rax
mov    (%rax),%eax
add    $0xffffff80,%eax
sub    $0x3,%eax
ja     1254 <main+0xf4>
jmp    1248 <main+0xe8>
movl   $0x7f,-0x4(%rbp)
jmp    125b <main+0xfb>
movl   $0x7e,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
cmp    $0x1,%edi
jg     117c <main+0x1c>
mov    (%rbx),%rdi
call   1080 <print_usage@plt>
mov    $0x7f,%eax
jmp    11c7 <main+0x67>
mov    0x2e5d(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
lea    0x8(%rsp),%rdi
call   1040 <sigemptyset@plt>
movq   $0x0,(%rsp)
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
xor    %edx,%edx
call   1030 <sigaction@plt>
test   %rax,%rax
js     11cd <main+0x6d>
xor    %eax,%eax
call   1050 <redirect_tty@plt>
mov    %rax,%rcx
mov    $0x7f,%eax
test   %rcx,%rcx
jns    11e0 <main+0x80>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe2c(%rip),%rdi
call   1060 <perror@plt>
mov    $0x7f,%eax
jmp    11c7 <main+0x67>
mov    0x8(%rbx),%rdi
add    $0x8,%rbx
mov    %rbx,%rsi
call   1070 <execvp@plt>
lea    0xe1e(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dcd(%rip),%rax
mov    (%rax),%ecx
and    $0xfffffffc,%ecx
xor    %eax,%eax
cmp    $0x80,%ecx
sete   %al
or     $0x7e,%eax
jmp    11c7 <main+0x67>

LLVM IR (-O0):
%struct.sigaction = type { i64, i32, i32 }
@SIG_IGN = global i32 0
@SIGHUP = global i32 0
@.str = [21 x i8] c"cannot ignore SIGHUP\00"
@.str.1 = [15 x i8] c"cannot execute\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sigaction
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 2
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
%13 = call i32 @print_usage(i8* %12)
store i32 127, i32* %3
br label %40
14: ; preds = %2
%15 = load i32, i32* @SIG_IGN
%16 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %6, i32 0, i32 2
store i32 %15, i32* %16
%17 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %6, i32 0, i32 1
%18 = call i32 @sigemptyset(i32* %17)
%19 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %6, i32 0, i32 0
store i64 0, i64* %19
%20 = load i32, i32* @SIGHUP
%21 = call i64 @sigaction(i32 %20, %struct.sigaction* %6, i32* null)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %14
%24 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i32 127, i32* %3
br label %40
25: ; preds = %14
%26 = call i64 (...) @redirect_tty()
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %25
store i32 127, i32* %3
br label %40
29: ; preds = %25
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = call i32 @execvp(i8* %32, i8** %34)
%36 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%37 = load i32, i32* @errno
switch i32 %37, label %39 [
i32 131, label %38
i32 130, label %38
i32 129, label %38
i32 128, label %38
]
38: ; preds = %29, %29, %29, %29
store i32 127, i32* %3
br label %40
39: ; preds = %29
store i32 126, i32* %3
br label %40
40: ; preds = %39, %38, %28, %23, %9
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
%struct.sigaction = type { i64, i32, i32 }
@SIG_IGN = global i32 0
@SIGHUP = global i32 0
@.str = [21 x i8] c"cannot ignore SIGHUP\00"
@.str.1 = [15 x i8] c"cannot execute\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.sigaction
%4 = bitcast %struct.sigaction* %3 to i8*
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @print_usage(i8* %7)
br label %32
9: ; preds = %2
%10 = load i32, i32* @SIG_IGN
%11 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 2
store i32 %10, i32* %11
%12 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 1
%13 = call i32 @sigemptyset(i32* %12)
%14 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 0
store i64 0, i64* %14
%15 = load i32, i32* @SIGHUP
%16 = call i64 @sigaction(i32 %15, %struct.sigaction* %3, i32* null)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %9
%19 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %32
20: ; preds = %9
%21 = call i64 (...) @redirect_tty()
%22 = icmp slt i64 %21, 0
br i1 %22, label %32, label %23
23: ; preds = %20
%24 = getelementptr inbounds i8*, i8** %1, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @execvp(i8* %25, i8** %24)
%27 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%28 = load i32, i32* @errno
%29 = and i32 %28, -4
%30 = icmp eq i32 %29, 128
%31 = select i1 %30, i32 127, i32 126
br label %32
32: ; preds = %23, %20, %18, %6
%33 = phi i32 [ 127, %6 ], [ 127, %18 ], [ 127, %20 ], [ %31, %23 ]
ret i32 %33
}