// File: /workspace/github_c_makefile_star2_O1/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 0x494bd(%rip), %rax     # 0x69ec0
movq (%rax), %rax
movss 0x20(%rax), %xmm0
xorl %ebp, %ebp
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x20a1b
jnp 0x20d26
movq 0x49136(%rip), %rax     # 0x69b58
movq (%rax), %rax
cvttss2si 0x20(%rax), %eax
btl $0x8, %eax
jb 0x20d26
movl %edi, %ebx
cmpl $0x1, %edi
jne 0x20a78
movq 0x48db6(%rip), %r12     # 0x697f8
cmpq $0x0, (%r12)
jne 0x20a78
leaq 0x33500(%rip), %r15     # 0x53f50
xorl %edi, %edi
movl $0x138, %esi            # imm = 0x138
movq %r15, %rdx
callq 0x19430
testq %rax, %rax
je 0x20ac5
movq %rax, %r14
movl $0x40000, %ebp          # imm = 0x40000
leaq 0x33ac8(%rip), %r13     # 0x5453b
jmp 0x20ba3
xorl %r15d, %r15d
cmpl $0x2, %ebx
jne 0x20c99
movq 0x48dd5(%rip), %r12     # 0x69860
cmpq $0x0, (%r12)
jne 0x20c99
leaq 0x334c1(%rip), %r15     # 0x53f5e
xorl %edi, %edi
movl $0x138, %esi            # imm = 0x138
movq %r15, %rdx
callq 0x19430
testq %rax, %rax
je 0x20b29
movq %rax, %r14
movl $0x80000, %ebp          # imm = 0x80000
leaq 0x33aa5(%rip), %r13     # 0x54565
jmp 0x20ba3
leaq 0x33a46(%rip), %rdx     # 0x54512
xorl %r14d, %r14d
xorl %edi, %edi
movl $0x138, %esi            # imm = 0x138
callq 0x19430
testq %rax, %rax
je 0x20aeb
movq %rax, %rdi
callq 0x18b90
movq %rax, %r14
testq %r14, %r14
jne 0x20b06
leaq 0x33a32(%rip), %rdx     # 0x54529
xorl %edi, %edi
movl $0x138, %esi            # imm = 0x138
callq 0x19430
movq %rax, %r14
testq %r14, %r14
je 0x20d24
movq 0x48ce2(%rip), %r12     # 0x697f8
movl $0x40000, %ebp          # imm = 0x40000
leaq 0x33a19(%rip), %r13     # 0x5453b
movl $0x400, %eax            # imm = 0x400
jmp 0x20b93
leaq 0x339e2(%rip), %rdx     # 0x54512
xorl %r14d, %r14d
xorl %edi, %edi
movl $0x138, %esi            # imm = 0x138
callq 0x19430
testq %rax, %rax
je 0x20b57
movq %rax, %rdi
callq 0x18b90
movq %rax, %rdi
callq 0x18b90
movq %rax, %r14
testq %r14, %r14
jne 0x20b72
leaq 0x339ef(%rip), %rdx     # 0x54552
xorl %edi, %edi
movl $0x138, %esi            # imm = 0x138
callq 0x19430
movq %rax, %r14
testq %r14, %r14
je 0x20d24
movq 0x48cde(%rip), %r12     # 0x69860
movl $0x80000, %ebp          # imm = 0x80000
leaq 0x339d7(%rip), %r13     # 0x54565
movl $0x1000, %eax           # imm = 0x1000
movq %r15, 0x138(%r14)
orb $0x1, 0x41(%r14)
orl %eax, 0x44(%r14)
callq 0x19710
movq %rax, %r15
leaq 0x3b039(%rip), %rdi     # 0x5bbeb
callq 0x18260
movq %rax, 0x138(%r15)
movq %r15, %rdi
callq 0x19310
movq %r13, 0x120(%r15)
movss 0x4(%r14), %xmm0
movss %xmm0, 0x4(%r15)
movss 0x8(%r14), %xmm0
movss %xmm0, 0x8(%r15)
movss 0xc(%r14), %xmm0
movss %xmm0, 0xc(%r15)
movss 0x4(%r14), %xmm0
movss %xmm0, 0x460(%r15)
movss 0x8(%r14), %xmm0
movss %xmm0, 0x464(%r15)
movss 0xc(%r14), %xmm0
movss %xmm0, 0x468(%r15)
movss 0x10(%r14), %xmm0
movss %xmm0, 0x10(%r15)
movss 0x14(%r14), %xmm0
movss %xmm0, 0x14(%r15)
movss 0x18(%r14), %xmm0
movss %xmm0, 0x18(%r15)
movss 0x10(%r14), %xmm0
movss %xmm0, 0x46c(%r15)
movss 0x14(%r14), %xmm0
movss %xmm0, 0x470(%r15)
movss 0x18(%r14), %xmm0
movss %xmm0, 0x474(%r15)
movl %ebp, 0x40(%r15)
movq 0x48bae(%rip), %rax     # 0x69828
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(%r15)
movq %r15, (%r12)
testq %r15, %r15
je 0x20d1d
movl %ebx, 0x47c(%r15)
movq 0x48954(%rip), %rbx     # 0x69600
movq 0x120(%r15), %rsi
movq %r15, %rdi
callq *0x58(%rbx)
movl $0x0, 0x27c(%r15)
movl $0x1, %ebp
movl %ebp, 0x49c(%r15)
movq 0x460(%r15), %rax
movq %rax, 0x4(%r15)
movups 0x468(%r15), %xmm0
movups %xmm0, 0xc(%r15)
movq %r15, %rdi
callq 0x18580
movl %ebp, 0x108(%r15)
movq %r15, %rdi
callq *0x90(%rbx)
movl $0x7, 0x118(%r15)
movq %r15, %rdi
callq 0x18580
movq %r15, %rdi
callq 0x19070
jmp 0x20d26
movl $0x1, %ebp
jmp 0x20d26
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq