; LLVM IR from gazebosim/gz-physics :: tpe/lib/src/aabb_tree/AABB.ll (ZNK4aabb4AABB18computeSurfaceAreaEv)

; 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.aabb::AABB" = type { %"class.std::vector", %"class.std::vector", %"class.std::vector", 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
declare dso_local noundef i64 @_ZNKSt6vectorIdSaIdEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #0 align 2

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_ZNK4aabb4AABB18computeSurfaceAreaEv(ptr noundef nonnull align 8 dereferenceable(80) %0) #0 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca double, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca double, align 8
  %7 = alloca i32, align 4
  %8 = alloca double, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %9 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  store double 0.000000e+00, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !11
  br label %10

10:                                               ; preds = %52, %1
  %11 = load i32, ptr %4, align 4, !tbaa !11
  %12 = zext i32 %11 to i64
  %13 = getelementptr inbounds %"class.aabb::AABB", ptr %9, i32 0, i32 0
  %14 = call noundef i64 @_ZNKSt6vectorIdSaIdEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %13) #2
  %15 = icmp ult i64 %12, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %10
  store i32 2, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %55

17:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store double 1.000000e+00, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 0, ptr %7, align 4, !tbaa !11
  br label %18

18:                                               ; preds = %45, %17
  %19 = load i32, ptr %7, align 4, !tbaa !11
  %20 = zext i32 %19 to i64
  %21 = getelementptr inbounds %"class.aabb::AABB", ptr %9, i32 0, i32 0
  %22 = call noundef i64 @_ZNKSt6vectorIdSaIdEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %21) #2
  %23 = icmp ult i64 %20, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %18
  store i32 5, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %48

25:                                               ; preds = %18
  %26 = load i32, ptr %4, align 4, !tbaa !11
  %27 = load i32, ptr %7, align 4, !tbaa !11
  %28 = icmp eq i32 %26, %27
  br i1 %28, label %29, label %30

29:                                               ; preds = %25
  br label %45

30:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %31 = getelementptr inbounds %"class.aabb::AABB", ptr %9, i32 0, i32 1
  %32 = load i32, ptr %7, align 4, !tbaa !11
  %33 = zext i32 %32 to i64
  %34 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %31, i64 noundef %33) #2
  %35 = load double, ptr %34, align 8, !tbaa !9
  %36 = getelementptr inbounds %"class.aabb::AABB", ptr %9, i32 0, i32 0
  %37 = load i32, ptr %7, align 4, !tbaa !11
  %38 = zext i32 %37 to i64
  %39 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %36, i64 noundef %38) #2
  %40 = load double, ptr %39, align 8, !tbaa !9
  %41 = fsub double %35, %40
  store double %41, ptr %8, align 8, !tbaa !9
  %42 = load double, ptr %8, align 8, !tbaa !9
  %43 = load double, ptr %6, align 8, !tbaa !9
  %44 = fmul double %43, %42
  store double %44, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %45

45:                                               ; preds = %30, %29
  %46 = load i32, ptr %7, align 4, !tbaa !11
  %47 = add i32 %46, 1
  store i32 %47, ptr %7, align 4, !tbaa !11
  br label %18, !llvm.loop !13

48:                                               ; preds = %24
  %49 = load double, ptr %6, align 8, !tbaa !9
  %50 = load double, ptr %3, align 8, !tbaa !9
  %51 = fadd double %50, %49
  store double %51, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %52

52:                                               ; preds = %48
  %53 = load i32, ptr %4, align 4, !tbaa !11
  %54 = add i32 %53, 1
  store i32 %54, ptr %4, align 4, !tbaa !11
  br label %10, !llvm.loop !15

55:                                               ; preds = %16
  %56 = load double, ptr %3, align 8, !tbaa !9
  %57 = fmul double 2.000000e+00, %56
  store i32 1, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  ret double %57
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #0 align 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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
declare dso_local noundef i64 @_ZNKSt6vectorIdSaIdEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_ZNK4aabb4AABB18computeSurfaceAreaEv(ptr noundef nonnull align 8 dereferenceable(80) %0) local_unnamed_addr #0 align 2 {
  %2 = tail call noundef i64 @_ZNKSt6vectorIdSaIdEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #1
  %.not = icmp eq i64 %2, 0
  br i1 %.not, label %._crit_edge21, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %1
  %3 = getelementptr inbounds i8, ptr %0, i64 24
  br label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %._crit_edge
  %.020 = phi double [ 0.000000e+00, %.preheader.lr.ph ], [ %6, %._crit_edge ]
  %.01519 = phi i32 [ 0, %.preheader.lr.ph ], [ %7, %._crit_edge ]
  %4 = tail call noundef i64 @_ZNKSt6vectorIdSaIdEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #1
  %.not23 = icmp eq i64 %4, 0
  br i1 %.not23, label %._crit_edge, label %.lr.ph

._crit_edge21.loopexit:                           ; preds = %._crit_edge
  %5 = fmul double %6, 2.000000e+00
  br label %._crit_edge21

._crit_edge21:                                    ; preds = %._crit_edge21.loopexit, %1
  %.0.lcssa = phi double [ 0.000000e+00, %1 ], [ %5, %._crit_edge21.loopexit ]
  ret double %.0.lcssa

._crit_edge:                                      ; preds = %20, %.preheader
  %.014.lcssa = phi double [ 1.000000e+00, %.preheader ], [ %.1, %20 ]
  %6 = fadd double %.020, %.014.lcssa
  %7 = add i32 %.01519, 1
  %8 = zext i32 %7 to i64
  %9 = tail call noundef i64 @_ZNKSt6vectorIdSaIdEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #1
  %10 = icmp ugt i64 %9, %8
  br i1 %10, label %.preheader, label %._crit_edge21.loopexit, !llvm.loop !5

.lr.ph:                                           ; preds = %.preheader, %20
  %11 = phi i64 [ %22, %20 ], [ 0, %.preheader ]
  %.01318 = phi i32 [ %21, %20 ], [ 0, %.preheader ]
  %.01417 = phi double [ %.1, %20 ], [ 1.000000e+00, %.preheader ]
  %12 = icmp eq i32 %.01519, %.01318
  br i1 %12, label %20, label %13

13:                                               ; preds = %.lr.ph
  %14 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %3, i64 noundef %11) #1
  %15 = load double, ptr %14, align 8, !tbaa !7
  %16 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %11) #1
  %17 = load double, ptr %16, align 8, !tbaa !7
  %18 = fsub double %15, %17
  %19 = fmul double %.01417, %18
  br label %20

20:                                               ; preds = %.lr.ph, %13
  %.1 = phi double [ %.01417, %.lr.ph ], [ %19, %13 ]
  %21 = add i32 %.01318, 1
  %22 = zext i32 %21 to i64
  %23 = tail call noundef i64 @_ZNKSt6vectorIdSaIdEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #1
  %24 = icmp ugt i64 %23, %22
  br i1 %24, label %.lr.ph, label %._crit_edge, !llvm.loop !11
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 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 = { 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 = !{!"double", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = distinct !{!11, !6}


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