#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 average_block_size(int const *, int);
int count_blocks(int const *, int);
int fragmentation_level(int const *);
double percent_unoccupied(int const *);
int /*<<< orphan*/ printf(char *, ...);
int total_block_size(int const *, int);
void print_statistics(const int *mem, int simulated_time, int nallocs,
                      int ndeallocs) {
  printf("\n\t======== SIMULATION STATISTICS ========\n");
  printf("Simulated Time >> %d units\n", simulated_time);
  printf("Total Number of Allocations: %d\n", nallocs);
  printf("Total Number of Deallocations: %d\n", ndeallocs);
  printf("Number of Blocks: Allocated %d >> Free %d\n", count_blocks(mem, 1),
         count_blocks(mem, 0));
  printf("Total Size: Allocated %d >> Free %d\n", total_block_size(mem, 1),
         total_block_size(mem, 0));
  printf("Average Size: Allocated %d >> Free %d\n", average_block_size(mem, 1),
         average_block_size(mem, 0));
  printf("Fragmentation Level: %d\n", fragmentation_level(mem));
  printf("Percent of Free Memory Unoccupied with Average Allocation Size %d: "
         "%0.2f\n\n",
         average_block_size(mem, 1), percent_unoccupied(mem));
  return;
}


x86 assembly (clang, -O0):
<print_statistics>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%esi
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   1070 <count_blocks@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1070 <count_blocks@plt>
mov    -0x24(%rbp),%esi
mov    %eax,%edx
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   1080 <total_block_size@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1080 <total_block_size@plt>
mov    -0x20(%rbp),%esi
mov    %eax,%edx
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   1050 <average_block_size@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1050 <average_block_size@plt>
mov    -0x1c(%rbp),%esi
mov    %eax,%edx
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fragmentation_level@plt>
mov    %eax,%esi
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   1050 <average_block_size@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <percent_unoccupied@plt>
mov    -0x18(%rbp),%esi
lea    0xe9b(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_statistics>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %edx,%r15d
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xfb2(%rip),%rdi
call   1040 <puts@plt>
lea    0xe6b(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe77(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe87(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1080 <count_blocks@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <count_blocks@plt>
lea    0xe80(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1090 <total_block_size@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <total_block_size@plt>
lea    0xe80(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1060 <average_block_size@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <average_block_size@plt>
lea    0xe7a(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <fragmentation_level@plt>
lea    0xe87(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1060 <average_block_size@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1070 <percent_unoccupied@plt>
lea    0xe79(%rip),%rdi
mov    %ebp,%esi
mov    $0x1,%al
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <printf@plt>

LLVM IR (-O0):
@.str = [43 x i8] c"\0A\09======== SIMULATION STATISTICS ========\0A\00"
@.str.1 = [28 x i8] c"Simulated Time >> %d units\0A\00"
@.str.2 = [33 x i8] c"Total Number of Allocations: %d\0A\00"
@.str.3 = [35 x i8] c"Total Number of Deallocations: %d\0A\00"
@.str.4 = [43 x i8] c"Number of Blocks: Allocated %d >> Free %d\0A\00"
@.str.5 = [37 x i8] c"Total Size: Allocated %d >> Free %d\0A\00"
@.str.6 = [39 x i8] c"Average Size: Allocated %d >> Free %d\0A\00"
@.str.7 = [25 x i8] c"Fragmentation Level: %d\0A\00"
@.str.8 = [75 x i8] c"Percent of Free Memory Unoccupied with Average Allocation Size %d: %0.2f\0A\0A\00"
define void @print_statistics(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* %6
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = load i32, i32* %7
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%14 = load i32, i32* %8
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i32 %14)
%16 = load i32*, i32** %5
%17 = call i32 @count_blocks(i32* %16, i32 1)
%18 = load i32*, i32** %5
%19 = call i32 @count_blocks(i32* %18, i32 0)
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i32 %17, i32 %19)
%21 = load i32*, i32** %5
%22 = call i32 @total_block_size(i32* %21, i32 1)
%23 = load i32*, i32** %5
%24 = call i32 @total_block_size(i32* %23, i32 0)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i32 %22, i32 %24)
%26 = load i32*, i32** %5
%27 = call i32 @average_block_size(i32* %26, i32 1)
%28 = load i32*, i32** %5
%29 = call i32 @average_block_size(i32* %28, i32 0)
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0), i32 %27, i32 %29)
%31 = load i32*, i32** %5
%32 = call i32 @fragmentation_level(i32* %31)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i32 %32)
%34 = load i32*, i32** %5
%35 = call i32 @average_block_size(i32* %34, i32 1)
%36 = load i32*, i32** %5
%37 = call double @percent_unoccupied(i32* %36)
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.8, i64 0, i64 0), i32 %35, double %37)
ret void
}

LLVM IR (-O2):
@.str.1 = [28 x i8] c"Simulated Time >> %d units\0A\00"
@.str.2 = [33 x i8] c"Total Number of Allocations: %d\0A\00"
@.str.3 = [35 x i8] c"Total Number of Deallocations: %d\0A\00"
@.str.4 = [43 x i8] c"Number of Blocks: Allocated %d >> Free %d\0A\00"
@.str.5 = [37 x i8] c"Total Size: Allocated %d >> Free %d\0A\00"
@.str.6 = [39 x i8] c"Average Size: Allocated %d >> Free %d\0A\00"
@.str.7 = [25 x i8] c"Fragmentation Level: %d\0A\00"
@.str.8 = [75 x i8] c"Percent of Free Memory Unoccupied with Average Allocation Size %d: %0.2f\0A\0A\00"
@str = [42 x i8] c"\0A\09======== SIMULATION STATISTICS ========\00"
define void @print_statistics(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %1)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %2)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i32 %3)
%9 = tail call i32 @count_blocks(i32* %0, i32 1)
%10 = tail call i32 @count_blocks(i32* %0, i32 0)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i32 %9, i32 %10)
%12 = tail call i32 @total_block_size(i32* %0, i32 1)
%13 = tail call i32 @total_block_size(i32* %0, i32 0)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i32 %12, i32 %13)
%15 = tail call i32 @average_block_size(i32* %0, i32 1)
%16 = tail call i32 @average_block_size(i32* %0, i32 0)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0), i32 %15, i32 %16)
%18 = tail call i32 @fragmentation_level(i32* %0)
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i32 %18)
%20 = tail call i32 @average_block_size(i32* %0, i32 1)
%21 = tail call double @percent_unoccupied(i32* %0)
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([75 x i8], [75 x i8]* @.str.8, i64 0, i64 0), i32 %20, double %21)
ret void
}