; 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: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #1

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @poly_expandroots(ptr noundef, i32 noundef, ptr noundef) #2

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

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

21:                                               ; preds = %17
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = load i32, ptr %9, align 4, !tbaa !9
  %24 = zext i32 %23 to i64
  %25 = getelementptr inbounds double, ptr %22, i64 %24
  %26 = load double, ptr %25, align 8, !tbaa !11
  %27 = fneg double %26
  %28 = load double, ptr %10, align 8, !tbaa !11
  %29 = fmul double %28, %27
  store double %29, ptr %10, align 8, !tbaa !11
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = load i32, ptr %9, align 4, !tbaa !9
  %32 = zext i32 %31 to i64
  %33 = getelementptr inbounds double, ptr %30, i64 %32
  %34 = load double, ptr %33, align 8, !tbaa !11
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = load i32, ptr %9, align 4, !tbaa !9
  %37 = zext i32 %36 to i64
  %38 = getelementptr inbounds double, ptr %35, i64 %37
  %39 = load double, ptr %38, align 8, !tbaa !11
  %40 = fdiv double %34, %39
  %41 = load i32, ptr %9, align 4, !tbaa !9
  %42 = zext i32 %41 to i64
  %43 = getelementptr inbounds double, ptr %16, i64 %42
  store double %40, ptr %43, align 8, !tbaa !11
  br label %44

44:                                               ; preds = %21
  %45 = load i32, ptr %9, align 4, !tbaa !9
  %46 = add i32 %45, 1
  store i32 %46, ptr %9, align 4, !tbaa !9
  br label %17, !llvm.loop !13

47:                                               ; preds = %17
  %48 = load i32, ptr %7, align 4, !tbaa !9
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = call i32 @poly_expandroots(ptr noundef %16, i32 noundef %48, ptr noundef %49)
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %51

51:                                               ; preds = %64, %47
  %52 = load i32, ptr %9, align 4, !tbaa !9
  %53 = load i32, ptr %7, align 4, !tbaa !9
  %54 = add i32 %53, 1
  %55 = icmp ult i32 %52, %54
  br i1 %55, label %56, label %67

56:                                               ; preds = %51
  %57 = load double, ptr %10, align 8, !tbaa !11
  %58 = load ptr, ptr %8, align 8, !tbaa !5
  %59 = load i32, ptr %9, align 4, !tbaa !9
  %60 = zext i32 %59 to i64
  %61 = getelementptr inbounds double, ptr %58, i64 %60
  %62 = load double, ptr %61, align 8, !tbaa !11
  %63 = fmul double %62, %57
  store double %63, ptr %61, align 8, !tbaa !11
  br label %64

64:                                               ; preds = %56
  %65 = load i32, ptr %9, align 4, !tbaa !9
  %66 = add i32 %65, 1
  store i32 %66, ptr %9, align 4, !tbaa !9
  br label %51, !llvm.loop !15

67:                                               ; preds = %51
  %68 = load ptr, ptr %11, align 8
  call void @llvm.stackrestore.p0(ptr %68)
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  ret i32 0
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn }
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: nounwind uwtable
declare dso_local i32 @poly_expandroots(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @poly_expandroots2(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, i32 noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = zext i32 %2 to i64
  %6 = alloca double, i64 %5, align 16
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %._crit_edge.thread, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %4
  %xtraiter = and i64 %5, 1
  %7 = icmp eq i32 %2, 1
  br i1 %7, label %._crit_edge.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %5, 4294967294
  br label %.lr.ph

._crit_edge.thread:                               ; preds = %4
  %8 = call i32 @poly_expandroots(ptr noundef nonnull %6, i32 noundef %2, ptr noundef %3)
  br label %.lr.ph26.preheader

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.1, %.lr.ph ]
  %.02022 = phi double [ 1.000000e+00, %.lr.ph.preheader.new ], [ %20, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %9 = getelementptr inbounds double, ptr %1, i64 %indvars.iv
  %10 = load double, ptr %9, align 8, !tbaa !5
  %11 = fneg double %10
  %12 = fmul double %.02022, %11
  %13 = getelementptr inbounds double, ptr %0, i64 %indvars.iv
  %14 = load double, ptr %13, align 8, !tbaa !5
  %15 = fdiv double %14, %10
  %16 = getelementptr inbounds double, ptr %6, i64 %indvars.iv
  store double %15, ptr %16, align 16, !tbaa !5
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %17 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.next
  %18 = load double, ptr %17, align 8, !tbaa !5
  %19 = fneg double %18
  %20 = fmul double %12, %19
  %21 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.next
  %22 = load double, ptr %21, align 8, !tbaa !5
  %23 = fdiv double %22, %18
  %24 = getelementptr inbounds double, ptr %6, i64 %indvars.iv.next
  store double %23, ptr %24, align 8, !tbaa !5
  %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 %._crit_edge.unr-lcssa, label %.lr.ph, !llvm.loop !9

._crit_edge.unr-lcssa:                            ; preds = %.lr.ph, %.lr.ph.preheader
  %.lcssa.ph = phi double [ poison, %.lr.ph.preheader ], [ %20, %.lr.ph ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next.1, %.lr.ph ]
  %.02022.unr = phi double [ 1.000000e+00, %.lr.ph.preheader ], [ %20, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.unr-lcssa
  %25 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.unr
  %26 = load double, ptr %25, align 8, !tbaa !5
  %27 = fneg double %26
  %28 = fmul double %.02022.unr, %27
  %29 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.unr
  %30 = load double, ptr %29, align 8, !tbaa !5
  %31 = fdiv double %30, %26
  %32 = getelementptr inbounds double, ptr %6, i64 %indvars.iv.unr
  store double %31, ptr %32, align 8, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.unr-lcssa, %.lr.ph.epil
  %.lcssa = phi double [ %.lcssa.ph, %._crit_edge.unr-lcssa ], [ %28, %.lr.ph.epil ]
  %33 = call i32 @poly_expandroots(ptr noundef nonnull %6, i32 noundef %2, ptr noundef %3)
  %34 = add i32 %2, 1
  %.not28 = icmp eq i32 %34, 0
  br i1 %.not28, label %._crit_edge27, label %.lr.ph26.preheader

.lr.ph26.preheader:                               ; preds = %._crit_edge.thread, %._crit_edge
  %35 = phi i32 [ 1, %._crit_edge.thread ], [ %34, %._crit_edge ]
  %.020.lcssa37 = phi double [ 1.000000e+00, %._crit_edge.thread ], [ %.lcssa, %._crit_edge ]
  %wide.trip.count33 = zext i32 %35 to i64
  %min.iters.check = icmp ult i32 %35, 4
  br i1 %min.iters.check, label %.lr.ph26.preheader39, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph26.preheader
  %n.vec = and i64 %wide.trip.count33, 4294967292
  %broadcast.splatinsert = insertelement <2 x double> poison, double %.020.lcssa37, i64 0
  %broadcast.splat = shufflevector <2 x double> %broadcast.splatinsert, <2 x double> poison, <2 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %36 = getelementptr inbounds double, ptr %3, i64 %index
  %37 = getelementptr inbounds i8, ptr %36, i64 16
  %wide.load = load <2 x double>, ptr %36, align 8, !tbaa !5
  %wide.load38 = load <2 x double>, ptr %37, align 8, !tbaa !5
  %38 = fmul <2 x double> %broadcast.splat, %wide.load
  %39 = fmul <2 x double> %broadcast.splat, %wide.load38
  store <2 x double> %38, ptr %36, align 8, !tbaa !5
  store <2 x double> %39, ptr %37, align 8, !tbaa !5
  %index.next = add nuw i64 %index, 4
  %40 = icmp eq i64 %index.next, %n.vec
  br i1 %40, label %middle.block, label %vector.body, !llvm.loop !11

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count33
  br i1 %cmp.n, label %._crit_edge27, label %.lr.ph26.preheader39

.lr.ph26.preheader39:                             ; preds = %middle.block, %.lr.ph26.preheader
  %indvars.iv30.ph = phi i64 [ 0, %.lr.ph26.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph26

.lr.ph26:                                         ; preds = %.lr.ph26.preheader39, %.lr.ph26
  %indvars.iv30 = phi i64 [ %indvars.iv.next31, %.lr.ph26 ], [ %indvars.iv30.ph, %.lr.ph26.preheader39 ]
  %41 = getelementptr inbounds double, ptr %3, i64 %indvars.iv30
  %42 = load double, ptr %41, align 8, !tbaa !5
  %43 = fmul double %.020.lcssa37, %42
  store double %43, ptr %41, align 8, !tbaa !5
  %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_edge27, label %.lr.ph26, !llvm.loop !14

._crit_edge27:                                    ; preds = %.lr.ph26, %middle.block, %._crit_edge
  ret i32 0
}

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

!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, !12, !13}
!12 = !{!"llvm.loop.isvectorized", i32 1}
!13 = !{!"llvm.loop.unroll.runtime.disable"}
!14 = distinct !{!14, !10, !13, !12}


; Effective O3 passes: ADCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass