// File: /workspace/github_c_makefile_star2_O3/QwazyWabbitWOS[P]lmctf60/g_items.c
// Function: Pickup_Armor
qboolean Pickup_Armor (edict_t *ent, edict_t *other)
{
	int				old_armor_index;
	gitem_armor_t	*oldinfo;
	gitem_armor_t	*newinfo;
	int				newcount;
	float			salvage;
	int				salvagecount;

	// get info on new armor
	newinfo = (gitem_armor_t *)ent->item->info;

	old_armor_index = ArmorIndex (other);

	// handle armor shards specially
	if (ent->item->tag == ARMOR_SHARD)
	{
		if (!old_armor_index)
			other->client->pers.inventory[jacket_armor_index] = 2;
		else
			other->client->pers.inventory[old_armor_index] += 2;
	}

	// if player has no armor, just use it
	else if (!old_armor_index)
	{
		other->client->pers.inventory[ITEM_INDEX(ent->item)] = newinfo->base_count;
	}

	// use the better armor
	else
	{
		// get info on old armor
		if (old_armor_index == jacket_armor_index)
			oldinfo = &jacketarmor_info;
		else if (old_armor_index == combat_armor_index)
			oldinfo = &combatarmor_info;
		else // (old_armor_index == body_armor_index)
			oldinfo = &bodyarmor_info;

		if (newinfo->normal_protection > oldinfo->normal_protection)
		{
			// calc new armor values
			salvage = oldinfo->normal_protection / newinfo->normal_protection;
			salvagecount = salvage * other->client->pers.inventory[old_armor_index];
			newcount = newinfo->base_count + salvagecount;
			if (newcount > newinfo->max_count)
				newcount = newinfo->max_count;

			// zero count of old armor so it goes away
			other->client->pers.inventory[old_armor_index] = 0;

			// change armor to new item with computed value
			other->client->pers.inventory[ITEM_INDEX(ent->item)] = newcount;
		}
		else
		{
			// calc new armor values
			salvage = newinfo->normal_protection / oldinfo->normal_protection;
			salvagecount = salvage * newinfo->base_count;
			newcount = other->client->pers.inventory[old_armor_index] + salvagecount;
			if (newcount > oldinfo->max_count)
				newcount = oldinfo->max_count;

			// if we're already maxed out then we don't need the new armor
			if (other->client->pers.inventory[old_armor_index] >= newcount)
				return false;

			// update current armor value
			other->client->pers.inventory[old_armor_index] = newcount;
		}
	}

	if (!(ent->spawnflags & DROPPED_ITEM) && (deathmatch->value))
		SetRespawn (ent, 20);


#ifdef WEAP_BALANCE_OK
	//surt limit max armor pickup
	if ((int)ctfflags->value & CTF_WEAP_BALANCE)
	{
		if (other->client->pers.inventory[old_armor_index] > (other->max_health*2))
			other->client->pers.inventory[old_armor_index] = (other->max_health*2);
	}
	//end surt code
#endif

	return true;
}

// Assembly:
pushq %rbx
movq 0x330(%rdi), %rcx
movq 0x70(%rcx), %rdx
movq 0x58(%rsi), %rax
testq %rax, %rax
je 0x30aa5
movl 0x420f1(%rip), %r8d     # 0x72b44
movslq %r8d, %r9
cmpl $0x0, 0x318(%rax,%r9,4)
movl %r8d, %esi
jg 0x30a8b
movslq 0x420dd(%rip), %rsi     # 0x72b48
cmpl $0x0, 0x318(%rax,%rsi,4)
jg 0x30a8b
movslq 0x420d0(%rip), %r10     # 0x72b4c
xorl %esi, %esi
cmpl $0x0, 0x318(%rax,%r10,4)
cmovgl %r10d, %esi
cmpl $0x4, 0x78(%rcx)
jne 0x30ac3
testl %esi, %esi
je 0x30ab2
movslq %esi, %rcx
addl $0x2, 0x318(%rax,%rcx,4)
jmp 0x30bb0
cmpl $0x4, 0x78(%rcx)
jne 0x30ad8
movslq 0x42092(%rip), %r9      # 0x72b44
movl $0x2, 0x318(%rax,%r9,4)
jmp 0x30bb0
testl %esi, %esi
je 0x30ad8
cmpl 0x4207b(%rip), %esi     # 0x72b48
jne 0x30aff
movq 0x38292(%rip), %r9      # 0x68d68
jmp 0x30b06
movl (%rdx), %edx
subq 0x3835f(%rip), %rcx     # 0x68e40
sarq $0x3, %rcx
movabsq $-0x3c3c3c3c3c3c3c3c, %rsi # imm = 0xC3C3C3C3C3C3C3C4
imulq %rcx, %rsi
movl %edx, 0x318(%rax,%rsi)
jmp 0x30bb0
movq 0x37ad2(%rip), %r9      # 0x685d8
cmpl %r8d, %esi
jne 0x30b12
movq 0x37df6(%rip), %r9      # 0x68908
movss 0x8(%rdx), %xmm0
movss 0x8(%r9), %xmm1
ucomiss %xmm1, %xmm0
jbe 0x30b79
divss %xmm0, %xmm1
movslq %esi, %rsi
xorps %xmm0, %xmm0
cvtsi2ssl 0x318(%rax,%rsi,4), %xmm0
mulss %xmm1, %xmm0
cvttss2si %xmm0, %r8d
addl (%rdx), %r8d
movl 0x4(%rdx), %edx
cmpl %edx, %r8d
cmovgel %edx, %r8d
movl $0x0, 0x318(%rax,%rsi,4)
subq 0x382e3(%rip), %rcx     # 0x68e40
sarq $0x3, %rcx
movabsq $-0x3c3c3c3c3c3c3c3c, %rdx # imm = 0xC3C3C3C3C3C3C3C4
imulq %rcx, %rdx
movl %r8d, 0x318(%rax,%rdx)
jmp 0x30bb0
divss %xmm1, %xmm0
xorps %xmm1, %xmm1
cvtsi2ssl (%rdx), %xmm1
mulss %xmm0, %xmm1
cvttss2si %xmm1, %ecx
movslq %esi, %rdx
movl 0x318(%rax,%rdx,4), %esi
addl %esi, %ecx
movl 0x4(%r9), %r8d
cmpl %r8d, %ecx
cmovgel %r8d, %ecx
xorl %ebx, %ebx
cmpl %ecx, %esi
jge 0x30c26
movl %ecx, 0x318(%rax,%rdx,4)
movl $0x1, %ebx
testb $0x1, 0x142(%rdi)
jne 0x30c26
movq 0x382fb(%rip), %rax     # 0x68ec0
movq (%rax), %rax
movss 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x30bd7
jnp 0x30c26
orb $-0x80, 0x11f(%rdi)
orb $0x1, 0xc8(%rdi)
movl $0x0, 0x108(%rdi)
movq 0x381aa(%rip), %rax     # 0x68da0
movss 0x4(%rax), %xmm0
addss 0x2303d(%rip), %xmm0    # 0x53c40
movss %xmm0, 0x200(%rdi)
movq 0x3813e(%rip), %rax     # 0x68d50
movq %rax, 0x210(%rdi)
movq 0x379e0(%rip), %rax     # 0x68600
callq *0x90(%rax)
movl %ebx, %eax
popq %rbx
retq