#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 */
struct inotify_event {
  int dummy;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ IN_NONBLOCK;
int /*<<< orphan*/ IN_OPEN;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ PATH_MAX;
int /*<<< orphan*/ close(int);
scalar_t__ creat(char *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int inotify_add_watch(int, char *, int /*<<< orphan*/);
int inotify_init1(int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ mkdir(char *, int);
int open(char *, int /*<<< orphan*/);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ test_daemon();
int /*<<< orphan*/ test_init(int, char **);
int /*<<< orphan*/ test_msg(char *, ...);
int /*<<< orphan*/ test_waitsig();
int /*<<< orphan*/ unlink(char *);
int main(int argc, char *argv[]) {
  char buf[((sizeof(struct inotify_event) + PATH_MAX))];
  int fd, wd;
  test_init(argc, argv);
  mkdir("/etc", 0600);
  unlink("/etc"
         "/zdtm-test");
  if (creat("/etc"
            "/zdtm-test",
            0600) < 0) {
    test_msg("ERR: %s:%d: "
             "Can't make test file"
             " (errno = %d (%m))\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/kawamuray/criu/refs/heads/master/test/"
             "zdtm/live/static/inotify_irmap.c",
             36, errno);
    exit(1);
  }
  fd = inotify_init1(IN_NONBLOCK);
  if (fd < 0) {
    test_msg("FAIL: %s:%d: "
             "inotify_init failed"
             " (errno = %d (%m))\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/kawamuray/criu/refs/heads/master/test/"
             "zdtm/live/static/inotify_irmap.c",
             42, errno);
    unlink("/etc"
           "/zdtm-test");
    exit(1);
  }
  wd = inotify_add_watch(fd,
                         "/etc"
                         "/zdtm-test",
                         IN_OPEN);
  if (wd < 0) {
    test_msg("FAIL: %s:%d: "
             "inotify_add_watch failed"
             " (errno = %d (%m))\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/kawamuray/criu/refs/heads/master/test/"
             "zdtm/live/static/inotify_irmap.c",
             49, errno);
    unlink("/etc"
           "/zdtm-test");
    exit(1);
  }
  test_daemon();
  test_waitsig();
  memset(buf, 0, sizeof(buf));
  wd = open("/etc"
            "/zdtm-test",
            O_RDONLY);
  if (read(fd, buf, sizeof(buf)) <= 0) {
    unlink("/etc"
           "/zdtm-test");
    test_msg("FAIL: %s:%d: "
             "No events in queue"
             " (errno = %d (%m))\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/kawamuray/criu/refs/heads/master/test/"
             "zdtm/live/static/inotify_irmap.c",
             61, errno);
    exit(1);
  }
  close(wd);
  close(fd);
  unlink("/etc"
         "/zdtm-test");
  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    0x2df3(%rip),%rax
movslq (%rax),%rdx
mov    %rdx,%rax
add    $0x4,%rax
mov    %rax,-0x38(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
add    $0x13,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <test_init@plt>
lea    0xdc2(%rip),%rdi
mov    $0x180,%esi
call   1050 <mkdir@plt>
lea    0xdb6(%rip),%rdi
call   1030 <unlink@plt>
lea    0xdaa(%rip),%rdi
mov    $0x180,%esi
call   10e0 <creat@plt>
cmp    $0x0,%rax
jge    129c <main+0xbc>
mov    0x2d52(%rip),%rax
mov    (%rax),%ecx
lea    0xd95(%rip),%rdi
lea    0xdc2(%rip),%rsi
mov    $0x24,%edx
mov    $0x0,%al
call   1090 <test_msg@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    0x2d2d(%rip),%rax
mov    (%rax),%edi
call   1100 <inotify_init1@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    12f0 <main+0x110>
mov    0x2d0a(%rip),%rax
mov    (%rax),%ecx
lea    0xe22(%rip),%rdi
lea    0xd7a(%rip),%rsi
mov    $0x2a,%edx
mov    $0x0,%al
call   1090 <test_msg@plt>
lea    0xd24(%rip),%rdi
call   1030 <unlink@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x24(%rbp),%edi
mov    0x2cbe(%rip),%rax
mov    (%rax),%edx
lea    0xd02(%rip),%rsi
call   10c0 <inotify_add_watch@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    134e <main+0x16e>
mov    0x2cac(%rip),%rax
mov    (%rax),%ecx
lea    0xdf8(%rip),%rdi
lea    0xd1c(%rip),%rsi
mov    $0x31,%edx
mov    $0x0,%al
call   1090 <test_msg@plt>
lea    0xcc6(%rip),%rdi
call   1030 <unlink@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    $0x0,%al
call   1060 <test_daemon@plt>
mov    $0x0,%al
call   10b0 <test_waitsig@plt>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rax
mov    %eax,%edx
xor    %esi,%esi
call   1070 <memset@plt>
mov    0x2c6c(%rip),%rax
mov    (%rax),%esi
lea    0xc88(%rip),%rdi
call   10d0 <open@plt>
mov    -0x30(%rbp),%rsi
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,-0x28(%rbp)
mov    -0x24(%rbp),%edi
mov    %eax,%edx
call   10a0 <read@plt>
cmp    $0x0,%rax
jg     13dc <main+0x1fc>
lea    0xc5b(%rip),%rdi
call   1030 <unlink@plt>
mov    0x2c12(%rip),%rax
mov    (%rax),%ecx
lea    0xd97(%rip),%rdi
lea    0xc82(%rip),%rsi
mov    $0x3d,%edx
mov    $0x0,%al
call   1090 <test_msg@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x28(%rbp),%edi
call   1080 <close@plt>
mov    -0x24(%rbp),%edi
call   1080 <close@plt>
lea    0xc12(%rip),%rdi
call   1030 <unlink@plt>
lea    0xd8a(%rip),%rdi
mov    $0x0,%al
call   1090 <test_msg@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    0x2dfe(%rip),%rax
movslq (%rax),%r14
mov    %rsp,%r15
lea    0x13(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
call   1040 <test_init@plt>
lea    0xdee(%rip),%rdi
mov    $0x180,%esi
call   1050 <mkdir@plt>
lea    0xde2(%rip),%rbx
mov    %rbx,%rdi
call   1030 <unlink@plt>
mov    %rbx,%rdi
mov    $0x180,%esi
call   10e0 <creat@plt>
test   %rax,%rax
js     12fd <main+0x11d>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
call   1100 <inotify_init1@plt>
test   %eax,%eax
js     131b <main+0x13b>
mov    %eax,%ebx
mov    0x2d58(%rip),%rax
mov    (%rax),%edx
lea    0xd9c(%rip),%rsi
mov    %ebx,%edi
call   10c0 <inotify_add_watch@plt>
test   %eax,%eax
js     1339 <main+0x159>
add    $0x4,%r14
xor    %eax,%eax
call   1060 <test_daemon@plt>
xor    %eax,%eax
call   10b0 <test_waitsig@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    %r14d,%edx
call   1070 <memset@plt>
mov    0x2d42(%rip),%rax
mov    (%rax),%esi
lea    0xd5e(%rip),%rdi
call   10d0 <open@plt>
mov    %eax,%r12d
mov    %ebx,%edi
mov    %r15,%rsi
mov    %r14d,%edx
call   10a0 <read@plt>
test   %rax,%rax
jle    1372 <main+0x192>
mov    %r12d,%edi
call   1080 <close@plt>
mov    %ebx,%edi
call   1080 <close@plt>
lea    0xd2a(%rip),%rdi
call   1030 <unlink@plt>
lea    0xea2(%rip),%rdi
xor    %eax,%eax
call   1090 <test_msg@plt>
xor    %eax,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cc4(%rip),%rax
mov    (%rax),%ecx
lea    0xd07(%rip),%rdi
lea    0xd34(%rip),%rsi
mov    $0x24,%edx
jmp    139a <main+0x1ba>
mov    0x2ca6(%rip),%rax
mov    (%rax),%ecx
lea    0xdbe(%rip),%rdi
lea    0xd16(%rip),%rsi
mov    $0x2a,%edx
jmp    1355 <main+0x175>
mov    0x2c88(%rip),%rax
mov    (%rax),%ecx
lea    0xdd4(%rip),%rdi
lea    0xcf8(%rip),%rsi
mov    $0x31,%edx
xor    %eax,%eax
call   1090 <test_msg@plt>
lea    0xca2(%rip),%rdi
call   1030 <unlink@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
lea    0xc8c(%rip),%rdi
call   1030 <unlink@plt>
mov    0x2c43(%rip),%rax
mov    (%rax),%ecx
lea    0xdc8(%rip),%rdi
lea    0xcb3(%rip),%rsi
mov    $0x3d,%edx
xor    %eax,%eax
call   1090 <test_msg@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [5 x i8] c"/etc\00"
@.str.1 = [15 x i8] c"/etc/zdtm-test\00"
@.str.2 = [52 x i8] c"ERR: %s:%d: Can't make test file (errno = %d (%m))\0A\00"
@.str.3 = [161 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/kawamuray/criu/refs/heads/master/test/zdtm/live/static/inotify_irmap.c\00"
@errno = global i32 0
@IN_NONBLOCK = global i32 0
@.str.4 = [52 x i8] c"FAIL: %s:%d: inotify_init failed (errno = %d (%m))\0A\00"
@IN_OPEN = global i32 0
@.str.5 = [57 x i8] c"FAIL: %s:%d: inotify_add_watch failed (errno = %d (%m))\0A\00"
@O_RDONLY = global i32 0
@.str.6 = [51 x i8] c"FAIL: %s:%d: No events in queue (errno = %d (%m))\0A\00"
@.str.7 = [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 i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* @PATH_MAX
%11 = sext i32 %10 to i64
%12 = add i64 4, %11
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %6
%14 = alloca i8, i64 %12
store i64 %12, i64* %7
%15 = load i32, i32* %4
%16 = load i8**, i8*** %5
%17 = call i32 @test_init(i32 %15, i8** %16)
%18 = call i32 @mkdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 384)
%19 = call i32 @unlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%20 = call i64 @creat(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 384)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %2
%23 = load i32, i32* @errno
%24 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([161 x i8], [161 x i8]* @.str.3, i64 0, i64 0), i32 36, i32 %23)
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %2
%27 = load i32, i32* @IN_NONBLOCK
%28 = call i32 @inotify_init1(i32 %27)
store i32 %28, i32* %8
%29 = load i32, i32* %8
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %26
%32 = load i32, i32* @errno
%33 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([161 x i8], [161 x i8]* @.str.3, i64 0, i64 0), i32 42, i32 %32)
%34 = call i32 @unlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %26
%37 = load i32, i32* %8
%38 = load i32, i32* @IN_OPEN
%39 = call i32 @inotify_add_watch(i32 %37, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %38)
store i32 %39, i32* %9
%40 = load i32, i32* %9
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %47
42: ; preds = %36
%43 = load i32, i32* @errno
%44 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([161 x i8], [161 x i8]* @.str.3, i64 0, i64 0), i32 49, i32 %43)
%45 = call i32 @unlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %36
%48 = call i32 (...) @test_daemon()
%49 = call i32 (...) @test_waitsig()
%50 = trunc i64 %12 to i32
%51 = call i32 @memset(i8* %14, i32 0, i32 %50)
%52 = load i32, i32* @O_RDONLY
%53 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %52)
store i32 %53, i32* %9
%54 = load i32, i32* %8
%55 = trunc i64 %12 to i32
%56 = call i64 @read(i32 %54, i8* %14, i32 %55)
%57 = icmp sle i64 %56, 0
br i1 %57, label %58, label %63
58: ; preds = %47
%59 = call i32 @unlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%60 = load i32, i32* @errno
%61 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([161 x i8], [161 x i8]* @.str.3, i64 0, i64 0), i32 61, i32 %60)
%62 = call i32 @exit(i32 1)
unreachable
63: ; preds = %47
%64 = load i32, i32* %9
%65 = call i32 @close(i32 %64)
%66 = load i32, i32* %8
%67 = call i32 @close(i32 %66)
%68 = call i32 @unlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%69 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
store i32 0, i32* %3
%70 = load i8*, i8** %6
%71 = load i32, i32* %3
ret i32 %71
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [5 x i8] c"/etc\00"
@.str.1 = [15 x i8] c"/etc/zdtm-test\00"
@.str.2 = [52 x i8] c"ERR: %s:%d: Can't make test file (errno = %d (%m))\0A\00"
@.str.3 = [161 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/kawamuray/criu/refs/heads/master/test/zdtm/live/static/inotify_irmap.c\00"
@errno = global i32 0
@IN_NONBLOCK = global i32 0
@.str.4 = [52 x i8] c"FAIL: %s:%d: inotify_init failed (errno = %d (%m))\0A\00"
@IN_OPEN = global i32 0
@.str.5 = [57 x i8] c"FAIL: %s:%d: inotify_add_watch failed (errno = %d (%m))\0A\00"
@O_RDONLY = global i32 0
@.str.6 = [51 x i8] c"FAIL: %s:%d: No events in queue (errno = %d (%m))\0A\00"
@.str.7 = [6 x i8] c"PASS\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = load i32, i32* @PATH_MAX
%4 = sext i32 %3 to i64
%5 = add nsw i64 %4, 4
%6 = alloca i8, i64 %5
%7 = tail call i32 @test_init(i32 %0, i8** %1)
%8 = tail call i32 @mkdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 384)
%9 = tail call i32 @unlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i64 @creat(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 384)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @errno
%14 = tail call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([161 x i8], [161 x i8]* @.str.3, i64 0, i64 0), i32 36, i32 %13)
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i32, i32* @IN_NONBLOCK
%18 = tail call i32 @inotify_init1(i32 %17)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %16
%21 = load i32, i32* @errno
%22 = tail call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([161 x i8], [161 x i8]* @.str.3, i64 0, i64 0), i32 42, i32 %21)
%23 = tail call i32 @unlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %16
%26 = load i32, i32* @IN_OPEN
%27 = tail call i32 @inotify_add_watch(i32 %18, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %26)
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %25
%30 = load i32, i32* @errno
%31 = tail call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([161 x i8], [161 x i8]* @.str.3, i64 0, i64 0), i32 49, i32 %30)
%32 = tail call i32 @unlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%33 = tail call i32 @exit(i32 1)
unreachable
34: ; preds = %25
%35 = tail call i32 (...) @test_daemon()
%36 = tail call i32 (...) @test_waitsig()
%37 = trunc i64 %5 to i32
%38 = call i32 @memset(i8* %6, i32 0, i32 %37)
%39 = load i32, i32* @O_RDONLY
%40 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %39)
%41 = call i64 @read(i32 %18, i8* %6, i32 %37)
%42 = icmp slt i64 %41, 1
br i1 %42, label %43, label %48
43: ; preds = %34
%44 = call i32 @unlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%45 = load i32, i32* @errno
%46 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([161 x i8], [161 x i8]* @.str.3, i64 0, i64 0), i32 61, i32 %45)
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %34
%49 = call i32 @close(i32 %40)
%50 = call i32 @close(i32 %18)
%51 = call i32 @unlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%52 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
ret i32 0
}