#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 ssize_t;

/* Variables and functions */
int digits(ssize_t n) {
  if (n < 100000) {
    if (n < 1000) {
      if (n < 100)
        return 2;
      else
        return 3;
    } else {
      if (n < 10000)
        return 4;
      else
        return 5;
    }
  } else {
    if (n < 10000000) {
      if (n < 1000000)
        return 6;
      else
        return 7;
    } else {
      if (n < 100000000)
        return 8;
      else
        return 9;
    }
  }
}


x86 assembly (clang, -O0):
<digits>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
cmpl   $0x186a0,-0x8(%rbp)
jge    1168 <digits+0x68>
cmpl   $0x3e8,-0x8(%rbp)
jge    1143 <digits+0x43>
cmpl   $0x64,-0x8(%rbp)
jge    1137 <digits+0x37>
movl   $0x2,-0x4(%rbp)
jmp    11ba <digits+0xba>
movl   $0x3,-0x4(%rbp)
jmp    11ba <digits+0xba>
cmpl   $0x2710,-0x8(%rbp)
jge    115c <digits+0x5c>
movl   $0x4,-0x4(%rbp)
jmp    11ba <digits+0xba>
movl   $0x5,-0x4(%rbp)
jmp    11ba <digits+0xba>
cmpl   $0x989680,-0x8(%rbp)
jge    119a <digits+0x9a>
cmpl   $0xf4240,-0x8(%rbp)
jge    118e <digits+0x8e>
movl   $0x6,-0x4(%rbp)
jmp    11ba <digits+0xba>
movl   $0x7,-0x4(%rbp)
jmp    11ba <digits+0xba>
cmpl   $0x5f5e100,-0x8(%rbp)
jge    11b3 <digits+0xb3>
movl   $0x8,-0x4(%rbp)
jmp    11ba <digits+0xba>
movl   $0x9,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<digits>:
cmp    $0x1869f,%edi
jg     111c <digits+0x1c>
cmp    $0x3e7,%edi
jg     1133 <digits+0x33>
xor    %eax,%eax
cmp    $0x64,%edi
setl   %al
xor    $0x3,%eax
ret
cmp    $0x98967f,%edi
ja     1142 <digits+0x42>
cmp    $0xf4240,%edi
mov    $0x7,%eax
sbb    $0x0,%eax
ret
cmp    $0x2710,%edi
mov    $0x5,%eax
sbb    $0x0,%eax
ret
cmp    $0x5f5e100,%edi
mov    $0x9,%eax
sbb    $0x0,%eax
ret

LLVM IR (-O0):
define i32 @digits(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp slt i32 %4, 100000
br i1 %5, label %6, label %19
6: ; preds = %1
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 1000
br i1 %8, label %9, label %14
9: ; preds = %6
%10 = load i32, i32* %3
%11 = icmp slt i32 %10, 100
br i1 %11, label %12, label %13
12: ; preds = %9
store i32 2, i32* %2
br label %32
13: ; preds = %9
store i32 3, i32* %2
br label %32
14: ; preds = %6
%15 = load i32, i32* %3
%16 = icmp slt i32 %15, 10000
br i1 %16, label %17, label %18
17: ; preds = %14
store i32 4, i32* %2
br label %32
18: ; preds = %14
store i32 5, i32* %2
br label %32
19: ; preds = %1
%20 = load i32, i32* %3
%21 = icmp slt i32 %20, 10000000
br i1 %21, label %22, label %27
22: ; preds = %19
%23 = load i32, i32* %3
%24 = icmp slt i32 %23, 1000000
br i1 %24, label %25, label %26
25: ; preds = %22
store i32 6, i32* %2
br label %32
26: ; preds = %22
store i32 7, i32* %2
br label %32
27: ; preds = %19
%28 = load i32, i32* %3
%29 = icmp slt i32 %28, 100000000
br i1 %29, label %30, label %31
30: ; preds = %27
store i32 8, i32* %2
br label %32
31: ; preds = %27
store i32 9, i32* %2
br label %32
32: ; preds = %31, %30, %26, %25, %18, %17, %13, %12
%33 = load i32, i32* %2
ret i32 %33
}

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