// File: malcolmyeh[P]CC3K/goblin.cc
// Function: Goblin::dealDamage[abi:cxx11](Character*)
std::string Goblin::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 (rand() % 2 == 0)
    {
        combatMsg = attacker + "'s attack missed. ";
        return combatMsg;
    }
    amount = ceil((100.0 / (100.0 + defense)) * attack);

    opponent->takeDamage((int)amount);

    combatMsg = attacker + " deals " + std::to_string((int)amount) + " damage to you (HP: " + std::to_string(opponent->getHP()) + "). ";

    if (rand() % 2 == 0 && opponent->getGold() >= 1)
    {
        opponent->updateGold(-1);
        combatMsg += attacker + " swipes 1 gold from you. (Gold: " + std::to_string(opponent->getGold()) + ")";
    }

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

    return combatMsg;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x240, %rsp            # imm = 0x240
movq %rdi, -0x220(%rbp)
movq %rdi, %rax
movq %rax, -0x218(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x210(%rbp)
movb $0x0, -0x21(%rbp)
callq 0x4280
movq -0x210(%rbp), %rsi
addq $0x18, %rsi
leaq -0x48(%rbp), %rdi
callq 0x40e0
jmp 0x152b2
movq -0x210(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x58(%rbp)
movq -0x18(%rbp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movl %eax, -0x224(%rbp)
jmp 0x152d4
movq -0x210(%rbp), %rax
movl -0x224(%rbp), %ecx
movl %ecx, -0x5c(%rbp)
testb $0x1, 0x39(%rax)
je 0x15359
movq -0x210(%rbp), %rax
movb $0x0, 0x39(%rax)
leaq 0x95aa(%rip), %rdx      # 0x1e8a6
leaq -0x80(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0xdac0
jmp 0x1530b
movq -0x220(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x4220
leaq -0x80(%rbp), %rdi
callq 0x4130
movb $0x1, -0x21(%rbp)
movl $0x1, -0x84(%rbp)
jmp 0x1577e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x157b6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x1578f
callq 0x4090
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x153b6
leaq 0x9542(%rip), %rdx      # 0x1e8b4
leaq -0xa8(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0xdac0
jmp 0x15384
movq -0x220(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x4220
leaq -0xa8(%rbp), %rdi
callq 0x4130
movb $0x1, -0x21(%rbp)
movl $0x1, -0x84(%rbp)
jmp 0x1577e
cvtsi2sdl -0x5c(%rbp), %xmm1
movsd 0x94a5(%rip), %xmm0     # 0x1e868
addsd %xmm0, %xmm1
divsd %xmm1, %xmm0
cvtsi2sdl -0x58(%rbp), %xmm1
mulsd %xmm1, %xmm0
callq 0x4050
movsd %xmm0, -0x20(%rbp)
movq -0x18(%rbp), %rdi
cvttsd2si -0x20(%rbp), %esi
movq (%rdi), %rax
movq 0x48(%rax), %rax
callq *%rax
jmp 0x153f2
leaq 0x94ce(%rip), %rdx      # 0x1e8c7
leaq -0x148(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0xdac0
jmp 0x1540b
cvttsd2si -0x20(%rbp), %esi
leaq -0x168(%rbp), %rdi
callq 0xdbe0
jmp 0x1541e
leaq -0x128(%rbp), %rdi
leaq -0x148(%rbp), %rsi
leaq -0x168(%rbp), %rdx
callq 0x11d30
jmp 0x1543a
leaq 0x948e(%rip), %rdx      # 0x1e8cf
leaq -0x108(%rbp), %rdi
leaq -0x128(%rbp), %rsi
callq 0xdb40
jmp 0x15456
movq -0x18(%rbp), %rdi
movq (%rdi), %rax
movq 0x18(%rax), %rax
callq *%rax
movl %eax, -0x228(%rbp)
jmp 0x1546b
movl -0x228(%rbp), %esi
leaq -0x188(%rbp), %rdi
callq 0xdbe0
jmp 0x1547f
leaq -0xe8(%rbp), %rdi
leaq -0x108(%rbp), %rsi
leaq -0x188(%rbp), %rdx
callq 0x11d30
jmp 0x1549b
leaq 0x966b(%rip), %rdx      # 0x1eb0d
leaq -0xc8(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0xdb40
jmp 0x154b7
movq -0x220(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x4220
leaq -0xc8(%rbp), %rdi
callq 0x4130
leaq -0xe8(%rbp), %rdi
callq 0x4130
leaq -0x188(%rbp), %rdi
callq 0x4130
leaq -0x108(%rbp), %rdi
callq 0x4130
leaq -0x128(%rbp), %rdi
callq 0x4130
leaq -0x168(%rbp), %rdi
callq 0x4130
leaq -0x148(%rbp), %rdi
callq 0x4130
callq 0x4090
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x15739
movq -0x18(%rbp), %rdi
movq (%rdi), %rax
movq 0x20(%rax), %rax
callq *%rax
movl %eax, -0x22c(%rbp)
jmp 0x15549
movl -0x22c(%rbp), %eax
cmpl $0x1, %eax
jl 0x15739
movq -0x18(%rbp), %rdi
movq (%rdi), %rax
movq (%rax), %rax
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq *%rax
jmp 0x1556b
leaq 0x951e(%rip), %rdx      # 0x1ea90
leaq -0x1e8(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0xdac0
jmp 0x15584
movq -0x18(%rbp), %rdi
movq (%rdi), %rax
movq 0x20(%rax), %rax
callq *%rax
movl %eax, -0x230(%rbp)
jmp 0x15599
movl -0x230(%rbp), %esi
leaq -0x208(%rbp), %rdi
callq 0xdbe0
jmp 0x155ad
leaq -0x1c8(%rbp), %rdi
leaq -0x1e8(%rbp), %rsi
leaq -0x208(%rbp), %rdx
callq 0x11d30
jmp 0x155c9
leaq 0x919b(%rip), %rdx      # 0x1e76b
leaq -0x1a8(%rbp), %rdi
leaq -0x1c8(%rbp), %rsi
callq 0xdb40
jmp 0x155e5
movq -0x220(%rbp), %rdi
leaq -0x1a8(%rbp), %rsi
callq 0x4240
jmp 0x155fa
leaq -0x1a8(%rbp), %rdi
callq 0x4130
leaq -0x1c8(%rbp), %rdi
callq 0x4130
leaq -0x208(%rbp), %rdi
callq 0x4130
leaq -0x1e8(%rbp), %rdi
callq 0x4130
jmp 0x15739
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x156c0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x156b4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x156a8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x1569c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x15690
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x4130
leaq -0x188(%rbp), %rdi
callq 0x4130
leaq -0x108(%rbp), %rdi
callq 0x4130
leaq -0x128(%rbp), %rdi
callq 0x4130
leaq -0x168(%rbp), %rdi
callq 0x4130
leaq -0x148(%rbp), %rdi
callq 0x4130
jmp 0x1578f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x1572b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x1571f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x15713
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x1a8(%rbp), %rdi
callq 0x4130
leaq -0x1c8(%rbp), %rdi
callq 0x4130
leaq -0x208(%rbp), %rdi
callq 0x4130
leaq -0x1e8(%rbp), %rdi
callq 0x4130
jmp 0x1578f
movq -0x18(%rbp), %rdi
movq (%rdi), %rax
movq 0x18(%rax), %rax
callq *%rax
movl %eax, -0x234(%rbp)
jmp 0x1574e
movl -0x234(%rbp), %eax
cmpl $0x0, %eax
jne 0x15770
movq -0x220(%rbp), %rdi
leaq 0x917d(%rip), %rsi      # 0x1e8e4
callq 0x41a0
jmp 0x1576e
jmp 0x15770
movb $0x1, -0x21(%rbp)
movl $0x1, -0x84(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x4130
testb $0x1, -0x21(%rbp)
jne 0x157a6
jmp 0x1579a
leaq -0x48(%rbp), %rdi
callq 0x4130
jmp 0x157b6
movq -0x220(%rbp), %rdi
callq 0x4130
movq -0x218(%rbp), %rax
addq $0x240, %rsp            # imm = 0x240
popq %rbp
retq
movq -0x220(%rbp), %rdi
callq 0x4130
movq -0x50(%rbp), %rdi
callq 0x42f0
nopl (%rax,%rax)