#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*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ srand(unsigned int);
scalar_t__ time(int /*<<< orphan*/ *);
int main(void) {
  int in_hand[4][13] = {{0}, {0}};
  int num_cards, rank, suit;
  const char rank_code[] = {'2', '3', '4', '5', '6', '7', '8',
                            '9', 't', 'j', 'q', 'k', 'a'};
  const char suit_code[] = {'c', 'd', 'h', 's'};
  srand((unsigned)time(NULL));
  printf("Enter number of cards in hand: ");
  scanf("%d", &num_cards);
  printf("Your hand:\n");
  while (num_cards > 0) {
    suit = rand() % 4;
    rank = rand() % 13;
    if (!in_hand[suit][rank]) {
      in_hand[suit][rank] = 1;
      num_cards -= 1;
      printf("\t%c%c", rank_code[rank], suit_code[suit]);
    }
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xe0(%rbp),%rdi
xor    %esi,%esi
mov    $0xd0,%edx
call   1040 <memset@plt>
mov    0xe74(%rip),%rax
mov    %rax,-0xf9(%rbp)
mov    0xe6f(%rip),%eax
mov    %eax,-0xf1(%rbp)
mov    0xe67(%rip),%al
mov    %al,-0xed(%rbp)
mov    0xe5c(%rip),%eax
mov    %eax,-0xfd(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe55(%rip),%rdi
lea    -0xe4(%rbp),%rsi
call   1070 <scanf@plt>
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0xe4(%rbp)
jle    12b6 <main+0x156>
mov    $0x0,%al
call   1080 <rand@plt>
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %edx,-0xec(%rbp)
mov    $0x0,%al
call   1080 <rand@plt>
mov    $0xd,%ecx
cltd
idiv   %ecx
mov    %edx,-0xe8(%rbp)
movslq -0xec(%rbp),%rcx
lea    -0xe0(%rbp),%rax
imul   $0x34,%rcx,%rcx
add    %rcx,%rax
movslq -0xe8(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jne    12b1 <main+0x151>
movslq -0xec(%rbp),%rcx
lea    -0xe0(%rbp),%rax
imul   $0x34,%rcx,%rcx
add    %rcx,%rax
movslq -0xe8(%rbp),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0xe4(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0xe4(%rbp)
movslq -0xe8(%rbp),%rax
movsbl -0xf9(%rbp,%rax,1),%esi
ff
movslq -0xec(%rbp),%rax
movsbl -0xfd(%rbp,%rax,1),%edx
ff
lea    0xd96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f6 <main+0x96>
lea    0xd81(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xe8,%rsp
xorps  %xmm0,%xmm0
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)
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
lea    0xe28(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe3a(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1080 <scanf@plt>
lea    0xe32(%rip),%rdi
call   1040 <puts@plt>
cmpl   $0x0,0xc(%rsp)
jle    12af <main+0x13f>
lea    0xde1(%rip),%r15
lea    0xde7(%rip),%r12
lea    0xe07(%rip),%r14
jmp    1237 <main+0xc7>
nop
cmpl   $0x0,0xc(%rsp)
jle    12af <main+0x13f>
xor    %eax,%eax
call   1090 <rand@plt>
mov    %eax,%ebx
lea    0x3(%rbx),%eax
test   %ebx,%ebx
cmovns %ebx,%eax
and    $0xfffffffc,%eax
sub    %eax,%ebx
xor    %eax,%eax
call   1090 <rand@plt>
movslq %eax,%rcx
imul   $0x4ec4ec4f,%rcx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rax
add    %edx,%eax
lea    (%rax,%rax,2),%edx
lea    (%rax,%rdx,4),%eax
sub    %eax,%ecx
movslq %ebx,%rax
movslq %ecx,%rcx
imul   $0x34,%rax,%rdx
add    %rsp,%rdx
add    $0x10,%rdx
cmpl   $0x0,(%rdx,%rcx,4)
jne    1230 <main+0xc0>
addl   $0xffffffff,0xc(%rsp)
lea    (%rdx,%rcx,4),%rdx
movl   $0x1,(%rdx)
movsbl (%rcx,%r15,1),%esi
movsbl (%rax,%r12,1),%edx
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1230 <main+0xc0>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0xe8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.rank_code = [13 x i8] c"23456789tjqka"
@__const.main.suit_code = [4 x i8] c"cdhs"
@.str = [32 x i8] c"Enter number of cards in hand: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [12 x i8] c"Your hand:\0A\00"
@.str.3 = [6 x i8] c"\09%c%c\00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [4 x [13 x i32]]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [13 x i8]
%7 = alloca [4 x i8]
store i32 0, i32* %1
%8 = bitcast [4 x [13 x i32]]* %2 to i8*
%9 = bitcast [13 x i8]* %6 to i8*
%10 = bitcast [4 x i8]* %7 to i8*
%11 = call i64 @time(i32* null)
%12 = trunc i64 %11 to i32
%13 = call i32 @srand(i32 %12)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %53, %0
%18 = load i32, i32* %3
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %54
20: ; preds = %17
%21 = call i32 (...) @rand()
%22 = srem i32 %21, 4
store i32 %22, i32* %5
%23 = call i32 (...) @rand()
%24 = srem i32 %23, 13
store i32 %24, i32* %4
%25 = load i32, i32* %5
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [4 x [13 x i32]], [4 x [13 x i32]]* %2, i64 0, i64 %26
%28 = load i32, i32* %4
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [13 x i32], [13 x i32]* %27, i64 0, i64 %29
%31 = load i32, i32* %30
%32 = icmp ne i32 %31, 0
br i1 %32, label %53, label %33
33: ; preds = %20
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [4 x [13 x i32]], [4 x [13 x i32]]* %2, i64 0, i64 %35
%37 = load i32, i32* %4
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [13 x i32], [13 x i32]* %36, i64 0, i64 %38
store i32 1, i32* %39
%40 = load i32, i32* %3
%41 = sub nsw i32 %40, 1
store i32 %41, i32* %3
%42 = load i32, i32* %4
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [13 x i8], [13 x i8]* %6, i64 0, i64 %43
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = load i32, i32* %5
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 %48
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %46, i32 %51)
br label %53
53: ; preds = %33, %20
br label %17
54: ; preds = %17
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@__const.main.rank_code = [13 x i8] c"23456789tjqka"
@__const.main.suit_code = [4 x i8] c"cdhs"
@.str = [32 x i8] c"Enter number of cards in hand: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [6 x i8] c"\09%c%c\00"
@str = [11 x i8] c"Your hand:\00"
define i32 @main() {
%1 = alloca [4 x [13 x i32]]
%2 = alloca i32
%3 = bitcast [4 x [13 x i32]]* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i64 @time(i32* null)
%6 = trunc i64 %5 to i32
%7 = tail call i32 @srand(i32 %6)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
%11 = load i32, i32* %2
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %36
13: ; preds = %0, %33
%14 = call i32 (...) @rand()
%15 = srem i32 %14, 4
%16 = call i32 (...) @rand()
%17 = srem i32 %16, 13
%18 = sext i32 %15 to i64
%19 = sext i32 %17 to i64
%20 = getelementptr inbounds [4 x [13 x i32]], [4 x [13 x i32]]* %1, i64 0, i64 %18, i64 %19
%21 = load i32, i32* %20
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %33
23: ; preds = %13
store i32 1, i32* %20
%24 = load i32, i32* %2
%25 = add nsw i32 %24, -1
store i32 %25, i32* %2
%26 = getelementptr inbounds [13 x i8], [13 x i8]* @__const.main.rank_code, i64 0, i64 %19
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = getelementptr inbounds [4 x i8], [4 x i8]* @__const.main.suit_code, i64 0, i64 %18
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %28, i32 %31)
br label %33
33: ; preds = %23, %13
%34 = load i32, i32* %2
%35 = icmp sgt i32 %34, 0
br i1 %35, label %13, label %36
36: ; preds = %33, %0
%37 = call i32 @putchar(i32 10)
ret i32 0
}