LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_cpp_makefile_star2_O3/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 0x404a24
movq (%rbx), %rdi
movl $0x3b03e, %esi          # imm = 0x3B03E
movl $0x6, %edx
callq 0x404a24
movl $0x3b03f, %r14d         # imm = 0x3B03F
movq (%rbx), %rdi
movl %r14d, %esi
xorl %edx, %edx
callq 0x404a24
incl %r14d
cmpl $0x3b045, %r14d         # imm = 0x3B045
jne 0x407a1c
movq (%rbx), %rdi
movl $0x3632d, %esi          # imm = 0x3632D
movl $0xff, %edx
callq 0x404a24
movq (%rbx), %rdi
movl $0x3632e, %esi          # imm = 0x3632E
movl $0xff, %edx
popq %rbx
popq %r14
popq %rbp
jmp 0x404a24
nop
// File: /workspace/github_cpp_makefile_star2_O3/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 0x404a24
movq (%rbx), %rdi
movl $0x3bc60, %esi          # imm = 0x3BC60
movl $0x70, %edx
callq 0x404a24
movq (%rbx), %rdi
movl $0x3bc61, %esi          # imm = 0x3BC61
movl $0x56, %edx
callq 0x404a24
movq (%rbx), %rdi
movl $0x3bc62, %esi          # imm = 0x3BC62
movl $0xab, %edx
callq 0x404a24
movq (%rbx), %rdi
movl $0x3bc63, %esi          # imm = 0x3BC63
movl $0xbc, %edx
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x404a24
nop
// File: /workspace/github_cpp_makefile_star2_O3/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 0x406c93
movl $0xc0, %edi
movq %rbx, %rsi
callq 0x406c93
movl $0xc4, %edi
movq %rbx, %rsi
callq 0x406c93
movl $0xb7, %edi
movq %rbx, %rsi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x406c93
nop
// File: /workspace/github_cpp_makefile_star2_O3/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
testl %esi, %esi
je 0x40a91d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %ebx, %ecx
movslq %ecx, %rdx
imulq $0x66666667, %rdx, %rcx # imm = 0x66666667
movq %rcx, %rsi
shrq $0x3f, %rsi
sarq $0x22, %rcx
addl %esi, %ecx
addl $0x9, %edx
incl %eax
cmpl $0x12, %edx
ja 0x40a8e7
testl %eax, %eax
je 0x40a91d
movl $0x1, %r12d
addl %r12d, %r12d
leal (%r12,%r12,4), %r12d
decl %eax
jne 0x40a912
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 0x40a95f
movb %al, (%rsi)
incq 0x8(%r14)
jmp 0x40a96a
movq %r14, %rdi
movq %r15, %rdx
callq 0x40ad1c
movl %r12d, %eax
imulq %r13, %rax
shrq $0x23, %rax
cmpl $0x9, %r12d
movl %eax, %r12d
ja 0x40a927
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/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 0x4049fa
movzbl %al, %eax
movzbl %r13b, %r13d
btl %r13d, %eax
setb 0x23(%r14)
addl $0x3b153, %r12d         # imm = 0x3B153
movq %rbx, %rdi
movl %r12d, %esi
callq 0x4049fa
movzbl %al, %eax
btl %r13d, %eax
setb 0x24(%r14)
movq %rbx, %rdi
movl %r15d, %esi
callq 0x4049fa
movb %al, 0x6(%r14)
leal 0x1(%r15), %esi
movq %rbx, %rdi
callq 0x4049fa
movb %al, 0x7(%r14)
leal 0x2(%r15), %esi
movq %rbx, %rdi
callq 0x4049fa
movb %al, 0x8(%r14)
leal 0x4(%r15), %esi
movq %rbx, %rdi
callq 0x4049fa
andb $0x1f, %al
movb %al, 0x9(%r14)
leal 0x5(%r15), %esi
movq %rbx, %rdi
callq 0x4049fa
movb %al, 0xa(%r14)
leal 0x6(%r15), %esi
movq %rbx, %rdi
callq 0x4049fa
movb %al, 0xb(%r14)
leal 0x7(%r15), %esi
movq %rbx, %rdi
callq 0x4049fa
movb %al, 0xc(%r14)
leal 0x8(%r15), %esi
movq %rbx, %rdi
callq 0x4049fa
movb %al, 0xd(%r14)
addl $0x9, %r15d
movq %rbx, %rdi
movl %r15d, %esi
callq 0x4049fa
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 0x40bc68
// File: /workspace/github_cpp_makefile_star2_O3/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 0x4049fa
cmpb $-0x1, %al
je 0x40bd1a
movl $0x14, %r12d
xorl %r14d, %r14d
movl (%rbx), %esi
addl %r12d, %esi
movq -0x30(%rbp), %r13
movq %r13, %rdi
callq 0x4049fa
movl %eax, %r15d
addb $0x31, %r15b
movl (%rbx), %esi
addl %r12d, %esi
movq %r13, %rdi
callq 0x4049fa
movzbl %al, %eax
cmpl $0x2e, %eax
jg 0x40bcda
cmpl $0xa, %eax
je 0x40bce9
cmpl $0x2d, %eax
jne 0x40bcf1
movb $0x72, %r15b
jmp 0x40bcf1
cmpl $0x2f, %eax
je 0x40bcee
cmpl $0x64, %eax
jne 0x40bcf1
movb $0x75, %r15b
jmp 0x40bcf1
movb $0x20, %r15b
jmp 0x40bcf1
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 0x4049fa
cmpq $0x11, %r14
ja 0x40bd1d
movq %r13, %r14
cmpb $-0x1, %al
jne 0x40bc9e
jmp 0x40bd1d
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_O3/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 0x40a9ca
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 0x40a9ca
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 0x40be8a
movzbl 0xb(%rbx), %edx
leaq 0x180825(%rip), %rdi    # 0x58c698
movq %r12, %rsi
movl %r15d, %r8d
xorl %eax, %eax
callq 0x4e21a0
movb %r14b, 0xb(%rbx)
movb %r14b, 0xc(%rbx)
jmp 0x40beb2
leaq 0x180935(%rip), %rdi    # 0x58c7c6
callq 0x4e96e0
movzbl 0xb(%rbx), %edx
leaq 0x1807c3(%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 0x40bec0
callq 0x410b90
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0x40bece
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 0x40bef1
callq 0x410b90
jmp 0x40bef1
movq %rax, %rbx
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0x40beff
callq 0x410b90
movq %rbx, %rdi
callq 0x4bb660
nop
// File: /workspace/github_cpp_makefile_star2_O3/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 0x40a9ca
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 0x40a9ca
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 0x40bfb9
movl %eax, %r14d
leaq 0xf(%rbx), %rsi
movzbl %al, %ecx
leaq 0x180723(%rip), %rdi    # 0x58c6cf
xorl %eax, %eax
callq 0x4e21a0
movb %r14b, 0xc(%rbx)
jmp 0x40bfc5
leaq 0x180835(%rip), %rdi    # 0x58c7f5
callq 0x4e96e0
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x40bfd3
callq 0x410b90
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0x40bfe1
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 0x40c004
callq 0x410b90
jmp 0x40c004
movq %rax, %rbx
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0x40c012
callq 0x410b90
movq %rbx, %rdi
callq 0x4bb660
// File: /workspace/github_cpp_makefile_star2_O3/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 0x404a24
movl (%r14), %esi
incl %esi
movzbl 0x7(%r14), %edx
movq %rbx, %rdi
callq 0x404a24
movl (%r14), %esi
addl $0x2, %esi
movzbl 0x8(%r14), %edx
movq %rbx, %rdi
callq 0x404a24
movl (%r14), %esi
addl $0x4, %esi
movq %rbx, %rdi
callq 0x4049fa
andb $-0x20, %al
orb 0x9(%r14), %al
movl (%r14), %esi
addl $0x4, %esi
movzbl %al, %edx
movq %rbx, %rdi
callq 0x404a24
movl (%r14), %esi
addl $0x5, %esi
movzbl 0xa(%r14), %edx
movq %rbx, %rdi
callq 0x404a24
movl (%r14), %esi
addl $0x6, %esi
movzbl 0xb(%r14), %edx
movq %rbx, %rdi
callq 0x404a24
movl (%r14), %esi
addl $0x7, %esi
movzbl 0xc(%r14), %edx
movq %rbx, %rdi
callq 0x404a24
movl (%r14), %esi
addl $0x8, %esi
movzbl 0xd(%r14), %edx
movq %rbx, %rdi
callq 0x404a24
movl (%r14), %esi
addl $0x9, %esi
movzbl 0xe(%r14), %edx
movq %rbx, %rdi
callq 0x404a24
movzbl 0x4(%r14), %r15d
movzbl 0x5(%r14), %eax
addl %r15d, %eax
decl %eax
cmpl %r15d, %eax
jle 0x40c12c
movzbl %r15b, %r15d
movl %r15d, %edi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x40c160
movl %r15d, %edi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x40c1d6
incb %r15b
movzbl %r15b, %ecx
movzbl 0x4(%r14), %eax
movzbl 0x5(%r14), %edx
addl %edx, %eax
decl %eax
cmpl %ecx, %eax
jg 0x40c0f5
movzbl 0x23(%r14), %esi
movzbl %al, %edi
movq %rbx, %rdx
callq 0x40c160
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 0x40c1d6
// File: /workspace/github_cpp_makefile_star2_O3/Thilotilo[P]DoaERando/General.cpp
// Function: DoaERando::General::DumpGeneral()
void General::DumpGeneral()
{
    printf("%s:\n", name);
    printf("\tid: 0x%02X\n", id);
    printf("\taddress: 0x%X\n", address);
    printf("\tcount: %d\n", count);
    printf("\tSTR: %d\n", strength);
    printf("\tINT: %d\n", intelligence);
    printf("\tAGI: %d\n", agility);
    printf("\tzone: %d\n", zone);
    printf("\tHP exp: %d, %d\n", enemySoldierExponent, allySoldierExponent);
    printf("\tDefense: %d\n", enemyDefenseId);
    printf("\tMax Tactic Level: %d\n", enemyMaxTacticLevel);
    printf("\tWeapon: 0x%02X\n", weaponId);
    printf("\tEncounterable? %d\n", encounterable);
    printf("\tRecruitable? %d\n", recruitable);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0xf(%rdi), %rsi
leaq 0x1804a2(%rip), %rdi    # 0x58c702
xorl %eax, %eax
callq 0x4e21a0
movzbl 0x4(%rbx), %esi
leaq 0x180495(%rip), %rdi    # 0x58c707
xorl %eax, %eax
callq 0x4e21a0
movl (%rbx), %esi
leaq 0x180492(%rip), %rdi    # 0x58c714
xorl %eax, %eax
callq 0x4e21a0
movzbl 0x5(%rbx), %esi
leaq 0x180490(%rip), %rdi    # 0x58c724
xorl %eax, %eax
callq 0x4e21a0
movzbl 0x6(%rbx), %esi
leaq 0x18048a(%rip), %rdi    # 0x58c730
xorl %eax, %eax
callq 0x4e21a0
movzbl 0x7(%rbx), %esi
leaq 0x180482(%rip), %rdi    # 0x58c73a
xorl %eax, %eax
callq 0x4e21a0
movzbl 0xe(%rbx), %esi
leaq 0x18047a(%rip), %rdi    # 0x58c744
xorl %eax, %eax
callq 0x4e21a0
movzbl 0x8(%rbx), %esi
leaq 0x180472(%rip), %rdi    # 0x58c74e
xorl %eax, %eax
callq 0x4e21a0
movzbl 0xb(%rbx), %esi
movzbl 0xc(%rbx), %edx
leaq 0x180467(%rip), %rdi    # 0x58c759
xorl %eax, %eax
callq 0x4e21a0
movzbl 0xa(%rbx), %esi
leaq 0x180466(%rip), %rdi    # 0x58c76a
xorl %eax, %eax
callq 0x4e21a0
movzbl 0xd(%rbx), %esi
leaq 0x180462(%rip), %rdi    # 0x58c778
xorl %eax, %eax
callq 0x4e21a0
movzbl 0x9(%rbx), %esi
leaq 0x180467(%rip), %rdi    # 0x58c78f
xorl %eax, %eax
callq 0x4e21a0
movzbl 0x23(%rbx), %esi
leaq 0x180466(%rip), %rdi    # 0x58c7a0
xorl %eax, %eax
callq 0x4e21a0
movzbl 0x24(%rbx), %esi
leaq 0x180468(%rip), %rdi    # 0x58c7b4
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x4e21a0
nopl (%rax)
// File: /workspace/github_cpp_makefile_star2_O3/Thilotilo[P]DoaERando/Generals.cpp
// Function: DoaERando::Generals::ReadGenerals()
void Generals::ReadGenerals()
{
    for (BYTE i = 5; i < 0xD8; ++i)
    {
        if (i != UV10_ID)
        {
            AddGeneral(i);
            if (i == LIU_BEI_ID || i == CAO_PI_ID ||
                i == SIMA_YI_ID || i == SUN_QUAN_ID)
            {
                myRestrictedGeneralAddresses.push_back(GetGeneralAddress(i));
            }
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0x18(%rdi), %r14
movb $0x52, %r13b
movabsq $0x80000000800001, %r15 # imm = 0x80000000800001
testb %r13b, %r13b
je 0x40c445
leal -0x4d(%r13), %eax
movzbl %al, %r12d
movq %rbx, %rdi
movl %r12d, %esi
callq 0x40c4c6
leal -0x71(%r12), %eax
cmpl $0x37, %eax
ja 0x40c40a
btq %rax, %r15
jb 0x40c410
cmpl $0x57, %r12d
jne 0x40c445
movq %rbx, %rdi
movl %r12d, %esi
callq 0x40c46e
addl $0x28010, %eax          # imm = 0x28010
movl %eax, -0x2c(%rbp)
movq 0x20(%rbx), %rsi
cmpq 0x28(%rbx), %rsi
je 0x40c439
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x20(%rbx)
jmp 0x40c445
movq %r14, %rdi
leaq -0x2c(%rbp), %rdx
callq 0x40d076
incb %r13b
cmpb $0x25, %r13b
jne 0x40c3e2
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/Thilotilo[P]DoaERando/Generals.cpp
// Function: DoaERando::Generals::AddGeneral(unsigned char)
void Generals::AddGeneral(BYTE id)
{
    if (GeneralExists(id))
    {
        AddCopy(id);
    }
    else
    {
        auto address = GetGeneralAddress(id);
        General general(address, id, myRom);
        myGenerals.push_back(general);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x30, %rsp
movl %esi, %r14d
movq %rdi, %rbx
callq 0x40c556
testb %al, %al
je 0x40c4f4
movzbl %r14b, %esi
movq %rbx, %rdi
addq $0x30, %rsp
popq %rbx
popq %r14
popq %rbp
jmp 0x40c5d0
movzbl %r14b, %r14d
movq %rbx, %rdi
movl %r14d, %esi
callq 0x40c46e
leal 0x28010(%rax), %esi
movq 0x48(%rbx), %rcx
leaq -0x38(%rbp), %rdi
movl %r14d, %edx
callq 0x40bad8
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x40c541
movq -0x18(%rbp), %rax
movq %rax, 0x20(%rsi)
movups -0x38(%rbp), %xmm0
movups -0x28(%rbp), %xmm1
movups %xmm1, 0x10(%rsi)
movups %xmm0, (%rsi)
addq $0x28, 0x8(%rbx)
jmp 0x40c54d
leaq -0x38(%rbp), %rdx
movq %rbx, %rdi
callq 0x40d1ae
addq $0x30, %rsp
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/Thilotilo[P]DoaERando/Generals.cpp
// Function: DoaERando::Generals::AddCopy(unsigned char)
void Generals::AddCopy(BYTE id)
{
    auto address = GetGeneralAddress(id);
    for (auto& general: myGenerals)
    {
        if (general.address == address)
        {
            general.count++;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
callq 0x40c46e
movq (%rbx), %rcx
movq 0x8(%rbx), %rdx
cmpq %rdx, %rcx
je 0x40c5ff
addl $0x28010, %eax          # imm = 0x28010
cmpl %eax, (%rcx)
jne 0x40c5f6
incb 0x5(%rcx)
addq $0x28, %rcx
cmpq %rdx, %rcx
jne 0x40c5ef
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/Thilotilo[P]DoaERando/Generals.cpp
// Function: DoaERando::Generals::AdjustZone1Generals()
void Generals::AdjustZone1Generals()
{
    // These are generals that are not found in zone 1 but are marked as zone 1, making
    //  zone 1 over populated:

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

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

// Assembly:
movq (%rdi), %rcx
movq 0x8(%rdi), %rdi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
subq %rcx, %rdi
je 0x40c703
pushq %rbp
movq %rsp, %rbp
sarq $0x3, %rdi
movabsq $-0x3333333333333333, %rdx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rdi, %rdx
movzbl %sil, %esi
cmpq $0x1, %rdx
adcq $0x0, %rdx
xorl %edi, %edi
leaq (%rdi,%rdi,4), %r9
movzbl 0x5(%rcx,%r9,8), %r8d
testl %r8d, %r8d
je 0x40c6f6
movzbl 0x4(%rcx,%r9,8), %r9d
addl %r9d, %r8d
cmpl %r9d, %esi
je 0x40c700
incl %r9d
cmpl %r8d, %r9d
jb 0x40c6e9
incq %rdi
cmpq %rdx, %rdi
jne 0x40c6d1
jmp 0x40c702
movl %edi, %eax
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/Thilotilo[P]DoaERando/Generals.cpp
// Function: DoaERando::Generals::SwapIDs(int, int)
void Generals::SwapIDs(int slot1, int slot2)
{
    if (!isRestrictedGeneralAddress(myGenerals[slot1].address) &&
        !isRestrictedGeneralAddress(myGenerals[slot2].address))
    {
        auto tempId = myGenerals[slot1].id;
        auto tempCount = myGenerals[slot1].count;
        myGenerals[slot1].id = myGenerals[slot2].id;
        myGenerals[slot1].count = myGenerals[slot2].count;
        myGenerals[slot2].id = tempId;
        myGenerals[slot2].count = tempCount;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movslq %esi, %rcx
movq (%rdi), %rax
movq 0x18(%rdi), %rsi
leaq (%rcx,%rcx,4), %rcx
movq 0x20(%rdi), %rdi
cmpq %rdi, %rsi
je 0x40c752
movl (%rax,%rcx,8), %r8d
movq %rsi, %r9
cmpl %r8d, (%r9)
je 0x40c779
addq $0x4, %r9
cmpq %rdi, %r9
jne 0x40c726
movslq %edx, %rdx
leaq (%rdx,%rdx,4), %rdx
leaq (%rax,%rdx,8), %rdx
movl (%rdx), %r8d
cmpl %r8d, (%rsi)
je 0x40c779
addq $0x4, %rsi
cmpq %rdi, %rsi
jne 0x40c742
jmp 0x40c75d
movslq %edx, %rdx
leaq (%rdx,%rdx,4), %rdx
leaq (%rax,%rdx,8), %rdx
leaq (%rax,%rcx,8), %rax
movzwl 0x4(%rax), %ecx
movb 0x4(%rdx), %sil
movb %sil, 0x4(%rax)
movb 0x5(%rdx), %sil
movb %sil, 0x5(%rax)
movw %cx, 0x4(%rdx)
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/Thilotilo[P]DoaERando/Generals.cpp
// Function: DoaERando::Generals::SwapZones(int, int)
void Generals::SwapZones(int slot1, int slot2)
{
    if (!isRestrictedGeneralAddress(myGenerals[slot1].address) &&
        !isRestrictedGeneralAddress(myGenerals[slot2].address))
    {
        auto tempZone = myGenerals[slot1].zone;
        myGenerals[slot1].zone = myGenerals[slot2].zone;
        myGenerals[slot2].zone = tempZone;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movslq %esi, %rcx
movq (%rdi), %rax
movq 0x18(%rdi), %rsi
leaq (%rcx,%rcx,4), %rcx
movq 0x20(%rdi), %rdi
cmpq %rdi, %rsi
je 0x40c7f5
movl (%rax,%rcx,8), %r8d
movq %rsi, %r9
cmpl %r8d, (%r9)
je 0x40c812
addq $0x4, %r9
cmpq %rdi, %r9
jne 0x40c7cc
movslq %edx, %rdx
leaq (%rdx,%rdx,4), %r8
movl (%rax,%r8,8), %r8d
cmpl %r8d, (%rsi)
je 0x40c812
addq $0x4, %rsi
cmpq %rdi, %rsi
jne 0x40c7e5
jmp 0x40c7f8
movslq %edx, %rdx
leaq (%rax,%rcx,8), %rcx
movb 0x8(%rcx), %sil
leaq (%rdx,%rdx,4), %rdx
movb 0x8(%rax,%rdx,8), %dil
movb %dil, 0x8(%rcx)
movb %sil, 0x8(%rax,%rdx,8)
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/Thilotilo[P]DoaERando/Generals.cpp
// Function: DoaERando::Generals::SetZonesForZone0(DoaERando::RandomNumberGenerator&)
void Generals::SetZonesForZone0(RNG& rng)
{
    for (auto& general : myGenerals)
    {
        if (general.zone == 0)
        {
            // Zone 1 already has too many generals, let's only allow zone 2 and above:
            general.zone = rng.GetRandomByte(2, 8);
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq (%rdi), %r14
movq 0x8(%rdi), %r15
cmpq %r15, %r14
je 0x40c853
movq %rsi, %rbx
cmpb $0x0, 0x8(%r14)
jne 0x40c84a
movq %rbx, %rdi
movl $0x2, %esi
movl $0x8, %edx
callq 0x410846
movb %al, 0x8(%r14)
addq $0x28, %r14
cmpq %r15, %r14
jne 0x40c82d
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/Thilotilo[P]DoaERando/Generals.cpp
// Function: DoaERando::Generals::ScaleForZone(DoaERando::RandomNumberGenerator&)
void Generals::ScaleForZone(RNG& rng)
{
    for (auto& general : myGenerals)
    {
        if (general.id != CAO_PI_ID &&
            general.id != SIMA_YI_ID &&
            general.id != SUN_QUAN_ID)
        {
            general.ScaleWeaponForZone(rng);
            general.ScaleArmorForZone(rng);
            general.ScaleMaxTacticForZone(rng);
            general.ScaleSoldiersForZone(rng);
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq (%rdi), %r14
movq 0x8(%rdi), %r15
cmpq %r15, %r14
je 0x40c938
movq %rsi, %rbx
movabsq $0x2000004000001, %r12  # imm = 0x2000004000001
movzbl 0x4(%r14), %eax
addl $-0x57, %eax
cmpl $0x31, %eax
ja 0x40c903
btq %rax, %r12
jb 0x40c92f
movq %r14, %rdi
movq %rbx, %rsi
callq 0x40bd32
movq %r14, %rdi
movq %rbx, %rsi
callq 0x40bd6a
movq %r14, %rdi
movq %rbx, %rsi
callq 0x40bda2
movq %r14, %rdi
movq %rbx, %rsi
callq 0x40bdce
addq $0x28, %r14
cmpq %r15, %r14
jne 0x40c8f0
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/Thilotilo[P]DoaERando/Generals.cpp
// Function: DoaERando::Generals::SetAndScaleGeneralForZone(unsigned char, unsigned char, DoaERando::RandomNumberGenerator&)
void Generals::SetAndScaleGeneralForZone(BYTE generalId, BYTE zone, RNG& rng)
{
    int generalIndex = GetGeneralIndexById(generalId);
    myGenerals[generalIndex].zone = zone;
    myGenerals[generalIndex].ScaleWeaponForZone(rng);
    myGenerals[generalIndex].ScaleArmorForZone(rng);
    myGenerals[generalIndex].ScaleMaxTacticForZone(rng);
    myGenerals[generalIndex].ScaleSoldiersForZone(rng);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rcx, %rbx
movl %edx, %r15d
movq %rdi, %r14
callq 0x40c69c
cltq
movq (%r14), %rdi
shlq $0x3, %rax
leaq (%rax,%rax,4), %r12
movb %r15b, 0x8(%rdi,%r12)
addq %r12, %rdi
movq %rbx, %rsi
callq 0x40bd32
movq (%r14), %rdi
addq %r12, %rdi
movq %rbx, %rsi
callq 0x40bd6a
movq (%r14), %rdi
addq %r12, %rdi
movq %rbx, %rsi
callq 0x40bda2
addq (%r14), %r12
movq %r12, %rdi
movq %rbx, %rsi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x40bdce
// File: /workspace/github_cpp_makefile_star2_O3/Thilotilo[P]DoaERando/Generals.cpp
// Function: DoaERando::Generals::UpdateGenerals()
void Generals::UpdateGenerals()
{
    const int GENERAL_ADDRESSES_LSB_START = 0x32610;
    const int GENERAL_ADDRESSES_MSB_START = 0x32710;
    for (auto& general : myGenerals)
    {
        general.UpdateGeneral(myRom);
        general.DumpGeneral();

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq (%rdi), %r14
movq 0x8(%rdi), %rax
movq %rax, -0x30(%rbp)
cmpq %rax, %r14
je 0x40cb27
movq %rdi, %rbx
movl $0xff, %r12d
movq 0x48(%rbx), %rsi
movq %r14, %rdi
callq 0x40c01a
movq %r14, %rdi
callq 0x40c24c
cmpb $0x0, 0x5(%r14)
movl $0xfffd7ff0, %eax       # imm = 0xFFFD7FF0
je 0x40cb19
xorl %r13d, %r13d
movl (%r14), %r15d
addl %eax, %r15d
movl %r15d, %edx
shrl $0x8, %edx
movq 0x48(%rbx), %rdi
movzbl 0x4(%r14), %eax
leal (%rax,%r13), %esi
addl $0x32710, %esi          # imm = 0x32710
andl %r12d, %edx
callq 0x404a24
movq 0x48(%rbx), %rdi
movzbl 0x4(%r14), %eax
leal (%rax,%r13), %esi
addl $0x32610, %esi          # imm = 0x32610
andl %r12d, %r15d
movl %r15d, %edx
callq 0x404a24
incl %r13d
movzbl 0x5(%r14), %eax
cmpl %eax, %r13d
movl $0xfffd7ff0, %eax       # imm = 0xFFFD7FF0
jb 0x40cac2
addq $0x28, %r14
cmpq -0x30(%rbp), %r14
jne 0x40ca9f
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/Thilotilo[P]DoaERando/Generals.cpp
// Function: DoaERando::Generals::SetStartingGenerals(std::vector<unsigned char, std::allocator<unsigned char>>&)
void Generals::SetStartingGenerals(vector<BYTE>& startingGeneralIds)
{
    for (auto& generalId : startingGeneralIds)
    {
        int index = GetGeneralIndexById(generalId);
        myStartingGeneralAddresses.push_back(myGenerals[index].address);
        myGenerals[index].encounterable = false;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq (%rsi), %r15
movq 0x8(%rsi), %r12
cmpq %r12, %r15
je 0x40cf13
movq %rdi, %rbx
leaq 0x30(%rdi), %rax
movq %rax, -0x30(%rbp)
movq (%rdi), %r13
movzbl (%r15), %esi
movq %rbx, %rdi
callq 0x40c69c
cltq
leaq (%rax,%rax,4), %r14
leaq (,%r14,8), %rdx
addq %r13, %rdx
movq 0x38(%rbx), %rsi
cmpq 0x40(%rbx), %rsi
je 0x40cef9
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x38(%rbx)
jmp 0x40cf05
movq -0x30(%rbp), %rdi
callq 0x40d360
movq (%rbx), %r13
movb $0x0, 0x23(%r13,%r14,8)
incq %r15
cmpq %r12, %r15
jne 0x40cec4
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/Thilotilo[P]DoaERando/Generals.cpp
// Function: DoaERando::Generals::GetGeneralIdsFromZone(unsigned char)
std::vector<BYTE> Generals::GetGeneralIdsFromZone(BYTE zone)
{
    std::vector<BYTE> generalIdsForZone;
    for (auto& general : myGenerals)
    {
        if (isStartingGeneralAddress(general.address) || isRestrictedGeneralAddress(general.address))
        {
            continue;
        }
        if (general.zone == zone)
        {
            // The game likes to use the last id if there are multiples
            generalIdsForZone.push_back(general.id + (general.count - 1));
        }
    }
    return generalIdsForZone;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movq (%rsi), %r13
movq 0x8(%rsi), %r12
cmpq %r12, %r13
je 0x40cfbf
movl %edx, %r14d
movq %rsi, %r15
movl (%r13), %eax
movq 0x30(%r15), %rcx
movq 0x38(%r15), %rdx
cmpq %rdx, %rcx
je 0x40cf6e
cmpl %eax, (%rcx)
je 0x40cfb6
addq $0x4, %rcx
jmp 0x40cf5f
movq 0x18(%r15), %rcx
movq 0x20(%r15), %rdx
cmpq %rdx, %rcx
je 0x40cf85
cmpl %eax, (%rcx)
je 0x40cfb6
addq $0x4, %rcx
jmp 0x40cf76
cmpb %r14b, 0x8(%r13)
jne 0x40cfb6
movb 0x4(%r13), %al
addb 0x5(%r13), %al
decb %al
movb %al, -0x29(%rbp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x40cfaa
movb %al, (%rsi)
incq 0x8(%rbx)
jmp 0x40cfb6
movq %rbx, %rdi
leaq -0x29(%rbp), %rdx
callq 0x40ad1c
addq $0x28, %r13
cmpq %r12, %r13
jne 0x40cf53
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x40cfe1
callq 0x410b90
movq %r14, %rdi
callq 0x4bb660
nop
// File: /workspace/github_cpp_makefile_star2_O3/Thilotilo[P]DoaERando/Generals.cpp
// Function: DoaERando::Generals::GetAllGeneralIds()
std::vector<BYTE> Generals::GetAllGeneralIds()
{
    std::vector<BYTE> generalIds;
    for (auto& general : myGenerals)
    {
        // The game likes to use the last id if there are multiples
        generalIds.push_back(general.id + (general.count - 1));
    }
    return generalIds;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movq (%rsi), %r15
movq 0x8(%rsi), %r12
cmpq %r12, %r15
je 0x40d04d
leaq -0x21(%rbp), %r14
movb 0x4(%r15), %al
addb 0x5(%r15), %al
decb %al
movb %al, -0x21(%rbp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x40d039
movb %al, (%rsi)
incq 0x8(%rbx)
jmp 0x40d044
movq %rbx, %rdi
movq %r14, %rdx
callq 0x40ad1c
addq $0x28, %r15
cmpq %r12, %r15
jne 0x40d01a
movq %rbx, %rax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x40d06d
callq 0x410b90
movq %r14, %rdi
callq 0x4bb660
nop
// File: /workspace/github_cpp_makefile_star2_O3/Thilotilo[P]DoaERando/BattleRandomizer.cpp
// Function: DoaERando::Battle::Battle(int)
Battle::Battle(int id)
{
    vector<int> zoneForBattle = {1, 1, 1, 1, 1, 1,
                                 2, 2, 2, 2, 2, 2, 2, 2,
                                 3, 3, 3, 3, 3, 3,
                                 4, 4, 4, 4, 4, 4, 4,
                                 5, 5, 5, 5, 5,
                                 6, 6, 6, 6, 6, 6, 6, 6,
                                 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
                                 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
                                 4, 4,
                                 5, 5,
                                 7, 7, 8, 6};

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x160, %rsp            # imm = 0x160
movl %esi, %r14d
movq %rdi, %rbx
leaq 0x17f3ed(%rip), %rsi    # 0x58c840
leaq -0x180(%rbp), %r15
movl $0x140, %edx            # imm = 0x140
movq %r15, %rdi
callq 0x401070
leaq -0x40(%rbp), %r12
leaq -0x21(%rbp), %rcx
movl $0x50, %edx
movq %r12, %rdi
movq %r15, %rsi
callq 0x40ff6a
movslq %r14d, %rax
movq (%r12), %rdi
movl (%rdi,%rax,4), %ecx
movl %ecx, (%rbx)
movl %eax, 0x4(%rbx)
xorl %eax, %eax
movb %al, 0xc(%rbx)
movl $0x0, 0x8(%rbx)
movl $0x5, 0x10(%rbx)
movb %al, 0x14(%rbx)
callq 0x410b90
addq $0x160, %rsp            # imm = 0x160
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/Thilotilo[P]DoaERando/BattleRandomizer.cpp
// Function: DoaERando::Battle::OrganizeBattle()
void Battle::OrganizeBattle()
{
    // Reorder battles so that Generals come first, then rebel forces, then empty slots
    std::vector<BYTE> generalList;
    int numRebels = 0;

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

    int index = 0;

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

    battleModified = true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
xorps %xmm0, %xmm0
leaq -0x40(%rbp), %r14
movaps %xmm0, (%r14)
movq $0x0, 0x10(%r14)
movq %rdi, -0x48(%rbp)
leaq 0x8(%rdi), %r13
xorl %ebx, %ebx
xorl %edx, %edx
movl %edx, %r12d
leaq (%rbx,%r13), %r15
movb (%r13,%rbx), %al
cmpb $0x5, %al
jb 0x40d517
movq -0x38(%rbp), %rsi
cmpq -0x30(%rbp), %rsi
je 0x40d50c
movb %al, (%rsi)
incq -0x38(%rbp)
jmp 0x40d517
movq %r14, %rdi
movq %r15, %rdx
callq 0x40ae0e
movb (%r15), %cl
xorl %eax, %eax
cmpb $0x4, %cl
sete %al
leal (%r12,%rax), %edx
incq %rbx
cmpq $0x5, %rbx
jne 0x40d4ea
movq -0x40(%rbp), %r14
movq -0x38(%rbp), %rsi
xorl %r15d, %r15d
cmpq %rsi, %r14
je 0x40d557
leaq (%r14,%r15), %rdi
incq %rdi
movb -0x1(%rdi), %r8b
movb %r8b, (%r13,%r15)
incq %r15
cmpq %rsi, %rdi
jne 0x40d53f
testl %edx, %edx
movq -0x48(%rbp), %r13
je 0x40d595
xorl %ebx, %ebx
cmpb $0x4, %cl
sete %bl
movl %r15d, %ecx
leaq (%rcx,%r13), %rdi
addq $0x8, %rdi
leal (%r12,%rax), %edx
decl %edx
incq %rdx
movl $0x4, %esi
callq 0x401080
addl %r12d, %ebx
negl %ebx
xorl %eax, %eax
decl %eax
cmpl %eax, %ebx
jne 0x40d58c
subl %eax, %r15d
cmpl $0x4, %r15d
ja 0x40d5b5
movl %r15d, %eax
leaq (%rax,%r13), %rdi
addq $0x8, %rdi
movl $0x5, %edx
subl %r15d, %edx
xorl %esi, %esi
callq 0x401080
movb $0x1, 0x14(%r13)
testq %r14, %r14
je 0x40d5c7
movq %r14, %rdi
callq 0x410b90
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x40d5e7
callq 0x410b90
movq %rbx, %rdi
callq 0x4bb660
nop
// File: /workspace/github_cpp_makefile_star2_O3/Thilotilo[P]DoaERando/BattleRandomizer.cpp
// Function: DoaERando::BattleRandomizer::PlaceGeneralInBattle(unsigned char, int)
bool BattleRandomizer::PlaceGeneralInBattle(BYTE id, int battleId)
{
    if (myBattles[battleId].slotsRemaining == 0)
    {
        return false;
    }
    for (int i = 0; i < 5; ++i)
    {
        if (myBattles[battleId].generals[i] == id)
        {
            return false;
        }
        if (myBattles[battleId].generals[i] == 0x00)
        {
            myBattles[battleId].generals[i] = id;
            myBattles[battleId].slotsRemaining--;
            return true;
        }
    }
    return false;
}

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq (%rdx), %r12
movq 0x8(%rdx), %rax
movq %rax, -0x30(%rbp)
cmpq %rax, %r12
je 0x40d7da
movq %rcx, %rbx
movq %rsi, %r14
movq %rdi, %r15
movslq (%r12), %rax
movq (%r15), %rcx
leaq (%rax,%rax,2), %rdx
movslq 0x10(%rcx,%rdx,8), %rdx
testq %rdx, %rdx
jle 0x40d7bf
movl $0x5, %r13d
subq %rdx, %r13
movq %rbx, %rdi
xorl %esi, %esi
movl $0x9, %edx
callq 0x41086c
cmpl $0x6, %eax
setge %cl
testq %r13, %r13
setne %dl
testb %cl, %dl
jne 0x40d782
movq %r13, -0x38(%rbp)
movl $0x14, %r13d
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4108c0
movl (%r12), %edx
movzbl %al, %esi
movq %r15, %rdi
callq 0x40d678
testb %al, %al
jne 0x40d778
leal -0x1(%r13), %ecx
cmpl $0x1, %r13d
movl %ecx, %r13d
ja 0x40d74d
testb %al, %al
movq -0x38(%rbp), %r13
je 0x40d787
jmp 0x40d7ab
cmpl $0x8, %eax
ja 0x40d7ab
movslq (%r12), %rax
leaq (%rax,%rax,2), %rax
shlq $0x3, %rax
addq (%r15), %rax
movb $0x4, 0x8(%r13,%rax)
movslq (%r12), %rax
movq (%r15), %rcx
leaq (%rax,%rax,2), %rax
decl 0x10(%rcx,%rax,8)
incq %r13
cmpl $0x5, %r13d
jne 0x40d724
movslq (%r12), %rax
movq (%r15), %rcx
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax,8), %rdi
callq 0x40d4ba
addq $0x4, %r12
cmpq -0x30(%rbp), %r12
jne 0x40d702
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/Thilotilo[P]DoaERando/BattleRandomizer.cpp
// Function: DoaERando::BattleRandomizer::FillBattleWithOnlyGenerals(std::vector<unsigned char, std::allocator<unsigned char>>, int, DoaERando::RandomNumberGenerator&)
void BattleRandomizer::FillBattleWithOnlyGenerals(vector<BYTE> generalIds, int battleId, RNG& rng)
{
    int startingIndex = 5 - myBattles[battleId].slotsRemaining;
    for (int i = startingIndex; i < 5; ++i)
    {
        bool success = false;
        while (!success)
        {
            BYTE generalToInsert = rng.GetRandomValueFromByteVector(generalIds);
            success = PlaceGeneralInBattle(generalToInsert, battleId);
        }
    }
    myBattles[battleId].OrganizeBattle();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %rbx
movl %edx, %r14d
movslq %edx, %rcx
movq (%rdi), %rax
leaq (%rcx,%rcx,2), %rdx
movl 0x10(%rax,%rdx,8), %ecx
testl %ecx, %ecx
jle 0x40d850
movq %rsi, %r12
movq %rdi, %r15
movq %rdx, -0x30(%rbp)
movl $0x5, %r13d
subl %ecx, %r13d
movq %rbx, %rdi
movq %r12, %rsi
callq 0x4108c0
movzbl %al, %esi
movq %r15, %rdi
movl %r14d, %edx
callq 0x40d678
testb %al, %al
je 0x40d823
incl %r13d
cmpl $0x5, %r13d
jne 0x40d823
movq (%r15), %rax
movq -0x30(%rbp), %rdx
leaq (%rax,%rdx,8), %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x40d4ba
nop