; LLVM IR from aparis69/Rock-fracturing :: Code/Source/blocks-sdf.ll (ZNK8SDFBlock6SignedERK7Vector3)

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

%struct.SDFBlock = type { %struct.SDFNode, %"class.std::vector.5", double }
%struct.SDFNode = type { ptr, %class.Box }
%class.Box = type { %struct.Vector3, %struct.Vector3 }
%struct.Vector3 = type { double, double, double }
%"class.std::vector.5" = type { %"struct.std::_Vector_base.6" }
%"struct.std::_Vector_base.6" = type { %"struct.std::_Vector_base<Plane, std::allocator<Plane>>::_Vector_impl" }
%"struct.std::_Vector_base<Plane, std::allocator<Plane>>::_Vector_impl" = type { %"struct.std::_Vector_base<Plane, std::allocator<Plane>>::_Vector_impl_data" }
%"struct.std::_Vector_base<Plane, std::allocator<Plane>>::_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
declare dso_local noundef double @_ZNK8SDFBlock19SmoothingPolynomialEddd(ptr noundef nonnull align 8 dereferenceable(88), double noundef, double noundef, double noundef) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZNK8SDFBlock6SignedERK7Vector3(ptr noundef nonnull align 8 dereferenceable(88) %0, ptr noundef nonnull align 8 dereferenceable(24) %1) unnamed_addr #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca double, align 8
  %6 = alloca i32, align 4
  %7 = alloca double, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %9 = getelementptr inbounds %struct.SDFBlock, ptr %8, i32 0, i32 1
  %10 = call noundef nonnull align 8 dereferenceable(56) ptr @_ZNKSt6vectorI5PlaneSaIS0_EE2atEm(ptr noundef nonnull align 8 dereferenceable(24) %9, i64 noundef 0)
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = call noundef double @_ZNK5Plane6SignedERK7Vector3(ptr noundef nonnull align 8 dereferenceable(56) %10, ptr noundef nonnull align 8 dereferenceable(24) %11)
  store double %12, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 1, ptr %6, align 4, !tbaa !11
  br label %13

13:                                               ; preds = %35, %2
  %14 = load i32, ptr %6, align 4, !tbaa !11
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds %struct.SDFBlock, ptr %8, i32 0, i32 1
  %17 = call noundef i64 @_ZNKSt6vectorI5PlaneSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %16) #4
  %18 = icmp ult i64 %15, %17
  br i1 %18, label %20, label %19

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

20:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %21 = getelementptr inbounds %struct.SDFBlock, ptr %8, i32 0, i32 1
  %22 = load i32, ptr %6, align 4, !tbaa !11
  %23 = sext i32 %22 to i64
  %24 = call noundef nonnull align 8 dereferenceable(56) ptr @_ZNKSt6vectorI5PlaneSaIS0_EE2atEm(ptr noundef nonnull align 8 dereferenceable(24) %21, i64 noundef %23)
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = call noundef double @_ZNK5Plane6SignedERK7Vector3(ptr noundef nonnull align 8 dereferenceable(56) %24, ptr noundef nonnull align 8 dereferenceable(24) %25)
  store double %26, ptr %7, align 8, !tbaa !9
  %27 = load double, ptr %5, align 8, !tbaa !9
  %28 = fneg double %27
  %29 = load double, ptr %7, align 8, !tbaa !9
  %30 = fneg double %29
  %31 = getelementptr inbounds %struct.SDFBlock, ptr %8, i32 0, i32 2
  %32 = load double, ptr %31, align 8, !tbaa !13
  %33 = call noundef double @_ZNK8SDFBlock19SmoothingPolynomialEddd(ptr noundef nonnull align 8 dereferenceable(88) %8, double noundef %28, double noundef %30, double noundef %32)
  %34 = fneg double %33
  store double %34, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %35

35:                                               ; preds = %20
  %36 = load i32, ptr %6, align 4, !tbaa !11
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %6, align 4, !tbaa !11
  br label %13, !llvm.loop !22

38:                                               ; preds = %19
  %39 = load double, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret double %39
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(56) ptr @_ZNKSt6vectorI5PlaneSaIS0_EE2atEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK5Plane6SignedERK7Vector3(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef nonnull align 8 dereferenceable(24)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorI5PlaneSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #3 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 = { 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 #3 = { 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 #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 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !10, i64 80}
!14 = !{!"_ZTS8SDFBlock", !15, i64 0, !18, i64 56, !10, i64 80}
!15 = !{!"_ZTS7SDFNode", !16, i64 8}
!16 = !{!"_ZTS3Box", !17, i64 0, !17, i64 24}
!17 = !{!"_ZTS7Vector3", !10, i64 0, !10, i64 8, !10, i64 16}
!18 = !{!"_ZTSSt6vectorI5PlaneSaIS0_EE", !19, i64 0}
!19 = !{!"_ZTSSt12_Vector_baseI5PlaneSaIS0_EE", !20, i64 0}
!20 = !{!"_ZTSNSt12_Vector_baseI5PlaneSaIS0_EE12_Vector_implE", !21, i64 0}
!21 = !{!"_ZTSNSt12_Vector_baseI5PlaneSaIS0_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!22 = distinct !{!22, !23}
!23 = !{!"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 uwtable
declare dso_local noundef double @_ZNK8SDFBlock19SmoothingPolynomialEddd(ptr noundef nonnull align 8 dereferenceable(88), double noundef, double noundef, double noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZNK8SDFBlock6SignedERK7Vector3(ptr noundef nonnull align 8 dereferenceable(88) %0, ptr noundef nonnull align 8 dereferenceable(24) %1) unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 56
  %4 = tail call noundef nonnull align 8 dereferenceable(56) ptr @_ZNKSt6vectorI5PlaneSaIS0_EE2atEm(ptr noundef nonnull align 8 dereferenceable(24) %3, i64 noundef 0)
  %5 = tail call noundef double @_ZNK5Plane6SignedERK7Vector3(ptr noundef nonnull align 8 dereferenceable(56) %4, ptr noundef nonnull align 8 dereferenceable(24) %1)
  %6 = tail call noundef i64 @_ZNKSt6vectorI5PlaneSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %3) #3
  %7 = icmp ugt i64 %6, 1
  br i1 %7, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %2
  %8 = getelementptr inbounds i8, ptr %0, i64 80
  br label %9

._crit_edge:                                      ; preds = %9, %2
  %.0.lcssa = phi double [ %5, %2 ], [ %16, %9 ]
  ret double %.0.lcssa

9:                                                ; preds = %.lr.ph, %9
  %indvars.iv = phi i64 [ 1, %.lr.ph ], [ %indvars.iv.next, %9 ]
  %.011 = phi double [ %5, %.lr.ph ], [ %16, %9 ]
  %10 = tail call noundef nonnull align 8 dereferenceable(56) ptr @_ZNKSt6vectorI5PlaneSaIS0_EE2atEm(ptr noundef nonnull align 8 dereferenceable(24) %3, i64 noundef %indvars.iv)
  %11 = tail call noundef double @_ZNK5Plane6SignedERK7Vector3(ptr noundef nonnull align 8 dereferenceable(56) %10, ptr noundef nonnull align 8 dereferenceable(24) %1)
  %12 = fneg double %.011
  %13 = fneg double %11
  %14 = load double, ptr %8, align 8, !tbaa !5
  %15 = tail call noundef double @_ZNK8SDFBlock19SmoothingPolynomialEddd(ptr noundef nonnull align 8 dereferenceable(88) %0, double noundef %12, double noundef %13, double noundef %14)
  %16 = fneg double %15
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %17 = tail call noundef i64 @_ZNKSt6vectorI5PlaneSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %3) #3
  %18 = icmp ugt i64 %17, %indvars.iv.next
  br i1 %18, label %9, label %._crit_edge, !llvm.loop !18
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(56) ptr @_ZNKSt6vectorI5PlaneSaIS0_EE2atEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK5Plane6SignedERK7Vector3(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorI5PlaneSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #2 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 = { 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 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 = { 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, !10, i64 80}
!6 = !{!"_ZTS8SDFBlock", !7, i64 0, !13, i64 56, !10, i64 80}
!7 = !{!"_ZTS7SDFNode", !8, i64 8}
!8 = !{!"_ZTS3Box", !9, i64 0, !9, i64 24}
!9 = !{!"_ZTS7Vector3", !10, i64 0, !10, i64 8, !10, i64 16}
!10 = !{!"double", !11, i64 0}
!11 = !{!"omnipotent char", !12, i64 0}
!12 = !{!"Simple C++ TBAA"}
!13 = !{!"_ZTSSt6vectorI5PlaneSaIS0_EE", !14, i64 0}
!14 = !{!"_ZTSSt12_Vector_baseI5PlaneSaIS0_EE", !15, i64 0}
!15 = !{!"_ZTSNSt12_Vector_baseI5PlaneSaIS0_EE12_Vector_implE", !16, i64 0}
!16 = !{!"_ZTSNSt12_Vector_baseI5PlaneSaIS0_EE17_Vector_impl_dataE", !17, i64 0, !17, i64 8, !17, i64 16}
!17 = !{!"any pointer", !11, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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