// File: 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
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq (%rax), %rdi
movl -0x1c(%rbp), %esi
callq 0xbdf50
movq %rax, %rdi
callq 0xbdfd0
movb %al, %cl
movq -0xc8(%rbp), %rax
andb $0x1, %cl
movb %cl, -0x1d(%rbp)
movq (%rax), %rdi
movl -0x1c(%rbp), %esi
callq 0xbdf90
movl 0x4(%rax), %eax
movl %eax, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movsd 0xbd2d(%rip), %xmm0     # 0xc57b0
movsd %xmm0, -0x30(%rbp)
testb $0x1, -0x1d(%rbp)
je 0xb9c1b
movq -0xc8(%rbp), %rax
movq (%rax), %rdi
movl -0x1c(%rbp), %esi
callq 0xbdf50
movq %rax, %rdi
callq 0xbdff0
movq %rax, %rcx
movq -0xc8(%rbp), %rax
movsbl (%rcx), %ecx
movl %ecx, -0xcc(%rbp)
movq (%rax), %rdi
movl -0x1c(%rbp), %esi
callq 0xbdf90
movq %rax, %rcx
movl -0xcc(%rbp), %eax
movsbl (%rcx), %ecx
cmpl %ecx, %eax
je 0xb9ae1
movl $0x1, -0x24(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x34(%rbp)
cmpl $0xb, -0x34(%rbp)
jg 0xb9c16
movq -0xc8(%rbp), %rax
movq (%rax), %rdi
movl -0x1c(%rbp), %esi
callq 0xbdf50
movq %rax, %rdi
callq 0xbdff0
movq -0xc8(%rbp), %rcx
movsbl (%rax), %eax
movsbl 0x10(%rcx), %ecx
cmpl %ecx, %eax
jne 0xb9b3a
movq -0xc8(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x34(%rbp), %rsi
callq 0x12520
movq %rax, -0xd8(%rbp)
jmp 0xb9b55
movq -0xc8(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x34(%rbp), %rsi
callq 0x1d480
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
addq $0x8, %rdi
callq 0x1ddd0
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0xd9(%rbp)
je 0xb9bbd
movq -0x40(%rbp), %rdi
addq $0x8, %rdi
callq 0x11090
movq %rax, %rdi
movq -0x18(%rbp), %rsi
callq 0x110a0
movsd %xmm0, -0x50(%rbp)
movsd %xmm1, -0x48(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x104e0
movaps %xmm0, %xmm1
movsd -0x30(%rbp), %xmm0
ucomisd %xmm1, %xmm0
seta %al
movb %al, -0xd9(%rbp)
movb -0xd9(%rbp), %al
testb $0x1, %al
jne 0xb9bc9
jmp 0xb9c06
movq -0x40(%rbp), %rdi
addq $0x8, %rdi
callq 0x11090
movq %rax, %rdi
movq -0x18(%rbp), %rsi
callq 0x110a0
movsd %xmm0, -0x60(%rbp)
movsd %xmm1, -0x58(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x104e0
movsd %xmm0, -0x30(%rbp)
movq -0x40(%rbp), %rdi
callq 0x1b470
movl %eax, -0x28(%rbp)
jmp 0xb9c08
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xb9ae7
jmp 0xb9e87
movl $0x1, -0x64(%rbp)
cmpl $0xb, -0x64(%rbp)
jg 0xb9e85
movq -0xc8(%rbp), %rax
movq (%rax), %rdi
movl -0x1c(%rbp), %esi
callq 0xbdf90
movq -0xc8(%rbp), %rcx
movsbl (%rax), %eax
movsbl 0x10(%rcx), %ecx
cmpl %ecx, %eax
jne 0xb9c6d
movq -0xc8(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x64(%rbp), %rsi
callq 0x12520
movq %rax, -0xe8(%rbp)
jmp 0xb9c88
movq -0xc8(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x64(%rbp), %rsi
callq 0x1d480
movq %rax, -0xe8(%rbp)
movq -0xc8(%rbp), %rax
movq -0xe8(%rbp), %rcx
movq %rcx, -0x70(%rbp)
movq (%rax), %rdi
movl -0x1c(%rbp), %esi
callq 0xbdf90
movq -0xc8(%rbp), %rcx
movsbl (%rax), %eax
movsbl 0x10(%rcx), %ecx
cmpl %ecx, %eax
jne 0xb9cd4
movq -0xc8(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x64(%rbp), %rsi
callq 0x1d480
movq %rax, -0xf0(%rbp)
jmp 0xb9cef
movq -0xc8(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x64(%rbp), %rsi
callq 0x12520
movq %rax, -0xf0(%rbp)
movq -0xf0(%rbp), %rax
movq %rax, -0x78(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x24(%rbp), %eax
jl 0xb9dbd
movq -0x70(%rbp), %rdi
addq $0x8, %rdi
callq 0x1ddd0
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0xf1(%rbp)
je 0xb9d69
movq -0x70(%rbp), %rdi
addq $0x8, %rdi
callq 0x11090
movq %rax, %rdi
movq -0x18(%rbp), %rsi
callq 0x110a0
movsd %xmm0, -0x88(%rbp)
movsd %xmm1, -0x80(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x104e0
movaps %xmm0, %xmm1
movsd -0x30(%rbp), %xmm0
ucomisd %xmm1, %xmm0
seta %al
movb %al, -0xf1(%rbp)
movb -0xf1(%rbp), %al
testb $0x1, %al
jne 0xb9d75
jmp 0xb9dbb
movq -0x70(%rbp), %rdi
addq $0x8, %rdi
callq 0x11090
movq %rax, %rdi
movq -0x18(%rbp), %rsi
callq 0x110a0
movsd %xmm0, -0x98(%rbp)
movsd %xmm1, -0x90(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x104e0
movsd %xmm0, -0x30(%rbp)
movq -0x70(%rbp), %rdi
callq 0x1b470
movl %eax, -0x28(%rbp)
jmp 0xb9dbd
movq -0x78(%rbp), %rdi
addq $0x8, %rdi
callq 0x1ddd0
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0xf2(%rbp)
je 0xb9e23
movq -0x78(%rbp), %rdi
addq $0x8, %rdi
callq 0x11090
movq %rax, %rdi
movq -0x18(%rbp), %rsi
callq 0x110a0
movsd %xmm0, -0xa8(%rbp)
movsd %xmm1, -0xa0(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x104e0
movaps %xmm0, %xmm1
movsd -0x30(%rbp), %xmm0
ucomisd %xmm1, %xmm0
seta %al
movb %al, -0xf2(%rbp)
movb -0xf2(%rbp), %al
testb $0x1, %al
jne 0xb9e2f
jmp 0xb9e75
movq -0x78(%rbp), %rdi
addq $0x8, %rdi
callq 0x11090
movq %rax, %rdi
movq -0x18(%rbp), %rsi
callq 0x110a0
movsd %xmm0, -0xb8(%rbp)
movsd %xmm1, -0xb0(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x104e0
movsd %xmm0, -0x30(%rbp)
movq -0x78(%rbp), %rdi
callq 0x1b470
movl %eax, -0x28(%rbp)
jmp 0xb9e77
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0xb9c22
jmp 0xb9e87
cmpl $0x0, -0x28(%rbp)
je 0xb9ed9
movq -0xc8(%rbp), %rax
cmpl $0x0, -0x28(%rbp)
setg %cl
andb $0x1, %cl
movb %cl, -0xb9(%rbp)
movq (%rax), %rdi
movl -0x1c(%rbp), %esi
callq 0xbdf50
movq -0xc8(%rbp), %rdi
movq %rax, %rsi
movl -0x28(%rbp), %edx
movl %edx, %eax
negl %eax
cmovnsl %eax, %edx
movb -0xb9(%rbp), %al
andb $0x1, %al
movzbl %al, %ecx
callq 0xb85b0
movb $0x1, -0x1(%rbp)
jmp 0xb9edd
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
nopl (%rax,%rax)