#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_PRIVATE;
int /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ abort();
void *mmap(int /*<<< orphan*/ *, int, int /*<<< orphan*/, int /*<<< orphan*/,
           int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
void *mfd_assert_mmap_private(int fd) {
  void *p;
  p = mmap(NULL, 8192, PROT_READ, MAP_PRIVATE, fd, 0);
  if (p == MAP_FAILED) {
    printf("mmap() failed: %m\n");
    abort();
  }
  return p;
}


x86 assembly (clang, -O0):
<mfd_assert_mmap_private>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2eb6(%rip),%rax
mov    (%rax),%edx
mov    0x2e8d(%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    0x2e5f(%rip),%rcx
cmp    (%rcx),%rax
jne    118d <mfd_assert_mmap_private+0x5d>
lea    0xe7f(%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_private>:
push   %rax
mov    %edi,%r8d
mov    0x2ebd(%rip),%rax
mov    (%rax),%edx
mov    0x2e94(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    $0x2000,%esi
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    0x2e74(%rip),%rcx
cmp    (%rcx),%rax
je     1163 <mfd_assert_mmap_private+0x33>
pop    %rcx
ret
lea    0xe96(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

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

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