// File: 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
subq $0x100, %rsp            # imm = 0x100
movb %dl, %al
movsd %xmm0, -0x18(%rbp)
movsd %xmm1, -0x10(%rbp)
movq %rdi, -0x20(%rbp)
movq %rsi, -0x28(%rbp)
andb $0x1, %al
movb %al, -0x29(%rbp)
movq %rcx, -0x38(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq -0x28(%rbp), %rdi
addq $0x8, %rdi
callq 0x11090
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rdi
callq 0x10a80
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rsi
leaq -0x18(%rbp), %rdi
callq 0x110a0
movsd %xmm0, -0x60(%rbp)
movsd %xmm1, -0x58(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x10520
movsd %xmm0, -0x50(%rbp)
movq -0x28(%rbp), %rdi
callq 0x32880
testb $0x1, %al
jne 0x310f5
jmp 0x31109
movq -0x28(%rbp), %rdi
callq 0x11170
movsd (%rax), %xmm0
movsd %xmm0, -0x68(%rbp)
jmp 0x3113c
movq -0x48(%rbp), %rdi
callq 0x104e0
movsd 0x90b46(%rip), %xmm1    # 0xc1c60
ucomisd %xmm1, %xmm0
jbe 0x31130
movq -0x48(%rbp), %rdi
callq 0x10520
movsd %xmm0, -0x68(%rbp)
jmp 0x3113a
movsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
jmp 0x3113c
movsd -0x50(%rbp), %xmm0
subsd -0x68(%rbp), %xmm0
movsd 0x8fee2(%rip), %xmm1    # 0xc1030
movsd %xmm1, -0x78(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x116b0
movaps 0x8fefd(%rip), %xmm1    # 0xc1060
pand %xmm1, %xmm0
movsd %xmm0, -0x70(%rbp)
movsd 0x8fecc(%rip), %xmm0    # 0xc1040
ucomisd -0x70(%rbp), %xmm0
jbe 0x3117f
movb $0x0, -0x29(%rbp)
testb $0x1, -0x29(%rbp)
je 0x312f4
cmpq $0x0, -0x38(%rbp)
je 0x31253
movq -0xf8(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x18(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x38(%rbp), %rcx
movsd -0x98(%rbp), %xmm0
movsd -0x90(%rbp), %xmm1
movl $0x1, %edx
callq 0x2ef50
movq -0xf8(%rbp), %rdi
movl %eax, -0x84(%rbp)
movq -0x28(%rbp), %rsi
movq -0x18(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xa8(%rbp)
movsd -0xb0(%rbp), %xmm0
movsd -0xa8(%rbp), %xmm1
xorl %edx, %edx
leaq -0x80(%rbp), %rcx
callq 0x2ef50
movl %eax, -0x9c(%rbp)
movl -0x9c(%rbp), %eax
cmpl -0x84(%rbp), %eax
jg 0x31236
movsd -0x80(%rbp), %xmm0
movq -0x38(%rbp), %rax
movsd %xmm0, (%rax)
leaq -0x84(%rbp), %rdi
leaq -0x9c(%rbp), %rsi
callq 0x13150
movl (%rax), %eax
movl %eax, -0x4(%rbp)
jmp 0x31333
movq -0xf8(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x18(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xc0(%rbp)
movsd -0xc8(%rbp), %xmm0
movsd -0xc0(%rbp), %xmm1
movl $0x1, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0x2ef50
movq -0xf8(%rbp), %rdi
movl %eax, -0xb4(%rbp)
movq -0x28(%rbp), %rsi
movq -0x18(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xd8(%rbp)
movsd -0xe0(%rbp), %xmm0
movsd -0xd8(%rbp), %xmm1
xorl %edx, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0x2ef50
movl %eax, -0xcc(%rbp)
leaq -0xb4(%rbp), %rdi
leaq -0xcc(%rbp), %rsi
callq 0x13150
movl (%rax), %eax
movl %eax, -0x4(%rbp)
jmp 0x31333
movq -0xf8(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x18(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0x38(%rbp), %rcx
movsd -0xf0(%rbp), %xmm0
movsd -0xe8(%rbp), %xmm1
xorl %edx, %edx
callq 0x2ef50
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
nop