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

```asm
<grid_search_reg2d_nn>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0xe0,%rsp
  mov    %rdi,-0x98(%rbp)
  mov    %rsi,-0xa0(%rbp)
  mov    %rdx,-0xa8(%rbp)
  mov    %rcx,-0xb0(%rbp)
  movsd  %xmm0,-0xb8(%rbp)
  movsd  %xmm1,-0xc0(%rbp)
  mov    %r8,-0xc8(%rbp)
  mov    %r9,-0xd0(%rbp)
  movl   $0x0,-0x8c(%rbp)
  mov    -0xb8(%rbp),%rax
  movq   %rax,%xmm0
  call   <cos@plt>
  movq   %xmm0,%rax
  mov    %rax,-0x48(%rbp)
  mov    -0xb8(%rbp),%rax
  movq   %rax,%xmm0
  call   <sin@plt>
  movq   %xmm0,%rax
  mov    %rax,-0x40(%rbp)
  mov    -0xc0(%rbp),%rax
  movq   %rax,%xmm0
  call   <cos@plt>
  movq   %xmm0,%rax
  mov    %rax,-0x38(%rbp)
  mov    -0xc0(%rbp),%rax
  movq   %rax,%xmm0
  call   <sin@plt>
  movq   %xmm0,%rax
  mov    %rax,-0x30(%rbp)
  movsd  D41(%rip),%xmm0
  movsd  %xmm0,-0x68(%rbp)
  movq   $0x0,-0x88(%rbp)
  jmp    L319
L114:
  mov    -0x88(%rbp),%rax
  lea    0x0(,%rax,8),%rdx
  mov    -0xb0(%rbp),%rax
  add    %rdx,%rax
  movsd  D41(%rip),%xmm0
  movsd  %xmm0,(%rax)
  addq   $0x1,-0x88(%rbp)
L319:
  cmpq   $0x3,-0x88(%rbp)
  jle    L114
  movq   $0x0,-0x58(%rbp)
  mov    -0xa0(%rbp),%rax
  sub    $0x1,%rax
  mov    %rax,-0x50(%rbp)
  mov    -0xd0(%rbp),%rax
  movsd  (%rax),%xmm1
  movsd  -0xc0(%rbp),%xmm0
  comisd %xmm1,%xmm0
  jb     L32
  mov    -0x98(%rbp),%rax
  shl    $0x3,%rax
  lea    -0x8(%rax),%rdx
  mov    -0xd0(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm0
  comisd -0xc0(%rbp),%xmm0
  jb     L32
  mov    -0xc8(%rbp),%rax
  movsd  (%rax),%xmm1
  mov    -0xa0(%rbp),%rax
  shl    $0x3,%rax
  lea    -0x8(%rax),%rdx
  mov    -0xc8(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm0
  comisd %xmm1,%xmm0
  jbe    L176
  mov    -0xc8(%rbp),%rax
  movsd  (%rax),%xmm0
  comisd -0xb8(%rbp),%xmm0
  jb     L327
  movq   $0x0,-0x58(%rbp)
  movq   $0x1,-0x50(%rbp)
  jmp    L32
L327:
  mov    -0xa0(%rbp),%rax
  sub    $0x2,%rax
  mov    %rax,-0x58(%rbp)
  mov    -0xa0(%rbp),%rax
  sub    $0x1,%rax
  mov    %rax,-0x50(%rbp)
  jmp    L32
L176:
  mov    -0xc8(%rbp),%rax
  movsd  (%rax),%xmm1
  movsd  -0xb8(%rbp),%xmm0
  comisd %xmm1,%xmm0
  jb     L236
  movq   $0x0,-0x58(%rbp)
  movq   $0x1,-0x50(%rbp)
  jmp    L32
L236:
  mov    -0xa0(%rbp),%rax
  sub    $0x2,%rax
  mov    %rax,-0x58(%rbp)
  mov    -0xa0(%rbp),%rax
  sub    $0x1,%rax
  mov    %rax,-0x50(%rbp)
L32:
  mov    -0x98(%rbp),%rax
  shl    $0x3,%rax
  mov    %rax,%rcx
  mov    $0x2f,%edx
  lea    D0(%rip),%rax
  mov    %rax,%rsi
  lea    D23(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <Malloc@plt>
  cltq
  mov    %rax,-0x28(%rbp)
  movq   $0x0,-0x78(%rbp)
  jmp    L7
L142:
  mov    -0x78(%rbp),%rax
  lea    0x0(,%rax,8),%rdx
  mov    -0xd0(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rax
  movq   %rax,%xmm0
  call   <cos@plt>
  movq   %xmm0,%rax
  movq   %rax,%xmm2
  mulsd  -0x38(%rbp),%xmm2
  movsd  %xmm2,-0xd8(%rbp)
  mov    -0x78(%rbp),%rax
  lea    0x0(,%rax,8),%rdx
  mov    -0xd0(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rax
  movq   %rax,%xmm0
  call   <sin@plt>
  movq   %xmm0,%rax
  movq   %rax,%xmm0
  mulsd  -0x30(%rbp),%xmm0
  mov    -0x78(%rbp),%rax
  lea    0x0(,%rax,8),%rdx
  mov    -0x28(%rbp),%rax
  add    %rdx,%rax
  addsd  -0xd8(%rbp),%xmm0
  movsd  %xmm0,(%rax)
  addq   $0x1,-0x78(%rbp)
L7:
  mov    -0x78(%rbp),%rax
  cmp    -0x98(%rbp),%rax
  jl     L142
  mov    -0x58(%rbp),%rax
  mov    %rax,-0x70(%rbp)
  jmp    L276
L239:
  mov    -0x70(%rbp),%rax
  lea    0x0(,%rax,8),%rdx
  mov    -0xc8(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rax
  movq   %rax,%xmm0
  call   <cos@plt>
  movsd  -0x48(%rbp),%xmm1
  mulsd  %xmm1,%xmm0
  movsd  %xmm0,-0x20(%rbp)
  mov    -0x70(%rbp),%rax
  lea    0x0(,%rax,8),%rdx
  mov    -0xc8(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rax
  movq   %rax,%xmm0
  call   <sin@plt>
  movsd  -0x40(%rbp),%xmm1
  mulsd  %xmm1,%xmm0
  movsd  %xmm0,-0x18(%rbp)
  cmpq   $0x1,-0x70(%rbp)
  jle    L214
  mov    -0xa0(%rbp),%rax
  sub    $0x2,%rax
  cmp    %rax,-0x70(%rbp)
  jge    L214
  mov    $0x1,%eax
  jmp    L246
L214:
  mov    $0x0,%eax
L246:
  cltq
  mov    %rax,-0x10(%rbp)
  movq   $0x0,-0x78(%rbp)
  jmp    L17
L227:
  cmpq   $0x0,-0x10(%rbp)
  je     L82
  cmpq   $0x1,-0x78(%rbp)
  jle    L82
  mov    -0x98(%rbp),%rax
  sub    $0x2,%rax
  cmp    %rax,-0x78(%rbp)
  jl     L317
L82:
  mov    -0x70(%rbp),%rax
  imul   -0x98(%rbp),%rax
  mov    %rax,%rdx
  mov    -0x78(%rbp),%rax
  add    %rdx,%rax
  mov    %rax,-0x8(%rbp)
  mov    -0x78(%rbp),%rax
  lea    0x0(,%rax,8),%rdx
  mov    -0x28(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm0
  mulsd  -0x20(%rbp),%xmm0
  addsd  -0x18(%rbp),%xmm0
  movq   %xmm0,%rax
  movq   %rax,%xmm0
  call   <acos@plt>
  movq   %xmm0,%rax
  mov    %rax,-0x60(%rbp)
  movsd  -0x68(%rbp),%xmm0
  comisd -0x60(%rbp),%xmm0
  jbe    L172
  movq   $0x0,-0x88(%rbp)
  jmp    L301
L257:
  mov    -0x88(%rbp),%rax
  lea    0x0(,%rax,8),%rdx
  mov    -0xb0(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm0
  comisd -0x60(%rbp),%xmm0
  jbe    L78
  movq   $0x3,-0x80(%rbp)
  jmp    L221
L169:
  mov    -0x80(%rbp),%rax
  shl    $0x2,%rax
  lea    -0x4(%rax),%rdx
  mov    -0xa8(%rbp),%rax
  add    %rdx,%rax
  mov    -0x80(%rbp),%rdx
  lea    0x0(,%rdx,4),%rcx
  mov    -0xa8(%rbp),%rdx
  add    %rcx,%rdx
  mov    (%rax),%eax
  mov    %eax,(%rdx)
  mov    -0x80(%rbp),%rax
  shl    $0x3,%rax
  lea    -0x8(%rax),%rdx
  mov    -0xb0(%rbp),%rax
  add    %rax,%rdx
  mov    -0x80(%rbp),%rax
  lea    0x0(,%rax,8),%rcx
  mov    -0xb0(%rbp),%rax
  add    %rcx,%rax
  movsd  (%rdx),%xmm0
  movsd  %xmm0,(%rax)
  subq   $0x1,-0x80(%rbp)
L221:
  mov    -0x80(%rbp),%rax
  cmp    -0x88(%rbp),%rax
  jg     L169
  movl   $0xffffffff,-0x8c(%rbp)
  mov    -0x88(%rbp),%rax
  lea    0x0(,%rax,4),%rdx
  mov    -0xa8(%rbp),%rax
  add    %rdx,%rax
  mov    -0x8(%rbp),%rdx
  mov    %edx,(%rax)
  mov    -0x88(%rbp),%rax
  lea    0x0(,%rax,8),%rdx
  mov    -0xb0(%rbp),%rax
  add    %rdx,%rax
  movsd  -0x60(%rbp),%xmm0
  movsd  %xmm0,(%rax)
  mov    -0xb0(%rbp),%rax
  movsd  0x18(%rax),%xmm0
  movsd  %xmm0,-0x68(%rbp)
  jmp    L172
L78:
  addq   $0x1,-0x88(%rbp)
L301:
  cmpq   $0x3,-0x88(%rbp)
  jle    L257
  jmp    L172
L317:
  nop
L172:
  addq   $0x1,-0x78(%rbp)
L17:
  mov    -0x78(%rbp),%rax
  cmp    -0x98(%rbp),%rax
  jl     L227
  addq   $0x1,-0x70(%rbp)
L276:
  mov    -0x70(%rbp),%rax
  cmp    -0x50(%rbp),%rax
  jle    L239
  mov    -0x28(%rbp),%rax
  mov    %rax,%rcx
  mov    $0x59,%edx
  lea    D0(%rip),%rax
  mov    %rax,%rsi
  lea    D23(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <Free@plt>
  movq   $0x0,-0x88(%rbp)
  jmp    L184
L288:
  mov    -0x88(%rbp),%rax
  lea    0x0(,%rax,8),%rdx
  mov    -0xb0(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm1
  movsd  D49(%rip),%xmm0
  addsd  %xmm0,%xmm1
  mov    -0x88(%rbp),%rax
  lea    0x0(,%rax,8),%rdx
  mov    -0xb0(%rbp),%rax
  add    %rdx,%rax
  movsd  D2(%rip),%xmm0
  divsd  %xmm1,%xmm0
  movsd  %xmm0,(%rax)
  addq   $0x1,-0x88(%rbp)
L184:
  cmpq   $0x3,-0x88(%rbp)
  jle    L288
  pxor   %xmm0,%xmm0
  movsd  %xmm0,-0x60(%rbp)
  movq   $0x0,-0x88(%rbp)
  jmp    L118
L244:
  mov    -0x88(%rbp),%rax
  lea    0x0(,%rax,8),%rdx
  mov    -0xb0(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm0
  movsd  -0x60(%rbp),%xmm1
  addsd  %xmm1,%xmm0
  movsd  %xmm0,-0x60(%rbp)
  addq   $0x1,-0x88(%rbp)
L118:
  cmpq   $0x3,-0x88(%rbp)
  jle    L244
  movq   $0x0,-0x88(%rbp)
  jmp    L252
L207:
  mov    -0x88(%rbp),%rax
  lea    0x0(,%rax,8),%rdx
  mov    -0xb0(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm0
  mov    -0x88(%rbp),%rax
  lea    0x0(,%rax,8),%rdx
  mov    -0xb0(%rbp),%rax
  add    %rdx,%rax
  divsd  -0x60(%rbp),%xmm0
  movsd  %xmm0,(%rax)
  addq   $0x1,-0x88(%rbp)
L252:
  cmpq   $0x3,-0x88(%rbp)
  jle    L207
  mov    -0x8c(%rbp),%eax
  leave
  ret
```

tool_calls: name: read_data
arguments: data_tag: D41
type_infered: byte[8]
name: read_data
arguments: data_tag: D0
type_infered: string
name: read_data
arguments: data_tag: D23
type_infered: string
name: read_data
arguments: data_tag: D49
type_infered: byte[8]
name: read_data
arguments: data_tag: D2
type_infered: f64

tool: {"D41": [0x40,0x8c,0xb5,0x78,0x1d,0xaf,0x15,0x44]}

tool: D0: /scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/AZed/cdo/refs/heads/master/src/remap_search_reg2d.c

tool: D23: grid_search_reg2d_nn

tool: {"D49": [0x9b,0x2b,0xa1,0x86,0x9b,0x84,0x06,0x3d]}

tool: D2: 1

assistant: ```c
int grid_search_reg2d_nn(long nx, long ny, int *restrict nbr_add, double *restrict nbr_dist, double plat, double plon, const double *restrict src_center_lat, const double *restrict src_center_lon) {
  int search_result = 0;
  long n, srch_add;
  long i;
  long ii, jj;
  long jjskip;
  double coslat, sinlat;
  double dist_min, distance;
  double *sincoslon;
  double coslat_dst = cos(plat);
  double sinlat_dst = sin(plat);
  double coslon_dst = cos(plon);
  double sinlon_dst = sin(plon);
  dist_min = 1.e+20;
  for (n = 0; n < 4; ++n)
    nbr_dist[n] = 1.e+20;
  long jjf = 0, jjl = ny - 1;
  if (plon >= src_center_lon[0] && plon <= src_center_lon[nx - 1]) {
    if (src_center_lat[0] < src_center_lat[ny - 1]) {
      if (plat <= src_center_lat[0]) {
        jjf = 0;
        jjl = 1;
      } else {
        jjf = ny - 2;
        jjl = ny - 1;
      }
    } else {
      if (plat >= src_center_lat[0]) {
        jjf = 0;
        jjl = 1;
      } else {
        jjf = ny - 2;
        jjl = ny - 1;
      }
    }
  }
  sincoslon = (double *)Malloc(__func__, "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/AZed/cdo/refs/heads/master/src/remap_search_reg2d.c", 47, (nx * sizeof(double)));
  for (ii = 0; ii < nx; ++ii)
    sincoslon[ii] = coslon_dst * cos(src_center_lon[ii]) + sinlon_dst * sin(src_center_lon[ii]);
  for (jj = jjf; jj <= jjl; ++jj) {
    coslat = coslat_dst * cos(src_center_lat[jj]);
    sinlat = sinlat_dst * sin(src_center_lat[jj]);
    jjskip = jj > 1 && jj < (ny - 2);
    for (ii = 0; ii < nx; ++ii) {
      if (jjskip && ii > 1 && ii < (nx - 2))
        continue;
      srch_add = jj * nx + ii;
      distance = acos(coslat * sincoslon[ii] + sinlat);
      if (distance < dist_min) {
        for (n = 0; n < 4; ++n) {
          if (distance < nbr_dist[n]) {
            for (i = 3; i > n; --i) {
              nbr_add[i] = nbr_add[i - 1];
              nbr_dist[i] = nbr_dist[i - 1];
            }
            search_result = -1;
            nbr_add[n] = srch_add;
            nbr_dist[n] = distance;
            dist_min = nbr_dist[3];
            break;
          }
        }
      }
    }
  }
  Free(__func__, "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/AZed/cdo/refs/heads/master/src/remap_search_reg2d.c", 89, (sincoslon));
  for (n = 0; n < 4; ++n)
    nbr_dist[n] = 1.0 / (nbr_dist[n] + 1.e-14);
  distance = 0.0;
  for (n = 0; n < 4; ++n)
    distance += nbr_dist[n];
  for (n = 0; n < 4; ++n)
    nbr_dist[n] /= distance;
  return (search_result);
}
```