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

/* Variables and functions */
scalar_t__ sigaction(int, struct sigaction *, int /*<<< orphan*/ *);
scalar_t__ sigemptyset(int /*<<< orphan*/ *);
int install_signal_handler(int signo, void (*func)(int)) {
  struct sigaction action;
  action.sa_handler = func;
  action.sa_flags = 0;
  if (sigemptyset(&action.sa_mask) < 0 || sigaction(signo, &action, NULL) < 0) {
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<install_signal_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x18(%rbp)
lea    -0x28(%rbp),%rdi
add    $0x8,%rdi
call   1040 <sigemptyset@plt>
cmp    $0x0,%rax
jl     1170 <install_signal_handler+0x50>
mov    -0x8(%rbp),%edi
lea    -0x28(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
cmp    $0x0,%rax
jge    117c <install_signal_handler+0x5c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1183 <install_signal_handler+0x63>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<install_signal_handler>:
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebx
mov    %rsi,0x8(%rsp)
movq   $0x0,0x18(%rsp)
lea    0x10(%rsp),%rdi
call   1040 <sigemptyset@plt>
test   %rax,%rax
js     1158 <install_signal_handler+0x38>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
xor    %edx,%edx
call   1030 <sigaction@plt>
sar    $0x3f,%rax
jmp    115d <install_signal_handler+0x3d>
mov    $0xffffffff,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sigaction = type { void (i32)*, i32, i64 }
define i32 @install_signal_handler(i32 %0, void (i32)* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca void (i32)*
%6 = alloca %struct.sigaction
store i32 %0, i32* %4
store void (i32)* %1, void (i32)** %5
%7 = load void (i32)*, void (i32)** %5
%8 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %6, i32 0, i32 0
store void (i32)* %7, void (i32)** %8
%9 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %6, i32 0, i32 2
store i64 0, i64* %9
%10 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %6, i32 0, i32 1
%11 = call i64 @sigemptyset(i32* %10)
%12 = icmp slt i64 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %2
%14 = load i32, i32* %4
%15 = call i64 @sigaction(i32 %14, %struct.sigaction* %6, i32* null)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13, %2
store i32 -1, i32* %3
br label %19
18: ; preds = %13
store i32 0, i32* %3
br label %19
19: ; preds = %18, %17
%20 = load i32, i32* %3
ret i32 %20
}

LLVM IR (-O2):
%struct.sigaction = type { void (i32)*, i32, i64 }
define i32 @install_signal_handler(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 0
store void (i32)* %1, void (i32)** %5
%6 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 2
store i64 0, i64* %6
%7 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 1
%8 = call i64 @sigemptyset(i32* %7)
%9 = icmp slt i64 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %2
%11 = call i64 @sigaction(i32 %0, %struct.sigaction* %3, i32* null)
%12 = ashr i64 %11, 63
%13 = trunc i64 %12 to i32
br label %14
14: ; preds = %10, %2
%15 = phi i32 [ -1, %2 ], [ %13, %10 ]
ret i32 %15
}