#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*/ SIGCHLD;
int /*<<< orphan*/ SIG_BLOCK;
scalar_t__ sigaddset(int /*<<< orphan*/ *, int /*<<< orphan*/);
scalar_t__ sigemptyset(int /*<<< orphan*/ *);
scalar_t__ sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *,
                       int /*<<< orphan*/ *);
int /*<<< orphan*/ unix_fatal(char *);
void block_sig(sigset_t *mask) {
  if (sigemptyset(mask) < 0) {
    unix_fatal("sigemptyset error");
  }
  if (sigaddset(mask, SIGCHLD) < 0) {
    unix_fatal("sigadset error");
  }
  if (sigprocmask(SIG_BLOCK, mask, NULL) < 0) {
    unix_fatal("sigprocmask error");
  }
}


x86 assembly (clang, -O0):
<block_sig>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <sigemptyset@plt>
cmp    $0x0,%rax
jge    116b <block_sig+0x2b>
lea    0xe9a(%rip),%rdi
call   1030 <unix_fatal@plt>
mov    -0x8(%rbp),%rdi
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
call   1060 <sigaddset@plt>
cmp    $0x0,%rax
jge    1193 <block_sig+0x53>
lea    0xe84(%rip),%rdi
call   1030 <unix_fatal@plt>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <sigprocmask@plt>
cmp    $0x0,%rax
jge    11bf <block_sig+0x7f>
lea    0xe67(%rip),%rdi
call   1030 <unix_fatal@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<block_sig>:
push   %rbx
mov    %rdi,%rbx
call   1050 <sigemptyset@plt>
test   %rax,%rax
jns    115a <block_sig+0x1a>
lea    0xeab(%rip),%rdi
call   1030 <unix_fatal@plt>
mov    0x2e87(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <sigaddset@plt>
test   %rax,%rax
jns    117c <block_sig+0x3c>
lea    0xe9b(%rip),%rdi
call   1030 <unix_fatal@plt>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1040 <sigprocmask@plt>
test   %rax,%rax
js     1196 <block_sig+0x56>
pop    %rbx
ret
lea    0xe84(%rip),%rdi
pop    %rbx
jmp    1030 <unix_fatal@plt>

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

LLVM IR (-O2):
@.str = [18 x i8] c"sigemptyset error\00"
@SIGCHLD = global i32 0
@.str.1 = [15 x i8] c"sigadset error\00"
@SIG_BLOCK = global i32 0
@.str.2 = [18 x i8] c"sigprocmask error\00"
define void @block_sig(i32* %0) {
%2 = tail call i64 @sigemptyset(i32* %0)
%3 = icmp slt i64 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @unix_fatal(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %4, %1
%7 = load i32, i32* @SIGCHLD
%8 = tail call i64 @sigaddset(i32* %0, i32 %7)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = tail call i32 @unix_fatal(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %6
%13 = load i32, i32* @SIG_BLOCK
%14 = tail call i64 @sigprocmask(i32 %13, i32* %0, i32* null)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = tail call i32 @unix_fatal(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %16, %12
ret void
}