#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;
};
typedef int /*<<< orphan*/ ev;

/* Variables and functions */
int /*<<< orphan*/ EVIOCGRAB;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ exit(int);
scalar_t__ ioctl(int, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
scalar_t__ read_all(int, struct input_event *, int);
void *events_eater(void *_arg) {
  struct input_event ev;
  char *arg = _arg;
  int fd = open(arg, O_RDONLY);
  if (fd < 0) {
    perror("evdev open");
    exit(1);
  }
  if (ioctl(fd, EVIOCGRAB, 1) < 0) {
    perror("EVIOCGRAB");
    exit(1);
  }
  while (1) {
    if (read_all(fd, &ev, sizeof(ev)) <= 0)
      return 0;
  }
}


x86 assembly (clang, -O0):
<events_eater>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e79(%rip),%rax
mov    (%rax),%esi
call   1040 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1199 <events_eater+0x49>
lea    0xe76(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x1c(%rbp),%edi
mov    0x2e3d(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    11cf <events_eater+0x7f>
lea    0xe4b(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    11d4 <events_eater+0x84>
mov    -0x1c(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1070 <read_all@plt>
cmp    $0x0,%rax
jg     11f7 <events_eater+0xa7>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret
jmp    11d4 <events_eater+0x84>

x86 assembly (clang, -O2):
<events_eater>:
push   %r14
push   %rbx
push   %rax
mov    0x2e8d(%rip),%rax
mov    (%rax),%esi
call   1040 <open@plt>
test   %eax,%eax
js     11ae <events_eater+0x5e>
mov    %eax,%ebx
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    $0x1,%edx
call   1030 <ioctl@plt>
test   %rax,%rax
js     11b7 <events_eater+0x67>
mov    %rsp,%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1070 <read_all@plt>
test   %rax,%rax
jg     1190 <events_eater+0x40>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe4b(%rip),%rdi
jmp    11be <events_eater+0x6e>
lea    0xe4d(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.input_event = type { i32 }
@O_RDONLY = global i32 0
@.str = [11 x i8] c"evdev open\00"
@EVIOCGRAB = global i32 0
@.str.1 = [10 x i8] c"EVIOCGRAB\00"
define i8* @events_eater(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.input_event
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = load i32, i32* @O_RDONLY
%9 = call i32 @open(i8* %7, i32 %8)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %1
%16 = load i32, i32* %5
%17 = load i32, i32* @EVIOCGRAB
%18 = call i64 @ioctl(i32 %16, i32 %17, i32 1)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %15
br label %24
24: ; preds = %23, %29
%25 = load i32, i32* %5
%26 = call i64 @read_all(i32 %25, %struct.input_event* %3, i32 4)
%27 = icmp sle i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %24
ret i8* null
29: ; preds = %24
br label %24
}

LLVM IR (-O2):
%struct.input_event = type { i32 }
@O_RDONLY = global i32 0
@.str = [11 x i8] c"evdev open\00"
@EVIOCGRAB = global i32 0
@.str.1 = [10 x i8] c"EVIOCGRAB\00"
define noalias i8* @events_eater(i8* nocapture %0) {
%2 = alloca %struct.input_event
%3 = bitcast %struct.input_event* %2 to i8*
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* %0, i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %1
%11 = load i32, i32* @EVIOCGRAB
%12 = tail call i64 @ioctl(i32 %5, i32 %11, i32 1)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = tail call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %10, %17
%18 = call i64 @read_all(i32 %5, %struct.input_event* %2, i32 4)
%19 = icmp slt i64 %18, 1
br i1 %19, label %20, label %17
20: ; preds = %17
ret i8* null
}