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

; 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: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) #2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #3

; 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 zeroext i1 @_ZN13Proto_vEBTree6insertEy(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %1) #4 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  %12 = load ptr, ptr %4, align 8
  %13 = getelementptr inbounds %class.Proto_vEBTree, ptr %12, i32 0, i32 0
  %14 = load i64, ptr %13, align 8, !tbaa !11
  %15 = icmp eq i64 %14, 2
  br i1 %15, label %16, label %44

16:                                               ; preds = %2
  %17 = load i64, ptr %5, align 8, !tbaa !9
  %18 = icmp eq i64 %17, 0
  br i1 %18, label %19, label %29

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

23:                                               ; preds = %19
  store i1 false, ptr %3, align 1
  br label %96

24:                                               ; preds = %19
  %25 = getelementptr inbounds %class.Proto_vEBTree, ptr %12, i32 0, i32 3
  store i8 1, ptr %25, align 8, !tbaa !15
  %26 = getelementptr inbounds %class.Proto_vEBTree, ptr %12, i32 0, i32 5
  %27 = load i32, ptr %26, align 4, !tbaa !18
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %26, align 4, !tbaa !18
  store i1 true, ptr %3, align 1
  br label %96

29:                                               ; preds = %16
  %30 = load i64, ptr %5, align 8, !tbaa !9
  %31 = icmp eq i64 %30, 1
  br i1 %31, label %32, label %42

32:                                               ; preds = %29
  %33 = getelementptr inbounds %class.Proto_vEBTree, ptr %12, i32 0, i32 4
  %34 = load i8, ptr %33, align 1, !tbaa !19, !range !16, !noundef !17
  %35 = trunc i8 %34 to i1
  br i1 %35, label %36, label %37

36:                                               ; preds = %32
  store i1 false, ptr %3, align 1
  br label %96

37:                                               ; preds = %32
  %38 = getelementptr inbounds %class.Proto_vEBTree, ptr %12, i32 0, i32 4
  store i8 1, ptr %38, align 1, !tbaa !19
  %39 = getelementptr inbounds %class.Proto_vEBTree, ptr %12, i32 0, i32 5
  %40 = load i32, ptr %39, align 4, !tbaa !18
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %39, align 4, !tbaa !18
  store i1 true, ptr %3, align 1
  br label %96

42:                                               ; preds = %29
  %43 = call ptr @__cxa_allocate_exception(i64 4) #5
  store i32 -1, ptr %43, align 16, !tbaa !20
  call void @__cxa_throw(ptr %43, ptr @_ZTIi, ptr null) #6
  unreachable

44:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %45 = getelementptr inbounds %class.Proto_vEBTree, ptr %12, i32 0, i32 0
  %46 = load i64, ptr %45, align 8, !tbaa !11
  %47 = call noundef double @_ZSt4sqrtIyEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef %46)
  %48 = fptoui double %47 to i64
  store i64 %48, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %49 = load i64, ptr %5, align 8, !tbaa !9
  %50 = load i64, ptr %6, align 8, !tbaa !9
  %51 = udiv i64 %49, %50
  store i64 %51, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %52 = load i64, ptr %5, align 8, !tbaa !9
  %53 = load i64, ptr %6, align 8, !tbaa !9
  %54 = urem i64 %52, %53
  store i64 %54, ptr %8, align 8, !tbaa !9
  %55 = getelementptr inbounds %class.Proto_vEBTree, ptr %12, i32 0, i32 2
  %56 = load ptr, ptr %55, align 8, !tbaa !21
  %57 = load i64, ptr %7, align 8, !tbaa !9
  %58 = getelementptr inbounds ptr, ptr %56, i64 %57
  %59 = load ptr, ptr %58, align 8, !tbaa !5
  %60 = icmp eq ptr %59, null
  br i1 %60, label %61, label %87

61:                                               ; preds = %44
  %62 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 32) #7
  %63 = load i64, ptr %6, align 8, !tbaa !9
  invoke void @_ZN13Proto_vEBTreeC1Ey(ptr noundef nonnull align 8 dereferenceable(32) %62, i64 noundef %63)
          to label %64 unwind label %83

64:                                               ; preds = %61
  %65 = getelementptr inbounds %class.Proto_vEBTree, ptr %12, i32 0, i32 2
  %66 = load ptr, ptr %65, align 8, !tbaa !21
  %67 = load i64, ptr %7, align 8, !tbaa !9
  %68 = getelementptr inbounds ptr, ptr %66, i64 %67
  store ptr %62, ptr %68, align 8, !tbaa !5
  %69 = getelementptr inbounds %class.Proto_vEBTree, ptr %12, i32 0, i32 2
  %70 = load ptr, ptr %69, align 8, !tbaa !21
  %71 = load i64, ptr %7, align 8, !tbaa !9
  %72 = getelementptr inbounds ptr, ptr %70, i64 %71
  %73 = load ptr, ptr %72, align 8, !tbaa !5
  %74 = load i64, ptr %8, align 8, !tbaa !9
  %75 = call noundef zeroext i1 @_ZN13Proto_vEBTree6insertEy(ptr noundef nonnull align 8 dereferenceable(32) %73, i64 noundef %74)
  %76 = getelementptr inbounds %class.Proto_vEBTree, ptr %12, i32 0, i32 5
  %77 = load i32, ptr %76, align 4, !tbaa !18
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %76, align 4, !tbaa !18
  %79 = getelementptr inbounds %class.Proto_vEBTree, ptr %12, i32 0, i32 1
  %80 = load ptr, ptr %79, align 8, !tbaa !22
  %81 = load i64, ptr %7, align 8, !tbaa !9
  %82 = call noundef zeroext i1 @_ZN13Proto_vEBTree6insertEy(ptr noundef nonnull align 8 dereferenceable(32) %80, i64 noundef %81)
  store i1 true, ptr %3, align 1
  store i32 1, ptr %11, align 4
  br label %95

83:                                               ; preds = %61
  %84 = landingpad { ptr, i32 }
          cleanup
  %85 = extractvalue { ptr, i32 } %84, 0
  store ptr %85, ptr %9, align 8
  %86 = extractvalue { ptr, i32 } %84, 1
  store i32 %86, ptr %10, align 4
  call void @_ZdlPvm(ptr noundef %62, i64 noundef 32) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  br label %98

87:                                               ; preds = %44
  %88 = getelementptr inbounds %class.Proto_vEBTree, ptr %12, i32 0, i32 2
  %89 = load ptr, ptr %88, align 8, !tbaa !21
  %90 = load i64, ptr %7, align 8, !tbaa !9
  %91 = getelementptr inbounds ptr, ptr %89, i64 %90
  %92 = load ptr, ptr %91, align 8, !tbaa !5
  %93 = load i64, ptr %8, align 8, !tbaa !9
  %94 = call noundef zeroext i1 @_ZN13Proto_vEBTree6insertEy(ptr noundef nonnull align 8 dereferenceable(32) %92, i64 noundef %93)
  store i1 %94, ptr %3, align 1
  store i32 1, ptr %11, align 4
  br label %95

95:                                               ; preds = %87, %64
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  br label %96

96:                                               ; preds = %95, %37, %36, %24, %23
  %97 = load i1, ptr %3, align 1
  ret i1 %97

98:                                               ; preds = %83
  %99 = load ptr, ptr %9, align 8
  %100 = load i32, ptr %10, align 4
  %101 = insertvalue { ptr, i32 } poison, ptr %99, 0
  %102 = insertvalue { ptr, i32 } %101, i32 %100, 1
  resume { ptr, i32 } %102
}

declare ptr @__cxa_allocate_exception(i64)

declare void @__cxa_throw(ptr, ptr, ptr)

declare void @_ZN13Proto_vEBTreeC1Ey(ptr, i64)

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 = { nobuiltin allocsize(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 = { nobuiltin nounwind "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 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 }
attributes #6 = { noreturn }
attributes #7 = { builtin allocsize(0) }
attributes #8 = { builtin 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 = !{!"long long", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_ZTS13Proto_vEBTree", !10, i64 0, !6, i64 8, !6, i64 16, !13, i64 24, !13, i64 25, !14, i64 28}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!12, !13, i64 24}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = !{!12, !14, i64 28}
!19 = !{!12, !13, i64 25}
!20 = !{!14, !14, i64 0}
!21 = !{!12, !6, i64 16}
!22 = !{!12, !6, i64 8}


; 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

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) local_unnamed_addr #1

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN13Proto_vEBTree6insertEy(ptr nocapture noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %1) local_unnamed_addr #3 align 2 personality ptr @__gxx_personality_v0 {
  br label %tailrecurse.outer

tailrecurse.outer:                                ; preds = %30, %2
  %.tr.ph = phi ptr [ %42, %30 ], [ %0, %2 ]
  %.tr20.ph = phi i64 [ %21, %30 ], [ %1, %2 ]
  %ret.known.tr.ph = phi i1 [ true, %30 ], [ false, %2 ]
  br label %tailrecurse

tailrecurse:                                      ; preds = %tailrecurse.outer, %18
  %.tr = phi ptr [ %26, %18 ], [ %.tr.ph, %tailrecurse.outer ]
  %.tr20 = phi i64 [ %22, %18 ], [ %.tr20.ph, %tailrecurse.outer ]
  %3 = load i64, ptr %.tr, align 8, !tbaa !5
  %4 = icmp eq i64 %3, 2
  br i1 %4, label %5, label %18

5:                                                ; preds = %tailrecurse
  switch i64 %.tr20, label %16 [
    i64 0, label %6
    i64 1, label %11
  ]

6:                                                ; preds = %5
  %7 = getelementptr inbounds i8, ptr %.tr, i64 24
  %8 = load i8, ptr %7, align 8, !tbaa !13, !range !14, !noundef !15
  %9 = trunc nuw i8 %8 to i1
  br i1 %9, label %48, label %10

10:                                               ; preds = %6
  store i8 1, ptr %7, align 8, !tbaa !13
  br label %.sink.split

11:                                               ; preds = %5
  %12 = getelementptr inbounds i8, ptr %.tr, i64 25
  %13 = load i8, ptr %12, align 1, !tbaa !16, !range !14, !noundef !15
  %14 = trunc nuw i8 %13 to i1
  br i1 %14, label %48, label %15

15:                                               ; preds = %11
  store i8 1, ptr %12, align 1, !tbaa !16
  br label %.sink.split

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

18:                                               ; preds = %tailrecurse
  %19 = tail call noundef double @_ZSt4sqrtIyEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef %3)
  %20 = fptoui double %19 to i64
  %21 = udiv i64 %.tr20, %20
  %22 = urem i64 %.tr20, %20
  %23 = getelementptr inbounds i8, ptr %.tr, i64 16
  %24 = load ptr, ptr %23, align 8, !tbaa !18
  %25 = getelementptr inbounds ptr, ptr %24, i64 %21
  %26 = load ptr, ptr %25, align 8, !tbaa !19
  %27 = icmp eq ptr %26, null
  br i1 %27, label %28, label %tailrecurse

28:                                               ; preds = %18
  %29 = tail call noalias noundef nonnull dereferenceable(32) ptr @_Znwm(i64 noundef 32) #6
  invoke void @_ZN13Proto_vEBTreeC1Ey(ptr noundef nonnull align 8 dereferenceable(32) %29, i64 noundef %20)
          to label %30 unwind label %43

30:                                               ; preds = %28
  %31 = getelementptr inbounds i8, ptr %.tr, i64 16
  %32 = load ptr, ptr %31, align 8, !tbaa !18
  %33 = getelementptr inbounds ptr, ptr %32, i64 %21
  store ptr %29, ptr %33, align 8, !tbaa !19
  %34 = load ptr, ptr %31, align 8, !tbaa !18
  %35 = getelementptr inbounds ptr, ptr %34, i64 %21
  %36 = load ptr, ptr %35, align 8, !tbaa !19
  %37 = tail call noundef zeroext i1 @_ZN13Proto_vEBTree6insertEy(ptr noundef nonnull align 8 dereferenceable(32) %36, i64 noundef %22)
  %38 = getelementptr inbounds i8, ptr %.tr, i64 28
  %39 = load i32, ptr %38, align 4, !tbaa !20
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %38, align 4, !tbaa !20
  %41 = getelementptr inbounds i8, ptr %.tr, i64 8
  %42 = load ptr, ptr %41, align 8, !tbaa !21
  br label %tailrecurse.outer

43:                                               ; preds = %28
  %44 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZdlPvm(ptr noundef nonnull %29, i64 noundef 32) #7
  resume { ptr, i32 } %44

.sink.split:                                      ; preds = %10, %15
  %45 = getelementptr inbounds i8, ptr %.tr, i64 28
  %46 = load i32, ptr %45, align 4, !tbaa !20
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %45, align 4, !tbaa !20
  br label %48

48:                                               ; preds = %.sink.split, %11, %6
  %.1 = phi i1 [ false, %6 ], [ false, %11 ], [ true, %.sink.split ]
  %current.ret.tr21 = or i1 %ret.known.tr.ph, %.1
  ret i1 %current.ret.tr21
}

declare ptr @__cxa_allocate_exception(i64) local_unnamed_addr

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

declare void @_ZN13Proto_vEBTreeC1Ey(ptr, i64) local_unnamed_addr

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 = { nobuiltin allocsize(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 = { nobuiltin nounwind "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 }
attributes #5 = { noreturn }
attributes #6 = { builtin allocsize(0) }
attributes #7 = { builtin 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, !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 24}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = !{!6, !11, i64 25}
!17 = !{!12, !12, i64 0}
!18 = !{!6, !10, i64 16}
!19 = !{!10, !10, i64 0}
!20 = !{!6, !12, i64 28}
!21 = !{!6, !10, i64 8}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass