#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 */
typedef int /*<<< orphan*/ off_t;

/* Variables and functions */
void *MAP_FAILED;
int /*<<< orphan*/ die(char *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
void *mmap(void *, size_t, int, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ release_pack_memory(size_t, int);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
void *xmmap(void *start, size_t length, int prot, int flags, int fd,
            off_t offset) {
  void *ret = mmap(start, length, prot, flags, fd, offset);
  if (ret == MAP_FAILED) {
    if (!length)
      return NULL;
    release_pack_memory(length, fd);
    ret = mmap(start, length, prot, flags, fd, offset);
    if (ret == MAP_FAILED)
      die("Out of memory? mmap failed: %s", strerror(errno));
  }
  return ret;
}


x86 assembly (clang, -O0):
<xmmap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x24(%rbp),%r8d
mov    -0x28(%rbp),%r9d
call   1030 <mmap@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    0x2e50(%rip),%rcx
cmp    (%rcx),%rax
jne    1209 <xmmap+0xc9>
cmpq   $0x0,-0x18(%rbp)
jne    11a9 <xmmap+0x69>
movq   $0x0,-0x8(%rbp)
jmp    1211 <xmmap+0xd1>
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1040 <release_pack_memory@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x24(%rbp),%r8d
mov    -0x28(%rbp),%r9d
call   1030 <mmap@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    0x2df9(%rip),%rcx
cmp    (%rcx),%rax
jne    1204 <xmmap+0xc4>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %eax,%esi
lea    0xe01(%rip),%rdi
call   1050 <die@plt>
jmp    1209 <xmmap+0xc9>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xmmap>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r14d
mov    %ecx,%r12d
mov    %edx,%r13d
mov    %rsi,%rbp
mov    %rdi,%r15
mov    %r9d,0x4(%rsp)
call   1030 <mmap@plt>
mov    %rax,%rbx
mov    0x2e6a(%rip),%rax
cmp    (%rax),%rbx
je     1185 <xmmap+0x45>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
test   %rbp,%rbp
je     11da <xmmap+0x9a>
mov    %rbp,%rdi
mov    %r14d,%ebx
mov    %r14d,%esi
mov    %rax,%r14
call   1040 <release_pack_memory@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %r13d,%edx
mov    %r12d,%ecx
mov    %ebx,%r8d
mov    0x4(%rsp),%r9d
call   1030 <mmap@plt>
mov    %rax,%rbx
cmp    (%r14),%rax
jne    1173 <xmmap+0x33>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe2f(%rip),%rdi
mov    %eax,%esi
call   1050 <die@plt>
jmp    1173 <xmmap+0x33>
xor    %ebx,%ebx
jmp    1173 <xmmap+0x33>

LLVM IR (-O0):
@MAP_FAILED = global i8* null
@.str = [31 x i8] c"Out of memory? mmap failed: %s\00"
@errno = global i32 0
define i8* @xmmap(i8* %0, i64 %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
store i8* %0, i8** %8
store i64 %1, i64* %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i32 %5, i32* %13
%15 = load i8*, i8** %8
%16 = load i64, i64* %9
%17 = load i32, i32* %10
%18 = load i32, i32* %11
%19 = load i32, i32* %12
%20 = load i32, i32* %13
%21 = call i8* @mmap(i8* %15, i64 %16, i32 %17, i32 %18, i32 %19, i32 %20)
store i8* %21, i8** %14
%22 = load i8*, i8** %14
%23 = load i8*, i8** @MAP_FAILED
%24 = icmp eq i8* %22, %23
br i1 %24, label %25, label %48
25: ; preds = %6
%26 = load i64, i64* %9
%27 = icmp ne i64 %26, 0
br i1 %27, label %29, label %28
28: ; preds = %25
store i8* null, i8** %7
br label %50
29: ; preds = %25
%30 = load i64, i64* %9
%31 = load i32, i32* %12
%32 = call i32 @release_pack_memory(i64 %30, i32 %31)
%33 = load i8*, i8** %8
%34 = load i64, i64* %9
%35 = load i32, i32* %10
%36 = load i32, i32* %11
%37 = load i32, i32* %12
%38 = load i32, i32* %13
%39 = call i8* @mmap(i8* %33, i64 %34, i32 %35, i32 %36, i32 %37, i32 %38)
store i8* %39, i8** %14
%40 = load i8*, i8** %14
%41 = load i8*, i8** @MAP_FAILED
%42 = icmp eq i8* %40, %41
br i1 %42, label %43, label %47
43: ; preds = %29
%44 = load i32, i32* @errno
%45 = call i32 @strerror(i32 %44)
%46 = call i32 @die(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %45)
br label %47
47: ; preds = %43, %29
br label %48
48: ; preds = %47, %6
%49 = load i8*, i8** %14
store i8* %49, i8** %7
br label %50
50: ; preds = %48, %28
%51 = load i8*, i8** %7
ret i8* %51
}

LLVM IR (-O2):
@MAP_FAILED = global i8* null
@.str = [31 x i8] c"Out of memory? mmap failed: %s\00"
@errno = global i32 0
define i8* @xmmap(i8* %0, i64 %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = tail call i8* @mmap(i8* %0, i64 %1, i32 %2, i32 %3, i32 %4, i32 %5)
%8 = load i8*, i8** @MAP_FAILED
%9 = icmp eq i8* %7, %8
br i1 %9, label %10, label %21
10: ; preds = %6
%11 = icmp eq i64 %1, 0
br i1 %11, label %21, label %12
12: ; preds = %10
%13 = tail call i32 @release_pack_memory(i64 %1, i32 %4)
%14 = tail call i8* @mmap(i8* %0, i64 %1, i32 %2, i32 %3, i32 %4, i32 %5)
%15 = load i8*, i8** @MAP_FAILED
%16 = icmp eq i8* %14, %15
br i1 %16, label %17, label %21
17: ; preds = %12
%18 = load i32, i32* @errno
%19 = tail call i32 @strerror(i32 %18)
%20 = tail call i32 @die(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %6, %17, %12, %10
%22 = phi i8* [ null, %10 ], [ %14, %17 ], [ %14, %12 ], [ %7, %6 ]
ret i8* %22
}