#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 SIG_BLOCK;
int SIG_UNBLOCK;
int sigaddset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int sigemptyset(int /*<<< orphan*/ *);
int sigprocmask(int const, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int set_sigchld(int block) {
  const int action = block ? SIG_BLOCK : SIG_UNBLOCK;
  sigset_t sigchld_mask;
  return sigemptyset(&sigchld_mask) == -1 ||
         sigaddset(&sigchld_mask, SIGCHLD) == -1 ||
         sigprocmask(action, &sigchld_mask, NULL) == -1;
}


x86 assembly (clang, -O0):
<set_sigchld>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     1156 <set_sigchld+0x26>
mov    0x2e84(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
jmp    1162 <set_sigchld+0x32>
mov    0x2e8b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x8(%rbp)
lea    -0xc(%rbp),%rdi
call   1040 <sigemptyset@plt>
mov    %eax,%ecx
mov    $0x1,%al
cmp    $0xffffffff,%ecx
mov    %al,-0x11(%rbp)
je     11bc <set_sigchld+0x8c>
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdi
call   1050 <sigaddset@plt>
mov    %eax,%ecx
mov    $0x1,%al
cmp    $0xffffffff,%ecx
mov    %al,-0x11(%rbp)
je     11bc <set_sigchld+0x8c>
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
cmp    $0xffffffff,%eax
sete   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_sigchld>:
push   %rbp
push   %rbx
push   %rax
test   %edi,%edi
jne    1140 <set_sigchld+0x10>
mov    0x2eaa(%rip),%rax
jmp    1147 <set_sigchld+0x17>
mov    0x2e89(%rip),%rax
mov    (%rax),%ebx
lea    0x4(%rsp),%rdi
call   1040 <sigemptyset@plt>
mov    $0x1,%ebp
cmp    $0xffffffff,%eax
je     118c <set_sigchld+0x5c>
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdi
call   1050 <sigaddset@plt>
cmp    $0xffffffff,%eax
je     118c <set_sigchld+0x5c>
lea    0x4(%rsp),%rsi
mov    %ebx,%edi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
xor    %ebp,%ebp
cmp    $0xffffffff,%eax
sete   %bpl
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@SIG_BLOCK = global i32 0
@SIG_UNBLOCK = global i32 0
@SIGCHLD = global i32 0
define i32 @set_sigchld(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = load i32, i32* @SIG_BLOCK
br label %11
9: ; preds = %1
%10 = load i32, i32* @SIG_UNBLOCK
br label %11
11: ; preds = %9, %7
%12 = phi i32 [ %8, %7 ], [ %10, %9 ]
store i32 %12, i32* %3
%13 = call i32 @sigemptyset(i32* %4)
%14 = icmp eq i32 %13, -1
br i1 %14, label %23, label %15
15: ; preds = %11
%16 = load i32, i32* @SIGCHLD
%17 = call i32 @sigaddset(i32* %4, i32 %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %23, label %19
19: ; preds = %15
%20 = load i32, i32* %3
%21 = call i32 @sigprocmask(i32 %20, i32* %4, i32* null)
%22 = icmp eq i32 %21, -1
br label %23
23: ; preds = %19, %15, %11
%24 = phi i1 [ true, %15 ], [ true, %11 ], [ %22, %19 ]
%25 = zext i1 %24 to i32
ret i32 %25
}

LLVM IR (-O2):
@SIG_BLOCK = global i32 0
@SIG_UNBLOCK = global i32 0
@SIGCHLD = global i32 0
define i32 @set_sigchld(i32 %0) {
%2 = alloca i32
%3 = icmp eq i32 %0, 0
%4 = load i32, i32* @SIG_BLOCK
%5 = load i32, i32* @SIG_UNBLOCK
%6 = select i1 %3, i32 %5, i32 %4
%7 = bitcast i32* %2 to i8*
%8 = call i32 @sigemptyset(i32* %2)
%9 = icmp eq i32 %8, -1
br i1 %9, label %18, label %10
10: ; preds = %1
%11 = load i32, i32* @SIGCHLD
%12 = call i32 @sigaddset(i32* %2, i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %18, label %14
14: ; preds = %10
%15 = call i32 @sigprocmask(i32 %6, i32* %2, i32* null)
%16 = icmp eq i32 %15, -1
%17 = zext i1 %16 to i32
br label %18
18: ; preds = %14, %10, %1
%19 = phi i32 [ 1, %10 ], [ 1, %1 ], [ %17, %14 ]
ret i32 %19
}