#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 /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int MAP_ANONYMOUS;
char *MAP_FAILED;
int MAP_SHARED;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char *mmap(int /*<<< orphan*/ *, size_t, int, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ munmap(char *, size_t);
int /*<<< orphan*/ perror(char *);
size_t strtoull(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  char *chars;
  size_t nbytes;
  if (argc < 2) {
    nbytes = 2;
  } else {
    nbytes = strtoull(argv[1], NULL, 0);
  }
  chars = mmap(NULL, nbytes, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS,
               -1, 0);
  if (chars == MAP_FAILED) {
    perror("mmap");
    exit(EXIT_FAILURE);
  }
  munmap(chars, nbytes);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    117d <main+0x2d>
movq   $0x2,-0x20(%rbp)
jmp    1194 <main+0x44>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1040 <strtoull@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
mov    0x2e59(%rip),%rax
mov    (%rax),%edx
mov    0x2e18(%rip),%rax
or     (%rax),%edx
mov    0x2e37(%rip),%rax
mov    (%rax),%ecx
mov    0x2e1e(%rip),%rax
or     (%rax),%ecx
xor    %eax,%eax
mov    %eax,%edi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2dd3(%rip),%rcx
cmp    (%rcx),%rax
jne    1200 <main+0xb0>
lea    0xe13(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <munmap@plt>
mov    0x2da4(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x2,%ebx
cmp    $0x2,%edi
jl     116b <main+0x1b>
mov    0x8(%rsi),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <strtoull@plt>
mov    %rax,%rbx
mov    0x2e86(%rip),%rax
mov    0x2e47(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e64(%rip),%rax
mov    0x2e4d(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    0x2e07(%rip),%rcx
cmp    (%rcx),%rax
je     11c4 <main+0x74>
mov    %rax,%rdi
mov    %rbx,%rsi
call   1050 <munmap@plt>
mov    0x2df8(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret
lea    0xe35(%rip),%rdi
call   1060 <perror@plt>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_FAILED = global i8* null
@.str = [5 x i8] c"mmap\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %11
10: ; preds = %2
store i64 2, i64* %7
br label %16
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i64 @strtoull(i8* %14, i32* null, i32 0)
store i64 %15, i64* %7
br label %16
16: ; preds = %11, %10
%17 = load i64, i64* %7
%18 = load i32, i32* @PROT_READ
%19 = load i32, i32* @PROT_WRITE
%20 = or i32 %18, %19
%21 = load i32, i32* @MAP_SHARED
%22 = load i32, i32* @MAP_ANONYMOUS
%23 = or i32 %21, %22
%24 = call i8* @mmap(i32* null, i64 %17, i32 %20, i32 %23, i32 -1, i32 0)
store i8* %24, i8** %6
%25 = load i8*, i8** %6
%26 = load i8*, i8** @MAP_FAILED
%27 = icmp eq i8* %25, %26
br i1 %27, label %28, label %32
28: ; preds = %16
%29 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %16
%33 = load i8*, i8** %6
%34 = load i64, i64* %7
%35 = call i32 @munmap(i8* %33, i64 %34)
%36 = load i32, i32* @EXIT_SUCCESS
ret i32 %36
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_FAILED = global i8* null
@.str = [5 x i8] c"mmap\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i64 @strtoull(i8* nocapture %6, i32* null, i32 0)
br label %8
8: ; preds = %2, %4
%9 = phi i64 [ %7, %4 ], [ 2, %2 ]
%10 = load i32, i32* @PROT_READ
%11 = load i32, i32* @PROT_WRITE
%12 = or i32 %11, %10
%13 = load i32, i32* @MAP_SHARED
%14 = load i32, i32* @MAP_ANONYMOUS
%15 = or i32 %14, %13
%16 = tail call i8* @mmap(i32* null, i64 %9, i32 %12, i32 %15, i32 -1, i32 0)
%17 = load i8*, i8** @MAP_FAILED
%18 = icmp eq i8* %16, %17
br i1 %18, label %19, label %23
19: ; preds = %8
%20 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = tail call i32 @exit(i32 %21)
unreachable
23: ; preds = %8
%24 = tail call i32 @munmap(i8* %16, i64 %9)
%25 = load i32, i32* @EXIT_SUCCESS
ret i32 %25
}