// File: /workspace/github_c_makefile_star2_O2/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 %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rsi, %r15
movq %rdi, %rbx
movq 0x330(%rdi), %r14
movq 0x70(%r14), %r12
movq %rsi, %rdi
callq 0x187a0
cmpl $0x4, 0x78(%r14)
jne 0x2e131
movq 0x58(%r15), %rcx
testl %eax, %eax
je 0x2e146
cltq
addl $0x2, 0x318(%rcx,%rax,4)
jmp 0x2e230
testl %eax, %eax
je 0x2e15d
cmpl 0x42b0d(%rip), %eax     # 0x70c48
jne 0x2e185
movq 0x38c24(%rip), %rcx     # 0x66d68
jmp 0x2e18c
movslq 0x42af7(%rip), %rax     # 0x70c44
movl $0x2, 0x318(%rcx,%rax,4)
jmp 0x2e230
movl (%r12), %ecx
movq 0x58(%r15), %rsi
subq 0x38cd4(%rip), %r14     # 0x66e40
movl $0x88, %edi
movq %r14, %rax
cqto
idivq %rdi
movl %ecx, 0x318(%rsi,%rax,4)
jmp 0x2e230
movq 0x3844c(%rip), %rcx     # 0x665d8
cmpl 0x42ab2(%rip), %eax     # 0x70c44
jne 0x2e19b
movq 0x3876d(%rip), %rcx     # 0x66908
movss 0x8(%r12), %xmm1
movss 0x8(%rcx), %xmm0
ucomiss %xmm0, %xmm1
jbe 0x2e1fa
divss %xmm1, %xmm0
movq 0x58(%r15), %rcx
cltq
cvtsi2ssl 0x318(%rcx,%rax,4), %xmm1
mulss %xmm0, %xmm1
cvttss2si %xmm1, %esi
addl (%r12), %esi
movl 0x4(%r12), %edx
cmpl %edx, %esi
cmovgel %edx, %esi
andl $0x0, 0x318(%rcx,%rax,4)
subq 0x38c5c(%rip), %r14     # 0x66e40
movl $0x88, %edi
movq %r14, %rax
cqto
idivq %rdi
movl %esi, 0x318(%rcx,%rax,4)
jmp 0x2e230
divss %xmm0, %xmm1
cvtsi2ssl (%r12), %xmm0
mulss %xmm1, %xmm0
cvttss2si %xmm0, %edx
movq 0x58(%r15), %rsi
cltq
movl 0x318(%rsi,%rax,4), %edi
addl %edi, %edx
movl 0x4(%rcx), %ecx
cmpl %ecx, %edx
cmovgel %ecx, %edx
xorl %ebp, %ebp
cmpl %edx, %edi
jge 0x2e265
movl %edx, 0x318(%rsi,%rax,4)
pushq $0x1
popq %rbp
testb $0x1, 0x142(%rbx)
jne 0x2e265
movq 0x38c7d(%rip), %rax     # 0x66ec0
movq (%rax), %rax
movss 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x2e255
jnp 0x2e265
movss 0x219e3(%rip), %xmm0    # 0x4fc40
movq %rbx, %rdi
callq 0x196d0
movl %ebp, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq