// File: /workspace/github_cpp_makefile_star2_O1/MichaelXanth[P]RPG_Game/Game/Game.cpp
// Function: Game::StartBattle()
void Game::StartBattle(void)
{
    vector<Monster *> monsters;
    short extraMonsters = rand() % 3;
    unsigned int lvlOfEM = 0;
    unsigned int generalLvlOfMon = 0;
    bool  battleOver  = false;
    short faints      = 0;
    bool  heroesWon   = false;
    bool  monstersWon = false;

    int  arrow     = 0;
    char selection = ' ';

    /* If the heroes are below level 5 then the number of monsters that appear 
     * is equal to the number of heroes. Over level 5 the number of monsters 
     * can be increased by 2 extra monsters.
     */
    if (heroes[0]->GetLevel() > 4)
        extraMonsters = rand() % 3;
    else
        extraMonsters = 0;

    for (short i = 0; i < heroes.size(); i++) {
        monsters.push_back(Battle::FindMonster(heroes[i]->GetLevel()));
        lvlOfEM += heroes[i]->GetLevel();
    }

    generalLvlOfMon += lvlOfEM;
    lvlOfEM = lvlOfEM / heroes.size(); /* calculates the average of the 3 heroes */

    for (short i = 0; i < extraMonsters; i++) {
        monsters.push_back(Battle::FindMonster(floor(lvlOfEM))); //creates a monster
        generalLvlOfMon += floor(lvlOfEM);
    }

    generalLvlOfMon = generalLvlOfMon / (extraMonsters + heroes.size()); //the average of all monsters

    unsigned int level = 0;

    while(battleOver == false) {
        bool res = true;

        for (short int j = 0; j < heroes.size(); j++) {
            if (res == true /*&& selection != 'c'*/) {
                cout << "\033[2J\033[1;1H";

                if (monsters.size() > heroes.size())
                    cout << "\033[" << ((monsters.size() - 1) * 31) / 2 + 7 << "C";
                else
                    cout << "\033[" << ((heroes.size() - 1) * 31) / 2 + 7 << "C";

                if (j == 0)
                    level++;

                cout << "---> Round " << level << " <---" << endl << endl;

                DisplayAllStats(monsters);
            }

            if (heroes[j]->Fainted() == false)
            {

                if (res == false && selection == 'c')
                    cout << "\033[3A";

                cout << "Press 'c' to skip this Hero" << endl;
                cout << "Hero " << j + 1 << ": \033[38;5;220m" << heroes[j]->GetName() << "\033[0m" << endl;
                cout << "\033[J" << endl;

                do {

                    if (res == false && selection == '\n') {
                        cout << "\033[6A";
                        cout << "\033[J";
                        cout << "Choose a new action: " << endl;
                    }

                    // Displays and handles the arrow menu
                    do {
                        DisplayActions(arrow);

                        selection = getch();

                        if (selection == 'w' && arrow)
                            arrow--;
                        else if (selection == 's' && arrow < 4)
                            arrow++;

                        if (selection != '\n')
                            cout << "\033[5A";

                        if (selection == 'c' && j == heroes.size() - 1)
                            cout << "\033[5B";

                    }while(selection != 'c' && selection != '\n');

                    if (selection == 'c')
                        break;

                } while((res = ChooseAction(*heroes[j],arrow + 1,monsters)) == false);

                if (selection == 'c') {
                    if (j < heroes.size() - 1) /* If a hero was skipped we disable the screen refresh */
                        res = false;          /* only if we are not at the last hero of the current round */
                    else
                        res = true;           /* We set the 'res' var to TRUE for enabling the screen refresh for the next round */

                    continue;
                }

                if (res == true)
                    cout << "\033[8A\033[J";

                // When the vector of monsters is empty then heroes won
                if (monsters.empty() == true) {
                    heroesWon = true;
                    monstersWon = false;
                    break;
                }
            
            } else {
                cout << "\033[35mWarning:\033[0m Hero \033[38;5;220m" << heroes[j]->GetName() << "\033[0m has fainted." << endl;
                usleep(1500000);
                cout << "\033[1A\033[K";
            }
        }

        for (short int j = 0 ; j < monsters.size() ; j++)
        {
            short chance = rand() % heroes.size();

            if (heroes[chance]->Fainted() == false) {
                Battle::MonsterAttack(*monsters[j], *heroes[chance]);//monster attacks a random hero

                if (heroes[chance]->Fainted() == true)
                    faints++;

                // If all heroes faint then monsters win
                if (faints == heroes.size()) {
                    monstersWon = true;
                    heroesWon = false;
                    break;
                }
            }
            else
                j--;
        }

        if (heroesWon == true && monstersWon == false) {
            battleOver = true;
            
            // When the heroes win then they gain experience and money
            for (int k = 0; k < heroes.size(); k++) {
                
                // If a hero faints the they are restored to half HP
                if (heroes[k]->Fainted() == true)
                    heroes[k]->RestoreToHalfHP();

                if (heroes[k]->GetLevel() < 100)
                    heroes[k]->GainXP(ceil((double)generalLvlOfMon * (extraMonsters + heroes.size()) / 10));
                heroes[k]->ChangeMoney(2 * generalLvlOfMon * (extraMonsters + heroes.size()));
            }
            break;
        
        } else if (heroesWon == false && monstersWon == true) {
            battleOver = true;
            
            // If the heroes lose then they lose half their money and are restore to half HP
            for (int k = 0; k < heroes.size(); k++) {
                heroes[k]->ChangeMoney(-(heroes[k]->GetMoney() / 2));
                heroes[k]->RestoreToHalfHP();
            }
            break;
        }

        // Heroes and monsters alike get back some of their HP
        for (int c = 0; c < heroes.size(); c++) {
            if (heroes[c]->Fainted() == false)
                heroes[c]->EndTurnRefill();
        }

        for (int c = 0; c < monsters.size(); c++)
            monsters[c]->EndRound();
    }

    // If monsters win then they are deleted since they are not needed anymore
    for (int i = monsters.size(); !monsters.empty(); i--) {
        delete monsters[i - 1];
        monsters.erase(monsters.begin() + i - 1);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdi, %rbx
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
callq 0x3060
movq 0x10(%rbx), %rax
movq (%rax), %rax
movq (%rax), %rdi
callq 0x108f0
xorl %ebp, %ebp
movl $0x0, %edx
cmpl $0x5, %eax
jb 0xbf20
callq 0x3060
movslq %eax, %rdx
imulq $0x55555556, %rdx, %rax # imm = 0x55555556
movq %rax, %rcx
shrq $0x3f, %rcx
shrq $0x20, %rax
addl %ecx, %eax
leal (%rax,%rax,2), %eax
subl %eax, %edx
movq %rdx, 0x30(%rsp)
movq 0x10(%rbx), %rax
movq 0x8(%rax), %rcx
movq (%rax), %rdx
subq %rdx, %rcx
je 0xbf9b
xorl %r13d, %r13d
movw $0x1, %r12w
leaq 0x10(%rsp), %r14
leaq 0x38(%rsp), %r15
xorl %ebp, %ebp
movq (%rax), %rax
movq (%rax,%r13,8), %rdi
callq 0x108f0
movl %eax, %edi
callq 0xaefe
movq %rax, 0x38(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0xefc4
movq 0x10(%rbx), %rax
movq (%rax), %rax
movq (%rax,%r13,8), %rdi
callq 0x108f0
addl %eax, %ebp
movq 0x10(%rbx), %rax
movq 0x8(%rax), %rcx
subq (%rax), %rcx
movswq %r12w, %r13
sarq $0x3, %rcx
incl %r12d
cmpq %r13, %rcx
ja 0xbf49
jmp 0xbf9f
sarq $0x3, %rcx
movl %ebp, %eax
xorl %r15d, %r15d
xorl %edx, %edx
divq %rcx
movq %rax, %r14
movq 0x30(%rsp), %rax
testw %ax, %ax
jle 0xbfe1
leaq 0x38(%rsp), %r12
movl %eax, %r13d
movl %r14d, %edi
callq 0xaefe
movq %rax, 0x38(%rsp)
leaq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0xefc4
addl %r14d, %ebp
decw %r13w
jne 0xbfbe
movl %ebp, %eax
movswq 0x30(%rsp), %rdx
movq 0x10(%rbx), %rcx
movq 0x8(%rcx), %rsi
subq (%rcx), %rsi
sarq $0x3, %rsi
movq %rdx, 0x70(%rsp)
addq %rdx, %rsi
xorl %edx, %edx
divq %rsi
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x78(%rsp)
addq %rax, %rax
movq %rax, 0x80(%rsp)
movb $0x20, %bpl
movq $0x0, 0x60(%rsp)
movq $0x0, 0x68(%rsp)
xorl %edx, %edx
movl $0x0, 0x2c(%rsp)
movl $0x0, 0x5c(%rsp)
testb $0x1, 0x60(%rsp)
jne 0xc905
movq 0x10(%rbx), %rax
movq 0x8(%rax), %rcx
cmpq (%rax), %rcx
je 0xc637
movl %edx, 0xc(%rsp)
movb $0x1, %r14b
xorl %r13d, %r13d
movq $0x0, 0x30(%rsp)
testb $0x1, %r14b
je 0xc1f6
movl $0xa, %edx
movq 0x22f3e(%rip), %rdi     # 0x2efc8
leaq 0x1833f(%rip), %rsi     # 0x243d0
callq 0x31e0
movq 0x18(%rsp), %rax
subq 0x10(%rsp), %rax
movq 0x10(%rbx), %rcx
movq 0x8(%rcx), %rdx
subq (%rcx), %rdx
cmpq %rdx, %rax
jbe 0xc0d4
movl $0x2, %edx
movq 0x22f0c(%rip), %rdi     # 0x2efc8
leaq 0x18318(%rip), %rsi     # 0x243db
callq 0x31e0
movq 0x18(%rsp), %rsi
leaq 0x10(%rsp), %rax
jmp 0xc0f4
movl $0x2, %edx
movq 0x22ee8(%rip), %rdi     # 0x2efc8
leaq 0x182f4(%rip), %rsi     # 0x243db
callq 0x31e0
movq 0x10(%rbx), %rax
movq 0x8(%rax), %rsi
subq (%rax), %rsi
movq %rsi, %rax
sarq $0x3, %rax
shlq $0x2, %rsi
subq %rax, %rsi
addq $-0x1f, %rsi
shrq %rsi
addq $0x7, %rsi
movq 0x22eb1(%rip), %rdi     # 0x2efc8
callq 0x30f0
movl $0x1, %edx
movq %rax, %rdi
leaq 0x1b67b(%rip), %rsi     # 0x277a6
callq 0x31e0
cmpw $0x1, 0x30(%rsp)
adcl $0x0, 0x5c(%rsp)
movl $0xb, %edx
movq 0x22e81(%rip), %rdi     # 0x2efc8
leaq 0x18290(%rip), %rsi     # 0x243de
callq 0x31e0
movl 0x5c(%rsp), %esi
movq 0x22e6a(%rip), %rdi     # 0x2efc8
callq 0x30f0
movq %rax, %r12
movl $0x5, %edx
movq %rax, %rdi
leaq 0x18275(%rip), %rsi     # 0x243ea
callq 0x31e0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3190
movsbl %al, %esi
movq %r12, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3100
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3190
movsbl %al, %esi
movq %r12, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3100
movq %rbx, %rdi
leaq 0x10(%rsp), %rsi
callq 0xcc2e
movl 0x18(%rsp), %eax
subl 0x10(%rsp), %eax
shrl $0x3, %eax
movw %ax, 0x38(%rsp)
movq %rbx, %rdi
leaq 0x38(%rsp), %rsi
callq 0xdc4c
movq 0x10(%rbx), %rax
movq (%rax), %rax
movq (%rax,%r13,8), %rdi
callq 0x108b8
testb %al, %al
je 0xc2d3
movl $0x22, %edx
movq 0x22dae(%rip), %rdi     # 0x2efc8
leaq 0x1821e(%rip), %rsi     # 0x2443f
callq 0x31e0
movq 0x10(%rbx), %rax
movq (%rax), %rax
movq (%rax,%r13,8), %rsi
leaq 0x38(%rsp), %rdi
callq 0x108c2
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq 0x22d7c(%rip), %rdi     # 0x2efc8
callq 0x31e0
movq %rax, %r12
movl $0x11, %edx
movq %rax, %rdi
leaq 0x181ff(%rip), %rsi     # 0x24462
callq 0x31e0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3190
movsbl %al, %esi
movq %r12, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3100
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0xc2ac
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x31b0
movl $0x16e360, %edi         # imm = 0x16E360
callq 0x3260
movl $0x7, %edx
movq 0x22d06(%rip), %rdi     # 0x2efc8
leaq 0x1bc95(%rip), %rsi     # 0x27f5e
callq 0x31e0
jmp 0xc5ff
movl %r14d, %eax
andb $0x1, %al
movl %ebp, %ecx
xorb $0x63, %cl
orb %al, %cl
jne 0xc2f9
movl $0x4, %edx
movq 0x22cdb(%rip), %rdi     # 0x2efc8
leaq 0x1809d(%rip), %rsi     # 0x24391
callq 0x31e0
movl $0x1b, %edx
movq 0x22cc3(%rip), %rdi     # 0x2efc8
leaq 0x180e4(%rip), %rsi     # 0x243f0
callq 0x31e0
movq 0x22cb0(%rip), %rcx     # 0x2efc8
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x3190
movsbl %al, %esi
movq 0x22c92(%rip), %rdi     # 0x2efc8
callq 0x3040
movq %rax, %rdi
callq 0x3100
movl $0x5, %edx
movq 0x22c79(%rip), %rdi     # 0x2efc8
leaq 0x180b6(%rip), %rsi     # 0x2440c
callq 0x31e0
movswl 0x30(%rsp), %esi
incl %esi
movq 0x22c5f(%rip), %rdi     # 0x2efc8
callq 0x32e0
movq %rax, %r12
movl $0xd, %edx
movq %rax, %rdi
leaq 0x17ffb(%rip), %rsi     # 0x2437b
callq 0x31e0
movq 0x10(%rbx), %rax
movq (%rax), %rax
movq (%rax,%r13,8), %rsi
leaq 0x38(%rsp), %rdi
callq 0x108c2
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq %r12, %rdi
callq 0x31e0
movq %rax, %r12
movl $0x4, %edx
movq %rax, %rdi
leaq 0x1aa26(%rip), %rsi     # 0x26de4
callq 0x31e0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3190
movsbl %al, %esi
movq %r12, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3100
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0xc407
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x31b0
movl $0x3, %edx
movq 0x22bb5(%rip), %rdi     # 0x2efc8
leaq 0x1a389(%rip), %rsi     # 0x267a3
callq 0x31e0
movq 0x22ba2(%rip), %rcx     # 0x2efc8
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x3190
movsbl %al, %esi
movq 0x22b84(%rip), %rdi     # 0x2efc8
callq 0x3040
movq %rax, %rdi
callq 0x3100
movl %r14d, %eax
andb $0x1, %al
xorb $0xa, %bpl
orb %al, %bpl
jne 0xc4d9
movl $0x4, %edx
movq 0x22b5d(%rip), %rdi     # 0x2efc8
leaq 0x17fa0(%rip), %rsi     # 0x24412
callq 0x31e0
movl $0x3, %edx
movq 0x22b45(%rip), %rdi     # 0x2efc8
leaq 0x1a319(%rip), %rsi     # 0x267a3
callq 0x31e0
movl $0x15, %edx
movq 0x22b2d(%rip), %rdi     # 0x2efc8
leaq 0x17f75(%rip), %rsi     # 0x24417
callq 0x31e0
movq 0x22b1a(%rip), %rcx     # 0x2efc8
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x3190
movsbl %al, %esi
movq 0x22afc(%rip), %rdi     # 0x2efc8
callq 0x3040
movq %rax, %rdi
callq 0x3100
movl %r15d, 0x38(%rsp)
leaq 0x38(%rsp), %rsi
xorl %edx, %edx
callq 0xbc0c
callq 0x10728
movl %eax, %ebp
cmpb $0x73, %al
sete %al
cmpl $0x4, %r15d
setl %cl
andb %al, %cl
movzbl %cl, %eax
movl %r15d, %ecx
negl %ecx
movl $0x0, %r12d
sbbl %r12d, %r12d
orl %eax, %r12d
cmpb $0x77, %bpl
cmovnel %eax, %r12d
cmpb $0xa, %bpl
je 0xc539
movl $0x4, %edx
movq 0x22a9b(%rip), %rdi     # 0x2efc8
leaq 0x17ef9(%rip), %rsi     # 0x2442d
callq 0x31e0
cmpb $0x63, %bpl
jne 0xc56e
movq 0x10(%rbx), %rax
movq 0x8(%rax), %rcx
subq (%rax), %rcx
sarq $0x3, %rcx
decq %rcx
cmpq %r13, %rcx
jne 0xc56e
movl $0x4, %edx
movq 0x22a66(%rip), %rdi     # 0x2efc8
leaq 0x17ec9(%rip), %rsi     # 0x24432
callq 0x31e0
addl %r12d, %r15d
cmpb $0x63, %bpl
je 0xc584
movzbl %bpl, %eax
cmpl $0xa, %eax
jne 0xc4d9
cmpb $0x63, %bpl
je 0xc5b4
movq 0x10(%rbx), %rax
movq (%rax), %rax
movq (%rax,%r13,8), %rsi
leal 0x1(%r15), %eax
movswl %ax, %edx
movq %rbx, %rdi
leaq 0x10(%rsp), %rcx
callq 0xca36
movl %eax, %r14d
testb %al, %al
je 0xc451
cmpb $0x63, %bpl
jne 0xc5d5
movq 0x10(%rbx), %rax
movq 0x8(%rax), %rcx
subq (%rax), %rcx
sarq $0x3, %rcx
decq %rcx
cmpq %r13, %rcx
setbe %r14b
jmp 0xc5ff
testb $0x1, %r14b
je 0xc5f3
movl $0x7, %edx
movq 0x229e1(%rip), %rdi     # 0x2efc8
leaq 0x17e49(%rip), %rsi     # 0x24437
callq 0x31e0
movq 0x10(%rsp), %rax
cmpq 0x18(%rsp), %rax
je 0xc62d
movq 0x30(%rsp), %rax
incl %eax
movq %rax, 0x30(%rsp)
movswq %ax, %r13
movq 0x10(%rbx), %rax
movq 0x8(%rax), %rcx
subq (%rax), %rcx
sarq $0x3, %rcx
cmpq %r13, %rcx
ja 0xc074
movl 0xc(%rsp), %edx
jmp 0xc637
movb $0x1, %dl
movl $0x0, 0x2c(%rsp)
movl %edx, 0xc(%rsp)
movq 0x18(%rsp), %rax
cmpq 0x10(%rsp), %rax
je 0xc70b
xorl %r12d, %r12d
xorl %r14d, %r14d
callq 0x3060
cltq
movq 0x10(%rbx), %rcx
movq (%rcx), %rsi
movq 0x8(%rcx), %rcx
subq %rsi, %rcx
sarq $0x3, %rcx
xorl %edx, %edx
divq %rcx
movswq %dx, %r13
movq (%rsi,%r13,8), %rdi
callq 0x108b8
testb %al, %al
je 0xc685
decl %r14d
jmp 0xc6e7
movq 0x10(%rsp), %rax
movq (%rax,%r12,8), %rdi
movq 0x10(%rbx), %rax
movq (%rax), %rax
movq (%rax,%r13,8), %rsi
callq 0xb58c
movq 0x10(%rbx), %rax
movq (%rax), %rax
movq (%rax,%r13,8), %rdi
callq 0x108b8
movzbl %al, %eax
movq 0x68(%rsp), %rcx
addl %eax, %ecx
movq %rcx, 0x68(%rsp)
movswq %cx, %rax
movq 0x10(%rbx), %rcx
movq 0x8(%rcx), %rdx
subq (%rcx), %rdx
sarq $0x3, %rdx
cmpq %rax, %rdx
jne 0xc6e7
movb $0x1, %al
movl %eax, 0x2c(%rsp)
movl $0x0, 0xc(%rsp)
xorl %eax, %eax
jmp 0xc6e9
movb $0x1, %al
testb %al, %al
je 0xc70b
incl %r14d
movswq %r14w, %r12
movq 0x18(%rsp), %rax
subq 0x10(%rsp), %rax
sarq $0x3, %rax
cmpq %r12, %rax
ja 0xc651
testb $0x1, 0x2c(%rsp)
sete %al
movl 0xc(%rsp), %ecx
andb %cl, %al
cmpb $0x1, %al
jne 0xc811
movq 0x10(%rbx), %rcx
movq (%rcx), %rax
movb $0x1, %dl
movq %rdx, 0x60(%rsp)
cmpq %rax, 0x8(%rcx)
je 0xc878
xorl %r12d, %r12d
movq (%rax,%r12,8), %rdi
callq 0x108b8
testb %al, %al
je 0xc759
movq 0x10(%rbx), %rax
movq (%rax), %rax
movq (%rax,%r12,8), %rdi
callq 0x1113a
movq 0x10(%rbx), %rax
movq (%rax), %rax
movq (%rax,%r12,8), %rdi
callq 0x108f0
cmpl $0x63, %eax
ja 0xc7ca
movq 0x10(%rbx), %rax
movq (%rax), %rcx
movq 0x8(%rax), %rax
movq (%rcx,%r12,8), %r14
subq %rcx, %rax
sarq $0x3, %rax
addq 0x70(%rsp), %rax
movq %rax, %xmm1
punpckldq 0x17b3a(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x17b42(%rip), %xmm1    # 0x242e0
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x78(%rsp), %xmm0
divsd 0x17b38(%rip), %xmm0    # 0x242f0
callq 0x3050
cvttsd2si %xmm0, %rsi
movq %r14, %rdi
callq 0x11148
movq 0x10(%rbx), %rax
movq (%rax), %rcx
movq 0x8(%rax), %rsi
movq (%rcx,%r12,8), %rdi
subq %rcx, %rsi
shrq $0x3, %rsi
addl 0x70(%rsp), %esi
imull 0x80(%rsp), %esi
callq 0x11164
incq %r12
movq 0x10(%rbx), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r12, %rcx
ja 0xc73c
jmp 0xc878
testb $0x1, %cl
jne 0xc87d
testb $0x1, 0x2c(%rsp)
je 0xc87d
movq 0x10(%rbx), %rcx
movq (%rcx), %rax
movb $0x1, %dl
movq %rdx, 0x60(%rsp)
cmpq %rax, 0x8(%rcx)
je 0xc878
xorl %r12d, %r12d
movq (%rax,%r12,8), %r14
movq %r14, %rdi
callq 0x10afe
shrl %eax
negl %eax
movq %r14, %rdi
movl %eax, %esi
callq 0x11164
movq 0x10(%rbx), %rax
movq (%rax), %rax
movq (%rax,%r12,8), %rdi
callq 0x1113a
incq %r12
movq 0x10(%rbx), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r12, %rcx
ja 0xc834
xorl %r14d, %r14d
jmp 0xc8f8
movq 0x10(%rbx), %rcx
movq (%rcx), %rax
cmpq %rax, 0x8(%rcx)
je 0xc8c4
xorl %r14d, %r14d
movq (%rax,%r14,8), %rdi
callq 0x108b8
testb %al, %al
jne 0xc8aa
movq 0x10(%rbx), %rax
movq (%rax), %rax
movq (%rax,%r14,8), %rdi
callq 0x111da
incq %r14
movq 0x10(%rbx), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r14, %rcx
ja 0xc88d
movq 0x10(%rsp), %rax
movb $0x1, %r14b
cmpq %rax, 0x18(%rsp)
je 0xc8f8
xorl %r12d, %r12d
movq (%rax,%r12,8), %rdi
callq 0x18f68
incq %r12
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r12, %rcx
ja 0xc8d6
testb %r14b, %r14b
movl 0xc(%rsp), %edx
jne 0xc045
movq 0x10(%rsp), %rdi
cmpq 0x18(%rsp), %rdi
je 0xc980
movq 0x18(%rsp), %rax
subq %rdi, %rax
shrq $0x3, %rax
movslq %eax, %rbx
shlq $0x3, %rbx
movq %rbx, %r14
negq %r14
movq -0x8(%rdi,%rbx), %rdi
testq %rdi, %rdi
je 0xc93a
movq (%rdi), %rax
callq *0x18(%rax)
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rdx
leaq (%rax,%rbx), %rsi
cmpq %rdx, %rsi
je 0xc960
leaq (%rax,%rbx), %rdi
addq $-0x8, %rdi
subq %rax, %rdx
addq %r14, %rdx
callq 0x32b0
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rax
addq $-0x8, %rax
movq %rax, 0x18(%rsp)
addq $-0x8, %rbx
addq $0x8, %r14
cmpq %rax, %rdi
jne 0xc92a
testq %rdi, %rdi
je 0xc992
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x31b0
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xc9e3
jmp 0xc9e3
jmp 0xc9e3
jmp 0xc9e3
jmp 0xc9e3
jmp 0xc9e3
jmp 0xc9e3
jmp 0xc9e3
jmp 0xc9e3
jmp 0xc9e3
jmp 0xc9e3
jmp 0xc9bc
movq %rax, %rbx
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0xc9e6
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x31b0
jmp 0xc9e6
jmp 0xc9e3
jmp 0xc9e3
jmp 0xc9e3
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0xc9fd
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x31b0
movq %rbx, %rdi
callq 0x32f0
nop