// File: /workspace/github_c_makefile_star2_O1/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, 0x8(%rsp)
movl %edx, %r15d
movl %esi, %ebx
callq 0x3d75
movslq %ebx, %rbp
leaq 0xf0d3(%rip), %rax      # 0x135f0
movq (%rax,%rbp,8), %rax
subsd 0x10(%rax), %xmm0
addsd 0x8b2a(%rip), %xmm0     # 0xd058
movsd %xmm0, 0x10(%rsp)
movsd 0x8ae4(%rip), %xmm2     # 0xd020
divsd %xmm2, %xmm0
leaq 0x30(%rsp), %r14
movq %r14, %rdi
callq 0x22b0
movsd 0x8ad3(%rip), %xmm0     # 0xd028
movsd (%r14), %xmm1
mulsd %xmm0, %xmm1
addsd 0x10(%rsp), %xmm1
addsd %xmm1, %xmm0
movsd 0x8ab0(%rip), %xmm3     # 0xd020
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 0x8a86(%rip), %xmm0     # 0xd030
addsd 0x8aae(%rip), %xmm0     # 0xd060
cvttsd2si %xmm0, %rax
cmpl $0x5, %eax
movl $0x1, %r12d
cmovnel %eax, %r12d
leaq 0xf365(%rip), %rax      # 0x13930
movq (%rax,%rbp,8), %rcx
leaq 0xeeda(%rip), %r13      # 0x134b0
leaq 0x995d(%rip), %rsi      # 0xdf3a
movq %r13, %rdi
movl %r15d, %edx
movl %r12d, %r8d
xorl %eax, %eax
callq 0x21a0
movq 0xf404(%rip), %rdi      # 0x139f8
movq %r13, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x2210
callq 0x3c58
xorl %eax, %eax
cmpl $0x0, 0x8(%rsp)
sete %al
movl $0x3e8, %ecx            # imm = 0x3E8
movl $0x5dc, %edx            # imm = 0x5DC
cmovel %ecx, %edx
movl $0x1f4, %ecx            # imm = 0x1F4
movl $0x2ee, %esi            # imm = 0x2EE
cmovel %ecx, %esi
movl $0x64, %ecx
movl $0x96, %edi
cmovel %ecx, %edi
movl $0x32, %ecx
movl $0x4b, %r8d
cmovel %ecx, %r8d
leal 0x2(%rax), %ecx
leal (%rax,%rax,2), %r9d
addl $0x7, %r9d
movl %r9d, 0x1c(%rsp)
shll $0x3, %eax
leaq 0x8b70(%rip), %r9       # 0xd1d0
movsd (%rax,%r9), %xmm0
movsd %xmm0, 0x10(%rsp)
movl %edx, (%r14)
movl %esi, 0x4(%r14)
movl %edi, 0x8(%r14)
movl %r8d, 0xc(%r14)
leaq 0xf30e(%rip), %rdx      # 0x13990
movq (%rdx,%rbp,8), %r13
xorps %xmm3, %xmm3
cvtsi2sd %r15d, %xmm3
movslq %r12d, %rdx
movsd 0x78(%r13,%rdx,8), %xmm2
mulsd 0x98(%r13,%rdx,8), %xmm2
divsd 0x89be(%rip), %xmm2     # 0xd068
addsd 0x89ae(%rip), %xmm2     # 0xd060
mulsd %xmm3, %xmm2
leaq 0x8b23(%rip), %rsi      # 0xd1e0
movapd %xmm2, %xmm0
divsd (%rax,%rsi), %xmm0
leaq -0x1(%rdx), %r14
addsd 0x8(%r13), %xmm0
movsd %xmm0, 0x8(%r13)
leaq 0x8b13(%rip), %rsi      # 0xd1f0
movapd %xmm2, %xmm0
divsd (%rax,%rsi), %xmm0
movq %rbp, 0x28(%rsp)
leaq 0xeefe(%rip), %rsi      # 0x135f0
movq (%rsi,%rbp,8), %rsi
movsd 0x20(%rsi), %xmm1
subsd %xmm0, %xmm1
xorpd %xmm0, %xmm0
maxsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rsi)
leaq 0x8aed(%rip), %rsi      # 0xd200
movsd %xmm2, 0x8(%rsp)
movapd %xmm2, %xmm0
divsd (%rax,%rsi), %xmm0
movsd (%r13), %xmm1
subsd %xmm0, %xmm1
xorpd %xmm0, %xmm0
maxsd %xmm1, %xmm0
movsd %xmm0, (%r13)
cmpl $0x1, %edx
jne 0x476c
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
mulsd 0x8922(%rip), %xmm0     # 0xd070
addsd 0x88f2(%rip), %xmm0     # 0xd048
movsd %xmm3, 0x20(%rsp)
callq 0x22d0
movsd 0x20(%rsp), %xmm3
cvttsd2si %xmm0, %rcx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
divsd %xmm0, %xmm3
movsd 0xa0(%r13,%r14,8), %xmm0
subsd %xmm3, %xmm0
xorpd %xmm1, %xmm1
maxsd %xmm0, %xmm1
movsd %xmm1, 0xa0(%r13,%r14,8)
callq 0x22e0
sarl $0x3, %eax
cltd
idivl 0x1c(%rsp)
movzwl 0x1a(%r13), %eax
subl %edx, %eax
testw %ax, %ax
movl $0x0, %ecx
cmovgl %eax, %ecx
movw %cx, 0x1a(%r13)
movsd 0x8(%rsp), %xmm0
divsd 0x10(%rsp), %xmm0
addsd 0x8879(%rip), %xmm0     # 0xd048
callq 0x22d0
cvttsd2si %xmm0, %r15
testl %r15d, %r15d
jle 0x48a5
xorl %r12d, %r12d
leaq 0xecc4(%rip), %r14      # 0x134b0
movzbl 0xe9cd(%rip), %eax      # 0x131c0
movzbl 0xe9c7(%rip), %ebp      # 0x131c1
addl %eax, %ebp
callq 0x22e0
sarl $0x3, %eax
cltd
idivl %ebp
movl %edx, %eax
movzbl 0xe9b0(%rip), %ecx      # 0x131c0
movslq %edx, %rdx
cmpl %ecx, %eax
jge 0x4847
cmpw $0x0, 0xd2(%r13,%rdx,2)
js 0x489c
movw $0xffff, 0xd2(%r13,%rdx,2) # imm = 0xFFFF
movq %r12, 0x20(%r13,%rdx,8)
movq %r12, 0x40(%r13,%rdx,8)
testl %ebx, %ebx
jne 0x489c
movl %eax, %edx
leaq 0x9721(%rip), %rsi      # 0xdf66
jmp 0x4877
subq %rcx, %rdx
cmpw $0x0, 0x110(%r13,%rdx,2)
js 0x489c
movw $0xffff, 0x110(%r13,%rdx,2) # imm = 0xFFFF
movw $0x0, 0xc6(%r13,%rdx,2)
testl %ebx, %ebx
jne 0x489c
leaq 0x96dd(%rip), %rsi      # 0xdf54
incl %edx
movq %r14, %rdi
xorl %eax, %eax
callq 0x21a0
movq 0xf16e(%rip), %rdi      # 0x139f8
movq %r14, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x2210
callq 0x3c58
decl %r15d
jne 0x47ec
leaq 0xe924(%rip), %r12      # 0x131d0
leaq 0xebfd(%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
movsd 0x8(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jb 0x491f
cmpb $0x0, 0xc0(%r13,%rbp)
jne 0x491f
movb $0x1, 0xc0(%r13,%rbp)
testl %ebx, %ebx
jne 0x491f
movq (%r12), %rdx
movq %r14, %rdi
leaq 0x967b(%rip), %rsi      # 0xdf7a
xorl %eax, %eax
callq 0x21a0
movq 0xf0eb(%rip), %rdi      # 0x139f8
movq %r14, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x2210
callq 0x3c58
incq %rbp
addq $0x8, %r12
cmpq $0x4, %rbp
jne 0x48b5
movsd 0x8(%rsp), %xmm0
ucomisd 0x873e(%rip), %xmm0     # 0xd078
jbe 0x495a
movq 0x28(%rsp), %rax
leaq 0xeca8(%rip), %rcx      # 0x135f0
movq (%rcx,%rax,8), %rax
movabsq $0x40c3880000000000, %rcx # imm = 0x40C3880000000000
movq %rcx, 0x30(%rax)
movsd 0xe84e(%rip), %xmm0     # 0x131b0
movl %ebx, %edi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4339