#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 qtdDigitosF(int);
int qtdDigitosW(int);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int x;
  scanf("%d", &x);
  printf("Qtd dígitos de %d: %d\n", x, qtdDigitosW(x));
  int lx = qtdDigitosF(x);
  printf("#%5d#\n", x);
  int aux = 5 - lx;
  printf("#");
  while (aux > 0) {
    printf(" ");
    aux = aux - 1;
  }
  printf("%d#\n", x);
  int i;
  printf("#");
  for (i = 5 - lx; i > 0; i = i - 1) {
    printf(" ");
  }
  printf("%d#\n", x);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <qtdDigitosW@plt>
mov    -0x18(%rbp),%esi
mov    %eax,%edx
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1050 <qtdDigitosF@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x5,%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x10(%rbp)
jle    11db <main+0x9b>
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11b5 <main+0x75>
mov    -0x8(%rbp),%esi
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x5,%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    122b <main+0xeb>
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1205 <main+0xc5>
mov    -0x8(%rbp),%esi
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
lea    0xea6(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1070 <scanf@plt>
mov    0x4(%rsp),%ebx
mov    %ebx,%edi
call   1040 <qtdDigitosW@plt>
lea    0xe8d(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rsp),%edi
call   1060 <qtdDigitosF@plt>
mov    %eax,%ebx
mov    0x4(%rsp),%esi
lea    0xe84(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x23,%edi
call   1030 <putchar@plt>
cmp    $0x4,%ebx
jg     1214 <main+0xc4>
mov    $0x6,%ebp
sub    %ebx,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x20,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
jg     11c0 <main+0x70>
mov    0x4(%rsp),%esi
lea    0xe45(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x23,%edi
call   1030 <putchar@plt>
cmp    $0x4,%ebx
jg     1230 <main+0xe0>
mov    $0x6,%ebp
sub    %ebx,%ebp
nopw   0x0(%rax,%rax,1)
mov    $0x20,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
jg     1200 <main+0xb0>
jmp    1230 <main+0xe0>
mov    0x4(%rsp),%esi
lea    0xe03(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x23,%edi
call   1030 <putchar@plt>
mov    0x4(%rsp),%esi
lea    0xde7(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [24 x i8] c"Qtd d\C3\ADgitos de %d: %d\0A\00"
@.str.2 = [7 x i8] c"#%5d#\0A\00"
@.str.3 = [2 x i8] c"#\00"
@.str.4 = [2 x i8] c" \00"
@.str.5 = [5 x i8] c"%d#\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%7 = load i32, i32* %2
%8 = load i32, i32* %2
%9 = call i32 @qtdDigitosW(i32 %8)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %7, i32 %9)
%11 = load i32, i32* %2
%12 = call i32 @qtdDigitosF(i32 %11)
store i32 %12, i32* %3
%13 = load i32, i32* %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = load i32, i32* %3
%16 = sub nsw i32 5, %15
store i32 %16, i32* %4
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %18
18: ; preds = %21, %0
%19 = load i32, i32* %4
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %18
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%23 = load i32, i32* %4
%24 = sub nsw i32 %23, 1
store i32 %24, i32* %4
br label %18
25: ; preds = %18
%26 = load i32, i32* %2
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %26)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%29 = load i32, i32* %3
%30 = sub nsw i32 5, %29
store i32 %30, i32* %5
br label %31
31: ; preds = %36, %25
%32 = load i32, i32* %5
%33 = icmp sgt i32 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %31
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %36
36: ; preds = %34
%37 = load i32, i32* %5
%38 = sub nsw i32 %37, 1
store i32 %38, i32* %5
br label %31
39: ; preds = %31
%40 = load i32, i32* %2
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %40)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [24 x i8] c"Qtd d\C3\ADgitos de %d: %d\0A\00"
@.str.2 = [7 x i8] c"#%5d#\0A\00"
@.str.5 = [5 x i8] c"%d#\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%4 = load i32, i32* %1
%5 = call i32 @qtdDigitosW(i32 %4)
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %4, i32 %5)
%7 = load i32, i32* %1
%8 = call i32 @qtdDigitosF(i32 %7)
%9 = load i32, i32* %1
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%11 = sub nsw i32 5, %8
%12 = call i32 @putchar(i32 35)
%13 = icmp slt i32 %8, 5
br i1 %13, label %14, label %28
14: ; preds = %0, %14
%15 = phi i32 [ %17, %14 ], [ %11, %0 ]
%16 = call i32 @putchar(i32 32)
%17 = add nsw i32 %15, -1
%18 = icmp sgt i32 %15, 1
br i1 %18, label %14, label %19
19: ; preds = %14
%20 = load i32, i32* %1
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %20)
%22 = call i32 @putchar(i32 35)
br i1 %13, label %23, label %32
23: ; preds = %19, %23
%24 = phi i32 [ %26, %23 ], [ %11, %19 ]
%25 = call i32 @putchar(i32 32)
%26 = add nsw i32 %24, -1
%27 = icmp sgt i32 %24, 1
br i1 %27, label %23, label %32
28: ; preds = %0
%29 = load i32, i32* %1
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %29)
%31 = call i32 @putchar(i32 35)
br label %32
32: ; preds = %23, %28, %19
%33 = load i32, i32* %1
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %33)
ret i32 0
}