user: Converte this assembly snippet into its equivalent C code:

```asm
<getfrac_onenight>:
  endbr64
  push   %r15
  movslq %edi,%rdi
  push   %r14
  mov    %rdi,%r15
  mov    %r8,%r14
  push   %r13
  mov    %rcx,%r13
  push   %r12
  mov    %rsi,%r12
  push   %rbp
  push   %rbx
  sub    $0x58,%rsp
  movsd  D24(%rip),%xmm1
  divsd  D22(%rip),%xmm4
  addsd  D27(%rip),%xmm4
  mov    %rdi,0x28(%rsp)
  divsd  %xmm0,%xmm1
  movsd  (%rsi),%xmm0
  movsd  %xmm2,0x18(%rsp)
  movsd  %xmm4,0x30(%rsp)
  addsd  %xmm4,%xmm0
  addsd  -0x8(%rsi,%rdi,8),%xmm4
  movsd  %xmm3,0x20(%rsp)
  cvttsd2si %xmm4,%rbx
  cvttsd2si %xmm0,%rax
  add    $0x1,%ebx
  sub    %eax,%ebx
  mov    %eax,0x38(%rsp)
  mov    $0x2,%eax
  cmp    %eax,%ebx
  cmovl  %eax,%ebx
  lea    0x0(,%rbx,8),%edi
  movsd  %xmm1,0x10(%rsp)
  call   <malloc@plt>
  xor    %esi,%esi
  mov    %rax,%rbp
  mov    %ebx,%eax
  shl    $0x3,%rax
  mov    %rbp,%rdi
  mov    %rax,%rdx
  mov    %rax,0x40(%rsp)
  call   <memset@plt>
  test   %r15d,%r15d
  jle    L34
  lea    -0x1(%rbx),%eax
  pxor   %xmm3,%xmm3
  xor    %r15d,%r15d
  mov    %eax,0x3c(%rsp)
  movsd  %xmm3,0x48(%rsp)
  movsd  %xmm3,(%rsp)
  xchg   %ax,%ax
L26:
  movsd  (%r12,%r15,8),%xmm0
  subsd  0x20(%rsp),%xmm0
  mulsd  0x10(%rsp),%xmm0
  movsd  %xmm0,0x8(%rsp)
  call   <floor@plt>
  pxor   %xmm1,%xmm1
  movsd  0x8(%rsp),%xmm0
  movsd  0x18(%rsp),%xmm7
  cvtsi2sd %rax,%xmm1
  subsd  %xmm1,%xmm0
  comisd %xmm0,%xmm7
  jb     L8
  movsd  0x30(%rsp),%xmm0
  addsd  (%r12,%r15,8),%xmm0
  mov    $0x0,%ecx
  movsd  (%r14,%r15,8),%xmm1
  cvttsd2si %xmm0,%rax
  movsd  0x0(%r13,%r15,8),%xmm0
  mulsd  %xmm1,%xmm1
  sub    0x38(%rsp),%eax
  cmovs  %ecx,%eax
  mulsd  %xmm0,%xmm0
  cmp    %ebx,%eax
  cmovge 0x3c(%rsp),%eax
  cltq
  lea    0x0(%rbp,%rax,8),%rax
  divsd  %xmm1,%xmm0
  movsd  (%rax),%xmm1
  addsd  %xmm0,%xmm1
  addsd  (%rsp),%xmm0
  movsd  %xmm1,(%rax)
  movsd  %xmm0,(%rsp)
L8:
  add    $0x1,%r15
  cmp    %r15,0x28(%rsp)
  jne    L26
L12:
  mov    0x40(%rsp),%rdx
  mov    %rbp,%rax
  pxor   %xmm0,%xmm0
  add    %rbp,%rdx
  nopl   0x0(%rax)
L48:
  movsd  (%rax),%xmm1
  divsd  (%rsp),%xmm1
  maxsd  %xmm0,%xmm1
  add    $0x8,%rax
  movapd %xmm1,%xmm0
  cmp    %rax,%rdx
  jne    L48
  mov    %rbp,%rdi
  movsd  %xmm1,(%rsp)
  call   <free@plt>
  movsd  (%rsp),%xmm0
  add    $0x58,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax,%rax,1)
L34:
  pxor   %xmm5,%xmm5
  movsd  %xmm5,0x48(%rsp)
  movsd  %xmm5,(%rsp)
  jmp    L12
```

tool_calls: name: unpack_data
arguments: data_label: D24
type_infered: f64
name: unpack_data
arguments: data_label: D22
type_infered: f64
name: unpack_data
arguments: data_label: D27
type_infered: f64

tool: D24: 1

tool: D22: 24

tool: D27: 0.5

assistant: ```c
double getfrac_onenight(int n, double *t, double *u, double *v, double *err, double bper, double depth, double qtran, double bt0, double timezone) {
  int i, j, k, nnights;
  long night, night0, night1;
  double ph, f0, maxfrac;
  double *chisqrnights, chisqrtot, val;
  f0 = 1. / bper;
  timezone = timezone / 24.0 + 0.5;
  night0 = (long)(t[0] + timezone);
  night1 = (long)(t[n - 1] + timezone);
  nnights = (int)((night1 - night0) + 1);
  if (nnights < 2)
    nnights = 2;
  chisqrnights = (double *)malloc(nnights * sizeof(double));
  chisqrtot = 0.;
  for (i = 0; i < nnights; i++)
    chisqrnights[i] = 0.;
  for (i = 0; i < n; i++) {
    ph = (t[i] - bt0) * f0;
    ph -= floor(ph);
    if (ph <= qtran) {
      night = (long)(t[i] + timezone);
      k = (int)(night - night0);
      if (k < 0)
        k = 0;
      if (k >= nnights)
        k = nnights - 1;
      val = v[i] * v[i] / (err[i] * err[i]);
      chisqrnights[k] += val;
      chisqrtot += val;
    }
  }
  maxfrac = 0.;
  for (k = 0; k < nnights; k++) {
    val = chisqrnights[k] / chisqrtot;
    if (val > maxfrac)
      maxfrac = val;
  }
  free(chisqrnights);
  return (maxfrac);
}
```