// File: /workspace/github_cpp_makefile_star2_O2/FakePsyho[P]halite2/MyBot.cpp
// Function: execOrder(Order&)
Move execOrder(Order &o) {
	const Ship& ship = m.get_ship(player_id, o.ship);
	
	if (o.type == OrderType::Colonize) {
		Planet& planet = m.planets[o.planet];
		if (ship.can_dock(planet)) {
			Move mv = Move::dock(ship.entity_id, planet.entity_id);
			mv.evasion = Evasion::None;
			return mv;
		} else {
			Move mv = move_to(ship, planet.location);
			mv.evasion = Evasion::None;
			return mv;
		}
		
	} else if (o.type == OrderType::AttackShip) {
		Ship eship = *enemyShips[o.target];
		double dist = ship.location.get_distance_to(eship.location);
		Location loc;
		loc = ship.location + (eship.location - ship.location).normalize() * max(MAX_SPEED, eship.location.dist(ship.location));
		if (!m.in_ex_bounds(loc, 4)) loc = ship.location + (eship.location - ship.location).normalize() * 1000;
		if (shipTarget[eship.entity_id] != eship.location)
			loc = shipTarget[eship.entity_id];
		double aces = 1e9;
		for (auto &e : findCloseEntities(ship.location, 10.0, MASK_ALLIES, ship.entity_id)) aces = min(aces, closestEnemyShip[e.entity_id]);
		double ces = closestEnemyShip[ship.entity_id];
		double maxSpeed = MAX_SPEED;
		if (maxFollowers[eship.entity_id] > 2 && ces < 20.0 && aces < 25.0 && ces < aces) maxSpeed = max(3.0, min(MAX_SPEED, 7.0 - (aces - ces) / 3));
		Move mv = move_to(ship, loc, maxSpeed);
		// Move mv = move_to(ship, eship.location, MAX_SPEED);
		mv.evasion = Evasion::Small;
		return mv;
		
	} else if (o.type == OrderType::AttackMiner) {
		Ship eship = *enemyShips[o.target];
		double dist = ship.location.get_distance_to(eship.location);
		
		double aces = 1e9;
		for (auto &e : findCloseEntities(ship.location, 10.0, MASK_ALLIES, ship.entity_id)) aces = min(aces, closestEnemyShip[e.entity_id]);
		double ces = closestEnemyShip[ship.entity_id];
		double maxSpeed = MAX_SPEED;
		if (maxFollowers[eship.entity_id] > 2 && ces < 20.0 && aces < 25.0 && ces < aces) maxSpeed = max(3.0, min(MAX_SPEED, 7.0 - (aces - ces) / 3));
		
		Move mv = move_to(ship, eship.location, maxSpeed, 5.05);
		mv.evasion = Evasion::Medium;
		return mv;
		
	} else if (o.type == OrderType::HitAndRun) {
		Ship eship = *enemyShips[o.target];
		double dist = ship.location.get_distance_to(eship.location);
		Move mv = move_to(ship, eship.location, MAX_SPEED, 5.05, true);
		mv.evasion = Evasion::None;
		return mv;
		
	// } else if (o.type == OrderType::DefendMiner) {
		// Ship aship = m.get_ship(player_id, aggressiveShips[o.target]);
		// double dist = ship.location.get_distance_to(aship.location);
		// Move mv = Move::stop(ship.entity_id);
		// REP(tries, 10) {
			// auto nav = move_to(ship, aship.location + Location(rng.nextDouble(-2, 2), rng.nextDouble(-2, 2)), max(0.0, min(dist + 1.25, MAX_SPEED)));
			// if (nav.Y) {
				// mv = nav.X;
				// break;
			// }
		// }
		// mv.evasion = Evasion::None;
		// return mv;		
		
	} else if (o.type == OrderType::Hide) {
		Location loc = Location(o.cornerx == 0 ? 1 : m.map_width - 1, o.cornery == 0 ? 1 : m.map_height - 1);
		double dist = ship.location.get_distance_to(loc);
		Move mv = move_to(ship, loc, min(dist, MAX_SPEED), 0.0, true);
		mv.evasion = Evasion::None;
		return mv;
		
	} else if (o.type == OrderType::Undock) {
		Move mv = Move::undock(ship.entity_id);
		return mv;
		
	} else {
		assert(false);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rsi, %r15
movq %rdi, %rbx
movl 0x18312(%rip), %esi     # 0x1ccdc
movl 0x60(%r15), %edx
leaq 0x18313(%rip), %rdi     # 0x1cce8
callq 0x9b58
movq %rax, %r14
movl (%r15), %eax
addl $-0x2, %eax
cmpl $0x6, %eax
ja 0x4f85
leaq 0xd8bd(%rip), %rcx      # 0x122b0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl 0x64(%r15), %eax
imulq $0xa0, %rax, %r15
addq 0x1835a(%rip), %r15     # 0x1cd68
movq %r14, %rdi
movq %r15, %rsi
callq 0x9d1e
testb %al, %al
je 0x4f5c
movl (%r14), %eax
movl (%r15), %ecx
andq $0x0, 0x20(%rbx)
xorl %edx, %edx
movb %dl, 0x28(%rbx)
movb %dl, 0x48(%rbx)
movb %dl, 0x34(%rbx)
andq $0x0, 0x2c(%rbx)
movl $0x2, (%rbx)
movl %eax, 0x4(%rbx)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x8(%rbx)
movl %ecx, 0x18(%rbx)
jmp 0x4f47
movq 0x6c(%r15), %xmm0
pxor %xmm1, %xmm1
pcmpeqd %xmm0, %xmm1
movq 0x1827c(%rip), %xmm0    # 0x1cce8
pcmpeqd %xmm2, %xmm2
paddd %xmm0, %xmm2
movdqa %xmm1, %xmm0
pandn %xmm2, %xmm0
psrld $0x1f, %xmm1
por %xmm0, %xmm1
cvtdq2pd %xmm1, %xmm0
leaq 0x60(%rsp), %rdx
movapd %xmm0, (%rdx)
movsd 0x8(%r14), %xmm1
movsd 0x10(%r14), %xmm2
subsd %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
subsd %xmm0, %xmm2
mulsd %xmm2, %xmm2
mulsd %xmm1, %xmm1
addsd %xmm2, %xmm1
sqrtsd %xmm1, %xmm1
movsd 0xd646(%rip), %xmm0     # 0x12108
minsd %xmm1, %xmm0
andl $0x0, 0x8(%rsp)
orl $-0x1, (%rsp)
pushq $0x1
popq %rcx
xorpd %xmm1, %xmm1
jmp 0x4da0
movl 0x68(%r15), %eax
leaq 0x30(%rsp), %r15
movl %eax, (%r15)
leaq 0x18632(%rip), %rdi     # 0x1d120
movq %r15, %rsi
callq 0x9e20
movq (%rax), %rsi
leaq 0x60(%rsp), %r12
movl $0x88, %edx
movq %r12, %rdi
callq 0x21e0
movupd 0x8(%r12), %xmm1
movapd %xmm1, 0x10(%rsp)
movupd 0x8(%r14), %xmm0
subpd %xmm0, %xmm1
movapd %xmm1, (%r15)
leaq 0x30(%rsp), %rdi
callq 0x9e6e
movupd 0x8(%r14), %xmm2
movapd 0x10(%rsp), %xmm3
subpd %xmm2, %xmm3
movapd %xmm3, %xmm4
mulpd %xmm3, %xmm4
unpckhpd %xmm4, %xmm4            # xmm4 = xmm4[1,1]
mulsd %xmm3, %xmm3
addsd %xmm4, %xmm3
sqrtsd %xmm3, %xmm3
maxsd 0xd5a7(%rip), %xmm3     # 0x12108
unpcklpd %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0]
unpcklpd %xmm3, %xmm3            # xmm3 = xmm3[0,0]
mulpd %xmm0, %xmm3
addpd %xmm2, %xmm3
leaq 0x50(%rsp), %rsi
movapd %xmm3, (%rsi)
leaq 0x18167(%rip), %rdi     # 0x1cce8
movsd 0xd507(%rip), %xmm0     # 0x12090
callq 0x9c1c
testb %al, %al
jne 0x4bcc
movupd 0x8(%r14), %xmm0
movapd 0x10(%rsp), %xmm1
subpd %xmm0, %xmm1
leaq 0x30(%rsp), %rdi
movapd %xmm1, (%rdi)
callq 0x9e6e
unpcklpd %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0]
mulpd 0xd6a4(%rip), %xmm0     # 0x12260
movupd 0x8(%r14), %xmm1
addpd %xmm0, %xmm1
movapd %xmm1, 0x50(%rsp)
leaq 0x181e5(%rip), %rdi     # 0x1cdb8
leaq 0x60(%rsp), %r15
movq %r15, %rsi
callq 0x9ec4
movsd (%rax), %xmm0
ucomisd 0x8(%r15), %xmm0
jne 0x4bfd
jp 0x4bfd
movsd 0x8(%rax), %xmm0
ucomisd 0x70(%rsp), %xmm0
jne 0x4bfd
jnp 0x4c18
leaq 0x181b4(%rip), %rdi     # 0x1cdb8
leaq 0x60(%rsp), %rsi
callq 0x9ec4
movupd (%rax), %xmm0
movapd %xmm0, 0x50(%rsp)
movsd 0x8(%r14), %xmm0
movsd 0x10(%r14), %xmm1
movl (%r14), %edx
leaq 0x30(%rsp), %r12
movsd 0xd3ec(%rip), %xmm2     # 0x12020
pushq $0x2
popq %rsi
movq %r12, %rdi
callq 0x2d33
movq (%r12), %r15
movq 0x8(%r12), %r13
movsd 0xd420(%rip), %xmm0     # 0x12070
movsd %xmm0, 0x10(%rsp)
leaq 0x1824b(%rip), %r12     # 0x1cea8
cmpq %r13, %r15
je 0x4dba
movq %r12, %rdi
movq %r15, %rsi
callq 0x9d46
movsd (%rax), %xmm0
minsd 0x10(%rsp), %xmm0
addq $0x78, %r15
movsd %xmm0, 0x10(%rsp)
jmp 0x4c5d
movl (%r14), %eax
andq $0x0, 0x20(%rbx)
xorl %ecx, %ecx
movb %cl, 0x28(%rbx)
movb %cl, 0x48(%rbx)
movb %cl, 0x34(%rbx)
andq $0x0, 0x2c(%rbx)
movl $0x3, (%rbx)
movl %eax, 0x4(%rbx)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x8(%rbx)
andl $0x0, 0x18(%rbx)
jmp 0x4f47
movl 0x68(%r15), %eax
leaq 0x30(%rsp), %rsi
movl %eax, (%rsi)
leaq 0x18454(%rip), %rdi     # 0x1d120
callq 0x9e20
movq (%rax), %rsi
leaq 0x60(%rsp), %rdi
movl $0x88, %edx
callq 0x21e0
leaq 0x68(%rsp), %r15
movsd 0x8(%r14), %xmm0
movsd 0x10(%r14), %xmm1
movl (%r14), %edx
leaq 0x30(%rsp), %r13
movsd 0xd31c(%rip), %xmm2     # 0x12020
pushq $0x2
popq %rsi
movq %r13, %rdi
callq 0x2d33
movq (%r13), %r12
movq 0x8(%r13), %rbp
movsd 0xd351(%rip), %xmm0     # 0x12070
movsd %xmm0, 0x10(%rsp)
leaq 0x1817c(%rip), %r13     # 0x1cea8
cmpq %rbp, %r12
je 0x4e82
movq %r13, %rdi
movq %r12, %rsi
callq 0x9d46
movsd (%rax), %xmm0
minsd 0x10(%rsp), %xmm0
addq $0x78, %r12
movsd %xmm0, 0x10(%rsp)
jmp 0x4d2c
movl 0x68(%r15), %eax
leaq 0x30(%rsp), %rsi
movl %eax, (%rsi)
leaq 0x183b8(%rip), %rdi     # 0x1d120
callq 0x9e20
movq (%rax), %rsi
leaq 0x60(%rsp), %rdi
movl $0x88, %edx
callq 0x21e0
leaq 0x68(%rsp), %rdx
andl $0x0, 0x8(%rsp)
orl $-0x1, (%rsp)
movsd 0xd373(%rip), %xmm0     # 0x12108
movsd 0xd3bb(%rip), %xmm1     # 0x12158
pushq $0x1
popq %rcx
movq %rbx, %rdi
movq %r14, %rsi
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x3700
andl $0x0, 0x30(%rbx)
jmp 0x4f47
leaq 0x30(%rsp), %rdi
callq 0xd7f8
leaq 0x180dd(%rip), %rdi     # 0x1cea8
movq %r14, %rsi
callq 0x9d46
movsd (%rax), %xmm0
movsd %xmm0, 0x28(%rsp)
leaq 0x18124(%rip), %rdi     # 0x1cf08
leaq 0x60(%rsp), %rsi
callq 0x9cd0
cmpl $0x3, (%rax)
movsd 0xd30f(%rip), %xmm0     # 0x12108
jl 0x4e51
movsd 0xd35d(%rip), %xmm1     # 0x12160
movsd 0x28(%rsp), %xmm2
ucomisd %xmm2, %xmm1
jbe 0x4e51
movsd 0xd239(%rip), %xmm1     # 0x12050
movsd 0x10(%rsp), %xmm3
ucomisd %xmm3, %xmm1
jbe 0x4e51
ucomisd %xmm2, %xmm3
jbe 0x4e51
subsd %xmm2, %xmm3
movsd 0xd333(%rip), %xmm1     # 0x12168
divsd %xmm1, %xmm3
movsd 0xd2c7(%rip), %xmm2     # 0x12108
movapd %xmm2, %xmm0
subsd %xmm3, %xmm0
minsd %xmm2, %xmm0
maxsd %xmm1, %xmm0
andl $0x0, 0x8(%rsp)
orl $-0x1, (%rsp)
leaq 0x50(%rsp), %rdx
xorpd %xmm1, %xmm1
movq %rbx, %rdi
movq %r14, %rsi
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x3700
movl $0x1, 0x30(%rbx)
jmp 0x4f47
leaq 0x30(%rsp), %rdi
callq 0xd7f8
leaq 0x18015(%rip), %rdi     # 0x1cea8
movq %r14, %rsi
callq 0x9d46
movsd (%rax), %xmm0
movsd %xmm0, 0x28(%rsp)
leaq 0x1805c(%rip), %rdi     # 0x1cf08
leaq 0x60(%rsp), %rsi
callq 0x9cd0
cmpl $0x3, (%rax)
movsd 0xd247(%rip), %xmm0     # 0x12108
jl 0x4f19
movsd 0xd295(%rip), %xmm1     # 0x12160
movsd 0x28(%rsp), %xmm2
ucomisd %xmm2, %xmm1
jbe 0x4f19
movsd 0xd171(%rip), %xmm1     # 0x12050
movsd 0x10(%rsp), %xmm3
ucomisd %xmm3, %xmm1
jbe 0x4f19
ucomisd %xmm2, %xmm3
jbe 0x4f19
subsd %xmm2, %xmm3
movsd 0xd26b(%rip), %xmm1     # 0x12168
divsd %xmm1, %xmm3
movsd 0xd1ff(%rip), %xmm2     # 0x12108
movapd %xmm2, %xmm0
subsd %xmm3, %xmm0
minsd %xmm2, %xmm0
maxsd %xmm1, %xmm0
andl $0x0, 0x8(%rsp)
orl $-0x1, (%rsp)
movsd 0xd22e(%rip), %xmm1     # 0x12158
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x3700
movl $0x2, 0x30(%rbx)
movq %rbx, %rax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addq $0x8, %r15
andl $0x0, 0x8(%rsp)
orl $-0x1, (%rsp)
movsd 0xd197(%rip), %xmm0     # 0x12108
xorpd %xmm1, %xmm1
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
jmp 0x4da6
leaq 0xd341(%rip), %rdi      # 0x122cd
leaq 0xd340(%rip), %rsi      # 0x122d3
leaq 0xd35d(%rip), %rcx      # 0x122f7
movl $0x2de, %edx            # imm = 0x2DE
callq 0x2170
jmp 0x4fa6
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0xd7f8
movq %rbx, %rdi
callq 0x23f0