#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*/ SIGINT;
int /*<<< orphan*/ SIGTERM;
int /*<<< orphan*/ SIG_BLOCK;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int signalfd(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
scalar_t__ sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *,
                       int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int initialize_signals(void) {
  int signal_fd;
  sigset_t sigmask;
  sigemptyset(&sigmask);
  sigaddset(&sigmask, SIGINT);
  sigaddset(&sigmask, SIGTERM);
  if (sigprocmask(SIG_BLOCK, &sigmask, NULL) < 0) {
    fprintf(stderr, "Couldn't block signals: '%s'\n", strerror(errno));
    return -1;
  }
  if ((signal_fd = signalfd(-1, &sigmask, 0)) < 0) {
    fprintf(stderr, "Couldn't setup signal FD: '%s'\n", strerror(errno));
    return -1;
  }
  return signal_fd;
}


x86 assembly (clang, -O0):
<initialize_signals>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0xc(%rbp),%rdi
call   1060 <sigemptyset@plt>
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdi
call   1080 <sigaddset@plt>
mov    0x2e56(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdi
call   1080 <sigaddset@plt>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
lea    -0xc(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
cmp    $0x0,%rax
jge    11ed <initialize_signals+0x8d>
mov    0x2e14(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x10(%rbp),%edi
mov    %rax,%rdx
lea    0xe24(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1247 <initialize_signals+0xe7>
mov    $0xffffffff,%edi
lea    -0xc(%rbp),%rsi
xor    %edx,%edx
call   1040 <signalfd@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    1241 <initialize_signals+0xe1>
mov    0x2dc0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x14(%rbp),%edi
mov    %rax,%rdx
lea    0xdee(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1247 <initialize_signals+0xe7>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<initialize_signals>:
push   %rbp
push   %rbx
push   %rax
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <sigemptyset@plt>
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1080 <sigaddset@plt>
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1080 <sigaddset@plt>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
test   %rax,%rax
js     11c8 <initialize_signals+0x68>
lea    0x4(%rsp),%rsi
mov    $0xffffffff,%edi
xor    %edx,%edx
call   1040 <signalfd@plt>
test   %eax,%eax
jns    11f8 <initialize_signals+0x98>
lea    0xe58(%rip),%rbx
jmp    11cf <initialize_signals+0x6f>
lea    0xe31(%rip),%rbx
mov    0x2dfa(%rip),%rax
mov    (%rax),%ebp
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@SIGINT = global i32 0
@SIGTERM = global i32 0
@SIG_BLOCK = global i32 0
@stderr = global i32 0
@.str = [30 x i8] c"Couldn't block signals: '%s'\0A\00"
@errno = global i32 0
@.str.1 = [32 x i8] c"Couldn't setup signal FD: '%s'\0A\00"
define i32 @initialize_signals() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = call i32 @sigemptyset(i32* %3)
%5 = load i32, i32* @SIGINT
%6 = call i32 @sigaddset(i32* %3, i32 %5)
%7 = load i32, i32* @SIGTERM
%8 = call i32 @sigaddset(i32* %3, i32 %7)
%9 = load i32, i32* @SIG_BLOCK
%10 = call i64 @sigprocmask(i32 %9, i32* %3, i32* null)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %0
%13 = load i32, i32* @stderr
%14 = load i32, i32* @errno
%15 = call i8* @strerror(i32 %14)
%16 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 -1, i32* %1
br label %27
17: ; preds = %0
%18 = call i32 @signalfd(i32 -1, i32* %3, i32 0)
store i32 %18, i32* %2
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %17
%21 = load i32, i32* @stderr
%22 = load i32, i32* @errno
%23 = call i8* @strerror(i32 %22)
%24 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %23)
store i32 -1, i32* %1
br label %27
25: ; preds = %17
%26 = load i32, i32* %2
store i32 %26, i32* %1
br label %27
27: ; preds = %25, %20, %12
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
@SIGINT = global i32 0
@SIGTERM = global i32 0
@SIG_BLOCK = global i32 0
@stderr = global i32 0
@.str = [30 x i8] c"Couldn't block signals: '%s'\0A\00"
@errno = global i32 0
@.str.1 = [32 x i8] c"Couldn't setup signal FD: '%s'\0A\00"
define i32 @initialize_signals() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @sigemptyset(i32* %1)
%4 = load i32, i32* @SIGINT
%5 = call i32 @sigaddset(i32* %1, i32 %4)
%6 = load i32, i32* @SIGTERM
%7 = call i32 @sigaddset(i32* %1, i32 %6)
%8 = load i32, i32* @SIG_BLOCK
%9 = call i64 @sigprocmask(i32 %8, i32* %1, i32* null)
%10 = icmp slt i64 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %0
%12 = call i32 @signalfd(i32 -1, i32* %1, i32 0)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %11, %0
%15 = phi i8* [ getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), %0 ], [ getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), %11 ]
%16 = load i32, i32* @stderr
%17 = load i32, i32* @errno
%18 = call i8* @strerror(i32 %17)
%19 = call i32 @fprintf(i32 %16, i8* %15, i8* %18)
br label %20
20: ; preds = %14, %11
%21 = phi i32 [ %12, %11 ], [ -1, %14 ]
ret i32 %21
}