; LLVM IR from ermig1979/Simd :: src/Simd/SimdBaseSquaredDifferenceSum.ll (ZN4Simd4Base23SquaredDifferenceSum32fEPKfS2_mPf)

; 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: mustprogress uwtable
define dso_local void @_ZN4Simd4Base23SquaredDifferenceSum32fEPKfS2_mPf(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca [4 x float], align 16
  %11 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %12 = load i64, ptr %7, align 8, !tbaa !9
  %13 = call noundef i64 @_ZN4Simd7AlignLoEmm(i64 noundef %12, i64 noundef 4)
  store i64 %13, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %10) #4
  call void @llvm.memset.p0.i64(ptr align 16 %10, i8 0, i64 16, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  store i64 0, ptr %11, align 8, !tbaa !9
  br label %14

14:                                               ; preds = %79, %4
  %15 = load i64, ptr %11, align 8, !tbaa !9
  %16 = load i64, ptr %9, align 8, !tbaa !9
  %17 = icmp ult i64 %15, %16
  br i1 %17, label %18, label %82

18:                                               ; preds = %14
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = load i64, ptr %11, align 8, !tbaa !9
  %21 = add i64 %20, 0
  %22 = getelementptr inbounds float, ptr %19, i64 %21
  %23 = load float, ptr %22, align 4, !tbaa !11
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = load i64, ptr %11, align 8, !tbaa !9
  %26 = add i64 %25, 0
  %27 = getelementptr inbounds float, ptr %24, i64 %26
  %28 = load float, ptr %27, align 4, !tbaa !11
  %29 = fsub float %23, %28
  %30 = call noundef float @_ZN4Simd6SquareIfEET_S1_(float noundef %29)
  %31 = getelementptr inbounds [4 x float], ptr %10, i64 0, i64 0
  %32 = load float, ptr %31, align 16, !tbaa !11
  %33 = fadd float %32, %30
  store float %33, ptr %31, align 16, !tbaa !11
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = load i64, ptr %11, align 8, !tbaa !9
  %36 = add i64 %35, 1
  %37 = getelementptr inbounds float, ptr %34, i64 %36
  %38 = load float, ptr %37, align 4, !tbaa !11
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = load i64, ptr %11, align 8, !tbaa !9
  %41 = add i64 %40, 1
  %42 = getelementptr inbounds float, ptr %39, i64 %41
  %43 = load float, ptr %42, align 4, !tbaa !11
  %44 = fsub float %38, %43
  %45 = call noundef float @_ZN4Simd6SquareIfEET_S1_(float noundef %44)
  %46 = getelementptr inbounds [4 x float], ptr %10, i64 0, i64 1
  %47 = load float, ptr %46, align 4, !tbaa !11
  %48 = fadd float %47, %45
  store float %48, ptr %46, align 4, !tbaa !11
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = load i64, ptr %11, align 8, !tbaa !9
  %51 = add i64 %50, 2
  %52 = getelementptr inbounds float, ptr %49, i64 %51
  %53 = load float, ptr %52, align 4, !tbaa !11
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = load i64, ptr %11, align 8, !tbaa !9
  %56 = add i64 %55, 2
  %57 = getelementptr inbounds float, ptr %54, i64 %56
  %58 = load float, ptr %57, align 4, !tbaa !11
  %59 = fsub float %53, %58
  %60 = call noundef float @_ZN4Simd6SquareIfEET_S1_(float noundef %59)
  %61 = getelementptr inbounds [4 x float], ptr %10, i64 0, i64 2
  %62 = load float, ptr %61, align 8, !tbaa !11
  %63 = fadd float %62, %60
  store float %63, ptr %61, align 8, !tbaa !11
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = load i64, ptr %11, align 8, !tbaa !9
  %66 = add i64 %65, 3
  %67 = getelementptr inbounds float, ptr %64, i64 %66
  %68 = load float, ptr %67, align 4, !tbaa !11
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = load i64, ptr %11, align 8, !tbaa !9
  %71 = add i64 %70, 3
  %72 = getelementptr inbounds float, ptr %69, i64 %71
  %73 = load float, ptr %72, align 4, !tbaa !11
  %74 = fsub float %68, %73
  %75 = call noundef float @_ZN4Simd6SquareIfEET_S1_(float noundef %74)
  %76 = getelementptr inbounds [4 x float], ptr %10, i64 0, i64 3
  %77 = load float, ptr %76, align 4, !tbaa !11
  %78 = fadd float %77, %75
  store float %78, ptr %76, align 4, !tbaa !11
  br label %79

79:                                               ; preds = %18
  %80 = load i64, ptr %11, align 8, !tbaa !9
  %81 = add i64 %80, 4
  store i64 %81, ptr %11, align 8, !tbaa !9
  br label %14, !llvm.loop !13

82:                                               ; preds = %14
  br label %83

83:                                               ; preds = %101, %82
  %84 = load i64, ptr %11, align 8, !tbaa !9
  %85 = load i64, ptr %7, align 8, !tbaa !9
  %86 = icmp ult i64 %84, %85
  br i1 %86, label %87, label %104

87:                                               ; preds = %83
  %88 = load ptr, ptr %5, align 8, !tbaa !5
  %89 = load i64, ptr %11, align 8, !tbaa !9
  %90 = getelementptr inbounds float, ptr %88, i64 %89
  %91 = load float, ptr %90, align 4, !tbaa !11
  %92 = load ptr, ptr %6, align 8, !tbaa !5
  %93 = load i64, ptr %11, align 8, !tbaa !9
  %94 = getelementptr inbounds float, ptr %92, i64 %93
  %95 = load float, ptr %94, align 4, !tbaa !11
  %96 = fsub float %91, %95
  %97 = call noundef float @_ZN4Simd6SquareIfEET_S1_(float noundef %96)
  %98 = getelementptr inbounds [4 x float], ptr %10, i64 0, i64 0
  %99 = load float, ptr %98, align 16, !tbaa !11
  %100 = fadd float %99, %97
  store float %100, ptr %98, align 16, !tbaa !11
  br label %101

101:                                              ; preds = %87
  %102 = load i64, ptr %11, align 8, !tbaa !9
  %103 = add i64 %102, 1
  store i64 %103, ptr %11, align 8, !tbaa !9
  br label %83, !llvm.loop !15

104:                                              ; preds = %83
  %105 = getelementptr inbounds [4 x float], ptr %10, i64 0, i64 0
  %106 = load float, ptr %105, align 16, !tbaa !11
  %107 = getelementptr inbounds [4 x float], ptr %10, i64 0, i64 1
  %108 = load float, ptr %107, align 4, !tbaa !11
  %109 = fadd float %106, %108
  %110 = getelementptr inbounds [4 x float], ptr %10, i64 0, i64 2
  %111 = load float, ptr %110, align 8, !tbaa !11
  %112 = fadd float %109, %111
  %113 = getelementptr inbounds [4 x float], ptr %10, i64 0, i64 3
  %114 = load float, ptr %113, align 4, !tbaa !11
  %115 = fadd float %112, %114
  %116 = load ptr, ptr %8, align 8, !tbaa !5
  store float %115, ptr %116, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  ret void
}

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN4Simd7AlignLoEmm(i64 noundef, i64 noundef) #2

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

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef float @_ZN4Simd6SquareIfEET_S1_(float noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { alwaysinline 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !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 nounwind uwtable
define dso_local void @_ZN4Simd4Base23SquaredDifferenceSum32fEPKfS2_mPf(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, i64 noundef %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #0 {
  %5 = tail call noundef i64 @_ZN4Simd7AlignLoEmm(i64 noundef %2, i64 noundef 4)
  %.not = icmp eq i64 %5, 0
  br i1 %.not, label %.preheader, label %.lr.ph

.preheader:                                       ; preds = %.lr.ph, %4
  %.sroa.0.0.lcssa = phi float [ 0.000000e+00, %4 ], [ %13, %.lr.ph ]
  %.sroa.8.0.lcssa = phi float [ 0.000000e+00, %4 ], [ %21, %.lr.ph ]
  %.sroa.11.0.lcssa = phi float [ 0.000000e+00, %4 ], [ %29, %.lr.ph ]
  %.sroa.14.0.lcssa = phi float [ 0.000000e+00, %4 ], [ %37, %.lr.ph ]
  %.0.lcssa = phi i64 [ 0, %4 ], [ %38, %.lr.ph ]
  %6 = icmp ult i64 %.0.lcssa, %2
  br i1 %6, label %.lr.ph43, label %._crit_edge

.lr.ph:                                           ; preds = %4, %.lr.ph
  %.036 = phi i64 [ %38, %.lr.ph ], [ 0, %4 ]
  %.sroa.14.035 = phi float [ %37, %.lr.ph ], [ 0.000000e+00, %4 ]
  %.sroa.11.034 = phi float [ %29, %.lr.ph ], [ 0.000000e+00, %4 ]
  %.sroa.8.033 = phi float [ %21, %.lr.ph ], [ 0.000000e+00, %4 ]
  %.sroa.0.032 = phi float [ %13, %.lr.ph ], [ 0.000000e+00, %4 ]
  %7 = getelementptr inbounds float, ptr %0, i64 %.036
  %8 = load float, ptr %7, align 4, !tbaa !5
  %9 = getelementptr inbounds float, ptr %1, i64 %.036
  %10 = load float, ptr %9, align 4, !tbaa !5
  %11 = fsub float %8, %10
  %12 = tail call noundef float @_ZN4Simd6SquareIfEET_S1_(float noundef %11)
  %13 = fadd float %.sroa.0.032, %12
  %14 = or disjoint i64 %.036, 1
  %15 = getelementptr inbounds float, ptr %0, i64 %14
  %16 = load float, ptr %15, align 4, !tbaa !5
  %17 = getelementptr inbounds float, ptr %1, i64 %14
  %18 = load float, ptr %17, align 4, !tbaa !5
  %19 = fsub float %16, %18
  %20 = tail call noundef float @_ZN4Simd6SquareIfEET_S1_(float noundef %19)
  %21 = fadd float %.sroa.8.033, %20
  %22 = or disjoint i64 %.036, 2
  %23 = getelementptr inbounds float, ptr %0, i64 %22
  %24 = load float, ptr %23, align 4, !tbaa !5
  %25 = getelementptr inbounds float, ptr %1, i64 %22
  %26 = load float, ptr %25, align 4, !tbaa !5
  %27 = fsub float %24, %26
  %28 = tail call noundef float @_ZN4Simd6SquareIfEET_S1_(float noundef %27)
  %29 = fadd float %.sroa.11.034, %28
  %30 = or disjoint i64 %.036, 3
  %31 = getelementptr inbounds float, ptr %0, i64 %30
  %32 = load float, ptr %31, align 4, !tbaa !5
  %33 = getelementptr inbounds float, ptr %1, i64 %30
  %34 = load float, ptr %33, align 4, !tbaa !5
  %35 = fsub float %32, %34
  %36 = tail call noundef float @_ZN4Simd6SquareIfEET_S1_(float noundef %35)
  %37 = fadd float %.sroa.14.035, %36
  %38 = add i64 %.036, 4
  %39 = icmp ult i64 %38, %5
  br i1 %39, label %.lr.ph, label %.preheader, !llvm.loop !9

.lr.ph43:                                         ; preds = %.preheader, %.lr.ph43
  %.142 = phi i64 [ %47, %.lr.ph43 ], [ %.0.lcssa, %.preheader ]
  %.sroa.0.141 = phi float [ %46, %.lr.ph43 ], [ %.sroa.0.0.lcssa, %.preheader ]
  %40 = getelementptr inbounds float, ptr %0, i64 %.142
  %41 = load float, ptr %40, align 4, !tbaa !5
  %42 = getelementptr inbounds float, ptr %1, i64 %.142
  %43 = load float, ptr %42, align 4, !tbaa !5
  %44 = fsub float %41, %43
  %45 = tail call noundef float @_ZN4Simd6SquareIfEET_S1_(float noundef %44)
  %46 = fadd float %.sroa.0.141, %45
  %47 = add i64 %.142, 1
  %exitcond.not = icmp eq i64 %47, %2
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph43, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph43, %.preheader
  %.sroa.0.1.lcssa = phi float [ %.sroa.0.0.lcssa, %.preheader ], [ %46, %.lr.ph43 ]
  %48 = fadd float %.sroa.8.0.lcssa, %.sroa.0.1.lcssa
  %49 = fadd float %.sroa.11.0.lcssa, %48
  %50 = fadd float %.sroa.14.0.lcssa, %49
  store float %50, ptr %3, align 4, !tbaa !5
  ret void
}

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN4Simd7AlignLoEmm(i64 noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef float @_ZN4Simd6SquareIfEET_S1_(float noundef) local_unnamed_addr #1

attributes #0 = { 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 #1 = { alwaysinline 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" }

!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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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