#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;
void *MAP_FAILED;
int MAP_PRIVATE;
int PROT_READ;
int PROT_WRITE;
void *mmap(int /*<<< orphan*/, int, int, int, int /*<<< orphan*/,
           int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
void *create_stack() {
  void *newsp;
  if ((newsp = mmap(0, 0xffff, PROT_READ | PROT_WRITE,
                    MAP_PRIVATE | MAP_ANONYMOUS, 0, 0)) == MAP_FAILED) {
    perror("mmap()");
    return MAP_FAILED;
  }
  return newsp;
}


x86 assembly (clang, -O0):
<create_stack>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2ec9(%rip),%rax
mov    (%rax),%edx
mov    0x2e98(%rip),%rax
or     (%rax),%edx
mov    0x2e87(%rip),%rax
mov    (%rax),%ecx
mov    0x2e96(%rip),%rax
or     (%rax),%ecx
xor    %r9d,%r9d
mov    $0xffff,%esi
mov    %r9d,%edi
mov    %r9d,%r8d
call   1030 <mmap@plt>
mov    %rax,-0x10(%rbp)
mov    0x2e56(%rip),%rcx
cmp    (%rcx),%rax
jne    1192 <create_stack+0x72>
lea    0xe86(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e3a(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    119a <create_stack+0x7a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_stack>:
push   %rbx
mov    0x2ed0(%rip),%rax
mov    0x2ea1(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e8e(%rip),%rax
mov    0x2e9f(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
xor    %edi,%edi
mov    $0xffff,%esi
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    0x2e62(%rip),%rbx
cmp    (%rbx),%rax
je     1165 <create_stack+0x45>
pop    %rbx
ret
lea    0xe94(%rip),%rdi
call   1040 <perror@plt>
mov    (%rbx),%rax
pop    %rbx
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 i8* null
@.str = [7 x i8] c"mmap()\00"
define i8* @create_stack() {
%1 = alloca i8*
%2 = alloca i8*
%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 i8* @mmap(i32 0, i32 65535, i32 %5, i32 %8, i32 0, i32 0)
store i8* %9, i8** %2
%10 = load i8*, i8** @MAP_FAILED
%11 = icmp eq i8* %9, %10
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%14 = load i8*, i8** @MAP_FAILED
store i8* %14, i8** %1
br label %17
15: ; preds = %0
%16 = load i8*, i8** %2
store i8* %16, i8** %1
br label %17
17: ; preds = %15, %12
%18 = load i8*, i8** %1
ret i8* %18
}

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 i8* null
@.str = [7 x i8] c"mmap()\00"
define i8* @create_stack() {
%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 i8* @mmap(i32 0, i32 65535, i32 %3, i32 %6, i32 0, i32 0)
%8 = load i8*, i8** @MAP_FAILED
%9 = icmp eq i8* %7, %8
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%12 = load i8*, i8** @MAP_FAILED
br label %13
13: ; preds = %0, %10
%14 = phi i8* [ %12, %10 ], [ %7, %0 ]
ret i8* %14
}