#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 */
scalar_t__ fabs(double);
int /*<<< orphan*/ pr_err(double *, double *, double, int, double, double *,
                          double *);
double positive_errors(double *pars, double *err, double d_max, int n_c,
                       int nslice) {
  double r;
  int i;
  double sum_pos = 0.0;
  double sum = 0.0;
  double pr_val;
  double pr_val_err;
  for (i = 0; i < nslice; i++) {
    r = d_max / (1.0 * nslice) * i;
    pr_err(pars, err, d_max, n_c, r, &pr_val, &pr_val_err);
    if (pr_val > pr_val_err)
      sum_pos += pr_val;
    sum += fabs(pr_val);
  }
  return sum_pos / sum;
}


x86 assembly (clang, -O0):
<positive_errors>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11ee <positive_errors+0xce>
movsd  -0x18(%rbp),%xmm0
cvtsi2sdl -0x20(%rbp),%xmm2
movsd  0xe90(%rip),%xmm1
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
cvtsi2sdl -0x2c(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movsd  -0x18(%rbp),%xmm0
mov    -0x1c(%rbp),%edx
movsd  -0x28(%rbp),%xmm1
lea    -0x48(%rbp),%rcx
lea    -0x50(%rbp),%r8
call   1040 <pr_err@plt>
movsd  -0x48(%rbp),%xmm0
ucomisd -0x50(%rbp),%xmm0
jbe    11c7 <positive_errors+0xa7>
movsd  -0x48(%rbp),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x48(%rbp),%xmm0
call   1030 <fabs@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1152 <positive_errors+0x32>
movsd  -0x38(%rbp),%xmm0
divsd  -0x40(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<positive_errors>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
movsd  %xmm0,0x10(%rsp)
test   %ecx,%ecx
jle    1230 <positive_errors+0x110>
mov    %ecx,%ebx
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbp
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
movsd  0x10(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rsp)
xorpd  %xmm0,%xmm0
lea    0x30(%rsp),%r12
lea    0x28(%rsp),%r13
xorpd  %xmm1,%xmm1
movsd  %xmm1,(%rsp)
xorpd  %xmm2,%xmm2
nopl   0x0(%rax)
movsd  %xmm2,0x20(%rsp)
movsd  %xmm0,0x8(%rsp)
movsd  0x18(%rsp),%xmm1
mulsd  %xmm2,%xmm1
mov    %rbp,%rdi
mov    %r15,%rsi
movsd  0x10(%rsp),%xmm0
mov    %r14d,%edx
mov    %r12,%rcx
mov    %r13,%r8
call   1040 <pr_err@plt>
movsd  0x30(%rsp),%xmm0
movsd  0x28(%rsp),%xmm1
cmpltsd %xmm0,%xmm1
movapd %xmm1,%xmm2
andpd  %xmm0,%xmm2
movsd  0xe37(%rip),%xmm3
andnpd %xmm3,%xmm1
orpd   %xmm2,%xmm1
movsd  (%rsp),%xmm2
addsd  %xmm1,%xmm2
movsd  %xmm2,(%rsp)
call   1030 <fabs@plt>
movsd  0x20(%rsp),%xmm2
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
addsd  0xdf8(%rip),%xmm2
add    $0xffffffff,%ebx
jne    1180 <positive_errors+0x60>
movsd  (%rsp),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
jmp    1238 <positive_errors+0x118>
movsd  0xdc8(%rip),%xmm0
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @positive_errors(double* %0, double* %1, double %2, i32 %3, i32 %4) {
%6 = alloca double*
%7 = alloca double*
%8 = alloca double
%9 = alloca i32
%10 = alloca i32
%11 = alloca double
%12 = alloca i32
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca double
store double* %0, double** %6
store double* %1, double** %7
store double %2, double* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
store double 0.000000e+00, double* %13
store double 0.000000e+00, double* %14
store i32 0, i32* %12
br label %17
17: ; preds = %49, %5
%18 = load i32, i32* %12
%19 = load i32, i32* %10
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %52
21: ; preds = %17
%22 = load double, double* %8
%23 = load i32, i32* %10
%24 = sitofp i32 %23 to double
%25 = fmul double 1.000000e+00, %24
%26 = fdiv double %22, %25
%27 = load i32, i32* %12
%28 = sitofp i32 %27 to double
%29 = fmul double %26, %28
store double %29, double* %11
%30 = load double*, double** %6
%31 = load double*, double** %7
%32 = load double, double* %8
%33 = load i32, i32* %9
%34 = load double, double* %11
%35 = call i32 @pr_err(double* %30, double* %31, double %32, i32 %33, double %34, double* %15, double* %16)
%36 = load double, double* %15
%37 = load double, double* %16
%38 = fcmp ogt double %36, %37
br i1 %38, label %39, label %43
39: ; preds = %21
%40 = load double, double* %15
%41 = load double, double* %13
%42 = fadd double %41, %40
store double %42, double* %13
br label %43
43: ; preds = %39, %21
%44 = load double, double* %15
%45 = call i64 @fabs(double %44)
%46 = sitofp i64 %45 to double
%47 = load double, double* %14
%48 = fadd double %47, %46
store double %48, double* %14
br label %49
49: ; preds = %43
%50 = load i32, i32* %12
%51 = add nsw i32 %50, 1
store i32 %51, i32* %12
br label %17
52: ; preds = %17
%53 = load double, double* %13
%54 = load double, double* %14
%55 = fdiv double %53, %54
ret double %55
}

LLVM IR (-O2):
define double @positive_errors(double* %0, double* %1, double %2, i32 %3, i32 %4) {
%6 = alloca double
%7 = alloca double
%8 = bitcast double* %6 to i8*
%9 = bitcast double* %7 to i8*
%10 = icmp sgt i32 %4, 0
br i1 %10, label %11, label %33
11: ; preds = %5
%12 = sitofp i32 %4 to double
%13 = fdiv double %2, %12
br label %14
14: ; preds = %11, %14
%15 = phi double [ 0.000000e+00, %11 ], [ %28, %14 ]
%16 = phi double [ 0.000000e+00, %11 ], [ %25, %14 ]
%17 = phi i32 [ 0, %11 ], [ %29, %14 ]
%18 = sitofp i32 %17 to double
%19 = fmul double %13, %18
%20 = call i32 @pr_err(double* %0, double* %1, double %2, i32 %3, double %19, double* %6, double* %7)
%21 = load double, double* %6
%22 = load double, double* %7
%23 = fcmp ogt double %21, %22
%24 = select i1 %23, double %21, double -0.000000e+00
%25 = fadd double %16, %24
%26 = call i64 @fabs(double %21)
%27 = sitofp i64 %26 to double
%28 = fadd double %15, %27
%29 = add nuw nsw i32 %17, 1
%30 = icmp eq i32 %29, %4
br i1 %30, label %31, label %14
31: ; preds = %14
%32 = fdiv double %25, %28
br label %33
33: ; preds = %31, %5
%34 = phi double [ %32, %31 ], [ 0x7FF8000000000000, %5 ]
ret double %34
}