LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_cpp_makefile_star2_O1/Thilotilo[P]DoaERando/Rom.cpp
// Function: DoaERando::ROM::ReadRom(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void ROM::ReadRom(std::string file)
{
    ifstream fin(file, ios::binary);
    if (fin.fail()) throw 0;
    myContents = vector<BYTE>(
        (istreambuf_iterator<char>(fin)),
        (istreambuf_iterator<char>())
        );
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x230, %rsp            # imm = 0x230
movq %rdi, %rbx
leaq -0x238(%rbp), %r14
movq %r14, %rdi
movl $0x4, %edx
callq 0x456a80
movq (%r14), %rax
movq -0x18(%rax), %rcx
testb $0x5, -0x218(%rbp,%rcx)
jne 0x4046fd
movq -0x18(%rax), %rax
movq -0x150(%rbp,%rax), %rsi
leaq -0x30(%rbp), %rdi
leaq -0x11(%rbp), %r9
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
xorl %ecx, %ecx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
callq 0x404af2
movq (%rbx), %rdi
movq -0x30(%rbp), %rax
movq %rax, (%rbx)
movq -0x28(%rbp), %rax
movq %rax, 0x8(%rbx)
movq -0x20(%rbp), %rax
movq %rax, 0x10(%rbx)
xorps %xmm0, %xmm0
movaps %xmm0, -0x30(%rbp)
movq $0x0, -0x20(%rbp)
testq %rdi, %rdi
je 0x4046d7
callq 0x410b90
movq -0x30(%rbp), %rdi
testq %rdi, %rdi
je 0x4046e5
callq 0x410b90
leaq -0x238(%rbp), %rdi
callq 0x4577b0
addq $0x230, %rsp            # imm = 0x230
popq %rbx
popq %r14
popq %rbp
retq
movl $0x4, %edi
callq 0x410e70
movl $0x0, (%rax)
movq $0x5f66e8, %rsi         # imm = 0x5F66E8
movq %rax, %rdi
xorl %edx, %edx
callq 0x411ec0
jmp 0x404720
movq %rax, %rbx
leaq -0x238(%rbp), %rdi
callq 0x4577b0
movq %rbx, %rdi
callq 0x4bb660
nop
// File: /workspace/github_cpp_makefile_star2_O1/Thilotilo[P]DoaERando/Rom.cpp
// Function: DoaERando::ROM::SwapBytesAtBank(int, int, int)
void ROM::SwapBytesAtBank(int bank, int address1, int address2)
{
    int baseOffset1 = address1 - 0x8000;
    int baseOffset2 = address2 - 0x8000;
    SwapBytes(0x10 + (bank * 0x4000) + baseOffset1,
              0x10 + (bank * 0x4000) + baseOffset2);

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
shll $0xe, %esi
leal (%rdx,%rsi), %eax
addl $0x10, %eax
addl %esi, %ecx
addl $0x10, %ecx
movl $0xffff8000, %edx       # imm = 0xFFFF8000
addl %edx, %eax
addl %edx, %ecx
cltq
movq (%rdi), %rdx
movb (%rdx,%rax), %sil
movslq %ecx, %rcx
movb (%rdx,%rcx), %r8b
movb %r8b, (%rdx,%rax)
movq (%rdi), %rax
movb %sil, (%rax,%rcx)
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/Thilotilo[P]DoaERando/Randomizer.cpp
// Function: DoaERando::Randomizer::GetGeneralLocation(unsigned char)
int Randomizer::GetGeneralLocation(BYTE id)
{
    const int BANK_OFFSET = 0x30010 - 0x8000;
    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 + BANK_OFFSET;
    return address;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %ebx
movq %rdi, %r14
movq (%rdi), %rdi
leal 0x32710(%rbx), %esi
callq 0x4049fe
movzbl %al, %r15d
movq (%r14), %rdi
addl $0x32610, %ebx          # imm = 0x32610
movl %ebx, %esi
callq 0x4049fe
movzbl %al, %eax
shll $0x8, %r15d
addl %r15d, %eax
addl $0x28010, %eax          # imm = 0x28010
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O1/Thilotilo[P]DoaERando/Randomizer.cpp
// Function: DoaERando::Randomizer::PrintName(unsigned char)
void Randomizer::PrintName(BYTE id)
{
    int nameOffset = GetGeneralLocation(id) + 20;
    while (myRom->ReadByte(nameOffset) != 0xFF)
    {
        char character = myRom->ReadByte(nameOffset) + 'A' - 0x10;
        switch(myRom->ReadByte(nameOffset))
        {
            case 0x2D:
                character = 'r';
                break;
            case 0x2F:
                character = 't';
                break;
            case 0x64:
                character = 'u';
                break;
            case 0x0A:
                character = ' ';
                break;
            default:
                break;
        }

        printf("%c", character);
        ++nameOffset;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
callq 0x404e26
movl %eax, %r14d
addl $0x14, %r14d
movq (%rbx), %rdi
movl %r14d, %esi
callq 0x4049fe
cmpb $-0x1, %al
je 0x404ef3
movq (%rbx), %rdi
movl %r14d, %esi
callq 0x4049fe
movl %eax, %r15d
addb $0x31, %r15b
movq (%rbx), %rdi
movl %r14d, %esi
callq 0x4049fe
movzbl %al, %eax
cmpl $0x2e, %eax
jg 0x404ece
cmpl $0xa, %eax
je 0x404edd
cmpl $0x2d, %eax
jne 0x404ee5
movb $0x72, %r15b
jmp 0x404ee5
cmpl $0x2f, %eax
je 0x404ee2
cmpl $0x64, %eax
jne 0x404ee5
movb $0x75, %r15b
jmp 0x404ee5
movb $0x20, %r15b
jmp 0x404ee5
movb $0x74, %r15b
movsbl %r15b, %edi
callq 0x4e9e00
incl %r14d
jmp 0x404e8b
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/Thilotilo[P]DoaERando/Randomizer.cpp
// Function: DoaERando::AreExitsFromSameCave(int, int)
static bool AreExitsFromSameCave(int offset1, int offset2)
{
    const int MT_GANG_TAI_ENTRANCE_OFFSET = 0x0B;
    const int MT_GANG_TAI_EXIT_OFFSET = 0x1F;
    const int WU_CAVE_EXIT_OFFSET = 0x26;
    const int WU_CAVE_ENTRANCE_OFFSET = 0x39;
    const int CHANG_AN_ENTRANCE_OFFSET = 0x58;
    const int CHANG_AN_EXIT_OFFSET = 0x61;
    const int WEI_CAVE_2_ENTRANCE_OFFSET = 0x6C;
    const int WEI_CAVE_2_EXIT_OFFSET = 0x7B;
    const int WEI_CAVE_1_EXIT_OFFSET = 0x7E;
    const int WEI_CAVE_1_ENTRANCE_OFFSET = 0x93;

    return ((offset1 == MT_GANG_TAI_ENTRANCE_OFFSET && offset2 == MT_GANG_TAI_EXIT_OFFSET) ||
            (offset1 == MT_GANG_TAI_EXIT_OFFSET && offset2 == MT_GANG_TAI_ENTRANCE_OFFSET) ||
            (offset1 == WU_CAVE_ENTRANCE_OFFSET && offset2 == WU_CAVE_EXIT_OFFSET) ||
            (offset1 == WU_CAVE_EXIT_OFFSET && offset2 == WU_CAVE_ENTRANCE_OFFSET) ||
            (offset1 == CHANG_AN_ENTRANCE_OFFSET && offset2 == CHANG_AN_EXIT_OFFSET) ||
            (offset1 == CHANG_AN_EXIT_OFFSET && offset2 == CHANG_AN_ENTRANCE_OFFSET) ||
            (offset1 == WEI_CAVE_2_ENTRANCE_OFFSET && offset2 == WEI_CAVE_2_EXIT_OFFSET) ||
            (offset1 == WEI_CAVE_2_EXIT_OFFSET && offset2 == WEI_CAVE_2_ENTRANCE_OFFSET) ||
            (offset1 == WEI_CAVE_1_ENTRANCE_OFFSET && offset2 == WEI_CAVE_1_EXIT_OFFSET) ||
            (offset1 == WEI_CAVE_1_EXIT_OFFSET && offset2 == WEI_CAVE_1_ENTRANCE_OFFSET));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movl %edi, %ecx
xorl $0xb, %ecx
movl %esi, %edx
xorl $0x1f, %edx
movb $0x1, %al
orl %ecx, %edx
je 0x405b38
movl %edi, %ecx
xorl $0x1f, %ecx
movl %esi, %edx
xorl $0xb, %edx
orl %ecx, %edx
je 0x405b38
movl %edi, %ecx
xorl $0x39, %ecx
movl %esi, %edx
xorl $0x26, %edx
orl %ecx, %edx
je 0x405b38
movl %edi, %ecx
xorl $0x26, %ecx
movl %esi, %edx
xorl $0x39, %edx
orl %ecx, %edx
je 0x405b38
movl %edi, %ecx
xorl $0x58, %ecx
movl %esi, %edx
xorl $0x61, %edx
orl %ecx, %edx
je 0x405b38
movl %edi, %ecx
xorl $0x61, %ecx
movl %esi, %edx
xorl $0x58, %edx
orl %ecx, %edx
je 0x405b38
movl %edi, %ecx
xorl $0x6c, %ecx
movl %esi, %edx
xorl $0x7b, %edx
orl %ecx, %edx
je 0x405b38
movl %edi, %ecx
xorl $0x7b, %ecx
movl %esi, %edx
xorl $0x6c, %edx
orl %ecx, %edx
je 0x405b38
movl %edi, %ecx
xorl $0x93, %ecx
movl %esi, %edx
xorl $0x7e, %edx
orl %ecx, %edx
je 0x405b38
xorl $0x7e, %edi
xorl $0x93, %esi
orl %edi, %esi
sete %al
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/Thilotilo[P]DoaERando/Randomizer.cpp
// Function: DoaERando::Randomizer::FixNMIGlitch()
void Randomizer::FixNMIGlitch()
{
    // This should hopefully stop all of the crashes
    std::vector<BYTE> loopingCode = {
        0x68,               // PLA
        0x85, 0xF3,         // STA $F3
        0x68,               // PLA
        0x85, 0xF4,         // STA $F4
        // Now we're just shifting this section up to follow immediately
        0xA0, 0x02,         // LDY #$02
        0xB1, 0xF3,         // LDA ($F3),Y
        0x48,               // PHA
        0x88,               // DEY
        0xB1, 0xF3,         // LDA ($F3),Y
        0x48,               // PHA
        0xA5, 0x45,         // LDA $45
        0x4C, 0x80, 0xC4,   // JMP $C480
        // Zero out remaining bytes from this logic
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
    };
    for (int i = 0; i < loopingCode.size(); ++i)
    {
        myRom->WriteByte(0x3C50B + i, loopingCode[i]);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x40, %rsp
movq %rdi, %rbx
movups 0x18628e(%rip), %xmm0   # 0x58c397
leaq -0x50(%rbp), %rsi
movups %xmm0, 0xf(%rsi)
movups 0x186270(%rip), %xmm0   # 0x58c388
movaps %xmm0, (%rsi)
leaq -0x30(%rbp), %r14
leaq -0x11(%rbp), %rcx
movl $0x1f, %edx
movq %r14, %rdi
callq 0x40a9c2
movq (%r14), %rdi
cmpq %rdi, 0x8(%r14)
je 0x406166
xorl %r14d, %r14d
movq (%rbx), %rax
movzbl (%rdi,%r14), %edx
leal 0x3c50b(%r14), %esi
movq %rax, %rdi
callq 0x404a28
incq %r14
movq -0x30(%rbp), %rdi
movq -0x28(%rbp), %rax
subq %rdi, %rax
cmpq %r14, %rax
ja 0x40613c
testq %rdi, %rdi
je 0x406170
callq 0x410b90
addq $0x40, %rsp
popq %rbx
popq %r14
popq %rbp
retq
movq %rax, %rbx
movq -0x30(%rbp), %rdi
testq %rdi, %rdi
je 0x40618a
callq 0x410b90
movq %rbx, %rdi
callq 0x4bb660
// File: /workspace/github_cpp_makefile_star2_O1/Thilotilo[P]DoaERando/Randomizer.cpp
// Function: DoaERando::Randomizer::GivePartyMaxFoodFromNPC()
void Randomizer::GivePartyMaxFoodFromNPC()
{
    printf("Feeding the armies well...\n");
    // 0xF423F is 999999 in decimal.  These bytes determine the amount of food the NPC gives you.
    // Note that the text still says 1000.  I'll need to change that elsewhere.
    myRom->WriteByte(0x361D7, 0x0F);
    myRom->WriteByte(0x361DB, 0x42);
    myRom->WriteByte(0x361DF, 0x3F);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0x186090(%rip), %rdi    # 0x58c2b8
callq 0x4e96e0
movq (%rbx), %rdi
movl $0x361d7, %esi          # imm = 0x361D7
movl $0xf, %edx
callq 0x404a28
movq (%rbx), %rdi
movl $0x361db, %esi          # imm = 0x361DB
movl $0x42, %edx
callq 0x404a28
movq (%rbx), %rdi
movl $0x361df, %esi          # imm = 0x361DF
movl $0x3f, %edx
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x404a28
nop
// File: /workspace/github_cpp_makefile_star2_O1/Thilotilo[P]DoaERando/Randomizer.cpp
// Function: DoaERando::Randomizer::ModifyEncounterRate()
void Randomizer::ModifyEncounterRate()
{
    printf("Keeping the enemies away(ish)...\n");
    // Don't encounter enemies on anything that's not mountains (and whatever id 0x05 is)
    myRom->WriteByte(0x3F4D6, 0x04);
    // Make Mountain encounter rate really high (50%)
    myRom->WriteByte(0x3F51C, 0x01);
    myRom->WriteByte(0x3F522, 0x00);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0x186059(%rip), %rdi    # 0x58c2d3
callq 0x4e96e0
movq (%rbx), %rdi
movl $0x3f4d6, %esi          # imm = 0x3F4D6
movl $0x4, %edx
callq 0x404a28
movq (%rbx), %rdi
movl $0x3f51c, %esi          # imm = 0x3F51C
movl $0x1, %edx
callq 0x404a28
movq (%rbx), %rdi
movl $0x3f522, %esi          # imm = 0x3F522
xorl %edx, %edx
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x404a28
// File: /workspace/github_cpp_makefile_star2_O1/Thilotilo[P]DoaERando/Randomizer.cpp
// Function: DoaERando::Randomizer::DisableChapter1LockForSiShui()
void Randomizer::DisableChapter1LockForSiShui()
{
    printf("Opening Si Shui fortress to Liu Bei...\n");
    // Make only chapters below 1 (i.e., none) block entrance to Si Shui
    myRom->WriteByte(0x3642B, 0x01);
    // Don't disable Si Shui battle unless we enter in chapter 0 (i.e., never)
    myRom->WriteByte(0x3643B, 0x00);
    // Don't decrement the Y counter unless we are in a chapter below 1 (i.e., never)
    myRom->WriteByte(0x3BE8B, 0x01);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0x18602c(%rip), %rdi    # 0x58c2f4
callq 0x4e96e0
movq (%rbx), %rdi
movl $0x3642b, %esi          # imm = 0x3642B
movl $0x1, %edx
callq 0x404a28
movq (%rbx), %rdi
movl $0x3643b, %esi          # imm = 0x3643B
xorl %edx, %edx
callq 0x404a28
movq (%rbx), %rdi
movl $0x3be8b, %esi          # imm = 0x3BE8B
movl $0x1, %edx
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x404a28
// File: /workspace/github_cpp_makefile_star2_O1/Thilotilo[P]DoaERando/Randomizer.cpp
// Function: DoaERando::Randomizer::IncreaseTacticGains()
void Randomizer::IncreaseTacticGains()
{
    // Since we aren't gaining TP on every level now, let's up our TP gain
    // Here, we're going to randomize each 1/16 chance value to be between
    // 5-10, with the last slot being 15-20.
    const int TACTIC_GAINS_OFFSET = 0x3B666;
    for (int i = 0; i < 15; ++i)
    {
        BYTE tacticGain = myRNG.GetRandomByte(5, 10);
        myRom->WriteByte(TACTIC_GAINS_OFFSET + i, tacticGain);
        printf("Increasing tactic gain 0x%X to %d\n", i, tacticGain);
    }
    BYTE tacticGain = myRNG.GetRandomByte(15, 20);
    myRom->WriteByte(TACTIC_GAINS_OFFSET + 15, tacticGain);
    printf("Increasing tactic gain 0x%X to %d\n", 15, tacticGain);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0x8(%rdi), %r14
leaq 0x185d8b(%rip), %r15    # 0x58c143
xorl %r12d, %r12d
movq %r14, %rdi
movl $0x5, %esi
movl $0xa, %edx
callq 0x410846
movq (%rbx), %rdi
leal 0x3b666(%r12), %esi
movzbl %al, %r13d
movl %r13d, %edx
callq 0x404a28
movq %r15, %rdi
movl %r12d, %esi
movl %r13d, %edx
xorl %eax, %eax
callq 0x4e21a0
incl %r12d
cmpl $0xf, %r12d
jne 0x4063bb
movq %r14, %rdi
movl $0xf, %esi
movl $0x14, %edx
callq 0x410846
movq (%rbx), %rdi
movzbl %al, %ebx
movl $0x3b675, %esi          # imm = 0x3B675
movl %ebx, %edx
callq 0x404a28
leaq 0x185d1b(%rip), %rdi    # 0x58c143
movl $0xf, %esi
movl %ebx, %edx
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4e21a0
// File: /workspace/github_cpp_makefile_star2_O1/Thilotilo[P]DoaERando/Randomizer.cpp
// Function: DoaERando::Randomizer::DoubleXpGain()
void Randomizer::DoubleXpGain()
{
    const int XP_MULTIPLIER_OFFSET = 0x39a28;
    for (int i = 0; i < 8; ++i)
    {
        BYTE currentXpBoost = myRom->ReadByte(XP_MULTIPLIER_OFFSET + i);
        BYTE increasedXpBoost = currentXpBoost * 2;
        myRom->WriteByte(XP_MULTIPLIER_OFFSET + i, increasedXpBoost);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movq %rdi, %rbx
movl $0x39a28, %r14d         # imm = 0x39A28
movq (%rbx), %rdi
movl %r14d, %esi
callq 0x4049fe
addb %al, %al
movq (%rbx), %rdi
movzbl %al, %edx
movl %r14d, %esi
callq 0x404a28
incl %r14d
cmpl $0x39a30, %r14d         # imm = 0x39A30
jne 0x406454
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/Thilotilo[P]DoaERando/Randomizer.cpp
// Function: DoaERando::Randomizer::MakeAllGeneralsRecruitableAndEncounterable()
void Randomizer::MakeAllGeneralsRecruitableAndEncounterable()
{
    myGenerals.SetAllGeneralsEncounterable();
    myGenerals.SetAllGeneralsRecruitable();

    //Allow any General that appears in a town and isn't already on your party to show up.
    myRom->WriteByte(0x3E8F0, 0xC0); // Compare general config with 0xC0 rather than 0x80
    myRom->WriteByte(0x3E8F1, 0xD0); // Branch if != 0xC0 rather than branching if == 0x80 
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movq %rdi, %rbx
leaq 0x9d0(%rdi), %r14
movq %r14, %rdi
callq 0x40c8c8
movq %r14, %rdi
callq 0x40c8e8
movq (%rbx), %rdi
movl $0x3e8f0, %esi          # imm = 0x3E8F0
movl $0xc0, %edx
callq 0x404a28
movq (%rbx), %rdi
movl $0x3e8f1, %esi          # imm = 0x3E8F1
movl $0xd0, %edx
popq %rbx
popq %r14
popq %rbp
jmp 0x404a28
nop
// File: /workspace/github_cpp_makefile_star2_O1/Thilotilo[P]DoaERando/Randomizer.cpp
// Function: DoaERando::Randomizer::RandomizeTacticLevels()
void Randomizer::RandomizeTacticLevels()
{
    const int TACTIC_LEVEL_OFFSET = 0x3b880;
    printf("Old Tactic Levels:\n");
    for(int i = 1; i < 50; ++i)
    {
        printf("  Level %d: Tactic id 0x%X\n", i + 1, myRom->ReadByte(TACTIC_LEVEL_OFFSET + i));
    }
    for (int i = 0; i < 10000; ++i)
    {
        int levelSlot1 = myRNG.GetRandomByte(1, 49);
        int levelSlot2 = myRNG.GetRandomByte(1, 49);

        myRom->SwapBytes(TACTIC_LEVEL_OFFSET + levelSlot1, TACTIC_LEVEL_OFFSET + levelSlot2);
    }

    printf("New Tactic Levels:\n");
    for(int i = 1; i < 50; ++i)
    {
        printf("  Level %d: Tactic id 0x%X\n", i + 1, myRom->ReadByte(TACTIC_LEVEL_OFFSET + i));
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0x185e39(%rip), %rdi    # 0x58c31b
callq 0x4e96e0
movl $0x3b881, %r14d         # imm = 0x3B881
leaq 0x185c72(%rip), %r15    # 0x58c166
leal -0x3b87f(%r14), %r12d
movq (%rbx), %rdi
movl %r14d, %esi
callq 0x4049fe
movzbl %al, %edx
movq %r15, %rdi
movl %r12d, %esi
xorl %eax, %eax
callq 0x4e21a0
incl %r14d
cmpl $0x3b8b2, %r14d         # imm = 0x3B8B2
jne 0x4064f4
leaq 0x8(%rbx), %r14
movl $0x2710, %r12d          # imm = 0x2710
movl $0x3b880, %r13d         # imm = 0x3B880
movq %r14, %rdi
movl $0x1, %esi
movl $0x31, %edx
callq 0x410846
movzbl %al, %r15d
movq %r14, %rdi
movl $0x1, %esi
movl $0x31, %edx
callq 0x410846
movzbl %al, %edx
movq (%rbx), %rdi
addl %r13d, %r15d
addl %r13d, %edx
movl %r15d, %esi
callq 0x404a52
decl %r12d
jne 0x406532
leaq 0x185db4(%rip), %rdi    # 0x58c32e
callq 0x4e96e0
movl $0x3b881, %r14d         # imm = 0x3B881
leaq 0x185bda(%rip), %r15    # 0x58c166
leal -0x3b87f(%r14), %r12d
movq (%rbx), %rdi
movl %r14d, %esi
callq 0x4049fe
movzbl %al, %edx
movq %r15, %rdi
movl %r12d, %esi
xorl %eax, %eax
callq 0x4e21a0
incl %r14d
cmpl $0x3b8b2, %r14d         # imm = 0x3B8B2
jne 0x40658c
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/Randomizer.cpp
// Function: DoaERando::Randomizer::RandomizeBattles()
void Randomizer::RandomizeBattles()
{
    myBattleRandomizer.RandomizeZone1(myGenerals, myRNG);
    myBattleRandomizer.RandomizeZone2(myGenerals, myRNG);
    myBattleRandomizer.RandomizeZone3(myGenerals, myRNG);
    myBattleRandomizer.RandomizeZone4(myGenerals, myRNG);
    myBattleRandomizer.RandomizeZone5(myGenerals, myRNG);
    myBattleRandomizer.RandomizeZone6(myGenerals, myRNG);
    myBattleRandomizer.RandomizeZone7(myGenerals, myRNG);
    myBattleRandomizer.RandomizeZone8(myGenerals, myRNG);
    myBattleRandomizer.UpdateBattles(*myRom);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdi, %rbx
leaq 0xa20(%rdi), %r14
leaq 0x9d0(%rdi), %r15
leaq 0x8(%rdi), %r12
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x40d912
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x40dd28
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x40df4a
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x40e138
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x40e3fc
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x40e620
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x40e812
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x40eb42
movq (%rbx), %rsi
movq %r14, %rdi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x40fec2
nop
// File: /workspace/github_cpp_makefile_star2_O1/Thilotilo[P]DoaERando/Randomizer.cpp
// Function: DoaERando::Randomizer::MoveGuiYangBattle()
void Randomizer::MoveGuiYangBattle()
{
    // First, set the flags to clear the throne room battle
    // We only want to set two bits, so let's read and then set those 2 bits only
    auto flags = myRom->ReadByte(0x34761);
    // bit 1 = Gui Yang battle started
    // bit 2 = Gui Yang battle won
    flags |= 0x06;
    myRom->WriteByte(0x34761, flags);

    // Next, we're going to move the Gui Yang battle to the castle entrance
    myRom->WriteByte(0x30C2B, 0x09); // Vertical offset in block
    myRom->WriteByte(0x30C83, 0x12); // Vertical block
    myRom->WriteByte(0x30CDB, 0x03); // Horizontal offset in block
    myRom->WriteByte(0x30D33, 0x0E); // Horizontal block
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq (%rdi), %rdi
movl $0x34761, %esi          # imm = 0x34761
callq 0x4049fe
orb $0x6, %al
movq (%rbx), %rdi
movzbl %al, %edx
movl $0x34761, %esi          # imm = 0x34761
callq 0x404a28
movq (%rbx), %rdi
movl $0x30c2b, %esi          # imm = 0x30C2B
movl $0x9, %edx
callq 0x404a28
movq (%rbx), %rdi
movl $0x30c83, %esi          # imm = 0x30C83
movl $0x12, %edx
callq 0x404a28
movq (%rbx), %rdi
movl $0x30cdb, %esi          # imm = 0x30CDB
movl $0x3, %edx
callq 0x404a28
movq (%rbx), %rdi
movl $0x30d33, %esi          # imm = 0x30D33
movl $0xe, %edx
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x404a28
// File: /workspace/github_cpp_makefile_star2_O1/Thilotilo[P]DoaERando/Randomizer.cpp
// Function: DoaERando::Randomizer::SetGeneralForZone0AndRemove(unsigned char, std::vector<unsigned char, std::allocator<unsigned char>>&)
void Randomizer::SetGeneralForZone0AndRemove(BYTE generalId, std::vector<BYTE>& ids)
{
    myGenerals.SetAndScaleGeneralForZone(generalId, 0, myRNG);
    myGenerals.SetGeneralEncounterable(generalId, false);
    myGenerals.SetGeneralRecruitable(generalId, false);
    PullIdFromVector(generalId, ids);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdx, %rbx
movl %esi, %r14d
leaq 0x9d0(%rdi), %r15
leaq 0x8(%rdi), %rcx
movq %r15, %rdi
xorl %edx, %edx
callq 0x40c9b0
movq %r15, %rdi
movl %r14d, %esi
xorl %edx, %edx
callq 0x40ca52
movq %r15, %rdi
movl %r14d, %esi
xorl %edx, %edx
callq 0x40ca76
movl %r14d, %edi
movq %rbx, %rsi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x406ce1
// File: /workspace/github_cpp_makefile_star2_O1/Thilotilo[P]DoaERando/Randomizer.cpp
// Function: DoaERando::Randomizer::ReconfigureLiuKuiTentGeneral()
void Randomizer::ReconfigureLiuKuiTentGeneral()
{
    std::vector<BYTE> tentNPCData {
        // Configure NPC info ->actual NPC ID to be set by the manipulator,
        // So we just set it to 0 for now
        0x13, 0x04, 0x97, 0x1C, 0x19, 0x19, 0x00,
        // Since there's no longer any code to execute, we need to clear
        // those extra 2 bytes too (plus move the original FF)
        0xFF, 0x00, 0x00
    };

    for (int i = 0; i < tentNPCData.size(); ++i)
    {
        myRom->WriteByte(0x31420 + i, tentNPCData[i]);
    }

    // Remove now-unused code for loading the NPC so we can reclaim
    // it for other nefarious purposes.
    const size_t NUM_EVENT_BYTES_TO_CLEAR = 11;
    for (size_t i = 0; i < NUM_EVENT_BYTES_TO_CLEAR; ++i)
    {
        myRom->WriteByte(0x36EE0 + i, 0x00);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x30, %rsp
movq %rdi, %rbx
movabsq $-0xffe6e6e368fbed, %rax # imm = 0xFF0019191C970413
leaq -0x3a(%rbp), %rsi
movq %rax, (%rsi)
movw $0x0, 0x8(%rsi)
leaq -0x30(%rbp), %r14
leaq -0x11(%rbp), %rcx
movl $0xa, %edx
movq %r14, %rdi
callq 0x40a9c2
movq (%r14), %rax
cmpq %rax, 0x8(%r14)
je 0x406e95
xorl %r14d, %r14d
movq (%rbx), %rdi
movzbl (%rax,%r14), %edx
leal 0x31420(%r14), %esi
callq 0x404a28
incq %r14
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rcx
subq %rax, %rcx
cmpq %r14, %rcx
ja 0x406e6e
movq $-0xb, %r14
movq (%rbx), %rdi
leal 0x36eeb(%r14), %esi
xorl %edx, %edx
callq 0x404a28
incq %r14
jne 0x406e9c
movq -0x30(%rbp), %rdi
testq %rdi, %rdi
je 0x406ec0
callq 0x410b90
addq $0x30, %rsp
popq %rbx
popq %r14
popq %rbp
retq
jmp 0x406ecb
movq %rax, %rbx
movq -0x30(%rbp), %rdi
testq %rdi, %rdi
je 0x406edc
callq 0x410b90
movq %rbx, %rdi
callq 0x4bb660
// File: /workspace/github_cpp_makefile_star2_O1/Thilotilo[P]DoaERando/Randomizer.cpp
// Function: DoaERando::Randomizer::MakeZone0GeneralsUnfirable()
void Randomizer::MakeZone0GeneralsUnfirable()
{
    std::vector<BYTE> newCode {
        // $60AF contains the general id
        0xAC, 0xAF, 0x60,   // LDY $60AF
        0xA9, 0x02,         // LDA #$02
        // E3C8 returns byte A of the general info of the general id in Y
        0x20, 0xC8, 0xE3,   // JSR $E3C8
        0xF0, 0x05,         // BEQ ($94E5) - the "can't fire" response
        0xD0, 0x09,         // BNE ($94EB) - the confirmation dialog
        // Now finish padding the rest of the overwritten code
        0x00, 0x00, 0x00
    };

    for (int i = 0; i < newCode.size(); ++i)
    {
        myRom->WriteByte(0x394E6 + i, newCode[i]);
    }

    // Remove the old unfirable generals list so we can reclaim
    // it for other nefarious purposes.
    const size_t NUM_EVENT_BYTES_TO_CLEAR = 17;
    for (size_t i = 0; i < NUM_EVENT_BYTES_TO_CLEAR; ++i)
    {
        myRom->WriteByte(0x39587 + i, 0x00);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x30, %rsp
movq %rdi, %rbx
movabsq $-0x1c37dffd569f5054, %rax # imm = 0xE3C82002A960AFAC
leaq -0x3f(%rbp), %rsi
movq %rax, (%rsi)
movl $0x9d005f0, 0x8(%rsi)   # imm = 0x9D005F0
movw $0x0, 0xc(%rsi)
movb $0x0, 0xe(%rsi)
leaq -0x30(%rbp), %r14
leaq -0x11(%rbp), %rcx
movl $0xf, %edx
movq %r14, %rdi
callq 0x40a9c2
movq (%r14), %rax
cmpq %rax, 0x8(%r14)
je 0x406f5c
xorl %r14d, %r14d
movq (%rbx), %rdi
movzbl (%rax,%r14), %edx
leal 0x394e6(%r14), %esi
callq 0x404a28
incq %r14
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rcx
subq %rax, %rcx
cmpq %r14, %rcx
ja 0x406f35
movq $-0x11, %r14
movq (%rbx), %rdi
leal 0x39598(%r14), %esi
xorl %edx, %edx
callq 0x404a28
incq %r14
jne 0x406f63
movq -0x30(%rbp), %rdi
testq %rdi, %rdi
je 0x406f87
callq 0x410b90
addq $0x30, %rsp
popq %rbx
popq %r14
popq %rbp
retq
jmp 0x406f92
movq %rax, %rbx
movq -0x30(%rbp), %rdi
testq %rdi, %rdi
je 0x406fa3
callq 0x410b90
movq %rbx, %rdi
callq 0x4bb660
nop
// File: /workspace/github_cpp_makefile_star2_O1/Thilotilo[P]DoaERando/Randomizer.cpp
// Function: DoaERando::Randomizer::RemoveUneededEntranceTriggerCode()
void Randomizer::RemoveUneededEntranceTriggerCode()
{
    // Tie Men Xia - we don't want to remove NPCs, so the
    // code is unneeded
    // Remove the "code executed" bit
    BYTE execByte = myRom->ReadByte(0x31A2D);
    execByte &= 0xDF; // clear bit 5
    myRom->WriteByte(0x31A2D, execByte);
    // Blank out both the code-to-execute pointer (moving the
    // FF terminator as well) and the actual code
    myRom->WriteByte(0x31A31, 0xFF);
    myRom->WriteByte(0x31A32, 0x00);
    myRom->WriteByte(0x31A33, 0x00);

    const size_t NUM_EVENT_BYTES_TO_CLEAR = 15;
    for (size_t i = 0; i < NUM_EVENT_BYTES_TO_CLEAR; ++i)
    {
        myRom->WriteByte(0x3536E, 0x00);
    }

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movq %rdi, %rbx
movq (%rdi), %rdi
movl $0x31a2d, %esi          # imm = 0x31A2D
callq 0x4049fe
andb $-0x21, %al
movq (%rbx), %rdi
movzbl %al, %edx
movl $0x31a2d, %esi          # imm = 0x31A2D
callq 0x404a28
movq (%rbx), %rdi
movl $0x31a31, %esi          # imm = 0x31A31
movl $0xff, %edx
callq 0x404a28
movq (%rbx), %rdi
movl $0x31a32, %esi          # imm = 0x31A32
xorl %edx, %edx
callq 0x404a28
movq (%rbx), %rdi
movl $0x31a33, %esi          # imm = 0x31A33
xorl %edx, %edx
callq 0x404a28
movl $0xf, %r14d
movq (%rbx), %rdi
movl $0x3536e, %esi          # imm = 0x3536E
xorl %edx, %edx
callq 0x404a28
decq %r14
jne 0x40700b
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/Thilotilo[P]DoaERando/Randomizer.cpp
// Function: DoaERando::Randomizer::MoveGemswordToSimaHuisHut()
void Randomizer::MoveGemswordToSimaHuisHut()
{
    // Move the actual gemsword
    myRom->WriteByte(0x30A12, 0x01);
    myRom->WriteByte(0x30A52, 0x01);
    myRom->WriteByte(0x30A92, 0x0A);
    myRom->WriteByte(0x30AD2, 0x1E);

    // Remove the gemsword room in Luo Yang
    // (Easier and nicer than removing the discolored tile
    myRom->WriteByte(0x1F6F2, 0x15);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq (%rdi), %rdi
movl $0x30a12, %esi          # imm = 0x30A12
movl $0x1, %edx
callq 0x404a28
movq (%rbx), %rdi
movl $0x30a52, %esi          # imm = 0x30A52
movl $0x1, %edx
callq 0x404a28
movq (%rbx), %rdi
movl $0x30a92, %esi          # imm = 0x30A92
movl $0xa, %edx
callq 0x404a28
movq (%rbx), %rdi
movl $0x30ad2, %esi          # imm = 0x30AD2
movl $0x1e, %edx
callq 0x404a28
movq (%rbx), %rdi
movl $0x1f6f2, %esi          # imm = 0x1F6F2
movl $0x15, %edx
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x404a28
nop
// File: /workspace/github_cpp_makefile_star2_O1/Thilotilo[P]DoaERando/Randomizer.cpp
// Function: DoaERando::Randomizer::RemoveFinalIntroScreen()
void Randomizer::RemoveFinalIntroScreen()
{
    // This is just a way of freeing bytes from bank 7 in order to
    // put code in.  We free a few hundred bytes this way. We free
    // up bytes in 2 places: the code that calls the screen and
    // the text in that screen.

    const int NUM_BYTES_TO_CLEAR_CODE = 0x1DC58 - 0x1DAF9;
    const int NUM_BYTES_TO_CLEAR_TEXT = 0x1D27A - 0x1D244;

    for (int i = 0; i < NUM_BYTES_TO_CLEAR_CODE; ++i)
    {
        myRom->WriteByte(0x1DAF9, 0x00);
    }

    for (int i = 0; i < NUM_BYTES_TO_CLEAR_TEXT; ++i)
    {
        myRom->WriteByte(0x1D27A, 0x00);
    }

    // Lastly, we have to tell the code to skip over the zeroed code
    // (JMP $926A)
    myRom->WriteByte(0x1D241, 0x4C);
    myRom->WriteByte(0x1D242, 0x6A);
    myRom->WriteByte(0x1D243, 0x92);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movq %rdi, %rbx
movl $0x15f, %r14d           # imm = 0x15F
movq (%rbx), %rdi
movl $0x1daf9, %esi          # imm = 0x1DAF9
xorl %edx, %edx
callq 0x404a28
decl %r14d
jne 0x40781e
movl $0x36, %r14d
movq (%rbx), %rdi
movl $0x1d27a, %esi          # imm = 0x1D27A
xorl %edx, %edx
callq 0x404a28
decl %r14d
jne 0x407838
movq (%rbx), %rdi
movl $0x1d241, %esi          # imm = 0x1D241
movl $0x4c, %edx
callq 0x404a28
movq (%rbx), %rdi
movl $0x1d242, %esi          # imm = 0x1D242
movl $0x6a, %edx
callq 0x404a28
movq (%rbx), %rdi
movl $0x1d243, %esi          # imm = 0x1D243
movl $0x92, %edx
popq %rbx
popq %r14
popq %rbp
jmp 0x404a28
// File: /workspace/github_cpp_makefile_star2_O1/Thilotilo[P]DoaERando/Randomizer.cpp
// Function: DoaERando::Randomizer::ProtectChapter1Generals()
void Randomizer::ProtectChapter1Generals()
{
    // The Yellow Scarves battles do stuff to Cheng Yuanzhi and Zheng Mao.
    // We want it to not do that.

    // Don't change the flags for generals once all 3 Yellow Scarves locations
    // have been checked.
    myRom->WriteByte(0x3B03D, 0xF0);
    myRom->WriteByte(0x3B03E, 0x06);
    for (int i = 0; i < 6; ++i)
    {
        myRom->WriteByte(0x3B03F + i, 0x00);
    }

    // Don't modify flags for these generals after finishing chapter 1 either
    myRom->WriteByte(0x3632D, 0xFF);
    myRom->WriteByte(0x3632E, 0xFF);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movq %rdi, %rbx
movq (%rdi), %rdi
movl $0x3b03d, %esi          # imm = 0x3B03D
movl $0xf0, %edx
callq 0x404a28
movq (%rbx), %rdi
movl $0x3b03e, %esi          # imm = 0x3B03E
movl $0x6, %edx
callq 0x404a28
movl $0x3b03f, %r14d         # imm = 0x3B03F
movq (%rbx), %rdi
movl %r14d, %esi
xorl %edx, %edx
callq 0x404a28
incl %r14d
cmpl $0x3b045, %r14d         # imm = 0x3B045
jne 0x407a5e
movq (%rbx), %rdi
movl $0x3632d, %esi          # imm = 0x3632D
movl $0xff, %edx
callq 0x404a28
movq (%rbx), %rdi
movl $0x3632e, %esi          # imm = 0x3632E
movl $0xff, %edx
popq %rbx
popq %r14
popq %rbp
jmp 0x404a28
nop
// File: /workspace/github_cpp_makefile_star2_O1/Thilotilo[P]DoaERando/Randomizer.cpp
// Function: DoaERando::Randomizer::MakeWarlordsImmuneToAnSha()
void Randomizer::MakeWarlordsImmuneToAnSha()
{
    // Sun Quan, Cao Pi, and Sima Yi are already immune to An Sha
    myRom->WriteByte(0x3BC5F, 0xA8); // Add Liu Bei
    myRom->WriteByte(0x3BC60, 0x70); // Add Cao Cao
    myRom->WriteByte(0x3BC61, 0x56); // Add Sun Ce
    myRom->WriteByte(0x3BC62, 0xAB); // Add Liu Chan
    myRom->WriteByte(0x3BC63, 0xBC); // Add the Lu Bu that takes the gemsword
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq (%rdi), %rdi
movl $0x3bc5f, %esi          # imm = 0x3BC5F
movl $0xa8, %edx
callq 0x404a28
movq (%rbx), %rdi
movl $0x3bc60, %esi          # imm = 0x3BC60
movl $0x70, %edx
callq 0x404a28
movq (%rbx), %rdi
movl $0x3bc61, %esi          # imm = 0x3BC61
movl $0x56, %edx
callq 0x404a28
movq (%rbx), %rdi
movl $0x3bc62, %esi          # imm = 0x3BC62
movl $0xab, %edx
callq 0x404a28
movq (%rbx), %rdi
movl $0x3bc63, %esi          # imm = 0x3BC63
movl $0xbc, %edx
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x404a28
nop
// File: /workspace/github_cpp_makefile_star2_O1/Thilotilo[P]DoaERando/Randomizer.cpp
// Function: DoaERando::PullLuBuIds(std::vector<unsigned char, std::allocator<unsigned char>>&)
static void PullLuBuIds(vector<BYTE>& ids)
{
    // Remove all 4 Lu Bu bytes.
    PullIdFromVector(LU_BU_GEMSWORD_ID, ids);
    PullIdFromVector(LU_BU_NAN_YANG_ID, ids);
    PullIdFromVector(LU_BU_JI_ZHOU_ID, ids);
    PullIdFromVector(LU_BU_SHU_ID, ids);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl $0xbc, %edi
movq %rbx, %rsi
callq 0x406ce1
movl $0xc0, %edi
movq %rbx, %rsi
callq 0x406ce1
movl $0xc4, %edi
movq %rbx, %rsi
callq 0x406ce1
movl $0xb7, %edi
movq %rbx, %rsi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x406ce1
// File: /workspace/github_cpp_makefile_star2_O1/Thilotilo[P]DoaERando/Randomizer.cpp
// Function: DoaERando::appendNumber(std::vector<unsigned char, std::allocator<unsigned char>>&, int)
static void appendNumber(std::vector<BYTE>& v, int num)
{
    int digits = numDigits(num);

    int divisor = 1;
    for (int i = 1; i < digits; ++i)
    {
        divisor *= 10;
    }

    while (divisor > 0)
    {
        v.push_back((num / divisor) % 10);
        divisor /= 10;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %ebx
movq %rdi, %r14
movl $0x1, %r12d
movl $0x1, %eax
testl %esi, %esi
je 0x40a8fe
xorl %eax, %eax
movl %ebx, %ecx
movslq %ecx, %rdx
imulq $0x66666667, %rdx, %rcx # imm = 0x66666667
movq %rcx, %rsi
shrq $0x3f, %rsi
sarq $0x22, %rcx
addl %esi, %ecx
incl %eax
addl $0x9, %edx
cmpl $0x12, %edx
ja 0x40a8dd
cmpl $0x2, %eax
jl 0x40a916
decl %eax
movl $0x1, %r12d
addl %r12d, %r12d
leal (%r12,%r12,4), %r12d
decl %eax
jne 0x40a90b
leaq -0x29(%rbp), %r15
movl $0xcccccccd, %r13d      # imm = 0xCCCCCCCD
movl %ebx, %eax
cltd
idivl %r12d
cltq
imulq $0x66666667, %rax, %rcx # imm = 0x66666667
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x22, %rcx
addl %edx, %ecx
addl %ecx, %ecx
leal (%rcx,%rcx,4), %ecx
subl %ecx, %eax
movb %al, -0x29(%rbp)
movq 0x8(%r14), %rsi
cmpq 0x10(%r14), %rsi
je 0x40a958
movb %al, (%rsi)
incq 0x8(%r14)
jmp 0x40a963
movq %r14, %rdi
movq %r15, %rdx
callq 0x40ad06
movl %r12d, %eax
imulq %r13, %rax
shrq $0x23, %rax
cmpl $0x9, %r12d
movl %eax, %r12d
ja 0x40a920
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/General.cpp
// Function: DoaERando::General::General(int, unsigned char, DoaERando::ROM&)
General::General(int address, BYTE id, ROM& rom)
    : address(address)
    , id(id)
    , count(1)
    , encounterable(IsEncounterable(id, rom))
    , recruitable(IsRecruitable(id, rom))
{
    strength = rom.ReadByte(address + STRENGTH_OFFSET);
    intelligence = rom.ReadByte(address + INTELLIGENCE_OFFSET);
    zone = rom.ReadByte(address + ZONE_OFFSET);
    weaponId = rom.ReadByte(address + WEAPON_OFFSET) & WEAPON_BITMASK;
    enemyDefenseId = rom.ReadByte(address + ENEMY_DEFENSE_OFFSET);
    enemySoldierExponent = rom.ReadByte(address + ENEMY_SOLDIERS_OFFSET);
    allySoldierExponent = rom.ReadByte(address + ALLY_SOLDIERS_OFFSET);
    enemyMaxTacticLevel = rom.ReadByte(address + TACTICS_LEVEL_OFFSET);
    agility = rom.ReadByte(address + AGILITY_OFFSET);
    ReadName(rom);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %rbx
movl %esi, %r15d
movq %rdi, %r14
movl %edx, %r13d
notb %r13b
movl %esi, (%rdi)
movb %dl, 0x4(%rdi)
movb $0x1, 0x5(%rdi)
andb $0x7, %r13b
shrb $0x3, %dl
movzbl %dl, %r12d
leal 0x35722(%r12), %esi
movq %rcx, %rdi
callq 0x4049fe
movzbl %al, %eax
movzbl %r13b, %r13d
btl %r13d, %eax
setb 0x23(%r14)
addl $0x3b153, %r12d         # imm = 0x3B153
movq %rbx, %rdi
movl %r12d, %esi
callq 0x4049fe
movzbl %al, %eax
btl %r13d, %eax
setb 0x24(%r14)
movq %rbx, %rdi
movl %r15d, %esi
callq 0x4049fe
movb %al, 0x6(%r14)
leal 0x1(%r15), %esi
movq %rbx, %rdi
callq 0x4049fe
movb %al, 0x7(%r14)
leal 0x2(%r15), %esi
movq %rbx, %rdi
callq 0x4049fe
movb %al, 0x8(%r14)
leal 0x4(%r15), %esi
movq %rbx, %rdi
callq 0x4049fe
andb $0x1f, %al
movb %al, 0x9(%r14)
leal 0x5(%r15), %esi
movq %rbx, %rdi
callq 0x4049fe
movb %al, 0xa(%r14)
leal 0x6(%r15), %esi
movq %rbx, %rdi
callq 0x4049fe
movb %al, 0xb(%r14)
leal 0x7(%r15), %esi
movq %rbx, %rdi
callq 0x4049fe
movb %al, 0xc(%r14)
leal 0x8(%r15), %esi
movq %rbx, %rdi
callq 0x4049fe
movb %al, 0xd(%r14)
addl $0x9, %r15d
movq %rbx, %rdi
movl %r15d, %esi
callq 0x4049fe
movb %al, 0xe(%r14)
movq %r14, %rdi
movq %rbx, %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x40bc2c
// File: /workspace/github_cpp_makefile_star2_O1/Thilotilo[P]DoaERando/General.cpp
// Function: DoaERando::General::ReadName(DoaERando::ROM&)
void General::ReadName(ROM& rom)
{
    const int NAME_OFFSET = 20;
    int nameOffset = 0;
    while (rom.ReadByte(address + nameOffset + NAME_OFFSET) != 0xFF && nameOffset < 19)
    {
        char character = rom.ReadByte(address + nameOffset + NAME_OFFSET) + 'A' - 0x10;
        switch(rom.ReadByte(address + nameOffset + NAME_OFFSET))
        {
            case 0x2D:
                character = 'r';
                break;
            case 0x2F:
                character = 't';
                break;
            case 0x64:
                character = 'u';
                break;
            case 0x0A:
                character = ' ';
                break;
            default:
                break;
        }

        name[nameOffset++] = character;
    }
    name[nameOffset] = 0x00;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rax
movq %rdi, %rbx
movl (%rdi), %esi
addl $0x14, %esi
movq %rax, -0x30(%rbp)
movq %rax, %rdi
callq 0x4049fe
cmpb $-0x1, %al
je 0x40bcde
movl $0x14, %r12d
xorl %r14d, %r14d
movl (%rbx), %esi
addl %r12d, %esi
movq -0x30(%rbp), %r13
movq %r13, %rdi
callq 0x4049fe
movl %eax, %r15d
addb $0x31, %r15b
movl (%rbx), %esi
addl %r12d, %esi
movq %r13, %rdi
callq 0x4049fe
movzbl %al, %eax
cmpl $0x2e, %eax
jg 0x40bc9e
cmpl $0xa, %eax
je 0x40bcad
cmpl $0x2d, %eax
jne 0x40bcb5
movb $0x72, %r15b
jmp 0x40bcb5
cmpl $0x2f, %eax
je 0x40bcb2
cmpl $0x64, %eax
jne 0x40bcb5
movb $0x75, %r15b
jmp 0x40bcb5
movb $0x20, %r15b
jmp 0x40bcb5
movb $0x74, %r15b
leaq 0x1(%r14), %r13
movb %r15b, 0xf(%rbx,%r14)
incl %r12d
movl (%rbx), %esi
addl %r12d, %esi
movq -0x30(%rbp), %rdi
callq 0x4049fe
cmpq $0x11, %r14
ja 0x40bce1
movq %r13, %r14
cmpb $-0x1, %al
jne 0x40bc62
jmp 0x40bce1
xorl %r13d, %r13d
movb $0x0, 0xf(%rbx,%r13)
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/General.cpp
// Function: DoaERando::General::ScaleSoldiersForZone(DoaERando::RandomNumberGenerator&)
void General::ScaleSoldiersForZone(RNG& rng)
{
    // Zone 9 is tiger leveling
    const std::vector<BYTE> MIN_SOLDIERS = {1,   10,  24, 33, 48, 53, 64, 82,  99,  128};
    const std::vector<BYTE> MAX_SOLDIERS = {121, 27,  32, 47, 61, 60, 79, 111, 121, 148};

    BYTE randomizedSoldiers = rng.GetRandomByte(MIN_SOLDIERS[zone], MAX_SOLDIERS[zone]);
    {
        if (allySoldierExponent & 0x80)
        {
            printf("Tiger detected, not modifying the first value.\n");
            printf("Changing %s's enemy soldier exponent from %d to %d\n", name, 
                                                                           enemySoldierExponent,
                                                                           randomizedSoldiers);
            enemySoldierExponent = randomizedSoldiers;
        }
        else
        {
            printf("Changing %s's soldier exponent from %d (and %d) to %d\n", name,
                                                                              enemySoldierExponent,
                                                                              allySoldierExponent,
                                                                              randomizedSoldiers);
            enemySoldierExponent = randomizedSoldiers;
            allySoldierExponent = randomizedSoldiers;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x50, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movabsq $0x5240353021180a01, %rax # imm = 0x5240353021180A01
leaq -0x40(%rbp), %rsi
movq %rax, (%rsi)
movw $0x8063, 0x8(%rsi)      # imm = 0x8063
leaq -0x68(%rbp), %rdi
leaq -0x4a(%rbp), %r15
movl $0xa, %edx
movq %r15, %rcx
callq 0x40a9c2
movabsq $0x6f4f3c3d2f201b79, %rax # imm = 0x6F4F3C3D2F201B79
movq %rax, (%r15)
movw $0x9479, 0x8(%r15)      # imm = 0x9479
leaq -0x40(%rbp), %rdi
leaq -0x4a(%rbp), %rsi
leaq -0x21(%rbp), %rcx
movl $0xa, %edx
callq 0x40a9c2
movzbl 0x8(%rbx), %eax
movq -0x68(%rbp), %rcx
movzbl (%rcx,%rax), %esi
movq -0x40(%rbp), %rcx
movzbl (%rcx,%rax), %edx
movq %r14, %rdi
callq 0x410846
movl %eax, %r14d
movsbl 0xc(%rbx), %ecx
leaq 0xf(%rbx), %r12
movzbl %al, %r15d
testl %ecx, %ecx
js 0x40be4e
movzbl 0xb(%rbx), %edx
leaq 0x180861(%rip), %rdi    # 0x58c698
movq %r12, %rsi
movl %r15d, %r8d
xorl %eax, %eax
callq 0x4e21a0
movb %r14b, 0xb(%rbx)
movb %r14b, 0xc(%rbx)
jmp 0x40be76
leaq 0x180971(%rip), %rdi    # 0x58c7c6
callq 0x4e96e0
movzbl 0xb(%rbx), %edx
leaq 0x1807ff(%rip), %rdi    # 0x58c664
movq %r12, %rsi
movl %r15d, %ecx
xorl %eax, %eax
callq 0x4e21a0
movb %r14b, 0xb(%rbx)
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x40be84
callq 0x410b90
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0x40be92
callq 0x410b90
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x40beb5
callq 0x410b90
jmp 0x40beb5
movq %rax, %rbx
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0x40bec3
callq 0x410b90
movq %rbx, %rdi
callq 0x4bb660
nop
// File: /workspace/github_cpp_makefile_star2_O1/Thilotilo[P]DoaERando/General.cpp
// Function: DoaERando::General::ScaleAllySoldiersForAnotherZone(int, DoaERando::RandomNumberGenerator&)
void General::ScaleAllySoldiersForAnotherZone(int zone, RNG& rng)
{
    // Zone 9 is tiger leveling
    const std::vector<BYTE> MIN_SOLDIERS = {1,   10,  24, 33, 48, 53, 64, 82,  99,  128};
    const std::vector<BYTE> MAX_SOLDIERS = {121, 27,  32, 47, 61, 60, 79, 111, 121, 148};

    BYTE randomizedSoldiers = rng.GetRandomByte(MIN_SOLDIERS[zone], MAX_SOLDIERS[zone]);
    if (allySoldierExponent & 0x80)
    {
        printf("Tiger detected, not modifying ally soldiers\n");
    }
    else
    {
        printf("Changing %s's ally soldier exponent from %d to %d\n", name,
                                                                      allySoldierExponent,
                                                                      randomizedSoldiers);
        allySoldierExponent = randomizedSoldiers;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x50, %rsp
movq %rdx, %r14
movl %esi, %r15d
movq %rdi, %rbx
movabsq $0x5240353021180a01, %rax # imm = 0x5240353021180A01
leaq -0x40(%rbp), %rsi
movq %rax, (%rsi)
movw $0x8063, 0x8(%rsi)      # imm = 0x8063
leaq -0x68(%rbp), %rdi
leaq -0x4a(%rbp), %r12
movl $0xa, %edx
movq %r12, %rcx
callq 0x40a9c2
movabsq $0x6f4f3c3d2f201b79, %rax # imm = 0x6F4F3C3D2F201B79
movq %rax, (%r12)
movw $0x9479, 0x8(%r12)      # imm = 0x9479
leaq -0x40(%rbp), %rdi
leaq -0x4a(%rbp), %rsi
leaq -0x21(%rbp), %rcx
movl $0xa, %edx
callq 0x40a9c2
movslq %r15d, %rax
movq -0x68(%rbp), %rcx
movzbl (%rcx,%rax), %esi
movq -0x40(%rbp), %rcx
movzbl (%rcx,%rax), %edx
movq %r14, %rdi
callq 0x410846
movsbl 0xc(%rbx), %edx
testl %edx, %edx
js 0x40bf7d
movl %eax, %r14d
leaq 0xf(%rbx), %rsi
movzbl %al, %ecx
leaq 0x18075f(%rip), %rdi    # 0x58c6cf
xorl %eax, %eax
callq 0x4e21a0
movb %r14b, 0xc(%rbx)
jmp 0x40bf89
leaq 0x180871(%rip), %rdi    # 0x58c7f5
callq 0x4e96e0
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x40bf97
callq 0x410b90
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0x40bfa5
callq 0x410b90
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x40bfc8
callq 0x410b90
jmp 0x40bfc8
movq %rax, %rbx
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0x40bfd6
callq 0x410b90
movq %rbx, %rdi
callq 0x4bb660
// File: /workspace/github_cpp_makefile_star2_O1/Thilotilo[P]DoaERando/General.cpp
// Function: DoaERando::General::UpdateGeneral(DoaERando::ROM&)
void General::UpdateGeneral(ROM& rom)
{
    rom.WriteByte(address + STRENGTH_OFFSET, strength);
    rom.WriteByte(address + INTELLIGENCE_OFFSET, intelligence);
    rom.WriteByte(address + ZONE_OFFSET, zone);
    BYTE weaponPaletteByte = rom.ReadByte(address + WEAPON_OFFSET);
    weaponPaletteByte &= (~WEAPON_BITMASK);
    weaponPaletteByte |= weaponId;
    rom.WriteByte(address + WEAPON_OFFSET, weaponPaletteByte);
    rom.WriteByte(address + ENEMY_DEFENSE_OFFSET, enemyDefenseId);
    rom.WriteByte(address + ENEMY_SOLDIERS_OFFSET, enemySoldierExponent);
    rom.WriteByte(address + ALLY_SOLDIERS_OFFSET, allySoldierExponent);
    rom.WriteByte(address + TACTICS_LEVEL_OFFSET, enemyMaxTacticLevel);
    rom.WriteByte(address + AGILITY_OFFSET, agility);

    for (BYTE i = id; i < id + count - 1; ++i)
    {
        WriteEncounterableBit(i, false, rom);
        WriteRecruitableBit(i, false, rom);
    }
    WriteEncounterableBit(id + count - 1, encounterable, rom);
    WriteRecruitableBit(id + count - 1, recruitable, rom);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
movl (%rdi), %esi
movzbl 0x6(%rdi), %edx
movq %rbx, %rdi
callq 0x404a28
movl (%r14), %esi
incl %esi
movzbl 0x7(%r14), %edx
movq %rbx, %rdi
callq 0x404a28
movl (%r14), %esi
addl $0x2, %esi
movzbl 0x8(%r14), %edx
movq %rbx, %rdi
callq 0x404a28
movl (%r14), %esi
addl $0x4, %esi
movq %rbx, %rdi
callq 0x4049fe
andb $-0x20, %al
orb 0x9(%r14), %al
movl (%r14), %esi
addl $0x4, %esi
movzbl %al, %edx
movq %rbx, %rdi
callq 0x404a28
movl (%r14), %esi
addl $0x5, %esi
movzbl 0xa(%r14), %edx
movq %rbx, %rdi
callq 0x404a28
movl (%r14), %esi
addl $0x6, %esi
movzbl 0xb(%r14), %edx
movq %rbx, %rdi
callq 0x404a28
movl (%r14), %esi
addl $0x7, %esi
movzbl 0xc(%r14), %edx
movq %rbx, %rdi
callq 0x404a28
movl (%r14), %esi
addl $0x8, %esi
movzbl 0xd(%r14), %edx
movq %rbx, %rdi
callq 0x404a28
movl (%r14), %esi
addl $0x9, %esi
movzbl 0xe(%r14), %edx
movq %rbx, %rdi
callq 0x404a28
movzbl 0x4(%r14), %r15d
movzbl 0x5(%r14), %eax
addl %r15d, %eax
decl %eax
cmpl %r15d, %eax
jle 0x40c0f0
movzbl %r15b, %r15d
movl %r15d, %edi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x40c124
movl %r15d, %edi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x40c19a
incb %r15b
movzbl %r15b, %ecx
movzbl 0x4(%r14), %eax
movzbl 0x5(%r14), %edx
addl %edx, %eax
decl %eax
cmpl %ecx, %eax
jg 0x40c0b9
movzbl 0x23(%r14), %esi
movzbl %al, %edi
movq %rbx, %rdx
callq 0x40c124
movb 0x4(%r14), %al
addb 0x5(%r14), %al
decb %al
movzbl 0x24(%r14), %esi
movzbl %al, %edi
movq %rbx, %rdx
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x40c19a