#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*/ temp;
struct lineFile {
  int dummy;
};
typedef scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ chopByWhite(char *, char **, int);
scalar_t__ getpid();
int /*<<< orphan*/ lineFileClose(struct lineFile **);
struct lineFile *lineFileMayOpen(char *, int);
scalar_t__ lineFileNextReal(struct lineFile *, char **);
int /*<<< orphan*/ safef(char *, int, char *, int);
long long sqlLongLong(char *);
scalar_t__ strstr(char *, char *);
long long currentVmPeak() {
  long long vmPeak = 0;
  pid_t pid = getpid();
  char temp[256];
  safef(temp, sizeof(temp), "/proc/%d/status", (int)pid);
  struct lineFile *lf = lineFileMayOpen(temp, 1);
  if (lf) {
    char *line;
    while (lineFileNextReal(lf, &line)) {
      if (strstr(line, "VmPeak")) {
        char *words[3];
        chopByWhite(line, words, 3);
        vmPeak = sqlLongLong(words[1]);
        break;
      }
    }
    lineFileClose(&lf);
  }
  return vmPeak;
}


x86 assembly (clang, -O0):
<currentVmPeak>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movq   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %rax,-0x10(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    %eax,%ecx
mov    $0x100,%esi
lea    0xe49(%rip),%rdx
call   1070 <safef@plt>
lea    -0x110(%rbp),%rdi
mov    $0x1,%esi
call   1050 <lineFileMayOpen@plt>
mov    %rax,-0x118(%rbp)
cmpq   $0x0,-0x118(%rbp)
je     125f <currentVmPeak+0xdf>
jmp    11e7 <currentVmPeak+0x67>
mov    -0x118(%rbp),%rdi
lea    -0x120(%rbp),%rsi
call   1080 <lineFileNextReal@plt>
cmp    $0x0,%rax
je     1253 <currentVmPeak+0xd3>
mov    -0x120(%rbp),%rdi
lea    0xdfe(%rip),%rsi
call   10a0 <strstr@plt>
cmp    $0x0,%rax
je     124e <currentVmPeak+0xce>
mov    -0x120(%rbp),%rdi
lea    -0x140(%rbp),%rsi
mov    $0x3,%edx
call   1060 <chopByWhite@plt>
mov    -0x138(%rbp),%rdi
call   1090 <sqlLongLong@plt>
mov    %rax,-0x8(%rbp)
jmp    1253 <currentVmPeak+0xd3>
jmp    11e7 <currentVmPeak+0x67>
lea    -0x118(%rbp),%rdi
call   1030 <lineFileClose@plt>
mov    -0x8(%rbp),%rax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<currentVmPeak>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x138,%rsp
xor    %r14d,%r14d
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe61(%rip),%rdx
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %eax,%ecx
call   1070 <safef@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1050 <lineFileMayOpen@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     122b <currentVmPeak+0xab>
mov    %rax,%rbx
mov    %rsp,%r15
xor    %r14d,%r14d
lea    0xe36(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1080 <lineFileNextReal@plt>
test   %rax,%rax
je     1221 <currentVmPeak+0xa1>
mov    (%rsp),%rdi
mov    %r12,%rsi
call   10a0 <strstr@plt>
test   %rax,%rax
je     11e0 <currentVmPeak+0x60>
mov    (%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    $0x3,%edx
call   1060 <chopByWhite@plt>
mov    0x18(%rsp),%rdi
call   1090 <sqlLongLong@plt>
mov    %rax,%r14
lea    0x8(%rsp),%rdi
call   1030 <lineFileClose@plt>
mov    %r14,%rax
add    $0x138,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.lineFile = type { i32 }
@.str = [16 x i8] c"/proc/%d/status\00"
@.str.1 = [7 x i8] c"VmPeak\00"
define i64 @currentVmPeak() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca [256 x i8]
%4 = alloca %struct.lineFile*
%5 = alloca i8*
%6 = alloca [3 x i8*]
store i64 0, i64* %1
%7 = call i64 (...) @getpid()
store i64 %7, i64* %2
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%9 = load i64, i64* %2
%10 = trunc i64 %9 to i32
%11 = call i32 @safef(i8* %8, i32 256, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%13 = call %struct.lineFile* @lineFileMayOpen(i8* %12, i32 1)
store %struct.lineFile* %13, %struct.lineFile** %4
%14 = load %struct.lineFile*, %struct.lineFile** %4
%15 = icmp ne %struct.lineFile* %14, null
br i1 %15, label %16, label %35
16: ; preds = %0
br label %17
17: ; preds = %32, %16
%18 = load %struct.lineFile*, %struct.lineFile** %4
%19 = call i64 @lineFileNextReal(%struct.lineFile* %18, i8** %5)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %33
21: ; preds = %17
%22 = load i8*, i8** %5
%23 = call i64 @strstr(i8* %22, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %32
25: ; preds = %21
%26 = load i8*, i8** %5
%27 = getelementptr inbounds [3 x i8*], [3 x i8*]* %6, i64 0, i64 0
%28 = call i32 @chopByWhite(i8* %26, i8** %27, i32 3)
%29 = getelementptr inbounds [3 x i8*], [3 x i8*]* %6, i64 0, i64 1
%30 = load i8*, i8** %29
%31 = call i64 @sqlLongLong(i8* %30)
store i64 %31, i64* %1
br label %33
32: ; preds = %21
br label %17
33: ; preds = %25, %17
%34 = call i32 @lineFileClose(%struct.lineFile** %4)
br label %35
35: ; preds = %33, %0
%36 = load i64, i64* %1
ret i64 %36
}

LLVM IR (-O2):
%struct.lineFile = type { i32 }
@.str = [16 x i8] c"/proc/%d/status\00"
@.str.1 = [7 x i8] c"VmPeak\00"
define i64 @currentVmPeak() {
%1 = alloca [256 x i8]
%2 = alloca %struct.lineFile*
%3 = alloca i8*
%4 = alloca [3 x i8*]
%5 = tail call i64 (...) @getpid()
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%7 = trunc i64 %5 to i32
%8 = call i32 @safef(i8* %6, i32 256, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = bitcast %struct.lineFile** %2 to i8*
%10 = call %struct.lineFile* @lineFileMayOpen(i8* %6, i32 1)
store %struct.lineFile* %10, %struct.lineFile** %2
%11 = icmp eq %struct.lineFile* %10, null
br i1 %11, label %32, label %12
12: ; preds = %0
%13 = bitcast i8** %3 to i8*
br label %14
14: ; preds = %17, %12
%15 = call i64 @lineFileNextReal(%struct.lineFile* %10, i8** %3)
%16 = icmp eq i64 %15, 0
br i1 %16, label %29, label %17
17: ; preds = %14
%18 = load i8*, i8** %3
%19 = call i64 @strstr(i8* %18, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %14, label %21
21: ; preds = %17
%22 = bitcast [3 x i8*]* %4 to i8*
%23 = load i8*, i8** %3
%24 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 0
%25 = call i32 @chopByWhite(i8* %23, i8** %24, i32 3)
%26 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 1
%27 = load i8*, i8** %26
%28 = call i64 @sqlLongLong(i8* %27)
br label %29
29: ; preds = %14, %21
%30 = phi i64 [ %28, %21 ], [ 0, %14 ]
%31 = call i32 @lineFileClose(%struct.lineFile** %2)
br label %32
32: ; preds = %29, %0
%33 = phi i64 [ %30, %29 ], [ 0, %0 ]
ret i64 %33
}