; LLVM IR from atlantis13579/Riemann :: Src/CollisionPrimitive (ConvexMesh)

; 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.Riemann::ConvexMesh" = type { ptr, ptr, ptr, ptr, i16, i16, i16, i16, %"class.std::vector", %"class.Maths::TAABB3" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<char, std::allocator<char>>::_Vector_impl" }
%"struct.std::_Vector_base<char, std::allocator<char>>::_Vector_impl" = type { %"struct.std::_Vector_base<char, std::allocator<char>>::_Vector_impl_data" }
%"struct.std::_Vector_base<char, std::allocator<char>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.Maths::TAABB3" = type { %"class.Maths::TVector3", %"class.Maths::TVector3" }
%"class.Maths::TVector3" = type { float, float, float }
%"struct.Riemann::ConvexMeshFace" = type { %"class.Riemann::Plane3", i16, i8, i8 }
%"class.Riemann::Plane3" = type { %"class.Maths::TVector3", float }

; 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZNK5Maths8TVector3IfE3DotERKS1_(ptr noundef nonnull align 4 dereferenceable(12), ptr noundef nonnull align 4 dereferenceable(12)) #1 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZNK7Riemann10ConvexMesh14GetSupportFaceERKN5Maths8TVector3IfEEPS3_(ptr noundef nonnull align 8 dereferenceable(88) %0, ptr noundef nonnull align 4 dereferenceable(12) %1, ptr noundef %2) #2 align 2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca float, align 4
  %9 = alloca i16, align 2
  %10 = alloca i16, align 2
  %11 = alloca ptr, align 8
  %12 = alloca float, align 4
  %13 = alloca ptr, align 8
  %14 = alloca i8, align 1
  %15 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  %16 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store float 0xC7EFFFFFE0000000, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2, ptr %9) #3
  store i16 -1, ptr %9, align 2, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 2, ptr %10) #3
  store i16 0, ptr %10, align 2, !tbaa !11
  br label %17

17:                                               ; preds = %43, %3
  %18 = load i16, ptr %10, align 2, !tbaa !11
  %19 = zext i16 %18 to i32
  %20 = getelementptr inbounds %"class.Riemann::ConvexMesh", ptr %16, i32 0, i32 6
  %21 = load i16, ptr %20, align 4, !tbaa !13
  %22 = zext i16 %21 to i32
  %23 = icmp slt i32 %19, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 2, ptr %10) #3
  br label %46

25:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %26 = getelementptr inbounds %"class.Riemann::ConvexMesh", ptr %16, i32 0, i32 2
  %27 = load ptr, ptr %26, align 8, !tbaa !21
  %28 = load i16, ptr %10, align 2, !tbaa !11
  %29 = zext i16 %28 to i64
  %30 = getelementptr inbounds %"struct.Riemann::ConvexMeshFace", ptr %27, i64 %29
  %31 = getelementptr inbounds %"struct.Riemann::ConvexMeshFace", ptr %30, i32 0, i32 0
  store ptr %31, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = load ptr, ptr %11, align 8, !tbaa !5
  %34 = getelementptr inbounds %"class.Riemann::Plane3", ptr %33, i32 0, i32 0
  %35 = call noundef float @_ZNK5Maths8TVector3IfE3DotERKS1_(ptr noundef nonnull align 4 dereferenceable(12) %32, ptr noundef nonnull align 4 dereferenceable(12) %34)
  store float %35, ptr %12, align 4, !tbaa !9
  %36 = load float, ptr %12, align 4, !tbaa !9
  %37 = load float, ptr %8, align 4, !tbaa !9
  %38 = fcmp ogt float %36, %37
  br i1 %38, label %39, label %42

39:                                               ; preds = %25
  %40 = load float, ptr %12, align 4, !tbaa !9
  store float %40, ptr %8, align 4, !tbaa !9
  %41 = load i16, ptr %10, align 2, !tbaa !11
  store i16 %41, ptr %9, align 2, !tbaa !11
  br label %42

42:                                               ; preds = %39, %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  br label %43

43:                                               ; preds = %42
  %44 = load i16, ptr %10, align 2, !tbaa !11
  %45 = add i16 %44, 1
  store i16 %45, ptr %10, align 2, !tbaa !11
  br label %17, !llvm.loop !22

46:                                               ; preds = %24
  %47 = load i16, ptr %9, align 2, !tbaa !11
  %48 = zext i16 %47 to i32
  %49 = icmp ne i32 %48, 65535
  br i1 %49, label %50, label %95

50:                                               ; preds = %46
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %51 = getelementptr inbounds %"class.Riemann::ConvexMesh", ptr %16, i32 0, i32 2
  %52 = load ptr, ptr %51, align 8, !tbaa !21
  %53 = load i16, ptr %9, align 2, !tbaa !11
  %54 = zext i16 %53 to i64
  %55 = getelementptr inbounds %"struct.Riemann::ConvexMeshFace", ptr %52, i64 %54
  store ptr %55, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %14) #3
  store i8 0, ptr %14, align 1, !tbaa !24
  br label %56

56:                                               ; preds = %87, %50
  %57 = load i8, ptr %14, align 1, !tbaa !24
  %58 = zext i8 %57 to i32
  %59 = load ptr, ptr %13, align 8, !tbaa !5
  %60 = getelementptr inbounds %"struct.Riemann::ConvexMeshFace", ptr %59, i32 0, i32 2
  %61 = load i8, ptr %60, align 2, !tbaa !25
  %62 = zext i8 %61 to i32
  %63 = icmp slt i32 %58, %62
  br i1 %63, label %65, label %64

64:                                               ; preds = %56
  call void @llvm.lifetime.end.p0(i64 1, ptr %14) #3
  br label %90

65:                                               ; preds = %56
  %66 = getelementptr inbounds %"class.Riemann::ConvexMesh", ptr %16, i32 0, i32 0
  %67 = load ptr, ptr %66, align 8, !tbaa !28
  %68 = getelementptr inbounds %"class.Riemann::ConvexMesh", ptr %16, i32 0, i32 3
  %69 = load ptr, ptr %68, align 8, !tbaa !29
  %70 = load ptr, ptr %13, align 8, !tbaa !5
  %71 = getelementptr inbounds %"struct.Riemann::ConvexMeshFace", ptr %70, i32 0, i32 1
  %72 = load i16, ptr %71, align 4, !tbaa !30
  %73 = zext i16 %72 to i32
  %74 = load i8, ptr %14, align 1, !tbaa !24
  %75 = zext i8 %74 to i32
  %76 = add nsw i32 %73, %75
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds i8, ptr %69, i64 %77
  %79 = load i8, ptr %78, align 1, !tbaa !24
  %80 = zext i8 %79 to i64
  %81 = getelementptr inbounds %"class.Maths::TVector3", ptr %67, i64 %80
  %82 = load ptr, ptr %7, align 8, !tbaa !5
  %83 = load i8, ptr %14, align 1, !tbaa !24
  %84 = zext i8 %83 to i64
  %85 = getelementptr inbounds %"class.Maths::TVector3", ptr %82, i64 %84
  %86 = call noundef nonnull align 4 dereferenceable(12) ptr @_ZN5Maths8TVector3IfEaSERKS1_(ptr noundef nonnull align 4 dereferenceable(12) %85, ptr noundef nonnull align 4 dereferenceable(12) %81)
  br label %87

87:                                               ; preds = %65
  %88 = load i8, ptr %14, align 1, !tbaa !24
  %89 = add i8 %88, 1
  store i8 %89, ptr %14, align 1, !tbaa !24
  br label %56, !llvm.loop !31

90:                                               ; preds = %64
  %91 = load ptr, ptr %13, align 8, !tbaa !5
  %92 = getelementptr inbounds %"struct.Riemann::ConvexMeshFace", ptr %91, i32 0, i32 2
  %93 = load i8, ptr %92, align 2, !tbaa !25
  %94 = zext i8 %93 to i32
  store i32 %94, ptr %4, align 4
  store i32 1, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  br label %96

95:                                               ; preds = %46
  store i32 0, ptr %4, align 4
  store i32 1, ptr %15, align 4
  br label %96

96:                                               ; preds = %95, %90
  call void @llvm.lifetime.end.p0(i64 2, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %97 = load i32, ptr %4, align 4
  ret i32 %97
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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 = !{!"float", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!14, !12, i64 36}
!14 = !{!"_ZTSN7Riemann10ConvexMeshE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !12, i64 32, !12, i64 34, !12, i64 36, !12, i64 38, !15, i64 40, !19, i64 64}
!15 = !{!"_ZTSSt6vectorIcSaIcEE", !16, i64 0}
!16 = !{!"_ZTSSt12_Vector_baseIcSaIcEE", !17, i64 0}
!17 = !{!"_ZTSNSt12_Vector_baseIcSaIcEE12_Vector_implE", !18, i64 0}
!18 = !{!"_ZTSNSt12_Vector_baseIcSaIcEE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!19 = !{!"_ZTSN5Maths6TAABB3IfEE", !20, i64 0, !20, i64 12}
!20 = !{!"_ZTSN5Maths8TVector3IfEE", !10, i64 0, !10, i64 4, !10, i64 8}
!21 = !{!14, !6, i64 16}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = !{!7, !7, i64 0}
!25 = !{!26, !7, i64 18}
!26 = !{!"_ZTSN7Riemann14ConvexMeshFaceE", !27, i64 0, !12, i64 16, !7, i64 18, !7, i64 19}
!27 = !{!"_ZTSN7Riemann6Plane3E", !20, i64 0, !10, i64 12}
!28 = !{!14, !6, i64 0}
!29 = !{!14, !6, i64 24}
!30 = !{!26, !12, i64 16}
!31 = distinct !{!31, !23}


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

%"struct.Riemann::ConvexMeshFace" = type { %"class.Riemann::Plane3", i16, i8, i8 }
%"class.Riemann::Plane3" = type { %"class.Maths::TVector3", float }
%"class.Maths::TVector3" = type { float, float, float }

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZNK7Riemann10ConvexMesh14GetSupportFaceERKN5Maths8TVector3IfEEPS3_(ptr nocapture noundef nonnull readonly align 8 dereferenceable(88) %0, ptr noundef nonnull align 4 dereferenceable(12) %1, ptr noundef %2) local_unnamed_addr #1 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 36
  %5 = load i16, ptr %4, align 4, !tbaa !5
  %.not36 = icmp eq i16 %5, 0
  br i1 %.not36, label %._crit_edge34, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  br label %7

._crit_edge:                                      ; preds = %7
  %.not = icmp eq i16 %.123, -1
  br i1 %.not, label %._crit_edge34, label %16

7:                                                ; preds = %.lr.ph, %7
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %7 ]
  %.02130 = phi float [ 0xC7EFFFFFE0000000, %.lr.ph ], [ %.1, %7 ]
  %.02229 = phi i16 [ -1, %.lr.ph ], [ %.123, %7 ]
  %8 = load ptr, ptr %6, align 8, !tbaa !18
  %9 = getelementptr inbounds %"struct.Riemann::ConvexMeshFace", ptr %8, i64 %indvars.iv
  %10 = tail call noundef float @_ZNK5Maths8TVector3IfE3DotERKS1_(ptr noundef nonnull align 4 dereferenceable(12) %1, ptr noundef nonnull align 4 dereferenceable(12) %9)
  %11 = fcmp ogt float %10, %.02130
  %12 = trunc nuw i64 %indvars.iv to i16
  %.123 = select i1 %11, i16 %12, i16 %.02229
  %.1 = select i1 %11, float %10, float %.02130
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %13 = load i16, ptr %4, align 4, !tbaa !5
  %14 = zext i16 %13 to i64
  %15 = icmp ult i64 %indvars.iv.next, %14
  br i1 %15, label %7, label %._crit_edge, !llvm.loop !19

16:                                               ; preds = %._crit_edge
  %17 = getelementptr inbounds i8, ptr %0, i64 16
  %18 = load ptr, ptr %17, align 8, !tbaa !18
  %19 = zext i16 %.123 to i64
  %20 = getelementptr inbounds %"struct.Riemann::ConvexMeshFace", ptr %18, i64 %19
  %21 = getelementptr inbounds i8, ptr %20, i64 18
  %22 = load i8, ptr %21, align 2, !tbaa !21
  %.not37 = icmp eq i8 %22, 0
  br i1 %.not37, label %._crit_edge34, label %.lr.ph33

.lr.ph33:                                         ; preds = %16
  %23 = getelementptr inbounds i8, ptr %0, i64 24
  %24 = getelementptr inbounds i8, ptr %20, i64 16
  br label %26

._crit_edge34.loopexit:                           ; preds = %26
  %25 = zext i8 %38 to i32
  br label %._crit_edge34

26:                                               ; preds = %.lr.ph33, %26
  %indvars.iv40 = phi i64 [ 0, %.lr.ph33 ], [ %indvars.iv.next41, %26 ]
  %27 = load ptr, ptr %0, align 8, !tbaa !24
  %28 = load ptr, ptr %23, align 8, !tbaa !25
  %29 = load i16, ptr %24, align 4, !tbaa !26
  %30 = zext i16 %29 to i64
  %31 = getelementptr inbounds i8, ptr %28, i64 %30
  %32 = getelementptr inbounds i8, ptr %31, i64 %indvars.iv40
  %33 = load i8, ptr %32, align 1, !tbaa !27
  %34 = zext i8 %33 to i64
  %35 = getelementptr inbounds %"class.Maths::TVector3", ptr %27, i64 %34
  %36 = getelementptr inbounds %"class.Maths::TVector3", ptr %2, i64 %indvars.iv40
  %37 = tail call noundef nonnull align 4 dereferenceable(12) ptr @_ZN5Maths8TVector3IfEaSERKS1_(ptr noundef nonnull align 4 dereferenceable(12) %36, ptr noundef nonnull align 4 dereferenceable(12) %35)
  %indvars.iv.next41 = add nuw nsw i64 %indvars.iv40, 1
  %38 = load i8, ptr %21, align 2, !tbaa !21
  %39 = zext i8 %38 to i64
  %40 = icmp ult i64 %indvars.iv.next41, %39
  br i1 %40, label %26, label %._crit_edge34.loopexit, !llvm.loop !28

._crit_edge34:                                    ; preds = %3, %16, %._crit_edge34.loopexit, %._crit_edge
  %.020 = phi i32 [ 0, %._crit_edge ], [ 0, %16 ], [ %25, %._crit_edge34.loopexit ], [ 0, %3 ]
  ret i32 %.020
}

attributes #0 = { 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 #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" }

!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, !10, i64 36}
!6 = !{!"_ZTSN7Riemann10ConvexMeshE", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !10, i64 34, !10, i64 36, !10, i64 38, !11, i64 40, !15, i64 64}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!"_ZTSSt6vectorIcSaIcEE", !12, i64 0}
!12 = !{!"_ZTSSt12_Vector_baseIcSaIcEE", !13, i64 0}
!13 = !{!"_ZTSNSt12_Vector_baseIcSaIcEE12_Vector_implE", !14, i64 0}
!14 = !{!"_ZTSNSt12_Vector_baseIcSaIcEE17_Vector_impl_dataE", !7, i64 0, !7, i64 8, !7, i64 16}
!15 = !{!"_ZTSN5Maths6TAABB3IfEE", !16, i64 0, !16, i64 12}
!16 = !{!"_ZTSN5Maths8TVector3IfEE", !17, i64 0, !17, i64 4, !17, i64 8}
!17 = !{!"float", !8, i64 0}
!18 = !{!6, !7, i64 16}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!22, !8, i64 18}
!22 = !{!"_ZTSN7Riemann14ConvexMeshFaceE", !23, i64 0, !10, i64 16, !8, i64 18, !8, i64 19}
!23 = !{!"_ZTSN7Riemann6Plane3E", !16, i64 0, !17, i64 12}
!24 = !{!6, !7, i64 0}
!25 = !{!6, !7, i64 24}
!26 = !{!22, !10, i64 16}
!27 = !{!8, !8, i64 0}
!28 = distinct !{!28, !20}


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