#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*/ uint32_t;
typedef int /*<<< orphan*/ int32_t;

/* Variables and functions */
void *MAP_FAILED;
int /*<<< orphan*/ errno;
void *mmap(void *, uintptr_t, int /*<<< orphan*/, int /*<<< orphan*/,
           int /*<<< orphan*/, int /*<<< orphan*/);
uintptr_t x_cgo_mmap(void *addr, uintptr_t length, int32_t prot, int32_t flags,
                     int32_t fd, uint32_t offset) {
  void *p;
  ;
  p = mmap(addr, length, prot, flags, fd, offset);
  ;
  if (p == MAP_FAILED) {
    return (uintptr_t)errno;
  }
  return (uintptr_t)p;
}


x86 assembly (clang, -O0):
<x_cgo_mmap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x24(%rbp),%r8d
mov    -0x28(%rbp),%r9d
call   1030 <mmap@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    0x2e80(%rip),%rcx
cmp    (%rcx),%rax
jne    1174 <x_cgo_mmap+0x64>
mov    0x2e78(%rip),%rax
movslq (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    117c <x_cgo_mmap+0x6c>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<x_cgo_mmap>:
push   %rax
call   1030 <mmap@plt>
mov    0x2ebb(%rip),%rcx
cmp    (%rcx),%rax
mov    0x2eb9(%rip),%rcx
movslq (%rcx),%rcx
cmove  %rcx,%rax
pop    %rcx
ret

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

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