#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int getCardFace(int const **, int);
int isThreeOFAKind(const int wDeck[][13], int hand[]) {
  int i, card, count = 1;
  int prevCard = getCardFace(wDeck, hand[0]);
  int hasThreeOfKind = -1;
  for (i = 1; i < 5; i++) {
    card = getCardFace(wDeck, hand[i]);
    if (card == prevCard) {
      count++;
      if (count == 3)
        hasThreeOfKind = card;
    } else
      count = 1;
    prevCard = card;
  }
  return hasThreeOfKind;
}


x86 assembly (clang, -O0):
<isThreeOFAKind>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
call   1030 <getCardFace@plt>
mov    %eax,-0x20(%rbp)
movl   $0xffffffff,-0x24(%rbp)
movl   $0x1,-0x14(%rbp)
cmpl   $0x5,-0x14(%rbp)
jge    11ad <isThreeOFAKind+0x9d>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
call   1030 <getCardFace@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x20(%rbp),%eax
jne    1192 <isThreeOFAKind+0x82>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x3,-0x1c(%rbp)
jne    118d <isThreeOFAKind+0x7d>
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    1199 <isThreeOFAKind+0x89>
movl   $0x1,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1147 <isThreeOFAKind+0x37>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isThreeOFAKind>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %rdi,%rbx
mov    (%rsi),%esi
call   1030 <getCardFace@plt>
mov    %eax,%r14d
mov    0x4(%r12),%esi
mov    %rbx,%rdi
call   1030 <getCardFace@plt>
mov    %eax,%r15d
mov    0x8(%r12),%esi
mov    %rbx,%rdi
mov    %rbx,(%rsp)
call   1030 <getCardFace@plt>
mov    %eax,%r13d
xor    %ebp,%ebp
cmp    %r14d,%r15d
sete   %bpl
mov    $0xffffffff,%r14d
cmove  %eax,%r14d
mov    0xc(%r12),%esi
mov    %rbx,%rdi
call   1030 <getCardFace@plt>
add    $0x3,%ebp
cmp    %r15d,%r13d
mov    $0xffffffff,%ecx
cmovne %ecx,%r14d
mov    $0x2,%ebx
cmove  %ebp,%ebx
mov    %eax,%ebp
cmp    $0x3,%ebx
mov    %r14d,%r15d
cmove  %eax,%r15d
cmp    %r13d,%eax
cmovne %r14d,%r15d
mov    0x10(%r12),%esi
mov    (%rsp),%rdi
call   1030 <getCardFace@plt>
cmp    $0x2,%ebx
mov    %r15d,%ecx
cmove  %eax,%ecx
cmp    %r13d,%ebp
cmovne %r15d,%ecx
cmp    %ebp,%eax
cmovne %r15d,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @isThreeOFAKind([13 x i32]* %0, i32* %1) {
%3 = alloca [13 x i32]*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store [13 x i32]* %0, [13 x i32]** %3
store i32* %1, i32** %4
store i32 1, i32* %7
%10 = load [13 x i32]*, [13 x i32]** %3
%11 = bitcast [13 x i32]* %10 to i32**
%12 = load i32*, i32** %4
%13 = getelementptr inbounds i32, i32* %12, i64 0
%14 = load i32, i32* %13
%15 = call i32 @getCardFace(i32** %11, i32 %14)
store i32 %15, i32* %8
store i32 -1, i32* %9
store i32 1, i32* %5
br label %16
16: ; preds = %42, %2
%17 = load i32, i32* %5
%18 = icmp slt i32 %17, 5
br i1 %18, label %19, label %45
19: ; preds = %16
%20 = load [13 x i32]*, [13 x i32]** %3
%21 = bitcast [13 x i32]* %20 to i32**
%22 = load i32*, i32** %4
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
%26 = load i32, i32* %25
%27 = call i32 @getCardFace(i32** %21, i32 %26)
store i32 %27, i32* %6
%28 = load i32, i32* %6
%29 = load i32, i32* %8
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %39
31: ; preds = %19
%32 = load i32, i32* %7
%33 = add nsw i32 %32, 1
store i32 %33, i32* %7
%34 = load i32, i32* %7
%35 = icmp eq i32 %34, 3
br i1 %35, label %36, label %38
36: ; preds = %31
%37 = load i32, i32* %6
store i32 %37, i32* %9
br label %38
38: ; preds = %36, %31
br label %40
39: ; preds = %19
store i32 1, i32* %7
br label %40
40: ; preds = %39, %38
%41 = load i32, i32* %6
store i32 %41, i32* %8
br label %42
42: ; preds = %40
%43 = load i32, i32* %5
%44 = add nsw i32 %43, 1
store i32 %44, i32* %5
br label %16
45: ; preds = %16
%46 = load i32, i32* %9
ret i32 %46
}

LLVM IR (-O2):
define i32 @isThreeOFAKind([13 x i32]* %0, i32* nocapture %1) {
%3 = bitcast [13 x i32]* %0 to i32**
%4 = load i32, i32* %1
%5 = tail call i32 @getCardFace(i32** %3, i32 %4)
%6 = getelementptr inbounds i32, i32* %1, i64 1
%7 = load i32, i32* %6
%8 = tail call i32 @getCardFace(i32** %3, i32 %7)
%9 = icmp eq i32 %8, %5
%10 = getelementptr inbounds i32, i32* %1, i64 2
%11 = load i32, i32* %10
%12 = tail call i32 @getCardFace(i32** %3, i32 %11)
%13 = icmp eq i32 %12, %8
%14 = select i1 %13, i1 %9, i1 false
%15 = select i1 %14, i32 %12, i32 -1
%16 = getelementptr inbounds i32, i32* %1, i64 3
%17 = load i32, i32* %16
%18 = tail call i32 @getCardFace(i32** %3, i32 %17)
%19 = icmp eq i32 %18, %12
%20 = select i1 %9, i32 4, i32 3
%21 = select i1 %13, i32 %20, i32 2
%22 = icmp eq i32 %21, 3
%23 = select i1 %19, i1 %22, i1 false
%24 = select i1 %23, i32 %18, i32 %15
%25 = getelementptr inbounds i32, i32* %1, i64 4
%26 = load i32, i32* %25
%27 = tail call i32 @getCardFace(i32** %3, i32 %26)
%28 = icmp eq i32 %27, %18
%29 = icmp eq i32 %21, 2
%30 = select i1 %28, i1 %19, i1 false
%31 = select i1 %30, i1 %29, i1 false
%32 = select i1 %31, i32 %27, i32 %24
ret i32 %32
}