void getamplitude(double *f_r, double *f_i, double *W_r, double *W_i, int Nf,
                  int peakfindx, double *a_r, double *a_i) {
  double denom;
  int i_f, i_w;
  i_f = peakfindx;
  i_w = 2 * peakfindx;
  denom = 1. - W_r[i_w] * W_r[i_w] - W_i[i_w] * W_i[i_w];
  if (denom < 1.0e-12) {
    *a_r = 0.;
    *a_i = 0.;
  } else {
    *a_r = (f_r[i_f] - f_r[i_f] * W_r[i_w] - f_i[i_f] * W_i[i_w]) / denom;
    *a_i = (f_i[i_f] + f_i[i_f] * W_r[i_w] - f_r[i_f] * W_i[i_w]) / denom;
  }
}


x86 assembly (clang, -O0):
<getamplitude>:
push   %rbp
mov    %rsp,%rbp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x18(%rbp),%rax
movslq -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm0,%xmm1
movsd  0xe98(%rip),%xmm0
addsd  %xmm0,%xmm1
mov    -0x20(%rbp),%rax
movslq -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xe46(%rip),%xmm0
ucomisd -0x30(%rbp),%xmm0
jbe    11e0 <getamplitude+0xe0>
mov    0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    0x18(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
jmp    12e1 <getamplitude+0x1e1>
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x18(%rbp),%rax
movslq -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
divsd  -0x30(%rbp),%xmm0
mov    0x10(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x18(%rbp),%rax
movslq -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
divsd  -0x30(%rbp),%xmm0
mov    0x18(%rbp),%rax
movsd  %xmm0,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<getamplitude>:
mov    0x10(%rsp),%r8
mov    0x8(%rsp),%r10
lea    (%r9,%r9,1),%eax
cltq
movsd  (%rdx,%rax,8),%xmm1
movapd %xmm1,%xmm2
mulsd  %xmm1,%xmm2
movsd  0xedb(%rip),%xmm0
subsd  %xmm2,%xmm0
movsd  (%rcx,%rax,8),%xmm2
movapd %xmm2,%xmm3
mulsd  %xmm2,%xmm3
subsd  %xmm3,%xmm0
movsd  0xec6(%rip),%xmm3
ucomisd %xmm0,%xmm3
jbe    1159 <getamplitude+0x59>
movq   $0x0,(%r10)
xorpd  %xmm1,%xmm1
movsd  %xmm1,(%r8)
ret
movslq %r9d,%r9
movsd  (%rdi,%r9,8),%xmm3
mulsd  %xmm3,%xmm1
subsd  %xmm1,%xmm3
mulsd  (%rsi,%r9,8),%xmm2
subsd  %xmm2,%xmm3
divsd  %xmm0,%xmm3
movsd  %xmm3,(%r10)
movsd  (%rsi,%r9,8),%xmm2
movsd  (%rdx,%rax,8),%xmm1
mulsd  %xmm2,%xmm1
addsd  %xmm2,%xmm1
movsd  (%rdi,%r9,8),%xmm2
mulsd  (%rcx,%rax,8),%xmm2
subsd  %xmm2,%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%r8)
ret

LLVM IR (-O0):
define void @getamplitude(double* %0, double* %1, double* %2, double* %3, i32 %4, i32 %5, double* %6, double* %7) {
%9 = alloca double*
%10 = alloca double*
%11 = alloca double*
%12 = alloca double*
%13 = alloca i32
%14 = alloca i32
%15 = alloca double*
%16 = alloca double*
%17 = alloca double
%18 = alloca i32
%19 = alloca i32
store double* %0, double** %9
store double* %1, double** %10
store double* %2, double** %11
store double* %3, double** %12
store i32 %4, i32* %13
store i32 %5, i32* %14
store double* %6, double** %15
store double* %7, double** %16
%20 = load i32, i32* %14
store i32 %20, i32* %18
%21 = load i32, i32* %14
%22 = mul nsw i32 2, %21
store i32 %22, i32* %19
%23 = load double*, double** %11
%24 = load i32, i32* %19
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds double, double* %23, i64 %25
%27 = load double, double* %26
%28 = load double*, double** %11
%29 = load i32, i32* %19
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double, double* %28, i64 %30
%32 = load double, double* %31
%33 = fneg double %27
%34 = call double @llvm.fmuladd.f64(double %33, double %32, double 1.000000e+00)
%35 = load double*, double** %12
%36 = load i32, i32* %19
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds double, double* %35, i64 %37
%39 = load double, double* %38
%40 = load double*, double** %12
%41 = load i32, i32* %19
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds double, double* %40, i64 %42
%44 = load double, double* %43
%45 = fneg double %39
%46 = call double @llvm.fmuladd.f64(double %45, double %44, double %34)
store double %46, double* %17
%47 = load double, double* %17
%48 = fcmp olt double %47, 0x3D719799812DEA11
br i1 %48, label %49, label %52
49: ; preds = %8
%50 = load double*, double** %15
store double 0.000000e+00, double* %50
%51 = load double*, double** %16
store double 0.000000e+00, double* %51
br label %116
52: ; preds = %8
%53 = load double*, double** %9
%54 = load i32, i32* %18
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds double, double* %53, i64 %55
%57 = load double, double* %56
%58 = load double*, double** %9
%59 = load i32, i32* %18
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds double, double* %58, i64 %60
%62 = load double, double* %61
%63 = load double*, double** %11
%64 = load i32, i32* %19
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds double, double* %63, i64 %65
%67 = load double, double* %66
%68 = fneg double %62
%69 = call double @llvm.fmuladd.f64(double %68, double %67, double %57)
%70 = load double*, double** %10
%71 = load i32, i32* %18
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds double, double* %70, i64 %72
%74 = load double, double* %73
%75 = load double*, double** %12
%76 = load i32, i32* %19
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds double, double* %75, i64 %77
%79 = load double, double* %78
%80 = fneg double %74
%81 = call double @llvm.fmuladd.f64(double %80, double %79, double %69)
%82 = load double, double* %17
%83 = fdiv double %81, %82
%84 = load double*, double** %15
store double %83, double* %84
%85 = load double*, double** %10
%86 = load i32, i32* %18
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds double, double* %85, i64 %87
%89 = load double, double* %88
%90 = load double*, double** %10
%91 = load i32, i32* %18
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds double, double* %90, i64 %92
%94 = load double, double* %93
%95 = load double*, double** %11
%96 = load i32, i32* %19
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds double, double* %95, i64 %97
%99 = load double, double* %98
%100 = call double @llvm.fmuladd.f64(double %94, double %99, double %89)
%101 = load double*, double** %9
%102 = load i32, i32* %18
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds double, double* %101, i64 %103
%105 = load double, double* %104
%106 = load double*, double** %12
%107 = load i32, i32* %19
%108 = sext i32 %107 to i64
%109 = getelementptr inbounds double, double* %106, i64 %108
%110 = load double, double* %109
%111 = fneg double %105
%112 = call double @llvm.fmuladd.f64(double %111, double %110, double %100)
%113 = load double, double* %17
%114 = fdiv double %112, %113
%115 = load double*, double** %16
store double %114, double* %115
br label %116
116: ; preds = %52, %49
ret void
}

LLVM IR (-O2):
define void @getamplitude(double* nocapture %0, double* nocapture %1, double* nocapture %2, double* nocapture %3, i32 %4, i32 %5, double* nocapture writeonly %6, double* nocapture writeonly %7) {
%9 = shl nsw i32 %5, 1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds double, double* %2, i64 %10
%12 = load double, double* %11
%13 = fneg double %12
%14 = tail call double @llvm.fmuladd.f64(double %13, double %12, double 1.000000e+00)
%15 = getelementptr inbounds double, double* %3, i64 %10
%16 = load double, double* %15
%17 = fneg double %16
%18 = tail call double @llvm.fmuladd.f64(double %17, double %16, double %14)
%19 = fcmp olt double %18, 0x3D719799812DEA11
br i1 %19, label %20, label %21
20: ; preds = %8
store double 0.000000e+00, double* %6
br label %40
21: ; preds = %8
%22 = sext i32 %5 to i64
%23 = getelementptr inbounds double, double* %0, i64 %22
%24 = load double, double* %23
%25 = fneg double %24
%26 = tail call double @llvm.fmuladd.f64(double %25, double %12, double %24)
%27 = getelementptr inbounds double, double* %1, i64 %22
%28 = load double, double* %27
%29 = fneg double %28
%30 = tail call double @llvm.fmuladd.f64(double %29, double %16, double %26)
%31 = fdiv double %30, %18
store double %31, double* %6
%32 = load double, double* %27
%33 = load double, double* %11
%34 = tail call double @llvm.fmuladd.f64(double %32, double %33, double %32)
%35 = load double, double* %23
%36 = load double, double* %15
%37 = fneg double %35
%38 = tail call double @llvm.fmuladd.f64(double %37, double %36, double %34)
%39 = fdiv double %38, %18
br label %40
40: ; preds = %21, %20
%41 = phi double [ %39, %21 ], [ 0.000000e+00, %20 ]
store double %41, double* %7
ret void
}