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

/* Variables and functions */
scalar_t__ sigaction(int, struct sigaction *, struct sigaction *);
scalar_t__ sigemptyset(int /*<<< orphan*/ *);
int stonith_signal_set_simple_handler(int sig, void (*handler)(int),
                                      struct sigaction *oldact) {
  struct sigaction sa;
  sigset_t mask;
  (void)stonith_signal_set_simple_handler;
  if (sigemptyset(&mask) < 0) {
    return (-1);
  }
  sa.sa_handler = handler;
  sa.sa_mask = mask;
  sa.sa_flags = 0;
  if (sigaction(sig, &sa, oldact) < 0) {
    return (-1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<stonith_signal_set_simple_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x34(%rbp),%rdi
call   1040 <sigemptyset@plt>
cmp    $0x0,%rax
jge    1152 <stonith_signal_set_simple_handler+0x32>
movl   $0xffffffff,-0x4(%rbp)
jmp    1195 <stonith_signal_set_simple_handler+0x75>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rdx
lea    -0x30(%rbp),%rsi
call   1030 <sigaction@plt>
cmp    $0x0,%rax
jge    118e <stonith_signal_set_simple_handler+0x6e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1195 <stonith_signal_set_simple_handler+0x75>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stonith_signal_set_simple_handler>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0x4(%rsp),%rdi
call   1040 <sigemptyset@plt>
test   %rax,%rax
js     116a <stonith_signal_set_simple_handler+0x4a>
mov    %rbx,0x8(%rsp)
mov    0x4(%rsp),%eax
mov    %eax,0x18(%rsp)
movq   $0x0,0x10(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    %r14,%rdx
call   1030 <sigaction@plt>
sar    $0x3f,%rax
jmp    116f <stonith_signal_set_simple_handler+0x4f>
mov    $0xffffffff,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.sigaction = type { void (i32)*, i64, i32 }
define i32 @stonith_signal_set_simple_handler(i32 %0, void (i32)* %1, %struct.sigaction* %2) {
%4 = alloca %struct.sigaction
%5 = alloca i32
%6 = bitcast %struct.sigaction* %4 to i8*
%7 = bitcast i32* %5 to i8*
%8 = call i64 @sigemptyset(i32* %5)
%9 = icmp slt i64 %8, 0
br i1 %9, label %18, label %10
10: ; preds = %3
%11 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %4, i64 0, i32 0
store void (i32)* %1, void (i32)** %11
%12 = load i32, i32* %5
%13 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %4, i64 0, i32 2
store i32 %12, i32* %13
%14 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %4, i64 0, i32 1
store i64 0, i64* %14
%15 = call i64 @sigaction(i32 %0, %struct.sigaction* %4, %struct.sigaction* %2)
%16 = ashr i64 %15, 63
%17 = trunc i64 %16 to i32
br label %18
18: ; preds = %10, %3
%19 = phi i32 [ -1, %3 ], [ %17, %10 ]
ret i32 %19
}