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

/* Variables and functions */
int /*<<< orphan*/ SA_RESTART;
int SIGALRM;
int /*<<< orphan*/ err_sys(char *);
int /*<<< orphan*/ memset(struct sigaction *, char, int);
scalar_t__ sigaction(int, struct sigaction *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
void vn_signal(int signum, void (*handler)(int)) {
  struct sigaction sa;
  memset(&sa, '\0', sizeof(struct sigaction));
  sa.sa_handler = handler;
  sigemptyset(&sa.sa_mask);
  if (signum == SIGALRM) {
  } else {
    sa.sa_flags |= SA_RESTART;
  }
  if (sigaction(signum, &sa, NULL) < 0) {
    err_sys("[vn_signal] sigaction error");
  }
}


x86 assembly (clang, -O0):
<vn_signal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    -0x20(%rbp),%rdi
add    $0xc,%rdi
call   1060 <sigemptyset@plt>
mov    -0x4(%rbp),%eax
mov    0x2e6a(%rip),%rcx
cmp    (%rcx),%eax
jne    118b <vn_signal+0x4b>
jmp    119a <vn_signal+0x5a>
mov    0x2e4e(%rip),%rax
mov    (%rax),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
cmp    $0x0,%rax
jge    11c0 <vn_signal+0x80>
lea    0xe45(%rip),%rdi
call   1040 <err_sys@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vn_signal>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
mov    %r14,0x8(%rsp)
lea    0x14(%rsp),%rdi
call   1060 <sigemptyset@plt>
mov    0x2e75(%rip),%rax
cmp    %ebx,(%rax)
je     1184 <vn_signal+0x44>
mov    0x2e62(%rip),%rax
mov    (%rax),%eax
or     %eax,0x10(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
xor    %edx,%edx
call   1030 <sigaction@plt>
test   %rax,%rax
jns    11a3 <vn_signal+0x63>
lea    0xe62(%rip),%rdi
call   1040 <err_sys@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sigaction = type { void (i32)*, i32, i32 }
@SIGALRM = global i32 0
@SA_RESTART = global i32 0
@.str = [28 x i8] c"[vn_signal] sigaction error\00"
define void @vn_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 = call i32 @memset(%struct.sigaction* %5, i8 signext 0, i32 16)
%7 = load void (i32)*, void (i32)** %4
%8 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %5, i32 0, i32 0
store void (i32)* %7, void (i32)** %8
%9 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %5, i32 0, i32 2
%10 = call i32 @sigemptyset(i32* %9)
%11 = load i32, i32* %3
%12 = load i32, i32* @SIGALRM
%13 = icmp eq i32 %11, %12
br i1 %13, label %14, label %15
14: ; preds = %2
br label %20
15: ; preds = %2
%16 = load i32, i32* @SA_RESTART
%17 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %5, i32 0, i32 1
%18 = load i32, i32* %17
%19 = or i32 %18, %16
store i32 %19, i32* %17
br label %20
20: ; preds = %15, %14
%21 = load i32, i32* %3
%22 = call i64 @sigaction(i32 %21, %struct.sigaction* %5, i32* null)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = call i32 @err_sys(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %26
26: ; preds = %24, %20
ret void
}

LLVM IR (-O2):
%struct.sigaction = type { void (i32)*, i32, i32 }
@SIGALRM = global i32 0
@SA_RESTART = global i32 0
@.str = [28 x i8] c"[vn_signal] sigaction error\00"
define void @vn_signal(i32 %0, void (i32)* %1) {
%3 = alloca %struct.sigaction
%4 = bitcast %struct.sigaction* %3 to i8*
%5 = call i32 @memset(%struct.sigaction* %3, i8 signext 0, i32 16)
%6 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 0
store void (i32)* %1, void (i32)** %6
%7 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 2
%8 = call i32 @sigemptyset(i32* %7)
%9 = load i32, i32* @SIGALRM
%10 = icmp eq i32 %9, %0
br i1 %10, label %16, label %11
11: ; preds = %2
%12 = load i32, i32* @SA_RESTART
%13 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 1
%14 = load i32, i32* %13
%15 = or i32 %14, %12
store i32 %15, i32* %13
br label %16
16: ; preds = %2, %11
%17 = call i64 @sigaction(i32 %0, %struct.sigaction* %3, i32* null)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i32 @err_sys(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %19, %16
ret void
}