user: 请将这段汇编代码片段转换成等效的C代码：

```asm
<ln_grid_search>:
  endbr64
  push   %r15
  movapd %xmm0,%xmm4
  pxor   %xmm0,%xmm0
  push   %r14
  mov    %rcx,%r14
  push   %r13
  mov    %edx,%r13d
  push   %r12
  mov    %rsi,%r12
  lea    D11(%rip),%rsi
  push   %rbp
  movq   %xmm1,%rbp
  push   %rbx
  mov    %r8d,%ebx
  sub    $0x38,%rsp
  comisd %xmm2,%xmm0
  mov    %rdi,(%rsp)
  mov    %r9,0x8(%rsp)
  movsd  %xmm3,0x10(%rsp)
  ja     L58
L37:
  lea    0x0(,%rbx,8),%edi
  mov    %rsi,0x20(%rsp)
  movsd  %xmm4,0x18(%rsp)
  movsd  %xmm2,0x28(%rsp)
  call   <malloc@plt>
  pxor   %xmm1,%xmm1
  movq   %rbp,%xmm0
  test   %ebx,%ebx
  movsd  0x18(%rsp),%xmm4
  mov    %rax,%r15
  lea    -0x1(%rbx),%eax
  mov    0x20(%rsp),%rsi
  cvtsi2sd %eax,%xmm1
  subsd  %xmm4,%xmm0
  divsd  %xmm1,%xmm0
  jle    L4
  movsd  0x28(%rsp),%xmm2
  mov    %ebx,%eax
  xor    %edx,%edx
L39:
  pxor   %xmm1,%xmm1
  cvtsi2sd %edx,%xmm1
  mulsd  %xmm0,%xmm1
  addsd  %xmm4,%xmm1
  addsd  %xmm2,%xmm1
  movsd  %xmm1,(%r15,%rdx,8)
  add    $0x1,%rdx
  cmp    %rax,%rdx
  jne    L39
  mov    %r14,%rdi
  mov    %rdx,0x18(%rsp)
  call   <strcmp@plt>
  mov    0x18(%rsp),%rdx
  test   %rax,%rax
  jne    L51
  mov    %r15,%rbp
  lea    (%r15,%rdx,8),%r14
  nopl   0x0(%rax)
L15:
  movsd  0x0(%rbp),%xmm0
  mov    $0xa,%edi
  add    $0x8,%rbp
  call   <pow@plt>
  movsd  %xmm0,-0x8(%rbp)
  cmp    %r14,%rbp
  jne    L15
L51:
  movsd  0x10(%rsp),%xmm0
  mov    (%rsp),%rdi
  mov    %ebx,%r8d
  mov    %r15,%rcx
  mov    0x8(%rsp),%r9
  mov    %r13d,%edx
  mov    %r12,%rsi
  call   <ln_grid_optimal@plt>
  mov    %r15,%rdi
  cltq
  movsd  (%r15,%rax,8),%xmm0
  movsd  %xmm0,(%rsp)
  call   <free@plt>
  movsd  (%rsp),%xmm0
  add    $0x38,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  xchg   %ax,%ax
L58:
  mov    (%rsp),%rdi
  mov    %r12,%rsi
  movsd  %xmm4,0x28(%rsp)
  call   <ln_argmin_asymptotic@plt>
  lea    D11(%rip),%rsi
  mov    %r14,%rdi
  mov    %rsi,0x18(%rsp)
  movsd  %xmm0,0x20(%rsp)
  call   <strcmp@plt>
  mov    0x18(%rsp),%rsi
  movsd  0x20(%rsp),%xmm2
  test   %rax,%rax
  movsd  0x28(%rsp),%xmm4
  jne    L37
  movapd %xmm2,%xmm0
  mov    %rsi,0x20(%rsp)
  movsd  %xmm4,0x18(%rsp)
  call   <log10@plt>
  mov    0x20(%rsp),%rsi
  movsd  0x18(%rsp),%xmm4
  movapd %xmm0,%xmm2
  jmp    L37
  xchg   %ax,%ax
L4:
  mov    %r14,%rdi
  call   <strcmp@plt>
  jmp    L51
```

tool_calls: name: unpack_data
arguments: tag: D11
data_type: string

tool: D11: log

assistant: ```c
double ln_grid_search(const double *data, const double *weight, const int n, const double xmin, const double xmax, double offset, const char *scale, const int k, const char *risk_function, const double threshold) {
  if (offset < 0) {
    offset = ln_argmin_asymptotic(data, weight, n);
    if (strcmp(scale, "log") == 0) {
      offset = log10(offset);
    }
  }
  double *bandwidths = malloc(k * sizeof(double));
  double delta = (xmax - xmin) / (k - 1);
  for (int i = 0; i < k; i++) {
    bandwidths[i] = i * delta + xmin + offset;
  }
  if (strcmp(scale, "log") == 0) {
    for (int i = 0; i < k; i++) {
      bandwidths[i] = pow(10, bandwidths[i]);
    }
  }
  int idx = ln_grid_optimal(data, weight, n, bandwidths, k, risk_function, threshold);
  double result = bandwidths[idx];
  free(bandwidths);
  return result;
}
```