// File: /workspace/github_cpp_makefile_star2_O2/wrighteagle2d[P]wrighteaglebase/Debug/../src/InterceptModel.cpp
// Function: InterceptModel::CalcGoingThroughSpeed(PlayerState const&, Ray const&, double const&, double)
double InterceptModel::CalcGoingThroughSpeed(const PlayerState &player,
                                             const Ray &ballcourse,
                                             const double &distance,
                                             const double fix) {
  Vector rel_pos = (player.GetPredictedPos() - ballcourse.Origin())
                       .Rotate(-ballcourse.Dir());
  double kick_area = (player.IsGoalie())
                         ? ServerParam::instance().maxCatchableArea()
                         : player.GetKickableArea();
  double peak =
      CalcPeakPoint(rel_pos, player.GetEffectiveSpeedMax(), kick_area, fix);
  double gtspeed = 0.0;

  if (peak < 0) {
    double d = Max(0.0, kick_area * kick_area - rel_pos.Y() * rel_pos.Y());
    gtspeed = rel_pos.X() + Sqrt(d) + 0.06;
    gtspeed = Max(gtspeed, 1.2);
    return gtspeed;
  } else if (peak < distance) {
    double cycletopoint = Dasher::instance().RealCycleNeedToPoint(
        player, ballcourse.GetPoint(peak));
    gtspeed = ServerParam::instance().GetBallSpeed((int)(cycletopoint), peak);

    if (player.IsGoalie() && player.GetUnum() > 0 &&
        player.GetBodyDirConf() > PlayerParam::instance().minValidConf()) {
      Ray ray(player.GetPredictedPos(), player.GetBodyDir());
      Vector pt;
      if (ballcourse.Intersection(Line(ray), pt)) {
        double c2p = Dasher::instance().RealCycleNeedToPoint(player, pt);
        double pk = pt.Dist(ballcourse.Origin());
        double gtspd = ServerParam::instance().GetBallSpeed((int)ceil(c2p), pk);
        gtspeed = Max(gtspeed, gtspd);
      }
    }

    if (gtspeed < ServerParam::instance().ballSpeedMax()) {
      double cycletopoint = Dasher::instance().RealCycleNeedToPoint(
          player, ballcourse.GetPoint(distance));
      double speed = ServerParam::instance().GetBallSpeed(
          (int)ceil(cycletopoint), distance);
      gtspeed = Max(gtspeed, speed);
    }
  } else {
    double cycletopoint = Dasher::instance().RealCycleNeedToPoint(
        player, ballcourse.GetPoint(distance));
    gtspeed =
        ServerParam::instance().GetBallSpeed((int)ceil(cycletopoint), distance);
  }

  return gtspeed;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movsd %xmm0, -0x30(%rbp)
movq %rcx, %rbx
movq %rdx, %r15
movq %rsi, %r14
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0xd4c0
movsd (%rax), %xmm0
movsd 0x8(%rax), %xmm1
subsd (%r15), %xmm0
subsd 0x8(%r15), %xmm1
leaq -0x90(%rbp), %rdi
movsd %xmm0, (%rdi)
movsd %xmm1, 0x8(%rdi)
movsd 0x10(%r15), %xmm0
xorps 0x30a66(%rip), %xmm0    # 0x57020
leaq -0xa8(%rbp), %rsi
movlps %xmm0, (%rsi)
callq 0xd02c
movsd %xmm0, -0x38(%rbp)
movsd %xmm0, -0x70(%rbp)
movsd %xmm1, -0x40(%rbp)
movsd %xmm1, -0x68(%rbp)
cmpb $0x1, 0x175(%r14)
jne 0x265f4
callq 0x3db2c
addq $0x3458, %rax           # imm = 0x3458
jmp 0x265fd
movq (%r14), %rax
movq %r14, %rdi
callq *0x10(%rax)
movsd (%rax), %xmm0
leaq -0x78(%rbp), %rcx
movsd %xmm0, -0x58(%rbp)
movsd %xmm0, (%rcx)
leaq 0x60(%r14), %rdx
leaq -0x70(%rbp), %rsi
movsd -0x30(%rbp), %xmm0
callq 0x262fe
movsd %xmm0, -0x60(%rbp)
xorpd %xmm3, %xmm3
ucomisd %xmm0, %xmm3
jbe 0x2667c
movsd -0x40(%rbp), %xmm1
mulsd %xmm1, %xmm1
movsd -0x58(%rbp), %xmm2
mulsd %xmm2, %xmm2
subsd %xmm1, %xmm2
maxsd %xmm3, %xmm2
sqrtsd %xmm2, %xmm0
movsd -0x38(%rbp), %xmm1
addsd %xmm0, %xmm1
addsd 0x3214a(%rip), %xmm1    # 0x587a8
movsd 0x3214a(%rip), %xmm0    # 0x587b0
maxsd %xmm1, %xmm0
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movsd (%rbx), %xmm1
movsd %xmm1, -0x30(%rbp)
movsd %xmm0, -0x38(%rbp)
callq 0x1a77c
movq %rax, %r12
movsd -0x30(%rbp), %xmm0
ucomisd -0x38(%rbp), %xmm0
jbe 0x268c0
leaq -0x60(%rbp), %r13
movq %r15, %rdi
movq %r13, %rsi
callq 0x1cc1e
pushq $0x1
popq %rdx
movq %r12, %rdi
movq %r14, %rsi
callq 0x1cd4c
movsd %xmm0, -0x30(%rbp)
callq 0x3db2c
cvttsd2si -0x30(%rbp), %ecx
movsd (%r13), %xmm1
mulsd 0x3460(%rax), %xmm1
cmpl $0x63, %ecx
ja 0x266f8
movl %ecx, %ecx
movsd 0x3095d(%rip), %xmm0    # 0x57048
subsd 0x3470(%rax,%rcx,8), %xmm0
divsd %xmm0, %xmm1
cmpb $0x1, 0x175(%r14)
movsd %xmm1, -0x30(%rbp)
jne 0x26834
cmpl $0x0, 0x11c(%r14)
jle 0x26834
movsd 0xc0(%r14), %xmm0
movsd %xmm0, -0x38(%rbp)
callq 0x38d94
movsd -0x38(%rbp), %xmm0
ucomisd 0x31e8(%rax), %xmm0
jbe 0x26834
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0xd4c0
movups (%rax), %xmm0
leaq -0x90(%rbp), %rsi
movaps %xmm0, (%rsi)
movsd 0xb0(%r14), %xmm0
movsd %xmm0, 0x10(%rsi)
xorpd %xmm0, %xmm0
leaq -0x50(%rbp), %r12
movapd %xmm0, (%r12)
leaq -0xa8(%rbp), %r13
movq %r13, %rdi
callq 0x1cc46
movq %r15, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x23566
testb %al, %al
je 0x26834
callq 0x1a77c
movsd -0x50(%rbp), %xmm0
movsd -0x48(%rbp), %xmm1
pushq $0x1
popq %rdx
movq %rax, %rdi
movq %r14, %rsi
callq 0x1cd4c
movsd %xmm0, -0x38(%rbp)
movsd -0x50(%rbp), %xmm0
movsd -0x48(%rbp), %xmm1
subsd (%r15), %xmm0
subsd 0x8(%r15), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
sqrtsd %xmm0, %xmm0
movsd %xmm0, -0x40(%rbp)
callq 0x3db2c
movq %rax, %r12
movsd -0x38(%rbp), %xmm0
callq 0x90f0
movsd -0x40(%rbp), %xmm1
cvttsd2si %xmm0, %eax
mulsd 0x3460(%r12), %xmm1
cmpl $0x63, %eax
ja 0x26826
movl %eax, %eax
movsd 0x30830(%rip), %xmm0    # 0x57048
subsd 0x3470(%r12,%rax,8), %xmm0
divsd %xmm0, %xmm1
movsd -0x30(%rbp), %xmm0
maxsd %xmm0, %xmm1
movsd %xmm1, -0x30(%rbp)
callq 0x3db2c
movsd 0x30f8(%rax), %xmm1
movsd -0x30(%rbp), %xmm0
ucomisd %xmm0, %xmm1
jbe 0x2666a
callq 0x1a77c
movq %rax, %r12
movq %r15, %rdi
movq %rbx, %rsi
callq 0x1cc1e
pushq $0x1
popq %rdx
movq %r12, %rdi
movq %r14, %rsi
callq 0x1cd4c
movsd %xmm0, -0x38(%rbp)
callq 0x3db2c
movq %rax, %r14
movsd -0x38(%rbp), %xmm0
callq 0x90f0
cvttsd2si %xmm0, %eax
movsd (%rbx), %xmm0
mulsd 0x3460(%r14), %xmm0
cmpl $0x63, %eax
ja 0x268b6
movl %eax, %eax
movsd 0x307a0(%rip), %xmm1    # 0x57048
subsd 0x3470(%r14,%rax,8), %xmm1
divsd %xmm1, %xmm0
maxsd -0x30(%rbp), %xmm0
jmp 0x2666a
movq %r15, %rdi
movq %rbx, %rsi
callq 0x1cc1e
pushq $0x1
popq %rdx
movq %r12, %rdi
movq %r14, %rsi
callq 0x1cd4c
movsd %xmm0, -0x30(%rbp)
callq 0x3db2c
movq %rax, %r14
movsd -0x30(%rbp), %xmm0
callq 0x90f0
cvttsd2si %xmm0, %eax
movsd (%rbx), %xmm0
mulsd 0x3460(%r14), %xmm0
cmpl $0x63, %eax
ja 0x2666a
movl %eax, %eax
movsd 0x30734(%rip), %xmm1    # 0x57048
subsd 0x3470(%r14,%rax,8), %xmm1
divsd %xmm1, %xmm0
jmp 0x2666a
nop