// File: /workspace/github_c_makefile_star2_O3/QwazyWabbitWOS[P]lmctf60/p_view.c
// Function: SV_CalcViewOffset
void SV_CalcViewOffset (edict_t *ent)
{
	float		*angles;
	float		bob;
	float		ratio;
	float		delta;
	vec3_t		v;


//===================================

	// base angles
	angles = ent->client->ps.kick_angles;

	// if dead, fix the angle and don't add any kick
	if (ent->deadflag)
	{
		VectorClear (angles);

		ent->client->ps.viewangles[ROLL] = 40;
		ent->client->ps.viewangles[PITCH] = -15;
		ent->client->ps.viewangles[YAW] = ent->client->killer_yaw;
	}
	else
	{
		// add angles based on weapon kick

		VectorCopy (ent->client->kick_angles, angles);

		// add angles based on damage kick

		ratio = (ent->client->v_dmg_time - level.time) / DAMAGE_TIME;
		if (ratio < 0)
		{
			ratio = 0;
			ent->client->v_dmg_pitch = 0;
			ent->client->v_dmg_roll = 0;
		}
		angles[PITCH] += ratio * ent->client->v_dmg_pitch;
		angles[ROLL] += ratio * ent->client->v_dmg_roll;

		// add pitch based on fall kick

		ratio = (ent->client->fall_time - level.time) / FALL_TIME;
		if (ratio < 0)
			ratio = 0;
		angles[PITCH] += ratio * ent->client->fall_value;

		// add angles based on velocity

		delta = DotProduct (ent->velocity, forward);
		angles[PITCH] += delta*run_pitch->value;
		
		delta = DotProduct (ent->velocity, right);
		angles[ROLL] += delta*run_roll->value;

		// add angles based on bob

		delta = bobfracsin * bob_pitch->value * xyspeed;
		if (ent->client->ps.pmove.pm_flags & PMF_DUCKED)
			delta *= 6;		// crouching
		angles[PITCH] += delta;
		delta = bobfracsin * bob_roll->value * xyspeed;
		if (ent->client->ps.pmove.pm_flags & PMF_DUCKED)
			delta *= 6;		// crouching
		if (bobcycle & 1)
			delta = -delta;
		angles[ROLL] += delta;
	}

//===================================

	// base origin

	VectorClear (v);

	// add view height

	v[2] += ent->viewheight;

	// add fall height

	ratio = (ent->client->fall_time - level.time) / FALL_TIME;
	if (ratio < 0)
		ratio = 0;
	v[2] -= ratio * ent->client->fall_value * 0.4f;

	// add bob height

	bob = bobfracsin * xyspeed * bob_up->value;
	if (bob > 6)
		bob = 6;
	//gi.DebugGraph (bob *2, 255);
	v[2] += bob;

	// add kick offset

	VectorAdd (v, ent->client->kick_origin, v);

	// absolutely bound offsets
	// so the view can never be outside the player box

	if (v[0] < -14)
		v[0] = -14;
	else if (v[0] > 14)
		v[0] = 14;
	if (v[1] < -14)
		v[1] = -14;
	else if (v[1] > 14)
		v[1] = 14;
	if (v[2] < -22)
		v[2] = -22;
	else if (v[2] > 30)
		v[2] = 30;

	VectorCopy (v, ent->client->ps.viewoffset);
}

// Assembly:
movq 0x58(%rdi), %rax
cmpl $0x0, 0x260(%rdi)
je 0x4a0aa
movl $0x0, 0x3c(%rax)
movq $0x0, 0x34(%rax)
movl $0x42200000, 0x24(%rax) # imm = 0x42200000
movl $0xc1700000, 0x1c(%rax) # imm = 0xC1700000
movss 0xe74(%rax), %xmm1
movss 0xea0(%rax), %xmm0
movss %xmm1, 0x20(%rax)
movq 0x1ed26(%rip), %rcx     # 0x68da0
movss 0xea4(%rax), %xmm1
movq 0x1ebef(%rip), %rdx     # 0x68c78
movss (%rdx), %xmm3
movq 0x1eeb4(%rip), %rdx     # 0x68f48
movss (%rdx), %xmm2
subss 0x4(%rcx), %xmm0
divss 0x10b43(%rip), %xmm0    # 0x5abe8
jmp 0x4a274
movss 0xe7c(%rax), %xmm1
movss 0xe80(%rax), %xmm0
movss %xmm0, 0x38(%rax)
movss 0xe84(%rax), %xmm0
movss 0xe9c(%rax), %xmm5
movq 0x1ecca(%rip), %rcx     # 0x68da0
movss 0x4(%rcx), %xmm3
subss %xmm3, %xmm5
addss %xmm5, %xmm5
xorps %xmm2, %xmm2
ucomiss %xmm5, %xmm2
jbe 0x4a0fe
movq $0x0, 0xe94(%rax)
xorps %xmm4, %xmm4
xorps %xmm5, %xmm5
jmp 0x4a10e
movss 0xe94(%rax), %xmm2
movss 0xe98(%rax), %xmm4
mulss %xmm5, %xmm4
addss %xmm1, %xmm4
mulss %xmm5, %xmm2
addss %xmm0, %xmm2
movss %xmm2, 0x3c(%rax)
movss 0xea0(%rax), %xmm0
movss 0xea4(%rax), %xmm1
subss %xmm3, %xmm0
divss 0x10aa9(%rip), %xmm0    # 0x5abe8
xorps %xmm3, %xmm3
maxss %xmm0, %xmm3
mulss %xmm1, %xmm3
addss %xmm4, %xmm3
movss %xmm3, 0x34(%rax)
movss 0x1c4(%rdi), %xmm4
mulss 0x4eef9(%rip), %xmm4    # 0x9905c
movss 0x1c0(%rdi), %xmm6
mulss 0x4eee5(%rip), %xmm6    # 0x99058
addss %xmm4, %xmm6
movss 0x1c8(%rdi), %xmm5
mulss 0x4eed9(%rip), %xmm5    # 0x99060
addss %xmm6, %xmm5
movq 0x1e4c6(%rip), %rcx     # 0x68658
movq (%rcx), %rcx
mulss 0x20(%rcx), %xmm5
addss %xmm3, %xmm5
movss %xmm5, 0x34(%rax)
movss 0x1c0(%rdi), %xmm3
movss 0x1c4(%rdi), %xmm6
mulss 0x4ee91(%rip), %xmm6    # 0x9904c
mulss 0x4ee85(%rip), %xmm3    # 0x99048
movss 0x1c8(%rdi), %xmm4
mulss 0x4ee7d(%rip), %xmm4    # 0x99050
addss %xmm6, %xmm3
addss %xmm3, %xmm4
movq 0x1ed06(%rip), %rcx     # 0x68ee8
movq (%rcx), %rcx
mulss 0x20(%rcx), %xmm4
addss %xmm2, %xmm4
movss %xmm4, 0x3c(%rax)
movq 0x1ea7e(%rip), %rcx     # 0x68c78
movss (%rcx), %xmm3
movq 0x1e833(%rip), %rcx     # 0x68a38
movq (%rcx), %rcx
movss 0x20(%rcx), %xmm7
mulss %xmm3, %xmm7
movq 0x1ed30(%rip), %rcx     # 0x68f48
movss (%rcx), %xmm2
mulss %xmm2, %xmm7
testb $0x1, 0x10(%rax)
movss 0x8cd8(%rip), %xmm6     # 0x52f04
je 0x4a232
mulss %xmm6, %xmm7
addss %xmm7, %xmm5
movss %xmm5, 0x34(%rax)
movq 0x1ea26(%rip), %rcx     # 0x68c68
movq (%rcx), %rcx
movss 0x20(%rcx), %xmm5
mulss %xmm3, %xmm5
mulss %xmm2, %xmm5
je 0x4a258
mulss %xmm6, %xmm5
movq 0x1e931(%rip), %rcx     # 0x68b90
testb $0x1, (%rcx)
je 0x4a26b
xorps 0xba65(%rip), %xmm5     # 0x55cd0
addss %xmm5, %xmm4
movss %xmm4, 0x3c(%rax)
mulss %xmm3, %xmm2
xorps %xmm4, %xmm4
cvtsi2ssl 0x278(%rdi), %xmm4
xorps %xmm3, %xmm3
xorps %xmm5, %xmm5
maxss %xmm0, %xmm5
mulss %xmm1, %xmm5
mulss 0x10953(%rip), %xmm5    # 0x5abec
addss %xmm4, %xmm5
movq 0x1e83c(%rip), %rcx     # 0x68ae0
movq (%rcx), %rcx
mulss 0x20(%rcx), %xmm2
movss 0x8c50(%rip), %xmm0     # 0x52f04
minss %xmm2, %xmm0
addss %xmm5, %xmm0
movss 0xe88(%rax), %xmm5
movss 0xe8c(%rax), %xmm4
movss 0x1091c(%rip), %xmm1    # 0x5abf0
ucomiss %xmm5, %xmm1
movaps %xmm1, %xmm2
ja 0x4a2f6
ucomiss 0x10911(%rip), %xmm5    # 0x5abf4
jbe 0x4a2ef
movss 0x10907(%rip), %xmm2    # 0x5abf4
jmp 0x4a2f6
addss %xmm3, %xmm5
movaps %xmm5, %xmm2
addss 0xe90(%rax), %xmm0
ucomiss %xmm4, %xmm1
ja 0x4a31d
ucomiss 0x108ea(%rip), %xmm4    # 0x5abf4
jbe 0x4a316
movss 0x108e0(%rip), %xmm1    # 0x5abf4
jmp 0x4a31d
addss %xmm3, %xmm4
movaps %xmm4, %xmm1
movss 0x108d3(%rip), %xmm3    # 0x5abf8
ucomiss %xmm0, %xmm3
ja 0x4a33e
ucomiss 0x8f63(%rip), %xmm0     # 0x53294
movaps %xmm0, %xmm3
jbe 0x4a33e
movss 0x8f56(%rip), %xmm3     # 0x53294
movss %xmm2, 0x28(%rax)
movss %xmm1, 0x2c(%rax)
movss %xmm3, 0x30(%rax)
retq