; LLVM IR from jrouwe/JoltPhysics :: TestFramework/UI/UIComboBox.ll (ZN10UIComboBox15SetItemInternalEi)

; 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.UIComboBox = type { %class.UIElement, %"class.JPH::Array.5", i32, ptr, ptr, ptr, %"class.std::function" }
%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.2", 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.2" = type { i64, i64, ptr }
%"class.JPH::Array.5" = type { i64, i64, 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: mustprogress uwtable
define dso_local void @_ZN10UIComboBox15SetItemInternalEi(ptr noundef nonnull align 8 dereferenceable(232) %0, i32 noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %6 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %7 = getelementptr inbounds %class.UIComboBox, ptr %6, i32 0, i32 2
  %8 = load i32, ptr %7, align 8, !tbaa !11
  store i32 %8, ptr %5, align 4, !tbaa !9
  %9 = load i32, ptr %4, align 4, !tbaa !9
  %10 = icmp slt i32 %9, 0
  br i1 %10, label %11, label %13

11:                                               ; preds = %2
  %12 = getelementptr inbounds %class.UIComboBox, ptr %6, i32 0, i32 2
  store i32 0, ptr %12, align 8, !tbaa !11
  br label %30

13:                                               ; preds = %2
  %14 = load i32, ptr %4, align 4, !tbaa !9
  %15 = getelementptr inbounds %class.UIComboBox, ptr %6, i32 0, i32 1
  %16 = call noundef i64 @_ZNK3JPH5ArrayINSt7__cxx1112basic_stringIcSt11char_traitsIcENS_12STLAllocatorIcEEEENS5_IS7_EEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %15)
  %17 = trunc i64 %16 to i32
  %18 = sub nsw i32 %17, 1
  %19 = icmp sgt i32 %14, %18
  br i1 %19, label %20, label %26

20:                                               ; preds = %13
  %21 = getelementptr inbounds %class.UIComboBox, ptr %6, i32 0, i32 1
  %22 = call noundef i64 @_ZNK3JPH5ArrayINSt7__cxx1112basic_stringIcSt11char_traitsIcENS_12STLAllocatorIcEEEENS5_IS7_EEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %21)
  %23 = trunc i64 %22 to i32
  %24 = sub nsw i32 %23, 1
  %25 = getelementptr inbounds %class.UIComboBox, ptr %6, i32 0, i32 2
  store i32 %24, ptr %25, align 8, !tbaa !11
  br label %29

26:                                               ; preds = %13
  %27 = load i32, ptr %4, align 4, !tbaa !9
  %28 = getelementptr inbounds %class.UIComboBox, ptr %6, i32 0, i32 2
  store i32 %27, ptr %28, align 8, !tbaa !11
  br label %29

29:                                               ; preds = %26, %20
  br label %30

30:                                               ; preds = %29, %11
  %31 = getelementptr inbounds %class.UIComboBox, ptr %6, i32 0, i32 2
  %32 = load i32, ptr %31, align 8, !tbaa !11
  %33 = load i32, ptr %5, align 4, !tbaa !9
  %34 = icmp ne i32 %32, %33
  br i1 %34, label %35, label %43

35:                                               ; preds = %30
  %36 = getelementptr inbounds %class.UIComboBox, ptr %6, i32 0, i32 6
  %37 = call noundef zeroext i1 @_ZNKSt8functionIFviEEcvbEv(ptr noundef nonnull align 8 dereferenceable(32) %36) #4
  br i1 %37, label %38, label %42

38:                                               ; preds = %35
  %39 = getelementptr inbounds %class.UIComboBox, ptr %6, i32 0, i32 6
  %40 = getelementptr inbounds %class.UIComboBox, ptr %6, i32 0, i32 2
  %41 = load i32, ptr %40, align 8, !tbaa !11
  call void @_ZNKSt8functionIFviEEclEi(ptr noundef nonnull align 8 dereferenceable(32) %39, i32 noundef %41)
  br label %42

42:                                               ; preds = %38, %35
  call void @_ZN10UIComboBox16UpdateStaticTextEv(ptr noundef nonnull align 8 dereferenceable(232) %6)
  br label %43

43:                                               ; preds = %42, %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret void
}

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNKSt8functionIFviEEclEi(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN10UIComboBox16UpdateStaticTextEv(ptr noundef nonnull align 8 dereferenceable(232)) #1 align 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 = { 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 = { 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, !10, i64 168}
!12 = !{!"_ZTS10UIComboBox", !13, i64 0, !23, i64 144, !10, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !24, i64 200}
!13 = !{!"_ZTS9UIElement", !14, i64 0, !10, i64 8, !6, i64 16, !15, i64 24, !17, i64 48, !17, i64 60, !19, i64 72, !19, i64 80, !19, i64 88, !19, i64 96, !21, i64 104, !21, i64 105, !21, i64 106, !21, i64 107, !21, i64 108, !21, i64 109, !21, i64 110, !22, i64 112, !6, i64 136}
!14 = !{!"_ZTS15UIEventListener"}
!15 = !{!"_ZTSN3JPH5ArrayIP9UIElementNS_12STLAllocatorIS2_EEEE", !16, i64 0, !16, i64 8, !6, i64 16}
!16 = !{!"long", !7, i64 0}
!17 = !{!"_ZTSN9UIElement8PositionE", !18, i64 0, !19, i64 4}
!18 = !{!"_ZTSN9UIElement10EAlignmentE", !7, i64 0}
!19 = !{!"_ZTSN9UIElement4SizeE", !10, i64 0, !20, i64 4}
!20 = !{!"_ZTSN9UIElement6EUnitsE", !7, i64 0}
!21 = !{!"bool", !7, i64 0}
!22 = !{!"_ZTSN3JPH5ArrayIP11UIAnimationNS_12STLAllocatorIS2_EEEE", !16, i64 0, !16, i64 8, !6, i64 16}
!23 = !{!"_ZTSN3JPH5ArrayINSt7__cxx1112basic_stringIcSt11char_traitsIcENS_12STLAllocatorIcEEEENS5_IS7_EEEE", !16, i64 0, !16, i64 8, !6, i64 16}
!24 = !{!"_ZTSSt8functionIFviEE", !25, i64 0, !6, i64 24}
!25 = !{!"_ZTSSt14_Function_base", !7, i64 0, !6, i64 16}


; 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 uwtable
define dso_local void @_ZN10UIComboBox15SetItemInternalEi(ptr noundef nonnull align 8 dereferenceable(232) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 168
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = icmp slt i32 %1, 0
  br i1 %5, label %14, label %6

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 144
  %8 = tail call noundef i64 @_ZNK3JPH5ArrayINSt7__cxx1112basic_stringIcSt11char_traitsIcENS_12STLAllocatorIcEEEENS5_IS7_EEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %7)
  %9 = trunc i64 %8 to i32
  %.not = icmp sgt i32 %9, %1
  br i1 %.not, label %14, label %10

10:                                               ; preds = %6
  %11 = tail call noundef i64 @_ZNK3JPH5ArrayINSt7__cxx1112basic_stringIcSt11char_traitsIcENS_12STLAllocatorIcEEEENS5_IS7_EEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %7)
  %12 = trunc i64 %11 to i32
  %13 = add nsw i32 %12, -1
  br label %14

14:                                               ; preds = %6, %2, %10
  %.sink = phi i32 [ %13, %10 ], [ 0, %2 ], [ %1, %6 ]
  store i32 %.sink, ptr %3, align 8, !tbaa !5
  %.not4 = icmp eq i32 %.sink, %4
  br i1 %.not4, label %21, label %15

15:                                               ; preds = %14
  %16 = getelementptr inbounds i8, ptr %0, i64 200
  %17 = tail call noundef zeroext i1 @_ZNKSt8functionIFviEEcvbEv(ptr noundef nonnull align 8 dereferenceable(32) %16) #3
  br i1 %17, label %18, label %20

18:                                               ; preds = %15
  %19 = load i32, ptr %3, align 8, !tbaa !5
  tail call void @_ZNKSt8functionIFviEEclEi(ptr noundef nonnull align 8 dereferenceable(32) %16, i32 noundef %19)
  br label %20

20:                                               ; preds = %18, %15
  tail call void @_ZN10UIComboBox16UpdateStaticTextEv(ptr noundef nonnull align 8 dereferenceable(232) %0)
  br label %21

21:                                               ; preds = %20, %14
  ret void
}

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNKSt8functionIFviEEclEi(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN10UIComboBox16UpdateStaticTextEv(ptr noundef nonnull align 8 dereferenceable(232)) local_unnamed_addr #0 align 2

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" }
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 = { 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, !9, i64 168}
!6 = !{!"_ZTS10UIComboBox", !7, i64 0, !21, i64 144, !9, i64 168, !12, i64 176, !12, i64 184, !12, i64 192, !22, i64 200}
!7 = !{!"_ZTS9UIElement", !8, i64 0, !9, i64 8, !12, i64 16, !13, i64 24, !15, i64 48, !15, i64 60, !17, i64 72, !17, i64 80, !17, i64 88, !17, i64 96, !19, i64 104, !19, i64 105, !19, i64 106, !19, i64 107, !19, i64 108, !19, i64 109, !19, i64 110, !20, i64 112, !12, i64 136}
!8 = !{!"_ZTS15UIEventListener"}
!9 = !{!"int", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{!"any pointer", !10, i64 0}
!13 = !{!"_ZTSN3JPH5ArrayIP9UIElementNS_12STLAllocatorIS2_EEEE", !14, i64 0, !14, i64 8, !12, i64 16}
!14 = !{!"long", !10, i64 0}
!15 = !{!"_ZTSN9UIElement8PositionE", !16, i64 0, !17, i64 4}
!16 = !{!"_ZTSN9UIElement10EAlignmentE", !10, i64 0}
!17 = !{!"_ZTSN9UIElement4SizeE", !9, i64 0, !18, i64 4}
!18 = !{!"_ZTSN9UIElement6EUnitsE", !10, i64 0}
!19 = !{!"bool", !10, i64 0}
!20 = !{!"_ZTSN3JPH5ArrayIP11UIAnimationNS_12STLAllocatorIS2_EEEE", !14, i64 0, !14, i64 8, !12, i64 16}
!21 = !{!"_ZTSN3JPH5ArrayINSt7__cxx1112basic_stringIcSt11char_traitsIcENS_12STLAllocatorIcEEEENS5_IS7_EEEE", !14, i64 0, !14, i64 8, !12, i64 16}
!22 = !{!"_ZTSSt8functionIFviEE", !23, i64 0, !12, i64 24}
!23 = !{!"_ZTSSt14_Function_base", !10, i64 0, !12, i64 16}


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