#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*/ error(char *, int);
int mb_error_to_string(int);
int mb_reserve_pages(int);
int /*<<< orphan*/ printf(char *, int, int);
void do_reserve(int n_pages) {
  int ret = mb_reserve_pages(n_pages);
  if (ret < 0) {
    error("mb_reserve_pages() said %s\n", mb_error_to_string(ret));
  }
  printf("Got %d of %d pages\n", ret, n_pages);
  if (ret == 0) {
    error("reserve of %d pages failed\n", n_pages);
  }
}


x86 assembly (clang, -O0):
<do_reserve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <mb_reserve_pages@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1176 <do_reserve+0x36>
mov    -0x8(%rbp),%edi
call   1060 <mb_error_to_string@plt>
mov    %eax,%esi
lea    0xe8f(%rip),%rdi
call   1050 <error@plt>
mov    -0x8(%rbp),%esi
mov    -0x4(%rbp),%edx
lea    0xe99(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x0,-0x8(%rbp)
jne    11a1 <do_reserve+0x61>
mov    -0x4(%rbp),%esi
lea    0xe94(%rip),%rdi
call   1050 <error@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_reserve>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
call   1040 <mb_reserve_pages@plt>
mov    %eax,%ebp
test   %eax,%eax
js     116b <do_reserve+0x2b>
lea    0xec5(%rip),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
call   1030 <printf@plt>
test   %ebp,%ebp
je     1196 <do_reserve+0x56>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    %ebp,%edi
call   1060 <mb_error_to_string@plt>
lea    0xe87(%rip),%rdi
mov    %eax,%esi
call   1050 <error@plt>
lea    0xe95(%rip),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <printf@plt>
lea    0xe93(%rip),%rdi
mov    %ebx,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <error@plt>

LLVM IR (-O0):
@.str = [28 x i8] c"mb_reserve_pages() said %s\0A\00"
@.str.1 = [20 x i8] c"Got %d of %d pages\0A\00"
@.str.2 = [28 x i8] c"reserve of %d pages failed\0A\00"
define void @do_reserve(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = call i32 @mb_reserve_pages(i32 %4)
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = load i32, i32* %3
%10 = call i32 @mb_error_to_string(i32 %9)
%11 = call i32 @error(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %10)
br label %12
12: ; preds = %8, %1
%13 = load i32, i32* %3
%14 = load i32, i32* %2
%15 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 %14)
%16 = load i32, i32* %3
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %12
%19 = load i32, i32* %2
%20 = call i32 @error(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %18, %12
ret void
}

LLVM IR (-O2):
@.str = [28 x i8] c"mb_reserve_pages() said %s\0A\00"
@.str.1 = [20 x i8] c"Got %d of %d pages\0A\00"
@.str.2 = [28 x i8] c"reserve of %d pages failed\0A\00"
define void @do_reserve(i32 %0) {
%2 = tail call i32 @mb_reserve_pages(i32 %0)
%3 = icmp slt i32 %2, 0
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = tail call i32 @mb_error_to_string(i32 %2)
%6 = tail call i32 @error(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %2, i32 %0)
br label %13
8: ; preds = %1
%9 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %2, i32 %0)
%10 = icmp eq i32 %2, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @error(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %0)
br label %13
13: ; preds = %4, %11, %8
ret void
}