#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*/ printf(char *, ...);
int /*<<< orphan*/ usagex();
int count_digits(int val) {
  int ndigits;
  if (val < 0) {
    printf("Error: code 0 or negative\n");
    ndigits = 0;
  } else if (val < 1)
    ndigits = 0;
  else if (val < 10)
    ndigits = 1;
  else if (val < 100)
    ndigits = 2;
  else if (val < 1000)
    ndigits = 3;
  else if (val < 10000)
    ndigits = 4;
  else if (val < 100000)
    ndigits = 5;
  else if (val < 1000000)
    ndigits = 6;
  else if (val < 10000000)
    ndigits = 7;
  else if (val < 100000000)
    ndigits = 8;
  else
    ndigits = 9;
  if (ndigits > 8) {
    printf("ERROR: %d has more than 8 digits (it has %d digits)\n", val,
           ndigits);
    usagex();
  }
  return ndigits;
}


x86 assembly (clang, -O0):
<count_digits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    114f <count_digits+0x2f>
lea    0xec4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x8(%rbp)
jmp    125b <count_digits+0x13b>
cmpl   $0x1,-0x4(%rbp)
jge    1165 <count_digits+0x45>
movl   $0x0,-0x8(%rbp)
jmp    1256 <count_digits+0x136>
cmpl   $0xa,-0x4(%rbp)
jge    117b <count_digits+0x5b>
movl   $0x1,-0x8(%rbp)
jmp    1251 <count_digits+0x131>
cmpl   $0x64,-0x4(%rbp)
jge    1191 <count_digits+0x71>
movl   $0x2,-0x8(%rbp)
jmp    124c <count_digits+0x12c>
cmpl   $0x3e8,-0x4(%rbp)
jge    11aa <count_digits+0x8a>
movl   $0x3,-0x8(%rbp)
jmp    1247 <count_digits+0x127>
cmpl   $0x2710,-0x4(%rbp)
jge    11c3 <count_digits+0xa3>
movl   $0x4,-0x8(%rbp)
jmp    1242 <count_digits+0x122>
cmpl   $0x186a0,-0x4(%rbp)
jge    11dc <count_digits+0xbc>
movl   $0x5,-0x8(%rbp)
jmp    123d <count_digits+0x11d>
cmpl   $0xf4240,-0x4(%rbp)
jge    11f5 <count_digits+0xd5>
movl   $0x6,-0x8(%rbp)
jmp    1238 <count_digits+0x118>
cmpl   $0x989680,-0x4(%rbp)
jge    120e <count_digits+0xee>
movl   $0x7,-0x8(%rbp)
jmp    1233 <count_digits+0x113>
cmpl   $0x5f5e100,-0x4(%rbp)
jge    1227 <count_digits+0x107>
movl   $0x8,-0x8(%rbp)
jmp    122e <count_digits+0x10e>
movl   $0x9,-0x8(%rbp)
jmp    1233 <count_digits+0x113>
jmp    1238 <count_digits+0x118>
jmp    123d <count_digits+0x11d>
jmp    1242 <count_digits+0x122>
jmp    1247 <count_digits+0x127>
jmp    124c <count_digits+0x12c>
jmp    1251 <count_digits+0x131>
jmp    1256 <count_digits+0x136>
jmp    125b <count_digits+0x13b>
cmpl   $0x8,-0x8(%rbp)
jle    1280 <count_digits+0x160>
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xda9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <usagex@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_digits>:
push   %rbx
test   %edi,%edi
js     11c8 <count_digits+0x98>
je     11d4 <count_digits+0xa4>
mov    %edi,%esi
mov    $0x1,%ebx
cmp    $0xa,%edi
jb     11d6 <count_digits+0xa6>
mov    $0x2,%ebx
cmp    $0x64,%esi
jb     11d6 <count_digits+0xa6>
mov    $0x3,%ebx
cmp    $0x3e8,%esi
jb     11d6 <count_digits+0xa6>
mov    $0x4,%ebx
cmp    $0x2710,%esi
jb     11d6 <count_digits+0xa6>
mov    $0x5,%ebx
cmp    $0x186a0,%esi
jb     11d6 <count_digits+0xa6>
mov    $0x6,%ebx
cmp    $0xf4240,%esi
jb     11d6 <count_digits+0xa6>
mov    $0x7,%ebx
cmp    $0x989680,%esi
jb     11d6 <count_digits+0xa6>
mov    $0x8,%ebx
cmp    $0x5f5e100,%esi
jb     11d6 <count_digits+0xa6>
lea    0xe52(%rip),%rdi
mov    $0x9,%ebx
mov    $0x9,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <usagex@plt>
jmp    11d6 <count_digits+0xa6>
lea    0xe66(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Error: code 0 or negative\0A\00"
@.str.1 = [53 x i8] c"ERROR: %d has more than 8 digits (it has %d digits)\0A\00"
define i32 @count_digits(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %54
8: ; preds = %1
%9 = load i32, i32* %2
%10 = icmp slt i32 %9, 1
br i1 %10, label %11, label %12
11: ; preds = %8
store i32 0, i32* %3
br label %53
12: ; preds = %8
%13 = load i32, i32* %2
%14 = icmp slt i32 %13, 10
br i1 %14, label %15, label %16
15: ; preds = %12
store i32 1, i32* %3
br label %52
16: ; preds = %12
%17 = load i32, i32* %2
%18 = icmp slt i32 %17, 100
br i1 %18, label %19, label %20
19: ; preds = %16
store i32 2, i32* %3
br label %51
20: ; preds = %16
%21 = load i32, i32* %2
%22 = icmp slt i32 %21, 1000
br i1 %22, label %23, label %24
23: ; preds = %20
store i32 3, i32* %3
br label %50
24: ; preds = %20
%25 = load i32, i32* %2
%26 = icmp slt i32 %25, 10000
br i1 %26, label %27, label %28
27: ; preds = %24
store i32 4, i32* %3
br label %49
28: ; preds = %24
%29 = load i32, i32* %2
%30 = icmp slt i32 %29, 100000
br i1 %30, label %31, label %32
31: ; preds = %28
store i32 5, i32* %3
br label %48
32: ; preds = %28
%33 = load i32, i32* %2
%34 = icmp slt i32 %33, 1000000
br i1 %34, label %35, label %36
35: ; preds = %32
store i32 6, i32* %3
br label %47
36: ; preds = %32
%37 = load i32, i32* %2
%38 = icmp slt i32 %37, 10000000
br i1 %38, label %39, label %40
39: ; preds = %36
store i32 7, i32* %3
br label %46
40: ; preds = %36
%41 = load i32, i32* %2
%42 = icmp slt i32 %41, 100000000
br i1 %42, label %43, label %44
43: ; preds = %40
store i32 8, i32* %3
br label %45
44: ; preds = %40
store i32 9, i32* %3
br label %45
45: ; preds = %44, %43
br label %46
46: ; preds = %45, %39
br label %47
47: ; preds = %46, %35
br label %48
48: ; preds = %47, %31
br label %49
49: ; preds = %48, %27
br label %50
50: ; preds = %49, %23
br label %51
51: ; preds = %50, %19
br label %52
52: ; preds = %51, %15
br label %53
53: ; preds = %52, %11
br label %54
54: ; preds = %53, %6
%55 = load i32, i32* %3
%56 = icmp sgt i32 %55, 8
br i1 %56, label %57, label %62
57: ; preds = %54
%58 = load i32, i32* %2
%59 = load i32, i32* %3
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i32 %58, i32 %59)
%61 = call i32 (...) @usagex()
br label %62
62: ; preds = %57, %54
%63 = load i32, i32* %3
ret i32 %63
}

LLVM IR (-O2):
@.str.1 = [53 x i8] c"ERROR: %d has more than 8 digits (it has %d digits)\0A\00"
@str = [26 x i8] c"Error: code 0 or negative\00"
define i32 @count_digits(i32 %0) {
%2 = icmp slt i32 %0, 0
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %26
5: ; preds = %1
%6 = icmp eq i32 %0, 0
br i1 %6, label %26, label %7
7: ; preds = %5
%8 = icmp ult i32 %0, 10
br i1 %8, label %26, label %9
9: ; preds = %7
%10 = icmp ult i32 %0, 100
br i1 %10, label %26, label %11
11: ; preds = %9
%12 = icmp ult i32 %0, 1000
br i1 %12, label %26, label %13
13: ; preds = %11
%14 = icmp ult i32 %0, 10000
br i1 %14, label %26, label %15
15: ; preds = %13
%16 = icmp ult i32 %0, 100000
br i1 %16, label %26, label %17
17: ; preds = %15
%18 = icmp ult i32 %0, 1000000
br i1 %18, label %26, label %19
19: ; preds = %17
%20 = icmp ult i32 %0, 10000000
br i1 %20, label %26, label %21
21: ; preds = %19
%22 = icmp ult i32 %0, 100000000
br i1 %22, label %26, label %23
23: ; preds = %21
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i32 %0, i32 9)
%25 = tail call i32 (...) @usagex()
br label %26
26: ; preds = %19, %17, %15, %13, %11, %9, %7, %5, %3, %23, %21
%27 = phi i32 [ 9, %23 ], [ 8, %21 ], [ 7, %19 ], [ 6, %17 ], [ 5, %15 ], [ 4, %13 ], [ 3, %11 ], [ 2, %9 ], [ 1, %7 ], [ 0, %5 ], [ 0, %3 ]
ret i32 %27
}