// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movq 0x8(%rdi), %rdx
subq (%rdi), %rdx
shrq $0x2, %rdx
xorl %esi, %esi
callq 0x1c0e
movq (%rbx), %rsi
movl (%rsi), %ecx
pushq $0xd
popq %r15
movl %ecx, %eax
cltd
idivl %r15d
cmpl $0x9, %edx
jg 0x224f
movl 0x4(%rsi), %r10d
leal 0x1(%rcx), %r11d
cmpl %r11d, %r10d
jne 0x225c
leal 0x2(%rcx), %eax
cmpl %eax, 0x8(%rsi)
jne 0x225c
leal 0x3(%rcx), %eax
cmpl %eax, 0xc(%rsi)
jne 0x225c
movl 0x10(%rsi), %r9d
movl 0x14(%rsi), %r8d
movl %r9d, %eax
cltd
idivl %r15d
movl %edx, %edi
cmpl $0xb, %edx
setl %al
incl %r9d
cmpl %r9d, %r8d
sete %dl
andb %al, %dl
cmpb $0x1, %dl
jne 0x2231
movb $0x1, %bpl
cmpl %r8d, 0x18(%rsi)
je 0x238a
movl %r8d, %eax
cltd
idivl %r15d
cmpl %edx, %edi
jne 0x225c
movl 0x18(%rsi), %eax
cltd
idivl %r15d
movb $0x1, %bpl
cmpl %edx, %edi
jne 0x225c
jmp 0x238a
cmpl $0xa, %edx
jne 0x22d0
movl 0x4(%rsi), %r10d
leal 0x1(%rcx), %r11d
cmpl %r11d, %r10d
jne 0x22d0
addl $0x2, %ecx
cmpl %ecx, 0x8(%rsi)
jne 0x22d0
movl 0xc(%rsi), %r8d
movl 0x10(%rsi), %edi
movl %r8d, %eax
cltd
idivl %r15d
movl %edx, %ecx
cmpl $0xa, %edx
setl %al
leal 0x1(%r8), %edx
cmpl %edx, %edi
sete %dl
andb %al, %dl
cmpb $0x1, %dl
jne 0x22a9
leal 0x2(%r8), %eax
cmpl %eax, 0x14(%rsi)
jne 0x22a9
addl $0x3, %r8d
movb $0x1, %bpl
cmpl %r8d, 0x18(%rsi)
je 0x238a
movl %edi, %eax
cltd
idivl %r15d
cmpl %edx, %ecx
jne 0x22d0
movl 0x14(%rsi), %eax
cltd
idivl %r15d
cmpl %edx, %ecx
jne 0x22d0
movl 0x18(%rsi), %eax
cltd
idivl %r15d
movb $0x1, %bpl
cmpl %edx, %ecx
je 0x238a
movq %rsp, %r14
andq $0x0, 0x10(%r14)
xorps %xmm0, %xmm0
movaps %xmm0, (%r14)
xorl %r12d, %r12d
xorl %r13d, %r13d
movq 0x8(%rbx), %rax
subq %rsi, %rax
sarq $0x2, %rax
cmpq %r13, %rax
jbe 0x2320
movl (%rsi,%r12), %eax
cltd
idivl %r15d
movl %edx, %ecx
movl (%rsi), %eax
cltd
idivl %r15d
cmpl %edx, %ecx
je 0x2317
addq %r12, %rsi
movq %r14, %rdi
callq 0x2ac8
movq (%rbx), %rsi
incq %r13
addq $0x4, %r12
jmp 0x22e5
movq (%rsp), %rsi
movq 0x8(%rsp), %rdi
subq %rsi, %rdi
sarq $0x2, %rdi
leaq -0x3(%rdi), %rax
cmpq $0x1, %rax
ja 0x2354
movb $0x1, %al
xorl %ecx, %ecx
cmpq %rcx, %rdi
je 0x2358
movl (%rsi), %edx
addl %ecx, %edx
cmpl (%rsi,%rcx,4), %edx
sete %dl
andb %dl, %al
incq %rcx
jmp 0x233e
xorl %ebp, %ebp
jmp 0x2382
movb $0x1, %bpl
testb $0x1, %al
jne 0x2382
xorl %r8d, %r8d
cmpq %r8, %rdi
sete %bpl
je 0x2382
movl (%rsi,%r8,4), %eax
cltd
idivl %r15d
movl %edx, %ecx
movl (%rsi), %eax
cltd
idivl %r15d
incq %r8
cmpl %edx, %ecx
je 0x2362
movq %rsp, %rdi
callq 0x2c46
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq %rsp, %rdi
callq 0x2c46
movq %rbx, %rdi
callq 0x1160