#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*/ SIGINT;
int /*<<< orphan*/ SIGUSR1;
int /*<<< orphan*/ SIG_BLOCK;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *);
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int signalfd(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int create_sig_fd() {
  sigset_t mask;
  int sfd;
  sigemptyset(&mask);
  sigaddset(&mask, SIGCHLD);
  sigaddset(&mask, SIGINT);
  sigaddset(&mask, SIGUSR1);
  do {
    if (!(sigprocmask(SIG_BLOCK, &mask, NULL) != -1)) {
      fprintf(stderr, "%s:%i: %s\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/andysan/perf_tools/refs/heads/master/"
              "perfrecord.c",
              174, "sigprocmask(SIG_BLOCK, &mask, NULL) != -1");
      abort();
    }
  } while (0);
  sfd = signalfd(-1, &mask, 0);
  do {
    if (!(sfd != -1)) {
      fprintf(stderr, "%s:%i: %s\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/andysan/perf_tools/refs/heads/master/"
              "perfrecord.c",
              176, "sfd != -1");
      abort();
    }
  } while (0);
  return sfd;
}


x86 assembly (clang, -O0):
<create_sig_fd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x4(%rbp),%rdi
call   1070 <sigemptyset@plt>
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
lea    -0x4(%rbp),%rdi
call   1080 <sigaddset@plt>
mov    0x2e56(%rip),%rax
mov    (%rax),%esi
lea    -0x4(%rbp),%rdi
call   1080 <sigaddset@plt>
mov    0x2e4c(%rip),%rax
mov    (%rax),%esi
lea    -0x4(%rbp),%rdi
call   1080 <sigaddset@plt>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
lea    -0x4(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
cmp    $0xffffffff,%eax
jne    11f5 <create_sig_fd+0x95>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
lea    0xe2a(%rip),%rsi
lea    0xe2e(%rip),%rdx
mov    $0xae,%ecx
lea    0xeae(%rip),%r8
call   1060 <fprintf@plt>
mov    $0x0,%al
call   1040 <abort@plt>
jmp    11fa <create_sig_fd+0x9a>
mov    $0xffffffff,%edi
lea    -0x4(%rbp),%rsi
xor    %edx,%edx
call   1050 <signalfd@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1246 <create_sig_fd+0xe6>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
lea    0xdd9(%rip),%rsi
lea    0xddd(%rip),%rdx
mov    $0xb0,%ecx
lea    0xe87(%rip),%r8
call   1060 <fprintf@plt>
mov    $0x0,%al
call   1040 <abort@plt>
jmp    124b <create_sig_fd+0xeb>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_sig_fd>:
push   %rbx
sub    $0x10,%rsp
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <sigemptyset@plt>
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1080 <sigaddset@plt>
mov    0x2e56(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1080 <sigaddset@plt>
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1080 <sigaddset@plt>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
cmp    $0xffffffff,%eax
je     11d9 <create_sig_fd+0x79>
lea    0xc(%rsp),%rsi
mov    $0xffffffff,%edi
xor    %edx,%edx
call   1050 <signalfd@plt>
cmp    $0xffffffff,%eax
je     11fe <create_sig_fd+0x9e>
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
lea    0xe17(%rip),%rsi
lea    0xe1b(%rip),%rdx
lea    0xea0(%rip),%r8
mov    $0xae,%ecx
jmp    1221 <create_sig_fd+0xc1>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
lea    0xdf2(%rip),%rsi
lea    0xdf6(%rip),%rdx
lea    0xea5(%rip),%r8
mov    $0xb0,%ecx
call   1060 <fprintf@plt>
xor    %eax,%eax
call   1040 <abort@plt>

LLVM IR (-O0):
@SIGCHLD = global i32 0
@SIGINT = global i32 0
@SIGUSR1 = global i32 0
@SIG_BLOCK = global i32 0
@stderr = global i32 0
@.str = [11 x i8] c"%s:%i: %s\0A\00"
@.str.1 = [140 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/andysan/perf_tools/refs/heads/master/perfrecord.c\00"
@.str.2 = [42 x i8] c"sigprocmask(SIG_BLOCK, &mask, NULL) != -1\00"
@.str.3 = [10 x i8] c"sfd != -1\00"
define i32 @create_sig_fd() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 @sigemptyset(i32* %1)
%4 = load i32, i32* @SIGCHLD
%5 = call i32 @sigaddset(i32* %1, i32 %4)
%6 = load i32, i32* @SIGINT
%7 = call i32 @sigaddset(i32* %1, i32 %6)
%8 = load i32, i32* @SIGUSR1
%9 = call i32 @sigaddset(i32* %1, i32 %8)
br label %10
10: ; preds = %0
%11 = load i32, i32* @SIG_BLOCK
%12 = call i32 @sigprocmask(i32 %11, i32* %1, i32* null)
%13 = icmp ne i32 %12, -1
br i1 %13, label %18, label %14
14: ; preds = %10
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str.1, i64 0, i64 0), i32 174, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 (...) @abort()
unreachable
18: ; preds = %10
br label %19
19: ; preds = %18
%20 = call i32 @signalfd(i32 -1, i32* %1, i32 0)
store i32 %20, i32* %2
br label %21
21: ; preds = %19
%22 = load i32, i32* %2
%23 = icmp ne i32 %22, -1
br i1 %23, label %28, label %24
24: ; preds = %21
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str.1, i64 0, i64 0), i32 176, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%27 = call i32 (...) @abort()
unreachable
28: ; preds = %21
br label %29
29: ; preds = %28
%30 = load i32, i32* %2
ret i32 %30
}

LLVM IR (-O2):
@SIGCHLD = global i32 0
@SIGINT = global i32 0
@SIGUSR1 = global i32 0
@SIG_BLOCK = global i32 0
@stderr = global i32 0
@.str = [11 x i8] c"%s:%i: %s\0A\00"
@.str.1 = [140 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/andysan/perf_tools/refs/heads/master/perfrecord.c\00"
@.str.2 = [42 x i8] c"sigprocmask(SIG_BLOCK, &mask, NULL) != -1\00"
@.str.3 = [10 x i8] c"sfd != -1\00"
define i32 @create_sig_fd() {
%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* @SIGINT
%7 = call i32 @sigaddset(i32* %1, i32 %6)
%8 = load i32, i32* @SIGUSR1
%9 = call i32 @sigaddset(i32* %1, i32 %8)
%10 = load i32, i32* @SIG_BLOCK
%11 = call i32 @sigprocmask(i32 %10, i32* %1, i32* null)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %17
13: ; preds = %0
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str.1, i64 0, i64 0), i32 174, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 (...) @abort()
unreachable
17: ; preds = %0
%18 = call i32 @signalfd(i32 -1, i32* %1, i32 0)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str.1, i64 0, i64 0), i32 176, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%23 = call i32 (...) @abort()
unreachable
24: ; preds = %17
ret i32 %18
}