LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_cpp_makefile_star2_O2/Thilotilo[P]DoaERando/General.cpp
// Function: DoaERando::General::DumpGeneral()
void General::DumpGeneral()
{
    printf("%s:\n", name);
    printf("\tid: 0x%02X\n", id);
    printf("\taddress: 0x%X\n", address);
    printf("\tcount: %d\n", count);
    printf("\tSTR: %d\n", strength);
    printf("\tINT: %d\n", intelligence);
    printf("\tAGI: %d\n", agility);
    printf("\tzone: %d\n", zone);
    printf("\tHP exp: %d, %d\n", enemySoldierExponent, allySoldierExponent);
    printf("\tDefense: %d\n", enemyDefenseId);
    printf("\tMax Tactic Level: %d\n", enemyMaxTacticLevel);
    printf("\tWeapon: 0x%02X\n", weaponId);
    printf("\tEncounterable? %d\n", encounterable);
    printf("\tRecruitable? %d\n", recruitable);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0xf(%rdi), %rsi
leaq 0x180402(%rip), %rdi    # 0x58b6d8
xorl %eax, %eax
callq 0x4e1140
movzbl 0x4(%rbx), %esi
leaq 0x1803f5(%rip), %rdi    # 0x58b6dd
xorl %eax, %eax
callq 0x4e1140
movl (%rbx), %esi
leaq 0x1803f2(%rip), %rdi    # 0x58b6ea
xorl %eax, %eax
callq 0x4e1140
movzbl 0x5(%rbx), %esi
leaq 0x1803f0(%rip), %rdi    # 0x58b6fa
xorl %eax, %eax
callq 0x4e1140
movzbl 0x6(%rbx), %esi
leaq 0x1803ea(%rip), %rdi    # 0x58b706
xorl %eax, %eax
callq 0x4e1140
movzbl 0x7(%rbx), %esi
leaq 0x1803e2(%rip), %rdi    # 0x58b710
xorl %eax, %eax
callq 0x4e1140
movzbl 0xe(%rbx), %esi
leaq 0x1803da(%rip), %rdi    # 0x58b71a
xorl %eax, %eax
callq 0x4e1140
movzbl 0x8(%rbx), %esi
leaq 0x1803d2(%rip), %rdi    # 0x58b724
xorl %eax, %eax
callq 0x4e1140
movzbl 0xb(%rbx), %esi
movzbl 0xc(%rbx), %edx
leaq 0x1803c7(%rip), %rdi    # 0x58b72f
xorl %eax, %eax
callq 0x4e1140
movzbl 0xa(%rbx), %esi
leaq 0x1803c6(%rip), %rdi    # 0x58b740
xorl %eax, %eax
callq 0x4e1140
movzbl 0xd(%rbx), %esi
leaq 0x1803c2(%rip), %rdi    # 0x58b74e
xorl %eax, %eax
callq 0x4e1140
movzbl 0x9(%rbx), %esi
leaq 0x1803c7(%rip), %rdi    # 0x58b765
xorl %eax, %eax
callq 0x4e1140
movzbl 0x23(%rbx), %esi
leaq 0x1803c6(%rip), %rdi    # 0x58b776
xorl %eax, %eax
callq 0x4e1140
movzbl 0x24(%rbx), %esi
leaq 0x1803c8(%rip), %rdi    # 0x58b78a
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x4e1140
nop
// File: /workspace/github_cpp_makefile_star2_O2/Thilotilo[P]DoaERando/Generals.cpp
// Function: DoaERando::Generals::ReadGenerals()
void Generals::ReadGenerals()
{
    for (BYTE i = 5; i < 0xD8; ++i)
    {
        if (i != UV10_ID)
        {
            AddGeneral(i);
            if (i == LIU_BEI_ID || i == CAO_PI_ID ||
                i == SIMA_YI_ID || i == SUN_QUAN_ID)
            {
                myRestrictedGeneralAddresses.push_back(GetGeneralAddress(i));
            }
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0x18(%rdi), %r14
movb $0x5, %r13b
leaq -0x2c(%rbp), %r15
cmpb $-0x4d, %r13b
je 0x40b4a3
movzbl %r13b, %r12d
cmpl $0xd8, %r12d
je 0x40b4a8
movq %rbx, %rdi
movl %r12d, %esi
callq 0x40b520
leal -0x71(%r12), %eax
cmpl $0x37, %eax
ja 0x40b484
movabsq $0x80000000800001, %rcx # imm = 0x80000000800001
btq %rax, %rcx
jb 0x40b48a
cmpl $0x57, %r12d
jne 0x40b4a3
movq %rbx, %rdi
movl %r12d, %esi
callq 0x40b4b8
movl %eax, -0x2c(%rbp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x40bfee
incb %r13b
jmp 0x40b44c
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/Thilotilo[P]DoaERando/Generals.cpp
// Function: DoaERando::Generals::AddGeneral(unsigned char)
void Generals::AddGeneral(BYTE id)
{
    if (GeneralExists(id))
    {
        AddCopy(id);
    }
    else
    {
        auto address = GetGeneralAddress(id);
        General general(address, id, myRom);
        myGenerals.push_back(general);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x28, %rsp
movl %esi, %r14d
movq %rdi, %rbx
callq 0x40b58c
testb %al, %al
je 0x40b552
movzbl %r14b, %esi
movq %rbx, %rdi
addq $0x28, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x40b5f6
movzbl %r14b, %r14d
movq %rbx, %rdi
movl %r14d, %esi
callq 0x40b4b8
movq 0x48(%rbx), %rcx
leaq -0x40(%rbp), %r15
movq %r15, %rdi
movl %eax, %esi
movl %r14d, %edx
callq 0x40abcc
movq %rbx, %rdi
movq %r15, %rsi
callq 0x40bf94
addq $0x28, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/Thilotilo[P]DoaERando/Generals.cpp
// Function: DoaERando::Generals::GeneralExists(unsigned char)
bool Generals::GeneralExists(BYTE id)
{
    for (int i = 0; i < myGenerals.size(); ++i)
    {
        if(myGenerals[i].address == GetGeneralAddress(id))
        {
            return true;
        }
    }

    return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
pushq $-0x1
popq %r12
xorl %r13d, %r13d
movzbl %sil, %eax
movl %eax, -0x2c(%rbp)
movq (%rbx), %rcx
movq 0x8(%rbx), %rax
subq %rcx, %rax
cqto
pushq $0x28
popq %rsi
idivq %rsi
movq %rax, %r15
incq %r12
cmpq %r12, %rax
jbe 0x40b5e0
movl (%rcx,%r13), %r14d
addq $0x28, %r13
movq %rbx, %rdi
movl -0x2c(%rbp), %esi
callq 0x40b4b8
cmpl %eax, %r14d
jne 0x40b5ab
cmpq %r12, %r15
seta %al
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/Thilotilo[P]DoaERando/Generals.cpp
// Function: DoaERando::Generals::AddCopy(unsigned char)
void Generals::AddCopy(BYTE id)
{
    auto address = GetGeneralAddress(id);
    for (auto& general: myGenerals)
    {
        if (general.address == address)
        {
            general.count++;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
callq 0x40b4b8
movq (%rbx), %rcx
movq 0x8(%rbx), %rdx
cmpq %rdx, %rcx
je 0x40b61d
cmpl %eax, (%rcx)
jne 0x40b617
incb 0x5(%rcx)
addq $0x28, %rcx
jmp 0x40b60b
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/Thilotilo[P]DoaERando/Generals.cpp
// Function: DoaERando::Generals::AdjustZone1Generals()
void Generals::AdjustZone1Generals()
{
    // These are generals that are not found in zone 1 but are marked as zone 1, making
    //  zone 1 over populated:

    // Zhou Chao is in Chang An - he belongs in chapter 3
    int zhouChaoIndex = GetGeneralIndexById(ZHOU_CHAO_ID);
    myGenerals[zhouChaoIndex].zone = 3;
    // Wang Gui is in Luo Yang - he belongs in chapter 2
    int wangGuiIndex = GetGeneralIndexById(WANG_GUI_ID);
    myGenerals[wangGuiIndex].zone = 2;
    // Sun Gan is not in the game - he belongs in chapter 0
    int sunGanIndex = GetGeneralIndexById(SUN_GAN_ID);
    myGenerals[sunGanIndex].zone = 0;
    // Huo Hu is in Lu Bu's fortress - he belongs in chapter 2
    int huoHuIndex = GetGeneralIndexById(HUO_HU_ID);
    myGenerals[huoHuIndex].zone = 2;
    // Yang Jin is in Hua Xiong's fortress - he belongs in chapter 2
    int yangJinIndex = GetGeneralIndexById(YANG_JIN_ID);
    myGenerals[yangJinIndex].zone = 2;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
pushq $0x8
popq %rsi
callq 0x40b6b6
cltq
movq (%rbx), %r14
imulq $0x28, %rax, %rax
movb $0x3, 0x8(%r14,%rax)
pushq $0x9
popq %rsi
movq %rbx, %rdi
callq 0x40b6b6
cltq
imulq $0x28, %rax, %rax
movb $0x2, %r15b
movb %r15b, 0x8(%r14,%rax)
movq %rbx, %rdi
movl $0x9e, %esi
callq 0x40b6b6
cltq
imulq $0x28, %rax, %rax
movb $0x0, 0x8(%r14,%rax)
movq %rbx, %rdi
movl $0xb8, %esi
callq 0x40b6b6
cltq
imulq $0x28, %rax, %rax
movb %r15b, 0x8(%r14,%rax)
movq %rbx, %rdi
movl $0xb9, %esi
callq 0x40b6b6
cltq
imulq $0x28, %rax, %rax
movb %r15b, 0x8(%r14,%rax)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/Thilotilo[P]DoaERando/Generals.cpp
// Function: DoaERando::Generals::GetGeneralIndexById(unsigned char)
int Generals::GetGeneralIndexById(BYTE id)
{
    int i = 0;
    for (i = 0; i < myGenerals.size(); ++i)
    {
        for (int j = myGenerals[i].id; j < myGenerals[i].id + myGenerals[i].count; ++j)
        {
            if (j == id)
            {
                return i;
            }
        }
    }
    return -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq (%rdi), %r8
movq 0x8(%rdi), %rax
subq %r8, %rax
movabsq $0x28, %rcx
cqto
idivq %rcx
movq %rax, %rcx
addq $0x5, %r8
xorl %edx, %edx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rdx, %rcx
je 0x40b705
movzbl -0x1(%r8), %edi
movzbl (%r8), %r9d
movl %esi, %r10d
subl %edi, %r10d
cmpl %r9d, %r10d
jb 0x40b703
incq %rdx
addq $0x28, %r8
jmp 0x40b6e1
movl %edx, %eax
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/Thilotilo[P]DoaERando/Generals.cpp
// Function: DoaERando::Generals::SwapIDs(int, int)
void Generals::SwapIDs(int slot1, int slot2)
{
    if (!isRestrictedGeneralAddress(myGenerals[slot1].address) &&
        !isRestrictedGeneralAddress(myGenerals[slot2].address))
    {
        auto tempId = myGenerals[slot1].id;
        auto tempCount = myGenerals[slot1].count;
        myGenerals[slot1].id = myGenerals[slot2].id;
        myGenerals[slot1].count = myGenerals[slot2].count;
        myGenerals[slot2].id = tempId;
        myGenerals[slot2].count = tempCount;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %edx, %r14d
movq %rdi, %rbx
movslq %esi, %rax
movq (%rdi), %r12
imulq $0x28, %rax, %r15
movl (%r12,%r15), %esi
callq 0x40b770
testb %al, %al
jne 0x40b767
movslq %r14d, %rax
imulq $0x28, %rax, %r14
movl (%r12,%r14), %esi
movq %rbx, %rdi
callq 0x40b770
testb %al, %al
jne 0x40b767
addq %r12, %r15
addq %r12, %r14
movzwl 0x4(%r15), %eax
movb 0x4(%r14), %cl
movb %cl, 0x4(%r15)
movb 0x5(%r14), %cl
movb %cl, 0x5(%r15)
movw %ax, 0x4(%r14)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/Thilotilo[P]DoaERando/Generals.cpp
// Function: DoaERando::Generals::isRestrictedGeneralAddress(int)
bool Generals::isRestrictedGeneralAddress(int address)
{
    for (auto &i : myRestrictedGeneralAddresses)
    {
        if (i == address)
        {
            return true;
        }
    }
    return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq 0x18(%rdi), %rdx
movq 0x20(%rdi), %rax
movq %rdx, %rcx
cmpq %rax, %rdx
je 0x40b78c
leaq 0x4(%rcx), %rdx
cmpl %esi, (%rcx)
jne 0x40b77c
cmpq %rax, %rcx
setne %al
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/Thilotilo[P]DoaERando/Generals.cpp
// Function: DoaERando::Generals::SwapZones(int, int)
void Generals::SwapZones(int slot1, int slot2)
{
    if (!isRestrictedGeneralAddress(myGenerals[slot1].address) &&
        !isRestrictedGeneralAddress(myGenerals[slot2].address))
    {
        auto tempZone = myGenerals[slot1].zone;
        myGenerals[slot1].zone = myGenerals[slot2].zone;
        myGenerals[slot2].zone = tempZone;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %edx, %r14d
movq %rdi, %rbx
movslq %esi, %rax
movq (%rdi), %r12
imulq $0x28, %rax, %r15
movl (%r12,%r15), %esi
callq 0x40b770
testb %al, %al
jne 0x40b7e9
movslq %r14d, %rax
imulq $0x28, %rax, %r14
movl (%r12,%r14), %esi
movq %rbx, %rdi
callq 0x40b770
testb %al, %al
jne 0x40b7e9
addq %r12, %r15
addq %r12, %r14
movb 0x8(%r15), %al
movb 0x8(%r14), %cl
movb %cl, 0x8(%r15)
movb %al, 0x8(%r14)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/Thilotilo[P]DoaERando/Generals.cpp
// Function: DoaERando::Generals::SetZonesForZone0(DoaERando::RandomNumberGenerator&)
void Generals::SetZonesForZone0(RNG& rng)
{
    for (auto& general : myGenerals)
    {
        if (general.zone == 0)
        {
            // Zone 1 already has too many generals, let's only allow zone 2 and above:
            general.zone = rng.GetRandomByte(2, 8);
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq (%rdi), %r12
movq 0x8(%rdi), %r13
pushq $0x2
popq %r14
pushq $0x8
popq %r15
cmpq %r13, %r12
je 0x40b838
cmpb $0x0, 0x8(%r12)
jne 0x40b832
movq %rbx, %rdi
movl %r14d, %esi
movl %r15d, %edx
callq 0x40ed6a
movb %al, 0x8(%r12)
addq $0x28, %r12
jmp 0x40b812
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/Thilotilo[P]DoaERando/Generals.cpp
// Function: DoaERando::Generals::isStartingGeneralAddress(int)
bool Generals::isStartingGeneralAddress(int address)
{
    for (auto &i : myStartingGeneralAddresses)
    {
        if (i == address)
        {
            return true;
        }
    }
    return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq 0x30(%rdi), %rdx
movq 0x38(%rdi), %rax
movq %rdx, %rcx
cmpq %rax, %rdx
je 0x40b89c
leaq 0x4(%rcx), %rdx
cmpl %esi, (%rcx)
jne 0x40b88c
cmpq %rax, %rcx
setne %al
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/Thilotilo[P]DoaERando/Generals.cpp
// Function: DoaERando::Generals::ScaleForZone(DoaERando::RandomNumberGenerator&)
void Generals::ScaleForZone(RNG& rng)
{
    for (auto& general : myGenerals)
    {
        if (general.id != CAO_PI_ID &&
            general.id != SIMA_YI_ID &&
            general.id != SUN_QUAN_ID)
        {
            general.ScaleWeaponForZone(rng);
            general.ScaleArmorForZone(rng);
            general.ScaleMaxTacticForZone(rng);
            general.ScaleSoldiersForZone(rng);
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rsi, %rbx
movq (%rdi), %r14
movq 0x8(%rdi), %r15
movabsq $0x2000004000001, %r12  # imm = 0x2000004000001
cmpq %r15, %r14
je 0x40b90d
movzbl 0x4(%r14), %eax
addl $-0x57, %eax
cmpl $0x31, %eax
ja 0x40b8db
btq %rax, %r12
jb 0x40b907
movq %r14, %rdi
movq %rbx, %rsi
callq 0x40add6
movq %r14, %rdi
movq %rbx, %rsi
callq 0x40ae0e
movq %r14, %rdi
movq %rbx, %rsi
callq 0x40ae46
movq %r14, %rdi
movq %rbx, %rsi
callq 0x40ae72
addq $0x28, %r14
jmp 0x40b8c3
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/Thilotilo[P]DoaERando/Generals.cpp
// Function: DoaERando::Generals::SetAndScaleGeneralForZone(unsigned char, unsigned char, DoaERando::RandomNumberGenerator&)
void Generals::SetAndScaleGeneralForZone(BYTE generalId, BYTE zone, RNG& rng)
{
    int generalIndex = GetGeneralIndexById(generalId);
    myGenerals[generalIndex].zone = zone;
    myGenerals[generalIndex].ScaleWeaponForZone(rng);
    myGenerals[generalIndex].ScaleArmorForZone(rng);
    myGenerals[generalIndex].ScaleMaxTacticForZone(rng);
    myGenerals[generalIndex].ScaleSoldiersForZone(rng);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rcx, %rbx
movl %edx, %r15d
movq %rdi, %r14
callq 0x40b6b6
cltq
movq (%r14), %rdi
imulq $0x28, %rax, %r12
movb %r15b, 0x8(%rdi,%r12)
addq %r12, %rdi
movq %rbx, %rsi
callq 0x40add6
movq (%r14), %rdi
addq %r12, %rdi
movq %rbx, %rsi
callq 0x40ae0e
movq (%r14), %rdi
addq %r12, %rdi
movq %rbx, %rsi
callq 0x40ae46
addq (%r14), %r12
movq %r12, %rdi
movq %rbx, %rsi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x40ae72
// File: /workspace/github_cpp_makefile_star2_O2/Thilotilo[P]DoaERando/Generals.cpp
// Function: DoaERando::Generals::UpdateGenerals()
void Generals::UpdateGenerals()
{
    const int GENERAL_ADDRESSES_LSB_START = 0x32610;
    const int GENERAL_ADDRESSES_MSB_START = 0x32710;
    for (auto& general : myGenerals)
    {
        general.UpdateGeneral(myRom);
        general.DumpGeneral();

        for (int i = 0; i < general.count; ++i)
        {
            int bankAddress = ConvertRomAddressToBankAddress(general.address);
            BYTE lsb = bankAddress & 0xFF;
            BYTE msb = (bankAddress >> 8) & 0xFF;
            myRom.WriteByte(GENERAL_ADDRESSES_MSB_START + general.id + i, msb);
            myRom.WriteByte(GENERAL_ADDRESSES_LSB_START + general.id + i, lsb);
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq (%rdi), %r14
movq 0x8(%rdi), %rax
movq %rax, -0x30(%rbp)
movl $0xff, %r12d
cmpq -0x30(%rbp), %r14
je 0x40bae0
movq 0x48(%rbx), %rsi
movq %r14, %rdi
callq 0x40b09c
movq %r14, %rdi
callq 0x40b2c2
movl $0x32610, %r13d         # imm = 0x32610
leal -0x32610(%r13), %eax
movzbl 0x5(%r14), %ecx
cmpl %ecx, %eax
jae 0x40bada
movl (%r14), %r15d
movl $0xfffd7ff0, %eax       # imm = 0xFFFD7FF0
addl %eax, %r15d
movl %r15d, %edx
shrl $0x8, %edx
movq 0x48(%rbx), %rdi
movzbl 0x4(%r14), %eax
leal (%rax,%r13), %esi
addl $0x100, %esi            # imm = 0x100
andl %r12d, %edx
callq 0x404a00
movq 0x48(%rbx), %rdi
movzbl 0x4(%r14), %esi
addl %r13d, %esi
andl %r12d, %r15d
movl %r15d, %edx
callq 0x404a00
incl %r13d
jmp 0x40ba82
addq $0x28, %r14
jmp 0x40ba62
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/Thilotilo[P]DoaERando/Generals.cpp
// Function: DoaERando::Generals::ScaleSpecialGenerals(DoaERando::RandomNumberGenerator&)
void Generals::ScaleSpecialGenerals(RNG& rng)
{
    int index = GetGeneralIndexById(CAO_PI_ID);
    myGenerals[index].enemyMaxTacticLevel = rng.GetRandomByte(35, 50);
    
    index = GetGeneralIndexById(SIMA_YI_ID);
    myGenerals[index].enemyMaxTacticLevel = rng.GetRandomByte(35, 50);

    index = GetGeneralIndexById(SUN_QUAN_ID);
    myGenerals[index].enemyMaxTacticLevel = rng.GetRandomByte(35, 50);

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
pushq $0x71
popq %rsi
callq 0x40b6b6
movl %eax, %r13d
pushq $0x23
popq %r15
pushq $0x32
popq %r12
movq %r14, %rdi
movl %r15d, %esi
movl %r12d, %edx
callq 0x40ed6a
movslq %r13d, %rcx
movq (%rbx), %rdx
imulq $0x28, %rcx, %rcx
movb %al, 0xd(%rdx,%rcx)
movq %rbx, %rdi
movl $0x88, %esi
callq 0x40b6b6
movl %eax, %r13d
movq %r14, %rdi
movl %r15d, %esi
movl %r12d, %edx
callq 0x40ed6a
movslq %r13d, %rcx
movq (%rbx), %rdx
imulq $0x28, %rcx, %rcx
movb %al, 0xd(%rdx,%rcx)
pushq $0x57
popq %rsi
movq %rbx, %rdi
callq 0x40b6b6
movl %eax, %r13d
movq %r14, %rdi
movl %r15d, %esi
movl %r12d, %edx
callq 0x40ed6a
movslq %r13d, %rcx
movq (%rbx), %rdx
imulq $0x28, %rcx, %rcx
movb %al, 0xd(%rdx,%rcx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/Thilotilo[P]DoaERando/Generals.cpp
// Function: DoaERando::Generals::RandomizeLiuShan(DoaERando::RandomNumberGenerator&)
void Generals::RandomizeLiuShan(RNG& rng)
{
    // Scale Liu Shan's STR/INT/AGI to an above average range (180-220)
    int LiuShanIndex = GetGeneralIndexById(LIU_CHAN_ID);
    myGenerals[LiuShanIndex].strength = rng.GetRandomByte(180, 220);
    myGenerals[LiuShanIndex].intelligence = rng.GetRandomByte(180, 220);
    myGenerals[LiuShanIndex].agility = rng.GetRandomByte(180, 220);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
movl $0xab, %esi
callq 0x40b6b6
movl %eax, %r15d
movq %r14, %rdi
movl $0xb4, %esi
movl $0xdc, %edx
callq 0x40ed6a
movslq %r15d, %rcx
movq (%rbx), %rdx
imulq $0x28, %rcx, %r15
movb %al, 0x6(%rdx,%r15)
movq %r14, %rdi
movl $0xb4, %esi
movl $0xdc, %edx
callq 0x40ed6a
movq (%rbx), %rcx
movb %al, 0x7(%rcx,%r15)
movq %r14, %rdi
movl $0xb4, %esi
movl $0xdc, %edx
callq 0x40ed6a
movq (%rbx), %rcx
movb %al, 0xe(%rcx,%r15)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/Thilotilo[P]DoaERando/Generals.cpp
// Function: DoaERando::Generals::SetStartingGenerals(std::vector<unsigned char, std::allocator<unsigned char>>&)
void Generals::SetStartingGenerals(vector<BYTE>& startingGeneralIds)
{
    for (auto& generalId : startingGeneralIds)
    {
        int index = GetGeneralIndexById(generalId);
        myStartingGeneralAddresses.push_back(myGenerals[index].address);
        myGenerals[index].encounterable = false;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq (%rsi), %r15
movq 0x8(%rsi), %r12
leaq 0x30(%rdi), %r14
cmpq %r12, %r15
je 0x40be73
movzbl (%r15), %esi
movq %rbx, %rdi
callq 0x40b6b6
cltq
imulq $0x28, %rax, %r13
movq (%rbx), %rsi
addq %r13, %rsi
movq %r14, %rdi
callq 0x40bfc8
movq (%rbx), %rax
movb $0x0, 0x23(%rax,%r13)
incq %r15
jmp 0x40be40
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/Thilotilo[P]DoaERando/Generals.cpp
// Function: DoaERando::Generals::GetGeneralIdsFromZone(unsigned char)
std::vector<BYTE> Generals::GetGeneralIdsFromZone(BYTE zone)
{
    std::vector<BYTE> generalIdsForZone;
    for (auto& general : myGenerals)
    {
        if (isStartingGeneralAddress(general.address) || isRestrictedGeneralAddress(general.address))
        {
            continue;
        }
        if (general.zone == zone)
        {
            // The game likes to use the last id if there are multiples
            generalIdsForZone.push_back(general.id + (general.count - 1));
        }
    }
    return generalIdsForZone;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, %r14d
movq %rsi, %r15
xorps %xmm0, %xmm0
andq $0x0, 0x10(%rdi)
movq %rdi, -0x38(%rbp)
movups %xmm0, (%rdi)
movq (%rsi), %r12
movq 0x8(%rsi), %rbx
cmpq %rbx, %r12
je 0x40beff
movl (%r12), %r13d
movq %r15, %rdi
movl %r13d, %esi
callq 0x40b880
testb %al, %al
jne 0x40bef9
movq %r15, %rdi
movl %r13d, %esi
callq 0x40b770
testb %al, %al
jne 0x40bef9
cmpb %r14b, 0x8(%r12)
jne 0x40bef9
movb 0x4(%r12), %al
addb 0x5(%r12), %al
decb %al
movb %al, -0x29(%rbp)
movq -0x38(%rbp), %rdi
leaq -0x29(%rbp), %rsi
callq 0x409faa
addq $0x28, %r12
jmp 0x40beaf
movq -0x38(%rbp), %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq -0x38(%rbp), %rdi
callq 0x404baa
movq %r14, %rdi
callq 0x4ba600
// File: /workspace/github_cpp_makefile_star2_O2/Thilotilo[P]DoaERando/Generals.cpp
// Function: DoaERando::Generals::GetAllGeneralIds()
std::vector<BYTE> Generals::GetAllGeneralIds()
{
    std::vector<BYTE> generalIds;
    for (auto& general : myGenerals)
    {
        // The game likes to use the last id if there are multiples
        generalIds.push_back(general.id + (general.count - 1));
    }
    return generalIds;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
xorps %xmm0, %xmm0
andq $0x0, 0x10(%rdi)
movups %xmm0, (%rdi)
movq (%rsi), %r15
movq 0x8(%rsi), %r12
leaq -0x21(%rbp), %r14
cmpq %r12, %r15
je 0x40bf71
movb 0x4(%r15), %al
addb 0x5(%r15), %al
decb %al
movb %al, -0x21(%rbp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x409faa
addq $0x28, %r15
jmp 0x40bf4e
movq %rbx, %rax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq %rbx, %rdi
callq 0x404baa
movq %r14, %rdi
callq 0x4ba600
// File: /workspace/github_cpp_makefile_star2_O2/Thilotilo[P]DoaERando/BattleRandomizer.cpp
// Function: DoaERando::Battle::Battle(int)
Battle::Battle(int id)
{
    vector<int> zoneForBattle = {1, 1, 1, 1, 1, 1,
                                 2, 2, 2, 2, 2, 2, 2, 2,
                                 3, 3, 3, 3, 3, 3,
                                 4, 4, 4, 4, 4, 4, 4,
                                 5, 5, 5, 5, 5,
                                 6, 6, 6, 6, 6, 6, 6, 6,
                                 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
                                 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
                                 4, 4,
                                 5, 5,
                                 7, 7, 8, 6};

    zone = zoneForBattle[id];
    battleId = id;
    for (int i = 0; i < 5; ++i)
    {
        generals[i] = 0x00;
    }
    slotsRemaining = 5;
    battleModified = false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x160, %rsp            # imm = 0x160
movl %esi, %r14d
movq %rdi, %rbx
leaq 0x17f429(%rip), %rsi    # 0x58b810
leaq -0x180(%rbp), %r15
movl $0x140, %edx            # imm = 0x140
movq %r15, %rdi
callq 0x401070
leaq -0x40(%rbp), %r12
pushq $0x50
popq %rdx
leaq -0x21(%rbp), %rcx
movq %r12, %rdi
movq %r15, %rsi
callq 0x40e4cc
movslq %r14d, %rax
movq (%r12), %rcx
movl (%rcx,%rax,4), %ecx
movl %ecx, (%rbx)
movl %eax, 0x4(%rbx)
pushq $-0x5
popq %rax
testq %rax, %rax
je 0x40c432
movb $0x0, 0xd(%rbx,%rax)
incq %rax
jmp 0x40c423
movl $0x5, 0x10(%rbx)
movb $0x0, 0x14(%rbx)
leaq -0x40(%rbp), %rdi
callq 0x409e52
addq $0x160, %rsp            # imm = 0x160
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/Thilotilo[P]DoaERando/BattleRandomizer.cpp
// Function: DoaERando::Battle::OrganizeBattle()
void Battle::OrganizeBattle()
{
    // Reorder battles so that Generals come first, then rebel forces, then empty slots
    std::vector<BYTE> generalList;
    int numRebels = 0;

    // First, let's just collect the generals and the number of rebel forces
    for (int i = 0; i < 5; ++i)
    {
        if (generals[i] > 0x04)
        {
            generalList.push_back(generals[i]);
        }
        if (generals[i] == 0x04)
        {
            numRebels++;
        }
    }

    int index = 0;

    // assign the generals
    for (auto& general : generalList)
    {
        generals[index++] = general;
    }
    // assign the rebel forces
    for (int i = 0; i < numRebels; ++i)
    {
        generals[index++] = 0x04;
    }
    // assign empty slots
    while (index < 0x05)
    {
        generals[index++] = 0x00;
    }

    battleModified = true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
xorps %xmm0, %xmm0
leaq -0x50(%rbp), %r14
andq $0x0, 0x10(%r14)
movaps %xmm0, (%r14)
movq %rdi, -0x30(%rbp)
leaq 0x8(%rdi), %r12
xorl %ebx, %ebx
xorl %r13d, %r13d
cmpq $0x5, %rbx
je 0x40c4b3
movb (%r12,%rbx), %al
cmpb $0x5, %al
jb 0x40c4a4
leaq (%r12,%rbx), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x409c42
movb (%r15), %al
xorl %ecx, %ecx
cmpb $0x4, %al
sete %cl
addl %ecx, %r13d
incq %rbx
jmp 0x40c484
movq -0x50(%rbp), %rcx
movq -0x48(%rbp), %rdx
xorl %eax, %eax
leaq (%rcx,%rax), %rsi
cmpq %rdx, %rsi
je 0x40c4d2
movb (%rsi), %sil
movb %sil, (%r12,%rax)
incq %rax
jmp 0x40c4bd
addl %eax, %r13d
cmpq %rax, %r13
je 0x40c4ec
movb $0x4, (%r12,%rax)
incq %rax
jmp 0x40c4d5
movb $0x0, (%r12,%r13)
incq %r13
cmpq $0x4, %r13
jbe 0x40c4e4
movq -0x30(%rbp), %rax
movb $0x1, 0x14(%rax)
leaq -0x50(%rbp), %rdi
callq 0x404baa
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x404baa
movq %rbx, %rdi
callq 0x4ba600
// File: /workspace/github_cpp_makefile_star2_O2/Thilotilo[P]DoaERando/BattleRandomizer.cpp
// Function: DoaERando::BattleRandomizer::PlaceGeneralInBattle(unsigned char, int)
bool BattleRandomizer::PlaceGeneralInBattle(BYTE id, int battleId)
{
    if (myBattles[battleId].slotsRemaining == 0)
    {
        return false;
    }
    for (int i = 0; i < 5; ++i)
    {
        if (myBattles[battleId].generals[i] == id)
        {
            return false;
        }
        if (myBattles[battleId].generals[i] == 0x00)
        {
            myBattles[battleId].generals[i] = id;
            myBattles[battleId].slotsRemaining--;
            return true;
        }
    }
    return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movslq %edx, %rax
movq (%rdi), %rdx
imulq $0x18, %rax, %rcx
cmpl $0x0, 0x10(%rdx,%rcx)
je 0x40c5dc
addq %rcx, %rdx
xorl %r8d, %r8d
movq %r8, %rax
cmpq $0x5, %r8
je 0x40c5cf
movb 0x8(%rdx,%rax), %r9b
cmpb %sil, %r9b
je 0x40c5cf
leaq 0x1(%rax), %r8
testb %r9b, %r9b
jne 0x40c5a3
movb %sil, 0x7(%rdx,%r8)
movq (%rdi), %rdx
decl 0x10(%rdx,%rcx)
movb $0x1, %cl
jmp 0x40c5d1
xorl %ecx, %ecx
cmpq $0x5, %rax
setb %al
andb %cl, %al
jmp 0x40c5de
xorl %eax, %eax
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/Thilotilo[P]DoaERando/BattleRandomizer.cpp
// Function: DoaERando::BattleRandomizer::FillBattlesRandomly(std::vector<unsigned char, std::allocator<unsigned char>>, std::vector<int, std::allocator<int>>, DoaERando::RandomNumberGenerator&)
void BattleRandomizer::FillBattlesRandomly(vector<BYTE> generalIds, vector<int> battleIds, RNG& rng)
{
    for (auto& battleId : battleIds)
    {
        int startingIndex = 5 - myBattles[battleId].slotsRemaining;
        for (int i = startingIndex; i < 5; ++i)
        {
            int value = rng.GetRandomInt(0, 9);
            // 60% chance of a general unless this is slot 0, in which case it's 100%
            if (value < 6 || i == 0)
            {
                // Get General
                int tries = 20;
                bool success = false;
                while (!success && tries-- > 0)
                {
                    BYTE generalToInsert = rng.GetRandomValueFromByteVector(generalIds);
                    success = PlaceGeneralInBattle(generalToInsert, battleId);
                }
                if (!success)
                {
                    // There are no more generals in this zone.
                    // Set Rebel Force instead
                    myBattles[battleId].generals[i] = 0x04;
                    myBattles[battleId].slotsRemaining--;
                }
            }
            // 40% chance of a rebel force
            else if (value < 9)
            {
                // Set Rebel Force
                myBattles[battleId].generals[i] = 0x04;
                myBattles[battleId].slotsRemaining--;
            }
        }
        myBattles[battleId].OrganizeBattle();
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %rbx
movq %rsi, %r14
movq %rdi, %r15
movq (%rdx), %r13
movq 0x8(%rdx), %rax
movq %rax, -0x38(%rbp)
cmpq -0x38(%rbp), %r13
je 0x40c6d1
movslq (%r13), %rax
movq (%r15), %rcx
imulq $0x18, %rax, %rax
pushq $0x5
popq %rdx
subl 0x10(%rcx,%rax), %edx
movslq %edx, %r12
cmpq $0x5, %r12
jge 0x40c6b8
movq %rbx, %rdi
xorl %esi, %esi
pushq $0x9
popq %rdx
callq 0x40ed8e
cmpl $0x6, %eax
setge %cl
movq %r12, -0x30(%rbp)
testq %r12, %r12
setne %dl
testb %cl, %dl
jne 0x40c67d
xorl %eax, %eax
pushq $-0x14
popq %r12
testb $0x1, %al
jne 0x40c6ae
testl %r12d, %r12d
je 0x40c6ae
movq %rbx, %rdi
movq %r14, %rsi
callq 0x40edc4
movl (%r13), %edx
movzbl %al, %esi
movq %r15, %rdi
callq 0x40c588
incl %r12d
jmp 0x40c655
cmpl $0x8, %eax
movq -0x30(%rbp), %r12
ja 0x40c6a6
movslq (%r13), %rax
imulq $0x18, %rax, %rax
addq (%r15), %rax
movb $0x4, 0x8(%r12,%rax)
movslq (%r13), %rax
movq (%r15), %rcx
imulq $0x18, %rax, %rax
decl 0x10(%rcx,%rax)
incq %r12
jmp 0x40c624
testb $0x1, %al
movq -0x30(%rbp), %r12
je 0x40c686
jmp 0x40c6a6
movslq (%r13), %rax
imulq $0x18, %rax, %rdi
addq (%r15), %rdi
callq 0x40c456
addq $0x4, %r13
jmp 0x40c605
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/Thilotilo[P]DoaERando/BattleRandomizer.cpp
// Function: DoaERando::BattleRandomizer::FillBattleWithOnlyGenerals(std::vector<unsigned char, std::allocator<unsigned char>>, int, DoaERando::RandomNumberGenerator&)
void BattleRandomizer::FillBattleWithOnlyGenerals(vector<BYTE> generalIds, int battleId, RNG& rng)
{
    int startingIndex = 5 - myBattles[battleId].slotsRemaining;
    for (int i = startingIndex; i < 5; ++i)
    {
        bool success = false;
        while (!success)
        {
            BYTE generalToInsert = rng.GetRandomValueFromByteVector(generalIds);
            success = PlaceGeneralInBattle(generalToInsert, battleId);
        }
    }
    myBattles[battleId].OrganizeBattle();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %rbx
movl %edx, %r15d
movq %rsi, %r12
movq %rdi, %r14
movslq %edx, %rax
movq (%rdi), %rcx
imulq $0x18, %rax, %rax
pushq $0x5
popq %r13
movq %rax, -0x30(%rbp)
subl 0x10(%rcx,%rax), %r13d
cmpl $0x4, %r13d
jg 0x40c739
movq %rbx, %rdi
movq %r12, %rsi
callq 0x40edc4
movzbl %al, %esi
movq %r14, %rdi
movl %r15d, %edx
callq 0x40c588
testb %al, %al
je 0x40c717
incl %r13d
jmp 0x40c711
movq -0x30(%rbp), %rdi
addq (%r14), %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x40c456
nop
// File: /workspace/github_cpp_makefile_star2_O2/Thilotilo[P]DoaERando/BattleRandomizer.cpp
// Function: DoaERando::BattleRandomizer::RandomizeZone3(DoaERando::Generals&, DoaERando::RandomNumberGenerator&)
void BattleRandomizer::RandomizeZone3(Generals& generals, RNG& rng)
{
    // We may want to add special logic to handle Yuan Shu's assassination/joining of
    // Yuan Shao in Ji Zhou, but for now, we're just ignoring that.  There are no
    // special considerations in this zone.

    std::vector<BYTE> generalIds = generals.GetGeneralIdsFromZone(3);

    vector<int> battlesToFill = {0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13};
    // Make sure every general goes to a relevant battle
    for (auto& id : generalIds)
    {
        int battleIndex = rng.GetRandomInt(0, battlesToFill.size() - 1);
        int battleId = battlesToFill[battleIndex];
        while (!PlaceGeneralInBattle(id, battleId))
        {
            battleIndex = ((battleIndex + 1) % battlesToFill.size());
            battleId = battlesToFill[battleIndex];
        }
    }

    // Now fill all battles with generals/rebel forces
    FillBattlesRandomly(generalIds, battlesToFill, rng);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdx, %rbx
movq %rdi, %r14
leaq -0x60(%rbp), %rdi
pushq $0x3
popq %rdx
callq 0x40be82
movups 0x17ed97(%rip), %xmm0   # 0x58b984
leaq -0xb0(%rbp), %rsi
movaps %xmm0, (%rsi)
movabsq $0x1300000012, %rax     # imm = 0x1300000012
movq %rax, 0x10(%rsi)
leaq -0x48(%rbp), %rdi
pushq $0x6
popq %rdx
leaq -0x29(%rbp), %rcx
callq 0x40e4cc
movq -0x60(%rbp), %r12
movq -0x58(%rbp), %r13
cmpq %r13, %r12
je 0x40cc85
movq -0x40(%rbp), %rdx
subq -0x48(%rbp), %rdx
shrq $0x2, %rdx
decl %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x40ed8e
movl %eax, %r15d
cltq
shlq $0x2, %rax
addq -0x48(%rbp), %rax
movl (%rax), %edx
movzbl (%r12), %esi
movq %r14, %rdi
callq 0x40c588
testb %al, %al
jne 0x40cc80
incl %r15d
movslq %r15d, %rax
movq -0x48(%rbp), %rcx
movq -0x40(%rbp), %rsi
subq %rcx, %rsi
sarq $0x2, %rsi
xorl %edx, %edx
divq %rsi
movq %rdx, %r15
movslq %r15d, %rax
leaq (%rcx,%rax,4), %rax
jmp 0x40cc47
incq %r12
jmp 0x40cc1d
leaq -0x90(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x409dc8
leaq -0x78(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x40e502
leaq -0x90(%rbp), %rsi
leaq -0x78(%rbp), %rdx
movq %r14, %rdi
movq %rbx, %rcx
callq 0x40c5e0
leaq -0x78(%rbp), %rdi
callq 0x409e52
leaq -0x90(%rbp), %rdi
callq 0x404baa
leaq -0x48(%rbp), %rdi
callq 0x409e52
leaq -0x60(%rbp), %rdi
callq 0x404baa
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x78(%rbp), %rdi
callq 0x409e52
jmp 0x40cd02
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
callq 0x404baa
jmp 0x40cd1a
jmp 0x40cd17
movq %rax, %rbx
jmp 0x40cd23
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x409e52
leaq -0x60(%rbp), %rdi
callq 0x404baa
movq %rbx, %rdi
callq 0x4ba600
// File: /workspace/github_cpp_makefile_star2_O2/Thilotilo[P]DoaERando/BattleRandomizer.cpp
// Function: DoaERando::BattleRandomizer::RandomizeZone2(std::vector<unsigned char, std::allocator<unsigned char>>&, DoaERando::RandomNumberGenerator&)
void BattleRandomizer::RandomizeZone2(std::vector<BYTE>& generalIds, RNG& rng)
{
    // There are no special considerations in this zone.  We may want to reconsider because
    // Luo Yang can change for the final battle, but for now, we'll leave it intact.

    vector<int> battlesToFill = {0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D};
    // Make sure every general goes to a relevant battle
    for (auto& id : generalIds)
    {
        int battleIndex = rng.GetRandomInt(0, battlesToFill.size() - 1);
        int battleId = battlesToFill[battleIndex];
        while (!PlaceGeneralInBattle(id, battleId))
        {
            battleIndex = ((battleIndex + 1) % battlesToFill.size());
            battleId = battlesToFill[battleIndex];
        }
    }

    // Now fill all battles with generals/rebel forces
    FillBattlesRandomly(generalIds, battlesToFill, rng);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
movups 0x17e12b(%rip), %xmm0   # 0x58babc
leaq -0xa0(%rbp), %rsi
movaps %xmm0, 0x10(%rsi)
movups 0x17e109(%rip), %xmm0   # 0x58baac
movaps %xmm0, (%rsi)
leaq -0x48(%rbp), %rdi
pushq $0x8
popq %rdx
leaq -0x29(%rbp), %rcx
callq 0x40e4cc
movq (%r15), %r13
movq %r15, -0x50(%rbp)
movq 0x8(%r15), %r15
cmpq %r15, %r13
je 0x40da29
movq -0x40(%rbp), %rdx
subq -0x48(%rbp), %rdx
shrq $0x2, %rdx
decl %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x40ed8e
movl %eax, %r12d
cltq
shlq $0x2, %rax
addq -0x48(%rbp), %rax
movl (%rax), %edx
movzbl (%r13), %esi
movq %r14, %rdi
callq 0x40c588
testb %al, %al
jne 0x40da24
incl %r12d
movslq %r12d, %rax
movq -0x48(%rbp), %rcx
movq -0x40(%rbp), %rsi
subq %rcx, %rsi
sarq $0x2, %rsi
xorl %edx, %edx
divq %rsi
movq %rdx, %r12
movslq %r12d, %rax
leaq (%rcx,%rax,4), %rax
jmp 0x40d9eb
incq %r13
jmp 0x40d9c1
leaq -0x80(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x409dc8
leaq -0x68(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x40e502
leaq -0x80(%rbp), %rsi
leaq -0x68(%rbp), %rdx
movq %r14, %rdi
movq %rbx, %rcx
callq 0x40c5e0
leaq -0x68(%rbp), %rdi
callq 0x409e52
leaq -0x80(%rbp), %rdi
callq 0x404baa
leaq -0x48(%rbp), %rdi
callq 0x409e52
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x409e52
jmp 0x40da91
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
callq 0x404baa
jmp 0x40daa1
jmp 0x40da9e
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x409e52
movq %rbx, %rdi
callq 0x4ba600
// File: /workspace/github_cpp_makefile_star2_O2/Thilotilo[P]DoaERando/BattleRandomizer.cpp
// Function: DoaERando::BattleRandomizer::RandomizeZone3(std::vector<unsigned char, std::allocator<unsigned char>>&, DoaERando::RandomNumberGenerator&)
void BattleRandomizer::RandomizeZone3(std::vector<BYTE>& generalIds, RNG& rng)
{
    // There are no special considerations in this zone.

    vector<int> battlesToFill = {0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13};
    // Make sure every general goes to a relevant battle
    for (auto& id : generalIds)
    {
        int battleIndex = rng.GetRandomInt(0, battlesToFill.size() - 1);
        int battleId = battlesToFill[battleIndex];
        while (!PlaceGeneralInBattle(id, battleId))
        {
            battleIndex = ((battleIndex + 1) % battlesToFill.size());
            battleId = battlesToFill[battleIndex];
        }
    }

    // Now fill all battles with generals/rebel forces
    FillBattlesRandomly(generalIds, battlesToFill, rng);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
movups 0x17deb1(%rip), %xmm0   # 0x58b984
leaq -0xa0(%rbp), %rsi
movaps %xmm0, (%rsi)
movabsq $0x1300000012, %rax     # imm = 0x1300000012
movq %rax, 0x10(%rsi)
leaq -0x48(%rbp), %rdi
pushq $0x6
popq %rdx
leaq -0x29(%rbp), %rcx
callq 0x40e4cc
movq (%r15), %r13
movq %r15, -0x50(%rbp)
movq 0x8(%r15), %r15
cmpq %r15, %r13
je 0x40db6e
movq -0x40(%rbp), %rdx
subq -0x48(%rbp), %rdx
shrq $0x2, %rdx
decl %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x40ed8e
movl %eax, %r12d
cltq
shlq $0x2, %rax
addq -0x48(%rbp), %rax
movl (%rax), %edx
movzbl (%r13), %esi
movq %r14, %rdi
callq 0x40c588
testb %al, %al
jne 0x40db69
incl %r12d
movslq %r12d, %rax
movq -0x48(%rbp), %rcx
movq -0x40(%rbp), %rsi
subq %rcx, %rsi
sarq $0x2, %rsi
xorl %edx, %edx
divq %rsi
movq %rdx, %r12
movslq %r12d, %rax
leaq (%rcx,%rax,4), %rax
jmp 0x40db30
incq %r13
jmp 0x40db06
leaq -0x80(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x409dc8
leaq -0x68(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x40e502
leaq -0x80(%rbp), %rsi
leaq -0x68(%rbp), %rdx
movq %r14, %rdi
movq %rbx, %rcx
callq 0x40c5e0
leaq -0x68(%rbp), %rdi
callq 0x409e52
leaq -0x80(%rbp), %rdi
callq 0x404baa
leaq -0x48(%rbp), %rdi
callq 0x409e52
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x409e52
jmp 0x40dbd6
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
callq 0x404baa
jmp 0x40dbe6
jmp 0x40dbe3
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x409e52
movq %rbx, %rdi
callq 0x4ba600
nop
// File: /workspace/github_cpp_makefile_star2_O2/Thilotilo[P]DoaERando/BattleRandomizer.cpp
// Function: DoaERando::BattleRandomizer::RandomizeZone6(std::vector<unsigned char, std::allocator<unsigned char>>&, DoaERando::RandomNumberGenerator&)
void BattleRandomizer::RandomizeZone6(std::vector<BYTE>& generalIds, RNG& rng)
{
    // Ideally, we want to add a special consideration for the Luo battle here.  We would like
    // it to yield the Ma Chao/Ma Dai equivalents when accepting their offer at the town,  but
    // coupling that logic is beyond our scope at the moment, so we're going to fully randomize everything.
    // Note that there is no reason that Lu Bu (4F) can't trigger the recruitable flag, so no need to
    // relegate it to duplicates

    // All the other battles can be filled like normal.
    vector<int> battlesToFill = {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x4F};
    // Make sure every general goes to a relevant battle
    for (auto& id : generalIds)
    {
        int battleIndex = rng.GetRandomInt(0, battlesToFill.size() - 1);
        int battleId = battlesToFill[battleIndex];
        while (!PlaceGeneralInBattle(id, battleId))
        {
            battleIndex = ((battleIndex + 1) % battlesToFill.size());
            battleId = battlesToFill[battleIndex];
        }
    }

    // Now fill all battles with generals/rebel forces
    FillBattlesRandomly(generalIds, battlesToFill, rng);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
movups 0x17da76(%rip), %xmm0   # 0x58b9e0
leaq -0xb0(%rbp), %rsi
movaps %xmm0, 0x10(%rsi)
movups 0x17da54(%rip), %xmm0   # 0x58b9d0
movaps %xmm0, (%rsi)
movl $0x4f, 0x20(%rsi)
leaq -0x48(%rbp), %rdi
pushq $0x9
popq %rdx
leaq -0x29(%rbp), %rcx
callq 0x40e4cc
movq (%r15), %r13
movq %r15, -0x50(%rbp)
movq 0x8(%r15), %r15
cmpq %r15, %r13
je 0x40e009
movq -0x40(%rbp), %rdx
subq -0x48(%rbp), %rdx
shrq $0x2, %rdx
decl %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x40ed8e
movl %eax, %r12d
cltq
shlq $0x2, %rax
addq -0x48(%rbp), %rax
movl (%rax), %edx
movzbl (%r13), %esi
movq %r14, %rdi
callq 0x40c588
testb %al, %al
jne 0x40e004
incl %r12d
movslq %r12d, %rax
movq -0x48(%rbp), %rcx
movq -0x40(%rbp), %rsi
subq %rcx, %rsi
sarq $0x2, %rsi
xorl %edx, %edx
divq %rsi
movq %rdx, %r12
movslq %r12d, %rax
leaq (%rcx,%rax,4), %rax
jmp 0x40dfcb
incq %r13
jmp 0x40dfa1
leaq -0x80(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x409dc8
leaq -0x68(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x40e502
leaq -0x80(%rbp), %rsi
leaq -0x68(%rbp), %rdx
movq %r14, %rdi
movq %rbx, %rcx
callq 0x40c5e0
leaq -0x68(%rbp), %rdi
callq 0x409e52
leaq -0x80(%rbp), %rdi
callq 0x404baa
leaq -0x48(%rbp), %rdi
callq 0x409e52
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x409e52
jmp 0x40e074
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
callq 0x404baa
jmp 0x40e084
jmp 0x40e081
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x409e52
movq %rbx, %rdi
callq 0x4ba600
nop
// File: /workspace/github_cpp_makefile_star2_O2/Thilotilo[P]DoaERando/BattleRandomizer.cpp
// Function: DoaERando::BattleRandomizer::UpdateBattles(DoaERando::ROM&)
void BattleRandomizer::UpdateBattles(ROM& rom)
{
    const int BATTLE0_OFFSET = 0x30D70;

    for (auto& battle : myBattles)
    {
        if (battle.battleModified)
        {
            printf("Battle 0x%02X is now 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X\n",
                   battle.battleId, battle.generals[0], battle.generals[1],
                   battle.generals[2], battle.generals[3], battle.generals[4]);
            int battleOffset = BATTLE0_OFFSET + (5 * battle.battleId);
            for (int i = 0; i < 5; ++i)
            {
                rom.WriteByte(battleOffset + i, battle.generals[i]);
            }
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq (%rdi), %r15
movq 0x8(%rdi), %r12
cmpq %r12, %r15
je 0x40e4bd
cmpb $0x1, 0x14(%r15)
jne 0x40e4b7
movl 0x4(%r15), %esi
movzbl 0x8(%r15), %edx
movzbl 0x9(%r15), %ecx
movzbl 0xa(%r15), %r8d
movzbl 0xb(%r15), %r9d
movzbl 0xc(%r15), %eax
movl %eax, (%rsp)
leaq 0x17d5f1(%rip), %rdi    # 0x58ba72
xorl %eax, %eax
callq 0x4e1140
movl 0x4(%r15), %eax
leal (%rax,%rax,4), %r13d
addl $0x30d70, %r13d         # imm = 0x30D70
xorl %r14d, %r14d
cmpq $0x5, %r14
je 0x40e4b7
movzbl 0x8(%r15,%r14), %edx
leal (%r14,%r13), %esi
movq %rbx, %rdi
callq 0x404a00
incq %r14
jmp 0x40e49a
addq $0x18, %r15
jmp 0x40e44e
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/Thilotilo[P]DoaERando/NPCManipulator.cpp
// Function: DoaERando::NPCManipulator::ReplaceSongYongAndSongRen(unsigned char, unsigned char)
void NPCManipulator::ReplaceSongYongAndSongRen(BYTE generalId1, BYTE generalId2)
{
    // This sets the NPC Data.
    myRom.WriteByte(0x31AC9, generalId1);
    myRom.WriteByte(0x31AD0, generalId2);
    // This sets the text strings.
    myRom.WriteByte(0x36207, generalId1);
    myRom.WriteByte(0x3620B, generalId2);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %edx, %ebx
movl %esi, %r14d
movq %rdi, %r15
movq (%rdi), %rdi
movl $0x31ac9, %esi          # imm = 0x31AC9
movl %r14d, %edx
callq 0x404a00
movq (%r15), %rdi
movl $0x31ad0, %esi          # imm = 0x31AD0
movl %ebx, %edx
callq 0x404a00
movq (%r15), %rdi
movl $0x36207, %esi          # imm = 0x36207
movl %r14d, %edx
callq 0x404a00
movq (%r15), %rdi
movl $0x3620b, %esi          # imm = 0x3620B
movl %ebx, %edx
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x404a00
// File: /workspace/github_cpp_makefile_star2_O2/Thilotilo[P]DoaERando/NPCManipulator.cpp
// Function: DoaERando::NPCManipulator::ReplaceChenDeng(unsigned char)
void NPCManipulator::ReplaceChenDeng(BYTE generalId)
{
    myRom.WriteByte(0x311C0, generalId);
    // This replaces the name given by Chen Deng's father
    myRom.WriteByte(0x2963D, generalId);
    // This is a temporary fix for extra long names before
    // we overhaul the text stuff.
    // It rewrites (so)n to s(on) so that it can create a
    // newline before the general name.
    myRom.WriteByte(0x29639, 0x2E);
    myRom.WriteByte(0x2963A, 0xE0);
    myRom.WriteByte(0x2963B, 0xEC);
    myRom.WriteByte(0x2963C, 0xD2);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movl %esi, %r14d
movq %rdi, %rbx
movq (%rdi), %rdi
movl $0x311c0, %esi          # imm = 0x311C0
movl %r14d, %edx
callq 0x404a00
movq (%rbx), %rdi
movl $0x2963d, %esi          # imm = 0x2963D
movl %r14d, %edx
callq 0x404a00
movq (%rbx), %rdi
pushq $0x2e
popq %rdx
movl $0x29639, %esi          # imm = 0x29639
callq 0x404a00
movq (%rbx), %rdi
movl $0x2963a, %esi          # imm = 0x2963A
movl $0xe0, %edx
callq 0x404a00
movq (%rbx), %rdi
movl $0x2963b, %esi          # imm = 0x2963B
movl $0xec, %edx
callq 0x404a00
movq (%rbx), %rdi
movl $0x2963c, %esi          # imm = 0x2963C
movl $0xd2, %edx
popq %rbx
popq %r14
popq %rbp
jmp 0x404a00
nop