// File: /workspace/github_c_makefile_star2_O2/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 $0x618, %rsp            # imm = 0x618
movq 0x451ea(%rip), %rax     # 0x66838
andq $0x0, (%rax)
movq 0x44ef7(%rip), %rax     # 0x66550
andq $0x0, (%rax)
movb $0x0, 0x210(%rsp)
movl $0x4a8, %r14d           # imm = 0x4A8
xorl %r12d, %r12d
pushq $0x3
popq %rbx
xorl %r15d, %r15d
movq $0x0, 0x8(%rsp)
movq $0x0, (%rsp)
movq 0x456b4(%rip), %rax     # 0x66d40
movslq 0x610(%rax), %rcx
cmpq %rcx, %r12
jge 0x216ee
movq 0x44eb9(%rip), %rax     # 0x66558
movq (%rax), %rax
leaq (%rax,%r14), %r15
cmpl $0x0, 0x60(%rax,%r14)
je 0x216e2
movq 0x58(%rax,%r14), %rax
movl 0x1100(%rax), %eax
cmpl $0x2, %eax
je 0x216d4
cmpl $0x1, %eax
jne 0x216e2
movq %r15, %rdi
movl %ebx, %esi
callq 0x18030
addq %rax, 0x8(%rsp)
jmp 0x216e2
movq %r15, %rdi
movl %ebx, %esi
callq 0x18030
addq %rax, (%rsp)
incq %r12
addq $0x4a8, %r14            # imm = 0x4A8
jmp 0x21685
movl $0x4a8, %r12d           # imm = 0x4A8
xorl %ebx, %ebx
xorl %r14d, %r14d
movslq %ecx, %rax
cmpq %rax, %rbx
jge 0x21796
movq 0x44e4c(%rip), %rax     # 0x66558
movq (%rax), %r15
addq %r12, %r15
movq %r15, %rdi
pushq $0xd
popq %rsi
callq 0x18030
movq %rax, %rbp
movq %r15, %rdi
pushq $0x7
popq %rsi
callq 0x18030
leaq (%rax,%rax,2), %rax
leaq (%rax,%rbp,4), %rbp
movq %r15, %rdi
pushq $0xb
popq %rsi
callq 0x18030
leaq (,%rax,2), %r13
addq %rbp, %r13
movq %r15, %rdi
pushq $0x9
popq %rsi
callq 0x18030
movq %rax, %rbp
movq %r15, %rdi
pushq $0x8
popq %rsi
callq 0x18030
addq %rbp, %rax
addq %r13, %rax
cmpq %r14, %rax
jle 0x2177a
movq 0x44ddc(%rip), %rcx     # 0x66550
movq %r15, (%rcx)
movq %rax, %r14
incq %rbx
movq 0x455bc(%rip), %rax     # 0x66d40
movl 0x610(%rax), %ecx
addq $0x4a8, %r12            # imm = 0x4A8
jmp 0x216f9
movl $0x4a8, %ebx            # imm = 0x4A8
xorl %ebp, %ebp
xorl %r14d, %r14d
movq 0x44da9(%rip), %r13     # 0x66550
movslq %ecx, %rax
cmpq %rax, %rbp
jge 0x21821
movq 0x44da2(%rip), %rax     # 0x66558
movq (%rax), %r15
addq %rbx, %r15
cmpq (%r13), %r15
je 0x2180f
movq %r15, %rdi
pushq $0x4
popq %rsi
callq 0x18030
movq %rax, %r12
shlq $0x3, %r12
movq %r15, %rdi
pushq $0x9
popq %rsi
callq 0x18030
leaq (%r12,%rax,4), %r12
movq %r15, %rdi
pushq $0xa
popq %rsi
callq 0x18030
addq %r12, %rax
movq 0x45548(%rip), %rcx     # 0x66d40
movl 0x610(%rcx), %ecx
cmpq %r14, %rax
jle 0x2180f
movq 0x4502e(%rip), %rdx     # 0x66838
movq %r15, (%rdx)
jmp 0x21812
movq %r14, %rax
incq %rbp
addq $0x4a8, %rbx            # imm = 0x4A8
movq %rax, %r14
jmp 0x217a7
movq (%r13), %rax
testq %rax, %rax
je 0x21885
leaq 0x410(%rsp), %rbx
movb $0x0, (%rbx)
movq 0x58(%rax), %rax
movl 0x1100(%rax), %esi
pushq $-0x7
popq %rdx
movq %rbx, %rdi
callq 0x18210
movq (%r13), %rax
movl $0x2c0, %ecx            # imm = 0x2C0
addq 0x58(%rax), %rcx
leaq 0x2e190(%rip), %rdx     # 0x4f9ee
leaq 0x10(%rsp), %r14
movq %r14, %rdi
movl $0x200, %esi            # imm = 0x200
movq %rbx, %r8
xorl %eax, %eax
callq 0x18f30
leaq 0x210(%rsp), %rdi
movq %r14, %rsi
callq 0x19800
movq 0x44fac(%rip), %r14     # 0x66838
movq (%r14), %rax
testq %rax, %rax
je 0x218ee
leaq 0x410(%rsp), %rbx
movb $0x0, (%rbx)
movq 0x58(%rax), %rax
movl 0x1100(%rax), %esi
pushq $-0x7
popq %rdx
movq %rbx, %rdi
callq 0x18210
movq (%r14), %rax
movl $0x2c0, %ecx            # imm = 0x2C0
addq 0x58(%rax), %rcx
leaq 0x2e13e(%rip), %rdx     # 0x4fa05
leaq 0x10(%rsp), %r14
movq %r14, %rdi
movl $0x200, %esi            # imm = 0x200
movq %rbx, %r8
xorl %eax, %eax
callq 0x18f30
leaq 0x210(%rsp), %rdi
movq %r14, %rsi
callq 0x19800
movq 0x8(%rsp), %r14
movq (%rsp), %r12
movq 0x44d02(%rip), %rax     # 0x66600
cmpq %r14, %r12
jle 0x2193d
movq 0x20(%rax), %rbx
leaq 0x2e10e(%rip), %rdi     # 0x4fa1c
callq *0x48(%rax)
pushq $0x5
popq %rsi
movss 0x2d60c(%rip), %xmm0    # 0x4ef28
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
movq %r15, %rdi
movl %eax, %edx
callq *%rbx
leaq 0x2e0fd(%rip), %rsi     # 0x4fa2d
leaq 0x10(%rsp), %rdi
movq %r12, %rdx
movq %r14, %rcx
jmp 0x2197a
movq 0x20(%rax), %rbx
movq 0x48(%rax), %rax
jge 0x21983
leaq 0x2e0fa(%rip), %rdi     # 0x4fa48
callq *%rax
pushq $0x5
popq %rsi
movss 0x2d5cd(%rip), %xmm0    # 0x4ef28
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
movq %r15, %rdi
movl %eax, %edx
callq *%rbx
leaq 0x2e0e9(%rip), %rsi     # 0x4fa58
leaq 0x10(%rsp), %rdi
movq %r14, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x198c0
jmp 0x219ba
leaq 0x2e0e9(%rip), %rdi     # 0x4fa73
callq *%rax
pushq $0x5
popq %rsi
movss 0x2d591(%rip), %xmm0    # 0x4ef28
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
movq %r15, %rdi
movl %eax, %edx
callq *%rbx
leaq 0x2e0d8(%rip), %rsi     # 0x4fa83
leaq 0x10(%rsp), %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x198c0
leaq 0x210(%rsp), %rbx
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x19800
pushq $0x2
popq %rdi
movq %rbx, %rsi
callq 0x193f0
xorl %eax, %eax
callq 0x19440
addq $0x618, %rsp            # imm = 0x618
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq