// File: /workspace/github_c_makefile_star2_O3/QwazyWabbitWOS[P]lmctf60/p_hud.c
// Function: CTFSquadboardMessage
void CTFSquadboardMessage (edict_t *ent, edict_t* killer) // ADC
{
	char	entry[MAX_MSGLEN];
	char	string[MAX_MSGLEN];
	int		len, i, j, team, ready;
	edict_t		*cl_ent;
	int maxsize = 1000;

	gclient_t* clients [MAX_CLIENTS];
	int clientCount = 0;
	gclient_t* sortedClients [MAX_CLIENTS];
	int sortedCount = 0;

	int teamOfInterest = 0;

	char* squad = 0;
	int numCategoryLines = 0;

	char readyString [] = "string2"; // green string
	char notReadyString [] = "string"; // white string

	char statusStart [MAX_STATUS_LEN];
	int greenStatusLen = (int)strlen (GREEN_STATUS_STR);

	int widestName = 0; // in chars

	for (i = 0; i< MAX_CLIENTS; i++)
		clients [i] = sortedClients [i] = 0;

	teamOfInterest = (ent->client->ctf.teamnum == CTF_TEAM_RED) ? 0 : 1;

	for (i = 0; i< game.maxclients; i++)
	{
		cl_ent = g_edicts + 1 + i;
		if (!cl_ent->inuse)
			continue;
		if (game.clients[i].ctf.teamnum == CTF_TEAM_RED)
			team = 0;
		else if (game.clients[i].ctf.teamnum == CTF_TEAM_BLUE)
			team = 1;
		else
			continue; // unknown team?

		if (team == teamOfInterest)
		{
			len = (int)strlen(game.clients[i].pers.netname);
			clients [clientCount++] = &game.clients [i];

			if (len > widestName)
				widestName = len;
		}
	}

	// We want to put the predefined categories first
	// in the list, then any remaining ones.

	for (i = 0, ready = 1; ready; i++) // squad loop
	{
		ready = 0;

		switch (i)
		{
		case 0:	 squad = "Offense"; break;
		case 1:	 squad = "Middle";  break;
		case 2:	 squad = "Defense"; break;
		default: squad = 0;         break;
		}

		for (j = 0; j< game.maxclients; j++) // client loop
		{
			if (clients[j])
			{
				ready = 1;

				if (squad == 0)
					squad = clients[j]->pers.squad;

				if (!Q_stricmp (clients[j]->pers.squad, squad))
				{
					sortedClients [sortedCount++] = clients [j];
					clients [j] = 0;
				}
			}
		}
	}

	// print level name and exit rules
	// add the clients in sorted order
	*string = 0;
	len = 0;

	if (teamOfInterest == 0) // red
		strcpy (string, "xv 0 yv 0 picn redlion_i xv 32 yv 0 picn redtag ");
	else  // blue
		strcpy (string, "xv 0 yv 0 picn bluewolf_i xv 32 yv 0 picn bluetag ");

	strcat (string, "xv 48 yv 10 string \"Squad Board\" ");

	squad = 0;

	for (i = 0; i< 16 ; i++)
	{
		if (i >= sortedCount)
			break; // we're done

		*entry = 0;

		if (!squad || Q_stricmp (squad, sortedClients[i]->pers.squad))
		{
			squad = sortedClients[i]->pers.squad;

			sprintf(entry+(int)strlen(entry),
				"xv 0 yv %d string \"%s\" ",
				42 + i * 8 + numCategoryLines * 8,
				sortedClients[i]->pers.squad);

			numCategoryLines++;
		}

		// If the status starts with "Ready", then it should be shown
		// in green.

		strncpy (statusStart, sortedClients[i]->pers.squadStatus, 
			greenStatusLen);
		statusStart[greenStatusLen] = 0;

		ready = !Q_stricmp (statusStart, GREEN_STATUS_STR);

		// Note that the width %*s below is the widest chars
		// for a netname. We want the names padded with spaces
		// to make the status line up.

		sprintf(entry+(int)strlen(entry),
			"xv 0 yv %d %s \"   %-*s %s\" ",
			42 + i * 8 + numCategoryLines * 8,
			ready ? readyString : notReadyString,
			widestName, sortedClients[i]->pers.netname,
			sortedClients[i]->pers.squadStatus);

		if (maxsize - len > (int)strlen(entry)) {
			strcat(string, entry);
			len = (int)strlen(string);
		}
	}

	gi.WriteByte (svc_layout);
	gi.WriteString (string);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1b68, %rsp           # imm = 0x1B68
movq %rdi, %rbx
movabsq $0x32676e69727473, %rax # imm = 0x32676E69727473
movq %rax, 0x38(%rsp)
movl $0x676e69, 0x33(%rsp)   # imm = 0x676E69
movl $0x69727473, 0x30(%rsp) # imm = 0x69727473
leaq 0xb60(%rsp), %rdi
xorl %r15d, %r15d
movl $0x800, %edx            # imm = 0x800
xorl %esi, %esi
callq 0x18880
leaq 0x1360(%rsp), %rdi
movl $0x800, %edx            # imm = 0x800
xorl %esi, %esi
callq 0x18880
movq 0x58(%rbx), %rax
movl 0x1100(%rax), %eax
xorl %ecx, %ecx
movl %eax, 0x28(%rsp)
cmpl $0x1, %eax
setne %al
movq 0x20495(%rip), %r12     # 0x68d40
movslq 0x610(%r12), %r13
movl $0x0, 0xc(%rsp)
testq %r13, %r13
jle 0x48967
movb %al, %cl
movq 0x1fc8b(%rip), %rax     # 0x68558
movq (%rax), %rbx
movq 0x408(%r12), %rbp
imulq $0x4a8, %r13, %rsi      # imm = 0x4A8
xorl %r14d, %r14d
movl $0x0, 0xc(%rsp)
xorl %edi, %edi
movl %ecx, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
cmpl $0x0, 0x508(%rbx,%r14)
je 0x48954
movl 0x1100(%rbp), %eax
cmpl $0x1, %eax
je 0x48917
cmpl $0x2, %eax
jne 0x48954
movl $0x1, %eax
jmp 0x48919
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x48954
movl %edi, 0x10(%rsp)
leaq 0x2c0(%rbp), %rdi
callq 0x18680
movl 0x10(%rsp), %edi
movq 0x18(%rsp), %rsi
movslq %edi, %rcx
incl %edi
movq %rbp, 0x1360(%rsp,%rcx,8)
movl 0xc(%rsp), %ecx
cmpl %eax, %ecx
cmovgl %ecx, %eax
movl 0x20(%rsp), %ecx
movl %eax, 0xc(%rsp)
addq $0x9140, %rbp           # imm = 0x9140
addq $0x4a8, %r14            # imm = 0x4A8
cmpq %r14, %rsi
jne 0x488f5
xorl %ebx, %ebx
cmpl $0x2, %ebx
ja 0x48980
movl %ebx, %eax
leaq 0x11cdd(%rip), %rcx     # 0x5a654
movslq (%rcx,%rax,4), %r14
addq %rcx, %r14
jmp 0x48983
xorl %r14d, %r14d
testl %r13d, %r13d
jle 0x489e8
xorl %ebp, %ebp
xorl %ecx, %ecx
movq 0x1360(%rsp,%rbp,8), %r13
testq %r13, %r13
je 0x489d2
leaq 0x2d0(%r13), %rdi
testq %r14, %r14
cmoveq %rdi, %r14
movq %r14, %rsi
callq 0x18690
movl $0x1, %ecx
testl %eax, %eax
jne 0x489d2
movslq %r15d, %rax
incl %r15d
movq %r13, 0xb60(%rsp,%rax,8)
movq $0x0, 0x1360(%rsp,%rbp,8)
incq %rbp
movslq 0x610(%r12), %r13
cmpq %r13, %rbp
jl 0x4898c
incl %ebx
testl %ecx, %ecx
jne 0x48969
cmpl $0x1, 0x28(%rsp)
je 0x48a23
movups 0x11fb8(%rip), %xmm0    # 0x5a9ae
movaps %xmm0, 0x80(%rsp)
movups 0x11f99(%rip), %xmm0    # 0x5a99e
movaps %xmm0, 0x70(%rsp)
movups 0x11f7d(%rip), %xmm0    # 0x5a98e
movaps %xmm0, 0x60(%rsp)
movl $0x206761, 0x8f(%rsp) # imm = 0x206761
jmp 0x48a52
movups 0x11f53(%rip), %xmm0    # 0x5a97d
movaps %xmm0, 0x80(%rsp)
movups 0x11f34(%rip), %xmm0    # 0x5a96d
movaps %xmm0, 0x70(%rsp)
movups 0x11f18(%rip), %xmm0    # 0x5a95d
movaps %xmm0, 0x60(%rsp)
movb $0x0, 0x90(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x18680
movups 0x11f5e(%rip), %xmm0    # 0x5a9c1
movups %xmm0, 0x60(%rsp,%rax)
movups 0x11f62(%rip), %xmm0    # 0x5a9d1
movups %xmm0, 0x70(%rsp,%rax)
movw $0x20, 0x80(%rsp,%rax)
testl %r15d, %r15d
jle 0x48c0f
decl %r15d
cmpl $0xf, %r15d
movl $0xf, %eax
cmovbl %r15d, %eax
incl %eax
movq %rax, 0x28(%rsp)
leaq 0x5e0(%rsp), %rbp
xorl %r13d, %r13d
movq $0x0, 0x18(%rsp)
xorl %r14d, %r14d
xorl %r15d, %r15d
movb $0x0, 0x5e0(%rsp)
testq %r15, %r15
je 0x48ae1
movq 0xb60(%rsp,%r13,8), %rsi
movl $0x2d0, %eax            # imm = 0x2D0
addq %rax, %rsi
movq %r15, %rdi
callq 0x18690
testl %eax, %eax
je 0x48b2c
movq 0xb60(%rsp,%r13,8), %r15
leaq 0x2d0(%r15), %r12
movq %rbp, %rdi
callq 0x18680
cltq
leaq (%rsp,%rax), %rdi
addq $0x5e0, %rdi            # imm = 0x5E0
leal (%r13,%r14), %eax
leal 0x2a(,%rax,8), %edx
leaq 0x11ecb(%rip), %rsi     # 0x5a9e3
movq %r12, 0x20(%rsp)
movq %r12, %rcx
xorl %eax, %eax
callq 0x196f0
incl %r14d
jmp 0x48b39
movq %r15, 0x20(%rsp)
movq 0xb60(%rsp,%r13,8), %r15
movq %r14, 0x10(%rsp)
movl %r13d, %r14d
leaq 0x2e0(%r15), %rbx
movl $0x5, %edx
leaq 0x40(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x181c0
movb $0x0, 0x45(%rsp)
movq %r12, %rdi
leaq 0x11e8f(%rip), %rsi     # 0x5a9fb
callq 0x18690
movl %eax, %r12d
movq %rbp, %rdi
callq 0x18680
addl 0x10(%rsp), %r14d
testl %r12d, %r12d
cltq
leaq 0x5e0(%rsp,%rax), %rdi
leal 0x2a(,%r14,8), %edx
leaq 0x30(%rsp), %rcx
leaq 0x38(%rsp), %rax
cmoveq %rax, %rcx
addq $0x2c0, %r15            # imm = 0x2C0
movq %rbx, (%rsp)
leaq 0x11e4b(%rip), %rsi     # 0x5aa01
movl 0xc(%rsp), %r8d
movq %r15, %r9
xorl %eax, %eax
callq 0x196f0
movl $0x3e8, %ebx            # imm = 0x3E8
subl 0x18(%rsp), %ebx
movq %rbp, %rdi
callq 0x18680
cmpl %eax, %ebx
jle 0x48bf7
leaq 0x60(%rsp), %r14
movq %r14, %rdi
movq %rbp, %rsi
callq 0x19640
movq %r14, %rdi
callq 0x18680
movq %rax, 0x18(%rsp)
incq %r13
cmpq %r13, 0x28(%rsp)
movq 0x10(%rsp), %r14
movq 0x20(%rsp), %r15
jne 0x48ab8
movq 0x1f9ea(%rip), %rbx     # 0x68600
movl $0x4, %edi
callq *0xc8(%rbx)
leaq 0x60(%rsp), %rdi
callq *0xe8(%rbx)
addq $0x1b68, %rsp           # imm = 0x1B68
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq