#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(int /*<<< orphan*/);
int /*<<< orphan*/ swap(int *, int *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void shuffle(int arr[], int n) {
  srand(time(NULL));
  int i;
  for (i = n - 1; i > 0; i--) {
    int j = rand() % (i + 1);
    swap(&arr[i], &arr[j]);
  }
}


x86 assembly (clang, -O0):
<shuffle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
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    11b6 <shuffle+0x76>
mov    $0x0,%al
call   1060 <rand@plt>
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x10(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
call   1050 <swap@plt>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1168 <shuffle+0x28>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shuffle>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
cmp    $0x2,%ebp
jl     1189 <shuffle+0x49>
mov    %ebp,%ebp
xchg   %ax,%ax
lea    -0x1(%rbp),%rbx
xor    %eax,%eax
call   1060 <rand@plt>
cltd
idiv   %ebp
mov    %ebx,%eax
lea    (%r14,%rax,4),%rdi
movslq %edx,%rax
lea    (%r14,%rax,4),%rsi
call   1050 <swap@plt>
cmp    $0x2,%rbp
mov    %rbx,%rbp
ja     1160 <shuffle+0x20>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @shuffle(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%7 = call i32 @time(i32* null)
%8 = call i32 @srand(i32 %7)
%9 = load i32, i32* %4
%10 = sub nsw i32 %9, 1
store i32 %10, i32* %5
br label %11
11: ; preds = %28, %2
%12 = load i32, i32* %5
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %31
14: ; preds = %11
%15 = call i32 (...) @rand()
%16 = load i32, i32* %5
%17 = add nsw i32 %16, 1
%18 = srem i32 %15, %17
store i32 %18, i32* %6
%19 = load i32*, i32** %3
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
%23 = load i32*, i32** %3
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
%27 = call i32 @swap(i32* %22, i32* %26)
br label %28
28: ; preds = %14
%29 = load i32, i32* %5
%30 = add nsw i32 %29, -1
store i32 %30, i32* %5
br label %11
31: ; preds = %11
ret void
}

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