// File: /workspace/github_cpp_makefile_star2_O2/whitefusion[P]Jaipur_cardgame-/Game.cpp
// Function: Game::tradeVerify(std::vector<int, std::allocator<int>>&, std::vector<int, std::allocator<int>>&, Player&, Market&)
bool Game::tradeVerify(vector<int> &mtake, vector<int> &htake, Player &p, Market &m){
    // if no cards in hand, return false
    if (p.getSize(0)+p.getSize(1) < 2 || mtake.size() < 2)
        return false;

    int msize = mtake.size();
    int hsize = htake.size();

    // out of range
    for (int i = 0; i < msize; ++i)
        if (mtake.at(i) > 5 || mtake.at(i) < 1 || isalpha(mtake.at(i)))
            return false;

     for (int i = 0; i < hsize; ++i)
         if (htake.at(i) > 7 || htake.at(i) < 1 || isalpha(htake.at(i)))
             return false;


    // Rules: mcards >= hcards; --- total card # conserved 
    // size[0] + mcards - hcards <= 7; --- new size of hand cards should be <= 7
    // mcards - hcards <= size[1]; --- # of camel to exchange <= available camels
    // cannot take camel cards on market

    // no same index are allowed
    for (int i = 0; i < msize; ++i){
        for (int j = 0; j < msize; ++j){
            if ((i !=j) && (mtake.at(i) == mtake.at(j)))
                return false;
        }
    }
    
    // no same index are allowed
    for (int i = 0; i < hsize; ++i){
        for (int j = 0; j < hsize; ++j){
            if ((i != j) && (htake.at(i) == htake.at(j)))
                return false;
        }
    }

    // same goods cannot be traded
    for (int i = 0; i < msize; ++i){
        for (int j = 0; j < hsize; ++j){
            if (market.getGoods(mtake.at(i)).getCard() == p.getHand(0,htake.at(j)-1).getCard())
                return false;
        }
    }

    

    // size ...
    if (msize < hsize || p.getSize(0) + msize - hsize > 7 || p.getSize(1) < msize - hsize)
        return false;
    else {
         for (int i = 0; i < msize; ++i)
             if (m.getGoods(mtake.at(i)).getCard() == "CAMEL" )
                 return false;
    }        
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %r8, %r15
movq %rcx, %r13
movq %rdx, %r12
movq %rsi, %r14
movq %rdi, 0x50(%rsp)
xorl %ebp, %ebp
movq %rcx, %rdi
xorl %esi, %esi
callq 0x8b20
movl %eax, %ebx
pushq $0x1
popq %rsi
movq %r13, 0x20(%rsp)
movq %r13, %rdi
callq 0x8b20
addl %ebx, %eax
cmpl $0x2, %eax
jl 0xb9ae
movq 0x8(%r14), %rax
subq (%r14), %rax
movq %rax, 0x48(%rsp)
sarq $0x2, %rax
xorl %ebp, %ebp
movq %rax, 0x10(%rsp)
cmpq $0x2, %rax
jb 0xb9ae
movq 0x8(%r12), %rbx
subq (%r12), %rbx
shrq $0x2, %rbx
movq 0x10(%rsp), %rax
testl %eax, %eax
movl $0x0, %r13d
cmovgl %eax, %r13d
cmpq %rbp, %r13
je 0xb9c2
movq %r14, %rdi
movq %rbp, %rsi
callq 0x5358
cmpl $0x5, (%rax)
jg 0xb9ac
movq %r14, %rdi
movq %rbp, %rsi
callq 0x5358
cmpl $0x0, (%rax)
jle 0xb9ac
movq %r14, %rdi
movq %rbp, %rsi
callq 0x5358
movl (%rax), %edi
callq 0x2260
incq %rbp
testl %eax, %eax
je 0xb96e
xorl %ebp, %ebp
movl %ebp, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rax
xorl %ebx, %ebx
testl %eax, %eax
movl $0x0, %ecx
movq %rax, 0x38(%rsp)
cmovgl %eax, %ecx
movq %rcx, 0x28(%rsp)
cmpq %rbx, 0x28(%rsp)
je 0xba1f
movq %r12, %rdi
movq %rbx, %rsi
callq 0x5358
cmpl $0x7, (%rax)
jg 0xb9ac
movq %r12, %rdi
movq %rbx, %rsi
callq 0x5358
cmpl $0x0, (%rax)
jle 0xb9ac
movq %r12, %rdi
movq %rbx, %rsi
callq 0x5358
movl (%rax), %edi
callq 0x2260
incq %rbx
xorl %ebp, %ebp
testl %eax, %eax
je 0xb9db
jmp 0xb9ae
movq %r13, 0x18(%rsp)
movq %r15, 0x40(%rsp)
movl 0x10(%rsp), %r13d
xorl %ebx, %ebx
cmpq 0x18(%rsp), %rbx
je 0xba6f
xorl %ebp, %ebp
cmpq %rbp, %r13
je 0xba6a
cmpq %rbp, %rbx
je 0xba65
movq %r14, %rdi
movq %rbx, %rsi
callq 0x5358
movl (%rax), %r15d
movq %r14, %rdi
movq %rbp, %rsi
callq 0x5358
cmpl (%rax), %r15d
je 0xb9ac
incq %rbp
jmp 0xba39
incq %rbx
jmp 0xba30
movl 0x38(%rsp), %r13d
xorl %ebx, %ebx
cmpq 0x28(%rsp), %rbx
je 0xbab5
xorl %ebp, %ebp
cmpq %rbp, %r13
je 0xbab0
cmpq %rbp, %rbx
je 0xbaab
movq %r12, %rdi
movq %rbx, %rsi
callq 0x5358
movl (%rax), %r15d
movq %r12, %rdi
movq %rbp, %rsi
callq 0x5358
cmpl (%rax), %r15d
je 0xb9ac
incq %rbp
jmp 0xba7f
incq %rbx
jmp 0xba76
xorl %r13d, %r13d
leaq 0xb8(%rsp), %r15
movq 0x18(%rsp), %rax
cmpq %rax, %r13
je 0xbb9e
xorl %eax, %eax
cmpq %rax, 0x28(%rsp)
je 0xbb96
movq %rax, 0x30(%rsp)
movq 0x50(%rsp), %rax
movq 0x8(%rax), %rbx
movq %r14, %rdi
movq %r13, %rsi
callq 0x5358
movl (%rax), %edx
leaq 0x58(%rsp), %rbp
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x7ff6
leaq 0x78(%rsp), %rdi
movq %rbp, %rsi
callq 0x7d18
movq %r12, %rdi
movq 0x30(%rsp), %rsi
callq 0x5358
leaq 0x98(%rsp), %rbx
movl (%rax), %ecx
decl %ecx
movq %rbx, %rdi
movq 0x20(%rsp), %rsi
xorl %edx, %edx
callq 0x8ba0
movq %r15, %rdi
movq %rbx, %rsi
callq 0x7d18
leaq 0x78(%rsp), %rbp
movq %rbp, %rdi
movq %r15, %rsi
callq 0x3e6e
movb %al, 0xf(%rsp)
movq %r15, %rdi
callq 0x20e0
movq %rbx, %rdi
callq 0x7d12
movq %rbp, %rdi
callq 0x20e0
leaq 0x58(%rsp), %rdi
callq 0x7d12
movq 0x30(%rsp), %rax
incq %rax
xorl %ebp, %ebp
cmpb $0x0, 0xf(%rsp)
je 0xbad0
jmp 0xb9ae
incq %r13
jmp 0xbac0
movq 0x10(%rsp), %rax
subl 0x38(%rsp), %eax
movq %rax, 0x10(%rsp)
jl 0xb9ac
xorl %ebp, %ebp
movq 0x20(%rsp), %rdi
xorl %esi, %esi
callq 0x8b20
addl 0x10(%rsp), %eax
cmpl $0x7, %eax
jg 0xb9ae
pushq $0x1
popq %rsi
movq 0x20(%rsp), %rdi
callq 0x8b20
cmpl 0x10(%rsp), %eax
jl 0xb9ac
movq 0x48(%rsp), %rax
shrq $0x2, %rax
cltq
movq %rax, 0x20(%rsp)
xorl %r15d, %r15d
leaq 0x58(%rsp), %r13
leaq 0x78(%rsp), %r12
movq 0x18(%rsp), %rax
cmpq %r15, %rax
je 0xbc64
movq %r14, %rdi
movq %r15, %rsi
callq 0x5358
movl (%rax), %edx
movq %r13, %rdi
movq 0x40(%rsp), %rsi
callq 0x7ff6
movq %r12, %rdi
movq %r13, %rsi
callq 0x7d18
movq %r12, %rdi
leaq 0x1549(%rip), %rsi      # 0xd183
callq 0x83b7
movl %eax, %ebx
movq %r12, %rdi
callq 0x20e0
movq %r13, %rdi
callq 0x7d12
incq %r15
xorl %ebp, %ebp
testb %bl, %bl
movq 0x18(%rsp), %rax
je 0xbc06
jmp 0xb9ae
cmpq 0x20(%rsp), %r15
setge %bpl
jmp 0xb9ae
jmp 0xbc74
movq %rax, %rbx
jmp 0xbc98
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x7d12
jmp 0xbc8e
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x20e0
leaq 0x58(%rsp), %rdi
callq 0x7d12
movq %rbx, %rdi
callq 0x22a0