; LLVM IR from idmillington/cyclone-physics :: src/plinks.ll (ZNK7cyclone13ParticleCable10addContactEPNS_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::ParticleCable" = type { %"class.cyclone::ParticleLink", double, 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
define dso_local noundef i32 @_ZNK7cyclone13ParticleCable10addContactEPNS_15ParticleContactEj(ptr noundef nonnull align 8 dereferenceable(40) %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
  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 @_ZNK7cyclone12ParticleLink13currentLengthEv(ptr noundef nonnull align 8 dereferenceable(24) %13)
  store double %14, ptr %8, align 8, !tbaa !11
  %15 = load double, ptr %8, align 8, !tbaa !11
  %16 = getelementptr inbounds %"class.cyclone::ParticleCable", ptr %13, i32 0, i32 1
  %17 = load double, ptr %16, align 8, !tbaa !13
  %18 = fcmp olt 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 %51

20:                                               ; preds = %3
  %21 = getelementptr inbounds %"class.cyclone::ParticleLink", ptr %13, i32 0, i32 1
  %22 = getelementptr inbounds [2 x ptr], ptr %21, i64 0, i64 0
  %23 = load ptr, ptr %22, align 8, !tbaa !5
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %"class.cyclone::ParticleContact", ptr %24, i32 0, i32 0
  %26 = getelementptr inbounds [2 x ptr], ptr %25, i64 0, i64 0
  store ptr %23, ptr %26, align 8, !tbaa !5
  %27 = getelementptr inbounds %"class.cyclone::ParticleLink", ptr %13, i32 0, i32 1
  %28 = getelementptr inbounds [2 x ptr], ptr %27, i64 0, i64 1
  %29 = load ptr, ptr %28, align 8, !tbaa !5
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %"class.cyclone::ParticleContact", ptr %30, i32 0, i32 0
  %32 = getelementptr inbounds [2 x ptr], ptr %31, i64 0, i64 1
  store ptr %29, ptr %32, 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
  %33 = getelementptr inbounds %"class.cyclone::ParticleLink", ptr %13, i32 0, i32 1
  %34 = getelementptr inbounds [2 x ptr], ptr %33, i64 0, i64 1
  %35 = load ptr, ptr %34, 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) %35)
  call void @llvm.lifetime.start.p0(i64 32, ptr %12) #4
  %36 = getelementptr inbounds %"class.cyclone::ParticleLink", ptr %13, i32 0, i32 1
  %37 = getelementptr inbounds [2 x ptr], ptr %36, i64 0, i64 0
  %38 = load ptr, ptr %37, 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) %38)
  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)
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %"class.cyclone::ParticleContact", ptr %39, i32 0, i32 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %40, ptr align 8 %10, i64 32, i1 false), !tbaa.struct !17
  %41 = load double, ptr %8, align 8, !tbaa !11
  %42 = getelementptr inbounds %"class.cyclone::ParticleCable", ptr %13, i32 0, i32 1
  %43 = load double, ptr %42, align 8, !tbaa !13
  %44 = fsub double %41, %43
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = getelementptr inbounds %"class.cyclone::ParticleContact", ptr %45, i32 0, i32 3
  store double %44, ptr %46, align 8, !tbaa !18
  %47 = getelementptr inbounds %"class.cyclone::ParticleCable", ptr %13, i32 0, i32 2
  %48 = load double, ptr %47, align 8, !tbaa !21
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %"class.cyclone::ParticleContact", ptr %49, i32 0, i32 1
  store double %48, ptr %50, 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 %51

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

; 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

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 = !{!"_ZTSN7cyclone13ParticleCableE", !15, i64 0, !12, i64 24, !12, i64 32}
!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 = !{!14, !12, i64 32}
!22 = !{!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
define dso_local noundef range(i32 0, 2) i32 @_ZNK7cyclone13ParticleCable10addContactEPNS_15ParticleContactEj(ptr noundef nonnull align 8 dereferenceable(40) %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 = tail call noundef double @_ZNK7cyclone12ParticleLink13currentLengthEv(ptr noundef nonnull align 8 dereferenceable(24) %0)
  %8 = getelementptr inbounds i8, ptr %0, i64 24
  %9 = load double, ptr %8, align 8, !tbaa !5
  %10 = fcmp olt double %7, %9
  br i1 %10, label %25, label %11

11:                                               ; preds = %3
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  %13 = load ptr, ptr %12, align 8, !tbaa !12
  store ptr %13, ptr %1, align 8, !tbaa !12
  %14 = getelementptr inbounds i8, ptr %0, i64 16
  %15 = load ptr, ptr %14, align 8, !tbaa !12
  %16 = getelementptr inbounds i8, ptr %1, i64 8
  store ptr %15, ptr %16, 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) %15)
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %6) #4
  %17 = load ptr, ptr %12, 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) %17)
  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)
  %18 = getelementptr inbounds i8, ptr %1, i64 24
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %18, ptr noundef nonnull align 8 dereferenceable(32) %4, i64 32, i1 false), !tbaa.struct !14
  %19 = load double, ptr %8, align 8, !tbaa !5
  %20 = fsub double %7, %19
  %21 = getelementptr inbounds i8, ptr %1, i64 56
  store double %20, ptr %21, align 8, !tbaa !16
  %22 = getelementptr inbounds i8, ptr %0, i64 32
  %23 = load double, ptr %22, align 8, !tbaa !19
  %24 = getelementptr inbounds i8, ptr %1, i64 16
  store double %23, ptr %24, align 8, !tbaa !20
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #4
  br label %25

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

; 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

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 = !{!"_ZTSN7cyclone13ParticleCableE", !7, i64 0, !11, i64 24, !11, i64 32}
!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 56}
!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}
!19 = !{!6, !11, i64 32}
!20 = !{!17, !11, i64 16}


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