; LLVM IR from yinqiwen/ardb :: src/db/codec.ll (ZN4ardb11ValueObject6DecodeERNS_6BufferEb)

; 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.ardb::ValueObject" = type { i8, i16, %"struct.ardb::MetaObject", %"class.std::vector" }
%"struct.ardb::MetaObject" = type { i8, i64, i64, i8, %"struct.ardb::StreamID" }
%"struct.ardb::StreamID" = type { i64, i64 }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<ardb::Data, std::allocator<ardb::Data>>::_Vector_impl" }
%"struct.std::_Vector_base<ardb::Data, std::allocator<ardb::Data>>::_Vector_impl" = type { %"struct.std::_Vector_base<ardb::Data, std::allocator<ardb::Data>>::_Vector_impl_data" }
%"struct.std::_Vector_base<ardb::Data, std::allocator<ardb::Data>>::_Vector_impl_data" = type { ptr, ptr, ptr }

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorIN4ardb4DataESaIS1_EE6resizeEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #0 align 2

declare noundef zeroext i1 @_ZN4ardb4Data6DecodeERNS_6BufferEb(ptr noundef nonnull align 8 dereferenceable(13), ptr noundef nonnull align 8 dereferenceable(33), i1 noundef zeroext) #1

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN4ardb6Buffer8ReadByteERc(ptr noundef nonnull align 8 dereferenceable(33), ptr noundef nonnull align 1 dereferenceable(1)) #3 align 2

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN4ardb11ValueObject6DecodeERNS_6BufferEb(ptr noundef nonnull align 8 dereferenceable(80) %0, ptr noundef nonnull align 8 dereferenceable(33) %1, i1 noundef zeroext %2) #0 align 2 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca i8, align 1
  %9 = alloca i32, align 4
  %10 = alloca i8, align 1
  %11 = alloca i8, align 1
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  %12 = zext i1 %2 to i8
  store i8 %12, ptr %7, align 1, !tbaa !9
  %13 = load ptr, ptr %5, align 8
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = call noundef zeroext i1 @_ZN4ardb11ValueObject10DecodeMetaERNS_6BufferE(ptr noundef nonnull align 8 dereferenceable(80) %13, ptr noundef nonnull align 8 dereferenceable(33) %14)
  br i1 %15, label %17, label %16

16:                                               ; preds = %3
  store i1 false, ptr %4, align 1
  br label %57

17:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #5
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = call noundef zeroext i1 @_ZN4ardb6Buffer8ReadByteERc(ptr noundef nonnull align 8 dereferenceable(33) %18, ptr noundef nonnull align 1 dereferenceable(1) %8)
  br i1 %19, label %21, label %20

20:                                               ; preds = %17
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %56

21:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #5
  %22 = load i8, ptr %8, align 1, !tbaa !11
  store i8 %22, ptr %10, align 1, !tbaa !11
  %23 = load i8, ptr %10, align 1, !tbaa !11
  %24 = zext i8 %23 to i32
  %25 = icmp sgt i32 %24, 0
  br i1 %25, label %26, label %54

26:                                               ; preds = %21
  %27 = getelementptr inbounds %"class.ardb::ValueObject", ptr %13, i32 0, i32 3
  %28 = load i8, ptr %10, align 1, !tbaa !11
  %29 = zext i8 %28 to i64
  call void @_ZNSt6vectorIN4ardb4DataESaIS1_EE6resizeEm(ptr noundef nonnull align 8 dereferenceable(24) %27, i64 noundef %29)
  call void @llvm.lifetime.start.p0(i64 1, ptr %11) #5
  store i8 0, ptr %11, align 1, !tbaa !11
  br label %30

30:                                               ; preds = %48, %26
  %31 = load i8, ptr %11, align 1, !tbaa !11
  %32 = zext i8 %31 to i32
  %33 = load i8, ptr %10, align 1, !tbaa !11
  %34 = zext i8 %33 to i32
  %35 = icmp slt i32 %32, %34
  br i1 %35, label %37, label %36

36:                                               ; preds = %30
  store i32 2, ptr %9, align 4
  br label %51

37:                                               ; preds = %30
  %38 = getelementptr inbounds %"class.ardb::ValueObject", ptr %13, i32 0, i32 3
  %39 = load i8, ptr %11, align 1, !tbaa !11
  %40 = zext i8 %39 to i64
  %41 = call noundef nonnull align 8 dereferenceable(13) ptr @_ZNSt6vectorIN4ardb4DataESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %38, i64 noundef %40) #5
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = load i8, ptr %7, align 1, !tbaa !9, !range !12, !noundef !13
  %44 = trunc i8 %43 to i1
  %45 = call noundef zeroext i1 @_ZN4ardb4Data6DecodeERNS_6BufferEb(ptr noundef nonnull align 8 dereferenceable(13) %41, ptr noundef nonnull align 8 dereferenceable(33) %42, i1 noundef zeroext %44)
  br i1 %45, label %47, label %46

46:                                               ; preds = %37
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %51

47:                                               ; preds = %37
  br label %48

48:                                               ; preds = %47
  %49 = load i8, ptr %11, align 1, !tbaa !11
  %50 = add i8 %49, 1
  store i8 %50, ptr %11, align 1, !tbaa !11
  br label %30, !llvm.loop !14

51:                                               ; preds = %46, %36
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #5
  %52 = load i32, ptr %9, align 4
  switch i32 %52, label %55 [
    i32 2, label %53
  ]

53:                                               ; preds = %51
  br label %54

54:                                               ; preds = %53, %21
  store i1 true, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %55

55:                                               ; preds = %54, %51
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #5
  br label %56

56:                                               ; preds = %55, %20
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #5
  br label %57

57:                                               ; preds = %56, %16
  %58 = load i1, ptr %4, align 1
  ret i1 %58
}

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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 }

!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 = !{!"bool", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{i8 0, i8 2}
!13 = !{}
!14 = distinct !{!14, !15}
!15 = !{!"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"

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorIN4ardb4DataESaIS1_EE6resizeEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

declare noundef zeroext i1 @_ZN4ardb4Data6DecodeERNS_6BufferEb(ptr noundef nonnull align 8 dereferenceable(13), ptr noundef nonnull align 8 dereferenceable(33), i1 noundef zeroext) local_unnamed_addr #1

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

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

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN4ardb11ValueObject6DecodeERNS_6BufferEb(ptr noundef nonnull align 8 dereferenceable(80) %0, ptr noundef nonnull align 8 dereferenceable(33) %1, i1 noundef zeroext %2) local_unnamed_addr #0 align 2 {
  %4 = alloca i8, align 1
  %5 = tail call noundef zeroext i1 @_ZN4ardb11ValueObject10DecodeMetaERNS_6BufferE(ptr noundef nonnull align 8 dereferenceable(80) %0, ptr noundef nonnull align 8 dereferenceable(33) %1)
  br i1 %5, label %6, label %16

6:                                                ; preds = %3
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %4) #5
  %7 = call noundef zeroext i1 @_ZN4ardb6Buffer8ReadByteERc(ptr noundef nonnull align 8 dereferenceable(33) %1, ptr noundef nonnull align 1 dereferenceable(1) %4)
  br i1 %7, label %8, label %.critedge

8:                                                ; preds = %6
  %9 = load i8, ptr %4, align 1, !tbaa !5
  %.not = icmp eq i8 %9, 0
  br i1 %.not, label %.critedge, label %10

10:                                               ; preds = %8
  %11 = getelementptr inbounds i8, ptr %0, i64 56
  %12 = zext i8 %9 to i64
  call void @_ZNSt6vectorIN4ardb4DataESaIS1_EE6resizeEm(ptr noundef nonnull align 8 dereferenceable(24) %11, i64 noundef %12)
  br label %13

13:                                               ; preds = %13, %10
  %indvars.iv = phi i64 [ 0, %10 ], [ %indvars.iv.next, %13 ]
  %14 = call noundef nonnull align 8 dereferenceable(13) ptr @_ZNSt6vectorIN4ardb4DataESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %11, i64 noundef %indvars.iv) #5
  %15 = call noundef zeroext i1 @_ZN4ardb4Data6DecodeERNS_6BufferEb(ptr noundef nonnull align 8 dereferenceable(13) %14, ptr noundef nonnull align 8 dereferenceable(33) %1, i1 noundef zeroext %2)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp ne i64 %indvars.iv.next, %12
  %or.cond.not = select i1 %15, i1 %exitcond.not, i1 false
  br i1 %or.cond.not, label %13, label %.critedge, !llvm.loop !8

.critedge:                                        ; preds = %13, %8, %6
  %.2 = phi i1 [ false, %6 ], [ true, %8 ], [ %15, %13 ]
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %4) #5
  br label %16

16:                                               ; preds = %3, %.critedge
  %.3 = phi i1 [ %.2, %.critedge ], [ false, %3 ]
  ret i1 %.3
}

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 = { "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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass