#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*/ fatal_error(char *);
long num_digits(long n) {
  if (n < 0) {
    fatal_error("Invalid size.");
  } else if (n < 10) {
    return 1;
  } else if (n < 100) {
    return 2;
  } else if (n < 1000) {
    return 3;
  } else if (n < 10000) {
    return 4;
  } else {
    fatal_error("Size too big.");
  }
}


x86 assembly (clang, -O0):
<num_digits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    1138 <num_digits+0x28>
lea    0xed2(%rip),%rdi
call   1030 <fatal_error@plt>
jmp    11be <num_digits+0xae>
cmpq   $0xa,-0x10(%rbp)
jge    1150 <num_digits+0x40>
movq   $0x1,-0x8(%rbp)
jmp    11be <num_digits+0xae>
cmpq   $0x64,-0x10(%rbp)
jge    1168 <num_digits+0x58>
movq   $0x2,-0x8(%rbp)
jmp    11be <num_digits+0xae>
cmpq   $0x3e8,-0x10(%rbp)
jge    1183 <num_digits+0x73>
movq   $0x3,-0x8(%rbp)
jmp    11be <num_digits+0xae>
cmpq   $0x2710,-0x10(%rbp)
jge    119e <num_digits+0x8e>
movq   $0x4,-0x8(%rbp)
jmp    11be <num_digits+0xae>
lea    0xe69(%rip),%rdi
call   1030 <fatal_error@plt>
jmp    11af <num_digits+0x9f>
jmp    11b4 <num_digits+0xa4>
jmp    11b9 <num_digits+0xa9>
jmp    11be <num_digits+0xae>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<num_digits>:
test   %rdi,%rdi
js     1150 <num_digits+0x40>
mov    $0x1,%eax
cmp    $0xa,%rdi
jb     1161 <num_digits+0x51>
mov    $0x2,%eax
cmp    $0x64,%rdi
jb     1161 <num_digits+0x51>
mov    $0x3,%eax
cmp    $0x3e8,%rdi
jb     1161 <num_digits+0x51>
mov    $0x4,%eax
cmp    $0x2710,%rdi
jb     1161 <num_digits+0x51>
lea    0xec0(%rip),%rdi
jmp    1157 <num_digits+0x47>
lea    0xea9(%rip),%rdi
push   %rax
call   1030 <fatal_error@plt>
add    $0x8,%rsp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"Invalid size.\00"
@.str.1 = [14 x i8] c"Size too big.\00"
define i64 @num_digits(i64 %0) {
%2 = alloca i64
%3 = alloca i64
store i64 %0, i64* %3
%4 = load i64, i64* %3
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = call i32 @fatal_error(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %30
8: ; preds = %1
%9 = load i64, i64* %3
%10 = icmp slt i64 %9, 10
br i1 %10, label %11, label %12
11: ; preds = %8
store i64 1, i64* %2
br label %30
12: ; preds = %8
%13 = load i64, i64* %3
%14 = icmp slt i64 %13, 100
br i1 %14, label %15, label %16
15: ; preds = %12
store i64 2, i64* %2
br label %30
16: ; preds = %12
%17 = load i64, i64* %3
%18 = icmp slt i64 %17, 1000
br i1 %18, label %19, label %20
19: ; preds = %16
store i64 3, i64* %2
br label %30
20: ; preds = %16
%21 = load i64, i64* %3
%22 = icmp slt i64 %21, 10000
br i1 %22, label %23, label %24
23: ; preds = %20
store i64 4, i64* %2
br label %30
24: ; preds = %20
%25 = call i32 @fatal_error(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %24
br label %27
27: ; preds = %26
br label %28
28: ; preds = %27
br label %29
29: ; preds = %28
br label %30
30: ; preds = %11, %15, %19, %23, %29, %6
%31 = load i64, i64* %2
ret i64 %31
}

LLVM IR (-O2):
@.str = [14 x i8] c"Invalid size.\00"
@.str.1 = [14 x i8] c"Size too big.\00"
define i64 @num_digits(i64 %0) {
%2 = icmp slt i64 %0, 0
br i1 %2, label %11, label %3
3: ; preds = %1
%4 = icmp ult i64 %0, 10
br i1 %4, label %14, label %5
5: ; preds = %3
%6 = icmp ult i64 %0, 100
br i1 %6, label %14, label %7
7: ; preds = %5
%8 = icmp ult i64 %0, 1000
br i1 %8, label %14, label %9
9: ; preds = %7
%10 = icmp ult i64 %0, 10000
br i1 %10, label %14, label %11
11: ; preds = %9, %1
%12 = phi i8* [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), %9 ]
%13 = tail call i32 @fatal_error(i8* %12)
br label %14
14: ; preds = %11, %9, %7, %5, %3
%15 = phi i64 [ 1, %3 ], [ 2, %5 ], [ 3, %7 ], [ 4, %9 ], [ undef, %11 ]
ret i64 %15
}