// File: /workspace/github_c_makefile_star2_O2/jrrk[P]cbzone/c_move.c
// Function: movecopter
void movecopter(g, pl)
     Genericp g;
     Genericp pl;
{
  float dx, dy, tazm, t1, t2, t3, cp, sp, dcp, dsp, cm, sm;
  float xmt, ymt, xpt, ypt, rate, temp, dist;
  int i;
  Genericp s;

  g->pcount++;
  if (!(pl->attr & IS_ALIVE)) {
    g->pcount = 0;
    g->attr &= ~CAN_SHOOT;
  }

  if (g->attr & IS_NEW) {
    g->pcount = 10;
    g->ecount = 0;
    g->attr |= CAN_SHOOT;
    g->attr &= ~IS_NEW;
    if (frand() > 0.5)
      g->orientation = PI / 2.0;
    else
      g->orientation = -PI / 2.0;
  }

  s = g->salvo;
  if (g->ecount < 150 && g->range > 400.0)
    if (!(s->attr & STILL_THERE))
      g->z -= 5.0;
    else
      g->z += 5.0;
  else
    g->z += 5.0;

  if (g->z <= 40.0)
    g->z = 40.0;
  if (g->z > 150.0)
    g->z = 150.0;
  if (g->attr & IS_BLOCKED && g->z < 90.0) {
    g->z = 90.0;
    g->attr &= ~IS_BLOCKED;
  }

  g->speed = 20.0;
  if (g->pcount >= 10) {
    g->pcount = 0;
    if (g->range > 400.0 && g->ecount < 150) {
      dx = pl->x - g->x;
      dy = pl->y - g->y;
      if (fabs(dy) < 1.e-7)
        dy = sign(1.e-7, dy);
      if (dy <= 0.0)
        tazm = - atan(dx / dy) + ra (180.0);
      else
        tazm = - atan(dx / dy);
      if (g->azm > PI2)
        g->azm -= PI2;
      if (g->azm < 0.0)
        g->azm += PI2;
      t1 = (tazm - g->azm) / 10.0;
      t3 = (tazm - (g->azm - PI2)) /10.0;
      if (fabs(t3) < fabs(t1))
        t1 = t3;
      if (fabs(t1) > 0.06)
        t1 = sign (0.06, t1);
      g->rotate = t1;
    }
    else {
      tazm = g->orientation;
      if (tazm < 0.0)
        tazm += PI2;
      if (tazm > PI2)
        tazm -= PI2;
      if (g->azm < 0.0)
        g->azm += PI2;
      if (g->azm > PI2)
        g->azm -= PI2;
      t1 = (tazm - g->azm) / 10.0;
      t2 = (tazm - (g->azm - PI2)) / 10.0;
      if (fabs(t2) < fabs(t1))
        t1 = t2;
      if (fabs(t1) > 0.06)
        t1 = sign (0.06, t1);
      g->rotate = t1;
      g->speed = 30.0;
    }
  }

  if (g->attr & CAN_SHOOT && g->z < 50.0 &&
      !(s->attr & STILL_THERE)) {
    /*
     * the original Fortran had the following
     *    sp = pl->sa     and    cp = pl->ca
     *
     * however, sa and ca were undefined...fortran was really good
     * about making these 0, C doesn't guarantee this will occur.
     * the two choices to fix this are to make sp and cp
     * 0 initially or to make them the sin/cos of azm.
     * the first method makes the copter fire as it hits
     * the ground, the second method the copter won't fire
     * until it is very close unless you are moving straight
     * toward it or straight away from it.
     */
    cp = sp = 0;
    dcp = cos(pl->rotate);
    dsp = sin(pl->rotate);
    cm = cos(g->azm);
    sm = sin(g->azm);
    xmt = g->x;
    ymt = g->y;
    xpt = pl->x;
    ypt = pl->y;
    rate = 40.0;

    for (i=0; i<50; i++) {
      temp = cp;
      cp = cp * dcp - sp * dsp;
      sp = sp * dcp + dsp * temp;
      xmt -= sm * rate;
      ymt += cm * rate;
      xpt -= sp * pl->speed;
      ypt += cp * pl->speed;
      dist = (xpt-xmt)*(xpt-xmt) + (ymt-ypt)*(ymt-ypt);
      if (dist <= BMC_TOL) {
        s->attr = START_LIVING;
        s->x = g->x;
        s->y = g->y;
        s->z = 0.0;
        s->prox = g->prox;
        s->proy = g->proy;
        s->azm = g->azm;
        s->speed = 40.0;
        s->ecount = 0;
        message(3, True);
        break;
      }
    }
  }
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x30, %rsp
movq %rdi, %rbx
incl 0x4c(%rdi)
movq %rsi, %r14
testb $0x1, 0x8(%rsi)
jne 0xb3dc
andl $0x0, 0x4c(%rbx)
movl 0x8(%rbx), %eax
andl $-0x21, %eax
movl %eax, 0x8(%rbx)
jmp 0xb3df
movl 0x8(%rbx), %eax
testb $0x2, %al
je 0xb429
movl $0xa, 0x4c(%rbx)
andl $0x0, 0x44(%rbx)
andl $-0x23, %eax
orl $0x20, %eax
movl %eax, 0x8(%rbx)
callq 0x4520
movzwl %ax, %eax
cvtsi2sd %eax, %xmm0
divsd 0x1c65(%rip), %xmm0     # 0xd070
xorl %eax, %eax
ucomisd 0x2833(%rip), %xmm0     # 0xdc48
seta %al
leaq 0x28d9(%rip), %rcx      # 0xdcf8
movss (%rcx,%rax,4), %xmm0
movss %xmm0, 0x40(%rbx)
movq 0x650(%rbx), %r15
movl 0x44(%rbx), %ecx
cmpl $0x95, %ecx
jg 0xb463
movss 0x34(%rbx), %xmm0
ucomiss 0x290d(%rip), %xmm0     # 0xdd54
jbe 0xb463
movzwl 0x8(%r15), %eax
movss 0x14(%rbx), %xmm0
testw $0x119, %ax             # imm = 0x119
jne 0xb468
addss 0x28f7(%rip), %xmm0     # 0xdd58
jmp 0xb470
movss 0x14(%rbx), %xmm0
addss 0x28c0(%rip), %xmm0     # 0xdd30
movss %xmm0, 0x14(%rbx)
movss 0x28df(%rip), %xmm1     # 0xdd5c
ucomiss %xmm0, %xmm1
jae 0xb48f
movss 0x289a(%rip), %xmm1     # 0xdd24
ucomiss %xmm1, %xmm0
jbe 0xb497
movss %xmm1, 0x14(%rbx)
movaps %xmm1, %xmm0
movl 0x8(%rbx), %eax
testw $0x600, %ax             # imm = 0x600
je 0xb4bc
movss 0x28a0(%rip), %xmm1     # 0xdd48
ucomiss %xmm0, %xmm1
jbe 0xb4bc
movl $0x42b40000, 0x14(%rbx) # imm = 0x42B40000
andl $0xfffff9ff, %eax       # imm = 0xFFFFF9FF
movl %eax, 0x8(%rbx)
movl $0x41a00000, 0x2c(%rbx) # imm = 0x41A00000
cmpl $0xa, 0x4c(%rbx)
jl 0xb744
andl $0x0, 0x4c(%rbx)
cmpl $0x95, %ecx
jg 0xb640
movss 0x34(%rbx), %xmm0
ucomiss 0x286b(%rip), %xmm0     # 0xdd54
jbe 0xb640
movss 0xc(%r14), %xmm0
movss 0x10(%r14), %xmm3
subss 0xc(%rbx), %xmm0
subss 0x10(%rbx), %xmm3
xorps %xmm1, %xmm1
xorl %eax, %eax
ucomiss %xmm3, %xmm1
seta %cl
movaps 0x1b39(%rip), %xmm1     # 0xd050
andps %xmm3, %xmm1
cvtss2sd %xmm1, %xmm1
movsd 0x2782(%rip), %xmm2     # 0xdca8
ucomisd %xmm1, %xmm2
jbe 0xb53a
movb %cl, %al
leaq 0x277b(%rip), %rcx      # 0xdcb0
movss (%rcx,%rax,4), %xmm3
movaps %xmm3, 0x10(%rsp)
divss %xmm3, %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x4270
movaps 0x10(%rsp), %xmm5
movsd 0x275f(%rip), %xmm1     # 0xdcb8
subsd %xmm0, %xmm1
cvtsd2ss %xmm1, %xmm1
cvtsd2ss %xmm0, %xmm0
xorps 0x1aa4(%rip), %xmm0     # 0xd010
cmpnless 0x27cb(%rip), %xmm5     # 0xdd40
andps %xmm5, %xmm0
andnps %xmm1, %xmm5
orps %xmm0, %xmm5
movss 0x20(%rbx), %xmm1
cvtss2sd %xmm1, %xmm0
ucomisd 0x2561(%rip), %xmm0     # 0xdaf0
jbe 0xb5a2
addsd 0x255f(%rip), %xmm0     # 0xdaf8
cvtsd2ss %xmm0, %xmm1
movss %xmm1, 0x20(%rbx)
xorps %xmm0, %xmm0
ucomiss %xmm1, %xmm0
jbe 0xb5bf
cvtss2sd %xmm1, %xmm1
addsd 0x253a(%rip), %xmm1     # 0xdaf0
cvtsd2ss %xmm1, %xmm1
movss %xmm1, 0x20(%rbx)
cvtss2sd %xmm5, %xmm2
subss %xmm1, %xmm5
divss 0x1a35(%rip), %xmm5     # 0xd004
cvtss2sd %xmm1, %xmm1
addsd 0x251d(%rip), %xmm1     # 0xdaf8
subsd %xmm1, %xmm2
divsd 0x1fd9(%rip), %xmm2     # 0xd5c0
cvtsd2ss %xmm2, %xmm2
movaps 0x1a5e(%rip), %xmm3     # 0xd050
movaps %xmm2, %xmm1
andps %xmm3, %xmm1
movaps %xmm5, %xmm4
andps %xmm3, %xmm4
cmpltss %xmm4, %xmm1
andps %xmm1, %xmm2
andnps %xmm5, %xmm1
orps %xmm2, %xmm1
xorl %eax, %eax
ucomiss %xmm1, %xmm0
seta %cl
andps %xmm1, %xmm3
cvtss2sd %xmm3, %xmm0
ucomisd 0x26dd(%rip), %xmm0     # 0xdd00
jbe 0xb633
movb %cl, %al
leaq 0x26da(%rip), %rcx      # 0xdd08
movss (%rcx,%rax,4), %xmm1
movss %xmm1, 0x30(%rbx)
movl 0x8(%rbx), %eax
jmp 0xb744
movss 0x20(%rbx), %xmm1
movss 0x40(%rbx), %xmm3
cvtss2sd %xmm3, %xmm0
movsd 0x249a(%rip), %xmm4     # 0xdaf0
addsd %xmm4, %xmm0
cvtsd2ss %xmm0, %xmm5
xorps %xmm2, %xmm2
movaps %xmm3, %xmm0
cmpltss %xmm2, %xmm0
andps %xmm0, %xmm5
andnps %xmm3, %xmm0
orps %xmm5, %xmm0
cvtss2sd %xmm0, %xmm3
ucomisd %xmm4, %xmm3
jbe 0xb688
addsd 0x2474(%rip), %xmm3     # 0xdaf8
cvtsd2ss %xmm3, %xmm0
ucomiss %xmm1, %xmm2
jbe 0xb6a2
cvtss2sd %xmm1, %xmm1
addsd 0x2457(%rip), %xmm1     # 0xdaf0
cvtsd2ss %xmm1, %xmm1
movss %xmm1, 0x20(%rbx)
cvtss2sd %xmm1, %xmm2
ucomisd 0x2442(%rip), %xmm2     # 0xdaf0
jbe 0xb6c5
addsd 0x2440(%rip), %xmm2     # 0xdaf8
cvtsd2ss %xmm2, %xmm1
movss %xmm1, 0x20(%rbx)
cvtss2sd %xmm1, %xmm2
cvtss2sd %xmm0, %xmm3
subss %xmm1, %xmm0
divss 0x192f(%rip), %xmm0     # 0xd004
addsd 0x241b(%rip), %xmm2     # 0xdaf8
subsd %xmm2, %xmm3
divsd 0x1ed7(%rip), %xmm3     # 0xd5c0
cvtsd2ss %xmm3, %xmm2
movaps 0x195c(%rip), %xmm3     # 0xd050
movaps %xmm2, %xmm1
andps %xmm3, %xmm1
movaps %xmm0, %xmm4
andps %xmm3, %xmm4
cmpltss %xmm4, %xmm1
andps %xmm1, %xmm2
andnps %xmm0, %xmm1
orps %xmm2, %xmm1
xorps %xmm0, %xmm0
xorl %ecx, %ecx
ucomiss %xmm1, %xmm0
seta %dl
andps %xmm1, %xmm3
cvtss2sd %xmm3, %xmm0
ucomisd 0x25d8(%rip), %xmm0     # 0xdd00
jbe 0xb738
movb %dl, %cl
leaq 0x25d5(%rip), %rdx      # 0xdd08
movss (%rdx,%rcx,4), %xmm1
movss %xmm1, 0x30(%rbx)
movl $0x41f00000, 0x2c(%rbx) # imm = 0x41F00000
testb $0x20, %al
je 0xb761
movss 0x23e4(%rip), %xmm0     # 0xdb34
ucomiss 0x14(%rbx), %xmm0
jbe 0xb761
movzwl 0x8(%r15), %eax
testw $0x119, %ax             # imm = 0x119
je 0xb76b
addq $0x30, %rsp
popq %rbx
popq %r14
popq %r15
retq
cvtss2sd 0x30(%r14), %xmm0
callq 0x41e0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x10(%rsp)
cvtss2sd 0x30(%r14), %xmm0
callq 0x45a0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xc(%rsp)
cvtss2sd 0x20(%rbx), %xmm0
callq 0x41e0
cvtsd2ss %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
cvtss2sd 0x20(%rbx), %xmm0
callq 0x45a0
movss 0xc(%rsp), %xmm12
movss 0x10(%rsp), %xmm11
cvtsd2ss %xmm0, %xmm1
movsd 0xc(%rbx), %xmm0
xorps 0x1840(%rip), %xmm1     # 0xd010
movsd 0xc(%r14), %xmm2
unpcklps 0x20(%rsp), %xmm1       # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
movss 0x2c(%r14), %xmm3
shufps $0x0, %xmm3, %xmm3      # xmm3 = xmm3[0,0,0,0]
xorps %xmm4, %xmm4
pushq $0x33
popq %rax
mulps 0x241e(%rip), %xmm1     # 0xdc10
movaps 0x1817(%rip), %xmm5     # 0xd010
movss 0x255f(%rip), %xmm6     # 0xdd60
xorps %xmm9, %xmm9
movaps %xmm0, %xmm7
decl %eax
je 0xb761
movaps %xmm12, %xmm10
mulss %xmm4, %xmm10
movaps %xmm9, %xmm8
mulss %xmm11, %xmm8
subss %xmm10, %xmm8
mulss %xmm12, %xmm9
mulss %xmm11, %xmm4
addss %xmm9, %xmm4
addps %xmm1, %xmm7
movaps %xmm4, %xmm9
xorps %xmm5, %xmm9
unpcklps %xmm8, %xmm9            # xmm9 = xmm9[0],xmm8[0],xmm9[1],xmm8[1]
mulps %xmm3, %xmm9
addps %xmm9, %xmm2
movaps %xmm2, %xmm9
subss %xmm7, %xmm9
movaps %xmm7, %xmm10
subps %xmm2, %xmm10
mulps %xmm10, %xmm10
shufps $0x55, %xmm10, %xmm10   # xmm10 = xmm10[1,1,1,1]
mulss %xmm9, %xmm9
addss %xmm10, %xmm9
ucomiss %xmm9, %xmm6
movaps %xmm8, %xmm9
jb 0xb808
movl $0x3, 0x8(%r15)
movlps %xmm0, 0xc(%r15)
andl $0x0, 0x14(%r15)
movsd 0x18(%rbx), %xmm0
movsd %xmm0, 0x18(%r15)
movss 0x20(%rbx), %xmm0
movss %xmm0, 0x20(%r15)
movl $0x42200000, 0x2c(%r15) # imm = 0x42200000
andl $0x0, 0x44(%r15)
pushq $0x3
popq %rdi
pushq $0x1
popq %rsi
xorl %eax, %eax
addq $0x30, %rsp
popq %rbx
popq %r14
popq %r15
jmp 0x73a4