#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 */
void nl_dvector_permute(const double *a, const size_t *P, size_t n, double *b) {
  size_t k;
  for (k = 0; k < n; k++)
    b[k] = a[P[k]];
}


x86 assembly (clang, -O0):
<nl_dvector_permute>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    115d <nl_dvector_permute+0x5d>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    -0x28(%rbp),%rdx
mov    (%rcx,%rdx,8),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    111c <nl_dvector_permute+0x1c>
pop    %rbp
ret

x86 assembly (clang, -O2):
<nl_dvector_permute>:
test   %rdx,%rdx
je     11a7 <nl_dvector_permute+0xa7>
lea    -0x1(%rdx),%rax
mov    %edx,%r8d
and    $0x3,%r8d
cmp    $0x3,%rax
jae    111f <nl_dvector_permute+0x1f>
xor    %r9d,%r9d
jmp    117b <nl_dvector_permute+0x7b>
and    $0xfffffffffffffffc,%rdx
xor    %r9d,%r9d
cs nopw 0x0(%rax,%rax,1)
mov    (%rsi,%r9,8),%rax
movsd  (%rdi,%rax,8),%xmm0
movsd  %xmm0,(%rcx,%r9,8)
mov    0x8(%rsi,%r9,8),%rax
movsd  (%rdi,%rax,8),%xmm0
movsd  %xmm0,0x8(%rcx,%r9,8)
mov    0x10(%rsi,%r9,8),%rax
movsd  (%rdi,%rax,8),%xmm0
movsd  %xmm0,0x10(%rcx,%r9,8)
mov    0x18(%rsi,%r9,8),%rax
movsd  (%rdi,%rax,8),%xmm0
movsd  %xmm0,0x18(%rcx,%r9,8)
add    $0x4,%r9
cmp    %r9,%rdx
jne    1130 <nl_dvector_permute+0x30>
test   %r8,%r8
je     11a7 <nl_dvector_permute+0xa7>
lea    (%rcx,%r9,8),%rcx
lea    (%rsi,%r9,8),%rax
xor    %edx,%edx
nopw   0x0(%rax,%rax,1)
mov    (%rax,%rdx,8),%rsi
movsd  (%rdi,%rsi,8),%xmm0
movsd  %xmm0,(%rcx,%rdx,8)
add    $0x1,%rdx
cmp    %rdx,%r8
jne    1190 <nl_dvector_permute+0x90>
ret

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

LLVM IR (-O2):
define void @nl_dvector_permute(double* nocapture %0, i64* nocapture %1, i64 %2, double* nocapture writeonly %3) {
%5 = icmp eq i64 %2, 0
br i1 %5, label %55, label %6
6: ; preds = %4
%7 = add i64 %2, -1
%8 = and i64 %2, 3
%9 = icmp ult i64 %7, 3
br i1 %9, label %41, label %10
10: ; preds = %6
%11 = and i64 %2, -4
br label %12
12: ; preds = %12, %10
%13 = phi i64 [ 0, %10 ], [ %38, %12 ]
%14 = phi i64 [ 0, %10 ], [ %39, %12 ]
%15 = getelementptr inbounds i64, i64* %1, i64 %13
%16 = load i64, i64* %15
%17 = getelementptr inbounds double, double* %0, i64 %16
%18 = load double, double* %17
%19 = getelementptr inbounds double, double* %3, i64 %13
store double %18, double* %19
%20 = or i64 %13, 1
%21 = getelementptr inbounds i64, i64* %1, i64 %20
%22 = load i64, i64* %21
%23 = getelementptr inbounds double, double* %0, i64 %22
%24 = load double, double* %23
%25 = getelementptr inbounds double, double* %3, i64 %20
store double %24, double* %25
%26 = or i64 %13, 2
%27 = getelementptr inbounds i64, i64* %1, i64 %26
%28 = load i64, i64* %27
%29 = getelementptr inbounds double, double* %0, i64 %28
%30 = load double, double* %29
%31 = getelementptr inbounds double, double* %3, i64 %26
store double %30, double* %31
%32 = or i64 %13, 3
%33 = getelementptr inbounds i64, i64* %1, i64 %32
%34 = load i64, i64* %33
%35 = getelementptr inbounds double, double* %0, i64 %34
%36 = load double, double* %35
%37 = getelementptr inbounds double, double* %3, i64 %32
store double %36, double* %37
%38 = add nuw i64 %13, 4
%39 = add i64 %14, 4
%40 = icmp eq i64 %39, %11
br i1 %40, label %41, label %12
41: ; preds = %12, %6
%42 = phi i64 [ 0, %6 ], [ %38, %12 ]
%43 = icmp eq i64 %8, 0
br i1 %43, label %55, label %44
44: ; preds = %41, %44
%45 = phi i64 [ %52, %44 ], [ %42, %41 ]
%46 = phi i64 [ %53, %44 ], [ 0, %41 ]
%47 = getelementptr inbounds i64, i64* %1, i64 %45
%48 = load i64, i64* %47
%49 = getelementptr inbounds double, double* %0, i64 %48
%50 = load double, double* %49
%51 = getelementptr inbounds double, double* %3, i64 %45
store double %50, double* %51
%52 = add nuw i64 %45, 1
%53 = add i64 %46, 1
%54 = icmp eq i64 %53, %8
br i1 %54, label %55, label %44
55: ; preds = %41, %44, %4
ret void
}