// File: /workspace/github_c_makefile_star2_O2/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 0x187f0
movq 0x38269(%rip), %r12     # 0x66b58
movq (%r12), %rax
cvttss2si 0x20(%rax), %eax
btl $0xd, %eax
jae 0x2e919
callq 0x19bf0
pushq $0x1f
popq %rcx
cltd
idivl %ecx
addl $0x32, %edx
movq 0x3852d(%rip), %rax     # 0x66e40
movl %edx, 0xd1c(%rax)
cmpl $0x0, 0x140(%rbx)
je 0x2e969
movq 0x138(%rbx), %r15
leaq 0x236c9(%rip), %rsi     # 0x51ff9
movq %r15, %rdi
callq 0x18bc0
testl %eax, %eax
je 0x2e969
andl $0x0, 0x140(%rbx)
movq 0x37cb6(%rip), %rax     # 0x66600
movq 0x8(%rax), %r13
leaq 0x4(%rbx), %rdi
callq 0x19200
leaq 0x23768(%rip), %rdi     # 0x520c6
movq %r15, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq *%r13
movq 0x38550(%rip), %rax     # 0x66ec0
movq (%rax), %rax
movss 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x2e986
jnp 0x2ebca
movq 0x37c8b(%rip), %rax     # 0x66618
movq (%rax), %rax
cvttss2si 0x20(%rax), %eax
btl $0xb, %eax
jae 0x2e9bb
movq 0x8(%r14), %rcx
cmpq 0x3830a(%rip), %rcx     # 0x66cb0
setne %dl
cmpq 0x37ee8(%rip), %rcx     # 0x66898
setne %cl
testb %cl, %dl
je 0x2ec89
testb $0x2, %al
je 0x2e9d0
movq 0x8(%r14), %rcx
cmpq 0x37c76(%rip), %rcx     # 0x66640
je 0x2ec89
testb $0x1, %al
je 0x2e9ff
movq 0x8(%r14), %rcx
cmpq 0x38091(%rip), %rcx     # 0x66a70
je 0x2ec89
cmpq 0x3848c(%rip), %rcx     # 0x66e78
je 0x2ec89
cmpq 0x381bf(%rip), %rcx     # 0x66bb8
je 0x2ec89
btl $0xd, %eax
jae 0x2ea2e
cmpl $0x2, 0x68(%r14)
je 0x2ec89
movq 0x138(%rbx), %rdi
leaq 0x2059e(%rip), %rsi     # 0x4efbc
callq 0x18bc0
xorps %xmm1, %xmm1
testl %eax, %eax
je 0x2ec89
movq (%r12), %rax
cvttss2si 0x20(%rax), %eax
testb $0x2, %al
jne 0x2ea4c
movq 0x10(%r14), %rax
cmpq 0x37e7a(%rip), %rax     # 0x668c0
je 0x2ec89
movq 0x379ed(%rip), %rax     # 0x66440
movq (%rax), %rax
cvttss2si 0x20(%rax), %ebp
testl %ebp, %ebp
je 0x2ebca
testb $0x1, %bpl
je 0x2ea87
movq 0x138(%rbx), %rdi
leaq 0x20545(%rip), %rsi     # 0x4efbc
callq 0x18bc0
xorps %xmm1, %xmm1
testl %eax, %eax
je 0x2ec89
testb $0x2, %bpl
je 0x2eaab
movq 0x138(%rbx), %rdi
leaq 0x20551(%rip), %rsi     # 0x4efec
callq 0x18bc0
xorps %xmm1, %xmm1
testl %eax, %eax
je 0x2ec89
testb $0x4, %bpl
je 0x2eacf
movq 0x138(%rbx), %rdi
leaq 0x20508(%rip), %rsi     # 0x4efc7
callq 0x18bc0
xorps %xmm1, %xmm1
testl %eax, %eax
je 0x2ec89
testb $0x8, %bpl
je 0x2eaf3
movq 0x138(%rbx), %rdi
leaq 0x204f3(%rip), %rsi     # 0x4efd6
callq 0x18bc0
xorps %xmm1, %xmm1
testl %eax, %eax
je 0x2ec89
testb $0x10, %bpl
je 0x2eb17
movq 0x138(%rbx), %rdi
leaq 0x20509(%rip), %rsi     # 0x4f010
callq 0x18bc0
xorps %xmm1, %xmm1
testl %eax, %eax
je 0x2ec89
testb $0x20, %bpl
je 0x2eb3b
movq 0x138(%rbx), %rdi
leaq 0x204d5(%rip), %rsi     # 0x4f000
callq 0x18bc0
xorps %xmm1, %xmm1
testl %eax, %eax
je 0x2ec89
testb $0x40, %bpl
je 0x2eb5f
movq 0x138(%rbx), %rdi
leaq 0x204d8(%rip), %rsi     # 0x4f027
callq 0x18bc0
xorps %xmm1, %xmm1
testl %eax, %eax
je 0x2ec89
testb %bpl, %bpl
jns 0x2eb82
movq 0x138(%rbx), %rdi
leaq 0x204c7(%rip), %rsi     # 0x4f039
callq 0x18bc0
xorps %xmm1, %xmm1
testl %eax, %eax
je 0x2ec89
btl $0x8, %ebp
jae 0x2eba6
movq 0x138(%rbx), %rdi
leaq 0x204b7(%rip), %rsi     # 0x4f04d
callq 0x18bc0
xorps %xmm1, %xmm1
testl %eax, %eax
je 0x2ec89
btl $0x9, %ebp
jae 0x2ebca
movq 0x138(%rbx), %rdi
leaq 0x23531(%rip), %rsi     # 0x520eb
callq 0x18bc0
xorps %xmm1, %xmm1
testl %eax, %eax
je 0x2ec89
movq 0x3838f(%rip), %rax     # 0x66f60
movq (%rax), %rax
movss 0x20(%rax), %xmm0
ucomiss %xmm1, %xmm0
jne 0x2ebe0
jnp 0x2ec26
movq 0x138(%rbx), %rdi
leaq 0x2340b(%rip), %rsi     # 0x51ff9
callq 0x18bc0
testl %eax, %eax
jne 0x2ec1a
movq 0x381a2(%rip), %rax     # 0x66da0
movl 0x154(%rax), %edx
leal 0x8(%rdx), %ecx
pushq $0x1
popq %rsi
shll %cl, %esi
orl %esi, 0x140(%rbx)
incl %edx
movl %edx, 0x154(%rax)
testb $0x8, 0x68(%r14)
je 0x2ec26
andq $0x0, 0x18(%r14)
movq %r14, 0x330(%rbx)
movq 0x3816c(%rip), %rax     # 0x66da0
movss 0x4(%rax), %xmm0
addss 0x23367(%rip), %xmm0    # 0x51fa8
movss %xmm0, 0x200(%rbx)
movq 0x378d0(%rip), %rax     # 0x66520
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 0x2ec9f
movq 0x37988(%rip), %rax     # 0x66600
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 0x19c50
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq