#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 */
void *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ PROT_READ;
void *mmap(int /*<<< orphan*/ *, size_t, int /*<<< orphan*/, int /*<<< orphan*/,
           int, int /*<<< orphan*/);
void *mmap_file(int file_descriptor, size_t fsize) {
  void *addr;
  if (file_descriptor == -1)
    return NULL;
  addr = mmap(NULL, fsize, PROT_READ, MAP_SHARED, file_descriptor, 0);
  if (addr == MAP_FAILED)
    return NULL;
  return addr;
}


x86 assembly (clang, -O0):
<mmap_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1136 <mmap_file+0x26>
movq   $0x0,-0x8(%rbp)
jmp    1189 <mmap_file+0x79>
mov    -0x18(%rbp),%rsi
mov    0x2eb7(%rip),%rax
mov    (%rax),%edx
mov    0x2e9e(%rip),%rax
mov    (%rax),%ecx
mov    -0xc(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2e65(%rip),%rcx
cmp    (%rcx),%rax
jne    1181 <mmap_file+0x71>
movq   $0x0,-0x8(%rbp)
jmp    1189 <mmap_file+0x79>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mmap_file>:
cmp    $0xffffffff,%edi
je     1147 <mmap_file+0x37>
push   %rbx
mov    %edi,%r8d
mov    0x2ed8(%rip),%rax
mov    (%rax),%edx
mov    0x2ebf(%rip),%rax
mov    (%rax),%ecx
xor    %ebx,%ebx
xor    %edi,%edi
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    0x2e92(%rip),%rcx
cmp    (%rcx),%rax
cmove  %rbx,%rax
pop    %rbx
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
define i8* @mmap_file(i32 %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i64
%6 = alloca i8*
store i32 %0, i32* %4
store i64 %1, i64* %5
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %10
9: ; preds = %2
store i8* null, i8** %3
br label %22
10: ; preds = %2
%11 = load i64, i64* %5
%12 = load i32, i32* @PROT_READ
%13 = load i32, i32* @MAP_SHARED
%14 = load i32, i32* %4
%15 = call i8* @mmap(i32* null, i64 %11, i32 %12, i32 %13, i32 %14, i32 0)
store i8* %15, i8** %6
%16 = load i8*, i8** %6
%17 = load i8*, i8** @MAP_FAILED
%18 = icmp eq i8* %16, %17
br i1 %18, label %19, label %20
19: ; preds = %10
store i8* null, i8** %3
br label %22
20: ; preds = %10
%21 = load i8*, i8** %6
store i8* %21, i8** %3
br label %22
22: ; preds = %20, %19, %9
%23 = load i8*, i8** %3
ret i8* %23
}

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