user: Translate the below assembly code into C programming language:

```asm
<refine_psd>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbx
  sub    $0x68,%rsp
  mov    %edi,-0x4c(%rbp)
  mov    %edx,-0x50(%rbp)
  mov    %rcx,-0x88(%rbp)
  mov    %r9,-0x48(%rbp)
  mov    0x10(%rbp),%r9
  mov    0x18(%rbp),%rdi
  mov    0x20(%rbp),%r10
  mov    0x28(%rbp),%r11
  mov    0x30(%rbp),%rax
  mov    %rax,-0x80(%rbp)
  mov    0x38(%rbp),%rax
  mov    %rax,-0x58(%rbp)
  mov    0x40(%rbp),%r15
  movsd  %xmm0,-0x60(%rbp)
  movsd  %xmm1,-0x68(%rbp)
  mov    0x48(%rbp),%rax
  mov    %rax,-0x70(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x38(%rbp)
  xor    %eax,%eax
  lea    (%rsi,%rsi,1),%r14d
  movslq %r14d,%rbx
  shl    $0x3,%rbx
  mov    %rbx,%rax
  mov    %rbx,%rcx
  and    $0xfffffffffffff000,%rcx
  mov    %rsp,%rdx
  sub    %rcx,%rdx
L83:
  cmp    %rdx,%rsp
  je     L115
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  jmp    L83
L115:
  mov    %rax,%rdx
  and    $0xfff,%edx
  sub    %rdx,%rsp
  test   %rdx,%rdx
  je     L97
  orq    $0x0,-0x8(%rsp,%rdx,1)
L97:
  mov    %rsp,%r12
  mov    %rbx,%rax
  mov    %rbx,%rcx
  and    $0xfffffffffffff000,%rcx
  mov    %rsp,%rdx
  sub    %rcx,%rdx
L35:
  cmp    %rdx,%rsp
  je     L71
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  jmp    L35
L71:
  mov    %rax,%rdx
  and    $0xfff,%edx
  sub    %rdx,%rsp
  test   %rdx,%rdx
  je     L84
  orq    $0x0,-0x8(%rsp,%rdx,1)
L84:
  mov    %rsp,%r13
  mov    %rbx,%rdx
  mov    %rbx,%rax
  and    $0xfffffffffffff000,%rax
  mov    %rsp,%rcx
  sub    %rax,%rcx
L125:
  cmp    %rcx,%rsp
  je     L96
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  jmp    L125
L96:
  mov    %rdx,%rax
  and    $0xfff,%eax
  sub    %rax,%rsp
  test   %rax,%rax
  je     L55
  orq    $0x0,-0x8(%rsp,%rax,1)
L55:
  mov    %rsp,-0x78(%rbp)
  mov    -0x58(%rbp),%rax
  movsd  (%rax),%xmm2
  movsd  %xmm2,-0x90(%rbp)
  sub    $0x8,%rsp
  push   %r13
  push   -0x48(%rbp)
  push   %r11
  push   %r10
  push   %rdi
  movapd %xmm2,%xmm0
  mov    -0x88(%rbp),%rcx
  mov    -0x50(%rbp),%edx
  mov    -0x4c(%rbp),%edi
  call   <def_hat@plt>
  add    $0x30,%rsp
  mov    -0x78(%rbp),%rdx
  mov    -0x48(%rbp),%rsi
  mov    %r14d,%edi
  call   <get_eigs@plt>
  test   %r14d,%r14d
  jle    L91
  mov    -0x48(%rbp),%rdi
  mov    %r14d,%r8d
  lea    0x0(%r13,%r8,8),%rcx
  mov    $0x0,%esi
L18:
  mov    %r13,%rax
  mov    %rdi,%rdx
  pxor   %xmm1,%xmm1
L114:
  movsd  (%rdx),%xmm0
  mulsd  (%rax),%xmm0
  addsd  %xmm0,%xmm1
  add    %rbx,%rdx
  add    $0x8,%rax
  cmp    %rcx,%rax
  jne    L114
  movsd  %xmm1,(%r12,%rsi,8)
  add    $0x1,%rsi
  add    $0x8,%rdi
  cmp    %r8,%rsi
  jne    L18
L91:
  push   -0x70(%rbp)
  push   %r15
  movsd  -0x68(%rbp),%xmm1
  movsd  -0x60(%rbp),%xmm0
  mov    -0x58(%rbp),%r9
  mov    -0x78(%rbp),%r8
  mov    -0x48(%rbp),%rcx
  mov    %r12,%rdx
  mov    -0x4c(%rbp),%esi
  mov    %r14d,%edi
  call   <optimize_px@plt>
  movq   %xmm0,%rbx
  add    $0x10,%rsp
  cmpl   $0x1,0x50(%rbp)
  je     L112
L42:
  mov    -0x38(%rbp),%rax
  sub    %fs:0x28,%rax
  jne    L44
  movq   %rbx,%xmm0
  lea    -0x28(%rbp),%rsp
  pop    %rbx
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  pop    %rbp
  ret
L112:
  pxor   %xmm0,%xmm0
  cvtsi2sdl -0x4c(%rbp),%xmm0
  movsd  -0x90(%rbp),%xmm1
  mulsd  %xmm0,%xmm1
  sub    $0x8,%rsp
  mov    -0x58(%rbp),%rax
  mulsd  (%rax),%xmm0
  cvttsd2si %xmm0,%eax
  push   %rax
  cvttsd2si %xmm1,%r9d
  mov    -0x78(%rbp),%r8
  mov    -0x80(%rbp),%rcx
  mov    %r13,%rdx
  mov    -0x48(%rbp),%rsi
  mov    %r14d,%edi
  call   <inv_hat@plt>
  add    $0x10,%rsp
  jmp    L42
L44:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
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;
}
```