#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 /*<<< orphan*/ _IO(char, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error_print(char *, char *, ...);
scalar_t__ ioctl(int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int disk_reserve(char *device) {
  int fd;
  fd = open(device, O_RDONLY);
  if (fd == -1) {
    error_print("<%s> - %s", device, strerror(errno));
    return -1;
  }
  printf("Reserving device <%s>...\n", device);
  if (ioctl(fd, _IO('D', 2))) {
    error_print("Could not reserve device <%s>", device);
    close(fd);
    return -1;
  }
  printf("Done.\n");
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<disk_reserve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11d1 <disk_reserve+0x61>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1070 <error_print@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    124f <disk_reserve+0xdf>
mov    -0x10(%rbp),%rsi
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    $0x44,%edi
mov    $0x2,%esi
call   1040 <_IO@plt>
mov    -0x24(%rbp),%edi
mov    %eax,%esi
call   1050 <ioctl@plt>
cmp    $0x0,%rax
je     1232 <disk_reserve+0xc2>
mov    -0x10(%rbp),%rsi
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1070 <error_print@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    124f <disk_reserve+0xdf>
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<disk_reserve>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     11ed <disk_reserve+0x6d>
mov    %eax,%ebp
lea    0xe67(%rip),%rdi
xor    %r14d,%r14d
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x44,%edi
mov    $0x2,%esi
call   1050 <_IO@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1060 <ioctl@plt>
test   %rax,%rax
je     1216 <disk_reserve+0x96>
lea    0xe50(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <error_print@plt>
mov    %ebp,%edi
call   1070 <close@plt>
mov    $0xffffffff,%r14d
jmp    1229 <disk_reserve+0xa9>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xdfe(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1080 <error_print@plt>
mov    $0xffffffff,%r14d
jmp    1229 <disk_reserve+0xa9>
lea    0xe25(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
call   1070 <close@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [10 x i8] c"<%s> - %s\00"
@errno = global i32 0
@.str.1 = [26 x i8] c"Reserving device <%s>...\0A\00"
@.str.2 = [30 x i8] c"Could not reserve device <%s>\00"
@.str.3 = [7 x i8] c"Done.\0A\00"
define i32 @disk_reserve(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 = load i32, i32* %4
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %15
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = load i32, i32* @errno
%13 = call i32 @strerror(i32 %12)
%14 = call i32 (i8*, i8*, ...) @error_print(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %11, i32 %13)
store i32 -1, i32* %2
br label %31
15: ; preds = %1
%16 = load i8*, i8** %3
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = load i32, i32* %4
%19 = call i32 @_IO(i8 signext 68, i32 2)
%20 = call i64 @ioctl(i32 %18, i32 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %15
%23 = load i8*, i8** %3
%24 = call i32 (i8*, i8*, ...) @error_print(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%25 = load i32, i32* %4
%26 = call i32 @close(i32 %25)
store i32 -1, i32* %2
br label %31
27: ; preds = %15
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%29 = load i32, i32* %4
%30 = call i32 @close(i32 %29)
store i32 0, i32* %2
br label %31
31: ; preds = %27, %22, %10
%32 = load i32, i32* %2
ret i32 %32
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [10 x i8] c"<%s> - %s\00"
@errno = global i32 0
@.str.1 = [26 x i8] c"Reserving device <%s>...\0A\00"
@.str.2 = [30 x i8] c"Could not reserve device <%s>\00"
@str = [6 x i8] c"Done.\00"
define i32 @disk_reserve(i8* %0) {
%2 = load i32, i32* @O_RDONLY
%3 = tail call i32 @open(i8* %0, i32 %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %9
5: ; preds = %1
%6 = load i32, i32* @errno
%7 = tail call i32 @strerror(i32 %6)
%8 = tail call i32 (i8*, i8*, ...) @error_print(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %7)
br label %20
9: ; preds = %1
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%11 = tail call i32 @_IO(i8 signext 68, i32 2)
%12 = tail call i64 @ioctl(i32 %3, i32 %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %9
%15 = tail call i32 (i8*, i8*, ...) @error_print(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%16 = tail call i32 @close(i32 %3)
br label %20
17: ; preds = %9
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
%19 = tail call i32 @close(i32 %3)
br label %20
20: ; preds = %17, %14, %5
%21 = phi i32 [ -1, %5 ], [ -1, %14 ], [ 0, %17 ]
ret i32 %21
}