// File: /workspace/github_cpp_makefile_star2_O2/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 $0x18, %rsp
movq %rcx, %rbx
movl %edx, %r14d
movq %rsi, 0x8(%rsp)
movq %rdi, %r15
movq 0xcbed(%rip), %rdi      # 0x11fd0
pushq $0xa
popq %rsi
callq 0x3170
movslq %r14d, %rdx
xorl %r12d, %r12d
xorl %ebp, %ebp
movq %rdx, 0x10(%rsp)
movq %r15, (%rsp)
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
sarq $0x4, %rcx
cmpq %rbp, %rcx
jbe 0x55da
movq (%r15), %rcx
movl 0x1c(%rcx,%rdx,4), %ecx
movq (%rax,%r12), %rax
cmpl (%rax), %ecx
jne 0x55ce
movl 0x30(%rax), %r14d
callq 0x3040
cltd
movq %r15, %r13
pushq $0x64
popq %r15
idivl %r15d
movq (%r13), %rsi
cmpl %edx, %r14d
jle 0x54c9
movl 0x80(%rsi), %r15d
callq 0x3040
movq (%rbx), %rcx
movq (%rcx,%r12), %rcx
cltd
idivl 0x28(%rcx)
movl %edx, %r14d
movl 0x38(%rcx), %esi
movq %r13, %rdi
callq 0x5814
addl %r15d, %r14d
leal (%rax,%r14), %r13d
incl %r13d
movq (%rbx), %rax
movq (%rax,%r12), %rax
movl 0x34(%rax), %r14d
callq 0x3040
cltd
pushq $0x64
popq %rcx
idivl %ecx
cmpl %edx, %r14d
jle 0x5506
addl %r13d, %r13d
movq (%rbx), %rax
movq (%rax,%r12), %rax
cmpb $0x0, 0x2c(%rax)
je 0x5534
movq (%rsp), %r15
movq (%r15), %rax
movl 0x8(%rax), %ecx
addl %r13d, %ecx
movl 0xc(%rax), %edx
cmpl %edx, %ecx
cmovgel %edx, %ecx
movl %ecx, 0x8(%rax)
leaq 0x50ef(%rip), %r14      # 0xa5b3
jmp 0x5560
addq $0x40, %rsi
movq 0xcafc(%rip), %rdi      # 0x11fd0
callq 0x3120
movq %rax, %rdi
leaq 0x50e4(%rip), %rsi      # 0xa5c7
callq 0x3130
movq (%rbx), %rcx
movq (%rcx,%r12), %rsi
addq $0x8, %rsi
movq %rax, %rdi
callq 0x3120
movq %rax, %rdi
movq %r13, %r15
jmp 0x55c1
movq (%rbx), %rax
movq (%rax,%r12), %rax
cmpb $0x0, 0x2c(%rax)
je 0x5549
movq (%rsp), %r15
movq (%r15), %rax
movl 0x8(%rax), %ecx
addl %r13d, %ecx
movl 0xc(%rax), %edx
cmpl %edx, %ecx
cmovgel %edx, %ecx
movl %ecx, 0x8(%rax)
leaq 0x5092(%rip), %r14      # 0xa5c4
jmp 0x5560
movq 0x8(%rsp), %rax
movq (%rax), %rax
subl %r13d, 0x8(%rax)
leaq 0x506c(%rip), %r14      # 0xa5b3
jmp 0x555c
movq 0x8(%rsp), %rax
movq (%rax), %rax
subl %r13d, 0x8(%rax)
leaq 0x5068(%rip), %r14      # 0xa5c4
movq (%rsp), %r15
movq (%r15), %rsi
addq $0x40, %rsi
movq 0xca62(%rip), %rdi      # 0x11fd0
callq 0x3120
movq %rax, %rdi
leaq 0x502e(%rip), %rsi      # 0xa5ab
callq 0x3130
movq (%rbx), %rcx
movq (%rcx,%r12), %rsi
addq $0x8, %rsi
movq %rax, %rdi
callq 0x3120
movq %rax, %rdi
leaq 0x502e(%rip), %rsi      # 0xa5cd
callq 0x3130
movq %rax, %rdi
movl %r13d, %esi
callq 0x31f0
movq %rax, %rdi
movq %r14, %rsi
callq 0x3130
movq 0xca0f(%rip), %rdi      # 0x11fd0
pushq $0xa
popq %rsi
callq 0x3170
movq 0x10(%rsp), %rdx
incq %rbp
addq $0x10, %r12
jmp 0x53fc
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop