#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 */
double **new_matrix2(int, int);
int /*<<< orphan*/ print_matrix(double **, int, int);
int /*<<< orphan*/ repmat(double **, double **, int, int, int, int);
void test_repmat() {
  double **A = new_matrix2(2, 3);
  int i, j;
  for (i = 0; i < 2; ++i)
    for (j = 0; j < 3; ++j)
      A[i][j] = (3 * i + (j + 1));
  double **B = new_matrix2(4, 9);
  repmat(B, A, 2, 3, 2, 3);
  print_matrix(A, 2, 3);
  print_matrix(B, 4, 9);
}


x86 assembly (clang, -O0):
<test_repmat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x2,%edi
mov    $0x3,%esi
call   1040 <new_matrix2@plt>
mov    %rax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x2,-0xc(%rbp)
jge    11b3 <test_repmat+0x83>
movl   $0x0,-0x10(%rbp)
cmpl   $0x3,-0x10(%rbp)
jge    11a0 <test_repmat+0x70>
imul   $0x3,-0xc(%rbp),%eax
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
add    %ecx,%eax
cvtsi2sd %eax,%xmm0
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x10(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1163 <test_repmat+0x33>
jmp    11a5 <test_repmat+0x75>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1152 <test_repmat+0x22>
mov    $0x4,%edi
mov    $0x9,%esi
call   1040 <new_matrix2@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x2,%r8d
mov    $0x3,%r9d
mov    %r8d,%edx
mov    %r9d,%ecx
call   1030 <repmat@plt>
mov    -0x8(%rbp),%rdi
mov    $0x2,%esi
mov    $0x3,%edx
call   1050 <print_matrix@plt>
mov    -0x18(%rbp),%rdi
mov    $0x4,%esi
mov    $0x9,%edx
call   1050 <print_matrix@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_repmat>:
push   %r14
push   %rbx
push   %rax
mov    $0x2,%edi
mov    $0x3,%esi
call   1040 <new_matrix2@plt>
mov    %rax,%rbx
mov    (%rax),%rax
movaps 0xeb0(%rip),%xmm0
movups %xmm0,(%rax)
movabs $0x4008000000000000,%rcx
mov    %rcx,0x10(%rax)
mov    0x8(%rbx),%rax
movaps 0xea4(%rip),%xmm0
movups %xmm0,(%rax)
movabs $0x4018000000000000,%rcx
mov    %rcx,0x10(%rax)
mov    $0x4,%edi
mov    $0x9,%esi
call   1040 <new_matrix2@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
mov    $0x2,%edx
mov    $0x3,%ecx
mov    $0x2,%r8d
mov    $0x3,%r9d
call   1030 <repmat@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
mov    $0x3,%edx
call   1050 <print_matrix@plt>
mov    %r14,%rdi
mov    $0x4,%esi
mov    $0x9,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <print_matrix@plt>

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

LLVM IR (-O2):
define void @test_repmat() {
%1 = tail call double** @new_matrix2(i32 2, i32 3)
%2 = load double*, double** %1
%3 = bitcast double* %2 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 2.000000e+00>, <2 x double>* %3
%4 = getelementptr inbounds double, double* %2, i64 2
store double 3.000000e+00, double* %4
%5 = getelementptr inbounds double*, double** %1, i64 1
%6 = load double*, double** %5
%7 = bitcast double* %6 to <2 x double>*
store <2 x double> <double 4.000000e+00, double 5.000000e+00>, <2 x double>* %7
%8 = getelementptr inbounds double, double* %6, i64 2
store double 6.000000e+00, double* %8
%9 = tail call double** @new_matrix2(i32 4, i32 9)
%10 = tail call i32 @repmat(double** %9, double** %1, i32 2, i32 3, i32 2, i32 3)
%11 = tail call i32 @print_matrix(double** %1, i32 2, i32 3)
%12 = tail call i32 @print_matrix(double** %9, i32 4, i32 9)
ret void
}