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

; 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::Msg" = type { i32, [4 x i8], %"class.cascadb::Slice", %"class.cascadb::Slice" }
%"class.cascadb::Slice" = type <{ ptr, i32, [4 x i8] }>
%"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: mustprogress uwtable
declare dso_local noundef i64 @_ZNK7cascadb3Msg4sizeEv(ptr noundef nonnull align 8 dereferenceable(40)) #0 align 2

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN7cascadb3Msg9read_fromERNS_11BlockReaderE(ptr noundef nonnull align 8 dereferenceable(40), ptr noundef nonnull align 8 dereferenceable(16)) #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN7cascadb6MsgBuf9read_fromERNS_11BlockReaderE(ptr noundef nonnull align 8 dereferenceable(104) %0, ptr noundef nonnull align 8 dereferenceable(16) %1) #0 align 2 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  %9 = alloca %"class.cascadb::Msg", align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %10 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !9
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = call noundef zeroext i1 @_ZN7cascadb11BlockReader10readUInt32EPj(ptr noundef nonnull align 8 dereferenceable(16) %11, ptr noundef %6)
  br i1 %12, label %14, label %13

13:                                               ; preds = %2
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %40

14:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  store i64 0, ptr %8, align 8, !tbaa !11
  br label %15

15:                                               ; preds = %34, %14
  %16 = load i64, ptr %8, align 8, !tbaa !11
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = zext i32 %17 to i64
  %19 = icmp ult i64 %16, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %15
  store i32 2, ptr %7, align 4
  br label %37

21:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 40, ptr %9) #2
  call void @_ZN7cascadb3MsgC2Ev(ptr noundef nonnull align 8 dereferenceable(40) %9)
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = call noundef zeroext i1 @_ZN7cascadb3Msg9read_fromERNS_11BlockReaderE(ptr noundef nonnull align 8 dereferenceable(40) %9, ptr noundef nonnull align 8 dereferenceable(16) %22)
  br i1 %23, label %25, label %24

24:                                               ; preds = %21
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %31

25:                                               ; preds = %21
  %26 = call noundef i64 @_ZNK7cascadb3Msg4sizeEv(ptr noundef nonnull align 8 dereferenceable(40) %9)
  %27 = getelementptr inbounds %"class.cascadb::MsgBuf", ptr %10, i32 0, i32 3
  %28 = load i64, ptr %27, align 8, !tbaa !13
  %29 = add i64 %28, %26
  store i64 %29, ptr %27, align 8, !tbaa !13
  %30 = getelementptr inbounds %"class.cascadb::MsgBuf", ptr %10, i32 0, i32 2
  call void @_ZN7cascadb10FastVectorINS_3MsgELi32EE9push_backERKS1_(ptr noundef nonnull align 8 dereferenceable(32) %30, ptr noundef nonnull align 8 dereferenceable(40) %9)
  store i32 0, ptr %7, align 4
  br label %31

31:                                               ; preds = %25, %24
  call void @llvm.lifetime.end.p0(i64 40, ptr %9) #2
  %32 = load i32, ptr %7, align 4
  switch i32 %32, label %37 [
    i32 0, label %33
  ]

33:                                               ; preds = %31
  br label %34

34:                                               ; preds = %33
  %35 = load i64, ptr %8, align 8, !tbaa !11
  %36 = add i64 %35, 1
  store i64 %36, ptr %8, align 8, !tbaa !11
  br label %15, !llvm.loop !21

37:                                               ; preds = %31, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %38 = load i32, ptr %7, align 4
  switch i32 %38, label %40 [
    i32 2, label %39
  ]

39:                                               ; preds = %37
  store i1 true, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %40

40:                                               ; preds = %39, %37, %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %41 = load i1, ptr %3, align 1
  ret i1 %41
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7cascadb3MsgC2Ev(ptr noundef nonnull align 8 dereferenceable(40)) unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7cascadb10FastVectorINS_3MsgELi32EE9push_backERKS1_(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(40)) #0 align 2

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !12, i64 96}
!14 = !{!"_ZTSN7cascadb6MsgBufE", !6, i64 0, !15, i64 8, !16, i64 64, !12, i64 96}
!15 = !{!"_ZTSN7cascadb6RWLockE", !7, i64 0}
!16 = !{!"_ZTSN7cascadb10FastVectorINS_3MsgELi32EEE", !17, i64 0, !12, i64 24}
!17 = !{!"_ZTSSt6vectorIPS_IN7cascadb3MsgESaIS1_EESaIS4_EE", !18, i64 0}
!18 = !{!"_ZTSSt12_Vector_baseIPSt6vectorIN7cascadb3MsgESaIS2_EESaIS5_EE", !19, i64 0}
!19 = !{!"_ZTSNSt12_Vector_baseIPSt6vectorIN7cascadb3MsgESaIS2_EESaIS5_EE12_Vector_implE", !20, i64 0}
!20 = !{!"_ZTSNSt12_Vector_baseIPSt6vectorIN7cascadb3MsgESaIS2_EESaIS5_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!21 = distinct !{!21, !22}
!22 = !{!"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::Msg" = type { i32, [4 x i8], %"class.cascadb::Slice", %"class.cascadb::Slice" }
%"class.cascadb::Slice" = type <{ ptr, i32, [4 x i8] }>

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZNK7cascadb3Msg4sizeEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #0 align 2

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN7cascadb6MsgBuf9read_fromERNS_11BlockReaderE(ptr noundef nonnull align 8 dereferenceable(104) %0, ptr noundef nonnull align 8 dereferenceable(16) %1) local_unnamed_addr #0 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca %"class.cascadb::Msg", align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #2
  store i32 0, ptr %3, align 4, !tbaa !5
  %5 = call noundef zeroext i1 @_ZN7cascadb11BlockReader10readUInt32EPj(ptr noundef nonnull align 8 dereferenceable(16) %1, ptr noundef nonnull %3)
  br i1 %5, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %2
  %6 = load i32, ptr %3, align 4, !tbaa !5
  %.not12 = icmp eq i32 %6, 0
  br i1 %.not12, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %7 = getelementptr inbounds i8, ptr %0, i64 96
  %8 = getelementptr inbounds i8, ptr %0, i64 64
  br label %9

9:                                                ; preds = %.lr.ph, %11
  %.013 = phi i64 [ 0, %.lr.ph ], [ %15, %11 ]
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %4) #2
  call void @_ZN7cascadb3MsgC2Ev(ptr noundef nonnull align 8 dereferenceable(40) %4)
  %10 = call noundef zeroext i1 @_ZN7cascadb3Msg9read_fromERNS_11BlockReaderE(ptr noundef nonnull align 8 dereferenceable(40) %4, ptr noundef nonnull align 8 dereferenceable(16) %1)
  br i1 %10, label %11, label %.critedge

11:                                               ; preds = %9
  %12 = call noundef i64 @_ZNK7cascadb3Msg4sizeEv(ptr noundef nonnull align 8 dereferenceable(40) %4)
  %13 = load i64, ptr %7, align 8, !tbaa !9
  %14 = add i64 %13, %12
  store i64 %14, ptr %7, align 8, !tbaa !9
  call void @_ZN7cascadb10FastVectorINS_3MsgELi32EE9push_backERKS1_(ptr noundef nonnull align 8 dereferenceable(32) %8, ptr noundef nonnull align 8 dereferenceable(40) %4)
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %4) #2
  %15 = add nuw nsw i64 %.013, 1
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = zext i32 %16 to i64
  %.not.not = icmp ult i64 %15, %17
  br i1 %.not.not, label %9, label %.loopexit, !llvm.loop !19

.critedge:                                        ; preds = %9
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %4) #2
  br label %.loopexit

.loopexit:                                        ; preds = %11, %.preheader, %.critedge, %2
  %.3 = phi i1 [ false, %2 ], [ false, %.critedge ], [ true, %.preheader ], [ true, %11 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #2
  ret i1 %.3
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7cascadb3MsgC2Ev(ptr noundef nonnull align 8 dereferenceable(40)) unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7cascadb10FastVectorINS_3MsgELi32EE9push_backERKS1_(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #0 align 2

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !18, i64 96}
!10 = !{!"_ZTSN7cascadb6MsgBufE", !11, i64 0, !12, i64 8, !13, i64 64, !18, i64 96}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"_ZTSN7cascadb6RWLockE", !7, i64 0}
!13 = !{!"_ZTSN7cascadb10FastVectorINS_3MsgELi32EEE", !14, i64 0, !18, i64 24}
!14 = !{!"_ZTSSt6vectorIPS_IN7cascadb3MsgESaIS1_EESaIS4_EE", !15, i64 0}
!15 = !{!"_ZTSSt12_Vector_baseIPSt6vectorIN7cascadb3MsgESaIS2_EESaIS5_EE", !16, i64 0}
!16 = !{!"_ZTSNSt12_Vector_baseIPSt6vectorIN7cascadb3MsgESaIS2_EESaIS5_EE12_Vector_implE", !17, i64 0}
!17 = !{!"_ZTSNSt12_Vector_baseIPSt6vectorIN7cascadb3MsgESaIS2_EESaIS5_EE17_Vector_impl_dataE", !11, i64 0, !11, i64 8, !11, i64 16}
!18 = !{!"long", !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: ConstraintEliminationPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass