// File: /workspace/github_cpp_makefile_star2_O1/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 %r12
pushq %rbx
subq $0x20, %rsp
movq %rdi, %rbx
movq 0x8(%rdi), %rdx
subq (%rdi), %rdx
shrq $0x2, %rdx
xorl %esi, %esi
callq 0x23c7
movq (%rbx), %rax
movslq (%rax), %rcx
imulq $0x4ec4ec4f, %rcx, %rdx # imm = 0x4EC4EC4F
movq %rdx, %rsi
shrq $0x3f, %rsi
sarq $0x22, %rdx
addl %esi, %edx
leal (%rdx,%rdx,2), %esi
leal (%rdx,%rsi,4), %esi
movl %ecx, %edx
subl %esi, %edx
cmpl $0x9, %edx
jg 0x2c40
leal 0x1(%rcx), %esi
cmpl %esi, 0x4(%rax)
jne 0x2c40
leal 0x2(%rcx), %esi
cmpl %esi, 0x8(%rax)
jne 0x2c40
leal 0x3(%rcx), %esi
cmpl %esi, 0xc(%rax)
jne 0x2c40
movslq 0x10(%rax), %rdi
imulq $0x4ec4ec4f, %rdi, %rsi # imm = 0x4EC4EC4F
movq %rsi, %r8
shrq $0x3f, %r8
sarq $0x22, %rsi
addl %r8d, %esi
leal (%rsi,%rsi,2), %r8d
leal (%rsi,%r8,4), %r8d
movl %edi, %esi
subl %r8d, %esi
cmpl $0xa, %esi
jg 0x2be9
incl %edi
cmpl %edi, 0x14(%rax)
jne 0x2be9
movb $0x1, %bpl
cmpl %edi, 0x18(%rax)
je 0x2eba
movslq 0x14(%rax), %rdi
imulq $0x4ec4ec4f, %rdi, %r8  # imm = 0x4EC4EC4F
movq %r8, %r9
shrq $0x3f, %r9
sarq $0x22, %r8
addl %r9d, %r8d
leal (%r8,%r8,2), %r9d
leal (%r8,%r9,4), %r8d
subl %r8d, %edi
cmpl %edi, %esi
jne 0x2c40
movslq 0x18(%rax), %rdi
imulq $0x4ec4ec4f, %rdi, %r8  # imm = 0x4EC4EC4F
movq %r8, %r9
shrq $0x3f, %r9
sarq $0x22, %r8
addl %r9d, %r8d
leal (%r8,%r8,2), %r9d
leal (%r8,%r9,4), %r8d
subl %r8d, %edi
movb $0x1, %bpl
cmpl %edi, %esi
je 0x2eba
cmpl $0xa, %edx
jg 0x2d1a
leal 0x1(%rcx), %edx
cmpl %edx, 0x4(%rax)
jne 0x2d1a
addl $0x2, %ecx
cmpl %ecx, 0x8(%rax)
jne 0x2d1a
movslq 0xc(%rax), %rdx
imulq $0x4ec4ec4f, %rdx, %rcx # imm = 0x4EC4EC4F
movq %rcx, %rsi
shrq $0x3f, %rsi
sarq $0x22, %rcx
addl %esi, %ecx
leal (%rcx,%rcx,2), %esi
leal (%rcx,%rsi,4), %esi
movl %edx, %ecx
subl %esi, %ecx
cmpl $0x9, %ecx
jg 0x2ca7
leal 0x1(%rdx), %esi
cmpl %esi, 0x10(%rax)
jne 0x2ca7
leal 0x2(%rdx), %esi
cmpl %esi, 0x14(%rax)
jne 0x2ca7
addl $0x3, %edx
movb $0x1, %bpl
cmpl %edx, 0x18(%rax)
je 0x2eba
movslq 0x10(%rax), %rdx
imulq $0x4ec4ec4f, %rdx, %rsi # imm = 0x4EC4EC4F
movq %rsi, %rdi
shrq $0x3f, %rdi
sarq $0x22, %rsi
addl %edi, %esi
leal (%rsi,%rsi,2), %edi
leal (%rsi,%rdi,4), %esi
subl %esi, %edx
cmpl %edx, %ecx
jne 0x2d1a
movslq 0x14(%rax), %rdx
imulq $0x4ec4ec4f, %rdx, %rsi # imm = 0x4EC4EC4F
movq %rsi, %rdi
shrq $0x3f, %rdi
sarq $0x22, %rsi
addl %edi, %esi
leal (%rsi,%rsi,2), %edi
leal (%rsi,%rdi,4), %esi
subl %esi, %edx
cmpl %edx, %ecx
jne 0x2d1a
movslq 0x18(%rax), %rax
imulq $0x4ec4ec4f, %rax, %rdx # imm = 0x4EC4EC4F
movq %rdx, %rsi
shrq $0x3f, %rsi
sarq $0x22, %rdx
addl %esi, %edx
leal (%rdx,%rdx,2), %esi
leal (%rdx,%rsi,4), %edx
subl %edx, %eax
movb $0x1, %bpl
cmpl %eax, %ecx
je 0x2eba
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movq (%rbx), %rdx
cmpq %rdx, 0x8(%rbx)
je 0x2dca
xorl %r15d, %r15d
movq %rsp, %r14
xorl %r12d, %r12d
movslq (%rdx,%r15), %rax
imulq $0x4ec4ec4f, %rax, %rcx # imm = 0x4EC4EC4F
movq %rcx, %rsi
shrq $0x3f, %rsi
sarq $0x22, %rcx
addl %esi, %ecx
leal (%rcx,%rcx,2), %esi
leal (%rcx,%rsi,4), %ecx
movl %eax, %esi
subl %ecx, %esi
movslq (%rdx), %rcx
imulq $0x4ec4ec4f, %rcx, %rdi # imm = 0x4EC4EC4F
movq %rdi, %r8
shrq $0x3f, %r8
sarq $0x22, %rdi
addl %r8d, %edi
leal (%rdi,%rdi,2), %r8d
leal (%rdi,%r8,4), %edi
subl %edi, %ecx
cmpl %ecx, %esi
je 0x2dac
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x2da1
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x2dac
addq %r15, %rdx
movq %r14, %rdi
callq 0x3cf6
incq %r12
movq (%rbx), %rdx
movq 0x8(%rbx), %rax
subq %rdx, %rax
sarq $0x2, %rax
addq $0x4, %r15
cmpq %r12, %rax
ja 0x2d40
movq (%rsp), %rdi
movq 0x8(%rsp), %rcx
movq %rcx, %rax
subq %rdi, %rax
sarq $0x2, %rax
leaq -0x3(%rax), %rdx
cmpq $0x1, %rdx
ja 0x2ea1
cmpq %rdi, %rcx
je 0x2ea5
movl (%rdi), %esi
movb $0x1, %dl
xorl %r8d, %r8d
xorl %r9d, %r9d
leal (%rsi,%r9), %r10d
cmpl (%rdi,%r9,4), %r10d
movzbl %dl, %edx
cmovnel %r8d, %edx
incq %r9
cmpq %r9, %rax
jne 0x2dfe
movb $0x1, %bpl
testb $0x1, %dl
jne 0x2ea8
cmpq %rdi, %rcx
sete %bpl
je 0x2ea8
cmpq $0x1, %rax
movq %rax, %rcx
adcq $0x0, %rcx
xorl %edx, %edx
testb %dl, %dl
jne 0x2ea8
movslq (%rdi), %rdx
imulq $0x4ec4ec4f, %rdx, %rsi # imm = 0x4EC4EC4F
movq %rsi, %r8
shrq $0x3f, %r8
sarq $0x22, %rsi
addl %r8d, %esi
leal (%rsi,%rsi,2), %r8d
leal (%rsi,%r8,4), %esi
subl %esi, %edx
movl $0x1, %r8d
movq %r8, %rsi
cmpq %r8, %rcx
je 0x2e98
movslq (%rdi,%rsi,4), %r9
imulq $0x4ec4ec4f, %r9, %r8   # imm = 0x4EC4EC4F
movq %r8, %r10
shrq $0x3f, %r10
sarq $0x22, %r8
addl %r10d, %r8d
leal (%r8,%r8,2), %r10d
leal (%r8,%r10,4), %r8d
subl %r8d, %r9d
leaq 0x1(%rsi), %r8
cmpl %edx, %r9d
je 0x2e63
cmpq %rsi, %rax
setbe %bpl
jmp 0x2ea8
xorl %ebp, %ebp
jmp 0x2ea8
movb $0x1, %bpl
testq %rdi, %rdi
je 0x2eba
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
movl %ebp, %eax
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x2ee2
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
movq %rbx, %rdi
callq 0x1150