// File: /workspace/github_cpp_makefile_star2_O2/Agusyc[P]CTRPG/src/battle.cpp
// Function: Battle::useItem()
int Battle::useItem() {
    unsigned int choice;
    bool exitLoop = false;
    while (!exitLoop) {
        for (unsigned int i = 0; i < player.items.size(); i++) {
            cout << i + 1 << ". " << player.items.at(i).name << endl;
        }

        cout << player.items.size() + 1 << ". Go back" << endl;

        cout << "Your choice: ";

        cin >> choice;

        cout << endl;

        if (choice == player.items.size() + 1) {
            return 1;
        }

        if (choice > player.items.size() || choice < 1) {
            printMessage("That's not a valid choice...");
            cout << endl;
            continue;
        }

        exitLoop = true;
    }

    Item item = player.items.at(choice - 1);

    stringstream ss;

    ss << "The item " << YELLOW << item.name << WHITE << ":" << endl;

    if (item.attackBoost != 0) {
        ss << "Boosts your attack by " << GREEN << item.attackBoost << WHITE << endl;
        player.attack += item.attackBoost;
    }

    if (item.defenseBoost != 0) {
        ss << "Boosts your defense by " << GREEN << item.defenseBoost << WHITE << endl;
        player.defense += item.defenseBoost;
    }

    if (item.manaRecover != 0) {
        ss << "Gives you " << GREEN << item.manaRecover << WHITE << " mana." << endl;
        player.mana += item.manaRecover;
    }

    if (item.staminaRecover != 0) {
        ss << "Gives you " << GREEN << item.staminaRecover << WHITE << " stamina." << endl;
        player.stamina += item.staminaRecover;
    }

    if (item.hpRecover != 0) {
        ss << "Gives you " << GREEN << item.hpRecover << WHITE << " HP." << endl;
        player.hp += item.hpRecover;
    }

    cout << ss.str() << endl;

    player.items.erase(player.items.begin() + item.id); // Delete item with index "item.id"

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x238, %rsp            # imm = 0x238
movq %rdi, %r14
leaq 0x60(%rdi), %rax
movq %rax, -0x30(%rbp)
xorl %r15d, %r15d
movq 0x7e39(%rip), %r12      # 0xcfd0
movl %r15d, %ebx
movq 0x68(%r14), %rsi
subq 0x60(%r14), %rsi
sarq $0x6, %rsi
cmpq %rbx, %rsi
jbe 0x51ed
leal 0x1(%rbx), %r15d
movq %r12, %rdi
movq %r15, %rsi
callq 0x3170
movq %rax, %rdi
leaq 0x3f83(%rip), %rsi      # 0x9147
callq 0x3220
movq %rax, %r13
movq -0x30(%rbp), %rdi
movq %rbx, %rsi
callq 0x6322
movq %r13, %rdi
movq %rax, %rsi
callq 0x31d0
movq %rax, %rdi
callq 0x3110
jmp 0x5197
incq %rsi
movq %r12, %rdi
callq 0x3170
movq %rax, %rdi
leaq 0x3f48(%rip), %rsi      # 0x914a
callq 0x3220
movq %rax, %rdi
callq 0x3110
movq %r12, %rdi
leaq 0x3f16(%rip), %rsi      # 0x912f
callq 0x3220
movq 0x7dbb(%rip), %rdi      # 0xcfe0
leaq -0x34(%rbp), %rsi
callq 0x3480
movq %r12, %rdi
callq 0x3110
movq 0x68(%r14), %rax
subq 0x60(%r14), %rax
movl -0x34(%rbp), %esi
sarq $0x6, %rax
leaq 0x1(%rax), %rcx
cmpq %rsi, %rcx
je 0x52c6
testq %rsi, %rsi
je 0x5258
cmpq %rsi, %rax
jae 0x52ce
leaq -0xd8(%rbp), %rbx
movq %rbx, %rdi
leaq 0x3eeb(%rip), %rsi      # 0x9154
leaq -0x260(%rbp), %rdx
callq 0x30c0
leaq -0xb8(%rbp), %r15
movq %r15, %rdi
leaq 0x3dc6(%rip), %rsi      # 0x904c
leaq -0x78(%rbp), %rdx
callq 0x30c0
movq %rbx, %rdi
movq %r15, %rsi
pushq $0x23
popq %rdx
movl $0x12c, %ecx            # imm = 0x12C
pushq $0x1
popq %r8
callq 0x8e78
movq %r15, %rdi
callq 0x3100
movq %rbx, %rdi
callq 0x3100
movq %r12, %rdi
callq 0x3110
xorl %r15d, %r15d
jmp 0x5197
pushq $0x1
popq %rax
jmp 0x555b
decl %esi
movq -0x30(%rbp), %rdi
callq 0x6322
leaq -0x78(%rbp), %rdi
movq %rax, %rsi
callq 0x6344
leaq -0x260(%rbp), %rdi
callq 0x3180
leaq -0x250(%rbp), %r15
leaq 0x3fdc(%rip), %rsi      # 0x92db
movq %r15, %rdi
callq 0x3220
leaq 0x3d32(%rip), %rsi      # 0x9040
movq %rax, %rdi
callq 0x3220
leaq -0x78(%rbp), %rsi
movq %rax, %rdi
callq 0x31d0
leaq 0x3d23(%rip), %rsi      # 0x904c
movq %rax, %rdi
callq 0x3220
leaq 0x4184(%rip), %rsi      # 0x94bc
movq %rax, %rdi
callq 0x3220
movq %rax, %rdi
callq 0x3110
cmpl $0x0, -0x58(%rbp)
je 0x5395
leaq 0x3f90(%rip), %rsi      # 0x92e5
movq %r15, %rdi
callq 0x3220
leaq 0x3dbb(%rip), %rsi      # 0x911f
movq %rax, %rdi
callq 0x3220
movl -0x58(%rbp), %esi
movq %rax, %rdi
callq 0x3470
leaq 0x3cce(%rip), %rsi      # 0x904c
movq %rax, %rdi
callq 0x3220
movq %rax, %rdi
callq 0x3110
movl -0x58(%rbp), %eax
addl %eax, 0x20(%r14)
cmpl $0x0, -0x54(%rbp)
je 0x53e2
leaq 0x3f5a(%rip), %rsi      # 0x92fc
movq %r15, %rdi
callq 0x3220
leaq 0x3d6e(%rip), %rsi      # 0x911f
movq %rax, %rdi
callq 0x3220
movl -0x54(%rbp), %esi
movq %rax, %rdi
callq 0x3470
leaq 0x3c81(%rip), %rsi      # 0x904c
movq %rax, %rdi
callq 0x3220
movq %rax, %rdi
callq 0x3110
movl -0x54(%rbp), %eax
addl %eax, 0x24(%r14)
cmpl $0x0, -0x50(%rbp)
je 0x543e
leaq 0x3f25(%rip), %rsi      # 0x9314
movq %r15, %rdi
callq 0x3220
leaq 0x3d21(%rip), %rsi      # 0x911f
movq %rax, %rdi
callq 0x3220
movl -0x50(%rbp), %esi
movq %rax, %rdi
callq 0x3470
leaq 0x3c34(%rip), %rsi      # 0x904c
movq %rax, %rdi
callq 0x3220
leaq 0x3ef8(%rip), %rsi      # 0x931f
movq %rax, %rdi
callq 0x3220
movq %rax, %rdi
callq 0x3110
movl -0x50(%rbp), %eax
addl %eax, 0x2c(%r14)
cmpl $0x0, -0x4c(%rbp)
je 0x549a
leaq 0x3ec9(%rip), %rsi      # 0x9314
movq %r15, %rdi
callq 0x3220
leaq 0x3cc5(%rip), %rsi      # 0x911f
movq %rax, %rdi
callq 0x3220
movl -0x4c(%rbp), %esi
movq %rax, %rdi
callq 0x3470
leaq 0x3bd8(%rip), %rsi      # 0x904c
movq %rax, %rdi
callq 0x3220
leaq 0x3ea3(%rip), %rsi      # 0x9326
movq %rax, %rdi
callq 0x3220
movq %rax, %rdi
callq 0x3110
movl -0x4c(%rbp), %eax
addl %eax, 0x30(%r14)
cmpl $0x0, -0x48(%rbp)
je 0x54f6
leaq 0x3e6d(%rip), %rsi      # 0x9314
movq %r15, %rdi
callq 0x3220
leaq 0x3c69(%rip), %rsi      # 0x911f
movq %rax, %rdi
callq 0x3220
movl -0x48(%rbp), %esi
movq %rax, %rdi
callq 0x3470
leaq 0x3b7c(%rip), %rsi      # 0x904c
movq %rax, %rdi
callq 0x3220
leaq 0x3d30(%rip), %rsi      # 0x920f
movq %rax, %rdi
callq 0x3220
movq %rax, %rdi
callq 0x3110
movl -0x48(%rbp), %eax
addl %eax, 0x34(%r14)
leaq -0x248(%rbp), %rsi
leaq -0x98(%rbp), %rdi
callq 0x33f0
movq 0x7ac0(%rip), %rdi      # 0xcfd0
leaq -0x98(%rbp), %rsi
callq 0x31d0
movq %rax, %rdi
callq 0x3110
leaq -0x98(%rbp), %rdi
callq 0x3100
movslq -0x3c(%rbp), %rsi
shlq $0x6, %rsi
movq -0x30(%rbp), %rdi
addq (%rdi), %rsi
callq 0x636e
leaq -0x260(%rbp), %rdi
callq 0x3190
leaq -0x78(%rbp), %rdi
callq 0x3100
xorl %eax, %eax
addq $0x238, %rsp            # imm = 0x238
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5587
jmp 0x5587
movq %rax, %rbx
jmp 0x5596
movq %rax, %rbx
leaq -0x98(%rbp), %rdi
callq 0x3100
jmp 0x558a
movq %rax, %rbx
leaq -0x260(%rbp), %rdi
callq 0x3190
leaq -0x78(%rbp), %rdi
jmp 0x55b7
movq %rax, %rbx
jmp 0x55b0
movq %rax, %rbx
leaq -0xb8(%rbp), %rdi
callq 0x3100
leaq -0xd8(%rbp), %rdi
callq 0x3100
jmp 0x55c1
movq %rax, %rbx
movq %rbx, %rdi
callq 0x3490
nop