#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);
double pr(double *, double, int, double);
double positive_integral(double *pars, double d_max, int n_c, int nslice) {
  double r;
  double value;
  int i;
  double sum_pos = 0.0;
  double sum = 0.0;
  for (i = 0; i < nslice; i++) {
    r = d_max / (1.0 * nslice) * i;
    value = pr(pars, d_max, n_c, r);
    if (value > 0.0)
      sum_pos += value;
    sum += fabs(value);
  }
  return sum_pos / sum;
}


x86 assembly (clang, -O0):
<positive_integral>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11e5 <positive_integral+0xc5>
movsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x18(%rbp),%xmm2
movsd  0xe94(%rip),%xmm1
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
cvtsi2sdl -0x2c(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
mov    -0x14(%rbp),%esi
movsd  -0x20(%rbp),%xmm1
call   1030 <pr@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11be <positive_integral+0x9e>
movsd  -0x28(%rbp),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1040 <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    114e <positive_integral+0x2e>
movsd  -0x38(%rbp),%xmm0
divsd  -0x40(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<positive_integral>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
movsd  %xmm0,0x10(%rsp)
test   %edx,%edx
jle    11e9 <positive_integral+0xc9>
mov    %edx,%ebx
mov    %esi,%r14d
mov    %rdi,%rbp
xorps  %xmm0,%xmm0
cvtsi2sd %edx,%xmm0
movsd  0x10(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rsp)
xorpd  %xmm1,%xmm1
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
xorpd  %xmm0,%xmm0
nopw   0x0(%rax,%rax,1)
movsd  %xmm0,0x20(%rsp)
movsd  %xmm1,0x28(%rsp)
movsd  0x18(%rsp),%xmm1
mulsd  %xmm0,%xmm1
mov    %rbp,%rdi
movsd  0x10(%rsp),%xmm0
mov    %r14d,%esi
call   1030 <pr@plt>
movapd %xmm0,%xmm1
maxsd  0xe65(%rip),%xmm1
movsd  0x8(%rsp),%xmm2
addsd  %xmm1,%xmm2
movsd  %xmm2,0x8(%rsp)
call   1040 <fabs@plt>
movsd  0x28(%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  %xmm0,%xmm1
movsd  0x20(%rsp),%xmm0
addsd  0xe38(%rip),%xmm0
add    $0xffffffff,%ebx
jne    1170 <positive_integral+0x50>
movsd  0x8(%rsp),%xmm0
divsd  %xmm1,%xmm0
jmp    11f1 <positive_integral+0xd1>
movsd  0xe0f(%rip),%xmm0
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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