// File: /workspace/github_cpp_makefile_star2_O1/rozpo[P]enemy/data/game/shop/Shop.cpp
// Function: Shop::openShop(std::shared_ptr<Player>&)
void Shop::openShop(std::shared_ptr<Player> &player)
{
    int x;
    int heal_cost;
    int recover_cost = 0;

    while(true)
    {
        recover_cost = 0;
        heal_cost = player->max_hitpoints-player->hitpoints;
        if(heal_cost > player->gold)
            heal_cost = player->gold;

        for(int i = 0; i < 4; i++)
            recover_cost += 10-player->uses[i];

        print(player->gold, heal_cost, recover_cost);
        std::cin >> x;
        switch(x)
        {
            case e_shop_heal:
            {
                if(player->gold >= heal_cost)
                {
                    if(player->hitpoints > 0)
                    {
                        player->hitpoints += heal_cost;
                        player->gold-=heal_cost;
                        std::cout << player->name << " is now healthy\n";
                    }
                    else
                    {
                        std::cout << "You can heal only live characters\n";
                    }
                }
                else
                {
                    std::cout << "You dont have enough money \n";
                }
            }
                break;
            case e_shop_revive:
            {
                if(player->gold >= 100)
                {
                    if(player->hitpoints <= 0)
                    {
                        player->hitpoints = player->max_hitpoints;
                        player->gold-=100;
                        std::cout << player->name << " is now alive\n";
                    }
                    else
                    {
                        std::cout << "You can revive only dead characters\n";
                    }
                }
                else
                {
                    std::cout << "You dont have enough money \n";
                }
            }
                break;
            case e_shop_recover:
            {
                if(player->gold >= recover_cost)
                {
                    for(int i=0; i < 4; i++)
                        player->uses[i]=10;
                    player->gold-=recover_cost;
                    recover_cost = 0;
                    std::cout << player->name << " skills was recovered\n";
                }
                else
                {
                    std::cout << "You dont have enough money \n";
                }
            }
                break;

            case e_shop_add_hitpoints:
            {
                if(player->gold >= 75)
                {
                    player->max_hitpoints += 10;
                    player->hitpoints += 10;
                    player->gold-=75;
                    std::cout << player->name << " max hitpoints is now " << player->max_hitpoints << "\n";
                }
                else
                {
                    std::cout << "You dont have enough money \n";
                }
            }
                break;
            case e_shop_add_strength:
            {
                if(player->gold >= 50)
                {
                    player->strength += 2;
                    player->gold-=50;
                    std::cout << player->name << " strength is now " << player->strength << "\n";
                }
                else
                {
                    std::cout << "You dont have enough money \n";
                }
            }
                break;
            case e_shop_add_agility:
            {
                if(player->gold >= 50)
                {
                    player->agility += 2;
                    player->gold-=50;
                    std::cout << player->name << " agility is now " << player->agility << "\n";
                }
                else
                {
                    std::cout << "You dont have enough money \n";
                }
            }
                break;

            case e_shop_add_intelligence:
            {
                if(player->gold >= 50)
                {
                    player->intelligence += 2;
                    player->gold-=50;
                    std::cout << player->name << " intelligence is now " << player->intelligence << "\n";
                }
                else
                {
                    std::cout << "You dont have enough money \n";
                }
            }
                break;
            default:
                return;
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
movq %rsp, %rax
movl $0x0, (%rax)
leaq 0x4(%rsp), %r13
leaq 0x4e32(%rip), %r15      # 0xb680
movl $0x0, (%rsp)
movq (%rbx), %rdx
movl 0x8(%rdx), %eax
movl 0xc(%rdx), %r12d
leaq 0x3c(%rdx), %rsi
movl 0x3c(%rdx), %ecx
xorl %edi, %edi
xorl %ebp, %ebp
subl 0x2c(%rdx,%rdi,4), %ebp
addl $0xa, %ebp
incq %rdi
cmpq $0x4, %rdi
jne 0x686a
subl %eax, %r12d
cmpl %ecx, %r12d
cmovgel %ecx, %r12d
movl %ebp, (%rsp)
movq %r14, %rdi
movl %r12d, %edx
movq %rsp, %rcx
callq 0x6b70
movq 0xa744(%rip), %rdi      # 0x10fe0
movq %r13, %rsi
callq 0x30a0
movl 0x4(%rsp), %eax
decl %eax
cmpl $0x6, %eax
ja 0x6b60
movslq (%r15,%rax,4), %rax
addq %r15, %rax
jmpq *%rax
movq (%rbx), %rax
movl 0x3c(%rax), %ecx
subl %r12d, %ecx
jl 0x6aed
movl 0x8(%rax), %edx
testl %edx, %edx
jle 0x6b0a
addl %r12d, %edx
movl %edx, 0x8(%rax)
movl %ecx, 0x3c(%rax)
movq 0x40(%rax), %rsi
movq 0x48(%rax), %rdx
movq 0xa6e2(%rip), %rdi      # 0x10fd0
callq 0x3140
movl $0x10, %edx
movq %rax, %rdi
leaq 0x4d9a(%rip), %rsi      # 0xb69c
callq 0x3140
jmp 0x684e
movq (%rbx), %rax
movl 0x3c(%rax), %ecx
cmpl $0x32, %ecx
jl 0x6aed
addl $0x2, 0x10(%rax)
addl $-0x32, %ecx
movl %ecx, 0x3c(%rax)
movq 0x40(%rax), %rsi
movq 0x48(%rax), %rdx
movq 0xa69c(%rip), %rdi      # 0x10fd0
callq 0x3140
movq %rax, %r12
movl $0x11, %edx
movq %rax, %rdi
leaq 0x4e04(%rip), %rsi      # 0xb74f
callq 0x3140
movq (%rbx), %rax
movl 0x10(%rax), %esi
jmp 0x6acc
movq (%rbx), %rax
cmpl %ebp, 0x3c(%rax)
jl 0x6aed
xorl %ecx, %ecx
movl $0xa, 0x2c(%rax,%rcx,4)
incq %rcx
cmpq $0x4, %rcx
jne 0x6969
subl %ebp, 0x3c(%rax)
movl $0x0, (%rsp)
movq 0x40(%rax), %rsi
movq 0x48(%rax), %rdx
movq 0xa63d(%rip), %rdi      # 0x10fd0
callq 0x3140
movl $0x16, %edx
movq %rax, %rdi
leaq 0x4d7a(%rip), %rsi      # 0xb721
callq 0x3140
jmp 0x684e
movq (%rbx), %rax
movl 0x3c(%rax), %ecx
cmpl $0x4b, %ecx
jl 0x6aed
addl $0xa, 0xc(%rax)
addl $0xa, 0x8(%rax)
addl $-0x4b, %ecx
movl %ecx, 0x3c(%rax)
movq 0x40(%rax), %rsi
movq 0x48(%rax), %rdx
movq 0xa5f3(%rip), %rdi      # 0x10fd0
callq 0x3140
movq %rax, %r12
movl $0x16, %edx
movq %rax, %rdi
leaq 0x4d44(%rip), %rsi      # 0xb738
callq 0x3140
movq (%rbx), %rax
movl 0xc(%rax), %esi
jmp 0x6acc
movq (%rbx), %rax
movl 0x3c(%rax), %ecx
cmpl $0x64, %ecx
jl 0x6aed
cmpl $0x0, 0x8(%rax)
jle 0x6b27
movl $0x24, %edx
movq 0xa5a7(%rip), %rdi      # 0x10fd0
leaq 0x4ccc(%rip), %rsi      # 0xb6fc
callq 0x3140
jmp 0x684e
movq (%rbx), %rax
movl 0x3c(%rax), %ecx
cmpl $0x32, %ecx
jl 0x6aed
addl $0x2, 0x14(%rax)
addl $-0x32, %ecx
movl %ecx, 0x3c(%rax)
movq 0x40(%rax), %rsi
movq 0x48(%rax), %rdx
movq 0xa56e(%rip), %rdi      # 0x10fd0
callq 0x3140
movq %rax, %r12
movl $0x10, %edx
movq %rax, %rdi
leaq 0x4ce8(%rip), %rsi      # 0xb761
callq 0x3140
movq (%rbx), %rax
movl 0x14(%rax), %esi
jmp 0x6acc
movq (%rbx), %rax
movl 0x3c(%rax), %ecx
cmpl $0x32, %ecx
jl 0x6aed
addl $0x2, 0x18(%rax)
addl $-0x32, %ecx
movl %ecx, 0x3c(%rax)
movq 0x40(%rax), %rsi
movq 0x48(%rax), %rdx
movq 0xa526(%rip), %rdi      # 0x10fd0
callq 0x3140
movq %rax, %r12
movl $0x15, %edx
movq %rax, %rdi
leaq 0x4cb1(%rip), %rsi      # 0xb772
callq 0x3140
movq (%rbx), %rax
movl 0x18(%rax), %esi
movq %r12, %rdi
callq 0x31b0
movl $0x1, %edx
movq %rax, %rdi
leaq 0x4b93(%rip), %rsi      # 0xb676
callq 0x3140
jmp 0x684e
movl $0x1c, %edx
movq 0xa4d7(%rip), %rdi      # 0x10fd0
leaq 0x4bd0(%rip), %rsi      # 0xb6d0
callq 0x3140
jmp 0x684e
movl $0x22, %edx
movq 0xa4ba(%rip), %rdi      # 0x10fd0
leaq 0x4b90(%rip), %rsi      # 0xb6ad
callq 0x3140
jmp 0x684e
movl 0xc(%rax), %edx
movl %edx, 0x8(%rax)
addl $-0x64, %ecx
movl %ecx, 0x3c(%rax)
movq 0x40(%rax), %rsi
movq 0x48(%rax), %rdx
movq 0xa48e(%rip), %rdi      # 0x10fd0
callq 0x3140
movl $0xe, %edx
movq %rax, %rdi
leaq 0x4b97(%rip), %rsi      # 0xb6ed
callq 0x3140
jmp 0x684e
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop