// File: /workspace/github_cpp_makefile_star2_O1/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 $0x78, %rsp
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 0x694a6
movl %eax, %eax
leaq 0x6399(%rip), %rcx      # 0x6f838
movsd (%rcx,%rax,8), %xmm0
jmp 0x694ae
movsd 0x1c02(%rip), %xmm0     # 0x6b0b0
movsd %xmm0, -0x30(%rbp)
movq %rdx, -0x70(%rbp)
callq 0x5b2be
movapd %xmm0, %xmm5
movslq 0x14(%r15), %rax
movq 0x8(%r15), %rcx
movsd (%r14), %xmm1
movsd 0x8(%r14), %xmm0
imulq $0x178, %rax, %rax      # imm = 0x178
subsd -0xc8(%rax,%rcx), %xmm1
subsd -0xc0(%rax,%rcx), %xmm0
movapd 0x1b1c(%rip), %xmm2     # 0x6b010
movapd %xmm1, %xmm4
andpd %xmm2, %xmm4
movsd 0x1b3c(%rip), %xmm3     # 0x6b040
ucomisd %xmm4, %xmm3
jbe 0x69518
andpd %xmm0, %xmm2
xorpd %xmm4, %xmm4
ucomisd %xmm2, %xmm3
ja 0x6953b
movsd %xmm5, -0x50(%rbp)
callq 0x90d0
movsd -0x50(%rbp), %xmm5
movapd %xmm0, %xmm4
mulsd 0x1b15(%rip), %xmm4     # 0x6b048
divsd 0x1b15(%rip), %xmm4     # 0x6b050
movsd %xmm4, -0x80(%rbp)
movsd 0x1b40(%rip), %xmm0     # 0x6b088
movsd -0x30(%rbp), %xmm1
mulsd %xmm1, %xmm0
addsd %xmm0, %xmm5
movslq 0x14(%r15), %rax
movq 0x8(%r15), %rbx
movsd (%r14), %xmm2
movsd 0x8(%r14), %xmm0
movq %r14, -0x88(%rbp)
imulq $0x178, %rax, %r14      # imm = 0x178
subsd -0xc8(%r14,%rbx), %xmm2
movsd %xmm2, -0x40(%rbp)
subsd -0xc0(%r14,%rbx), %xmm0
movapd %xmm0, -0x50(%rbp)
addsd %xmm5, %xmm1
movsd %xmm1, -0x30(%rbp)
subsd %xmm4, %xmm5
addsd 0x1acf(%rip), %xmm5     # 0x6b078
mulsd 0x1a9f(%rip), %xmm5     # 0x6b050
divsd 0x1a8f(%rip), %xmm5     # 0x6b048
leaq -0x98(%rbp), %r12
leaq -0x90(%rbp), %r13
movapd %xmm5, %xmm0
movq %r12, %rdi
movq %r13, %rsi
callq 0x92d0
movsd (%r12), %xmm0
movsd (%r13), %xmm1
movsd -0x40(%rbp), %xmm2
movapd %xmm2, %xmm3
mulsd %xmm0, %xmm2
movapd %xmm2, %xmm4
movapd -0x50(%rbp), %xmm2
mulsd %xmm2, %xmm0
mulsd %xmm1, %xmm3
subsd %xmm0, %xmm3
mulsd %xmm1, %xmm2
addsd %xmm4, %xmm2
addsd -0xc8(%r14,%rbx), %xmm3
movsd %xmm3, -0x58(%rbp)
addsd -0xc0(%r14,%rbx), %xmm2
movapd %xmm2, -0x50(%rbp)
movslq 0x14(%r15), %rax
movq 0x8(%r15), %rbx
movq -0x88(%rbp), %r13
movsd (%r13), %xmm0
imulq $0x178, %rax, %r14      # imm = 0x178
subsd -0xc8(%r14,%rbx), %xmm0
movsd %xmm0, -0x78(%rbp)
movsd 0x8(%r13), %xmm0
subsd -0xc0(%r14,%rbx), %xmm0
movapd %xmm0, -0x40(%rbp)
movsd -0x30(%rbp), %xmm0
subsd -0x80(%rbp), %xmm0
addsd 0x19c4(%rip), %xmm0     # 0x6b040
mulsd 0x19cc(%rip), %xmm0     # 0x6b050
divsd 0x19bc(%rip), %xmm0     # 0x6b048
leaq -0x98(%rbp), %r15
leaq -0x90(%rbp), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x92d0
movsd (%r15), %xmm0
movsd (%r12), %xmm1
movsd -0x78(%rbp), %xmm3
movapd %xmm3, %xmm2
mulsd %xmm0, %xmm3
movapd -0x40(%rbp), %xmm4
mulsd %xmm4, %xmm0
mulsd %xmm1, %xmm2
subsd %xmm0, %xmm2
mulsd %xmm1, %xmm4
addsd %xmm3, %xmm4
addsd -0xc8(%r14,%rbx), %xmm2
addsd -0xc0(%r14,%rbx), %xmm4
movapd %xmm4, -0x40(%rbp)
movq -0x70(%rbp), %rbx
testq %rbx, %rbx
cmoveq %r13, %rbx
movsd -0x58(%rbp), %xmm0
subsd (%rbx), %xmm0
movapd -0x50(%rbp), %xmm1
subsd 0x8(%rbx), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
xorpd %xmm4, %xmm4
ucomisd %xmm4, %xmm0
movsd %xmm2, -0x30(%rbp)
jb 0x69731
xorps %xmm1, %xmm1
sqrtsd %xmm0, %xmm1
jmp 0x69743
callq 0x93c0
xorpd %xmm4, %xmm4
movsd -0x30(%rbp), %xmm2
movapd %xmm0, %xmm1
movapd %xmm2, %xmm0
subsd (%rbx), %xmm0
movapd -0x40(%rbp), %xmm3
subsd 0x8(%rbx), %xmm3
mulsd %xmm3, %xmm3
mulsd %xmm0, %xmm0
addsd %xmm3, %xmm0
ucomisd %xmm4, %xmm0
jb 0x6976d
sqrtsd %xmm0, %xmm0
jmp 0x69781
movapd %xmm1, -0x70(%rbp)
callq 0x93c0
movapd -0x70(%rbp), %xmm1
movsd -0x30(%rbp), %xmm2
ucomisd %xmm1, %xmm0
cmpltsd %xmm0, %xmm1
movapd -0x50(%rbp), %xmm0
andpd %xmm1, %xmm0
andnpd -0x40(%rbp), %xmm1
orpd %xmm0, %xmm1
movsd -0x58(%rbp), %xmm0
ja 0x697a7
movapd %xmm2, %xmm0
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq