user: Translate the below assembly code into C programming language:

```asm
<sphx2s>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  movslq %r8d,%r13
  push   %r12
  mov    %esi,%r12d
  push   %rbp
  mov    %rdi,%rbp
  push   %rbx
  mov    %r9,%rbx
  sub    $0xc8,%rsp
  mov    0x108(%rsp),%rax
  mov    %edx,0x6c(%rsp)
  mov    %ecx,(%rsp)
  mov    0x100(%rsp),%r14
  mov    %rax,0x58(%rsp)
  mov    0x110(%rsp),%rax
  mov    %rax,0x60(%rsp)
  mov    %fs:0x28,%rax
  mov    %rax,0xb8(%rsp)
  xor    %eax,%eax
  mov    %esi,0x24(%rsp)
  mov    %edx,%esi
  test   %edx,%edx
  jg     L11
  mov    %r12d,0x6c(%rsp)
  mov    $0x1,%esi
  movl   $0x1,0x24(%rsp)
L11:
  pxor   %xmm4,%xmm4
  ucomisd 0x20(%rbp),%xmm4
  jp     L604
  je     L94
L604:
  mov    %r12d,%eax
  imul   %r13d,%eax
  test   %r12d,%r12d
  jle    L831
  movslq (%rsp),%r8
  cltq
  movslq %r13d,%r10
  mov    0x58(%rsp),%r9
  lea    0x0(,%rax,8),%rcx
  shl    $0x3,%r10
  xor    %edi,%edi
  shl    $0x3,%r8
  cs nopw 0x0(%rax,%rax,1)
L667:
  movsd  (%rbx),%xmm0
  subsd  0x10(%rbp),%xmm0
  mov    %r9,%rdx
  xor    %eax,%eax
  xchg   %ax,%ax
L117:
  add    $0x1,%eax
  movsd  %xmm0,(%rdx)
  add    %rcx,%rdx
  cmp    %eax,%esi
  jne    L117
  add    $0x1,%edi
  add    %r8,%rbx
  add    %r10,%r9
  cmp    %edi,%r12d
  jne    L667
L831:
  mov    0x6c(%rsp),%edx
  test   %edx,%edx
  jle    L684
  movslq (%rsp),%rax
  lea    0x0(,%r13,8),%r15
  mov    %r14,0x38(%rsp)
  movl   $0x0,0x68(%rsp)
  shl    $0x3,%rax
  mov    %rax,0x70(%rsp)
  mov    0x24(%rsp),%eax
  sub    $0x1,%eax
  add    $0x1,%rax
  imul   %r15,%rax
  mov    %rax,0x88(%rsp)
  lea    0xa0(%rsp),%rax
  mov    %rax,0x78(%rsp)
  lea    0xb0(%rsp),%rax
  mov    %rax,0x80(%rsp)
  xchg   %ax,%ax
L82:
  mov    0x38(%rsp),%rax
  mov    0x78(%rsp),%rsi
  mov    0x80(%rsp),%rdi
  movsd  (%rax),%xmm0
  call   <sincosd@plt>
  movsd  0x18(%rbp),%xmm2
  movsd  0x20(%rbp),%xmm1
  movsd  0xa0(%rsp),%xmm0
  mov    0x24(%rsp),%eax
  movapd %xmm2,%xmm7
  mulsd  %xmm0,%xmm7
  mulsd  %xmm1,%xmm0
  movsd  %xmm7,0x18(%rsp)
  movsd  %xmm0,0x48(%rsp)
  movsd  0xb0(%rsp),%xmm0
  mulsd  %xmm0,%xmm2
  mulsd  %xmm0,%xmm1
  movsd  %xmm2,0x50(%rsp)
  movsd  %xmm1,0x28(%rsp)
  test   %eax,%eax
  jle    L199
  movsd  D65(%rip),%xmm5
  lea    0xa8(%rsp),%rax
  mov    0x58(%rsp),%rbx
  xor    %r13d,%r13d
  mov    %rax,0x30(%rsp)
  mov    0x60(%rsp),%r12
  lea    0x98(%rsp),%r14
  movsd  %xmm5,0x10(%rsp)
  jmp    L736
  nopl   0x0(%rax)
L492:
  subsd  %xmm5,%xmm0
  movsd  %xmm0,(%rbx)
L37:
  mov    D136(%rip),%rax
  movapd %xmm4,%xmm0
  movsd  %xmm2,0x8(%rsp)
  movsd  %xmm3,(%rsp)
  movq   %rax,%xmm1
  call   <fmod@plt>
  pxor   %xmm7,%xmm7
  movsd  (%rsp),%xmm3
  movsd  0x8(%rsp),%xmm2
  movapd %xmm0,%xmm1
  movsd  0x98(%rsp),%xmm0
  ucomisd %xmm7,%xmm1
  jp     L433
  jne    L433
  mov    0x38(%rsp),%rax
  mulsd  0x8(%rbp),%xmm0
  addsd  (%rax),%xmm0
  comisd D188(%rip),%xmm0
  jbe    L155
  movsd  D136(%rip),%xmm6
  subsd  %xmm0,%xmm6
  movapd %xmm6,%xmm0
L155:
  movsd  D183(%rip),%xmm1
  movsd  %xmm0,(%r12)
  comisd %xmm0,%xmm1
  jbe    L750
  movsd  D169(%rip),%xmm1
  subsd  %xmm0,%xmm1
  movsd  %xmm1,(%r12)
L750:
  add    $0x1,%r13d
  add    %r15,%rbx
  add    %r15,%r12
  cmp    %r13d,0x24(%rsp)
  je     L464
L736:
  movsd  (%rbx),%xmm4
  mov    0x30(%rsp),%rdi
  mov    %r14,%rsi
  movapd %xmm4,%xmm0
  movsd  %xmm4,(%rsp)
  call   <sincosd@plt>
  movsd  0x18(%rsp),%xmm0
  movsd  0x28(%rsp),%xmm3
  movsd  0x98(%rsp),%xmm2
  movsd  D67(%rip),%xmm6
  movsd  (%rsp),%xmm4
  mulsd  %xmm2,%xmm0
  subsd  %xmm0,%xmm3
  movapd %xmm3,%xmm0
  andpd  D88(%rip),%xmm0
  comisd %xmm0,%xmm6
  ja     L567
L800:
  pxor   %xmm7,%xmm7
  mov    $0x1,%edx
  movsd  0xa0(%rsp),%xmm2
  xorpd  D202(%rip),%xmm2
  mulsd  0xa8(%rsp),%xmm2
  ucomisd %xmm7,%xmm3
  setp   %al
  cmovne %edx,%eax
  test   %al,%al
  jne    L376
  ucomisd %xmm7,%xmm2
  setp   %al
  cmovne %edx,%eax
  test   %al,%al
  jne    L376
  movsd  D188(%rip),%xmm7
  comisd 0x8(%rbp),%xmm7
  jbe    L853
  movsd  D136(%rip),%xmm0
  addsd  %xmm4,%xmm0
L626:
  addsd  0x0(%rbp),%xmm0
  pxor   %xmm6,%xmm6
  movsd  %xmm0,(%rbx)
  movsd  0x0(%rbp),%xmm1
  comisd %xmm6,%xmm1
  jb     L285
  comisd %xmm0,%xmm6
  jbe    L328
  addsd  0x10(%rsp),%xmm0
  movsd  %xmm0,(%rbx)
L328:
  movsd  0x10(%rsp),%xmm5
  comisd %xmm5,%xmm0
  ja     L492
  movsd  D236(%rip),%xmm5
  comisd %xmm0,%xmm5
  jbe    L37
  addsd  0x10(%rsp),%xmm0
  movsd  %xmm0,(%rbx)
  jmp    L37
  nopl   0x0(%rax)
L433:
  mulsd  0x48(%rsp),%xmm0
  addsd  0x50(%rsp),%xmm0
  movapd %xmm0,%xmm1
  andpd  D88(%rip),%xmm1
  comisd D158(%rip),%xmm1
  jbe    L467
  mulsd  %xmm3,%xmm3
  pxor   %xmm4,%xmm4
  mulsd  %xmm2,%xmm2
  comisd %xmm0,%xmm4
  movapd %xmm3,%xmm1
  addsd  %xmm2,%xmm1
  movapd %xmm1,%xmm0
  ja     L6
  call   <sqrt@plt>
  mov    %eax,%edi
  call   <acosd@plt>
  andpd  D88(%rip),%xmm0
L291:
  movsd  %xmm0,(%r12)
  jmp    L750
  nopw   0x0(%rax,%rax,1)
L285:
  comisd %xmm6,%xmm0
  jbe    L328
  subsd  0x10(%rsp),%xmm0
  movsd  %xmm0,(%rbx)
  jmp    L328
  nopl   0x0(%rax)
L853:
  movapd %xmm4,%xmm0
  xorpd  D202(%rip),%xmm0
  jmp    L626
  nopl   0x0(%rax)
L376:
  movapd %xmm3,%xmm1
  movapd %xmm2,%xmm0
  movsd  %xmm2,(%rsp)
  movsd  %xmm4,0x40(%rsp)
  movsd  %xmm3,0x8(%rsp)
  call   <atan2d@plt>
  movsd  (%rsp),%xmm2
  movsd  0x8(%rsp),%xmm3
  movsd  0x40(%rsp),%xmm4
  jmp    L626
  nopl   0x0(%rax)
L567:
  movsd  D233(%rip),%xmm1
  mov    0x38(%rsp),%rax
  movsd  %xmm4,0x8(%rsp)
  subsd  %xmm2,%xmm1
  mulsd  0x18(%rsp),%xmm1
  movsd  (%rax),%xmm0
  addsd  0x8(%rbp),%xmm0
  movsd  %xmm1,(%rsp)
  call   <cosd@plt>
  movsd  (%rsp),%xmm1
  movsd  0x8(%rsp),%xmm4
  movapd %xmm1,%xmm3
  subsd  %xmm0,%xmm3
  jmp    L800
  nopl   0x0(%rax,%rax,1)
L467:
  call   <asind@plt>
  jmp    L291
  nopw   0x0(%rax,%rax,1)
L6:
  call   <sqrt@plt>
  mov    %eax,%edi
  call   <acosd@plt>
  andpd  D88(%rip),%xmm0
  xorpd  D202(%rip),%xmm0
  jmp    L291
  nopl   0x0(%rax)
L464:
  mov    0x88(%rsp),%rcx
  add    %rcx,0x58(%rsp)
  add    %rcx,0x60(%rsp)
L199:
  addl   $0x1,0x68(%rsp)
  mov    0x70(%rsp),%rdi
  mov    0x68(%rsp),%eax
  add    %rdi,0x38(%rsp)
  cmp    %eax,0x6c(%rsp)
  jne    L82
L684:
  mov    0xb8(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L80
  add    $0xc8,%rsp
  xor    %eax,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L94:
  ucomisd 0x8(%rbp),%xmm4
  movsd  0x0(%rbp),%xmm0
  movsd  0x10(%rbp),%xmm2
  movsd  D65(%rip),%xmm1
  jp     L187
  jne    L187
  addsd  D136(%rip),%xmm0
  movsd  %xmm1,0x8(%rsp)
  subsd  %xmm2,%xmm0
  call   <fmod@plt>
  mov    0x6c(%rsp),%r10d
  movsd  0x8(%rsp),%xmm1
  test   %r10d,%r10d
  jle    L684
  movslq (%rsp),%rsi
  mov    0x24(%rsp),%r9d
  movslq %r13d,%rcx
  shl    $0x3,%rcx
  mov    %rsi,%rax
  shl    $0x3,%rsi
  test   %r9d,%r9d
  jle    L684
  cmp    $0x1,%eax
  movslq 0x24(%rsp),%rax
  jne    L423
  cmp    $0x1,%r13d
  jne    L423
  mov    %rax,%r9
  imul   %rcx,%rax
  mov    %r12d,(%rsp)
  mov    0x58(%rsp),%r10
  movsd  D236(%rip),%xmm3
  mov    0x60(%rsp),%r12
  xor    %r8d,%r8d
  xor    %edi,%edi
  mov    %rax,%r11
  nopl   0x0(%rax)
L323:
  mov    %edi,%eax
  mov    %r12,%r13
  cltd
  idivl  (%rsp)
  mov    %r10,%rax
  movslq %edx,%rdx
  lea    (%rbx,%rdx,8),%r15
  xor    %edx,%edx
  jmp    L551
  nopw   0x0(%rax,%rax,1)
L640:
  subsd  %xmm1,%xmm2
  movsd  %xmm2,(%rax)
L462:
  add    $0x1,%edx
  add    %rcx,%rax
  add    %rcx,%r13
  add    %rsi,%r15
  cmp    %edx,%r9d
  je     L720
L551:
  movsd  (%r15),%xmm2
  pxor   %xmm4,%xmm4
  addsd  %xmm0,%xmm2
  movsd  %xmm2,(%rax)
  movsd  (%r14),%xmm2
  movsd  %xmm2,0x0(%r13)
  movsd  0x0(%rbp),%xmm2
  comisd %xmm4,%xmm2
  jb     L253
  movsd  (%rax),%xmm2
  comisd %xmm2,%xmm4
  jbe    L705
  addsd  %xmm1,%xmm2
  movsd  %xmm2,(%rax)
L705:
  comisd %xmm1,%xmm2
  ja     L640
  comisd %xmm2,%xmm3
  jbe    L462
  addsd  %xmm1,%xmm2
  movsd  %xmm2,(%rax)
  jmp    L462
L187:
  addsd  %xmm2,%xmm0
  movsd  %xmm1,0x8(%rsp)
  call   <fmod@plt>
  mov    0x6c(%rsp),%r8d
  movapd %xmm0,%xmm2
  test   %r8d,%r8d
  jle    L684
  movslq (%rsp),%rsi
  mov    0x24(%rsp),%edi
  movslq %r13d,%rcx
  shl    $0x3,%rcx
  mov    %rsi,%rax
  shl    $0x3,%rsi
  test   %edi,%edi
  jle    L684
  cmp    $0x1,%r13d
  movsd  0x8(%rsp),%xmm1
  jne    L160
  cmp    $0x1,%eax
  jne    L160
  movslq 0x24(%rsp),%rax
  mov    %r12d,(%rsp)
  xor    %r8d,%r8d
  xor    %edi,%edi
  movq   D202(%rip),%xmm3
  movsd  D236(%rip),%xmm4
  mov    %rax,%r9
  imul   %rcx,%rax
  mov    0x58(%rsp),%r10
  mov    0x60(%rsp),%r12
  mov    %rax,%r11
  nopw   0x0(%rax,%rax,1)
L580:
  mov    %edi,%eax
  mov    %r12,%r13
  cltd
  idivl  (%rsp)
  mov    %r10,%rax
  movslq %edx,%rdx
  lea    (%rbx,%rdx,8),%r15
  xor    %edx,%edx
  jmp    L41
  nopw   0x0(%rax,%rax,1)
L346:
  subsd  %xmm1,%xmm0
  movsd  %xmm0,(%rax)
L311:
  add    $0x1,%edx
  add    %rcx,%rax
  add    %rcx,%r13
  add    %rsi,%r15
  cmp    %edx,%r9d
  je     L852
L41:
  movapd %xmm2,%xmm0
  subsd  (%r15),%xmm0
  pxor   %xmm5,%xmm5
  movsd  %xmm0,(%rax)
  movsd  (%r14),%xmm0
  xorpd  %xmm3,%xmm0
  movsd  %xmm0,0x0(%r13)
  movsd  0x0(%rbp),%xmm0
  comisd %xmm5,%xmm0
  jb     L235
  movsd  (%rax),%xmm0
  comisd %xmm0,%xmm5
  jbe    L477
  addsd  %xmm1,%xmm0
  movsd  %xmm0,(%rax)
L477:
  comisd %xmm1,%xmm0
  ja     L346
  comisd %xmm0,%xmm4
  jbe    L311
  addsd  %xmm1,%xmm0
  movsd  %xmm0,(%rax)
  jmp    L311
L253:
  movsd  (%rax),%xmm2
  comisd %xmm4,%xmm2
  jbe    L705
  subsd  %xmm1,%xmm2
  movsd  %xmm2,(%rax)
  jmp    L705
  nopl   0x0(%rax,%rax,1)
L235:
  movsd  (%rax),%xmm0
  comisd %xmm5,%xmm0
  jbe    L477
  subsd  %xmm1,%xmm0
  movsd  %xmm0,(%rax)
  jmp    L477
  nopl   0x0(%rax)
L852:
  add    %r11,%r10
  add    %r11,%r12
  add    %r9d,%edi
  add    $0x1,%r8d
  add    %rsi,%r14
  cmp    %r8d,0x6c(%rsp)
  jne    L580
  jmp    L684
  nopl   0x0(%rax,%rax,1)
L720:
  add    %r11,%r10
  add    %r11,%r12
  add    %r9d,%edi
  add    $0x1,%r8d
  add    %rsi,%r14
  cmp    %r8d,0x6c(%rsp)
  jne    L323
  jmp    L684
L160:
  movslq 0x24(%rsp),%rax
  mov    %r12d,0x8(%rsp)
  xor    %r10d,%r10d
  xor    %r9d,%r9d
  movq   D202(%rip),%xmm3
  movsd  D236(%rip),%xmm4
  mov    %rax,%rdi
  imul   %rcx,%rax
  mov    0x58(%rsp),%r8
  mov    0x60(%rsp),%r12
  mov    %rax,%r11
L594:
  mov    %r9d,%eax
  mov    %r12,%r13
  cltd
  idivl  0x8(%rsp)
  imul   (%rsp),%edx
  movslq %edx,%rax
  xor    %edx,%edx
  lea    (%rbx,%rax,8),%r15
  mov    %r8,%rax
  jmp    L152
  nopl   0x0(%rax)
L293:
  subsd  %xmm1,%xmm0
  movsd  %xmm0,(%rax)
L510:
  add    $0x1,%edx
  add    %rcx,%rax
  add    %rcx,%r13
  add    %rsi,%r15
  cmp    %edx,%edi
  je     L46
L152:
  movapd %xmm2,%xmm0
  subsd  (%r15),%xmm0
  pxor   %xmm7,%xmm7
  movsd  %xmm0,(%rax)
  movsd  (%r14),%xmm0
  xorpd  %xmm3,%xmm0
  movsd  %xmm0,0x0(%r13)
  movsd  0x0(%rbp),%xmm0
  comisd %xmm7,%xmm0
  jb     L524
  movsd  (%rax),%xmm0
  comisd %xmm0,%xmm7
  jbe    L506
  addsd  %xmm1,%xmm0
  movsd  %xmm0,(%rax)
L506:
  comisd %xmm1,%xmm0
  ja     L293
  comisd %xmm0,%xmm4
  jbe    L510
  addsd  %xmm1,%xmm0
  add    $0x1,%edx
  add    %rcx,%r13
  add    %rsi,%r15
  movsd  %xmm0,(%rax)
  add    %rcx,%rax
  cmp    %edx,%edi
  jne    L152
L46:
  add    %r11,%r8
  add    %r11,%r12
  add    %edi,%r9d
  add    $0x1,%r10d
  add    %rsi,%r14
  cmp    %r10d,0x6c(%rsp)
  jne    L594
  jmp    L684
  nopl   0x0(%rax)
L524:
  movsd  (%rax),%xmm0
  comisd %xmm7,%xmm0
  jbe    L506
  subsd  %xmm1,%xmm0
  movsd  %xmm0,(%rax)
  jmp    L506
L423:
  mov    %rax,%rdi
  imul   %rcx,%rax
  mov    %r12d,0x8(%rsp)
  xor    %r10d,%r10d
  movsd  D236(%rip),%xmm3
  mov    0x58(%rsp),%r8
  xor    %r9d,%r9d
  mov    0x60(%rsp),%r12
  mov    %rax,%r11
L35:
  mov    %r9d,%eax
  mov    %r12,%r13
  cltd
  idivl  0x8(%rsp)
  imul   (%rsp),%edx
  movslq %edx,%rax
  xor    %edx,%edx
  lea    (%rbx,%rax,8),%r15
  mov    %r8,%rax
  jmp    L288
L349:
  subsd  %xmm1,%xmm2
  movsd  %xmm2,(%rax)
L395:
  add    $0x1,%edx
  add    %rcx,%rax
  add    %rcx,%r13
  add    %rsi,%r15
  cmp    %edx,%edi
  je     L394
L288:
  movsd  (%r15),%xmm2
  pxor   %xmm4,%xmm4
  addsd  %xmm0,%xmm2
  movsd  %xmm2,(%rax)
  movsd  (%r14),%xmm2
  movsd  %xmm2,0x0(%r13)
  movsd  0x0(%rbp),%xmm2
  comisd %xmm4,%xmm2
  movsd  (%rax),%xmm2
  jb     L186
  comisd %xmm2,%xmm4
  jbe    L792
  addsd  %xmm1,%xmm2
  movsd  %xmm2,(%rax)
L792:
  comisd %xmm1,%xmm2
  ja     L349
  comisd %xmm2,%xmm3
  jbe    L395
  addsd  %xmm1,%xmm2
  add    $0x1,%edx
  add    %rcx,%r13
  add    %rsi,%r15
  movsd  %xmm2,(%rax)
  add    %rcx,%rax
  cmp    %edx,%edi
  jne    L288
L394:
  add    %r11,%r8
  add    %r11,%r12
  add    %edi,%r9d
  add    $0x1,%r10d
  add    %rsi,%r14
  cmp    %r10d,0x6c(%rsp)
  jne    L35
  jmp    L684
  nopl   (%rax)
L186:
  comisd %xmm4,%xmm2
  jbe    L792
  subsd  %xmm1,%xmm2
  movsd  %xmm2,(%rax)
  jmp    L792
L80:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: parse_data
arguments: data_label: D65
data_type: f64
name: parse_data
arguments: data_label: D136
data_type: f64
name: parse_data
arguments: data_label: D188
data_type: f64[2]
name: parse_data
arguments: data_label: D183
data_type: f32[2]
name: parse_data
arguments: data_label: D169
data_type: f32[2]
name: parse_data
arguments: data_label: D67
data_type: byte[8]
name: parse_data
arguments: data_label: D88
data_type: qword[2]
name: parse_data
arguments: data_label: D202
data_type: f32[4]
name: parse_data
arguments: data_label: D236
data_type: f32[2]
name: parse_data
arguments: data_label: D158
data_type: f64[2]
name: parse_data
arguments: data_label: D233
data_type: f64

tool: D65: 360

tool: D136: 180

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

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

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

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

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

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

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

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

tool: D233: 1

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