// File: /workspace/github_c_makefile_star2_O2/kernfel[P]fNEAT/robot-simplistic.c
// Function: move_robot_in_tilemaze
void move_robot_in_tilemaze( Robot *bot, TileMaze *maze, struct Robot_Params *params, double *controller_outputs ) {
	adjust_heading( bot, params, controller_outputs );
	
	double motor_output = controller_outputs[0];
	if ( fabs(motor_output) > params->motor_threshold ) {
		if ( motor_output > 0 )
			motor_output = motor_output - params->motor_threshold;
		else
			motor_output = motor_output + params->motor_threshold;
		double m_x = cos(bot->heading) * motor_output * params->motor_sensitivity;
		double m_y = sin(bot->heading) * motor_output * params->motor_sensitivity;
		
		// Intercepts of the likeliest points of collision
		double forward_x = m_x>0 ? m_x + params->radius : m_x - params->radius;
		double forward_y = m_y>0 ? m_y + params->radius : m_y - params->radius;
		int curtile_x = (int)(bot->x / maze->tile_width);
		int curtile_y = (int)(bot->y / maze->tile_width);
		int cross_x = (int)((bot->x + forward_x) / maze->tile_width) - curtile_x;
		int cross_y = (int)((bot->y + forward_y) / maze->tile_width) - curtile_y;
		double depth_x = (bot->x + forward_x - (cross_x>0 ? curtile_x+1 : curtile_x)*maze->tile_width) / forward_x;
		double depth_y = (bot->y + forward_y - (cross_y>0 ? curtile_y+1 : curtile_y)*maze->tile_width) / forward_y;
		
		double adjust=0;
		
		// Collision only with an x edge
		if ( cross_x && ! cross_y
		 && (  curtile_x+cross_x == maze->x || curtile_x+cross_x == -1
		    || ! maze->tiles[curtile_x+cross_x + maze->x*curtile_y]
		    )
		) {
			adjust = depth_x;
		
		// Collision only with a y edge
		} else if ( cross_y && ! cross_x
		 && (  curtile_y+cross_y == maze->y || curtile_y+cross_y == -1
		    || ! maze->tiles[curtile_x + maze->x*(curtile_y+cross_y)]
		    )
		) {
			adjust = depth_y;
		
		// Collision with both x and y edges, necessitating checks against adjacent and diagonal tiles
		} else if ( cross_x && cross_y ) {
			// Separating axis perpendicular to the bot's path, as a unit vector:
			double sep_axis_x = m_y / sqrt(m_x*m_x + m_y*m_y);
			double sep_axis_y = -m_x / sqrt(m_x*m_x + m_y*m_y);
			// Half size of a tile when projected onto the separating axis:
			double proj_tile_halfwidth = (fabs(sep_axis_x) + fabs(sep_axis_y)) * maze->tile_width/2;
			// Bot's center projected onto the separating axis
			double proj_bot = sep_axis_x*(bot->x+m_x) + sep_axis_y*(bot->y+m_y);
			
			// Check against solid x-adjacent tile
			if ( curtile_x+cross_x == maze->x || curtile_x+cross_x == -1 ) {
				adjust = depth_x;
			} else if ( ! maze->tiles[curtile_x+cross_x + maze->x*curtile_y] ) {
				// Do tile and bot share space on the separating axis?
				// Note, this may not be the case even with cross_x appropriately set, as the border-crossing may happen only
				// at the edge between the y-adjacent and diagonally adjacent tiles.
				double proj_tile_center = maze->tile_width * (sep_axis_x*(curtile_x+cross_x+0.5) + sep_axis_y*(curtile_y+0.5));
				if ( fabs(proj_bot - proj_tile_center) < params->radius + proj_tile_halfwidth ) {
					adjust = depth_x;
				}
			}
			
			// Check against solid y-adjacent tile
			if ( curtile_y+cross_y == maze->y || curtile_y+cross_y == -1 ) {
				adjust = max(adjust, depth_y);
			} else if ( ! maze->tiles[curtile_x + maze->x*(curtile_y+cross_y)] ) {
				// Do tile and bot share space on the separating axis?
				double proj_tile_center = maze->tile_width * (sep_axis_x*(curtile_x+0.5) + sep_axis_y*(curtile_y+cross_y+0.5));
				if ( fabs(proj_bot - proj_tile_center) < params->radius + proj_tile_halfwidth ) {
					adjust = max(adjust, depth_y);
				}
			}

			// If all else fails, check against solid diagonally adjacent tile
			if ( ! adjust && ! maze->tiles[curtile_x+cross_x + maze->x*(curtile_y+cross_y)] ) {
				// Project corner onto separating axis
				double corner_x = maze->tile_width * (curtile_x + (cross_x>0?1:0)), corner_y = maze->tile_width * (curtile_y + (cross_y>0?1:0));
				double proj_corner = sep_axis_x*corner_x + sep_axis_y*corner_y;
				
				// Colliding with corner:
				if ( fabs(proj_bot - proj_corner) < params->radius ) {
					double bc_x = corner_x - bot->x, bc_y = corner_y - bot->y;
					double norm_m = sqrt(m_x*m_x + m_y*m_y);
					double bf = (bc_x*m_x + bc_y*m_y) / norm_m; // Projection of bot-to-corner onto the bot's path (pt F)
					double fc = bc_x*sep_axis_x + bc_y*sep_axis_y; // Distance from the corner to pt F; fc < r.
					double fx = sqrt(params->radius*params->radius - fc*fc); // Distance from pt F to pushback point X
					if ( norm_m > bf - fx )
						adjust = 1 - (bf - fx)/norm_m;
				
				// Colliding with the edge that continues one of curtile's y-parallel edges
				} else if ( (proj_bot > proj_corner && m_x < 0 && m_y > 0) // Bot heading UL
				 || (proj_bot < proj_corner && m_x < 0 && m_y < 0)         // Bot heading DL
				 || (proj_bot > proj_corner && m_x > 0 && m_y < 0)         // Bot heading DR
				 || (proj_bot < proj_corner && m_x > 0 && m_y > 0) ) {     // Bot heading UR
					adjust = depth_x;
				
				// Colliding with the edge that continues one of curtile's x-parallel edges
				} else if ( (proj_bot > proj_corner && m_x > 0 && m_y > 0) // Bot heading UR
				 || (proj_bot < proj_corner && m_x < 0 && m_y > 0)         // Bot heading UL
				 || (proj_bot > proj_corner && m_x < 0 && m_y < 0)         // Bot heading DL
				 || (proj_bot < proj_corner && m_x > 0 && m_y < 0) ) {     // Bot heading DR
					adjust = depth_y;
				}
			}
		}
		
		// Apply the adjusted movement vector
		bot->x += (1 - adjust) * m_x;
		bot->y += (1 - adjust) * m_y;
	}
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rcx, %r12
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
movq %rdx, %rsi
movq %rcx, %rdx
callq 0x4f5c
movsd (%r12), %xmm0
movapd 0xfa8(%rip), %xmm2      # 0x6240
andpd %xmm0, %xmm2
movsd 0x10(%r15), %xmm1
ucomisd %xmm1, %xmm2
jbe 0x57e3
movapd %xmm1, %xmm2
xorpd 0x1108(%rip), %xmm2     # 0x63c0
xorpd %xmm3, %xmm3
cmpltsd %xmm0, %xmm3
andpd %xmm3, %xmm2
andnpd %xmm1, %xmm3
orpd %xmm2, %xmm3
addsd %xmm0, %xmm3
movapd %xmm3, 0x10(%rsp)
movsd 0x10(%rbx), %xmm0
callq 0x1080
movaps %xmm0, (%rsp)
movsd 0x10(%rbx), %xmm0
movsd 0x8(%r15), %xmm1
movaps %xmm1, 0x20(%rsp)
callq 0x1130
movapd 0x20(%rsp), %xmm15
movapd %xmm0, %xmm1
movsd (%r15), %xmm0
movsd (%r14), %xmm4
movapd 0x10(%rsp), %xmm2
unpcklpd %xmm2, %xmm2            # xmm2 = xmm2[0,0]
movapd (%rsp), %xmm3
unpcklpd %xmm1, %xmm3            # xmm3 = xmm3[0],xmm1[0]
movhpd 0x8(%r15), %xmm15       # xmm15 = xmm15[0],mem[0]
mulpd %xmm2, %xmm3
mulpd %xmm3, %xmm15
movupd (%rbx), %xmm1
movapd %xmm0, %xmm2
unpcklpd %xmm0, %xmm2            # xmm2 = xmm2[0],xmm0[0]
movapd 0x107b(%rip), %xmm3     # 0x63c0
xorpd %xmm2, %xmm3
xorpd %xmm5, %xmm5
cmpltpd %xmm15, %xmm5
andpd %xmm5, %xmm2
andnpd %xmm3, %xmm5
orpd %xmm2, %xmm5
addpd %xmm15, %xmm5
movapd %xmm4, %xmm2
unpcklpd %xmm4, %xmm2            # xmm2 = xmm2[0],xmm4[0]
movapd %xmm1, %xmm3
divpd %xmm2, %xmm3
cvttpd2dq %xmm3, %xmm8
pshufd $0x55, %xmm8, %xmm3     # xmm3 = xmm8[1,1,1,1]
movd %xmm3, %esi
movd %xmm8, %edx
movapd %xmm5, %xmm13
addpd %xmm1, %xmm13
movapd %xmm13, %xmm3
divpd %xmm2, %xmm3
cvttpd2dq %xmm3, %xmm7
pshufd $0x55, %xmm7, %xmm2     # xmm2 = xmm7[1,1,1,1]
movd %xmm2, %ecx
movd %xmm7, %eax
xorl %r9d, %r9d
cmpl %edx, %eax
setg %r9b
addl %edx, %r9d
xorl %edi, %edi
cmpl %esi, %ecx
setg %r8b
cvtsi2sd %r9d, %xmm3
mulsd %xmm4, %xmm3
movapd %xmm13, %xmm2
subsd %xmm3, %xmm2
divsd %xmm5, %xmm2
cmpl %edx, %eax
je 0x5412
cmpl %esi, %ecx
jne 0x5412
movl 0x8(%r14), %r9d
cmpl %eax, %r9d
sete %r10b
cmpl $-0x1, %eax
sete %r11b
orb %r10b, %r11b
jne 0x57c0
movq 0x10(%r14), %r10
imull %esi, %r9d
addl %eax, %r9d
movslq %r9d, %r9
cmpb $0x0, (%r10,%r9)
je 0x57c0
movb %r8b, %dil
addl %esi, %edi
cvtsi2sd %edi, %xmm6
unpckhpd %xmm13, %xmm13          # xmm13 = xmm13[1,1]
mulsd %xmm4, %xmm6
subsd %xmm6, %xmm13
unpckhpd %xmm5, %xmm5            # xmm5 = xmm5[1,1]
divsd %xmm5, %xmm13
pcmpeqd %xmm8, %xmm7
movd %xmm7, %edi
notl %edi
testb $0x1, %dil
jne 0x547f
pextrw $0x2, %xmm7, %r8d
testb $0x1, %r8b
jne 0x547f
cmpl $-0x1, %ecx
je 0x57c5
cmpl %ecx, 0xc(%r14)
je 0x57c5
movq 0x10(%r14), %r8
movl 0x8(%r14), %r9d
imull %ecx, %r9d
addl %edx, %r9d
movslq %r9d, %r9
cmpb $0x0, (%r8,%r9)
je 0x57c5
cmpl %esi, %ecx
setne %r8b
andb %r8b, %dil
cmpb $0x1, %dil
jne 0x5669
movapd %xmm15, %xmm5
unpckhpd %xmm15, %xmm5           # xmm5 = xmm5[1],xmm15[1]
movapd %xmm5, %xmm7
mulsd %xmm5, %xmm7
movapd %xmm15, %xmm8
mulsd %xmm15, %xmm8
addsd %xmm7, %xmm8
sqrtsd %xmm8, %xmm7
movapd %xmm5, %xmm8
divsd %xmm7, %xmm8
movapd 0xef5(%rip), %xmm9      # 0x63c0
xorpd %xmm15, %xmm9
movsd %xmm7, 0x10(%rsp)
divsd %xmm7, %xmm9
movapd 0xd5c(%rip), %xmm11     # 0x6240
movapd %xmm8, %xmm7
andpd %xmm11, %xmm7
andpd %xmm9, %xmm11
addsd %xmm7, %xmm11
mulsd %xmm4, %xmm11
mulsd 0xc1a(%rip), %xmm11     # 0x6120
movapd %xmm15, %xmm7
addsd %xmm1, %xmm7
movapd %xmm1, %xmm10
unpckhpd %xmm1, %xmm10           # xmm10 = xmm10[1],xmm1[1]
movapd %xmm5, %xmm12
addsd %xmm10, %xmm12
mulsd %xmm9, %xmm12
mulsd %xmm8, %xmm7
addsd %xmm12, %xmm7
movl 0x8(%r14), %edi
cmpl %eax, %edi
sete %r8b
cmpl $-0x1, %eax
sete %r9b
orb %r8b, %r9b
movapd %xmm2, %xmm14
jne 0x55c2
movq 0x10(%r14), %r8
movl %edi, %r9d
imull %esi, %r9d
addl %eax, %r9d
movslq %r9d, %r9
xorpd %xmm14, %xmm14
cmpb $0x0, (%r8,%r9)
jne 0x55c2
cvtsi2sd %eax, %xmm12
addsd 0xba8(%rip), %xmm12     # 0x6120
cvtsi2sd %esi, %xmm14
addsd 0xb9a(%rip), %xmm14     # 0x6120
mulsd %xmm9, %xmm14
mulsd %xmm8, %xmm12
addsd %xmm14, %xmm12
mulsd %xmm4, %xmm12
movapd %xmm7, %xmm14
subsd %xmm12, %xmm14
andpd 0xc93(%rip), %xmm14     # 0x6240
movapd %xmm11, %xmm12
addsd %xmm0, %xmm12
cmpltsd %xmm12, %xmm14
andpd %xmm2, %xmm14
cmpl $-0x1, %ecx
je 0x5673
cmpl %ecx, 0xc(%r14)
je 0x5673
movq 0x10(%r14), %rsi
movl %edi, %r8d
imull %ecx, %r8d
addl %edx, %r8d
movslq %r8d, %r8
cmpb $0x0, (%rsi,%r8)
jne 0x5678
cvtsi2sd %edx, %xmm12
addsd 0xb21(%rip), %xmm12     # 0x6120
movapd %xmm14, (%rsp)
cvtsi2sd %ecx, %xmm14
addsd 0xb0d(%rip), %xmm14     # 0x6120
mulsd %xmm9, %xmm14
mulsd %xmm8, %xmm12
addsd %xmm14, %xmm12
mulsd %xmm4, %xmm12
movapd %xmm7, %xmm4
subsd %xmm12, %xmm4
andpd 0xc08(%rip), %xmm4      # 0x6240
addsd %xmm0, %xmm11
movapd (%rsp), %xmm14
movapd %xmm14, %xmm12
maxsd %xmm13, %xmm12
cmpltsd %xmm11, %xmm4
andpd %xmm4, %xmm12
andnpd %xmm14, %xmm4
orpd %xmm12, %xmm4
movapd %xmm4, %xmm14
jmp 0x5678
xorpd %xmm13, %xmm13
jmp 0x57c5
maxsd %xmm13, %xmm14
xorpd %xmm4, %xmm4
ucomisd %xmm4, %xmm14
jne 0x5697
jp 0x5697
movq 0x10(%r14), %rdx
imull %ecx, %edi
addl %eax, %edi
movslq %edi, %rax
cmpb $0x0, (%rdx,%rax)
je 0x56a1
movapd %xmm14, %xmm13
jmp 0x57c5
movapd %xmm9, %xmm11
mulsd %xmm6, %xmm11
movapd %xmm8, %xmm4
mulsd %xmm3, %xmm4
addsd %xmm11, %xmm4
movapd %xmm7, %xmm11
subsd %xmm4, %xmm11
andpd 0xb74(%rip), %xmm11     # 0x6240
ucomisd %xmm11, %xmm0
jbe 0x5728
subsd %xmm1, %xmm3
subsd %xmm10, %xmm6
mulsd %xmm6, %xmm5
movapd %xmm3, %xmm13
mulsd %xmm15, %xmm13
addsd %xmm5, %xmm13
divsd 0x10(%rsp), %xmm13
mulsd %xmm6, %xmm9
mulsd %xmm8, %xmm3
addsd %xmm9, %xmm3
mulsd %xmm3, %xmm3
mulsd %xmm0, %xmm0
subsd %xmm3, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x57ef
sqrtsd %xmm0, %xmm0
jmp 0x581c
xorpd %xmm0, %xmm0
cmpltpd %xmm15, %xmm0
movapd %xmm4, %xmm3
cmpltpd %xmm7, %xmm3
xorpd %xmm6, %xmm6
movapd %xmm15, %xmm8
cmpltpd %xmm6, %xmm8
andpd %xmm3, %xmm8
movd %xmm8, %ecx
pextrw $0x4, %xmm0, %eax
testb $0x1, %al
je 0x5762
testb $0x1, %cl
jne 0x57c0
movapd %xmm7, %xmm3
cmpltpd %xmm4, %xmm3
xorpd %xmm0, %xmm0
movapd %xmm15, %xmm6
cmpltpd %xmm0, %xmm6
andpd %xmm3, %xmm6
movd %xmm6, %edx
testb $0x1, %dl
je 0x578c
ucomisd %xmm5, %xmm0
ja 0x57c0
ucomisd %xmm4, %xmm7
seta %dil
ucomisd %xmm0, %xmm15
seta %sil
andb %sil, %dil
cmpb $0x1, %dil
jne 0x57ac
ucomisd %xmm5, %xmm0
ja 0x57c0
ucomisd %xmm7, %xmm4
seta %r8b
andb %r8b, %sil
testb %sil, %al
je 0x585a
movapd %xmm2, %xmm13
movsd 0x943(%rip), %xmm0      # 0x6110
subsd %xmm13, %xmm0
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
mulpd %xmm15, %xmm0
addpd %xmm1, %xmm0
movupd %xmm0, (%rbx)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movapd %xmm15, 0x20(%rsp)
movapd %xmm13, 0x30(%rsp)
movapd %xmm14, (%rsp)
callq 0x1180
movapd (%rsp), %xmm14
movapd 0x30(%rsp), %xmm13
movapd 0x20(%rsp), %xmm15
subsd %xmm0, %xmm13
movapd %xmm13, %xmm0
movsd 0x10(%rsp), %xmm2
divsd %xmm2, %xmm0
movsd 0x8d8(%rip), %xmm1      # 0x6110
subsd %xmm0, %xmm1
cmpltsd %xmm2, %xmm13
andpd %xmm13, %xmm1
andnpd %xmm14, %xmm13
orpd %xmm1, %xmm13
movupd (%rbx), %xmm1
jmp 0x57c5
ucomisd %xmm5, %xmm0
seta %r8b
testb %r8b, %cl
jne 0x57c5
orb %dl, %dil
andb %dil, %al
testb $0x1, %al
jne 0x57c5
andb %r8b, %sil
je 0x5697
jmp 0x57c5