// File: /workspace/github_cpp_makefile_star2_O1/Serfati[P]Heroes-of-Might-and-Magic-3/Hero.cpp
// Function: Hero::attackEnemy(Hero&)
bool Hero::attackEnemy(Hero &enemy) {
    int attackCount,defendCount;
    double ratio,howMuchToDelete;
    string attack,toAttack,line;
    Creature c;
    if ( ! enemy.army->isDestroyed() && ! army->isDestroyed()) {
        cout << this->getName() << "'s turn:" << endl;
        /* -~=[  Gets creature to attack and creature to defend  ]~=- */
        do {
            try {
                if ( std::cin.peek() == '\n' )
                    std::cin.ignore();
                getline(cin , line);
                stringstream ss(line);
                ss >> attack >> toAttack;
                if ( enemy.army->getArmyList()[c.creaTypeByName(toAttack)] < 1 ||
                     this->army->getArmyList()[c.creaTypeByName(attack)] < 1 )
                    throw std::invalid_argument("Creature to attack not found! try again.");
            }
            catch( std::invalid_argument &e ) {
                cout << e.what() << endl;
            }
        } while ( enemy.army->getArmyList()[c.creaTypeByName(toAttack)] < 1 ||
                  this->army->getArmyList()[c.creaTypeByName(attack)] < 1 );

        /* -~=[  Battle | Update | Save | Show and Return   ]=~- */

        //attack!
        ratio = (army->getRealArmy()[c.creaTypeByName(attack)]->attackAnother(
                *enemy.army->getRealArmy()[c.creaTypeByName(toAttack)]));
        attackCount = army->getArmyList()[c.creaTypeByName(attack)];
        defendCount = enemy.army->getArmyList()[c.creaTypeByName(toAttack)];
        howMuchToDelete = floor(ratio * attackCount);

        //delete destroyed and update
        int x = int(howMuchToDelete >= defendCount ? 0 : (defendCount - howMuchToDelete));
        enemy.army->setAtArmyList(c.creaTypeByName(toAttack),x);

        //reset creatures details
        army->reBuild();
        enemy.army->reBuild();
        //saves
        save();
        enemy.save();
        //SHOW
        if ( !enemy.army->isDestroyed() && !army->isDestroyed()) {
            enemy.showHeroFight();
            this->showHeroFight();
        }
        return enemy.attackEnemy(*this);
    }
    /* -~=[  Check if Eliminated  ]=~- */
    if ( army->isDestroyed()) {

        cout << "victorious" << endl;
        enemy.addGold(this->getGold());
        isAlive = false;
        this->rmdir();
        return 1;
    }
    if ( enemy.army->isDestroyed()) {
        cout << "You have been perished" << endl;
        this->addGold(enemy.getGold());
        enemy.isAlive = false;
        enemy.rmdir();
        return 0;
    }
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x338, %rsp            # imm = 0x338
movq %rsi, %rbx
movq %rdi, -0x38(%rbp)
leaq -0x70(%rbp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq -0x50(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq -0x128(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq -0xf8(%rbp), %rdi
callq 0x9ee0
movq %rbx, -0x40(%rbp)
movq 0x40(%rbx), %rdi
callq 0x7188
testb %al, %al
jne 0x8a08
movq -0x38(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x7188
testb %al, %al
je 0x8b24
movq -0x38(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x7188
testb %al, %al
je 0x8a98
movq 0x75a0(%rip), %rbx      # 0xffc0
leaq 0x2cfd(%rip), %rsi      # 0xb724
movl $0xa, %edx
movq %rbx, %rdi
callq 0x32d0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %esi
movq 0x756e(%rip), %rdi      # 0xffc0
callq 0x3030
movq %rax, %rdi
callq 0x31b0
movq -0x40(%rbp), %rcx
cmpb $0x1, 0x3a(%rcx)
jne 0x8a84
movq -0x38(%rbp), %rax
movsd 0x30(%rax), %xmm0
addsd 0x30(%rcx), %xmm0
minsd 0x2bf1(%rip), %xmm0     # 0xb670
movsd %xmm0, 0x30(%rcx)
movq -0x38(%rbp), %rdi
movb $0x0, 0x3a(%rdi)
movb $0x1, %bl
callq 0x9710
jmp 0x91cb
movq -0x40(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x7188
testb %al, %al
je 0x8b1d
movq 0x7510(%rip), %rbx      # 0xffc0
leaq 0x2c78(%rip), %rsi      # 0xb72f
movl $0x16, %edx
movq %rbx, %rdi
callq 0x32d0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %esi
movq 0x74de(%rip), %rdi      # 0xffc0
callq 0x3030
movq %rax, %rdi
callq 0x31b0
movq -0x38(%rbp), %rax
cmpb $0x1, 0x3a(%rax)
movq -0x40(%rbp), %rdi
jne 0x8b14
movsd 0x30(%rdi), %xmm0
addsd 0x30(%rax), %xmm0
minsd 0x2b61(%rip), %xmm0     # 0xb670
movsd %xmm0, 0x30(%rax)
movb $0x0, 0x3a(%rdi)
callq 0x9710
xorl %ebx, %ebx
jmp 0x91cb
leaq -0x350(%rbp), %r15
movq %r15, -0x10(%r15)
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rsi
movq 0x10(%rax), %rdx
addq %rsi, %rdx
leaq -0x360(%rbp), %rdi
callq 0x693a
movq -0x360(%rbp), %rsi
movq -0x358(%rbp), %rdx
movq 0x7461(%rip), %rdi      # 0xffc0
callq 0x32d0
movq %rax, %rbx
leaq 0x2b84(%rip), %rsi      # 0xb6f2
movl $0x8, %edx
movq %rax, %rdi
callq 0x32d0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31b0
movq -0x360(%rbp), %rdi
cmpq %r15, %rdi
je 0x8bbd
movq -0x350(%rbp), %rsi
incq %rsi
callq 0x3290
movq 0x741c(%rip), %r12      # 0xffe0
leaq -0x360(%rbp), %r15
leaq -0xf8(%rbp), %r13
movq %r12, %rdi
callq 0x30f0
cmpl $0xa, %eax
jne 0x8be7
movq %r12, %rdi
callq 0x3440
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %edx
movq %r12, %rdi
leaq -0x138(%rbp), %rsi
callq 0x3450
movq %r15, %rdi
leaq -0x138(%rbp), %rsi
movl $0x18, %edx
callq 0x3380
movq %r15, %rdi
leaq -0x80(%rbp), %rsi
callq 0x3300
movq %rax, %rdi
leaq -0x60(%rbp), %rsi
callq 0x3300
movq -0x40(%rbp), %rax
movq 0x40(%rax), %rbx
leaq -0xd0(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
addq %rsi, %rdx
leaq -0xe0(%rbp), %rdi
callq 0x693a
movq %r13, %rdi
leaq -0xe0(%rbp), %rsi
callq 0xa126
cltq
movq (%rbx), %rcx
movl (%rcx,%rax,4), %ebx
testl %ebx, %ebx
jle 0x8ccd
movq -0x38(%rbp), %rax
movq 0x40(%rax), %r14
leaq -0xb0(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdx
addq %rsi, %rdx
leaq -0xc0(%rbp), %rdi
callq 0x693a
movq %r13, %rdi
leaq -0xc0(%rbp), %rsi
callq 0xa126
cltq
movq (%r14), %rcx
cmpl $0x0, (%rcx,%rax,4)
setle %r14b
jmp 0x8cd0
movb $0x1, %r14b
testl %ebx, %ebx
jle 0x8cf6
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
cmpq %rax, %rdi
je 0x8cf6
movq -0xb0(%rbp), %rsi
incq %rsi
callq 0x3290
movq -0xe0(%rbp), %rdi
leaq -0xd0(%rbp), %rax
cmpq %rax, %rdi
je 0x8d18
movq -0xd0(%rbp), %rsi
incq %rsi
callq 0x3290
testb %r14b, %r14b
jne 0x8e27
movq %r15, %rdi
movq 0x7275(%rip), %rsi      # 0xffa0
callq 0x31e0
leaq -0x2e0(%rbp), %rdi
callq 0x30d0
movq -0x40(%rbp), %rax
movq 0x40(%rax), %rbx
leaq -0x108(%rbp), %rax
movq %rax, -0x118(%rbp)
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
addq %rsi, %rdx
leaq -0x118(%rbp), %r14
movq %r14, %rdi
callq 0x693a
movq %r13, %rdi
movq %r14, %rsi
callq 0xa126
cltq
movq (%rbx), %rcx
movl (%rcx,%rax,4), %ebx
testl %ebx, %ebx
jle 0x8dce
movq -0x38(%rbp), %rax
movq 0x40(%rax), %r14
leaq -0x90(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdx
addq %rsi, %rdx
leaq -0xa0(%rbp), %rdi
callq 0x693a
movq %r13, %rdi
leaq -0xa0(%rbp), %rsi
callq 0xa126
cltq
movq (%r14), %rcx
cmpl $0x0, (%rcx,%rax,4)
setle %r14b
jmp 0x8dd1
movb $0x1, %r14b
testl %ebx, %ebx
jle 0x8df7
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x8df7
movq -0x90(%rbp), %rsi
incq %rsi
callq 0x3290
movq -0x118(%rbp), %rdi
leaq -0x108(%rbp), %rax
cmpq %rax, %rdi
je 0x8e19
movq -0x108(%rbp), %rsi
incq %rsi
callq 0x3290
testb %r14b, %r14b
jne 0x8bd2
jmp 0x8f2e
movl $0x10, %edi
callq 0x3140
movq %rax, %r14
movq %rax, %rdi
leaq 0x28bd(%rip), %rsi      # 0xb6fb
callq 0x3460
movq %r14, %rdi
movq 0x718b(%rip), %rsi      # 0xffd8
movq 0x7174(%rip), %rdx      # 0xffc8
callq 0x3400
jmp 0x9233
movq %rdx, %rbx
movq %rax, -0x30(%rbp)
movq %r14, %rdi
callq 0x31d0
jmp 0x8ece
movq %rdx, %rbx
movq %rax, -0x30(%rbp)
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
cmpq %rax, %rdi
je 0x8ea3
movq -0xb0(%rbp), %rsi
incq %rsi
callq 0x3290
jmp 0x8ea3
jmp 0x8eeb
movq %rdx, %rbx
movq %rax, -0x30(%rbp)
movq -0xe0(%rbp), %rdi
leaq -0xd0(%rbp), %rax
cmpq %rax, %rdi
je 0x8ece
movq -0xd0(%rbp), %rsi
incq %rsi
callq 0x3290
jmp 0x8ece
movq %rdx, %rbx
movq %rax, -0x30(%rbp)
movq %r15, %rdi
movq 0x70c8(%rip), %rsi      # 0xffa0
callq 0x31e0
leaq -0x2e0(%rbp), %rdi
callq 0x30d0
jmp 0x8ef2
movq %rdx, %rbx
movq %rax, -0x30(%rbp)
cmpl $0x1, %ebx
jne 0x9360
movq -0x30(%rbp), %rdi
callq 0x3100
movq (%rax), %rcx
movq %rax, %rdi
callq *0x10(%rcx)
movq 0x70ac(%rip), %rdi      # 0xffc0
movq %rax, %rsi
callq 0x3270
movq %rax, %rdi
callq 0x3130
callq 0x33c0
jmp 0x8d3c
movq -0x38(%rbp), %rax
movq 0x40(%rax), %rbx
leaq -0x1c8(%rbp), %r15
movq %r15, -0x10(%r15)
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdx
addq %rsi, %rdx
leaq -0x1d8(%rbp), %rdi
callq 0x693a
leaq -0xf8(%rbp), %rdi
leaq -0x1d8(%rbp), %rsi
callq 0xa126
cltq
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %rbx
movq -0x40(%rbp), %rax
movq 0x40(%rax), %r14
leaq -0x1a8(%rbp), %r12
movq %r12, -0x10(%r12)
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
addq %rsi, %rdx
leaq -0x1b8(%rbp), %rdi
callq 0x693a
leaq -0xf8(%rbp), %rdi
leaq -0x1b8(%rbp), %rsi
callq 0xa126
cltq
movq 0x18(%r14), %rcx
movq (%rcx,%rax,8), %rsi
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movsd %xmm0, -0x30(%rbp)
movq -0x1b8(%rbp), %rdi
cmpq %r12, %rdi
je 0x8fe6
movq -0x1a8(%rbp), %rsi
incq %rsi
callq 0x3290
movq -0x1d8(%rbp), %rdi
cmpq %r15, %rdi
je 0x9001
movq -0x1c8(%rbp), %rsi
incq %rsi
callq 0x3290
movq -0x38(%rbp), %rax
movq 0x40(%rax), %rbx
leaq -0x188(%rbp), %r14
movq %r14, -0x10(%r14)
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdx
addq %rsi, %rdx
leaq -0x198(%rbp), %rdi
callq 0x693a
leaq -0xf8(%rbp), %rdi
leaq -0x198(%rbp), %rsi
callq 0xa126
cltq
movq (%rbx), %rcx
movl (%rcx,%rax,4), %ebx
movq -0x198(%rbp), %rdi
cmpq %r14, %rdi
movq -0x40(%rbp), %r14
je 0x9065
movq -0x188(%rbp), %rsi
incq %rsi
callq 0x3290
movq 0x40(%r14), %r15
leaq -0x168(%rbp), %r14
movq %r14, -0x10(%r14)
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
addq %rsi, %rdx
leaq -0x178(%rbp), %rdi
callq 0x693a
leaq -0xf8(%rbp), %rdi
leaq -0x178(%rbp), %rsi
callq 0xa126
cltq
movq (%r15), %rcx
movl (%rcx,%rax,4), %r15d
movq -0x178(%rbp), %rdi
cmpq %r14, %rdi
je 0x90c2
movq -0x168(%rbp), %rsi
incq %rsi
callq 0x3290
cvtsi2sd %ebx, %xmm1
movsd -0x30(%rbp), %xmm0
mulsd %xmm1, %xmm0
callq 0x33e0
movsd %xmm0, -0x30(%rbp)
movq -0x40(%rbp), %rax
movq 0x40(%rax), %r12
leaq -0x148(%rbp), %rbx
movq %rbx, -0x10(%rbx)
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
addq %rsi, %rdx
leaq -0x158(%rbp), %rdi
callq 0x693a
leaq -0xf8(%rbp), %rdi
leaq -0x158(%rbp), %rsi
callq 0xa126
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
movapd %xmm0, %xmm1
movsd -0x30(%rbp), %xmm2
subsd %xmm2, %xmm1
cmplesd %xmm2, %xmm0
andnpd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
cltq
movq (%r12), %rdx
movl %ecx, (%rdx,%rax,4)
movq -0x158(%rbp), %rdi
cmpq %rbx, %rdi
je 0x915c
movq -0x148(%rbp), %rsi
incq %rsi
callq 0x3290
movq -0x38(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x77bc
movq -0x40(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x77bc
movq -0x38(%rbp), %rdi
callq 0x93be
movq -0x40(%rbp), %rdi
callq 0x93be
movq -0x40(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x7188
testb %al, %al
jne 0x91bc
movq -0x38(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x7188
testb %al, %al
jne 0x91bc
movq -0x40(%rbp), %rdi
callq 0x878c
movq -0x38(%rbp), %rdi
callq 0x878c
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x898c
movl %eax, %ebx
movq -0x138(%rbp), %rdi
leaq -0x128(%rbp), %rax
cmpq %rax, %rdi
je 0x91ed
movq -0x128(%rbp), %rsi
incq %rsi
callq 0x3290
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x9206
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x3290
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x921f
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x3290
movl %ebx, %eax
addq $0x338, %rsp            # imm = 0x338
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x9334
movq %rax, -0x30(%rbp)
callq 0x33c0
jmp 0x9360
movq %rax, %rdi
callq 0x6841
movq %rax, -0x30(%rbp)
movq -0x158(%rbp), %rdi
cmpq %rbx, %rdi
je 0x9360
movq -0x148(%rbp), %rsi
jmp 0x9358
movq %rax, -0x30(%rbp)
movq -0x178(%rbp), %rdi
cmpq %r14, %rdi
je 0x9360
movq -0x168(%rbp), %rsi
jmp 0x9358
movq %rax, -0x30(%rbp)
movq -0x198(%rbp), %rdi
cmpq %r14, %rdi
je 0x9360
movq -0x188(%rbp), %rsi
jmp 0x9358
jmp 0x9334
movq %rax, -0x30(%rbp)
movq -0x1b8(%rbp), %rdi
cmpq %r12, %rdi
je 0x92d8
movq -0x1a8(%rbp), %rsi
incq %rsi
callq 0x3290
jmp 0x92d8
movq %rax, -0x30(%rbp)
movq -0x1d8(%rbp), %rdi
cmpq %r15, %rdi
je 0x9360
movq -0x1c8(%rbp), %rsi
jmp 0x9358
jmp 0x9334
movq %rax, -0x30(%rbp)
movq -0x360(%rbp), %rdi
cmpq %r15, %rdi
je 0x9360
movq -0x350(%rbp), %rsi
jmp 0x9358
jmp 0x9334
movq %rax, -0x30(%rbp)
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x933e
movq -0x90(%rbp), %rsi
incq %rsi
callq 0x3290
jmp 0x933e
jmp 0x9334
movq %rax, -0x30(%rbp)
jmp 0x9360
movq %rax, -0x30(%rbp)
movq -0x118(%rbp), %rdi
leaq -0x108(%rbp), %rax
cmpq %rax, %rdi
je 0x9360
movq -0x108(%rbp), %rsi
incq %rsi
callq 0x3290
movq -0x138(%rbp), %rdi
leaq -0x128(%rbp), %rax
cmpq %rax, %rdi
je 0x9382
movq -0x128(%rbp), %rsi
incq %rsi
callq 0x3290
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x939b
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x3290
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x93b4
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x3290
movq -0x30(%rbp), %rdi
callq 0x3420
nop