LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_cpp_makefile_star2_O1/Thilotilo[P]DoaERando/General.cpp
// Function: DoaERando::General::WriteEncounterableBit(unsigned char, bool, DoaERando::ROM&)
void General::WriteEncounterableBit(BYTE id, bool isEncounterable, ROM& rom)
{
    const int ENCOUNTERABLE_OFFSET = 0x35722;
    const BYTE bitmask = 1 << (7 - (id % 8));
    BYTE currentByte = rom.ReadByte(ENCOUNTERABLE_OFFSET + (id / 8));
    BYTE newByte;
    if (isEncounterable)
    {
        newByte = currentByte | bitmask;
    }
    else
    {
        newByte = currentByte & (~bitmask);
    }

    rom.WriteByte(ENCOUNTERABLE_OFFSET + (id / 8), newByte);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %rbx
movl %edi, %r14d
notb %r14b
movl %r14d, %ecx
andb $0x7, %cl
movb $0x1, %r13b
shlb %cl, %r13b
movl %esi, %r15d
shrb $0x3, %dil
movzbl %dil, %r12d
addl $0x35722, %r12d         # imm = 0x35722
movq %rdx, %rdi
movl %r12d, %esi
callq 0x4049fe
movb $-0x2, %dl
movl %r14d, %ecx
rolb %cl, %dl
orb %al, %r13b
andb %al, %dl
movzbl %r13b, %eax
movzbl %dl, %ecx
testl %r15d, %r15d
cmovnel %eax, %ecx
movzbl %cl, %edx
movq %rbx, %rdi
movl %r12d, %esi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x404a28
nop
// File: /workspace/github_cpp_makefile_star2_O1/Thilotilo[P]DoaERando/General.cpp
// Function: DoaERando::General::WriteRecruitableBit(unsigned char, bool, DoaERando::ROM&)
void General::WriteRecruitableBit(BYTE id, bool isRecruitable, ROM& rom)
{
    const int RECRUITABLE_OFFSET = 0x3B153;
    const BYTE bitmask = 1 << (7 - (id % 8));
    BYTE currentByte = rom.ReadByte(RECRUITABLE_OFFSET + (id / 8));
    BYTE newByte;
    if (isRecruitable)
    {
        newByte = currentByte | bitmask;
    }
    else
    {
        newByte = currentByte & (~bitmask);
    }

    rom.WriteByte(RECRUITABLE_OFFSET + (id / 8), newByte);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %rbx
movl %edi, %r14d
notb %r14b
movl %r14d, %ecx
andb $0x7, %cl
movb $0x1, %r13b
shlb %cl, %r13b
movl %esi, %r15d
shrb $0x3, %dil
movzbl %dil, %r12d
addl $0x3b153, %r12d         # imm = 0x3B153
movq %rdx, %rdi
movl %r12d, %esi
callq 0x4049fe
movb $-0x2, %dl
movl %r14d, %ecx
rolb %cl, %dl
orb %al, %r13b
andb %al, %dl
movzbl %r13b, %eax
movzbl %dl, %ecx
testl %r15d, %r15d
cmovnel %eax, %ecx
movzbl %cl, %edx
movq %rbx, %rdi
movl %r12d, %esi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x404a28
nop
// File: /workspace/github_cpp_makefile_star2_O1/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 0x1804de(%rip), %rdi    # 0x58c702
xorl %eax, %eax
callq 0x4e21a0
movzbl 0x4(%rbx), %esi
leaq 0x1804d1(%rip), %rdi    # 0x58c707
xorl %eax, %eax
callq 0x4e21a0
movl (%rbx), %esi
leaq 0x1804ce(%rip), %rdi    # 0x58c714
xorl %eax, %eax
callq 0x4e21a0
movzbl 0x5(%rbx), %esi
leaq 0x1804cc(%rip), %rdi    # 0x58c724
xorl %eax, %eax
callq 0x4e21a0
movzbl 0x6(%rbx), %esi
leaq 0x1804c6(%rip), %rdi    # 0x58c730
xorl %eax, %eax
callq 0x4e21a0
movzbl 0x7(%rbx), %esi
leaq 0x1804be(%rip), %rdi    # 0x58c73a
xorl %eax, %eax
callq 0x4e21a0
movzbl 0xe(%rbx), %esi
leaq 0x1804b6(%rip), %rdi    # 0x58c744
xorl %eax, %eax
callq 0x4e21a0
movzbl 0x8(%rbx), %esi
leaq 0x1804ae(%rip), %rdi    # 0x58c74e
xorl %eax, %eax
callq 0x4e21a0
movzbl 0xb(%rbx), %esi
movzbl 0xc(%rbx), %edx
leaq 0x1804a3(%rip), %rdi    # 0x58c759
xorl %eax, %eax
callq 0x4e21a0
movzbl 0xa(%rbx), %esi
leaq 0x1804a2(%rip), %rdi    # 0x58c76a
xorl %eax, %eax
callq 0x4e21a0
movzbl 0xd(%rbx), %esi
leaq 0x18049e(%rip), %rdi    # 0x58c778
xorl %eax, %eax
callq 0x4e21a0
movzbl 0x9(%rbx), %esi
leaq 0x1804a3(%rip), %rdi    # 0x58c78f
xorl %eax, %eax
callq 0x4e21a0
movzbl 0x23(%rbx), %esi
leaq 0x1804a2(%rip), %rdi    # 0x58c7a0
xorl %eax, %eax
callq 0x4e21a0
movzbl 0x24(%rbx), %esi
leaq 0x1804a4(%rip), %rdi    # 0x58c7b4
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x4e21a0
nopl (%rax)
// File: /workspace/github_cpp_makefile_star2_O1/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 $0x52, %r13b
movabsq $0x80000000800001, %r15 # imm = 0x80000000800001
testb %r13b, %r13b
je 0x40c409
leal -0x4d(%r13), %eax
movzbl %al, %r12d
movq %rbx, %rdi
movl %r12d, %esi
callq 0x40c48a
leal -0x71(%r12), %eax
cmpl $0x37, %eax
ja 0x40c3ce
btq %rax, %r15
jb 0x40c3d4
cmpl $0x57, %r12d
jne 0x40c409
movq %rbx, %rdi
movl %r12d, %esi
callq 0x40c432
addl $0x28010, %eax          # imm = 0x28010
movl %eax, -0x2c(%rbp)
movq 0x20(%rbx), %rsi
cmpq 0x28(%rbx), %rsi
je 0x40c3fd
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x20(%rbx)
jmp 0x40c409
movq %r14, %rdi
leaq -0x2c(%rbp), %rdx
callq 0x40d11a
incb %r13b
cmpb $0x25, %r13b
jne 0x40c3a6
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O1/Thilotilo[P]DoaERando/Generals.cpp
// Function: DoaERando::Generals::GetGeneralBankAddress(unsigned char)
int Generals::GetGeneralBankAddress(BYTE id)
{
    const int GENERAL_ADDRESSES_LSB_START = 0x32610;
    const int GENERAL_ADDRESSES_MSB_START = 0x32710;
    int msb = myRom.ReadByte(GENERAL_ADDRESSES_MSB_START + id);
    int lsb = myRom.ReadByte(GENERAL_ADDRESSES_LSB_START + id);
    int address = (msb << 8) + lsb;
    return address;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %ebx
movq %rdi, %r14
movq 0x48(%rdi), %rdi
leal 0x32710(%rbx), %esi
callq 0x4049fe
movzbl %al, %r15d
movq 0x48(%r14), %rdi
addl $0x32610, %ebx          # imm = 0x32610
movl %ebx, %esi
callq 0x4049fe
movzbl %al, %eax
shll $0x8, %r15d
orl %eax, %r15d
movl %r15d, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O1/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 %r14
pushq %rbx
subq $0x30, %rsp
movl %esi, %r14d
movq %rdi, %rbx
callq 0x40c51a
testb %al, %al
je 0x40c4b8
movzbl %r14b, %esi
movq %rbx, %rdi
addq $0x30, %rsp
popq %rbx
popq %r14
popq %rbp
jmp 0x40c5b2
movzbl %r14b, %r14d
movq %rbx, %rdi
movl %r14d, %esi
callq 0x40c432
leal 0x28010(%rax), %esi
movq 0x48(%rbx), %rcx
leaq -0x38(%rbp), %rdi
movl %r14d, %edx
callq 0x40ba9c
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x40c505
movq -0x18(%rbp), %rax
movq %rax, 0x20(%rsi)
movups -0x38(%rbp), %xmm0
movups -0x28(%rbp), %xmm1
movups %xmm1, 0x10(%rsi)
movups %xmm0, (%rsi)
addq $0x28, 0x8(%rbx)
jmp 0x40c511
leaq -0x38(%rbp), %rdx
movq %rbx, %rdi
callq 0x40d252
addq $0x30, %rsp
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/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), %rax
cmpq %rax, 0x8(%rdi)
setne %r15b
je 0x40c59f
movq %rdi, %rbx
movl (%rax), %r12d
movzbl %sil, %esi
movl %esi, -0x2c(%rbp)
callq 0x40c432
addl $0x28010, %eax          # imm = 0x28010
cmpl %eax, %r12d
je 0x40c59f
movl $0x28, %r12d
xorl %r13d, %r13d
incq %r13
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
movabsq $-0x3333333333333333, %rdx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rdx, %rcx
cmpq %r13, %rcx
seta %r15b
jbe 0x40c59f
movl (%rax,%r12), %r14d
addq $0x28, %r12
movq %rbx, %rdi
movl -0x2c(%rbp), %esi
callq 0x40c432
addl $0x28010, %eax          # imm = 0x28010
cmpl %eax, %r14d
jne 0x40c55a
movl %r15d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O1/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 0x40c432
movq (%rbx), %rcx
movq 0x8(%rbx), %rdx
cmpq %rdx, %rcx
je 0x40c5e1
addl $0x28010, %eax          # imm = 0x28010
cmpl %eax, (%rcx)
jne 0x40c5d8
incb 0x5(%rcx)
addq $0x28, %rcx
cmpq %rdx, %rcx
jne 0x40c5d1
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/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
movl $0x8, %esi
callq 0x40c67e
cltq
movq (%rbx), %r14
leaq (%rax,%rax,4), %rax
movb $0x3, 0x8(%r14,%rax,8)
movq %rbx, %rdi
movl $0x9, %esi
callq 0x40c67e
cltq
leaq (%rax,%rax,4), %rax
movb $0x2, %r15b
movb %r15b, 0x8(%r14,%rax,8)
movq %rbx, %rdi
movl $0x9e, %esi
callq 0x40c67e
cltq
leaq (%rax,%rax,4), %rax
movb $0x0, 0x8(%r14,%rax,8)
movq %rbx, %rdi
movl $0xb8, %esi
callq 0x40c67e
cltq
leaq (%rax,%rax,4), %rax
movb %r15b, 0x8(%r14,%rax,8)
movq %rbx, %rdi
movl $0xb9, %esi
callq 0x40c67e
cltq
leaq (%rax,%rax,4), %rax
movb %r15b, 0x8(%r14,%rax,8)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O1/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:
movq (%rdi), %rcx
movq 0x8(%rdi), %rdi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
subq %rcx, %rdi
je 0x40c70c
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
sarq $0x3, %rdi
movabsq $-0x3333333333333333, %rdx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rdi, %rdx
movzbl %sil, %edi
cmpq $0x1, %rdx
adcq $0x0, %rdx
negl %edi
xorl %r8d, %r8d
leaq (%r8,%r8,4), %rbx
movzbl 0x5(%rcx,%rbx,8), %r11d
testl %r11d, %r11d
setne %r10b
je 0x40c6f6
movzbl 0x4(%rcx,%rbx,8), %ebx
cmpb %sil, %bl
je 0x40c6f3
addl %ebx, %r11d
incl %ebx
cmpl %r11d, %ebx
setb %r10b
jae 0x40c6f6
leal (%rdi,%rbx), %r14d
incl %r14d
incl %ebx
cmpl $0x1, %r14d
jne 0x40c6db
movl %r8d, %r9d
testb %r10b, %r10b
jne 0x40c705
incq %r8
cmpq %rdx, %r8
jne 0x40c6b9
jmp 0x40c708
movl %r9d, %eax
popq %rbx
popq %r14
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O1/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 %rbx
movslq %esi, %rcx
movq (%rdi), %rax
movq 0x18(%rdi), %rsi
leaq (%rcx,%rcx,4), %rcx
movq 0x20(%rdi), %rdi
cmpq %rdi, %rsi
setne %r8b
movl %r8d, %r10d
je 0x40c756
movl (%rax,%rcx,8), %r9d
movl %r8d, %r10d
cmpl %r9d, (%rsi)
je 0x40c756
leaq 0x4(%rsi), %r11
cmpq %rdi, %r11
setne %r10b
je 0x40c756
leaq 0x4(%r11), %rbx
cmpl %r9d, (%r11)
movq %rbx, %r11
jne 0x40c741
testb %r10b, %r10b
jne 0x40c7ae
movslq %edx, %rdx
leaq (%rdx,%rdx,4), %rdx
cmpq %rdi, %rsi
je 0x40c789
movl (%rax,%rdx,8), %r9d
cmpl %r9d, (%rsi)
je 0x40c789
addq $0x4, %rsi
cmpq %rdi, %rsi
setne %r8b
je 0x40c789
leaq 0x4(%rsi), %r10
cmpl %r9d, (%rsi)
movq %r10, %rsi
jne 0x40c774
testb %r8b, %r8b
jne 0x40c7ae
leaq (%rax,%rcx,8), %rcx
leaq (%rax,%rdx,8), %rax
movzwl 0x4(%rcx), %edx
movb 0x4(%rax), %sil
movb %sil, 0x4(%rcx)
movb 0x5(%rax), %sil
movb %sil, 0x5(%rcx)
movw %dx, 0x4(%rax)
popq %rbx
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O1/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 %rbx
movslq %esi, %rcx
movq (%rdi), %rax
movq 0x18(%rdi), %rsi
leaq (%rcx,%rcx,4), %rcx
movq 0x20(%rdi), %rdi
cmpq %rdi, %rsi
setne %r8b
movl %r8d, %r10d
je 0x40c82c
movl (%rax,%rcx,8), %r9d
movl %r8d, %r10d
cmpl %r9d, (%rsi)
je 0x40c82c
leaq 0x4(%rsi), %r11
cmpq %rdi, %r11
setne %r10b
je 0x40c82c
leaq 0x4(%r11), %rbx
cmpl %r9d, (%r11)
movq %rbx, %r11
jne 0x40c817
testb %r10b, %r10b
jne 0x40c87a
movslq %edx, %rdx
leaq (%rdx,%rdx,4), %rdx
cmpq %rdi, %rsi
je 0x40c85f
movl (%rax,%rdx,8), %r9d
cmpl %r9d, (%rsi)
je 0x40c85f
addq $0x4, %rsi
cmpq %rdi, %rsi
setne %r8b
je 0x40c85f
leaq 0x4(%rsi), %r10
cmpl %r9d, (%rsi)
movq %r10, %rsi
jne 0x40c84a
testb %r8b, %r8b
jne 0x40c87a
leaq (%rax,%rcx,8), %rcx
leaq (%rax,%rdx,8), %rax
movb 0x8(%rcx), %dl
movb 0x8(%rax), %sil
movb %sil, 0x8(%rcx)
movb %dl, 0x8(%rax)
popq %rbx
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O1/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 %rbx
pushq %rax
movq (%rdi), %r14
movq 0x8(%rdi), %r15
cmpq %r15, %r14
je 0x40c8bd
movq %rsi, %rbx
cmpb $0x0, 0x8(%r14)
jne 0x40c8b4
movq %rbx, %rdi
movl $0x2, %esi
movl $0x8, %edx
callq 0x410846
movb %al, 0x8(%r14)
addq $0x28, %r14
cmpq %r15, %r14
jne 0x40c897
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/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 (%rdi), %r14
movq 0x8(%rdi), %r15
cmpq %r15, %r14
je 0x40c9a6
movq %rsi, %rbx
movabsq $0x2000004000001, %r12  # imm = 0x2000004000001
movzbl 0x4(%r14), %eax
addl $-0x57, %eax
cmpl $0x31, %eax
ja 0x40c971
btq %rax, %r12
jb 0x40c99d
movq %r14, %rdi
movq %rbx, %rsi
callq 0x40bcf6
movq %r14, %rdi
movq %rbx, %rsi
callq 0x40bd2e
movq %r14, %rdi
movq %rbx, %rsi
callq 0x40bd66
movq %r14, %rdi
movq %rbx, %rsi
callq 0x40bd92
addq $0x28, %r14
cmpq %r15, %r14
jne 0x40c95e
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O1/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 0x40c67e
cltq
movq (%r14), %rdi
shlq $0x3, %rax
leaq (%rax,%rax,4), %r12
movb %r15b, 0x8(%rdi,%r12)
addq %r12, %rdi
movq %rbx, %rsi
callq 0x40bcf6
movq (%r14), %rdi
addq %r12, %rdi
movq %rbx, %rsi
callq 0x40bd2e
movq (%r14), %rdi
addq %r12, %rdi
movq %rbx, %rsi
callq 0x40bd66
addq (%r14), %r12
movq %r12, %rdi
movq %rbx, %rsi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x40bd92
// File: /workspace/github_cpp_makefile_star2_O1/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), %r14
movq 0x8(%rdi), %rax
movq %rax, -0x30(%rbp)
cmpq %rax, %r14
je 0x40cb95
movq %rdi, %rbx
movl $0xff, %r12d
movq 0x48(%rbx), %rsi
movq %r14, %rdi
callq 0x40bfde
movq %r14, %rdi
callq 0x40c210
cmpb $0x0, 0x5(%r14)
movl $0xfffd7ff0, %eax       # imm = 0xFFFD7FF0
je 0x40cb87
xorl %r13d, %r13d
movl (%r14), %r15d
addl %eax, %r15d
movl %r15d, %edx
shrl $0x8, %edx
movq 0x48(%rbx), %rdi
movzbl 0x4(%r14), %eax
leal (%rax,%r13), %esi
addl $0x32710, %esi          # imm = 0x32710
andl %r12d, %edx
callq 0x404a28
movq 0x48(%rbx), %rdi
movzbl 0x4(%r14), %eax
leal (%rax,%r13), %esi
addl $0x32610, %esi          # imm = 0x32610
andl %r12d, %r15d
movl %r15d, %edx
callq 0x404a28
incl %r13d
movzbl 0x5(%r14), %eax
cmpl %eax, %r13d
movl $0xfffd7ff0, %eax       # imm = 0xFFFD7FF0
jb 0x40cb30
addq $0x28, %r14
cmpq -0x30(%rbp), %r14
jne 0x40cb0d
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/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 %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
movl $0x71, %esi
callq 0x40c67e
movl %eax, %r15d
movq %r14, %rdi
movl $0x23, %esi
movl $0x32, %edx
callq 0x410846
movslq %r15d, %rcx
movq (%rbx), %rdx
leaq (%rcx,%rcx,4), %rcx
movb %al, 0xd(%rdx,%rcx,8)
movq %rbx, %rdi
movl $0x88, %esi
callq 0x40c67e
movl %eax, %r15d
movq %r14, %rdi
movl $0x23, %esi
movl $0x32, %edx
callq 0x410846
movslq %r15d, %rcx
movq (%rbx), %rdx
leaq (%rcx,%rcx,4), %rcx
movb %al, 0xd(%rdx,%rcx,8)
movq %rbx, %rdi
movl $0x57, %esi
callq 0x40c67e
movl %eax, %r15d
movq %r14, %rdi
movl $0x23, %esi
movl $0x32, %edx
callq 0x410846
movslq %r15d, %rcx
movq (%rbx), %rdx
leaq (%rcx,%rcx,4), %rcx
movb %al, 0xd(%rdx,%rcx,8)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/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 0x40c67e
movl %eax, %r15d
movq %r14, %rdi
movl $0xb4, %esi
movl $0xdc, %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 $0xb4, %esi
movl $0xdc, %edx
callq 0x410846
movq (%rbx), %rcx
movb %al, 0x7(%rcx,%r15)
movq %r14, %rdi
movl $0xb4, %esi
movl $0xdc, %edx
callq 0x410846
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_O1/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 (%rsi), %r15
movq 0x8(%rsi), %r12
cmpq %r12, %r15
je 0x40cf79
movq %rdi, %rbx
leaq 0x30(%rdi), %r14
movzbl (%r15), %esi
movq %rbx, %rdi
callq 0x40c67e
cltq
leaq (%rax,%rax,4), %r13
leaq (,%r13,8), %rdx
addq (%rbx), %rdx
movq 0x38(%rbx), %rsi
cmpq 0x40(%rbx), %rsi
je 0x40cf60
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x38(%rbx)
jmp 0x40cf68
movq %r14, %rdi
callq 0x40d404
movq (%rbx), %rax
movb $0x0, 0x23(%rax,%r13,8)
incq %r15
cmpq %r12, %r15
jne 0x40cf2b
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %rax
movq %rdi, %rbx
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movq (%rsi), %r13
movq 0x8(%rsi), %r12
cmpq %r12, %r13
je 0x40d063
movl %edx, %r14d
movq %rsi, %r15
movl (%r13), %eax
movq 0x30(%r15), %rdx
movq 0x38(%r15), %rcx
cmpq %rcx, %rdx
setne %sil
je 0x40cfee
cmpl %eax, (%rdx)
je 0x40cfee
addq $0x4, %rdx
cmpq %rcx, %rdx
setne %sil
je 0x40cfee
leaq 0x4(%rdx), %rdi
cmpl %eax, (%rdx)
movq %rdi, %rdx
jne 0x40cfda
testb %sil, %sil
jne 0x40d056
movq 0x18(%r15), %rdx
movq 0x20(%r15), %rcx
cmpq %rcx, %rdx
setne %sil
je 0x40d020
cmpl %eax, (%rdx)
je 0x40d020
addq $0x4, %rdx
cmpq %rcx, %rdx
setne %sil
je 0x40d020
leaq 0x4(%rdx), %rdi
cmpl %eax, (%rdx)
movq %rdi, %rdx
jne 0x40d00c
testb %sil, %sil
jne 0x40d056
cmpb %r14b, 0x8(%r13)
jne 0x40d056
movb 0x4(%r13), %al
addb 0x5(%r13), %al
decb %al
movb %al, -0x29(%rbp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x40d04a
movb %al, (%rsi)
incq 0x8(%rbx)
jmp 0x40d056
movq %rbx, %rdi
leaq -0x29(%rbp), %rdx
callq 0x40ad06
addq $0x28, %r13
cmpq %r12, %r13
jne 0x40cfbd
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x40d085
callq 0x410b90
movq %r14, %rdi
callq 0x4bb660
nop
// File: /workspace/github_cpp_makefile_star2_O1/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
movups %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movq (%rsi), %r15
movq 0x8(%rsi), %r12
cmpq %r12, %r15
je 0x40d0f1
leaq -0x21(%rbp), %r14
movb 0x4(%r15), %al
addb 0x5(%r15), %al
decb %al
movb %al, -0x21(%rbp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x40d0dd
movb %al, (%rsi)
incq 0x8(%rbx)
jmp 0x40d0e8
movq %rbx, %rdi
movq %r14, %rdx
callq 0x40ad06
addq $0x28, %r15
cmpq %r12, %r15
jne 0x40d0be
movq %rbx, %rax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x40d111
callq 0x410b90
movq %r14, %rdi
callq 0x4bb660
nop
// File: /workspace/github_cpp_makefile_star2_O1/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 0x17f349(%rip), %rsi    # 0x58c840
leaq -0x180(%rbp), %r15
movl $0x140, %edx            # imm = 0x140
movq %r15, %rdi
callq 0x401070
leaq -0x40(%rbp), %r12
leaq -0x21(%rbp), %rcx
movl $0x50, %edx
movq %r12, %rdi
movq %r15, %rsi
callq 0x40ff5a
movslq %r14d, %rax
movq (%r12), %rdi
movl (%rdi,%rax,4), %ecx
movl %ecx, (%rbx)
movl %eax, 0x4(%rbx)
xorl %eax, %eax
movb %al, 0xc(%rbx)
movl $0x0, 0x8(%rbx)
movl $0x5, 0x10(%rbx)
movb %al, 0x14(%rbx)
testq %rdi, %rdi
je 0x40d552
callq 0x410b90
addq $0x160, %rsp            # imm = 0x160
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/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 -0x40(%rbp), %r14
movaps %xmm0, (%r14)
movq $0x0, 0x10(%r14)
movq %rdi, -0x48(%rbp)
leaq 0x8(%rdi), %r13
xorl %ebx, %ebx
xorl %ecx, %ecx
movl %ecx, %r12d
leaq (%rbx,%r13), %r15
movb (%r13,%rbx), %al
cmpb $0x5, %al
jb 0x40d5bf
movq -0x38(%rbp), %rsi
cmpq -0x30(%rbp), %rsi
je 0x40d5b4
movb %al, (%rsi)
incq -0x38(%rbp)
jmp 0x40d5bf
movq %r14, %rdi
movq %r15, %rdx
callq 0x40adf8
movb (%r15), %al
xorl %ecx, %ecx
cmpb $0x4, %al
sete %cl
addl %r12d, %ecx
incq %rbx
cmpq $0x5, %rbx
jne 0x40d592
movq -0x40(%rbp), %r14
movq -0x38(%rbp), %rdx
xorl %r15d, %r15d
cmpq %rdx, %r14
je 0x40d5fd
leaq (%r14,%r15), %rsi
incq %rsi
movb -0x1(%rsi), %dil
movb %dil, (%r13,%r15)
incq %r15
cmpq %rdx, %rsi
jne 0x40d5e5
testl %ecx, %ecx
movq -0x48(%rbp), %r13
je 0x40d63c
xorl %ebx, %ebx
cmpb $0x4, %al
sete %bl
movl %r15d, %eax
leaq (%rax,%r13), %rdi
addq $0x8, %rdi
leal (%r12,%rbx), %edx
decl %edx
incq %rdx
movl $0x4, %esi
callq 0x401080
addl %ebx, %r12d
negl %r12d
xorl %eax, %eax
decl %eax
cmpl %eax, %r12d
jne 0x40d632
subl %eax, %r15d
cmpl $0x4, %r15d
ja 0x40d65f
movl %r15d, %eax
leaq (%rax,%r13), %rdi
addq $0x8, %rdi
movl $0x4, %edx
subl %r15d, %edx
incq %rdx
xorl %esi, %esi
callq 0x401080
movb $0x1, 0x14(%r13)
testq %r14, %r14
je 0x40d671
movq %r14, %rdi
callq 0x410b90
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x40d691
callq 0x410b90
movq %rbx, %rdi
callq 0x4bb660
nop
// File: /workspace/github_cpp_makefile_star2_O1/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, %rcx
movq (%rdi), %rax
leaq (%rcx,%rcx,2), %rcx
cmpl $0x0, 0x10(%rax,%rcx,8)
je 0x40d767
leaq (%rax,%rcx,8), %rdx
movb $0x1, %al
xorl %r8d, %r8d
movb 0x8(%rdx,%r8), %r9b
cmpb %sil, %r9b
je 0x40d763
testb %r9b, %r9b
je 0x40d76b
cmpq $0x4, %r8
leaq 0x1(%r8), %r9
setb %al
movq %r9, %r8
cmpq $0x5, %r9
jne 0x40d740
xorl %ecx, %ecx
jmp 0x40d779
xorl %eax, %eax
jmp 0x40d77b
movb %sil, 0x8(%rdx,%r8)
movq (%rdi), %rdx
decl 0x10(%rdx,%rcx,8)
movb $0x1, %cl
andb %cl, %al
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O1/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 (%rdx), %r12
movq 0x8(%rdx), %rax
movq %rax, -0x30(%rbp)
cmpq %rax, %r12
je 0x40d884
movq %rcx, %rbx
movq %rsi, %r14
movq %rdi, %r15
movslq (%r12), %rax
movq (%r15), %rcx
leaq (%rax,%rax,2), %rax
movslq 0x10(%rcx,%rax,8), %rax
testq %rax, %rax
jle 0x40d862
movl $0x5, %r13d
subq %rax, %r13
movq %rbx, %rdi
xorl %esi, %esi
movl $0x9, %edx
callq 0x41086c
cmpl $0x6, %eax
setge %cl
testq %r13, %r13
setne %dl
testb %cl, %dl
jne 0x40d82c
movq %r13, -0x38(%rbp)
movl $0x14, %r13d
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4108c0
movl (%r12), %edx
movzbl %al, %esi
movq %r15, %rdi
callq 0x40d722
testb %al, %al
jne 0x40d822
leal -0x1(%r13), %ecx
cmpl $0x1, %r13d
movl %ecx, %r13d
ja 0x40d7f7
testb %al, %al
movq -0x38(%rbp), %r13
je 0x40d831
jmp 0x40d855
cmpl $0x8, %eax
jg 0x40d855
movslq (%r12), %rax
leaq (%rax,%rax,2), %rax
shlq $0x3, %rax
addq (%r15), %rax
movb $0x4, 0x8(%r13,%rax)
movslq (%r12), %rax
movq (%r15), %rcx
leaq (%rax,%rax,2), %rax
decl 0x10(%rcx,%rax,8)
incq %r13
cmpl $0x5, %r13d
jne 0x40d7ce
movslq (%r12), %rax
leaq (%rax,%rax,2), %rdi
shlq $0x3, %rdi
addq (%r15), %rdi
callq 0x40d562
addq $0x4, %r12
cmpq -0x30(%rbp), %r12
jne 0x40d7ac
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O1/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, %r14
movq %rdi, %rbx
movslq %edx, %rax
movq (%rdi), %rcx
leaq (%rax,%rax,2), %rax
movq %rax, -0x30(%rbp)
movl 0x10(%rcx,%rax,8), %eax
testl %eax, %eax
jle 0x40d8f3
movl %edx, %r12d
movq %rsi, %r13
movl $0x5, %r15d
subl %eax, %r15d
movq %r14, %rdi
movq %r13, %rsi
callq 0x4108c0
movzbl %al, %esi
movq %rbx, %rdi
movl %r12d, %edx
callq 0x40d722
testb %al, %al
je 0x40d8cd
incl %r15d
cmpl $0x5, %r15d
jne 0x40d8cd
movq -0x30(%rbp), %rdi
shlq $0x3, %rdi
addq (%rbx), %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x40d562
nop
// File: /workspace/github_cpp_makefile_star2_O1/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 0x17d891(%rip), %xmm0   # 0x58caec
leaq -0xa0(%rbp), %rsi
movaps %xmm0, 0x10(%rsi)
movups 0x17d86f(%rip), %xmm0   # 0x58cadc
movaps %xmm0, (%rsi)
leaq -0x48(%rbp), %rdi
leaq -0x29(%rbp), %rcx
movl $0x8, %edx
callq 0x40ff5a
movq (%r15), %r13
movq %r15, -0x50(%rbp)
movq 0x8(%r15), %r15
cmpq %r15, %r13
je 0x40f2ee
movq -0x40(%rbp), %rdx
subq -0x48(%rbp), %rdx
shrq $0x2, %rdx
decl %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x41086c
movl %eax, %r12d
cltq
movq -0x48(%rbp), %rcx
movl (%rcx,%rax,4), %edx
movzbl (%r13), %esi
movq %r14, %rdi
callq 0x40d722
testb %al, %al
jne 0x40f2e9
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
jmp 0x40f2b3
incq %r13
jmp 0x40f28d
leaq -0x80(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x40ab9e
leaq -0x68(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x40ff98
leaq -0x80(%rbp), %rsi
leaq -0x68(%rbp), %rdx
movq %r14, %rdi
movq %rbx, %rcx
callq 0x40d77e
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0x40f329
callq 0x410b90
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x40f337
callq 0x410b90
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x40f345
callq 0x410b90
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0x40f36a
callq 0x410b90
jmp 0x40f36a
movq %rax, %rbx
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x40f37f
callq 0x410b90
jmp 0x40f37f
jmp 0x40f37c
movq %rax, %rbx
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x40f38d
callq 0x410b90
movq %rbx, %rdi
callq 0x4bb660
nop
// File: /workspace/github_cpp_makefile_star2_O1/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 0x17d5fd(%rip), %xmm0   # 0x58c9b4
leaq -0xa0(%rbp), %rsi
movaps %xmm0, (%rsi)
movabsq $0x1300000012, %rax     # imm = 0x1300000012
movq %rax, 0x10(%rsi)
leaq -0x48(%rbp), %rdi
leaq -0x29(%rbp), %rcx
movl $0x6, %edx
callq 0x40ff5a
movq (%r15), %r13
movq %r15, -0x50(%rbp)
movq 0x8(%r15), %r15
cmpq %r15, %r13
je 0x40f44d
movq -0x40(%rbp), %rdx
subq -0x48(%rbp), %rdx
shrq $0x2, %rdx
decl %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x41086c
movl %eax, %r12d
cltq
movq -0x48(%rbp), %rcx
movl (%rcx,%rax,4), %edx
movzbl (%r13), %esi
movq %r14, %rdi
callq 0x40d722
testb %al, %al
jne 0x40f448
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
jmp 0x40f412
incq %r13
jmp 0x40f3ec
leaq -0x80(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x40ab9e
leaq -0x68(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x40ff98
leaq -0x80(%rbp), %rsi
leaq -0x68(%rbp), %rdx
movq %r14, %rdi
movq %rbx, %rcx
callq 0x40d77e
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0x40f488
callq 0x410b90
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x40f496
callq 0x410b90
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x40f4a4
callq 0x410b90
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0x40f4c9
callq 0x410b90
jmp 0x40f4c9
movq %rax, %rbx
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x40f4de
callq 0x410b90
jmp 0x40f4de
jmp 0x40f4db
movq %rax, %rbx
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x40f4ec
callq 0x410b90
movq %rbx, %rdi
callq 0x4bb660
// File: /workspace/github_cpp_makefile_star2_O1/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 (%rdi), %r15
movq 0x8(%rdi), %r12
cmpq %r12, %r15
je 0x40ff4a
movq %rsi, %rbx
cmpb $0x1, 0x14(%r15)
jne 0x40ff41
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 0x17cb95(%rip), %rdi    # 0x58caa2
xorl %eax, %eax
callq 0x4e21a0
movslq 0x4(%r15), %rax
leaq (%rax,%rax,4), %r13
addq $0x30d70, %r13          # imm = 0x30D70
xorl %r14d, %r14d
movzbl 0x8(%r15,%r14), %edx
leal (%r14,%r13), %esi
movq %rbx, %rdi
callq 0x404a28
incq %r14
cmpq $0x5, %r14
jne 0x40ff26
addq $0x18, %r15
cmpq %r12, %r15
jne 0x40fedf
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O1/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 0x404a28
movq (%r15), %rdi
movl $0x31ad0, %esi          # imm = 0x31AD0
movl %ebx, %edx
callq 0x404a28
movq (%r15), %rdi
movl $0x36207, %esi          # imm = 0x36207
movl %r14d, %edx
callq 0x404a28
movq (%r15), %rdi
movl $0x3620b, %esi          # imm = 0x3620B
movl %ebx, %edx
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x404a28
// File: /workspace/github_cpp_makefile_star2_O1/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 0x404a28
movq (%rbx), %rdi
movl $0x2963d, %esi          # imm = 0x2963D
movl %r14d, %edx
callq 0x404a28
movq (%rbx), %rdi
movl $0x29639, %esi          # imm = 0x29639
movl $0x2e, %edx
callq 0x404a28
movq (%rbx), %rdi
movl $0x2963a, %esi          # imm = 0x2963A
movl $0xe0, %edx
callq 0x404a28
movq (%rbx), %rdi
movl $0x2963b, %esi          # imm = 0x2963B
movl $0xec, %edx
callq 0x404a28
movq (%rbx), %rdi
movl $0x2963c, %esi          # imm = 0x2963C
movl $0xd2, %edx
popq %rbx
popq %r14
popq %rbp
jmp 0x404a28
nop
// File: /workspace/github_cpp_makefile_star2_O1/Thilotilo[P]DoaERando/NPCManipulator.cpp
// Function: DoaERando::NPCManipulator::ReplaceHuangZhongAndWeiYan(unsigned char, unsigned char)
void NPCManipulator::ReplaceHuangZhongAndWeiYan(BYTE generalId1, BYTE generalId2)
{
    // This is the NPC data
    myRom.WriteByte(0x31772, generalId1);
    myRom.WriteByte(0x31779, generalId2);
    // This is for the post-battle flags change
    myRom.WriteByte(0x3B062, generalId1);
    myRom.WriteByte(0x3B065, 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 $0x31772, %esi          # imm = 0x31772
movl %r14d, %edx
callq 0x404a28
movq (%r15), %rdi
movl $0x31779, %esi          # imm = 0x31779
movl %ebx, %edx
callq 0x404a28
movq (%r15), %rdi
movl $0x3b062, %esi          # imm = 0x3B062
movl %r14d, %edx
callq 0x404a28
movq (%r15), %rdi
movl $0x3b065, %esi          # imm = 0x3B065
movl %ebx, %edx
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x404a28