#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 rand();
int /*<<< orphan*/ srand(unsigned int);
scalar_t__ time(int /*<<< orphan*/ *);
void shuff(int cards[]) {
  int t;
  int i;
  int desk[52] = {0};
  for (i = 0; i < 52; i++)
    desk[i] = (i / 13 + 3) * 100 + i % 13 + 1;
  srand((unsigned)time(NULL));
  for (i = 0; i < 52; i++) {
    do {
      t = rand() % 52;
    } while (desk[t] == 0);
    cards[i] = desk[t];
    desk[t] = 0;
  }
}


x86 assembly (clang, -O0):
<shuff>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0xe0(%rbp),%rdi
xor    %esi,%esi
mov    $0xd0,%edx
call   1030 <memset@plt>
movl   $0x0,-0x10(%rbp)
cmpl   $0x34,-0x10(%rbp)
jge    11ad <shuff+0x6d>
mov    -0x10(%rbp),%eax
mov    $0xd,%ecx
cltd
idiv   %ecx
add    $0x3,%eax
imul   $0x64,%eax,%ecx
mov    -0x10(%rbp),%eax
mov    $0xd,%esi
cltd
idiv   %esi
add    %edx,%ecx
add    $0x1,%ecx
movslq -0x10(%rbp),%rax
mov    %ecx,-0xe0(%rbp,%rax,4)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1169 <shuff+0x29>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
movl   $0x0,-0x10(%rbp)
cmpl   $0x34,-0x10(%rbp)
jge    122a <shuff+0xea>
jmp    11d3 <shuff+0x93>
mov    $0x0,%al
call   1060 <rand@plt>
mov    $0x34,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
movslq -0xc(%rbp),%rax
cmpl   $0x0,-0xe0(%rbp,%rax,4)
je     11d3 <shuff+0x93>
movslq -0xc(%rbp),%rax
mov    -0xe0(%rbp,%rax,4),%edx
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
movslq -0xc(%rbp),%rax
movl   $0x0,-0xe0(%rbp,%rax,4)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11c4 <shuff+0x84>
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shuff>:
push   %r14
push   %rbx
sub    $0xd8,%rsp
mov    %rdi,%r14
pxor   %xmm0,%xmm0
movdqa %xmm0,0xc0(%rsp)
movdqa %xmm0,0xb0(%rsp)
movdqa %xmm0,0xa0(%rsp)
movdqa %xmm0,0x90(%rsp)
movdqa %xmm0,0x80(%rsp)
movdqa %xmm0,0x70(%rsp)
movdqa %xmm0,0x60(%rsp)
movdqa %xmm0,0x50(%rsp)
movdqa %xmm0,0x40(%rsp)
movdqa %xmm0,0x30(%rsp)
movdqa %xmm0,0x20(%rsp)
movdqa %xmm0,0x10(%rsp)
movdqa %xmm0,(%rsp)
movdqa 0xe5b(%rip),%xmm6
xor    %eax,%eax
movdqa 0xe61(%rip),%xmm2
movdqa 0xe68(%rip),%xmm8
movdqa 0xe6f(%rip),%xmm9
movdqa 0xe76(%rip),%xmm10
movdqa 0xe7d(%rip),%xmm11
movdqa 0xe85(%rip),%xmm7
movdqa 0xe8d(%rip),%xmm3
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movdqa %xmm6,%xmm1
punpckhbw %xmm0,%xmm1
pmullw %xmm2,%xmm1
psrlw  $0x8,%xmm1
movdqa %xmm6,%xmm4
punpcklbw %xmm0,%xmm4
pmullw %xmm2,%xmm4
psrlw  $0x8,%xmm4
packuswb %xmm1,%xmm4
psrlw  $0x2,%xmm4
pand   %xmm8,%xmm4
movdqa %xmm4,%xmm1
punpcklbw %xmm0,%xmm1
punpcklwd %xmm0,%xmm1
pmaddwd %xmm9,%xmm1
punpcklbw %xmm4,%xmm4
pmullw %xmm10,%xmm4
pand   %xmm11,%xmm4
packuswb %xmm4,%xmm4
movdqa %xmm6,%xmm5
psubb  %xmm4,%xmm5
punpcklbw %xmm0,%xmm5
punpcklwd %xmm0,%xmm5
paddd  %xmm1,%xmm5
paddd  %xmm7,%xmm5
movdqa %xmm5,(%rsp,%rax,4)
add    $0x4,%rax
paddb  %xmm3,%xmm6
cmp    $0x34,%rax
jne    11f0 <shuff+0xc0>
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
xor    %ebx,%ebx
xchg   %ax,%ax
xor    %eax,%eax
call   1050 <rand@plt>
cltq
imul   $0x4ec4ec4f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x24,%rcx
add    %edx,%ecx
imul   $0x34,%ecx,%ecx
sub    %ecx,%eax
cltq
mov    (%rsp,%rax,4),%ecx
test   %ecx,%ecx
je     1280 <shuff+0x150>
mov    %ecx,(%r14,%rbx,4)
movl   $0x0,(%rsp,%rax,4)
add    $0x1,%rbx
cmp    $0x34,%rbx
jne    1280 <shuff+0x150>
add    $0xd8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @shuff(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca [52 x i32]
store i32* %0, i32** %2
%6 = bitcast [52 x i32]* %5 to i8*
store i32 0, i32* %4
br label %7
7: ; preds = %22, %1
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 52
br i1 %9, label %10, label %25
10: ; preds = %7
%11 = load i32, i32* %4
%12 = sdiv i32 %11, 13
%13 = add nsw i32 %12, 3
%14 = mul nsw i32 %13, 100
%15 = load i32, i32* %4
%16 = srem i32 %15, 13
%17 = add nsw i32 %14, %16
%18 = add nsw i32 %17, 1
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [52 x i32], [52 x i32]* %5, i64 0, i64 %20
store i32 %18, i32* %21
br label %22
22: ; preds = %10
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
br label %7
25: ; preds = %7
%26 = call i64 @time(i32* null)
%27 = trunc i64 %26 to i32
%28 = call i32 @srand(i32 %27)
store i32 0, i32* %4
br label %29
29: ; preds = %54, %25
%30 = load i32, i32* %4
%31 = icmp slt i32 %30, 52
br i1 %31, label %32, label %57
32: ; preds = %29
br label %33
33: ; preds = %36, %32
%34 = call i32 (...) @rand()
%35 = srem i32 %34, 52
store i32 %35, i32* %3
br label %36
36: ; preds = %33
%37 = load i32, i32* %3
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [52 x i32], [52 x i32]* %5, i64 0, i64 %38
%40 = load i32, i32* %39
%41 = icmp eq i32 %40, 0
br i1 %41, label %33, label %42
42: ; preds = %36
%43 = load i32, i32* %3
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [52 x i32], [52 x i32]* %5, i64 0, i64 %44
%46 = load i32, i32* %45
%47 = load i32*, i32** %2
%48 = load i32, i32* %4
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i32, i32* %47, i64 %49
store i32 %46, i32* %50
%51 = load i32, i32* %3
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [52 x i32], [52 x i32]* %5, i64 0, i64 %52
store i32 0, i32* %53
br label %54
54: ; preds = %42
%55 = load i32, i32* %4
%56 = add nsw i32 %55, 1
store i32 %56, i32* %4
br label %29
57: ; preds = %29
ret void
}

LLVM IR (-O2):
define void @shuff(i32* nocapture writeonly %0) {
%2 = alloca [52 x i32]
%3 = bitcast [52 x i32]* %2 to i8*
br label %4
4: ; preds = %4, %1
%5 = phi i64 [ 0, %1 ], [ %18, %4 ]
%6 = phi <4 x i8> [ <i8 0, i8 1, i8 2, i8 3>, %1 ], [ %19, %4 ]
%7 = freeze <4 x i8> %6
%8 = udiv <4 x i8> %7, <i8 13, i8 13, i8 13, i8 13>
%9 = zext <4 x i8> %8 to <4 x i32>
%10 = mul nuw nsw <4 x i32> %9, <i32 100, i32 100, i32 100, i32 100>
%11 = mul <4 x i8> %8, <i8 13, i8 13, i8 13, i8 13>
%12 = sub <4 x i8> %7, %11
%13 = zext <4 x i8> %12 to <4 x i32>
%14 = add nuw nsw <4 x i32> %13, <i32 301, i32 301, i32 301, i32 301>
%15 = add nuw nsw <4 x i32> %14, %10
%16 = getelementptr inbounds [52 x i32], [52 x i32]* %2, i64 0, i64 %5
%17 = bitcast i32* %16 to <4 x i32>*
store <4 x i32> %15, <4 x i32>* %17
%18 = add nuw i64 %5, 4
%19 = add <4 x i8> %6, <i8 4, i8 4, i8 4, i8 4>
%20 = icmp eq i64 %18, 52
br i1 %20, label %21, label %4
21: ; preds = %4
%22 = tail call i64 @time(i32* null)
%23 = trunc i64 %22 to i32
%24 = tail call i32 @srand(i32 %23)
br label %25
25: ; preds = %21, %34
%26 = phi i64 [ 0, %21 ], [ %37, %34 ]
br label %27
27: ; preds = %25, %27
%28 = tail call i32 (...) @rand()
%29 = srem i32 %28, 52
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [52 x i32], [52 x i32]* %2, i64 0, i64 %30
%32 = load i32, i32* %31
%33 = icmp eq i32 %32, 0
br i1 %33, label %27, label %34
34: ; preds = %27
%35 = getelementptr inbounds [52 x i32], [52 x i32]* %2, i64 0, i64 %30
%36 = getelementptr inbounds i32, i32* %0, i64 %26
store i32 %32, i32* %36
store i32 0, i32* %35
%37 = add nuw nsw i64 %26, 1
%38 = icmp eq i64 %37, 52
br i1 %38, label %39, label %25
39: ; preds = %34
ret void
}