// File: /workspace/github_cpp_makefile_star2_O3/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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd0, %rsp
movq %rsi, %r15
movq %rdi, %rbx
movl 0x177f3(%rip), %esi     # 0x1dcdc
movl 0x60(%r15), %edx
leaq 0x177f4(%rip), %rdi     # 0x1dce8
callq 0xd6ae
movq %rax, %r14
movl (%r15), %eax
addl $-0x2, %eax
cmpl $0x6, %eax
ja 0x6b27
leaq 0xfdbe(%rip), %rcx      # 0x162d0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl 0x64(%r15), %ecx
movq 0x17842(%rip), %rax     # 0x1dd68
leaq (%rcx,%rcx,4), %rcx
shlq $0x5, %rcx
movsd 0x8(%r14), %xmm0
subsd 0x8(%rax,%rcx), %xmm0
movsd 0x10(%r14), %xmm1
subsd 0x10(%rax,%rcx), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
sqrtsd %xmm0, %xmm0
movsd 0x70(%rax,%rcx), %xmm1
addsd 0xfbac(%rip), %xmm1     # 0x16110
ucomisd %xmm0, %xmm1
jae 0x692c
leaq (%rax,%rcx), %rdx
addq $0x8, %rdx
xorl %r15d, %r15d
movsd 0xfb87(%rip), %xmm0     # 0x16108
xorpd %xmm1, %xmm1
movq %rbx, %rdi
movq %r14, %rsi
xorl %ecx, %ecx
jmp 0x6910
movq 0x6c(%r15), %xmm0
pxor %xmm1, %xmm1
pcmpeqd %xmm0, %xmm1
movq 0x17740(%rip), %xmm0    # 0x1dce8
pcmpeqd %xmm2, %xmm2
paddd %xmm0, %xmm2
movdqa %xmm1, %xmm0
pandn %xmm2, %xmm0
psrld $0x1f, %xmm1
por %xmm0, %xmm1
cvtdq2pd %xmm1, %xmm0
leaq 0x40(%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 0xfb0a(%rip), %xmm0     # 0x16108
minsd %xmm1, %xmm0
xorl %r15d, %r15d
xorpd %xmm1, %xmm1
jmp 0x6905
movl 0x68(%r15), %eax
leaq 0x18(%rsp), %rsi
movl %eax, (%rsi)
leaq 0x17b00(%rip), %rdi     # 0x1e120
callq 0xd884
movq (%rax), %rsi
leaq 0x40(%rsp), %r15
movl $0x88, %edx
movq %r15, %rdi
callq 0x31f0
movupd 0x8(%r14), %xmm0
movupd 0x8(%r15), %xmm3
subpd %xmm0, %xmm3
movapd %xmm3, %xmm1
mulpd %xmm3, %xmm1
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
movapd %xmm3, %xmm2
mulsd %xmm3, %xmm2
addsd %xmm1, %xmm2
xorps %xmm1, %xmm1
sqrtsd %xmm2, %xmm1
xorpd %xmm2, %xmm2
cmpneqsd %xmm1, %xmm2
movq %xmm2, %rax
andl $0x1, %eax
movapd %xmm1, %xmm2
unpcklpd %xmm1, %xmm2            # xmm2 = xmm2[0],xmm1[0]
divpd %xmm2, %xmm3
movd %eax, %xmm2
pshufd $0x0, %xmm2, %xmm2      # xmm2 = xmm2[0,0,0,0]
pslld $0x1f, %xmm2
psrad $0x1f, %xmm2
maxsd 0xfa67(%rip), %xmm1     # 0x16108
pand %xmm3, %xmm2
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
mulpd %xmm2, %xmm1
addpd %xmm0, %xmm1
movapd %xmm1, 0x30(%rsp)
ucomisd 0xf9d9(%rip), %xmm1     # 0x16098
jbe 0x6701
xorps %xmm3, %xmm3
cvtsi2sdl 0x1761c(%rip), %xmm3 # 0x1dce8
addsd 0xf9cc(%rip), %xmm3     # 0x160a0
ucomisd %xmm1, %xmm3
jbe 0x6701
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
ucomisd 0xf9b2(%rip), %xmm1     # 0x16098
jbe 0x6701
xorps %xmm3, %xmm3
cvtsi2sdl 0x175f9(%rip), %xmm3 # 0x1dcec
addsd 0xf9a5(%rip), %xmm3     # 0x160a0
ucomisd %xmm1, %xmm3
ja 0x6713
mulpd 0xfb77(%rip), %xmm2     # 0x16280
addpd %xmm2, %xmm0
movapd %xmm0, 0x30(%rsp)
leaq 0x1769e(%rip), %rdi     # 0x1ddb8
leaq 0x40(%rsp), %r15
movq %r15, %rsi
callq 0xd8ea
movsd (%rax), %xmm0
ucomisd 0x8(%r15), %xmm0
jne 0x6744
jp 0x6744
movsd 0x8(%rax), %xmm0
ucomisd 0x50(%rsp), %xmm0
jne 0x6744
jnp 0x675f
leaq 0x1766d(%rip), %rdi     # 0x1ddb8
leaq 0x40(%rsp), %rsi
callq 0xd8ea
movupd (%rax), %xmm0
movapd %xmm0, 0x30(%rsp)
movsd 0x8(%r14), %xmm0
movsd 0x10(%r14), %xmm1
movl (%r14), %edx
leaq 0x18(%rsp), %r12
movsd 0xf8a5(%rip), %xmm2     # 0x16020
movq %r12, %rdi
movl $0x2, %esi
callq 0x3ff2
movq (%r12), %r15
movq 0x8(%r12), %r13
movsd 0xf8e7(%rip), %xmm0     # 0x16080
cmpq %r13, %r15
je 0x6961
movsd %xmm0, 0x8(%rsp)
leaq 0x176f9(%rip), %r12     # 0x1dea8
movq %r12, %rdi
movq %r15, %rsi
callq 0xd7b8
movsd (%rax), %xmm0
minsd 0x8(%rsp), %xmm0
addq $0x78, %r15
movsd %xmm0, 0x8(%rsp)
cmpq %r13, %r15
jne 0x67af
movsd %xmm0, 0x10(%rsp)
movq 0x18(%rsp), %r15
jmp 0x6967
movl (%r14), %eax
xorl %ecx, %ecx
movq %rcx, 0x20(%rbx)
movb %cl, 0x28(%rbx)
movb %cl, 0x48(%rbx)
movq %rcx, 0x2c(%rbx)
movb %cl, 0x34(%rbx)
movl $0x3, (%rbx)
movl %eax, 0x4(%rbx)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x8(%rbx)
movl $0x0, 0x18(%rbx)
jmp 0x6b13
movl 0x68(%r15), %eax
leaq 0x18(%rsp), %rsi
movl %eax, (%rsi)
leaq 0x178f7(%rip), %rdi     # 0x1e120
callq 0xd884
movq (%rax), %rsi
leaq 0x40(%rsp), %rdi
movl $0x88, %edx
callq 0x31f0
movsd 0x8(%r14), %xmm0
movsd 0x10(%r14), %xmm1
movl (%r14), %edx
leaq 0x18(%rsp), %r12
movsd 0xf7c4(%rip), %xmm2     # 0x16020
movq %r12, %rdi
movl $0x2, %esi
callq 0x3ff2
movq (%r12), %r15
movq 0x8(%r12), %r13
movsd 0xf806(%rip), %xmm0     # 0x16080
cmpq %r13, %r15
je 0x6a39
movsd %xmm0, 0x8(%rsp)
leaq 0x17618(%rip), %r12     # 0x1dea8
movq %r12, %rdi
movq %r15, %rsi
callq 0xd7b8
movsd (%rax), %xmm0
minsd 0x8(%rsp), %xmm0
addq $0x78, %r15
movsd %xmm0, 0x8(%rsp)
cmpq %r13, %r15
jne 0x6890
movsd %xmm0, 0x10(%rsp)
movq 0x18(%rsp), %r15
jmp 0x6a3f
movl 0x68(%r15), %eax
leaq 0x18(%rsp), %rsi
movl %eax, (%rsi)
leaq 0x1784a(%rip), %rdi     # 0x1e120
callq 0xd884
movq (%rax), %rsi
leaq 0x40(%rsp), %rdi
movl $0x88, %edx
callq 0x31f0
leaq 0x48(%rsp), %rdx
xorl %r15d, %r15d
movsd 0xf80b(%rip), %xmm0     # 0x16108
movsd 0xf85b(%rip), %xmm1     # 0x16160
movq %rbx, %rdi
movq %r14, %rsi
movl $0x1, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
pushq %r15
pushq $-0x1
callq 0x4bbf
addq $0x10, %rsp
movl %r15d, 0x30(%rbx)
jmp 0x6b13
addq %rcx, %rax
movl (%r14), %ecx
movl (%rax), %eax
xorl %edx, %edx
movq %rdx, 0x20(%rbx)
movb %dl, 0x28(%rbx)
movb %dl, 0x48(%rbx)
movq %rdx, 0x2c(%rbx)
movb %dl, 0x34(%rbx)
movl $0x2, (%rbx)
movl %ecx, 0x4(%rbx)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x8(%rbx)
movl %eax, 0x18(%rbx)
jmp 0x6b13
movsd %xmm0, 0x10(%rsp)
testq %r15, %r15
je 0x697c
movq 0x28(%rsp), %rsi
subq %r15, %rsi
movq %r15, %rdi
callq 0x3240
leaq 0x17525(%rip), %rdi     # 0x1dea8
movq %r14, %rsi
callq 0xd7b8
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
leaq 0x1756c(%rip), %rdi     # 0x1df08
leaq 0x40(%rsp), %rsi
callq 0xd752
cmpl $0x3, (%rax)
movsd 0xf757(%rip), %xmm0     # 0x16108
jl 0x6a09
movsd 0xf7ad(%rip), %xmm1     # 0x16168
movsd 0x8(%rsp), %xmm2
ucomisd %xmm2, %xmm1
jbe 0x6a09
movsd 0xf681(%rip), %xmm1     # 0x16050
movsd 0x10(%rsp), %xmm3
ucomisd %xmm3, %xmm1
jbe 0x6a09
ucomisd %xmm2, %xmm3
jbe 0x6a09
subsd %xmm2, %xmm3
movsd 0xf783(%rip), %xmm1     # 0x16170
divsd %xmm1, %xmm3
movsd 0xf70f(%rip), %xmm2     # 0x16108
movapd %xmm2, %xmm0
subsd %xmm3, %xmm0
minsd %xmm2, %xmm0
maxsd %xmm1, %xmm0
leaq 0x30(%rsp), %rdx
xorpd %xmm1, %xmm1
movq %rbx, %rdi
movq %r14, %rsi
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
pushq $0x0
pushq $-0x1
callq 0x4bbf
addq $0x10, %rsp
movl $0x1, 0x30(%rbx)
jmp 0x6b13
movsd %xmm0, 0x10(%rsp)
testq %r15, %r15
je 0x6a54
movq 0x28(%rsp), %rsi
subq %r15, %rsi
movq %r15, %rdi
callq 0x3240
leaq 0x48(%rsp), %r15
leaq 0x17448(%rip), %rdi     # 0x1dea8
movq %r14, %rsi
callq 0xd7b8
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
leaq 0x1748f(%rip), %rdi     # 0x1df08
leaq 0x40(%rsp), %rsi
callq 0xd752
cmpl $0x3, (%rax)
movsd 0xf67a(%rip), %xmm0     # 0x16108
jl 0x6ae6
movsd 0xf6d0(%rip), %xmm1     # 0x16168
movsd 0x8(%rsp), %xmm2
ucomisd %xmm2, %xmm1
jbe 0x6ae6
movsd 0xf5a4(%rip), %xmm1     # 0x16050
movsd 0x10(%rsp), %xmm3
ucomisd %xmm3, %xmm1
jbe 0x6ae6
ucomisd %xmm2, %xmm3
jbe 0x6ae6
subsd %xmm2, %xmm3
movsd 0xf6a6(%rip), %xmm1     # 0x16170
divsd %xmm1, %xmm3
movsd 0xf632(%rip), %xmm2     # 0x16108
movapd %xmm2, %xmm0
subsd %xmm3, %xmm0
minsd %xmm2, %xmm0
maxsd %xmm1, %xmm0
movsd 0xf672(%rip), %xmm1     # 0x16160
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
pushq $0x0
pushq $-0x1
callq 0x4bbf
addq $0x10, %rsp
movl $0x2, 0x30(%rbx)
movq %rbx, %rax
addq $0xd0, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
leaq 0xf7bf(%rip), %rdi      # 0x162ed
leaq 0xf7be(%rip), %rsi      # 0x162f3
leaq 0xf7db(%rip), %rcx      # 0x16317
movl $0x2de, %edx            # imm = 0x2DE
callq 0x3160
jmp 0x6b48
movq %rax, %rbx
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x6b62
movq 0x28(%rsp), %rsi
subq %rdi, %rsi
callq 0x3240
movq %rbx, %rdi
callq 0x33d0