; LLVM IR from weicao/cascadb :: src/tree/msg.ll (ZN7cascadb6MsgBufD2Ev)

; 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::FastVector<cascadb::Msg>::Iterator" = type { ptr, i64, i64 }
%"class.cascadb::MsgBuf" = type { ptr, %"class.cascadb::RWLock", %"class.cascadb::FastVector", 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::FastVector" = type { %"class.std::vector", i64 }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<std::vector<cascadb::Msg> *, std::allocator<std::vector<cascadb::Msg> *>>::_Vector_impl" }
%"struct.std::_Vector_base<std::vector<cascadb::Msg> *, std::allocator<std::vector<cascadb::Msg> *>>::_Vector_impl" = type { %"struct.std::_Vector_base<std::vector<cascadb::Msg> *, std::allocator<std::vector<cascadb::Msg> *>>::_Vector_impl_data" }
%"struct.std::_Vector_base<std::vector<cascadb::Msg> *, std::allocator<std::vector<cascadb::Msg> *>>::_Vector_impl_data" = type { ptr, ptr, ptr }

; 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 void @_ZN7cascadb3Msg7destroyEv(ptr noundef nonnull align 8 dereferenceable(40)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN7cascadb6MsgBufD2Ev(ptr noundef nonnull align 8 dereferenceable(104) %0) unnamed_addr #2 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca ptr, align 8
  %3 = alloca %"class.cascadb::FastVector<cascadb::Msg>::Iterator", align 8
  %4 = alloca %"class.cascadb::FastVector<cascadb::Msg>::Iterator", align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 24, ptr %3) #5
  %6 = getelementptr inbounds %"class.cascadb::MsgBuf", ptr %5, i32 0, i32 2
  invoke void @_ZN7cascadb10FastVectorINS_3MsgELi32EE5beginEv(ptr dead_on_unwind writable sret(%"class.cascadb::FastVector<cascadb::Msg>::Iterator") align 8 %3, ptr noundef nonnull align 8 dereferenceable(32) %6)
          to label %7 unwind label %26

7:                                                ; preds = %1
  br label %8

8:                                                ; preds = %20, %7
  call void @llvm.lifetime.start.p0(i64 24, ptr %4) #5
  %9 = getelementptr inbounds %"class.cascadb::MsgBuf", ptr %5, i32 0, i32 2
  invoke void @_ZN7cascadb10FastVectorINS_3MsgELi32EE3endEv(ptr dead_on_unwind writable sret(%"class.cascadb::FastVector<cascadb::Msg>::Iterator") align 8 %4, ptr noundef nonnull align 8 dereferenceable(32) %9)
          to label %10 unwind label %26

10:                                               ; preds = %8
  %11 = invoke noundef zeroext i1 @_ZNK7cascadb10FastVectorINS_3MsgELi32EE8IteratorneERKS3_(ptr noundef nonnull align 8 dereferenceable(24) %3, ptr noundef nonnull align 8 dereferenceable(24) %4)
          to label %12 unwind label %26

12:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 24, ptr %4) #5
  br i1 %11, label %14, label %13

13:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 24, ptr %3) #5
  br label %21

14:                                               ; preds = %12
  %15 = invoke noundef ptr @_ZN7cascadb10FastVectorINS_3MsgELi32EE8IteratorptEv(ptr noundef nonnull align 8 dereferenceable(24) %3)
          to label %16 unwind label %26

16:                                               ; preds = %14
  invoke void @_ZN7cascadb3Msg7destroyEv(ptr noundef nonnull align 8 dereferenceable(40) %15)
          to label %17 unwind label %26

17:                                               ; preds = %16
  br label %18

18:                                               ; preds = %17
  %19 = invoke noundef nonnull align 8 dereferenceable(24) ptr @_ZN7cascadb10FastVectorINS_3MsgELi32EE8IteratorppEi(ptr noundef nonnull align 8 dereferenceable(24) %3, i32 noundef 0)
          to label %20 unwind label %26

20:                                               ; preds = %18
  br label %8, !llvm.loop !9

21:                                               ; preds = %13
  %22 = getelementptr inbounds %"class.cascadb::MsgBuf", ptr %5, i32 0, i32 2
  invoke void @_ZN7cascadb10FastVectorINS_3MsgELi32EE5clearEv(ptr noundef nonnull align 8 dereferenceable(32) %22)
          to label %23 unwind label %26

23:                                               ; preds = %21
  %24 = getelementptr inbounds %"class.cascadb::MsgBuf", ptr %5, i32 0, i32 2
  call void @_ZN7cascadb10FastVectorINS_3MsgELi32EED2Ev(ptr noundef nonnull align 8 dereferenceable(32) %24) #5
  %25 = getelementptr inbounds %"class.cascadb::MsgBuf", ptr %5, i32 0, i32 1
  call void @_ZN7cascadb6RWLockD1Ev(ptr noundef nonnull align 8 dereferenceable(56) %25) #5
  ret void

26:                                               ; preds = %21, %18, %16, %14, %10, %8, %1
  %27 = landingpad { ptr, i32 }
          catch ptr null
  %28 = extractvalue { ptr, i32 } %27, 0
  call void @__clang_call_terminate(ptr %28) #6
  unreachable
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7cascadb10FastVectorINS_3MsgELi32EE5beginEv(ptr dead_on_unwind noalias writable sret(%"class.cascadb::FastVector<cascadb::Msg>::Iterator") align 8, ptr noundef nonnull align 8 dereferenceable(32)) #1 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) #3

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZNK7cascadb10FastVectorINS_3MsgELi32EE8IteratorneERKS3_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7cascadb10FastVectorINS_3MsgELi32EE3endEv(ptr dead_on_unwind noalias writable sret(%"class.cascadb::FastVector<cascadb::Msg>::Iterator") align 8, ptr noundef nonnull align 8 dereferenceable(32)) #1 align 2

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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7cascadb10FastVectorINS_3MsgELi32EED2Ev(ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #2 align 2

; Function Attrs: nounwind
declare void @_ZN7cascadb6RWLockD1Ev(ptr noundef nonnull align 8 dereferenceable(56)) unnamed_addr #4

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 = { noinline noreturn nounwind uwtable "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 "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 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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

%"class.cascadb::FastVector<cascadb::Msg>::Iterator" = type { ptr, i64, i64 }

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

; Function Attrs: mustprogress 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 void @_ZN7cascadb3Msg7destroyEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN7cascadb6MsgBufD2Ev(ptr noundef nonnull align 8 dereferenceable(104) %0) unnamed_addr #2 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca %"class.cascadb::FastVector<cascadb::Msg>::Iterator", align 8
  %3 = alloca %"class.cascadb::FastVector<cascadb::Msg>::Iterator", align 8
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %2) #5
  %4 = getelementptr inbounds i8, ptr %0, i64 64
  invoke void @_ZN7cascadb10FastVectorINS_3MsgELi32EE5beginEv(ptr dead_on_unwind nonnull writable sret(%"class.cascadb::FastVector<cascadb::Msg>::Iterator") align 8 %2, ptr noundef nonnull align 8 dereferenceable(32) %4)
          to label %.preheader unwind label %.loopexit.split-lp

.preheader:                                       ; preds = %1, %12
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #5
  invoke void @_ZN7cascadb10FastVectorINS_3MsgELi32EE3endEv(ptr dead_on_unwind nonnull writable sret(%"class.cascadb::FastVector<cascadb::Msg>::Iterator") align 8 %3, ptr noundef nonnull align 8 dereferenceable(32) %4)
          to label %5 unwind label %.loopexit

5:                                                ; preds = %.preheader
  %6 = invoke noundef zeroext i1 @_ZNK7cascadb10FastVectorINS_3MsgELi32EE8IteratorneERKS3_(ptr noundef nonnull align 8 dereferenceable(24) %2, ptr noundef nonnull align 8 dereferenceable(24) %3)
          to label %7 unwind label %.loopexit

7:                                                ; preds = %5
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #5
  br i1 %6, label %10, label %8

8:                                                ; preds = %7
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %2) #5
  call void @_ZN7cascadb10FastVectorINS_3MsgELi32EE5clearEv(ptr noundef nonnull align 8 dereferenceable(32) %4)
  call void @_ZN7cascadb10FastVectorINS_3MsgELi32EED2Ev(ptr noundef nonnull align 8 dereferenceable(32) %4) #5
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  call void @_ZN7cascadb6RWLockD1Ev(ptr noundef nonnull align 8 dereferenceable(56) %9) #5
  ret void

10:                                               ; preds = %7
  %11 = call noundef ptr @_ZN7cascadb10FastVectorINS_3MsgELi32EE8IteratorptEv(ptr noundef nonnull align 8 dereferenceable(24) %2)
  invoke void @_ZN7cascadb3Msg7destroyEv(ptr noundef nonnull align 8 dereferenceable(40) %11)
          to label %12 unwind label %.loopexit

12:                                               ; preds = %10
  %13 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZN7cascadb10FastVectorINS_3MsgELi32EE8IteratorppEi(ptr noundef nonnull align 8 dereferenceable(24) %2, i32 noundef 0)
  br label %.preheader, !llvm.loop !5

.loopexit:                                        ; preds = %.preheader, %5, %10
  %lpad.loopexit = landingpad { ptr, i32 }
          catch ptr null
  br label %14

.loopexit.split-lp:                               ; preds = %1
  %lpad.loopexit.split-lp = landingpad { ptr, i32 }
          catch ptr null
  br label %14

14:                                               ; preds = %.loopexit.split-lp, %.loopexit
  %lpad.phi = phi { ptr, i32 } [ %lpad.loopexit, %.loopexit ], [ %lpad.loopexit.split-lp, %.loopexit.split-lp ]
  %15 = extractvalue { ptr, i32 } %lpad.phi, 0
  call void @__clang_call_terminate(ptr %15) #6
  unreachable
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7cascadb10FastVectorINS_3MsgELi32EE5beginEv(ptr dead_on_unwind noalias writable sret(%"class.cascadb::FastVector<cascadb::Msg>::Iterator") align 8, ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #1 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZNK7cascadb10FastVectorINS_3MsgELi32EE8IteratorneERKS3_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7cascadb10FastVectorINS_3MsgELi32EE3endEv(ptr dead_on_unwind noalias writable sret(%"class.cascadb::FastVector<cascadb::Msg>::Iterator") align 8, ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #1 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(24) ptr @_ZN7cascadb10FastVectorINS_3MsgELi32EE8IteratorppEi(ptr noundef nonnull align 8 dereferenceable(24), i32 noundef) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7cascadb10FastVectorINS_3MsgELi32EE5clearEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7cascadb10FastVectorINS_3MsgELi32EED2Ev(ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #2 align 2

; Function Attrs: nounwind
declare void @_ZN7cascadb6RWLockD1Ev(ptr noundef nonnull align 8 dereferenceable(56)) unnamed_addr #4

attributes #0 = { mustprogress 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 = { noinline noreturn nounwind uwtable "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 "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 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass