#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;
int MAP_PRIVATE;
int PAGE_SIZE;
int PROT_READ;
int PROT_WRITE;
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, int);
void *mmap(int /*<<< orphan*/, int, int, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main() {
  int i;
  void *ret;
  for (i = 0;; i++) {
    ret = mmap(0, PAGE_SIZE * 2, PROT_READ | PROT_WRITE,
               MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
    if (ret == (void *)-1) {
      fprintf(stderr, " Allocation failed #%d. errno %d\n", i, errno);
      exit(1);
    }
    *((char *)ret) = 0;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    0x2e93(%rip),%rax
mov    (%rax),%esi
shl    $0x1,%esi
mov    0x2e9f(%rip),%rax
mov    (%rax),%edx
mov    0x2e56(%rip),%rax
or     (%rax),%edx
mov    0x2e45(%rip),%rax
mov    (%rax),%ecx
mov    0x2e64(%rip),%rax
or     (%rax),%ecx
xor    %r9d,%r9d
mov    $0xffffffff,%r8d
mov    %r9d,%edi
call   1030 <mmap@plt>
mov    %rax,-0x10(%rbp)
mov    $0xffffffffffffffff,%rax
cmp    %rax,-0x10(%rbp)
jne    11c7 <main+0x97>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
mov    0x2e11(%rip),%rax
mov    (%rax),%ecx
lea    0xe48(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1146 <main+0x16>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %ebx,%ebx
mov    0x2e9c(%rip),%r14
mov    0x2ead(%rip),%r15
mov    0x2e66(%rip),%r12
mov    0x2e57(%rip),%r13
mov    0x2e78(%rip),%rbp
mov    (%r14),%esi
mov    (%r12),%edx
or     (%r15),%edx
add    %esi,%esi
mov    0x0(%rbp),%ecx
or     0x0(%r13),%ecx
xor    %edi,%edi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
cmp    $0xffffffffffffffff,%rax
je     1191 <main+0x61>
movb   $0x0,(%rax)
add    $0x1,%ebx
jmp    1160 <main+0x30>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
mov    0x2e1f(%rip),%rax
mov    (%rax),%ecx
lea    0xe56(%rip),%rsi
mov    %ebx,%edx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@PAGE_SIZE = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@stderr = global i32 0
@.str = [34 x i8] c" Allocation failed #%d. errno %d\0A\00"
@errno = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
store i32 0, i32* %1
store i32 0, i32* %2
br label %4
4: ; preds = %24, %0
%5 = load i32, i32* @PAGE_SIZE
%6 = mul nsw i32 %5, 2
%7 = load i32, i32* @PROT_READ
%8 = load i32, i32* @PROT_WRITE
%9 = or i32 %7, %8
%10 = load i32, i32* @MAP_PRIVATE
%11 = load i32, i32* @MAP_ANONYMOUS
%12 = or i32 %10, %11
%13 = call i8* @mmap(i32 0, i32 %6, i32 %9, i32 %12, i32 -1, i32 0)
store i8* %13, i8** %3
%14 = load i8*, i8** %3
%15 = icmp eq i8* %14, inttoptr (i64 -1 to i8*)
br i1 %15, label %16, label %22
16: ; preds = %4
%17 = load i32, i32* @stderr
%18 = load i32, i32* %2
%19 = load i32, i32* @errno
%20 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %18, i32 %19)
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %4
%23 = load i8*, i8** %3
store i8 0, i8* %23
br label %24
24: ; preds = %22
%25 = load i32, i32* %2
%26 = add nsw i32 %25, 1
store i32 %26, i32* %2
br label %4
}

LLVM IR (-O2):
@PAGE_SIZE = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@stderr = global i32 0
@.str = [34 x i8] c" Allocation failed #%d. errno %d\0A\00"
@errno = global i32 0
define i32 @main() {
br label %1
1: ; preds = %18, %0
%2 = phi i32 [ 0, %0 ], [ %19, %18 ]
%3 = load i32, i32* @PAGE_SIZE
%4 = shl nsw i32 %3, 1
%5 = load i32, i32* @PROT_READ
%6 = load i32, i32* @PROT_WRITE
%7 = or i32 %6, %5
%8 = load i32, i32* @MAP_PRIVATE
%9 = load i32, i32* @MAP_ANONYMOUS
%10 = or i32 %9, %8
%11 = tail call i8* @mmap(i32 0, i32 %4, i32 %7, i32 %10, i32 -1, i32 0)
%12 = icmp eq i8* %11, inttoptr (i64 -1 to i8*)
br i1 %12, label %13, label %18
13: ; preds = %1
%14 = load i32, i32* @stderr
%15 = load i32, i32* @errno
%16 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %2, i32 %15)
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %1
store i8 0, i8* %11
%19 = add nuw nsw i32 %2, 1
br label %1
}