; LLVM IR from idmillington/cyclone-physics :: src/plinks.ll (ZNK7cyclone21ParticleRodConstraint10addContactEPNS_15ParticleContactEj)

; 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.cyclone::Vector3" = type { double, double, double, double }
%"class.cyclone::ParticleRodConstraint" = type { %"class.cyclone::ParticleConstraint", double }
%"class.cyclone::ParticleConstraint" = type { %"class.cyclone::ParticleContactGenerator", ptr, %"class.cyclone::Vector3" }
%"class.cyclone::ParticleContactGenerator" = type { ptr }
%"class.cyclone::ParticleContact" = type { [2 x ptr], double, %"class.cyclone::Vector3", double, [2 x %"class.cyclone::Vector3"] }

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

declare void @_ZNK7cyclone8Particle11getPositionEv(ptr dead_on_unwind writable sret(%"class.cyclone::Vector3") align 8, ptr noundef nonnull align 8 dereferenceable(144)) #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK7cyclone7Vector3miERKS0_(ptr dead_on_unwind noalias writable sret(%"class.cyclone::Vector3") align 8, ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(32)) #2 align 2

; 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
declare dso_local void @_ZN7cyclone7Vector39normaliseEv(ptr noundef nonnull align 8 dereferenceable(32)) #2 align 2

; 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) #3

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK7cyclone7Vector3mlEd(ptr dead_on_unwind noalias writable sret(%"class.cyclone::Vector3") align 8, ptr noundef nonnull align 8 dereferenceable(32), double noundef) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef double @_ZNK7cyclone18ParticleConstraint13currentLengthEv(ptr noundef nonnull align 8 dereferenceable(48)) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZNK7cyclone21ParticleRodConstraint10addContactEPNS_15ParticleContactEj(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr noundef %1, i32 noundef %2) unnamed_addr #2 align 2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca double, align 8
  %9 = alloca i32, align 4
  %10 = alloca %"class.cyclone::Vector3", align 8
  %11 = alloca %"class.cyclone::Vector3", align 8
  %12 = alloca %"class.cyclone::Vector3", align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  %13 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %14 = call noundef double @_ZNK7cyclone18ParticleConstraint13currentLengthEv(ptr noundef nonnull align 8 dereferenceable(48) %13)
  store double %14, ptr %8, align 8, !tbaa !11
  %15 = load double, ptr %8, align 8, !tbaa !11
  %16 = getelementptr inbounds %"class.cyclone::ParticleRodConstraint", ptr %13, i32 0, i32 1
  %17 = load double, ptr %16, align 8, !tbaa !13
  %18 = fcmp oeq double %15, %17
  br i1 %18, label %19, label %20

19:                                               ; preds = %3
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %57

20:                                               ; preds = %3
  %21 = getelementptr inbounds %"class.cyclone::ParticleConstraint", ptr %13, i32 0, i32 1
  %22 = load ptr, ptr %21, align 8, !tbaa !18
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = getelementptr inbounds %"class.cyclone::ParticleContact", ptr %23, i32 0, i32 0
  %25 = getelementptr inbounds [2 x ptr], ptr %24, i64 0, i64 0
  store ptr %22, ptr %25, align 8, !tbaa !5
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds %"class.cyclone::ParticleContact", ptr %26, i32 0, i32 0
  %28 = getelementptr inbounds [2 x ptr], ptr %27, i64 0, i64 1
  store ptr null, ptr %28, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 32, ptr %10) #4
  %29 = getelementptr inbounds %"class.cyclone::ParticleConstraint", ptr %13, i32 0, i32 2
  call void @llvm.lifetime.start.p0(i64 32, ptr %11) #4
  %30 = getelementptr inbounds %"class.cyclone::ParticleConstraint", ptr %13, i32 0, i32 1
  %31 = load ptr, ptr %30, align 8, !tbaa !18
  call void @_ZNK7cyclone8Particle11getPositionEv(ptr dead_on_unwind writable sret(%"class.cyclone::Vector3") align 8 %11, ptr noundef nonnull align 8 dereferenceable(144) %31)
  call void @_ZNK7cyclone7Vector3miERKS0_(ptr dead_on_unwind writable sret(%"class.cyclone::Vector3") align 8 %10, ptr noundef nonnull align 8 dereferenceable(32) %29, ptr noundef nonnull align 8 dereferenceable(32) %11)
  call void @llvm.lifetime.end.p0(i64 32, ptr %11) #4
  call void @_ZN7cyclone7Vector39normaliseEv(ptr noundef nonnull align 8 dereferenceable(32) %10)
  %32 = load double, ptr %8, align 8, !tbaa !11
  %33 = getelementptr inbounds %"class.cyclone::ParticleRodConstraint", ptr %13, i32 0, i32 1
  %34 = load double, ptr %33, align 8, !tbaa !13
  %35 = fcmp ogt double %32, %34
  br i1 %35, label %36, label %45

36:                                               ; preds = %20
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds %"class.cyclone::ParticleContact", ptr %37, i32 0, i32 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %38, ptr align 8 %10, i64 32, i1 false), !tbaa.struct !19
  %39 = load double, ptr %8, align 8, !tbaa !11
  %40 = getelementptr inbounds %"class.cyclone::ParticleRodConstraint", ptr %13, i32 0, i32 1
  %41 = load double, ptr %40, align 8, !tbaa !13
  %42 = fsub double %39, %41
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = getelementptr inbounds %"class.cyclone::ParticleContact", ptr %43, i32 0, i32 3
  store double %42, ptr %44, align 8, !tbaa !20
  br label %54

45:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 32, ptr %12) #4
  call void @_ZNK7cyclone7Vector3mlEd(ptr dead_on_unwind writable sret(%"class.cyclone::Vector3") align 8 %12, ptr noundef nonnull align 8 dereferenceable(32) %10, double noundef -1.000000e+00)
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = getelementptr inbounds %"class.cyclone::ParticleContact", ptr %46, i32 0, i32 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %47, ptr align 8 %12, i64 32, i1 false), !tbaa.struct !19
  call void @llvm.lifetime.end.p0(i64 32, ptr %12) #4
  %48 = getelementptr inbounds %"class.cyclone::ParticleRodConstraint", ptr %13, i32 0, i32 1
  %49 = load double, ptr %48, align 8, !tbaa !13
  %50 = load double, ptr %8, align 8, !tbaa !11
  %51 = fsub double %49, %50
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = getelementptr inbounds %"class.cyclone::ParticleContact", ptr %52, i32 0, i32 3
  store double %51, ptr %53, align 8, !tbaa !20
  br label %54

54:                                               ; preds = %45, %36
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = getelementptr inbounds %"class.cyclone::ParticleContact", ptr %55, i32 0, i32 1
  store double 0.000000e+00, ptr %56, align 8, !tbaa !22
  store i32 1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 32, ptr %10) #4
  br label %57

57:                                               ; preds = %54, %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %58 = load i32, ptr %4, align 4
  ret i32 %58
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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" }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!14, !12, i64 48}
!14 = !{!"_ZTSN7cyclone21ParticleRodConstraintE", !15, i64 0, !12, i64 48}
!15 = !{!"_ZTSN7cyclone18ParticleConstraintE", !16, i64 0, !6, i64 8, !17, i64 16}
!16 = !{!"_ZTSN7cyclone24ParticleContactGeneratorE"}
!17 = !{!"_ZTSN7cyclone7Vector3E", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24}
!18 = !{!15, !6, i64 8}
!19 = !{i64 0, i64 8, !11, i64 8, i64 8, !11, i64 16, i64 8, !11, i64 24, i64 8, !11}
!20 = !{!21, !12, i64 56}
!21 = !{!"_ZTSN7cyclone15ParticleContactE", !7, i64 0, !12, i64 16, !17, i64 24, !12, i64 56, !7, i64 64}
!22 = !{!21, !12, i64 16}


; 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.cyclone::Vector3" = type { double, double, double, double }

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

declare void @_ZNK7cyclone8Particle11getPositionEv(ptr dead_on_unwind writable sret(%"class.cyclone::Vector3") align 8, ptr noundef nonnull align 8 dereferenceable(144)) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK7cyclone7Vector3miERKS0_(ptr dead_on_unwind noalias writable sret(%"class.cyclone::Vector3") align 8, ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7cyclone7Vector39normaliseEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress 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) #3

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK7cyclone7Vector3mlEd(ptr dead_on_unwind noalias writable sret(%"class.cyclone::Vector3") align 8, ptr noundef nonnull align 8 dereferenceable(32), double noundef) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef double @_ZNK7cyclone18ParticleConstraint13currentLengthEv(ptr noundef nonnull align 8 dereferenceable(48)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 2) i32 @_ZNK7cyclone21ParticleRodConstraint10addContactEPNS_15ParticleContactEj(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr nocapture noundef writeonly %1, i32 noundef %2) unnamed_addr #2 align 2 {
  %4 = alloca %"class.cyclone::Vector3", align 8
  %5 = alloca %"class.cyclone::Vector3", align 8
  %6 = alloca %"class.cyclone::Vector3", align 8
  %7 = tail call noundef double @_ZNK7cyclone18ParticleConstraint13currentLengthEv(ptr noundef nonnull align 8 dereferenceable(48) %0)
  %8 = getelementptr inbounds i8, ptr %0, i64 48
  %9 = load double, ptr %8, align 8, !tbaa !5
  %10 = fcmp oeq double %7, %9
  br i1 %10, label %30, label %11

11:                                               ; preds = %3
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  %13 = load ptr, ptr %12, align 8, !tbaa !14
  store ptr %13, ptr %1, align 8, !tbaa !15
  %14 = getelementptr inbounds i8, ptr %1, i64 8
  store ptr null, ptr %14, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %4) #4
  %15 = getelementptr inbounds i8, ptr %0, i64 16
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %5) #4
  %16 = load ptr, ptr %12, align 8, !tbaa !14
  call void @_ZNK7cyclone8Particle11getPositionEv(ptr dead_on_unwind nonnull writable sret(%"class.cyclone::Vector3") align 8 %5, ptr noundef nonnull align 8 dereferenceable(144) %16)
  call void @_ZNK7cyclone7Vector3miERKS0_(ptr dead_on_unwind nonnull writable sret(%"class.cyclone::Vector3") align 8 %4, ptr noundef nonnull align 8 dereferenceable(32) %15, ptr noundef nonnull align 8 dereferenceable(32) %5)
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #4
  call void @_ZN7cyclone7Vector39normaliseEv(ptr noundef nonnull align 8 dereferenceable(32) %4)
  %17 = load double, ptr %8, align 8, !tbaa !5
  %18 = fcmp ogt double %7, %17
  br i1 %18, label %19, label %23

19:                                               ; preds = %11
  %20 = getelementptr inbounds i8, ptr %1, i64 24
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %20, ptr noundef nonnull align 8 dereferenceable(32) %4, i64 32, i1 false), !tbaa.struct !16
  %21 = load double, ptr %8, align 8, !tbaa !5
  %22 = fsub double %7, %21
  br label %27

23:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %6) #4
  call void @_ZNK7cyclone7Vector3mlEd(ptr dead_on_unwind nonnull writable sret(%"class.cyclone::Vector3") align 8 %6, ptr noundef nonnull align 8 dereferenceable(32) %4, double noundef -1.000000e+00)
  %24 = getelementptr inbounds i8, ptr %1, i64 24
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %24, ptr noundef nonnull align 8 dereferenceable(32) %6, i64 32, i1 false), !tbaa.struct !16
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %6) #4
  %25 = load double, ptr %8, align 8, !tbaa !5
  %26 = fsub double %25, %7
  br label %27

27:                                               ; preds = %23, %19
  %.sink = phi double [ %22, %19 ], [ %26, %23 ]
  %28 = getelementptr inbounds i8, ptr %1, i64 56
  store double %.sink, ptr %28, align 8
  %29 = getelementptr inbounds i8, ptr %1, i64 16
  store double 0.000000e+00, ptr %29, align 8, !tbaa !18
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #4
  br label %30

30:                                               ; preds = %3, %27
  %.0 = phi i32 [ 1, %27 ], [ 0, %3 ]
  ret i32 %.0
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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" }
attributes #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !13, i64 48}
!6 = !{!"_ZTSN7cyclone21ParticleRodConstraintE", !7, i64 0, !13, i64 48}
!7 = !{!"_ZTSN7cyclone18ParticleConstraintE", !8, i64 0, !9, i64 8, !12, i64 16}
!8 = !{!"_ZTSN7cyclone24ParticleContactGeneratorE"}
!9 = !{!"any pointer", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{!"_ZTSN7cyclone7Vector3E", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24}
!13 = !{!"double", !10, i64 0}
!14 = !{!7, !9, i64 8}
!15 = !{!9, !9, i64 0}
!16 = !{i64 0, i64 8, !17, i64 8, i64 8, !17, i64 16, i64 8, !17, i64 24, i64 8, !17}
!17 = !{!13, !13, i64 0}
!18 = !{!19, !13, i64 16}
!19 = !{!"_ZTSN7cyclone15ParticleContactE", !10, i64 0, !13, i64 16, !12, i64 24, !13, i64 56, !10, i64 64}


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