// File: /workspace/github_c_makefile_star2_O3/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 0x3150f(%rip), %rbx     # 0x53826
cmpl $0x1, %eax
je 0x2232e
cmpl $0x2, %eax
jne 0x22407
movq 0x464cc(%rip), %rcx     # 0x687f8
jmp 0x22335
movq 0x4652b(%rip), %rcx     # 0x68860
movq (%rcx), %rdx
testq %rdx, %rdx
je 0x22407
movq 0x110(%rdx), %rcx
testq %rcx, %rcx
cmoveq %rdx, %rcx
cmpq %r14, %rcx
je 0x223f2
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 0x190d0
movq 0x58(%r14), %rax
movss 0xec0(%rax), %xmm0
cvttps2dq %xmm0, %xmm0
cvtdq2ps %xmm0, %xmm0
subss 0x4(%r15), %xmm0
cvttss2si %xmm0, %ecx
movl %ecx, %eax
addl $0x2d0, %eax            # imm = 0x2D0
cltq
imulq $-0x49f49f49, %rax, %rdx # imm = 0xB60B60B7
shrq $0x20, %rdx
addl %edx, %ecx
addl $0x2d0, %ecx            # imm = 0x2D0
movl %ecx, %edx
shrl $0x1f, %edx
sarl $0x8, %ecx
addl %edx, %ecx
imull $0x168, %ecx, %ecx      # imm = 0x168
subl %ecx, %eax
leal -0x152(%rax), %ecx
cmpl $0xfffffec4, %ecx       # imm = 0xFFFFFEC4
jb 0x22407
cmpl $0x43, %eax
jae 0x22414
leaq 0x3143c(%rip), %rbx     # 0x5382c
jmp 0x22407
cmpl $0x1, %eax
leaq 0x31444(%rip), %rax     # 0x53840
leaq 0x3144a(%rip), %rbx     # 0x5384d
cmoveq %rax, %rbx
movq %rbx, %rax
addq $0x20, %rsp
popq %rbx
popq %r14
popq %r15
retq
cmpl $0x70, %eax
jae 0x22422
leaq 0x31411(%rip), %rbx     # 0x53831
jmp 0x22407
cmpl $0x9d, %eax
jae 0x22432
leaq 0x31406(%rip), %rbx     # 0x53836
jmp 0x22407
cmpl $0xca, %eax
jae 0x22442
leaq 0x313cc(%rip), %rbx     # 0x5380c
jmp 0x22407
cmpl $0xf7, %eax
jae 0x22452
leaq 0x313c2(%rip), %rbx     # 0x53812
jmp 0x22407
cmpl $0x124, %eax            # imm = 0x124
leaq 0x313c3(%rip), %rax     # 0x53821
leaq 0x313b7(%rip), %rbx     # 0x5381c
cmovbq %rax, %rbx
jmp 0x22407