#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ sigset_t;
struct TYPE_3__ {
  scalar_t__ si_signo;
};
typedef TYPE_1__ siginfo_t;
typedef int /*<<< orphan*/ info;

/* Variables and functions */
int /*<<< orphan*/ SFD_NONBLOCK;
scalar_t__ SIGUSR1;
scalar_t__ SIGUSR2;
int /*<<< orphan*/ SIG_BLOCK;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ kill(int /*<<< orphan*/, scalar_t__);
int read(int, TYPE_1__ *, int);
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, scalar_t__);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int signalfd(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *,
                               int /*<<< orphan*/ *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ test_daemon();
int /*<<< orphan*/ test_init(int, char **);
int /*<<< orphan*/ test_msg(char *, ...);
int /*<<< orphan*/ test_waitsig();
int main(int argc, char *argv[]) {
  int fd, ret;
  sigset_t mask;
  siginfo_t info;
  test_init(argc, argv);
  sigemptyset(&mask);
  sigaddset(&mask, SIGUSR1);
  fd = signalfd(-1, &mask, SFD_NONBLOCK);
  if (fd < 0) {
    test_msg("FAIL: %s:%d: "
             "Can't create signalfd"
             " (errno = %d (%s))\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/AuthenticEshkinKot/criu/refs/heads/"
             "master/test/zdtm/live/static/signalfd00.c",
             37, errno, strerror(errno));
    exit(1);
  }
  sigemptyset(&mask);
  sigaddset(&mask, SIGUSR1);
  sigaddset(&mask, SIGUSR2);
  sigprocmask(SIG_BLOCK, &mask, NULL);
  test_daemon();
  test_waitsig();
  kill(getpid(), SIGUSR2);
  ret = read(fd, &info, sizeof(info));
  if (ret >= 0) {
    test_msg("FAIL: %s:%d: "
             "ghost signal"
             " (errno = %d (%s))\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/AuthenticEshkinKot/criu/refs/heads/"
             "master/test/zdtm/live/static/signalfd00.c",
             53, errno, strerror(errno));
    exit(1);
  }
  kill(getpid(), SIGUSR1);
  ret = read(fd, &info, sizeof(info));
  if (ret != sizeof(info)) {
    test_msg("FAIL: %s:%d: "
             "no signal"
             " (errno = %d (%s))\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/AuthenticEshkinKot/criu/refs/heads/"
             "master/test/zdtm/live/static/signalfd00.c",
             61, errno, strerror(errno));
    exit(1);
  }
  if (info.si_signo != SIGUSR1) {
    test_msg("FAIL: %s:%d: "
             "wrong signal"
             " (errno = %d (%s))\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/AuthenticEshkinKot/criu/refs/heads/"
             "master/test/zdtm/live/static/signalfd00.c",
             66, errno, strerror(errno));
    exit(1);
  }
  test_msg("PASS\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <test_init@plt>
lea    -0x1c(%rbp),%rdi
call   10b0 <sigemptyset@plt>
mov    0x2de6(%rip),%rax
mov    (%rax),%rsi
lea    -0x1c(%rbp),%rdi
call   10f0 <sigaddset@plt>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffff,%edi
lea    -0x1c(%rbp),%rsi
call   1070 <signalfd@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1276 <main+0xa6>
mov    0x2d8f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x2c(%rbp),%ecx
mov    %eax,%r8d
lea    0xda7(%rip),%rdi
lea    0xdd6(%rip),%rsi
mov    $0x25,%edx
mov    $0x0,%al
call   1080 <test_msg@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    -0x1c(%rbp),%rdi
call   10b0 <sigemptyset@plt>
mov    0x2d62(%rip),%rax
mov    (%rax),%rsi
lea    -0x1c(%rbp),%rdi
call   10f0 <sigaddset@plt>
mov    0x2d37(%rip),%rax
mov    (%rax),%rsi
lea    -0x1c(%rbp),%rdi
call   10f0 <sigaddset@plt>
mov    0x2d14(%rip),%rax
mov    (%rax),%edi
lea    -0x1c(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
mov    $0x0,%al
call   1060 <test_daemon@plt>
mov    $0x0,%al
call   10a0 <test_waitsig@plt>
mov    $0x0,%al
call   1050 <getpid@plt>
mov    %eax,%edi
mov    0x2cf7(%rip),%rax
mov    (%rax),%rsi
call   10c0 <kill@plt>
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x8,%edx
call   1090 <read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     1343 <main+0x173>
mov    0x2cc2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2cb6(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x30(%rbp),%ecx
mov    %eax,%r8d
lea    0xdb7(%rip),%rdi
lea    0xd09(%rip),%rsi
mov    $0x35,%edx
mov    $0x0,%al
call   1080 <test_msg@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    $0x0,%al
call   1050 <getpid@plt>
mov    %eax,%edi
mov    0x2c95(%rip),%rax
mov    (%rax),%rsi
call   10c0 <kill@plt>
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x8,%edx
call   1090 <read@plt>
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rax
cmp    $0x8,%rax
je     13c1 <main+0x1f1>
mov    0x2c44(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2c38(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x34(%rbp),%ecx
mov    %eax,%r8d
lea    0xd66(%rip),%rdi
lea    0xc8b(%rip),%rsi
mov    $0x3d,%edx
mov    $0x0,%al
call   1080 <test_msg@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x28(%rbp),%rax
mov    0x2c1c(%rip),%rcx
cmp    (%rcx),%rax
je     1419 <main+0x249>
mov    0x2bec(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2be0(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x38(%rbp),%ecx
mov    %eax,%r8d
lea    0xd38(%rip),%rdi
lea    0xc33(%rip),%rsi
mov    $0x42,%edx
mov    $0x0,%al
call   1080 <test_msg@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    0xd41(%rip),%rdi
mov    $0x0,%al
call   1080 <test_msg@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
call   1040 <test_init@plt>
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   10b0 <sigemptyset@plt>
mov    0x2df5(%rip),%r14
mov    (%r14),%rsi
mov    %rbx,%rdi
call   10f0 <sigaddset@plt>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffff,%edi
mov    %rbx,%rsi
call   1070 <signalfd@plt>
test   %eax,%eax
js     12df <main+0x10f>
mov    %eax,%ebp
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   10b0 <sigemptyset@plt>
mov    (%r14),%rsi
mov    %rbx,%rdi
call   10f0 <sigaddset@plt>
mov    0x2d93(%rip),%r15
mov    (%r15),%rsi
mov    %rbx,%rdi
call   10f0 <sigaddset@plt>
mov    0x2d71(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
xor    %eax,%eax
call   1060 <test_daemon@plt>
xor    %eax,%eax
call   10a0 <test_waitsig@plt>
xor    %eax,%eax
call   1050 <getpid@plt>
mov    (%r15),%rsi
mov    %eax,%edi
call   10c0 <kill@plt>
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0x8,%edx
call   1090 <read@plt>
test   %eax,%eax
jns    1304 <main+0x134>
xor    %eax,%eax
call   1050 <getpid@plt>
mov    (%r14),%rsi
mov    %eax,%edi
call   10c0 <kill@plt>
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0x8,%edx
call   1090 <read@plt>
cmp    $0x8,%eax
jne    1329 <main+0x159>
mov    0x10(%rsp),%rax
cmp    (%r14),%rax
jne    134e <main+0x17e>
lea    0xe96(%rip),%rdi
xor    %eax,%eax
call   1080 <test_msg@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2ce2(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10e0 <strerror@plt>
lea    0xd0a(%rip),%rdi
lea    0xd39(%rip),%rsi
mov    $0x25,%edx
jmp    1371 <main+0x1a1>
mov    0x2cbd(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10e0 <strerror@plt>
lea    0xdc2(%rip),%rdi
lea    0xd14(%rip),%rsi
mov    $0x35,%edx
jmp    1371 <main+0x1a1>
mov    0x2c98(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10e0 <strerror@plt>
lea    0xdca(%rip),%rdi
lea    0xcef(%rip),%rsi
mov    $0x3d,%edx
jmp    1371 <main+0x1a1>
mov    0x2c73(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10e0 <strerror@plt>
lea    0xdcf(%rip),%rdi
lea    0xcca(%rip),%rsi
mov    $0x42,%edx
mov    %ebx,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1080 <test_msg@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.TYPE_3__ = type { i64 }
@SIGUSR1 = global i64 0
@SFD_NONBLOCK = global i32 0
@.str = [54 x i8] c"FAIL: %s:%d: Can't create signalfd (errno = %d (%s))\0A\00"
@.str.1 = [167 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/AuthenticEshkinKot/criu/refs/heads/master/test/zdtm/live/static/signalfd00.c\00"
@errno = global i32 0
@SIGUSR2 = global i64 0
@SIG_BLOCK = global i32 0
@.str.2 = [45 x i8] c"FAIL: %s:%d: ghost signal (errno = %d (%s))\0A\00"
@.str.3 = [42 x i8] c"FAIL: %s:%d: no signal (errno = %d (%s))\0A\00"
@.str.4 = [45 x i8] c"FAIL: %s:%d: wrong signal (errno = %d (%s))\0A\00"
@.str.5 = [6 x i8] c"PASS\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.TYPE_3__
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = load i8**, i8*** %5
%12 = call i32 @test_init(i32 %10, i8** %11)
%13 = call i32 @sigemptyset(i32* %8)
%14 = load i64, i64* @SIGUSR1
%15 = call i32 @sigaddset(i32* %8, i64 %14)
%16 = load i32, i32* @SFD_NONBLOCK
%17 = call i32 @signalfd(i32 -1, i32* %8, i32 %16)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %2
%21 = load i32, i32* @errno
%22 = load i32, i32* @errno
%23 = call i32 @strerror(i32 %22)
%24 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([167 x i8], [167 x i8]* @.str.1, i64 0, i64 0), i32 37, i32 %21, i32 %23)
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %2
%27 = call i32 @sigemptyset(i32* %8)
%28 = load i64, i64* @SIGUSR1
%29 = call i32 @sigaddset(i32* %8, i64 %28)
%30 = load i64, i64* @SIGUSR2
%31 = call i32 @sigaddset(i32* %8, i64 %30)
%32 = load i32, i32* @SIG_BLOCK
%33 = call i32 @sigprocmask(i32 %32, i32* %8, i32* null)
%34 = call i32 (...) @test_daemon()
%35 = call i32 (...) @test_waitsig()
%36 = call i32 (...) @getpid()
%37 = load i64, i64* @SIGUSR2
%38 = call i32 @kill(i32 %36, i64 %37)
%39 = load i32, i32* %6
%40 = call i32 @read(i32 %39, %struct.TYPE_3__* %9, i32 8)
store i32 %40, i32* %7
%41 = load i32, i32* %7
%42 = icmp sge i32 %41, 0
br i1 %42, label %43, label %49
43: ; preds = %26
%44 = load i32, i32* @errno
%45 = load i32, i32* @errno
%46 = call i32 @strerror(i32 %45)
%47 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([167 x i8], [167 x i8]* @.str.1, i64 0, i64 0), i32 53, i32 %44, i32 %46)
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %26
%50 = call i32 (...) @getpid()
%51 = load i64, i64* @SIGUSR1
%52 = call i32 @kill(i32 %50, i64 %51)
%53 = load i32, i32* %6
%54 = call i32 @read(i32 %53, %struct.TYPE_3__* %9, i32 8)
store i32 %54, i32* %7
%55 = load i32, i32* %7
%56 = sext i32 %55 to i64
%57 = icmp ne i64 %56, 8
br i1 %57, label %58, label %64
58: ; preds = %49
%59 = load i32, i32* @errno
%60 = load i32, i32* @errno
%61 = call i32 @strerror(i32 %60)
%62 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([167 x i8], [167 x i8]* @.str.1, i64 0, i64 0), i32 61, i32 %59, i32 %61)
%63 = call i32 @exit(i32 1)
unreachable
64: ; preds = %49
%65 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %9, i32 0, i32 0
%66 = load i64, i64* %65
%67 = load i64, i64* @SIGUSR1
%68 = icmp ne i64 %66, %67
br i1 %68, label %69, label %75
69: ; preds = %64
%70 = load i32, i32* @errno
%71 = load i32, i32* @errno
%72 = call i32 @strerror(i32 %71)
%73 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([167 x i8], [167 x i8]* @.str.1, i64 0, i64 0), i32 66, i32 %70, i32 %72)
%74 = call i32 @exit(i32 1)
unreachable
75: ; preds = %64
%76 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i64 }
@SIGUSR1 = global i64 0
@SFD_NONBLOCK = global i32 0
@.str = [54 x i8] c"FAIL: %s:%d: Can't create signalfd (errno = %d (%s))\0A\00"
@.str.1 = [167 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/AuthenticEshkinKot/criu/refs/heads/master/test/zdtm/live/static/signalfd00.c\00"
@errno = global i32 0
@SIGUSR2 = global i64 0
@SIG_BLOCK = global i32 0
@.str.2 = [45 x i8] c"FAIL: %s:%d: ghost signal (errno = %d (%s))\0A\00"
@.str.3 = [42 x i8] c"FAIL: %s:%d: no signal (errno = %d (%s))\0A\00"
@.str.4 = [45 x i8] c"FAIL: %s:%d: wrong signal (errno = %d (%s))\0A\00"
@.str.5 = [6 x i8] c"PASS\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca %struct.TYPE_3__
%5 = bitcast i32* %3 to i8*
%6 = bitcast %struct.TYPE_3__* %4 to i8*
%7 = tail call i32 @test_init(i32 %0, i8** %1)
%8 = call i32 @sigemptyset(i32* %3)
%9 = load i64, i64* @SIGUSR1
%10 = call i32 @sigaddset(i32* %3, i64 %9)
%11 = load i32, i32* @SFD_NONBLOCK
%12 = call i32 @signalfd(i32 -1, i32* %3, i32 %11)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i32, i32* @errno
%16 = call i32 @strerror(i32 %15)
%17 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([167 x i8], [167 x i8]* @.str.1, i64 0, i64 0), i32 37, i32 %15, i32 %16)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = call i32 @sigemptyset(i32* %3)
%21 = load i64, i64* @SIGUSR1
%22 = call i32 @sigaddset(i32* %3, i64 %21)
%23 = load i64, i64* @SIGUSR2
%24 = call i32 @sigaddset(i32* %3, i64 %23)
%25 = load i32, i32* @SIG_BLOCK
%26 = call i32 @sigprocmask(i32 %25, i32* %3, i32* null)
%27 = call i32 (...) @test_daemon()
%28 = call i32 (...) @test_waitsig()
%29 = call i32 (...) @getpid()
%30 = load i64, i64* @SIGUSR2
%31 = call i32 @kill(i32 %29, i64 %30)
%32 = call i32 @read(i32 %12, %struct.TYPE_3__* %4, i32 8)
%33 = icmp sgt i32 %32, -1
br i1 %33, label %34, label %39
34: ; preds = %19
%35 = load i32, i32* @errno
%36 = call i32 @strerror(i32 %35)
%37 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([167 x i8], [167 x i8]* @.str.1, i64 0, i64 0), i32 53, i32 %35, i32 %36)
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %19
%40 = call i32 (...) @getpid()
%41 = load i64, i64* @SIGUSR1
%42 = call i32 @kill(i32 %40, i64 %41)
%43 = call i32 @read(i32 %12, %struct.TYPE_3__* %4, i32 8)
%44 = icmp eq i32 %43, 8
br i1 %44, label %50, label %45
45: ; preds = %39
%46 = load i32, i32* @errno
%47 = call i32 @strerror(i32 %46)
%48 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([167 x i8], [167 x i8]* @.str.1, i64 0, i64 0), i32 61, i32 %46, i32 %47)
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %39
%51 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %4, i64 0, i32 0
%52 = load i64, i64* %51
%53 = load i64, i64* @SIGUSR1
%54 = icmp eq i64 %52, %53
br i1 %54, label %60, label %55
55: ; preds = %50
%56 = load i32, i32* @errno
%57 = call i32 @strerror(i32 %56)
%58 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([167 x i8], [167 x i8]* @.str.1, i64 0, i64 0), i32 66, i32 %56, i32 %57)
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %50
%61 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}