#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_PRIVATE;
int PROT_READ;
int PROT_WRITE;
void *mmap(void *, size_t, int, int, int const, int const);
void *morecore(size_t size_in_bytes) {
  void *addr = 0;
  const int filedescriptor = -1;
  const int offset = 0;
  void *p = mmap(addr, size_in_bytes, PROT_READ | PROT_WRITE,
                 MAP_PRIVATE | MAP_ANON, filedescriptor, offset);
  if (p == MAP_FAILED)
    return NULL;
  return p;
}


x86 assembly (clang, -O0):
<morecore>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    0x2eb7(%rip),%rax
mov    (%rax),%edx
mov    0x2e8e(%rip),%rax
or     (%rax),%edx
mov    0x2e75(%rip),%rax
mov    (%rax),%ecx
mov    0x2e74(%rip),%rax
or     (%rax),%ecx
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2e45(%rip),%rcx
cmp    (%rcx),%rax
jne    1191 <morecore+0x81>
movq   $0x0,-0x8(%rbp)
jmp    1199 <morecore+0x89>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<morecore>:
push   %rbx
mov    %rdi,%rsi
mov    0x2edd(%rip),%rax
mov    0x2eb6(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e9b(%rip),%rax
mov    0x2e9c(%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    0x2e6f(%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_PRIVATE = global i32 0
@MAP_ANON = global i32 0
@MAP_FAILED = global i8* null
define i8* @morecore(i64 %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
store i64 %0, i64* %3
store i8* null, i8** %4
store i32 -1, i32* %5
store i32 0, i32* %6
%8 = load i8*, i8** %4
%9 = load i64, i64* %3
%10 = load i32, i32* @PROT_READ
%11 = load i32, i32* @PROT_WRITE
%12 = or i32 %10, %11
%13 = load i32, i32* @MAP_PRIVATE
%14 = load i32, i32* @MAP_ANON
%15 = or i32 %13, %14
%16 = call i8* @mmap(i8* %8, i64 %9, i32 %12, i32 %15, i32 -1, i32 0)
store i8* %16, i8** %7
%17 = load i8*, i8** %7
%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** %7
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_PRIVATE = global i32 0
@MAP_ANON = global i32 0
@MAP_FAILED = global i8* null
define i8* @morecore(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_ANON
%7 = or i32 %6, %5
%8 = tail call i8* @mmap(i8* null, i64 %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
}