// File: /workspace/github_cpp_makefile_star2_O3/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 0xb9ce(%rip), %rdi      # 0x10fd0
movl $0x1, %edx
callq 0x3140
movq (%rbx), %rax
cmpq %rax, 0x8(%rbx)
je 0x58fb
movslq %ebp, %rdx
xorl %r12d, %r12d
movq 0xb9aa(%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 0x58dd
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 0x56b2
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 0x571b
cmpl $0x1, %esi
je 0x570e
xorl %eax, %eax
testl %esi, %esi
jne 0x5726
movq 0x8(%rsp), %rax
movq (%rax), %rax
movl 0x10(%rax), %eax
jmp 0x5726
movq 0x40(%rax), %rsi
movq 0x48(%rax), %rdx
movq %r15, %rdi
callq 0x3140
movq %rax, %r13
movl $0x7, %edx
movq %rax, %rdi
leaq 0x5ef3(%rip), %rsi      # 0xb5c7
callq 0x3140
movq (%rbx), %rax
movq (%rax,%r12), %rax
movq 0x8(%rax), %rsi
movq 0x10(%rax), %rdx
movq %r13, %rdi
movq 0xb8de(%rip), %r15      # 0x10fd0
callq 0x3140
movb $0xa, 0x7(%rsp)
movl $0x1, %edx
movq %rax, %rdi
leaq 0x7(%rsp), %rsi
jmp 0x58ce
movq 0x8(%rsp), %rax
movq (%rax), %rax
movl 0x14(%rax), %eax
jmp 0x5726
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 0x5788
addl %ebp, %ebp
movq (%rbx), %rax
movq (%rax,%r12), %rax
cmpb $0x0, 0x2c(%rax)
movq 0xb864(%rip), %r15      # 0x10fd0
movq 0x8(%rsp), %rsi
je 0x57bd
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 0x57c8
movq (%rbx), %rax
movq (%rax,%r12), %rax
cmpb $0x0, 0x2c(%rax)
movq 0xb836(%rip), %r15      # 0x10fd0
movq 0x8(%rsp), %rsi
je 0x583b
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 0x5846
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 0x5dbe(%rip), %rsi      # 0xb5ab
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 0x5db2(%rip), %rsi      # 0xb5cd
callq 0x3140
movq %r13, %rdi
movl %ebp, %esi
callq 0x31b0
movl $0x10, %edx
movq %rax, %rdi
leaq 0x5d7a(%rip), %rsi      # 0xb5b3
jmp 0x58b7
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 0x5d40(%rip), %rsi      # 0xb5ab
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 0x5d34(%rip), %rsi      # 0xb5cd
callq 0x3140
movq %r13, %rdi
movl %ebp, %esi
callq 0x31b0
movl $0x2, %edx
movq %rax, %rdi
leaq 0x5d0d(%rip), %rsi      # 0xb5c4
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 0x5633
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq