// File: /workspace/github_c_makefile_star2_O2/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 $0x1b78, %rsp           # imm = 0x1B78
movabsq $0x32676e69727473, %rax # imm = 0x32676E69727473
movq %rax, 0x48(%rsp)
movl $0x676e69, 0x2b(%rsp)   # imm = 0x676E69
movl $0x69727473, 0x28(%rsp) # imm = 0x69727473
xorl %eax, %eax
cmpq $0x100, %rax            # imm = 0x100
je 0x44b33
andq $0x0, 0xb70(%rsp,%rax,8)
andq $0x0, 0x1370(%rsp,%rax,8)
incq %rax
jmp 0x44b14
movq 0x58(%rdi), %rax
movl 0x1100(%rax), %eax
xorl %r14d, %r14d
movl %eax, 0x20(%rsp)
cmpl $0x1, %eax
setne %r14b
movq 0x221ee(%rip), %rcx     # 0x66d40
movl 0x610(%rcx), %ebp
movq 0x219f9(%rip), %rax     # 0x66558
movq (%rax), %rbx
movq 0x408(%rcx), %r12
xorl %r13d, %r13d
testl %ebp, %ebp
movl $0x0, %eax
cmovgl %ebp, %eax
imulq $0x4a8, %rax, %rcx      # imm = 0x4A8
xorl %r15d, %r15d
movl $0x0, 0x14(%rsp)
movq %rcx, 0x18(%rsp)
cmpq %r13, %rcx
je 0x44bf8
cmpl $0x0, 0x508(%rbx,%r13)
je 0x44be8
movl 0x1100(%r12), %eax
cmpl $0x1, %eax
je 0x44bb4
cmpl $0x2, %eax
jne 0x44be8
pushq $0x1
popq %rax
jmp 0x44bb6
xorl %eax, %eax
cmpl %r14d, %eax
jne 0x44be8
leaq 0x2c0(%r12), %rdi
callq 0x186c0
movslq %r15d, %rcx
incl %r15d
movq %r12, 0x1370(%rsp,%rcx,8)
movl 0x14(%rsp), %ecx
cmpl %eax, %ecx
cmovgl %ecx, %eax
movq 0x18(%rsp), %rcx
movl %eax, 0x14(%rsp)
addq $0x4a8, %r13            # imm = 0x4A8
addq $0x9140, %r12           # imm = 0x9140
jmp 0x44b8d
xorl %ecx, %ecx
pushq $0x1
popq %rbx
movl %ebx, %eax
xorl %r12d, %r12d
testl %eax, %eax
je 0x44c94
cmpl $0x2, %ecx
movq %rcx, 0x18(%rsp)
ja 0x44c26
movl %ecx, %eax
leaq 0x11a27(%rip), %rcx     # 0x56644
movslq (%rcx,%rax,4), %r14
addq %rcx, %r14
jmp 0x44c29
xorl %r14d, %r14d
xorl %r13d, %r13d
xorl %eax, %eax
movslq %ebp, %rcx
cmpq %rcx, %r13
jge 0x44c88
movq 0x1370(%rsp,%r13,8), %r15
testq %r15, %r15
je 0x44c83
leaq 0x2d0(%r15), %rdi
testq %r14, %r14
cmoveq %rdi, %r14
movq %r14, %rsi
callq 0x186d0
movq 0x220e0(%rip), %rcx     # 0x66d40
movl 0x610(%rcx), %ebp
testl %eax, %eax
jne 0x44c81
movslq %r12d, %rax
incl %r12d
movq %r15, 0xb70(%rsp,%rax,8)
andq $0x0, 0x1370(%rsp,%r13,8)
movl %ebx, %eax
incq %r13
jmp 0x44c2e
movq 0x18(%rsp), %rcx
incl %ecx
jmp 0x44c02
cmpl $0x1, 0x20(%rsp)
je 0x44cd2
movups 0x11cfc(%rip), %xmm0    # 0x5699e
movaps %xmm0, 0x90(%rsp)
movups 0x11cdd(%rip), %xmm0    # 0x5698e
movaps %xmm0, 0x80(%rsp)
movups 0x11cbe(%rip), %xmm0    # 0x5697e
movaps %xmm0, 0x70(%rsp)
movl $0x206761, 0x9f(%rsp) # imm = 0x206761
jmp 0x44d04
movups 0x11c94(%rip), %xmm0    # 0x5696d
movaps %xmm0, 0x90(%rsp)
movups 0x11c75(%rip), %xmm0    # 0x5695d
movaps %xmm0, 0x80(%rsp)
movups 0x11c56(%rip), %xmm0    # 0x5694d
movaps %xmm0, 0x70(%rsp)
movb $0x0, 0xa0(%rsp)
leaq 0x70(%rsp), %rdi
callq 0x186c0
movups 0x11c9c(%rip), %xmm0    # 0x569b1
movups %xmm0, 0x70(%rsp,%rax)
movups 0x11ca0(%rip), %xmm0    # 0x569c1
movups %xmm0, 0x80(%rsp,%rax)
movw $0x20, 0x90(%rsp,%rax)
movslq %r12d, %rax
movq %rax, 0x40(%rsp)
leaq 0x5f0(%rsp), %r15
xorl %r13d, %r13d
xorl %r14d, %r14d
xorl %ebx, %ebx
movq $0x0, 0x30(%rsp)
cmpq $0xf, %r13
ja 0x44ec5
cmpq 0x40(%rsp), %r13
jge 0x44ec5
movb $0x0, 0x5f0(%rsp)
testq %r14, %r14
movq %r13, 0x20(%rsp)
je 0x44d97
movq 0xb70(%rsp,%r13,8), %rsi
movl $0x2d0, %eax            # imm = 0x2D0
addq %rax, %rsi
movq %r14, %rdi
callq 0x186d0
testl %eax, %eax
je 0x44de1
movq 0xb70(%rsp,%r13,8), %r14
leaq 0x2d0(%r14), %r12
movq %r15, %rdi
callq 0x186c0
cltq
leaq (%rsp,%rax), %rdi
addq $0x5f0, %rdi            # imm = 0x5F0
leal (%r13,%rbx), %eax
leal 0x2a(,%rax,8), %edx
leaq 0x11c05(%rip), %rsi     # 0x569d3
movq %r12, 0x38(%rsp)
movq %r12, %rcx
xorl %eax, %eax
callq 0x198c0
incl %ebx
jmp 0x44dee
movq %r14, 0x38(%rsp)
movq 0xb70(%rsp,%r13,8), %r14
movq %r15, %r12
movl %r13d, %r15d
leaq 0x2e0(%r14), %rbp
leaq 0x50(%rsp), %r13
movq %r13, %rdi
movq %rbp, %rsi
pushq $0x5
popq %rdx
callq 0x181e0
movb $0x0, 0x55(%rsp)
movq %r13, %rdi
leaq 0x11bce(%rip), %rsi     # 0x569eb
callq 0x186d0
movl %eax, %r13d
movq %r12, %rdi
callq 0x186c0
movq %rbx, 0x18(%rsp)
addl %ebx, %r15d
testl %r13d, %r13d
cltq
leaq 0x5f0(%rsp,%rax), %rdi
leal 0x2a(,%r15,8), %edx
leaq 0x28(%rsp), %rcx
leaq 0x48(%rsp), %rax
cmoveq %rax, %rcx
addq $0x2c0, %r14            # imm = 0x2C0
movq %rbp, (%rsp)
leaq 0x11b87(%rip), %rsi     # 0x569f1
movl 0x14(%rsp), %r8d
movq %r14, %r9
xorl %eax, %eax
callq 0x198c0
movl $0x3e8, %ebx            # imm = 0x3E8
subl 0x30(%rsp), %ebx
movq %r12, %rdi
callq 0x186c0
cmpl %eax, %ebx
movq %r12, %r15
jle 0x44eae
leaq 0x70(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x19800
movq %rbx, %rdi
callq 0x186c0
movq %rax, 0x30(%rsp)
movq 0x20(%rsp), %r13
incq %r13
movq 0x18(%rsp), %rbx
movq 0x38(%rsp), %r14
jmp 0x44d54
movq 0x21734(%rip), %rbx     # 0x66600
pushq $0x4
popq %rdi
callq *0xc8(%rbx)
leaq 0x70(%rsp), %rdi
callq *0xe8(%rbx)
addq $0x1b78, %rsp           # imm = 0x1B78
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq