user: 请从给定的汇编指令推导出C源代码:

```asm
<rank>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  mov    %rdi,%r13
  shr    $0x3f,%r13
  push   %r12
  mov    %rdi,%r12
  push   %rbp
  add    %rdi,%r13
  mov    %rsi,%rbp
  push   %rbx
  sar    %r13
  mov    %rdx,%rbx
  lea    0x0(,%r13,8),%r15
  mov    %r15,%rdi
  sub    $0x28,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x18(%rsp)
  xor    %eax,%eax
  call   <malloc@plt>
  mov    %rax,%r14
  cmp    $0x1,%r12
  jle    L51
  mov    %r15,%rdx
  mov    $0xff,%esi
  mov    %rax,%rdi
  call   <memset@plt>
  lea    0x10(%rsp),%rcx
  mov    %rbp,%rsi
  mov    %r12,%rdi
  lea    0x8(%rsp),%rdx
  call   <minmax@plt>
  movsd  0x10(%rsp),%xmm0
  movsd  0x8(%rsp),%xmm2
  ucomisd %xmm2,%xmm0
  jp     L84
  je     L22
L84:
  lea    -0x1(%r13),%rax
  pxor   %xmm3,%xmm3
  subsd  %xmm2,%xmm0
  cvtsi2sd %rax,%xmm3
  divsd  %xmm0,%xmm3
L115:
  xor    %edx,%edx
  jmp    L87
  nopl   0x0(%rax,%rax,1)
L187:
  mov    %rdx,(%rcx)
  mov    %rax,(%rbx,%rdx,8)
  add    $0x1,%rdx
  cmp    %rdx,%r12
  je     L103
L87:
  movsd  0x0(%rbp,%rdx,8),%xmm0
  movapd %xmm0,%xmm1
  subsd  %xmm2,%xmm1
  mulsd  %xmm3,%xmm1
  cvttsd2si %xmm1,%rax
  lea    (%r14,%rax,8),%rcx
  mov    (%rcx),%rax
  cmp    $0xffffffffffffffff,%rax
  je     L187
  movsd  0x0(%rbp,%rax,8),%xmm1
  comisd %xmm0,%xmm1
  jb     L83
  mov    %rdx,(%rcx)
  mov    %rax,(%rbx,%rdx,8)
  add    $0x1,%rdx
  cmp    %rdx,%r12
  jne    L87
L103:
  mov    %r14,%rdi
  xor    %esi,%esi
  xor    %edx,%edx
  cmp    $0x1,%r12
  je     L128
  nopl   (%rax)
L49:
  mov    (%rdi),%rax
  cmp    $0xffffffffffffffff,%rax
  je     L196
  nopl   0x0(%rax)
L6:
  lea    (%rbx,%rax,8),%rcx
  add    $0x1,%rdx
  mov    (%rcx),%rax
  mov    %rdx,(%rcx)
  cmp    $0xffffffffffffffff,%rax
  jne    L6
L196:
  add    $0x1,%rsi
  add    $0x8,%rdi
  cmp    %rsi,%r13
  jg     L49
  test   %r12,%r12
  mov    $0x1,%ecx
  cmovg  %r12,%rcx
  cmp    $0x1,%r12
  je     L128
  mov    %rcx,%rdx
  pcmpeqd %xmm1,%xmm1
  mov    %rbx,%rax
  shr    %rdx
  shl    $0x4,%rdx
  add    %rbx,%rdx
  nopl   0x0(%rax,%rax,1)
L168:
  movdqu (%rax),%xmm0
  add    $0x10,%rax
  paddq  %xmm1,%xmm0
  movups %xmm0,-0x10(%rax)
  cmp    %rax,%rdx
  jne    L168
  mov    %rcx,%rax
  and    $0xfffffffffffffffe,%rax
  and    $0x1,%ecx
  je     L229
L31:
  subq   $0x1,(%rbx,%rax,8)
L229:
  mov    %r14,%rdi
  call   <free@plt>
L171:
  mov    0x18(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L32
  add    $0x28,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L104:
  comisd 0x0(%rbp,%rax,8),%xmm0
  jbe    L187
L83:
  lea    (%rbx,%rax,8),%rcx
  mov    (%rcx),%rax
  cmp    $0xffffffffffffffff,%rax
  jne    L104
  jmp    L187
L51:
  lea    0x10(%rsp),%rcx
  lea    0x8(%rsp),%rdx
  mov    %rbp,%rsi
  mov    %r12,%rdi
  call   <minmax@plt>
  movsd  0x10(%rsp),%xmm0
  movsd  0x8(%rsp),%xmm2
  ucomisd %xmm2,%xmm0
  jp     L260
  je     L217
L260:
  lea    -0x1(%r13),%rax
  pxor   %xmm3,%xmm3
  subsd  %xmm2,%xmm0
  cvtsi2sd %rax,%xmm3
  divsd  %xmm0,%xmm3
  test   %r12,%r12
  jle    L229
  jmp    L115
  nopw   0x0(%rax,%rax,1)
L217:
  cmp    $0x1,%r12
  jne    L171
  xor    %eax,%eax
  mov    %rax,(%rbx,%rax,8)
  jmp    L171
L22:
  mov    %r12,%rdx
  movdqa D13(%rip),%xmm0
  movdqa D6(%rip),%xmm2
  mov    %rbx,%rax
  shr    %rdx
  shl    $0x4,%rdx
  add    %rbx,%rdx
  nopl   (%rax)
L12:
  movdqa %xmm0,%xmm1
  add    $0x10,%rax
  paddq  %xmm2,%xmm0
  movups %xmm1,-0x10(%rax)
  cmp    %rax,%rdx
  jne    L12
  mov    %r12,%rax
  and    $0xfffffffffffffffe,%rax
  and    $0x1,%r12d
  je     L171
  mov    %rax,(%rbx,%rax,8)
  jmp    L171
L128:
  xor    %eax,%eax
  jmp    L31
L32:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: unpack_data
arguments: tag: D13
datatype: byte[16]
name: unpack_data
arguments: tag: D6
datatype: byte[16]

tool: {"D13": [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00]}

tool: {"D6": [0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00]}

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);
}
```