#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 _parseLine(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ strncmp(char *, char *, int);
int get_vm_peak() {
  int result = -1;
  char line[128];
  FILE *file = fopen("/proc/self/status", "r");
  if (file == NULL)
    return -2;
  while (fgets(line, 128, file) != NULL)
    if (strncmp(line, "VmPeak:", 7) == 0) {
      result = _parseLine(line);
      break;
    }
  fclose(file);
  return result;
}


x86 assembly (clang, -O0):
<get_vm_peak>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0xffffffff,-0x8(%rbp)
lea    0xe97(%rip),%rdi
lea    0xea2(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x98(%rbp)
cmpq   $0x0,-0x98(%rbp)
jne    1196 <get_vm_peak+0x46>
movl   $0xfffffffe,-0x4(%rbp)
jmp    120a <get_vm_peak+0xba>
jmp    119b <get_vm_peak+0x4b>
lea    -0x90(%rbp),%rdi
mov    -0x98(%rbp),%rdx
mov    $0x80,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     11f8 <get_vm_peak+0xa8>
lea    -0x90(%rbp),%rdi
lea    0xe49(%rip),%rsi
mov    $0x7,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    11f3 <get_vm_peak+0xa3>
lea    -0x90(%rbp),%rdi
call   1030 <_parseLine@plt>
mov    %eax,-0x8(%rbp)
jmp    11f8 <get_vm_peak+0xa8>
jmp    119b <get_vm_peak+0x4b>
mov    -0x98(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_vm_peak>:
push   %r15
push   %r14
push   %rbx
sub    $0x80,%rsp
lea    0xe9d(%rip),%rdi
lea    0xea8(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11c6 <get_vm_peak+0x76>
mov    %rax,%r14
mov    %rsp,%rbx
lea    0xe93(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x80,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11cd <get_vm_peak+0x7d>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x7,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    1190 <get_vm_peak+0x40>
mov    %rsp,%rdi
call   1030 <_parseLine@plt>
mov    %eax,%ebx
jmp    11d2 <get_vm_peak+0x82>
mov    $0xfffffffe,%ebx
jmp    11da <get_vm_peak+0x8a>
mov    $0xffffffff,%ebx
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %ebx,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [18 x i8] c"/proc/self/status\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [8 x i8] c"VmPeak:\00"
define i32 @get_vm_peak() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [128 x i8]
%4 = alloca i32*
store i32 -1, i32* %2
%5 = 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* %5, i32** %4
%6 = load i32*, i32** %4
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %9
8: ; preds = %0
store i32 -2, i32* %1
br label %27
9: ; preds = %0
br label %10
10: ; preds = %22, %9
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%12 = load i32*, i32** %4
%13 = call i32* @fgets(i8* %11, i32 128, i32* %12)
%14 = icmp ne i32* %13, null
br i1 %14, label %15, label %23
15: ; preds = %10
%16 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%17 = call i64 @strncmp(i8* %16, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 7)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%21 = call i32 @_parseLine(i8* %20)
store i32 %21, i32* %2
br label %23
22: ; preds = %15
br label %10
23: ; preds = %19, %10
%24 = load i32*, i32** %4
%25 = call i32 @fclose(i32* %24)
%26 = load i32, i32* %2
store i32 %26, i32* %1
br label %27
27: ; preds = %23, %8
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
@.str = [18 x i8] c"/proc/self/status\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [8 x i8] c"VmPeak:\00"
define i32 @get_vm_peak() {
%1 = alloca [128 x i8]
%2 = getelementptr inbounds [128 x i8], [128 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 %16, label %5
5: ; preds = %0, %8
%6 = call i32* @fgets(i8* %2, i32 128, i32* %3)
%7 = icmp eq i32* %6, null
br i1 %7, label %13, label %8
8: ; preds = %5
%9 = call i64 @strncmp(i8* %2, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 7)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %5
11: ; preds = %8
%12 = call i32 @_parseLine(i8* %2)
br label %13
13: ; preds = %5, %11
%14 = phi i32 [ %12, %11 ], [ -1, %5 ]
%15 = call i32 @fclose(i32* %3)
br label %16
16: ; preds = %0, %13
%17 = phi i32 [ %14, %13 ], [ -2, %0 ]
ret i32 %17
}