#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;
#define CDS_DISC_OK 132
#define CDS_DRIVE_NOT_READY 131
#define CDS_NO_DISC 130
#define CDS_NO_INFO 129
#define CDS_TRAY_OPEN 128
int O_NONBLOCK;
int O_RDONLY;
int /*<<< orphan*/ close(int);
int ioctl(int, int /*<<< orphan*/, int);
int open(char *, int);
int /*<<< orphan*/ printf(char *);
int main(int argc, char *argv[]) {
  int fd, result, slot;
  if (argc != 2) {
    printf("ERROR! デバイスファイルを指定してください\n");
    return (-1);
  }
  fd = open(argv[1], O_RDONLY | O_NONBLOCK);
  result = ioctl(fd, CDROM_DRIVE_STATUS, slot);
  close(fd);
  switch (result) {
  case CDS_NO_INFO:
    printf("NO_INFOMATION\n");
    return (-1);
  case CDS_NO_DISC:
    printf("NO_DISC\n");
    return (0);
  case CDS_TRAY_OPEN:
    printf("TRAY_OPEN\n");
    return (1);
  case CDS_DRIVE_NOT_READY:
    printf("NOT_READY\n");
    return (0);
  case CDS_DISC_OK:
    printf("DISC_OK\n");
    return (0);
  default:
    printf("ERROR!\n");
    return (-1);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1178 <main+0x38>
lea    0xead(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    126f <main+0x12f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
mov    0x2e58(%rip),%rax
mov    (%rax),%eax
or     %eax,%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
mov    -0x1c(%rbp),%edx
call   1040 <ioctl@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x4,%eax
ja     125c <main+0x11c>
mov    -0x28(%rbp),%rax
lea    0xe25(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe65(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    126f <main+0x12f>
lea    0xe5c(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    126f <main+0x12f>
lea    0xe4d(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    126f <main+0x12f>
lea    0xe40(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    126f <main+0x12f>
lea    0xe33(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    126f <main+0x12f>
lea    0xe24(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    $0xffffffff,%r14d
cmp    $0x2,%edi
jne    11ab <main+0x6b>
mov    0x8(%rsi),%rdi
mov    0x2e86(%rip),%rax
mov    0x2e87(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1060 <open@plt>
mov    %eax,%ebx
mov    0x2e5d(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1040 <ioctl@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1050 <close@plt>
add    $0xffffff80,%ebp
cmp    $0x4,%ebp
ja     11b4 <main+0x74>
movslq %ebp,%rax
lea    0xedd(%rip),%rcx
movslq (%rcx,%rax,4),%rdi
add    %rcx,%rdi
lea    0xee3(%rip),%rcx
mov    (%rcx,%rax,4),%r14d
jmp    11bb <main+0x7b>
lea    0xe87(%rip),%rdi
jmp    11bb <main+0x7b>
lea    0xe77(%rip),%rdi
call   1030 <puts@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [60 x i8] c"ERROR! \E3\83\87\E3\83\90\E3\82\A4\E3\82\B9\E3\83\95\E3\82\A1\E3\82\A4\E3\83\AB\E3\82\92\E6\8C\87\E5\AE\9A\E3\81\97\E3\81\A6\E3\81\8F\E3\81\A0\E3\81\95\E3\81\84\0A\00"
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@CDROM_DRIVE_STATUS = global i32 0
@.str.1 = [15 x i8] c"NO_INFOMATION\0A\00"
@.str.2 = [9 x i8] c"NO_DISC\0A\00"
@.str.3 = [11 x i8] c"TRAY_OPEN\0A\00"
@.str.4 = [11 x i8] c"NOT_READY\0A\00"
@.str.5 = [9 x i8] c"DISC_OK\0A\00"
@.str.6 = [8 x i8] c"ERROR!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %40
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = load i32, i32* @O_RDONLY
%18 = load i32, i32* @O_NONBLOCK
%19 = or i32 %17, %18
%20 = call i32 @open(i8* %16, i32 %19)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = load i32, i32* @CDROM_DRIVE_STATUS
%23 = load i32, i32* %8
%24 = call i32 @ioctl(i32 %21, i32 %22, i32 %23)
store i32 %24, i32* %7
%25 = load i32, i32* %6
%26 = call i32 @close(i32 %25)
%27 = load i32, i32* %7
switch i32 %27, label %38 [
i32 129, label %28
i32 130, label %30
i32 128, label %32
i32 131, label %34
i32 132, label %36
]
28: ; preds = %13
%29 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %40
30: ; preds = %13
%31 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %40
32: ; preds = %13
%33 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %40
34: ; preds = %13
%35 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %40
36: ; preds = %13
%37 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %3
br label %40
38: ; preds = %13
%39 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %3
br label %40
40: ; preds = %38, %36, %34, %32, %30, %28, %11
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@CDROM_DRIVE_STATUS = global i32 0
@str = [8 x i8] c"DISC_OK\00"
@str.7 = [10 x i8] c"NOT_READY\00"
@str.8 = [10 x i8] c"TRAY_OPEN\00"
@str.9 = [8 x i8] c"NO_DISC\00"
@str.10 = [14 x i8] c"NO_INFOMATION\00"
@str.11 = [7 x i8] c"ERROR!\00"
@str.12 = [59 x i8] c"ERROR! \E3\83\87\E3\83\90\E3\82\A4\E3\82\B9\E3\83\95\E3\82\A1\E3\82\A4\E3\83\AB\E3\82\92\E6\8C\87\E5\AE\9A\E3\81\97\E3\81\A6\E3\81\8F\E3\81\A0\E3\81\95\E3\81\84\00"
@reltable.main = [5 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([10 x i8]* @str.8 to i64), i64 ptrtoint ([5 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @str.10 to i64), i64 ptrtoint ([5 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @str.9 to i64), i64 ptrtoint ([5 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([10 x i8]* @str.7 to i64), i64 ptrtoint ([5 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @str to i64), i64 ptrtoint ([5 x i32]* @reltable.main to i64)) to i32)]
@switch.table.main.13 = [5 x i32] [i32 1, i32 -1, i32 0, i32 0, i32 0]
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %4, label %23
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 = load i32, i32* @CDROM_DRIVE_STATUS
%12 = tail call i32 @ioctl(i32 %10, i32 %11, i32 undef)
%13 = tail call i32 @close(i32 %10)
%14 = add i32 %12, -128
%15 = icmp ult i32 %14, 5
br i1 %15, label %16, label %23
16: ; preds = %4
%17 = sext i32 %14 to i64
%18 = shl i64 %17, 2
%19 = call i8* @llvm.load.relative.i64(i8* bitcast ([5 x i32]* @reltable.main to i8*), i64 %18)
%20 = sext i32 %14 to i64
%21 = getelementptr inbounds [5 x i32], [5 x i32]* @switch.table.main.13, i64 0, i64 %20
%22 = load i32, i32* %21
br label %23
23: ; preds = %4, %16, %2
%24 = phi i8* [ getelementptr inbounds ([59 x i8], [59 x i8]* @str.12, i64 0, i64 0), %2 ], [ %19, %16 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @str.11, i64 0, i64 0), %4 ]
%25 = phi i32 [ -1, %2 ], [ %22, %16 ], [ -1, %4 ]
%26 = tail call i32 @puts(i8* dereferenceable(1) %24)
ret i32 %25
}