; LLVM IR from jrouwe/JoltPhysics :: 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> }
%"struct.JPH::RayCastT" = type { %"class.JPH::Vec3", %"class.JPH::Vec3" }
%"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 }
%"class.JPH::BroadPhaseCastResult" = type { %"class.JPH::BodyID", float }
%"class.JPH::BodyID" = type { i32 }
%"class.JPH::RayCastResult" = type { %"class.JPH::BroadPhaseCastResult", %"class.JPH::SubShapeID" }
%"class.JPH::SubShapeID" = type { i32 }

; 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 zeroext i1 @_ZNK3JPH13TriangleShape7CastRayERKNS_7RayCastERKNS_17SubShapeIDCreatorERNS_13RayCastResultE(ptr noundef nonnull align 16 dereferenceable(112) %0, ptr noundef nonnull align 16 dereferenceable(32) %1, ptr noundef nonnull align 4 dereferenceable(8) %2, ptr noundef nonnull align 4 dereferenceable(12) %3) unnamed_addr #2 align 2 {
  %5 = alloca i1, align 1
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca float, align 4
  %11 = alloca %"class.JPH::Vec3", align 16
  %12 = alloca %"class.JPH::Vec3", align 16
  %13 = alloca %"class.JPH::Vec3", align 16
  %14 = alloca %"class.JPH::Vec3", align 16
  %15 = alloca %"class.JPH::Vec3", align 16
  %16 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  %17 = load ptr, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = getelementptr inbounds %"struct.JPH::RayCastT", ptr %18, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %11, ptr align 16 %19, i64 16, i1 false), !tbaa.struct !9
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = getelementptr inbounds %"struct.JPH::RayCastT", ptr %20, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %12, ptr align 16 %21, i64 16, i1 false), !tbaa.struct !9
  %22 = getelementptr inbounds %"class.JPH::TriangleShape", ptr %17, i32 0, i32 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %13, ptr align 16 %22, i64 16, i1 false), !tbaa.struct !9
  %23 = getelementptr inbounds %"class.JPH::TriangleShape", ptr %17, i32 0, i32 3
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %14, ptr align 16 %23, i64 16, i1 false), !tbaa.struct !9
  %24 = getelementptr inbounds %"class.JPH::TriangleShape", ptr %17, i32 0, i32 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %15, ptr align 16 %24, i64 16, i1 false), !tbaa.struct !9
  %25 = getelementptr inbounds { double, double }, ptr %11, i32 0, i32 0
  %26 = load double, ptr %25, align 16
  %27 = getelementptr inbounds { double, double }, ptr %11, i32 0, i32 1
  %28 = load double, ptr %27, align 8
  %29 = getelementptr inbounds { double, double }, ptr %12, i32 0, i32 0
  %30 = load double, ptr %29, align 16
  %31 = getelementptr inbounds { double, double }, ptr %12, i32 0, i32 1
  %32 = load double, ptr %31, align 8
  %33 = getelementptr inbounds { double, double }, ptr %13, i32 0, i32 0
  %34 = load double, ptr %33, align 16
  %35 = getelementptr inbounds { double, double }, ptr %13, i32 0, i32 1
  %36 = load double, ptr %35, align 8
  %37 = getelementptr inbounds { double, double }, ptr %14, i32 0, i32 0
  %38 = load double, ptr %37, align 16
  %39 = getelementptr inbounds { double, double }, ptr %14, i32 0, i32 1
  %40 = load double, ptr %39, align 8
  %41 = call noundef float @_ZN3JPH11RayTriangleENS_4Vec3ES0_S0_S0_S0_(double %26, double %28, double %30, double %32, double %34, double %36, double %38, double %40, ptr noundef byval(%"class.JPH::Vec3") align 16 %15)
  store float %41, ptr %10, align 4, !tbaa !11
  %42 = load float, ptr %10, align 4, !tbaa !11
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  %44 = getelementptr inbounds %"class.JPH::BroadPhaseCastResult", ptr %43, i32 0, i32 1
  %45 = load float, ptr %44, align 4, !tbaa !13
  %46 = fcmp olt float %42, %45
  br i1 %46, label %47, label %55

47:                                               ; preds = %4
  %48 = load float, ptr %10, align 4, !tbaa !11
  %49 = load ptr, ptr %9, align 8, !tbaa !5
  %50 = getelementptr inbounds %"class.JPH::BroadPhaseCastResult", ptr %49, i32 0, i32 1
  store float %48, ptr %50, align 4, !tbaa !13
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK3JPH17SubShapeIDCreator5GetIDEv(ptr noundef nonnull align 4 dereferenceable(8) %51)
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = getelementptr inbounds %"class.JPH::RayCastResult", ptr %53, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %54, ptr align 4 %52, i64 4, i1 false), !tbaa.struct !17
  store i1 true, ptr %5, align 1
  store i32 1, ptr %16, align 4
  br label %56

55:                                               ; preds = %4
  store i1 false, ptr %5, align 1
  store i32 1, ptr %16, align 4
  br label %56

56:                                               ; preds = %55, %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  %57 = load i1, ptr %5, align 1
  ret i1 %57
}

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local noundef float @_ZN3JPH11RayTriangleENS_4Vec3ES0_S0_S0_S0_(double, double, double, double, double, double, double, double, ptr noundef byval(%"class.JPH::Vec3") align 16) #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNK3JPH17SubShapeIDCreator5GetIDEv(ptr noundef nonnull align 4 dereferenceable(8)) #4 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 = { 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 = !{i64 0, i64 16, !10}
!10 = !{!7, !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!14, !12, i64 4}
!14 = !{!"_ZTSN3JPH20BroadPhaseCastResultE", !15, i64 0, !12, i64 4}
!15 = !{!"_ZTSN3JPH6BodyIDE", !16, i64 0}
!16 = !{!"int", !7, i64 0}
!17 = !{i64 0, i64 4, !18}
!18 = !{!16, !16, i64 0}


; 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::Vec3" = type { %union.anon.3 }
%union.anon.3 = type { <4 x float> }

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZNK3JPH13TriangleShape7CastRayERKNS_7RayCastERKNS_17SubShapeIDCreatorERNS_13RayCastResultE(ptr nocapture noundef nonnull readonly align 16 dereferenceable(112) %0, ptr nocapture noundef nonnull readonly align 16 dereferenceable(32) %1, ptr noundef nonnull align 4 dereferenceable(8) %2, ptr nocapture noundef nonnull align 4 dereferenceable(12) %3) unnamed_addr #0 align 2 {
  %.sroa.05.0.copyload = load double, ptr %1, align 16
  %.sroa.26.0..sroa_idx = getelementptr inbounds i8, ptr %1, i64 8
  %.sroa.26.0.copyload = load double, ptr %.sroa.26.0..sroa_idx, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %1, i64 16
  %.sroa.03.0.copyload = load double, ptr %5, align 16
  %.sroa.24.0..sroa_idx = getelementptr inbounds i8, ptr %1, i64 24
  %.sroa.24.0.copyload = load double, ptr %.sroa.24.0..sroa_idx, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 48
  %.sroa.01.0.copyload = load double, ptr %6, align 16
  %.sroa.22.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 56
  %.sroa.22.0.copyload = load double, ptr %.sroa.22.0..sroa_idx, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 64
  %.sroa.0.0.copyload = load double, ptr %7, align 16
  %.sroa.2.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 72
  %.sroa.2.0.copyload = load double, ptr %.sroa.2.0..sroa_idx, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 80
  %9 = tail call noundef float @_ZN3JPH11RayTriangleENS_4Vec3ES0_S0_S0_S0_(double %.sroa.05.0.copyload, double %.sroa.26.0.copyload, 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, ptr noundef nonnull byval(%"class.JPH::Vec3") align 16 %8)
  %10 = getelementptr inbounds i8, ptr %3, i64 4
  %11 = load float, ptr %10, align 4, !tbaa !8
  %12 = fcmp olt float %9, %11
  br i1 %12, label %13, label %17

13:                                               ; preds = %4
  store float %9, ptr %10, align 4, !tbaa !8
  %14 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK3JPH17SubShapeIDCreator5GetIDEv(ptr noundef nonnull align 4 dereferenceable(8) %2)
  %15 = getelementptr inbounds i8, ptr %3, i64 8
  %16 = load i32, ptr %14, align 4, !tbaa !13
  store i32 %16, ptr %15, align 4, !tbaa !13
  br label %17

17:                                               ; preds = %4, %13
  ret i1 %12
}

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local noundef float @_ZN3JPH11RayTriangleENS_4Vec3ES0_S0_S0_S0_(double, double, double, double, double, double, double, double, ptr noundef byval(%"class.JPH::Vec3") align 16) local_unnamed_addr #1

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

attributes #0 = { 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 #1 = { 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 #2 = { 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, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !12, i64 4}
!9 = !{!"_ZTSN3JPH20BroadPhaseCastResultE", !10, i64 0, !12, i64 4}
!10 = !{!"_ZTSN3JPH6BodyIDE", !11, i64 0}
!11 = !{!"int", !6, i64 0}
!12 = !{!"float", !6, i64 0}
!13 = !{!11, !11, i64 0}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass