#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 pow(double, double);
double _acceleration_weighted(double *thetai, int n, double theta_hat,
                              const double *weights) {
  double a = 0;
  double sq = 0;
  double cb = 0;
  for (int i = 0; i < n; i++) {
    double diff = theta_hat - thetai[i];
    sq += diff * diff * weights[i];
    cb += diff * diff * diff * weights[i];
  }
  a = cb / (6.0 * pow(sq, 1.5));
  return a;
}


x86 assembly (clang, -O0):
<_acceleration_weighted>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11cf <_acceleration_weighted+0xbf>
movsd  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x3c(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
mulsd  -0x48(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x48(%rbp),%xmm0
mulsd  -0x48(%rbp),%xmm0
mulsd  -0x48(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x38(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1147 <_acceleration_weighted+0x37>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xe22(%rip),%xmm1
call   1030 <pow@plt>
movaps %xmm0,%xmm2
movsd  -0x50(%rbp),%xmm0
movsd  0xe05(%rip),%xmm1
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_acceleration_weighted>:
sub    $0x18,%rsp
test   %esi,%esi
jle    1133 <_acceleration_weighted+0x23>
mov    %esi,%ecx
cmp    $0x1,%esi
jne    113c <_acceleration_weighted+0x2c>
xorpd  %xmm1,%xmm1
xor    %eax,%eax
test   $0x1,%cl
jne    11bc <_acceleration_weighted+0xac>
jmp    11e2 <_acceleration_weighted+0xd2>
xorpd  %xmm4,%xmm4
jmp    11e2 <_acceleration_weighted+0xd2>
mov    %ecx,%esi
and    $0xfffffffe,%esi
xorpd  %xmm1,%xmm1
xor    %eax,%eax
nopw   0x0(%rax,%rax,1)
movapd %xmm0,%xmm2
subsd  (%rdi,%rax,8),%xmm2
movapd %xmm2,%xmm3
mulsd  %xmm2,%xmm3
mulsd  %xmm3,%xmm2
unpcklpd %xmm2,%xmm3
movsd  (%rdx,%rax,8),%xmm2
movsd  0x8(%rdx,%rax,8),%xmm4
unpcklpd %xmm2,%xmm2
mulpd  %xmm3,%xmm2
addpd  %xmm1,%xmm2
movapd %xmm0,%xmm1
subsd  0x8(%rdi,%rax,8),%xmm1
movapd %xmm1,%xmm3
mulsd  %xmm1,%xmm3
mulsd  %xmm3,%xmm1
unpcklpd %xmm1,%xmm3
unpcklpd %xmm4,%xmm4
mulpd  %xmm3,%xmm4
movapd %xmm4,%xmm1
addpd  %xmm2,%xmm1
add    $0x2,%rax
cmp    %rax,%rsi
jne    1150 <_acceleration_weighted+0x40>
addpd  %xmm2,%xmm4
test   $0x1,%cl
je     11e2 <_acceleration_weighted+0xd2>
subsd  (%rdi,%rax,8),%xmm0
movapd %xmm0,%xmm2
mulsd  %xmm0,%xmm2
mulsd  %xmm2,%xmm0
unpcklpd %xmm0,%xmm2
movsd  (%rdx,%rax,8),%xmm4
unpcklpd %xmm4,%xmm4
mulpd  %xmm2,%xmm4
addpd  %xmm1,%xmm4
movapd %xmm4,(%rsp)
movsd  0xe11(%rip),%xmm1
movapd %xmm4,%xmm0
call   1030 <pow@plt>
mulsd  0xe08(%rip),%xmm0
movapd (%rsp),%xmm1
unpckhpd %xmm1,%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x18,%rsp
ret

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

LLVM IR (-O2):
define double @_acceleration_weighted(double* nocapture %0, i32 %1, double %2, double* nocapture %3) {
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %32
6: ; preds = %4
%7 = zext i32 %1 to i64
%8 = and i64 %7, 1
%9 = icmp eq i32 %1, 1
br i1 %9, label %14, label %10
10: ; preds = %6
%11 = and i64 %7, 4294967294
br label %39
12: ; preds = %39
%13 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %64, <2 x double> %66, <2 x double> %54)
br label %14
14: ; preds = %12, %6
%15 = phi <2 x double> [ undef, %6 ], [ %13, %12 ]
%16 = phi i64 [ 0, %6 ], [ %68, %12 ]
%17 = phi <2 x double> [ zeroinitializer, %6 ], [ %67, %12 ]
%18 = icmp eq i64 %8, 0
br i1 %18, label %32, label %19
19: ; preds = %14
%20 = getelementptr inbounds double, double* %0, i64 %16
%21 = load double, double* %20
%22 = fsub double %2, %21
%23 = fmul double %22, %22
%24 = getelementptr inbounds double, double* %3, i64 %16
%25 = load double, double* %24
%26 = fmul double %22, %23
%27 = insertelement <2 x double> poison, double %23, i64 0
%28 = insertelement <2 x double> %27, double %26, i64 1
%29 = insertelement <2 x double> poison, double %25, i64 0
%30 = shufflevector <2 x double> %29, <2 x double> poison, <2 x i32> zeroinitializer
%31 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %28, <2 x double> %30, <2 x double> %17)
br label %32
32: ; preds = %19, %14, %4
%33 = phi <2 x double> [ zeroinitializer, %4 ], [ %15, %14 ], [ %31, %19 ]
%34 = extractelement <2 x double> %33, i64 0
%35 = tail call double @pow(double %34, double 1.500000e+00)
%36 = fmul double %35, 6.000000e+00
%37 = extractelement <2 x double> %33, i64 1
%38 = fdiv double %37, %36
ret double %38
39: ; preds = %39, %10
%40 = phi i64 [ 0, %10 ], [ %68, %39 ]
%41 = phi <2 x double> [ zeroinitializer, %10 ], [ %67, %39 ]
%42 = phi i64 [ 0, %10 ], [ %69, %39 ]
%43 = getelementptr inbounds double, double* %0, i64 %40
%44 = load double, double* %43
%45 = fsub double %2, %44
%46 = fmul double %45, %45
%47 = getelementptr inbounds double, double* %3, i64 %40
%48 = load double, double* %47
%49 = fmul double %45, %46
%50 = insertelement <2 x double> poison, double %46, i64 0
%51 = insertelement <2 x double> %50, double %49, i64 1
%52 = insertelement <2 x double> poison, double %48, i64 0
%53 = shufflevector <2 x double> %52, <2 x double> poison, <2 x i32> zeroinitializer
%54 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %51, <2 x double> %53, <2 x double> %41)
%55 = or i64 %40, 1
%56 = getelementptr inbounds double, double* %0, i64 %55
%57 = load double, double* %56
%58 = fsub double %2, %57
%59 = fmul double %58, %58
%60 = getelementptr inbounds double, double* %3, i64 %55
%61 = load double, double* %60
%62 = fmul double %58, %59
%63 = insertelement <2 x double> poison, double %59, i64 0
%64 = insertelement <2 x double> %63, double %62, i64 1
%65 = insertelement <2 x double> poison, double %61, i64 0
%66 = shufflevector <2 x double> %65, <2 x double> poison, <2 x i32> zeroinitializer
%67 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %64, <2 x double> %66, <2 x double> %54)
%68 = add nuw nsw i64 %40, 2
%69 = add i64 %42, 2
%70 = icmp eq i64 %69, %11
br i1 %70, label %12, label %39
}