#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 /*<<< orphan*/ sigset_t;

/* Variables and functions */
int /*<<< orphan*/ SIGTERM;
int /*<<< orphan*/ SIG_UNBLOCK;
int /*<<< orphan*/ X_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
scalar_t__ execv(char *, char **);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ perror(char *);
scalar_t__ pthread_sigmask(int /*<<< orphan*/, int /*<<< orphan*/ *,
                           int /*<<< orphan*/ *);
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  sigset_t signal_mask;
  if (argc < 2) {
    fprintf(stderr, "Usage: %s <command> <arguments>\n", argv[0]);
    exit(1);
  }
  if (access(argv[1], X_OK)) {
    perror("access");
    fprintf(stderr, "Error: command %s not found or cannot be executed\n",
            argv[1]);
    exit(1);
  }
  sigemptyset(&signal_mask);
  sigaddset(&signal_mask, SIGTERM);
  if (pthread_sigmask(SIG_UNBLOCK, &signal_mask, NULL)) {
    perror("pthread_sigmask");
    fprintf(stderr, "Error: cannot unblock SIGTERM\n");
    exit(1);
  }
  if (execv(argv[1], &argv[1])) {
    perror("execv");
    fprintf(stderr, "Error: cannot execute command %s\n", argv[1]);
    exit(1);
  }
  return 0;
}


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    11c8 <main+0x48>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe49(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e01(%rip),%rax
mov    (%rax),%esi
call   1060 <access@plt>
cmp    $0x0,%rax
je     121d <main+0x9d>
lea    0xe32(%rip),%rdi
call   1070 <perror@plt>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe1c(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    -0x14(%rbp),%rdi
call   1040 <sigemptyset@plt>
mov    0x2db3(%rip),%rax
mov    (%rax),%esi
lea    -0x14(%rbp),%rdi
call   1090 <sigaddset@plt>
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
lea    -0x14(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <pthread_sigmask@plt>
cmp    $0x0,%rax
je     1285 <main+0x105>
lea    0xdfc(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d5d(%rip),%rax
mov    (%rax),%edi
lea    0xdf7(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
call   10a0 <execv@plt>
cmp    $0x0,%rax
je     12d9 <main+0x159>
lea    0xddf(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d11(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdc8(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x1,%edi
jle    11f7 <main+0x77>
mov    0x8(%rbx),%rdi
add    $0x8,%rbx
mov    0x2e3d(%rip),%rax
mov    (%rax),%esi
call   1060 <access@plt>
test   %rax,%rax
jne    120c <main+0x8c>
lea    0x4(%rsp),%r14
mov    %r14,%rdi
call   1040 <sigemptyset@plt>
mov    0x2e25(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1090 <sigaddset@plt>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1050 <pthread_sigmask@plt>
test   %rax,%rax
jne    122d <main+0xad>
mov    (%rbx),%rdi
mov    %rbx,%rsi
call   10a0 <execv@plt>
test   %rax,%rax
jne    125a <main+0xda>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xdf6(%rip),%rsi
jmp    1279 <main+0xf9>
lea    0xe0e(%rip),%rdi
call   1070 <perror@plt>
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xdfd(%rip),%rsi
jmp    1279 <main+0xf9>
lea    0xe27(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
lea    0xe22(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xe29(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d5b(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe17(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [33 x i8] c"Usage: %s <command> <arguments>\0A\00"
@X_OK = global i32 0
@.str.1 = [7 x i8] c"access\00"
@.str.2 = [51 x i8] c"Error: command %s not found or cannot be executed\0A\00"
@SIGTERM = global i32 0
@SIG_UNBLOCK = global i32 0
@.str.3 = [16 x i8] c"pthread_sigmask\00"
@.str.4 = [31 x i8] c"Error: cannot unblock SIGTERM\0A\00"
@.str.5 = [6 x i8] c"execv\00"
@.str.6 = [34 x i8] c"Error: cannot execute command %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
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 %16
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = load i32, i32* @X_OK
%21 = call i64 @access(i8* %19, i32 %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %31
23: ; preds = %16
%24 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%25 = load i32, i32* @stderr
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i8* %28)
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %16
%32 = call i32 @sigemptyset(i32* %6)
%33 = load i32, i32* @SIGTERM
%34 = call i32 @sigaddset(i32* %6, i32 %33)
%35 = load i32, i32* @SIG_UNBLOCK
%36 = call i64 @pthread_sigmask(i32 %35, i32* %6, i32* null)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %43
38: ; preds = %31
%39 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%40 = load i32, i32* @stderr
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %31
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 1
%46 = load i8*, i8** %45
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 1
%49 = call i64 @execv(i8* %46, i8** %48)
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %59
51: ; preds = %43
%52 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%53 = load i32, i32* @stderr
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 1
%56 = load i8*, i8** %55
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i8* %56)
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %43
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [33 x i8] c"Usage: %s <command> <arguments>\0A\00"
@X_OK = global i32 0
@.str.1 = [7 x i8] c"access\00"
@.str.2 = [51 x i8] c"Error: command %s not found or cannot be executed\0A\00"
@SIGTERM = global i32 0
@SIG_UNBLOCK = global i32 0
@.str.3 = [16 x i8] c"pthread_sigmask\00"
@.str.4 = [31 x i8] c"Error: cannot unblock SIGTERM\0A\00"
@.str.5 = [6 x i8] c"execv\00"
@.str.6 = [34 x i8] c"Error: cannot execute command %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %11
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = load i32, i32* @X_OK
%15 = tail call i64 @access(i8* %13, i32 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %23, label %17
17: ; preds = %11
%18 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %12
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i8* %20)
%22 = tail call i32 @exit(i32 1)
unreachable
23: ; preds = %11
%24 = call i32 @sigemptyset(i32* %3)
%25 = load i32, i32* @SIGTERM
%26 = call i32 @sigaddset(i32* %3, i32 %25)
%27 = load i32, i32* @SIG_UNBLOCK
%28 = call i64 @pthread_sigmask(i32 %27, i32* %3, i32* null)
%29 = icmp eq i64 %28, 0
br i1 %29, label %35, label %30
30: ; preds = %23
%31 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%32 = load i32, i32* @stderr
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %23
%36 = load i8*, i8** %12
%37 = call i64 @execv(i8* %36, i8** %12)
%38 = icmp eq i64 %37, 0
br i1 %38, label %45, label %39
39: ; preds = %35
%40 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%41 = load i32, i32* @stderr
%42 = load i8*, i8** %12
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i8* %42)
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %35
ret i32 0
}