; LLVM IR from jrouwe/JoltPhysics :: TestFramework/UI/UIManager.ll (ZN9UIManager8FindByIDEi)

; 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.UIManager = type { %class.UIElement, ptr, ptr, %"class.JPH::Array.3", i8, %"class.std::unique_ptr", %"class.std::unique_ptr", %"class.std::function", i32, float }
%class.UIElement = type { %class.UIEventListener, i32, ptr, %"class.JPH::Array", %"class.UIElement::Position", %"class.UIElement::Position", %"class.UIElement::Size", %"class.UIElement::Size", %"class.UIElement::Size", %"class.UIElement::Size", i8, i8, i8, i8, i8, i8, i8, %"class.JPH::Array.0", ptr }
%class.UIEventListener = type { ptr }
%"class.JPH::Array" = type { i64, i64, ptr }
%"class.UIElement::Position" = type { i32, %"class.UIElement::Size" }
%"class.UIElement::Size" = type { i32, i32 }
%"class.JPH::Array.0" = type { i64, i64, ptr }
%"class.JPH::Array.3" = type { i64, i64, ptr }
%"class.std::unique_ptr" = type { %"struct.std::__uniq_ptr_data" }
%"struct.std::__uniq_ptr_data" = type { %"class.std::__uniq_ptr_impl" }
%"class.std::__uniq_ptr_impl" = type { %"class.std::tuple" }
%"class.std::tuple" = type { %"struct.std::_Tuple_impl" }
%"struct.std::_Tuple_impl" = type { %"struct.std::_Head_base.7" }
%"struct.std::_Head_base.7" = type { ptr }
%"class.std::function" = type { %"class.std::_Function_base", ptr }
%"class.std::_Function_base" = type { %"union.std::_Any_data", ptr }
%"union.std::_Any_data" = type { %"union.std::_Nocopy_types" }
%"union.std::_Nocopy_types" = type { { 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNK3JPH5ArrayINS0_IP9UIElementNS_12STLAllocatorIS2_EEEENS3_IS5_EEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #1 align 2

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN9UIManager8FindByIDEi(ptr noundef nonnull align 8 dereferenceable(248) %0, i32 noundef %1) unnamed_addr #3 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %10 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %11 = load i32, ptr %5, align 4, !tbaa !9
  %12 = call noundef ptr @_ZN9UIElement8FindByIDEi(ptr noundef nonnull align 8 dereferenceable(144) %10, i32 noundef %11)
  store ptr %12, ptr %6, align 8, !tbaa !5
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %17

15:                                               ; preds = %2
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %16, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %68

17:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %18 = getelementptr inbounds %class.UIManager, ptr %10, i32 0, i32 3
  %19 = call noundef i64 @_ZNK3JPH5ArrayINS0_IP9UIElementNS_12STLAllocatorIS2_EEEENS3_IS5_EEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %18)
  %20 = trunc i64 %19 to i32
  %21 = sub nsw i32 %20, 1
  store i32 %21, ptr %8, align 4, !tbaa !9
  br label %22

22:                                               ; preds = %62, %17
  %23 = load i32, ptr %8, align 4, !tbaa !9
  %24 = icmp sge i32 %23, 0
  br i1 %24, label %26, label %25

25:                                               ; preds = %22
  store i32 2, ptr %7, align 4
  br label %65

26:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %56, %26
  %28 = load i32, ptr %9, align 4, !tbaa !9
  %29 = getelementptr inbounds %class.UIManager, ptr %10, i32 0, i32 3
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZN3JPH5ArrayINS0_IP9UIElementNS_12STLAllocatorIS2_EEEENS3_IS5_EEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %29, i64 noundef %31)
  %33 = call noundef i64 @_ZNK3JPH5ArrayIP9UIElementNS_12STLAllocatorIS2_EEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %32)
  %34 = trunc i64 %33 to i32
  %35 = icmp slt i32 %28, %34
  br i1 %35, label %37, label %36

36:                                               ; preds = %27
  store i32 5, ptr %7, align 4
  br label %59

37:                                               ; preds = %27
  %38 = getelementptr inbounds %class.UIManager, ptr %10, i32 0, i32 3
  %39 = load i32, ptr %8, align 4, !tbaa !9
  %40 = sext i32 %39 to i64
  %41 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZN3JPH5ArrayINS0_IP9UIElementNS_12STLAllocatorIS2_EEEENS3_IS5_EEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %38, i64 noundef %40)
  %42 = load i32, ptr %9, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN3JPH5ArrayIP9UIElementNS_12STLAllocatorIS2_EEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %41, i64 noundef %43)
  %45 = load ptr, ptr %44, align 8, !tbaa !5
  %46 = load i32, ptr %5, align 4, !tbaa !9
  %47 = load ptr, ptr %45, align 8, !tbaa !11
  %48 = getelementptr inbounds ptr, ptr %47, i64 8
  %49 = load ptr, ptr %48, align 8
  %50 = call noundef ptr %49(ptr noundef nonnull align 8 dereferenceable(144) %45, i32 noundef %46)
  store ptr %50, ptr %6, align 8, !tbaa !5
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = icmp ne ptr %51, null
  br i1 %52, label %53, label %55

53:                                               ; preds = %37
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %54, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %59

55:                                               ; preds = %37
  br label %56

56:                                               ; preds = %55
  %57 = load i32, ptr %9, align 4, !tbaa !9
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %9, align 4, !tbaa !9
  br label %27, !llvm.loop !13

59:                                               ; preds = %53, %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  %60 = load i32, ptr %7, align 4
  switch i32 %60, label %65 [
    i32 5, label %61
  ]

61:                                               ; preds = %59
  br label %62

62:                                               ; preds = %61
  %63 = load i32, ptr %8, align 4, !tbaa !9
  %64 = add nsw i32 %63, -1
  store i32 %64, ptr %8, align 4, !tbaa !9
  br label %22, !llvm.loop !15

65:                                               ; preds = %59, %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  %66 = load i32, ptr %7, align 4
  switch i32 %66, label %68 [
    i32 2, label %67
  ]

67:                                               ; preds = %65
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %68

68:                                               ; preds = %67, %65, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  %69 = load ptr, ptr %3, align 8
  ret ptr %69
}

declare noundef ptr @_ZN9UIElement8FindByIDEi(ptr noundef nonnull align 8 dereferenceable(144), i32 noundef) unnamed_addr #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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 = { "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 = !{!"vtable pointer", !8, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNK3JPH5ArrayINS0_IP9UIElementNS_12STLAllocatorIS2_EEEENS3_IS5_EEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(24) ptr @_ZN3JPH5ArrayINS0_IP9UIElementNS_12STLAllocatorIS2_EEEENS3_IS5_EEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #1 align 2

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZN3JPH5ArrayIP9UIElementNS_12STLAllocatorIS2_EEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN9UIManager8FindByIDEi(ptr noundef nonnull align 8 dereferenceable(248) %0, i32 noundef %1) unnamed_addr #2 align 2 {
  %3 = tail call noundef ptr @_ZN9UIElement8FindByIDEi(ptr noundef nonnull align 8 dereferenceable(144) %0, i32 noundef %1)
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %4, label %.thread

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 160
  %6 = tail call noundef i64 @_ZNK3JPH5ArrayINS0_IP9UIElementNS_12STLAllocatorIS2_EEEENS3_IS5_EEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %5)
  %7 = trunc i64 %6 to i32
  %8 = icmp slt i32 %7, 1
  br i1 %8, label %.thread, label %.preheader.preheader

.preheader.preheader:                             ; preds = %4
  %9 = and i64 %6, 2147483647
  br label %.preheader

.loopexit:                                        ; preds = %14, %.preheader
  %10 = icmp slt i64 %indvars.iv34, 2
  br i1 %10, label %.thread, label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %.loopexit
  %indvars.iv34 = phi i64 [ %9, %.preheader.preheader ], [ %indvars.iv.next35, %.loopexit ]
  %indvars.iv.next35 = add nsw i64 %indvars.iv34, -1
  %11 = tail call noundef nonnull align 8 dereferenceable(24) ptr @_ZN3JPH5ArrayINS0_IP9UIElementNS_12STLAllocatorIS2_EEEENS3_IS5_EEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %5, i64 noundef %indvars.iv.next35)
  %12 = tail call noundef i64 @_ZNK3JPH5ArrayIP9UIElementNS_12STLAllocatorIS2_EEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %11)
  %13 = trunc i64 %12 to i32
  %.not2427 = icmp sgt i32 %13, 0
  br i1 %.not2427, label %.lr.ph, label %.loopexit

14:                                               ; preds = %.lr.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %15 = tail call noundef nonnull align 8 dereferenceable(24) ptr @_ZN3JPH5ArrayINS0_IP9UIElementNS_12STLAllocatorIS2_EEEENS3_IS5_EEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %5, i64 noundef %indvars.iv.next35)
  %16 = tail call noundef i64 @_ZNK3JPH5ArrayIP9UIElementNS_12STLAllocatorIS2_EEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %15)
  %sext = shl i64 %16, 32
  %17 = ashr exact i64 %sext, 32
  %.not24 = icmp slt i64 %indvars.iv.next, %17
  br i1 %.not24, label %.lr.ph, label %.loopexit, !llvm.loop !5

.lr.ph:                                           ; preds = %.preheader, %14
  %indvars.iv = phi i64 [ %indvars.iv.next, %14 ], [ 0, %.preheader ]
  %18 = tail call noundef nonnull align 8 dereferenceable(24) ptr @_ZN3JPH5ArrayINS0_IP9UIElementNS_12STLAllocatorIS2_EEEENS3_IS5_EEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %5, i64 noundef %indvars.iv.next35)
  %19 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN3JPH5ArrayIP9UIElementNS_12STLAllocatorIS2_EEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %18, i64 noundef %indvars.iv)
  %20 = load ptr, ptr %19, align 8, !tbaa !7
  %21 = load ptr, ptr %20, align 8, !tbaa !11
  %22 = getelementptr inbounds i8, ptr %21, i64 64
  %23 = load ptr, ptr %22, align 8
  %24 = tail call noundef ptr %23(ptr noundef nonnull align 8 dereferenceable(144) %20, i32 noundef %1)
  %.not23 = icmp eq ptr %24, null
  br i1 %.not23, label %14, label %.thread

.thread:                                          ; preds = %.loopexit, %.lr.ph, %4, %2
  %.3 = phi ptr [ %3, %2 ], [ null, %4 ], [ %24, %.lr.ph ], [ null, %.loopexit ]
  ret ptr %.3
}

declare noundef ptr @_ZN9UIElement8FindByIDEi(ptr noundef nonnull align 8 dereferenceable(144), i32 noundef) unnamed_addr #3

attributes #0 = { 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 #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 = { "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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!12, !12, i64 0}
!12 = !{!"vtable pointer", !10, i64 0}


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