// File: /workspace/github_c_makefile_star2_O3/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 0xc189
movl $0x0, 0x4c(%rbx)
movl 0x8(%rbx), %eax
andl $-0x21, %eax
movl %eax, 0x8(%rbx)
jmp 0xc18c
movl 0x8(%rbx), %eax
testb $0x2, %al
je 0xc1d9
movl $0xa, 0x4c(%rbx)
movl $0x0, 0x44(%rbx)
andl $-0x23, %eax
orl $0x20, %eax
movl %eax, 0x8(%rbx)
callq 0x4510
movzwl %ax, %eax
cvtsi2sd %eax, %xmm0
divsd 0x1eb5(%rip), %xmm0     # 0xe070
xorl %eax, %eax
ucomisd 0x2ac3(%rip), %xmm0     # 0xec88
seta %al
leaq 0x2b69(%rip), %rcx      # 0xed38
movss (%rcx,%rax,4), %xmm0
movss %xmm0, 0x40(%rbx)
movq 0x650(%rbx), %r15
movl 0x44(%rbx), %ecx
cmpl $0x95, %ecx
jg 0xc214
movss 0x34(%rbx), %xmm0
ucomiss 0x2b9d(%rip), %xmm0     # 0xed94
jbe 0xc214
movzwl 0x8(%r15), %eax
movss 0x14(%rbx), %xmm0
testl $0x119, %eax            # imm = 0x119
jne 0xc219
addss 0x2b86(%rip), %xmm0     # 0xed98
jmp 0xc221
movss 0x14(%rbx), %xmm0
addss 0x2b4f(%rip), %xmm0     # 0xed70
movss %xmm0, 0x14(%rbx)
movss 0x2b6e(%rip), %xmm1     # 0xed9c
ucomiss %xmm0, %xmm1
jae 0xc248
ucomiss 0x2b2a(%rip), %xmm0     # 0xed64
jbe 0xc252
movl $0x43160000, 0x14(%rbx) # imm = 0x43160000
movl 0x8(%rbx), %eax
jmp 0xc278
movl $0x42200000, 0x14(%rbx) # imm = 0x42200000
movaps %xmm1, %xmm0
movl 0x8(%rbx), %eax
testl $0x600, %eax            # imm = 0x600
je 0xc278
movss 0x2b24(%rip), %xmm1     # 0xed88
ucomiss %xmm0, %xmm1
jbe 0xc278
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 0xc52a
movl $0x0, 0x4c(%rbx)
cmpl $0x95, %ecx
jg 0xc40b
movss 0x34(%rbx), %xmm0
ucomiss 0x2aec(%rip), %xmm0     # 0xed94
jbe 0xc40b
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 0x1d7a(%rip), %xmm1     # 0xe050
andps %xmm3, %xmm1
cvtss2sd %xmm1, %xmm1
movsd 0x2a03(%rip), %xmm2     # 0xece8
ucomisd %xmm1, %xmm2
jbe 0xc2f9
movb %cl, %al
leaq 0x29fc(%rip), %rcx      # 0xecf0
movss (%rcx,%rax,4), %xmm3
movaps %xmm3, 0x10(%rsp)
divss %xmm3, %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x4270
movaps 0x10(%rsp), %xmm5
movsd 0x29e0(%rip), %xmm1     # 0xecf8
subsd %xmm0, %xmm1
cvtsd2ss %xmm1, %xmm1
cvtsd2ss %xmm0, %xmm0
xorps 0x1ce5(%rip), %xmm0     # 0xe010
cmpnless 0x2a4c(%rip), %xmm5     # 0xed80
andps %xmm5, %xmm0
andnps %xmm1, %xmm5
orps %xmm0, %xmm5
movss 0x20(%rbx), %xmm1
xorps %xmm0, %xmm0
cvtss2sd %xmm1, %xmm0
ucomisd 0x27df(%rip), %xmm0     # 0xeb30
jbe 0xc367
addsd 0x27dd(%rip), %xmm0     # 0xeb38
xorps %xmm1, %xmm1
cvtsd2ss %xmm0, %xmm1
movss %xmm1, 0x20(%rbx)
xorps %xmm0, %xmm0
ucomiss %xmm1, %xmm0
jbe 0xc384
cvtss2sd %xmm1, %xmm1
addsd 0x27b5(%rip), %xmm1     # 0xeb30
cvtsd2ss %xmm1, %xmm1
movss %xmm1, 0x20(%rbx)
xorps %xmm2, %xmm2
cvtss2sd %xmm5, %xmm2
subss %xmm1, %xmm5
divss 0x1c6d(%rip), %xmm5     # 0xe004
cvtss2sd %xmm1, %xmm1
addsd 0x2795(%rip), %xmm1     # 0xeb38
subsd %xmm1, %xmm2
divsd 0x2241(%rip), %xmm2     # 0xe5f0
cvtsd2ss %xmm2, %xmm2
movaps 0x1c96(%rip), %xmm3     # 0xe050
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
xorps %xmm0, %xmm0
cvtss2sd %xmm3, %xmm0
ucomisd 0x2952(%rip), %xmm0     # 0xed40
jbe 0xc3fe
movb %cl, %al
leaq 0x294f(%rip), %rcx      # 0xed48
movss (%rcx,%rax,4), %xmm1
movss %xmm1, 0x30(%rbx)
movl 0x8(%rbx), %eax
jmp 0xc52a
movss 0x20(%rbx), %xmm1
movss 0x40(%rbx), %xmm3
xorps %xmm0, %xmm0
cvtss2sd %xmm3, %xmm0
movsd 0x270c(%rip), %xmm4     # 0xeb30
addsd %xmm4, %xmm0
cvtsd2ss %xmm0, %xmm5
xorps %xmm2, %xmm2
movaps %xmm3, %xmm0
cmpltss %xmm2, %xmm0
andps %xmm0, %xmm5
andnps %xmm3, %xmm0
orps %xmm5, %xmm0
xorps %xmm3, %xmm3
cvtss2sd %xmm0, %xmm3
ucomisd %xmm4, %xmm3
jbe 0xc45c
addsd 0x26e3(%rip), %xmm3     # 0xeb38
xorps %xmm0, %xmm0
cvtsd2ss %xmm3, %xmm0
ucomiss %xmm1, %xmm2
jbe 0xc476
cvtss2sd %xmm1, %xmm1
addsd 0x26c3(%rip), %xmm1     # 0xeb30
cvtsd2ss %xmm1, %xmm1
movss %xmm1, 0x20(%rbx)
xorps %xmm2, %xmm2
cvtss2sd %xmm1, %xmm2
ucomisd 0x26ab(%rip), %xmm2     # 0xeb30
jbe 0xc4a2
addsd 0x26a9(%rip), %xmm2     # 0xeb38
xorps %xmm1, %xmm1
cvtsd2ss %xmm2, %xmm1
movss %xmm1, 0x20(%rbx)
xorps %xmm2, %xmm2
cvtss2sd %xmm1, %xmm2
xorps %xmm3, %xmm3
cvtss2sd %xmm0, %xmm3
subss %xmm1, %xmm0
divss 0x1b4f(%rip), %xmm0     # 0xe004
addsd 0x267b(%rip), %xmm2     # 0xeb38
subsd %xmm2, %xmm3
divsd 0x2127(%rip), %xmm3     # 0xe5f0
xorps %xmm2, %xmm2
cvtsd2ss %xmm3, %xmm2
movaps 0x1b79(%rip), %xmm3     # 0xe050
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
xorps %xmm0, %xmm0
cvtss2sd %xmm3, %xmm0
ucomisd 0x2832(%rip), %xmm0     # 0xed40
jbe 0xc51e
movb %dl, %cl
leaq 0x282f(%rip), %rdx      # 0xed48
movss (%rdx,%rcx,4), %xmm1
movss %xmm1, 0x30(%rbx)
movl $0x41f00000, 0x2c(%rbx) # imm = 0x41F00000
testb $0x20, %al
je 0xc670
movss 0x2646(%rip), %xmm0     # 0xeb80
ucomiss 0x14(%rbx), %xmm0
jbe 0xc670
movzwl 0x8(%r15), %eax
testl $0x119, %eax            # imm = 0x119
jne 0xc670
xorps %xmm0, %xmm0
cvtss2sd 0x30(%r14), %xmm0
callq 0x41e0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x10(%rsp)
xorps %xmm0, %xmm0
cvtss2sd 0x30(%r14), %xmm0
callq 0x4590
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xc(%rsp)
xorps %xmm0, %xmm0
cvtss2sd 0x20(%rbx), %xmm0
callq 0x41e0
cvtsd2ss %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
xorps %xmm0, %xmm0
cvtss2sd 0x20(%rbx), %xmm0
callq 0x4590
movss 0xc(%rsp), %xmm12
movss 0x10(%rsp), %xmm11
xorps %xmm1, %xmm1
cvtsd2ss %xmm0, %xmm1
movsd 0xc(%rbx), %xmm0
xorps 0x1a48(%rip), %xmm1     # 0xe010
movsd 0xc(%r14), %xmm8
unpcklps 0x20(%rsp), %xmm1       # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
movss 0x2c(%r14), %xmm2
shufps $0x0, %xmm2, %xmm2      # xmm2 = xmm2[0,0,0,0]
xorps %xmm3, %xmm3
movl $0x32, %eax
mulps 0x2664(%rip), %xmm1     # 0xec50
movaps 0x1a1d(%rip), %xmm4     # 0xe010
movss 0x27a5(%rip), %xmm5     # 0xeda0
xorps %xmm6, %xmm6
movaps %xmm0, %xmm7
movaps %xmm8, %xmm9
movaps %xmm3, %xmm8
addps %xmm1, %xmm7
movaps %xmm12, %xmm10
mulss %xmm6, %xmm10
mulss %xmm11, %xmm3
subss %xmm10, %xmm3
mulss %xmm12, %xmm8
mulss %xmm11, %xmm6
addss %xmm8, %xmm6
movaps %xmm6, %xmm8
xorps %xmm4, %xmm8
unpcklps %xmm3, %xmm8            # xmm8 = xmm8[0],xmm3[0],xmm8[1],xmm3[1]
mulps %xmm2, %xmm8
addps %xmm9, %xmm8
movaps %xmm8, %xmm9
subss %xmm7, %xmm9
movaps %xmm7, %xmm10
subps %xmm8, %xmm10
mulps %xmm10, %xmm10
shufps $0x55, %xmm10, %xmm10   # xmm10 = xmm10[1,1,1,1]
mulss %xmm9, %xmm9
addss %xmm10, %xmm9
ucomiss %xmm9, %xmm5
jae 0xc67a
decl %eax
jne 0xc601
addq $0x30, %rsp
popq %rbx
popq %r14
popq %r15
retq
movl $0x3, 0x8(%r15)
movlps %xmm0, 0xc(%r15)
xorl %eax, %eax
movl %eax, 0x14(%r15)
movsd 0x18(%rbx), %xmm0
movsd %xmm0, 0x18(%r15)
movss 0x20(%rbx), %xmm0
movss %xmm0, 0x20(%r15)
movl $0x42200000, 0x2c(%r15) # imm = 0x42200000
movl %eax, 0x44(%r15)
movl $0x3, %edi
movl $0x1, %esi
xorl %eax, %eax
addq $0x30, %rsp
popq %rbx
popq %r14
popq %r15
jmp 0x7a9c