// File: /workspace/github_c_makefile_star2_O2/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, %ebp
movl %edx, %r15d
movl %esi, %ebx
callq 0x3a49
movslq %ebx, %r12
leaq 0xe4ec(%rip), %rax      # 0x125e0
movq (%rax,%r12,8), %rax
subsd 0x10(%rax), %xmm0
addsd 0x6f4b(%rip), %xmm0     # 0xb050
callq 0x39cd
divsd 0x6f26(%rip), %xmm0     # 0xb038
addsd 0x6ef6(%rip), %xmm0     # 0xb010
cvttsd2si %xmm0, %rax
cmpl $0x5, %eax
pushq $0x1
popq %r14
cmovnel %eax, %r14d
leaq 0xe7ef(%rip), %rax      # 0x12920
movq (%rax,%r12,8), %rcx
leaq 0xe364(%rip), %rdi      # 0x124a0
leaq 0x7e37(%rip), %rsi      # 0xbf7a
movl %r15d, %edx
movl %r14d, %r8d
xorl %eax, %eax
callq 0x2190
callq 0x399b
testl %ebp, %ebp
je 0x4185
movapd 0x70bf(%rip), %xmm0     # 0xb220
movaps 0x70c8(%rip), %xmm2     # 0xb230
movsd 0x6ef8(%rip), %xmm1     # 0xb068
movsd %xmm1, 0x8(%rsp)
pushq $0x7
popq %rdi
movsd 0x6eef(%rip), %xmm1     # 0xb070
pushq $0x2
jmp 0x41af
movapd 0x7073(%rip), %xmm0     # 0xb200
movaps 0x707c(%rip), %xmm2     # 0xb210
movsd 0x6ebc(%rip), %xmm1     # 0xb058
movsd %xmm1, 0x8(%rsp)
pushq $0xa
popq %rdi
movsd 0x6eb3(%rip), %xmm1     # 0xb060
pushq $0x3
popq %rax
movaps %xmm2, 0x30(%rsp)
leaq 0xe7c4(%rip), %rcx      # 0x12980
movq (%rcx,%r12,8), %r13
movslq %r14d, %rbp
cvtsi2sd %r15d, %xmm4
movsd 0x78(%r13,%rbp,8), %xmm3
mulsd 0x98(%r13,%rbp,8), %xmm3
divsd 0x6e97(%rip), %xmm3     # 0xb078
addsd 0x6e27(%rip), %xmm3     # 0xb010
mulsd %xmm4, %xmm3
movapd %xmm3, %xmm2
divsd %xmm1, %xmm2
addsd 0x8(%r13), %xmm2
movsd %xmm2, 0x8(%r13)
leaq 0xe3d8(%rip), %rcx      # 0x125e0
movq (%rcx,%r12,8), %rcx
movapd %xmm3, 0x10(%rsp)
movapd %xmm3, %xmm1
unpcklpd %xmm3, %xmm1            # xmm1 = xmm1[0],xmm3[0]
divpd %xmm0, %xmm1
movsd 0x20(%rcx), %xmm0
movhpd (%r13), %xmm0           # xmm0 = xmm0[0],mem[0]
subpd %xmm1, %xmm0
xorpd %xmm1, %xmm1
movapd %xmm0, %xmm2
cmpltpd %xmm1, %xmm2
movmskpd %xmm2, %edx
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
testb $0x1, %dl
jne 0x424f
movapd %xmm0, %xmm2
movsd %xmm2, 0x20(%rcx)
testb $0x2, %dl
jne 0x4261
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
movapd %xmm0, %xmm1
decq %rbp
movsd %xmm1, (%r13)
cmpl $0x1, %r14d
movq %r12, 0x28(%rsp)
jne 0x42a5
cvtsi2sd %eax, %xmm0
mulsd 0x6dff(%rip), %xmm0     # 0xb080
addsd 0x6dbf(%rip), %xmm0     # 0xb048
movl %edi, %r14d
movsd %xmm4, 0x20(%rsp)
callq 0x22c0
movsd 0x20(%rsp), %xmm4
movl %r14d, %edi
cvttsd2si %xmm0, %rax
cvtsi2sd %eax, %xmm0
divsd %xmm0, %xmm4
movsd 0xa0(%r13,%rbp,8), %xmm0
subsd %xmm4, %xmm0
xorpd %xmm1, %xmm1
maxsd %xmm0, %xmm1
movsd %xmm1, 0xa0(%r13,%rbp,8)
callq 0x245b
movzwl 0x1a(%r13), %ecx
subl %eax, %ecx
xorl %ebp, %ebp
testw %cx, %cx
cmovlel %ebp, %ecx
movw %cx, 0x1a(%r13)
movapd 0x10(%rsp), %xmm0
divsd 0x8(%rsp), %xmm0
addsd 0x6d4e(%rip), %xmm0     # 0xb048
callq 0x22c0
cvttsd2si %xmm0, %r15
testl %r15d, %r15d
cmovlel %ebp, %r15d
leaq 0x7c94(%rip), %rbp      # 0xbfa6
leaq 0xe187(%rip), %r14      # 0x124a0
leaq 0x7c74(%rip), %r12      # 0xbf94
subl $0x1, %r15d
jb 0x43be
movzbl 0xde7f(%rip), %eax      # 0x121b0
movzbl 0xde79(%rip), %edi      # 0x121b1
addl %eax, %edi
callq 0x245b
movzbl 0xde6a(%rip), %ecx      # 0x121b0
movslq %eax, %rdx
cmpl %ecx, %eax
jge 0x437a
cmpw $0x0, 0xd2(%r13,%rdx,2)
js 0x4320
orw $-0x1, 0xd2(%r13,%rdx,2)
andq $0x0, 0x20(%r13,%rdx,8)
andq $0x0, 0x40(%r13,%rdx,8)
testl %ebx, %ebx
jne 0x4320
movl %eax, %edx
movq %rbp, %rsi
jmp 0x43a8
subq %rcx, %rdx
cmpw $0x0, 0x110(%r13,%rdx,2)
js 0x4320
orw $-0x1, 0x110(%r13,%rdx,2)
andw $0x0, 0xc6(%r13,%rdx,2)
testl %ebx, %ebx
jne 0x4320
movq %r12, %rsi
incl %edx
movq %r14, %rdi
xorl %eax, %eax
callq 0x2190
callq 0x399b
jmp 0x4320
leaq 0xddfb(%rip), %r12      # 0x121c0
leaq 0xe0d4(%rip), %r14      # 0x124a0
leaq 0x7be7(%rip), %r15      # 0xbfba
xorl %ebp, %ebp
movl %ebp, %ebp
cmpq $0x3, %rbp
ja 0x4429
movl 0x30(%rsp,%rbp,4), %edi
callq 0x245b
cvtsi2sd %eax, %xmm0
movapd 0x10(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jb 0x4424
cmpb $0x0, 0xc0(%r13,%rbp)
jne 0x4424
movb $0x1, 0xc0(%r13,%rbp)
testl %ebx, %ebx
jne 0x4424
movq (%r12,%rbp,8), %rdx
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x2190
callq 0x399b
incq %rbp
jmp 0x43d5
movapd 0x10(%rsp), %xmm0
ucomisd 0x6c51(%rip), %xmm0     # 0xb088
jbe 0x4457
movq 0x28(%rsp), %rax
leaq 0xe19b(%rip), %rcx      # 0x125e0
movq (%rcx,%rax,8), %rax
movabsq $0x40c3880000000000, %rcx # imm = 0x40C3880000000000
movq %rcx, 0x30(%rax)
movsd 0xdd41(%rip), %xmm0     # 0x121a0
movl %ebx, %edi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3f26