; LLVM IR from ermig1979/Simd :: src/Simd/SimdBaseStatistic.ll (ZN4Simd4Base10GetColSumsEPKhmmmPj)

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

17:                                               ; preds = %46, %5
  %18 = load i64, ptr %11, align 8, !tbaa !9
  %19 = load i64, ptr %9, align 8, !tbaa !9
  %20 = icmp ult i64 %18, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %17
  store i32 2, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  br label %49

22:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  store i64 0, ptr %13, align 8, !tbaa !9
  br label %23

23:                                               ; preds = %39, %22
  %24 = load i64, ptr %13, align 8, !tbaa !9
  %25 = load i64, ptr %8, align 8, !tbaa !9
  %26 = icmp ult i64 %24, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %23
  store i32 5, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  br label %42

28:                                               ; preds = %23
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = load i64, ptr %13, align 8, !tbaa !9
  %31 = getelementptr inbounds i8, ptr %29, i64 %30
  %32 = load i8, ptr %31, align 1, !tbaa !11
  %33 = zext i8 %32 to i32
  %34 = load ptr, ptr %10, align 8, !tbaa !5
  %35 = load i64, ptr %13, align 8, !tbaa !9
  %36 = getelementptr inbounds i32, ptr %34, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !12
  %38 = add i32 %37, %33
  store i32 %38, ptr %36, align 4, !tbaa !12
  br label %39

39:                                               ; preds = %28
  %40 = load i64, ptr %13, align 8, !tbaa !9
  %41 = add i64 %40, 1
  store i64 %41, ptr %13, align 8, !tbaa !9
  br label %23, !llvm.loop !14

42:                                               ; preds = %27
  %43 = load i64, ptr %7, align 8, !tbaa !9
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = getelementptr inbounds i8, ptr %44, i64 %43
  store ptr %45, ptr %6, align 8, !tbaa !5
  br label %46

46:                                               ; preds = %42
  %47 = load i64, ptr %11, align 8, !tbaa !9
  %48 = add i64 %47, 1
  store i64 %48, ptr %11, align 8, !tbaa !9
  br label %17, !llvm.loop !16

49:                                               ; preds = %21
  ret void
}

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

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

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @_ZN4Simd4Base10GetColSumsEPKhmmmPj(ptr nocapture noundef readonly %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, ptr nocapture noundef %4) local_unnamed_addr #0 {
  %6 = shl i64 %2, 2
  tail call void @llvm.memset.p0.i64(ptr align 4 %4, i8 0, i64 %6, i1 false)
  %.not = icmp eq i64 %3, 0
  %.not19 = icmp eq i64 %2, 0
  %or.cond = or i1 %.not, %.not19
  br i1 %or.cond, label %._crit_edge18, label %.preheader.us.preheader

.preheader.us.preheader:                          ; preds = %5
  %7 = shl i64 %2, 2
  %scevgep = getelementptr i8, ptr %4, i64 %7
  %8 = add i64 %3, -1
  %9 = mul i64 %8, %1
  %10 = getelementptr i8, ptr %0, i64 %9
  %scevgep22 = getelementptr i8, ptr %10, i64 %2
  %min.iters.check = icmp ult i64 %2, 8
  %bound0 = icmp ugt ptr %scevgep22, %4
  %bound1 = icmp ugt ptr %scevgep, %0
  %found.conflict = and i1 %bound0, %bound1
  %stride.check = icmp slt i64 %1, 0
  %11 = or i1 %found.conflict, %stride.check
  %n.vec = and i64 %2, -8
  %cmp.n = icmp eq i64 %n.vec, %2
  %xtraiter = and i64 %2, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %.01317.us = phi i64 [ %59, %._crit_edge.us ], [ 0, %.preheader.us.preheader ]
  %.01416.us = phi ptr [ %58, %._crit_edge.us ], [ %0, %.preheader.us.preheader ]
  %brmerge = or i1 %min.iters.check, %11
  br i1 %brmerge, label %scalar.ph.preheader, label %vector.body

vector.body:                                      ; preds = %.preheader.us, %vector.body
  %index = phi i64 [ %index.next, %vector.body ], [ 0, %.preheader.us ]
  %12 = getelementptr inbounds i8, ptr %.01416.us, i64 %index
  %13 = getelementptr inbounds i8, ptr %12, i64 4
  %wide.load = load <4 x i8>, ptr %12, align 1, !tbaa !5, !alias.scope !8
  %wide.load23 = load <4 x i8>, ptr %13, align 1, !tbaa !5, !alias.scope !8
  %14 = zext <4 x i8> %wide.load to <4 x i32>
  %15 = zext <4 x i8> %wide.load23 to <4 x i32>
  %16 = getelementptr inbounds i32, ptr %4, i64 %index
  %17 = getelementptr inbounds i8, ptr %16, i64 16
  %wide.load24 = load <4 x i32>, ptr %16, align 4, !tbaa !11, !alias.scope !13, !noalias !8
  %wide.load25 = load <4 x i32>, ptr %17, align 4, !tbaa !11, !alias.scope !13, !noalias !8
  %18 = add <4 x i32> %wide.load24, %14
  %19 = add <4 x i32> %wide.load25, %15
  store <4 x i32> %18, ptr %16, align 4, !tbaa !11, !alias.scope !13, !noalias !8
  store <4 x i32> %19, ptr %17, align 4, !tbaa !11, !alias.scope !13, !noalias !8
  %index.next = add nuw i64 %index, 8
  %20 = icmp eq i64 %index.next, %n.vec
  br i1 %20, label %middle.block, label %vector.body, !llvm.loop !15

middle.block:                                     ; preds = %vector.body
  br i1 %cmp.n, label %._crit_edge.us, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %.preheader.us, %middle.block
  %.015.us.ph = phi i64 [ 0, %.preheader.us ], [ %n.vec, %middle.block ]
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader, %scalar.ph.prol
  %.015.us.prol = phi i64 [ %27, %scalar.ph.prol ], [ %.015.us.ph, %scalar.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %scalar.ph.prol ], [ 0, %scalar.ph.preheader ]
  %21 = getelementptr inbounds i8, ptr %.01416.us, i64 %.015.us.prol
  %22 = load i8, ptr %21, align 1, !tbaa !5
  %23 = zext i8 %22 to i32
  %24 = getelementptr inbounds i32, ptr %4, i64 %.015.us.prol
  %25 = load i32, ptr %24, align 4, !tbaa !11
  %26 = add i32 %25, %23
  store i32 %26, ptr %24, align 4, !tbaa !11
  %27 = add nuw i64 %.015.us.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 %scalar.ph.prol.loopexit, label %scalar.ph.prol, !llvm.loop !19

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %.015.us.unr = phi i64 [ %.015.us.ph, %scalar.ph.preheader ], [ %27, %scalar.ph.prol ]
  %28 = sub i64 %.015.us.ph, %2
  %29 = icmp ugt i64 %28, -4
  br i1 %29, label %._crit_edge.us, label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %.015.us = phi i64 [ %57, %scalar.ph ], [ %.015.us.unr, %scalar.ph.prol.loopexit ]
  %30 = getelementptr inbounds i8, ptr %.01416.us, i64 %.015.us
  %31 = load i8, ptr %30, align 1, !tbaa !5
  %32 = zext i8 %31 to i32
  %33 = getelementptr inbounds i32, ptr %4, i64 %.015.us
  %34 = load i32, ptr %33, align 4, !tbaa !11
  %35 = add i32 %34, %32
  store i32 %35, ptr %33, align 4, !tbaa !11
  %36 = add nuw i64 %.015.us, 1
  %37 = getelementptr inbounds i8, ptr %.01416.us, i64 %36
  %38 = load i8, ptr %37, align 1, !tbaa !5
  %39 = zext i8 %38 to i32
  %40 = getelementptr inbounds i32, ptr %4, i64 %36
  %41 = load i32, ptr %40, align 4, !tbaa !11
  %42 = add i32 %41, %39
  store i32 %42, ptr %40, align 4, !tbaa !11
  %43 = add nuw i64 %.015.us, 2
  %44 = getelementptr inbounds i8, ptr %.01416.us, i64 %43
  %45 = load i8, ptr %44, align 1, !tbaa !5
  %46 = zext i8 %45 to i32
  %47 = getelementptr inbounds i32, ptr %4, i64 %43
  %48 = load i32, ptr %47, align 4, !tbaa !11
  %49 = add i32 %48, %46
  store i32 %49, ptr %47, align 4, !tbaa !11
  %50 = add nuw i64 %.015.us, 3
  %51 = getelementptr inbounds i8, ptr %.01416.us, i64 %50
  %52 = load i8, ptr %51, align 1, !tbaa !5
  %53 = zext i8 %52 to i32
  %54 = getelementptr inbounds i32, ptr %4, i64 %50
  %55 = load i32, ptr %54, align 4, !tbaa !11
  %56 = add i32 %55, %53
  store i32 %56, ptr %54, align 4, !tbaa !11
  %57 = add nuw i64 %.015.us, 4
  %exitcond.not.3 = icmp eq i64 %57, %2
  br i1 %exitcond.not.3, label %._crit_edge.us, label %scalar.ph, !llvm.loop !21

._crit_edge.us:                                   ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block
  %58 = getelementptr inbounds i8, ptr %.01416.us, i64 %1
  %59 = add nuw i64 %.01317.us, 1
  %exitcond21.not = icmp eq i64 %59, %3
  br i1 %exitcond21.not, label %._crit_edge18, label %.preheader.us, !llvm.loop !22

._crit_edge18:                                    ; preds = %._crit_edge.us, %5
  ret void
}

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

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9}
!9 = distinct !{!9, !10}
!10 = distinct !{!10, !"LVerDomain"}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !6, i64 0}
!13 = !{!14}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !16, !17, !18}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!"llvm.loop.isvectorized", i32 1}
!18 = !{!"llvm.loop.unroll.runtime.disable"}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.unroll.disable"}
!21 = distinct !{!21, !16, !17}
!22 = distinct !{!22, !16}


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