#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 */
size_t get_index(unsigned int, unsigned int, unsigned int const);
int /*<<< orphan*/ printf(char *, ...);
void print_matrix(float (*A)[4][4], const unsigned int N) {
  unsigned int i_block, j_block;
  unsigned int i, j;
  float *A_linear;
  for (i = 0; i < N / 4; i++) {
    for (i_block = 0; i_block < 4; i_block++) {
      for (j = 0; j < N / 4; j++) {
        for (j_block = 0; j_block < 4; j_block++) {
          printf("% 1.4f ", A[get_index(i, j, N / 4)][i_block][j_block]);
        }
      }
      printf("\n");
    }
  }
  printf("memory layout, linear: ");
  A_linear = &(A[0][0][0]);
  for (i = 0; i < N * N; ++i) {
    printf("% 1.3f ", A_linear[i]);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<print_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0xc(%rbp),%ecx
shr    $0x2,%ecx
cmp    %ecx,%eax
jae    121c <print_matrix+0xfc>
movl   $0x0,-0x10(%rbp)
cmpl   $0x4,-0x10(%rbp)
jae    1209 <print_matrix+0xe9>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0xc(%rbp),%ecx
shr    $0x2,%ecx
cmp    %ecx,%eax
jae    11ed <print_matrix+0xcd>
movl   $0x0,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jae    11da <print_matrix+0xba>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0xc(%rbp),%edx
shr    $0x2,%edx
call   1030 <get_index@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
shl    $0x6,%rcx
add    %rcx,%rax
mov    -0x10(%rbp),%ecx
shl    $0x4,%rcx
add    %rcx,%rax
mov    -0x14(%rbp),%ecx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe3b(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1177 <print_matrix+0x57>
jmp    11df <print_matrix+0xbf>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115f <print_matrix+0x3f>
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    114e <print_matrix+0x2e>
jmp    120e <print_matrix+0xee>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1136 <print_matrix+0x16>
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0xc(%rbp),%ecx
imul   -0xc(%rbp),%ecx
cmp    %ecx,%eax
jae    1277 <print_matrix+0x157>
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%ecx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdc0(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1239 <print_matrix+0x119>
lea    0xd8a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_matrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,0x8(%rsp)
mov    %esi,(%rsp)
cmp    $0x4,%esi
jb     1289 <print_matrix+0x159>
mov    (%rsp),%r14d
shr    $0x2,%r14d
cmp    $0x2,%r14d
mov    $0x1,%ebx
cmovae %r14d,%ebx
xor    %eax,%eax
mov    %ebx,0x4(%rsp)
mov    0x8(%rsp),%r13
nop
mov    %rax,0x10(%rsp)
xor    %r12d,%r12d
nopl   0x0(%rax,%rax,1)
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x10(%rsp),%r15
mov    %r15d,%edi
mov    %ebp,%esi
mov    %r14d,%edx
call   1040 <get_index@plt>
shl    $0x6,%rax
add    %r13,%rax
mov    %r14d,%ebx
mov    %r12,%r14
shl    $0x4,%r14
movss  (%r14,%rax,1),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe3c(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    %r15d,%edi
mov    %ebp,%esi
mov    %ebx,%edx
call   1040 <get_index@plt>
shl    $0x6,%rax
add    %r13,%rax
movss  0x4(%r14,%rax,1),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe10(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    %r15d,%edi
mov    %ebp,%esi
mov    %ebx,%edx
call   1040 <get_index@plt>
shl    $0x6,%rax
add    %r13,%rax
movss  0x8(%r14,%rax,1),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xde4(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    %r15d,%edi
mov    %ebp,%esi
mov    %ebx,%edx
call   1040 <get_index@plt>
shl    $0x6,%rax
add    %r13,%rax
movss  0xc(%r14,%rax,1),%xmm0
mov    %ebx,%r14d
lea    0xdb9(%rip),%rdi
mov    0x4(%rsp),%ebx
cvtss2sd %xmm0,%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
add    $0x1,%ebp
cmp    %ebp,%ebx
jne    1190 <print_matrix+0x60>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%r12
cmp    $0x4,%r12
jne    1180 <print_matrix+0x50>
mov    0x10(%rsp),%rax
add    $0x1,%eax
cmp    %ebx,%eax
jne    1170 <print_matrix+0x40>
lea    0xd78(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rsp),%eax
imul   %eax,%eax
test   %eax,%eax
mov    0x8(%rsp),%r15
je     12dd <print_matrix+0x1ad>
mov    %eax,%ebp
xor    %ebx,%ebx
lea    0xd6f(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movss  (%r15,%rbx,4),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r14,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    12c0 <print_matrix+0x190>
mov    $0xa,%edi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"% 1.4f \00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [24 x i8] c"memory layout, linear: \00"
@.str.3 = [8 x i8] c"% 1.3f \00"
define void @print_matrix([4 x [4 x float]]* %0, i32 %1) {
%3 = alloca [4 x [4 x float]]*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca float*
store [4 x [4 x float]]* %0, [4 x [4 x float]]** %3
store i32 %1, i32* %4
store i32 0, i32* %7
br label %10
10: ; preds = %59, %2
%11 = load i32, i32* %7
%12 = load i32, i32* %4
%13 = udiv i32 %12, 4
%14 = icmp ult i32 %11, %13
br i1 %14, label %15, label %62
15: ; preds = %10
store i32 0, i32* %5
br label %16
16: ; preds = %55, %15
%17 = load i32, i32* %5
%18 = icmp ult i32 %17, 4
br i1 %18, label %19, label %58
19: ; preds = %16
store i32 0, i32* %8
br label %20
20: ; preds = %50, %19
%21 = load i32, i32* %8
%22 = load i32, i32* %4
%23 = udiv i32 %22, 4
%24 = icmp ult i32 %21, %23
br i1 %24, label %25, label %53
25: ; preds = %20
store i32 0, i32* %6
br label %26
26: ; preds = %46, %25
%27 = load i32, i32* %6
%28 = icmp ult i32 %27, 4
br i1 %28, label %29, label %49
29: ; preds = %26
%30 = load [4 x [4 x float]]*, [4 x [4 x float]]** %3
%31 = load i32, i32* %7
%32 = load i32, i32* %8
%33 = load i32, i32* %4
%34 = udiv i32 %33, 4
%35 = call i64 @get_index(i32 %31, i32 %32, i32 %34)
%36 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %30, i64 %35
%37 = load i32, i32* %5
%38 = zext i32 %37 to i64
%39 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %36, i64 0, i64 %38
%40 = load i32, i32* %6
%41 = zext i32 %40 to i64
%42 = getelementptr inbounds [4 x float], [4 x float]* %39, i64 0, i64 %41
%43 = load float, float* %42
%44 = fpext float %43 to double
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), double %44)
br label %46
46: ; preds = %29
%47 = load i32, i32* %6
%48 = add i32 %47, 1
store i32 %48, i32* %6
br label %26
49: ; preds = %26
br label %50
50: ; preds = %49
%51 = load i32, i32* %8
%52 = add i32 %51, 1
store i32 %52, i32* %8
br label %20
53: ; preds = %20
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %55
55: ; preds = %53
%56 = load i32, i32* %5
%57 = add i32 %56, 1
store i32 %57, i32* %5
br label %16
58: ; preds = %16
br label %59
59: ; preds = %58
%60 = load i32, i32* %7
%61 = add i32 %60, 1
store i32 %61, i32* %7
br label %10
62: ; preds = %10
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%64 = load [4 x [4 x float]]*, [4 x [4 x float]]** %3
%65 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %64, i64 0
%66 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %65, i64 0, i64 0
%67 = getelementptr inbounds [4 x float], [4 x float]* %66, i64 0, i64 0
store float* %67, float** %9
store i32 0, i32* %7
br label %68
68: ; preds = %82, %62
%69 = load i32, i32* %7
%70 = load i32, i32* %4
%71 = load i32, i32* %4
%72 = mul i32 %70, %71
%73 = icmp ult i32 %69, %72
br i1 %73, label %74, label %85
74: ; preds = %68
%75 = load float*, float** %9
%76 = load i32, i32* %7
%77 = zext i32 %76 to i64
%78 = getelementptr inbounds float, float* %75, i64 %77
%79 = load float, float* %78
%80 = fpext float %79 to double
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), double %80)
br label %82
82: ; preds = %74
%83 = load i32, i32* %7
%84 = add i32 %83, 1
store i32 %84, i32* %7
br label %68
85: ; preds = %68
%86 = 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 = [8 x i8] c"% 1.4f \00"
@.str.2 = [24 x i8] c"memory layout, linear: \00"
@.str.3 = [8 x i8] c"% 1.3f \00"
define void @print_matrix([4 x [4 x float]]* nocapture %0, i32 %1) {
%3 = lshr i32 %1, 2
%4 = icmp ult i32 %1, 4
br i1 %4, label %42, label %5
5: ; preds = %2
%6 = call i32 @llvm.umax.i32(i32 %3, i32 1)
br label %7
7: ; preds = %5, %39
%8 = phi i32 [ %40, %39 ], [ 0, %5 ]
br label %9
9: ; preds = %7, %35
%10 = phi i64 [ 0, %7 ], [ %37, %35 ]
br label %11
11: ; preds = %9, %11
%12 = phi i32 [ 0, %9 ], [ %33, %11 ]
%13 = tail call i64 @get_index(i32 %8, i32 %12, i32 %3)
%14 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %0, i64 %13, i64 %10, i64 0
%15 = load float, float* %14
%16 = fpext float %15 to double
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), double %16)
%18 = tail call i64 @get_index(i32 %8, i32 %12, i32 %3)
%19 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %0, i64 %18, i64 %10, i64 1
%20 = load float, float* %19
%21 = fpext float %20 to double
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), double %21)
%23 = tail call i64 @get_index(i32 %8, i32 %12, i32 %3)
%24 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %0, i64 %23, i64 %10, i64 2
%25 = load float, float* %24
%26 = fpext float %25 to double
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), double %26)
%28 = tail call i64 @get_index(i32 %8, i32 %12, i32 %3)
%29 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %0, i64 %28, i64 %10, i64 3
%30 = load float, float* %29
%31 = fpext float %30 to double
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), double %31)
%33 = add nuw nsw i32 %12, 1
%34 = icmp eq i32 %33, %6
br i1 %34, label %35, label %11
35: ; preds = %11
%36 = tail call i32 @putchar(i32 10)
%37 = add nuw nsw i64 %10, 1
%38 = icmp eq i64 %37, 4
br i1 %38, label %39, label %9
39: ; preds = %35
%40 = add nuw nsw i32 %8, 1
%41 = icmp eq i32 %40, %6
br i1 %41, label %42, label %7
42: ; preds = %39, %2
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%44 = mul i32 %1, %1
%45 = icmp eq i32 %44, 0
br i1 %45, label %56, label %46
46: ; preds = %42
%47 = zext i32 %44 to i64
br label %48
48: ; preds = %46, %48
%49 = phi i64 [ 0, %46 ], [ %54, %48 ]
%50 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %0, i64 0, i64 0, i64 %49
%51 = load float, float* %50
%52 = fpext float %51 to double
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), double %52)
%54 = add nuw nsw i64 %49, 1
%55 = icmp eq i64 %54, %47
br i1 %55, label %56, label %48
56: ; preds = %48, %42
%57 = tail call i32 @putchar(i32 10)
ret void
}