// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x30, %rsp
movq %rcx, %r12
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
movsd 0x8(%rcx), %xmm1
movsd 0x10(%rcx), %xmm0
subsd 0x8(%rdi), %xmm1
subsd 0x10(%rdi), %xmm0
movapd 0x23d8f(%rip), %xmm2    # 0x6b010
movapd %xmm1, %xmm4
andpd %xmm2, %xmm4
movsd 0x23daf(%rip), %xmm3    # 0x6b040
ucomisd %xmm4, %xmm3
jbe 0x472a5
andpd %xmm0, %xmm2
xorpd %xmm4, %xmm4
ucomisd %xmm2, %xmm3
ja 0x472be
callq 0x90d0
movapd %xmm0, %xmm4
mulsd 0x23d92(%rip), %xmm4    # 0x6b048
divsd 0x23d92(%rip), %xmm4    # 0x6b050
subsd 0xb0(%r15), %xmm4
andpd 0x23d41(%rip), %xmm4    # 0x6b010
movapd %xmm4, -0x40(%rbp)
movsd 0x8(%r12), %xmm0
movsd 0x10(%r12), %xmm1
subsd 0x8(%r15), %xmm0
subsd 0x10(%r15), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x4730a
sqrtsd %xmm0, %xmm0
jmp 0x4730f
callq 0x93c0
movsd %xmm0, -0x28(%rbp)
callq 0x450ba
movq 0x5c38(%rax), %rax
movslq 0x114(%r15), %rcx
imulq $0x3700, %rcx, %rcx     # imm = 0x3700
movsd -0x28(%rbp), %xmm0
subsd 0x3038(%rax,%rcx), %xmm0
movsd %xmm0, -0x28(%rbp)
callq 0x4a75c
movsd -0x28(%rbp), %xmm0
addsd 0x30d8(%rax), %xmm0
movsd %xmm0, -0x28(%rbp)
movapd -0x40(%rbp), %xmm0
divsd 0x23ce3(%rip), %xmm0    # 0x6b048
movapd %xmm0, -0x40(%rbp)
callq 0x450ba
movq 0x5c38(%rax), %rax
movslq 0x114(%r15), %rcx
imulq $0x3700, %rcx, %rcx     # imm = 0x3700
movsd -0x28(%rbp), %xmm0
divsd 0x3040(%rax,%rcx), %xmm0
addsd -0x40(%rbp), %xmm0
mulsd 0x23d09(%rip), %xmm0    # 0x6b0a8
addsd 0x244d1(%rip), %xmm0    # 0x6b878
movsd %xmm0, -0x28(%rbp)
movsd 0x30(%r12), %xmm0
movsd 0x38(%r12), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
ucomisd 0x23cc2(%rip), %xmm0    # 0x6b090
jb 0x473d6
sqrtsd %xmm0, %xmm0
jmp 0x473db
callq 0x93c0
movsd %xmm0, -0x40(%rbp)
callq 0x4a75c
movsd 0x30f8(%rax), %xmm0
movsd %xmm0, -0x48(%rbp)
callq 0x4a75c
movsd -0x48(%rbp), %xmm0
mulsd 0x30e0(%rax), %xmm0
movsd -0x40(%rbp), %xmm1
divsd %xmm0, %xmm1
movsd 0x24463(%rip), %xmm0    # 0x6b878
mulsd %xmm0, %xmm1
addsd %xmm0, %xmm1
movsd -0x28(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
callq 0x450ba
movq 0x5c38(%rax), %rax
movslq 0x114(%r15), %rcx
imulq $0x3700, %rcx, %rcx     # imm = 0x3700
movsd 0x3048(%rax,%rcx), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd (%r14), %xmm0
movsd %xmm0, -0x48(%rbp)
callq 0x4a75c
movsd -0x48(%rbp), %xmm0
divsd 0x3130(%rax), %xmm0
mulsd -0x40(%rbp), %xmm0
mulsd -0x28(%rbp), %xmm0
divsd (%rbx), %xmm0
mulsd 0x23bc3(%rip), %xmm0    # 0x6b048
divsd 0x23bc3(%rip), %xmm0    # 0x6b050
addq $0x30, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq