#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 */
typedef int uint64_t;
typedef int uint32_t;

/* Variables and functions */
uint32_t digits10(uint64_t v) {
  if (v < 10)
    return 1;
  if (v < 100)
    return 2;
  if (v < 1000)
    return 3;
  if (v < 1000000000000UL) {
    if (v < 100000000UL) {
      if (v < 1000000) {
        if (v < 10000)
          return 4;
        return 5 + (v >= 100000);
      }
      return 7 + (v >= 10000000UL);
    }
    if (v < 10000000000UL) {
      return 9 + (v >= 1000000000UL);
    }
    return 11 + (v >= 100000000000UL);
  }
  return 12 + digits10(v / 1000000000000UL);
}


x86 assembly (clang, -O0):
<digits10>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0xa,-0x8(%rbp)
jge    1131 <digits10+0x21>
movl   $0x1,-0x4(%rbp)
jmp    125c <digits10+0x14c>
cmpl   $0x64,-0x8(%rbp)
jge    1147 <digits10+0x37>
movl   $0x2,-0x4(%rbp)
jmp    125c <digits10+0x14c>
cmpl   $0x3e8,-0x8(%rbp)
jge    1160 <digits10+0x50>
movl   $0x3,-0x4(%rbp)
jmp    125c <digits10+0x14c>
movslq -0x8(%rbp),%rax
movabs $0xe8d4a51000,%rcx
cmp    %rcx,%rax
jae    123c <digits10+0x12c>
movslq -0x8(%rbp),%rax
cmp    $0x5f5e100,%rax
jae    11e4 <digits10+0xd4>
cmpl   $0xf4240,-0x8(%rbp)
jge    11c7 <digits10+0xb7>
cmpl   $0x2710,-0x8(%rbp)
jge    11ad <digits10+0x9d>
movl   $0x4,-0x4(%rbp)
jmp    125c <digits10+0x14c>
cmpl   $0x186a0,-0x8(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%eax
add    $0x5,%eax
mov    %eax,-0x4(%rbp)
jmp    125c <digits10+0x14c>
movslq -0x8(%rbp),%rax
cmp    $0x989680,%rax
setae  %al
and    $0x1,%al
movzbl %al,%eax
add    $0x7,%eax
mov    %eax,-0x4(%rbp)
jmp    125c <digits10+0x14c>
movslq -0x8(%rbp),%rax
movabs $0x2540be400,%rcx
cmp    %rcx,%rax
jae    1218 <digits10+0x108>
movslq -0x8(%rbp),%rax
cmp    $0x3b9aca00,%rax
setae  %al
and    $0x1,%al
movzbl %al,%eax
add    $0x9,%eax
mov    %eax,-0x4(%rbp)
jmp    125c <digits10+0x14c>
movslq -0x8(%rbp),%rax
movabs $0x174876e800,%rcx
cmp    %rcx,%rax
setae  %al
and    $0x1,%al
movzbl %al,%eax
add    $0xb,%eax
mov    %eax,-0x4(%rbp)
jmp    125c <digits10+0x14c>
movslq -0x8(%rbp),%rax
movabs $0xe8d4a51000,%rcx
xor    %edx,%edx
div    %rcx
mov    %eax,%edi
call   1030 <digits10@plt>
add    $0xc,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<digits10>:
mov    $0x1,%eax
cmp    $0xa,%edi
jl     1166 <digits10+0x66>
mov    $0x2,%eax
cmp    $0x64,%edi
jb     1166 <digits10+0x66>
mov    $0x3,%eax
cmp    $0x3e8,%edi
jb     1166 <digits10+0x66>
cmp    $0x5f5e0ff,%edi
ja     114b <digits10+0x4b>
cmp    $0xf423f,%edi
ja     1158 <digits10+0x58>
mov    $0x4,%eax
cmp    $0x2710,%edi
jb     1166 <digits10+0x66>
cmp    $0x186a0,%edi
mov    $0x5,%eax
jmp    1163 <digits10+0x63>
cmp    $0x3b9aca00,%edi
mov    $0x9,%eax
jmp    1163 <digits10+0x63>
cmp    $0x989680,%edi
mov    $0x7,%eax
sbb    $0xffffffff,%eax
ret

LLVM IR (-O0):
define i32 @digits10(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp slt i32 %4, 10
br i1 %5, label %6, label %7
6: ; preds = %1
store i32 1, i32* %2
br label %64
7: ; preds = %1
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 100
br i1 %9, label %10, label %11
10: ; preds = %7
store i32 2, i32* %2
br label %64
11: ; preds = %7
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 1000
br i1 %13, label %14, label %15
14: ; preds = %11
store i32 3, i32* %2
br label %64
15: ; preds = %11
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = icmp ult i64 %17, 1000000000000
br i1 %18, label %19, label %57
19: ; preds = %15
%20 = load i32, i32* %3
%21 = sext i32 %20 to i64
%22 = icmp ult i64 %21, 100000000
br i1 %22, label %23, label %41
23: ; preds = %19
%24 = load i32, i32* %3
%25 = icmp slt i32 %24, 1000000
br i1 %25, label %26, label %35
26: ; preds = %23
%27 = load i32, i32* %3
%28 = icmp slt i32 %27, 10000
br i1 %28, label %29, label %30
29: ; preds = %26
store i32 4, i32* %2
br label %64
30: ; preds = %26
%31 = load i32, i32* %3
%32 = icmp sge i32 %31, 100000
%33 = zext i1 %32 to i32
%34 = add nsw i32 5, %33
store i32 %34, i32* %2
br label %64
35: ; preds = %23
%36 = load i32, i32* %3
%37 = sext i32 %36 to i64
%38 = icmp uge i64 %37, 10000000
%39 = zext i1 %38 to i32
%40 = add nsw i32 7, %39
store i32 %40, i32* %2
br label %64
41: ; preds = %19
%42 = load i32, i32* %3
%43 = sext i32 %42 to i64
%44 = icmp ult i64 %43, 10000000000
br i1 %44, label %45, label %51
45: ; preds = %41
%46 = load i32, i32* %3
%47 = sext i32 %46 to i64
%48 = icmp uge i64 %47, 1000000000
%49 = zext i1 %48 to i32
%50 = add nsw i32 9, %49
store i32 %50, i32* %2
br label %64
51: ; preds = %41
%52 = load i32, i32* %3
%53 = sext i32 %52 to i64
%54 = icmp uge i64 %53, 100000000000
%55 = zext i1 %54 to i32
%56 = add nsw i32 11, %55
store i32 %56, i32* %2
br label %64
57: ; preds = %15
%58 = load i32, i32* %3
%59 = sext i32 %58 to i64
%60 = udiv i64 %59, 1000000000000
%61 = trunc i64 %60 to i32
%62 = call i32 @digits10(i32 %61)
%63 = add nsw i32 12, %62
store i32 %63, i32* %2
br label %64
64: ; preds = %57, %51, %45, %35, %30, %29, %14, %10, %6
%65 = load i32, i32* %2
ret i32 %65
}

LLVM IR (-O2):
define i32 @digits10(i32 %0) {
%2 = icmp slt i32 %0, 10
br i1 %2, label %22, label %3
3: ; preds = %1
%4 = icmp ult i32 %0, 100
br i1 %4, label %22, label %5
5: ; preds = %3
%6 = icmp ult i32 %0, 1000
br i1 %6, label %22, label %7
7: ; preds = %5
%8 = icmp ult i32 %0, 100000000
br i1 %8, label %9, label %19
9: ; preds = %7
%10 = icmp ult i32 %0, 1000000
br i1 %10, label %11, label %16
11: ; preds = %9
%12 = icmp ult i32 %0, 10000
br i1 %12, label %22, label %13
13: ; preds = %11
%14 = icmp ugt i32 %0, 99999
%15 = select i1 %14, i32 6, i32 5
br label %22
16: ; preds = %9
%17 = icmp ugt i32 %0, 9999999
%18 = select i1 %17, i32 8, i32 7
br label %22
19: ; preds = %7
%20 = icmp ugt i32 %0, 999999999
%21 = select i1 %20, i32 10, i32 9
br label %22
22: ; preds = %11, %5, %3, %1, %19, %16, %13
%23 = phi i32 [ %15, %13 ], [ %18, %16 ], [ %21, %19 ], [ 1, %1 ], [ 2, %3 ], [ 3, %5 ], [ 4, %11 ]
ret i32 %23
}