#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 array_weighted_mean(double *, double *, int);
double array_weighted_stddev(double *, double *, int);
void array_force_weighted_stddev(double *a, double *w, int n,
                                 double newstddev) {
  double mean, oldstddev, f;
  int i;
  mean = array_weighted_mean(a, w, n);
  oldstddev = array_weighted_stddev(a, w, n);
  f = newstddev / oldstddev;
  for (i = 0; i < n; i++)
    a[i] = mean + (a[i] - mean) * f;
}


x86 assembly (clang, -O0):
<array_force_weighted_stddev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <array_weighted_mean@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <array_weighted_stddev@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
divsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11c3 <array_force_weighted_stddev+0xa3>
movsd  -0x28(%rbp),%xmm1
mov    -0x8(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x28(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1178 <array_force_weighted_stddev+0x58>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<array_force_weighted_stddev>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
movapd %xmm0,0x10(%rsp)
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <array_weighted_mean@plt>
movapd %xmm0,(%rsp)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1040 <array_weighted_stddev@plt>
movapd (%rsp),%xmm7
movapd 0x10(%rsp),%xmm6
test   %ebp,%ebp
jle    127f <array_force_weighted_stddev+0x15f>
divsd  %xmm0,%xmm6
mov    %ebp,%eax
cmp    $0x4,%ebp
jae    1172 <array_force_weighted_stddev+0x52>
xor    %ecx,%ecx
jmp    1260 <array_force_weighted_stddev+0x140>
mov    %eax,%ecx
and    $0xfffffffc,%ecx
movapd %xmm7,%xmm0
unpcklpd %xmm7,%xmm0
movapd %xmm6,%xmm1
unpcklpd %xmm6,%xmm1
lea    -0x4(%rcx),%rdx
mov    %rdx,%rsi
shr    $0x2,%rsi
add    $0x1,%rsi
test   %rdx,%rdx
je     1288 <array_force_weighted_stddev+0x168>
mov    %rsi,%rdi
and    $0xfffffffffffffffe,%rdi
xor    %edx,%edx
nopl   0x0(%rax,%rax,1)
movupd (%rbx,%rdx,8),%xmm2
movupd 0x10(%rbx,%rdx,8),%xmm3
movupd 0x20(%rbx,%rdx,8),%xmm4
movupd 0x30(%rbx,%rdx,8),%xmm5
subpd  %xmm0,%xmm2
subpd  %xmm0,%xmm3
mulpd  %xmm1,%xmm2
addpd  %xmm0,%xmm2
mulpd  %xmm1,%xmm3
addpd  %xmm0,%xmm3
movupd %xmm2,(%rbx,%rdx,8)
movupd %xmm3,0x10(%rbx,%rdx,8)
subpd  %xmm0,%xmm4
subpd  %xmm0,%xmm5
mulpd  %xmm1,%xmm4
addpd  %xmm0,%xmm4
mulpd  %xmm1,%xmm5
addpd  %xmm0,%xmm5
movupd %xmm4,0x20(%rbx,%rdx,8)
movupd %xmm5,0x30(%rbx,%rdx,8)
add    $0x8,%rdx
add    $0xfffffffffffffffe,%rdi
jne    11b0 <array_force_weighted_stddev+0x90>
test   $0x1,%sil
je     124c <array_force_weighted_stddev+0x12c>
movupd (%rbx,%rdx,8),%xmm2
movupd 0x10(%rbx,%rdx,8),%xmm3
subpd  %xmm0,%xmm2
subpd  %xmm0,%xmm3
mulpd  %xmm1,%xmm2
addpd  %xmm0,%xmm2
mulpd  %xmm1,%xmm3
addpd  %xmm0,%xmm3
movupd %xmm2,(%rbx,%rdx,8)
movupd %xmm3,0x10(%rbx,%rdx,8)
cmp    %rax,%rcx
je     127f <array_force_weighted_stddev+0x15f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  (%rbx,%rcx,8),%xmm0
subsd  %xmm7,%xmm0
mulsd  %xmm6,%xmm0
addsd  %xmm7,%xmm0
movsd  %xmm0,(%rbx,%rcx,8)
add    $0x1,%rcx
cmp    %rcx,%rax
jne    1260 <array_force_weighted_stddev+0x140>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %edx,%edx
test   $0x1,%sil
jne    121e <array_force_weighted_stddev+0xfe>
jmp    124c <array_force_weighted_stddev+0x12c>

LLVM IR (-O0):
define void @array_force_weighted_stddev(double* %0, double* %1, i32 %2, double %3) {
%5 = alloca double*
%6 = alloca double*
%7 = alloca i32
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca i32
store double* %0, double** %5
store double* %1, double** %6
store i32 %2, i32* %7
store double %3, double* %8
%13 = load double*, double** %5
%14 = load double*, double** %6
%15 = load i32, i32* %7
%16 = call double @array_weighted_mean(double* %13, double* %14, i32 %15)
store double %16, double* %9
%17 = load double*, double** %5
%18 = load double*, double** %6
%19 = load i32, i32* %7
%20 = call double @array_weighted_stddev(double* %17, double* %18, i32 %19)
store double %20, double* %10
%21 = load double, double* %8
%22 = load double, double* %10
%23 = fdiv double %21, %22
store double %23, double* %11
store i32 0, i32* %12
br label %24
24: ; preds = %43, %4
%25 = load i32, i32* %12
%26 = load i32, i32* %7
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %46
28: ; preds = %24
%29 = load double, double* %9
%30 = load double*, double** %5
%31 = load i32, i32* %12
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds double, double* %30, i64 %32
%34 = load double, double* %33
%35 = load double, double* %9
%36 = fsub double %34, %35
%37 = load double, double* %11
%38 = call double @llvm.fmuladd.f64(double %36, double %37, double %29)
%39 = load double*, double** %5
%40 = load i32, i32* %12
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double, double* %39, i64 %41
store double %38, double* %42
br label %43
43: ; preds = %28
%44 = load i32, i32* %12
%45 = add nsw i32 %44, 1
store i32 %45, i32* %12
br label %24
46: ; preds = %24
ret void
}

LLVM IR (-O2):
define void @array_force_weighted_stddev(double* %0, double* %1, i32 %2, double %3) {
%5 = tail call double @array_weighted_mean(double* %0, double* %1, i32 %2)
%6 = tail call double @array_weighted_stddev(double* %0, double* %1, i32 %2)
%7 = fdiv double %3, %6
%8 = icmp sgt i32 %2, 0
br i1 %8, label %9, label %88
9: ; preds = %4
%10 = zext i32 %2 to i64
%11 = icmp ult i32 %2, 4
br i1 %11, label %78, label %12
12: ; preds = %9
%13 = and i64 %10, 4294967292
%14 = insertelement <2 x double> poison, double %5, i64 0
%15 = shufflevector <2 x double> %14, <2 x double> poison, <2 x i32> zeroinitializer
%16 = insertelement <2 x double> poison, double %5, i64 0
%17 = shufflevector <2 x double> %16, <2 x double> poison, <2 x i32> zeroinitializer
%18 = insertelement <2 x double> poison, double %7, i64 0
%19 = shufflevector <2 x double> %18, <2 x double> poison, <2 x i32> zeroinitializer
%20 = insertelement <2 x double> poison, double %7, i64 0
%21 = shufflevector <2 x double> %20, <2 x double> poison, <2 x i32> zeroinitializer
%22 = add nsw i64 %13, -4
%23 = lshr exact i64 %22, 2
%24 = add nuw nsw i64 %23, 1
%25 = and i64 %24, 1
%26 = icmp eq i64 %22, 0
br i1 %26, label %60, label %27
27: ; preds = %12
%28 = and i64 %24, 9223372036854775806
br label %29
29: ; preds = %29, %27
%30 = phi i64 [ 0, %27 ], [ %57, %29 ]
%31 = phi i64 [ 0, %27 ], [ %58, %29 ]
%32 = getelementptr inbounds double, double* %0, i64 %30
%33 = bitcast double* %32 to <2 x double>*
%34 = load <2 x double>, <2 x double>* %33
%35 = getelementptr inbounds double, double* %32, i64 2
%36 = bitcast double* %35 to <2 x double>*
%37 = load <2 x double>, <2 x double>* %36
%38 = fsub <2 x double> %34, %15
%39 = fsub <2 x double> %37, %17
%40 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %38, <2 x double> %19, <2 x double> %15)
%41 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %39, <2 x double> %21, <2 x double> %17)
%42 = bitcast double* %32 to <2 x double>*
store <2 x double> %40, <2 x double>* %42
%43 = bitcast double* %35 to <2 x double>*
store <2 x double> %41, <2 x double>* %43
%44 = or i64 %30, 4
%45 = getelementptr inbounds double, double* %0, i64 %44
%46 = bitcast double* %45 to <2 x double>*
%47 = load <2 x double>, <2 x double>* %46
%48 = getelementptr inbounds double, double* %45, i64 2
%49 = bitcast double* %48 to <2 x double>*
%50 = load <2 x double>, <2 x double>* %49
%51 = fsub <2 x double> %47, %15
%52 = fsub <2 x double> %50, %17
%53 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %51, <2 x double> %19, <2 x double> %15)
%54 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %52, <2 x double> %21, <2 x double> %17)
%55 = bitcast double* %45 to <2 x double>*
store <2 x double> %53, <2 x double>* %55
%56 = bitcast double* %48 to <2 x double>*
store <2 x double> %54, <2 x double>* %56
%57 = add nuw i64 %30, 8
%58 = add i64 %31, 2
%59 = icmp eq i64 %58, %28
br i1 %59, label %60, label %29
60: ; preds = %29, %12
%61 = phi i64 [ 0, %12 ], [ %57, %29 ]
%62 = icmp eq i64 %25, 0
br i1 %62, label %76, label %63
63: ; preds = %60
%64 = getelementptr inbounds double, double* %0, i64 %61
%65 = bitcast double* %64 to <2 x double>*
%66 = load <2 x double>, <2 x double>* %65
%67 = getelementptr inbounds double, double* %64, i64 2
%68 = bitcast double* %67 to <2 x double>*
%69 = load <2 x double>, <2 x double>* %68
%70 = fsub <2 x double> %66, %15
%71 = fsub <2 x double> %69, %17
%72 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %70, <2 x double> %19, <2 x double> %15)
%73 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %71, <2 x double> %21, <2 x double> %17)
%74 = bitcast double* %64 to <2 x double>*
store <2 x double> %72, <2 x double>* %74
%75 = bitcast double* %67 to <2 x double>*
store <2 x double> %73, <2 x double>* %75
br label %76
76: ; preds = %60, %63
%77 = icmp eq i64 %13, %10
br i1 %77, label %88, label %78
78: ; preds = %9, %76
%79 = phi i64 [ 0, %9 ], [ %13, %76 ]
br label %80
80: ; preds = %78, %80
%81 = phi i64 [ %86, %80 ], [ %79, %78 ]
%82 = getelementptr inbounds double, double* %0, i64 %81
%83 = load double, double* %82
%84 = fsub double %83, %5
%85 = tail call double @llvm.fmuladd.f64(double %84, double %7, double %5)
store double %85, double* %82
%86 = add nuw nsw i64 %81, 1
%87 = icmp eq i64 %86, %10
br i1 %87, label %88, label %80
88: ; preds = %80, %76, %4
ret void
}