#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 /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int num;
  int dig;
  do {
    printf("请输入一个非负数");
    scanf("%d", &num);
    if (num < 0)
      ;
    puts("\a 不要输入负数");
  } while (num < 0);
  dig = 0;
  do {
    num = num / 10;
    dig = dig + 1;
  } while (num > 0);
  printf("号数的位为 %d . \n", dig);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xec5(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
jge    116c <main+0x3c>
jmp    116c <main+0x3c>
lea    0xea9(%rip),%rdi
call   1030 <puts@plt>
cmpl   $0x0,-0x8(%rbp)
jl     113f <main+0xf>
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
jg     1189 <main+0x59>
mov    -0xc(%rbp),%esi
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xec1(%rip),%r14
lea    0xed3(%rip),%r15
lea    0x4(%rsp),%r12
lea    0xeca(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <scanf@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    0x4(%rsp),%eax
test   %eax,%eax
js     1160 <main+0x30>
xor    %esi,%esi
nopw   0x0(%rax,%rax,1)
movslq %eax,%rcx
imul   $0x66666667,%rcx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rax
add    %edx,%eax
add    $0x1,%esi
cmp    $0x9,%ecx
jg     1190 <main+0x60>
mov    %eax,0x4(%rsp)
lea    0xe77(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [25 x i8] c"\E8\AF\B7\E8\BE\93\E5\85\A5\E4\B8\80\E4\B8\AA\E9\9D\9E\E8\B4\9F\E6\95\B0\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [21 x i8] c"\07 \E4\B8\8D\E8\A6\81\E8\BE\93\E5\85\A5\E8\B4\9F\E6\95\B0\00"
@.str.3 = [23 x i8] c"\E5\8F\B7\E6\95\B0\E7\9A\84\E4\BD\8D\E4\B8\BA %d . \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
br label %4
4: ; preds = %12, %0
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %4
br label %10
10: ; preds = %9, %4
%11 = call i32 @puts(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %12
12: ; preds = %10
%13 = load i32, i32* %2
%14 = icmp slt i32 %13, 0
br i1 %14, label %4, label %15
15: ; preds = %12
store i32 0, i32* %3
br label %16
16: ; preds = %21, %15
%17 = load i32, i32* %2
%18 = sdiv i32 %17, 10
store i32 %18, i32* %2
%19 = load i32, i32* %3
%20 = add nsw i32 %19, 1
store i32 %20, i32* %3
br label %21
21: ; preds = %16
%22 = load i32, i32* %2
%23 = icmp sgt i32 %22, 0
br i1 %23, label %16, label %24
24: ; preds = %21
%25 = load i32, i32* %3
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %25)
ret i32 0
}

LLVM IR (-O2):
@.str = [25 x i8] c"\E8\AF\B7\E8\BE\93\E5\85\A5\E4\B8\80\E4\B8\AA\E9\9D\9E\E8\B4\9F\E6\95\B0\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [21 x i8] c"\07 \E4\B8\8D\E8\A6\81\E8\BE\93\E5\85\A5\E8\B4\9F\E6\95\B0\00"
@.str.3 = [23 x i8] c"\E5\8F\B7\E6\95\B0\E7\9A\84\E4\BD\8D\E4\B8\BA %d . \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
br label %3
3: ; preds = %3, %0
%4 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 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 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%7 = load i32, i32* %1
%8 = icmp slt i32 %7, 0
br i1 %8, label %3, label %9
9: ; preds = %3, %9
%10 = phi i32 [ %12, %9 ], [ %7, %3 ]
%11 = phi i32 [ %13, %9 ], [ 0, %3 ]
%12 = sdiv i32 %10, 10
%13 = add nuw nsw i32 %11, 1
%14 = icmp sgt i32 %10, 9
br i1 %14, label %9, label %15
15: ; preds = %9
store i32 %12, i32* %1
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %13)
ret i32 0
}