; LLVM IR from jrouwe/JoltPhysics :: TestFramework/UI/UISlider.ll (ZN8UISlider9MouseDownEii)

; 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.UISlider = type <{ %class.UIElement, float, float, float, float, ptr, ptr, ptr, i32, [4 x i8], %class.UITexturedQuad, %class.UITexturedQuad, %"class.std::function", i32, [4 x i8] }>
%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.UITexturedQuad = type { %"class.JPH::RefConst", i32, i32, i32, i32, i32, i32, i32, i32 }
%"class.JPH::RefConst" = 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: mustprogress uwtable
declare dso_local void @_ZNK8UISlider14GetSliderRangeERiS0_(ptr noundef nonnull align 8 dereferenceable(308), ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK8UISlider13GetThumbStartEii(ptr noundef nonnull align 8 dereferenceable(308), i32 noundef, i32 noundef) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN8UISlider9MouseDownEii(ptr noundef nonnull align 8 dereferenceable(308) %0, i32 noundef %1, i32 noundef %2) unnamed_addr #1 align 2 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  %12 = load ptr, ptr %5, align 8
  %13 = load i32, ptr %6, align 4, !tbaa !9
  %14 = load i32, ptr %7, align 4, !tbaa !9
  %15 = call noundef zeroext i1 @_ZNK9UIElement8ContainsEii(ptr noundef nonnull align 8 dereferenceable(144) %12, i32 noundef %13, i32 noundef %14)
  br i1 %15, label %16, label %40

16:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  call void @_ZNK8UISlider14GetSliderRangeERiS0_(ptr noundef nonnull align 8 dereferenceable(308) %12, ptr noundef nonnull align 4 dereferenceable(4) %8, ptr noundef nonnull align 4 dereferenceable(4) %9)
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %17 = load i32, ptr %8, align 4, !tbaa !9
  %18 = load i32, ptr %9, align 4, !tbaa !9
  %19 = call noundef i32 @_ZNK8UISlider13GetThumbStartEii(ptr noundef nonnull align 8 dereferenceable(308) %12, i32 noundef %17, i32 noundef %18)
  store i32 %19, ptr %10, align 4, !tbaa !9
  %20 = load i32, ptr %6, align 4, !tbaa !9
  %21 = load i32, ptr %10, align 4, !tbaa !9
  %22 = icmp sge i32 %20, %21
  br i1 %22, label %23, label %36

23:                                               ; preds = %16
  %24 = load i32, ptr %6, align 4, !tbaa !9
  %25 = load i32, ptr %10, align 4, !tbaa !9
  %26 = getelementptr inbounds %class.UISlider, ptr %12, i32 0, i32 11
  %27 = getelementptr inbounds %class.UITexturedQuad, ptr %26, i32 0, i32 3
  %28 = load i32, ptr %27, align 8, !tbaa !11
  %29 = add nsw i32 %25, %28
  %30 = icmp slt i32 %24, %29
  br i1 %30, label %31, label %36

31:                                               ; preds = %23
  %32 = load i32, ptr %6, align 4, !tbaa !9
  %33 = load i32, ptr %10, align 4, !tbaa !9
  %34 = sub nsw i32 %32, %33
  %35 = getelementptr inbounds %class.UISlider, ptr %12, i32 0, i32 13
  store i32 %34, ptr %35, align 8, !tbaa !28
  store i1 true, ptr %4, align 1
  store i32 1, ptr %11, align 4
  br label %37

36:                                               ; preds = %23, %16
  store i32 0, ptr %11, align 4
  br label %37

37:                                               ; preds = %36, %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %38 = load i32, ptr %11, align 4
  switch i32 %38, label %46 [
    i32 0, label %39
    i32 1, label %44
  ]

39:                                               ; preds = %37
  br label %40

40:                                               ; preds = %39, %3
  %41 = load i32, ptr %6, align 4, !tbaa !9
  %42 = load i32, ptr %7, align 4, !tbaa !9
  %43 = call noundef zeroext i1 @_ZN9UIElement9MouseDownEii(ptr noundef nonnull align 8 dereferenceable(144) %12, i32 noundef %41, i32 noundef %42)
  store i1 %43, ptr %4, align 1
  br label %44

44:                                               ; preds = %40, %37
  %45 = load i1, ptr %4, align 1
  ret i1 %45

46:                                               ; preds = %37
  unreachable
}

declare noundef zeroext i1 @_ZNK9UIElement8ContainsEii(ptr noundef nonnull align 8 dereferenceable(144), i32 noundef, i32 noundef) #3

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

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 = { 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 = { "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 248}
!12 = !{!"_ZTS8UISlider", !13, i64 0, !23, i64 144, !23, i64 148, !23, i64 152, !23, i64 156, !6, i64 160, !6, i64 168, !6, i64 176, !10, i64 184, !24, i64 192, !24, i64 232, !26, i64 272, !10, i64 304}
!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 = !{!"float", !7, i64 0}
!24 = !{!"_ZTS14UITexturedQuad", !25, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36}
!25 = !{!"_ZTSN3JPH8RefConstI7TextureEE", !6, i64 0}
!26 = !{!"_ZTSSt8functionIFvfEE", !27, i64 0, !6, i64 24}
!27 = !{!"_ZTSSt14_Function_base", !7, i64 0, !6, i64 16}
!28 = !{!12, !10, i64 304}


; 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress 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 void @_ZNK8UISlider14GetSliderRangeERiS0_(ptr noundef nonnull align 8 dereferenceable(308), ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK8UISlider13GetThumbStartEii(ptr noundef nonnull align 8 dereferenceable(308), i32 noundef, i32 noundef) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN8UISlider9MouseDownEii(ptr noundef nonnull align 8 dereferenceable(308) %0, i32 noundef %1, i32 noundef %2) unnamed_addr #1 align 2 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = tail call noundef zeroext i1 @_ZNK9UIElement8ContainsEii(ptr noundef nonnull align 8 dereferenceable(144) %0, i32 noundef %1, i32 noundef %2)
  br i1 %6, label %7, label %19

7:                                                ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #4
  call void @_ZNK8UISlider14GetSliderRangeERiS0_(ptr noundef nonnull align 8 dereferenceable(308) %0, ptr noundef nonnull align 4 dereferenceable(4) %4, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %8 = load i32, ptr %4, align 4, !tbaa !5
  %9 = load i32, ptr %5, align 4, !tbaa !5
  %10 = call noundef i32 @_ZNK8UISlider13GetThumbStartEii(ptr noundef nonnull align 8 dereferenceable(308) %0, i32 noundef %8, i32 noundef %9)
  %.not = icmp sgt i32 %10, %1
  br i1 %.not, label %.thread, label %11

11:                                               ; preds = %7
  %12 = getelementptr inbounds i8, ptr %0, i64 248
  %13 = load i32, ptr %12, align 8, !tbaa !9
  %14 = add nsw i32 %13, %10
  %15 = icmp sgt i32 %14, %1
  br i1 %15, label %16, label %.thread

.thread:                                          ; preds = %11, %7
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #4
  br label %19

16:                                               ; preds = %11
  %17 = sub nsw i32 %1, %10
  %18 = getelementptr inbounds i8, ptr %0, i64 304
  store i32 %17, ptr %18, align 8, !tbaa !27
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #4
  br label %21

19:                                               ; preds = %.thread, %3
  %20 = call noundef zeroext i1 @_ZN9UIElement9MouseDownEii(ptr noundef nonnull align 8 dereferenceable(144) %0, i32 noundef %1, i32 noundef %2)
  br label %21

21:                                               ; preds = %16, %19
  %.1 = phi i1 [ true, %16 ], [ %20, %19 ]
  ret i1 %.1
}

declare noundef zeroext i1 @_ZNK9UIElement8ContainsEii(ptr noundef nonnull align 8 dereferenceable(144), i32 noundef, i32 noundef) local_unnamed_addr #3

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

attributes #0 = { mustprogress 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 = { 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 = { "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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 248}
!10 = !{!"_ZTS8UISlider", !11, i64 0, !22, i64 144, !22, i64 148, !22, i64 152, !22, i64 156, !13, i64 160, !13, i64 168, !13, i64 176, !6, i64 184, !23, i64 192, !23, i64 232, !25, i64 272, !6, i64 304}
!11 = !{!"_ZTS9UIElement", !12, i64 0, !6, i64 8, !13, i64 16, !14, i64 24, !16, i64 48, !16, i64 60, !18, i64 72, !18, i64 80, !18, i64 88, !18, i64 96, !20, i64 104, !20, i64 105, !20, i64 106, !20, i64 107, !20, i64 108, !20, i64 109, !20, i64 110, !21, i64 112, !13, i64 136}
!12 = !{!"_ZTS15UIEventListener"}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!"_ZTSN3JPH5ArrayIP9UIElementNS_12STLAllocatorIS2_EEEE", !15, i64 0, !15, i64 8, !13, i64 16}
!15 = !{!"long", !7, i64 0}
!16 = !{!"_ZTSN9UIElement8PositionE", !17, i64 0, !18, i64 4}
!17 = !{!"_ZTSN9UIElement10EAlignmentE", !7, i64 0}
!18 = !{!"_ZTSN9UIElement4SizeE", !6, i64 0, !19, i64 4}
!19 = !{!"_ZTSN9UIElement6EUnitsE", !7, i64 0}
!20 = !{!"bool", !7, i64 0}
!21 = !{!"_ZTSN3JPH5ArrayIP11UIAnimationNS_12STLAllocatorIS2_EEEE", !15, i64 0, !15, i64 8, !13, i64 16}
!22 = !{!"float", !7, i64 0}
!23 = !{!"_ZTS14UITexturedQuad", !24, i64 0, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36}
!24 = !{!"_ZTSN3JPH8RefConstI7TextureEE", !13, i64 0}
!25 = !{!"_ZTSSt8functionIFvfEE", !26, i64 0, !13, i64 24}
!26 = !{!"_ZTSSt14_Function_base", !7, i64 0, !13, i64 16}
!27 = !{!10, !6, i64 304}


; Effective O3 passes: GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass