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

/* Variables and functions */
int /*<<< orphan*/ SA_NODEFER;
int /*<<< orphan*/ SIGUSR1;
int /*<<< orphan*/ sigaction(int /*<<< orphan*/, struct sigaction *,
                             int /*<<< orphan*/ *);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
void register_signal_handler(void (*handler)(int)) {
  struct sigaction act;
  act.sa_handler = handler;
  act.sa_flags = SA_NODEFER;
  sigemptyset(&act.sa_mask);
  sigaction(SIGUSR1, &act, NULL);
}


x86 assembly (clang, -O0):
<register_signal_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e9d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
lea    -0x18(%rbp),%rdi
add    $0x8,%rdi
call   1040 <sigemptyset@plt>
mov    0x2e94(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<register_signal_handler>:
sub    $0x18,%rsp
mov    %rdi,0x8(%rsp)
mov    0x2ea8(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
lea    0x10(%rsp),%rdi
call   1040 <sigemptyset@plt>
mov    0x2ea1(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1030 <sigaction@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.sigaction = type { void (i32)*, i32, i32 }
@SA_NODEFER = global i32 0
@SIGUSR1 = global i32 0
define void @register_signal_handler(void (i32)* %0) {
%2 = alloca void (i32)*
%3 = alloca %struct.sigaction
store void (i32)* %0, void (i32)** %2
%4 = load void (i32)*, void (i32)** %2
%5 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i32 0, i32 0
store void (i32)* %4, void (i32)** %5
%6 = load i32, i32* @SA_NODEFER
%7 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i32 0, i32 2
store i32 %6, i32* %7
%8 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i32 0, i32 1
%9 = call i32 @sigemptyset(i32* %8)
%10 = load i32, i32* @SIGUSR1
%11 = call i32 @sigaction(i32 %10, %struct.sigaction* %3, i32* null)
ret void
}

LLVM IR (-O2):
%struct.sigaction = type { void (i32)*, i32, i32 }
@SA_NODEFER = global i32 0
@SIGUSR1 = global i32 0
define void @register_signal_handler(void (i32)* %0) {
%2 = alloca %struct.sigaction
%3 = bitcast %struct.sigaction* %2 to i8*
%4 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %2, i64 0, i32 0
store void (i32)* %0, void (i32)** %4
%5 = load i32, i32* @SA_NODEFER
%6 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %2, i64 0, i32 2
store i32 %5, i32* %6
%7 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %2, i64 0, i32 1
%8 = call i32 @sigemptyset(i32* %7)
%9 = load i32, i32* @SIGUSR1
%10 = call i32 @sigaction(i32 %9, %struct.sigaction* %2, i32* null)
ret void
}