#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*/ O_RDONLY;
int _eject_error(char const *, int /*<<< orphan*/);
scalar_t__ close(int);
int /*<<< orphan*/ errno;
int open(char const *, int /*<<< orphan*/);
int _eject(char const *device) {
  int fd;
  if ((fd = open(device, O_RDONLY)) < 0)
    return -_eject_error(device, errno);
  if (close(fd) != 0)
    return -_eject_error(device, errno);
  return 0;
}


x86 assembly (clang, -O0):
<_eject>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2ea1(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    117a <_eject+0x4a>
mov    -0x10(%rbp),%rdi
mov    0x2e73(%rip),%rax
mov    (%rax),%esi
call   1030 <_eject_error@plt>
mov    %eax,%ecx
xor    %eax,%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    11b3 <_eject+0x83>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
cmp    $0x0,%rax
je     11ac <_eject+0x7c>
mov    -0x10(%rbp),%rdi
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
call   1030 <_eject_error@plt>
mov    %eax,%ecx
xor    %eax,%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    11b3 <_eject+0x83>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_eject>:
push   %rbx
mov    %rdi,%rbx
mov    0x2ead(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
test   %eax,%eax
js     1152 <_eject+0x22>
mov    %eax,%edi
call   1040 <close@plt>
test   %rax,%rax
je     1167 <_eject+0x37>
mov    0x2e7f(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1030 <_eject_error@plt>
neg    %eax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@errno = global i32 0
define i32 @_eject(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = load i32, i32* @O_RDONLY
%7 = call i32 @open(i8* %5, i32 %6)
store i32 %7, i32* %4
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = load i32, i32* @errno
%12 = call i32 @_eject_error(i8* %10, i32 %11)
%13 = sub nsw i32 0, %12
store i32 %13, i32* %2
br label %24
14: ; preds = %1
%15 = load i32, i32* %4
%16 = call i64 @close(i32 %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = load i8*, i8** %3
%20 = load i32, i32* @errno
%21 = call i32 @_eject_error(i8* %19, i32 %20)
%22 = sub nsw i32 0, %21
store i32 %22, i32* %2
br label %24
23: ; preds = %14
store i32 0, i32* %2
br label %24
24: ; preds = %23, %18, %9
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@errno = global i32 0
define i32 @_eject(i8* %0) {
%2 = load i32, i32* @O_RDONLY
%3 = tail call i32 @open(i8* %0, i32 %2)
%4 = icmp slt i32 %3, 0
br i1 %4, label %8, label %5
5: ; preds = %1
%6 = tail call i64 @close(i32 %3)
%7 = icmp eq i64 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %5, %1
%9 = load i32, i32* @errno
%10 = tail call i32 @_eject_error(i8* %0, i32 %9)
%11 = sub nsw i32 0, %10
br label %12
12: ; preds = %8, %5
%13 = phi i32 [ 0, %5 ], [ %11, %8 ]
ret i32 %13
}