; LLVM IR from weicao/cascadb :: src/tree/node.ll (ZN7cascadb9InnerNode6msgbufEi)

; 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.cascadb::InnerNode" = type { %"class.cascadb::DataNode.base", i8, i64, ptr, %"class.cascadb::Slice", i32, i32, i32, i16, %"class.std::vector", i64, i64, i64 }
%"class.cascadb::DataNode.base" = type <{ %"class.cascadb::Node", ptr, i32 }>
%"class.cascadb::Node" = type { ptr, %"class.std::__cxx11::basic_string", i64, %"class.cascadb::Mutex", i8, i8, i8, %struct.timeval, %struct.timeval, i32, i32, %"class.cascadb::RWLock" }
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }
%"class.cascadb::Mutex" = type { i8, %union.pthread_mutex_t }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }
%struct.timeval = type { i64, i64 }
%"class.cascadb::RWLock" = type { %union.pthread_rwlock_t }
%union.pthread_rwlock_t = type { %struct.__pthread_rwlock_arch_t }
%struct.__pthread_rwlock_arch_t = type { i32, i32, i32, i32, i32, i32, i32, i32, i8, [7 x i8], i64, i32 }
%"class.cascadb::Slice" = type <{ ptr, i32, [4 x i8] }>
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<cascadb::Pivot, std::allocator<cascadb::Pivot>>::_Vector_impl" }
%"struct.std::_Vector_base<cascadb::Pivot, std::allocator<cascadb::Pivot>>::_Vector_impl" = type { %"struct.std::_Vector_base<cascadb::Pivot, std::allocator<cascadb::Pivot>>::_Vector_impl_data" }
%"struct.std::_Vector_base<cascadb::Pivot, std::allocator<cascadb::Pivot>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.cascadb::Pivot" = type <{ %"class.cascadb::Slice", %"class.cascadb::Slice", i64, ptr, i32, i32, i32, i16, [2 x i8] }>
%"class.cascadb::DataNode" = type <{ %"class.cascadb::Node", ptr, i32, [4 x i8] }>

@.str.1 = external hidden unnamed_addr constant [66 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [42 x i8], align 1
@__PRETTY_FUNCTION__._ZN7cascadb9InnerNode6msgbufEi = external hidden unnamed_addr constant [40 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [27 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(62) ptr @_ZNSt6vectorIN7cascadb5PivotESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN7cascadb9InnerNode6msgbufEi(ptr noundef nonnull align 8 dereferenceable(312) %0, i32 noundef %1) #3 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %8 = load ptr, ptr %4, align 8
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = icmp sge i32 %9, 0
  br i1 %10, label %11, label %17

11:                                               ; preds = %2
  %12 = load i32, ptr %5, align 4, !tbaa !9
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds %"class.cascadb::InnerNode", ptr %8, i32 0, i32 9
  %15 = call noundef i64 @_ZNKSt6vectorIN7cascadb5PivotESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %14) #4
  %16 = icmp ule i64 %13, %15
  br label %17

17:                                               ; preds = %11, %2
  %18 = phi i1 [ false, %2 ], [ %16, %11 ]
  br i1 %18, label %19, label %20

19:                                               ; preds = %17
  br label %22

20:                                               ; preds = %17
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 195, ptr noundef @__PRETTY_FUNCTION__._ZN7cascadb9InnerNode6msgbufEi) #5
  unreachable

21:                                               ; No predecessors!
  br label %22

22:                                               ; preds = %21, %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %23 = load i32, ptr %5, align 4, !tbaa !9
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %25, label %27

25:                                               ; preds = %22
  %26 = getelementptr inbounds %"class.cascadb::InnerNode", ptr %8, i32 0, i32 3
  br label %34

27:                                               ; preds = %22
  %28 = getelementptr inbounds %"class.cascadb::InnerNode", ptr %8, i32 0, i32 9
  %29 = load i32, ptr %5, align 4, !tbaa !9
  %30 = sub nsw i32 %29, 1
  %31 = sext i32 %30 to i64
  %32 = call noundef nonnull align 8 dereferenceable(62) ptr @_ZNSt6vectorIN7cascadb5PivotESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %28, i64 noundef %31) #4
  %33 = getelementptr inbounds %"class.cascadb::Pivot", ptr %32, i32 0, i32 3
  br label %34

34:                                               ; preds = %27, %25
  %35 = phi ptr [ %26, %25 ], [ %33, %27 ]
  store ptr %35, ptr %6, align 8, !tbaa !5
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = load ptr, ptr %36, align 8, !tbaa !5
  %38 = icmp ne ptr %37, null
  br i1 %38, label %39, label %42

39:                                               ; preds = %34
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = load ptr, ptr %40, align 8, !tbaa !5
  store ptr %41, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %54

42:                                               ; preds = %34
  %43 = getelementptr inbounds %"class.cascadb::DataNode", ptr %8, i32 0, i32 2
  %44 = load i32, ptr %43, align 8, !tbaa !11
  %45 = icmp eq i32 %44, 2
  br i1 %45, label %46, label %47

46:                                               ; preds = %42
  br label %49

47:                                               ; preds = %42
  call void @__assert_fail(ptr noundef @.str.4, ptr noundef @.str.1, i32 noundef 201, ptr noundef @__PRETTY_FUNCTION__._ZN7cascadb9InnerNode6msgbufEi) #5
  unreachable

48:                                               ; No predecessors!
  br label %49

49:                                               ; preds = %48, %46
  %50 = load i32, ptr %5, align 4, !tbaa !9
  %51 = call noundef zeroext i1 @_ZN7cascadb9InnerNode11load_msgbufEi(ptr noundef nonnull align 8 dereferenceable(312) %8, i32 noundef %50)
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = load ptr, ptr %52, align 8, !tbaa !5
  store ptr %53, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %54

54:                                               ; preds = %49, %39
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %55 = load ptr, ptr %3, align 8
  ret ptr %55
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN7cascadb9InnerNode11load_msgbufEi(ptr noundef nonnull align 8 dereferenceable(312), i32 noundef) #3 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn 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 #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 }
attributes #5 = { noreturn 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, !21, i64 208}
!12 = !{!"_ZTSN7cascadb8DataNodeE", !13, i64 0, !6, i64 200, !21, i64 208}
!13 = !{!"_ZTSN7cascadb4NodeE", !14, i64 8, !16, i64 40, !17, i64 48, !18, i64 96, !18, i64 97, !18, i64 98, !19, i64 104, !19, i64 120, !10, i64 136, !10, i64 140, !20, i64 144}
!14 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !15, i64 0, !16, i64 8, !7, i64 16}
!15 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!16 = !{!"long", !7, i64 0}
!17 = !{!"_ZTSN7cascadb5MutexE", !18, i64 0, !7, i64 8}
!18 = !{!"bool", !7, i64 0}
!19 = !{!"_ZTS7timeval", !16, i64 0, !16, i64 8}
!20 = !{!"_ZTSN7cascadb6RWLockE", !7, i64 0}
!21 = !{!"_ZTSN7cascadb10NodeStatusE", !7, 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"

@.str.1 = external hidden unnamed_addr constant [66 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [42 x i8], align 1
@__PRETTY_FUNCTION__._ZN7cascadb9InnerNode6msgbufEi = external hidden unnamed_addr constant [40 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [27 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(62) ptr @_ZNSt6vectorIN7cascadb5PivotESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN7cascadb9InnerNode6msgbufEi(ptr noundef nonnull align 8 dereferenceable(312) %0, i32 noundef %1) local_unnamed_addr #2 align 2 {
  %3 = icmp sgt i32 %1, -1
  br i1 %3, label %4, label %.critedge

4:                                                ; preds = %2
  %5 = zext nneg i32 %1 to i64
  %6 = getelementptr inbounds i8, ptr %0, i64 264
  %7 = tail call noundef i64 @_ZNKSt6vectorIN7cascadb5PivotESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %6) #3
  %.not = icmp ult i64 %7, %5
  br i1 %.not, label %.critedge, label %8

.critedge:                                        ; preds = %2, %4
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i32 noundef 195, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN7cascadb9InnerNode6msgbufEi) #4
  unreachable

8:                                                ; preds = %4
  %9 = icmp eq i32 %1, 0
  br i1 %9, label %10, label %12

10:                                               ; preds = %8
  %11 = getelementptr inbounds i8, ptr %0, i64 224
  br label %17

12:                                               ; preds = %8
  %13 = add nsw i32 %1, -1
  %14 = zext nneg i32 %13 to i64
  %15 = tail call noundef nonnull align 8 dereferenceable(62) ptr @_ZNSt6vectorIN7cascadb5PivotESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %6, i64 noundef %14) #3
  %16 = getelementptr inbounds i8, ptr %15, i64 40
  br label %17

17:                                               ; preds = %12, %10
  %18 = phi ptr [ %11, %10 ], [ %16, %12 ]
  %19 = load ptr, ptr %18, align 8, !tbaa !5
  %.not11 = icmp eq ptr %19, null
  br i1 %.not11, label %20, label %28

20:                                               ; preds = %17
  %21 = getelementptr inbounds i8, ptr %0, i64 208
  %22 = load i32, ptr %21, align 8, !tbaa !9
  %23 = icmp eq i32 %22, 2
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  tail call void @__assert_fail(ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.1, i32 noundef 201, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN7cascadb9InnerNode6msgbufEi) #4
  unreachable

25:                                               ; preds = %20
  %26 = tail call noundef zeroext i1 @_ZN7cascadb9InnerNode11load_msgbufEi(ptr noundef nonnull align 8 dereferenceable(312) %0, i32 noundef %1)
  %27 = load ptr, ptr %18, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %17, %25
  %.0 = phi ptr [ %27, %25 ], [ %19, %17 ]
  ret ptr %.0
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN7cascadb9InnerNode11load_msgbufEi(ptr noundef nonnull align 8 dereferenceable(312), i32 noundef) local_unnamed_addr #2 align 2

attributes #0 = { noreturn 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 #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" }
attributes #3 = { nounwind }
attributes #4 = { noreturn 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 208}
!10 = !{!"_ZTSN7cascadb8DataNodeE", !11, i64 0, !6, i64 200, !20, i64 208}
!11 = !{!"_ZTSN7cascadb4NodeE", !12, i64 8, !14, i64 40, !15, i64 48, !16, i64 96, !16, i64 97, !16, i64 98, !17, i64 104, !17, i64 120, !18, i64 136, !18, i64 140, !19, i64 144}
!12 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !13, i64 0, !14, i64 8, !7, i64 16}
!13 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!"_ZTSN7cascadb5MutexE", !16, i64 0, !7, i64 8}
!16 = !{!"bool", !7, i64 0}
!17 = !{!"_ZTS7timeval", !14, i64 0, !14, i64 8}
!18 = !{!"int", !7, i64 0}
!19 = !{!"_ZTSN7cascadb6RWLockE", !7, i64 0}
!20 = !{!"_ZTSN7cascadb10NodeStatusE", !7, i64 0}


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