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


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    11b5 <shuffle+0x85>
mov    $0x0,%al
call   1050 <rand@plt>
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
cltd
idiv   %ecx
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
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1158 <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     117c <shuffle+0x4c>
mov    %ebp,%ebp
xchg   %ax,%ax
lea    -0x1(%rbp),%rbx
xor    %eax,%eax
call   1050 <rand@plt>
cltd
idiv   %ebp
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     1150 <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
%7 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%8 = call i32 @time(i32* null)
%9 = call i32 @srand(i32 %8)
%10 = load i32, i32* %4
%11 = sub nsw i32 %10, 1
store i32 %11, i32* %5
br label %12
12: ; preds = %39, %2
%13 = load i32, i32* %5
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %42
15: ; preds = %12
%16 = call i32 (...) @rand()
%17 = load i32, i32* %5
%18 = add nsw i32 %17, 1
%19 = srem i32 %16, %18
store i32 %19, i32* %6
%20 = load i32*, i32** %3
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
%24 = load i32, i32* %23
store i32 %24, i32* %7
%25 = load i32*, i32** %3
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %25, i64 %27
%29 = load i32, i32* %28
%30 = load i32*, i32** %3
%31 = load i32, i32* %6
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %30, i64 %32
store i32 %29, i32* %33
%34 = load i32, i32* %7
%35 = load i32*, i32** %3
%36 = load i32, i32* %5
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %35, i64 %37
store i32 %34, i32* %38
br label %39
39: ; preds = %15
%40 = load i32, i32* %5
%41 = add nsw i32 %40, -1
store i32 %41, i32* %5
br label %12
42: ; preds = %12
ret void
}

LLVM IR (-O2):
define void @shuffle(i32* nocapture %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 %21
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 = sext i32 %13 to i64
%15 = getelementptr inbounds i32, i32* %0, i64 %14
%16 = load i32, i32* %15
%17 = and i64 %10, 4294967295
%18 = getelementptr inbounds i32, i32* %0, i64 %17
%19 = load i32, i32* %18
store i32 %19, i32* %15
store i32 %16, i32* %18
%20 = icmp ugt i64 %9, 2
br i1 %20, label %8, label %21
21: ; preds = %8, %2
ret void
}