// File: /workspace/github_c_makefile_star2_O1/QwazyWabbitWOS[P]lmctf60/g_tourney.c
// Function: Victory
void Victory()
{
    long i;
    edict_t *ent=NULL;
    long redscore, bluescore;
    long temp, oscore, dscore;
    char victory_buf[MAX_INFO_STRING];
    char temp_buf[MAX_INFO_STRING];
    char teambuf[MAX_INFO_STRING];

    bluescore = redscore = 0;
    oscore = dscore = 0;
    dmvp = omvp = NULL;

    strcpy(victory_buf,"");

    for (i=0 ; i<game.maxclients ; i++) {
        ent = g_edicts + 1 + i;

        if (!ent->inuse) {
            continue;
        }

        if (ent->client->ctf.teamnum == CTF_TEAM_RED) { // RED TEAM
            redscore += stats_get(ent, STATS_SCORE);
        } else if (ent->client->ctf.teamnum == CTF_TEAM_BLUE) { // BLUE TEAM
            bluescore += stats_get(ent, STATS_SCORE);
        }
    }

    // Find the dmvp
    for (i=0 ; i<game.maxclients ; i++) {
        ent = g_edicts + 1 + i;

        temp = 4*stats_get(ent, STATS_OFFENSE_CARRIER) +
            3*stats_get(ent, STATS_DEFENSE_FLAG) +
            2*stats_get(ent, STATS_RETURNS) +
            stats_get(ent, STATS_DEFENSE_CARRIER) +
            stats_get(ent, STATS_DEFENSE_BASE);

        if (temp > dscore) {
            dscore = temp;
            dmvp = ent;
        }
    }

    // Find the omvp
    for (i=0 ; i<game.maxclients ; i++) {
        ent = g_edicts + 1 + i;

        // Exclude dmvp
        if (ent == dmvp) {
            continue;
        }

        temp = 8*stats_get(ent, STATS_CAPTURES) + 4*stats_get(ent, STATS_DEFENSE_CARRIER)
            + stats_get(ent, STATS_ASSISTS);

        if (temp > oscore) {
            oscore = temp;
            omvp = ent;
        }
    }

    if (dmvp) {
        strcpy(teambuf,"");
        ctf_teamstring(teambuf,dmvp->client->ctf.teamnum,CTF_TEAM_MATCHING);

        Com_sprintf(temp_buf, sizeof temp_buf, "Defense MVP: %s (%s)!\n",
            dmvp->client->pers.netname,
            teambuf);
        strcat(victory_buf,temp_buf);
    }

    if (omvp) {
        strcpy(teambuf,"");
        ctf_teamstring(teambuf,omvp->client->ctf.teamnum,CTF_TEAM_MATCHING);

        Com_sprintf(temp_buf, sizeof temp_buf, "Offense MVP: %s (%s)!\n",
            omvp->client->pers.netname,
            teambuf);
        strcat(victory_buf, temp_buf);
    }

    if (bluescore > redscore) {
        gi.sound (ent, CHAN_CTF, gi.soundindex ("ctf/end_blue.wav"), 1, ATTN_NONE, 0);
        sprintf(temp_buf, "Blue: %ld beats red: %ld!\n", bluescore,redscore);
        strcat(victory_buf, temp_buf);
    } else if (redscore > bluescore) {
        gi.sound (ent, CHAN_CTF, gi.soundindex ("ctf/end_red.wav"), 1, ATTN_NONE, 0);
        sprintf(temp_buf, "Red: %ld beats blue: %ld!\n", redscore,bluescore);
        strcat(victory_buf, temp_buf);
    } else {
        gi.sound (ent, CHAN_CTF, gi.soundindex ("ctf/end_tie.wav"), 1, ATTN_NONE, 0);
        sprintf(temp_buf, "Tie game at %ld!\n", redscore);
        strcat(victory_buf, temp_buf);
    }

    ctf_BSafePrint(PRINT_HIGH, victory_buf);
    ctf_SetLogName(); //automated log rename check each level
    //sl_Logging( gi, NULL );
    //this will cause the name of the log to change when the day number changes
    //which hypothetically would be midnight
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x628, %rsp            # imm = 0x628
movq 0x46503(%rip), %rax     # 0x69838
xorl %ebp, %ebp
movq %rbp, (%rax)
movq 0x4620f(%rip), %r13     # 0x69550
movq %rbp, (%r13)
movb $0x0, 0x220(%rsp)
movq 0x469ec(%rip), %rax     # 0x69d40
cmpl $0x0, 0x610(%rax)
jle 0x233e9
movl $0x4a8, %ebx            # imm = 0x4A8
xorl %r13d, %r13d
movq 0x461e8(%rip), %r15     # 0x69558
xorl %ebp, %ebp
xorl %r12d, %r12d
movq (%r15), %r14
cmpl $0x0, 0x60(%r14,%rbx)
je 0x233b5
leaq (%r14,%rbx), %rdi
movq 0x58(%r14,%rbx), %rax
movl 0x1100(%rax), %eax
cmpl $0x2, %eax
je 0x233a8
cmpl $0x1, %eax
jne 0x233b5
movl $0x3, %esi
callq 0x18030
addq %rax, %rbp
jmp 0x233b5
movl $0x3, %esi
callq 0x18030
addq %rax, %r13
incq %r12
movq 0x46981(%rip), %rax     # 0x69d40
movslq 0x610(%rax), %rax
addq $0x4a8, %rbx            # imm = 0x4A8
cmpq %rax, %r12
jl 0x23375
leaq (%r14,%rbx), %r15
addq $-0x4a8, %r15           # imm = 0xFB58
movq %r13, %r14
movq 0x46169(%rip), %r13     # 0x69550
jmp 0x233ef
xorl %r15d, %r15d
xorl %r14d, %r14d
movq 0x4694a(%rip), %rax     # 0x69d40
cmpl $0x0, 0x610(%rax)
movq %rbp, 0x10(%rsp)
movq %r14, 0x8(%rsp)
jle 0x234d8
xorl %ebx, %ebx
xorl %r14d, %r14d
xorl %ebp, %ebp
movq 0x4613d(%rip), %rax     # 0x69558
movq (%rax), %rax
movq %rax, (%rsp)
leaq (%rax,%rbx), %r12
addq $0x4a8, %r12            # imm = 0x4A8
movq %r12, %rdi
movl $0xd, %esi
callq 0x18030
movq %rax, %r13
movq %r12, %rdi
movl $0x7, %esi
callq 0x18030
leaq (%rax,%rax,2), %rax
leaq (%rax,%r13,4), %r13
movq %r12, %rdi
movl $0xb, %esi
callq 0x18030
leaq (,%rax,2), %r15
addq %r13, %r15
movq %r12, %rdi
movl $0x9, %esi
callq 0x18030
movq %rax, %r13
movq %r12, %rdi
movl $0x8, %esi
callq 0x18030
addq %r13, %rax
addq %r15, %rax
cmpq %r14, %rax
jle 0x2349f
movq 0x460b7(%rip), %rcx     # 0x69550
movq %r12, (%rcx)
movq %rax, %r14
incq %rbp
movq 0x46897(%rip), %rax     # 0x69d40
movslq 0x610(%rax), %rax
addq $0x4a8, %rbx            # imm = 0x4A8
cmpq %rax, %rbp
jl 0x23414
movq (%rsp), %r15
addq %rbx, %r15
movq 0x10(%rsp), %rbp
movq 0x8(%rsp), %r14
movq 0x46078(%rip), %r13     # 0x69550
movq 0x46861(%rip), %rax     # 0x69d40
cmpl $0x0, 0x610(%rax)
jle 0x235a9
movl $0x4a8, %ebp            # imm = 0x4A8
xorl %ebx, %ebx
movq $0x0, 0x18(%rsp)
xorl %r14d, %r14d
movq 0x46052(%rip), %rax     # 0x69558
movq (%rax), %rax
movq %rax, (%rsp)
leaq (%rax,%rbp), %r12
cmpq (%r13), %r12
je 0x23570
movq %r12, %rdi
movl $0x4, %esi
callq 0x18030
movq %rax, %r13
shlq $0x3, %r13
movq %r12, %rdi
movl $0x9, %esi
callq 0x18030
leaq (,%rax,4), %r15
addq %r13, %r15
movq 0x46006(%rip), %r13     # 0x69550
movq %r12, %rdi
movl $0xa, %esi
callq 0x18030
addq %r15, %rax
cmpq 0x18(%rsp), %rax
jle 0x23570
movq 0x462d0(%rip), %rcx     # 0x69838
movq %r12, (%rcx)
movq %rax, 0x18(%rsp)
incq %r14
movq 0x467c6(%rip), %rax     # 0x69d40
movslq 0x610(%rax), %rax
addq $-0x4a8, %rbx           # imm = 0xFB58
addq $0x4a8, %rbp            # imm = 0x4A8
cmpq %rax, %r14
jl 0x234ff
movq (%rsp), %r15
subq %rbx, %r15
movq 0x10(%rsp), %rbp
movq 0x8(%rsp), %r14
movq (%r13), %rax
testq %rax, %rax
je 0x23611
leaq 0x420(%rsp), %r12
movb $0x0, (%r12)
movq 0x58(%rax), %rax
movl 0x1100(%rax), %esi
movq %r12, %rdi
movl $0xfffffff9, %edx       # imm = 0xFFFFFFF9
callq 0x181f0
movq (%r13), %rax
movl $0x2c0, %ecx            # imm = 0x2C0
addq 0x58(%rax), %rcx
leaq 0x313d4(%rip), %rdx     # 0x549be
leaq 0x20(%rsp), %r13
movq %r13, %rdi
movl $0x200, %esi            # imm = 0x200
movq %r12, %r8
xorl %eax, %eax
callq 0x18e10
leaq 0x220(%rsp), %rdi
movq %r13, %rsi
callq 0x19640
movq 0x46220(%rip), %rcx     # 0x69838
movq (%rcx), %rax
testq %rax, %rax
je 0x23681
movq %rcx, %rbx
leaq 0x420(%rsp), %r12
movb $0x0, (%r12)
movq 0x58(%rax), %rax
movl 0x1100(%rax), %esi
movq %r12, %rdi
movl $0xfffffff9, %edx       # imm = 0xFFFFFFF9
callq 0x181f0
movq (%rbx), %rax
movl $0x2c0, %ecx            # imm = 0x2C0
addq 0x58(%rax), %rcx
leaq 0x3137b(%rip), %rdx     # 0x549d5
leaq 0x20(%rsp), %r13
movq %r13, %rdi
movl $0x200, %esi            # imm = 0x200
movq %r12, %r8
xorl %eax, %eax
callq 0x18e10
leaq 0x220(%rsp), %rdi
movq %r13, %rsi
callq 0x19640
movq 0x45f78(%rip), %rax     # 0x69600
cmpq %rbp, %r14
jle 0x236c9
movq 0x20(%rax), %rbx
leaq 0x31354(%rip), %rdi     # 0x549ec
callq *0x48(%rax)
movss 0x30885(%rip), %xmm0    # 0x53f28
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
movq %r15, %rdi
movl $0x5, %esi
movl %eax, %edx
callq *%rbx
leaq 0x31341(%rip), %rsi     # 0x549fd
leaq 0x20(%rsp), %rdi
movq %r14, %rdx
movq %rbp, %rcx
jmp 0x23708
movq 0x20(%rax), %rbx
movq 0x48(%rax), %rax
jge 0x23711
leaq 0x3133e(%rip), %rdi     # 0x54a18
callq *%rax
movss 0x30844(%rip), %xmm0    # 0x53f28
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
movq %r15, %rdi
movl $0x5, %esi
movl %eax, %edx
callq *%rbx
leaq 0x3132b(%rip), %rsi     # 0x54a28
leaq 0x20(%rsp), %rdi
movq %rbp, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x19700
jmp 0x2374a
leaq 0x3132b(%rip), %rdi     # 0x54a43
callq *%rax
movss 0x30806(%rip), %xmm0    # 0x53f28
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
movq %r15, %rdi
movl $0x5, %esi
movl %eax, %edx
callq *%rbx
leaq 0x31318(%rip), %rsi     # 0x54a53
leaq 0x20(%rsp), %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x19700
leaq 0x220(%rsp), %rbx
leaq 0x20(%rsp), %rsi
movq %rbx, %rdi
callq 0x19640
movl $0x2, %edi
movq %rbx, %rsi
callq 0x19270
xorl %eax, %eax
callq 0x192c0
addq $0x628, %rsp            # imm = 0x628
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq