#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 shuffle(int *deck, int n_cards) {
  int i;
  static int first_time = 1;
  if (first_time) {
    first_time = 0;
    srand((unsigned int)time(NULL));
  }
  for (i = n_cards - 1; i > 0; i -= 1) {
    int where;
    int temp;
    where = rand() % i;
    temp = deck[where];
    deck[where] = deck[i];
    deck[i] = temp;
  }
}


x86 assembly (clang, -O0):
<shuffle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,0x2ef2(%rip)
je     1166 <shuffle+0x36>
movl   $0x0,0x2ee2(%rip)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jle    11c7 <shuffle+0x97>
mov    $0x0,%al
call   1050 <rand@plt>
cltd
idivl  -0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    116f <shuffle+0x3f>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shuffle>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
cmpb   $0x0,0x2efc(%rip)
jne    1157 <shuffle+0x27>
movb   $0x1,0x2ef3(%rip)
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
cmp    $0x2,%ebp
jl     118c <shuffle+0x5c>
mov    %ebp,%ebp
xchg   %ax,%ax
lea    -0x1(%rbp),%rbx
xor    %eax,%eax
call   1050 <rand@plt>
cltd
idiv   %ebx
movslq %edx,%rax
mov    (%r14,%rax,4),%ecx
mov    %ebx,%edx
mov    (%r14,%rdx,4),%esi
mov    %esi,(%r14,%rax,4)
mov    %ecx,(%r14,%rdx,4)
cmp    $0x2,%rbp
mov    %rbx,%rbp
ja     1160 <shuffle+0x30>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@shuffle.first_time = internal global i32 1
define void @shuffle(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%8 = load i32, i32* @shuffle.first_time
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %2
store i32 0, i32* @shuffle.first_time
%11 = call i64 @time(i32* null)
%12 = trunc i64 %11 to i32
%13 = call i32 @srand(i32 %12)
br label %14
14: ; preds = %10, %2
%15 = load i32, i32* %4
%16 = sub nsw i32 %15, 1
store i32 %16, i32* %5
br label %17
17: ; preds = %43, %14
%18 = load i32, i32* %5
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %46
20: ; preds = %17
%21 = call i32 (...) @rand()
%22 = load i32, i32* %5
%23 = srem i32 %21, %22
store i32 %23, i32* %6
%24 = load i32*, i32** %3
%25 = load i32, i32* %6
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %24, i64 %26
%28 = load i32, i32* %27
store i32 %28, i32* %7
%29 = load i32*, i32** %3
%30 = load i32, i32* %5
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %29, i64 %31
%33 = load i32, i32* %32
%34 = load i32*, i32** %3
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %34, i64 %36
store i32 %33, i32* %37
%38 = load i32, i32* %7
%39 = load i32*, i32** %3
%40 = load i32, i32* %5
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32, i32* %39, i64 %41
store i32 %38, i32* %42
br label %43
43: ; preds = %20
%44 = load i32, i32* %5
%45 = sub nsw i32 %44, 1
store i32 %45, i32* %5
br label %17
46: ; preds = %17
ret void
}

LLVM IR (-O2):
@shuffle.first_time = internal unnamed_addr global i1 false
define void @shuffle(i32* nocapture %0, i32 %1) {
%3 = load i1, i1* @shuffle.first_time
br i1 %3, label %8, label %4
4: ; preds = %2
store i1 true, i1* @shuffle.first_time
%5 = tail call i64 @time(i32* null)
%6 = trunc i64 %5 to i32
%7 = tail call i32 @srand(i32 %6)
br label %8
8: ; preds = %4, %2
%9 = icmp sgt i32 %1, 1
br i1 %9, label %10, label %25
10: ; preds = %8
%11 = zext i32 %1 to i64
br label %12
12: ; preds = %10, %12
%13 = phi i64 [ %11, %10 ], [ %14, %12 ]
%14 = add nsw i64 %13, -1
%15 = trunc i64 %14 to i32
%16 = tail call i32 (...) @rand()
%17 = srem i32 %16, %15
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %0, i64 %18
%20 = load i32, i32* %19
%21 = and i64 %14, 4294967295
%22 = getelementptr inbounds i32, i32* %0, i64 %21
%23 = load i32, i32* %22
store i32 %23, i32* %19
store i32 %20, i32* %22
%24 = icmp ugt i64 %13, 2
br i1 %24, label %12, label %25
25: ; preds = %12, %8
ret void
}