// File: /workspace/github_c_makefile_star2_O3/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 0x455e3(%rip), %rbx     # 0x68838
xorl %eax, %eax
movq %rax, (%rbx)
movq 0x452ef(%rip), %rcx     # 0x68550
movq %rax, (%rcx)
movb $0x0, 0x220(%rsp)
movq 0x45acd(%rip), %r12     # 0x68d40
cmpl $0x0, 0x610(%r12)
jle 0x23477
movl $0x4a8, %ebx            # imm = 0x4A8
movq $0x0, 0x10(%rsp)
movq 0x452c1(%rip), %r13     # 0x68558
xorl %ebp, %ebp
xorl %r14d, %r14d
movq (%r13), %r15
cmpl $0x0, 0x60(%r15,%rbx)
je 0x232df
leaq (%r15,%rbx), %rdi
movq 0x58(%r15,%rbx), %rax
movl 0x1100(%rax), %eax
cmpl $0x2, %eax
je 0x232d0
cmpl $0x1, %eax
jne 0x232df
movl $0x3, %esi
callq 0x18030
addq %rax, %rbp
jmp 0x232df
movl $0x3, %esi
callq 0x18030
addq %rax, 0x10(%rsp)
incq %r14
movslq 0x610(%r12), %rax
addq $0x4a8, %rbx            # imm = 0x4A8
cmpq %rax, %r14
jl 0x2329c
testl %eax, %eax
jle 0x2347e
movq %rbp, 0x18(%rsp)
xorl %ebx, %ebx
xorl %ebp, %ebp
xorl %r14d, %r14d
movq (%r13), %rax
movq %rax, 0x8(%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), %r15
movq %r12, %rdi
movl $0xb, %esi
callq 0x18030
leaq (%r15,%rax,2), %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 %rbp, %rax
jle 0x23389
movq 0x451cd(%rip), %rcx     # 0x68550
movq %r12, (%rcx)
movq %rax, %rbp
incq %r14
movq 0x459ad(%rip), %rdi     # 0x68d40
movslq 0x610(%rdi), %rax
addq $0x4a8, %rbx            # imm = 0x4A8
cmpq %rax, %r14
movq 0x451ad(%rip), %r13     # 0x68558
jl 0x2330a
movq 0x45198(%rip), %rcx     # 0x68550
movq (%rcx), %rcx
testl %eax, %eax
jle 0x234a5
movq (%r13), %rdx
movl $0x4a8, %ebx            # imm = 0x4A8
xorl %r14d, %r14d
xorl %r15d, %r15d
xorl %ebp, %ebp
leaq (%rdx,%rbx), %r12
cmpq %rcx, %r12
movq %rdx, 0x8(%rsp)
je 0x2343d
movq %r12, %rdi
movl $0x4, %esi
callq 0x18030
movq %rax, %r13
shlq $0x3, %r13
movq %r12, %rdi
movl $0x9, %esi
callq 0x18030
leaq (%r13,%rax,4), %r13
movq %r12, %rdi
movl $0xa, %esi
callq 0x18030
addq %r13, %rax
movq 0x45139(%rip), %rcx     # 0x68558
movq (%rcx), %rdx
movq 0x45127(%rip), %rcx     # 0x68550
movq (%rcx), %rcx
cmpq %r15, %rax
jle 0x23442
movq 0x45400(%rip), %rsi     # 0x68838
movq %r12, (%rsi)
jmp 0x23445
movq %r15, %rax
jmp 0x2344c
movq %r15, %rax
movq 0x458f4(%rip), %rdi     # 0x68d40
incq %rbp
movslq 0x610(%rdi), %rsi
addq $-0x4a8, %r14           # imm = 0xFB58
addq $0x4a8, %rbx            # imm = 0x4A8
movq %rax, %r15
cmpq %rsi, %rbp
jl 0x233d4
subq %r14, 0x8(%rsp)
jmp 0x234aa
xorl %r14d, %r14d
xorl %ebp, %ebp
jmp 0x23494
leaq (%r15,%rbx), %rax
addq $-0x4a8, %rax           # imm = 0xFB58
movq 0x10(%rsp), %r14
movq 0x453a4(%rip), %rbx     # 0x68838
movq %rax, 0x8(%rsp)
movq 0x450b0(%rip), %rax     # 0x68550
movq (%rax), %rcx
jmp 0x234bb
addq %rbx, 0x8(%rsp)
movq 0x18(%rsp), %rbp
movq 0x10(%rsp), %r14
movq 0x4537d(%rip), %rbx     # 0x68838
testq %rcx, %rcx
je 0x23525
leaq 0x420(%rsp), %r12
movb $0x0, (%r12)
movq 0x58(%rcx), %rax
movl 0x1100(%rax), %esi
movq %r12, %rdi
movl $0xfffffff9, %edx       # imm = 0xFFFFFFF9
callq 0x181f0
movq 0x45065(%rip), %rax     # 0x68550
movq (%rax), %rax
movl $0x2c0, %ecx            # imm = 0x2C0
addq 0x58(%rax), %rcx
leaq 0x304f0(%rip), %rdx     # 0x539ee
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 (%rbx), %rax
testq %rax, %rax
je 0x2358b
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 0x304a1(%rip), %rdx     # 0x53a05
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 0x4506e(%rip), %rax     # 0x68600
cmpq %rbp, %r14
jle 0x235d5
movq 0x20(%rax), %rbx
leaq 0x3047a(%rip), %rdi     # 0x53a1c
callq *0x48(%rax)
movss 0x2f97b(%rip), %xmm0    # 0x52f28
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
movq 0x8(%rsp), %rdi
movl $0x5, %esi
movl %eax, %edx
callq *%rbx
leaq 0x30465(%rip), %rsi     # 0x53a2d
leaq 0x20(%rsp), %rdi
movq %r14, %rdx
movq %rbp, %rcx
jmp 0x23616
movq 0x20(%rax), %rbx
movq 0x48(%rax), %rax
jge 0x2361f
leaq 0x30462(%rip), %rdi     # 0x53a48
callq *%rax
movss 0x2f938(%rip), %xmm0    # 0x52f28
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
movq 0x8(%rsp), %rdi
movl $0x5, %esi
movl %eax, %edx
callq *%rbx
leaq 0x3044d(%rip), %rsi     # 0x53a58
leaq 0x20(%rsp), %rdi
movq %rbp, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x196f0
jmp 0x2365a
leaq 0x3044d(%rip), %rdi     # 0x53a73
callq *%rax
movss 0x2f8f8(%rip), %xmm0    # 0x52f28
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
movq 0x8(%rsp), %rdi
movl $0x5, %esi
movl %eax, %edx
callq *%rbx
leaq 0x30438(%rip), %rsi     # 0x53a83
leaq 0x20(%rsp), %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x196f0
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