// File: boczeratul[P]StarCraftGA/SCTools.cpp
// Function: isValidAction
int isValidAction(int action)
{
    int check;
    int requirementsMet = 1;
    validBO = 1;
    
    for (check = 1; check <= SCActionRequirements[action][0][0]; check++ )
    {
        if (SCActionRequirements[action][check][0] == 73)
        {
            if (SCActionRequirements[action][check][1] > maxsupply() - supply())
            {
                if (SCVerbose)
                    printf("Spawn more overlords!\n");
                requirementsMet = 0;
                if (numOfActions == 0)
                {
                    validBO = 0;
                }
            }
        }
        else if (SCActionRequirements[action][check][0] == 32 && SCActionRequirements[action][check][1] == 1)
        {
            if (SCState[32] == 0)
            {
                if (SCVerbose)
                    printf("No more drones to pull from gas");
                requirementsMet = 0;
                if (numOfActions == 0)
                    validBO = 0;
            }
        }
        else if (SCActionRequirements[action][check][0] >= 30 && SCActionRequirements[action][check][0] <= 41)
        {
            if (SCState[SCActionRequirements[action][check][0]] == SCState[SCActionRequirements[action][check][2]]*SCActionRequirements[action][check][1])
            {
                if (SCVerbose)
                    printf("No enough production space (%s)\n", SCStateString[SCActionRequirements[action][check][0]]);
                requirementsMet = 0;
                if (numOfActions == 0)
                    validBO = 0;
            } 
        }
        else
        {
            if (SCActionRequirements[action][check][2] == 0)
            {
                if (SCState[SCActionRequirements[action][check][0]] < SCActionRequirements[action][check][1])
                {
                    if (SCActionRequirements[action][check][0] == 0)
                    {
                        if (SCVerbose)
                            printf("We require more minerals!\n");
                        if (numOfActions == 0 && SCState[16] - SCState[32] <= 0)
                            validBO = 0;
                    }
                    else if (SCActionRequirements[action][check][0] == 1)
                    {
                        if (SCVerbose)
                            printf("We require more vespene gas!\n");
                        if (numOfActions == 0 && SCState[32] <= 0)
                            validBO = 0;
                    }
                    else
                    {
                        if (SCVerbose)
                            printf("We need %d %s(s)!\n",SCActionRequirements[action][check][1], SCStateString[SCActionRequirements[action][check][0]]);
                        if (numOfActions == 0)
                            validBO = 0;
                    }
                    requirementsMet = 0;
                }
            }
            else
            {
                if (SCState[SCActionRequirements[action][check][0]] >= SCActionRequirements[action][check][1]) {
                    if (SCVerbose)
                        printf("Too many %s(s)!\n", SCStateString[SCActionRequirements[action][check][0]]);
                    requirementsMet = 0;
                    if (numOfActions == 0)
                        validBO = 0;
                }  
            }
        }
    }

    return requirementsMet;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movl %edi, -0x4(%rbp)
movl $0x1, -0xc(%rbp)
movl $0x1, 0xfc30(%rip)      # 0x1802c
movl $0x1, -0x8(%rbp)
movl -0x8(%rbp), %eax
movslq -0x4(%rbp), %rdx
leaq 0xb08f(%rip), %rcx      # 0x134a0
imulq $0x78, %rdx, %rdx
addq %rdx, %rcx
cmpl (%rcx), %eax
jg 0x88de
movslq -0x4(%rbp), %rcx
leaq 0xb075(%rip), %rax      # 0x134a0
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
movslq -0x8(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
cmpl $0x49, (%rax)
jne 0x84b8
movslq -0x4(%rbp), %rcx
leaq 0xb053(%rip), %rax      # 0x134a0
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
movslq -0x8(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, -0x10(%rbp)
callq 0x7fc0
movl %eax, -0x14(%rbp)
callq 0x7f00
movl -0x14(%rbp), %ecx
movl %eax, %edx
movl -0x10(%rbp), %eax
subl %edx, %ecx
cmpl %ecx, %eax
jle 0x84b3
cmpl $0x0, 0x7359(%rip)      # 0xf7e0
je 0x8497
leaq 0x3472(%rip), %rdi      # 0xb902
movb $0x0, %al
callq 0x1040
movl $0x0, -0xc(%rbp)
cmpl $0x0, 0xf46b(%rip)      # 0x17910
jne 0x84b1
movl $0x0, 0xfb7b(%rip)      # 0x1802c
jmp 0x84b3
jmp 0x88ce
movslq -0x4(%rbp), %rcx
leaq 0xafdd(%rip), %rax      # 0x134a0
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
movslq -0x8(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
cmpl $0x20, (%rax)
jne 0x853e
movslq -0x4(%rbp), %rcx
leaq 0xafbb(%rip), %rax      # 0x134a0
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
movslq -0x8(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
cmpl $0x1, 0x4(%rax)
jne 0x853e
cmpl $0x0, 0x736c(%rip)      # 0xf870
jne 0x8539
cmpl $0x0, 0x72d3(%rip)      # 0xf7e0
je 0x851d
leaq 0x3403(%rip), %rdi      # 0xb919
movb $0x0, %al
callq 0x1040
movl $0x0, -0xc(%rbp)
cmpl $0x0, 0xf3e5(%rip)      # 0x17910
jne 0x8537
movl $0x0, 0xfaf5(%rip)      # 0x1802c
jmp 0x8539
jmp 0x88cc
movslq -0x4(%rbp), %rcx
leaq 0xaf57(%rip), %rax      # 0x134a0
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
movslq -0x8(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
cmpl $0x1e, (%rax)
jl 0x8667
movslq -0x4(%rbp), %rcx
leaq 0xaf31(%rip), %rax      # 0x134a0
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
movslq -0x8(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
cmpl $0x29, (%rax)
jg 0x8667
movslq -0x4(%rbp), %rcx
leaq 0xaf0b(%rip), %rax      # 0x134a0
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
movslq -0x8(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movslq (%rax), %rcx
leaq 0x723f(%rip), %rax      # 0xf7f0
movl (%rax,%rcx,4), %eax
movslq -0x4(%rbp), %rdx
leaq 0xaee1(%rip), %rcx      # 0x134a0
imulq $0x78, %rdx, %rdx
addq %rdx, %rcx
movslq -0x8(%rbp), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rcx
movslq 0x8(%rcx), %rdx
leaq 0x7214(%rip), %rcx      # 0xf7f0
movl (%rcx,%rdx,4), %ecx
movslq -0x4(%rbp), %rsi
leaq 0xaeb6(%rip), %rdx      # 0x134a0
imulq $0x78, %rsi, %rsi
addq %rsi, %rdx
movslq -0x8(%rbp), %rsi
imulq $0xc, %rsi, %rsi
addq %rsi, %rdx
imull 0x4(%rdx), %ecx
cmpl %ecx, %eax
jne 0x8662
cmpl $0x0, 0x71d5(%rip)      # 0xf7e0
je 0x8646
movslq -0x4(%rbp), %rcx
leaq 0xae88(%rip), %rax      # 0x134a0
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
movslq -0x8(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movslq (%rax), %rcx
leaq 0x72ec(%rip), %rax      # 0xf920
movq (%rax,%rcx,8), %rsi
leaq 0x32fa(%rip), %rdi      # 0xb939
movb $0x0, %al
callq 0x1040
movl $0x0, -0xc(%rbp)
cmpl $0x0, 0xf2bc(%rip)      # 0x17910
jne 0x8660
movl $0x0, 0xf9cc(%rip)      # 0x1802c
jmp 0x8662
jmp 0x88ca
movslq -0x4(%rbp), %rcx
leaq 0xae2e(%rip), %rax      # 0x134a0
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
movslq -0x8(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0x8(%rax)
jne 0x881c
movslq -0x4(%rbp), %rcx
leaq 0xae07(%rip), %rax      # 0x134a0
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
movslq -0x8(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movslq (%rax), %rcx
leaq 0x713b(%rip), %rax      # 0xf7f0
movl (%rax,%rcx,4), %eax
movslq -0x4(%rbp), %rdx
leaq 0xaddd(%rip), %rcx      # 0x134a0
imulq $0x78, %rdx, %rdx
addq %rdx, %rcx
movslq -0x8(%rbp), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x4(%rcx), %eax
jge 0x8817
movslq -0x4(%rbp), %rcx
leaq 0xadb7(%rip), %rax      # 0x134a0
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
movslq -0x8(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, (%rax)
jne 0x8740
cmpl $0x0, 0x70d9(%rip)      # 0xf7e0
je 0x8717
leaq 0x324a(%rip), %rdi      # 0xb95a
movb $0x0, %al
callq 0x1040
cmpl $0x0, 0xf1f2(%rip)      # 0x17910
jne 0x873b
movl 0x710a(%rip), %eax      # 0xf830
subl 0x7144(%rip), %eax      # 0xf870
cmpl $0x0, %eax
jg 0x873b
movl $0x0, 0xf8f1(%rip)      # 0x1802c
jmp 0x8810
movslq -0x4(%rbp), %rcx
leaq 0xad55(%rip), %rax      # 0x134a0
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
movslq -0x8(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
cmpl $0x1, (%rax)
jne 0x8797
cmpl $0x0, 0x7077(%rip)      # 0xf7e0
je 0x8779
leaq 0x3203(%rip), %rdi      # 0xb975
movb $0x0, %al
callq 0x1040
cmpl $0x0, 0xf190(%rip)      # 0x17910
jne 0x8795
cmpl $0x0, 0x70e7(%rip)      # 0xf870
jg 0x8795
movl $0x0, 0xf897(%rip)      # 0x1802c
jmp 0x880e
cmpl $0x0, 0x7042(%rip)      # 0xf7e0
je 0x87f9
movslq -0x4(%rbp), %rcx
leaq 0xacf5(%rip), %rax      # 0x134a0
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
movslq -0x8(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %esi
movslq -0x4(%rbp), %rcx
leaq 0xacd5(%rip), %rax      # 0x134a0
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
movslq -0x8(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movslq (%rax), %rcx
leaq 0x7139(%rip), %rax      # 0xf920
movq (%rax,%rcx,8), %rdx
leaq 0x31a1(%rip), %rdi      # 0xb993
movb $0x0, %al
callq 0x1040
cmpl $0x0, 0xf110(%rip)      # 0x17910
jne 0x880c
movl $0x0, 0xf820(%rip)      # 0x1802c
jmp 0x880e
jmp 0x8810
movl $0x0, -0xc(%rbp)
jmp 0x88c8
movslq -0x4(%rbp), %rcx
leaq 0xac79(%rip), %rax      # 0x134a0
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
movslq -0x8(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movslq (%rax), %rcx
leaq 0x6fad(%rip), %rax      # 0xf7f0
movl (%rax,%rcx,4), %eax
movslq -0x4(%rbp), %rdx
leaq 0xac4f(%rip), %rcx      # 0x134a0
imulq $0x78, %rdx, %rdx
addq %rdx, %rcx
movslq -0x8(%rbp), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x4(%rcx), %eax
jl 0x88c6
cmpl $0x0, 0x6f71(%rip)      # 0xf7e0
je 0x88aa
movslq -0x4(%rbp), %rcx
leaq 0xac24(%rip), %rax      # 0x134a0
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
movslq -0x8(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movslq (%rax), %rcx
leaq 0x7088(%rip), %rax      # 0xf920
movq (%rax,%rcx,8), %rsi
leaq 0x3103(%rip), %rdi      # 0xb9a6
movb $0x0, %al
callq 0x1040
movl $0x0, -0xc(%rbp)
cmpl $0x0, 0xf058(%rip)      # 0x17910
jne 0x88c4
movl $0x0, 0xf768(%rip)      # 0x1802c
jmp 0x88c6
jmp 0x88c8
jmp 0x88ca
jmp 0x88cc
jmp 0x88ce
jmp 0x88d0
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x8403
movl -0xc(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopw (%rax,%rax)