// File: /workspace/github_cpp_makefile_star2_O2/FakePsyho[P]halite2/MyBot.cpp
// Function: getSpawningPoint(hlt::Planet&)
Location getSpawningPoint(Planet& p) {
	Location bloc(-1e9, -1e9);
	Location origin(m.map_width / 2.0, m.map_height / 2.0);
	VC<Entity> entities = findCloseEntities(p.location, p.radius + 10, MASK_ALL);
	FOR(dx, -SPAWN_RADIUS, +SPAWN_RADIUS + 1) FOR(dy, -SPAWN_RADIUS, +SPAWN_RADIUS + 1) {
		double offset_angle = atan2(dy, dx);
		double offset_x = dx + p.radius * cos(offset_angle);
		double offset_y = dy + p.radius * sin(offset_angle);
		auto loc = p.location + Location(offset_x, offset_y);
		
		bool collision = false;
		for (Entity& e : entities) if (loc.dist(e.location) < SHIP_RADIUS * 4) {
			collision = true;
			break;
		}
		if (collision) continue;
		if (origin.dist_sq(loc) < origin.dist_sq(bloc)) bloc = loc;
	}
	return bloc;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x98, %rsp
movq %rdi, %rbx
cvtsi2sdl 0x198f3(%rip), %xmm1 # 0x1cce8
movsd 0xec1b(%rip), %xmm0     # 0x12018
mulsd %xmm0, %xmm1
movapd %xmm1, 0x10(%rsp)
cvtsi2sdl 0x198dd(%rip), %xmm1 # 0x1ccec
mulsd %xmm0, %xmm1
movapd %xmm1, (%rsp)
movsd 0x8(%rdi), %xmm0
movsd 0x10(%rdi), %xmm1
movsd 0x70(%rdi), %xmm2
addsd 0xebf1(%rip), %xmm2     # 0x12020
leaq 0x58(%rsp), %rdi
pushq $0x1f
popq %rsi
pushq $-0x1
popq %rdx
callq 0x2d33
movaps 0x10(%rsp), %xmm0
movlhps %xmm0, %xmm0            # xmm0 = xmm0[0,0]
movaps %xmm0, 0x10(%rsp)
movaps (%rsp), %xmm0
movlhps %xmm0, %xmm0            # xmm0 = xmm0[0,0]
movaps %xmm0, (%rsp)
movaps 0xedd2(%rip), %xmm0     # 0x12230
movaps %xmm0, 0x20(%rsp)
pushq $-0x2
popq %r15
movsd 0xebb9(%rip), %xmm0     # 0x12028
movapd %xmm0, 0x30(%rsp)
movl %r15d, %ebp
cmpl $0x3, %ebp
je 0x35d9
movsd 0xeb9f(%rip), %xmm5     # 0x12028
movl %r15d, %r14d
cmpl $0x3, %r14d
je 0x35be
movl %r14d, %edi
movl %ebp, %esi
movapd %xmm5, 0x80(%rsp)
callq 0x9bce
movapd %xmm0, %xmm1
movsd %xmm0, 0x50(%rsp)
movups 0x70(%rbx), %xmm0
movaps %xmm0, 0x40(%rsp)
movapd %xmm1, %xmm0
callq 0x2410
movapd %xmm0, 0x70(%rsp)
movaps 0x40(%rsp), %xmm0
movhps 0x70(%rbx), %xmm0       # xmm0 = xmm0[0,1],mem[0,1]
movaps %xmm0, 0x40(%rsp)
movsd 0x50(%rsp), %xmm0
callq 0x2070
movapd 0x80(%rsp), %xmm5
movsd 0xeb3b(%rip), %xmm4     # 0x12030
movapd 0x70(%rsp), %xmm1
unpcklpd %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
mulpd 0x40(%rsp), %xmm1
movapd %xmm1, %xmm0
movapd 0x30(%rsp), %xmm1
unpcklpd %xmm5, %xmm1            # xmm1 = xmm1[0],xmm5[0]
addpd %xmm0, %xmm1
movupd 0x8(%rbx), %xmm0
addpd %xmm1, %xmm0
movq 0x58(%rsp), %rax
movq 0x60(%rsp), %rcx
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
cmpq %rcx, %rax
je 0x3565
movapd %xmm0, %xmm2
subsd 0x8(%rax), %xmm2
movapd %xmm1, %xmm3
subsd 0x10(%rax), %xmm3
mulsd %xmm3, %xmm3
mulsd %xmm2, %xmm2
addsd %xmm3, %xmm2
sqrtsd %xmm2, %xmm2
addq $0x78, %rax
ucomisd %xmm2, %xmm4
jbe 0x3532
jmp 0x35ae
movapd %xmm0, %xmm1
movapd 0x20(%rsp), %xmm3
unpcklpd %xmm3, %xmm1            # xmm1 = xmm1[0],xmm3[0]
movapd 0x10(%rsp), %xmm2
subpd %xmm1, %xmm2
movapd %xmm0, %xmm1
unpckhpd %xmm3, %xmm1            # xmm1 = xmm1[1],xmm3[1]
movapd (%rsp), %xmm3
subpd %xmm1, %xmm3
mulpd %xmm3, %xmm3
mulpd %xmm2, %xmm2
addpd %xmm3, %xmm2
movapd %xmm2, %xmm1
unpckhpd %xmm2, %xmm1            # xmm1 = xmm1[1],xmm2[1]
ucomisd %xmm2, %xmm1
jbe 0x35ae
movapd %xmm0, 0x20(%rsp)
addsd 0xea5a(%rip), %xmm5     # 0x12010
incl %r14d
jmp 0x348c
movapd 0x30(%rsp), %xmm0
addsd 0xea44(%rip), %xmm0     # 0x12010
movapd %xmm0, 0x30(%rsp)
incl %ebp
jmp 0x3478
leaq 0x58(%rsp), %rdi
callq 0xd7f8
movaps 0x20(%rsp), %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addq $0x98, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq