// File: /workspace/github_cpp_makefile_star2_O3/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 $0x218, %rsp            # imm = 0x218
cmpb $0x0, 0xd8(%rdi)
je 0x3d01
movl $0x3e8, %edi            # imm = 0x3E8
callq 0xb5bd
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdi, %rbx
leaq -0x98(%rbp), %r15
cmpb $0x1, 0xd9(%rbx)
jne 0x3d41
movq %rbx, %rdi
callq 0x4544
decl %eax
cmpl $0x3, %eax
ja 0x3f20
leaq 0x82d6(%rip), %rcx      # 0xc004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rbx, %rdi
callq 0x4770
jmp 0x3d63
movq %rbx, %rdi
callq 0x4770
xorb $0x1, 0xd9(%rbx)
cmpb $0x0, 0xd8(%rbx)
je 0x3d0b
jmp 0x3ce5
movq %rbx, %rdi
callq 0x6696
testl %eax, %eax
jne 0x3d50
jmp 0x3d49
movl 0x34(%rbx), %r12d
leaq -0x240(%rbp), %rdi
callq 0x9e13
movl -0x20c(%rbp), %r13d
leaq -0x1e0(%rbp), %rdi
callq 0x86a2
leaq -0x1f8(%rbp), %rdi
callq 0x864a
movq -0x240(%rbp), %rdi
leaq -0x230(%rbp), %rax
cmpq %rax, %rdi
je 0x3db0
callq 0x3260
movl %r13d, %eax
shrl $0x1f, %eax
addl %r13d, %eax
sarl %eax
cmpl %eax, %r12d
movl $0x4b, %r12d
movl $0x20, %eax
cmovll %eax, %r12d
callq 0x3090
cltq
imulq $0x51eb851f, %rax, %rcx # imm = 0x51EB851F
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x25, %rcx
addl %edx, %ecx
imull $0x64, %ecx, %ecx
subl %ecx, %eax
cmpl %r12d, %eax
jge 0x3fca
leaq -0x198(%rbp), %rax
movq %rax, -0x1a8(%rbp)
leaq -0x1a8(%rbp), %r14
movq %r14, %rdi
leaq 0x827f(%rip), %rsi      # 0xc094
leaq 0x8292(%rip), %rdx      # 0xc0ae
callq 0x890c
leaq -0x178(%rbp), %rax
movq %rax, -0x188(%rbp)
leaq -0x188(%rbp), %r12
movq %r12, %rdi
leaq 0x820c(%rip), %rsi      # 0xc04c
leaq 0x820a(%rip), %rdx      # 0xc051
callq 0x890c
movq %r14, %rdi
movq %r12, %rsi
movl $0x23, %edx
movl $0x12c, %ecx            # imm = 0x12C
movl $0x1, %r8d
callq 0xb4c8
leaq -0x98(%rbp), %r15
movq -0x188(%rbp), %rdi
leaq -0x178(%rbp), %rax
cmpq %rax, %rdi
je 0x3e86
callq 0x3260
movq -0x1a8(%rbp), %rdi
leaq -0x198(%rbp), %rax
cmpq %rax, %rdi
je 0x3e9e
callq 0x3260
movb $0x1, 0xd8(%rbx)
movq %rbx, %rdi
callq 0x6df8
jmp 0x3d50
movb $0x1, 0xda(%rbx)
leaq -0x78(%rbp), %rax
movq %rax, -0x88(%rbp)
leaq -0x88(%rbp), %r13
movq %r13, %rdi
leaq 0x818e(%rip), %rsi      # 0xc063
leaq 0x8194(%rip), %rdx      # 0xc070
callq 0x890c
movq %r13, %rdi
leaq 0x8155(%rip), %rsi      # 0xc040
callq 0x3520
movq %r15, -0xa8(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x406d
movq %rdx, -0xa8(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x98(%rbp)
jmp 0x4074
leaq -0x118(%rbp), %rax
movq %rax, -0x128(%rbp)
leaq -0x108(%rbp), %r13
leaq -0x128(%rbp), %r14
movq %r14, %rdi
leaq 0x8192(%rip), %rsi      # 0xc0d8
leaq 0x81a8(%rip), %rdx      # 0xc0f5
callq 0x890c
leaq -0xf8(%rbp), %rax
movq %rax, -0x108(%rbp)
movq %r13, %rdi
leaq 0x80e2(%rip), %rsi      # 0xc04c
leaq 0x80e0(%rip), %rdx      # 0xc051
callq 0x890c
movq %r14, %rdi
movq %r13, %rsi
movl $0x23, %edx
movl $0x12c, %ecx            # imm = 0x12C
movl $0x1, %r8d
callq 0xb4c8
movq -0x108(%rbp), %rdi
leaq -0xf8(%rbp), %rax
cmpq %rax, %rdi
je 0x3fa9
callq 0x3260
movq -0x128(%rbp), %rdi
leaq -0x118(%rbp), %rax
cmpq %rax, %rdi
je 0x3d50
callq 0x3260
jmp 0x3d50
leaq -0x158(%rbp), %rax
movq %rax, -0x168(%rbp)
leaq -0x168(%rbp), %r14
movq %r14, %rdi
leaq 0x80c6(%rip), %rsi      # 0xc0af
leaq 0x80e7(%rip), %rdx      # 0xc0d7
callq 0x890c
leaq -0x138(%rbp), %rax
movq %rax, -0x148(%rbp)
leaq -0x148(%rbp), %r12
movq %r12, %rdi
leaq 0x8038(%rip), %rsi      # 0xc04c
leaq 0x8036(%rip), %rdx      # 0xc051
callq 0x890c
movq %r14, %rdi
movq %r12, %rsi
movl $0x23, %edx
movl $0x12c, %ecx            # imm = 0x12C
movl $0x1, %r8d
callq 0xb4c8
leaq -0x98(%rbp), %r15
movq -0x148(%rbp), %rdi
leaq -0x138(%rbp), %rax
cmpq %rax, %rdi
je 0x405a
callq 0x3260
movq -0x168(%rbp), %rdi
leaq -0x158(%rbp), %rax
jmp 0x4394
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movq 0x8(%rax), %rdx
movq %rdx, -0xa0(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq -0xd8(%rbp), %rax
movq %rax, -0xe8(%rbp)
leaq -0xe8(%rbp), %rdi
leaq 0x7fc7(%rip), %rsi      # 0xc071
leaq 0x7fc7(%rip), %rdx      # 0xc078
callq 0x890c
movq -0xa8(%rbp), %rcx
movl $0xf, %edi
cmpq %r15, %rcx
je 0x40ce
movq -0x98(%rbp), %rdi
movq -0xa0(%rbp), %r8
movq -0xe8(%rbp), %rsi
movq -0xe0(%rbp), %rdx
leaq (%rdx,%r8), %rax
cmpq %rdi, %rax
jbe 0x4109
movl $0xf, %edi
leaq -0xd8(%rbp), %r9
cmpq %r9, %rsi
je 0x4104
movq -0xd8(%rbp), %rdi
cmpq %rdi, %rax
jbe 0x4117
leaq -0xa8(%rbp), %rdi
callq 0x30b0
jmp 0x4127
leaq -0xe8(%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x32e0
leaq -0x38(%rbp), %rsi
movq %rsi, -0x48(%rbp)
movq (%rax), %rdx
leaq 0x10(%rax), %rcx
cmpq %rcx, %rdx
je 0x4148
movq %rdx, -0x48(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x38(%rbp)
jmp 0x414e
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, -0x40(%rbp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
leaq -0x48(%rbp), %rdi
leaq 0x7ed7(%rip), %rsi      # 0xc04c
callq 0x3520
leaq -0x230(%rbp), %rsi
movq %rsi, -0x240(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x41aa
movq %rdx, -0x240(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x230(%rbp)
jmp 0x41b0
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, -0x238(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq -0xb8(%rbp), %rax
movq %rax, -0xc8(%rbp)
leaq -0xc8(%rbp), %rdi
leaq 0x7e93(%rip), %rsi      # 0xc079
leaq 0x7ea6(%rip), %rdx      # 0xc093
callq 0x890c
movq -0x240(%rbp), %rcx
movl $0xf, %edi
leaq -0x230(%rbp), %rax
cmpq %rax, %rcx
je 0x4211
movq -0x230(%rbp), %rdi
movq -0x238(%rbp), %r8
movq -0xc8(%rbp), %rsi
movq -0xc0(%rbp), %rdx
leaq (%rdx,%r8), %rax
cmpq %rdi, %rax
jbe 0x424c
movl $0xf, %edi
leaq -0xb8(%rbp), %r9
cmpq %r9, %rsi
je 0x4247
movq -0xb8(%rbp), %rdi
cmpq %rdi, %rax
jbe 0x425a
leaq -0x240(%rbp), %rdi
callq 0x30b0
jmp 0x426a
leaq -0xc8(%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x32e0
leaq -0x58(%rbp), %rsi
movq %rsi, -0x68(%rbp)
movq (%rax), %rdx
leaq 0x10(%rax), %rcx
cmpq %rcx, %rdx
je 0x428b
movq %rdx, -0x68(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x58(%rbp)
jmp 0x4291
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, -0x60(%rbp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
leaq -0x1b8(%rbp), %rax
movq %rax, -0x1c8(%rbp)
leaq -0x1c8(%rbp), %r13
movq %r13, %rdi
leaq 0x7d80(%rip), %rsi      # 0xc04c
leaq 0x7d7e(%rip), %rdx      # 0xc051
callq 0x890c
leaq -0x68(%rbp), %rdi
movq %r13, %rsi
movl $0x23, %edx
movl $0x12c, %ecx            # imm = 0x12C
movl $0x1, %r8d
callq 0xb4c8
movq -0x1c8(%rbp), %rdi
leaq -0x1b8(%rbp), %rax
cmpq %rax, %rdi
je 0x430c
callq 0x3260
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x431e
callq 0x3260
movq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rax
cmpq %rax, %rdi
je 0x4336
callq 0x3260
movq -0x240(%rbp), %rdi
leaq -0x230(%rbp), %rax
cmpq %rax, %rdi
je 0x434e
callq 0x3260
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x4360
callq 0x3260
movq -0xe8(%rbp), %rdi
leaq -0xd8(%rbp), %rax
cmpq %rax, %rdi
je 0x4378
callq 0x3260
movq -0xa8(%rbp), %rdi
cmpq %r15, %rdi
je 0x4389
callq 0x3260
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x3d49
callq 0x3260
jmp 0x3d49
movq %rax, %rbx
movq -0x188(%rbp), %rdi
leaq -0x178(%rbp), %rax
cmpq %rax, %rdi
je 0x43c7
callq 0x3260
jmp 0x43c7
movq %rax, %rbx
movq -0x1a8(%rbp), %rdi
leaq -0x198(%rbp), %rax
jmp 0x4435
movq %rax, %rbx
movq -0x148(%rbp), %rdi
leaq -0x138(%rbp), %rax
cmpq %rax, %rdi
je 0x43f7
callq 0x3260
jmp 0x43f7
movq %rax, %rbx
movq -0x168(%rbp), %rdi
leaq -0x158(%rbp), %rax
jmp 0x4435
movq %rax, %rbx
movq -0x108(%rbp), %rdi
leaq -0xf8(%rbp), %rax
cmpq %rax, %rdi
je 0x4427
callq 0x3260
jmp 0x4427
movq %rax, %rbx
movq -0x128(%rbp), %rdi
leaq -0x118(%rbp), %rax
cmpq %rax, %rdi
jne 0x4531
jmp 0x4536
leaq -0x78(%rbp), %r12
movq %rax, %rbx
movq -0x1c8(%rbp), %rdi
leaq -0x1b8(%rbp), %rax
cmpq %rax, %rdi
je 0x446b
callq 0x3260
jmp 0x446b
leaq -0x78(%rbp), %r12
movq %rax, %rbx
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x4486
callq 0x3260
jmp 0x4486
leaq -0x78(%rbp), %r12
movq %rax, %rbx
movq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rax
cmpq %rax, %rdi
je 0x44a7
callq 0x3260
jmp 0x44a7
leaq -0x78(%rbp), %r12
movq %rax, %rbx
movq -0x240(%rbp), %rdi
leaq -0x230(%rbp), %rax
cmpq %rax, %rdi
je 0x44c8
callq 0x3260
jmp 0x44c8
leaq -0x78(%rbp), %r12
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x44e3
callq 0x3260
jmp 0x44e3
leaq -0x78(%rbp), %r12
movq %rax, %rbx
movq -0xe8(%rbp), %rdi
leaq -0xd8(%rbp), %rax
cmpq %rax, %rdi
je 0x4504
callq 0x3260
jmp 0x4504
leaq -0x78(%rbp), %r12
movq %rax, %rbx
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0x4525
callq 0x3260
jmp 0x4525
leaq -0x78(%rbp), %r12
movq %rax, %rbx
movq -0x88(%rbp), %rdi
cmpq %r12, %rdi
je 0x4536
callq 0x3260
movq %rbx, %rdi
callq 0x34d0
movq %rax, %rbx
jmp 0x4536
nop