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


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)
je     115a <main+0x2a>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e77(%rip),%rax
mov    (%rax),%esi
mov    0x2e76(%rip),%rax
or     (%rax),%esi
call   1040 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    118f <main+0x5f>
mov    $0xfffffffe,%edi
call   1050 <exit@plt>
mov    -0x14(%rbp),%edi
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
call   1030 <ioctl@plt>
mov    %eax,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rax
cmp    $0x2,%edi
jne    1160 <main+0x30>
mov    0x8(%rsi),%rdi
mov    0x2e9f(%rip),%rax
mov    0x2ea0(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1040 <open@plt>
cmp    $0xffffffff,%eax
jne    116a <main+0x3a>
mov    $0xfffffffe,%edi
call   1050 <exit@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
mov    0x2e5f(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
call   1030 <ioctl@plt>
mov    %eax,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@CDROM_DRIVE_STATUS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 2
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @exit(i32 -1)
unreachable
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 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %11
%21 = call i32 @exit(i32 -2)
unreachable
22: ; preds = %11
%23 = load i32, i32* %6
%24 = load i32, i32* @CDROM_DRIVE_STATUS
%25 = call i32 @ioctl(i32 %23, i32 %24)
%26 = call i32 @exit(i32 %25)
unreachable
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@CDROM_DRIVE_STATUS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @exit(i32 -1)
unreachable
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = load i32, i32* @O_RDONLY
%10 = load i32, i32* @O_NONBLOCK
%11 = or i32 %10, %9
%12 = tail call i32 @open(i8* %8, i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %6
%15 = tail call i32 @exit(i32 -2)
unreachable
16: ; preds = %6
%17 = load i32, i32* @CDROM_DRIVE_STATUS
%18 = tail call i32 @ioctl(i32 %12, i32 %17)
%19 = tail call i32 @exit(i32 %18)
unreachable
}