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

; 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> }
%"struct.JPH::AssertLastParam" = type { i8 }
%"class.JPH::AABox" = type { %"class.JPH::Vec3", %"class.JPH::Vec3" }
%"class.JPH::TriangleSplitterFixedLeafSize" = type { %"class.JPH::TriangleSplitter", i32, i32, 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 }

@.str = external hidden unnamed_addr constant [40 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [115 x i8], align 1

; 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 { double, double } @_ZN3JPH29TriangleSplitterFixedLeafSize19GetCentroidForGroupEj(ptr noundef nonnull align 8 dereferenceable(88) %0, i32 noundef %1) #1 align 2 {
  %3 = alloca %"class.JPH::Vec3", align 16
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca %"struct.JPH::AssertLastParam", align 1
  %7 = alloca %"class.JPH::AABox", align 16
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %9 = load ptr, ptr %4, align 8
  br label %10

10:                                               ; preds = %2
  %11 = load i32, ptr %5, align 4, !tbaa !9
  %12 = getelementptr inbounds %"class.JPH::TriangleSplitterFixedLeafSize", ptr %9, i32 0, i32 1
  %13 = load i32, ptr %12, align 8, !tbaa !11
  %14 = urem i32 %11, %13
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %19, label %16

16:                                               ; preds = %10
  %17 = call noundef zeroext i1 @_ZN3JPH23AssertFailedParamHelperEPKcS1_jNS_15AssertLastParamE(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 33)
  br i1 %17, label %18, label %19

18:                                               ; preds = %16
  call void asm sideeffect "int $$0x3", "~{dirflag},~{fpsr},~{flags}"() #3, !srcloc !17
  br label %19

19:                                               ; preds = %18, %16, %10
  br label %20

20:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 32, ptr %7) #3
  call void @_ZN3JPH5AABoxC2Ev(ptr noundef nonnull align 16 dereferenceable(32) %7)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %21

21:                                               ; preds = %34, %20
  %22 = load i32, ptr %8, align 4, !tbaa !9
  %23 = getelementptr inbounds %"class.JPH::TriangleSplitterFixedLeafSize", ptr %9, i32 0, i32 1
  %24 = load i32, ptr %23, align 8, !tbaa !11
  %25 = icmp ult i32 %22, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %37

27:                                               ; preds = %21
  %28 = getelementptr inbounds %"class.JPH::TriangleSplitter", ptr %9, i32 0, i32 1
  %29 = load ptr, ptr %28, align 8, !tbaa !18
  %30 = load i32, ptr %5, align 4, !tbaa !9
  %31 = load i32, ptr %8, align 4, !tbaa !9
  %32 = add i32 %30, %31
  %33 = call noundef nonnull align 4 dereferenceable(16) ptr @_ZNK3JPH16TriangleSplitter11GetTriangleEj(ptr noundef nonnull align 8 dereferenceable(72) %9, i32 noundef %32)
  call void @_ZN3JPH5AABox11EncapsulateERKNS_5ArrayINS_6Float3ENS_12STLAllocatorIS2_EEEERKNS_15IndexedTriangleE(ptr noundef nonnull align 16 dereferenceable(32) %7, ptr noundef nonnull align 8 dereferenceable(24) %29, ptr noundef nonnull align 4 dereferenceable(16) %33)
  br label %34

34:                                               ; preds = %27
  %35 = load i32, ptr %8, align 4, !tbaa !9
  %36 = add i32 %35, 1
  store i32 %36, ptr %8, align 4, !tbaa !9
  br label %21, !llvm.loop !19

37:                                               ; preds = %26
  %38 = call { double, double } @_ZNK3JPH5AABox9GetCenterEv(ptr noundef nonnull align 16 dereferenceable(32) %7)
  %39 = getelementptr inbounds %"class.JPH::Vec3", ptr %3, i32 0, i32 0
  %40 = getelementptr inbounds %union.anon, ptr %39, i32 0, i32 0
  %41 = getelementptr inbounds { double, double }, ptr %40, i32 0, i32 0
  %42 = extractvalue { double, double } %38, 0
  store double %42, ptr %41, align 16
  %43 = getelementptr inbounds { double, double }, ptr %40, i32 0, i32 1
  %44 = extractvalue { double, double } %38, 1
  store double %44, ptr %43, align 8
  call void @llvm.lifetime.end.p0(i64 32, ptr %7) #3
  %45 = getelementptr inbounds %"class.JPH::Vec3", ptr %3, i32 0, i32 0
  %46 = getelementptr inbounds %union.anon, ptr %45, i32 0, i32 0
  %47 = load { double, double }, ptr %46, align 16
  ret { double, double } %47
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN3JPH23AssertFailedParamHelperEPKcS1_jNS_15AssertLastParamE(ptr noundef, ptr noundef, i32 noundef) #2

; 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 } @_ZNK3JPH5AABox9GetCenterEv(ptr noundef nonnull align 16 dereferenceable(32)) #1 align 2

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 = { 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 #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, !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, !10, i64 72}
!12 = !{!"_ZTSN3JPH29TriangleSplitterFixedLeafSizeE", !13, i64 0, !10, i64 72, !10, i64 76, !10, i64 80, !10, i64 84}
!13 = !{!"_ZTSN3JPH16TriangleSplitterE", !6, i64 8, !6, i64 16, !14, i64 24, !16, i64 48}
!14 = !{!"_ZTSN3JPH5ArrayINS_6Float3ENS_12STLAllocatorIS1_EEEE", !15, i64 0, !15, i64 8, !6, i64 16}
!15 = !{!"long", !7, i64 0}
!16 = !{!"_ZTSN3JPH5ArrayIjNS_12STLAllocatorIjEEEE", !15, i64 0, !15, i64 8, !6, i64 16}
!17 = !{i64 2156885090}
!18 = !{!13, !6, i64 8}
!19 = distinct !{!19, !20}
!20 = !{!"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::AABox" = type { %"class.JPH::Vec3", %"class.JPH::Vec3" }
%"class.JPH::Vec3" = type { %union.anon }
%union.anon = type { <4 x float> }

@.str = external hidden unnamed_addr constant [40 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [115 x i8], align 1

; 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 { double, double } @_ZN3JPH29TriangleSplitterFixedLeafSize19GetCentroidForGroupEj(ptr noundef nonnull align 8 dereferenceable(88) %0, i32 noundef %1) local_unnamed_addr #1 align 2 {
  %3 = alloca %"class.JPH::AABox", align 16
  %4 = getelementptr inbounds i8, ptr %0, i64 72
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = urem i32 %1, %5
  %7 = icmp eq i32 %6, 0
  br i1 %7, label %11, label %8

8:                                                ; preds = %2
  %9 = tail call noundef zeroext i1 @_ZN3JPH23AssertFailedParamHelperEPKcS1_jNS_15AssertLastParamE(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 33)
  br i1 %9, label %10, label %11

10:                                               ; preds = %8
  tail call void asm sideeffect "int $$0x3", "~{dirflag},~{fpsr},~{flags}"() #3, !srcloc !15
  br label %11

11:                                               ; preds = %2, %8, %10
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %3) #3
  call void @_ZN3JPH5AABoxC2Ev(ptr noundef nonnull align 16 dereferenceable(32) %3)
  %12 = load i32, ptr %4, align 8, !tbaa !5
  %.not = icmp eq i32 %12, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %11
  %13 = getelementptr inbounds i8, ptr %0, i64 8
  br label %15

._crit_edge:                                      ; preds = %15, %11
  %14 = call { double, double } @_ZNK3JPH5AABox9GetCenterEv(ptr noundef nonnull align 16 dereferenceable(32) %3)
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %3) #3
  ret { double, double } %14

15:                                               ; preds = %.lr.ph, %15
  %.05 = phi i32 [ 0, %.lr.ph ], [ %19, %15 ]
  %16 = load ptr, ptr %13, align 8, !tbaa !16
  %17 = add i32 %.05, %1
  %18 = call noundef nonnull align 4 dereferenceable(16) ptr @_ZNK3JPH16TriangleSplitter11GetTriangleEj(ptr noundef nonnull align 8 dereferenceable(72) %0, i32 noundef %17)
  call void @_ZN3JPH5AABox11EncapsulateERKNS_5ArrayINS_6Float3ENS_12STLAllocatorIS2_EEEERKNS_15IndexedTriangleE(ptr noundef nonnull align 16 dereferenceable(32) %3, ptr noundef nonnull align 8 dereferenceable(24) %16, ptr noundef nonnull align 4 dereferenceable(16) %18)
  %19 = add nuw i32 %.05, 1
  %20 = load i32, ptr %4, align 8, !tbaa !5
  %21 = icmp ult i32 %19, %20
  br i1 %21, label %15, label %._crit_edge, !llvm.loop !17
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN3JPH23AssertFailedParamHelperEPKcS1_jNS_15AssertLastParamE(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

; 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 } @_ZNK3JPH5AABox9GetCenterEv(ptr noundef nonnull align 16 dereferenceable(32)) local_unnamed_addr #1 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 = { 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 #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 72}
!6 = !{!"_ZTSN3JPH29TriangleSplitterFixedLeafSizeE", !7, i64 0, !14, i64 72, !14, i64 76, !14, i64 80, !14, i64 84}
!7 = !{!"_ZTSN3JPH16TriangleSplitterE", !8, i64 8, !8, i64 16, !11, i64 24, !13, i64 48}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"_ZTSN3JPH5ArrayINS_6Float3ENS_12STLAllocatorIS1_EEEE", !12, i64 0, !12, i64 8, !8, i64 16}
!12 = !{!"long", !9, i64 0}
!13 = !{!"_ZTSN3JPH5ArrayIjNS_12STLAllocatorIjEEEE", !12, i64 0, !12, i64 8, !8, i64 16}
!14 = !{!"int", !9, i64 0}
!15 = !{i64 2156885090}
!16 = !{!7, !8, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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