#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 */
scalar_t__ EACCES;
int /*<<< orphan*/ O_RDONLY;
scalar_t__ errno;
int /*<<< orphan*/ fileno(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ getuid();
int /*<<< orphan*/ isatty(int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
char *parse_args(int, char **);
int /*<<< orphan*/ perror(char *);
scalar_t__ print_device_info(int);
int print_events(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ setbuf(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
scalar_t__ test_grab(int);
int main(int argc, char **argv) {
  int fd;
  char *filename;
  filename = parse_args(argc, argv);
  if (!filename)
    return 1;
  if ((fd = open(filename, O_RDONLY)) < 0) {
    perror("evtest");
    if (errno == EACCES && getuid() != 0)
      fprintf(stderr,
              "You do not have access to %s. Try "
              "running as root instead.\n",
              filename);
    return 1;
  }
  free(filename);
  if (!isatty(fileno(stdout)))
    setbuf(stdout, NULL);
  if (print_device_info(fd))
    return 1;
  printf("Testing ... (interrupt to exit)\n");
  if (test_grab(fd)) {
    printf("***********************************************\n");
    printf("  This device is grabbed by another process.\n");
    printf("  No events are available to evtest while the\n"
           "  other grab is active.\n");
    printf("  In most cases, this is caused by an X driver,\n"
           "  try VT-switching and re-run evtest again.\n");
    printf("***********************************************\n");
  }
  return print_events(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   10a0 <parse_args@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    120d <main+0x3d>
movl   $0x1,-0x4(%rbp)
jmp    1343 <main+0x173>
mov    -0x20(%rbp),%rdi
mov    0x2dd0(%rip),%rax
mov    (%rax),%esi
call   10d0 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1287 <main+0xb7>
lea    0xdce(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2d8a(%rip),%rax
mov    (%rax),%rax
mov    0x2d98(%rip),%rcx
cmp    (%rcx),%rax
jne    127b <main+0xab>
mov    $0x0,%al
call   1070 <getuid@plt>
cmp    $0x0,%rax
je     127b <main+0xab>
mov    0x2d67(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xd91(%rip),%rsi
call   10b0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1343 <main+0x173>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    0x2d29(%rip),%rax
mov    (%rax),%edi
call   10c0 <fileno@plt>
mov    %eax,%edi
call   1040 <isatty@plt>
cmp    $0x0,%eax
jne    12c0 <main+0xf0>
mov    0x2d0b(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1080 <setbuf@plt>
mov    -0x14(%rbp),%edi
call   10f0 <print_device_info@plt>
cmp    $0x0,%rax
je     12de <main+0x10e>
movl   $0x1,-0x4(%rbp)
jmp    1343 <main+0x173>
lea    0xd5e(%rip),%rdi
call   1090 <printf@plt>
mov    -0x14(%rbp),%edi
call   1060 <test_grab@plt>
cmp    $0x0,%rax
je     1338 <main+0x168>
lea    0xd61(%rip),%rdi
call   1090 <printf@plt>
lea    0xd86(%rip),%rdi
call   1090 <printf@plt>
lea    0xda8(%rip),%rdi
call   1090 <printf@plt>
lea    0xde3(%rip),%rdi
call   1090 <printf@plt>
lea    0xd31(%rip),%rdi
call   1090 <printf@plt>
mov    -0x14(%rbp),%edi
call   1050 <print_events@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
call   10a0 <parse_args@plt>
test   %rax,%rax
je     1231 <main+0x61>
mov    %rax,%rbx
mov    0x2e01(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10d0 <open@plt>
test   %eax,%eax
js     129d <main+0xcd>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x2db6(%rip),%rbx
mov    (%rbx),%edi
call   10c0 <fileno@plt>
mov    %eax,%edi
call   1050 <isatty@plt>
test   %eax,%eax
jne    1225 <main+0x55>
mov    (%rbx),%edi
xor    %esi,%esi
call   1090 <setbuf@plt>
mov    %ebp,%edi
call   10f0 <print_device_info@plt>
test   %rax,%rax
je     123d <main+0x6d>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xdff(%rip),%rdi
call   1040 <puts@plt>
mov    %ebp,%edi
call   1070 <test_grab@plt>
test   %rax,%rax
je     1290 <main+0xc0>
lea    0xed6(%rip),%rbx
mov    %rbx,%rdi
call   1040 <puts@plt>
lea    0xdf8(%rip),%rdi
call   1040 <puts@plt>
lea    0xe19(%rip),%rdi
call   1040 <puts@plt>
lea    0xe53(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    %ebp,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1060 <print_events@plt>
lea    0xd5c(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2d18(%rip),%rax
mov    (%rax),%rax
mov    0x2d26(%rip),%rcx
cmp    (%rcx),%rax
jne    1231 <main+0x61>
xor    %eax,%eax
call   1080 <getuid@plt>
test   %rax,%rax
je     1231 <main+0x61>
mov    0x2cf6(%rip),%rax
mov    (%rax),%edi
lea    0xd24(%rip),%rsi
mov    %rbx,%rdx
call   10b0 <fprintf@plt>
jmp    1231 <main+0x61>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [7 x i8] c"evtest\00"
@errno = global i64 0
@EACCES = global i64 0
@stderr = global i32 0
@.str.1 = [60 x i8] c"You do not have access to %s. Try running as root instead.\0A\00"
@stdout = global i32 0
@.str.2 = [33 x i8] c"Testing ... (interrupt to exit)\0A\00"
@.str.3 = [49 x i8] c"***********************************************\0A\00"
@.str.4 = [46 x i8] c" This device is grabbed by another process.\0A\00"
@.str.5 = [71 x i8] c" No events are available to evtest while the\0A other grab is active.\0A\00"
@.str.6 = [93 x i8] c" In most cases, this is caused by an X driver,\0A try VT-switching and re-run evtest again.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = load i8**, i8*** %5
%10 = call i8* @parse_args(i32 %8, i8** %9)
store i8* %10, i8** %7
%11 = load i8*, i8** %7
%12 = icmp ne i8* %11, null
br i1 %12, label %14, label %13
13: ; preds = %2
store i32 1, i32* %3
br label %61
14: ; preds = %2
%15 = load i8*, i8** %7
%16 = load i32, i32* @O_RDONLY
%17 = call i32 @open(i8* %15, i32 %16)
store i32 %17, i32* %6
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %32
19: ; preds = %14
%20 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%21 = load i64, i64* @errno
%22 = load i64, i64* @EACCES
%23 = icmp eq i64 %21, %22
br i1 %23, label %24, label %31
24: ; preds = %19
%25 = call i64 (...) @getuid()
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %24
%28 = load i32, i32* @stderr
%29 = load i8*, i8** %7
%30 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0), i8* %29)
br label %31
31: ; preds = %27, %24, %19
store i32 1, i32* %3
br label %61
32: ; preds = %14
%33 = load i8*, i8** %7
%34 = call i32 @free(i8* %33)
%35 = load i32, i32* @stdout
%36 = call i32 @fileno(i32 %35)
%37 = call i32 @isatty(i32 %36)
%38 = icmp ne i32 %37, 0
br i1 %38, label %42, label %39
39: ; preds = %32
%40 = load i32, i32* @stdout
%41 = call i32 @setbuf(i32 %40, i32* null)
br label %42
42: ; preds = %39, %32
%43 = load i32, i32* %6
%44 = call i64 @print_device_info(i32 %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %42
store i32 1, i32* %3
br label %61
47: ; preds = %42
%48 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
%49 = load i32, i32* %6
%50 = call i64 @test_grab(i32 %49)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %58
52: ; preds = %47
%53 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0))
%54 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0))
%55 = call i32 @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.5, i64 0, i64 0))
%56 = call i32 @printf(i8* getelementptr inbounds ([93 x i8], [93 x i8]* @.str.6, i64 0, i64 0))
%57 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0))
br label %58
58: ; preds = %52, %47
%59 = load i32, i32* %6
%60 = call i32 @print_events(i32 %59)
store i32 %60, i32* %3
br label %61
61: ; preds = %58, %46, %31, %13
%62 = load i32, i32* %3
ret i32 %62
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [7 x i8] c"evtest\00"
@errno = global i64 0
@EACCES = global i64 0
@stderr = global i32 0
@.str.1 = [60 x i8] c"You do not have access to %s. Try running as root instead.\0A\00"
@stdout = global i32 0
@str = [32 x i8] c"Testing ... (interrupt to exit)\00"
@str.8 = [45 x i8] c" This device is grabbed by another process.\00"
@str.9 = [70 x i8] c" No events are available to evtest while the\0A other grab is active.\00"
@str.10 = [92 x i8] c" In most cases, this is caused by an X driver,\0A try VT-switching and re-run evtest again.\00"
@str.11 = [48 x i8] c"***********************************************\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i8* @parse_args(i32 %0, i8** %1)
%4 = icmp eq i8* %3, null
br i1 %4, label %44, label %5
5: ; preds = %2
%6 = load i32, i32* @O_RDONLY
%7 = tail call i32 @open(i8* %3, i32 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %20
9: ; preds = %5
%10 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%11 = load i64, i64* @errno
%12 = load i64, i64* @EACCES
%13 = icmp eq i64 %11, %12
br i1 %13, label %14, label %44
14: ; preds = %9
%15 = tail call i64 (...) @getuid()
%16 = icmp eq i64 %15, 0
br i1 %16, label %44, label %17
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0), i8* %3)
br label %44
20: ; preds = %5
%21 = tail call i32 @free(i8* %3)
%22 = load i32, i32* @stdout
%23 = tail call i32 @fileno(i32 %22)
%24 = tail call i32 @isatty(i32 %23)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %20
%27 = load i32, i32* @stdout
%28 = tail call i32 @setbuf(i32 %27, i32* null)
br label %29
29: ; preds = %26, %20
%30 = tail call i64 @print_device_info(i32 %7)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %44
32: ; preds = %29
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
%34 = tail call i64 @test_grab(i32 %7)
%35 = icmp eq i64 %34, 0
br i1 %35, label %42, label %36
36: ; preds = %32
%37 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str.11, i64 0, i64 0))
%38 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.8, i64 0, i64 0))
%39 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([70 x i8], [70 x i8]* @str.9, i64 0, i64 0))
%40 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([92 x i8], [92 x i8]* @str.10, i64 0, i64 0))
%41 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str.11, i64 0, i64 0))
br label %42
42: ; preds = %36, %32
%43 = tail call i32 @print_events(i32 %7)
br label %44
44: ; preds = %29, %9, %14, %17, %2, %42
%45 = phi i32 [ %43, %42 ], [ 1, %2 ], [ 1, %17 ], [ 1, %14 ], [ 1, %9 ], [ 1, %29 ]
ret i32 %45
}