// File: /workspace/github_c_makefile_star2_O2/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
xorps %xmm0, %xmm0
movss %xmm0, 0xc(%rsp)
xorl %r13d, %r13d
leaq 0x2fe14(%rip), %r14     # 0x4f542
leaq 0x10(%rsp), %r15
xorl %r12d, %r12d
movq %r12, %rdi
movl $0x138, %esi            # imm = 0x138
movq %r14, %rdx
callq 0x195e0
testq %rax, %rax
je 0x1f791
movq %rax, %r12
movsd 0x4(%rbx), %xmm0
movsd 0x4(%rax), %xmm1
subps %xmm1, %xmm0
movlps %xmm0, 0x10(%rsp)
movss 0xc(%rbx), %xmm0
subss 0xc(%rax), %xmm0
movss %xmm0, 0x18(%rsp)
movq %r15, %rdi
callq 0x19460
movss 0xc(%rsp), %xmm1
ucomiss %xmm1, %xmm0
cmovaq %r12, %r13
maxss %xmm1, %xmm0
movss %xmm0, 0xc(%rsp)
jmp 0x1f736
leaq 0x2f7b8(%rip), %rdx     # 0x4ef50
xorl %edi, %edi
movl $0x138, %esi            # imm = 0x138
callq 0x195e0
movq %rax, %r14
testq %rax, %rax
je 0x1f7e7
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 0x19460
ucomiss 0xc(%rsp), %xmm0
jbe 0x1f7e7
movq %r14, %r13
movss %xmm0, 0xc(%rsp)
leaq 0x2f770(%rip), %rdx     # 0x4ef5e
movq %r14, %rdi
movl $0x138, %esi            # imm = 0x138
callq 0x195e0
testq %rax, %rax
je 0x1f833
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 0x19460
ucomiss 0xc(%rsp), %xmm0
ja 0x1f851
movq %r13, %r14
testq %r13, %r13
jne 0x1f851
leaq 0x2fd00(%rip), %rdx     # 0x4f542
xorl %edi, %edi
movl $0x138, %esi            # imm = 0x138
callq 0x195e0
movq %rax, %r14
movq %r14, %rax
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq