; LLVM IR from PetarV-/Algorithms :: Data Structures/Proto-vEB Tree.ll (ZN13Proto_vEBTree3maxEv)

; 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.Proto_vEBTree = type { i64, ptr, ptr, i8, i8, i32 }

@_ZTIi = external constant ptr

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt4sqrtIyEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

declare ptr @__cxa_allocate_exception(i64)

declare void @__cxa_throw(ptr, ptr, ptr)

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN13Proto_vEBTree3maxEv(ptr noundef nonnull align 8 dereferenceable(32) %0) #2 align 2 {
  %2 = alloca i64, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8
  %8 = getelementptr inbounds %class.Proto_vEBTree, ptr %7, i32 0, i32 0
  %9 = load i64, ptr %8, align 8, !tbaa !9
  %10 = icmp eq i64 %9, 2
  br i1 %10, label %11, label %23

11:                                               ; preds = %1
  %12 = getelementptr inbounds %class.Proto_vEBTree, ptr %7, i32 0, i32 4
  %13 = load i8, ptr %12, align 1, !tbaa !14, !range !15, !noundef !16
  %14 = trunc i8 %13 to i1
  br i1 %14, label %15, label %16

15:                                               ; preds = %11
  store i64 1, ptr %2, align 8
  br label %42

16:                                               ; preds = %11
  %17 = getelementptr inbounds %class.Proto_vEBTree, ptr %7, i32 0, i32 3
  %18 = load i8, ptr %17, align 8, !tbaa !17, !range !15, !noundef !16
  %19 = trunc i8 %18 to i1
  br i1 %19, label %20, label %21

20:                                               ; preds = %16
  store i64 0, ptr %2, align 8
  br label %42

21:                                               ; preds = %16
  %22 = call ptr @__cxa_allocate_exception(i64 4) #3
  store i32 -1, ptr %22, align 16, !tbaa !18
  call void @__cxa_throw(ptr %22, ptr @_ZTIi, ptr null) #4
  unreachable

23:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %24 = getelementptr inbounds %class.Proto_vEBTree, ptr %7, i32 0, i32 0
  %25 = load i64, ptr %24, align 8, !tbaa !9
  %26 = call noundef double @_ZSt4sqrtIyEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef %25)
  %27 = fptoui double %26 to i64
  store i64 %27, ptr %4, align 8, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %28 = getelementptr inbounds %class.Proto_vEBTree, ptr %7, i32 0, i32 1
  %29 = load ptr, ptr %28, align 8, !tbaa !20
  %30 = call noundef i64 @_ZN13Proto_vEBTree3maxEv(ptr noundef nonnull align 8 dereferenceable(32) %29)
  store i64 %30, ptr %5, align 8, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %31 = getelementptr inbounds %class.Proto_vEBTree, ptr %7, i32 0, i32 2
  %32 = load ptr, ptr %31, align 8, !tbaa !21
  %33 = load i64, ptr %5, align 8, !tbaa !19
  %34 = getelementptr inbounds ptr, ptr %32, i64 %33
  %35 = load ptr, ptr %34, align 8, !tbaa !5
  %36 = call noundef i64 @_ZN13Proto_vEBTree3maxEv(ptr noundef nonnull align 8 dereferenceable(32) %35)
  store i64 %36, ptr %6, align 8, !tbaa !19
  %37 = load i64, ptr %5, align 8, !tbaa !19
  %38 = load i64, ptr %4, align 8, !tbaa !19
  %39 = mul i64 %37, %38
  %40 = load i64, ptr %6, align 8, !tbaa !19
  %41 = add i64 %39, %40
  store i64 %41, ptr %2, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %42

42:                                               ; preds = %23, %20, %15
  %43 = load i64, ptr %2, align 8
  ret i64 %43
}

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 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 }
attributes #4 = { noreturn }

!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, !11, i64 0}
!10 = !{!"_ZTS13Proto_vEBTree", !11, i64 0, !6, i64 8, !6, i64 16, !12, i64 24, !12, i64 25, !13, i64 28}
!11 = !{!"long long", !7, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!10, !12, i64 25}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = !{!10, !12, i64 24}
!18 = !{!13, !13, i64 0}
!19 = !{!11, !11, i64 0}
!20 = !{!10, !6, i64 8}
!21 = !{!10, !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"

@_ZTIi = external constant ptr

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt4sqrtIyEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef) local_unnamed_addr #0

declare ptr @__cxa_allocate_exception(i64) local_unnamed_addr

declare void @__cxa_throw(ptr, ptr, ptr) local_unnamed_addr

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN13Proto_vEBTree3maxEv(ptr nocapture noundef nonnull readonly align 8 dereferenceable(32) %0) local_unnamed_addr #1 align 2 {
  %2 = load i64, ptr %0, align 8, !tbaa !5
  %3 = icmp eq i64 %2, 2
  br i1 %3, label %tailrecurse._crit_edge, label %tailrecurse

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %1
  %accumulator.tr.lcssa = phi i64 [ 0, %1 ], [ %24, %tailrecurse ]
  %.tr.lcssa = phi ptr [ %0, %1 ], [ %22, %tailrecurse ]
  %4 = getelementptr inbounds i8, ptr %.tr.lcssa, i64 25
  %5 = load i8, ptr %4, align 1, !tbaa !13, !range !14, !noundef !15
  %6 = trunc nuw i8 %5 to i1
  br i1 %6, label %27, label %7

7:                                                ; preds = %tailrecurse._crit_edge
  %8 = getelementptr inbounds i8, ptr %.tr.lcssa, i64 24
  %9 = load i8, ptr %8, align 8, !tbaa !16, !range !14, !noundef !15
  %10 = trunc nuw i8 %9 to i1
  br i1 %10, label %27, label %11

11:                                               ; preds = %7
  %12 = tail call ptr @__cxa_allocate_exception(i64 4) #2
  store i32 -1, ptr %12, align 16, !tbaa !17
  tail call void @__cxa_throw(ptr nonnull %12, ptr nonnull @_ZTIi, ptr null) #3
  unreachable

tailrecurse:                                      ; preds = %1, %tailrecurse
  %13 = phi i64 [ %25, %tailrecurse ], [ %2, %1 ]
  %.tr7 = phi ptr [ %22, %tailrecurse ], [ %0, %1 ]
  %accumulator.tr6 = phi i64 [ %24, %tailrecurse ], [ 0, %1 ]
  %14 = tail call noundef double @_ZSt4sqrtIyEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef %13)
  %15 = fptoui double %14 to i64
  %16 = getelementptr inbounds i8, ptr %.tr7, i64 8
  %17 = load ptr, ptr %16, align 8, !tbaa !18
  %18 = tail call noundef i64 @_ZN13Proto_vEBTree3maxEv(ptr noundef nonnull align 8 dereferenceable(32) %17)
  %19 = getelementptr inbounds i8, ptr %.tr7, i64 16
  %20 = load ptr, ptr %19, align 8, !tbaa !19
  %21 = getelementptr inbounds ptr, ptr %20, i64 %18
  %22 = load ptr, ptr %21, align 8, !tbaa !20
  %23 = mul i64 %18, %15
  %24 = add i64 %23, %accumulator.tr6
  %25 = load i64, ptr %22, align 8, !tbaa !5
  %26 = icmp eq i64 %25, 2
  br i1 %26, label %tailrecurse._crit_edge, label %tailrecurse

27:                                               ; preds = %7, %tailrecurse._crit_edge
  %.0 = phi i64 [ 1, %tailrecurse._crit_edge ], [ 0, %7 ]
  %accumulator.ret.tr = add i64 %.0, %accumulator.tr.lcssa
  ret i64 %accumulator.ret.tr
}

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 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 = { nounwind }
attributes #3 = { noreturn }

!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, !7, i64 0}
!6 = !{!"_ZTS13Proto_vEBTree", !7, i64 0, !10, i64 8, !10, i64 16, !11, i64 24, !11, i64 25, !12, i64 28}
!7 = !{!"long long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"bool", !8, i64 0}
!12 = !{!"int", !8, i64 0}
!13 = !{!6, !11, i64 25}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = !{!6, !11, i64 24}
!17 = !{!12, !12, i64 0}
!18 = !{!6, !10, i64 8}
!19 = !{!6, !10, i64 16}
!20 = !{!10, !10, i64 0}


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