// File: /workspace/github_cpp_makefile_star2_O3/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 $0x68, %rsp
movq %rdx, -0x70(%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 0x66d28
movl %eax, %eax
leaq 0x6ad7(%rip), %rcx      # 0x6d7f8
movsd (%rcx,%rax,8), %xmm0
jmp 0x66d30
movsd 0x2380(%rip), %xmm0     # 0x690b0
movsd %xmm0, -0x30(%rbp)
callq 0x59a22
movapd %xmm0, %xmm7
movslq 0x14(%r15), %rax
movq 0x8(%r15), %rbx
movsd (%r14), %xmm6
movsd 0x8(%r14), %xmm5
imulq $0x178, %rax, %rcx      # imm = 0x178
movapd %xmm6, %xmm1
subsd -0xc8(%rcx,%rbx), %xmm1
movapd %xmm5, %xmm0
subsd -0xc0(%rcx,%rbx), %xmm0
movapd 0x2296(%rip), %xmm2     # 0x69010
movapd %xmm1, %xmm4
andpd %xmm2, %xmm4
movsd 0x22b6(%rip), %xmm3     # 0x69040
ucomisd %xmm4, %xmm3
movq %r14, -0x68(%rbp)
jbe 0x66da7
andpd %xmm0, %xmm2
ucomisd %xmm2, %xmm3
jbe 0x66da7
decq %rax
xorpd %xmm0, %xmm0
jmp 0x66ddc
movsd %xmm7, -0x50(%rbp)
callq 0x90d0
movsd -0x50(%rbp), %xmm7
mulsd 0x228a(%rip), %xmm0     # 0x69048
divsd 0x228a(%rip), %xmm0     # 0x69050
movslq 0x14(%r15), %rax
movq 0x8(%r15), %rbx
movsd (%r14), %xmm6
movsd 0x8(%r14), %xmm5
decq %rax
movsd %xmm0, -0x60(%rbp)
movsd 0x229f(%rip), %xmm1     # 0x69088
movsd -0x30(%rbp), %xmm2
mulsd %xmm2, %xmm1
addsd %xmm1, %xmm7
imulq $0x178, %rax, %r14      # imm = 0x178
subsd 0xb0(%rbx,%r14), %xmm6
movsd %xmm6, -0x38(%rbp)
subsd 0xb8(%rbx,%r14), %xmm5
movapd %xmm5, -0x50(%rbp)
addsd %xmm7, %xmm2
movsd %xmm2, -0x30(%rbp)
subsd %xmm0, %xmm7
addsd 0x2248(%rip), %xmm7     # 0x69078
mulsd 0x2218(%rip), %xmm7     # 0x69050
divsd 0x2208(%rip), %xmm7     # 0x69048
leaq -0x80(%rbp), %r12
leaq -0x78(%rbp), %r13
movapd %xmm7, %xmm0
movq %r12, %rdi
movq %r13, %rsi
callq 0x92d0
movsd (%r12), %xmm0
movsd (%r13), %xmm1
movsd -0x38(%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 0xb0(%rbx,%r14), %xmm3
movsd %xmm3, -0x38(%rbp)
addsd 0xb8(%rbx,%r14), %xmm2
movapd %xmm2, -0x50(%rbp)
movslq 0x14(%r15), %rax
movq 0x8(%r15), %rbx
movq -0x68(%rbp), %r13
movsd (%r13), %xmm0
imulq $0x178, %rax, %r14      # imm = 0x178
subsd -0xc8(%r14,%rbx), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd 0x8(%r13), %xmm0
subsd -0xc0(%r14,%rbx), %xmm0
movapd %xmm0, -0x90(%rbp)
movsd -0x30(%rbp), %xmm0
subsd -0x60(%rbp), %xmm0
addsd 0x2143(%rip), %xmm0     # 0x69040
mulsd 0x214b(%rip), %xmm0     # 0x69050
divsd 0x213b(%rip), %xmm0     # 0x69048
leaq -0x80(%rbp), %r15
leaq -0x78(%rbp), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x92d0
movsd -0x38(%rbp), %xmm0
movsd (%r15), %xmm1
movsd (%r12), %xmm2
movsd -0x58(%rbp), %xmm3
movapd %xmm3, %xmm5
mulsd %xmm1, %xmm3
movapd -0x90(%rbp), %xmm7
mulsd %xmm7, %xmm1
mulsd %xmm2, %xmm5
subsd %xmm1, %xmm5
mulsd %xmm2, %xmm7
addsd %xmm3, %xmm7
addsd -0xc8(%r14,%rbx), %xmm5
addsd -0xc0(%r14,%rbx), %xmm7
movq -0x70(%rbp), %rax
testq %rax, %rax
cmoveq %r13, %rax
movsd (%rax), %xmm2
movsd 0x8(%rax), %xmm3
movapd %xmm0, %xmm1
subsd %xmm2, %xmm1
movapd -0x50(%rbp), %xmm6
movapd %xmm6, %xmm4
subsd %xmm3, %xmm4
mulsd %xmm4, %xmm4
mulsd %xmm1, %xmm1
addsd %xmm4, %xmm1
sqrtsd %xmm1, %xmm1
movapd %xmm5, %xmm4
subsd %xmm2, %xmm4
movapd %xmm7, %xmm2
subsd %xmm3, %xmm2
mulsd %xmm2, %xmm2
mulsd %xmm4, %xmm4
addsd %xmm2, %xmm4
xorps %xmm2, %xmm2
sqrtsd %xmm4, %xmm2
ucomisd %xmm1, %xmm2
cmpltsd %xmm2, %xmm1
movapd %xmm6, %xmm2
andpd %xmm1, %xmm2
andnpd %xmm7, %xmm1
orpd %xmm2, %xmm1
ja 0x66fe8
movapd %xmm5, %xmm0
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop