#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 */

/* Variables and functions */
int /*<<< orphan*/ EVIOCGRAB;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int ioctl(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
void grab_device(int in_fd) {
  int ret;
  ret = ioctl(in_fd, EVIOCGRAB, 1);
  if (ret == -1) {
    perror("ioctl");
    fprintf(stderr, "Could not grab the device\n");
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<grab_device>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e93(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edx
call   1030 <ioctl@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    119d <grab_device+0x5d>
lea    0xe8b(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
lea    0xe7c(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<grab_device>:
push   %rax
mov    0x2ea0(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edx
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
je     115b <grab_device+0x1b>
pop    %rax
ret
lea    0xe9e(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
lea    0xe8f(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@EVIOCGRAB = global i32 0
@.str = [6 x i8] c"ioctl\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"Could not grab the device\0A\00"
@EXIT_FAILURE = global i32 0
define void @grab_device(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = load i32, i32* @EVIOCGRAB
%6 = call i32 @ioctl(i32 %4, i32 %5, i32 1)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %15
9: ; preds = %1
%10 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %1
ret void
}

LLVM IR (-O2):
@EVIOCGRAB = global i32 0
@.str = [6 x i8] c"ioctl\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"Could not grab the device\0A\00"
@EXIT_FAILURE = global i32 0
define void @grab_device(i32 %0) {
%2 = load i32, i32* @EVIOCGRAB
%3 = tail call i32 @ioctl(i32 %0, i32 %2, i32 1)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %11
5: ; preds = %1
%6 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %1
ret void
}