// File: /workspace/github_c_makefile_star2_O3/QwazyWabbitWOS[P]lmctf60/g_phys.c
// Function: SV_Physics_Step
void SV_Physics_Step (edict_t *ent)
{
	qboolean	wasonground;
	qboolean	hitsound = false;
	float		*vel;
	float		speed, newspeed, control;
	float		friction;
	edict_t		*groundentity;
	int			mask;

	// airborn monsters should always check for ground
#ifdef MONSTERS_OK
	if (!ent->groundentity)
		M_CheckGround (ent);
#endif
	groundentity = ent->groundentity;

	SV_CheckVelocity (ent);

	if (groundentity)
		wasonground = true;
	else
		wasonground = false;
		
	if (ent->avelocity[0] || ent->avelocity[1] || ent->avelocity[2])
		SV_AddRotationalFriction (ent);

	// add gravity except:
	//   flying monsters
	//   swimming monsters who are in the water
	if (! wasonground)
		if (!(ent->flags & FL_FLY))
			if (!((ent->flags & FL_SWIM) && (ent->waterlevel > 2)))
			{
				if (ent->velocity[2] < sv_gravity->value*-0.1)
					hitsound = true;
				if (ent->waterlevel == 0)
					SV_AddGravity (ent);
			}

	// friction for flying monsters that have been given vertical velocity
	if ((ent->flags & FL_FLY) && (ent->velocity[2] != 0))
	{
		speed = fabs(ent->velocity[2]);
		control = speed < sv_stopspeed ? sv_stopspeed : speed;
		friction = sv_friction/3;
		newspeed = speed - (FRAMETIME * control * friction);
		if (newspeed < 0)
			newspeed = 0;
		newspeed /= speed;
		ent->velocity[2] *= newspeed;
	}

	// friction for flying monsters that have been given vertical velocity
	if ((ent->flags & FL_SWIM) && (ent->velocity[2] != 0))
	{
		speed = fabs(ent->velocity[2]);
		control = speed < sv_stopspeed ? sv_stopspeed : speed;
		newspeed = speed - (FRAMETIME * control * sv_waterfriction * ent->waterlevel);
		if (newspeed < 0)
			newspeed = 0;
		newspeed /= speed;
		ent->velocity[2] *= newspeed;
	}

	if (ent->velocity[2] || ent->velocity[1] || ent->velocity[0])
	{
		// apply friction
		// let dead monsters who aren't completely onground slide
		if ((wasonground) || (ent->flags & (FL_SWIM|FL_FLY)))
			if (!(ent->health <= 0.0 && !M_CheckBottom(ent)))
			{
				vel = ent->velocity;
				speed = sqrtf(vel[0] * vel[0] + vel[1] * vel[1]);
				if (speed)
				{
					friction = sv_friction;

					control = speed < sv_stopspeed ? sv_stopspeed : speed;
					newspeed = speed - FRAMETIME*control*friction;

					if (newspeed < 0)
						newspeed = 0;
					newspeed /= speed;

					vel[0] *= newspeed;
					vel[1] *= newspeed;
				}
			}

		if (ent->svflags & SVF_MONSTER)
			mask = MASK_MONSTERSOLID;
		else
			mask = MASK_SOLID;
		SV_FlyMove (ent, FRAMETIME, mask);

		gi.linkentity (ent);
		G_TouchTriggers (ent);
		if (!ent->inuse)
			return;

		if (ent->groundentity)
			if (!wasonground)
				if (hitsound)
					gi.sound (ent, 0, gi.soundindex("world/land.wav"), 1, 1, 0);
	}

// regular thinking
	SV_RunThink (ent);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x2b8(%rdi), %r14
movq 0x30371(%rip), %rax     # 0x68970
movq (%rax), %rax
movl $0x70, %ecx
movaps 0x1d6c2(%rip), %xmm0    # 0x55cd0
movss (%rbx,%rcx,4), %xmm2
movss 0x20(%rax), %xmm1
ucomiss %xmm1, %xmm2
ja 0x38625
xorps %xmm0, %xmm1
ucomiss %xmm2, %xmm1
jbe 0x3862a
movss %xmm1, (%rbx,%rcx,4)
incq %rcx
cmpq $0x73, %rcx
jne 0x3860e
movss 0x1cc(%rbx), %xmm1
xorps %xmm0, %xmm0
ucomiss %xmm0, %xmm1
jne 0x38666
jp 0x38666
movss 0x1d0(%rbx), %xmm1
ucomiss %xmm0, %xmm1
jne 0x38666
jp 0x38666
movss 0x1d4(%rbx), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x38666
jnp 0x3866e
movq %rbx, %rdi
callq 0x18850
movl 0x11c(%rbx), %eax
testq %r14, %r14
je 0x38682
testb $0x1, %al
jne 0x386f4
jmp 0x38740
testb $0x1, %al
jne 0x386f4
movl %eax, %edx
shrb %dl
movl 0x30c(%rbx), %ecx
cmpl $0x3, %ecx
setge %sil
testb %sil, %dl
jne 0x38740
movss 0x1c8(%rbx), %xmm0
xorps %xmm2, %xmm2
cvtss2sd %xmm0, %xmm2
movq 0x3090a(%rip), %rdx     # 0x68fc0
movq (%rdx), %rdx
movss 0x20(%rdx), %xmm1
cvtss2sd %xmm1, %xmm3
mulsd 0x1f346(%rip), %xmm3    # 0x57a10
ucomisd %xmm2, %xmm3
seta %bpl
testl %ecx, %ecx
jne 0x38742
mulss 0x1e0(%rbx), %xmm1
mulss 0x1b54a(%rip), %xmm1    # 0x53c30
addss %xmm1, %xmm0
movss %xmm0, 0x1c8(%rbx)
jmp 0x38742
movss 0x1c8(%rbx), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x38706
jnp 0x38740
movaps 0x1a833(%rip), %xmm2    # 0x52f40
andps %xmm0, %xmm2
movss 0x1d534(%rip), %xmm3    # 0x55c4c
maxss %xmm2, %xmm3
mulss 0x1b50c(%rip), %xmm3    # 0x53c30
addss %xmm3, %xmm3
addss %xmm2, %xmm3
maxss %xmm3, %xmm1
divss %xmm2, %xmm1
mulss %xmm0, %xmm1
movss %xmm1, 0x1c8(%rbx)
xorl %ebp, %ebp
movss 0x1c8(%rbx), %xmm0
testb $0x2, %al
je 0x3879a
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x38758
jnp 0x3879a
movaps 0x1a7e1(%rip), %xmm2    # 0x52f40
andps %xmm0, %xmm2
movss 0x1d4e2(%rip), %xmm3    # 0x55c4c
maxss %xmm2, %xmm3
cvtsi2ssl 0x30c(%rbx), %xmm4
mulss 0x1b4b2(%rip), %xmm3    # 0x53c30
mulss %xmm4, %xmm3
addss %xmm2, %xmm3
maxss %xmm3, %xmm1
divss %xmm2, %xmm1
mulss %xmm1, %xmm0
movss %xmm0, 0x1c8(%rbx)
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x387c6
jp 0x387c6
movss 0x1c4(%rbx), %xmm0
ucomiss %xmm1, %xmm0
jne 0x387c6
jp 0x387c6
movss 0x1c0(%rbx), %xmm0
ucomiss %xmm1, %xmm0
jne 0x387c6
jnp 0x388c9
testq %r14, %r14
sete %cl
testb $0x3, %al
sete %al
testb %al, %cl
jne 0x3884a
cmpl $0x0, 0x254(%rbx)
jg 0x387ea
movq %rbx, %rdi
callq 0x19130
testl %eax, %eax
je 0x3884a
movsd 0x1c0(%rbx), %xmm0
movaps %xmm0, %xmm1
mulps %xmm0, %xmm1
shufps $0x55, %xmm1, %xmm1     # xmm1 = xmm1[1,1,1,1]
movaps %xmm0, %xmm2
mulss %xmm0, %xmm2
addss %xmm1, %xmm2
sqrtss %xmm2, %xmm2
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm2
jne 0x38815
jnp 0x3884a
movss 0x1d42f(%rip), %xmm3    # 0x55c4c
maxss %xmm2, %xmm3
mulss 0x1b407(%rip), %xmm3    # 0x53c30
mulss 0x1a6d3(%rip), %xmm3    # 0x52f04
addss %xmm2, %xmm3
maxss %xmm3, %xmm1
divss %xmm2, %xmm1
unpcklps %xmm1, %xmm1            # xmm1 = xmm1[0,0,1,1]
mulps %xmm0, %xmm1
movlps %xmm1, 0x1c0(%rbx)
testb $0x4, 0xc8(%rbx)
movl $0x3, %eax
movl $0x2020003, %esi        # imm = 0x2020003
cmovel %eax, %esi
movss 0x1aa2a(%rip), %xmm0    # 0x53290
movq %rbx, %rdi
callq 0x18140
movq 0x2fd8b(%rip), %r15     # 0x68600
movq %rbx, %rdi
callq *0x90(%r15)
movq %rbx, %rdi
callq 0x19200
cmpl $0x0, 0x60(%rbx)
je 0x388db
cmpq $0x0, 0x2b8(%rbx)
setne %al
testq %r14, %r14
jne 0x388c9
andb %al, %bpl
je 0x388c9
movq 0x20(%r15), %r14
leaq 0x1f20e(%rip), %rdi     # 0x57abb
callq *0x48(%r15)
movss 0x1a66f(%rip), %xmm0    # 0x52f28
xorps %xmm2, %xmm2
movq %rbx, %rdi
xorl %esi, %esi
movl %eax, %edx
movaps %xmm0, %xmm1
callq *%r14
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x18620
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq