// File: /workspace/github_cpp_makefile_star2_O3/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, -0x40(%rbp)
movq %rcx, %rbx
movq %rdx, %r15
movq %rsi, %r14
movq 0x68(%rsi), %r12
movl $0x1, -0x60(%rbp)
movl $0x1, %eax
cmpl $0x0, 0x668(%r12)
jg 0x2c8a0
leaq -0x60(%rbp), %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0xef58
movslq (%r13), %rax
shlq $0x4, %rax
movsd 0x8(%r12,%rax), %xmm0
subsd (%r15), %xmm0
movsd %xmm0, -0x38(%rbp)
movsd 0x10(%r12,%rax), %xmm0
subsd 0x8(%r15), %xmm0
movsd %xmm0, -0x30(%rbp)
movsd 0x10(%r15), %xmm0
mulsd 0x3c7cb(%rip), %xmm0    # 0x690a0
divsd 0x3c76b(%rip), %xmm0    # 0x69048
leaq -0x60(%rbp), %r12
leaq -0xa0(%rbp), %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0x92d0
movsd (%r12), %xmm0
movsd (%r13), %xmm1
movsd -0x38(%rbp), %xmm3
movapd %xmm3, %xmm2
mulsd %xmm0, %xmm3
movsd -0x30(%rbp), %xmm4
mulsd %xmm4, %xmm0
mulsd %xmm1, %xmm2
subsd %xmm0, %xmm2
mulsd %xmm1, %xmm4
addsd %xmm3, %xmm4
movsd %xmm2, -0x38(%rbp)
movsd %xmm2, -0x88(%rbp)
movsd %xmm4, -0x30(%rbp)
movsd %xmm4, -0x80(%rbp)
cmpb $0x1, 0x175(%r14)
jne 0x2c953
callq 0x49360
addq $0x3458, %rax           # imm = 0x3458
jmp 0x2c95c
movq (%r14), %rax
movq %r14, %rdi
callq *0x10(%rax)
movsd (%rax), %xmm0
leaq -0xa8(%rbp), %rcx
movsd %xmm0, -0x48(%rbp)
movsd %xmm0, (%rcx)
leaq 0x60(%r14), %rdx
leaq -0x88(%rbp), %rsi
movsd -0x40(%rbp), %xmm0
callq 0x2c5f2
movsd %xmm0, -0x78(%rbp)
xorpd %xmm3, %xmm3
ucomisd %xmm0, %xmm3
jbe 0x2c9e4
movsd -0x30(%rbp), %xmm1
mulsd %xmm1, %xmm1
movsd -0x48(%rbp), %xmm2
mulsd %xmm2, %xmm2
subsd %xmm1, %xmm2
maxsd %xmm3, %xmm2
xorps %xmm0, %xmm0
sqrtsd %xmm2, %xmm0
movsd -0x38(%rbp), %xmm1
addsd %xmm0, %xmm1
addsd 0x3de12(%rip), %xmm1    # 0x6a7d8
movsd 0x3de12(%rip), %xmm0    # 0x6a7e0
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, -0x40(%rbp)
callq 0x1f148
movq %rax, %r12
movsd -0x30(%rbp), %xmm0
ucomisd -0x40(%rbp), %xmm0
jbe 0x2cc92
movq %rbx, -0x40(%rbp)
leaq -0x78(%rbp), %r13
movq %r15, %rdi
movq %r13, %rsi
callq 0x2a27a
leaq -0x60(%rbp), %rbx
movq %r12, %rdi
movq %r14, %rsi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2100c
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
subsd (%rbx), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0x49360
cvttsd2si -0x30(%rbp), %ecx
movsd (%r13), %xmm1
mulsd 0x3460(%rax), %xmm1
cmpl $0x63, %ecx
ja 0x2ca78
movl %ecx, %ecx
movsd 0x3c5ed(%rip), %xmm0    # 0x69058
subsd 0x3470(%rax,%rcx,8), %xmm0
divsd %xmm0, %xmm1
cmpb $0x1, 0x175(%r14)
movsd %xmm1, -0x30(%rbp)
jne 0x2cbeb
cmpl $0x0, 0x11c(%r14)
jle 0x2cbeb
movsd 0xc0(%r14), %xmm0
movsd %xmm0, -0x38(%rbp)
callq 0x43dce
movsd -0x38(%rbp), %xmm0
ucomisd 0x31e8(%rax), %xmm0
jbe 0x2cbeb
movq 0x68(%r14), %r12
movl $0x1, -0x60(%rbp)
movl $0x1, %eax
cmpl $0x0, 0x668(%r12)
jg 0x2cae8
movq %r12, %rdi
movq %rbx, %rsi
callq 0xef58
movslq (%rbx), %rax
shlq $0x4, %rax
movups 0x8(%r12,%rax), %xmm0
leaq -0x60(%rbp), %rsi
movaps %xmm0, (%rsi)
movsd 0xb0(%r14), %xmm0
movsd %xmm0, 0x10(%rsi)
xorpd %xmm0, %xmm0
leaq -0x70(%rbp), %rbx
movapd %xmm0, (%rbx)
leaq -0xa0(%rbp), %r12
movq %r12, %rdi
callq 0x220f2
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x291bc
testb %al, %al
je 0x2cbeb
callq 0x1f148
movsd -0x70(%rbp), %xmm0
movsd -0x68(%rbp), %xmm1
leaq -0xa0(%rbp), %rbx
movq %rax, %rdi
movq %r14, %rsi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2100c
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
subsd (%rbx), %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x70(%rbp), %xmm0
movsd -0x68(%rbp), %xmm1
subsd (%r15), %xmm0
subsd 0x8(%r15), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
sqrtsd %xmm0, %xmm0
movsd %xmm0, -0x48(%rbp)
callq 0x49360
movq %rax, %r12
movsd -0x38(%rbp), %xmm0
callq 0x9100
movsd -0x48(%rbp), %xmm1
cvttsd2si %xmm0, %eax
mulsd 0x3460(%r12), %xmm1
cmpl $0x63, %eax
ja 0x2cbdd
movl %eax, %eax
movsd 0x3c489(%rip), %xmm0    # 0x69058
subsd 0x3470(%r12,%rax,8), %xmm0
divsd %xmm0, %xmm1
movsd -0x30(%rbp), %xmm0
maxsd %xmm0, %xmm1
movsd %xmm1, -0x30(%rbp)
callq 0x49360
movsd 0x30f8(%rax), %xmm1
movsd -0x30(%rbp), %xmm0
ucomisd %xmm0, %xmm1
jbe 0x2c9d2
callq 0x1f148
movq %rax, %rbx
movq %r15, %rdi
movq -0x40(%rbp), %r12
movq %r12, %rsi
callq 0x2a27a
leaq -0x60(%rbp), %r15
movq %rbx, %rdi
movq %r14, %rsi
movl $0x1, %edx
movq %r15, %rcx
callq 0x2100c
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
subsd (%r15), %xmm0
movsd %xmm0, -0x38(%rbp)
callq 0x49360
movq %rax, %r14
movsd -0x38(%rbp), %xmm0
callq 0x9100
cvttsd2si %xmm0, %eax
movsd (%r12), %xmm0
mulsd 0x3460(%r14), %xmm0
cmpl $0x63, %eax
ja 0x2cc88
movl %eax, %eax
movsd 0x3c3de(%rip), %xmm1    # 0x69058
subsd 0x3470(%r14,%rax,8), %xmm1
divsd %xmm1, %xmm0
maxsd -0x30(%rbp), %xmm0
jmp 0x2c9d2
movq %r15, %rdi
movq %rbx, %rsi
callq 0x2a27a
movq %rbx, %r15
leaq -0x60(%rbp), %rbx
movq %r12, %rdi
movq %r14, %rsi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2100c
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
subsd (%rbx), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0x49360
movq %rax, %r14
movsd -0x30(%rbp), %xmm0
callq 0x9100
cvttsd2si %xmm0, %eax
movsd (%r15), %xmm0
mulsd 0x3460(%r14), %xmm0
cmpl $0x63, %eax
ja 0x2c9d2
movl %eax, %eax
movsd 0x3c35a(%rip), %xmm1    # 0x69058
subsd 0x3470(%r14,%rax,8), %xmm1
divsd %xmm1, %xmm0
jmp 0x2c9d2
nop