// File: /workspace/github_c_makefile_star2_O3/QwazyWabbitWOS[P]lmctf60/g_ctffunc.c
// Function: ctf_findflagposition
edict_t * ctf_findflagposition(edict_t *whichflag)
{
	edict_t	*bestspot;
	float	bestdistance, flagdistance;
	edict_t	*spot;
	vec3_t v;


	spot = NULL;
	bestspot = NULL;
	bestdistance = 0;
	while ((spot = G_Find (spot, FOFS(classname), "info_player_deathmatch")) != NULL)
	{
		
		VectorSubtract (whichflag->s.origin, spot->s.origin, v);
		flagdistance = VectorLength(v);

		if (flagdistance > bestdistance)
		{
			bestspot = spot;
			bestdistance = flagdistance;
		}
	}

        // MJD This should have parentheses, given that you DO want to do
	// an asignment and not a ==
	spot = G_Find (spot, FOFS(classname), "info_flag_red");
	if (spot)
	{
		
		VectorSubtract (whichflag->s.origin, spot->s.origin, v);
		flagdistance = VectorLength(v);

		if (flagdistance > bestdistance)
		{
			bestspot = spot;
			bestdistance = flagdistance;
		}
	}

        // MJD This should have parentheses, given that you DO want to do
	// an asignment and not a ==
	spot = G_Find (spot, FOFS(classname), "info_flag_blue");
	if (spot)
	{
		
		VectorSubtract (whichflag->s.origin, spot->s.origin, v);
		flagdistance = VectorLength(v);

		if (flagdistance > bestdistance)
		{
			bestspot = spot;
			bestdistance = flagdistance;
		}
	}

	if (bestspot)
	{
		return bestspot;
	}

	// if there is a player just spawned on each and every start spot
	// we have no choice to turn one into a telefrag meltdown
	spot = G_Find (NULL, FOFS(classname), "info_player_deathmatch");

	return spot;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x20, %rsp
movq %rdi, %rbx
leaq 0x32528(%rip), %rdx     # 0x53542
xorl %r13d, %r13d
xorl %edi, %edi
movl $0x138, %esi            # imm = 0x138
callq 0x19430
testq %rax, %rax
je 0x210b3
movq %rax, %r14
xorps %xmm1, %xmm1
xorl %r13d, %r13d
leaq 0x10(%rsp), %r15
leaq 0x324fb(%rip), %r12     # 0x53542
movss %xmm1, 0xc(%rsp)
movsd 0x4(%rbx), %xmm0
movsd 0x4(%r14), %xmm1
subps %xmm1, %xmm0
movlps %xmm0, 0x10(%rsp)
movss 0xc(%rbx), %xmm0
subss 0xc(%r14), %xmm0
movss %xmm0, 0x18(%rsp)
movq %r15, %rdi
callq 0x192e0
movss 0xc(%rsp), %xmm1
ucomiss %xmm1, %xmm0
cmovaq %r14, %r13
maxss %xmm1, %xmm0
movss %xmm0, 0xc(%rsp)
movq %r14, %rdi
movl $0x138, %esi            # imm = 0x138
movq %r12, %rdx
callq 0x19430
movss 0xc(%rsp), %xmm0
movq %rax, %r14
movaps %xmm0, %xmm1
testq %rax, %rax
jne 0x21047
jmp 0x210b6
xorps %xmm0, %xmm0
movss %xmm0, 0xc(%rsp)
leaq 0x31e8d(%rip), %rdx     # 0x52f50
xorl %edi, %edi
movl $0x138, %esi            # imm = 0x138
callq 0x19430
movq %rax, %r14
testq %rax, %rax
je 0x21112
movsd 0x4(%rbx), %xmm0
movsd 0x4(%r14), %xmm1
subps %xmm1, %xmm0
leaq 0x10(%rsp), %rdi
movlps %xmm0, (%rdi)
movss 0xc(%rbx), %xmm0
subss 0xc(%r14), %xmm0
movss %xmm0, 0x8(%rdi)
callq 0x192e0
ucomiss 0xc(%rsp), %xmm0
jbe 0x21112
movq %r14, %r13
movss %xmm0, 0xc(%rsp)
leaq 0x31e45(%rip), %rdx     # 0x52f5e
movq %r14, %rdi
movl $0x138, %esi            # imm = 0x138
callq 0x19430
testq %rax, %rax
je 0x2115e
movq %rax, %r14
movsd 0x4(%rbx), %xmm0
movsd 0x4(%rax), %xmm1
subps %xmm1, %xmm0
leaq 0x10(%rsp), %rdi
movlps %xmm0, (%rdi)
movss 0xc(%rbx), %xmm0
subss 0xc(%rax), %xmm0
movss %xmm0, 0x8(%rdi)
callq 0x192e0
ucomiss 0xc(%rsp), %xmm0
ja 0x2117c
movq %r13, %r14
testq %r13, %r13
jne 0x2117c
leaq 0x323d5(%rip), %rdx     # 0x53542
xorl %edi, %edi
movl $0x138, %esi            # imm = 0x138
callq 0x19430
movq %rax, %r14
movq %r14, %rax
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq