#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 */
int /*<<< orphan*/ EINVAL;
void *MAP_FAILED;
void *__mmap2(void *, size_t, int /*<<< orphan*/, int /*<<< orphan*/, int,
              size_t);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ mips_change_flags(int);
int /*<<< orphan*/ mips_change_prot(int);
void *mmap(void *addr, size_t size, int prot, int flags, int fd, long offset) {
  if (offset & ((1UL << 12) - 1)) {
    errno = EINVAL;
    return MAP_FAILED;
  }
  return __mmap2(addr, size, mips_change_prot(prot), mips_change_flags(flags),
                 fd, (size_t)offset >> 12);
}


x86 assembly (clang, -O0):
<mmap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x30(%rbp),%rax
and    $0xfff,%rax
cmp    $0x0,%rax
je     1187 <mmap+0x57>
mov    0x2e6f(%rip),%rax
mov    (%rax),%ecx
mov    0x2e6e(%rip),%rax
mov    %ecx,(%rax)
mov    0x2e55(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    11cc <mmap+0x9c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x1c(%rbp),%edi
call   1050 <mips_change_prot@plt>
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%edi
call   1040 <mips_change_flags@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x34(%rbp),%edx
mov    %eax,%ecx
mov    -0x24(%rbp),%r8d
mov    -0x30(%rbp),%r9
shr    $0xc,%r9
call   1030 <__mmap2@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%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,%rbx
test   $0xfff,%ebx
je     1171 <mmap+0x41>
mov    0x2e8b(%rip),%rax
mov    (%rax),%eax
mov    0x2e8a(%rip),%rcx
mov    %eax,(%rcx)
mov    0x2e71(%rip),%rax
mov    (%rax),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r8d,%r14d
mov    %ecx,%ebp
mov    %rsi,%r15
mov    %rdi,%r12
mov    %edx,%edi
call   1050 <mips_change_prot@plt>
mov    %eax,%r13d
mov    %ebp,%edi
call   1040 <mips_change_flags@plt>
shr    $0xc,%rbx
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r13d,%edx
mov    %eax,%ecx
mov    %r14d,%r8d
mov    %rbx,%r9
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <__mmap2@plt>

LLVM IR (-O0):
@EINVAL = global i32 0
@errno = global i32 0
@MAP_FAILED = global i8* null
define i8* @mmap(i8* %0, i64 %1, i32 %2, i32 %3, i32 %4, i64 %5) {
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i64
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 i64 %5, i64* %13
%14 = load i64, i64* %13
%15 = and i64 %14, 4095
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %6
%18 = load i32, i32* @EINVAL
store i32 %18, i32* @errno
%19 = load i8*, i8** @MAP_FAILED
store i8* %19, i8** %7
br label %31
20: ; preds = %6
%21 = load i8*, i8** %8
%22 = load i64, i64* %9
%23 = load i32, i32* %10
%24 = call i32 @mips_change_prot(i32 %23)
%25 = load i32, i32* %11
%26 = call i32 @mips_change_flags(i32 %25)
%27 = load i32, i32* %12
%28 = load i64, i64* %13
%29 = lshr i64 %28, 12
%30 = call i8* @__mmap2(i8* %21, i64 %22, i32 %24, i32 %26, i32 %27, i64 %29)
store i8* %30, i8** %7
br label %31
31: ; preds = %20, %17
%32 = load i8*, i8** %7
ret i8* %32
}

LLVM IR (-O2):
@EINVAL = global i32 0
@errno = global i32 0
@MAP_FAILED = global i8* null
define i8* @mmap(i8* %0, i64 %1, i32 %2, i32 %3, i32 %4, i64 %5) {
%7 = and i64 %5, 4095
%8 = icmp eq i64 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %6
%10 = load i32, i32* @EINVAL
store i32 %10, i32* @errno
%11 = load i8*, i8** @MAP_FAILED
br label %17
12: ; preds = %6
%13 = tail call i32 @mips_change_prot(i32 %2)
%14 = tail call i32 @mips_change_flags(i32 %3)
%15 = lshr i64 %5, 12
%16 = tail call i8* @__mmap2(i8* %0, i64 %1, i32 %13, i32 %14, i32 %4, i64 %15)
br label %17
17: ; preds = %12, %9
%18 = phi i8* [ %11, %9 ], [ %16, %12 ]
ret i8* %18
}