// File: fredericmarchand[P]TexasHoldem/./CardUtil.h
// Function: evaluateHand(Card**)
static Hand evaluateHand(Card *hand[])
{
    int straight,flush,three,four,full,pairs;
    int k;

    straight = flush = three = four = full = pairs = 0;
    k = 0;

    //checks for flush
    while (k < 4 && hand[k]->getSuit() == hand[k+1]->getSuit())
    {
        k++;
    }

    if (k == 4)
    {
        flush = 1;
    }

    //checks for straight
    k = 0;
    while (k < 4 && hand[k]->getCardValue() == hand[k+1]->getCardValue()-1)
    {
        k++;
    }
    if (k == 4)
    {
        straight = 1;
    }

    //checks for fours
    for (int i = 0; i < 2; i++)
    {
        k = i;
        while (k < i+3 && hand[k]->getCardValue() == hand[k+1]->getCardValue())
        {
            k++;
        }
        if (k == i+3)
        {
            four = 1;
        }
    }

    //checks for threes and fullhouse
    if (!four)
    {
        for (int i = 0; i < 3; i++)
        {
            k = i;
            while (k < i+2 && hand[k]->getCardValue() == hand[k+1]->getCardValue())
            {
                k++;
            }
            if (k == i+2)
            {
                three = 1;
                if (i == 0)
                {
                    if (hand[3]->getCardValue() == hand[4]->getCardValue())
                    {
                        full = 1;
                    }
                }
                else if (i == 1){
                    if (hand[0]->getCardValue() == hand[4]->getCardValue())
                    {
                        full = 1;
                    }
                }
                else
                {
                    if (hand[0]->getCardValue() == hand[1]->getCardValue())
                    {
                        full = 1;
                    }
                }
            }
        }
    }

    if (straight && flush)
    {
        return STRAIGHT_FLUSH;
    }
    else if (four)
    {
        return FOUR_OF_A_KIND;
    }
    else if (full)
    {
        return FULL_HOUSE;
    }
    else if (flush)
    {
        return FLUSH;
    }
    else if (straight)
    {
        return STRAIGHT;
    }
    else if (three)
    {
        return THREE_OF_A_KIND;
    }

    //checks for pairs
    for (k = 0; k < 4; k++)
    {
        if (hand[k]->getCardValue() == hand[k+1]->getCardValue())
        {
            pairs++;
        }
    }

    if (pairs == 2)
    {
        return TWO_PAIR;
    }
    else if (pairs)
    {
        return PAIR;
    }
    else
    {
        return HIGH_CARD;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movl $0x0, -0x28(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x18(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x0, -0x2c(%rbp)
xorl %eax, %eax
cmpl $0x4, -0x2c(%rbp)
movb %al, -0x35(%rbp)
jge 0x3caf
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x25d0
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rax
movl -0x2c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x25d0
movl %eax, %ecx
movl -0x3c(%rbp), %eax
cmpl %ecx, %eax
sete %al
movb %al, -0x35(%rbp)
movb -0x35(%rbp), %al
testb $0x1, %al
jne 0x3cb8
jmp 0x3cc3
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x3c6d
cmpl $0x4, -0x2c(%rbp)
jne 0x3cd0
movl $0x1, -0x18(%rbp)
movl $0x0, -0x2c(%rbp)
xorl %eax, %eax
cmpl $0x4, -0x2c(%rbp)
movb %al, -0x3d(%rbp)
jge 0x3d1c
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x25e0
movl %eax, -0x44(%rbp)
movq -0x10(%rbp), %rax
movl -0x2c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x25e0
movl %eax, %ecx
movl -0x44(%rbp), %eax
subl $0x1, %ecx
cmpl %ecx, %eax
sete %al
movb %al, -0x3d(%rbp)
movb -0x3d(%rbp), %al
testb $0x1, %al
jne 0x3d25
jmp 0x3d30
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x3cd7
cmpl $0x4, -0x2c(%rbp)
jne 0x3d3d
movl $0x1, -0x14(%rbp)
movl $0x0, -0x30(%rbp)
cmpl $0x2, -0x30(%rbp)
jge 0x3dd5
movl -0x30(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %ecx
movl -0x30(%rbp), %edx
addl $0x3, %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0x45(%rbp)
jge 0x3d9d
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x25e0
movl %eax, -0x4c(%rbp)
movq -0x10(%rbp), %rax
movl -0x2c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x25e0
movl %eax, %ecx
movl -0x4c(%rbp), %eax
cmpl %ecx, %eax
sete %al
movb %al, -0x45(%rbp)
movb -0x45(%rbp), %al
testb $0x1, %al
jne 0x3da6
jmp 0x3db1
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x3d54
movl -0x2c(%rbp), %eax
movl -0x30(%rbp), %ecx
addl $0x3, %ecx
cmpl %ecx, %eax
jne 0x3dc5
movl $0x1, -0x20(%rbp)
jmp 0x3dc7
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x3d44
cmpl $0x0, -0x20(%rbp)
jne 0x3f18
movl $0x0, -0x34(%rbp)
cmpl $0x3, -0x34(%rbp)
jge 0x3f16
movl -0x34(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %ecx
movl -0x34(%rbp), %edx
addl $0x2, %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0x4d(%rbp)
jge 0x3e3f
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x25e0
movl %eax, -0x54(%rbp)
movq -0x10(%rbp), %rax
movl -0x2c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x25e0
movl %eax, %ecx
movl -0x54(%rbp), %eax
cmpl %ecx, %eax
sete %al
movb %al, -0x4d(%rbp)
movb -0x4d(%rbp), %al
testb $0x1, %al
jne 0x3e48
jmp 0x3e53
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x3df6
movl -0x2c(%rbp), %eax
movl -0x34(%rbp), %ecx
addl $0x2, %ecx
cmpl %ecx, %eax
jne 0x3f06
movl $0x1, -0x1c(%rbp)
cmpl $0x0, -0x34(%rbp)
jne 0x3ea0
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x25e0
movl %eax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x25e0
movl %eax, %ecx
movl -0x58(%rbp), %eax
cmpl %ecx, %eax
jne 0x3e9e
movl $0x1, -0x24(%rbp)
jmp 0x3f04
cmpl $0x1, -0x34(%rbp)
jne 0x3ed4
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x25e0
movl %eax, -0x5c(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x25e0
movl %eax, %ecx
movl -0x5c(%rbp), %eax
cmpl %ecx, %eax
jne 0x3ed2
movl $0x1, -0x24(%rbp)
jmp 0x3f02
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x25e0
movl %eax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x25e0
movl %eax, %ecx
movl -0x60(%rbp), %eax
cmpl %ecx, %eax
jne 0x3f00
movl $0x1, -0x24(%rbp)
jmp 0x3f02
jmp 0x3f04
jmp 0x3f06
jmp 0x3f08
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x3de6
jmp 0x3f18
cmpl $0x0, -0x14(%rbp)
je 0x3f30
cmpl $0x0, -0x18(%rbp)
je 0x3f30
movl $0x9, -0x4(%rbp)
jmp 0x400f
cmpl $0x0, -0x20(%rbp)
je 0x3f42
movl $0x8, -0x4(%rbp)
jmp 0x400f
cmpl $0x0, -0x24(%rbp)
je 0x3f54
movl $0x7, -0x4(%rbp)
jmp 0x400f
cmpl $0x0, -0x18(%rbp)
je 0x3f66
movl $0x6, -0x4(%rbp)
jmp 0x400f
cmpl $0x0, -0x14(%rbp)
je 0x3f78
movl $0x5, -0x4(%rbp)
jmp 0x400f
cmpl $0x0, -0x1c(%rbp)
je 0x3f8a
movl $0x4, -0x4(%rbp)
jmp 0x400f
jmp 0x3f8c
jmp 0x3f8e
jmp 0x3f90
jmp 0x3f92
jmp 0x3f94
movl $0x0, -0x2c(%rbp)
cmpl $0x4, -0x2c(%rbp)
jge 0x3fea
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x25e0
movl %eax, -0x64(%rbp)
movq -0x10(%rbp), %rax
movl -0x2c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x25e0
movl %eax, %ecx
movl -0x64(%rbp), %eax
cmpl %ecx, %eax
jne 0x3fdd
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x3fdf
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x3f9b
cmpl $0x2, -0x28(%rbp)
jne 0x3ff9
movl $0x3, -0x4(%rbp)
jmp 0x400f
cmpl $0x0, -0x28(%rbp)
je 0x4008
movl $0x2, -0x4(%rbp)
jmp 0x400f
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)