#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 */
unsigned long long getPhysMemoryBytes();
unsigned long long pagesize();
unsigned long long vmstat_free_count();
unsigned long long vmstat_inactive_count();
double total_minus_free_over_total() {
  unsigned long long free_count = vmstat_free_count();
  unsigned long long inactive_count = vmstat_inactive_count();
  unsigned long long bytesFree = (free_count + inactive_count) * pagesize();
  unsigned long long bytesTotal = getPhysMemoryBytes();
  double used = (double)(bytesTotal - bytesFree) / (double)bytesTotal;
  return (used * 100.0);
}


x86 assembly (clang, -O0):
<total_minus_free_over_total>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
xor    %eax,%eax
mov    %al,-0x29(%rbp)
call   1030 <vmstat_free_count@plt>
mov    %rax,%rcx
mov    -0x29(%rbp),%al
mov    %rcx,-0x8(%rbp)
call   1050 <vmstat_inactive_count@plt>
mov    %rax,%rcx
mov    -0x29(%rbp),%al
mov    %rcx,-0x10(%rbp)
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%rdx
add    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
call   1060 <pagesize@plt>
mov    -0x38(%rbp),%rcx
mov    %rax,%rdx
mov    -0x29(%rbp),%al
imul   %rdx,%rcx
mov    %rcx,-0x18(%rbp)
call   1040 <getPhysMemoryBytes@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rdx
mov    %rax,%rcx
sub    %rdx,%rcx
movq   %rcx,%xmm0
movaps 0xe5c(%rip),%xmm3
punpckldq %xmm3,%xmm0
movapd 0xe60(%rip),%xmm2
subpd  %xmm2,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movq   %rax,%xmm1
punpckldq %xmm3,%xmm1
subpd  %xmm2,%xmm1
movaps %xmm1,%xmm2
unpckhpd %xmm1,%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe08(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<total_minus_free_over_total>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <vmstat_free_count@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1050 <vmstat_inactive_count@plt>
mov    %rax,%rbx
add    %r14,%rbx
xor    %eax,%eax
call   1060 <pagesize@plt>
mov    %rax,%r14
imul   %rbx,%r14
xor    %eax,%eax
call   1040 <getPhysMemoryBytes@plt>
movq   %rax,%xmm1
sub    %r14,%rax
movq   %rax,%xmm2
movdqa 0xe7b(%rip),%xmm3
punpckldq %xmm3,%xmm2
movapd 0xe7f(%rip),%xmm4
subpd  %xmm4,%xmm2
movapd %xmm2,%xmm0
unpckhpd %xmm2,%xmm0
addsd  %xmm2,%xmm0
punpckldq %xmm3,%xmm1
subpd  %xmm4,%xmm1
movapd %xmm1,%xmm2
unpckhpd %xmm1,%xmm2
addsd  %xmm1,%xmm2
divsd  %xmm2,%xmm0
mulsd  0xe5f(%rip),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define double @total_minus_free_over_total() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca double
%6 = call i64 (...) @vmstat_free_count()
store i64 %6, i64* %1
%7 = call i64 (...) @vmstat_inactive_count()
store i64 %7, i64* %2
%8 = load i64, i64* %1
%9 = load i64, i64* %2
%10 = add i64 %8, %9
%11 = call i64 (...) @pagesize()
%12 = mul i64 %10, %11
store i64 %12, i64* %3
%13 = call i64 (...) @getPhysMemoryBytes()
store i64 %13, i64* %4
%14 = load i64, i64* %4
%15 = load i64, i64* %3
%16 = sub i64 %14, %15
%17 = uitofp i64 %16 to double
%18 = load i64, i64* %4
%19 = uitofp i64 %18 to double
%20 = fdiv double %17, %19
store double %20, double* %5
%21 = load double, double* %5
%22 = fmul double %21, 1.000000e+02
ret double %22
}

LLVM IR (-O2):
define double @total_minus_free_over_total() {
%1 = tail call i64 (...) @vmstat_free_count()
%2 = tail call i64 (...) @vmstat_inactive_count()
%3 = add i64 %2, %1
%4 = tail call i64 (...) @pagesize()
%5 = mul i64 %3, %4
%6 = tail call i64 (...) @getPhysMemoryBytes()
%7 = sub i64 %6, %5
%8 = uitofp i64 %7 to double
%9 = uitofp i64 %6 to double
%10 = fdiv double %8, %9
%11 = fmul double %10, 1.000000e+02
ret double %11
}