#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 {
  unsigned int mask;
  scalar_t__ len;
};
typedef int /*<<< orphan*/ emask;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
scalar_t__ EAGAIN;
int /*<<< orphan*/ PATH_MAX;
int /*<<< orphan*/ decode_event_mask(char *, int, unsigned int);
scalar_t__ errno;
int read(int, char *, int);
int /*<<< orphan*/ strerror(scalar_t__);
int /*<<< orphan*/ test_msg(char *, char *, int, ...);
int inotify_read_events(char *prefix, int inotify_fd, unsigned int *expected) {
  struct inotify_event *event;
  char buf[((sizeof(struct inotify_event) + PATH_MAX)) * 8];
  int ret, off, n = 0;
  while (1) {
    ret = read(inotify_fd, buf, sizeof(buf));
    if (ret < 0) {
      if (errno != EAGAIN) {
        test_msg("ERR: %s:%d: "
                 "Can't read inotify queue"
                 " (errno = %d (%s))\n",
                 "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                 "outputs/2022-01-22/02-19-57/repos/LK4D4/criu/refs/heads/"
                 "master/test/zdtm/live/static/inotify00.c",
                 82, errno, strerror(errno));
        return -1;
      } else {
        ret = 0;
        goto out;
      }
    } else if (ret == 0)
      break;
    for (off = 0; off < ret; n++, off += sizeof(*event) + event->len) {
      char emask[128];
      event = (void *)(buf + off);
      decode_event_mask(emask, sizeof(emask), event->mask);
      test_msg("\t%-16s: event %#10x -> %s\n", prefix, event->mask, emask);
      if (expected)
        *expected &= ~event->mask;
    }
  }
out:
  test_msg("\t%-16s: read %2d events\n", prefix, n);
  return ret;
}


x86 assembly (clang, -O0):
<inotify_read_events>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    0x2e93(%rip),%rax
movslq (%rax),%rcx
lea    0x80(,%rcx,8),%rax
mov    %rax,-0xe0(%rbp)
mov    %rsp,%rdx
mov    %rdx,-0x30(%rbp)
lea    0x8f(,%rcx,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xd8(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x44(%rbp)
jmp    11a2 <inotify_read_events+0x62>
mov    -0xd8(%rbp),%rsi
mov    -0xe0(%rbp),%rax
mov    -0x14(%rbp),%edi
mov    %eax,%edx
call   1040 <read@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jge    1244 <inotify_read_events+0x104>
mov    0x2e0a(%rip),%rax
mov    (%rax),%rax
mov    0x2df0(%rip),%rcx
cmp    (%rcx),%rax
je     1238 <inotify_read_events+0xf8>
mov    0x2df0(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0xe8(%rbp)
mov    0x2ddf(%rip),%rax
mov    (%rax),%rdi
call   1060 <strerror@plt>
mov    -0xe8(%rbp),%rcx
mov    %eax,%r8d
lea    0xdee(%rip),%rdi
lea    0xe1f(%rip),%rsi
mov    $0x52,%edx
mov    $0x0,%al
call   1030 <test_msg@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x48(%rbp)
jmp    1324 <inotify_read_events+0x1e4>
movl   $0x0,-0x3c(%rbp)
jmp    1302 <inotify_read_events+0x1c2>
cmpl   $0x0,-0x3c(%rbp)
jne    1253 <inotify_read_events+0x113>
jmp    12fd <inotify_read_events+0x1bd>
jmp    1258 <inotify_read_events+0x118>
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jge    12f8 <inotify_read_events+0x1b8>
mov    -0xd8(%rbp),%rax
movslq -0x40(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
lea    -0xd0(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%edx
mov    $0x80,%esi
call   1050 <decode_event_mask@plt>
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rax
mov    (%rax),%edx
lea    -0xd0(%rbp),%rcx
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1030 <test_msg@plt>
cmpq   $0x0,-0x20(%rbp)
je     12cf <inotify_read_events+0x18f>
mov    -0x28(%rbp),%rax
mov    (%rax),%ecx
xor    $0xffffffff,%ecx
mov    -0x20(%rbp),%rax
and    (%rax),%ecx
mov    %ecx,(%rax)
jmp    12d4 <inotify_read_events+0x194>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rcx
add    $0x10,%rcx
movslq -0x40(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x40(%rbp)
jmp    125f <inotify_read_events+0x11f>
jmp    119d <inotify_read_events+0x5d>
jmp    1302 <inotify_read_events+0x1c2>
mov    -0x10(%rbp),%rsi
mov    -0x44(%rbp),%edx
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1030 <test_msg@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x48(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inotify_read_events>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
mov    %rdx,%r13
mov    %rdi,-0x38(%rbp)
mov    0x2e8e(%rip),%rax
movslq (%rax),%rax
lea    0x0(,%rax,8),%rdx
sub    $0xffffff80,%edx
mov    %rsp,%r15
lea    0x8f(,%rax,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    %esi,-0x2c(%rbp)
mov    %esi,%edi
mov    %r15,%rsi
mov    %rdx,-0x40(%rbp)
call   1040 <read@plt>
xor    %ebx,%ebx
test   %eax,%eax
js     1244 <inotify_read_events+0x104>
mov    %r15,-0x48(%rbp)
jmp    11c7 <inotify_read_events+0x87>
cs nopw 0x0(%rax,%rax,1)
mov    -0x2c(%rbp),%edi
mov    %r15,%rsi
mov    -0x40(%rbp),%rdx
call   1040 <read@plt>
test   %eax,%eax
js     1244 <inotify_read_events+0x104>
test   %eax,%eax
je     125a <inotify_read_events+0x11a>
xor    %ecx,%ecx
mov    %eax,-0x30(%rbp)
jmp    11fa <inotify_read_events+0xba>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%ebx
mov    -0x48(%rbp),%r15
mov    0x8(%r15,%r14,1),%eax
lea    (%r14,%rax,1),%ecx
add    $0x10,%ecx
mov    -0x30(%rbp),%eax
cmp    %eax,%ecx
jge    11b0 <inotify_read_events+0x70>
movslq %ecx,%r14
mov    (%r15,%r14,1),%r12d
mov    %r13,%r15
lea    -0xd0(%rbp),%r13
mov    %r13,%rdi
mov    $0x80,%esi
mov    %r12d,%edx
call   1050 <decode_event_mask@plt>
lea    0xeaf(%rip),%rdi
mov    -0x38(%rbp),%rsi
mov    %r12d,%edx
mov    %r13,%rcx
mov    %r15,%r13
xor    %eax,%eax
call   1030 <test_msg@plt>
test   %r15,%r15
je     11e0 <inotify_read_events+0xa0>
not    %r12d
and    %r12d,0x0(%r13)
jmp    11e0 <inotify_read_events+0xa0>
mov    0x2d8d(%rip),%rax
mov    (%rax),%r14
mov    0x2d73(%rip),%rax
cmp    (%rax),%r14
jne    1273 <inotify_read_events+0x133>
lea    0xe8b(%rip),%rdi
xor    %r14d,%r14d
mov    -0x38(%rbp),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <test_msg@plt>
jmp    12a1 <inotify_read_events+0x161>
mov    %r14,%rdi
call   1060 <strerror@plt>
lea    0xd7e(%rip),%rdi
lea    0xdaf(%rip),%rsi
mov    $0x52,%edx
mov    %r14,%rcx
mov    %eax,%r8d
xor    %eax,%eax
call   1030 <test_msg@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.inotify_event = type { i32, i64 }
@PATH_MAX = global i32 0
@errno = global i64 0
@EAGAIN = global i64 0
@.str = [56 x i8] c"ERR: %s:%d: Can't read inotify queue (errno = %d (%s))\0A\00"
@.str.1 = [153 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/LK4D4/criu/refs/heads/master/test/zdtm/live/static/inotify00.c\00"
@.str.2 = [27 x i8] c"\09%-16s: event %x -> %s\0A\00"
@.str.3 = [25 x i8] c"\09%-16s: read %2d events\0A\00"
define i32 @inotify_read_events(i8* %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca %struct.inotify_event*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca [128 x i8]
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32* %2, i32** %7
%16 = load i32, i32* @PATH_MAX
%17 = sext i32 %16 to i64
%18 = add i64 16, %17
%19 = mul i64 %18, 8
%20 = call i8* @llvm.stacksave()
store i8* %20, i8** %9
%21 = alloca i8, i64 %19
store i64 %19, i64* %10
store i32 0, i32* %13
br label %22
22: ; preds = %87, %3
br label %23
23: ; preds = %22
%24 = load i32, i32* %6
%25 = trunc i64 %19 to i32
%26 = call i32 @read(i32 %24, i8* %21, i32 %25)
store i32 %26, i32* %11
%27 = load i32, i32* %11
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %39
29: ; preds = %23
%30 = load i64, i64* @errno
%31 = load i64, i64* @EAGAIN
%32 = icmp ne i64 %30, %31
br i1 %32, label %33, label %38
33: ; preds = %29
%34 = load i64, i64* @errno
%35 = load i64, i64* @errno
%36 = call i32 @strerror(i64 %35)
%37 = call i32 (i8*, i8*, i32, ...) @test_msg(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([153 x i8], [153 x i8]* @.str.1, i64 0, i64 0), i32 82, i64 %34, i32 %36)
store i32 -1, i32* %4
store i32 1, i32* %14
br label %94
38: ; preds = %29
store i32 0, i32* %11
br label %89
39: ; preds = %23
%40 = load i32, i32* %11
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %39
br label %88
43: ; preds = %39
br label %44
44: ; preds = %43
store i32 0, i32* %12
br label %45
45: ; preds = %76, %44
%46 = load i32, i32* %12
%47 = load i32, i32* %11
%48 = icmp slt i32 %46, %47
br i1 %48, label %49, label %87
49: ; preds = %45
%50 = load i32, i32* %12
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %21, i64 %51
%53 = bitcast i8* %52 to %struct.inotify_event*
store %struct.inotify_event* %53, %struct.inotify_event** %8
%54 = getelementptr inbounds [128 x i8], [128 x i8]* %15, i64 0, i64 0
%55 = load %struct.inotify_event*, %struct.inotify_event** %8
%56 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %55, i32 0, i32 0
%57 = load i32, i32* %56
%58 = call i32 @decode_event_mask(i8* %54, i32 128, i32 %57)
%59 = load i8*, i8** %5
%60 = load %struct.inotify_event*, %struct.inotify_event** %8
%61 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %60, i32 0, i32 0
%62 = load i32, i32* %61
%63 = getelementptr inbounds [128 x i8], [128 x i8]* %15, i64 0, i64 0
%64 = call i32 (i8*, i8*, i32, ...) @test_msg(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %59, i32 %62, i8* %63)
%65 = load i32*, i32** %7
%66 = icmp ne i32* %65, null
br i1 %66, label %67, label %75
67: ; preds = %49
%68 = load %struct.inotify_event*, %struct.inotify_event** %8
%69 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %68, i32 0, i32 0
%70 = load i32, i32* %69
%71 = xor i32 %70, -1
%72 = load i32*, i32** %7
%73 = load i32, i32* %72
%74 = and i32 %73, %71
store i32 %74, i32* %72
br label %75
75: ; preds = %67, %49
br label %76
76: ; preds = %75
%77 = load i32, i32* %13
%78 = add nsw i32 %77, 1
store i32 %78, i32* %13
%79 = load %struct.inotify_event*, %struct.inotify_event** %8
%80 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %79, i32 0, i32 1
%81 = load i64, i64* %80
%82 = add i64 16, %81
%83 = load i32, i32* %12
%84 = sext i32 %83 to i64
%85 = add i64 %84, %82
%86 = trunc i64 %85 to i32
store i32 %86, i32* %12
br label %45
87: ; preds = %45
br label %22
88: ; preds = %42
br label %89
89: ; preds = %88, %38
%90 = load i8*, i8** %5
%91 = load i32, i32* %13
%92 = call i32 (i8*, i8*, i32, ...) @test_msg(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %90, i32 %91)
%93 = load i32, i32* %11
store i32 %93, i32* %4
store i32 1, i32* %14
br label %94
94: ; preds = %89, %33
%95 = load i8*, i8** %9
%96 = load i32, i32* %4
ret i32 %96
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@errno = global i64 0
@EAGAIN = global i64 0
@.str = [56 x i8] c"ERR: %s:%d: Can't read inotify queue (errno = %d (%s))\0A\00"
@.str.1 = [153 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/LK4D4/criu/refs/heads/master/test/zdtm/live/static/inotify00.c\00"
@.str.2 = [27 x i8] c"\09%-16s: event %x -> %s\0A\00"
@.str.3 = [25 x i8] c"\09%-16s: read %2d events\0A\00"
define i32 @inotify_read_events(i8* %0, i32 %1, i32* %2) {
%4 = alloca [128 x i8]
%5 = load i32, i32* @PATH_MAX
%6 = sext i32 %5 to i64
%7 = shl nsw i64 %6, 3
%8 = add nsw i64 %7, 128
%9 = alloca i8, i64 %8
%10 = trunc i64 %8 to i32
%11 = call i32 @read(i32 %1, i8* %9, i32 %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %19, label %13
13: ; preds = %3
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%15 = icmp eq i32* %2, null
br label %27
16: ; preds = %44
%17 = call i32 @read(i32 %1, i8* %9, i32 %10)
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %27
19: ; preds = %16, %3
%20 = phi i32 [ 0, %3 ], [ %45, %16 ]
%21 = load i64, i64* @errno
%22 = load i64, i64* @EAGAIN
%23 = icmp eq i64 %21, %22
br i1 %23, label %53, label %24
24: ; preds = %19
%25 = call i32 @strerror(i64 %21)
%26 = call i32 (i8*, i8*, i32, ...) @test_msg(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([153 x i8], [153 x i8]* @.str.1, i64 0, i64 0), i32 82, i64 %21, i32 %25)
br label %56
27: ; preds = %13, %16
%28 = phi i32 [ %11, %13 ], [ %17, %16 ]
%29 = phi i32 [ 0, %13 ], [ %45, %16 ]
%30 = icmp eq i32 %28, 0
br i1 %30, label %53, label %31
31: ; preds = %27, %44
%32 = phi i32 [ %45, %44 ], [ %29, %27 ]
%33 = phi i32 [ %51, %44 ], [ 0, %27 ]
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %9, i64 %34
%36 = bitcast i8* %35 to i32*
%37 = load i32, i32* %36
%38 = call i32 @decode_event_mask(i8* %14, i32 128, i32 %37)
%39 = call i32 (i8*, i8*, i32, ...) @test_msg(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32 %37, i8* %14)
br i1 %15, label %44, label %40
40: ; preds = %31
%41 = xor i32 %37, -1
%42 = load i32, i32* %2
%43 = and i32 %42, %41
store i32 %43, i32* %2
br label %44
44: ; preds = %40, %31
%45 = add nsw i32 %32, 1
%46 = getelementptr inbounds i8, i8* %35, i64 8
%47 = bitcast i8* %46 to i64*
%48 = load i64, i64* %47
%49 = trunc i64 %48 to i32
%50 = add i32 %33, 16
%51 = add i32 %50, %49
%52 = icmp slt i32 %51, %28
br i1 %52, label %31, label %16
53: ; preds = %27, %19
%54 = phi i32 [ %20, %19 ], [ %29, %27 ]
%55 = call i32 (i8*, i8*, i32, ...) @test_msg(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %0, i32 %54)
br label %56
56: ; preds = %53, %24
%57 = phi i32 [ -1, %24 ], [ 0, %53 ]
ret i32 %57
}