#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();
void shuffle(int *array, size_t n) {
  for (size_t i = 0; i < n; ++i) {
    int t = array[i];
    int r = rand() % n;
    array[i] = array[r];
    array[r] = t;
  }
}


x86 assembly (clang, -O0):
<shuffle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    118d <shuffle+0x7d>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x10(%rbp)
mov    %edx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1128 <shuffle+0x18>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shuffle>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rsi,%rsi
je     116b <shuffle+0x5b>
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
jmp    114d <shuffle+0x3d>
cs nopw 0x0(%rax,%rax,1)
xor    %edx,%edx
div    %r14
movslq %edx,%rax
mov    (%r15,%rax,4),%ecx
mov    %ecx,(%r15,%rbx,4)
mov    %ebp,(%r15,%rax,4)
add    $0x1,%rbx
cmp    %rbx,%r14
je     116b <shuffle+0x5b>
mov    (%r15,%rbx,4),%ebp
xor    %eax,%eax
call   1030 <rand@plt>
mov    %rax,%rcx
or     %r14,%rcx
shr    $0x20,%rcx
jne    1130 <shuffle+0x20>
xor    %edx,%edx
div    %r14d
jmp    1135 <shuffle+0x25>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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