#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*/ create_pool(int);
int /*<<< orphan*/ destroy_pool();
void *my_malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int test_one() {
  printf("Test One: Blocks of size 10\n");
  create_pool(1000);
  int i = 0;
  void *bl = my_malloc(10);
  while (bl) {
    bl = my_malloc(10);
    i++;
  }
  printf("Blocks Created: %d\n", i);
  destroy_pool();
  return 1;
}


x86 assembly (clang, -O0):
<test_one>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x3e8,%edi
call   1050 <create_pool@plt>
movl   $0x0,-0x4(%rbp)
mov    $0xa,%edi
call   1030 <my_malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     119c <test_one+0x5c>
mov    $0xa,%edi
call   1030 <my_malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1175 <test_one+0x35>
mov    -0x4(%rbp),%esi
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <destroy_pool@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_one>:
push   %rbx
lea    0xebc(%rip),%rdi
call   1040 <puts@plt>
mov    $0x3e8,%edi
call   1060 <create_pool@plt>
mov    $0xa,%edi
call   1030 <my_malloc@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     1192 <test_one+0x42>
nopl   0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <my_malloc@plt>
add    $0x1,%ebx
test   %rax,%rax
jne    1180 <test_one+0x30>
lea    0xe67(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1070 <destroy_pool@plt>
mov    $0x1,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [29 x i8] c"Test One: Blocks of size 10\0A\00"
@.str.1 = [20 x i8] c"Blocks Created: %d\0A\00"
define i32 @test_one() {
%1 = alloca i32
%2 = alloca i8*
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @create_pool(i32 1000)
store i32 0, i32* %1
%5 = call i8* @my_malloc(i32 10)
store i8* %5, i8** %2
br label %6
6: ; preds = %9, %0
%7 = load i8*, i8** %2
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %13
9: ; preds = %6
%10 = call i8* @my_malloc(i32 10)
store i8* %10, i8** %2
%11 = load i32, i32* %1
%12 = add nsw i32 %11, 1
store i32 %12, i32* %1
br label %6
13: ; preds = %6
%14 = load i32, i32* %1
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = call i32 (...) @destroy_pool()
ret i32 1
}

LLVM IR (-O2):
@.str.1 = [20 x i8] c"Blocks Created: %d\0A\00"
@str = [28 x i8] c"Test One: Blocks of size 10\00"
define i32 @test_one() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 @create_pool(i32 1000)
%3 = tail call i8* @my_malloc(i32 10)
%4 = icmp eq i8* %3, null
br i1 %4, label %10, label %5
5: ; preds = %0, %5
%6 = phi i32 [ %8, %5 ], [ 0, %0 ]
%7 = tail call i8* @my_malloc(i32 10)
%8 = add nuw nsw i32 %6, 1
%9 = icmp eq i8* %7, null
br i1 %9, label %10, label %5
10: ; preds = %5, %0
%11 = phi i32 [ 0, %0 ], [ %8, %5 ]
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = tail call i32 (...) @destroy_pool()
ret i32 1
}