; LLVM IR from weicao/cascadb :: src/serialize/block.ll (ZN7cascadb11BlockReader9readSliceERNS_5SliceE)

; 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::Slice" = type <{ ptr, i32, [4 x i8] }>
%"class.cascadb::BlockReader" = type { ptr, i64 }
%"class.cascadb::Block" = type { %"class.cascadb::Slice", i64, i64 }

@.str = external hidden unnamed_addr constant [25 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [72 x i8], align 1
@__PRETTY_FUNCTION__._ZN7cascadb11BlockReader9readSliceERNS_5SliceE = external hidden unnamed_addr constant [46 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN7cascadb11BlockReader9readSliceERNS_5SliceE(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull align 8 dereferenceable(12) %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 %"class.cascadb::Slice", align 8
  %8 = alloca %"class.cascadb::Slice", align 8
  %9 = alloca { ptr, i32 }, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %11 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  %12 = call noundef zeroext i1 @_ZN7cascadb11BlockReader10readUInt32EPj(ptr noundef nonnull align 8 dereferenceable(16) %11, ptr noundef %6)
  br i1 %12, label %13, label %52

13:                                               ; preds = %2
  %14 = getelementptr inbounds %"class.cascadb::BlockReader", ptr %11, i32 0, i32 1
  %15 = load i64, ptr %14, align 8, !tbaa !9
  %16 = getelementptr inbounds %"class.cascadb::BlockReader", ptr %11, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !12
  %18 = getelementptr inbounds %"class.cascadb::Block", ptr %17, i32 0, i32 2
  %19 = load i64, ptr %18, align 8, !tbaa !13
  %20 = icmp ule i64 %15, %19
  br i1 %20, label %21, label %22

21:                                               ; preds = %13
  br label %24

22:                                               ; preds = %13
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 13, ptr noundef @__PRETTY_FUNCTION__._ZN7cascadb11BlockReader9readSliceERNS_5SliceE) #7
  unreachable

23:                                               ; No predecessors!
  br label %24

24:                                               ; preds = %23, %21
  %25 = getelementptr inbounds %"class.cascadb::BlockReader", ptr %11, i32 0, i32 1
  %26 = load i64, ptr %25, align 8, !tbaa !9
  %27 = load i32, ptr %6, align 4, !tbaa !17
  %28 = zext i32 %27 to i64
  %29 = add i64 %26, %28
  %30 = getelementptr inbounds %"class.cascadb::BlockReader", ptr %11, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !12
  %32 = getelementptr inbounds %"class.cascadb::Block", ptr %31, i32 0, i32 2
  %33 = load i64, ptr %32, align 8, !tbaa !13
  %34 = icmp ule i64 %29, %33
  br i1 %34, label %35, label %51

35:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #6
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #6
  %36 = getelementptr inbounds %"class.cascadb::BlockReader", ptr %11, i32 0, i32 0
  %37 = load ptr, ptr %36, align 8, !tbaa !12
  %38 = call noundef ptr @_ZN7cascadb5Block5startEv(ptr noundef nonnull align 8 dereferenceable(32) %37)
  %39 = getelementptr inbounds %"class.cascadb::BlockReader", ptr %11, i32 0, i32 1
  %40 = load i64, ptr %39, align 8, !tbaa !9
  %41 = getelementptr inbounds i8, ptr %38, i64 %40
  %42 = load i32, ptr %6, align 4, !tbaa !17
  %43 = zext i32 %42 to i64
  call void @_ZN7cascadb5SliceC2EPKcm(ptr noundef nonnull align 8 dereferenceable(12) %8, ptr noundef %41, i64 noundef %43)
  %44 = call { ptr, i32 } @_ZNK7cascadb5Slice5cloneEv(ptr noundef nonnull align 8 dereferenceable(12) %8)
  store { ptr, i32 } %44, ptr %9, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %7, ptr align 8 %9, i64 12, i1 false)
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %45, ptr align 8 %7, i64 12, i1 false), !tbaa.struct !18
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #6
  %46 = load i32, ptr %6, align 4, !tbaa !17
  %47 = zext i32 %46 to i64
  %48 = getelementptr inbounds %"class.cascadb::BlockReader", ptr %11, i32 0, i32 1
  %49 = load i64, ptr %48, align 8, !tbaa !9
  %50 = add i64 %49, %47
  store i64 %50, ptr %48, align 8, !tbaa !9
  store i1 true, ptr %3, align 1
  store i32 1, ptr %10, align 4
  br label %53

51:                                               ; preds = %24
  br label %52

52:                                               ; preds = %51, %2
  store i1 false, ptr %3, align 1
  store i32 1, ptr %10, align 4
  br label %53

53:                                               ; preds = %52, %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  %54 = load i1, ptr %3, align 1
  ret i1 %54
}

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

; 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZN7cascadb5Block5startEv(ptr noundef nonnull align 8 dereferenceable(32)) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7cascadb5SliceC2EPKcm(ptr noundef nonnull align 8 dereferenceable(12), ptr noundef, i64 noundef) unnamed_addr #4 align 2

; Function Attrs: mustprogress uwtable
declare dso_local { ptr, i32 } @_ZNK7cascadb5Slice5cloneEv(ptr noundef nonnull align 8 dereferenceable(12)) #0 align 2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #5

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

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 = { 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 #3 = { inlinehint 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 = { 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 #5 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { nounwind }
attributes #7 = { 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, !11, i64 8}
!10 = !{!"_ZTSN7cascadb11BlockReaderE", !6, i64 0, !11, i64 8}
!11 = !{!"long", !7, i64 0}
!12 = !{!10, !6, i64 0}
!13 = !{!14, !11, i64 24}
!14 = !{!"_ZTSN7cascadb5BlockE", !15, i64 0, !11, i64 16, !11, i64 24}
!15 = !{!"_ZTSN7cascadb5SliceE", !6, i64 0, !16, i64 8}
!16 = !{!"int", !7, i64 0}
!17 = !{!16, !16, i64 0}
!18 = !{i64 0, i64 8, !5, i64 8, i64 4, !17}


; 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::Slice" = type <{ ptr, i32, [4 x i8] }>

@.str = external hidden unnamed_addr constant [25 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [72 x i8], align 1
@__PRETTY_FUNCTION__._ZN7cascadb11BlockReader9readSliceERNS_5SliceE = external hidden unnamed_addr constant [46 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN7cascadb11BlockReader9readSliceERNS_5SliceE(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr nocapture noundef nonnull writeonly align 8 dereferenceable(12) %1) local_unnamed_addr #0 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca %"class.cascadb::Slice", align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #5
  %5 = call noundef zeroext i1 @_ZN7cascadb11BlockReader10readUInt32EPj(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull %3)
  br i1 %5, label %6, label %28

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = load i64, ptr %7, align 8, !tbaa !5
  %9 = load ptr, ptr %0, align 8, !tbaa !11
  %10 = getelementptr inbounds i8, ptr %9, i64 24
  %11 = load i64, ptr %10, align 8, !tbaa !12
  %.not = icmp ugt i64 %8, %11
  br i1 %.not, label %12, label %13

12:                                               ; preds = %6
  call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 13, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN7cascadb11BlockReader9readSliceERNS_5SliceE) #6
  unreachable

13:                                               ; preds = %6
  %14 = load i32, ptr %3, align 4, !tbaa !16
  %15 = zext i32 %14 to i64
  %16 = add i64 %8, %15
  %.not6 = icmp ugt i64 %16, %11
  br i1 %.not6, label %28, label %17

17:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #5
  %18 = call noundef ptr @_ZN7cascadb5Block5startEv(ptr noundef nonnull align 8 dereferenceable(32) %9)
  %19 = load i64, ptr %7, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %18, i64 %19
  %21 = load i32, ptr %3, align 4, !tbaa !16
  %22 = zext i32 %21 to i64
  call void @_ZN7cascadb5SliceC2EPKcm(ptr noundef nonnull align 8 dereferenceable(12) %4, ptr noundef %20, i64 noundef %22)
  %23 = call { ptr, i32 } @_ZNK7cascadb5Slice5cloneEv(ptr noundef nonnull align 8 dereferenceable(12) %4)
  %.fca.0.extract = extractvalue { ptr, i32 } %23, 0
  %.fca.1.extract = extractvalue { ptr, i32 } %23, 1
  store ptr %.fca.0.extract, ptr %1, align 8, !tbaa !17
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %1, i64 8
  store i32 %.fca.1.extract, ptr %.sroa.4.0..sroa_idx, align 8, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #5
  %24 = load i32, ptr %3, align 4, !tbaa !16
  %25 = zext i32 %24 to i64
  %26 = load i64, ptr %7, align 8, !tbaa !5
  %27 = add i64 %26, %25
  store i64 %27, ptr %7, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %2, %13, %17
  %.0 = phi i1 [ true, %17 ], [ false, %13 ], [ false, %2 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #5
  ret i1 %.0
}

; 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 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZN7cascadb5Block5startEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7cascadb5SliceC2EPKcm(ptr noundef nonnull align 8 dereferenceable(12), ptr noundef, i64 noundef) unnamed_addr #4 align 2

; Function Attrs: mustprogress uwtable
declare dso_local { ptr, i32 } @_ZNK7cascadb5Slice5cloneEv(ptr noundef nonnull align 8 dereferenceable(12)) local_unnamed_addr #0 align 2

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

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 = { 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 #3 = { inlinehint 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 = { 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 #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, !10, i64 8}
!6 = !{!"_ZTSN7cascadb11BlockReaderE", !7, i64 0, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!13, !10, i64 24}
!13 = !{!"_ZTSN7cascadb5BlockE", !14, i64 0, !10, i64 16, !10, i64 24}
!14 = !{!"_ZTSN7cascadb5SliceE", !7, i64 0, !15, i64 8}
!15 = !{!"int", !8, i64 0}
!16 = !{!15, !15, i64 0}
!17 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass