; LLVM IR from jgaeddert/liquid-dsp :: src/matrix/src (matrix)

; 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

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

13:                                               ; preds = %42, %4
  %14 = load i32, ptr %9, align 4, !tbaa !9
  %15 = load i32, ptr %7, align 4, !tbaa !9
  %16 = icmp ult i32 %14, %15
  br i1 %16, label %17, label %45

17:                                               ; preds = %13
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = load i32, ptr %9, align 4, !tbaa !9
  %20 = zext i32 %19 to i64
  %21 = getelementptr inbounds double, ptr %18, i64 %20
  %22 = load double, ptr %21, align 8, !tbaa !11
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = load i32, ptr %9, align 4, !tbaa !9
  %25 = zext i32 %24 to i64
  %26 = getelementptr inbounds double, ptr %23, i64 %25
  %27 = load double, ptr %26, align 8, !tbaa !11
  %28 = load double, ptr %10, align 8, !tbaa !11
  %29 = call double @llvm.fmuladd.f64(double %22, double %27, double %28)
  store double %29, ptr %10, align 8, !tbaa !11
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = load i32, ptr %9, align 4, !tbaa !9
  %32 = zext i32 %31 to i64
  %33 = getelementptr inbounds double, ptr %30, i64 %32
  %34 = load double, ptr %33, align 8, !tbaa !11
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = load i32, ptr %9, align 4, !tbaa !9
  %37 = zext i32 %36 to i64
  %38 = getelementptr inbounds double, ptr %35, i64 %37
  %39 = load double, ptr %38, align 8, !tbaa !11
  %40 = load double, ptr %11, align 8, !tbaa !11
  %41 = call double @llvm.fmuladd.f64(double %34, double %39, double %40)
  store double %41, ptr %11, align 8, !tbaa !11
  br label %42

42:                                               ; preds = %17
  %43 = load i32, ptr %9, align 4, !tbaa !9
  %44 = add i32 %43, 1
  store i32 %44, ptr %9, align 4, !tbaa !9
  br label %13, !llvm.loop !13

45:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %46 = load double, ptr %10, align 8, !tbaa !11
  %47 = load double, ptr %11, align 8, !tbaa !11
  %48 = fdiv double %46, %47
  store double %48, ptr %12, align 8, !tbaa !11
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %49

49:                                               ; preds = %65, %45
  %50 = load i32, ptr %9, align 4, !tbaa !9
  %51 = load i32, ptr %7, align 4, !tbaa !9
  %52 = icmp ult i32 %50, %51
  br i1 %52, label %53, label %68

53:                                               ; preds = %49
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = load i32, ptr %9, align 4, !tbaa !9
  %56 = zext i32 %55 to i64
  %57 = getelementptr inbounds double, ptr %54, i64 %56
  %58 = load double, ptr %57, align 8, !tbaa !11
  %59 = load double, ptr %12, align 8, !tbaa !11
  %60 = fmul double %58, %59
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = load i32, ptr %9, align 4, !tbaa !9
  %63 = zext i32 %62 to i64
  %64 = getelementptr inbounds double, ptr %61, i64 %63
  store double %60, ptr %64, align 8, !tbaa !11
  br label %65

65:                                               ; preds = %53
  %66 = load i32, ptr %9, align 4, !tbaa !9
  %67 = add i32 %66, 1
  store i32 %67, ptr %9, align 4, !tbaa !9
  br label %49, !llvm.loop !15

68:                                               ; preds = %49
  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 4, ptr %9) #3
  ret i32 0
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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/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: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local noundef i32 @matrix_proj(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, i32 noundef %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #0 {
  %5 = ptrtoint ptr %0 to i64
  %6 = ptrtoint ptr %3 to i64
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %._crit_edge32, label %.lr.ph.preheader

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

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %wide.trip.count, 4294967294
  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 ]
  %8 = phi <2 x double> [ zeroinitializer, %.lr.ph.preheader.new ], [ %24, %.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 !5
  %11 = getelementptr inbounds double, ptr %1, i64 %indvars.iv
  %12 = load double, ptr %11, align 8, !tbaa !5
  %13 = insertelement <2 x double> poison, double %10, i64 0
  %14 = shufflevector <2 x double> %13, <2 x double> poison, <2 x i32> zeroinitializer
  %15 = insertelement <2 x double> %13, double %12, i64 1
  %16 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %14, <2 x double> %15, <2 x double> %8)
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %17 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.next
  %18 = load double, ptr %17, align 8, !tbaa !5
  %19 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.next
  %20 = load double, ptr %19, align 8, !tbaa !5
  %21 = insertelement <2 x double> poison, double %18, i64 0
  %22 = shufflevector <2 x double> %21, <2 x double> poison, <2 x i32> zeroinitializer
  %23 = insertelement <2 x double> %21, double %20, i64 1
  %24 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %22, <2 x double> %23, <2 x double> %16)
  %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.unr-lcssa, label %.lr.ph, !llvm.loop !9

._crit_edge.unr-lcssa:                            ; preds = %.lr.ph, %.lr.ph.preheader
  %.lcssa.ph = phi <2 x double> [ poison, %.lr.ph.preheader ], [ %24, %.lr.ph ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next.1, %.lr.ph ]
  %.unr = phi <2 x double> [ zeroinitializer, %.lr.ph.preheader ], [ %24, %.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
  %25 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.unr
  %26 = load double, ptr %25, align 8, !tbaa !5
  %27 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.unr
  %28 = load double, ptr %27, align 8, !tbaa !5
  %29 = insertelement <2 x double> poison, double %26, i64 0
  %30 = shufflevector <2 x double> %29, <2 x double> poison, <2 x i32> zeroinitializer
  %31 = insertelement <2 x double> %29, double %28, i64 1
  %32 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %30, <2 x double> %31, <2 x double> %.unr)
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.unr-lcssa, %.lr.ph.epil
  %.lcssa = phi <2 x double> [ %.lcssa.ph, %._crit_edge.unr-lcssa ], [ %32, %.lr.ph.epil ]
  %33 = extractelement <2 x double> %.lcssa, i64 0
  %34 = extractelement <2 x double> %.lcssa, i64 1
  %35 = fdiv double %34, %33
  br i1 %.not, label %._crit_edge32, label %.lr.ph31.preheader

.lr.ph31.preheader:                               ; preds = %._crit_edge
  %wide.trip.count39 = zext i32 %2 to i64
  %min.iters.check = icmp ult i32 %2, 4
  %36 = sub i64 %6, %5
  %diff.check = icmp ult i64 %36, 32
  %or.cond = or i1 %min.iters.check, %diff.check
  br i1 %or.cond, label %.lr.ph31.preheader44, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph31.preheader
  %n.vec = and i64 %wide.trip.count, 4294967292
  %broadcast.splatinsert = insertelement <2 x double> poison, double %35, 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 ]
  %37 = getelementptr inbounds double, ptr %0, i64 %index
  %38 = getelementptr inbounds i8, ptr %37, i64 16
  %wide.load = load <2 x double>, ptr %37, align 8, !tbaa !5
  %wide.load43 = load <2 x double>, ptr %38, align 8, !tbaa !5
  %39 = fmul <2 x double> %broadcast.splat, %wide.load
  %40 = fmul <2 x double> %broadcast.splat, %wide.load43
  %41 = getelementptr inbounds double, ptr %3, i64 %index
  %42 = getelementptr inbounds i8, ptr %41, i64 16
  store <2 x double> %39, ptr %41, align 8, !tbaa !5
  store <2 x double> %40, ptr %42, align 8, !tbaa !5
  %index.next = add nuw i64 %index, 4
  %43 = icmp eq i64 %index.next, %n.vec
  br i1 %43, label %middle.block, label %vector.body, !llvm.loop !11

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %._crit_edge32, label %.lr.ph31.preheader44

.lr.ph31.preheader44:                             ; preds = %middle.block, %.lr.ph31.preheader
  %indvars.iv36.ph = phi i64 [ 0, %.lr.ph31.preheader ], [ %n.vec, %middle.block ]
  %xtraiter46 = and i64 %wide.trip.count, 3
  %lcmp.mod47.not = icmp eq i64 %xtraiter46, 0
  br i1 %lcmp.mod47.not, label %.lr.ph31.prol.loopexit, label %.lr.ph31.prol

.lr.ph31.prol:                                    ; preds = %.lr.ph31.preheader44, %.lr.ph31.prol
  %indvars.iv36.prol = phi i64 [ %indvars.iv.next37.prol, %.lr.ph31.prol ], [ %indvars.iv36.ph, %.lr.ph31.preheader44 ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph31.prol ], [ 0, %.lr.ph31.preheader44 ]
  %44 = getelementptr inbounds double, ptr %0, i64 %indvars.iv36.prol
  %45 = load double, ptr %44, align 8, !tbaa !5
  %46 = fmul double %35, %45
  %47 = getelementptr inbounds double, ptr %3, i64 %indvars.iv36.prol
  store double %46, ptr %47, align 8, !tbaa !5
  %indvars.iv.next37.prol = add nuw nsw i64 %indvars.iv36.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter46
  br i1 %prol.iter.cmp.not, label %.lr.ph31.prol.loopexit, label %.lr.ph31.prol, !llvm.loop !14

.lr.ph31.prol.loopexit:                           ; preds = %.lr.ph31.prol, %.lr.ph31.preheader44
  %indvars.iv36.unr = phi i64 [ %indvars.iv36.ph, %.lr.ph31.preheader44 ], [ %indvars.iv.next37.prol, %.lr.ph31.prol ]
  %48 = sub nsw i64 %indvars.iv36.ph, %wide.trip.count
  %49 = icmp ugt i64 %48, -4
  br i1 %49, label %._crit_edge32, label %.lr.ph31

.lr.ph31:                                         ; preds = %.lr.ph31.prol.loopexit, %.lr.ph31
  %indvars.iv36 = phi i64 [ %indvars.iv.next37.3, %.lr.ph31 ], [ %indvars.iv36.unr, %.lr.ph31.prol.loopexit ]
  %50 = getelementptr inbounds double, ptr %0, i64 %indvars.iv36
  %51 = load double, ptr %50, align 8, !tbaa !5
  %52 = fmul double %35, %51
  %53 = getelementptr inbounds double, ptr %3, i64 %indvars.iv36
  store double %52, ptr %53, align 8, !tbaa !5
  %indvars.iv.next37 = add nuw nsw i64 %indvars.iv36, 1
  %54 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.next37
  %55 = load double, ptr %54, align 8, !tbaa !5
  %56 = fmul double %35, %55
  %57 = getelementptr inbounds double, ptr %3, i64 %indvars.iv.next37
  store double %56, ptr %57, align 8, !tbaa !5
  %indvars.iv.next37.1 = add nuw nsw i64 %indvars.iv36, 2
  %58 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.next37.1
  %59 = load double, ptr %58, align 8, !tbaa !5
  %60 = fmul double %35, %59
  %61 = getelementptr inbounds double, ptr %3, i64 %indvars.iv.next37.1
  store double %60, ptr %61, align 8, !tbaa !5
  %indvars.iv.next37.2 = add nuw nsw i64 %indvars.iv36, 3
  %62 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.next37.2
  %63 = load double, ptr %62, align 8, !tbaa !5
  %64 = fmul double %35, %63
  %65 = getelementptr inbounds double, ptr %3, i64 %indvars.iv.next37.2
  store double %64, ptr %65, align 8, !tbaa !5
  %indvars.iv.next37.3 = add nuw nsw i64 %indvars.iv36, 4
  %exitcond40.not.3 = icmp eq i64 %indvars.iv.next37.3, %wide.trip.count39
  br i1 %exitcond40.not.3, label %._crit_edge32, label %.lr.ph31, !llvm.loop !16

._crit_edge32:                                    ; preds = %.lr.ph31.prol.loopexit, %.lr.ph31, %middle.block, %4, %._crit_edge
  ret i32 0
}

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

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" }
attributes #1 = { 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/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10, !12, !13}
!12 = !{!"llvm.loop.isvectorized", i32 1}
!13 = !{!"llvm.loop.unroll.runtime.disable"}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.unroll.disable"}
!16 = distinct !{!16, !10, !12}


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