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

%"struct.JPH::AssertLastParam" = type { i8 }
%"struct.JPH::HeightFieldShape::HSGetTrianglesContext" = type <{ %"class.JPH::HeightFieldShape::DecodingContext", ptr, [8 x i8], %"class.JPH::OrientedBox", %"class.JPH::Vec3", %"class.JPH::Mat44", i32, [4 x i8], ptr, i32, [4 x i8], ptr, i8, i8, [14 x i8] }>
%"class.JPH::HeightFieldShape::DecodingContext" = type <{ ptr, i32, [128 x i32], [4 x i8] }>
%"class.JPH::OrientedBox" = type { %"class.JPH::Mat44", %"class.JPH::Vec3" }
%"class.JPH::Vec3" = type { %union.anon.3 }
%union.anon.3 = type { <4 x float> }
%"class.JPH::Mat44" = type { [4 x %"class.JPH::Vec4"] }
%"class.JPH::Vec4" = type { %union.anon.29 }
%union.anon.29 = type { <4 x float> }

@.str.2 = external hidden unnamed_addr constant [102 x i8], align 1
@.str.31 = external hidden unnamed_addr constant [62 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: inlinehint mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN3JPH23AssertFailedParamHelperEPKcS1_jNS_15AssertLastParamE(ptr noundef, ptr noundef, i32 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZNK3JPH16HeightFieldShape16GetTrianglesNextERNS_5Shape19GetTrianglesContextEiPNS_6Float3EPPKNS_15PhysicsMaterialE(ptr noundef nonnull align 16 dereferenceable(176) %0, ptr noundef nonnull align 16 dereferenceable(4288) %1, i32 noundef %2, ptr noundef %3, ptr noundef %4) unnamed_addr #2 align 2 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca %"struct.JPH::AssertLastParam", align 1
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i32 %2, ptr %9, align 4, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  %15 = load ptr, ptr %7, align 8
  br label %16

16:                                               ; preds = %5
  %17 = load i32, ptr %9, align 4, !tbaa !9
  %18 = icmp sge i32 %17, 32
  br i1 %18, label %22, label %19

19:                                               ; preds = %16
  %20 = call noundef zeroext i1 @_ZN3JPH23AssertFailedParamHelperEPKcS1_jNS_15AssertLastParamE(ptr noundef @.str.31, ptr noundef @.str.2, i32 noundef 2515)
  br i1 %20, label %21, label %22

21:                                               ; preds = %19
  call void asm sideeffect "int $$0x3", "~{dirflag},~{fpsr},~{flags}"() #5, !srcloc !11
  br label %22

22:                                               ; preds = %21, %19, %16
  br label %23

23:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %24, ptr %13, align 8, !tbaa !5
  %25 = load ptr, ptr %13, align 8, !tbaa !5
  %26 = getelementptr inbounds %"struct.JPH::HeightFieldShape::HSGetTrianglesContext", ptr %25, i32 0, i32 0
  %27 = call noundef zeroext i1 @_ZNK3JPH16HeightFieldShape15DecodingContext13IsDoneWalkingEv(ptr noundef nonnull align 8 dereferenceable(524) %26)
  br i1 %27, label %28, label %29

28:                                               ; preds = %23
  store i32 0, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %49

29:                                               ; preds = %23
  %30 = load i32, ptr %9, align 4, !tbaa !9
  %31 = load ptr, ptr %13, align 8, !tbaa !5
  %32 = getelementptr inbounds %"struct.JPH::HeightFieldShape::HSGetTrianglesContext", ptr %31, i32 0, i32 6
  store i32 %30, ptr %32, align 16, !tbaa !12
  %33 = load ptr, ptr %10, align 8, !tbaa !5
  %34 = load ptr, ptr %13, align 8, !tbaa !5
  %35 = getelementptr inbounds %"struct.JPH::HeightFieldShape::HSGetTrianglesContext", ptr %34, i32 0, i32 8
  store ptr %33, ptr %35, align 8, !tbaa !19
  %36 = load ptr, ptr %11, align 8, !tbaa !5
  %37 = load ptr, ptr %13, align 8, !tbaa !5
  %38 = getelementptr inbounds %"struct.JPH::HeightFieldShape::HSGetTrianglesContext", ptr %37, i32 0, i32 11
  store ptr %36, ptr %38, align 8, !tbaa !20
  %39 = load ptr, ptr %13, align 8, !tbaa !5
  %40 = getelementptr inbounds %"struct.JPH::HeightFieldShape::HSGetTrianglesContext", ptr %39, i32 0, i32 12
  store i8 0, ptr %40, align 16, !tbaa !21
  %41 = load ptr, ptr %13, align 8, !tbaa !5
  %42 = getelementptr inbounds %"struct.JPH::HeightFieldShape::HSGetTrianglesContext", ptr %41, i32 0, i32 9
  store i32 0, ptr %42, align 16, !tbaa !22
  %43 = load ptr, ptr %13, align 8, !tbaa !5
  %44 = getelementptr inbounds %"struct.JPH::HeightFieldShape::HSGetTrianglesContext", ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %13, align 8, !tbaa !5
  call void @_ZN3JPH16HeightFieldShape15DecodingContext15WalkHeightFieldINS0_21HSGetTrianglesContextEEEvRT_(ptr noundef nonnull align 8 dereferenceable(524) %44, ptr noundef nonnull align 16 dereferenceable(738) %45)
  %46 = load ptr, ptr %13, align 8, !tbaa !5
  %47 = getelementptr inbounds %"struct.JPH::HeightFieldShape::HSGetTrianglesContext", ptr %46, i32 0, i32 9
  %48 = load i32, ptr %47, align 16, !tbaa !22
  store i32 %48, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %49

49:                                               ; preds = %29, %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  %50 = load i32, ptr %6, align 4
  ret i32 %50
}

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK3JPH16HeightFieldShape15DecodingContext13IsDoneWalkingEv(ptr noundef nonnull align 8 dereferenceable(524)) #3 align 2

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local void @_ZN3JPH16HeightFieldShape15DecodingContext15WalkHeightFieldINS0_21HSGetTrianglesContextEEEvRT_(ptr noundef nonnull align 8 dereferenceable(524), ptr noundef nonnull align 16 dereferenceable(738)) #4 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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 #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 = !{i64 2158631134}
!12 = !{!13, !10, i64 704}
!13 = !{!"_ZTSN3JPH16HeightFieldShape21HSGetTrianglesContextE", !14, i64 0, !6, i64 528, !15, i64 544, !17, i64 624, !16, i64 640, !10, i64 704, !6, i64 712, !10, i64 720, !6, i64 728, !18, i64 736, !18, i64 737}
!14 = !{!"_ZTSN3JPH16HeightFieldShape15DecodingContextE", !6, i64 0, !10, i64 8, !7, i64 12}
!15 = !{!"_ZTSN3JPH11OrientedBoxE", !16, i64 0, !17, i64 64}
!16 = !{!"_ZTSN3JPH5Mat44E", !7, i64 0}
!17 = !{!"_ZTSN3JPH4Vec3E", !7, i64 0}
!18 = !{!"bool", !7, i64 0}
!19 = !{!13, !6, i64 712}
!20 = !{!13, !6, i64 728}
!21 = !{!13, !18, i64 736}
!22 = !{!13, !10, i64 720}


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

@.str.2 = external hidden unnamed_addr constant [102 x i8], align 1
@.str.31 = external hidden unnamed_addr constant [62 x i8], align 1

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZNK3JPH16HeightFieldShape16GetTrianglesNextERNS_5Shape19GetTrianglesContextEiPNS_6Float3EPPKNS_15PhysicsMaterialE(ptr nocapture noundef nonnull readnone align 16 dereferenceable(176) %0, ptr noundef nonnull align 16 dereferenceable(4288) %1, i32 noundef %2, ptr noundef %3, ptr noundef %4) unnamed_addr #1 align 2 {
  %6 = icmp sgt i32 %2, 31
  br i1 %6, label %10, label %7

7:                                                ; preds = %5
  %8 = tail call noundef zeroext i1 @_ZN3JPH23AssertFailedParamHelperEPKcS1_jNS_15AssertLastParamE(ptr noundef nonnull @.str.31, ptr noundef nonnull @.str.2, i32 noundef 2515)
  br i1 %8, label %9, label %10

9:                                                ; preds = %7
  tail call void asm sideeffect "int $$0x3", "~{dirflag},~{fpsr},~{flags}"() #4, !srcloc !5
  br label %10

10:                                               ; preds = %5, %7, %9
  %11 = tail call noundef zeroext i1 @_ZNK3JPH16HeightFieldShape15DecodingContext13IsDoneWalkingEv(ptr noundef nonnull align 8 dereferenceable(524) %1)
  br i1 %11, label %19, label %12

12:                                               ; preds = %10
  %13 = getelementptr inbounds i8, ptr %1, i64 704
  store i32 %2, ptr %13, align 16, !tbaa !6
  %14 = getelementptr inbounds i8, ptr %1, i64 712
  store ptr %3, ptr %14, align 8, !tbaa !17
  %15 = getelementptr inbounds i8, ptr %1, i64 728
  store ptr %4, ptr %15, align 8, !tbaa !18
  %16 = getelementptr inbounds i8, ptr %1, i64 736
  store i8 0, ptr %16, align 16, !tbaa !19
  %17 = getelementptr inbounds i8, ptr %1, i64 720
  store i32 0, ptr %17, align 16, !tbaa !20
  tail call void @_ZN3JPH16HeightFieldShape15DecodingContext15WalkHeightFieldINS0_21HSGetTrianglesContextEEEvRT_(ptr noundef nonnull align 8 dereferenceable(524) %1, ptr noundef nonnull align 16 dereferenceable(738) %1)
  %18 = load i32, ptr %17, align 16, !tbaa !20
  br label %19

19:                                               ; preds = %10, %12
  %.0 = phi i32 [ %18, %12 ], [ 0, %10 ]
  ret i32 %.0
}

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK3JPH16HeightFieldShape15DecodingContext13IsDoneWalkingEv(ptr noundef nonnull align 8 dereferenceable(524)) local_unnamed_addr #2 align 2

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local void @_ZN3JPH16HeightFieldShape15DecodingContext15WalkHeightFieldINS0_21HSGetTrianglesContextEEEvRT_(ptr noundef nonnull align 8 dereferenceable(524), ptr noundef nonnull align 16 dereferenceable(738)) local_unnamed_addr #3 align 2

attributes #0 = { 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 #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 = { 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 #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 = !{i64 2158631134}
!6 = !{!7, !12, i64 704}
!7 = !{!"_ZTSN3JPH16HeightFieldShape21HSGetTrianglesContextE", !8, i64 0, !9, i64 528, !13, i64 544, !15, i64 624, !14, i64 640, !12, i64 704, !9, i64 712, !12, i64 720, !9, i64 728, !16, i64 736, !16, i64 737}
!8 = !{!"_ZTSN3JPH16HeightFieldShape15DecodingContextE", !9, i64 0, !12, i64 8, !10, i64 12}
!9 = !{!"any pointer", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{!"int", !10, i64 0}
!13 = !{!"_ZTSN3JPH11OrientedBoxE", !14, i64 0, !15, i64 64}
!14 = !{!"_ZTSN3JPH5Mat44E", !10, i64 0}
!15 = !{!"_ZTSN3JPH4Vec3E", !10, i64 0}
!16 = !{!"bool", !10, i64 0}
!17 = !{!7, !9, i64 712}
!18 = !{!7, !9, i64 728}
!19 = !{!7, !16, i64 736}
!20 = !{!7, !12, i64 720}


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