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

/* Variables and functions */
scalar_t__ SIG_IGN;
int /*<<< orphan*/ err(int, char *);
int /*<<< orphan*/ memset(struct sigaction *, int /*<<< orphan*/, int);
scalar_t__ sigaction(int, struct sigaction *, int /*<<< orphan*/);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
void setsigign(int sig, int flags) {
  struct sigaction sa;
  memset(&sa, 0, sizeof(sa));
  sa.sa_sigaction = (void *)SIG_IGN;
  sa.sa_flags = flags;
  sigemptyset(&sa.sa_mask);
  if (sigaction(sig, &sa, 0))
    err(1, "sigaction");
}


x86 assembly (clang, -O0):
<setsigign>:
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>
mov    0x2e83(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
lea    -0x18(%rbp),%rdi
add    $0x4,%rdi
call   1050 <sigemptyset@plt>
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1030 <sigaction@plt>
cmp    $0x0,%rax
je     11a8 <setsigign+0x68>
mov    $0x1,%edi
lea    0xe5d(%rip),%rsi
call   1060 <err@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setsigign>:
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>
mov    0x2e83(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x8(%rsp)
mov    %ebx,(%rsp)
lea    0x4(%rsp),%rdi
call   1050 <sigemptyset@plt>
mov    %ebp,%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1030 <sigaction@plt>
test   %rax,%rax
je     119c <setsigign+0x5c>
lea    0xe6e(%rip),%rsi
mov    $0x1,%edi
call   1060 <err@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sigaction = type { i32, i32, i8* }
@SIG_IGN = global i64 0
@.str = [10 x i8] c"sigaction\00"
define void @setsigign(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 = load i64, i64* @SIG_IGN
%8 = inttoptr i64 %7 to i8*
%9 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %5, i32 0, i32 2
store i8* %8, i8** %9
%10 = load i32, i32* %4
%11 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %5, i32 0, i32 0
store i32 %10, i32* %11
%12 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %5, i32 0, i32 1
%13 = call i32 @sigemptyset(i32* %12)
%14 = load i32, i32* %3
%15 = call i64 @sigaction(i32 %14, %struct.sigaction* %5, i32 0)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 @err(i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %2
ret void
}

LLVM IR (-O2):
%struct.sigaction = type { i32, i32, i8* }
@SIG_IGN = global i64 0
@.str = [10 x i8] c"sigaction\00"
define void @setsigign(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 = load i64, i64* @SIG_IGN
%7 = inttoptr i64 %6 to i8*
%8 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 2
store i8* %7, i8** %8
%9 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 0
store i32 %1, i32* %9
%10 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 1
%11 = call i32 @sigemptyset(i32* %10)
%12 = call i64 @sigaction(i32 %0, %struct.sigaction* %3, i32 0)
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %2
%15 = call i32 @err(i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %2
ret void
}