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


x86 assembly (clang, -O0):
<rg>:
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,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11db <rg+0xbb>
movsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x18(%rbp),%xmm2
movsd  0xe9c(%rip),%xmm1
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
cvtsi2sdl -0x3c(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
mov    -0x14(%rbp),%esi
movsd  -0x30(%rbp),%xmm1
call   1030 <pr@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x30(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    114e <rg+0x2e>
movsd  -0x20(%rbp),%xmm0
movsd  0xe18(%rip),%xmm1
mulsd  -0x28(%rbp),%xmm1
divsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rg>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
movsd  %xmm0,(%rsp)
test   %edx,%edx
jle    11d1 <rg+0xb1>
mov    %edx,%ebx
mov    %esi,%r14d
mov    %rdi,%rbp
xorps  %xmm0,%xmm0
cvtsi2sd %edx,%xmm0
movsd  (%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
xorpd  %xmm0,%xmm0
xorpd  %xmm1,%xmm1
xorpd  %xmm2,%xmm2
nop
movsd  %xmm2,0x18(%rsp)
movsd  %xmm0,0x20(%rsp)
movsd  %xmm1,0x28(%rsp)
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
mov    %rbp,%rdi
movsd  (%rsp),%xmm0
mov    %r14d,%esi
call   1030 <pr@plt>
movsd  0x18(%rsp),%xmm2
movsd  0x28(%rsp),%xmm1
addsd  %xmm0,%xmm2
movsd  0x10(%rsp),%xmm3
mulsd  %xmm3,%xmm3
mulsd  %xmm0,%xmm3
movsd  0x20(%rsp),%xmm0
addsd  %xmm3,%xmm1
addsd  0xe46(%rip),%xmm0
add    $0xffffffff,%ebx
jne    1160 <rg+0x40>
addsd  %xmm2,%xmm2
divsd  %xmm2,%xmm1
jmp    11d9 <rg+0xb9>
movsd  0xe27(%rip),%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jb     11f3 <rg+0xd3>
xorps  %xmm0,%xmm0
sqrtsd %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
movapd %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <sqrt@plt>

LLVM IR (-O0):
define double @rg(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 double
%12 = alloca double
%13 = alloca i32
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* %9
store double 0.000000e+00, double* %10
store i32 0, i32* %13
br label %14
14: ; preds = %41, %4
%15 = load i32, i32* %13
%16 = load i32, i32* %8
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %44
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* %13
%25 = sitofp i32 %24 to double
%26 = fmul double %23, %25
store double %26, double* %11
%27 = load double*, double** %5
%28 = load double, double* %6
%29 = load i32, i32* %7
%30 = load double, double* %11
%31 = call double @pr(double* %27, double %28, i32 %29, double %30)
store double %31, double* %12
%32 = load double, double* %12
%33 = load double, double* %10
%34 = fadd double %33, %32
store double %34, double* %10
%35 = load double, double* %11
%36 = load double, double* %11
%37 = fmul double %35, %36
%38 = load double, double* %12
%39 = load double, double* %9
%40 = call double @llvm.fmuladd.f64(double %37, double %38, double %39)
store double %40, double* %9
br label %41
41: ; preds = %18
%42 = load i32, i32* %13
%43 = add nsw i32 %42, 1
store i32 %43, i32* %13
br label %14
44: ; preds = %14
%45 = load double, double* %9
%46 = load double, double* %10
%47 = fmul double 2.000000e+00, %46
%48 = fdiv double %45, %47
%49 = call double @sqrt(double %48)
ret double %49
}

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