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

; 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::SixDOFConstraint" = type { %"class.JPH::TwoBodyConstraint", %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Quat", %"class.JPH::Quat", i8, i8, i8, i8, i8, i8, [6 x float], [6 x float], [3 x %"class.JPH::SpringSettings"], [6 x %"class.JPH::MotorSettings"], [6 x float], [6 x i32], %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Quat", [3 x %"class.JPH::Vec3"], [3 x %"class.JPH::Vec3"], [3 x float], [3 x %"class.JPH::AxisConstraintPart"], %"class.JPH::PointConstraintPart", %"class.JPH::SwingTwistConstraintPart", %"class.JPH::RotationEulerConstraintPart", [3 x %"class.JPH::AxisConstraintPart"], [3 x %"class.JPH::AngleConstraintPart"] }
%"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::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::Vec3" = type { %union.anon }
%union.anon = type { <4 x float> }
%"class.JPH::Quat" = type { %"class.JPH::Vec4" }
%"class.JPH::Vec4" = type { %union.anon.4 }
%union.anon.4 = type { <4 x float> }
%"class.JPH::PointConstraintPart" = type { %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Mat44", %"class.JPH::Mat44", %"class.JPH::Mat44", %"class.JPH::Vec3" }
%"class.JPH::Mat44" = type { [4 x %"class.JPH::Vec4"] }
%"class.JPH::SwingTwistConstraintPart" = type { i8, i8, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::AngleConstraintPart", %"class.JPH::AngleConstraintPart", %"class.JPH::AngleConstraintPart" }
%"class.JPH::AngleConstraintPart" = type { %"class.JPH::Vec3", %"class.JPH::Vec3", float, %"class.JPH::SpringPart", float }
%"class.JPH::SpringPart" = type { float, float }
%"class.JPH::RotationEulerConstraintPart" = type { %"class.JPH::Mat44", %"class.JPH::Mat44", %"class.JPH::Mat44", %"class.JPH::Vec3" }
%"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 }

; 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 nounwind uwtable
define dso_local void @_ZN3JPH16SixDOFConstraint32CacheRotationPositionMotorActiveEv(ptr noundef nonnull align 16 dereferenceable(1856) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8
  %5 = getelementptr inbounds %"class.JPH::SixDOFConstraint", ptr %4, i32 0, i32 9
  store i8 0, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !30
  br label %6

6:                                                ; preds = %27, %1
  %7 = load i32, ptr %3, align 4, !tbaa !30
  %8 = icmp slt i32 %7, 3
  br i1 %8, label %10, label %9

9:                                                ; preds = %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  br label %30

10:                                               ; preds = %6
  %11 = getelementptr inbounds %"class.JPH::SixDOFConstraint", ptr %4, i32 0, i32 16
  %12 = load i32, ptr %3, align 4, !tbaa !30
  %13 = add nsw i32 3, %12
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [6 x i32], ptr %11, i64 0, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !31
  %17 = icmp eq i32 %16, 2
  br i1 %17, label %18, label %26

18:                                               ; preds = %10
  %19 = load i32, ptr %3, align 4, !tbaa !30
  %20 = shl i32 1, %19
  %21 = getelementptr inbounds %"class.JPH::SixDOFConstraint", ptr %4, i32 0, i32 9
  %22 = load i8, ptr %21, align 4, !tbaa !9
  %23 = zext i8 %22 to i32
  %24 = or i32 %23, %20
  %25 = trunc i32 %24 to i8
  store i8 %25, ptr %21, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %18, %10
  br label %27

27:                                               ; preds = %26
  %28 = load i32, ptr %3, align 4, !tbaa !30
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %3, align 4, !tbaa !30
  br label %6, !llvm.loop !33

30:                                               ; preds = %9
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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, !7, i64 116}
!10 = !{!"_ZTSN3JPH16SixDOFConstraintE", !11, i64 0, !19, i64 48, !19, i64 64, !20, i64 80, !20, i64 96, !7, i64 112, !7, i64 113, !17, i64 114, !17, i64 115, !7, i64 116, !17, i64 117, !7, i64 120, !7, i64 144, !7, i64 168, !7, i64 204, !7, i64 372, !7, i64 396, !19, i64 432, !19, i64 448, !19, i64 464, !20, i64 480, !7, i64 496, !7, i64 544, !7, i64 592, !7, i64 604, !22, i64 800, !24, i64 1040, !29, i64 1312, !7, i64 1520, !7, i64 1712}
!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 = !{!"_ZTSN3JPH19PointConstraintPartE", !19, i64 0, !19, i64 16, !23, i64 32, !23, i64 96, !23, i64 160, !19, i64 224}
!23 = !{!"_ZTSN3JPH5Mat44E", !7, i64 0}
!24 = !{!"_ZTSN3JPH24SwingTwistConstraintPartE", !7, i64 0, !25, i64 1, !26, i64 4, !26, i64 8, !26, i64 12, !26, i64 16, !26, i64 20, !26, i64 24, !26, i64 28, !26, i64 32, !26, i64 36, !26, i64 40, !26, i64 44, !26, i64 48, !26, i64 52, !26, i64 56, !26, i64 60, !26, i64 64, !19, i64 80, !19, i64 96, !19, i64 112, !27, i64 128, !27, i64 176, !27, i64 224}
!25 = !{!"_ZTSN3JPH10ESwingTypeE", !7, i64 0}
!26 = !{!"float", !7, i64 0}
!27 = !{!"_ZTSN3JPH19AngleConstraintPartE", !19, i64 0, !19, i64 16, !26, i64 32, !28, i64 36, !26, i64 44}
!28 = !{!"_ZTSN3JPH10SpringPartE", !26, i64 0, !26, i64 4}
!29 = !{!"_ZTSN3JPH27RotationEulerConstraintPartE", !23, i64 0, !23, i64 64, !23, i64 128, !19, i64 192}
!30 = !{!16, !16, i64 0}
!31 = !{!32, !32, i64 0}
!32 = !{!"_ZTSN3JPH11EMotorStateE", !7, i64 0}
!33 = distinct !{!33, !34}
!34 = !{!"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 nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local void @_ZN3JPH16SixDOFConstraint32CacheRotationPositionMotorActiveEv(ptr nocapture noundef nonnull align 16 dereferenceable(1856) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 116
  store i8 0, ptr %2, align 4, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 408
  %4 = load i32, ptr %3, align 8, !tbaa !29
  %5 = icmp eq i32 %4, 2
  %spec.store.select = zext i1 %5 to i8
  store i8 %spec.store.select, ptr %2, align 4
  %spec.select = zext i1 %5 to i8
  %6 = getelementptr inbounds i8, ptr %0, i64 412
  %7 = load i32, ptr %6, align 4, !tbaa !29
  %8 = icmp eq i32 %7, 2
  br i1 %8, label %9, label %11

9:                                                ; preds = %1
  %10 = or disjoint i8 %spec.select, 2
  store i8 %10, ptr %2, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %9, %1
  %12 = phi i8 [ %spec.select, %1 ], [ %10, %9 ]
  %13 = getelementptr inbounds i8, ptr %0, i64 416
  %14 = load i32, ptr %13, align 16, !tbaa !29
  %15 = icmp eq i32 %14, 2
  br i1 %15, label %16, label %18

16:                                               ; preds = %11
  %17 = or i8 %12, 4
  store i8 %17, ptr %2, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %16, %11
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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, !13, i64 116}
!6 = !{!"_ZTSN3JPH16SixDOFConstraintE", !7, i64 0, !18, i64 48, !18, i64 64, !19, i64 80, !19, i64 96, !13, i64 112, !13, i64 113, !15, i64 114, !15, i64 115, !13, i64 116, !15, i64 117, !13, i64 120, !13, i64 144, !13, i64 168, !13, i64 204, !13, i64 372, !13, i64 396, !18, i64 432, !18, i64 448, !18, i64 464, !19, i64 480, !13, i64 496, !13, i64 544, !13, i64 592, !13, i64 604, !21, i64 800, !23, i64 1040, !28, i64 1312, !13, i64 1520, !13, i64 1712}
!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 = !{!"_ZTSN3JPH19PointConstraintPartE", !18, i64 0, !18, i64 16, !22, i64 32, !22, i64 96, !22, i64 160, !18, i64 224}
!22 = !{!"_ZTSN3JPH5Mat44E", !13, i64 0}
!23 = !{!"_ZTSN3JPH24SwingTwistConstraintPartE", !13, i64 0, !24, i64 1, !25, i64 4, !25, i64 8, !25, i64 12, !25, i64 16, !25, i64 20, !25, i64 24, !25, i64 28, !25, i64 32, !25, i64 36, !25, i64 40, !25, i64 44, !25, i64 48, !25, i64 52, !25, i64 56, !25, i64 60, !25, i64 64, !18, i64 80, !18, i64 96, !18, i64 112, !26, i64 128, !26, i64 176, !26, i64 224}
!24 = !{!"_ZTSN3JPH10ESwingTypeE", !13, i64 0}
!25 = !{!"float", !13, i64 0}
!26 = !{!"_ZTSN3JPH19AngleConstraintPartE", !18, i64 0, !18, i64 16, !25, i64 32, !27, i64 36, !25, i64 44}
!27 = !{!"_ZTSN3JPH10SpringPartE", !25, i64 0, !25, i64 4}
!28 = !{!"_ZTSN3JPH27RotationEulerConstraintPartE", !22, i64 0, !22, i64 64, !22, i64 128, !18, i64 192}
!29 = !{!30, !30, i64 0}
!30 = !{!"_ZTSN3JPH11EMotorStateE", !13, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass