#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;
scalar_t__ handle_mem_failure(size_t);
void *mmap(void *, size_t, int, int, int, int /*<<< orphan*/);
void *my_mmap(void *addr, size_t length, int prot, int flags, int fd,
              off_t offset) {
  void *new;
  do {
    new = mmap(addr, length, prot, flags, fd, offset);
  } while (new == MAP_FAILED && handle_mem_failure(length));
  return new;
}


x86 assembly (clang, -O0):
<my_mmap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    %r9d,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
mov    -0x20(%rbp),%r9d
call   1030 <mmap@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rcx
xor    %eax,%eax
mov    0x2e76(%rip),%rdx
cmp    (%rdx),%rcx
mov    %al,-0x29(%rbp)
jne    1189 <my_mmap+0x69>
mov    -0x10(%rbp),%rdi
call   1040 <handle_mem_failure@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    113e <my_mmap+0x1e>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_mmap>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9d,0x4(%rsp)
mov    %r8d,%r15d
mov    %ecx,%r12d
mov    %edx,%r13d
mov    %rsi,%rbx
mov    %rdi,%rbp
nop
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r13d,%edx
mov    %r12d,%ecx
mov    %r15d,%r8d
mov    0x4(%rsp),%r9d
call   1030 <mmap@plt>
mov    %rax,%r14
mov    0x2e7d(%rip),%rax
cmp    (%rax),%r14
jne    1175 <my_mmap+0x55>
mov    %rbx,%rdi
call   1040 <handle_mem_failure@plt>
test   %rax,%rax
jne    1140 <my_mmap+0x20>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@MAP_FAILED = global i8* null
define i8* @my_mmap(i8* %0, i64 %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
store i8* %0, i8** %7
store i64 %1, i64* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32 %5, i32* %12
br label %14
14: ; preds = %30, %6
%15 = load i8*, i8** %7
%16 = load i64, i64* %8
%17 = load i32, i32* %9
%18 = load i32, i32* %10
%19 = load i32, i32* %11
%20 = load i32, i32* %12
%21 = call i8* @mmap(i8* %15, i64 %16, i32 %17, i32 %18, i32 %19, i32 %20)
store i8* %21, i8** %13
br label %22
22: ; preds = %14
%23 = load i8*, i8** %13
%24 = load i8*, i8** @MAP_FAILED
%25 = icmp eq i8* %23, %24
br i1 %25, label %26, label %30
26: ; preds = %22
%27 = load i64, i64* %8
%28 = call i64 @handle_mem_failure(i64 %27)
%29 = icmp ne i64 %28, 0
br label %30
30: ; preds = %26, %22
%31 = phi i1 [ false, %22 ], [ %29, %26 ]
br i1 %31, label %14, label %32
32: ; preds = %30
%33 = load i8*, i8** %13
ret i8* %33
}

LLVM IR (-O2):
@MAP_FAILED = global i8* null
define i8* @my_mmap(i8* %0, i64 %1, i32 %2, i32 %3, i32 %4, i32 %5) {
br label %7
7: ; preds = %11, %6
%8 = tail call i8* @mmap(i8* %0, i64 %1, i32 %2, i32 %3, i32 %4, i32 %5)
%9 = load i8*, i8** @MAP_FAILED
%10 = icmp eq i8* %8, %9
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = tail call i64 @handle_mem_failure(i64 %1)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %7
14: ; preds = %7, %11
ret i8* %8
}