#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 scalar_t__ off_t;

/* Variables and functions */
int MAP_FIXED;
int /*<<< orphan*/ __vm_lock(int);
int /*<<< orphan*/ __vm_unlock();
scalar_t__ syscall(int, void *, size_t, int, int, int, scalar_t__);
void *__mmap(void *start, size_t len, int prot, int flags, int fd, off_t off) {
  void *ret;
  if (sizeof(off_t) > sizeof(long))
    if (((long)off & 0xfff) |
        ((long)((unsigned long long)off >>
                (12 + 8 * (sizeof(off_t) - sizeof(long))))))
      start = (void *)-1;
  if (flags & MAP_FIXED)
    __vm_lock(-1);
  ret = (void *)syscall(9, start, len, prot, flags, fd, off);
  if (flags & MAP_FIXED)
    __vm_unlock();
  return ret;
}


x86 assembly (clang, -O0):
<__mmap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    %r9,-0x28(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2e88(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     116d <__mmap+0x3d>
mov    $0xffffffff,%edi
call   1050 <__vm_lock@plt>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
mov    -0x1c(%rbp),%r9d
mov    -0x28(%rbp),%rax
mov    $0x9,%edi
mov    %rax,(%rsp)
call   1030 <syscall@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2e40(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11b2 <__mmap+0x82>
mov    $0x0,%al
call   1040 <__vm_unlock@plt>
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__mmap>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%r12
mov    %r8d,%r14d
mov    %ecx,%ebx
mov    %edx,%r15d
mov    %rsi,%r13
mov    %rdi,%rbp
mov    0x2e8d(%rip),%rax
test   %ecx,(%rax)
je     1161 <__mmap+0x31>
mov    $0xffffffff,%edi
call   1050 <__vm_lock@plt>
mov    %r12,(%rsp)
mov    $0x9,%edi
mov    %rbp,%rsi
mov    %r13,%rdx
mov    %r15d,%ecx
mov    %ebx,%r8d
mov    %r14d,%r9d
call   1030 <syscall@plt>
mov    %rax,%rbp
mov    0x2e58(%rip),%rax
test   %ebx,(%rax)
je     1193 <__mmap+0x63>
xor    %eax,%eax
call   1040 <__vm_unlock@plt>
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@MAP_FIXED = global i32 0
define i8* @__mmap(i8* %0, i64 %1, i32 %2, i32 %3, i32 %4, i64 %5) {
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i64
%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 i64 %5, i64* %12
%14 = load i32, i32* %10
%15 = load i32, i32* @MAP_FIXED
%16 = and i32 %14, %15
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %6
%19 = call i32 @__vm_lock(i32 -1)
br label %20
20: ; preds = %18, %6
%21 = load i8*, i8** %7
%22 = load i64, i64* %8
%23 = load i32, i32* %9
%24 = load i32, i32* %10
%25 = load i32, i32* %11
%26 = load i64, i64* %12
%27 = call i64 @syscall(i32 9, i8* %21, i64 %22, i32 %23, i32 %24, i32 %25, i64 %26)
%28 = inttoptr i64 %27 to i8*
store i8* %28, i8** %13
%29 = load i32, i32* %10
%30 = load i32, i32* @MAP_FIXED
%31 = and i32 %29, %30
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %20
%34 = call i32 (...) @__vm_unlock()
br label %35
35: ; preds = %33, %20
%36 = load i8*, i8** %13
ret i8* %36
}

LLVM IR (-O2):
@MAP_FIXED = global i32 0
define i8* @__mmap(i8* %0, i64 %1, i32 %2, i32 %3, i32 %4, i64 %5) {
%7 = load i32, i32* @MAP_FIXED
%8 = and i32 %7, %3
%9 = icmp eq i32 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %6
%11 = tail call i32 @__vm_lock(i32 -1)
br label %12
12: ; preds = %10, %6
%13 = tail call i64 @syscall(i32 9, i8* %0, i64 %1, i32 %2, i32 %3, i32 %4, i64 %5)
%14 = load i32, i32* @MAP_FIXED
%15 = and i32 %14, %3
%16 = icmp eq i32 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %12
%18 = tail call i32 (...) @__vm_unlock()
br label %19
19: ; preds = %17, %12
%20 = inttoptr i64 %13 to i8*
ret i8* %20
}