#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 close(int);
int ioctl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int);
int main(int argc, char *argv[]) {
  int fd, ret;
  if (argc < 2)
    return 1;
  fd = open(argv[1], O_RDONLY | O_NONBLOCK);
  if (fd < 0)
    return 1;
  ret = ioctl(fd, CDROMEJECT, 0);
  if (ret)
    return 1;
  ret = close(fd);
  if (ret)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    115c <main+0x2c>
movl   $0x1,-0x4(%rbp)
jmp    11e8 <main+0xb8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
mov    0x2e74(%rip),%rax
or     (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1194 <main+0x64>
movl   $0x1,-0x4(%rbp)
jmp    11e8 <main+0xb8>
mov    -0x14(%rbp),%edi
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <ioctl@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11c0 <main+0x90>
movl   $0x1,-0x4(%rbp)
jmp    11e8 <main+0xb8>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11e1 <main+0xb1>
movl   $0x1,-0x4(%rbp)
jmp    11e8 <main+0xb8>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    $0x1,%ebx
cmp    $0x2,%edi
jl     1182 <main+0x52>
mov    0x8(%rsi),%rdi
mov    0x2e98(%rip),%rax
mov    0x2e99(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1050 <open@plt>
test   %eax,%eax
js     1182 <main+0x52>
mov    %eax,%ebp
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
xor    %edx,%edx
call   1030 <ioctl@plt>
test   %eax,%eax
jne    1182 <main+0x52>
mov    %ebp,%edi
call   1040 <close@plt>
xor    %ebx,%ebx
test   %eax,%eax
setne  %bl
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@CDROMEJECT = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 1, i32* %3
br label %36
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = load i32, i32* @O_RDONLY
%16 = load i32, i32* @O_NONBLOCK
%17 = or i32 %15, %16
%18 = call i32 @open(i8* %14, i32 %17)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %11
store i32 1, i32* %3
br label %36
22: ; preds = %11
%23 = load i32, i32* %6
%24 = load i32, i32* @CDROMEJECT
%25 = call i32 @ioctl(i32 %23, i32 %24, i32 0)
store i32 %25, i32* %7
%26 = load i32, i32* %7
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %22
store i32 1, i32* %3
br label %36
29: ; preds = %22
%30 = load i32, i32* %6
%31 = call i32 @close(i32 %30)
store i32 %31, i32* %7
%32 = load i32, i32* %7
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %29
store i32 1, i32* %3
br label %36
35: ; preds = %29
store i32 0, i32* %3
br label %36
36: ; preds = %35, %34, %28, %21, %10
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@CDROMEJECT = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %20, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = load i32, i32* @O_RDONLY
%8 = load i32, i32* @O_NONBLOCK
%9 = or i32 %8, %7
%10 = tail call i32 @open(i8* %6, i32 %9)
%11 = icmp slt i32 %10, 0
br i1 %11, label %20, label %12
12: ; preds = %4
%13 = load i32, i32* @CDROMEJECT
%14 = tail call i32 @ioctl(i32 %10, i32 %13, i32 0)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %12
%17 = tail call i32 @close(i32 %10)
%18 = icmp ne i32 %17, 0
%19 = zext i1 %18 to i32
br label %20
20: ; preds = %16, %12, %4, %2
%21 = phi i32 [ 1, %2 ], [ 1, %4 ], [ 1, %12 ], [ %19, %16 ]
ret i32 %21
}