// File: 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
movq %rsp, %rbp
subq $0x2e0, %rsp            # imm = 0x2E0
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x108(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x1b730
callq 0x40a0
movl %eax, %ecx
movq -0x108(%rbp), %rax
movslq %ecx, %rdx
imulq $0x55555556, %rdx, %rsi # imm = 0x55555556
movq %rsi, %rdx
shrq $0x3f, %rdx
shrq $0x20, %rsi
addl %edx, %esi
movl %esi, %edx
leal (%rdx,%rdx,2), %edx
subl %edx, %ecx
movw %cx, -0x22(%rbp)
movl $0x0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movb $0x0, -0x2d(%rbp)
movw $0x0, -0x30(%rbp)
movb $0x0, -0x31(%rbp)
movb $0x0, -0x32(%rbp)
movl $0x0, -0x38(%rbp)
movb $0x20, -0x39(%rbp)
movq 0x10(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x5030
movq (%rax), %rdi
callq 0x1ea90
movl %eax, -0xfc(%rbp)
jmp 0x1857b
movl -0xfc(%rbp), %eax
cmpl $0x4, %eax
jbe 0x185ad
callq 0x40a0
movl $0x3, %ecx
cltd
idivl %ecx
movw %dx, %ax
movw %ax, -0x22(%rbp)
jmp 0x185b3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x195a2
movw $0x0, -0x22(%rbp)
movw $0x0, -0x4e(%rbp)
movq -0x108(%rbp), %rax
movswq -0x4e(%rbp), %rcx
movq %rcx, -0x110(%rbp)
movq 0x10(%rax), %rdi
callq 0x5ad0
movq %rax, %rcx
movq -0x110(%rbp), %rax
cmpq %rcx, %rax
jae 0x1867d
movq -0x108(%rbp), %rax
movq 0x10(%rax), %rdi
movswq -0x4e(%rbp), %rsi
callq 0x5030
movq (%rax), %rdi
callq 0x1ea90
movl %eax, -0x114(%rbp)
jmp 0x1860d
movl -0x114(%rbp), %edi
callq 0x17030
movq %rax, -0x120(%rbp)
jmp 0x18621
movq -0x120(%rbp), %rax
movq %rax, -0x58(%rbp)
leaq -0x20(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x1b750
jmp 0x1863b
movq -0x108(%rbp), %rax
movq 0x10(%rax), %rdi
movswq -0x4e(%rbp), %rsi
callq 0x5030
movq (%rax), %rdi
callq 0x1ea90
movl %eax, -0x124(%rbp)
jmp 0x18660
movl -0x124(%rbp), %eax
addl -0x28(%rbp), %eax
movl %eax, -0x28(%rbp)
movw -0x4e(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x4e(%rbp)
jmp 0x185b9
movq -0x108(%rbp), %rax
movl -0x28(%rbp), %ecx
addl -0x2c(%rbp), %ecx
movl %ecx, -0x2c(%rbp)
movl -0x28(%rbp), %ecx
movq %rcx, -0x130(%rbp)
movq 0x10(%rax), %rdi
callq 0x5ad0
movq %rax, %rcx
movq -0x130(%rbp), %rax
xorl %edx, %edx
divq %rcx
movl %eax, -0x28(%rbp)
movw $0x0, -0x5a(%rbp)
movswl -0x5a(%rbp), %eax
movswl -0x22(%rbp), %ecx
cmpl %ecx, %eax
jge 0x18750
movl -0x28(%rbp), %edi
callq 0x1b780
movsd %xmm0, -0x138(%rbp)
jmp 0x186da
movsd -0x138(%rbp), %xmm0
cvttsd2si %xmm0, %rax
movl %eax, %edi
callq 0x17030
movq %rax, -0x140(%rbp)
jmp 0x186f7
movq -0x140(%rbp), %rax
movq %rax, -0x68(%rbp)
leaq -0x20(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x1b750
jmp 0x18711
movl -0x28(%rbp), %edi
callq 0x1b780
movsd %xmm0, -0x148(%rbp)
jmp 0x18723
movsd -0x148(%rbp), %xmm1
movl -0x2c(%rbp), %eax
cvtsi2sd %rax, %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movl %eax, -0x2c(%rbp)
movw -0x5a(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x5a(%rbp)
jmp 0x186b8
movq -0x108(%rbp), %rax
movl -0x2c(%rbp), %ecx
movq %rcx, -0x150(%rbp)
movswq -0x22(%rbp), %rcx
movq %rcx, -0x158(%rbp)
movq 0x10(%rax), %rdi
callq 0x5ad0
movq -0x158(%rbp), %rcx
movq %rax, %rdx
movq -0x150(%rbp), %rax
addq %rdx, %rcx
xorl %edx, %edx
divq %rcx
movl %eax, -0x2c(%rbp)
movl $0x0, -0x6c(%rbp)
movb -0x2d(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x194a1
movb $0x1, -0x6d(%rbp)
movw $0x0, -0x70(%rbp)
movq -0x108(%rbp), %rax
movswq -0x70(%rbp), %rcx
movq %rcx, -0x160(%rbp)
movq 0x10(%rax), %rdi
callq 0x5ad0
movq %rax, %rcx
movq -0x160(%rbp), %rax
cmpq %rcx, %rax
jae 0x18ed0
movb -0x6d(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x189b5
movq 0x357cd(%rip), %rdi     # 0x4dfc8
leaq 0x24bce(%rip), %rsi     # 0x3d3d0
callq 0x4260
jmp 0x18809
leaq -0x20(%rbp), %rdi
callq 0x1b7a0
movq %rax, %rcx
movq -0x108(%rbp), %rax
movq %rcx, -0x168(%rbp)
movq 0x10(%rax), %rdi
callq 0x5ad0
movq %rax, %rcx
movq -0x168(%rbp), %rax
cmpq %rcx, %rax
jbe 0x188a1
movq 0x35786(%rip), %rdi     # 0x4dfc8
leaq 0x24b92(%rip), %rsi     # 0x3d3db
callq 0x4260
movq %rax, -0x170(%rbp)
jmp 0x18857
leaq -0x20(%rbp), %rdi
callq 0x1b7a0
movq -0x170(%rbp), %rdi
movq %rax, %rsi
shlq $0x5, %rsi
subq %rax, %rsi
addq $-0x1f, %rsi
shrq %rsi
addq $0x7, %rsi
callq 0x4080
movq %rax, -0x178(%rbp)
jmp 0x1888a
movq -0x178(%rbp), %rdi
leaq 0x27f7e(%rip), %rsi     # 0x40816
callq 0x4260
jmp 0x1889f
jmp 0x1890e
movq 0x35720(%rip), %rdi     # 0x4dfc8
leaq 0x24b2c(%rip), %rsi     # 0x3d3db
callq 0x4260
movq %rax, -0x180(%rbp)
jmp 0x188bd
movq -0x108(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x5ad0
movq -0x180(%rbp), %rdi
movq %rax, %rsi
shlq $0x5, %rsi
subq %rax, %rsi
addq $-0x1f, %rsi
shrq %rsi
addq $0x7, %rsi
callq 0x4080
movq %rax, -0x188(%rbp)
jmp 0x188f7
movq -0x188(%rbp), %rdi
leaq 0x27f11(%rip), %rsi     # 0x40816
callq 0x4260
jmp 0x1890c
jmp 0x1890e
movswl -0x70(%rbp), %eax
cmpl $0x0, %eax
jne 0x18920
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
movq 0x356a1(%rip), %rdi     # 0x4dfc8
leaq 0x24ab0(%rip), %rsi     # 0x3d3de
callq 0x4260
movq %rax, -0x190(%rbp)
jmp 0x1893c
movq -0x190(%rbp), %rdi
movl -0x6c(%rbp), %esi
callq 0x4370
movq %rax, -0x198(%rbp)
jmp 0x18954
movq -0x198(%rbp), %rdi
leaq 0x24a88(%rip), %rsi     # 0x3d3ea
callq 0x4260
movq %rax, -0x1a0(%rbp)
jmp 0x18970
movq -0x1a0(%rbp), %rdi
movq 0x3563a(%rip), %rsi     # 0x4dfb8
callq 0x4290
movq %rax, -0x1a8(%rbp)
jmp 0x1898c
movq -0x1a8(%rbp), %rdi
movq 0x3561e(%rip), %rsi     # 0x4dfb8
callq 0x4290
jmp 0x189a1
movq -0x108(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x195c0
jmp 0x189b3
jmp 0x189b5
movq -0x108(%rbp), %rax
movq 0x10(%rax), %rdi
movswq -0x70(%rbp), %rsi
callq 0x5030
movq (%rax), %rdi
callq 0x1ea40
movb %al, -0x1a9(%rbp)
jmp 0x189da
movb -0x1a9(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x18de2
movb -0x6d(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x18a1b
movsbl -0x39(%rbp), %eax
cmpl $0x63, %eax
jne 0x18a1b
movq 0x355bd(%rip), %rdi     # 0x4dfc8
leaq 0x2497f(%rip), %rsi     # 0x3d391
callq 0x4260
jmp 0x18a19
jmp 0x18a1b
movq 0x355a6(%rip), %rdi     # 0x4dfc8
leaq 0x249c7(%rip), %rsi     # 0x3d3f0
callq 0x4260
movq %rax, -0x1b8(%rbp)
jmp 0x18a37
movq -0x1b8(%rbp), %rdi
movq 0x35573(%rip), %rsi     # 0x4dfb8
callq 0x4290
jmp 0x18a4c
movq 0x35575(%rip), %rdi     # 0x4dfc8
leaq 0x249b2(%rip), %rsi     # 0x3d40c
callq 0x4260
movq %rax, -0x1c0(%rbp)
jmp 0x18a68
movq -0x1c0(%rbp), %rdi
movswl -0x70(%rbp), %esi
incl %esi
callq 0x4430
movq %rax, -0x1c8(%rbp)
jmp 0x18a83
movq -0x1c8(%rbp), %rdi
leaq 0x248ea(%rip), %rsi     # 0x3d37b
callq 0x4260
movq %rax, -0x1d0(%rbp)
jmp 0x18a9f
movq -0x108(%rbp), %rax
movq 0x10(%rax), %rdi
movswq -0x70(%rbp), %rsi
callq 0x5030
movq (%rax), %rsi
leaq -0x90(%rbp), %rdi
callq 0x1ea60
jmp 0x18ac5
movq -0x1d0(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x4210
movq %rax, -0x1d8(%rbp)
jmp 0x18ae1
movq -0x1d8(%rbp), %rdi
leaq 0x27385(%rip), %rsi     # 0x3fe74
callq 0x4260
movq %rax, -0x1e0(%rbp)
jmp 0x18afd
movq -0x1e0(%rbp), %rdi
movq 0x354ad(%rip), %rsi     # 0x4dfb8
callq 0x4290
jmp 0x18b12
leaq -0x90(%rbp), %rdi
callq 0x4160
movq 0x354a3(%rip), %rdi     # 0x4dfc8
leaq 0x26d07(%rip), %rsi     # 0x3f833
callq 0x4260
movq %rax, -0x1e8(%rbp)
jmp 0x18b3a
movq -0x1e8(%rbp), %rdi
movq 0x35470(%rip), %rsi     # 0x4dfb8
callq 0x4290
jmp 0x18b4f
jmp 0x18b51
movb -0x6d(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x18be5
movsbl -0x39(%rbp), %eax
cmpl $0xa, %eax
jne 0x18be5
movq 0x35456(%rip), %rdi     # 0x4dfc8
leaq 0x24899(%rip), %rsi     # 0x3d412
callq 0x4260
jmp 0x18b80
movq 0x35441(%rip), %rdi     # 0x4dfc8
leaq 0x26ca5(%rip), %rsi     # 0x3f833
callq 0x4260
jmp 0x18b95
movq 0x3542c(%rip), %rdi     # 0x4dfc8
leaq 0x24874(%rip), %rsi     # 0x3d417
callq 0x4260
movq %rax, -0x1f0(%rbp)
jmp 0x18bb1
movq -0x1f0(%rbp), %rdi
movq 0x353f9(%rip), %rsi     # 0x4dfb8
callq 0x4290
jmp 0x18bc6
jmp 0x18be5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x4160
jmp 0x195a2
jmp 0x18be7
movq -0x108(%rbp), %rdi
movl -0x38(%rbp), %eax
movl %eax, -0x94(%rbp)
leaq -0x94(%rbp), %rsi
xorl %edx, %edx
callq 0x181b0
jmp 0x18c07
callq 0x1e820
movb %al, -0x1f1(%rbp)
jmp 0x18c14
movb -0x1f1(%rbp), %al
movb %al, -0x39(%rbp)
movsbl -0x39(%rbp), %eax
cmpl $0x77, %eax
jne 0x18c37
cmpl $0x0, -0x38(%rbp)
je 0x18c37
movl -0x38(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x18c51
movsbl -0x39(%rbp), %eax
cmpl $0x73, %eax
jne 0x18c4f
cmpl $0x4, -0x38(%rbp)
jge 0x18c4f
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x18c51
movsbl -0x39(%rbp), %eax
cmpl $0xa, %eax
je 0x18c71
movq 0x35367(%rip), %rdi     # 0x4dfc8
leaq 0x247c5(%rip), %rsi     # 0x3d42d
callq 0x4260
jmp 0x18c6f
jmp 0x18c71
movsbl -0x39(%rbp), %eax
cmpl $0x63, %eax
jne 0x18cc0
movq -0x108(%rbp), %rax
movswq -0x70(%rbp), %rcx
movq %rcx, -0x200(%rbp)
movq 0x10(%rax), %rdi
callq 0x5ad0
movq %rax, %rcx
movq -0x200(%rbp), %rax
subq $0x1, %rcx
cmpq %rcx, %rax
jne 0x18cc0
movq 0x35318(%rip), %rdi     # 0x4dfc8
leaq 0x2477b(%rip), %rsi     # 0x3d432
callq 0x4260
jmp 0x18cbe
jmp 0x18cc0
jmp 0x18cc2
movsbl -0x39(%rbp), %ecx
xorl %eax, %eax
cmpl $0x63, %ecx
movb %al, -0x201(%rbp)
je 0x18ce3
movsbl -0x39(%rbp), %eax
cmpl $0xa, %eax
setne %al
movb %al, -0x201(%rbp)
movb -0x201(%rbp), %al
testb $0x1, %al
jne 0x18be7
movsbl -0x39(%rbp), %eax
cmpl $0x63, %eax
jne 0x18cfc
jmp 0x18d52
jmp 0x18cfe
movq -0x108(%rbp), %rax
movq 0x10(%rax), %rdi
movswq -0x70(%rbp), %rsi
callq 0x5030
movq -0x108(%rbp), %rdi
movq (%rax), %rsi
movl -0x38(%rbp), %eax
incl %eax
movswl %ax, %edx
leaq -0x20(%rbp), %rcx
callq 0x19610
movb %al, -0x202(%rbp)
jmp 0x18d36
movb -0x202(%rbp), %al
movb %al, %cl
andb $0x1, %cl
movb %cl, -0x6d(%rbp)
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0x18b51
movsbl -0x39(%rbp), %eax
cmpl $0x63, %eax
jne 0x18d99
movq -0x108(%rbp), %rax
movswq -0x70(%rbp), %rcx
movq %rcx, -0x210(%rbp)
movq 0x10(%rax), %rdi
callq 0x5ad0
movq %rax, %rcx
movq -0x210(%rbp), %rax
subq $0x1, %rcx
cmpq %rcx, %rax
jae 0x18d90
movb $0x0, -0x6d(%rbp)
jmp 0x18d94
movb $0x1, -0x6d(%rbp)
jmp 0x18ebf
movb -0x6d(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x18dbd
movq 0x3521b(%rip), %rdi     # 0x4dfc8
leaq 0x24683(%rip), %rsi     # 0x3d437
callq 0x4260
jmp 0x18dbb
jmp 0x18dbd
leaq -0x20(%rbp), %rdi
callq 0x1b7c0
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x18ddd
movb $0x1, -0x31(%rbp)
movb $0x0, -0x32(%rbp)
jmp 0x18ed0
jmp 0x18ebd
movq 0x351df(%rip), %rdi     # 0x4dfc8
leaq 0x2464f(%rip), %rsi     # 0x3d43f
callq 0x4260
movq %rax, -0x218(%rbp)
jmp 0x18dfe
movq -0x108(%rbp), %rax
movq 0x10(%rax), %rdi
movswq -0x70(%rbp), %rsi
callq 0x5030
movq (%rax), %rsi
leaq -0xb8(%rbp), %rdi
callq 0x1ea60
jmp 0x18e24
movq -0x218(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x4210
movq %rax, -0x220(%rbp)
jmp 0x18e40
movq -0x220(%rbp), %rdi
leaq 0x24614(%rip), %rsi     # 0x3d462
callq 0x4260
movq %rax, -0x228(%rbp)
jmp 0x18e5c
movq -0x228(%rbp), %rdi
movq 0x3514e(%rip), %rsi     # 0x4dfb8
callq 0x4290
jmp 0x18e71
leaq -0xb8(%rbp), %rdi
callq 0x4160
movl $0x16e360, %edi         # imm = 0x16E360
callq 0x4390
jmp 0x18e89
movq 0x35138(%rip), %rdi     # 0x4dfc8
leaq 0x28137(%rip), %rsi     # 0x40fce
callq 0x4260
jmp 0x18e9e
jmp 0x18ebd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x4160
jmp 0x195a2
jmp 0x18ebf
movw -0x70(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x70(%rbp)
jmp 0x187b4
movw $0x0, -0xba(%rbp)
movswq -0xba(%rbp), %rax
movq %rax, -0x230(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x1b7a0
movq %rax, %rcx
movq -0x230(%rbp), %rax
cmpq %rcx, %rax
jae 0x19067
callq 0x40a0
movl %eax, %ecx
movq -0x108(%rbp), %rax
movslq %ecx, %rcx
movq %rcx, -0x240(%rbp)
movq 0x10(%rax), %rdi
callq 0x5ad0
movq %rax, %rcx
movq -0x240(%rbp), %rax
xorl %edx, %edx
divq %rcx
movq -0x108(%rbp), %rax
movw %dx, %cx
movw %cx, -0xbc(%rbp)
movq 0x10(%rax), %rdi
movswq -0xbc(%rbp), %rsi
callq 0x5030
movq (%rax), %rdi
callq 0x1ea40
movb %al, -0x231(%rbp)
jmp 0x18f66
movb -0x231(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x1903c
movswq -0xba(%rbp), %rsi
leaq -0x20(%rbp), %rdi
callq 0x1b800
movq %rax, %rcx
movq -0x108(%rbp), %rax
movq (%rcx), %rcx
movq %rcx, -0x248(%rbp)
movq 0x10(%rax), %rdi
movswq -0xbc(%rbp), %rsi
callq 0x5030
movq -0x248(%rbp), %rdi
movq (%rax), %rsi
callq 0x17a70
jmp 0x18fc1
movq -0x108(%rbp), %rax
movq 0x10(%rax), %rdi
movswq -0xbc(%rbp), %rsi
callq 0x5030
movq (%rax), %rdi
callq 0x1ea40
movb %al, -0x249(%rbp)
jmp 0x18fe9
movb -0x249(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x19005
movw -0x30(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x30(%rbp)
movq -0x108(%rbp), %rax
movswq -0x30(%rbp), %rcx
movq %rcx, -0x258(%rbp)
movq 0x10(%rax), %rdi
callq 0x5ad0
movq %rax, %rcx
movq -0x258(%rbp), %rax
cmpq %rcx, %rax
jne 0x1903a
movb $0x1, -0x32(%rbp)
movb $0x0, -0x31(%rbp)
jmp 0x19067
jmp 0x1904e
movw -0xba(%rbp), %ax
addw $-0x1, %ax
movw %ax, -0xba(%rbp)
jmp 0x19050
movw -0xba(%rbp), %ax
addw $0x1, %ax
movw %ax, -0xba(%rbp)
jmp 0x18ed9
movb -0x31(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x19296
movb -0x32(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x19296
movb $0x1, -0x2d(%rbp)
movl $0x0, -0xc0(%rbp)
movq -0x108(%rbp), %rax
movslq -0xc0(%rbp), %rcx
movq %rcx, -0x260(%rbp)
movq 0x10(%rax), %rdi
callq 0x5ad0
movq %rax, %rcx
movq -0x260(%rbp), %rax
cmpq %rcx, %rax
jae 0x19291
movq -0x108(%rbp), %rax
movq 0x10(%rax), %rdi
movslq -0xc0(%rbp), %rsi
callq 0x5030
movq (%rax), %rdi
callq 0x1ea40
movb %al, -0x261(%rbp)
jmp 0x190ef
movb -0x261(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x19122
movq -0x108(%rbp), %rax
movq 0x10(%rax), %rdi
movslq -0xc0(%rbp), %rsi
callq 0x5030
movq (%rax), %rdi
callq 0x1f950
jmp 0x19120
jmp 0x19122
movq -0x108(%rbp), %rax
movq 0x10(%rax), %rdi
movslq -0xc0(%rbp), %rsi
callq 0x5030
movq (%rax), %rdi
callq 0x1ea90
movl %eax, -0x268(%rbp)
jmp 0x19149
movl -0x268(%rbp), %eax
cmpl $0x64, %eax
jae 0x19210
movq -0x108(%rbp), %rax
movq 0x10(%rax), %rdi
movslq -0xc0(%rbp), %rsi
callq 0x5030
movq %rax, %rcx
movq -0x108(%rbp), %rax
movq (%rcx), %rcx
movq %rcx, -0x270(%rbp)
movl -0x2c(%rbp), %ecx
cvtsi2sd %rcx, %xmm0
movsd %xmm0, -0x280(%rbp)
movswq -0x22(%rbp), %rcx
movq %rcx, -0x278(%rbp)
movq 0x10(%rax), %rdi
callq 0x5ad0
movsd -0x280(%rbp), %xmm0
movq %rax, %rcx
movq -0x278(%rbp), %rax
addq %rcx, %rax
movq %rax, %xmm1
movaps 0x24107(%rip), %xmm2    # 0x3d2d0
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x2410b(%rip), %xmm2    # 0x3d2e0
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movsd 0x24100(%rip), %xmm1    # 0x3d2f0
divsd %xmm1, %xmm0
callq 0x4060
movq -0x270(%rbp), %rdi
cvttsd2si %xmm0, %rax
movl %eax, %esi
callq 0x1f980
jmp 0x1920e
jmp 0x19210
movq -0x108(%rbp), %rax
movq 0x10(%rax), %rdi
movslq -0xc0(%rbp), %rsi
callq 0x5030
movq %rax, %rcx
movq -0x108(%rbp), %rax
movq (%rcx), %rcx
movq %rcx, -0x290(%rbp)
movl -0x2c(%rbp), %ecx
movl %ecx, -0x294(%rbp)
movswl -0x22(%rbp), %ecx
movl %ecx, -0x284(%rbp)
movq 0x10(%rax), %rdi
callq 0x5ad0
movl -0x294(%rbp), %esi
movq -0x290(%rbp), %rdi
movq %rax, %rcx
movl -0x284(%rbp), %eax
addl %ecx, %eax
imull %eax, %esi
addl %esi, %esi
callq 0x1f9d0
jmp 0x1927b
jmp 0x1927d
movl -0xc0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc0(%rbp)
jmp 0x19097
jmp 0x194a1
movb -0x31(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x19396
movb -0x32(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x19396
movb $0x1, -0x2d(%rbp)
movl $0x0, -0xc4(%rbp)
movq -0x108(%rbp), %rax
movslq -0xc4(%rbp), %rcx
movq %rcx, -0x2a0(%rbp)
movq 0x10(%rax), %rdi
callq 0x5ad0
movq %rax, %rcx
movq -0x2a0(%rbp), %rax
cmpq %rcx, %rax
jae 0x19391
movq -0x108(%rbp), %rax
movq 0x10(%rax), %rdi
movslq -0xc4(%rbp), %rsi
callq 0x5030
movq %rax, %rcx
movq -0x108(%rbp), %rax
movq (%rcx), %rcx
movq %rcx, -0x2b0(%rbp)
movq 0x10(%rax), %rdi
movslq -0xc4(%rbp), %rsi
callq 0x5030
movq (%rax), %rdi
callq 0x1eeb0
movl %eax, -0x2a4(%rbp)
jmp 0x19342
movq -0x2b0(%rbp), %rdi
movl -0x2a4(%rbp), %esi
shrl %esi
negl %esi
callq 0x1f9d0
jmp 0x1935a
movq -0x108(%rbp), %rax
movq 0x10(%rax), %rdi
movslq -0xc4(%rbp), %rsi
callq 0x5030
movq (%rax), %rdi
callq 0x1f950
jmp 0x1937b
jmp 0x1937d
movl -0xc4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc4(%rbp)
jmp 0x192c6
jmp 0x194a1
jmp 0x19398
movl $0x0, -0xc8(%rbp)
movq -0x108(%rbp), %rax
movslq -0xc8(%rbp), %rcx
movq %rcx, -0x2b8(%rbp)
movq 0x10(%rax), %rdi
callq 0x5ad0
movq %rax, %rcx
movq -0x2b8(%rbp), %rax
cmpq %rcx, %rax
jae 0x1943f
movq -0x108(%rbp), %rax
movq 0x10(%rax), %rdi
movslq -0xc8(%rbp), %rsi
callq 0x5030
movq (%rax), %rdi
callq 0x1ea40
movb %al, -0x2b9(%rbp)
jmp 0x193f6
movb -0x2b9(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x19429
movq -0x108(%rbp), %rax
movq 0x10(%rax), %rdi
movslq -0xc8(%rbp), %rsi
callq 0x5030
movq (%rax), %rdi
callq 0x1fb30
jmp 0x19427
jmp 0x19429
jmp 0x1942b
movl -0xc8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc8(%rbp)
jmp 0x193a2
movl $0x0, -0xcc(%rbp)
movslq -0xcc(%rbp), %rax
movq %rax, -0x2c8(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x1b7a0
movq %rax, %rcx
movq -0x2c8(%rbp), %rax
cmpq %rcx, %rax
jae 0x1949c
movslq -0xcc(%rbp), %rsi
leaq -0x20(%rbp), %rdi
callq 0x1b800
movq (%rax), %rdi
callq 0x2e970
jmp 0x19489
jmp 0x1948b
movl -0xcc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xcc(%rbp)
jmp 0x19449
jmp 0x18799
leaq -0x20(%rbp), %rdi
callq 0x1b7a0
movl %eax, -0xd0(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x1b7c0
xorb $-0x1, %al
testb $0x1, %al
jne 0x194c4
jmp 0x19590
movl -0xd0(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
leaq -0x20(%rbp), %rdi
callq 0x1b800
movq (%rax), %rax
movq %rax, -0x2d0(%rbp)
cmpq $0x0, %rax
je 0x194f6
movq -0x2d0(%rbp), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
leaq -0x20(%rbp), %rdi
movq %rdi, -0x2e0(%rbp)
callq 0x1b890
movq %rax, -0xf0(%rbp)
movslq -0xd0(%rbp), %rsi
leaq -0xf0(%rbp), %rdi
callq 0x1b8c0
movq %rax, -0xe8(%rbp)
leaq -0xe8(%rbp), %rdi
movl $0x1, %esi
callq 0x1b900
movq %rax, -0xe0(%rbp)
leaq -0xd8(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x1b940
movq -0x2e0(%rbp), %rdi
movq -0xd8(%rbp), %rsi
callq 0x1b820
movq %rax, -0x2d8(%rbp)
jmp 0x1956e
movq -0x2d8(%rbp), %rax
movq %rax, -0xf8(%rbp)
movl -0xd0(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xd0(%rbp)
jmp 0x194b0
leaq -0x20(%rbp), %rdi
callq 0x1b980
addq $0x2e0, %rsp            # imm = 0x2E0
popq %rbp
retq
leaq -0x20(%rbp), %rdi
callq 0x1b980
movq -0x48(%rbp), %rdi
callq 0x4440
nopw %cs:(%rax,%rax)