user: Please show me the C implementation that matches the assembly code listed below:

```asm
<sphx2s>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0xa8,%rsp
  mov    %rdi,%rbp
  mov    %esi,%ebx
  mov    %edx,0x5c(%rsp)
  mov    %ecx,%r14d
  mov    %r8d,0x8(%rsp)
  mov    %r9,%r12
  mov    0xe0(%rsp),%r15
  mov    0xe8(%rsp),%rax
  mov    %rax,0x48(%rsp)
  mov    0xf0(%rsp),%rax
  mov    %rax,0x50(%rsp)
  mov    %fs:0x28,%rax
  mov    %rax,0x98(%rsp)
  xor    %eax,%eax
  mov    %edx,%ecx
  mov    %esi,%r13d
  test   %edx,%edx
  jle    L189
L324:
  pxor   %xmm0,%xmm0
  ucomisd 0x20(%rbp),%xmm0
  jp     L291
  je     L529
L291:
  mov    0x8(%rsp),%edi
  mov    %edi,%eax
  imul   %ebx,%eax
  test   %ebx,%ebx
  jle    L399
  cltq
  lea    0x0(,%rax,8),%rsi
  movslq %r14d,%r10
  shl    $0x3,%r10
  movslq %edi,%r9
  shl    $0x3,%r9
  mov    0x48(%rsp),%r8
  mov    $0x0,%edi
L563:
  movsd  (%r12),%xmm0
  subsd  0x10(%rbp),%xmm0
  mov    %r8,%rax
  test   %ecx,%ecx
  jle    L629
  mov    $0x0,%edx
L242:
  movsd  %xmm0,(%rax)
  add    %rsi,%rax
  add    $0x1,%edx
  cmp    %edx,%ecx
  jne    L242
L629:
  add    $0x1,%edi
  add    %r10,%r12
  add    %r9,%r8
  cmp    %edi,%ebx
  jne    L563
L399:
  cmpl   $0x0,0x5c(%rsp)
  jle    L494
  movslq 0x8(%rsp),%rbx
  lea    0x0(,%rbx,8),%rcx
  mov    %rcx,0x30(%rsp)
  movslq %r14d,%r14
  lea    0x0(,%r14,8),%rax
  mov    %rax,0x60(%rsp)
  lea    -0x1(%r13),%eax
  add    $0x1,%rax
  imul   %rcx,%rax
  mov    %rax,0x68(%rsp)
  movl   $0x0,0x58(%rsp)
  jmp    L229
L189:
  mov    %esi,0x5c(%rsp)
  mov    $0x1,%ecx
  mov    $0x1,%r13d
  jmp    L324
L529:
  ucomisd 0x8(%rbp),%xmm0
  jp     L607
  jne    L607
  movsd  D354(%rip),%xmm0
  addsd  0x0(%rbp),%xmm0
  subsd  0x10(%rbp),%xmm0
  movsd  D10(%rip),%xmm1
  call   <fmod@plt>
  movapd %xmm0,%xmm3
  cmpl   $0x0,0x5c(%rsp)
  jle    L494
  movslq 0x8(%rsp),%rcx
  shl    $0x3,%rcx
  movslq %r14d,%rsi
  shl    $0x3,%rsi
  lea    -0x1(%r13),%r9d
  add    $0x1,%r9
  imul   %rcx,%r9
  mov    $0x0,%r8d
  mov    $0x0,%edi
  pxor   %xmm7,%xmm7
  movsd  D10(%rip),%xmm10
  movsd  D228(%rip),%xmm6
  movapd %xmm10,%xmm9
  movapd %xmm10,%xmm5
  mov    %r9,0x10(%rsp)
  mov    %ebx,0x8(%rsp)
  mov    0x48(%rsp),%r9
  mov    0x50(%rsp),%r10
  jmp    L366
L392:
  movsd  (%rax),%xmm0
  comisd %xmm7,%xmm0
  jbe    L228
  subsd  %xmm10,%xmm0
  movsd  %xmm0,(%rax)
L228:
  movsd  (%rax),%xmm0
  comisd %xmm1,%xmm0
  jbe    L478
  subsd  %xmm5,%xmm0
  movsd  %xmm0,(%rax)
L154:
  add    %rcx,%rax
  add    %rcx,%rbx
  add    $0x1,%edx
  add    %rsi,%r11
  cmp    %edx,%r13d
  je     L479
L202:
  movapd %xmm3,%xmm0
  addsd  (%r11),%xmm0
  movsd  %xmm0,(%rax)
  movsd  (%r15),%xmm0
  movsd  %xmm0,(%rbx)
  movsd  0x0(%rbp),%xmm0
  comisd %xmm2,%xmm0
  jb     L392
  movsd  (%rax),%xmm0
  comisd %xmm0,%xmm4
  jbe    L228
  addsd  %xmm8,%xmm0
  movsd  %xmm0,(%rax)
  jmp    L228
L478:
  comisd %xmm0,%xmm6
  jbe    L154
  addsd  %xmm9,%xmm0
  movsd  %xmm0,(%rax)
  jmp    L154
L479:
  mov    0x10(%rsp),%rax
  add    %rax,%r9
  add    %rax,%r10
  add    %edx,%edi
L382:
  add    $0x1,%r8d
  add    %rsi,%r15
  cmp    %r8d,0x5c(%rsp)
  je     L494
L366:
  mov    %edi,%eax
  cltd
  idivl  0x8(%rsp)
  imul   %r14d,%edx
  movslq %edx,%rdx
  lea    (%r12,%rdx,8),%r11
  test   %r13d,%r13d
  jle    L382
  mov    %r9,%rax
  mov    %r10,%rbx
  mov    $0x0,%edx
  pxor   %xmm2,%xmm2
  movapd %xmm2,%xmm4
  movsd  D10(%rip),%xmm8
  movapd %xmm8,%xmm1
  jmp    L202
L607:
  movsd  0x0(%rbp),%xmm0
  addsd  0x10(%rbp),%xmm0
  movsd  D10(%rip),%xmm1
  call   <fmod@plt>
  movapd %xmm0,%xmm2
  cmpl   $0x0,0x5c(%rsp)
  jle    L494
  movslq 0x8(%rsp),%rcx
  shl    $0x3,%rcx
  movslq %r14d,%rsi
  shl    $0x3,%rsi
  lea    -0x1(%r13),%r9d
  add    $0x1,%r9
  imul   %rcx,%r9
  mov    $0x0,%r8d
  mov    $0x0,%edi
  movq   D195(%rip),%xmm4
  pxor   %xmm3,%xmm3
  movapd %xmm3,%xmm8
  movsd  D228(%rip),%xmm7
  movsd  D10(%rip),%xmm11
  movapd %xmm11,%xmm6
  mov    %r9,0x10(%rsp)
  mov    %ebx,0x8(%rsp)
  mov    0x48(%rsp),%r9
  mov    0x50(%rsp),%r10
  jmp    L510
L244:
  movsd  (%rax),%xmm0
  comisd %xmm8,%xmm0
  jbe    L156
  subsd  %xmm10,%xmm0
  movsd  %xmm0,(%rax)
L156:
  movsd  (%rax),%xmm0
  comisd %xmm1,%xmm0
  jbe    L415
  subsd  %xmm6,%xmm0
  movsd  %xmm0,(%rax)
L416:
  add    %rcx,%rax
  add    %rcx,%rbx
  add    $0x1,%edx
  add    %rsi,%r11
  cmp    %edx,%r13d
  je     L120
L380:
  movapd %xmm2,%xmm0
  subsd  (%r11),%xmm0
  movsd  %xmm0,(%rax)
  movsd  (%r15),%xmm0
  xorpd  %xmm4,%xmm0
  movsd  %xmm0,(%rbx)
  movsd  0x0(%rbp),%xmm0
  comisd %xmm3,%xmm0
  jb     L244
  movsd  (%rax),%xmm0
  comisd %xmm0,%xmm5
  jbe    L156
  addsd  %xmm9,%xmm0
  movsd  %xmm0,(%rax)
  jmp    L156
L415:
  comisd %xmm0,%xmm7
  jbe    L416
  addsd  %xmm11,%xmm0
  movsd  %xmm0,(%rax)
  jmp    L416
L120:
  mov    0x10(%rsp),%rax
  add    %rax,%r9
  add    %rax,%r10
  add    %edx,%edi
L216:
  add    $0x1,%r8d
  add    %rsi,%r15
  cmp    %r8d,0x5c(%rsp)
  je     L494
L510:
  mov    %edi,%eax
  cltd
  idivl  0x8(%rsp)
  imul   %r14d,%edx
  movslq %edx,%rdx
  lea    (%r12,%rdx,8),%r11
  test   %r13d,%r13d
  jle    L216
  mov    %r9,%rax
  mov    %r10,%rbx
  mov    $0x0,%edx
  movsd  D10(%rip),%xmm10
  pxor   %xmm5,%xmm5
  movapd %xmm10,%xmm9
  movapd %xmm10,%xmm1
  jmp    L380
L426:
  movsd  D211(%rip),%xmm1
  subsd  %xmm3,%xmm1
  mulsd  0x20(%rsp),%xmm1
  movsd  %xmm1,0x8(%rsp)
  movsd  (%r15),%xmm0
  addsd  0x8(%rbp),%xmm0
  call   <cosd@plt>
  movsd  0x8(%rsp),%xmm1
  subsd  %xmm0,%xmm1
  movsd  %xmm1,0x8(%rsp)
  jmp    L155
L82:
  movsd  0x8(%rsp),%xmm1
  movsd  0x18(%rsp),%xmm0
  call   <atan2d@plt>
  jmp    L249
L603:
  movsd  0x10(%rsp),%xmm0
  xorpd  D195(%rip),%xmm0
  jmp    L249
L133:
  addsd  D10(%rip),%xmm0
  movsd  %xmm0,(%rbx)
  jmp    L459
L258:
  comisd D97(%rip),%xmm0
  jbe    L459
  subsd  D10(%rip),%xmm0
  movsd  %xmm0,(%rbx)
  jmp    L459
L209:
  movsd  D228(%rip),%xmm1
  comisd %xmm0,%xmm1
  jbe    L550
  addsd  D10(%rip),%xmm0
  movsd  %xmm0,(%rbx)
  jmp    L550
L508:
  movsd  D354(%rip),%xmm1
  subsd  %xmm0,%xmm1
  movsd  %xmm1,(%r12)
  jmp    L257
L444:
  movsd  0x38(%rsp),%xmm0
  mulsd  0x78(%rsp),%xmm0
  addsd  0x40(%rsp),%xmm0
  movapd %xmm0,%xmm1
  andpd  D109(%rip),%xmm1
  comisd D347(%rip),%xmm1
  jbe    L436
  pxor   %xmm1,%xmm1
  comisd %xmm0,%xmm1
  ja     L41
  movsd  0x8(%rsp),%xmm0
  mulsd  %xmm0,%xmm0
  movsd  0x18(%rsp),%xmm1
  mulsd  %xmm1,%xmm1
  addsd  %xmm1,%xmm0
  call   <sqrt@plt>
  mov    %eax,%edi
  call   <acosd@plt>
  andpd  D109(%rip),%xmm0
L68:
  movsd  %xmm0,(%r12)
L578:
  add    $0x1,%r14d
  mov    0x30(%rsp),%rax
  add    %rax,%rbx
  add    %rax,%r12
  cmp    %r14d,%r13d
  je     L89
L408:
  movsd  (%rbx),%xmm5
  movsd  %xmm5,0x10(%rsp)
  lea    0x78(%rsp),%rsi
  lea    0x88(%rsp),%rdi
  movapd %xmm5,%xmm0
  call   <sincosd@plt>
  movsd  0x78(%rsp),%xmm3
  movsd  0x20(%rsp),%xmm1
  mulsd  %xmm3,%xmm1
  movsd  0x28(%rsp),%xmm7
  subsd  %xmm1,%xmm7
  movsd  %xmm7,0x8(%rsp)
  movapd %xmm7,%xmm1
  andpd  D109(%rip),%xmm1
  movsd  D305(%rip),%xmm2
  comisd %xmm1,%xmm2
  ja     L426
L155:
  movsd  0x80(%rsp),%xmm0
  xorpd  D195(%rip),%xmm0
  movapd %xmm0,%xmm6
  mulsd  0x88(%rsp),%xmm6
  movsd  %xmm6,0x18(%rsp)
  movsd  0x8(%rsp),%xmm4
  ucomisd D97(%rip),%xmm4
  setp   %al
  mov    $0x1,%edx
  cmovne %edx,%eax
  test   %al,%al
  jne    L82
  ucomisd D97(%rip),%xmm6
  setp   %al
  cmovne %edx,%eax
  test   %al,%al
  jne    L82
  movsd  D42(%rip),%xmm0
  comisd 0x8(%rbp),%xmm0
  jbe    L603
  movsd  0x10(%rsp),%xmm0
  addsd  D354(%rip),%xmm0
L249:
  addsd  0x0(%rbp),%xmm0
  movsd  %xmm0,(%rbx)
  movsd  0x0(%rbp),%xmm1
  comisd D97(%rip),%xmm1
  jb     L258
  pxor   %xmm1,%xmm1
  comisd %xmm0,%xmm1
  ja     L133
L459:
  movsd  (%rbx),%xmm0
  comisd D10(%rip),%xmm0
  jbe    L209
  subsd  D10(%rip),%xmm0
  movsd  %xmm0,(%rbx)
L550:
  movsd  D354(%rip),%xmm1
  movsd  0x10(%rsp),%xmm0
  call   <fmod@plt>
  ucomisd D97(%rip),%xmm0
  jp     L444
  jne    L444
  movsd  0x8(%rbp),%xmm0
  mulsd  0x78(%rsp),%xmm0
  addsd  (%r15),%xmm0
  comisd D42(%rip),%xmm0
  ja     L508
  movsd  %xmm0,(%r12)
L257:
  movsd  (%r12),%xmm0
  movsd  D316(%rip),%xmm1
  comisd %xmm0,%xmm1
  jbe    L578
  movsd  D57(%rip),%xmm1
  subsd  %xmm0,%xmm1
  movsd  %xmm1,(%r12)
  jmp    L578
L41:
  movsd  0x8(%rsp),%xmm0
  mulsd  %xmm0,%xmm0
  movsd  0x18(%rsp),%xmm1
  mulsd  %xmm1,%xmm1
  addsd  %xmm1,%xmm0
  call   <sqrt@plt>
  mov    %eax,%edi
  call   <acosd@plt>
  orpd   D195(%rip),%xmm0
  jmp    L68
L436:
  call   <asind@plt>
  movsd  %xmm0,(%r12)
  jmp    L578
L89:
  mov    0x68(%rsp),%rcx
  add    %rcx,0x48(%rsp)
  add    %rcx,0x50(%rsp)
L139:
  addl   $0x1,0x58(%rsp)
  mov    0x58(%rsp),%eax
  add    0x60(%rsp),%r15
  cmp    %eax,0x5c(%rsp)
  je     L494
L229:
  lea    0x80(%rsp),%rsi
  lea    0x90(%rsp),%rdi
  movsd  (%r15),%xmm0
  call   <sincosd@plt>
  movsd  0x18(%rbp),%xmm2
  movsd  0x80(%rsp),%xmm0
  movapd %xmm2,%xmm4
  mulsd  %xmm0,%xmm4
  movsd  %xmm4,0x20(%rsp)
  movsd  0x20(%rbp),%xmm1
  mulsd  %xmm1,%xmm0
  movsd  %xmm0,0x38(%rsp)
  movsd  0x90(%rsp),%xmm0
  mulsd  %xmm0,%xmm2
  movsd  %xmm2,0x40(%rsp)
  mulsd  %xmm0,%xmm1
  movsd  %xmm1,0x28(%rsp)
  test   %r13d,%r13d
  jle    L139
  mov    0x48(%rsp),%rbx
  mov    0x50(%rsp),%r12
  mov    $0x0,%r14d
  jmp    L408
L494:
  mov    0x98(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L127
  mov    $0x0,%eax
  add    $0xa8,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L127:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: extract_symbolic_data
arguments: data_tag: D354
type: f64
name: extract_symbolic_data
arguments: data_tag: D10
type: f64[2]
name: extract_symbolic_data
arguments: data_tag: D228
type: f32[2]
name: extract_symbolic_data
arguments: data_tag: D195
type: f32[4]
name: extract_symbolic_data
arguments: data_tag: D211
type: f64
name: extract_symbolic_data
arguments: data_tag: D97
type: f32[4]
name: extract_symbolic_data
arguments: data_tag: D109
type: qword[2]
name: extract_symbolic_data
arguments: data_tag: D347
type: f64[2]
name: extract_symbolic_data
arguments: data_tag: D305
type: byte[8]
name: extract_symbolic_data
arguments: data_tag: D42
type: f64[2]
name: extract_symbolic_data
arguments: data_tag: D316
type: f32[2]
name: extract_symbolic_data
arguments: data_tag: D57
type: f32[2]

tool: D354: 180

tool: {"D10": [360.0,180.0]}

tool: {"D228": [0.0,-3.8515625]}

tool: {"D195": [0.0,-0.0,0.0,0.0]}

tool: D211: 1

tool: {"D97": [0.0,0.0,null,null]}

tool: {"D109": [0x7fffffffffffffff,0x0000000000000000]}

tool: {"D347": [0.99,0.0]}

tool: {"D305": [0xf1,0x68,0xe3,0x88,0xb5,0xf8,0xe4,0x3e]}

tool: {"D42": [90.0,-90.0]}

tool: {"D316": [0.0,-3.3515625]}

tool: {"D57": [0.0,-3.6015625]}

assistant: ```c
int sphx2s(const double eul[5], int nphi, int ntheta, int spt, int sll, const double phi[], const double theta[], double lng[], double lat[]) {
  int jphi, mphi, mtheta, rowlen, rowoff;
  double cosphi, costhe, costhe3, costhe4, dlng, dphi, sinphi, sinthe, sinthe3, sinthe4, x, y, z;
  register int iphi, itheta;
  register const double *phip, *thetap;
  register double *latp, *lngp;
  if (ntheta > 0) {
    mphi = nphi;
    mtheta = ntheta;
  } else {
    mphi = 1;
    mtheta = 1;
    ntheta = nphi;
  }
  if (eul[4] == 0.0) {
    if (eul[1] == 0.0) {
      dlng = fmod(eul[0] + 180.0 - eul[2], 360.0);
      jphi = 0;
      thetap = theta;
      lngp = lng;
      latp = lat;
      for (itheta = 0; itheta < ntheta; itheta++, thetap += spt) {
        phip = phi + (jphi % nphi) * spt;
        for (iphi = 0; iphi < mphi; iphi++, phip += spt, jphi++) {
          *lngp = *phip + dlng;
          *latp = *thetap;
          if (eul[0] >= 0.0) {
            if (*lngp < 0.0)
              *lngp += 360.0;
          } else {
            if (*lngp > 0.0)
              *lngp -= 360.0;
          }
          if (*lngp > 360.0) {
            *lngp -= 360.0;
          } else if (*lngp < -360.0) {
            *lngp += 360.0;
          }
          lngp += sll;
          latp += sll;
        }
      }
    } else {
      dlng = fmod(eul[0] + eul[2], 360.0);
      jphi = 0;
      thetap = theta;
      lngp = lng;
      latp = lat;
      for (itheta = 0; itheta < ntheta; itheta++, thetap += spt) {
        phip = phi + (jphi % nphi) * spt;
        for (iphi = 0; iphi < mphi; iphi++, phip += spt, jphi++) {
          *lngp = dlng - *phip;
          *latp = -(*thetap);
          if (eul[0] >= 0.0) {
            if (*lngp < 0.0)
              *lngp += 360.0;
          } else {
            if (*lngp > 0.0)
              *lngp -= 360.0;
          }
          if (*lngp > 360.0) {
            *lngp -= 360.0;
          } else if (*lngp < -360.0) {
            *lngp += 360.0;
          }
          lngp += sll;
          latp += sll;
        }
      }
    }
    return 0;
  }
  phip = phi;
  rowoff = 0;
  rowlen = nphi * sll;
  for (iphi = 0; iphi < nphi; iphi++, rowoff += sll, phip += spt) {
    dphi = *phip - eul[2];
    lngp = lng + rowoff;
    for (itheta = 0; itheta < mtheta; itheta++) {
      *lngp = dphi;
      lngp += rowlen;
    }
  }
  thetap = theta;
  lngp = lng;
  latp = lat;
  for (itheta = 0; itheta < ntheta; itheta++, thetap += spt) {
    sincosd(*thetap, &sinthe, &costhe);
    costhe3 = costhe * eul[3];
    costhe4 = costhe * eul[4];
    sinthe3 = sinthe * eul[3];
    sinthe4 = sinthe * eul[4];
    for (iphi = 0; iphi < mphi; iphi++, lngp += sll, latp += sll) {
      dphi = *lngp;
      sincosd(dphi, &sinphi, &cosphi);
      x = sinthe4 - costhe3 * cosphi;
      if (fabs(x) < 1.0e-5) {
        x = -cosd(*thetap + eul[1]) + costhe3 * (1.0 - cosphi);
      }
      y = -costhe * sinphi;
      if (x != 0.0 || y != 0.0) {
        dlng = atan2d(y, x);
      } else {
        if (eul[1] < 90.0) {
          dlng = dphi + 180.0;
        } else {
          dlng = -dphi;
        }
      }
      *lngp = eul[0] + dlng;
      if (eul[0] >= 0.0) {
        if (*lngp < 0.0)
          *lngp += 360.0;
      } else {
        if (*lngp > 0.0)
          *lngp -= 360.0;
      }
      if (*lngp > 360.0) {
        *lngp -= 360.0;
      } else if (*lngp < -360.0) {
        *lngp += 360.0;
      }
      if (fmod(dphi, 180.0) == 0.0) {
        *latp = *thetap + cosphi * eul[1];
        if (*latp > 90.0)
          *latp = 180.0 - *latp;
        if (*latp < -90.0)
          *latp = -180.0 - *latp;
      } else {
        z = sinthe3 + costhe4 * cosphi;
        if (fabs(z) > 0.99) {
          *latp = ((z) < 0.0 ? -fabs(acosd(sqrt(x * x + y * y))) : fabs(acosd(sqrt(x * x + y * y))));
        } else {
          *latp = asind(z);
        }
      }
    }
  }
  return 0;
}
```