// File: 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
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x48(%rbp)
leaq 0x194e8c(%rip), %rdi    # 0x59b067
xorl %eax, %eax
callq 0x4f06e0
leaq -0x20(%rbp), %rdi
movq %rdi, -0x40(%rbp)
callq 0x40fa90
movq -0x40(%rbp), %rdi
movb $-0x58, -0x21(%rbp)
leaq -0x21(%rbp), %rsi
callq 0x40fab0
jmp 0x406202
jmp 0x406204
movq -0x48(%rbp), %rdi
addq $0x8, %rdi
movl $0x5, %esi
movl $0xd7, %edx
callq 0x41db50
movb %al, -0x49(%rbp)
jmp 0x406220
movb -0x49(%rbp), %al
movb %al, -0x35(%rbp)
movzbl -0x35(%rbp), %ecx
movb $0x1, %al
cmpl $0xb3, %ecx
movb %al, -0x4a(%rbp)
je 0x406268
movzbl -0x35(%rbp), %ecx
movb $0x1, %al
cmpl $0xa6, %ecx
movb %al, -0x4a(%rbp)
je 0x406268
movzbl -0x35(%rbp), %ecx
movb $0x1, %al
cmpl $0xa7, %ecx
movb %al, -0x4a(%rbp)
je 0x406268
movzbl -0x35(%rbp), %eax
cmpl $0xa8, %eax
sete %al
movb %al, -0x4a(%rbp)
movb -0x4a(%rbp), %al
testb $0x1, %al
jne 0x406204
leaq 0x194e13(%rip), %rdi    # 0x59b089
xorl %eax, %eax
callq 0x4f06e0
jmp 0x40627f
movq -0x48(%rbp), %rdi
movzbl -0x35(%rbp), %esi
callq 0x4060e0
jmp 0x40628e
leaq 0x194dfd(%rip), %rdi    # 0x59b092
xorl %eax, %eax
callq 0x4f06e0
jmp 0x40629e
movq -0x48(%rbp), %rax
movq (%rax), %rdi
movzbl -0x35(%rbp), %edx
movl $0x35558, %esi          # imm = 0x35558
callq 0x404c20
jmp 0x4062b5
leaq -0x20(%rbp), %rdi
leaq -0x35(%rbp), %rsi
callq 0x40fae0
jmp 0x4062c4
jmp 0x4062c6
movq -0x48(%rbp), %rdi
addq $0x8, %rdi
movl $0x5, %esi
movl $0xd7, %edx
callq 0x41db50
movb %al, -0x4b(%rbp)
jmp 0x4062e2
movb -0x4b(%rbp), %al
movb %al, -0x36(%rbp)
movzbl -0x36(%rbp), %ecx
movb $0x1, %al
cmpl $0xb3, %ecx
movb %al, -0x4c(%rbp)
je 0x40633c
movzbl -0x36(%rbp), %ecx
movb $0x1, %al
cmpl $0xa6, %ecx
movb %al, -0x4c(%rbp)
je 0x40633c
movzbl -0x36(%rbp), %ecx
movb $0x1, %al
cmpl $0xa7, %ecx
movb %al, -0x4c(%rbp)
je 0x40633c
movzbl -0x36(%rbp), %ecx
movb $0x1, %al
cmpl $0xa8, %ecx
movb %al, -0x4c(%rbp)
je 0x40633c
movzbl -0x36(%rbp), %eax
movzbl -0x35(%rbp), %ecx
cmpl %ecx, %eax
sete %al
movb %al, -0x4c(%rbp)
movb -0x4c(%rbp), %al
testb $0x1, %al
jne 0x4062c6
leaq 0x194d3f(%rip), %rdi    # 0x59b089
xorl %eax, %eax
callq 0x4f06e0
jmp 0x406353
movq -0x48(%rbp), %rdi
movzbl -0x36(%rbp), %esi
callq 0x4060e0
jmp 0x406362
leaq 0x194d29(%rip), %rdi    # 0x59b092
xorl %eax, %eax
callq 0x4f06e0
jmp 0x406372
movq -0x48(%rbp), %rax
movq (%rax), %rdi
movzbl -0x36(%rbp), %edx
movl $0x35559, %esi          # imm = 0x35559
callq 0x404c20
jmp 0x406389
leaq -0x20(%rbp), %rdi
leaq -0x36(%rbp), %rsi
callq 0x40fae0
jmp 0x406398
movq -0x48(%rbp), %rdi
addq $0x9d0, %rdi            # imm = 0x9D0
leaq -0x20(%rbp), %rsi
callq 0x416750
jmp 0x4063ae
movq -0x48(%rbp), %rax
movq (%rax), %rdi
movzbl -0x35(%rbp), %edx
movl $0x35434, %esi          # imm = 0x35434
callq 0x404c20
jmp 0x4063c5
movq -0x48(%rbp), %rax
movq (%rax), %rdi
movzbl -0x36(%rbp), %edx
movl $0x35437, %esi          # imm = 0x35437
callq 0x404c20
jmp 0x4063dc
leaq -0x20(%rbp), %rdi
callq 0x404f50
addq $0x50, %rsp
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x404f50
movq -0x30(%rbp), %rdi
callq 0x4c9ba0
nopl (%rax)