#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 /*<<< orphan*/ MAP_PRIVATE;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ mmap(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/, int,
                        int);
int do_inf_mmap(void *data) {
  int fd = (int)data;
  int i;
  for (i = 0; i < (1 << 10); i++) {
    mmap(NULL, 4096 * 40 / 2, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd,
         4096 * 40 / 2);
  }
  return 0;
}


x86 assembly (clang, -O0):
<do_inf_mmap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x400,-0x10(%rbp)
jge    1176 <do_inf_mmap+0x66>
mov    0x2eba(%rip),%rax
mov    (%rax),%edx
mov    0x2e91(%rip),%rax
or     (%rax),%edx
mov    0x2e80(%rip),%rax
mov    (%rax),%ecx
mov    -0xc(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0x14000,%r9d
mov    %r9d,%esi
call   1030 <mmap@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    112a <do_inf_mmap+0x1a>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_inf_mmap>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%rbx
mov    $0x400,%ebp
mov    0x2ed1(%rip),%r14
mov    0x2eaa(%rip),%r15
mov    0x2e9b(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r15),%edx
or     (%r14),%edx
mov    (%r12),%ecx
xor    %edi,%edi
mov    $0x14000,%esi
mov    %ebx,%r8d
mov    $0x14000,%r9d
call   1030 <mmap@plt>
add    $0xffffffff,%ebp
jne    1140 <do_inf_mmap+0x30>
xor    %eax,%eax
pop    %rbx
pop    %r12
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
define i32 @do_inf_mmap(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = ptrtoint i8* %5 to i32
store i32 %6, i32* %3
store i32 0, i32* %4
br label %7
7: ; preds = %17, %1
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 1024
br i1 %9, label %10, label %20
10: ; preds = %7
%11 = load i32, i32* @PROT_READ
%12 = load i32, i32* @PROT_WRITE
%13 = or i32 %11, %12
%14 = load i32, i32* @MAP_PRIVATE
%15 = load i32, i32* %3
%16 = call i32 @mmap(i32* null, i32 81920, i32 %13, i32 %14, i32 %15, i32 81920)
br label %17
17: ; preds = %10
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 1
store i32 %19, i32* %4
br label %7
20: ; preds = %7
ret i32 0
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
define i32 @do_inf_mmap(i8* %0) {
%2 = ptrtoint i8* %0 to i64
%3 = trunc i64 %2 to i32
br label %4
4: ; preds = %1, %4
%5 = phi i32 [ 0, %1 ], [ %11, %4 ]
%6 = load i32, i32* @PROT_READ
%7 = load i32, i32* @PROT_WRITE
%8 = or i32 %7, %6
%9 = load i32, i32* @MAP_PRIVATE
%10 = tail call i32 @mmap(i32* null, i32 81920, i32 %8, i32 %9, i32 %3, i32 81920)
%11 = add nuw nsw i32 %5, 1
%12 = icmp eq i32 %11, 1024
br i1 %12, label %13, label %4
13: ; preds = %4
ret i32 0
}