; LLVM IR from jrouwe/JoltPhysics :: TestFramework/UI/UIElement.ll (ZN9UIElement7MouseUpEii)

; 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.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 }

; 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 ptr @_ZN3JPH5ArrayIP9UIElementNS_12STLAllocatorIS2_EEE5beginEv(ptr noundef nonnull align 8 dereferenceable(24)) #1 align 2

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN9UIElement7MouseUpEii(ptr noundef nonnull align 8 dereferenceable(144) %0, i32 noundef %1, i32 noundef %2) unnamed_addr #3 align 2 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  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
  %13 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %14 = getelementptr inbounds %class.UIElement, ptr %13, i32 0, i32 3
  store ptr %14, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %15 = load ptr, ptr %8, align 8, !tbaa !5
  %16 = call noundef ptr @_ZN3JPH5ArrayIP9UIElementNS_12STLAllocatorIS2_EEE5beginEv(ptr noundef nonnull align 8 dereferenceable(24) %15)
  store ptr %16, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %17 = load ptr, ptr %8, align 8, !tbaa !5
  %18 = call noundef ptr @_ZN3JPH5ArrayIP9UIElementNS_12STLAllocatorIS2_EEE3endEv(ptr noundef nonnull align 8 dereferenceable(24) %17)
  store ptr %18, ptr %10, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %48, %3
  %20 = load ptr, ptr %9, align 8, !tbaa !5
  %21 = load ptr, ptr %10, align 8, !tbaa !5
  %22 = icmp ne ptr %20, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %19
  store i32 2, ptr %11, align 4
  br label %51

24:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %25 = load ptr, ptr %9, align 8, !tbaa !5
  %26 = load ptr, ptr %25, align 8, !tbaa !5
  store ptr %26, ptr %12, align 8, !tbaa !5
  %27 = load ptr, ptr %12, align 8, !tbaa !5
  %28 = call noundef zeroext i1 @_ZNK9UIElement9IsVisibleEv(ptr noundef nonnull align 8 dereferenceable(144) %27)
  br i1 %28, label %29, label %44

29:                                               ; preds = %24
  %30 = load ptr, ptr %12, align 8, !tbaa !5
  %31 = getelementptr inbounds %class.UIElement, ptr %30, i32 0, i32 14
  %32 = load i8, ptr %31, align 4, !tbaa !11, !range !22, !noundef !23
  %33 = trunc i8 %32 to i1
  br i1 %33, label %44, label %34

34:                                               ; preds = %29
  %35 = load ptr, ptr %12, align 8, !tbaa !5
  %36 = load i32, ptr %6, align 4, !tbaa !9
  %37 = load i32, ptr %7, align 4, !tbaa !9
  %38 = load ptr, ptr %35, align 8, !tbaa !24
  %39 = getelementptr inbounds ptr, ptr %38, i64 12
  %40 = load ptr, ptr %39, align 8
  %41 = call noundef zeroext i1 %40(ptr noundef nonnull align 8 dereferenceable(144) %35, i32 noundef %36, i32 noundef %37)
  br i1 %41, label %42, label %43

42:                                               ; preds = %34
  store i1 true, ptr %4, align 1
  store i32 1, ptr %11, align 4
  br label %45

43:                                               ; preds = %34
  br label %44

44:                                               ; preds = %43, %29, %24
  store i32 0, ptr %11, align 4
  br label %45

45:                                               ; preds = %44, %42
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  %46 = load i32, ptr %11, align 4
  switch i32 %46, label %51 [
    i32 0, label %47
  ]

47:                                               ; preds = %45
  br label %48

48:                                               ; preds = %47
  %49 = load ptr, ptr %9, align 8, !tbaa !5
  %50 = getelementptr inbounds ptr, ptr %49, i32 1
  store ptr %50, ptr %9, align 8, !tbaa !5
  br label %19

51:                                               ; preds = %45, %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %52 = load i32, ptr %11, align 4
  switch i32 %52, label %56 [
    i32 2, label %53
    i32 1, label %54
  ]

53:                                               ; preds = %51
  store i1 false, ptr %4, align 1
  br label %54

54:                                               ; preds = %53, %51
  %55 = load i1, ptr %4, align 1
  ret i1 %55

56:                                               ; preds = %51
  unreachable
}

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 = { 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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !20, i64 108}
!12 = !{!"_ZTS9UIElement", !13, i64 0, !10, i64 8, !6, 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, !6, i64 136}
!13 = !{!"_ZTS15UIEventListener"}
!14 = !{!"_ZTSN3JPH5ArrayIP9UIElementNS_12STLAllocatorIS2_EEEE", !15, i64 0, !15, i64 8, !6, i64 16}
!15 = !{!"long", !7, i64 0}
!16 = !{!"_ZTSN9UIElement8PositionE", !17, i64 0, !18, i64 4}
!17 = !{!"_ZTSN9UIElement10EAlignmentE", !7, i64 0}
!18 = !{!"_ZTSN9UIElement4SizeE", !10, 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, !6, i64 16}
!22 = !{i8 0, i8 2}
!23 = !{}
!24 = !{!25, !25, i64 0}
!25 = !{!"vtable pointer", !8, 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"

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN9UIElement7MouseUpEii(ptr noundef nonnull align 8 dereferenceable(144) %0, i32 noundef %1, i32 noundef %2) unnamed_addr #2 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 24
  %5 = tail call noundef ptr @_ZN3JPH5ArrayIP9UIElementNS_12STLAllocatorIS2_EEE5beginEv(ptr noundef nonnull align 8 dereferenceable(24) %4)
  %6 = tail call noundef ptr @_ZN3JPH5ArrayIP9UIElementNS_12STLAllocatorIS2_EEE3endEv(ptr noundef nonnull align 8 dereferenceable(24) %4)
  %.not17.not = icmp eq ptr %5, %6
  br i1 %.not17.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3, %.critedge
  %.01618 = phi ptr [ %18, %.critedge ], [ %5, %3 ]
  %7 = load ptr, ptr %.01618, align 8, !tbaa !5
  %8 = tail call noundef zeroext i1 @_ZNK9UIElement9IsVisibleEv(ptr noundef nonnull align 8 dereferenceable(144) %7)
  br i1 %8, label %9, label %.critedge

9:                                                ; preds = %.lr.ph
  %10 = getelementptr inbounds i8, ptr %7, i64 108
  %11 = load i8, ptr %10, align 4, !tbaa !9, !range !21, !noundef !22
  %12 = trunc nuw i8 %11 to i1
  br i1 %12, label %.critedge, label %13

13:                                               ; preds = %9
  %14 = load ptr, ptr %7, align 8, !tbaa !23
  %15 = getelementptr inbounds i8, ptr %14, i64 96
  %16 = load ptr, ptr %15, align 8
  %17 = tail call noundef zeroext i1 %16(ptr noundef nonnull align 8 dereferenceable(144) %7, i32 noundef %1, i32 noundef %2)
  br i1 %17, label %._crit_edge, label %.critedge

.critedge:                                        ; preds = %13, %9, %.lr.ph
  %18 = getelementptr inbounds i8, ptr %.01618, i64 8
  %.not.not = icmp eq ptr %18, %6
  br i1 %.not.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.critedge, %13, %3
  %.not.lcssa = phi i1 [ false, %3 ], [ true, %13 ], [ false, %.critedge ]
  ret i1 %.not.lcssa
}

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

!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, !19, i64 108}
!10 = !{!"_ZTS9UIElement", !11, i64 0, !12, i64 8, !6, 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, !6, i64 136}
!11 = !{!"_ZTS15UIEventListener"}
!12 = !{!"int", !7, i64 0}
!13 = !{!"_ZTSN3JPH5ArrayIP9UIElementNS_12STLAllocatorIS2_EEEE", !14, i64 0, !14, i64 8, !6, i64 16}
!14 = !{!"long", !7, i64 0}
!15 = !{!"_ZTSN9UIElement8PositionE", !16, i64 0, !17, i64 4}
!16 = !{!"_ZTSN9UIElement10EAlignmentE", !7, i64 0}
!17 = !{!"_ZTSN9UIElement4SizeE", !12, i64 0, !18, i64 4}
!18 = !{!"_ZTSN9UIElement6EUnitsE", !7, i64 0}
!19 = !{!"bool", !7, i64 0}
!20 = !{!"_ZTSN3JPH5ArrayIP11UIAnimationNS_12STLAllocatorIS2_EEEE", !14, i64 0, !14, i64 8, !6, i64 16}
!21 = !{i8 0, i8 2}
!22 = !{}
!23 = !{!24, !24, i64 0}
!24 = !{!"vtable pointer", !8, i64 0}


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