; LLVM IR from vczh/herodb :: Kernel/Source/Vlpp.ll (ZNK2vl10reflection11description5Value12CanConvertToEPNS1_9ITypeInfoE)

; 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.vl::reflection::description::Value" = type { %"class.vl::Object", i32, ptr, %"class.vl::Ptr.777", %"class.vl::ObjectString", ptr }
%"class.vl::Object" = type { ptr }
%"class.vl::Ptr.777" = type { ptr, ptr, ptr, ptr }
%"class.vl::ObjectString" = type { %"class.vl::Object", ptr, ptr, i64, i64, i64 }

; 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
declare dso_local noundef zeroext i1 @_ZNK2vl10reflection11description5Value12CanConvertToEPNS1_15ITypeDescriptorENS2_9ValueTypeE(ptr noundef nonnull align 8 dereferenceable(112), ptr noundef, i32 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZNK2vl10reflection11description5Value12CanConvertToEPNS1_9ITypeInfoE(ptr noundef nonnull align 8 dereferenceable(112) %0, ptr noundef %1) #1 align 2 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %8 = load ptr, ptr %4, align 8
  %9 = getelementptr inbounds %"class.vl::reflection::description::Value", ptr %8, i32 0, i32 1
  %10 = load i32, ptr %9, align 8, !tbaa !9
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %12, label %20

12:                                               ; preds = %2
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = load ptr, ptr %13, align 8, !tbaa !16
  %15 = getelementptr inbounds ptr, ptr %14, i64 2
  %16 = load ptr, ptr %15, align 8
  %17 = call noundef i32 %16(ptr noundef nonnull align 8 dereferenceable(8) %13)
  %18 = icmp eq i32 %17, 2
  br i1 %18, label %19, label %20

19:                                               ; preds = %12
  store i1 true, ptr %3, align 1
  br label %49

20:                                               ; preds = %12, %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %21, ptr %7, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %40, %20
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = icmp ne ptr %23, null
  br i1 %24, label %25, label %41

25:                                               ; preds = %22
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = load ptr, ptr %26, align 8, !tbaa !16
  %28 = getelementptr inbounds ptr, ptr %27, i64 2
  %29 = load ptr, ptr %28, align 8
  %30 = call noundef i32 %29(ptr noundef nonnull align 8 dereferenceable(8) %26)
  switch i32 %30, label %34 [
    i32 0, label %31
    i32 1, label %32
    i32 3, label %33
    i32 2, label %33
  ]

31:                                               ; preds = %25
  store i32 1, ptr %6, align 4, !tbaa !18
  store ptr null, ptr %7, align 8, !tbaa !5
  br label %40

32:                                               ; preds = %25
  store i32 2, ptr %6, align 4, !tbaa !18
  store ptr null, ptr %7, align 8, !tbaa !5
  br label %40

33:                                               ; preds = %25, %25
  store i32 3, ptr %6, align 4, !tbaa !18
  store ptr null, ptr %7, align 8, !tbaa !5
  br label %40

34:                                               ; preds = %25
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = load ptr, ptr %35, align 8, !tbaa !16
  %37 = getelementptr inbounds ptr, ptr %36, i64 3
  %38 = load ptr, ptr %37, align 8
  %39 = call noundef ptr %38(ptr noundef nonnull align 8 dereferenceable(8) %35)
  store ptr %39, ptr %7, align 8, !tbaa !5
  br label %40

40:                                               ; preds = %34, %33, %32, %31
  br label %22, !llvm.loop !19

41:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = load ptr, ptr %42, align 8, !tbaa !16
  %44 = getelementptr inbounds ptr, ptr %43, i64 4
  %45 = load ptr, ptr %44, align 8
  %46 = call noundef ptr %45(ptr noundef nonnull align 8 dereferenceable(8) %42)
  %47 = load i32, ptr %6, align 4, !tbaa !18
  %48 = call noundef zeroext i1 @_ZNK2vl10reflection11description5Value12CanConvertToEPNS1_15ITypeDescriptorENS2_9ValueTypeE(ptr noundef nonnull align 8 dereferenceable(112) %8, ptr noundef %46, i32 noundef %47)
  store i1 %48, ptr %3, align 1
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %49

49:                                               ; preds = %41, %19
  %50 = load i1, ptr %3, align 1
  ret i1 %50
}

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 = { 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, !12, i64 8}
!10 = !{!"_ZTSN2vl10reflection11description5ValueE", !11, i64 0, !12, i64 8, !6, i64 16, !13, i64 24, !14, i64 56, !6, i64 104}
!11 = !{!"_ZTSN2vl6ObjectE"}
!12 = !{!"_ZTSN2vl10reflection11description5Value9ValueTypeE", !7, i64 0}
!13 = !{!"_ZTSN2vl3PtrINS_10reflection18DescriptableObjectEEE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!14 = !{!"_ZTSN2vl12ObjectStringIwEE", !11, i64 0, !6, i64 8, !6, i64 16, !15, i64 24, !15, i64 32, !15, i64 40}
!15 = !{!"long", !7, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"vtable pointer", !8, i64 0}
!18 = !{!12, !12, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"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"

@switch.table._ZNK2vl10reflection11description5Value12CanConvertToEPNS1_9ITypeInfoE = private unnamed_addr constant [4 x i32] [i32 1, i32 2, i32 3, i32 3], align 4

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZNK2vl10reflection11description5Value12CanConvertToEPNS1_15ITypeDescriptorENS2_9ValueTypeE(ptr noundef nonnull align 8 dereferenceable(112), ptr noundef, i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZNK2vl10reflection11description5Value12CanConvertToEPNS1_9ITypeInfoE(ptr noundef nonnull align 8 dereferenceable(112) %0, ptr noundef %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = icmp eq i32 %4, 0
  br i1 %5, label %6, label %12

6:                                                ; preds = %2
  %7 = load ptr, ptr %1, align 8, !tbaa !15
  %8 = getelementptr inbounds i8, ptr %7, i64 16
  %9 = load ptr, ptr %8, align 8
  %10 = tail call noundef i32 %9(ptr noundef nonnull align 8 dereferenceable(8) %1)
  %11 = icmp eq i32 %10, 2
  br i1 %11, label %29, label %.lr.ph.preheader

12:                                               ; preds = %2
  %.not11 = icmp eq ptr %1, null
  br i1 %.not11, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %6, %12
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %18
  %.013 = phi ptr [ %22, %18 ], [ %1, %.lr.ph.preheader ]
  %13 = load ptr, ptr %1, align 8, !tbaa !15
  %14 = getelementptr inbounds i8, ptr %13, i64 16
  %15 = load ptr, ptr %14, align 8
  %16 = tail call noundef i32 %15(ptr noundef nonnull align 8 dereferenceable(8) %1)
  %17 = icmp ult i32 %16, 4
  br i1 %17, label %switch.lookup, label %18

18:                                               ; preds = %.lr.ph
  %19 = load ptr, ptr %.013, align 8, !tbaa !15
  %20 = getelementptr inbounds i8, ptr %19, i64 24
  %21 = load ptr, ptr %20, align 8
  %22 = tail call noundef ptr %21(ptr noundef nonnull align 8 dereferenceable(8) %.013)
  %.not = icmp eq ptr %22, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !17

switch.lookup:                                    ; preds = %.lr.ph
  %23 = zext nneg i32 %16 to i64
  %switch.gep = getelementptr inbounds [4 x i32], ptr @switch.table._ZNK2vl10reflection11description5Value12CanConvertToEPNS1_9ITypeInfoE, i64 0, i64 %23
  %switch.load = load i32, ptr %switch.gep, align 4
  br label %._crit_edge

._crit_edge:                                      ; preds = %18, %switch.lookup, %12
  %.08.lcssa = phi i32 [ 0, %12 ], [ %switch.load, %switch.lookup ], [ 0, %18 ]
  %24 = load ptr, ptr %1, align 8, !tbaa !15
  %25 = getelementptr inbounds i8, ptr %24, i64 32
  %26 = load ptr, ptr %25, align 8
  %27 = tail call noundef ptr %26(ptr noundef nonnull align 8 dereferenceable(8) %1)
  %28 = tail call noundef zeroext i1 @_ZNK2vl10reflection11description5Value12CanConvertToEPNS1_15ITypeDescriptorENS2_9ValueTypeE(ptr noundef nonnull align 8 dereferenceable(112) %0, ptr noundef %27, i32 noundef %.08.lcssa)
  br label %29

29:                                               ; preds = %6, %._crit_edge
  %.010 = phi i1 [ %28, %._crit_edge ], [ true, %6 ]
  ret i1 %.010
}

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

!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, !8, i64 8}
!6 = !{!"_ZTSN2vl10reflection11description5ValueE", !7, i64 0, !8, i64 8, !11, i64 16, !12, i64 24, !13, i64 56, !11, i64 104}
!7 = !{!"_ZTSN2vl6ObjectE"}
!8 = !{!"_ZTSN2vl10reflection11description5Value9ValueTypeE", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"any pointer", !9, i64 0}
!12 = !{!"_ZTSN2vl3PtrINS_10reflection18DescriptableObjectEEE", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24}
!13 = !{!"_ZTSN2vl12ObjectStringIwEE", !7, i64 0, !11, i64 8, !11, i64 16, !14, i64 24, !14, i64 32, !14, i64 40}
!14 = !{!"long", !9, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"vtable pointer", !10, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass