// File: /workspace/github_c_makefile_star2_O2/QwazyWabbitWOS[P]lmctf60/g_replace.c
// Function: replace_location
void replace_location(edict_t *person, char *temp, 
									  qboolean positionvalid, qboolean lineofsight)
{
	edict_t *cur = NULL;
	edict_t *fav = NULL;
	float favrating = 0;
	float currating;
	vec3_t distvector;
	float curdist, reddist, bluedist;
	char *name, *showname, *favname = NULL ; //MJD Uninitilized - Might
	                                          //be used this way. This
	qboolean	noprefix = false;
	strcpy(temp,"");

	while ((cur = findallradius(cur, person->s.origin, 1024)) != NULL)
	{
		if 	(cur->item && cur->item->classname)
			name = cur->item->classname;
		else
			name = cur->classname;
		
		currating = 1;
		showname = NULL;

		if (!strcmp(name, "flag"))
		{
			if ((redflag && (cur == redflag) && (person == redflag->owner)) ||
				(blueflag && (cur == blueflag) && (person == blueflag->owner)))
				continue;
			showname = "Flag";
			currating *= 10;
		}
		else if ((!strcmp(name, "info_flag_red") ||
				 !strcmp(name, "info_flag_blue")) && positionvalid) 
		{
			showname = "Base";
			currating *= 12;
		}
		else if (!strcmp(name, "info_position") && positionvalid)
		{
			// Skip this if spawnflags is 1, and it is not visible.
			if (!visibility_test(person,cur) && (cur->spawnflags & 1))
				continue;
			showname = cur->message;
			currating *= 1000;
			if (cur->spawnflags & 2)
				noprefix = true;
		}

		else if (!strcmp(name, "item_quad") ||
			!strcmp(name, "item_invulnerability") )
		{
			currating *= 8;
		}
		else if (!strcmp(name, "item_health_mega") )
		{
			showname = "Mega Health";
			currating *= 7;
		}
		else if (!strcmp(name, "weapon_bfg") ||
			!strcmp(name, "weapon_railgun") ||
			!strcmp(name, "weapon_rocketlauncher") ||
			!strcmp(name, "weapon_hyperblaster") )
		{
			currating *= 6;
		}
		else if (!strcmp(name, "weapon_chaingun") ||
			!strcmp(name, "weapon_grenadelauncher") )
		{
			currating *= 5;
		}
		else if (!strcmp(name, "weapon_machinegun") ||
			!strcmp(name, "weapon_supershotgun") ||
			!strcmp(name, "weapon_shotgun") )
		{
			currating *= 4;
		}
		else if (!strcmp(name, "item_power_screen") ||
			!strcmp(name, "item_power_shield") )
		{
			currating *= 5;
		}
		else if (!strcmp(name, "item_armor_body") ||
			!strcmp(name, "item_armor_combat") ||
			!strcmp(name, "item_armor_jacket") )
		{
			currating *= 4;
		}
		else if (!strcmp(name, "item_silencer") ||
			!strcmp(name, "item_breather") ||
			!strcmp(name, "item_enviro") ||
			!strcmp(name, "item_adrenaline") ||
			!strcmp(name, "item_bandolier") ||
			!strcmp(name, "item_pack") )
		{
			currating *= 3;
		}
		else if (!cur->item)
			continue;
		else
			currating *= 1;
		//ok, we now have a preliminary rating based on the type of object.
		//now lets decide a bit based on the distance to the ob
	
		VectorSubtract(person->s.origin, cur->s.origin, distvector);
		curdist = VectorLength(distvector);
	
		if (curdist < 64)
			curdist = 64; 
		//don't count distances less than a playerwidth away
		//as being significantly different
	
		currating *= (12000/curdist); //score increases for small distances
	
		//and lets adjust the rating further by whether or not we 
		//have line of sight to the object in question.

		// Don't tell us about powerup if they are not in sight
		if ( !visibility_test(person,cur) && lineofsight)
			continue;
	
		if (currating > favrating) //new winner
		{
			fav = cur;
			favrating = currating;
			favname = showname;  // MJD If you fail this test,
			                     // favname may stay uninitilized!
		}
	}
	
	//test distances to the flags
	if (fav == NULL)
		strcpy(temp, "");
	else if (noprefix)
	{
		if (favname != NULL) // MJD Because of this line, favname should
		             // be null, I think... (surt agrees ... initialized above now)
		{
			strcat(temp, favname);
		}
		else if (fav->item)
		{
			if (fav->item->pickup_name)
				strcat(temp, fav->item->pickup_name);
			else if (fav->item->classname)
				strcat(temp, fav->item->classname);
		}
		else
			strcat(temp, fav->classname);
	}
	else
	{
		VectorSubtract(fav->s.origin, person->s.origin, distvector);
		if (VectorLength(distvector) < 128)
			strcpy(temp, "at ");
		else
		{
			if (fabsf(distvector[0]) > fabsf(distvector[1]) &&		// 0 Biggest
				fabsf(distvector[0]) > fabsf(distvector[2]))
			{
				if (distvector[0] > 0)
					strcpy(temp, "north of ");
				else
					strcpy(temp, "south of ");
			}
			else if (fabsf(distvector[1]) > fabsf(distvector[2]))	// 1 biggest
			{
				if (distvector[1] > 0)
					strcpy(temp, "west of ");
				else
					strcpy(temp, "east of ");
			}
			else												// 2 biggest
			{
				if (distvector[2] > 0)
					strcpy(temp, "below ");
				else
					strcpy(temp, "above ");
			}

		}
		

		if (!positionvalid)
			strcat(temp, "the ");

		cur = G_Find(NULL, FOFS(classname), "info_flag_red");
		VectorSubtract(fav->s.origin, cur->s.origin, distvector);
		reddist = VectorLength(distvector);
		cur = G_Find(NULL, FOFS(classname), "info_flag_blue");
		VectorSubtract(fav->s.origin, cur->s.origin, distvector);
		bluedist = VectorLength(distvector);
		
		if (!positionvalid)
		{
			if (reddist > 2 * bluedist ) //closer to blue
				strcat(temp, "blue ");
			else if (bluedist > 2 * reddist ) //closer to red
				strcat(temp, "red ");
		}

		if (favname)
		{
			strcat(temp, favname);
		}
		else if (fav->item)
		{
			if (fav->item->pickup_name)
				strcat(temp, fav->item->pickup_name);
			else if (fav->item->classname)
				strcat(temp, fav->item->classname);
		}
		else
			strcat(temp, fav->classname);

	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %ecx, 0xc(%rsp)
movl %edx, %ebp
movq %rdi, %r15
movq %rsi, 0x18(%rsp)
movb $0x0, (%rsi)
leaq 0x4(%rdi), %r13
movq $0x0, 0x38(%rsp)
xorps %xmm0, %xmm0
movss %xmm0, 0x24(%rsp)
xorl %r12d, %r12d
movq $0x0, 0x10(%rsp)
movl $0x0, 0x8(%rsp)
movq %r12, %rdi
movq %r13, %rsi
movss 0x321f8(%rip), %xmm0    # 0x4eef0
callq 0x19960
testq %rax, %rax
je 0x1d156
movq %rax, %r12
movq 0x330(%rax), %r14
testq %r14, %r14
je 0x1cd1d
movq (%r14), %rbx
testq %rbx, %rbx
jne 0x1cd25
movq 0x138(%r12), %rbx
movq %rbx, %rdi
leaq 0x3a1cc(%rip), %rsi     # 0x56efb
callq 0x18bc0
testl %eax, %eax
je 0x1cd80
movq %rbx, %rdi
leaq 0x3220e(%rip), %rsi     # 0x4ef50
callq 0x18bc0
testl %eax, %eax
je 0x1cdd2
movq %rbx, %rdi
leaq 0x32205(%rip), %rsi     # 0x4ef5e
callq 0x18bc0
testl %ebp, %ebp
je 0x1cdd6
testl %eax, %eax
jne 0x1cdd6
movss 0x32186(%rip), %xmm0    # 0x4eef4
movss %xmm0, 0x4(%rsp)
leaq 0x321f2(%rip), %rbx     # 0x4ef6d
jmp 0x1d092
movq 0x49a71(%rip), %rax     # 0x667f8
movq (%rax), %rax
cmpq %rax, %r12
jne 0x1cd9c
cmpq %r15, 0x110(%rax)
je 0x1ccea
movq 0x49abd(%rip), %rax     # 0x66860
movq (%rax), %rax
cmpq %rax, %r12
jne 0x1cdb8
cmpq %r15, 0x110(%rax)
je 0x1ccea
movss 0x32154(%rip), %xmm0    # 0x4ef14
movss %xmm0, 0x4(%rsp)
leaq 0x3395e(%rip), %rbx     # 0x5072b
jmp 0x1d092
testl %ebp, %ebp
jne 0x1cd66
movq %rbx, %rdi
leaq 0x32192(%rip), %rsi     # 0x4ef72
callq 0x18bc0
testl %ebp, %ebp
je 0x1ce3b
testl %eax, %eax
jne 0x1ce3b
movq %r15, %rdi
movq %r12, %rsi
callq 0x18430
movl 0x140(%r12), %ecx
testl %eax, %eax
jne 0x1ce0f
movl %ecx, %eax
andl $0x1, %eax
jne 0x1ccea
movq 0x130(%r12), %rbx
testb $0x2, %cl
pushq $0x1
popq %rax
movl 0x8(%rsp), %ecx
cmovnel %eax, %ecx
movl %ecx, 0x8(%rsp)
movss 0x320e0(%rip), %xmm0    # 0x4ef10
movss %xmm0, 0x4(%rsp)
jmp 0x1d092
movq %rbx, %rdi
leaq 0x3213b(%rip), %rsi     # 0x4ef80
callq 0x18bc0
testl %eax, %eax
je 0x1d082
movq %rbx, %rdi
leaq 0x3212e(%rip), %rsi     # 0x4ef8a
callq 0x18bc0
testl %eax, %eax
je 0x1d082
movq %rbx, %rdi
leaq 0x3212c(%rip), %rsi     # 0x4ef9f
callq 0x18bc0
testl %eax, %eax
je 0x1d13c
movq %rbx, %rdi
leaq 0x32132(%rip), %rsi     # 0x4efbc
callq 0x18bc0
testl %eax, %eax
je 0x1d064
movq %rbx, %rdi
leaq 0x32126(%rip), %rsi     # 0x4efc7
callq 0x18bc0
testl %eax, %eax
je 0x1d064
movq %rbx, %rdi
leaq 0x3211e(%rip), %rsi     # 0x4efd6
callq 0x18bc0
testl %eax, %eax
je 0x1d064
movq %rbx, %rdi
leaq 0x3211d(%rip), %rsi     # 0x4efec
callq 0x18bc0
testl %eax, %eax
je 0x1d064
movq %rbx, %rdi
leaq 0x3211a(%rip), %rsi     # 0x4f000
callq 0x18bc0
testl %eax, %eax
je 0x1d06e
movq %rbx, %rdi
leaq 0x32113(%rip), %rsi     # 0x4f010
callq 0x18bc0
testl %eax, %eax
je 0x1d06e
movq %rbx, %rdi
leaq 0x32113(%rip), %rsi     # 0x4f027
callq 0x18bc0
testl %eax, %eax
je 0x1d05a
movq %rbx, %rdi
leaq 0x3210e(%rip), %rsi     # 0x4f039
callq 0x18bc0
testl %eax, %eax
je 0x1d05a
movq %rbx, %rdi
leaq 0x3210b(%rip), %rsi     # 0x4f04d
callq 0x18bc0
testl %eax, %eax
je 0x1d05a
movq %rbx, %rdi
leaq 0x32103(%rip), %rsi     # 0x4f05c
callq 0x18bc0
testl %eax, %eax
je 0x1d06e
movq %rbx, %rdi
leaq 0x320fe(%rip), %rsi     # 0x4f06e
callq 0x18bc0
testl %eax, %eax
je 0x1d06e
movq %rbx, %rdi
leaq 0x320f9(%rip), %rsi     # 0x4f080
callq 0x18bc0
testl %eax, %eax
je 0x1d05a
movq %rbx, %rdi
leaq 0x320f2(%rip), %rsi     # 0x4f090
callq 0x18bc0
testl %eax, %eax
je 0x1d05a
movq %rbx, %rdi
leaq 0x320ed(%rip), %rsi     # 0x4f0a2
callq 0x18bc0
testl %eax, %eax
je 0x1d05a
movq %rbx, %rdi
leaq 0x320e8(%rip), %rsi     # 0x4f0b4
callq 0x18bc0
testl %eax, %eax
je 0x1d078
movq %rbx, %rdi
leaq 0x320df(%rip), %rsi     # 0x4f0c2
callq 0x18bc0
testl %eax, %eax
je 0x1d078
movq %rbx, %rdi
leaq 0x320d6(%rip), %rsi     # 0x4f0d0
callq 0x18bc0
testl %eax, %eax
je 0x1d078
movq %rbx, %rdi
leaq 0x320cf(%rip), %rsi     # 0x4f0dc
callq 0x18bc0
testl %eax, %eax
je 0x1d078
movq %rbx, %rdi
leaq 0x320cc(%rip), %rsi     # 0x4f0ec
callq 0x18bc0
testl %eax, %eax
je 0x1d078
movq %rbx, %rdi
leaq 0x320c8(%rip), %rsi     # 0x4f0fb
callq 0x18bc0
testq %r14, %r14
jne 0x1d045
testl %eax, %eax
jne 0x1ccea
xorl %ecx, %ecx
testl %eax, %eax
sete %cl
leaq 0x31edd(%rip), %rax     # 0x4ef30
movss (%rax,%rcx,4), %xmm0
jmp 0x1d08a
movss 0x31ea6(%rip), %xmm0    # 0x4ef08
jmp 0x1d08a
movss 0x31e94(%rip), %xmm0    # 0x4ef00
jmp 0x1d08a
movss 0x31e8e(%rip), %xmm0    # 0x4ef04
jmp 0x1d08a
movss 0x31e8c(%rip), %xmm0    # 0x4ef0c
jmp 0x1d08a
movss 0x31e6e(%rip), %xmm0    # 0x4eef8
movss %xmm0, 0x4(%rsp)
xorl %ebx, %ebx
movsd 0x4(%r15), %xmm0
movsd 0x4(%r12), %xmm1
subps %xmm1, %xmm0
movlps %xmm0, 0x28(%rsp)
movss 0xc(%r15), %xmm0
subss 0xc(%r12), %xmm0
movss %xmm0, 0x30(%rsp)
leaq 0x28(%rsp), %rdi
callq 0x19460
movss %xmm0, 0x44(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x18430
cmpl $0x0, 0xc(%rsp)
je 0x1d0e4
testl %eax, %eax
je 0x1ccea
movss 0x31e2c(%rip), %xmm0    # 0x4ef18
maxss 0x44(%rsp), %xmm0
movss 0x31e22(%rip), %xmm1    # 0x4ef1c
divss %xmm0, %xmm1
movss 0x4(%rsp), %xmm2
mulss %xmm1, %xmm2
movss 0x24(%rsp), %xmm0
ucomiss %xmm0, %xmm2
maxss %xmm0, %xmm2
movq 0x38(%rsp), %rax
cmovaq %r12, %rax
movq %rax, 0x38(%rsp)
movq 0x10(%rsp), %rax
cmovaq %rbx, %rax
movq %rax, 0x10(%rsp)
movss %xmm2, 0x24(%rsp)
jmp 0x1ccea
movss 0x31db8(%rip), %xmm0    # 0x4eefc
movss %xmm0, 0x4(%rsp)
leaq 0x31e5f(%rip), %rbx     # 0x4efb0
jmp 0x1d092
movq 0x38(%rsp), %r12
testq %r12, %r12
je 0x1d17b
cmpl $0x0, 0x8(%rsp)
je 0x1d188
movq 0x10(%rsp), %rsi
testq %rsi, %rsi
je 0x1d1da
movq 0x18(%rsp), %rdi
jmp 0x1d408
movq 0x18(%rsp), %rax
movb $0x0, (%rax)
jmp 0x1d40d
movsd 0x4(%r12), %xmm0
movsd 0x4(%r15), %xmm1
subps %xmm1, %xmm0
leaq 0x28(%rsp), %rdi
movlps %xmm0, (%rdi)
movss 0xc(%r12), %xmm0
subss 0xc(%r15), %xmm0
movss %xmm0, 0x8(%rdi)
callq 0x19460
movss 0x31d61(%rip), %xmm1    # 0x4ef20
ucomiss %xmm0, %xmm1
jbe 0x1d20e
movq 0x18(%rsp), %r14
movl $0x207461, (%r14)       # imm = 0x207461
movq 0x10(%rsp), %r15
jmp 0x1d2dd
movq 0x330(%r12), %rax
testq %rax, %rax
movq 0x18(%rsp), %rdi
je 0x1d27d
movq 0x50(%rax), %rsi
testq %rsi, %rsi
jne 0x1d408
movq (%rax), %rsi
testq %rsi, %rsi
jne 0x1d408
jmp 0x1d40d
movq 0x28(%rsp), %xmm0
movdqa 0x31d24(%rip), %xmm2    # 0x4ef40
movdqa %xmm0, %xmm4
pand %xmm2, %xmm4
pshufd $0x55, %xmm4, %xmm3     # xmm3 = xmm4[1,1,1,1]
ucomiss %xmm3, %xmm4
movd 0x30(%rsp), %xmm1
pand %xmm1, %xmm2
movq 0x18(%rsp), %r14
jbe 0x1d25b
ucomiss %xmm2, %xmm4
jbe 0x1d25b
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
movq 0x10(%rsp), %r15
jbe 0x1d2a4
movabsq $0x666f206874726f6e, %rax # imm = 0x666F206874726F6E
jmp 0x1d2ae
ucomiss %xmm2, %xmm3
movq 0x10(%rsp), %r15
jbe 0x1d28a
shufps $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x1d2ba
movabsq $0x20666f2074736577, %rax # imm = 0x20666F2074736577
jmp 0x1d2c4
movq 0x138(%r12), %rsi
jmp 0x1d408
pxor %xmm0, %xmm0
ucomiss %xmm0, %xmm1
jbe 0x1d2ce
movl $0x20776f, 0x3(%r14)    # imm = 0x20776F
movl $0x6f6c6562, (%r14)     # imm = 0x6F6C6562
jmp 0x1d2dd
movabsq $0x666f206874756f73, %rax # imm = 0x666F206874756F73
movq %rax, (%r14)
movw $0x20, 0x8(%r14)
jmp 0x1d2dd
movabsq $0x20666f2074736165, %rax # imm = 0x20666F2074736165
movq %rax, (%r14)
movb $0x0, 0x8(%r14)
jmp 0x1d2dd
movl $0x206576, 0x3(%r14)    # imm = 0x206576
movl $0x766f6261, (%r14)     # imm = 0x766F6261
testl %ebp, %ebp
jne 0x1d2f7
movq %r14, %rdi
callq 0x186c0
movl $0x20656874, (%r14,%rax) # imm = 0x20656874
movb $0x0, 0x4(%r14,%rax)
leaq 0x31c52(%rip), %rdx     # 0x4ef50
xorl %edi, %edi
movl $0x138, %esi            # imm = 0x138
callq 0x195e0
movsd 0x4(%r12), %xmm0
movsd 0x4(%rax), %xmm1
subps %xmm1, %xmm0
leaq 0x28(%rsp), %rbx
movlps %xmm0, (%rbx)
movss 0xc(%r12), %xmm0
subss 0xc(%rax), %xmm0
movss %xmm0, 0x8(%rbx)
movq %rbx, %rdi
callq 0x19460
movss %xmm0, 0xc(%rsp)
leaq 0x31c17(%rip), %rdx     # 0x4ef5e
xorl %edi, %edi
movl $0x138, %esi            # imm = 0x138
callq 0x195e0
movsd 0x4(%r12), %xmm0
movsd 0x4(%rax), %xmm1
subps %xmm1, %xmm0
movlps %xmm0, (%rbx)
movss 0xc(%r12), %xmm0
subss 0xc(%rax), %xmm0
movss %xmm0, 0x8(%rbx)
movq %rbx, %rdi
callq 0x19460
testl %ebp, %ebp
jne 0x1d3d0
movaps %xmm0, %xmm1
addss %xmm0, %xmm1
movss 0xc(%rsp), %xmm2
ucomiss %xmm1, %xmm2
jbe 0x1d3ae
movq %r14, %rdi
callq 0x186c0
movl $0x65756c62, (%r14,%rax) # imm = 0x65756C62
movw $0x20, 0x4(%r14,%rax)
jmp 0x1d3d0
movaps %xmm2, %xmm1
addss %xmm2, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x1d3d0
movq %r14, %rdi
callq 0x186c0
movl $0x20646572, (%r14,%rax) # imm = 0x20646572
movb $0x0, 0x4(%r14,%rax)
testq %r15, %r15
je 0x1d3dd
movq %r14, %rdi
movq %r15, %rsi
jmp 0x1d408
movq 0x330(%r12), %rax
testq %rax, %rax
je 0x1d3fd
movq 0x50(%rax), %rsi
testq %rsi, %rsi
jne 0x1d405
movq (%rax), %rsi
testq %rsi, %rsi
jne 0x1d405
jmp 0x1d40d
movq 0x138(%r12), %rsi
movq %r14, %rdi
callq 0x19800
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq