#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 */
unsigned long long atoll(char *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char *strtok(char *, char *);
unsigned long long memory() {
  static char buf[1024];
  FILE *fp;
  unsigned long long mem = 0;
  if ((fp = fopen("/proc/self/stat", "r")) != NULL) {
    if (fgets(buf, 1024, fp)) {
      char *tok = strtok(buf, " ");
      for (int i = 1; i < 23; i++) {
        tok = strtok(NULL, " ");
      }
      if (tok != NULL) {
        mem = atoll(tok);
      }
    }
  }
  return mem;
}


x86 assembly (clang, -O0):
<memory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x10(%rbp)
lea    0xea9(%rip),%rdi
lea    0xeb2(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
je     11fc <memory+0xbc>
mov    -0x8(%rbp),%rdx
lea    0x2ed4(%rip),%rdi
mov    $0x400,%esi
call   1030 <fgets@plt>
cmp    $0x0,%rax
je     11f7 <memory+0xb7>
lea    0x2eb9(%rip),%rdi
lea    0xe74(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
cmpl   $0x17,-0x1c(%rbp)
jge    11da <memory+0x9a>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe4f(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ae <memory+0x6e>
cmpq   $0x0,-0x18(%rbp)
je     11f2 <memory+0xb2>
mov    -0x18(%rbp),%rdi
call   1040 <atoll@plt>
mov    %rax,-0x10(%rbp)
jmp    11f7 <memory+0xb7>
jmp    11fc <memory+0xbc>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<memory>:
push   %rbx
lea    0xeb8(%rip),%rdi
lea    0xec1(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     127a <memory+0x13a>
lea    0x2eec(%rip),%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1030 <fgets@plt>
test   %rax,%rax
je     127a <memory+0x13a>
lea    0x2ecf(%rip),%rdi
lea    0xe8a(%rip),%rbx
mov    %rbx,%rsi
call   1060 <strtok@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1060 <strtok@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1060 <strtok@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1060 <strtok@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1060 <strtok@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1060 <strtok@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1060 <strtok@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1060 <strtok@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1060 <strtok@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1060 <strtok@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1060 <strtok@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1060 <strtok@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1060 <strtok@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1060 <strtok@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1060 <strtok@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1060 <strtok@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1060 <strtok@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1060 <strtok@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1060 <strtok@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1060 <strtok@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1060 <strtok@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1060 <strtok@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1060 <strtok@plt>
test   %rax,%rax
je     127a <memory+0x13a>
mov    %rax,%rdi
pop    %rbx
jmp    1040 <atoll@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@memory.buf = internal global [1024 x i8] zeroinitializer
@.str = [16 x i8] c"/proc/self/stat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c" \00"
define i64 @memory() {
%1 = alloca i32*
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i32
store i64 0, i64* %2
%5 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %1
%6 = icmp ne i32* %5, null
br i1 %6, label %7, label %29
7: ; preds = %0
%8 = load i32*, i32** %1
%9 = call i64 @fgets(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @memory.buf, i64 0, i64 0), i32 1024, i32* %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %28
11: ; preds = %7
%12 = call i8* @strtok(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @memory.buf, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %12, i8** %3
store i32 1, i32* %4
br label %13
13: ; preds = %18, %11
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 23
br i1 %15, label %16, label %21
16: ; preds = %13
%17 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %17, i8** %3
br label %18
18: ; preds = %16
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 1
store i32 %20, i32* %4
br label %13
21: ; preds = %13
%22 = load i8*, i8** %3
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i8*, i8** %3
%26 = call i64 @atoll(i8* %25)
store i64 %26, i64* %2
br label %27
27: ; preds = %24, %21
br label %28
28: ; preds = %27, %7
br label %29
29: ; preds = %28, %0
%30 = load i64, i64* %2
ret i64 %30
}

LLVM IR (-O2):
@memory.buf = internal global [1024 x i8] zeroinitializer
@.str = [16 x i8] c"/proc/self/stat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c" \00"
define i64 @memory() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %33, label %3
3: ; preds = %0
%4 = tail call i64 @fgets(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @memory.buf, i64 0, i64 0), i32 1024, i32* %1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %33, label %6
6: ; preds = %3
%7 = tail call i8* @strtok(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @memory.buf, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%8 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%9 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%10 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%11 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%12 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%13 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%14 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%15 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%16 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%17 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%18 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%19 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%20 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%21 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%22 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%23 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%24 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%25 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%26 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%27 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%28 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%29 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%30 = icmp eq i8* %29, null
br i1 %30, label %33, label %31
31: ; preds = %6
%32 = tail call i64 @atoll(i8* %29)
br label %33
33: ; preds = %6, %31, %3, %0
%34 = phi i64 [ 0, %3 ], [ 0, %0 ], [ %32, %31 ], [ 0, %6 ]
ret i64 %34
}