; LLVM IR from jgaeddert/liquid-dsp :: src/dotprod/src/sumsq.sse (liquid_sumsqf_sse)

; 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 float @liquid_sumsqf_sse(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca <4 x float>, align 16
  %6 = alloca <4 x float>, align 16
  %7 = alloca <4 x float>, align 16
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca [4 x float], align 16
  %11 = alloca float, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #4
  %12 = call <4 x float> @_mm_setzero_ps()
  store <4 x float> %12, ptr %7, align 16, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %13 = load i32, ptr %4, align 4, !tbaa !9
  %14 = lshr i32 %13, 2
  %15 = shl i32 %14, 2
  store i32 %15, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %32, %2
  %17 = load i32, ptr %9, align 4, !tbaa !9
  %18 = load i32, ptr %8, align 4, !tbaa !9
  %19 = icmp ult i32 %17, %18
  br i1 %19, label %20, label %35

20:                                               ; preds = %16
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = load i32, ptr %9, align 4, !tbaa !9
  %23 = zext i32 %22 to i64
  %24 = getelementptr inbounds float, ptr %21, i64 %23
  %25 = call <4 x float> @_mm_loadu_ps(ptr noundef %24)
  store <4 x float> %25, ptr %5, align 16, !tbaa !11
  %26 = load <4 x float>, ptr %5, align 16, !tbaa !11
  %27 = load <4 x float>, ptr %5, align 16, !tbaa !11
  %28 = call <4 x float> @_mm_mul_ps(<4 x float> noundef %26, <4 x float> noundef %27)
  store <4 x float> %28, ptr %6, align 16, !tbaa !11
  %29 = load <4 x float>, ptr %7, align 16, !tbaa !11
  %30 = load <4 x float>, ptr %6, align 16, !tbaa !11
  %31 = call <4 x float> @_mm_add_ps(<4 x float> noundef %29, <4 x float> noundef %30)
  store <4 x float> %31, ptr %7, align 16, !tbaa !11
  br label %32

32:                                               ; preds = %20
  %33 = load i32, ptr %9, align 4, !tbaa !9
  %34 = add i32 %33, 4
  store i32 %34, ptr %9, align 4, !tbaa !9
  br label %16, !llvm.loop !12

35:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 16, ptr %10) #4
  %36 = getelementptr inbounds [4 x float], ptr %10, i64 0, i64 0
  %37 = load <4 x float>, ptr %7, align 16, !tbaa !11
  call void @_mm_store_ps(ptr noundef %36, <4 x float> noundef %37)
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %38 = getelementptr inbounds [4 x float], ptr %10, i64 0, i64 0
  %39 = load float, ptr %38, align 16, !tbaa !14
  %40 = getelementptr inbounds [4 x float], ptr %10, i64 0, i64 1
  %41 = load float, ptr %40, align 4, !tbaa !14
  %42 = fadd float %39, %41
  %43 = getelementptr inbounds [4 x float], ptr %10, i64 0, i64 2
  %44 = load float, ptr %43, align 8, !tbaa !14
  %45 = fadd float %42, %44
  %46 = getelementptr inbounds [4 x float], ptr %10, i64 0, i64 3
  %47 = load float, ptr %46, align 4, !tbaa !14
  %48 = fadd float %45, %47
  store float %48, ptr %11, align 4, !tbaa !14
  br label %49

49:                                               ; preds = %66, %35
  %50 = load i32, ptr %9, align 4, !tbaa !9
  %51 = load i32, ptr %4, align 4, !tbaa !9
  %52 = icmp ult i32 %50, %51
  br i1 %52, label %53, label %69

53:                                               ; preds = %49
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = load i32, ptr %9, align 4, !tbaa !9
  %56 = zext i32 %55 to i64
  %57 = getelementptr inbounds float, ptr %54, i64 %56
  %58 = load float, ptr %57, align 4, !tbaa !14
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = load i32, ptr %9, align 4, !tbaa !9
  %61 = zext i32 %60 to i64
  %62 = getelementptr inbounds float, ptr %59, i64 %61
  %63 = load float, ptr %62, align 4, !tbaa !14
  %64 = load float, ptr %11, align 4, !tbaa !14
  %65 = call float @llvm.fmuladd.f32(float %58, float %63, float %64)
  store float %65, ptr %11, align 4, !tbaa !14
  br label %66

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

69:                                               ; preds = %49
  %70 = load float, ptr %11, align 4, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %5) #4
  ret float %70
}

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

; Function Attrs: alwaysinline nounwind uwtable
declare hidden <4 x float> @_mm_setzero_ps() #2

; Function Attrs: alwaysinline nounwind uwtable
declare hidden <4 x float> @_mm_loadu_ps(ptr noundef) #2

; Function Attrs: alwaysinline nounwind uwtable
declare hidden <4 x float> @_mm_mul_ps(<4 x float> noundef, <4 x float> noundef) #2

; Function Attrs: alwaysinline nounwind uwtable
declare hidden <4 x float> @_mm_add_ps(<4 x float> noundef, <4 x float> noundef) #2

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @_mm_store_ps(ptr noundef, <4 x float> noundef) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #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"="128" "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 = { alwaysinline nounwind uwtable "min-legal-vector-width"="128" "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 }

!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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !15, i64 0}
!15 = !{!"float", !7, i64 0}
!16 = distinct !{!16, !13}


; 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: nounwind uwtable
define dso_local float @liquid_sumsqf_sse(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca [4 x float], align 16
  %4 = tail call <4 x float> @_mm_setzero_ps()
  %5 = and i32 %1, -4
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %2
  %6 = zext i32 %5 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %.02021 = phi <4 x float> [ %4, %.lr.ph.preheader ], [ %10, %.lr.ph ]
  %7 = getelementptr inbounds float, ptr %0, i64 %indvars.iv
  %8 = tail call <4 x float> @_mm_loadu_ps(ptr noundef %7)
  %9 = tail call <4 x float> @_mm_mul_ps(<4 x float> noundef %8, <4 x float> noundef %8)
  %10 = tail call <4 x float> @_mm_add_ps(<4 x float> noundef %.02021, <4 x float> noundef %9)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 4
  %11 = icmp ult i64 %indvars.iv.next, %6
  br i1 %11, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !5

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %12 = trunc nuw i64 %indvars.iv.next to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %2
  %.020.lcssa = phi <4 x float> [ %4, %2 ], [ %10, %._crit_edge.loopexit ]
  %.019.lcssa = phi i32 [ 0, %2 ], [ %12, %._crit_edge.loopexit ]
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #4
  call void @_mm_store_ps(ptr noundef nonnull %3, <4 x float> noundef %.020.lcssa)
  %13 = load float, ptr %3, align 16, !tbaa !7
  %14 = getelementptr inbounds i8, ptr %3, i64 4
  %15 = load float, ptr %14, align 4, !tbaa !7
  %16 = fadd float %13, %15
  %17 = getelementptr inbounds i8, ptr %3, i64 8
  %18 = load float, ptr %17, align 8, !tbaa !7
  %19 = fadd float %16, %18
  %20 = getelementptr inbounds i8, ptr %3, i64 12
  %21 = load float, ptr %20, align 4, !tbaa !7
  %22 = fadd float %19, %21
  %23 = icmp ult i32 %.019.lcssa, %1
  br i1 %23, label %.lr.ph27.preheader, label %._crit_edge28

.lr.ph27.preheader:                               ; preds = %._crit_edge
  %24 = zext i32 %.019.lcssa to i64
  %wide.trip.count = zext i32 %1 to i64
  %25 = sub nsw i64 %wide.trip.count, %24
  %xtraiter = and i64 %25, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph27.prol.loopexit, label %.lr.ph27.prol

.lr.ph27.prol:                                    ; preds = %.lr.ph27.preheader, %.lr.ph27.prol
  %indvars.iv33.prol = phi i64 [ %indvars.iv.next34.prol, %.lr.ph27.prol ], [ %24, %.lr.ph27.preheader ]
  %.025.prol = phi float [ %28, %.lr.ph27.prol ], [ %22, %.lr.ph27.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph27.prol ], [ 0, %.lr.ph27.preheader ]
  %26 = getelementptr inbounds float, ptr %0, i64 %indvars.iv33.prol
  %27 = load float, ptr %26, align 4, !tbaa !7
  %28 = call float @llvm.fmuladd.f32(float %27, float %27, float %.025.prol)
  %indvars.iv.next34.prol = add nuw nsw i64 %indvars.iv33.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.lr.ph27.prol.loopexit, label %.lr.ph27.prol, !llvm.loop !11

.lr.ph27.prol.loopexit:                           ; preds = %.lr.ph27.prol, %.lr.ph27.preheader
  %.lcssa.unr = phi float [ poison, %.lr.ph27.preheader ], [ %28, %.lr.ph27.prol ]
  %indvars.iv33.unr = phi i64 [ %24, %.lr.ph27.preheader ], [ %indvars.iv.next34.prol, %.lr.ph27.prol ]
  %.025.unr = phi float [ %22, %.lr.ph27.preheader ], [ %28, %.lr.ph27.prol ]
  %29 = sub nsw i64 %24, %wide.trip.count
  %30 = icmp ugt i64 %29, -4
  br i1 %30, label %._crit_edge28, label %.lr.ph27.preheader.new

.lr.ph27.preheader.new:                           ; preds = %.lr.ph27.prol.loopexit
  %invariant.gep = getelementptr i8, ptr %0, i64 4
  %invariant.gep42 = getelementptr i8, ptr %0, i64 8
  %invariant.gep44 = getelementptr i8, ptr %0, i64 12
  br label %.lr.ph27

.lr.ph27:                                         ; preds = %.lr.ph27, %.lr.ph27.preheader.new
  %indvars.iv33 = phi i64 [ %indvars.iv33.unr, %.lr.ph27.preheader.new ], [ %indvars.iv.next34.3, %.lr.ph27 ]
  %.025 = phi float [ %.025.unr, %.lr.ph27.preheader.new ], [ %39, %.lr.ph27 ]
  %31 = getelementptr inbounds float, ptr %0, i64 %indvars.iv33
  %32 = load float, ptr %31, align 4, !tbaa !7
  %33 = call float @llvm.fmuladd.f32(float %32, float %32, float %.025)
  %gep = getelementptr float, ptr %invariant.gep, i64 %indvars.iv33
  %34 = load float, ptr %gep, align 4, !tbaa !7
  %35 = call float @llvm.fmuladd.f32(float %34, float %34, float %33)
  %gep43 = getelementptr float, ptr %invariant.gep42, i64 %indvars.iv33
  %36 = load float, ptr %gep43, align 4, !tbaa !7
  %37 = call float @llvm.fmuladd.f32(float %36, float %36, float %35)
  %gep45 = getelementptr float, ptr %invariant.gep44, i64 %indvars.iv33
  %38 = load float, ptr %gep45, align 4, !tbaa !7
  %39 = call float @llvm.fmuladd.f32(float %38, float %38, float %37)
  %indvars.iv.next34.3 = add nuw nsw i64 %indvars.iv33, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next34.3, %wide.trip.count
  br i1 %exitcond.not.3, label %._crit_edge28, label %.lr.ph27, !llvm.loop !13

._crit_edge28:                                    ; preds = %.lr.ph27.prol.loopexit, %.lr.ph27, %._crit_edge
  %.0.lcssa = phi float [ %22, %._crit_edge ], [ %.lcssa.unr, %.lr.ph27.prol.loopexit ], [ %39, %.lr.ph27 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #4
  ret float %.0.lcssa
}

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

; Function Attrs: alwaysinline nounwind uwtable
declare hidden <4 x float> @_mm_setzero_ps() local_unnamed_addr #2

; Function Attrs: alwaysinline nounwind uwtable
declare hidden <4 x float> @_mm_loadu_ps(ptr noundef) local_unnamed_addr #2

; Function Attrs: alwaysinline nounwind uwtable
declare hidden <4 x float> @_mm_mul_ps(<4 x float> noundef, <4 x float> noundef) local_unnamed_addr #2

; Function Attrs: alwaysinline nounwind uwtable
declare hidden <4 x float> @_mm_add_ps(<4 x float> noundef, <4 x float> noundef) local_unnamed_addr #2

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @_mm_store_ps(ptr noundef, <4 x float> noundef) local_unnamed_addr #2

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

; Function Attrs: mustprogress 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"="128" "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 willreturn memory(argmem: readwrite) }
attributes #2 = { alwaysinline nounwind uwtable "min-legal-vector-width"="128" "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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"float", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.unroll.disable"}
!13 = distinct !{!13, !6}


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