// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movl %edx, -0xc(%rbp)
movl %ecx, -0x10(%rbp)
movl -0x4(%rbp), %edi
movl -0x8(%rbp), %esi
callq 0x4430
movsd %xmm0, -0x58(%rbp)
movsd -0x58(%rbp), %xmm0
movslq -0x8(%rbp), %rcx
leaq 0x10629(%rip), %rax     # 0x155e0
movq (%rax,%rcx,8), %rax
subsd 0x10(%rax), %xmm0
movsd 0xa0c8(%rip), %xmm1     # 0xf090
addsd %xmm1, %xmm0
callq 0x4380
movsd 0xa067(%rip), %xmm1     # 0xf040
divsd %xmm1, %xmm0
movsd 0xa02b(%rip), %xmm1     # 0xf010
addsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
cvttsd2si -0x58(%rbp), %rax
movl %eax, -0x4c(%rbp)
cmpl $0x5, -0x4c(%rbp)
jne 0x5004
movl $0x1, -0x4c(%rbp)
movl -0xc(%rbp), %edx
movslq -0x8(%rbp), %rcx
leaq 0x1090e(%rip), %rax     # 0x15920
movq (%rax,%rcx,8), %rcx
movl -0x4c(%rbp), %r8d
leaq 0x1047f(%rip), %rdi     # 0x154a0
leaq 0xb010(%rip), %rsi      # 0x10038
movb $0x0, %al
callq 0x2190
callq 0x4320
cmpl $0x0, -0x10(%rbp)
jne 0x5082
movl $0x32, -0x30(%rbp)
movl $0x2, -0x2c(%rbp)
movl $0x14, -0x28(%rbp)
movl $0x3, -0x24(%rbp)
movl $0xa, -0x20(%rbp)
movl $0x3, -0x1c(%rbp)
movl $0x3e8, -0x40(%rbp)     # imm = 0x3E8
movl $0x1f4, -0x3c(%rbp)     # imm = 0x1F4
movl $0x64, -0x38(%rbp)
movl $0x32, -0x34(%rbp)
jmp 0x50c8
movl $0x64, -0x30(%rbp)
movl $0x3, -0x2c(%rbp)
movl $0xa, -0x28(%rbp)
movl $0x2, -0x24(%rbp)
movl $0x7, -0x20(%rbp)
movl $0x6, -0x1c(%rbp)
movl $0x5dc, -0x40(%rbp)     # imm = 0x5DC
movl $0x2ee, -0x3c(%rbp)     # imm = 0x2EE
movl $0x96, -0x38(%rbp)
movl $0x4b, -0x34(%rbp)
movslq -0x8(%rbp), %rcx
leaq 0x108ad(%rip), %rax     # 0x15980
movq (%rax,%rcx,8), %rax
movq %rax, -0x68(%rbp)
movl -0x4c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x4c(%rbp)
cvtsi2sdl -0xc(%rbp), %xmm0
movq -0x68(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movsd 0x80(%rax,%rcx,8), %xmm2
movq -0x68(%rbp), %rax
movslq -0x4c(%rbp), %rcx
mulsd 0xa0(%rax,%rcx,8), %xmm2
movsd 0x9f55(%rip), %xmm1     # 0xf068
divsd %xmm1, %xmm2
movsd 0x9ef1(%rip), %xmm1     # 0xf010
subsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x58(%rbp), %xmm0
cvtsi2sdl -0x30(%rbp), %xmm1
divsd %xmm1, %xmm0
movq -0x68(%rbp), %rax
addsd 0x8(%rax), %xmm0
movsd %xmm0, 0x8(%rax)
movsd -0x58(%rbp), %xmm1
cvtsi2sdl -0x2c(%rbp), %xmm0
divsd %xmm0, %xmm1
movslq -0x8(%rbp), %rcx
leaq 0x1047f(%rip), %rax     # 0x155e0
movq (%rax,%rcx,8), %rax
movsd 0x20(%rax), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rax)
movslq -0x8(%rbp), %rcx
leaq 0x10462(%rip), %rax     # 0x155e0
movq (%rax,%rcx,8), %rax
xorps %xmm0, %xmm0
ucomisd 0x20(%rax), %xmm0
jbe 0x51a3
movslq -0x8(%rbp), %rcx
leaq 0x10449(%rip), %rax     # 0x155e0
movq (%rax,%rcx,8), %rax
xorps %xmm0, %xmm0
movsd %xmm0, 0x20(%rax)
movsd -0x58(%rbp), %xmm1
cvtsi2sdl -0x28(%rbp), %xmm0
divsd %xmm0, %xmm1
movq -0x68(%rbp), %rax
movsd (%rax), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, (%rax)
movq -0x68(%rbp), %rax
xorps %xmm0, %xmm0
ucomisd (%rax), %xmm0
jbe 0x51d9
movq -0x68(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
cmpl $0x0, -0x4c(%rbp)
jne 0x5209
cvtsi2sdl -0x24(%rbp), %xmm0
movsd 0x9eac(%rip), %xmm1     # 0xf098
mulsd %xmm1, %xmm0
movsd 0x9e90(%rip), %xmm1     # 0xf088
addsd %xmm1, %xmm0
callq 0x22c0
cvttsd2si %xmm0, %rax
movl %eax, -0x24(%rbp)
cvtsi2sdl -0xc(%rbp), %xmm1
cvtsi2sdl -0x24(%rbp), %xmm0
divsd %xmm0, %xmm1
movq -0x68(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movsd 0xa0(%rax,%rcx,8), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0xa0(%rax,%rcx,8)
movq -0x68(%rbp), %rax
movslq -0x4c(%rbp), %rcx
xorps %xmm0, %xmm0
ucomisd 0xa0(%rax,%rcx,8), %xmm0
jbe 0x525f
movq -0x68(%rbp), %rax
movslq -0x4c(%rbp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, 0xa0(%rax,%rcx,8)
movslq -0x20(%rbp), %rax
movl %eax, %edi
callq 0x2480
movl %eax, %edx
movq -0x68(%rbp), %rax
movswl 0x1a(%rax), %ecx
subl %edx, %ecx
movw %cx, 0x1a(%rax)
movq -0x68(%rbp), %rax
movswl 0x1a(%rax), %eax
cmpl $0x0, %eax
jge 0x5291
movq -0x68(%rbp), %rax
movw $0x0, 0x1a(%rax)
movsd -0x58(%rbp), %xmm0
cvtsi2sdl -0x1c(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd 0x9de1(%rip), %xmm1     # 0xf088
addsd %xmm1, %xmm0
callq 0x22c0
cvttsd2si %xmm0, %rax
movl %eax, -0x6c(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x6c(%rbp), %eax
jge 0x53ea
movzbl 0xfede(%rip), %eax      # 0x151b0
movzbl 0xfed8(%rip), %ecx      # 0x151b1
addl %ecx, %eax
cltq
movl %eax, %edi
callq 0x2480
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
movzbl 0xfebf(%rip), %ecx      # 0x151b0
cmpl %ecx, %eax
jl 0x5367
movzbl 0xfeb4(%rip), %ecx      # 0x151b0
movl -0x48(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x48(%rbp)
movq -0x68(%rbp), %rax
movslq -0x48(%rbp), %rcx
movswl 0x110(%rax,%rcx,2), %eax
cmpl $0x0, %eax
jl 0x5365
movq -0x68(%rbp), %rax
movslq -0x48(%rbp), %rcx
movw $0xffff, 0x110(%rax,%rcx,2) # imm = 0xFFFF
movq -0x68(%rbp), %rax
movslq -0x48(%rbp), %rcx
movw $0x0, 0xc6(%rax,%rcx,2)
cmpl $0x0, -0x8(%rbp)
jne 0x5363
movl -0x48(%rbp), %edx
addl $0x1, %edx
leaq 0x10150(%rip), %rdi     # 0x154a0
leaq 0xacfb(%rip), %rsi      # 0x10052
movb $0x0, %al
callq 0x2190
callq 0x4320
jmp 0x5365
jmp 0x53da
movq -0x68(%rbp), %rax
movslq -0x48(%rbp), %rcx
movswl 0xd2(%rax,%rcx,2), %eax
cmpl $0x0, %eax
jl 0x53d8
movq -0x68(%rbp), %rax
movslq -0x48(%rbp), %rcx
movw $0xffff, 0xd2(%rax,%rcx,2) # imm = 0xFFFF
movq -0x68(%rbp), %rax
movslq -0x48(%rbp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, 0x20(%rax,%rcx,8)
movq -0x68(%rbp), %rax
movslq -0x48(%rbp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, 0x40(%rax,%rcx,8)
cmpl $0x0, -0x8(%rbp)
jne 0x53d6
movl -0x48(%rbp), %edx
addl $0x1, %edx
leaq 0x100dd(%rip), %rdi     # 0x154a0
leaq 0xac9a(%rip), %rsi      # 0x10064
movb $0x0, %al
callq 0x2190
callq 0x4320
jmp 0x53d8
jmp 0x53da
jmp 0x53dc
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x52bf
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
cmpq $0x3, %rax
jg 0x5493
movsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x78(%rbp)
movl -0x5c(%rbp), %eax
subq $0x0, %rax
movslq -0x40(%rbp,%rax,4), %rax
movl %eax, %edi
callq 0x2480
movsd -0x78(%rbp), %xmm0
cvtsi2sd %eax, %xmm1
ucomisd %xmm1, %xmm0
jb 0x5482
movq -0x68(%rbp), %rax
movl -0x5c(%rbp), %ecx
cmpb $0x0, 0xc0(%rax,%rcx)
jne 0x5480
movq -0x68(%rbp), %rax
movl -0x5c(%rbp), %ecx
movb $0x1, 0xc0(%rax,%rcx)
cmpl $0x0, -0x8(%rbp)
jne 0x547e
movl -0x5c(%rbp), %eax
movl %eax, %ecx
subq $0x0, %rcx
leaq 0xfd60(%rip), %rax      # 0x151c0
movq (%rax,%rcx,8), %rdx
leaq 0x10035(%rip), %rdi     # 0x154a0
leaq 0xac06(%rip), %rsi      # 0x10078
movb $0x0, %al
callq 0x2190
callq 0x4320
jmp 0x5480
jmp 0x5482
jmp 0x5484
movl -0x5c(%rbp), %eax
addq $0x1, %rax
movl %eax, -0x5c(%rbp)
jmp 0x53f1
movsd -0x58(%rbp), %xmm0
movsd 0x9c00(%rip), %xmm1     # 0xf0a0
ucomisd %xmm1, %xmm0
jbe 0x54c2
movslq -0x8(%rbp), %rcx
leaq 0x1012f(%rip), %rax     # 0x155e0
movq (%rax,%rcx,8), %rax
movsd 0x9beb(%rip), %xmm0     # 0xf0a8
movsd %xmm0, 0x30(%rax)
movl -0x8(%rbp), %edi
movsd 0xfcd3(%rip), %xmm0     # 0x151a0
callq 0x4b30
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax,%rax)