#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 */
int /*<<< orphan*/ def_hat(int, int, int, double *, double *, double *,
                           double *, double *, double *, double *, double *,
                           double);
int /*<<< orphan*/ get_eigs(int, double *, double *);
int /*<<< orphan*/ inv_hat(int, double *, double *, double *, double *, int,
                           int);
double optimize_px(int, int, double *, double *, double *, double *, double *,
                   double, double, double *);
double refine_psd(int numt, int nharm, int detrend_order, double hat_matr[],
                  double hat0[], double hat_hat[], double sinx[], double cosx[],
                  double wt[], double cn[], double vec1[], double *lambda0,
                  double *lambda0_range, double chi0, double tc, double *Tr,
                  int inv) {
  int i, j, k, npar = 2 * nharm;
  double p[npar], vec[npar], eigs[npar], sum, px, lambda00 = *lambda0;
  def_hat(numt, nharm, detrend_order, hat_matr, hat0, sinx, cosx, wt, cn,
          hat_hat, vec, *lambda0);
  get_eigs(npar, hat_hat, eigs);
  for (i = 0; i < npar; i++) {
    for (sum = 0, j = 0; j < npar; j++)
      sum += hat_hat[i + j * npar] * vec[j];
    p[i] = sum;
  }
  px = optimize_px(npar, numt, p, hat_hat, eigs, lambda0, lambda0_range, chi0,
                   tc, Tr);
  if (inv == 1)
    inv_hat(npar, hat_hat, vec, vec1, eigs, numt * lambda00, numt * (*lambda0));
  return px;
}


x86 assembly (clang, -O0):
<refine_psd>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0x98,%rsp
mov    0x50(%rbp),%eax
mov    0x48(%rbp),%rax
mov    0x40(%rbp),%rax
mov    0x38(%rbp),%rax
mov    0x30(%rbp),%rax
mov    0x28(%rbp),%rax
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %edi,-0x1c(%rbp)
mov    %esi,-0x20(%rbp)
mov    %edx,-0x24(%rbp)
mov    %rcx,-0x30(%rbp)
mov    %r8,-0x38(%rbp)
mov    %r9,-0x40(%rbp)
movsd  %xmm0,-0x48(%rbp)
movsd  %xmm1,-0x50(%rbp)
mov    -0x20(%rbp),%eax
add    %eax,%eax
mov    %eax,-0x60(%rbp)
mov    -0x60(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x68(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xb0(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x70(%rbp)
mov    -0x60(%rbp),%eax
mov    %eax,%ecx
lea    0xf(,%rcx,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rax
sub    %rdx,%rax
mov    %rax,-0xa8(%rbp)
mov    %rax,%rsp
mov    %rcx,-0x78(%rbp)
mov    -0x60(%rbp),%ecx
lea    0xf(,%rcx,8),%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0xa0(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x80(%rbp)
mov    0x38(%rbp),%rcx
movsd  (%rcx),%xmm0
movsd  %xmm0,-0x98(%rbp)
ff
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%r8
mov    0x10(%rbp),%r9
mov    0x18(%rbp),%r14
mov    0x20(%rbp),%rbx
mov    0x28(%rbp),%r11
mov    -0x40(%rbp),%r10
mov    0x38(%rbp),%r15
movsd  (%r15),%xmm0
sub    $0x30,%rsp
mov    %r14,(%rsp)
mov    %rbx,0x8(%rsp)
mov    %r11,0x10(%rsp)
mov    %r10,0x18(%rsp)
mov    %rax,0x20(%rsp)
call   1060 <def_hat@plt>
mov    -0xa0(%rbp),%rdx
add    $0x30,%rsp
mov    -0x60(%rbp),%edi
mov    -0x40(%rbp),%rsi
call   1040 <get_eigs@plt>
movl   $0x0,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0x60(%rbp),%eax
jge    1327 <refine_psd+0x1e7>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movl   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%eax
cmp    -0x60(%rbp),%eax
jge    1301 <refine_psd+0x1c1>
mov    -0xa8(%rbp),%rax
mov    -0x40(%rbp),%rcx
mov    -0x54(%rbp),%edx
mov    -0x58(%rbp),%esi
imul   -0x60(%rbp),%esi
add    %esi,%edx
movslq %edx,%rdx
movsd  (%rcx,%rdx,8),%xmm0
movslq -0x58(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x88(%rbp),%xmm1
ff
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    12a7 <refine_psd+0x167>
mov    -0xb0(%rbp),%rax
movsd  -0x88(%rbp),%xmm0
ff
movslq -0x54(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1289 <refine_psd+0x149>
mov    -0xa0(%rbp),%r8
mov    -0xb0(%rbp),%rdx
mov    -0x60(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x40(%rbp),%rcx
mov    0x38(%rbp),%r9
mov    0x40(%rbp),%r10
movsd  -0x48(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm1
mov    0x48(%rbp),%rax
sub    $0x10,%rsp
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1050 <optimize_px@plt>
add    $0x10,%rsp
movsd  %xmm0,-0x90(%rbp)
ff
cmpl   $0x1,0x50(%rbp)
jne    13c9 <refine_psd+0x289>
mov    -0xa0(%rbp),%r8
mov    -0xa8(%rbp),%rdx
mov    -0x60(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    0x30(%rbp),%rcx
cvtsi2sdl -0x1c(%rbp),%xmm0
mulsd  -0x98(%rbp),%xmm0
ff
cvttsd2si %xmm0,%r9d
cvtsi2sdl -0x1c(%rbp),%xmm0
mov    0x38(%rbp),%rax
mulsd  (%rax),%xmm0
cvttsd2si %xmm0,%eax
sub    $0x10,%rsp
mov    %eax,(%rsp)
call   1030 <inv_hat@plt>
add    $0x10,%rsp
movsd  -0x90(%rbp),%xmm0
ff
mov    -0x68(%rbp),%rax
mov    %rax,%rsp
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<refine_psd>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
movsd  %xmm1,-0x38(%rbp)
movsd  %xmm0,-0x58(%rbp)
mov    %r9,%r12
mov    0x38(%rbp),%r11
mov    0x10(%rbp),%r9
movupd 0x18(%rbp),%xmm1
mov    0x28(%rbp),%r10
lea    (%rsi,%rsi,1),%r13d
mov    %rsi,-0x48(%rbp)
mov    %rsp,%r15
lea    0x0(,%r13,8),%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rsp,%r14
sub    %rax,%r14
mov    %r14,%rsp
movsd  (%r11),%xmm0
sub    $0x30,%rsp
mov    %rbx,0x20(%rsp)
mov    %r12,0x18(%rsp)
mov    %r10,0x10(%rsp)
movupd %xmm1,(%rsp)
mov    %edi,-0x2c(%rbp)
movsd  %xmm0,-0x40(%rbp)
call   1060 <def_hat@plt>
add    $0x30,%rsp
mov    %r13d,%edi
mov    %r12,%rsi
mov    %r14,-0x50(%rbp)
mov    %r14,%rdx
call   1040 <get_eigs@plt>
cmpl   $0x0,-0x48(%rbp)
jle    129c <refine_psd+0x15c>
cmp    $0x2,%r13d
mov    $0x1,%r8d
cmovge %r13d,%r8d
movslq %r13d,%rcx
mov    %r8d,%edx
and    $0x7ffffffe,%edx
mov    %rcx,%rsi
shl    $0x4,%rsi
xor    %r10d,%r10d
mov    %r12,%r9
jmp    1223 <refine_psd+0xe3>
nopl   (%rax)
movsd  %xmm0,(%r15,%r10,8)
add    $0x1,%r10
add    $0x8,%r9
cmp    %r8,%r10
je     129c <refine_psd+0x15c>
xorpd  %xmm0,%xmm0
cmp    $0x2,%r13d
jge    1240 <refine_psd+0x100>
xor    %eax,%eax
jmp    1278 <refine_psd+0x138>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r9,%rdi
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nop
movsd  (%rdi),%xmm1
mulsd  (%rbx,%rax,8),%xmm1
addsd  %xmm0,%xmm1
movsd  (%rdi,%rcx,8),%xmm0
mulsd  0x8(%rbx,%rax,8),%xmm0
addsd  %xmm1,%xmm0
add    $0x2,%rax
add    %rsi,%rdi
cmp    %rax,%rdx
jne    1250 <refine_psd+0x110>
test   $0x1,%r8b
je     1210 <refine_psd+0xd0>
mov    %rax,%rdi
imul   %rcx,%rdi
add    %r10,%rdi
movsd  (%r12,%rdi,8),%xmm1
mulsd  (%rbx,%rax,8),%xmm1
addsd  %xmm1,%xmm0
jmp    1210 <refine_psd+0xd0>
mov    %r13d,%edi
mov    -0x2c(%rbp),%esi
mov    %r15,%rdx
mov    %r12,%rcx
mov    -0x50(%rbp),%r15
mov    %r15,%r8
mov    0x38(%rbp),%r14
mov    %r14,%r9
movsd  -0x58(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
push   0x48(%rbp)
push   0x40(%rbp)
call   1050 <optimize_px@plt>
add    $0x10,%rsp
cmpl   $0x1,0x50(%rbp)
jne    131c <refine_psd+0x1dc>
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
cvtsi2sdl -0x2c(%rbp),%xmm0
mov    0x30(%rbp),%rcx
movsd  -0x40(%rbp),%xmm1
mulsd  %xmm0,%xmm1
cvttsd2si %xmm1,%r9d
mulsd  (%r14),%xmm0
cvttsd2si %xmm0,%eax
sub    $0x8,%rsp
mov    %r13d,%edi
mov    %r12,%rsi
mov    %rbx,%rdx
mov    %r15,%r8
push   %rax
call   1030 <inv_hat@plt>
movsd  -0x38(%rbp),%xmm0
add    $0x10,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @refine_psd(i32 %0, i32 %1, i32 %2, double* %3, double* %4, double* %5, double* %6, double* %7, double* %8, double* %9, double* %10, double* %11, double* %12, double %13, double %14, double* %15, i32 %16) {
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca double*
%22 = alloca double*
%23 = alloca double*
%24 = alloca double*
%25 = alloca double*
%26 = alloca double*
%27 = alloca double*
%28 = alloca double*
%29 = alloca double*
%30 = alloca double*
%31 = alloca double
%32 = alloca double
%33 = alloca double*
%34 = alloca i32
%35 = alloca i32
%36 = alloca i32
%37 = alloca i32
%38 = alloca i32
%39 = alloca i8*
%40 = alloca i64
%41 = alloca i64
%42 = alloca i64
%43 = alloca double
%44 = alloca double
%45 = alloca double
store i32 %0, i32* %18
store i32 %1, i32* %19
store i32 %2, i32* %20
store double* %3, double** %21
store double* %4, double** %22
store double* %5, double** %23
store double* %6, double** %24
store double* %7, double** %25
store double* %8, double** %26
store double* %9, double** %27
store double* %10, double** %28
store double* %11, double** %29
store double* %12, double** %30
store double %13, double* %31
store double %14, double* %32
store double* %15, double** %33
store i32 %16, i32* %34
%46 = load i32, i32* %19
%47 = mul nsw i32 2, %46
store i32 %47, i32* %38
%48 = load i32, i32* %38
%49 = zext i32 %48 to i64
%50 = call i8* @llvm.stacksave()
store i8* %50, i8** %39
%51 = alloca double, i64 %49
store i64 %49, i64* %40
%52 = load i32, i32* %38
%53 = zext i32 %52 to i64
%54 = alloca double, i64 %53
store i64 %53, i64* %41
%55 = load i32, i32* %38
%56 = zext i32 %55 to i64
%57 = alloca double, i64 %56
store i64 %56, i64* %42
%58 = load double*, double** %29
%59 = load double, double* %58
store double %59, double* %45
%60 = load i32, i32* %18
%61 = load i32, i32* %19
%62 = load i32, i32* %20
%63 = load double*, double** %21
%64 = load double*, double** %22
%65 = load double*, double** %24
%66 = load double*, double** %25
%67 = load double*, double** %26
%68 = load double*, double** %27
%69 = load double*, double** %23
%70 = load double*, double** %29
%71 = load double, double* %70
%72 = call i32 @def_hat(i32 %60, i32 %61, i32 %62, double* %63, double* %64, double* %65, double* %66, double* %67, double* %68, double* %69, double* %54, double %71)
%73 = load i32, i32* %38
%74 = load double*, double** %23
%75 = call i32 @get_eigs(i32 %73, double* %74, double* %57)
store i32 0, i32* %35
br label %76
76: ; preds = %109, %17
%77 = load i32, i32* %35
%78 = load i32, i32* %38
%79 = icmp slt i32 %77, %78
br i1 %79, label %80, label %112
80: ; preds = %76
store double 0.000000e+00, double* %43
store i32 0, i32* %36
br label %81
81: ; preds = %101, %80
%82 = load i32, i32* %36
%83 = load i32, i32* %38
%84 = icmp slt i32 %82, %83
br i1 %84, label %85, label %104
85: ; preds = %81
%86 = load double*, double** %23
%87 = load i32, i32* %35
%88 = load i32, i32* %36
%89 = load i32, i32* %38
%90 = mul nsw i32 %88, %89
%91 = add nsw i32 %87, %90
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds double, double* %86, i64 %92
%94 = load double, double* %93
%95 = load i32, i32* %36
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds double, double* %54, i64 %96
%98 = load double, double* %97
%99 = load double, double* %43
%100 = call double @llvm.fmuladd.f64(double %94, double %98, double %99)
store double %100, double* %43
br label %101
101: ; preds = %85
%102 = load i32, i32* %36
%103 = add nsw i32 %102, 1
store i32 %103, i32* %36
br label %81
104: ; preds = %81
%105 = load double, double* %43
%106 = load i32, i32* %35
%107 = sext i32 %106 to i64
%108 = getelementptr inbounds double, double* %51, i64 %107
store double %105, double* %108
br label %109
109: ; preds = %104
%110 = load i32, i32* %35
%111 = add nsw i32 %110, 1
store i32 %111, i32* %35
br label %76
112: ; preds = %76
%113 = load i32, i32* %38
%114 = load i32, i32* %18
%115 = load double*, double** %23
%116 = load double*, double** %29
%117 = load double*, double** %30
%118 = load double, double* %31
%119 = load double, double* %32
%120 = load double*, double** %33
%121 = call double @optimize_px(i32 %113, i32 %114, double* %51, double* %115, double* %57, double* %116, double* %117, double %118, double %119, double* %120)
store double %121, double* %44
%122 = load i32, i32* %34
%123 = icmp eq i32 %122, 1
br i1 %123, label %124, label %140
124: ; preds = %112
%125 = load i32, i32* %38
%126 = load double*, double** %23
%127 = load double*, double** %28
%128 = load i32, i32* %18
%129 = sitofp i32 %128 to double
%130 = load double, double* %45
%131 = fmul double %129, %130
%132 = fptosi double %131 to i32
%133 = load i32, i32* %18
%134 = sitofp i32 %133 to double
%135 = load double*, double** %29
%136 = load double, double* %135
%137 = fmul double %134, %136
%138 = fptosi double %137 to i32
%139 = call i32 @inv_hat(i32 %125, double* %126, double* %54, double* %127, double* %57, i32 %132, i32 %138)
br label %140
140: ; preds = %124, %112
%141 = load double, double* %44
%142 = load i8*, i8** %39
ret double %141
}

LLVM IR (-O2):
define double @refine_psd(i32 %0, i32 %1, i32 %2, double* %3, double* %4, double* %5, double* %6, double* %7, double* %8, double* %9, double* %10, double* %11, double* %12, double %13, double %14, double* %15, i32 %16) {
%18 = shl i32 %1, 1
%19 = zext i32 %18 to i64
%20 = alloca double, i64 %19
%21 = alloca double, i64 %19
%22 = alloca double, i64 %19
%23 = load double, double* %11
%24 = call i32 @def_hat(i32 %0, i32 %1, i32 %2, double* %3, double* %4, double* %6, double* %7, double* %8, double* %9, double* %5, double* %21, double %23)
%25 = call i32 @get_eigs(i32 %18, double* %5, double* %22)
%26 = icmp sgt i32 %1, 0
br i1 %26, label %27, label %76
27: ; preds = %17
%28 = sext i32 %18 to i64
%29 = call i32 @llvm.smax.i32(i32 %18, i32 1)
%30 = zext i32 %29 to i64
%31 = and i64 %30, 1
%32 = icmp slt i32 %18, 2
%33 = and i64 %30, 2147483646
%34 = icmp eq i64 %31, 0
br label %35
35: ; preds = %71, %27
%36 = phi i64 [ 0, %27 ], [ %74, %71 ]
br i1 %32, label %59, label %37
37: ; preds = %35, %37
%38 = phi i64 [ %56, %37 ], [ 0, %35 ]
%39 = phi double [ %55, %37 ], [ 0.000000e+00, %35 ]
%40 = phi i64 [ %57, %37 ], [ 0, %35 ]
%41 = mul nsw i64 %38, %28
%42 = add nsw i64 %41, %36
%43 = getelementptr inbounds double, double* %5, i64 %42
%44 = load double, double* %43
%45 = getelementptr inbounds double, double* %21, i64 %38
%46 = load double, double* %45
%47 = call double @llvm.fmuladd.f64(double %44, double %46, double %39)
%48 = or i64 %38, 1
%49 = mul nsw i64 %48, %28
%50 = add nsw i64 %49, %36
%51 = getelementptr inbounds double, double* %5, i64 %50
%52 = load double, double* %51
%53 = getelementptr inbounds double, double* %21, i64 %48
%54 = load double, double* %53
%55 = call double @llvm.fmuladd.f64(double %52, double %54, double %47)
%56 = add nuw nsw i64 %38, 2
%57 = add i64 %40, 2
%58 = icmp eq i64 %57, %33
br i1 %58, label %59, label %37
59: ; preds = %37, %35
%60 = phi double [ undef, %35 ], [ %55, %37 ]
%61 = phi i64 [ 0, %35 ], [ %56, %37 ]
%62 = phi double [ 0.000000e+00, %35 ], [ %55, %37 ]
br i1 %34, label %71, label %63
63: ; preds = %59
%64 = mul nsw i64 %61, %28
%65 = add nsw i64 %64, %36
%66 = getelementptr inbounds double, double* %5, i64 %65
%67 = load double, double* %66
%68 = getelementptr inbounds double, double* %21, i64 %61
%69 = load double, double* %68
%70 = call double @llvm.fmuladd.f64(double %67, double %69, double %62)
br label %71
71: ; preds = %59, %63
%72 = phi double [ %60, %59 ], [ %70, %63 ]
%73 = getelementptr inbounds double, double* %20, i64 %36
store double %72, double* %73
%74 = add nuw nsw i64 %36, 1
%75 = icmp eq i64 %74, %30
br i1 %75, label %76, label %35
76: ; preds = %71, %17
%77 = call double @optimize_px(i32 %18, i32 %0, double* %20, double* %5, double* %22, double* %11, double* %12, double %13, double %14, double* %15)
%78 = icmp eq i32 %16, 1
br i1 %78, label %79, label %87
79: ; preds = %76
%80 = sitofp i32 %0 to double
%81 = fmul double %23, %80
%82 = fptosi double %81 to i32
%83 = load double, double* %11
%84 = fmul double %83, %80
%85 = fptosi double %84 to i32
%86 = call i32 @inv_hat(i32 %18, double* %5, double* %21, double* %10, double* %22, i32 %82, i32 %85)
br label %87
87: ; preds = %79, %76
ret double %77
}