#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*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t strtoul(char *, int /*<<< orphan*/ *, int);
size_t get_free_memory(void) {
  FILE *f;
  size_t i;
  char buf[256];
  char *p;
  f = fopen("/proc/meminfo", "rt");
  assert(f != NULL);
  fgets(buf, 256, f);
  fgets(buf, 256, f);
  fclose(f);
  p = NULL;
  for (i = 0; i < 256; i++)
    if (buf[i] == ':') {
      p = buf + i + 1;
      break;
    }
  return strtoul(p, NULL, 10);
}


x86 assembly (clang, -O0):
<get_free_memory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
lea    0xe9e(%rip),%rdi
lea    0xea5(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x100,%esi
call   1040 <fgets@plt>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x100,%esi
call   1040 <fgets@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
movq   $0x0,-0x118(%rbp)
movq   $0x0,-0x10(%rbp)
cmpq   $0x100,-0x10(%rbp)
jae    121e <get_free_memory+0xce>
mov    -0x10(%rbp),%rax
movsbl -0x110(%rbp,%rax,1),%eax
ff
cmp    $0x3a,%eax
jne    1208 <get_free_memory+0xb8>
lea    -0x110(%rbp),%rax
add    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x118(%rbp)
jmp    121e <get_free_memory+0xce>
jmp    120d <get_free_memory+0xbd>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11ca <get_free_memory+0x7a>
mov    -0x118(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1070 <strtoul@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_free_memory>:
push   %r14
push   %rbx
sub    $0x108,%rsp
lea    0xe9f(%rip),%rdi
lea    0xea6(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1050 <assert@plt>
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x100,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
mov    %r14,%rdi
mov    $0x100,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %edi,%edi
xor    %eax,%eax
nopl   (%rax)
cmpb   $0x3a,(%rsp,%rax,1)
je     11e9 <get_free_memory+0x99>
cmpb   $0x3a,0x1(%rsp,%rax,1)
je     11d9 <get_free_memory+0x89>
cmpb   $0x3a,0x2(%rsp,%rax,1)
je     11df <get_free_memory+0x8f>
cmpb   $0x3a,0x3(%rsp,%rax,1)
je     11e5 <get_free_memory+0x95>
add    $0x4,%rax
cmp    $0x100,%rax
jne    11b0 <get_free_memory+0x60>
jmp    11f1 <get_free_memory+0xa1>
add    $0x1,%rax
jmp    11e9 <get_free_memory+0x99>
add    $0x2,%rax
jmp    11e9 <get_free_memory+0x99>
add    $0x3,%rax
lea    (%rsp,%rax,1),%rdi
add    $0x1,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1070 <strtoul@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/meminfo\00"
@.str.1 = [3 x i8] c"rt\00"
define i64 @get_free_memory() {
%1 = alloca i32*
%2 = alloca i64
%3 = alloca [256 x i8]
%4 = alloca i8*
%5 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %1
%6 = load i32*, i32** %1
%7 = icmp ne i32* %6, null
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%11 = load i32*, i32** %1
%12 = call i32 @fgets(i8* %10, i32 256, i32* %11)
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%14 = load i32*, i32** %1
%15 = call i32 @fgets(i8* %13, i32 256, i32* %14)
%16 = load i32*, i32** %1
%17 = call i32 @fclose(i32* %16)
store i8* null, i8** %4
store i64 0, i64* %2
br label %18
18: ; preds = %33, %0
%19 = load i64, i64* %2
%20 = icmp ult i64 %19, 256
br i1 %20, label %21, label %36
21: ; preds = %18
%22 = load i64, i64* %2
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 58
br i1 %26, label %27, label %32
27: ; preds = %21
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%29 = load i64, i64* %2
%30 = getelementptr inbounds i8, i8* %28, i64 %29
%31 = getelementptr inbounds i8, i8* %30, i64 1
store i8* %31, i8** %4
br label %36
32: ; preds = %21
br label %33
33: ; preds = %32
%34 = load i64, i64* %2
%35 = add i64 %34, 1
store i64 %35, i64* %2
br label %18
36: ; preds = %27, %18
%37 = load i8*, i8** %4
%38 = call i64 @strtoul(i8* %37, i32* null, i32 10)
ret i64 %38
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/meminfo\00"
@.str.1 = [3 x i8] c"rt\00"
define i64 @get_free_memory() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp ne i32* %3, null
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = call i32 @fgets(i8* %2, i32 256, i32* %3)
%8 = call i32 @fgets(i8* %2, i32 256, i32* %3)
%9 = call i32 @fclose(i32* %3)
br label %10
10: ; preds = %34, %0
%11 = phi i64 [ 0, %0 ], [ %35, %34 ]
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 58
br i1 %14, label %15, label %19
15: ; preds = %29, %24, %19, %10
%16 = phi i64 [ %11, %10 ], [ %20, %19 ], [ %25, %24 ], [ %30, %29 ]
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 %16
%18 = getelementptr inbounds i8, i8* %17, i64 1
br label %37
19: ; preds = %10
%20 = or i64 %11, 1
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 58
br i1 %23, label %15, label %24
24: ; preds = %19
%25 = or i64 %11, 2
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 58
br i1 %28, label %15, label %29
29: ; preds = %24
%30 = or i64 %11, 3
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = icmp eq i8 %32, 58
br i1 %33, label %15, label %34
34: ; preds = %29
%35 = add nuw nsw i64 %11, 4
%36 = icmp eq i64 %35, 256
br i1 %36, label %37, label %10
37: ; preds = %34, %15
%38 = phi i8* [ %18, %15 ], [ null, %34 ]
%39 = call i64 @strtoul(i8* nocapture %38, i32* null, i32 10)
ret i64 %39
}