#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 */
typedef double uint64_t;

/* Variables and functions */
scalar_t__ log10(double);
int digits_w(double value, uint64_t ticks) {
  int w;
  value = (ticks == 0) ? 0.0 : value / ticks;
  w = value < 1.0 ? 1 : (int)log10(value);
  w += 4;
  return w < 6 ? 6 : w;
}


x86 assembly (clang, -O0):
<digits_w>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1147 <digits_w+0x37>
jp     1147 <digits_w+0x37>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1156 <digits_w+0x46>
movsd  -0x8(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  0xe98(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    1180 <digits_w+0x70>
mov    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    118d <digits_w+0x7d>
movsd  -0x8(%rbp),%xmm0
call   1030 <log10@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x6,-0x14(%rbp)
jge    11b3 <digits_w+0xa3>
mov    $0x6,%eax
mov    %eax,-0x28(%rbp)
jmp    11b9 <digits_w+0xa9>
mov    -0x14(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<digits_w>:
movapd %xmm0,%xmm2
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    1120 <digits_w+0x10>
jnp    1128 <digits_w+0x18>
divsd  %xmm1,%xmm2
movapd %xmm2,%xmm0
push   %rax
mov    $0x6,%eax
movsd  0xeca(%rip),%xmm1
ucomisd %xmm0,%xmm1
ja     1152 <digits_w+0x42>
call   1030 <log10@plt>
mov    %rax,%rcx
add    $0x4,%ecx
cmp    $0x7,%ecx
mov    $0x6,%eax
cmovge %ecx,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @digits_w(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca i32
store double %0, double* %3
store double %1, double* %4
%6 = load double, double* %4
%7 = fcmp oeq double %6, 0.000000e+00
br i1 %7, label %8, label %9
8: ; preds = %2
br label %13
9: ; preds = %2
%10 = load double, double* %3
%11 = load double, double* %4
%12 = fdiv double %10, %11
br label %13
13: ; preds = %9, %8
%14 = phi double [ 0.000000e+00, %8 ], [ %12, %9 ]
store double %14, double* %3
%15 = load double, double* %3
%16 = fcmp olt double %15, 1.000000e+00
br i1 %16, label %17, label %18
17: ; preds = %13
br label %22
18: ; preds = %13
%19 = load double, double* %3
%20 = call i64 @log10(double %19)
%21 = trunc i64 %20 to i32
br label %22
22: ; preds = %18, %17
%23 = phi i32 [ 1, %17 ], [ %21, %18 ]
store i32 %23, i32* %5
%24 = load i32, i32* %5
%25 = add nsw i32 %24, 4
store i32 %25, i32* %5
%26 = load i32, i32* %5
%27 = icmp slt i32 %26, 6
br i1 %27, label %28, label %29
28: ; preds = %22
br label %31
29: ; preds = %22
%30 = load i32, i32* %5
br label %31
31: ; preds = %29, %28
%32 = phi i32 [ 6, %28 ], [ %30, %29 ]
ret i32 %32
}

LLVM IR (-O2):
define i32 @digits_w(double %0, double %1) {
%3 = fcmp oeq double %1, 0.000000e+00
%4 = fdiv double %0, %1
%5 = select i1 %3, double 0.000000e+00, double %4
%6 = fcmp olt double %5, 1.000000e+00
br i1 %6, label %13, label %7
7: ; preds = %2
%8 = tail call i64 @log10(double %5)
%9 = trunc i64 %8 to i32
%10 = add i32 %9, 4
%11 = icmp sgt i32 %10, 6
%12 = select i1 %11, i32 %10, i32 6
br label %13
13: ; preds = %7, %2
%14 = phi i32 [ 6, %2 ], [ %12, %7 ]
ret i32 %14
}