// File: /workspace/github_cpp_makefile_star2_O3/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
movl %edx, %r15d
movapd %xmm1, %xmm2
movq %rsi, %r14
movsd %xmm0, -0x20(%rbp)
movapd %xmm0, %xmm1
subsd 0x8(%rsi), %xmm1
movsd %xmm2, -0x28(%rbp)
movapd %xmm2, %xmm0
subsd 0x10(%rsi), %xmm0
movapd 0x47fc6(%rip), %xmm2    # 0x69010
movapd %xmm1, %xmm4
andpd %xmm2, %xmm4
movsd 0x47fe6(%rip), %xmm3    # 0x69040
ucomisd %xmm4, %xmm3
jbe 0x2106e
andpd %xmm0, %xmm2
xorpd %xmm4, %xmm4
ucomisd %xmm2, %xmm3
ja 0x21087
callq 0x90d0
movapd %xmm0, %xmm4
mulsd 0x47fc9(%rip), %xmm4    # 0x69048
divsd 0x47fc9(%rip), %xmm4    # 0x69050
movsd 0xc0(%r14), %xmm0
ucomisd 0x49220(%rip), %xmm0    # 0x6a2b8
jbe 0x210a5
movsd 0xb0(%r14), %xmm0
jmp 0x210e2
movsd 0x30(%r14), %xmm0
movsd 0x38(%r14), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
sqrtsd %xmm0, %xmm0
ucomisd 0x48c07(%rip), %xmm0    # 0x69cd0
movapd %xmm4, %xmm0
jbe 0x210e2
leaq 0x30(%r14), %rdi
movapd %xmm4, -0x40(%rbp)
callq 0xe702
movapd -0x40(%rbp), %xmm4
subsd %xmm0, %xmm4
movsd 0x47f72(%rip), %xmm0    # 0x69060
ucomisd %xmm4, %xmm0
jbe 0x21108
movsd 0x47f74(%rip), %xmm1    # 0x69070
addsd %xmm1, %xmm4
ucomisd %xmm4, %xmm0
ja 0x210fc
jmp 0x2112c
ucomisd 0x47f38(%rip), %xmm4    # 0x69048
jb 0x2112c
movsd 0x47f4e(%rip), %xmm0    # 0x69068
movsd 0x47f26(%rip), %xmm1    # 0x69048
addsd %xmm0, %xmm4
ucomisd %xmm1, %xmm4
jae 0x21122
andpd 0x47edc(%rip), %xmm4    # 0x69010
movsd 0x47f74(%rip), %xmm0    # 0x690b0
ucomisd %xmm4, %xmm0
seta %al
xorb $0x1, %r15b
orb %al, %r15b
jne 0x211a0
movq %r14, %rsi
testq %rbx, %rbx
je 0x211c1
movsd -0x20(%rbp), %xmm0
movsd -0x28(%rbp), %xmm1
movl $0x1, %edx
movq %rbx, %rcx
callq 0x1f3e2
movl %eax, %r15d
leaq -0x30(%rbp), %rcx
movq %r14, %rsi
movsd -0x20(%rbp), %xmm0
movsd -0x28(%rbp), %xmm1
xorl %edx, %edx
callq 0x1f3e2
cmpl %r15d, %eax
jg 0x21194
movsd -0x30(%rbp), %xmm0
movsd %xmm0, (%rbx)
cmpl %r15d, %eax
cmovll %eax, %r15d
movl %r15d, %eax
jmp 0x211f4
movq %r14, %rsi
movsd -0x20(%rbp), %xmm0
movsd -0x28(%rbp), %xmm1
xorl %edx, %edx
movq %rbx, %rcx
addq $0x28, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x1f3e2
movsd -0x20(%rbp), %xmm0
movsd -0x28(%rbp), %xmm1
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x1f3e2
movl %eax, %ebx
movq %r14, %rsi
movsd -0x20(%rbp), %xmm0
movsd -0x28(%rbp), %xmm1
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1f3e2
cmpl %ebx, %eax
cmovgel %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop