#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*/ do_vect(double **, unsigned long);
int /*<<< orphan*/ free(double *);
int /*<<< orphan*/ permute_dimensions(int, unsigned int, unsigned int,
                                      unsigned int, unsigned int *,
                                      unsigned int *, unsigned int *, int, int,
                                      int, int *, int *, int *);
int permuted_index(int, unsigned long, unsigned int, unsigned int,
                   unsigned int);
void permute_map(int ordermode, unsigned nc, unsigned nr, unsigned ns,
                 unsigned *nx, unsigned *ny, unsigned *nz, int ncstart,
                 int nrstart, int nsstart, int *nxstart, int *nystart,
                 int *nzstart, double *phi, double **pphi) {
  unsigned long nvox, count;
  nvox = nc * nr * ns;
  do_vect(pphi, nvox);
  for (count = 0; count < nvox; count++)
    *(*pphi + permuted_index(ordermode, count, nc, nr, ns)) = *(phi + count);
  free(phi);
  permute_dimensions(ordermode, nc, nr, ns, nx, ny, nz, ncstart, nrstart,
                     nsstart, nxstart, nystart, nzstart);
}


x86 assembly (clang, -O0):
<permute_map>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x80,%rsp
mov    0x50(%rbp),%rax
mov    0x48(%rbp),%rax
mov    0x40(%rbp),%rax
mov    0x38(%rbp),%rax
mov    0x30(%rbp),%rax
mov    0x28(%rbp),%eax
mov    0x20(%rbp),%eax
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%rax
mov    %edi,-0x24(%rbp)
mov    %esi,-0x28(%rbp)
mov    %edx,-0x2c(%rbp)
mov    %ecx,-0x30(%rbp)
mov    %r8,-0x38(%rbp)
mov    %r9,-0x40(%rbp)
mov    -0x28(%rbp),%eax
imul   -0x2c(%rbp),%eax
imul   -0x30(%rbp),%eax
mov    %eax,%eax
mov    %rax,-0x48(%rbp)
mov    0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1060 <do_vect@plt>
movq   $0x0,-0x50(%rbp)
mov    -0x50(%rbp),%rax
cmp    -0x48(%rbp),%rax
jae    1212 <permute_map+0xd2>
mov    0x48(%rbp),%rax
mov    -0x50(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    0x50(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x58(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x50(%rbp),%rsi
mov    -0x28(%rbp),%edx
mov    -0x2c(%rbp),%ecx
mov    -0x30(%rbp),%r8d
call   1030 <permuted_index@plt>
movsd  -0x60(%rbp),%xmm0
mov    %eax,%ecx
mov    -0x58(%rbp),%rax
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
jmp    11ad <permute_map+0x6d>
mov    0x48(%rbp),%rdi
call   1040 <free@plt>
mov    -0x24(%rbp),%edi
mov    -0x28(%rbp),%esi
mov    -0x2c(%rbp),%edx
mov    -0x30(%rbp),%ecx
mov    -0x38(%rbp),%r8
mov    -0x40(%rbp),%r9
mov    0x10(%rbp),%r12
mov    0x18(%rbp),%r15d
mov    0x20(%rbp),%r14d
mov    0x28(%rbp),%ebx
mov    0x30(%rbp),%r11
mov    0x38(%rbp),%r10
mov    0x40(%rbp),%rax
mov    %r12,(%rsp)
mov    %r15d,0x8(%rsp)
mov    %r14d,0x10(%rsp)
mov    %ebx,0x18(%rsp)
mov    %r11,0x20(%rsp)
mov    %r10,0x28(%rsp)
mov    %rax,0x30(%rsp)
call   1050 <permute_dimensions@plt>
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<permute_map>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9,0x18(%rsp)
mov    %r8,0x10(%rsp)
mov    %edi,0x4(%rsp)
mov    0xa0(%rsp),%r15
mov    0x98(%rsp),%r14
mov    %edx,0xc(%rsp)
mov    %edx,%r12d
mov    %esi,%ebp
imul   %esi,%r12d
mov    %ecx,0x8(%rsp)
imul   %ecx,%r12d
mov    %r15,%rdi
mov    %r12,%rsi
call   1060 <do_vect@plt>
test   %r12d,%r12d
je     11dc <permute_map+0x9c>
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  (%r14,%r13,8),%xmm0
movsd  %xmm0,0x20(%rsp)
mov    (%r15),%rbx
mov    0x4(%rsp),%edi
mov    %r13,%rsi
mov    %ebp,%edx
mov    0xc(%rsp),%ecx
mov    0x8(%rsp),%r8d
call   1030 <permuted_index@plt>
cltq
movsd  0x20(%rsp),%xmm0
movsd  %xmm0,(%rbx,%rax,8)
add    $0x1,%r13
cmp    %r13,%r12
jne    11a0 <permute_map+0x60>
mov    %r14,%rdi
call   1040 <free@plt>
mov    0x4(%rsp),%edi
mov    %ebp,%esi
mov    0xc(%rsp),%edx
mov    0x8(%rsp),%ecx
mov    0x10(%rsp),%r8
mov    0x18(%rsp),%r9
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <permute_dimensions@plt>

LLVM IR (-O0):
define void @permute_map(i32 %0, i32 %1, i32 %2, i32 %3, i32* %4, i32* %5, i32* %6, i32 %7, i32 %8, i32 %9, i32* %10, i32* %11, i32* %12, double* %13, double** %14) {
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32*
%21 = alloca i32*
%22 = alloca i32*
%23 = alloca i32
%24 = alloca i32
%25 = alloca i32
%26 = alloca i32*
%27 = alloca i32*
%28 = alloca i32*
%29 = alloca double*
%30 = alloca double**
%31 = alloca i64
%32 = alloca i64
store i32 %0, i32* %16
store i32 %1, i32* %17
store i32 %2, i32* %18
store i32 %3, i32* %19
store i32* %4, i32** %20
store i32* %5, i32** %21
store i32* %6, i32** %22
store i32 %7, i32* %23
store i32 %8, i32* %24
store i32 %9, i32* %25
store i32* %10, i32** %26
store i32* %11, i32** %27
store i32* %12, i32** %28
store double* %13, double** %29
store double** %14, double*** %30
%33 = load i32, i32* %17
%34 = load i32, i32* %18
%35 = mul i32 %33, %34
%36 = load i32, i32* %19
%37 = mul i32 %35, %36
%38 = zext i32 %37 to i64
store i64 %38, i64* %31
%39 = load double**, double*** %30
%40 = load i64, i64* %31
%41 = call i32 @do_vect(double** %39, i64 %40)
store i64 0, i64* %32
br label %42
42: ; preds = %61, %15
%43 = load i64, i64* %32
%44 = load i64, i64* %31
%45 = icmp ult i64 %43, %44
br i1 %45, label %46, label %64
46: ; preds = %42
%47 = load double*, double** %29
%48 = load i64, i64* %32
%49 = getelementptr inbounds double, double* %47, i64 %48
%50 = load double, double* %49
%51 = load double**, double*** %30
%52 = load double*, double** %51
%53 = load i32, i32* %16
%54 = load i64, i64* %32
%55 = load i32, i32* %17
%56 = load i32, i32* %18
%57 = load i32, i32* %19
%58 = call i32 @permuted_index(i32 %53, i64 %54, i32 %55, i32 %56, i32 %57)
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds double, double* %52, i64 %59
store double %50, double* %60
br label %61
61: ; preds = %46
%62 = load i64, i64* %32
%63 = add i64 %62, 1
store i64 %63, i64* %32
br label %42
64: ; preds = %42
%65 = load double*, double** %29
%66 = call i32 @free(double* %65)
%67 = load i32, i32* %16
%68 = load i32, i32* %17
%69 = load i32, i32* %18
%70 = load i32, i32* %19
%71 = load i32*, i32** %20
%72 = load i32*, i32** %21
%73 = load i32*, i32** %22
%74 = load i32, i32* %23
%75 = load i32, i32* %24
%76 = load i32, i32* %25
%77 = load i32*, i32** %26
%78 = load i32*, i32** %27
%79 = load i32*, i32** %28
%80 = call i32 @permute_dimensions(i32 %67, i32 %68, i32 %69, i32 %70, i32* %71, i32* %72, i32* %73, i32 %74, i32 %75, i32 %76, i32* %77, i32* %78, i32* %79)
ret void
}

LLVM IR (-O2):
define void @permute_map(i32 %0, i32 %1, i32 %2, i32 %3, i32* %4, i32* %5, i32* %6, i32 %7, i32 %8, i32 %9, i32* %10, i32* %11, i32* %12, double* nocapture %13, double** %14) {
%16 = mul i32 %2, %1
%17 = mul i32 %16, %3
%18 = zext i32 %17 to i64
%19 = tail call i32 @do_vect(double** %14, i64 %18)
%20 = icmp eq i32 %17, 0
br i1 %20, label %31, label %21
21: ; preds = %15, %21
%22 = phi i64 [ %29, %21 ], [ 0, %15 ]
%23 = getelementptr inbounds double, double* %13, i64 %22
%24 = load double, double* %23
%25 = load double*, double** %14
%26 = tail call i32 @permuted_index(i32 %0, i64 %22, i32 %1, i32 %2, i32 %3)
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds double, double* %25, i64 %27
store double %24, double* %28
%29 = add nuw nsw i64 %22, 1
%30 = icmp eq i64 %29, %18
br i1 %30, label %31, label %21
31: ; preds = %21, %15
%32 = tail call i32 @free(double* %13)
%33 = tail call i32 @permute_dimensions(i32 %0, i32 %1, i32 %2, i32 %3, i32* %4, i32* %5, i32* %6, i32 %7, i32 %8, i32 %9, i32* %10, i32* %11, i32* %12)
ret void
}