#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*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ emulate_mouse(int);
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int fd;
  char *device;
  if (argc < 2) {
    printf("Not enough inputs!\n");
    printf("Use: mouseDriver <device>\n");
    printf("<device> = /dev/hidraw1, for example\n");
    exit(1);
  }
  device = argv[1];
  fd = open(device, O_RDONLY);
  if (fd < 0) {
    printf("\nError(%d) opening device: %s\n", fd, device);
    printf("Try changing permissions: sudo chmod 666 %s\n\n", device);
    exit(2);
  }
  emulate_mouse(fd);
  close(fd);
  exit(3);
}


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)
cmpl   $0x2,-0x8(%rbp)
jge    11a4 <main+0x54>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2e2d(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1200 <main+0xb0>
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x2,%edi
call   1060 <exit@plt>
mov    -0x14(%rbp),%edi
call   1070 <emulate_mouse@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    $0x3,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x1,%edi
jg     1196 <main+0x36>
lea    0xede(%rip),%rdi
call   1030 <puts@plt>
lea    0xee5(%rip),%rdi
call   1030 <puts@plt>
lea    0xef3(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x8(%rsi),%rbx
mov    0x2e47(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    11df <main+0x7f>
lea    0xe48(%rip),%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe54(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x2,%edi
call   1070 <exit@plt>
mov    %ebp,%edi
call   1080 <emulate_mouse@plt>
mov    %ebp,%edi
call   1050 <close@plt>
mov    $0x3,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"Not enough inputs!\0A\00"
@.str.1 = [27 x i8] c"Use: mouseDriver <device>\0A\00"
@.str.2 = [38 x i8] c"<device> = /dev/hidraw1, for example\0A\00"
@O_RDONLY = global i32 0
@.str.3 = [31 x i8] c"\0AError(%d) opening device: %s\0A\00"
@.str.4 = [46 x i8] c"Try changing permissions: sudo chmod 666 %s\0A\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 = icmp slt i32 %8, 2
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
store i8* %18, i8** %7
%19 = load i8*, i8** %7
%20 = load i32, i32* @O_RDONLY
%21 = call i32 @open(i8* %19, i32 %20)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %31
24: ; preds = %15
%25 = load i32, i32* %6
%26 = load i8*, i8** %7
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %25, i8* %26)
%28 = load i8*, i8** %7
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i8* %28)
%30 = call i32 @exit(i32 2)
unreachable
31: ; preds = %15
%32 = load i32, i32* %6
%33 = call i32 @emulate_mouse(i32 %32)
%34 = load i32, i32* %6
%35 = call i32 @close(i32 %34)
%36 = call i32 @exit(i32 3)
unreachable
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str.3 = [31 x i8] c"\0AError(%d) opening device: %s\0A\00"
@.str.4 = [46 x i8] c"Try changing permissions: sudo chmod 666 %s\0A\0A\00"
@str = [19 x i8] c"Not enough inputs!\00"
@str.5 = [26 x i8] c"Use: mouseDriver <device>\00"
@str.6 = [37 x i8] c"<device> = /dev/hidraw1, for example\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.5, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.6, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = load i32, i32* @O_RDONLY
%13 = tail call i32 @open(i8* %11, i32 %12)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %9
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %13, i8* %11)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i8* %11)
%18 = tail call i32 @exit(i32 2)
unreachable
19: ; preds = %9
%20 = tail call i32 @emulate_mouse(i32 %13)
%21 = tail call i32 @close(i32 %13)
%22 = tail call i32 @exit(i32 3)
unreachable
}