// File: /workspace/github_c_makefile_star2_O1/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rcx, %r12
movq %rdx, %r14
movq %rsi, %rbp
movq %rdi, %rbx
movq %rdx, %rsi
movq %rcx, %rdx
callq 0x5468
movsd (%r12), %xmm0
movapd 0x19d6(%rip), %xmm2     # 0x7180
andpd %xmm0, %xmm2
movsd 0x10(%r14), %xmm1
ucomisd %xmm1, %xmm2
jbe 0x5ec0
movapd %xmm1, %xmm2
xorpd 0x1b16(%rip), %xmm2     # 0x72e0
xorpd %xmm3, %xmm3
cmpltsd %xmm0, %xmm3
andpd %xmm3, %xmm2
andnpd %xmm1, %xmm3
orpd %xmm2, %xmm3
addsd %xmm0, %xmm3
movapd %xmm3, (%rsp)
movsd 0x10(%rbx), %xmm0
callq 0x1080
mulsd (%rsp), %xmm0
mulsd 0x8(%r14), %xmm0
movapd %xmm0, 0x30(%rsp)
movsd 0x10(%rbx), %xmm0
callq 0x1130
xorpd %xmm4, %xmm4
movapd 0x30(%rsp), %xmm8
movapd %xmm0, %xmm9
mulsd (%rsp), %xmm9
mulsd 0x8(%r14), %xmm9
movsd (%r14), %xmm0
movapd 0x1aaa(%rip), %xmm3     # 0x72e0
xorpd %xmm0, %xmm3
xorpd %xmm1, %xmm1
cmpltsd %xmm8, %xmm1
movapd %xmm1, %xmm2
andpd %xmm0, %xmm2
andnpd %xmm3, %xmm1
orpd %xmm2, %xmm1
addsd %xmm8, %xmm1
cmpltsd %xmm9, %xmm4
andpd %xmm4, %xmm0
andnpd %xmm3, %xmm4
orpd %xmm0, %xmm4
addsd %xmm9, %xmm4
movsd (%rbp), %xmm0
movsd (%rbx), %xmm2
movapd %xmm1, %xmm11
addsd %xmm2, %xmm11
divsd %xmm0, %xmm2
cvttsd2si %xmm2, %r13d
movsd 0x8(%rbx), %xmm2
movapd %xmm4, %xmm10
addsd %xmm2, %xmm10
divsd %xmm0, %xmm2
cvttsd2si %xmm2, %r15d
movapd %xmm11, %xmm2
divsd %xmm0, %xmm2
cvttsd2si %xmm2, %r12d
movapd %xmm10, %xmm2
divsd %xmm0, %xmm2
cvttsd2si %xmm2, %r8d
xorl %edx, %edx
cmpl %r13d, %r12d
setg %dl
addl %r13d, %edx
xorl %eax, %eax
cmpl %r15d, %r8d
setg %cl
xorps %xmm3, %xmm3
cvtsi2sd %edx, %xmm3
movapd %xmm3, %xmm2
mulsd %xmm0, %xmm2
subsd %xmm2, %xmm11
divsd %xmm1, %xmm11
cmpl %r13d, %r12d
je 0x5929
cmpl %r15d, %r8d
jne 0x5929
movl 0x8(%rbp), %edx
cmpl %r12d, %edx
sete %sil
cmpl $-0x1, %r12d
sete %dil
orb %sil, %dil
jne 0x5d48
movq 0x10(%rbp), %rsi
imull %r15d, %edx
addl %r12d, %edx
movslq %edx, %rdx
cmpb $0x0, (%rsi,%rdx)
je 0x5d48
movb %cl, %al
addl %r15d, %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
mulsd %xmm1, %xmm0
subsd %xmm0, %xmm10
divsd %xmm4, %xmm10
cmpl %r13d, %r12d
jne 0x597c
cmpl %r15d, %r8d
je 0x597c
cmpl $-0x1, %r8d
je 0x5e91
cmpl %r8d, 0xc(%rbp)
je 0x5e91
movq 0x10(%rbp), %rax
movl 0x8(%rbp), %ecx
imull %r8d, %ecx
addl %r13d, %ecx
movslq %ecx, %rcx
cmpb $0x0, (%rax,%rcx)
je 0x5e91
xorpd %xmm4, %xmm4
cmpl %r13d, %r12d
je 0x5e96
cmpl %r15d, %r8d
je 0x5e96
movsd %xmm1, 0x10(%rsp)
movsd %xmm3, 0x18(%rsp)
movapd %xmm9, %xmm0
mulsd %xmm9, %xmm0
movapd %xmm8, %xmm15
mulsd %xmm8, %xmm15
addsd %xmm0, %xmm15
xorps %xmm1, %xmm1
sqrtsd %xmm15, %xmm1
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm15
movapd %xmm1, %xmm0
movsd %xmm9, (%rsp)
movapd %xmm10, 0x60(%rsp)
movapd %xmm11, 0x50(%rsp)
movq %rbp, 0x48(%rsp)
movapd %xmm15, 0x90(%rsp)
jae 0x5a3b
movapd %xmm15, %xmm0
movl %r8d, %ebp
movsd %xmm1, 0x20(%rsp)
callq 0x1180
xorpd %xmm2, %xmm2
movsd 0x20(%rsp), %xmm1
movapd 0x90(%rsp), %xmm15
movl %ebp, %r8d
movq 0x48(%rsp), %rbp
movapd 0x50(%rsp), %xmm11
movapd 0x60(%rsp), %xmm10
movsd (%rsp), %xmm9
movapd 0x30(%rsp), %xmm8
movapd %xmm9, %xmm13
divsd %xmm0, %xmm13
movapd 0x1892(%rip), %xmm14    # 0x72e0
xorpd %xmm8, %xmm14
ucomisd %xmm2, %xmm15
jae 0x5ab4
movapd %xmm15, %xmm0
movl %r8d, %ebp
movapd %xmm13, 0x20(%rsp)
movapd %xmm14, 0x70(%rsp)
callq 0x1180
movapd 0x90(%rsp), %xmm15
movapd 0x70(%rsp), %xmm14
movapd 0x20(%rsp), %xmm13
movl %ebp, %r8d
movq 0x48(%rsp), %rbp
movapd 0x50(%rsp), %xmm11
movapd 0x60(%rsp), %xmm10
movsd (%rsp), %xmm9
movapd 0x30(%rsp), %xmm8
movapd %xmm0, %xmm1
divsd %xmm1, %xmm14
movapd 0x16bf(%rip), %xmm4     # 0x7180
movapd %xmm13, %xmm0
andpd %xmm4, %xmm0
andpd %xmm14, %xmm4
addsd %xmm0, %xmm4
movsd (%rbp), %xmm3
mulsd %xmm3, %xmm4
mulsd 0x168c(%rip), %xmm4     # 0x7170
movsd (%rbx), %xmm2
movsd 0x8(%rbx), %xmm1
movapd %xmm8, %xmm0
addsd %xmm2, %xmm0
movapd %xmm9, %xmm5
addsd %xmm1, %xmm5
mulsd %xmm14, %xmm5
mulsd %xmm13, %xmm0
addsd %xmm5, %xmm0
movl 0x8(%rbp), %eax
cmpl %r12d, %eax
sete %cl
cmpl $-0x1, %r12d
sete %dl
orb %cl, %dl
movapd %xmm11, %xmm12
jne 0x5b97
movq 0x10(%rbp), %rcx
movl %eax, %edx
imull %r15d, %edx
addl %r12d, %edx
movslq %edx, %rdx
xorpd %xmm12, %xmm12
cmpb $0x0, (%rcx,%rdx)
jne 0x5b97
xorps %xmm5, %xmm5
cvtsi2sd %r12d, %xmm5
movsd 0x161f(%rip), %xmm6     # 0x7170
addsd %xmm6, %xmm5
cvtsi2sd %r15d, %xmm7
addsd %xmm6, %xmm7
mulsd %xmm14, %xmm7
mulsd %xmm13, %xmm5
addsd %xmm7, %xmm5
mulsd %xmm3, %xmm5
movapd %xmm0, %xmm12
subsd %xmm5, %xmm12
andpd 0x15fd(%rip), %xmm12    # 0x7180
movsd (%r14), %xmm5
addsd %xmm4, %xmm5
cmpltsd %xmm5, %xmm12
andpd %xmm11, %xmm12
cmpl $-0x1, %r8d
je 0x5c2b
cmpl %r8d, 0xc(%rbp)
je 0x5c2b
movq 0x10(%rbp), %rcx
movl %eax, %edx
imull %r8d, %edx
addl %r13d, %edx
movslq %edx, %rdx
cmpb $0x0, (%rcx,%rdx)
jne 0x5c30
xorps %xmm5, %xmm5
cvtsi2sd %r13d, %xmm5
movsd 0x159f(%rip), %xmm6     # 0x7170
xorps %xmm7, %xmm7
cvtsi2sd %r8d, %xmm7
addsd %xmm6, %xmm5
addsd %xmm6, %xmm7
mulsd %xmm14, %xmm7
mulsd %xmm13, %xmm5
addsd %xmm7, %xmm5
mulsd %xmm3, %xmm5
movapd %xmm0, %xmm6
subsd %xmm5, %xmm6
andpd 0x157d(%rip), %xmm6     # 0x7180
addsd (%r14), %xmm4
movapd %xmm12, %xmm5
maxsd %xmm10, %xmm5
cmpltsd %xmm4, %xmm6
andpd %xmm6, %xmm5
andnpd %xmm12, %xmm6
orpd %xmm5, %xmm6
movapd %xmm6, %xmm12
jmp 0x5c30
maxsd %xmm10, %xmm12
xorpd %xmm4, %xmm4
ucomisd %xmm4, %xmm12
jne 0x5c50
jp 0x5c50
movq 0x10(%rbp), %rcx
imull %r8d, %eax
addl %r12d, %eax
cltq
cmpb $0x0, (%rcx,%rax)
je 0x5c5a
movapd %xmm12, %xmm4
jmp 0x5e96
movsd 0x18(%rsp), %xmm6
mulsd %xmm3, %xmm6
movsd 0x10(%rsp), %xmm7
mulsd %xmm3, %xmm7
movapd %xmm14, %xmm4
mulsd %xmm7, %xmm4
movapd %xmm13, %xmm3
mulsd %xmm6, %xmm3
addsd %xmm4, %xmm3
movapd %xmm0, %xmm4
subsd %xmm3, %xmm4
andpd 0x14ec(%rip), %xmm4     # 0x7180
movsd (%r14), %xmm5
ucomisd %xmm4, %xmm5
jbe 0x5cd5
subsd %xmm2, %xmm6
subsd %xmm1, %xmm7
xorpd %xmm5, %xmm5
ucomisd %xmm5, %xmm15
movapd %xmm6, %xmm1
movapd %xmm7, %xmm2
movapd %xmm12, 0x80(%rsp)
jb 0x5d52
xorps %xmm3, %xmm3
sqrtsd %xmm15, %xmm3
jmp 0x5da5
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm9
movapd %xmm3, %xmm1
cmpltpd %xmm0, %xmm1
movapd %xmm8, %xmm4
cmpltpd %xmm2, %xmm4
andpd %xmm1, %xmm4
movd %xmm4, %eax
jbe 0x5cff
testb $0x1, %al
jne 0x5d48
cmpltpd %xmm3, %xmm0
movapd %xmm8, %xmm3
cmpltpd %xmm2, %xmm3
andpd %xmm0, %xmm3
movd %xmm3, %ecx
testb $0x1, %cl
je 0x5d22
ucomisd %xmm9, %xmm2
ja 0x5d48
xorpd %xmm3, %xmm3
cmpltpd %xmm8, %xmm2
andpd %xmm2, %xmm1
movd %xmm1, %edx
testb $0x1, %dl
je 0x5e4b
ucomisd %xmm9, %xmm3
jbe 0x5e4b
movapd %xmm11, %xmm4
jmp 0x5e96
movapd %xmm15, %xmm0
movsd %xmm1, 0x18(%rsp)
movsd %xmm2, 0x10(%rsp)
movapd %xmm13, 0x20(%rsp)
movapd %xmm14, 0x70(%rsp)
callq 0x1180
xorpd %xmm5, %xmm5
movapd 0x70(%rsp), %xmm14
movapd 0x20(%rsp), %xmm13
movsd 0x10(%rsp), %xmm2
movsd 0x18(%rsp), %xmm1
movsd (%rsp), %xmm9
movapd 0x30(%rsp), %xmm8
movapd %xmm0, %xmm3
movapd %xmm9, %xmm0
mulsd %xmm2, %xmm0
movapd %xmm1, %xmm4
mulsd %xmm8, %xmm4
addsd %xmm0, %xmm4
divsd %xmm3, %xmm4
mulsd %xmm2, %xmm14
mulsd %xmm1, %xmm13
addsd %xmm14, %xmm13
movsd (%r14), %xmm0
mulsd %xmm13, %xmm13
mulsd %xmm0, %xmm0
subsd %xmm13, %xmm0
ucomisd %xmm5, %xmm0
jb 0x5ded
sqrtsd %xmm0, %xmm0
jmp 0x5e17
movapd %xmm4, 0x60(%rsp)
movsd %xmm3, 0x50(%rsp)
callq 0x1180
movsd 0x50(%rsp), %xmm3
movapd 0x60(%rsp), %xmm4
movsd (%rsp), %xmm9
movapd 0x30(%rsp), %xmm8
movapd 0x80(%rsp), %xmm2
subsd %xmm0, %xmm4
movapd %xmm4, %xmm0
divsd %xmm3, %xmm0
movsd 0x120c(%rip), %xmm1     # 0x7040
subsd %xmm0, %xmm1
cmpltsd %xmm3, %xmm4
andpd %xmm4, %xmm1
andnpd %xmm2, %xmm4
orpd %xmm1, %xmm4
jmp 0x5e96
ucomisd %xmm3, %xmm9
andpd %xmm0, %xmm2
movd %xmm2, %esi
jbe 0x5e65
movapd %xmm11, %xmm4
testb $0x1, %sil
jne 0x5e96
xorpd %xmm0, %xmm0
ucomisd %xmm9, %xmm0
seta %dil
ucomisd %xmm0, %xmm9
seta %r8b
testb %dil, %al
jne 0x5e91
orb %cl, %dl
andb %dl, %r8b
jne 0x5e91
movapd %xmm12, %xmm4
andb %dil, %sil
je 0x5e96
movapd %xmm10, %xmm4
movsd 0x11a2(%rip), %xmm0     # 0x7040
subsd %xmm4, %xmm0
mulsd %xmm0, %xmm8
addsd (%rbx), %xmm8
movsd %xmm8, (%rbx)
mulsd %xmm9, %xmm0
addsd 0x8(%rbx), %xmm0
movsd %xmm0, 0x8(%rbx)
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq