// File: /workspace/github_c_makefile_star2_O1/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, 0x2b(%rsp)   # imm = 0x676E69
movl $0x69727473, 0x28(%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 %r14d, %r14d
movl %eax, 0x10(%rsp)
cmpl $0x1, %eax
setne %cl
movq 0x208b0(%rip), %r12     # 0x69d40
movslq 0x610(%r12), %rax
movl $0x0, 0xc(%rsp)
testq %rax, %rax
jle 0x49545
movb %cl, %r14b
movq 0x200a5(%rip), %rcx     # 0x69558
movq (%rcx), %rcx
movq 0x408(%r12), %r13
imulq $0x4a8, %rax, %rbx      # imm = 0x4A8
xorl %ebp, %ebp
movl $0x0, 0xc(%rsp)
xorl %edi, %edi
movq %rcx, 0x18(%rsp)
cmpl $0x0, 0x508(%rcx,%rbp)
je 0x49532
movl 0x1100(%r13), %eax
cmpl $0x1, %eax
je 0x494f8
cmpl $0x2, %eax
jne 0x49532
movl $0x1, %eax
jmp 0x494fa
xorl %eax, %eax
cmpl %r14d, %eax
jne 0x49532
movl %edi, 0x20(%rsp)
leaq 0x2c0(%r13), %rdi
callq 0x18680
movl 0x20(%rsp), %edi
movslq %edi, %rcx
incl %edi
movq %r13, 0x1360(%rsp,%rcx,8)
movl 0xc(%rsp), %ecx
cmpl %eax, %ecx
cmovgl %ecx, %eax
movq 0x18(%rsp), %rcx
movl %eax, 0xc(%rsp)
addq $0x9140, %r13           # imm = 0x9140
addq $0x4a8, %rbp            # imm = 0x4A8
cmpq %rbp, %rbx
jne 0x494d6
leaq 0x11e48(%rip), %r13     # 0x5b394
xorl %ebp, %ebp
cmpl $0x2, %ebp
ja 0x4955f
movl %ebp, %eax
movslq (%r13,%rax,4), %r14
addq %r13, %r14
jmp 0x49562
xorl %r14d, %r14d
cmpl $0x0, 0x610(%r12)
jle 0x495d6
xorl %ebx, %ebx
xorl %ecx, %ecx
movq 0x1360(%rsp,%rbx,8), %rdi
testq %rdi, %rdi
je 0x495bf
addq $0x2d0, %rdi            # imm = 0x2D0
testq %r14, %r14
cmoveq %rdi, %r14
movq %r14, %rsi
callq 0x18690
movl $0x1, %ecx
testl %eax, %eax
jne 0x495bf
movq 0x1360(%rsp,%rbx,8), %rax
movslq %r15d, %rdx
incl %r15d
movq %rax, 0xb60(%rsp,%rdx,8)
movq $0x0, 0x1360(%rsp,%rbx,8)
incq %rbx
movslq 0x610(%r12), %rax
cmpq %rax, %rbx
jl 0x49571
testl %ecx, %ecx
sete %al
jmp 0x495d8
movb $0x1, %al
incl %ebp
testb %al, %al
je 0x4954e
movb $0x0, 0x60(%rsp)
cmpl $0x1, 0x10(%rsp)
je 0x49622
movups 0x120f9(%rip), %xmm0    # 0x5b6ee
movaps %xmm0, 0x80(%rsp)
movups 0x120da(%rip), %xmm0    # 0x5b6de
movaps %xmm0, 0x70(%rsp)
movups 0x120be(%rip), %xmm0    # 0x5b6ce
movaps %xmm0, 0x60(%rsp)
movl $0x206761, 0x8f(%rsp) # imm = 0x206761
jmp 0x49651
movups 0x12094(%rip), %xmm0    # 0x5b6bd
movaps %xmm0, 0x80(%rsp)
movups 0x12075(%rip), %xmm0    # 0x5b6ad
movaps %xmm0, 0x70(%rsp)
movups 0x12059(%rip), %xmm0    # 0x5b69d
movaps %xmm0, 0x60(%rsp)
movb $0x0, 0x90(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x18680
movups 0x1209f(%rip), %xmm0    # 0x5b701
movups %xmm0, 0x60(%rsp,%rax)
movups 0x120a3(%rip), %xmm0    # 0x5b711
movups %xmm0, 0x70(%rsp,%rax)
movw $0x20, 0x80(%rsp,%rax)
testl %r15d, %r15d
jle 0x49809
decl %r15d
cmpl $0xf, %r15d
movl $0xf, %eax
cmovbl %r15d, %eax
incl %eax
movq %rax, 0x30(%rsp)
leaq 0x5e0(%rsp), %rbp
xorl %r14d, %r14d
movq $0x0, 0x10(%rsp)
xorl %r13d, %r13d
xorl %r12d, %r12d
movb $0x0, 0x5e0(%rsp)
testq %r12, %r12
je 0x496e0
movq 0xb60(%rsp,%r14,8), %rsi
movl $0x2d0, %eax            # imm = 0x2D0
addq %rax, %rsi
movq %r12, %rdi
callq 0x18690
testl %eax, %eax
je 0x4972b
movq 0xb60(%rsp,%r14,8), %r12
movl $0x2d0, %eax            # imm = 0x2D0
addq %rax, %r12
movq %rbp, %rdi
callq 0x18680
cltq
leaq (%rsp,%rax), %rdi
addq $0x5e0, %rdi            # imm = 0x5E0
leal (%r14,%r13), %eax
leal 0x2a(,%rax,8), %edx
leaq 0x1200c(%rip), %rsi     # 0x5b723
movq %r12, 0x18(%rsp)
movq %r12, %rcx
xorl %eax, %eax
callq 0x19700
incl %r13d
jmp 0x49730
movq %r12, 0x18(%rsp)
movq 0xb60(%rsp,%r14,8), %r15
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 0x11fd8(%rip), %rsi     # 0x5b73b
callq 0x18690
movl %eax, %r12d
movq %rbp, %rdi
callq 0x18680
movq %r13, 0x20(%rsp)
leal (%r14,%r13), %ecx
testl %r12d, %r12d
cltq
leaq 0x5e0(%rsp,%rax), %rdi
leal 0x2a(,%rcx,8), %edx
leaq 0x28(%rsp), %rcx
leaq 0x38(%rsp), %rax
cmoveq %rax, %rcx
addq $0x2c0, %r15            # imm = 0x2C0
movq %rbx, (%rsp)
leaq 0x11f91(%rip), %rsi     # 0x5b741
movl 0xc(%rsp), %r8d
movq %r15, %r9
xorl %eax, %eax
callq 0x19700
movl $0x3e8, %ebx            # imm = 0x3E8
subl 0x10(%rsp), %ebx
movq %rbp, %rdi
callq 0x18680
cmpl %eax, %ebx
jle 0x497f1
leaq 0x60(%rsp), %r15
movq %r15, %rdi
movq %rbp, %rsi
callq 0x19640
movq %r15, %rdi
callq 0x18680
movq %rax, 0x10(%rsp)
incq %r14
cmpq %r14, 0x30(%rsp)
movq 0x20(%rsp), %r13
movq 0x18(%rsp), %r12
jne 0x496b7
movq 0x1fdf0(%rip), %rbx     # 0x69600
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