#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_NONBLOCK;
int /*<<< orphan*/ close(int);
scalar_t__ ioctl(int, int, int *);
int open(char *, int /*<<< orphan*/);
int ipod_ioctl(int request, int *arg) {
  int fd;
  fd = open("/dev/fb0", O_NONBLOCK);
  if (fd < 0)
    fd = open("/dev/fb/0", O_NONBLOCK);
  if (fd < 0)
    return -1;
  if (ioctl(fd, request, arg) < 0) {
    close(fd);
    return -1;
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<ipod_ioctl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2ea2(%rip),%rax
mov    (%rax),%esi
lea    0xeb1(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1179 <ipod_ioctl+0x49>
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
lea    0xe98(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    118f <ipod_ioctl+0x5f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cb <ipod_ioctl+0x9b>
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    11bc <ipod_ioctl+0x8c>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cb <ipod_ioctl+0x9b>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ipod_ioctl>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebp
mov    0x2ea5(%rip),%r15
mov    (%r15),%esi
lea    0xeb3(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    116d <ipod_ioctl+0x3d>
mov    (%r15),%esi
lea    0xea7(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
js     1194 <ipod_ioctl+0x64>
mov    %ebx,%edi
mov    %ebp,%esi
mov    %r14,%rdx
call   1030 <ioctl@plt>
mov    %rax,%rbp
mov    %ebx,%edi
call   1040 <close@plt>
sar    $0x3f,%rbp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xffffffff,%ebp
jmp    1187 <ipod_ioctl+0x57>

LLVM IR (-O0):
@.str = [9 x i8] c"/dev/fb0\00"
@O_NONBLOCK = global i32 0
@.str.1 = [10 x i8] c"/dev/fb/0\00"
define i32 @ipod_ioctl(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
%7 = load i32, i32* @O_NONBLOCK
%8 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @O_NONBLOCK
%13 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %12)
store i32 %13, i32* %6
br label %14
14: ; preds = %11, %2
%15 = load i32, i32* %6
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %14
store i32 -1, i32* %3
br label %30
18: ; preds = %14
%19 = load i32, i32* %6
%20 = load i32, i32* %4
%21 = load i32*, i32** %5
%22 = call i64 @ioctl(i32 %19, i32 %20, i32* %21)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %18
%25 = load i32, i32* %6
%26 = call i32 @close(i32 %25)
store i32 -1, i32* %3
br label %30
27: ; preds = %18
%28 = load i32, i32* %6
%29 = call i32 @close(i32 %28)
store i32 0, i32* %3
br label %30
30: ; preds = %27, %24, %17
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@.str = [9 x i8] c"/dev/fb0\00"
@O_NONBLOCK = global i32 0
@.str.1 = [10 x i8] c"/dev/fb/0\00"
define i32 @ipod_ioctl(i32 %0, i32* %1) {
%3 = load i32, i32* @O_NONBLOCK
%4 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i32, i32* @O_NONBLOCK
%8 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = icmp slt i32 %8, 0
br i1 %9, label %16, label %10
10: ; preds = %2, %6
%11 = phi i32 [ %8, %6 ], [ %4, %2 ]
%12 = tail call i64 @ioctl(i32 %11, i32 %0, i32* %1)
%13 = tail call i32 @close(i32 %11)
%14 = ashr i64 %12, 63
%15 = trunc i64 %14 to i32
br label %16
16: ; preds = %10, %6
%17 = phi i32 [ -1, %6 ], [ %15, %10 ]
ret i32 %17
}