// File: /workspace/github_cpp_makefile_star2_O1/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 0x3d05
movl $0x3e8, %edi            # imm = 0x3E8
callq 0xb621
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 0x3d45
movq %rbx, %rdi
callq 0x4550
decl %eax
cmpl $0x3, %eax
ja 0x3f24
leaq 0x82d2(%rip), %rcx      # 0xc004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rbx, %rdi
callq 0x477c
jmp 0x3d67
movq %rbx, %rdi
callq 0x477c
xorb $0x1, 0xd9(%rbx)
cmpb $0x0, 0xd8(%rbx)
je 0x3d0f
jmp 0x3ce9
movq %rbx, %rdi
callq 0x6700
testl %eax, %eax
jne 0x3d54
jmp 0x3d4d
movl 0x34(%rbx), %r12d
leaq -0x240(%rbp), %rdi
callq 0x9e63
movl -0x20c(%rbp), %r13d
leaq -0x1e0(%rbp), %rdi
callq 0x86f8
leaq -0x1f8(%rbp), %rdi
callq 0x86aa
movq -0x240(%rbp), %rdi
leaq -0x230(%rbp), %rax
cmpq %rax, %rdi
je 0x3db4
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 0x3fce
leaq -0x198(%rbp), %rax
movq %rax, -0x1a8(%rbp)
leaq -0x1a8(%rbp), %r14
movq %r14, %rdi
leaq 0x827b(%rip), %rsi      # 0xc094
leaq 0x828e(%rip), %rdx      # 0xc0ae
callq 0x894a
leaq -0x178(%rbp), %rax
movq %rax, -0x188(%rbp)
leaq -0x188(%rbp), %r12
movq %r12, %rdi
leaq 0x8208(%rip), %rsi      # 0xc04c
leaq 0x8206(%rip), %rdx      # 0xc051
callq 0x894a
movq %r14, %rdi
movq %r12, %rsi
movl $0x23, %edx
movl $0x12c, %ecx            # imm = 0x12C
movl $0x1, %r8d
callq 0xb52c
leaq -0x98(%rbp), %r15
movq -0x188(%rbp), %rdi
leaq -0x178(%rbp), %rax
cmpq %rax, %rdi
je 0x3e8a
callq 0x3260
movq -0x1a8(%rbp), %rdi
leaq -0x198(%rbp), %rax
cmpq %rax, %rdi
je 0x3ea2
callq 0x3260
movb $0x1, 0xd8(%rbx)
movq %rbx, %rdi
callq 0x6e80
jmp 0x3d54
movb $0x1, 0xda(%rbx)
leaq -0x78(%rbp), %rax
movq %rax, -0x88(%rbp)
leaq -0x88(%rbp), %r13
movq %r13, %rdi
leaq 0x818a(%rip), %rsi      # 0xc063
leaq 0x8190(%rip), %rdx      # 0xc070
callq 0x894a
movq %r13, %rdi
leaq 0x8151(%rip), %rsi      # 0xc040
callq 0x3520
movq %r15, -0xa8(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x4071
movq %rdx, -0xa8(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x98(%rbp)
jmp 0x4078
leaq -0x118(%rbp), %rax
movq %rax, -0x128(%rbp)
leaq -0x108(%rbp), %r13
leaq -0x128(%rbp), %r14
movq %r14, %rdi
leaq 0x818e(%rip), %rsi      # 0xc0d8
leaq 0x81a4(%rip), %rdx      # 0xc0f5
callq 0x894a
leaq -0xf8(%rbp), %rax
movq %rax, -0x108(%rbp)
movq %r13, %rdi
leaq 0x80de(%rip), %rsi      # 0xc04c
leaq 0x80dc(%rip), %rdx      # 0xc051
callq 0x894a
movq %r14, %rdi
movq %r13, %rsi
movl $0x23, %edx
movl $0x12c, %ecx            # imm = 0x12C
movl $0x1, %r8d
callq 0xb52c
movq -0x108(%rbp), %rdi
leaq -0xf8(%rbp), %rax
cmpq %rax, %rdi
je 0x3fad
callq 0x3260
movq -0x128(%rbp), %rdi
leaq -0x118(%rbp), %rax
cmpq %rax, %rdi
je 0x3d54
callq 0x3260
jmp 0x3d54
leaq -0x158(%rbp), %rax
movq %rax, -0x168(%rbp)
leaq -0x168(%rbp), %r14
movq %r14, %rdi
leaq 0x80c2(%rip), %rsi      # 0xc0af
leaq 0x80e3(%rip), %rdx      # 0xc0d7
callq 0x894a
leaq -0x138(%rbp), %rax
movq %rax, -0x148(%rbp)
leaq -0x148(%rbp), %r12
movq %r12, %rdi
leaq 0x8034(%rip), %rsi      # 0xc04c
leaq 0x8032(%rip), %rdx      # 0xc051
callq 0x894a
movq %r14, %rdi
movq %r12, %rsi
movl $0x23, %edx
movl $0x12c, %ecx            # imm = 0x12C
movl $0x1, %r8d
callq 0xb52c
leaq -0x98(%rbp), %r15
movq -0x148(%rbp), %rdi
leaq -0x138(%rbp), %rax
cmpq %rax, %rdi
je 0x405e
callq 0x3260
movq -0x168(%rbp), %rdi
leaq -0x158(%rbp), %rax
jmp 0x43a0
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 0x7fc3(%rip), %rsi      # 0xc071
leaq 0x7fc3(%rip), %rdx      # 0xc078
callq 0x894a
movq -0xa8(%rbp), %rcx
movl $0xf, %esi
cmpq %r15, %rcx
je 0x40d2
movq -0x98(%rbp), %rsi
movq -0xa0(%rbp), %r8
movq -0xe0(%rbp), %rdx
leaq (%rdx,%r8), %rax
cmpq %rsi, %rax
jbe 0x410a
movl $0xf, %esi
leaq -0xd8(%rbp), %rdi
cmpq %rdi, -0xe8(%rbp)
je 0x4105
movq -0xd8(%rbp), %rsi
cmpq %rsi, %rax
jbe 0x411f
movq -0xe8(%rbp), %rsi
leaq -0xa8(%rbp), %rdi
callq 0x30b0
jmp 0x412f
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 0x4150
movq %rdx, -0x48(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x38(%rbp)
jmp 0x4156
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 0x7ecf(%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 0x41b2
movq %rdx, -0x240(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x230(%rbp)
jmp 0x41b8
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 0x7e8b(%rip), %rsi      # 0xc079
leaq 0x7e9e(%rip), %rdx      # 0xc093
callq 0x894a
movq -0x240(%rbp), %rcx
movl $0xf, %esi
leaq -0x230(%rbp), %rax
cmpq %rax, %rcx
je 0x4219
movq -0x230(%rbp), %rsi
movq -0x238(%rbp), %r8
movq -0xc0(%rbp), %rdx
leaq (%rdx,%r8), %rax
cmpq %rsi, %rax
jbe 0x4251
movl $0xf, %esi
leaq -0xb8(%rbp), %rdi
cmpq %rdi, -0xc8(%rbp)
je 0x424c
movq -0xb8(%rbp), %rsi
cmpq %rsi, %rax
jbe 0x4266
movq -0xc8(%rbp), %rsi
leaq -0x240(%rbp), %rdi
callq 0x30b0
jmp 0x4276
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 0x4297
movq %rdx, -0x68(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x58(%rbp)
jmp 0x429d
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 0x7d74(%rip), %rsi      # 0xc04c
leaq 0x7d72(%rip), %rdx      # 0xc051
callq 0x894a
leaq -0x68(%rbp), %rdi
movq %r13, %rsi
movl $0x23, %edx
movl $0x12c, %ecx            # imm = 0x12C
movl $0x1, %r8d
callq 0xb52c
movq -0x1c8(%rbp), %rdi
leaq -0x1b8(%rbp), %rax
cmpq %rax, %rdi
je 0x4318
callq 0x3260
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x432a
callq 0x3260
movq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rax
cmpq %rax, %rdi
je 0x4342
callq 0x3260
movq -0x240(%rbp), %rdi
leaq -0x230(%rbp), %rax
cmpq %rax, %rdi
je 0x435a
callq 0x3260
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x436c
callq 0x3260
movq -0xe8(%rbp), %rdi
leaq -0xd8(%rbp), %rax
cmpq %rax, %rdi
je 0x4384
callq 0x3260
movq -0xa8(%rbp), %rdi
cmpq %r15, %rdi
je 0x4395
callq 0x3260
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x3d4d
callq 0x3260
jmp 0x3d4d
movq %rax, %rbx
movq -0x188(%rbp), %rdi
leaq -0x178(%rbp), %rax
cmpq %rax, %rdi
je 0x43d3
callq 0x3260
jmp 0x43d3
movq %rax, %rbx
movq -0x1a8(%rbp), %rdi
leaq -0x198(%rbp), %rax
jmp 0x4441
movq %rax, %rbx
movq -0x148(%rbp), %rdi
leaq -0x138(%rbp), %rax
cmpq %rax, %rdi
je 0x4403
callq 0x3260
jmp 0x4403
movq %rax, %rbx
movq -0x168(%rbp), %rdi
leaq -0x158(%rbp), %rax
jmp 0x4441
movq %rax, %rbx
movq -0x108(%rbp), %rdi
leaq -0xf8(%rbp), %rax
cmpq %rax, %rdi
je 0x4433
callq 0x3260
jmp 0x4433
movq %rax, %rbx
movq -0x128(%rbp), %rdi
leaq -0x118(%rbp), %rax
cmpq %rax, %rdi
jne 0x453d
jmp 0x4542
leaq -0x78(%rbp), %r12
movq %rax, %rbx
movq -0x1c8(%rbp), %rdi
leaq -0x1b8(%rbp), %rax
cmpq %rax, %rdi
je 0x4477
callq 0x3260
jmp 0x4477
leaq -0x78(%rbp), %r12
movq %rax, %rbx
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x4492
callq 0x3260
jmp 0x4492
leaq -0x78(%rbp), %r12
movq %rax, %rbx
movq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rax
cmpq %rax, %rdi
je 0x44b3
callq 0x3260
jmp 0x44b3
leaq -0x78(%rbp), %r12
movq %rax, %rbx
movq -0x240(%rbp), %rdi
leaq -0x230(%rbp), %rax
cmpq %rax, %rdi
je 0x44d4
callq 0x3260
jmp 0x44d4
leaq -0x78(%rbp), %r12
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x44ef
callq 0x3260
jmp 0x44ef
leaq -0x78(%rbp), %r12
movq %rax, %rbx
movq -0xe8(%rbp), %rdi
leaq -0xd8(%rbp), %rax
cmpq %rax, %rdi
je 0x4510
callq 0x3260
jmp 0x4510
leaq -0x78(%rbp), %r12
movq %rax, %rbx
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0x4531
callq 0x3260
jmp 0x4531
leaq -0x78(%rbp), %r12
movq %rax, %rbx
movq -0x88(%rbp), %rdi
cmpq %r12, %rdi
je 0x4542
callq 0x3260
movq %rbx, %rdi
callq 0x34d0
movq %rax, %rbx
jmp 0x4542
nop