; LLVM IR from idmillington/cyclone-physics :: src/fgen.ll (ZN7cyclone8Buoyancy11updateForceEPNS_9RigidBodyEd)

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

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

; 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
define dso_local void @_ZN7cyclone8Buoyancy11updateForceEPNS_9RigidBodyEd(ptr noundef nonnull align 8 dereferenceable(72) %0, ptr noundef %1, double noundef %2) unnamed_addr #1 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca double, align 8
  %7 = alloca %"class.cyclone::Vector3", align 8
  %8 = alloca double, align 8
  %9 = alloca i32, align 4
  %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 double %2, ptr %6, align 8, !tbaa !9
  %11 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 32, ptr %7) #4
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds %"class.cyclone::Buoyancy", ptr %11, i32 0, i32 5
  call void @_ZNK7cyclone9RigidBody20getPointInWorldSpaceERKNS_7Vector3E(ptr dead_on_unwind writable sret(%"class.cyclone::Vector3") align 8 %7, ptr noundef nonnull align 8 dereferenceable(536) %12, ptr noundef nonnull align 8 dereferenceable(32) %13)
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %14 = getelementptr inbounds %"class.cyclone::Vector3", ptr %7, i32 0, i32 1
  %15 = load double, ptr %14, align 8, !tbaa !11
  store double %15, ptr %8, align 8, !tbaa !9
  %16 = load double, ptr %8, align 8, !tbaa !9
  %17 = getelementptr inbounds %"class.cyclone::Buoyancy", ptr %11, i32 0, i32 3
  %18 = load double, ptr %17, align 8, !tbaa !13
  %19 = getelementptr inbounds %"class.cyclone::Buoyancy", ptr %11, i32 0, i32 1
  %20 = load double, ptr %19, align 8, !tbaa !16
  %21 = fadd double %18, %20
  %22 = fcmp oge double %16, %21
  br i1 %22, label %23, label %24

23:                                               ; preds = %3
  store i32 1, ptr %9, align 4
  br label %63

24:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 32, ptr %10) #4
  call void @_ZN7cyclone7Vector3C2Eddd(ptr noundef nonnull align 8 dereferenceable(32) %10, double noundef 0.000000e+00, double noundef 0.000000e+00, double noundef 0.000000e+00)
  %25 = load double, ptr %8, align 8, !tbaa !9
  %26 = getelementptr inbounds %"class.cyclone::Buoyancy", ptr %11, i32 0, i32 3
  %27 = load double, ptr %26, align 8, !tbaa !13
  %28 = getelementptr inbounds %"class.cyclone::Buoyancy", ptr %11, i32 0, i32 1
  %29 = load double, ptr %28, align 8, !tbaa !16
  %30 = fsub double %27, %29
  %31 = fcmp ole double %25, %30
  br i1 %31, label %32, label %41

32:                                               ; preds = %24
  %33 = getelementptr inbounds %"class.cyclone::Buoyancy", ptr %11, i32 0, i32 4
  %34 = load double, ptr %33, align 8, !tbaa !17
  %35 = getelementptr inbounds %"class.cyclone::Buoyancy", ptr %11, i32 0, i32 2
  %36 = load double, ptr %35, align 8, !tbaa !18
  %37 = fmul double %34, %36
  %38 = getelementptr inbounds %"class.cyclone::Vector3", ptr %10, i32 0, i32 1
  store double %37, ptr %38, align 8, !tbaa !11
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds %"class.cyclone::Buoyancy", ptr %11, i32 0, i32 5
  call void @_ZN7cyclone9RigidBody19addForceAtBodyPointERKNS_7Vector3ES3_(ptr noundef nonnull align 8 dereferenceable(536) %39, ptr noundef nonnull align 8 dereferenceable(32) %10, ptr noundef nonnull align 8 dereferenceable(32) %40)
  store i32 1, ptr %9, align 4
  br label %62

41:                                               ; preds = %24
  %42 = getelementptr inbounds %"class.cyclone::Buoyancy", ptr %11, i32 0, i32 4
  %43 = load double, ptr %42, align 8, !tbaa !17
  %44 = getelementptr inbounds %"class.cyclone::Buoyancy", ptr %11, i32 0, i32 2
  %45 = load double, ptr %44, align 8, !tbaa !18
  %46 = fmul double %43, %45
  %47 = load double, ptr %8, align 8, !tbaa !9
  %48 = getelementptr inbounds %"class.cyclone::Buoyancy", ptr %11, i32 0, i32 1
  %49 = load double, ptr %48, align 8, !tbaa !16
  %50 = fsub double %47, %49
  %51 = getelementptr inbounds %"class.cyclone::Buoyancy", ptr %11, i32 0, i32 3
  %52 = load double, ptr %51, align 8, !tbaa !13
  %53 = fsub double %50, %52
  %54 = fmul double %46, %53
  %55 = fdiv double %54, 2.000000e+00
  %56 = getelementptr inbounds %"class.cyclone::Buoyancy", ptr %11, i32 0, i32 1
  %57 = load double, ptr %56, align 8, !tbaa !16
  %58 = fmul double %55, %57
  %59 = getelementptr inbounds %"class.cyclone::Vector3", ptr %10, i32 0, i32 1
  store double %58, ptr %59, align 8, !tbaa !11
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %"class.cyclone::Buoyancy", ptr %11, i32 0, i32 5
  call void @_ZN7cyclone9RigidBody19addForceAtBodyPointERKNS_7Vector3ES3_(ptr noundef nonnull align 8 dereferenceable(536) %60, ptr noundef nonnull align 8 dereferenceable(32) %10, ptr noundef nonnull align 8 dereferenceable(32) %61)
  store i32 0, ptr %9, align 4
  br label %62

62:                                               ; preds = %41, %32
  call void @llvm.lifetime.end.p0(i64 32, ptr %10) #4
  br label %63

63:                                               ; preds = %62, %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %7) #4
  %64 = load i32, ptr %9, align 4
  switch i32 %64, label %66 [
    i32 0, label %65
    i32 1, label %65
  ]

65:                                               ; preds = %63, %63
  ret void

66:                                               ; preds = %63
  unreachable
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7cyclone7Vector3C2Eddd(ptr noundef nonnull align 8 dereferenceable(32), double noundef, double noundef, double noundef) unnamed_addr #3 align 2

declare void @_ZN7cyclone9RigidBody19addForceAtBodyPointERKNS_7Vector3ES3_(ptr noundef nonnull align 8 dereferenceable(536), ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(32)) #2

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

; 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
define dso_local void @_ZN7cyclone8Buoyancy11updateForceEPNS_9RigidBodyEd(ptr noundef nonnull align 8 dereferenceable(72) %0, ptr noundef nonnull %1, double noundef %2) unnamed_addr #1 align 2 {
  %4 = alloca %"class.cyclone::Vector3", align 8
  %5 = alloca %"class.cyclone::Vector3", align 8
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %4) #4
  %6 = getelementptr inbounds i8, ptr %0, i64 40
  call void @_ZNK7cyclone9RigidBody20getPointInWorldSpaceERKNS_7Vector3E(ptr dead_on_unwind nonnull writable sret(%"class.cyclone::Vector3") align 8 %4, ptr noundef nonnull align 8 dereferenceable(536) %1, ptr noundef nonnull align 8 dereferenceable(32) %6)
  %7 = getelementptr inbounds i8, ptr %4, i64 8
  %8 = load double, ptr %7, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 24
  %10 = load double, ptr %9, align 8, !tbaa !10
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  %12 = load double, ptr %11, align 8, !tbaa !13
  %13 = fadd double %10, %12
  %14 = fcmp ult double %8, %13
  br i1 %14, label %15, label %33

15:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %5) #4
  call void @_ZN7cyclone7Vector3C2Eddd(ptr noundef nonnull align 8 dereferenceable(32) %5, double noundef 0.000000e+00, double noundef 0.000000e+00, double noundef 0.000000e+00)
  %16 = load double, ptr %9, align 8, !tbaa !10
  %17 = load double, ptr %11, align 8, !tbaa !13
  %18 = fsub double %16, %17
  %19 = fcmp ugt double %8, %18
  %20 = getelementptr inbounds i8, ptr %0, i64 32
  %21 = load double, ptr %20, align 8, !tbaa !14
  %22 = getelementptr inbounds i8, ptr %0, i64 16
  %23 = load double, ptr %22, align 8, !tbaa !15
  %24 = fmul double %21, %23
  br i1 %19, label %25, label %31

25:                                               ; preds = %15
  %26 = fsub double %8, %17
  %27 = fsub double %26, %16
  %28 = fmul double %27, %24
  %29 = fmul double %28, 5.000000e-01
  %30 = fmul double %17, %29
  br label %31

31:                                               ; preds = %15, %25
  %.sink = phi double [ %30, %25 ], [ %24, %15 ]
  %32 = getelementptr inbounds i8, ptr %5, i64 8
  store double %.sink, ptr %32, align 8, !tbaa !5
  call void @_ZN7cyclone9RigidBody19addForceAtBodyPointERKNS_7Vector3ES3_(ptr noundef nonnull align 8 dereferenceable(536) %1, 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 %5) #4
  br label %33

33:                                               ; preds = %3, %31
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #4
  ret void
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7cyclone7Vector3C2Eddd(ptr noundef nonnull align 8 dereferenceable(32), double noundef, double noundef, double noundef) unnamed_addr #3 align 2

declare void @_ZN7cyclone9RigidBody19addForceAtBodyPointERKNS_7Vector3ES3_(ptr noundef nonnull align 8 dereferenceable(536), ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #2

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


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