; LLVM IR from jrouwe/JoltPhysics :: Jolt/Physics/Constraints (SliderConstraint)

; 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.JPH::Vec3" = type { %union.anon }
%union.anon = type { <4 x float> }
%"class.JPH::SliderConstraint" = type { %"class.JPH::TwoBodyConstraint", %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Quat", i8, float, float, %"class.JPH::SpringSettings", float, %"class.JPH::MotorSettings", i32, float, float, %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Vec3", float, [12 x i8], %"class.JPH::DualAxisConstraintPart", %"class.JPH::RotationEulerConstraintPart", %"class.JPH::AxisConstraintPart", %"class.JPH::AxisConstraintPart" }
%"class.JPH::TwoBodyConstraint" = type { %"class.JPH::Constraint", ptr, ptr }
%"class.JPH::Constraint" = type { ptr, %"class.JPH::RefTarget.3", i32, i32, i8, i8, i8, i64 }
%"class.JPH::RefTarget.3" = type { %"struct.std::atomic" }
%"struct.std::atomic" = type { %"struct.std::__atomic_base" }
%"struct.std::__atomic_base" = type { i32 }
%"class.JPH::Quat" = type { %"class.JPH::Vec4" }
%"class.JPH::Vec4" = type { %union.anon.4 }
%union.anon.4 = type { <4 x float> }
%"class.JPH::SpringSettings" = type { i8, %union.anon.2, float }
%union.anon.2 = type { float }
%"class.JPH::MotorSettings" = type { %"class.JPH::SpringSettings", float, float, float, float }
%"class.JPH::DualAxisConstraintPart" = type <{ %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Matrix", %"class.JPH::Vector", [8 x i8] }>
%"class.JPH::Matrix" = type { [2 x %"class.JPH::Vector"] }
%"class.JPH::Vector" = type { [2 x float] }
%"class.JPH::RotationEulerConstraintPart" = type { %"class.JPH::Mat44", %"class.JPH::Mat44", %"class.JPH::Mat44", %"class.JPH::Vec3" }
%"class.JPH::Mat44" = type { [4 x %"class.JPH::Vec4"] }
%"class.JPH::AxisConstraintPart" = type { %"class.JPH::Float3", %"class.JPH::Float3", %"class.JPH::Float3", %"class.JPH::Float3", float, %"class.JPH::SpringPart", float }
%"class.JPH::Float3" = type { float, float, float }
%"class.JPH::SpringPart" = type { float, float }

; 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: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local { double, double } @_ZNK3JPH5Mat44mlENS_4Vec3E(ptr noundef nonnull align 16 dereferenceable(64), double, double) #2 align 2

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef float @_ZNK3JPH4Vec33DotES0_(ptr noundef nonnull align 16 dereferenceable(16), double, double) #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3JPH16SliderConstraint31CalculateSlidingAxisAndPositionERKNS_5Mat44E(ptr noundef nonnull align 16 dereferenceable(832) %0, ptr noundef nonnull align 16 dereferenceable(64) %1) #4 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %"class.JPH::Vec3", align 16
  %6 = alloca %"class.JPH::Vec3", align 16
  %7 = alloca %"class.JPH::Vec3", align 16
  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
  %9 = getelementptr inbounds %"class.JPH::SliderConstraint", ptr %8, i32 0, i32 7
  %10 = load i8, ptr %9, align 16, !tbaa !9, !range !35, !noundef !36
  %11 = trunc i8 %10 to i1
  br i1 %11, label %20, label %12

12:                                               ; preds = %2
  %13 = getelementptr inbounds %"class.JPH::SliderConstraint", ptr %8, i32 0, i32 13
  %14 = load i32, ptr %13, align 8, !tbaa !37
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %20, label %16

16:                                               ; preds = %12
  %17 = getelementptr inbounds %"class.JPH::SliderConstraint", ptr %8, i32 0, i32 11
  %18 = load float, ptr %17, align 8, !tbaa !38
  %19 = fcmp ogt float %18, 0.000000e+00
  br i1 %19, label %20, label %43

20:                                               ; preds = %16, %12, %2
  call void @llvm.lifetime.start.p0(i64 16, ptr %5) #5
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %"class.JPH::SliderConstraint", ptr %8, i32 0, i32 3
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %6, ptr align 16 %22, i64 16, i1 false), !tbaa.struct !39
  %23 = getelementptr inbounds { double, double }, ptr %6, i32 0, i32 0
  %24 = load double, ptr %23, align 16
  %25 = getelementptr inbounds { double, double }, ptr %6, i32 0, i32 1
  %26 = load double, ptr %25, align 8
  %27 = call { double, double } @_ZNK3JPH5Mat44mlENS_4Vec3E(ptr noundef nonnull align 16 dereferenceable(64) %21, double %24, double %26)
  %28 = getelementptr inbounds %"class.JPH::Vec3", ptr %5, i32 0, i32 0
  %29 = getelementptr inbounds %union.anon, ptr %28, i32 0, i32 0
  %30 = getelementptr inbounds { double, double }, ptr %29, i32 0, i32 0
  %31 = extractvalue { double, double } %27, 0
  store double %31, ptr %30, align 16
  %32 = getelementptr inbounds { double, double }, ptr %29, i32 0, i32 1
  %33 = extractvalue { double, double } %27, 1
  store double %33, ptr %32, align 8
  %34 = getelementptr inbounds %"class.JPH::SliderConstraint", ptr %8, i32 0, i32 19
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %34, ptr align 16 %5, i64 16, i1 false), !tbaa.struct !39
  call void @llvm.lifetime.end.p0(i64 16, ptr %5) #5
  %35 = getelementptr inbounds %"class.JPH::SliderConstraint", ptr %8, i32 0, i32 18
  %36 = getelementptr inbounds %"class.JPH::SliderConstraint", ptr %8, i32 0, i32 19
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %7, ptr align 16 %36, i64 16, i1 false), !tbaa.struct !39
  %37 = getelementptr inbounds { double, double }, ptr %7, i32 0, i32 0
  %38 = load double, ptr %37, align 16
  %39 = getelementptr inbounds { double, double }, ptr %7, i32 0, i32 1
  %40 = load double, ptr %39, align 8
  %41 = call noundef float @_ZNK3JPH4Vec33DotES0_(ptr noundef nonnull align 16 dereferenceable(16) %35, double %38, double %40)
  %42 = getelementptr inbounds %"class.JPH::SliderConstraint", ptr %8, i32 0, i32 22
  store float %41, ptr %42, align 16, !tbaa !41
  br label %43

43:                                               ; preds = %20, %16
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { alwaysinline mustprogress uwtable "min-legal-vector-width"="128" "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 = { alwaysinline 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 = { 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 #5 = { 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, !17, i64 144}
!10 = !{!"_ZTSN3JPH16SliderConstraintE", !11, i64 0, !19, i64 48, !19, i64 64, !19, i64 80, !19, i64 96, !19, i64 112, !20, i64 128, !17, i64 144, !22, i64 148, !22, i64 152, !23, i64 156, !22, i64 168, !25, i64 172, !26, i64 200, !22, i64 204, !22, i64 208, !19, i64 224, !19, i64 240, !19, i64 256, !19, i64 272, !19, i64 288, !19, i64 304, !22, i64 320, !27, i64 336, !30, i64 496, !32, i64 704, !32, i64 768}
!11 = !{!"_ZTSN3JPH17TwoBodyConstraintE", !12, i64 0, !6, i64 32, !6, i64 40}
!12 = !{!"_ZTSN3JPH10ConstraintE", !13, i64 8, !16, i64 12, !16, i64 16, !7, i64 20, !7, i64 21, !17, i64 22, !18, i64 24}
!13 = !{!"_ZTSN3JPH9RefTargetINS_10ConstraintEEE", !14, i64 0}
!14 = !{!"_ZTSSt6atomicIjE", !15, i64 0}
!15 = !{!"_ZTSSt13__atomic_baseIjE", !16, i64 0}
!16 = !{!"int", !7, i64 0}
!17 = !{!"bool", !7, i64 0}
!18 = !{!"long", !7, i64 0}
!19 = !{!"_ZTSN3JPH4Vec3E", !7, i64 0}
!20 = !{!"_ZTSN3JPH4QuatE", !21, i64 0}
!21 = !{!"_ZTSN3JPH4Vec4E", !7, i64 0}
!22 = !{!"float", !7, i64 0}
!23 = !{!"_ZTSN3JPH14SpringSettingsE", !24, i64 0, !7, i64 4, !22, i64 8}
!24 = !{!"_ZTSN3JPH11ESpringModeE", !7, i64 0}
!25 = !{!"_ZTSN3JPH13MotorSettingsE", !23, i64 0, !22, i64 12, !22, i64 16, !22, i64 20, !22, i64 24}
!26 = !{!"_ZTSN3JPH11EMotorStateE", !7, i64 0}
!27 = !{!"_ZTSN3JPH22DualAxisConstraintPartE", !19, i64 0, !19, i64 16, !19, i64 32, !19, i64 48, !19, i64 64, !19, i64 80, !19, i64 96, !19, i64 112, !28, i64 128, !29, i64 144}
!28 = !{!"_ZTSN3JPH6MatrixILj2ELj2EEE", !7, i64 0}
!29 = !{!"_ZTSN3JPH6VectorILj2EEE", !7, i64 0}
!30 = !{!"_ZTSN3JPH27RotationEulerConstraintPartE", !31, i64 0, !31, i64 64, !31, i64 128, !19, i64 192}
!31 = !{!"_ZTSN3JPH5Mat44E", !7, i64 0}
!32 = !{!"_ZTSN3JPH18AxisConstraintPartE", !33, i64 0, !33, i64 12, !33, i64 24, !33, i64 36, !22, i64 48, !34, i64 52, !22, i64 60}
!33 = !{!"_ZTSN3JPH6Float3E", !22, i64 0, !22, i64 4, !22, i64 8}
!34 = !{!"_ZTSN3JPH10SpringPartE", !22, i64 0, !22, i64 4}
!35 = !{i8 0, i8 2}
!36 = !{}
!37 = !{!10, !26, i64 200}
!38 = !{!10, !22, i64 168}
!39 = !{i64 0, i64 16, !40}
!40 = !{!7, !7, i64 0}
!41 = !{!10, !22, i64 320}


; 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: alwaysinline mustprogress uwtable
declare dso_local { double, double } @_ZNK3JPH5Mat44mlENS_4Vec3E(ptr noundef nonnull align 16 dereferenceable(64), double, double) local_unnamed_addr #0 align 2

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef float @_ZNK3JPH4Vec33DotES0_(ptr noundef nonnull align 16 dereferenceable(16), double, double) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3JPH16SliderConstraint31CalculateSlidingAxisAndPositionERKNS_5Mat44E(ptr noundef nonnull align 16 dereferenceable(832) %0, ptr noundef nonnull align 16 dereferenceable(64) %1) local_unnamed_addr #2 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 144
  %4 = load i8, ptr %3, align 16, !tbaa !5, !range !34, !noundef !35
  %5 = trunc nuw i8 %4 to i1
  %6 = getelementptr inbounds i8, ptr %0, i64 200
  %7 = load i32, ptr %6, align 8
  %.not = icmp ne i32 %7, 0
  %or.cond.not10 = select i1 %5, i1 true, i1 %.not
  %8 = getelementptr inbounds i8, ptr %0, i64 168
  %9 = load float, ptr %8, align 8
  %10 = fcmp ogt float %9, 0.000000e+00
  %or.cond9 = select i1 %or.cond.not10, i1 true, i1 %10
  br i1 %or.cond9, label %11, label %20

11:                                               ; preds = %2
  %12 = getelementptr inbounds i8, ptr %0, i64 80
  %.sroa.01.0.copyload = load double, ptr %12, align 16
  %.sroa.22.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 88
  %.sroa.22.0.copyload = load double, ptr %.sroa.22.0..sroa_idx, align 8, !tbaa !36
  %13 = tail call { double, double } @_ZNK3JPH5Mat44mlENS_4Vec3E(ptr noundef nonnull align 16 dereferenceable(64) %1, double %.sroa.01.0.copyload, double %.sroa.22.0.copyload)
  %14 = extractvalue { double, double } %13, 0
  %15 = extractvalue { double, double } %13, 1
  %16 = getelementptr inbounds i8, ptr %0, i64 272
  store double %14, ptr %16, align 16
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 280
  store double %15, ptr %.sroa.4.0..sroa_idx, align 8, !tbaa !36
  %17 = getelementptr inbounds i8, ptr %0, i64 256
  %18 = tail call noundef float @_ZNK3JPH4Vec33DotES0_(ptr noundef nonnull align 16 dereferenceable(16) %17, double %14, double %15)
  %19 = getelementptr inbounds i8, ptr %0, i64 320
  store float %18, ptr %19, align 16, !tbaa !37
  br label %20

20:                                               ; preds = %2, %11
  ret void
}

attributes #0 = { alwaysinline mustprogress uwtable "min-legal-vector-width"="128" "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 = { alwaysinline 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 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 144}
!6 = !{!"_ZTSN3JPH16SliderConstraintE", !7, i64 0, !18, i64 48, !18, i64 64, !18, i64 80, !18, i64 96, !18, i64 112, !19, i64 128, !15, i64 144, !21, i64 148, !21, i64 152, !22, i64 156, !21, i64 168, !24, i64 172, !25, i64 200, !21, i64 204, !21, i64 208, !18, i64 224, !18, i64 240, !18, i64 256, !18, i64 272, !18, i64 288, !18, i64 304, !21, i64 320, !26, i64 336, !29, i64 496, !31, i64 704, !31, i64 768}
!7 = !{!"_ZTSN3JPH17TwoBodyConstraintE", !8, i64 0, !17, i64 32, !17, i64 40}
!8 = !{!"_ZTSN3JPH10ConstraintE", !9, i64 8, !12, i64 12, !12, i64 16, !13, i64 20, !13, i64 21, !15, i64 22, !16, i64 24}
!9 = !{!"_ZTSN3JPH9RefTargetINS_10ConstraintEEE", !10, i64 0}
!10 = !{!"_ZTSSt6atomicIjE", !11, i64 0}
!11 = !{!"_ZTSSt13__atomic_baseIjE", !12, i64 0}
!12 = !{!"int", !13, i64 0}
!13 = !{!"omnipotent char", !14, i64 0}
!14 = !{!"Simple C++ TBAA"}
!15 = !{!"bool", !13, i64 0}
!16 = !{!"long", !13, i64 0}
!17 = !{!"any pointer", !13, i64 0}
!18 = !{!"_ZTSN3JPH4Vec3E", !13, i64 0}
!19 = !{!"_ZTSN3JPH4QuatE", !20, i64 0}
!20 = !{!"_ZTSN3JPH4Vec4E", !13, i64 0}
!21 = !{!"float", !13, i64 0}
!22 = !{!"_ZTSN3JPH14SpringSettingsE", !23, i64 0, !13, i64 4, !21, i64 8}
!23 = !{!"_ZTSN3JPH11ESpringModeE", !13, i64 0}
!24 = !{!"_ZTSN3JPH13MotorSettingsE", !22, i64 0, !21, i64 12, !21, i64 16, !21, i64 20, !21, i64 24}
!25 = !{!"_ZTSN3JPH11EMotorStateE", !13, i64 0}
!26 = !{!"_ZTSN3JPH22DualAxisConstraintPartE", !18, i64 0, !18, i64 16, !18, i64 32, !18, i64 48, !18, i64 64, !18, i64 80, !18, i64 96, !18, i64 112, !27, i64 128, !28, i64 144}
!27 = !{!"_ZTSN3JPH6MatrixILj2ELj2EEE", !13, i64 0}
!28 = !{!"_ZTSN3JPH6VectorILj2EEE", !13, i64 0}
!29 = !{!"_ZTSN3JPH27RotationEulerConstraintPartE", !30, i64 0, !30, i64 64, !30, i64 128, !18, i64 192}
!30 = !{!"_ZTSN3JPH5Mat44E", !13, i64 0}
!31 = !{!"_ZTSN3JPH18AxisConstraintPartE", !32, i64 0, !32, i64 12, !32, i64 24, !32, i64 36, !21, i64 48, !33, i64 52, !21, i64 60}
!32 = !{!"_ZTSN3JPH6Float3E", !21, i64 0, !21, i64 4, !21, i64 8}
!33 = !{!"_ZTSN3JPH10SpringPartE", !21, i64 0, !21, i64 4}
!34 = !{i8 0, i8 2}
!35 = !{}
!36 = !{!13, !13, i64 0}
!37 = !{!6, !21, i64 320}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass