// File: /workspace/github_cpp_makefile_star2_O1/wrighteagle2d[P]wrighteaglebase/Debug/../src/Tackler.cpp
// Function: Tackler::GetTackleInfoToDir(Agent const&, double, double*, Vector*)
bool Tackler::GetTackleInfoToDir(const Agent &agent, AngleDeg dir,
                                 AngleDeg *p_tackle_angle, Vector *p_ball_vel) {
  UpdateTackleData(agent);

  Array<int, 3> dir_idx;

  dir_idx[0] = dir2idx(dir);       //当前区间
  dir_idx[1] = dir2idx(dir - 1.0); //左边相邻区间
  dir_idx[2] = dir2idx(dir + 1.0); //右边相邻区间

  Vector optimal_ball_vel;
  AngleDeg best_tackle_angle = 0.0;
  double max_ball_speed = -1.0;
  bool ret = false;

  for (int j = 0; j < 3; ++j) {
    for (uint i = 0; i < mDirMap[dir_idx[j]].size(); ++i) {
      const int angle_idx1 = mDirMap[dir_idx[j]][i].first;
      const int angle_idx2 = mDirMap[dir_idx[j]][i].second;

      AngleDeg dir1 = mBallVelAfterTackle[angle_idx1].Dir();
      AngleDeg dir2 = mBallVelAfterTackle[angle_idx2].Dir();

      if (IsAngleDegInBetween(dir1, dir, dir2)) {
        ret = true;

        if (p_tackle_angle ||
            p_ball_vel) { //这里要找出使出球速度最大的tackle_angle
          dir2 = GetNormalizeAngleDeg(dir2, dir1);
          dir = GetNormalizeAngleDeg(dir, dir1);

          double rate = (dir2 - dir) / (dir2 - dir1);
          Vector ball_vel = mBallVelAfterTackle[angle_idx1] * rate +
                            mBallVelAfterTackle[angle_idx2] * (1.0 - rate);
          double ball_speed = ball_vel.Mod();

          if (ball_speed > max_ball_speed) {
            optimal_ball_vel = ball_vel;
            max_ball_speed = ball_speed;
            best_tackle_angle = mTackleAngle[angle_idx1] * rate +
                                mTackleAngle[angle_idx2] * (1.0 - rate);
          }

          continue;
        }

        return true;
      }
    }
  }

  if (ret) {
    if (p_ball_vel) {
      *p_ball_vel = optimal_ball_vel;
    }

    if (p_tackle_angle) {
      *p_tackle_angle = best_tackle_angle;
    }
  }

  return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rcx, %r14
movq %rdx, %rbx
movsd %xmm0, -0x38(%rbp)
movq %rdi, -0x70(%rbp)
callq 0x4df58
movsd -0x38(%rbp), %xmm3
xorpd %xmm1, %xmm1
ucomisd %xmm3, %xmm1
jbe 0x4e7e1
movsd 0x1c89f(%rip), %xmm2    # 0x6b070
movapd %xmm3, %xmm0
addsd %xmm2, %xmm0
ucomisd %xmm0, %xmm1
ja 0x4e7d5
jmp 0x4e80d
ucomisd 0x1c887(%rip), %xmm3    # 0x6b070
movapd %xmm3, %xmm0
jb 0x4e80d
movsd 0x1c871(%rip), %xmm1    # 0x6b068
movsd 0x1c871(%rip), %xmm2    # 0x6b070
movapd %xmm3, %xmm0
addsd %xmm1, %xmm0
ucomisd %xmm2, %xmm0
jae 0x4e803
callq 0x96b0
cvttsd2si %xmm0, %eax
movl %eax, -0x8c(%rbp)
movsd 0x1c874(%rip), %xmm0    # 0x6b098
addsd -0x38(%rbp), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
jbe 0x4e847
movsd 0x1c835(%rip), %xmm2    # 0x6b070
addsd %xmm2, %xmm0
ucomisd %xmm0, %xmm1
ja 0x4e83b
jmp 0x4e86b
ucomisd 0x1c821(%rip), %xmm0    # 0x6b070
jb 0x4e86b
movsd 0x1c80f(%rip), %xmm1    # 0x6b068
movsd 0x1c80f(%rip), %xmm2    # 0x6b070
addsd %xmm1, %xmm0
ucomisd %xmm2, %xmm0
jae 0x4e861
callq 0x96b0
cvttsd2si %xmm0, %eax
movl %eax, -0x88(%rbp)
movsd 0x1c7d6(%rip), %xmm0    # 0x6b058
addsd -0x38(%rbp), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
jbe 0x4e8a5
movsd 0x1c7d7(%rip), %xmm2    # 0x6b070
addsd %xmm2, %xmm0
ucomisd %xmm0, %xmm1
ja 0x4e899
jmp 0x4e8c9
ucomisd 0x1c7c3(%rip), %xmm0    # 0x6b070
jb 0x4e8c9
movsd 0x1c7b1(%rip), %xmm1    # 0x6b068
movsd 0x1c7b1(%rip), %xmm2    # 0x6b070
addsd %xmm1, %xmm0
ucomisd %xmm2, %xmm0
jae 0x4e8bf
callq 0x96b0
cvttsd2si %xmm0, %eax
movl %eax, -0x84(%rbp)
movq -0x70(%rbp), %rax
leaq 0x2200(%rax), %r15
addq $0xb58, %rax            # imm = 0xB58
movq %rax, -0xc8(%rbp)
movq %rbx, -0xa0(%rbp)
movq %r14, -0x98(%rbp)
orq %r14, %rbx
setne -0x29(%rbp)
movsd 0x1c78b(%rip), %xmm0    # 0x6b098
movsd %xmm0, -0x78(%rbp)
xorl %ecx, %ecx
movq $0x0, -0x50(%rbp)
xorpd %xmm0, %xmm0
movsd %xmm0, -0x68(%rbp)
movq $0x0, -0x80(%rbp)
movsd %xmm0, -0x60(%rbp)
movsd %xmm0, -0x58(%rbp)
movq %r15, -0x40(%rbp)
movq -0xc8(%rbp), %r13
movq %rcx, -0xa8(%rbp)
leaq -0x8c(,%rcx,4), %rbx
addq %rbp, %rbx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x4f084
movq 0x8(%rax), %rcx
cmpq (%rax), %rcx
setne %al
je 0x4ec2d
xorl %r12d, %r12d
movq %rbx, -0xd0(%rbp)
movb %al, -0x2a(%rbp)
movq %r15, %rdi
movq %rbx, %rsi
callq 0x4f084
movq (%rax), %rax
movslq (%rax,%r12,8), %r14
movq %r15, %rdi
movq %rbx, %rsi
callq 0x4f084
movq (%rax), %rax
movslq 0x4(%rax,%r12,8), %rbx
movq %r14, -0xd8(%rbp)
shlq $0x4, %r14
addq %r13, %r14
movq %r14, %rdi
callq 0xe804
movsd %xmm0, -0x48(%rbp)
movq %rbx, %r15
shlq $0x4, %r15
addq %r13, %r15
movq %r15, %rdi
callq 0xe804
movsd -0x48(%rbp), %xmm7
movsd -0x38(%rbp), %xmm4
ucomisd %xmm4, %xmm7
jbe 0x4e9fe
movapd %xmm4, %xmm1
movsd 0x1c686(%rip), %xmm5    # 0x6b070
movsd 0x1c676(%rip), %xmm6    # 0x6b068
addsd %xmm5, %xmm1
ucomisd %xmm1, %xmm7
ja 0x4e9f2
jmp 0x4ea2e
movapd %xmm7, %xmm2
movsd 0x1c666(%rip), %xmm5    # 0x6b070
addsd %xmm5, %xmm2
ucomisd %xmm2, %xmm4
movapd %xmm4, %xmm1
movsd 0x1c64a(%rip), %xmm6    # 0x6b068
jb 0x4ea2e
movapd %xmm4, %xmm1
addsd %xmm6, %xmm1
ucomisd %xmm2, %xmm1
jae 0x4ea24
ucomisd %xmm0, %xmm7
jbe 0x4ea44
movapd %xmm0, %xmm2
addsd %xmm5, %xmm2
ucomisd %xmm2, %xmm7
ja 0x4ea38
jmp 0x4ea64
movapd %xmm7, %xmm3
addsd %xmm5, %xmm3
ucomisd %xmm3, %xmm0
movapd %xmm0, %xmm2
jb 0x4ea64
movapd %xmm0, %xmm2
addsd %xmm6, %xmm2
ucomisd %xmm3, %xmm2
jae 0x4ea5a
xorl %eax, %eax
ucomisd %xmm1, %xmm2
jb 0x4eb22
movl $0x1, %eax
movb $0x1, %cl
movq %rcx, -0x80(%rbp)
cmpb $0x0, -0x29(%rbp)
je 0x4eb22
ucomisd %xmm0, %xmm7
jbe 0x4eb69
addsd %xmm5, %xmm0
ucomisd %xmm0, %xmm7
ja 0x4ea8f
ucomisd %xmm4, %xmm7
jbe 0x4eb81
addsd %xmm5, %xmm4
ucomisd %xmm4, %xmm7
ja 0x4eaa3
movapd %xmm0, %xmm3
subsd %xmm4, %xmm3
subsd %xmm7, %xmm0
divsd %xmm0, %xmm3
movsd (%r14), %xmm0
mulsd %xmm3, %xmm0
movsd 0x8(%r14), %xmm1
mulsd %xmm3, %xmm1
movsd 0x1c580(%rip), %xmm2    # 0x6b058
subsd %xmm3, %xmm2
movsd (%r15), %xmm5
mulsd %xmm2, %xmm5
addsd %xmm0, %xmm5
movsd 0x8(%r15), %xmm6
mulsd %xmm2, %xmm6
addsd %xmm1, %xmm6
movapd %xmm6, %xmm1
mulsd %xmm6, %xmm1
movapd %xmm5, %xmm0
mulsd %xmm5, %xmm0
addsd %xmm1, %xmm0
ucomisd 0x1c57d(%rip), %xmm0    # 0x6b090
jb 0x4eb99
sqrtsd %xmm0, %xmm0
jmp 0x4ebe2
movq -0x40(%rbp), %r15
movsd %xmm4, -0x38(%rbp)
cmpl $0x7, %eax
movq -0xd0(%rbp), %rbx
je 0x4eb3f
testl %eax, %eax
jne 0x4ec2a
incl %r12d
movq %r15, %rdi
movq %rbx, %rsi
callq 0x4f084
movq 0x8(%rax), %rcx
subq (%rax), %rcx
sarq $0x3, %rcx
cmpq %r12, %rcx
seta %al
ja 0x4e979
jmp 0x4ec2d
movapd %xmm7, %xmm1
addsd %xmm5, %xmm1
ucomisd %xmm1, %xmm0
jb 0x4ea99
addsd %xmm6, %xmm0
jmp 0x4eb71
movapd %xmm7, %xmm1
addsd %xmm5, %xmm1
ucomisd %xmm1, %xmm4
jb 0x4eaad
addsd %xmm6, %xmm4
jmp 0x4eb89
movsd %xmm4, -0x38(%rbp)
movsd %xmm3, -0x48(%rbp)
movsd %xmm2, -0xc0(%rbp)
movsd %xmm5, -0xb8(%rbp)
movsd %xmm6, -0xb0(%rbp)
callq 0x93c0
movsd -0xb0(%rbp), %xmm6
movsd -0xb8(%rbp), %xmm5
movsd -0xc0(%rbp), %xmm2
movsd -0x48(%rbp), %xmm3
movsd -0x38(%rbp), %xmm4
movq -0x40(%rbp), %r15
movl $0x7, %eax
ucomisd -0x78(%rbp), %xmm0
jbe 0x4eb26
movq -0x70(%rbp), %rcx
mulsd 0x10(%rcx,%rbx,8), %xmm2
movq -0xd8(%rbp), %rdx
mulsd 0x10(%rcx,%rdx,8), %xmm3
addsd %xmm2, %xmm3
movsd %xmm5, -0x58(%rbp)
movsd %xmm6, -0x60(%rbp)
movsd %xmm0, -0x78(%rbp)
movsd %xmm3, -0x68(%rbp)
jmp 0x4eb26
movb -0x2a(%rbp), %al
testb $0x1, %al
movq -0xa8(%rbp), %rax
jne 0x4ec54
cmpq $0x2, %rax
leaq 0x1(%rax), %rax
setae %cl
movq %rcx, -0x50(%rbp)
movq %rax, %rcx
cmpq $0x3, %rax
jne 0x4e942
testb $0x1, -0x50(%rbp)
je 0x4ec96
movq -0x80(%rbp), %rax
testb $0x1, %al
je 0x4ec98
movq -0x98(%rbp), %rax
testq %rax, %rax
je 0x4ec81
movsd -0x58(%rbp), %xmm0
movsd %xmm0, (%rax)
movsd -0x60(%rbp), %xmm0
movsd %xmm0, 0x8(%rax)
movq -0xa0(%rbp), %rax
testq %rax, %rax
je 0x4ec96
movsd -0x68(%rbp), %xmm0
movsd %xmm0, (%rax)
movb $0x1, %al
andb $0x1, %al
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq