; LLVM IR from jrouwe/JoltPhysics :: Jolt/Core/RTTI.ll (ZNK3JPH4RTTI6CastToEPKvPKS0_)

; 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 }
%"class.JPH::RTTI" = type { ptr, i32, [4 x i8], %"class.JPH::StaticArray", ptr, ptr }
%"class.JPH::StaticArray" = type { i32, [4 x i8], [4 x %"struct.JPH::StaticArray<JPH::RTTI::BaseClass, 4>::Storage"] }
%"struct.JPH::StaticArray<JPH::RTTI::BaseClass, 4>::Storage" = type { [16 x i8] }
%"struct.JPH::RTTI::BaseClass" = type { ptr, i32 }

@.str.1 = external hidden unnamed_addr constant [71 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [20 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 nounwind uwtable
declare dso_local noundef ptr @_ZNK3JPH11StaticArrayINS_4RTTI9BaseClassELj4EE5beginEv(ptr noundef nonnull align 8 dereferenceable(72)) #2 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZNK3JPH4RTTI6CastToEPKvPKS0_(ptr noundef nonnull align 8 dereferenceable(104) %0, ptr noundef %1, ptr noundef %2) #3 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca %"struct.JPH::AssertLastParam", align 1
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  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
  %16 = load ptr, ptr %5, align 8
  br label %17

17:                                               ; preds = %3
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %23, label %20

20:                                               ; preds = %17
  %21 = call noundef zeroext i1 @_ZN3JPH23AssertFailedParamHelperEPKcS1_jNS_15AssertLastParamE(ptr noundef @.str.6, ptr noundef @.str.1, i32 noundef 108)
  br i1 %21, label %22, label %23

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

23:                                               ; preds = %22, %20, %17
  br label %24

24:                                               ; preds = %23
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = icmp eq ptr %16, %25
  br i1 %26, label %27, label %29

27:                                               ; preds = %24
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %28, ptr %4, align 8
  br label %71

29:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %30 = getelementptr inbounds %"class.JPH::RTTI", ptr %16, i32 0, i32 3
  store ptr %30, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %31 = load ptr, ptr %9, align 8, !tbaa !5
  %32 = call noundef ptr @_ZNK3JPH11StaticArrayINS_4RTTI9BaseClassELj4EE5beginEv(ptr noundef nonnull align 8 dereferenceable(72) %31)
  store ptr %32, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  %34 = call noundef ptr @_ZNK3JPH11StaticArrayINS_4RTTI9BaseClassELj4EE3endEv(ptr noundef nonnull align 8 dereferenceable(72) %33)
  store ptr %34, ptr %11, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %65, %29
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = load ptr, ptr %11, align 8, !tbaa !5
  %38 = icmp ne ptr %36, %37
  br i1 %38, label %40, label %39

39:                                               ; preds = %35
  store i32 4, ptr %12, align 4
  br label %68

40:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %41 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %41, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = load ptr, ptr %13, align 8, !tbaa !5
  %44 = getelementptr inbounds %"struct.JPH::RTTI::BaseClass", ptr %43, i32 0, i32 1
  %45 = load i32, ptr %44, align 8, !tbaa !10
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds i8, ptr %42, i64 %46
  store ptr %47, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %48 = load ptr, ptr %13, align 8, !tbaa !5
  %49 = getelementptr inbounds %"struct.JPH::RTTI::BaseClass", ptr %48, i32 0, i32 0
  %50 = load ptr, ptr %49, align 8, !tbaa !13
  %51 = load ptr, ptr %14, align 8, !tbaa !5
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = call noundef ptr @_ZNK3JPH4RTTI6CastToEPKvPKS0_(ptr noundef nonnull align 8 dereferenceable(104) %50, ptr noundef %51, ptr noundef %52)
  store ptr %53, ptr %15, align 8, !tbaa !5
  %54 = load ptr, ptr %15, align 8, !tbaa !5
  %55 = icmp ne ptr %54, null
  br i1 %55, label %56, label %58

56:                                               ; preds = %40
  %57 = load ptr, ptr %15, align 8, !tbaa !5
  store ptr %57, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %59

58:                                               ; preds = %40
  store i32 0, ptr %12, align 4
  br label %59

59:                                               ; preds = %58, %56
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  %60 = load i32, ptr %12, align 4
  switch i32 %60, label %62 [
    i32 0, label %61
  ]

61:                                               ; preds = %59
  store i32 0, ptr %12, align 4
  br label %62

62:                                               ; preds = %61, %59
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  %63 = load i32, ptr %12, align 4
  switch i32 %63, label %68 [
    i32 0, label %64
  ]

64:                                               ; preds = %62
  br label %65

65:                                               ; preds = %64
  %66 = load ptr, ptr %10, align 8, !tbaa !5
  %67 = getelementptr inbounds %"struct.JPH::RTTI::BaseClass", ptr %66, i32 1
  store ptr %67, ptr %10, align 8, !tbaa !5
  br label %35

68:                                               ; preds = %62, %39
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  %69 = load i32, ptr %12, align 4
  switch i32 %69, label %73 [
    i32 4, label %70
    i32 1, label %71
  ]

70:                                               ; preds = %68
  store ptr null, ptr %4, align 8
  br label %71

71:                                               ; preds = %70, %68, %27
  %72 = load ptr, ptr %4, align 8
  ret ptr %72

73:                                               ; preds = %68
  unreachable
}

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 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 = { 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{i64 2157010028}
!10 = !{!11, !12, i64 8}
!11 = !{!"_ZTSN3JPH4RTTI9BaseClassE", !6, i64 0, !12, i64 8}
!12 = !{!"int", !7, i64 0}
!13 = !{!11, !6, 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"

@.str.1 = external hidden unnamed_addr constant [71 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [20 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 nounwind uwtable
declare dso_local noundef ptr @_ZNK3JPH11StaticArrayINS_4RTTI9BaseClassELj4EE5beginEv(ptr noundef nonnull align 8 dereferenceable(72)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK3JPH11StaticArrayINS_4RTTI9BaseClassELj4EE3endEv(ptr noundef nonnull align 8 dereferenceable(72)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZNK3JPH4RTTI6CastToEPKvPKS0_(ptr noundef nonnull align 8 dereferenceable(104) %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #2 align 2 {
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %4, label %7

4:                                                ; preds = %3
  %5 = tail call noundef zeroext i1 @_ZN3JPH23AssertFailedParamHelperEPKcS1_jNS_15AssertLastParamE(ptr noundef nonnull @.str.6, ptr noundef nonnull @.str.1, i32 noundef 108)
  br i1 %5, label %6, label %7

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

7:                                                ; preds = %3, %4, %6
  %8 = icmp eq ptr %0, %2
  br i1 %8, label %.loopexit, label %9

9:                                                ; preds = %7
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  %11 = tail call noundef ptr @_ZNK3JPH11StaticArrayINS_4RTTI9BaseClassELj4EE5beginEv(ptr noundef nonnull align 8 dereferenceable(72) %10)
  %12 = tail call noundef ptr @_ZNK3JPH11StaticArrayINS_4RTTI9BaseClassELj4EE3endEv(ptr noundef nonnull align 8 dereferenceable(72) %10)
  %.not2729 = icmp eq ptr %11, %12
  br i1 %.not2729, label %.loopexit, label %.lr.ph

13:                                               ; preds = %.lr.ph
  %14 = getelementptr inbounds i8, ptr %.02130, i64 16
  %.not27 = icmp eq ptr %14, %12
  br i1 %.not27, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %9, %13
  %.02130 = phi ptr [ %14, %13 ], [ %11, %9 ]
  %15 = getelementptr inbounds i8, ptr %.02130, i64 8
  %16 = load i32, ptr %15, align 8, !tbaa !6
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds i8, ptr %1, i64 %17
  %19 = load ptr, ptr %.02130, align 8, !tbaa !12
  %20 = tail call noundef ptr @_ZNK3JPH4RTTI6CastToEPKvPKS0_(ptr noundef nonnull align 8 dereferenceable(104) %19, ptr noundef %18, ptr noundef %2)
  %.not28 = icmp eq ptr %20, null
  br i1 %.not28, label %13, label %.loopexit

.loopexit:                                        ; preds = %13, %.lr.ph, %9, %7
  %.3 = phi ptr [ %1, %7 ], [ null, %9 ], [ null, %13 ], [ %20, %.lr.ph ]
  ret ptr %.3
}

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 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 = { 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 2157010028}
!6 = !{!7, !11, i64 8}
!7 = !{!"_ZTSN3JPH4RTTI9BaseClassE", !8, i64 0, !11, i64 8}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!7, !8, i64 0}


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