#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_ANONYMOUS;
void *MAP_FAILED;
int MAP_PRIVATE;
int PROT_READ;
int PROT_WRITE;
void *mmap(int /*<<< orphan*/ *, int, int, int, int, int /*<<< orphan*/);
void *vispo_alloc_pages(int length) {
  int prot = PROT_READ | PROT_WRITE;
  int flags = MAP_ANONYMOUS | MAP_PRIVATE;
  void *p;
  p = mmap(NULL, length, prot, flags, -1, 0);
  if (p == MAP_FAILED)
    return NULL;
  return p;
}


x86 assembly (clang, -O0):
<vispo_alloc_pages>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    0x2ed6(%rip),%rax
mov    (%rax),%eax
mov    0x2ea5(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x10(%rbp)
mov    0x2ea9(%rip),%rax
mov    (%rax),%eax
mov    0x2e88(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
xor    %eax,%eax
mov    %eax,%edi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2e51(%rip),%rcx
cmp    (%rcx),%rax
jne    1185 <vispo_alloc_pages+0x75>
movq   $0x0,-0x8(%rbp)
jmp    118d <vispo_alloc_pages+0x7d>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vispo_alloc_pages>:
push   %rbx
mov    %edi,%esi
mov    0x2ede(%rip),%rax
mov    0x2eaf(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2eb4(%rip),%rax
mov    0x2e95(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
xor    %ebx,%ebx
xor    %edi,%edi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    0x2e70(%rip),%rcx
cmp    (%rcx),%rax
cmove  %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i8* null
define i8* @vispo_alloc_pages(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i32 %0, i32* %3
%7 = load i32, i32* @PROT_READ
%8 = load i32, i32* @PROT_WRITE
%9 = or i32 %7, %8
store i32 %9, i32* %4
%10 = load i32, i32* @MAP_ANONYMOUS
%11 = load i32, i32* @MAP_PRIVATE
%12 = or i32 %10, %11
store i32 %12, i32* %5
%13 = load i32, i32* %3
%14 = load i32, i32* %4
%15 = load i32, i32* %5
%16 = call i8* @mmap(i32* null, i32 %13, i32 %14, i32 %15, i32 -1, i32 0)
store i8* %16, i8** %6
%17 = load i8*, i8** %6
%18 = load i8*, i8** @MAP_FAILED
%19 = icmp eq i8* %17, %18
br i1 %19, label %20, label %21
20: ; preds = %1
store i8* null, i8** %2
br label %23
21: ; preds = %1
%22 = load i8*, i8** %6
store i8* %22, i8** %2
br label %23
23: ; preds = %21, %20
%24 = load i8*, i8** %2
ret i8* %24
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i8* null
define i8* @vispo_alloc_pages(i32 %0) {
%2 = load i32, i32* @PROT_READ
%3 = load i32, i32* @PROT_WRITE
%4 = or i32 %3, %2
%5 = load i32, i32* @MAP_ANONYMOUS
%6 = load i32, i32* @MAP_PRIVATE
%7 = or i32 %6, %5
%8 = tail call i8* @mmap(i32* null, i32 %0, i32 %4, i32 %7, i32 -1, i32 0)
%9 = load i8*, i8** @MAP_FAILED
%10 = icmp eq i8* %8, %9
%11 = select i1 %10, i8* null, i8* %8
ret i8* %11
}