// File: /workspace/github_cpp_makefile_star2_O1/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)
cmpl $0x0, 0x668(%r12)
jle 0x2d252
addq $0x18, %r12
jmp 0x2d270
leaq -0x60(%rbp), %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0xf062
movslq (%r13), %rax
shlq $0x4, %rax
addq %rax, %r12
addq $0x8, %r12
movsd (%r12), %xmm0
subsd (%r15), %xmm0
movsd %xmm0, -0x38(%rbp)
movsd 0x8(%r12), %xmm0
subsd 0x8(%r15), %xmm0
movsd %xmm0, -0x30(%rbp)
movsd 0x10(%r15), %xmm0
mulsd 0x3de00(%rip), %xmm0    # 0x6b0a0
divsd 0x3dda0(%rip), %xmm0    # 0x6b048
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 0x2d31e
callq 0x4a75c
addq $0x3458, %rax           # imm = 0x3458
jmp 0x2d327
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 0x2cfa4
movsd %xmm0, -0x78(%rbp)
xorpd %xmm2, %xmm2
ucomisd %xmm0, %xmm2
jbe 0x2d38c
movsd -0x30(%rbp), %xmm1
mulsd %xmm1, %xmm1
movsd -0x48(%rbp), %xmm0
mulsd %xmm0, %xmm0
subsd %xmm1, %xmm0
maxsd %xmm2, %xmm0
ucomisd %xmm2, %xmm0
jb 0x2d48a
sqrtsd %xmm0, %xmm0
jmp 0x2d48f
movsd (%rbx), %xmm1
movsd %xmm1, -0x30(%rbp)
movsd %xmm0, -0x40(%rbp)
callq 0x1f5e8
movq %rax, %r12
movsd -0x30(%rbp), %xmm0
ucomisd -0x40(%rbp), %xmm0
jbe 0x2d4be
movq %rbx, -0x40(%rbp)
leaq -0x78(%rbp), %r13
movq %r15, %rdi
movq %r13, %rsi
callq 0x2abbc
leaq -0x60(%rbp), %rbx
movq %r12, %rdi
movq %r14, %rsi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x21622
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
subsd (%rbx), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0x4a75c
cvttsd2si -0x30(%rbp), %ecx
movsd (%r13), %xmm1
mulsd 0x3460(%rax), %xmm1
cmpl $0x63, %ecx
ja 0x2d420
movl %ecx, %ecx
movsd 0x3dc45(%rip), %xmm0    # 0x6b058
subsd 0x3470(%rax,%rcx,8), %xmm0
divsd %xmm0, %xmm1
cmpb $0x1, 0x175(%r14)
movsd %xmm1, -0x30(%rbp)
jne 0x2d665
cmpl $0x0, 0x11c(%r14)
jle 0x2d665
movsd 0xc0(%r14), %xmm0
movsd %xmm0, -0x38(%rbp)
callq 0x450ba
movsd -0x38(%rbp), %xmm0
ucomisd 0x31e8(%rax), %xmm0
jbe 0x2d665
movq 0x68(%r14), %r12
movl $0x1, -0x60(%rbp)
cmpl $0x0, 0x668(%r12)
jle 0x2d539
addq $0x18, %r12
jmp 0x2d552
callq 0x93c0
movsd -0x38(%rbp), %xmm1
addsd %xmm0, %xmm1
addsd 0x3f348(%rip), %xmm1    # 0x6c7e8
movsd 0x3f348(%rip), %xmm0    # 0x6c7f0
maxsd %xmm1, %xmm0
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rdi
movq %rbx, %rsi
callq 0x2abbc
movq %rbx, %r15
leaq -0x60(%rbp), %rbx
movq %r12, %rdi
movq %r14, %rsi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x21622
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
subsd (%rbx), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0x4a75c
movq %rax, %r14
movsd -0x30(%rbp), %xmm0
callq 0x9100
cvttsd2si %xmm0, %eax
movsd (%r15), %xmm0
mulsd 0x3460(%r14), %xmm0
cmpl $0x63, %eax
ja 0x2d4ac
movl %eax, %eax
movsd 0x3db32(%rip), %xmm1    # 0x6b058
subsd 0x3470(%r14,%rax,8), %xmm1
divsd %xmm1, %xmm0
jmp 0x2d4ac
movq %r12, %rdi
movq %rbx, %rsi
callq 0xf062
movslq (%rbx), %rax
shlq $0x4, %rax
addq %rax, %r12
addq $0x8, %r12
xorpd %xmm0, %xmm0
leaq -0x60(%rbp), %rsi
movapd %xmm0, (%rsi)
movups (%r12), %xmm1
movaps %xmm1, (%rsi)
movsd 0xb0(%r14), %xmm1
movsd %xmm1, 0x10(%rsi)
leaq -0x70(%rbp), %rbx
movapd %xmm0, (%rbx)
leaq -0xa0(%rbp), %r12
movq %r12, %rdi
callq 0x2276a
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x29a2c
testb %al, %al
je 0x2d665
callq 0x1f5e8
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 0x21622
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
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x2d60b
sqrtsd %xmm0, %xmm0
jmp 0x2d610
callq 0x93c0
movsd %xmm0, -0x48(%rbp)
callq 0x4a75c
movq %rax, %r12
movsd -0x38(%rbp), %xmm0
callq 0x9100
cvttsd2si %xmm0, %eax
movsd -0x48(%rbp), %xmm1
mulsd 0x3460(%r12), %xmm1
cmpl $0x63, %eax
ja 0x2d657
movl %eax, %eax
movsd 0x3da0f(%rip), %xmm0    # 0x6b058
subsd 0x3470(%r12,%rax,8), %xmm0
divsd %xmm0, %xmm1
movsd -0x30(%rbp), %xmm0
maxsd %xmm0, %xmm1
movsd %xmm1, -0x30(%rbp)
callq 0x4a75c
movsd 0x30f8(%rax), %xmm1
movsd -0x30(%rbp), %xmm0
ucomisd %xmm0, %xmm1
jbe 0x2d4ac
callq 0x1f5e8
movq %rax, %rbx
movq %r15, %rdi
movq -0x40(%rbp), %r12
movq %r12, %rsi
callq 0x2abbc
leaq -0x60(%rbp), %r15
movq %rbx, %rdi
movq %r14, %rsi
movl $0x1, %edx
movq %r15, %rcx
callq 0x21622
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
subsd (%r15), %xmm0
movsd %xmm0, -0x38(%rbp)
callq 0x4a75c
movq %rax, %r14
movsd -0x38(%rbp), %xmm0
callq 0x9100
cvttsd2si %xmm0, %eax
movsd (%r12), %xmm0
mulsd 0x3460(%r14), %xmm0
cmpl $0x63, %eax
ja 0x2d702
movl %eax, %eax
movsd 0x3d964(%rip), %xmm1    # 0x6b058
subsd 0x3470(%r14,%rax,8), %xmm1
divsd %xmm1, %xmm0
maxsd -0x30(%rbp), %xmm0
jmp 0x2d4ac