#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 /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int ioctl(int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int main(void) {
  int fd, retcode;
  fd = open("/dev/scd0", O_RDONLY);
  printf("Ejecting the CD-ROM...\n");
  retcode = ioctl(fd, CDROMEJECT);
  if (retcode < 0) {
    printf("Failed to eject the CD-ROM...\n");
  } else {
    printf("CD-ROM ejected...\n");
  }
  close(fd);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
lea    0xe91(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
lea    0xe8c(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
mov    0x2e4b(%rip),%rax
mov    (%rax),%esi
call   1040 <ioctl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11b2 <main+0x62>
lea    0xe7a(%rip),%rdi
call   1030 <printf@plt>
jmp    11be <main+0x6e>
lea    0xe88(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
lea    0xe9f(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%ebx
lea    0xe9b(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e5d(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1040 <ioctl@plt>
test   %eax,%eax
lea    0xea6(%rip),%rax
lea    0xe8d(%rip),%rdi
cmovs  %rax,%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/scd0\00"
@O_RDONLY = global i32 0
@.str.1 = [24 x i8] c"Ejecting the CD-ROM...\0A\00"
@CDROMEJECT = global i32 0
@.str.2 = [31 x i8] c"Failed to eject the CD-ROM...\0A\00"
@.str.3 = [19 x i8] c"CD-ROM ejected...\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = load i32, i32* @O_RDONLY
%5 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %2
%6 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%7 = load i32, i32* %2
%8 = load i32, i32* @CDROMEJECT
%9 = call i32 @ioctl(i32 %7, i32 %8)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %16
14: ; preds = %0
%15 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %16
16: ; preds = %14, %12
%17 = load i32, i32* %2
%18 = call i32 @close(i32 %17)
%19 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/scd0\00"
@O_RDONLY = global i32 0
@CDROMEJECT = global i32 0
@str = [23 x i8] c"Ejecting the CD-ROM...\00"
@str.4 = [18 x i8] c"CD-ROM ejected...\00"
@str.5 = [30 x i8] c"Failed to eject the CD-ROM...\00"
define i32 @main() {
%1 = load i32, i32* @O_RDONLY
%2 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%4 = load i32, i32* @CDROMEJECT
%5 = tail call i32 @ioctl(i32 %2, i32 %4)
%6 = icmp slt i32 %5, 0
%7 = select i1 %6, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @str.5, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @str.4, i64 0, i64 0)
%8 = tail call i32 @puts(i8* dereferenceable(1) %7)
%9 = tail call i32 @close(i32 %2)
%10 = tail call i32 @exit(i32 0)
unreachable
}