; LLVM IR from ermig1979/Simd :: src/Simd/SimdBaseLbp.ll (ZN4Simd4Base11LbpEstimateEPKhmmmPhm)

; 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 @_ZN4Simd4Base11LbpEstimateEPKhmmmPhm(ptr noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5) #0 {
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca i32, align 4
  %15 = alloca i64, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i64 %1, ptr %8, align 8, !tbaa !9
  store i64 %2, ptr %9, align 8, !tbaa !9
  store i64 %3, ptr %10, align 8, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !5
  store i64 %5, ptr %12, align 8, !tbaa !9
  %16 = load ptr, ptr %11, align 8, !tbaa !5
  %17 = load i64, ptr %9, align 8, !tbaa !9
  call void @llvm.memset.p0.i64(ptr align 1 %16, i8 0, i64 %17, i1 false)
  %18 = load i64, ptr %8, align 8, !tbaa !9
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %19, i64 %18
  store ptr %20, ptr %7, align 8, !tbaa !5
  %21 = load i64, ptr %12, align 8, !tbaa !9
  %22 = load ptr, ptr %11, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %22, i64 %21
  store ptr %23, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  store i64 2, ptr %13, align 8, !tbaa !9
  br label %24

24:                                               ; preds = %62, %6
  %25 = load i64, ptr %13, align 8, !tbaa !9
  %26 = load i64, ptr %10, align 8, !tbaa !9
  %27 = icmp ult i64 %25, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %24
  store i32 2, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  br label %65

29:                                               ; preds = %24
  %30 = load ptr, ptr %11, align 8, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %30, i64 0
  store i8 0, ptr %31, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  store i64 1, ptr %15, align 8, !tbaa !9
  br label %32

32:                                               ; preds = %48, %29
  %33 = load i64, ptr %15, align 8, !tbaa !9
  %34 = load i64, ptr %9, align 8, !tbaa !9
  %35 = sub i64 %34, 1
  %36 = icmp ult i64 %33, %35
  br i1 %36, label %38, label %37

37:                                               ; preds = %32
  store i32 5, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  br label %51

38:                                               ; preds = %32
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = load i64, ptr %15, align 8, !tbaa !9
  %41 = getelementptr inbounds i8, ptr %39, i64 %40
  %42 = load i64, ptr %8, align 8, !tbaa !9
  %43 = call noundef i32 @_ZN4Simd4Base11LbpEstimateEPKhl(ptr noundef %41, i64 noundef %42)
  %44 = trunc i32 %43 to i8
  %45 = load ptr, ptr %11, align 8, !tbaa !5
  %46 = load i64, ptr %15, align 8, !tbaa !9
  %47 = getelementptr inbounds i8, ptr %45, i64 %46
  store i8 %44, ptr %47, align 1, !tbaa !11
  br label %48

48:                                               ; preds = %38
  %49 = load i64, ptr %15, align 8, !tbaa !9
  %50 = add i64 %49, 1
  store i64 %50, ptr %15, align 8, !tbaa !9
  br label %32, !llvm.loop !12

51:                                               ; preds = %37
  %52 = load ptr, ptr %11, align 8, !tbaa !5
  %53 = load i64, ptr %9, align 8, !tbaa !9
  %54 = sub i64 %53, 1
  %55 = getelementptr inbounds i8, ptr %52, i64 %54
  store i8 0, ptr %55, align 1, !tbaa !11
  %56 = load i64, ptr %8, align 8, !tbaa !9
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  %58 = getelementptr inbounds i8, ptr %57, i64 %56
  store ptr %58, ptr %7, align 8, !tbaa !5
  %59 = load i64, ptr %12, align 8, !tbaa !9
  %60 = load ptr, ptr %11, align 8, !tbaa !5
  %61 = getelementptr inbounds i8, ptr %60, i64 %59
  store ptr %61, ptr %11, align 8, !tbaa !5
  br label %62

62:                                               ; preds = %51
  %63 = load i64, ptr %13, align 8, !tbaa !9
  %64 = add i64 %63, 1
  store i64 %64, ptr %13, align 8, !tbaa !9
  br label %24, !llvm.loop !14

65:                                               ; preds = %28
  %66 = load ptr, ptr %11, align 8, !tbaa !5
  %67 = load i64, ptr %9, align 8, !tbaa !9
  call void @llvm.memset.p0.i64(ptr align 1 %66, i8 0, i64 %67, i1 false)
  ret void
}

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

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

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN4Simd4Base11LbpEstimateEPKhl(ptr noundef, i64 noundef) #3

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

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


; 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 @_ZN4Simd4Base11LbpEstimateEPKhmmmPhm(ptr noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, ptr nocapture noundef writeonly %4, i64 noundef %5) local_unnamed_addr #0 {
  tail call void @llvm.memset.p0.i64(ptr align 1 %4, i8 0, i64 %2, i1 false)
  %.02732 = getelementptr inbounds i8, ptr %4, i64 %5
  %7 = icmp ugt i64 %3, 2
  br i1 %7, label %.lr.ph37, label %._crit_edge38

.lr.ph37:                                         ; preds = %6
  %8 = add i64 %2, -1
  %9 = icmp ugt i64 %8, 1
  br i1 %9, label %.lr.ph.us, label %.lr.ph37.split.preheader

.lr.ph37.split.preheader:                         ; preds = %.lr.ph37
  %10 = add i64 %3, -2
  %11 = add i64 %3, -3
  %xtraiter = and i64 %10, 3
  %12 = icmp ult i64 %11, 3
  br i1 %12, label %._crit_edge38.loopexit47.unr-lcssa, label %.lr.ph37.split.preheader.new

.lr.ph37.split.preheader.new:                     ; preds = %.lr.ph37.split.preheader
  %unroll_iter = and i64 %10, -4
  br label %.lr.ph37.split

.lr.ph.us:                                        ; preds = %.lr.ph37, %._crit_edge.us
  %.02735.us = phi ptr [ %.027.us, %._crit_edge.us ], [ %.02732, %.lr.ph37 ]
  %.02634.us.pn = phi ptr [ %.02634.us, %._crit_edge.us ], [ %0, %.lr.ph37 ]
  %.02533.us = phi i64 [ %20, %._crit_edge.us ], [ 2, %.lr.ph37 ]
  %.02634.us = getelementptr inbounds i8, ptr %.02634.us.pn, i64 %1
  store i8 0, ptr %.02735.us, align 1, !tbaa !5
  br label %13

13:                                               ; preds = %.lr.ph.us, %13
  %.030.us = phi i64 [ 1, %.lr.ph.us ], [ %18, %13 ]
  %14 = getelementptr inbounds i8, ptr %.02634.us, i64 %.030.us
  %15 = tail call noundef i32 @_ZN4Simd4Base11LbpEstimateEPKhl(ptr noundef nonnull %14, i64 noundef %1)
  %16 = trunc i32 %15 to i8
  %17 = getelementptr inbounds i8, ptr %.02735.us, i64 %.030.us
  store i8 %16, ptr %17, align 1, !tbaa !5
  %18 = add nuw i64 %.030.us, 1
  %exitcond41.not = icmp eq i64 %18, %8
  br i1 %exitcond41.not, label %._crit_edge.us, label %13, !llvm.loop !8

._crit_edge.us:                                   ; preds = %13
  %19 = getelementptr inbounds i8, ptr %.02735.us, i64 %8
  store i8 0, ptr %19, align 1, !tbaa !5
  %20 = add nuw i64 %.02533.us, 1
  %.027.us = getelementptr inbounds i8, ptr %.02735.us, i64 %5
  %exitcond42.not = icmp eq i64 %20, %3
  br i1 %exitcond42.not, label %._crit_edge38, label %.lr.ph.us, !llvm.loop !10

._crit_edge38.loopexit47.unr-lcssa:               ; preds = %.lr.ph37.split, %.lr.ph37.split.preheader
  %.027.lcssa48.ph = phi ptr [ poison, %.lr.ph37.split.preheader ], [ %.027.3, %.lr.ph37.split ]
  %.02735.unr = phi ptr [ %.02732, %.lr.ph37.split.preheader ], [ %.027.3, %.lr.ph37.split ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge38, label %.lr.ph37.split.epil

.lr.ph37.split.epil:                              ; preds = %._crit_edge38.loopexit47.unr-lcssa, %.lr.ph37.split.epil
  %.02735.epil = phi ptr [ %.027.epil, %.lr.ph37.split.epil ], [ %.02735.unr, %._crit_edge38.loopexit47.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph37.split.epil ], [ 0, %._crit_edge38.loopexit47.unr-lcssa ]
  store i8 0, ptr %.02735.epil, align 1, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %.02735.epil, i64 %8
  store i8 0, ptr %21, align 1, !tbaa !5
  %.027.epil = getelementptr inbounds i8, ptr %.02735.epil, i64 %5
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge38, label %.lr.ph37.split.epil, !llvm.loop !11

._crit_edge38:                                    ; preds = %._crit_edge38.loopexit47.unr-lcssa, %.lr.ph37.split.epil, %._crit_edge.us, %6
  %.027.lcssa = phi ptr [ %.02732, %6 ], [ %.027.us, %._crit_edge.us ], [ %.027.lcssa48.ph, %._crit_edge38.loopexit47.unr-lcssa ], [ %.027.epil, %.lr.ph37.split.epil ]
  tail call void @llvm.memset.p0.i64(ptr align 1 %.027.lcssa, i8 0, i64 %2, i1 false)
  ret void

.lr.ph37.split:                                   ; preds = %.lr.ph37.split, %.lr.ph37.split.preheader.new
  %.02735 = phi ptr [ %.02732, %.lr.ph37.split.preheader.new ], [ %.027.3, %.lr.ph37.split ]
  %niter = phi i64 [ 0, %.lr.ph37.split.preheader.new ], [ %niter.next.3, %.lr.ph37.split ]
  store i8 0, ptr %.02735, align 1, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %.02735, i64 %8
  store i8 0, ptr %22, align 1, !tbaa !5
  %.027 = getelementptr inbounds i8, ptr %.02735, i64 %5
  store i8 0, ptr %.027, align 1, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %.027, i64 %8
  store i8 0, ptr %23, align 1, !tbaa !5
  %.027.1 = getelementptr inbounds i8, ptr %.027, i64 %5
  store i8 0, ptr %.027.1, align 1, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %.027.1, i64 %8
  store i8 0, ptr %24, align 1, !tbaa !5
  %.027.2 = getelementptr inbounds i8, ptr %.027.1, i64 %5
  store i8 0, ptr %.027.2, align 1, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %.027.2, i64 %8
  store i8 0, ptr %25, align 1, !tbaa !5
  %.027.3 = getelementptr inbounds i8, ptr %.027.2, i64 %5
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge38.loopexit47.unr-lcssa, label %.lr.ph37.split, !llvm.loop !10
}

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

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN4Simd4Base11LbpEstimateEPKhl(ptr noundef, i64 noundef) local_unnamed_addr #2

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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" }

!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 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !9}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.unroll.disable"}


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