// File: /workspace/github_cpp_makefile_star2_O2/Agusyc[P]CTRPG/src/battle.cpp
// Function: Battle::loop()
void Battle::loop() {
    // Run this loop until the user loses or wins
    while (!over) {
        if (playerTurn) {
            // Checks the user response from the menu
            switch(showMenu()) {
            case 1:
                if (attack() == 1) {
                    continue;
                }
                break;
            case 2:
                defending = true;
                printMessage(string("You use your ") + YELLOW + string("shield ") + WHITE + string("to, like, defend yourself."));
                break;
            case 3:
                if (useItem() == 1) {
                    continue;
                }
                break;
            case 4:
                int chance;
                // If player has more than 50 % of his health
                if (player.hp >= (parsePlayer().hp / 2)) {
                    chance = 75; // 75% chance of fleeing
                } else {
                    chance = 32; // 32% chance of fleeing
                }
                // See if the player flees or not
                if (rand() % 100 < chance) {
                    printMessage("You escape... You chicken!");
                    over = true;
                    writeItems();
                    continue;
                } else {
                    printMessage("You tried to escape... But you couldn't!");
                }
                break;
            default:
                printMessage("That is not a valid option...");
                continue;
            }
        } else {
            // The enemy attacks
            attack();
        }
        // Pass to the next turn
        playerTurn = !playerTurn;
    }

    clearScreen();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x228, %rsp            # imm = 0x228
movq %rdi, %rbx
leaq -0x248(%rbp), %r15
leaq 0x5661(%rip), %r13      # 0x904c
cmpb $0x0, 0xd8(%rbx)
jne 0x3cea
cmpb $0x1, 0xd9(%rbx)
jne 0x3a2e
movq %rbx, %rdi
callq 0x3e00
decl %eax
cmpl $0x3, %eax
ja 0x3c22
leaq 0x55e9(%rip), %rcx      # 0x9004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rbx, %rdi
callq 0x3f28
jmp 0x3a43
movq %rbx, %rdi
callq 0x3f28
jmp 0x3cde
movq %rbx, %rdi
callq 0x516e
testl %eax, %eax
jne 0x39eb
jmp 0x3cde
movq %r13, %r12
movl 0x34(%rbx), %r13d
movq %r15, %rdi
callq 0x7de5
movl -0x214(%rbp), %eax
cltd
pushq $0x2
popq %rcx
idivl %ecx
movl %eax, %r14d
movq %r15, %rdi
callq 0x6090
cmpl %r14d, %r13d
pushq $0x4b
popq %r14
pushq $0x20
popq %rax
cmovll %eax, %r14d
callq 0x3080
cltd
pushq $0x64
popq %rcx
idivl %ecx
cmpl %r14d, %edx
jge 0x3c81
leaq -0xd0(%rbp), %rdi
leaq 0x55f2(%rip), %rsi      # 0x9094
movq %r15, %rdx
callq 0x30c0
leaq -0x50(%rbp), %rdx
movq %r12, %r13
leaq -0x1b0(%rbp), %r12
movq %r12, %rdi
movq %r13, %rsi
callq 0x30c0
leaq -0xd0(%rbp), %r14
movq %r14, %rdi
movq %r12, %rsi
pushq $0x23
popq %rdx
movl $0x12c, %ecx            # imm = 0x12C
pushq $0x1
popq %r8
callq 0x8e78
movq %r12, %rdi
callq 0x3100
movq %r14, %rdi
callq 0x3100
movb $0x1, 0xd8(%rbx)
movq %rbx, %rdi
callq 0x55ca
jmp 0x39eb
movb $0x1, 0xda(%rbx)
leaq -0x130(%rbp), %r12
movq %r12, %rdi
leaq 0x5546(%rip), %rsi      # 0x9063
leaq -0x2c(%rbp), %rdx
callq 0x30c0
leaq -0x70(%rbp), %rdi
movq %r12, %rsi
leaq 0x550c(%rip), %rdx      # 0x9040
callq 0x612a
leaq -0x110(%rbp), %r14
movq %r14, %rdi
leaq 0x5527(%rip), %rsi      # 0x9071
leaq -0x2b(%rbp), %rdx
callq 0x30c0
leaq -0x50(%rbp), %r12
movq %r12, %rdi
leaq -0x70(%rbp), %rsi
movq %r14, %rdx
callq 0x60b9
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x612a
leaq -0xf0(%rbp), %r14
movq %r14, %rdi
leaq 0x54f4(%rip), %rsi      # 0x9079
leaq -0x2a(%rbp), %rdx
callq 0x30c0
leaq -0x150(%rbp), %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x60b9
leaq -0x1d0(%rbp), %r12
movq %r12, %rdi
movq %r13, %rsi
leaq -0x29(%rbp), %rdx
callq 0x30c0
leaq -0x150(%rbp), %r14
movq %r14, %rdi
movq %r12, %rsi
pushq $0x23
popq %rdx
movl $0x12c, %ecx            # imm = 0x12C
pushq $0x1
popq %r8
callq 0x8e78
movq %r12, %rdi
callq 0x3100
movq %r14, %rdi
callq 0x3100
leaq -0xf0(%rbp), %rdi
callq 0x3100
movq %r15, %rdi
callq 0x3100
leaq -0x50(%rbp), %rdi
callq 0x3100
leaq -0x110(%rbp), %rdi
callq 0x3100
leaq -0x70(%rbp), %rdi
callq 0x3100
leaq -0x130(%rbp), %rdi
jmp 0x3cd9
leaq -0x90(%rbp), %rdi
leaq 0x54a8(%rip), %rsi      # 0x90d8
movq %r15, %rdx
callq 0x30c0
leaq -0x170(%rbp), %r12
movq %r12, %rdi
movq %r13, %rsi
leaq -0x50(%rbp), %rdx
callq 0x30c0
leaq -0x90(%rbp), %r14
movq %r14, %rdi
movq %r12, %rsi
pushq $0x23
popq %rdx
movl $0x12c, %ecx            # imm = 0x12C
pushq $0x1
popq %r8
callq 0x8e78
movq %r12, %rdi
callq 0x3100
movq %r14, %rdi
callq 0x3100
jmp 0x39eb
leaq -0xb0(%rbp), %rdi
leaq 0x5420(%rip), %rsi      # 0x90af
movq %r15, %rdx
callq 0x30c0
leaq -0x50(%rbp), %rdx
movq %r12, %r13
leaq -0x190(%rbp), %r12
movq %r12, %rdi
movq %r13, %rsi
callq 0x30c0
leaq -0xb0(%rbp), %r14
movq %r14, %rdi
movq %r12, %rsi
pushq $0x23
popq %rdx
movl $0x12c, %ecx            # imm = 0x12C
pushq $0x1
popq %r8
callq 0x8e78
movq %r12, %rdi
callq 0x3100
movq %r14, %rdi
callq 0x3100
xorb $0x1, 0xd9(%rbx)
jmp 0x39eb
movl $0x3e8, %edi            # imm = 0x3E8
callq 0x8f3b
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x1b0(%rbp), %rdi
callq 0x3100
jmp 0x3d1a
movq %rax, %rbx
leaq -0xd0(%rbp), %rdi
jmp 0x3dde
jmp 0x3df4
movq %rax, %rbx
leaq -0x190(%rbp), %rdi
callq 0x3100
jmp 0x3d3f
movq %rax, %rbx
leaq -0xb0(%rbp), %rdi
jmp 0x3dde
jmp 0x3df4
movq %rax, %rbx
leaq -0x170(%rbp), %rdi
callq 0x3100
jmp 0x3d64
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
jmp 0x3dde
jmp 0x3df4
movq %rax, %rbx
leaq -0x1d0(%rbp), %rdi
callq 0x3100
jmp 0x3d86
movq %rax, %rbx
leaq -0x150(%rbp), %rdi
callq 0x3100
jmp 0x3d97
movq %rax, %rbx
leaq -0xf0(%rbp), %rdi
callq 0x3100
jmp 0x3da8
movq %rax, %rbx
leaq -0x248(%rbp), %rdi
callq 0x3100
jmp 0x3db9
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x3100
leaq -0x110(%rbp), %rdi
callq 0x3100
leaq -0x70(%rbp), %rdi
callq 0x3100
leaq -0x130(%rbp), %rdi
callq 0x3100
jmp 0x3df7
movq %rax, %rbx
jmp 0x3dc2
movq %rax, %rbx
jmp 0x3dce
movq %rax, %rbx
jmp 0x3dd7
movq %rax, %rbx
movq %rbx, %rdi
callq 0x3490
nop