; LLVM IR from idmillington/cyclone-physics :: src/collide_coarse.ll (ZN7cyclone14BoundingSphereC2ERKS0_S2_)

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7cyclone7Vector3C2Ev(ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #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) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7cyclone14BoundingSphereC2ERKS0_S2_(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef nonnull align 8 dereferenceable(40) %1, ptr noundef nonnull align 8 dereferenceable(40) %2) unnamed_addr #2 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca %"class.cyclone::Vector3", align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca %"class.cyclone::Vector3", align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %11 = load ptr, ptr %4, align 8
  %12 = getelementptr inbounds %"struct.cyclone::BoundingSphere", ptr %11, i32 0, i32 0
  call void @_ZN7cyclone7Vector3C2Ev(ptr noundef nonnull align 8 dereferenceable(32) %12)
  call void @llvm.lifetime.start.p0(i64 32, ptr %7) #5
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = getelementptr inbounds %"struct.cyclone::BoundingSphere", ptr %13, i32 0, i32 0
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %"struct.cyclone::BoundingSphere", ptr %15, i32 0, i32 0
  call void @_ZNK7cyclone7Vector3miERKS0_(ptr dead_on_unwind writable sret(%"class.cyclone::Vector3") align 8 %7, ptr noundef nonnull align 8 dereferenceable(32) %14, ptr noundef nonnull align 8 dereferenceable(32) %16)
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %17 = call noundef double @_ZNK7cyclone7Vector315squareMagnitudeEv(ptr noundef nonnull align 8 dereferenceable(32) %7)
  store double %17, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = getelementptr inbounds %"struct.cyclone::BoundingSphere", ptr %18, i32 0, i32 1
  %20 = load double, ptr %19, align 8, !tbaa !11
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %"struct.cyclone::BoundingSphere", ptr %21, i32 0, i32 1
  %23 = load double, ptr %22, align 8, !tbaa !11
  %24 = fsub double %20, %23
  store double %24, ptr %9, align 8, !tbaa !9
  %25 = load double, ptr %9, align 8, !tbaa !9
  %26 = load double, ptr %9, align 8, !tbaa !9
  %27 = fmul double %25, %26
  %28 = load double, ptr %8, align 8, !tbaa !9
  %29 = fcmp oge double %27, %28
  br i1 %29, label %30, label %55

30:                                               ; preds = %3
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %"struct.cyclone::BoundingSphere", ptr %31, i32 0, i32 1
  %33 = load double, ptr %32, align 8, !tbaa !11
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %"struct.cyclone::BoundingSphere", ptr %34, i32 0, i32 1
  %36 = load double, ptr %35, align 8, !tbaa !11
  %37 = fcmp ogt double %33, %36
  br i1 %37, label %38, label %46

38:                                               ; preds = %30
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds %"struct.cyclone::BoundingSphere", ptr %39, i32 0, i32 0
  %41 = getelementptr inbounds %"struct.cyclone::BoundingSphere", ptr %11, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %41, ptr align 8 %40, i64 32, i1 false), !tbaa.struct !14
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %"struct.cyclone::BoundingSphere", ptr %42, i32 0, i32 1
  %44 = load double, ptr %43, align 8, !tbaa !11
  %45 = getelementptr inbounds %"struct.cyclone::BoundingSphere", ptr %11, i32 0, i32 1
  store double %44, ptr %45, align 8, !tbaa !11
  br label %54

46:                                               ; preds = %30
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds %"struct.cyclone::BoundingSphere", ptr %47, i32 0, i32 0
  %49 = getelementptr inbounds %"struct.cyclone::BoundingSphere", ptr %11, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %49, ptr align 8 %48, i64 32, i1 false), !tbaa.struct !14
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = getelementptr inbounds %"struct.cyclone::BoundingSphere", ptr %50, i32 0, i32 1
  %52 = load double, ptr %51, align 8, !tbaa !11
  %53 = getelementptr inbounds %"struct.cyclone::BoundingSphere", ptr %11, i32 0, i32 1
  store double %52, ptr %53, align 8, !tbaa !11
  br label %54

54:                                               ; preds = %46, %38
  br label %85

55:                                               ; preds = %3
  %56 = load double, ptr %8, align 8, !tbaa !9
  %57 = call double @sqrt(double noundef %56) #5
  store double %57, ptr %8, align 8, !tbaa !9
  %58 = load double, ptr %8, align 8, !tbaa !9
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds %"struct.cyclone::BoundingSphere", ptr %59, i32 0, i32 1
  %61 = load double, ptr %60, align 8, !tbaa !11
  %62 = fadd double %58, %61
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = getelementptr inbounds %"struct.cyclone::BoundingSphere", ptr %63, i32 0, i32 1
  %65 = load double, ptr %64, align 8, !tbaa !11
  %66 = fadd double %62, %65
  %67 = fmul double %66, 5.000000e-01
  %68 = getelementptr inbounds %"struct.cyclone::BoundingSphere", ptr %11, i32 0, i32 1
  store double %67, ptr %68, align 8, !tbaa !11
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = getelementptr inbounds %"struct.cyclone::BoundingSphere", ptr %69, i32 0, i32 0
  %71 = getelementptr inbounds %"struct.cyclone::BoundingSphere", ptr %11, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %71, ptr align 8 %70, i64 32, i1 false), !tbaa.struct !14
  %72 = load double, ptr %8, align 8, !tbaa !9
  %73 = fcmp ogt double %72, 0.000000e+00
  br i1 %73, label %74, label %84

74:                                               ; preds = %55
  call void @llvm.lifetime.start.p0(i64 32, ptr %10) #5
  %75 = getelementptr inbounds %"struct.cyclone::BoundingSphere", ptr %11, i32 0, i32 1
  %76 = load double, ptr %75, align 8, !tbaa !11
  %77 = load ptr, ptr %5, align 8, !tbaa !5
  %78 = getelementptr inbounds %"struct.cyclone::BoundingSphere", ptr %77, i32 0, i32 1
  %79 = load double, ptr %78, align 8, !tbaa !11
  %80 = fsub double %76, %79
  %81 = load double, ptr %8, align 8, !tbaa !9
  %82 = fdiv double %80, %81
  call void @_ZNK7cyclone7Vector3mlEd(ptr dead_on_unwind writable sret(%"class.cyclone::Vector3") align 8 %10, ptr noundef nonnull align 8 dereferenceable(32) %7, double noundef %82)
  %83 = getelementptr inbounds %"struct.cyclone::BoundingSphere", ptr %11, i32 0, i32 0
  call void @_ZN7cyclone7Vector3pLERKS0_(ptr noundef nonnull align 8 dereferenceable(32) %83, ptr noundef nonnull align 8 dereferenceable(32) %10)
  call void @llvm.lifetime.end.p0(i64 32, ptr %10) #5
  br label %84

84:                                               ; preds = %74, %55
  br label %85

85:                                               ; preds = %84, %54
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr %7) #5
  ret void
}

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

; 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: mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK7cyclone7Vector315squareMagnitudeEv(ptr noundef nonnull align 8 dereferenceable(32)) #0 align 2

; Function Attrs: nounwind
declare double @sqrt(double noundef) #4

; 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 nounwind uwtable
declare dso_local void @_ZN7cyclone7Vector3pLERKS0_(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) #3

attributes #0 = { 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 #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nounwind "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 = !{!"double", !7, i64 0}
!11 = !{!12, !10, i64 32}
!12 = !{!"_ZTSN7cyclone14BoundingSphereE", !13, i64 0, !10, i64 32}
!13 = !{!"_ZTSN7cyclone7Vector3E", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!14 = !{i64 0, i64 8, !9, i64 8, i64 8, !9, i64 16, i64 8, !9, i64 24, i64 8, !9}


; 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 nounwind uwtable
declare dso_local void @_ZN7cyclone7Vector3C2Ev(ptr noundef nonnull align 8 dereferenceable(32)) 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) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7cyclone14BoundingSphereC2ERKS0_S2_(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef nonnull align 8 dereferenceable(40) %1, ptr noundef nonnull align 8 dereferenceable(40) %2) unnamed_addr #2 align 2 {
  %4 = alloca %"class.cyclone::Vector3", align 8
  %5 = alloca %"class.cyclone::Vector3", align 8
  tail call void @_ZN7cyclone7Vector3C2Ev(ptr noundef nonnull align 8 dereferenceable(32) %0)
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %4) #5
  call void @_ZNK7cyclone7Vector3miERKS0_(ptr dead_on_unwind nonnull writable sret(%"class.cyclone::Vector3") align 8 %4, ptr noundef nonnull align 8 dereferenceable(32) %2, ptr noundef nonnull align 8 dereferenceable(32) %1)
  %6 = call noundef double @_ZNK7cyclone7Vector315squareMagnitudeEv(ptr noundef nonnull align 8 dereferenceable(32) %4)
  %7 = getelementptr inbounds i8, ptr %2, i64 32
  %8 = load double, ptr %7, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %1, i64 32
  %10 = load double, ptr %9, align 8, !tbaa !5
  %11 = fsub double %8, %10
  %12 = fmul double %11, %11
  %13 = fcmp ult double %12, %6
  br i1 %13, label %21, label %14

14:                                               ; preds = %3
  %15 = fcmp ogt double %10, %8
  %16 = getelementptr inbounds i8, ptr %0, i64 32
  br i1 %15, label %17, label %19

17:                                               ; preds = %14
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(32) %1, i64 32, i1 false), !tbaa.struct !11
  %18 = load double, ptr %9, align 8, !tbaa !5
  store double %18, ptr %16, align 8, !tbaa !5
  br label %34

19:                                               ; preds = %14
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(32) %2, i64 32, i1 false), !tbaa.struct !11
  %20 = load double, ptr %7, align 8, !tbaa !5
  store double %20, ptr %16, align 8, !tbaa !5
  br label %34

21:                                               ; preds = %3
  %22 = call double @sqrt(double noundef %6) #5
  %23 = load double, ptr %9, align 8, !tbaa !5
  %24 = fadd double %22, %23
  %25 = load double, ptr %7, align 8, !tbaa !5
  %26 = fadd double %24, %25
  %27 = fmul double %26, 5.000000e-01
  %28 = getelementptr inbounds i8, ptr %0, i64 32
  store double %27, ptr %28, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(32) %1, i64 32, i1 false), !tbaa.struct !11
  %29 = fcmp ogt double %22, 0.000000e+00
  br i1 %29, label %30, label %34

30:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %5) #5
  %31 = load double, ptr %9, align 8, !tbaa !5
  %32 = fsub double %27, %31
  %33 = fdiv double %32, %22
  call void @_ZNK7cyclone7Vector3mlEd(ptr dead_on_unwind nonnull writable sret(%"class.cyclone::Vector3") align 8 %5, ptr noundef nonnull align 8 dereferenceable(32) %4, double noundef %33)
  call void @_ZN7cyclone7Vector3pLERKS0_(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(32) %5)
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #5
  br label %34

34:                                               ; preds = %21, %30, %17, %19
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #5
  ret void
}

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

; 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 nounwind uwtable
declare dso_local noundef double @_ZNK7cyclone7Vector315squareMagnitudeEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sqrt(double noundef) local_unnamed_addr #4

; 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 nounwind uwtable
declare dso_local void @_ZN7cyclone7Vector3pLERKS0_(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) #3

attributes #0 = { 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 #1 = { mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { mustprogress nofree nounwind willreturn memory(write) "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, !8, i64 32}
!6 = !{!"_ZTSN7cyclone14BoundingSphereE", !7, i64 0, !8, i64 32}
!7 = !{!"_ZTSN7cyclone7Vector3E", !8, i64 0, !8, i64 8, !8, i64 16, !8, i64 24}
!8 = !{!"double", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{i64 0, i64 8, !12, i64 8, i64 8, !12, i64 16, i64 8, !12, i64 24, i64 8, !12}
!12 = !{!8, !8, i64 0}


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