// File: /workspace/github_c_makefile_star2_O3/hyc[P]trek73c/trekx.c
// Function: Damage
void Damage(From, Nto, Hits, Sorc)
int From, Nto, Hits, Sorc;
{
  int fax[6];
  int odds[(int)Warp - (int)Comp + 1];
  reg int I, J, S;
  double H;
  Damages L;
  reg Srec *WITH;
  int FORLIM;

  H = Bearing(From, Nto);
  H = RMod(H - Objects[Nto]->Act_Crs + 225) / 90 + 1;
  S = (long)H;
  if (S == 5)
    S = 1;
  sprintf(scrstr," Hit %d on %s's shield %d", Hits, Snams[Nto], S);
  SEndln();
  if (Sorc == 0) {
    fax[0] = 50;
    fax[1] = 2;
    fax[2] = 20;
    fax[3] = 3;
    fax[4] = 10;
    fax[5] = 3;
    odds[0] = 1000;
    odds[(int)Snsr - (int)Comp] = 500;
    odds[(int)Prob - (int)Comp] = 100;
    odds[(int)Warp - (int)Comp] = 50;
  } else {
    fax[0] = 100;
    fax[1] = 3;
    fax[2] = 10;
    fax[3] = 2;
    fax[4] = 7;
    fax[5] = 6;
    odds[0] = 1500;
    odds[(int)Snsr - (int)Comp] = 750;
    odds[(int)Prob - (int)Comp] = 150;
    odds[(int)Warp - (int)Comp] = 75;
  }
  WITH = Ships[Nto];
  S--;
  H = Hits * (1 - WITH->Sdrns[S] * WITH->Seff[S] / 100);
  WITH->Weff += H / fax[0];
  Objects[Nto]->Fuel -= H / fax[1];
  if (Objects[Nto]->Fuel < 0)
    Objects[Nto]->Fuel = 0.0;
  WITH->Regen -= H / fax[2];
  if (WITH->Regen < 0)
    WITH->Regen = 0.0;
  if (!S)
    fax[3] = (long)floor(fax[3] * 1.5 + 0.5);
  WITH->Seff[S] -= (double)Hits / fax[3];
  if (WITH->Seff[S] < 0)
    WITH->Seff[S] = 0.0;
  WITH->Crew -= _randint((long)fax[4]);
  if (WITH->Crew < 0)
    WITH->Crew = 0;
  FORLIM = (long)floor(H / fax[5] + 0.5);
  for (I = 0; I < FORLIM; I++) {
    J = _randint((long)(Phasers + Tubes));
    if (J >= Phasers) {
      J -= Phasers;
      if (WITH->Tstat[J] >= 0) {
	WITH->Tstat[J] = (-1);
	WITH->Tengy[J] = 0;
	if (!Nto) {
	  sprintf(scrstr," Tube %d damaged.", J+1);
	  SEndln();
	}
      }
    } else {
      if (WITH->Pstat[J] >= 0) {
	WITH->Pstat[J] = (-1);
	WITH->PChrg[J] = 0.0;
	WITH->PCrts[J] = 0.0;
	if (!Nto) {
	  sprintf(scrstr," Phaser %d damaged.", J+1);
	  SEndln();
	}
      }
    }
  }
  for (L = Comp; (long)L <= (long)Warp; L = (Damages)((long)L + 1)) {
    if (H >= _randint((long)odds[(long)L - (long)Comp])) {
      if (!WITH->Dmge[(long)L]) {
	WITH->Dmge[(long)L] = true;
	if (!Nto) {
	  sprintf(scrstr,"  %s", DText[(long)L - (long)Comp]);
	  SEndln();
	}
      }
    }
  }
  if (H > 42)
    Objects[Nto]->Tim_Del = 10000.0;
  Distrib(Nto, Iter);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %ecx, %r15d
movl %edx, %ebp
movl %esi, %ebx
callq 0x3e93
movslq %ebx, %r12
leaq 0xefc8(%rip), %rax      # 0x135f0
movq (%rax,%r12,8), %rax
subsd 0x10(%rax), %xmm0
addsd 0x8b4f(%rip), %xmm0     # 0xd188
movsd %xmm0, (%rsp)
movsd 0x8b0a(%rip), %xmm2     # 0xd150
divsd %xmm2, %xmm0
leaq 0x30(%rsp), %r14
movq %r14, %rdi
callq 0x22b0
movsd 0x8af9(%rip), %xmm0     # 0xd158
movsd (%r14), %xmm1
mulsd %xmm0, %xmm1
addsd (%rsp), %xmm1
addsd %xmm1, %xmm0
movsd 0x8ad7(%rip), %xmm3     # 0xd150
movapd %xmm3, %xmm2
cmpnlesd %xmm1, %xmm2
andpd %xmm2, %xmm1
andnpd %xmm0, %xmm2
orpd %xmm1, %xmm2
addsd %xmm2, %xmm3
xorpd %xmm1, %xmm1
movapd %xmm2, %xmm0
cmpltsd %xmm1, %xmm0
andpd %xmm0, %xmm3
andnpd %xmm2, %xmm0
orpd %xmm3, %xmm0
divsd 0x8aad(%rip), %xmm0     # 0xd160
addsd 0x8a7d(%rip), %xmm0     # 0xd138
cvttsd2si %xmm0, %rax
cmpl $0x5, %eax
movl $0x1, %r14d
cmovnel %eax, %r14d
leaq 0xf25c(%rip), %rax      # 0x13930
movq %r12, 0x20(%rsp)
movq (%rax,%r12,8), %rcx
leaq 0xedcc(%rip), %r12      # 0x134b0
leaq 0x9907(%rip), %rsi      # 0xdff2
movq %r12, %rdi
movl %ebp, %edx
movl %r14d, %r8d
xorl %eax, %eax
callq 0x21a0
movq 0xf2f7(%rip), %rdi      # 0x139f8
movq %r12, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x2210
callq 0x3d76
testl %r15d, %r15d
je 0x474a
movapd 0x89c0(%rip), %xmm0     # 0xd0e0
movaps 0x89c9(%rip), %xmm2     # 0xd0f0
movsd 0x8a71(%rip), %xmm1     # 0xd1a0
movsd %xmm1, 0x18(%rsp)
movl $0x7, %r15d
movsd 0x8a65(%rip), %xmm1     # 0xd1a8
movl $0x2, %eax
jmp 0x477a
movapd 0x896e(%rip), %xmm0     # 0xd0c0
movaps 0x8977(%rip), %xmm2     # 0xd0d0
movsd 0x8a2f(%rip), %xmm1     # 0xd190
movsd %xmm1, 0x18(%rsp)
movl $0xa, %r15d
movsd 0x8a23(%rip), %xmm1     # 0xd198
movl $0x3, %eax
movaps %xmm2, 0x30(%rsp)
leaq 0xf20a(%rip), %rcx      # 0x13990
movq 0x20(%rsp), %rdx
movq (%rcx,%rdx,8), %r12
movslq %r14d, %r13
cvtsi2sd %ebp, %xmm4
movsd 0x78(%r12,%r13,8), %xmm3
mulsd 0x98(%r12,%r13,8), %xmm3
divsd 0x8a01(%rip), %xmm3     # 0xd1b0
addsd 0x8981(%rip), %xmm3     # 0xd138
mulsd %xmm4, %xmm3
movapd %xmm3, %xmm2
divsd %xmm1, %xmm2
addsd 0x8(%r12), %xmm2
movsd %xmm2, 0x8(%r12)
leaq 0xee18(%rip), %rcx      # 0x135f0
movq (%rcx,%rdx,8), %rcx
movapd %xmm3, (%rsp)
movapd %xmm3, %xmm2
unpcklpd %xmm3, %xmm2            # xmm2 = xmm2[0],xmm3[0]
movsd 0x20(%rcx), %xmm1
movhpd (%r12), %xmm1           # xmm1 = xmm1[0],mem[0]
divpd %xmm0, %xmm2
subpd %xmm2, %xmm1
xorpd %xmm0, %xmm0
movapd %xmm1, %xmm2
cmpltpd %xmm0, %xmm2
movmskpd %xmm2, %edx
xorpd %xmm0, %xmm0
testb $0x1, %dl
jne 0x481a
movapd %xmm1, %xmm0
movsd %xmm0, 0x20(%rcx)
testb $0x2, %dl
xorpd %xmm0, %xmm0
jne 0x4830
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
movapd %xmm1, %xmm0
decq %r13
movsd %xmm0, (%r12)
cmpl $0x1, %r14d
jne 0x486c
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
mulsd 0x896a(%rip), %xmm0     # 0xd1b8
addsd 0x8922(%rip), %xmm0     # 0xd178
movsd %xmm4, 0x28(%rsp)
callq 0x22d0
movsd 0x28(%rsp), %xmm4
cvttsd2si %xmm0, %rax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd %xmm0, %xmm4
movsd 0xa0(%r12,%r13,8), %xmm0
subsd %xmm4, %xmm0
xorpd %xmm1, %xmm1
maxsd %xmm0, %xmm1
movsd %xmm1, 0xa0(%r12,%r13,8)
callq 0x22e0
sarl $0x3, %eax
cltd
idivl %r15d
movzwl 0x1a(%r12), %eax
subl %edx, %eax
xorl %ecx, %ecx
testw %ax, %ax
cmovgl %eax, %ecx
movw %cx, 0x1a(%r12)
movapd (%rsp), %xmm0
divsd 0x18(%rsp), %xmm0
addsd 0x88ac(%rip), %xmm0     # 0xd178
callq 0x22d0
cvttsd2si %xmm0, %r15
testl %r15d, %r15d
jle 0x49a4
xorl %ebp, %ebp
leaq 0xebc8(%rip), %r14      # 0x134b0
movzbl 0xe8d1(%rip), %eax      # 0x131c0
movzbl 0xe8ca(%rip), %r13d     # 0x131c1
addl %eax, %r13d
callq 0x22e0
sarl $0x3, %eax
cltd
idivl %r13d
movl %edx, %eax
movzbl 0xe8b1(%rip), %ecx      # 0x131c0
movslq %edx, %rdx
cmpl %ecx, %eax
jge 0x4946
cmpw $0x0, 0xd2(%r12,%rdx,2)
js 0x499b
movw $0xffff, 0xd2(%r12,%rdx,2) # imm = 0xFFFF
movq %rbp, 0x20(%r12,%rdx,8)
movq %rbp, 0x40(%r12,%rdx,8)
testl %ebx, %ebx
jne 0x499b
movl %eax, %edx
leaq 0x96da(%rip), %rsi      # 0xe01e
jmp 0x4976
subq %rcx, %rdx
cmpw $0x0, 0x110(%r12,%rdx,2)
js 0x499b
movw $0xffff, 0x110(%r12,%rdx,2) # imm = 0xFFFF
movw $0x0, 0xc6(%r12,%rdx,2)
testl %ebx, %ebx
jne 0x499b
leaq 0x9696(%rip), %rsi      # 0xe00c
incl %edx
movq %r14, %rdi
xorl %eax, %eax
callq 0x21a0
movq 0xf06f(%rip), %rdi      # 0x139f8
movq %r14, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x2210
callq 0x3d76
decl %r15d
jne 0x48e8
leaq 0xe825(%rip), %r13      # 0x131d0
leaq 0xeafe(%rip), %r14      # 0x134b0
xorl %ebp, %ebp
movl 0x30(%rsp,%rbp,4), %r15d
callq 0x22e0
sarl $0x3, %eax
cltd
idivl %r15d
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
movapd (%rsp), %xmm1
ucomisd %xmm0, %xmm1
jb 0x4a1d
cmpb $0x0, 0xc0(%r12,%rbp)
jne 0x4a1d
movb $0x1, 0xc0(%r12,%rbp)
testl %ebx, %ebx
jne 0x4a1d
movq (%r13), %rdx
movq %r14, %rdi
leaq 0x9635(%rip), %rsi      # 0xe032
xorl %eax, %eax
callq 0x21a0
movq 0xefed(%rip), %rdi      # 0x139f8
movq %r14, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x2210
callq 0x3d76
incq %rbp
addq $0x8, %r13
cmpq $0x4, %rbp
jne 0x49b4
movapd (%rsp), %xmm0
ucomisd 0x8789(%rip), %xmm0     # 0xd1c0
jbe 0x4a57
movq 0x20(%rsp), %rax
leaq 0xebab(%rip), %rcx      # 0x135f0
movq (%rcx,%rax,8), %rax
movabsq $0x40c3880000000000, %rcx # imm = 0x40C3880000000000
movq %rcx, 0x30(%rax)
movsd 0xe751(%rip), %xmm0     # 0x131b0
movl %ebx, %edi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x443f