// File: /workspace/github_c_makefile_star2_O3/QwazyWabbitWOS[P]lmctf60/g_items.c
// Function: SpawnItem
void SpawnItem (edict_t *ent, gitem_t *item)
{
	PrecacheItem (item);


	//Radomize the quad
	//This is called every time any item is spawned, but it
	//is ok to make things more random.
	if((int)ctfflags->value & CTF_RANDOM_QUAD)
		itemlist[QUAD_INDEX].quantity = 50 + (rand() % 31);


	if (ent->spawnflags)
	{
		if (strcmp(ent->classname, "key_power_cube") != 0)
		{
			ent->spawnflags = 0;
			gi.dprintf("%s at %s has invalid spawnflags set\n", ent->classname, vtos(ent->s.origin));
		}
	}

	// some items will be prevented in deathmatch
	if (deathmatch->value)
	{
		if ( (int)dmflags->value & DF_NO_ARMOR )
		{
			if (item->pickup == Pickup_Armor || item->pickup == Pickup_PowerArmor)
			{
				G_FreeEdict (ent);
				return;
			}
		}
		if ( (int)dmflags->value & DF_NO_ITEMS )
		{
			if (item->pickup == Pickup_Powerup)
			{
				G_FreeEdict (ent);
				return;
			}
		}
		if ( (int)dmflags->value & DF_NO_HEALTH )
		{
			if (item->pickup == Pickup_Health || item->pickup == Pickup_Adrenaline || item->pickup == Pickup_AncientHead)
			{
				G_FreeEdict (ent);
				return;
			}
		}
		if ( (int)dmflags->value & DF_INFINITE_AMMO )
		{
			if ( (item->flags == IT_AMMO) || (strcmp(ent->classname, "weapon_bfg") == 0) )
			{
				G_FreeEdict (ent);
				return;
			}
		}

		//surt ... ummm this code vanished at some point ... why?
		if ( ! ((int)ctfflags->value & CTF_ALLOW_INVULN) )
		{
			//unless they enabled the allow invulnerability flag, take it out
			if (item->use == Use_Invulnerability)
			{
				G_FreeEdict(ent);
				return;
			}
		}

		if ((int)disabled_weps->value)
		{
			if ( ((int)disabled_weps->value & DIS_BFG) && (strcmp(ent->classname, "weapon_bfg") == 0) )
			{
				G_FreeEdict (ent);
				return;
			}
			if ( ((int)disabled_weps->value & DIS_HYPERBLASTER) && (strcmp(ent->classname, "weapon_hyperblaster") == 0) )
			{
				G_FreeEdict (ent);
				return;
			}
			if ( ((int)disabled_weps->value & DIS_RAILGUN) && (strcmp(ent->classname, "weapon_railgun") == 0) )
			{
				G_FreeEdict (ent);
				return;
			}
			if ( ((int)disabled_weps->value & DIS_ROCKETLAUNCHER) && (strcmp(ent->classname, "weapon_rocketlauncher") == 0) )
			{
				G_FreeEdict (ent);
				return;
			}
			if ( ((int)disabled_weps->value & DIS_GRENADELAUNCHER) && (strcmp(ent->classname, "weapon_grenadelauncher") == 0) )
			{
				G_FreeEdict (ent);
				return;
			}
			if ( ((int)disabled_weps->value & DIS_CHAINGUN) && (strcmp(ent->classname, "weapon_chaingun") == 0) )
			{
				G_FreeEdict (ent);
				return;
			}
			if ( ((int)disabled_weps->value & DIS_MACHINEGUN) && (strcmp(ent->classname, "weapon_machinegun") == 0) )
			{
				G_FreeEdict (ent);
				return;
			}
			if ( ((int)disabled_weps->value & DIS_SUPERSHOTGUN) && (strcmp(ent->classname, "weapon_supershotgun") == 0) )
			{
				G_FreeEdict (ent);
				return;
			}
			if ( ((int)disabled_weps->value & DIS_SHOTGUN) && (strcmp(ent->classname, "weapon_shotgun") == 0) )
			{
				G_FreeEdict (ent);
				return;
			}

			if ( ((int)disabled_weps->value & DIS_PLASMA) && (strcmp(ent->classname, "weapon_plasma") == 0) )
			{
				G_FreeEdict (ent);
				return;
			}

		}

		
	}

	if (coop->value && (strcmp(ent->classname, "key_power_cube") == 0))
	{
		ent->spawnflags |= (1 << (8 + level.power_cubes));
		level.power_cubes++;
	}

	// don't let them drop items that stay in a coop game
	if ((coop->value) && (item->flags & IT_STAY_COOP))
	{
		item->drop = NULL;
	}

	ent->item = item;
	ent->nextthink = level.time + 2 * FRAMETIME;    // items start after other solids
	ent->think = droptofloor;
	ent->s.effects = item->world_model_flags;
	ent->s.renderfx = RF_GLOW;
	if (ent->model)
		gi.modelindex (ent->model);

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
movq %rsi, %rdi
callq 0x18790
movq 0x37899(%rip), %r12     # 0x68b58
movq (%r12), %rax
cvttss2si 0x20(%rax), %eax
btl $0xd, %eax
jae 0x31305
callq 0x19a10
cltq
imulq $-0x7bdef7bd, %rax, %rcx # imm = 0x84210843
shrq $0x20, %rcx
addl %eax, %ecx
movl %ecx, %edx
shrl $0x1f, %edx
sarl $0x4, %ecx
addl %edx, %ecx
movl %ecx, %edx
shll $0x5, %edx
subl %edx, %ecx
addl %ecx, %eax
addl $0x32, %eax
movq 0x37b41(%rip), %rcx     # 0x68e40
movl %eax, 0xd1c(%rcx)
cmpl $0x0, 0x140(%rbx)
je 0x31358
movq 0x138(%rbx), %r15
leaq 0x24cfd(%rip), %rsi     # 0x56019
movq %r15, %rdi
callq 0x18b20
testl %eax, %eax
je 0x31358
movl $0x0, 0x140(%rbx)
movq 0x372c7(%rip), %rax     # 0x68600
movq 0x8(%rax), %r13
leaq 0x4(%rbx), %rdi
callq 0x190a0
leaq 0x24d99(%rip), %rdi     # 0x560e6
movq %r15, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq *%r13
movq 0x37b61(%rip), %rax     # 0x68ec0
movq (%rax), %rax
movss 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x31375
jnp 0x315b9
movq 0x3729c(%rip), %rax     # 0x68618
movq (%rax), %rax
cvttss2si 0x20(%rax), %eax
btl $0xb, %eax
jae 0x313aa
movq 0x8(%r14), %rcx
cmpq 0x3791b(%rip), %rcx     # 0x68cb0
setne %dl
cmpq 0x374f9(%rip), %rcx     # 0x68898
setne %cl
testb %cl, %dl
je 0x3167d
testb $0x2, %al
je 0x313bf
movq 0x8(%r14), %rcx
cmpq 0x37287(%rip), %rcx     # 0x68640
je 0x3167d
testb $0x1, %al
je 0x313ee
movq 0x8(%r14), %rcx
cmpq 0x376a2(%rip), %rcx     # 0x68a70
je 0x3167d
cmpq 0x37a9d(%rip), %rcx     # 0x68e78
je 0x3167d
cmpq 0x377d0(%rip), %rcx     # 0x68bb8
je 0x3167d
btl $0xd, %eax
jae 0x3141d
cmpl $0x2, 0x68(%r14)
je 0x3167d
movq 0x138(%rbx), %rdi
leaq 0x21baf(%rip), %rsi     # 0x52fbc
callq 0x18b20
xorps %xmm1, %xmm1
testl %eax, %eax
je 0x3167d
movq (%r12), %rax
cvttss2si 0x20(%rax), %eax
testb $0x2, %al
jne 0x3143b
movq 0x10(%r14), %rax
cmpq 0x3748b(%rip), %rax     # 0x688c0
je 0x3167d
movq 0x36ffe(%rip), %rax     # 0x68440
movq (%rax), %rax
cvttss2si 0x20(%rax), %ebp
testl %ebp, %ebp
je 0x315b9
testb $0x1, %bpl
je 0x31476
movq 0x138(%rbx), %rdi
leaq 0x21b56(%rip), %rsi     # 0x52fbc
callq 0x18b20
xorps %xmm1, %xmm1
testl %eax, %eax
je 0x3167d
testb $0x2, %bpl
je 0x3149a
movq 0x138(%rbx), %rdi
leaq 0x21b62(%rip), %rsi     # 0x52fec
callq 0x18b20
xorps %xmm1, %xmm1
testl %eax, %eax
je 0x3167d
testb $0x4, %bpl
je 0x314be
movq 0x138(%rbx), %rdi
leaq 0x21b19(%rip), %rsi     # 0x52fc7
callq 0x18b20
xorps %xmm1, %xmm1
testl %eax, %eax
je 0x3167d
testb $0x8, %bpl
je 0x314e2
movq 0x138(%rbx), %rdi
leaq 0x21b04(%rip), %rsi     # 0x52fd6
callq 0x18b20
xorps %xmm1, %xmm1
testl %eax, %eax
je 0x3167d
testb $0x10, %bpl
je 0x31506
movq 0x138(%rbx), %rdi
leaq 0x21b1a(%rip), %rsi     # 0x53010
callq 0x18b20
xorps %xmm1, %xmm1
testl %eax, %eax
je 0x3167d
testb $0x20, %bpl
je 0x3152a
movq 0x138(%rbx), %rdi
leaq 0x21ae6(%rip), %rsi     # 0x53000
callq 0x18b20
xorps %xmm1, %xmm1
testl %eax, %eax
je 0x3167d
testb $0x40, %bpl
je 0x3154e
movq 0x138(%rbx), %rdi
leaq 0x21ae9(%rip), %rsi     # 0x53027
callq 0x18b20
xorps %xmm1, %xmm1
testl %eax, %eax
je 0x3167d
testb %bpl, %bpl
jns 0x31571
movq 0x138(%rbx), %rdi
leaq 0x21ad8(%rip), %rsi     # 0x53039
callq 0x18b20
xorps %xmm1, %xmm1
testl %eax, %eax
je 0x3167d
btl $0x8, %ebp
jae 0x31595
movq 0x138(%rbx), %rdi
leaq 0x21ac8(%rip), %rsi     # 0x5304d
callq 0x18b20
xorps %xmm1, %xmm1
testl %eax, %eax
je 0x3167d
btl $0x9, %ebp
jae 0x315b9
movq 0x138(%rbx), %rdi
leaq 0x24b62(%rip), %rsi     # 0x5610b
callq 0x18b20
xorps %xmm1, %xmm1
testl %eax, %eax
je 0x3167d
movq 0x379a0(%rip), %rax     # 0x68f60
movq (%rax), %rax
movss 0x20(%rax), %xmm0
ucomiss %xmm1, %xmm0
jne 0x315cf
jnp 0x3161a
movq 0x138(%rbx), %rdi
leaq 0x24a3c(%rip), %rsi     # 0x56019
callq 0x18b20
testl %eax, %eax
jne 0x3160b
movq 0x377b3(%rip), %rax     # 0x68da0
movl 0x154(%rax), %edx
leal 0x8(%rdx), %ecx
movl $0x1, %esi
shll %cl, %esi
orl %esi, 0x140(%rbx)
incl %edx
movl %edx, 0x154(%rax)
testb $0x8, 0x68(%r14)
je 0x3161a
movq $0x0, 0x18(%r14)
movq %r14, 0x330(%rbx)
movq 0x37778(%rip), %rax     # 0x68da0
movss 0x4(%rax), %xmm0
addss 0x24993(%rip), %xmm0    # 0x55fc8
movss %xmm0, 0x200(%rbx)
movq 0x36edc(%rip), %rax     # 0x68520
movq %rax, 0x210(%rbx)
movl 0x38(%r14), %eax
movl %eax, 0x40(%rbx)
movl $0x200, 0x44(%rbx)      # imm = 0x200
movq 0x120(%rbx), %rdi
testq %rdi, %rdi
je 0x31693
movq 0x36f94(%rip), %rax     # 0x68600
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmpq *0x40(%rax)
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x19a50
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq