; LLVM IR from idmillington/cyclone-physics :: src/plinks.ll (ZNK7cyclone11ParticleRod10addContactEPNS_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::ParticleRod" = type { %"class.cyclone::ParticleLink", double }
%"class.cyclone::ParticleLink" = type { %"class.cyclone::ParticleContactGenerator", [2 x ptr] }
%"class.cyclone::ParticleContactGenerator" = type { ptr }
%"class.cyclone::ParticleContact" = type { [2 x ptr], double, %"class.cyclone::Vector3", double, [2 x %"class.cyclone::Vector3"] }

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

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

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

; 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)) #0 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7cyclone7Vector39normaliseEv(ptr noundef nonnull align 8 dereferenceable(32)) #0 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
define dso_local noundef i32 @_ZNK7cyclone11ParticleRod10addContactEPNS_15ParticleContactEj(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef %1, i32 noundef %2) unnamed_addr #0 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
  %13 = 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
  %14 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %15 = call noundef double @_ZNK7cyclone12ParticleLink13currentLengthEv(ptr noundef nonnull align 8 dereferenceable(24) %14)
  store double %15, ptr %8, align 8, !tbaa !11
  %16 = load double, ptr %8, align 8, !tbaa !11
  %17 = getelementptr inbounds %"class.cyclone::ParticleRod", ptr %14, i32 0, i32 1
  %18 = load double, ptr %17, align 8, !tbaa !13
  %19 = fcmp oeq double %16, %18
  br i1 %19, label %20, label %21

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

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

44:                                               ; preds = %21
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = getelementptr inbounds %"class.cyclone::ParticleContact", ptr %45, i32 0, i32 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %46, ptr align 8 %10, i64 32, i1 false), !tbaa.struct !17
  %47 = load double, ptr %8, align 8, !tbaa !11
  %48 = getelementptr inbounds %"class.cyclone::ParticleRod", ptr %14, i32 0, i32 1
  %49 = load double, ptr %48, align 8, !tbaa !13
  %50 = fsub double %47, %49
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = getelementptr inbounds %"class.cyclone::ParticleContact", ptr %51, i32 0, i32 3
  store double %50, ptr %52, align 8, !tbaa !18
  br label %62

53:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 32, ptr %13) #4
  call void @_ZNK7cyclone7Vector3mlEd(ptr dead_on_unwind writable sret(%"class.cyclone::Vector3") align 8 %13, ptr noundef nonnull align 8 dereferenceable(32) %10, double noundef -1.000000e+00)
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %"class.cyclone::ParticleContact", ptr %54, i32 0, i32 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %55, ptr align 8 %13, i64 32, i1 false), !tbaa.struct !17
  call void @llvm.lifetime.end.p0(i64 32, ptr %13) #4
  %56 = getelementptr inbounds %"class.cyclone::ParticleRod", ptr %14, i32 0, i32 1
  %57 = load double, ptr %56, align 8, !tbaa !13
  %58 = load double, ptr %8, align 8, !tbaa !11
  %59 = fsub double %57, %58
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = getelementptr inbounds %"class.cyclone::ParticleContact", ptr %60, i32 0, i32 3
  store double %59, ptr %61, align 8, !tbaa !18
  br label %62

62:                                               ; preds = %53, %44
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = getelementptr inbounds %"class.cyclone::ParticleContact", ptr %63, i32 0, i32 1
  store double 0.000000e+00, ptr %64, align 8, !tbaa !21
  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 %65

65:                                               ; preds = %62, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %66 = load i32, ptr %4, align 4
  ret i32 %66
}

; 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) #0 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 24}
!14 = !{!"_ZTSN7cyclone11ParticleRodE", !15, i64 0, !12, i64 24}
!15 = !{!"_ZTSN7cyclone12ParticleLinkE", !16, i64 0, !7, i64 8}
!16 = !{!"_ZTSN7cyclone24ParticleContactGeneratorE"}
!17 = !{i64 0, i64 8, !11, i64 8, i64 8, !11, i64 16, i64 8, !11, i64 24, i64 8, !11}
!18 = !{!19, !12, i64 56}
!19 = !{!"_ZTSN7cyclone15ParticleContactE", !7, i64 0, !12, i64 16, !20, i64 24, !12, i64 56, !7, i64 64}
!20 = !{!"_ZTSN7cyclone7Vector3E", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24}
!21 = !{!19, !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 uwtable
declare dso_local noundef double @_ZNK7cyclone12ParticleLink13currentLengthEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0 align 2

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

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

; 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 #0 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7cyclone7Vector39normaliseEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #0 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
define dso_local noundef range(i32 0, 2) i32 @_ZNK7cyclone11ParticleRod10addContactEPNS_15ParticleContactEj(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr nocapture noundef writeonly %1, i32 noundef %2) unnamed_addr #0 align 2 {
  %4 = alloca %"class.cyclone::Vector3", align 8
  %5 = alloca %"class.cyclone::Vector3", align 8
  %6 = alloca %"class.cyclone::Vector3", align 8
  %7 = alloca %"class.cyclone::Vector3", align 8
  %8 = tail call noundef double @_ZNK7cyclone12ParticleLink13currentLengthEv(ptr noundef nonnull align 8 dereferenceable(24) %0)
  %9 = getelementptr inbounds i8, ptr %0, i64 24
  %10 = load double, ptr %9, align 8, !tbaa !5
  %11 = fcmp oeq double %8, %10
  br i1 %11, label %32, label %12

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

21:                                               ; preds = %12
  %22 = getelementptr inbounds i8, ptr %1, i64 24
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %22, ptr noundef nonnull align 8 dereferenceable(32) %4, i64 32, i1 false), !tbaa.struct !14
  %23 = load double, ptr %9, align 8, !tbaa !5
  %24 = fsub double %8, %23
  br label %29

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

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

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

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


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