#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_matrix(int N, char *name, double *matrix) {
  printf("\nMatrix %s\n", name);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      printf("%8g\t", matrix[N * i + j]);
    }
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<print_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xed2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11a9 <print_matrix+0x99>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    118d <print_matrix+0x7d>
mov    -0x18(%rbp),%rax
mov    -0x4(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
add    -0x20(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe94(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    114f <print_matrix+0x3f>
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113c <print_matrix+0x2c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_matrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r13
mov    %edi,%ebp
lea    0xec9(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebp,%ebp
jle    11a0 <print_matrix+0x80>
mov    %ebp,%ebp
lea    0x0(,%rbp,8),%r15
xor    %r12d,%r12d
lea    0xeb6(%rip),%r14
cs nopw 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
mov    $0x1,%al
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1170 <print_matrix+0x50>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%r12
add    %r15,%r13
cmp    %rbp,%r12
jne    1160 <print_matrix+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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