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

/* Variables and functions */
int /*<<< orphan*/ sigaction(int, struct sigaction *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
void setsig(struct sigaction *sa, int sig, void (*fun)(int), int flags) {
  sa->sa_handler = fun;
  sa->sa_flags = flags;
  sigemptyset(&sa->sa_mask);
  sigaction(sig, sa, NULL);
}


x86 assembly (clang, -O0):
<setsig>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x1c(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x8(%rbp),%rdi
add    $0xc,%rdi
call   1040 <sigemptyset@plt>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setsig>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %rdx,(%rdi)
mov    %ecx,0x8(%rdi)
add    $0xc,%rdi
call   1040 <sigemptyset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %edx,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <sigaction@plt>

LLVM IR (-O0):
%struct.sigaction = type { void (i32)*, i32, i32 }
define void @setsig(%struct.sigaction* %0, i32 %1, void (i32)* %2, i32 %3) {
%5 = alloca %struct.sigaction*
%6 = alloca i32
%7 = alloca void (i32)*
%8 = alloca i32
store %struct.sigaction* %0, %struct.sigaction** %5
store i32 %1, i32* %6
store void (i32)* %2, void (i32)** %7
store i32 %3, i32* %8
%9 = load void (i32)*, void (i32)** %7
%10 = load %struct.sigaction*, %struct.sigaction** %5
%11 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %10, i32 0, i32 0
store void (i32)* %9, void (i32)** %11
%12 = load i32, i32* %8
%13 = load %struct.sigaction*, %struct.sigaction** %5
%14 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %13, i32 0, i32 1
store i32 %12, i32* %14
%15 = load %struct.sigaction*, %struct.sigaction** %5
%16 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %15, i32 0, i32 2
%17 = call i32 @sigemptyset(i32* %16)
%18 = load i32, i32* %6
%19 = load %struct.sigaction*, %struct.sigaction** %5
%20 = call i32 @sigaction(i32 %18, %struct.sigaction* %19, i32* null)
ret void
}

LLVM IR (-O2):
%struct.sigaction = type { void (i32)*, i32, i32 }
define void @setsig(%struct.sigaction* %0, i32 %1, void (i32)* %2, i32 %3) {
%5 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %0, i64 0, i32 0
store void (i32)* %2, void (i32)** %5
%6 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %0, i64 0, i32 1
store i32 %3, i32* %6
%7 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %0, i64 0, i32 2
%8 = tail call i32 @sigemptyset(i32* %7)
%9 = tail call i32 @sigaction(i32 %1, %struct.sigaction* %0, i32* null)
ret void
}