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

; 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::HeightFieldShape" = type <{ %"class.JPH::Shape.base", [6 x i8], %"class.JPH::Vec3", %"class.JPH::Vec3", i32, i32, i32, i32, i32, i8, i8, i16, i16, [6 x i8], ptr, ptr, ptr, %"class.JPH::Array.9", %"class.JPH::Array.6", i32, [4 x i8] }>
%"class.JPH::Shape.base" = type <{ ptr, %"class.JPH::RefTarget.12", [4 x i8], i64, i8, i8 }>
%"class.JPH::RefTarget.12" = type { %"struct.std::atomic" }
%"struct.std::atomic" = type { %"struct.std::__atomic_base" }
%"struct.std::__atomic_base" = type { i32 }
%"class.JPH::Vec3" = type { %union.anon.3 }
%union.anon.3 = type { <4 x float> }
%"class.JPH::Array.9" = type { i64, i64, ptr }
%"class.JPH::Array.6" = type { i64, i64, ptr }

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN3JPH6SquareIjEET_S1_(i32 noundef) #0

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

; 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: mustprogress uwtable
define dso_local { i64, i32 } @_ZNK3JPH16HeightFieldShape8GetStatsEv(ptr noundef nonnull align 16 dereferenceable(176) %0) unnamed_addr #2 align 2 {
  %2 = alloca %"struct.JPH::Shape::Stats", align 8
  %3 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %4 = load ptr, ptr %3, align 8
  %5 = getelementptr inbounds %"class.JPH::HeightFieldShape", ptr %4, i32 0, i32 17
  %6 = call noundef i64 @_ZNK3JPH5ArrayINS_8RefConstINS_15PhysicsMaterialEEENS_12STLAllocatorIS3_EEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %5)
  %7 = mul i64 %6, 8
  %8 = add i64 176, %7
  %9 = getelementptr inbounds %"class.JPH::HeightFieldShape", ptr %4, i32 0, i32 7
  %10 = load i32, ptr %9, align 4, !tbaa !9
  %11 = zext i32 %10 to i64
  %12 = mul i64 %11, 16
  %13 = add i64 %8, %12
  %14 = getelementptr inbounds %"class.JPH::HeightFieldShape", ptr %4, i32 0, i32 6
  %15 = load i32, ptr %14, align 8, !tbaa !23
  %16 = zext i32 %15 to i64
  %17 = mul i64 %16, 1
  %18 = add i64 %13, %17
  %19 = getelementptr inbounds %"class.JPH::HeightFieldShape", ptr %4, i32 0, i32 8
  %20 = load i32, ptr %19, align 16, !tbaa !24
  %21 = zext i32 %20 to i64
  %22 = mul i64 %21, 1
  %23 = add i64 %18, %22
  %24 = getelementptr inbounds %"class.JPH::HeightFieldShape", ptr %4, i32 0, i32 18
  %25 = call noundef i64 @_ZNK3JPH5ArrayIhNS_12STLAllocatorIhEEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %24)
  %26 = mul i64 %25, 1
  %27 = add i64 %23, %26
  %28 = getelementptr inbounds %"class.JPH::HeightFieldShape", ptr %4, i32 0, i32 6
  %29 = load i32, ptr %28, align 8, !tbaa !23
  %30 = icmp eq i32 %29, 0
  br i1 %30, label %31, label %32

31:                                               ; preds = %1
  br label %38

32:                                               ; preds = %1
  %33 = getelementptr inbounds %"class.JPH::HeightFieldShape", ptr %4, i32 0, i32 4
  %34 = load i32, ptr %33, align 16, !tbaa !25
  %35 = sub i32 %34, 1
  %36 = call noundef i32 @_ZN3JPH6SquareIjEET_S1_(i32 noundef %35)
  %37 = mul i32 %36, 2
  br label %38

38:                                               ; preds = %32, %31
  %39 = phi i32 [ 0, %31 ], [ %37, %32 ]
  call void @_ZN3JPH5Shape5StatsC2Emj(ptr noundef nonnull align 8 dereferenceable(12) %2, i64 noundef %27, i32 noundef %39)
  %40 = load { i64, i32 }, ptr %2, align 8
  ret { i64, i32 } %40
}

; 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 = { 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 #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" }

!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, !15, i64 76}
!10 = !{!"_ZTSN3JPH16HeightFieldShapeE", !11, i64 0, !19, i64 32, !19, i64 48, !15, i64 64, !15, i64 68, !15, i64 72, !15, i64 76, !15, i64 80, !7, i64 84, !7, i64 85, !20, i64 86, !20, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !21, i64 120, !22, i64 144, !15, i64 168}
!11 = !{!"_ZTSN3JPH5ShapeE", !12, i64 8, !16, i64 16, !17, i64 24, !18, i64 25}
!12 = !{!"_ZTSN3JPH9RefTargetINS_5ShapeEEE", !13, i64 0}
!13 = !{!"_ZTSSt6atomicIjE", !14, i64 0}
!14 = !{!"_ZTSSt13__atomic_baseIjE", !15, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = !{!"long", !7, i64 0}
!17 = !{!"_ZTSN3JPH10EShapeTypeE", !7, i64 0}
!18 = !{!"_ZTSN3JPH13EShapeSubTypeE", !7, i64 0}
!19 = !{!"_ZTSN3JPH4Vec3E", !7, i64 0}
!20 = !{!"short", !7, i64 0}
!21 = !{!"_ZTSN3JPH5ArrayINS_8RefConstINS_15PhysicsMaterialEEENS_12STLAllocatorIS3_EEEE", !16, i64 0, !16, i64 8, !6, i64 16}
!22 = !{!"_ZTSN3JPH5ArrayIhNS_12STLAllocatorIhEEEE", !16, i64 0, !16, i64 8, !6, i64 16}
!23 = !{!10, !15, i64 72}
!24 = !{!10, !15, i64 80}
!25 = !{!10, !15, i64 64}


; 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: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN3JPH6SquareIjEET_S1_(i32 noundef) local_unnamed_addr #0

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local { i64, i32 } @_ZNK3JPH16HeightFieldShape8GetStatsEv(ptr noundef nonnull align 16 dereferenceable(176) %0) unnamed_addr #2 align 2 {
  %2 = alloca %"struct.JPH::Shape::Stats", align 8
  %3 = getelementptr inbounds i8, ptr %0, i64 120
  %4 = tail call noundef i64 @_ZNK3JPH5ArrayINS_8RefConstINS_15PhysicsMaterialEEENS_12STLAllocatorIS3_EEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %3)
  %5 = getelementptr inbounds i8, ptr %0, i64 76
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 72
  %8 = load i32, ptr %7, align 8, !tbaa !22
  %9 = getelementptr inbounds i8, ptr %0, i64 80
  %10 = load i32, ptr %9, align 16, !tbaa !23
  %11 = getelementptr inbounds i8, ptr %0, i64 144
  %12 = tail call noundef i64 @_ZNK3JPH5ArrayIhNS_12STLAllocatorIhEEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %11)
  %13 = load i32, ptr %7, align 8, !tbaa !22
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %21, label %15

15:                                               ; preds = %1
  %16 = getelementptr inbounds i8, ptr %0, i64 64
  %17 = load i32, ptr %16, align 16, !tbaa !24
  %18 = add i32 %17, -1
  %19 = tail call noundef i32 @_ZN3JPH6SquareIjEET_S1_(i32 noundef %18)
  %20 = shl i32 %19, 1
  br label %21

21:                                               ; preds = %1, %15
  %22 = phi i32 [ %20, %15 ], [ 0, %1 ]
  %23 = shl i64 %4, 3
  %24 = add i64 %23, 176
  %25 = zext i32 %6 to i64
  %26 = shl nuw nsw i64 %25, 4
  %27 = add i64 %24, %26
  %28 = zext i32 %8 to i64
  %29 = add i64 %27, %28
  %30 = zext i32 %10 to i64
  %31 = add i64 %29, %30
  %32 = add i64 %31, %12
  call void @_ZN3JPH5Shape5StatsC2Emj(ptr noundef nonnull align 8 dereferenceable(12) %2, i64 noundef %32, i32 noundef %22)
  %.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
}

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

attributes #0 = { 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 #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 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, !11, i64 76}
!6 = !{!"_ZTSN3JPH16HeightFieldShapeE", !7, i64 0, !17, i64 32, !17, i64 48, !11, i64 64, !11, i64 68, !11, i64 72, !11, i64 76, !11, i64 80, !12, i64 84, !12, i64 85, !18, i64 86, !18, i64 88, !19, i64 96, !19, i64 104, !19, i64 112, !20, i64 120, !21, i64 144, !11, i64 168}
!7 = !{!"_ZTSN3JPH5ShapeE", !8, i64 8, !14, i64 16, !15, i64 24, !16, i64 25}
!8 = !{!"_ZTSN3JPH9RefTargetINS_5ShapeEEE", !9, i64 0}
!9 = !{!"_ZTSSt6atomicIjE", !10, i64 0}
!10 = !{!"_ZTSSt13__atomic_baseIjE", !11, i64 0}
!11 = !{!"int", !12, i64 0}
!12 = !{!"omnipotent char", !13, i64 0}
!13 = !{!"Simple C++ TBAA"}
!14 = !{!"long", !12, i64 0}
!15 = !{!"_ZTSN3JPH10EShapeTypeE", !12, i64 0}
!16 = !{!"_ZTSN3JPH13EShapeSubTypeE", !12, i64 0}
!17 = !{!"_ZTSN3JPH4Vec3E", !12, i64 0}
!18 = !{!"short", !12, i64 0}
!19 = !{!"any pointer", !12, i64 0}
!20 = !{!"_ZTSN3JPH5ArrayINS_8RefConstINS_15PhysicsMaterialEEENS_12STLAllocatorIS3_EEEE", !14, i64 0, !14, i64 8, !19, i64 16}
!21 = !{!"_ZTSN3JPH5ArrayIhNS_12STLAllocatorIhEEEE", !14, i64 0, !14, i64 8, !19, i64 16}
!22 = !{!6, !11, i64 72}
!23 = !{!6, !11, i64 80}
!24 = !{!6, !11, i64 64}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass