// File: /workspace/github_c_makefile_star2_O3/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 0x488b4(%rip), %rax     # 0x68ec0
movq (%rax), %rax
movss 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x20622
jnp 0x20809
movq 0x4852f(%rip), %rax     # 0x68b58
movq (%rax), %rax
cvttss2si 0x20(%rax), %eax
btl $0x8, %eax
jb 0x20809
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq 0x481ab(%rip), %r12     # 0x687f8
movq (%r12), %rbx
testq %rbx, %rbx
je 0x20671
movq 0x138(%rbx), %rdi
leaq 0x3a8d7(%rip), %rsi     # 0x5af3b
callq 0x18b20
testl %eax, %eax
je 0x2080f
movl $0x1, %edi
callq 0x18b60
movq 0x48176(%rip), %rcx     # 0x687f8
movq %rax, (%rcx)
testq %rax, %rax
jne 0x20694
movl $0x1, %edi
callq 0x193d0
movq 0x481c5(%rip), %rax     # 0x68860
movq (%rax), %rbx
testq %rbx, %rbx
je 0x206be
movq 0x138(%rbx), %rdi
leaq 0x3a88a(%rip), %rsi     # 0x5af3b
callq 0x18b20
testl %eax, %eax
je 0x2082f
movl $0x2, %edi
callq 0x18b60
movq 0x48191(%rip), %rcx     # 0x68860
movq %rax, (%rcx)
testq %rax, %rax
jne 0x206e1
movl $0x2, %edi
callq 0x193d0
leaq 0x33ca7(%rip), %rdx     # 0x5438f
xorl %edi, %edi
movl $0x138, %esi            # imm = 0x138
callq 0x19430
testq %rax, %rax
je 0x207a8
movq %rax, %rbx
movq 0x48739(%rip), %rbp     # 0x68e40
movabsq $-0x3c3c3c3c3c3c3c3c, %r14 # imm = 0xC3C3C3C3C3C3C3C4
movl $0x1, %r13d
movq %r12, %rax
cmpl $0x1, %r13d
je 0x2072d
cmpl $0x2, %r13d
jne 0x2077f
movq 0x48133(%rip), %rax     # 0x68860
movq (%rax), %r15
movq 0x58(%rbx), %rax
testq %rax, %rax
setne %cl
testq %r15, %r15
setne %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x2077f
movq 0x330(%r15), %rcx
subq %rbp, %rcx
sarq $0x3, %rcx
imulq %r14, %rcx
cmpl $0x0, 0x318(%rax,%rcx)
je 0x2077f
movq %rbx, %rdi
movl $0xfffffffb, %esi       # imm = 0xFFFFFFFB
callq 0x18ce0
testl %eax, %eax
jne 0x2077f
movq %r15, %rdi
movq %rbx, %rsi
callq 0x19080
incl %r13d
cmpl $0x3, %r13d
jne 0x20717
movq %rbx, %rdi
movl $0x138, %esi            # imm = 0x138
leaq 0x33bf8(%rip), %rdx     # 0x5438f
callq 0x19430
movq %rax, %rbx
testq %rax, %rax
jne 0x20711
movq 0x48049(%rip), %rax     # 0x687f8
movq (%rax), %rax
movq 0x47e47(%rip), %rbx     # 0x68600
leaq 0x8(%rbx), %r14
addq $0x90, %rbx
testq %rax, %rax
leaq 0x32d17(%rip), %rdi     # 0x534e5
cmovneq %rax, %rdi
movq %rbx, %rcx
cmoveq %r14, %rcx
xorl %eax, %eax
callq *(%rcx)
movq 0x4807c(%rip), %rax     # 0x68860
movq (%rax), %rax
testq %rax, %rax
leaq 0x32d22(%rip), %rdi     # 0x53513
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 0x20671
cmpl $0x1, 0x47c(%rbx)
jne 0x20671
jmp 0x20694
cmpq $0x0, 0x330(%rbx)
je 0x206be
cmpl $0x2, 0x47c(%rbx)
jne 0x206be
jmp 0x206e1