#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 fragmentation_level(int const *);
int total_block_size(int const *, int /*<<< orphan*/);
float percent_unoccupied(const int *mem) {
  int frag_val = fragmentation_level(mem);
  int free_block_size = total_block_size(mem, 0);
  int avg_alloc_size = average_block_size(mem, 1);
  float result =
      (100.0 * (1.0 - ((frag_val * avg_alloc_size) / (float)free_block_size)));
  return result;
}


x86 assembly (clang, -O0):
<percent_unoccupied>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <fragmentation_level@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1050 <total_block_size@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   1040 <average_block_size@plt>
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
imul   -0x14(%rbp),%eax
cvtsi2ss %eax,%xmm0
cvtsi2ssl -0x10(%rbp),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe81(%rip),%xmm1
subsd  %xmm0,%xmm1
movsd  0xe6d(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<percent_unoccupied>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1030 <fragmentation_level@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <total_block_size@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    $0x1,%esi
call   1040 <average_block_size@plt>
imul   %r14d,%eax
cvtsi2ss %eax,%xmm0
cvtsi2ss %ebp,%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe8c(%rip),%xmm1
subsd  %xmm0,%xmm1
mulsd  0xe88(%rip),%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define float @percent_unoccupied(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca float
store i32* %0, i32** %2
%7 = load i32*, i32** %2
%8 = call i32 @fragmentation_level(i32* %7)
store i32 %8, i32* %3
%9 = load i32*, i32** %2
%10 = call i32 @total_block_size(i32* %9, i32 0)
store i32 %10, i32* %4
%11 = load i32*, i32** %2
%12 = call i32 @average_block_size(i32* %11, i32 1)
store i32 %12, i32* %5
%13 = load i32, i32* %3
%14 = load i32, i32* %5
%15 = mul nsw i32 %13, %14
%16 = sitofp i32 %15 to float
%17 = load i32, i32* %4
%18 = sitofp i32 %17 to float
%19 = fdiv float %16, %18
%20 = fpext float %19 to double
%21 = fsub double 1.000000e+00, %20
%22 = fmul double 1.000000e+02, %21
%23 = fptrunc double %22 to float
store float %23, float* %6
%24 = load float, float* %6
ret float %24
}

LLVM IR (-O2):
define float @percent_unoccupied(i32* %0) {
%2 = tail call i32 @fragmentation_level(i32* %0)
%3 = tail call i32 @total_block_size(i32* %0, i32 0)
%4 = tail call i32 @average_block_size(i32* %0, i32 1)
%5 = mul nsw i32 %4, %2
%6 = sitofp i32 %5 to float
%7 = sitofp i32 %3 to float
%8 = fdiv float %6, %7
%9 = fpext float %8 to double
%10 = fsub double 1.000000e+00, %9
%11 = fmul double %10, 1.000000e+02
%12 = fptrunc double %11 to float
ret float %12
}