// File: /workspace/github_c_makefile_star2_O0/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:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq $0x0, -0x10(%rbp)
movl $0x1, -0x14(%rbp)
movq $0x0, -0x20(%rbp)
movq 0x6108a(%rip), %rax     # 0x82ec0
movq (%rax), %rax
movss 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x21e4a
jp 0x21e4a
jmp 0x21e63
movq 0x60d07(%rip), %rax     # 0x82b58
movq (%rax), %rax
cvttss2si 0x20(%rax), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x0, %eax
je 0x21e6f
movl $0x1, -0x4(%rbp)
jmp 0x220e6
movq 0x60982(%rip), %rax     # 0x827f8
cmpq $0x0, (%rax)
je 0x21ec5
movq 0x60975(%rip), %rax     # 0x827f8
movq (%rax), %rax
movq 0x138(%rax), %rdi
leaq 0x55c87(%rip), %rsi     # 0x77b1b
callq 0x18bf0
cmpl $0x0, %eax
jne 0x21ec5
movq 0x60953(%rip), %rax     # 0x827f8
movq (%rax), %rax
cmpq $0x0, 0x330(%rax)
je 0x21ec5
movq 0x6093f(%rip), %rax     # 0x827f8
movq (%rax), %rax
cmpl $0x1, 0x47c(%rax)
je 0x21ef5
movl $0x1, %edi
callq 0x18c50
movq %rax, %rcx
movq 0x6091f(%rip), %rax     # 0x827f8
movq %rcx, (%rax)
movq 0x60915(%rip), %rax     # 0x827f8
cmpq $0x0, (%rax)
jne 0x21ef3
movl $0x1, %edi
callq 0x195f0
jmp 0x21ef5
movq 0x60964(%rip), %rax     # 0x82860
cmpq $0x0, (%rax)
je 0x21f4b
movq 0x60957(%rip), %rax     # 0x82860
movq (%rax), %rax
movq 0x138(%rax), %rdi
leaq 0x55c01(%rip), %rsi     # 0x77b1b
callq 0x18bf0
cmpl $0x0, %eax
jne 0x21f4b
movq 0x60935(%rip), %rax     # 0x82860
movq (%rax), %rax
cmpq $0x0, 0x330(%rax)
je 0x21f4b
movq 0x60921(%rip), %rax     # 0x82860
movq (%rax), %rax
cmpl $0x2, 0x47c(%rax)
je 0x21f7b
movl $0x2, %edi
callq 0x18c50
movq %rax, %rcx
movq 0x60901(%rip), %rax     # 0x82860
movq %rcx, (%rax)
movq 0x608f7(%rip), %rax     # 0x82860
cmpq $0x0, (%rax)
jne 0x21f79
movl $0x2, %edi
callq 0x195f0
jmp 0x21f7b
movq -0x10(%rbp), %rdi
xorl %eax, %eax
addq $0x138, %rax            # imm = 0x138
movl %eax, %esi
leaq 0x4f407(%rip), %rdx     # 0x71397
callq 0x19660
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x22067
movl $0x1, -0x14(%rbp)
cmpl $0x3, -0x14(%rbp)
jge 0x22044
movl -0x14(%rbp), %edi
movl $0xfffffff9, %esi       # imm = 0xFFFFFFF9
callq 0x18ef0
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x58(%rax)
je 0x22036
cmpq $0x0, -0x20(%rbp)
je 0x22036
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq 0x330(%rax), %rax
movq 0x60e4a(%rip), %rcx     # 0x82e40
subq %rcx, %rax
movl $0x88, %ecx
cqto
idivq %rcx
movq %rax, %rcx
movq -0x28(%rbp), %rax
cmpl $0x0, 0x318(%rax,%rcx,4)
je 0x22036
movq -0x10(%rbp), %rdi
movl $0xfffffffb, %esi       # imm = 0xFFFFFFFB
callq 0x18e40
cmpl $0x0, %eax
jne 0x22034
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x19240
jmp 0x22036
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x21fab
movq -0x10(%rbp), %rdi
xorl %eax, %eax
addq $0x138, %rax            # imm = 0x138
movl %eax, %esi
leaq 0x4f33e(%rip), %rdx     # 0x71397
callq 0x19660
movq %rax, -0x10(%rbp)
jmp 0x21f99
movq 0x6078a(%rip), %rax     # 0x827f8
cmpq $0x0, (%rax)
je 0x22090
movq 0x60585(%rip), %rax     # 0x82600
movq 0x90(%rax), %rax
movq 0x6076f(%rip), %rcx     # 0x827f8
movq (%rcx), %rdi
callq *%rax
jmp 0x220a3
leaq 0x4e42e(%rip), %rdi     # 0x704c5
movq 0x60562(%rip), %rcx     # 0x82600
movb $0x0, %al
callq *0x8(%rcx)
movq 0x607b6(%rip), %rax     # 0x82860
cmpq $0x0, (%rax)
je 0x220cc
movq 0x60549(%rip), %rax     # 0x82600
movq 0x90(%rax), %rax
movq 0x6079b(%rip), %rcx     # 0x82860
movq (%rcx), %rdi
callq *%rax
jmp 0x220df
leaq 0x4e420(%rip), %rdi     # 0x704f3
movq 0x60526(%rip), %rcx     # 0x82600
movb $0x0, %al
callq *0x8(%rcx)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nop