// File: /workspace/github_c_makefile_star2_O2/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
callq 0x19190
movss 0x1cc(%rbx), %xmm1
xorps %xmm0, %xmm0
ucomiss %xmm0, %xmm1
jne 0x35636
jp 0x35636
movss 0x1d0(%rbx), %xmm1
ucomiss %xmm0, %xmm1
jne 0x35636
jp 0x35636
movss 0x1d4(%rbx), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x35636
jnp 0x3563e
movq %rbx, %rdi
callq 0x188b0
testq %r14, %r14
jne 0x35664
movl 0x11c(%rbx), %ecx
testb $0x1, %cl
jne 0x35664
shrb %cl
movl 0x30c(%rbx), %eax
cmpl $0x3, %eax
setge %dl
testb %dl, %cl
je 0x35860
xorl %ebp, %ebp
movl 0x11c(%rbx), %eax
testb $0x1, %al
je 0x356bd
movss 0x1c8(%rbx), %xmm0
xorpd %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x35683
jnp 0x356bd
movaps 0x198b6(%rip), %xmm2    # 0x4ef40
andps %xmm0, %xmm2
movss 0x1c597(%rip), %xmm3    # 0x51c2c
maxss %xmm2, %xmm3
mulss 0x1a58f(%rip), %xmm3    # 0x4fc30
addss %xmm3, %xmm3
addss %xmm2, %xmm3
maxss %xmm3, %xmm1
divss %xmm2, %xmm1
mulss %xmm0, %xmm1
movss %xmm1, 0x1c8(%rbx)
movss 0x1c8(%rbx), %xmm0
testb $0x2, %al
je 0x35716
xorpd %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x356d4
jnp 0x35716
movaps 0x19865(%rip), %xmm2    # 0x4ef40
andps %xmm0, %xmm2
movss 0x1c546(%rip), %xmm3    # 0x51c2c
maxss %xmm2, %xmm3
cvtsi2ssl 0x30c(%rbx), %xmm4
mulss 0x1a536(%rip), %xmm3    # 0x4fc30
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 0x35742
jp 0x35742
movss 0x1c4(%rbx), %xmm0
ucomiss %xmm1, %xmm0
jne 0x35742
jp 0x35742
movss 0x1c0(%rbx), %xmm0
ucomiss %xmm1, %xmm0
jne 0x35742
jnp 0x35843
testq %r14, %r14
sete %cl
testb $0x3, %al
sete %al
testb %al, %cl
jne 0x357c6
cmpl $0x0, 0x254(%rbx)
jg 0x35766
movq %rbx, %rdi
callq 0x192a0
testl %eax, %eax
je 0x357c6
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 0x35791
jnp 0x357c6
movss 0x1c493(%rip), %xmm3    # 0x51c2c
maxss %xmm2, %xmm3
mulss 0x1a48b(%rip), %xmm3    # 0x4fc30
mulss 0x19753(%rip), %xmm3    # 0x4ef00
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)
pushq $0x3
popq %rax
movl $0x2020003, %esi        # imm = 0x2020003
cmovel %eax, %esi
movss 0x19ab0(%rip), %xmm0    # 0x4f290
movq %rbx, %rdi
callq 0x18140
movq 0x30e11(%rip), %r15     # 0x66600
movq %rbx, %rdi
callq *0x90(%r15)
movq %rbx, %rdi
callq 0x19380
cmpl $0x0, 0x60(%rbx)
je 0x35855
cmpq $0x0, 0x2b8(%rbx)
setne %al
testq %r14, %r14
jne 0x35843
andb %al, %bpl
je 0x35843
movq 0x20(%r15), %r14
leaq 0x1e274(%rip), %rdi     # 0x53a9b
callq *0x48(%r15)
movss 0x196f5(%rip), %xmm0    # 0x4ef28
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 0x18660
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
cvtss2sd 0x1c8(%rbx), %xmm0
movq 0x31751(%rip), %rcx     # 0x66fc0
movq (%rcx), %rcx
cvtss2sd 0x20(%rcx), %xmm1
mulsd 0x1e171(%rip), %xmm1    # 0x539f0
ucomisd %xmm0, %xmm1
seta %bpl
testl %eax, %eax
jne 0x35666
movq %rbx, %rdi
callq 0x18a50
jmp 0x35666