; LLVM IR from MRPT/mrpt :: libs/math/src/CSparse (cs_house)

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

14:                                               ; preds = %3
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %18, label %17

17:                                               ; preds = %14, %3
  store double -1.000000e+00, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %99

18:                                               ; preds = %14
  store i32 1, ptr %10, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %36, %18
  %20 = load i32, ptr %10, align 4, !tbaa !9
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = icmp slt i32 %20, %21
  br i1 %22, label %23, label %39

23:                                               ; preds = %19
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = load i32, ptr %10, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds double, ptr %24, i64 %26
  %28 = load double, ptr %27, align 8, !tbaa !11
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = load i32, ptr %10, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds double, ptr %29, i64 %31
  %33 = load double, ptr %32, align 8, !tbaa !11
  %34 = load double, ptr %9, align 8, !tbaa !11
  %35 = call double @llvm.fmuladd.f64(double %28, double %33, double %34)
  store double %35, ptr %9, align 8, !tbaa !11
  br label %36

36:                                               ; preds = %23
  %37 = load i32, ptr %10, align 4, !tbaa !9
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %10, align 4, !tbaa !9
  br label %19, !llvm.loop !13

39:                                               ; preds = %19
  %40 = load double, ptr %9, align 8, !tbaa !11
  %41 = fcmp oeq double %40, 0.000000e+00
  br i1 %41, label %42, label %57

42:                                               ; preds = %39
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds double, ptr %43, i64 0
  %45 = load double, ptr %44, align 8, !tbaa !11
  %46 = call double @llvm.fabs.f64(double %45)
  store double %46, ptr %8, align 8, !tbaa !11
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds double, ptr %47, i64 0
  %49 = load double, ptr %48, align 8, !tbaa !11
  %50 = fcmp ole double %49, 0.000000e+00
  %51 = zext i1 %50 to i64
  %52 = select i1 %50, i32 2, i32 0
  %53 = sitofp i32 %52 to double
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  store double %53, ptr %54, align 8, !tbaa !11
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds double, ptr %55, i64 0
  store double 1.000000e+00, ptr %56, align 8, !tbaa !11
  br label %97

57:                                               ; preds = %39
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds double, ptr %58, i64 0
  %60 = load double, ptr %59, align 8, !tbaa !11
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = getelementptr inbounds double, ptr %61, i64 0
  %63 = load double, ptr %62, align 8, !tbaa !11
  %64 = load double, ptr %9, align 8, !tbaa !11
  %65 = call double @llvm.fmuladd.f64(double %60, double %63, double %64)
  %66 = call double @sqrt(double noundef %65) #4
  store double %66, ptr %8, align 8, !tbaa !11
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = getelementptr inbounds double, ptr %67, i64 0
  %69 = load double, ptr %68, align 8, !tbaa !11
  %70 = fcmp ole double %69, 0.000000e+00
  br i1 %70, label %71, label %77

71:                                               ; preds = %57
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = getelementptr inbounds double, ptr %72, i64 0
  %74 = load double, ptr %73, align 8, !tbaa !11
  %75 = load double, ptr %8, align 8, !tbaa !11
  %76 = fsub double %74, %75
  br label %86

77:                                               ; preds = %57
  %78 = load double, ptr %9, align 8, !tbaa !11
  %79 = fneg double %78
  %80 = load ptr, ptr %5, align 8, !tbaa !5
  %81 = getelementptr inbounds double, ptr %80, i64 0
  %82 = load double, ptr %81, align 8, !tbaa !11
  %83 = load double, ptr %8, align 8, !tbaa !11
  %84 = fadd double %82, %83
  %85 = fdiv double %79, %84
  br label %86

86:                                               ; preds = %77, %71
  %87 = phi double [ %76, %71 ], [ %85, %77 ]
  %88 = load ptr, ptr %5, align 8, !tbaa !5
  %89 = getelementptr inbounds double, ptr %88, i64 0
  store double %87, ptr %89, align 8, !tbaa !11
  %90 = load double, ptr %8, align 8, !tbaa !11
  %91 = load ptr, ptr %5, align 8, !tbaa !5
  %92 = getelementptr inbounds double, ptr %91, i64 0
  %93 = load double, ptr %92, align 8, !tbaa !11
  %94 = fmul double %90, %93
  %95 = fdiv double -1.000000e+00, %94
  %96 = load ptr, ptr %6, align 8, !tbaa !5
  store double %95, ptr %96, align 8, !tbaa !11
  br label %97

97:                                               ; preds = %86, %42
  %98 = load double, ptr %8, align 8, !tbaa !11
  store double %98, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %99

99:                                               ; preds = %97, %17
  call void @llvm.lifetime.end.p0(i64 4, 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
  %100 = load double, ptr %4, align 8
  ret double %100
}

; 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 speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

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

; Function Attrs: nounwind
declare double @sqrt(double noundef) #3

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

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


; 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 nounwind memory(write, argmem: readwrite) uwtable
define dso_local double @cs_house(ptr noundef %0, ptr noundef writeonly %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = icmp ne ptr %0, null
  %5 = icmp ne ptr %1, null
  %or.cond = and i1 %4, %5
  br i1 %or.cond, label %.preheader, label %40

.preheader:                                       ; preds = %3
  %6 = icmp sgt i32 %2, 1
  br i1 %6, label %.lr.ph.preheader, label %._crit_edge.thread

.lr.ph.preheader:                                 ; preds = %.preheader
  %wide.trip.count = zext nneg i32 %2 to i64
  %7 = add nsw i64 %wide.trip.count, -1
  %8 = add nsw i64 %wide.trip.count, -2
  %xtraiter = and i64 %7, 3
  %9 = icmp ult i64 %8, 3
  br i1 %9, label %._crit_edge.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %7, -4
  %invariant.gep = getelementptr inbounds i8, ptr %0, i64 8
  %invariant.gep43 = getelementptr inbounds i8, ptr %0, i64 16
  %invariant.gep45 = getelementptr inbounds i8, ptr %0, i64 24
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader.new ], [ %indvars.iv.next.3, %.lr.ph ]
  %.03036 = phi double [ 0.000000e+00, %.lr.ph.preheader.new ], [ %18, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %10 = getelementptr inbounds double, ptr %0, i64 %indvars.iv
  %11 = load double, ptr %10, align 8, !tbaa !5
  %12 = tail call double @llvm.fmuladd.f64(double %11, double %11, double %.03036)
  %gep = getelementptr inbounds double, ptr %invariant.gep, i64 %indvars.iv
  %13 = load double, ptr %gep, align 8, !tbaa !5
  %14 = tail call double @llvm.fmuladd.f64(double %13, double %13, double %12)
  %gep44 = getelementptr inbounds double, ptr %invariant.gep43, i64 %indvars.iv
  %15 = load double, ptr %gep44, align 8, !tbaa !5
  %16 = tail call double @llvm.fmuladd.f64(double %15, double %15, double %14)
  %gep46 = getelementptr inbounds double, ptr %invariant.gep45, i64 %indvars.iv
  %17 = load double, ptr %gep46, align 8, !tbaa !5
  %18 = tail call double @llvm.fmuladd.f64(double %17, double %17, double %16)
  %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 %._crit_edge.unr-lcssa, label %.lr.ph, !llvm.loop !9

._crit_edge.unr-lcssa:                            ; preds = %.lr.ph, %.lr.ph.preheader
  %.lcssa.ph = phi double [ poison, %.lr.ph.preheader ], [ %18, %.lr.ph ]
  %indvars.iv.unr = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next.3, %.lr.ph ]
  %.03036.unr = phi double [ 0.000000e+00, %.lr.ph.preheader ], [ %18, %.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.unr-lcssa, %.lr.ph.epil
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.lr.ph.epil ], [ %indvars.iv.unr, %._crit_edge.unr-lcssa ]
  %.03036.epil = phi double [ %21, %.lr.ph.epil ], [ %.03036.unr, %._crit_edge.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %._crit_edge.unr-lcssa ]
  %19 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.epil
  %20 = load double, ptr %19, align 8, !tbaa !5
  %21 = tail call double @llvm.fmuladd.f64(double %20, double %20, double %.03036.epil)
  %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 %._crit_edge, label %.lr.ph.epil, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph.epil, %._crit_edge.unr-lcssa
  %.lcssa = phi double [ %.lcssa.ph, %._crit_edge.unr-lcssa ], [ %21, %.lr.ph.epil ]
  %22 = fcmp oeq double %.lcssa, 0.000000e+00
  br i1 %22, label %._crit_edge.thread, label %27

._crit_edge.thread:                               ; preds = %.preheader, %._crit_edge
  %23 = load double, ptr %0, align 8, !tbaa !5
  %24 = tail call double @llvm.fabs.f64(double %23)
  %25 = fcmp ole double %23, 0.000000e+00
  %26 = select i1 %25, double 2.000000e+00, double 0.000000e+00
  store double %26, ptr %1, align 8, !tbaa !5
  store double 1.000000e+00, ptr %0, align 8, !tbaa !5
  br label %40

27:                                               ; preds = %._crit_edge
  %28 = load double, ptr %0, align 8, !tbaa !5
  %29 = tail call double @llvm.fmuladd.f64(double %28, double %28, double %.lcssa)
  %30 = tail call double @sqrt(double noundef %29) #3
  %31 = load double, ptr %0, align 8, !tbaa !5
  %32 = fcmp ugt double %31, 0.000000e+00
  %33 = fsub double %31, %30
  %34 = fneg double %.lcssa
  %35 = fadd double %30, %31
  %36 = fdiv double %34, %35
  %37 = select i1 %32, double %36, double %33
  store double %37, ptr %0, align 8, !tbaa !5
  %38 = fmul double %30, %37
  %39 = fdiv double -1.000000e+00, %38
  store double %39, ptr %1, align 8, !tbaa !5
  br label %40

40:                                               ; preds = %._crit_edge.thread, %27, %3
  %.032 = phi double [ -1.000000e+00, %3 ], [ %24, %._crit_edge.thread ], [ %30, %27 ]
  ret double %.032
}

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

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sqrt(double noundef) local_unnamed_addr #2

attributes #0 = { nofree nounwind memory(write, 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 #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { mustprogress nofree nounwind willreturn memory(write) "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 = !{!"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"}


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