// File: /workspace/github_cpp_makefile_star2_O3/wrighteagle2d[P]wrighteaglebase/Debug/../src/WorldState.cpp
// Function: WorldStateUpdater::UpdateMostSimilarPlayer(Vector const&, int)
bool WorldStateUpdater::UpdateMostSimilarPlayer(const Vector &pos, int index) {
  bool is_known_side = mpObserver->UnknownPlayer(index).IsKnownSide();
  int least_num = mpObserver->UnknownPlayerBugInfo(index).mLeastNum;

  int min_index = 0;
  double min = 100000;

  if (is_known_side) {
    if (mpObserver->UnknownPlayer(index).Side() !=
        mpObserver->UnknownPlayerBugInfo(index).mSide) {
      least_num = 1;
    }
    for (int i = least_num; i <= TEAMSIZE; i++) {
      const PlayerState &player =
          mpObserver->UnknownPlayer(index).Side() == mSelfSide
              ? mpWorldState->GetTeammate(i)
              : mpWorldState->GetOpponent(i);
      if (player.GetPosDelay() != 0 && (player.GetPos() - pos).Mod() < min) {
        min = (player.GetPos() - pos).Mod();
        min_index = player.GetUnum();
      }
    }
  } else {
    for (int i = 1; i <= TEAMSIZE; i++) {
      const PlayerState &player =
          mpObserver->UnknownPlayerBugInfo(index).mSide == mSelfSide
              ? mpWorldState->GetTeammate(i)
              : mpWorldState->GetOpponent(i);
      const PlayerState &opp_player =
          mpObserver->UnknownPlayerBugInfo(index).mSide == mSelfSide
              ? mpWorldState->GetOpponent(i)
              : mpWorldState->GetTeammate(i);
      if (i >= least_num) {
        if (player.GetPosDelay() != 0 && (player.GetPos() - pos).Mod() < min) {
          min = (player.GetPos() - pos).Mod();
          min_index = player.GetUnum();
        }
      }

      if (opp_player.GetPosDelay() != 0 &&
          (opp_player.GetPos() - pos).Mod() < min) {
        min = (opp_player.GetPos() - pos).Mod();
        min_index = opp_player.GetUnum();
      }
    }
  }

  if (min_index != 0) {
    bool is_teammate = min_index > 0;
    this->UpdateSpecificUnknownPlayer(mpObserver->UnknownPlayer(index),
                                      abs(min_index), is_teammate);
    return true;
  } else {
    return false;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rsi, %rcx
movq (%rdi), %rax
movslq %edx, %rdx
imulq $0x2e8ba2e9, %rdx, %rsi # imm = 0x2E8BA2E9
movq %rsi, %r8
shrq $0x3f, %r8
sarq $0x22, %rsi
addl %r8d, %esi
leal (%rsi,%rsi,4), %r8d
leal (%rsi,%r8,4), %r8d
addl %esi, %r8d
movl %edx, %esi
subl %r8d, %esi
movslq %esi, %rsi
imulq $0x70, %rsi, %rsi
addq %rax, %rsi
addq $0x2840, %rsi           # imm = 0x2840
shlq $0x4, %rdx
addq %rdx, %rax
addq $0x31e4, %rax           # imm = 0x31E4
movslq 0x4(%rax), %rdx
cmpb $0x0, 0x40(%rsi)
je 0x658bf
movb 0x41(%rsi), %r8b
cmpb (%rax), %r8b
movl $0x1, %r9d
cmovel %edx, %r9d
xorl %eax, %eax
cmpl $0xb, %r9d
jg 0x659b3
movslq %r9d, %rdx
imulq $0x178, %rdx, %r9       # imm = 0x178
leaq 0x10d0(%r9), %r10
addq $0xa8, %r9
cmpb 0x10(%rdi), %r8b
movq 0x8(%rdi), %r8
movsd (%rcx), %xmm0
cmovneq %r10, %r9
movsd 0x8(%rcx), %xmm1
leaq (%r9,%r8), %rcx
addq $-0x170, %rcx           # imm = 0xFE90
incq %rdx
movsd 0x7ed2(%rip), %xmm2     # 0x6d740
cmpl $0x0, 0x10(%rcx)
je 0x658a5
movsd (%rcx), %xmm3
subsd %xmm0, %xmm3
movsd 0x8(%rcx), %xmm4
subsd %xmm1, %xmm4
mulsd %xmm4, %xmm4
mulsd %xmm3, %xmm3
addsd %xmm4, %xmm3
sqrtsd %xmm3, %xmm3
ucomisd %xmm3, %xmm2
jbe 0x658a5
movl 0x114(%rcx), %eax
movapd %xmm3, %xmm2
addq $0x178, %rcx            # imm = 0x178
movq %rdx, %r8
incq %r8
cmpl $0xc, %edx
movq %r8, %rdx
jne 0x6586e
jmp 0x65997
movb (%rax), %al
movq 0x8(%rdi), %r8
leaq 0x10d0(%r8), %r9
addq $0xa8, %r8
cmpb 0x10(%rdi), %al
movsd (%rcx), %xmm0
movsd 0x8(%rcx), %xmm1
movq %r9, %rcx
cmoveq %r8, %rcx
cmoveq %r9, %r8
movsd 0x7e4e(%rip), %xmm2     # 0x6d740
xorl %eax, %eax
movl $0x1, %r9d
movl $0x8, %r10d
cmpq %rdx, %r9
jl 0x65944
cmpl $0x0, 0x10(%rcx,%r10)
je 0x65944
movsd (%rcx,%r10), %xmm3
movsd 0x8(%rcx,%r10), %xmm4
subsd %xmm0, %xmm3
subsd %xmm1, %xmm4
mulsd %xmm4, %xmm4
mulsd %xmm3, %xmm3
addsd %xmm4, %xmm3
sqrtsd %xmm3, %xmm3
ucomisd %xmm3, %xmm2
jbe 0x65944
movl 0x114(%rcx,%r10), %eax
movapd %xmm3, %xmm2
cmpl $0x0, 0x10(%r8,%r10)
je 0x65983
movsd (%r8,%r10), %xmm3
movsd 0x8(%r8,%r10), %xmm4
subsd %xmm0, %xmm3
subsd %xmm1, %xmm4
mulsd %xmm4, %xmm4
mulsd %xmm3, %xmm3
addsd %xmm4, %xmm3
sqrtsd %xmm3, %xmm3
ucomisd %xmm3, %xmm2
jbe 0x65983
movl 0x114(%r8,%r10), %eax
movapd %xmm3, %xmm2
incq %r9
addq $0x178, %r10            # imm = 0x178
cmpq $0xc, %r9
jne 0x65900
testl %eax, %eax
je 0x659b1
setg %cl
movl %eax, %edx
negl %edx
cmovsl %eax, %edx
movzbl %cl, %ecx
callq 0x645d8
movb $0x1, %al
jmp 0x659b3
xorl %eax, %eax
popq %rbp
retq
nop