#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*/ *fopen(char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, ...);
scalar_t__ strncmp(char *, char *, int);
double VmHWM(void) {
  char word[1024];
  FILE *f = fopen("/proc/self/status", "r");
  double res;
  if (!f)
    return -1.0;
  while (1) {
    if (fscanf(f, "%1023s", word) < 0) {
      fclose(f);
      return -1.0;
    }
    if (!strncmp(word, "VmHWM:", 6)) {
      if (fscanf(f, "%lf%2s", &res, word) < 0) {
        fclose(f);
        return -1.0;
      }
      if (strncmp(word, "kB", 2)) {
        fclose(f);
        return -1.0;
      }
      res *= 1024;
      fclose(f);
      return res;
    }
  }
}


x86 assembly (clang, -O0):
<VmHWM>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
lea    0xebe(%rip),%rdi
lea    0xec9(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
jne    1185 <VmHWM+0x45>
movsd  0xe85(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12b6 <VmHWM+0x176>
jmp    118a <VmHWM+0x4a>
mov    -0x418(%rbp),%rdi
lea    -0x410(%rbp),%rdx
lea    0xe85(%rip),%rsi
mov    $0x0,%al
call   1050 <fscanf@plt>
cmp    $0x0,%rax
jge    11ce <VmHWM+0x8e>
mov    -0x418(%rbp),%rdi
call   1040 <fclose@plt>
movsd  0xe3c(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12b6 <VmHWM+0x176>
lea    -0x410(%rbp),%rdi
lea    0xe4f(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    12b1 <VmHWM+0x171>
mov    -0x418(%rbp),%rdi
lea    -0x410(%rbp),%rcx
lea    0xe2d(%rip),%rsi
lea    -0x420(%rbp),%rdx
mov    $0x0,%al
call   1050 <fscanf@plt>
cmp    $0x0,%rax
jge    123b <VmHWM+0xfb>
mov    -0x418(%rbp),%rdi
call   1040 <fclose@plt>
movsd  0xdcf(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12b6 <VmHWM+0x176>
lea    -0x410(%rbp),%rdi
lea    0xdf0(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     127b <VmHWM+0x13b>
mov    -0x418(%rbp),%rdi
call   1040 <fclose@plt>
movsd  0xd8f(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12b6 <VmHWM+0x176>
movsd  0xd85(%rip),%xmm0
mulsd  -0x420(%rbp),%xmm0
ff
movsd  %xmm0,-0x420(%rbp)
ff
mov    -0x418(%rbp),%rdi
call   1040 <fclose@plt>
movsd  -0x420(%rbp),%xmm0
ff
movsd  %xmm0,-0x8(%rbp)
jmp    12b6 <VmHWM+0x176>
jmp    118a <VmHWM+0x4a>
movsd  -0x8(%rbp),%xmm0
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<VmHWM>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x418,%rsp
lea    0xebb(%rip),%rdi
lea    0xec6(%rip),%rsi
call   1060 <fopen@plt>
movsd  0xe97(%rip),%xmm0
test   %rax,%rax
je     1205 <VmHWM+0xc5>
mov    %rax,%r15
lea    0xea8(%rip),%r14
lea    0x10(%rsp),%rbx
lea    0xea3(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <fscanf@plt>
test   %rax,%rax
js     11f5 <VmHWM+0xb5>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1190 <VmHWM+0x50>
lea    0xe71(%rip),%rsi
lea    0x8(%rsp),%rdx
lea    0x10(%rsp),%rcx
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <fscanf@plt>
test   %rax,%rax
js     11f5 <VmHWM+0xb5>
lea    0xe58(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1214 <VmHWM+0xd4>
mov    %r15,%rdi
call   1040 <fclose@plt>
movsd  0xdfb(%rip),%xmm0
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
movsd  0x8(%rsp),%xmm0
mulsd  0xde6(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %r15,%rdi
call   1040 <fclose@plt>
movsd  0x8(%rsp),%xmm0
jmp    1205 <VmHWM+0xc5>

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"%1023s\00"
@.str.3 = [7 x i8] c"VmHWM:\00"
@.str.4 = [7 x i8] c"%lf%2s\00"
@.str.5 = [3 x i8] c"kB\00"
define double @VmHWM() {
%1 = alloca double
%2 = alloca [1024 x i8]
%3 = alloca i32*
%4 = alloca double
%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** %3
%6 = load i32*, i32** %3
%7 = icmp ne i32* %6, null
br i1 %7, label %9, label %8
8: ; preds = %0
store double -1.000000e+00, double* %1
br label %44
9: ; preds = %0
br label %10
10: ; preds = %9, %43
%11 = load i32*, i32** %3
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%13 = call i64 (i32*, i8*, ...) @fscanf(i32* %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = load i32*, i32** %3
%17 = call i32 @fclose(i32* %16)
store double -1.000000e+00, double* %1
br label %44
18: ; preds = %10
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%20 = call i64 @strncmp(i8* %19, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 6)
%21 = icmp ne i64 %20, 0
br i1 %21, label %43, label %22
22: ; preds = %18
%23 = load i32*, i32** %3
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%25 = call i64 (i32*, i8*, ...) @fscanf(i32* %23, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), double* %4, i8* %24)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = load i32*, i32** %3
%29 = call i32 @fclose(i32* %28)
store double -1.000000e+00, double* %1
br label %44
30: ; preds = %22
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%32 = call i64 @strncmp(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 2)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = load i32*, i32** %3
%36 = call i32 @fclose(i32* %35)
store double -1.000000e+00, double* %1
br label %44
37: ; preds = %30
%38 = load double, double* %4
%39 = fmul double %38, 1.024000e+03
store double %39, double* %4
%40 = load i32*, i32** %3
%41 = call i32 @fclose(i32* %40)
%42 = load double, double* %4
store double %42, double* %1
br label %44
43: ; preds = %18
br label %10
44: ; preds = %37, %34, %27, %15, %8
%45 = load double, double* %1
ret double %45
}

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"%1023s\00"
@.str.3 = [7 x i8] c"VmHWM:\00"
@.str.4 = [7 x i8] c"%lf%2s\00"
@.str.5 = [3 x i8] c"kB\00"
define double @VmHWM() {
%1 = alloca [1024 x i8]
%2 = alloca double
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%4 = 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))
%5 = bitcast double* %2 to i8*
%6 = icmp eq i32* %4, null
br i1 %6, label %30, label %7
7: ; preds = %0, %12
%8 = call i64 (i32*, i8*, ...) @fscanf(i32* %4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = call i32 @fclose(i32* %4)
br label %30
12: ; preds = %7
%13 = call i64 @strncmp(i8* %3, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 6)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %7
15: ; preds = %12
%16 = call i64 (i32*, i8*, ...) @fscanf(i32* %4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), double* %2, i8* %3)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = call i32 @fclose(i32* %4)
br label %30
20: ; preds = %15
%21 = call i64 @strncmp(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 2)
%22 = icmp eq i64 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %20
%24 = call i32 @fclose(i32* %4)
br label %30
25: ; preds = %20
%26 = load double, double* %2
%27 = fmul double %26, 1.024000e+03
store double %27, double* %2
%28 = call i32 @fclose(i32* %4)
%29 = load double, double* %2
br label %30
30: ; preds = %0, %25, %23, %18, %10
%31 = phi double [ -1.000000e+00, %10 ], [ -1.000000e+00, %18 ], [ -1.000000e+00, %23 ], [ %29, %25 ], [ -1.000000e+00, %0 ]
ret double %31
}