; LLVM IR from jrouwe/JoltPhysics :: Jolt/Physics/Collision/Shape/ConvexHullShape.ll (ZNK3JPH15ConvexHullShape8GetStatsEv)

; 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"

%"struct.JPH::Shape::Stats" = type <{ i64, i32, [4 x i8] }>
%"class.JPH::ConvexHullShape" = type <{ %"class.JPH::ConvexShape.base", [4 x i8], %"class.JPH::Vec3", %"class.JPH::Mat44", %"class.JPH::AABox", %"class.JPH::Array.8", %"class.JPH::Array.11", %"class.JPH::Array.14", %"class.JPH::Array.17", float, float, float, [4 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.5", [4 x i8], i64, i8, i8 }>
%"class.JPH::RefTarget.5" = 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::Vec3" = type { %union.anon.6 }
%union.anon.6 = type { <4 x float> }
%"class.JPH::Mat44" = type { [4 x %"class.JPH::Vec4"] }
%"class.JPH::Vec4" = type { %union.anon.7 }
%union.anon.7 = type { <4 x float> }
%"class.JPH::AABox" = type { %"class.JPH::Vec3", %"class.JPH::Vec3" }
%"class.JPH::Array.8" = type { i64, i64, ptr }
%"class.JPH::Array.11" = type { i64, i64, ptr }
%"class.JPH::Array.14" = type { i64, i64, ptr }
%"class.JPH::Array.17" = type { i64, i64, ptr }
%"struct.JPH::ConvexHullShape::Face" = type { i16, i16 }

; 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNK3JPH5ArrayIhNS_12STLAllocatorIhEEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #1 align 2

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

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

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local { i64, i32 } @_ZNK3JPH15ConvexHullShape8GetStatsEv(ptr noundef nonnull align 16 dereferenceable(272) %0) unnamed_addr #2 align 2 {
  %2 = alloca %"struct.JPH::Shape::Stats", align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %9 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %10 = getelementptr inbounds %"class.JPH::ConvexHullShape", ptr %9, i32 0, i32 6
  store ptr %10, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = call noundef ptr @_ZNK3JPH5ArrayINS_15ConvexHullShape4FaceENS_12STLAllocatorIS2_EEE5beginEv(ptr noundef nonnull align 8 dereferenceable(24) %11)
  store ptr %12, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = call noundef ptr @_ZNK3JPH5ArrayINS_15ConvexHullShape4FaceENS_12STLAllocatorIS2_EEE3endEv(ptr noundef nonnull align 8 dereferenceable(24) %13)
  store ptr %14, ptr %7, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %29, %1
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = icmp ne ptr %16, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %32

20:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %21, ptr %8, align 8, !tbaa !5
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = getelementptr inbounds %"struct.JPH::ConvexHullShape::Face", ptr %22, i32 0, i32 1
  %24 = load i16, ptr %23, align 2, !tbaa !11
  %25 = zext i16 %24 to i32
  %26 = sub nsw i32 %25, 2
  %27 = load i32, ptr %4, align 4, !tbaa !9
  %28 = add i32 %27, %26
  store i32 %28, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %29

29:                                               ; preds = %20
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %"struct.JPH::ConvexHullShape::Face", ptr %30, i32 1
  store ptr %31, ptr %6, align 8, !tbaa !5
  br label %15

32:                                               ; preds = %19
  %33 = getelementptr inbounds %"class.JPH::ConvexHullShape", ptr %9, i32 0, i32 5
  %34 = call noundef i64 @_ZNK3JPH5ArrayINS_15ConvexHullShape5PointENS_12STLAllocatorIS2_EEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %33)
  %35 = mul i64 %34, 32
  %36 = add i64 272, %35
  %37 = getelementptr inbounds %"class.JPH::ConvexHullShape", ptr %9, i32 0, i32 6
  %38 = call noundef i64 @_ZNK3JPH5ArrayINS_15ConvexHullShape4FaceENS_12STLAllocatorIS2_EEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %37)
  %39 = mul i64 %38, 4
  %40 = add i64 %36, %39
  %41 = getelementptr inbounds %"class.JPH::ConvexHullShape", ptr %9, i32 0, i32 7
  %42 = call noundef i64 @_ZNK3JPH5ArrayINS_5PlaneENS_12STLAllocatorIS1_EEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %41)
  %43 = mul i64 %42, 16
  %44 = add i64 %40, %43
  %45 = getelementptr inbounds %"class.JPH::ConvexHullShape", ptr %9, i32 0, i32 8
  %46 = call noundef i64 @_ZNK3JPH5ArrayIhNS_12STLAllocatorIhEEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %45)
  %47 = mul i64 %46, 1
  %48 = add i64 %44, %47
  %49 = load i32, ptr %4, align 4, !tbaa !9
  call void @_ZN3JPH5Shape5StatsC2Emj(ptr noundef nonnull align 8 dereferenceable(12) %2, i64 noundef %48, i32 noundef %49)
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  %50 = load { i64, i32 }, ptr %2, align 8
  ret { i64, i32 } %50
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3JPH5Shape5StatsC2Emj(ptr noundef nonnull align 8 dereferenceable(12), i64 noundef, i32 noundef) unnamed_addr #3 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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 #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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 2}
!12 = !{!"_ZTSN3JPH15ConvexHullShape4FaceE", !13, i64 0, !13, i64 2}
!13 = !{!"short", !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"

%"struct.JPH::Shape::Stats" = type <{ i64, i32, [4 x i8] }>

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

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

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

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

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local { i64, i32 } @_ZNK3JPH15ConvexHullShape8GetStatsEv(ptr noundef nonnull align 16 dereferenceable(272) %0) unnamed_addr #1 align 2 {
  %2 = alloca %"struct.JPH::Shape::Stats", align 8
  %3 = getelementptr inbounds i8, ptr %0, i64 184
  %4 = tail call noundef ptr @_ZNK3JPH5ArrayINS_15ConvexHullShape4FaceENS_12STLAllocatorIS2_EEE5beginEv(ptr noundef nonnull align 8 dereferenceable(24) %3)
  %5 = tail call noundef ptr @_ZNK3JPH5ArrayINS_15ConvexHullShape4FaceENS_12STLAllocatorIS2_EEE3endEv(ptr noundef nonnull align 8 dereferenceable(24) %3)
  %.not10 = icmp eq ptr %4, %5
  br i1 %.not10, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %1
  %6 = ptrtoint ptr %5 to i64
  %7 = ptrtoint ptr %4 to i64
  %8 = add i64 %6, -4
  %9 = sub i64 %8, %7
  %min.iters.check = icmp ult i64 %9, 32
  br i1 %min.iters.check, label %.lr.ph.preheader17, label %vector.ph

.lr.ph.preheader17:                               ; preds = %middle.block, %.lr.ph.preheader
  %.012.ph = phi i32 [ 0, %.lr.ph.preheader ], [ %23, %middle.block ]
  %.0911.ph = phi ptr [ %4, %.lr.ph.preheader ], [ %ind.end, %middle.block ]
  br label %.lr.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %10 = lshr i64 %9, 2
  %11 = add nuw nsw i64 %10, 1
  %n.mod.vf = and i64 %11, 7
  %12 = icmp eq i64 %n.mod.vf, 0
  %13 = select i1 %12, i64 8, i64 %n.mod.vf
  %n.vec = sub nsw i64 %11, %13
  %14 = shl i64 %n.vec, 2
  %ind.end = getelementptr i8, ptr %4, i64 %14
  %invariant.gep = getelementptr i8, ptr %4, i64 2
  %invariant.gep22 = getelementptr i8, ptr %4, i64 2
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %20, %vector.body ]
  %vec.phi13 = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %21, %vector.body ]
  %offset.idx = shl i64 %index, 2
  %15 = or disjoint i64 %offset.idx, 16
  %gep = getelementptr i8, ptr %invariant.gep, i64 %offset.idx
  %gep23 = getelementptr i8, ptr %invariant.gep22, i64 %15
  %wide.vec = load <8 x i16>, ptr %gep, align 2, !tbaa !5
  %wide.vec15 = load <8 x i16>, ptr %gep23, align 2, !tbaa !5
  %strided.vec = shufflevector <8 x i16> %wide.vec, <8 x i16> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
  %strided.vec16 = shufflevector <8 x i16> %wide.vec15, <8 x i16> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
  %16 = zext <4 x i16> %strided.vec to <4 x i32>
  %17 = zext <4 x i16> %strided.vec16 to <4 x i32>
  %18 = add <4 x i32> %vec.phi, <i32 -2, i32 -2, i32 -2, i32 -2>
  %19 = add <4 x i32> %vec.phi13, <i32 -2, i32 -2, i32 -2, i32 -2>
  %20 = add <4 x i32> %18, %16
  %21 = add <4 x i32> %19, %17
  %index.next = add nuw i64 %index, 8
  %22 = icmp eq i64 %index.next, %n.vec
  br i1 %22, label %middle.block, label %vector.body, !llvm.loop !10

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <4 x i32> %21, %20
  %23 = tail call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx)
  br label %.lr.ph.preheader17

._crit_edge:                                      ; preds = %.lr.ph, %1
  %.0.lcssa = phi i32 [ 0, %1 ], [ %42, %.lr.ph ]
  %24 = getelementptr inbounds i8, ptr %0, i64 160
  %25 = tail call noundef i64 @_ZNK3JPH5ArrayINS_15ConvexHullShape5PointENS_12STLAllocatorIS2_EEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %24)
  %26 = shl i64 %25, 5
  %27 = add i64 %26, 272
  %28 = tail call noundef i64 @_ZNK3JPH5ArrayINS_15ConvexHullShape4FaceENS_12STLAllocatorIS2_EEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %3)
  %29 = shl i64 %28, 2
  %30 = add i64 %27, %29
  %31 = getelementptr inbounds i8, ptr %0, i64 208
  %32 = tail call noundef i64 @_ZNK3JPH5ArrayINS_5PlaneENS_12STLAllocatorIS1_EEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %31)
  %33 = shl i64 %32, 4
  %34 = add i64 %30, %33
  %35 = getelementptr inbounds i8, ptr %0, i64 232
  %36 = tail call noundef i64 @_ZNK3JPH5ArrayIhNS_12STLAllocatorIhEEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %35)
  %37 = add i64 %34, %36
  call void @_ZN3JPH5Shape5StatsC2Emj(ptr noundef nonnull align 8 dereferenceable(12) %2, i64 noundef %37, i32 noundef %.0.lcssa)
  %.fca.0.load = load i64, ptr %2, align 8
  %.fca.0.insert = insertvalue { i64, i32 } poison, i64 %.fca.0.load, 0
  %.fca.1.gep = getelementptr inbounds i8, ptr %2, i64 8
  %.fca.1.load = load i32, ptr %.fca.1.gep, align 8
  %.fca.1.insert = insertvalue { i64, i32 } %.fca.0.insert, i32 %.fca.1.load, 1
  ret { i64, i32 } %.fca.1.insert

.lr.ph:                                           ; preds = %.lr.ph.preheader17, %.lr.ph
  %.012 = phi i32 [ %42, %.lr.ph ], [ %.012.ph, %.lr.ph.preheader17 ]
  %.0911 = phi ptr [ %43, %.lr.ph ], [ %.0911.ph, %.lr.ph.preheader17 ]
  %38 = getelementptr inbounds i8, ptr %.0911, i64 2
  %39 = load i16, ptr %38, align 2, !tbaa !5
  %40 = zext i16 %39 to i32
  %41 = add i32 %.012, -2
  %42 = add i32 %41, %40
  %43 = getelementptr inbounds i8, ptr %.0911, i64 4
  %.not = icmp eq ptr %43, %5
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3JPH5Shape5StatsC2Emj(ptr noundef nonnull align 8 dereferenceable(12), i64 noundef, i32 noundef) unnamed_addr #1 align 2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.vector.reduce.add.v4i32(<4 x i32>) #2

attributes #0 = { 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 #1 = { 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 #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 2}
!6 = !{!"_ZTSN3JPH15ConvexHullShape4FaceE", !7, i64 0, !7, i64 2}
!7 = !{!"short", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = distinct !{!10, !11, !12}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !12, !11}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass