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

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ sscanf(char *, char *, char *, char *, char *);
scalar_t__ strcmp(char *, char *);
int getmeminfo(uint64_t *size, uint64_t *free) {
  FILE *f;
  char key[64];
  char val[64];
  char unit[8];
  char buff[1024];
  uint64_t data;
  *size = 0;
  *free = 0;
  f = fopen("/proc/meminfo", "r");
  while (fgets(buff, sizeof(buff), f)) {
    key[0] = 0;
    val[0] = 0;
    unit[0] = 0;
    sscanf(buff, "%s%s%s", key, val, unit);
    if (strcmp("MemTotal:", key) == 0) {
      data = atoi(val);
      if (strcmp("kB", unit) == 0) {
        data *= 1024;
      }
      *size = data;
    }
    if (strcmp("MemFree:", key) == 0) {
      data = atoi(val);
      if (strcmp("kB", unit) == 0) {
        data *= 1024;
      }
      *free += data;
    }
    if (strcmp("Buffers:", key) == 0) {
      data = atoi(val);
      if (strcmp("kB", unit) == 0) {
        data *= 1024;
      }
      *free += data;
    }
    if (strcmp("Cached:", key) == 0) {
      data = atoi(val);
      if (strcmp("kB", unit) == 0) {
        data *= 1024;
      }
      *free += data;
    }
  }
  fclose(f);
  return (0);
}


x86 assembly (clang, -O0):
<getmeminfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4c0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
lea    0xe72(%rip),%rdi
lea    0xe79(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    -0x4b0(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     138f <getmeminfo+0x22f>
movb   $0x0,-0x60(%rbp)
movb   $0x0,-0xa0(%rbp)
movb   $0x0,-0xa8(%rbp)
lea    -0x4b0(%rbp),%rdi
lea    -0x60(%rbp),%rdx
lea    -0xa0(%rbp),%rcx
lea    -0xa8(%rbp),%r8
lea    0xe21(%rip),%rsi
call   1060 <sscanf@plt>
lea    -0x60(%rbp),%rsi
lea    0xe18(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1258 <getmeminfo+0xf8>
lea    -0xa0(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x4b4(%rbp)
lea    -0xa8(%rbp),%rsi
lea    0xdf3(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    124c <getmeminfo+0xec>
mov    -0x4b4(%rbp),%eax
shl    $0xa,%eax
mov    %eax,-0x4b4(%rbp)
mov    -0x4b4(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
lea    -0x60(%rbp),%rsi
lea    0xdc1(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    12be <getmeminfo+0x15e>
lea    -0xa0(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x4b4(%rbp)
lea    -0xa8(%rbp),%rsi
lea    0xd8f(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    12b0 <getmeminfo+0x150>
mov    -0x4b4(%rbp),%eax
shl    $0xa,%eax
mov    %eax,-0x4b4(%rbp)
mov    -0x4b4(%rbp),%ecx
mov    -0x10(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
lea    -0x60(%rbp),%rsi
lea    0xd64(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1324 <getmeminfo+0x1c4>
lea    -0xa0(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x4b4(%rbp)
lea    -0xa8(%rbp),%rsi
lea    0xd29(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1316 <getmeminfo+0x1b6>
mov    -0x4b4(%rbp),%eax
shl    $0xa,%eax
mov    %eax,-0x4b4(%rbp)
mov    -0x4b4(%rbp),%ecx
mov    -0x10(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
lea    -0x60(%rbp),%rsi
lea    0xd07(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    138a <getmeminfo+0x22a>
lea    -0xa0(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x4b4(%rbp)
lea    -0xa8(%rbp),%rsi
lea    0xcc3(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    137c <getmeminfo+0x21c>
mov    -0x4b4(%rbp),%eax
shl    $0xa,%eax
mov    %eax,-0x4b4(%rbp)
mov    -0x4b4(%rbp),%ecx
mov    -0x10(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
jmp    119e <getmeminfo+0x3e>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x4c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getmeminfo>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x498,%rsp
mov    %rsi,%r15
mov    %rdi,(%rsp)
movl   $0x0,(%rdi)
movl   $0x0,(%rsi)
lea    0xe75(%rip),%rdi
lea    0xe7c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r13
lea    0x90(%rsp),%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     1339 <getmeminfo+0x1d9>
lea    0x90(%rsp),%rbx
lea    0x50(%rsp),%rbp
lea    0x10(%rsp),%r14
lea    0x8(%rsp),%r12
jmp    1204 <getmeminfo+0xa4>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    %ebx,(%r15)
lea    0x90(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r13,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     1339 <getmeminfo+0x1d9>
movb   $0x0,0x50(%rsp)
movb   $0x0,0x10(%rsp)
movb   $0x0,0x8(%rsp)
mov    %rbx,%rdi
lea    0xdf3(%rip),%rsi
mov    %rbp,%rdx
mov    %r14,%rcx
mov    %r12,%r8
call   1060 <sscanf@plt>
lea    0xde5(%rip),%rdi
mov    %rbp,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    1277 <getmeminfo+0x117>
mov    %r13,%rbx
mov    %r14,%rdi
call   1080 <atoi@plt>
mov    %eax,%r13d
lea    0xdcd(%rip),%rdi
mov    %r12,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    1265 <getmeminfo+0x105>
shl    $0xa,%r13d
mov    (%rsp),%rax
mov    %r13d,(%rax)
mov    %rbx,%r13
lea    0x90(%rsp),%rbx
lea    0xda6(%rip),%rdi
mov    %rbp,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    12b7 <getmeminfo+0x157>
mov    %r14,%rdi
call   1080 <atoi@plt>
mov    %eax,%ebx
lea    0xd85(%rip),%rdi
mov    %r12,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    12ac <getmeminfo+0x14c>
shl    $0xa,%ebx
add    %ebx,(%r15)
lea    0x90(%rsp),%rbx
lea    0xd6f(%rip),%rdi
mov    %rbp,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    12f7 <getmeminfo+0x197>
mov    %r14,%rdi
call   1080 <atoi@plt>
mov    %eax,%ebx
lea    0xd45(%rip),%rdi
mov    %r12,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    12ec <getmeminfo+0x18c>
shl    $0xa,%ebx
add    %ebx,(%r15)
lea    0x90(%rsp),%rbx
lea    0xd38(%rip),%rdi
mov    %rbp,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    11eb <getmeminfo+0x8b>
mov    %r14,%rdi
call   1080 <atoi@plt>
mov    %eax,%ebx
lea    0xd01(%rip),%rdi
mov    %r12,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    11e0 <getmeminfo+0x80>
shl    $0xa,%ebx
jmp    11e0 <getmeminfo+0x80>
mov    %r13,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x498,%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 = [7 x i8] c"%s%s%s\00"
@.str.3 = [10 x i8] c"MemTotal:\00"
@.str.4 = [3 x i8] c"kB\00"
@.str.5 = [9 x i8] c"MemFree:\00"
@.str.6 = [9 x i8] c"Buffers:\00"
@.str.7 = [8 x i8] c"Cached:\00"
define i32 @getmeminfo(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca [64 x i8]
%7 = alloca [64 x i8]
%8 = alloca [8 x i8]
%9 = alloca [1024 x i8]
%10 = alloca i32
store i32* %0, i32** %3
store i32* %1, i32** %4
%11 = load i32*, i32** %3
store i32 0, i32* %11
%12 = load i32*, i32** %4
store i32 0, i32* %12
%13 = 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* %13, i32** %5
br label %14
14: ; preds = %97, %2
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%16 = load i32*, i32** %5
%17 = call i64 @fgets(i8* %15, i32 1024, i32* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %98
19: ; preds = %14
%20 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
store i8 0, i8* %20
%21 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
store i8 0, i8* %21
%22 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
store i8 0, i8* %22
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%24 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%25 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%26 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%27 = call i32 @sscanf(i8* %23, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %24, i8* %25, i8* %26)
%28 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%29 = call i64 @strcmp(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %43
31: ; preds = %19
%32 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%33 = call i32 @atoi(i8* %32)
store i32 %33, i32* %10
%34 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%35 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %34)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %31
%38 = load i32, i32* %10
%39 = mul nsw i32 %38, 1024
store i32 %39, i32* %10
br label %40
40: ; preds = %37, %31
%41 = load i32, i32* %10
%42 = load i32*, i32** %3
store i32 %41, i32* %42
br label %43
43: ; preds = %40, %19
%44 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%45 = call i64 @strcmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* %44)
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %61
47: ; preds = %43
%48 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%49 = call i32 @atoi(i8* %48)
store i32 %49, i32* %10
%50 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%51 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %50)
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %47
%54 = load i32, i32* %10
%55 = mul nsw i32 %54, 1024
store i32 %55, i32* %10
br label %56
56: ; preds = %53, %47
%57 = load i32, i32* %10
%58 = load i32*, i32** %4
%59 = load i32, i32* %58
%60 = add nsw i32 %59, %57
store i32 %60, i32* %58
br label %61
61: ; preds = %56, %43
%62 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%63 = call i64 @strcmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %62)
%64 = icmp eq i64 %63, 0
br i1 %64, label %65, label %79
65: ; preds = %61
%66 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%67 = call i32 @atoi(i8* %66)
store i32 %67, i32* %10
%68 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%69 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %68)
%70 = icmp eq i64 %69, 0
br i1 %70, label %71, label %74
71: ; preds = %65
%72 = load i32, i32* %10
%73 = mul nsw i32 %72, 1024
store i32 %73, i32* %10
br label %74
74: ; preds = %71, %65
%75 = load i32, i32* %10
%76 = load i32*, i32** %4
%77 = load i32, i32* %76
%78 = add nsw i32 %77, %75
store i32 %78, i32* %76
br label %79
79: ; preds = %74, %61
%80 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%81 = call i64 @strcmp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* %80)
%82 = icmp eq i64 %81, 0
br i1 %82, label %83, label %97
83: ; preds = %79
%84 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%85 = call i32 @atoi(i8* %84)
store i32 %85, i32* %10
%86 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%87 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %86)
%88 = icmp eq i64 %87, 0
br i1 %88, label %89, label %92
89: ; preds = %83
%90 = load i32, i32* %10
%91 = mul nsw i32 %90, 1024
store i32 %91, i32* %10
br label %92
92: ; preds = %89, %83
%93 = load i32, i32* %10
%94 = load i32*, i32** %4
%95 = load i32, i32* %94
%96 = add nsw i32 %95, %93
store i32 %96, i32* %94
br label %97
97: ; preds = %92, %79
br label %14
98: ; preds = %14
%99 = load i32*, i32** %5
%100 = call i32 @fclose(i32* %99)
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/meminfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [7 x i8] c"%s%s%s\00"
@.str.3 = [10 x i8] c"MemTotal:\00"
@.str.4 = [3 x i8] c"kB\00"
@.str.5 = [9 x i8] c"MemFree:\00"
@.str.6 = [9 x i8] c"Buffers:\00"
@.str.7 = [8 x i8] c"Cached:\00"
define i32 @getmeminfo(i32* nocapture writeonly %0, i32* nocapture %1) {
%3 = alloca [64 x i8]
%4 = alloca [64 x i8]
%5 = alloca [8 x i8]
%6 = alloca [1024 x i8]
%7 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
store i32 0, i32* %0
store i32 0, i32* %1
%11 = 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))
%12 = call i64 @fgets(i8* %10, i32 1024, i32* %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %60, label %14
14: ; preds = %2, %57
store i8 0, i8* %7
store i8 0, i8* %8
store i8 0, i8* %9
%15 = call i32 @sscanf(i8* %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %7, i8* %8, i8* %9)
%16 = call i64 @strcmp(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %7)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = call i32 @atoi(i8* %8)
%20 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %9)
%21 = icmp eq i64 %20, 0
%22 = shl nsw i32 %19, 10
%23 = select i1 %21, i32 %22, i32 %19
store i32 %23, i32* %0
br label %24
24: ; preds = %18, %14
%25 = call i64 @strcmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* %7)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %35
27: ; preds = %24
%28 = call i32 @atoi(i8* %8)
%29 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %9)
%30 = icmp eq i64 %29, 0
%31 = shl nsw i32 %28, 10
%32 = select i1 %30, i32 %31, i32 %28
%33 = load i32, i32* %1
%34 = add nsw i32 %32, %33
store i32 %34, i32* %1
br label %35
35: ; preds = %27, %24
%36 = call i64 @strcmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %7)
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %46
38: ; preds = %35
%39 = call i32 @atoi(i8* %8)
%40 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %9)
%41 = icmp eq i64 %40, 0
%42 = shl nsw i32 %39, 10
%43 = select i1 %41, i32 %42, i32 %39
%44 = load i32, i32* %1
%45 = add nsw i32 %43, %44
store i32 %45, i32* %1
br label %46
46: ; preds = %38, %35
%47 = call i64 @strcmp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* %7)
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %57
49: ; preds = %46
%50 = call i32 @atoi(i8* %8)
%51 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %9)
%52 = icmp eq i64 %51, 0
%53 = shl nsw i32 %50, 10
%54 = select i1 %52, i32 %53, i32 %50
%55 = load i32, i32* %1
%56 = add nsw i32 %54, %55
store i32 %56, i32* %1
br label %57
57: ; preds = %49, %46
%58 = call i64 @fgets(i8* %10, i32 1024, i32* %11)
%59 = icmp eq i64 %58, 0
br i1 %59, label %60, label %14
60: ; preds = %57, %2
%61 = call i32 @fclose(i32* %11)
ret i32 0
}