// File: /workspace/github_c_makefile_star2_O2/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 0x46266
andl $0x0, 0x3c(%rax)
andq $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 0x20b6a(%rip), %rcx     # 0x66da0
movss 0xea4(%rax), %xmm1
movq 0x20a33(%rip), %rdx     # 0x66c78
movss (%rdx), %xmm3
movq 0x20cf8(%rip), %rdx     # 0x66f48
movss (%rdx), %xmm2
subss 0x4(%rcx), %xmm0
divss 0x10947(%rip), %xmm0    # 0x56ba8
jmp 0x4642d
movss 0xe7c(%rax), %xmm1
movss 0xe80(%rax), %xmm0
movss %xmm0, 0x38(%rax)
movss 0xe84(%rax), %xmm0
movss 0xe9c(%rax), %xmm5
movq 0x20b0e(%rip), %rcx     # 0x66da0
movss 0x4(%rcx), %xmm3
subss %xmm3, %xmm5
addss %xmm5, %xmm5
xorps %xmm2, %xmm2
ucomiss %xmm5, %xmm2
jbe 0x462b7
andq $0x0, 0xe94(%rax)
xorps %xmm4, %xmm4
xorps %xmm5, %xmm5
jmp 0x462c7
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 0x108b0(%rip), %xmm0    # 0x56ba8
xorps %xmm3, %xmm3
maxss %xmm0, %xmm3
mulss %xmm1, %xmm3
addss %xmm4, %xmm3
movss %xmm3, 0x34(%rax)
movss 0x1c4(%rdi), %xmm4
mulss 0x50e40(%rip), %xmm4    # 0x9715c
movss 0x1c0(%rdi), %xmm6
mulss 0x50e2c(%rip), %xmm6    # 0x97158
addss %xmm4, %xmm6
movss 0x1c8(%rdi), %xmm5
mulss 0x50e20(%rip), %xmm5    # 0x97160
addss %xmm6, %xmm5
movq 0x2030d(%rip), %rcx     # 0x66658
movq (%rcx), %rcx
mulss 0x20(%rcx), %xmm5
addss %xmm3, %xmm5
movss %xmm5, 0x34(%rax)
movss 0x1c0(%rdi), %xmm3
movss 0x1c4(%rdi), %xmm6
mulss 0x50dd8(%rip), %xmm6    # 0x9714c
mulss 0x50dcc(%rip), %xmm3    # 0x97148
movss 0x1c8(%rdi), %xmm4
mulss 0x50dc4(%rip), %xmm4    # 0x97150
addss %xmm6, %xmm3
addss %xmm3, %xmm4
movq 0x20b4d(%rip), %rcx     # 0x66ee8
movq (%rcx), %rcx
mulss 0x20(%rcx), %xmm4
addss %xmm2, %xmm4
movss %xmm4, 0x3c(%rax)
movq 0x208c5(%rip), %rcx     # 0x66c78
movss (%rcx), %xmm3
movq 0x2067a(%rip), %rcx     # 0x66a38
movq (%rcx), %rcx
movss 0x20(%rcx), %xmm7
mulss %xmm3, %xmm7
movq 0x20b77(%rip), %rcx     # 0x66f48
movss (%rcx), %xmm2
mulss %xmm2, %xmm7
testb $0x1, 0x10(%rax)
movss 0x8b1b(%rip), %xmm6     # 0x4ef00
je 0x463eb
mulss %xmm6, %xmm7
addss %xmm7, %xmm5
movss %xmm5, 0x34(%rax)
movq 0x2086d(%rip), %rcx     # 0x66c68
movq (%rcx), %rcx
movss 0x20(%rcx), %xmm5
mulss %xmm3, %xmm5
mulss %xmm2, %xmm5
je 0x46411
mulss %xmm6, %xmm5
movq 0x20778(%rip), %rcx     # 0x66b90
testb $0x1, (%rcx)
je 0x46424
xorps 0xb88c(%rip), %xmm5     # 0x51cb0
addss %xmm5, %xmm4
movss %xmm4, 0x3c(%rax)
mulss %xmm3, %xmm2
cvtsi2ssl 0x278(%rdi), %xmm4
xorps %xmm3, %xmm3
xorps %xmm5, %xmm5
maxss %xmm0, %xmm5
mulss %xmm1, %xmm5
mulss 0x1075d(%rip), %xmm5    # 0x56bac
addss %xmm4, %xmm5
movq 0x20686(%rip), %rcx     # 0x66ae0
movq (%rcx), %rcx
mulss 0x20(%rcx), %xmm2
movss 0x8a96(%rip), %xmm0     # 0x4ef00
minss %xmm2, %xmm0
addss %xmm5, %xmm0
movss 0xe88(%rax), %xmm5
movss 0xe8c(%rax), %xmm4
movss 0x10726(%rip), %xmm1    # 0x56bb0
ucomiss %xmm5, %xmm1
movaps %xmm1, %xmm2
ja 0x464ac
ucomiss 0x1071b(%rip), %xmm5    # 0x56bb4
jbe 0x464a5
movss 0x10711(%rip), %xmm2    # 0x56bb4
jmp 0x464ac
addss %xmm3, %xmm5
movaps %xmm5, %xmm2
addss 0xe90(%rax), %xmm0
ucomiss %xmm4, %xmm1
ja 0x464d3
ucomiss 0x106f4(%rip), %xmm4    # 0x56bb4
jbe 0x464cc
movss 0x106ea(%rip), %xmm1    # 0x56bb4
jmp 0x464d3
addss %xmm3, %xmm4
movaps %xmm4, %xmm1
movss 0x106dd(%rip), %xmm3    # 0x56bb8
ucomiss %xmm0, %xmm3
ja 0x464f4
ucomiss 0x8dad(%rip), %xmm0     # 0x4f294
movaps %xmm0, %xmm3
jbe 0x464f4
movss 0x8da0(%rip), %xmm3     # 0x4f294
movss %xmm2, 0x28(%rax)
movss %xmm1, 0x2c(%rax)
movss %xmm3, 0x30(%rax)
retq