; LLVM IR from ermig1979/Simd :: src/Simd/SimdBaseAbsDifferenceSum.ll (ZN4Simd4Base16AbsDifferenceSumEPKhmS2_mmmPm)

; 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: mustprogress uwtable
define dso_local void @_ZN4Simd4Base16AbsDifferenceSumEPKhmS2_mmmPm(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3, i64 noundef %4, i64 noundef %5, ptr noundef %6) #0 {
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca i64, align 8
  store ptr %0, ptr %8, align 8, !tbaa !5
  store i64 %1, ptr %9, align 8, !tbaa !9
  store ptr %2, ptr %10, align 8, !tbaa !5
  store i64 %3, ptr %11, align 8, !tbaa !9
  store i64 %4, ptr %12, align 8, !tbaa !9
  store i64 %5, ptr %13, align 8, !tbaa !9
  store ptr %6, ptr %14, align 8, !tbaa !5
  %19 = load ptr, ptr %14, align 8, !tbaa !5
  store i64 0, ptr %19, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  store i64 0, ptr %15, align 8, !tbaa !9
  br label %20

20:                                               ; preds = %60, %7
  %21 = load i64, ptr %15, align 8, !tbaa !9
  %22 = load i64, ptr %13, align 8, !tbaa !9
  %23 = icmp ult i64 %21, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  store i32 2, ptr %16, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  br label %63

25:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  store i32 0, ptr %17, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #3
  store i64 0, ptr %18, align 8, !tbaa !9
  br label %26

26:                                               ; preds = %45, %25
  %27 = load i64, ptr %18, align 8, !tbaa !9
  %28 = load i64, ptr %12, align 8, !tbaa !9
  %29 = icmp ult i64 %27, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %26
  store i32 5, ptr %16, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #3
  br label %48

31:                                               ; preds = %26
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = load i64, ptr %18, align 8, !tbaa !9
  %34 = getelementptr inbounds i8, ptr %32, i64 %33
  %35 = load i8, ptr %34, align 1, !tbaa !13
  %36 = zext i8 %35 to i32
  %37 = load ptr, ptr %10, align 8, !tbaa !5
  %38 = load i64, ptr %18, align 8, !tbaa !9
  %39 = getelementptr inbounds i8, ptr %37, i64 %38
  %40 = load i8, ptr %39, align 1, !tbaa !13
  %41 = zext i8 %40 to i32
  %42 = call noundef i32 @_ZN4Simd4Base15AbsDifferenceU8Eii(i32 noundef %36, i32 noundef %41)
  %43 = load i32, ptr %17, align 4, !tbaa !11
  %44 = add nsw i32 %43, %42
  store i32 %44, ptr %17, align 4, !tbaa !11
  br label %45

45:                                               ; preds = %31
  %46 = load i64, ptr %18, align 8, !tbaa !9
  %47 = add i64 %46, 1
  store i64 %47, ptr %18, align 8, !tbaa !9
  br label %26, !llvm.loop !14

48:                                               ; preds = %30
  %49 = load i32, ptr %17, align 4, !tbaa !11
  %50 = sext i32 %49 to i64
  %51 = load ptr, ptr %14, align 8, !tbaa !5
  %52 = load i64, ptr %51, align 8, !tbaa !9
  %53 = add i64 %52, %50
  store i64 %53, ptr %51, align 8, !tbaa !9
  %54 = load i64, ptr %9, align 8, !tbaa !9
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  %56 = getelementptr inbounds i8, ptr %55, i64 %54
  store ptr %56, ptr %8, align 8, !tbaa !5
  %57 = load i64, ptr %11, align 8, !tbaa !9
  %58 = load ptr, ptr %10, align 8, !tbaa !5
  %59 = getelementptr inbounds i8, ptr %58, i64 %57
  store ptr %59, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  br label %60

60:                                               ; preds = %48
  %61 = load i64, ptr %15, align 8, !tbaa !9
  %62 = add i64 %61, 1
  store i64 %62, ptr %15, align 8, !tbaa !9
  br label %20, !llvm.loop !16

63:                                               ; preds = %24
  ret void
}

; 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 nounwind uwtable
declare dso_local noundef i32 @_ZN4Simd4Base15AbsDifferenceU8Eii(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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!"int", !7, i64 0}
!13 = !{!7, !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"

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN4Simd4Base16AbsDifferenceSumEPKhmS2_mmmPm(ptr nocapture noundef readonly %0, i64 noundef %1, ptr nocapture noundef readonly %2, i64 noundef %3, i64 noundef %4, i64 noundef %5, ptr nocapture noundef %6) local_unnamed_addr #0 {
  store i64 0, ptr %6, align 8, !tbaa !5
  %.not = icmp eq i64 %5, 0
  %.not27 = icmp eq i64 %4, 0
  %or.cond = or i1 %.not, %.not27
  br i1 %or.cond, label %._crit_edge26, label %.preheader.us

.preheader.us:                                    ; preds = %7, %._crit_edge.us
  %.01825.us = phi i64 [ %23, %._crit_edge.us ], [ 0, %7 ]
  %.01924.us = phi ptr [ %21, %._crit_edge.us ], [ %0, %7 ]
  %.02023.us = phi ptr [ %22, %._crit_edge.us ], [ %2, %7 ]
  br label %8

8:                                                ; preds = %.preheader.us, %8
  %.022.us = phi i64 [ 0, %.preheader.us ], [ %17, %8 ]
  %.01721.us = phi i32 [ 0, %.preheader.us ], [ %16, %8 ]
  %9 = getelementptr inbounds i8, ptr %.01924.us, i64 %.022.us
  %10 = load i8, ptr %9, align 1, !tbaa !9
  %11 = zext i8 %10 to i32
  %12 = getelementptr inbounds i8, ptr %.02023.us, i64 %.022.us
  %13 = load i8, ptr %12, align 1, !tbaa !9
  %14 = zext i8 %13 to i32
  %15 = tail call noundef i32 @_ZN4Simd4Base15AbsDifferenceU8Eii(i32 noundef %11, i32 noundef %14)
  %16 = add nsw i32 %15, %.01721.us
  %17 = add nuw i64 %.022.us, 1
  %exitcond.not = icmp eq i64 %17, %4
  br i1 %exitcond.not, label %._crit_edge.us, label %8, !llvm.loop !10

._crit_edge.us:                                   ; preds = %8
  %18 = sext i32 %16 to i64
  %19 = load i64, ptr %6, align 8, !tbaa !5
  %20 = add i64 %19, %18
  store i64 %20, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %.01924.us, i64 %1
  %22 = getelementptr inbounds i8, ptr %.02023.us, i64 %3
  %23 = add nuw i64 %.01825.us, 1
  %exitcond28.not = icmp eq i64 %23, %5
  br i1 %exitcond28.not, label %._crit_edge26, label %.preheader.us, !llvm.loop !12

._crit_edge26:                                    ; preds = %._crit_edge.us, %7
  ret void
}

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN4Simd4Base15AbsDifferenceU8Eii(i32 noundef, i32 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 = !{!"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: CorrelatedValuePropagationPass,DSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass