// File: FakePsyho[P]halite2/MyBot.cpp
// Function: colonizeOrder(hlt::Ship const&, hlt::Planet const&, bool)
Order colonizeOrder(const Ship& ship, const Planet& planet, bool delay = false) {
	Order o;
	o.type = OrderType::Colonize;
	o.ship = ship.entity_id;
	o.planet = planet.entity_id;
	
	if (planetEnemyShips[planet.entity_id] > 0) return o;
	int spots_left = planet.docking_spots - planetMyShips[planet.entity_id];
	if (planetShipTurn[planet.entity_id] < (ship.location.dist(planet.location) - 4 - planet.radius) / 7.0) spots_left--;
	if (spots_left <= 0) return o;
	
	double v = 0;
	if (ship.can_dock(planet)) {
		v = 2500 + closestEnemy[ship.entity_id] + planetMyShips[planet.entity_id];
		// if (shipSafety[ship.entity_id] >= 2) v += 2000 + 100 * shipSafety[ship.entity_id];
		if (shipSafety[ship.entity_id] >= (players_no == 2 ? 2 : 1)) v += 2000;
		if (delay) v = -10000;
	} else {
		v = 2000 - ship.location.dist(planet.location) + planet.radius + planetValue[planet.entity_id] + (turn < 20 ? planetMyShips[planet.entity_id] * 2 : 0);
	}
	o.value = v;
	
	return o;
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x40(%rsp)
movb %cl, %al
movq %rdi, %rcx
movq %rcx, 0x38(%rsp)
movq %rsi, 0x60(%rsp)
movq %rdx, 0x58(%rsp)
andb $0x1, %al
movb %al, 0x57(%rsp)
callq 0x139c0
movq 0x40(%rsp), %rdi
movl $0x2, (%rdi)
movq 0x60(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x60(%rdi)
movq 0x58(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x64(%rdi)
movq 0x58(%rsp), %rsi
leaq 0x4b525(%rip), %rdi     # 0x52008
callq 0x13a50
cmpl $0x0, (%rax)
jle 0x6af2
jmp 0x6d05
movq 0x58(%rsp), %rax
movl 0x84(%rax), %eax
movl %eax, 0x2c(%rsp)
movq 0x58(%rsp), %rsi
leaq 0x4b4cb(%rip), %rdi     # 0x51fd8
callq 0x13a50
movq %rax, %rcx
movl 0x2c(%rsp), %eax
subl (%rcx), %eax
movl %eax, 0x50(%rsp)
movq 0x58(%rsp), %rsi
leaq 0x4b35d(%rip), %rdi     # 0x51e88
callq 0x13a50
cvtsi2sdl (%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
movq 0x60(%rsp), %rdi
addq $0x8, %rdi
movq 0x58(%rsp), %rsi
addq $0x8, %rsi
callq 0x12ac0
movsd 0x30(%rsp), %xmm1
movsd 0x34519(%rip), %xmm2    # 0x3b078
subsd %xmm2, %xmm0
movq 0x58(%rsp), %rax
subsd 0x70(%rax), %xmm0
movsd 0x3456b(%rip), %xmm2    # 0x3b0e0
divsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x6b8a
movl 0x50(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x50(%rsp)
cmpl $0x0, 0x50(%rsp)
jg 0x6b96
jmp 0x6d05
xorps %xmm0, %xmm0
movsd %xmm0, 0x48(%rsp)
movq 0x60(%rsp), %rdi
movq 0x58(%rsp), %rsi
callq 0x13b40
testb $0x1, %al
jne 0x6bb7
jmp 0x6c5a
movq 0x60(%rsp), %rsi
leaq 0x4b475(%rip), %rdi     # 0x52038
callq 0x13b90
movsd 0x34520(%rip), %xmm0    # 0x3b0f0
addsd (%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
movq 0x58(%rsp), %rsi
leaq 0x4b3f2(%rip), %rdi     # 0x51fd8
callq 0x13a50
movsd 0x20(%rsp), %xmm0
cvtsi2sdl (%rax), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, 0x48(%rsp)
movq 0x60(%rsp), %rsi
leaq 0x4b30d(%rip), %rdi     # 0x51f18
callq 0x13a50
movl (%rax), %eax
movl 0x4a658(%rip), %esi     # 0x51270
movl $0x1, %ecx
movl $0x2, %edx
cmpl $0x2, %esi
cmovel %edx, %ecx
cmpl %ecx, %eax
jl 0x6c40
movsd 0x344b4(%rip), %xmm0    # 0x3b0e8
addsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x48(%rsp)
testb $0x1, 0x57(%rsp)
je 0x6c55
movsd 0x344a9(%rip), %xmm0    # 0x3b0f8
movsd %xmm0, 0x48(%rsp)
jmp 0x6cf5
movq 0x60(%rsp), %rdi
addq $0x8, %rdi
movq 0x58(%rsp), %rsi
addq $0x8, %rsi
callq 0x12ac0
movaps %xmm0, %xmm1
movsd 0x3446c(%rip), %xmm0    # 0x3b0e8
subsd %xmm1, %xmm0
movq 0x58(%rsp), %rax
addsd 0x70(%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x58(%rsp), %rsi
leaq 0x4b3fc(%rip), %rdi     # 0x52098
callq 0x13b90
movsd 0x10(%rsp), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
cmpl $0x14, 0x4b4f0(%rip)    # 0x521a8
jge 0x6cd5
movq 0x58(%rsp), %rsi
leaq 0x4b312(%rip), %rdi     # 0x51fd8
callq 0x13a50
movl (%rax), %eax
shll %eax
movl %eax, 0xc(%rsp)
jmp 0x6cdd
xorl %eax, %eax
movl %eax, 0xc(%rsp)
jmp 0x6cdd
movsd 0x18(%rsp), %xmm0
movl 0xc(%rsp), %eax
cvtsi2sd %eax, %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, 0x48(%rsp)
movq 0x40(%rsp), %rax
movsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x8(%rax)
movq 0x38(%rsp), %rax
addq $0x68, %rsp
retq
nop