; 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 i32 @poly_expandroots(ptr noundef %0, i32 noundef %1, ptr noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  %10 = load i32, ptr %6, align 4, !tbaa !9
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %12, label %15

12:                                               ; preds = %3
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  %14 = getelementptr inbounds double, ptr %13, i64 0
  store double 0.000000e+00, ptr %14, align 8, !tbaa !11
  store i32 0, ptr %4, align 4
  br label %87

15:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %30, %15
  %17 = load i32, ptr %8, align 4, !tbaa !9
  %18 = load i32, ptr %6, align 4, !tbaa !9
  %19 = icmp ule i32 %17, %18
  br i1 %19, label %20, label %33

20:                                               ; preds = %16
  %21 = load i32, ptr %8, align 4, !tbaa !9
  %22 = icmp eq i32 %21, 0
  %23 = zext i1 %22 to i64
  %24 = select i1 %22, i32 1, i32 0
  %25 = sitofp i32 %24 to double
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = load i32, ptr %8, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds double, ptr %26, i64 %28
  store double %25, ptr %29, align 8, !tbaa !11
  br label %30

30:                                               ; preds = %20
  %31 = load i32, ptr %8, align 4, !tbaa !9
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %8, align 4, !tbaa !9
  br label %16, !llvm.loop !13

33:                                               ; preds = %16
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %34

34:                                               ; preds = %83, %33
  %35 = load i32, ptr %8, align 4, !tbaa !9
  %36 = load i32, ptr %6, align 4, !tbaa !9
  %37 = icmp ult i32 %35, %36
  br i1 %37, label %38, label %86

38:                                               ; preds = %34
  %39 = load i32, ptr %8, align 4, !tbaa !9
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %9, align 4, !tbaa !9
  br label %41

41:                                               ; preds = %67, %38
  %42 = load i32, ptr %9, align 4, !tbaa !9
  %43 = icmp sgt i32 %42, 0
  br i1 %43, label %44, label %70

44:                                               ; preds = %41
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = load i32, ptr %8, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds double, ptr %45, i64 %47
  %49 = load double, ptr %48, align 8, !tbaa !11
  %50 = fneg double %49
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = load i32, ptr %9, align 4, !tbaa !9
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds double, ptr %51, i64 %53
  %55 = load double, ptr %54, align 8, !tbaa !11
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = load i32, ptr %9, align 4, !tbaa !9
  %58 = sub nsw i32 %57, 1
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds double, ptr %56, i64 %59
  %61 = load double, ptr %60, align 8, !tbaa !11
  %62 = call double @llvm.fmuladd.f64(double %50, double %55, double %61)
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = load i32, ptr %9, align 4, !tbaa !9
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds double, ptr %63, i64 %65
  store double %62, ptr %66, align 8, !tbaa !11
  br label %67

67:                                               ; preds = %44
  %68 = load i32, ptr %9, align 4, !tbaa !9
  %69 = add nsw i32 %68, -1
  store i32 %69, ptr %9, align 4, !tbaa !9
  br label %41, !llvm.loop !15

70:                                               ; preds = %41
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = load i32, ptr %8, align 4, !tbaa !9
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds double, ptr %71, i64 %73
  %75 = load double, ptr %74, align 8, !tbaa !11
  %76 = fneg double %75
  %77 = load ptr, ptr %7, align 8, !tbaa !5
  %78 = load i32, ptr %9, align 4, !tbaa !9
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds double, ptr %77, i64 %79
  %81 = load double, ptr %80, align 8, !tbaa !11
  %82 = fmul double %81, %76
  store double %82, ptr %80, align 8, !tbaa !11
  br label %83

83:                                               ; preds = %70
  %84 = load i32, ptr %8, align 4, !tbaa !9
  %85 = add nsw i32 %84, 1
  store i32 %85, ptr %8, align 4, !tbaa !9
  br label %34, !llvm.loop !16

86:                                               ; preds = %34
  store i32 0, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %87

87:                                               ; preds = %86, %12
  %88 = load i32, ptr %4, align 4
  ret i32 %88
}

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}
!16 = distinct !{!16, !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: readwrite) uwtable
define dso_local noundef i32 @poly_expandroots(ptr nocapture noundef readonly %0, i32 noundef %1, ptr nocapture noundef %2) local_unnamed_addr #1 {
  %4 = icmp eq i32 %1, 0
  br i1 %4, label %8, label %.preheader29.preheader

.preheader29.preheader:                           ; preds = %3
  %5 = add i32 %1, 1
  %wide.trip.count = zext i32 %5 to i64
  %6 = add nsw i64 %wide.trip.count, -1
  %xtraiter = and i64 %wide.trip.count, 3
  %7 = icmp ult i64 %6, 3
  br i1 %7, label %.preheader.preheader.unr-lcssa, label %.preheader29.preheader.new

.preheader29.preheader.new:                       ; preds = %.preheader29.preheader
  %unroll_iter = and i64 %wide.trip.count, 4294967292
  br label %.preheader29

8:                                                ; preds = %3
  store double 0.000000e+00, ptr %2, align 8, !tbaa !5
  br label %.loopexit

.preheader29:                                     ; preds = %.preheader29, %.preheader29.preheader.new
  %indvars.iv = phi i64 [ 0, %.preheader29.preheader.new ], [ %indvars.iv.next.3, %.preheader29 ]
  %niter = phi i64 [ 0, %.preheader29.preheader.new ], [ %niter.next.3, %.preheader29 ]
  %9 = icmp eq i64 %indvars.iv, 0
  %10 = uitofp i1 %9 to double
  %11 = getelementptr inbounds double, ptr %2, i64 %indvars.iv
  store double %10, ptr %11, align 8, !tbaa !5
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %12 = getelementptr inbounds double, ptr %2, i64 %indvars.iv.next
  store double 0.000000e+00, ptr %12, align 8, !tbaa !5
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %13 = getelementptr inbounds double, ptr %2, i64 %indvars.iv.next.1
  store double 0.000000e+00, ptr %13, align 8, !tbaa !5
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %14 = getelementptr inbounds double, ptr %2, i64 %indvars.iv.next.2
  store double 0.000000e+00, ptr %14, align 8, !tbaa !5
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %.preheader.preheader.unr-lcssa, label %.preheader29, !llvm.loop !9

.preheader.preheader.unr-lcssa:                   ; preds = %.preheader29, %.preheader29.preheader
  %indvars.iv.unr = phi i64 [ 0, %.preheader29.preheader ], [ %indvars.iv.next.3, %.preheader29 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader.preheader, label %.preheader29.epil

.preheader29.epil:                                ; preds = %.preheader.preheader.unr-lcssa, %.preheader29.epil
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.preheader29.epil ], [ %indvars.iv.unr, %.preheader.preheader.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.preheader29.epil ], [ 0, %.preheader.preheader.unr-lcssa ]
  %15 = icmp eq i64 %indvars.iv.epil, 0
  %16 = uitofp i1 %15 to double
  %17 = getelementptr inbounds double, ptr %2, i64 %indvars.iv.epil
  store double %16, ptr %17, align 8, !tbaa !5
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %.preheader.preheader, label %.preheader29.epil, !llvm.loop !11

.preheader.preheader:                             ; preds = %.preheader29.epil, %.preheader.preheader.unr-lcssa
  %wide.trip.count42 = zext i32 %1 to i64
  %18 = shl nuw nsw i64 %wide.trip.count42, 3
  %scevgep44 = getelementptr i8, ptr %0, i64 %18
  %invariant.gep = getelementptr i8, ptr %2, i64 16
  %bound0 = icmp ugt ptr %scevgep44, %2
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %.loopexit55
  %indvars.iv39 = phi i64 [ 0, %.preheader.preheader ], [ %indvars.iv.next40, %.loopexit55 ]
  %indvars.iv34 = phi i64 [ 1, %.preheader.preheader ], [ %indvars.iv.next35, %.loopexit55 ]
  %19 = getelementptr inbounds double, ptr %0, i64 %indvars.iv39
  %min.iters.check = icmp ult i64 %indvars.iv34, 4
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.memcheck

vector.memcheck:                                  ; preds = %.preheader
  %20 = shl nuw nsw i64 %indvars.iv39, 3
  %gep = getelementptr i8, ptr %invariant.gep, i64 %20
  %bound1 = icmp ugt ptr %gep, %0
  %found.conflict = and i1 %bound0, %bound1
  br i1 %found.conflict, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %indvars.iv34, 9223372036854775804
  %ind.end = and i64 %indvars.iv34, 3
  %21 = load double, ptr %19, align 8, !tbaa !5, !alias.scope !13
  %broadcast.splatinsert45 = insertelement <2 x double> poison, double %21, i64 0
  %22 = shufflevector <2 x double> %broadcast.splatinsert45, <2 x double> poison, <2 x i32> zeroinitializer
  %23 = fneg <2 x double> %22
  %24 = shufflevector <2 x double> %broadcast.splatinsert45, <2 x double> poison, <2 x i32> zeroinitializer
  %25 = fneg <2 x double> %24
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %offset.idx = sub i64 %indvars.iv34, %index
  %26 = getelementptr inbounds double, ptr %2, i64 %offset.idx
  %27 = getelementptr inbounds i8, ptr %26, i64 -8
  %28 = getelementptr inbounds i8, ptr %26, i64 -24
  %wide.load = load <2 x double>, ptr %27, align 8, !tbaa !5, !alias.scope !16, !noalias !13
  %wide.load47 = load <2 x double>, ptr %28, align 8, !tbaa !5, !alias.scope !16, !noalias !13
  %29 = getelementptr i8, ptr %26, i64 -16
  %30 = getelementptr i8, ptr %26, i64 -32
  %wide.load49 = load <2 x double>, ptr %29, align 8, !tbaa !5, !alias.scope !16, !noalias !13
  %wide.load51 = load <2 x double>, ptr %30, align 8, !tbaa !5, !alias.scope !16, !noalias !13
  %reverse53 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %23, <2 x double> %wide.load, <2 x double> %wide.load49)
  store <2 x double> %reverse53, ptr %27, align 8, !tbaa !5, !alias.scope !16, !noalias !13
  %reverse54 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %25, <2 x double> %wide.load47, <2 x double> %wide.load51)
  store <2 x double> %reverse54, ptr %28, align 8, !tbaa !5, !alias.scope !16, !noalias !13
  %index.next = add nuw i64 %index, 4
  %31 = icmp eq i64 %index.next, %n.vec
  br i1 %31, label %middle.block, label %vector.body, !llvm.loop !18

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %indvars.iv34, %n.vec
  br i1 %cmp.n, label %.loopexit55, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %vector.memcheck, %.preheader
  %indvars.iv36.ph = phi i64 [ %indvars.iv34, %vector.memcheck ], [ %indvars.iv34, %.preheader ], [ %ind.end, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv36 = phi i64 [ %indvars.iv.next37, %scalar.ph ], [ %indvars.iv36.ph, %scalar.ph.preheader ]
  %32 = load double, ptr %19, align 8, !tbaa !5
  %33 = fneg double %32
  %34 = getelementptr inbounds double, ptr %2, i64 %indvars.iv36
  %35 = load double, ptr %34, align 8, !tbaa !5
  %36 = getelementptr i8, ptr %34, i64 -8
  %37 = load double, ptr %36, align 8, !tbaa !5
  %38 = tail call double @llvm.fmuladd.f64(double %33, double %35, double %37)
  store double %38, ptr %34, align 8, !tbaa !5
  %indvars.iv.next37 = add nsw i64 %indvars.iv36, -1
  %39 = icmp sgt i64 %indvars.iv36, 1
  br i1 %39, label %scalar.ph, label %.loopexit55, !llvm.loop !21

.loopexit55:                                      ; preds = %scalar.ph, %middle.block
  %indvars.iv.next40 = add nuw nsw i64 %indvars.iv39, 1
  %40 = load double, ptr %19, align 8, !tbaa !5
  %41 = fneg double %40
  %42 = load double, ptr %2, align 8, !tbaa !5
  %43 = fmul double %42, %41
  store double %43, ptr %2, align 8, !tbaa !5
  %indvars.iv.next35 = add nuw nsw i64 %indvars.iv34, 1
  %exitcond43.not = icmp eq i64 %indvars.iv.next40, %wide.trip.count42
  br i1 %exitcond43.not, label %.loopexit, label %.preheader, !llvm.loop !22

.loopexit:                                        ; preds = %.loopexit55, %8
  ret i32 0
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x double> @llvm.fmuladd.v2f64(<2 x double>, <2 x double>, <2 x double>) #2

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

!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, !12}
!12 = !{!"llvm.loop.unroll.disable"}
!13 = !{!14}
!14 = distinct !{!14, !15}
!15 = distinct !{!15, !"LVerDomain"}
!16 = !{!17}
!17 = distinct !{!17, !15}
!18 = distinct !{!18, !10, !19, !20}
!19 = !{!"llvm.loop.isvectorized", i32 1}
!20 = !{!"llvm.loop.unroll.runtime.disable"}
!21 = distinct !{!21, !10, !19}
!22 = distinct !{!22, !10}


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