; LLVM IR from idmillington/cyclone-physics :: src/pfgen.ll (ZN7cyclone16ParticleBuoyancy11updateForceEPNS_8ParticleEd)

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

declare void @_ZN7cyclone8Particle8addForceERKNS_7Vector3E(ptr noundef nonnull align 8 dereferenceable(144), ptr noundef nonnull align 8 dereferenceable(32)) #1

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

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

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

23:                                               ; 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)
  %24 = load double, ptr %7, align 8, !tbaa !9
  %25 = getelementptr inbounds %"class.cyclone::ParticleBuoyancy", ptr %11, i32 0, i32 3
  %26 = load double, ptr %25, align 8, !tbaa !13
  %27 = getelementptr inbounds %"class.cyclone::ParticleBuoyancy", ptr %11, i32 0, i32 1
  %28 = load double, ptr %27, align 8, !tbaa !16
  %29 = fsub double %26, %28
  %30 = fcmp ole double %24, %29
  br i1 %30, label %31, label %39

31:                                               ; preds = %23
  %32 = getelementptr inbounds %"class.cyclone::ParticleBuoyancy", ptr %11, i32 0, i32 4
  %33 = load double, ptr %32, align 8, !tbaa !17
  %34 = getelementptr inbounds %"class.cyclone::ParticleBuoyancy", ptr %11, i32 0, i32 2
  %35 = load double, ptr %34, align 8, !tbaa !18
  %36 = fmul double %33, %35
  %37 = getelementptr inbounds %"class.cyclone::Vector3", ptr %10, i32 0, i32 1
  store double %36, ptr %37, align 8, !tbaa !11
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_ZN7cyclone8Particle8addForceERKNS_7Vector3E(ptr noundef nonnull align 8 dereferenceable(144) %38, ptr noundef nonnull align 8 dereferenceable(32) %10)
  store i32 1, ptr %9, align 4
  br label %59

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

59:                                               ; preds = %39, %31
  call void @llvm.lifetime.end.p0(i64 32, ptr %10) #4
  br label %60

60:                                               ; preds = %59, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  %61 = load i32, ptr %9, align 4
  switch i32 %61, label %63 [
    i32 0, label %62
    i32 1, label %62
  ]

62:                                               ; preds = %60, %60
  ret void

63:                                               ; preds = %60
  unreachable
}

; 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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { 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 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 = !{!"_ZTSN7cyclone16ParticleBuoyancyE", !15, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!15 = !{!"_ZTSN7cyclone22ParticleForceGeneratorE"}
!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

declare void @_ZN7cyclone8Particle8addForceERKNS_7Vector3E(ptr noundef nonnull align 8 dereferenceable(144), ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #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 #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7cyclone16ParticleBuoyancy11updateForceEPNS_8ParticleEd(ptr nocapture noundef nonnull readonly align 8 dereferenceable(40) %0, ptr noundef nonnull %1, double noundef %2) unnamed_addr #2 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
  call void @_ZNK7cyclone8Particle11getPositionEv(ptr dead_on_unwind nonnull writable sret(%"class.cyclone::Vector3") align 8 %4, ptr noundef nonnull align 8 dereferenceable(144) %1)
  %6 = getelementptr inbounds i8, ptr %4, i64 8
  %7 = load double, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #4
  %8 = getelementptr inbounds i8, ptr %0, i64 24
  %9 = load double, ptr %8, align 8, !tbaa !10
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  %11 = load double, ptr %10, align 8, !tbaa !13
  %12 = fadd double %9, %11
  %13 = fcmp ult double %7, %12
  br i1 %13, label %14, label %32

14:                                               ; 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)
  %15 = load double, ptr %8, align 8, !tbaa !10
  %16 = load double, ptr %10, align 8, !tbaa !13
  %17 = fsub double %15, %16
  %18 = fcmp ugt double %7, %17
  %19 = getelementptr inbounds i8, ptr %0, i64 32
  %20 = load double, ptr %19, align 8, !tbaa !14
  %21 = getelementptr inbounds i8, ptr %0, i64 16
  %22 = load double, ptr %21, align 8, !tbaa !15
  %23 = fmul double %20, %22
  br i1 %18, label %24, label %30

24:                                               ; preds = %14
  %25 = fsub double %7, %16
  %26 = fsub double %25, %15
  %27 = fmul double %26, %23
  %28 = fmul double %16, 2.000000e+00
  %29 = fdiv double %27, %28
  br label %30

30:                                               ; preds = %14, %24
  %.sink = phi double [ %29, %24 ], [ %23, %14 ]
  %31 = getelementptr inbounds i8, ptr %5, i64 8
  store double %.sink, ptr %31, align 8, !tbaa !5
  call void @_ZN7cyclone8Particle8addForceERKNS_7Vector3E(ptr noundef nonnull align 8 dereferenceable(144) %1, ptr noundef nonnull align 8 dereferenceable(32) %5)
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #4
  br label %32

32:                                               ; preds = %3, %30
  ret void
}

; 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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { 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 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 = !{!"_ZTSN7cyclone16ParticleBuoyancyE", !12, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32}
!12 = !{!"_ZTSN7cyclone22ParticleForceGeneratorE"}
!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