#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 */
unsigned long abs(unsigned long);
int uintlen(unsigned long n) {
  n = abs(n);
  if (n < 10)
    return 1;
  if (n < 100)
    return 2;
  if (n < 1000)
    return 3;
  if (n < 10000)
    return 4;
  if (n < 100000)
    return 5;
  if (n < 1000000)
    return 6;
  if (n < 10000000)
    return 7;
  if (n < 100000000)
    return 8;
  if (n < 1000000000)
    return 9;
  return 10;
}


x86 assembly (clang, -O0):
<uintlen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <abs@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0xa,-0x10(%rbp)
jae    1140 <uintlen+0x30>
movl   $0x1,-0x4(%rbp)
jmp    1214 <uintlen+0x104>
cmpq   $0x64,-0x10(%rbp)
jae    1157 <uintlen+0x47>
movl   $0x2,-0x4(%rbp)
jmp    1214 <uintlen+0x104>
cmpq   $0x3e8,-0x10(%rbp)
jae    1171 <uintlen+0x61>
movl   $0x3,-0x4(%rbp)
jmp    1214 <uintlen+0x104>
cmpq   $0x2710,-0x10(%rbp)
jae    118b <uintlen+0x7b>
movl   $0x4,-0x4(%rbp)
jmp    1214 <uintlen+0x104>
cmpq   $0x186a0,-0x10(%rbp)
jae    11a5 <uintlen+0x95>
movl   $0x5,-0x4(%rbp)
jmp    1214 <uintlen+0x104>
cmpq   $0xf4240,-0x10(%rbp)
jae    11bf <uintlen+0xaf>
movl   $0x6,-0x4(%rbp)
jmp    1214 <uintlen+0x104>
cmpq   $0x989680,-0x10(%rbp)
jae    11d9 <uintlen+0xc9>
movl   $0x7,-0x4(%rbp)
jmp    1214 <uintlen+0x104>
cmpq   $0x5f5e100,-0x10(%rbp)
05
jae    11f3 <uintlen+0xe3>
movl   $0x8,-0x4(%rbp)
jmp    1214 <uintlen+0x104>
cmpq   $0x3b9aca00,-0x10(%rbp)
3b
jae    120d <uintlen+0xfd>
movl   $0x9,-0x4(%rbp)
jmp    1214 <uintlen+0x104>
movl   $0xa,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uintlen>:
mov    %rdi,%rcx
neg    %rcx
cmovs  %rdi,%rcx
mov    $0x1,%eax
cmp    $0xa,%rcx
jb     1183 <uintlen+0x83>
mov    $0x2,%eax
cmp    $0x64,%rcx
jb     1183 <uintlen+0x83>
mov    $0x3,%eax
cmp    $0x3e8,%rcx
jb     1183 <uintlen+0x83>
mov    $0x4,%eax
cmp    $0x2710,%rcx
jb     1183 <uintlen+0x83>
mov    $0x5,%eax
cmp    $0x186a0,%rcx
jb     1183 <uintlen+0x83>
mov    $0x6,%eax
cmp    $0xf4240,%rcx
jb     1183 <uintlen+0x83>
mov    $0x7,%eax
cmp    $0x989680,%rcx
jb     1183 <uintlen+0x83>
mov    $0x8,%eax
cmp    $0x5f5e100,%rcx
jb     1183 <uintlen+0x83>
cmp    $0x3b9aca00,%rcx
mov    $0xa,%eax
sbb    $0x0,%eax
ret

LLVM IR (-O0):
define i32 @uintlen(i64 %0) {
%2 = alloca i32
%3 = alloca i64
store i64 %0, i64* %3
%4 = load i64, i64* %3
%5 = call i64 @abs(i64 %4)
store i64 %5, i64* %3
%6 = load i64, i64* %3
%7 = icmp ult i64 %6, 10
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 1, i32* %2
br label %42
9: ; preds = %1
%10 = load i64, i64* %3
%11 = icmp ult i64 %10, 100
br i1 %11, label %12, label %13
12: ; preds = %9
store i32 2, i32* %2
br label %42
13: ; preds = %9
%14 = load i64, i64* %3
%15 = icmp ult i64 %14, 1000
br i1 %15, label %16, label %17
16: ; preds = %13
store i32 3, i32* %2
br label %42
17: ; preds = %13
%18 = load i64, i64* %3
%19 = icmp ult i64 %18, 10000
br i1 %19, label %20, label %21
20: ; preds = %17
store i32 4, i32* %2
br label %42
21: ; preds = %17
%22 = load i64, i64* %3
%23 = icmp ult i64 %22, 100000
br i1 %23, label %24, label %25
24: ; preds = %21
store i32 5, i32* %2
br label %42
25: ; preds = %21
%26 = load i64, i64* %3
%27 = icmp ult i64 %26, 1000000
br i1 %27, label %28, label %29
28: ; preds = %25
store i32 6, i32* %2
br label %42
29: ; preds = %25
%30 = load i64, i64* %3
%31 = icmp ult i64 %30, 10000000
br i1 %31, label %32, label %33
32: ; preds = %29
store i32 7, i32* %2
br label %42
33: ; preds = %29
%34 = load i64, i64* %3
%35 = icmp ult i64 %34, 100000000
br i1 %35, label %36, label %37
36: ; preds = %33
store i32 8, i32* %2
br label %42
37: ; preds = %33
%38 = load i64, i64* %3
%39 = icmp ult i64 %38, 1000000000
br i1 %39, label %40, label %41
40: ; preds = %37
store i32 9, i32* %2
br label %42
41: ; preds = %37
store i32 10, i32* %2
br label %42
42: ; preds = %41, %40, %36, %32, %28, %24, %20, %16, %12, %8
%43 = load i32, i32* %2
ret i32 %43
}

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