// File: 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
movq %rsp, %rbp
subq $0x190, %rsp            # imm = 0x190
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x140(%rbp)
movq -0x28(%rbp), %rdi
xorl %esi, %esi
callq 0x14730
movl %eax, -0x134(%rbp)
movq -0x28(%rbp), %rdi
movl $0x1, %esi
callq 0x14730
movl %eax, %ecx
movl -0x134(%rbp), %eax
addl %ecx, %eax
cmpl $0x2, %eax
jl 0x1b307
movq -0x18(%rbp), %rdi
callq 0x9b40
cmpq $0x2, %rax
jae 0x1b310
movb $0x0, -0x1(%rbp)
jmp 0x1b7c4
movq -0x18(%rbp), %rdi
callq 0x9b40
movl %eax, -0x34(%rbp)
movq -0x20(%rbp), %rdi
callq 0x9b40
movl %eax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0x1b38a
movq -0x18(%rbp), %rdi
movslq -0x3c(%rbp), %rsi
callq 0x9b60
cmpl $0x5, (%rax)
jg 0x1b374
movq -0x18(%rbp), %rdi
movslq -0x3c(%rbp), %rsi
callq 0x9b60
cmpl $0x1, (%rax)
jl 0x1b374
movq -0x18(%rbp), %rdi
movslq -0x3c(%rbp), %rsi
callq 0x9b60
movl (%rax), %edi
callq 0x2320
cmpl $0x0, %eax
je 0x1b37d
movb $0x0, -0x1(%rbp)
jmp 0x1b7c4
jmp 0x1b37f
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x1b32f
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x38(%rbp), %eax
jge 0x1b3ec
movq -0x20(%rbp), %rdi
movslq -0x40(%rbp), %rsi
callq 0x9b60
cmpl $0x7, (%rax)
jg 0x1b3d6
movq -0x20(%rbp), %rdi
movslq -0x40(%rbp), %rsi
callq 0x9b60
cmpl $0x1, (%rax)
jl 0x1b3d6
movq -0x20(%rbp), %rdi
movslq -0x40(%rbp), %rsi
callq 0x9b60
movl (%rax), %edi
callq 0x2320
cmpl $0x0, %eax
je 0x1b3df
movb $0x0, -0x1(%rbp)
jmp 0x1b7c4
jmp 0x1b3e1
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x1b391
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0x1b464
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0x1b457
movl -0x44(%rbp), %eax
cmpl -0x48(%rbp), %eax
je 0x1b44a
movq -0x18(%rbp), %rdi
movslq -0x44(%rbp), %rsi
callq 0x9b60
movl (%rax), %eax
movl %eax, -0x144(%rbp)
movq -0x18(%rbp), %rdi
movslq -0x48(%rbp), %rsi
callq 0x9b60
movq %rax, %rcx
movl -0x144(%rbp), %eax
cmpl (%rcx), %eax
jne 0x1b44a
movb $0x0, -0x1(%rbp)
jmp 0x1b7c4
jmp 0x1b44c
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x1b402
jmp 0x1b459
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x1b3f3
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x38(%rbp), %eax
jge 0x1b4dc
movl $0x0, -0x50(%rbp)
movl -0x50(%rbp), %eax
cmpl -0x38(%rbp), %eax
jge 0x1b4cf
movl -0x4c(%rbp), %eax
cmpl -0x50(%rbp), %eax
je 0x1b4c2
movq -0x20(%rbp), %rdi
movslq -0x4c(%rbp), %rsi
callq 0x9b60
movl (%rax), %eax
movl %eax, -0x148(%rbp)
movq -0x20(%rbp), %rdi
movslq -0x50(%rbp), %rsi
callq 0x9b60
movq %rax, %rcx
movl -0x148(%rbp), %eax
cmpl (%rcx), %eax
jne 0x1b4c2
movb $0x0, -0x1(%rbp)
jmp 0x1b7c4
jmp 0x1b4c4
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x1b47a
jmp 0x1b4d1
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x1b46b
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0x1b67f
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl -0x38(%rbp), %eax
jge 0x1b66f
movq -0x140(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x158(%rbp)
movq -0x18(%rbp), %rdi
movslq -0x54(%rbp), %rsi
callq 0x9b60
movq -0x158(%rbp), %rsi
movl (%rax), %edx
leaq -0x98(%rbp), %rdi
movq %rdi, -0x150(%rbp)
callq 0x132c0
movq -0x150(%rbp), %rsi
leaq -0x78(%rbp), %rdi
callq 0x12d60
jmp 0x1b54f
movq -0x28(%rbp), %rax
movq %rax, -0x168(%rbp)
movq -0x20(%rbp), %rdi
movslq -0x58(%rbp), %rsi
callq 0x9b60
movq %rax, -0x160(%rbp)
jmp 0x1b570
movq -0x168(%rbp), %rsi
movq -0x160(%rbp), %rax
movl (%rax), %ecx
decl %ecx
leaq -0xe8(%rbp), %rdi
xorl %edx, %edx
callq 0x14820
jmp 0x1b592
leaq -0xc8(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x12d60
jmp 0x1b5a7
leaq -0x78(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x5f90
movb %al, -0x169(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x2130
leaq -0xe8(%rbp), %rdi
callq 0x12d40
leaq -0x78(%rbp), %rdi
callq 0x2130
leaq -0x98(%rbp), %rdi
callq 0x12d40
movb -0x169(%rbp), %al
testb $0x1, %al
jne 0x1b5f6
jmp 0x1b65f
movb $0x0, -0x1(%rbp)
jmp 0x1b7c4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x1b64e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x1b645
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x12d40
leaq -0x78(%rbp), %rdi
callq 0x2130
leaq -0x98(%rbp), %rdi
callq 0x12d40
jmp 0x1b7d2
jmp 0x1b661
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x1b4f6
jmp 0x1b671
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x1b4e3
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
jl 0x1b6b5
movq -0x28(%rbp), %rdi
xorl %esi, %esi
callq 0x14730
addl -0x34(%rbp), %eax
subl -0x38(%rbp), %eax
cmpl $0x7, %eax
jg 0x1b6b5
movq -0x28(%rbp), %rdi
movl $0x1, %esi
callq 0x14730
movl -0x34(%rbp), %ecx
subl -0x38(%rbp), %ecx
cmpl %ecx, %eax
jge 0x1b6be
movb $0x0, -0x1(%rbp)
jmp 0x1b7c4
movl $0x0, -0xec(%rbp)
movl -0xec(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0x1b7be
movq -0x30(%rbp), %rax
movq %rax, -0x180(%rbp)
movq -0x18(%rbp), %rdi
movslq -0xec(%rbp), %rsi
callq 0x9b60
movq -0x180(%rbp), %rsi
movl (%rax), %edx
leaq -0x130(%rbp), %rdi
movq %rdi, -0x178(%rbp)
callq 0x132c0
movq -0x178(%rbp), %rsi
leaq -0x110(%rbp), %rdi
callq 0x12d60
jmp 0x1b723
leaq 0x2a59(%rip), %rsi      # 0x1e183
leaq -0x110(%rbp), %rdi
callq 0x13920
movb %al, -0x181(%rbp)
jmp 0x1b73e
leaq -0x110(%rbp), %rdi
callq 0x2130
leaq -0x130(%rbp), %rdi
callq 0x12d40
movb -0x181(%rbp), %al
testb $0x1, %al
jne 0x1b762
jmp 0x1b7a8
movb $0x0, -0x1(%rbp)
jmp 0x1b7c4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x1b79a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x2130
leaq -0x130(%rbp), %rdi
callq 0x12d40
jmp 0x1b7d2
jmp 0x1b7aa
movl -0xec(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xec(%rbp)
jmp 0x1b6c8
jmp 0x1b7c0
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x190, %rsp            # imm = 0x190
popq %rbp
retq
movq -0xa0(%rbp), %rdi
callq 0x2360
nop