; LLVM IR from mickypaganini/SSI2016-jet-clustering :: spartyjet-4.0.2_mac/ExternalTools/DetectorModel.ll (ZNK13DetectorModel4Grid8phiIndexEdRm)

; 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.DetectorModel::Grid" = type { ptr, %"class.std::vector", i64, i64, i64, double, double, double, double, double }
%"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 }

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZNK13DetectorModel4Grid8phiIndexEdRm(ptr noundef nonnull align 8 dereferenceable(96) %0, double noundef %1, ptr noundef nonnull align 8 dereferenceable(8) %2) unnamed_addr #0 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca double, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store double %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  %7 = load ptr, ptr %4, align 8
  %8 = load double, ptr %5, align 8, !tbaa !9
  %9 = fcmp olt double %8, 0.000000e+00
  br i1 %9, label %10, label %15

10:                                               ; preds = %3
  %11 = getelementptr inbounds %"class.DetectorModel::Grid", ptr %7, i32 0, i32 9
  %12 = load double, ptr %11, align 8, !tbaa !11
  %13 = load double, ptr %5, align 8, !tbaa !9
  %14 = fadd double %13, %12
  store double %14, ptr %5, align 8, !tbaa !9
  br label %15

15:                                               ; preds = %10, %3
  %16 = load double, ptr %5, align 8, !tbaa !9
  %17 = getelementptr inbounds %"class.DetectorModel::Grid", ptr %7, i32 0, i32 8
  %18 = load double, ptr %17, align 8, !tbaa !18
  %19 = fdiv double %16, %18
  %20 = fptoui double %19 to i64
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  store i64 %20, ptr %21, align 8, !tbaa !19
  br label %22

22:                                               ; preds = %28, %15
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = load i64, ptr %23, align 8, !tbaa !19
  %25 = getelementptr inbounds %"class.DetectorModel::Grid", ptr %7, i32 0, i32 4
  %26 = load i64, ptr %25, align 8, !tbaa !20
  %27 = icmp uge i64 %24, %26
  br i1 %27, label %28, label %34

28:                                               ; preds = %22
  %29 = getelementptr inbounds %"class.DetectorModel::Grid", ptr %7, i32 0, i32 4
  %30 = load i64, ptr %29, align 8, !tbaa !20
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = load i64, ptr %31, align 8, !tbaa !19
  %33 = sub i64 %32, %30
  store i64 %33, ptr %31, align 8, !tbaa !19
  br label %22, !llvm.loop !21

34:                                               ; preds = %22
  ret i1 true
}

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

!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 = !{!"double", !7, i64 0}
!11 = !{!12, !10, i64 88}
!12 = !{!"_ZTSN13DetectorModel4GridE", !13, i64 8, !17, i64 32, !17, i64 40, !17, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88}
!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 = !{!"long", !7, i64 0}
!18 = !{!12, !10, i64 80}
!19 = !{!17, !17, i64 0}
!20 = !{!12, !17, i64 48}
!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: mustprogress nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local noundef zeroext i1 @_ZNK13DetectorModel4Grid8phiIndexEdRm(ptr nocapture noundef nonnull readonly align 8 dereferenceable(96) %0, double noundef %1, ptr nocapture noundef nonnull writeonly align 8 dereferenceable(8) %2) unnamed_addr #0 align 2 {
  %4 = fcmp olt double %1, 0.000000e+00
  %5 = getelementptr inbounds i8, ptr %0, i64 88
  %6 = load double, ptr %5, align 8
  %7 = fadd double %6, %1
  %.0 = select i1 %4, double %7, double %1
  %8 = getelementptr inbounds i8, ptr %0, i64 80
  %9 = load double, ptr %8, align 8, !tbaa !5
  %10 = fdiv double %.0, %9
  %11 = fptoui double %10 to i64
  %12 = getelementptr inbounds i8, ptr %0, i64 48
  br label %13

13:                                               ; preds = %13, %3
  %storemerge = phi i64 [ %11, %3 ], [ %15, %13 ]
  store i64 %storemerge, ptr %2, align 8, !tbaa !16
  %14 = load i64, ptr %12, align 8, !tbaa !17
  %.not = icmp ult i64 %storemerge, %14
  %15 = sub i64 %storemerge, %14
  br i1 %.not, label %16, label %13, !llvm.loop !18

16:                                               ; preds = %13
  ret i1 true
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(argmem: readwrite) 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, !15, i64 80}
!6 = !{!"_ZTSN13DetectorModel4GridE", !7, i64 8, !14, i64 32, !14, i64 40, !14, i64 48, !15, i64 56, !15, i64 64, !15, i64 72, !15, i64 80, !15, i64 88}
!7 = !{!"_ZTSSt6vectorIdSaIdEE", !8, i64 0}
!8 = !{!"_ZTSSt12_Vector_baseIdSaIdEE", !9, i64 0}
!9 = !{!"_ZTSNSt12_Vector_baseIdSaIdEE12_Vector_implE", !10, i64 0}
!10 = !{!"_ZTSNSt12_Vector_baseIdSaIdEE17_Vector_impl_dataE", !11, i64 0, !11, i64 8, !11, i64 16}
!11 = !{!"any pointer", !12, i64 0}
!12 = !{!"omnipotent char", !13, i64 0}
!13 = !{!"Simple C++ TBAA"}
!14 = !{!"long", !12, i64 0}
!15 = !{!"double", !12, i64 0}
!16 = !{!14, !14, i64 0}
!17 = !{!6, !14, i64 48}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,InstCombinePass,LICMPass,LoopRotatePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass