// File: /workspace/github_c_makefile_star2_O1/QwazyWabbitWOS[P]lmctf60/g_tourney.c
// Function: Tourney_Think
void Tourney_Think(edict_t *ent)
{
    int     minutes;
    edict_t *player;
    int     i;
    char    message[MAX_INFO_STRING];

    ent->nextthink = level.time + 1;

    // If game paused, don't keep counting down
    if (GamePaused()) {
        return;
    }

    minutes = ent->count/60;

    if (matchstate == MATCH_OVER) {
        Time_Left = 0;
    } else if (ent->count < 60) {
        Time_Left = ent->count;
    } else {
        Time_Left = minutes + 1;
    }


    if (matchstate == MATCH_COUNTDOWN || matchstate == MATCH_RAILGUN_COUNTDOWN) {
        if(ent->count <= 10) {
            gi.sound (ent, CHAN_CTF, gi.soundindex (CTF_Countdown_Table[ent->count]), 1, ATTN_NONE, 0);
        }

        switch (ent->count) {
        case 60:
            ctf_BSafePrint(PRINT_HIGH, "60 seconds until match begins.\n");
            break;
        case 30:
            ctf_BSafePrint(PRINT_HIGH, "30 seconds until match begins.\n");
            break;
        case 15:
            if (matchstate == MATCH_RAILGUN_COUNTDOWN) {
                ctf_BSafePrint(PRINT_HIGH, "Prepare to annihilate your enemy...\n");

                gi.sound(ent, CHAN_CTF, gi.soundindex ("weapons/bfg__l1a.wav"), 1, ATTN_NONE, 0);
            } else {
                ctf_BSafePrint(PRINT_HIGH, "15 seconds until match begins.\n");
            }
            break;
        case 10:
            ctf_BSafePrint(PRINT_HIGH, "10 seconds until match begins.\n");
            break;
        case 0:
        //    gi.sound (ent, CHAN_CTF, gi.soundindex ("ctf/go.wav"), 1, ATTN_NONE, 0);
            Last_Guy = 0;
            Position_Count = 0;
            Match_Start(ent);
            break;
        }
    } else if (matchstate == MATCH_RAILGUN_INPLAY) {
        edict_t *cl_ent;

        if (++Position_Count == 6) {
            cl_ent = g_edicts + 1 + Last_Guy;

            while (cl_ent->health <= 0) {
                Last_Guy++;

                if (Last_Guy == game.maxclients) {
                    Last_Guy = 0;
                    break;
                }
            }

            cl_ent = g_edicts + 1 + Last_Guy;

            if(cl_ent->health > 0) {
                ForceCommand(cl_ent, "say I am %p");
            }

            Last_Guy++;
            Position_Count = 0;
        }


        if (ent->count == 0 || One_Man_Left()) {
            Railgun_Victor = Declare_Railgun_Victor();
            matchstate = MATCH_RAILGUN_OVER;
        } else if(ent->count <= 15) {
            sprintf(message, "%d\n", ent->count);
            ctf_BSafePrint(PRINT_HIGH, message);

            if (ent->count <= 10) {
                gi.sound (ent, CHAN_CTF, gi.soundindex (CTF_Countdown_Table[ent->count]), 1, ATTN_NONE, 0);
            }
        }

    } else if (matchstate == MATCH_INPLAY) {
        // Start the countdown if we hit the fraglimit
        if (ent->count > 10) {
            for (i=0 ; i<maxclients->value ; i++) {
                player = g_edicts + 1 + i;
                if (!player->inuse) {
                    continue;
                }

                if (fraglimit->value && stats_get(player, STATS_SCORE) >= fraglimit->value) {
                    // Fraglimit was hit
                    ent->count = 10;
                }
            }
        }

        if (ent->count <= 0) { // End match
            Match_End(ent);
            return;
        } else if (!(ent->count % 60)) {
            if (minutes > 1) {
                sprintf(message, "%d minutes until match ends.\n", minutes);
            } else if (minutes == 1) {
                sprintf(message, "%d minute until match ends.\n", minutes);
            } else {
                sprintf(message, "%d frags until match ends.\n", (int)fraglimit->value);
            }
            ctf_BSafePrint(PRINT_HIGH, message);
        } else if(ent->count <= 10) {
            gi.sound (ent, CHAN_CTF, gi.soundindex (CTF_Countdown_Table[ent->count]), 1, ATTN_NONE, 0);
        }
    } else if (matchstate == MATCH_OVER) {
        if (ent->count <= 0) {
            matchstate = MATCH_NONE;
            ent->think = G_FreeEdict;
            tourneyclock = NULL;
        }
    }

    ent->count--;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x228, %rsp            # imm = 0x228
movq 0x4649f(%rip), %rax     # 0x69da0
movss 0x4(%rax), %xmm0
addss 0x3061a(%rip), %xmm0    # 0x53f28
movss %xmm0, 0x200(%rdi)
movq 0x46183(%rip), %rax     # 0x69aa0
cmpl $0x0, (%rax)
jne 0x23d65
movq %rdi, %rbx
movslq 0x290(%rdi), %rdi
imulq $-0x77777777, %rdi, %r14 # imm = 0x88888889
shrq $0x20, %r14
addl %edi, %r14d
movl %r14d, %esi
shrl $0x1f, %esi
sarl $0x5, %r14d
cmpq $0x3c, %rdi
movq 0x45e85(%rip), %rbp     # 0x697d8
movl (%rbp), %eax
leal 0x1(%r14,%rsi), %ecx
cmovll %edi, %ecx
xorl %edx, %edx
cmpl $0x4, %eax
cmovnel %ecx, %edx
movq 0x46293(%rip), %rcx     # 0x69c00
movl %edx, (%rcx)
addl $-0x2, %eax
cmpl $0x4, %eax
ja 0x23d5f
leaq 0x30fe2(%rip), %rcx     # 0x54964
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpl $0xa, %edi
jg 0x239c4
movq 0x45c69(%rip), %rax     # 0x69600
movq 0x20(%rax), %r14
movq 0x45d6e(%rip), %rcx     # 0x69710
movq (%rcx,%rdi,8), %rdi
callq *0x48(%rax)
movss 0x30577(%rip), %xmm0    # 0x53f28
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
movq %rbx, %rdi
movl $0x5, %esi
movl %eax, %edx
callq *%r14
movl 0x290(%rbx), %eax
cmpl $0xe, %eax
jle 0x23bbe
cmpl $0xf, %eax
je 0x23c0d
cmpl $0x1e, %eax
je 0x23c42
cmpl $0x3c, %eax
jne 0x23d5f
leaq 0x310fc(%rip), %rsi     # 0x54af1
jmp 0x23d55
movq 0x45bcf(%rip), %r14     # 0x695d0
movzwl (%r14), %eax
incl %eax
movw %ax, (%r14)
cmpw $0x6, %ax
jne 0x23a72
movq 0x45b40(%rip), %rax     # 0x69558
movq (%rax), %rax
leaq 0x4a8(%rax), %rdi
movq 0x463ef(%rip), %r15     # 0x69e18
movswq (%r15), %rcx
imulq $0x4a8, %rcx, %rcx      # imm = 0x4A8
cmpl $0x0, 0x6fc(%rax,%rcx)
jg 0x23a44
movw $0x0, (%r15)
movswq (%r15), %rax
imulq $0x4a8, %rax, %rax      # imm = 0x4A8
cmpl $0x0, 0x254(%rdi,%rax)
jle 0x23a68
addq %rax, %rdi
leaq 0x31148(%rip), %rsi     # 0x54bab
callq 0x18c40
incw (%r15)
movw $0x0, (%r14)
cmpl $0x0, 0x290(%rbx)
je 0x23a88
callq 0x18380
testl %eax, %eax
je 0x23c71
callq 0x18080
movq 0x45cf4(%rip), %rcx     # 0x69788
movq %rax, (%rcx)
movl $0x7, (%rbp)
jmp 0x23d5f
movq %rsi, 0x10(%rsp)
movq %rbx, 0x8(%rsp)
movq %rdi, 0x18(%rsp)
cmpl $0xb, %edi
jl 0x23b5a
movq 0x45a6e(%rip), %rbx     # 0x69530
movq (%rbx), %rax
movss 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x23b5a
movl $0x4a8, %r15d           # imm = 0x4A8
movl $0x1, %ebp
movq 0x45a70(%rip), %r13     # 0x69558
movq 0x46311(%rip), %r12     # 0x69e00
movq (%r13), %rdi
cmpl $0x0, 0x60(%rdi,%r15)
je 0x23b3d
movq (%r12), %rax
movss 0x20(%rax), %xmm0
ucomiss 0x30e55(%rip), %xmm0    # 0x54960
jne 0x23b0f
jnp 0x23b3d
addq %r15, %rdi
movl $0x3, %esi
callq 0x18030
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
movq (%r12), %rax
ucomiss 0x20(%rax), %xmm0
jb 0x23b3d
movq 0x8(%rsp), %rax
movl $0xa, 0x290(%rax)
xorps %xmm0, %xmm0
cvtsi2ss %ebp, %xmm0
movq (%rbx), %rax
movss 0x20(%rax), %xmm1
addq $0x4a8, %r15            # imm = 0x4A8
incl %ebp
ucomiss %xmm0, %xmm1
ja 0x23aef
movq 0x8(%rsp), %rbx
movslq 0x290(%rbx), %rax
testq %rax, %rax
jle 0x23bdb
imull $0xeeeeeeef, %eax, %ecx # imm = 0xEEEEEEEF
rorl $0x2, %ecx
cmpl $0x4444444, %ecx        # imm = 0x4444444
jbe 0x23cea
cmpl $0xa, %eax
jle 0x23cb4
jmp 0x23d5f
testl %edi, %edi
jg 0x23d5f
movl $0x0, (%rbp)
movq 0x4588c(%rip), %rax     # 0x69430
movq %rax, 0x210(%rbx)
movq 0x46436(%rip), %rax     # 0x69fe8
movq $0x0, (%rax)
jmp 0x23d5f
testl %eax, %eax
je 0x23c4e
cmpl $0xa, %eax
jne 0x23d5f
leaq 0x30fb5(%rip), %rsi     # 0x54b8b
jmp 0x23d55
callq 0x19530
movq 0x45bf1(%rip), %rax     # 0x697d8
movl $0x4, (%rax)
movl $0x12c, 0x290(%rbx)     # imm = 0x12C
movq 0x46142(%rip), %rax     # 0x69d40
movl $0x0, 0x624(%rax)
jmp 0x23d65
cmpl $0x5, (%rbp)
jne 0x23d0a
leaq 0x30f13(%rip), %rsi     # 0x54b31
movl $0x2, %edi
callq 0x19270
movq 0x459d1(%rip), %rax     # 0x69600
movq 0x20(%rax), %r14
leaq 0x30f1c(%rip), %rdi     # 0x54b56
callq *0x48(%rax)
jmp 0x23ccd
leaq 0x30ec8(%rip), %rsi     # 0x54b11
jmp 0x23d55
movq 0x461c3(%rip), %rax     # 0x69e18
xorl %ecx, %ecx
movw %cx, (%rax)
movq 0x4596f(%rip), %rax     # 0x695d0
movw %cx, (%rax)
movq %rbx, %rdi
callq 0x18910
jmp 0x23d5f
movl 0x290(%rbx), %edx
cmpl $0xf, %edx
jg 0x23d5f
leaq 0x3259d(%rip), %rsi     # 0x56224
leaq 0x20(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x19700
movl $0x2, %edi
movq %r14, %rsi
callq 0x19270
movslq 0x290(%rbx), %rax
cmpq $0xa, %rax
jg 0x23d5f
movq 0x45945(%rip), %rcx     # 0x69600
movq 0x20(%rcx), %r14
movq 0x45a4a(%rip), %rdx     # 0x69710
movq (%rdx,%rax,8), %rdi
callq *0x48(%rcx)
movss 0x30253(%rip), %xmm0    # 0x53f28
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
movq %rbx, %rdi
movl $0x5, %esi
movl %eax, %edx
callq *%r14
jmp 0x23d5f
movq 0x18(%rsp), %rax
cmpl $0x78, %eax
jl 0x23d13
addl 0x10(%rsp), %r14d
leaq 0x30ca0(%rip), %rsi     # 0x549a0
leaq 0x20(%rsp), %rdi
movl %r14d, %edx
jmp 0x23d49
leaq 0x30e5a(%rip), %rsi     # 0x54b6b
jmp 0x23d55
addl $-0x3c, %eax
cmpl $0x3b, %eax
ja 0x23d2e
leaq 0x30e95(%rip), %rsi     # 0x54bb7
leaq 0x20(%rsp), %rdi
movl $0x1, %edx
jmp 0x23d49
movq 0x460cb(%rip), %rax     # 0x69e00
movq (%rax), %rax
cvttss2si 0x20(%rax), %edx
leaq 0x30e90(%rip), %rsi     # 0x54bd4
leaq 0x20(%rsp), %rdi
xorl %eax, %eax
callq 0x19700
leaq 0x20(%rsp), %rsi
movl $0x2, %edi
callq 0x19270
decl 0x290(%rbx)
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq