; LLVM IR from nativeformat/NFSmartPlayer :: source/plugins/util/BandSplitter.ll (ZN12nativeformat6plugin4util12BandSplitter6stagesEm)

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

%"class.nativeformat::plugin::util::BandSplitter" = type { ptr, i64, i64, %"class.std::vector", %"class.std::vector.0" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl" }
%"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl" = type { %"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl_data" }
%"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::vector.0" = type { %"struct.std::_Vector_base.1" }
%"struct.std::_Vector_base.1" = type { %"struct.std::_Vector_base<std::pair<nativeformat::plugin::util::ButterFilter, nativeformat::plugin::util::ButterFilter>, std::allocator<std::pair<nativeformat::plugin::util::ButterFilter, nativeformat::plugin::util::ButterFilter>>>::_Vector_impl" }
%"struct.std::_Vector_base<std::pair<nativeformat::plugin::util::ButterFilter, nativeformat::plugin::util::ButterFilter>, std::allocator<std::pair<nativeformat::plugin::util::ButterFilter, nativeformat::plugin::util::ButterFilter>>>::_Vector_impl" = type { %"struct.std::_Vector_base<std::pair<nativeformat::plugin::util::ButterFilter, nativeformat::plugin::util::ButterFilter>, std::allocator<std::pair<nativeformat::plugin::util::ButterFilter, nativeformat::plugin::util::ButterFilter>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<std::pair<nativeformat::plugin::util::ButterFilter, nativeformat::plugin::util::ButterFilter>, std::allocator<std::pair<nativeformat::plugin::util::ButterFilter, nativeformat::plugin::util::ButterFilter>>>::_Vector_impl_data" = type { ptr, ptr, ptr }

; 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt5floorImEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN12nativeformat6plugin4util12BandSplitter6stagesEm(ptr noundef nonnull align 8 dereferenceable(72) %0, i64 noundef %1) #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  %8 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store i64 0, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %9 = getelementptr inbounds %"class.nativeformat::plugin::util::BandSplitter", ptr %8, i32 0, i32 1
  %10 = load i64, ptr %9, align 8, !tbaa !11
  store i64 %10, ptr %6, align 8, !tbaa !9
  br label %11

11:                                               ; preds = %33, %2
  %12 = load i64, ptr %6, align 8, !tbaa !9
  %13 = icmp ugt i64 %12, 1
  br i1 %13, label %14, label %34

14:                                               ; preds = %11
  %15 = load i64, ptr %5, align 8, !tbaa !9
  %16 = add i64 %15, 1
  store i64 %16, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %17 = load i64, ptr %6, align 8, !tbaa !9
  %18 = udiv i64 %17, 2
  %19 = call noundef double @_ZSt5floorImEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef %18)
  %20 = fptoui double %19 to i64
  store i64 %20, ptr %7, align 8, !tbaa !9
  %21 = load i64, ptr %4, align 8, !tbaa !9
  %22 = load i64, ptr %7, align 8, !tbaa !9
  %23 = icmp uge i64 %21, %22
  br i1 %23, label %24, label %31

24:                                               ; preds = %14
  %25 = load i64, ptr %7, align 8, !tbaa !9
  %26 = load i64, ptr %6, align 8, !tbaa !9
  %27 = sub i64 %26, %25
  store i64 %27, ptr %6, align 8, !tbaa !9
  %28 = load i64, ptr %7, align 8, !tbaa !9
  %29 = load i64, ptr %4, align 8, !tbaa !9
  %30 = sub i64 %29, %28
  store i64 %30, ptr %4, align 8, !tbaa !9
  br label %33

31:                                               ; preds = %14
  %32 = load i64, ptr %7, align 8, !tbaa !9
  store i64 %32, ptr %6, align 8, !tbaa !9
  br label %33

33:                                               ; preds = %31, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %11, !llvm.loop !21

34:                                               ; preds = %11
  %35 = load i64, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret i64 %35
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 = { 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 = { 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, !10, i64 8}
!12 = !{!"_ZTSN12nativeformat6plugin4util12BandSplitterE", !10, i64 8, !10, i64 16, !13, i64 24, !17, i64 48}
!13 = !{!"_ZTSSt6vectorIdSaIdEE", !14, i64 0}
!14 = !{!"_ZTSSt12_Vector_baseIdSaIdEE", !15, i64 0}
!15 = !{!"_ZTSNSt12_Vector_baseIdSaIdEE12_Vector_implE", !16, i64 0}
!16 = !{!"_ZTSNSt12_Vector_baseIdSaIdEE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!17 = !{!"_ZTSSt6vectorISt4pairIN12nativeformat6plugin4util12ButterFilterES4_ESaIS5_EE", !18, i64 0}
!18 = !{!"_ZTSSt12_Vector_baseISt4pairIN12nativeformat6plugin4util12ButterFilterES4_ESaIS5_EE", !19, i64 0}
!19 = !{!"_ZTSNSt12_Vector_baseISt4pairIN12nativeformat6plugin4util12ButterFilterES4_ESaIS5_EE12_Vector_implE", !20, i64 0}
!20 = !{!"_ZTSNSt12_Vector_baseISt4pairIN12nativeformat6plugin4util12ButterFilterES4_ESaIS5_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


; 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt5floorImEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_ZN12nativeformat6plugin4util12BandSplitter6stagesEm(ptr nocapture noundef nonnull readonly align 8 dereferenceable(72) %0, i64 noundef %1) local_unnamed_addr #1 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %5 = icmp ugt i64 %4, 1
  br i1 %5, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %2, %.lr.ph
  %.018 = phi i64 [ %.1, %.lr.ph ], [ %1, %2 ]
  %.01117 = phi i64 [ %.112, %.lr.ph ], [ %4, %2 ]
  %.01316 = phi i64 [ %6, %.lr.ph ], [ 0, %2 ]
  %6 = add i64 %.01316, 1
  %7 = lshr i64 %.01117, 1
  %8 = tail call noundef double @_ZSt5floorImEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef %7)
  %9 = fptoui double %8 to i64
  %.not = icmp ult i64 %.018, %9
  %10 = sub i64 %.01117, %9
  %.112 = select i1 %.not, i64 %9, i64 %10
  %11 = select i1 %.not, i64 0, i64 %9
  %.1 = sub i64 %.018, %11
  %12 = icmp ugt i64 %.112, 1
  br i1 %12, label %.lr.ph, label %._crit_edge, !llvm.loop !19

._crit_edge:                                      ; preds = %.lr.ph, %2
  %.013.lcssa = phi i64 [ 0, %2 ], [ %6, %.lr.ph ]
  ret i64 %.013.lcssa
}

attributes #0 = { inlinehint 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 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, !7, i64 8}
!6 = !{!"_ZTSN12nativeformat6plugin4util12BandSplitterE", !7, i64 8, !7, i64 16, !10, i64 24, !15, i64 48}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSSt6vectorIdSaIdEE", !11, i64 0}
!11 = !{!"_ZTSSt12_Vector_baseIdSaIdEE", !12, i64 0}
!12 = !{!"_ZTSNSt12_Vector_baseIdSaIdEE12_Vector_implE", !13, i64 0}
!13 = !{!"_ZTSNSt12_Vector_baseIdSaIdEE17_Vector_impl_dataE", !14, i64 0, !14, i64 8, !14, i64 16}
!14 = !{!"any pointer", !8, i64 0}
!15 = !{!"_ZTSSt6vectorISt4pairIN12nativeformat6plugin4util12ButterFilterES4_ESaIS5_EE", !16, i64 0}
!16 = !{!"_ZTSSt12_Vector_baseISt4pairIN12nativeformat6plugin4util12ButterFilterES4_ESaIS5_EE", !17, i64 0}
!17 = !{!"_ZTSNSt12_Vector_baseISt4pairIN12nativeformat6plugin4util12ButterFilterES4_ESaIS5_EE12_Vector_implE", !18, i64 0}
!18 = !{!"_ZTSNSt12_Vector_baseISt4pairIN12nativeformat6plugin4util12ButterFilterES4_ESaIS5_EE17_Vector_impl_dataE", !14, i64 0, !14, i64 8, !14, i64 16}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass