#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_DISC_STATUS;
int /*<<< orphan*/ CDROM_DRIVE_STATUS;
int /*<<< orphan*/ CDSL_CURRENT;
scalar_t__ ioctl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int init_cdrom(int fd) {
  if (ioctl(fd, CDROM_DRIVE_STATUS, CDSL_CURRENT) < 0) {
    perror("drive not ready\n");
    return 1;
  }
  if (ioctl(fd, CDROM_DISC_STATUS, CDSL_CURRENT) < 0) {
    perror("no disc inserted?\n");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<init_cdrom>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2ea3(%rip),%rax
mov    (%rax),%esi
mov    0x2e92(%rip),%rax
mov    (%rax),%edx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    1167 <init_cdrom+0x47>
lea    0xeaa(%rip),%rdi
call   1040 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11aa <init_cdrom+0x8a>
mov    -0x8(%rbp),%edi
mov    0x2e87(%rip),%rax
mov    (%rax),%esi
mov    0x2e56(%rip),%rax
mov    (%rax),%edx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    11a3 <init_cdrom+0x83>
lea    0xe7f(%rip),%rdi
call   1040 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11aa <init_cdrom+0x8a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_cdrom>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
mov    0x2eab(%rip),%rax
mov    (%rax),%esi
mov    0x2e9a(%rip),%r14
mov    (%r14),%edx
call   1030 <ioctl@plt>
test   %rax,%rax
js     1168 <init_cdrom+0x48>
mov    0x2eae(%rip),%rax
mov    (%rax),%esi
mov    (%r14),%edx
mov    %ebx,%edi
call   1030 <ioctl@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
js     1171 <init_cdrom+0x51>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe91(%rip),%rdi
jmp    1178 <init_cdrom+0x58>
lea    0xe99(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%eax
jmp    1160 <init_cdrom+0x40>

LLVM IR (-O0):
@CDROM_DRIVE_STATUS = global i32 0
@CDSL_CURRENT = global i32 0
@.str = [17 x i8] c"drive not ready\0A\00"
@CDROM_DISC_STATUS = global i32 0
@.str.1 = [19 x i8] c"no disc inserted?\0A\00"
define i32 @init_cdrom(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = load i32, i32* @CDROM_DRIVE_STATUS
%6 = load i32, i32* @CDSL_CURRENT
%7 = call i64 @ioctl(i32 %4, i32 %5, i32 %6)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %2
br label %20
11: ; preds = %1
%12 = load i32, i32* %3
%13 = load i32, i32* @CDROM_DISC_STATUS
%14 = load i32, i32* @CDSL_CURRENT
%15 = call i64 @ioctl(i32 %12, i32 %13, i32 %14)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %11
%18 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %2
br label %20
19: ; preds = %11
store i32 0, i32* %2
br label %20
20: ; preds = %19, %17, %9
%21 = load i32, i32* %2
ret i32 %21
}

LLVM IR (-O2):
@CDROM_DRIVE_STATUS = global i32 0
@CDSL_CURRENT = global i32 0
@.str = [17 x i8] c"drive not ready\0A\00"
@CDROM_DISC_STATUS = global i32 0
@.str.1 = [19 x i8] c"no disc inserted?\0A\00"
define i32 @init_cdrom(i32 %0) {
%2 = load i32, i32* @CDROM_DRIVE_STATUS
%3 = load i32, i32* @CDSL_CURRENT
%4 = tail call i64 @ioctl(i32 %0, i32 %2, i32 %3)
%5 = icmp slt i64 %4, 0
br i1 %5, label %11, label %6
6: ; preds = %1
%7 = load i32, i32* @CDROM_DISC_STATUS
%8 = load i32, i32* @CDSL_CURRENT
%9 = tail call i64 @ioctl(i32 %0, i32 %7, i32 %8)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %6, %1
%12 = phi i8* [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), %6 ]
%13 = tail call i32 @perror(i8* %12)
br label %14
14: ; preds = %11, %6
%15 = phi i32 [ 0, %6 ], [ 1, %11 ]
ret i32 %15
}