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

```asm
<ks_test>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x28,%rsp
  mov    %rdx,0x10(%rsp)
  mov    %rcx,0x18(%rsp)
  test   %edi,%edi
  jle    L84
  mov    %edi,%r14d
  mov    %rsi,%r15
  lea    0x1(%rdi),%ebp
  movslq %ebp,%rbp
  lea    0x0(,%rbp,4),%rdi
  call   <malloc@plt>
  mov    %rax,%rbx
  shl    $0x3,%rbp
  mov    %rbp,%rdi
  call   <malloc@plt>
  mov    %rax,%r13
  mov    %rbp,%rdi
  call   <malloc@plt>
  mov    %rax,%r12
  pxor   %xmm6,%xmm6
  cvtsi2sd %r14d,%xmm6
  movq   %xmm6,%rbp
  test   %rbx,%rbx
  setne  %dl
  test   %r13,%r13
  setne  %al
  test   %al,%dl
  je     L147
  test   %r12,%r12
  je     L147
  lea    0x1(%r14),%esi
  mov    $0x0,%eax
L139:
  movl   $0x0,(%rbx,%rax,4)
  mov    %rbp,0x0(%r13,%rax,8)
  movq   $0x0,(%r12,%rax,8)
  add    $0x1,%rax
  cmp    %rsi,%rax
  jne    L139
  mov    %r15,%rdx
  lea    -0x1(%r14),%eax
  lea    0x8(%r15,%rax,8),%rdi
  pxor   %xmm2,%xmm2
  jmp    L158
L84:
  lea    D36(%rip),%rdi
  call   <puts@plt>
  lea    D59(%rip),%rdi
  call   <puts@plt>
  mov    $0x0,%edi
  call   <exit@plt>
L147:
  lea    D22(%rip),%rdi
  call   <puts@plt>
  lea    D59(%rip),%rdi
  call   <puts@plt>
  mov    $0x0,%edi
  call   <exit@plt>
L129:
  lea    D36(%rip),%rdi
  call   <puts@plt>
  lea    D59(%rip),%rdi
  call   <puts@plt>
  mov    $0x0,%edi
  call   <exit@plt>
L125:
  add    $0x8,%rdx
  cmp    %rdx,%rdi
  je     L137
L158:
  movq   %rbp,%xmm0
  mulsd  (%rdx),%xmm0
  comisd %xmm0,%xmm2
  ja     L129
  movq   %rbp,%xmm3
  comisd %xmm3,%xmm0
  ja     L129
  cvttsd2si %xmm0,%eax
  cltq
  addl   $0x1,(%rbx,%rax,4)
  shl    $0x3,%rax
  lea    0x0(%r13,%rax,1),%rcx
  movsd  (%rcx),%xmm1
  comisd %xmm0,%xmm1
  jbe    L123
  movsd  %xmm0,(%rcx)
L123:
  add    %r12,%rax
  comisd (%rax),%xmm0
  jbe    L125
  movsd  %xmm0,(%rax)
  jmp    L125
L137:
  mov    $0x0,%eax
  mov    D39(%rip),%r14
  mov    %r14,0x8(%rsp)
  movq   %r14,%xmm0
  jmp    L34
L86:
  add    $0x1,%rax
  cmp    %rsi,%rax
  je     L23
L34:
  mov    (%rbx,%rax,4),%edx
  test   %edx,%edx
  jle    L86
  movsd  0x0(%r13,%rax,8),%xmm1
  subsd  %xmm0,%xmm1
  movq   %r14,%xmm4
  maxsd  %xmm4,%xmm1
  movq   %xmm1,%r14
  pxor   %xmm1,%xmm1
  cvtsi2sd %edx,%xmm1
  addsd  %xmm1,%xmm0
  movapd %xmm0,%xmm1
  subsd  (%r12,%rax,8),%xmm1
  maxsd  0x8(%rsp),%xmm1
  movsd  %xmm1,0x8(%rsp)
  jmp    L86
L23:
  pxor   %xmm0,%xmm0
  movq   %rbp,%xmm7
  ucomisd %xmm7,%xmm0
  ja     L156
  movq   %rbp,%xmm0
  sqrtsd %xmm0,%xmm0
  movsd  0x8(%rsp),%xmm1
  divsd  %xmm0,%xmm1
  mov    0x10(%rsp),%rax
  movsd  %xmm1,(%rax)
L98:
  movq   %r14,%xmm1
  divsd  %xmm0,%xmm1
  mov    0x18(%rsp),%rax
  movsd  %xmm1,(%rax)
  mov    %rbx,%rdi
  call   <free@plt>
  mov    %r13,%rdi
  call   <free@plt>
  mov    %r12,%rdi
  call   <free@plt>
  add    $0x28,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L156:
  movq   %rbp,%xmm0
  call   <sqrt@plt>
  movapd %xmm0,%xmm1
  movsd  0x8(%rsp),%xmm0
  divsd  %xmm1,%xmm0
  mov    0x10(%rsp),%rax
  movsd  %xmm0,(%rax)
  movq   %rbp,%xmm0
  call   <sqrt@plt>
  jmp    L98
```

tool_calls: name: unpack_data
arguments: tag: D36
type_infered: string
name: unpack_data
arguments: tag: D59
type_infered: string
name: unpack_data
arguments: tag: D22
type_infered: string
name: unpack_data
arguments: tag: D39
type_infered: f64

tool: D36: Error in ks_test: argument out of range

tool: D59: Program aborted


tool: D22: Error in ks_test: could not allocate auxiliary arrays

tool: D39: 0

assistant: ```c
void ks_test(int n, double f[], double *pkp, double *pkm) {
  int *pn, k, i;
  double *pu, *pv, xn, sn, x, kp, km;
  if (n <= 0) {
    printf("Error in ks_test: argument out of range\n");
    printf("Program aborted\n\n");
    exit(0);
  }
  pn = malloc((n + 1) * sizeof(int));
  pu = malloc((n + 1) * sizeof(double));
  pv = malloc((n + 1) * sizeof(double));
  xn = (double)n;
  if (pn && pu && pv) {
    for (k = 0; k <= n; k++) {
      pn[k] = 0;
      pu[k] = xn;
      pv[k] = 0.0;
    }
  } else {
    printf("Error in ks_test: could not allocate auxiliary arrays\n");
    printf("Program aborted\n\n");
    exit(0);
  }
  for (i = 0; i < n; i++) {
    x = xn * f[i];
    if ((x < 0) || (x > xn)) {
      printf("Error in ks_test: argument out of range\n");
      printf("Program aborted\n\n");
      exit(0);
    }
    k = (int)x;
    pn[k] += 1;
    if (x < pu[k])
      pu[k] = x;
    if (x > pv[k])
      pv[k] = x;
  }
  sn = 0.0;
  kp = 0.0;
  km = 0.0;
  for (k = 0; k <= n; k++) {
    if (pn[k] > 0) {
      x = pu[k] - sn;
      if (x > km)
        km = x;
      sn += (double)pn[k];
      x = sn - pv[k];
      if (x > kp)
        kp = x;
    }
  }
  *pkp = kp / sqrt(xn);
  *pkm = km / sqrt(xn);
  free(pn);
  free(pu);
  free(pv);
}
```