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

10:                                               ; preds = %2
  %11 = load ptr, ptr %5, align 8, !tbaa !9
  %12 = getelementptr inbounds double, ptr %11, i64 0
  store double 0.000000e+00, ptr %12, align 8, !tbaa !11
  store i32 0, ptr %3, align 4
  br label %67

13:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %28, %13
  %15 = load i32, ptr %6, align 4, !tbaa !5
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = icmp ule i32 %15, %16
  br i1 %17, label %18, label %31

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

28:                                               ; preds = %18
  %29 = load i32, ptr %6, align 4, !tbaa !5
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %6, align 4, !tbaa !5
  br label %14, !llvm.loop !13

31:                                               ; preds = %14
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %63, %31
  %33 = load i32, ptr %6, align 4, !tbaa !5
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = icmp ult i32 %33, %34
  br i1 %35, label %36, label %66

36:                                               ; preds = %32
  %37 = load i32, ptr %6, align 4, !tbaa !5
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %7, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %59, %36
  %40 = load i32, ptr %7, align 4, !tbaa !5
  %41 = icmp sgt i32 %40, 0
  br i1 %41, label %42, label %62

42:                                               ; preds = %39
  %43 = load ptr, ptr %5, align 8, !tbaa !9
  %44 = load i32, ptr %7, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds double, ptr %43, i64 %45
  %47 = load double, ptr %46, align 8, !tbaa !11
  %48 = load ptr, ptr %5, align 8, !tbaa !9
  %49 = load i32, ptr %7, align 4, !tbaa !5
  %50 = sub nsw i32 %49, 1
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds double, ptr %48, i64 %51
  %53 = load double, ptr %52, align 8, !tbaa !11
  %54 = fadd double %47, %53
  %55 = load ptr, ptr %5, align 8, !tbaa !9
  %56 = load i32, ptr %7, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds double, ptr %55, i64 %57
  store double %54, ptr %58, align 8, !tbaa !11
  br label %59

59:                                               ; preds = %42
  %60 = load i32, ptr %7, align 4, !tbaa !5
  %61 = add nsw i32 %60, -1
  store i32 %61, ptr %7, align 4, !tbaa !5
  br label %39, !llvm.loop !15

62:                                               ; preds = %39
  br label %63

63:                                               ; preds = %62
  %64 = load i32, ptr %6, align 4, !tbaa !5
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %6, align 4, !tbaa !5
  br label %32, !llvm.loop !16

66:                                               ; preds = %32
  store i32 0, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %67

67:                                               ; preds = %66, %10
  %68 = load i32, ptr %3, align 4
  ret i32 %68
}

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 = { 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"}
!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: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local noundef i32 @poly_expandbinomial(i32 noundef %0, ptr nocapture noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq i32 %0, 0
  br i1 %3, label %7, label %.preheader24.preheader

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

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

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

.preheader24:                                     ; preds = %.preheader24, %.preheader24.preheader.new
  %indvars.iv = phi i64 [ 0, %.preheader24.preheader.new ], [ %indvars.iv.next.3, %.preheader24 ]
  %niter = phi i64 [ 0, %.preheader24.preheader.new ], [ %niter.next.3, %.preheader24 ]
  %8 = icmp eq i64 %indvars.iv, 0
  %9 = uitofp i1 %8 to double
  %10 = getelementptr inbounds double, ptr %1, i64 %indvars.iv
  store double %9, ptr %10, align 8, !tbaa !5
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %11 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.next
  store double 0.000000e+00, ptr %11, align 8, !tbaa !5
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %12 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.next.1
  store double 0.000000e+00, ptr %12, align 8, !tbaa !5
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %13 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.next.2
  store double 0.000000e+00, ptr %13, 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 %.preheader24, !llvm.loop !9

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

.preheader24.epil:                                ; preds = %.preheader.preheader.unr-lcssa, %.preheader24.epil
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.preheader24.epil ], [ %indvars.iv.unr, %.preheader.preheader.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.preheader24.epil ], [ 0, %.preheader.preheader.unr-lcssa ]
  %14 = icmp eq i64 %indvars.iv.epil, 0
  %15 = uitofp i1 %14 to double
  %16 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.epil
  store double %15, ptr %16, 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 %.preheader24.epil, !llvm.loop !11

.preheader.preheader:                             ; preds = %.preheader24.epil, %.preheader.preheader.unr-lcssa
  br label %.preheader

.loopexit:                                        ; preds = %scalar.ph, %scalar.ph.1, %scalar.ph.2, %middle.block
  %indvars.iv.next30 = add nuw nsw i64 %indvars.iv29, 1
  %exitcond35.not = icmp eq i64 %indvars.iv.next30, %wide.trip.count
  br i1 %exitcond35.not, label %.loopexit23, label %.preheader, !llvm.loop !13

.preheader:                                       ; preds = %.preheader.preheader, %.loopexit
  %indvars.iv29 = phi i64 [ %indvars.iv.next30, %.loopexit ], [ 1, %.preheader.preheader ]
  %min.iters.check = icmp ult i64 %indvars.iv29, 4
  br i1 %min.iters.check, label %scalar.ph, label %vector.ph

vector.ph:                                        ; preds = %.preheader
  %n.vec = and i64 %indvars.iv29, 9223372036854775804
  %ind.end = and i64 %indvars.iv29, 3
  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.iv29, %index
  %17 = getelementptr inbounds double, ptr %1, i64 %offset.idx
  %18 = getelementptr inbounds i8, ptr %17, i64 -8
  %19 = getelementptr inbounds i8, ptr %17, i64 -24
  %wide.load = load <2 x double>, ptr %18, align 8, !tbaa !5
  %wide.load36 = load <2 x double>, ptr %19, align 8, !tbaa !5
  %20 = getelementptr i8, ptr %17, i64 -16
  %21 = getelementptr i8, ptr %17, i64 -32
  %wide.load38 = load <2 x double>, ptr %20, align 8, !tbaa !5
  %wide.load40 = load <2 x double>, ptr %21, align 8, !tbaa !5
  %22 = fadd <2 x double> %wide.load, %wide.load38
  %23 = fadd <2 x double> %wide.load36, %wide.load40
  store <2 x double> %22, ptr %18, align 8, !tbaa !5
  store <2 x double> %23, ptr %19, align 8, !tbaa !5
  %index.next = add nuw i64 %index, 4
  %24 = icmp eq i64 %index.next, %n.vec
  br i1 %24, label %middle.block, label %vector.body, !llvm.loop !14

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

scalar.ph:                                        ; preds = %.preheader, %middle.block
  %indvars.iv31.ph = phi i64 [ %indvars.iv29, %.preheader ], [ %ind.end, %middle.block ]
  %25 = getelementptr inbounds double, ptr %1, i64 %indvars.iv31.ph
  %26 = load double, ptr %25, align 8, !tbaa !5
  %27 = getelementptr i8, ptr %25, i64 -8
  %28 = load double, ptr %27, align 8, !tbaa !5
  %29 = fadd double %26, %28
  store double %29, ptr %25, align 8, !tbaa !5
  %30 = icmp ugt i64 %indvars.iv31.ph, 1
  br i1 %30, label %scalar.ph.1, label %.loopexit, !llvm.loop !17

scalar.ph.1:                                      ; preds = %scalar.ph
  %31 = getelementptr double, ptr %1, i64 %indvars.iv31.ph
  %32 = getelementptr i8, ptr %31, i64 -8
  %33 = load double, ptr %32, align 8, !tbaa !5
  %34 = getelementptr i8, ptr %31, i64 -16
  %35 = load double, ptr %34, align 8, !tbaa !5
  %36 = fadd double %33, %35
  store double %36, ptr %32, align 8, !tbaa !5
  %37 = icmp eq i64 %indvars.iv31.ph, 3
  br i1 %37, label %scalar.ph.2, label %.loopexit, !llvm.loop !17

scalar.ph.2:                                      ; preds = %scalar.ph.1
  %38 = getelementptr double, ptr %1, i64 %indvars.iv31.ph
  %39 = getelementptr i8, ptr %38, i64 -16
  %40 = load double, ptr %39, align 8, !tbaa !5
  %41 = getelementptr i8, ptr %38, i64 -24
  %42 = load double, ptr %41, align 8, !tbaa !5
  %43 = fadd double %40, %42
  store double %43, ptr %39, align 8, !tbaa !5
  br label %.loopexit

.loopexit23:                                      ; preds = %.loopexit, %7
  ret i32 0
}

attributes #0 = { 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" }

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


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