#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*/ assert(int);
int decimal_digits_naive(int x) {
  assert(x >= 0);
  if (x == 0)
    return 1;
  int pow = 1;
  int digits = 0;
  while (x >= pow) {
    pow *= 10;
    digits += 1;
  }
  return digits;
}


x86 assembly (clang, -O0):
<decimal_digits_naive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpl   $0x0,-0x8(%rbp)
jne    1142 <decimal_digits_naive+0x32>
movl   $0x1,-0x4(%rbp)
jmp    1177 <decimal_digits_naive+0x67>
movl   $0x1,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jl     1171 <decimal_digits_naive+0x61>
imul   $0xa,-0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1150 <decimal_digits_naive+0x40>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decimal_digits_naive>:
push   %rbx
mov    %edi,%ebx
not    %edi
shr    $0x1f,%edi
call   1030 <assert@plt>
test   %ebx,%ebx
je     113e <decimal_digits_naive+0x2e>
jle    1145 <decimal_digits_naive+0x35>
mov    $0x1,%ecx
xor    %eax,%eax
nopw   0x0(%rax,%rax,1)
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
add    $0x1,%eax
cmp    %ebx,%ecx
jle    1130 <decimal_digits_naive+0x20>
pop    %rbx
ret
mov    $0x1,%eax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @decimal_digits_naive(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = icmp sge i32 %6, 0
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i32, i32* %3
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %1
store i32 1, i32* %2
br label %25
13: ; preds = %1
store i32 1, i32* %4
store i32 0, i32* %5
br label %14
14: ; preds = %18, %13
%15 = load i32, i32* %3
%16 = load i32, i32* %4
%17 = icmp sge i32 %15, %16
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = load i32, i32* %4
%20 = mul nsw i32 %19, 10
store i32 %20, i32* %4
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 1
store i32 %22, i32* %5
br label %14
23: ; preds = %14
%24 = load i32, i32* %5
store i32 %24, i32* %2
br label %25
25: ; preds = %23, %12
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
define i32 @decimal_digits_naive(i32 %0) {
%2 = xor i32 %0, -1
%3 = lshr i32 %2, 31
%4 = tail call i32 @assert(i32 %3)
%5 = icmp eq i32 %0, 0
br i1 %5, label %14, label %6
6: ; preds = %1
%7 = icmp slt i32 %0, 1
br i1 %7, label %14, label %8
8: ; preds = %6, %8
%9 = phi i32 [ %12, %8 ], [ 0, %6 ]
%10 = phi i32 [ %11, %8 ], [ 1, %6 ]
%11 = mul nsw i32 %10, 10
%12 = add nuw nsw i32 %9, 1
%13 = icmp sgt i32 %11, %0
br i1 %13, label %14, label %8
14: ; preds = %8, %6, %1
%15 = phi i32 [ 1, %1 ], [ 0, %6 ], [ %12, %8 ]
ret i32 %15
}