// File: /workspace/github_cpp_makefile_star2_O3/Thilotilo[P]DoaERando/BattleRandomizer.cpp
// Function: DoaERando::BattleRandomizer::RandomizeZone3(DoaERando::Generals&, DoaERando::RandomNumberGenerator&)
void BattleRandomizer::RandomizeZone3(Generals& generals, RNG& rng)
{
    // We may want to add special logic to handle Yuan Shu's assassination/joining of
    // Yuan Shao in Ji Zhou, but for now, we're just ignoring that.  There are no
    // special considerations in this zone.

    std::vector<BYTE> generalIds = generals.GetGeneralIdsFromZone(3);

    vector<int> battlesToFill = {0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13};
    // 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 %rdi, %r14
leaq -0x80(%rbp), %rdi
movl $0x3, %edx
callq 0x40cf22
movups 0x17eacb(%rip), %xmm0   # 0x58c9b4
leaq -0xb0(%rbp), %rsi
movaps %xmm0, (%rsi)
movabsq $0x1300000012, %rax     # imm = 0x1300000012
movq %rax, 0x10(%rsi)
leaq -0x68(%rbp), %rdi
leaq -0x29(%rbp), %rcx
movl $0x6, %edx
callq 0x40ff6a
movq -0x80(%rbp), %r12
movq -0x78(%rbp), %r13
cmpq %r13, %r12
je 0x40dfd6
movq -0x60(%rbp), %rdx
subq -0x68(%rbp), %rdx
shrq $0x2, %rdx
decl %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x41086c
movl %eax, %r15d
cltq
movq -0x68(%rbp), %rcx
movl (%rcx,%rax,4), %edx
movzbl (%r12), %esi
movq %r14, %rdi
callq 0x40d678
testb %al, %al
jne 0x40df7b
incl %r15d
movslq %r15d, %rax
movq -0x68(%rbp), %rcx
movq -0x60(%rbp), %rsi
subq %rcx, %rsi
sarq $0x2, %rsi
xorl %edx, %edx
divq %rsi
movq %rdx, %r15
movslq %r15d, %rax
jmp 0x40df45
incq %r12
cmpq %r13, %r12
jne 0x40df24
movq -0x78(%rbp), %r15
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
movq $0x0, -0x40(%rbp)
subq -0x80(%rbp), %r15
je 0x40dfd9
js 0x40e064
movq %r15, %rdi
callq 0x411fc0
movq %rax, %r12
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %r13
movq %rax, -0x50(%rbp)
movq %rax, -0x48(%rbp)
addq %rax, %r15
movq %r15, -0x40(%rbp)
subq %rsi, %r13
je 0x40dfea
movq %r12, %rdi
movq %r13, %rdx
callq 0x401020
jmp 0x40dfea
xorl %r15d, %r15d
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
movq %r15, -0x40(%rbp)
xorl %r13d, %r13d
xorl %r12d, %r12d
addq %r12, %r13
movq %r13, -0x48(%rbp)
leaq -0x98(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x40ffa8
leaq -0x50(%rbp), %rsi
leaq -0x98(%rbp), %rdx
movq %r14, %rdi
movq %rbx, %rcx
callq 0x40d6d4
movq -0x98(%rbp), %rdi
testq %rdi, %rdi
je 0x40e028
callq 0x410b90
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x40e036
callq 0x410b90
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0x40e044
callq 0x410b90
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x40e052
callq 0x410b90
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x402684
movq %rax, %rbx
movq -0x98(%rbp), %rdi
testq %rdi, %rdi
je 0x40e082
callq 0x410b90
jmp 0x40e082
movq %rax, %rbx
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x40e09c
callq 0x410b90
jmp 0x40e09c
movq %rax, %rbx
jmp 0x40e0aa
jmp 0x40e099
movq %rax, %rbx
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0x40e0aa
callq 0x410b90
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x40e0b8
callq 0x410b90
movq %rbx, %rdi
callq 0x4bb660