#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 */

/* Variables and functions */
void *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ abort();
void *mmap(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/, int,
           int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
void *mfd_assert_mmap_shared(int fd) {
  void *p;
  p = mmap(NULL, 8192, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
  if (p == MAP_FAILED) {
    printf("mmap() failed: %m\n");
    abort();
  }
  return p;
}


x86 assembly (clang, -O0):
<mfd_assert_mmap_shared>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2eb6(%rip),%rax
mov    (%rax),%edx
mov    0x2e85(%rip),%rax
or     (%rax),%edx
mov    0x2e94(%rip),%rax
mov    (%rax),%ecx
mov    -0x4(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0x2000,%esi
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2e4e(%rip),%rcx
cmp    (%rcx),%rax
jne    1196 <mfd_assert_mmap_shared+0x66>
lea    0xe76(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mfd_assert_mmap_shared>:
push   %rax
mov    %edi,%r8d
mov    0x2ebd(%rip),%rax
mov    0x2e8e(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e9b(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    $0x2000,%esi
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    0x2e63(%rip),%rcx
cmp    (%rcx),%rax
je     116c <mfd_assert_mmap_shared+0x3c>
pop    %rcx
ret
lea    0xe8d(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str = [19 x i8] c"mmap() failed: %m\0A\00"
define i8* @mfd_assert_mmap_shared(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
store i32 %0, i32* %2
%4 = load i32, i32* @PROT_READ
%5 = load i32, i32* @PROT_WRITE
%6 = or i32 %4, %5
%7 = load i32, i32* @MAP_SHARED
%8 = load i32, i32* %2
%9 = call i8* @mmap(i32* null, i32 8192, i32 %6, i32 %7, i32 %8, i32 0)
store i8* %9, i8** %3
%10 = load i8*, i8** %3
%11 = load i8*, i8** @MAP_FAILED
%12 = icmp eq i8* %10, %11
br i1 %12, label %13, label %16
13: ; preds = %1
%14 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%15 = call i32 (...) @abort()
unreachable
16: ; preds = %1
%17 = load i8*, i8** %3
ret i8* %17
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str = [19 x i8] c"mmap() failed: %m\0A\00"
define i8* @mfd_assert_mmap_shared(i32 %0) {
%2 = load i32, i32* @PROT_READ
%3 = load i32, i32* @PROT_WRITE
%4 = or i32 %3, %2
%5 = load i32, i32* @MAP_SHARED
%6 = tail call i8* @mmap(i32* null, i32 8192, i32 %4, i32 %5, i32 %0, i32 0)
%7 = load i8*, i8** @MAP_FAILED
%8 = icmp eq i8* %6, %7
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 (...) @abort()
unreachable
12: ; preds = %1
ret i8* %6
}