#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 dummy;
};

/* Variables and functions */
int /*<<< orphan*/ die(char *, char const *, int, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
scalar_t__ sigaction(int, struct sigaction *, int /*<<< orphan*/ *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
void safe_sigaction(const char *name, int signum, struct sigaction *sa) {
  if (sigaction(signum, sa, NULL) < 0) {
    die("could not set handler for signal %s (%i): %s\n", name, signum,
        (strerror(errno)));
  }
}


x86 assembly (clang, -O0):
<safe_sigaction>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
cmp    $0x0,%rax
jge    118e <safe_sigaction+0x5e>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    %eax,%ecx
lea    0xe77(%rip),%rdi
call   1040 <die@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<safe_sigaction>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
mov    %esi,%edi
mov    %rdx,%rsi
xor    %edx,%edx
call   1030 <sigaction@plt>
test   %rax,%rax
js     1152 <safe_sigaction+0x22>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e87(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe99(%rip),%rdi
mov    %r14,%rsi
mov    %ebx,%edx
mov    %eax,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <die@plt>

LLVM IR (-O0):
%struct.sigaction = type { i32 }
@.str = [46 x i8] c"could not set handler for signal %s (%i): %s\0A\00"
@errno = global i32 0
define void @safe_sigaction(i8* %0, i32 %1, %struct.sigaction* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca %struct.sigaction*
store i8* %0, i8** %4
store i32 %1, i32* %5
store %struct.sigaction* %2, %struct.sigaction** %6
%7 = load i32, i32* %5
%8 = load %struct.sigaction*, %struct.sigaction** %6
%9 = call i64 @sigaction(i32 %7, %struct.sigaction* %8, i32* null)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %3
%12 = load i8*, i8** %4
%13 = load i32, i32* %5
%14 = load i32, i32* @errno
%15 = call i32 @strerror(i32 %14)
%16 = call i32 @die(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* %12, i32 %13, i32 %15)
br label %17
17: ; preds = %11, %3
ret void
}

LLVM IR (-O2):
%struct.sigaction = type { i32 }
@.str = [46 x i8] c"could not set handler for signal %s (%i): %s\0A\00"
@errno = global i32 0
define void @safe_sigaction(i8* %0, i32 %1, %struct.sigaction* %2) {
%4 = tail call i64 @sigaction(i32 %1, %struct.sigaction* %2, i32* null)
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %3
%7 = load i32, i32* @errno
%8 = tail call i32 @strerror(i32 %7)
%9 = tail call i32 @die(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %1, i32 %8)
br label %10
10: ; preds = %6, %3
ret void
}