// File: /workspace/github_cpp_makefile_star2_O1/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 $0xc8, %rsp
movq %r8, 0x58(%rsp)
movq %rcx, %r13
movq %rdx, %rbp
movq %rsi, %r12
movq %rdi, 0x60(%rsp)
xorl %ebx, %ebx
movq %rcx, %rdi
xorl %esi, %esi
callq 0xa61e
movl %eax, %r14d
movq %r13, %rdi
movl $0x1, %esi
callq 0xa61e
addl %r14d, %eax
cmpl $0x2, %eax
jl 0xe56e
movq (%r12), %r14
movq 0x8(%r12), %r15
subq %r14, %r15
sarq $0x2, %r15
cmpq $0x2, %r15
jae 0xe585
xorl %ebx, %ebx
andb $0x1, %bl
movl %ebx, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, 0x38(%rsp)
movq %r12, 0x8(%rsp)
movq (%rbp), %rbx
movq %rbp, 0x40(%rsp)
movq 0x8(%rbp), %r13
testl %r15d, %r15d
jle 0xe5d3
movl %r15d, %ebp
andl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
xorl %r12d, %r12d
cmpq %r12, %r15
je 0xe941
movl (%r14,%r12,4), %edi
leal -0x6(%rdi), %eax
cmpl $-0x5, %eax
jb 0xe56c
callq 0x2240
testl %eax, %eax
jne 0xe56c
incq %r12
cmpq %r12, %rbp
jne 0xe5ad
subq %rbx, %r13
sarq $0x2, %r13
testl %r13d, %r13d
jle 0xe619
movl %r13d, %ebp
andl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
xorl %r12d, %r12d
cmpq %r12, %r13
je 0xe97a
movl (%rbx,%r12,4), %edi
leal -0x8(%rdi), %eax
cmpl $-0x7, %eax
jb 0xe56c
callq 0x2240
testl %eax, %eax
jne 0xe56c
incq %r12
cmpq %r12, %rbp
jne 0xe5eb
testl %r15d, %r15d
setg %cl
jle 0xe66d
movl %r15d, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
xorl %esi, %esi
xorl %eax, %eax
cmpq %rax, %rsi
je 0xe64f
cmpq %rsi, %r15
jbe 0xe94d
cmpq %rax, %r15
jbe 0xe956
movl (%r14,%rsi,4), %edi
cmpl (%r14,%rax,4), %edi
je 0xe664
incq %rax
cmpq %rax, %rdx
jne 0xe62e
incq %rsi
cmpq %rdx, %rsi
setb %cl
jne 0xe62c
jmp 0xe66d
testb $0x1, %cl
jne 0xe56c
testl %r13d, %r13d
setg %cl
movq 0x40(%rsp), %rbp
jle 0xe6c4
movl %r13d, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
xorl %esi, %esi
xorl %eax, %eax
cmpq %rax, %rsi
je 0xe6a6
cmpq %rsi, %r13
jbe 0xe965
cmpq %rax, %r13
jbe 0xe96e
movl (%rbx,%rsi,4), %edi
cmpl (%rbx,%rax,4), %edi
je 0xe6bb
incq %rax
cmpq %rax, %rdx
jne 0xe687
incq %rsi
cmpq %rdx, %rsi
setb %cl
jne 0xe685
jmp 0xe6c4
testb $0x1, %cl
jne 0xe56c
testl %r15d, %r15d
setg %cl
jle 0xe83b
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %r15, %rdx
andq %rax, %rdx
movq %rdx, 0x48(%rsp)
movq %r13, %rdx
andq %rax, %rdx
movq %rdx, 0x50(%rsp)
xorl %r8d, %r8d
leaq 0xa8(%rsp), %rbx
movq %r13, 0x30(%rsp)
movb %cl, 0x7(%rsp)
testl %r13d, %r13d
jle 0xe825
xorl %r14d, %r14d
movq 0x8(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
cmpq %r8, %rdx
jbe 0xe99f
movq 0x60(%rsp), %rcx
movq 0x8(%rcx), %rsi
movq %r8, %r13
movl (%rax,%r8,4), %edx
leaq 0x88(%rsp), %r12
movq %r12, %rdi
callq 0x96fa
leaq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x92fe
movq (%rbp), %rax
movq 0x8(%rbp), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
cmpq %r14, %rdx
jbe 0xe98e
movl (%rax,%r14,4), %ecx
decl %ecx
movq %rbx, %rdi
movq 0x38(%rsp), %rsi
xorl %edx, %edx
callq 0xa6f2
leaq 0x68(%rsp), %rdi
movq %rbx, %rsi
callq 0x92fe
movq 0x18(%rsp), %rdx
cmpq 0x70(%rsp), %rdx
jne 0xe7b6
testq %rdx, %rdx
je 0xe7ba
movq 0x68(%rsp), %rsi
movq 0x10(%rsp), %rdi
callq 0x21b0
testl %eax, %eax
sete %bpl
jmp 0xe7bd
xorl %ebp, %ebp
jmp 0xe7bd
movb $0x1, %bpl
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0xe7d9
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x21a0
movq %rbx, %rdi
callq 0x92e2
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xe7fd
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21a0
leaq 0x88(%rsp), %rdi
callq 0x92e2
testb %bpl, %bpl
jne 0xe846
incq %r14
cmpq %r14, 0x50(%rsp)
movq 0x40(%rsp), %rbp
movq %r13, %r8
jne 0xe70b
incq %r8
cmpq 0x48(%rsp), %r8
setb %cl
movq 0x30(%rsp), %r13
jne 0xe6fb
cmpl %r13d, %r15d
jl 0xe56c
jmp 0xe85d
movq 0x30(%rsp), %r13
cmpl %r13d, %r15d
setl %al
orb 0x7(%rsp), %al
testb $0x1, %al
jne 0xe56c
xorl %ebx, %ebx
movq 0x38(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0xa61e
movl %r15d, %ebp
subl %r13d, %ebp
addl %ebp, %eax
cmpl $0x7, %eax
jg 0xe56e
movq %r14, %rdi
movl $0x1, %esi
callq 0xa61e
cmpl %ebp, %eax
jl 0xe56c
testl %r15d, %r15d
setle %bl
jle 0xe56e
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
xorl %r14d, %r14d
leaq 0x88(%rsp), %r12
leaq 0x10(%rsp), %r13
movq 0x8(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
cmpq %r14, %rdx
jbe 0xe9ab
movl (%rax,%r14,4), %edx
movq %r12, %rdi
movq 0x58(%rsp), %rsi
callq 0x96fa
movq %r13, %rdi
movq %r12, %rsi
callq 0x92fe
movq %r13, %rdi
leaq 0x1885(%rip), %rsi      # 0x1017e
callq 0x2080
movl %eax, %ebp
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xe91c
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21a0
movq %r12, %rdi
callq 0x92e2
testl %ebp, %ebp
movq 0x8(%rsp), %rcx
je 0xe56e
incq %r14
cmpq %r15, %r14
setae %bl
jne 0xe8bc
jmp 0xe56e
leaq 0x1a00(%rip), %rdi      # 0x10348
movq %r15, %rsi
jmp 0xe960
leaq 0x19f4(%rip), %rdi      # 0x10348
jmp 0xe960
leaq 0x19eb(%rip), %rdi      # 0x10348
movq %rax, %rsi
movq %r15, %rdx
jmp 0xe987
leaq 0x19dc(%rip), %rdi      # 0x10348
jmp 0xe984
leaq 0x19d3(%rip), %rdi      # 0x10348
movq %rax, %rsi
jmp 0xe984
leaq 0x19c7(%rip), %rdi      # 0x10348
movq %r13, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x21f0
leaq 0x19b3(%rip), %rdi      # 0x10348
movq %r14, %rsi
xorl %eax, %eax
callq 0x21f0
leaq 0x19a2(%rip), %rdi      # 0x10348
movq %r8, %rsi
jmp 0xe987
leaq 0x1996(%rip), %rdi      # 0x10348
movq %r14, %rsi
jmp 0xe987
jmp 0xe9cd
jmp 0xe9d2
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x92e2
jmp 0xe9d5
movq %rax, %rbx
jmp 0xe9f1
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xe9f1
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21a0
leaq 0x88(%rsp), %rdi
callq 0x92e2
movq %rbx, %rdi
callq 0x2280