// File: /workspace/github_cpp_makefile_star2_O3/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, -0x78(%rbp)
movq 0x8914(%rip), %r15      # 0xefd0
movq 0x68(%r14), %rsi
movq 0x60(%r14), %rax
subq %rax, %rsi
je 0x676d
movl $0x1, %eax
xorl %r13d, %r13d
movl %eax, %ebx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x3190
movq %rax, %r12
movl $0x2, %edx
movq %rax, %rdi
leaq 0x5a53(%rip), %rsi      # 0xc147
callq 0x32f0
movq 0x60(%r14), %rax
movq 0x68(%r14), %rdx
subq %rax, %rdx
sarq $0x6, %rdx
cmpq %r13, %rdx
jbe 0x6d5e
shlq $0x6, %r13
movq (%rax,%r13), %rsi
movq 0x8(%rax,%r13), %rdx
movq %r12, %rdi
callq 0x32f0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %r12, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31a0
movq 0x68(%r14), %rsi
subq 0x60(%r14), %rsi
sarq $0x6, %rsi
leal 0x1(%rbx), %eax
movq %rbx, %r13
cmpq %rbx, %rsi
ja 0x66d5
jmp 0x6771
sarq $0x6, %rsi
incq %rsi
movq %r15, %rdi
callq 0x3190
movq %rax, %rbx
movl $0x9, %edx
movq %rax, %rdi
leaq 0x59bc(%rip), %rsi      # 0xc14a
callq 0x32f0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31a0
movl $0xd, %edx
movq %r15, %rdi
leaq 0x5966(%rip), %rsi      # 0xc12f
callq 0x32f0
movq 0x880b(%rip), %rdi      # 0xefe0
leaq -0x2c(%rbp), %rsi
callq 0x34c0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31a0
movl -0x2c(%rbp), %r13d
movq 0x60(%r14), %r12
movq 0x68(%r14), %rax
subq %r12, %rax
sarq $0x6, %rax
leaq 0x1(%rax), %rcx
cmpq %r13, %rcx
je 0x68f9
testq %r13, %r13
je 0x6833
cmpq %r13, %rax
jae 0x6903
leaq -0x88(%rbp), %rax
movq %rax, -0x98(%rbp)
leaq -0x98(%rbp), %rbx
movq %rbx, %rdi
leaq 0x5902(%rip), %rsi      # 0xc154
leaq 0x5917(%rip), %rdx      # 0xc170
callq 0x890c
leaq -0xc8(%rbp), %r12
movq %r12, -0xd8(%rbp)
leaq -0xd8(%rbp), %r13
movq %r13, %rdi
leaq 0x57cf(%rip), %rsi      # 0xc04c
leaq 0x57cd(%rip), %rdx      # 0xc051
callq 0x890c
movq %rbx, %rdi
movq %r13, %rsi
movl $0x23, %edx
movl $0x12c, %ecx            # imm = 0x12C
movl $0x1, %r8d
callq 0xb4c8
movq -0xd8(%rbp), %rdi
cmpq %r12, %rdi
je 0x68b5
callq 0x3260
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq %rax, %rdi
je 0x68cd
callq 0x3260
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31a0
jmp 0x66bc
movl $0x1, %eax
jmp 0x6d4c
decl %r13d
shlq $0x6, %r13
leaq -0x60(%rbp), %rax
movq %rax, -0x10(%rax)
movq (%r12,%r13), %rsi
movq 0x8(%r12,%r13), %rdx
addq %rsi, %rdx
leaq -0x70(%rbp), %rbx
movq %rbx, %rdi
callq 0x886e
movups 0x20(%r12,%r13), %xmm0
movups 0x30(%r12,%r13), %xmm1
movups %xmm1, 0x30(%rbx)
movups %xmm0, 0x20(%rbx)
leaq -0x260(%rbp), %rdi
callq 0x31b0
leaq -0x250(%rbp), %r15
leaq 0x5983(%rip), %rsi      # 0xc2db
movl $0x9, %edx
movq %r15, %rdi
callq 0x32f0
leaq 0x56d4(%rip), %rsi      # 0xc040
movl $0x5, %edx
movq %r15, %rdi
callq 0x32f0
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rdx
movq %r15, %rdi
callq 0x32f0
movq %rax, %rbx
leaq 0x56b9(%rip), %rsi      # 0xc04c
movl $0x5, %edx
movq %rax, %rdi
callq 0x32f0
leaq 0x5b3f(%rip), %rsi      # 0xc4e6
movl $0x1, %edx
movq %rbx, %rdi
callq 0x32f0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31a0
cmpl $0x0, -0x50(%rbp)
je 0x6a59
leaq 0x58fd(%rip), %rsi      # 0xc2e5
movl $0x16, %edx
movq %r15, %rdi
callq 0x32f0
leaq 0x5723(%rip), %rsi      # 0xc11f
movl $0x5, %edx
movq %r15, %rdi
callq 0x32f0
movl -0x50(%rbp), %esi
movq %r15, %rdi
callq 0x34b0
movq %rax, %rbx
leaq 0x562e(%rip), %rsi      # 0xc04c
movl $0x5, %edx
movq %rax, %rdi
callq 0x32f0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31a0
movl -0x50(%rbp), %eax
addl %eax, 0x20(%r14)
cmpl $0x0, -0x4c(%rbp)
je 0x6ad7
leaq 0x5896(%rip), %rsi      # 0xc2fc
movl $0x17, %edx
movq %r15, %rdi
callq 0x32f0
leaq 0x56a5(%rip), %rsi      # 0xc11f
movl $0x5, %edx
movq %r15, %rdi
callq 0x32f0
movl -0x4c(%rbp), %esi
movq %r15, %rdi
callq 0x34b0
movq %rax, %rbx
leaq 0x55b0(%rip), %rsi      # 0xc04c
movl $0x5, %edx
movq %rax, %rdi
callq 0x32f0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31a0
movl -0x4c(%rbp), %eax
addl %eax, 0x24(%r14)
cmpl $0x0, -0x48(%rbp)
je 0x6b6d
leaq 0x582c(%rip), %rsi      # 0xc314
movl $0xa, %edx
movq %r15, %rdi
callq 0x32f0
leaq 0x5623(%rip), %rsi      # 0xc11f
movl $0x5, %edx
movq %r15, %rdi
callq 0x32f0
movl -0x48(%rbp), %esi
movq %r15, %rdi
callq 0x34b0
movq %rax, %rbx
leaq 0x552e(%rip), %rsi      # 0xc04c
movl $0x5, %edx
movq %rax, %rdi
callq 0x32f0
leaq 0x57ed(%rip), %rsi      # 0xc31f
movl $0x6, %edx
movq %rbx, %rdi
callq 0x32f0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31a0
movl -0x48(%rbp), %eax
addl %eax, 0x2c(%r14)
cmpl $0x0, -0x44(%rbp)
je 0x6c03
leaq 0x5796(%rip), %rsi      # 0xc314
movl $0xa, %edx
movq %r15, %rdi
callq 0x32f0
leaq 0x558d(%rip), %rsi      # 0xc11f
movl $0x5, %edx
movq %r15, %rdi
callq 0x32f0
movl -0x44(%rbp), %esi
movq %r15, %rdi
callq 0x34b0
movq %rax, %rbx
leaq 0x5498(%rip), %rsi      # 0xc04c
movl $0x5, %edx
movq %rax, %rdi
callq 0x32f0
leaq 0x575e(%rip), %rsi      # 0xc326
movl $0x9, %edx
movq %rbx, %rdi
callq 0x32f0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31a0
movl -0x44(%rbp), %eax
addl %eax, 0x30(%r14)
cmpl $0x0, -0x40(%rbp)
je 0x6c99
leaq 0x5700(%rip), %rsi      # 0xc314
movl $0xa, %edx
movq %r15, %rdi
callq 0x32f0
leaq 0x54f7(%rip), %rsi      # 0xc11f
movl $0x5, %edx
movq %r15, %rdi
callq 0x32f0
movl -0x40(%rbp), %esi
movq %r15, %rdi
callq 0x34b0
movq %rax, %rbx
leaq 0x5402(%rip), %rsi      # 0xc04c
movl $0x5, %edx
movq %rax, %rdi
callq 0x32f0
leaq 0x55b1(%rip), %rsi      # 0xc20f
movl $0x4, %edx
movq %rbx, %rdi
callq 0x32f0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31a0
movl -0x40(%rbp), %eax
addl %eax, 0x34(%r14)
leaq -0x248(%rbp), %rsi
leaq -0xb8(%rbp), %rdi
callq 0x3440
movq -0xb8(%rbp), %rsi
movq -0xb0(%rbp), %rdx
movq 0x830f(%rip), %rdi      # 0xefd0
callq 0x32f0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31a0
leaq -0xa8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x6d05
callq 0x3260
movslq -0x34(%rbp), %rsi
shlq $0x6, %rsi
movq -0x78(%rbp), %rdi
addq (%rdi), %rsi
callq 0x8bf0
movq 0x8290(%rip), %rsi      # 0xefb0
leaq -0x260(%rbp), %rdi
callq 0x31d0
leaq -0x1e0(%rbp), %rdi
callq 0x30c0
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x6d4a
callq 0x3260
xorl %eax, %eax
addq $0x238, %rsp            # imm = 0x238
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x56cd(%rip), %rdi      # 0xc432
movq %r13, %rsi
xorl %eax, %eax
callq 0x3400
jmp 0x6dbb
jmp 0x6dbb
movq %rax, %rbx
jmp 0x6ddd
movq %rax, %rbx
leaq -0xa8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x6dbe
callq 0x3260
jmp 0x6dbe
movq %rax, %rbx
movq -0xd8(%rbp), %rdi
cmpq %r12, %rdi
je 0x6dab
callq 0x3260
jmp 0x6dab
movq %rax, %rbx
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
jmp 0x6de5
movq %rax, %rbx
movq 0x81eb(%rip), %rsi      # 0xefb0
leaq -0x260(%rbp), %rdi
callq 0x31d0
leaq -0x1e0(%rbp), %rdi
callq 0x30c0
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x6def
callq 0x3260
movq %rbx, %rdi
callq 0x34d0
nop