// File: ljc2154[P]Rummy/rummy.cpp
// Function: isWinner(std::vector<int, std::allocator<int>>)
bool isWinner(vector<int> hand)
{
	mergeSort(hand, 0, hand.size());		// sort hand first

	/* Check if first 4 are in a row */
	if (hand[0] % 13 < 10 && hand[1] == hand[0] + 1 && hand[2] == hand[0] + 2
				&& hand[3] == hand[0] + 3)
	{
		/* Check if last 3 are in a row */
		if (hand[4] % 13 < 11 && hand[5] == hand[4] + 1 && hand[6] == hand[4] + 1)
			return true;
		/* check if last 3 are the same rank */
		if (hand[4] % 13 == hand[5] % 13 && hand[4] % 13 == hand[6] % 13)
			return true;
	}

	/* Check if first 3 are in a row */
	if (hand[0] % 13 < 11 && hand[1] == hand[0] + 1 && hand[2] == hand[0] + 2)
	{
		/* Check if last 4 are in a row */
		if (hand[3] % 13 < 10 && hand[4] == hand[3] + 1 && hand[5] == hand[3] + 2
					&& hand[6] == hand[3] + 3)
			return true;
		/* Check if last 4 are the same rank */
		if (hand[3] % 13 == hand[4] % 13 && hand[3] % 13 == hand[5] % 13
					&& hand[3] % 13 == hand[6] % 13)
			return true;
	}

	/* Add cards not of same rank as first to a list */
	vector<int> nonMatches;
	for (int i = 0; i < hand.size(); i++)
	{
		if (hand[i] % 13 != hand[0] % 13)
			nonMatches.push_back(hand[i]);
	}

	/* Check for a legitimate number of nonmatches (3 or 4) */
	if (nonMatches.size() != 3 && nonMatches.size() != 4)
		return false;

	/* Check if nonmatches are not in a row */
	bool areInARow = true;
	for (int i = 0; i < nonMatches.size(); i++)
	{
		if (nonMatches[i] != nonMatches[0] + i)
			areInARow = false;
	}
	if (areInARow)
		return true;

	/* Check if nonmatches are not the same */
	for (int i = 0; i < nonMatches.size(); i++)
	{
		if (nonMatches[i] % 13 != nonMatches[0] % 13)
			return false;
	}
	return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x58(%rbp)
movq %rdi, -0x10(%rbp)
callq 0x4130
movq -0x58(%rbp), %rdi
movl %eax, %edx
xorl %esi, %esi
callq 0x22f0
movq -0x58(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x4110
movl (%rax), %eax
movl $0xd, %ecx
cltd
idivl %ecx
cmpl $0xa, %edx
jge 0x2cb7
movq -0x58(%rbp), %rdi
movl $0x1, %esi
callq 0x4110
movq -0x58(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x5c(%rbp)
xorl %eax, %eax
movl %eax, %esi
callq 0x4110
movq %rax, %rcx
movl -0x5c(%rbp), %eax
movl (%rcx), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jne 0x2cb7
movq -0x58(%rbp), %rdi
movl $0x2, %esi
callq 0x4110
movq -0x58(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x60(%rbp)
xorl %eax, %eax
movl %eax, %esi
callq 0x4110
movq %rax, %rcx
movl -0x60(%rbp), %eax
movl (%rcx), %ecx
addl $0x2, %ecx
cmpl %ecx, %eax
jne 0x2cb7
movq -0x58(%rbp), %rdi
movl $0x3, %esi
callq 0x4110
movq -0x58(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x64(%rbp)
xorl %eax, %eax
movl %eax, %esi
callq 0x4110
movq %rax, %rcx
movl -0x64(%rbp), %eax
movl (%rcx), %ecx
addl $0x3, %ecx
cmpl %ecx, %eax
jne 0x2cb7
movq -0x58(%rbp), %rdi
movl $0x4, %esi
callq 0x4110
movl (%rax), %eax
movl $0xd, %ecx
cltd
idivl %ecx
cmpl $0xb, %edx
jge 0x2c34
movq -0x58(%rbp), %rdi
movl $0x5, %esi
callq 0x4110
movq -0x58(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x68(%rbp)
movl $0x4, %esi
callq 0x4110
movq %rax, %rcx
movl -0x68(%rbp), %eax
movl (%rcx), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jne 0x2c34
movq -0x58(%rbp), %rdi
movl $0x6, %esi
callq 0x4110
movq -0x58(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x6c(%rbp)
movl $0x4, %esi
callq 0x4110
movq %rax, %rcx
movl -0x6c(%rbp), %eax
movl (%rcx), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jne 0x2c34
movb $0x1, -0x1(%rbp)
jmp 0x30e5
movq -0x58(%rbp), %rdi
movl $0x4, %esi
callq 0x4110
movq -0x58(%rbp), %rdi
movl (%rax), %eax
movl $0xd, %ecx
cltd
idivl %ecx
movl %edx, -0x70(%rbp)
movl $0x5, %esi
callq 0x4110
movl (%rax), %eax
movl $0xd, %ecx
cltd
idivl %ecx
movl %edx, %eax
movl -0x70(%rbp), %edx
cmpl %eax, %edx
jne 0x2cb5
movq -0x58(%rbp), %rdi
movl $0x4, %esi
callq 0x4110
movq -0x58(%rbp), %rdi
movl (%rax), %eax
movl $0xd, %ecx
cltd
idivl %ecx
movl %edx, -0x74(%rbp)
movl $0x6, %esi
callq 0x4110
movl (%rax), %eax
movl $0xd, %ecx
cltd
idivl %ecx
movl %edx, %eax
movl -0x74(%rbp), %edx
cmpl %eax, %edx
jne 0x2cb5
movb $0x1, -0x1(%rbp)
jmp 0x30e5
jmp 0x2cb7
movq -0x58(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x4110
movl (%rax), %eax
movl $0xd, %ecx
cltd
idivl %ecx
cmpl $0xb, %edx
jge 0x2ed8
movq -0x58(%rbp), %rdi
movl $0x1, %esi
callq 0x4110
movq -0x58(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x78(%rbp)
xorl %eax, %eax
movl %eax, %esi
callq 0x4110
movq %rax, %rcx
movl -0x78(%rbp), %eax
movl (%rcx), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jne 0x2ed8
movq -0x58(%rbp), %rdi
movl $0x2, %esi
callq 0x4110
movq -0x58(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x7c(%rbp)
xorl %eax, %eax
movl %eax, %esi
callq 0x4110
movq %rax, %rcx
movl -0x7c(%rbp), %eax
movl (%rcx), %ecx
addl $0x2, %ecx
cmpl %ecx, %eax
jne 0x2ed8
movq -0x58(%rbp), %rdi
movl $0x3, %esi
callq 0x4110
movl (%rax), %eax
movl $0xd, %ecx
cltd
idivl %ecx
cmpl $0xa, %edx
jge 0x2e03
movq -0x58(%rbp), %rdi
movl $0x4, %esi
callq 0x4110
movq -0x58(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x80(%rbp)
movl $0x3, %esi
callq 0x4110
movq %rax, %rcx
movl -0x80(%rbp), %eax
movl (%rcx), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jne 0x2e03
movq -0x58(%rbp), %rdi
movl $0x5, %esi
callq 0x4110
movq -0x58(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x84(%rbp)
movl $0x3, %esi
callq 0x4110
movq %rax, %rcx
movl -0x84(%rbp), %eax
movl (%rcx), %ecx
addl $0x2, %ecx
cmpl %ecx, %eax
jne 0x2e03
movq -0x58(%rbp), %rdi
movl $0x6, %esi
callq 0x4110
movq -0x58(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x88(%rbp)
movl $0x3, %esi
callq 0x4110
movq %rax, %rcx
movl -0x88(%rbp), %eax
movl (%rcx), %ecx
addl $0x3, %ecx
cmpl %ecx, %eax
jne 0x2e03
movb $0x1, -0x1(%rbp)
jmp 0x30e5
movq -0x58(%rbp), %rdi
movl $0x3, %esi
callq 0x4110
movq -0x58(%rbp), %rdi
movl (%rax), %eax
movl $0xd, %ecx
cltd
idivl %ecx
movl %edx, -0x8c(%rbp)
movl $0x4, %esi
callq 0x4110
movl (%rax), %eax
movl $0xd, %ecx
cltd
idivl %ecx
movl %edx, %eax
movl -0x8c(%rbp), %edx
cmpl %eax, %edx
jne 0x2ed6
movq -0x58(%rbp), %rdi
movl $0x3, %esi
callq 0x4110
movq -0x58(%rbp), %rdi
movl (%rax), %eax
movl $0xd, %ecx
cltd
idivl %ecx
movl %edx, -0x90(%rbp)
movl $0x5, %esi
callq 0x4110
movl (%rax), %eax
movl $0xd, %ecx
cltd
idivl %ecx
movl %edx, %eax
movl -0x90(%rbp), %edx
cmpl %eax, %edx
jne 0x2ed6
movq -0x58(%rbp), %rdi
movl $0x3, %esi
callq 0x4110
movq -0x58(%rbp), %rdi
movl (%rax), %eax
movl $0xd, %ecx
cltd
idivl %ecx
movl %edx, -0x94(%rbp)
movl $0x6, %esi
callq 0x4110
movl (%rax), %eax
movl $0xd, %ecx
cltd
idivl %ecx
movl %edx, %eax
movl -0x94(%rbp), %edx
cmpl %eax, %edx
jne 0x2ed6
movb $0x1, -0x1(%rbp)
jmp 0x30e5
jmp 0x2ed8
leaq -0x28(%rbp), %rdi
callq 0x4150
movl $0x0, -0x2c(%rbp)
movq -0x58(%rbp), %rdi
movslq -0x2c(%rbp), %rax
movq %rax, -0xa0(%rbp)
callq 0x4130
movq %rax, %rcx
movq -0xa0(%rbp), %rax
cmpq %rcx, %rax
jae 0x2f96
movq -0x58(%rbp), %rdi
movslq -0x2c(%rbp), %rsi
callq 0x4110
movq -0x58(%rbp), %rdi
movl (%rax), %eax
movl $0xd, %ecx
cltd
idivl %ecx
movl %edx, -0xa4(%rbp)
xorl %eax, %eax
movl %eax, %esi
callq 0x4110
movl (%rax), %eax
movl $0xd, %ecx
cltd
idivl %ecx
movl %edx, %eax
movl -0xa4(%rbp), %edx
cmpl %eax, %edx
je 0x2f86
movq -0x58(%rbp), %rdi
movslq -0x2c(%rbp), %rsi
callq 0x4110
movq %rax, %rsi
leaq -0x28(%rbp), %rdi
callq 0x4170
jmp 0x2f6a
jmp 0x2f86
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x41e0
jmp 0x30f3
jmp 0x2f88
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x2ee8
leaq -0x28(%rbp), %rdi
callq 0x4130
cmpq $0x3, %rax
je 0x2fc4
leaq -0x28(%rbp), %rdi
callq 0x4130
cmpq $0x4, %rax
je 0x2fc4
movb $0x0, -0x1(%rbp)
movl $0x1, -0x40(%rbp)
jmp 0x30dc
movb $0x1, -0x41(%rbp)
movl $0x0, -0x48(%rbp)
movslq -0x48(%rbp), %rax
movq %rax, -0xb0(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x4130
movq %rax, %rcx
movq -0xb0(%rbp), %rax
cmpq %rcx, %rax
jae 0x3037
movslq -0x48(%rbp), %rsi
leaq -0x28(%rbp), %rdi
callq 0x4110
movl (%rax), %eax
movl %eax, -0xb4(%rbp)
leaq -0x28(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x4110
movq %rax, %rcx
movl -0xb4(%rbp), %eax
movl (%rcx), %ecx
addl -0x48(%rbp), %ecx
cmpl %ecx, %eax
je 0x302a
movb $0x0, -0x41(%rbp)
jmp 0x302c
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x2fcf
testb $0x1, -0x41(%rbp)
je 0x304d
movb $0x1, -0x1(%rbp)
movl $0x1, -0x40(%rbp)
jmp 0x30dc
movl $0x0, -0x4c(%rbp)
movslq -0x4c(%rbp), %rax
movq %rax, -0xc0(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x4130
movq %rax, %rcx
movq -0xc0(%rbp), %rax
cmpq %rcx, %rax
jae 0x30d1
movslq -0x4c(%rbp), %rsi
leaq -0x28(%rbp), %rdi
callq 0x4110
movl (%rax), %eax
movl $0xd, %ecx
cltd
idivl %ecx
movl %edx, -0xc4(%rbp)
leaq -0x28(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x4110
movl (%rax), %eax
movl $0xd, %ecx
cltd
idivl %ecx
movl %edx, %eax
movl -0xc4(%rbp), %edx
cmpl %eax, %edx
je 0x30c4
movb $0x0, -0x1(%rbp)
movl $0x1, -0x40(%rbp)
jmp 0x30dc
jmp 0x30c6
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x3054
movb $0x1, -0x1(%rbp)
movl $0x1, -0x40(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x41e0
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xd0, %rsp
popq %rbp
retq
movq -0x38(%rbp), %rdi
callq 0x1170
nopl (%rax)