#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 *, int);
int pscanf(char *, char *, long *, long *, long *, long *, long *);
const char *ram_perc(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("%d",
                       100 * ((total - free) - (buffers + cached)) / total)
             : NULL;
}


x86 assembly (clang, -O0):
<ram_perc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xed1(%rip),%rdi
lea    0xed8(%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    118f <ram_perc+0x6f>
mov    -0x8(%rbp),%rax
sub    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
add    -0x20(%rbp),%rcx
sub    %rcx,%rax
imul   $0x64,%rax,%rax
cqto
idivq  -0x8(%rbp)
mov    %eax,%esi
lea    0xee3(%rip),%rdi
call   1030 <bprintf@plt>
mov    %rax,-0x28(%rbp)
jmp    119a <ram_perc+0x7a>
xor    %eax,%eax
mov    %rax,-0x28(%rbp)
jmp    119a <ram_perc+0x7a>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ram_perc>:
sub    $0x28,%rsp
lea    0x8(%rsp),%rax
mov    %rax,(%rsp)
lea    0xecc(%rip),%rdi
lea    0xed3(%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    1188 <ram_perc+0x68>
mov    0x20(%rsp),%rcx
mov    0x18(%rsp),%rax
add    0x10(%rsp),%rax
add    0x8(%rsp),%rax
mov    %rcx,%rdx
sub    %rax,%rdx
imul   $0x64,%rdx,%rax
mov    %rax,%rdx
or     %rcx,%rdx
shr    $0x20,%rdx
je     118f <ram_perc+0x6f>
cqto
idiv   %rcx
jmp    1193 <ram_perc+0x73>
xor    %eax,%eax
add    $0x28,%rsp
ret
xor    %edx,%edx
div    %ecx
lea    0xeca(%rip),%rdi
mov    %eax,%esi
call   1030 <bprintf@plt>
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"%d\00"
define i8* @ram_perc() {
%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 %20
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 = load i64, i64* %4
%13 = add nsw i64 %11, %12
%14 = sub nsw i64 %10, %13
%15 = mul nsw i64 100, %14
%16 = load i64, i64* %1
%17 = sdiv i64 %15, %16
%18 = trunc i64 %17 to i32
%19 = call i8* @bprintf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %18)
br label %21
20: ; preds = %0
br label %21
21: ; preds = %20, %7
%22 = phi i8* [ %19, %7 ], [ null, %20 ]
ret i8* %22
}

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"%d\00"
define i8* @ram_perc() {
%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 = mul nsw i64 %18, 100
%20 = sdiv i64 %19, %12
%21 = trunc i64 %20 to i32
%22 = call i8* @bprintf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %0, %11
%24 = phi i8* [ %22, %11 ], [ null, %0 ]
ret i8* %24
}