#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 SFD_CLOEXEC;
int SFD_NONBLOCK;
int /*<<< orphan*/ SIGCHLD;
int /*<<< orphan*/ SIG_BLOCK;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int signalfd(int, int /*<<< orphan*/ *, int);
int sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int child_signalfd(void) {
  sigset_t mask;
  int rv;
  int fd;
  sigemptyset(&mask);
  sigaddset(&mask, SIGCHLD);
  rv = sigprocmask(SIG_BLOCK, &mask, NULL);
  if (rv == -1) {
    perror("sigprocmask");
    abort();
  }
  fd = signalfd(-1, &mask, SFD_NONBLOCK | SFD_CLOEXEC);
  if (fd == -1) {
    perror("signalfd");
    abort();
  }
  return fd;
}


x86 assembly (clang, -O0):
<child_signalfd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x4(%rbp),%rdi
call   1060 <sigemptyset@plt>
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
lea    -0x4(%rbp),%rdi
call   1080 <sigaddset@plt>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
lea    -0x4(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11b9 <child_signalfd+0x59>
lea    0xe53(%rip),%rdi
call   1070 <perror@plt>
mov    $0x0,%al
call   1040 <abort@plt>
mov    0x2e10(%rip),%rax
mov    (%rax),%edx
mov    0x2e27(%rip),%rax
or     (%rax),%edx
mov    $0xffffffff,%edi
lea    -0x4(%rbp),%rsi
call   1050 <signalfd@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11f9 <child_signalfd+0x99>
lea    0xe1f(%rip),%rdi
call   1070 <perror@plt>
mov    $0x0,%al
call   1040 <abort@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<child_signalfd>:
push   %rbx
sub    $0x10,%rsp
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <sigemptyset@plt>
mov    0x2e67(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1080 <sigaddset@plt>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
cmp    $0xffffffff,%eax
je     11c7 <child_signalfd+0x67>
mov    0x2e2e(%rip),%rax
mov    0x2e47(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xc(%rsp),%rsi
mov    $0xffffffff,%edi
call   1050 <signalfd@plt>
cmp    $0xffffffff,%eax
je     11d0 <child_signalfd+0x70>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe32(%rip),%rdi
jmp    11d7 <child_signalfd+0x77>
lea    0xe35(%rip),%rdi
call   1070 <perror@plt>
xor    %eax,%eax
call   1040 <abort@plt>

LLVM IR (-O0):
@SIGCHLD = global i32 0
@SIG_BLOCK = global i32 0
@.str = [12 x i8] c"sigprocmask\00"
@SFD_NONBLOCK = global i32 0
@SFD_CLOEXEC = global i32 0
@.str.1 = [9 x i8] c"signalfd\00"
define i32 @child_signalfd() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = call i32 @sigemptyset(i32* %1)
%5 = load i32, i32* @SIGCHLD
%6 = call i32 @sigaddset(i32* %1, i32 %5)
%7 = load i32, i32* @SIG_BLOCK
%8 = call i32 @sigprocmask(i32 %7, i32* %1, i32* null)
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%13 = call i32 (...) @abort()
unreachable
14: ; preds = %0
%15 = load i32, i32* @SFD_NONBLOCK
%16 = load i32, i32* @SFD_CLOEXEC
%17 = or i32 %15, %16
%18 = call i32 @signalfd(i32 -1, i32* %1, i32 %17)
store i32 %18, i32* %3
%19 = load i32, i32* %3
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %24
21: ; preds = %14
%22 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 (...) @abort()
unreachable
24: ; preds = %14
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
@SIGCHLD = global i32 0
@SIG_BLOCK = global i32 0
@.str = [12 x i8] c"sigprocmask\00"
@SFD_NONBLOCK = global i32 0
@SFD_CLOEXEC = global i32 0
@.str.1 = [9 x i8] c"signalfd\00"
define i32 @child_signalfd() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @sigemptyset(i32* %1)
%4 = load i32, i32* @SIGCHLD
%5 = call i32 @sigaddset(i32* %1, i32 %4)
%6 = load i32, i32* @SIG_BLOCK
%7 = call i32 @sigprocmask(i32 %6, i32* %1, i32* null)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%11 = call i32 (...) @abort()
unreachable
12: ; preds = %0
%13 = load i32, i32* @SFD_NONBLOCK
%14 = load i32, i32* @SFD_CLOEXEC
%15 = or i32 %14, %13
%16 = call i32 @signalfd(i32 -1, i32* %1, i32 %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %12
%19 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 (...) @abort()
unreachable
21: ; preds = %12
ret i32 %16
}