; LLVM IR from erayzesen/QuarkPhysics :: QuarkPhysics/qbody.ll (ZN5QBody6UpdateEv)

; 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.__gnu_cxx::__normal_iterator" = type { ptr }
%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.0", i8, [7 x i8], %"class.std::vector", i32, i8, [3 x i8] }>
%class.QAABB = type { %struct.QVector, %struct.QVector, %struct.QVector, float }
%struct.QVector = type { float, 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.0" = type { %"class.std::_Function_base", ptr }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = 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: mustprogress nounwind uwtable
declare dso_local ptr @_ZNSt6vectorIP5QMeshSaIS1_EE5beginEv(ptr noundef nonnull align 8 dereferenceable(24)) #1 align 2

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5QBody6UpdateEv(ptr noundef nonnull align 8 dereferenceable(293) %0) unnamed_addr #3 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca %"class.__gnu_cxx::__normal_iterator", align 8
  %5 = alloca %"class.__gnu_cxx::__normal_iterator", align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %10 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %11 = getelementptr inbounds %class.QBody, ptr %10, i32 0, i32 44
  store ptr %11, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = call ptr @_ZNSt6vectorIP5QMeshSaIS1_EE5beginEv(ptr noundef nonnull align 8 dereferenceable(24) %12) #5
  %14 = getelementptr inbounds %"class.__gnu_cxx::__normal_iterator", ptr %4, i32 0, i32 0
  store ptr %13, ptr %14, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = call ptr @_ZNSt6vectorIP5QMeshSaIS1_EE3endEv(ptr noundef nonnull align 8 dereferenceable(24) %15) #5
  %17 = getelementptr inbounds %"class.__gnu_cxx::__normal_iterator", ptr %5, i32 0, i32 0
  store ptr %16, ptr %17, align 8
  br label %18

18:                                               ; preds = %47, %1
  %19 = call noundef zeroext i1 @_ZN9__gnu_cxxneIPP5QMeshSt6vectorIS2_SaIS2_EEEEbRKNS_17__normal_iteratorIT_T0_EESC_(ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef nonnull align 8 dereferenceable(8) %5) #5
  br i1 %19, label %21, label %20

20:                                               ; preds = %18
  store i32 2, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  br label %49

21:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %22 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNK9__gnu_cxx17__normal_iteratorIPP5QMeshSt6vectorIS2_SaIS2_EEEdeEv(ptr noundef nonnull align 8 dereferenceable(8) %4) #5
  %23 = load ptr, ptr %22, align 8, !tbaa !5
  store ptr %23, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  store i64 0, ptr %8, align 8, !tbaa !9
  br label %24

24:                                               ; preds = %43, %21
  %25 = load i64, ptr %8, align 8, !tbaa !9
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = call noundef i32 @_ZN5QMesh16GetParticleCountEv(ptr noundef nonnull align 8 dereferenceable(256) %26)
  %28 = sext i32 %27 to i64
  %29 = icmp ult i64 %25, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %24
  store i32 4, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %46

31:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = load i64, ptr %8, align 8, !tbaa !9
  %34 = trunc i64 %33 to i32
  %35 = call noundef ptr @_ZN5QMesh13GetParticleAtEi(ptr noundef nonnull align 8 dereferenceable(256) %32, i32 noundef %34)
  store ptr %35, ptr %9, align 8, !tbaa !5
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  %37 = call noundef zeroext i1 @_ZN9QParticle9GetIsLazyEv(ptr noundef nonnull align 8 dereferenceable(290) %36)
  %38 = zext i1 %37 to i32
  %39 = icmp eq i32 %38, 1
  br i1 %39, label %40, label %42

40:                                               ; preds = %31
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  call void @_ZN9QParticle22ResetOneTimeCollisionsEv(ptr noundef nonnull align 8 dereferenceable(290) %41)
  br label %42

42:                                               ; preds = %40, %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  br label %43

43:                                               ; preds = %42
  %44 = load i64, ptr %8, align 8, !tbaa !9
  %45 = add i64 %44, 1
  store i64 %45, ptr %8, align 8, !tbaa !9
  br label %24, !llvm.loop !11

46:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  br label %47

47:                                               ; preds = %46
  %48 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN9__gnu_cxx17__normal_iteratorIPP5QMeshSt6vectorIS2_SaIS2_EEEppEv(ptr noundef nonnull align 8 dereferenceable(8) %4) #5
  br label %18

49:                                               ; preds = %20
  ret void
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN9__gnu_cxxneIPP5QMeshSt6vectorIS2_SaIS2_EEEEbRKNS_17__normal_iteratorIT_T0_EESC_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #4

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

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

declare void @_ZN9QParticle22ResetOneTimeCollisionsEv(ptr noundef nonnull align 8 dereferenceable(290)) #2

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

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 = { inlinehint 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 #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 = !{!"long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; 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.__gnu_cxx::__normal_iterator" = type { ptr }

; 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 nounwind uwtable
declare dso_local ptr @_ZNSt6vectorIP5QMeshSaIS1_EE5beginEv(ptr noundef nonnull align 8 dereferenceable(24)) 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 uwtable
define dso_local void @_ZN5QBody6UpdateEv(ptr noundef nonnull align 8 dereferenceable(293) %0) unnamed_addr #3 align 2 {
  %2 = alloca %"class.__gnu_cxx::__normal_iterator", align 8
  %3 = alloca %"class.__gnu_cxx::__normal_iterator", align 8
  %4 = getelementptr inbounds i8, ptr %0, i64 264
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %5 = tail call ptr @_ZNSt6vectorIP5QMeshSaIS1_EE5beginEv(ptr noundef nonnull align 8 dereferenceable(24) %4) #5
  store ptr %5, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #5
  %6 = tail call ptr @_ZNSt6vectorIP5QMeshSaIS1_EE3endEv(ptr noundef nonnull align 8 dereferenceable(24) %4) #5
  store ptr %6, ptr %3, align 8
  %7 = call noundef zeroext i1 @_ZN9__gnu_cxxneIPP5QMeshSt6vectorIS2_SaIS2_EEEEbRKNS_17__normal_iteratorIT_T0_EESC_(ptr noundef nonnull align 8 dereferenceable(8) %2, ptr noundef nonnull align 8 dereferenceable(8) %3) #5
  br i1 %7, label %.lr.ph11, label %._crit_edge12

._crit_edge12:                                    ; preds = %._crit_edge, %1
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  ret void

.lr.ph11:                                         ; preds = %1, %._crit_edge
  %8 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNK9__gnu_cxx17__normal_iteratorIPP5QMeshSt6vectorIS2_SaIS2_EEEdeEv(ptr noundef nonnull align 8 dereferenceable(8) %2) #5
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  %10 = call noundef i32 @_ZN5QMesh16GetParticleCountEv(ptr noundef nonnull align 8 dereferenceable(256) %9)
  %.not = icmp eq i32 %10, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %17, %.lr.ph11
  %11 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN9__gnu_cxx17__normal_iteratorIPP5QMeshSt6vectorIS2_SaIS2_EEEppEv(ptr noundef nonnull align 8 dereferenceable(8) %2) #5
  %12 = call noundef zeroext i1 @_ZN9__gnu_cxxneIPP5QMeshSt6vectorIS2_SaIS2_EEEEbRKNS_17__normal_iteratorIT_T0_EESC_(ptr noundef nonnull align 8 dereferenceable(8) %2, ptr noundef nonnull align 8 dereferenceable(8) %3) #5
  br i1 %12, label %.lr.ph11, label %._crit_edge12

.lr.ph:                                           ; preds = %.lr.ph11, %17
  %.09 = phi i64 [ %18, %17 ], [ 0, %.lr.ph11 ]
  %13 = trunc i64 %.09 to i32
  %14 = call noundef ptr @_ZN5QMesh13GetParticleAtEi(ptr noundef nonnull align 8 dereferenceable(256) %9, i32 noundef %13)
  %15 = call noundef zeroext i1 @_ZN9QParticle9GetIsLazyEv(ptr noundef nonnull align 8 dereferenceable(290) %14)
  br i1 %15, label %16, label %17

16:                                               ; preds = %.lr.ph
  call void @_ZN9QParticle22ResetOneTimeCollisionsEv(ptr noundef nonnull align 8 dereferenceable(290) %14)
  br label %17

17:                                               ; preds = %16, %.lr.ph
  %18 = add nuw i64 %.09, 1
  %19 = call noundef i32 @_ZN5QMesh16GetParticleCountEv(ptr noundef nonnull align 8 dereferenceable(256) %9)
  %20 = sext i32 %19 to i64
  %21 = icmp ult i64 %18, %20
  br i1 %21, label %.lr.ph, label %._crit_edge, !llvm.loop !9
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN9__gnu_cxxneIPP5QMeshSt6vectorIS2_SaIS2_EEEEbRKNS_17__normal_iteratorIT_T0_EESC_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #4

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

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

declare void @_ZN9QParticle22ResetOneTimeCollisionsEv(ptr noundef nonnull align 8 dereferenceable(290)) local_unnamed_addr #2

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

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 = { inlinehint 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 #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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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