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

/* Variables and functions */
int sigaction(int, struct sigaction *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int _eggx_signal(int signum, int sa__flags, void (*sa__handler)(int)) {
  struct sigaction sa;
  sigset_t sm;
  sigemptyset(&sm);
  sigaddset(&sm, signum);
  sa.sa_handler = sa__handler;
  sa.sa_mask = sm;
  sa.sa_flags = sa__flags;
  return (sigaction(signum, &sa, NULL));
}


x86 assembly (clang, -O0):
<_eggx_signal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
lea    -0x24(%rbp),%rdi
call   1040 <sigemptyset@plt>
mov    -0x4(%rbp),%esi
lea    -0x24(%rbp),%rdi
call   1050 <sigaddset@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_eggx_signal>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%rbx
mov    %esi,%r14d
mov    %edi,%ebp
lea    0x4(%rsp),%r15
mov    %r15,%rdi
call   1040 <sigemptyset@plt>
mov    %r15,%rdi
mov    %ebp,%esi
call   1050 <sigaddset@plt>
mov    %rbx,0x8(%rsp)
mov    0x4(%rsp),%eax
mov    %eax,0x14(%rsp)
mov    %r14d,0x10(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
xor    %edx,%edx
call   1030 <sigaction@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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