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

```asm
<rank>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  add    $0xffffffffffffff80,%rsp
  mov    %rdi,-0x68(%rbp)
  mov    %rsi,-0x70(%rbp)
  mov    %rdx,-0x78(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  mov    -0x68(%rbp),%rax
  mov    %rax,%rdx
  shr    $0x3f,%rdx
  add    %rdx,%rax
  sar    %rax
  mov    %rax,-0x30(%rbp)
  mov    -0x30(%rbp),%rax
  shl    $0x3,%rax
  mov    %rax,%rdi
  call   <malloc@plt>
  mov    %rax,-0x28(%rbp)
  movq   $0x0,-0x48(%rbp)
  jmp    L212
L149:
  mov    -0x48(%rbp),%rax
  lea    0x0(,%rax,8),%rdx
  mov    -0x28(%rbp),%rax
  add    %rdx,%rax
  movq   $0xffffffffffffffff,(%rax)
  addq   $0x1,-0x48(%rbp)
L212:
  mov    -0x48(%rbp),%rax
  cmp    -0x30(%rbp),%rax
  jl     L149
  lea    -0x50(%rbp),%rcx
  lea    -0x58(%rbp),%rdx
  mov    -0x70(%rbp),%rsi
  mov    -0x68(%rbp),%rax
  mov    %rax,%rdi
  call   <minmax@plt>
  movsd  -0x50(%rbp),%xmm0
  movsd  -0x58(%rbp),%xmm1
  ucomisd %xmm1,%xmm0
  jp     L6
  ucomisd %xmm1,%xmm0
  jne    L6
  movq   $0x0,-0x48(%rbp)
  jmp    L38
L4:
  mov    -0x48(%rbp),%rax
  lea    0x0(,%rax,8),%rdx
  mov    -0x78(%rbp),%rax
  add    %rax,%rdx
  mov    -0x48(%rbp),%rax
  mov    %rax,(%rdx)
  addq   $0x1,-0x48(%rbp)
L38:
  mov    -0x48(%rbp),%rax
  cmp    -0x68(%rbp),%rax
  jl     L4
  jmp    L97
L6:
  mov    -0x30(%rbp),%rax
  sub    $0x1,%rax
  pxor   %xmm0,%xmm0
  cvtsi2sd %rax,%xmm0
  movsd  -0x50(%rbp),%xmm1
  movsd  -0x58(%rbp),%xmm2
  subsd  %xmm2,%xmm1
  divsd  %xmm1,%xmm0
  movsd  %xmm0,-0x20(%rbp)
  movq   $0x0,-0x48(%rbp)
  jmp    L8
L191:
  mov    -0x48(%rbp),%rax
  lea    0x0(,%rax,8),%rdx
  mov    -0x70(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm0
  movsd  %xmm0,-0x10(%rbp)
  movsd  -0x58(%rbp),%xmm1
  movsd  -0x10(%rbp),%xmm0
  subsd  %xmm1,%xmm0
  mulsd  -0x20(%rbp),%xmm0
  cvttsd2si %xmm0,%rax
  mov    %rax,-0x40(%rbp)
  mov    -0x40(%rbp),%rax
  lea    0x0(,%rax,8),%rdx
  mov    -0x28(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rax
  mov    %rax,-0x38(%rbp)
  cmpq   $0xffffffffffffffff,-0x38(%rbp)
  je     L3
  mov    -0x38(%rbp),%rax
  lea    0x0(,%rax,8),%rdx
  mov    -0x70(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm0
  comisd -0x10(%rbp),%xmm0
  jae    L3
  jmp    L13
L3:
  mov    -0x40(%rbp),%rax
  lea    0x0(,%rax,8),%rdx
  mov    -0x28(%rbp),%rax
  add    %rax,%rdx
  mov    -0x48(%rbp),%rax
  mov    %rax,(%rdx)
  jmp    L154
L13:
  mov    -0x38(%rbp),%rax
  mov    %rax,-0x18(%rbp)
  mov    -0x38(%rbp),%rax
  lea    0x0(,%rax,8),%rdx
  mov    -0x78(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rax
  mov    %rax,-0x38(%rbp)
  cmpq   $0xffffffffffffffff,-0x38(%rbp)
  je     L43
  mov    -0x38(%rbp),%rax
  lea    0x0(,%rax,8),%rdx
  mov    -0x70(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm1
  movsd  -0x10(%rbp),%xmm0
  comisd %xmm1,%xmm0
  ja     L13
L43:
  mov    -0x18(%rbp),%rax
  lea    0x0(,%rax,8),%rdx
  mov    -0x78(%rbp),%rax
  add    %rax,%rdx
  mov    -0x48(%rbp),%rax
  mov    %rax,(%rdx)
L154:
  mov    -0x48(%rbp),%rax
  lea    0x0(,%rax,8),%rdx
  mov    -0x78(%rbp),%rax
  add    %rax,%rdx
  mov    -0x38(%rbp),%rax
  mov    %rax,(%rdx)
  addq   $0x1,-0x48(%rbp)
L8:
  mov    -0x48(%rbp),%rax
  cmp    -0x68(%rbp),%rax
  jl     L191
  movq   $0x0,-0x48(%rbp)
  movq   $0x0,-0x40(%rbp)
  jmp    L181
L197:
  mov    -0x40(%rbp),%rax
  lea    0x0(,%rax,8),%rdx
  mov    -0x28(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rax
  mov    %rax,-0x38(%rbp)
  jmp    L206
L78:
  mov    -0x38(%rbp),%rax
  mov    %rax,-0x18(%rbp)
  mov    -0x38(%rbp),%rax
  lea    0x0(,%rax,8),%rdx
  mov    -0x78(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rax
  mov    %rax,-0x38(%rbp)
  addq   $0x1,-0x48(%rbp)
  mov    -0x18(%rbp),%rax
  lea    0x0(,%rax,8),%rdx
  mov    -0x78(%rbp),%rax
  add    %rax,%rdx
  mov    -0x48(%rbp),%rax
  mov    %rax,(%rdx)
L206:
  cmpq   $0xffffffffffffffff,-0x38(%rbp)
  jne    L78
  addq   $0x1,-0x40(%rbp)
L181:
  mov    -0x40(%rbp),%rax
  cmp    -0x30(%rbp),%rax
  jl     L197
  movq   $0x0,-0x48(%rbp)
  jmp    L196
L45:
  mov    -0x48(%rbp),%rax
  lea    0x0(,%rax,8),%rdx
  mov    -0x78(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rdx
  mov    -0x48(%rbp),%rax
  lea    0x0(,%rax,8),%rcx
  mov    -0x78(%rbp),%rax
  add    %rcx,%rax
  sub    $0x1,%rdx
  mov    %rdx,(%rax)
  addq   $0x1,-0x48(%rbp)
L196:
  mov    -0x48(%rbp),%rax
  cmp    -0x68(%rbp),%rax
  jl     L45
  mov    -0x28(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
L97:
  mov    -0x8(%rbp),%rax
  sub    %fs:0x28,%rax
  je     L173
  call   <__stack_chk_fail@plt>
L173:
  leave
  ret
```

assistant: ```c
void rank(long nmax, double *x, long *list) {
  long *jptr, nl, n, i, ip, ipp;
  double xmin, xmax, sc, xn;
  nl = nmax / 2;
  jptr = (long *)malloc(nl * sizeof(long));
  for (n = 0; n < nl; n++)
    jptr[n] = (-1);
  minmax(nmax, x, &xmin, &xmax);
  if (xmax == xmin) {
    for (n = 0; n < nmax; n++)
      list[n] = n;
    return;
  }
  sc = (nl - 1) / (xmax - xmin);
  for (n = 0; n < nmax; n++) {
    xn = x[n];
    i = (long)((xn - xmin) * sc);
    ip = jptr[i];
    if ((ip == (-1)) || (xn <= x[ip])) {
      jptr[i] = n;
    } else {
      do {
        ipp = ip;
        ip = list[ip];
      } while ((ip != (-1)) && (xn > x[ip]));
      list[ipp] = n;
    }
    list[n] = ip;
  }
  for (n = 0, i = 0; i < nl; i++) {
    ip = jptr[i];
    while (ip != (-1)) {
      ipp = ip;
      ip = list[ip];
      list[ipp] = ++n;
    }
  }
  for (n = 0; n < nmax; n++)
    list[n] -= 1;
  free(jptr);
}
```