// File: /workspace/github_c_makefile_star2_O3/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 $0x218, %rsp            # imm = 0x218
movq 0x45589(%rip), %rax     # 0x68da0
movss 0x4(%rax), %xmm0
addss 0x2f704(%rip), %xmm0    # 0x52f28
movss %xmm0, 0x200(%rdi)
movq 0x4526d(%rip), %rax     # 0x68aa0
cmpl $0x0, (%rax)
jne 0x23ca5
movq %rdi, %rbx
movl 0x290(%rdi), %ebp
movq 0x44f8c(%rip), %r12     # 0x687d8
movl (%r12), %ecx
cmpl $0x4, %ecx
jne 0x23893
movq 0x453a4(%rip), %rax     # 0x68c00
movl $0x0, (%rax)
testl %ebp, %ebp
jg 0x23c9f
movl $0x0, (%r12)
movq 0x44bb7(%rip), %rax     # 0x68430
movq %rax, 0x210(%rbx)
movq 0x45761(%rip), %rax     # 0x68fe8
movq $0x0, (%rax)
jmp 0x23c9f
movslq %ebp, %rax
imulq $-0x77777777, %rax, %r14 # imm = 0x88888889
shrq $0x20, %r14
addl %ebp, %r14d
movl %r14d, %edx
shrl $0x1f, %edx
sarl $0x5, %r14d
addl %edx, %r14d
leal 0x1(%r14), %edx
cmpl $0x3c, %eax
cmovll %ebp, %edx
movq 0x4533e(%rip), %rsi     # 0x68c00
movl %edx, (%rsi)
addl $-0x2, %ecx
cmpl $0x4, %ecx
ja 0x23c9f
leaq 0x300bd(%rip), %rdx     # 0x53994
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
cmpl $0xa, %ebp
jg 0x2391f
movq 0x44d14(%rip), %rcx     # 0x68600
movq 0x20(%rcx), %r14
movq 0x44e19(%rip), %rdx     # 0x68710
movq (%rdx,%rax,8), %rdi
callq *0x48(%rcx)
movss 0x2f622(%rip), %xmm0    # 0x52f28
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
movq %rbx, %rdi
movl $0x5, %esi
movl %eax, %edx
callq *%r14
movl 0x290(%rbx), %ebp
cmpl $0xe, %ebp
jle 0x23b09
cmpl $0xf, %ebp
je 0x23b22
cmpl $0x1e, %ebp
je 0x23b58
cmpl $0x3c, %ebp
jne 0x23c9f
leaq 0x301d7(%rip), %rsi     # 0x53b21
jmp 0x23c95
movq 0x44c7a(%rip), %r14     # 0x685d0
movzwl (%r14), %eax
incl %eax
movw %ax, (%r14)
cmpw $0x6, %ax
jne 0x239d5
movq 0x44beb(%rip), %rax     # 0x68558
movq (%rax), %rcx
leaq 0x4a8(%rcx), %rdi
movq 0x4549a(%rip), %r15     # 0x68e18
movswq (%r15), %rax
imulq $0x4a8, %rax, %rdx      # imm = 0x4A8
cmpl $0x0, 0x6fc(%rcx,%rdx)
jg 0x2399b
movw $0x0, (%r15)
xorl %eax, %eax
movswq %ax, %rcx
imulq $0x4a8, %rcx, %rcx      # imm = 0x4A8
cmpl $0x0, 0x254(%rdi,%rcx)
jle 0x239c9
addq %rcx, %rdi
leaq 0x30221(%rip), %rsi     # 0x53bdb
callq 0x18c40
movzwl (%r15), %eax
movl 0x290(%rbx), %ebp
incl %eax
movw %ax, (%r15)
movw $0x0, (%r14)
testl %ebp, %ebp
je 0x239e6
callq 0x18380
testl %eax, %eax
je 0x23bd1
callq 0x18080
movq 0x44d96(%rip), %rcx     # 0x68788
movq %rax, (%rcx)
movl $0x7, (%r12)
jmp 0x23c9f
movl %ebp, %eax
cmpl $0xb, %ebp
jl 0x23ad1
movq 0x44b1c(%rip), %r12     # 0x68530
movq (%r12), %rax
movss 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
movl %ebp, %eax
jbe 0x23ad9
movq %rbx, 0x8(%rsp)
movq 0x44b21(%rip), %rax     # 0x68558
movq (%rax), %rdi
movl $0x4a8, %r13d           # imm = 0x4A8
movl $0x1, %r15d
movq 0x453b3(%rip), %rbx     # 0x68e00
cmpl $0x0, 0x60(%rdi,%r13)
je 0x23a9f
movq (%rbx), %rax
movss 0x20(%rax), %xmm0
ucomiss 0x2ff2c(%rip), %xmm0    # 0x53990
jne 0x23a68
jnp 0x23a9f
addq %r13, %rdi
movl $0x3, %esi
callq 0x18030
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
movq (%rbx), %rax
ucomiss 0x20(%rax), %xmm0
movq 0x44acd(%rip), %rax     # 0x68558
movq (%rax), %rdi
jb 0x23a9f
movq 0x8(%rsp), %rax
movl $0xa, 0x290(%rax)
xorps %xmm0, %xmm0
cvtsi2ss %r15d, %xmm0
movq (%r12), %rax
movss 0x20(%rax), %xmm1
addq $0x4a8, %r13            # imm = 0x4A8
incl %r15d
ucomiss %xmm0, %xmm1
ja 0x23a4d
movq 0x8(%rsp), %rbx
movl 0x290(%rbx), %eax
movq 0x44d07(%rip), %r12     # 0x687d8
testl %eax, %eax
jle 0x23b87
imull $0xeeeeeeef, %eax, %ecx # imm = 0xEEEEEEEF
rorl $0x2, %ecx
cmpl $0x4444444, %ecx        # imm = 0x4444444
jbe 0x23bb4
cmpl $0xa, %eax
ja 0x23c9f
movq 0x44b02(%rip), %rcx     # 0x68600
movq 0x20(%rcx), %r14
movl %eax, %eax
jmp 0x23c1f
testl %ebp, %ebp
je 0x23b64
cmpl $0xa, %ebp
jne 0x23c9f
leaq 0x3009e(%rip), %rsi     # 0x53bbb
jmp 0x23c95
cmpl $0x5, (%r12)
jne 0x23c4a
leaq 0x3002d(%rip), %rsi     # 0x53b61
movl $0x2, %edi
callq 0x19270
movq 0x44abb(%rip), %rax     # 0x68600
movq 0x20(%rax), %r14
leaq 0x30036(%rip), %rdi     # 0x53b86
callq *0x48(%rax)
jmp 0x23c2d
leaq 0x2ffe2(%rip), %rsi     # 0x53b41
jmp 0x23c95
movq 0x452ad(%rip), %rax     # 0x68e18
xorl %ecx, %ecx
movw %cx, (%rax)
movq 0x44a59(%rip), %rax     # 0x685d0
movw %cx, (%rax)
movq %rbx, %rdi
callq 0x18910
jmp 0x23c9f
callq 0x19530
movl $0x4, (%r12)
movl $0x12c, 0x290(%rbx)     # imm = 0x12C
movq 0x4519b(%rip), %rax     # 0x68d40
movl $0x0, 0x624(%rax)
jmp 0x23ca5
cmpl $0x78, %ebp
jl 0x23c53
leaq 0x2fe0c(%rip), %rsi     # 0x539d0
leaq 0x10(%rsp), %rdi
movl %r14d, %edx
jmp 0x23c89
movl 0x290(%rbx), %edx
cmpl $0xf, %edx
jg 0x23c9f
leaq 0x3165d(%rip), %rsi     # 0x55244
leaq 0x10(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x196f0
movl $0x2, %edi
movq %r14, %rsi
callq 0x19270
movslq 0x290(%rbx), %rax
cmpq $0xa, %rax
jg 0x23c9f
movq 0x449e5(%rip), %rcx     # 0x68600
movq 0x20(%rcx), %r14
movq 0x44aea(%rip), %rdx     # 0x68710
movq (%rdx,%rax,8), %rdi
callq *0x48(%rcx)
movss 0x2f2f3(%rip), %xmm0    # 0x52f28
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
movq %rbx, %rdi
movl $0x5, %esi
movl %eax, %edx
callq *%r14
jmp 0x23c9f
leaq 0x2ff4a(%rip), %rsi     # 0x53b9b
jmp 0x23c95
addl $-0x3c, %ebp
cmpl $0x3b, %ebp
ja 0x23c6e
leaq 0x2ff85(%rip), %rsi     # 0x53be7
leaq 0x10(%rsp), %rdi
movl $0x1, %edx
jmp 0x23c89
movq 0x4518b(%rip), %rax     # 0x68e00
movq (%rax), %rax
cvttss2si 0x20(%rax), %edx
leaq 0x2ff80(%rip), %rsi     # 0x53c04
leaq 0x10(%rsp), %rdi
xorl %eax, %eax
callq 0x196f0
leaq 0x10(%rsp), %rsi
movl $0x2, %edi
callq 0x19270
decl 0x290(%rbx)
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq