#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*/ JSIOCGAXES;
int /*<<< orphan*/ JSIOCGBUTTONS;
int /*<<< orphan*/ JSIOCGNAME(int);
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, ...);
char *malloc(int);
int open(char *, int /*<<< orphan*/);
void joystick_info(char *path, unsigned char *n_axes, unsigned char *n_buttons,
                   char **name) {
  int fd;
  fd = open(path, O_RDONLY);
  if (fd > 0) {
    *name = malloc(256);
    if (name != NULL) {
      ioctl(fd, JSIOCGAXES, n_axes);
      ioctl(fd, JSIOCGBUTTONS, n_buttons);
      ioctl(fd, JSIOCGNAME(256), *name);
    }
    close(fd);
    return;
  }
  n_axes = 0;
  n_buttons = 0;
  *name = NULL;
}


x86 assembly (clang, -O0):
<joystick_info>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jle    1204 <joystick_info+0xb4>
mov    $0x100,%edi
call   1050 <malloc@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x20(%rbp)
je     11f7 <joystick_info+0xa7>
mov    -0x24(%rbp),%edi
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1030 <ioctl@plt>
mov    -0x24(%rbp),%edi
mov    0x2e09(%rip),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%rdx
mov    $0x0,%al
call   1030 <ioctl@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    $0x100,%edi
call   1070 <JSIOCGNAME@plt>
mov    -0x28(%rbp),%edi
mov    %eax,%esi
mov    -0x20(%rbp),%rax
mov    (%rax),%rdx
mov    $0x0,%al
call   1030 <ioctl@plt>
mov    -0x24(%rbp),%edi
call   1040 <close@plt>
jmp    121f <joystick_info+0xcf>
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<joystick_info>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
test   %eax,%eax
jle    11d4 <joystick_info+0x84>
mov    %eax,%ebp
mov    $0x100,%edi
call   1050 <malloc@plt>
mov    %rax,(%rbx)
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r15,%rdx
xor    %eax,%eax
call   1030 <ioctl@plt>
mov    0x2e33(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <ioctl@plt>
mov    $0x100,%edi
call   1070 <JSIOCGNAME@plt>
mov    (%rbx),%rdx
mov    %ebp,%edi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <ioctl@plt>
mov    %ebp,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <close@plt>
movq   $0x0,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@JSIOCGAXES = global i32 0
@JSIOCGBUTTONS = global i32 0
define void @joystick_info(i8* %0, i8* %1, i8* %2, i8** %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8**
%9 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8** %3, i8*** %8
%10 = load i8*, i8** %5
%11 = load i32, i32* @O_RDONLY
%12 = call i32 @open(i8* %10, i32 %11)
store i32 %12, i32* %9
%13 = load i32, i32* %9
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %37
15: ; preds = %4
%16 = call i8* @malloc(i32 256)
%17 = load i8**, i8*** %8
store i8* %16, i8** %17
%18 = load i8**, i8*** %8
%19 = icmp ne i8** %18, null
br i1 %19, label %20, label %34
20: ; preds = %15
%21 = load i32, i32* %9
%22 = load i32, i32* @JSIOCGAXES
%23 = load i8*, i8** %6
%24 = call i32 (i32, i32, ...) @ioctl(i32 %21, i32 %22, i8* %23)
%25 = load i32, i32* %9
%26 = load i32, i32* @JSIOCGBUTTONS
%27 = load i8*, i8** %7
%28 = call i32 (i32, i32, ...) @ioctl(i32 %25, i32 %26, i8* %27)
%29 = load i32, i32* %9
%30 = call i32 @JSIOCGNAME(i32 256)
%31 = load i8**, i8*** %8
%32 = load i8*, i8** %31
%33 = call i32 (i32, i32, ...) @ioctl(i32 %29, i32 %30, i8* %32)
br label %34
34: ; preds = %20, %15
%35 = load i32, i32* %9
%36 = call i32 @close(i32 %35)
br label %39
37: ; preds = %4
store i8* null, i8** %6
store i8* null, i8** %7
%38 = load i8**, i8*** %8
store i8* null, i8** %38
br label %39
39: ; preds = %37, %34
ret void
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@JSIOCGAXES = global i32 0
@JSIOCGBUTTONS = global i32 0
define void @joystick_info(i8* nocapture %0, i8* %1, i8* %2, i8** nocapture %3) {
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* %0, i32 %5)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %18
8: ; preds = %4
%9 = tail call dereferenceable_or_null(256) i8* @malloc(i32 256)
store i8* %9, i8** %3
%10 = load i32, i32* @JSIOCGAXES
%11 = tail call i32 (i32, i32, ...) @ioctl(i32 %6, i32 %10, i8* %1)
%12 = load i32, i32* @JSIOCGBUTTONS
%13 = tail call i32 (i32, i32, ...) @ioctl(i32 %6, i32 %12, i8* %2)
%14 = tail call i32 @JSIOCGNAME(i32 256)
%15 = load i8*, i8** %3
%16 = tail call i32 (i32, i32, ...) @ioctl(i32 %6, i32 %14, i8* %15)
%17 = tail call i32 @close(i32 %6)
br label %19
18: ; preds = %4
store i8* null, i8** %3
br label %19
19: ; preds = %18, %8
ret void
}