// File: /workspace/github_c_makefile_star2_O3/QwazyWabbitWOS[P]lmctf60/g_ctffunc.c
// Function: ctf_spawnflag
qboolean ctf_spawnflag(int teamnum)
{
	edict_t		*ent = NULL; // MJD Uninitialized
	edict_t         *spot;

	if (!deathmatch->value)
		return false;

	if ((int)ctfflags->value & CTF_FLAGS_NOFLAGS)
		return false;

	// Check if the flags already exist

	if (teamnum == CTF_TEAM_RED  && !redflag) // RED FLAG
	{	
		spot = G_Find (NULL, FOFS(classname), "info_flag_red");
		if (!spot)
		{
			spot = G_Find (NULL, FOFS(classname), "info_player_deathmatch");
			if (spot)
				spot = ctf_findflagposition(spot);

			if (!spot)
				spot = G_Find (NULL, FOFS(classname), "info_player_start");


			// Make the spawn point glow
			if (spot)
			{
				spot->classname = "info_flag_red";
				spot->s.effects |= EF_COLOR_SHELL;
				spot->s.renderfx |= RF_SHELL_RED;
			}
			else // No spawn location found -- we will fail
				return false;
		}
		
		ent = G_Spawn();
		ent->classname = ED_NewString ("flag");
		ED_CallSpawn(ent);
		
		// Model support for flags
		ent->model = "players/male/flag1.md2";
		// Model support for flags
		
		VectorCopy (spot->s.origin, ent->s.origin);
		VectorCopy (spot->s.origin, ent->homeposition);
		VectorCopy (spot->s.angles, ent->s.angles);
		VectorCopy (spot->s.angles, ent->homeangles);
		//ent->s.effects |= EF_COLOR_SHELL | EF_FLAG1;
		//ent->s.renderfx |= RF_SHELL_RED;
		ent->s.effects = EF_FLAG1;
		// Paril
		if (flag_init->value)
			ent->s.frame = 173;
		else
			ent->s.frame = 0;
		// Paril
		redflag = ent;
	}
	else if (teamnum == CTF_TEAM_BLUE && !blueflag) // BLUE FLAG
	{
		spot = G_Find (NULL, FOFS(classname), "info_flag_blue");
		if (!spot)
		{
			spot = G_Find (NULL, FOFS(classname), "info_player_deathmatch");
			if (spot)
			{
				spot = ctf_findflagposition(spot);
				spot = ctf_findflagposition(spot);
			}

			if (!spot)
				spot = G_Find (NULL, FOFS(classname), "target_changelevel");

			// Make the spawn point glow
			if (spot)
			{
				spot->classname = "info_flag_blue";
				spot->s.effects |= EF_COLOR_SHELL;
				spot->s.renderfx |= RF_SHELL_BLUE;
			}
			else // No spawn location found -- we will fail
				return false;
		}

		ent = G_Spawn();
		ent->classname = ED_NewString ("flag");
		ED_CallSpawn(ent);
		// Model support for flags
		ent->model = "players/male/flag2.md2";
		// Model support for flags

		
		VectorCopy (spot->s.origin, ent->s.origin);
		VectorCopy (spot->s.origin, ent->homeposition);
		VectorCopy (spot->s.angles, ent->s.angles);
		VectorCopy (spot->s.angles, ent->homeangles);
		//ent->s.effects |= EF_COLOR_SHELL | EF_FLAG2;
		//ent->s.renderfx |= RF_SHELL_BLUE;
		ent->s.effects = EF_FLAG2;
		// Paril
		if (flag_init->value)
			ent->s.frame = 173;
		else
			ent->s.frame = 0;
		// Paril
		blueflag = ent;
	}


	//ent->model = "players/male/test.md2";

	if (ent)
	{
		//common
		ent->flagteam = teamnum; // passed as parameter
		gi.setmodel (ent, ent->model);
		ent->takedamage = DAMAGE_NO; //no damage on flags
		ent->dontfree = 1;
		ctf_resetflagandplayer (ent, NULL);
		ent->solid = SOLID_TRIGGER;
		gi.linkentity(ent); //make it touchable
		ent->movetype = MOVETYPE_TOSS;
		ctf_ResetFlagProps(ent);
		ctf_deletespawnpointsnearflag(ent);
	}
	return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq 0x485b5(%rip), %rax     # 0x68ec0
movq (%rax), %rax
movss 0x20(%rax), %xmm0
xorl %r12d, %r12d
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x20924
jnp 0x20c34
movq 0x4822d(%rip), %rax     # 0x68b58
movq (%rax), %rax
cvttss2si 0x20(%rax), %eax
btl $0x8, %eax
jb 0x20c34
movl %edi, %ebx
cmpl $0x1, %edi
jne 0x20981
movq 0x47ead(%rip), %r13     # 0x687f8
cmpq $0x0, (%r13)
jne 0x20981
leaq 0x325f7(%rip), %r14     # 0x52f50
xorl %edi, %edi
movl $0x138, %esi            # imm = 0x138
movq %r14, %rdx
callq 0x19430
testq %rax, %rax
je 0x209d1
movq %rax, %r15
movl $0x40000, %ebp          # imm = 0x40000
leaq 0x32bef(%rip), %r12     # 0x5356b
jmp 0x20ac0
movl $0x1, %r12d
cmpl $0x2, %ebx
jne 0x20c34
movq 0x47ec9(%rip), %r13     # 0x68860
cmpq $0x0, (%r13)
jne 0x20c34
leaq 0x325b5(%rip), %r14     # 0x52f5e
xorl %edi, %edi
movl $0x138, %esi            # imm = 0x138
movq %r14, %rdx
callq 0x19430
testq %rax, %rax
je 0x20a32
movq %rax, %r15
movl $0x80000, %ebp          # imm = 0x80000
leaq 0x32bc9(%rip), %r12     # 0x53595
jmp 0x20ac0
leaq 0x32b6a(%rip), %rdx     # 0x53542
xorl %r12d, %r12d
xorl %edi, %edi
movl $0x138, %esi            # imm = 0x138
callq 0x19430
testq %rax, %rax
je 0x209f9
movq %rax, %rdi
callq 0x18b90
testq %rax, %rax
jne 0x20a15
leaq 0x32b59(%rip), %rdx     # 0x53559
xorl %edi, %edi
movl $0x138, %esi            # imm = 0x138
callq 0x19430
testq %rax, %rax
je 0x20c34
movq %rax, %r15
movq 0x47dd9(%rip), %r13     # 0x687f8
movl $0x40000, %ebp          # imm = 0x40000
leaq 0x32b40(%rip), %r12     # 0x5356b
movl $0x400, %eax            # imm = 0x400
jmp 0x20a99
leaq 0x32b09(%rip), %rdx     # 0x53542
xorl %r12d, %r12d
xorl %edi, %edi
movl $0x138, %esi            # imm = 0x138
callq 0x19430
testq %rax, %rax
je 0x20a62
movq %rax, %rdi
callq 0x18b90
movq %rax, %rdi
callq 0x18b90
testq %rax, %rax
jne 0x20a7e
leaq 0x32b19(%rip), %rdx     # 0x53582
xorl %edi, %edi
movl $0x138, %esi            # imm = 0x138
callq 0x19430
testq %rax, %rax
je 0x20c34
movq %rax, %r15
movq 0x47dd8(%rip), %r13     # 0x68860
movl $0x80000, %ebp          # imm = 0x80000
leaq 0x32b01(%rip), %r12     # 0x53595
movl $0x1000, %eax           # imm = 0x1000
movq %r14, 0x138(%r15)
movq 0x40(%r15), %xmm0
movd %eax, %xmm1
movdqa 0x329fe(%rip), %xmm2    # 0x534b0
punpckldq %xmm1, %xmm2    # xmm2 = xmm2[0],xmm1[0],xmm2[1],xmm1[1]
por %xmm0, %xmm2
movq %xmm2, 0x40(%r15)
callq 0x19700
movq %rax, %r14
leaq 0x3a46c(%rip), %rdi     # 0x5af3b
callq 0x18260
movq %rax, 0x138(%r14)
movq %r14, %rdi
callq 0x19310
movq %r12, 0x120(%r14)
movss 0x4(%r15), %xmm0
movss %xmm0, 0x4(%r14)
movss 0x8(%r15), %xmm0
movss %xmm0, 0x8(%r14)
movss 0xc(%r15), %xmm0
movss %xmm0, 0xc(%r14)
movss 0x4(%r15), %xmm0
movss %xmm0, 0x460(%r14)
movss 0x8(%r15), %xmm0
movss %xmm0, 0x464(%r14)
movss 0xc(%r15), %xmm0
movss %xmm0, 0x468(%r14)
movss 0x10(%r15), %xmm0
movss %xmm0, 0x10(%r14)
movss 0x14(%r15), %xmm0
movss %xmm0, 0x14(%r14)
movss 0x18(%r15), %xmm0
movss %xmm0, 0x18(%r14)
movss 0x10(%r15), %xmm0
movss %xmm0, 0x46c(%r14)
movss 0x14(%r15), %xmm0
movss %xmm0, 0x470(%r14)
movss 0x18(%r15), %xmm0
movss %xmm0, 0x474(%r14)
movl %ebp, 0x40(%r14)
movq 0x47c91(%rip), %rax     # 0x68828
movq (%rax), %rax
xorl %ecx, %ecx
xorps %xmm0, %xmm0
ucomiss 0x20(%rax), %xmm0
movl $0xad, %eax
cmovnel %eax, %ecx
cmovpl %eax, %ecx
movl %ecx, 0x38(%r14)
movq %r14, (%r13)
movl %ebx, 0x47c(%r14)
movq 0x47a3c(%rip), %rbx     # 0x68600
movq %r14, %rdi
movq %r12, %rsi
callq *0x58(%rbx)
movl $0x0, 0x27c(%r14)
movl $0x1, %r12d
movl %r12d, 0x49c(%r14)
movups 0x460(%r14), %xmm0
movups %xmm0, 0x4(%r14)
movsd 0x470(%r14), %xmm0
movsd %xmm0, 0x14(%r14)
movq %r14, %rdi
callq 0x18580
movl %r12d, 0x108(%r14)
movq %r14, %rdi
callq *0x90(%rbx)
movl $0x7, 0x118(%r14)
movq %r14, %rdi
callq 0x18580
movq %r14, %rdi
callq 0x19070
movl %r12d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq