// File: /workspace/github_cpp_makefile_star2_O1/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, %rbx
movq 0x68(%rbx), %rsi
movq 0x60(%rbx), %rax
subq %rax, %rsi
je 0x67ce
movl $0x1, %r14d
xorl %r12d, %r12d
movl %r14d, %r13d
movq 0x8895(%rip), %rdi      # 0xefd0
movq %r13, %rsi
callq 0x3190
movq %rax, %r15
movl $0x2, %edx
movq %rax, %rdi
leaq 0x59f2(%rip), %rsi      # 0xc147
callq 0x32f0
movq 0x60(%rbx), %rax
movq 0x68(%rbx), %rdx
subq %rax, %rdx
sarq $0x6, %rdx
cmpq %r12, %rdx
jbe 0x6ddd
shlq $0x6, %r12
movq (%rax,%r12), %rsi
movq 0x8(%rax,%r12), %rdx
movq %r15, %rdi
callq 0x32f0
movq %rax, %r15
movq (%rax), %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
movq 0x68(%rbx), %rsi
subq 0x60(%rbx), %rsi
sarq $0x6, %rsi
incl %r14d
movq %r13, %r12
cmpq %r13, %rsi
ja 0x6731
jmp 0x67d2
sarq $0x6, %rsi
incq %rsi
movq 0x87f4(%rip), %r14      # 0xefd0
movq %r14, %rdi
callq 0x3190
movq %rax, %r15
movl $0x9, %edx
movq %rax, %rdi
leaq 0x5954(%rip), %rsi      # 0xc14a
callq 0x32f0
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 $0xd, %edx
movq %r14, %rdi
leaq 0x58fe(%rip), %rsi      # 0xc12f
callq 0x32f0
movq 0x87a3(%rip), %rdi      # 0xefe0
leaq -0x2c(%rbp), %rsi
callq 0x34c0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31a0
movq 0x68(%rbx), %rax
subq 0x60(%rbx), %rax
movl -0x2c(%rbp), %ecx
sarq $0x6, %rax
leaq 0x1(%rax), %rdx
cmpq %rcx, %rdx
je 0x695e
testq %rcx, %rcx
je 0x6897
cmpq %rcx, %rax
jae 0x6968
leaq -0x80(%rbp), %rax
movq %rax, -0x90(%rbp)
leaq -0x90(%rbp), %r15
movq %r15, %rdi
leaq 0x58a1(%rip), %rsi      # 0xc154
leaq 0x58b6(%rip), %rdx      # 0xc170
callq 0x894a
leaq -0xc0(%rbp), %r14
movq %r14, -0xd0(%rbp)
leaq -0xd0(%rbp), %r12
movq %r12, %rdi
leaq 0x576e(%rip), %rsi      # 0xc04c
leaq 0x576c(%rip), %rdx      # 0xc051
callq 0x894a
movq %r15, %rdi
movq %r12, %rsi
movl $0x23, %edx
movl $0x12c, %ecx            # imm = 0x12C
movl $0x1, %r8d
callq 0xb52c
movq -0xd0(%rbp), %rdi
cmpq %r14, %rdi
je 0x6916
callq 0x3260
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x692b
callq 0x3260
movq 0x869e(%rip), %r14      # 0xefd0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31a0
jmp 0x6717
movl $0x1, %eax
jmp 0x6dcb
movl -0x2c(%rbp), %r14d
decl %r14d
movq 0x60(%rbx), %r13
movq 0x68(%rbx), %rdx
subq %r13, %rdx
sarq $0x6, %rdx
cmpq %r14, %rdx
jbe 0x6dee
shlq $0x6, %r14
leaq -0x60(%rbp), %r12
movq %r12, -0x10(%r12)
movq (%r13,%r14), %rsi
movq 0x8(%r13,%r14), %rdx
addq %rsi, %rdx
leaq -0x70(%rbp), %r15
movq %r15, %rdi
callq 0x88b0
movups 0x20(%r13,%r14), %xmm0
movups 0x30(%r13,%r14), %xmm1
movups %xmm1, 0x30(%r15)
movups %xmm0, 0x20(%r15)
leaq -0x258(%rbp), %rdi
callq 0x31b0
leaq -0x248(%rbp), %r14
leaq 0x58fe(%rip), %rsi      # 0xc2db
movl $0x9, %edx
movq %r14, %rdi
callq 0x32f0
leaq 0x564f(%rip), %rsi      # 0xc040
movl $0x5, %edx
movq %r14, %rdi
callq 0x32f0
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rdx
movq %r14, %rdi
callq 0x32f0
movq %rax, %r15
leaq 0x5634(%rip), %rsi      # 0xc04c
movl $0x5, %edx
movq %rax, %rdi
callq 0x32f0
leaq 0x5aba(%rip), %rsi      # 0xc4e6
movl $0x1, %edx
movq %r15, %rdi
callq 0x32f0
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
cmpl $0x0, -0x50(%rbp)
je 0x6add
leaq 0x5878(%rip), %rsi      # 0xc2e5
movl $0x16, %edx
movq %r14, %rdi
callq 0x32f0
leaq 0x569e(%rip), %rsi      # 0xc11f
movl $0x5, %edx
movq %r14, %rdi
callq 0x32f0
movl -0x50(%rbp), %esi
movq %r14, %rdi
callq 0x34b0
movq %rax, %r15
leaq 0x55a9(%rip), %rsi      # 0xc04c
movl $0x5, %edx
movq %rax, %rdi
callq 0x32f0
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 -0x50(%rbp), %eax
addl %eax, 0x20(%rbx)
cmpl $0x0, -0x4c(%rbp)
je 0x6b5a
leaq 0x5812(%rip), %rsi      # 0xc2fc
movl $0x17, %edx
movq %r14, %rdi
callq 0x32f0
leaq 0x5621(%rip), %rsi      # 0xc11f
movl $0x5, %edx
movq %r14, %rdi
callq 0x32f0
movl -0x4c(%rbp), %esi
movq %r14, %rdi
callq 0x34b0
movq %rax, %r15
leaq 0x552c(%rip), %rsi      # 0xc04c
movl $0x5, %edx
movq %rax, %rdi
callq 0x32f0
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 -0x4c(%rbp), %eax
addl %eax, 0x24(%rbx)
cmpl $0x0, -0x48(%rbp)
je 0x6bef
leaq 0x57a9(%rip), %rsi      # 0xc314
movl $0xa, %edx
movq %r14, %rdi
callq 0x32f0
leaq 0x55a0(%rip), %rsi      # 0xc11f
movl $0x5, %edx
movq %r14, %rdi
callq 0x32f0
movl -0x48(%rbp), %esi
movq %r14, %rdi
callq 0x34b0
movq %rax, %r15
leaq 0x54ab(%rip), %rsi      # 0xc04c
movl $0x5, %edx
movq %rax, %rdi
callq 0x32f0
leaq 0x576a(%rip), %rsi      # 0xc31f
movl $0x6, %edx
movq %r15, %rdi
callq 0x32f0
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 -0x48(%rbp), %eax
addl %eax, 0x2c(%rbx)
cmpl $0x0, -0x44(%rbp)
je 0x6c84
leaq 0x5714(%rip), %rsi      # 0xc314
movl $0xa, %edx
movq %r14, %rdi
callq 0x32f0
leaq 0x550b(%rip), %rsi      # 0xc11f
movl $0x5, %edx
movq %r14, %rdi
callq 0x32f0
movl -0x44(%rbp), %esi
movq %r14, %rdi
callq 0x34b0
movq %rax, %r15
leaq 0x5416(%rip), %rsi      # 0xc04c
movl $0x5, %edx
movq %rax, %rdi
callq 0x32f0
leaq 0x56dc(%rip), %rsi      # 0xc326
movl $0x9, %edx
movq %r15, %rdi
callq 0x32f0
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 -0x44(%rbp), %eax
addl %eax, 0x30(%rbx)
cmpl $0x0, -0x40(%rbp)
je 0x6d19
leaq 0x567f(%rip), %rsi      # 0xc314
movl $0xa, %edx
movq %r14, %rdi
callq 0x32f0
leaq 0x5476(%rip), %rsi      # 0xc11f
movl $0x5, %edx
movq %r14, %rdi
callq 0x32f0
movl -0x40(%rbp), %esi
movq %r14, %rdi
callq 0x34b0
movq %rax, %r14
leaq 0x5381(%rip), %rsi      # 0xc04c
movl $0x5, %edx
movq %rax, %rdi
callq 0x32f0
leaq 0x5530(%rip), %rsi      # 0xc20f
movl $0x4, %edx
movq %r14, %rdi
callq 0x32f0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31a0
movl -0x40(%rbp), %eax
addl %eax, 0x34(%rbx)
leaq -0x240(%rbp), %rsi
leaq -0xb0(%rbp), %rdi
callq 0x3440
movq -0xb0(%rbp), %rsi
movq -0xa8(%rbp), %rdx
movq 0x828f(%rip), %rdi      # 0xefd0
callq 0x32f0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31a0
addq $0x60, %rbx
leaq -0xa0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x6d89
callq 0x3260
movslq -0x34(%rbp), %rsi
shlq $0x6, %rsi
addq (%rbx), %rsi
movq %rbx, %rdi
callq 0x8c46
movq 0x820d(%rip), %rsi      # 0xefb0
leaq -0x258(%rbp), %rdi
callq 0x31d0
leaq -0x1d8(%rbp), %rdi
callq 0x30c0
movq -0x70(%rbp), %rdi
cmpq %r12, %rdi
je 0x6dc9
callq 0x3260
xorl %eax, %eax
addq $0x238, %rsp            # imm = 0x238
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x564e(%rip), %rdi      # 0xc432
movq %r12, %rsi
xorl %eax, %eax
callq 0x3400
leaq 0x563d(%rip), %rdi      # 0xc432
movq %r14, %rsi
jmp 0x6de7
jmp 0x6e53
jmp 0x6e53
movq %rax, %rbx
jmp 0x6e75
movq %rax, %rbx
leaq -0xa0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x6e56
callq 0x3260
jmp 0x6e56
movq %rax, %rbx
movq -0xd0(%rbp), %rdi
cmpq %r14, %rdi
je 0x6e36
callq 0x3260
jmp 0x6e36
movq %rax, %rbx
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x6e4b
callq 0x3260
movq %rbx, %rdi
callq 0x34d0
movq %rax, %rbx
movq 0x8153(%rip), %rsi      # 0xefb0
leaq -0x258(%rbp), %rdi
callq 0x31d0
leaq -0x1d8(%rbp), %rdi
callq 0x30c0
movq -0x70(%rbp), %rdi
cmpq %r12, %rdi
jne 0x6e46
jmp 0x6e4b