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

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

%"struct.ardb::KeyObject" = type { %"struct.ardb::Data", i8, [7 x i8], %"struct.ardb::Data", %"class.std::vector" }
%"struct.ardb::Data" = type <{ i64, i32, i8, [3 x i8] }>
%"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 }

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

; 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 @_ZN4ardb9KeyObject12DecodePrefixERNS_6BufferEb(ptr noundef nonnull align 8 dereferenceable(64), ptr noundef nonnull align 8 dereferenceable(33), i1 noundef zeroext) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN4ardb9KeyObject19DecodeElementLengthERNS_6BufferE(ptr noundef nonnull align 8 dereferenceable(64), ptr noundef nonnull align 8 dereferenceable(33)) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN4ardb9KeyObject13DecodeElementERNS_6BufferEbi(ptr noundef nonnull align 8 dereferenceable(64), ptr noundef nonnull align 8 dereferenceable(33), i1 noundef zeroext, i32 noundef) #2 align 2

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

18:                                               ; preds = %4
  %19 = getelementptr inbounds %"struct.ardb::KeyObject", ptr %15, i32 0, i32 0
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = load i8, ptr %8, align 1, !tbaa !9, !range !11, !noundef !12
  %22 = trunc i8 %21 to i1
  %23 = call noundef zeroext i1 @_ZN4ardb4Data6DecodeERNS_6BufferEb(ptr noundef nonnull align 8 dereferenceable(13) %19, ptr noundef nonnull align 8 dereferenceable(33) %20, i1 noundef zeroext %22)
  br i1 %23, label %25, label %24

24:                                               ; preds = %18
  store i1 false, ptr %5, align 1
  br label %59

25:                                               ; preds = %18
  br label %26

26:                                               ; preds = %25, %4
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = load i8, ptr %8, align 1, !tbaa !9, !range !11, !noundef !12
  %29 = trunc i8 %28 to i1
  %30 = call noundef zeroext i1 @_ZN4ardb9KeyObject12DecodePrefixERNS_6BufferEb(ptr noundef nonnull align 8 dereferenceable(64) %15, ptr noundef nonnull align 8 dereferenceable(33) %27, i1 noundef zeroext %29)
  br i1 %30, label %32, label %31

31:                                               ; preds = %26
  store i1 false, ptr %5, align 1
  br label %59

32:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = call noundef i32 @_ZN4ardb9KeyObject19DecodeElementLengthERNS_6BufferE(ptr noundef nonnull align 8 dereferenceable(64) %15, ptr noundef nonnull align 8 dereferenceable(33) %33)
  store i32 %34, ptr %10, align 4, !tbaa !13
  %35 = load i32, ptr %10, align 4, !tbaa !13
  %36 = icmp sgt i32 %35, 0
  br i1 %36, label %37, label %57

37:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !13
  br label %38

38:                                               ; preds = %51, %37
  %39 = load i32, ptr %11, align 4, !tbaa !13
  %40 = load i32, ptr %10, align 4, !tbaa !13
  %41 = icmp slt i32 %39, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %38
  store i32 2, ptr %12, align 4
  br label %54

43:                                               ; preds = %38
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = load i8, ptr %8, align 1, !tbaa !9, !range !11, !noundef !12
  %46 = trunc i8 %45 to i1
  %47 = load i32, ptr %11, align 4, !tbaa !13
  %48 = call noundef zeroext i1 @_ZN4ardb9KeyObject13DecodeElementERNS_6BufferEbi(ptr noundef nonnull align 8 dereferenceable(64) %15, ptr noundef nonnull align 8 dereferenceable(33) %44, i1 noundef zeroext %46, i32 noundef %47)
  br i1 %48, label %50, label %49

49:                                               ; preds = %43
  store i1 false, ptr %5, align 1
  store i32 1, ptr %12, align 4
  br label %54

50:                                               ; preds = %43
  br label %51

51:                                               ; preds = %50
  %52 = load i32, ptr %11, align 4, !tbaa !13
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %11, align 4, !tbaa !13
  br label %38, !llvm.loop !15

54:                                               ; preds = %49, %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  %55 = load i32, ptr %12, align 4
  switch i32 %55, label %58 [
    i32 2, label %56
  ]

56:                                               ; preds = %54
  br label %57

57:                                               ; preds = %56, %32
  store i1 true, ptr %5, align 1
  store i32 1, ptr %12, align 4
  br label %58

58:                                               ; preds = %57, %54
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %59

59:                                               ; preds = %58, %31, %24
  %60 = load i1, ptr %5, align 1
  ret i1 %60
}

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

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

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 #0

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN4ardb9KeyObject19DecodeElementLengthERNS_6BufferE(ptr noundef nonnull align 8 dereferenceable(64), ptr noundef nonnull align 8 dereferenceable(33)) local_unnamed_addr #1 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN4ardb9KeyObject6DecodeERNS_6BufferEbb(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr noundef nonnull align 8 dereferenceable(33) %1, i1 noundef zeroext %2, i1 noundef zeroext %3) local_unnamed_addr #1 align 2 {
  tail call void @_ZN4ardb9KeyObject5ClearEv(ptr noundef nonnull align 8 dereferenceable(64) %0)
  br i1 %3, label %5, label %7

5:                                                ; preds = %4
  %6 = tail call noundef zeroext i1 @_ZN4ardb4Data6DecodeERNS_6BufferEb(ptr noundef nonnull align 8 dereferenceable(13) %0, ptr noundef nonnull align 8 dereferenceable(33) %1, i1 noundef zeroext %2)
  br i1 %6, label %7, label %.critedge

7:                                                ; preds = %5, %4
  %8 = tail call noundef zeroext i1 @_ZN4ardb9KeyObject12DecodePrefixERNS_6BufferEb(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr noundef nonnull align 8 dereferenceable(33) %1, i1 noundef zeroext %2)
  br i1 %8, label %9, label %.critedge

9:                                                ; preds = %7
  %10 = tail call noundef i32 @_ZN4ardb9KeyObject19DecodeElementLengthERNS_6BufferE(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr noundef nonnull align 8 dereferenceable(33) %1)
  %11 = icmp sgt i32 %10, 0
  br i1 %11, label %.preheader, label %.critedge

.preheader:                                       ; preds = %9, %.preheader
  %.01518 = phi i32 [ %13, %.preheader ], [ 0, %9 ]
  %12 = tail call noundef zeroext i1 @_ZN4ardb9KeyObject13DecodeElementERNS_6BufferEbi(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr noundef nonnull align 8 dereferenceable(33) %1, i1 noundef zeroext %2, i32 noundef %.01518)
  %13 = add nuw nsw i32 %.01518, 1
  %exitcond.not = icmp ne i32 %13, %10
  %or.cond.not = select i1 %12, i1 %exitcond.not, i1 false
  br i1 %or.cond.not, label %.preheader, label %.critedge, !llvm.loop !5

.critedge:                                        ; preds = %.preheader, %9, %7, %5
  %.2 = phi i1 [ false, %5 ], [ false, %7 ], [ true, %9 ], [ %12, %.preheader ]
  ret i1 %.2
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4ardb9KeyObject5ClearEv(ptr noundef nonnull align 8 dereferenceable(64)) local_unnamed_addr #1 align 2

attributes #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 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" }

!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,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass