#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 /*<<< orphan*/ free(char *);
char *malloc(scalar_t__);
int /*<<< orphan*/ printf(char *, char *, char *);
scalar_t__ snprintf(int /*<<< orphan*/ *, int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
void printCards(int cards[]) {
  for (int i = 0; i < 52; i++) {
    int suite = (cards[i] - 1) / 13;
    char *cardString = malloc(snprintf(NULL, 0, "%s", "Diamonds") + 1);
    char *suiteString;
    if (suite == 0) {
      suiteString = "Clubs";
    } else if (suite == 1) {
      suiteString = "Diamonds";
    } else if (suite == 2) {
      suiteString = "Hearts";
    } else if (suite == 3) {
      suiteString = "Spades";
    }
    if (i % 13 == 9) {
      cardString = "Jack";
    } else if (i % 13 == 10) {
      cardString = "Queen";
    } else if (i % 13 == 11) {
      cardString = "King";
    } else if (i % 13 == 12) {
      cardString = "Ace";
    } else {
      sprintf(cardString, "%d", (i % 13) + 2);
    }
    printf("%s of %s\n", cardString, suiteString);
    free(cardString);
  }
}


x86 assembly (clang, -O0):
<printCards>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x34,-0xc(%rbp)
jge    1309 <printCards+0x1b9>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
sub    $0x1,%eax
mov    $0xd,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
lea    0xe6d(%rip),%rdx
lea    0xe69(%rip),%rcx
call   1050 <snprintf@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    11c9 <printCards+0x79>
lea    0xe4c(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    1221 <printCards+0xd1>
cmpl   $0x1,-0x10(%rbp)
jne    11e3 <printCards+0x93>
lea    0xe29(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    121c <printCards+0xcc>
cmpl   $0x2,-0x10(%rbp)
jne    11fd <printCards+0xad>
lea    0xe1e(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    1217 <printCards+0xc7>
cmpl   $0x3,-0x10(%rbp)
jne    1212 <printCards+0xc2>
lea    0xe0b(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    1217 <printCards+0xc7>
jmp    121c <printCards+0xcc>
jmp    1221 <printCards+0xd1>
mov    -0xc(%rbp),%eax
mov    $0xd,%ecx
cltd
idiv   %ecx
cmp    $0x9,%edx
jne    1245 <printCards+0xf5>
lea    0xde4(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    12de <printCards+0x18e>
mov    -0xc(%rbp),%eax
mov    $0xd,%ecx
cltd
idiv   %ecx
cmp    $0xa,%edx
jne    1269 <printCards+0x119>
lea    0xdc5(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    12d9 <printCards+0x189>
mov    -0xc(%rbp),%eax
mov    $0xd,%ecx
cltd
idiv   %ecx
cmp    $0xb,%edx
jne    128d <printCards+0x13d>
lea    0xda7(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    12d4 <printCards+0x184>
mov    -0xc(%rbp),%eax
mov    $0xd,%ecx
cltd
idiv   %ecx
cmp    $0xc,%edx
jne    12b1 <printCards+0x161>
lea    0xd88(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    12cf <printCards+0x17f>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%eax
mov    $0xd,%ecx
cltd
idiv   %ecx
add    $0x2,%edx
lea    0xd6a(%rip),%rsi
call   1070 <sprintf@plt>
jmp    12d4 <printCards+0x184>
jmp    12d9 <printCards+0x189>
jmp    12de <printCards+0x18e>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xd4a(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1163 <printCards+0x13>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printCards>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,0x8(%rsp)
mov    $0xfffffff7,%r14d
mov    $0x2,%ebx
xor    %r13d,%r13d
jmp    11cd <printCards+0x7d>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movslq %r14d,%rax
lea    0xeba(%rip),%rcx
movslq (%rcx,%rax,4),%rbp
add    %rcx,%rbp
mov    0x4(%rsp),%ebx
mov    (%rsp),%r14d
lea    0xe97(%rip),%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
call   1040 <printf@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
add    $0x1,%r13
add    $0x1,%r14d
add    $0x1,%ebx
mov    %r15,0x10(%rsp)
cmp    $0x34,%r13
je     1298 <printCards+0x148>
mov    %ebx,0x4(%rsp)
mov    %r13d,%eax
imul   $0x4ec4ec4f,%rax,%rax
shr    $0x22,%rax
lea    (%rax,%rax,2),%ecx
lea    (%rax,%rcx,4),%ebx
mov    %r14d,(%rsp)
sub    %ebx,%r14d
mov    0x8(%rsp),%rax
mov    (%rax,%r13,4),%r12d
xor    %edi,%edi
xor    %esi,%esi
lea    0xe00(%rip),%rdx
lea    0xdfc(%rip),%rcx
call   1050 <snprintf@plt>
lea    0x1(%rax),%rdi
call   1060 <malloc@plt>
mov    %rax,%rbp
lea    0xb(%r12),%eax
lea    0xde8(%rip),%r15
cmp    $0x19,%eax
jb     1270 <printCards+0x120>
lea    -0xe(%r12),%eax
lea    0xdce(%rip),%r15
cmp    $0xd,%eax
jb     1270 <printCards+0x120>
lea    -0x1b(%r12),%eax
lea    0xdcc(%rip),%r15
cmp    $0xd,%eax
jb     1270 <printCards+0x120>
add    $0xffffffd8,%r12d
cmp    $0xd,%r12d
lea    0xdbf(%rip),%rax
mov    0x10(%rsp),%r15
cmovb  %rax,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    $0x4,%r14d
jb     1180 <printCards+0x30>
mov    %ebx,%eax
mov    0x4(%rsp),%ebx
mov    %ebx,%edx
sub    %eax,%edx
mov    %rbp,%rdi
lea    0xda6(%rip),%rsi
call   1070 <sprintf@plt>
jmp    1195 <printCards+0x45>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [9 x i8] c"Diamonds\00"
@.str.2 = [6 x i8] c"Clubs\00"
@.str.3 = [7 x i8] c"Hearts\00"
@.str.4 = [7 x i8] c"Spades\00"
@.str.5 = [5 x i8] c"Jack\00"
@.str.6 = [6 x i8] c"Queen\00"
@.str.7 = [5 x i8] c"King\00"
@.str.8 = [4 x i8] c"Ace\00"
@.str.9 = [3 x i8] c"%d\00"
@.str.10 = [10 x i8] c"%s of %s\0A\00"
define void @printCards(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
store i32* %0, i32** %2
store i32 0, i32* %3
br label %7
7: ; preds = %74, %1
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 52
br i1 %9, label %10, label %77
10: ; preds = %7
%11 = load i32*, i32** %2
%12 = load i32, i32* %3
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i32, i32* %11, i64 %13
%15 = load i32, i32* %14
%16 = sub nsw i32 %15, 1
%17 = sdiv i32 %16, 13
store i32 %17, i32* %4
%18 = call i64 @snprintf(i32* null, i32 0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%19 = add nsw i64 %18, 1
%20 = call i8* @malloc(i64 %19)
store i8* %20, i8** %5
%21 = load i32, i32* %4
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %10
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8** %6
br label %39
24: ; preds = %10
%25 = load i32, i32* %4
%26 = icmp eq i32 %25, 1
br i1 %26, label %27, label %28
27: ; preds = %24
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8** %6
br label %38
28: ; preds = %24
%29 = load i32, i32* %4
%30 = icmp eq i32 %29, 2
br i1 %30, label %31, label %32
31: ; preds = %28
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8** %6
br label %37
32: ; preds = %28
%33 = load i32, i32* %4
%34 = icmp eq i32 %33, 3
br i1 %34, label %35, label %36
35: ; preds = %32
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8** %6
br label %36
36: ; preds = %35, %32
br label %37
37: ; preds = %36, %31
br label %38
38: ; preds = %37, %27
br label %39
39: ; preds = %38, %23
%40 = load i32, i32* %3
%41 = srem i32 %40, 13
%42 = icmp eq i32 %41, 9
br i1 %42, label %43, label %44
43: ; preds = %39
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8** %5
br label %68
44: ; preds = %39
%45 = load i32, i32* %3
%46 = srem i32 %45, 13
%47 = icmp eq i32 %46, 10
br i1 %47, label %48, label %49
48: ; preds = %44
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8** %5
br label %67
49: ; preds = %44
%50 = load i32, i32* %3
%51 = srem i32 %50, 13
%52 = icmp eq i32 %51, 11
br i1 %52, label %53, label %54
53: ; preds = %49
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8** %5
br label %66
54: ; preds = %49
%55 = load i32, i32* %3
%56 = srem i32 %55, 13
%57 = icmp eq i32 %56, 12
br i1 %57, label %58, label %59
58: ; preds = %54
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8** %5
br label %65
59: ; preds = %54
%60 = load i8*, i8** %5
%61 = load i32, i32* %3
%62 = srem i32 %61, 13
%63 = add nsw i32 %62, 2
%64 = call i32 @sprintf(i8* %60, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i32 %63)
br label %65
65: ; preds = %59, %58
br label %66
66: ; preds = %65, %53
br label %67
67: ; preds = %66, %48
br label %68
68: ; preds = %67, %43
%69 = load i8*, i8** %5
%70 = load i8*, i8** %6
%71 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i8* %69, i8* %70)
%72 = load i8*, i8** %5
%73 = call i32 @free(i8* %72)
br label %74
74: ; preds = %68
%75 = load i32, i32* %3
%76 = add nsw i32 %75, 1
store i32 %76, i32* %3
br label %7
77: ; preds = %7
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [9 x i8] c"Diamonds\00"
@.str.2 = [6 x i8] c"Clubs\00"
@.str.3 = [7 x i8] c"Hearts\00"
@.str.4 = [7 x i8] c"Spades\00"
@.str.5 = [5 x i8] c"Jack\00"
@.str.6 = [6 x i8] c"Queen\00"
@.str.7 = [5 x i8] c"King\00"
@.str.8 = [4 x i8] c"Ace\00"
@.str.9 = [3 x i8] c"%d\00"
@.str.10 = [10 x i8] c"%s of %s\0A\00"
@reltable.printCards = [4 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.5 to i64), i64 ptrtoint ([4 x i32]* @reltable.printCards to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.6 to i64), i64 ptrtoint ([4 x i32]* @reltable.printCards to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.7 to i64), i64 ptrtoint ([4 x i32]* @reltable.printCards to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.8 to i64), i64 ptrtoint ([4 x i32]* @reltable.printCards to i64)) to i32)]
define void @printCards(i32* nocapture %0) {
br label %3
2: ; preds = %37
ret void
3: ; preds = %1, %37
%4 = phi i64 [ 0, %1 ], [ %41, %37 ]
%5 = phi i8* [ undef, %1 ], [ %24, %37 ]
%6 = getelementptr inbounds i32, i32* %0, i64 %4
%7 = load i32, i32* %6
%8 = tail call i64 @snprintf(i32* null, i32 0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%9 = add nsw i64 %8, 1
%10 = tail call i8* @malloc(i64 %9)
%11 = add i32 %7, 11
%12 = icmp ult i32 %11, 25
br i1 %12, label %23, label %13
13: ; preds = %3
%14 = add i32 %7, -14
%15 = icmp ult i32 %14, 13
br i1 %15, label %23, label %16
16: ; preds = %13
%17 = add i32 %7, -27
%18 = icmp ult i32 %17, 13
br i1 %18, label %23, label %19
19: ; preds = %16
%20 = add i32 %7, -40
%21 = icmp ult i32 %20, 13
%22 = select i1 %21, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %5
br label %23
23: ; preds = %19, %16, %13, %3
%24 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), %3 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), %13 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), %16 ], [ %22, %19 ]
%25 = trunc i64 %4 to i8
%26 = urem i8 %25, 13
%27 = zext i8 %26 to i32
%28 = add nsw i32 %27, -9
%29 = icmp ult i32 %28, 4
br i1 %29, label %33, label %30
30: ; preds = %23
%31 = add nuw nsw i32 %27, 2
%32 = tail call i32 @sprintf(i8* dereferenceable(1) %10, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i32 %31)
br label %37
33: ; preds = %23
%34 = sext i32 %28 to i64
%35 = shl i64 %34, 2
%36 = call i8* @llvm.load.relative.i64(i8* bitcast ([4 x i32]* @reltable.printCards to i8*), i64 %35)
br label %37
37: ; preds = %33, %30
%38 = phi i8* [ %10, %30 ], [ %36, %33 ]
%39 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i8* %38, i8* %24)
%40 = tail call i32 @free(i8* %38)
%41 = add nuw nsw i64 %4, 1
%42 = icmp eq i64 %41, 52
br i1 %42, label %2, label %3
}