; LLVM IR from erayzesen/QuarkPhysics :: QuarkPhysics/qrigidbody.ll (ZN10QRigidBody12ApplyImpulseE7QVectorS0_)

; 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.QVector = type { float, float }
%class.QBody = type <{ ptr, float, float, ptr, %struct.QVector, %struct.QVector, float, float, %class.QAABB, i32, i8, i8, i8, i8, float, i32, i8, [3 x i8], float, i8, i8, [2 x i8], %struct.QVector, float, float, float, float, float, i32, i32, i8, i8, i8, i8, i32, i32, i32, i8, [3 x i8], %"class.std::function", %"class.std::function", %"class.std::function.0", i8, [7 x i8], %"class.std::vector", i32, i8, [3 x i8] }>
%class.QAABB = type { %struct.QVector, %struct.QVector, %struct.QVector, float }
%"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::function.0" = type { %"class.std::_Function_base", ptr }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<QMesh *, std::allocator<QMesh *>>::_Vector_impl" }
%"struct.std::_Vector_base<QMesh *, std::allocator<QMesh *>>::_Vector_impl" = type { %"struct.std::_Vector_base<QMesh *, std::allocator<QMesh *>>::_Vector_impl_data" }
%"struct.std::_Vector_base<QMesh *, std::allocator<QMesh *>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%class.QRigidBody = type { %class.QBody.base, i8, %struct.QVector, float, [4 x i8] }
%class.QBody.base = type <{ ptr, float, float, ptr, %struct.QVector, %struct.QVector, float, float, %class.QAABB, i32, i8, i8, i8, i8, float, i32, i8, [3 x i8], float, i8, i8, [2 x i8], %struct.QVector, float, float, float, float, float, i32, i32, i8, i8, i8, i8, i32, i32, i32, i8, [3 x i8], %"class.std::function", %"class.std::function", %"class.std::function.0", i8, [7 x i8], %"class.std::vector", i32, i8 }>

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZNK7QVector3DotES_(ptr noundef nonnull align 4 dereferenceable(8), <2 x float>) #0 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local <2 x float> @_ZNK7QVector13PerpendicularEv(ptr noundef nonnull align 4 dereferenceable(8)) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef float @_ZN5QBody10GetInertiaEv(ptr noundef nonnull align 8 dereferenceable(293)) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN10QRigidBody12ApplyImpulseE7QVectorS0_(ptr noundef nonnull align 8 dereferenceable(308) %0, <2 x float> %1, <2 x float> %2) #3 align 2 {
  %4 = alloca %struct.QVector, align 4
  %5 = alloca %struct.QVector, align 4
  %6 = alloca ptr, align 8
  %7 = alloca float, align 4
  %8 = alloca %struct.QVector, align 4
  store <2 x float> %1, ptr %4, align 4
  store <2 x float> %2, ptr %5, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  %9 = load ptr, ptr %6, align 8
  %10 = getelementptr inbounds %class.QBody, ptr %9, i32 0, i32 5
  %11 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZN7QVectormIERKS_(ptr noundef nonnull align 4 dereferenceable(8) %10, ptr noundef nonnull align 4 dereferenceable(8) %4)
  %12 = getelementptr inbounds %class.QRigidBody, ptr %9, i32 0, i32 1
  %13 = load i8, ptr %12, align 1, !tbaa !9, !range !27, !noundef !28
  %14 = trunc i8 %13 to i1
  %15 = zext i1 %14 to i32
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %27

17:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  %18 = call <2 x float> @_ZNK7QVector13PerpendicularEv(ptr noundef nonnull align 4 dereferenceable(8) %4)
  store <2 x float> %18, ptr %8, align 4
  %19 = load <2 x float>, ptr %8, align 4
  %20 = call noundef float @_ZNK7QVector3DotES_(ptr noundef nonnull align 4 dereferenceable(8) %5, <2 x float> %19)
  %21 = call noundef float @_ZN5QBody10GetInertiaEv(ptr noundef nonnull align 8 dereferenceable(293) %9)
  %22 = fdiv float %20, %21
  store float %22, ptr %7, align 4, !tbaa !29
  %23 = load float, ptr %7, align 4, !tbaa !29
  %24 = getelementptr inbounds %class.QBody, ptr %9, i32 0, i32 7
  %25 = load float, ptr %24, align 4, !tbaa !30
  %26 = fsub float %25, %23
  store float %26, ptr %24, align 4, !tbaa !30
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  br label %27

27:                                               ; preds = %17, %3
  ret ptr %9
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(8) ptr @_ZN7QVectormIERKS_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) #4 align 2

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

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

attributes #0 = { inlinehint mustprogress nounwind uwtable "min-legal-vector-width"="64" "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 uwtable "min-legal-vector-width"="64" "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 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 uwtable "min-legal-vector-width"="64" "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 = { 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 #5 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { 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, !16, i64 293}
!10 = !{!"_ZTS10QRigidBody", !11, i64 0, !16, i64 293, !13, i64 296, !12, i64 304}
!11 = !{!"_ZTS5QBody", !12, i64 8, !12, i64 12, !6, i64 16, !13, i64 24, !13, i64 32, !12, i64 40, !12, i64 44, !14, i64 48, !15, i64 76, !16, i64 80, !16, i64 81, !16, i64 82, !12, i64 84, !17, i64 88, !16, i64 92, !12, i64 96, !16, i64 100, !16, i64 101, !13, i64 104, !12, i64 112, !12, i64 116, !12, i64 120, !12, i64 124, !12, i64 128, !18, i64 132, !18, i64 136, !16, i64 140, !16, i64 141, !16, i64 142, !18, i64 144, !18, i64 148, !18, i64 152, !16, i64 156, !19, i64 160, !19, i64 192, !21, i64 224, !16, i64 256, !22, i64 264, !26, i64 288, !16, i64 292}
!12 = !{!"float", !7, i64 0}
!13 = !{!"_ZTS7QVector", !12, i64 0, !12, i64 4}
!14 = !{!"_ZTS5QAABB", !13, i64 0, !13, i64 8, !13, i64 16, !12, i64 24}
!15 = !{!"_ZTSN5QBody5ModesE", !7, i64 0}
!16 = !{!"bool", !7, i64 0}
!17 = !{!"_ZTSN5QBody9BodyTypesE", !7, i64 0}
!18 = !{!"int", !7, i64 0}
!19 = !{!"_ZTSSt8functionIFvP5QBodyEE", !20, i64 0, !6, i64 24}
!20 = !{!"_ZTSSt14_Function_base", !7, i64 0, !6, i64 16}
!21 = !{!"_ZTSSt8functionIFbP5QBodyNS0_13CollisionInfoEEE", !20, i64 0, !6, i64 24}
!22 = !{!"_ZTSSt6vectorIP5QMeshSaIS1_EE", !23, i64 0}
!23 = !{!"_ZTSSt12_Vector_baseIP5QMeshSaIS1_EE", !24, i64 0}
!24 = !{!"_ZTSNSt12_Vector_baseIP5QMeshSaIS1_EE12_Vector_implE", !25, i64 0}
!25 = !{!"_ZTSNSt12_Vector_baseIP5QMeshSaIS1_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!26 = !{!"_ZTSN5QBody16SimulationModelsE", !7, i64 0}
!27 = !{i8 0, i8 2}
!28 = !{}
!29 = !{!12, !12, i64 0}
!30 = !{!11, !12, i64 44}


; 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.QVector = type { float, float }

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZNK7QVector3DotES_(ptr noundef nonnull align 4 dereferenceable(8), <2 x float>) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local <2 x float> @_ZNK7QVector13PerpendicularEv(ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef float @_ZN5QBody10GetInertiaEv(ptr noundef nonnull align 8 dereferenceable(293)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef nonnull ptr @_ZN10QRigidBody12ApplyImpulseE7QVectorS0_(ptr noundef nonnull returned align 8 dereferenceable(308) %0, <2 x float> %1, <2 x float> %2) local_unnamed_addr #3 align 2 {
  %4 = alloca %struct.QVector, align 8
  %5 = alloca %struct.QVector, align 8
  store <2 x float> %1, ptr %4, align 8
  store <2 x float> %2, ptr %5, align 8
  %6 = getelementptr inbounds i8, ptr %0, i64 32
  %7 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZN7QVectormIERKS_(ptr noundef nonnull align 4 dereferenceable(8) %6, ptr noundef nonnull align 4 dereferenceable(8) %4)
  %8 = getelementptr inbounds i8, ptr %0, i64 293
  %9 = load i8, ptr %8, align 1, !tbaa !5, !range !26, !noundef !27
  %10 = icmp eq i8 %9, 0
  br i1 %10, label %11, label %19

11:                                               ; preds = %3
  %12 = call <2 x float> @_ZNK7QVector13PerpendicularEv(ptr noundef nonnull align 4 dereferenceable(8) %4)
  %13 = call noundef float @_ZNK7QVector3DotES_(ptr noundef nonnull align 4 dereferenceable(8) %5, <2 x float> %12)
  %14 = call noundef float @_ZN5QBody10GetInertiaEv(ptr noundef nonnull align 8 dereferenceable(293) %0)
  %15 = fdiv float %13, %14
  %16 = getelementptr inbounds i8, ptr %0, i64 44
  %17 = load float, ptr %16, align 4, !tbaa !28
  %18 = fsub float %17, %15
  store float %18, ptr %16, align 4, !tbaa !28
  br label %19

19:                                               ; preds = %11, %3
  ret ptr %0
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(8) ptr @_ZN7QVectormIERKS_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #4 align 2

attributes #0 = { inlinehint mustprogress nounwind uwtable "min-legal-vector-width"="64" "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 uwtable "min-legal-vector-width"="64" "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 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 uwtable "min-legal-vector-width"="64" "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 = { 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, !15, i64 293}
!6 = !{!"_ZTS10QRigidBody", !7, i64 0, !15, i64 293, !12, i64 296, !8, i64 304}
!7 = !{!"_ZTS5QBody", !8, i64 8, !8, i64 12, !11, i64 16, !12, i64 24, !12, i64 32, !8, i64 40, !8, i64 44, !13, i64 48, !14, i64 76, !15, i64 80, !15, i64 81, !15, i64 82, !8, i64 84, !16, i64 88, !15, i64 92, !8, i64 96, !15, i64 100, !15, i64 101, !12, i64 104, !8, i64 112, !8, i64 116, !8, i64 120, !8, i64 124, !8, i64 128, !17, i64 132, !17, i64 136, !15, i64 140, !15, i64 141, !15, i64 142, !17, i64 144, !17, i64 148, !17, i64 152, !15, i64 156, !18, i64 160, !18, i64 192, !20, i64 224, !15, i64 256, !21, i64 264, !25, i64 288, !15, i64 292}
!8 = !{!"float", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"any pointer", !9, i64 0}
!12 = !{!"_ZTS7QVector", !8, i64 0, !8, i64 4}
!13 = !{!"_ZTS5QAABB", !12, i64 0, !12, i64 8, !12, i64 16, !8, i64 24}
!14 = !{!"_ZTSN5QBody5ModesE", !9, i64 0}
!15 = !{!"bool", !9, i64 0}
!16 = !{!"_ZTSN5QBody9BodyTypesE", !9, i64 0}
!17 = !{!"int", !9, i64 0}
!18 = !{!"_ZTSSt8functionIFvP5QBodyEE", !19, i64 0, !11, i64 24}
!19 = !{!"_ZTSSt14_Function_base", !9, i64 0, !11, i64 16}
!20 = !{!"_ZTSSt8functionIFbP5QBodyNS0_13CollisionInfoEEE", !19, i64 0, !11, i64 24}
!21 = !{!"_ZTSSt6vectorIP5QMeshSaIS1_EE", !22, i64 0}
!22 = !{!"_ZTSSt12_Vector_baseIP5QMeshSaIS1_EE", !23, i64 0}
!23 = !{!"_ZTSNSt12_Vector_baseIP5QMeshSaIS1_EE12_Vector_implE", !24, i64 0}
!24 = !{!"_ZTSNSt12_Vector_baseIP5QMeshSaIS1_EE17_Vector_impl_dataE", !11, i64 0, !11, i64 8, !11, i64 16}
!25 = !{!"_ZTSN5QBody16SimulationModelsE", !9, i64 0}
!26 = !{i8 0, i8 2}
!27 = !{}
!28 = !{!7, !8, i64 44}


; Effective O3 passes: GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass