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

; 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"

%struct.smatrixf_s = type { i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32 }

; 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 float @llvm.fmuladd.f32(float, float, float) #1

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

10:                                               ; preds = %21, %3
  %11 = load i32, ptr %7, align 4, !tbaa !9
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.smatrixf_s, ptr %12, i32 0, i32 0
  %14 = load i32, ptr %13, align 8, !tbaa !11
  %15 = icmp ult i32 %11, %14
  br i1 %15, label %16, label %24

16:                                               ; preds = %10
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = zext i32 %18 to i64
  %20 = getelementptr inbounds float, ptr %17, i64 %19
  store float 0.000000e+00, ptr %20, align 4, !tbaa !13
  br label %21

21:                                               ; preds = %16
  %22 = load i32, ptr %7, align 4, !tbaa !9
  %23 = add i32 %22, 1
  store i32 %23, ptr %7, align 4, !tbaa !9
  br label %10, !llvm.loop !15

24:                                               ; preds = %10
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %25

25:                                               ; preds = %80, %24
  %26 = load i32, ptr %7, align 4, !tbaa !9
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.smatrixf_s, ptr %27, i32 0, i32 0
  %29 = load i32, ptr %28, align 8, !tbaa !11
  %30 = icmp ult i32 %26, %29
  br i1 %30, label %31, label %83

31:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store float 0.000000e+00, ptr %9, align 4, !tbaa !13
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %32

32:                                               ; preds = %71, %31
  %33 = load i32, ptr %8, align 4, !tbaa !9
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.smatrixf_s, ptr %34, i32 0, i32 6
  %36 = load ptr, ptr %35, align 8, !tbaa !17
  %37 = load i32, ptr %7, align 4, !tbaa !9
  %38 = zext i32 %37 to i64
  %39 = getelementptr inbounds i32, ptr %36, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !9
  %41 = icmp ult i32 %33, %40
  br i1 %41, label %42, label %74

42:                                               ; preds = %32
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.smatrixf_s, ptr %43, i32 0, i32 4
  %45 = load ptr, ptr %44, align 8, !tbaa !18
  %46 = load i32, ptr %7, align 4, !tbaa !9
  %47 = zext i32 %46 to i64
  %48 = getelementptr inbounds ptr, ptr %45, i64 %47
  %49 = load ptr, ptr %48, align 8, !tbaa !5
  %50 = load i32, ptr %8, align 4, !tbaa !9
  %51 = zext i32 %50 to i64
  %52 = getelementptr inbounds float, ptr %49, i64 %51
  %53 = load float, ptr %52, align 4, !tbaa !13
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.smatrixf_s, ptr %55, i32 0, i32 2
  %57 = load ptr, ptr %56, align 8, !tbaa !19
  %58 = load i32, ptr %7, align 4, !tbaa !9
  %59 = zext i32 %58 to i64
  %60 = getelementptr inbounds ptr, ptr %57, i64 %59
  %61 = load ptr, ptr %60, align 8, !tbaa !5
  %62 = load i32, ptr %8, align 4, !tbaa !9
  %63 = zext i32 %62 to i64
  %64 = getelementptr inbounds i16, ptr %61, i64 %63
  %65 = load i16, ptr %64, align 2, !tbaa !20
  %66 = zext i16 %65 to i64
  %67 = getelementptr inbounds float, ptr %54, i64 %66
  %68 = load float, ptr %67, align 4, !tbaa !13
  %69 = load float, ptr %9, align 4, !tbaa !13
  %70 = call float @llvm.fmuladd.f32(float %53, float %68, float %69)
  store float %70, ptr %9, align 4, !tbaa !13
  br label %71

71:                                               ; preds = %42
  %72 = load i32, ptr %8, align 4, !tbaa !9
  %73 = add i32 %72, 1
  store i32 %73, ptr %8, align 4, !tbaa !9
  br label %32, !llvm.loop !22

74:                                               ; preds = %32
  %75 = load float, ptr %9, align 4, !tbaa !13
  %76 = load ptr, ptr %6, align 8, !tbaa !5
  %77 = load i32, ptr %7, align 4, !tbaa !9
  %78 = zext i32 %77 to i64
  %79 = getelementptr inbounds float, ptr %76, i64 %78
  store float %75, ptr %79, align 4, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %80

80:                                               ; preds = %74
  %81 = load i32, ptr %7, align 4, !tbaa !9
  %82 = add i32 %81, 1
  store i32 %82, ptr %7, align 4, !tbaa !9
  br label %25, !llvm.loop !23

83:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #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, !10, i64 0}
!12 = !{!"smatrixf_s", !10, i64 0, !10, i64 4, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !10, i64 56, !10, i64 60}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!12, !6, i64 40}
!18 = !{!12, !6, i64 24}
!19 = !{!12, !6, i64 8}
!20 = !{!21, !21, i64 0}
!21 = !{!"short", !7, i64 0}
!22 = distinct !{!22, !16}
!23 = distinct !{!23, !16}


; 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 float @llvm.fmuladd.f32(float, float, float) #0

; Function Attrs: nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local noundef i32 @smatrixf_vmul(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #1 {
  %4 = load i32, ptr %0, align 8, !tbaa !5
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %._crit_edge33, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %3
  %5 = zext i32 %4 to i64
  %6 = shl nuw nsw i64 %5, 2
  tail call void @llvm.memset.p0.i64(ptr align 4 %2, i8 0, i64 %6, i1 false), !tbaa !11
  %7 = getelementptr inbounds i8, ptr %0, i64 40
  %8 = load ptr, ptr %7, align 8, !tbaa !13
  %9 = getelementptr inbounds i8, ptr %0, i64 24
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  %wide.trip.count41 = zext i32 %4 to i64
  br label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %._crit_edge
  %indvars.iv38 = phi i64 [ 0, %.preheader.lr.ph ], [ %indvars.iv.next39, %._crit_edge ]
  %11 = getelementptr inbounds i32, ptr %8, i64 %indvars.iv38
  %12 = load i32, ptr %11, align 4, !tbaa !14
  %.not35 = icmp eq i32 %12, 0
  br i1 %.not35, label %._crit_edge, label %.lr.ph29

.lr.ph29:                                         ; preds = %.preheader
  %13 = load ptr, ptr %9, align 8, !tbaa !15
  %14 = getelementptr inbounds ptr, ptr %13, i64 %indvars.iv38
  %15 = load ptr, ptr %14, align 8, !tbaa !16
  %16 = load ptr, ptr %10, align 8, !tbaa !17
  %17 = getelementptr inbounds ptr, ptr %16, i64 %indvars.iv38
  %18 = load ptr, ptr %17, align 8, !tbaa !16
  %wide.trip.count = zext i32 %12 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %19 = icmp ult i32 %12, 4
  br i1 %19, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph29.new

.lr.ph29.new:                                     ; preds = %.lr.ph29
  %unroll_iter = and i64 %wide.trip.count, 4294967292
  br label %20

20:                                               ; preds = %20, %.lr.ph29.new
  %indvars.iv = phi i64 [ 0, %.lr.ph29.new ], [ %indvars.iv.next.3, %20 ]
  %.028 = phi float [ 0.000000e+00, %.lr.ph29.new ], [ %52, %20 ]
  %niter = phi i64 [ 0, %.lr.ph29.new ], [ %niter.next.3, %20 ]
  %21 = getelementptr inbounds float, ptr %15, i64 %indvars.iv
  %22 = load float, ptr %21, align 4, !tbaa !11
  %23 = getelementptr inbounds i16, ptr %18, i64 %indvars.iv
  %24 = load i16, ptr %23, align 2, !tbaa !18
  %25 = zext i16 %24 to i64
  %26 = getelementptr inbounds float, ptr %1, i64 %25
  %27 = load float, ptr %26, align 4, !tbaa !11
  %28 = tail call float @llvm.fmuladd.f32(float %22, float %27, float %.028)
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %29 = getelementptr inbounds float, ptr %15, i64 %indvars.iv.next
  %30 = load float, ptr %29, align 4, !tbaa !11
  %31 = getelementptr inbounds i16, ptr %18, i64 %indvars.iv.next
  %32 = load i16, ptr %31, align 2, !tbaa !18
  %33 = zext i16 %32 to i64
  %34 = getelementptr inbounds float, ptr %1, i64 %33
  %35 = load float, ptr %34, align 4, !tbaa !11
  %36 = tail call float @llvm.fmuladd.f32(float %30, float %35, float %28)
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %37 = getelementptr inbounds float, ptr %15, i64 %indvars.iv.next.1
  %38 = load float, ptr %37, align 4, !tbaa !11
  %39 = getelementptr inbounds i16, ptr %18, i64 %indvars.iv.next.1
  %40 = load i16, ptr %39, align 2, !tbaa !18
  %41 = zext i16 %40 to i64
  %42 = getelementptr inbounds float, ptr %1, i64 %41
  %43 = load float, ptr %42, align 4, !tbaa !11
  %44 = tail call float @llvm.fmuladd.f32(float %38, float %43, float %36)
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %45 = getelementptr inbounds float, ptr %15, i64 %indvars.iv.next.2
  %46 = load float, ptr %45, align 4, !tbaa !11
  %47 = getelementptr inbounds i16, ptr %18, i64 %indvars.iv.next.2
  %48 = load i16, ptr %47, align 2, !tbaa !18
  %49 = zext i16 %48 to i64
  %50 = getelementptr inbounds float, ptr %1, i64 %49
  %51 = load float, ptr %50, align 4, !tbaa !11
  %52 = tail call float @llvm.fmuladd.f32(float %46, float %51, float %44)
  %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.loopexit.unr-lcssa, label %20, !llvm.loop !20

._crit_edge.loopexit.unr-lcssa:                   ; preds = %20, %.lr.ph29
  %.lcssa.ph = phi float [ poison, %.lr.ph29 ], [ %52, %20 ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph29 ], [ %indvars.iv.next.3, %20 ]
  %.028.unr = phi float [ 0.000000e+00, %.lr.ph29 ], [ %52, %20 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.loopexit.unr-lcssa, %.epil.preheader
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.epil.preheader ], [ %indvars.iv.unr, %._crit_edge.loopexit.unr-lcssa ]
  %.028.epil = phi float [ %60, %.epil.preheader ], [ %.028.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %53 = getelementptr inbounds float, ptr %15, i64 %indvars.iv.epil
  %54 = load float, ptr %53, align 4, !tbaa !11
  %55 = getelementptr inbounds i16, ptr %18, i64 %indvars.iv.epil
  %56 = load i16, ptr %55, align 2, !tbaa !18
  %57 = zext i16 %56 to i64
  %58 = getelementptr inbounds float, ptr %1, i64 %57
  %59 = load float, ptr %58, align 4, !tbaa !11
  %60 = tail call float @llvm.fmuladd.f32(float %54, float %59, float %.028.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 %.epil.preheader, !llvm.loop !22

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.epil.preheader, %.preheader
  %.0.lcssa = phi float [ 0.000000e+00, %.preheader ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %60, %.epil.preheader ]
  %61 = getelementptr inbounds float, ptr %2, i64 %indvars.iv38
  store float %.0.lcssa, ptr %61, align 4, !tbaa !11
  %indvars.iv.next39 = add nuw nsw i64 %indvars.iv38, 1
  %exitcond42.not = icmp eq i64 %indvars.iv.next39, %wide.trip.count41
  br i1 %exitcond42.not, label %._crit_edge33, label %.preheader, !llvm.loop !24

._crit_edge33:                                    ; preds = %._crit_edge, %3
  ret i32 0
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

!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, !7, i64 0}
!6 = !{!"smatrixf_s", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !7, i64 56, !7, i64 60}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !8, i64 0}
!13 = !{!6, !10, i64 40}
!14 = !{!7, !7, i64 0}
!15 = !{!6, !10, i64 24}
!16 = !{!10, !10, i64 0}
!17 = !{!6, !10, i64 8}
!18 = !{!19, !19, i64 0}
!19 = !{!"short", !8, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.unroll.disable"}
!24 = distinct !{!24, !21}


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