#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 getchar_inteiros();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
int main() {
  int num = -2, n_digit = 0, sum_digit = 0;
  do {
    printf("Insira um número inteiro positivo: ");
    num = getchar_inteiros();
    putchar('\n');
  } while (num <= 0);
  while (num > 0) {
    ++n_digit;
    sum_digit += num % 10;
    num = num / 10;
  }
  printf("Número de dígitos: %d\nSoma de dígitos: %d\n", n_digit, sum_digit);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xfffffffe,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getchar_inteiros@plt>
mov    %eax,-0x8(%rbp)
mov    $0xa,%edi
call   1030 <putchar@plt>
cmpl   $0x0,-0x8(%rbp)
jle    1154 <main+0x24>
jmp    1185 <main+0x55>
cmpl   $0x0,-0x8(%rbp)
jle    11bc <main+0x8c>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    -0x10(%rbp),%edx
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
jmp    1185 <main+0x55>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
lea    0xec5(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getchar_inteiros@plt>
mov    %eax,%ebp
mov    $0xa,%edi
call   1030 <putchar@plt>
test   %ebp,%ebp
jle    1140 <main+0x10>
xor    %edx,%edx
mov    $0xcccccccd,%eax
xor    %esi,%esi
nopw   0x0(%rax,%rax,1)
add    $0x1,%esi
mov    %ebp,%ecx
imul   %rax,%rcx
shr    $0x23,%rcx
lea    (%rcx,%rcx,1),%edi
lea    (%rdi,%rdi,4),%edi
mov    %ebp,%ebx
sub    %edi,%ebx
add    %ebx,%edx
cmp    $0x9,%ebp
mov    %ecx,%ebp
ja     1170 <main+0x40>
lea    0xe8e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [37 x i8] c"Insira um n\C3\BAmero inteiro positivo: \00"
@.str.1 = [46 x i8] c"N\C3\BAmero de d\C3\ADgitos: %d\0ASoma de d\C3\ADgitos: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 -2, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
br label %5
5: ; preds = %9, %0
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (...) @getchar_inteiros()
store i32 %7, i32* %2
%8 = call i32 @putchar(i8 signext 10)
br label %9
9: ; preds = %5
%10 = load i32, i32* %2
%11 = icmp sle i32 %10, 0
br i1 %11, label %5, label %12
12: ; preds = %9
br label %13
13: ; preds = %16, %12
%14 = load i32, i32* %2
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %25
16: ; preds = %13
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
store i32 %18, i32* %3
%19 = load i32, i32* %2
%20 = srem i32 %19, 10
%21 = load i32, i32* %4
%22 = add nsw i32 %21, %20
store i32 %22, i32* %4
%23 = load i32, i32* %2
%24 = sdiv i32 %23, 10
store i32 %24, i32* %2
br label %13
25: ; preds = %13
%26 = load i32, i32* %3
%27 = load i32, i32* %4
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32 %26, i32 %27)
ret i32 0
}

LLVM IR (-O2):
@.str = [37 x i8] c"Insira um n\C3\BAmero inteiro positivo: \00"
@.str.1 = [46 x i8] c"N\C3\BAmero de d\C3\ADgitos: %d\0ASoma de d\C3\ADgitos: %d\0A\00"
define i32 @main() {
br label %1
1: ; preds = %1, %0
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 (...) @getchar_inteiros()
%4 = tail call i32 @putchar(i8 signext 10)
%5 = icmp slt i32 %3, 1
br i1 %5, label %1, label %6
6: ; preds = %1, %6
%7 = phi i32 [ %12, %6 ], [ 0, %1 ]
%8 = phi i32 [ %10, %6 ], [ 0, %1 ]
%9 = phi i32 [ %13, %6 ], [ %3, %1 ]
%10 = add nuw nsw i32 %8, 1
%11 = urem i32 %9, 10
%12 = add nuw nsw i32 %7, %11
%13 = udiv i32 %9, 10
%14 = icmp ult i32 %9, 10
br i1 %14, label %15, label %6
15: ; preds = %6
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32 %10, i32 %12)
ret i32 0
}