; LLVM IR from doyubkim/fluid-engine-dev :: src/jet/collider_set2.ll (ZNK3jet12ColliderSet210velocityAtERKNS_6VectorIdLm2EEE)

; 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.jet::Vector" = type { double, double }
%"class.jet::ColliderSet2" = type { %"class.jet::Collider2", %"class.std::vector" }
%"class.jet::Collider2" = type { ptr, %"class.std::shared_ptr", double, %"class.std::function" }
%"class.std::shared_ptr" = type { %"class.std::__shared_ptr" }
%"class.std::__shared_ptr" = type { ptr, %"class.std::__shared_count" }
%"class.std::__shared_count" = type { ptr }
%"class.std::function" = type { %"class.std::_Function_base", ptr }
%"class.std::_Function_base" = type { %"union.std::_Any_data", ptr }
%"union.std::_Any_data" = type { %"union.std::_Nocopy_types" }
%"union.std::_Nocopy_types" = type { { i64, i64 } }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<std::shared_ptr<jet::Collider2>, std::allocator<std::shared_ptr<jet::Collider2>>>::_Vector_impl" }
%"struct.std::_Vector_base<std::shared_ptr<jet::Collider2>, std::allocator<std::shared_ptr<jet::Collider2>>>::_Vector_impl" = type { %"struct.std::_Vector_base<std::shared_ptr<jet::Collider2>, std::allocator<std::shared_ptr<jet::Collider2>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<std::shared_ptr<jet::Collider2>, std::allocator<std::shared_ptr<jet::Collider2>>>::_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: mustprogress uwtable
define dso_local void @_ZNK3jet12ColliderSet210velocityAtERKNS_6VectorIdLm2EEE(ptr dead_on_unwind noalias writable sret(%"class.jet::Vector") align 8 %0, ptr noundef nonnull align 8 dereferenceable(88) %1, ptr noundef nonnull align 8 dereferenceable(16) %2) unnamed_addr #1 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca double, align 8
  %9 = alloca i64, align 8
  %10 = alloca double, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %4, align 8
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %12 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store i64 -1, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store double 0x7FEFFFFFFFFFFFFF, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  store i64 0, ptr %9, align 8, !tbaa !9
  br label %13

13:                                               ; preds = %35, %3
  %14 = load i64, ptr %9, align 8, !tbaa !9
  %15 = getelementptr inbounds %"class.jet::ColliderSet2", ptr %12, i32 0, i32 1
  %16 = call noundef i64 @_ZNKSt6vectorISt10shared_ptrIN3jet9Collider2EESaIS3_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %15) #4
  %17 = icmp ult i64 %14, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %38

19:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %20 = getelementptr inbounds %"class.jet::ColliderSet2", ptr %12, i32 0, i32 1
  %21 = load i64, ptr %9, align 8, !tbaa !9
  %22 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNKSt6vectorISt10shared_ptrIN3jet9Collider2EESaIS3_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %20, i64 noundef %21) #4
  %23 = call noundef ptr @_ZNKSt19__shared_ptr_accessIN3jet9Collider2ELN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %22) #4
  %24 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNK3jet9Collider27surfaceEv(ptr noundef nonnull align 8 dereferenceable(64) %23)
  %25 = call noundef ptr @_ZNKSt19__shared_ptr_accessIN3jet8Surface2ELN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %24) #4
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = call noundef double @_ZNK3jet8Surface215closestDistanceERKNS_6VectorIdLm2EEE(ptr noundef nonnull align 8 dereferenceable(49) %25, ptr noundef nonnull align 8 dereferenceable(16) %26)
  store double %27, ptr %10, align 8, !tbaa !11
  %28 = load double, ptr %10, align 8, !tbaa !11
  %29 = load double, ptr %8, align 8, !tbaa !11
  %30 = fcmp olt double %28, %29
  br i1 %30, label %31, label %34

31:                                               ; preds = %19
  %32 = load double, ptr %10, align 8, !tbaa !11
  store double %32, ptr %8, align 8, !tbaa !11
  %33 = load i64, ptr %9, align 8, !tbaa !9
  store i64 %33, ptr %7, align 8, !tbaa !9
  br label %34

34:                                               ; preds = %31, %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %35

35:                                               ; preds = %34
  %36 = load i64, ptr %9, align 8, !tbaa !9
  %37 = add i64 %36, 1
  store i64 %37, ptr %9, align 8, !tbaa !9
  br label %13, !llvm.loop !13

38:                                               ; preds = %18
  %39 = load i64, ptr %7, align 8, !tbaa !9
  %40 = icmp ne i64 %39, -1
  br i1 %40, label %41, label %50

41:                                               ; preds = %38
  %42 = getelementptr inbounds %"class.jet::ColliderSet2", ptr %12, i32 0, i32 1
  %43 = load i64, ptr %7, align 8, !tbaa !9
  %44 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNKSt6vectorISt10shared_ptrIN3jet9Collider2EESaIS3_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %42, i64 noundef %43) #4
  %45 = call noundef ptr @_ZNKSt19__shared_ptr_accessIN3jet9Collider2ELN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %44) #4
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = load ptr, ptr %45, align 8, !tbaa !15
  %48 = getelementptr inbounds ptr, ptr %47, i64 2
  %49 = load ptr, ptr %48, align 8
  call void %49(ptr dead_on_unwind writable sret(%"class.jet::Vector") align 8 %0, ptr noundef nonnull align 8 dereferenceable(64) %45, ptr noundef nonnull align 8 dereferenceable(16) %46)
  store i32 1, ptr %11, align 4
  br label %51

50:                                               ; preds = %38
  call void @_ZN3jet6VectorIdLm2EEC2Ev(ptr noundef nonnull align 8 dereferenceable(16) %0)
  store i32 1, ptr %11, align 4
  br label %51

51:                                               ; preds = %50, %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorISt10shared_ptrIN3jet9Collider2EESaIS3_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNKSt6vectorISt10shared_ptrIN3jet9Collider2EESaIS3_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNKSt19__shared_ptr_accessIN3jet9Collider2ELN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1)) #2 align 2

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNK3jet9Collider27surfaceEv(ptr noundef nonnull align 8 dereferenceable(64)) #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNKSt19__shared_ptr_accessIN3jet8Surface2ELN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1)) #2 align 2

declare noundef double @_ZNK3jet8Surface215closestDistanceERKNS_6VectorIdLm2EEE(ptr noundef nonnull align 8 dereferenceable(49), ptr noundef nonnull align 8 dereferenceable(16)) #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3jet6VectorIdLm2EEC2Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #2 align 2

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


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

%"class.jet::Vector" = type { double, double }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK3jet12ColliderSet210velocityAtERKNS_6VectorIdLm2EEE(ptr dead_on_unwind noalias writable sret(%"class.jet::Vector") align 8 %0, ptr noundef nonnull align 8 dereferenceable(88) %1, ptr noundef nonnull align 8 dereferenceable(16) %2) unnamed_addr #0 align 2 {
  %4 = getelementptr inbounds i8, ptr %1, i64 64
  %5 = tail call noundef i64 @_ZNKSt6vectorISt10shared_ptrIN3jet9Collider2EESaIS3_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %4) #3
  %.not19 = icmp eq i64 %5, 0
  br i1 %.not19, label %._crit_edge.thread, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph
  %.not = icmp eq i64 %.1, -1
  br i1 %.not, label %._crit_edge.thread, label %15

.lr.ph:                                           ; preds = %3, %.lr.ph
  %.017 = phi i64 [ %.1, %.lr.ph ], [ -1, %3 ]
  %.01116 = phi i64 [ %12, %.lr.ph ], [ 0, %3 ]
  %.01215 = phi double [ %.113, %.lr.ph ], [ 0x7FEFFFFFFFFFFFFF, %3 ]
  %6 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNKSt6vectorISt10shared_ptrIN3jet9Collider2EESaIS3_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %4, i64 noundef %.01116) #3
  %7 = tail call noundef ptr @_ZNKSt19__shared_ptr_accessIN3jet9Collider2ELN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %6) #3
  %8 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNK3jet9Collider27surfaceEv(ptr noundef nonnull align 8 dereferenceable(64) %7)
  %9 = tail call noundef ptr @_ZNKSt19__shared_ptr_accessIN3jet8Surface2ELN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %8) #3
  %10 = tail call noundef double @_ZNK3jet8Surface215closestDistanceERKNS_6VectorIdLm2EEE(ptr noundef nonnull align 8 dereferenceable(49) %9, ptr noundef nonnull align 8 dereferenceable(16) %2)
  %11 = fcmp olt double %10, %.01215
  %.113 = select i1 %11, double %10, double %.01215
  %.1 = select i1 %11, i64 %.01116, i64 %.017
  %12 = add nuw i64 %.01116, 1
  %13 = tail call noundef i64 @_ZNKSt6vectorISt10shared_ptrIN3jet9Collider2EESaIS3_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %4) #3
  %14 = icmp ult i64 %12, %13
  br i1 %14, label %.lr.ph, label %._crit_edge, !llvm.loop !5

15:                                               ; preds = %._crit_edge
  %16 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNKSt6vectorISt10shared_ptrIN3jet9Collider2EESaIS3_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %4, i64 noundef %.1) #3
  %17 = tail call noundef ptr @_ZNKSt19__shared_ptr_accessIN3jet9Collider2ELN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %16) #3
  %18 = load ptr, ptr %17, align 8, !tbaa !7
  %19 = getelementptr inbounds i8, ptr %18, i64 16
  %20 = load ptr, ptr %19, align 8
  tail call void %20(ptr dead_on_unwind writable sret(%"class.jet::Vector") align 8 %0, ptr noundef nonnull align 8 dereferenceable(64) %17, ptr noundef nonnull align 8 dereferenceable(16) %2)
  br label %21

._crit_edge.thread:                               ; preds = %3, %._crit_edge
  tail call void @_ZN3jet6VectorIdLm2EEC2Ev(ptr noundef nonnull align 8 dereferenceable(16) %0)
  br label %21

21:                                               ; preds = %._crit_edge.thread, %15
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorISt10shared_ptrIN3jet9Collider2EESaIS3_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNKSt6vectorISt10shared_ptrIN3jet9Collider2EESaIS3_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNKSt19__shared_ptr_accessIN3jet9Collider2ELN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1)) local_unnamed_addr #1 align 2

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNK3jet9Collider27surfaceEv(ptr noundef nonnull align 8 dereferenceable(64)) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNKSt19__shared_ptr_accessIN3jet8Surface2ELN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1)) local_unnamed_addr #1 align 2

declare noundef double @_ZNK3jet8Surface215closestDistanceERKNS_6VectorIdLm2EEE(ptr noundef nonnull align 8 dereferenceable(49), ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3jet6VectorIdLm2EEC2Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #1 align 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 = { 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 = { "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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"vtable pointer", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}


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