#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 len;
};

/* Variables and functions */
int /*<<< orphan*/ evh(struct inotify_event *);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
void hee(int ino) {
  char buf[4096], *s = buf;
  int r;
  if ((r = read(ino, buf, 4096)) <= 0) {
    perror("read/ino");
    return;
  }
  while (1) {
    struct inotify_event *ev = (struct inotify_event *)s;
    evh(ev);
    int l = (sizeof(struct inotify_event)) + ev->len;
    if ((r -= l) <= 0)
      return;
    else
      s += l;
  }
}


x86 assembly (clang, -O0):
<hee>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x1010(%rbp),%rax
mov    %rax,-0x1018(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x1010(%rbp),%rsi
mov    $0x1000,%edx
call   1040 <read@plt>
mov    %eax,-0x101c(%rbp)
cmp    $0x0,%eax
jg     1180 <hee+0x50>
lea    0xe8a(%rip),%rdi
call   1050 <perror@plt>
jmp    11f4 <hee+0xc4>
jmp    1185 <hee+0x55>
mov    -0x1018(%rbp),%rax
mov    %rax,-0x1028(%rbp)
mov    -0x1028(%rbp),%rdi
call   1030 <evh@plt>
mov    -0x1028(%rbp),%rax
movslq (%rax),%rax
add    $0x4,%rax
mov    %eax,-0x102c(%rbp)
mov    -0x102c(%rbp),%ecx
mov    -0x101c(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x101c(%rbp)
cmp    $0x0,%eax
jg     11d5 <hee+0xa5>
jmp    11f4 <hee+0xc4>
mov    -0x102c(%rbp),%ecx
mov    -0x1018(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x1018(%rbp)
jmp    1185 <hee+0x55>
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hee>:
push   %rbp
push   %rbx
sub    $0x1008,%rsp
mov    %rsp,%rbx
mov    %rbx,%rsi
mov    $0x1000,%edx
call   1040 <read@plt>
test   %eax,%eax
jle    1170 <hee+0x40>
mov    %eax,%ebp
nop
mov    %rbx,%rdi
call   1030 <evh@plt>
mov    (%rbx),%eax
add    $0x4,%eax
cltq
add    %rax,%rbx
sub    %eax,%ebp
jg     1150 <hee+0x20>
add    $0x1008,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe89(%rip),%rdi
add    $0x1008,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <perror@plt>

LLVM IR (-O0):
%struct.inotify_event = type { i32 }
@.str = [9 x i8] c"read/ino\00"
define void @hee(i32 %0) {
%2 = alloca i32
%3 = alloca [4096 x i8]
%4 = alloca i8*
%5 = alloca i32
%6 = alloca %struct.inotify_event*
%7 = alloca i32
store i32 %0, i32* %2
%8 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
store i8* %8, i8** %4
%9 = load i32, i32* %2
%10 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%11 = call i32 @read(i32 %9, i8* %10, i32 4096)
store i32 %11, i32* %5
%12 = icmp sle i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %38
15: ; preds = %1
br label %16
16: ; preds = %15, %37
%17 = load i8*, i8** %4
%18 = bitcast i8* %17 to %struct.inotify_event*
store %struct.inotify_event* %18, %struct.inotify_event** %6
%19 = load %struct.inotify_event*, %struct.inotify_event** %6
%20 = call i32 @evh(%struct.inotify_event* %19)
%21 = load %struct.inotify_event*, %struct.inotify_event** %6
%22 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %21, i32 0, i32 0
%23 = load i32, i32* %22
%24 = sext i32 %23 to i64
%25 = add i64 4, %24
%26 = trunc i64 %25 to i32
store i32 %26, i32* %7
%27 = load i32, i32* %7
%28 = load i32, i32* %5
%29 = sub nsw i32 %28, %27
store i32 %29, i32* %5
%30 = icmp sle i32 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %16
br label %38
32: ; preds = %16
%33 = load i32, i32* %7
%34 = load i8*, i8** %4
%35 = sext i32 %33 to i64
%36 = getelementptr inbounds i8, i8* %34, i64 %35
store i8* %36, i8** %4
br label %37
37: ; preds = %32
br label %16
38: ; preds = %31, %13
ret void
}

LLVM IR (-O2):
%struct.inotify_event = type { i32 }
@.str = [9 x i8] c"read/ino\00"
define void @hee(i32 %0) {
%2 = alloca [4096 x i8]
%3 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%4 = call i32 @read(i32 %0, i8* %3, i32 4096)
%5 = icmp slt i32 %4, 1
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %20
8: ; preds = %1, %8
%9 = phi i32 [ %16, %8 ], [ %4, %1 ]
%10 = phi i8* [ %19, %8 ], [ %3, %1 ]
%11 = bitcast i8* %10 to %struct.inotify_event*
%12 = call i32 @evh(%struct.inotify_event* %11)
%13 = bitcast i8* %10 to i32*
%14 = load i32, i32* %13
%15 = add i32 %14, 4
%16 = sub nsw i32 %9, %15
%17 = icmp slt i32 %16, 1
%18 = sext i32 %15 to i64
%19 = getelementptr inbounds i8, i8* %10, i64 %18
br i1 %17, label %20, label %8
20: ; preds = %8, %6
ret void
}