#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, int, int, size_t);
int /*<<< orphan*/ errno;
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, prot, flags, fd, (size_t)offset >> 12);
}


x86 assembly (clang, -O0):
<mmap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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     1167 <mmap+0x57>
mov    0x2e8f(%rip),%rax
mov    (%rax),%ecx
mov    0x2e8e(%rip),%rax
mov    %ecx,(%rax)
mov    0x2e75(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    118a <mmap+0x7a>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%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    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mmap>:
test   $0xfff,%r9d
je     1136 <mmap+0x26>
mov    0x2eb8(%rip),%rax
mov    (%rax),%eax
mov    0x2eb7(%rip),%rcx
mov    %eax,(%rcx)
mov    0x2e9e(%rip),%rax
mov    (%rax),%rax
ret
shr    $0xc,%r9
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 %29
20: ; preds = %6
%21 = load i8*, i8** %8
%22 = load i64, i64* %9
%23 = load i32, i32* %10
%24 = load i32, i32* %11
%25 = load i32, i32* %12
%26 = load i64, i64* %13
%27 = lshr i64 %26, 12
%28 = call i8* @__mmap2(i8* %21, i64 %22, i32 %23, i32 %24, i32 %25, i64 %27)
store i8* %28, i8** %7
br label %29
29: ; preds = %20, %17
%30 = load i8*, i8** %7
ret i8* %30
}

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 %15
12: ; preds = %6
%13 = lshr i64 %5, 12
%14 = tail call i8* @__mmap2(i8* %0, i64 %1, i32 %2, i32 %3, i32 %4, i64 %13)
br label %15
15: ; preds = %12, %9
%16 = phi i8* [ %11, %9 ], [ %14, %12 ]
ret i8* %16
}