#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int atoi(char const *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strncmp(char *, char *, int);
int mem_info(char *format) {
  FILE *f = fopen("/proc/meminfo", "r");
  if (f == NULL) {
    fprintf(stderr, "Can't open '%s'.\n", "/proc/meminfo");
    return EXIT_FAILURE;
  }
  int mem[4];
  char *keys[4] = {"MemTotal", "MemFree", "Buffers", "Cached"};
  int lens[4] = {(sizeof("MemTotal") - 1), (sizeof("MemFree") - 1),
                 (sizeof("Buffers") - 1), (sizeof("Cached") - 1)};
  do {
    char line[256];
    fgets(line, 256, f);
    for (int i = 0; i < 4; i++) {
      if (!strncmp(keys[i], line, lens[i])) {
        const char *p = line + lens[i];
        if (*p++ == ':') {
          mem[i] = atoi(p);
          break;
        }
      }
    }
  } while (!feof(f));
  fclose(f);
  printf(format, ((mem[0] - mem[1] - mem[2] - mem[3]) * 100) / mem[0]);
  putchar('\n');
  fflush(stdout);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<mem_info>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe4a(%rip),%rdi
lea    0xe51(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11fe <mem_info+0x5e>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
lea    0xe2f(%rip),%rsi
lea    0xe18(%rip),%rdx
call   1080 <fprintf@plt>
mov    0x2de4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    137b <mem_info+0x1db>
mov    0x2bdb(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0x2bd8(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0x2bd5(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0x2bd2(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xe1f(%rip),%rax
mov    %rax,-0x60(%rbp)
mov    0xe1c(%rip),%rax
mov    %rax,-0x58(%rbp)
lea    -0x160(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x100,%esi
call   1070 <fgets@plt>
movl   $0x0,-0x164(%rbp)
cmpl   $0x4,-0x164(%rbp)
jge    1312 <mem_info+0x172>
movslq -0x164(%rbp),%rax
mov    -0x50(%rbp,%rax,8),%rdi
lea    -0x160(%rbp),%rsi
movslq -0x164(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    12f9 <mem_info+0x159>
lea    -0x160(%rbp),%rax
movslq -0x164(%rbp),%rcx
movslq -0x60(%rbp,%rcx,4),%rcx
add    %rcx,%rax
mov    %rax,-0x170(%rbp)
mov    -0x170(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x170(%rbp)
movsbl (%rax),%eax
cmp    $0x3a,%eax
jne    12f4 <mem_info+0x154>
mov    -0x170(%rbp),%rdi
call   10c0 <atoi@plt>
mov    %eax,%ecx
movslq -0x164(%rbp),%rax
mov    %ecx,-0x30(%rbp,%rax,4)
jmp    1312 <mem_info+0x172>
jmp    12f9 <mem_info+0x159>
jmp    12fe <mem_info+0x15e>
mov    -0x164(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x164(%rbp)
jmp    125f <mem_info+0xbf>
jmp    1317 <mem_info+0x177>
mov    -0x18(%rbp),%rdi
call   1090 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1240 <mem_info+0xa0>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%eax
sub    -0x2c(%rbp),%eax
sub    -0x28(%rbp),%eax
sub    -0x24(%rbp),%eax
imul   $0x64,%eax,%eax
cltd
idivl  -0x30(%rbp)
mov    %eax,%esi
call   1060 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x2c68(%rip),%rax
mov    (%rax),%edi
call   10a0 <fflush@plt>
mov    0x2c52(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x170,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mem_info>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
mov    %rdi,%rbp
lea    0xe45(%rip),%rdi
lea    0xe4c(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     131e <mem_info+0x17e>
mov    %rax,%rbx
mov    %rbp,0x18(%rsp)
lea    0x20(%rsp),%r15
lea    0xe3e(%rip),%r12
lea    0xe40(%rip),%r13
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x100,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    $0x8,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
jne    1230 <mem_info+0x90>
cmpb   $0x3a,0x28(%rsp)
jne    1230 <mem_info+0x90>
mov    $0x8,%r14d
xor    %ebp,%ebp
jmp    12b0 <mem_info+0x110>
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %r15,%rsi
mov    $0x7,%edx
call   1040 <strncmp@plt>
mov    $0x7,%r14d
test   %eax,%eax
jne    1256 <mem_info+0xb6>
mov    $0x1,%ebp
cmpb   $0x3a,0x27(%rsp)
je     12b0 <mem_info+0x110>
lea    0xdd6(%rip),%rdi
mov    %r15,%rsi
mov    $0x7,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
jne    127a <mem_info+0xda>
mov    $0x2,%ebp
cmpb   $0x3a,0x27(%rsp)
je     12b0 <mem_info+0x110>
lea    0xdba(%rip),%rdi
mov    %r15,%rsi
mov    $0x6,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
jne    12c0 <mem_info+0x120>
cmpb   $0x3a,0x26(%rsp)
jne    12c0 <mem_info+0x120>
mov    $0x6,%r14d
mov    $0x3,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    (%rsp,%r14,1),%rdi
add    $0x21,%rdi
call   10c0 <atoi@plt>
mov    %eax,(%rsp,%rbp,4)
mov    %rbx,%rdi
call   1090 <feof@plt>
test   %eax,%eax
je     11f0 <mem_info+0x50>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    (%rsp),%ecx
mov    0x4(%rsp),%eax
add    0x8(%rsp),%eax
add    0xc(%rsp),%eax
mov    %ecx,%edx
sub    %eax,%edx
imul   $0x64,%edx,%eax
cltd
idiv   %ecx
mov    0x18(%rsp),%rdi
mov    %eax,%esi
call   1060 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x2cc2(%rip),%rax
mov    (%rax),%edi
call   10a0 <fflush@plt>
mov    0x2cac(%rip),%rax
jmp    1341 <mem_info+0x1a1>
mov    0x2cbb(%rip),%rax
mov    (%rax),%edi
lea    0xce2(%rip),%rsi
lea    0xccb(%rip),%rdx
call   1080 <fprintf@plt>
mov    0x2c97(%rip),%rax
mov    (%rax),%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"
@stderr = global i32 0
@.str.2 = [18 x i8] c"Can't open '%s'.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [9 x i8] c"MemTotal\00"
@.str.4 = [8 x i8] c"MemFree\00"
@.str.5 = [8 x i8] c"Buffers\00"
@.str.6 = [7 x i8] c"Cached\00"
@__const.mem_info.keys = [4 x i8*] [i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i32 0, i32 0)]
@__const.mem_info.lens = [4 x i32] [i32 8, i32 7, i32 7, i32 6]
@stdout = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @mem_info(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [4 x i32]
%6 = alloca [4 x i8*]
%7 = alloca [4 x i32]
%8 = alloca [256 x i8]
%9 = alloca i32
%10 = alloca i8*
store i8* %0, i8** %3
%11 = 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* %11, i32** %4
%12 = load i32*, i32** %4
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %18
14: ; preds = %1
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
store i32 %17, i32* %2
br label %94
18: ; preds = %1
%19 = bitcast [4 x i8*]* %6 to i8*
%20 = bitcast [4 x i32]* %7 to i8*
br label %21
21: ; preds = %65, %18
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%23 = load i32*, i32** %4
%24 = call i32 @fgets(i8* %22, i32 256, i32* %23)
store i32 0, i32* %9
br label %25
25: ; preds = %61, %21
%26 = load i32, i32* %9
%27 = icmp slt i32 %26, 4
br i1 %27, label %28, label %64
28: ; preds = %25
%29 = load i32, i32* %9
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [4 x i8*], [4 x i8*]* %6, i64 0, i64 %30
%32 = load i8*, i8** %31
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%34 = load i32, i32* %9
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [4 x i32], [4 x i32]* %7, i64 0, i64 %35
%37 = load i32, i32* %36
%38 = call i32 @strncmp(i8* %32, i8* %33, i32 %37)
%39 = icmp ne i32 %38, 0
br i1 %39, label %60, label %40
40: ; preds = %28
%41 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%42 = load i32, i32* %9
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [4 x i32], [4 x i32]* %7, i64 0, i64 %43
%45 = load i32, i32* %44
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %41, i64 %46
store i8* %47, i8** %10
%48 = load i8*, i8** %10
%49 = getelementptr inbounds i8, i8* %48, i32 1
store i8* %49, i8** %10
%50 = load i8, i8* %48
%51 = sext i8 %50 to i32
%52 = icmp eq i32 %51, 58
br i1 %52, label %53, label %59
53: ; preds = %40
%54 = load i8*, i8** %10
%55 = call i32 @atoi(i8* %54)
%56 = load i32, i32* %9
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 %57
store i32 %55, i32* %58
br label %64
59: ; preds = %40
br label %60
60: ; preds = %59, %28
br label %61
61: ; preds = %60
%62 = load i32, i32* %9
%63 = add nsw i32 %62, 1
store i32 %63, i32* %9
br label %25
64: ; preds = %53, %25
br label %65
65: ; preds = %64
%66 = load i32*, i32** %4
%67 = call i32 @feof(i32* %66)
%68 = icmp ne i32 %67, 0
%69 = xor i1 %68, true
br i1 %69, label %21, label %70
70: ; preds = %65
%71 = load i32*, i32** %4
%72 = call i32 @fclose(i32* %71)
%73 = load i8*, i8** %3
%74 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 0
%75 = load i32, i32* %74
%76 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 1
%77 = load i32, i32* %76
%78 = sub nsw i32 %75, %77
%79 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 2
%80 = load i32, i32* %79
%81 = sub nsw i32 %78, %80
%82 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 3
%83 = load i32, i32* %82
%84 = sub nsw i32 %81, %83
%85 = mul nsw i32 %84, 100
%86 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 0
%87 = load i32, i32* %86
%88 = sdiv i32 %85, %87
%89 = call i32 @printf(i8* %73, i32 %88)
%90 = call i32 @putchar(i8 signext 10)
%91 = load i32, i32* @stdout
%92 = call i32 @fflush(i32 %91)
%93 = load i32, i32* @EXIT_SUCCESS
store i32 %93, i32* %2
br label %94
94: ; preds = %70, %14
%95 = load i32, i32* %2
ret i32 %95
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/meminfo\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [18 x i8] c"Can't open '%s'.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [9 x i8] c"MemTotal\00"
@.str.4 = [8 x i8] c"MemFree\00"
@.str.5 = [8 x i8] c"Buffers\00"
@.str.6 = [7 x i8] c"Cached\00"
@stdout = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @mem_info(i8* %0) {
%2 = alloca [4 x i32]
%3 = alloca [256 x i8]
%4 = 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))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
br label %72
10: ; preds = %1
%11 = bitcast [4 x i32]* %2 to i8*
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 8
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 7
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 7
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 6
br label %17
17: ; preds = %49, %10
%18 = call i32 @fgets(i8* %12, i32 256, i32* %4)
%19 = call i32 @strncmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %12, i32 8)
%20 = icmp eq i32 %19, 0
%21 = load i8, i8* %13
%22 = icmp eq i8 %21, 58
%23 = select i1 %20, i1 %22, i1 false
br i1 %23, label %24, label %31
24: ; preds = %43, %37, %31, %17
%25 = phi i64 [ 0, %17 ], [ 1, %31 ], [ 2, %37 ], [ 3, %43 ]
%26 = phi i64 [ 8, %17 ], [ 7, %31 ], [ 7, %37 ], [ 6, %43 ]
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %26
%28 = getelementptr inbounds i8, i8* %27, i64 1
%29 = call i32 @atoi(i8* %28)
%30 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 %25
store i32 %29, i32* %30
br label %49
31: ; preds = %17
%32 = call i32 @strncmp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* %12, i32 7)
%33 = icmp eq i32 %32, 0
%34 = load i8, i8* %14
%35 = icmp eq i8 %34, 58
%36 = select i1 %33, i1 %35, i1 false
br i1 %36, label %24, label %37
37: ; preds = %31
%38 = call i32 @strncmp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %12, i32 7)
%39 = icmp eq i32 %38, 0
%40 = load i8, i8* %15
%41 = icmp eq i8 %40, 58
%42 = select i1 %39, i1 %41, i1 false
br i1 %42, label %24, label %43
43: ; preds = %37
%44 = call i32 @strncmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8* %12, i32 6)
%45 = icmp eq i32 %44, 0
%46 = load i8, i8* %16
%47 = icmp eq i8 %46, 58
%48 = select i1 %45, i1 %47, i1 false
br i1 %48, label %24, label %49
49: ; preds = %43, %24
%50 = call i32 @feof(i32* %4)
%51 = icmp eq i32 %50, 0
br i1 %51, label %17, label %52
52: ; preds = %49
%53 = call i32 @fclose(i32* %4)
%54 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 0
%55 = load i32, i32* %54
%56 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 1
%57 = load i32, i32* %56
%58 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 2
%59 = load i32, i32* %58
%60 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 3
%61 = load i32, i32* %60
%62 = add i32 %57, %59
%63 = add i32 %62, %61
%64 = sub i32 %55, %63
%65 = mul nsw i32 %64, 100
%66 = sdiv i32 %65, %55
%67 = call i32 @printf(i8* %0, i32 %66)
%68 = call i32 @putchar(i8 signext 10)
%69 = load i32, i32* @stdout
%70 = call i32 @fflush(i32 %69)
%71 = load i32, i32* @EXIT_SUCCESS
br label %72
72: ; preds = %52, %6
%73 = phi i32 [ %9, %6 ], [ %71, %52 ]
ret i32 %73
}