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

/* Variables and functions */
int /*<<< orphan*/ SA_RESTART;
scalar_t__ sigaction(int, struct sigaction *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int signalsetup(int signum, void *sigact) {
  struct sigaction snu;
  sigemptyset(&snu.sa_mask);
  snu.sa_flags = SA_RESTART;
  snu.sa_sigaction = sigact;
  if (sigaction(signum, &snu, NULL))
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<signalsetup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
add    $0xc,%rdi
call   1040 <sigemptyset@plt>
mov    0x2ea5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
cmp    $0x0,%rax
je     1176 <signalsetup+0x56>
movl   $0xffffffff,-0x4(%rbp)
jmp    117d <signalsetup+0x5d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<signalsetup>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0x14(%rsp),%rdi
call   1040 <sigemptyset@plt>
mov    0x2eac(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    %rbx,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
xor    %edx,%edx
call   1030 <sigaction@plt>
neg    %rax
sbb    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.sigaction = type { i8*, i32, i32 }
@SA_RESTART = global i32 0
define i32 @signalsetup(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca %struct.sigaction
store i32 %0, i32* %4
store i8* %1, i8** %5
%7 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %6, i32 0, i32 2
%8 = call i32 @sigemptyset(i32* %7)
%9 = load i32, i32* @SA_RESTART
%10 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %6, i32 0, i32 1
store i32 %9, i32* %10
%11 = load i8*, i8** %5
%12 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %6, i32 0, i32 0
store i8* %11, i8** %12
%13 = load i32, i32* %4
%14 = call i64 @sigaction(i32 %13, %struct.sigaction* %6, i32* null)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %2
store i32 -1, i32* %3
br label %18
17: ; preds = %2
store i32 0, i32* %3
br label %18
18: ; preds = %17, %16
%19 = load i32, i32* %3
ret i32 %19
}

LLVM IR (-O2):
%struct.sigaction = type { i8*, i32, i32 }
@SA_RESTART = global i32 0
define i32 @signalsetup(i32 %0, i8* %1) {
%3 = alloca %struct.sigaction
%4 = bitcast %struct.sigaction* %3 to i8*
%5 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 2
%6 = call i32 @sigemptyset(i32* %5)
%7 = load i32, i32* @SA_RESTART
%8 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 1
store i32 %7, i32* %8
%9 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 0
store i8* %1, i8** %9
%10 = call i64 @sigaction(i32 %0, %struct.sigaction* %3, i32* null)
%11 = icmp ne i64 %10, 0
%12 = sext i1 %11 to i32
ret i32 %12
}