#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*/ free(void *);
double get_time();
void *malloc(int);
int /*<<< orphan*/ printf(char *, double);
int main(int argc, char **argv) {
  void *allocated1[5000];
  void *allocated2[5000];
  void *allocated3[5000];
  double start, end;
  int i;
  start = get_time();
  for (i = 0; i < 5000; i++)
    allocated1[i] = malloc(512);
  for (i = 0; i < 5000; i++)
    free(allocated1[i]);
  for (i = 0; i < 5000; i++)
    allocated2[i] = malloc(512);
  for (i = 0; i < 5000; i++)
    free(allocated2[i]);
  for (i = 0; i < 5000; i++)
    allocated3[i] = malloc(512);
  end = get_time();
  printf("time elapsed: %.4lf\n", end - start);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1d4f0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1050 <get_time@plt>
movsd  %xmm0,-0x1d4d8(%rbp)
ff
movl   $0x0,-0x1d4e4(%rbp)
cmpl   $0x1388,-0x1d4e4(%rbp)
jge    11b2 <main+0x72>
mov    $0x200,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
movslq -0x1d4e4(%rbp),%rax
mov    %rcx,-0x9c50(%rbp,%rax,8)
ff
mov    -0x1d4e4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1d4e4(%rbp)
jmp    1172 <main+0x32>
movl   $0x0,-0x1d4e4(%rbp)
cmpl   $0x1388,-0x1d4e4(%rbp)
jge    11f4 <main+0xb4>
movslq -0x1d4e4(%rbp),%rax
mov    -0x9c50(%rbp,%rax,8),%rdi
ff
call   1030 <free@plt>
mov    -0x1d4e4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1d4e4(%rbp)
jmp    11bc <main+0x7c>
movl   $0x0,-0x1d4e4(%rbp)
cmpl   $0x1388,-0x1d4e4(%rbp)
jge    123e <main+0xfe>
mov    $0x200,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
movslq -0x1d4e4(%rbp),%rax
mov    %rcx,-0x13890(%rbp,%rax,8)
ff
mov    -0x1d4e4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1d4e4(%rbp)
jmp    11fe <main+0xbe>
movl   $0x0,-0x1d4e4(%rbp)
cmpl   $0x1388,-0x1d4e4(%rbp)
jge    1280 <main+0x140>
movslq -0x1d4e4(%rbp),%rax
mov    -0x13890(%rbp,%rax,8),%rdi
ff
call   1030 <free@plt>
mov    -0x1d4e4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1d4e4(%rbp)
jmp    1248 <main+0x108>
movl   $0x0,-0x1d4e4(%rbp)
cmpl   $0x1388,-0x1d4e4(%rbp)
jge    12ca <main+0x18a>
mov    $0x200,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
movslq -0x1d4e4(%rbp),%rax
mov    %rcx,-0x1d4d0(%rbp,%rax,8)
ff
mov    -0x1d4e4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1d4e4(%rbp)
jmp    128a <main+0x14a>
mov    $0x0,%al
call   1050 <get_time@plt>
movsd  %xmm0,-0x1d4e0(%rbp)
ff
movsd  -0x1d4e0(%rbp),%xmm0
ff
subsd  -0x1d4d8(%rbp),%xmm0
ff
lea    0xd10(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x1d4f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x13890,%rsp
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <get_time@plt>
movsd  %xmm0,0x8(%rsp)
nopw   0x0(%rax,%rax,1)
mov    $0x200,%edi
call   1060 <malloc@plt>
mov    %rax,0x9c50(%rsp,%rbx,8)
add    $0x1,%rbx
cmp    $0x1388,%rbx
jne    1160 <main+0x20>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x9c50(%rsp,%rbx,8),%rdi
call   1030 <free@plt>
add    $0x1,%rbx
cmp    $0x1388,%rbx
jne    1190 <main+0x50>
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    $0x200,%edi
call   1060 <malloc@plt>
mov    %rax,0x10(%rsp,%rbx,8)
add    $0x1,%rbx
cmp    $0x1388,%rbx
jne    11b0 <main+0x70>
xor    %ebx,%ebx
xchg   %ax,%ax
mov    0x10(%rsp,%rbx,8),%rdi
call   1030 <free@plt>
add    $0x1,%rbx
cmp    $0x1388,%rbx
jne    11d0 <main+0x90>
xor    %eax,%eax
call   1050 <get_time@plt>
subsd  0x8(%rsp),%xmm0
lea    0xe05(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x13890,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [21 x i8] c"time elapsed: %.4lf\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [5000 x i8*]
%7 = alloca [5000 x i8*]
%8 = alloca [5000 x i8*]
%9 = alloca double
%10 = alloca double
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call double (...) @get_time()
store double %12, double* %9
store i32 0, i32* %11
br label %13
13: ; preds = %21, %2
%14 = load i32, i32* %11
%15 = icmp slt i32 %14, 5000
br i1 %15, label %16, label %24
16: ; preds = %13
%17 = call i8* @malloc(i32 512)
%18 = load i32, i32* %11
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [5000 x i8*], [5000 x i8*]* %6, i64 0, i64 %19
store i8* %17, i8** %20
br label %21
21: ; preds = %16
%22 = load i32, i32* %11
%23 = add nsw i32 %22, 1
store i32 %23, i32* %11
br label %13
24: ; preds = %13
store i32 0, i32* %11
br label %25
25: ; preds = %34, %24
%26 = load i32, i32* %11
%27 = icmp slt i32 %26, 5000
br i1 %27, label %28, label %37
28: ; preds = %25
%29 = load i32, i32* %11
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [5000 x i8*], [5000 x i8*]* %6, i64 0, i64 %30
%32 = load i8*, i8** %31
%33 = call i32 @free(i8* %32)
br label %34
34: ; preds = %28
%35 = load i32, i32* %11
%36 = add nsw i32 %35, 1
store i32 %36, i32* %11
br label %25
37: ; preds = %25
store i32 0, i32* %11
br label %38
38: ; preds = %46, %37
%39 = load i32, i32* %11
%40 = icmp slt i32 %39, 5000
br i1 %40, label %41, label %49
41: ; preds = %38
%42 = call i8* @malloc(i32 512)
%43 = load i32, i32* %11
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [5000 x i8*], [5000 x i8*]* %7, i64 0, i64 %44
store i8* %42, i8** %45
br label %46
46: ; preds = %41
%47 = load i32, i32* %11
%48 = add nsw i32 %47, 1
store i32 %48, i32* %11
br label %38
49: ; preds = %38
store i32 0, i32* %11
br label %50
50: ; preds = %59, %49
%51 = load i32, i32* %11
%52 = icmp slt i32 %51, 5000
br i1 %52, label %53, label %62
53: ; preds = %50
%54 = load i32, i32* %11
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [5000 x i8*], [5000 x i8*]* %7, i64 0, i64 %55
%57 = load i8*, i8** %56
%58 = call i32 @free(i8* %57)
br label %59
59: ; preds = %53
%60 = load i32, i32* %11
%61 = add nsw i32 %60, 1
store i32 %61, i32* %11
br label %50
62: ; preds = %50
store i32 0, i32* %11
br label %63
63: ; preds = %71, %62
%64 = load i32, i32* %11
%65 = icmp slt i32 %64, 5000
br i1 %65, label %66, label %74
66: ; preds = %63
%67 = call i8* @malloc(i32 512)
%68 = load i32, i32* %11
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds [5000 x i8*], [5000 x i8*]* %8, i64 0, i64 %69
store i8* %67, i8** %70
br label %71
71: ; preds = %66
%72 = load i32, i32* %11
%73 = add nsw i32 %72, 1
store i32 %73, i32* %11
br label %63
74: ; preds = %63
%75 = call double (...) @get_time()
store double %75, double* %10
%76 = load double, double* %10
%77 = load double, double* %9
%78 = fsub double %76, %77
%79 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), double %78)
ret i32 0
}

LLVM IR (-O2):
@.str = [21 x i8] c"time elapsed: %.4lf\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [5000 x i8*]
%4 = alloca [5000 x i8*]
%5 = bitcast [5000 x i8*]* %3 to i8*
%6 = bitcast [5000 x i8*]* %4 to i8*
%7 = tail call double (...) @get_time()
br label %8
8: ; preds = %2, %8
%9 = phi i64 [ 0, %2 ], [ %12, %8 ]
%10 = tail call dereferenceable_or_null(512) i8* @malloc(i32 512)
%11 = getelementptr inbounds [5000 x i8*], [5000 x i8*]* %3, i64 0, i64 %9
store i8* %10, i8** %11
%12 = add nuw nsw i64 %9, 1
%13 = icmp eq i64 %12, 5000
br i1 %13, label %14, label %8
14: ; preds = %8, %14
%15 = phi i64 [ %19, %14 ], [ 0, %8 ]
%16 = getelementptr inbounds [5000 x i8*], [5000 x i8*]* %3, i64 0, i64 %15
%17 = load i8*, i8** %16
%18 = tail call i32 @free(i8* %17)
%19 = add nuw nsw i64 %15, 1
%20 = icmp eq i64 %19, 5000
br i1 %20, label %21, label %14
21: ; preds = %14, %21
%22 = phi i64 [ %25, %21 ], [ 0, %14 ]
%23 = tail call dereferenceable_or_null(512) i8* @malloc(i32 512)
%24 = getelementptr inbounds [5000 x i8*], [5000 x i8*]* %4, i64 0, i64 %22
store i8* %23, i8** %24
%25 = add nuw nsw i64 %22, 1
%26 = icmp eq i64 %25, 5000
br i1 %26, label %27, label %21
27: ; preds = %21, %27
%28 = phi i64 [ %32, %27 ], [ 0, %21 ]
%29 = getelementptr inbounds [5000 x i8*], [5000 x i8*]* %4, i64 0, i64 %28
%30 = load i8*, i8** %29
%31 = tail call i32 @free(i8* %30)
%32 = add nuw nsw i64 %28, 1
%33 = icmp eq i64 %32, 5000
br i1 %33, label %34, label %27
34: ; preds = %27
%35 = tail call double (...) @get_time()
%36 = fsub double %35, %7
%37 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), double %36)
ret i32 0
}