; LLVM IR from xxks-kkk/algo :: utility (utility)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @countDigits(i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @chunk_number(i32 noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = call i32 @countDigits(i32 noundef %13)
  store i32 %14, ptr %8, align 4, !tbaa !5
  %15 = load i32, ptr %6, align 4, !tbaa !5
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %27

17:                                               ; preds = %3
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = load i32, ptr %8, align 4, !tbaa !5
  %20 = sub nsw i32 %19, 1
  %21 = load i32, ptr %7, align 4, !tbaa !5
  %22 = sub nsw i32 %20, %21
  %23 = sitofp i32 %22 to double
  %24 = call double @pow(double noundef 1.000000e+01, double noundef %23) #3
  %25 = fptosi double %24 to i32
  %26 = sdiv i32 %18, %25
  store i32 %26, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %59

27:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %28 = load i32, ptr %5, align 4, !tbaa !5
  %29 = load i32, ptr %8, align 4, !tbaa !5
  %30 = sub nsw i32 %29, 1
  %31 = load i32, ptr %7, align 4, !tbaa !5
  %32 = sub nsw i32 %30, %31
  %33 = sitofp i32 %32 to double
  %34 = call double @pow(double noundef 1.000000e+01, double noundef %33) #3
  %35 = fptosi double %34 to i32
  %36 = sdiv i32 %28, %35
  store i32 %36, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %37 = load i32, ptr %8, align 4, !tbaa !5
  %38 = load i32, ptr %8, align 4, !tbaa !5
  %39 = sub nsw i32 %38, 1
  %40 = load i32, ptr %7, align 4, !tbaa !5
  %41 = sub nsw i32 %39, %40
  %42 = sub nsw i32 %37, %41
  store i32 %42, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %43 = load i32, ptr %11, align 4, !tbaa !5
  %44 = load i32, ptr %6, align 4, !tbaa !5
  %45 = sub nsw i32 %43, %44
  store i32 %45, ptr %12, align 4, !tbaa !5
  %46 = load i32, ptr %10, align 4, !tbaa !5
  %47 = load i32, ptr %10, align 4, !tbaa !5
  %48 = load i32, ptr %12, align 4, !tbaa !5
  %49 = sitofp i32 %48 to double
  %50 = call double @pow(double noundef 1.000000e+01, double noundef %49) #3
  %51 = fptosi double %50 to i32
  %52 = sdiv i32 %47, %51
  %53 = load i32, ptr %12, align 4, !tbaa !5
  %54 = sitofp i32 %53 to double
  %55 = call double @pow(double noundef 1.000000e+01, double noundef %54) #3
  %56 = fptosi double %55 to i32
  %57 = mul nsw i32 %52, %56
  %58 = sub nsw i32 %46, %57
  store i32 %58, ptr %4, align 4
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %59

59:                                               ; preds = %27, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %60 = load i32, ptr %4, align 4
  ret i32 %60
}

; Function Attrs: nounwind
declare double @pow(double noundef, double noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: nounwind uwtable
declare dso_local i32 @countDigits(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @chunk_number(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = tail call i32 @countDigits(i32 noundef %0)
  %5 = icmp eq i32 %1, 0
  %6 = xor i32 %2, -1
  %7 = add i32 %4, %6
  %8 = sitofp i32 %7 to double
  %9 = tail call double @pow(double noundef 1.000000e+01, double noundef %8) #2
  %10 = fptosi double %9 to i32
  %11 = sdiv i32 %0, %10
  br i1 %5, label %22, label %12

12:                                               ; preds = %3
  %reass.sub = sub i32 %2, %1
  %13 = add i32 %reass.sub, 1
  %14 = sitofp i32 %13 to double
  %15 = tail call double @pow(double noundef 1.000000e+01, double noundef %14) #2
  %16 = fptosi double %15 to i32
  %17 = sdiv i32 %11, %16
  %18 = tail call double @pow(double noundef 1.000000e+01, double noundef %14) #2
  %19 = fptosi double %18 to i32
  %20 = mul nsw i32 %17, %19
  %21 = sub nsw i32 %11, %20
  br label %22

22:                                               ; preds = %3, %12
  %.0 = phi i32 [ %21, %12 ], [ %11, %3 ]
  ret i32 %.0
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @pow(double noundef, double noundef) local_unnamed_addr #1

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { mustprogress nofree nounwind willreturn memory(write) "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass