// File: 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
subq $0x220, %rsp            # imm = 0x220
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movsd %xmm0, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x188(%rbp)
movq -0x18(%rbp), %rdi
movl $0x1, %esi
callq 0x11fc0
movq %rax, -0x180(%rbp)
movq -0x20(%rbp), %rdi
callq 0x32c70
movq -0x180(%rbp), %rdi
movq %rax, %rsi
callq 0x110a0
movsd %xmm0, -0x50(%rbp)
movsd %xmm1, -0x48(%rbp)
movq -0x20(%rbp), %rdi
callq 0x32c80
movsd (%rax), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x58(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x11110
movsd %xmm0, -0x40(%rbp)
movsd %xmm1, -0x38(%rbp)
movq -0x18(%rbp), %rdi
callq 0x1d780
testb $0x1, %al
jne 0x4ebf1
jmp 0x4ec0c
callq 0x855e0
movq %rax, %rdi
callq 0x4f380
movsd (%rax), %xmm0
movsd %xmm0, -0x190(%rbp)
jmp 0x4ec22
movq -0x18(%rbp), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
movsd (%rax), %xmm0
movsd %xmm0, -0x190(%rbp)
movsd -0x190(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
movq -0x18(%rbp), %rdi
callq 0x1d810
movq -0x188(%rbp), %rdi
movq %rax, %rdx
movsd -0x30(%rbp), %xmm0
leaq -0x40(%rbp), %rsi
leaq -0x60(%rbp), %rcx
callq 0x4e790
movsd %xmm0, -0x68(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x70(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x68(%rbp), %xmm0
jbe 0x4ed81
xorps %xmm0, %xmm0
movsd %xmm0, -0x80(%rbp)
movsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x1a8(%rbp)
movsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x1a0(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x17700
movsd (%rax), %xmm0
movsd %xmm0, -0x1b0(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x17700
movsd -0x1b0(%rbp), %xmm1
movsd -0x1a8(%rbp), %xmm0
movsd -0x1a0(%rbp), %xmm2
mulsd (%rax), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x88(%rbp)
leaq -0x80(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x12a90
movsd (%rax), %xmm0
movsd %xmm0, -0x78(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x176f0
movsd (%rax), %xmm0
movsd %xmm0, -0x198(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x12420
movaps %xmm0, %xmm1
movsd -0x198(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd 0x739d0(%rip), %xmm1    # 0xc2710
addsd %xmm1, %xmm0
movsd %xmm0, -0x70(%rbp)
movsd 0x739b7(%rip), %xmm0    # 0xc2708
movsd %xmm0, -0x90(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x12a90
movsd (%rax), %xmm0
movsd %xmm0, -0x70(%rbp)
movsd -0x70(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x4f18d
movsd -0x68(%rbp), %xmm1
movq -0x28(%rbp), %rax
movsd (%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x4f0de
callq 0x2ec90
movq %rax, -0x1c0(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x1b8(%rbp)
movq -0x20(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x32610
movq -0x1c0(%rbp), %rdi
movq -0x1b8(%rbp), %rsi
movsd %xmm0, -0xa8(%rbp)
movsd %xmm1, -0xa0(%rbp)
movsd -0xa8(%rbp), %xmm0
movsd -0xa0(%rbp), %xmm1
movl $0x1, %edx
callq 0x329f0
movsd %xmm0, -0x98(%rbp)
callq 0x855e0
movq %rax, %rdi
cvttsd2si -0x98(%rbp), %eax
movl %eax, -0xac(%rbp)
leaq -0xac(%rbp), %rsi
leaq -0x68(%rbp), %rdx
callq 0x23dd0
movsd %xmm0, -0x70(%rbp)
movq -0x18(%rbp), %rdi
callq 0x1d780
testb $0x1, %al
jne 0x4ee39
jmp 0x4efea
movq -0x18(%rbp), %rdi
callq 0x1b470
cmpl $0x0, %eax
jle 0x4efea
movq -0x18(%rbp), %rdi
callq 0x32a60
movsd %xmm0, -0x1c8(%rbp)
callq 0x798a0
movq %rax, %rdi
callq 0x1d950
movsd -0x1c8(%rbp), %xmm0
ucomisd (%rax), %xmm0
jbe 0x4efea
movq -0x18(%rbp), %rdi
movl $0x1, %esi
callq 0x11fc0
movq %rax, -0x1d8(%rbp)
movq -0x18(%rbp), %rdi
callq 0x11170
movq -0x1d8(%rbp), %rsi
movq %rax, %rdx
leaq -0xc8(%rbp), %rdi
callq 0x1fde0
xorps %xmm0, %xmm0
movsd %xmm0, -0xe0(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0xe8(%rbp)
leaq -0xd8(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
leaq -0xe8(%rbp), %rdx
callq 0x11a10
movq -0x20(%rbp), %rax
movq %rax, -0x1d0(%rbp)
leaq -0x100(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x32670
movq -0x1d0(%rbp), %rdi
leaq -0x100(%rbp), %rsi
leaq -0xd8(%rbp), %rdx
callq 0x473c0
testb $0x1, %al
jne 0x4ef20
jmp 0x4efe8
callq 0x2ec90
movq %rax, %rdi
movq -0x18(%rbp), %rsi
movq -0xd8(%rbp), %rax
movq %rax, -0x118(%rbp)
movq -0xd0(%rbp), %rax
movq %rax, -0x110(%rbp)
movsd -0x118(%rbp), %xmm0
movsd -0x110(%rbp), %xmm1
movl $0x1, %edx
callq 0x329f0
movsd %xmm0, -0x108(%rbp)
movq -0x20(%rbp), %rdi
callq 0x32c70
movq %rax, %rsi
leaq -0xd8(%rbp), %rdi
callq 0x1d6d0
movsd %xmm0, -0x120(%rbp)
callq 0x855e0
movq %rax, -0x1e0(%rbp)
movsd -0x108(%rbp), %xmm0
callq 0xa110
movq -0x1e0(%rbp), %rdi
cvttsd2si %xmm0, %eax
movl %eax, -0x12c(%rbp)
leaq -0x12c(%rbp), %rsi
leaq -0x120(%rbp), %rdx
callq 0x23dd0
movsd %xmm0, -0x128(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0x128(%rbp), %rsi
callq 0x12a90
movsd (%rax), %xmm0
movsd %xmm0, -0x70(%rbp)
jmp 0x4efea
movsd -0x70(%rbp), %xmm0
movsd %xmm0, -0x1e8(%rbp)
callq 0x855e0
movq %rax, %rdi
callq 0x23d60
movsd -0x1e8(%rbp), %xmm1
movsd (%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x4f0d9
callq 0x2ec90
movq %rax, -0x200(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x1f8(%rbp)
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x32610
movq -0x200(%rbp), %rdi
movq -0x1f8(%rbp), %rsi
movsd %xmm0, -0x148(%rbp)
movsd %xmm1, -0x140(%rbp)
movsd -0x148(%rbp), %xmm0
movsd -0x140(%rbp), %xmm1
movl $0x1, %edx
callq 0x329f0
movsd %xmm0, -0x138(%rbp)
callq 0x855e0
movq %rax, -0x1f0(%rbp)
movsd -0x138(%rbp), %xmm0
callq 0xa110
movq -0x1f0(%rbp), %rdi
cvttsd2si %xmm0, %eax
movl %eax, -0x154(%rbp)
movq -0x28(%rbp), %rdx
leaq -0x154(%rbp), %rsi
callq 0x23dd0
movsd %xmm0, -0x150(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0x12a90
movsd (%rax), %xmm0
movsd %xmm0, -0x70(%rbp)
jmp 0x4f181
callq 0x2ec90
movq %rax, -0x218(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x210(%rbp)
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x32610
movq -0x218(%rbp), %rdi
movq -0x210(%rbp), %rsi
movsd %xmm0, -0x170(%rbp)
movsd %xmm1, -0x168(%rbp)
movsd -0x170(%rbp), %xmm0
movsd -0x168(%rbp), %xmm1
movl $0x1, %edx
callq 0x329f0
movsd %xmm0, -0x160(%rbp)
callq 0x855e0
movq %rax, -0x208(%rbp)
movsd -0x160(%rbp), %xmm0
callq 0xa110
movq -0x208(%rbp), %rdi
cvttsd2si %xmm0, %eax
movl %eax, -0x174(%rbp)
movq -0x28(%rbp), %rdx
leaq -0x174(%rbp), %rsi
callq 0x23dd0
movsd %xmm0, -0x70(%rbp)
jmp 0x4f183
movsd -0x70(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
movsd -0x8(%rbp), %xmm0
addq $0x220, %rsp            # imm = 0x220
popq %rbp
retq
nopl (%rax,%rax)