// File: boczeratul[P]StarCraftGA/ga.cpp
// Function: generateChromosomeByRequest(int*)
void generateChromosomeByRequest(int* chromosome)
{
    int i, j, length = 0;
    int actionCounts[60];
    int actionAvailable[60];
    
    int actionRW[60];
    int totalRW, roll;
    
    for (i = 0; i < 60; i++)
    {
        actionCounts[i] = 0;
        actionAvailable[i] = 0;
    }
    
    while(1) {
        totalRW = 0;
        for (i = 0; i < 60; i++)
        {
            if (requests[i] == -1 || requests[i] - actionCounts[i] > 0)
            {
                actionAvailable[i] = 1;
                for (j = 0; j < 60; j++)
                {
                    if (actionDependency[i][j] && actionCounts[j] == 0)
                        actionAvailable[i] = 0;
                }
            }
            else
                actionAvailable[i] = 0;
            
            if (actionAvailable[i])
            {
                totalRW += actionProb[i];
                actionRW[i] = totalRW;
            }
            else
                actionRW[i] = totalRW;
        }
        
        roll = rand() % totalRW;
        for (i = 0; i < 60; i++)
            if (roll < actionRW[i])
            {
                chromosome[length + 1] = i;
                length++;
                actionCounts[i]++;
                break;
            }
        
        int allReqMet = 1;
        
        for (i = 0; i < 60; i++)
            if (requests[i] > actionCounts[i])
                allReqMet = 0;
        
        if (allReqMet || length == 249)
        {
            chromosome[0] = length;
            break;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x300, %rsp            # imm = 0x300
movq %rdi, -0x8(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x0, -0xc(%rbp)
cmpl $0x3c, -0xc(%rbp)
jge 0x15ac
movslq -0xc(%rbp), %rax
movl $0x0, -0x110(%rbp,%rax,4)
movslq -0xc(%rbp), %rax
movl $0x0, -0x200(%rbp,%rax,4)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x157d
jmp 0x15ae
movl $0x0, -0x2f4(%rbp)
movl $0x0, -0xc(%rbp)
cmpl $0x3c, -0xc(%rbp)
jge 0x16ca
movslq -0xc(%rbp), %rcx
leaq 0xcd7c(%rip), %rax      # 0xe350
cmpl $-0x1, (%rax,%rcx,4)
je 0x15f8
movslq -0xc(%rbp), %rcx
leaq 0xcd6b(%rip), %rax      # 0xe350
movl (%rax,%rcx,4), %eax
movslq -0xc(%rbp), %rcx
subl -0x110(%rbp,%rcx,4), %eax
cmpl $0x0, %eax
jle 0x165f
movslq -0xc(%rbp), %rax
movl $0x1, -0x200(%rbp,%rax,4)
movl $0x0, -0x10(%rbp)
cmpl $0x3c, -0x10(%rbp)
jge 0x165d
movslq -0xc(%rbp), %rcx
leaq 0xe551(%rip), %rax      # 0xfb70
imulq $0xf0, %rcx, %rcx
addq %rcx, %rax
movslq -0x10(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
je 0x1650
movslq -0x10(%rbp), %rax
cmpl $0x0, -0x110(%rbp,%rax,4)
jne 0x1650
movslq -0xc(%rbp), %rax
movl $0x0, -0x200(%rbp,%rax,4)
jmp 0x1652
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x160e
jmp 0x166e
movslq -0xc(%rbp), %rax
movl $0x0, -0x200(%rbp,%rax,4)
movslq -0xc(%rbp), %rax
cmpl $0x0, -0x200(%rbp,%rax,4)
je 0x16a9
movslq -0xc(%rbp), %rcx
leaq 0x11d29(%rip), %rax     # 0x133b0
movl (%rax,%rcx,4), %eax
addl -0x2f4(%rbp), %eax
movl %eax, -0x2f4(%rbp)
movl -0x2f4(%rbp), %ecx
movslq -0xc(%rbp), %rax
movl %ecx, -0x2f0(%rbp,%rax,4)
jmp 0x16ba
movl -0x2f4(%rbp), %ecx
movslq -0xc(%rbp), %rax
movl %ecx, -0x2f0(%rbp,%rax,4)
jmp 0x16bc
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x15bf
callq 0x1050
cltd
idivl -0x2f4(%rbp)
movl %edx, -0x2f8(%rbp)
movl $0x0, -0xc(%rbp)
cmpl $0x3c, -0xc(%rbp)
jge 0x173c
movl -0x2f8(%rbp), %eax
movslq -0xc(%rbp), %rcx
cmpl -0x2f0(%rbp,%rcx,4), %eax
jge 0x172f
movl -0xc(%rbp), %edx
movq -0x8(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movslq -0xc(%rbp), %rax
movl -0x110(%rbp,%rax,4), %ecx
addl $0x1, %ecx
movl %ecx, -0x110(%rbp,%rax,4)
jmp 0x173c
jmp 0x1731
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x16e3
movl $0x1, -0x2fc(%rbp)
movl $0x0, -0xc(%rbp)
cmpl $0x3c, -0xc(%rbp)
jge 0x1785
movslq -0xc(%rbp), %rcx
leaq 0xcbf2(%rip), %rax      # 0xe350
movl (%rax,%rcx,4), %eax
movslq -0xc(%rbp), %rcx
cmpl -0x110(%rbp,%rcx,4), %eax
jle 0x1778
movl $0x0, -0x2fc(%rbp)
jmp 0x177a
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x174d
cmpl $0x0, -0x2fc(%rbp)
jne 0x1797
cmpl $0xf9, -0x14(%rbp)
jne 0x17a2
movl -0x14(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, (%rax)
jmp 0x17a7
jmp 0x15ae
addq $0x300, %rsp            # imm = 0x300
popq %rbp
retq