#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 */
scalar_t__ analyze_hand(int **);
int /*<<< orphan*/ printf(char *);
int strlen(char *);
int translate(char);
void build_hands(char line[50]) {
  int index, card_value, card_type, i, j;
  int first_hand[4][16] = {0};
  int second_hand[4][16] = {0};
  for (index = 0; index < strlen(line); index += 3) {
    card_value = translate(line[index]);
    card_type = translate(line[index + 1]);
    if (index >= 13) {
      second_hand[card_type][card_value] = 1;
    } else {
      first_hand[card_type][card_value] = 1;
    }
  }
  if (analyze_hand(first_hand) > analyze_hand(second_hand))
    printf("PLAYER 1\n");
  else
    printf("PLAYER 2\n");
}


x86 assembly (clang, -O0):
<build_hands>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
lea    -0x220(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x224(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x224(%rbp),%eax
cmp    %ecx,%eax
jge    1237 <build_hands+0xe7>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1070 <translate@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%edi
call   1070 <translate@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xd,-0xc(%rbp)
jl     1207 <build_hands+0xb7>
movslq -0x14(%rbp),%rcx
lea    -0x220(%rbp),%rax
shl    $0x6,%rcx
add    %rcx,%rax
movslq -0x10(%rbp),%rcx
movl   $0x1,(%rax,%rcx,4)
jmp    1224 <build_hands+0xd4>
movslq -0x14(%rbp),%rcx
lea    -0x120(%rbp),%rax
shl    $0x6,%rcx
add    %rcx,%rax
movslq -0x10(%rbp),%rcx
movl   $0x1,(%rax,%rcx,4)
jmp    1229 <build_hands+0xd9>
mov    -0xc(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0xc(%rbp)
jmp    118c <build_hands+0x3c>
lea    -0x120(%rbp),%rdi
call   1060 <analyze_hand@plt>
mov    %rax,-0x230(%rbp)
lea    -0x220(%rbp),%rdi
call   1060 <analyze_hand@plt>
mov    %rax,%rcx
mov    -0x230(%rbp),%rax
cmp    %rcx,%rax
jle    127a <build_hands+0x12a>
lea    0xd90(%rip),%rdi
call   1040 <printf@plt>
jmp    1286 <build_hands+0x136>
lea    0xd89(%rip),%rdi
call   1040 <printf@plt>
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_hands>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x200,%rsp
mov    %rdi,%r14
xorps  %xmm0,%xmm0
movaps %xmm0,0x1f0(%rsp)
movaps %xmm0,0x1e0(%rsp)
movaps %xmm0,0x1d0(%rsp)
movaps %xmm0,0x1c0(%rsp)
movaps %xmm0,0x1b0(%rsp)
movaps %xmm0,0x1a0(%rsp)
movaps %xmm0,0x190(%rsp)
movaps %xmm0,0x180(%rsp)
movaps %xmm0,0x170(%rsp)
movaps %xmm0,0x160(%rsp)
movaps %xmm0,0x150(%rsp)
movaps %xmm0,0x140(%rsp)
movaps %xmm0,0x130(%rsp)
movaps %xmm0,0x120(%rsp)
movaps %xmm0,0x110(%rsp)
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
call   1040 <strlen@plt>
test   %eax,%eax
jle    12a5 <build_hands+0x165>
xor    %ebx,%ebx
mov    %rsp,%r15
lea    0x100(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl (%r14,%rbx,1),%edi
call   1060 <translate@plt>
mov    %eax,%ebp
movsbl 0x1(%r14,%rbx,1),%edi
call   1060 <translate@plt>
cmp    $0xd,%rbx
cltq
movslq %ebp,%rcx
mov    %r12,%rdx
cmovae %r15,%rdx
shl    $0x6,%rax
add    %rdx,%rax
movl   $0x1,(%rax,%rcx,4)
add    $0x3,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
cmp    %ebx,%eax
jg     1260 <build_hands+0x120>
lea    0x100(%rsp),%rdi
call   1050 <analyze_hand@plt>
mov    %rax,%rbx
mov    %rsp,%rdi
call   1050 <analyze_hand@plt>
cmp    %rax,%rbx
lea    0xd42(%rip),%rax
lea    0xd32(%rip),%rdi
cmovg  %rax,%rdi
call   1030 <puts@plt>
add    $0x200,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"PLAYER 1\0A\00"
@.str.1 = [10 x i8] c"PLAYER 2\0A\00"
define void @build_hands(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [4 x [16 x i32]]
%9 = alloca [4 x [16 x i32]]
store i8* %0, i8** %2
%10 = bitcast [4 x [16 x i32]]* %8 to i8*
%11 = bitcast [4 x [16 x i32]]* %9 to i8*
store i32 0, i32* %3
br label %12
12: ; preds = %48, %1
%13 = load i32, i32* %3
%14 = load i8*, i8** %2
%15 = call i32 @strlen(i8* %14)
%16 = icmp slt i32 %13, %15
br i1 %16, label %17, label %51
17: ; preds = %12
%18 = load i8*, i8** %2
%19 = load i32, i32* %3
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = call i32 @translate(i8 signext %22)
store i32 %23, i32* %4
%24 = load i8*, i8** %2
%25 = load i32, i32* %3
%26 = add nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %24, i64 %27
%29 = load i8, i8* %28
%30 = call i32 @translate(i8 signext %29)
store i32 %30, i32* %5
%31 = load i32, i32* %3
%32 = icmp sge i32 %31, 13
br i1 %32, label %33, label %40
33: ; preds = %17
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [4 x [16 x i32]], [4 x [16 x i32]]* %9, i64 0, i64 %35
%37 = load i32, i32* %4
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [16 x i32], [16 x i32]* %36, i64 0, i64 %38
store i32 1, i32* %39
br label %47
40: ; preds = %17
%41 = load i32, i32* %5
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [4 x [16 x i32]], [4 x [16 x i32]]* %8, i64 0, i64 %42
%44 = load i32, i32* %4
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [16 x i32], [16 x i32]* %43, i64 0, i64 %45
store i32 1, i32* %46
br label %47
47: ; preds = %40, %33
br label %48
48: ; preds = %47
%49 = load i32, i32* %3
%50 = add nsw i32 %49, 3
store i32 %50, i32* %3
br label %12
51: ; preds = %12
%52 = getelementptr inbounds [4 x [16 x i32]], [4 x [16 x i32]]* %8, i64 0, i64 0
%53 = bitcast [16 x i32]* %52 to i32**
%54 = call i64 @analyze_hand(i32** %53)
%55 = getelementptr inbounds [4 x [16 x i32]], [4 x [16 x i32]]* %9, i64 0, i64 0
%56 = bitcast [16 x i32]* %55 to i32**
%57 = call i64 @analyze_hand(i32** %56)
%58 = icmp sgt i64 %54, %57
br i1 %58, label %59, label %61
59: ; preds = %51
%60 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %63
61: ; preds = %51
%62 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %63
63: ; preds = %61, %59
ret void
}

LLVM IR (-O2):
@str = [9 x i8] c"PLAYER 2\00"
@str.2 = [9 x i8] c"PLAYER 1\00"
define void @build_hands(i8* %0) {
%2 = alloca [4 x [16 x i32]]
%3 = alloca [4 x [16 x i32]]
%4 = bitcast [4 x [16 x i32]]* %2 to i8*
%5 = bitcast [4 x [16 x i32]]* %3 to i8*
%6 = tail call i32 @strlen(i8* %0)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %26
8: ; preds = %1, %8
%9 = phi i64 [ %22, %8 ], [ 0, %1 ]
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = tail call i32 @translate(i8 signext %11)
%13 = add nuw nsw i64 %9, 1
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
%16 = tail call i32 @translate(i8 signext %15)
%17 = icmp ugt i64 %9, 12
%18 = sext i32 %16 to i64
%19 = sext i32 %12 to i64
%20 = select i1 %17, [4 x [16 x i32]]* %3, [4 x [16 x i32]]* %2
%21 = getelementptr inbounds [4 x [16 x i32]], [4 x [16 x i32]]* %20, i64 0, i64 %18, i64 %19
store i32 1, i32* %21
%22 = add nuw i64 %9, 3
%23 = tail call i32 @strlen(i8* %0)
%24 = trunc i64 %22 to i32
%25 = icmp sgt i32 %23, %24
br i1 %25, label %8, label %26
26: ; preds = %8, %1
%27 = bitcast [4 x [16 x i32]]* %2 to i32**
%28 = call i64 @analyze_hand(i32** %27)
%29 = bitcast [4 x [16 x i32]]* %3 to i32**
%30 = call i64 @analyze_hand(i32** %29)
%31 = icmp sgt i64 %28, %30
%32 = select i1 %31, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0)
%33 = call i32 @puts(i8* dereferenceable(1) %32)
ret void
}