; LLVM IR from zig-gamedev/zphysics :: libs/Jolt/TriangleSplitter (TriangleSplitterLongestAxis)

; 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::AABox" = type { %"class.JPH::Vec3", %"class.JPH::Vec3" }
%"class.JPH::Vec3" = type { %union.anon }
%union.anon = type { <4 x float> }
%"struct.JPH::TriangleSplitter::Range" = type { i32, i32 }
%"class.JPH::TriangleSplitter" = type { ptr, ptr, ptr, %"class.JPH::Array", %"class.JPH::Array.0" }
%"class.JPH::Array" = type { i64, i64, ptr }
%"class.JPH::Array.0" = 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: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN3JPH27TriangleSplitterLongestAxis5SplitERKNS_16TriangleSplitter5RangeERS2_S5_(ptr noundef nonnull align 8 dereferenceable(72) %0, ptr noundef nonnull align 4 dereferenceable(8) %1, ptr noundef nonnull align 4 dereferenceable(8) %2, ptr noundef nonnull align 4 dereferenceable(8) %3) unnamed_addr #1 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca %"class.JPH::AABox", align 16
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca %"class.JPH::Vec3", align 16
  %13 = alloca float, align 4
  %14 = alloca %"class.JPH::Vec3", align 16
  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
  store ptr %3, ptr %8, align 8, !tbaa !5
  %15 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 32, ptr %9) #4
  call void @_ZN3JPH5AABoxC2Ev(ptr noundef nonnull align 16 dereferenceable(32) %9)
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds %"struct.JPH::TriangleSplitter::Range", ptr %16, i32 0, i32 0
  %18 = load i32, ptr %17, align 4, !tbaa !9
  store i32 %18, ptr %10, align 4, !tbaa !12
  br label %19

19:                                               ; preds = %31, %4
  %20 = load i32, ptr %10, align 4, !tbaa !12
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %"struct.JPH::TriangleSplitter::Range", ptr %21, i32 0, i32 1
  %23 = load i32, ptr %22, align 4, !tbaa !13
  %24 = icmp ult i32 %20, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %34

26:                                               ; preds = %19
  %27 = getelementptr inbounds %"class.JPH::TriangleSplitter", ptr %15, i32 0, i32 1
  %28 = load ptr, ptr %27, align 8, !tbaa !14
  %29 = load i32, ptr %10, align 4, !tbaa !12
  %30 = call noundef nonnull align 4 dereferenceable(16) ptr @_ZNK3JPH16TriangleSplitter11GetTriangleEj(ptr noundef nonnull align 8 dereferenceable(72) %15, i32 noundef %29)
  call void @_ZN3JPH5AABox11EncapsulateERKNS_5ArrayINS_6Float3ENS_12STLAllocatorIS2_EEEERKNS_15IndexedTriangleE(ptr noundef nonnull align 16 dereferenceable(32) %9, ptr noundef nonnull align 8 dereferenceable(24) %28, ptr noundef nonnull align 4 dereferenceable(16) %30)
  br label %31

31:                                               ; preds = %26
  %32 = load i32, ptr %10, align 4, !tbaa !12
  %33 = add i32 %32, 1
  store i32 %33, ptr %10, align 4, !tbaa !12
  br label %19, !llvm.loop !19

34:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr %12) #4
  %35 = call { double, double } @_ZNK3JPH5AABox9GetExtentEv(ptr noundef nonnull align 16 dereferenceable(32) %9)
  %36 = getelementptr inbounds %"class.JPH::Vec3", ptr %12, i32 0, i32 0
  %37 = getelementptr inbounds %union.anon, ptr %36, i32 0, i32 0
  %38 = getelementptr inbounds { double, double }, ptr %37, i32 0, i32 0
  %39 = extractvalue { double, double } %35, 0
  store double %39, ptr %38, align 16
  %40 = getelementptr inbounds { double, double }, ptr %37, i32 0, i32 1
  %41 = extractvalue { double, double } %35, 1
  store double %41, ptr %40, align 8
  %42 = call noundef i32 @_ZNK3JPH4Vec324GetHighestComponentIndexEv(ptr noundef nonnull align 16 dereferenceable(16) %12)
  call void @llvm.lifetime.end.p0(i64 16, ptr %12) #4
  store i32 %42, ptr %11, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr %14) #4
  %43 = call { double, double } @_ZNK3JPH5AABox9GetCenterEv(ptr noundef nonnull align 16 dereferenceable(32) %9)
  %44 = getelementptr inbounds %"class.JPH::Vec3", ptr %14, i32 0, i32 0
  %45 = getelementptr inbounds %union.anon, ptr %44, i32 0, i32 0
  %46 = getelementptr inbounds { double, double }, ptr %45, i32 0, i32 0
  %47 = extractvalue { double, double } %43, 0
  store double %47, ptr %46, align 16
  %48 = getelementptr inbounds { double, double }, ptr %45, i32 0, i32 1
  %49 = extractvalue { double, double } %43, 1
  store double %49, ptr %48, align 8
  %50 = load i32, ptr %11, align 4, !tbaa !12
  %51 = call noundef float @_ZNK3JPH4Vec3ixEj(ptr noundef nonnull align 16 dereferenceable(16) %14, i32 noundef %50)
  call void @llvm.lifetime.end.p0(i64 16, ptr %14) #4
  store float %51, ptr %13, align 4, !tbaa !21
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = load i32, ptr %11, align 4, !tbaa !12
  %54 = load float, ptr %13, align 4, !tbaa !21
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = load ptr, ptr %8, align 8, !tbaa !5
  %57 = call noundef zeroext i1 @_ZN3JPH16TriangleSplitter13SplitInternalERKNS0_5RangeEjfRS1_S4_(ptr noundef nonnull align 8 dereferenceable(72) %15, ptr noundef nonnull align 4 dereferenceable(8) %52, i32 noundef %53, float noundef %54, ptr noundef nonnull align 4 dereferenceable(8) %55, ptr noundef nonnull align 4 dereferenceable(8) %56)
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %9) #4
  ret i1 %57
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3JPH5AABoxC2Ev(ptr noundef nonnull align 16 dereferenceable(32)) unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3JPH5AABox11EncapsulateERKNS_5ArrayINS_6Float3ENS_12STLAllocatorIS2_EEEERKNS_15IndexedTriangleE(ptr noundef nonnull align 16 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 4 dereferenceable(16)) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(16) ptr @_ZNK3JPH16TriangleSplitter11GetTriangleEj(ptr noundef nonnull align 8 dereferenceable(72), i32 noundef) #1 align 2

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

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local noundef i32 @_ZNK3JPH4Vec324GetHighestComponentIndexEv(ptr noundef nonnull align 16 dereferenceable(16)) #2 align 2

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

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local noundef float @_ZNK3JPH4Vec3ixEj(ptr noundef nonnull align 16 dereferenceable(16), i32 noundef) #2 align 2

declare noundef zeroext i1 @_ZN3JPH16TriangleSplitter13SplitInternalERKNS0_5RangeEjfRS1_S4_(ptr noundef nonnull align 8 dereferenceable(72), ptr noundef nonnull align 4 dereferenceable(8), i32 noundef, float noundef, ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) #3

attributes #0 = { 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 = { "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, !11, i64 0}
!10 = !{!"_ZTSN3JPH16TriangleSplitter5RangeE", !11, i64 0, !11, i64 4}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !11, i64 4}
!14 = !{!15, !6, i64 8}
!15 = !{!"_ZTSN3JPH16TriangleSplitterE", !6, i64 8, !6, i64 16, !16, i64 24, !18, i64 48}
!16 = !{!"_ZTSN3JPH5ArrayINS_6Float3ENS_12STLAllocatorIS1_EEEE", !17, i64 0, !17, i64 8, !6, i64 16}
!17 = !{!"long", !7, i64 0}
!18 = !{!"_ZTSN3JPH5ArrayIjNS_12STLAllocatorIjEEEE", !17, i64 0, !17, i64 8, !6, i64 16}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!22, !22, i64 0}
!22 = !{!"float", !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::AABox" = type { %"class.JPH::Vec3", %"class.JPH::Vec3" }
%"class.JPH::Vec3" = type { %union.anon }
%union.anon = 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: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN3JPH27TriangleSplitterLongestAxis5SplitERKNS_16TriangleSplitter5RangeERS2_S5_(ptr noundef nonnull align 8 dereferenceable(72) %0, ptr noundef nonnull align 4 dereferenceable(8) %1, ptr noundef nonnull align 4 dereferenceable(8) %2, ptr noundef nonnull align 4 dereferenceable(8) %3) unnamed_addr #1 align 2 {
  %5 = alloca %"class.JPH::AABox", align 16
  %6 = alloca %"class.JPH::Vec3", align 16
  %7 = alloca %"class.JPH::Vec3", align 16
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %5) #4
  call void @_ZN3JPH5AABoxC2Ev(ptr noundef nonnull align 16 dereferenceable(32) %5)
  %8 = load i32, ptr %1, align 4, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %1, i64 4
  %10 = load i32, ptr %9, align 4, !tbaa !10
  %11 = icmp ult i32 %8, %10
  br i1 %11, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %4
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  br label %24

._crit_edge:                                      ; preds = %24, %4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %6) #4
  %13 = call { double, double } @_ZNK3JPH5AABox9GetExtentEv(ptr noundef nonnull align 16 dereferenceable(32) %5)
  %14 = extractvalue { double, double } %13, 0
  store double %14, ptr %6, align 16
  %15 = getelementptr inbounds i8, ptr %6, i64 8
  %16 = extractvalue { double, double } %13, 1
  store double %16, ptr %15, align 8
  %17 = call noundef i32 @_ZNK3JPH4Vec324GetHighestComponentIndexEv(ptr noundef nonnull align 16 dereferenceable(16) %6)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %6) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %7) #4
  %18 = call { double, double } @_ZNK3JPH5AABox9GetCenterEv(ptr noundef nonnull align 16 dereferenceable(32) %5)
  %19 = extractvalue { double, double } %18, 0
  store double %19, ptr %7, align 16
  %20 = getelementptr inbounds i8, ptr %7, i64 8
  %21 = extractvalue { double, double } %18, 1
  store double %21, ptr %20, align 8
  %22 = call noundef float @_ZNK3JPH4Vec3ixEj(ptr noundef nonnull align 16 dereferenceable(16) %7, i32 noundef %17)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %7) #4
  %23 = call noundef zeroext i1 @_ZN3JPH16TriangleSplitter13SplitInternalERKNS0_5RangeEjfRS1_S4_(ptr noundef nonnull align 8 dereferenceable(72) %0, ptr noundef nonnull align 4 dereferenceable(8) %1, i32 noundef %17, float noundef %22, ptr noundef nonnull align 4 dereferenceable(8) %2, ptr noundef nonnull align 4 dereferenceable(8) %3)
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #4
  ret i1 %23

24:                                               ; preds = %.lr.ph, %24
  %.011 = phi i32 [ %8, %.lr.ph ], [ %27, %24 ]
  %25 = load ptr, ptr %12, align 8, !tbaa !11
  %26 = call noundef nonnull align 4 dereferenceable(16) ptr @_ZNK3JPH16TriangleSplitter11GetTriangleEj(ptr noundef nonnull align 8 dereferenceable(72) %0, i32 noundef %.011)
  call void @_ZN3JPH5AABox11EncapsulateERKNS_5ArrayINS_6Float3ENS_12STLAllocatorIS2_EEEERKNS_15IndexedTriangleE(ptr noundef nonnull align 16 dereferenceable(32) %5, ptr noundef nonnull align 8 dereferenceable(24) %25, ptr noundef nonnull align 4 dereferenceable(16) %26)
  %27 = add nuw i32 %.011, 1
  %28 = load i32, ptr %9, align 4, !tbaa !10
  %29 = icmp ult i32 %27, %28
  br i1 %29, label %24, label %._crit_edge, !llvm.loop !17
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3JPH5AABoxC2Ev(ptr noundef nonnull align 16 dereferenceable(32)) unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3JPH5AABox11EncapsulateERKNS_5ArrayINS_6Float3ENS_12STLAllocatorIS2_EEEERKNS_15IndexedTriangleE(ptr noundef nonnull align 16 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 4 dereferenceable(16)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(16) ptr @_ZNK3JPH16TriangleSplitter11GetTriangleEj(ptr noundef nonnull align 8 dereferenceable(72), i32 noundef) local_unnamed_addr #1 align 2

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

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local noundef i32 @_ZNK3JPH4Vec324GetHighestComponentIndexEv(ptr noundef nonnull align 16 dereferenceable(16)) local_unnamed_addr #2 align 2

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

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local noundef float @_ZNK3JPH4Vec3ixEj(ptr noundef nonnull align 16 dereferenceable(16), i32 noundef) local_unnamed_addr #2 align 2

declare noundef zeroext i1 @_ZN3JPH16TriangleSplitter13SplitInternalERKNS0_5RangeEjfRS1_S4_(ptr noundef nonnull align 8 dereferenceable(72), ptr noundef nonnull align 4 dereferenceable(8), i32 noundef, float noundef, ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #3

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 = { "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, !7, i64 0}
!6 = !{!"_ZTSN3JPH16TriangleSplitter5RangeE", !7, i64 0, !7, i64 4}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 4}
!11 = !{!12, !13, i64 8}
!12 = !{!"_ZTSN3JPH16TriangleSplitterE", !13, i64 8, !13, i64 16, !14, i64 24, !16, i64 48}
!13 = !{!"any pointer", !8, i64 0}
!14 = !{!"_ZTSN3JPH5ArrayINS_6Float3ENS_12STLAllocatorIS1_EEEE", !15, i64 0, !15, i64 8, !13, i64 16}
!15 = !{!"long", !8, i64 0}
!16 = !{!"_ZTSN3JPH5ArrayIjNS_12STLAllocatorIjEEEE", !15, i64 0, !15, i64 8, !13, i64 16}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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