// File: boczeratul[P]StarCraftGA/SCTools.cpp
// Function: oneSecInSCDemo
int oneSecInSCDemo()
{
    ++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("@%02d:%02d %s\n", SCGameTime/60, SCGameTime%60, SCActionString[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 0x6c06(%rip), %eax      # 0xf7e4
addl $0x1, %eax
movl %eax, 0x6bfd(%rip)      # 0xf7e4
movl $0xffffffff, -0x8(%rbp) # imm = 0xFFFFFFFF
movl 0xed1c(%rip), %eax      # 0x17910
subl $0x1, %eax
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jl 0x8c62
movslq -0xc(%rbp), %rcx
leaq 0xed15(%rip), %rax      # 0x17920
movl 0x4(%rax,%rcx,8), %edx
addl $-0x1, %edx
leaq 0xed07(%rip), %rax      # 0x17920
movl %edx, 0x4(%rax,%rcx,8)
movslq -0xc(%rbp), %rcx
leaq 0xecf8(%rip), %rax      # 0x17920
cmpl $0x0, 0x4(%rax,%rcx,8)
jne 0x8c53
movl 0xecdb(%rip), %eax      # 0x17910
addl $-0x1, %eax
movl %eax, 0xecd2(%rip)      # 0x17910
movslq -0xc(%rbp), %rcx
leaq 0xecd7(%rip), %rax      # 0x17920
movl (%rax,%rcx,8), %edi
callq 0x8360
jmp 0x8c55
jmp 0x8c55
jmp 0x8c57
movl -0xc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x8bfa
callq 0x7de0
movl 0xf3bb(%rip), %eax      # 0x18028
cmpl 0xefcd(%rip), %eax      # 0x17c40
jg 0x8c89
movslq 0xf3ac(%rip), %rcx      # 0x18028
leaq 0xefbd(%rip), %rax      # 0x17c40
movl (%rax,%rcx,4), %eax
movl %eax, -0x8(%rbp)
jmp 0x8c8b
cmpl $0x0, -0x8(%rbp)
jl 0x8e1a
movl -0x8(%rbp), %edi
callq 0x83e0
cmpl $0x0, %eax
je 0x8de6
movl 0x6b38(%rip), %eax      # 0xf7e4
movl $0x3c, %ecx
cltd
idivl %ecx
movl %eax, %esi
movl 0x6b28(%rip), %eax      # 0xf7e4
movl $0x3c, %ecx
cltd
idivl %ecx
movslq -0x8(%rbp), %rcx
leaq 0xea61(%rip), %rax      # 0x17730
movq (%rax,%rcx,8), %rcx
leaq 0x2bbd(%rip), %rdi      # 0xb897
movb $0x0, %al
callq 0x1040
movl -0x8(%rbp), %edi
callq 0x88f0
movl 0xec21(%rip), %eax      # 0x17910
movl %eax, -0x10(%rbp)
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
cmpl 0xec0e(%rip), %eax      # 0x17910
jge 0x8d38
movslq -0x8(%rbp), %rcx
leaq 0xe931(%rip), %rax      # 0x17640
movl (%rax,%rcx,4), %eax
movslq -0xc(%rbp), %rdx
leaq 0xec03(%rip), %rcx      # 0x17920
cmpl 0x4(%rcx,%rdx,8), %eax
jle 0x8d2b
movl -0xc(%rbp), %eax
movl %eax, -0x10(%rbp)
jmp 0x8d38
jmp 0x8d2d
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x8cf9
movl 0xebd2(%rip), %eax      # 0x17910
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
cmpl -0x10(%rbp), %eax
jle 0x8d98
movl -0xc(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rcx
leaq 0xebc7(%rip), %rax      # 0x17920
movl (%rax,%rcx,8), %edx
movslq -0xc(%rbp), %rcx
leaq 0xebb9(%rip), %rax      # 0x17920
movl %edx, (%rax,%rcx,8)
movl -0xc(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rcx
leaq 0xeba6(%rip), %rax      # 0x17920
movl 0x4(%rax,%rcx,8), %edx
movslq -0xc(%rbp), %rcx
leaq 0xeb97(%rip), %rax      # 0x17920
movl %edx, 0x4(%rax,%rcx,8)
movl -0xc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x8d41
movl -0x8(%rbp), %edx
movslq -0x10(%rbp), %rcx
leaq 0xeb7a(%rip), %rax      # 0x17920
movl %edx, (%rax,%rcx,8)
movslq -0x8(%rbp), %rcx
leaq 0xe88c(%rip), %rax      # 0x17640
movl (%rax,%rcx,4), %edx
movslq -0x10(%rbp), %rcx
leaq 0xeb5e(%rip), %rax      # 0x17920
movl %edx, 0x4(%rax,%rcx,8)
movl 0xeb44(%rip), %eax      # 0x17910
addl $0x1, %eax
movl %eax, 0xeb3b(%rip)      # 0x17910
movl 0xf24d(%rip), %eax      # 0x18028
addl $0x1, %eax
movl %eax, 0xf244(%rip)      # 0x18028
jmp 0x8de8
jmp 0x8e1a
movl 0xf23a(%rip), %eax      # 0x18028
cmpl 0xee4c(%rip), %eax      # 0x17c40
jg 0x8e0c
movslq 0xf22b(%rip), %rcx      # 0x18028
leaq 0xee3c(%rip), %rax      # 0x17c40
movl (%rax,%rcx,4), %eax
movl %eax, -0x8(%rbp)
jmp 0x8e15
movl $0xffffffff, -0x8(%rbp) # imm = 0xFFFFFFFF
jmp 0x8e1a
jmp 0x8c8b
cmpl $0x0, 0xf20b(%rip)      # 0x1802c
jne 0x8e2c
movl $0x0, -0x4(%rbp)
jmp 0x8e53
movl 0xf1f6(%rip), %eax      # 0x18028
cmpl 0xee08(%rip), %eax      # 0x17c40
jle 0x8e4c
cmpl $0x0, 0xeacf(%rip)      # 0x17910
jne 0x8e4c
movl $0x0, -0x4(%rbp)
jmp 0x8e53
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x10, %rsp
popq %rbp
retq
nopl (%rax)