#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_BLOCK;
int /*<<< orphan*/ SIG_UNBLOCK;
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 block_signal(int sig, int block_it) {
  sigset_t ss;
  sigemptyset(&ss);
  sigaddset(&ss, sig);
  if (sigprocmask(block_it ? SIG_BLOCK : SIG_UNBLOCK, &ss, 0) < 0) {
    perror("sigprocmask");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<block_signal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    -0xc(%rbp),%rdi
call   1040 <sigemptyset@plt>
mov    -0x4(%rbp),%esi
lea    -0xc(%rbp),%rdi
call   1070 <sigaddset@plt>
cmpl   $0x0,-0x8(%rbp)
je     118e <block_signal+0x3e>
mov    0x2e54(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
jmp    119a <block_signal+0x4a>
mov    0x2e53(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
lea    -0xc(%rbp),%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
cmp    $0x0,%rax
jge    11c8 <block_signal+0x78>
lea    0xe47(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<block_signal>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %edi,%ebx
lea    0xc(%rsp),%r14
mov    %r14,%rdi
call   1040 <sigemptyset@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1070 <sigaddset@plt>
test   %ebp,%ebp
jne    1180 <block_signal+0x30>
mov    0x2e6a(%rip),%rax
jmp    1187 <block_signal+0x37>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
test   %rax,%rax
js     11a1 <block_signal+0x51>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe58(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

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

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