#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 matrix_print(unsigned char *matrix, unsigned int size) {
  unsigned long k;
  for (k = 0; k < size * size; k++) {
    printf("%3d ", matrix[k]);
    if ((k + 1) % size == 0)
      printf("\n");
  }
}


x86 assembly (clang, -O0):
<matrix_print>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
imul   -0xc(%rbp),%ecx
mov    %ecx,%ecx
cmp    %rcx,%rax
jae    1195 <matrix_print+0x85>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    -0xc(%rbp),%ecx
xor    %edx,%edx
div    %rcx
cmp    $0x0,%rdx
jne    117f <matrix_print+0x6f>
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1184 <matrix_print+0x74>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1127 <matrix_print+0x17>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matrix_print>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %esi,%r12d
imul   %r12d,%r12d
test   %r12d,%r12d
je     11a8 <matrix_print+0x88>
mov    %rdi,%r14
mov    %esi,%r13d
neg    %r12
mov    $0x1,%ebx
lea    0xeb6(%rip),%r15
jmp    1162 <matrix_print+0x42>
nopl   0x0(%rax)
lea    (%r12,%rbx,1),%rax
add    $0x1,%rax
add    $0x1,%rbx
cmp    $0x1,%rax
je     11a8 <matrix_print+0x88>
movzbl -0x1(%r14,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rax
shr    $0x20,%rax
je     1190 <matrix_print+0x70>
mov    %rbx,%rax
xor    %edx,%edx
div    %r13
test   %rdx,%rdx
jne    1150 <matrix_print+0x30>
jmp    119c <matrix_print+0x7c>
nopw   0x0(%rax,%rax,1)
mov    %ebx,%eax
xor    %edx,%edx
div    %r13d
test   %rdx,%rdx
jne    1150 <matrix_print+0x30>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1150 <matrix_print+0x30>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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