// File: /workspace/github_cpp_makefile_star2_O3/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, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
callq 0x3060
movq 0x10(%rbx), %rax
movq (%rax), %rax
movq (%rax), %rdi
callq 0x10840
xorl %ebp, %ebp
movl $0x0, %ecx
movq %rcx, 0x18(%rsp)
cmpl $0x5, %eax
jb 0xbf06
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, 0x18(%rsp)
movq %rbx, 0x10(%rsp)
movq 0x10(%rbx), %rdi
movq (%rdi), %rsi
movq 0x8(%rdi), %r8
subq %rsi, %r8
je 0xbf86
xorl %r13d, %r13d
movw $0x1, %r12w
leaq 0x20(%rsp), %r14
leaq 0x48(%rsp), %r15
xorl %ebp, %ebp
movq 0x10(%rsp), %rbx
movq (%rsi,%r13,8), %rdi
callq 0x10840
movl %eax, %edi
callq 0xaee6
movq %rax, 0x48(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0xef2c
movq 0x10(%rbx), %rax
movq (%rax), %rax
movq (%rax,%r13,8), %rdi
callq 0x10840
addl %eax, %ebp
movswq %r12w, %r13
movq 0x10(%rbx), %rdi
movq (%rdi), %rsi
movq 0x8(%rdi), %r8
subq %rsi, %r8
sarq $0x3, %r8
incl %r12d
cmpq %r13, %r8
ja 0xbf34
jmp 0xbf8a
sarq $0x3, %r8
movl %ebp, %ecx
xorl %r13d, %r13d
movq %rcx, %rax
xorl %edx, %edx
divq %r8
movq %rax, %r14
movq 0x18(%rsp), %rax
testw %ax, %ax
jle 0xbfe3
leaq 0x20(%rsp), %r15
leaq 0x48(%rsp), %r12
movl %eax, %ebx
movl %r14d, %edi
callq 0xaee6
movq %rax, 0x48(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0xef2c
addl %r14d, %ebp
decw %bx
jne 0xbfb0
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rdi
movq (%rdi), %rsi
movl %ebp, %ecx
movq 0x18(%rsp), %rax
movswq %ax, %rax
movq 0x8(%rdi), %rdi
movq %rdi, %r8
subq %rsi, %r8
sarq $0x3, %r8
movq %rax, 0x80(%rsp)
addq %rax, %r8
movq %rcx, %rax
xorl %edx, %edx
divq %r8
movq %rax, 0x78(%rsp)
movb $0x20, 0xf(%rsp)
movq 0x22faf(%rip), %r15     # 0x2efc8
leaq 0x48(%rsp), %r14
movq $0x0, 0x70(%rsp)
movq $0x0, 0x68(%rsp)
movl $0x0, 0x44(%rsp)
cmpq %rsi, %rdi
je 0xc595
movb $0x1, 0x18(%rsp)
xorl %r12d, %r12d
xorl %ebx, %ebx
testb $0x1, 0x18(%rsp)
je 0xc1c7
movl $0xa, %edx
movq %r15, %rdi
leaq 0x1836b(%rip), %rsi     # 0x243d0
callq 0x31e0
movq 0x28(%rsp), %rax
subq 0x20(%rsp), %rax
movq 0x10(%rsp), %rcx
movq 0x10(%rcx), %rcx
movq 0x8(%rcx), %rdx
subq (%rcx), %rdx
cmpq %rdx, %rax
jbe 0xc0a4
movl $0x2, %edx
movq %r15, %rdi
leaq 0x18343(%rip), %rsi     # 0x243db
callq 0x31e0
leaq 0x20(%rsp), %rax
jmp 0xc0c1
movl $0x2, %edx
movq %r15, %rdi
leaq 0x18328(%rip), %rsi     # 0x243db
callq 0x31e0
movq 0x10(%rsp), %rax
movq 0x10(%rax), %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 %r15, %rdi
callq 0x30f0
movl $0x1, %edx
movq %rax, %rdi
leaq 0x1b6de(%rip), %rsi     # 0x277d6
callq 0x31e0
cmpw $0x1, %bx
adcl $0x0, 0x44(%rsp)
movl $0xb, %edx
movq %r15, %rdi
leaq 0x182c9(%rip), %rsi     # 0x243de
callq 0x31e0
movl 0x44(%rsp), %esi
movq %r15, %rdi
callq 0x30f0
movq %rax, %rbp
movl $0x5, %edx
movq %rax, %rdi
leaq 0x182b2(%rip), %rsi     # 0x243ea
callq 0x31e0
movq (%rbp), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x3190
movsbl %al, %esi
movq %rbp, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3100
movq %rax, %rbp
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x3190
movsbl %al, %esi
movq %rbp, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3100
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0xcb9e
movl 0x28(%rsp), %eax
subl 0x20(%rsp), %eax
shrl $0x3, %eax
movw %ax, 0x48(%rsp)
movq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0xdbb8
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rsi
movq (%rsi,%r12,8), %rdi
callq 0x10808
testb %al, %al
je 0xc294
movl $0x22, %edx
movq %r15, %rdi
leaq 0x18258(%rip), %rsi     # 0x2443f
callq 0x31e0
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rax
movq (%rax,%r12,8), %rsi
movq %r14, %rdi
callq 0x10812
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
movq %r15, %rdi
callq 0x31e0
movq %rax, %rbp
movl $0x11, %edx
movq %rax, %rdi
leaq 0x1823a(%rip), %rsi     # 0x24462
callq 0x31e0
movq (%rbp), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x3190
movsbl %al, %esi
movq %rbp, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3100
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0xc271
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x31b0
movl $0x16e360, %edi         # imm = 0x16E360
callq 0x3260
movl $0x7, %edx
movq %r15, %rdi
leaq 0x1bd04(%rip), %rsi     # 0x27f8e
callq 0x31e0
jmp 0xc56f
movb 0x18(%rsp), %cl
andb $0x1, %cl
movb 0xf(%rsp), %al
xorb $0x63, %al
movb %cl, 0x18(%rsp)
orb %cl, %al
jne 0xc2bd
movl $0x4, %edx
movq %r15, %rdi
leaq 0x180d9(%rip), %rsi     # 0x24391
callq 0x31e0
movl $0x1b, %edx
movq %r15, %rdi
leaq 0x18124(%rip), %rsi     # 0x243f0
callq 0x31e0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3190
movsbl %al, %esi
movq %r15, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3100
movl $0x5, %edx
movq %r15, %rdi
leaq 0x18105(%rip), %rsi     # 0x2440c
callq 0x31e0
movswl %bx, %esi
incl %esi
movq %r15, %rdi
callq 0x32e0
movq %rax, %rbp
movl $0xd, %edx
movq %rax, %rdi
leaq 0x18050(%rip), %rsi     # 0x2437b
callq 0x31e0
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rax
movq (%rax,%r12,8), %rsi
movq %r14, %rdi
callq 0x10812
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
movq %rbp, %rdi
callq 0x31e0
movq %rax, %rbp
movl $0x4, %edx
movq %rax, %rdi
leaq 0x1aa78(%rip), %rsi     # 0x26de4
callq 0x31e0
movq (%rbp), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x3190
movsbl %al, %esi
movq %rbp, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3100
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0xc3b5
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x31b0
movl $0x3, %edx
movq %r15, %rdi
leaq 0x1a3df(%rip), %rsi     # 0x267a3
callq 0x31e0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3190
movsbl %al, %esi
movq %r15, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3100
movb 0xf(%rsp), %al
xorb $0xa, %al
orb %al, 0x18(%rsp)
sete %cl
testb $0x1, %cl
je 0xc465
movl $0x4, %edx
movq %r15, %rdi
leaq 0x18001(%rip), %rsi     # 0x24412
callq 0x31e0
movl $0x3, %edx
movq %r15, %rdi
leaq 0x1a37e(%rip), %rsi     # 0x267a3
callq 0x31e0
movl $0x15, %edx
movq %r15, %rdi
leaq 0x17fde(%rip), %rsi     # 0x24417
callq 0x31e0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3190
movsbl %al, %esi
movq %r15, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3100
movl %r13d, 0x48(%rsp)
movq %r14, %rsi
xorl %edx, %edx
callq 0xbbde
callq 0x10684
movl %eax, %ebp
cmpb $0x77, %al
jne 0xc489
testl %r13d, %r13d
je 0xc489
decl %r13d
jmp 0xc4a5
cmpb $0x73, %bpl
sete %al
cmpl $0x4, %r13d
setl %cl
andb %al, %cl
movzbl %cl, %eax
addl %eax, %r13d
cmpb $0xa, %bpl
je 0xc4c1
movl $0x4, %edx
movq %r15, %rdi
leaq 0x17f79(%rip), %rsi     # 0x2442d
callq 0x31e0
cmpb $0x63, %bpl
jne 0xc465
jmp 0xc51b
movq 0x10(%rsp), %rdi
movq 0x10(%rdi), %rax
movq (%rax), %rax
movq (%rax,%r12,8), %rsi
leal 0x1(%r13), %eax
movswl %ax, %edx
leaq 0x20(%rsp), %rcx
callq 0xc9a2
movb $0x1, %cl
testb %al, %al
je 0xc3fd
movl $0x7, %edx
movq %r15, %rdi
leaq 0x17f3c(%rip), %rsi     # 0x24437
callq 0x31e0
movq 0x20(%rsp), %rax
movb $0xa, 0xf(%rsp)
movb $0x1, 0x18(%rsp)
cmpq 0x28(%rsp), %rax
jne 0xc56f
jmp 0xc700
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rcx
movq 0x8(%rcx), %rax
subq (%rcx), %rax
sarq $0x3, %rax
decq %rax
cmpq %r12, %rax
jne 0xc562
movl $0x4, %edx
movq %r15, %rdi
leaq 0x17eec(%rip), %rsi     # 0x24432
callq 0x31e0
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rcx
movq 0x8(%rcx), %rax
subq (%rcx), %rax
sarq $0x3, %rax
decq %rax
cmpq %r12, %rax
setbe 0x18(%rsp)
movb $0x63, 0xf(%rsp)
incl %ebx
movswq %bx, %r12
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rax
subq %rsi, %rax
sarq $0x3, %rax
cmpq %r12, %rax
ja 0xc04b
movq 0x28(%rsp), %rax
cmpq 0x20(%rsp), %rax
je 0xc65b
xorl %r12d, %r12d
xorl %ebx, %ebx
callq 0x3060
cltq
movq 0x10(%rsp), %rcx
movq 0x10(%rcx), %rcx
movq (%rcx), %rsi
movq 0x8(%rcx), %rcx
subq %rsi, %rcx
sarq $0x3, %rcx
xorl %edx, %edx
divq %rcx
movswq %dx, %rbp
movq (%rsi,%rbp,8), %rdi
callq 0x10808
testb %al, %al
je 0xc5e2
decl %ebx
jmp 0xc63e
movq 0x20(%rsp), %rax
movq (%rax,%r12,8), %rdi
movq 0x10(%rsp), %r12
movq 0x10(%r12), %rax
movq (%rax), %rax
movq (%rax,%rbp,8), %rsi
callq 0xb574
movq 0x10(%r12), %rax
movq (%rax), %rax
movq (%rax,%rbp,8), %rdi
callq 0x10808
movzbl %al, %eax
movq 0x70(%rsp), %rcx
addl %eax, %ecx
movq %rcx, 0x70(%rsp)
movswq %cx, %rax
movq 0x10(%r12), %rcx
movq 0x8(%rcx), %rdx
subq (%rcx), %rdx
sarq $0x3, %rdx
cmpq %rax, %rdx
je 0xc70c
incl %ebx
movswq %bx, %r12
movq 0x28(%rsp), %rax
subq 0x20(%rsp), %rax
sarq $0x3, %rax
cmpq %r12, %rax
ja 0xc5aa
testb $0x1, 0x68(%rsp)
jne 0xc806
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rsi
cmpq %rsi, 0x8(%rax)
je 0xc6bb
xorl %ebx, %ebx
movq (%rsi,%rbx,8), %rdi
callq 0x10808
testb %al, %al
jne 0xc69c
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rax
movq (%rax,%rbx,8), %rdi
callq 0x11180
incq %rbx
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rcx
subq %rsi, %rcx
sarq $0x3, %rcx
cmpq %rbx, %rcx
ja 0xc67a
movq 0x20(%rsp), %rcx
cmpq %rcx, 0x28(%rsp)
je 0xc6f7
xorl %ebx, %ebx
movq (%rcx,%rbx,8), %rdi
callq 0x18f98
incq %rbx
movq 0x20(%rsp), %rcx
movq 0x28(%rsp), %rax
subq %rcx, %rax
sarq $0x3, %rax
cmpq %rbx, %rax
ja 0xc6c9
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdi
jmp 0xc038
movb $0x1, %al
movq %rax, 0x68(%rsp)
jmp 0xc595
movq (%rcx), %rax
cmpq %rax, 0x8(%rcx)
movq 0x10(%rsp), %r15
je 0xc760
xorl %ebx, %ebx
movq (%rax,%rbx,8), %r14
movq %r14, %rdi
callq 0x10a4e
shrl %eax
negl %eax
movq %r14, %rdi
movl %eax, %esi
callq 0x1110a
movq 0x10(%r15), %rax
movq (%rax), %rax
movq (%rax,%rbx,8), %rdi
callq 0x110e0
incq %rbx
movq 0x10(%r15), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rbx, %rcx
ja 0xc71c
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rdx
cmpq %rdx, %rdi
je 0xc7e2
movq %rdx, %rax
subq %rdi, %rax
shrq $0x3, %rax
movslq %eax, %rbx
shlq $0x3, %rbx
movq %rbx, %r14
negq %r14
movq -0x8(%rdi,%rbx), %rax
testq %rax, %rax
je 0xc7a3
movq (%rax), %rcx
movq %rax, %rdi
callq *0x18(%rcx)
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rdx
leaq (%rdi,%rbx), %rsi
cmpq %rdx, %rsi
je 0xc7cc
leaq (%rdi,%rbx), %rax
addq $-0x8, %rax
subq %rdi, %rdx
addq %r14, %rdx
movq %rax, %rdi
callq 0x32b0
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rdx
addq $-0x8, %rdx
movq %rdx, 0x28(%rsp)
addq $-0x8, %rbx
addq $0x8, %r14
cmpq %rdx, %rdi
jne 0xc786
testq %rdi, %rdi
je 0xc7f4
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x31b0
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%rsp), %r15
movq 0x10(%r15), %rcx
movq (%rcx), %rax
cmpq %rax, 0x8(%rcx)
movq 0x80(%rsp), %r12
movq 0x78(%rsp), %r13
je 0xc760
movl %r13d, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
movsd %xmm0, 0x18(%rsp)
addq %r13, %r13
xorl %ebx, %ebx
movq (%rax,%rbx,8), %rdi
callq 0x10808
testb %al, %al
je 0xc85c
movq 0x10(%r15), %rax
movq (%rax), %rax
movq (%rax,%rbx,8), %rdi
callq 0x110e0
movq 0x10(%r15), %rax
movq (%rax), %rax
movq (%rax,%rbx,8), %rdi
callq 0x10840
cmpl $0x63, %eax
ja 0xc8cb
movq 0x10(%r15), %rax
movq (%rax), %rcx
movq 0x8(%rax), %rax
movq (%rcx,%rbx,8), %r14
subq %rcx, %rax
sarq $0x3, %rax
addq %r12, %rax
movq %rax, %xmm1
punpckldq 0x17a39(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x17a41(%rip), %xmm1    # 0x242e0
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x18(%rsp), %xmm0
divsd 0x17a37(%rip), %xmm0    # 0x242f0
callq 0x3050
cvttsd2si %xmm0, %rsi
movq %r14, %rdi
callq 0x110ee
movq 0x10(%r15), %rax
movq (%rax), %rcx
movq 0x8(%rax), %rsi
movq (%rcx,%rbx,8), %rdi
subq %rcx, %rsi
shrq $0x3, %rsi
addl %r12d, %esi
imull %r13d, %esi
callq 0x1110a
incq %rbx
movq 0x10(%r15), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rbx, %rcx
ja 0xc83f
jmp 0xc760
jmp 0xc94f
jmp 0xc94f
jmp 0xc94f
jmp 0xc94f
jmp 0xc94f
jmp 0xc94f
jmp 0xc94f
jmp 0xc94f
jmp 0xc94f
jmp 0xc94f
jmp 0xc94f
jmp 0xc94f
jmp 0xc92a
movq %rax, %rbx
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0xc952
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x31b0
jmp 0xc952
jmp 0xc94f
jmp 0xc94f
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0xc969
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x31b0
movq %rbx, %rdi
callq 0x32f0
nop