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

; 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"

%"struct.JPH::AssertLastParam" = type { i8 }
%"class.UIElement::Size" = type { i32, i32 }

@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [83 x i8], align 1

; 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 noundef i32 @_ZNK9UIElement4Size7GetSizeEPKS_MS_KFivE(ptr noundef nonnull align 4 dereferenceable(8) %0, ptr noundef %1, i64 %2, i64 %3) #1 align 2 {
  %5 = alloca i32, align 4
  %6 = alloca { i64, i64 }, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca { i64, i64 }, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca %"struct.JPH::AssertLastParam", align 1
  %13 = getelementptr inbounds { i64, i64 }, ptr %6, i32 0, i32 0
  store i64 %2, ptr %13, align 8
  %14 = getelementptr inbounds { i64, i64 }, ptr %6, i32 0, i32 1
  store i64 %3, ptr %14, align 8
  %15 = load { i64, i64 }, ptr %6, align 8, !tbaa !5
  store ptr %0, ptr %7, align 8, !tbaa !8
  store ptr %1, ptr %8, align 8, !tbaa !8
  store { i64, i64 } %15, ptr %9, align 8, !tbaa !5
  %16 = load ptr, ptr %7, align 8
  %17 = getelementptr inbounds %"class.UIElement::Size", ptr %16, i32 0, i32 1
  %18 = load i32, ptr %17, align 4, !tbaa !10
  switch i32 %18, label %51 [
    i32 0, label %19
    i32 1, label %22
  ]

19:                                               ; preds = %4
  %20 = getelementptr inbounds %"class.UIElement::Size", ptr %16, i32 0, i32 0
  %21 = load i32, ptr %20, align 4, !tbaa !14
  store i32 %21, ptr %5, align 4
  br label %57

22:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %23 = load ptr, ptr %8, align 8, !tbaa !8
  %24 = call noundef ptr @_ZNK9UIElement9GetParentEv(ptr noundef nonnull align 8 dereferenceable(144) %23)
  store ptr %24, ptr %10, align 8, !tbaa !8
  %25 = load ptr, ptr %10, align 8, !tbaa !8
  %26 = icmp ne ptr %25, null
  br i1 %26, label %27, label %49

27:                                               ; preds = %22
  %28 = getelementptr inbounds %"class.UIElement::Size", ptr %16, i32 0, i32 0
  %29 = load i32, ptr %28, align 4, !tbaa !14
  %30 = load ptr, ptr %10, align 8, !tbaa !8
  %31 = load { i64, i64 }, ptr %9, align 8, !tbaa !5
  %32 = extractvalue { i64, i64 } %31, 1
  %33 = getelementptr inbounds i8, ptr %30, i64 %32
  %34 = extractvalue { i64, i64 } %31, 0
  %35 = and i64 %34, 1
  %36 = icmp ne i64 %35, 0
  br i1 %36, label %37, label %42

37:                                               ; preds = %27
  %38 = load ptr, ptr %33, align 8, !tbaa !15
  %39 = sub i64 %34, 1
  %40 = getelementptr i8, ptr %38, i64 %39, !nosanitize !17
  %41 = load ptr, ptr %40, align 8, !nosanitize !17
  br label %44

42:                                               ; preds = %27
  %43 = inttoptr i64 %34 to ptr
  br label %44

44:                                               ; preds = %42, %37
  %45 = phi ptr [ %41, %37 ], [ %43, %42 ]
  %46 = call noundef i32 %45(ptr noundef nonnull align 8 dereferenceable(144) %33)
  %47 = mul nsw i32 %29, %46
  %48 = sdiv i32 %47, 100
  store i32 %48, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %50

49:                                               ; preds = %22
  store i32 0, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %50

50:                                               ; preds = %49, %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %57

51:                                               ; preds = %4
  br label %52

52:                                               ; preds = %51
  %53 = call noundef zeroext i1 @_ZN3JPH23AssertFailedParamHelperEPKcS1_jNS_15AssertLastParamE(ptr noundef @.str.1, ptr noundef @.str.2, i32 noundef 260)
  br i1 %53, label %54, label %55

54:                                               ; preds = %52
  call void asm sideeffect "int $$0x3", "~{dirflag},~{fpsr},~{flags}"() #4, !srcloc !18
  br label %55

55:                                               ; preds = %54, %52
  br label %56

56:                                               ; preds = %55
  store i32 0, ptr %5, align 4
  br label %57

57:                                               ; preds = %56, %50, %19
  %58 = load i32, ptr %5, align 4
  ret i32 %58
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN3JPH23AssertFailedParamHelperEPKcS1_jNS_15AssertLastParamE(ptr noundef, ptr noundef, i32 noundef) #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 = { 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 #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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = !{!11, !13, i64 4}
!11 = !{!"_ZTSN9UIElement4SizeE", !12, i64 0, !13, i64 4}
!12 = !{!"int", !6, i64 0}
!13 = !{!"_ZTSN9UIElement6EUnitsE", !6, i64 0}
!14 = !{!11, !12, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"vtable pointer", !7, i64 0}
!17 = !{}
!18 = !{i64 2157815925}


; 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"

@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [83 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZNK9UIElement4Size7GetSizeEPKS_MS_KFivE(ptr nocapture noundef nonnull readonly align 4 dereferenceable(8) %0, ptr noundef %1, i64 %2, i64 %3) local_unnamed_addr #0 align 2 {
  %5 = getelementptr inbounds i8, ptr %0, i64 4
  %6 = load i32, ptr %5, align 4, !tbaa !5
  switch i32 %6, label %27 [
    i32 0, label %7
    i32 1, label %9
  ]

7:                                                ; preds = %4
  %8 = load i32, ptr %0, align 4, !tbaa !11
  br label %30

9:                                                ; preds = %4
  %10 = tail call noundef ptr @_ZNK9UIElement9GetParentEv(ptr noundef nonnull align 8 dereferenceable(144) %1)
  %.not = icmp eq ptr %10, null
  br i1 %.not, label %30, label %11

11:                                               ; preds = %9
  %12 = load i32, ptr %0, align 4, !tbaa !11
  %13 = getelementptr inbounds i8, ptr %10, i64 %3
  %14 = and i64 %2, 1
  %.not11 = icmp eq i64 %14, 0
  br i1 %.not11, label %20, label %15

15:                                               ; preds = %11
  %16 = load ptr, ptr %13, align 8, !tbaa !12
  %17 = getelementptr i8, ptr %16, i64 %2
  %18 = getelementptr i8, ptr %17, i64 -1
  %19 = load ptr, ptr %18, align 8, !nosanitize !14
  br label %22

20:                                               ; preds = %11
  %21 = inttoptr i64 %2 to ptr
  br label %22

22:                                               ; preds = %20, %15
  %23 = phi ptr [ %19, %15 ], [ %21, %20 ]
  %24 = tail call noundef i32 %23(ptr noundef nonnull align 8 dereferenceable(144) %13)
  %25 = mul nsw i32 %24, %12
  %26 = sdiv i32 %25, 100
  br label %30

27:                                               ; preds = %4
  %28 = tail call noundef zeroext i1 @_ZN3JPH23AssertFailedParamHelperEPKcS1_jNS_15AssertLastParamE(ptr noundef nonnull @.str.1, ptr noundef nonnull @.str.2, i32 noundef 260)
  br i1 %28, label %29, label %30

29:                                               ; preds = %27
  tail call void asm sideeffect "int $$0x3", "~{dirflag},~{fpsr},~{flags}"() #3, !srcloc !15
  br label %30

30:                                               ; preds = %29, %27, %22, %9, %7
  %.1 = phi i32 [ %8, %7 ], [ %26, %22 ], [ 0, %9 ], [ 0, %27 ], [ 0, %29 ]
  ret i32 %.1
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN3JPH23AssertFailedParamHelperEPKcS1_jNS_15AssertLastParamE(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #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 = { 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 = { 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, !10, i64 4}
!6 = !{!"_ZTSN9UIElement4SizeE", !7, i64 0, !10, i64 4}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSN9UIElement6EUnitsE", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"vtable pointer", !9, i64 0}
!14 = !{}
!15 = !{i64 2157815925}


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