// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdx, -0x68(%rbp)
movq %rsi, %r14
movq %rdi, %r15
movslq 0x14(%rdi), %rax
movq 0x8(%rdi), %rcx
imulq $0x178, %rax, %rax      # imm = 0x178
leaq (%rax,%rcx), %rdi
addq $-0xd0, %rdi
movl 0x118(%rdi), %eax
decl %eax
cmpl $0x2, %eax
ja 0x55056
movl %eax, %eax
leaq 0x6789(%rip), %rcx      # 0x5b7d8
movsd (%rcx,%rax,8), %xmm0
jmp 0x5505e
movsd 0x202a(%rip), %xmm0     # 0x57088
movsd %xmm0, -0x30(%rbp)
callq 0x4bef2
movsd 0x1ff0(%rip), %xmm3     # 0x57060
movsd -0x30(%rbp), %xmm1
mulsd %xmm1, %xmm3
movapd %xmm1, %xmm2
addsd %xmm0, %xmm3
movsd %xmm3, -0x50(%rbp)
movslq 0x14(%r15), %rax
movq 0x8(%r15), %rcx
movsd (%r14), %xmm0
movsd 0x8(%r14), %xmm1
imulq $0x178, %rax, %rax      # imm = 0x178
subsd -0xc8(%rax,%rcx), %xmm0
subsd -0xc0(%rax,%rcx), %xmm1
addsd %xmm3, %xmm2
movsd %xmm2, -0x30(%rbp)
leaq -0x78(%rbp), %r12
movsd %xmm0, (%r12)
movsd %xmm1, 0x8(%r12)
movq %r12, %rdi
callq 0xcd30
movslq 0x14(%r15), %rax
movq 0x8(%r15), %rbx
movsd (%r14), %xmm1
movsd 0x8(%r14), %xmm2
imulq $0x178, %rax, %r13      # imm = 0x178
subsd -0xc8(%r13,%rbx), %xmm1
subsd -0xc0(%r13,%rbx), %xmm2
movsd %xmm0, -0x60(%rbp)
movsd %xmm1, (%r12)
movsd %xmm2, 0x8(%r12)
movsd -0x50(%rbp), %xmm1
subsd %xmm0, %xmm1
addsd 0x1f2b(%rip), %xmm1     # 0x57050
leaq -0x38(%rbp), %rsi
movsd %xmm1, (%rsi)
movq %r12, %rdi
callq 0xd02c
addsd -0xc8(%r13,%rbx), %xmm0
movsd %xmm0, -0x58(%rbp)
addsd -0xc0(%r13,%rbx), %xmm1
movapd %xmm1, -0x50(%rbp)
movslq 0x14(%r15), %rax
movq 0x8(%r15), %rbx
movsd (%r14), %xmm0
movsd 0x8(%r14), %xmm1
imulq $0x178, %rax, %r15      # imm = 0x178
subsd -0xc8(%r15,%rbx), %xmm0
subsd -0xc0(%r15,%rbx), %xmm1
movsd %xmm0, (%r12)
movsd %xmm1, 0x8(%r12)
movsd -0x30(%rbp), %xmm0
subsd -0x60(%rbp), %xmm0
addsd 0x1ea0(%rip), %xmm0     # 0x57040
leaq -0x38(%rbp), %rax
movsd %xmm0, (%rax)
leaq -0x78(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0xd02c
movsd -0x58(%rbp), %xmm6
addsd -0xc8(%r15,%rbx), %xmm0
addsd -0xc0(%r15,%rbx), %xmm1
movq -0x68(%rbp), %rax
testq %rax, %rax
cmoveq %r14, %rax
movsd (%rax), %xmm3
movsd 0x8(%rax), %xmm4
movapd %xmm6, %xmm2
subsd %xmm3, %xmm2
movapd -0x50(%rbp), %xmm7
movapd %xmm7, %xmm5
subsd %xmm4, %xmm5
mulsd %xmm5, %xmm5
mulsd %xmm2, %xmm2
addsd %xmm5, %xmm2
sqrtsd %xmm2, %xmm2
movapd %xmm0, %xmm5
subsd %xmm3, %xmm5
movapd %xmm1, %xmm3
subsd %xmm4, %xmm3
mulsd %xmm3, %xmm3
mulsd %xmm5, %xmm5
addsd %xmm3, %xmm5
sqrtsd %xmm5, %xmm3
ucomisd %xmm2, %xmm3
cmpltsd %xmm3, %xmm2
movapd %xmm7, %xmm3
andpd %xmm2, %xmm3
andnpd %xmm1, %xmm2
orpd %xmm3, %xmm2
ja 0x55246
movapd %xmm0, %xmm6
movapd %xmm6, %xmm0
movapd %xmm2, %xmm1
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop