user: Demonstrate the C code that generates the assembly output below:

```asm
<grid_search_reg2d_nn>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  mov    %rsi,%r13
  push   %r12
  mov    %r9,%r12
  push   %rbp
  mov    %rdi,%rbp
  push   %rbx
  mov    %rcx,%rbx
  sub    $0xb8,%rsp
  lea    0xa0(%rsp),%r14
  lea    0xa8(%rsp),%r15
  mov    %rsi,0x50(%rsp)
  movsd  %xmm0,0x18(%rsp)
  mov    %r14,%rsi
  movapd %xmm1,%xmm0
  mov    %r15,%rdi
  movsd  %xmm1,0x28(%rsp)
  mov    %rdx,0x60(%rsp)
  mov    %rcx,0x70(%rsp)
  mov    %r8,0x30(%rsp)
  mov    %r14,0x20(%rsp)
  call   <sincos@plt>
  movsd  0x18(%rsp),%xmm0
  mov    %r14,%rsi
  mov    %r15,%rdi
  movsd  0xa0(%rsp),%xmm2
  movsd  %xmm2,(%rsp)
  movsd  0xa8(%rsp),%xmm2
  movsd  %xmm2,0x8(%rsp)
  call   <sincos@plt>
  mov    D7(%rip),%rsi
  movsd  0xa0(%rsp),%xmm2
  movsd  0x28(%rsp),%xmm1
  comisd (%r12),%xmm1
  movsd  %xmm2,0x38(%rsp)
  movsd  0xa8(%rsp),%xmm2
  mov    %rsi,(%rbx)
  mov    %rsi,0x8(%rbx)
  mov    %rsi,0x10(%rbx)
  mov    %rsi,0x18(%rbx)
  lea    -0x1(%r13),%rsi
  lea    0x0(,%rbp,8),%rbx
  mov    %rsi,0x10(%rsp)
  movsd  %xmm2,0x40(%rsp)
  jb     L190
  movsd  -0x8(%r12,%rbx,1),%xmm0
  comisd %xmm1,%xmm0
  jae    L107
L190:
  xor    %r13d,%r13d
L228:
  lea    D11(%rip),%rax
  mov    %rbx,%rcx
  mov    $0x2f,%edx
  mov    %rax,0x90(%rsp)
  mov    %rax,%rsi
  lea    D30(%rip),%rax
  mov    %rax,0x98(%rsp)
  mov    %rax,%rdi
  xor    %eax,%eax
  call   <Malloc@plt>
  cltq
  mov    %rax,0x28(%rsp)
  test   %rbp,%rbp
  jle    L273
L141:
  mov    0x28(%rsp),%rax
  mov    %rbp,0x18(%rsp)
  sub    %rax,%r12
  lea    (%rbx,%rax,1),%r14
  mov    %rax,%rbx
  mov    %r12,%rbp
  mov    0x20(%rsp),%r12
  nopl   (%rax)
L175:
  movsd  0x0(%rbp,%rbx,1),%xmm0
  mov    %r12,%rsi
  mov    %r15,%rdi
  add    $0x8,%rbx
  call   <sincos@plt>
  movsd  (%rsp),%xmm0
  movsd  0x8(%rsp),%xmm1
  mulsd  0xa0(%rsp),%xmm0
  mulsd  0xa8(%rsp),%xmm1
  addsd  %xmm1,%xmm0
  movsd  %xmm0,-0x8(%rbx)
  cmp    %r14,%rbx
  jne    L175
  mov    0x18(%rsp),%rbp
L273:
  cmp    0x10(%rsp),%r13
  jg     L83
L211:
  mov    %r13,%rax
  movl   $0x0,0x68(%rsp)
  imul   %rbp,%rax
  mov    %rax,0x18(%rsp)
  mov    0x10(%rsp),%rax
  add    $0x1,%rax
  mov    %rax,0x48(%rsp)
  mov    D7(%rip),%rax
  mov    %rax,0x10(%rsp)
  mov    0x50(%rsp),%rax
  mov    %r15,0x50(%rsp)
  mov    0x70(%rsp),%r15
  sub    $0x2,%rax
  mov    %rax,0x58(%rsp)
  xchg   %ax,%ax
L209:
  mov    0x30(%rsp),%rax
  mov    0x20(%rsp),%rsi
  xor    %r12d,%r12d
  mov    0x50(%rsp),%rdi
  movsd  (%rax,%r13,8),%xmm0
  call   <sincos@plt>
  movsd  0x38(%rsp),%xmm6
  movsd  0x40(%rsp),%xmm7
  mulsd  0xa0(%rsp),%xmm6
  mulsd  0xa8(%rsp),%xmm7
  movsd  %xmm6,(%rsp)
  movsd  %xmm7,0x8(%rsp)
  cmp    $0x1,%r13
  jle    L168
  xor    %r12d,%r12d
  cmp    %r13,0x58(%rsp)
  setg   %r12b
L168:
  test   %rbp,%rbp
  jle    L21
  mov    0x28(%rsp),%r14
  and    $0x1,%r12d
  xor    %ebx,%ebx
  jmp    L268
  xchg   %ax,%ax
L49:
  add    $0x1,%rbx
  add    $0x8,%r14
  cmp    %rbx,%rbp
  je     L21
L268:
  cmp    $0x1,%rbx
  jle    L79
  test   %r12b,%r12b
  je     L79
  lea    -0x2(%rbp),%rax
  cmp    %rbx,%rax
  jg     L49
L79:
  movsd  (%rsp),%xmm0
  mulsd  (%r14),%xmm0
  addsd  0x8(%rsp),%xmm0
  call   <acos@plt>
  movsd  0x10(%rsp),%xmm5
  comisd %xmm0,%xmm5
  jbe    L49
  mov    %r15,%r8
  xor    %ecx,%ecx
  movsd  (%r8),%xmm1
  comisd %xmm0,%xmm1
  ja     L87
L128:
  add    $0x1,%rcx
  add    $0x8,%r8
  cmp    $0x4,%rcx
  je     L49
  movsd  (%r8),%xmm1
  comisd %xmm0,%xmm1
  jbe    L128
L87:
  cmp    $0x3,%rcx
  je     L93
  lea    0x1(%rcx),%r9
  mov    0x60(%rsp),%rax
  mov    $0x3,%r10d
  mov    %r8,0x80(%rsp)
  sub    %rcx,%r10
  mov    %rcx,0x78(%rsp)
  lea    0x0(,%r9,4),%rdi
  lea    0x0(,%r10,4),%rdx
  lea    -0x4(%rax,%rdi,1),%rsi
  add    %rax,%rdi
  movsd  %xmm0,0x88(%rsp)
  mov    %r9,0x68(%rsp)
  mov    %r10,0x10(%rsp)
  call   <memmove@plt>
  mov    0x68(%rsp),%r9
  mov    0x10(%rsp),%r10
  shl    $0x3,%r9
  lea    0x0(,%r10,8),%rdx
  lea    -0x8(%r15,%r9,1),%rsi
  lea    (%r15,%r9,1),%rdi
  call   <memmove@plt>
  mov    0x78(%rsp),%rcx
  mov    0x80(%rsp),%r8
  movsd  0x88(%rsp),%xmm0
L93:
  mov    0x18(%rsp),%eax
  mov    0x60(%rsp),%rsi
  add    $0x8,%r14
  movsd  %xmm0,(%r8)
  movsd  0x18(%r15),%xmm2
  movl   $0xffffffff,0x68(%rsp)
  add    %ebx,%eax
  add    $0x1,%rbx
  mov    %eax,(%rsi,%rcx,4)
  movsd  %xmm2,0x10(%rsp)
  cmp    %rbx,%rbp
  jne    L268
  nopw   0x0(%rax,%rax,1)
L21:
  add    %rbp,0x18(%rsp)
  add    $0x1,%r13
  cmp    0x48(%rsp),%r13
  jne    L209
L122:
  mov    0x28(%rsp),%rcx
  mov    0x90(%rsp),%rsi
  mov    $0x59,%edx
  xor    %eax,%eax
  mov    0x98(%rsp),%rdi
  call   <Free@plt>
  mov    0x70(%rsp),%rdx
  movsd  D53(%rip),%xmm3
  movsd  D74(%rip),%xmm2
  mov    %rdx,%rax
  lea    0x20(%rdx),%rcx
L225:
  movsd  (%rdx),%xmm1
  movapd %xmm2,%xmm0
  add    $0x8,%rdx
  addsd  %xmm3,%xmm1
  divsd  %xmm1,%xmm0
  movsd  %xmm0,-0x8(%rdx)
  cmp    %rcx,%rdx
  jne    L225
  mov    0x70(%rsp),%rdx
  pxor   %xmm1,%xmm1
  addsd  (%rdx),%xmm1
  addsd  0x8(%rdx),%xmm1
  addsd  0x10(%rdx),%xmm1
  addsd  0x18(%rdx),%xmm1
L146:
  movsd  (%rax),%xmm0
  add    $0x8,%rax
  divsd  %xmm1,%xmm0
  movsd  %xmm0,-0x8(%rax)
  cmp    %rax,%rcx
  jne    L146
  mov    0x68(%rsp),%eax
  add    $0xb8,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L107:
  mov    0x30(%rsp),%rax
  movsd  (%rax),%xmm0
  movsd  -0x8(%rax,%r13,8),%xmm1
  comisd %xmm0,%xmm1
  jbe    L37
  sub    $0x2,%r13
  comisd 0x18(%rsp),%xmm0
  jb     L228
L32:
  lea    D11(%rip),%rax
  mov    %rbx,%rcx
  mov    $0x2f,%edx
  xor    %r13d,%r13d
  mov    %rax,0x90(%rsp)
  mov    %rax,%rsi
  lea    D30(%rip),%rax
  mov    %rax,0x98(%rsp)
  mov    %rax,%rdi
  xor    %eax,%eax
  call   <Malloc@plt>
  movq   $0x1,0x10(%rsp)
  cltq
  mov    %rax,0x28(%rsp)
  test   %rbp,%rbp
  jg     L141
  jmp    L211
L37:
  movsd  0x18(%rsp),%xmm3
  comisd %xmm0,%xmm3
  jae    L32
  mov    0x50(%rsp),%rax
  lea    -0x2(%rax),%r13
  jmp    L228
L83:
  movl   $0x0,0x68(%rsp)
  jmp    L122
```

tool_calls: name: read_data
arguments: tag: D7
data_type: byte[8]
name: read_data
arguments: tag: D11
data_type: string
name: read_data
arguments: tag: D30
data_type: string
name: read_data
arguments: tag: D53
data_type: byte[8]
name: read_data
arguments: tag: D74
data_type: f64

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

tool: D11: /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: D30: grid_search_reg2d_nn

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

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