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

/* Variables and functions */
int NSIG;
int /*<<< orphan*/ SIG_BLOCK;
int /*<<< orphan*/ SIG_DFL;
int /*<<< orphan*/ execv(char *, char **);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ memset(struct sigaction *, int /*<<< orphan*/, int);
int /*<<< orphan*/ sigaction(int, struct sigaction *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int /*<<< orphan*/ sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *,
                               int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int i;
  sigset_t blockedsigs;
  struct sigaction action;
  sigemptyset(&blockedsigs);
  sigprocmask(SIG_BLOCK, NULL, NULL);
  memset(&action, 0, sizeof(action));
  action.sa_handler = SIG_DFL;
  action.sa_flags = 0;
  sigemptyset(&action.sa_mask);
  for (i = 0; i < NSIG; ++i)
    sigaction(i, &action, NULL);
  execv(argv[1], argv + 1);
  fprintf(stderr, "failed to execv %s\n", argv[1]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
call   1070 <sigemptyset@plt>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1030 <sigprocmask@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1050 <memset@plt>
mov    0x2e25(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
lea    -0x30(%rbp),%rdi
call   1070 <sigemptyset@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2df6(%rip),%rcx
cmp    (%rcx),%eax
jge    11f8 <main+0x98>
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <sigaction@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11c8 <main+0x68>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
call   1080 <execv@plt>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xddb(%rip),%rsi
call   1060 <fprintf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
lea    0xc(%rsp),%rdi
call   1070 <sigemptyset@plt>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
xor    %ebx,%ebx
xor    %esi,%esi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
lea    0x10(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1050 <memset@plt>
mov    0x2e29(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x20(%rsp)
movq   $0x0,0x18(%rsp)
mov    %r15,%rdi
call   1070 <sigemptyset@plt>
mov    0x2e03(%rip),%r12
cmpl   $0x0,(%r12)
jle    11f5 <main+0x95>
lea    0x10(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r15,%rsi
xor    %edx,%edx
call   1040 <sigaction@plt>
add    $0x1,%ebx
cmp    (%r12),%ebx
jl     11e0 <main+0x80>
lea    0x8(%r14),%rsi
mov    0x8(%r14),%rdi
call   1080 <execv@plt>
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rdx
lea    0xdea(%rip),%rsi
call   1060 <fprintf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sigaction = type { i32, i64, i32 }
@SIG_BLOCK = global i32 0
@SIG_DFL = global i32 0
@NSIG = global i32 0
@stderr = global i32 0
@.str = [20 x i8] c"failed to execv %s\0A\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 %struct.sigaction
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 @sigemptyset(i32* %7)
%10 = load i32, i32* @SIG_BLOCK
%11 = call i32 @sigprocmask(i32 %10, i32* null, i32* null)
%12 = call i32 @memset(%struct.sigaction* %8, i32 0, i32 24)
%13 = load i32, i32* @SIG_DFL
%14 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %8, i32 0, i32 2
store i32 %13, i32* %14
%15 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %8, i32 0, i32 1
store i64 0, i64* %15
%16 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %8, i32 0, i32 0
%17 = call i32 @sigemptyset(i32* %16)
store i32 0, i32* %6
br label %18
18: ; preds = %25, %2
%19 = load i32, i32* %6
%20 = load i32, i32* @NSIG
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %28
22: ; preds = %18
%23 = load i32, i32* %6
%24 = call i32 @sigaction(i32 %23, %struct.sigaction* %8, i32* null)
br label %25
25: ; preds = %22
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
store i32 %27, i32* %6
br label %18
28: ; preds = %18
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = call i32 @execv(i8* %31, i8** %33)
%35 = load i32, i32* @stderr
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
%39 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %38)
ret i32 0
}

LLVM IR (-O2):
%struct.sigaction = type { i32, i64, i32 }
@SIG_BLOCK = global i32 0
@SIG_DFL = global i32 0
@NSIG = global i32 0
@stderr = global i32 0
@.str = [20 x i8] c"failed to execv %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca %struct.sigaction
%5 = bitcast i32* %3 to i8*
%6 = bitcast %struct.sigaction* %4 to i8*
%7 = call i32 @sigemptyset(i32* %3)
%8 = load i32, i32* @SIG_BLOCK
%9 = call i32 @sigprocmask(i32 %8, i32* null, i32* null)
%10 = call i32 @memset(%struct.sigaction* %4, i32 0, i32 24)
%11 = load i32, i32* @SIG_DFL
%12 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %4, i64 0, i32 2
store i32 %11, i32* %12
%13 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %4, i64 0, i32 1
store i64 0, i64* %13
%14 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %4, i64 0, i32 0
%15 = call i32 @sigemptyset(i32* %14)
%16 = load i32, i32* @NSIG
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %2, %18
%19 = phi i32 [ %21, %18 ], [ 0, %2 ]
%20 = call i32 @sigaction(i32 %19, %struct.sigaction* %4, i32* null)
%21 = add nuw nsw i32 %19, 1
%22 = load i32, i32* @NSIG
%23 = icmp slt i32 %21, %22
br i1 %23, label %18, label %24
24: ; preds = %18, %2
%25 = getelementptr inbounds i8*, i8** %1, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @execv(i8* %26, i8** %25)
%28 = load i32, i32* @stderr
%29 = load i8*, i8** %25
%30 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %29)
ret i32 0
}