#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 */
int errno;
void *mmap(void *, size_t, int, int, int, int /*<<< orphan*/);
void *__sulong_posix_mmap(void *addr, size_t length, int prot, int flags,
                          int fd, off_t offset) {
  {
    int native_errno = errno;
    void *result = mmap(addr, length, prot, flags, fd, offset);
    if (result == (void *)-1) {
      result = (void *)(long)-errno;
    }
    errno = native_errno;
    return result;
  };
}


x86 assembly (clang, -O0):
<__sulong_posix_mmap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    %r9d,-0x20(%rbp)
mov    0x2eab(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
mov    -0x20(%rbp),%r9d
call   1030 <mmap@plt>
mov    %rax,-0x30(%rbp)
mov    $0xffffffffffffffff,%rax
cmp    %rax,-0x30(%rbp)
jne    117b <__sulong_posix_mmap+0x6b>
xor    %eax,%eax
mov    0x2e6d(%rip),%rcx
sub    (%rcx),%eax
cltq
mov    %rax,-0x30(%rbp)
mov    -0x24(%rbp),%ecx
mov    0x2e5b(%rip),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__sulong_posix_mmap>:
push   %rbp
push   %rbx
push   %rax
mov    0x2ec6(%rip),%rbx
mov    (%rbx),%ebp
call   1030 <mmap@plt>
movslq (%rbx),%rcx
neg    %rcx
cmp    $0xffffffffffffffff,%rax
cmove  %rcx,%rax
mov    %ebp,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
define i8* @__sulong_posix_mmap(i8* %0, i64 %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
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 i32 %5, i32* %12
%15 = load i32, i32* @errno
store i32 %15, i32* %13
%16 = load i8*, i8** %7
%17 = load i64, i64* %8
%18 = load i32, i32* %9
%19 = load i32, i32* %10
%20 = load i32, i32* %11
%21 = load i32, i32* %12
%22 = call i8* @mmap(i8* %16, i64 %17, i32 %18, i32 %19, i32 %20, i32 %21)
store i8* %22, i8** %14
%23 = load i8*, i8** %14
%24 = icmp eq i8* %23, inttoptr (i64 -1 to i8*)
br i1 %24, label %25, label %30
25: ; preds = %6
%26 = load i32, i32* @errno
%27 = sub nsw i32 0, %26
%28 = sext i32 %27 to i64
%29 = inttoptr i64 %28 to i8*
store i8* %29, i8** %14
br label %30
30: ; preds = %25, %6
%31 = load i32, i32* %13
store i32 %31, i32* @errno
%32 = load i8*, i8** %14
ret i8* %32
}

LLVM IR (-O2):
@errno = global i32 0
define i8* @__sulong_posix_mmap(i8* %0, i64 %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = load i32, i32* @errno
%8 = tail call i8* @mmap(i8* %0, i64 %1, i32 %2, i32 %3, i32 %4, i32 %5)
%9 = icmp eq i8* %8, inttoptr (i64 -1 to i8*)
%10 = load i32, i32* @errno
%11 = sub nsw i32 0, %10
%12 = sext i32 %11 to i64
%13 = inttoptr i64 %12 to i8*
%14 = select i1 %9, i8* %13, i8* %8
store i32 %7, i32* @errno
ret i8* %14
}