// File: /workspace/github_cpp_makefile_star2_O3/MichaelXanth[P]RPG_Game/Market/Market.cpp
// Function: Market::NewStuff(std::vector<Hero*, std::allocator<Hero*>>&)
void Market::NewStuff(vector<Hero *>& heroes)
{
    if (heroes.size() == 1)
    {
        if (heroes[0]->Living::GetLevel() < prevLevel + 2)
            return;

        prevLevel = heroes[0]->Living::GetLevel();
    
    } else {
        unsigned int averageLevel = 0;

        for (unsigned int i = 0; i < heroes.size(); i++)
            averageLevel += heroes[i]->Living::GetLevel();
        
        averageLevel /= heroes.size();

        if (averageLevel < prevLevel + 2)
            return;

        prevLevel = averageLevel;
    }

    if (rand() % prevLevel < prevLevel / 6)
        AddLightingSpells(rand() % 10);

    if (rand() % prevLevel < prevLevel / 6)
        AddFireSpells(rand() % 10);

    if (rand() % prevLevel < prevLevel / 6)
        AddIceSpells(rand() % 10);

    if (rand() % prevLevel < prevLevel / 6)
        AddWeapons(rand() % 10);

    if (rand() % prevLevel < prevLevel / 6)
        AddPotions(rand() % 10);

    if (rand() % prevLevel < prevLevel / 6)
        AddArmors(rand() % 10);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq (%rsi), %rax
movq 0x8(%rsi), %rdx
movq %rdx, %rcx
subq %rax, %rcx
cmpq $0x8, %rcx
jne 0x1ab60
movq (%rax), %rdi
callq 0x10840
movl 0x1f0(%rbx), %ecx
addl $0x2, %ecx
cmpl %ecx, %eax
jb 0x1ad93
movq (%r14), %rax
movq (%rax), %rdi
callq 0x10840
jmp 0x1abb6
cmpq %rax, %rdx
je 0x1ab97
xorl %edx, %edx
movl $0x1, %r12d
xorl %r15d, %r15d
movq (%rax,%rdx,8), %rdi
callq 0x10840
addl %eax, %r15d
movl %r12d, %edx
movq (%r14), %rax
movq 0x8(%r14), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
incl %r12d
cmpq %rdx, %rcx
ja 0x1ab70
jmp 0x1ab9e
sarq $0x3, %rcx
xorl %r15d, %r15d
movl %r15d, %eax
xorl %edx, %edx
divl %ecx
movl 0x1f0(%rbx), %ecx
addl $0x2, %ecx
cmpl %eax, %ecx
ja 0x1ad93
movl %eax, 0x1f0(%rbx)
callq 0x3060
movl 0x1f0(%rbx), %ecx
xorl %edx, %edx
divl %ecx
movl $0xaaaaaaab, %r14d      # imm = 0xAAAAAAAB
imulq %r14, %rcx
shrq $0x22, %rcx
cmpl %ecx, %edx
jae 0x1ac0d
callq 0x3060
cltq
imulq $0x66666667, %rax, %rcx # imm = 0x66666667
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x22, %rcx
addl %edx, %ecx
addl %ecx, %ecx
leal (%rcx,%rcx,4), %ecx
subl %ecx, %eax
leaq -0x24(%rbp), %rsi
movl %eax, (%rsi)
movq %rbx, %rdi
callq 0x195f8
callq 0x3060
movl 0x1f0(%rbx), %ecx
xorl %edx, %edx
divl %ecx
imulq %rcx, %r14
shrq $0x22, %r14
cmpl %r14d, %edx
jae 0x1ac59
callq 0x3060
cltq
imulq $0x66666667, %rax, %rcx # imm = 0x66666667
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x22, %rcx
addl %edx, %ecx
addl %ecx, %ecx
leal (%rcx,%rcx,4), %ecx
subl %ecx, %eax
leaq -0x24(%rbp), %rsi
movl %eax, (%rsi)
movq %rbx, %rdi
callq 0x198e4
callq 0x3060
movl 0x1f0(%rbx), %ecx
xorl %edx, %edx
divl %ecx
movl $0xaaaaaaab, %r14d      # imm = 0xAAAAAAAB
imulq %r14, %rcx
shrq $0x22, %rcx
cmpl %ecx, %edx
jae 0x1acaa
callq 0x3060
cltq
imulq $0x66666667, %rax, %rcx # imm = 0x66666667
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x22, %rcx
addl %edx, %ecx
addl %ecx, %ecx
leal (%rcx,%rcx,4), %ecx
subl %ecx, %eax
leaq -0x24(%rbp), %rsi
movl %eax, (%rsi)
movq %rbx, %rdi
callq 0x19bae
callq 0x3060
movl 0x1f0(%rbx), %ecx
xorl %edx, %edx
divl %ecx
imulq %rcx, %r14
shrq $0x22, %r14
cmpl %r14d, %edx
jae 0x1acf6
callq 0x3060
cltq
imulq $0x66666667, %rax, %rcx # imm = 0x66666667
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x22, %rcx
addl %edx, %ecx
addl %ecx, %ecx
leal (%rcx,%rcx,4), %ecx
subl %ecx, %eax
leaq -0x24(%rbp), %rsi
movl %eax, (%rsi)
movq %rbx, %rdi
callq 0x19e74
callq 0x3060
movl 0x1f0(%rbx), %ecx
xorl %edx, %edx
divl %ecx
movl $0xaaaaaaab, %r14d      # imm = 0xAAAAAAAB
imulq %r14, %rcx
shrq $0x22, %rcx
cmpl %ecx, %edx
jae 0x1ad47
callq 0x3060
cltq
imulq $0x66666667, %rax, %rcx # imm = 0x66666667
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x22, %rcx
addl %edx, %ecx
addl %ecx, %ecx
leal (%rcx,%rcx,4), %ecx
subl %ecx, %eax
leaq -0x24(%rbp), %rsi
movl %eax, (%rsi)
movq %rbx, %rdi
callq 0x1a0dc
callq 0x3060
movl 0x1f0(%rbx), %ecx
xorl %edx, %edx
divl %ecx
imulq %rcx, %r14
shrq $0x22, %r14
cmpl %r14d, %edx
jae 0x1ad93
callq 0x3060
cltq
imulq $0x66666667, %rax, %rcx # imm = 0x66666667
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x22, %rcx
addl %edx, %ecx
addl %ecx, %ecx
leal (%rcx,%rcx,4), %ecx
subl %ecx, %eax
leaq -0x24(%rbp), %rsi
movl %eax, (%rsi)
movq %rbx, %rdi
callq 0x1a4c2
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq