; LLVM IR from ThePhysicsGuys/Physics3D :: Physics3D/externalforces (externalForce)

; 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.P3D::ConstPartIter" = type { ptr, ptr, ptr }
%"struct.P3D::IteratorEnd" = type { i8 }
%"class.P3D::Physical" = type { %"class.P3D::RigidBody", ptr, %"class.P3D::UnorderedVector.0" }
%"class.P3D::RigidBody" = type { ptr, %"class.P3D::UnorderedVector", double, %"struct.P3D::Vector", %"class.P3D::SymmetricMatrix" }
%"class.P3D::UnorderedVector" = type { %"class.std::vector" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<P3D::AttachedPart, std::allocator<P3D::AttachedPart>>::_Vector_impl" }
%"struct.std::_Vector_base<P3D::AttachedPart, std::allocator<P3D::AttachedPart>>::_Vector_impl" = type { %"struct.std::_Vector_base<P3D::AttachedPart, std::allocator<P3D::AttachedPart>>::_Vector_impl_data" }
%"struct.std::_Vector_base<P3D::AttachedPart, std::allocator<P3D::AttachedPart>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"struct.P3D::Vector" = type { %union.anon }
%union.anon = type { [3 x double] }
%"class.P3D::SymmetricMatrix" = type { [6 x double] }
%"class.P3D::UnorderedVector.0" = type { %"class.std::vector.1" }
%"class.std::vector.1" = type { %"struct.std::_Vector_base.2" }
%"struct.std::_Vector_base.2" = type { %"struct.std::_Vector_base<P3D::ConnectedPhysical, std::allocator<P3D::ConnectedPhysical>>::_Vector_impl" }
%"struct.std::_Vector_base<P3D::ConnectedPhysical, std::allocator<P3D::ConnectedPhysical>>::_Vector_impl" = type { %"struct.std::_Vector_base<P3D::ConnectedPhysical, std::allocator<P3D::ConnectedPhysical>>::_Vector_impl_data" }
%"struct.std::_Vector_base<P3D::ConnectedPhysical, std::allocator<P3D::ConnectedPhysical>>::_Vector_impl_data" = type { ptr, ptr, ptr }

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZNK3P3D13ExternalForce27getPotentialEnergyForObjectEPKNS_14WorldPrototypeERKNS_17MotorizedPhysicalE(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef %1, ptr noundef nonnull align 8 dereferenceable(416) %2) unnamed_addr #0 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca double, align 8
  %8 = alloca ptr, align 8
  %9 = alloca %"struct.P3D::ConstPartIter", align 8
  %10 = alloca %"struct.P3D::IteratorEnd", align 1
  %11 = alloca %"struct.P3D::IteratorEnd", align 1
  %12 = alloca %"struct.P3D::IteratorEnd", align 1
  %13 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %14 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store double 0.000000e+00, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %"class.P3D::Physical", ptr %15, i32 0, i32 0
  store ptr %16, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 24, ptr %9) #4
  %17 = load ptr, ptr %8, align 8, !tbaa !5
  call void @_ZNK3P3D9RigidBody5beginEv(ptr dead_on_unwind writable sret(%"struct.P3D::ConstPartIter") align 8 %9, ptr noundef nonnull align 8 dereferenceable(112) %17)
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #4
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  call void @_ZNK3P3D9RigidBody3endEv(ptr noundef nonnull align 8 dereferenceable(112) %18)
  br label %19

19:                                               ; preds = %32, %3
  %20 = call noundef zeroext i1 @_ZNK3P3D13ConstPartIterneENS_11IteratorEndE(ptr noundef nonnull align 8 dereferenceable(24) %9)
  br i1 %20, label %22, label %21

21:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %33

22:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %23 = call noundef nonnull align 8 dereferenceable(200) ptr @_ZNK3P3D13ConstPartIterdeEv(ptr noundef nonnull align 8 dereferenceable(24) %9)
  store ptr %23, ptr %13, align 8, !tbaa !5
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = load ptr, ptr %13, align 8, !tbaa !5
  %26 = load ptr, ptr %14, align 8, !tbaa !11
  %27 = getelementptr inbounds ptr, ptr %26, i64 1
  %28 = load ptr, ptr %27, align 8
  %29 = call noundef double %28(ptr noundef nonnull align 8 dereferenceable(8) %14, ptr noundef %24, ptr noundef nonnull align 8 dereferenceable(200) %25)
  %30 = load double, ptr %7, align 8, !tbaa !9
  %31 = fadd double %30, %29
  store double %31, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  br label %32

32:                                               ; preds = %22
  call void @_ZN3P3D13ConstPartIterppEv(ptr noundef nonnull align 8 dereferenceable(24) %9)
  br label %19

33:                                               ; preds = %21
  %34 = load double, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret double %34
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK3P3D9RigidBody5beginEv(ptr dead_on_unwind noalias writable sret(%"struct.P3D::ConstPartIter") align 8, ptr noundef nonnull align 8 dereferenceable(112)) #0 align 2

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK3P3D13ConstPartIterneENS_11IteratorEndE(ptr noundef nonnull align 8 dereferenceable(24)) #3 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(200) ptr @_ZNK3P3D13ConstPartIterdeEv(ptr noundef nonnull align 8 dereferenceable(24)) #3 align 2

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3P3D13ConstPartIterppEv(ptr noundef nonnull align 8 dereferenceable(24)) #3 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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 = !{!"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"

%"struct.P3D::ConstPartIter" = type { ptr, ptr, ptr }

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZNK3P3D13ExternalForce27getPotentialEnergyForObjectEPKNS_14WorldPrototypeERKNS_17MotorizedPhysicalE(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef %1, ptr noundef nonnull align 8 dereferenceable(416) %2) unnamed_addr #0 align 2 {
  %4 = alloca %"struct.P3D::ConstPartIter", align 8
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %4) #4
  call void @_ZNK3P3D9RigidBody5beginEv(ptr dead_on_unwind nonnull writable sret(%"struct.P3D::ConstPartIter") align 8 %4, ptr noundef nonnull align 8 dereferenceable(112) %2)
  call void @_ZNK3P3D9RigidBody3endEv(ptr noundef nonnull align 8 dereferenceable(112) %2)
  %5 = call noundef zeroext i1 @_ZNK3P3D13ConstPartIterneENS_11IteratorEndE(ptr noundef nonnull align 8 dereferenceable(24) %4)
  br i1 %5, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %3
  %.0.lcssa = phi double [ 0.000000e+00, %3 ], [ %11, %.lr.ph ]
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %4) #4
  ret double %.0.lcssa

.lr.ph:                                           ; preds = %3, %.lr.ph
  %.08 = phi double [ %11, %.lr.ph ], [ 0.000000e+00, %3 ]
  %6 = call noundef nonnull align 8 dereferenceable(200) ptr @_ZNK3P3D13ConstPartIterdeEv(ptr noundef nonnull align 8 dereferenceable(24) %4)
  %7 = load ptr, ptr %0, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %7, i64 8
  %9 = load ptr, ptr %8, align 8
  %10 = call noundef double %9(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef %1, ptr noundef nonnull align 8 dereferenceable(200) %6)
  %11 = fadd double %.08, %10
  call void @_ZN3P3D13ConstPartIterppEv(ptr noundef nonnull align 8 dereferenceable(24) %4)
  %12 = call noundef zeroext i1 @_ZNK3P3D13ConstPartIterneENS_11IteratorEndE(ptr noundef nonnull align 8 dereferenceable(24) %4)
  br i1 %12, label %.lr.ph, label %._crit_edge
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK3P3D9RigidBody5beginEv(ptr dead_on_unwind noalias writable sret(%"struct.P3D::ConstPartIter") align 8, ptr noundef nonnull align 8 dereferenceable(112)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNK3P3D9RigidBody3endEv(ptr noundef nonnull align 8 dereferenceable(112)) local_unnamed_addr #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK3P3D13ConstPartIterneENS_11IteratorEndE(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #3 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(200) ptr @_ZNK3P3D13ConstPartIterdeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #3 align 2

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3P3D13ConstPartIterppEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #3 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}


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