; LLVM IR from tivole/Numerary :: src/regression.ll (ZN8numerary8Numerary17linear_regressionEPdS1_RKi)

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

14:                                               ; preds = %58, %3
  %15 = load i32, ptr %7, align 4, !tbaa !11
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = load i32, ptr %16, align 4, !tbaa !11
  %18 = icmp slt i32 %15, %17
  br i1 %18, label %19, label %61

19:                                               ; preds = %14
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = load i32, ptr %7, align 4, !tbaa !11
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds double, ptr %20, i64 %22
  %24 = load double, ptr %23, align 8, !tbaa !9
  %25 = load double, ptr %8, align 8, !tbaa !9
  %26 = fadd double %25, %24
  store double %26, ptr %8, align 8, !tbaa !9
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = load i32, ptr %7, align 4, !tbaa !11
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds double, ptr %27, i64 %29
  %31 = load double, ptr %30, align 8, !tbaa !9
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = load i32, ptr %7, align 4, !tbaa !11
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds double, ptr %32, i64 %34
  %36 = load double, ptr %35, align 8, !tbaa !9
  %37 = load double, ptr %11, align 8, !tbaa !9
  %38 = call double @llvm.fmuladd.f64(double %31, double %36, double %37)
  store double %38, ptr %11, align 8, !tbaa !9
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = load i32, ptr %7, 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 = load double, ptr %9, align 8, !tbaa !9
  %45 = fadd double %44, %43
  store double %45, ptr %9, align 8, !tbaa !9
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = load i32, ptr %7, align 4, !tbaa !11
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds double, ptr %46, i64 %48
  %50 = load double, ptr %49, align 8, !tbaa !9
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = load i32, ptr %7, align 4, !tbaa !11
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds double, ptr %51, i64 %53
  %55 = load double, ptr %54, align 8, !tbaa !9
  %56 = load double, ptr %10, align 8, !tbaa !9
  %57 = call double @llvm.fmuladd.f64(double %50, double %55, double %56)
  store double %57, ptr %10, align 8, !tbaa !9
  br label %58

58:                                               ; preds = %19
  %59 = load i32, ptr %7, align 4, !tbaa !11
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %7, align 4, !tbaa !11
  br label %14, !llvm.loop !13

61:                                               ; preds = %14
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = load i32, ptr %62, align 4, !tbaa !11
  %64 = sitofp i32 %63 to double
  %65 = load double, ptr %10, align 8, !tbaa !9
  %66 = load double, ptr %8, align 8, !tbaa !9
  %67 = load double, ptr %9, align 8, !tbaa !9
  %68 = fmul double %66, %67
  %69 = fneg double %68
  %70 = call double @llvm.fmuladd.f64(double %64, double %65, double %69)
  %71 = load ptr, ptr %6, align 8, !tbaa !5
  %72 = load i32, ptr %71, align 4, !tbaa !11
  %73 = sitofp i32 %72 to double
  %74 = load double, ptr %11, align 8, !tbaa !9
  %75 = load double, ptr %8, align 8, !tbaa !9
  %76 = load double, ptr %8, align 8, !tbaa !9
  %77 = fmul double %75, %76
  %78 = fneg double %77
  %79 = call double @llvm.fmuladd.f64(double %73, double %74, double %78)
  %80 = fdiv double %70, %79
  %81 = load ptr, ptr %12, align 8, !tbaa !5
  %82 = getelementptr inbounds double, ptr %81, i64 0
  store double %80, ptr %82, align 8, !tbaa !9
  %83 = load double, ptr %9, align 8, !tbaa !9
  %84 = load ptr, ptr %12, align 8, !tbaa !5
  %85 = getelementptr inbounds double, ptr %84, i64 0
  %86 = load double, ptr %85, align 8, !tbaa !9
  %87 = load double, ptr %8, align 8, !tbaa !9
  %88 = fneg double %86
  %89 = call double @llvm.fmuladd.f64(double %88, double %87, double %83)
  %90 = load ptr, ptr %6, align 8, !tbaa !5
  %91 = load i32, ptr %90, align 4, !tbaa !11
  %92 = sitofp i32 %91 to double
  %93 = fdiv double %89, %92
  %94 = load ptr, ptr %12, align 8, !tbaa !5
  %95 = getelementptr inbounds double, ptr %94, i64 1
  store double %93, ptr %95, align 8, !tbaa !9
  %96 = load ptr, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  ret ptr %96
}

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

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #3

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

attributes #0 = { mustprogress 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 = { nobuiltin allocsize(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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nounwind }
attributes #5 = { builtin allocsize(0) }

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


; 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 uwtable
define dso_local noalias noundef nonnull ptr @_ZN8numerary8Numerary17linear_regressionEPdS1_RKi(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef nonnull readonly align 4 dereferenceable(4) %2) local_unnamed_addr #0 align 2 {
  %4 = tail call noalias noundef nonnull dereferenceable(16) ptr @_Znam(i64 noundef 16) #4
  %5 = load i32, ptr %2, align 4, !tbaa !5
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %3
  %wide.trip.count = zext nneg i32 %5 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %7 = icmp eq i32 %5, 1
  br i1 %7, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %wide.trip.count, 2147483646
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.1, %.lr.ph ]
  %.03539 = phi double [ 0.000000e+00, %.lr.ph.preheader.new ], [ %25, %.lr.ph ]
  %.03638 = phi double [ 0.000000e+00, %.lr.ph.preheader.new ], [ %22, %.lr.ph ]
  %8 = phi <2 x double> [ zeroinitializer, %.lr.ph.preheader.new ], [ %30, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %9 = getelementptr inbounds double, ptr %0, i64 %indvars.iv
  %10 = load double, ptr %9, align 8, !tbaa !9
  %11 = fadd double %.03638, %10
  %12 = getelementptr inbounds double, ptr %1, i64 %indvars.iv
  %13 = load double, ptr %12, align 8, !tbaa !9
  %14 = fadd double %.03539, %13
  %15 = insertelement <2 x double> poison, double %10, i64 0
  %16 = shufflevector <2 x double> %15, <2 x double> poison, <2 x i32> zeroinitializer
  %17 = insertelement <2 x double> poison, double %13, i64 0
  %18 = insertelement <2 x double> %17, double %10, i64 1
  %19 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %16, <2 x double> %18, <2 x double> %8)
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %20 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.next
  %21 = load double, ptr %20, align 8, !tbaa !9
  %22 = fadd double %11, %21
  %23 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.next
  %24 = load double, ptr %23, align 8, !tbaa !9
  %25 = fadd double %14, %24
  %26 = insertelement <2 x double> poison, double %21, i64 0
  %27 = shufflevector <2 x double> %26, <2 x double> poison, <2 x i32> zeroinitializer
  %28 = insertelement <2 x double> poison, double %24, i64 0
  %29 = insertelement <2 x double> %28, double %21, i64 1
  %30 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %27, <2 x double> %29, <2 x double> %19)
  %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.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !11

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %.lcssa58.ph = phi double [ poison, %.lr.ph.preheader ], [ %22, %.lr.ph ]
  %.lcssa57.ph = phi double [ poison, %.lr.ph.preheader ], [ %25, %.lr.ph ]
  %.lcssa.ph = phi <2 x double> [ poison, %.lr.ph.preheader ], [ %30, %.lr.ph ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next.1, %.lr.ph ]
  %.03539.unr = phi double [ 0.000000e+00, %.lr.ph.preheader ], [ %25, %.lr.ph ]
  %.03638.unr = phi double [ 0.000000e+00, %.lr.ph.preheader ], [ %22, %.lr.ph ]
  %.unr = phi <2 x double> [ zeroinitializer, %.lr.ph.preheader ], [ %30, %.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.loopexit.unr-lcssa
  %31 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.unr
  %32 = load double, ptr %31, align 8, !tbaa !9
  %33 = fadd double %.03638.unr, %32
  %34 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.unr
  %35 = load double, ptr %34, align 8, !tbaa !9
  %36 = fadd double %.03539.unr, %35
  %37 = insertelement <2 x double> poison, double %32, i64 0
  %38 = shufflevector <2 x double> %37, <2 x double> poison, <2 x i32> zeroinitializer
  %39 = insertelement <2 x double> poison, double %35, i64 0
  %40 = insertelement <2 x double> %39, double %32, i64 1
  %41 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %38, <2 x double> %40, <2 x double> %.unr)
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.epil, %._crit_edge.loopexit.unr-lcssa, %3
  %.036.lcssa = phi double [ 0.000000e+00, %3 ], [ %.lcssa58.ph, %._crit_edge.loopexit.unr-lcssa ], [ %33, %.lr.ph.epil ]
  %.035.lcssa = phi double [ 0.000000e+00, %3 ], [ %.lcssa57.ph, %._crit_edge.loopexit.unr-lcssa ], [ %36, %.lr.ph.epil ]
  %42 = phi <2 x double> [ zeroinitializer, %3 ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %41, %.lr.ph.epil ]
  %43 = sitofp i32 %5 to double
  %44 = fneg double %.036.lcssa
  %45 = fmul double %.035.lcssa, %44
  %46 = extractelement <2 x double> %42, i64 0
  %47 = tail call double @llvm.fmuladd.f64(double %43, double %46, double %45)
  %48 = fmul double %.036.lcssa, %44
  %49 = extractelement <2 x double> %42, i64 1
  %50 = tail call double @llvm.fmuladd.f64(double %43, double %49, double %48)
  %51 = fdiv double %47, %50
  store double %51, ptr %4, align 8, !tbaa !9
  %52 = fneg double %51
  %53 = tail call double @llvm.fmuladd.f64(double %52, double %.036.lcssa, double %.035.lcssa)
  %54 = fdiv double %53, %43
  %55 = getelementptr inbounds i8, ptr %4, i64 8
  store double %54, ptr %55, align 8, !tbaa !9
  ret ptr %4
}

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #1

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

; 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>) #3

attributes #0 = { mustprogress 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 = { nobuiltin allocsize(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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { builtin allocsize(0) }

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


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