; 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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local double @poly_val_lagrange_barycentric(ptr noundef %0, ptr noundef %1, ptr noundef %2, double noundef %3, i32 noundef %4) #1 {
  %6 = alloca double, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca double, align 8
  %11 = alloca i32, align 4
  %12 = alloca double, align 8
  %13 = alloca double, align 8
  %14 = alloca double, align 8
  %15 = alloca float, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store double %3, ptr %10, align 8, !tbaa !9
  store i32 %4, ptr %11, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  store double 0.000000e+00, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  store double 0.000000e+00, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  store float 0x3EB0C6F7A0000000, ptr %15, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  store i32 0, ptr %16, align 4, !tbaa !11
  br label %18

18:                                               ; preds = %66, %5
  %19 = load i32, ptr %16, align 4, !tbaa !11
  %20 = load i32, ptr %11, align 4, !tbaa !11
  %21 = icmp ult i32 %19, %20
  br i1 %21, label %22, label %69

22:                                               ; preds = %18
  %23 = load double, ptr %10, align 8, !tbaa !9
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = load i32, ptr %16, align 4, !tbaa !11
  %26 = zext i32 %25 to i64
  %27 = getelementptr inbounds double, ptr %24, i64 %26
  %28 = load double, ptr %27, align 8, !tbaa !9
  %29 = fsub double %23, %28
  store double %29, ptr %14, align 8, !tbaa !9
  %30 = load double, ptr %14, align 8, !tbaa !9
  %31 = call double @llvm.fabs.f64(double %30)
  %32 = load float, ptr %15, align 4, !tbaa !13
  %33 = fpext float %32 to double
  %34 = fcmp olt double %31, %33
  br i1 %34, label %35, label %41

35:                                               ; preds = %22
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = load i32, ptr %16, align 4, !tbaa !11
  %38 = zext i32 %37 to i64
  %39 = getelementptr inbounds double, ptr %36, i64 %38
  %40 = load double, ptr %39, align 8, !tbaa !9
  store double %40, ptr %6, align 8
  store i32 1, ptr %17, align 4
  br label %73

41:                                               ; preds = %22
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  %43 = load i32, ptr %16, align 4, !tbaa !11
  %44 = zext i32 %43 to i64
  %45 = getelementptr inbounds double, ptr %42, i64 %44
  %46 = load double, ptr %45, align 8, !tbaa !9
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = load i32, ptr %16, align 4, !tbaa !11
  %49 = zext i32 %48 to i64
  %50 = getelementptr inbounds double, ptr %47, i64 %49
  %51 = load double, ptr %50, align 8, !tbaa !9
  %52 = fmul double %46, %51
  %53 = load double, ptr %14, align 8, !tbaa !9
  %54 = fdiv double %52, %53
  %55 = load double, ptr %12, align 8, !tbaa !9
  %56 = fadd double %55, %54
  store double %56, ptr %12, align 8, !tbaa !9
  %57 = load ptr, ptr %9, align 8, !tbaa !5
  %58 = load i32, ptr %16, align 4, !tbaa !11
  %59 = zext i32 %58 to i64
  %60 = getelementptr inbounds double, ptr %57, i64 %59
  %61 = load double, ptr %60, align 8, !tbaa !9
  %62 = load double, ptr %14, align 8, !tbaa !9
  %63 = fdiv double %61, %62
  %64 = load double, ptr %13, align 8, !tbaa !9
  %65 = fadd double %64, %63
  store double %65, ptr %13, align 8, !tbaa !9
  br label %66

66:                                               ; preds = %41
  %67 = load i32, ptr %16, align 4, !tbaa !11
  %68 = add i32 %67, 1
  store i32 %68, ptr %16, align 4, !tbaa !11
  br label %18, !llvm.loop !15

69:                                               ; preds = %18
  %70 = load double, ptr %12, align 8, !tbaa !9
  %71 = load double, ptr %13, align 8, !tbaa !9
  %72 = fdiv double %70, %71
  store double %72, ptr %6, align 8
  store i32 1, ptr %17, align 4
  br label %73

73:                                               ; preds = %69, %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %74 = load double, ptr %6, align 8
  ret double %74
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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: nofree norecurse nosync nounwind memory(argmem: read) uwtable
define dso_local double @poly_val_lagrange_barycentric(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2, double noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %5
  %wide.trip.count = zext i32 %4 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %15
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %15 ]
  %6 = phi <2 x double> [ zeroinitializer, %.lr.ph.preheader ], [ %26, %15 ]
  %7 = getelementptr inbounds double, ptr %0, i64 %indvars.iv
  %8 = load double, ptr %7, align 8, !tbaa !5
  %9 = fsub double %3, %8
  %10 = tail call double @llvm.fabs.f64(double %9)
  %11 = fcmp olt double %10, 0x3EB0C6F7A0000000
  br i1 %11, label %12, label %15

12:                                               ; preds = %.lr.ph
  %13 = getelementptr inbounds double, ptr %1, i64 %indvars.iv
  %14 = load double, ptr %13, align 8, !tbaa !5
  br label %._crit_edge

15:                                               ; preds = %.lr.ph
  %16 = getelementptr inbounds double, ptr %2, i64 %indvars.iv
  %17 = load double, ptr %16, align 8, !tbaa !5
  %18 = getelementptr inbounds double, ptr %1, i64 %indvars.iv
  %19 = load double, ptr %18, align 8, !tbaa !5
  %20 = fmul double %17, %19
  %21 = insertelement <2 x double> poison, double %20, i64 0
  %22 = insertelement <2 x double> %21, double %17, i64 1
  %23 = insertelement <2 x double> poison, double %9, i64 0
  %24 = shufflevector <2 x double> %23, <2 x double> poison, <2 x i32> zeroinitializer
  %25 = fdiv <2 x double> %22, %24
  %26 = fadd <2 x double> %6, %25
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !9

._crit_edge.loopexit:                             ; preds = %15
  %27 = extractelement <2 x double> %26, i64 0
  %28 = extractelement <2 x double> %26, i64 1
  %29 = fdiv double %27, %28
  br label %._crit_edge

._crit_edge:                                      ; preds = %5, %._crit_edge.loopexit, %12
  %.022 = phi double [ %14, %12 ], [ 0x7FF8000000000000, %5 ], [ %29, %._crit_edge.loopexit ]
  ret double %.022
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #1

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

!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"}


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