; LLVM IR from erayzesen/QuarkPhysics :: QuarkPhysics/qsoftbody.ll (ZN9QSoftBody10ApplyForceE7QVector)

; 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"

%struct.QVector = type { float, float }
%class.QBody = type <{ ptr, float, float, ptr, %struct.QVector, %struct.QVector, float, float, %class.QAABB, i32, i8, i8, i8, i8, float, i32, i8, [3 x i8], float, i8, i8, [2 x i8], %struct.QVector, float, float, float, float, float, i32, i32, i8, i8, i8, i8, i32, i32, i32, i8, [3 x i8], %"class.std::function", %"class.std::function", %"class.std::function.30", i8, [7 x i8], %"class.std::vector.33", i32, i8, [3 x i8] }>
%class.QAABB = type { %struct.QVector, %struct.QVector, %struct.QVector, float }
%"class.std::function" = type { %"class.std::_Function_base", ptr }
%"class.std::_Function_base" = type { %"union.std::_Any_data", ptr }
%"union.std::_Any_data" = type { %"union.std::_Nocopy_types" }
%"union.std::_Nocopy_types" = type { { i64, i64 } }
%"class.std::function.30" = type { %"class.std::_Function_base", ptr }
%"class.std::vector.33" = type { %"struct.std::_Vector_base.34" }
%"struct.std::_Vector_base.34" = type { %"struct.std::_Vector_base<QMesh *, std::allocator<QMesh *>>::_Vector_impl" }
%"struct.std::_Vector_base<QMesh *, std::allocator<QMesh *>>::_Vector_impl" = type { %"struct.std::_Vector_base<QMesh *, std::allocator<QMesh *>>::_Vector_impl_data" }
%"struct.std::_Vector_base<QMesh *, std::allocator<QMesh *>>::_Vector_impl_data" = type { ptr, ptr, 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: 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 noundef ptr @_ZN9QSoftBody10ApplyForceE7QVector(ptr noundef nonnull align 8 dereferenceable(360) %0, <2 x float> %1) unnamed_addr #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca %struct.QVector, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca %struct.QVector, align 4
  store <2 x float> %1, ptr %4, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  %12 = load ptr, ptr %5, align 8
  %13 = call noundef i32 @_ZN5QBody7GetModeEv(ptr noundef nonnull align 8 dereferenceable(293) %12)
  %14 = icmp eq i32 %13, 1
  br i1 %14, label %19, label %15

15:                                               ; preds = %2
  %16 = call noundef zeroext i1 @_ZN5QBody10GetEnabledEv(ptr noundef nonnull align 8 dereferenceable(293) %12)
  %17 = zext i1 %16 to i32
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %19, label %20

19:                                               ; preds = %15, %2
  store ptr %12, ptr %3, align 8
  br label %64

20:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %21

21:                                               ; preds = %60, %20
  %22 = load i32, ptr %6, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds %class.QBody, ptr %12, i32 0, i32 44
  %25 = call noundef i64 @_ZNKSt6vectorIP5QMeshSaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %24) #5
  %26 = icmp ult i64 %23, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %21
  store i32 2, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %63

28:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %29 = getelementptr inbounds %class.QBody, ptr %12, i32 0, i32 44
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP5QMeshSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %29, i64 noundef %31) #5
  %33 = load ptr, ptr %32, align 8, !tbaa !5
  store ptr %33, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %34

34:                                               ; preds = %56, %28
  %35 = load i32, ptr %9, align 4, !tbaa !9
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = call noundef i32 @_ZN5QMesh16GetParticleCountEv(ptr noundef nonnull align 8 dereferenceable(256) %36)
  %38 = icmp slt i32 %35, %37
  br i1 %38, label %40, label %39

39:                                               ; preds = %34
  store i32 5, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  br label %59

40:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = load i32, ptr %9, align 4, !tbaa !9
  %43 = call noundef ptr @_ZN5QMesh13GetParticleAtEi(ptr noundef nonnull align 8 dereferenceable(256) %41, i32 noundef %42)
  store ptr %43, ptr %10, align 8, !tbaa !5
  %44 = load ptr, ptr %10, align 8, !tbaa !5
  %45 = call noundef zeroext i1 @_ZN9QParticle10GetEnabledEv(ptr noundef nonnull align 8 dereferenceable(290) %44)
  %46 = zext i1 %45 to i32
  %47 = icmp eq i32 %46, 0
  br i1 %47, label %48, label %49

48:                                               ; preds = %40
  store i32 7, ptr %7, align 4
  br label %53

49:                                               ; preds = %40
  %50 = load ptr, ptr %10, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %11, ptr align 4 %4, i64 8, i1 false), !tbaa.struct !11
  %51 = load <2 x float>, ptr %11, align 4
  %52 = call noundef ptr @_ZN9QParticle10ApplyForceE7QVector(ptr noundef nonnull align 8 dereferenceable(290) %50, <2 x float> %51)
  store i32 0, ptr %7, align 4
  br label %53

53:                                               ; preds = %49, %48
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  %54 = load i32, ptr %7, align 4
  switch i32 %54, label %66 [
    i32 0, label %55
    i32 7, label %56
  ]

55:                                               ; preds = %53
  br label %56

56:                                               ; preds = %55, %53
  %57 = load i32, ptr %9, align 4, !tbaa !9
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %9, align 4, !tbaa !9
  br label %34, !llvm.loop !14

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

60:                                               ; preds = %59
  %61 = load i32, ptr %6, align 4, !tbaa !9
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %6, align 4, !tbaa !9
  br label %21, !llvm.loop !16

63:                                               ; preds = %27
  store ptr %12, ptr %3, align 8
  br label %64

64:                                               ; preds = %63, %19
  %65 = load ptr, ptr %3, align 8
  ret ptr %65

66:                                               ; preds = %53
  unreachable
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN5QBody7GetModeEv(ptr noundef nonnull align 8 dereferenceable(293)) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN5QBody10GetEnabledEv(ptr noundef nonnull align 8 dereferenceable(293)) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIP5QMeshSaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP5QMeshSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #3 align 2

declare noundef i32 @_ZN5QMesh16GetParticleCountEv(ptr noundef nonnull align 8 dereferenceable(256)) #4

declare noundef ptr @_ZN5QMesh13GetParticleAtEi(ptr noundef nonnull align 8 dereferenceable(256), i32 noundef) #4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN9QParticle10GetEnabledEv(ptr noundef nonnull align 8 dereferenceable(290)) #3 align 2

declare noundef ptr @_ZN9QParticle10ApplyForceE7QVector(ptr noundef nonnull align 8 dereferenceable(290), <2 x float>) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress uwtable "min-legal-vector-width"="64" "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 = { "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 = !{!"int", !7, i64 0}
!11 = !{i64 0, i64 4, !12, i64 4, i64 4, !12}
!12 = !{!13, !13, i64 0}
!13 = !{!"float", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


; 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"

; Function Attrs: mustprogress uwtable
define dso_local noundef nonnull ptr @_ZN9QSoftBody10ApplyForceE7QVector(ptr noundef nonnull returned align 8 dereferenceable(360) %0, <2 x float> %1) unnamed_addr #0 align 2 {
  %3 = tail call noundef i32 @_ZN5QBody7GetModeEv(ptr noundef nonnull align 8 dereferenceable(293) %0)
  %4 = icmp eq i32 %3, 1
  br i1 %4, label %.loopexit, label %5

5:                                                ; preds = %2
  %6 = tail call noundef zeroext i1 @_ZN5QBody10GetEnabledEv(ptr noundef nonnull align 8 dereferenceable(293) %0)
  br i1 %6, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %5
  %7 = getelementptr inbounds i8, ptr %0, i64 264
  %8 = tail call noundef i64 @_ZNKSt6vectorIP5QMeshSaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %7) #3
  %.not = icmp eq i64 %8, 0
  br i1 %.not, label %.loopexit, label %.lr.ph16

.lr.ph16:                                         ; preds = %.preheader, %._crit_edge
  %indvars.iv = phi i64 [ %indvars.iv.next, %._crit_edge ], [ 0, %.preheader ]
  %9 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP5QMeshSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %7, i64 noundef %indvars.iv) #3
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %11 = tail call noundef i32 @_ZN5QMesh16GetParticleCountEv(ptr noundef nonnull align 8 dereferenceable(256) %10)
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %19, %.lr.ph16
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %13 = tail call noundef i64 @_ZNKSt6vectorIP5QMeshSaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %7) #3
  %14 = icmp ugt i64 %13, %indvars.iv.next
  br i1 %14, label %.lr.ph16, label %.loopexit, !llvm.loop !9

.lr.ph:                                           ; preds = %.lr.ph16, %19
  %.01314 = phi i32 [ %20, %19 ], [ 0, %.lr.ph16 ]
  %15 = tail call noundef ptr @_ZN5QMesh13GetParticleAtEi(ptr noundef nonnull align 8 dereferenceable(256) %10, i32 noundef %.01314)
  %16 = tail call noundef zeroext i1 @_ZN9QParticle10GetEnabledEv(ptr noundef nonnull align 8 dereferenceable(290) %15)
  br i1 %16, label %17, label %19

17:                                               ; preds = %.lr.ph
  %18 = tail call noundef ptr @_ZN9QParticle10ApplyForceE7QVector(ptr noundef nonnull align 8 dereferenceable(290) %15, <2 x float> %1)
  br label %19

19:                                               ; preds = %.lr.ph, %17
  %20 = add nuw nsw i32 %.01314, 1
  %21 = tail call noundef i32 @_ZN5QMesh16GetParticleCountEv(ptr noundef nonnull align 8 dereferenceable(256) %10)
  %22 = icmp slt i32 %20, %21
  br i1 %22, label %.lr.ph, label %._crit_edge, !llvm.loop !11

.loopexit:                                        ; preds = %._crit_edge, %.preheader, %2, %5
  ret ptr %0
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN5QBody7GetModeEv(ptr noundef nonnull align 8 dereferenceable(293)) local_unnamed_addr #1 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIP5QMeshSaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP5QMeshSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #1 align 2

declare noundef i32 @_ZN5QMesh16GetParticleCountEv(ptr noundef nonnull align 8 dereferenceable(256)) local_unnamed_addr #2

declare noundef ptr @_ZN5QMesh13GetParticleAtEi(ptr noundef nonnull align 8 dereferenceable(256), i32 noundef) local_unnamed_addr #2

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

declare noundef ptr @_ZN9QParticle10ApplyForceE7QVector(ptr noundef nonnull align 8 dereferenceable(290), <2 x float>) local_unnamed_addr #2

attributes #0 = { mustprogress uwtable "min-legal-vector-width"="64" "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 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 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass