#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_ANON;
int MAP_PRIVATE;
int PROT_EXEC;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
void *malloc(unsigned long);
void *mmap(int /*<<< orphan*/, unsigned long, int, int, int,
           int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(void) {
  void *p;
  unsigned long size = (~(0UL)) >> 1;
  fprintf(stderr, "Attempting too-big malloc()...\n");
  p = malloc(size);
  if (p)
    fprintf(stderr, "huge malloc() succeeded??\n");
  fprintf(stderr, "Attempting too-big mmap()...\n");
  p = mmap(0, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANON,
           -1, 0);
  if (-1 != (long)p)
    fprintf(stderr, "huge mmap() succeeded??\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movabs $0x7fffffffffffffff,%rax
ff ff 7f
mov    %rax,-0x18(%rbp)
mov    0x2e7c(%rip),%rax
mov    (%rax),%edi
lea    0xea3(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     118f <main+0x5f>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
lea    0xe96(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
lea    0xe9c(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rsi
mov    0x2e49(%rip),%rax
mov    (%rax),%edx
mov    0x2e10(%rip),%rax
or     (%rax),%edx
mov    0x2e1f(%rip),%rax
or     (%rax),%edx
mov    0x2dee(%rip),%rax
mov    (%rax),%ecx
mov    0x2ded(%rip),%rax
or     (%rax),%ecx
xor    %r9d,%r9d
mov    $0xffffffff,%r8d
mov    %r9d,%edi
call   1030 <mmap@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rcx
mov    $0xffffffffffffffff,%rax
cmp    %rcx,%rax
je     1213 <main+0xe3>
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
lea    0xe4b(%rip),%rsi
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2ea8(%rip),%rbx
mov    (%rbx),%edi
lea    0xecf(%rip),%rsi
call   1040 <fprintf@plt>
mov    (%rbx),%edi
lea    0xee1(%rip),%rsi
call   1040 <fprintf@plt>
mov    (%rbx),%edi
lea    0xeee(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e9f(%rip),%rax
mov    0x2e68(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e75(%rip),%rax
or     (%rax),%edx
mov    0x2e44(%rip),%rax
mov    0x2e45(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
movabs $0x7fffffffffffffff,%rsi
ff ff 7f
xor    %edi,%edi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
cmp    $0xffffffffffffffff,%rax
je     11ad <main+0x8d>
mov    (%rbx),%edi
lea    0xeb1(%rip),%rsi
call   1040 <fprintf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [32 x i8] c"Attempting too-big malloc()...\0A\00"
@.str.1 = [27 x i8] c"huge malloc() succeeded??\0A\00"
@.str.2 = [30 x i8] c"Attempting too-big mmap()...\0A\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@PROT_EXEC = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANON = global i32 0
@.str.3 = [25 x i8] c"huge mmap() succeeded??\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i64
store i32 0, i32* %1
store i64 9223372036854775807, i64* %3
%4 = load i32, i32* @stderr
%5 = call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%6 = load i64, i64* %3
%7 = call i8* @malloc(i64 %6)
store i8* %7, i8** %2
%8 = load i8*, i8** %2
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %10, %0
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%16 = load i64, i64* %3
%17 = load i32, i32* @PROT_READ
%18 = load i32, i32* @PROT_WRITE
%19 = or i32 %17, %18
%20 = load i32, i32* @PROT_EXEC
%21 = or i32 %19, %20
%22 = load i32, i32* @MAP_PRIVATE
%23 = load i32, i32* @MAP_ANON
%24 = or i32 %22, %23
%25 = call i8* @mmap(i32 0, i64 %16, i32 %21, i32 %24, i32 -1, i32 0)
store i8* %25, i8** %2
%26 = load i8*, i8** %2
%27 = ptrtoint i8* %26 to i64
%28 = icmp ne i64 -1, %27
br i1 %28, label %29, label %32
29: ; preds = %13
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %32
32: ; preds = %29, %13
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [32 x i8] c"Attempting too-big malloc()...\0A\00"
@.str.1 = [27 x i8] c"huge malloc() succeeded??\0A\00"
@.str.2 = [30 x i8] c"Attempting too-big mmap()...\0A\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@PROT_EXEC = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANON = global i32 0
@.str.3 = [25 x i8] c"huge mmap() succeeded??\0A\00"
define i32 @main() {
%1 = load i32, i32* @stderr
%2 = tail call i32 @fprintf(i32 %1, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%3 = load i32, i32* @stderr
%4 = tail call i32 @fprintf(i32 %3, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%7 = load i32, i32* @PROT_READ
%8 = load i32, i32* @PROT_WRITE
%9 = or i32 %8, %7
%10 = load i32, i32* @PROT_EXEC
%11 = or i32 %9, %10
%12 = load i32, i32* @MAP_PRIVATE
%13 = load i32, i32* @MAP_ANON
%14 = or i32 %13, %12
%15 = tail call i8* @mmap(i32 0, i64 9223372036854775807, i32 %11, i32 %14, i32 -1, i32 0)
%16 = icmp eq i8* %15, inttoptr (i64 -1 to i8*)
br i1 %16, label %20, label %17
17: ; preds = %0
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %20
20: ; preds = %17, %0
ret i32 0
}