#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, double, double, double);
int /*<<< orphan*/ sscanf(char *, char *, double *);
scalar_t__ strncmp(char *, char *, int);
int main(void) {
  FILE *fp;
  char line[256];
  double mem_free, buffers, cached = 0.0;
  fp = fopen("/proc/meminfo", "r");
  while (fgets(line, 256, fp)) {
    if (strncmp("MemFree:", line, 8) == 0) {
      sscanf(line + 8, "%*[ ]%lf", &mem_free);
    }
    if (strncmp("Buffers:", line, 8) == 0) {
      sscanf(line + 8, "%*[ ]%lf", &buffers);
    }
    if (strncmp("Cached:", line, 7) == 0) {
      sscanf(line + 7, "%*[ ]%lf", &cached);
    }
  }
  printf("Free Memory:%f Buffers:%f Cached:%f \n", mem_free, buffers, cached);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x128(%rbp)
ff
lea    0xe7c(%rip),%rdi
lea    0xe83(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x100,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1278 <main+0x118>
lea    -0x110(%rbp),%rsi
lea    0xe4f(%rip),%rdi
mov    $0x8,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11f3 <main+0x93>
lea    -0x110(%rbp),%rdi
add    $0x8,%rdi
lea    0xe32(%rip),%rsi
lea    -0x118(%rbp),%rdx
call   1070 <sscanf@plt>
lea    -0x110(%rbp),%rsi
lea    0xe21(%rip),%rdi
mov    $0x8,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1233 <main+0xd3>
lea    -0x110(%rbp),%rdi
add    $0x8,%rdi
lea    0xdf2(%rip),%rsi
lea    -0x120(%rbp),%rdx
call   1070 <sscanf@plt>
lea    -0x110(%rbp),%rsi
lea    0xdea(%rip),%rdi
mov    $0x7,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1273 <main+0x113>
lea    -0x110(%rbp),%rdi
add    $0x7,%rdi
lea    0xdb2(%rip),%rsi
lea    -0x128(%rbp),%rdx
call   1070 <sscanf@plt>
jmp    1194 <main+0x34>
movsd  -0x118(%rbp),%xmm0
ff
movsd  -0x120(%rbp),%xmm1
ff
movsd  -0x128(%rbp),%xmm2
ff
lea    0xd9c(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
movq   $0x0,0x8(%rsp)
lea    0xe7f(%rip),%rdi
lea    0xe86(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
lea    0xe64(%rip),%r13
lea    0xe66(%rip),%rbp
lea    0xe68(%rip),%r12
lea    0xe6a(%rip),%r15
jmp    11e5 <main+0x85>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     125f <main+0xff>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    120c <main+0xac>
lea    0x28(%rsp),%rdi
mov    %rbp,%rsi
lea    0x18(%rsp),%rdx
call   1070 <sscanf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1233 <main+0xd3>
lea    0x28(%rsp),%rdi
mov    %rbp,%rsi
lea    0x10(%rsp),%rdx
call   1070 <sscanf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11d0 <main+0x70>
lea    0x27(%rsp),%rdi
mov    %rbp,%rsi
lea    0x8(%rsp),%rdx
call   1070 <sscanf@plt>
jmp    11d0 <main+0x70>
movsd  0x18(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
movsd  0x8(%rsp),%xmm2
lea    0xdbb(%rip),%rdi
call   1050 <printf@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/meminfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"MemFree:\00"
@.str.3 = [9 x i8] c"%*[ ]%lf\00"
@.str.4 = [9 x i8] c"Buffers:\00"
@.str.5 = [8 x i8] c"Cached:\00"
@.str.6 = [38 x i8] c"Free Memory:%f Buffers:%f Cached:%f \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [256 x i8]
%4 = alloca double
%5 = alloca double
%6 = alloca double
store i32 0, i32* %1
store double 0.000000e+00, double* %6
%7 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %2
br label %8
8: ; preds = %37, %0
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%10 = load i32*, i32** %2
%11 = call i64 @fgets(i8* %9, i32 256, i32* %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %38
13: ; preds = %8
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%15 = call i64 @strncmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %14, i32 8)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%19 = getelementptr inbounds i8, i8* %18, i64 8
%20 = call i32 @sscanf(i8* %19, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), double* %4)
br label %21
21: ; preds = %17, %13
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%23 = call i64 @strncmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %22, i32 8)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %21
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%27 = getelementptr inbounds i8, i8* %26, i64 8
%28 = call i32 @sscanf(i8* %27, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), double* %5)
br label %29
29: ; preds = %25, %21
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%31 = call i64 @strncmp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %30, i32 7)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %29
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%35 = getelementptr inbounds i8, i8* %34, i64 7
%36 = call i32 @sscanf(i8* %35, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), double* %6)
br label %37
37: ; preds = %33, %29
br label %8
38: ; preds = %8
%39 = load double, double* %4
%40 = load double, double* %5
%41 = load double, double* %6
%42 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0), double %39, double %40, double %41)
%43 = load i32*, i32** %2
%44 = call i32 @fclose(i32* %43)
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/meminfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"MemFree:\00"
@.str.3 = [9 x i8] c"%*[ ]%lf\00"
@.str.4 = [9 x i8] c"Buffers:\00"
@.str.5 = [8 x i8] c"Cached:\00"
@.str.6 = [38 x i8] c"Free Memory:%f Buffers:%f Cached:%f \0A\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%6 = bitcast double* %2 to i8*
%7 = bitcast double* %3 to i8*
%8 = bitcast double* %4 to i8*
store double 0.000000e+00, double* %4
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = call i64 @fgets(i8* %5, i32 256, i32* %9)
%11 = icmp ne i64 %10, 0
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 8
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 7
br label %14
14: ; preds = %0, %29
%15 = call i64 @strncmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %5, i32 8)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 @sscanf(i8* %12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), double* %2)
br label %19
19: ; preds = %17, %14
%20 = call i64 @strncmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %5, i32 8)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 @sscanf(i8* %12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), double* %3)
br label %24
24: ; preds = %22, %19
%25 = call i64 @strncmp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %5, i32 7)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = call i32 @sscanf(i8* %13, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), double* %4)
br label %29
29: ; preds = %27, %24
%30 = call i64 @fgets(i8* %5, i32 256, i32* %9)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %14
32: ; preds = %29
%33 = load double, double* %2
%34 = load double, double* %3
%35 = load double, double* %4
%36 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0), double %33, double %34, double %35)
%37 = call i32 @fclose(i32* %9)
ret i32 0
}