// File: /workspace/github_cpp_makefile_star2_O2/malcolmyeh[P]CC3K/troll.cc
// Function: Troll::dealDamage[abi:cxx11](Character*)
std::string Troll::dealDamage(Character *opponent)
{
    double amount;
    double secondHit;

    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 (rand() % 2 == 0)
    {
        combatMsg = attacker + "'s attack missed. ";
        return combatMsg;
    }

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

    if (rand() % 3 == 0)
    {
        //double hits player
        combatMsg = attacker + " strikes you twice for " + std::to_string((int)amount) + " + " + std::to_string((int)secondHit) + " damage (HP: " + std::to_string(opponent->getHP()) + "). ";
        opponent->takeDamage((int)(amount + secondHit));
    }
    else if (rand() % 3 == 1)
    {
        //hurts itself with second hit
        combatMsg = attacker + " deals " + std::to_string((int)amount) + " damage to you (HP: " + std::to_string(opponent->getHP()) + "). ";
        combatMsg += attacker + " hurts itself in confusion for " + std::to_string((int)secondHit) + " damage. (HP: " + std::to_string(this->HP) + "). ";
        opponent->takeDamage((int)amount);
        this->takeDamage((int)secondHit);
    }
    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 $0x178, %rsp            # imm = 0x178
movq %rdi, %rbx
leaq 0x10(%rdi), %rax
movq %rax, (%rdi)
andq $0x0, 0x8(%rdi)
movq %rdx, %r14
movq %rsi, %r15
movb $0x0, 0x10(%rdi)
addq $0x18, %rsi
leaq -0x138(%rbp), %rdi
callq 0x4200
movl 0x8(%r15), %r13d
movq (%r14), %rax
movq %r14, %rdi
callq *0x10(%rax)
cmpb $0x1, 0x39(%r15)
jne 0xbb34
movb $0x0, 0x39(%r15)
leaq 0x4e07(%rip), %rdx      # 0x10926
leaq -0x118(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x848f
jmp 0xbb5a
movl %eax, %r12d
callq 0x4070
testb $0x1, %al
jne 0xbb95
leaq 0x4ded(%rip), %rdx      # 0x10934
leaq -0x118(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x848f
leaq -0x118(%rbp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x41d0
movq %r14, %rdi
callq 0x40e0
leaq -0x138(%rbp), %rdi
callq 0x40e0
movq %rbx, %rax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cvtsi2sd %r12d, %xmm0
movsd 0x4d46(%rip), %xmm1     # 0x108e8
addsd %xmm1, %xmm0
divsd %xmm0, %xmm1
cvtsi2sd %r13d, %xmm0
mulsd %xmm1, %xmm0
callq 0x4030
movsd 0x5050(%rip), %xmm1     # 0x10c10
movsd %xmm0, -0x30(%rbp)
mulsd %xmm0, %xmm1
movsd %xmm1, -0x38(%rbp)
callq 0x4070
pushq $0x3
popq %r12
cltd
idivl %r12d
testl %edx, %edx
je 0xbdfc
callq 0x4070
cltd
idivl %r12d
cmpl $0x1, %edx
jne 0xbf82
leaq 0x4d4b(%rip), %rdx      # 0x10947
leaq -0x98(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x848f
cvttsd2si -0x30(%rbp), %r12d
leaq -0x78(%rbp), %rdi
movl %r12d, %esi
callq 0x851e
leaq -0xb8(%rbp), %rdi
leaq -0x98(%rbp), %rsi
leaq -0x78(%rbp), %rdx
callq 0x9190
leaq 0x4d10(%rip), %rdx      # 0x1094f
leaq -0xd8(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x84c7
movq (%r14), %rax
movq %r14, %rdi
callq *0x18(%rax)
leaq -0x58(%rbp), %rdi
movl %eax, %esi
callq 0x851e
leaq -0xf8(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
leaq -0x58(%rbp), %rdx
callq 0x9190
leaq 0x4f41(%rip), %rdx      # 0x10bc5
leaq -0x118(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x84c7
leaq -0x118(%rbp), %r13
movq %rbx, %rdi
movq %r13, %rsi
callq 0x41d0
movq %r13, %rdi
callq 0x40e0
leaq -0xf8(%rbp), %rdi
callq 0x40e0
leaq -0x58(%rbp), %rdi
callq 0x40e0
leaq -0xd8(%rbp), %rdi
callq 0x40e0
leaq -0xb8(%rbp), %rdi
callq 0x40e0
leaq -0x78(%rbp), %rdi
callq 0x40e0
leaq -0x98(%rbp), %rdi
callq 0x40e0
leaq 0x4f40(%rip), %rdx      # 0x10c3a
leaq -0x98(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x848f
cvttsd2si -0x38(%rbp), %r13d
leaq -0x78(%rbp), %rdi
movl %r13d, %esi
callq 0x851e
leaq -0xb8(%rbp), %rdi
leaq -0x98(%rbp), %rsi
leaq -0x78(%rbp), %rdx
callq 0x9190
leaq 0x4f1d(%rip), %rdx      # 0x10c5a
leaq -0xd8(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x84c7
movl 0x10(%r15), %esi
leaq -0x58(%rbp), %rdi
callq 0x851e
leaq -0xf8(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
leaq -0x58(%rbp), %rdx
callq 0x9190
leaq 0x4e4a(%rip), %rdx      # 0x10bc5
leaq -0x118(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x84c7
leaq -0x118(%rbp), %rsi
movq %rbx, %rdi
callq 0x42b0
leaq -0x118(%rbp), %rdi
callq 0x40e0
leaq -0xf8(%rbp), %rdi
callq 0x40e0
leaq -0x58(%rbp), %rdi
callq 0x40e0
leaq -0xd8(%rbp), %rdi
callq 0x40e0
leaq -0xb8(%rbp), %rdi
callq 0x40e0
leaq -0x78(%rbp), %rdi
callq 0x40e0
leaq -0x98(%rbp), %rdi
callq 0x40e0
movq (%r14), %rax
movq %r14, %rdi
movl %r12d, %esi
callq *0x48(%rax)
jmp 0xbf71
leaq 0x4e1b(%rip), %rdx      # 0x10c1e
leaq -0x58(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x848f
cvttsd2si -0x30(%rbp), %esi
leaq -0x198(%rbp), %rdi
callq 0x851e
leaq -0x78(%rbp), %rdi
leaq -0x58(%rbp), %rsi
leaq -0x198(%rbp), %rdx
callq 0x9190
leaq 0x4df7(%rip), %rdx      # 0x10c36
leaq -0x98(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x84c7
cvttsd2si -0x38(%rbp), %esi
leaq -0x178(%rbp), %rdi
callq 0x851e
leaq -0xb8(%rbp), %rdi
leaq -0x98(%rbp), %rsi
leaq -0x178(%rbp), %rdx
callq 0x9190
leaq 0x4804(%rip), %rdx      # 0x10685
leaq -0xd8(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x84c7
movq (%r14), %rax
movq %r14, %rdi
callq *0x18(%rax)
leaq -0x158(%rbp), %rdi
movl %eax, %esi
callq 0x851e
leaq -0xf8(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
leaq -0x158(%rbp), %rdx
callq 0x9190
leaq 0x4cf9(%rip), %rdx      # 0x10bc5
leaq -0x118(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x84c7
leaq -0x118(%rbp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x41d0
movq %r15, %rdi
callq 0x40e0
leaq -0xf8(%rbp), %rdi
callq 0x40e0
leaq -0x158(%rbp), %rdi
callq 0x40e0
leaq -0xd8(%rbp), %rdi
callq 0x40e0
leaq -0xb8(%rbp), %rdi
callq 0x40e0
leaq -0x178(%rbp), %rdi
callq 0x40e0
leaq -0x98(%rbp), %rdi
callq 0x40e0
leaq -0x78(%rbp), %rdi
callq 0x40e0
leaq -0x198(%rbp), %rdi
callq 0x40e0
leaq -0x58(%rbp), %rdi
callq 0x40e0
movsd -0x30(%rbp), %xmm0
addsd -0x38(%rbp), %xmm0
cvttsd2si %xmm0, %r13d
movq %r14, %r15
movq (%r15), %rax
movq %r15, %rdi
movl %r13d, %esi
callq *0x48(%rax)
jmp 0xc08c
cvttsd2si -0x30(%rbp), %r15d
movq (%r14), %rax
movq %r14, %rdi
movl %r15d, %esi
callq *0x48(%rax)
leaq 0x49ac(%rip), %rdx      # 0x10947
leaq -0x98(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x848f
leaq -0x78(%rbp), %rdi
movl %r15d, %esi
callq 0x851e
leaq -0xb8(%rbp), %rdi
leaq -0x98(%rbp), %rsi
leaq -0x78(%rbp), %rdx
callq 0x9190
leaq 0x4977(%rip), %rdx      # 0x1094f
leaq -0xd8(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x84c7
movq (%r14), %rax
movq %r14, %rdi
callq *0x18(%rax)
leaq -0x58(%rbp), %rdi
movl %eax, %esi
callq 0x851e
leaq -0xf8(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
leaq -0x58(%rbp), %rdx
callq 0x9190
leaq 0x4ba8(%rip), %rdx      # 0x10bc5
leaq -0x118(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x84c7
leaq -0x118(%rbp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x41d0
movq %r15, %rdi
callq 0x40e0
leaq -0xf8(%rbp), %rdi
callq 0x40e0
leaq -0x58(%rbp), %rdi
callq 0x40e0
leaq -0xd8(%rbp), %rdi
callq 0x40e0
leaq -0xb8(%rbp), %rdi
callq 0x40e0
leaq -0x78(%rbp), %rdi
callq 0x40e0
leaq -0x98(%rbp), %rdi
callq 0x40e0
movq (%r14), %rax
movq %r14, %rdi
callq *0x18(%rax)
testl %eax, %eax
jne 0xbb74
leaq 0x48c0(%rip), %rsi      # 0x10964
movq %rbx, %rdi
callq 0x4290
jmp 0xbb74
movq %rax, %r14
leaq -0x118(%rbp), %rdi
callq 0x40e0
jmp 0xc0dd
jmp 0xc0da
jmp 0xc0eb
jmp 0xc15f
jmp 0xc0fd
jmp 0xc104
jmp 0xc10e
jmp 0xc0da
jmp 0xc1e8
jmp 0xc0eb
movq %rax, %r14
leaq -0xf8(%rbp), %rdi
callq 0x40e0
jmp 0xc0ee
movq %rax, %r14
leaq -0x58(%rbp), %rdi
callq 0x40e0
jmp 0xc162
jmp 0xc0fd
jmp 0xc104
movq %rax, %r14
jmp 0xc16e
jmp 0xc10e
movq %rax, %r14
jmp 0xc17a
jmp 0xc1e8
movq %rax, %r14
jmp 0xc183
jmp 0xc1e8
movq %rax, %r14
leaq -0xf8(%rbp), %rdi
callq 0x40e0
jmp 0xc12c
movq %rax, %r14
leaq -0x158(%rbp), %rdi
callq 0x40e0
jmp 0xc18f
movq %rax, %r14
jmp 0xc19b
movq %rax, %r14
jmp 0xc1a7
movq %rax, %r14
jmp 0xc1b3
movq %rax, %r14
jmp 0xc1bf
movq %rax, %r14
jmp 0xc1c8
movq %rax, %r14
jmp 0xc1d4
jmp 0xc1e8
jmp 0xc15f
movq %rax, %r14
leaq -0xd8(%rbp), %rdi
callq 0x40e0
leaq -0xb8(%rbp), %rdi
callq 0x40e0
leaq -0x78(%rbp), %rdi
callq 0x40e0
leaq -0x98(%rbp), %rdi
jmp 0xc1d8
movq %rax, %r14
leaq -0xd8(%rbp), %rdi
callq 0x40e0
leaq -0xb8(%rbp), %rdi
callq 0x40e0
leaq -0x178(%rbp), %rdi
callq 0x40e0
leaq -0x98(%rbp), %rdi
callq 0x40e0
leaq -0x78(%rbp), %rdi
callq 0x40e0
leaq -0x198(%rbp), %rdi
callq 0x40e0
leaq -0x58(%rbp), %rdi
callq 0x40e0
jmp 0xc1eb
jmp 0xc1e8
jmp 0xc1e8
movq %rax, %r14
jmp 0xc1f7
movq %rax, %r14
leaq -0x138(%rbp), %rdi
callq 0x40e0
movq %rbx, %rdi
callq 0x40e0
movq %r14, %rdi
callq 0x4280
nop