; LLVM IR from tivole/Numerary :: src/interpolation.ll (ZN8numerary8Numerary19lagrange_polynomialEPdS1_RKdRKi)

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

14:                                               ; preds = %67, %4
  %15 = load i32, ptr %11, align 4, !tbaa !11
  %16 = load ptr, ptr %8, align 8, !tbaa !5
  %17 = load i32, ptr %16, align 4, !tbaa !11
  %18 = icmp slt i32 %15, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %14
  store i32 2, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  br label %70

20:                                               ; preds = %14
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = load i32, ptr %11, align 4, !tbaa !11
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds double, ptr %21, i64 %23
  %25 = load double, ptr %24, align 8, !tbaa !9
  store double %25, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  store i32 0, ptr %13, align 4, !tbaa !11
  br label %26

26:                                               ; preds = %60, %20
  %27 = load i32, ptr %13, align 4, !tbaa !11
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  %29 = load i32, ptr %28, align 4, !tbaa !11
  %30 = icmp slt i32 %27, %29
  br i1 %30, label %32, label %31

31:                                               ; preds = %26
  store i32 5, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  br label %63

32:                                               ; preds = %26
  %33 = load i32, ptr %13, align 4, !tbaa !11
  %34 = load i32, ptr %11, align 4, !tbaa !11
  %35 = icmp ne i32 %33, %34
  br i1 %35, label %36, label %59

36:                                               ; preds = %32
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = load double, ptr %37, align 8, !tbaa !9
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = load i32, ptr %13, align 4, !tbaa !11
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds double, ptr %39, i64 %41
  %43 = load double, ptr %42, align 8, !tbaa !9
  %44 = fsub double %38, %43
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = load i32, ptr %11, align 4, !tbaa !11
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds double, ptr %45, i64 %47
  %49 = load double, ptr %48, align 8, !tbaa !9
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = load i32, ptr %13, align 4, !tbaa !11
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds double, ptr %50, i64 %52
  %54 = load double, ptr %53, align 8, !tbaa !9
  %55 = fsub double %49, %54
  %56 = fdiv double %44, %55
  %57 = load double, ptr %9, align 8, !tbaa !9
  %58 = fmul double %57, %56
  store double %58, ptr %9, align 8, !tbaa !9
  br label %59

59:                                               ; preds = %36, %32
  br label %60

60:                                               ; preds = %59
  %61 = load i32, ptr %13, align 4, !tbaa !11
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %13, align 4, !tbaa !11
  br label %26, !llvm.loop !13

63:                                               ; preds = %31
  %64 = load double, ptr %9, align 8, !tbaa !9
  %65 = load double, ptr %10, align 8, !tbaa !9
  %66 = fadd double %65, %64
  store double %66, ptr %10, align 8, !tbaa !9
  br label %67

67:                                               ; preds = %63
  %68 = load i32, ptr %11, align 4, !tbaa !11
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %11, align 4, !tbaa !11
  br label %14, !llvm.loop !15

70:                                               ; preds = %19
  %71 = load double, ptr %10, align 8, !tbaa !9
  store i32 1, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  ret double %71
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

attributes #0 = { mustprogress 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !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 nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local noundef double @_ZN8numerary8Numerary19lagrange_polynomialEPdS1_RKdRKi(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef nonnull readonly align 8 dereferenceable(8) %2, ptr nocapture noundef nonnull readonly align 4 dereferenceable(4) %3) local_unnamed_addr #0 align 2 {
  %5 = load i32, ptr %3, align 4, !tbaa !5
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph28, label %._crit_edge29

.lr.ph28:                                         ; preds = %4
  %7 = load double, ptr %2, align 8
  %wide.trip.count35 = zext nneg i32 %5 to i64
  %xtraiter = and i64 %wide.trip.count35, 1
  %8 = icmp eq i32 %5, 1
  %unroll_iter = and i64 %wide.trip.count35, 2147483646
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.lr.ph.us

.lr.ph.us:                                        ; preds = %._crit_edge.us, %.lr.ph28
  %indvars.iv32 = phi i64 [ %indvars.iv.next33, %._crit_edge.us ], [ 0, %.lr.ph28 ]
  %.02125.us = phi double [ %38, %._crit_edge.us ], [ 0.000000e+00, %.lr.ph28 ]
  %9 = getelementptr inbounds double, ptr %1, i64 %indvars.iv32
  %10 = load double, ptr %9, align 8, !tbaa !9
  %11 = getelementptr inbounds double, ptr %0, i64 %indvars.iv32
  br i1 %8, label %._crit_edge.us.unr-lcssa, label %.lr.ph.us.new

.lr.ph.us.new:                                    ; preds = %.lr.ph.us, %29
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %29 ], [ 0, %.lr.ph.us ]
  %.02223.us = phi double [ %.1.us.1, %29 ], [ %10, %.lr.ph.us ]
  %niter = phi i64 [ %niter.next.1, %29 ], [ 0, %.lr.ph.us ]
  %.not.us = icmp eq i64 %indvars.iv, %indvars.iv32
  br i1 %.not.us, label %20, label %12

12:                                               ; preds = %.lr.ph.us.new
  %13 = getelementptr inbounds double, ptr %0, i64 %indvars.iv
  %14 = load double, ptr %13, align 8, !tbaa !9
  %15 = fsub double %7, %14
  %16 = load double, ptr %11, align 8, !tbaa !9
  %17 = fsub double %16, %14
  %18 = fdiv double %15, %17
  %19 = fmul double %.02223.us, %18
  br label %20

20:                                               ; preds = %12, %.lr.ph.us.new
  %.1.us = phi double [ %19, %12 ], [ %.02223.us, %.lr.ph.us.new ]
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %.not.us.1 = icmp eq i64 %indvars.iv.next, %indvars.iv32
  br i1 %.not.us.1, label %29, label %21

21:                                               ; preds = %20
  %22 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.next
  %23 = load double, ptr %22, align 8, !tbaa !9
  %24 = fsub double %7, %23
  %25 = load double, ptr %11, align 8, !tbaa !9
  %26 = fsub double %25, %23
  %27 = fdiv double %24, %26
  %28 = fmul double %.1.us, %27
  br label %29

29:                                               ; preds = %21, %20
  %.1.us.1 = phi double [ %28, %21 ], [ %.1.us, %20 ]
  %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.us.unr-lcssa, label %.lr.ph.us.new, !llvm.loop !11

._crit_edge.us.unr-lcssa:                         ; preds = %29, %.lr.ph.us
  %.1.us.lcssa.ph = phi double [ poison, %.lr.ph.us ], [ %.1.us.1, %29 ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.us ], [ %indvars.iv.next.1, %29 ]
  %.02223.us.unr = phi double [ %10, %.lr.ph.us ], [ %.1.us.1, %29 ]
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.us.unr-lcssa
  %.not.us.epil = icmp eq i64 %indvars.iv.unr, %indvars.iv32
  br i1 %.not.us.epil, label %._crit_edge.us, label %30

30:                                               ; preds = %.epil.preheader
  %31 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.unr
  %32 = load double, ptr %31, align 8, !tbaa !9
  %33 = fsub double %7, %32
  %34 = load double, ptr %11, align 8, !tbaa !9
  %35 = fsub double %34, %32
  %36 = fdiv double %33, %35
  %37 = fmul double %.02223.us.unr, %36
  br label %._crit_edge.us

._crit_edge.us:                                   ; preds = %.epil.preheader, %30, %._crit_edge.us.unr-lcssa
  %.1.us.lcssa = phi double [ %.1.us.lcssa.ph, %._crit_edge.us.unr-lcssa ], [ %37, %30 ], [ %.02223.us.unr, %.epil.preheader ]
  %38 = fadd double %.02125.us, %.1.us.lcssa
  %indvars.iv.next33 = add nuw nsw i64 %indvars.iv32, 1
  %exitcond36.not = icmp eq i64 %indvars.iv.next33, %wide.trip.count35
  br i1 %exitcond36.not, label %._crit_edge29, label %.lr.ph.us, !llvm.loop !13

._crit_edge29:                                    ; preds = %._crit_edge.us, %4
  %.021.lcssa = phi double [ 0.000000e+00, %4 ], [ %38, %._crit_edge.us ]
  ret double %.021.lcssa
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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