#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_32BIT;
int MAP_ANONYMOUS;
int MAP_PRIVATE;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char *malloc(int);
char *mmap(int /*<<< orphan*/ *, int, int, int, int, int /*<<< orphan*/);
scalar_t__ sbrk(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int mytest() {
  char *p = malloc(12);
  if (p <= (char *)sbrk(0)) {
    fprintf(stderr, "malloc() still allocate from heap area\n");
    return 0;
  }
  p = mmap(NULL, 12, PROT_READ | PROT_WRITE,
           MAP_32BIT | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
  if (p >= (char *)0x40000000 || p <= (char *)sbrk(0)) {
    fprintf(stderr, "mmap wrapper dose not work\n");
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<mytest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0xc,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
xor    %edi,%edi
call   1040 <sbrk@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
cmp    %rcx,%rax
ja     1196 <mytest+0x56>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
lea    0xe7b(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1234 <mytest+0xf4>
mov    0x2e53(%rip),%rax
mov    (%rax),%edx
mov    0x2e1a(%rip),%rax
or     (%rax),%edx
mov    0x2e49(%rip),%rax
mov    (%rax),%ecx
mov    0x2e00(%rip),%rax
or     (%rax),%ecx
mov    0x2e17(%rip),%rax
or     (%rax),%ecx
xor    %eax,%eax
mov    %eax,%edi
mov    $0xc,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x10(%rbp)
mov    $0x40000000,%eax
cmp    %rax,-0x10(%rbp)
jae    120c <mytest+0xcc>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
xor    %edi,%edi
call   1040 <sbrk@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
ja     122d <mytest+0xed>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
lea    0xe0c(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1234 <mytest+0xf4>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mytest>:
push   %r14
push   %rbx
push   %rax
mov    $0xc,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
xor    %edi,%edi
call   1040 <sbrk@plt>
cmp    %rax,%rbx
jbe    11c7 <mytest+0x87>
mov    0x2e8c(%rip),%rax
mov    0x2e55(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e82(%rip),%rax
mov    0x2e3b(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2e50(%rip),%rax
or     (%rax),%ecx
xor    %edi,%edi
mov    $0xc,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
lea    0xe82(%rip),%rbx
cmp    $0x3fffffff,%rax
ja     11ce <mytest+0x8e>
mov    %rax,%r14
xor    %edi,%edi
call   1040 <sbrk@plt>
mov    %rax,%rcx
mov    $0x1,%eax
cmp    %rcx,%r14
jbe    11ce <mytest+0x8e>
jmp    11e1 <mytest+0xa1>
lea    0xe32(%rip),%rbx
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [40 x i8] c"malloc() still allocate from heap area\0A\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_32BIT = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@.str.1 = [28 x i8] c"mmap wrapper dose not work\0A\00"
define i32 @mytest() {
%1 = alloca i32
%2 = alloca i8*
%3 = call i8* @malloc(i32 12)
store i8* %3, i8** %2
%4 = load i8*, i8** %2
%5 = call i64 @sbrk(i32 0)
%6 = inttoptr i64 %5 to i8*
%7 = icmp ule i8* %4, %6
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %32
11: ; preds = %0
%12 = load i32, i32* @PROT_READ
%13 = load i32, i32* @PROT_WRITE
%14 = or i32 %12, %13
%15 = load i32, i32* @MAP_32BIT
%16 = load i32, i32* @MAP_PRIVATE
%17 = or i32 %15, %16
%18 = load i32, i32* @MAP_ANONYMOUS
%19 = or i32 %17, %18
%20 = call i8* @mmap(i32* null, i32 12, i32 %14, i32 %19, i32 -1, i32 0)
store i8* %20, i8** %2
%21 = load i8*, i8** %2
%22 = icmp uge i8* %21, inttoptr (i64 1073741824 to i8*)
br i1 %22, label %28, label %23
23: ; preds = %11
%24 = load i8*, i8** %2
%25 = call i64 @sbrk(i32 0)
%26 = inttoptr i64 %25 to i8*
%27 = icmp ule i8* %24, %26
br i1 %27, label %28, label %31
28: ; preds = %23, %11
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %32
31: ; preds = %23
store i32 1, i32* %1
br label %32
32: ; preds = %31, %28, %8
%33 = load i32, i32* %1
ret i32 %33
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [40 x i8] c"malloc() still allocate from heap area\0A\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_32BIT = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@.str.1 = [28 x i8] c"mmap wrapper dose not work\0A\00"
define i32 @mytest() {
%1 = tail call dereferenceable_or_null(12) i8* @malloc(i32 12)
%2 = tail call i64 @sbrk(i32 0)
%3 = inttoptr i64 %2 to i8*
%4 = icmp ugt i8* %1, %3
br i1 %4, label %5, label %20
5: ; preds = %0
%6 = load i32, i32* @PROT_READ
%7 = load i32, i32* @PROT_WRITE
%8 = or i32 %7, %6
%9 = load i32, i32* @MAP_32BIT
%10 = load i32, i32* @MAP_PRIVATE
%11 = or i32 %10, %9
%12 = load i32, i32* @MAP_ANONYMOUS
%13 = or i32 %11, %12
%14 = tail call i8* @mmap(i32* null, i32 12, i32 %8, i32 %13, i32 -1, i32 0)
%15 = icmp ult i8* %14, inttoptr (i64 1073741824 to i8*)
br i1 %15, label %16, label %20
16: ; preds = %5
%17 = tail call i64 @sbrk(i32 0)
%18 = inttoptr i64 %17 to i8*
%19 = icmp ugt i8* %14, %18
br i1 %19, label %24, label %20
20: ; preds = %5, %16, %0
%21 = phi i8* [ getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), %0 ], [ getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), %16 ], [ getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), %5 ]
%22 = load i32, i32* @stderr
%23 = tail call i32 @fprintf(i32 %22, i8* %21)
br label %24
24: ; preds = %20, %16
%25 = phi i32 [ 1, %16 ], [ 0, %20 ]
ret i32 %25
}