int IntLength(int x) {
  x = (x < 0) ? -x : x;
  if (x > 999999999)
    return 10;
  if (x > 99999999)
    return 9;
  if (x > 9999999)
    return 8;
  if (x > 999999)
    return 7;
  if (x > 99999)
    return 6;
  if (x > 9999)
    return 5;
  if (x > 999)
    return 4;
  if (x > 99)
    return 3;
  if (x > 9)
    return 2;
  return 1;
}


x86 assembly (clang, -O0):
<IntLength>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    111e <IntLength+0x1e>
xor    %eax,%eax
sub    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1124 <IntLength+0x24>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x3b9ac9ff,-0x8(%rbp)
jle    1143 <IntLength+0x43>
movl   $0xa,-0x4(%rbp)
jmp    120c <IntLength+0x10c>
cmpl   $0x5f5e0ff,-0x8(%rbp)
jle    115c <IntLength+0x5c>
movl   $0x9,-0x4(%rbp)
jmp    120c <IntLength+0x10c>
cmpl   $0x98967f,-0x8(%rbp)
jle    1175 <IntLength+0x75>
movl   $0x8,-0x4(%rbp)
jmp    120c <IntLength+0x10c>
cmpl   $0xf423f,-0x8(%rbp)
jle    118e <IntLength+0x8e>
movl   $0x7,-0x4(%rbp)
jmp    120c <IntLength+0x10c>
cmpl   $0x1869f,-0x8(%rbp)
jle    11a7 <IntLength+0xa7>
movl   $0x6,-0x4(%rbp)
jmp    120c <IntLength+0x10c>
cmpl   $0x270f,-0x8(%rbp)
jle    11c0 <IntLength+0xc0>
movl   $0x5,-0x4(%rbp)
jmp    120c <IntLength+0x10c>
cmpl   $0x3e7,-0x8(%rbp)
jle    11d9 <IntLength+0xd9>
movl   $0x4,-0x4(%rbp)
jmp    120c <IntLength+0x10c>
cmpl   $0x63,-0x8(%rbp)
jle    11ef <IntLength+0xef>
movl   $0x3,-0x4(%rbp)
jmp    120c <IntLength+0x10c>
cmpl   $0x9,-0x8(%rbp)
jle    1205 <IntLength+0x105>
movl   $0x2,-0x4(%rbp)
jmp    120c <IntLength+0x10c>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<IntLength>:
mov    %edi,%ecx
neg    %ecx
cmovs  %edi,%ecx
mov    $0xa,%eax
cmp    $0x3b9ac9ff,%ecx
ja     1177 <IntLength+0x77>
mov    $0x9,%eax
cmp    $0x5f5e0ff,%ecx
ja     1177 <IntLength+0x77>
mov    $0x8,%eax
cmp    $0x98967f,%ecx
ja     1177 <IntLength+0x77>
mov    $0x7,%eax
cmp    $0xf423f,%ecx
ja     1177 <IntLength+0x77>
mov    $0x6,%eax
cmp    $0x1869f,%ecx
ja     1177 <IntLength+0x77>
mov    $0x5,%eax
cmp    $0x270f,%ecx
ja     1177 <IntLength+0x77>
mov    $0x4,%eax
cmp    $0x3e7,%ecx
ja     1177 <IntLength+0x77>
mov    $0x3,%eax
cmp    $0x63,%ecx
ja     1177 <IntLength+0x77>
cmp    $0xa,%ecx
mov    $0x1,%eax
sbb    $0xffffffff,%eax
ret

LLVM IR (-O0):
define i32 @IntLength(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = load i32, i32* %3
%8 = sub nsw i32 0, %7
br label %11
9: ; preds = %1
%10 = load i32, i32* %3
br label %11
11: ; preds = %9, %6
%12 = phi i32 [ %8, %6 ], [ %10, %9 ]
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = icmp sgt i32 %13, 999999999
br i1 %14, label %15, label %16
15: ; preds = %11
store i32 10, i32* %2
br label %49
16: ; preds = %11
%17 = load i32, i32* %3
%18 = icmp sgt i32 %17, 99999999
br i1 %18, label %19, label %20
19: ; preds = %16
store i32 9, i32* %2
br label %49
20: ; preds = %16
%21 = load i32, i32* %3
%22 = icmp sgt i32 %21, 9999999
br i1 %22, label %23, label %24
23: ; preds = %20
store i32 8, i32* %2
br label %49
24: ; preds = %20
%25 = load i32, i32* %3
%26 = icmp sgt i32 %25, 999999
br i1 %26, label %27, label %28
27: ; preds = %24
store i32 7, i32* %2
br label %49
28: ; preds = %24
%29 = load i32, i32* %3
%30 = icmp sgt i32 %29, 99999
br i1 %30, label %31, label %32
31: ; preds = %28
store i32 6, i32* %2
br label %49
32: ; preds = %28
%33 = load i32, i32* %3
%34 = icmp sgt i32 %33, 9999
br i1 %34, label %35, label %36
35: ; preds = %32
store i32 5, i32* %2
br label %49
36: ; preds = %32
%37 = load i32, i32* %3
%38 = icmp sgt i32 %37, 999
br i1 %38, label %39, label %40
39: ; preds = %36
store i32 4, i32* %2
br label %49
40: ; preds = %36
%41 = load i32, i32* %3
%42 = icmp sgt i32 %41, 99
br i1 %42, label %43, label %44
43: ; preds = %40
store i32 3, i32* %2
br label %49
44: ; preds = %40
%45 = load i32, i32* %3
%46 = icmp sgt i32 %45, 9
br i1 %46, label %47, label %48
47: ; preds = %44
store i32 2, i32* %2
br label %49
48: ; preds = %44
store i32 1, i32* %2
br label %49
49: ; preds = %48, %47, %43, %39, %35, %31, %27, %23, %19, %15
%50 = load i32, i32* %2
ret i32 %50
}

LLVM IR (-O2):
define i32 @IntLength(i32 %0) {
%2 = tail call i32 @llvm.abs.i32(i32 %0, i1 true)
%3 = icmp ugt i32 %2, 999999999
br i1 %3, label %21, label %4
4: ; preds = %1
%5 = icmp ugt i32 %2, 99999999
br i1 %5, label %21, label %6
6: ; preds = %4
%7 = icmp ugt i32 %2, 9999999
br i1 %7, label %21, label %8
8: ; preds = %6
%9 = icmp ugt i32 %2, 999999
br i1 %9, label %21, label %10
10: ; preds = %8
%11 = icmp ugt i32 %2, 99999
br i1 %11, label %21, label %12
12: ; preds = %10
%13 = icmp ugt i32 %2, 9999
br i1 %13, label %21, label %14
14: ; preds = %12
%15 = icmp ugt i32 %2, 999
br i1 %15, label %21, label %16
16: ; preds = %14
%17 = icmp ugt i32 %2, 99
br i1 %17, label %21, label %18
18: ; preds = %16
%19 = icmp ugt i32 %2, 9
%20 = select i1 %19, i32 2, i32 1
br label %21
21: ; preds = %18, %16, %14, %12, %10, %8, %6, %4, %1
%22 = phi i32 [ 10, %1 ], [ 9, %4 ], [ 8, %6 ], [ 7, %8 ], [ 6, %10 ], [ 5, %12 ], [ 4, %14 ], [ 3, %16 ], [ %20, %18 ]
ret i32 %22
}