#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*/ MatrixCopy(double *, int, int, double *);
int /*<<< orphan*/ printf(char *, ...);
void test_MatrixCopy() {
  double a[3][4] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
  double b[3][4];
  MatrixCopy((double *)a, 3, 4, (double *)b);
  int i, j;
  for (i = 0; i < 3; i++) {
    for (j = 0; j < 4; j++) {
      printf("%lf\t", b[i][j]);
    }
    printf("\n");
  }
  return;
}


x86 assembly (clang, -O0):
<test_MatrixCopy>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
lea    -0x60(%rbp),%rdi
lea    0xeba(%rip),%rsi
mov    $0x60,%edx
call   1050 <memcpy@plt>
lea    -0x60(%rbp),%rdi
lea    -0xc0(%rbp),%rcx
mov    $0x3,%esi
mov    $0x4,%edx
call   1040 <MatrixCopy@plt>
movl   $0x0,-0xc4(%rbp)
cmpl   $0x3,-0xc4(%rbp)
jge    11fd <test_MatrixCopy+0xcd>
movl   $0x0,-0xc8(%rbp)
cmpl   $0x4,-0xc8(%rbp)
jge    11db <test_MatrixCopy+0xab>
movslq -0xc4(%rbp),%rcx
lea    -0xc0(%rbp),%rax
shl    $0x5,%rcx
add    %rcx,%rax
movslq -0xc8(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xea0(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0xc8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc8(%rbp)
jmp    118b <test_MatrixCopy+0x5b>
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc4(%rbp)
jmp    1174 <test_MatrixCopy+0x44>
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_MatrixCopy>:
push   %rbx
sub    $0xc0,%rsp
movaps 0xf11(%rip),%xmm0
movaps %xmm0,0xb0(%rsp)
movaps 0xef2(%rip),%xmm0
movaps %xmm0,0xa0(%rsp)
movaps 0xed3(%rip),%xmm0
movaps %xmm0,0x90(%rsp)
movaps 0xeb4(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
movaps 0xe95(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xe79(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
lea    0x60(%rsp),%rdi
mov    %rsp,%rcx
mov    $0x3,%esi
mov    $0x4,%edx
call   1050 <MatrixCopy@plt>
movsd  (%rsp),%xmm0
lea    0xeb1(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  0x8(%rsp),%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  0x10(%rsp),%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  0x18(%rsp),%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
movsd  0x20(%rsp),%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  0x28(%rsp),%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  0x30(%rsp),%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  0x38(%rsp),%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
movsd  0x40(%rsp),%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  0x48(%rsp),%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  0x50(%rsp),%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  0x58(%rsp),%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0xc0,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.test_MatrixCopy.a = [3 x [4 x double]] [[4 x double] [double 1.000000e+00, double 2.000000e+00, double 3.000000e+00, double 4.000000e+00], [4 x double] [double 5.000000e+00, double 6.000000e+00, double 7.000000e+00, double 8.000000e+00], [4 x double] [double 9.000000e+00, double 1.000000e+01, double 1.100000e+01, double 1.200000e+01]]
@.str = [5 x i8] c"%lf\09\00"
@.str.1 = [2 x i8] c"\0A\00"
define void @test_MatrixCopy() {
%1 = alloca [3 x [4 x double]]
%2 = alloca [3 x [4 x double]]
%3 = alloca i32
%4 = alloca i32
%5 = bitcast [3 x [4 x double]]* %1 to i8*
%6 = getelementptr inbounds [3 x [4 x double]], [3 x [4 x double]]* %1, i64 0, i64 0
%7 = bitcast [4 x double]* %6 to double*
%8 = getelementptr inbounds [3 x [4 x double]], [3 x [4 x double]]* %2, i64 0, i64 0
%9 = bitcast [4 x double]* %8 to double*
%10 = call i32 @MatrixCopy(double* %7, i32 3, i32 4, double* %9)
store i32 0, i32* %3
br label %11
11: ; preds = %32, %0
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 3
br i1 %13, label %14, label %35
14: ; preds = %11
store i32 0, i32* %4
br label %15
15: ; preds = %27, %14
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 4
br i1 %17, label %18, label %30
18: ; preds = %15
%19 = load i32, i32* %3
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [3 x [4 x double]], [3 x [4 x double]]* %2, i64 0, i64 %20
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [4 x double], [4 x double]* %21, i64 0, i64 %23
%25 = load double, double* %24
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %25)
br label %27
27: ; preds = %18
%28 = load i32, i32* %4
%29 = add nsw i32 %28, 1
store i32 %29, i32* %4
br label %15
30: ; preds = %15
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %32
32: ; preds = %30
%33 = load i32, i32* %3
%34 = add nsw i32 %33, 1
store i32 %34, i32* %3
br label %11
35: ; preds = %11
ret void
}

LLVM IR (-O2):
@__const.test_MatrixCopy.a = [3 x [4 x double]] [[4 x double] [double 1.000000e+00, double 2.000000e+00, double 3.000000e+00, double 4.000000e+00], [4 x double] [double 5.000000e+00, double 6.000000e+00, double 7.000000e+00, double 8.000000e+00], [4 x double] [double 9.000000e+00, double 1.000000e+01, double 1.100000e+01, double 1.200000e+01]]
@.str = [5 x i8] c"%lf\09\00"
define void @test_MatrixCopy() {
%1 = alloca [3 x [4 x double]]
%2 = alloca [3 x [4 x double]]
%3 = bitcast [3 x [4 x double]]* %1 to i8*
%4 = bitcast [3 x [4 x double]]* %2 to i8*
%5 = getelementptr inbounds [3 x [4 x double]], [3 x [4 x double]]* %1, i64 0, i64 0, i64 0
%6 = getelementptr inbounds [3 x [4 x double]], [3 x [4 x double]]* %2, i64 0, i64 0, i64 0
%7 = call i32 @MatrixCopy(double* %5, i32 3, i32 4, double* %6)
%8 = load double, double* %6
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %8)
%10 = getelementptr inbounds [3 x [4 x double]], [3 x [4 x double]]* %2, i64 0, i64 0, i64 1
%11 = load double, double* %10
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %11)
%13 = getelementptr inbounds [3 x [4 x double]], [3 x [4 x double]]* %2, i64 0, i64 0, i64 2
%14 = load double, double* %13
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %14)
%16 = getelementptr inbounds [3 x [4 x double]], [3 x [4 x double]]* %2, i64 0, i64 0, i64 3
%17 = load double, double* %16
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %17)
%19 = call i32 @putchar(i32 10)
%20 = getelementptr inbounds [3 x [4 x double]], [3 x [4 x double]]* %2, i64 0, i64 1, i64 0
%21 = load double, double* %20
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %21)
%23 = getelementptr inbounds [3 x [4 x double]], [3 x [4 x double]]* %2, i64 0, i64 1, i64 1
%24 = load double, double* %23
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %24)
%26 = getelementptr inbounds [3 x [4 x double]], [3 x [4 x double]]* %2, i64 0, i64 1, i64 2
%27 = load double, double* %26
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %27)
%29 = getelementptr inbounds [3 x [4 x double]], [3 x [4 x double]]* %2, i64 0, i64 1, i64 3
%30 = load double, double* %29
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %30)
%32 = call i32 @putchar(i32 10)
%33 = getelementptr inbounds [3 x [4 x double]], [3 x [4 x double]]* %2, i64 0, i64 2, i64 0
%34 = load double, double* %33
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %34)
%36 = getelementptr inbounds [3 x [4 x double]], [3 x [4 x double]]* %2, i64 0, i64 2, i64 1
%37 = load double, double* %36
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %37)
%39 = getelementptr inbounds [3 x [4 x double]], [3 x [4 x double]]* %2, i64 0, i64 2, i64 2
%40 = load double, double* %39
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %40)
%42 = getelementptr inbounds [3 x [4 x double]], [3 x [4 x double]]* %2, i64 0, i64 2, i64 3
%43 = load double, double* %42
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %43)
%45 = call i32 @putchar(i32 10)
ret void
}