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

/* Variables and functions */
int /*<<< orphan*/ SIG_SETMASK;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
scalar_t__ sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *,
                       int /*<<< orphan*/ *);
void ignore_signal(int sig) {
  sigset_t newmask;
  sigemptyset(&newmask);
  if (sig) {
    sigaddset(&newmask, sig);
  }
  do {
    if (sigprocmask(SIG_SETMASK, &newmask, NULL) < 0) {
      perror("sigprocmask(SIG_SETMASK, &newmask, NULL) < 0");
      exit(1);
    }
  } while (0);
}


x86 assembly (clang, -O0):
<ignore_signal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
call   1040 <sigemptyset@plt>
cmpl   $0x0,-0x4(%rbp)
je     117a <ignore_signal+0x2a>
mov    -0x4(%rbp),%esi
lea    -0x8(%rbp),%rdi
call   1070 <sigaddset@plt>
jmp    117f <ignore_signal+0x2f>
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
cmp    $0x0,%rax
jge    11b5 <ignore_signal+0x65>
lea    0xe5a(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    11ba <ignore_signal+0x6a>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ignore_signal>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0xc(%rsp),%rdi
call   1040 <sigemptyset@plt>
test   %ebx,%ebx
je     1171 <ignore_signal+0x21>
lea    0xc(%rsp),%rdi
mov    %ebx,%esi
call   1070 <sigaddset@plt>
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
lea    0xc(%rsp),%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
test   %rax,%rax
js     1191 <ignore_signal+0x41>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe68(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@SIG_SETMASK = global i32 0
@.str = [45 x i8] c"sigprocmask(SIG_SETMASK, &newmask, NULL) < 0\00"
define void @ignore_signal(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = call i32 @sigemptyset(i32* %3)
%5 = load i32, i32* %2
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load i32, i32* %2
%9 = call i32 @sigaddset(i32* %3, i32 %8)
br label %10
10: ; preds = %7, %1
br label %11
11: ; preds = %10
%12 = load i32, i32* @SIG_SETMASK
%13 = call i64 @sigprocmask(i32 %12, i32* %3, i32* null)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = call i32 @perror(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %11
br label %19
19: ; preds = %18
ret void
}

LLVM IR (-O2):
@SIG_SETMASK = global i32 0
@.str = [45 x i8] c"sigprocmask(SIG_SETMASK, &newmask, NULL) < 0\00"
define void @ignore_signal(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = call i32 @sigemptyset(i32* %2)
%5 = icmp eq i32 %0, 0
br i1 %5, label %8, label %6
6: ; preds = %1
%7 = call i32 @sigaddset(i32* %2, i32 %0)
br label %8
8: ; preds = %1, %6
%9 = load i32, i32* @SIG_SETMASK
%10 = call i64 @sigprocmask(i32 %9, i32* %2, i32* null)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = call i32 @perror(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %8
ret void
}