// File: wrighteagle2d[P]wrighteaglebase/Debug/../src/PlayerState.cpp
// Function: PlayerState::GetRandAngle(double const&, double const&, BallState const&) const
AngleDeg PlayerState::GetRandAngle(const double &power, const double &vel,
                                   const BallState &bs) const {

  double dir_diff = fabs((bs.GetPos() - GetPos()).Dir() - GetBodyDir());
  Vector tmp = bs.GetPos() - GetPos();
  double dist_ball =
      (tmp.Mod() - GetPlayerSize() - -ServerParam::instance().ballSize());

  double pos_rate =
      0.5 + 0.25 * (dir_diff / 180 + dist_ball / GetKickableMargin());
  // [0.5, 1.0]
  double speed_rate =
      0.5 + 0.5 * (bs.GetVel().Mod() / (ServerParam::instance().ballSpeedMax() *
                                        ServerParam::instance().ballDecay()));
  // [0, 2*kick_rand]
  double max_rand = GetKickRand() *
                    (power / ServerParam::instance().maxPower()) *
                    (pos_rate + speed_rate);

  return Rad2Deg(max_rand / vel);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x20(%rbp), %rdi
addq $0x8, %rdi
callq 0x11090
movq -0x88(%rbp), %rdi
movq %rax, -0xd0(%rbp)
addq $0x8, %rdi
callq 0x11090
movq -0xd0(%rbp), %rdi
movq %rax, %rsi
callq 0x110a0
movsd %xmm0, -0x38(%rbp)
movsd %xmm1, -0x30(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x10520
movq -0x88(%rbp), %rdi
movsd %xmm0, -0xc8(%rbp)
callq 0x11170
movsd -0xc8(%rbp), %xmm0
subsd (%rax), %xmm0
movaps 0x444ed(%rip), %xmm1    # 0xc1060
pand %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movq -0x20(%rbp), %rdi
addq $0x8, %rdi
callq 0x11090
movq -0x88(%rbp), %rdi
movq %rax, -0xc0(%rbp)
addq $0x8, %rdi
callq 0x11090
movq -0xc0(%rbp), %rdi
movq %rax, %rsi
callq 0x110a0
movsd %xmm0, -0x48(%rbp)
movsd %xmm1, -0x40(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x104e0
movq -0x88(%rbp), %rdi
movsd %xmm0, -0xb8(%rbp)
callq 0x57020
movsd -0xb8(%rbp), %xmm0
subsd (%rax), %xmm0
movsd %xmm0, -0xb0(%rbp)
callq 0x855e0
movq %rax, %rdi
callq 0x12f10
movsd -0xb0(%rbp), %xmm0
movq -0x88(%rbp), %rdi
movsd (%rax), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x28(%rbp), %xmm0
movsd 0x443f1(%rip), %xmm1    # 0xc1028
divsd %xmm1, %xmm0
movsd %xmm0, -0xa0(%rbp)
movsd -0x50(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
callq 0x56fe0
movsd -0xa8(%rbp), %xmm1
movsd -0xa0(%rbp), %xmm0
divsd (%rax), %xmm1
addsd %xmm1, %xmm0
movsd 0x443c3(%rip), %xmm1    # 0xc1038
mulsd %xmm1, %xmm0
movsd 0x4439f(%rip), %xmm1    # 0xc1020
addsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
movq -0x20(%rbp), %rdi
callq 0x10a80
movq %rax, %rdi
callq 0x104e0
movsd %xmm0, -0x90(%rbp)
callq 0x855e0
movq %rax, %rdi
callq 0x23d60
movsd (%rax), %xmm0
movsd %xmm0, -0x98(%rbp)
callq 0x855e0
movq %rax, %rdi
callq 0x113d0
movsd -0x98(%rbp), %xmm1
movsd -0x90(%rbp), %xmm0
movq -0x88(%rbp), %rdi
mulsd (%rax), %xmm1
divsd %xmm1, %xmm0
movsd 0x44330(%rip), %xmm1    # 0xc1020
mulsd %xmm1, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
callq 0x7d650
movsd (%rax), %xmm0
movsd %xmm0, -0x78(%rbp)
movq -0x10(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x80(%rbp)
callq 0x855e0
movq %rax, %rdi
callq 0x10f10
movsd -0x80(%rbp), %xmm1
movsd -0x78(%rbp), %xmm0
divsd (%rax), %xmm1
mulsd %xmm1, %xmm0
movsd -0x58(%rbp), %xmm1
addsd -0x60(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x68(%rbp), %xmm0
movq -0x18(%rbp), %rax
divsd (%rax), %xmm0
movsd %xmm0, -0x70(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x124d0
addq $0xd0, %rsp
popq %rbp
retq
nop