; LLVM IR from InsightSoftwareConsortium/ITK :: Modules/ThirdParty/VNL/src/vxl/v3p/netlib/linalg (lsqrDense)

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

20:                                               ; preds = %24, %4
  %21 = load ptr, ptr %10, align 8, !tbaa !5
  %22 = load ptr, ptr %11, align 8, !tbaa !5
  %23 = icmp ne ptr %21, %22
  br i1 %23, label %24, label %33

24:                                               ; preds = %20
  %25 = load ptr, ptr %10, align 8, !tbaa !5
  %26 = getelementptr inbounds double, ptr %25, i32 1
  store ptr %26, ptr %10, align 8, !tbaa !5
  %27 = load double, ptr %25, align 8, !tbaa !11
  %28 = load ptr, ptr %12, align 8, !tbaa !5
  %29 = getelementptr inbounds double, ptr %28, i32 1
  store ptr %29, ptr %12, align 8, !tbaa !5
  %30 = load double, ptr %28, align 8, !tbaa !11
  %31 = load double, ptr %9, align 8, !tbaa !11
  %32 = call double @llvm.fmuladd.f64(double %27, double %30, double %31)
  store double %32, ptr %9, align 8, !tbaa !11
  br label %20, !llvm.loop !13

33:                                               ; preds = %20
  %34 = load double, ptr %9, align 8, !tbaa !11
  %35 = load double, ptr %9, align 8, !tbaa !11
  %36 = fadd double %35, %34
  store double %36, ptr %9, align 8, !tbaa !11
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %37, ptr %10, align 8, !tbaa !5
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %38, ptr %12, align 8, !tbaa !5
  %39 = load ptr, ptr %10, align 8, !tbaa !5
  %40 = load i32, ptr %6, align 4, !tbaa !9
  %41 = zext i32 %40 to i64
  %42 = getelementptr inbounds double, ptr %39, i64 %41
  store ptr %42, ptr %11, align 8, !tbaa !5
  br label %43

43:                                               ; preds = %47, %33
  %44 = load ptr, ptr %10, align 8, !tbaa !5
  %45 = load ptr, ptr %11, align 8, !tbaa !5
  %46 = icmp ne ptr %44, %45
  br i1 %46, label %47, label %57

47:                                               ; preds = %43
  %48 = load double, ptr %9, align 8, !tbaa !11
  %49 = load ptr, ptr %10, align 8, !tbaa !5
  %50 = getelementptr inbounds double, ptr %49, i32 1
  store ptr %50, ptr %10, align 8, !tbaa !5
  %51 = load double, ptr %49, align 8, !tbaa !11
  %52 = load ptr, ptr %12, align 8, !tbaa !5
  %53 = getelementptr inbounds double, ptr %52, i32 1
  store ptr %53, ptr %12, align 8, !tbaa !5
  %54 = load double, ptr %52, align 8, !tbaa !11
  %55 = fneg double %48
  %56 = call double @llvm.fmuladd.f64(double %55, double %51, double %54)
  store double %56, ptr %52, align 8, !tbaa !11
  br label %43, !llvm.loop !15

57:                                               ; preds = %43
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 #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++ 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: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @_ZNK9lsqrDense25HouseholderTransformationEjPKdPd(ptr nocapture noundef nonnull readnone align 8 dereferenceable(160) %0, i32 noundef %1, ptr noundef readonly %2, ptr nocapture noundef %3) local_unnamed_addr #1 align 2 {
  %5 = zext i32 %1 to i64
  %6 = getelementptr inbounds double, ptr %2, i64 %5
  %.not25 = icmp eq i32 %1, 0
  br i1 %.not25, label %._crit_edge34, label %.lr.ph

.lr.ph:                                           ; preds = %4, %.lr.ph
  %.028 = phi ptr [ %9, %.lr.ph ], [ %3, %4 ]
  %.02027 = phi ptr [ %7, %.lr.ph ], [ %2, %4 ]
  %.02226 = phi double [ %11, %.lr.ph ], [ 0.000000e+00, %4 ]
  %7 = getelementptr inbounds i8, ptr %.02027, i64 8
  %8 = load double, ptr %.02027, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %.028, i64 8
  %10 = load double, ptr %.028, align 8, !tbaa !5
  %11 = tail call double @llvm.fmuladd.f64(double %8, double %10, double %.02226)
  %.not = icmp eq ptr %7, %6
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph
  br i1 %.not25, label %._crit_edge34, label %.lr.ph33

.lr.ph33:                                         ; preds = %._crit_edge
  %12 = fadd double %11, %11
  %13 = fneg double %12
  %14 = add nuw nsw i64 %5, 2305843009213693951
  %15 = and i64 %14, 2305843009213693951
  %16 = add nuw nsw i64 %15, 1
  %min.iters.check = icmp ult i64 %15, 9
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.memcheck

vector.memcheck:                                  ; preds = %.lr.ph33
  %17 = shl nuw nsw i64 %5, 3
  %scevgep = getelementptr i8, ptr %3, i64 %17
  %scevgep36 = getelementptr i8, ptr %2, i64 %17
  %bound0 = icmp ugt ptr %scevgep36, %3
  %bound1 = icmp ugt ptr %scevgep, %2
  %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 %16, 4611686018427387900
  %18 = shl i64 %n.vec, 3
  %ind.end = getelementptr i8, ptr %3, i64 %18
  %19 = shl i64 %n.vec, 3
  %ind.end37 = getelementptr i8, ptr %2, i64 %19
  %broadcast.splatinsert = insertelement <2 x double> poison, double %13, 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 ]
  %offset.idx = shl i64 %index, 3
  %next.gep = getelementptr i8, ptr %3, i64 %offset.idx
  %offset.idx40 = shl i64 %index, 3
  %next.gep41 = getelementptr i8, ptr %2, i64 %offset.idx40
  %20 = getelementptr i8, ptr %next.gep41, i64 16
  %wide.load = load <2 x double>, ptr %next.gep41, align 8, !tbaa !5, !alias.scope !11
  %wide.load43 = load <2 x double>, ptr %20, align 8, !tbaa !5, !alias.scope !11
  %21 = getelementptr i8, ptr %next.gep, i64 16
  %wide.load44 = load <2 x double>, ptr %next.gep, align 8, !tbaa !5, !alias.scope !14, !noalias !11
  %wide.load45 = load <2 x double>, ptr %21, align 8, !tbaa !5, !alias.scope !14, !noalias !11
  %22 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %broadcast.splat, <2 x double> %wide.load, <2 x double> %wide.load44)
  %23 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %broadcast.splat, <2 x double> %wide.load43, <2 x double> %wide.load45)
  store <2 x double> %22, ptr %next.gep, align 8, !tbaa !5, !alias.scope !14, !noalias !11
  store <2 x double> %23, ptr %21, align 8, !tbaa !5, !alias.scope !14, !noalias !11
  %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 !16

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

scalar.ph.preheader:                              ; preds = %middle.block, %vector.memcheck, %.lr.ph33
  %.131.ph = phi ptr [ %3, %vector.memcheck ], [ %3, %.lr.ph33 ], [ %ind.end, %middle.block ]
  %.12130.ph = phi ptr [ %2, %vector.memcheck ], [ %2, %.lr.ph33 ], [ %ind.end37, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %.131 = phi ptr [ %27, %scalar.ph ], [ %.131.ph, %scalar.ph.preheader ]
  %.12130 = phi ptr [ %25, %scalar.ph ], [ %.12130.ph, %scalar.ph.preheader ]
  %25 = getelementptr inbounds i8, ptr %.12130, i64 8
  %26 = load double, ptr %.12130, align 8, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %.131, i64 8
  %28 = load double, ptr %.131, align 8, !tbaa !5
  %29 = tail call double @llvm.fmuladd.f64(double %13, double %26, double %28)
  store double %29, ptr %.131, align 8, !tbaa !5
  %.not24 = icmp eq ptr %25, %6
  br i1 %.not24, label %._crit_edge34, label %scalar.ph, !llvm.loop !19

._crit_edge34:                                    ; preds = %scalar.ph, %middle.block, %4, %._crit_edge
  ret void
}

; 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 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12}
!12 = distinct !{!12, !13}
!13 = distinct !{!13, !"LVerDomain"}
!14 = !{!15}
!15 = distinct !{!15, !13}
!16 = distinct !{!16, !10, !17, !18}
!17 = !{!"llvm.loop.isvectorized", i32 1}
!18 = !{!"llvm.loop.unroll.runtime.disable"}
!19 = distinct !{!19, !10, !17}


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