#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 input_event {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
size_t read(int, struct input_event *, int);
int /*<<< orphan*/ stderr;
int IERead(int fd, struct input_event *ev, int *events) {
  size_t bytes_read = 0;
  bytes_read = read(fd, ev, sizeof(struct input_event) * 64);
  if (bytes_read < (int)sizeof(struct input_event)) {
    fprintf(stderr, "read() failed\n");
    return -1;
  }
  *events = (int)(bytes_read / sizeof(struct input_event));
  return 0;
}


x86 assembly (clang, -O0):
<IERead>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x100,%edx
call   1030 <read@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x4,-0x20(%rbp)
jae    117c <IERead+0x5c>
mov    0x2e7e(%rip),%rax
mov    (%rax),%edi
lea    0xe95(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1193 <IERead+0x73>
mov    -0x20(%rbp),%rax
shr    $0x2,%rax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<IERead>:
push   %rbx
mov    %rdx,%rbx
mov    $0x100,%edx
call   1030 <read@plt>
cmp    $0x3,%rax
ja     1150 <IERead+0x30>
mov    0x2ea5(%rip),%rax
mov    (%rax),%edi
lea    0xebc(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret
shr    $0x2,%rax
mov    %eax,(%rbx)
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.input_event = type { i32 }
@stderr = global i32 0
@.str = [15 x i8] c"read() failed\0A\00"
define i32 @IERead(i32 %0, %struct.input_event* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.input_event*
%7 = alloca i32*
%8 = alloca i64
store i32 %0, i32* %5
store %struct.input_event* %1, %struct.input_event** %6
store i32* %2, i32** %7
store i64 0, i64* %8
%9 = load i32, i32* %5
%10 = load %struct.input_event*, %struct.input_event** %6
%11 = call i64 @read(i32 %9, %struct.input_event* %10, i32 256)
store i64 %11, i64* %8
%12 = load i64, i64* %8
%13 = icmp ult i64 %12, 4
br i1 %13, label %14, label %17
14: ; preds = %3
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %22
17: ; preds = %3
%18 = load i64, i64* %8
%19 = udiv i64 %18, 4
%20 = trunc i64 %19 to i32
%21 = load i32*, i32** %7
store i32 %20, i32* %21
store i32 0, i32* %4
br label %22
22: ; preds = %17, %14
%23 = load i32, i32* %4
ret i32 %23
}

LLVM IR (-O2):
%struct.input_event = type { i32 }
@stderr = global i32 0
@.str = [15 x i8] c"read() failed\0A\00"
define i32 @IERead(i32 %0, %struct.input_event* nocapture %1, i32* nocapture writeonly %2) {
%4 = tail call i64 @read(i32 %0, %struct.input_event* %1, i32 256)
%5 = icmp ult i64 %4, 4
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %12
9: ; preds = %3
%10 = lshr i64 %4, 2
%11 = trunc i64 %10 to i32
store i32 %11, i32* %2
br label %12
12: ; preds = %9, %6
%13 = phi i32 [ -1, %6 ], [ 0, %9 ]
ret i32 %13
}