#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*/ logError(char *, char const *, int /*<<< orphan*/);
void *mmap(int /*<<< orphan*/ *, size_t, int, int /*<<< orphan*/, int,
           int /*<<< orphan*/);
int /*<<< orphan*/ 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) {
    logError("bcm2835_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    0x2e6e(%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    0x2e3b(%rip),%rcx
cmp    (%rcx),%rax
jne    11b6 <mapmem+0x86>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
lea    0xe4f(%rip),%rdi
call   1040 <logError@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mapmem>:
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r9d
mov    %edx,%r8d
mov    %rdi,%r14
mov    0x2eb4(%rip),%rax
mov    0x2e7d(%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    0x2e57(%rip),%rax
cmp    (%rax),%rbx
jne    118d <mapmem+0x5d>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe7d(%rip),%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <logError@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str = [34 x i8] c"bcm2835_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 %26
21: ; preds = %4
%22 = load i8*, i8** %5
%23 = load i32, i32* @errno
%24 = call i32 @strerror(i32 %23)
%25 = call i32 @logError(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %22, i32 %24)
br label %26
26: ; preds = %21, %4
%27 = load i8*, i8** %9
ret i8* %27
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str = [34 x i8] c"bcm2835_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 %16
12: ; preds = %4
%13 = load i32, i32* @errno
%14 = tail call i32 @strerror(i32 %13)
%15 = tail call i32 @logError(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %14)
br label %16
16: ; preds = %12, %4
ret i8* %9
}