; 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.fmuladd.f64(double, double, double) #1

; Function Attrs: nounwind uwtable
define dso_local double @r8poly_value_horner(i32 noundef %0, ptr noundef %1, double noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca double, align 8
  %7 = alloca i32, align 4
  %8 = alloca double, align 8
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  store double %2, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %9 = load ptr, ptr %5, align 8, !tbaa !9
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds double, ptr %9, i64 %11
  %13 = load double, ptr %12, align 8, !tbaa !11
  store double %13, ptr %8, align 8, !tbaa !11
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = sub nsw i32 %14, 1
  store i32 %15, ptr %7, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %28, %3
  %17 = load i32, ptr %7, align 4, !tbaa !5
  %18 = icmp sle i32 0, %17
  br i1 %18, label %19, label %31

19:                                               ; preds = %16
  %20 = load double, ptr %8, align 8, !tbaa !11
  %21 = load double, ptr %6, align 8, !tbaa !11
  %22 = load ptr, ptr %5, align 8, !tbaa !9
  %23 = load i32, ptr %7, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds double, ptr %22, i64 %24
  %26 = load double, ptr %25, align 8, !tbaa !11
  %27 = call double @llvm.fmuladd.f64(double %20, double %21, double %26)
  store double %27, ptr %8, align 8, !tbaa !11
  br label %28

28:                                               ; preds = %19
  %29 = load i32, ptr %7, align 4, !tbaa !5
  %30 = add nsw i32 %29, -1
  store i32 %30, ptr %7, align 4, !tbaa !5
  br label %16, !llvm.loop !13

31:                                               ; preds = %16
  %32 = load double, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret double %32
}

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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; 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.fmuladd.f64(double, double, double) #0

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: read) uwtable
define dso_local double @r8poly_value_horner(i32 noundef %0, ptr nocapture noundef readonly %1, double noundef %2) local_unnamed_addr #1 {
  %4 = sext i32 %0 to i64
  %5 = getelementptr inbounds double, ptr %1, i64 %4
  %6 = load double, ptr %5, align 8, !tbaa !5
  %7 = icmp sgt i32 %0, 0
  br i1 %7, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %3
  %8 = zext nneg i32 %0 to i64
  %xtraiter = and i64 %8, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader, %.lr.ph.prol
  %indvars.iv.prol = phi i64 [ %indvars.iv.next.prol, %.lr.ph.prol ], [ %8, %.lr.ph.preheader ]
  %.011.prol = phi double [ %11, %.lr.ph.prol ], [ %6, %.lr.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader ]
  %indvars.iv.next.prol = add nsw i64 %indvars.iv.prol, -1
  %9 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.next.prol
  %10 = load double, ptr %9, align 8, !tbaa !5
  %11 = tail call double @llvm.fmuladd.f64(double %.011.prol, double %2, double %10)
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol, !llvm.loop !9

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader
  %indvars.iv.unr = phi i64 [ %8, %.lr.ph.preheader ], [ %indvars.iv.next.prol, %.lr.ph.prol ]
  %.011.unr = phi double [ %6, %.lr.ph.preheader ], [ %11, %.lr.ph.prol ]
  %.lcssa.unr = phi double [ poison, %.lr.ph.preheader ], [ %11, %.lr.ph.prol ]
  %12 = icmp ult i32 %0, 4
  br i1 %12, label %._crit_edge, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.prol.loopexit
  %invariant.gep = getelementptr i8, ptr %1, i64 -8
  %invariant.gep15 = getelementptr i8, ptr %1, i64 -16
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ %indvars.iv.unr, %.lr.ph.preheader.new ], [ %indvars.iv.next.3, %.lr.ph ]
  %.011 = phi double [ %.011.unr, %.lr.ph.preheader.new ], [ %22, %.lr.ph ]
  %gep = getelementptr double, ptr %invariant.gep, i64 %indvars.iv
  %13 = load double, ptr %gep, align 8, !tbaa !5
  %14 = tail call double @llvm.fmuladd.f64(double %.011, double %2, double %13)
  %gep16 = getelementptr double, ptr %invariant.gep15, i64 %indvars.iv
  %15 = load double, ptr %gep16, align 8, !tbaa !5
  %16 = tail call double @llvm.fmuladd.f64(double %14, double %2, double %15)
  %indvars.iv.next.2 = add nsw i64 %indvars.iv, -3
  %17 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.next.2
  %18 = load double, ptr %17, align 8, !tbaa !5
  %19 = tail call double @llvm.fmuladd.f64(double %16, double %2, double %18)
  %indvars.iv.next.3 = add nsw i64 %indvars.iv, -4
  %20 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.next.3
  %21 = load double, ptr %20, align 8, !tbaa !5
  %22 = tail call double @llvm.fmuladd.f64(double %19, double %2, double %21)
  %23 = icmp ugt i64 %indvars.iv.next.2, 1
  br i1 %23, label %.lr.ph, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %3
  %.0.lcssa = phi double [ %6, %3 ], [ %.lcssa.unr, %.lr.ph.prol.loopexit ], [ %22, %.lr.ph ]
  ret double %.0.lcssa
}

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


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