// File: /workspace/github_cpp_makefile_star2_O3/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 $0xb8, %rsp
movq %r8, %r14
movq %rcx, %r13
movq %rdx, 0x30(%rsp)
movq %rsi, %r12
movq %rdi, %r15
xorl %ebx, %ebx
movq %rcx, %rdi
xorl %esi, %esi
callq 0xa5f8
movl %eax, %ebp
movq %r13, %rdi
movl $0x1, %esi
callq 0xa5f8
addl %ebp, %eax
cmpl $0x2, %eax
jl 0xe46d
movq %r15, 0x50(%rsp)
movq (%r12), %rbp
movq 0x8(%r12), %r15
subq %rbp, %r15
sarq $0x2, %r15
cmpq $0x2, %r15
jae 0xe481
xorl %ebx, %ebx
movl %ebx, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, 0x28(%rsp)
movq %r12, 0x20(%rsp)
movq %r14, 0x40(%rsp)
movq 0x30(%rsp), %rax
movq (%rax), %r13
movq 0x8(%rax), %rbx
testl %r15d, %r15d
jle 0xe4d5
movl %r15d, %r14d
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
xorl %r12d, %r12d
cmpq %r12, %r15
je 0xe7f5
movl (%rbp,%r12,4), %edi
leal -0x6(%rdi), %eax
cmpl $-0x5, %eax
jb 0xe46b
callq 0x2240
testl %eax, %eax
jne 0xe46b
incq %r12
cmpq %r12, %r14
jne 0xe4ae
subq %r13, %rbx
sarq $0x2, %rbx
testl %ebx, %ebx
jle 0xe51c
movl %ebx, %r14d
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
xorl %r12d, %r12d
cmpq %r12, %rbx
je 0xe819
movl (%r13,%r12,4), %edi
leal -0x8(%rdi), %eax
cmpl $-0x7, %eax
jb 0xe46b
callq 0x2240
testl %eax, %eax
jne 0xe46b
incq %r12
cmpq %r12, %r14
jne 0xe4ed
testl %r15d, %r15d
jle 0xe563
movl %r15d, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %esi, %esi
xorl %eax, %eax
cmpq %rax, %rsi
je 0xe553
cmpq %rsi, %r15
jbe 0xe801
cmpq %rax, %r15
jbe 0xe80a
movl (%rbp,%rsi,4), %edx
cmpl (%rbp,%rax,4), %edx
je 0xe46b
incq %rax
cmpq %rax, %rcx
jne 0xe52e
incq %rsi
cmpq %rcx, %rsi
jne 0xe52c
testl %ebx, %ebx
jle 0xe5aa
movl %ebx, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %esi, %esi
xorl %eax, %eax
cmpq %rax, %rsi
je 0xe59a
cmpq %rsi, %rbx
jbe 0xe825
cmpq %rax, %rbx
jbe 0xe82e
movl (%r13,%rsi,4), %edx
cmpl (%r13,%rax,4), %edx
je 0xe46b
incq %rax
cmpq %rax, %rcx
jne 0xe573
incq %rsi
cmpq %rcx, %rsi
jne 0xe571
testl %r15d, %r15d
movq 0x28(%rsp), %r14
jle 0xe71a
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %r15, %rcx
andq %rax, %rcx
movq %rcx, 0x38(%rsp)
movq %rbx, %rcx
andq %rax, %rcx
movq %rcx, 0x48(%rsp)
xorl %r8d, %r8d
leaq 0x78(%rsp), %r13
testl %ebx, %ebx
jle 0xe70c
xorl %ebp, %ebp
movq 0x20(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
cmpq %r8, %rdx
jbe 0xe853
movq 0x50(%rsp), %rcx
movq 0x8(%rcx), %rsi
movq %r8, %r12
movl (%rax,%r8,4), %edx
movq %r13, %rdi
callq 0x96b2
movq %rsp, %rdi
movq %r13, %rsi
callq 0x92ae
movq 0x30(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
cmpq %rbp, %rdx
leaq 0x98(%rsp), %r13
jbe 0xe842
movl (%rax,%rbp,4), %ecx
decl %ecx
movq %r13, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0xa6bc
leaq 0x58(%rsp), %rdi
movq %r13, %rsi
callq 0x92ae
movq 0x8(%rsp), %rdx
cmpq 0x60(%rsp), %rdx
jne 0xe691
movq 0x58(%rsp), %r13
testq %rdx, %rdx
je 0xe69b
movq (%rsp), %rdi
movq %r13, %rsi
callq 0x21b0
testl %eax, %eax
sete %r14b
jmp 0xe69e
movq 0x58(%rsp), %r13
xorl %r14d, %r14d
jmp 0xe69e
movb $0x1, %r14b
leaq 0x68(%rsp), %rax
cmpq %rax, %r13
je 0xe6b8
movq 0x68(%rsp), %rsi
incq %rsi
movq %r13, %rdi
callq 0x21a0
leaq 0x98(%rsp), %rdi
callq 0x9292
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xe6e0
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x21a0
leaq 0x78(%rsp), %r13
movq %r13, %rdi
callq 0x9292
testb %r14b, %r14b
movq 0x28(%rsp), %r14
jne 0xe46b
incq %rbp
cmpq %rbp, 0x48(%rsp)
movq %r12, %r8
jne 0xe5e5
incq %r8
cmpq 0x38(%rsp), %r8
jne 0xe5db
movl %r15d, %ebp
subl %ebx, %ebp
jl 0xe46b
xorl %ebx, %ebx
movq %r14, %rdi
xorl %esi, %esi
callq 0xa5f8
addl %ebp, %eax
cmpl $0x7, %eax
jg 0xe46d
movq %r14, %rdi
movl $0x1, %esi
callq 0xa5f8
cmpl %ebp, %eax
jl 0xe46b
testl %r15d, %r15d
jle 0xe7ee
leaq 0x10(%rsp), %r14
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
xorl %ebx, %ebx
leaq 0x78(%rsp), %r12
movq %rsp, %r13
movq 0x20(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
cmpq %rbx, %rdx
jbe 0xe85f
movl (%rax,%rbx,4), %edx
movq %r12, %rdi
movq 0x40(%rsp), %rsi
callq 0x96b2
movq %r13, %rdi
movq %r12, %rsi
callq 0x92ae
movq %r13, %rdi
leaq 0x19cd(%rip), %rsi      # 0x1017e
callq 0x2080
movl %eax, %ebp
movq (%rsp), %rdi
cmpq %r14, %rdi
je 0xe7ce
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x21a0
movq %r12, %rdi
callq 0x9292
testl %ebp, %ebp
je 0xe46b
incq %rbx
cmpq %rbx, %r15
jne 0xe770
setbe %bl
jmp 0xe46d
movb $0x1, %bl
jmp 0xe46d
leaq 0x1b5c(%rip), %rdi      # 0x10358
movq %r15, %rsi
jmp 0xe814
leaq 0x1b50(%rip), %rdi      # 0x10358
jmp 0xe814
leaq 0x1b47(%rip), %rdi      # 0x10358
movq %rax, %rsi
movq %r15, %rdx
jmp 0xe83b
leaq 0x1b38(%rip), %rdi      # 0x10358
movq %rbx, %rsi
jmp 0xe838
leaq 0x1b2c(%rip), %rdi      # 0x10358
jmp 0xe838
leaq 0x1b23(%rip), %rdi      # 0x10358
movq %rax, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x21f0
leaq 0x1b0f(%rip), %rdi      # 0x10358
movq %rbp, %rsi
xorl %eax, %eax
callq 0x21f0
leaq 0x1afe(%rip), %rdi      # 0x10358
movq %r8, %rsi
jmp 0xe83b
leaq 0x1af2(%rip), %rdi      # 0x10358
movq %rbx, %rsi
jmp 0xe83b
jmp 0xe881
jmp 0xe886
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x9292
jmp 0xe889
movq %rax, %rbx
jmp 0xe8a4
movq %rax, %rbx
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xe8a4
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x21a0
leaq 0x78(%rsp), %rdi
callq 0x9292
movq %rbx, %rdi
callq 0x2280