// File: /workspace/github_cpp_makefile_star2_O3/MichaelXanth[P]RPG_Game/Market/Market.cpp
// Function: Market::Sell(std::vector<Hero*, std::allocator<Hero*>>&)
void Market::Sell(vector<Hero *>& heroes)
{
    unsigned int i;

    int action;
    string testAction;
    bool infoState     = false;
    Hero* selectedHero = NULL;

    if (heroes.size() == 1 && isAbleToSell(heroes[0]) == -1) {
        usleep(2500000);
        DisplayMarket();
        return;
    
    } else {
        for (i = 0; i < heroes.size() && isAbleToSell(heroes[i],false) == -1; i++)
            ;

        if (i == heroes.size()) {
            cerr << endl << "\033[31mError:\033[0m No one of the heroes have any Items or Spells for sale.";
            usleep(2500000);
            DisplayMarket();
            return;
        }
    }

    while(true) {
        int sellState;

        if (heroes.size() == 1) {
            selectedHero = heroes[0];
        
        } else {
            for (i = 0; i < heroes.size() && isAbleToSell(heroes[i],false) == -1; i++)
                ;

            if (i == heroes.size()) {
                cerr << endl << "-------------------------------" << endl << endl;
                cerr << "\033[35mWarning:\033[0m No one of the heroes have any Items or Spells left for sale.";
                usleep(2500000);
                DisplayMarket();
                return;
            }

            while(selectedHero == NULL) {
                //bool errorFlag = false;
                cout << endl;
                cout << "-------------------------------" << endl << endl;
                cout << "(Type 0 to cancel)" << endl;
                cout << "Choose a Hero (1 - " << heroes.size() << "): ";

                cout << "\n\n\n\n\n";
                cout << "\033[5A\033[23C";

                while(true) {
                    bool errFlag = false;

                    cout << "\033[s";

                    do {
                        if (errFlag)
                            usleep(1800000);

                        cout << "\033[u";
                        cout << "\033[J";
                        cout << "\033[s";

                        cin >> testAction;

                        errFlag = true;
                    } while(!isNumeric(testAction.c_str(),action));

                    if (action < 0 || action > heroes.size()) {
                        cerr << endl << "\033[31mError:\033[0m Please choose a number in the given range." << endl;


                        usleep(1800000);

                        cout << "\033[u";
                        cout << "\033[J";

                        //cout << "\033[K";
                        //cout << "\033[1A\033[K";
                        //cout << "\033[1A\033[K";

                        //if (errorFlag)
                        //    cout << "\033[1A\033[K";

                        //errorFlag = true;
                    
                    } else {
                        if (!action) {
                            DisplayMarket();
                            return;
                        }
                        selectedHero = heroes[action - 1];
                        break;
                    }
                }
            }
        }

        if ((sellState = isAbleToSell(selectedHero)) != -1) {
            bool errFlag = false;

            selectedHero->DisplayProdsForSale(infoState,sellState);

            cout << endl;
            /*if (sellState == 0 || sellState == 1)
            {
                cout << "\033[44C-------------------------------" << endl << endl;
                cout << "\033[44CChoose an action: ";
            
            } else {*/
                cout << "-------------------------------" << endl << endl;
                cout << "Choose an action: ";
            //}

            cout << "\n\n\n\n\n";
            cout << "\033[5A\033[18C";

            cout << "\033[s";

            do {
                if (errFlag)
                    usleep(1800000);

                cout << "\033[u";
                cout << "\033[J";
                cout << "\033[s";

                cin >> testAction;

                errFlag = true;
            } while(!isValid(testAction.c_str(),action,1,3));

            switch(action)
            {
                case 1:
                    Sale(*selectedHero,sellState);
                    break;
                case 2:
                    infoState = !infoState;
                    //selectedHero->DisplayProdsForSale(infoState,sellState);
                    break;
                case 3:
                    DisplayMarket();
                    return;
            }
        
        } else if (heroes.size() == 1) {
            usleep(2500000);
            DisplayMarket();
            return;
        }

        if (sellState == -1) {
            DisplayMarket();
            return;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, -0x48(%rbp)
leaq -0x70(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq $0x0, -0x8(%rcx)
xorl %eax, %eax
movb %al, (%rcx)
movb %al, -0x29(%rbp)
movq (%rsi), %rax
movq %rsi, -0x40(%rbp)
movq 0x8(%rsi), %rcx
movq %rcx, %rdx
subq %rax, %rdx
cmpq $0x8, %rdx
jne 0x21e46
movq (%rax), %rsi
leaq -0x34(%rbp), %rdx
movb $0x1, (%rdx)
callq 0x21036
cmpl $-0x1, %eax
je 0x22446
movq -0x40(%rbp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
cmpq %rax, %rcx
je 0x21e8f
movl $0x1, %r15d
xorl %r14d, %r14d
leaq -0x34(%rbp), %rbx
movq (%rax,%r14,8), %rsi
movb $0x0, -0x34(%rbp)
movq %rbx, %rdx
callq 0x21036
cmpl $-0x1, %eax
jne 0x21e97
movl %r15d, %r14d
movq -0x40(%rbp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x3, %rdx
incl %r15d
cmpq %r14, %rdx
ja 0x21e58
jmp 0x21ea2
xorl %r14d, %r14d
movq %rax, %rcx
jmp 0x21ea2
movq -0x40(%rbp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %r14, %rdx
jne 0x21f1a
movq 0xd138(%rip), %rdi      # 0x2eff0
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x3190
movsbl %al, %esi
movq 0xd11d(%rip), %rdi      # 0x2eff0
callq 0x3040
movq %rax, %rdi
callq 0x3100
leaq 0x5abd(%rip), %rsi      # 0x279a4
movl $0x47, %edx
movq %rax, %rdi
callq 0x31e0
movl $0x2625a0, %edi         # imm = 0x2625A0
callq 0x3260
leaq -0x34(%rbp), %rsi
movb $0x0, (%rsi)
movq -0x48(%rbp), %rdi
xorl %edx, %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x1b982
jmp 0x22594
movq $0x0, -0x58(%rbp)
movq 0xd09f(%rip), %r12      # 0x2efc8
leaq 0x294e(%rip), %r13      # 0x2487e
leaq 0x2971(%rip), %rbx      # 0x248a8
leaq 0x4865(%rip), %r15      # 0x267a3
movq %rcx, %rdx
subq %rax, %rdx
cmpq $0x8, %rdx
jne 0x220f1
movq (%rax), %rsi
movb $0x1, -0x30(%rbp)
movq %rsi, -0x58(%rbp)
leaq -0x30(%rbp), %rdx
callq 0x21036
movl %eax, -0x34(%rbp)
cmpl $-0x1, %eax
je 0x2213d
movq -0x58(%rbp), %rdi
leaq -0x29(%rbp), %rsi
leaq -0x34(%rbp), %rdx
callq 0x1180e
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
movl $0x1f, %edx
movq %r12, %rdi
leaq 0x529c(%rip), %rsi      # 0x27252
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, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3190
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3100
movl $0x12, %edx
movq %r12, %rdi
leaq 0x57f7(%rip), %rsi      # 0x27813
callq 0x31e0
movl $0x5, %edx
movq %r12, %rdi
leaq 0x53f8(%rip), %rsi      # 0x27428
callq 0x31e0
movl $0x9, %edx
movq %r12, %rdi
leaq 0x57e2(%rip), %rsi      # 0x27826
callq 0x31e0
movl $0x3, %edx
movq %r12, %rdi
movq %r13, %rsi
callq 0x31e0
movl $0x3, %edx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x31e0
movl $0x3, %edx
movq %r12, %rdi
movq %r15, %rsi
callq 0x31e0
movl $0x3, %edx
movq %r12, %rdi
movq %r13, %rsi
callq 0x31e0
movq 0xcf48(%rip), %rdi      # 0x2efd8
leaq -0x80(%rbp), %rsi
callq 0x3230
movq -0x80(%rbp), %rdi
movl $0x1, -0x30(%rbp)
movl $0x3, -0x5c(%rbp)
leaq -0x4c(%rbp), %rsi
leaq -0x30(%rbp), %rdx
leaq -0x5c(%rbp), %rcx
movl $0x1, %r8d
callq 0x10336
testb %al, %al
jne 0x220d2
movl $0x1b7740, %edi         # imm = 0x1B7740
callq 0x3260
jmp 0x22059
movl -0x4c(%rbp), %eax
cmpl $0x1, %eax
je 0x22160
cmpl $0x2, %eax
je 0x2215a
cmpl $0x3, %eax
jne 0x2216d
jmp 0x2257d
cmpq %rax, %rcx
je 0x22153
movl $0x1, %r14d
xorl %esi, %esi
movq %rsi, -0x88(%rbp)
movq (%rax,%rsi,8), %rsi
movb $0x0, -0x30(%rbp)
leaq -0x30(%rbp), %rdx
callq 0x21036
cmpl $-0x1, %eax
jne 0x22187
movl %r14d, %esi
movq -0x40(%rbp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x3, %rdx
incl %r14d
cmpq %rsi, %rdx
ja 0x220fe
jmp 0x22199
movq -0x40(%rbp), %rcx
movq 0x8(%rcx), %rax
subq (%rcx), %rax
cmpq $0x8, %rax
jne 0x2216d
jmp 0x2255a
movq %rax, %rcx
xorl %esi, %esi
jmp 0x22199
xorb $0x1, -0x29(%rbp)
jmp 0x2216d
movq -0x58(%rbp), %rsi
leaq -0x34(%rbp), %rdx
callq 0x21192
cmpl $-0x1, -0x34(%rbp)
je 0x2246c
movq -0x40(%rbp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
jmp 0x21f3e
movq -0x40(%rbp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
movq -0x88(%rbp), %rsi
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rsi, %rcx
je 0x22488
movq -0x58(%rbp), %rsi
testq %rsi, %rsi
jne 0x21f51
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
movl $0x1f, %edx
movq %r12, %rdi
leaq 0x5065(%rip), %rsi      # 0x27252
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, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3190
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3100
movl $0x12, %edx
movq %r12, %rdi
leaq 0x514a(%rip), %rsi      # 0x2739d
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
movl $0x13, %edx
movq %r12, %rdi
leaq 0x552b(%rip), %rsi      # 0x277ba
callq 0x31e0
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rsi
subq (%rax), %rsi
sarq $0x3, %rsi
movq %r12, %rdi
callq 0x30f0
movl $0x3, %edx
movq %rax, %rdi
leaq 0x5167(%rip), %rsi      # 0x27421
callq 0x31e0
movl $0x5, %edx
movq %r12, %rdi
leaq 0x515a(%rip), %rsi      # 0x27428
callq 0x31e0
movl $0x9, %edx
movq %r12, %rdi
leaq 0x54ec(%rip), %rsi      # 0x277ce
callq 0x31e0
movl $0x3, %edx
movq %r12, %rdi
movq %r13, %rsi
callq 0x31e0
movl $0x3, %edx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x31e0
movl $0x3, %edx
movq %r12, %rdi
movq %r15, %rsi
callq 0x31e0
movl $0x3, %edx
movq %r12, %rdi
movq %r13, %rsi
callq 0x31e0
movq 0xccaa(%rip), %rdi      # 0x2efd8
leaq -0x80(%rbp), %rsi
callq 0x3230
movq -0x80(%rbp), %rdi
leaq -0x4c(%rbp), %rsi
movl $0x1, %edx
callq 0x1023c
testb %al, %al
jne 0x22359
movl $0x1b7740, %edi         # imm = 0x1B7740
callq 0x3260
jmp 0x222f7
movslq -0x4c(%rbp), %rax
testq %rax, %rax
js 0x2237d
movq -0x40(%rbp), %rdx
movq (%rdx), %rcx
movq 0x8(%rdx), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
cmpq %rax, %rdx
jae 0x2241c
movq 0xcc6c(%rip), %rcx      # 0x2eff0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x3190
movsbl %al, %esi
movq 0xcc4e(%rip), %rdi      # 0x2eff0
callq 0x3040
movq %rax, %rdi
callq 0x3100
movq %rax, %r14
movl $0x3a, %edx
movq %rax, %rdi
leaq 0x5417(%rip), %rsi      # 0x277d8
callq 0x31e0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3190
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3100
movl $0x1b7740, %edi         # imm = 0x1B7740
callq 0x3260
movl $0x3, %edx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x31e0
movl $0x3, %edx
movq %r12, %rdi
movq %r15, %rsi
callq 0x31e0
jmp 0x222e7
testl %eax, %eax
je 0x2242a
movq -0x8(%rcx,%rax,8), %rsi
jmp 0x221ad
leaq -0x30(%rbp), %rsi
movb $0x0, (%rsi)
movq -0x48(%rbp), %rdi
xorl %edx, %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x1b982
jmp 0x22594
movl $0x2625a0, %edi         # imm = 0x2625A0
callq 0x3260
leaq -0x34(%rbp), %rsi
movb $0x0, (%rsi)
movq -0x48(%rbp), %rdi
xorl %edx, %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x1b982
jmp 0x22594
leaq -0x30(%rbp), %rsi
movb $0x0, (%rsi)
movq -0x48(%rbp), %rdi
xorl %edx, %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x1b982
jmp 0x22594
movq 0xcb61(%rip), %rdi      # 0x2eff0
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x3190
movsbl %al, %esi
movq 0xcb46(%rip), %rdi      # 0x2eff0
callq 0x3040
movq %rax, %rdi
callq 0x3100
movq %rax, %rbx
leaq 0x4d91(%rip), %rsi      # 0x27252
movl $0x1f, %edx
movq %rax, %rdi
callq 0x31e0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3190
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3100
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3190
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3100
movq 0xcaca(%rip), %rdi      # 0x2eff0
leaq 0x54bf(%rip), %rsi      # 0x279ec
movl $0x4e, %edx
callq 0x31e0
movl $0x2625a0, %edi         # imm = 0x2625A0
callq 0x3260
leaq -0x30(%rbp), %rsi
movb $0x0, (%rsi)
movq -0x48(%rbp), %rdi
xorl %edx, %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x1b982
jmp 0x22594
movl $0x2625a0, %edi         # imm = 0x2625A0
callq 0x3260
leaq -0x30(%rbp), %rsi
movb $0x0, (%rsi)
movq -0x48(%rbp), %rdi
xorl %edx, %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x1b982
jmp 0x22594
leaq -0x30(%rbp), %rsi
movb $0x0, (%rsi)
movq -0x48(%rbp), %rdi
xorl %edx, %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x1b982
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x225a6
callq 0x3170
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x225d9
jmp 0x225d9
jmp 0x225d9
jmp 0x225d9
jmp 0x225d9
jmp 0x225d9
jmp 0x225d9
jmp 0x225d9
jmp 0x225d9
jmp 0x225d9
jmp 0x225d9
jmp 0x225d9
jmp 0x225d9
jmp 0x225d9
jmp 0x225d9
jmp 0x225d9
jmp 0x225d9
jmp 0x225d9
movq %rax, %rbx
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x225ee
callq 0x3170
movq %rbx, %rdi
callq 0x32f0