; 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> }
%"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: alwaysinline mustprogress uwtable
declare dso_local { double, double } @_ZNK3JPH4Vec3mlES0_(ptr noundef nonnull align 16 dereferenceable(16), double, double) #2 align 2

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local { double, double } @_ZNK3JPH4Vec33AbsEv(ptr noundef nonnull align 16 dereferenceable(16)) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local { double, double } @_ZNK3JPH13TriangleShape14MakeScaleValidENS_4Vec3E(ptr noundef nonnull align 16 dereferenceable(112) %0, double %1, double %2) unnamed_addr #3 align 2 {
  %4 = alloca %"class.JPH::Vec3", align 16
  %5 = alloca %"class.JPH::Vec3", align 16
  %6 = alloca ptr, align 8
  %7 = alloca %"class.JPH::Vec3", align 16
  %8 = alloca %"class.JPH::Vec3", align 16
  %9 = alloca i32, align 4
  %10 = alloca %"class.JPH::Vec3", align 16
  %11 = alloca %"class.JPH::Vec3", align 16
  %12 = alloca %"class.JPH::Vec3", align 16
  %13 = getelementptr inbounds { double, double }, ptr %5, i32 0, i32 0
  store double %1, ptr %13, align 16
  %14 = getelementptr inbounds { double, double }, ptr %5, i32 0, i32 1
  store double %2, ptr %14, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  %15 = load ptr, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %8, ptr align 16 %5, i64 16, i1 false), !tbaa.struct !9
  %16 = getelementptr inbounds { double, double }, ptr %8, i32 0, i32 0
  %17 = load double, ptr %16, align 16
  %18 = getelementptr inbounds { double, double }, ptr %8, i32 0, i32 1
  %19 = load double, ptr %18, align 8
  %20 = call { double, double } @_ZN3JPH12ScaleHelpers16MakeNonZeroScaleENS_4Vec3E(double %17, double %19)
  %21 = getelementptr inbounds %"class.JPH::Vec3", ptr %7, i32 0, i32 0
  %22 = getelementptr inbounds %union.anon.3, ptr %21, i32 0, i32 0
  %23 = getelementptr inbounds { double, double }, ptr %22, i32 0, i32 0
  %24 = extractvalue { double, double } %20, 0
  store double %24, ptr %23, align 16
  %25 = getelementptr inbounds { double, double }, ptr %22, i32 0, i32 1
  %26 = extractvalue { double, double } %20, 1
  store double %26, ptr %25, align 8
  %27 = getelementptr inbounds %"class.JPH::TriangleShape", ptr %15, i32 0, i32 5
  %28 = load float, ptr %27, align 16, !tbaa !11
  %29 = fcmp oeq float %28, 0.000000e+00
  br i1 %29, label %30, label %31

30:                                               ; preds = %3
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %4, ptr align 16 %7, i64 16, i1 false), !tbaa.struct !9
  store i32 1, ptr %9, align 4
  br label %68

31:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 16, ptr %10) #5
  %32 = call { double, double } @_ZNK3JPH4Vec37GetSignEv(ptr noundef nonnull align 16 dereferenceable(16) %7)
  %33 = getelementptr inbounds %"class.JPH::Vec3", ptr %10, i32 0, i32 0
  %34 = getelementptr inbounds %union.anon.3, ptr %33, i32 0, i32 0
  %35 = getelementptr inbounds { double, double }, ptr %34, i32 0, i32 0
  %36 = extractvalue { double, double } %32, 0
  store double %36, ptr %35, align 16
  %37 = getelementptr inbounds { double, double }, ptr %34, i32 0, i32 1
  %38 = extractvalue { double, double } %32, 1
  store double %38, ptr %37, align 8
  %39 = call { double, double } @_ZNK3JPH4Vec33AbsEv(ptr noundef nonnull align 16 dereferenceable(16) %7)
  %40 = getelementptr inbounds %"class.JPH::Vec3", ptr %12, i32 0, i32 0
  %41 = getelementptr inbounds %union.anon.3, ptr %40, i32 0, i32 0
  %42 = getelementptr inbounds { double, double }, ptr %41, i32 0, i32 0
  %43 = extractvalue { double, double } %39, 0
  store double %43, ptr %42, align 16
  %44 = getelementptr inbounds { double, double }, ptr %41, i32 0, i32 1
  %45 = extractvalue { double, double } %39, 1
  store double %45, ptr %44, align 8
  %46 = getelementptr inbounds { double, double }, ptr %12, i32 0, i32 0
  %47 = load double, ptr %46, align 16
  %48 = getelementptr inbounds { double, double }, ptr %12, i32 0, i32 1
  %49 = load double, ptr %48, align 8
  %50 = call { double, double } @_ZN3JPH12ScaleHelpers16MakeUniformScaleENS_4Vec3E(double %47, double %49)
  %51 = getelementptr inbounds %"class.JPH::Vec3", ptr %11, i32 0, i32 0
  %52 = getelementptr inbounds %union.anon.3, ptr %51, i32 0, i32 0
  %53 = getelementptr inbounds { double, double }, ptr %52, i32 0, i32 0
  %54 = extractvalue { double, double } %50, 0
  store double %54, ptr %53, align 16
  %55 = getelementptr inbounds { double, double }, ptr %52, i32 0, i32 1
  %56 = extractvalue { double, double } %50, 1
  store double %56, ptr %55, align 8
  %57 = getelementptr inbounds { double, double }, ptr %11, i32 0, i32 0
  %58 = load double, ptr %57, align 16
  %59 = getelementptr inbounds { double, double }, ptr %11, i32 0, i32 1
  %60 = load double, ptr %59, align 8
  %61 = call { double, double } @_ZNK3JPH4Vec3mlES0_(ptr noundef nonnull align 16 dereferenceable(16) %10, double %58, double %60)
  %62 = getelementptr inbounds %"class.JPH::Vec3", ptr %4, i32 0, i32 0
  %63 = getelementptr inbounds %union.anon.3, ptr %62, i32 0, i32 0
  %64 = getelementptr inbounds { double, double }, ptr %63, i32 0, i32 0
  %65 = extractvalue { double, double } %61, 0
  store double %65, ptr %64, align 16
  %66 = getelementptr inbounds { double, double }, ptr %63, i32 0, i32 1
  %67 = extractvalue { double, double } %61, 1
  store double %67, ptr %66, align 8
  call void @llvm.lifetime.end.p0(i64 16, ptr %10) #5
  store i32 1, ptr %9, align 4
  br label %68

68:                                               ; preds = %31, %30
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #5
  %69 = getelementptr inbounds %"class.JPH::Vec3", ptr %4, i32 0, i32 0
  %70 = getelementptr inbounds %union.anon.3, ptr %69, i32 0, i32 0
  %71 = load { double, double }, ptr %70, align 16
  ret { double, double } %71
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local { double, double } @_ZN3JPH12ScaleHelpers16MakeNonZeroScaleENS_4Vec3E(double, double) #4

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local { double, double } @_ZNK3JPH4Vec37GetSignEv(ptr noundef nonnull align 16 dereferenceable(16)) #2 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local { double, double } @_ZN3JPH12ScaleHelpers16MakeUniformScaleENS_4Vec3E(double, double) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { alwaysinline mustprogress uwtable "min-legal-vector-width"="128" "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 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, !23, i64 96}
!12 = !{!"_ZTSN3JPH13TriangleShapeE", !13, i64 0, !24, i64 48, !24, i64 64, !24, i64 80, !23, i64 96}
!13 = !{!"_ZTSN3JPH11ConvexShapeE", !14, i64 0, !22, i64 32, !23, i64 40}
!14 = !{!"_ZTSN3JPH5ShapeE", !15, i64 8, !19, i64 16, !20, i64 24, !21, i64 25}
!15 = !{!"_ZTSN3JPH9RefTargetINS_5ShapeEEE", !16, i64 0}
!16 = !{!"_ZTSSt6atomicIjE", !17, i64 0}
!17 = !{!"_ZTSSt13__atomic_baseIjE", !18, i64 0}
!18 = !{!"int", !7, i64 0}
!19 = !{!"long", !7, i64 0}
!20 = !{!"_ZTSN3JPH10EShapeTypeE", !7, i64 0}
!21 = !{!"_ZTSN3JPH13EShapeSubTypeE", !7, i64 0}
!22 = !{!"_ZTSN3JPH8RefConstINS_15PhysicsMaterialEEE", !6, i64 0}
!23 = !{!"float", !7, i64 0}
!24 = !{!"_ZTSN3JPH4Vec3E", !7, 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 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: alwaysinline mustprogress uwtable
declare dso_local { double, double } @_ZNK3JPH4Vec3mlES0_(ptr noundef nonnull align 16 dereferenceable(16), double, double) local_unnamed_addr #1 align 2

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local { double, double } @_ZNK3JPH4Vec33AbsEv(ptr noundef nonnull align 16 dereferenceable(16)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local { double, double } @_ZNK3JPH13TriangleShape14MakeScaleValidENS_4Vec3E(ptr nocapture noundef nonnull readonly align 16 dereferenceable(112) %0, double %1, double %2) unnamed_addr #2 align 2 {
  %4 = alloca %"class.JPH::Vec3", align 16
  %5 = alloca %"class.JPH::Vec3", align 16
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #4
  %6 = tail call { double, double } @_ZN3JPH12ScaleHelpers16MakeNonZeroScaleENS_4Vec3E(double %1, double %2)
  %7 = extractvalue { double, double } %6, 0
  store double %7, ptr %4, align 16
  %8 = getelementptr inbounds i8, ptr %4, i64 8
  %9 = extractvalue { double, double } %6, 1
  store double %9, ptr %8, align 8
  %10 = getelementptr inbounds i8, ptr %0, i64 96
  %11 = load float, ptr %10, align 16, !tbaa !5
  %12 = fcmp oeq float %11, 0.000000e+00
  br i1 %12, label %25, label %13

13:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #4
  %14 = call { double, double } @_ZNK3JPH4Vec37GetSignEv(ptr noundef nonnull align 16 dereferenceable(16) %4)
  %15 = extractvalue { double, double } %14, 0
  store double %15, ptr %5, align 16
  %16 = getelementptr inbounds i8, ptr %5, i64 8
  %17 = extractvalue { double, double } %14, 1
  store double %17, ptr %16, align 8
  %18 = call { double, double } @_ZNK3JPH4Vec33AbsEv(ptr noundef nonnull align 16 dereferenceable(16) %4)
  %19 = extractvalue { double, double } %18, 0
  %20 = extractvalue { double, double } %18, 1
  %21 = call { double, double } @_ZN3JPH12ScaleHelpers16MakeUniformScaleENS_4Vec3E(double %19, double %20)
  %22 = extractvalue { double, double } %21, 0
  %23 = extractvalue { double, double } %21, 1
  %24 = call { double, double } @_ZNK3JPH4Vec3mlES0_(ptr noundef nonnull align 16 dereferenceable(16) %5, double %22, double %23)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #4
  br label %25

25:                                               ; preds = %3, %13
  %.fca.1.insert.merged = phi { double, double } [ %24, %13 ], [ %6, %3 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #4
  ret { double, double } %.fca.1.insert.merged
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local { double, double } @_ZN3JPH12ScaleHelpers16MakeNonZeroScaleENS_4Vec3E(double, double) local_unnamed_addr #3

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local { double, double } @_ZNK3JPH4Vec37GetSignEv(ptr noundef nonnull align 16 dereferenceable(16)) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local { double, double } @_ZN3JPH12ScaleHelpers16MakeUniformScaleENS_4Vec3E(double, double) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { alwaysinline mustprogress uwtable "min-legal-vector-width"="128" "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 = { inlinehint 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, !20, i64 96}
!6 = !{!"_ZTSN3JPH13TriangleShapeE", !7, i64 0, !21, i64 48, !21, i64 64, !21, i64 80, !20, i64 96}
!7 = !{!"_ZTSN3JPH11ConvexShapeE", !8, i64 0, !18, i64 32, !20, i64 40}
!8 = !{!"_ZTSN3JPH5ShapeE", !9, i64 8, !15, i64 16, !16, i64 24, !17, i64 25}
!9 = !{!"_ZTSN3JPH9RefTargetINS_5ShapeEEE", !10, i64 0}
!10 = !{!"_ZTSSt6atomicIjE", !11, i64 0}
!11 = !{!"_ZTSSt13__atomic_baseIjE", !12, i64 0}
!12 = !{!"int", !13, i64 0}
!13 = !{!"omnipotent char", !14, i64 0}
!14 = !{!"Simple C++ TBAA"}
!15 = !{!"long", !13, i64 0}
!16 = !{!"_ZTSN3JPH10EShapeTypeE", !13, i64 0}
!17 = !{!"_ZTSN3JPH13EShapeSubTypeE", !13, i64 0}
!18 = !{!"_ZTSN3JPH8RefConstINS_15PhysicsMaterialEEE", !19, i64 0}
!19 = !{!"any pointer", !13, i64 0}
!20 = !{!"float", !13, i64 0}
!21 = !{!"_ZTSN3JPH4Vec3E", !13, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass