// File: /workspace/github_cpp_makefile_star2_O3/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, -0x30(%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 0x9ea8
movq %rbx, -0x38(%rbp)
movq 0x40(%rbx), %rdi
callq 0x7146
testb %al, %al
jne 0x89ea
movq -0x30(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x7146
testb %al, %al
je 0x8b06
movq -0x30(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x7146
testb %al, %al
je 0x8a7a
movq 0x75be(%rip), %rbx      # 0xffc0
leaq 0x2cfb(%rip), %rsi      # 0xb704
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 0x758c(%rip), %rdi      # 0xffc0
callq 0x3030
movq %rax, %rdi
callq 0x31b0
movq -0x38(%rbp), %rcx
cmpb $0x1, 0x3a(%rcx)
jne 0x8a66
movq -0x30(%rbp), %rax
movsd 0x30(%rax), %xmm0
addsd 0x30(%rcx), %xmm0
minsd 0x2bef(%rip), %xmm0     # 0xb650
movsd %xmm0, 0x30(%rcx)
movq -0x30(%rbp), %rdi
movb $0x0, 0x3a(%rdi)
movb $0x1, %bl
callq 0x96d2
jmp 0x919b
movq -0x38(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x7146
testb %al, %al
je 0x8aff
movq 0x752e(%rip), %rbx      # 0xffc0
leaq 0x2c76(%rip), %rsi      # 0xb70f
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 0x74fc(%rip), %rdi      # 0xffc0
callq 0x3030
movq %rax, %rdi
callq 0x31b0
movq -0x30(%rbp), %rax
cmpb $0x1, 0x3a(%rax)
movq -0x38(%rbp), %rdi
jne 0x8af6
movsd 0x30(%rdi), %xmm0
addsd 0x30(%rax), %xmm0
minsd 0x2b5f(%rip), %xmm0     # 0xb650
movsd %xmm0, 0x30(%rax)
movb $0x0, 0x3a(%rdi)
callq 0x96d2
xorl %ebx, %ebx
jmp 0x919b
leaq -0x350(%rbp), %r15
movq %r15, -0x10(%r15)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rsi
movq 0x10(%rax), %rdx
addq %rsi, %rdx
leaq -0x360(%rbp), %rdi
callq 0x6930
movq -0x360(%rbp), %rsi
movq -0x358(%rbp), %rdx
movq 0x747f(%rip), %rdi      # 0xffc0
callq 0x32d0
movq %rax, %rbx
leaq 0x2b82(%rip), %rsi      # 0xb6d2
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 0x8b9f
movq -0x350(%rbp), %rsi
incq %rsi
callq 0x3290
movq 0x743a(%rip), %r12      # 0xffe0
leaq -0x360(%rbp), %r15
leaq -0xf8(%rbp), %r13
movq %r12, %rdi
callq 0x30f0
cmpl $0xa, %eax
jne 0x8bc9
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 -0x38(%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 0x6930
movq %r13, %rdi
leaq -0xe0(%rbp), %rsi
callq 0xa0ee
cltq
movq (%rbx), %rcx
cmpl $0x0, (%rcx,%rax,4)
jle 0x8ccf
movq -0x30(%rbp), %rax
movq 0x40(%rax), %rbx
leaq -0xb0(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdx
addq %rsi, %rdx
leaq -0xc0(%rbp), %rdi
callq 0x6930
movq %r13, %rdi
leaq -0xc0(%rbp), %rsi
callq 0xa0ee
cltq
movq (%rbx), %rcx
cmpl $0x0, (%rcx,%rax,4)
setle %bl
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
cmpq %rax, %rdi
je 0x8cd1
movq -0xb0(%rbp), %rsi
incq %rsi
callq 0x3290
jmp 0x8cd1
movb $0x1, %bl
movq -0xe0(%rbp), %rdi
leaq -0xd0(%rbp), %rax
cmpq %rax, %rdi
je 0x8cf3
movq -0xd0(%rbp), %rsi
incq %rsi
callq 0x3290
testb %bl, %bl
jne 0x8df9
movq %r15, %rdi
movq 0x729b(%rip), %rsi      # 0xffa0
callq 0x31e0
leaq -0x2e0(%rbp), %rdi
callq 0x30d0
movq -0x38(%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 0x6930
movq %r13, %rdi
movq %r14, %rsi
callq 0xa0ee
cltq
movq (%rbx), %rcx
cmpl $0x0, (%rcx,%rax,4)
jle 0x8dc8
movq -0x30(%rbp), %rax
movq 0x40(%rax), %rbx
leaq -0x90(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdx
addq %rsi, %rdx
leaq -0xa0(%rbp), %rdi
callq 0x6930
movq %r13, %rdi
leaq -0xa0(%rbp), %rsi
callq 0xa0ee
cltq
movq (%rbx), %rcx
cmpl $0x0, (%rcx,%rax,4)
setle %bl
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x8dca
movq -0x90(%rbp), %rsi
incq %rsi
callq 0x3290
jmp 0x8dca
movb $0x1, %bl
movq -0x118(%rbp), %rdi
leaq -0x108(%rbp), %rax
cmpq %rax, %rdi
je 0x8dec
movq -0x108(%rbp), %rsi
incq %rsi
callq 0x3290
testb %bl, %bl
jne 0x8bb4
jmp 0x8efd
movl $0x10, %edi
callq 0x3140
movq %rax, -0x40(%rbp)
movq %rax, %rdi
leaq 0x28ca(%rip), %rsi      # 0xb6db
callq 0x3460
movq -0x40(%rbp), %rdi
movq 0x71b7(%rip), %rsi      # 0xffd8
movq 0x71a0(%rip), %rdx      # 0xffc8
callq 0x3400
jmp 0x9203
movq %rdx, %rbx
movq %rax, %r14
movq -0x40(%rbp), %rdi
callq 0x31d0
jmp 0x8e9f
movq %rdx, %rbx
movq %rax, %r14
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
cmpq %rax, %rdi
je 0x8e75
movq -0xb0(%rbp), %rsi
incq %rsi
callq 0x3290
jmp 0x8e75
jmp 0x8ebc
movq %rdx, %rbx
movq %rax, %r14
movq -0xe0(%rbp), %rdi
leaq -0xd0(%rbp), %rax
cmpq %rax, %rdi
je 0x8e9f
movq -0xd0(%rbp), %rsi
incq %rsi
callq 0x3290
jmp 0x8e9f
movq %rdx, %rbx
movq %rax, %r14
movq %r15, %rdi
movq 0x70f7(%rip), %rsi      # 0xffa0
callq 0x31e0
leaq -0x2e0(%rbp), %rdi
callq 0x30d0
jmp 0x8ec2
movq %rdx, %rbx
movq %rax, %r14
cmpl $0x1, %ebx
jne 0x9323
movq %r14, %rdi
callq 0x3100
movq (%rax), %rcx
movq %rax, %rdi
callq *0x10(%rcx)
movq 0x70dd(%rip), %rdi      # 0xffc0
movq %rax, %rsi
callq 0x3270
movq %rax, %rdi
callq 0x3130
callq 0x33c0
jmp 0x8d16
movq -0x30(%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 0x6930
leaq -0xf8(%rbp), %rdi
leaq -0x1d8(%rbp), %rsi
callq 0xa0ee
cltq
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %rbx
movq -0x38(%rbp), %rax
movq 0x40(%rax), %r13
leaq -0x1a8(%rbp), %r12
movq %r12, -0x10(%r12)
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
addq %rsi, %rdx
leaq -0x1b8(%rbp), %rdi
callq 0x6930
leaq -0xf8(%rbp), %rdi
leaq -0x1b8(%rbp), %rsi
callq 0xa0ee
cltq
movq 0x18(%r13), %rcx
movq (%rcx,%rax,8), %rsi
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movsd %xmm0, -0x40(%rbp)
movq -0x1b8(%rbp), %rdi
cmpq %r12, %rdi
je 0x8fb5
movq -0x1a8(%rbp), %rsi
incq %rsi
callq 0x3290
movq -0x1d8(%rbp), %rdi
cmpq %r15, %rdi
je 0x8fd0
movq -0x1c8(%rbp), %rsi
incq %rsi
callq 0x3290
movq -0x30(%rbp), %rax
movq 0x40(%rax), %rbx
leaq -0x188(%rbp), %r15
movq %r15, -0x10(%r15)
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdx
addq %rsi, %rdx
leaq -0x198(%rbp), %rdi
callq 0x6930
leaq -0xf8(%rbp), %rdi
leaq -0x198(%rbp), %rsi
callq 0xa0ee
cltq
movq (%rbx), %rcx
movl (%rcx,%rax,4), %ebx
movq -0x198(%rbp), %rdi
cmpq %r15, %rdi
je 0x9030
movq -0x188(%rbp), %rsi
incq %rsi
callq 0x3290
movq -0x38(%rbp), %rax
movq 0x40(%rax), %r15
leaq -0x168(%rbp), %r12
movq %r12, -0x10(%r12)
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
addq %rsi, %rdx
leaq -0x178(%rbp), %rdi
callq 0x6930
leaq -0xf8(%rbp), %rdi
leaq -0x178(%rbp), %rsi
callq 0xa0ee
cltq
movq (%r15), %rcx
movl (%rcx,%rax,4), %r15d
movq -0x178(%rbp), %rdi
cmpq %r12, %rdi
je 0x9092
movq -0x168(%rbp), %rsi
incq %rsi
callq 0x3290
cvtsi2sd %ebx, %xmm1
movsd -0x40(%rbp), %xmm0
mulsd %xmm1, %xmm0
callq 0x33e0
movsd %xmm0, -0x40(%rbp)
movq -0x38(%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 0x6930
leaq -0xf8(%rbp), %rdi
leaq -0x158(%rbp), %rsi
callq 0xa0ee
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
movapd %xmm0, %xmm1
movsd -0x40(%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 0x912c
movq -0x148(%rbp), %rsi
incq %rsi
callq 0x3290
movq -0x30(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x777a
movq -0x38(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x777a
movq -0x30(%rbp), %rdi
callq 0x9380
movq -0x38(%rbp), %rdi
callq 0x9380
movq -0x38(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x7146
testb %al, %al
jne 0x918c
movq -0x30(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x7146
testb %al, %al
jne 0x918c
movq -0x38(%rbp), %rdi
callq 0x876e
movq -0x30(%rbp), %rdi
callq 0x876e
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x896e
movl %eax, %ebx
movq -0x138(%rbp), %rdi
leaq -0x128(%rbp), %rax
cmpq %rax, %rdi
je 0x91bd
movq -0x128(%rbp), %rsi
incq %rsi
callq 0x3290
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x91d6
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x3290
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x91ef
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 0x92f9
movq %rax, %r14
callq 0x33c0
jmp 0x9323
movq %rax, %rdi
callq 0x6837
movq %rax, %r14
movq -0x158(%rbp), %rdi
cmpq %rbx, %rdi
je 0x9323
movq -0x148(%rbp), %rsi
jmp 0x931b
movq %rax, %r14
movq -0x178(%rbp), %rdi
cmpq %r12, %rdi
je 0x9323
movq -0x168(%rbp), %rsi
jmp 0x931b
movq %rax, %r14
movq -0x198(%rbp), %rdi
cmpq %r15, %rdi
je 0x9323
movq -0x188(%rbp), %rsi
jmp 0x931b
jmp 0x92f9
movq %rax, %r14
movq -0x1b8(%rbp), %rdi
cmpq %r12, %rdi
je 0x929f
movq -0x1a8(%rbp), %rsi
incq %rsi
callq 0x3290
jmp 0x929f
movq %rax, %r14
movq -0x1d8(%rbp), %rdi
cmpq %r15, %rdi
je 0x9323
movq -0x1c8(%rbp), %rsi
jmp 0x931b
jmp 0x92f9
movq %rax, %r14
movq -0x360(%rbp), %rdi
cmpq %r15, %rdi
je 0x9323
movq -0x350(%rbp), %rsi
jmp 0x931b
jmp 0x92f9
movq %rax, %r14
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x9301
movq -0x90(%rbp), %rsi
incq %rsi
callq 0x3290
jmp 0x9301
jmp 0x92f9
movq %rax, %r14
jmp 0x9323
movq %rax, %r14
movq -0x118(%rbp), %rdi
leaq -0x108(%rbp), %rax
cmpq %rax, %rdi
je 0x9323
movq -0x108(%rbp), %rsi
incq %rsi
callq 0x3290
movq -0x138(%rbp), %rdi
leaq -0x128(%rbp), %rax
cmpq %rax, %rdi
je 0x9345
movq -0x128(%rbp), %rsi
incq %rsi
callq 0x3290
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x935e
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x3290
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x9377
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x3290
movq %r14, %rdi
callq 0x3420
nop