// File: /workspace/github_c_makefile_star2_O3/QwazyWabbitWOS[P]lmctf60/g_func.c
// Function: plat_Accelerate
void plat_Accelerate (moveinfo_t *moveinfo)
{
	// are we decelerating?
	if (moveinfo->remaining_distance <= moveinfo->decel_distance)
	{
		if (moveinfo->remaining_distance < moveinfo->decel_distance)
		{
			if (moveinfo->next_speed)
			{
				moveinfo->current_speed = moveinfo->next_speed;
				moveinfo->next_speed = 0;
				return;
			}
			if (moveinfo->current_speed > moveinfo->decel)
				moveinfo->current_speed -= moveinfo->decel;
		}
		return;
	}

	// are we at full speed and need to start decelerating during this move?
	if (moveinfo->current_speed == moveinfo->move_speed)
		if ((moveinfo->remaining_distance - moveinfo->current_speed) < moveinfo->decel_distance)
		{
			float	p1_distance;
			float	p2_distance;
			float	distance;

			p1_distance = moveinfo->remaining_distance - moveinfo->decel_distance;
			p2_distance = moveinfo->move_speed * (1.0 - (p1_distance / moveinfo->move_speed));
			distance = p1_distance + p2_distance;
			moveinfo->current_speed = moveinfo->move_speed;
			moveinfo->next_speed = moveinfo->move_speed - moveinfo->decel * (p2_distance / distance);
			return;
		}

	// are we accelerating?
	if (moveinfo->current_speed < moveinfo->speed)
	{
		float	old_speed;
		float	p1_distance;
		float	p1_speed;
		float	p2_distance;
		float	distance;

		old_speed = moveinfo->current_speed;

		// figure simple acceleration up to move_speed
		moveinfo->current_speed += moveinfo->accel;
		if (moveinfo->current_speed > moveinfo->speed)
			moveinfo->current_speed = moveinfo->speed;

		// are we accelerating throughout this entire move?
		if ((moveinfo->remaining_distance - moveinfo->current_speed) >= moveinfo->decel_distance)
			return;

		// during this move we will accelrate from current_speed to move_speed
		// and cross over the decel_distance; figure the average speed for the
		// entire move
		p1_distance = moveinfo->remaining_distance - moveinfo->decel_distance;
		p1_speed = (old_speed + moveinfo->move_speed) / 2.0f;
		p2_distance = moveinfo->move_speed * (1.0 - (p1_distance / p1_speed));
		distance = p1_distance + p2_distance;
		moveinfo->current_speed = (p1_speed * (p1_distance / distance)) + (moveinfo->move_speed * (p2_distance / distance));
		moveinfo->next_speed = moveinfo->move_speed - moveinfo->decel * (p2_distance / distance);
		return;
	}

	// we are at constant velocity (move_speed)
	return;
}

// Assembly:
movss 0x6c(%rdi), %xmm1
movss 0x70(%rdi), %xmm3
ucomiss %xmm1, %xmm3
jae 0x2c801
movss 0x60(%rdi), %xmm2
movss 0x64(%rdi), %xmm0
ucomiss %xmm0, %xmm2
jne 0x2c823
jp 0x2c823
movaps %xmm1, %xmm4
subss %xmm2, %xmm4
ucomiss %xmm4, %xmm3
jbe 0x2c823
subss %xmm3, %xmm1
xorps %xmm2, %xmm2
cvtss2sd %xmm0, %xmm2
movaps %xmm1, %xmm3
divss %xmm0, %xmm3
cvtss2sd %xmm3, %xmm3
movsd 0x2953a(%rip), %xmm4    # 0x55d10
subsd %xmm3, %xmm4
mulsd %xmm2, %xmm4
xorps %xmm2, %xmm2
cvtsd2ss %xmm4, %xmm2
addss %xmm2, %xmm1
movss %xmm0, 0x60(%rdi)
divss %xmm1, %xmm2
mulss 0x44(%rdi), %xmm2
subss %xmm2, %xmm0
movss %xmm0, 0x68(%rdi)
retq
jbe 0x2c800
movss 0x68(%rdi), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x2c816
jnp 0x2c8b5
movss %xmm0, 0x60(%rdi)
movl $0x0, 0x68(%rdi)
retq
movss 0x40(%rdi), %xmm4
ucomiss %xmm2, %xmm4
jbe 0x2c800
movss 0x3c(%rdi), %xmm5
addss %xmm2, %xmm5
minss %xmm5, %xmm4
movss %xmm4, 0x60(%rdi)
movaps %xmm1, %xmm5
subss %xmm4, %xmm5
ucomiss %xmm3, %xmm5
jae 0x2c800
subss %xmm3, %xmm1
addss %xmm0, %xmm2
mulss 0x27ba5(%rip), %xmm2    # 0x54400
xorps %xmm3, %xmm3
cvtss2sd %xmm0, %xmm3
movaps %xmm1, %xmm4
divss %xmm2, %xmm4
cvtss2sd %xmm4, %xmm4
movsd 0x2949b(%rip), %xmm5    # 0x55d10
subsd %xmm4, %xmm5
mulsd %xmm3, %xmm5
xorps %xmm3, %xmm3
cvtsd2ss %xmm5, %xmm3
movaps %xmm1, %xmm4
addss %xmm3, %xmm4
divss %xmm4, %xmm1
divss %xmm4, %xmm3
movaps %xmm0, %xmm4
mulss %xmm3, %xmm4
mulss %xmm2, %xmm1
addss %xmm4, %xmm1
movss %xmm1, 0x60(%rdi)
mulss 0x44(%rdi), %xmm3
subss %xmm3, %xmm0
jmp 0x2c7fb
movss 0x44(%rdi), %xmm0
movss 0x60(%rdi), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x2c800
subss %xmm0, %xmm1
movss %xmm1, 0x60(%rdi)
retq