#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 exp(double);
double gls_oneperiod(double *, double *, double *, int, double);
int /*<<< orphan*/ isnan(double);
int log10(double);
double ls_oneperiod(double *, double *, int, double);
double pow(double, double);
double getlsampthresh_func(double amp_scale, int N, double *t, double *mag_orig,
                           double *sig, double *mag_signal, double *mag_tmp,
                           double period, int Nsubharm, int Nharm,
                           double *subharmA, double *subharmB, double *harmA,
                           double *harmB, double fundA, double fundB,
                           double minPer, double thresh, int use_orig_ls) {
  int i, ngood = 0;
  double val, T, effm, expy, outprob, zval;
  for (i = 0; i < N; i++) {
    mag_tmp[i] = mag_orig[i] + amp_scale * mag_signal[i];
    if (!isnan(mag_tmp[i]) && !isnan(sig[i]) && sig[i] > 0)
      ngood++;
  }
  if (use_orig_ls) {
    val = ls_oneperiod(t, mag_tmp, N, period);
  } else {
    val = gls_oneperiod(t, mag_tmp, sig, N, period);
  }
  T = t[N - 1] - t[0];
  effm = log10(2.0 * T / minPer);
  if (use_orig_ls) {
    expy = -val * 0.434294482;
    outprob = effm + expy;
    if (outprob > -2.0) {
      expy = exp(-val);
      outprob = 1.0 - pow(1.0 - expy, 2.0 * T / minPer);
      outprob = log10(outprob);
    }
  } else {
    if (val == 0.)
      outprob = 0.0;
    else {
      zval = (ngood - 3) * (val / (1.0 - val)) / 2.0;
      expy = -(ngood - 3) * log10((1.0 + (2.0 * zval) / (ngood - 3))) / 2.0;
      outprob = effm + expy;
      if (outprob > -2.0) {
        expy = pow(((1.0 + (2.0 * zval) / (ngood - 3))), (-(ngood - 3) / 2.0));
        outprob = 1.0 - pow(1.0 - expy, 2.0 * T / minPer);
        outprob = log10(outprob);
      }
    }
  }
  return (outprob - thresh);
}


x86 assembly (clang, -O0):
<getlsampthresh_func>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    0x40(%rbp),%eax
mov    0x38(%rbp),%rax
mov    0x30(%rbp),%rax
mov    0x28(%rbp),%rax
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
movsd  %xmm1,-0x40(%rbp)
movsd  %xmm2,-0x48(%rbp)
movsd  %xmm3,-0x50(%rbp)
movsd  %xmm4,-0x58(%rbp)
movsd  %xmm5,-0x60(%rbp)
movl   $0x0,-0x68(%rbp)
movl   $0x0,-0x64(%rbp)
mov    -0x64(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1273 <getlsampthresh_func+0x113>
mov    -0x20(%rbp),%rax
movslq -0x64(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x8(%rbp),%xmm0
mov    -0x30(%rbp),%rax
movslq -0x64(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x38(%rbp),%rax
movslq -0x64(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x38(%rbp),%rax
movslq -0x64(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1050 <isnan@plt>
cmp    $0x0,%eax
jne    1260 <getlsampthresh_func+0x100>
mov    -0x28(%rbp),%rax
movslq -0x64(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1050 <isnan@plt>
cmp    $0x0,%eax
jne    1260 <getlsampthresh_func+0x100>
mov    -0x28(%rbp),%rax
movslq -0x64(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1260 <getlsampthresh_func+0x100>
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    1265 <getlsampthresh_func+0x105>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    11c7 <getlsampthresh_func+0x67>
cmpl   $0x0,0x40(%rbp)
je     129c <getlsampthresh_func+0x13c>
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0xc(%rbp),%edx
movsd  -0x40(%rbp),%xmm0
call   1070 <ls_oneperiod@plt>
movsd  %xmm0,-0x70(%rbp)
jmp    12ba <getlsampthresh_func+0x15a>
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0xc(%rbp),%ecx
movsd  -0x40(%rbp),%xmm0
call   1030 <gls_oneperiod@plt>
movsd  %xmm0,-0x70(%rbp)
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
subsd  (%rax),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  0xd1f(%rip),%xmm0
mulsd  -0x78(%rbp),%xmm0
divsd  -0x58(%rbp),%xmm0
call   1080 <log10@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x80(%rbp)
cmpl   $0x0,0x40(%rbp)
je     13e7 <getlsampthresh_func+0x287>
movsd  -0x70(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xcf1(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x80(%rbp),%xmm0
addsd  -0x88(%rbp),%xmm0
ff
movsd  %xmm0,-0x90(%rbp)
ff
movsd  -0x90(%rbp),%xmm0
ff
movsd  0xcb0(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    13e2 <getlsampthresh_func+0x282>
movsd  -0x70(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1040 <exp@plt>
movsd  %xmm0,-0x88(%rbp)
ff
movsd  0xc7d(%rip),%xmm0
subsd  -0x88(%rbp),%xmm0
ff
movsd  0xc5d(%rip),%xmm1
mulsd  -0x78(%rbp),%xmm1
divsd  -0x58(%rbp),%xmm1
call   1060 <pow@plt>
movaps %xmm0,%xmm1
movsd  0xc53(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
movsd  -0x90(%rbp),%xmm0
ff
call   1080 <log10@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
jmp    158a <getlsampthresh_func+0x42a>
movsd  -0x70(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    140f <getlsampthresh_func+0x2af>
jp     140f <getlsampthresh_func+0x2af>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
jmp    1585 <getlsampthresh_func+0x425>
mov    -0x68(%rbp),%eax
sub    $0x3,%eax
cvtsi2sd %eax,%xmm0
movsd  -0x70(%rbp),%xmm1
movsd  0xbea(%rip),%xmm2
subsd  -0x70(%rbp),%xmm2
divsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  0xbc5(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x98(%rbp)
ff
mov    -0x68(%rbp),%ecx
sub    $0x3,%ecx
xor    %eax,%eax
sub    %ecx,%eax
mov    %eax,-0x9c(%rbp)
movsd  0xba1(%rip),%xmm1
mulsd  -0x98(%rbp),%xmm1
ff
mov    -0x68(%rbp),%eax
sub    $0x3,%eax
cvtsi2sd %eax,%xmm0
divsd  %xmm0,%xmm1
movsd  0xb93(%rip),%xmm0
addsd  %xmm1,%xmm0
call   1080 <log10@plt>
mov    %eax,%ecx
mov    -0x9c(%rbp),%eax
imul   %ecx,%eax
cvtsi2sd %eax,%xmm0
movsd  0xb63(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x80(%rbp),%xmm0
addsd  -0x88(%rbp),%xmm0
ff
movsd  %xmm0,-0x90(%rbp)
ff
movsd  -0x90(%rbp),%xmm0
ff
movsd  0xb3a(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1580 <getlsampthresh_func+0x420>
movsd  0xb20(%rip),%xmm1
mulsd  -0x98(%rbp),%xmm1
ff
mov    -0x68(%rbp),%eax
sub    $0x3,%eax
cvtsi2sd %eax,%xmm0
divsd  %xmm0,%xmm1
movsd  0xb12(%rip),%xmm0
addsd  %xmm1,%xmm0
mov    -0x68(%rbp),%ecx
sub    $0x3,%ecx
xor    %eax,%eax
sub    %ecx,%eax
cvtsi2sd %eax,%xmm1
movsd  0xae8(%rip),%xmm2
divsd  %xmm2,%xmm1
call   1060 <pow@plt>
movsd  %xmm0,-0x88(%rbp)
ff
movsd  0xadf(%rip),%xmm0
subsd  -0x88(%rbp),%xmm0
ff
movsd  0xabf(%rip),%xmm1
mulsd  -0x78(%rbp),%xmm1
divsd  -0x58(%rbp),%xmm1
call   1060 <pow@plt>
movaps %xmm0,%xmm1
movsd  0xab5(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
movsd  -0x90(%rbp),%xmm0
ff
call   1080 <log10@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
jmp    1585 <getlsampthresh_func+0x425>
jmp    158a <getlsampthresh_func+0x42a>
movsd  -0x90(%rbp),%xmm0
ff
subsd  -0x60(%rbp),%xmm0
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getlsampthresh_func>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
movsd  %xmm5,0x40(%rsp)
movsd  %xmm4,0x30(%rsp)
movsd  %xmm1,0x38(%rsp)
mov    %r9,%r13
mov    %rcx,%r12
mov    %rsi,0x10(%rsp)
movsd  %xmm0,0x20(%rsp)
test   %edi,%edi
mov    %edi,0xc(%rsp)
jle    120a <getlsampthresh_func+0xaa>
mov    %r8,%rbp
mov    %rdx,%rbx
mov    %edi,%r14d
xor    %r15d,%r15d
xor    %eax,%eax
mov    %rax,0x18(%rsp)
jmp    11b9 <getlsampthresh_func+0x59>
xchg   %ax,%ax
add    $0x1,%r15
cmp    %r15,%r14
je     1211 <getlsampthresh_func+0xb1>
movsd  0x0(%rbp,%r15,8),%xmm0
mulsd  0x20(%rsp),%xmm0
addsd  (%rbx,%r15,8),%xmm0
movsd  %xmm0,0x0(%r13,%r15,8)
call   1050 <isnan@plt>
test   %eax,%eax
jne    11b0 <getlsampthresh_func+0x50>
movsd  (%r12,%r15,8),%xmm0
call   1050 <isnan@plt>
test   %eax,%eax
jne    11b0 <getlsampthresh_func+0x50>
movsd  (%r12,%r15,8),%xmm0
ucomisd 0xe27(%rip),%xmm0
jbe    11b0 <getlsampthresh_func+0x50>
mov    0x18(%rsp),%rax
add    $0x1,%eax
mov    %rax,0x18(%rsp)
jmp    11b0 <getlsampthresh_func+0x50>
xor    %eax,%eax
mov    %rax,0x18(%rsp)
mov    0xb0(%rsp),%r14d
test   %r14d,%r14d
je     123c <getlsampthresh_func+0xdc>
mov    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    %r13,%rsi
mov    0xc(%rsp),%ebx
mov    %ebx,%edx
movsd  0x38(%rsp),%xmm0
call   1070 <ls_oneperiod@plt>
jmp    125b <getlsampthresh_func+0xfb>
mov    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
mov    0xc(%rsp),%ebx
mov    %ebx,%ecx
movsd  0x38(%rsp),%xmm0
call   1030 <gls_oneperiod@plt>
movaps %xmm0,0x20(%rsp)
movslq %ebx,%rax
movsd  -0x8(%rbp,%rax,8),%xmm0
subsd  0x0(%rbp),%xmm0
addsd  %xmm0,%xmm0
divsd  0x30(%rsp),%xmm0
movsd  %xmm0,0x30(%rsp)
call   1080 <log10@plt>
cvtsi2sd %eax,%xmm2
test   %r14d,%r14d
je     1301 <getlsampthresh_func+0x1a1>
movsd  0xd6c(%rip),%xmm0
movapd 0x20(%rsp),%xmm1
mulsd  %xmm1,%xmm0
addsd  %xmm0,%xmm2
ucomisd 0xd5e(%rip),%xmm2
movapd %xmm2,%xmm0
jbe    13b3 <getlsampthresh_func+0x253>
xorpd  0xd74(%rip),%xmm1
movapd %xmm1,%xmm0
call   1040 <exp@plt>
movsd  0xd43(%rip),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
movsd  0x30(%rsp),%xmm1
call   1060 <pow@plt>
movsd  0xd28(%rip),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
call   1080 <log10@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
jmp    13b3 <getlsampthresh_func+0x253>
xorpd  %xmm0,%xmm0
movapd 0x20(%rsp),%xmm3
ucomisd %xmm0,%xmm3
jne    1317 <getlsampthresh_func+0x1b7>
jnp    13b3 <getlsampthresh_func+0x253>
mov    0x18(%rsp),%rcx
lea    -0x3(%rcx),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0xce2(%rip),%xmm1
movsd  %xmm2,0x10(%rsp)
movapd %xmm1,%xmm2
subsd  %xmm3,%xmm2
divsd  %xmm2,%xmm3
mulsd  %xmm0,%xmm3
mulsd  0xccc(%rip),%xmm3
mov    $0x3,%ebx
sub    %ecx,%ebx
addsd  %xmm3,%xmm3
divsd  %xmm0,%xmm3
addsd  %xmm1,%xmm3
movapd %xmm3,0x20(%rsp)
movapd %xmm3,%xmm0
call   1080 <log10@plt>
movapd 0x20(%rsp),%xmm2
imul   %ebx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xc92(%rip),%xmm0
addsd  0x10(%rsp),%xmm0
ucomisd 0xc74(%rip),%xmm0
jbe    13b3 <getlsampthresh_func+0x253>
xorps  %xmm1,%xmm1
cvtsi2sd %ebx,%xmm1
mulsd  0xc73(%rip),%xmm1
movapd %xmm2,%xmm0
call   1060 <pow@plt>
jmp    12c5 <getlsampthresh_func+0x165>
subsd  0x40(%rsp),%xmm0
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @getlsampthresh_func(double %0, i32 %1, double* %2, double* %3, double* %4, double* %5, double* %6, double %7, i32 %8, i32 %9, double* %10, double* %11, double* %12, double* %13, double %14, double %15, double %16, double %17, i32 %18) {
%20 = alloca double
%21 = alloca i32
%22 = alloca double*
%23 = alloca double*
%24 = alloca double*
%25 = alloca double*
%26 = alloca double*
%27 = alloca double
%28 = alloca i32
%29 = alloca i32
%30 = alloca double*
%31 = alloca double*
%32 = alloca double*
%33 = alloca double*
%34 = alloca double
%35 = alloca double
%36 = alloca double
%37 = alloca double
%38 = alloca i32
%39 = alloca i32
%40 = alloca i32
%41 = alloca double
%42 = alloca double
%43 = alloca double
%44 = alloca double
%45 = alloca double
%46 = alloca double
store double %0, double* %20
store i32 %1, i32* %21
store double* %2, double** %22
store double* %3, double** %23
store double* %4, double** %24
store double* %5, double** %25
store double* %6, double** %26
store double %7, double* %27
store i32 %8, i32* %28
store i32 %9, i32* %29
store double* %10, double** %30
store double* %11, double** %31
store double* %12, double** %32
store double* %13, double** %33
store double %14, double* %34
store double %15, double* %35
store double %16, double* %36
store double %17, double* %37
store i32 %18, i32* %38
store i32 0, i32* %40
store i32 0, i32* %39
br label %47
47: ; preds = %94, %19
%48 = load i32, i32* %39
%49 = load i32, i32* %21
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %97
51: ; preds = %47
%52 = load double*, double** %23
%53 = load i32, i32* %39
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds double, double* %52, i64 %54
%56 = load double, double* %55
%57 = load double, double* %20
%58 = load double*, double** %25
%59 = load i32, i32* %39
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds double, double* %58, i64 %60
%62 = load double, double* %61
%63 = call double @llvm.fmuladd.f64(double %57, double %62, double %56)
%64 = load double*, double** %26
%65 = load i32, i32* %39
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds double, double* %64, i64 %66
store double %63, double* %67
%68 = load double*, double** %26
%69 = load i32, i32* %39
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds double, double* %68, i64 %70
%72 = load double, double* %71
%73 = call i32 @isnan(double %72)
%74 = icmp ne i32 %73, 0
br i1 %74, label %93, label %75
75: ; preds = %51
%76 = load double*, double** %24
%77 = load i32, i32* %39
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds double, double* %76, i64 %78
%80 = load double, double* %79
%81 = call i32 @isnan(double %80)
%82 = icmp ne i32 %81, 0
br i1 %82, label %93, label %83
83: ; preds = %75
%84 = load double*, double** %24
%85 = load i32, i32* %39
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds double, double* %84, i64 %86
%88 = load double, double* %87
%89 = fcmp ogt double %88, 0.000000e+00
br i1 %89, label %90, label %93
90: ; preds = %83
%91 = load i32, i32* %40
%92 = add nsw i32 %91, 1
store i32 %92, i32* %40
br label %93
93: ; preds = %90, %83, %75, %51
br label %94
94: ; preds = %93
%95 = load i32, i32* %39
%96 = add nsw i32 %95, 1
store i32 %96, i32* %39
br label %47
97: ; preds = %47
%98 = load i32, i32* %38
%99 = icmp ne i32 %98, 0
br i1 %99, label %100, label %106
100: ; preds = %97
%101 = load double*, double** %22
%102 = load double*, double** %26
%103 = load i32, i32* %21
%104 = load double, double* %27
%105 = call double @ls_oneperiod(double* %101, double* %102, i32 %103, double %104)
store double %105, double* %41
br label %113
106: ; preds = %97
%107 = load double*, double** %22
%108 = load double*, double** %26
%109 = load double*, double** %24
%110 = load i32, i32* %21
%111 = load double, double* %27
%112 = call double @gls_oneperiod(double* %107, double* %108, double* %109, i32 %110, double %111)
store double %112, double* %41
br label %113
113: ; preds = %106, %100
%114 = load double*, double** %22
%115 = load i32, i32* %21
%116 = sub nsw i32 %115, 1
%117 = sext i32 %116 to i64
%118 = getelementptr inbounds double, double* %114, i64 %117
%119 = load double, double* %118
%120 = load double*, double** %22
%121 = getelementptr inbounds double, double* %120, i64 0
%122 = load double, double* %121
%123 = fsub double %119, %122
store double %123, double* %42
%124 = load double, double* %42
%125 = fmul double 2.000000e+00, %124
%126 = load double, double* %36
%127 = fdiv double %125, %126
%128 = call i32 @log10(double %127)
%129 = sitofp i32 %128 to double
store double %129, double* %43
%130 = load i32, i32* %38
%131 = icmp ne i32 %130, 0
br i1 %131, label %132, label %157
132: ; preds = %113
%133 = load double, double* %41
%134 = fneg double %133
%135 = fmul double %134, 0x3FDBCB7B15417D1A
store double %135, double* %44
%136 = load double, double* %43
%137 = load double, double* %44
%138 = fadd double %136, %137
store double %138, double* %45
%139 = load double, double* %45
%140 = fcmp ogt double %139, -2.000000e+00
br i1 %140, label %141, label %156
141: ; preds = %132
%142 = load double, double* %41
%143 = fneg double %142
%144 = call double @exp(double %143)
store double %144, double* %44
%145 = load double, double* %44
%146 = fsub double 1.000000e+00, %145
%147 = load double, double* %42
%148 = fmul double 2.000000e+00, %147
%149 = load double, double* %36
%150 = fdiv double %148, %149
%151 = call double @pow(double %146, double %150)
%152 = fsub double 1.000000e+00, %151
store double %152, double* %45
%153 = load double, double* %45
%154 = call i32 @log10(double %153)
%155 = sitofp i32 %154 to double
store double %155, double* %45
br label %156
156: ; preds = %141, %132
br label %217
157: ; preds = %113
%158 = load double, double* %41
%159 = fcmp oeq double %158, 0.000000e+00
br i1 %159, label %160, label %161
160: ; preds = %157
store double 0.000000e+00, double* %45
br label %216
161: ; preds = %157
%162 = load i32, i32* %40
%163 = sub nsw i32 %162, 3
%164 = sitofp i32 %163 to double
%165 = load double, double* %41
%166 = load double, double* %41
%167 = fsub double 1.000000e+00, %166
%168 = fdiv double %165, %167
%169 = fmul double %164, %168
%170 = fdiv double %169, 2.000000e+00
store double %170, double* %46
%171 = load i32, i32* %40
%172 = sub nsw i32 %171, 3
%173 = sub nsw i32 0, %172
%174 = load double, double* %46
%175 = fmul double 2.000000e+00, %174
%176 = load i32, i32* %40
%177 = sub nsw i32 %176, 3
%178 = sitofp i32 %177 to double
%179 = fdiv double %175, %178
%180 = fadd double 1.000000e+00, %179
%181 = call i32 @log10(double %180)
%182 = mul nsw i32 %173, %181
%183 = sitofp i32 %182 to double
%184 = fdiv double %183, 2.000000e+00
store double %184, double* %44
%185 = load double, double* %43
%186 = load double, double* %44
%187 = fadd double %185, %186
store double %187, double* %45
%188 = load double, double* %45
%189 = fcmp ogt double %188, -2.000000e+00
br i1 %189, label %190, label %215
190: ; preds = %161
%191 = load double, double* %46
%192 = fmul double 2.000000e+00, %191
%193 = load i32, i32* %40
%194 = sub nsw i32 %193, 3
%195 = sitofp i32 %194 to double
%196 = fdiv double %192, %195
%197 = fadd double 1.000000e+00, %196
%198 = load i32, i32* %40
%199 = sub nsw i32 %198, 3
%200 = sub nsw i32 0, %199
%201 = sitofp i32 %200 to double
%202 = fdiv double %201, 2.000000e+00
%203 = call double @pow(double %197, double %202)
store double %203, double* %44
%204 = load double, double* %44
%205 = fsub double 1.000000e+00, %204
%206 = load double, double* %42
%207 = fmul double 2.000000e+00, %206
%208 = load double, double* %36
%209 = fdiv double %207, %208
%210 = call double @pow(double %205, double %209)
%211 = fsub double 1.000000e+00, %210
store double %211, double* %45
%212 = load double, double* %45
%213 = call i32 @log10(double %212)
%214 = sitofp i32 %213 to double
store double %214, double* %45
br label %215
215: ; preds = %190, %161
br label %216
216: ; preds = %215, %160
br label %217
217: ; preds = %216, %156
%218 = load double, double* %45
%219 = load double, double* %37
%220 = fsub double %218, %219
ret double %220
}

LLVM IR (-O2):
define double @getlsampthresh_func(double %0, i32 %1, double* %2, double* nocapture %3, double* %4, double* nocapture %5, double* %6, double %7, i32 %8, i32 %9, double* nocapture readnone %10, double* nocapture readnone %11, double* nocapture readnone %12, double* nocapture readnone %13, double %14, double %15, double %16, double %17, i32 %18) {
%20 = icmp sgt i32 %1, 0
br i1 %20, label %21, label %48
21: ; preds = %19
%22 = zext i32 %1 to i64
br label %23
23: ; preds = %21, %44
%24 = phi i64 [ 0, %21 ], [ %46, %44 ]
%25 = phi i32 [ 0, %21 ], [ %45, %44 ]
%26 = getelementptr inbounds double, double* %3, i64 %24
%27 = load double, double* %26
%28 = getelementptr inbounds double, double* %5, i64 %24
%29 = load double, double* %28
%30 = tail call double @llvm.fmuladd.f64(double %0, double %29, double %27)
%31 = getelementptr inbounds double, double* %6, i64 %24
store double %30, double* %31
%32 = tail call i32 @isnan(double %30)
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %44
34: ; preds = %23
%35 = getelementptr inbounds double, double* %4, i64 %24
%36 = load double, double* %35
%37 = tail call i32 @isnan(double %36)
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %44
39: ; preds = %34
%40 = load double, double* %35
%41 = fcmp ogt double %40, 0.000000e+00
br i1 %41, label %42, label %44
42: ; preds = %39
%43 = add nsw i32 %25, 1
br label %44
44: ; preds = %23, %34, %39, %42
%45 = phi i32 [ %25, %23 ], [ %25, %34 ], [ %43, %42 ], [ %25, %39 ]
%46 = add nuw nsw i64 %24, 1
%47 = icmp eq i64 %46, %22
br i1 %47, label %48, label %23
48: ; preds = %44, %19
%49 = phi i32 [ 0, %19 ], [ %45, %44 ]
%50 = icmp eq i32 %18, 0
br i1 %50, label %53, label %51
51: ; preds = %48
%52 = tail call double @ls_oneperiod(double* %2, double* %6, i32 %1, double %7)
br label %55
53: ; preds = %48
%54 = tail call double @gls_oneperiod(double* %2, double* %6, double* %4, i32 %1, double %7)
br label %55
55: ; preds = %53, %51
%56 = phi double [ %52, %51 ], [ %54, %53 ]
%57 = add nsw i32 %1, -1
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds double, double* %2, i64 %58
%60 = load double, double* %59
%61 = load double, double* %2
%62 = fsub double %60, %61
%63 = fmul double %62, 2.000000e+00
%64 = fdiv double %63, %16
%65 = tail call i32 @log10(double %64)
%66 = sitofp i32 %65 to double
br i1 %50, label %74, label %67
67: ; preds = %55
%68 = fmul double %56, 0x3FDBCB7B15417D1A
%69 = fsub double %66, %68
%70 = fcmp ogt double %69, -2.000000e+00
br i1 %70, label %71, label %104
71: ; preds = %67
%72 = fneg double %56
%73 = tail call double @exp(double %72)
br label %97
74: ; preds = %55
%75 = fcmp oeq double %56, 0.000000e+00
br i1 %75, label %104, label %76
76: ; preds = %74
%77 = add nsw i32 %49, -3
%78 = sitofp i32 %77 to double
%79 = fsub double 1.000000e+00, %56
%80 = fdiv double %56, %79
%81 = fmul double %80, %78
%82 = fmul double %81, 5.000000e-01
%83 = sub i32 3, %49
%84 = fmul double %82, 2.000000e+00
%85 = fdiv double %84, %78
%86 = fadd double %85, 1.000000e+00
%87 = tail call i32 @log10(double %86)
%88 = mul nsw i32 %87, %83
%89 = sitofp i32 %88 to double
%90 = fmul double %89, 5.000000e-01
%91 = fadd double %90, %66
%92 = fcmp ogt double %91, -2.000000e+00
br i1 %92, label %93, label %104
93: ; preds = %76
%94 = sitofp i32 %83 to double
%95 = fmul double %94, 5.000000e-01
%96 = tail call double @pow(double %86, double %95)
br label %97
97: ; preds = %71, %93
%98 = phi double [ %96, %93 ], [ %73, %71 ]
%99 = fsub double 1.000000e+00, %98
%100 = tail call double @pow(double %99, double %64)
%101 = fsub double 1.000000e+00, %100
%102 = tail call i32 @log10(double %101)
%103 = sitofp i32 %102 to double
br label %104
104: ; preds = %97, %74, %76, %67
%105 = phi double [ %69, %67 ], [ %91, %76 ], [ 0.000000e+00, %74 ], [ %103, %97 ]
%106 = fsub double %105, %17
ret double %106
}