// File: boczeratul[P]StarCraftGA/SCTools.cpp
// Function: oneSecInSCNonStop
int oneSecInSCNonStop()
{
    ++SCGameTime;
    
    int action = -1;
    //printf("\n================= Time %d ================\n",SCGameTime);

    //printf("%d ongoing actions:\n",numOfActions);
    int i;
    for (i = numOfActions - 1; i >= 0; i--)
    {
        Actions[i][1]--;
        if (Actions[i][1] == 0)
        {
            numOfActions--;
            //printf("%s: Done!\n", SCActionString[Actions[i][0]]);
            finishAction(Actions[i][0]);
        }
        else
        {
            //printf("%s: %d seconds remained\n", SCActionString[Actions[i][0]], Actions[i][1]);
        }
    }

    getResources();
    //showInformation();
    
    if (SCBuildOrderPointer <= SCBuildOrder[0])
    {
        action = SCBuildOrder[SCBuildOrderPointer];
        //printf("New action: %d\n", action);
    }
    
    while (action >= 0)
    {
        //printf("    ==> %s\n", SCActionString[action]);
        if (isValidAction(action))
        {
            //printf("action accepted: %d!\n", action);
            performAction(action);

            int insert = numOfActions;
            for (i = 0; i < numOfActions; i++)
                if (SCActionTime[action] > Actions[i][1])
                {
                    insert = i;
                    break;
                }

            for (i = numOfActions; i > insert; i--)
            {
                Actions[i][0] = Actions[i-1][0];
                Actions[i][1] = Actions[i-1][1];
            }

            Actions[insert][0] = action;
            Actions[insert][1] = SCActionTime[action];

            numOfActions++;
            SCBuildOrderPointer++;
        }
        else
            break;

        if (SCBuildOrderPointer <= SCBuildOrder[0])
        {
            action = SCBuildOrder[SCBuildOrderPointer];
        }
        else
        {
            action = -1;
            break;
        }
    }
    
    if (!validBO)
        return 0;
    
    if (SCBuildOrderPointer > SCBuildOrder[0] && numOfActions == 0)
        return 0;
    else 
        return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movl 0x6e66(%rip), %eax      # 0xf7e4
addl $0x1, %eax
movl %eax, 0x6e5d(%rip)      # 0xf7e4
movl $0xffffffff, -0x8(%rbp) # imm = 0xFFFFFFFF
movl 0xef7c(%rip), %eax      # 0x17910
subl $0x1, %eax
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jl 0x8a02
movslq -0xc(%rbp), %rcx
leaq 0xef75(%rip), %rax      # 0x17920
movl 0x4(%rax,%rcx,8), %edx
addl $-0x1, %edx
leaq 0xef67(%rip), %rax      # 0x17920
movl %edx, 0x4(%rax,%rcx,8)
movslq -0xc(%rbp), %rcx
leaq 0xef58(%rip), %rax      # 0x17920
cmpl $0x0, 0x4(%rax,%rcx,8)
jne 0x89f3
movl 0xef3b(%rip), %eax      # 0x17910
addl $-0x1, %eax
movl %eax, 0xef32(%rip)      # 0x17910
movslq -0xc(%rbp), %rcx
leaq 0xef37(%rip), %rax      # 0x17920
movl (%rax,%rcx,8), %edi
callq 0x8360
jmp 0x89f5
jmp 0x89f5
jmp 0x89f7
movl -0xc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x899a
callq 0x7de0
movl 0xf61b(%rip), %eax      # 0x18028
cmpl 0xf22d(%rip), %eax      # 0x17c40
jg 0x8a29
movslq 0xf60c(%rip), %rcx      # 0x18028
leaq 0xf21d(%rip), %rax      # 0x17c40
movl (%rax,%rcx,4), %eax
movl %eax, -0x8(%rbp)
jmp 0x8a2b
cmpl $0x0, -0x8(%rbp)
jl 0x8b7f
movl -0x8(%rbp), %edi
callq 0x83e0
cmpl $0x0, %eax
je 0x8b4b
movl -0x8(%rbp), %edi
callq 0x88f0
movl 0xeebc(%rip), %eax      # 0x17910
movl %eax, -0x10(%rbp)
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
cmpl 0xeea9(%rip), %eax      # 0x17910
jge 0x8a9d
movslq -0x8(%rbp), %rcx
leaq 0xebcc(%rip), %rax      # 0x17640
movl (%rax,%rcx,4), %eax
movslq -0xc(%rbp), %rdx
leaq 0xee9e(%rip), %rcx      # 0x17920
cmpl 0x4(%rcx,%rdx,8), %eax
jle 0x8a90
movl -0xc(%rbp), %eax
movl %eax, -0x10(%rbp)
jmp 0x8a9d
jmp 0x8a92
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x8a5e
movl 0xee6d(%rip), %eax      # 0x17910
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
cmpl -0x10(%rbp), %eax
jle 0x8afd
movl -0xc(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rcx
leaq 0xee62(%rip), %rax      # 0x17920
movl (%rax,%rcx,8), %edx
movslq -0xc(%rbp), %rcx
leaq 0xee54(%rip), %rax      # 0x17920
movl %edx, (%rax,%rcx,8)
movl -0xc(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rcx
leaq 0xee41(%rip), %rax      # 0x17920
movl 0x4(%rax,%rcx,8), %edx
movslq -0xc(%rbp), %rcx
leaq 0xee32(%rip), %rax      # 0x17920
movl %edx, 0x4(%rax,%rcx,8)
movl -0xc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x8aa6
movl -0x8(%rbp), %edx
movslq -0x10(%rbp), %rcx
leaq 0xee15(%rip), %rax      # 0x17920
movl %edx, (%rax,%rcx,8)
movslq -0x8(%rbp), %rcx
leaq 0xeb27(%rip), %rax      # 0x17640
movl (%rax,%rcx,4), %edx
movslq -0x10(%rbp), %rcx
leaq 0xedf9(%rip), %rax      # 0x17920
movl %edx, 0x4(%rax,%rcx,8)
movl 0xeddf(%rip), %eax      # 0x17910
addl $0x1, %eax
movl %eax, 0xedd6(%rip)      # 0x17910
movl 0xf4e8(%rip), %eax      # 0x18028
addl $0x1, %eax
movl %eax, 0xf4df(%rip)      # 0x18028
jmp 0x8b4d
jmp 0x8b7f
movl 0xf4d5(%rip), %eax      # 0x18028
cmpl 0xf0e7(%rip), %eax      # 0x17c40
jg 0x8b71
movslq 0xf4c6(%rip), %rcx      # 0x18028
leaq 0xf0d7(%rip), %rax      # 0x17c40
movl (%rax,%rcx,4), %eax
movl %eax, -0x8(%rbp)
jmp 0x8b7a
movl $0xffffffff, -0x8(%rbp) # imm = 0xFFFFFFFF
jmp 0x8b7f
jmp 0x8a2b
cmpl $0x0, 0xf4a6(%rip)      # 0x1802c
jne 0x8b91
movl $0x0, -0x4(%rbp)
jmp 0x8bb8
movl 0xf491(%rip), %eax      # 0x18028
cmpl 0xf0a3(%rip), %eax      # 0x17c40
jle 0x8bb1
cmpl $0x0, 0xed6a(%rip)      # 0x17910
jne 0x8bb1
movl $0x0, -0x4(%rbp)
jmp 0x8bb8
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x10, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)