#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 JS_DATA_TYPE {
  int x;
  int y;
  int buttons;
};

/* Variables and functions */
int /*<<< orphan*/ Error(char *);
int JS_RETURN;
int read(int, struct JS_DATA_TYPE *, int);
int xf86JoystickGetState(int fd, int *x, int *y, int *buttons) {
  struct JS_DATA_TYPE js;
  int status;
  status = read(fd, &js, JS_RETURN);
  if (status != JS_RETURN) {
    Error("Joystick read");
    return 0;
  }
  *x = js.x;
  *y = js.y;
  *buttons = js.buttons;
  return 1;
}


x86 assembly (clang, -O0):
<xf86JoystickGetState>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2ea7(%rip),%rax
mov    (%rax),%edx
lea    -0x30(%rbp),%rsi
call   1040 <read@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    0x2e8f(%rip),%rcx
cmp    (%rcx),%eax
je     1179 <xf86JoystickGetState+0x59>
lea    0xe98(%rip),%rdi
call   1030 <Error@plt>
movl   $0x0,-0x4(%rbp)
jmp    119b <xf86JoystickGetState+0x7b>
mov    -0x30(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x2c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xf86JoystickGetState>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    0x2ead(%rip),%rbx
mov    (%rbx),%edx
lea    0x8(%rsp),%rsi
call   1040 <read@plt>
cmp    (%rbx),%eax
jne    1168 <xf86JoystickGetState+0x48>
mov    0x8(%rsp),%eax
mov    %eax,(%r12)
mov    0xc(%rsp),%eax
mov    %eax,(%r15)
mov    0x10(%rsp),%eax
mov    %eax,(%r14)
mov    $0x1,%eax
jmp    1176 <xf86JoystickGetState+0x56>
lea    0xe91(%rip),%rdi
call   1030 <Error@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.JS_DATA_TYPE = type { i32, i32, i32 }
@JS_RETURN = global i32 0
@.str = [14 x i8] c"Joystick read\00"
define i32 @xf86JoystickGetState(i32 %0, i32* %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca %struct.JS_DATA_TYPE
%11 = alloca i32
store i32 %0, i32* %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
%12 = load i32, i32* %6
%13 = load i32, i32* @JS_RETURN
%14 = call i32 @read(i32 %12, %struct.JS_DATA_TYPE* %10, i32 %13)
store i32 %14, i32* %11
%15 = load i32, i32* %11
%16 = load i32, i32* @JS_RETURN
%17 = icmp ne i32 %15, %16
br i1 %17, label %18, label %20
18: ; preds = %4
%19 = call i32 @Error(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %5
br label %30
20: ; preds = %4
%21 = getelementptr inbounds %struct.JS_DATA_TYPE, %struct.JS_DATA_TYPE* %10, i32 0, i32 0
%22 = load i32, i32* %21
%23 = load i32*, i32** %7
store i32 %22, i32* %23
%24 = getelementptr inbounds %struct.JS_DATA_TYPE, %struct.JS_DATA_TYPE* %10, i32 0, i32 1
%25 = load i32, i32* %24
%26 = load i32*, i32** %8
store i32 %25, i32* %26
%27 = getelementptr inbounds %struct.JS_DATA_TYPE, %struct.JS_DATA_TYPE* %10, i32 0, i32 2
%28 = load i32, i32* %27
%29 = load i32*, i32** %9
store i32 %28, i32* %29
store i32 1, i32* %5
br label %30
30: ; preds = %20, %18
%31 = load i32, i32* %5
ret i32 %31
}

LLVM IR (-O2):
%struct.JS_DATA_TYPE = type { i32, i32, i32 }
@JS_RETURN = global i32 0
@.str = [14 x i8] c"Joystick read\00"
define i32 @xf86JoystickGetState(i32 %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3) {
%5 = alloca %struct.JS_DATA_TYPE
%6 = bitcast %struct.JS_DATA_TYPE* %5 to i8*
%7 = load i32, i32* @JS_RETURN
%8 = call i32 @read(i32 %0, %struct.JS_DATA_TYPE* %5, i32 %7)
%9 = load i32, i32* @JS_RETURN
%10 = icmp eq i32 %8, %9
br i1 %10, label %13, label %11
11: ; preds = %4
%12 = tail call i32 @Error(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %20
13: ; preds = %4
%14 = getelementptr inbounds %struct.JS_DATA_TYPE, %struct.JS_DATA_TYPE* %5, i64 0, i32 0
%15 = load i32, i32* %14
store i32 %15, i32* %1
%16 = getelementptr inbounds %struct.JS_DATA_TYPE, %struct.JS_DATA_TYPE* %5, i64 0, i32 1
%17 = load i32, i32* %16
store i32 %17, i32* %2
%18 = getelementptr inbounds %struct.JS_DATA_TYPE, %struct.JS_DATA_TYPE* %5, i64 0, i32 2
%19 = load i32, i32* %18
store i32 %19, i32* %3
br label %20
20: ; preds = %13, %11
%21 = phi i32 [ 0, %11 ], [ 1, %13 ]
ret i32 %21
}