#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 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, int);
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(192, start, len, prot, flags, fd, off >> 12);
  if (flags & MAP_FIXED)
    __vm_unlock();
  return ret;
}


x86 assembly (clang, -O0):
<__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    -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    -0x20(%rbp),%eax
sar    $0xc,%eax
mov    $0xc0,%edi
mov    %eax,(%rsp)
call   1030 <syscall@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2e3f(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11b3 <__mmap+0x83>
mov    $0x0,%al
call   1040 <__vm_unlock@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__mmap>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9d,%ebp
mov    %r8d,%r14d
mov    %ecx,%ebx
mov    %edx,%r15d
mov    %rsi,%r12
mov    %rdi,%r13
mov    0x2e8d(%rip),%rax
test   %ecx,(%rax)
je     1161 <__mmap+0x31>
mov    $0xffffffff,%edi
call   1050 <__vm_lock@plt>
sar    $0xc,%ebp
mov    %ebp,(%rsp)
mov    $0xc0,%edi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %r15d,%ecx
mov    %ebx,%r8d
mov    %r14d,%r9d
call   1030 <syscall@plt>
mov    %rax,%rbp
mov    0x2e56(%rip),%rax
test   %ebx,(%rax)
je     1195 <__mmap+0x65>
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, 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
%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 i32, i32* %12
%27 = ashr i32 %26, 12
%28 = call i64 @syscall(i32 192, i8* %21, i64 %22, i32 %23, i32 %24, i32 %25, i32 %27)
%29 = inttoptr i64 %28 to i8*
store i8* %29, i8** %13
%30 = load i32, i32* %10
%31 = load i32, i32* @MAP_FIXED
%32 = and i32 %30, %31
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %20
%35 = call i32 (...) @__vm_unlock()
br label %36
36: ; preds = %34, %20
%37 = load i8*, i8** %13
ret i8* %37
}

LLVM IR (-O2):
@MAP_FIXED = global i32 0
define i8* @__mmap(i8* %0, i64 %1, i32 %2, i32 %3, i32 %4, i32 %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 = ashr i32 %5, 12
%14 = tail call i64 @syscall(i32 192, i8* %0, i64 %1, i32 %2, i32 %3, i32 %4, i32 %13)
%15 = load i32, i32* @MAP_FIXED
%16 = and i32 %15, %3
%17 = icmp eq i32 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %12
%19 = tail call i32 (...) @__vm_unlock()
br label %20
20: ; preds = %18, %12
%21 = inttoptr i64 %14 to i8*
ret i8* %21
}