// File: /workspace/github_cpp_makefile_star2_O3/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 0x23f4
movq (%rbx), %rdx
movslq (%rdx), %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), %esi
movl %eax, %ecx
subl %esi, %ecx
cmpl $0x9, %ecx
jg 0x2c9a
movl 0x4(%rdx), %ecx
leal 0x1(%rax), %esi
cmpl %esi, %ecx
jne 0x2ca9
leal 0x2(%rax), %edi
cmpl %edi, 0x8(%rdx)
jne 0x2ca9
leal 0x3(%rax), %edi
cmpl %edi, 0xc(%rdx)
jne 0x2ca9
movl 0x10(%rdx), %edi
movl 0x14(%rdx), %r8d
movslq %edi, %r9
imulq $0x4ec4ec4f, %r9, %rdi  # imm = 0x4EC4EC4F
movq %rdi, %r10
shrq $0x3f, %r10
sarq $0x22, %rdi
addl %r10d, %edi
leal (%rdi,%rdi,2), %r10d
leal (%rdi,%r10,4), %r10d
movl %r9d, %edi
subl %r10d, %edi
cmpl $0xb, %edi
setl %r10b
incl %r9d
cmpl %r9d, %r8d
sete %r9b
andb %r10b, %r9b
cmpb $0x1, %r9b
jne 0x2c41
movb $0x1, %bpl
cmpl %r8d, 0x18(%rdx)
je 0x2f06
movslq %r8d, %r9
imulq $0x4ec4ec4f, %r9, %r9   # imm = 0x4EC4EC4F
movq %r9, %r10
shrq $0x3f, %r10
sarq $0x22, %r9
addl %r10d, %r9d
leal (%r9,%r9,2), %r10d
leal (%r9,%r10,4), %r9d
subl %r9d, %r8d
cmpl %r8d, %edi
jne 0x2ca9
movslq 0x18(%rdx), %r8
imulq $0x4ec4ec4f, %r8, %r9   # imm = 0x4EC4EC4F
movq %r9, %r10
shrq $0x3f, %r10
sarq $0x22, %r9
addl %r10d, %r9d
leal (%r9,%r9,2), %r10d
leal (%r9,%r10,4), %r9d
subl %r9d, %r8d
movb $0x1, %bpl
cmpl %r8d, %edi
jne 0x2ca9
jmp 0x2f06
cmpl $0xa, %ecx
jne 0x2d89
movl 0x4(%rdx), %ecx
leal 0x1(%rax), %esi
cmpl %esi, %ecx
jne 0x2d89
addl $0x2, %eax
cmpl %eax, 0x8(%rdx)
jne 0x2d89
movl 0xc(%rdx), %esi
movl 0x10(%rdx), %ecx
movslq %esi, %rdi
imulq $0x4ec4ec4f, %rdi, %rax # imm = 0x4EC4EC4F
movq %rax, %r8
shrq $0x3f, %r8
sarq $0x22, %rax
addl %r8d, %eax
leal (%rax,%rax,2), %r8d
leal (%rax,%r8,4), %r8d
movl %edi, %eax
subl %r8d, %eax
cmpl $0xa, %eax
setl %r8b
incl %edi
cmpl %edi, %ecx
sete %dil
andb %r8b, %dil
cmpb $0x1, %dil
jne 0x2d17
leal 0x2(%rsi), %edi
cmpl %edi, 0x14(%rdx)
jne 0x2d17
addl $0x3, %esi
movb $0x1, %bpl
cmpl %esi, 0x18(%rdx)
je 0x2f06
movslq %ecx, %rsi
imulq $0x4ec4ec4f, %rsi, %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, %ecx
cmpl %ecx, %eax
jne 0x2d89
movslq 0x14(%rdx), %rcx
imulq $0x4ec4ec4f, %rcx, %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, %ecx
cmpl %ecx, %eax
jne 0x2d89
movslq 0x18(%rdx), %rcx
imulq $0x4ec4ec4f, %rcx, %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, %ecx
movb $0x1, %bpl
cmpl %ecx, %eax
je 0x2f06
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movq 0x8(%rbx), %rax
cmpq %rdx, %rax
je 0x2ee9
xorl %r15d, %r15d
movq %rsp, %r14
xorl %r12d, %r12d
movslq (%rdx,%r15), %rcx
imulq $0x4ec4ec4f, %rcx, %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
movl %ecx, %edi
subl %esi, %edi
movslq (%rdx), %rsi
imulq $0x4ec4ec4f, %rsi, %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, %esi
cmpl %esi, %edi
je 0x2e23
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x2e11
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x2e23
addq %r15, %rdx
movq %r14, %rdi
callq 0x3d5c
movq (%rbx), %rdx
movq 0x8(%rbx), %rax
incq %r12
movq %rax, %rcx
subq %rdx, %rcx
sarq $0x2, %rcx
addq $0x4, %r15
cmpq %r12, %rcx
ja 0x2daf
movq (%rsp), %rdi
movq 0x8(%rsp), %rcx
movq %rcx, %rax
subq %rdi, %rax
sarq $0x2, %rax
leaq -0x3(%rax), %rdx
cmpq $0x1, %rdx
ja 0x2eed
cmpq %rdi, %rcx
je 0x2ef1
movl (%rdi), %ecx
movb $0x1, %dl
xorl %esi, %esi
leal (%rcx,%rsi), %r8d
cmpl (%rdi,%rsi,4), %r8d
sete %r8b
andb %r8b, %dl
incq %rsi
cmpq %rsi, %rax
jne 0x2e6d
movb $0x1, %bpl
testb %dl, %dl
jne 0x2ef4
movslq %ecx, %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), %edx
subl %edx, %ecx
decq %rax
xorl %edx, %edx
movslq (%rdi,%rdx,4), %rsi
imulq $0x4ec4ec4f, %rsi, %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, %esi
cmpl %ecx, %esi
sete %bpl
jne 0x2ef4
leaq 0x1(%rdx), %rsi
cmpq %rdx, %rax
movq %rsi, %rdx
jne 0x2eaf
jmp 0x2ef4
xorl %ebp, %ebp
jmp 0x2f06
xorl %ebp, %ebp
jmp 0x2ef4
movb $0x1, %bpl
testq %rdi, %rdi
je 0x2f06
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 0x2f2e
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
movq %rbx, %rdi
callq 0x1150