// File: /workspace/github_cpp_makefile_star2_O1/rozpo[P]enemy/data/game/battle/Battle.cpp
// Function: void Battle::calculateDamage<Player, Enemy>(std::shared_ptr<Player>&, std::shared_ptr<Enemy>&, int, std::vector<std::shared_ptr<Skill>, std::allocator<std::shared_ptr<Skill>>> const&)
void Battle::calculateDamage(std::shared_ptr<T1> &user,
                             std::shared_ptr<T2> &target,
                             int x,
                             const std::vector<std::shared_ptr<Skill>> &skills)
{
    int dmg = 0;
    std::cout << '\n';
    for(int i = 0; i<skills.size(); i++)
    {
        if (user->skills[ x ] == skills[ i ]->id) {
            if (skills[ i ]->chance >= ((std::rand () % 100) + 1)) {
                dmg = user->weapon_dmg + ((std::rand () % skills[ i ]->damage) + 1) +
                      (characterDamage (user , skills[ i ]->type));
                if (skills[ i ]->critical >= ((std::rand () % 100) + 1)) {
                    dmg *= 2;
                    if (! skills[ i ]->target)
                        target->hitpoints -= dmg;
                    else {
                        user->hitpoints += dmg;
                        if (user->hitpoints > user->max_hitpoints)
                            user->hitpoints = user->max_hitpoints;
                    }
                    std::cout << user->name << " using " << skills[ i ]->name << " " << dmg << "HP CRITICAL HIT!";
                } else {
                    if (! skills[ i ]->target)
                        target->hitpoints -= dmg;
                    else {
                        user->hitpoints += dmg;
                        if (user->hitpoints > user->max_hitpoints)
                            user->hitpoints = user->max_hitpoints;
                    }
                    std::cout << user->name << " using " << skills[ i ]->name << " " << dmg << "HP";
                }
                std::cout << '\n';
            } else
                std::cout << user->name << " miss! " << skills[ i ]->name << '\n';
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, %rbx
movl %edx, %ebp
movq %rsi, 0x18(%rsp)
movq %rdi, %r13
leaq 0x17(%rsp), %rsi
movb $0xa, (%rsi)
movq 0xb982(%rip), %rdi      # 0x10fd0
movl $0x1, %edx
callq 0x3140
movq (%rbx), %rax
cmpq %rax, 0x8(%rbx)
je 0x5947
movslq %ebp, %rdx
xorl %r12d, %r12d
movq 0xb95e(%rip), %r15      # 0x10fd0
xorl %r14d, %r14d
movq %rdx, 0x20(%rsp)
movq %r13, 0x8(%rsp)
movq (%r13), %rcx
movl 0x1c(%rcx,%rdx,4), %ecx
movq (%rax,%r12), %rax
cmpl (%rax), %ecx
jne 0x5929
movl 0x30(%rax), %ebp
callq 0x3040
movslq %eax, %rcx
imulq $0x51eb851f, %rcx, %rax # imm = 0x51EB851F
movq %rax, %rdx
shrq $0x3f, %rdx
sarq $0x25, %rax
addl %edx, %eax
imull $0x64, %eax, %eax
subl %eax, %ecx
movq (%r13), %rax
cmpl %ecx, %ebp
jle 0x56fe
movl 0x80(%rax), %r13d
callq 0x3040
movq (%rbx), %rcx
movq (%rcx,%r12), %rcx
cltd
idivl 0x28(%rcx)
movl 0x38(%rcx), %esi
cmpl $0x2, %esi
je 0x5767
cmpl $0x1, %esi
je 0x575a
xorl %eax, %eax
testl %esi, %esi
jne 0x5772
movq 0x8(%rsp), %rax
movq (%rax), %rax
movl 0x10(%rax), %eax
jmp 0x5772
movq 0x40(%rax), %rsi
movq 0x48(%rax), %rdx
movq %r15, %rdi
callq 0x3140
movq %rax, %r13
movl $0x7, %edx
movq %rax, %rdi
leaq 0x5e8f(%rip), %rsi      # 0xb5af
callq 0x3140
movq (%rbx), %rax
movq (%rax,%r12), %rax
movq 0x8(%rax), %rsi
movq 0x10(%rax), %rdx
movq %r13, %rdi
movq 0xb892(%rip), %r15      # 0x10fd0
callq 0x3140
movb $0xa, 0x7(%rsp)
movl $0x1, %edx
movq %rax, %rdi
leaq 0x7(%rsp), %rsi
jmp 0x591a
movq 0x8(%rsp), %rax
movq (%rax), %rax
movl 0x14(%rax), %eax
jmp 0x5772
movq 0x8(%rsp), %rax
movq (%rax), %rax
movl 0x18(%rax), %eax
addl %edx, %r13d
leal (%rax,%r13), %ebp
incl %ebp
movl 0x34(%rcx), %r13d
callq 0x3040
cltq
imulq $0x51eb851f, %rax, %rcx # imm = 0x51EB851F
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x25, %rcx
addl %edx, %ecx
imull $0x64, %ecx, %ecx
subl %ecx, %eax
cmpl %eax, %r13d
jle 0x57d4
addl %ebp, %ebp
movq (%rbx), %rax
movq (%rax,%r12), %rax
cmpb $0x0, 0x2c(%rax)
movq 0xb818(%rip), %r15      # 0x10fd0
movq 0x8(%rsp), %rsi
je 0x5809
movq (%rsi), %rax
movl 0x8(%rax), %ecx
addl %ebp, %ecx
movl 0xc(%rax), %edx
cmpl %edx, %ecx
cmovgel %edx, %ecx
movl %ecx, 0x8(%rax)
jmp 0x5814
movq (%rbx), %rax
movq (%rax,%r12), %rax
cmpb $0x0, 0x2c(%rax)
movq 0xb7ea(%rip), %r15      # 0x10fd0
movq 0x8(%rsp), %rsi
je 0x5887
movq (%rsi), %rax
movl 0x8(%rax), %ecx
addl %ebp, %ecx
movl 0xc(%rax), %edx
cmpl %edx, %ecx
cmovgel %edx, %ecx
movl %ecx, 0x8(%rax)
jmp 0x5892
movq 0x18(%rsp), %rax
movq (%rax), %rax
subl %ebp, 0x8(%rax)
movq (%rsi), %rax
movq 0x40(%rax), %rsi
movq 0x48(%rax), %rdx
movq %r15, %rdi
callq 0x3140
movq %rax, %r13
movl $0x7, %edx
movq %rax, %rdi
leaq 0x5d5a(%rip), %rsi      # 0xb593
callq 0x3140
movq (%rbx), %rax
movq (%rax,%r12), %rax
movq 0x8(%rax), %rsi
movq 0x10(%rax), %rdx
movq %r13, %rdi
callq 0x3140
movq %rax, %r13
movl $0x1, %edx
movq %rax, %rdi
leaq 0x5d4e(%rip), %rsi      # 0xb5b5
callq 0x3140
movq %r13, %rdi
movl %ebp, %esi
callq 0x31b0
movl $0x10, %edx
movq %rax, %rdi
leaq 0x5d16(%rip), %rsi      # 0xb59b
jmp 0x5903
movq 0x18(%rsp), %rax
movq (%rax), %rax
subl %ebp, 0x8(%rax)
movq (%rsi), %rax
movq 0x40(%rax), %rsi
movq 0x48(%rax), %rdx
movq %r15, %rdi
callq 0x3140
movq %rax, %r13
movl $0x7, %edx
movq %rax, %rdi
leaq 0x5cdc(%rip), %rsi      # 0xb593
callq 0x3140
movq (%rbx), %rax
movq (%rax,%r12), %rax
movq 0x8(%rax), %rsi
movq 0x10(%rax), %rdx
movq %r13, %rdi
callq 0x3140
movq %rax, %r13
movl $0x1, %edx
movq %rax, %rdi
leaq 0x5cd0(%rip), %rsi      # 0xb5b5
callq 0x3140
movq %r13, %rdi
movl %ebp, %esi
callq 0x31b0
movl $0x2, %edx
movq %rax, %rdi
leaq 0x5ca9(%rip), %rsi      # 0xb5ac
callq 0x3140
movb $0xa, 0x6(%rsp)
movl $0x1, %edx
movq %r15, %rdi
leaq 0x6(%rsp), %rsi
callq 0x3140
movq 0x20(%rsp), %rdx
movq 0x8(%rsp), %r13
incq %r14
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
sarq $0x4, %rcx
addq $0x10, %r12
cmpq %r14, %rcx
ja 0x567f
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq