#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;
};

/* Variables and functions */
int /*<<< orphan*/ sigaction(int, struct sigaction *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
void set_signal(int signo, void (*func)(int signo)) {
  struct sigaction act;
  act.sa_handler = func;
  sigemptyset(&act.sa_mask);
  sigaddset(&act.sa_mask, signo);
  act.sa_flags = 0;
  sigaction(signo, &act, NULL);
}


x86 assembly (clang, -O0):
<set_signal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x28(%rbp),%rdi
add    $0x10,%rdi
call   1040 <sigemptyset@plt>
lea    -0x28(%rbp),%rdi
add    $0x10,%rdi
mov    -0x4(%rbp),%esi
call   1050 <sigaddset@plt>
movq   $0x0,-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):
<set_signal>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
mov    %rsi,(%rsp)
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1040 <sigemptyset@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1050 <sigaddset@plt>
movq   $0x0,0x8(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
xor    %edx,%edx
call   1030 <sigaction@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sigaction = type { void (i32)*, i64, i32 }
define void @set_signal(i32 %0, void (i32)* %1) {
%3 = alloca i32
%4 = alloca void (i32)*
%5 = alloca %struct.sigaction
store i32 %0, i32* %3
store void (i32)* %1, void (i32)** %4
%6 = load void (i32)*, void (i32)** %4
%7 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %5, i32 0, i32 0
store void (i32)* %6, void (i32)** %7
%8 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %5, i32 0, i32 2
%9 = call i32 @sigemptyset(i32* %8)
%10 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %5, i32 0, i32 2
%11 = load i32, i32* %3
%12 = call i32 @sigaddset(i32* %10, i32 %11)
%13 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %5, i32 0, i32 1
store i64 0, i64* %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 { void (i32)*, i64, i32 }
define void @set_signal(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
%7 = call i32 @sigemptyset(i32* %6)
%8 = call i32 @sigaddset(i32* %6, i32 %0)
%9 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 1
store i64 0, i64* %9
%10 = call i32 @sigaction(i32 %0, %struct.sigaction* %3, i32* null)
ret void
}