// File: /workspace/github_cpp_makefile_star2_O3/jkingan[P]ladyheather/heathmsc.cpp
// Function: plot_sat_trail(int, int, int, int, float, float, int, int)
void plot_sat_trail(int grid_x,int grid_y, int grid_r,  int prn, float az,float el,  int color, int dots)
{
int x1,y1;
int x2,y2;
int i;
int row;
u08 m;

   // Draw the trail of previous sat positions.  The trail is marked with colored
   // on the hour and black dots otherwise  as time markers.  

   if(map_trails == 0) return;  // trails disabled
   if((prn == SUN_PRN) && (no_sun_moon & 0x01)) return;
   if((prn == MOON_PRN) && (no_sun_moon & 0x02)) return;

   m = 0;
   row = 0;

   // the current location of the sat
   if(az < 0.0F) az += 360.0F;
   if(az >= 360.0F) az -= 360.0F;
   x1 = grid_x + (int) ((el * cos360(az) * grid_r)+0.50);
   y1 = grid_y + (int) ((el * sin360(az) * grid_r)+0.50);
   if(x1 < 0) return;
   if(y1 < 0) return;
   if(x1 >= SCREEN_WIDTH) return;
   if(y1 >= SCREEN_WIDTH) return;

   for(i=0; i<trail_count; i++) { // check the old locations of the sat
      el = (float) sat_trail[prn].el[i];
      az = (float) sat_trail[prn].az[i];
      if((az == 0.0F) && (el == 0.0F)) break;  // end of valid locations
      if((prn == MOON_PRN) || (prn == SUN_PRN)) {  // moon color depends upon elevation
         if(el < 0.0F) color = GREY;  // !!!! this does not work since saved el is always positive
         else color = MOON_COLOR;
//sprintf(debug_text2, "moon: el:%f  moon_el:%f  color:%d", el, moon_el, color);
      }
      if(el < 0.0F) el = 0.0F - el;

      el = (el - 90.0F) / 90.0F;
      az += 90.0F;
      if(az < 0.0F) az += 360.0F;
      if(az >= 360.0F) az -= 360.0F;

      x2 = grid_x + (int) ((el * cos360(az) * grid_r)+0.50);
      y2 = grid_y + (int) ((el * sin360(az) * grid_r)+0.50);
      if(x2 < 0) continue;
      if(y2 < 0) continue;
      if(x2 >= SCREEN_WIDTH) continue;
      if(y2 >= SCREEN_WIDTH) continue;

      if(dots) {  // mark the trail with time markers
         if((sat_trail[prn].mins[i] % TRAIL_MARKER) == 0) {    // it's time to mark the trail
            if(sat_trail[prn].mins[i] != 0) {  // it's not the hour... dot the dot
               draw_circle(x2,y2, 2, color, 0);  // hollow circle
            }
            else {
               draw_circle(x2,y2, 2, color, 1);  // filled circle
            }
         }
      }
      else {   // draw the trail line
         line(x1,y1, x2,y2, color); 
      }

      x1 = x2;
      y1 = y2;
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %r9d, -0x4c(%rbp)
movl %esi, -0x44(%rbp)
movl %edi, -0x48(%rbp)
leaq 0x12674d(%rip), %rax    # 0x21b419
cmpb $0x0, (%rax)
je 0xf5045
movl %r8d, %r12d
movl %edx, %ebx
cmpl $0x3e9, %ecx            # imm = 0x3E9
je 0xf4cfb
cmpl $0x3e8, %ecx            # imm = 0x3E8
jne 0xf4d0b
leaq 0x7bf77(%rip), %rax     # 0x170c68
testb $0x1, (%rax)
je 0xf4d0b
jmp 0xf5045
leaq 0x7bf66(%rip), %rax     # 0x170c68
testb $0x2, (%rax)
jne 0xf5045
movss 0x29d19(%rip), %xmm4    # 0x11ea2c
movaps %xmm0, %xmm5
addss %xmm4, %xmm5
xorps %xmm2, %xmm2
movss %xmm1, -0x30(%rbp)
movaps %xmm0, %xmm3
cmpltss %xmm2, %xmm3
andps %xmm3, %xmm5
andnps %xmm0, %xmm3
orps %xmm5, %xmm3
movaps %xmm4, %xmm0
cmpnless %xmm3, %xmm0
movaps %xmm3, %xmm1
addss 0x37a9e(%rip), %xmm1    # 0x12c7e4
movaps %xmm0, %xmm2
andps %xmm3, %xmm2
andnps %xmm1, %xmm0
orps %xmm2, %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd 0x293d5(%rip), %xmm1    # 0x11e138
movl %ecx, %r14d
callq 0x94d0
divsd 0x143ed(%rip), %xmm0    # 0x109160
callq 0x9710
cvtsd2ss %xmm0, %xmm0
xorps %xmm1, %xmm1
cvtsi2ss %ebx, %xmm1
movss %xmm1, -0x34(%rbp)
mulss -0x30(%rbp), %xmm0
mulss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
addsd 0x142cb(%rip), %xmm0    # 0x109068
cvttsd2si %xmm0, %r13d
movsd -0x40(%rbp), %xmm0
movsd 0x29389(%rip), %xmm1    # 0x11e138
callq 0x94d0
divsd 0x143a4(%rip), %xmm0    # 0x109160
callq 0x9080
movss -0x30(%rbp), %xmm3
movsd 0x1429a(%rip), %xmm2    # 0x109068
movss -0x34(%rbp), %xmm1
addl -0x48(%rbp), %r13d
js 0xf5045
cvtsd2ss %xmm0, %xmm0
mulss %xmm3, %xmm0
mulss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
addsd %xmm2, %xmm0
cvttsd2si %xmm0, %r15d
addl -0x44(%rbp), %r15d
js 0xf5045
leaq 0x1239f9(%rip), %rax    # 0x218800
movl (%rax), %eax
cmpl %eax, %r13d
jge 0xf5045
cmpl %eax, %r15d
jge 0xf5045
cmpl $0x0, 0x286a3e(%rip)    # 0x37b860
jle 0xf5045
movl %r14d, %ecx
movslq %r14d, %rax
imulq $0x36c, %rax, %rax      # imm = 0x36C
leaq 0x286a34(%rip), %rdx    # 0x37b870
addq %rax, %rdx
movq %rdx, -0x58(%rbp)
andl $-0x2, %ecx
xorl %r14d, %r14d
xorps %xmm4, %xmm4
movl %ecx, -0x2c(%rbp)
movq -0x58(%rbp), %rax
movss (%rax,%r14,4), %xmm0
movss 0x124(%rax,%r14,4), %xmm2
ucomiss %xmm4, %xmm0
jne 0xf4e75
jp 0xf4e75
ucomiss %xmm4, %xmm2
jne 0xf4e75
jnp 0xf5045
ucomiss %xmm2, %xmm4
movl $0xe, %eax
movl $0x8, %edx
cmoval %edx, %eax
jbe 0xf4e91
xorps %xmm1, %xmm1
subss %xmm2, %xmm1
movaps %xmm1, %xmm2
cmpl $0x3e8, %ecx            # imm = 0x3E8
cmovel %eax, %r12d
movl %r12d, -0x40(%rbp)
addss 0x29b81(%rip), %xmm2    # 0x11ea28
movss 0x181d5(%rip), %xmm1    # 0x10d084
divss %xmm1, %xmm2
movss %xmm2, -0x30(%rbp)
addss %xmm1, %xmm0
movaps %xmm0, %xmm1
movss 0x29b65(%rip), %xmm3    # 0x11ea2c
addss %xmm3, %xmm1
movaps %xmm0, %xmm2
cmpltss %xmm4, %xmm2
andps %xmm2, %xmm1
andnps %xmm0, %xmm2
orps %xmm1, %xmm2
movaps %xmm3, %xmm0
cmpnless %xmm2, %xmm0
movaps %xmm0, %xmm1
andps %xmm2, %xmm1
addss 0x378f2(%rip), %xmm2    # 0x12c7e4
andnps %xmm2, %xmm0
orps %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x60(%rbp)
movsd 0x2922f(%rip), %xmm1    # 0x11e138
callq 0x94d0
movsd 0x1424a(%rip), %xmm1    # 0x109160
divsd %xmm1, %xmm0
callq 0x9710
cvtsd2ss %xmm0, %xmm0
mulss -0x30(%rbp), %xmm0
mulss -0x34(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x1412f(%rip), %xmm1    # 0x109068
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %ebx
movsd -0x60(%rbp), %xmm0
movsd 0x291ea(%rip), %xmm1    # 0x11e138
callq 0x94d0
divsd 0x14205(%rip), %xmm0    # 0x109160
callq 0x9080
addl -0x48(%rbp), %ebx
js 0xf4fdf
cvtsd2ss %xmm0, %xmm0
movss -0x30(%rbp), %xmm1
mulss %xmm0, %xmm1
movss -0x34(%rbp), %xmm2
mulss %xmm2, %xmm1
xorps %xmm0, %xmm0
cvtss2sd %xmm1, %xmm0
addsd 0x140de(%rip), %xmm0    # 0x109068
cvttsd2si %xmm0, %r12d
addl -0x44(%rbp), %r12d
movl -0x2c(%rbp), %ecx
xorps %xmm4, %xmm4
js 0xf4fd7
leaq 0x12385e(%rip), %rax    # 0x218800
movl (%rax), %eax
cmpl %eax, %ebx
jge 0xf4fd7
cmpl %eax, %r12d
jge 0xf4fd7
cmpl $0x0, -0x4c(%rbp)
je 0xf4fe7
movq -0x58(%rbp), %rax
movl 0x248(%rax,%r14,4), %eax
imull $0xeeeeeeef, %eax, %ecx # imm = 0xEEEEEEEF
movl $0x8888888, %edx        # imm = 0x8888888
addl %edx, %ecx
rorl %ecx
cmpl %edx, %ecx
jbe 0xf4ffe
movl -0x2c(%rbp), %ecx
jmp 0xf5028
movl %r15d, %r12d
movl %r13d, %ebx
jmp 0xf5028
movl %r15d, %r12d
movl %r13d, %ebx
jmp 0xf5022
movzbl -0x40(%rbp), %r8d
movl %r13d, %edi
movl %r15d, %esi
movl %ebx, %edx
movl %r12d, %ecx
callq 0xe38a
jmp 0xf5022
movl %ebx, %edi
movl %r12d, %esi
movl $0x2, %edx
testl %eax, %eax
je 0xf5014
movl -0x40(%rbp), %ecx
xorl %r8d, %r8d
jmp 0xf501d
movl -0x40(%rbp), %ecx
movl $0x1, %r8d
callq 0xf17c
movl -0x2c(%rbp), %ecx
xorps %xmm4, %xmm4
incq %r14
movslq 0x28682e(%rip), %rax    # 0x37b860
movl %ebx, %r13d
movl %r12d, %r15d
cmpq %rax, %r14
movl -0x40(%rbp), %r12d
jl 0xf4e4f
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq