// File: wrighteagle2d[P]wrighteaglebase/Debug/../src/WorldState.cpp
// Function: WorldStateUpdater::GetNearSidePos(Vector const&, Vector const*)
Vector WorldStateUpdater::GetNearSidePos(const Vector &pos,
                                         const Vector *expected_pos) {
  const ViewWidth view_width = GetSelf().GetViewWidth();
  const AngleDeg view_angle = sight::ViewAngle(view_width);
  const AngleDeg left = GetSelf().GetNeckGlobalDir() - view_angle * 0.5;
  const AngleDeg right = left + view_angle;
  const AngleDeg rel_dir = (pos - GetSelf().GetPos()).Dir();

  Vector pos1 = GetSelf().GetPos() +
                (pos - GetSelf().GetPos()).Rotate(left - rel_dir - FLOAT_EPS);
  Vector pos2 = GetSelf().GetPos() +
                (pos - GetSelf().GetPos()).Rotate(right - rel_dir + FLOAT_EPS);

  if (!expected_pos) {
    expected_pos = &pos;
  }

  if (pos1.Dist(*expected_pos) < pos2.Dist(*expected_pos)) {
    return pos1;
  } else {
    return pos2;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movq -0x18(%rbp), %rdi
movq %rdi, -0xe8(%rbp)
callq 0xbcea0
movq %rax, %rdi
callq 0x11070
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %edi
callq 0x5be10
movq -0xe8(%rbp), %rdi
movsd %xmm0, -0x38(%rbp)
callq 0xbcea0
movq %rax, %rdi
callq 0xa95b0
movq -0xe8(%rbp), %rdi
movaps %xmm0, %xmm1
movsd -0x38(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd 0x555f(%rip), %xmm2     # 0xc1020
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x40(%rbp), %xmm0
addsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x100(%rbp)
callq 0xbcea0
movq %rax, %rdi
addq $0x8, %rdi
callq 0x11090
movq -0x100(%rbp), %rdi
movq %rax, %rsi
callq 0x110a0
movsd %xmm0, -0x60(%rbp)
movsd %xmm1, -0x58(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x10520
movq -0xe8(%rbp), %rdi
movsd %xmm0, -0x50(%rbp)
callq 0xbcea0
movq %rax, %rdi
addq $0x8, %rdi
callq 0x11090
movq -0xe8(%rbp), %rdi
movq %rax, -0xf0(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0xf8(%rbp)
callq 0xbcea0
movq %rax, %rdi
addq $0x8, %rdi
callq 0x11090
movq -0xf8(%rbp), %rdi
movq %rax, %rsi
callq 0x110a0
movsd %xmm0, -0x90(%rbp)
movsd %xmm1, -0x88(%rbp)
movsd -0x40(%rbp), %xmm0
subsd -0x50(%rbp), %xmm0
movsd 0x5475(%rip), %xmm1     # 0xc1008
subsd %xmm1, %xmm0
movsd %xmm0, -0x98(%rbp)
leaq -0x90(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x11110
movq -0xf0(%rbp), %rdi
movsd %xmm0, -0x80(%rbp)
movsd %xmm1, -0x78(%rbp)
leaq -0x80(%rbp), %rsi
callq 0x11360
movq -0xe8(%rbp), %rdi
movsd %xmm0, -0x70(%rbp)
movsd %xmm1, -0x68(%rbp)
callq 0xbcea0
movq %rax, %rdi
addq $0x8, %rdi
callq 0x11090
movq -0xe8(%rbp), %rdi
movq %rax, -0xd8(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0xe0(%rbp)
callq 0xbcea0
movq %rax, %rdi
addq $0x8, %rdi
callq 0x11090
movq -0xe0(%rbp), %rdi
movq %rax, %rsi
callq 0x110a0
movsd %xmm0, -0xc8(%rbp)
movsd %xmm1, -0xc0(%rbp)
movsd -0x48(%rbp), %xmm0
subsd -0x50(%rbp), %xmm0
movsd 0x53bf(%rip), %xmm1     # 0xc1008
addsd %xmm1, %xmm0
movsd %xmm0, -0xd0(%rbp)
leaq -0xc8(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x11110
movq -0xd8(%rbp), %rdi
movsd %xmm0, -0xb8(%rbp)
movsd %xmm1, -0xb0(%rbp)
leaq -0xb8(%rbp), %rsi
callq 0x11360
movsd %xmm0, -0xa8(%rbp)
movsd %xmm1, -0xa0(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0xbbcaa
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x1d6d0
movsd %xmm0, -0x108(%rbp)
movq -0x28(%rbp), %rsi
leaq -0xa8(%rbp), %rdi
callq 0x1d6d0
movsd -0x108(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0xbbcef
movq -0x70(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xbbd05
movq -0xa8(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0x8(%rbp)
movsd -0x10(%rbp), %xmm0
movsd -0x8(%rbp), %xmm1
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
nopl (%rax,%rax)