#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 */
scalar_t__ pow(int, double);
size_t num_digits(int num) {
  size_t i = 0, l = 0;
  for (i = 5, l = 0; i >= l; i--) {
    if (num >= (int)pow(10, (double)i)) {
      return i + 1;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<num_digits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x5,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jb     11b5 <num_digits+0xa5>
mov    -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
movaps 0xeaa(%rip),%xmm1
movq   -0x18(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xea9(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
mov    $0xa,%edi
call   1030 <pow@plt>
mov    %rax,%rcx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jl     119f <num_digits+0x8f>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11bd <num_digits+0xad>
jmp    11a4 <num_digits+0x94>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    113b <num_digits+0x2b>
movq   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<num_digits>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    $0x7,%ebx
nopw   0x0(%rax,%rax,1)
lea    -0x2(%rbx),%rax
movq   %rax,%xmm1
punpckldq 0xecf(%rip),%xmm1
subpd  0xed7(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
mov    $0xa,%edi
call   1030 <pow@plt>
add    $0xffffffffffffffff,%rbx
cmp    %ebp,%eax
jg     1120 <num_digits+0x10>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define i64 @num_digits(i32 %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i64 [ 5, %1 ], [ %8, %2 ]
%4 = uitofp i64 %3 to double
%5 = tail call i64 @pow(i32 10, double %4)
%6 = trunc i64 %5 to i32
%7 = icmp sgt i32 %6, %0
%8 = add i64 %3, -1
br i1 %7, label %2, label %9
9: ; preds = %2
%10 = add i64 %3, 1
ret i64 %10
}