#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 calc_dmin(double **, size_t, size_t);
int /*<<< orphan*/ printf(char *, ...);
void show_bad_prob(double **p, size_t n, size_t ndim) {
  size_t i;
  double di_min, d_max = 0, d_avg = 0;
  for (i = 0; i < n; i++) {
    di_min = calc_dmin(p, ndim, i);
    if (di_min > d_max)
      d_max = di_min;
    d_avg += di_min;
  }
  d_avg /= n;
  printf("p: d_max = %f\n", d_max);
  printf("p: d_avg = %f\n", d_avg);
  printf("\n");
}


x86 assembly (clang, -O0):
<show_bad_prob>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11aa <show_bad_prob+0x8a>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <calc_dmin@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
ucomisd -0x30(%rbp),%xmm0
jbe    118a <show_bad_prob+0x6a>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    114c <show_bad_prob+0x2c>
movaps 0xe4f(%rip),%xmm0
movq   -0x10(%rbp),%xmm1
punpckldq %xmm0,%xmm1
movapd 0xe4e(%rip),%xmm0
subpd  %xmm0,%xmm1
movaps %xmm1,%xmm0
unpckhpd %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
lea    0xe35(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  -0x38(%rbp),%xmm0
lea    0xe31(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_bad_prob>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
test   %rsi,%rsi
je     1199 <show_bad_prob+0x69>
mov    %rdx,%r15
mov    %rdi,%r12
xorpd  %xmm3,%xmm3
xor    %ebx,%ebx
xorpd  %xmm1,%xmm1
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  %xmm1,0x10(%rsp)
movsd  %xmm3,0x8(%rsp)
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1050 <calc_dmin@plt>
movsd  0x8(%rsp),%xmm3
addsd  %xmm0,%xmm3
maxsd  0x10(%rsp),%xmm0
add    $0x1,%rbx
movapd %xmm0,%xmm1
cmp    %rbx,%r14
jne    1160 <show_bad_prob+0x30>
jmp    11a1 <show_bad_prob+0x71>
xorpd  %xmm0,%xmm0
xorpd  %xmm3,%xmm3
movq   %r14,%xmm1
punpckldq 0xe52(%rip),%xmm1
subpd  0xe5a(%rip),%xmm1
movapd %xmm1,%xmm2
unpckhpd %xmm1,%xmm2
addsd  %xmm1,%xmm2
divsd  %xmm2,%xmm3
movsd  %xmm3,0x8(%rsp)
lea    0xe4d(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xe4e(%rip),%rdi
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1040 <printf@plt>
mov    $0xa,%edi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"p: d_max = %f\0A\00"
@.str.1 = [15 x i8] c"p: d_avg = %f\0A\00"
@.str.2 = [2 x i8] c"\0A\00"
define void @show_bad_prob(double** %0, i64 %1, i64 %2) {
%4 = alloca double**
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca double
%9 = alloca double
%10 = alloca double
store double** %0, double*** %4
store i64 %1, i64* %5
store i64 %2, i64* %6
store double 0.000000e+00, double* %9
store double 0.000000e+00, double* %10
store i64 0, i64* %7
br label %11
11: ; preds = %29, %3
%12 = load i64, i64* %7
%13 = load i64, i64* %5
%14 = icmp ult i64 %12, %13
br i1 %14, label %15, label %32
15: ; preds = %11
%16 = load double**, double*** %4
%17 = load i64, i64* %6
%18 = load i64, i64* %7
%19 = call double @calc_dmin(double** %16, i64 %17, i64 %18)
store double %19, double* %8
%20 = load double, double* %8
%21 = load double, double* %9
%22 = fcmp ogt double %20, %21
br i1 %22, label %23, label %25
23: ; preds = %15
%24 = load double, double* %8
store double %24, double* %9
br label %25
25: ; preds = %23, %15
%26 = load double, double* %8
%27 = load double, double* %10
%28 = fadd double %27, %26
store double %28, double* %10
br label %29
29: ; preds = %25
%30 = load i64, i64* %7
%31 = add i64 %30, 1
store i64 %31, i64* %7
br label %11
32: ; preds = %11
%33 = load i64, i64* %5
%34 = uitofp i64 %33 to double
%35 = load double, double* %10
%36 = fdiv double %35, %34
store double %36, double* %10
%37 = load double, double* %9
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), double %37)
%39 = load double, double* %10
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), double %39)
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"p: d_max = %f\0A\00"
@.str.1 = [15 x i8] c"p: d_avg = %f\0A\00"
define void @show_bad_prob(double** %0, i64 %1, i64 %2) {
%4 = icmp eq i64 %1, 0
br i1 %4, label %15, label %5
5: ; preds = %3, %5
%6 = phi double [ %12, %5 ], [ 0.000000e+00, %3 ]
%7 = phi double [ %11, %5 ], [ 0.000000e+00, %3 ]
%8 = phi i64 [ %13, %5 ], [ 0, %3 ]
%9 = tail call double @calc_dmin(double** %0, i64 %2, i64 %8)
%10 = fcmp ogt double %9, %7
%11 = select i1 %10, double %9, double %7
%12 = fadd double %6, %9
%13 = add nuw i64 %8, 1
%14 = icmp eq i64 %13, %1
br i1 %14, label %15, label %5
15: ; preds = %5, %3
%16 = phi double [ 0.000000e+00, %3 ], [ %11, %5 ]
%17 = phi double [ 0.000000e+00, %3 ], [ %12, %5 ]
%18 = uitofp i64 %1 to double
%19 = fdiv double %17, %18
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), double %16)
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), double %19)
%22 = tail call i32 @putchar(i32 10)
ret void
}