// File: /workspace/github_cpp_makefile_star2_O2/malcolmyeh[P]CC3K/dragon.cc
// Function: Dragon::dealDamage[abi:cxx11](Character*)
std::string Dragon::dealDamage(Character *opponent)
{
    double amount;
    std::string combatMsg;
    std::string attacker = this->race;
    int attack = this->Atk;
    int defense = opponent->getDef();
    if (this->stunned)
    {
        this->stunned = false;
        combatMsg = attacker + " is stunned. ";
        return combatMsg;
    }

    if (this->HP <= 50)
    {
        if (rand() % 2 == 0)
        {
            this->HP += 15;
            combatMsg += "Dragon's magical scales recovers 15 health (HP: " + std::to_string(this->HP) + "). ";
        }
    }

    if (rand() % 2 == 0)
    {
        combatMsg += attacker + "'s attack missed. ";
        return combatMsg;
    }


    amount = ceil((100.0 / (100.0 + defense)) * attack);

    if (rand() % 3 == 0)
    {
        amount *= 1.25;
        opponent->takeDamage((int)amount);
        combatMsg += attacker + " breathes fire, dealing " + std::to_string((int)amount) + " damage to you (HP: " + std::to_string(opponent->getHP()) + "). ";
    }
    else
    {
        opponent->takeDamage((int)amount);
        combatMsg += attacker + " deals " + std::to_string((int)amount) + " damage to you (HP: " + std::to_string(opponent->getHP()) + "). ";
    }

    if (opponent->getHP() == 0)
    {
        combatMsg += "You have been slain.";
    }

    return combatMsg;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rdi, %rbx
leaq 0x10(%rdi), %rax
movq %rax, (%rdi)
andq $0x0, 0x8(%rdi)
movq %rdx, %r14
movq %rsi, %r12
movb $0x0, 0x10(%rdi)
addq $0x18, %rsi
leaq -0x130(%rbp), %rdi
callq 0x4200
movl 0x8(%r12), %r13d
movq (%r14), %rax
movq %r14, %rdi
callq *0x10(%rax)
cmpb $0x1, 0x39(%r12)
jne 0xcff1
movb $0x0, 0x39(%r12)
leaq 0x395c(%rip), %rdx      # 0x10926
leaq -0x48(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0x848f
leaq -0x48(%rbp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x41d0
movq %r14, %rdi
jmp 0xd0a3
movl %eax, %r15d
cmpl $0x32, 0x10(%r12)
jg 0xd073
callq 0x4070
testb $0x1, %al
jne 0xd073
movl 0x10(%r12), %esi
addl $0xf, %esi
movl %esi, 0x10(%r12)
leaq -0x70(%rbp), %rdi
callq 0x851e
leaq 0x3d6e(%rip), %rsi      # 0x10d90
leaq -0x90(%rbp), %rdi
leaq -0x70(%rbp), %rdx
callq 0x84f0
leaq 0x3b8c(%rip), %rdx      # 0x10bc5
leaq -0x48(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x84c7
leaq -0x48(%rbp), %rsi
movq %rbx, %rdi
callq 0x42b0
leaq -0x48(%rbp), %rdi
callq 0x40e0
leaq -0x90(%rbp), %rdi
callq 0x40e0
leaq -0x70(%rbp), %rdi
callq 0x40e0
callq 0x4070
testb $0x1, %al
jne 0xd0c9
leaq 0x38b1(%rip), %rdx      # 0x10934
leaq -0x48(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0x848f
leaq -0x48(%rbp), %rsi
movq %rbx, %rdi
callq 0x42b0
leaq -0x48(%rbp), %rdi
callq 0x40e0
leaq -0x130(%rbp), %rdi
callq 0x40e0
movq %rbx, %rax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cvtsi2sd %r15d, %xmm0
movsd 0x3812(%rip), %xmm1     # 0x108e8
addsd %xmm1, %xmm0
divsd %xmm0, %xmm1
cvtsi2sd %r13d, %xmm0
mulsd %xmm1, %xmm0
callq 0x4030
movsd %xmm0, -0x50(%rbp)
callq 0x4070
pushq $0x3
popq %rcx
cltd
idivl %ecx
testl %edx, %edx
je 0xd1c6
cvttsd2si -0x50(%rbp), %r15d
movq (%r14), %rax
movq %r14, %rdi
movl %r15d, %esi
callq *0x48(%rax)
leaq 0x382a(%rip), %rdx      # 0x10947
leaq -0xf0(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0x848f
leaq -0xd0(%rbp), %rdi
movl %r15d, %esi
callq 0x851e
leaq -0x110(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
leaq -0xd0(%rbp), %rdx
callq 0x9190
leaq 0x37ef(%rip), %rdx      # 0x1094f
leaq -0x70(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x84c7
movq (%r14), %rax
movq %r14, %rdi
callq *0x18(%rax)
leaq -0xb0(%rbp), %rdi
movl %eax, %esi
callq 0x851e
leaq -0x90(%rbp), %rdi
leaq -0x70(%rbp), %rsi
leaq -0xb0(%rbp), %rdx
callq 0x9190
leaq 0x3a20(%rip), %rdx      # 0x10bc5
leaq -0x48(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x84c7
leaq -0x48(%rbp), %rsi
movq %rbx, %rdi
callq 0x42b0
jmp 0xd28f
movsd -0x50(%rbp), %xmm0
mulsd 0x39ad(%rip), %xmm0     # 0x10b80
cvttsd2si %xmm0, %r15d
movq (%r14), %rax
movq %r14, %rdi
movl %r15d, %esi
callq *0x48(%rax)
leaq 0x3bd6(%rip), %rdx      # 0x10dc1
leaq -0xf0(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0x848f
leaq -0xd0(%rbp), %rdi
movl %r15d, %esi
callq 0x851e
leaq -0x110(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
leaq -0xd0(%rbp), %rdx
callq 0x9190
leaq 0x3721(%rip), %rdx      # 0x1094f
leaq -0x70(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x84c7
movq (%r14), %rax
movq %r14, %rdi
callq *0x18(%rax)
leaq -0xb0(%rbp), %rdi
movl %eax, %esi
callq 0x851e
leaq -0x90(%rbp), %rdi
leaq -0x70(%rbp), %rsi
leaq -0xb0(%rbp), %rdx
callq 0x9190
leaq 0x3952(%rip), %rdx      # 0x10bc5
leaq -0x48(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x84c7
leaq -0x48(%rbp), %rsi
movq %rbx, %rdi
callq 0x42b0
leaq -0x48(%rbp), %rdi
callq 0x40e0
leaq -0x90(%rbp), %rdi
callq 0x40e0
leaq -0xb0(%rbp), %rdi
callq 0x40e0
leaq -0x70(%rbp), %rdi
callq 0x40e0
leaq -0x110(%rbp), %rdi
callq 0x40e0
leaq -0xd0(%rbp), %rdi
callq 0x40e0
leaq -0xf0(%rbp), %rdi
callq 0x40e0
movq (%r14), %rax
movq %r14, %rdi
callq *0x18(%rax)
testl %eax, %eax
jne 0xd0a8
leaq 0x366f(%rip), %rsi      # 0x10964
movq %rbx, %rdi
callq 0x4290
jmp 0xd0a8
jmp 0xd340
jmp 0xd34e
jmp 0xd35f
jmp 0xd370
jmp 0xd375
jmp 0xd37a
jmp 0xd3c7
movq %rax, %r14
leaq -0x48(%rbp), %rdi
callq 0x40e0
jmp 0xd324
movq %rax, %r14
leaq -0x90(%rbp), %rdi
callq 0x40e0
jmp 0xd335
movq %rax, %r14
leaq -0x70(%rbp), %rdi
jmp 0xd3b9
jmp 0xd3c7
movq %rax, %r14
leaq -0x48(%rbp), %rdi
callq 0x40e0
jmp 0xd351
movq %rax, %r14
leaq -0x90(%rbp), %rdi
callq 0x40e0
jmp 0xd362
movq %rax, %r14
leaq -0xb0(%rbp), %rdi
callq 0x40e0
jmp 0xd391
movq %rax, %r14
jmp 0xd39a
movq %rax, %r14
jmp 0xd3a6
movq %rax, %r14
jmp 0xd3b2
jmp 0xd3c7
jmp 0xd38e
movq %rax, %r14
leaq -0x48(%rbp), %rdi
jmp 0xd3b9
jmp 0xd3c7
movq %rax, %r14
leaq -0x70(%rbp), %rdi
callq 0x40e0
leaq -0x110(%rbp), %rdi
callq 0x40e0
leaq -0xd0(%rbp), %rdi
callq 0x40e0
leaq -0xf0(%rbp), %rdi
callq 0x40e0
jmp 0xd3ca
jmp 0xd3c7
movq %rax, %r14
jmp 0xd3d6
movq %rax, %r14
leaq -0x130(%rbp), %rdi
callq 0x40e0
movq %rbx, %rdi
callq 0x40e0
movq %r14, %rdi
callq 0x4280
nop