#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 random();
void shuffle(size_t *items, size_t len) {
  size_t i;
  for (i = 0; i < len; i++) {
    size_t j = random() % len;
    size_t t = items[i];
    items[i] = items[j];
    items[j] = t;
  }
}


x86 assembly (clang, -O0):
<shuffle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1192 <shuffle+0x82>
mov    $0x0,%al
call   1030 <random@plt>
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x10(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x28(%rbp),%rdx
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1128 <shuffle+0x18>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shuffle>:
push   %r15
push   %r14
push   %rbx
test   %rsi,%rsi
je     1168 <shuffle+0x58>
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
jmp    114e <shuffle+0x3e>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %edx,%edx
div    %r14
mov    (%r15,%rbx,8),%rax
mov    (%r15,%rdx,8),%rcx
mov    %rcx,(%r15,%rbx,8)
mov    %rax,(%r15,%rdx,8)
add    $0x1,%rbx
cmp    %rbx,%r14
je     1168 <shuffle+0x58>
xor    %eax,%eax
call   1030 <random@plt>
mov    %rax,%rcx
or     %r14,%rcx
shr    $0x20,%rcx
jne    1130 <shuffle+0x20>
xor    %edx,%edx
div    %r14d
jmp    1135 <shuffle+0x25>
pop    %rbx
pop    %r14
pop    %r15
ret

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

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