#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();
void shuffle(int *array) {
  for (int i = 1000000 - 1 - 1; i > 0; i--) {
    int j = rand() % (i + 1);
    int tmp = array[j];
    array[j] = array[i];
    array[i] = tmp;
  }
}


x86 assembly (clang, -O0):
<shuffle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0xf423e,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    1180 <shuffle+0x70>
mov    $0x0,%al
call   1030 <rand@plt>
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
cltd
idiv   %ecx
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1123 <shuffle+0x13>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shuffle>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0xf423f,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <rand@plt>
cltd
idiv   %ebx
movslq %edx,%rax
mov    (%r14,%rax,4),%ecx
mov    -0x4(%r14,%rbx,4),%edx
mov    %edx,(%r14,%rax,4)
mov    %ecx,-0x4(%r14,%rbx,4)
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
ja     1120 <shuffle+0x10>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define void @shuffle(i32* nocapture %0) {
br label %3
2: ; preds = %3
ret void
3: ; preds = %1, %3
%4 = phi i64 [ 999998, %1 ], [ %14, %3 ]
%5 = tail call i32 (...) @rand()
%6 = trunc i64 %4 to i32
%7 = add i32 %6, 1
%8 = srem i32 %5, %7
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i32, i32* %0, i64 %9
%11 = load i32, i32* %10
%12 = getelementptr inbounds i32, i32* %0, i64 %4
%13 = load i32, i32* %12
store i32 %13, i32* %10
store i32 %11, i32* %12
%14 = add nsw i64 %4, -1
%15 = icmp ugt i64 %4, 1
br i1 %15, label %3, label %2
}