; LLVM IR from jrouwe/JoltPhysics :: TestFramework/UI/UIHorizontalStack.ll (ZN17UIHorizontalStack10AutoLayoutEv)

; 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 }
%class.UIHorizontalStack = type <{ %class.UIElement, i32, i8, [3 x i8] }>

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN17UIHorizontalStack10AutoLayoutEv(ptr noundef nonnull align 8 dereferenceable(149) %0) unnamed_addr #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %7 = load ptr, ptr %2, align 8
  call void @_ZN9UIElement10AutoLayoutEv(ptr noundef nonnull align 8 dereferenceable(144) %7)
  %8 = getelementptr inbounds %class.UIElement, ptr %7, i32 0, i32 6
  call void @_ZN9UIElement4Size3SetEiNS_6EUnitsE(ptr noundef nonnull align 4 dereferenceable(8) %8, i32 noundef 0, i32 noundef 0)
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %9 = getelementptr inbounds %class.UIElement, ptr %7, i32 0, i32 3
  store ptr %9, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = call noundef ptr @_ZN3JPH5ArrayIP9UIElementNS_12STLAllocatorIS2_EEE5beginEv(ptr noundef nonnull align 8 dereferenceable(24) %10)
  store ptr %11, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = call noundef ptr @_ZN3JPH5ArrayIP9UIElementNS_12STLAllocatorIS2_EEE3endEv(ptr noundef nonnull align 8 dereferenceable(24) %12)
  store ptr %13, ptr %5, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %43, %1
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = icmp ne ptr %15, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  br label %46

19:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = load ptr, ptr %20, align 8, !tbaa !5
  store ptr %21, ptr %6, align 8, !tbaa !5
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = call noundef zeroext i1 @_ZNK9UIElement9IsVisibleEv(ptr noundef nonnull align 8 dereferenceable(144) %22)
  br i1 %23, label %28, label %24

24:                                               ; preds = %19
  %25 = getelementptr inbounds %class.UIHorizontalStack, ptr %7, i32 0, i32 2
  %26 = load i8, ptr %25, align 4, !tbaa !9, !range !22, !noundef !23
  %27 = trunc i8 %26 to i1
  br i1 %27, label %28, label %42

28:                                               ; preds = %24, %19
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = call noundef i32 @_ZNK9UIElement8GetWidthEv(ptr noundef nonnull align 8 dereferenceable(144) %7)
  call void @_ZN9UIElement12SetRelativeXEiNS_6EUnitsENS_10EAlignmentE(ptr noundef nonnull align 8 dereferenceable(144) %29, i32 noundef %30, i32 noundef 0, i32 noundef 0)
  %31 = getelementptr inbounds %class.UIElement, ptr %7, i32 0, i32 6
  %32 = call noundef i32 @_ZNK9UIElement8GetWidthEv(ptr noundef nonnull align 8 dereferenceable(144) %7)
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = call noundef i32 @_ZNK9UIElement8GetWidthEv(ptr noundef nonnull align 8 dereferenceable(144) %33)
  %35 = add nsw i32 %32, %34
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = call noundef i32 @_ZNK9UIElement15GetPaddingRightEv(ptr noundef nonnull align 8 dereferenceable(144) %36)
  %38 = add nsw i32 %35, %37
  %39 = getelementptr inbounds %class.UIHorizontalStack, ptr %7, i32 0, i32 1
  %40 = load i32, ptr %39, align 8, !tbaa !24
  %41 = add nsw i32 %38, %40
  call void @_ZN9UIElement4Size3SetEiNS_6EUnitsE(ptr noundef nonnull align 4 dereferenceable(8) %31, i32 noundef %41, i32 noundef 0)
  br label %42

42:                                               ; preds = %28, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  br label %43

43:                                               ; preds = %42
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds ptr, ptr %44, i32 1
  store ptr %45, ptr %4, align 8, !tbaa !5
  br label %14

46:                                               ; preds = %18
  ret void
}

declare void @_ZN9UIElement10AutoLayoutEv(ptr noundef nonnull align 8 dereferenceable(144)) unnamed_addr #2

declare void @_ZN9UIElement4Size3SetEiNS_6EUnitsE(ptr noundef nonnull align 4 dereferenceable(8), i32 noundef, i32 noundef) #2

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

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

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZNK9UIElement15GetPaddingRightEv(ptr noundef nonnull align 8 dereferenceable(144)) #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 = { "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 = { 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 #4 = { 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 #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, !20, i64 148}
!10 = !{!"_ZTS17UIHorizontalStack", !11, i64 0, !13, i64 144, !20, i64 148}
!11 = !{!"_ZTS9UIElement", !12, i64 0, !13, 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}
!12 = !{!"_ZTS15UIEventListener"}
!13 = !{!"int", !7, i64 0}
!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", !13, 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 = !{!10, !13, i64 144}


; 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
declare dso_local noundef i32 @_ZNK9UIElement8GetWidthEv(ptr noundef nonnull align 8 dereferenceable(144)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN17UIHorizontalStack10AutoLayoutEv(ptr noundef nonnull align 8 dereferenceable(149) %0) unnamed_addr #0 align 2 {
  tail call void @_ZN9UIElement10AutoLayoutEv(ptr noundef nonnull align 8 dereferenceable(144) %0)
  %2 = getelementptr inbounds i8, ptr %0, i64 72
  tail call void @_ZN9UIElement4Size3SetEiNS_6EUnitsE(ptr noundef nonnull align 4 dereferenceable(8) %2, i32 noundef 0, i32 noundef 0)
  %3 = getelementptr inbounds i8, ptr %0, i64 24
  %4 = tail call noundef ptr @_ZN3JPH5ArrayIP9UIElementNS_12STLAllocatorIS2_EEE5beginEv(ptr noundef nonnull align 8 dereferenceable(24) %3)
  %5 = tail call noundef ptr @_ZN3JPH5ArrayIP9UIElementNS_12STLAllocatorIS2_EEE3endEv(ptr noundef nonnull align 8 dereferenceable(24) %3)
  %.not11 = icmp eq ptr %4, %5
  br i1 %.not11, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 148
  %7 = getelementptr inbounds i8, ptr %0, i64 144
  br label %8

._crit_edge:                                      ; preds = %23, %1
  ret void

8:                                                ; preds = %.lr.ph, %23
  %.012 = phi ptr [ %4, %.lr.ph ], [ %24, %23 ]
  %9 = load ptr, ptr %.012, align 8, !tbaa !5
  %10 = tail call noundef zeroext i1 @_ZNK9UIElement9IsVisibleEv(ptr noundef nonnull align 8 dereferenceable(144) %9)
  br i1 %10, label %14, label %11

11:                                               ; preds = %8
  %12 = load i8, ptr %6, align 4, !tbaa !9, !range !22, !noundef !23
  %13 = trunc nuw i8 %12 to i1
  br i1 %13, label %14, label %23

14:                                               ; preds = %11, %8
  %15 = tail call noundef i32 @_ZNK9UIElement8GetWidthEv(ptr noundef nonnull align 8 dereferenceable(144) %0)
  tail call void @_ZN9UIElement12SetRelativeXEiNS_6EUnitsENS_10EAlignmentE(ptr noundef nonnull align 8 dereferenceable(144) %9, i32 noundef %15, i32 noundef 0, i32 noundef 0)
  %16 = tail call noundef i32 @_ZNK9UIElement8GetWidthEv(ptr noundef nonnull align 8 dereferenceable(144) %0)
  %17 = tail call noundef i32 @_ZNK9UIElement8GetWidthEv(ptr noundef nonnull align 8 dereferenceable(144) %9)
  %18 = add nsw i32 %17, %16
  %19 = tail call noundef i32 @_ZNK9UIElement15GetPaddingRightEv(ptr noundef nonnull align 8 dereferenceable(144) %9)
  %20 = add nsw i32 %18, %19
  %21 = load i32, ptr %7, align 8, !tbaa !24
  %22 = add nsw i32 %20, %21
  tail call void @_ZN9UIElement4Size3SetEiNS_6EUnitsE(ptr noundef nonnull align 4 dereferenceable(8) %2, i32 noundef %22, i32 noundef 0)
  br label %23

23:                                               ; preds = %14, %11
  %24 = getelementptr inbounds i8, ptr %.012, i64 8
  %.not = icmp eq ptr %24, %5
  br i1 %.not, label %._crit_edge, label %8
}

declare void @_ZN9UIElement10AutoLayoutEv(ptr noundef nonnull align 8 dereferenceable(144)) unnamed_addr #1

declare void @_ZN9UIElement4Size3SetEiNS_6EUnitsE(ptr noundef nonnull align 4 dereferenceable(8), i32 noundef, i32 noundef) local_unnamed_addr #1

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

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZNK9UIElement15GetPaddingRightEv(ptr noundef nonnull align 8 dereferenceable(144)) 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 = { "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" }

!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, !20, i64 148}
!10 = !{!"_ZTS17UIHorizontalStack", !11, i64 0, !13, i64 144, !20, i64 148}
!11 = !{!"_ZTS9UIElement", !12, i64 0, !13, 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}
!12 = !{!"_ZTS15UIEventListener"}
!13 = !{!"int", !7, i64 0}
!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", !13, 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 = !{!10, !13, i64 144}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass