#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 */
typedef scalar_t__ clock_t;

/* Variables and functions */
int /*<<< orphan*/ al_free(int *);
scalar_t__ al_malloc(int);
int /*<<< orphan*/ allocator_destroy();
int /*<<< orphan*/ allocator_init();
scalar_t__ clock();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, scalar_t__);
int /*<<< orphan*/ free(int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  int *arr[(10000)];
  int i, counter;
  clock_t beg, end;
  allocator_init();
  counter = 0;
  beg = clock();
  while (counter++ < (500)) {
    for (i = 0; i < (10000); ++i)
      arr[i] = (int *)malloc(sizeof(int));
    for (i = 0; i < (10000); ++i)
      free(arr[i]);
  }
  end = clock();
  fprintf(stdout, "default use : %lu\n", end - beg);
  counter = 0;
  beg = clock();
  while (counter++ < (500)) {
    for (i = 0; i < (10000); ++i)
      arr[i] = (int *)al_malloc(sizeof(int));
    for (i = 0; i < (10000); ++i)
      al_free(arr[i]);
  }
  end = clock();
  fprintf(stdout, "allocator use : %lu\n", end - beg);
  allocator_destroy();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x138b0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1090 <allocator_init@plt>
movl   $0x0,-0x13898(%rbp)
mov    $0x0,%al
call   1050 <clock@plt>
mov    %rax,-0x138a0(%rbp)
mov    -0x13898(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x13898(%rbp)
cmp    $0x1f4,%eax
jge    1265 <main+0xe5>
movl   $0x0,-0x13894(%rbp)
cmpl   $0x2710,-0x13894(%rbp)
jge    121e <main+0x9e>
mov    $0x4,%edi
call   1080 <malloc@plt>
mov    %rax,%rcx
movslq -0x13894(%rbp),%rax
mov    %rcx,-0x13890(%rbp,%rax,8)
ff
mov    -0x13894(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x13894(%rbp)
jmp    11de <main+0x5e>
movl   $0x0,-0x13894(%rbp)
cmpl   $0x2710,-0x13894(%rbp)
jge    1260 <main+0xe0>
movslq -0x13894(%rbp),%rax
mov    -0x13890(%rbp,%rax,8),%rdi
ff
call   1030 <free@plt>
mov    -0x13894(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x13894(%rbp)
jmp    1228 <main+0xa8>
jmp    11b8 <main+0x38>
mov    $0x0,%al
call   1050 <clock@plt>
mov    %rax,-0x138a8(%rbp)
mov    0x2d66(%rip),%rax
mov    (%rax),%edi
mov    -0x138a8(%rbp),%rdx
sub    -0x138a0(%rbp),%rdx
lea    0xd6f(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x0,-0x13898(%rbp)
mov    $0x0,%al
call   1050 <clock@plt>
mov    %rax,-0x138a0(%rbp)
mov    -0x13898(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x13898(%rbp)
cmp    $0x1f4,%eax
jge    135b <main+0x1db>
movl   $0x0,-0x13894(%rbp)
cmpl   $0x2710,-0x13894(%rbp)
jge    1314 <main+0x194>
mov    $0x4,%edi
call   10a0 <al_malloc@plt>
mov    %rax,%rcx
movslq -0x13894(%rbp),%rax
mov    %rcx,-0x13890(%rbp,%rax,8)
ff
mov    -0x13894(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x13894(%rbp)
jmp    12d4 <main+0x154>
movl   $0x0,-0x13894(%rbp)
cmpl   $0x2710,-0x13894(%rbp)
jge    1356 <main+0x1d6>
movslq -0x13894(%rbp),%rax
mov    -0x13890(%rbp,%rax,8),%rdi
ff
call   1060 <al_free@plt>
mov    -0x13894(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x13894(%rbp)
jmp    131e <main+0x19e>
jmp    12ae <main+0x12e>
mov    $0x0,%al
call   1050 <clock@plt>
mov    %rax,-0x138a8(%rbp)
mov    0x2c70(%rip),%rax
mov    (%rax),%edi
mov    -0x138a8(%rbp),%rdx
sub    -0x138a0(%rbp),%rdx
lea    0xc8c(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x0,%al
call   1040 <allocator_destroy@plt>
xor    %eax,%eax
add    $0x138b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x13888,%rsp
xor    %eax,%eax
call   1090 <allocator_init@plt>
xor    %eax,%eax
call   1050 <clock@plt>
mov    %rax,%r15
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x4,%edi
call   1080 <malloc@plt>
mov    %rax,(%rsp,%rbx,8)
add    $0x1,%rbx
cmp    $0x2710,%rbx
jne    11c0 <main+0x40>
xor    %ebx,%ebx
nopl   (%rax)
mov    (%rsp,%rbx,8),%rdi
call   1030 <free@plt>
add    $0x1,%rbx
cmp    $0x2710,%rbx
jne    11e0 <main+0x60>
add    $0x1,%ebp
cmp    $0x1f5,%ebp
jne    11b0 <main+0x30>
xor    %eax,%eax
call   1050 <clock@plt>
mov    0x2dd1(%rip),%r14
mov    (%r14),%edi
sub    %r15,%rax
lea    0xde4(%rip),%rsi
mov    %rax,%rdx
call   1070 <fprintf@plt>
xor    %eax,%eax
call   1050 <clock@plt>
mov    %rax,%r15
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x4,%edi
call   10a0 <al_malloc@plt>
mov    %rax,(%rsp,%rbx,8)
add    $0x1,%rbx
cmp    $0x2710,%rbx
jne    1250 <main+0xd0>
xor    %ebx,%ebx
nopl   (%rax)
mov    (%rsp,%rbx,8),%rdi
call   1060 <al_free@plt>
add    $0x1,%rbx
cmp    $0x2710,%rbx
jne    1270 <main+0xf0>
add    $0x1,%ebp
cmp    $0x1f5,%ebp
jne    1240 <main+0xc0>
xor    %eax,%eax
call   1050 <clock@plt>
mov    (%r14),%edi
sub    %r15,%rax
lea    0xd6e(%rip),%rsi
mov    %rax,%rdx
call   1070 <fprintf@plt>
xor    %eax,%eax
call   1040 <allocator_destroy@plt>
xor    %eax,%eax
add    $0x13888,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [19 x i8] c"default use : %lu\0A\00"
@.str.1 = [21 x i8] c"allocator use : %lu\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [10000 x i32*]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i32 (...) @allocator_init()
store i32 0, i32* %8
%12 = call i64 (...) @clock()
store i64 %12, i64* %9
br label %13
13: ; preds = %43, %2
%14 = load i32, i32* %8
%15 = add nsw i32 %14, 1
store i32 %15, i32* %8
%16 = icmp slt i32 %14, 500
br i1 %16, label %17, label %44
17: ; preds = %13
store i32 0, i32* %7
br label %18
18: ; preds = %27, %17
%19 = load i32, i32* %7
%20 = icmp slt i32 %19, 10000
br i1 %20, label %21, label %30
21: ; preds = %18
%22 = call i64 @malloc(i32 4)
%23 = inttoptr i64 %22 to i32*
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [10000 x i32*], [10000 x i32*]* %6, i64 0, i64 %25
store i32* %23, i32** %26
br label %27
27: ; preds = %21
%28 = load i32, i32* %7
%29 = add nsw i32 %28, 1
store i32 %29, i32* %7
br label %18
30: ; preds = %18
store i32 0, i32* %7
br label %31
31: ; preds = %40, %30
%32 = load i32, i32* %7
%33 = icmp slt i32 %32, 10000
br i1 %33, label %34, label %43
34: ; preds = %31
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [10000 x i32*], [10000 x i32*]* %6, i64 0, i64 %36
%38 = load i32*, i32** %37
%39 = call i32 @free(i32* %38)
br label %40
40: ; preds = %34
%41 = load i32, i32* %7
%42 = add nsw i32 %41, 1
store i32 %42, i32* %7
br label %31
43: ; preds = %31
br label %13
44: ; preds = %13
%45 = call i64 (...) @clock()
store i64 %45, i64* %10
%46 = load i32, i32* @stdout
%47 = load i64, i64* %10
%48 = load i64, i64* %9
%49 = sub nsw i64 %47, %48
%50 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i64 %49)
store i32 0, i32* %8
%51 = call i64 (...) @clock()
store i64 %51, i64* %9
br label %52
52: ; preds = %82, %44
%53 = load i32, i32* %8
%54 = add nsw i32 %53, 1
store i32 %54, i32* %8
%55 = icmp slt i32 %53, 500
br i1 %55, label %56, label %83
56: ; preds = %52
store i32 0, i32* %7
br label %57
57: ; preds = %66, %56
%58 = load i32, i32* %7
%59 = icmp slt i32 %58, 10000
br i1 %59, label %60, label %69
60: ; preds = %57
%61 = call i64 @al_malloc(i32 4)
%62 = inttoptr i64 %61 to i32*
%63 = load i32, i32* %7
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [10000 x i32*], [10000 x i32*]* %6, i64 0, i64 %64
store i32* %62, i32** %65
br label %66
66: ; preds = %60
%67 = load i32, i32* %7
%68 = add nsw i32 %67, 1
store i32 %68, i32* %7
br label %57
69: ; preds = %57
store i32 0, i32* %7
br label %70
70: ; preds = %79, %69
%71 = load i32, i32* %7
%72 = icmp slt i32 %71, 10000
br i1 %72, label %73, label %82
73: ; preds = %70
%74 = load i32, i32* %7
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds [10000 x i32*], [10000 x i32*]* %6, i64 0, i64 %75
%77 = load i32*, i32** %76
%78 = call i32 @al_free(i32* %77)
br label %79
79: ; preds = %73
%80 = load i32, i32* %7
%81 = add nsw i32 %80, 1
store i32 %81, i32* %7
br label %70
82: ; preds = %70
br label %52
83: ; preds = %52
%84 = call i64 (...) @clock()
store i64 %84, i64* %10
%85 = load i32, i32* @stdout
%86 = load i64, i64* %10
%87 = load i64, i64* %9
%88 = sub nsw i64 %86, %87
%89 = call i32 @fprintf(i32 %85, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i64 %88)
%90 = call i32 (...) @allocator_destroy()
ret i32 0
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [19 x i8] c"default use : %lu\0A\00"
@.str.1 = [21 x i8] c"allocator use : %lu\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [10000 x i32*]
%4 = bitcast [10000 x i32*]* %3 to i8*
%5 = tail call i32 (...) @allocator_init()
%6 = tail call i64 (...) @clock()
br label %10
7: ; preds = %19
%8 = add nuw nsw i32 %11, 1
%9 = icmp eq i32 %8, 501
br i1 %9, label %26, label %10
10: ; preds = %2, %7
%11 = phi i32 [ 1, %2 ], [ %8, %7 ]
br label %12
12: ; preds = %10, %12
%13 = phi i64 [ 0, %10 ], [ %17, %12 ]
%14 = tail call i64 @malloc(i32 4)
%15 = inttoptr i64 %14 to i32*
%16 = getelementptr inbounds [10000 x i32*], [10000 x i32*]* %3, i64 0, i64 %13
store i32* %15, i32** %16
%17 = add nuw nsw i64 %13, 1
%18 = icmp eq i64 %17, 10000
br i1 %18, label %19, label %12
19: ; preds = %12, %19
%20 = phi i64 [ %24, %19 ], [ 0, %12 ]
%21 = getelementptr inbounds [10000 x i32*], [10000 x i32*]* %3, i64 0, i64 %20
%22 = load i32*, i32** %21
%23 = tail call i32 @free(i32* %22)
%24 = add nuw nsw i64 %20, 1
%25 = icmp eq i64 %24, 10000
br i1 %25, label %7, label %19
26: ; preds = %7
%27 = tail call i64 (...) @clock()
%28 = load i32, i32* @stdout
%29 = sub nsw i64 %27, %6
%30 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i64 %29)
%31 = tail call i64 (...) @clock()
br label %35
32: ; preds = %44
%33 = add nuw nsw i32 %36, 1
%34 = icmp eq i32 %33, 501
br i1 %34, label %51, label %35
35: ; preds = %26, %32
%36 = phi i32 [ 1, %26 ], [ %33, %32 ]
br label %37
37: ; preds = %35, %37
%38 = phi i64 [ 0, %35 ], [ %42, %37 ]
%39 = tail call i64 @al_malloc(i32 4)
%40 = inttoptr i64 %39 to i32*
%41 = getelementptr inbounds [10000 x i32*], [10000 x i32*]* %3, i64 0, i64 %38
store i32* %40, i32** %41
%42 = add nuw nsw i64 %38, 1
%43 = icmp eq i64 %42, 10000
br i1 %43, label %44, label %37
44: ; preds = %37, %44
%45 = phi i64 [ %49, %44 ], [ 0, %37 ]
%46 = getelementptr inbounds [10000 x i32*], [10000 x i32*]* %3, i64 0, i64 %45
%47 = load i32*, i32** %46
%48 = tail call i32 @al_free(i32* %47)
%49 = add nuw nsw i64 %45, 1
%50 = icmp eq i64 %49, 10000
br i1 %50, label %32, label %44
51: ; preds = %32
%52 = tail call i64 (...) @clock()
%53 = load i32, i32* @stdout
%54 = sub nsw i64 %52, %31
%55 = tail call i32 @fprintf(i32 %53, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i64 %54)
%56 = tail call i32 (...) @allocator_destroy()
ret i32 0
}