// File: /workspace/github_c_makefile_star2_O1/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 0x38336(%rip), %r12     # 0x69b58
movq (%r12), %rax
cvttss2si 0x20(%rax), %eax
btl $0xd, %eax
jae 0x31868
callq 0x19a20
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 0x385de(%rip), %rcx     # 0x69e40
movl %eax, 0xd1c(%rcx)
cmpl $0x0, 0x140(%rbx)
je 0x318bb
movq 0x138(%rbx), %r15
leaq 0x256a6(%rip), %rsi     # 0x56f25
movq %r15, %rdi
callq 0x18b20
testl %eax, %eax
je 0x318bb
movl $0x0, 0x140(%rbx)
movq 0x37d64(%rip), %rax     # 0x69600
movq 0x8(%rax), %r13
leaq 0x4(%rbx), %rdi
callq 0x190a0
leaq 0x25742(%rip), %rdi     # 0x56ff2
movq %r15, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq *%r13
movq 0x385fe(%rip), %rax     # 0x69ec0
movq (%rax), %rax
movss 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x318d8
jnp 0x31b1c
movq 0x37d39(%rip), %rax     # 0x69618
movq (%rax), %rax
cvttss2si 0x20(%rax), %eax
btl $0xb, %eax
jae 0x3190d
movq 0x8(%r14), %rcx
cmpq 0x383b8(%rip), %rcx     # 0x69cb0
setne %dl
cmpq 0x37f96(%rip), %rcx     # 0x69898
setne %cl
testb %cl, %dl
je 0x31bf6
testb $0x2, %al
je 0x31922
movq 0x8(%r14), %rcx
cmpq 0x37d24(%rip), %rcx     # 0x69640
je 0x31bf6
testb $0x1, %al
je 0x31951
movq 0x8(%r14), %rcx
cmpq 0x3813f(%rip), %rcx     # 0x69a70
je 0x31bf6
cmpq 0x3853a(%rip), %rcx     # 0x69e78
je 0x31bf6
cmpq 0x3826d(%rip), %rcx     # 0x69bb8
je 0x31bf6
btl $0xd, %eax
jae 0x31980
cmpl $0x2, 0x68(%r14)
je 0x31bf6
movq 0x138(%rbx), %rdi
leaq 0x2264c(%rip), %rsi     # 0x53fbc
callq 0x18b20
xorps %xmm1, %xmm1
testl %eax, %eax
je 0x31bf6
movq (%r12), %rax
cvttss2si 0x20(%rax), %eax
testb $0x2, %al
jne 0x3199e
movq 0x10(%r14), %rax
cmpq 0x37f28(%rip), %rax     # 0x698c0
je 0x31bf6
movq 0x37a9b(%rip), %rax     # 0x69440
movq (%rax), %rax
cvttss2si 0x20(%rax), %ebp
testl %ebp, %ebp
je 0x31b1c
testb $0x1, %bpl
je 0x319d9
movq 0x138(%rbx), %rdi
leaq 0x225f3(%rip), %rsi     # 0x53fbc
callq 0x18b20
xorps %xmm1, %xmm1
testl %eax, %eax
je 0x31bf6
testb $0x2, %bpl
je 0x319fd
movq 0x138(%rbx), %rdi
leaq 0x225ff(%rip), %rsi     # 0x53fec
callq 0x18b20
xorps %xmm1, %xmm1
testl %eax, %eax
je 0x31bf6
testb $0x4, %bpl
je 0x31a21
movq 0x138(%rbx), %rdi
leaq 0x225b6(%rip), %rsi     # 0x53fc7
callq 0x18b20
xorps %xmm1, %xmm1
testl %eax, %eax
je 0x31bf6
testb $0x8, %bpl
je 0x31a45
movq 0x138(%rbx), %rdi
leaq 0x225a1(%rip), %rsi     # 0x53fd6
callq 0x18b20
xorps %xmm1, %xmm1
testl %eax, %eax
je 0x31bf6
testb $0x10, %bpl
je 0x31a69
movq 0x138(%rbx), %rdi
leaq 0x225b7(%rip), %rsi     # 0x54010
callq 0x18b20
xorps %xmm1, %xmm1
testl %eax, %eax
je 0x31bf6
testb $0x20, %bpl
je 0x31a8d
movq 0x138(%rbx), %rdi
leaq 0x22583(%rip), %rsi     # 0x54000
callq 0x18b20
xorps %xmm1, %xmm1
testl %eax, %eax
je 0x31bf6
testb $0x40, %bpl
je 0x31ab1
movq 0x138(%rbx), %rdi
leaq 0x22586(%rip), %rsi     # 0x54027
callq 0x18b20
xorps %xmm1, %xmm1
testl %eax, %eax
je 0x31bf6
testb %bpl, %bpl
jns 0x31ad4
movq 0x138(%rbx), %rdi
leaq 0x22575(%rip), %rsi     # 0x54039
callq 0x18b20
xorps %xmm1, %xmm1
testl %eax, %eax
je 0x31bf6
btl $0x8, %ebp
jae 0x31af8
movq 0x138(%rbx), %rdi
leaq 0x22565(%rip), %rsi     # 0x5404d
callq 0x18b20
xorps %xmm1, %xmm1
testl %eax, %eax
je 0x31bf6
btl $0x9, %ebp
jae 0x31b1c
movq 0x138(%rbx), %rdi
leaq 0x2550b(%rip), %rsi     # 0x57017
callq 0x18b20
xorps %xmm1, %xmm1
testl %eax, %eax
je 0x31bf6
movq 0x3843d(%rip), %rax     # 0x69f60
movq (%rax), %rax
movss 0x20(%rax), %xmm0
ucomiss %xmm1, %xmm0
jne 0x31b32
jnp 0x31b93
movss %xmm0, 0x4(%rsp)
movq 0x138(%rbx), %rdi
leaq 0x253df(%rip), %rsi     # 0x56f25
callq 0x18b20
testl %eax, %eax
jne 0x31b74
movq 0x3824a(%rip), %rax     # 0x69da0
movl 0x154(%rax), %edx
leal 0x8(%rdx), %ecx
movl $0x1, %esi
shll %cl, %esi
orl %esi, 0x140(%rbx)
incl %edx
movl %edx, 0x154(%rax)
xorps %xmm0, %xmm0
movss 0x4(%rsp), %xmm1
ucomiss %xmm0, %xmm1
jne 0x31b84
jnp 0x31b93
testb $0x8, 0x68(%r14)
je 0x31b93
movq $0x0, 0x18(%r14)
movq %r14, 0x330(%rbx)
movq 0x381ff(%rip), %rax     # 0x69da0
movss 0x4(%rax), %xmm0
addss 0x25326(%rip), %xmm0    # 0x56ed4
movss %xmm0, 0x200(%rbx)
movq 0x37963(%rip), %rax     # 0x69520
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 0x31c0c
movq 0x37a1b(%rip), %rax     # 0x69600
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 0x19a60
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq