#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*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, char *, int *, char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strcmp(char *, char *);
int main(int argc, char **argv) {
  int div = 1;
  if (argc > 1 && argv[1][0] == '-') {
    if (argv[1][1] == 'm' && !argv[1][2]) {
      div = 1024;
    }
  }
  FILE *f = fopen("/proc/meminfo", "r");
  char name[20];
  int value;
  char unit[3];
  int mtotal, mfree;
  while (fscanf(f, "%s %d %s", name, &value, unit) > 1) {
    if (strcmp(name, "MemTotal:") == 0) {
      mtotal = value;
    } else if (strcmp(name, "MemFree:") == 0) {
      mfree = value;
    }
  }
  printf("\ttotal\tused\tfree\n");
  printf("Mem:\t%d\t%d\t%d\n", mtotal / div, (mtotal - mfree) / div,
         mfree / div);
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11be <main+0x6e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    11be <main+0x6e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl 0x1(%rax),%eax
cmp    $0x6d,%eax
jne    11b9 <main+0x69>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
cmpb   $0x0,0x2(%rax)
jne    11b9 <main+0x69>
movl   $0x400,-0x14(%rbp)
jmp    11be <main+0x6e>
lea    0xe3b(%rip),%rdi
lea    0xe42(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x40(%rbp),%rdx
lea    -0x47(%rbp),%r8
lea    0xe28(%rip),%rsi
lea    -0x44(%rbp),%rcx
call   1050 <fscanf@plt>
cmp    $0x1,%eax
jle    1249 <main+0xf9>
lea    -0x40(%rbp),%rdi
lea    0xe14(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    121f <main+0xcf>
mov    -0x44(%rbp),%eax
mov    %eax,-0x4c(%rbp)
jmp    1244 <main+0xf4>
lea    -0x40(%rbp),%rdi
lea    0xdf9(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    123f <main+0xef>
mov    -0x44(%rbp),%eax
mov    %eax,-0x50(%rbp)
jmp    1244 <main+0xf4>
jmp    11d5 <main+0x85>
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4c(%rbp),%eax
cltd
idivl  -0x14(%rbp)
mov    %eax,%esi
mov    -0x4c(%rbp),%eax
sub    -0x50(%rbp),%eax
cltd
idivl  -0x14(%rbp)
mov    %eax,-0x54(%rbp)
mov    -0x50(%rbp),%eax
cltd
idivl  -0x14(%rbp)
mov    -0x54(%rbp),%edx
mov    %eax,%ecx
lea    0xdbe(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    $0x1,%ecx
cmp    $0x2,%edi
jl     1198 <main+0x38>
mov    0x8(%rsi),%rax
cmpb   $0x2d,(%rax)
jne    1198 <main+0x38>
cmpb   $0x6d,0x1(%rax)
jne    1198 <main+0x38>
cmpb   $0x0,0x2(%rax)
mov    $0x400,%eax
mov    $0x1,%ecx
cmove  %eax,%ecx
mov    %ecx,0x8(%rsp)
lea    0xe5d(%rip),%rdi
lea    0xe64(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
lea    0xe57(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %rsp,%rcx
lea    0x5(%rsp),%r8
mov    %rax,%rdi
call   1060 <fscanf@plt>
cmp    $0x2,%eax
jl     123e <main+0xde>
lea    0x10(%rsp),%rbp
lea    0xe31(%rip),%r13
mov    %rsp,%r14
lea    0x5(%rsp),%r15
jmp    120d <main+0xad>
nopl   0x0(%rax)
mov    (%rsp),%r12d
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
mov    %r14,%rcx
mov    %r15,%r8
call   1060 <fscanf@plt>
cmp    $0x1,%eax
jle    123e <main+0xde>
mov    %rbp,%rdi
lea    0xe02(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     11f0 <main+0x90>
mov    %rbp,%rdi
lea    0xdf8(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    11f4 <main+0x94>
mov    (%rsp),%eax
mov    %eax,0xc(%rsp)
jmp    11f4 <main+0x94>
lea    0xdf6(%rip),%rdi
call   1030 <puts@plt>
mov    %r12d,%eax
cltd
mov    0x8(%rsp),%edi
idiv   %edi
mov    %eax,%esi
mov    0xc(%rsp),%ebp
sub    %ebp,%r12d
mov    %r12d,%eax
cltd
idiv   %edi
mov    %eax,%ecx
mov    %ebp,%eax
cltd
idiv   %edi
lea    0xdbb(%rip),%rdi
mov    %ecx,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x28,%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"%s %d %s\00"
@.str.3 = [10 x i8] c"MemTotal:\00"
@.str.4 = [9 x i8] c"MemFree:\00"
@.str.5 = [18 x i8] c"\09total\09used\09free\0A\00"
@.str.6 = [15 x i8] c"Mem:\09%d\09%d\09%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
%8 = alloca [20 x i8]
%9 = alloca i32
%10 = alloca [3 x i8]
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %6
%13 = load i32, i32* %4
%14 = icmp sgt i32 %13, 1
br i1 %14, label %15, label %40
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = getelementptr inbounds i8, i8* %18, i64 0
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 45
br i1 %22, label %23, label %40
23: ; preds = %15
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = getelementptr inbounds i8, i8* %26, i64 1
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 109
br i1 %30, label %31, label %39
31: ; preds = %23
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = getelementptr inbounds i8, i8* %34, i64 2
%36 = load i8, i8* %35
%37 = icmp ne i8 %36, 0
br i1 %37, label %39, label %38
38: ; preds = %31
store i32 1024, i32* %6
br label %39
39: ; preds = %38, %31, %23
br label %40
40: ; preds = %39, %15, %2
%41 = 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* %41, i32** %7
br label %42
42: ; preds = %61, %40
%43 = load i32*, i32** %7
%44 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%45 = getelementptr inbounds [3 x i8], [3 x i8]* %10, i64 0, i64 0
%46 = call i32 @fscanf(i32* %43, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %44, i32* %9, i8* %45)
%47 = icmp sgt i32 %46, 1
br i1 %47, label %48, label %62
48: ; preds = %42
%49 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%50 = call i64 @strcmp(i8* %49, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %48
%53 = load i32, i32* %9
store i32 %53, i32* %11
br label %61
54: ; preds = %48
%55 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%56 = call i64 @strcmp(i8* %55, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%57 = icmp eq i64 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %54
%59 = load i32, i32* %9
store i32 %59, i32* %12
br label %60
60: ; preds = %58, %54
br label %61
61: ; preds = %60, %52
br label %42
62: ; preds = %42
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%64 = load i32, i32* %11
%65 = load i32, i32* %6
%66 = sdiv i32 %64, %65
%67 = load i32, i32* %11
%68 = load i32, i32* %12
%69 = sub nsw i32 %67, %68
%70 = load i32, i32* %6
%71 = sdiv i32 %69, %70
%72 = load i32, i32* %12
%73 = load i32, i32* %6
%74 = sdiv i32 %72, %73
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 %66, i32 %71, i32 %74)
%76 = load i32*, i32** %7
%77 = call i32 @fclose(i32* %76)
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"%s %d %s\00"
@.str.3 = [10 x i8] c"MemTotal:\00"
@.str.4 = [9 x i8] c"MemFree:\00"
@.str.6 = [15 x i8] c"Mem:\09%d\09%d\09%d\0A\00"
@str = [17 x i8] c"\09total\09used\09free\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [20 x i8]
%4 = alloca i32
%5 = alloca [3 x i8]
%6 = icmp sgt i32 %0, 1
br i1 %6, label %7, label %21
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 45
br i1 %11, label %12, label %21
12: ; preds = %7
%13 = getelementptr inbounds i8, i8* %9, i64 1
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 109
br i1 %15, label %16, label %21
16: ; preds = %12
%17 = getelementptr inbounds i8, i8* %9, i64 2
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
%20 = select i1 %19, i32 1024, i32 1
br label %21
21: ; preds = %16, %12, %7, %2
%22 = phi i32 [ 1, %12 ], [ 1, %7 ], [ 1, %2 ], [ %20, %16 ]
%23 = 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))
%24 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%25 = bitcast i32* %4 to i8*
%26 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%27 = call i32 @fscanf(i32* %23, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %24, i32* %4, i8* %26)
%28 = icmp sgt i32 %27, 1
br i1 %28, label %29, label %46
29: ; preds = %21, %41
%30 = phi i32 [ %43, %41 ], [ undef, %21 ]
%31 = phi i32 [ %42, %41 ], [ undef, %21 ]
%32 = call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %29
%35 = load i32, i32* %4
br label %41
36: ; preds = %29
%37 = call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
%39 = load i32, i32* %4
%40 = select i1 %38, i32 %39, i32 %30
br label %41
41: ; preds = %36, %34
%42 = phi i32 [ %35, %34 ], [ %31, %36 ]
%43 = phi i32 [ %30, %34 ], [ %40, %36 ]
%44 = call i32 @fscanf(i32* %23, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %24, i32* %4, i8* %26)
%45 = icmp sgt i32 %44, 1
br i1 %45, label %29, label %46
46: ; preds = %41, %21
%47 = phi i32 [ undef, %21 ], [ %42, %41 ]
%48 = phi i32 [ undef, %21 ], [ %43, %41 ]
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%50 = sdiv i32 %47, %22
%51 = sub nsw i32 %47, %48
%52 = sdiv i32 %51, %22
%53 = sdiv i32 %48, %22
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 %50, i32 %52, i32 %53)
%55 = call i32 @fclose(i32* %23)
ret i32 0
}