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

; 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 noundef zeroext i1 @_ZN7cascadb3Msg8write_toERNS_11BlockWriterE(ptr noundef nonnull align 8 dereferenceable(40), ptr noundef nonnull align 8 dereferenceable(16)) #1 align 2

; 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

; 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 uwtable
define dso_local noundef zeroext i1 @_ZN7cascadb6MsgBuf8write_toERNS_11BlockWriterE(ptr noundef nonnull align 8 dereferenceable(104) %0, ptr noundef nonnull align 8 dereferenceable(16) %1) #1 align 2 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca %"class.cascadb::FastVector<cascadb::Msg>::Iterator", align 8
  %7 = alloca %"class.cascadb::FastVector<cascadb::Msg>::Iterator", align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = getelementptr inbounds %"class.cascadb::MsgBuf", ptr %9, i32 0, i32 2
  %12 = call noundef i64 @_ZNK7cascadb10FastVectorINS_3MsgELi32EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %11)
  %13 = trunc i64 %12 to i32
  %14 = call noundef zeroext i1 @_ZN7cascadb11BlockWriter11writeUInt32Ej(ptr noundef nonnull align 8 dereferenceable(16) %10, i32 noundef %13)
  br i1 %14, label %16, label %15

15:                                               ; preds = %2
  store i1 false, ptr %3, align 1
  br label %33

16:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 24, ptr %6) #3
  %17 = getelementptr inbounds %"class.cascadb::MsgBuf", ptr %9, i32 0, i32 2
  call void @_ZN7cascadb10FastVectorINS_3MsgELi32EE5beginEv(ptr dead_on_unwind writable sret(%"class.cascadb::FastVector<cascadb::Msg>::Iterator") align 8 %6, ptr noundef nonnull align 8 dereferenceable(32) %17)
  br label %18

18:                                               ; preds = %28, %16
  call void @llvm.lifetime.start.p0(i64 24, ptr %7) #3
  %19 = getelementptr inbounds %"class.cascadb::MsgBuf", ptr %9, i32 0, i32 2
  call void @_ZN7cascadb10FastVectorINS_3MsgELi32EE3endEv(ptr dead_on_unwind writable sret(%"class.cascadb::FastVector<cascadb::Msg>::Iterator") align 8 %7, ptr noundef nonnull align 8 dereferenceable(32) %19)
  %20 = call noundef zeroext i1 @_ZNK7cascadb10FastVectorINS_3MsgELi32EE8IteratorneERKS3_(ptr noundef nonnull align 8 dereferenceable(24) %6, ptr noundef nonnull align 8 dereferenceable(24) %7)
  call void @llvm.lifetime.end.p0(i64 24, ptr %7) #3
  br i1 %20, label %22, label %21

21:                                               ; preds = %18
  store i32 2, ptr %8, align 4
  br label %30

22:                                               ; preds = %18
  %23 = call noundef ptr @_ZN7cascadb10FastVectorINS_3MsgELi32EE8IteratorptEv(ptr noundef nonnull align 8 dereferenceable(24) %6)
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = call noundef zeroext i1 @_ZN7cascadb3Msg8write_toERNS_11BlockWriterE(ptr noundef nonnull align 8 dereferenceable(40) %23, ptr noundef nonnull align 8 dereferenceable(16) %24)
  br i1 %25, label %27, label %26

26:                                               ; preds = %22
  store i1 false, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %30

27:                                               ; preds = %22
  br label %28

28:                                               ; preds = %27
  %29 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZN7cascadb10FastVectorINS_3MsgELi32EE8IteratorppEi(ptr noundef nonnull align 8 dereferenceable(24) %6, i32 noundef 0)
  br label %18, !llvm.loop !9

30:                                               ; preds = %26, %21
  call void @llvm.lifetime.end.p0(i64 24, ptr %6) #3
  %31 = load i32, ptr %8, align 4
  switch i32 %31, label %35 [
    i32 2, label %32
    i32 1, label %33
  ]

32:                                               ; preds = %30
  store i1 true, ptr %3, align 1
  br label %33

33:                                               ; preds = %32, %30, %15
  %34 = load i1, ptr %3, align 1
  ret i1 %34

35:                                               ; preds = %30
  unreachable
}

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

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

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 = { 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 noundef zeroext i1 @_ZN7cascadb3Msg8write_toERNS_11BlockWriterE(ptr noundef nonnull align 8 dereferenceable(40), ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1 align 2

; 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

; 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 uwtable
define dso_local noundef zeroext i1 @_ZN7cascadb6MsgBuf8write_toERNS_11BlockWriterE(ptr noundef nonnull align 8 dereferenceable(104) %0, ptr noundef nonnull align 8 dereferenceable(16) %1) local_unnamed_addr #1 align 2 {
  %3 = alloca %"class.cascadb::FastVector<cascadb::Msg>::Iterator", align 8
  %4 = alloca %"class.cascadb::FastVector<cascadb::Msg>::Iterator", align 8
  %5 = getelementptr inbounds i8, ptr %0, i64 64
  %6 = tail call noundef i64 @_ZNK7cascadb10FastVectorINS_3MsgELi32EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %5)
  %7 = trunc i64 %6 to i32
  %8 = tail call noundef zeroext i1 @_ZN7cascadb11BlockWriter11writeUInt32Ej(ptr noundef nonnull align 8 dereferenceable(16) %1, i32 noundef %7)
  br i1 %8, label %9, label %16

9:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #3
  call void @_ZN7cascadb10FastVectorINS_3MsgELi32EE5beginEv(ptr dead_on_unwind nonnull writable sret(%"class.cascadb::FastVector<cascadb::Msg>::Iterator") align 8 %3, ptr noundef nonnull align 8 dereferenceable(32) %5)
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %4) #3
  call void @_ZN7cascadb10FastVectorINS_3MsgELi32EE3endEv(ptr dead_on_unwind nonnull writable sret(%"class.cascadb::FastVector<cascadb::Msg>::Iterator") align 8 %4, ptr noundef nonnull align 8 dereferenceable(32) %5)
  %10 = call noundef zeroext i1 @_ZNK7cascadb10FastVectorINS_3MsgELi32EE8IteratorneERKS3_(ptr noundef nonnull align 8 dereferenceable(24) %3, ptr noundef nonnull align 8 dereferenceable(24) %4)
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %4) #3
  br i1 %10, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %9, %13
  %11 = call noundef ptr @_ZN7cascadb10FastVectorINS_3MsgELi32EE8IteratorptEv(ptr noundef nonnull align 8 dereferenceable(24) %3)
  %12 = call noundef zeroext i1 @_ZN7cascadb3Msg8write_toERNS_11BlockWriterE(ptr noundef nonnull align 8 dereferenceable(40) %11, ptr noundef nonnull align 8 dereferenceable(16) %1)
  br i1 %12, label %13, label %._crit_edge

13:                                               ; preds = %.lr.ph
  %14 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZN7cascadb10FastVectorINS_3MsgELi32EE8IteratorppEi(ptr noundef nonnull align 8 dereferenceable(24) %3, i32 noundef 0)
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %4) #3
  call void @_ZN7cascadb10FastVectorINS_3MsgELi32EE3endEv(ptr dead_on_unwind nonnull writable sret(%"class.cascadb::FastVector<cascadb::Msg>::Iterator") align 8 %4, ptr noundef nonnull align 8 dereferenceable(32) %5)
  %15 = call noundef zeroext i1 @_ZNK7cascadb10FastVectorINS_3MsgELi32EE8IteratorneERKS3_(ptr noundef nonnull align 8 dereferenceable(24) %3, ptr noundef nonnull align 8 dereferenceable(24) %4)
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %4) #3
  br i1 %15, label %.lr.ph, label %._crit_edge, !llvm.loop !5

._crit_edge:                                      ; preds = %13, %.lr.ph, %9
  %switch = phi i1 [ true, %9 ], [ %12, %.lr.ph ], [ %12, %13 ]
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #3
  br label %16

16:                                               ; preds = %._crit_edge, %2
  %.1 = phi i1 [ false, %2 ], [ %switch, %._crit_edge ]
  ret i1 %.1
}

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

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

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 = { 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: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass