; LLVM IR from jrouwe/JoltPhysics :: 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::HeightFieldShapeSettings" = type <{ %"class.JPH::ShapeSettings", %"class.JPH::Vec3", %"class.JPH::Vec3", i32, float, float, i32, i32, i32, %"class.JPH::Array", %"class.JPH::Array.6", %"class.JPH::Array.9", float, [12 x i8] }>
%"class.JPH::ShapeSettings" = type { %"class.JPH::SerializableObject", %"class.JPH::RefTarget", i64, %"class.JPH::Result" }
%"class.JPH::SerializableObject" = type { ptr }
%"class.JPH::RefTarget" = type { %"struct.std::atomic" }
%"struct.std::atomic" = type { %"struct.std::__atomic_base" }
%"struct.std::__atomic_base" = type { i32 }
%"class.JPH::Result" = type <{ %union.anon, i8, [7 x i8] }>
%union.anon = type { %"class.std::__cxx11::basic_string" }
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char, std::char_traits<char>, JPH::STLAllocator<char>>::_Alloc_hider", i64, %union.anon.2 }
%"struct.std::__cxx11::basic_string<char, std::char_traits<char>, JPH::STLAllocator<char>>::_Alloc_hider" = type { ptr }
%union.anon.2 = type { i64, [8 x i8] }
%"class.JPH::Vec3" = type { %union.anon.3 }
%union.anon.3 = type { <4 x float> }
%"class.JPH::Array" = type { i64, i64, ptr }
%"class.JPH::Array.6" = type { i64, i64, ptr }
%"class.JPH::Array.9" = 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 void @_ZNK3JPH24HeightFieldShapeSettings24DetermineMinAndMaxSampleERfS1_S1_(ptr noundef nonnull align 16 dereferenceable(208) %0, ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef nonnull align 4 dereferenceable(4) %3) #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 ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca float, align 4
  %13 = alloca float, align 4
  %14 = alloca float, align 4
  %15 = alloca float, align 4
  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
  %16 = load ptr, ptr %5, align 8
  %17 = getelementptr inbounds %"class.JPH::HeightFieldShapeSettings", ptr %16, i32 0, i32 4
  %18 = load float, ptr %17, align 4, !tbaa !9
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  store float %18, ptr %19, align 4, !tbaa !25
  %20 = getelementptr inbounds %"class.JPH::HeightFieldShapeSettings", ptr %16, i32 0, i32 5
  %21 = load float, ptr %20, align 8, !tbaa !26
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  store float %21, ptr %22, align 4, !tbaa !25
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %23 = getelementptr inbounds %"class.JPH::HeightFieldShapeSettings", ptr %16, i32 0, i32 9
  store ptr %23, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %24 = load ptr, ptr %9, align 8, !tbaa !5
  %25 = call noundef ptr @_ZNK3JPH5ArrayIfNS_12STLAllocatorIfEEE5beginEv(ptr noundef nonnull align 8 dereferenceable(24) %24)
  store ptr %25, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  %27 = call noundef ptr @_ZNK3JPH5ArrayIfNS_12STLAllocatorIfEEE3endEv(ptr noundef nonnull align 8 dereferenceable(24) %26)
  store ptr %27, ptr %11, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %48, %4
  %29 = load ptr, ptr %10, align 8, !tbaa !5
  %30 = load ptr, ptr %11, align 8, !tbaa !5
  %31 = icmp ne ptr %29, %30
  br i1 %31, label %33, label %32

32:                                               ; preds = %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %51

33:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %34 = load ptr, ptr %10, align 8, !tbaa !5
  %35 = load float, ptr %34, align 4, !tbaa !25
  store float %35, ptr %12, align 4, !tbaa !25
  %36 = load float, ptr %12, align 4, !tbaa !25
  %37 = fcmp une float %36, 0x47EFFFFFE0000000
  br i1 %37, label %38, label %47

38:                                               ; preds = %33
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIfERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %39, ptr noundef nonnull align 4 dereferenceable(4) %12)
  %41 = load float, ptr %40, align 4, !tbaa !25
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  store float %41, ptr %42, align 4, !tbaa !25
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIfERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %43, ptr noundef nonnull align 4 dereferenceable(4) %12)
  %45 = load float, ptr %44, align 4, !tbaa !25
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  store float %45, ptr %46, align 4, !tbaa !25
  br label %47

47:                                               ; preds = %38, %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %48

48:                                               ; preds = %47
  %49 = load ptr, ptr %10, align 8, !tbaa !5
  %50 = getelementptr inbounds float, ptr %49, i32 1
  store ptr %50, ptr %10, align 8, !tbaa !5
  br label %28

51:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = load float, ptr %52, align 4, !tbaa !25
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = load float, ptr %54, align 4, !tbaa !25
  %56 = fsub float %53, %55
  store float %56, ptr %14, align 4, !tbaa !25
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  store float 0x3EB0C6F7A0000000, ptr %15, align 4, !tbaa !25
  %57 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIfERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %14, ptr noundef nonnull align 4 dereferenceable(4) %15)
  %58 = load float, ptr %57, align 4, !tbaa !25
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  store float %58, ptr %13, align 4, !tbaa !25
  %59 = load float, ptr %13, align 4, !tbaa !25
  %60 = fdiv float 6.553400e+04, %59
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  store float %60, ptr %61, align 4, !tbaa !25
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  ret void
}

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIfERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIfERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #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 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 #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, !21, i64 100}
!10 = !{!"_ZTSN3JPH24HeightFieldShapeSettingsE", !11, i64 0, !20, i64 64, !20, i64 80, !16, i64 96, !21, i64 100, !21, i64 104, !16, i64 108, !16, i64 112, !16, i64 116, !22, i64 120, !23, i64 144, !24, i64 168, !21, i64 192}
!11 = !{!"_ZTSN3JPH13ShapeSettingsE", !12, i64 0, !13, i64 8, !17, i64 16, !18, i64 24}
!12 = !{!"_ZTSN3JPH18SerializableObjectE"}
!13 = !{!"_ZTSN3JPH9RefTargetINS_13ShapeSettingsEEE", !14, i64 0}
!14 = !{!"_ZTSSt6atomicIjE", !15, i64 0}
!15 = !{!"_ZTSSt13__atomic_baseIjE", !16, i64 0}
!16 = !{!"int", !7, i64 0}
!17 = !{!"long", !7, i64 0}
!18 = !{!"_ZTSN3JPH6ResultINS_3RefINS_5ShapeEEEEE", !7, i64 0, !19, i64 32}
!19 = !{!"_ZTSN3JPH6ResultINS_3RefINS_5ShapeEEEE6EStateE", !7, i64 0}
!20 = !{!"_ZTSN3JPH4Vec3E", !7, i64 0}
!21 = !{!"float", !7, i64 0}
!22 = !{!"_ZTSN3JPH5ArrayIfNS_12STLAllocatorIfEEEE", !17, i64 0, !17, i64 8, !6, i64 16}
!23 = !{!"_ZTSN3JPH5ArrayIhNS_12STLAllocatorIhEEEE", !17, i64 0, !17, i64 8, !6, i64 16}
!24 = !{!"_ZTSN3JPH5ArrayINS_8RefConstINS_15PhysicsMaterialEEENS_12STLAllocatorIS3_EEEE", !17, i64 0, !17, i64 8, !6, i64 16}
!25 = !{!21, !21, i64 0}
!26 = !{!10, !21, i64 104}


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

; 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 nounwind uwtable
define dso_local void @_ZNK3JPH24HeightFieldShapeSettings24DetermineMinAndMaxSampleERfS1_S1_(ptr noundef nonnull align 16 dereferenceable(208) %0, ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull align 4 dereferenceable(4) %2, ptr nocapture noundef nonnull writeonly align 4 dereferenceable(4) %3) local_unnamed_addr #1 align 2 {
  %5 = alloca float, align 4
  %6 = alloca float, align 4
  %7 = alloca float, align 4
  %8 = getelementptr inbounds i8, ptr %0, i64 100
  %9 = load float, ptr %8, align 4, !tbaa !5
  store float %9, ptr %1, align 4, !tbaa !24
  %10 = getelementptr inbounds i8, ptr %0, i64 104
  %11 = load float, ptr %10, align 8, !tbaa !25
  store float %11, ptr %2, align 4, !tbaa !24
  %12 = getelementptr inbounds i8, ptr %0, i64 120
  %13 = tail call noundef ptr @_ZNK3JPH5ArrayIfNS_12STLAllocatorIfEEE5beginEv(ptr noundef nonnull align 8 dereferenceable(24) %12)
  %14 = tail call noundef ptr @_ZNK3JPH5ArrayIfNS_12STLAllocatorIfEEE3endEv(ptr noundef nonnull align 8 dereferenceable(24) %12)
  %.not17 = icmp eq ptr %13, %14
  br i1 %.not17, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %28, %4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #3
  %15 = load float, ptr %2, align 4, !tbaa !24
  %16 = load float, ptr %1, align 4, !tbaa !24
  %17 = fsub float %15, %16
  store float %17, ptr %6, align 4, !tbaa !24
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %7) #3
  store float 0x3EB0C6F7A0000000, ptr %7, align 4, !tbaa !24
  %18 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIfERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %6, ptr noundef nonnull align 4 dereferenceable(4) %7)
  %19 = load float, ptr %18, align 4, !tbaa !24
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #3
  %20 = fdiv float 6.553400e+04, %19
  store float %20, ptr %3, align 4, !tbaa !24
  ret void

.lr.ph:                                           ; preds = %4, %28
  %.018 = phi ptr [ %29, %28 ], [ %13, %4 ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #3
  %21 = load float, ptr %.018, align 4, !tbaa !24
  store float %21, ptr %5, align 4, !tbaa !24
  %22 = fcmp une float %21, 0x47EFFFFFE0000000
  br i1 %22, label %23, label %28

23:                                               ; preds = %.lr.ph
  %24 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIfERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %25 = load float, ptr %24, align 4, !tbaa !24
  store float %25, ptr %1, align 4, !tbaa !24
  %26 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIfERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %27 = load float, ptr %26, align 4, !tbaa !24
  store float %27, ptr %2, align 4, !tbaa !24
  br label %28

28:                                               ; preds = %23, %.lr.ph
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  %29 = getelementptr inbounds i8, ptr %.018, i64 4
  %.not = icmp eq ptr %29, %14
  br i1 %.not, label %._crit_edge, label %.lr.ph
}

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIfERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIfERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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, !19, i64 100}
!6 = !{!"_ZTSN3JPH24HeightFieldShapeSettingsE", !7, i64 0, !18, i64 64, !18, i64 80, !12, i64 96, !19, i64 100, !19, i64 104, !12, i64 108, !12, i64 112, !12, i64 116, !20, i64 120, !22, i64 144, !23, i64 168, !19, i64 192}
!7 = !{!"_ZTSN3JPH13ShapeSettingsE", !8, i64 0, !9, i64 8, !15, i64 16, !16, i64 24}
!8 = !{!"_ZTSN3JPH18SerializableObjectE"}
!9 = !{!"_ZTSN3JPH9RefTargetINS_13ShapeSettingsEEE", !10, i64 0}
!10 = !{!"_ZTSSt6atomicIjE", !11, i64 0}
!11 = !{!"_ZTSSt13__atomic_baseIjE", !12, i64 0}
!12 = !{!"int", !13, i64 0}
!13 = !{!"omnipotent char", !14, i64 0}
!14 = !{!"Simple C++ TBAA"}
!15 = !{!"long", !13, i64 0}
!16 = !{!"_ZTSN3JPH6ResultINS_3RefINS_5ShapeEEEEE", !13, i64 0, !17, i64 32}
!17 = !{!"_ZTSN3JPH6ResultINS_3RefINS_5ShapeEEEE6EStateE", !13, i64 0}
!18 = !{!"_ZTSN3JPH4Vec3E", !13, i64 0}
!19 = !{!"float", !13, i64 0}
!20 = !{!"_ZTSN3JPH5ArrayIfNS_12STLAllocatorIfEEEE", !15, i64 0, !15, i64 8, !21, i64 16}
!21 = !{!"any pointer", !13, i64 0}
!22 = !{!"_ZTSN3JPH5ArrayIhNS_12STLAllocatorIhEEEE", !15, i64 0, !15, i64 8, !21, i64 16}
!23 = !{!"_ZTSN3JPH5ArrayINS_8RefConstINS_15PhysicsMaterialEEENS_12STLAllocatorIS3_EEEE", !15, i64 0, !15, i64 8, !21, i64 16}
!24 = !{!19, !19, i64 0}
!25 = !{!6, !19, i64 104}


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