// File: /workspace/github_c_makefile_star2_O1/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 0x4accf
movl $0x0, 0x3c(%rax)
movq $0x0, 0x34(%rax)
movl $0x42200000, 0x24(%rax) # imm = 0x42200000
movl $0xc1700000, 0x1c(%rax) # imm = 0xC1700000
movss 0xe74(%rax), %xmm0
movss %xmm0, 0x20(%rax)
jmp 0x4ae81
movss 0xe7c(%rax), %xmm2
movss %xmm2, 0x34(%rax)
movq 0xe80(%rax), %rcx
movq %rcx, 0x38(%rax)
movss 0xe9c(%rax), %xmm0
movq 0x1f0aa(%rip), %rcx     # 0x69da0
movss 0x4(%rcx), %xmm3
subss %xmm3, %xmm0
addss %xmm0, %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm0, %xmm1
jbe 0x4ad19
movq $0x0, 0xe94(%rax)
xorps %xmm0, %xmm0
movss 0xe98(%rax), %xmm4
mulss %xmm0, %xmm4
mulss 0xe94(%rax), %xmm0
addss %xmm2, %xmm4
addss 0x3c(%rax), %xmm0
movss %xmm0, 0x3c(%rax)
movss 0xea0(%rax), %xmm2
subss %xmm3, %xmm2
divss 0x10b69(%rip), %xmm2    # 0x5b8b8
maxss %xmm2, %xmm1
mulss 0xea4(%rax), %xmm1
addss %xmm4, %xmm1
movss %xmm1, 0x34(%rax)
movss 0x1c4(%rdi), %xmm2
mulss 0x4f2e8(%rip), %xmm2    # 0x9a05c
movss 0x1c0(%rdi), %xmm3
mulss 0x4f2d4(%rip), %xmm3    # 0x9a058
addss %xmm2, %xmm3
movss 0x1c8(%rdi), %xmm2
mulss 0x4f2c8(%rip), %xmm2    # 0x9a060
addss %xmm3, %xmm2
movq 0x1e8b5(%rip), %rcx     # 0x69658
movq (%rcx), %rcx
mulss 0x20(%rcx), %xmm2
addss %xmm1, %xmm2
movss %xmm2, 0x34(%rax)
movss 0x1c0(%rdi), %xmm3
movss 0x1c4(%rdi), %xmm4
mulss 0x4f280(%rip), %xmm4    # 0x9a04c
mulss 0x4f274(%rip), %xmm3    # 0x9a048
movss 0x1c8(%rdi), %xmm1
mulss 0x4f26c(%rip), %xmm1    # 0x9a050
addss %xmm4, %xmm3
addss %xmm3, %xmm1
movq 0x1f0f5(%rip), %rcx     # 0x69ee8
movq (%rcx), %rcx
mulss 0x20(%rcx), %xmm1
addss %xmm0, %xmm1
movss %xmm1, 0x3c(%rax)
movq 0x1ee6d(%rip), %rcx     # 0x69c78
movss (%rcx), %xmm3
movq 0x1ec22(%rip), %rcx     # 0x69a38
movq (%rcx), %rcx
movss 0x20(%rcx), %xmm5
mulss %xmm3, %xmm5
movq 0x1f11f(%rip), %rcx     # 0x69f48
movss (%rcx), %xmm0
mulss %xmm0, %xmm5
testb $0x1, 0x10(%rax)
movss 0x90c3(%rip), %xmm4     # 0x53f00
je 0x4ae43
mulss %xmm4, %xmm5
addss %xmm5, %xmm2
movss %xmm2, 0x34(%rax)
movq 0x1ee15(%rip), %rcx     # 0x69c68
movq (%rcx), %rcx
mulss 0x20(%rcx), %xmm3
mulss %xmm3, %xmm0
je 0x4ae65
mulss %xmm4, %xmm0
movq 0x1ed24(%rip), %rcx     # 0x69b90
testb $0x1, (%rcx)
je 0x4ae78
xorps 0xbd98(%rip), %xmm0     # 0x56c10
addss %xmm0, %xmm1
movss %xmm1, 0x3c(%rax)
xorps %xmm0, %xmm0
cvtsi2ssl 0x278(%rdi), %xmm0
movss 0xea0(%rax), %xmm1
movq 0x1ef05(%rip), %rcx     # 0x69da0
subss 0x4(%rcx), %xmm1
divss 0x10a10(%rip), %xmm1    # 0x5b8b8
xorps %xmm2, %xmm2
maxss %xmm1, %xmm2
mulss 0xea4(%rax), %xmm2
mulss 0x109fd(%rip), %xmm2    # 0x5b8bc
xorps %xmm1, %xmm1
addss %xmm0, %xmm2
movq 0x1edab(%rip), %rcx     # 0x69c78
movss (%rcx), %xmm3
movq 0x1f070(%rip), %rcx     # 0x69f48
mulss (%rcx), %xmm3
movq 0x1ebfd(%rip), %rcx     # 0x69ae0
movq (%rcx), %rcx
mulss 0x20(%rcx), %xmm3
movss 0x900d(%rip), %xmm0     # 0x53f00
minss %xmm3, %xmm0
addss %xmm2, %xmm0
movss 0xe88(%rax), %xmm5
movss 0xe8c(%rax), %xmm4
movss 0x109ad(%rip), %xmm2    # 0x5b8c0
ucomiss %xmm5, %xmm2
movaps %xmm2, %xmm3
ja 0x4af35
ucomiss 0x109a2(%rip), %xmm5    # 0x5b8c4
jbe 0x4af2e
movss 0x10998(%rip), %xmm3    # 0x5b8c4
jmp 0x4af35
addss %xmm1, %xmm5
movaps %xmm5, %xmm3
addss 0xe90(%rax), %xmm0
ucomiss %xmm4, %xmm2
ja 0x4af5c
ucomiss 0x1097b(%rip), %xmm4    # 0x5b8c4
jbe 0x4af55
movss 0x10971(%rip), %xmm2    # 0x5b8c4
jmp 0x4af5c
addss %xmm1, %xmm4
movaps %xmm4, %xmm2
movss 0x10964(%rip), %xmm1    # 0x5b8c8
ucomiss %xmm0, %xmm1
ja 0x4af7d
ucomiss 0x9324(%rip), %xmm0     # 0x54294
movaps %xmm0, %xmm1
jbe 0x4af7d
movss 0x9317(%rip), %xmm1     # 0x54294
movss %xmm3, 0x28(%rax)
movss %xmm2, 0x2c(%rax)
movss %xmm1, 0x30(%rax)
retq