; LLVM IR from zig-gamedev/zphysics :: libs/Jolt/Physics/Collision/Shape (TriangleShape)

; 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.JPH::Vec3" = type { %union.anon.3 }
%union.anon.3 = type { <4 x float> }
%"class.JPH::CollideSoftBodyVerticesVsTriangles" = type <{ %"class.JPH::Mat44", %"class.JPH::Mat44", %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Vec3", float, float, i32, [4 x i8] }>
%"class.JPH::Mat44" = type { [4 x %"class.JPH::Vec4"] }
%"class.JPH::Vec4" = type { %union.anon.5 }
%union.anon.5 = type { <4 x float> }
%"class.JPH::SoftBodyVertex" = type { %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Plane", i32, i8, float, float }
%"class.JPH::Plane" = type { %"class.JPH::Vec4" }
%"class.JPH::TriangleShape" = type <{ %"class.JPH::ConvexShape.base", [4 x i8], %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Vec3", float, [12 x i8] }>
%"class.JPH::ConvexShape.base" = type <{ %"class.JPH::Shape.base", [6 x i8], %"class.JPH::RefConst", float }>
%"class.JPH::Shape.base" = type <{ ptr, %"class.JPH::RefTarget.4", [4 x i8], i64, i8, i8 }>
%"class.JPH::RefTarget.4" = type { %"struct.std::atomic" }
%"struct.std::atomic" = type { %"struct.std::__atomic_base" }
%"struct.std::__atomic_base" = type { i32 }
%"class.JPH::RefConst" = 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

; 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 void @_ZNK3JPH13TriangleShape23CollideSoftBodyVerticesERKNS_5Mat44ENS_4Vec3EPNS_14SoftBodyVertexEjfS4_i(ptr noundef nonnull align 16 dereferenceable(112) %0, ptr noundef nonnull align 16 dereferenceable(64) %1, double %2, double %3, ptr noundef %4, i32 noundef %5, float noundef %6, double %7, double %8, i32 noundef %9) unnamed_addr #2 align 2 {
  %11 = alloca %"class.JPH::Vec3", align 16
  %12 = alloca %"class.JPH::Vec3", align 16
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i32, align 4
  %17 = alloca float, align 4
  %18 = alloca i32, align 4
  %19 = alloca %"class.JPH::CollideSoftBodyVerticesVsTriangles", align 16
  %20 = alloca %"class.JPH::Vec3", align 16
  %21 = alloca ptr, align 8
  %22 = alloca ptr, align 8
  %23 = alloca %"class.JPH::Vec3", align 16
  %24 = alloca %"class.JPH::Vec3", align 16
  %25 = alloca %"class.JPH::Vec3", align 16
  %26 = getelementptr inbounds { double, double }, ptr %11, i32 0, i32 0
  store double %2, ptr %26, align 16
  %27 = getelementptr inbounds { double, double }, ptr %11, i32 0, i32 1
  store double %3, ptr %27, align 8
  %28 = getelementptr inbounds { double, double }, ptr %12, i32 0, i32 0
  store double %7, ptr %28, align 16
  %29 = getelementptr inbounds { double, double }, ptr %12, i32 0, i32 1
  store double %8, ptr %29, align 8
  store ptr %0, ptr %13, align 8, !tbaa !5
  store ptr %1, ptr %14, align 8, !tbaa !5
  store ptr %4, ptr %15, align 8, !tbaa !5
  store i32 %5, ptr %16, align 4, !tbaa !9
  store float %6, ptr %17, align 4, !tbaa !11
  store i32 %9, ptr %18, align 4, !tbaa !9
  %30 = load ptr, ptr %13, align 8
  call void @llvm.lifetime.start.p0(i64 224, ptr %19) #4
  %31 = load ptr, ptr %14, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %20, ptr align 16 %11, i64 16, i1 false), !tbaa.struct !13
  %32 = getelementptr inbounds { double, double }, ptr %20, i32 0, i32 0
  %33 = load double, ptr %32, align 16
  %34 = getelementptr inbounds { double, double }, ptr %20, i32 0, i32 1
  %35 = load double, ptr %34, align 8
  call void @_ZN3JPH34CollideSoftBodyVerticesVsTrianglesC2ERKNS_5Mat44ENS_4Vec3E(ptr noundef nonnull align 16 dereferenceable(220) %19, ptr noundef nonnull align 16 dereferenceable(64) %31, double %33, double %35)
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #4
  %36 = load ptr, ptr %15, align 8, !tbaa !5
  store ptr %36, ptr %21, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #4
  %37 = load ptr, ptr %15, align 8, !tbaa !5
  %38 = load i32, ptr %16, align 4, !tbaa !9
  %39 = zext i32 %38 to i64
  %40 = getelementptr inbounds %"class.JPH::SoftBodyVertex", ptr %37, i64 %39
  store ptr %40, ptr %22, align 8, !tbaa !5
  br label %41

41:                                               ; preds = %71, %10
  %42 = load ptr, ptr %21, align 8, !tbaa !5
  %43 = load ptr, ptr %22, align 8, !tbaa !5
  %44 = icmp ult ptr %42, %43
  br i1 %44, label %46, label %45

45:                                               ; preds = %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #4
  br label %74

46:                                               ; preds = %41
  %47 = load ptr, ptr %21, align 8, !tbaa !5
  %48 = getelementptr inbounds %"class.JPH::SoftBodyVertex", ptr %47, i32 0, i32 7
  %49 = load float, ptr %48, align 4, !tbaa !15
  %50 = fcmp ogt float %49, 0.000000e+00
  br i1 %50, label %51, label %70

51:                                               ; preds = %46
  %52 = load ptr, ptr %21, align 8, !tbaa !5
  call void @_ZN3JPH34CollideSoftBodyVerticesVsTriangles11StartVertexERKNS_14SoftBodyVertexE(ptr noundef nonnull align 16 dereferenceable(220) %19, ptr noundef nonnull align 16 dereferenceable(80) %52)
  %53 = getelementptr inbounds %"class.JPH::TriangleShape", ptr %30, i32 0, i32 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %23, ptr align 16 %53, i64 16, i1 false), !tbaa.struct !13
  %54 = getelementptr inbounds %"class.JPH::TriangleShape", ptr %30, i32 0, i32 3
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %24, ptr align 16 %54, i64 16, i1 false), !tbaa.struct !13
  %55 = getelementptr inbounds %"class.JPH::TriangleShape", ptr %30, i32 0, i32 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %25, ptr align 16 %55, i64 16, i1 false), !tbaa.struct !13
  %56 = getelementptr inbounds { double, double }, ptr %23, i32 0, i32 0
  %57 = load double, ptr %56, align 16
  %58 = getelementptr inbounds { double, double }, ptr %23, i32 0, i32 1
  %59 = load double, ptr %58, align 8
  %60 = getelementptr inbounds { double, double }, ptr %24, i32 0, i32 0
  %61 = load double, ptr %60, align 16
  %62 = getelementptr inbounds { double, double }, ptr %24, i32 0, i32 1
  %63 = load double, ptr %62, align 8
  %64 = getelementptr inbounds { double, double }, ptr %25, i32 0, i32 0
  %65 = load double, ptr %64, align 16
  %66 = getelementptr inbounds { double, double }, ptr %25, i32 0, i32 1
  %67 = load double, ptr %66, align 8
  call void @_ZN3JPH34CollideSoftBodyVerticesVsTriangles15ProcessTriangleENS_4Vec3ES1_S1_(ptr noundef nonnull align 16 dereferenceable(220) %19, double %57, double %59, double %61, double %63, double %65, double %67)
  %68 = load ptr, ptr %21, align 8, !tbaa !5
  %69 = load i32, ptr %18, align 4, !tbaa !9
  call void @_ZNK3JPH34CollideSoftBodyVerticesVsTriangles12FinishVertexERNS_14SoftBodyVertexEi(ptr noundef nonnull align 16 dereferenceable(220) %19, ptr noundef nonnull align 16 dereferenceable(80) %68, i32 noundef %69)
  br label %70

70:                                               ; preds = %51, %46
  br label %71

71:                                               ; preds = %70
  %72 = load ptr, ptr %21, align 8, !tbaa !5
  %73 = getelementptr inbounds %"class.JPH::SoftBodyVertex", ptr %72, i32 1
  store ptr %73, ptr %21, align 8, !tbaa !5
  br label %41, !llvm.loop !21

74:                                               ; preds = %45
  call void @llvm.lifetime.end.p0(i64 224, ptr %19) #4
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3JPH34CollideSoftBodyVerticesVsTrianglesC2ERKNS_5Mat44ENS_4Vec3E(ptr noundef nonnull align 16 dereferenceable(220), ptr noundef nonnull align 16 dereferenceable(64), double, double) unnamed_addr #2 align 2

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local void @_ZN3JPH34CollideSoftBodyVerticesVsTriangles11StartVertexERKNS_14SoftBodyVertexE(ptr noundef nonnull align 16 dereferenceable(220), ptr noundef nonnull align 16 dereferenceable(80)) #3 align 2

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local void @_ZN3JPH34CollideSoftBodyVerticesVsTriangles15ProcessTriangleENS_4Vec3ES1_S1_(ptr noundef nonnull align 16 dereferenceable(220), double, double, double, double, double, double) #3 align 2

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local void @_ZNK3JPH34CollideSoftBodyVerticesVsTriangles12FinishVertexERNS_14SoftBodyVertexEi(ptr noundef nonnull align 16 dereferenceable(220), ptr noundef nonnull align 16 dereferenceable(80), i32 noundef) #3 align 2

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"="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 = { alwaysinline 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 = { 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 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{i64 0, i64 16, !14}
!14 = !{!7, !7, i64 0}
!15 = !{!16, !12, i64 76}
!16 = !{!"_ZTSN3JPH14SoftBodyVertexE", !17, i64 0, !17, i64 16, !17, i64 32, !18, i64 48, !10, i64 64, !20, i64 68, !12, i64 72, !12, i64 76}
!17 = !{!"_ZTSN3JPH4Vec3E", !7, i64 0}
!18 = !{!"_ZTSN3JPH5PlaneE", !19, i64 0}
!19 = !{!"_ZTSN3JPH4Vec4E", !7, i64 0}
!20 = !{!"bool", !7, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"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.JPH::CollideSoftBodyVerticesVsTriangles" = type <{ %"class.JPH::Mat44", %"class.JPH::Mat44", %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Vec3", float, float, i32, [4 x i8] }>
%"class.JPH::Mat44" = type { [4 x %"class.JPH::Vec4"] }
%"class.JPH::Vec4" = type { %union.anon.5 }
%union.anon.5 = type { <4 x float> }
%"class.JPH::Vec3" = type { %union.anon.3 }
%union.anon.3 = type { <4 x float> }
%"class.JPH::SoftBodyVertex" = type { %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Plane", i32, i8, float, float }
%"class.JPH::Plane" = type { %"class.JPH::Vec4" }

; 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 uwtable
define dso_local void @_ZNK3JPH13TriangleShape23CollideSoftBodyVerticesERKNS_5Mat44ENS_4Vec3EPNS_14SoftBodyVertexEjfS4_i(ptr nocapture noundef nonnull readonly align 16 dereferenceable(112) %0, ptr noundef nonnull align 16 dereferenceable(64) %1, double %2, double %3, ptr noundef %4, i32 noundef %5, float noundef %6, double %7, double %8, i32 noundef %9) unnamed_addr #1 align 2 {
  %11 = alloca %"class.JPH::CollideSoftBodyVerticesVsTriangles", align 16
  call void @llvm.lifetime.start.p0(i64 224, ptr nonnull %11) #3
  call void @_ZN3JPH34CollideSoftBodyVerticesVsTrianglesC2ERKNS_5Mat44ENS_4Vec3E(ptr noundef nonnull align 16 dereferenceable(220) %11, ptr noundef nonnull align 16 dereferenceable(64) %1, double %2, double %3)
  %12 = zext i32 %5 to i64
  %13 = getelementptr inbounds %"class.JPH::SoftBodyVertex", ptr %4, i64 %12
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %10
  %14 = getelementptr inbounds i8, ptr %0, i64 48
  %.sroa.24.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 56
  %15 = getelementptr inbounds i8, ptr %0, i64 64
  %.sroa.22.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 72
  %16 = getelementptr inbounds i8, ptr %0, i64 80
  %.sroa.2.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 88
  br label %17

._crit_edge:                                      ; preds = %22, %10
  call void @llvm.lifetime.end.p0(i64 224, ptr nonnull %11) #3
  ret void

17:                                               ; preds = %.lr.ph, %22
  %.020 = phi ptr [ %4, %.lr.ph ], [ %23, %22 ]
  %18 = getelementptr inbounds i8, ptr %.020, i64 76
  %19 = load float, ptr %18, align 4, !tbaa !5
  %20 = fcmp ogt float %19, 0.000000e+00
  br i1 %20, label %21, label %22

21:                                               ; preds = %17
  call void @_ZN3JPH34CollideSoftBodyVerticesVsTriangles11StartVertexERKNS_14SoftBodyVertexE(ptr noundef nonnull align 16 dereferenceable(220) %11, ptr noundef nonnull align 16 dereferenceable(80) %.020)
  %.sroa.03.0.copyload = load double, ptr %14, align 16
  %.sroa.24.0.copyload = load double, ptr %.sroa.24.0..sroa_idx, align 8, !tbaa !15
  %.sroa.01.0.copyload = load double, ptr %15, align 16
  %.sroa.22.0.copyload = load double, ptr %.sroa.22.0..sroa_idx, align 8, !tbaa !15
  %.sroa.0.0.copyload = load double, ptr %16, align 16
  %.sroa.2.0.copyload = load double, ptr %.sroa.2.0..sroa_idx, align 8, !tbaa !15
  call void @_ZN3JPH34CollideSoftBodyVerticesVsTriangles15ProcessTriangleENS_4Vec3ES1_S1_(ptr noundef nonnull align 16 dereferenceable(220) %11, double %.sroa.03.0.copyload, double %.sroa.24.0.copyload, double %.sroa.01.0.copyload, double %.sroa.22.0.copyload, double %.sroa.0.0.copyload, double %.sroa.2.0.copyload)
  call void @_ZNK3JPH34CollideSoftBodyVerticesVsTriangles12FinishVertexERNS_14SoftBodyVertexEi(ptr noundef nonnull align 16 dereferenceable(220) %11, ptr noundef nonnull align 16 dereferenceable(80) %.020, i32 noundef %9)
  br label %22

22:                                               ; preds = %17, %21
  %23 = getelementptr inbounds i8, ptr %.020, i64 80
  %24 = icmp ult ptr %23, %13
  br i1 %24, label %17, label %._crit_edge, !llvm.loop !16
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3JPH34CollideSoftBodyVerticesVsTrianglesC2ERKNS_5Mat44ENS_4Vec3E(ptr noundef nonnull align 16 dereferenceable(220), ptr noundef nonnull align 16 dereferenceable(64), double, double) unnamed_addr #1 align 2

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local void @_ZN3JPH34CollideSoftBodyVerticesVsTriangles11StartVertexERKNS_14SoftBodyVertexE(ptr noundef nonnull align 16 dereferenceable(220), ptr noundef nonnull align 16 dereferenceable(80)) local_unnamed_addr #2 align 2

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local void @_ZN3JPH34CollideSoftBodyVerticesVsTriangles15ProcessTriangleENS_4Vec3ES1_S1_(ptr noundef nonnull align 16 dereferenceable(220), double, double, double, double, double, double) local_unnamed_addr #2 align 2

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local void @_ZNK3JPH34CollideSoftBodyVerticesVsTriangles12FinishVertexERNS_14SoftBodyVertexEi(ptr noundef nonnull align 16 dereferenceable(220), ptr noundef nonnull align 16 dereferenceable(80), i32 noundef) local_unnamed_addr #2 align 2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { alwaysinline 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, !14, i64 76}
!6 = !{!"_ZTSN3JPH14SoftBodyVertexE", !7, i64 0, !7, i64 16, !7, i64 32, !10, i64 48, !12, i64 64, !13, i64 68, !14, i64 72, !14, i64 76}
!7 = !{!"_ZTSN3JPH4Vec3E", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSN3JPH5PlaneE", !11, i64 0}
!11 = !{!"_ZTSN3JPH4Vec4E", !8, i64 0}
!12 = !{!"int", !8, i64 0}
!13 = !{!"bool", !8, i64 0}
!14 = !{!"float", !8, i64 0}
!15 = !{!8, !8, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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