#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 O_NONBLOCK;
int O_RDONLY;
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int open_joystick(int fd) {
  fd = open("/dev/input/js0", O_RDONLY | O_NONBLOCK);
  if (fd >= 0)
    printf("Open Joystick Successful\n");
  if (fd < 0)
    perror("/dev/input/js0");
  return fd;
}


x86 assembly (clang, -O0):
<open_joystick>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e9e(%rip),%rax
mov    (%rax),%esi
mov    0x2e9d(%rip),%rax
or     (%rax),%esi
lea    0xeac(%rip),%rdi
call   1040 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jl     1172 <open_joystick+0x42>
lea    0xea2(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x0,-0x4(%rbp)
jge    1188 <open_joystick+0x58>
lea    0xe7d(%rip),%rdi
call   1050 <perror@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_joystick>:
push   %rbx
mov    0x2ea8(%rip),%rax
mov    0x2ea9(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xeb6(%rip),%rdi
call   1040 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
js     1165 <open_joystick+0x35>
lea    0xeb3(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
pop    %rbx
ret
lea    0xe94(%rip),%rdi
call   1050 <perror@plt>
jmp    1161 <open_joystick+0x31>

LLVM IR (-O0):
@.str = [15 x i8] c"/dev/input/js0\00"
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [26 x i8] c"Open Joystick Successful\0A\00"
define i32 @open_joystick(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* @O_RDONLY
%4 = load i32, i32* @O_NONBLOCK
%5 = or i32 %3, %4
%6 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = icmp sge i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %9, %1
%12 = load i32, i32* %2
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %11
%17 = load i32, i32* %2
ret i32 %17
}

LLVM IR (-O2):
@.str = [15 x i8] c"/dev/input/js0\00"
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@str = [25 x i8] c"Open Joystick Successful\00"
define i32 @open_joystick(i32 %0) {
%2 = load i32, i32* @O_RDONLY
%3 = load i32, i32* @O_NONBLOCK
%4 = or i32 %3, %2
%5 = tail call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp sgt i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
br label %11
9: ; preds = %1
%10 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %7, %9
ret i32 %5
}