user: Please show me the C implementation that matches the assembly code listed below:

```asm
<lomb_scargle>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %r15
  mov    %edi,%r15d
  push   %r14
  mov    %ecx,%r14d
  push   %r13
  push   %r12
  push   %rbx
  sub    $0x118,%rsp
  mov    0x10(%rbp),%rax
  mov    %r8,-0x58(%rbp)
  mov    0x18(%rbp),%r12
  mov    0x20(%rbp),%r13
  mov    %edx,-0xac(%rbp)
  cvttsd2si %xmm1,%edx
  mov    %rax,-0x68(%rbp)
  mov    0x28(%rbp),%rax
  mov    %r9,-0x60(%rbp)
  mov    %rax,-0x78(%rbp)
  mov    0x30(%rbp),%rax
  mov    %rax,-0x80(%rbp)
  mov    0x38(%rbp),%rax
  mov    %rax,-0x108(%rbp)
  mov    0x40(%rbp),%rax
  mov    %rax,-0x110(%rbp)
  mov    0x48(%rbp),%rax
  mov    %rax,-0x118(%rbp)
  mov    0x50(%rbp),%rax
  mov    %rax,-0x120(%rbp)
  mov    0x58(%rbp),%rax
  mov    %rax,-0xb8(%rbp)
  mov    0x60(%rbp),%rax
  mov    %rax,-0xc0(%rbp)
  mov    0x68(%rbp),%rax
  mov    %rax,-0xc8(%rbp)
  mov    0x70(%rbp),%rax
  mov    0x90(%rbp),%rcx
  movsd  %xmm0,-0xd8(%rbp)
  mov    %rax,-0xd0(%rbp)
  mov    0x78(%rbp),%rax
  mov    %rcx,-0x140(%rbp)
  mov    %rax,-0xf0(%rbp)
  mov    0x80(%rbp),%rax
  movsd  %xmm1,-0xe0(%rbp)
  mov    %rax,-0xf8(%rbp)
  mov    0x88(%rbp),%rax
  movsd  %xmm2,-0x88(%rbp)
  mov    %rax,-0x138(%rbp)
  movsd  %xmm3,-0xe8(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x38(%rbp)
  xor    %eax,%eax
  mov    %edx,%eax
  shr    $0x1f,%eax
  add    %edx,%eax
  sar    %eax
  mov    %eax,(%rcx)
  mov    %rsp,%rcx
  mov    %eax,-0x4c(%rbp)
  movslq %edi,%rax
  lea    0xf(,%rax,8),%rax
  mov    %rax,%r8
  mov    %rax,%rdx
  and    $0xfffffffffffff000,%r8
  and    $0xfffffffffffffff0,%rdx
  sub    %r8,%rcx
  cmp    %rcx,%rsp
  je     L165
L6:
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  cmp    %rcx,%rsp
  jne    L6
L165:
  and    $0xfff,%edx
  sub    %rdx,%rsp
  test   %rdx,%rdx
  jne    L184
L237:
  mov    %rax,%r8
  mov    %rsp,%rcx
  mov    %rax,%rdx
  mov    %rsp,-0xa0(%rbp)
  and    $0xfffffffffffff000,%r8
  and    $0xfffffffffffffff0,%rdx
  sub    %r8,%rcx
  cmp    %rcx,%rsp
  je     L157
L53:
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  cmp    %rcx,%rsp
  jne    L53
L157:
  and    $0xfff,%edx
  sub    %rdx,%rsp
  test   %rdx,%rdx
  jne    L197
L149:
  mov    %rax,%r8
  mov    %rsp,%rcx
  mov    %rax,%rdx
  mov    %rsp,-0xa8(%rbp)
  and    $0xfffffffffffff000,%r8
  and    $0xfffffffffffffff0,%rdx
  sub    %r8,%rcx
  cmp    %rcx,%rsp
  je     L70
L190:
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  cmp    %rcx,%rsp
  jne    L190
L70:
  and    $0xfff,%edx
  sub    %rdx,%rsp
  test   %rdx,%rdx
  je     L103
  orq    $0x0,-0x8(%rsp,%rdx,1)
L103:
  mov    %rax,%rdx
  mov    %rsp,%rcx
  and    $0xfffffffffffff000,%rax
  mov    %rsp,-0x128(%rbp)
  sub    %rax,%rcx
  and    $0xfffffffffffffff0,%rdx
  cmp    %rcx,%rsp
  je     L225
L163:
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  cmp    %rcx,%rsp
  jne    L163
L225:
  mov    %rdx,%rax
  and    $0xfff,%eax
  sub    %rax,%rsp
  test   %rax,%rax
  je     L206
  orq    $0x0,-0x8(%rsp,%rax,1)
L206:
  movslq %esi,%rax
  mov    %rsp,-0x130(%rbp)
  mov    %rax,-0x90(%rbp)
  test   %rax,%rax
  je     L186
  movq   $0x0,-0x98(%rbp)
  xor    %ebx,%ebx
  movq   $0x0,-0x70(%rbp)
  movq   $0x0,-0x100(%rbp)
  jmp    L71
  nopl   0x0(%rax)
L231:
  mov    -0x80(%rbp),%rdx
  mov    -0x78(%rbp),%rsi
  xor    %r9d,%r9d
  mov    %r13,%r8
  mov    %r12,%rcx
  mov    %r15d,%edi
  add    $0x1,%rbx
  call   <update_sincos@plt>
  cmp    -0x90(%rbp),%rbx
  je     L143
L71:
  mov    -0x68(%rbp),%r9
  mov    -0x60(%rbp),%rdx
  mov    %r15d,%edi
  mov    %r13,%r8
  mov    %r12,%rcx
  mov    %r14d,%esi
  call   <do_lomb@plt>
  movsd  -0x70(%rbp),%xmm4
  pxor   %xmm5,%xmm5
  mov    -0x58(%rbp),%rax
  mov    $0x0,%edi
  ucomisd %xmm5,%xmm4
  movsd  %xmm0,(%rax,%rbx,8)
  setnp  %al
  cmovne %edi,%eax
  test   %al,%al
  je     L222
  comisd -0x98(%rbp),%xmm0
  ja     L185
L222:
  comisd -0x88(%rbp),%xmm0
  jbe    L231
  sub    $0x8,%rsp
  lea    -0x4c(%rbp),%rax
  mov    -0x60(%rbp),%rdx
  mov    %r13,%r8
  push   %rax
  mov    -0xa0(%rbp),%r9
  mov    %r12,%rcx
  mov    %r14d,%esi
  push   -0x68(%rbp)
  movsd  -0xe0(%rbp),%xmm0
  mov    %r15d,%edi
  push   -0x120(%rbp)
  push   -0x118(%rbp)
  push   -0x110(%rbp)
  push   -0x108(%rbp)
  push   -0xa8(%rbp)
  call   <do_lomb_zoom@plt>
  mov    -0xf0(%rbp),%rax
  add    $0x38,%rsp
  movsd  -0xe8(%rbp),%xmm1
  mov    -0xc0(%rbp),%r9
  mov    -0xc8(%rbp),%r8
  mov    %r14d,%edx
  mov    %r15d,%edi
  movsd  (%rax),%xmm0
  lea    -0x48(%rbp),%rax
  push   $0x0
  mov    -0xb8(%rbp),%rcx
  mov    -0xac(%rbp),%esi
  push   %rax
  lea    -0x40(%rbp),%rax
  push   -0xf8(%rbp)
  push   %rax
  push   -0xd0(%rbp)
  push   -0x60(%rbp)
  push   -0x68(%rbp)
  push   -0xa8(%rbp)
  push   -0xa0(%rbp)
  movsd  %xmm0,-0x40(%rbp)
  movsd  -0xd8(%rbp),%xmm0
  call   <refine_psd@plt>
  add    $0x50,%rsp
  comisd -0x70(%rbp),%xmm0
  mov    -0x58(%rbp),%rax
  movsd  %xmm0,(%rax,%rbx,8)
  jbe    L231
  mov    -0xa0(%rbp),%rsi
  mov    -0x130(%rbp),%r8
  mov    %r15d,%edi
  mov    -0x128(%rbp),%rcx
  mov    -0xa8(%rbp),%rdx
  call   <copy_sincos@plt>
  mov    -0x58(%rbp),%rax
  mov    -0x140(%rbp),%rsi
  mov    %rbx,-0x100(%rbp)
  movsd  (%rax,%rbx,8),%xmm3
  mov    -0x4c(%rbp),%eax
  movsd  %xmm3,-0x70(%rbp)
  mov    %eax,(%rsi)
  jmp    L231
  nopl   0x0(%rax)
L184:
  orq    $0x0,-0x8(%rsp,%rdx,1)
  jmp    L237
L197:
  orq    $0x0,-0x8(%rsp,%rdx,1)
  jmp    L149
  cs nopw 0x0(%rax,%rax,1)
L185:
  mov    -0x130(%rbp),%r8
  mov    %r13,%rdx
  mov    %r12,%rsi
  mov    %r15d,%edi
  mov    -0x128(%rbp),%rcx
  movsd  %xmm0,-0x98(%rbp)
  call   <copy_sincos@plt>
  mov    -0x58(%rbp),%rax
  mov    %rbx,-0x100(%rbp)
  movsd  (%rax,%rbx,8),%xmm0
  jmp    L222
  nopl   0x0(%rax)
L143:
  mov    -0x58(%rbp),%rax
  mov    -0x100(%rbp),%rsi
  lea    (%rax,%rsi,8),%rax
  mov    %rax,-0x58(%rbp)
L186:
  sub    $0x8,%rsp
  movsd  -0xe8(%rbp),%xmm1
  movsd  -0xd8(%rbp),%xmm0
  mov    %r14d,%edx
  push   $0x1
  mov    -0xac(%rbp),%esi
  mov    %r15d,%edi
  push   -0x138(%rbp)
  mov    -0xc0(%rbp),%r9
  mov    -0xc8(%rbp),%r8
  push   -0xf8(%rbp)
  mov    -0xb8(%rbp),%rcx
  push   -0xf0(%rbp)
  push   -0xd0(%rbp)
  push   -0x60(%rbp)
  push   -0x68(%rbp)
  push   -0x130(%rbp)
  push   -0x128(%rbp)
  call   <refine_psd@plt>
  mov    -0x58(%rbp),%rax
  add    $0x50,%rsp
  movsd  %xmm0,(%rax)
  mov    -0x38(%rbp),%rax
  sub    %fs:0x28,%rax
  jne    L38
  lea    -0x28(%rbp),%rsp
  pop    %rbx
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  pop    %rbp
  ret
L38:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
void lomb_scargle(int numt, int numf, int nharm, int detrend_order, double psd[], double cn[], double wth[], double sinx[], double cosx[], double sinx_step[], double cosx_step[], double sinx_back[], double cosx_back[], double sinx_smallstep[], double cosx_smallstep[], double hat_matr[], double hat_hat[], double hat0[], double soln[], double chi0, double freq_zoom, double psdmin, double tone_control, double lambda0[], double lambda0_range[], double Tr[], int ifreq[]) {
  int i, k, npar = 2 * (int)nharm, ifr = (int)(freq_zoom) / 2;
  unsigned long j;
  unsigned long jmax = 0;
  *ifreq = ifr;
  double psdmax = 0., psd0max = 0., Trace, sinx1[numt], cosx1[numt], sinx2[numt], cosx2[numt], lambda, px, pxmax;
  for (j = 0; j < numf; j++) {
    psd[j] = do_lomb(numt, detrend_order, cn, sinx, cosx, wth);
    if (psd[j] > psd0max && psdmax == 0) {
      psd0max = psd[j];
      copy_sincos(numt, sinx, cosx, sinx2, cosx2);
      jmax = j;
    }
    if (psd[j] > (double)psdmin) {
      px = do_lomb_zoom(numt, detrend_order, cn, sinx, cosx, sinx1, cosx1, sinx_back, cosx_back, sinx_smallstep, cosx_smallstep, wth, freq_zoom, &ifr);
      lambda = *lambda0;
      psd[j] = refine_psd(numt, nharm, detrend_order, hat_matr, hat0, hat_hat, sinx1, cosx1, wth, cn, soln, &lambda, lambda0_range, chi0, tone_control, &Trace, 0);
      if (psd[j] > psdmax) {
        copy_sincos(numt, sinx1, cosx1, sinx2, cosx2);
        psdmax = psd[j];
        *ifreq = ifr;
        jmax = j;
      }
    }
    update_sincos(numt, sinx_step, cosx_step, sinx, cosx, 0);
  }
  psd[jmax] = refine_psd(numt, nharm, detrend_order, hat_matr, hat0, hat_hat, sinx2, cosx2, wth, cn, soln, lambda0, lambda0_range, chi0, tone_control, Tr, 1);
}
```