// File: /workspace/github_cpp_makefile_star2_O1/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 0x499b0(%rip), %xmm2    # 0x6b010
movapd %xmm1, %xmm4
andpd %xmm2, %xmm4
movsd 0x499d0(%rip), %xmm3    # 0x6b040
ucomisd %xmm4, %xmm3
jbe 0x21684
andpd %xmm0, %xmm2
xorpd %xmm4, %xmm4
ucomisd %xmm2, %xmm3
ja 0x2169d
callq 0x90d0
movapd %xmm0, %xmm4
mulsd 0x499b3(%rip), %xmm4    # 0x6b048
divsd 0x499b3(%rip), %xmm4    # 0x6b050
movsd 0xc0(%r14), %xmm0
ucomisd 0x4ac1a(%rip), %xmm0    # 0x6c2c8
jbe 0x216bb
movsd 0xb0(%r14), %xmm0
jmp 0x2170e
movsd 0x30(%r14), %xmm0
movsd 0x38(%r14), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
movapd %xmm4, -0x40(%rbp)
jb 0x216e8
sqrtsd %xmm0, %xmm0
jmp 0x216f2
callq 0x93c0
movapd -0x40(%rbp), %xmm4
ucomisd 0x4a5d6(%rip), %xmm0    # 0x6bcd0
movapd %xmm4, %xmm0
jbe 0x2170e
leaq 0x30(%r14), %rdi
callq 0xe804
movapd -0x40(%rbp), %xmm4
subsd %xmm0, %xmm4
movsd 0x49946(%rip), %xmm0    # 0x6b060
ucomisd %xmm4, %xmm0
jbe 0x21734
movsd 0x49948(%rip), %xmm1    # 0x6b070
addsd %xmm1, %xmm4
ucomisd %xmm4, %xmm0
ja 0x21728
jmp 0x21758
ucomisd 0x4990c(%rip), %xmm4    # 0x6b048
jb 0x21758
movsd 0x49922(%rip), %xmm0    # 0x6b068
movsd 0x498fa(%rip), %xmm1    # 0x6b048
addsd %xmm0, %xmm4
ucomisd %xmm1, %xmm4
jae 0x2174e
andpd 0x498b0(%rip), %xmm4    # 0x6b010
movsd 0x49948(%rip), %xmm0    # 0x6b0b0
ucomisd %xmm4, %xmm0
seta %al
xorb $0x1, %r15b
orb %al, %r15b
jne 0x217cc
movq %r14, %rsi
testq %rbx, %rbx
je 0x217ed
movsd -0x20(%rbp), %xmm0
movsd -0x28(%rbp), %xmm1
movl $0x1, %edx
movq %rbx, %rcx
callq 0x1f89c
movl %eax, %r15d
leaq -0x30(%rbp), %rcx
movq %r14, %rsi
movsd -0x20(%rbp), %xmm0
movsd -0x28(%rbp), %xmm1
xorl %edx, %edx
callq 0x1f89c
cmpl %r15d, %eax
jg 0x217c0
movsd -0x30(%rbp), %xmm0
movsd %xmm0, (%rbx)
cmpl %r15d, %eax
cmovll %eax, %r15d
movl %r15d, %eax
jmp 0x21820
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 0x1f89c
movsd -0x20(%rbp), %xmm0
movsd -0x28(%rbp), %xmm1
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x1f89c
movl %eax, %ebx
movq %r14, %rsi
movsd -0x20(%rbp), %xmm0
movsd -0x28(%rbp), %xmm1
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1f89c
cmpl %ebx, %eax
cmovgel %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop