// File: /workspace/github_cpp_makefile_star2_O3/Thilotilo[P]DoaERando/BattleRandomizer.cpp
// Function: DoaERando::BattleRandomizer::RandomizeZone6(std::vector<unsigned char, std::allocator<unsigned char>>&, DoaERando::RandomNumberGenerator&)
void BattleRandomizer::RandomizeZone6(std::vector<BYTE>& generalIds, RNG& rng)
{
    // Ideally, we want to add a special consideration for the Luo battle here.  We would like
    // it to yield the Ma Chao/Ma Dai equivalents when accepting their offer at the town,  but
    // coupling that logic is beyond our scope at the moment, so we're going to fully randomize everything.
    // Note that there is no reason that Lu Bu (4F) can't trigger the recruitable flag, so no need to
    // relegate it to duplicates

    // All the other battles can be filled like normal.
    vector<int> battlesToFill = {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x4F};
    // Make sure every general goes to a relevant battle
    for (auto& id : generalIds)
    {
        int battleIndex = rng.GetRandomInt(0, battlesToFill.size() - 1);
        int battleId = battlesToFill[battleIndex];
        while (!PlaceGeneralInBattle(id, battleId))
        {
            battleIndex = ((battleIndex + 1) % battlesToFill.size());
            battleId = battlesToFill[battleIndex];
        }
    }

    // Now fill all battles with generals/rebel forces
    FillBattlesRandomly(generalIds, battlesToFill, rng);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
movups 0x17d108(%rip), %xmm0   # 0x58ca10
leaq -0xb0(%rbp), %rsi
movaps %xmm0, 0x10(%rsi)
movups 0x17d0e6(%rip), %xmm0   # 0x58ca00
movaps %xmm0, (%rsi)
movl $0x4f, 0x20(%rsi)
leaq -0x48(%rbp), %rdi
leaq -0x29(%rbp), %rcx
movl $0x9, %edx
callq 0x40ff6a
movq (%r15), %r13
movq %r15, -0x50(%rbp)
movq 0x8(%r15), %r15
cmpq %r15, %r13
je 0x40f9a2
movq -0x40(%rbp), %rdx
subq -0x48(%rbp), %rdx
shrq $0x2, %rdx
decl %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x41086c
movl %eax, %r12d
cltq
movq -0x48(%rbp), %rcx
movl (%rcx,%rax,4), %edx
movzbl (%r13), %esi
movq %r14, %rdi
callq 0x40d678
testb %al, %al
jne 0x40f99d
incl %r12d
movslq %r12d, %rax
movq -0x48(%rbp), %rcx
movq -0x40(%rbp), %rsi
subq %rcx, %rsi
sarq $0x2, %rsi
xorl %edx, %edx
divq %rsi
movq %rdx, %r12
movslq %r12d, %rax
jmp 0x40f967
incq %r13
jmp 0x40f941
leaq -0x80(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x40abb0
leaq -0x68(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x40ffa8
leaq -0x80(%rbp), %rsi
leaq -0x68(%rbp), %rdx
movq %r14, %rdi
movq %rbx, %rcx
callq 0x40d6d4
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0x40f9dd
callq 0x410b90
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x40f9eb
callq 0x410b90
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x40f9f9
callq 0x410b90
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0x40fa21
callq 0x410b90
jmp 0x40fa21
movq %rax, %rbx
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x40fa36
callq 0x410b90
jmp 0x40fa36
jmp 0x40fa33
movq %rax, %rbx
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x40fa44
callq 0x410b90
movq %rbx, %rdi
callq 0x4bb660