LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_cpp_makefile_star2_O2/jweinst1[P]Pages/src/util/BlockStr.cpp
// Function: operator<(BlockStr const&, BlockStr const&)
bool operator<(const BlockStr& lhs, const BlockStr& rhs)
{
        long lhsTotal = 0;
        long rhsTotal = 0;
        const char* lhsPtr = lhs.getString();
        const char* rhsPtr = rhs.getString();
        while(*lhsPtr) lhsTotal += *lhsPtr++;
        while(*rhsPtr) rhsTotal += *rhsPtr++;
        return lhsTotal < rhsTotal;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq (%rdi), %rdx
movq (%rsi), %rcx
xorl %eax, %eax
movsbq (%rdx), %rsi
testq %rsi, %rsi
je 0x30dd
incq %rdx
addq %rsi, %rax
jmp 0x30cc
xorl %edx, %edx
movsbq (%rcx), %rsi
testq %rsi, %rsi
je 0x30f0
incq %rcx
addq %rsi, %rdx
jmp 0x30df
cmpq %rdx, %rax
setl %al
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/jweinst1[P]Pages/src/util/BlockStr.cpp
// Function: BlockStr::operator==(BlockStr const&) const
bool BlockStr::operator ==(const BlockStr& other) const
{
        const char* current = _str;
        const char* comp = other.getString();
        while(*comp && *current)
        {
                if((*comp++ != *current++)) return false;
        }
        if(*comp != '\0' || *current != '\0') return false;
        else return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq (%rdi), %rax
movq (%rsi), %rcx
xorl %edx, %edx
movb (%rcx,%rdx), %sil
movb (%rax,%rdx), %dil
testb %sil, %sil
je 0x3131
incq %rdx
cmpb %dil, %sil
je 0x3118
xorl %eax, %eax
jmp 0x3137
testb %dil, %dil
sete %al
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/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
pushq $0x4
popq %rdx
movq %r14, %rdi
callq 0x454fd0
movq (%r14), %rax
movq -0x18(%rax), %rax
testb $0x5, -0x218(%rbp,%rax)
jne 0x4047a8
movq -0x150(%rbp,%rax), %rsi
leaq -0x30(%rbp), %rdi
pushq $-0x1
popq %rdx
leaq -0x11(%rbp), %r9
xorl %ecx, %ecx
movl %edx, %r8d
callq 0x404ac8
leaq -0x30(%rbp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x404d94
movq %r14, %rdi
callq 0x404baa
leaq -0x238(%rbp), %rdi
callq 0x455d00
addq $0x230, %rsp            # imm = 0x230
popq %rbx
popq %r14
popq %rbp
retq
pushq $0x4
popq %rdi
callq 0x40f3c0
andl $0x0, (%rax)
movq $0x5f66e8, %rsi         # imm = 0x5F66E8
movq %rax, %rdi
xorl %edx, %edx
callq 0x410410
jmp 0x4047c6
movq %rax, %rbx
leaq -0x238(%rbp), %rdi
callq 0x455d00
movq %rbx, %rdi
callq 0x4ba600
nop
// File: /workspace/github_cpp_makefile_star2_O2/Thilotilo[P]DoaERando/Rom.cpp
// Function: DoaERando::ROM::WriteRom(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int, int, int, int)
void ROM::WriteRom(std::string path, int major, int minor, int patch, int seed)
{
    ostringstream oss;
    oss << path << "/DoaERando_v" << major << "_" << minor << "_" << patch << "_seed" << seed << ".nes";
    cout << "Writing to file " << oss.str() << endl;
    ofstream fout(oss.str(), ios::out | ios::binary);
    if (fout.fail()) throw 0;
    fout.write((char*)myContents.data(), myContents.size());
    fout.close();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3a8, %rsp            # imm = 0x3A8
movl %r9d, -0x2c(%rbp)
movl %r8d, %r15d
movl %ecx, %r12d
movl %edx, %r13d
movq %rsi, %rbx
movq %rdi, -0x38(%rbp)
leaq -0x3d0(%rbp), %r14
movq %r14, %rdi
callq 0x480c20
movq %r14, %rdi
movq %rbx, %rsi
callq 0x48b400
leaq 0x1867dd(%rip), %rsi    # 0x58b004
movq %rax, %rdi
callq 0x478a00
movq %rax, %rdi
movl %r13d, %esi
callq 0x478da0
leaq 0x18b1e3(%rip), %rsi    # 0x58fa24
movq %rax, %rdi
callq 0x478a00
movq %rax, %rdi
movl %r12d, %esi
callq 0x478da0
leaq 0x18b1c9(%rip), %rsi    # 0x58fa24
movq %rax, %rdi
callq 0x478a00
movq %rax, %rdi
movl %r15d, %esi
callq 0x478da0
leaq 0x18679c(%rip), %rsi    # 0x58b011
movq %rax, %rdi
callq 0x478a00
movq %rax, %rdi
movl -0x2c(%rbp), %esi
callq 0x478da0
leaq 0x186ce7(%rip), %rsi    # 0x58b576
movq %rax, %rdi
callq 0x478a00
movq $0x6014a0, %rdi         # imm = 0x6014A0
leaq 0x186772(%rip), %rsi    # 0x58b017
callq 0x478a00
movq %rax, %r15
leaq -0x3c8(%rbp), %r14
leaq -0x258(%rbp), %rdi
movq %r14, %rsi
callq 0x47e610
leaq -0x258(%rbp), %rsi
movq %r15, %rdi
callq 0x48b400
movq %rax, %rdi
callq 0x4782e0
leaq -0x258(%rbp), %rdi
callq 0x488900
leaq -0x58(%rbp), %rdi
movq %r14, %rsi
callq 0x47e610
leaq -0x258(%rbp), %rdi
leaq -0x58(%rbp), %rsi
pushq $0x14
popq %rdx
callq 0x455140
leaq -0x58(%rbp), %rdi
callq 0x488900
movq -0x258(%rbp), %rax
movq -0x18(%rax), %rax
testb $0x5, -0x238(%rbp,%rax)
jne 0x404973
movq -0x38(%rbp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
subq %rsi, %rdx
leaq -0x258(%rbp), %rdi
callq 0x478150
leaq -0x258(%rbp), %rdi
callq 0x455990
leaq -0x258(%rbp), %rdi
callq 0x455bc0
leaq -0x3d0(%rbp), %rdi
callq 0x47d520
addq $0x3a8, %rsp            # imm = 0x3A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x4
popq %rdi
callq 0x40f3c0
andl $0x0, (%rax)
movq $0x5f66e8, %rsi         # imm = 0x5F66E8
movq %rax, %rdi
xorl %edx, %edx
callq 0x410410
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
jmp 0x4049a6
jmp 0x4049be
jmp 0x4049be
movq %rax, %rbx
leaq -0x258(%rbp), %rdi
callq 0x488900
jmp 0x4049c1
movq %rax, %rbx
leaq -0x258(%rbp), %rdi
callq 0x455bc0
jmp 0x4049c1
movq %rax, %rbx
leaq -0x3d0(%rbp), %rdi
callq 0x47d520
movq %rbx, %rdi
callq 0x4ba600
nop
// File: /workspace/github_cpp_makefile_star2_O2/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 0x404e62
movl %eax, %r14d
addl $0x14, %r14d
movq (%rbx), %rdi
movl %r14d, %esi
callq 0x4049d6
cmpb $-0x1, %al
je 0x404f2b
movq (%rbx), %rdi
movl %r14d, %esi
callq 0x4049d6
movl %eax, %r15d
movq (%rbx), %rdi
movl %r14d, %esi
callq 0x4049d6
cmpb $0xa, %al
je 0x404f14
movzbl %al, %eax
cmpl $0x64, %eax
je 0x404f0a
cmpl $0x2f, %eax
je 0x404f0f
cmpl $0x2d, %eax
jne 0x404f19
movb $0x72, %r15b
jmp 0x404f1d
movb $0x75, %r15b
jmp 0x404f1d
movb $0x74, %r15b
jmp 0x404f1d
movb $0x20, %r15b
jmp 0x404f1d
addb $0x31, %r15b
movsbl %r15b, %edi
callq 0x4e8da0
incl %r14d
jmp 0x404ec7
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/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 0x18555a(%rip), %xmm0   # 0x58b397
leaq -0x50(%rbp), %rsi
movups %xmm0, 0xf(%rsi)
movups 0x18553c(%rip), %xmm0   # 0x58b388
movaps %xmm0, (%rsi)
leaq -0x30(%rbp), %rdi
pushq $0x1f
popq %rdx
leaq -0x11(%rbp), %rcx
callq 0x409c64
xorl %r14d, %r14d
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rcx
subq %rax, %rcx
cmpq %r14, %rcx
jbe 0x405e8b
movq (%rbx), %rdi
movzbl (%rax,%r14), %edx
leal 0x3c50b(%r14), %esi
callq 0x404a00
incq %r14
jmp 0x405e62
leaq -0x30(%rbp), %rdi
callq 0x404baa
addq $0x40, %rsp
popq %rbx
popq %r14
popq %rbp
retq
movq %rax, %rbx
leaq -0x30(%rbp), %rdi
callq 0x404baa
movq %rbx, %rdi
callq 0x4ba600
nop
// File: /workspace/github_cpp_makefile_star2_O2/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 0x185376(%rip), %rdi    # 0x58b2b8
callq 0x4e8680
movq (%rbx), %rdi
pushq $0xf
popq %rdx
movl $0x361d7, %esi          # imm = 0x361D7
callq 0x404a00
movq (%rbx), %rdi
pushq $0x42
popq %rdx
movl $0x361db, %esi          # imm = 0x361DB
callq 0x404a00
movq (%rbx), %rdi
pushq $0x3f
popq %rdx
movl $0x361df, %esi          # imm = 0x361DF
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x404a00
nop
// File: /workspace/github_cpp_makefile_star2_O2/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 0x185345(%rip), %rdi    # 0x58b2d3
callq 0x4e8680
movq (%rbx), %rdi
pushq $0x4
popq %rdx
movl $0x3f4d6, %esi          # imm = 0x3F4D6
callq 0x404a00
movq (%rbx), %rdi
pushq $0x1
popq %rdx
movl $0x3f51c, %esi          # imm = 0x3F51C
callq 0x404a00
movq (%rbx), %rdi
movl $0x3f522, %esi          # imm = 0x3F522
xorl %edx, %edx
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x404a00
// File: /workspace/github_cpp_makefile_star2_O2/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 %r14
pushq %rbx
movq %rdi, %rbx
leaq 0x18531b(%rip), %rdi    # 0x58b2f4
callq 0x4e8680
movq (%rbx), %rdi
pushq $0x1
popq %r14
movl $0x3642b, %esi          # imm = 0x3642B
movl %r14d, %edx
callq 0x404a00
movq (%rbx), %rdi
movl $0x3643b, %esi          # imm = 0x3643B
xorl %edx, %edx
callq 0x404a00
movq (%rbx), %rdi
movl $0x3be8b, %esi          # imm = 0x3BE8B
movl %r14d, %edx
popq %rbx
popq %r14
popq %rbp
jmp 0x404a00
nop
// File: /workspace/github_cpp_makefile_star2_O2/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
pushq $0xf
popq %r13
xorl %r15d, %r15d
subl $0x1, %r13d
jb 0x406103
movq %r14, %rdi
pushq $0x5
popq %rsi
pushq $0xa
popq %rdx
callq 0x40ed6a
movq (%rbx), %rdi
leal 0x3b666(%r15), %esi
movzbl %al, %r12d
movl %r12d, %edx
callq 0x404a00
leaq 0x185052(%rip), %rdi    # 0x58b143
movl %r15d, %esi
movl %r12d, %edx
xorl %eax, %eax
callq 0x4e1140
incl %r15d
jmp 0x4060c0
pushq $0xf
popq %r15
pushq $0x14
popq %rdx
movq %r14, %rdi
movl %r15d, %esi
callq 0x40ed6a
movq (%rbx), %rdi
movzbl %al, %ebx
movl $0x3b675, %esi          # imm = 0x3B675
movl %ebx, %edx
callq 0x404a00
leaq 0x185015(%rip), %rdi    # 0x58b143
movl %r15d, %esi
movl %ebx, %edx
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4e1140
// File: /workspace/github_cpp_makefile_star2_O2/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 %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdi, %rbx
xorl %r15d, %r15d
pushq $0x8
popq %r12
subl $0x1, %r12d
jb 0x40618d
movq (%rbx), %rdi
movl %r15d, %r14d
orl $0x39a28, %r14d         # imm = 0x39A28
movl %r14d, %esi
callq 0x4049d6
addb %al, %al
movq (%rbx), %rdi
movzbl %al, %edx
movl %r14d, %esi
callq 0x404a00
incl %r15d
jmp 0x40615d
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/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 0x40b848
movq %r14, %rdi
callq 0x40b864
movq (%rbx), %rdi
movl $0x3e8f0, %esi          # imm = 0x3E8F0
movl $0xc0, %edx
callq 0x404a00
movq (%rbx), %rdi
movl $0x3e8f1, %esi          # imm = 0x3E8F1
movl $0xd0, %edx
popq %rbx
popq %r14
popq %rbp
jmp 0x404a00
nop
// File: /workspace/github_cpp_makefile_star2_O2/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, -0x30(%rbp)
leaq 0x185122(%rip), %rdi    # 0x58b31b
callq 0x4e8680
pushq $0x1
popq %rsi
pushq $0x31
popq %rbx
leaq 0x184f5b(%rip), %r14    # 0x58b166
subl $0x1, %ebx
jb 0x40623b
leal 0x1(%rsi), %r15d
movq -0x30(%rbp), %rax
movq (%rax), %rdi
orl $0x3b880, %esi          # imm = 0x3B880
callq 0x4049d6
movzbl %al, %edx
movq %r14, %rdi
movl %r15d, %esi
xorl %eax, %eax
callq 0x4e1140
movl %r15d, %esi
jmp 0x40620b
movq -0x30(%rbp), %rax
leaq 0x8(%rax), %r12
movl $0x2710, %ebx           # imm = 0x2710
pushq $0x1
popq %r15
pushq $0x31
popq %r14
subl $0x1, %ebx
jb 0x406293
movq %r12, %rdi
movl %r15d, %esi
movl %r14d, %edx
callq 0x40ed6a
movzbl %al, %r13d
movq %r12, %rdi
movl %r15d, %esi
movl %r14d, %edx
callq 0x40ed6a
movzbl %al, %edx
movq -0x30(%rbp), %rax
movq (%rax), %rdi
movl $0x3b880, %eax          # imm = 0x3B880
addl %eax, %r13d
addl %eax, %edx
movl %r13d, %esi
callq 0x404a2a
jmp 0x406250
leaq 0x185094(%rip), %rdi    # 0x58b32e
callq 0x4e8680
leaq 0x184ec0(%rip), %r12    # 0x58b166
subl $0x1, %r14d
jb 0x4062db
leal 0x1(%r15), %r13d
movq -0x30(%rbp), %rax
movq (%rax), %rdi
orl $0x3b880, %r15d         # imm = 0x3B880
movl %r15d, %esi
callq 0x4049d6
movzbl %al, %edx
movq %r12, %rdi
movl %r13d, %esi
xorl %eax, %eax
callq 0x4e1140
movl %r13d, %r15d
jmp 0x4062a6
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/Thilotilo[P]DoaERando/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 0x40c754
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x40ca36
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x40cbc0
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x40cd34
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x40cf20
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x40d0ac
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x40d224
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x40d458
movq (%rbx), %rsi
movq %r14, %rdi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x40e436
nop
// File: /workspace/github_cpp_makefile_star2_O2/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 0x4049d6
orb $0x6, %al
movq (%rbx), %rdi
movzbl %al, %edx
movl $0x34761, %esi          # imm = 0x34761
callq 0x404a00
movq (%rbx), %rdi
pushq $0x9
popq %rdx
movl $0x30c2b, %esi          # imm = 0x30C2B
callq 0x404a00
movq (%rbx), %rdi
pushq $0x12
popq %rdx
movl $0x30c83, %esi          # imm = 0x30C83
callq 0x404a00
movq (%rbx), %rdi
pushq $0x3
popq %rdx
movl $0x30cdb, %esi          # imm = 0x30CDB
callq 0x404a00
movq (%rbx), %rdi
pushq $0xe
popq %rdx
movl $0x30d33, %esi          # imm = 0x30D33
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x404a00
// File: /workspace/github_cpp_makefile_star2_O2/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 0x40b916
movq %r15, %rdi
movl %r14d, %esi
xorl %edx, %edx
callq 0x40b9b0
movq %r15, %rdi
movl %r14d, %esi
xorl %edx, %edx
callq 0x40b9d4
movl %r14d, %edi
movq %rbx, %rsi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x4069af
// File: /workspace/github_cpp_makefile_star2_O2/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)
andw $0x0, 0x8(%rsi)
leaq -0x30(%rbp), %rdi
pushq $0xa
popq %rdx
leaq -0x11(%rbp), %rcx
callq 0x409c64
xorl %r14d, %r14d
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rcx
subq %rax, %rcx
cmpq %r14, %rcx
jbe 0x406b2e
movq (%rbx), %rdi
movzbl (%rax,%r14), %edx
leal 0x31420(%r14), %esi
callq 0x404a00
incq %r14
jmp 0x406b05
pushq $-0xb
popq %r14
testq %r14, %r14
je 0x406b4d
movq (%rbx), %rdi
leal 0x36eeb(%r14), %esi
xorl %edx, %edx
callq 0x404a00
incq %r14
jmp 0x406b32
leaq -0x30(%rbp), %rdi
callq 0x404baa
addq $0x30, %rsp
popq %rbx
popq %r14
popq %rbp
retq
jmp 0x406b61
movq %rax, %rbx
leaq -0x30(%rbp), %rdi
callq 0x404baa
movq %rbx, %rdi
callq 0x4ba600
nop
// File: /workspace/github_cpp_makefile_star2_O2/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
andw $0x0, 0xc(%rsi)
movb $0x0, 0xe(%rsi)
leaq -0x30(%rbp), %rdi
pushq $0xf
popq %rdx
leaq -0x11(%rbp), %rcx
callq 0x409c64
xorl %r14d, %r14d
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rcx
subq %rax, %rcx
cmpq %r14, %rcx
jbe 0x406be1
movq (%rbx), %rdi
movzbl (%rax,%r14), %edx
leal 0x394e6(%r14), %esi
callq 0x404a00
incq %r14
jmp 0x406bb8
pushq $-0x11
popq %r14
testq %r14, %r14
je 0x406c00
movq (%rbx), %rdi
leal 0x39598(%r14), %esi
xorl %edx, %edx
callq 0x404a00
incq %r14
jmp 0x406be5
leaq -0x30(%rbp), %rdi
callq 0x404baa
addq $0x30, %rsp
popq %rbx
popq %r14
popq %rbp
retq
jmp 0x406c14
movq %rax, %rbx
leaq -0x30(%rbp), %rdi
callq 0x404baa
movq %rbx, %rdi
callq 0x4ba600
// File: /workspace/github_cpp_makefile_star2_O2/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 0x4049d6
andb $-0x21, %al
movq (%rbx), %rdi
movzbl %al, %edx
movl $0x31a2d, %esi          # imm = 0x31A2D
callq 0x404a00
movq (%rbx), %rdi
movl $0x31a31, %esi          # imm = 0x31A31
movl $0xff, %edx
callq 0x404a00
movq (%rbx), %rdi
movl $0x31a32, %esi          # imm = 0x31A32
xorl %edx, %edx
callq 0x404a00
movq (%rbx), %rdi
movl $0x31a33, %esi          # imm = 0x31A33
xorl %edx, %edx
callq 0x404a00
pushq $0xf
popq %r14
subq $0x1, %r14
jb 0x406c9c
movq (%rbx), %rdi
movl $0x3536e, %esi          # imm = 0x3536E
xorl %edx, %edx
callq 0x404a00
jmp 0x406c85
popq %rbx
popq %r14
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/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 %r14
pushq %rbx
movq %rdi, %rbx
movq (%rdi), %rdi
pushq $0x1
popq %r14
movl $0x30a12, %esi          # imm = 0x30A12
movl %r14d, %edx
callq 0x404a00
movq (%rbx), %rdi
movl $0x30a52, %esi          # imm = 0x30A52
movl %r14d, %edx
callq 0x404a00
movq (%rbx), %rdi
pushq $0xa
popq %rdx
movl $0x30a92, %esi          # imm = 0x30A92
callq 0x404a00
movq (%rbx), %rdi
pushq $0x1e
popq %rdx
movl $0x30ad2, %esi          # imm = 0x30AD2
callq 0x404a00
movq (%rbx), %rdi
pushq $0x15
popq %rdx
movl $0x1f6f2, %esi          # imm = 0x1F6F2
popq %rbx
popq %r14
popq %rbp
jmp 0x404a00
// File: /workspace/github_cpp_makefile_star2_O2/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
subl $0x1, %r14d
jb 0x4073db
movq (%rbx), %rdi
movl $0x1daf9, %esi          # imm = 0x1DAF9
xorl %edx, %edx
callq 0x404a00
jmp 0x4073c4
pushq $0x36
popq %r14
movq (%rbx), %rdi
subl $0x1, %r14d
jb 0x4073f6
movl $0x1d27a, %esi          # imm = 0x1D27A
xorl %edx, %edx
callq 0x404a00
jmp 0x4073df
pushq $0x4c
popq %rdx
movl $0x1d241, %esi          # imm = 0x1D241
callq 0x404a00
movq (%rbx), %rdi
pushq $0x6a
popq %rdx
movl $0x1d242, %esi          # imm = 0x1D242
callq 0x404a00
movq (%rbx), %rdi
movl $0x1d243, %esi          # imm = 0x1D243
movl $0x92, %edx
popq %rbx
popq %r14
popq %rbp
jmp 0x404a00
nop
// File: /workspace/github_cpp_makefile_star2_O2/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 %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq (%rdi), %rdi
movl $0x3b03d, %esi          # imm = 0x3B03D
movl $0xf0, %edx
callq 0x404a00
movq (%rbx), %rdi
pushq $0x6
popq %r14
movl $0x3b03e, %esi          # imm = 0x3B03E
movl %r14d, %edx
callq 0x404a00
xorl %r15d, %r15d
movq (%rbx), %rdi
subl $0x1, %r14d
jb 0x4075f2
leal 0x3b03f(%r15), %esi
xorl %edx, %edx
callq 0x404a00
incl %r15d
jmp 0x4075d6
movl $0x3632d, %esi          # imm = 0x3632D
movl $0xff, %edx
callq 0x404a00
movq (%rbx), %rdi
movl $0x3632e, %esi          # imm = 0x3632E
movl $0xff, %edx
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x404a00
nop
// File: /workspace/github_cpp_makefile_star2_O2/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 0x404a00
movq (%rbx), %rdi
pushq $0x70
popq %rdx
movl $0x3bc60, %esi          # imm = 0x3BC60
callq 0x404a00
movq (%rbx), %rdi
pushq $0x56
popq %rdx
movl $0x3bc61, %esi          # imm = 0x3BC61
callq 0x404a00
movq (%rbx), %rdi
movl $0x3bc62, %esi          # imm = 0x3BC62
movl $0xab, %edx
callq 0x404a00
movq (%rbx), %rdi
movl $0x3bc63, %esi          # imm = 0x3BC63
movl $0xbc, %edx
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x404a00
nop
// File: /workspace/github_cpp_makefile_star2_O2/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 0x4069af
movl $0xc0, %edi
movq %rbx, %rsi
callq 0x4069af
movl $0xc4, %edi
movq %rbx, %rsi
callq 0x4069af
movl $0xb7, %edi
movq %rbx, %rsi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x4069af
nop
// File: /workspace/github_cpp_makefile_star2_O2/Thilotilo[P]DoaERando/Randomizer.cpp
// Function: DoaERando::numDigits(int)
static int numDigits(int num)
{
    int digits = 0;
    if (num == 0)
    {
        return 1;
    }
    while (num != 0)
    {
        num = num/10;
        digits++;
    }

    return digits;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
testl %edi, %edi
je 0x409ba0
movl %edi, %eax
xorl %ecx, %ecx
movl $0xa, %esi
testl %eax, %eax
je 0x409ba5
cltd
idivl %esi
incl %ecx
jmp 0x409b95
movl $0x1, %ecx
movl %ecx, %eax
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/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 %esi, %edi
callq 0x409b84
pushq $0x1
popq %r15
movl %r15d, %ecx
cmpl %eax, %ecx
jge 0x409bd6
imull $0xa, %r15d, %r15d
incl %ecx
jmp 0x409bca
pushq $0xa
popq %r13
leaq -0x29(%rbp), %r12
testl %r15d, %r15d
je 0x409c08
movl %ebx, %eax
cltd
idivl %r15d
cltd
idivl %r13d
movb %dl, -0x29(%rbp)
movq %r14, %rdi
movq %r12, %rsi
callq 0x409faa
movl %r15d, %eax
xorl %edx, %edx
divl %r13d
movl %eax, %r15d
jmp 0x409bde
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/Thilotilo[P]DoaERando/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 %r12
pushq %rbx
movq %rcx, %rbx
movl %edx, %r12d
movl %esi, %r15d
movq %rdi, %r14
movl %esi, (%rdi)
movb %r12b, 0x4(%rdi)
movb $0x1, 0x5(%rdi)
movl %edx, %edi
movq %rcx, %rsi
callq 0x40acb2
movb %al, 0x23(%r14)
movl %r12d, %edi
movq %rbx, %rsi
callq 0x40acec
movb %al, 0x24(%r14)
movq %rbx, %rdi
movl %r15d, %esi
callq 0x4049d6
movb %al, 0x6(%r14)
leal 0x1(%r15), %esi
movq %rbx, %rdi
callq 0x4049d6
movb %al, 0x7(%r14)
leal 0x2(%r15), %esi
movq %rbx, %rdi
callq 0x4049d6
movb %al, 0x8(%r14)
leal 0x4(%r15), %esi
movq %rbx, %rdi
callq 0x4049d6
andb $0x1f, %al
movb %al, 0x9(%r14)
leal 0x5(%r15), %esi
movq %rbx, %rdi
callq 0x4049d6
movb %al, 0xa(%r14)
leal 0x6(%r15), %esi
movq %rbx, %rdi
callq 0x4049d6
movb %al, 0xb(%r14)
leal 0x7(%r15), %esi
movq %rbx, %rdi
callq 0x4049d6
movb %al, 0xc(%r14)
leal 0x8(%r15), %esi
movq %rbx, %rdi
callq 0x4049d6
movb %al, 0xd(%r14)
addl $0x9, %r15d
movq %rbx, %rdi
movl %r15d, %esi
callq 0x4049d6
movb %al, 0xe(%r14)
movq %r14, %rdi
movq %rbx, %rsi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x40ad26
nop
// File: /workspace/github_cpp_makefile_star2_O2/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, %rbx
movq %rdi, %r14
leaq 0xf(%rdi), %r15
pushq $0x14
popq %r13
xorl %r12d, %r12d
movl (%r14), %esi
addl %r13d, %esi
movq %rbx, %rdi
callq 0x4049d6
cmpq $0x12, %r12
ja 0x40adc3
cmpb $-0x1, %al
je 0x40adc3
movq %r15, -0x30(%rbp)
movl (%r14), %esi
addl %r13d, %esi
movq %rbx, %rdi
callq 0x4049d6
movl %eax, %r15d
movl (%r14), %esi
addl %r13d, %esi
movq %rbx, %rdi
callq 0x4049d6
cmpb $0xa, %al
je 0x40ada5
movzbl %al, %eax
cmpl $0x64, %eax
je 0x40ad9b
cmpl $0x2f, %eax
je 0x40ada0
cmpl $0x2d, %eax
jne 0x40adaa
movb $0x72, %r15b
jmp 0x40adae
movb $0x75, %r15b
jmp 0x40adae
movb $0x74, %r15b
jmp 0x40adae
movb $0x20, %r15b
jmp 0x40adae
addb $0x31, %r15b
incq %r12
movq -0x30(%rbp), %rax
movb %r15b, (%rax)
movq %rax, %r15
incq %r15
incl %r13d
jmp 0x40ad45
movb $0x0, (%r15)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/Thilotilo[P]DoaERando/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
pushq $0xa
popq %r15
leaq -0x4a(%rbp), %r12
movq %r15, %rdx
movq %r12, %rcx
callq 0x409c64
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
movq %r15, %rdx
callq 0x409c64
movzbl 0x8(%rbx), %eax
movq -0x68(%rbp), %rcx
movzbl (%rcx,%rax), %esi
movq -0x40(%rbp), %rcx
movzbl (%rcx,%rax), %edx
movq %r14, %rdi
callq 0x40ed6a
movl %eax, %r14d
movsbl 0xc(%rbx), %ecx
leaq 0xf(%rbx), %r12
movzbl %al, %r15d
testl %ecx, %ecx
js 0x40af30
movzbl 0xb(%rbx), %edx
leaq 0x180755(%rip), %rdi    # 0x58b66e
movq %r12, %rsi
movl %r15d, %r8d
xorl %eax, %eax
callq 0x4e1140
movb %r14b, 0xb(%rbx)
movb %r14b, 0xc(%rbx)
jmp 0x40af58
leaq 0x180865(%rip), %rdi    # 0x58b79c
callq 0x4e8680
movzbl 0xb(%rbx), %edx
leaq 0x1806f3(%rip), %rdi    # 0x58b63a
movq %r12, %rsi
movl %r15d, %ecx
xorl %eax, %eax
callq 0x4e1140
movb %r14b, 0xb(%rbx)
leaq -0x40(%rbp), %rdi
callq 0x404baa
leaq -0x68(%rbp), %rdi
callq 0x404baa
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
callq 0x404baa
jmp 0x40af88
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x404baa
movq %rbx, %rdi
callq 0x4ba600
nop
// File: /workspace/github_cpp_makefile_star2_O2/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 %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, %r14
movl %esi, %r15d
movq %rdi, %rbx
movabsq $0x5240353021180a01, %rax # imm = 0x5240353021180A01
leaq -0x48(%rbp), %rsi
movq %rax, (%rsi)
movw $0x8063, 0x8(%rsi)      # imm = 0x8063
leaq -0x70(%rbp), %rdi
pushq $0xa
popq %r12
leaq -0x52(%rbp), %r13
movq %r12, %rdx
movq %r13, %rcx
callq 0x409c64
movabsq $0x6f4f3c3d2f201b79, %rax # imm = 0x6F4F3C3D2F201B79
movq %rax, (%r13)
movw $0x9479, 0x8(%r13)      # imm = 0x9479
leaq -0x48(%rbp), %rdi
leaq -0x52(%rbp), %rsi
leaq -0x29(%rbp), %rcx
movq %r12, %rdx
callq 0x409c64
movslq %r15d, %rax
movq -0x70(%rbp), %rcx
movzbl (%rcx,%rax), %esi
movq -0x48(%rbp), %rcx
movzbl (%rcx,%rax), %edx
movq %r14, %rdi
callq 0x40ed6a
movsbl 0xc(%rbx), %edx
testl %edx, %edx
js 0x40b04c
movl %eax, %r14d
leaq 0xf(%rbx), %rsi
movzbl %al, %ecx
leaq 0x180666(%rip), %rdi    # 0x58b6a5
xorl %eax, %eax
callq 0x4e1140
movb %r14b, 0xc(%rbx)
jmp 0x40b058
leaq 0x180778(%rip), %rdi    # 0x58b7cb
callq 0x4e8680
leaq -0x48(%rbp), %rdi
callq 0x404baa
leaq -0x70(%rbp), %rdi
callq 0x404baa
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x404baa
jmp 0x40b08a
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x404baa
movq %rbx, %rdi
callq 0x4ba600
nop
// File: /workspace/github_cpp_makefile_star2_O2/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 0x404a00
movl (%r14), %esi
incl %esi
movzbl 0x7(%r14), %edx
movq %rbx, %rdi
callq 0x404a00
movl (%r14), %esi
addl $0x2, %esi
movzbl 0x8(%r14), %edx
movq %rbx, %rdi
callq 0x404a00
movl (%r14), %esi
addl $0x4, %esi
movq %rbx, %rdi
callq 0x4049d6
andb $-0x20, %al
orb 0x9(%r14), %al
movl (%r14), %esi
addl $0x4, %esi
movzbl %al, %edx
movq %rbx, %rdi
callq 0x404a00
movl (%r14), %esi
addl $0x5, %esi
movzbl 0xa(%r14), %edx
movq %rbx, %rdi
callq 0x404a00
movl (%r14), %esi
addl $0x6, %esi
movzbl 0xb(%r14), %edx
movq %rbx, %rdi
callq 0x404a00
movl (%r14), %esi
addl $0x7, %esi
movzbl 0xc(%r14), %edx
movq %rbx, %rdi
callq 0x404a00
movl (%r14), %esi
addl $0x8, %esi
movzbl 0xd(%r14), %edx
movq %rbx, %rdi
callq 0x404a00
movl (%r14), %esi
addl $0x9, %esi
movzbl 0xe(%r14), %edx
movq %rbx, %rdi
callq 0x404a00
movb 0x4(%r14), %al
movl %eax, %r15d
movzbl %r15b, %r15d
movzbl %al, %eax
movzbl 0x5(%r14), %ecx
addl %ecx, %eax
decl %eax
cmpl %r15d, %eax
jle 0x40b1a2
movl %r15d, %edi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x40b1d6
movl %r15d, %edi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x40b24c
incb %r15b
movb 0x4(%r14), %al
jmp 0x40b16a
movzbl 0x23(%r14), %esi
movzbl %al, %edi
movq %rbx, %rdx
callq 0x40b1d6
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 0x40b24c