#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 */
char const *bprintf(char *, float);
int pscanf(char *, char *, long *, long *, long *, long *, long *);
const char *ram_used(void) {
  long total, free, buffers, cached;
  return (pscanf("/proc/meminfo",
                 "MemTotal: %ld kB\n"
                 "MemFree: %ld kB\n"
                 "MemAvailable: %ld kB\nBuffers: %ld kB\n"
                 "Cached: %ld kB\n",
                 &total, &free, &buffers, &buffers, &cached) == 5)
             ? bprintf("%f",
                       (float)(total - free - buffers - cached) / 1024 / 1024)
             : NULL;
}


x86 assembly (clang, -O0):
<ram_used>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xed5(%rip),%rdi
lea    0xedc(%rip),%rsi
lea    -0x8(%rbp),%rdx
lea    -0x10(%rbp),%rcx
lea    -0x18(%rbp),%r9
lea    -0x20(%rbp),%rax
mov    %r9,%r8
mov    %rax,(%rsp)
call   1040 <pscanf@plt>
cmp    $0x5,%eax
jne    119d <ram_used+0x7d>
mov    -0x8(%rbp),%rax
sub    -0x10(%rbp),%rax
sub    -0x18(%rbp),%rax
sub    -0x20(%rbp),%rax
cvtsi2ss %rax,%xmm0
movss  0xe88(%rip),%xmm1
divss  %xmm1,%xmm0
movss  0xe7c(%rip),%xmm1
divss  %xmm1,%xmm0
lea    0xed9(%rip),%rdi
call   1030 <bprintf@plt>
mov    %rax,-0x28(%rbp)
jmp    11a8 <ram_used+0x88>
xor    %eax,%eax
mov    %rax,-0x28(%rbp)
jmp    11a8 <ram_used+0x88>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ram_used>:
sub    $0x28,%rsp
lea    0x8(%rsp),%rax
mov    %rax,(%rsp)
lea    0xed0(%rip),%rdi
lea    0xed7(%rip),%rsi
lea    0x20(%rsp),%rdx
lea    0x18(%rsp),%rcx
lea    0x10(%rsp),%r8
mov    %r8,%r9
call   1040 <pscanf@plt>
cmp    $0x5,%eax
jne    1194 <ram_used+0x74>
mov    0x20(%rsp),%rax
mov    0x18(%rsp),%rcx
add    0x10(%rsp),%rcx
add    0x8(%rsp),%rcx
sub    %rcx,%rax
cvtsi2ss %rax,%xmm0
movss  0xe85(%rip),%xmm1
mulss  %xmm1,%xmm0
mulss  %xmm1,%xmm0
lea    0xede(%rip),%rdi
call   1030 <bprintf@plt>
add    $0x28,%rsp
ret
xor    %eax,%eax
add    $0x28,%rsp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/meminfo\00"
@.str.1 = [86 x i8] c"MemTotal: %ld kB\0AMemFree: %ld kB\0AMemAvailable: %ld kB\0ABuffers: %ld kB\0ACached: %ld kB\0A\00"
@.str.2 = [3 x i8] c"%f\00"
define i8* @ram_used() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = call i32 @pscanf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str.1, i64 0, i64 0), i64* %1, i64* %2, i64* %3, i64* %3, i64* %4)
%6 = icmp eq i32 %5, 5
br i1 %6, label %7, label %19
7: ; preds = %0
%8 = load i64, i64* %1
%9 = load i64, i64* %2
%10 = sub nsw i64 %8, %9
%11 = load i64, i64* %3
%12 = sub nsw i64 %10, %11
%13 = load i64, i64* %4
%14 = sub nsw i64 %12, %13
%15 = sitofp i64 %14 to float
%16 = fdiv float %15, 1.024000e+03
%17 = fdiv float %16, 1.024000e+03
%18 = call i8* @bprintf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float %17)
br label %20
19: ; preds = %0
br label %20
20: ; preds = %19, %7
%21 = phi i8* [ %18, %7 ], [ null, %19 ]
ret i8* %21
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/meminfo\00"
@.str.1 = [86 x i8] c"MemTotal: %ld kB\0AMemFree: %ld kB\0AMemAvailable: %ld kB\0ABuffers: %ld kB\0ACached: %ld kB\0A\00"
@.str.2 = [3 x i8] c"%f\00"
define i8* @ram_used() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = bitcast i64* %1 to i8*
%6 = bitcast i64* %2 to i8*
%7 = bitcast i64* %3 to i8*
%8 = bitcast i64* %4 to i8*
%9 = call i32 @pscanf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str.1, i64 0, i64 0), i64* %1, i64* %2, i64* %3, i64* %3, i64* %4)
%10 = icmp eq i32 %9, 5
br i1 %10, label %11, label %23
11: ; preds = %0
%12 = load i64, i64* %1
%13 = load i64, i64* %2
%14 = load i64, i64* %3
%15 = load i64, i64* %4
%16 = add i64 %13, %14
%17 = add i64 %16, %15
%18 = sub i64 %12, %17
%19 = sitofp i64 %18 to float
%20 = fmul float %19, 0x3F50000000000000
%21 = fmul float %20, 0x3F50000000000000
%22 = call i8* @bprintf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float %21)
br label %23
23: ; preds = %0, %11
%24 = phi i8* [ %22, %11 ], [ null, %0 ]
ret i8* %24
}