#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 */
typedef int j;
typedef size_t i;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
void mat_print(double *a, int rows, int cols) {
  int i, j;
  for (i = 1; i <= rows; i++) {
    printf("  ");
    for (j = 1; j <= cols; j++) {
      printf("%f  ", ((a)[((j)-1) * rows + ((i)-1)]));
    }
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<mat_print>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     11ac <mat_print+0x9c>
lea    0xec6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     1190 <mat_print+0x80>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
imul   -0xc(%rbp),%ecx
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
add    %edx,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe85(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    114a <mat_print+0x3a>
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1129 <mat_print+0x19>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mat_print>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,(%rsp)
test   %esi,%esi
jle    11cb <mat_print+0xab>
mov    %rdi,%r15
mov    %rsi,%rax
mov    %rsi,%rcx
mov    %ecx,%ebp
mov    (%rsp),%rax
add    $0x1,%eax
add    $0x1,%ecx
mov    %rcx,0x10(%rsp)
shl    $0x3,%rbp
add    $0xffffffffffffffff,%rax
mov    %rax,0x8(%rsp)
mov    $0x1,%r12d
lea    0xe92(%rip),%rbx
jmp    1189 <mat_print+0x69>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%r12
add    $0x8,%r15
cmp    0x10(%rsp),%r12
je     11cb <mat_print+0xab>
lea    0xe72(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x0,(%rsp)
jle    1170 <mat_print+0x50>
mov    0x8(%rsp),%r14
mov    %r15,%r13
cs nopw 0x0(%rax,%rax,1)
nop
movsd  0x0(%r13),%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
add    %rbp,%r13
add    $0xffffffffffffffff,%r14
jne    11b0 <mat_print+0x90>
jmp    1170 <mat_print+0x50>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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