// File: /workspace/github_c_makefile_star2_O1/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 $0x10, %rsp
movq %rdi, %r14
leaq 0x33400(%rip), %rdx     # 0x54512
xorl %ebx, %ebx
xorl %edi, %edi
movl $0x138, %esi            # imm = 0x138
callq 0x19430
testq %rax, %rax
je 0x211b7
movq %rax, %r15
xorps %xmm1, %xmm1
xorl %ebx, %ebx
leaq 0x4(%rsp), %r12
leaq 0x333d5(%rip), %r13     # 0x54512
movss %xmm1, (%rsp)
movss 0x4(%r14), %xmm0
subss 0x4(%r15), %xmm0
movss %xmm0, 0x4(%rsp)
movss 0x8(%r14), %xmm0
subss 0x8(%r15), %xmm0
movss %xmm0, 0x8(%rsp)
movss 0xc(%r14), %xmm0
subss 0xc(%r15), %xmm0
movss %xmm0, 0xc(%rsp)
movq %r12, %rdi
callq 0x192e0
movss (%rsp), %xmm1
ucomiss %xmm1, %xmm0
cmovaq %r15, %rbx
maxss %xmm1, %xmm0
movss %xmm0, (%rsp)
movq %r15, %rdi
movl $0x138, %esi            # imm = 0x138
movq %r13, %rdx
callq 0x19430
movss (%rsp), %xmm0
movq %rax, %r15
movaps %xmm0, %xmm1
testq %rax, %rax
jne 0x2113d
jmp 0x211ba
xorps %xmm0, %xmm0
movss %xmm0, (%rsp)
leaq 0x32d8a(%rip), %rdx     # 0x53f50
xorl %edi, %edi
movl $0x138, %esi            # imm = 0x138
callq 0x19430
movq %rax, %r15
testq %rax, %rax
je 0x21224
movss 0x4(%r14), %xmm0
subss 0x4(%r15), %xmm0
leaq 0x4(%rsp), %rdi
movss %xmm0, (%rdi)
movss 0x8(%r14), %xmm0
subss 0x8(%r15), %xmm0
movss %xmm0, 0x4(%rdi)
movss 0xc(%r14), %xmm0
subss 0xc(%r15), %xmm0
movss %xmm0, 0x8(%rdi)
callq 0x192e0
ucomiss (%rsp), %xmm0
jbe 0x21224
movq %r15, %rbx
movss %xmm0, (%rsp)
leaq 0x32d33(%rip), %rdx     # 0x53f5e
movq %r15, %rdi
movl $0x138, %esi            # imm = 0x138
callq 0x19430
testq %rax, %rax
je 0x21282
movq %rax, %r15
movss 0x4(%r14), %xmm0
subss 0x4(%rax), %xmm0
leaq 0x4(%rsp), %rdi
movss %xmm0, (%rdi)
movss 0x8(%r14), %xmm0
subss 0x8(%rax), %xmm0
movss %xmm0, 0x4(%rdi)
movss 0xc(%r14), %xmm0
subss 0xc(%rax), %xmm0
movss %xmm0, 0x8(%rdi)
callq 0x192e0
ucomiss (%rsp), %xmm0
jbe 0x21282
movq %r15, %rbx
testq %rbx, %rbx
jne 0x2129d
leaq 0x33284(%rip), %rdx     # 0x54512
xorl %edi, %edi
movl $0x138, %esi            # imm = 0x138
callq 0x19430
movq %rax, %rbx
movq %rbx, %rax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq