; LLVM IR from idmillington/cyclone-physics :: src/contacts.ll (ZN7cyclone7Contact29calculateDesiredDeltaVelocityEd)

; 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::Contact" = type { [2 x ptr], double, double, %"class.cyclone::Vector3", %"class.cyclone::Vector3", double, %"class.cyclone::Matrix3", %"class.cyclone::Vector3", double, [2 x %"class.cyclone::Vector3"] }
%"class.cyclone::Matrix3" = type { [9 x double] }

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK7cyclone9RigidBody8getAwakeEv(ptr noundef nonnull align 8 dereferenceable(536)) #1 align 2

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7cyclone7Contact29calculateDesiredDeltaVelocityEd(ptr noundef nonnull align 8 dereferenceable(280) %0, double noundef %1) #3 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca %"class.cyclone::Vector3", align 8
  %7 = alloca %"class.cyclone::Vector3", align 8
  %8 = alloca %"class.cyclone::Vector3", align 8
  %9 = alloca %"class.cyclone::Vector3", align 8
  %10 = alloca double, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store double %1, ptr %4, align 8, !tbaa !9
  %11 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  store double 0.000000e+00, ptr %5, align 8, !tbaa !9
  %12 = getelementptr inbounds %"class.cyclone::Contact", ptr %11, i32 0, i32 0
  %13 = getelementptr inbounds [2 x ptr], ptr %12, i64 0, i64 0
  %14 = load ptr, ptr %13, align 8, !tbaa !5
  %15 = call noundef zeroext i1 @_ZNK7cyclone9RigidBody8getAwakeEv(ptr noundef nonnull align 8 dereferenceable(536) %14)
  br i1 %15, label %16, label %25

16:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 32, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 32, ptr %7) #5
  %17 = getelementptr inbounds %"class.cyclone::Contact", ptr %11, i32 0, i32 0
  %18 = getelementptr inbounds [2 x ptr], ptr %17, i64 0, i64 0
  %19 = load ptr, ptr %18, align 8, !tbaa !5
  call void @_ZNK7cyclone9RigidBody24getLastFrameAccelerationEv(ptr dead_on_unwind writable sret(%"class.cyclone::Vector3") align 8 %7, ptr noundef nonnull align 8 dereferenceable(536) %19)
  %20 = load double, ptr %4, align 8, !tbaa !9
  call void @_ZNK7cyclone7Vector3mlEd(ptr dead_on_unwind writable sret(%"class.cyclone::Vector3") align 8 %6, ptr noundef nonnull align 8 dereferenceable(32) %7, double noundef %20)
  %21 = getelementptr inbounds %"class.cyclone::Contact", ptr %11, i32 0, i32 4
  %22 = call noundef double @_ZNK7cyclone7Vector3mlERKS0_(ptr noundef nonnull align 8 dereferenceable(32) %6, ptr noundef nonnull align 8 dereferenceable(32) %21)
  %23 = load double, ptr %5, align 8, !tbaa !9
  %24 = fadd double %23, %22
  store double %24, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 32, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr %6) #5
  br label %25

25:                                               ; preds = %16, %2
  %26 = getelementptr inbounds %"class.cyclone::Contact", ptr %11, i32 0, i32 0
  %27 = getelementptr inbounds [2 x ptr], ptr %26, i64 0, i64 1
  %28 = load ptr, ptr %27, align 8, !tbaa !5
  %29 = icmp ne ptr %28, null
  br i1 %29, label %30, label %44

30:                                               ; preds = %25
  %31 = getelementptr inbounds %"class.cyclone::Contact", ptr %11, i32 0, i32 0
  %32 = getelementptr inbounds [2 x ptr], ptr %31, i64 0, i64 1
  %33 = load ptr, ptr %32, align 8, !tbaa !5
  %34 = call noundef zeroext i1 @_ZNK7cyclone9RigidBody8getAwakeEv(ptr noundef nonnull align 8 dereferenceable(536) %33)
  br i1 %34, label %35, label %44

35:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 32, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 32, ptr %9) #5
  %36 = getelementptr inbounds %"class.cyclone::Contact", ptr %11, i32 0, i32 0
  %37 = getelementptr inbounds [2 x ptr], ptr %36, i64 0, i64 1
  %38 = load ptr, ptr %37, align 8, !tbaa !5
  call void @_ZNK7cyclone9RigidBody24getLastFrameAccelerationEv(ptr dead_on_unwind writable sret(%"class.cyclone::Vector3") align 8 %9, ptr noundef nonnull align 8 dereferenceable(536) %38)
  %39 = load double, ptr %4, align 8, !tbaa !9
  call void @_ZNK7cyclone7Vector3mlEd(ptr dead_on_unwind writable sret(%"class.cyclone::Vector3") align 8 %8, ptr noundef nonnull align 8 dereferenceable(32) %9, double noundef %39)
  %40 = getelementptr inbounds %"class.cyclone::Contact", ptr %11, i32 0, i32 4
  %41 = call noundef double @_ZNK7cyclone7Vector3mlERKS0_(ptr noundef nonnull align 8 dereferenceable(32) %8, ptr noundef nonnull align 8 dereferenceable(32) %40)
  %42 = load double, ptr %5, align 8, !tbaa !9
  %43 = fsub double %42, %41
  store double %43, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 32, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr %8) #5
  br label %44

44:                                               ; preds = %35, %30, %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %45 = getelementptr inbounds %"class.cyclone::Contact", ptr %11, i32 0, i32 2
  %46 = load double, ptr %45, align 8, !tbaa !11
  store double %46, ptr %10, align 8, !tbaa !9
  %47 = getelementptr inbounds %"class.cyclone::Contact", ptr %11, i32 0, i32 7
  %48 = getelementptr inbounds %"class.cyclone::Vector3", ptr %47, i32 0, i32 0
  %49 = load double, ptr %48, align 8, !tbaa !15
  %50 = call double @llvm.fabs.f64(double %49)
  %51 = fcmp olt double %50, 2.500000e-01
  br i1 %51, label %52, label %53

52:                                               ; preds = %44
  store double 0.000000e+00, ptr %10, align 8, !tbaa !9
  br label %53

53:                                               ; preds = %52, %44
  %54 = getelementptr inbounds %"class.cyclone::Contact", ptr %11, i32 0, i32 7
  %55 = getelementptr inbounds %"class.cyclone::Vector3", ptr %54, i32 0, i32 0
  %56 = load double, ptr %55, align 8, !tbaa !15
  %57 = fneg double %56
  %58 = load double, ptr %10, align 8, !tbaa !9
  %59 = getelementptr inbounds %"class.cyclone::Contact", ptr %11, i32 0, i32 7
  %60 = getelementptr inbounds %"class.cyclone::Vector3", ptr %59, i32 0, i32 0
  %61 = load double, ptr %60, align 8, !tbaa !15
  %62 = load double, ptr %5, align 8, !tbaa !9
  %63 = fsub double %61, %62
  %64 = fneg double %58
  %65 = call double @llvm.fmuladd.f64(double %64, double %63, double %57)
  %66 = getelementptr inbounds %"class.cyclone::Contact", ptr %11, i32 0, i32 8
  store double %65, ptr %66, align 8, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK7cyclone7Vector3mlERKS0_(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(32)) #1 align 2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #4

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 24}
!12 = !{!"_ZTSN7cyclone7ContactE", !7, i64 0, !10, i64 16, !10, i64 24, !13, i64 32, !13, i64 64, !10, i64 96, !14, i64 104, !13, i64 176, !10, i64 208, !7, i64 216}
!13 = !{!"_ZTSN7cyclone7Vector3E", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!14 = !{!"_ZTSN7cyclone7Matrix3E", !7, i64 0}
!15 = !{!12, !10, i64 176}
!16 = !{!12, !10, i64 208}


; 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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK7cyclone9RigidBody8getAwakeEv(ptr noundef nonnull align 8 dereferenceable(536)) local_unnamed_addr #1 align 2

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7cyclone7Contact29calculateDesiredDeltaVelocityEd(ptr noundef nonnull align 8 dereferenceable(280) %0, double noundef %1) local_unnamed_addr #3 align 2 {
  %3 = alloca %"class.cyclone::Vector3", align 8
  %4 = alloca %"class.cyclone::Vector3", align 8
  %5 = alloca %"class.cyclone::Vector3", align 8
  %6 = alloca %"class.cyclone::Vector3", align 8
  %7 = load ptr, ptr %0, align 8, !tbaa !5
  %8 = tail call noundef zeroext i1 @_ZNK7cyclone9RigidBody8getAwakeEv(ptr noundef nonnull align 8 dereferenceable(536) %7)
  br i1 %8, label %9, label %14

9:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %3) #5
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %4) #5
  %10 = load ptr, ptr %0, align 8, !tbaa !5
  call void @_ZNK7cyclone9RigidBody24getLastFrameAccelerationEv(ptr dead_on_unwind nonnull writable sret(%"class.cyclone::Vector3") align 8 %4, ptr noundef nonnull align 8 dereferenceable(536) %10)
  call void @_ZNK7cyclone7Vector3mlEd(ptr dead_on_unwind nonnull writable sret(%"class.cyclone::Vector3") align 8 %3, ptr noundef nonnull align 8 dereferenceable(32) %4, double noundef %1)
  %11 = getelementptr inbounds i8, ptr %0, i64 64
  %12 = call noundef double @_ZNK7cyclone7Vector3mlERKS0_(ptr noundef nonnull align 8 dereferenceable(32) %3, ptr noundef nonnull align 8 dereferenceable(32) %11)
  %13 = fadd double %12, 0.000000e+00
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %3) #5
  br label %14

14:                                               ; preds = %9, %2
  %.07 = phi double [ %13, %9 ], [ 0.000000e+00, %2 ]
  %15 = getelementptr inbounds i8, ptr %0, i64 8
  %16 = load ptr, ptr %15, align 8, !tbaa !5
  %.not = icmp eq ptr %16, null
  br i1 %.not, label %24, label %17

17:                                               ; preds = %14
  %18 = call noundef zeroext i1 @_ZNK7cyclone9RigidBody8getAwakeEv(ptr noundef nonnull align 8 dereferenceable(536) %16)
  br i1 %18, label %19, label %24

19:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %5) #5
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %6) #5
  %20 = load ptr, ptr %15, align 8, !tbaa !5
  call void @_ZNK7cyclone9RigidBody24getLastFrameAccelerationEv(ptr dead_on_unwind nonnull writable sret(%"class.cyclone::Vector3") align 8 %6, ptr noundef nonnull align 8 dereferenceable(536) %20)
  call void @_ZNK7cyclone7Vector3mlEd(ptr dead_on_unwind nonnull writable sret(%"class.cyclone::Vector3") align 8 %5, ptr noundef nonnull align 8 dereferenceable(32) %6, double noundef %1)
  %21 = getelementptr inbounds i8, ptr %0, i64 64
  %22 = call noundef double @_ZNK7cyclone7Vector3mlERKS0_(ptr noundef nonnull align 8 dereferenceable(32) %5, ptr noundef nonnull align 8 dereferenceable(32) %21)
  %23 = fsub double %.07, %22
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %6) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #5
  br label %24

24:                                               ; preds = %19, %17, %14
  %.1 = phi double [ %23, %19 ], [ %.07, %17 ], [ %.07, %14 ]
  %25 = getelementptr inbounds i8, ptr %0, i64 24
  %26 = load double, ptr %25, align 8, !tbaa !9
  %27 = getelementptr inbounds i8, ptr %0, i64 176
  %28 = load double, ptr %27, align 8, !tbaa !14
  %29 = call double @llvm.fabs.f64(double %28)
  %30 = fcmp olt double %29, 2.500000e-01
  %31 = fneg double %28
  %32 = fsub double %28, %.1
  %.neg = fneg double %26
  %33 = select i1 %30, double -0.000000e+00, double %.neg
  %34 = call double @llvm.fmuladd.f64(double %33, double %32, double %31)
  %35 = getelementptr inbounds i8, ptr %0, i64 208
  store double %34, ptr %35, align 8, !tbaa !15
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK7cyclone7Vector3mlERKS0_(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #4

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !11, i64 24}
!10 = !{!"_ZTSN7cyclone7ContactE", !7, i64 0, !11, i64 16, !11, i64 24, !12, i64 32, !12, i64 64, !11, i64 96, !13, i64 104, !12, i64 176, !11, i64 208, !7, i64 216}
!11 = !{!"double", !7, i64 0}
!12 = !{!"_ZTSN7cyclone7Vector3E", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24}
!13 = !{!"_ZTSN7cyclone7Matrix3E", !7, i64 0}
!14 = !{!10, !11, i64 176}
!15 = !{!10, !11, i64 208}


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