#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 n_dig(int);
int p_dig(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int n, num, primeiro;
  do {
    printf("entre com um inteiro positivo (negativo para sair): ");
    scanf("%d", &num);
    if (num >= 0) {
      n = n_dig(num);
      primeiro = p_dig(num);
      printf("\n%d tem %d digitos e o primeiro é %d\n", num, n, primeiro);
    }
  } while (num >= 0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed1(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1060 <scanf@plt>
cmpl   $0x0,-0xc(%rbp)
jl     11a4 <main+0x64>
mov    -0xc(%rbp),%edi
call   1050 <n_dig@plt>
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <p_dig@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11a9 <main+0x69>
cmpl   $0x0,-0xc(%rbp)
jge    114f <main+0xf>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xead(%rip),%r14
lea    0xedb(%rip),%r15
lea    0xc(%rsp),%rbx
lea    0xed2(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
mov    0xc(%rsp),%edi
test   %edi,%edi
js     11b6 <main+0x76>
call   1050 <n_dig@plt>
mov    %eax,%ebp
mov    0xc(%rsp),%edi
call   1040 <p_dig@plt>
mov    0xc(%rsp),%esi
mov    %r12,%rdi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
cmpl   $0x0,0xc(%rsp)
jns    1170 <main+0x30>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [53 x i8] c"entre com um inteiro positivo (negativo para sair): \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [39 x i8] c"\0A%d tem %d digitos e o primeiro \C3\A9 %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
br label %5
5: ; preds = %20, %0
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%8 = load i32, i32* %3
%9 = icmp sge i32 %8, 0
br i1 %9, label %10, label %19
10: ; preds = %5
%11 = load i32, i32* %3
%12 = call i32 @n_dig(i32 %11)
store i32 %12, i32* %2
%13 = load i32, i32* %3
%14 = call i32 @p_dig(i32 %13)
store i32 %14, i32* %4
%15 = load i32, i32* %3
%16 = load i32, i32* %2
%17 = load i32, i32* %4
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i32 %15, i32 %16, i32 %17)
br label %19
19: ; preds = %10, %5
br label %20
20: ; preds = %19
%21 = load i32, i32* %3
%22 = icmp sge i32 %21, 0
br i1 %22, label %5, label %23
23: ; preds = %20
ret i32 0
}

LLVM IR (-O2):
@.str = [53 x i8] c"entre com um inteiro positivo (negativo para sair): \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [39 x i8] c"\0A%d tem %d digitos e o primeiro \C3\A9 %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
br label %3
3: ; preds = %8, %0
%4 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
%7 = icmp sgt i32 %6, -1
br i1 %7, label %8, label %16
8: ; preds = %3
%9 = call i32 @n_dig(i32 %6)
%10 = load i32, i32* %1
%11 = call i32 @p_dig(i32 %10)
%12 = load i32, i32* %1
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i32 %12, i32 %9, i32 %11)
%14 = load i32, i32* %1
%15 = icmp sgt i32 %14, -1
br i1 %15, label %3, label %16
16: ; preds = %3, %8
ret i32 0
}