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

%"struct.JPH::AssertLastParam" = type { i8 }
%"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 }

@.str.1 = external hidden unnamed_addr constant [64 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [98 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [57 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3JPH16SixDOFConstraint27CacheTranslationMotorActiveEv(ptr noundef nonnull align 16 dereferenceable(1856)) #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3JPH16SixDOFConstraint24CacheRotationMotorActiveEv(ptr noundef nonnull align 16 dereferenceable(1856)) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3JPH16SixDOFConstraint32CacheRotationPositionMotorActiveEv(ptr noundef nonnull align 16 dereferenceable(1856)) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3JPH16SixDOFConstraint13SetMotorStateENS_24SixDOFConstraintSettings5EAxisENS_11EMotorStateE(ptr noundef nonnull align 16 dereferenceable(1856) %0, i32 noundef %1, i32 noundef %2) #0 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca %"struct.JPH::AssertLastParam", align 1
  %8 = alloca %"struct.JPH::AssertLastParam", align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !11
  %9 = load ptr, ptr %4, align 8
  br label %10

10:                                               ; preds = %3
  %11 = load i32, ptr %6, align 4, !tbaa !11
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %22, label %13

13:                                               ; preds = %10
  %14 = getelementptr inbounds %"class.JPH::SixDOFConstraint", ptr %9, i32 0, i32 14
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = zext i32 %15 to i64
  %17 = getelementptr inbounds [6 x %"class.JPH::MotorSettings"], ptr %14, i64 0, i64 %16
  %18 = call noundef zeroext i1 @_ZNK3JPH13MotorSettings7IsValidEv(ptr noundef nonnull align 4 dereferenceable(28) %17)
  br i1 %18, label %22, label %19

19:                                               ; preds = %13
  %20 = call noundef zeroext i1 @_ZN3JPH23AssertFailedParamHelperEPKcS1_jNS_15AssertLastParamE(ptr noundef @.str.1, ptr noundef @.str.2, i32 noundef 312)
  br i1 %20, label %21, label %22

21:                                               ; preds = %19
  call void asm sideeffect "int $$0x3", "~{dirflag},~{fpsr},~{flags}"() #4, !srcloc !13
  br label %22

22:                                               ; preds = %21, %19, %13, %10
  br label %23

23:                                               ; preds = %22
  %24 = getelementptr inbounds %"class.JPH::SixDOFConstraint", ptr %9, i32 0, i32 16
  %25 = load i32, ptr %5, align 4, !tbaa !9
  %26 = zext i32 %25 to i64
  %27 = getelementptr inbounds [6 x i32], ptr %24, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !11
  %29 = load i32, ptr %6, align 4, !tbaa !11
  %30 = icmp ne i32 %28, %29
  br i1 %30, label %31, label %66

31:                                               ; preds = %23
  %32 = load i32, ptr %6, align 4, !tbaa !11
  %33 = getelementptr inbounds %"class.JPH::SixDOFConstraint", ptr %9, i32 0, i32 16
  %34 = load i32, ptr %5, align 4, !tbaa !9
  %35 = zext i32 %34 to i64
  %36 = getelementptr inbounds [6 x i32], ptr %33, i64 0, i64 %35
  store i32 %32, ptr %36, align 4, !tbaa !11
  %37 = load i32, ptr %5, align 4, !tbaa !9
  %38 = icmp sge i32 %37, 0
  br i1 %38, label %39, label %48

39:                                               ; preds = %31
  %40 = load i32, ptr %5, align 4, !tbaa !9
  %41 = icmp sle i32 %40, 2
  br i1 %41, label %42, label %48

42:                                               ; preds = %39
  %43 = getelementptr inbounds %"class.JPH::SixDOFConstraint", ptr %9, i32 0, i32 28
  %44 = load i32, ptr %5, align 4, !tbaa !9
  %45 = sub nsw i32 %44, 0
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [3 x %"class.JPH::AxisConstraintPart"], ptr %43, i64 0, i64 %46
  call void @_ZN3JPH18AxisConstraintPart10DeactivateEv(ptr noundef nonnull align 4 dereferenceable(64) %47)
  call void @_ZN3JPH16SixDOFConstraint27CacheTranslationMotorActiveEv(ptr noundef nonnull align 16 dereferenceable(1856) %9)
  br label %65

48:                                               ; preds = %39, %31
  br label %49

49:                                               ; preds = %48
  %50 = load i32, ptr %5, align 4, !tbaa !9
  %51 = icmp sge i32 %50, 3
  br i1 %51, label %52, label %55

52:                                               ; preds = %49
  %53 = load i32, ptr %5, align 4, !tbaa !9
  %54 = icmp sle i32 %53, 5
  br i1 %54, label %58, label %55

55:                                               ; preds = %52, %49
  %56 = call noundef zeroext i1 @_ZN3JPH23AssertFailedParamHelperEPKcS1_jNS_15AssertLastParamE(ptr noundef @.str.3, ptr noundef @.str.2, i32 noundef 327)
  br i1 %56, label %57, label %58

57:                                               ; preds = %55
  call void asm sideeffect "int $$0x3", "~{dirflag},~{fpsr},~{flags}"() #4, !srcloc !14
  br label %58

58:                                               ; preds = %57, %55, %52
  br label %59

59:                                               ; preds = %58
  %60 = getelementptr inbounds %"class.JPH::SixDOFConstraint", ptr %9, i32 0, i32 29
  %61 = load i32, ptr %5, align 4, !tbaa !9
  %62 = sub nsw i32 %61, 3
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [3 x %"class.JPH::AngleConstraintPart"], ptr %60, i64 0, i64 %63
  call void @_ZN3JPH19AngleConstraintPart10DeactivateEv(ptr noundef nonnull align 16 dereferenceable(48) %64)
  call void @_ZN3JPH16SixDOFConstraint24CacheRotationMotorActiveEv(ptr noundef nonnull align 16 dereferenceable(1856) %9)
  call void @_ZN3JPH16SixDOFConstraint32CacheRotationPositionMotorActiveEv(ptr noundef nonnull align 16 dereferenceable(1856) %9)
  br label %65

65:                                               ; preds = %59, %42
  br label %66

66:                                               ; preds = %65, %23
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK3JPH13MotorSettings7IsValidEv(ptr noundef nonnull align 4 dereferenceable(28)) #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN3JPH23AssertFailedParamHelperEPKcS1_jNS_15AssertLastParamE(ptr noundef, ptr noundef, i32 noundef) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3JPH18AxisConstraintPart10DeactivateEv(ptr noundef nonnull align 4 dereferenceable(64)) #3 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3JPH19AngleConstraintPart10DeactivateEv(ptr noundef nonnull align 16 dereferenceable(48)) #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 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 = { inlinehint 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 = { 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 = !{!"_ZTSN3JPH24SixDOFConstraintSettings5EAxisE", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"_ZTSN3JPH11EMotorStateE", !7, i64 0}
!13 = !{i64 2158401638}
!14 = !{i64 2158402056}


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

%"class.JPH::MotorSettings" = type { %"class.JPH::SpringSettings", float, float, float, float }
%"class.JPH::SpringSettings" = type { i8, %union.anon.2, float }
%union.anon.2 = type { float }
%"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 }
%"class.JPH::AngleConstraintPart" = type { %"class.JPH::Vec3", %"class.JPH::Vec3", float, %"class.JPH::SpringPart", float }
%"class.JPH::Vec3" = type { %union.anon }
%union.anon = type { <4 x float> }

@.str.1 = external hidden unnamed_addr constant [64 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [98 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [57 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3JPH16SixDOFConstraint27CacheTranslationMotorActiveEv(ptr noundef nonnull align 16 dereferenceable(1856)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3JPH16SixDOFConstraint24CacheRotationMotorActiveEv(ptr noundef nonnull align 16 dereferenceable(1856)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3JPH16SixDOFConstraint32CacheRotationPositionMotorActiveEv(ptr noundef nonnull align 16 dereferenceable(1856)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3JPH16SixDOFConstraint13SetMotorStateENS_24SixDOFConstraintSettings5EAxisENS_11EMotorStateE(ptr noundef nonnull align 16 dereferenceable(1856) %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 align 2 {
  %4 = icmp eq i32 %2, 0
  br i1 %4, label %._crit_edge, label %5

._crit_edge:                                      ; preds = %3
  %.pre = zext i32 %1 to i64
  br label %13

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 204
  %7 = zext i32 %1 to i64
  %8 = getelementptr inbounds [6 x %"class.JPH::MotorSettings"], ptr %6, i64 0, i64 %7
  %9 = tail call noundef zeroext i1 @_ZNK3JPH13MotorSettings7IsValidEv(ptr noundef nonnull align 4 dereferenceable(28) %8)
  br i1 %9, label %13, label %10

10:                                               ; preds = %5
  %11 = tail call noundef zeroext i1 @_ZN3JPH23AssertFailedParamHelperEPKcS1_jNS_15AssertLastParamE(ptr noundef nonnull @.str.1, ptr noundef nonnull @.str.2, i32 noundef 312)
  br i1 %11, label %12, label %13

12:                                               ; preds = %10
  tail call void asm sideeffect "int $$0x3", "~{dirflag},~{fpsr},~{flags}"() #4, !srcloc !5
  br label %13

13:                                               ; preds = %._crit_edge, %5, %10, %12
  %.pre-phi = phi i64 [ %.pre, %._crit_edge ], [ %7, %5 ], [ %7, %10 ], [ %7, %12 ]
  %14 = getelementptr inbounds i8, ptr %0, i64 396
  %15 = getelementptr inbounds [6 x i32], ptr %14, i64 0, i64 %.pre-phi
  %16 = load i32, ptr %15, align 4, !tbaa !6
  %.not = icmp eq i32 %16, %2
  br i1 %.not, label %30, label %17

17:                                               ; preds = %13
  store i32 %2, ptr %15, align 4, !tbaa !6
  %or.cond = icmp ult i32 %1, 3
  br i1 %or.cond, label %18, label %21

18:                                               ; preds = %17
  %19 = getelementptr inbounds i8, ptr %0, i64 1520
  %20 = getelementptr inbounds [3 x %"class.JPH::AxisConstraintPart"], ptr %19, i64 0, i64 %.pre-phi
  tail call void @_ZN3JPH18AxisConstraintPart10DeactivateEv(ptr noundef nonnull align 4 dereferenceable(64) %20)
  tail call void @_ZN3JPH16SixDOFConstraint27CacheTranslationMotorActiveEv(ptr noundef nonnull align 16 dereferenceable(1856) %0)
  br label %30

21:                                               ; preds = %17
  %22 = add i32 %1, -3
  %or.cond3 = icmp ult i32 %22, 3
  br i1 %or.cond3, label %26, label %23

23:                                               ; preds = %21
  %24 = tail call noundef zeroext i1 @_ZN3JPH23AssertFailedParamHelperEPKcS1_jNS_15AssertLastParamE(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.2, i32 noundef 327)
  br i1 %24, label %25, label %26

25:                                               ; preds = %23
  tail call void asm sideeffect "int $$0x3", "~{dirflag},~{fpsr},~{flags}"() #4, !srcloc !10
  br label %26

26:                                               ; preds = %23, %25, %21
  %27 = getelementptr inbounds i8, ptr %0, i64 1712
  %28 = sext i32 %22 to i64
  %29 = getelementptr inbounds [3 x %"class.JPH::AngleConstraintPart"], ptr %27, i64 0, i64 %28
  tail call void @_ZN3JPH19AngleConstraintPart10DeactivateEv(ptr noundef nonnull align 16 dereferenceable(48) %29)
  tail call void @_ZN3JPH16SixDOFConstraint24CacheRotationMotorActiveEv(ptr noundef nonnull align 16 dereferenceable(1856) %0)
  tail call void @_ZN3JPH16SixDOFConstraint32CacheRotationPositionMotorActiveEv(ptr noundef nonnull align 16 dereferenceable(1856) %0)
  br label %30

30:                                               ; preds = %18, %26, %13
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK3JPH13MotorSettings7IsValidEv(ptr noundef nonnull align 4 dereferenceable(28)) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN3JPH23AssertFailedParamHelperEPKcS1_jNS_15AssertLastParamE(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3JPH18AxisConstraintPart10DeactivateEv(ptr noundef nonnull align 4 dereferenceable(64)) local_unnamed_addr #3 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3JPH19AngleConstraintPart10DeactivateEv(ptr noundef nonnull align 16 dereferenceable(48)) 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 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 = { inlinehint 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 = { 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 = !{i64 2158401638}
!6 = !{!7, !7, i64 0}
!7 = !{!"_ZTSN3JPH11EMotorStateE", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{i64 2158402056}


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