#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_LOCKED;
int MAP_POPULATE;
int MAP_PRIVATE;
int PROT_READ;
int PROT_WRITE;
void *mmap(int /*<<< orphan*/ *, size_t, int, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
void *pagealign_alloc(size_t size) {
  void *ret =
      mmap(NULL, size, PROT_READ | PROT_WRITE,
           MAP_PRIVATE | MAP_ANONYMOUS | MAP_POPULATE | MAP_LOCKED, -1, 0);
  if (ret == MAP_FAILED) {
    perror("mmap");
    ret = NULL;
  }
  return ret;
}


x86 assembly (clang, -O0):
<pagealign_alloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
mov    0x2ec1(%rip),%rax
mov    (%rax),%edx
mov    0x2e80(%rip),%rax
or     (%rax),%edx
mov    0x2e6f(%rip),%rax
mov    (%rax),%ecx
mov    0x2e8e(%rip),%rax
or     (%rax),%ecx
mov    0x2e7d(%rip),%rax
or     (%rax),%ecx
mov    0x2e64(%rip),%rax
or     (%rax),%ecx
xor    %eax,%eax
mov    %eax,%edi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2e29(%rip),%rcx
cmp    (%rcx),%rax
jne    11a4 <pagealign_alloc+0x84>
lea    0xe69(%rip),%rdi
call   1040 <perror@plt>
movq   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pagealign_alloc>:
push   %rax
mov    0x2ed0(%rip),%rax
mov    0x2e91(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e7e(%rip),%rax
mov    0x2e9f(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2e8c(%rip),%rax
or     (%rax),%ecx
mov    %rdi,%rsi
mov    0x2e70(%rip),%rax
or     (%rax),%ecx
xor    %edi,%edi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    0x2e3f(%rip),%rcx
cmp    (%rcx),%rax
je     1178 <pagealign_alloc+0x58>
pop    %rcx
ret
lea    0xe81(%rip),%rdi
call   1040 <perror@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_POPULATE = global i32 0
@MAP_LOCKED = global i32 0
@MAP_FAILED = global i8* null
@.str = [5 x i8] c"mmap\00"
define i8* @pagealign_alloc(i64 %0) {
%2 = alloca i64
%3 = alloca i8*
store i64 %0, i64* %2
%4 = load i64, i64* %2
%5 = load i32, i32* @PROT_READ
%6 = load i32, i32* @PROT_WRITE
%7 = or i32 %5, %6
%8 = load i32, i32* @MAP_PRIVATE
%9 = load i32, i32* @MAP_ANONYMOUS
%10 = or i32 %8, %9
%11 = load i32, i32* @MAP_POPULATE
%12 = or i32 %10, %11
%13 = load i32, i32* @MAP_LOCKED
%14 = or i32 %12, %13
%15 = call i8* @mmap(i32* null, i64 %4, i32 %7, i32 %14, i32 -1, i32 0)
store i8* %15, i8** %3
%16 = load i8*, i8** %3
%17 = load i8*, i8** @MAP_FAILED
%18 = icmp eq i8* %16, %17
br i1 %18, label %19, label %21
19: ; preds = %1
%20 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %3
br label %21
21: ; preds = %19, %1
%22 = load i8*, i8** %3
ret i8* %22
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_POPULATE = global i32 0
@MAP_LOCKED = global i32 0
@MAP_FAILED = global i8* null
@.str = [5 x i8] c"mmap\00"
define i8* @pagealign_alloc(i64 %0) {
%2 = load i32, i32* @PROT_READ
%3 = load i32, i32* @PROT_WRITE
%4 = or i32 %3, %2
%5 = load i32, i32* @MAP_PRIVATE
%6 = load i32, i32* @MAP_ANONYMOUS
%7 = or i32 %6, %5
%8 = load i32, i32* @MAP_POPULATE
%9 = or i32 %7, %8
%10 = load i32, i32* @MAP_LOCKED
%11 = or i32 %9, %10
%12 = tail call i8* @mmap(i32* null, i64 %0, i32 %4, i32 %11, i32 -1, i32 0)
%13 = load i8*, i8** @MAP_FAILED
%14 = icmp eq i8* %12, %13
br i1 %14, label %15, label %17
15: ; preds = %1
%16 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %1
%18 = phi i8* [ null, %15 ], [ %12, %1 ]
ret i8* %18
}