#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 *, ...);
int quantidadeDeAlgarismos(int);
int /*<<< orphan*/ sprintf(char *, char *, int);
void imprimirMatriz(int matriz[][128], int n) {
  int i, j, maiorNumero;
  char format[64];
  maiorNumero = matriz[n - 1][n - 1];
  sprintf(format, "%%%dd", quantidadeDeAlgarismos(maiorNumero));
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      printf(format, matriz[i][j]);
      if (j < n - 1) {
        printf(" ");
      }
    }
    printf("\n");
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<imprimirMatriz>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
shl    $0x9,%rcx
add    %rcx,%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x18(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x18(%rbp),%edi
call   1030 <quantidadeDeAlgarismos@plt>
mov    -0x68(%rbp),%rdi
mov    %eax,%edx
lea    0xe81(%rip),%rsi
call   1050 <sprintf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1219 <imprimirMatriz+0xe9>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11fd <imprimirMatriz+0xcd>
lea    -0x60(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
shl    $0x9,%rcx
add    %rcx,%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11ea <imprimirMatriz+0xba>
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11ef <imprimirMatriz+0xbf>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    119e <imprimirMatriz+0x6e>
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    118b <imprimirMatriz+0x5b>
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<imprimirMatriz>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %esi,%r14d
mov    %rdi,%r13
movslq %esi,%rbx
lea    -0x1(%rbx),%r15
mov    %r15,%rax
shl    $0x9,%rax
add    %rdi,%rax
mov    -0x4(%rax,%rbx,4),%edi
call   1040 <quantidadeDeAlgarismos@plt>
lea    0xe8b(%rip),%rsi
mov    %rsp,%rdi
mov    %eax,%edx
call   1060 <sprintf@plt>
test   %ebx,%ebx
jle    11d9 <imprimirMatriz+0x99>
mov    %r14d,%ebp
mov    %rsp,%r14
xor    %r12d,%r12d
jmp    11aa <imprimirMatriz+0x6a>
xchg   %ax,%ax
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%r12
add    $0x200,%r13
cmp    %rbp,%r12
je     11d9 <imprimirMatriz+0x99>
xor    %ebx,%ebx
jmp    11b9 <imprimirMatriz+0x79>
xchg   %ax,%ax
add    $0x1,%rbx
cmp    %rbx,%rbp
je     1190 <imprimirMatriz+0x50>
mov    0x0(%r13,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    %r15,%rbx
jge    11b0 <imprimirMatriz+0x70>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    11b0 <imprimirMatriz+0x70>
mov    $0xa,%edi
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"%%%dd\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [2 x i8] c"\0A\00"
define void @imprimirMatriz([128 x i32]* %0, i32 %1) {
%3 = alloca [128 x i32]*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [64 x i8]
store [128 x i32]* %0, [128 x i32]** %3
store i32 %1, i32* %4
%9 = load [128 x i32]*, [128 x i32]** %3
%10 = load i32, i32* %4
%11 = sub nsw i32 %10, 1
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [128 x i32], [128 x i32]* %9, i64 %12
%14 = load i32, i32* %4
%15 = sub nsw i32 %14, 1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [128 x i32], [128 x i32]* %13, i64 0, i64 %16
%18 = load i32, i32* %17
store i32 %18, i32* %7
%19 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%20 = load i32, i32* %7
%21 = call i32 @quantidadeDeAlgarismos(i32 %20)
%22 = call i32 @sprintf(i8* %19, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %21)
store i32 0, i32* %5
br label %23
23: ; preds = %55, %2
%24 = load i32, i32* %5
%25 = load i32, i32* %4
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %58
27: ; preds = %23
store i32 0, i32* %6
br label %28
28: ; preds = %50, %27
%29 = load i32, i32* %6
%30 = load i32, i32* %4
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %53
32: ; preds = %28
%33 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%34 = load [128 x i32]*, [128 x i32]** %3
%35 = load i32, i32* %5
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [128 x i32], [128 x i32]* %34, i64 %36
%38 = load i32, i32* %6
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [128 x i32], [128 x i32]* %37, i64 0, i64 %39
%41 = load i32, i32* %40
%42 = call i32 (i8*, ...) @printf(i8* %33, i32 %41)
%43 = load i32, i32* %6
%44 = load i32, i32* %4
%45 = sub nsw i32 %44, 1
%46 = icmp slt i32 %43, %45
br i1 %46, label %47, label %49
47: ; preds = %32
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %49
49: ; preds = %47, %32
br label %50
50: ; preds = %49
%51 = load i32, i32* %6
%52 = add nsw i32 %51, 1
store i32 %52, i32* %6
br label %28
53: ; preds = %28
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %55
55: ; preds = %53
%56 = load i32, i32* %5
%57 = add nsw i32 %56, 1
store i32 %57, i32* %5
br label %23
58: ; preds = %23
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"%%%dd\00"
define void @imprimirMatriz([128 x i32]* nocapture %0, i32 %1) {
%3 = alloca [64 x i8]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%5 = add nsw i32 %1, -1
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds [128 x i32], [128 x i32]* %0, i64 %6, i64 %6
%8 = load i32, i32* %7
%9 = tail call i32 @quantidadeDeAlgarismos(i32 %8)
%10 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = icmp sgt i32 %1, 0
br i1 %11, label %12, label %31
12: ; preds = %2
%13 = zext i32 %1 to i64
br label %14
14: ; preds = %27, %12
%15 = phi i64 [ 0, %12 ], [ %29, %27 ]
br label %16
16: ; preds = %14, %24
%17 = phi i64 [ 0, %14 ], [ %25, %24 ]
%18 = getelementptr inbounds [128 x i32], [128 x i32]* %0, i64 %15, i64 %17
%19 = load i32, i32* %18
%20 = call i32 (i8*, ...) @printf(i8* %4, i32 %19)
%21 = icmp slt i64 %17, %6
br i1 %21, label %22, label %24
22: ; preds = %16
%23 = tail call i32 @putchar(i32 32)
br label %24
24: ; preds = %16, %22
%25 = add nuw nsw i64 %17, 1
%26 = icmp eq i64 %25, %13
br i1 %26, label %27, label %16
27: ; preds = %24
%28 = tail call i32 @putchar(i32 10)
%29 = add nuw nsw i64 %15, 1
%30 = icmp eq i64 %29, %13
br i1 %30, label %31, label %14
31: ; preds = %27, %2
%32 = tail call i32 @putchar(i32 10)
ret void
}