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

; 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::SwingTwistConstraint" = type { %"class.JPH::TwoBodyConstraint", %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Quat", %"class.JPH::Quat", float, float, float, float, float, %"class.JPH::MotorSettings", %"class.JPH::MotorSettings", i32, i32, %"class.JPH::Vec3", %"class.JPH::Quat", [3 x %"class.JPH::Vec3"], %"class.JPH::PointConstraintPart", %"class.JPH::SwingTwistConstraintPart", [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::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::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 }

@.str.1 = external hidden unnamed_addr constant [61 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [102 x i8], align 1

; 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 uwtable
define dso_local void @_ZN3JPH20SwingTwistConstraint18SetSwingMotorStateENS_11EMotorStateE(ptr noundef nonnull align 16 dereferenceable(944) %0, i32 noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca %"struct.JPH::AssertLastParam", align 1
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %10 = load ptr, ptr %3, align 8
  br label %11

11:                                               ; preds = %2
  %12 = load i32, ptr %4, align 4, !tbaa !9
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %20, label %14

14:                                               ; preds = %11
  %15 = getelementptr inbounds %"class.JPH::SwingTwistConstraint", ptr %10, i32 0, i32 10
  %16 = call noundef zeroext i1 @_ZNK3JPH13MotorSettings7IsValidEv(ptr noundef nonnull align 4 dereferenceable(28) %15)
  br i1 %16, label %20, label %17

17:                                               ; preds = %14
  %18 = call noundef zeroext i1 @_ZN3JPH23AssertFailedParamHelperEPKcS1_jNS_15AssertLastParamE(ptr noundef @.str.1, ptr noundef @.str.2, i32 noundef 161)
  br i1 %18, label %19, label %20

19:                                               ; preds = %17
  call void asm sideeffect "int $$0x3", "~{dirflag},~{fpsr},~{flags}"() #5, !srcloc !11
  br label %20

20:                                               ; preds = %19, %17, %14, %11
  br label %21

21:                                               ; preds = %20
  %22 = getelementptr inbounds %"class.JPH::SwingTwistConstraint", ptr %10, i32 0, i32 12
  %23 = load i32, ptr %22, align 4, !tbaa !12
  %24 = load i32, ptr %4, align 4, !tbaa !9
  %25 = icmp ne i32 %23, %24
  br i1 %25, label %26, label %47

26:                                               ; preds = %21
  %27 = load i32, ptr %4, align 4, !tbaa !9
  %28 = getelementptr inbounds %"class.JPH::SwingTwistConstraint", ptr %10, i32 0, i32 12
  store i32 %27, ptr %28, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %29 = getelementptr inbounds %"class.JPH::SwingTwistConstraint", ptr %10, i32 0, i32 19
  store ptr %29, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds [3 x %"class.JPH::AngleConstraintPart"], ptr %30, i64 0, i64 0
  store ptr %31, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds [3 x %"class.JPH::AngleConstraintPart"], ptr %32, i64 0, i64 0
  %34 = getelementptr inbounds %"class.JPH::AngleConstraintPart", ptr %33, i64 3
  store ptr %34, ptr %8, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %43, %26
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = icmp ne ptr %36, %37
  br i1 %38, label %40, label %39

39:                                               ; preds = %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  br label %46

40:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %41, ptr %9, align 8, !tbaa !5
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  call void @_ZN3JPH19AngleConstraintPart10DeactivateEv(ptr noundef nonnull align 16 dereferenceable(48) %42)
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  br label %43

43:                                               ; preds = %40
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = getelementptr inbounds %"class.JPH::AngleConstraintPart", ptr %44, i32 1
  store ptr %45, ptr %7, align 8, !tbaa !5
  br label %35

46:                                               ; preds = %39
  br label %47

47:                                               ; preds = %46, %21
  ret void
}

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3JPH19AngleConstraintPart10DeactivateEv(ptr noundef nonnull align 16 dereferenceable(48)) #4 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 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 = { 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 #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, !10, i64 0}
!10 = !{!"_ZTSN3JPH11EMotorStateE", !7, i64 0}
!11 = !{i64 2158324477}
!12 = !{!13, !10, i64 188}
!13 = !{!"_ZTSN3JPH20SwingTwistConstraintE", !14, i64 0, !22, i64 48, !22, i64 64, !23, i64 80, !23, i64 96, !25, i64 112, !25, i64 116, !25, i64 120, !25, i64 124, !25, i64 128, !26, i64 132, !26, i64 160, !10, i64 188, !10, i64 192, !22, i64 208, !23, i64 224, !7, i64 240, !29, i64 288, !31, i64 528, !7, i64 800}
!14 = !{!"_ZTSN3JPH17TwoBodyConstraintE", !15, i64 0, !6, i64 32, !6, i64 40}
!15 = !{!"_ZTSN3JPH10ConstraintE", !16, i64 8, !19, i64 12, !19, i64 16, !7, i64 20, !7, i64 21, !20, i64 22, !21, i64 24}
!16 = !{!"_ZTSN3JPH9RefTargetINS_10ConstraintEEE", !17, i64 0}
!17 = !{!"_ZTSSt6atomicIjE", !18, i64 0}
!18 = !{!"_ZTSSt13__atomic_baseIjE", !19, i64 0}
!19 = !{!"int", !7, i64 0}
!20 = !{!"bool", !7, i64 0}
!21 = !{!"long", !7, i64 0}
!22 = !{!"_ZTSN3JPH4Vec3E", !7, i64 0}
!23 = !{!"_ZTSN3JPH4QuatE", !24, i64 0}
!24 = !{!"_ZTSN3JPH4Vec4E", !7, i64 0}
!25 = !{!"float", !7, i64 0}
!26 = !{!"_ZTSN3JPH13MotorSettingsE", !27, i64 0, !25, i64 12, !25, i64 16, !25, i64 20, !25, i64 24}
!27 = !{!"_ZTSN3JPH14SpringSettingsE", !28, i64 0, !7, i64 4, !25, i64 8}
!28 = !{!"_ZTSN3JPH11ESpringModeE", !7, i64 0}
!29 = !{!"_ZTSN3JPH19PointConstraintPartE", !22, i64 0, !22, i64 16, !30, i64 32, !30, i64 96, !30, i64 160, !22, i64 224}
!30 = !{!"_ZTSN3JPH5Mat44E", !7, i64 0}
!31 = !{!"_ZTSN3JPH24SwingTwistConstraintPartE", !7, i64 0, !32, 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, !22, i64 80, !22, i64 96, !22, i64 112, !33, i64 128, !33, i64 176, !33, i64 224}
!32 = !{!"_ZTSN3JPH10ESwingTypeE", !7, i64 0}
!33 = !{!"_ZTSN3JPH19AngleConstraintPartE", !22, i64 0, !22, i64 16, !25, i64 32, !34, i64 36, !25, i64 44}
!34 = !{!"_ZTSN3JPH10SpringPartE", !25, i64 0, !25, i64 4}


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

@.str.1 = external hidden unnamed_addr constant [61 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [102 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3JPH20SwingTwistConstraint18SetSwingMotorStateENS_11EMotorStateE(ptr noundef nonnull align 16 dereferenceable(944) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = icmp eq i32 %1, 0
  br i1 %3, label %10, label %4

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 132
  %6 = tail call noundef zeroext i1 @_ZNK3JPH13MotorSettings7IsValidEv(ptr noundef nonnull align 4 dereferenceable(28) %5)
  br i1 %6, label %10, label %7

7:                                                ; preds = %4
  %8 = tail call noundef zeroext i1 @_ZN3JPH23AssertFailedParamHelperEPKcS1_jNS_15AssertLastParamE(ptr noundef nonnull @.str.1, ptr noundef nonnull @.str.2, i32 noundef 161)
  br i1 %8, label %9, label %10

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

10:                                               ; preds = %2, %4, %7, %9
  %11 = getelementptr inbounds i8, ptr %0, i64 188
  %12 = load i32, ptr %11, align 4, !tbaa !6
  %.not = icmp eq i32 %12, %1
  br i1 %.not, label %.loopexit, label %.loopexit.loopexit

.loopexit.loopexit:                               ; preds = %10
  store i32 %1, ptr %11, align 4, !tbaa !6
  %.0.ptr = getelementptr inbounds i8, ptr %0, i64 800
  tail call void @_ZN3JPH19AngleConstraintPart10DeactivateEv(ptr noundef nonnull align 16 dereferenceable(48) %.0.ptr)
  %.0.ptr.1 = getelementptr inbounds i8, ptr %0, i64 848
  tail call void @_ZN3JPH19AngleConstraintPart10DeactivateEv(ptr noundef nonnull align 16 dereferenceable(48) %.0.ptr.1)
  %.0.ptr.2 = getelementptr inbounds i8, ptr %0, i64 896
  tail call void @_ZN3JPH19AngleConstraintPart10DeactivateEv(ptr noundef nonnull align 16 dereferenceable(48) %.0.ptr.2)
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit, %10
  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 @_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 2158324477}
!6 = !{!7, !26, i64 188}
!7 = !{!"_ZTSN3JPH20SwingTwistConstraintE", !8, i64 0, !19, i64 48, !19, i64 64, !20, i64 80, !20, i64 96, !22, i64 112, !22, i64 116, !22, i64 120, !22, i64 124, !22, i64 128, !23, i64 132, !23, i64 160, !26, i64 188, !26, i64 192, !19, i64 208, !20, i64 224, !14, i64 240, !27, i64 288, !29, i64 528, !14, i64 800}
!8 = !{!"_ZTSN3JPH17TwoBodyConstraintE", !9, i64 0, !18, i64 32, !18, i64 40}
!9 = !{!"_ZTSN3JPH10ConstraintE", !10, i64 8, !13, i64 12, !13, i64 16, !14, i64 20, !14, i64 21, !16, i64 22, !17, i64 24}
!10 = !{!"_ZTSN3JPH9RefTargetINS_10ConstraintEEE", !11, i64 0}
!11 = !{!"_ZTSSt6atomicIjE", !12, i64 0}
!12 = !{!"_ZTSSt13__atomic_baseIjE", !13, i64 0}
!13 = !{!"int", !14, i64 0}
!14 = !{!"omnipotent char", !15, i64 0}
!15 = !{!"Simple C++ TBAA"}
!16 = !{!"bool", !14, i64 0}
!17 = !{!"long", !14, i64 0}
!18 = !{!"any pointer", !14, i64 0}
!19 = !{!"_ZTSN3JPH4Vec3E", !14, i64 0}
!20 = !{!"_ZTSN3JPH4QuatE", !21, i64 0}
!21 = !{!"_ZTSN3JPH4Vec4E", !14, i64 0}
!22 = !{!"float", !14, i64 0}
!23 = !{!"_ZTSN3JPH13MotorSettingsE", !24, i64 0, !22, i64 12, !22, i64 16, !22, i64 20, !22, i64 24}
!24 = !{!"_ZTSN3JPH14SpringSettingsE", !25, i64 0, !14, i64 4, !22, i64 8}
!25 = !{!"_ZTSN3JPH11ESpringModeE", !14, i64 0}
!26 = !{!"_ZTSN3JPH11EMotorStateE", !14, i64 0}
!27 = !{!"_ZTSN3JPH19PointConstraintPartE", !19, i64 0, !19, i64 16, !28, i64 32, !28, i64 96, !28, i64 160, !19, i64 224}
!28 = !{!"_ZTSN3JPH5Mat44E", !14, i64 0}
!29 = !{!"_ZTSN3JPH24SwingTwistConstraintPartE", !14, i64 0, !30, i64 1, !22, i64 4, !22, i64 8, !22, i64 12, !22, i64 16, !22, i64 20, !22, i64 24, !22, i64 28, !22, i64 32, !22, i64 36, !22, i64 40, !22, i64 44, !22, i64 48, !22, i64 52, !22, i64 56, !22, i64 60, !22, i64 64, !19, i64 80, !19, i64 96, !19, i64 112, !31, i64 128, !31, i64 176, !31, i64 224}
!30 = !{!"_ZTSN3JPH10ESwingTypeE", !14, i64 0}
!31 = !{!"_ZTSN3JPH19AngleConstraintPartE", !19, i64 0, !19, i64 16, !22, i64 32, !32, i64 36, !22, i64 44}
!32 = !{!"_ZTSN3JPH10SpringPartE", !22, i64 0, !22, i64 4}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass