#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 */
long atol(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ isdigit(char);
int /*<<< orphan*/ perror(char *);
long get_mem_free(void) {
  FILE *fp;
  char s1[30];
  char *s = s1;
  char free_mem[9];
  int i = 0;
  if ((fp = fopen("/proc/meminfo", "r")) == NULL) {
    perror("get_mem_free: can't open /proc/meminfo");
    return -1;
  }
  fgets(s, 30, fp);
  fgets(s, 30, fp);
  while (!isdigit(*s))
    ++s;
  while (isdigit(*s)) {
    free_mem[i++] = *s++;
  }
  free_mem[i] = '\0';
  fclose(fp);
  return atol(free_mem);
}


x86 assembly (clang, -O0):
<get_mem_free>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
lea    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x48(%rbp)
lea    0xe9d(%rip),%rdi
lea    0xe7b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11b1 <get_mem_free+0x51>
lea    0xe63(%rip),%rdi
call   1080 <perror@plt>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    1269 <get_mem_free+0x109>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x1e,%esi
call   1050 <fgets@plt>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x1e,%esi
call   1050 <fgets@plt>
mov    -0x38(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11f7 <get_mem_free+0x97>
jmp    1208 <get_mem_free+0xa8>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    11d5 <get_mem_free+0x75>
jmp    120d <get_mem_free+0xad>
mov    -0x38(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     124a <get_mem_free+0xea>
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x38(%rbp)
mov    (%rax),%cl
mov    -0x48(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x48(%rbp)
cltq
mov    %cl,-0x41(%rbp,%rax,1)
jmp    120d <get_mem_free+0xad>
movslq -0x48(%rbp),%rax
movb   $0x0,-0x41(%rbp,%rax,1)
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x41(%rbp),%rdi
call   1060 <atol@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_mem_free>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
lea    0xeab(%rip),%rdi
lea    0xe89(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1226 <get_mem_free+0xc6>
mov    %rax,%r14
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1e,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
mov    %rbx,%rdi
mov    $0x1e,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
nopl   (%rax)
movsbl (%rbx),%edi
call   1030 <isdigit@plt>
add    $0x1,%rbx
test   %rax,%rax
je     11b0 <get_mem_free+0x50>
movsbl -0x1(%rbx),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1203 <get_mem_free+0xa3>
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl -0x1(%rbx,%r15,1),%eax
mov    %al,0x7(%rsp,%r15,1)
movsbl (%rbx,%r15,1),%edi
add    $0x1,%r15
call   1030 <isdigit@plt>
test   %rax,%rax
jne    11e0 <get_mem_free+0x80>
mov    %r15d,%eax
jmp    1205 <get_mem_free+0xa5>
xor    %eax,%eax
movb   $0x0,0x7(%rsp,%rax,1)
mov    %r14,%rdi
call   1040 <fclose@plt>
lea    0x7(%rsp),%rdi
call   1060 <atol@plt>
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdd5(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffffffffffff,%rax
jmp    121c <get_mem_free+0xbc>

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/meminfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [39 x i8] c"get_mem_free: can't open /proc/meminfo\00"
define i64 @get_mem_free() {
%1 = alloca i64
%2 = alloca i32*
%3 = alloca [30 x i8]
%4 = alloca i8*
%5 = alloca [9 x i8]
%6 = alloca i32
%7 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
store i8* %7, i8** %4
store i32 0, i32* %6
%8 = 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* %8, i32** %2
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
store i64 -1, i64* %1
br label %50
12: ; preds = %0
%13 = load i8*, i8** %4
%14 = load i32*, i32** %2
%15 = call i32 @fgets(i8* %13, i32 30, i32* %14)
%16 = load i8*, i8** %4
%17 = load i32*, i32** %2
%18 = call i32 @fgets(i8* %16, i32 30, i32* %17)
br label %19
19: ; preds = %25, %12
%20 = load i8*, i8** %4
%21 = load i8, i8* %20
%22 = call i64 @isdigit(i8 signext %21)
%23 = icmp ne i64 %22, 0
%24 = xor i1 %23, true
br i1 %24, label %25, label %28
25: ; preds = %19
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %4
br label %19
28: ; preds = %19
br label %29
29: ; preds = %34, %28
%30 = load i8*, i8** %4
%31 = load i8, i8* %30
%32 = call i64 @isdigit(i8 signext %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %42
34: ; preds = %29
%35 = load i8*, i8** %4
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %4
%37 = load i8, i8* %35
%38 = load i32, i32* %6
%39 = add nsw i32 %38, 1
store i32 %39, i32* %6
%40 = sext i32 %38 to i64
%41 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 %40
store i8 %37, i8* %41
br label %29
42: ; preds = %29
%43 = load i32, i32* %6
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 %44
store i8 0, i8* %45
%46 = load i32*, i32** %2
%47 = call i32 @fclose(i32* %46)
%48 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 0
%49 = call i64 @atol(i8* %48)
store i64 %49, i64* %1
br label %50
50: ; preds = %42, %10
%51 = load i64, i64* %1
ret i64 %51
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/meminfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [39 x i8] c"get_mem_free: can't open /proc/meminfo\00"
define i64 @get_mem_free() {
%1 = alloca [30 x i8]
%2 = alloca [9 x i8]
%3 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%5 = 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))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
br label %39
9: ; preds = %0
%10 = call i32 @fgets(i8* %3, i32 30, i32* %5)
%11 = call i32 @fgets(i8* %3, i32 30, i32* %5)
br label %12
12: ; preds = %12, %9
%13 = phi i8* [ %3, %9 ], [ %17, %12 ]
%14 = load i8, i8* %13
%15 = call i64 @isdigit(i8 signext %14)
%16 = icmp eq i64 %15, 0
%17 = getelementptr inbounds i8, i8* %13, i64 1
br i1 %16, label %12, label %18
18: ; preds = %12
%19 = load i8, i8* %13
%20 = call i64 @isdigit(i8 signext %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %34, label %22
22: ; preds = %18, %22
%23 = phi i64 [ %27, %22 ], [ 0, %18 ]
%24 = phi i8* [ %25, %22 ], [ %13, %18 ]
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = load i8, i8* %24
%27 = add nuw i64 %23, 1
%28 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 %23
store i8 %26, i8* %28
%29 = load i8, i8* %25
%30 = call i64 @isdigit(i8 signext %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %22
32: ; preds = %22
%33 = and i64 %27, 4294967295
br label %34
34: ; preds = %32, %18
%35 = phi i64 [ 0, %18 ], [ %33, %32 ]
%36 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 %35
store i8 0, i8* %36
%37 = call i32 @fclose(i32* %5)
%38 = call i64 @atol(i8* %4)
br label %39
39: ; preds = %34, %7
%40 = phi i64 [ -1, %7 ], [ %38, %34 ]
ret i64 %40
}