; LLVM IR from CLASS-SZ/class_sz :: class-sz/tools (r8lib)

; 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @r8_digit(double noundef %0, i32 noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca double, align 8
  %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
  store double %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %10 = load double, ptr %4, align 8, !tbaa !5
  %11 = fcmp oeq double %10, 0.000000e+00
  br i1 %11, label %12, label %14

12:                                               ; preds = %2
  store i32 0, ptr %6, align 4, !tbaa !9
  %13 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %13, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %54

14:                                               ; preds = %2
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = icmp sle i32 %15, 0
  br i1 %16, label %17, label %19

17:                                               ; preds = %14
  store i32 0, ptr %6, align 4, !tbaa !9
  %18 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %18, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %54

19:                                               ; preds = %14
  %20 = load double, ptr %4, align 8, !tbaa !5
  %21 = call double @llvm.fabs.f64(double %20)
  store double %21, ptr %4, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %25, %19
  %23 = load double, ptr %4, align 8, !tbaa !5
  %24 = fcmp olt double %23, 1.000000e+00
  br i1 %24, label %25, label %28

25:                                               ; preds = %22
  %26 = load double, ptr %4, align 8, !tbaa !5
  %27 = fmul double %26, 1.000000e+01
  store double %27, ptr %4, align 8, !tbaa !5
  br label %22, !llvm.loop !11

28:                                               ; preds = %22
  br label %29

29:                                               ; preds = %32, %28
  %30 = load double, ptr %4, align 8, !tbaa !5
  %31 = fcmp ole double 1.000000e+01, %30
  br i1 %31, label %32, label %35

32:                                               ; preds = %29
  %33 = load double, ptr %4, align 8, !tbaa !5
  %34 = fdiv double %33, 1.000000e+01
  store double %34, ptr %4, align 8, !tbaa !5
  br label %29, !llvm.loop !13

35:                                               ; preds = %29
  store i32 1, ptr %7, align 4, !tbaa !9
  br label %36

36:                                               ; preds = %48, %35
  %37 = load i32, ptr %7, align 4, !tbaa !9
  %38 = load i32, ptr %5, align 4, !tbaa !9
  %39 = icmp sle i32 %37, %38
  br i1 %39, label %40, label %51

40:                                               ; preds = %36
  %41 = load double, ptr %4, align 8, !tbaa !5
  %42 = fptosi double %41 to i32
  store i32 %42, ptr %8, align 4, !tbaa !9
  %43 = load double, ptr %4, align 8, !tbaa !5
  %44 = load i32, ptr %8, align 4, !tbaa !9
  %45 = sitofp i32 %44 to double
  %46 = fsub double %43, %45
  %47 = fmul double %46, 1.000000e+01
  store double %47, ptr %4, align 8, !tbaa !5
  br label %48

48:                                               ; preds = %40
  %49 = load i32, ptr %7, align 4, !tbaa !9
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %7, align 4, !tbaa !9
  br label %36, !llvm.loop !14

51:                                               ; preds = %36
  %52 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %52, ptr %6, align 4, !tbaa !9
  %53 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %53, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %54

54:                                               ; preds = %51, %17, %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %55 = load i32, ptr %3, align 4
  ret i32 %55
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 #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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


; 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: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #0

; Function Attrs: nofree norecurse nosync nounwind memory(none) uwtable
define dso_local i32 @r8_digit(double noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = fcmp oeq double %0, 0.000000e+00
  %4 = icmp slt i32 %1, 1
  %or.cond = or i1 %3, %4
  br i1 %or.cond, label %.loopexit, label %5

5:                                                ; preds = %2
  %6 = tail call double @llvm.fabs.f64(double %0)
  %7 = fcmp olt double %6, 1.000000e+00
  br i1 %7, label %.lr.ph, label %.preheader22

.preheader22:                                     ; preds = %.lr.ph, %5
  %.019.lcssa = phi double [ %6, %5 ], [ %9, %.lr.ph ]
  %8 = fcmp ult double %.019.lcssa, 1.000000e+01
  br i1 %8, label %.lr.ph30.preheader, label %.lr.ph25

.lr.ph:                                           ; preds = %5, %.lr.ph
  %.01923 = phi double [ %9, %.lr.ph ], [ %6, %5 ]
  %9 = fmul double %.01923, 1.000000e+01
  %10 = fcmp olt double %9, 1.000000e+00
  br i1 %10, label %.lr.ph, label %.preheader22, !llvm.loop !5

.lr.ph25:                                         ; preds = %.preheader22, %.lr.ph25
  %.124 = phi double [ %11, %.lr.ph25 ], [ %.019.lcssa, %.preheader22 ]
  %11 = fdiv double %.124, 1.000000e+01
  %12 = fcmp ult double %11, 1.000000e+01
  br i1 %12, label %.lr.ph30.preheader, label %.lr.ph25, !llvm.loop !7

.lr.ph30.preheader:                               ; preds = %.lr.ph25, %.preheader22
  %.228.ph = phi double [ %.019.lcssa, %.preheader22 ], [ %11, %.lr.ph25 ]
  %13 = add nsw i32 %1, -1
  %xtraiter = and i32 %1, 3
  %14 = icmp ult i32 %13, 3
  br i1 %14, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph30.preheader.new

.lr.ph30.preheader.new:                           ; preds = %.lr.ph30.preheader
  %unroll_iter = and i32 %1, 2147483644
  br label %.lr.ph30

.lr.ph30:                                         ; preds = %.lr.ph30, %.lr.ph30.preheader.new
  %.228 = phi double [ %.228.ph, %.lr.ph30.preheader.new ], [ %30, %.lr.ph30 ]
  %niter = phi i32 [ 0, %.lr.ph30.preheader.new ], [ %niter.next.3, %.lr.ph30 ]
  %15 = fptosi double %.228 to i32
  %16 = sitofp i32 %15 to double
  %17 = fsub double %.228, %16
  %18 = fmul double %17, 1.000000e+01
  %19 = fptosi double %18 to i32
  %20 = sitofp i32 %19 to double
  %21 = fsub double %18, %20
  %22 = fmul double %21, 1.000000e+01
  %23 = fptosi double %22 to i32
  %24 = sitofp i32 %23 to double
  %25 = fsub double %22, %24
  %26 = fmul double %25, 1.000000e+01
  %27 = fptosi double %26 to i32
  %28 = sitofp i32 %27 to double
  %29 = fsub double %26, %28
  %30 = fmul double %29, 1.000000e+01
  %niter.next.3 = add i32 %niter, 4
  %niter.ncmp.3 = icmp eq i32 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph30, !llvm.loop !8

.loopexit.loopexit.unr-lcssa:                     ; preds = %.lr.ph30, %.lr.ph30.preheader
  %.lcssa.ph = phi i32 [ poison, %.lr.ph30.preheader ], [ %27, %.lr.ph30 ]
  %.228.unr = phi double [ %.228.ph, %.lr.ph30.preheader ], [ %30, %.lr.ph30 ]
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.loopexit, label %.lr.ph30.epil

.lr.ph30.epil:                                    ; preds = %.loopexit.loopexit.unr-lcssa, %.lr.ph30.epil
  %.228.epil = phi double [ %34, %.lr.ph30.epil ], [ %.228.unr, %.loopexit.loopexit.unr-lcssa ]
  %epil.iter = phi i32 [ %epil.iter.next, %.lr.ph30.epil ], [ 0, %.loopexit.loopexit.unr-lcssa ]
  %31 = fptosi double %.228.epil to i32
  %32 = sitofp i32 %31 to double
  %33 = fsub double %.228.epil, %32
  %34 = fmul double %33, 1.000000e+01
  %epil.iter.next = add i32 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i32 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %.loopexit, label %.lr.ph30.epil, !llvm.loop !9

.loopexit:                                        ; preds = %.loopexit.loopexit.unr-lcssa, %.lr.ph30.epil, %2
  %.018 = phi i32 [ 0, %2 ], [ %.lcssa.ph, %.loopexit.loopexit.unr-lcssa ], [ %31, %.lr.ph30.epil ]
  ret i32 %.018
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { nofree norecurse nosync nounwind memory(none) 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" }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}
!8 = distinct !{!8, !6}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.unroll.disable"}


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass