unsigned long buffer_size(void) {
  unsigned long total = 0, free = 0;
  int error = get_system_ram(&total, &free);
  if (error)
    return 0;
  unsigned long use = (unsigned long)((float)free * 0.70);
  printf("%s: %luMB total, %luMB free\n -> Use %luMB.\n", __func__,
         byte_to_mb(total), byte_to_mb(free), byte_to_mb(use));
  return use;
}


x86 assembly (clang, -O0):
<buffer_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1050 <get_system_ram@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1171 <buffer_size+0x41>
movq   $0x0,-0x8(%rbp)
jmp    123a <buffer_size+0x10a>
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x30(%rbp)
test   %rax,%rax
movss  %xmm0,-0x2c(%rbp)
js     11ae <buffer_size+0x7e>
movss  -0x30(%rbp),%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  -0x2c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe41(%rip),%xmm1
mulsd  %xmm1,%xmm0
movaps %xmm0,%xmm1
cvttsd2si %xmm1,%rax
mov    %rax,%rdx
sar    $0x3f,%rdx
movsd  0xe2e(%rip),%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rcx
and    %rdx,%rcx
or     %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x0,%al
call   1030 <byte_to_mb@plt>
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x0,%al
call   1030 <byte_to_mb@plt>
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x0,%al
call   1030 <byte_to_mb@plt>
mov    -0x38(%rbp),%edx
mov    -0x34(%rbp),%ecx
mov    %eax,%r8d
lea    0xdec(%rip),%rdi
lea    0xe11(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buffer_size>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
movq   $0x0,0x8(%rsp)
movq   $0x0,(%rsp)
xor    %ebx,%ebx
lea    0x8(%rsp),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1050 <get_system_ram@plt>
test   %eax,%eax
jne    11f5 <buffer_size+0xc5>
mov    (%rsp),%rax
test   %rax,%rax
js     1172 <buffer_size+0x42>
cvtsi2ss %rax,%xmm0
jmp    1187 <buffer_size+0x57>
mov    %rax,%rcx
shr    %rcx
and    $0x1,%eax
or     %rcx,%rax
cvtsi2ss %rax,%xmm0
addss  %xmm0,%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  0xe6d(%rip),%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,%rcx
subsd  0xe65(%rip),%xmm0
cvttsd2si %xmm0,%rbx
sar    $0x3f,%rcx
and    %rcx,%rbx
or     %rax,%rbx
mov    0x8(%rsp),%rdi
xor    %eax,%eax
call   1030 <byte_to_mb@plt>
mov    %eax,%r14d
mov    (%rsp),%rdi
xor    %eax,%eax
call   1030 <byte_to_mb@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <byte_to_mb@plt>
lea    0xe31(%rip),%rdi
lea    0xe56(%rip),%rsi
mov    %r14d,%edx
mov    %ebp,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [44 x i8] c"%s: %luMB total, %luMB free\0A -> Use %luMB.\0A\00"
@__func__.buffer_size = [12 x i8] c"buffer_size\00"
define i64 @buffer_size() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i64
%4 = alloca i32
%5 = alloca i64
store i64 0, i64* %2
store i64 0, i64* %3
%6 = call i32 (i64*, i64*, ...) bitcast (i32 (...)* @get_system_ram to i32 (i64*, i64*, ...)*)(i64* %2, i64* %3)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %0
store i64 0, i64* %1
br label %24
10: ; preds = %0
%11 = load i64, i64* %3
%12 = uitofp i64 %11 to float
%13 = fpext float %12 to double
%14 = fmul double %13, 0x3FE6666666666666
%15 = fptoui double %14 to i64
store i64 %15, i64* %5
%16 = load i64, i64* %2
%17 = call i32 (i64, ...) bitcast (i32 (...)* @byte_to_mb to i32 (i64, ...)*)(i64 %16)
%18 = load i64, i64* %3
%19 = call i32 (i64, ...) bitcast (i32 (...)* @byte_to_mb to i32 (i64, ...)*)(i64 %18)
%20 = load i64, i64* %5
%21 = call i32 (i64, ...) bitcast (i32 (...)* @byte_to_mb to i32 (i64, ...)*)(i64 %20)
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @__func__.buffer_size, i64 0, i64 0), i32 %17, i32 %19, i32 %21)
%23 = load i64, i64* %5
store i64 %23, i64* %1
br label %24
24: ; preds = %10, %9
%25 = load i64, i64* %1
ret i64 %25
}

LLVM IR (-O2):
@.str = [44 x i8] c"%s: %luMB total, %luMB free\0A -> Use %luMB.\0A\00"
@__func__.buffer_size = [12 x i8] c"buffer_size\00"
define i64 @buffer_size() {
%1 = alloca i64
%2 = alloca i64
%3 = bitcast i64* %1 to i8*
store i64 0, i64* %1
%4 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%5 = call i32 (i64*, i64*, ...) bitcast (i32 (...)* @get_system_ram to i32 (i64*, i64*, ...)*)(i64* %1, i64* %2)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %19
7: ; preds = %0
%8 = load i64, i64* %2
%9 = uitofp i64 %8 to float
%10 = fpext float %9 to double
%11 = fmul double %10, 0x3FE6666666666666
%12 = fptoui double %11 to i64
%13 = load i64, i64* %1
%14 = call i32 (i64, ...) bitcast (i32 (...)* @byte_to_mb to i32 (i64, ...)*)(i64 %13)
%15 = load i64, i64* %2
%16 = call i32 (i64, ...) bitcast (i32 (...)* @byte_to_mb to i32 (i64, ...)*)(i64 %15)
%17 = call i32 (i64, ...) bitcast (i32 (...)* @byte_to_mb to i32 (i64, ...)*)(i64 %12)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @__func__.buffer_size, i64 0, i64 0), i32 %14, i32 %16, i32 %17)
br label %19
19: ; preds = %0, %7
%20 = phi i64 [ %12, %7 ], [ 0, %0 ]
ret i64 %20
}