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

```asm
<grid_search_reg2d_nn>:
  endbr64
  push   %r15
  mov    %rsi,%r15
  push   %r14
  push   %r13
  mov    %r9,%r13
  push   %r12
  mov    %rdi,%r12
  push   %rbp
  mov    %rcx,%rbp
  push   %rbx
  sub    $0xd8,%rsp
  lea    0xc8(%rsp),%rbx
  lea    0xc0(%rsp),%r14
  mov    %rdx,0x48(%rsp)
  mov    %rbx,%rdi
  movsd  %xmm0,0x18(%rsp)
  mov    %r14,%rsi
  movapd %xmm1,%xmm0
  movsd  %xmm1,0x20(%rsp)
  mov    %r8,0x40(%rsp)
  mov    %rbx,0x38(%rsp)
  mov    %r14,0x30(%rsp)
  call   <sincos@plt>
  movsd  0x18(%rsp),%xmm0
  mov    %r14,%rsi
  mov    %rbx,%rdi
  movsd  0xc0(%rsp),%xmm3
  lea    0x0(,%r12,8),%rbx
  movsd  %xmm3,(%rsp)
  movsd  0xc8(%rsp),%xmm3
  movsd  %xmm3,0x8(%rsp)
  call   <sincos@plt>
  lea    0x8(%rbp),%rsi
  movsd  0xc0(%rsp),%xmm3
  movsd  0x20(%rsp),%xmm1
  mov    %rsi,0x98(%rsp)
  comisd 0x0(%r13),%xmm1
  lea    0x10(%rbp),%rsi
  movapd D62(%rip),%xmm0
  mov    %rsi,0xa0(%rsp)
  lea    0x18(%rbp),%rsi
  movsd  %xmm3,0x50(%rsp)
  movsd  0xc8(%rsp),%xmm3
  mov    %rsi,0xa8(%rsp)
  lea    -0x1(%r15),%rsi
  mov    %rsi,0x10(%rsp)
  movsd  %xmm3,0x58(%rsp)
  movups %xmm0,0x0(%rbp)
  movups %xmm0,0x10(%rbp)
  jb     L135
  movsd  -0x8(%r13,%rbx,1),%xmm0
  comisd %xmm1,%xmm0
  jae    L391
L135:
  movq   $0x0,0x18(%rsp)
L225:
  lea    D36(%rip),%rax
  mov    %rbx,%rcx
  mov    $0x2f,%edx
  mov    %rax,0xb8(%rsp)
  mov    %rax,%rsi
  lea    D23(%rip),%rax
  mov    %rax,0xb0(%rsp)
  mov    %rax,%rdi
  xor    %eax,%eax
  call   <Malloc@plt>
  cltq
  mov    %rax,0x20(%rsp)
  test   %r12,%r12
  jle    L183
L160:
  mov    0x20(%rsp),%rax
  mov    0x38(%rsp),%r14
  mov    %r12,0x28(%rsp)
  mov    %rbp,0x60(%rsp)
  sub    %rax,%r13
  add    %rax,%rbx
  mov    %rax,%rbp
  mov    %r13,%r12
  mov    0x30(%rsp),%r13
  nopl   (%rax)
L359:
  movsd  (%r12,%rbp,1),%xmm0
  mov    %r13,%rsi
  mov    %r14,%rdi
  add    $0x8,%rbp
  call   <sincos@plt>
  movsd  (%rsp),%xmm0
  movsd  0x8(%rsp),%xmm1
  mulsd  0xc0(%rsp),%xmm0
  mulsd  0xc8(%rsp),%xmm1
  addsd  %xmm1,%xmm0
  movsd  %xmm0,-0x8(%rbp)
  cmp    %rbx,%rbp
  jne    L359
  mov    0x28(%rsp),%r12
  mov    0x60(%rsp),%rbp
L183:
  mov    0x10(%rsp),%rsi
  cmp    %rsi,0x18(%rsp)
  jg     L347
L401:
  mov    0x18(%rsp),%rax
  movsd  D62(%rip),%xmm2
  movl   $0x0,0x70(%rsp)
  imul   %r12,%rax
  mov    %rax,0x28(%rsp)
  mov    0x10(%rsp),%rax
  movsd  %xmm2,0x10(%rsp)
  add    $0x1,%rax
  mov    %rax,0x60(%rsp)
  lea    -0x2(%r12),%rax
  mov    %rax,0x68(%rsp)
  lea    -0x2(%r15),%rax
  mov    %rax,0x78(%rsp)
  nop
L200:
  mov    0x40(%rsp),%rax
  mov    0x18(%rsp),%rbx
  xor    %r14d,%r14d
  mov    0x30(%rsp),%rsi
  mov    0x38(%rsp),%rdi
  movsd  (%rax,%rbx,8),%xmm0
  call   <sincos@plt>
  movsd  0x50(%rsp),%xmm3
  mulsd  0xc0(%rsp),%xmm3
  movsd  %xmm3,(%rsp)
  movsd  0x58(%rsp),%xmm3
  mulsd  0xc8(%rsp),%xmm3
  movsd  %xmm3,0x8(%rsp)
  cmp    $0x1,%rbx
  jle    L196
  cmp    %rbx,0x78(%rsp)
  setg   %r14b
L196:
  test   %r12,%r12
  jle    L133
  mov    0x68(%rsp),%rax
  test   %rax,%rax
  jle    L235
  cmp    %rax,%r12
  mov    %rax,%r13
  mov    0x20(%rsp),%r15
  cmovle %r12,%r13
  xor    %ebx,%ebx
  jmp    L7
  nopl   0x0(%rax,%rax,1)
L131:
  add    $0x1,%rbx
  add    $0x8,%r15
  cmp    %r13,%rbx
  jge    L104
L7:
  cmp    $0x1,%rbx
  jle    L9
  test   %r14b,%r14b
  jne    L131
L9:
  movsd  (%rsp),%xmm0
  mulsd  (%r15),%xmm0
  addsd  0x8(%rsp),%xmm0
  call   <acos@plt>
  movsd  0x10(%rsp),%xmm7
  comisd %xmm0,%xmm7
  jbe    L131
  movsd  0x0(%rbp),%xmm1
  movsd  0x10(%rbp),%xmm2
  comisd %xmm0,%xmm1
  ja     L156
  movsd  0x8(%rbp),%xmm1
  comisd %xmm0,%xmm1
  ja     L314
  comisd %xmm0,%xmm2
  ja     L232
  movsd  0x18(%rbp),%xmm1
  comisd %xmm0,%xmm1
  jbe    L131
  mov    0x48(%rsp),%rax
  mov    0xa8(%rsp),%r8
  lea    0xc(%rax),%r9
L358:
  mov    0x28(%rsp),%eax
  movsd  %xmm0,(%r8)
  movsd  0x18(%rbp),%xmm3
  add    $0x8,%r15
  movl   $0xffffffff,0x70(%rsp)
  add    %ebx,%eax
  add    $0x1,%rbx
  movsd  %xmm3,0x10(%rsp)
  mov    %eax,(%r9)
  cmp    %r13,%rbx
  jl     L7
L104:
  cmp    %rbx,%r12
  jle    L133
L132:
  mov    0x20(%rsp),%rax
  lea    (%rax,%rbx,8),%r13
  jmp    L326
  nopl   0x0(%rax)
L223:
  add    $0x1,%rbx
  add    $0x8,%r13
  cmp    %rbx,%r12
  jle    L133
L326:
  movsd  (%rsp),%xmm0
  mulsd  0x0(%r13),%xmm0
  addsd  0x8(%rsp),%xmm0
  call   <acos@plt>
  movsd  0x10(%rsp),%xmm5
  comisd %xmm0,%xmm5
  jbe    L223
  movsd  0x0(%rbp),%xmm1
  movsd  0x10(%rbp),%xmm2
  comisd %xmm0,%xmm1
  ja     L398
  movsd  0x8(%rbp),%xmm1
  comisd %xmm0,%xmm1
  ja     L170
  comisd %xmm0,%xmm2
  ja     L208
  movsd  0x18(%rbp),%xmm1
  comisd %xmm0,%xmm1
  jbe    L223
  mov    0x48(%rsp),%rax
  mov    0xa8(%rsp),%r14
  lea    0xc(%rax),%r15
L396:
  mov    0x28(%rsp),%eax
  movsd  %xmm0,(%r14)
  movsd  0x18(%rbp),%xmm2
  add    $0x8,%r13
  movl   $0xffffffff,0x70(%rsp)
  add    %ebx,%eax
  add    $0x1,%rbx
  movsd  %xmm2,0x10(%rsp)
  mov    %eax,(%r15)
  cmp    %rbx,%r12
  jg     L326
  cs nopw 0x0(%rax,%rax,1)
L133:
  addq   $0x1,0x18(%rsp)
  mov    0x18(%rsp),%rax
  add    %r12,0x28(%rsp)
  cmp    0x60(%rsp),%rax
  jne    L200
L122:
  mov    0x20(%rsp),%rcx
  mov    0xb8(%rsp),%rsi
  mov    $0x59,%edx
  xor    %eax,%eax
  mov    0xb0(%rsp),%rdi
  call   <Free@plt>
  movupd 0x0(%rbp),%xmm1
  mov    0x70(%rsp),%eax
  movapd D0(%rip),%xmm3
  movapd D51(%rip),%xmm0
  addpd  %xmm3,%xmm1
  movapd %xmm0,%xmm2
  divpd  %xmm1,%xmm2
  movupd 0x10(%rbp),%xmm1
  addpd  %xmm3,%xmm1
  divpd  %xmm1,%xmm0
  pxor   %xmm1,%xmm1
  addsd  %xmm2,%xmm1
  movapd %xmm2,%xmm3
  unpckhpd %xmm3,%xmm3
  addsd  %xmm3,%xmm1
  movapd %xmm0,%xmm3
  movapd %xmm0,%xmm6
  addsd  %xmm1,%xmm3
  unpckhpd %xmm6,%xmm6
  movapd %xmm6,%xmm1
  addsd  %xmm3,%xmm1
  unpcklpd %xmm1,%xmm1
  divpd  %xmm1,%xmm2
  divpd  %xmm1,%xmm0
  movups %xmm2,0x0(%rbp)
  movups %xmm0,0x10(%rbp)
  add    $0xd8,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L235:
  xor    %ebx,%ebx
  jmp    L132
  nopw   0x0(%rax,%rax,1)
L398:
  mov    0x48(%rsp),%r15
  mov    %rbp,%r14
  xor    %edi,%edi
  mov    %r15,%rax
L255:
  lea    0x1(%rdi),%r8
  mov    $0x3,%ecx
  movsd  %xmm0,0x80(%rsp)
  sub    %rdi,%rcx
  lea    0x0(,%r8,4),%rdi
  mov    %r8,0x70(%rsp)
  lea    0x0(,%rcx,4),%rdx
  lea    -0x4(%rax,%rdi,1),%rsi
  add    %rax,%rdi
  mov    %rcx,0x10(%rsp)
  call   <memmove@plt>
  mov    0x70(%rsp),%r8
  mov    0x10(%rsp),%rcx
  lea    0x0(,%r8,8),%rdi
  lea    0x0(,%rcx,8),%rdx
  lea    -0x8(%rbp,%rdi,1),%rsi
  add    %rbp,%rdi
  call   <memmove@plt>
  movsd  0x80(%rsp),%xmm0
  jmp    L396
  xchg   %ax,%ax
L156:
  mov    0x48(%rsp),%r9
  mov    %rbp,%r8
  xor    %ecx,%ecx
  mov    %r9,%rax
L185:
  mov    $0x3,%r10d
  mov    %r9,0x90(%rsp)
  sub    %rcx,%r10
  add    $0x1,%rcx
  mov    %r8,0x80(%rsp)
  lea    0x0(,%rcx,4),%rdi
  lea    0x0(,%r10,4),%rdx
  mov    %rcx,0x70(%rsp)
  lea    -0x4(%rax,%rdi,1),%rsi
  add    %rax,%rdi
  mov    %r10,0x10(%rsp)
  movsd  %xmm0,0x88(%rsp)
  call   <memmove@plt>
  mov    0x70(%rsp),%rcx
  mov    0x10(%rsp),%r10
  shl    $0x3,%rcx
  lea    0x0(,%r10,8),%rdx
  lea    -0x8(%rbp,%rcx,1),%rsi
  lea    0x0(%rbp,%rcx,1),%rdi
  call   <memmove@plt>
  mov    0x80(%rsp),%r8
  movsd  0x88(%rsp),%xmm0
  mov    0x90(%rsp),%r9
  jmp    L358
L170:
  mov    0x48(%rsp),%rax
  mov    0x98(%rsp),%r14
  mov    $0x1,%edi
  lea    0x4(%rax),%r15
  jmp    L255
L314:
  mov    0x48(%rsp),%rax
  mov    0x98(%rsp),%r8
  mov    $0x1,%ecx
  lea    0x4(%rax),%r9
  jmp    L185
L208:
  mov    0x48(%rsp),%rax
  mov    0xa0(%rsp),%r14
  mov    $0x2,%edi
  lea    0x8(%rax),%r15
  jmp    L255
L232:
  mov    0x48(%rsp),%rax
  mov    0xa0(%rsp),%r8
  mov    $0x2,%ecx
  lea    0x8(%rax),%r9
  jmp    L185
L391:
  mov    0x40(%rsp),%rax
  movsd  (%rax),%xmm0
  movsd  -0x8(%rax,%r15,8),%xmm1
  comisd %xmm0,%xmm1
  jbe    L203
  comisd 0x18(%rsp),%xmm0
  jb     L22
L256:
  lea    D36(%rip),%rax
  mov    %rbx,%rcx
  mov    $0x2f,%edx
  mov    %rax,0xb8(%rsp)
  mov    %rax,%rsi
  lea    D23(%rip),%rax
  mov    %rax,0xb0(%rsp)
  mov    %rax,%rdi
  xor    %eax,%eax
  call   <Malloc@plt>
  movq   $0x1,0x10(%rsp)
  movq   $0x0,0x18(%rsp)
  cltq
  mov    %rax,0x20(%rsp)
  test   %r12,%r12
  jg     L160
  jmp    L401
L203:
  movsd  0x18(%rsp),%xmm2
  comisd %xmm0,%xmm2
  jae    L256
L22:
  lea    -0x2(%r15),%rax
  mov    %rax,0x18(%rsp)
  jmp    L225
L347:
  movl   $0x0,0x70(%rsp)
  jmp    L122
```

tool_calls: name: unpack_data
arguments: data_tag: D62
type_guessed: byte[16]
name: unpack_data
arguments: data_tag: D36
type_guessed: string
name: unpack_data
arguments: data_tag: D23
type_guessed: string
name: unpack_data
arguments: data_tag: D0
type_guessed: byte[16]
name: unpack_data
arguments: data_tag: D51
type_guessed: f64[2]

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

tool: D36: /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: {"D0": [0x9b,0x2b,0xa1,0x86,0x9b,0x84,0x06,0x3d,0x9b,0x2b,0xa1,0x86,0x9b,0x84,0x06,0x3d]}

tool: {"D51": [1.0,1.0]}

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