#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*/ CDROMEJECT;
int O_NONBLOCK;
int O_RDONLY;
int /*<<< orphan*/ close(int);
int ioctl(int, int /*<<< orphan*/);
int open(char *, int);
int main() {
  int fd;
  if ((fd = open("/dev/hdc", O_RDONLY | O_NONBLOCK)) == -1)
    return (1);
  if ((ioctl(fd, CDROMEJECT)) == -1)
    return (1);
  close(fd);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e9a(%rip),%rax
mov    (%rax),%esi
mov    0x2e99(%rip),%rax
or     (%rax),%esi
lea    0xea8(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    1175 <main+0x45>
movl   $0x1,-0x4(%rbp)
jmp    11aa <main+0x7a>
mov    -0x8(%rbp),%edi
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    119b <main+0x6b>
movl   $0x1,-0x4(%rbp)
jmp    11aa <main+0x7a>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    0x2ea6(%rip),%rax
mov    0x2ea7(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xeb4(%rip),%rdi
call   1050 <open@plt>
mov    $0x1,%ebx
cmp    $0xffffffff,%eax
je     117b <main+0x4b>
mov    %eax,%ebp
mov    0x2e6c(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
je     117b <main+0x4b>
mov    %ebp,%edi
call   1040 <close@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"/dev/hdc\00"
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@CDROMEJECT = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = load i32, i32* @O_RDONLY
%4 = load i32, i32* @O_NONBLOCK
%5 = or i32 %3, %4
%6 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %2
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %9
8: ; preds = %0
store i32 1, i32* %1
br label %18
9: ; preds = %0
%10 = load i32, i32* %2
%11 = load i32, i32* @CDROMEJECT
%12 = call i32 @ioctl(i32 %10, i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %15
14: ; preds = %9
store i32 1, i32* %1
br label %18
15: ; preds = %9
%16 = load i32, i32* %2
%17 = call i32 @close(i32 %16)
store i32 0, i32* %1
br label %18
18: ; preds = %15, %14, %8
%19 = load i32, i32* %1
ret i32 %19
}

LLVM IR (-O2):
@.str = [9 x i8] c"/dev/hdc\00"
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@CDROMEJECT = global i32 0
define i32 @main() {
%1 = load i32, i32* @O_RDONLY
%2 = load i32, i32* @O_NONBLOCK
%3 = or i32 %2, %1
%4 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %12, label %6
6: ; preds = %0
%7 = load i32, i32* @CDROMEJECT
%8 = tail call i32 @ioctl(i32 %4, i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %12, label %10
10: ; preds = %6
%11 = tail call i32 @close(i32 %4)
br label %12
12: ; preds = %6, %0, %10
%13 = phi i32 [ 0, %10 ], [ 1, %0 ], [ 1, %6 ]
ret i32 %13
}