// File: /workspace/github_cpp_makefile_star2_O2/wrighteagle2d[P]wrighteaglebase/Debug/../src/Dasher.cpp
// Function: Dasher::CycleNeedToPoint(PlayerState const&, Vector, bool, double*)
int Dasher::CycleNeedToPoint(const PlayerState &player, Vector target,
                             bool can_inverse, double *buf) {
  const Vector &pos = player.GetPos();
  const Vector &vel = player.GetVel();

  const double dir = (target - pos).Dir();

  double facing;
  if (player.IsBodyDirValid()) {
    facing = player.GetBodyDir();
  } else if (vel.Mod() > 0.26) {
    facing = vel.Dir();
  } else {
    facing = dir; //认为不用转身
  }

  double diffang = fabs(GetNormalizeAngleDeg(dir - facing));

  if (diffang < 90.0) {
    can_inverse = false; //没有必要倒着跑
  }

  if (can_inverse) {
    if (buf != 0) {
      double tmp;

      int cycle1 =
          CycleNeedToPointWithCertainPosture(player, target, true, buf);
      int cycle2 =
          CycleNeedToPointWithCertainPosture(player, target, false, &tmp);

      if (cycle2 <= cycle1) {
        *buf = tmp;
      }

      return Min(cycle1, cycle2);
    } else {
      int cycle1 = CycleNeedToPointWithCertainPosture(player, target, true);
      int cycle2 = CycleNeedToPointWithCertainPosture(player, target, false);
      return Min(cycle1, cycle2);
    }
  } else {
    return CycleNeedToPointWithCertainPosture(player, target, false, buf);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x28, %rsp
movq %rcx, %rbx
movq %rsi, %r14
movsd %xmm0, -0x28(%rbp)
subsd 0x8(%rsi), %xmm0
movsd %xmm1, -0x20(%rbp)
subsd 0x10(%rsi), %xmm1
movl %edx, %r15d
leaq -0x40(%rbp), %rdi
movsd %xmm0, (%rdi)
movsd %xmm1, 0x8(%rdi)
callq 0xcd30
movapd %xmm0, %xmm2
movsd 0xc0(%r14), %xmm0
ucomisd 0x3c43f(%rip), %xmm0    # 0x58278
jbe 0x1be46
movsd 0xb0(%r14), %xmm0
jmp 0x1be83
movsd 0x30(%r14), %xmm0
movsd 0x38(%r14), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
sqrtsd %xmm0, %xmm0
ucomisd 0x3be2e(%rip), %xmm0    # 0x57c98
movapd %xmm2, %xmm0
jbe 0x1be83
leaq 0x30(%r14), %rdi
movsd %xmm2, -0x30(%rbp)
callq 0xcd30
movsd -0x30(%rbp), %xmm2
subsd %xmm0, %xmm2
movabsq $-0x3f99800000000000, %rax # imm = 0xC066800000000000
leaq -0x40(%rbp), %rdi
movq %rax, (%rdi)
movapd %xmm2, %xmm0
callq 0xd305
andpd 0x3b167(%rip), %xmm0    # 0x57010
movsd 0x3b1d7(%rip), %xmm1    # 0x57088
ucomisd %xmm0, %xmm1
seta %al
xorb $0x1, %r15b
orb %al, %r15b
jne 0x1bf09
pushq $0x1
popq %rdx
movq %r14, %rsi
testq %rbx, %rbx
je 0x1bf25
movsd -0x28(%rbp), %xmm0
movsd -0x20(%rbp), %xmm1
movq %rbx, %rcx
callq 0x1a974
movl %eax, %r15d
leaq -0x40(%rbp), %rcx
movq %r14, %rsi
movsd -0x28(%rbp), %xmm0
movsd -0x20(%rbp), %xmm1
xorl %edx, %edx
callq 0x1a974
cmpl %r15d, %eax
jg 0x1bf4f
movsd -0x40(%rbp), %xmm0
movsd %xmm0, (%rbx)
jmp 0x1bf4f
movq %r14, %rsi
movsd -0x28(%rbp), %xmm0
movsd -0x20(%rbp), %xmm1
xorl %edx, %edx
movq %rbx, %rcx
callq 0x1a974
movl %eax, %r15d
jmp 0x1bf56
movsd -0x28(%rbp), %xmm0
movsd -0x20(%rbp), %xmm1
xorl %ecx, %ecx
callq 0x1a974
movl %eax, %r15d
movq %r14, %rsi
movsd -0x28(%rbp), %xmm0
movsd -0x20(%rbp), %xmm1
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1a974
cmpl %r15d, %eax
cmovll %eax, %r15d
movl %r15d, %eax
addq $0x28, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq