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

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

@.str = external hidden unnamed_addr constant [16 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [90 x i8], align 1
@__PRETTY_FUNCTION__._ZN4Simd4Base26SquaredDifferenceSumMaskedEPKhmS2_mS2_mhmmPm = external hidden unnamed_addr constant [156 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #0

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

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local noundef i32 @_ZN4Simd4Base17SquaredDifferenceEii(i32 noundef, i32 noundef) #2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4Simd4Base26SquaredDifferenceSumMaskedEPKhmS2_mS2_mhmmPm(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5, i8 noundef zeroext %6, i64 noundef %7, i64 noundef %8, ptr noundef %9) #3 {
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i64, align 8
  %17 = alloca i8, align 1
  %18 = alloca i64, align 8
  %19 = alloca i64, align 8
  %20 = alloca ptr, align 8
  %21 = alloca i64, align 8
  %22 = alloca i32, align 4
  %23 = alloca i32, align 4
  %24 = alloca i64, align 8
  store ptr %0, ptr %11, align 8, !tbaa !5
  store i64 %1, ptr %12, align 8, !tbaa !9
  store ptr %2, ptr %13, align 8, !tbaa !5
  store i64 %3, ptr %14, align 8, !tbaa !9
  store ptr %4, ptr %15, align 8, !tbaa !5
  store i64 %5, ptr %16, align 8, !tbaa !9
  store i8 %6, ptr %17, align 1, !tbaa !11
  store i64 %7, ptr %18, align 8, !tbaa !9
  store i64 %8, ptr %19, align 8, !tbaa !9
  store ptr %9, ptr %20, align 8, !tbaa !5
  %25 = load i64, ptr %18, align 8, !tbaa !9
  %26 = icmp ult i64 %25, 65536
  br i1 %26, label %27, label %28

27:                                               ; preds = %10
  br label %30

28:                                               ; preds = %10
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 53, ptr noundef @__PRETTY_FUNCTION__._ZN4Simd4Base26SquaredDifferenceSumMaskedEPKhmS2_mS2_mhmmPm) #4
  unreachable

29:                                               ; No predecessors!
  br label %30

30:                                               ; preds = %29, %27
  %31 = load ptr, ptr %20, align 8, !tbaa !5
  store i64 0, ptr %31, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #5
  store i64 0, ptr %21, align 8, !tbaa !9
  br label %32

32:                                               ; preds = %85, %30
  %33 = load i64, ptr %21, align 8, !tbaa !9
  %34 = load i64, ptr %19, align 8, !tbaa !9
  %35 = icmp ult i64 %33, %34
  br i1 %35, label %37, label %36

36:                                               ; preds = %32
  store i32 2, ptr %22, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #5
  br label %88

37:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 4, ptr %23) #5
  store i32 0, ptr %23, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %24) #5
  store i64 0, ptr %24, align 8, !tbaa !9
  br label %38

38:                                               ; preds = %67, %37
  %39 = load i64, ptr %24, align 8, !tbaa !9
  %40 = load i64, ptr %18, align 8, !tbaa !9
  %41 = icmp ult i64 %39, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %38
  store i32 5, ptr %22, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %24) #5
  br label %70

43:                                               ; preds = %38
  %44 = load ptr, ptr %15, align 8, !tbaa !5
  %45 = load i64, ptr %24, align 8, !tbaa !9
  %46 = getelementptr inbounds i8, ptr %44, i64 %45
  %47 = load i8, ptr %46, align 1, !tbaa !11
  %48 = zext i8 %47 to i32
  %49 = load i8, ptr %17, align 1, !tbaa !11
  %50 = zext i8 %49 to i32
  %51 = icmp eq i32 %48, %50
  br i1 %51, label %52, label %66

52:                                               ; preds = %43
  %53 = load ptr, ptr %11, align 8, !tbaa !5
  %54 = load i64, ptr %24, align 8, !tbaa !9
  %55 = getelementptr inbounds i8, ptr %53, i64 %54
  %56 = load i8, ptr %55, align 1, !tbaa !11
  %57 = zext i8 %56 to i32
  %58 = load ptr, ptr %13, align 8, !tbaa !5
  %59 = load i64, ptr %24, align 8, !tbaa !9
  %60 = getelementptr inbounds i8, ptr %58, i64 %59
  %61 = load i8, ptr %60, align 1, !tbaa !11
  %62 = zext i8 %61 to i32
  %63 = call noundef i32 @_ZN4Simd4Base17SquaredDifferenceEii(i32 noundef %57, i32 noundef %62)
  %64 = load i32, ptr %23, align 4, !tbaa !12
  %65 = add nsw i32 %64, %63
  store i32 %65, ptr %23, align 4, !tbaa !12
  br label %66

66:                                               ; preds = %52, %43
  br label %67

67:                                               ; preds = %66
  %68 = load i64, ptr %24, align 8, !tbaa !9
  %69 = add i64 %68, 1
  store i64 %69, ptr %24, align 8, !tbaa !9
  br label %38, !llvm.loop !14

70:                                               ; preds = %42
  %71 = load i32, ptr %23, align 4, !tbaa !12
  %72 = sext i32 %71 to i64
  %73 = load ptr, ptr %20, align 8, !tbaa !5
  %74 = load i64, ptr %73, align 8, !tbaa !9
  %75 = add i64 %74, %72
  store i64 %75, ptr %73, align 8, !tbaa !9
  %76 = load i64, ptr %12, align 8, !tbaa !9
  %77 = load ptr, ptr %11, align 8, !tbaa !5
  %78 = getelementptr inbounds i8, ptr %77, i64 %76
  store ptr %78, ptr %11, align 8, !tbaa !5
  %79 = load i64, ptr %14, align 8, !tbaa !9
  %80 = load ptr, ptr %13, align 8, !tbaa !5
  %81 = getelementptr inbounds i8, ptr %80, i64 %79
  store ptr %81, ptr %13, align 8, !tbaa !5
  %82 = load i64, ptr %16, align 8, !tbaa !9
  %83 = load ptr, ptr %15, align 8, !tbaa !5
  %84 = getelementptr inbounds i8, ptr %83, i64 %82
  store ptr %84, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %23) #5
  br label %85

85:                                               ; preds = %70
  %86 = load i64, ptr %21, align 8, !tbaa !9
  %87 = add i64 %86, 1
  store i64 %87, ptr %21, align 8, !tbaa !9
  br label %32, !llvm.loop !16

88:                                               ; preds = %36
  ret void
}

attributes #0 = { noreturn 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { alwaysinline 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 #3 = { 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 #4 = { noreturn nounwind }
attributes #5 = { 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 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


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

@.str = external hidden unnamed_addr constant [16 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [90 x i8], align 1
@__PRETTY_FUNCTION__._ZN4Simd4Base26SquaredDifferenceSumMaskedEPKhmS2_mS2_mhmmPm = external hidden unnamed_addr constant [156 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local noundef i32 @_ZN4Simd4Base17SquaredDifferenceEii(i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4Simd4Base26SquaredDifferenceSumMaskedEPKhmS2_mS2_mhmmPm(ptr nocapture noundef readonly %0, i64 noundef %1, ptr nocapture noundef readonly %2, i64 noundef %3, ptr nocapture noundef readonly %4, i64 noundef %5, i8 noundef zeroext %6, i64 noundef %7, i64 noundef %8, ptr nocapture noundef %9) local_unnamed_addr #2 {
  %11 = icmp ult i64 %7, 65536
  br i1 %11, label %13, label %12

12:                                               ; preds = %10
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 53, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN4Simd4Base26SquaredDifferenceSumMaskedEPKhmS2_mS2_mhmmPm) #3
  unreachable

13:                                               ; preds = %10
  store i64 0, ptr %9, align 8, !tbaa !5
  %.not = icmp eq i64 %8, 0
  %.not36 = icmp eq i64 %7, 0
  %or.cond = or i1 %.not, %.not36
  br i1 %or.cond, label %._crit_edge35, label %.preheader.us

.preheader.us:                                    ; preds = %13, %._crit_edge.us
  %.02434.us = phi i64 [ %35, %._crit_edge.us ], [ 0, %13 ]
  %.02533.us = phi ptr [ %32, %._crit_edge.us ], [ %0, %13 ]
  %.02632.us = phi ptr [ %33, %._crit_edge.us ], [ %2, %13 ]
  %.02731.us = phi ptr [ %34, %._crit_edge.us ], [ %4, %13 ]
  br label %14

14:                                               ; preds = %.preheader.us, %27
  %.030.us = phi i64 [ 0, %.preheader.us ], [ %28, %27 ]
  %.02329.us = phi i32 [ 0, %.preheader.us ], [ %.1.us, %27 ]
  %15 = getelementptr inbounds i8, ptr %.02731.us, i64 %.030.us
  %16 = load i8, ptr %15, align 1, !tbaa !9
  %17 = icmp eq i8 %16, %6
  br i1 %17, label %18, label %27

18:                                               ; preds = %14
  %19 = getelementptr inbounds i8, ptr %.02533.us, i64 %.030.us
  %20 = load i8, ptr %19, align 1, !tbaa !9
  %21 = zext i8 %20 to i32
  %22 = getelementptr inbounds i8, ptr %.02632.us, i64 %.030.us
  %23 = load i8, ptr %22, align 1, !tbaa !9
  %24 = zext i8 %23 to i32
  %25 = tail call noundef i32 @_ZN4Simd4Base17SquaredDifferenceEii(i32 noundef %21, i32 noundef %24)
  %26 = add nsw i32 %25, %.02329.us
  br label %27

27:                                               ; preds = %18, %14
  %.1.us = phi i32 [ %26, %18 ], [ %.02329.us, %14 ]
  %28 = add nuw i64 %.030.us, 1
  %exitcond.not = icmp eq i64 %28, %7
  br i1 %exitcond.not, label %._crit_edge.us, label %14, !llvm.loop !10

._crit_edge.us:                                   ; preds = %27
  %29 = sext i32 %.1.us to i64
  %30 = load i64, ptr %9, align 8, !tbaa !5
  %31 = add i64 %30, %29
  store i64 %31, ptr %9, align 8, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %.02533.us, i64 %1
  %33 = getelementptr inbounds i8, ptr %.02632.us, i64 %3
  %34 = getelementptr inbounds i8, ptr %.02731.us, i64 %5
  %35 = add nuw i64 %.02434.us, 1
  %exitcond37.not = icmp eq i64 %35, %8
  br i1 %exitcond37.not, label %._crit_edge35, label %.preheader.us, !llvm.loop !12

._crit_edge35:                                    ; preds = %._crit_edge.us, %13
  ret void
}

attributes #0 = { noreturn 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 #1 = { alwaysinline 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 = { 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 #3 = { noreturn 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


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