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

/* Variables and functions */
scalar_t__ sigaction(int, struct sigaction *, struct sigaction *);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int /*<<< orphan*/ zfatal(char *);
void zsignal(int signum, void (*handler)(int)) {
  struct sigaction action;
  sigemptyset(&action.sa_mask);
  action.sa_flags = 0;
  action.sa_handler = handler;
  if (sigaction(signum, &action, (struct sigaction *)0) < 0) {
    zfatal("FATAL sigaction: %m");
  }
}


x86 assembly (clang, -O0):
<zsignal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x28(%rbp),%rdi
add    $0x10,%rdi
call   1050 <sigemptyset@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x28(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <sigaction@plt>
cmp    $0x0,%rax
jge    1182 <zsignal+0x52>
lea    0xe83(%rip),%rdi
call   1030 <zfatal@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zsignal>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0x10(%rsp),%rdi
call   1050 <sigemptyset@plt>
movq   $0x0,0x8(%rsp)
mov    %rbx,(%rsp)
mov    %rsp,%rsi
mov    %ebp,%edi
xor    %edx,%edx
call   1040 <sigaction@plt>
test   %rax,%rax
jns    116f <zsignal+0x3f>
lea    0xe96(%rip),%rdi
call   1030 <zfatal@plt>
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.sigaction = type { void (i32)*, i64, i32 }
@.str = [20 x i8] c"FATAL sigaction: %m\00"
define void @zsignal(i32 %0, void (i32)* %1) {
%3 = alloca i32
%4 = alloca void (i32)*
%5 = alloca %struct.sigaction
store i32 %0, i32* %3
store void (i32)* %1, void (i32)** %4
%6 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %5, i32 0, i32 2
%7 = call i32 @sigemptyset(i32* %6)
%8 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %5, i32 0, i32 1
store i64 0, i64* %8
%9 = load void (i32)*, void (i32)** %4
%10 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %5, i32 0, i32 0
store void (i32)* %9, void (i32)** %10
%11 = load i32, i32* %3
%12 = call i64 @sigaction(i32 %11, %struct.sigaction* %5, %struct.sigaction* null)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @zfatal(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %2
ret void
}

LLVM IR (-O2):
%struct.sigaction = type { void (i32)*, i64, i32 }
@.str = [20 x i8] c"FATAL sigaction: %m\00"
define void @zsignal(i32 %0, void (i32)* %1) {
%3 = alloca %struct.sigaction
%4 = bitcast %struct.sigaction* %3 to i8*
%5 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 2
%6 = call i32 @sigemptyset(i32* %5)
%7 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 1
store i64 0, i64* %7
%8 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 0
store void (i32)* %1, void (i32)** %8
%9 = call i64 @sigaction(i32 %0, %struct.sigaction* %3, %struct.sigaction* null)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @zfatal(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %2
ret void
}