#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*/ my_free(void *);
int /*<<< orphan*/ my_mallinfo();
void *my_malloc(int);
int /*<<< orphan*/ my_mallopt(int);
int /*<<< orphan*/ puts(char *);
void simpleBestFitTesting(void) {
  char buf[128];
  my_mallopt(2);
  puts("------------------- Best Fit: Typical Test -------------------\r\n");
  void *test1 = my_malloc(100);
  void *test2 = my_malloc(20);
  void *test3 = my_malloc(100);
  void *test4 = my_malloc(15);
  void *test5 = my_malloc(100);
  my_mallinfo();
  my_free(test2);
  my_free(test4);
  my_mallinfo();
  void *test6 = my_malloc(10);
  my_mallinfo();
  my_free(test1);
  my_free(test3);
  my_free(test5);
  my_free(test6);
  puts("------------------- Best Fit: Edge Case (First) "
       "-------------------\r\n");
  test1 = my_malloc(9);
  test2 = my_malloc(20);
  test3 = my_malloc(30);
  test4 = my_malloc(40);
  test5 = my_malloc(10);
  my_mallinfo();
  my_free(test1);
  my_free(test4);
  my_free(test5);
  my_mallinfo();
  test6 = my_malloc(8);
  my_mallinfo();
  my_free(test2);
  my_free(test3);
  my_free(test6);
  puts(
      "------------------- Best Fit: Edge Case (Last) -------------------\r\n");
  test1 = my_malloc(10);
  test2 = my_malloc(20);
  test3 = my_malloc(30);
  test4 = my_malloc(267);
  test5 = my_malloc(8);
  my_mallinfo();
  my_free(test1);
  my_free(test3);
  my_free(test5);
  my_mallinfo();
  test6 = my_malloc(8);
  my_mallinfo();
  my_free(test2);
  my_free(test4);
  my_free(test6);
}


x86 assembly (clang, -O0):
<simpleBestFitTesting>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    $0x2,%edi
call   1070 <my_mallopt@plt>
lea    0xe94(%rip),%rdi
call   1040 <puts@plt>
mov    $0x64,%edi
call   1030 <my_malloc@plt>
mov    %rax,-0x88(%rbp)
mov    $0x14,%edi
call   1030 <my_malloc@plt>
mov    %rax,-0x90(%rbp)
mov    $0x64,%edi
call   1030 <my_malloc@plt>
mov    %rax,-0x98(%rbp)
mov    $0xf,%edi
call   1030 <my_malloc@plt>
mov    %rax,-0xa0(%rbp)
mov    $0x64,%edi
call   1030 <my_malloc@plt>
mov    %rax,-0xa8(%rbp)
mov    $0x0,%al
call   1050 <my_mallinfo@plt>
mov    -0x90(%rbp),%rdi
call   1060 <my_free@plt>
mov    -0xa0(%rbp),%rdi
call   1060 <my_free@plt>
mov    $0x0,%al
call   1050 <my_mallinfo@plt>
mov    $0xa,%edi
call   1030 <my_malloc@plt>
mov    %rax,-0xb0(%rbp)
mov    $0x0,%al
call   1050 <my_mallinfo@plt>
mov    -0x88(%rbp),%rdi
call   1060 <my_free@plt>
mov    -0x98(%rbp),%rdi
call   1060 <my_free@plt>
mov    -0xa8(%rbp),%rdi
call   1060 <my_free@plt>
mov    -0xb0(%rbp),%rdi
call   1060 <my_free@plt>
lea    0xe06(%rip),%rdi
call   1040 <puts@plt>
mov    $0x9,%edi
call   1030 <my_malloc@plt>
mov    %rax,-0x88(%rbp)
mov    $0x14,%edi
call   1030 <my_malloc@plt>
mov    %rax,-0x90(%rbp)
mov    $0x1e,%edi
call   1030 <my_malloc@plt>
mov    %rax,-0x98(%rbp)
mov    $0x28,%edi
call   1030 <my_malloc@plt>
mov    %rax,-0xa0(%rbp)
mov    $0xa,%edi
call   1030 <my_malloc@plt>
mov    %rax,-0xa8(%rbp)
mov    $0x0,%al
call   1050 <my_mallinfo@plt>
mov    -0x88(%rbp),%rdi
call   1060 <my_free@plt>
mov    -0xa0(%rbp),%rdi
call   1060 <my_free@plt>
mov    -0xa8(%rbp),%rdi
call   1060 <my_free@plt>
mov    $0x0,%al
call   1050 <my_mallinfo@plt>
mov    $0x8,%edi
call   1030 <my_malloc@plt>
mov    %rax,-0xb0(%rbp)
mov    $0x0,%al
call   1050 <my_mallinfo@plt>
mov    -0x90(%rbp),%rdi
call   1060 <my_free@plt>
mov    -0x98(%rbp),%rdi
call   1060 <my_free@plt>
mov    -0xb0(%rbp),%rdi
call   1060 <my_free@plt>
lea    0xd7d(%rip),%rdi
call   1040 <puts@plt>
mov    $0xa,%edi
call   1030 <my_malloc@plt>
mov    %rax,-0x88(%rbp)
mov    $0x14,%edi
call   1030 <my_malloc@plt>
mov    %rax,-0x90(%rbp)
mov    $0x1e,%edi
call   1030 <my_malloc@plt>
mov    %rax,-0x98(%rbp)
mov    $0x10b,%edi
call   1030 <my_malloc@plt>
mov    %rax,-0xa0(%rbp)
mov    $0x8,%edi
call   1030 <my_malloc@plt>
mov    %rax,-0xa8(%rbp)
mov    $0x0,%al
call   1050 <my_mallinfo@plt>
mov    -0x88(%rbp),%rdi
call   1060 <my_free@plt>
mov    -0x98(%rbp),%rdi
call   1060 <my_free@plt>
mov    -0xa8(%rbp),%rdi
call   1060 <my_free@plt>
mov    $0x0,%al
call   1050 <my_mallinfo@plt>
mov    $0x8,%edi
call   1030 <my_malloc@plt>
mov    %rax,-0xb0(%rbp)
mov    $0x0,%al
call   1050 <my_mallinfo@plt>
mov    -0x90(%rbp),%rdi
call   1060 <my_free@plt>
mov    -0xa0(%rbp),%rdi
call   1060 <my_free@plt>
mov    -0xb0(%rbp),%rdi
call   1060 <my_free@plt>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<simpleBestFitTesting>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    $0x2,%edi
call   1070 <my_mallopt@plt>
lea    0xe96(%rip),%rdi
call   1040 <puts@plt>
mov    $0x64,%edi
call   1030 <my_malloc@plt>
mov    %rax,%r14
mov    $0x14,%edi
call   1030 <my_malloc@plt>
mov    %rax,%r13
mov    $0x64,%edi
call   1030 <my_malloc@plt>
mov    %rax,%r15
mov    $0xf,%edi
call   1030 <my_malloc@plt>
mov    %rax,%rbx
mov    $0x64,%edi
call   1030 <my_malloc@plt>
mov    %rax,%r12
xor    %eax,%eax
call   1050 <my_mallinfo@plt>
mov    %r13,%rdi
call   1060 <my_free@plt>
mov    %rbx,%rdi
call   1060 <my_free@plt>
xor    %eax,%eax
call   1050 <my_mallinfo@plt>
mov    $0xa,%edi
call   1030 <my_malloc@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <my_mallinfo@plt>
mov    %r14,%rdi
call   1060 <my_free@plt>
mov    %r15,%rdi
call   1060 <my_free@plt>
mov    %r12,%rdi
call   1060 <my_free@plt>
mov    %rbx,%rdi
call   1060 <my_free@plt>
lea    0xe38(%rip),%rdi
call   1040 <puts@plt>
mov    $0x9,%edi
call   1030 <my_malloc@plt>
mov    %rax,%r12
mov    $0x14,%edi
call   1030 <my_malloc@plt>
mov    %rax,%r14
mov    $0x1e,%edi
call   1030 <my_malloc@plt>
mov    %rax,%r15
mov    $0x28,%edi
call   1030 <my_malloc@plt>
mov    %rax,%r13
mov    $0xa,%edi
call   1030 <my_malloc@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <my_mallinfo@plt>
mov    %r12,%rdi
call   1060 <my_free@plt>
mov    %r13,%rdi
call   1060 <my_free@plt>
mov    %rbx,%rdi
call   1060 <my_free@plt>
xor    %eax,%eax
call   1050 <my_mallinfo@plt>
mov    $0x8,%edi
call   1030 <my_malloc@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <my_mallinfo@plt>
mov    %r14,%rdi
call   1060 <my_free@plt>
mov    %r15,%rdi
call   1060 <my_free@plt>
mov    %rbx,%rdi
call   1060 <my_free@plt>
lea    0xddf(%rip),%rdi
call   1040 <puts@plt>
mov    $0xa,%edi
call   1030 <my_malloc@plt>
mov    %rax,%r12
mov    $0x14,%edi
call   1030 <my_malloc@plt>
mov    %rax,%r14
mov    $0x1e,%edi
call   1030 <my_malloc@plt>
mov    %rax,%r13
mov    $0x10b,%edi
call   1030 <my_malloc@plt>
mov    %rax,%r15
mov    $0x8,%edi
call   1030 <my_malloc@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <my_mallinfo@plt>
mov    %r12,%rdi
call   1060 <my_free@plt>
mov    %r13,%rdi
call   1060 <my_free@plt>
mov    %rbx,%rdi
call   1060 <my_free@plt>
xor    %eax,%eax
call   1050 <my_mallinfo@plt>
mov    $0x8,%edi
call   1030 <my_malloc@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <my_mallinfo@plt>
mov    %r14,%rdi
call   1060 <my_free@plt>
mov    %r15,%rdi
call   1060 <my_free@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1060 <my_free@plt>

LLVM IR (-O0):
@.str = [65 x i8] c"------------------- Best Fit: Typical Test -------------------\0D\0A\00"
@.str.1 = [70 x i8] c"------------------- Best Fit: Edge Case (First) -------------------\0D\0A\00"
@.str.2 = [69 x i8] c"------------------- Best Fit: Edge Case (Last) -------------------\0D\0A\00"
define void @simpleBestFitTesting() {
%1 = alloca [128 x i8]
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = call i32 @my_mallopt(i32 2)
%9 = call i32 @puts(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0))
%10 = call i8* @my_malloc(i32 100)
store i8* %10, i8** %2
%11 = call i8* @my_malloc(i32 20)
store i8* %11, i8** %3
%12 = call i8* @my_malloc(i32 100)
store i8* %12, i8** %4
%13 = call i8* @my_malloc(i32 15)
store i8* %13, i8** %5
%14 = call i8* @my_malloc(i32 100)
store i8* %14, i8** %6
%15 = call i32 (...) @my_mallinfo()
%16 = load i8*, i8** %3
%17 = call i32 @my_free(i8* %16)
%18 = load i8*, i8** %5
%19 = call i32 @my_free(i8* %18)
%20 = call i32 (...) @my_mallinfo()
%21 = call i8* @my_malloc(i32 10)
store i8* %21, i8** %7
%22 = call i32 (...) @my_mallinfo()
%23 = load i8*, i8** %2
%24 = call i32 @my_free(i8* %23)
%25 = load i8*, i8** %4
%26 = call i32 @my_free(i8* %25)
%27 = load i8*, i8** %6
%28 = call i32 @my_free(i8* %27)
%29 = load i8*, i8** %7
%30 = call i32 @my_free(i8* %29)
%31 = call i32 @puts(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.1, i64 0, i64 0))
%32 = call i8* @my_malloc(i32 9)
store i8* %32, i8** %2
%33 = call i8* @my_malloc(i32 20)
store i8* %33, i8** %3
%34 = call i8* @my_malloc(i32 30)
store i8* %34, i8** %4
%35 = call i8* @my_malloc(i32 40)
store i8* %35, i8** %5
%36 = call i8* @my_malloc(i32 10)
store i8* %36, i8** %6
%37 = call i32 (...) @my_mallinfo()
%38 = load i8*, i8** %2
%39 = call i32 @my_free(i8* %38)
%40 = load i8*, i8** %5
%41 = call i32 @my_free(i8* %40)
%42 = load i8*, i8** %6
%43 = call i32 @my_free(i8* %42)
%44 = call i32 (...) @my_mallinfo()
%45 = call i8* @my_malloc(i32 8)
store i8* %45, i8** %7
%46 = call i32 (...) @my_mallinfo()
%47 = load i8*, i8** %3
%48 = call i32 @my_free(i8* %47)
%49 = load i8*, i8** %4
%50 = call i32 @my_free(i8* %49)
%51 = load i8*, i8** %7
%52 = call i32 @my_free(i8* %51)
%53 = call i32 @puts(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.2, i64 0, i64 0))
%54 = call i8* @my_malloc(i32 10)
store i8* %54, i8** %2
%55 = call i8* @my_malloc(i32 20)
store i8* %55, i8** %3
%56 = call i8* @my_malloc(i32 30)
store i8* %56, i8** %4
%57 = call i8* @my_malloc(i32 267)
store i8* %57, i8** %5
%58 = call i8* @my_malloc(i32 8)
store i8* %58, i8** %6
%59 = call i32 (...) @my_mallinfo()
%60 = load i8*, i8** %2
%61 = call i32 @my_free(i8* %60)
%62 = load i8*, i8** %4
%63 = call i32 @my_free(i8* %62)
%64 = load i8*, i8** %6
%65 = call i32 @my_free(i8* %64)
%66 = call i32 (...) @my_mallinfo()
%67 = call i8* @my_malloc(i32 8)
store i8* %67, i8** %7
%68 = call i32 (...) @my_mallinfo()
%69 = load i8*, i8** %3
%70 = call i32 @my_free(i8* %69)
%71 = load i8*, i8** %5
%72 = call i32 @my_free(i8* %71)
%73 = load i8*, i8** %7
%74 = call i32 @my_free(i8* %73)
ret void
}

LLVM IR (-O2):
@.str = [65 x i8] c"------------------- Best Fit: Typical Test -------------------\0D\0A\00"
@.str.1 = [70 x i8] c"------------------- Best Fit: Edge Case (First) -------------------\0D\0A\00"
@.str.2 = [69 x i8] c"------------------- Best Fit: Edge Case (Last) -------------------\0D\0A\00"
define void @simpleBestFitTesting() {
%1 = tail call i32 @my_mallopt(i32 2)
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0))
%3 = tail call i8* @my_malloc(i32 100)
%4 = tail call i8* @my_malloc(i32 20)
%5 = tail call i8* @my_malloc(i32 100)
%6 = tail call i8* @my_malloc(i32 15)
%7 = tail call i8* @my_malloc(i32 100)
%8 = tail call i32 (...) @my_mallinfo()
%9 = tail call i32 @my_free(i8* %4)
%10 = tail call i32 @my_free(i8* %6)
%11 = tail call i32 (...) @my_mallinfo()
%12 = tail call i8* @my_malloc(i32 10)
%13 = tail call i32 (...) @my_mallinfo()
%14 = tail call i32 @my_free(i8* %3)
%15 = tail call i32 @my_free(i8* %5)
%16 = tail call i32 @my_free(i8* %7)
%17 = tail call i32 @my_free(i8* %12)
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([70 x i8], [70 x i8]* @.str.1, i64 0, i64 0))
%19 = tail call i8* @my_malloc(i32 9)
%20 = tail call i8* @my_malloc(i32 20)
%21 = tail call i8* @my_malloc(i32 30)
%22 = tail call i8* @my_malloc(i32 40)
%23 = tail call i8* @my_malloc(i32 10)
%24 = tail call i32 (...) @my_mallinfo()
%25 = tail call i32 @my_free(i8* %19)
%26 = tail call i32 @my_free(i8* %22)
%27 = tail call i32 @my_free(i8* %23)
%28 = tail call i32 (...) @my_mallinfo()
%29 = tail call i8* @my_malloc(i32 8)
%30 = tail call i32 (...) @my_mallinfo()
%31 = tail call i32 @my_free(i8* %20)
%32 = tail call i32 @my_free(i8* %21)
%33 = tail call i32 @my_free(i8* %29)
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([69 x i8], [69 x i8]* @.str.2, i64 0, i64 0))
%35 = tail call i8* @my_malloc(i32 10)
%36 = tail call i8* @my_malloc(i32 20)
%37 = tail call i8* @my_malloc(i32 30)
%38 = tail call i8* @my_malloc(i32 267)
%39 = tail call i8* @my_malloc(i32 8)
%40 = tail call i32 (...) @my_mallinfo()
%41 = tail call i32 @my_free(i8* %35)
%42 = tail call i32 @my_free(i8* %37)
%43 = tail call i32 @my_free(i8* %39)
%44 = tail call i32 (...) @my_mallinfo()
%45 = tail call i8* @my_malloc(i32 8)
%46 = tail call i32 (...) @my_mallinfo()
%47 = tail call i32 @my_free(i8* %36)
%48 = tail call i32 @my_free(i8* %38)
%49 = tail call i32 @my_free(i8* %45)
ret void
}