; LLVM IR from jgaeddert/liquid-dsp :: src/math/src (poly)

; 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 speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

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

13:                                               ; preds = %61, %4
  %14 = load i32, ptr %11, align 4, !tbaa !9
  %15 = load i32, ptr %7, align 4, !tbaa !9
  %16 = icmp ult i32 %14, %15
  br i1 %16, label %17, label %64

17:                                               ; preds = %13
  store double 1.000000e+00, ptr %10, align 8, !tbaa !11
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %49, %17
  %19 = load i32, ptr %12, align 4, !tbaa !9
  %20 = load i32, ptr %7, align 4, !tbaa !9
  %21 = icmp ult i32 %19, %20
  br i1 %21, label %22, label %52

22:                                               ; preds = %18
  %23 = load i32, ptr %12, align 4, !tbaa !9
  %24 = load i32, ptr %11, align 4, !tbaa !9
  %25 = icmp ne i32 %23, %24
  br i1 %25, label %26, label %48

26:                                               ; preds = %22
  %27 = load double, ptr %8, align 8, !tbaa !11
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = load i32, ptr %12, align 4, !tbaa !9
  %30 = zext i32 %29 to i64
  %31 = getelementptr inbounds double, ptr %28, i64 %30
  %32 = load double, ptr %31, align 8, !tbaa !11
  %33 = fsub double %27, %32
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = load i32, ptr %11, align 4, !tbaa !9
  %36 = zext i32 %35 to i64
  %37 = getelementptr inbounds double, ptr %34, i64 %36
  %38 = load double, ptr %37, align 8, !tbaa !11
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = load i32, ptr %12, align 4, !tbaa !9
  %41 = zext i32 %40 to i64
  %42 = getelementptr inbounds double, ptr %39, i64 %41
  %43 = load double, ptr %42, align 8, !tbaa !11
  %44 = fsub double %38, %43
  %45 = fdiv double %33, %44
  %46 = load double, ptr %10, align 8, !tbaa !11
  %47 = fmul double %46, %45
  store double %47, ptr %10, align 8, !tbaa !11
  br label %48

48:                                               ; preds = %26, %22
  br label %49

49:                                               ; preds = %48
  %50 = load i32, ptr %12, align 4, !tbaa !9
  %51 = add i32 %50, 1
  store i32 %51, ptr %12, align 4, !tbaa !9
  br label %18, !llvm.loop !13

52:                                               ; preds = %18
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = load i32, ptr %11, align 4, !tbaa !9
  %55 = zext i32 %54 to i64
  %56 = getelementptr inbounds double, ptr %53, i64 %55
  %57 = load double, ptr %56, align 8, !tbaa !11
  %58 = load double, ptr %10, align 8, !tbaa !11
  %59 = load double, ptr %9, align 8, !tbaa !11
  %60 = call double @llvm.fmuladd.f64(double %57, double %58, double %59)
  store double %60, ptr %9, align 8, !tbaa !11
  br label %61

61:                                               ; preds = %52
  %62 = load i32, ptr %11, align 4, !tbaa !9
  %63 = add i32 %62, 1
  store i32 %63, ptr %11, align 4, !tbaa !9
  br label %13, !llvm.loop !15

64:                                               ; preds = %13
  %65 = load double, ptr %9, align 8, !tbaa !11
  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 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret double %65
}

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 = !{!"any pointer", !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 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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 @poly_interp_lagrange(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, i32 noundef %2, double noundef %3) local_unnamed_addr #1 {
  %.not28 = icmp eq i32 %2, 0
  br i1 %.not28, label %._crit_edge, label %.preheader.preheader

.preheader.preheader:                             ; preds = %4
  %wide.trip.count33 = zext i32 %2 to i64
  %xtraiter = and i64 %wide.trip.count33, 1
  %5 = icmp eq i32 %2, 1
  %unroll_iter = and i64 %wide.trip.count33, 4294967294
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %.epilog-lcssa
  %indvars.iv30 = phi i64 [ 0, %.preheader.preheader ], [ %indvars.iv.next31, %.epilog-lcssa ]
  %.02226 = phi double [ 0.000000e+00, %.preheader.preheader ], [ %35, %.epilog-lcssa ]
  %6 = getelementptr inbounds double, ptr %0, i64 %indvars.iv30
  br i1 %5, label %.unr-lcssa, label %.preheader.new

.preheader.new:                                   ; preds = %.preheader, %24
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %24 ], [ 0, %.preheader ]
  %.02124 = phi double [ %.1.1, %24 ], [ 1.000000e+00, %.preheader ]
  %niter = phi i64 [ %niter.next.1, %24 ], [ 0, %.preheader ]
  %.not = icmp eq i64 %indvars.iv, %indvars.iv30
  br i1 %.not, label %15, label %7

7:                                                ; preds = %.preheader.new
  %8 = getelementptr inbounds double, ptr %0, i64 %indvars.iv
  %9 = load double, ptr %8, align 8, !tbaa !5
  %10 = fsub double %3, %9
  %11 = load double, ptr %6, align 8, !tbaa !5
  %12 = fsub double %11, %9
  %13 = fdiv double %10, %12
  %14 = fmul double %.02124, %13
  br label %15

15:                                               ; preds = %.preheader.new, %7
  %.1 = phi double [ %14, %7 ], [ %.02124, %.preheader.new ]
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %.not.1 = icmp eq i64 %indvars.iv.next, %indvars.iv30
  br i1 %.not.1, label %24, label %16

16:                                               ; preds = %15
  %17 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.next
  %18 = load double, ptr %17, align 8, !tbaa !5
  %19 = fsub double %3, %18
  %20 = load double, ptr %6, align 8, !tbaa !5
  %21 = fsub double %20, %18
  %22 = fdiv double %19, %21
  %23 = fmul double %.1, %22
  br label %24

24:                                               ; preds = %16, %15
  %.1.1 = phi double [ %23, %16 ], [ %.1, %15 ]
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.unr-lcssa, label %.preheader.new, !llvm.loop !9

.unr-lcssa:                                       ; preds = %24, %.preheader
  %.1.lcssa.ph = phi double [ poison, %.preheader ], [ %.1.1, %24 ]
  %indvars.iv.unr = phi i64 [ 0, %.preheader ], [ %indvars.iv.next.1, %24 ]
  %.02124.unr = phi double [ 1.000000e+00, %.preheader ], [ %.1.1, %24 ]
  br i1 %lcmp.mod.not, label %.epilog-lcssa, label %.epil.preheader

.epil.preheader:                                  ; preds = %.unr-lcssa
  %.not.epil = icmp eq i64 %indvars.iv.unr, %indvars.iv30
  br i1 %.not.epil, label %.epilog-lcssa, label %25

25:                                               ; preds = %.epil.preheader
  %26 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.unr
  %27 = load double, ptr %26, align 8, !tbaa !5
  %28 = fsub double %3, %27
  %29 = load double, ptr %6, align 8, !tbaa !5
  %30 = fsub double %29, %27
  %31 = fdiv double %28, %30
  %32 = fmul double %.02124.unr, %31
  br label %.epilog-lcssa

.epilog-lcssa:                                    ; preds = %.epil.preheader, %25, %.unr-lcssa
  %.1.lcssa = phi double [ %.1.lcssa.ph, %.unr-lcssa ], [ %32, %25 ], [ %.02124.unr, %.epil.preheader ]
  %33 = getelementptr inbounds double, ptr %1, i64 %indvars.iv30
  %34 = load double, ptr %33, align 8, !tbaa !5
  %35 = tail call double @llvm.fmuladd.f64(double %34, double %.1.lcssa, double %.02226)
  %indvars.iv.next31 = add nuw nsw i64 %indvars.iv30, 1
  %exitcond34.not = icmp eq i64 %indvars.iv.next31, %wide.trip.count33
  br i1 %exitcond34.not, label %._crit_edge, label %.preheader, !llvm.loop !11

._crit_edge:                                      ; preds = %.epilog-lcssa, %4
  %.022.lcssa = phi double [ 0.000000e+00, %4 ], [ %35, %.epilog-lcssa ]
  ret double %.022.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.mustprogress"}
!11 = distinct !{!11, !10}


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