#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 */
double drand48();
shuffle_deck(int *deck) {
  int i, n, temp[52];
  for (i = 0; i < 52; i++)
    temp[i] = deck[i];
  for (i = 0; i < 52; i++) {
    do {
      n = (int)(51.9999999 * drand48());
    } while (temp[n] == 0);
    deck[i] = temp[n];
    temp[n] = 0;
  }
}


x86 assembly (clang, -O0):
<shuffle_deck>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x34,-0x14(%rbp)
jge    1154 <shuffle_deck+0x44>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
movslq -0x14(%rbp),%rax
mov    %ecx,-0xf0(%rbp,%rax,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1126 <shuffle_deck+0x16>
movl   $0x0,-0x14(%rbp)
cmpl   $0x34,-0x14(%rbp)
jge    11cc <shuffle_deck+0xbc>
jmp    116a <shuffle_deck+0x5a>
mov    $0x0,%al
call   1030 <drand48@plt>
movaps %xmm0,%xmm1
movsd  0xe84(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rax
cmpl   $0x0,-0xf0(%rbp,%rax,4)
je     116a <shuffle_deck+0x5a>
movslq -0x18(%rbp),%rax
mov    -0xf0(%rbp,%rax,4),%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
movslq -0x18(%rbp),%rax
movl   $0x0,-0xf0(%rbp,%rax,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115b <shuffle_deck+0x4b>
mov    -0x4(%rbp),%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shuffle_deck>:
push   %r14
push   %rbx
sub    $0xd8,%rsp
mov    %rdi,%r14
mov    %rsp,%rdi
mov    $0xd0,%edx
mov    %r14,%rsi
call   1030 <memcpy@plt>
xor    %ebx,%ebx
nop
xor    %eax,%eax
call   1040 <drand48@plt>
movsd  0xeb1(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
cltq
mov    (%rsp,%rax,4),%ecx
test   %ecx,%ecx
je     1140 <shuffle_deck+0x20>
mov    %ecx,(%r14,%rbx,4)
movl   $0x0,(%rsp,%rax,4)
add    $0x1,%rbx
cmp    $0x34,%rbx
jne    1140 <shuffle_deck+0x20>
add    $0xd8,%rsp
pop    %rbx
pop    %r14
ret

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

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