#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 */

/* Variables and functions */
double get_mem_usage();
int /*<<< orphan*/ mpp_max_double(int, double *);
int /*<<< orphan*/ mpp_min_double(int, double *);
double mpp_npes();
scalar_t__ mpp_pe();
scalar_t__ mpp_root_pe();
int /*<<< orphan*/ mpp_sum_double(int, double *);
int /*<<< orphan*/ printf(char *, char const *, double, double, double);
void print_mem_usage(const char *text) {
  double m, mmin, mmax, mavg;
  m = get_mem_usage();
  mmin = m;
  mmax = m;
  mavg = m;
  mpp_min_double(1, &mmin);
  mpp_max_double(1, &mmax);
  mpp_sum_double(1, &mavg);
  mavg /= mpp_npes();
  if (mpp_pe() == mpp_root_pe()) {
    printf("Memuse(MB) at %s, min=%g, max=%g, avg=%g\n", text, mmin, mmax,
           mavg);
  }
}


x86 assembly (clang, -O0):
<print_mem_usage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1080 <get_mem_usage@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    $0x1,%edi
lea    -0x18(%rbp),%rsi
call   10a0 <mpp_min_double@plt>
mov    $0x1,%edi
lea    -0x20(%rbp),%rsi
call   1040 <mpp_max_double@plt>
mov    $0x1,%edi
lea    -0x28(%rbp),%rsi
call   1030 <mpp_sum_double@plt>
mov    $0x0,%al
call   1090 <mpp_npes@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    $0x0,%al
call   1070 <mpp_pe@plt>
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1050 <mpp_root_pe@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
cmp    %rcx,%rax
jne    1239 <print_mem_usage+0xb9>
mov    -0x8(%rbp),%rsi
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
lea    0xdcc(%rip),%rdi
call   1060 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_mem_usage>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
xor    %eax,%eax
call   1080 <get_mem_usage@plt>
movsd  %xmm0,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
movsd  %xmm0,(%rsp)
lea    0x10(%rsp),%rsi
mov    $0x1,%edi
call   10a0 <mpp_min_double@plt>
lea    0x8(%rsp),%rsi
mov    $0x1,%edi
call   1040 <mpp_max_double@plt>
mov    %rsp,%rsi
mov    $0x1,%edi
call   1030 <mpp_sum_double@plt>
xor    %eax,%eax
call   1090 <mpp_npes@plt>
movsd  (%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
xor    %eax,%eax
call   1070 <mpp_pe@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <mpp_root_pe@plt>
cmp    %rax,%rbx
jne    1218 <print_mem_usage+0x98>
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
movsd  (%rsp),%xmm2
lea    0xdf0(%rip),%rdi
mov    %r14,%rsi
call   1060 <printf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [42 x i8] c"Memuse(MB) at %s, min=%g, max=%g, avg=%g\0A\00"
define void @print_mem_usage(i8* %0) {
%2 = alloca i8*
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
store i8* %0, i8** %2
%7 = call double (...) @get_mem_usage()
store double %7, double* %3
%8 = load double, double* %3
store double %8, double* %4
%9 = load double, double* %3
store double %9, double* %5
%10 = load double, double* %3
store double %10, double* %6
%11 = call i32 @mpp_min_double(i32 1, double* %4)
%12 = call i32 @mpp_max_double(i32 1, double* %5)
%13 = call i32 @mpp_sum_double(i32 1, double* %6)
%14 = call double (...) @mpp_npes()
%15 = load double, double* %6
%16 = fdiv double %15, %14
store double %16, double* %6
%17 = call i64 (...) @mpp_pe()
%18 = call i64 (...) @mpp_root_pe()
%19 = icmp eq i64 %17, %18
br i1 %19, label %20, label %26
20: ; preds = %1
%21 = load i8*, i8** %2
%22 = load double, double* %4
%23 = load double, double* %5
%24 = load double, double* %6
%25 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %21, double %22, double %23, double %24)
br label %26
26: ; preds = %20, %1
ret void
}

LLVM IR (-O2):
@.str = [42 x i8] c"Memuse(MB) at %s, min=%g, max=%g, avg=%g\0A\00"
define void @print_mem_usage(i8* %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = bitcast double* %2 to i8*
%6 = bitcast double* %3 to i8*
%7 = bitcast double* %4 to i8*
%8 = tail call double (...) @get_mem_usage()
store double %8, double* %2
store double %8, double* %3
store double %8, double* %4
%9 = call i32 @mpp_min_double(i32 1, double* %2)
%10 = call i32 @mpp_max_double(i32 1, double* %3)
%11 = call i32 @mpp_sum_double(i32 1, double* %4)
%12 = call double (...) @mpp_npes()
%13 = load double, double* %4
%14 = fdiv double %13, %12
store double %14, double* %4
%15 = call i64 (...) @mpp_pe()
%16 = call i64 (...) @mpp_root_pe()
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %23
18: ; preds = %1
%19 = load double, double* %2
%20 = load double, double* %3
%21 = load double, double* %4
%22 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %0, double %19, double %20, double %21)
br label %23
23: ; preds = %18, %1
ret void
}