; LLVM IR from zig-gamedev/zphysics :: libs/Jolt/Physics/Collision/Shape (HeightFieldShape)

; 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.3 }
%union.anon.3 = type { <4 x float> }
%struct.Visitor.34 = type { %"class.JPH::CollideSoftBodyVerticesVsTriangles.base", [128 x float], [4 x i8] }
%"class.JPH::CollideSoftBodyVerticesVsTriangles.base" = type <{ %"class.JPH::Mat44", %"class.JPH::Mat44", %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Vec3", float, float, i32 }>
%"class.JPH::Mat44" = type { [4 x %"class.JPH::Vec4"] }
%"class.JPH::Vec4" = type { %union.anon.29 }
%union.anon.29 = type { <4 x float> }
%"class.JPH::SoftBodyVertex" = type { %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Plane", i32, i8, float, float }
%"class.JPH::Plane" = type { %"class.JPH::Vec4" }

; 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: mustprogress uwtable
define dso_local void @_ZNK3JPH16HeightFieldShape23CollideSoftBodyVerticesERKNS_5Mat44ENS_4Vec3EPNS_14SoftBodyVertexEjfS4_i(ptr noundef nonnull align 16 dereferenceable(176) %0, ptr noundef nonnull align 16 dereferenceable(64) %1, double %2, double %3, ptr noundef %4, i32 noundef %5, float noundef %6, double %7, double %8, i32 noundef %9) unnamed_addr #2 align 2 {
  %11 = alloca %"class.JPH::Vec3", align 16
  %12 = alloca %"class.JPH::Vec3", align 16
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i32, align 4
  %17 = alloca float, align 4
  %18 = alloca i32, align 4
  %19 = alloca %struct.Visitor.34, align 16
  %20 = alloca %"class.JPH::Vec3", align 16
  %21 = alloca ptr, align 8
  %22 = alloca ptr, align 8
  %23 = getelementptr inbounds { double, double }, ptr %11, i32 0, i32 0
  store double %2, ptr %23, align 16
  %24 = getelementptr inbounds { double, double }, ptr %11, i32 0, i32 1
  store double %3, ptr %24, align 8
  %25 = getelementptr inbounds { double, double }, ptr %12, i32 0, i32 0
  store double %7, ptr %25, align 16
  %26 = getelementptr inbounds { double, double }, ptr %12, i32 0, i32 1
  store double %8, ptr %26, align 8
  store ptr %0, ptr %13, align 8, !tbaa !5
  store ptr %1, ptr %14, align 8, !tbaa !5
  store ptr %4, ptr %15, align 8, !tbaa !5
  store i32 %5, ptr %16, align 4, !tbaa !9
  store float %6, ptr %17, align 4, !tbaa !11
  store i32 %9, ptr %18, align 4, !tbaa !9
  %27 = load ptr, ptr %13, align 8
  call void @llvm.lifetime.start.p0(i64 736, ptr %19) #5
  %28 = load ptr, ptr %14, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %20, ptr align 16 %11, i64 16, i1 false), !tbaa.struct !13
  %29 = getelementptr inbounds { double, double }, ptr %20, i32 0, i32 0
  %30 = load double, ptr %29, align 16
  %31 = getelementptr inbounds { double, double }, ptr %20, i32 0, i32 1
  %32 = load double, ptr %31, align 8
  call void @_ZZNK3JPH16HeightFieldShape23CollideSoftBodyVerticesERKNS_5Mat44ENS_4Vec3EPNS_14SoftBodyVertexEjfS4_iEN7VisitorCI2NS_34CollideSoftBodyVerticesVsTrianglesEES3_S4_(ptr noundef nonnull align 16 dereferenceable(732) %19, ptr noundef nonnull align 16 dereferenceable(64) %28, double %30, double %32)
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #5
  %33 = load ptr, ptr %15, align 8, !tbaa !5
  store ptr %33, ptr %21, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #5
  %34 = load ptr, ptr %15, align 8, !tbaa !5
  %35 = load i32, ptr %16, align 4, !tbaa !9
  %36 = zext i32 %35 to i64
  %37 = getelementptr inbounds %"class.JPH::SoftBodyVertex", ptr %34, i64 %36
  store ptr %37, ptr %22, align 8, !tbaa !5
  br label %38

38:                                               ; preds = %53, %10
  %39 = load ptr, ptr %21, align 8, !tbaa !5
  %40 = load ptr, ptr %22, align 8, !tbaa !5
  %41 = icmp ult ptr %39, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %38
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #5
  br label %56

43:                                               ; preds = %38
  %44 = load ptr, ptr %21, align 8, !tbaa !5
  %45 = getelementptr inbounds %"class.JPH::SoftBodyVertex", ptr %44, i32 0, i32 7
  %46 = load float, ptr %45, align 4, !tbaa !15
  %47 = fcmp ogt float %46, 0.000000e+00
  br i1 %47, label %48, label %52

48:                                               ; preds = %43
  %49 = load ptr, ptr %21, align 8, !tbaa !5
  call void @_ZN3JPH34CollideSoftBodyVerticesVsTriangles11StartVertexERKNS_14SoftBodyVertexE(ptr noundef nonnull align 16 dereferenceable(220) %19, ptr noundef nonnull align 16 dereferenceable(80) %49)
  call void @_ZNK3JPH16HeightFieldShape15WalkHeightFieldIZNKS0_23CollideSoftBodyVerticesERKNS_5Mat44ENS_4Vec3EPNS_14SoftBodyVertexEjfS5_iE7VisitorEEvRT_(ptr noundef nonnull align 16 dereferenceable(176) %27, ptr noundef nonnull align 16 dereferenceable(732) %19)
  %50 = load ptr, ptr %21, align 8, !tbaa !5
  %51 = load i32, ptr %18, align 4, !tbaa !9
  call void @_ZNK3JPH34CollideSoftBodyVerticesVsTriangles12FinishVertexERNS_14SoftBodyVertexEi(ptr noundef nonnull align 16 dereferenceable(220) %19, ptr noundef nonnull align 16 dereferenceable(80) %50, i32 noundef %51)
  br label %52

52:                                               ; preds = %48, %43
  br label %53

53:                                               ; preds = %52
  %54 = load ptr, ptr %21, align 8, !tbaa !5
  %55 = getelementptr inbounds %"class.JPH::SoftBodyVertex", ptr %54, i32 1
  store ptr %55, ptr %21, align 8, !tbaa !5
  br label %38, !llvm.loop !21

56:                                               ; preds = %42
  call void @llvm.lifetime.end.p0(i64 736, ptr %19) #5
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare hidden void @_ZZNK3JPH16HeightFieldShape23CollideSoftBodyVerticesERKNS_5Mat44ENS_4Vec3EPNS_14SoftBodyVertexEjfS4_iEN7VisitorCI2NS_34CollideSoftBodyVerticesVsTrianglesEES3_S4_(ptr noundef nonnull align 16 dereferenceable(732), ptr noundef nonnull align 16 dereferenceable(64), double, double) unnamed_addr #3 align 2

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local void @_ZN3JPH34CollideSoftBodyVerticesVsTriangles11StartVertexERKNS_14SoftBodyVertexE(ptr noundef nonnull align 16 dereferenceable(220), ptr noundef nonnull align 16 dereferenceable(80)) #4 align 2

; Function Attrs: mustprogress uwtable
declare hidden void @_ZNK3JPH16HeightFieldShape15WalkHeightFieldIZNKS0_23CollideSoftBodyVerticesERKNS_5Mat44ENS_4Vec3EPNS_14SoftBodyVertexEjfS5_iE7VisitorEEvRT_(ptr noundef nonnull align 16 dereferenceable(176), ptr noundef nonnull align 16 dereferenceable(732)) #2 align 2

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local void @_ZNK3JPH34CollideSoftBodyVerticesVsTriangles12FinishVertexERNS_14SoftBodyVertexEi(ptr noundef nonnull align 16 dereferenceable(220), ptr noundef nonnull align 16 dereferenceable(80), i32 noundef) #4 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #4 = { 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 #5 = { 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, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{i64 0, i64 16, !14}
!14 = !{!7, !7, i64 0}
!15 = !{!16, !12, i64 76}
!16 = !{!"_ZTSN3JPH14SoftBodyVertexE", !17, i64 0, !17, i64 16, !17, i64 32, !18, i64 48, !10, i64 64, !20, i64 68, !12, i64 72, !12, i64 76}
!17 = !{!"_ZTSN3JPH4Vec3E", !7, i64 0}
!18 = !{!"_ZTSN3JPH5PlaneE", !19, i64 0}
!19 = !{!"_ZTSN3JPH4Vec4E", !7, i64 0}
!20 = !{!"bool", !7, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"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"

%struct.Visitor.34 = type { %"class.JPH::CollideSoftBodyVerticesVsTriangles.base", [128 x float], [4 x i8] }
%"class.JPH::CollideSoftBodyVerticesVsTriangles.base" = type <{ %"class.JPH::Mat44", %"class.JPH::Mat44", %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Vec3", float, float, i32 }>
%"class.JPH::Mat44" = type { [4 x %"class.JPH::Vec4"] }
%"class.JPH::Vec4" = type { %union.anon.29 }
%union.anon.29 = type { <4 x float> }
%"class.JPH::Vec3" = type { %union.anon.3 }
%union.anon.3 = type { <4 x float> }
%"class.JPH::SoftBodyVertex" = type { %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Vec3", %"class.JPH::Plane", i32, i8, float, float }
%"class.JPH::Plane" = type { %"class.JPH::Vec4" }

; 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 void @_ZNK3JPH16HeightFieldShape23CollideSoftBodyVerticesERKNS_5Mat44ENS_4Vec3EPNS_14SoftBodyVertexEjfS4_i(ptr noundef nonnull align 16 dereferenceable(176) %0, ptr noundef nonnull align 16 dereferenceable(64) %1, double %2, double %3, ptr noundef %4, i32 noundef %5, float noundef %6, double %7, double %8, i32 noundef %9) unnamed_addr #1 align 2 {
  %11 = alloca %struct.Visitor.34, align 16
  call void @llvm.lifetime.start.p0(i64 736, ptr nonnull %11) #4
  call void @_ZZNK3JPH16HeightFieldShape23CollideSoftBodyVerticesERKNS_5Mat44ENS_4Vec3EPNS_14SoftBodyVertexEjfS4_iEN7VisitorCI2NS_34CollideSoftBodyVerticesVsTrianglesEES3_S4_(ptr noundef nonnull align 16 dereferenceable(732) %11, ptr noundef nonnull align 16 dereferenceable(64) %1, double %2, double %3)
  %12 = zext i32 %5 to i64
  %13 = getelementptr inbounds %"class.JPH::SoftBodyVertex", ptr %4, i64 %12
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %18, %10
  call void @llvm.lifetime.end.p0(i64 736, ptr nonnull %11) #4
  ret void

.lr.ph:                                           ; preds = %10, %18
  %.014 = phi ptr [ %19, %18 ], [ %4, %10 ]
  %14 = getelementptr inbounds i8, ptr %.014, i64 76
  %15 = load float, ptr %14, align 4, !tbaa !5
  %16 = fcmp ogt float %15, 0.000000e+00
  br i1 %16, label %17, label %18

17:                                               ; preds = %.lr.ph
  call void @_ZN3JPH34CollideSoftBodyVerticesVsTriangles11StartVertexERKNS_14SoftBodyVertexE(ptr noundef nonnull align 16 dereferenceable(220) %11, ptr noundef nonnull align 16 dereferenceable(80) %.014)
  call void @_ZNK3JPH16HeightFieldShape15WalkHeightFieldIZNKS0_23CollideSoftBodyVerticesERKNS_5Mat44ENS_4Vec3EPNS_14SoftBodyVertexEjfS5_iE7VisitorEEvRT_(ptr noundef nonnull align 16 dereferenceable(176) %0, ptr noundef nonnull align 16 dereferenceable(732) %11)
  call void @_ZNK3JPH34CollideSoftBodyVerticesVsTriangles12FinishVertexERNS_14SoftBodyVertexEi(ptr noundef nonnull align 16 dereferenceable(220) %11, ptr noundef nonnull align 16 dereferenceable(80) %.014, i32 noundef %9)
  br label %18

18:                                               ; preds = %.lr.ph, %17
  %19 = getelementptr inbounds i8, ptr %.014, i64 80
  %20 = icmp ult ptr %19, %13
  br i1 %20, label %.lr.ph, label %._crit_edge, !llvm.loop !15
}

; Function Attrs: inlinehint mustprogress uwtable
declare hidden void @_ZZNK3JPH16HeightFieldShape23CollideSoftBodyVerticesERKNS_5Mat44ENS_4Vec3EPNS_14SoftBodyVertexEjfS4_iEN7VisitorCI2NS_34CollideSoftBodyVerticesVsTrianglesEES3_S4_(ptr noundef nonnull align 16 dereferenceable(732), ptr noundef nonnull align 16 dereferenceable(64), double, double) unnamed_addr #2 align 2

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local void @_ZN3JPH34CollideSoftBodyVerticesVsTriangles11StartVertexERKNS_14SoftBodyVertexE(ptr noundef nonnull align 16 dereferenceable(220), ptr noundef nonnull align 16 dereferenceable(80)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
declare hidden void @_ZNK3JPH16HeightFieldShape15WalkHeightFieldIZNKS0_23CollideSoftBodyVerticesERKNS_5Mat44ENS_4Vec3EPNS_14SoftBodyVertexEjfS5_iE7VisitorEEvRT_(ptr noundef nonnull align 16 dereferenceable(176), ptr noundef nonnull align 16 dereferenceable(732)) local_unnamed_addr #1 align 2

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local void @_ZNK3JPH34CollideSoftBodyVerticesVsTriangles12FinishVertexERNS_14SoftBodyVertexEi(ptr noundef nonnull align 16 dereferenceable(220), ptr noundef nonnull align 16 dereferenceable(80), i32 noundef) local_unnamed_addr #3 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 = { 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 #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, !14, i64 76}
!6 = !{!"_ZTSN3JPH14SoftBodyVertexE", !7, i64 0, !7, i64 16, !7, i64 32, !10, i64 48, !12, i64 64, !13, i64 68, !14, i64 72, !14, i64 76}
!7 = !{!"_ZTSN3JPH4Vec3E", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSN3JPH5PlaneE", !11, i64 0}
!11 = !{!"_ZTSN3JPH4Vec4E", !8, i64 0}
!12 = !{!"int", !8, i64 0}
!13 = !{!"bool", !8, i64 0}
!14 = !{!"float", !8, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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