// File: /workspace/github_cpp_makefile_star2_O3/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 0x18730d(%rip), %rdi    # 0x58c236
callq 0x4e96e0
xorps %xmm0, %xmm0
leaq -0x50(%rbp), %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
leaq -0x29(%rbp), %rdx
movb $-0x58, (%rdx)
xorl %esi, %esi
callq 0x40ad1c
leaq 0x8(%rbx), %r14
movq %r14, %rdi
movl $0x5, %esi
movl $0xd7, %edx
callq 0x410846
movl %eax, %r15d
movb %al, -0x29(%rbp)
movzbl %al, %r12d
leal -0xa6(%r12), %eax
cmpl $0x3, %eax
jb 0x404f52
cmpl $0xb3, %r12d
je 0x404f52
leaq 0x187165(%rip), %rdi    # 0x58c0f0
xorl %eax, %eax
callq 0x4e21a0
movq %rbx, %rdi
movl %r12d, %esi
callq 0x404e82
leaq 0x18739d(%rip), %rdi    # 0x58c341
callq 0x4e96e0
movq (%rbx), %rdi
movl $0x35558, %esi          # imm = 0x35558
movl %r12d, %edx
callq 0x404a24
movq -0x48(%rbp), %rsi
cmpq -0x40(%rbp), %rsi
je 0x404fcc
movb %r15b, (%rsi)
incq -0x48(%rbp)
jmp 0x404fd9
leaq -0x50(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x40ae0e
movl $0x2007, %r13d          # imm = 0x2007
movq %r14, %rdi
movl $0x5, %esi
movl $0xd7, %edx
callq 0x410846
movl %eax, %r15d
movb %al, -0x2a(%rbp)
movzbl %al, %r12d
leal -0xa6(%r12), %eax
cmpl $0xd, %eax
ja 0x40500e
btl %eax, %r13d
jb 0x404fdf
cmpb -0x29(%rbp), %r15b
je 0x404fdf
leaq 0x1870d5(%rip), %rdi    # 0x58c0f0
xorl %eax, %eax
callq 0x4e21a0
movq %rbx, %rdi
movl %r12d, %esi
callq 0x404e82
leaq 0x18730d(%rip), %rdi    # 0x58c341
callq 0x4e96e0
movq (%rbx), %rdi
movl $0x35559, %esi          # imm = 0x35559
movl %r12d, %edx
callq 0x404a24
movq -0x48(%rbp), %rsi
cmpq -0x40(%rbp), %rsi
je 0x40505c
movb %r15b, (%rsi)
incq -0x48(%rbp)
jmp 0x405069
leaq -0x50(%rbp), %rdi
leaq -0x2a(%rbp), %rdx
callq 0x40ae0e
leaq 0x9d0(%rbx), %rdi
leaq -0x50(%rbp), %rsi
callq 0x40ce9c
movq (%rbx), %rdi
movzbl -0x29(%rbp), %edx
movl $0x35434, %esi          # imm = 0x35434
callq 0x404a24
movq (%rbx), %rdi
movzbl -0x2a(%rbp), %edx
movl $0x35437, %esi          # imm = 0x35437
callq 0x404a24
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x4050a9
callq 0x410b90
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4050c0
jmp 0x4050c0
jmp 0x4050c0
jmp 0x4050c0
movq %rax, %rbx
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x4050d1
callq 0x410b90
movq %rbx, %rdi
callq 0x4bb660
nop