// File: /workspace/github_c_makefile_star2_O1/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:
movq 0x330(%rdi), %rcx
movq 0x58(%rsi), %rax
testq %rax, %rax
je 0x30fe0
movslq 0x42b95(%rip), %rdx     # 0x73b44
cmpl $0x0, 0x318(%rax,%rdx,4)
jg 0x30fe2
movslq 0x42b88(%rip), %rdx     # 0x73b48
cmpl $0x0, 0x318(%rax,%rdx,4)
jg 0x30fe2
movslq 0x42b7b(%rip), %rsi     # 0x73b4c
xorl %edx, %edx
cmpl $0x0, 0x318(%rax,%rsi,4)
cmovgl %esi, %edx
jmp 0x30fe2
xorl %edx, %edx
pushq %rbx
cmpl $0x4, 0x78(%rcx)
jne 0x30ffd
testl %edx, %edx
je 0x31016
movslq %edx, %rcx
addl $0x2, 0x318(%rax,%rcx,4)
jmp 0x31108
movq 0x70(%rcx), %rsi
testl %edx, %edx
je 0x3102d
cmpl 0x42b3d(%rip), %edx     # 0x73b48
jne 0x31054
movq 0x38d54(%rip), %r8      # 0x69d68
jmp 0x3105b
movslq 0x42b27(%rip), %rcx     # 0x73b44
movl $0x2, 0x318(%rax,%rcx,4)
jmp 0x31108
movl (%rsi), %edx
subq 0x38e0a(%rip), %rcx     # 0x69e40
sarq $0x3, %rcx
movabsq $-0x3c3c3c3c3c3c3c3c, %rsi # imm = 0xC3C3C3C3C3C3C3C4
imulq %rcx, %rsi
movl %edx, 0x318(%rax,%rsi)
jmp 0x31108
movq 0x3857d(%rip), %r8      # 0x695d8
cmpl 0x42ae3(%rip), %edx     # 0x73b44
jne 0x3106a
movq 0x3889e(%rip), %r8      # 0x69908
movss 0x8(%rsi), %xmm0
movss 0x8(%r8), %xmm1
ucomiss %xmm1, %xmm0
jbe 0x310d1
divss %xmm0, %xmm1
movslq %edx, %rdx
xorps %xmm0, %xmm0
cvtsi2ssl 0x318(%rax,%rdx,4), %xmm0
mulss %xmm1, %xmm0
cvttss2si %xmm0, %r8d
addl (%rsi), %r8d
movl 0x4(%rsi), %esi
cmpl %esi, %r8d
cmovgel %esi, %r8d
movl $0x0, 0x318(%rax,%rdx,4)
subq 0x38d8b(%rip), %rcx     # 0x69e40
sarq $0x3, %rcx
movabsq $-0x3c3c3c3c3c3c3c3c, %rdx # imm = 0xC3C3C3C3C3C3C3C4
imulq %rcx, %rdx
movl %r8d, 0x318(%rax,%rdx)
jmp 0x31108
divss %xmm1, %xmm0
xorps %xmm1, %xmm1
cvtsi2ssl (%rsi), %xmm1
mulss %xmm0, %xmm1
cvttss2si %xmm1, %ecx
movslq %edx, %rdx
movl 0x318(%rax,%rdx,4), %esi
addl %esi, %ecx
movl 0x4(%r8), %r8d
cmpl %r8d, %ecx
cmovgel %r8d, %ecx
xorl %ebx, %ebx
cmpl %ecx, %esi
jge 0x3117e
movl %ecx, 0x318(%rax,%rdx,4)
movl $0x1, %ebx
testb $0x1, 0x142(%rdi)
jne 0x3117e
movq 0x38da3(%rip), %rax     # 0x69ec0
movq (%rax), %rax
movss 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x3112f
jnp 0x3117e
orb $-0x80, 0x11f(%rdi)
orb $0x1, 0xc8(%rdi)
movl $0x0, 0x108(%rdi)
movq 0x38c52(%rip), %rax     # 0x69da0
movss 0x4(%rax), %xmm0
addss 0x23ab5(%rip), %xmm0    # 0x54c10
movss %xmm0, 0x200(%rdi)
movq 0x38be6(%rip), %rax     # 0x69d50
movq %rax, 0x210(%rdi)
movq 0x38488(%rip), %rax     # 0x69600
callq *0x90(%rax)
movl %ebx, %eax
popq %rbx
retq