#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*/ console_printchr(int);
int console_dignum(int i) {
  if (i < 10) {
    return 1;
  } else if (i < 100) {
    return 2;
  } else if (i < 1000) {
    return 3;
  } else {
    int c = 0;
    while (i > 0) {
      i = i / 10;
      c++;
    }
    console_printchr(c + 48);
    return c;
  }
}


x86 assembly (clang, -O0):
<console_dignum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0xa,-0x8(%rbp)
jge    1131 <console_dignum+0x21>
movl   $0x1,-0x4(%rbp)
jmp    119e <console_dignum+0x8e>
cmpl   $0x64,-0x8(%rbp)
jge    1147 <console_dignum+0x37>
movl   $0x2,-0x4(%rbp)
jmp    119e <console_dignum+0x8e>
cmpl   $0x3e8,-0x8(%rbp)
jge    1160 <console_dignum+0x50>
movl   $0x3,-0x4(%rbp)
jmp    119e <console_dignum+0x8e>
movl   $0x0,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    118d <console_dignum+0x7d>
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)
jmp    1167 <console_dignum+0x57>
mov    -0xc(%rbp),%edi
add    $0x30,%edi
call   1030 <console_printchr@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<console_dignum>:
push   %rbx
mov    $0x1,%ebx
cmp    $0xa,%edi
jl     115e <console_dignum+0x4e>
mov    $0x2,%ebx
cmp    $0x64,%edi
jb     115e <console_dignum+0x4e>
mov    $0x3,%ebx
cmp    $0x3e8,%edi
jb     115e <console_dignum+0x4e>
mov    $0x30,%ebx
mov    $0xcccccccd,%eax
nopl   0x0(%rax)
mov    %edi,%ecx
imul   %rax,%rcx
shr    $0x23,%rcx
add    $0x1,%ebx
cmp    $0x9,%edi
mov    %ecx,%edi
ja     1140 <console_dignum+0x30>
mov    %ebx,%edi
call   1030 <console_printchr@plt>
add    $0xffffffd0,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @console_dignum(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 10
br i1 %6, label %7, label %8
7: ; preds = %1
store i32 1, i32* %2
br label %30
8: ; preds = %1
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, 100
br i1 %10, label %11, label %12
11: ; preds = %8
store i32 2, i32* %2
br label %30
12: ; preds = %8
%13 = load i32, i32* %3
%14 = icmp slt i32 %13, 1000
br i1 %14, label %15, label %16
15: ; preds = %12
store i32 3, i32* %2
br label %30
16: ; preds = %12
store i32 0, i32* %4
br label %17
17: ; preds = %20, %16
%18 = load i32, i32* %3
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %17
%21 = load i32, i32* %3
%22 = sdiv i32 %21, 10
store i32 %22, i32* %3
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
br label %17
25: ; preds = %17
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 48
%28 = call i32 @console_printchr(i32 %27)
%29 = load i32, i32* %4
store i32 %29, i32* %2
br label %30
30: ; preds = %25, %15, %11, %7
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
define i32 @console_dignum(i32 %0) {
%2 = icmp slt i32 %0, 10
br i1 %2, label %16, label %3
3: ; preds = %1
%4 = icmp ult i32 %0, 100
br i1 %4, label %16, label %5
5: ; preds = %3
%6 = icmp ult i32 %0, 1000
br i1 %6, label %16, label %7
7: ; preds = %5, %7
%8 = phi i32 [ %11, %7 ], [ 0, %5 ]
%9 = phi i32 [ %10, %7 ], [ %0, %5 ]
%10 = udiv i32 %9, 10
%11 = add nuw nsw i32 %8, 1
%12 = icmp ult i32 %9, 10
br i1 %12, label %13, label %7
13: ; preds = %7
%14 = add nuw nsw i32 %8, 49
%15 = tail call i32 @console_printchr(i32 %14)
br label %16
16: ; preds = %5, %3, %1, %13
%17 = phi i32 [ %11, %13 ], [ 1, %1 ], [ 2, %3 ], [ 3, %5 ]
ret i32 %17
}