#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;

/* Variables and functions */
void *MAP_FAILED;
int /*<<< orphan*/ SYS_mmap;
intptr_t syscall6(int /*<<< orphan*/, uintptr_t, size_t, int, int, int,
                  int /*<<< orphan*/);
void *sys_mmap(void *addr, size_t length, int prot, int flags, int fd,
               off_t offset) {
  intptr_t ret =
      syscall6(SYS_mmap, (uintptr_t)addr, length, prot, flags, fd, offset);
  if (ret < 0 && ret > -4096)
    return MAP_FAILED;
  return (void *)ret;
}


x86 assembly (clang, -O0):
<sys_mmap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
mov    0x2eab(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
mov    -0x24(%rbp),%r9d
mov    -0x28(%rbp),%eax
mov    %eax,(%rsp)
call   1030 <syscall6@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jge    1185 <sys_mmap+0x75>
cmpq   $0xfffffffffffff000,-0x30(%rbp)
ff
jle    1185 <sys_mmap+0x75>
mov    0x2e5f(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    118d <sys_mmap+0x7d>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sys_mmap>:
push   %rax
mov    %r8d,%eax
mov    %ecx,%r8d
mov    %edx,%ecx
mov    %rsi,%rdx
mov    %rdi,%rsi
mov    0x2eba(%rip),%rdi
mov    (%rdi),%edi
mov    %r9d,(%rsp)
mov    %eax,%r9d
call   1030 <syscall6@plt>
cmp    $0xfffffffffffff001,%rax
jb     1146 <sys_mmap+0x36>
mov    0x2e95(%rip),%rax
mov    (%rax),%rax
pop    %rcx
ret

LLVM IR (-O0):
@SYS_mmap = global i32 0
@MAP_FAILED = global i8* null
define i8* @sys_mmap(i8* %0, i64 %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = 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 i32 %5, i32* %13
%15 = load i32, i32* @SYS_mmap
%16 = load i8*, i8** %8
%17 = ptrtoint i8* %16 to i64
%18 = load i64, i64* %9
%19 = load i32, i32* %10
%20 = load i32, i32* %11
%21 = load i32, i32* %12
%22 = load i32, i32* %13
%23 = call i64 @syscall6(i32 %15, i64 %17, i64 %18, i32 %19, i32 %20, i32 %21, i32 %22)
store i64 %23, i64* %14
%24 = load i64, i64* %14
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %6
%27 = load i64, i64* %14
%28 = icmp sgt i64 %27, -4096
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = load i8*, i8** @MAP_FAILED
store i8* %30, i8** %7
br label %34
31: ; preds = %26, %6
%32 = load i64, i64* %14
%33 = inttoptr i64 %32 to i8*
store i8* %33, i8** %7
br label %34
34: ; preds = %31, %29
%35 = load i8*, i8** %7
ret i8* %35
}

LLVM IR (-O2):
@SYS_mmap = global i32 0
@MAP_FAILED = global i8* null
define i8* @sys_mmap(i8* %0, i64 %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = load i32, i32* @SYS_mmap
%8 = ptrtoint i8* %0 to i64
%9 = tail call i64 @syscall6(i32 %7, i64 %8, i64 %1, i32 %2, i32 %3, i32 %4, i32 %5)
%10 = icmp ugt i64 %9, -4096
%11 = load i8*, i8** @MAP_FAILED
%12 = inttoptr i64 %9 to i8*
%13 = select i1 %10, i8* %11, i8* %12
ret i8* %13
}