#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 checkCards(char *);
int cmpCards(char, char);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int main() {
  char cards[14], i, l, temp;
  printf("A - Ace, K - King, Q - Queen, J - Jester, T - 10, the rest are their "
         "respective numbers\n");
  printf("Input your 13 cards: ");
  scanf("%s", cards);
  while (checkCards(cards) != 1) {
    printf("Input a valid stack of cards:\n");
    scanf("%s", cards);
  }
  for (i = 0; i < 13 - 1; i++) {
    for (l = 0; l < 13 - i - 1; l++) {
      if (cmpCards(cards[l], cards[l + 1]) == -1) {
        temp = cards[l];
        cards[l] = cards[l + 1];
        cards[l + 1] = temp;
      }
    }
  }
  printf("%s\n", cards);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xef5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x12(%rbp),%rsi
lea    0xef9(%rip),%rdi
call   1040 <scanf@plt>
lea    -0x12(%rbp),%rdi
call   1060 <checkCards@plt>
cmp    $0x1,%eax
je     11b0 <main+0x70>
lea    0xede(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x12(%rbp),%rsi
lea    0xec9(%rip),%rdi
call   1040 <scanf@plt>
jmp    117b <main+0x3b>
movb   $0x0,-0x13(%rbp)
movsbl -0x13(%rbp),%eax
cmp    $0xc,%eax
jge    125d <main+0x11d>
movb   $0x0,-0x14(%rbp)
movsbl -0x14(%rbp),%eax
movsbl -0x13(%rbp),%edx
mov    $0xd,%ecx
sub    %edx,%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    124b <main+0x10b>
movsbq -0x14(%rbp),%rax
mov    -0x12(%rbp,%rax,1),%cl
movsbl -0x14(%rbp),%eax
add    $0x1,%eax
cltq
movsbl %cl,%edi
movsbl -0x12(%rbp,%rax,1),%esi
call   1050 <cmpCards@plt>
cmp    $0xffffffff,%eax
jne    1239 <main+0xf9>
movsbq -0x14(%rbp),%rax
mov    -0x12(%rbp,%rax,1),%al
mov    %al,-0x15(%rbp)
movsbl -0x14(%rbp),%eax
add    $0x1,%eax
cltq
mov    -0x12(%rbp,%rax,1),%cl
movsbq -0x14(%rbp),%rax
mov    %cl,-0x12(%rbp,%rax,1)
mov    -0x15(%rbp),%cl
movsbl -0x14(%rbp),%eax
add    $0x1,%eax
cltq
mov    %cl,-0x12(%rbp,%rax,1)
jmp    123e <main+0xfe>
mov    -0x14(%rbp),%al
add    $0x1,%al
mov    %al,-0x14(%rbp)
jmp    11c5 <main+0x85>
jmp    1250 <main+0x110>
mov    -0x13(%rbp),%al
add    $0x1,%al
mov    %al,-0x13(%rbp)
jmp    11b4 <main+0x74>
lea    -0x12(%rbp),%rsi
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xeb6(%rip),%rdi
call   1030 <puts@plt>
lea    0xe91(%rip),%rdi
xor    %r12d,%r12d
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe96(%rip),%rdi
lea    0x2(%rsp),%rbx
mov    %rbx,%rsi
call   1050 <scanf@plt>
mov    %rbx,%rdi
call   1070 <checkCards@plt>
cmp    $0x1,%eax
je     11ea <main+0x9a>
lea    0xed0(%rip),%r14
lea    0xe6e(%rip),%r15
lea    0x2(%rsp),%rbx
nopl   (%rax)
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
mov    %rbx,%rdi
call   1070 <checkCards@plt>
cmp    $0x1,%eax
jne    11b0 <main+0x60>
jmp    11ea <main+0x9a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%r12d
cmp    $0xc,%r12d
je     1235 <main+0xe5>
mov    $0xc,%ebx
sub    %r12d,%ebx
xor    %eax,%eax
jmp    120a <main+0xba>
cs nopw 0x0(%rax,%rax,1)
lea    0x1(%rbp),%eax
movsbl %al,%eax
cmp    %eax,%ebx
jle    11e0 <main+0x90>
movslq %eax,%rbp
movsbl 0x2(%rsp,%rbp,1),%edi
movsbl 0x3(%rsp,%rbp,1),%esi
call   1060 <cmpCards@plt>
cmp    $0xffffffff,%eax
jne    1200 <main+0xb0>
movzbl 0x2(%rsp,%rbp,1),%eax
movzbl 0x3(%rsp,%rbp,1),%ecx
mov    %cl,0x2(%rsp,%rbp,1)
mov    %al,0x3(%rsp,%rbp,1)
jmp    1200 <main+0xb0>
lea    0x2(%rsp),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [89 x i8] c"A - Ace, K - King, Q - Queen, J - Jester, T - 10, the rest are their respective numbers\0A\00"
@.str.1 = [22 x i8] c"Input your 13 cards: \00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [31 x i8] c"Input a valid stack of cards:\0A\00"
@.str.4 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [14 x i8]
%3 = alloca i8
%4 = alloca i8
%5 = alloca i8
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([89 x i8], [89 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%8 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 0
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %8)
br label %10
10: ; preds = %14, %0
%11 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 0
%12 = call i32 @checkCards(i8* %11)
%13 = icmp ne i32 %12, 1
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%16 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 0
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %16)
br label %10
18: ; preds = %10
store i8 0, i8* %3
br label %19
19: ; preds = %70, %18
%20 = load i8, i8* %3
%21 = sext i8 %20 to i32
%22 = icmp slt i32 %21, 12
br i1 %22, label %23, label %73
23: ; preds = %19
store i8 0, i8* %4
br label %24
24: ; preds = %66, %23
%25 = load i8, i8* %4
%26 = sext i8 %25 to i32
%27 = load i8, i8* %3
%28 = sext i8 %27 to i32
%29 = sub nsw i32 13, %28
%30 = sub nsw i32 %29, 1
%31 = icmp slt i32 %26, %30
br i1 %31, label %32, label %69
32: ; preds = %24
%33 = load i8, i8* %4
%34 = sext i8 %33 to i64
%35 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = load i8, i8* %4
%38 = sext i8 %37 to i32
%39 = add nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 %40
%42 = load i8, i8* %41
%43 = call i32 @cmpCards(i8 signext %36, i8 signext %42)
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %65
45: ; preds = %32
%46 = load i8, i8* %4
%47 = sext i8 %46 to i64
%48 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 %47
%49 = load i8, i8* %48
store i8 %49, i8* %5
%50 = load i8, i8* %4
%51 = sext i8 %50 to i32
%52 = add nsw i32 %51, 1
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 %53
%55 = load i8, i8* %54
%56 = load i8, i8* %4
%57 = sext i8 %56 to i64
%58 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 %57
store i8 %55, i8* %58
%59 = load i8, i8* %5
%60 = load i8, i8* %4
%61 = sext i8 %60 to i32
%62 = add nsw i32 %61, 1
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 %63
store i8 %59, i8* %64
br label %65
65: ; preds = %45, %32
br label %66
66: ; preds = %65
%67 = load i8, i8* %4
%68 = add i8 %67, 1
store i8 %68, i8* %4
br label %24
69: ; preds = %24
br label %70
70: ; preds = %69
%71 = load i8, i8* %3
%72 = add i8 %71, 1
store i8 %72, i8* %3
br label %19
73: ; preds = %19
%74 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 0
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %74)
%76 = load i32, i32* %1
ret i32 %76
}

LLVM IR (-O2):
@.str.1 = [22 x i8] c"Input your 13 cards: \00"
@.str.2 = [3 x i8] c"%s\00"
@str = [88 x i8] c"A - Ace, K - King, Q - Queen, J - Jester, T - 10, the rest are their respective numbers\00"
@str.5 = [30 x i8] c"Input a valid stack of cards:\00"
define i32 @main() {
%1 = alloca [14 x i8]
%2 = getelementptr inbounds [14 x i8], [14 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([88 x i8], [88 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%6 = call i32 @checkCards(i8* %2)
%7 = icmp eq i32 %6, 1
br i1 %7, label %13, label %8
8: ; preds = %0, %8
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.5, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%11 = call i32 @checkCards(i8* %2)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %8
13: ; preds = %8, %0
br label %14
14: ; preds = %13, %36
%15 = phi i32 [ %37, %36 ], [ 0, %13 ]
%16 = sub nuw nsw i32 12, %15
br label %17
17: ; preds = %14, %31
%18 = phi i32 [ %34, %31 ], [ 0, %14 ]
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [14 x i8], [14 x i8]* %1, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = add nsw i32 %18, 1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [14 x i8], [14 x i8]* %1, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = call i32 @cmpCards(i8 signext %21, i8 signext %25)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %31
28: ; preds = %17
%29 = load i8, i8* %20
%30 = load i8, i8* %24
store i8 %30, i8* %20
store i8 %29, i8* %24
br label %31
31: ; preds = %17, %28
%32 = shl nsw i32 %18, 24
%33 = add i32 %32, 16777216
%34 = ashr exact i32 %33, 24
%35 = icmp sgt i32 %16, %34
br i1 %35, label %17, label %36
36: ; preds = %31
%37 = add nuw nsw i32 %15, 1
%38 = icmp eq i32 %37, 12
br i1 %38, label %39, label %14
39: ; preds = %36
%40 = call i32 @puts(i8* %2)
ret i32 0
}