#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 *getLineFromFile(char *, char *, char *, int, int *);
int /*<<< orphan*/ printf(char *, ...);
int printMemoryAvailable() {
  printf("\n-- Total usable memory:\n\t\t");
  int lineLength = 0;
  char *lineFromFile =
      getLineFromFile("/proc/meminfo", "rb", "MemFree", 7, &lineLength);
  int k = 0;
  int wordNumber = 1;
  while (k < lineLength) {
    if (lineFromFile[k] == ' ') {
      wordNumber++;
      k++;
    }
    if (wordNumber > 1 && lineFromFile[k] != 32)
      printf("%c", lineFromFile[k]);
    k++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<printMemoryAvailable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xed1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
lea    0xed8(%rip),%rdi
lea    0xedf(%rip),%rsi
lea    0xedb(%rip),%rdx
mov    $0x7,%ecx
lea    -0x4(%rbp),%r8
call   1040 <getLineFromFile@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11ec <printMemoryAvailable+0xcc>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jne    11a5 <printMemoryAvailable+0x85>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x18(%rbp)
jle    11de <printMemoryAvailable+0xbe>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
je     11de <printMemoryAvailable+0xbe>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1172 <printMemoryAvailable+0x52>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printMemoryAvailable>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
movl   $0x0,0xc(%rsp)
lea    0xec5(%rip),%rdi
lea    0xecc(%rip),%rsi
lea    0xec8(%rip),%rdx
lea    0xc(%rsp),%r8
mov    $0x7,%ecx
call   1050 <getLineFromFile@plt>
mov    %rax,%r14
mov    0xc(%rsp),%eax
test   %eax,%eax
jle    11c5 <printMemoryAvailable+0x95>
mov    $0x1,%ebp
jmp    1197 <printMemoryAvailable+0x67>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%ebx
cmp    %eax,%ebx
jge    11c5 <printMemoryAvailable+0x95>
movslq %ebx,%rbx
xor    %ecx,%ecx
cmpb   $0x20,(%r14,%rbx,1)
sete   %cl
add    %ecx,%ebx
add    %ecx,%ebp
cmp    $0x2,%ebp
jb     1190 <printMemoryAvailable+0x60>
movslq %ebx,%rcx
movsbl (%r14,%rcx,1),%edi
cmp    $0x20,%edi
je     1190 <printMemoryAvailable+0x60>
call   1030 <putchar@plt>
mov    0xc(%rsp),%eax
jmp    1190 <printMemoryAvailable+0x60>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"\0A-- Total usable memory:\0A\09\09\00"
@.str.1 = [14 x i8] c"/proc/meminfo\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [8 x i8] c"MemFree\00"
@.str.4 = [3 x i8] c"%c\00"
define i32 @printMemoryAvailable() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
%6 = call i8* @getLineFromFile(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 7, i32* %1)
store i8* %6, i8** %2
store i32 0, i32* %3
store i32 1, i32* %4
br label %7
7: ; preds = %43, %0
%8 = load i32, i32* %3
%9 = load i32, i32* %1
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %46
11: ; preds = %7
%12 = load i8*, i8** %2
%13 = load i32, i32* %3
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 32
br i1 %18, label %19, label %24
19: ; preds = %11
%20 = load i32, i32* %4
%21 = add nsw i32 %20, 1
store i32 %21, i32* %4
%22 = load i32, i32* %3
%23 = add nsw i32 %22, 1
store i32 %23, i32* %3
br label %24
24: ; preds = %19, %11
%25 = load i32, i32* %4
%26 = icmp sgt i32 %25, 1
br i1 %26, label %27, label %43
27: ; preds = %24
%28 = load i8*, i8** %2
%29 = load i32, i32* %3
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %33, 32
br i1 %34, label %35, label %43
35: ; preds = %27
%36 = load i8*, i8** %2
%37 = load i32, i32* %3
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %41)
br label %43
43: ; preds = %35, %27, %24
%44 = load i32, i32* %3
%45 = add nsw i32 %44, 1
store i32 %45, i32* %3
br label %7
46: ; preds = %7
ret i32 0
}

LLVM IR (-O2):
@.str = [28 x i8] c"\0A-- Total usable memory:\0A\09\09\00"
@.str.1 = [14 x i8] c"/proc/meminfo\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [8 x i8] c"MemFree\00"
define i32 @printMemoryAvailable() {
%1 = alloca i32
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%3 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%4 = call i8* @getLineFromFile(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 7, i32* %1)
%5 = load i32, i32* %1
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %32
7: ; preds = %0, %28
%8 = phi i32 [ %29, %28 ], [ %5, %0 ]
%9 = phi i32 [ %17, %28 ], [ 1, %0 ]
%10 = phi i32 [ %30, %28 ], [ 0, %0 ]
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %4, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 32
%15 = zext i1 %14 to i32
%16 = add nsw i32 %10, %15
%17 = add nuw nsw i32 %9, %15
%18 = icmp ugt i32 %17, 1
br i1 %18, label %19, label %28
19: ; preds = %7
%20 = sext i32 %16 to i64
%21 = getelementptr inbounds i8, i8* %4, i64 %20
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 32
br i1 %23, label %28, label %24
24: ; preds = %19
%25 = sext i8 %22 to i32
%26 = call i32 @putchar(i32 %25)
%27 = load i32, i32* %1
br label %28
28: ; preds = %24, %19, %7
%29 = phi i32 [ %27, %24 ], [ %8, %19 ], [ %8, %7 ]
%30 = add nsw i32 %16, 1
%31 = icmp slt i32 %30, %29
br i1 %31, label %7, label %32
32: ; preds = %28, %0
ret i32 0
}