#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 scanf(char *, int *);
int main() {
  int num = -1, count, n_digit = 0, sum_digit = 0, c;
  count = 0;
  printf("Insira um número inteiro positivo: ");
  while ((!(c = scanf("%d", &num)) || num <= 0) && count < 10) {
    printf("%d %d Número inválido! Tente outra vez: ", num, c);
    ++count;
  }
  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    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec5(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
je     1184 <main+0x64>
xor    %eax,%eax
cmpl   $0x0,-0x8(%rbp)
mov    %al,-0x19(%rbp)
jg     118e <main+0x6e>
cmpl   $0xa,-0xc(%rbp)
setl   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    119e <main+0x7e>
jmp    11c0 <main+0xa0>
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1159 <main+0x39>
jmp    11c5 <main+0xa5>
cmpl   $0x0,-0x8(%rbp)
jle    11fc <main+0xdc>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    -0x14(%rbp),%edx
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
jmp    11c5 <main+0xa5>
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
movl   $0xffffffff,0x4(%rsp)
ff
lea    0xec9(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xee0(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x4(%rsp),%esi
test   %eax,%eax
je     115b <main+0x3b>
test   %esi,%esi
jg     11aa <main+0x8a>
lea    0xec6(%rip),%r14
lea    0xebc(%rip),%r15
lea    0x4(%rsp),%r12
xor    %ebx,%ebx
mov    %r14,%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1040 <scanf@plt>
test   %eax,%eax
sete   %cl
mov    0x4(%rsp),%esi
test   %esi,%esi
setle  %dl
or     %cl,%dl
cmp    $0x1,%dl
jne    11a6 <main+0x86>
lea    0x1(%rbx),%ecx
cmp    $0x9,%ebx
mov    %ecx,%ebx
jb     1170 <main+0x50>
test   %esi,%esi
jle    11e6 <main+0xc6>
xor    %edx,%edx
mov    $0xcccccccd,%r8d
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %esi,%ecx
add    $0x1,%eax
mov    %esi,%esi
imul   %r8,%rsi
shr    $0x23,%rsi
lea    (%rsi,%rsi,1),%ebx
lea    (%rbx,%rbx,4),%ebx
mov    %ecx,%edi
sub    %ebx,%edi
add    %edi,%edx
cmp    $0x9,%ecx
ja     11c0 <main+0xa0>
mov    %esi,0x4(%rsp)
jmp    11ea <main+0xca>
xor    %eax,%eax
xor    %edx,%edx
lea    0xe62(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [37 x i8] c"Insira um n\C3\BAmero inteiro positivo: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [43 x i8] c"%d %d N\C3\BAmero inv\C3\A1lido! Tente outra vez: \00"
@.str.3 = [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
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 -1, i32* %2
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %3
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %19, %0
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
store i32 %9, i32* %6
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load i32, i32* %2
%13 = icmp sle i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %11, %8
%15 = load i32, i32* %3
%16 = icmp slt i32 %15, 10
br label %17
17: ; preds = %14, %11
%18 = phi i1 [ false, %11 ], [ %16, %14 ]
br i1 %18, label %19, label %25
19: ; preds = %17
%20 = load i32, i32* %2
%21 = load i32, i32* %6
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i32 %20, i32 %21)
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 1
store i32 %24, i32* %3
br label %8
25: ; preds = %17
br label %26
26: ; preds = %29, %25
%27 = load i32, i32* %2
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %38
29: ; preds = %26
%30 = load i32, i32* %4
%31 = add nsw i32 %30, 1
store i32 %31, i32* %4
%32 = load i32, i32* %2
%33 = srem i32 %32, 10
%34 = load i32, i32* %5
%35 = add nsw i32 %34, %33
store i32 %35, i32* %5
%36 = load i32, i32* %2
%37 = sdiv i32 %36, 10
store i32 %37, i32* %2
br label %26
38: ; preds = %26
%39 = load i32, i32* %4
%40 = load i32, i32* %5
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i32 %39, i32 %40)
ret i32 0
}

LLVM IR (-O2):
@.str = [37 x i8] c"Insira um n\C3\BAmero inteiro positivo: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [43 x i8] c"%d %d N\C3\BAmero inv\C3\A1lido! Tente outra vez: \00"
@.str.3 = [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 = bitcast i32* %1 to i8*
store i32 -1, i32* %1
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = icmp eq i32 %4, 0
%6 = load i32, i32* %1
%7 = icmp slt i32 %6, 1
%8 = select i1 %5, i1 true, i1 %7
br i1 %8, label %13, label %11
9: ; preds = %13
%10 = icmp sgt i32 %21, 0
br i1 %10, label %11, label %36
11: ; preds = %0, %9
%12 = phi i32 [ %21, %9 ], [ %6, %0 ]
br label %26
13: ; preds = %0, %13
%14 = phi i32 [ %21, %13 ], [ %6, %0 ]
%15 = phi i32 [ %19, %13 ], [ %4, %0 ]
%16 = phi i32 [ %18, %13 ], [ 0, %0 ]
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i32 %14, i32 %15)
%18 = add nuw nsw i32 %16, 1
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%20 = icmp eq i32 %19, 0
%21 = load i32, i32* %1
%22 = icmp slt i32 %21, 1
%23 = select i1 %20, i1 true, i1 %22
%24 = icmp ult i32 %16, 9
%25 = select i1 %23, i1 %24, i1 false
br i1 %25, label %13, label %9
26: ; preds = %11, %26
%27 = phi i32 [ %32, %26 ], [ 0, %11 ]
%28 = phi i32 [ %30, %26 ], [ 0, %11 ]
%29 = phi i32 [ %33, %26 ], [ %12, %11 ]
%30 = add nuw nsw i32 %28, 1
%31 = urem i32 %29, 10
%32 = add nuw nsw i32 %27, %31
%33 = udiv i32 %29, 10
%34 = icmp ult i32 %29, 10
br i1 %34, label %35, label %26
35: ; preds = %26
store i32 %33, i32* %1
br label %36
36: ; preds = %35, %9
%37 = phi i32 [ %30, %35 ], [ 0, %9 ]
%38 = phi i32 [ %32, %35 ], [ 0, %9 ]
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i32 %37, i32 %38)
ret i32 0
}