#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__ ULONG_MAX;
double rnd_1279();
void perm(double *data, long n, long p) {
  long i, change1, change2;
  double help;
  for (i = 0; i < p; i++) {
    change1 = (long)((rnd_1279() / (double)ULONG_MAX) * n);
    change2 = (long)((rnd_1279() / (double)ULONG_MAX) * n);
    help = data[change1];
    data[change1] = data[change2];
    data[change2] = help;
  }
}


x86 assembly (clang, -O0):
<perm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    11dd <perm+0xcd>
mov    $0x0,%al
call   1030 <rnd_1279@plt>
mov    0x2e90(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
cvtsi2sdq -0x10(%rbp),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1030 <rnd_1279@plt>
mov    0x2e66(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
cvtsi2sdq -0x10(%rbp),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x38(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x30(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    112c <perm+0x1c>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<perm>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdx,%rdx
jle    1198 <perm+0x88>
mov    %rdx,%rbx
mov    %rdi,%r14
cvtsi2sd %rsi,%xmm0
movsd  %xmm0,(%rsp)
mov    0x2ea4(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1030 <rnd_1279@plt>
xorps  %xmm1,%xmm1
cvtsi2sdq (%r15),%xmm1
divsd  %xmm1,%xmm0
mulsd  (%rsp),%xmm0
cvttsd2si %xmm0,%r12
xor    %eax,%eax
call   1030 <rnd_1279@plt>
xorps  %xmm1,%xmm1
cvtsi2sdq (%r15),%xmm1
divsd  %xmm1,%xmm0
mulsd  (%rsp),%xmm0
cvttsd2si %xmm0,%rax
movsd  (%r14,%r12,8),%xmm0
movsd  (%r14,%rax,8),%xmm1
movsd  %xmm1,(%r14,%r12,8)
movsd  %xmm0,(%r14,%rax,8)
add    $0xffffffffffffffff,%rbx
jne    1140 <perm+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@ULONG_MAX = global i64 0
define void @perm(double* %0, i64 %1, i64 %2) {
%4 = alloca double*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca double
store double* %0, double** %4
store i64 %1, i64* %5
store i64 %2, i64* %6
store i64 0, i64* %7
br label %11
11: ; preds = %47, %3
%12 = load i64, i64* %7
%13 = load i64, i64* %6
%14 = icmp slt i64 %12, %13
br i1 %14, label %15, label %50
15: ; preds = %11
%16 = call double (...) @rnd_1279()
%17 = load i64, i64* @ULONG_MAX
%18 = sitofp i64 %17 to double
%19 = fdiv double %16, %18
%20 = load i64, i64* %5
%21 = sitofp i64 %20 to double
%22 = fmul double %19, %21
%23 = fptosi double %22 to i64
store i64 %23, i64* %8
%24 = call double (...) @rnd_1279()
%25 = load i64, i64* @ULONG_MAX
%26 = sitofp i64 %25 to double
%27 = fdiv double %24, %26
%28 = load i64, i64* %5
%29 = sitofp i64 %28 to double
%30 = fmul double %27, %29
%31 = fptosi double %30 to i64
store i64 %31, i64* %9
%32 = load double*, double** %4
%33 = load i64, i64* %8
%34 = getelementptr inbounds double, double* %32, i64 %33
%35 = load double, double* %34
store double %35, double* %10
%36 = load double*, double** %4
%37 = load i64, i64* %9
%38 = getelementptr inbounds double, double* %36, i64 %37
%39 = load double, double* %38
%40 = load double*, double** %4
%41 = load i64, i64* %8
%42 = getelementptr inbounds double, double* %40, i64 %41
store double %39, double* %42
%43 = load double, double* %10
%44 = load double*, double** %4
%45 = load i64, i64* %9
%46 = getelementptr inbounds double, double* %44, i64 %45
store double %43, double* %46
br label %47
47: ; preds = %15
%48 = load i64, i64* %7
%49 = add nsw i64 %48, 1
store i64 %49, i64* %7
br label %11
50: ; preds = %11
ret void
}

LLVM IR (-O2):
@ULONG_MAX = global i64 0
define void @perm(double* nocapture %0, i64 %1, i64 %2) {
%4 = icmp sgt i64 %2, 0
br i1 %4, label %5, label %27
5: ; preds = %3
%6 = sitofp i64 %1 to double
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ 0, %5 ], [ %25, %7 ]
%9 = tail call double (...) @rnd_1279()
%10 = load i64, i64* @ULONG_MAX
%11 = sitofp i64 %10 to double
%12 = fdiv double %9, %11
%13 = fmul double %12, %6
%14 = fptosi double %13 to i64
%15 = tail call double (...) @rnd_1279()
%16 = load i64, i64* @ULONG_MAX
%17 = sitofp i64 %16 to double
%18 = fdiv double %15, %17
%19 = fmul double %18, %6
%20 = fptosi double %19 to i64
%21 = getelementptr inbounds double, double* %0, i64 %14
%22 = load double, double* %21
%23 = getelementptr inbounds double, double* %0, i64 %20
%24 = load double, double* %23
store double %24, double* %21
store double %22, double* %23
%25 = add nuw nsw i64 %8, 1
%26 = icmp eq i64 %25, %2
br i1 %26, label %27, label %7
27: ; preds = %7, %3
ret void
}