#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 */
int sigaction(int, struct sigaction *, int /*<<< orphan*/ *);
int sigfillset(int /*<<< orphan*/ *);
int setHandler(void (*handler)(int), int signum) {
  struct sigaction s;
  int retfunct;
  s.sa_handler = handler;
  s.sa_flags = 0;
  retfunct = sigfillset(&s.sa_mask);
  if (retfunct == 0)
    retfunct = sigaction(signum, &s, NULL);
  return retfunct;
}


x86 assembly (clang, -O0):
<setHandler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x18(%rbp)
lea    -0x28(%rbp),%rdi
add    $0x8,%rdi
call   1040 <sigfillset@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    116c <setHandler+0x4c>
mov    -0xc(%rbp),%edi
lea    -0x28(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setHandler>:
push   %rbx
sub    $0x20,%rsp
mov    %esi,%ebx
mov    %rdi,0x8(%rsp)
movq   $0x0,0x18(%rsp)
lea    0x10(%rsp),%rdi
call   1040 <sigfillset@plt>
test   %eax,%eax
jne    1151 <setHandler+0x31>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
xor    %edx,%edx
call   1030 <sigaction@plt>
add    $0x20,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
%struct.sigaction = type { void (i32)*, i32, i64 }
define i32 @setHandler(void (i32)* %0, 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)* %0, 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 i32 @sigfillset(i32* %7)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @sigaction(i32 %1, %struct.sigaction* %3, i32* null)
br label %12
12: ; preds = %10, %2
%13 = phi i32 [ %11, %10 ], [ %8, %2 ]
ret i32 %13
}