#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 /*<<< orphan*/ INFINITY;
int /*<<< orphan*/ RAND_MAX;
size_t nextafter(int /*<<< orphan*/, int /*<<< orphan*/);
size_t rand();
int /*<<< orphan*/ swap(double *, double *);
void shuffle(double *array, size_t size) {
  for (size_t i = 0; i != size; ++i) {
    int randindex =
        (int)((size - i) * (rand() / nextafter(RAND_MAX, INFINITY)));
    swap(array + i, array + randindex + i);
  }
}


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
je     11dd <shuffle+0xad>
mov    -0x10(%rbp),%rax
sub    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
mov    %rax,-0x30(%rbp)
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
call   1030 <nextafter@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
xor    %edx,%edx
div    %rcx
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
imul   %rcx,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
mov    -0x18(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
call   1040 <swap@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1148 <shuffle+0x18>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shuffle>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rsi,%rsi
je     11d0 <shuffle+0xa0>
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%r12
shl    $0x20,%r12
mov    0x2e90(%rip),%rbp
movabs $0xffffffff00000000,%r13
ff ff ff
jmp    119b <shuffle+0x6b>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rax
xor    %edx,%edx
div    %rcx
mov    %rax,%rsi
imul   %r12,%rsi
sar    $0x1d,%rsi
add    %rbx,%rsi
mov    %rbx,%rdi
call   1040 <swap@plt>
add    $0x8,%rbx
add    %r13,%r12
add    $0xffffffffffffffff,%r14
je     11d0 <shuffle+0xa0>
xor    %eax,%eax
call   1050 <rand@plt>
mov    %rax,%r15
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%esi
call   1030 <nextafter@plt>
mov    %rax,%rcx
mov    %r15,%rax
or     %rcx,%rax
shr    $0x20,%rax
jne    1170 <shuffle+0x40>
mov    %r15d,%eax
xor    %edx,%edx
div    %ecx
mov    %eax,%esi
jmp    117b <shuffle+0x4b>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@RAND_MAX = global i32 0
@INFINITY = global i32 0
define void @shuffle(double* %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 [ %20, %5 ], [ 0, %2 ]
%7 = sub i64 %1, %6
%8 = tail call i64 (...) @rand()
%9 = load i32, i32* @RAND_MAX
%10 = load i32, i32* @INFINITY
%11 = tail call i64 @nextafter(i32 %9, i32 %10)
%12 = udiv i64 %8, %11
%13 = getelementptr inbounds double, double* %0, i64 %6
%14 = shl i64 %7, 32
%15 = mul i64 %14, %12
%16 = ashr exact i64 %15, 32
%17 = getelementptr inbounds double, double* %0, i64 %16
%18 = getelementptr inbounds double, double* %17, i64 %6
%19 = tail call i32 @swap(double* %13, double* %18)
%20 = add nuw i64 %6, 1
%21 = icmp eq i64 %20, %1
br i1 %21, label %4, label %5
}