#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*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ strncmp(char *, char *, int);
int print_memstat() {
  char line[80];
  FILE *f = fopen("/proc/self/status", "r");
  if (!f)
    return -1;
  while (1) {
    if (!fgets(line, 80, f))
      break;
    if (strncmp(line, "VmSize", 6) == 0 || strncmp(line, "VmRSS", 5) == 0 ||
        strncmp(line, "VmData", 6) == 0)
      printf("%s", line);
  }
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<print_memstat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
lea    0xea1(%rip),%rdi
lea    0xeac(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
jne    1186 <print_memstat+0x36>
movl   $0xffffffff,-0x4(%rbp)
jmp    122d <print_memstat+0xdd>
jmp    118b <print_memstat+0x3b>
lea    -0x60(%rbp),%rdi
mov    -0x68(%rbp),%rdx
mov    $0x50,%esi
call   1060 <fgets@plt>
cmp    $0x0,%eax
jne    11ab <print_memstat+0x5b>
jmp    121d <print_memstat+0xcd>
lea    -0x60(%rbp),%rdi
lea    0xe5e(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     1208 <print_memstat+0xb8>
lea    -0x60(%rbp),%rdi
lea    0xe46(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     1208 <print_memstat+0xb8>
lea    -0x60(%rbp),%rdi
lea    0xe2d(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1218 <print_memstat+0xc8>
lea    -0x60(%rbp),%rsi
lea    0xe15(%rip),%rdi
call   1050 <printf@plt>
jmp    118b <print_memstat+0x3b>
mov    -0x68(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_memstat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
lea    0xe9b(%rip),%rdi
lea    0xea6(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     122c <print_memstat+0xdc>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x50,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %eax,%eax
je     1220 <print_memstat+0xd0>
lea    0xe78(%rip),%r14
mov    %rsp,%rbx
lea    0xe82(%rip),%r12
lea    0xe6e(%rip),%r13
lea    0xe6d(%rip),%rbp
jmp    11df <print_memstat+0x8f>
cs nopw 0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x50,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %eax,%eax
je     1220 <print_memstat+0xd0>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11c0 <print_memstat+0x70>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11c0 <print_memstat+0x70>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11cb <print_memstat+0x7b>
jmp    11c0 <print_memstat+0x70>
mov    %r15,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    1231 <print_memstat+0xe1>
mov    $0xffffffff,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"/proc/self/status\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [7 x i8] c"VmSize\00"
@.str.3 = [6 x i8] c"VmRSS\00"
@.str.4 = [7 x i8] c"VmData\00"
@.str.5 = [3 x i8] c"%s\00"
define i32 @print_memstat() {
%1 = alloca i32
%2 = alloca [80 x i8]
%3 = alloca i32*
%4 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %3
%5 = load i32*, i32** %3
%6 = icmp ne i32* %5, null
br i1 %6, label %8, label %7
7: ; preds = %0
store i32 -1, i32* %1
br label %34
8: ; preds = %0
br label %9
9: ; preds = %8, %30
%10 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%11 = load i32*, i32** %3
%12 = call i32 @fgets(i8* %10, i32 80, i32* %11)
%13 = icmp ne i32 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %9
br label %31
15: ; preds = %9
%16 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%17 = call i64 @strncmp(i8* %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 6)
%18 = icmp eq i64 %17, 0
br i1 %18, label %27, label %19
19: ; preds = %15
%20 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%21 = call i64 @strncmp(i8* %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 5)
%22 = icmp eq i64 %21, 0
br i1 %22, label %27, label %23
23: ; preds = %19
%24 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%25 = call i64 @strncmp(i8* %24, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 6)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %23, %19, %15
%28 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%29 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %27, %23
br label %9
31: ; preds = %14
%32 = load i32*, i32** %3
%33 = call i32 @fclose(i32* %32)
store i32 0, i32* %1
br label %34
34: ; preds = %31, %7
%35 = load i32, i32* %1
ret i32 %35
}

LLVM IR (-O2):
@.str = [18 x i8] c"/proc/self/status\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [7 x i8] c"VmSize\00"
@.str.3 = [6 x i8] c"VmRSS\00"
@.str.4 = [7 x i8] c"VmData\00"
@.str.5 = [3 x i8] c"%s\00"
define i32 @print_memstat() {
%1 = alloca [80 x i8]
%2 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %24, label %5
5: ; preds = %0
%6 = call i32 @fgets(i8* %2, i32 80, i32* %3)
%7 = icmp eq i32 %6, 0
br i1 %7, label %22, label %8
8: ; preds = %5, %19
%9 = call i64 @strncmp(i8* %2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 6)
%10 = icmp eq i64 %9, 0
br i1 %10, label %17, label %11
11: ; preds = %8
%12 = call i64 @strncmp(i8* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 5)
%13 = icmp eq i64 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = call i64 @strncmp(i8* %2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 6)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14, %11, %8
%18 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %2)
br label %19
19: ; preds = %17, %14
%20 = call i32 @fgets(i8* %2, i32 80, i32* %3)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %8
22: ; preds = %19, %5
%23 = call i32 @fclose(i32* %3)
br label %24
24: ; preds = %0, %22
%25 = phi i32 [ 0, %22 ], [ -1, %0 ]
ret i32 %25
}