#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*/ memcpy(double *, double *, int);
void m_descramble_rows(double *A, double *B, int nrow, int ncol, int *pr) {
  double *p;
  int i, rowsz = nrow * sizeof(double);
  p = A;
  for (i = 0; i < nrow; i++, p += nrow)
    memcpy(B + nrow * pr[i], p, rowsz);
}


x86 assembly (clang, -O0):
<m_descramble_rows>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    119b <m_descramble_rows+0x8b>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%eax
mov    -0x20(%rbp),%rcx
movslq -0x2c(%rbp),%rdx
imul   (%rcx,%rdx,4),%eax
cltq
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x14(%rbp),%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
jmp    1144 <m_descramble_rows+0x34>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<m_descramble_rows>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %edx,%edx
jle    117d <m_descramble_rows+0x6d>
mov    %r8,%r12
mov    %rsi,%r13
mov    %rdi,%rbx
movslq %edx,%rax
lea    0x0(,%rax,8),%ecx
mov    %ecx,0xc(%rsp)
mov    %edx,%ecx
mov    %rcx,0x10(%rsp)
mov    %rax,%rbp
lea    0x0(,%rax,8),%r14
xor    %r15d,%r15d
xchg   %ax,%ax
movslq (%r12,%r15,4),%rax
imul   %rbp,%rax
lea    0x0(,%rax,8),%rdi
add    %r13,%rdi
mov    %rbx,%rsi
mov    0xc(%rsp),%edx
call   1030 <memcpy@plt>
add    $0x1,%r15
add    %r14,%rbx
cmp    %r15,0x10(%rsp)
jne    1150 <m_descramble_rows+0x40>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @m_descramble_rows(double* %0, double* %1, i32 %2, i32 %3, i32* nocapture %4) {
%6 = sext i32 %2 to i64
%7 = shl i32 %2, 3
%8 = icmp sgt i32 %2, 0
br i1 %8, label %9, label %23
9: ; preds = %5
%10 = zext i32 %2 to i64
br label %11
11: ; preds = %9, %11
%12 = phi i64 [ 0, %9 ], [ %20, %11 ]
%13 = phi double* [ %0, %9 ], [ %21, %11 ]
%14 = getelementptr inbounds i32, i32* %4, i64 %12
%15 = load i32, i32* %14
%16 = mul nsw i32 %15, %2
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds double, double* %1, i64 %17
%19 = tail call i32 @memcpy(double* %18, double* %13, i32 %7)
%20 = add nuw nsw i64 %12, 1
%21 = getelementptr inbounds double, double* %13, i64 %6
%22 = icmp eq i64 %20, %10
br i1 %22, label %23, label %11
23: ; preds = %11, %5
ret void
}