; LLVM IR from ermig1979/Simd :: src/Simd/SimdBaseStatistic.ll (ZN4Simd4Base14CorrelationSumEPKhmS2_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"

@.str.1 = external hidden unnamed_addr constant [79 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [16 x i8], align 1
@__PRETTY_FUNCTION__._ZN4Simd4Base14CorrelationSumEPKhmS2_mmmPm = external hidden unnamed_addr constant [110 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN4Simd4Base14CorrelationSumEPKhmS2_mmmPm(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3, i64 noundef %4, i64 noundef %5, ptr noundef %6) #2 {
  %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 i64, ptr %12, align 8, !tbaa !9
  %20 = icmp ult i64 %19, 65536
  br i1 %20, label %21, label %22

21:                                               ; preds = %7
  br label %24

22:                                               ; preds = %7
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 212, ptr noundef @__PRETTY_FUNCTION__._ZN4Simd4Base14CorrelationSumEPKhmS2_mmmPm) #3
  unreachable

23:                                               ; No predecessors!
  br label %24

24:                                               ; preds = %23, %21
  %25 = load ptr, ptr %14, align 8, !tbaa !5
  store i64 0, ptr %25, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  store i64 0, ptr %15, align 8, !tbaa !9
  br label %26

26:                                               ; preds = %66, %24
  %27 = load i64, ptr %15, align 8, !tbaa !9
  %28 = load i64, ptr %13, align 8, !tbaa !9
  %29 = icmp ult i64 %27, %28
  br i1 %29, label %31, label %30

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

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

32:                                               ; preds = %51, %31
  %33 = load i64, ptr %18, align 8, !tbaa !9
  %34 = load i64, ptr %12, align 8, !tbaa !9
  %35 = icmp ult i64 %33, %34
  br i1 %35, label %37, label %36

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

37:                                               ; preds = %32
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = load i64, ptr %18, align 8, !tbaa !9
  %40 = getelementptr inbounds i8, ptr %38, i64 %39
  %41 = load i8, ptr %40, align 1, !tbaa !13
  %42 = zext i8 %41 to i32
  %43 = load ptr, ptr %10, align 8, !tbaa !5
  %44 = load i64, ptr %18, align 8, !tbaa !9
  %45 = getelementptr inbounds i8, ptr %43, i64 %44
  %46 = load i8, ptr %45, align 1, !tbaa !13
  %47 = zext i8 %46 to i32
  %48 = mul nsw i32 %42, %47
  %49 = load i32, ptr %17, align 4, !tbaa !11
  %50 = add nsw i32 %49, %48
  store i32 %50, ptr %17, align 4, !tbaa !11
  br label %51

51:                                               ; preds = %37
  %52 = load i64, ptr %18, align 8, !tbaa !9
  %53 = add i64 %52, 1
  store i64 %53, ptr %18, align 8, !tbaa !9
  br label %32, !llvm.loop !14

54:                                               ; preds = %36
  %55 = load i32, ptr %17, align 4, !tbaa !11
  %56 = sext i32 %55 to i64
  %57 = load ptr, ptr %14, align 8, !tbaa !5
  %58 = load i64, ptr %57, align 8, !tbaa !9
  %59 = add i64 %58, %56
  store i64 %59, ptr %57, align 8, !tbaa !9
  %60 = load i64, ptr %9, align 8, !tbaa !9
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = getelementptr inbounds i8, ptr %61, i64 %60
  store ptr %62, ptr %8, align 8, !tbaa !5
  %63 = load i64, ptr %11, align 8, !tbaa !9
  %64 = load ptr, ptr %10, align 8, !tbaa !5
  %65 = getelementptr inbounds i8, ptr %64, i64 %63
  store ptr %65, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #4
  br label %66

66:                                               ; preds = %54
  %67 = load i64, ptr %15, align 8, !tbaa !9
  %68 = add i64 %67, 1
  store i64 %68, ptr %15, align 8, !tbaa !9
  br label %26, !llvm.loop !16

69:                                               ; preds = %30
  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 = { 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 = { noreturn nounwind }
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 = !{!"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"

@.str.1 = external hidden unnamed_addr constant [79 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [16 x i8], align 1
@__PRETTY_FUNCTION__._ZN4Simd4Base14CorrelationSumEPKhmS2_mmmPm = external hidden unnamed_addr constant [110 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: mustprogress nounwind uwtable
define dso_local void @_ZN4Simd4Base14CorrelationSumEPKhmS2_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 writeonly %6) local_unnamed_addr #1 {
  %8 = icmp ult i64 %4, 65536
  br i1 %8, label %10, label %9

9:                                                ; preds = %7
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 212, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN4Simd4Base14CorrelationSumEPKhmS2_mmmPm) #3
  unreachable

10:                                               ; preds = %7
  store i64 0, ptr %6, align 8, !tbaa !5
  %.not = icmp eq i64 %5, 0
  %.not29 = icmp eq i64 %4, 0
  %or.cond = or i1 %.not, %.not29
  br i1 %or.cond, label %._crit_edge28, label %.preheader.us.preheader

.preheader.us.preheader:                          ; preds = %10
  %min.iters.check = icmp ult i64 %4, 8
  %n.vec = and i64 %4, 65528
  %cmp.n = icmp eq i64 %n.vec, %4
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %11 = phi i64 [ %36, %._crit_edge.us ], [ 0, %.preheader.us.preheader ]
  %.01927.us = phi i64 [ %39, %._crit_edge.us ], [ 0, %.preheader.us.preheader ]
  %.02026.us = phi ptr [ %37, %._crit_edge.us ], [ %0, %.preheader.us.preheader ]
  %.02125.us = phi ptr [ %38, %._crit_edge.us ], [ %2, %.preheader.us.preheader ]
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.body

vector.body:                                      ; preds = %.preheader.us, %vector.body
  %index = phi i64 [ %index.next, %vector.body ], [ 0, %.preheader.us ]
  %vec.phi = phi <4 x i32> [ %22, %vector.body ], [ zeroinitializer, %.preheader.us ]
  %vec.phi32 = phi <4 x i32> [ %23, %vector.body ], [ zeroinitializer, %.preheader.us ]
  %12 = getelementptr inbounds i8, ptr %.02026.us, i64 %index
  %13 = getelementptr inbounds i8, ptr %12, i64 4
  %wide.load = load <4 x i8>, ptr %12, align 1, !tbaa !9
  %wide.load33 = load <4 x i8>, ptr %13, align 1, !tbaa !9
  %14 = zext <4 x i8> %wide.load to <4 x i32>
  %15 = zext <4 x i8> %wide.load33 to <4 x i32>
  %16 = getelementptr inbounds i8, ptr %.02125.us, i64 %index
  %17 = getelementptr inbounds i8, ptr %16, i64 4
  %wide.load34 = load <4 x i8>, ptr %16, align 1, !tbaa !9
  %wide.load35 = load <4 x i8>, ptr %17, align 1, !tbaa !9
  %18 = zext <4 x i8> %wide.load34 to <4 x i32>
  %19 = zext <4 x i8> %wide.load35 to <4 x i32>
  %20 = mul nuw nsw <4 x i32> %18, %14
  %21 = mul nuw nsw <4 x i32> %19, %15
  %22 = add <4 x i32> %20, %vec.phi
  %23 = add <4 x i32> %21, %vec.phi32
  %index.next = add nuw i64 %index, 8
  %24 = icmp eq i64 %index.next, %n.vec
  br i1 %24, label %middle.block, label %vector.body, !llvm.loop !10

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <4 x i32> %23, %22
  %25 = tail call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx)
  br i1 %cmp.n, label %._crit_edge.us, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %.preheader.us
  %.024.us.ph = phi i64 [ 0, %.preheader.us ], [ %n.vec, %middle.block ]
  %.01823.us.ph = phi i32 [ 0, %.preheader.us ], [ %25, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %.024.us = phi i64 [ %34, %scalar.ph ], [ %.024.us.ph, %scalar.ph.preheader ]
  %.01823.us = phi i32 [ %33, %scalar.ph ], [ %.01823.us.ph, %scalar.ph.preheader ]
  %26 = getelementptr inbounds i8, ptr %.02026.us, i64 %.024.us
  %27 = load i8, ptr %26, align 1, !tbaa !9
  %28 = zext i8 %27 to i32
  %29 = getelementptr inbounds i8, ptr %.02125.us, i64 %.024.us
  %30 = load i8, ptr %29, align 1, !tbaa !9
  %31 = zext i8 %30 to i32
  %32 = mul nuw nsw i32 %31, %28
  %33 = add nuw nsw i32 %32, %.01823.us
  %34 = add nuw nsw i64 %.024.us, 1
  %exitcond.not = icmp eq i64 %34, %4
  br i1 %exitcond.not, label %._crit_edge.us, label %scalar.ph, !llvm.loop !14

._crit_edge.us:                                   ; preds = %scalar.ph, %middle.block
  %.lcssa = phi i32 [ %25, %middle.block ], [ %33, %scalar.ph ]
  %35 = zext nneg i32 %.lcssa to i64
  %36 = add i64 %11, %35
  store i64 %36, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %.02026.us, i64 %1
  %38 = getelementptr inbounds i8, ptr %.02125.us, i64 %3
  %39 = add nuw i64 %.01927.us, 1
  %exitcond31.not = icmp eq i64 %39, %5
  br i1 %exitcond31.not, label %._crit_edge28, label %.preheader.us, !llvm.loop !15

._crit_edge28:                                    ; preds = %._crit_edge.us, %10
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.vector.reduce.add.v4i32(<4 x i32>) #2

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 = { 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 #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !12, !13}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!"llvm.loop.isvectorized", i32 1}
!13 = !{!"llvm.loop.unroll.runtime.disable"}
!14 = distinct !{!14, !11, !13, !12}
!15 = distinct !{!15, !11}


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