#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();
void shuffleDeck(unsigned *deck) {
  unsigned tmpdeck[52];
  for (size_t i = 0; i < 52; i++) {
    size_t cardIndex;
    do {
      cardIndex = rand() % 52;
    } while (deck[cardIndex] == 0);
    tmpdeck[i] = deck[cardIndex];
    deck[cardIndex] = 0;
  }
  for (size_t i = 0; i < 52; i++) {
    deck[i] = tmpdeck[i];
  }
}


x86 assembly (clang, -O0):
<shuffleDeck>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0xe8(%rbp)
cmpq   $0x34,-0xe8(%rbp)
34
jae    11b0 <shuffleDeck+0xa0>
jmp    113d <shuffleDeck+0x2d>
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0x34,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
mov    %rax,-0xf0(%rbp)
mov    -0x8(%rbp),%rax
mov    -0xf0(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
je     113d <shuffleDeck+0x2d>
mov    -0x8(%rbp),%rax
mov    -0xf0(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
mov    -0xe8(%rbp),%rax
mov    %ecx,-0xe0(%rbp,%rax,4)
mov    -0x8(%rbp),%rax
mov    -0xf0(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0xe8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xe8(%rbp)
jmp    112a <shuffleDeck+0x1a>
movq   $0x0,-0xf8(%rbp)
cmpq   $0x34,-0xf8(%rbp)
34
jae    11fc <shuffleDeck+0xec>
mov    -0xf8(%rbp),%rax
mov    -0xe0(%rbp,%rax,4),%edx
mov    -0x8(%rbp),%rax
mov    -0xf8(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0xf8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xf8(%rbp)
jmp    11bb <shuffleDeck+0xab>
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shuffleDeck>:
push   %r14
push   %rbx
sub    $0xd8,%rsp
mov    %rdi,%rbx
xor    %r14d,%r14d
xor    %eax,%eax
call   1040 <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    (%rbx,%rax,4),%ecx
test   %ecx,%ecx
je     1130 <shuffleDeck+0x10>
mov    %ecx,(%rsp,%r14,4)
movl   $0x0,(%rbx,%rax,4)
add    $0x1,%r14
cmp    $0x34,%r14
jne    1130 <shuffleDeck+0x10>
mov    %rsp,%rsi
mov    $0xd0,%edx
mov    %rbx,%rdi
call   1030 <memcpy@plt>
add    $0xd8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define void @shuffleDeck(i32* nocapture %0) {
%2 = alloca [52 x i32]
%3 = bitcast [52 x i32]* %2 to i8*
br label %4
4: ; preds = %1, %13
%5 = phi i64 [ 0, %1 ], [ %16, %13 ]
br label %6
6: ; preds = %4, %6
%7 = tail call i32 (...) @rand()
%8 = srem i32 %7, 52
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i32, i32* %0, i64 %9
%11 = load i32, i32* %10
%12 = icmp eq i32 %11, 0
br i1 %12, label %6, label %13
13: ; preds = %6
%14 = getelementptr inbounds i32, i32* %0, i64 %9
%15 = getelementptr inbounds [52 x i32], [52 x i32]* %2, i64 0, i64 %5
store i32 %11, i32* %15
store i32 0, i32* %14
%16 = add nuw nsw i64 %5, 1
%17 = icmp eq i64 %16, 52
br i1 %17, label %18, label %4
18: ; preds = %13
%19 = bitcast i32* %0 to i8*
ret void
}