// File: /workspace/github_cpp_makefile_star2_O2/Thilotilo[P]DoaERando/Randomizer.cpp
// Function: DoaERando::Randomizer::RandomizeStartingGenerals()
void Randomizer::RandomizeStartingGenerals()
{
    printf("Randomizing Starting Generals...\n");

    std::vector<BYTE> startingGenerals;
    startingGenerals.push_back(0xA8);

    BYTE general1;
    do {
        general1 = myRNG.GetRandomByte(0x05, 0xD7);
    } while (general1 == 0xB3 || general1 == 0xA6 || general1 == 0xA7 || general1 == 0xA8);
    printf("Setting ");
    PrintName(general1);
    printf(" as a starting general\n");
    myRom->WriteByte(0x35558, general1);
    startingGenerals.push_back(general1);

    BYTE general2;
    do {
        general2 = myRNG.GetRandomByte(0x05, 0xD7);
    } while (general2 == 0xB3 || general2 == 0xA6 || general2 == 0xA7 || general2 == 0xA8 || general2 == general1);
    printf("Setting ");
    PrintName(general2);
    printf(" as a starting general\n");
    myRom->WriteByte(0x35559, general2);
    startingGenerals.push_back(general2);

    myGenerals.SetStartingGenerals(startingGenerals);

    // Set Starting generals to 0xCO
    // This uses the instructions from the ImproveInitialBattlesAndFlags method and places the
    // general IDs for the starting generals in the appropriate bytes.
    myRom->WriteByte(0x35434, general1);
    myRom->WriteByte(0x35437, general2);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
leaq 0x1862e5(%rip), %rdi    # 0x58b236
callq 0x4e8680
leaq -0x50(%rbp), %rdi
andq $0x0, 0x10(%rdi)
xorps %xmm0, %xmm0
movaps %xmm0, (%rdi)
leaq -0x29(%rbp), %rsi
movb $-0x58, (%rsi)
callq 0x409faa
leaq 0x8(%rbx), %r14
pushq $0x5
popq %r12
movl $0x2007, %r13d          # imm = 0x2007
movq %r14, %rdi
movl %r12d, %esi
movl $0xd7, %edx
callq 0x40ed6a
movb %al, -0x29(%rbp)
movzbl %al, %r15d
leal -0xa6(%r15), %eax
cmpl $0xd, %eax
ja 0x404fa8
btl %eax, %r13d
jb 0x404f7f
leaq 0x186141(%rip), %rdi    # 0x58b0f0
xorl %eax, %eax
callq 0x4e1140
movq %rbx, %rdi
movl %r15d, %esi
callq 0x404eae
leaq 0x186379(%rip), %rdi    # 0x58b341
callq 0x4e8680
movq (%rbx), %rdi
movl $0x35558, %esi          # imm = 0x35558
movl %r15d, %edx
callq 0x404a00
leaq -0x50(%rbp), %rdi
leaq -0x29(%rbp), %rsi
callq 0x409c42
pushq $0x5
popq %r12
movl $0x2007, %r13d          # imm = 0x2007
movq %r14, %rdi
movl %r12d, %esi
movl $0xd7, %edx
callq 0x40ed6a
movb %al, -0x2a(%rbp)
movzbl %al, %r15d
leal -0xa6(%r15), %ecx
cmpl $0xd, %ecx
ja 0x40501d
btl %ecx, %r13d
jb 0x404ff4
cmpb -0x29(%rbp), %al
je 0x404ff4
leaq 0x1860c7(%rip), %rdi    # 0x58b0f0
xorl %eax, %eax
callq 0x4e1140
movq %rbx, %rdi
movl %r15d, %esi
callq 0x404eae
leaq 0x1862ff(%rip), %rdi    # 0x58b341
callq 0x4e8680
movq (%rbx), %rdi
movl $0x35559, %esi          # imm = 0x35559
movl %r15d, %edx
callq 0x404a00
leaq -0x50(%rbp), %rdi
leaq -0x2a(%rbp), %rsi
callq 0x409c42
leaq 0x9d0(%rbx), %rdi
leaq -0x50(%rbp), %rsi
callq 0x40be24
movq (%rbx), %rdi
movzbl -0x29(%rbp), %edx
movl $0x35434, %esi          # imm = 0x35434
callq 0x404a00
movq (%rbx), %rdi
movzbl -0x2a(%rbp), %edx
movl $0x35437, %esi          # imm = 0x35437
callq 0x404a00
leaq -0x50(%rbp), %rdi
callq 0x404baa
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4050b6
jmp 0x4050b6
jmp 0x4050b6
jmp 0x4050b6
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x404baa
movq %rbx, %rdi
callq 0x4ba600