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

/* Variables and functions */
int /*<<< orphan*/ SYS_mmap;
int /*<<< orphan*/ _SC_PAGESIZE;
void *ehnlc_syscall1(int /*<<< orphan*/, void *);
long sysconf(int /*<<< orphan*/);
void *ehnlc_legacy_mmap(void *addr, size_t len, int prot, int flags, int fd,
                        off_t offset) {
  void *params[7];
  long page_size;
  page_size = sysconf(_SC_PAGESIZE);
  if (offset % page_size) {
    offset = page_size * (1 + (offset / page_size));
  }
  if (len % page_size) {
    len = page_size * (1 + (len / page_size));
  }
  params[0] = addr;
  params[1] = (void *)((long)len);
  params[2] = (void *)((long)prot);
  params[3] = (void *)((long)flags);
  params[4] = (void *)((long)fd);
  params[5] = (void *)((long)offset);
  params[6] = NULL;
  return ehnlc_syscall1(SYS_mmap, (void *)params);
}


x86 assembly (clang, -O0):
<ehnlc_legacy_mmap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%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    0x2ea0(%rip),%rax
mov    (%rax),%edi
call   1040 <sysconf@plt>
mov    %rax,-0x68(%rbp)
mov    -0x28(%rbp),%rax
cqto
idivq  -0x68(%rbp)
cmp    $0x0,%rdx
je     118c <ehnlc_legacy_mmap+0x6c>
mov    -0x68(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x28(%rbp),%rax
cqto
idivq  -0x68(%rbp)
mov    %rax,%rcx
mov    -0x70(%rbp),%rax
add    $0x1,%rcx
imul   %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x68(%rbp)
cmp    $0x0,%rdx
je     11c9 <ehnlc_legacy_mmap+0xa9>
mov    -0x68(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x10(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x68(%rbp)
mov    %rax,%rcx
mov    -0x78(%rbp),%rax
add    $0x1,%rcx
imul   %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x58(%rbp)
movslq -0x14(%rbp),%rax
mov    %rax,-0x50(%rbp)
movslq -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
movslq -0x1c(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
movq   $0x0,-0x30(%rbp)
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
lea    -0x60(%rbp),%rsi
call   1030 <ehnlc_syscall1@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ehnlc_legacy_mmap>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9,%rbp
mov    %r8d,%r14d
mov    %ecx,%r15d
mov    %edx,%r12d
mov    %rsi,%rbx
mov    %rdi,%r13
mov    0x2ea1(%rip),%rax
mov    (%rax),%edi
call   1040 <sysconf@plt>
mov    %rax,%rcx
mov    %rbp,%rax
or     %rcx,%rax
shr    $0x20,%rax
je     116a <ehnlc_legacy_mmap+0x4a>
mov    %rbp,%rax
cqto
idiv   %rcx
mov    %rax,%rsi
jmp    1172 <ehnlc_legacy_mmap+0x52>
mov    %ebp,%eax
xor    %edx,%edx
div    %ecx
mov    %eax,%esi
add    $0x1,%rsi
imul   %rcx,%rsi
test   %rdx,%rdx
cmove  %rbp,%rsi
mov    %rbx,%rax
or     %rcx,%rax
shr    $0x20,%rax
je     1197 <ehnlc_legacy_mmap+0x77>
mov    %rbx,%rax
xor    %edx,%edx
div    %rcx
jmp    119d <ehnlc_legacy_mmap+0x7d>
mov    %ebx,%eax
xor    %edx,%edx
div    %ecx
add    $0x1,%rax
imul   %rcx,%rax
test   %rdx,%rdx
cmove  %rbx,%rax
mov    %r13,(%rsp)
mov    %rax,0x8(%rsp)
movslq %r12d,%rax
mov    %rax,0x10(%rsp)
movslq %r15d,%rax
mov    %rax,0x18(%rsp)
movslq %r14d,%rax
mov    %rax,0x20(%rsp)
mov    %rsi,0x28(%rsp)
movq   $0x0,0x30(%rsp)
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   1030 <ehnlc_syscall1@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@_SC_PAGESIZE = global i32 0
@SYS_mmap = global i32 0
define i8* @ehnlc_legacy_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 [7 x 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* @_SC_PAGESIZE
%16 = call i64 @sysconf(i32 %15)
store i64 %16, i64* %14
%17 = load i64, i64* %12
%18 = load i64, i64* %14
%19 = srem i64 %17, %18
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %28
21: ; preds = %6
%22 = load i64, i64* %14
%23 = load i64, i64* %12
%24 = load i64, i64* %14
%25 = sdiv i64 %23, %24
%26 = add nsw i64 1, %25
%27 = mul nsw i64 %22, %26
store i64 %27, i64* %12
br label %28
28: ; preds = %21, %6
%29 = load i64, i64* %8
%30 = load i64, i64* %14
%31 = urem i64 %29, %30
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %40
33: ; preds = %28
%34 = load i64, i64* %14
%35 = load i64, i64* %8
%36 = load i64, i64* %14
%37 = udiv i64 %35, %36
%38 = add i64 1, %37
%39 = mul i64 %34, %38
store i64 %39, i64* %8
br label %40
40: ; preds = %33, %28
%41 = load i8*, i8** %7
%42 = getelementptr inbounds [7 x i8*], [7 x i8*]* %13, i64 0, i64 0
store i8* %41, i8** %42
%43 = load i64, i64* %8
%44 = inttoptr i64 %43 to i8*
%45 = getelementptr inbounds [7 x i8*], [7 x i8*]* %13, i64 0, i64 1
store i8* %44, i8** %45
%46 = load i32, i32* %9
%47 = sext i32 %46 to i64
%48 = inttoptr i64 %47 to i8*
%49 = getelementptr inbounds [7 x i8*], [7 x i8*]* %13, i64 0, i64 2
store i8* %48, i8** %49
%50 = load i32, i32* %10
%51 = sext i32 %50 to i64
%52 = inttoptr i64 %51 to i8*
%53 = getelementptr inbounds [7 x i8*], [7 x i8*]* %13, i64 0, i64 3
store i8* %52, i8** %53
%54 = load i32, i32* %11
%55 = sext i32 %54 to i64
%56 = inttoptr i64 %55 to i8*
%57 = getelementptr inbounds [7 x i8*], [7 x i8*]* %13, i64 0, i64 4
store i8* %56, i8** %57
%58 = load i64, i64* %12
%59 = inttoptr i64 %58 to i8*
%60 = getelementptr inbounds [7 x i8*], [7 x i8*]* %13, i64 0, i64 5
store i8* %59, i8** %60
%61 = getelementptr inbounds [7 x i8*], [7 x i8*]* %13, i64 0, i64 6
store i8* null, i8** %61
%62 = load i32, i32* @SYS_mmap
%63 = getelementptr inbounds [7 x i8*], [7 x i8*]* %13, i64 0, i64 0
%64 = bitcast i8** %63 to i8*
%65 = call i8* @ehnlc_syscall1(i32 %62, i8* %64)
ret i8* %65
}

LLVM IR (-O2):
@_SC_PAGESIZE = global i32 0
@SYS_mmap = global i32 0
define i8* @ehnlc_legacy_mmap(i8* %0, i64 %1, i32 %2, i32 %3, i32 %4, i64 %5) {
%7 = alloca [7 x i8*]
%8 = bitcast [7 x i8*]* %7 to i8*
%9 = load i32, i32* @_SC_PAGESIZE
%10 = tail call i64 @sysconf(i32 %9)
%11 = srem i64 %5, %10
%12 = sdiv i64 %5, %10
%13 = icmp eq i64 %11, 0
%14 = add nsw i64 %12, 1
%15 = mul nsw i64 %14, %10
%16 = select i1 %13, i64 %5, i64 %15
%17 = urem i64 %1, %10
%18 = udiv i64 %1, %10
%19 = icmp eq i64 %17, 0
%20 = add i64 %18, 1
%21 = mul i64 %20, %10
%22 = select i1 %19, i64 %1, i64 %21
%23 = getelementptr inbounds [7 x i8*], [7 x i8*]* %7, i64 0, i64 0
store i8* %0, i8** %23
%24 = inttoptr i64 %22 to i8*
%25 = getelementptr inbounds [7 x i8*], [7 x i8*]* %7, i64 0, i64 1
store i8* %24, i8** %25
%26 = sext i32 %2 to i64
%27 = inttoptr i64 %26 to i8*
%28 = getelementptr inbounds [7 x i8*], [7 x i8*]* %7, i64 0, i64 2
store i8* %27, i8** %28
%29 = sext i32 %3 to i64
%30 = inttoptr i64 %29 to i8*
%31 = getelementptr inbounds [7 x i8*], [7 x i8*]* %7, i64 0, i64 3
store i8* %30, i8** %31
%32 = sext i32 %4 to i64
%33 = inttoptr i64 %32 to i8*
%34 = getelementptr inbounds [7 x i8*], [7 x i8*]* %7, i64 0, i64 4
store i8* %33, i8** %34
%35 = inttoptr i64 %16 to i8*
%36 = getelementptr inbounds [7 x i8*], [7 x i8*]* %7, i64 0, i64 5
store i8* %35, i8** %36
%37 = getelementptr inbounds [7 x i8*], [7 x i8*]* %7, i64 0, i64 6
store i8* null, i8** %37
%38 = load i32, i32* @SYS_mmap
%39 = call i8* @ehnlc_syscall1(i32 %38, i8* %8)
ret i8* %39
}