#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 */
scalar_t__ floor(int);
int rand_lp();
void db_shuffle(double *array, int n) {
  int i, k;
  double tmp;
  k = n;
  while (k > 1) {
    i = (int)floor(k * rand_lp());
    k--;
    tmp = array[k];
    array[k] = array[i];
    array[i] = tmp;
  }
  return;
}


x86 assembly (clang, -O0):
<db_shuffle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jle    11a6 <db_shuffle+0x86>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1030 <rand_lp@plt>
mov    -0x24(%rbp),%edi
imul   %eax,%edi
call   1040 <floor@plt>
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x20(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    1135 <db_shuffle+0x15>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<db_shuffle>:
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%esi
jl     116a <db_shuffle+0x4a>
mov    %rdi,%r14
mov    %esi,%ebx
xchg   %ax,%ax
xor    %eax,%eax
call   1030 <rand_lp@plt>
mov    %ebx,%edi
imul   %eax,%edi
call   1040 <floor@plt>
lea    -0x1(%rbx),%rcx
mov    %ecx,%edx
movsd  (%r14,%rdx,8),%xmm0
cltq
movsd  (%r14,%rax,8),%xmm1
movsd  %xmm1,(%r14,%rdx,8)
movsd  %xmm0,(%r14,%rax,8)
cmp    $0x2,%rbx
mov    %rcx,%rbx
ja     1130 <db_shuffle+0x10>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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