#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 *, double const);
void printMat(const int matsize, const double *mat) {
  int i, j;
  printf("N=%d\n", matsize);
  for (i = 0; i < matsize; i++) {
    for (j = 0; j < matsize; j++) {
      printf("%f\n", mat[i * matsize + j]);
    }
  }
}


x86 assembly (clang, -O0):
<printMat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cvtsi2sdl -0x4(%rbp),%xmm0
lea    0xed5(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1199 <printMat+0x89>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1186 <printMat+0x76>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
imul   -0x4(%rbp),%ecx
add    -0x18(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe93(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    114a <printMat+0x3a>
jmp    118b <printMat+0x7b>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1137 <printMat+0x27>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printMat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r13
mov    %edi,%ebp
cvtsi2sd %edi,%xmm0
lea    0xed5(%rip),%rdi
call   1030 <printf@plt>
test   %ebp,%ebp
jle    1184 <printMat+0x74>
mov    %ebp,%ebp
lea    0x0(,%rbp,8),%r15
xor    %r12d,%r12d
lea    0xebe(%rip),%r14
nopl   0x0(%rax,%rax,1)
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  0x0(%r13,%rbx,8),%xmm0
mov    %r14,%rdi
call   1030 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1160 <printMat+0x50>
add    $0x1,%r12
add    %r15,%r13
cmp    %rbp,%r12
jne    1150 <printMat+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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