#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 */
struct rlimit {
  long rlim_cur;
  long rlim_max;
};

/* Variables and functions */
int /*<<< orphan*/ RLIMIT_AS;
long my_vm_size();
int /*<<< orphan*/ setrlimit(int /*<<< orphan*/, struct rlimit *);
void reserve_memory(unsigned long bytes) {
  struct rlimit r;
  long vm_size;
  bytes = (bytes + 0x1000 - 1) & ~0x1000;
  if ((vm_size = my_vm_size()) == -1)
    return;
  r.rlim_cur = r.rlim_max = vm_size + bytes;
  setrlimit(RLIMIT_AS, &r);
}


x86 assembly (clang, -O0):
<reserve_memory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1000,%rax
sub    $0x1,%rax
and    $0xffffffffffffefff,%rax
mov    %rax,-0x8(%rbp)
mov    $0x0,%al
call   1030 <my_vm_size@plt>
mov    %rax,-0x20(%rbp)
cmp    $0xffffffffffffffff,%rax
jne    115e <reserve_memory+0x3e>
jmp    1180 <reserve_memory+0x60>
mov    -0x20(%rbp),%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    %rax,-0x18(%rbp)
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1040 <setrlimit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reserve_memory>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
xor    %eax,%eax
call   1030 <my_vm_size@plt>
cmp    $0xffffffffffffffff,%rax
je     1160 <reserve_memory+0x40>
add    $0xfff,%rbx
and    $0xffffffffffffefff,%rbx
add    %rbx,%rax
mov    %rax,0x8(%rsp)
mov    %rax,(%rsp)
mov    0x2e8a(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   1040 <setrlimit@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.rlimit = type { i64, i64 }
@RLIMIT_AS = global i32 0
define void @reserve_memory(i64 %0) {
%2 = alloca i64
%3 = alloca %struct.rlimit
%4 = alloca i64
store i64 %0, i64* %2
%5 = load i64, i64* %2
%6 = add i64 %5, 4096
%7 = sub i64 %6, 1
%8 = and i64 %7, -4097
store i64 %8, i64* %2
%9 = call i64 (...) @my_vm_size()
store i64 %9, i64* %4
%10 = icmp eq i64 %9, -1
br i1 %10, label %11, label %12
11: ; preds = %1
br label %20
12: ; preds = %1
%13 = load i64, i64* %4
%14 = load i64, i64* %2
%15 = add i64 %13, %14
%16 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %3, i32 0, i32 1
store i64 %15, i64* %16
%17 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %3, i32 0, i32 0
store i64 %15, i64* %17
%18 = load i32, i32* @RLIMIT_AS
%19 = call i32 @setrlimit(i32 %18, %struct.rlimit* %3)
br label %20
20: ; preds = %12, %11
ret void
}

LLVM IR (-O2):
%struct.rlimit = type { i64, i64 }
@RLIMIT_AS = global i32 0
define void @reserve_memory(i64 %0) {
%2 = alloca %struct.rlimit
%3 = bitcast %struct.rlimit* %2 to i8*
%4 = tail call i64 (...) @my_vm_size()
%5 = icmp eq i64 %4, -1
br i1 %5, label %14, label %6
6: ; preds = %1
%7 = add i64 %0, 4095
%8 = and i64 %7, -4097
%9 = add i64 %4, %8
%10 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i64 0, i32 1
store i64 %9, i64* %10
%11 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i64 0, i32 0
store i64 %9, i64* %11
%12 = load i32, i32* @RLIMIT_AS
%13 = call i32 @setrlimit(i32 %12, %struct.rlimit* %2)
br label %14
14: ; preds = %1, %6
ret void
}