// File: /workspace/github_cpp_makefile_star2_O1/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 %rbx
subq $0x28, %rsp
movq %rdi, %rbx
leaq 0x187321(%rip), %rdi    # 0x58c236
callq 0x4e96e0
xorps %xmm0, %xmm0
movaps %xmm0, -0x40(%rbp)
movq $0x0, -0x30(%rbp)
movb $-0x58, -0x19(%rbp)
movq -0x38(%rbp), %rsi
testq %rsi, %rsi
je 0x404f3f
movb $-0x58, (%rsi)
incq -0x38(%rbp)
jmp 0x404f4c
leaq -0x40(%rbp), %rdi
leaq -0x19(%rbp), %rdx
callq 0x40ad06
leaq 0x8(%rbx), %r14
movq %r14, %rdi
movl $0x5, %esi
movl $0xd7, %edx
callq 0x410846
movb %al, -0x19(%rbp)
movzbl %al, %eax
leal -0xa6(%rax), %ecx
cmpl $0x3, %ecx
jb 0x404f50
cmpl $0xb3, %eax
je 0x404f50
leaq 0x18716f(%rip), %rdi    # 0x58c0f0
xorl %eax, %eax
callq 0x4e21a0
movzbl -0x19(%rbp), %esi
movq %rbx, %rdi
callq 0x404e72
leaq 0x1873a6(%rip), %rdi    # 0x58c341
callq 0x4e96e0
movq (%rbx), %rdi
movzbl -0x19(%rbp), %edx
movl $0x35558, %esi          # imm = 0x35558
callq 0x404a28
movq -0x38(%rbp), %rsi
cmpq -0x30(%rbp), %rsi
je 0x404fc6
movb -0x19(%rbp), %al
movb %al, (%rsi)
incq -0x38(%rbp)
jmp 0x404fd3
leaq -0x40(%rbp), %rdi
leaq -0x19(%rbp), %rdx
callq 0x40adf8
movl $0x2007, %r15d          # imm = 0x2007
movq %r14, %rdi
movl $0x5, %esi
movl $0xd7, %edx
callq 0x410846
movb %al, -0x1a(%rbp)
movzbl %al, %ecx
addl $0xffffff5a, %ecx       # imm = 0xFFFFFF5A
cmpl $0xd, %ecx
ja 0x405002
btl %ecx, %r15d
jb 0x404fd9
cmpb -0x19(%rbp), %al
je 0x404fd9
leaq 0x1870e2(%rip), %rdi    # 0x58c0f0
xorl %eax, %eax
callq 0x4e21a0
movzbl -0x1a(%rbp), %esi
movq %rbx, %rdi
callq 0x404e72
leaq 0x187319(%rip), %rdi    # 0x58c341
callq 0x4e96e0
movq (%rbx), %rdi
movzbl -0x1a(%rbp), %edx
movl $0x35559, %esi          # imm = 0x35559
callq 0x404a28
movq -0x38(%rbp), %rsi
cmpq -0x30(%rbp), %rsi
je 0x405053
movb -0x1a(%rbp), %al
movb %al, (%rsi)
incq -0x38(%rbp)
jmp 0x405060
leaq -0x40(%rbp), %rdi
leaq -0x1a(%rbp), %rdx
callq 0x40adf8
leaq 0x9d0(%rbx), %rdi
leaq -0x40(%rbp), %rsi
callq 0x40cf0a
movq (%rbx), %rdi
movzbl -0x19(%rbp), %edx
movl $0x35434, %esi          # imm = 0x35434
callq 0x404a28
movq (%rbx), %rdi
movzbl -0x1a(%rbp), %edx
movl $0x35437, %esi          # imm = 0x35437
callq 0x404a28
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x4050a0
callq 0x410b90
addq $0x28, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4050b3
jmp 0x4050b3
jmp 0x4050b3
jmp 0x4050b3
movq %rax, %rbx
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x4050c4
callq 0x410b90
movq %rbx, %rdi
callq 0x4bb660