// File: /workspace/github_c_makefile_star2_O2/QwazyWabbitWOS[P]lmctf60/g_ctffunc.c
// Function: ctf_faceEnemyFlag
char *
ctf_faceEnemyFlag(edict_t *ent)
{
	int angle;
	edict_t *flag;
	vec3_t distvector, angles;

	if (ent->client->ctf.teamnum == CTF_TEAM_RED)
		flag = blueflag;
	else if (ent->client->ctf.teamnum == CTF_TEAM_BLUE)
		flag = redflag;
	else return "north";

	if (!flag) //surt no flags mode always points north.
		return "north";

	if (flag->owner)
		flag = flag->owner;

	if (flag == ent)
	{
		if (ent->client->ctf.teamnum == CTF_TEAM_RED)
			return "blueflaggone";		
		else if (ent->client->ctf.teamnum == CTF_TEAM_BLUE)
			return "redflaggone";
	}

	VectorSubtract(flag->s.origin, ent->s.origin, distvector);

	/*
	if (abs(distvector[0]) > abs(distvector[1]) &&		// 0 Biggest
		abs(distvector[0]) > abs(distvector[2]))
	{
		if (distvector[0] > 0)
			strcpy(temp, "north of ");
		else
			strcpy(temp, "south of ");
	}
	else if (abs(distvector[1]) > abs(distvector[2]))	// 1 biggest
	{
		if (distvector[1] > 0)
			strcpy(temp, "west of ");
		else
			strcpy(temp, "east of ");
	}
	*/
	vectoangles(distvector, angles);
	//angle = angles[1];
	angle = (int)ent->client->v_angle[1] - angles[1];

	// Turn the angle positive
	angle = (angle + 720) % 360;

	if (angle < 22 || angle >= 338)
		return "north";
	else if (angle < 67)
		return "northeast";
	else if (angle < 112)
		return "east";
	else if (angle < 157)
		return "southeast";
	else if (angle < 202)
		return "south";
	else if (angle < 247)
		return "southwest";
	else if (angle < 292)
		return "west";
	else // MJD See Previous Error - Requires Default
		return "northwest";
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x20, %rsp
movq %rdi, %r14
movq 0x58(%rdi), %rax
movl 0x1100(%rax), %eax
leaq 0x2efbb(%rip), %rbx     # 0x4f826
cmpl $0x1, %eax
je 0x20882
cmpl $0x2, %eax
jne 0x20935
movq 0x45f78(%rip), %rcx     # 0x667f8
jmp 0x20889
movq 0x45fd7(%rip), %rcx     # 0x66860
movq (%rcx), %rdx
testq %rdx, %rdx
je 0x20935
movq 0x110(%rdx), %rcx
testq %rcx, %rcx
cmoveq %rdx, %rcx
cmpq %r14, %rcx
je 0x20920
movsd 0x4(%rcx), %xmm0
movsd 0x4(%r14), %xmm1
subps %xmm1, %xmm0
leaq 0x8(%rsp), %rdi
movlps %xmm0, (%rdi)
movss 0xc(%rcx), %xmm0
subss 0xc(%r14), %xmm0
movss %xmm0, 0x8(%rdi)
leaq 0x14(%rsp), %r15
movq %r15, %rsi
callq 0x19240
movq 0x58(%r14), %rax
movss 0xec0(%rax), %xmm0
cvttps2dq %xmm0, %xmm0
cvtdq2ps %xmm0, %xmm0
subss 0x4(%r15), %xmm0
cvttss2si %xmm0, %eax
addl $0x2d0, %eax            # imm = 0x2D0
movl $0x168, %ecx            # imm = 0x168
cltd
idivl %ecx
leal -0x152(%rdx), %eax
cmpl $0xfffffec4, %eax       # imm = 0xFFFFFEC4
jb 0x20935
cmpl $0x43, %edx
jae 0x20942
leaq 0x2ef0e(%rip), %rbx     # 0x4f82c
jmp 0x20935
cmpl $0x1, %eax
leaq 0x2ef16(%rip), %rax     # 0x4f840
leaq 0x2ef1c(%rip), %rbx     # 0x4f84d
cmoveq %rax, %rbx
movq %rbx, %rax
addq $0x20, %rsp
popq %rbx
popq %r14
popq %r15
retq
cmpl $0x70, %edx
jae 0x20950
leaq 0x2eee3(%rip), %rbx     # 0x4f831
jmp 0x20935
cmpl $0x9d, %edx
jae 0x20961
leaq 0x2eed7(%rip), %rbx     # 0x4f836
jmp 0x20935
cmpl $0xca, %edx
jae 0x20972
leaq 0x2ee9c(%rip), %rbx     # 0x4f80c
jmp 0x20935
cmpl $0xf7, %edx
jae 0x20983
leaq 0x2ee91(%rip), %rbx     # 0x4f812
jmp 0x20935
cmpl $0x124, %edx            # imm = 0x124
leaq 0x2ee91(%rip), %rax     # 0x4f821
leaq 0x2ee85(%rip), %rbx     # 0x4f81c
cmovbq %rax, %rbx
jmp 0x20935