// File: /workspace/github_c_makefile_star2_O1/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, 0x28(%rsp)
movb $0x0, (%rsi)
leaq 0x4(%rdi), %r13
movq $0x0, 0x38(%rsp)
xorps %xmm0, %xmm0
movss %xmm0, 0x34(%rsp)
xorl %r12d, %r12d
movq $0x0, 0x10(%rsp)
movl $0x0, 0x8(%rsp)
movq %r12, %rdi
movq %r13, %rsi
movss 0x35ab7(%rip), %xmm0    # 0x53ef0
callq 0x19790
testq %rax, %rax
je 0x1e8f3
movq %rax, %r12
movq 0x330(%r12), %r14
testq %r14, %r14
je 0x1e45f
movq (%r14), %rbx
testq %rbx, %rbx
jne 0x1e467
movq 0x138(%r12), %rbx
movq %rbx, %rdi
leaq 0x3d77a(%rip), %rsi     # 0x5bbeb
callq 0x18b20
testl %eax, %eax
je 0x1e4a9
movq %rbx, %rdi
leaq 0x35acc(%rip), %rsi     # 0x53f50
callq 0x18b20
testl %eax, %eax
je 0x1e4ea
movq %rbx, %rdi
leaq 0x35ac7(%rip), %rsi     # 0x53f5e
callq 0x18b20
testl %ebp, %ebp
je 0x1e4f2
testl %eax, %eax
jne 0x1e4f2
jmp 0x1e7b4
movq 0x4b348(%rip), %rax     # 0x697f8
movq (%rax), %rax
cmpq %rax, %r12
jne 0x1e4c5
cmpq %r15, 0x110(%rax)
je 0x1e742
movq 0x4b394(%rip), %rax     # 0x69860
movq (%rax), %rax
cmpq %rax, %r12
jne 0x1e79a
cmpq %r15, 0x110(%rax)
je 0x1e742
jmp 0x1e79a
testl %ebp, %ebp
jne 0x1e7b4
movq %rbx, %rdi
leaq 0x35a76(%rip), %rsi     # 0x53f72
callq 0x18b20
testl %ebp, %ebp
je 0x1e530
testl %eax, %eax
jne 0x1e530
movq %r15, %rdi
movq %r12, %rsi
callq 0x18400
testl %eax, %eax
jne 0x1e7d5
testb $0x1, 0x140(%r12)
jne 0x1e742
jmp 0x1e7d5
movq %rbx, %rdi
leaq 0x35a46(%rip), %rsi     # 0x53f80
callq 0x18b20
testl %eax, %eax
je 0x1e7cb
movq %rbx, %rdi
leaq 0x35a39(%rip), %rsi     # 0x53f8a
callq 0x18b20
testl %eax, %eax
je 0x1e7cb
movq %rbx, %rdi
leaq 0x35a37(%rip), %rsi     # 0x53f9f
callq 0x18b20
testl %eax, %eax
je 0x1e806
movq %rbx, %rdi
leaq 0x35a3d(%rip), %rsi     # 0x53fbc
callq 0x18b20
testl %eax, %eax
je 0x1e773
movq %rbx, %rdi
leaq 0x35a31(%rip), %rsi     # 0x53fc7
callq 0x18b20
testl %eax, %eax
je 0x1e773
movq %rbx, %rdi
leaq 0x35a29(%rip), %rsi     # 0x53fd6
callq 0x18b20
testl %eax, %eax
je 0x1e773
movq %rbx, %rdi
leaq 0x35a28(%rip), %rsi     # 0x53fec
callq 0x18b20
testl %eax, %eax
je 0x1e773
movq %rbx, %rdi
leaq 0x35a25(%rip), %rsi     # 0x54000
callq 0x18b20
testl %eax, %eax
je 0x1e780
movq %rbx, %rdi
leaq 0x35a1e(%rip), %rsi     # 0x54010
callq 0x18b20
testl %eax, %eax
je 0x1e780
movq %rbx, %rdi
leaq 0x35a1e(%rip), %rsi     # 0x54027
callq 0x18b20
testl %eax, %eax
je 0x1e766
movq %rbx, %rdi
leaq 0x35a19(%rip), %rsi     # 0x54039
callq 0x18b20
testl %eax, %eax
je 0x1e766
movq %rbx, %rdi
leaq 0x35a16(%rip), %rsi     # 0x5404d
callq 0x18b20
testl %eax, %eax
je 0x1e766
movq %rbx, %rdi
leaq 0x35a0e(%rip), %rsi     # 0x5405c
callq 0x18b20
testl %eax, %eax
je 0x1e780
movq %rbx, %rdi
leaq 0x35a09(%rip), %rsi     # 0x5406e
callq 0x18b20
testl %eax, %eax
je 0x1e780
movq %rbx, %rdi
leaq 0x35a04(%rip), %rsi     # 0x54080
callq 0x18b20
testl %eax, %eax
je 0x1e766
movq %rbx, %rdi
leaq 0x359fd(%rip), %rsi     # 0x54090
callq 0x18b20
testl %eax, %eax
je 0x1e766
movq %rbx, %rdi
leaq 0x359f8(%rip), %rsi     # 0x540a2
callq 0x18b20
testl %eax, %eax
je 0x1e766
movq %rbx, %rdi
leaq 0x359f3(%rip), %rsi     # 0x540b4
callq 0x18b20
testl %eax, %eax
je 0x1e78d
movq %rbx, %rdi
leaq 0x359ea(%rip), %rsi     # 0x540c2
callq 0x18b20
testl %eax, %eax
je 0x1e78d
movq %rbx, %rdi
leaq 0x359e1(%rip), %rsi     # 0x540d0
callq 0x18b20
testl %eax, %eax
je 0x1e78d
movq %rbx, %rdi
leaq 0x359d6(%rip), %rsi     # 0x540dc
callq 0x18b20
testl %eax, %eax
je 0x1e78d
movq %rbx, %rdi
leaq 0x359d3(%rip), %rsi     # 0x540ec
callq 0x18b20
testl %eax, %eax
je 0x1e78d
movq %rbx, %rdi
leaq 0x359cf(%rip), %rsi     # 0x540fb
callq 0x18b20
testq %r14, %r14
jne 0x1e81d
testl %eax, %eax
je 0x1e81d
movq %r12, %rdi
movq %r13, %rsi
movss 0x357a0(%rip), %xmm0    # 0x53ef0
callq 0x19790
movq %rax, %r12
testq %rax, %rax
jne 0x1e44a
jmp 0x1e8f3
movss 0x3579a(%rip), %xmm0    # 0x53f08
jmp 0x1e830
movss 0x35785(%rip), %xmm0    # 0x53f00
jmp 0x1e830
movss 0x3577c(%rip), %xmm0    # 0x53f04
jmp 0x1e830
movss 0x35777(%rip), %xmm0    # 0x53f0c
jmp 0x1e830
movss 0x35772(%rip), %xmm0    # 0x53f14
movss %xmm0, 0x4(%rsp)
leaq 0x36f7c(%rip), %rbx     # 0x5572b
jmp 0x1e838
movss 0x35738(%rip), %xmm0    # 0x53ef4
movss %xmm0, 0x4(%rsp)
leaq 0x357a4(%rip), %rbx     # 0x53f6d
jmp 0x1e838
movss 0x35725(%rip), %xmm0    # 0x53ef8
jmp 0x1e830
testb $0x2, 0x140(%r12)
movq 0x130(%r12), %rbx
movl $0x1, %eax
movl 0x8(%rsp), %ecx
cmovnel %eax, %ecx
movl %ecx, 0x8(%rsp)
movss 0x35712(%rip), %xmm0    # 0x53f10
movss %xmm0, 0x4(%rsp)
jmp 0x1e838
movss 0x356ee(%rip), %xmm0    # 0x53efc
movss %xmm0, 0x4(%rsp)
leaq 0x35795(%rip), %rbx     # 0x53fb0
jmp 0x1e838
xorl %ecx, %ecx
testl %eax, %eax
sete %cl
leaq 0x35705(%rip), %rax     # 0x53f30
movss (%rax,%rcx,4), %xmm0
movss %xmm0, 0x4(%rsp)
xorl %ebx, %ebx
movss 0x4(%r15), %xmm0
subss 0x4(%r12), %xmm0
movss %xmm0, 0x1c(%rsp)
movss 0x8(%r15), %xmm0
subss 0x8(%r12), %xmm0
movss %xmm0, 0x20(%rsp)
movss 0xc(%r15), %xmm0
subss 0xc(%r12), %xmm0
movss %xmm0, 0x24(%rsp)
leaq 0x1c(%rsp), %rdi
callq 0x192e0
movss %xmm0, 0x44(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x18400
cmpl $0x0, 0xc(%rsp)
je 0x1e89b
testl %eax, %eax
je 0x1e42b
movss 0x35675(%rip), %xmm0    # 0x53f18
maxss 0x44(%rsp), %xmm0
movss 0x3566b(%rip), %xmm1    # 0x53f1c
divss %xmm0, %xmm1
movss 0x4(%rsp), %xmm2
mulss %xmm1, %xmm2
movss 0x34(%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, 0x34(%rsp)
jmp 0x1e42b
movq 0x38(%rsp), %r12
testq %r12, %r12
je 0x1e918
cmpl $0x0, 0x8(%rsp)
je 0x1e925
movq 0x10(%rsp), %rsi
testq %rsi, %rsi
je 0x1e987
movq 0x28(%rsp), %rdi
jmp 0x1ebe9
movq 0x28(%rsp), %rax
movb $0x0, (%rax)
jmp 0x1ebee
movss 0x4(%r12), %xmm0
subss 0x4(%r15), %xmm0
leaq 0x1c(%rsp), %rdi
movss %xmm0, (%rdi)
movss 0x8(%r12), %xmm0
subss 0x8(%r15), %xmm0
movss %xmm0, 0x4(%rdi)
movss 0xc(%r12), %xmm0
subss 0xc(%r15), %xmm0
movss %xmm0, 0x8(%rdi)
callq 0x192e0
movss 0x355b4(%rip), %xmm1    # 0x53f20
ucomiss %xmm0, %xmm1
jbe 0x1e9bb
movq 0x28(%rsp), %r14
movl $0x207461, (%r14)       # imm = 0x207461
movq 0x10(%rsp), %r15
jmp 0x1eaa0
movq 0x330(%r12), %rax
testq %rax, %rax
movq 0x28(%rsp), %rdi
je 0x1ea41
movq 0x50(%rax), %rsi
testq %rsi, %rsi
jne 0x1ebe9
movq (%rax), %rsi
testq %rsi, %rsi
jne 0x1ebe9
jmp 0x1ebee
movss 0x1c(%rsp), %xmm2
movss 0x20(%rsp), %xmm0
movaps 0x35572(%rip), %xmm1    # 0x53f40
movaps %xmm2, %xmm3
andps %xmm1, %xmm3
andps %xmm0, %xmm1
ucomiss %xmm1, %xmm3
movq 0x28(%rsp), %r14
jbe 0x1ea13
movss 0x24(%rsp), %xmm4
andps 0x35552(%rip), %xmm4    # 0x53f40
ucomiss %xmm4, %xmm3
jbe 0x1ea13
xorps %xmm0, %xmm0
ucomiss %xmm0, %xmm2
movq 0x10(%rsp), %r15
jbe 0x1ea8c
movabsq $0x666f206874726f6e, %rax # imm = 0x666F206874726F6E
jmp 0x1ea96
movss 0x24(%rsp), %xmm2
movaps 0x35520(%rip), %xmm3    # 0x53f40
andps %xmm2, %xmm3
ucomiss %xmm3, %xmm1
movq 0x10(%rsp), %r15
jbe 0x1ea4e
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x1ea67
movabsq $0x20666f2074736577, %rax # imm = 0x20666F2074736577
jmp 0x1ea71
movq 0x138(%r12), %rsi
jmp 0x1ebe9
xorps %xmm0, %xmm0
ucomiss %xmm0, %xmm2
jbe 0x1ea7b
movl $0x20776f, 0x3(%r14)    # imm = 0x20776F
movl $0x6f6c6562, (%r14)     # imm = 0x6F6C6562
jmp 0x1eaa0
movabsq $0x20666f2074736165, %rax # imm = 0x20666F2074736165
movq %rax, (%r14)
movb $0x0, 0x8(%r14)
jmp 0x1eaa0
movl $0x206576, 0x3(%r14)    # imm = 0x206576
movl $0x766f6261, (%r14)     # imm = 0x766F6261
jmp 0x1eaa0
movabsq $0x666f206874756f73, %rax # imm = 0x666F206874756F73
movq %rax, (%r14)
movw $0x20, 0x8(%r14)
testl %ebp, %ebp
jne 0x1eaba
movq %r14, %rdi
callq 0x18680
movl $0x20656874, (%r14,%rax) # imm = 0x20656874
movb $0x0, 0x4(%r14,%rax)
leaq 0x3548f(%rip), %rdx     # 0x53f50
xorl %edi, %edi
movl $0x138, %esi            # imm = 0x138
callq 0x19430
movss 0x4(%r12), %xmm0
subss 0x4(%rax), %xmm0
leaq 0x1c(%rsp), %rbx
movss %xmm0, (%rbx)
movss 0x8(%r12), %xmm0
subss 0x8(%rax), %xmm0
movss %xmm0, 0x4(%rbx)
movss 0xc(%r12), %xmm0
subss 0xc(%rax), %xmm0
movss %xmm0, 0x8(%rbx)
movq %rbx, %rdi
callq 0x192e0
movss %xmm0, 0xc(%rsp)
leaq 0x35445(%rip), %rdx     # 0x53f5e
xorl %edi, %edi
movl $0x138, %esi            # imm = 0x138
callq 0x19430
movss 0x4(%r12), %xmm0
subss 0x4(%rax), %xmm0
movss %xmm0, (%rbx)
movss 0x8(%r12), %xmm0
subss 0x8(%rax), %xmm0
movss %xmm0, 0x4(%rbx)
movss 0xc(%r12), %xmm0
subss 0xc(%rax), %xmm0
movss %xmm0, 0x8(%rbx)
movq %rbx, %rdi
callq 0x192e0
testl %ebp, %ebp
jne 0x1ebb1
movaps %xmm0, %xmm1
addss %xmm0, %xmm1
movss 0xc(%rsp), %xmm2
ucomiss %xmm1, %xmm2
jbe 0x1eb8f
movq %r14, %rdi
callq 0x18680
movl $0x65756c62, (%r14,%rax) # imm = 0x65756C62
movw $0x20, 0x4(%r14,%rax)
jmp 0x1ebb1
movaps %xmm2, %xmm1
addss %xmm2, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x1ebb1
movq %r14, %rdi
callq 0x18680
movl $0x20646572, (%r14,%rax) # imm = 0x20646572
movb $0x0, 0x4(%r14,%rax)
testq %r15, %r15
je 0x1ebbe
movq %r14, %rdi
movq %r15, %rsi
jmp 0x1ebe9
movq 0x330(%r12), %rax
testq %rax, %rax
je 0x1ebde
movq 0x50(%rax), %rsi
testq %rsi, %rsi
jne 0x1ebe6
movq (%rax), %rsi
testq %rsi, %rsi
jne 0x1ebe6
jmp 0x1ebee
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