#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*/ _SC_PAGESIZE;
void *endHeap();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, ...);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ stderr;
size_t sysconf(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int i, j;
  float worst;
  char *a[128], *b[100];
  size_t pagesize;
  void *lowbreak, *highbreak, *maxbreak = 0;
  char *progname;
  if (argc > 0)
    progname = argv[0];
  else
    progname = "";
  pagesize = sysconf(_SC_PAGESIZE);
  fprintf(stderr, "%s, line %d: %s", progname, 34, "Testing memory utility\n");
  lowbreak = endHeap();
  fprintf(stderr, "%s, line %d: %s", progname, 42,
          "Getting small pieces of memory\n");
  for (i = 0; i < 100; i++) {
    for (j = 0; j < 128; j++) {
      a[j] = malloc(64);
    }
    highbreak = endHeap();
    maxbreak = ((maxbreak > highbreak) ? (maxbreak) : (highbreak));
    for (j = 0; j < 128; j++) {
      free(a[j]);
    }
    if (i % 10 == 0)
      fprintf(stderr, "%s: Using total of 0x%x of memory\n", progname,
              (unsigned)(highbreak - lowbreak));
  }
  worst = (maxbreak - lowbreak) / (64 * 128 * 1.0);
  fprintf(stderr, "%s: Using %2.2f times worst case calculation\n", progname,
          worst);
  if (worst > 2) {
    fprintf(stderr, "%s, line %d: %s", progname, 66,
            "* ERROR: Test indicates excessive memory usage\n");
  } else {
    fprintf(stderr, "%s, line %d: %s", progname, 68,
            "Small memory handled OK\n");
  }
  fprintf(stderr, "%s, line %d: %s", progname, 71,
          "Getting big blocks of memory\n");
  for (i = 0; i < 10; i++) {
    for (j = 0; j < 100; j++) {
      b[j] = malloc(10 * pagesize);
    }
    highbreak = endHeap();
    maxbreak = ((maxbreak > highbreak) ? (maxbreak) : (highbreak));
    for (j = 0; j < 100; j++) {
      free(b[j]);
    }
    fprintf(stderr, "%s: Using total of 0x%x of memory\n", progname,
            (unsigned)(highbreak - lowbreak));
  }
  fprintf(stderr, "%s, line %d: %s", progname, 90,
          "Allocations versus worst case memory usage:\n");
  worst = (maxbreak - lowbreak) / (100 * pagesize * 10 * 1.0);
  fprintf(stderr, "%s: Using %2.2f times worst case calculation\n", progname,
          worst);
  if (worst > 2) {
    fprintf(stderr, "%s, line %d: %s", progname, 96,
            "* ERROR: Test indicates excessive memory usage\n");
  } else {
    fprintf(stderr, "%s, line %d: %s", progname, 98, "Big memory handled OK\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x780,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x760(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    1191 <main+0x41>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x768(%rbp)
jmp    119f <main+0x4f>
lea    0xfd4(%rip),%rax
mov    %rax,-0x768(%rbp)
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
call   1070 <sysconf@plt>
mov    %rax,-0x748(%rbp)
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
mov    -0x768(%rbp),%rdx
lea    0xe75(%rip),%rsi
mov    $0x22,%ecx
lea    0xe79(%rip),%r8
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x0,%al
call   1040 <endHeap@plt>
mov    %rax,-0x750(%rbp)
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
mov    -0x768(%rbp),%rdx
lea    0xe3d(%rip),%rsi
mov    $0x2a,%ecx
lea    0xe59(%rip),%r8
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x64,-0x14(%rbp)
jge    133e <main+0x1ee>
movl   $0x0,-0x18(%rbp)
cmpl   $0x80,-0x18(%rbp)
jge    1262 <main+0x112>
mov    $0x40,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
movslq -0x18(%rbp),%rax
mov    %rcx,-0x420(%rbp,%rax,8)
ff
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    122e <main+0xde>
mov    $0x0,%al
call   1040 <endHeap@plt>
mov    %rax,-0x758(%rbp)
mov    -0x760(%rbp),%rax
cmp    -0x758(%rbp),%rax
jbe    1297 <main+0x147>
mov    -0x760(%rbp),%rax
mov    %rax,-0x770(%rbp)
jmp    12a5 <main+0x155>
mov    -0x758(%rbp),%rax
mov    %rax,-0x770(%rbp)
mov    -0x770(%rbp),%rax
mov    %rax,-0x760(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x80,-0x18(%rbp)
jge    12e6 <main+0x196>
movslq -0x18(%rbp),%rax
mov    -0x420(%rbp,%rax,8),%rdi
ff
call   1030 <free@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    12ba <main+0x16a>
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    132b <main+0x1db>
mov    0x2cd7(%rip),%rax
mov    (%rax),%edi
mov    -0x768(%rbp),%rdx
mov    -0x758(%rbp),%rax
mov    -0x750(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%ecx
lea    0xd64(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1330 <main+0x1e0>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    121d <main+0xcd>
mov    -0x760(%rbp),%rax
mov    -0x750(%rbp),%rcx
sub    %rcx,%rax
cvtsi2sd %rax,%xmm0
movsd  0xcac(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
mov    0x2c68(%rip),%rax
mov    (%rax),%edi
mov    -0x768(%rbp),%rdx
cvttss2si -0x1c(%rbp),%ecx
lea    0xd26(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movss  -0x1c(%rbp),%xmm0
movss  0xc67(%rip),%xmm1
ucomiss %xmm1,%xmm0
jbe    13d1 <main+0x281>
mov    0x2c2f(%rip),%rax
mov    (%rax),%edi
mov    -0x768(%rbp),%rdx
lea    0xc87(%rip),%rsi
mov    $0x42,%ecx
lea    0xd14(%rip),%r8
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    13fb <main+0x2ab>
mov    0x2c00(%rip),%rax
mov    (%rax),%edi
mov    -0x768(%rbp),%rdx
lea    0xc58(%rip),%rsi
mov    $0x44,%ecx
lea    0xd15(%rip),%r8
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2bd6(%rip),%rax
mov    (%rax),%edi
mov    -0x768(%rbp),%rdx
lea    0xc2e(%rip),%rsi
mov    $0x47,%ecx
lea    0xd04(%rip),%r8
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    1533 <main+0x3e3>
movl   $0x0,-0x18(%rbp)
cmpl   $0x64,-0x18(%rbp)
jge    1473 <main+0x323>
imul   $0xa,-0x748(%rbp),%rax
0a
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
movslq -0x18(%rbp),%rax
mov    %rcx,-0x740(%rbp,%rax,8)
ff
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    143d <main+0x2ed>
mov    $0x0,%al
call   1040 <endHeap@plt>
mov    %rax,-0x758(%rbp)
mov    -0x760(%rbp),%rax
cmp    -0x758(%rbp),%rax
jbe    14a8 <main+0x358>
mov    -0x760(%rbp),%rax
mov    %rax,-0x778(%rbp)
jmp    14b6 <main+0x366>
mov    -0x758(%rbp),%rax
mov    %rax,-0x778(%rbp)
mov    -0x778(%rbp),%rax
mov    %rax,-0x760(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x64,-0x18(%rbp)
jge    14f4 <main+0x3a4>
movslq -0x18(%rbp),%rax
mov    -0x740(%rbp,%rax,8),%rdi
ff
call   1030 <free@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    14cb <main+0x37b>
mov    0x2add(%rip),%rax
mov    (%rax),%edi
mov    -0x768(%rbp),%rdx
mov    -0x758(%rbp),%rax
mov    -0x750(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%ecx
lea    0xb6a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    142c <main+0x2dc>
mov    0x2a9e(%rip),%rax
mov    (%rax),%edi
mov    -0x768(%rbp),%rdx
lea    0xaf6(%rip),%rsi
lea    0xbef(%rip),%r8
xor    %eax,%eax
mov    $0x5a,%ecx
call   1050 <fprintf@plt>
mov    -0x760(%rbp),%rax
mov    -0x750(%rbp),%rcx
sub    %rcx,%rax
cvtsi2sd %rax,%xmm0
mov    -0x748(%rbp),%rax
imul   $0x3e8,%rax,%rax
movq   %rax,%xmm1
movaps 0xa93(%rip),%xmm2
punpckldq %xmm2,%xmm1
movapd 0xa97(%rip),%xmm2
subpd  %xmm2,%xmm1
movaps %xmm1,%xmm2
unpckhpd %xmm1,%xmm1
addsd  %xmm2,%xmm1
movsd  0xa60(%rip),%xmm2
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
mov    0x2a10(%rip),%rax
mov    (%rax),%edi
mov    -0x768(%rbp),%rdx
cvttss2si -0x1c(%rbp),%ecx
lea    0xace(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movss  -0x1c(%rbp),%xmm0
movss  0xa0f(%rip),%xmm1
ucomiss %xmm1,%xmm0
jbe    1629 <main+0x4d9>
mov    0x29d7(%rip),%rax
mov    (%rax),%edi
mov    -0x768(%rbp),%rdx
lea    0xa2f(%rip),%rsi
mov    $0x60,%ecx
lea    0xabc(%rip),%r8
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1653 <main+0x503>
mov    0x29a8(%rip),%rax
mov    (%rax),%edi
mov    -0x768(%rbp),%rdx
lea    0xa00(%rip),%rsi
mov    $0x62,%ecx
lea    0xb21(%rip),%r8
mov    $0x0,%al
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x780,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x748,%rsp
test   %edi,%edi
jle    116a <main+0x1a>
mov    (%rsi),%rbp
jmp    1171 <main+0x21>
lea    0xfeb(%rip),%rbp
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
call   1070 <sysconf@plt>
mov    %rax,0x18(%rsp)
mov    0x2e4d(%rip),%rbx
mov    (%rbx),%edi
lea    0xe9c(%rip),%r14
lea    0xea5(%rip),%r8
mov    %r14,%rsi
mov    %rbp,%rdx
mov    $0x22,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
xor    %eax,%eax
call   1040 <endHeap@plt>
mov    %rax,0x8(%rsp)
mov    (%rbx),%edi
lea    0xe96(%rip),%r8
mov    %r14,%rsi
mov    %rbp,%r13
mov    %rbp,%rdx
mov    $0x2a,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
xor    %r12d,%r12d
xor    %ebp,%ebp
jmp    11ec <main+0x9c>
xchg   %ax,%ax
add    $0x1,%ebp
cmp    $0x64,%ebp
je     1287 <main+0x137>
mov    %r12,%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x40,%edi
call   1060 <malloc@plt>
mov    %rax,0x340(%rsp,%rbx,8)
add    $0x1,%rbx
cmp    $0x80,%rbx
jne    1200 <main+0xb0>
xor    %eax,%eax
call   1040 <endHeap@plt>
mov    %rax,%r12
mov    %rax,%r14
xor    %ebx,%ebx
xchg   %ax,%ax
mov    0x340(%rsp,%rbx,8),%rdi
call   1030 <free@plt>
add    $0x1,%rbx
cmp    $0x80,%rbx
jne    1230 <main+0xe0>
cmp    %r12,%r15
cmova  %r15,%r12
imul   $0xcccccccd,%ebp,%eax
ror    %eax
cmp    $0x19999999,%eax
ja     11e0 <main+0x90>
mov    0x2d71(%rip),%rax
mov    (%rax),%edi
sub    0x8(%rsp),%r14d
lea    0xe03(%rip),%rsi
mov    %r13,%rdx
mov    %r14d,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    11e0 <main+0x90>
mov    %r12,%rax
sub    0x8(%rsp),%rax
cvtsi2sd %rax,%xmm0
mulsd  0xd64(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0x14(%rsp)
mov    0x2d2b(%rip),%rbp
mov    0x0(%rbp),%edi
cvttss2si %xmm0,%ecx
lea    0xde0(%rip),%rsi
mov    %r13,%rbx
mov    %r13,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
movss  0x14(%rsp),%xmm0
ucomiss 0xd33(%rip),%xmm0
mov    0x0(%rbp),%edi
lea    0xd51(%rip),%rsi
jbe    12f2 <main+0x1a2>
lea    0xde1(%rip),%r8
mov    %rbx,%rdx
mov    $0x42,%ecx
jmp    1301 <main+0x1b1>
lea    0xe00(%rip),%r8
mov    %rbx,%rdx
mov    $0x44,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2cc9(%rip),%rax
mov    (%rax),%edi
lea    0xd18(%rip),%rsi
lea    0xdf3(%rip),%r8
mov    %rbx,%rdx
mov    $0x47,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x18(%rsp),%rax
add    %eax,%eax
lea    (%rax,%rax,4),%ebp
xor    %r15d,%r15d
nopl   0x0(%rax,%rax,1)
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%edi
call   1060 <malloc@plt>
mov    %rax,0x20(%rsp,%rbx,8)
add    $0x1,%rbx
cmp    $0x64,%rbx
jne    1350 <main+0x200>
xor    %eax,%eax
call   1040 <endHeap@plt>
mov    %rax,%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x20(%rsp,%rbx,8),%rdi
call   1030 <free@plt>
add    $0x1,%rbx
cmp    $0x64,%rbx
jne    1380 <main+0x230>
cmp    %r14,%r12
cmovbe %r14,%r12
mov    0x2c36(%rip),%rax
mov    (%rax),%edi
sub    0x8(%rsp),%r14d
lea    0xcc8(%rip),%rsi
mov    %r13,%rdx
mov    %r14d,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
add    $0x1,%r15d
cmp    $0xa,%r15d
jne    1340 <main+0x1f0>
mov    0x2c06(%rip),%rbx
mov    (%rbx),%edi
lea    0xc55(%rip),%rsi
lea    0xd4e(%rip),%r8
mov    %r13,%rdx
mov    $0x5a,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
sub    0x8(%rsp),%r12
xorps  %xmm0,%xmm0
cvtsi2sd %r12,%xmm0
imul   $0x3e8,0x18(%rsp),%rax
movq   %rax,%xmm1
punpckldq 0xbfc(%rip),%xmm1
subpd  0xc04(%rip),%xmm1
movapd %xmm1,%xmm2
unpckhpd %xmm1,%xmm2
addsd  %xmm1,%xmm2
divsd  %xmm2,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0x8(%rsp)
mov    (%rbx),%edi
cvttss2si %xmm0,%ecx
lea    0xc58(%rip),%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
movss  0x8(%rsp),%xmm0
ucomiss 0xbae(%rip),%xmm0
mov    (%rbx),%edi
lea    0xbcd(%rip),%rsi
jbe    1476 <main+0x326>
lea    0xc5d(%rip),%r8
mov    %r13,%rdx
mov    $0x60,%ecx
jmp    1485 <main+0x335>
lea    0xce0(%rip),%r8
mov    %r13,%rdx
mov    $0x62,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x748,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@_SC_PAGESIZE = global i32 0
@stderr = global i32 0
@.str.1 = [16 x i8] c"%s, line %d: %s\00"
@.str.2 = [24 x i8] c"Testing memory utility\0A\00"
@.str.3 = [32 x i8] c"Getting small pieces of memory\0A\00"
@.str.4 = [35 x i8] c"%s: Using total of 0x%x of memory\0A\00"
@.str.5 = [46 x i8] c"%s: Using %2.2f times worst case calculation\0A\00"
@.str.6 = [48 x i8] c"* ERROR: Test indicates excessive memory usage\0A\00"
@.str.7 = [25 x i8] c"Small memory handled OK\0A\00"
@.str.8 = [30 x i8] c"Getting big blocks of memory\0A\00"
@.str.9 = [45 x i8] c"Allocations versus worst case memory usage:\0A\00"
@.str.10 = [23 x i8] c"Big memory handled OK\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca float
%9 = alloca [128 x i8*]
%10 = alloca [100 x i8*]
%11 = alloca i64
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %14
%16 = load i32, i32* %4
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
store i8* %21, i8** %15
br label %23
22: ; preds = %2
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %15
br label %23
23: ; preds = %22, %18
%24 = load i32, i32* @_SC_PAGESIZE
%25 = call i64 @sysconf(i32 %24)
store i64 %25, i64* %11
%26 = load i32, i32* @stderr
%27 = load i8*, i8** %15
%28 = call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %27, i32 34, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%29 = call i8* (...) @endHeap()
store i8* %29, i8** %12
%30 = load i32, i32* @stderr
%31 = load i8*, i8** %15
%32 = call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %31, i32 42, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %6
br label %33
33: ; preds = %86, %23
%34 = load i32, i32* %6
%35 = icmp slt i32 %34, 100
br i1 %35, label %36, label %89
36: ; preds = %33
store i32 0, i32* %7
br label %37
37: ; preds = %45, %36
%38 = load i32, i32* %7
%39 = icmp slt i32 %38, 128
br i1 %39, label %40, label %48
40: ; preds = %37
%41 = call i8* @malloc(i32 64)
%42 = load i32, i32* %7
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [128 x i8*], [128 x i8*]* %9, i64 0, i64 %43
store i8* %41, i8** %44
br label %45
45: ; preds = %40
%46 = load i32, i32* %7
%47 = add nsw i32 %46, 1
store i32 %47, i32* %7
br label %37
48: ; preds = %37
%49 = call i8* (...) @endHeap()
store i8* %49, i8** %13
%50 = load i8*, i8** %14
%51 = load i8*, i8** %13
%52 = icmp ugt i8* %50, %51
br i1 %52, label %53, label %55
53: ; preds = %48
%54 = load i8*, i8** %14
br label %57
55: ; preds = %48
%56 = load i8*, i8** %13
br label %57
57: ; preds = %55, %53
%58 = phi i8* [ %54, %53 ], [ %56, %55 ]
store i8* %58, i8** %14
store i32 0, i32* %7
br label %59
59: ; preds = %68, %57
%60 = load i32, i32* %7
%61 = icmp slt i32 %60, 128
br i1 %61, label %62, label %71
62: ; preds = %59
%63 = load i32, i32* %7
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [128 x i8*], [128 x i8*]* %9, i64 0, i64 %64
%66 = load i8*, i8** %65
%67 = call i32 @free(i8* %66)
br label %68
68: ; preds = %62
%69 = load i32, i32* %7
%70 = add nsw i32 %69, 1
store i32 %70, i32* %7
br label %59
71: ; preds = %59
%72 = load i32, i32* %6
%73 = srem i32 %72, 10
%74 = icmp eq i32 %73, 0
br i1 %74, label %75, label %85
75: ; preds = %71
%76 = load i32, i32* @stderr
%77 = load i8*, i8** %15
%78 = load i8*, i8** %13
%79 = load i8*, i8** %12
%80 = ptrtoint i8* %78 to i64
%81 = ptrtoint i8* %79 to i64
%82 = sub i64 %80, %81
%83 = trunc i64 %82 to i32
%84 = call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i8* %77, i32 %83)
br label %85
85: ; preds = %75, %71
br label %86
86: ; preds = %85
%87 = load i32, i32* %6
%88 = add nsw i32 %87, 1
store i32 %88, i32* %6
br label %33
89: ; preds = %33
%90 = load i8*, i8** %14
%91 = load i8*, i8** %12
%92 = ptrtoint i8* %90 to i64
%93 = ptrtoint i8* %91 to i64
%94 = sub i64 %92, %93
%95 = sitofp i64 %94 to double
%96 = fdiv double %95, 8.192000e+03
%97 = fptrunc double %96 to float
store float %97, float* %8
%98 = load i32, i32* @stderr
%99 = load i8*, i8** %15
%100 = load float, float* %8
%101 = fptosi float %100 to i32
%102 = call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %98, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.5, i64 0, i64 0), i8* %99, i32 %101)
%103 = load float, float* %8
%104 = fcmp ogt float %103, 2.000000e+00
br i1 %104, label %105, label %109
105: ; preds = %89
%106 = load i32, i32* @stderr
%107 = load i8*, i8** %15
%108 = call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %106, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %107, i32 66, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.6, i64 0, i64 0))
br label %113
109: ; preds = %89
%110 = load i32, i32* @stderr
%111 = load i8*, i8** %15
%112 = call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %110, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %111, i32 68, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0))
br label %113
113: ; preds = %109, %105
%114 = load i32, i32* @stderr
%115 = load i8*, i8** %15
%116 = call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %114, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %115, i32 71, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0))
store i32 0, i32* %6
br label %117
117: ; preds = %168, %113
%118 = load i32, i32* %6
%119 = icmp slt i32 %118, 10
br i1 %119, label %120, label %171
120: ; preds = %117
store i32 0, i32* %7
br label %121
121: ; preds = %132, %120
%122 = load i32, i32* %7
%123 = icmp slt i32 %122, 100
br i1 %123, label %124, label %135
124: ; preds = %121
%125 = load i64, i64* %11
%126 = mul i64 10, %125
%127 = trunc i64 %126 to i32
%128 = call i8* @malloc(i32 %127)
%129 = load i32, i32* %7
%130 = sext i32 %129 to i64
%131 = getelementptr inbounds [100 x i8*], [100 x i8*]* %10, i64 0, i64 %130
store i8* %128, i8** %131
br label %132
132: ; preds = %124
%133 = load i32, i32* %7
%134 = add nsw i32 %133, 1
store i32 %134, i32* %7
br label %121
135: ; preds = %121
%136 = call i8* (...) @endHeap()
store i8* %136, i8** %13
%137 = load i8*, i8** %14
%138 = load i8*, i8** %13
%139 = icmp ugt i8* %137, %138
br i1 %139, label %140, label %142
140: ; preds = %135
%141 = load i8*, i8** %14
br label %144
142: ; preds = %135
%143 = load i8*, i8** %13
br label %144
144: ; preds = %142, %140
%145 = phi i8* [ %141, %140 ], [ %143, %142 ]
store i8* %145, i8** %14
store i32 0, i32* %7
br label %146
146: ; preds = %155, %144
%147 = load i32, i32* %7
%148 = icmp slt i32 %147, 100
br i1 %148, label %149, label %158
149: ; preds = %146
%150 = load i32, i32* %7
%151 = sext i32 %150 to i64
%152 = getelementptr inbounds [100 x i8*], [100 x i8*]* %10, i64 0, i64 %151
%153 = load i8*, i8** %152
%154 = call i32 @free(i8* %153)
br label %155
155: ; preds = %149
%156 = load i32, i32* %7
%157 = add nsw i32 %156, 1
store i32 %157, i32* %7
br label %146
158: ; preds = %146
%159 = load i32, i32* @stderr
%160 = load i8*, i8** %15
%161 = load i8*, i8** %13
%162 = load i8*, i8** %12
%163 = ptrtoint i8* %161 to i64
%164 = ptrtoint i8* %162 to i64
%165 = sub i64 %163, %164
%166 = trunc i64 %165 to i32
%167 = call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %159, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i8* %160, i32 %166)
br label %168
168: ; preds = %158
%169 = load i32, i32* %6
%170 = add nsw i32 %169, 1
store i32 %170, i32* %6
br label %117
171: ; preds = %117
%172 = load i32, i32* @stderr
%173 = load i8*, i8** %15
%174 = call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %172, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %173, i32 90, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.9, i64 0, i64 0))
%175 = load i8*, i8** %14
%176 = load i8*, i8** %12
%177 = ptrtoint i8* %175 to i64
%178 = ptrtoint i8* %176 to i64
%179 = sub i64 %177, %178
%180 = sitofp i64 %179 to double
%181 = load i64, i64* %11
%182 = mul i64 100, %181
%183 = mul i64 %182, 10
%184 = uitofp i64 %183 to double
%185 = fmul double %184, 1.000000e+00
%186 = fdiv double %180, %185
%187 = fptrunc double %186 to float
store float %187, float* %8
%188 = load i32, i32* @stderr
%189 = load i8*, i8** %15
%190 = load float, float* %8
%191 = fptosi float %190 to i32
%192 = call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %188, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.5, i64 0, i64 0), i8* %189, i32 %191)
%193 = load float, float* %8
%194 = fcmp ogt float %193, 2.000000e+00
br i1 %194, label %195, label %199
195: ; preds = %171
%196 = load i32, i32* @stderr
%197 = load i8*, i8** %15
%198 = call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %196, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %197, i32 96, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.6, i64 0, i64 0))
br label %203
199: ; preds = %171
%200 = load i32, i32* @stderr
%201 = load i8*, i8** %15
%202 = call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %200, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %201, i32 98, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0))
br label %203
203: ; preds = %199, %195
ret i32 0
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@_SC_PAGESIZE = global i32 0
@stderr = global i32 0
@.str.1 = [16 x i8] c"%s, line %d: %s\00"
@.str.2 = [24 x i8] c"Testing memory utility\0A\00"
@.str.3 = [32 x i8] c"Getting small pieces of memory\0A\00"
@.str.4 = [35 x i8] c"%s: Using total of 0x%x of memory\0A\00"
@.str.5 = [46 x i8] c"%s: Using %2.2f times worst case calculation\0A\00"
@.str.6 = [48 x i8] c"* ERROR: Test indicates excessive memory usage\0A\00"
@.str.7 = [25 x i8] c"Small memory handled OK\0A\00"
@.str.8 = [30 x i8] c"Getting big blocks of memory\0A\00"
@.str.9 = [45 x i8] c"Allocations versus worst case memory usage:\0A\00"
@.str.10 = [23 x i8] c"Big memory handled OK\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [128 x i8*]
%4 = alloca [100 x i8*]
%5 = bitcast [128 x i8*]* %3 to i8*
%6 = bitcast [100 x i8*]* %4 to i8*
%7 = icmp sgt i32 %0, 0
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = load i8*, i8** %1
br label %10
10: ; preds = %2, %8
%11 = phi i8* [ %9, %8 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %2 ]
%12 = load i32, i32* @_SC_PAGESIZE
%13 = tail call i64 @sysconf(i32 %12)
%14 = load i32, i32* @stderr
%15 = tail call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %11, i32 34, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%16 = tail call i8* (...) @endHeap()
%17 = load i32, i32* @stderr
%18 = tail call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %11, i32 42, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
%19 = ptrtoint i8* %16 to i64
br label %20
20: ; preds = %10, %49
%21 = phi i8* [ null, %10 ], [ %40, %49 ]
%22 = phi i32 [ 0, %10 ], [ %50, %49 ]
br label %23
23: ; preds = %20, %23
%24 = phi i64 [ 0, %20 ], [ %27, %23 ]
%25 = tail call dereferenceable_or_null(64) i8* @malloc(i32 64)
%26 = getelementptr inbounds [128 x i8*], [128 x i8*]* %3, i64 0, i64 %24
store i8* %25, i8** %26
%27 = add nuw nsw i64 %24, 1
%28 = icmp eq i64 %27, 128
br i1 %28, label %29, label %23
29: ; preds = %23
%30 = tail call i8* (...) @endHeap()
%31 = icmp ugt i8* %21, %30
br label %32
32: ; preds = %29, %32
%33 = phi i64 [ 0, %29 ], [ %37, %32 ]
%34 = getelementptr inbounds [128 x i8*], [128 x i8*]* %3, i64 0, i64 %33
%35 = load i8*, i8** %34
%36 = tail call i32 @free(i8* %35)
%37 = add nuw nsw i64 %33, 1
%38 = icmp eq i64 %37, 128
br i1 %38, label %39, label %32
39: ; preds = %32
%40 = select i1 %31, i8* %21, i8* %30
%41 = urem i32 %22, 10
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %49
43: ; preds = %39
%44 = load i32, i32* @stderr
%45 = ptrtoint i8* %30 to i64
%46 = sub i64 %45, %19
%47 = trunc i64 %46 to i32
%48 = tail call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i8* %11, i32 %47)
br label %49
49: ; preds = %39, %43
%50 = add nuw nsw i32 %22, 1
%51 = icmp eq i32 %50, 100
br i1 %51, label %52, label %20
52: ; preds = %49
%53 = ptrtoint i8* %40 to i64
%54 = sub i64 %53, %19
%55 = sitofp i64 %54 to double
%56 = fmul double %55, 0x3F20000000000000
%57 = fptrunc double %56 to float
%58 = load i32, i32* @stderr
%59 = fptosi float %57 to i32
%60 = tail call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.5, i64 0, i64 0), i8* %11, i32 %59)
%61 = fcmp ogt float %57, 2.000000e+00
%62 = load i32, i32* @stderr
br i1 %61, label %63, label %65
63: ; preds = %52
%64 = tail call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %62, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %11, i32 66, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.6, i64 0, i64 0))
br label %67
65: ; preds = %52
%66 = tail call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %62, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %11, i32 68, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0))
br label %67
67: ; preds = %65, %63
%68 = load i32, i32* @stderr
%69 = tail call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %11, i32 71, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0))
%70 = trunc i64 %13 to i32
%71 = mul i32 %70, 10
br label %72
72: ; preds = %67, %91
%73 = phi i8* [ %40, %67 ], [ %92, %91 ]
%74 = phi i32 [ 0, %67 ], [ %98, %91 ]
br label %75
75: ; preds = %72, %75
%76 = phi i64 [ 0, %72 ], [ %79, %75 ]
%77 = tail call i8* @malloc(i32 %71)
%78 = getelementptr inbounds [100 x i8*], [100 x i8*]* %4, i64 0, i64 %76
store i8* %77, i8** %78
%79 = add nuw nsw i64 %76, 1
%80 = icmp eq i64 %79, 100
br i1 %80, label %81, label %75
81: ; preds = %75
%82 = tail call i8* (...) @endHeap()
%83 = icmp ugt i8* %73, %82
br label %84
84: ; preds = %81, %84
%85 = phi i64 [ 0, %81 ], [ %89, %84 ]
%86 = getelementptr inbounds [100 x i8*], [100 x i8*]* %4, i64 0, i64 %85
%87 = load i8*, i8** %86
%88 = tail call i32 @free(i8* %87)
%89 = add nuw nsw i64 %85, 1
%90 = icmp eq i64 %89, 100
br i1 %90, label %91, label %84
91: ; preds = %84
%92 = select i1 %83, i8* %73, i8* %82
%93 = load i32, i32* @stderr
%94 = ptrtoint i8* %82 to i64
%95 = sub i64 %94, %19
%96 = trunc i64 %95 to i32
%97 = tail call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %93, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i8* %11, i32 %96)
%98 = add nuw nsw i32 %74, 1
%99 = icmp eq i32 %98, 10
br i1 %99, label %100, label %72
100: ; preds = %91
%101 = load i32, i32* @stderr
%102 = tail call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %101, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %11, i32 90, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.9, i64 0, i64 0))
%103 = ptrtoint i8* %92 to i64
%104 = sub i64 %103, %19
%105 = sitofp i64 %104 to double
%106 = mul i64 %13, 1000
%107 = uitofp i64 %106 to double
%108 = fdiv double %105, %107
%109 = fptrunc double %108 to float
%110 = load i32, i32* @stderr
%111 = fptosi float %109 to i32
%112 = tail call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %110, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.5, i64 0, i64 0), i8* %11, i32 %111)
%113 = fcmp ogt float %109, 2.000000e+00
%114 = load i32, i32* @stderr
br i1 %113, label %115, label %117
115: ; preds = %100
%116 = tail call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %114, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %11, i32 96, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.6, i64 0, i64 0))
br label %119
117: ; preds = %100
%118 = tail call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %114, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %11, i32 98, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0))
br label %119
119: ; preds = %117, %115
ret i32 0
}