#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 util_rng_next_double();
void shuffle(int len, double *data) {
  int i;
  for (i = len - 1; i >= 1; i--) {
    int j = (int)(util_rng_next_double() * (i + 1));
    double tmp = data[i];
    data[i] = data[j];
    data[j] = tmp;
  }
}


x86 assembly (clang, -O0):
<shuffle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jl     1191 <shuffle+0x81>
mov    $0x0,%al
call   1030 <util_rng_next_double@plt>
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
imul   %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x20(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1128 <shuffle+0x18>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shuffle>:
push   %r15
push   %r14
push   %rbx
cmp    $0x2,%edi
jl     1157 <shuffle+0x47>
mov    %rsi,%r14
mov    %edi,%ebx
nop
lea    -0x1(%rbx),%r15
xor    %eax,%eax
call   1030 <util_rng_next_double@plt>
mov    %ebx,%ecx
imul   %eax,%ecx
mov    %r15d,%eax
movsd  (%r14,%rax,8),%xmm0
movslq %ecx,%rcx
movsd  (%r14,%rcx,8),%xmm1
movsd  %xmm1,(%r14,%rax,8)
movsd  %xmm0,(%r14,%rcx,8)
cmp    $0x2,%rbx
mov    %r15,%rbx
ja     1120 <shuffle+0x10>
pop    %rbx
pop    %r14
pop    %r15
ret

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

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