// File: /workspace/github_c_makefile_star2_O3/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 0x34aef(%rip), %xmm0    # 0x52ef0
callq 0x19780
testq %rax, %rax
je 0x1e8a2
movq %rax, %r12
movq 0x330(%r12), %r14
testq %r14, %r14
je 0x1e427
movq (%r14), %rbx
testq %rbx, %rbx
jne 0x1e42f
movq 0x138(%r12), %rbx
movq %rbx, %rdi
leaq 0x3cb02(%rip), %rsi     # 0x5af3b
callq 0x18b20
testl %eax, %eax
je 0x1e4b6
movq %rbx, %rdi
leaq 0x34b04(%rip), %rsi     # 0x52f50
callq 0x18b20
testl %eax, %eax
je 0x1e4f7
movq %rbx, %rdi
leaq 0x34afb(%rip), %rsi     # 0x52f5e
callq 0x18b20
testl %ebp, %ebp
je 0x1e474
testl %eax, %eax
je 0x1e781
movq %rbx, %rdi
leaq 0x34af4(%rip), %rsi     # 0x52f72
callq 0x18b20
testl %ebp, %ebp
je 0x1e4ff
testl %eax, %eax
jne 0x1e4ff
movq %r15, %rdi
movq %r12, %rsi
callq 0x18400
movl 0x140(%r12), %ecx
testl %eax, %eax
jne 0x1e874
movl %ecx, %eax
andl $0x1, %eax
jne 0x1e711
jmp 0x1e874
movq 0x4a33b(%rip), %rax     # 0x687f8
movq (%rax), %rax
cmpq %rax, %r12
jne 0x1e4d2
cmpq %r15, 0x110(%rax)
je 0x1e711
movq 0x4a387(%rip), %rax     # 0x68860
movq (%rax), %rax
cmpq %rax, %r12
jne 0x1e76a
cmpq %r15, 0x110(%rax)
je 0x1e711
jmp 0x1e76a
testl %ebp, %ebp
jne 0x1e781
movq %rbx, %rdi
leaq 0x34a77(%rip), %rsi     # 0x52f80
callq 0x18b20
testl %eax, %eax
je 0x1e760
movq %rbx, %rdi
leaq 0x34a6a(%rip), %rsi     # 0x52f8a
callq 0x18b20
testl %eax, %eax
je 0x1e760
movq %rbx, %rdi
leaq 0x34a68(%rip), %rsi     # 0x52f9f
callq 0x18b20
testl %eax, %eax
je 0x1e798
movq %rbx, %rdi
leaq 0x34a6e(%rip), %rsi     # 0x52fbc
callq 0x18b20
testl %eax, %eax
je 0x1e742
movq %rbx, %rdi
leaq 0x34a62(%rip), %rsi     # 0x52fc7
callq 0x18b20
testl %eax, %eax
je 0x1e742
movq %rbx, %rdi
leaq 0x34a5a(%rip), %rsi     # 0x52fd6
callq 0x18b20
testl %eax, %eax
je 0x1e742
movq %rbx, %rdi
leaq 0x34a59(%rip), %rsi     # 0x52fec
callq 0x18b20
testl %eax, %eax
je 0x1e742
movq %rbx, %rdi
leaq 0x34a56(%rip), %rsi     # 0x53000
callq 0x18b20
testl %eax, %eax
je 0x1e74c
movq %rbx, %rdi
leaq 0x34a4f(%rip), %rsi     # 0x53010
callq 0x18b20
testl %eax, %eax
je 0x1e74c
movq %rbx, %rdi
leaq 0x34a4f(%rip), %rsi     # 0x53027
callq 0x18b20
testl %eax, %eax
je 0x1e735
movq %rbx, %rdi
leaq 0x34a4a(%rip), %rsi     # 0x53039
callq 0x18b20
testl %eax, %eax
je 0x1e735
movq %rbx, %rdi
leaq 0x34a47(%rip), %rsi     # 0x5304d
callq 0x18b20
testl %eax, %eax
je 0x1e735
movq %rbx, %rdi
leaq 0x34a3f(%rip), %rsi     # 0x5305c
callq 0x18b20
testl %eax, %eax
je 0x1e74c
movq %rbx, %rdi
leaq 0x34a3a(%rip), %rsi     # 0x5306e
callq 0x18b20
testl %eax, %eax
je 0x1e74c
movq %rbx, %rdi
leaq 0x34a35(%rip), %rsi     # 0x53080
callq 0x18b20
testl %eax, %eax
je 0x1e735
movq %rbx, %rdi
leaq 0x34a2e(%rip), %rsi     # 0x53090
callq 0x18b20
testl %eax, %eax
je 0x1e735
movq %rbx, %rdi
leaq 0x34a29(%rip), %rsi     # 0x530a2
callq 0x18b20
testl %eax, %eax
je 0x1e735
movq %rbx, %rdi
leaq 0x34a24(%rip), %rsi     # 0x530b4
callq 0x18b20
testl %eax, %eax
je 0x1e756
movq %rbx, %rdi
leaq 0x34a1b(%rip), %rsi     # 0x530c2
callq 0x18b20
testl %eax, %eax
je 0x1e756
movq %rbx, %rdi
leaq 0x34a12(%rip), %rsi     # 0x530d0
callq 0x18b20
testl %eax, %eax
je 0x1e756
movq %rbx, %rdi
leaq 0x34a07(%rip), %rsi     # 0x530dc
callq 0x18b20
testl %eax, %eax
je 0x1e756
movq %rbx, %rdi
leaq 0x34a04(%rip), %rsi     # 0x530ec
callq 0x18b20
testl %eax, %eax
je 0x1e756
movq %rbx, %rdi
leaq 0x34a00(%rip), %rsi     # 0x530fb
callq 0x18b20
testq %r14, %r14
jne 0x1e7af
testl %eax, %eax
je 0x1e7af
movq %r12, %rdi
movq %r13, %rsi
movss 0x347d1(%rip), %xmm0    # 0x52ef0
callq 0x19780
movq %rax, %r12
testq %rax, %rax
jne 0x1e412
jmp 0x1e8a2
movss 0x347cf(%rip), %xmm0    # 0x52f0c
jmp 0x1e7c2
movss 0x347ba(%rip), %xmm0    # 0x52f04
jmp 0x1e7c2
movss 0x347b4(%rip), %xmm0    # 0x52f08
jmp 0x1e7c2
movss 0x347b2(%rip), %xmm0    # 0x52f10
jmp 0x1e7c2
movss 0x34794(%rip), %xmm0    # 0x52efc
jmp 0x1e7c2
movss 0x347a2(%rip), %xmm0    # 0x52f14
movss %xmm0, 0x4(%rsp)
leaq 0x35fcc(%rip), %rbx     # 0x5474b
jmp 0x1e7ca
movss 0x3476b(%rip), %xmm0    # 0x52ef4
movss %xmm0, 0x4(%rsp)
leaq 0x347d7(%rip), %rbx     # 0x52f6d
jmp 0x1e7ca
movss 0x34760(%rip), %xmm0    # 0x52f00
movss %xmm0, 0x4(%rsp)
leaq 0x34803(%rip), %rbx     # 0x52fb0
jmp 0x1e7ca
xorl %ecx, %ecx
testl %eax, %eax
sete %cl
leaq 0x34773(%rip), %rax     # 0x52f30
movss (%rax,%rcx,4), %xmm0
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 0x192e0
movss %xmm0, 0x44(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x18400
cmpl $0x0, 0xc(%rsp)
je 0x1e81c
testl %eax, %eax
je 0x1e3f3
movss 0x346f4(%rip), %xmm0    # 0x52f18
maxss 0x44(%rsp), %xmm0
movss 0x346ea(%rip), %xmm1    # 0x52f1c
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 0x1e3f3
movq 0x130(%r12), %rbx
testb $0x2, %cl
movl 0x8(%rsp), %eax
movl $0x1, %ecx
cmovnel %ecx, %eax
movl %eax, 0x8(%rsp)
movss 0x34661(%rip), %xmm0    # 0x52ef8
movss %xmm0, 0x4(%rsp)
jmp 0x1e7ca
movq 0x38(%rsp), %r12
testq %r12, %r12
je 0x1e8c7
cmpl $0x0, 0x8(%rsp)
je 0x1e8d4
movq 0x10(%rsp), %rsi
testq %rsi, %rsi
je 0x1e926
movq 0x18(%rsp), %rdi
jmp 0x1eb54
movq 0x18(%rsp), %rax
movb $0x0, (%rax)
jmp 0x1eb59
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 0x192e0
movss 0x34615(%rip), %xmm1    # 0x52f20
ucomiss %xmm0, %xmm1
jbe 0x1e95a
movq 0x18(%rsp), %r14
movl $0x207461, (%r14)       # imm = 0x207461
movq 0x10(%rsp), %r15
jmp 0x1ea29
movq 0x330(%r12), %rax
testq %rax, %rax
movq 0x18(%rsp), %rdi
je 0x1e9c9
movq 0x50(%rax), %rsi
testq %rsi, %rsi
jne 0x1eb54
movq (%rax), %rsi
testq %rsi, %rsi
jne 0x1eb54
jmp 0x1eb59
movq 0x28(%rsp), %xmm0
movdqa 0x345d8(%rip), %xmm2    # 0x52f40
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 0x1e9a7
ucomiss %xmm2, %xmm4
jbe 0x1e9a7
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
movq 0x10(%rsp), %r15
jbe 0x1e9f0
movabsq $0x666f206874726f6e, %rax # imm = 0x666F206874726F6E
jmp 0x1e9fa
ucomiss %xmm2, %xmm3
movq 0x10(%rsp), %r15
jbe 0x1e9d6
shufps $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x1ea06
movabsq $0x20666f2074736577, %rax # imm = 0x20666F2074736577
jmp 0x1ea10
movq 0x138(%r12), %rsi
jmp 0x1eb54
pxor %xmm0, %xmm0
ucomiss %xmm0, %xmm1
jbe 0x1ea1a
movl $0x20776f, 0x3(%r14)    # imm = 0x20776F
movl $0x6f6c6562, (%r14)     # imm = 0x6F6C6562
jmp 0x1ea29
movabsq $0x666f206874756f73, %rax # imm = 0x666F206874756F73
movq %rax, (%r14)
movw $0x20, 0x8(%r14)
jmp 0x1ea29
movabsq $0x20666f2074736165, %rax # imm = 0x20666F2074736165
movq %rax, (%r14)
movb $0x0, 0x8(%r14)
jmp 0x1ea29
movl $0x206576, 0x3(%r14)    # imm = 0x206576
movl $0x766f6261, (%r14)     # imm = 0x766F6261
testl %ebp, %ebp
jne 0x1ea43
movq %r14, %rdi
callq 0x18680
movl $0x20656874, (%r14,%rax) # imm = 0x20656874
movb $0x0, 0x4(%r14,%rax)
leaq 0x34506(%rip), %rdx     # 0x52f50
xorl %edi, %edi
movl $0x138, %esi            # imm = 0x138
callq 0x19430
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 0x192e0
movss %xmm0, 0xc(%rsp)
leaq 0x344cb(%rip), %rdx     # 0x52f5e
xorl %edi, %edi
movl $0x138, %esi            # imm = 0x138
callq 0x19430
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 0x192e0
testl %ebp, %ebp
jne 0x1eb1c
movaps %xmm0, %xmm1
addss %xmm0, %xmm1
movss 0xc(%rsp), %xmm2
ucomiss %xmm1, %xmm2
jbe 0x1eafa
movq %r14, %rdi
callq 0x18680
movl $0x65756c62, (%r14,%rax) # imm = 0x65756C62
movw $0x20, 0x4(%r14,%rax)
jmp 0x1eb1c
movaps %xmm2, %xmm1
addss %xmm2, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x1eb1c
movq %r14, %rdi
callq 0x18680
movl $0x20646572, (%r14,%rax) # imm = 0x20646572
movb $0x0, 0x4(%r14,%rax)
testq %r15, %r15
je 0x1eb29
movq %r14, %rdi
movq %r15, %rsi
jmp 0x1eb54
movq 0x330(%r12), %rax
testq %rax, %rax
je 0x1eb49
movq 0x50(%rax), %rsi
testq %rsi, %rsi
jne 0x1eb51
movq (%rax), %rsi
testq %rsi, %rsi
jne 0x1eb51
jmp 0x1eb59
movq 0x138(%r12), %rsi
movq %r14, %rdi
callq 0x19640
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq