; LLVM IR from sp-nitech/SPTK :: src/generation/delta_calculation.ll (ZN4sptk16DeltaCalculation15GetPointerIndexEi)

; 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.sptk::DeltaCalculation" = type { %"class.sptk::InputSourceInterface", i32, i32, %"class.std::vector", ptr, i8, double, i8, i32, %"class.std::vector.0", %"class.std::vector.0", %"struct.sptk::DeltaCalculation::Buffer" }
%"class.sptk::InputSourceInterface" = type { ptr }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<std::vector<double>, std::allocator<std::vector<double>>>::_Vector_impl" }
%"struct.std::_Vector_base<std::vector<double>, std::allocator<std::vector<double>>>::_Vector_impl" = type { %"struct.std::_Vector_base<std::vector<double>, std::allocator<std::vector<double>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<std::vector<double>, std::allocator<std::vector<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<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"struct.sptk::DeltaCalculation::Buffer" = type <{ %"class.std::vector", i32, i32, i8, [7 x i8] }>

; 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 noundef i32 @_ZN4sptk16DeltaCalculation15GetPointerIndexEi(ptr noundef nonnull align 8 dereferenceable(160) %0, i32 noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %6 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %7 = getelementptr inbounds %"class.sptk::DeltaCalculation", ptr %6, i32 0, i32 11
  %8 = getelementptr inbounds %"struct.sptk::DeltaCalculation::Buffer", ptr %7, i32 0, i32 1
  %9 = load i32, ptr %8, align 8, !tbaa !11
  %10 = load i32, ptr %4, align 4, !tbaa !9
  %11 = add nsw i32 %9, %10
  store i32 %11, ptr %5, align 4, !tbaa !9
  %12 = load i32, ptr %4, align 4, !tbaa !9
  %13 = icmp slt i32 %12, 0
  br i1 %13, label %14, label %24

14:                                               ; preds = %2
  br label %15

15:                                               ; preds = %18, %14
  %16 = load i32, ptr %5, align 4, !tbaa !9
  %17 = icmp slt i32 %16, 0
  br i1 %17, label %18, label %23

18:                                               ; preds = %15
  %19 = getelementptr inbounds %"class.sptk::DeltaCalculation", ptr %6, i32 0, i32 8
  %20 = load i32, ptr %19, align 4, !tbaa !25
  %21 = load i32, ptr %5, align 4, !tbaa !9
  %22 = add nsw i32 %21, %20
  store i32 %22, ptr %5, align 4, !tbaa !9
  br label %15, !llvm.loop !26

23:                                               ; preds = %15
  br label %40

24:                                               ; preds = %2
  %25 = load i32, ptr %4, align 4, !tbaa !9
  %26 = icmp slt i32 0, %25
  br i1 %26, label %27, label %39

27:                                               ; preds = %24
  br label %28

28:                                               ; preds = %33, %27
  %29 = getelementptr inbounds %"class.sptk::DeltaCalculation", ptr %6, i32 0, i32 8
  %30 = load i32, ptr %29, align 4, !tbaa !25
  %31 = load i32, ptr %5, align 4, !tbaa !9
  %32 = icmp sle i32 %30, %31
  br i1 %32, label %33, label %38

33:                                               ; preds = %28
  %34 = getelementptr inbounds %"class.sptk::DeltaCalculation", ptr %6, i32 0, i32 8
  %35 = load i32, ptr %34, align 4, !tbaa !25
  %36 = load i32, ptr %5, align 4, !tbaa !9
  %37 = sub nsw i32 %36, %35
  store i32 %37, ptr %5, align 4, !tbaa !9
  br label %28, !llvm.loop !28

38:                                               ; preds = %28
  br label %39

39:                                               ; preds = %38, %24
  br label %40

40:                                               ; preds = %39, %23
  %41 = load i32, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret i32 %41
}

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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 144}
!12 = !{!"_ZTSN4sptk16DeltaCalculationE", !13, i64 0, !10, i64 8, !10, i64 12, !14, i64 16, !6, i64 40, !18, i64 48, !19, i64 56, !18, i64 64, !10, i64 68, !20, i64 72, !20, i64 96, !24, i64 120}
!13 = !{!"_ZTSN4sptk20InputSourceInterfaceE"}
!14 = !{!"_ZTSSt6vectorIS_IdSaIdEESaIS1_EE", !15, i64 0}
!15 = !{!"_ZTSSt12_Vector_baseISt6vectorIdSaIdEESaIS2_EE", !16, i64 0}
!16 = !{!"_ZTSNSt12_Vector_baseISt6vectorIdSaIdEESaIS2_EE12_Vector_implE", !17, i64 0}
!17 = !{!"_ZTSNSt12_Vector_baseISt6vectorIdSaIdEESaIS2_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!18 = !{!"bool", !7, i64 0}
!19 = !{!"double", !7, i64 0}
!20 = !{!"_ZTSSt6vectorIiSaIiEE", !21, i64 0}
!21 = !{!"_ZTSSt12_Vector_baseIiSaIiEE", !22, i64 0}
!22 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE12_Vector_implE", !23, i64 0}
!23 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!24 = !{!"_ZTSN4sptk16DeltaCalculation6BufferE", !14, i64 0, !10, i64 24, !10, i64 28, !18, i64 32}
!25 = !{!12, !10, i64 68}
!26 = distinct !{!26, !27}
!27 = !{!"llvm.loop.mustprogress"}
!28 = distinct !{!28, !27}


; 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 willreturn memory(argmem: read) uwtable
define dso_local noundef i32 @_ZN4sptk16DeltaCalculation15GetPointerIndexEi(ptr nocapture noundef nonnull readonly align 8 dereferenceable(160) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 144
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = add nsw i32 %4, %1
  %6 = icmp slt i32 %1, 0
  br i1 %6, label %.preheader, label %13

.preheader:                                       ; preds = %2
  %7 = icmp slt i32 %5, 0
  br i1 %7, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader
  %8 = getelementptr inbounds i8, ptr %0, i64 68
  %9 = load i32, ptr %8, align 4, !tbaa !23
  br label %10

10:                                               ; preds = %.lr.ph, %10
  %.013 = phi i32 [ %5, %.lr.ph ], [ %11, %10 ]
  %11 = add nsw i32 %9, %.013
  %12 = icmp slt i32 %11, 0
  br i1 %12, label %10, label %.loopexit, !llvm.loop !24

13:                                               ; preds = %2
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %.loopexit, label %.preheader11

.preheader11:                                     ; preds = %13
  %14 = getelementptr inbounds i8, ptr %0, i64 68
  %15 = load i32, ptr %14, align 4, !tbaa !23
  br label %16

16:                                               ; preds = %16, %.preheader11
  %.1 = phi i32 [ %17, %16 ], [ %5, %.preheader11 ]
  %.not10 = icmp sgt i32 %15, %.1
  %17 = sub nsw i32 %.1, %15
  br i1 %.not10, label %.loopexit, label %16, !llvm.loop !26

.loopexit:                                        ; preds = %16, %10, %.preheader, %13
  %.2 = phi i32 [ %5, %13 ], [ %5, %.preheader ], [ %11, %10 ], [ %.1, %16 ]
  ret i32 %.2
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) 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, !8, i64 144}
!6 = !{!"_ZTSN4sptk16DeltaCalculationE", !7, i64 0, !8, i64 8, !8, i64 12, !11, i64 16, !15, i64 40, !16, i64 48, !17, i64 56, !16, i64 64, !8, i64 68, !18, i64 72, !18, i64 96, !22, i64 120}
!7 = !{!"_ZTSN4sptk20InputSourceInterfaceE"}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"_ZTSSt6vectorIS_IdSaIdEESaIS1_EE", !12, i64 0}
!12 = !{!"_ZTSSt12_Vector_baseISt6vectorIdSaIdEESaIS2_EE", !13, i64 0}
!13 = !{!"_ZTSNSt12_Vector_baseISt6vectorIdSaIdEESaIS2_EE12_Vector_implE", !14, i64 0}
!14 = !{!"_ZTSNSt12_Vector_baseISt6vectorIdSaIdEESaIS2_EE17_Vector_impl_dataE", !15, i64 0, !15, i64 8, !15, i64 16}
!15 = !{!"any pointer", !9, i64 0}
!16 = !{!"bool", !9, i64 0}
!17 = !{!"double", !9, i64 0}
!18 = !{!"_ZTSSt6vectorIiSaIiEE", !19, i64 0}
!19 = !{!"_ZTSSt12_Vector_baseIiSaIiEE", !20, i64 0}
!20 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE12_Vector_implE", !21, i64 0}
!21 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE17_Vector_impl_dataE", !15, i64 0, !15, i64 8, !15, i64 16}
!22 = !{!"_ZTSN4sptk16DeltaCalculation6BufferE", !11, i64 0, !8, i64 24, !8, i64 28, !16, i64 32}
!23 = !{!6, !8, i64 68}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}
!26 = distinct !{!26, !25}


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