void test_count(int c) {
  char **nums;
  nums = blkalloc((sizeof(char *) * c));
  for (int i = 0; i < c; i++) {
    nums[i] = blkalloc((sizeof(char) + 15));
  }
  for (int i = 0; i < c; i++) {
    blkfree((nums[i]));
  }
  printf("allocated and freed %d sub-blocks\n", c);
  blkfree((nums));
}


x86 assembly (clang, -O0):
<test_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movslq -0x4(%rbp),%rdi
shl    $0x3,%rdi
mov    $0x0,%al
call   1040 <blkalloc@plt>
cltq
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    118c <test_count+0x5c>
mov    $0x10,%edi
mov    $0x0,%al
call   1040 <blkalloc@plt>
movslq %eax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1157 <test_count+0x27>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11c0 <test_count+0x90>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    $0x0,%al
call   1050 <blkfree@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1193 <test_count+0x63>
mov    -0x4(%rbp),%esi
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x0,%al
call   1050 <blkfree@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_count>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r14d
movslq %edi,%rbx
lea    0x0(,%rbx,8),%rdi
xor    %eax,%eax
call   1040 <blkalloc@plt>
movslq %eax,%r15
test   %ebx,%ebx
jle    11a4 <test_count+0x74>
mov    %r14d,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    $0x10,%edi
xor    %eax,%eax
call   1040 <blkalloc@plt>
cltq
mov    %rax,(%r15,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1160 <test_count+0x30>
test   %r14d,%r14d
jle    11a4 <test_count+0x74>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r15,%rbx,8),%rdi
xor    %eax,%eax
call   1050 <blkfree@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1190 <test_count+0x60>
lea    0xe55(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <blkfree@plt>

LLVM IR (-O0):
@.str = [35 x i8] c"allocated and freed %d sub-blocks\0A\00"
define void @test_count(i32 %0) {
%2 = alloca i32
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = sext i32 %6 to i64
%8 = mul i64 8, %7
%9 = call i32 (i64, ...) bitcast (i32 (...)* @blkalloc to i32 (i64, ...)*)(i64 %8)
%10 = sext i32 %9 to i64
%11 = inttoptr i64 %10 to i8**
store i8** %11, i8*** %3
store i32 0, i32* %4
br label %12
12: ; preds = %24, %1
%13 = load i32, i32* %4
%14 = load i32, i32* %2
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %27
16: ; preds = %12
%17 = call i32 (i64, ...) bitcast (i32 (...)* @blkalloc to i32 (i64, ...)*)(i64 16)
%18 = sext i32 %17 to i64
%19 = inttoptr i64 %18 to i8*
%20 = load i8**, i8*** %3
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %20, i64 %22
store i8* %19, i8** %23
br label %24
24: ; preds = %16
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 1
store i32 %26, i32* %4
br label %12
27: ; preds = %12
store i32 0, i32* %5
br label %28
28: ; preds = %39, %27
%29 = load i32, i32* %5
%30 = load i32, i32* %2
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %42
32: ; preds = %28
%33 = load i8**, i8*** %3
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %33, i64 %35
%37 = load i8*, i8** %36
%38 = call i32 (i8*, ...) bitcast (i32 (...)* @blkfree to i32 (i8*, ...)*)(i8* %37)
br label %39
39: ; preds = %32
%40 = load i32, i32* %5
%41 = add nsw i32 %40, 1
store i32 %41, i32* %5
br label %28
42: ; preds = %28
%43 = load i32, i32* %2
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %43)
%45 = load i8**, i8*** %3
%46 = call i32 (i8**, ...) bitcast (i32 (...)* @blkfree to i32 (i8**, ...)*)(i8** %45)
ret void
}

LLVM IR (-O2):
@.str = [35 x i8] c"allocated and freed %d sub-blocks\0A\00"
define void @test_count(i32 %0) {
%2 = sext i32 %0 to i64
%3 = shl nsw i64 %2, 3
%4 = tail call i32 (i64, ...) bitcast (i32 (...)* @blkalloc to i32 (i64, ...)*)(i64 %3)
%5 = sext i32 %4 to i64
%6 = inttoptr i64 %5 to i8**
%7 = icmp sgt i32 %0, 0
br i1 %7, label %8, label %21
8: ; preds = %1
%9 = zext i32 %0 to i64
br label %13
10: ; preds = %13
br i1 %7, label %11, label %21
11: ; preds = %10
%12 = zext i32 %0 to i64
br label %24
13: ; preds = %8, %13
%14 = phi i64 [ 0, %8 ], [ %19, %13 ]
%15 = tail call i32 (i64, ...) bitcast (i32 (...)* @blkalloc to i32 (i64, ...)*)(i64 16)
%16 = sext i32 %15 to i64
%17 = inttoptr i64 %16 to i8*
%18 = getelementptr inbounds i8*, i8** %6, i64 %14
store i8* %17, i8** %18
%19 = add nuw nsw i64 %14, 1
%20 = icmp eq i64 %19, %9
br i1 %20, label %10, label %13
21: ; preds = %24, %1, %10
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %0)
%23 = tail call i32 (i8**, ...) bitcast (i32 (...)* @blkfree to i32 (i8**, ...)*)(i8** %6)
ret void
24: ; preds = %11, %24
%25 = phi i64 [ 0, %11 ], [ %29, %24 ]
%26 = getelementptr inbounds i8*, i8** %6, i64 %25
%27 = load i8*, i8** %26
%28 = tail call i32 (i8*, ...) bitcast (i32 (...)* @blkfree to i32 (i8*, ...)*)(i8* %27)
%29 = add nuw nsw i64 %25, 1
%30 = icmp eq i64 %29, %12
br i1 %30, label %21, label %24
}