#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 MAP_ANON;
void *MAP_FAILED;
int MAP_NORESERVE;
int MAP_PRIVATE;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ error_and_exit(char *, char *, int, char *);
void *mmap(void *, size_t, int const, int const, int, int /*<<< orphan*/);
int /*<<< orphan*/ munmap(void *, size_t);
void *request_vm(void *base_addr, size_t size) {
  const int flags = PROT_READ | PROT_WRITE;
  const int prot = MAP_PRIVATE | MAP_ANON | MAP_NORESERVE;
  void *ret = mmap(base_addr, size, flags, prot, -1, 0);
  if (base_addr != NULL && ret != base_addr) {
    munmap(base_addr, size);
    return NULL;
  }
  if (ret == MAP_FAILED)
    error_and_exit("CMalloc: Error at %s:%d %s.\n",
                   "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                   "outputs/2022-01-22/02-19-57/repos/maokelong/cmalloc/refs/"
                   "heads/master/sources/includes/system.inl.h",
                   33, "failed in requesting memory from OS.");
  return ret;
}


x86 assembly (clang, -O0):
<request_vm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2eb1(%rip),%rax
mov    (%rax),%eax
mov    0x2e80(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e64(%rip),%rax
mov    (%rax),%eax
mov    0x2e63(%rip),%rcx
or     (%rcx),%eax
mov    0x2e72(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11c6 <request_vm+0x96>
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     11c6 <request_vm+0x96>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <munmap@plt>
movq   $0x0,-0x8(%rbp)
jmp    1201 <request_vm+0xd1>
mov    -0x28(%rbp),%rax
mov    0x2de7(%rip),%rcx
cmp    (%rcx),%rax
jne    11f9 <request_vm+0xc9>
lea    0xe1f(%rip),%rdi
lea    0xe35(%rip),%rsi
mov    $0x21,%edx
lea    0xec5(%rip),%rcx
call   1040 <error_and_exit@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<request_vm>:
push   %r15
push   %r14
push   %rbx
mov    0x2ebc(%rip),%rax
mov    0x2e8d(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e72(%rip),%rax
mov    0x2e73(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2e7a(%rip),%rax
or     (%rax),%ecx
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,%r15
test   %rbx,%rbx
je     1193 <request_vm+0x63>
cmp    %rbx,%r15
je     1193 <request_vm+0x63>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <munmap@plt>
xor    %r15d,%r15d
jmp    11be <request_vm+0x8e>
mov    0x2e1e(%rip),%rax
cmp    (%rax),%r15
jne    11be <request_vm+0x8e>
lea    0xe5a(%rip),%rdi
lea    0xe70(%rip),%rsi
lea    0xf05(%rip),%rcx
mov    $0x21,%edx
call   1040 <error_and_exit@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANON = global i32 0
@MAP_NORESERVE = global i32 0
@MAP_FAILED = global i8* null
@.str = [29 x i8] c"CMalloc: Error at %s:%d %s.\0A\00"
@.str.1 = [156 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/maokelong/cmalloc/refs/heads/master/sources/includes/system.inl.h\00"
@.str.2 = [37 x i8] c"failed in requesting memory from OS.\00"
define i8* @request_vm(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %4
store i64 %1, i64* %5
%9 = load i32, i32* @PROT_READ
%10 = load i32, i32* @PROT_WRITE
%11 = or i32 %9, %10
store i32 %11, i32* %6
%12 = load i32, i32* @MAP_PRIVATE
%13 = load i32, i32* @MAP_ANON
%14 = or i32 %12, %13
%15 = load i32, i32* @MAP_NORESERVE
%16 = or i32 %14, %15
store i32 %16, i32* %7
%17 = load i8*, i8** %4
%18 = load i64, i64* %5
%19 = load i32, i32* %6
%20 = load i32, i32* %7
%21 = call i8* @mmap(i8* %17, i64 %18, i32 %19, i32 %20, i32 -1, i32 0)
store i8* %21, i8** %8
%22 = load i8*, i8** %4
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %32
24: ; preds = %2
%25 = load i8*, i8** %8
%26 = load i8*, i8** %4
%27 = icmp ne i8* %25, %26
br i1 %27, label %28, label %32
28: ; preds = %24
%29 = load i8*, i8** %4
%30 = load i64, i64* %5
%31 = call i32 @munmap(i8* %29, i64 %30)
store i8* null, i8** %3
br label %40
32: ; preds = %24, %2
%33 = load i8*, i8** %8
%34 = load i8*, i8** @MAP_FAILED
%35 = icmp eq i8* %33, %34
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = call i32 @error_and_exit(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([156 x i8], [156 x i8]* @.str.1, i64 0, i64 0), i32 33, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
br label %38
38: ; preds = %36, %32
%39 = load i8*, i8** %8
store i8* %39, i8** %3
br label %40
40: ; preds = %38, %28
%41 = load i8*, i8** %3
ret i8* %41
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANON = global i32 0
@MAP_NORESERVE = global i32 0
@MAP_FAILED = global i8* null
@.str = [29 x i8] c"CMalloc: Error at %s:%d %s.\0A\00"
@.str.1 = [156 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/maokelong/cmalloc/refs/heads/master/sources/includes/system.inl.h\00"
@.str.2 = [37 x i8] c"failed in requesting memory from OS.\00"
define i8* @request_vm(i8* %0, i64 %1) {
%3 = load i32, i32* @PROT_READ
%4 = load i32, i32* @PROT_WRITE
%5 = or i32 %4, %3
%6 = load i32, i32* @MAP_PRIVATE
%7 = load i32, i32* @MAP_ANON
%8 = or i32 %7, %6
%9 = load i32, i32* @MAP_NORESERVE
%10 = or i32 %8, %9
%11 = tail call i8* @mmap(i8* %0, i64 %1, i32 %5, i32 %10, i32 -1, i32 0)
%12 = icmp eq i8* %0, null
%13 = icmp eq i8* %11, %0
%14 = select i1 %12, i1 true, i1 %13
br i1 %14, label %17, label %15
15: ; preds = %2
%16 = tail call i32 @munmap(i8* %0, i64 %1)
br label %22
17: ; preds = %2
%18 = load i8*, i8** @MAP_FAILED
%19 = icmp eq i8* %11, %18
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = tail call i32 @error_and_exit(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([156 x i8], [156 x i8]* @.str.1, i64 0, i64 0), i32 33, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %17, %20, %15
%23 = phi i8* [ null, %15 ], [ %11, %20 ], [ %11, %17 ]
ret i8* %23
}