#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 /*<<< orphan*/ off_t;
typedef int /*<<< orphan*/ __ptr_t;
typedef int __off_t;

/* Variables and functions */
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ MAP_FAILED;
int /*<<< orphan*/ __set_errno(int /*<<< orphan*/);
int /*<<< orphan*/ __syscall_mmap2(int /*<<< orphan*/, size_t, int, int, int,
                                   int /*<<< orphan*/);
__ptr_t mmap(__ptr_t addr, size_t len, int prot, int flags, int fd,
             __off_t offset) {
  if (offset & ((1 << 12) - 1)) {
    __set_errno(EINVAL);
    return MAP_FAILED;
  }
  return (__syscall_mmap2(addr, len, prot, flags, fd, (off_t)(offset >> 12)));
}


x86 assembly (clang, -O0):
<mmap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    %r9d,-0x20(%rbp)
mov    -0x20(%rbp),%eax
and    $0xfff,%eax
cmp    $0x0,%eax
je     116d <mmap+0x4d>
mov    0x2e8b(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
mov    0x2e75(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    118e <mmap+0x6e>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
mov    -0x20(%rbp),%r9d
sar    $0xc,%r9d
call   1040 <__syscall_mmap2@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mmap>:
test   $0xfff,%r9d
je     1143 <mmap+0x23>
push   %rax
mov    0x2eaf(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
mov    0x2e99(%rip),%rax
mov    (%rax),%eax
pop    %rcx
ret
sar    $0xc,%r9d
jmp    1040 <__syscall_mmap2@plt>

LLVM IR (-O0):
@EINVAL = global i32 0
@MAP_FAILED = global i32 0
define i32 @mmap(i32 %0, i64 %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 %0, i32* %8
store i64 %1, i64* %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i32 %5, i32* %13
%14 = load i32, i32* %13
%15 = and i32 %14, 4095
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %6
%18 = load i32, i32* @EINVAL
%19 = call i32 @__set_errno(i32 %18)
%20 = load i32, i32* @MAP_FAILED
store i32 %20, i32* %7
br label %30
21: ; preds = %6
%22 = load i32, i32* %8
%23 = load i64, i64* %9
%24 = load i32, i32* %10
%25 = load i32, i32* %11
%26 = load i32, i32* %12
%27 = load i32, i32* %13
%28 = ashr i32 %27, 12
%29 = call i32 @__syscall_mmap2(i32 %22, i64 %23, i32 %24, i32 %25, i32 %26, i32 %28)
store i32 %29, i32* %7
br label %30
30: ; preds = %21, %17
%31 = load i32, i32* %7
ret i32 %31
}

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