#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 */
size_t rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void array_shuffle(int *array, size_t n) {
  if (n > 1) {
    srand(time(NULL));
    size_t i;
    for (i = n - 1; i > 0; i--) {
      size_t j = rand() % (i + 1);
      int t = array[i];
      array[i] = array[j];
      array[j] = t;
    }
  }
}


x86 assembly (clang, -O0):
<array_shuffle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x1,-0x10(%rbp)
jbe    11d2 <array_shuffle+0xa2>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
mov    -0x10(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jbe    11cd <array_shuffle+0x9d>
mov    $0x0,%al
call   1050 <rand@plt>
mov    -0x18(%rbp),%rcx
add    $0x1,%rcx
xor    %edx,%edx
div    %rcx
mov    %rdx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%edx
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1167 <array_shuffle+0x37>
jmp    11d2 <array_shuffle+0xa2>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<array_shuffle>:
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%rsi
jb     118a <array_shuffle+0x5a>
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
jmp    1171 <array_shuffle+0x41>
xor    %edx,%edx
div    %rbx
mov    -0x4(%r14,%rbx,4),%eax
mov    (%r14,%rdx,4),%ecx
mov    %ecx,-0x4(%r14,%rbx,4)
mov    %eax,(%r14,%rdx,4)
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
je     118a <array_shuffle+0x5a>
xor    %eax,%eax
call   1050 <rand@plt>
mov    %rax,%rcx
or     %rbx,%rcx
shr    $0x20,%rcx
jne    1150 <array_shuffle+0x20>
xor    %edx,%edx
div    %ebx
jmp    1155 <array_shuffle+0x25>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define void @array_shuffle(i32* nocapture %0, i64 %1) {
%3 = icmp ugt i64 %1, 1
br i1 %3, label %4, label %19
4: ; preds = %2
%5 = tail call i32 @time(i32* null)
%6 = tail call i32 @srand(i32 %5)
%7 = add i64 %1, -1
br label %8
8: ; preds = %4, %8
%9 = phi i64 [ %17, %8 ], [ %7, %4 ]
%10 = phi i64 [ %9, %8 ], [ %1, %4 ]
%11 = tail call i64 (...) @rand()
%12 = urem i64 %11, %10
%13 = getelementptr inbounds i32, i32* %0, i64 %9
%14 = load i32, i32* %13
%15 = getelementptr inbounds i32, i32* %0, i64 %12
%16 = load i32, i32* %15
store i32 %16, i32* %13
store i32 %14, i32* %15
%17 = add i64 %9, -1
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %8
19: ; preds = %8, %2
ret void
}