// File: /workspace/github_c_makefile_star2_O1/QwazyWabbitWOS[P]lmctf60/g_ctffunc.c
// Function: ctf_validateflags
qboolean ctf_validateflags()
{
	edict_t * tmp_player = NULL;
	int teamcount= CTF_TEAM_UNDEFINED+1;
	edict_t * tmp_flag = NULL;

	if (!deathmatch->value || (int)ctfflags->value & CTF_FLAGS_NOFLAGS)
		return true;
	
	if (
		  (!redflag) ||
	     (strcmp(redflag->classname, "flag") != 0) ||
		  (!redflag->item) ||
		  (redflag->flagteam != CTF_TEAM_RED)
		)
	{
		//something is wrong with redflag
		redflag = ctf_flagsearch(CTF_TEAM_RED);
		if (!redflag) //if above returned null, we need to create a new flag
			ctf_spawnflag(CTF_TEAM_RED);
	}
		
	if (
		  (!blueflag) ||
	     (strcmp(blueflag->classname, "flag") != 0) ||
		  (!blueflag->item) ||
		  (blueflag->flagteam != CTF_TEAM_BLUE)
		)
	{
		//something is wrong with redflag
		blueflag = ctf_flagsearch(CTF_TEAM_BLUE);
		if (!blueflag) //if above returned null, we need to create a new flag
			ctf_spawnflag(CTF_TEAM_BLUE);
	}

	tmp_player = G_Find (tmp_player, FOFS(classname), "player");
	while (tmp_player)
	{
		teamcount = CTF_TEAM_UNDEFINED+1;
		while (teamcount < CTF_TEAM_LIMIT)
		{
			tmp_flag = ctf_getteamflag(teamcount,CTF_TEAM_MATCHING);
			if (tmp_player->client && tmp_flag && tmp_player->client->pers.inventory[ITEM_INDEX(tmp_flag->item)] != 0) //player has flag
			{
				if (!ctf_validateplayer(tmp_player,CTF_TEAM_ANYTEAM)) //must be a valid player on valid team to hold a flag
				{
					ctf_resetflagandplayer(tmp_flag, tmp_player);				
				}
			}
			teamcount++;
		}
		tmp_player = G_Find (tmp_player, FOFS(classname), "player");
	}

	if (redflag)
		gi.linkentity(redflag); 
	else
		gi.dprintf("Error, red flag missing, please report this.\n");
	if (blueflag)
		gi.linkentity(blueflag); 
	else
		gi.dprintf("Error, blue flag missing, please report this.\n");
	

	return true;

}

// Assembly:
movq 0x497b8(%rip), %rax     # 0x69ec0
movq (%rax), %rax
movss 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x2071e
jnp 0x20901
movq 0x49433(%rip), %rax     # 0x69b58
movq (%rax), %rax
cvttss2si 0x20(%rax), %eax
btl $0x8, %eax
jb 0x20901
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq 0x490af(%rip), %rax     # 0x697f8
movq (%rax), %rbx
testq %rbx, %rbx
je 0x2076c
movq 0x138(%rbx), %rdi
leaq 0x3b48c(%rip), %rsi     # 0x5bbeb
callq 0x18b20
testl %eax, %eax
je 0x20907
movl $0x1, %edi
callq 0x18b60
movq 0x4907b(%rip), %rcx     # 0x697f8
movq %rax, (%rcx)
testq %rax, %rax
jne 0x2078f
movl $0x1, %edi
callq 0x193d0
movq 0x490ca(%rip), %r13     # 0x69860
movq (%r13), %rbx
testq %rbx, %rbx
je 0x207ba
movq 0x138(%rbx), %rdi
leaq 0x3b43e(%rip), %rsi     # 0x5bbeb
callq 0x18b20
testl %eax, %eax
je 0x20927
movl $0x2, %edi
callq 0x18b60
movq %rax, (%r13)
testq %rax, %rax
jne 0x207d7
movl $0x2, %edi
callq 0x193d0
leaq 0x34bb5(%rip), %rdx     # 0x55393
xorl %edi, %edi
movl $0x138, %esi            # imm = 0x138
callq 0x19430
testq %rax, %rax
je 0x208a6
movq %rax, %rbx
movq 0x49643(%rip), %rbp     # 0x69e40
movabsq $-0x3c3c3c3c3c3c3c3c, %r14 # imm = 0xC3C3C3C3C3C3C3C4
movl $0x1, %r12d
cmpl $0x2, %r12d
je 0x20825
cmpl $0x1, %r12d
jne 0x2082b
movq 0x48fd8(%rip), %rax     # 0x697f8
movq (%rax), %r15
jmp 0x2082e
movq (%r13), %r15
jmp 0x2082e
xorl %r15d, %r15d
movq 0x58(%rbx), %rax
testq %rax, %rax
setne %cl
testq %r15, %r15
setne %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x2087d
movq 0x330(%r15), %rcx
subq %rbp, %rcx
sarq $0x3, %rcx
imulq %r14, %rcx
cmpl $0x0, 0x318(%rax,%rcx)
je 0x2087d
movq %rbx, %rdi
movl $0xfffffffb, %esi       # imm = 0xFFFFFFFB
callq 0x18ce0
testl %eax, %eax
jne 0x2087d
movq %r15, %rdi
movq %rbx, %rsi
callq 0x19080
incl %r12d
cmpl $0x3, %r12d
jne 0x2080d
movq %rbx, %rdi
movl $0x138, %esi            # imm = 0x138
leaq 0x34afe(%rip), %rdx     # 0x55393
callq 0x19430
movq %rax, %rbx
testq %rax, %rax
jne 0x20807
movq 0x48f4b(%rip), %rax     # 0x697f8
movq (%rax), %rax
movq 0x48d49(%rip), %rbx     # 0x69600
leaq 0x8(%rbx), %r14
addq $0x90, %rbx
testq %rax, %rax
leaq 0x33be9(%rip), %rdi     # 0x544b5
cmovneq %rax, %rdi
movq %rbx, %rcx
cmoveq %r14, %rcx
xorl %eax, %eax
callq *(%rcx)
movq (%r13), %rax
testq %rax, %rax
leaq 0x33bfa(%rip), %rdi     # 0x544e3
cmovneq %rax, %rdi
cmoveq %r14, %rbx
callq *(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
movl $0x1, %eax
retq
cmpq $0x0, 0x330(%rbx)
je 0x2076c
cmpl $0x1, 0x47c(%rbx)
jne 0x2076c
jmp 0x2078f
cmpq $0x0, 0x330(%rbx)
je 0x207ba
cmpl $0x2, 0x47c(%rbx)
jne 0x207ba
jmp 0x207d7