void print_mat(int m, int n, double *a, int a_row_stride, int a_col_stride) {
  int i, j;
  for (i = 0; i < m; i++) {
    for (j = 0; j < n; j++) {
      printf("%f ", a[(i)*a_row_stride + (j)*a_col_stride]);
    }
    printf("\n");
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<print_mat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11a3 <print_mat+0x93>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1187 <print_mat+0x77>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
imul   -0x14(%rbp),%ecx
mov    -0x20(%rbp),%edx
imul   -0x18(%rbp),%edx
add    %edx,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe8e(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1143 <print_mat+0x33>
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1130 <print_mat+0x20>
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_mat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %esi,0xc(%rsp)
test   %edi,%edi
jle    11ba <print_mat+0x9a>
mov    %rdx,%r12
movslq %r8d,%rbx
movslq %ecx,%rax
mov    %edi,%ecx
mov    %rcx,0x18(%rsp)
mov    0xc(%rsp),%ecx
mov    %rcx,0x10(%rsp)
shl    $0x3,%rax
mov    %rax,0x20(%rsp)
shl    $0x3,%rbx
xor    %r14d,%r14d
lea    0xe96(%rip),%rbp
jmp    118a <print_mat+0x6a>
nopl   0x0(%rax)
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%r14
add    0x20(%rsp),%r12
cmp    0x18(%rsp),%r14
je     11ba <print_mat+0x9a>
cmpl   $0x0,0xc(%rsp)
jle    1170 <print_mat+0x50>
mov    0x10(%rsp),%r13
mov    %r12,%r15
nopl   0x0(%rax)
movsd  (%r15),%xmm0
mov    %rbp,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
add    %rbx,%r15
add    $0xffffffffffffffff,%r13
jne    11a0 <print_mat+0x80>
jmp    1170 <print_mat+0x50>
mov    $0xa,%edi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

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

LLVM IR (-O2):
@.str = [4 x i8] c"%f \00"
define void @print_mat(i32 %0, i32 %1, double* nocapture %2, i32 %3, i32 %4) {
%6 = icmp sgt i32 %0, 0
br i1 %6, label %7, label %30
7: ; preds = %5
%8 = icmp sgt i32 %1, 0
%9 = sext i32 %4 to i64
%10 = sext i32 %3 to i64
%11 = zext i32 %0 to i64
%12 = zext i32 %1 to i64
br label %13
13: ; preds = %7, %26
%14 = phi i64 [ 0, %7 ], [ %28, %26 ]
br i1 %8, label %15, label %26
15: ; preds = %13
%16 = mul nsw i64 %14, %10
br label %17
17: ; preds = %15, %17
%18 = phi i64 [ 0, %15 ], [ %24, %17 ]
%19 = mul nsw i64 %18, %9
%20 = add nsw i64 %19, %16
%21 = getelementptr inbounds double, double* %2, i64 %20
%22 = load double, double* %21
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double %22)
%24 = add nuw nsw i64 %18, 1
%25 = icmp eq i64 %24, %12
br i1 %25, label %26, label %17
26: ; preds = %17, %13
%27 = tail call i32 @putchar(i32 10)
%28 = add nuw nsw i64 %14, 1
%29 = icmp eq i64 %28, %11
br i1 %29, label %30, label %13
30: ; preds = %26, %5
%31 = tail call i32 @putchar(i32 10)
ret void
}