#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*/ STDIN_FILENO;
int /*<<< orphan*/ _SC_PAGESIZE;
void *mmap(int /*<<< orphan*/ *, size_t const, int /*<<< orphan*/,
           int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, void *);
size_t sysconf(int /*<<< orphan*/);
int main(void) {
  const size_t pagesize = sysconf(_SC_PAGESIZE);
  void *ptr = mmap(NULL, pagesize, PROT_READ, MAP_PRIVATE, STDIN_FILENO, 0);
  if (ptr == MAP_FAILED) {
    perror("mmap");
    return 0;
  }
  printf("mmap succeeded (%p) on stdin!\n", ptr);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e8a(%rip),%rax
mov    (%rax),%edi
call   1060 <sysconf@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
mov    0x2e8c(%rip),%rax
mov    (%rax),%edx
mov    0x2e5b(%rip),%rax
mov    (%rax),%ecx
mov    0x2e42(%rip),%rax
mov    (%rax),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2e2c(%rip),%rcx
cmp    (%rcx),%rax
jne    11bd <main+0x7d>
lea    0xe54(%rip),%rdi
call   1050 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    11d4 <main+0x94>
mov    -0x18(%rbp),%rsi
lea    0xe3d(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e98(%rip),%rax
mov    (%rax),%edi
call   1060 <sysconf@plt>
mov    0x2ea2(%rip),%rcx
mov    (%rcx),%edx
mov    0x2e71(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2e58(%rip),%rsi
mov    (%rsi),%r8d
xor    %ebx,%ebx
xor    %edi,%edi
mov    %rax,%rsi
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    0x2e47(%rip),%rcx
cmp    (%rcx),%rax
je     119e <main+0x5e>
lea    0xe78(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
pop    %rbx
ret
lea    0xe5b(%rip),%rdi
call   1050 <perror@plt>
jmp    119a <main+0x5a>

LLVM IR (-O0):
@_SC_PAGESIZE = global i32 0
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@STDIN_FILENO = global i32 0
@MAP_FAILED = global i8* null
@.str = [5 x i8] c"mmap\00"
@.str.1 = [31 x i8] c"mmap succeeded (%p) on stdin!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i8*
store i32 0, i32* %1
%4 = load i32, i32* @_SC_PAGESIZE
%5 = call i64 @sysconf(i32 %4)
store i64 %5, i64* %2
%6 = load i64, i64* %2
%7 = load i32, i32* @PROT_READ
%8 = load i32, i32* @MAP_PRIVATE
%9 = load i32, i32* @STDIN_FILENO
%10 = call i8* @mmap(i32* null, i64 %6, i32 %7, i32 %8, i32 %9, i32 0)
store i8* %10, i8** %3
%11 = load i8*, i8** %3
%12 = load i8*, i8** @MAP_FAILED
%13 = icmp eq i8* %11, %12
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %19
16: ; preds = %0
%17 = load i8*, i8** %3
%18 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %17)
store i32 1, i32* %1
br label %19
19: ; preds = %16, %14
%20 = load i32, i32* %1
ret i32 %20
}

LLVM IR (-O2):
@_SC_PAGESIZE = global i32 0
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@STDIN_FILENO = global i32 0
@MAP_FAILED = global i8* null
@.str = [5 x i8] c"mmap\00"
@.str.1 = [31 x i8] c"mmap succeeded (%p) on stdin!\0A\00"
define i32 @main() {
%1 = load i32, i32* @_SC_PAGESIZE
%2 = tail call i64 @sysconf(i32 %1)
%3 = load i32, i32* @PROT_READ
%4 = load i32, i32* @MAP_PRIVATE
%5 = load i32, i32* @STDIN_FILENO
%6 = tail call i8* @mmap(i32* null, i64 %2, i32 %3, i32 %4, i32 %5, i32 0)
%7 = load i8*, i8** @MAP_FAILED
%8 = icmp eq i8* %6, %7
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %13
11: ; preds = %0
%12 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %6)
br label %13
13: ; preds = %11, %9
%14 = phi i32 [ 0, %9 ], [ 1, %11 ]
ret i32 %14
}