; LLVM IR from erayzesen/QuarkPhysics :: QuarkPhysics/qmanifold.ll (ZN9QManifoldC2EP5QBodyS1_)

; 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.QManifold = type { %struct.QVector, float, float, i8, ptr, ptr, %"class.std::vector" }
%struct.QVector = type { float, float }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<QCollision::Contact *, std::allocator<QCollision::Contact *>>::_Vector_impl" }
%"struct.std::_Vector_base<QCollision::Contact *, std::allocator<QCollision::Contact *>>::_Vector_impl" = type { %"struct.std::_Vector_base<QCollision::Contact *, std::allocator<QCollision::Contact *>>::_Vector_impl_data" }
%"struct.std::_Vector_base<QCollision::Contact *, std::allocator<QCollision::Contact *>>::_Vector_impl_data" = type { ptr, ptr, 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.2", 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.0" = type { %"class.std::_Function_base", ptr }
%"class.std::vector.2" = type { %"struct.std::_Vector_base.3" }
%"struct.std::_Vector_base.3" = 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: mustprogress uwtable
define dso_local void @_ZN9QManifoldC2EP5QBodyS1_(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr noundef %1, ptr noundef %2) unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8
  %10 = getelementptr inbounds %class.QManifold, ptr %9, i32 0, i32 0
  %11 = call <2 x float> @_ZN7QVector4ZeroEv()
  store <2 x float> %11, ptr %10, align 8
  %12 = getelementptr inbounds %class.QManifold, ptr %9, i32 0, i32 1
  store float 0.000000e+00, ptr %12, align 8, !tbaa !9
  %13 = getelementptr inbounds %class.QManifold, ptr %9, i32 0, i32 3
  store i8 0, ptr %13, align 8, !tbaa !18
  %14 = getelementptr inbounds %class.QManifold, ptr %9, i32 0, i32 6
  call void @_ZNSt6vectorIPN10QCollision7ContactESaIS2_EEC2Ev(ptr noundef nonnull align 8 dereferenceable(24) %14) #3
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = icmp ult ptr %15, %16
  br i1 %17, label %18, label %23

18:                                               ; preds = %3
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %class.QManifold, ptr %9, i32 0, i32 4
  store ptr %19, ptr %20, align 8, !tbaa !19
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %class.QManifold, ptr %9, i32 0, i32 5
  store ptr %21, ptr %22, align 8, !tbaa !20
  br label %28

23:                                               ; preds = %3
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %class.QManifold, ptr %9, i32 0, i32 4
  store ptr %24, ptr %25, align 8, !tbaa !19
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %class.QManifold, ptr %9, i32 0, i32 5
  store ptr %26, ptr %27, align 8, !tbaa !20
  br label %28

28:                                               ; preds = %23, %18
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %class.QBody, ptr %29, i32 0, i32 27
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = getelementptr inbounds %class.QBody, ptr %31, i32 0, i32 27
  %33 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIfERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %30, ptr noundef nonnull align 4 dereferenceable(4) %32)
          to label %34 unwind label %73

34:                                               ; preds = %28
  %35 = load float, ptr %33, align 4, !tbaa !21
  %36 = getelementptr inbounds %class.QManifold, ptr %9, i32 0, i32 1
  store float %35, ptr %36, align 8, !tbaa !9
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = load ptr, ptr %37, align 8, !tbaa !22
  %39 = getelementptr inbounds ptr, ptr %38, i64 8
  %40 = load ptr, ptr %39, align 8
  %41 = invoke noundef float %40(ptr noundef nonnull align 8 dereferenceable(293) %37)
          to label %42 unwind label %73

42:                                               ; preds = %34
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = load ptr, ptr %43, align 8, !tbaa !22
  %45 = getelementptr inbounds ptr, ptr %44, i64 8
  %46 = load ptr, ptr %45, align 8
  %47 = invoke noundef float %46(ptr noundef nonnull align 8 dereferenceable(293) %43)
          to label %48 unwind label %73

48:                                               ; preds = %42
  %49 = fadd float %41, %47
  %50 = fdiv float 1.000000e+00, %49
  %51 = getelementptr inbounds %class.QManifold, ptr %9, i32 0, i32 2
  store float %50, ptr %51, align 4, !tbaa !24
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = load ptr, ptr %52, align 8, !tbaa !22
  %55 = getelementptr inbounds ptr, ptr %54, i64 2
  %56 = load ptr, ptr %55, align 8
  %57 = invoke noundef zeroext i1 %56(ptr noundef nonnull align 8 dereferenceable(293) %52, ptr noundef %53)
          to label %58 unwind label %73

58:                                               ; preds = %48
  %59 = zext i1 %57 to i32
  %60 = icmp eq i32 %59, 0
  br i1 %60, label %71, label %61

61:                                               ; preds = %58
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = load ptr, ptr %62, align 8, !tbaa !22
  %65 = getelementptr inbounds ptr, ptr %64, i64 2
  %66 = load ptr, ptr %65, align 8
  %67 = invoke noundef zeroext i1 %66(ptr noundef nonnull align 8 dereferenceable(293) %62, ptr noundef %63)
          to label %68 unwind label %73

68:                                               ; preds = %61
  %69 = zext i1 %67 to i32
  %70 = icmp eq i32 %69, 0
  br i1 %70, label %71, label %77

71:                                               ; preds = %68, %58
  %72 = getelementptr inbounds %class.QManifold, ptr %9, i32 0, i32 3
  store i8 1, ptr %72, align 8, !tbaa !18
  br label %77

73:                                               ; preds = %61, %48, %42, %34, %28
  %74 = landingpad { ptr, i32 }
          cleanup
  %75 = extractvalue { ptr, i32 } %74, 0
  store ptr %75, ptr %7, align 8
  %76 = extractvalue { ptr, i32 } %74, 1
  store i32 %76, ptr %8, align 4
  call void @_ZNSt6vectorIPN10QCollision7ContactESaIS2_EED2Ev(ptr noundef nonnull align 8 dereferenceable(24) %14) #3
  br label %78

77:                                               ; preds = %71, %68
  ret void

78:                                               ; preds = %73
  %79 = load ptr, ptr %7, align 8
  %80 = load i32, ptr %8, align 4
  %81 = insertvalue { ptr, i32 } poison, ptr %79, 0
  %82 = insertvalue { ptr, i32 } %81, i32 %80, 1
  resume { ptr, i32 } %82
}

; Function Attrs: mustprogress uwtable
declare dso_local <2 x float> @_ZN7QVector4ZeroEv() #0 align 2

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIfERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6vectorIPN10QCollision7ContactESaIS2_EED2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #1 align 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 = { 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 #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 = !{!10, !12, i64 8}
!10 = !{!"_ZTS9QManifold", !11, i64 0, !12, i64 8, !12, i64 12, !13, i64 16, !6, i64 24, !6, i64 32, !14, i64 40}
!11 = !{!"_ZTS7QVector", !12, i64 0, !12, i64 4}
!12 = !{!"float", !7, i64 0}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"_ZTSSt6vectorIPN10QCollision7ContactESaIS2_EE", !15, i64 0}
!15 = !{!"_ZTSSt12_Vector_baseIPN10QCollision7ContactESaIS2_EE", !16, i64 0}
!16 = !{!"_ZTSNSt12_Vector_baseIPN10QCollision7ContactESaIS2_EE12_Vector_implE", !17, i64 0}
!17 = !{!"_ZTSNSt12_Vector_baseIPN10QCollision7ContactESaIS2_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!18 = !{!10, !13, i64 16}
!19 = !{!10, !6, i64 24}
!20 = !{!10, !6, i64 32}
!21 = !{!12, !12, i64 0}
!22 = !{!23, !23, i64 0}
!23 = !{!"vtable pointer", !8, i64 0}
!24 = !{!10, !12, i64 12}


; 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 void @_ZN9QManifoldC2EP5QBodyS1_(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr noundef %1, ptr noundef %2) unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %4 = tail call <2 x float> @_ZN7QVector4ZeroEv()
  store <2 x float> %4, ptr %0, align 8
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  store float 0.000000e+00, ptr %5, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  store i8 0, ptr %6, align 8, !tbaa !17
  %7 = getelementptr inbounds i8, ptr %0, i64 40
  tail call void @_ZNSt6vectorIPN10QCollision7ContactESaIS2_EEC2Ev(ptr noundef nonnull align 8 dereferenceable(24) %7) #3
  %8 = icmp ult ptr %1, %2
  %spec.select = select i1 %8, ptr %1, ptr %2
  %spec.select19 = select i1 %8, ptr %2, ptr %1
  %9 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr %spec.select, ptr %9, align 8
  %10 = getelementptr inbounds i8, ptr %0, i64 32
  store ptr %spec.select19, ptr %10, align 8
  %11 = getelementptr inbounds i8, ptr %1, i64 128
  %12 = getelementptr inbounds i8, ptr %2, i64 128
  %13 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIfERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %11, ptr noundef nonnull align 4 dereferenceable(4) %12)
  %14 = load float, ptr %13, align 4, !tbaa !18
  store float %14, ptr %5, align 8, !tbaa !5
  %15 = load ptr, ptr %1, align 8, !tbaa !19
  %16 = getelementptr inbounds i8, ptr %15, i64 64
  %17 = load ptr, ptr %16, align 8
  %18 = invoke noundef float %17(ptr noundef nonnull align 8 dereferenceable(293) %1)
          to label %19 unwind label %40

19:                                               ; preds = %3
  %20 = load ptr, ptr %2, align 8, !tbaa !19
  %21 = getelementptr inbounds i8, ptr %20, i64 64
  %22 = load ptr, ptr %21, align 8
  %23 = invoke noundef float %22(ptr noundef nonnull align 8 dereferenceable(293) %2)
          to label %24 unwind label %40

24:                                               ; preds = %19
  %25 = fadd float %18, %23
  %26 = fdiv float 1.000000e+00, %25
  %27 = getelementptr inbounds i8, ptr %0, i64 12
  store float %26, ptr %27, align 4, !tbaa !21
  %28 = load ptr, ptr %1, align 8, !tbaa !19
  %29 = getelementptr inbounds i8, ptr %28, i64 16
  %30 = load ptr, ptr %29, align 8
  %31 = invoke noundef zeroext i1 %30(ptr noundef nonnull align 8 dereferenceable(293) %1, ptr noundef nonnull %2)
          to label %32 unwind label %40

32:                                               ; preds = %24
  br i1 %31, label %33, label %39

33:                                               ; preds = %32
  %34 = load ptr, ptr %2, align 8, !tbaa !19
  %35 = getelementptr inbounds i8, ptr %34, i64 16
  %36 = load ptr, ptr %35, align 8
  %37 = invoke noundef zeroext i1 %36(ptr noundef nonnull align 8 dereferenceable(293) %2, ptr noundef nonnull %1)
          to label %38 unwind label %40

38:                                               ; preds = %33
  br i1 %37, label %42, label %39

39:                                               ; preds = %38, %32
  store i8 1, ptr %6, align 8, !tbaa !17
  br label %42

40:                                               ; preds = %33, %24, %19, %3
  %41 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZNSt6vectorIPN10QCollision7ContactESaIS2_EED2Ev(ptr noundef nonnull align 8 dereferenceable(24) %7) #3
  resume { ptr, i32 } %41

42:                                               ; preds = %39, %38
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local <2 x float> @_ZN7QVector4ZeroEv() local_unnamed_addr #0 align 2

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIfERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6vectorIPN10QCollision7ContactESaIS2_EED2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #1 align 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 = { 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 #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, !8, i64 8}
!6 = !{!"_ZTS9QManifold", !7, i64 0, !8, i64 8, !8, i64 12, !11, i64 16, !12, i64 24, !12, i64 32, !13, i64 40}
!7 = !{!"_ZTS7QVector", !8, i64 0, !8, i64 4}
!8 = !{!"float", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"bool", !9, i64 0}
!12 = !{!"any pointer", !9, i64 0}
!13 = !{!"_ZTSSt6vectorIPN10QCollision7ContactESaIS2_EE", !14, i64 0}
!14 = !{!"_ZTSSt12_Vector_baseIPN10QCollision7ContactESaIS2_EE", !15, i64 0}
!15 = !{!"_ZTSNSt12_Vector_baseIPN10QCollision7ContactESaIS2_EE12_Vector_implE", !16, i64 0}
!16 = !{!"_ZTSNSt12_Vector_baseIPN10QCollision7ContactESaIS2_EE17_Vector_impl_dataE", !12, i64 0, !12, i64 8, !12, i64 16}
!17 = !{!6, !11, i64 16}
!18 = !{!8, !8, i64 0}
!19 = !{!20, !20, i64 0}
!20 = !{!"vtable pointer", !10, i64 0}
!21 = !{!6, !8, i64 12}


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