#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*/ printf(char *, ...);
void print_mat(const int N, const int LD, const double (*A)[LD]) {
  for (int j = 0; j < N; j++) {
    for (int i = 0; i < N; i++) {
      printf("%.3f ", A[i][j]);
    }
    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    -0x8(%rbp),%eax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11a7 <print_mat+0x97>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    118b <print_mat+0x7b>
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
imul   %rdx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe8a(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1143 <print_mat+0x33>
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1130 <print_mat+0x20>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_mat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edi,%edi
jle    1193 <print_mat+0x73>
mov    %rdx,%r12
mov    %esi,%ebx
mov    %edi,%ebp
shl    $0x3,%rbx
xor    %r13d,%r13d
lea    0xebc(%rip),%r15
mov    %rbp,(%rsp)
nopl   0x0(%rax,%rax,1)
mov    %r12,%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  (%r14),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
add    %rbx,%r14
add    $0xffffffffffffffff,%rbp
jne    1160 <print_mat+0x40>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%r13
add    $0x8,%r12
mov    (%rsp),%rbp
cmp    %rbp,%r13
jne    1150 <print_mat+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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