// File: /workspace/github_cpp_makefile_star2_O2/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
pushq $0x70
popq %rsi
callq 0x40b6b6
movl %eax, %r15d
movq %r14, %rdi
movl $0xdc, %esi
movl $0xff, %edx
callq 0x40ed6a
movslq %r15d, %rcx
movq (%rbx), %rdx
imulq $0x28, %rcx, %r15
movb %al, 0x6(%rdx,%r15)
movq %r14, %rdi
movl $0xdc, %esi
movl $0xff, %edx
callq 0x40ed6a
movq (%rbx), %rcx
movb %al, 0x7(%rcx,%r15)
movq %r14, %rdi
movl $0xdc, %esi
movl $0xff, %edx
callq 0x40ed6a
movq (%rbx), %rcx
movb %al, 0xe(%rcx,%r15)
pushq $0x56
popq %rsi
movq %rbx, %rdi
callq 0x40b6b6
movl %eax, %r15d
movq %r14, %rdi
movl $0xdc, %esi
movl $0xff, %edx
callq 0x40ed6a
movslq %r15d, %rcx
movq (%rbx), %rdx
imulq $0x28, %rcx, %r15
movb %al, 0x6(%rdx,%r15)
movq %r14, %rdi
movl $0xdc, %esi
movl $0xff, %edx
callq 0x40ed6a
movq (%rbx), %rcx
movb %al, 0x7(%rcx,%r15)
movq %r14, %rdi
movl $0xdc, %esi
movl $0xff, %edx
callq 0x40ed6a
movq (%rbx), %rcx
movb %al, 0xe(%rcx,%r15)
movq 0x48(%rbx), %rdi
pushq $0x4e
popq %rdx
movl $0x330cd, %esi          # imm = 0x330CD
callq 0x404a00
movq 0x48(%rbx), %rdi
pushq $0x4f
popq %rdx
movl $0x330ce, %esi          # imm = 0x330CE
callq 0x404a00
movq 0x48(%rbx), %rdi
pushq $0x50
popq %rdx
movl $0x330cf, %esi          # imm = 0x330CF
callq 0x404a00
movq 0x48(%rbx), %rdi
pushq $0x51
popq %rdx
movl $0x330d0, %esi          # imm = 0x330D0
callq 0x404a00
movq 0x48(%rbx), %rdi
pushq $0x52
popq %rdx
movl $0x330d1, %esi          # imm = 0x330D1
callq 0x404a00
movq 0x48(%rbx), %rdi
pushq $0x53
popq %rdx
movl $0x330d2, %esi          # imm = 0x330D2
callq 0x404a00
movq 0x48(%rbx), %rdi
pushq $0x7
popq %r14
movl $0x330d3, %esi          # imm = 0x330D3
movl %r14d, %edx
callq 0x404a00
movq 0x48(%rbx), %rdi
pushq $0x42
popq %rdx
movl $0x333ad, %esi          # imm = 0x333AD
callq 0x404a00
movq 0x48(%rbx), %rdi
pushq $0x43
popq %rdx
movl $0x333ae, %esi          # imm = 0x333AE
callq 0x404a00
movq 0x48(%rbx), %rdi
pushq $0x44
popq %rdx
movl $0x333af, %esi          # imm = 0x333AF
callq 0x404a00
movq 0x48(%rbx), %rdi
pushq $0x45
popq %rdx
movl $0x333b0, %esi          # imm = 0x333B0
callq 0x404a00
movq 0x48(%rbx), %rdi
pushq $0x46
popq %rdx
movl $0x333b1, %esi          # imm = 0x333B1
callq 0x404a00
movq 0x48(%rbx), %rdi
pushq $0x47
popq %rdx
movl $0x333b2, %esi          # imm = 0x333B2
callq 0x404a00
movq 0x48(%rbx), %rdi
movl $0x333b3, %esi          # imm = 0x333B3
movl %r14d, %edx
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x404a00
nop