// File: /workspace/github_cpp_makefile_star2_O1/Thilotilo[P]DoaERando/Generals.cpp
// Function: DoaERando::Generals::RandomizeCaoCaoAndSunCe(DoaERando::RandomNumberGenerator&)
void Generals::RandomizeCaoCaoAndSunCe(RNG& rng)
{
    // Scale the generals STR/INT/AGI to a high range (220-255)
    int CaoCaoIndex = GetGeneralIndexById(CAO_CAO_ID);
    myGenerals[CaoCaoIndex].strength = rng.GetRandomByte(220, 255);
    myGenerals[CaoCaoIndex].intelligence = rng.GetRandomByte(220, 255);
    myGenerals[CaoCaoIndex].agility = rng.GetRandomByte(220, 255);

    int SunCeIndex = GetGeneralIndexById(SUN_CE_ID);
    myGenerals[SunCeIndex].strength = rng.GetRandomByte(220, 255);
    myGenerals[SunCeIndex].intelligence = rng.GetRandomByte(220, 255);
    myGenerals[SunCeIndex].agility = rng.GetRandomByte(220, 255);

    // Update the Sun Ce portrait to look like Sun Quan but different color
    myRom.WriteByte(0x330CD, 0x4E); // Portrait Slices
    myRom.WriteByte(0x330CE, 0x4F);
    myRom.WriteByte(0x330CF, 0x50);
    myRom.WriteByte(0x330D0, 0x51);
    myRom.WriteByte(0x330D1, 0x52);
    myRom.WriteByte(0x330D2, 0x53);
    myRom.WriteByte(0x330D3, 0x07); // Portrait color

    // Update the Cao Cao portrait to look like Cao Pi but different color
    myRom.WriteByte(0x333AD, 0x42); // Portrait Slices
    myRom.WriteByte(0x333AE, 0x43);
    myRom.WriteByte(0x333AF, 0x44);
    myRom.WriteByte(0x333B0, 0x45);
    myRom.WriteByte(0x333B1, 0x46);
    myRom.WriteByte(0x333B2, 0x47);
    myRom.WriteByte(0x333B3, 0x07); // Portrait color
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
movl $0x70, %esi
callq 0x40c67e
movl %eax, %r15d
movq %r14, %rdi
movl $0xdc, %esi
movl $0xff, %edx
callq 0x410846
movslq %r15d, %rcx
movq (%rbx), %rdx
shlq $0x3, %rcx
leaq (%rcx,%rcx,4), %r15
movb %al, 0x6(%rdx,%r15)
movq %r14, %rdi
movl $0xdc, %esi
movl $0xff, %edx
callq 0x410846
movq (%rbx), %rcx
movb %al, 0x7(%rcx,%r15)
movq %r14, %rdi
movl $0xdc, %esi
movl $0xff, %edx
callq 0x410846
movq (%rbx), %rcx
movb %al, 0xe(%rcx,%r15)
movq %rbx, %rdi
movl $0x56, %esi
callq 0x40c67e
movl %eax, %r15d
movq %r14, %rdi
movl $0xdc, %esi
movl $0xff, %edx
callq 0x410846
movslq %r15d, %rcx
movq (%rbx), %rdx
shlq $0x3, %rcx
leaq (%rcx,%rcx,4), %r15
movb %al, 0x6(%rdx,%r15)
movq %r14, %rdi
movl $0xdc, %esi
movl $0xff, %edx
callq 0x410846
movq (%rbx), %rcx
movb %al, 0x7(%rcx,%r15)
movq %r14, %rdi
movl $0xdc, %esi
movl $0xff, %edx
callq 0x410846
movq (%rbx), %rcx
movb %al, 0xe(%rcx,%r15)
movq 0x48(%rbx), %rdi
movl $0x330cd, %esi          # imm = 0x330CD
movl $0x4e, %edx
callq 0x404a28
movq 0x48(%rbx), %rdi
movl $0x330ce, %esi          # imm = 0x330CE
movl $0x4f, %edx
callq 0x404a28
movq 0x48(%rbx), %rdi
movl $0x330cf, %esi          # imm = 0x330CF
movl $0x50, %edx
callq 0x404a28
movq 0x48(%rbx), %rdi
movl $0x330d0, %esi          # imm = 0x330D0
movl $0x51, %edx
callq 0x404a28
movq 0x48(%rbx), %rdi
movl $0x330d1, %esi          # imm = 0x330D1
movl $0x52, %edx
callq 0x404a28
movq 0x48(%rbx), %rdi
movl $0x330d2, %esi          # imm = 0x330D2
movl $0x53, %edx
callq 0x404a28
movq 0x48(%rbx), %rdi
movl $0x330d3, %esi          # imm = 0x330D3
movl $0x7, %edx
callq 0x404a28
movq 0x48(%rbx), %rdi
movl $0x333ad, %esi          # imm = 0x333AD
movl $0x42, %edx
callq 0x404a28
movq 0x48(%rbx), %rdi
movl $0x333ae, %esi          # imm = 0x333AE
movl $0x43, %edx
callq 0x404a28
movq 0x48(%rbx), %rdi
movl $0x333af, %esi          # imm = 0x333AF
movl $0x44, %edx
callq 0x404a28
movq 0x48(%rbx), %rdi
movl $0x333b0, %esi          # imm = 0x333B0
movl $0x45, %edx
callq 0x404a28
movq 0x48(%rbx), %rdi
movl $0x333b1, %esi          # imm = 0x333B1
movl $0x46, %edx
callq 0x404a28
movq 0x48(%rbx), %rdi
movl $0x333b2, %esi          # imm = 0x333B2
movl $0x47, %edx
callq 0x404a28
movq 0x48(%rbx), %rdi
movl $0x333b3, %esi          # imm = 0x333B3
movl $0x7, %edx
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x404a28
nop