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

/* Variables and functions */
int SA_RESTART;
int SA_SIGINFO;
int /*<<< orphan*/ sigaction(int, struct sigaction *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sigfillset(int /*<<< orphan*/ *);
void register_handler(int sig, void *handler) {
  struct sigaction sa;
  sa.sa_flags = SA_RESTART | SA_SIGINFO;
  sigfillset(&sa.sa_mask);
  sa.sa_sigaction = handler;
  sigaction(sig, &sa, NULL);
}


x86 assembly (clang, -O0):
<register_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2eb2(%rip),%rax
mov    (%rax),%eax
mov    0x2e99(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x28(%rbp)
lea    -0x28(%rbp),%rdi
add    $0x10,%rdi
call   1040 <sigfillset@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x28(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<register_handler>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2eb6(%rip),%rax
mov    0x2e9f(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    %ecx,(%rsp)
lea    0x10(%rsp),%rdi
call   1040 <sigfillset@plt>
mov    %rbx,0x8(%rsp)
mov    %rsp,%rsi
mov    %ebp,%edi
xor    %edx,%edx
call   1030 <sigaction@plt>
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.sigaction = type { i32, i8*, i32 }
@SA_RESTART = global i32 0
@SA_SIGINFO = global i32 0
define void @register_handler(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.sigaction
store i32 %0, i32* %3
store i8* %1, i8** %4
%6 = load i32, i32* @SA_RESTART
%7 = load i32, i32* @SA_SIGINFO
%8 = or i32 %6, %7
%9 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %5, i32 0, i32 0
store i32 %8, i32* %9
%10 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %5, i32 0, i32 2
%11 = call i32 @sigfillset(i32* %10)
%12 = load i8*, i8** %4
%13 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %5, i32 0, i32 1
store i8* %12, i8** %13
%14 = load i32, i32* %3
%15 = call i32 @sigaction(i32 %14, %struct.sigaction* %5, i32* null)
ret void
}

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