// File: /workspace/github_c_makefile_star2_O2/kernfel[P]fNEAT/robot-simplistic.c
// Function: move_robot_in_room
void move_robot_in_room( Robot *bot, Room *room, struct Robot_Params *params, double *controller_outputs ) {
	// Adjust heading
	adjust_heading( bot, params, controller_outputs );

	// Calculate forward move
	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;

		// Detect depth of collision, if any
		double new_x = bot->x + m_x, new_y = bot->y + m_y;
		double adjust_x=0, adjust_y=0;
		if ( new_x - params->radius < 0 ) {
			adjust_x = -(params->radius - new_x) / m_x;
		} else if ( new_x + params->radius > room->x ) {
			adjust_x = (new_x + params->radius - room->x) / m_x;
		}
		if ( new_y - params->radius < 0 ) {
			adjust_y = -(params->radius - new_y) / m_y;
		} else if ( new_y + params->radius > room->y ) {
			adjust_y = (new_y + params->radius - room->y) / m_y;
		}

		// Apply the adjusted movement vector
		bot->x += (1-max(adjust_x, adjust_y)) * m_x;
		bot->y += (1-max(adjust_x, adjust_y)) * m_y;
	}
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x38, %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 0x124c(%rip), %xmm2     # 0x6240
andpd %xmm0, %xmm2
movsd 0x10(%r15), %xmm1
ucomisd %xmm1, %xmm2
jbe 0x5131
movapd 0x13b0(%rip), %xmm2     # 0x63c0
xorpd %xmm1, %xmm2
xorpd %xmm3, %xmm3
cmpltsd %xmm0, %xmm3
andpd %xmm3, %xmm2
andnpd %xmm1, %xmm3
orpd %xmm2, %xmm3
addsd %xmm0, %xmm3
movapd %xmm3, 0x20(%rsp)
movsd 0x10(%rbx), %xmm0
callq 0x1080
movaps %xmm0, 0x10(%rsp)
movsd 0x10(%rbx), %xmm0
movsd 0x8(%r15), %xmm1
movaps %xmm1, (%rsp)
callq 0x1130
movapd (%rsp), %xmm7
movapd 0x20(%rsp), %xmm1
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
movapd 0x10(%rsp), %xmm2
unpcklpd %xmm0, %xmm2            # xmm2 = xmm2[0],xmm0[0]
movhpd 0x8(%r15), %xmm7        # xmm7 = xmm7[0],mem[0]
mulpd %xmm1, %xmm2
mulpd %xmm2, %xmm7
movupd (%rbx), %xmm0
movapd %xmm7, %xmm4
addpd %xmm0, %xmm4
movapd %xmm7, %xmm1
unpckhpd %xmm7, %xmm1            # xmm1 = xmm1[1],xmm7[1]
movsd (%r15), %xmm2
ucomisd %xmm4, %xmm2
movapd %xmm4, %xmm3
unpckhpd %xmm4, %xmm3            # xmm3 = xmm3[1],xmm4[1]
jbe 0x50ba
movapd %xmm2, %xmm6
subsd %xmm4, %xmm6
xorpd 0x130c(%rip), %xmm6     # 0x63c0
divsd %xmm7, %xmm6
jmp 0x50d9
addsd %xmm2, %xmm4
movsd (%r14), %xmm5
ucomisd %xmm5, %xmm4
xorpd %xmm6, %xmm6
jbe 0x50d9
subsd %xmm5, %xmm4
divsd %xmm7, %xmm4
movapd %xmm4, %xmm6
ucomisd %xmm3, %xmm2
jbe 0x50f1
subsd %xmm3, %xmm2
xorpd 0x12d5(%rip), %xmm2     # 0x63c0
divsd %xmm1, %xmm2
jmp 0x5111
addsd %xmm2, %xmm3
movsd 0x8(%r14), %xmm4
xorpd %xmm2, %xmm2
ucomisd %xmm4, %xmm3
jbe 0x5111
subsd %xmm4, %xmm3
divsd %xmm1, %xmm3
movapd %xmm3, %xmm2
maxsd %xmm2, %xmm6
movsd 0xff3(%rip), %xmm1      # 0x6110
subsd %xmm6, %xmm1
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
mulpd %xmm7, %xmm1
addpd %xmm0, %xmm1
movupd %xmm1, (%rbx)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq