// File: /workspace/github_cpp_makefile_star2_O3/Worthy-Wang[P]Warcraft3-StartWar/City.cpp
// Function: warcraft::City::win(std::shared_ptr<warcraft::Warrior>, std::shared_ptr<warcraft::Warrior>)
void City::win(WarriorPtr winner, WarriorPtr loser)
{
    cout << toString(winner->getColor()) << " " << winner->getName() << " " << winner->getId() <<" kills " << toString(loser->getColor()) << " " << loser->getName() << " " << loser->getId() << "in city " << loser->getCityId() << endl;

    //开始缴获敌人的武器, 当敌人没有武器的时候或者武器数量超过最大携带武器数时停止
    //首先胜者清理自己的武器
    vector<WeaponPtr>& winnerWeapons = winner->getWeapons();
    auto it = std::remove_if(winnerWeapons.begin(), winnerWeapons.end(), [](WeaponPtr& weapon){ return (weapon->getDurability()==0);  });
    winnerWeapons.erase(it, winnerWeapons.end());

    //缴获败者武器
    vector<WeaponPtr>& loserWeapons = loser->getWeapons();
    std::sort(loserWeapons.begin(), loserWeapons.end(), compAfterFight);
    for (auto &e :loserWeapons)
    {
        if (winnerWeapons.size() > MAX_WEAPON_SIZE)
            break;
        if (e->getDurability() > 0)
            winner->getNewWeapon(e);
    }

    //将败者的尸体扔出
    loser->getColor()==RED? (redWarrior.reset()):(blueWarrior.reset());

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rdx, -0x30(%rbp)
movq %rdi, %r14
movq %rsi, -0x38(%rbp)
movq (%rsi), %rax
movl 0x8(%rax), %eax
leaq -0xc0(%rbp), %r12
movq %r12, -0x10(%r12)
cmpl $0x1, %eax
je 0x4ccd
testl %eax, %eax
jne 0x4cea
movb $0x64, 0x2(%r12)
movw $0x6572, (%r12)         # imm = 0x6572
leaq -0xbd(%rbp), %rax
movq $0x3, -0xb(%rax)
movl $0x3, %edx
jmp 0x4cfa
leaq -0xbc(%rbp), %rax
movl $0x65756c62, -0x4(%rax) # imm = 0x65756C62
movq $0x4, -0xc(%rax)
movl $0x4, %edx
jmp 0x4cfa
movq $0x0, -0xc8(%rbp)
xorl %edx, %edx
movq %r12, %rax
movb $0x0, (%rax)
movq 0x122cc(%rip), %rdi     # 0x16fd0
movq %r12, %rsi
callq 0x4190
movq %rax, %rbx
leaq 0xbd95(%rip), %rsi      # 0x10aab
movl $0x1, %edx
movq %rax, %rdi
callq 0x4190
movq -0x38(%rbp), %rax
movq (%rax), %rax
leaq -0xa0(%rbp), %r15
movq %r15, -0x10(%r15)
movq 0x10(%rax), %rsi
movq 0x18(%rax), %rdx
addq %rsi, %rdx
leaq -0xb0(%rbp), %rdi
callq 0x570a
movq -0xb0(%rbp), %rsi
movq -0xa8(%rbp), %rdx
movq %rbx, %rdi
callq 0x4190
movq %rax, %rbx
leaq 0xbd3f(%rip), %rsi      # 0x10aab
movl $0x1, %edx
movq %rax, %rdi
callq 0x4190
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq 0x30(%rax), %rsi
movq %rbx, %rdi
callq 0x40e0
movq %rax, %rbx
leaq 0xb28a(%rip), %rsi      # 0x10020
movl $0x7, %edx
movq %rax, %rdi
callq 0x4190
movq -0x30(%rbp), %rax
movq (%rax), %rax
movl 0x8(%rax), %eax
leaq -0x80(%rbp), %r13
movq %r13, -0x10(%r13)
cmpl $0x1, %eax
je 0x4ddd
testl %eax, %eax
jne 0x4df7
movb $0x64, 0x2(%r13)
movw $0x6572, (%r13)         # imm = 0x6572
leaq -0x7d(%rbp), %rax
movq $0x3, -0xb(%rax)
movl $0x3, %edx
jmp 0x4e07
leaq -0x7c(%rbp), %rax
movl $0x65756c62, -0x4(%rax) # imm = 0x65756C62
movq $0x4, -0xc(%rax)
movl $0x4, %edx
jmp 0x4e07
movq $0x0, -0x88(%rbp)
xorl %edx, %edx
movq %r13, %rax
movq %r14, -0x40(%rbp)
movb $0x0, (%rax)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x4190
movq %rax, %rbx
leaq 0xbc88(%rip), %rsi      # 0x10aab
movl $0x1, %edx
movq %rax, %rdi
callq 0x4190
movq -0x30(%rbp), %rax
movq (%rax), %rax
leaq -0x60(%rbp), %r14
movq %r14, -0x10(%r14)
movq 0x10(%rax), %rsi
movq 0x18(%rax), %rdx
addq %rsi, %rdx
leaq -0x70(%rbp), %rdi
callq 0x570a
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rdx
movq %rbx, %rdi
callq 0x4190
movq %rax, %rbx
leaq 0xbc3e(%rip), %rsi      # 0x10aab
movl $0x1, %edx
movq %rax, %rdi
callq 0x4190
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq 0x30(%rax), %rsi
movq %rbx, %rdi
callq 0x40e0
movq %rax, %rbx
leaq 0xb1ef(%rip), %rsi      # 0x10086
movl $0x8, %edx
movq %rax, %rdi
callq 0x4190
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq 0x58(%rax), %rsi
movq %rbx, %rdi
callq 0x40e0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4150
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4030
movq %rax, %rdi
callq 0x40f0
movq -0x70(%rbp), %rdi
cmpq %r14, %rdi
je 0x4ef6
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x4170
movq -0x90(%rbp), %rdi
cmpq %r13, %rdi
je 0x4f0e
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x4170
movq -0xb0(%rbp), %rdi
cmpq %r15, %rdi
je 0x4f29
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x4170
movq -0xd0(%rbp), %rdi
cmpq %r12, %rdi
je 0x4f44
movq -0xc0(%rbp), %rsi
incq %rsi
callq 0x4170
movq -0x38(%rbp), %rax
movq (%rax), %r14
leaq 0x40(%r14), %r12
movq 0x40(%r14), %rax
movq 0x48(%r14), %r13
movq %r13, %rdx
subq %rax, %rdx
movq %rdx, %rsi
sarq $0x6, %rsi
movq %rdx, %rdi
movq %rax, %rcx
testq %rsi, %rsi
jle 0x4fbe
movq %rdx, %rcx
andq $-0x40, %rcx
addq %rax, %rcx
incq %rsi
leaq 0x20(%rax), %rbx
movq -0x20(%rbx), %rdi
cmpq $0x0, 0x38(%rdi)
je 0x5005
movq -0x10(%rbx), %rdi
cmpq $0x0, 0x38(%rdi)
je 0x500b
movq (%rbx), %rdi
cmpq $0x0, 0x38(%rdi)
je 0x5015
movq 0x10(%rbx), %rdi
cmpq $0x0, 0x38(%rdi)
je 0x5011
decq %rsi
addq $0x40, %rbx
cmpq $0x1, %rsi
jg 0x4f80
movq %r13, %rdi
subq %rcx, %rdi
sarq $0x4, %rdi
cmpq $0x1, %rdi
je 0x4ff4
cmpq $0x2, %rdi
je 0x4fe6
cmpq $0x3, %rdi
jne 0x5070
movq (%rcx), %rsi
cmpq $0x0, 0x38(%rsi)
je 0x5000
addq $0x10, %rcx
movq (%rcx), %rsi
cmpq $0x0, 0x38(%rsi)
je 0x5000
addq $0x10, %rcx
movq (%rcx), %rsi
cmpq $0x0, 0x38(%rsi)
cmovneq %r13, %rcx
movq %rcx, %rbx
jmp 0x5015
addq $-0x20, %rbx
jmp 0x5015
addq $-0x10, %rbx
jmp 0x5015
addq $0x10, %rbx
cmpq %r13, %rbx
sete %cl
leaq 0x10(%rbx), %r15
cmpq %r13, %r15
sete %sil
orb %cl, %sil
jne 0x506d
movq (%r15), %rax
cmpq $0x0, 0x38(%rax)
je 0x5059
movq 0x8(%r15), %rcx
xorps %xmm0, %xmm0
movups %xmm0, (%r15)
movq %rax, (%rbx)
movq 0x8(%rbx), %rdi
movq %rcx, 0x8(%rbx)
testq %rdi, %rdi
je 0x5055
callq 0x57a8
addq $0x10, %rbx
addq $0x10, %r15
cmpq %r13, %r15
jne 0x502b
movq 0x40(%r14), %rax
movq 0x48(%r14), %rdx
subq %rax, %rdx
movq %rbx, %r13
subq %rax, %r13
addq %rax, %r13
addq %rax, %rdx
movq %r12, %rdi
movq %r13, %rsi
callq 0x5814
movq -0x30(%rbp), %rax
movq (%rax), %r15
movq 0x40(%r15), %rbx
movq 0x48(%r15), %r12
cmpq %r12, %rbx
je 0x514e
movq %r12, %rax
subq %rbx, %rax
sarq $0x4, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
leaq -0xad0(%rip), %r13      # 0x45ea
movq %rbx, %rdi
movq %r12, %rsi
movq %r13, %rcx
callq 0x58e7
movq %rbx, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x59ba
movq 0x40(%r15), %rbx
movq 0x48(%r15), %r13
cmpq %r13, %rbx
je 0x514e
leaq -0x50(%rbp), %r12
movq 0x11eda(%rip), %r15     # 0x16fc8
movq 0x48(%r14), %rax
subq 0x40(%r14), %rax
cmpq $0xaf, %rax
ja 0x514e
movq (%rbx), %rax
cmpq $0x0, 0x38(%rax)
je 0x5145
movq -0x38(%rbp), %rcx
movq (%rcx), %rdi
movq %rax, -0x50(%rbp)
movq 0x8(%rbx), %rax
movq %rax, -0x48(%rbp)
testq %rax, %rax
je 0x512f
cmpb $0x0, (%r15)
je 0x512b
incl 0x8(%rax)
jmp 0x512f
lock
incl 0x8(%rax)
movq %r12, %rsi
callq 0xd056
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x5145
callq 0x57a8
addq $0x10, %rbx
cmpq %r13, %rbx
jne 0x50ee
movq -0x30(%rbp), %rax
movq (%rax), %rax
cmpl $0x0, 0x8(%rax)
je 0x516c
xorps %xmm0, %xmm0
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rdi
movups %xmm0, 0x18(%rax)
jmp 0x517b
xorps %xmm0, %xmm0
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rdi
movups %xmm0, 0x8(%rax)
testq %rdi, %rdi
je 0x5185
callq 0x57a8
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x519b
jmp 0x51a0
movq %rax, %rbx
jmp 0x51d5
movq %rax, %rbx
jmp 0x5208
movq %rax, %rbx
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x5223
callq 0x57a8
jmp 0x5223
movq %rax, %rbx
jmp 0x51ed
movq %rax, %rbx
movq -0x70(%rbp), %rdi
cmpq %r14, %rdi
je 0x51d5
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x4170
movq -0x90(%rbp), %rdi
cmpq %r13, %rdi
je 0x51ed
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x4170
movq -0xb0(%rbp), %rdi
cmpq %r15, %rdi
je 0x5208
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x4170
movq -0xd0(%rbp), %rdi
cmpq %r12, %rdi
je 0x5223
movq -0xc0(%rbp), %rsi
incq %rsi
callq 0x4170
movq %rbx, %rdi
callq 0x4230
nop