#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*/ get_info(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, void *);
void *sbrk(int /*<<< orphan*/);
int main() {
  void *p;
  int i;
  for (i = 0; i < 100; i++) {
    get_info("heap");
    get_info("stack");
    void *p = sbrk(0);
    printf("current heap top:0x%08p \n", p);
    p = (void *)malloc(0x10 * sizeof(int));
    printf("after malloc heap top:%08p\n", p);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x64,-0x14(%rbp)
jge    11bf <main+0x7f>
lea    0xe99(%rip),%rdi
call   1030 <get_info@plt>
lea    0xe92(%rip),%rdi
call   1030 <get_info@plt>
xor    %edi,%edi
call   1050 <sbrk@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe7d(%rip),%rdi
call   1040 <printf@plt>
mov    $0x40,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe79(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1156 <main+0x16>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0x64,%ebp
lea    0xeac(%rip),%r14
lea    0xeaa(%rip),%r15
lea    0xea9(%rip),%r12
lea    0xebc(%rip),%rbx
nopl   0x0(%rax)
mov    %r14,%rdi
call   1030 <get_info@plt>
mov    %r15,%rdi
call   1030 <get_info@plt>
xor    %edi,%edi
call   1050 <sbrk@plt>
mov    %r12,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    $0x40,%edi
call   1060 <malloc@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
add    $0xffffffff,%ebp
jne    1170 <main+0x30>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"heap\00"
@.str.1 = [6 x i8] c"stack\00"
@.str.2 = [26 x i8] c"current heap top:0x%08p \0A\00"
@.str.3 = [28 x i8] c"after malloc heap top:%08p\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i32 0, i32* %1
store i32 0, i32* %3
br label %5
5: ; preds = %18, %0
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 100
br i1 %7, label %8, label %21
8: ; preds = %5
%9 = call i32 @get_info(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @get_info(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%11 = call i8* @sbrk(i32 0)
store i8* %11, i8** %4
%12 = load i8*, i8** %4
%13 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%14 = call i64 @malloc(i32 64)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %4
%16 = load i8*, i8** %4
%17 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %16)
br label %18
18: ; preds = %8
%19 = load i32, i32* %3
%20 = add nsw i32 %19, 1
store i32 %20, i32* %3
br label %5
21: ; preds = %5
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"heap\00"
@.str.1 = [6 x i8] c"stack\00"
@.str.2 = [26 x i8] c"current heap top:0x%08p \0A\00"
@.str.3 = [28 x i8] c"after malloc heap top:%08p\0A\00"
define i32 @main() {
br label %1
1: ; preds = %0, %1
%2 = phi i32 [ 0, %0 ], [ %10, %1 ]
%3 = tail call i32 @get_info(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @get_info(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i8* @sbrk(i32 0)
%6 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%7 = tail call i64 @malloc(i32 64)
%8 = inttoptr i64 %7 to i8*
%9 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %8)
%10 = add nuw nsw i32 %2, 1
%11 = icmp eq i32 %10, 100
br i1 %11, label %12, label %1
12: ; preds = %1
ret i32 0
}