#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 dealACard();
int getLine(char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ rankHand(int const **, int *, int *);
int /*<<< orphan*/ sortHand(int const **, int *);
void playerDiscards(const int wDeck[][13], int *playerHand,
                    int *playerHandRank) {
  int playerToDiscard[5] = {0};
  int arrLen = 5 * 2 + 1;
  char input[arrLen];
  printf("Choose cards to throw (eg 145): ");
  arrLen = getLine(input, arrLen);
  char c;
  int cardPos, i = 0;
  while (((c = input[i++]) != '\0') && (c != '\n') && (i < arrLen)) {
    cardPos = c - 49;
    if (cardPos >= 0 && cardPos < 5)
      playerToDiscard[cardPos] = 1;
  }
  for (i = 0; i < 5; i++) {
    if (playerToDiscard[i] == 1)
      playerHand[i] = dealACard();
  }
  sortHand(wDeck, playerHand);
  rankHand(wDeck, playerHand, playerHandRank);
}


x86 assembly (clang, -O0):
<playerDiscards>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
xorps  %xmm0,%xmm0
movaps %xmm0,-0x30(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0xb,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x60(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x48(%rbp)
lea    0xe5a(%rip),%rdi
call   1030 <printf@plt>
mov    -0x60(%rbp),%rdi
mov    -0x34(%rbp),%esi
call   1060 <getLine@plt>
mov    %eax,-0x34(%rbp)
movl   $0x0,-0x54(%rbp)
mov    -0x60(%rbp),%rax
mov    -0x54(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x54(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x49(%rbp)
movsbl %al,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x61(%rbp)
je     1208 <playerDiscards+0xb8>
movsbl -0x49(%rbp),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x61(%rbp)
je     1208 <playerDiscards+0xb8>
mov    -0x54(%rbp),%eax
cmp    -0x34(%rbp),%eax
setl   %al
mov    %al,-0x61(%rbp)
mov    -0x61(%rbp),%al
test   $0x1,%al
jne    1218 <playerDiscards+0xc8>
jmp    1247 <playerDiscards+0xf7>
movsbl -0x49(%rbp),%eax
sub    $0x31,%eax
mov    %eax,-0x50(%rbp)
cmpl   $0x0,-0x50(%rbp)
jl     1242 <playerDiscards+0xf2>
cmpl   $0x5,-0x50(%rbp)
jge    1242 <playerDiscards+0xf2>
movslq -0x50(%rbp),%rax
movl   $0x1,-0x30(%rbp,%rax,4)
jmp    11c1 <playerDiscards+0x71>
movl   $0x0,-0x54(%rbp)
cmpl   $0x5,-0x54(%rbp)
jge    128e <playerDiscards+0x13e>
movslq -0x54(%rbp),%rax
cmpl   $0x1,-0x30(%rbp,%rax,4)
jne    127b <playerDiscards+0x12b>
mov    $0x0,%al
call   1070 <dealACard@plt>
mov    %eax,%edx
mov    -0x10(%rbp),%rax
movslq -0x54(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    1280 <playerDiscards+0x130>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    124e <playerDiscards+0xfe>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <sortHand@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <rankHand@plt>
mov    -0x40(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<playerDiscards>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %rsp,%r12
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movl   $0x0,0x10(%rsp)
lea    0xe83(%rip),%rdi
call   1030 <printf@plt>
lea    0x20(%rsp),%rdi
mov    $0xb,%esi
call   1060 <getLine@plt>
cmp    $0x2,%eax
mov    $0x1,%ecx
cmovge %eax,%ecx
add    $0xffffffff,%ecx
xor    %eax,%eax
jmp    11b4 <playerDiscards+0x64>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%rax
movsbq 0x20(%rsp,%rax,1),%rdx
test   %rdx,%rdx
je     11df <playerDiscards+0x8f>
cmp    $0xa,%dl
je     11df <playerDiscards+0x8f>
cmp    %rax,%rcx
je     11df <playerDiscards+0x8f>
lea    -0x31(%rdx),%esi
cmp    $0x4,%sil
ja     11b0 <playerDiscards+0x60>
movl   $0x1,-0xc4(%rsp,%rdx,4)
jmp    11b0 <playerDiscards+0x60>
cmpl   $0x1,(%rsp)
je     1233 <playerDiscards+0xe3>
cmpl   $0x1,0x4(%rsp)
je     1243 <playerDiscards+0xf3>
cmpl   $0x1,0x8(%rsp)
je     1254 <playerDiscards+0x104>
cmpl   $0x1,0xc(%rsp)
je     1265 <playerDiscards+0x115>
cmpl   $0x1,0x10(%rsp)
jne    120b <playerDiscards+0xbb>
xor    %eax,%eax
call   1070 <dealACard@plt>
mov    %eax,0x10(%rbx)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <sortHand@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <rankHand@plt>
mov    %r12,%rsp
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
xor    %eax,%eax
call   1070 <dealACard@plt>
mov    %eax,(%rbx)
cmpl   $0x1,0x4(%rsp)
jne    11ec <playerDiscards+0x9c>
xor    %eax,%eax
call   1070 <dealACard@plt>
mov    %eax,0x4(%rbx)
cmpl   $0x1,0x8(%rsp)
jne    11f3 <playerDiscards+0xa3>
xor    %eax,%eax
call   1070 <dealACard@plt>
mov    %eax,0x8(%rbx)
cmpl   $0x1,0xc(%rsp)
jne    11fa <playerDiscards+0xaa>
xor    %eax,%eax
call   1070 <dealACard@plt>
mov    %eax,0xc(%rbx)
cmpl   $0x1,0x10(%rsp)
je     1201 <playerDiscards+0xb1>
jmp    120b <playerDiscards+0xbb>

LLVM IR (-O0):
@.str = [33 x i8] c"Choose cards to throw (eg 145): \00"
define void @playerDiscards([13 x i32]* %0, i32* %1, i32* %2) {
%4 = alloca [13 x i32]*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca [5 x i32]
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i8
%12 = alloca i32
%13 = alloca i32
store [13 x i32]* %0, [13 x i32]** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%14 = bitcast [5 x i32]* %7 to i8*
store i32 11, i32* %8
%15 = load i32, i32* %8
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %9
%18 = alloca i8, i64 %16
store i64 %16, i64* %10
%19 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* %8
%21 = call i32 @getLine(i8* %18, i32 %20)
store i32 %21, i32* %8
store i32 0, i32* %13
br label %22
22: ; preds = %53, %3
%23 = load i32, i32* %13
%24 = add nsw i32 %23, 1
store i32 %24, i32* %13
%25 = sext i32 %23 to i64
%26 = getelementptr inbounds i8, i8* %18, i64 %25
%27 = load i8, i8* %26
store i8 %27, i8* %11
%28 = sext i8 %27 to i32
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %38
30: ; preds = %22
%31 = load i8, i8* %11
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %32, 10
br i1 %33, label %34, label %38
34: ; preds = %30
%35 = load i32, i32* %13
%36 = load i32, i32* %8
%37 = icmp slt i32 %35, %36
br label %38
38: ; preds = %34, %30, %22
%39 = phi i1 [ false, %30 ], [ false, %22 ], [ %37, %34 ]
br i1 %39, label %40, label %54
40: ; preds = %38
%41 = load i8, i8* %11
%42 = sext i8 %41 to i32
%43 = sub nsw i32 %42, 49
store i32 %43, i32* %12
%44 = load i32, i32* %12
%45 = icmp sge i32 %44, 0
br i1 %45, label %46, label %53
46: ; preds = %40
%47 = load i32, i32* %12
%48 = icmp slt i32 %47, 5
br i1 %48, label %49, label %53
49: ; preds = %46
%50 = load i32, i32* %12
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [5 x i32], [5 x i32]* %7, i64 0, i64 %51
store i32 1, i32* %52
br label %53
53: ; preds = %49, %46, %40
br label %22
54: ; preds = %38
store i32 0, i32* %13
br label %55
55: ; preds = %71, %54
%56 = load i32, i32* %13
%57 = icmp slt i32 %56, 5
br i1 %57, label %58, label %74
58: ; preds = %55
%59 = load i32, i32* %13
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [5 x i32], [5 x i32]* %7, i64 0, i64 %60
%62 = load i32, i32* %61
%63 = icmp eq i32 %62, 1
br i1 %63, label %64, label %70
64: ; preds = %58
%65 = call i32 (...) @dealACard()
%66 = load i32*, i32** %5
%67 = load i32, i32* %13
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i32, i32* %66, i64 %68
store i32 %65, i32* %69
br label %70
70: ; preds = %64, %58
br label %71
71: ; preds = %70
%72 = load i32, i32* %13
%73 = add nsw i32 %72, 1
store i32 %73, i32* %13
br label %55
74: ; preds = %55
%75 = load [13 x i32]*, [13 x i32]** %4
%76 = bitcast [13 x i32]* %75 to i32**
%77 = load i32*, i32** %5
%78 = call i32 @sortHand(i32** %76, i32* %77)
%79 = load [13 x i32]*, [13 x i32]** %4
%80 = bitcast [13 x i32]* %79 to i32**
%81 = load i32*, i32** %5
%82 = load i32*, i32** %6
%83 = call i32 @rankHand(i32** %80, i32* %81, i32* %82)
%84 = load i8*, i8** %9
ret void
}

LLVM IR (-O2):
@.str = [33 x i8] c"Choose cards to throw (eg 145): \00"
define void @playerDiscards([13 x i32]* %0, i32* %1, i32* %2) {
%4 = alloca [5 x i32]
%5 = bitcast [5 x i32]* %4 to i8*
%6 = tail call i8* @llvm.stacksave()
%7 = alloca [11 x i8]
%8 = getelementptr inbounds [11 x i8], [11 x i8]* %7, i64 0, i64 0
%9 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @getLine(i8* %8, i32 11)
%11 = call i32 @llvm.smax.i32(i32 %10, i32 1)
%12 = add nsw i32 %11, -1
%13 = zext i32 %12 to i64
br label %14
14: ; preds = %28, %3
%15 = phi i64 [ 0, %3 ], [ %16, %28 ]
%16 = add nuw nsw i64 %15, 1
%17 = getelementptr inbounds [11 x i8], [11 x i8]* %7, i64 0, i64 %15
%18 = load i8, i8* %17
%19 = sext i8 %18 to i64
switch i8 %18, label %20 [
i8 10, label %29
i8 0, label %29
]
20: ; preds = %14
%21 = icmp eq i64 %15, %13
br i1 %21, label %29, label %22
22: ; preds = %20
%23 = add i8 %18, -49
%24 = icmp ult i8 %23, 5
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = add nsw i64 %19, -49
%27 = getelementptr inbounds [5 x i32], [5 x i32]* %4, i64 0, i64 %26
store i32 1, i32* %27
br label %28
28: ; preds = %25, %22
br label %14
29: ; preds = %14, %14, %20
%30 = getelementptr inbounds [5 x i32], [5 x i32]* %4, i64 0, i64 0
%31 = load i32, i32* %30
%32 = icmp eq i32 %31, 1
br i1 %32, label %33, label %35
33: ; preds = %29
%34 = call i32 (...) @dealACard()
store i32 %34, i32* %1
br label %35
35: ; preds = %29, %33
%36 = getelementptr inbounds [5 x i32], [5 x i32]* %4, i64 0, i64 1
%37 = load i32, i32* %36
%38 = icmp eq i32 %37, 1
br i1 %38, label %39, label %42
39: ; preds = %35
%40 = call i32 (...) @dealACard()
%41 = getelementptr inbounds i32, i32* %1, i64 1
store i32 %40, i32* %41
br label %42
42: ; preds = %39, %35
%43 = getelementptr inbounds [5 x i32], [5 x i32]* %4, i64 0, i64 2
%44 = load i32, i32* %43
%45 = icmp eq i32 %44, 1
br i1 %45, label %46, label %49
46: ; preds = %42
%47 = call i32 (...) @dealACard()
%48 = getelementptr inbounds i32, i32* %1, i64 2
store i32 %47, i32* %48
br label %49
49: ; preds = %46, %42
%50 = getelementptr inbounds [5 x i32], [5 x i32]* %4, i64 0, i64 3
%51 = load i32, i32* %50
%52 = icmp eq i32 %51, 1
br i1 %52, label %53, label %56
53: ; preds = %49
%54 = call i32 (...) @dealACard()
%55 = getelementptr inbounds i32, i32* %1, i64 3
store i32 %54, i32* %55
br label %56
56: ; preds = %53, %49
%57 = getelementptr inbounds [5 x i32], [5 x i32]* %4, i64 0, i64 4
%58 = load i32, i32* %57
%59 = icmp eq i32 %58, 1
br i1 %59, label %60, label %63
60: ; preds = %56
%61 = call i32 (...) @dealACard()
%62 = getelementptr inbounds i32, i32* %1, i64 4
store i32 %61, i32* %62
br label %63
63: ; preds = %60, %56
%64 = bitcast [13 x i32]* %0 to i32**
%65 = call i32 @sortHand(i32** %64, i32* %1)
%66 = call i32 @rankHand(i32** %64, i32* %1, i32* %2)
ret void
}