#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 PROT_NONE;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char *mmap(int /*<<< orphan*/ *, int, int, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(void) {
  char *ptr;
  int ind, cnt;
  cnt = 100000;
  for (ind = 0; ind < cnt; ind++) {
    ptr = mmap(NULL, 100, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS,
               -1, 0);
    if (ptr == NULL) {
      fprintf(stderr, "Error allocating memory using mmap\n");
      return -1;
    }
    ptr = mmap(NULL, 100, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
    if (ptr == NULL) {
      fprintf(stderr, "Error allocating memory using mmap\n");
      return -1;
    }
  }
  ptr = NULL;
  *ptr = '\0';
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x186a0,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1229 <main+0x109>
mov    0x2ea8(%rip),%rax
mov    (%rax),%edx
mov    0x2e67(%rip),%rax
or     (%rax),%edx
mov    0x2e56(%rip),%rax
mov    (%rax),%ecx
mov    0x2e6d(%rip),%rax
or     (%rax),%ecx
xor    %eax,%eax
mov    %eax,%edi
mov    $0x64,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b4 <main+0x94>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
lea    0xe5d(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    123f <main+0x11f>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edx
mov    0x2df4(%rip),%rax
mov    (%rax),%ecx
mov    0x2e0b(%rip),%rax
or     (%rax),%ecx
xor    %eax,%eax
mov    %eax,%edi
mov    $0x64,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1216 <main+0xf6>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
lea    0xdfb(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    123f <main+0x11f>
jmp    121b <main+0xfb>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113d <main+0x1d>
movq   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2ec6(%rip),%r14
mov    0x2e87(%rip),%r15
mov    (%r15),%edx
or     (%r14),%edx
mov    0x2e72(%rip),%r12
mov    0x2e8b(%rip),%r13
mov    0x0(%r13),%ecx
or     (%r12),%ecx
xor    %ebx,%ebx
xor    %edi,%edi
mov    $0x64,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
test   %rax,%rax
je     11d0 <main+0xb0>
mov    0x2e70(%rip),%rbp
nopl   0x0(%rax,%rax,1)
mov    0x0(%rbp),%edx
mov    0x0(%r13),%ecx
or     (%r12),%ecx
xor    %edi,%edi
mov    $0x64,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
test   %rax,%rax
je     11d0 <main+0xb0>
mov    (%r15),%edx
or     (%r14),%edx
add    $0x1,%ebx
mov    0x0(%r13),%ecx
or     (%r12),%ecx
xor    %edi,%edi
mov    $0x64,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
test   %rax,%rax
jne    1180 <main+0x60>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
lea    0xe20(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@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 = [36 x i8] c"Error allocating memory using mmap\0A\00"
@PROT_NONE = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 100000, i32* %4
store i32 0, i32* %3
br label %5
5: ; preds = %34, %0
%6 = load i32, i32* %3
%7 = load i32, i32* %4
%8 = icmp slt i32 %6, %7
br i1 %8, label %9, label %37
9: ; preds = %5
%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_ANONYMOUS
%15 = or i32 %13, %14
%16 = call i8* @mmap(i32* null, i32 100, i32 %12, i32 %15, i32 -1, i32 0)
store i8* %16, i8** %2
%17 = load i8*, i8** %2
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %22
19: ; preds = %9
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %39
22: ; preds = %9
%23 = load i32, i32* @PROT_NONE
%24 = load i32, i32* @MAP_PRIVATE
%25 = load i32, i32* @MAP_ANONYMOUS
%26 = or i32 %24, %25
%27 = call i8* @mmap(i32* null, i32 100, i32 %23, i32 %26, i32 -1, i32 0)
store i8* %27, i8** %2
%28 = load i8*, i8** %2
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %33
30: ; preds = %22
%31 = load i32, i32* @stderr
%32 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %39
33: ; preds = %22
br label %34
34: ; preds = %33
%35 = load i32, i32* %3
%36 = add nsw i32 %35, 1
store i32 %36, i32* %3
br label %5
37: ; preds = %5
store i8* null, i8** %2
%38 = load i8*, i8** %2
store i8 0, i8* %38
store i32 0, i32* %1
br label %39
39: ; preds = %37, %30, %19
%40 = load i32, i32* %1
ret i32 %40
}

LLVM IR (-O2):
@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 = [36 x i8] c"Error allocating memory using mmap\0A\00"
@PROT_NONE = global i32 0
define i32 @main() {
%1 = load i32, i32* @PROT_READ
%2 = load i32, i32* @PROT_WRITE
%3 = or i32 %2, %1
%4 = load i32, i32* @MAP_PRIVATE
%5 = load i32, i32* @MAP_ANONYMOUS
%6 = or i32 %5, %4
%7 = tail call i8* @mmap(i32* null, i32 100, i32 %3, i32 %6, i32 -1, i32 0)
%8 = icmp eq i8* %7, null
br i1 %8, label %28, label %20
9: ; preds = %20
%10 = add nuw nsw i32 %21, 1
%11 = icmp ult i32 %21, 99999
tail call void @llvm.assume(i1 %11)
%12 = load i32, i32* @PROT_READ
%13 = load i32, i32* @PROT_WRITE
%14 = or i32 %13, %12
%15 = load i32, i32* @MAP_PRIVATE
%16 = load i32, i32* @MAP_ANONYMOUS
%17 = or i32 %16, %15
%18 = tail call i8* @mmap(i32* null, i32 100, i32 %14, i32 %17, i32 -1, i32 0)
%19 = icmp eq i8* %18, null
br i1 %19, label %28, label %20
20: ; preds = %0, %9
%21 = phi i32 [ %10, %9 ], [ 0, %0 ]
%22 = load i32, i32* @PROT_NONE
%23 = load i32, i32* @MAP_PRIVATE
%24 = load i32, i32* @MAP_ANONYMOUS
%25 = or i32 %24, %23
%26 = tail call i8* @mmap(i32* null, i32 100, i32 %22, i32 %25, i32 -1, i32 0)
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %9
28: ; preds = %20, %9, %0
%29 = load i32, i32* @stderr
%30 = tail call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
ret i32 -1
}