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

; 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::PulleyConstraint" = type { %"class.JPH::TwoBodyConstraint", %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Vec3", float, float, float, %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Vec3", float, float, [8 x i8], %"class.JPH::IndependentAxisConstraintPart" }
%"class.JPH::TwoBodyConstraint" = type { %"class.JPH::Constraint", ptr, ptr }
%"class.JPH::Constraint" = type { ptr, %"class.JPH::RefTarget.2", i32, i32, i8, i8, i8, i64 }
%"class.JPH::RefTarget.2" = type { %"struct.std::atomic" }
%"struct.std::atomic" = type { %"struct.std::__atomic_base" }
%"struct.std::__atomic_base" = type { i32 }
%"class.JPH::IndependentAxisConstraintPart" = type <{ %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Vec3", float, float, [8 x i8] }>

; 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: mustprogress uwtable
declare dso_local noundef float @_ZN3JPH16PulleyConstraint34CalculatePositionsNormalsAndLengthEv(ptr noundef nonnull align 16 dereferenceable(288)) #2 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN3JPH16PulleyConstraint23SolvePositionConstraintEff(ptr noundef nonnull align 16 dereferenceable(288) %0, float noundef %1, float noundef %2) unnamed_addr #2 align 2 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca float, align 4
  %7 = alloca float, align 4
  %8 = alloca float, align 4
  %9 = alloca float, align 4
  %10 = alloca %"class.JPH::Vec3", align 16
  %11 = alloca %"class.JPH::Vec3", align 16
  %12 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store float %1, ptr %6, align 4, !tbaa !9
  store float %2, ptr %7, align 4, !tbaa !9
  %13 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %14 = call noundef float @_ZN3JPH16PulleyConstraint34CalculatePositionsNormalsAndLengthEv(ptr noundef nonnull align 16 dereferenceable(288) %13)
  store float %14, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store float 0.000000e+00, ptr %9, align 4, !tbaa !9
  %15 = load float, ptr %8, align 4, !tbaa !9
  %16 = getelementptr inbounds %"class.JPH::PulleyConstraint", ptr %13, i32 0, i32 6
  %17 = load float, ptr %16, align 4, !tbaa !11
  %18 = fcmp olt float %15, %17
  br i1 %18, label %19, label %24

19:                                               ; preds = %3
  %20 = load float, ptr %8, align 4, !tbaa !9
  %21 = getelementptr inbounds %"class.JPH::PulleyConstraint", ptr %13, i32 0, i32 6
  %22 = load float, ptr %21, align 4, !tbaa !11
  %23 = fsub float %20, %22
  store float %23, ptr %9, align 4, !tbaa !9
  br label %35

24:                                               ; preds = %3
  %25 = load float, ptr %8, align 4, !tbaa !9
  %26 = getelementptr inbounds %"class.JPH::PulleyConstraint", ptr %13, i32 0, i32 7
  %27 = load float, ptr %26, align 8, !tbaa !23
  %28 = fcmp ogt float %25, %27
  br i1 %28, label %29, label %34

29:                                               ; preds = %24
  %30 = load float, ptr %8, align 4, !tbaa !9
  %31 = getelementptr inbounds %"class.JPH::PulleyConstraint", ptr %13, i32 0, i32 7
  %32 = load float, ptr %31, align 8, !tbaa !23
  %33 = fsub float %30, %32
  store float %33, ptr %9, align 4, !tbaa !9
  br label %34

34:                                               ; preds = %29, %24
  br label %35

35:                                               ; preds = %34, %19
  %36 = load float, ptr %9, align 4, !tbaa !9
  %37 = fcmp une float %36, 0.000000e+00
  br i1 %37, label %38, label %59

38:                                               ; preds = %35
  call void @_ZN3JPH16PulleyConstraint29CalculateConstraintPropertiesEv(ptr noundef nonnull align 16 dereferenceable(288) %13)
  %39 = getelementptr inbounds %"class.JPH::PulleyConstraint", ptr %13, i32 0, i32 15
  %40 = getelementptr inbounds %"class.JPH::TwoBodyConstraint", ptr %13, i32 0, i32 1
  %41 = load ptr, ptr %40, align 16, !tbaa !24
  %42 = getelementptr inbounds %"class.JPH::TwoBodyConstraint", ptr %13, i32 0, i32 2
  %43 = load ptr, ptr %42, align 8, !tbaa !25
  %44 = getelementptr inbounds %"class.JPH::PulleyConstraint", ptr %13, i32 0, i32 10
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %10, ptr align 16 %44, i64 16, i1 false), !tbaa.struct !26
  %45 = getelementptr inbounds %"class.JPH::PulleyConstraint", ptr %13, i32 0, i32 11
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %11, ptr align 16 %45, i64 16, i1 false), !tbaa.struct !26
  %46 = getelementptr inbounds %"class.JPH::PulleyConstraint", ptr %13, i32 0, i32 5
  %47 = load float, ptr %46, align 16, !tbaa !28
  %48 = load float, ptr %9, align 4, !tbaa !9
  %49 = load float, ptr %7, align 4, !tbaa !9
  %50 = getelementptr inbounds { double, double }, ptr %10, i32 0, i32 0
  %51 = load double, ptr %50, align 16
  %52 = getelementptr inbounds { double, double }, ptr %10, i32 0, i32 1
  %53 = load double, ptr %52, align 8
  %54 = getelementptr inbounds { double, double }, ptr %11, i32 0, i32 0
  %55 = load double, ptr %54, align 16
  %56 = getelementptr inbounds { double, double }, ptr %11, i32 0, i32 1
  %57 = load double, ptr %56, align 8
  %58 = call noundef zeroext i1 @_ZNK3JPH29IndependentAxisConstraintPart23SolvePositionConstraintERNS_4BodyES2_NS_4Vec3ES3_fff(ptr noundef nonnull align 16 dereferenceable(72) %39, ptr noundef nonnull align 16 dereferenceable(122) %41, ptr noundef nonnull align 16 dereferenceable(122) %43, double %51, double %53, double %55, double %57, float noundef %47, float noundef %48, float noundef %49)
  store i1 %58, ptr %4, align 1
  store i32 1, ptr %12, align 4
  br label %60

59:                                               ; preds = %35
  store i1 false, ptr %4, align 1
  store i32 1, ptr %12, align 4
  br label %60

60:                                               ; preds = %59, %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %61 = load i1, ptr %4, align 1
  ret i1 %61
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZNK3JPH29IndependentAxisConstraintPart23SolvePositionConstraintERNS_4BodyES2_NS_4Vec3ES3_fff(ptr noundef nonnull align 16 dereferenceable(72), ptr noundef nonnull align 16 dereferenceable(122), ptr noundef nonnull align 16 dereferenceable(122), double, double, double, double, float noundef, float noundef, float noundef) #3 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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 = !{!"float", !7, i64 0}
!11 = !{!12, !10, i64 116}
!12 = !{!"_ZTSN3JPH16PulleyConstraintE", !13, i64 0, !21, i64 48, !21, i64 64, !21, i64 80, !21, i64 96, !10, i64 112, !10, i64 116, !10, i64 120, !21, i64 128, !21, i64 144, !21, i64 160, !21, i64 176, !10, i64 192, !10, i64 196, !22, i64 208}
!13 = !{!"_ZTSN3JPH17TwoBodyConstraintE", !14, i64 0, !6, i64 32, !6, i64 40}
!14 = !{!"_ZTSN3JPH10ConstraintE", !15, i64 8, !18, i64 12, !18, i64 16, !7, i64 20, !7, i64 21, !19, i64 22, !20, i64 24}
!15 = !{!"_ZTSN3JPH9RefTargetINS_10ConstraintEEE", !16, i64 0}
!16 = !{!"_ZTSSt6atomicIjE", !17, i64 0}
!17 = !{!"_ZTSSt13__atomic_baseIjE", !18, i64 0}
!18 = !{!"int", !7, i64 0}
!19 = !{!"bool", !7, i64 0}
!20 = !{!"long", !7, i64 0}
!21 = !{!"_ZTSN3JPH4Vec3E", !7, i64 0}
!22 = !{!"_ZTSN3JPH29IndependentAxisConstraintPartE", !21, i64 0, !21, i64 16, !21, i64 32, !21, i64 48, !10, i64 64, !10, i64 68}
!23 = !{!12, !10, i64 120}
!24 = !{!13, !6, i64 32}
!25 = !{!13, !6, i64 40}
!26 = !{i64 0, i64 16, !27}
!27 = !{!7, !7, i64 0}
!28 = !{!12, !10, i64 112}


; 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 uwtable
declare dso_local noundef float @_ZN3JPH16PulleyConstraint34CalculatePositionsNormalsAndLengthEv(ptr noundef nonnull align 16 dereferenceable(288)) local_unnamed_addr #0 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN3JPH16PulleyConstraint23SolvePositionConstraintEff(ptr noundef nonnull align 16 dereferenceable(288) %0, float noundef %1, float noundef %2) unnamed_addr #0 align 2 {
  %4 = tail call noundef float @_ZN3JPH16PulleyConstraint34CalculatePositionsNormalsAndLengthEv(ptr noundef nonnull align 16 dereferenceable(288) %0)
  %5 = getelementptr inbounds i8, ptr %0, i64 116
  %6 = load float, ptr %5, align 4, !tbaa !5
  %7 = fcmp olt float %4, %6
  br i1 %7, label %12, label %8

8:                                                ; preds = %3
  %9 = getelementptr inbounds i8, ptr %0, i64 120
  %10 = load float, ptr %9, align 8, !tbaa !21
  %11 = fcmp ogt float %4, %10
  br i1 %11, label %12, label %.thread

12:                                               ; preds = %8, %3
  %.pn = phi float [ %6, %3 ], [ %10, %8 ]
  %.011 = fsub float %4, %.pn
  %13 = fcmp une float %.011, 0.000000e+00
  br i1 %13, label %14, label %.thread

14:                                               ; preds = %12
  tail call void @_ZN3JPH16PulleyConstraint29CalculateConstraintPropertiesEv(ptr noundef nonnull align 16 dereferenceable(288) %0)
  %15 = getelementptr inbounds i8, ptr %0, i64 208
  %16 = getelementptr inbounds i8, ptr %0, i64 32
  %17 = load ptr, ptr %16, align 16, !tbaa !22
  %18 = getelementptr inbounds i8, ptr %0, i64 40
  %19 = load ptr, ptr %18, align 8, !tbaa !23
  %20 = getelementptr inbounds i8, ptr %0, i64 160
  %.sroa.01.0.copyload = load double, ptr %20, align 16
  %.sroa.22.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 168
  %.sroa.22.0.copyload = load double, ptr %.sroa.22.0..sroa_idx, align 8, !tbaa !24
  %21 = getelementptr inbounds i8, ptr %0, i64 176
  %.sroa.0.0.copyload = load double, ptr %21, align 16
  %.sroa.2.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 184
  %.sroa.2.0.copyload = load double, ptr %.sroa.2.0..sroa_idx, align 8, !tbaa !24
  %22 = getelementptr inbounds i8, ptr %0, i64 112
  %23 = load float, ptr %22, align 16, !tbaa !25
  %24 = tail call noundef zeroext i1 @_ZNK3JPH29IndependentAxisConstraintPart23SolvePositionConstraintERNS_4BodyES2_NS_4Vec3ES3_fff(ptr noundef nonnull align 16 dereferenceable(72) %15, ptr noundef nonnull align 16 dereferenceable(122) %17, ptr noundef nonnull align 16 dereferenceable(122) %19, double %.sroa.01.0.copyload, double %.sroa.22.0.copyload, double %.sroa.0.0.copyload, double %.sroa.2.0.copyload, float noundef %23, float noundef %.011, float noundef %2)
  br label %.thread

.thread:                                          ; preds = %8, %12, %14
  %.0 = phi i1 [ %24, %14 ], [ false, %12 ], [ false, %8 ]
  ret i1 %.0
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZNK3JPH29IndependentAxisConstraintPart23SolvePositionConstraintERNS_4BodyES2_NS_4Vec3ES3_fff(ptr noundef nonnull align 16 dereferenceable(72), ptr noundef nonnull align 16 dereferenceable(122), ptr noundef nonnull align 16 dereferenceable(122), double, double, double, double, float noundef, float noundef, float noundef) local_unnamed_addr #1 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 = { 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" }

!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, !19, i64 116}
!6 = !{!"_ZTSN3JPH16PulleyConstraintE", !7, i64 0, !18, i64 48, !18, i64 64, !18, i64 80, !18, i64 96, !19, i64 112, !19, i64 116, !19, i64 120, !18, i64 128, !18, i64 144, !18, i64 160, !18, i64 176, !19, i64 192, !19, i64 196, !20, i64 208}
!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 = !{!"float", !13, i64 0}
!20 = !{!"_ZTSN3JPH29IndependentAxisConstraintPartE", !18, i64 0, !18, i64 16, !18, i64 32, !18, i64 48, !19, i64 64, !19, i64 68}
!21 = !{!6, !19, i64 120}
!22 = !{!7, !17, i64 32}
!23 = !{!7, !17, i64 40}
!24 = !{!13, !13, i64 0}
!25 = !{!6, !19, i64 112}


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