// File: /workspace/github_c_makefile_star2_O3/QwazyWabbitWOS[P]lmctf60/p_view.c
// Function: P_DamageFeedback
void P_DamageFeedback (edict_t *player)
{
	gclient_t	*client;
	float	side;
	float	realcount, count, kick;
	vec3_t	v;
	int		r, l;
	static	vec3_t	power_color = {0.0, 1.0, 0.0};
	static	vec3_t	acolor = {1.0, 1.0, 1.0};
	static	vec3_t	bcolor = {1.0, 0.0, 0.0};

	client = player->client;

	// flash the backgrounds behind the status numbers
	client->ps.stats[STAT_FLASHES] = 0;
	if (client->damage_blood)
		client->ps.stats[STAT_FLASHES] |= 1;
	if (client->damage_armor && !(player->flags & FL_GODMODE) && (client->invincible_framenum <= level.framenum))
		client->ps.stats[STAT_FLASHES] |= 2;

	// total points of damage shot at the player this frame
	count = (client->damage_blood + client->damage_armor + client->damage_parmor);
	if (count == 0)
		return;		// didn't take any damage

	// start a pain animation if still in the player model
	if (client->anim_priority < ANIM_PAIN && player->s.modelindex == 255)
	{
		static int		i;

		client->anim_priority = ANIM_PAIN;
		if (client->ps.pmove.pm_flags & PMF_DUCKED)
		{
			player->s.frame = FRAME_crpain1-1;
			client->anim_end = FRAME_crpain4;
		}
		else
		{
			i = (i+1)%3;
			switch (i)
			{
			case 0:
				player->s.frame = FRAME_pain101-1;
				client->anim_end = FRAME_pain104;
				break;
			case 1:
				player->s.frame = FRAME_pain201-1;
				client->anim_end = FRAME_pain204;
				break;
			case 2:
				player->s.frame = FRAME_pain301-1;
				client->anim_end = FRAME_pain304;
				break;
			}
		}
	}

	realcount = count;
	if (count < 10)
		count = 10;	// always make a visible effect

	// play an apropriate pain sound
	if ((level.time > player->pain_debounce_time) && !(player->flags & FL_GODMODE) && (client->invincible_framenum <= level.framenum))
	{
		r = 1 + (rand()&1);
		player->pain_debounce_time = level.time + 0.7;
		if (player->health < 25)
			l = 25;
		else if (player->health < 50)
			l = 50;
		else if (player->health < 75)
			l = 75;
		else
			l = 100;
		gi.sound (player, CHAN_VOICE, gi.soundindex(va("*pain%i_%i.wav", l, r)), 1, ATTN_NORM, 0);
	}

	// the total alpha of the blend is always proportional to count
	if (client->damage_alpha < 0)
		client->damage_alpha = 0;
	client->damage_alpha += count*0.01;
	if (client->damage_alpha < 0.2)
		client->damage_alpha = 0.2f;
	if (client->damage_alpha > 0.6)
		client->damage_alpha = 0.6f;		// don't go too saturated

	// the color of the blend will vary based on how much was absorbed
	// by different armors
	VectorClear (v);
	if (client->damage_parmor)
		VectorMA (v, (float)client->damage_parmor/realcount, power_color, v);
	if (client->damage_armor)
		VectorMA (v, (float)client->damage_armor/realcount,  acolor, v);
	if (client->damage_blood)
		VectorMA (v, (float)client->damage_blood/realcount,  bcolor, v);
	VectorCopy (v, client->damage_blend);


	//
	// calculate view angle kicks
	//
	kick = abs(client->damage_knockback);
	if (kick && player->health > 0)	// kick of 0 means no view adjust at all
	{
		kick = kick * 100 / player->health;

		if (kick < count*0.5)
			kick = count*0.5;
		if (kick > 50)
			kick = 50;

		VectorSubtract (client->damage_from, player->s.origin, v);
		VectorNormalize (v);
		
		side = DotProduct (v, right);
		client->v_dmg_roll = kick*side*0.3;
		
		side = -DotProduct (v, forward);
		client->v_dmg_pitch = kick*side*0.3;

		client->v_dmg_time = level.time + DAMAGE_TIME;
	}

	//
	// clear totals
	//
	client->damage_blood = 0;
	client->damage_armor = 0;
	client->damage_parmor = 0;
	client->damage_knockback = 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movq 0x58(%rdi), %r15
movl 0xe58(%r15), %ebp
movl 0xe60(%r15), %eax
xorl %ecx, %ecx
testl %eax, %eax
setne %cl
movw %cx, 0x96(%r15)
testl %ebp, %ebp
je 0x49bfc
testb $0x10, 0x11c(%rbx)
jne 0x49bfc
movq 0x1f1c0(%rip), %rdx     # 0x68da0
cvtsi2ssl (%rdx), %xmm0
ucomiss 0xf08(%r15), %xmm0
jb 0x49bfc
movzwl %cx, %ecx
orl $0x2, %ecx
movw %cx, 0x96(%r15)
addl %eax, %ebp
addl 0xe5c(%r15), %ebp
je 0x4a025
cmpl $0x2, 0xef8(%r15)
jg 0x49cb6
cmpl $0xff, 0x28(%rbx)
jne 0x49cb6
movl $0x3, 0xef8(%r15)
testb $0x1, 0x10(%r15)
jne 0x49c7c
movl 0x4f416(%rip), %eax     # 0x99054
movl %eax, %ecx
incl %ecx
movl $0xaaaaaaab, %edx       # imm = 0xAAAAAAAB
imulq %rcx, %rdx
shrq $0x21, %rdx
leal (%rdx,%rdx,2), %ecx
negl %ecx
addl %ecx, %eax
incl %eax
movl %eax, 0x4f3f6(%rip)     # 0x99054
cmpl $0x2, %eax
je 0x49c90
cmpl $0x1, %eax
jne 0x49ca4
movl $0x39, 0x38(%rbx)
movl $0x3d, 0xef4(%r15)
jmp 0x49cb6
movl $0xa8, 0x38(%rbx)
movl $0xac, 0xef4(%r15)
jmp 0x49cb6
movl $0x3d, 0x38(%rbx)
movl $0x41, 0xef4(%r15)
jmp 0x49cb6
movl $0x35, 0x38(%rbx)
movl $0x39, 0xef4(%r15)
cmpl $0xb, %ebp
movl $0xa, %eax
cmovgel %ebp, %eax
cvtsi2ss %eax, %xmm1
movq 0x1f0d4(%rip), %r12     # 0x68da0
movss 0x4(%r12), %xmm0
ucomiss 0x244(%rbx), %xmm0
jbe 0x49da2
testb $0x10, 0x11c(%rbx)
jne 0x49da2
xorps %xmm0, %xmm0
cvtsi2ssl (%r12), %xmm0
ucomiss 0xf08(%r15), %xmm0
jb 0x49da2
movss %xmm1, 0x10(%rsp)
callq 0x19a10
andl $0x1, %eax
incl %eax
xorps %xmm0, %xmm0
cvtss2sd 0x4(%r12), %xmm0
addsd 0xdcca(%rip), %xmm0     # 0x579f0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x244(%rbx)
movl 0x254(%rbx), %ecx
movl $0x19, %esi
cmpl $0x19, %ecx
jl 0x49d5c
movl $0x32, %esi
cmpl $0x32, %ecx
jb 0x49d5c
cmpl $0x4b, %ecx
movl $0x4b, %ecx
movl $0x64, %esi
cmovbl %ecx, %esi
movq 0x1e89d(%rip), %rcx     # 0x68600
movq 0x20(%rcx), %r14
movq 0x48(%rcx), %r13
leaq 0x10ec6(%rip), %rdi     # 0x5ac38
movl %eax, %edx
xorl %eax, %eax
callq 0x19340
movq %rax, %rdi
callq *%r13
movss 0x919f(%rip), %xmm0     # 0x52f28
xorps %xmm2, %xmm2
movq %rbx, %rdi
movl $0x2, %esi
movl %eax, %edx
movaps %xmm0, %xmm1
callq *%r14
movss 0x10(%rsp), %xmm1
xorps %xmm0, %xmm0
maxss 0xea8(%r15), %xmm0
xorps %xmm2, %xmm2
cvtss2sd %xmm1, %xmm2
cvtss2sd %xmm0, %xmm0
movsd 0x10dff(%rip), %xmm1    # 0x5abc0
movsd %xmm2, 0x20(%rsp)
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
xorps %xmm1, %xmm1
cvtss2sd %xmm0, %xmm1
movsd 0xbe2b(%rip), %xmm2     # 0x55c10
ucomisd %xmm1, %xmm2
jbe 0x49df3
movss 0xc1d5(%rip), %xmm0     # 0x55fc8
xorps %xmm1, %xmm1
cvtss2sd %xmm0, %xmm1
ucomisd 0x10dc6(%rip), %xmm1    # 0x5abc8
jbe 0x49e0c
movss 0x10dd4(%rip), %xmm0    # 0x5abe0
leaq 0xe58(%r15), %r13
xorps %xmm1, %xmm1
cvtsi2ss %ebp, %xmm1
movss %xmm0, 0xea8(%r15)
movl $0x0, 0x8(%rsp)
movq $0x0, (%rsp)
movl 0xe5c(%r15), %eax
testl %eax, %eax
movss %xmm1, 0x10(%rsp)
je 0x49e67
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
divss %xmm1, %xmm0
leaq 0x23fd2(%rip), %rsi     # 0x6de28
movq %rsp, %rdi
movq %rdi, %rdx
callq 0x19760
movss 0x10(%rsp), %xmm1
movl (%r13), %eax
testl %eax, %eax
je 0x49e92
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
divss %xmm1, %xmm0
leaq 0x23fb3(%rip), %rsi     # 0x6de34
movq %rsp, %rdi
movq %rdi, %rdx
callq 0x19760
movss 0x10(%rsp), %xmm1
movl 0xe60(%r15), %eax
testl %eax, %eax
je 0x49eba
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
divss %xmm1, %xmm0
leaq 0x23f91(%rip), %rsi     # 0x6de40
movq %rsp, %rdi
movq %rdi, %rdx
callq 0x19760
movsd (%rsp), %xmm0
movsd %xmm0, 0xeb0(%r15)
movss 0x8(%rsp), %xmm0
movss %xmm0, 0xeb8(%r15)
movl 0xe64(%r15), %ecx
movl %ecx, %eax
negl %eax
cmovsl %ecx, %eax
jae 0x4a01d
movl 0x254(%rbx), %ecx
testl %ecx, %ecx
jle 0x4a01d
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
xorps %xmm1, %xmm1
cvtsi2ss %ecx, %xmm1
mulss 0xbd3d(%rip), %xmm0     # 0x55c4c
divss %xmm1, %xmm0
xorps %xmm1, %xmm1
cvtss2sd %xmm0, %xmm1
movsd 0x20(%rsp), %xmm2
mulsd 0xbcc8(%rip), %xmm2     # 0x55bf0
ucomisd %xmm1, %xmm2
jbe 0x49f35
xorps %xmm0, %xmm0
cvtsd2ss %xmm2, %xmm0
movss 0x10ca7(%rip), %xmm1    # 0x5abe4
minss %xmm0, %xmm1
movaps %xmm1, 0x10(%rsp)
movsd 0xe68(%r15), %xmm0
movsd 0x4(%rbx), %xmm1
subps %xmm1, %xmm0
movq %rsp, %r14
movlps %xmm0, (%r14)
movss 0xe70(%r15), %xmm0
subss 0xc(%rbx), %xmm0
movss %xmm0, 0x8(%r14)
movq %r14, %rdi
callq 0x18390
movss (%r14), %xmm0
movss 0x4(%r14), %xmm1
movss 0x4f0bf(%rip), %xmm2    # 0x9904c
mulss %xmm1, %xmm2
movss 0x4f0af(%rip), %xmm3    # 0x99048
mulss %xmm0, %xmm3
addss %xmm2, %xmm3
movss 0x8(%r14), %xmm2
movss 0x4f0a1(%rip), %xmm4    # 0x99050
mulss %xmm2, %xmm4
mulss 0x4f0a1(%rip), %xmm1    # 0x9905c
mulss 0x4f095(%rip), %xmm0    # 0x99058
mulss 0x4f095(%rip), %xmm2    # 0x99060
addss %xmm1, %xmm0
addss %xmm0, %xmm2
xorps 0xbcf6(%rip), %xmm2     # 0x55cd0
addss %xmm3, %xmm4
unpcklps %xmm2, %xmm4            # xmm4 = xmm4[0],xmm2[0],xmm4[1],xmm2[1]
movaps 0x10(%rsp), %xmm0
shufps $0x0, %xmm0, %xmm0      # xmm0 = xmm0[0,0,0,0]
mulps %xmm4, %xmm0
cvtps2pd %xmm0, %xmm0
mulpd 0x10b58(%rip), %xmm0    # 0x5ab50
cvtpd2ps %xmm0, %xmm0
movlpd %xmm0, 0xe94(%r15)
movss 0x4(%r12), %xmm0
addss 0xa3ec(%rip), %xmm0     # 0x54400
movss %xmm0, 0xe9c(%r15)
xorps %xmm0, %xmm0
movups %xmm0, (%r13)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq