#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 /*<<< orphan*/ sa_handler;
  int /*<<< orphan*/ sa_mask;
  scalar_t__ sa_flags;
};
typedef int /*<<< orphan*/ sig_t;
typedef int /*<<< orphan*/ act;

/* Variables and functions */
int /*<<< orphan*/ memset(struct sigaction *, int /*<<< orphan*/, int);
int sigaction(int, struct sigaction *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int set_signal(int sig, sig_t func) {
  struct sigaction act;
  memset(&act, 0, sizeof(act));
  act.sa_flags = 0;
  sigemptyset(&act.sa_mask);
  act.sa_handler = func;
  return sigaction(sig, &act, NULL);
}


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

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

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