#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 */
int MAP_ANONYMOUS;
size_t *MAP_FAILED;
int MAP_PRIVATE;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ errno;
size_t *mmap(int /*<<< orphan*/ *, int, int, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, size_t *);
char *strerror(int /*<<< orphan*/);
int main() {
  size_t *m;
  m = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1,
           0);
  if (m == MAP_FAILED)
    printf("mmap failed: %s\n", strerror(errno));
  else
    printf("mmap succeeded: %p\n", m);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2eb2(%rip),%rax
mov    (%rax),%edx
mov    0x2e79(%rip),%rax
or     (%rax),%edx
mov    0x2e68(%rip),%rax
mov    (%rax),%ecx
mov    0x2e7f(%rip),%rax
or     (%rax),%ecx
xor    %eax,%eax
mov    %eax,%edi
mov    $0x1000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2e2f(%rip),%rcx
cmp    (%rcx),%rax
jne    11b4 <main+0x84>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %rax,%rsi
lea    0xe56(%rip),%rdi
call   1040 <printf@plt>
jmp    11c4 <main+0x94>
mov    -0x10(%rbp),%rsi
lea    0xe52(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    0x2ec0(%rip),%rax
mov    0x2e89(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e76(%rip),%rax
mov    0x2e8f(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
xor    %edi,%edi
mov    $0x1000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    0x2e47(%rip),%rcx
cmp    (%rcx),%rax
je     117f <main+0x4f>
lea    0xe94(%rip),%rdi
jmp    1194 <main+0x64>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe6c(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_FAILED = global i64* null
@.str = [17 x i8] c"mmap failed: %s\0A\00"
@errno = global i32 0
@.str.1 = [20 x i8] c"mmap succeeded: %p\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64*
store i32 0, i32* %1
%3 = load i32, i32* @PROT_READ
%4 = load i32, i32* @PROT_WRITE
%5 = or i32 %3, %4
%6 = load i32, i32* @MAP_PRIVATE
%7 = load i32, i32* @MAP_ANONYMOUS
%8 = or i32 %6, %7
%9 = call i64* @mmap(i32* null, i32 4096, i32 %5, i32 %8, i32 -1, i32 0)
store i64* %9, i64** %2
%10 = load i64*, i64** %2
%11 = load i64*, i64** @MAP_FAILED
%12 = icmp eq i64* %10, %11
br i1 %12, label %13, label %18
13: ; preds = %0
%14 = load i32, i32* @errno
%15 = call i8* @strerror(i32 %14)
%16 = bitcast i8* %15 to i64*
%17 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i64* %16)
br label %21
18: ; preds = %0
%19 = load i64*, i64** %2
%20 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i64* %19)
br label %21
21: ; preds = %18, %13
ret i32 0
}

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