// File: /workspace/github_c_makefile_star2_O2/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 0x4815c(%rip), %rax     # 0x66ec0
movq (%rax), %rax
movss 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x1ed7a
jnp 0x1ef58
movq 0x47dd7(%rip), %rax     # 0x66b58
movq (%rax), %rax
cvttss2si 0x20(%rax), %eax
btl $0x8, %eax
jb 0x1ef58
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq 0x47a53(%rip), %rax     # 0x667f8
movq (%rax), %rbx
testq %rbx, %rbx
je 0x1edc8
movq 0x138(%rbx), %rdi
leaq 0x38140(%rip), %rsi     # 0x56efb
callq 0x18bc0
testl %eax, %eax
je 0x1ef5c
pushq $0x1
popq %rdi
callq 0x18c10
movq 0x47a21(%rip), %rcx     # 0x667f8
movq %rax, (%rcx)
testq %rax, %rax
jne 0x1ede7
pushq $0x1
popq %rdi
callq 0x19570
movq 0x47a72(%rip), %rax     # 0x66860
movq (%rax), %rbx
testq %rbx, %rbx
je 0x1ee11
movq 0x138(%rbx), %rdi
leaq 0x380f7(%rip), %rsi     # 0x56efb
callq 0x18bc0
testl %eax, %eax
je 0x1ef7c
pushq $0x2
popq %rdi
callq 0x18c10
movq 0x47a40(%rip), %rcx     # 0x66860
movq %rax, (%rcx)
testq %rax, %rax
jne 0x1ee30
pushq $0x2
popq %rdi
callq 0x19570
leaq 0x31558(%rip), %rdx     # 0x5038f
xorl %edi, %edi
movl $0x138, %esi            # imm = 0x138
callq 0x195e0
movq %rax, %r14
movq 0x47ff3(%rip), %rbx     # 0x66e40
movl $0x88, %r12d
pushq $-0x5
popq %rbp
testq %r14, %r14
je 0x1eef7
pushq $0x1
popq %r13
cmpl $0x1, %r13d
je 0x1ee83
cmpl $0x2, %r13d
je 0x1ee7a
cmpl $0x3, %r13d
je 0x1eedb
xorl %r15d, %r15d
jmp 0x1ee8d
movq 0x479df(%rip), %rax     # 0x66860
jmp 0x1ee8a
movq 0x4796e(%rip), %rax     # 0x667f8
movq (%rax), %r15
movq 0x58(%r14), %rcx
testq %rcx, %rcx
setne %al
testq %r15, %r15
setne %dl
andb %al, %dl
cmpb $0x1, %dl
jne 0x1eed6
movq 0x330(%r15), %rax
subq %rbx, %rax
cqto
idivq %r12
cmpl $0x0, 0x318(%rcx,%rax,4)
je 0x1eed6
movq %r14, %rdi
movl %ebp, %esi
callq 0x18de0
testl %eax, %eax
jne 0x1eed6
movq %r15, %rdi
movq %r14, %rsi
callq 0x191d0
incl %r13d
jmp 0x1ee63
movq %r14, %rdi
movl $0x138, %esi            # imm = 0x138
leaq 0x314a5(%rip), %rdx     # 0x5038f
callq 0x195e0
movq %rax, %r14
jmp 0x1ee56
movq 0x478fa(%rip), %rax     # 0x667f8
movq (%rax), %rax
movq 0x476f8(%rip), %rbx     # 0x66600
leaq 0x8(%rbx), %r14
addq $0x90, %rbx
testq %rax, %rax
leaq 0x305c8(%rip), %rdi     # 0x4f4e5
cmovneq %rax, %rdi
movq %rbx, %rcx
cmoveq %r14, %rcx
xorl %eax, %eax
callq *(%rcx)
movq 0x4792d(%rip), %rax     # 0x66860
movq (%rax), %rax
testq %rax, %rax
leaq 0x305d3(%rip), %rdi     # 0x4f513
cmovneq %rax, %rdi
cmoveq %r14, %rbx
callq *(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
pushq $0x1
popq %rax
retq
cmpq $0x0, 0x330(%rbx)
je 0x1edc8
cmpl $0x1, 0x47c(%rbx)
jne 0x1edc8
jmp 0x1ede7
cmpq $0x0, 0x330(%rbx)
je 0x1ee11
cmpl $0x2, 0x47c(%rbx)
jne 0x1ee11
jmp 0x1ee30