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

/* Variables and functions */
int /*<<< orphan*/ SYS_mmap;
void *ehnlc_legacy_mmap(void *, size_t, int, int, int, scalar_t__);
void *ehnlc_syscall6(int /*<<< orphan*/, void *, void *, void *, void *, void *,
                     void *);
long errno;
void *ehnlc_mmap(void *addr, size_t len, int prot, int flags, int fd,
                 off_t offset) {
  void *rv;
  long s_rv;
  if (0) {
    rv = ehnlc_legacy_mmap(addr, len, prot, flags, fd, offset);
  } else {
    rv = ehnlc_syscall6(SYS_mmap, addr, (void *)len, (void *)(ssize_t)prot,
                        (void *)(ssize_t)flags, (void *)(ssize_t)fd,
                        (void *)(ssize_t)offset);
  }
  s_rv = (long)((ssize_t)rv);
  if (s_rv < 0 && s_rv >= -4096) {
    errno = -s_rv;
  }
  return (s_rv < 0 && s_rv >= -4096) ? NULL : rv;
}


x86 assembly (clang, -O0):
<ehnlc_mmap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%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    0x2eab(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
movslq -0x14(%rbp),%rcx
movslq -0x18(%rbp),%r8
movslq -0x1c(%rbp),%r9
mov    -0x28(%rbp),%rax
mov    %rax,(%rsp)
call   1030 <ehnlc_syscall6@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jge    118f <ehnlc_mmap+0x7f>
cmpq   $0xfffffffffffff000,-0x38(%rbp)
ff
jl     118f <ehnlc_mmap+0x7f>
xor    %eax,%eax
mov    %eax,%ecx
sub    -0x38(%rbp),%rcx
mov    0x2e4c(%rip),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x38(%rbp)
jge    11b3 <ehnlc_mmap+0xa3>
cmpq   $0xfffffffffffff000,-0x38(%rbp)
ff
jl     11b3 <ehnlc_mmap+0xa3>
xor    %eax,%eax
mov    %rax,-0x40(%rbp)
jmp    11bb <ehnlc_mmap+0xab>
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ehnlc_mmap>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r10
mov    %rdi,%rsi
mov    0x2ebe(%rip),%rax
mov    (%rax),%edi
movslq %edx,%rax
movslq %ecx,%r11
movslq %r8d,%rbx
mov    %r9,(%rsp)
mov    %r10,%rdx
mov    %rax,%rcx
mov    %r11,%r8
mov    %rbx,%r9
call   1030 <ehnlc_syscall6@plt>
test   %rax,%rax
jns    115e <ehnlc_mmap+0x4e>
cmp    $0xfffffffffffff000,%rax
jl     115e <ehnlc_mmap+0x4e>
neg    %rax
mov    0x2e7f(%rip),%rcx
mov    %rax,(%rcx)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@SYS_mmap = global i32 0
@errno = global i64 0
define i8* @ehnlc_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*
%14 = alloca i64
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
%15 = load i32, i32* @SYS_mmap
%16 = load i8*, i8** %7
%17 = load i64, i64* %8
%18 = inttoptr i64 %17 to i8*
%19 = load i32, i32* %9
%20 = sext i32 %19 to i64
%21 = inttoptr i64 %20 to i8*
%22 = load i32, i32* %10
%23 = sext i32 %22 to i64
%24 = inttoptr i64 %23 to i8*
%25 = load i32, i32* %11
%26 = sext i32 %25 to i64
%27 = inttoptr i64 %26 to i8*
%28 = load i64, i64* %12
%29 = inttoptr i64 %28 to i8*
%30 = call i8* @ehnlc_syscall6(i32 %15, i8* %16, i8* %18, i8* %21, i8* %24, i8* %27, i8* %29)
store i8* %30, i8** %13
%31 = load i8*, i8** %13
%32 = ptrtoint i8* %31 to i64
store i64 %32, i64* %14
%33 = load i64, i64* %14
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %41
35: ; preds = %6
%36 = load i64, i64* %14
%37 = icmp sge i64 %36, -4096
br i1 %37, label %38, label %41
38: ; preds = %35
%39 = load i64, i64* %14
%40 = sub nsw i64 0, %39
store i64 %40, i64* @errno
br label %41
41: ; preds = %38, %35, %6
%42 = load i64, i64* %14
%43 = icmp slt i64 %42, 0
br i1 %43, label %44, label %48
44: ; preds = %41
%45 = load i64, i64* %14
%46 = icmp sge i64 %45, -4096
br i1 %46, label %47, label %48
47: ; preds = %44
br label %50
48: ; preds = %44, %41
%49 = load i8*, i8** %13
br label %50
50: ; preds = %48, %47
%51 = phi i8* [ null, %47 ], [ %49, %48 ]
ret i8* %51
}

LLVM IR (-O2):
@SYS_mmap = global i32 0
@errno = global i64 0
define i8* @ehnlc_mmap(i8* %0, i64 %1, i32 %2, i32 %3, i32 %4, i64 %5) {
%7 = load i32, i32* @SYS_mmap
%8 = inttoptr i64 %1 to i8*
%9 = sext i32 %2 to i64
%10 = inttoptr i64 %9 to i8*
%11 = sext i32 %3 to i64
%12 = inttoptr i64 %11 to i8*
%13 = sext i32 %4 to i64
%14 = inttoptr i64 %13 to i8*
%15 = inttoptr i64 %5 to i8*
%16 = tail call i8* @ehnlc_syscall6(i32 %7, i8* %0, i8* %8, i8* %10, i8* %12, i8* %14, i8* %15)
%17 = icmp slt i8* %16, null
%18 = icmp sgt i8* %16, inttoptr (i64 -4097 to i8*)
%19 = and i1 %17, %18
br i1 %19, label %20, label %23
20: ; preds = %6
%21 = ptrtoint i8* %16 to i64
%22 = sub nsw i64 0, %21
store i64 %22, i64* @errno
br label %23
23: ; preds = %20, %6
%24 = phi i8* [ null, %20 ], [ %16, %6 ]
ret i8* %24
}