#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*/ MAP_SHARED;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *);
void *mmap(int /*<<< orphan*/ *, size_t, int, int /*<<< orphan*/, int,
           int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void *mapmem(const char *msg, size_t size, int fd, off_t off) {
  void *map = mmap(NULL, size, (PROT_READ | PROT_WRITE), MAP_SHARED, fd, off);
  if (map == MAP_FAILED)
    fprintf(stderr, "rpi_init: %s mmap failed: %s\n", msg, strerror(errno));
  return map;
}


x86 assembly (clang, -O0):
<mapmem>:
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    -0x10(%rbp),%rsi
mov    0x2ea7(%rip),%rax
mov    (%rax),%edx
mov    0x2e66(%rip),%rax
or     (%rax),%edx
mov    0x2e85(%rip),%rax
mov    (%rax),%ecx
mov    -0x14(%rbp),%r8d
mov    -0x18(%rbp),%r9d
xor    %eax,%eax
mov    %eax,%edi
call   1030 <mmap@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2e33(%rip),%rcx
cmp    (%rcx),%rax
jne    11c6 <mapmem+0x96>
mov    0x2e3b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rdx
mov    %rax,%rcx
lea    0xe3f(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mapmem>:
push   %rbp
push   %r14
push   %rbx
mov    %ecx,%r9d
mov    %edx,%r8d
mov    %rdi,%r14
mov    0x2eb4(%rip),%rax
mov    0x2e75(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e92(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
call   1030 <mmap@plt>
mov    %rax,%rbx
mov    0x2e4f(%rip),%rax
cmp    (%rax),%rbx
jne    1199 <mapmem+0x69>
mov    0x2e5b(%rip),%rax
mov    (%rax),%ebp
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe74(%rip),%rsi
mov    %ebp,%edi
mov    %r14,%rdx
mov    %rax,%rcx
call   1040 <fprintf@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@stderr = global i32 0
@.str = [30 x i8] c"rpi_init: %s mmap failed: %s\0A\00"
@errno = global i32 0
define i8* @mapmem(i8* %0, i64 %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %5
store i64 %1, i64* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = load i64, i64* %6
%11 = load i32, i32* @PROT_READ
%12 = load i32, i32* @PROT_WRITE
%13 = or i32 %11, %12
%14 = load i32, i32* @MAP_SHARED
%15 = load i32, i32* %7
%16 = load i32, i32* %8
%17 = call i8* @mmap(i32* null, i64 %10, i32 %13, i32 %14, i32 %15, i32 %16)
store i8* %17, i8** %9
%18 = load i8*, i8** %9
%19 = load i8*, i8** @MAP_FAILED
%20 = icmp eq i8* %18, %19
br i1 %20, label %21, label %27
21: ; preds = %4
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %5
%24 = load i32, i32* @errno
%25 = call i8* @strerror(i32 %24)
%26 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %23, i8* %25)
br label %27
27: ; preds = %21, %4
%28 = load i8*, i8** %9
ret i8* %28
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@stderr = global i32 0
@.str = [30 x i8] c"rpi_init: %s mmap failed: %s\0A\00"
@errno = global i32 0
define i8* @mapmem(i8* %0, i64 %1, i32 %2, i32 %3) {
%5 = load i32, i32* @PROT_READ
%6 = load i32, i32* @PROT_WRITE
%7 = or i32 %6, %5
%8 = load i32, i32* @MAP_SHARED
%9 = tail call i8* @mmap(i32* null, i64 %1, i32 %7, i32 %8, i32 %2, i32 %3)
%10 = load i8*, i8** @MAP_FAILED
%11 = icmp eq i8* %9, %10
br i1 %11, label %12, label %17
12: ; preds = %4
%13 = load i32, i32* @stderr
%14 = load i32, i32* @errno
%15 = tail call i8* @strerror(i32 %14)
%16 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %15)
br label %17
17: ; preds = %12, %4
ret i8* %9
}