#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*/ uint8_t;
struct inotify_event {
  int len;
};

/* Variables and functions */
struct inotify_event *for_event(struct inotify_event *e, uint8_t *buf,
                                size_t len) {
  uint8_t *tmp;
  if (e == NULL)
    return (struct inotify_event *)buf;
  tmp = (uint8_t *)e + sizeof(struct inotify_event) + e->len;
  if (tmp < buf + len)
    return (struct inotify_event *)tmp;
  return NULL;
}


x86 assembly (clang, -O0):
<for_event>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1128 <for_event+0x28>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1173 <for_event+0x73>
mov    -0x10(%rbp),%rax
add    $0x10,%rax
mov    -0x10(%rbp),%rcx
movslq (%rcx),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%rdx
shl    $0x2,%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
jae    116b <for_event+0x6b>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1173 <for_event+0x73>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<for_event>:
mov    %rsi,%rax
test   %rdi,%rdi
je     1120 <for_event+0x20>
movslq (%rdi),%rcx
lea    (%rdi,%rcx,4),%rcx
add    $0x10,%rcx
lea    (%rax,%rdx,4),%rdx
xor    %eax,%eax
cmp    %rdx,%rcx
cmovb  %rcx,%rax
ret

LLVM IR (-O0):
%struct.inotify_event = type { i32 }
define %struct.inotify_event* @for_event(%struct.inotify_event* %0, i32* %1, i64 %2) {
%4 = alloca %struct.inotify_event*
%5 = alloca %struct.inotify_event*
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i32*
store %struct.inotify_event* %0, %struct.inotify_event** %5
store i32* %1, i32** %6
store i64 %2, i64* %7
%9 = load %struct.inotify_event*, %struct.inotify_event** %5
%10 = icmp eq %struct.inotify_event* %9, null
br i1 %10, label %11, label %14
11: ; preds = %3
%12 = load i32*, i32** %6
%13 = bitcast i32* %12 to %struct.inotify_event*
store %struct.inotify_event* %13, %struct.inotify_event** %4
br label %32
14: ; preds = %3
%15 = load %struct.inotify_event*, %struct.inotify_event** %5
%16 = bitcast %struct.inotify_event* %15 to i32*
%17 = getelementptr inbounds i32, i32* %16, i64 4
%18 = load %struct.inotify_event*, %struct.inotify_event** %5
%19 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %18, i32 0, i32 0
%20 = load i32, i32* %19
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %17, i64 %21
store i32* %22, i32** %8
%23 = load i32*, i32** %8
%24 = load i32*, i32** %6
%25 = load i64, i64* %7
%26 = getelementptr inbounds i32, i32* %24, i64 %25
%27 = icmp ult i32* %23, %26
br i1 %27, label %28, label %31
28: ; preds = %14
%29 = load i32*, i32** %8
%30 = bitcast i32* %29 to %struct.inotify_event*
store %struct.inotify_event* %30, %struct.inotify_event** %4
br label %32
31: ; preds = %14
store %struct.inotify_event* null, %struct.inotify_event** %4
br label %32
32: ; preds = %31, %28, %11
%33 = load %struct.inotify_event*, %struct.inotify_event** %4
ret %struct.inotify_event* %33
}

LLVM IR (-O2):
%struct.inotify_event = type { i32 }
define %struct.inotify_event* @for_event(%struct.inotify_event* %0, i32* readnone %1, i64 %2) {
%4 = icmp eq %struct.inotify_event* %0, null
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = bitcast i32* %1 to %struct.inotify_event*
br label %17
7: ; preds = %3
%8 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %0, i64 4, i32 0
%9 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %0, i64 0, i32 0
%10 = load i32, i32* %9
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i32, i32* %8, i64 %11
%13 = getelementptr inbounds i32, i32* %1, i64 %2
%14 = icmp ult i32* %12, %13
%15 = bitcast i32* %12 to %struct.inotify_event*
%16 = select i1 %14, %struct.inotify_event* %15, %struct.inotify_event* null
br label %17
17: ; preds = %7, %5
%18 = phi %struct.inotify_event* [ %6, %5 ], [ %16, %7 ]
ret %struct.inotify_event* %18
}