#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 */
void *ant_alloc(size_t);
int /*<<< orphan*/ ant_free(void *, size_t);
int /*<<< orphan*/ heap_create(size_t);
int /*<<< orphan*/ heap_destroy();
int /*<<< orphan*/ heap_dump();
void test2() {
  size_t heap_sz = 9000;
  size_t request_sz = 1000;
  heap_create(heap_sz);
  void *p1 = ant_alloc(request_sz);
  void *p2 = ant_alloc(request_sz);
  void *p3 = ant_alloc(request_sz);
  void *p4 = ant_alloc(request_sz);
  heap_dump();
  ant_free(p2, request_sz);
  ant_free(p4, request_sz);
  heap_dump();
  ant_free(p1, request_sz);
  ant_free(p3, request_sz);
  heap_dump();
  heap_destroy();
}


x86 assembly (clang, -O0):
<test2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movq   $0x2328,-0x8(%rbp)
movq   $0x3e8,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <heap_create@plt>
mov    -0x10(%rbp),%rdi
call   1040 <ant_alloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <ant_alloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <ant_alloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <ant_alloc@plt>
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1050 <heap_dump@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <ant_free@plt>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <ant_free@plt>
mov    $0x0,%al
call   1050 <heap_dump@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <ant_free@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <ant_free@plt>
mov    $0x0,%al
call   1050 <heap_dump@plt>
mov    $0x0,%al
call   1070 <heap_destroy@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test2>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    $0x2328,%edi
call   1060 <heap_create@plt>
mov    $0x3e8,%edi
call   1040 <ant_alloc@plt>
mov    %rax,%r14
mov    $0x3e8,%edi
call   1040 <ant_alloc@plt>
mov    %rax,%r12
mov    $0x3e8,%edi
call   1040 <ant_alloc@plt>
mov    %rax,%r15
mov    $0x3e8,%edi
call   1040 <ant_alloc@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <heap_dump@plt>
mov    $0x3e8,%esi
mov    %r12,%rdi
call   1030 <ant_free@plt>
mov    $0x3e8,%esi
mov    %rbx,%rdi
call   1030 <ant_free@plt>
xor    %eax,%eax
call   1050 <heap_dump@plt>
mov    $0x3e8,%esi
mov    %r14,%rdi
call   1030 <ant_free@plt>
mov    $0x3e8,%esi
mov    %r15,%rdi
call   1030 <ant_free@plt>
xor    %eax,%eax
call   1050 <heap_dump@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1070 <heap_destroy@plt>

LLVM IR (-O0):
define void @test2() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i64 9000, i64* %1
store i64 1000, i64* %2
%7 = load i64, i64* %1
%8 = call i32 @heap_create(i64 %7)
%9 = load i64, i64* %2
%10 = call i8* @ant_alloc(i64 %9)
store i8* %10, i8** %3
%11 = load i64, i64* %2
%12 = call i8* @ant_alloc(i64 %11)
store i8* %12, i8** %4
%13 = load i64, i64* %2
%14 = call i8* @ant_alloc(i64 %13)
store i8* %14, i8** %5
%15 = load i64, i64* %2
%16 = call i8* @ant_alloc(i64 %15)
store i8* %16, i8** %6
%17 = call i32 (...) @heap_dump()
%18 = load i8*, i8** %4
%19 = load i64, i64* %2
%20 = call i32 @ant_free(i8* %18, i64 %19)
%21 = load i8*, i8** %6
%22 = load i64, i64* %2
%23 = call i32 @ant_free(i8* %21, i64 %22)
%24 = call i32 (...) @heap_dump()
%25 = load i8*, i8** %3
%26 = load i64, i64* %2
%27 = call i32 @ant_free(i8* %25, i64 %26)
%28 = load i8*, i8** %5
%29 = load i64, i64* %2
%30 = call i32 @ant_free(i8* %28, i64 %29)
%31 = call i32 (...) @heap_dump()
%32 = call i32 (...) @heap_destroy()
ret void
}

LLVM IR (-O2):
define void @test2() {
%1 = tail call i32 @heap_create(i64 9000)
%2 = tail call i8* @ant_alloc(i64 1000)
%3 = tail call i8* @ant_alloc(i64 1000)
%4 = tail call i8* @ant_alloc(i64 1000)
%5 = tail call i8* @ant_alloc(i64 1000)
%6 = tail call i32 (...) @heap_dump()
%7 = tail call i32 @ant_free(i8* %3, i64 1000)
%8 = tail call i32 @ant_free(i8* %5, i64 1000)
%9 = tail call i32 (...) @heap_dump()
%10 = tail call i32 @ant_free(i8* %2, i64 1000)
%11 = tail call i32 @ant_free(i8* %4, i64 1000)
%12 = tail call i32 (...) @heap_dump()
%13 = tail call i32 (...) @heap_destroy()
ret void
}