; LLVM IR from jrouwe/JoltPhysics :: Jolt/Geometry (ConvexHullBuilder)

; 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 }
%union.anon = type { <4 x float> }
%"class.JPH::ConvexHullBuilder::Face" = type <{ %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Array", ptr, float, i8, [11 x i8] }>
%"class.JPH::Array" = type { i64, i64, 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 } @_ZNK3JPH4Vec3miES0_(ptr noundef nonnull align 16 dereferenceable(16), double, double) #2 align 2

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

30:                                               ; preds = %85, %6
  %31 = load ptr, ptr %13, align 8, !tbaa !5
  %32 = load ptr, ptr %14, align 8, !tbaa !5
  %33 = icmp ne ptr %31, %32
  br i1 %33, label %35, label %34

34:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #6
  br label %88

35:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #6
  %36 = load ptr, ptr %13, align 8, !tbaa !5
  %37 = load ptr, ptr %36, align 8, !tbaa !5
  store ptr %37, ptr %15, align 8, !tbaa !5
  %38 = load ptr, ptr %15, align 8, !tbaa !5
  %39 = getelementptr inbounds %"class.JPH::ConvexHullBuilder::Face", ptr %38, i32 0, i32 5
  %40 = load i8, ptr %39, align 4, !tbaa !11, !range !17, !noundef !18
  %41 = trunc i8 %40 to i1
  br i1 %41, label %84, label %42

42:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #6
  %43 = load ptr, ptr %15, align 8, !tbaa !5
  %44 = getelementptr inbounds %"class.JPH::ConvexHullBuilder::Face", ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %15, align 8, !tbaa !5
  %46 = getelementptr inbounds %"class.JPH::ConvexHullBuilder::Face", ptr %45, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %18, ptr align 16 %46, i64 16, i1 false), !tbaa.struct !19
  %47 = getelementptr inbounds { double, double }, ptr %18, i32 0, i32 0
  %48 = load double, ptr %47, align 16
  %49 = getelementptr inbounds { double, double }, ptr %18, i32 0, i32 1
  %50 = load double, ptr %49, align 8
  %51 = call { double, double } @_ZNK3JPH4Vec3miES0_(ptr noundef nonnull align 16 dereferenceable(16) %7, double %48, double %50)
  %52 = getelementptr inbounds %"class.JPH::Vec3", ptr %17, i32 0, i32 0
  %53 = getelementptr inbounds %union.anon, ptr %52, i32 0, i32 0
  %54 = getelementptr inbounds { double, double }, ptr %53, i32 0, i32 0
  %55 = extractvalue { double, double } %51, 0
  store double %55, ptr %54, align 16
  %56 = getelementptr inbounds { double, double }, ptr %53, i32 0, i32 1
  %57 = extractvalue { double, double } %51, 1
  store double %57, ptr %56, align 8
  %58 = getelementptr inbounds { double, double }, ptr %17, i32 0, i32 0
  %59 = load double, ptr %58, align 16
  %60 = getelementptr inbounds { double, double }, ptr %17, i32 0, i32 1
  %61 = load double, ptr %60, align 8
  %62 = call noundef float @_ZNK3JPH4Vec33DotES0_(ptr noundef nonnull align 16 dereferenceable(16) %44, double %59, double %61)
  store float %62, ptr %16, align 4, !tbaa !9
  %63 = load float, ptr %16, align 4, !tbaa !9
  %64 = fcmp ogt float %63, 0.000000e+00
  br i1 %64, label %65, label %83

65:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #6
  %66 = load float, ptr %16, align 4, !tbaa !9
  %67 = load float, ptr %16, align 4, !tbaa !9
  %68 = fmul float %66, %67
  %69 = load ptr, ptr %15, align 8, !tbaa !5
  %70 = getelementptr inbounds %"class.JPH::ConvexHullBuilder::Face", ptr %69, i32 0, i32 0
  %71 = call noundef float @_ZNK3JPH4Vec38LengthSqEv(ptr noundef nonnull align 16 dereferenceable(16) %70)
  %72 = fdiv float %68, %71
  store float %72, ptr %19, align 4, !tbaa !9
  %73 = load float, ptr %19, align 4, !tbaa !9
  %74 = load ptr, ptr %11, align 8, !tbaa !5
  %75 = load float, ptr %74, align 4, !tbaa !9
  %76 = fcmp ogt float %73, %75
  br i1 %76, label %77, label %82

77:                                               ; preds = %65
  %78 = load ptr, ptr %15, align 8, !tbaa !5
  %79 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %78, ptr %79, align 8, !tbaa !5
  %80 = load float, ptr %19, align 4, !tbaa !9
  %81 = load ptr, ptr %11, align 8, !tbaa !5
  store float %80, ptr %81, align 4, !tbaa !9
  br label %82

82:                                               ; preds = %77, %65
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #6
  br label %83

83:                                               ; preds = %82, %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #6
  br label %84

84:                                               ; preds = %83, %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #6
  br label %85

85:                                               ; preds = %84
  %86 = load ptr, ptr %13, align 8, !tbaa !5
  %87 = getelementptr inbounds ptr, ptr %86, i32 1
  store ptr %87, ptr %13, align 8, !tbaa !5
  br label %30

88:                                               ; preds = %34
  ret void
}

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

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

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef float @_ZNK3JPH4Vec33DotES0_(ptr noundef nonnull align 16 dereferenceable(16), double, double) #5 align 2

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef float @_ZNK3JPH4Vec38LengthSqEv(ptr noundef nonnull align 16 dereferenceable(16)) #5 align 2

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 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 = { alwaysinline 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 #6 = { 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, !16, i64 68}
!12 = !{!"_ZTSN3JPH17ConvexHullBuilder4FaceE", !13, i64 0, !13, i64 16, !14, i64 32, !6, i64 56, !10, i64 64, !16, i64 68}
!13 = !{!"_ZTSN3JPH4Vec3E", !7, i64 0}
!14 = !{!"_ZTSN3JPH5ArrayIiNS_12STLAllocatorIiEEEE", !15, i64 0, !15, i64 8, !6, i64 16}
!15 = !{!"long", !7, i64 0}
!16 = !{!"bool", !7, i64 0}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{i64 0, i64 16, !20}
!20 = !{!7, !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 }
%union.anon = type { <4 x float> }

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK3JPH17ConvexHullBuilder15GetFaceForPointENS_4Vec3ERKNS_5ArrayIPNS0_4FaceENS_12STLAllocatorIS4_EEEERS4_Rf(ptr nocapture noundef nonnull readnone align 8 dereferenceable(56) %0, double %1, double %2, ptr noundef nonnull align 8 dereferenceable(24) %3, ptr nocapture noundef nonnull writeonly align 8 dereferenceable(8) %4, ptr nocapture noundef nonnull align 4 dereferenceable(4) %5) local_unnamed_addr #1 align 2 {
  %7 = alloca %"class.JPH::Vec3", align 16
  store double %1, ptr %7, align 16
  %8 = getelementptr inbounds i8, ptr %7, i64 8
  store double %2, ptr %8, align 8
  store ptr null, ptr %4, align 8, !tbaa !5
  store float 0.000000e+00, ptr %5, align 4, !tbaa !9
  %9 = tail call noundef ptr @_ZNK3JPH5ArrayIPNS_17ConvexHullBuilder4FaceENS_12STLAllocatorIS3_EEE5beginEv(ptr noundef nonnull align 8 dereferenceable(24) %3)
  %10 = tail call noundef ptr @_ZNK3JPH5ArrayIPNS_17ConvexHullBuilder4FaceENS_12STLAllocatorIS3_EEE3endEv(ptr noundef nonnull align 8 dereferenceable(24) %3)
  %.not27 = icmp eq ptr %9, %10
  br i1 %.not27, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %29, %6
  ret void

.lr.ph:                                           ; preds = %6, %29
  %.028 = phi ptr [ %30, %29 ], [ %9, %6 ]
  %11 = load ptr, ptr %.028, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %11, i64 68
  %13 = load i8, ptr %12, align 4, !tbaa !11, !range !17, !noundef !18
  %14 = trunc nuw i8 %13 to i1
  br i1 %14, label %29, label %15

15:                                               ; preds = %.lr.ph
  %16 = getelementptr inbounds i8, ptr %11, i64 16
  %.sroa.0.0.copyload = load double, ptr %16, align 16
  %.sroa.2.0..sroa_idx = getelementptr inbounds i8, ptr %11, i64 24
  %.sroa.2.0.copyload = load double, ptr %.sroa.2.0..sroa_idx, align 8, !tbaa !19
  %17 = call { double, double } @_ZNK3JPH4Vec3miES0_(ptr noundef nonnull align 16 dereferenceable(16) %7, double %.sroa.0.0.copyload, double %.sroa.2.0.copyload)
  %18 = extractvalue { double, double } %17, 0
  %19 = extractvalue { double, double } %17, 1
  %20 = call noundef float @_ZNK3JPH4Vec33DotES0_(ptr noundef nonnull align 16 dereferenceable(16) %11, double %18, double %19)
  %21 = fcmp ogt float %20, 0.000000e+00
  br i1 %21, label %22, label %29

22:                                               ; preds = %15
  %23 = fmul float %20, %20
  %24 = call noundef float @_ZNK3JPH4Vec38LengthSqEv(ptr noundef nonnull align 16 dereferenceable(16) %11)
  %25 = fdiv float %23, %24
  %26 = load float, ptr %5, align 4, !tbaa !9
  %27 = fcmp ogt float %25, %26
  br i1 %27, label %28, label %29

28:                                               ; preds = %22
  store ptr %11, ptr %4, align 8, !tbaa !5
  store float %25, ptr %5, align 4, !tbaa !9
  br label %29

29:                                               ; preds = %15, %28, %22, %.lr.ph
  %30 = getelementptr inbounds i8, ptr %.028, i64 8
  %.not = icmp eq ptr %30, %10
  br i1 %.not, label %._crit_edge, label %.lr.ph
}

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

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

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef float @_ZNK3JPH4Vec33DotES0_(ptr noundef nonnull align 16 dereferenceable(16), double, double) local_unnamed_addr #3 align 2

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef float @_ZNK3JPH4Vec38LengthSqEv(ptr noundef nonnull align 16 dereferenceable(16)) local_unnamed_addr #3 align 2

attributes #0 = { 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 #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 = { 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 = { alwaysinline 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 = !{!"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, !16, i64 68}
!12 = !{!"_ZTSN3JPH17ConvexHullBuilder4FaceE", !13, i64 0, !13, i64 16, !14, i64 32, !6, i64 56, !10, i64 64, !16, i64 68}
!13 = !{!"_ZTSN3JPH4Vec3E", !7, i64 0}
!14 = !{!"_ZTSN3JPH5ArrayIiNS_12STLAllocatorIiEEEE", !15, i64 0, !15, i64 8, !6, i64 16}
!15 = !{!"long", !7, i64 0}
!16 = !{!"bool", !7, i64 0}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!7, !7, i64 0}


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