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

; 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::Data" = type <{ i64, i32, i8, [3 x i8] }>
%"struct.ardb::MetaObject" = type { i8, i64, i64, i8, %"struct.ardb::StreamID" }
%"struct.ardb::StreamID" = type { i64, i64 }

; 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: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZN4ardb6Buffer9WriteByteEc(ptr noundef nonnull align 8 dereferenceable(33), i8 noundef signext) #1 align 2

declare void @_ZNK4ardb4Data6EncodeERNS_6BufferE(ptr noundef nonnull align 8 dereferenceable(13), ptr noundef nonnull align 8 dereferenceable(33)) #2

declare void @_ZNK4ardb8StreamID6EncodeERNS_4DataE(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(13)) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK4ardb10MetaObject6EncodeERNS_6BufferEh(ptr noundef nonnull align 8 dereferenceable(48) %0, ptr noundef nonnull align 8 dereferenceable(33) %1, i8 noundef zeroext %2) #3 align 2 personality ptr @__gxx_personality_v0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca %"struct.ardb::Data", align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i8 %2, ptr %6, align 1, !tbaa !9
  %10 = load ptr, ptr %4, align 8
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %"struct.ardb::MetaObject", ptr %10, i32 0, i32 0
  %13 = load i8, ptr %12, align 8, !tbaa !10
  %14 = call noundef i32 @_ZN4ardb6Buffer9WriteByteEc(ptr noundef nonnull align 8 dereferenceable(33) %11, i8 noundef signext %13)
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %"struct.ardb::MetaObject", ptr %10, i32 0, i32 1
  %17 = load i64, ptr %16, align 8, !tbaa !15
  %18 = call noundef zeroext i1 @_ZN4ardb12BufferHelper13WriteVarInt64ERNS_6BufferEl(ptr noundef nonnull align 8 dereferenceable(33) %15, i64 noundef %17)
  %19 = load i8, ptr %6, align 1, !tbaa !9
  %20 = zext i8 %19 to i32
  switch i32 %20, label %27 [
    i32 2, label %21
    i32 5, label %22
    i32 7, label %22
    i32 9, label %22
    i32 3, label %22
    i32 12, label %22
  ]

21:                                               ; preds = %3
  br label %28

22:                                               ; preds = %3, %3, %3, %3, %3
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %"struct.ardb::MetaObject", ptr %10, i32 0, i32 2
  %25 = load i64, ptr %24, align 8, !tbaa !16
  %26 = call noundef zeroext i1 @_ZN4ardb12BufferHelper13WriteVarInt64ERNS_6BufferEl(ptr noundef nonnull align 8 dereferenceable(33) %23, i64 noundef %25)
  br label %28

27:                                               ; preds = %3
  br label %28

28:                                               ; preds = %27, %22, %21
  %29 = load i8, ptr %6, align 1, !tbaa !9
  %30 = zext i8 %29 to i32
  switch i32 %30, label %49 [
    i32 5, label %31
    i32 12, label %40
  ]

31:                                               ; preds = %28
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %"struct.ardb::MetaObject", ptr %10, i32 0, i32 3
  %34 = load i8, ptr %33, align 8, !tbaa !17, !range !18, !noundef !19
  %35 = trunc i8 %34 to i1
  %36 = zext i1 %35 to i64
  %37 = select i1 %35, i32 1, i32 0
  %38 = trunc i32 %37 to i8
  %39 = call noundef i32 @_ZN4ardb6Buffer9WriteByteEc(ptr noundef nonnull align 8 dereferenceable(33) %32, i8 noundef signext %38)
  br label %50

40:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #5
  call void @_ZN4ardb4DataC1Ev(ptr noundef nonnull align 8 dereferenceable(13) %7)
  %41 = getelementptr inbounds %"struct.ardb::MetaObject", ptr %10, i32 0, i32 4
  invoke void @_ZNK4ardb8StreamID6EncodeERNS_4DataE(ptr noundef nonnull align 8 dereferenceable(16) %41, ptr noundef nonnull align 8 dereferenceable(13) %7)
          to label %42 unwind label %45

42:                                               ; preds = %40
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  invoke void @_ZNK4ardb4Data6EncodeERNS_6BufferE(ptr noundef nonnull align 8 dereferenceable(13) %7, ptr noundef nonnull align 8 dereferenceable(33) %43)
          to label %44 unwind label %45

44:                                               ; preds = %42
  call void @_ZN4ardb4DataD1Ev(ptr noundef nonnull align 8 dereferenceable(13) %7) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #5
  br label %50

45:                                               ; preds = %42, %40
  %46 = landingpad { ptr, i32 }
          cleanup
  %47 = extractvalue { ptr, i32 } %46, 0
  store ptr %47, ptr %8, align 8
  %48 = extractvalue { ptr, i32 } %46, 1
  store i32 %48, ptr %9, align 4
  call void @_ZN4ardb4DataD1Ev(ptr noundef nonnull align 8 dereferenceable(13) %7) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #5
  br label %51

49:                                               ; preds = %28
  br label %50

50:                                               ; preds = %49, %44, %31
  ret void

51:                                               ; preds = %45
  %52 = load ptr, ptr %8, align 8
  %53 = load i32, ptr %9, align 4
  %54 = insertvalue { ptr, i32 } poison, ptr %52, 0
  %55 = insertvalue { ptr, i32 } %54, i32 %53, 1
  resume { ptr, i32 } %55
}

declare noundef zeroext i1 @_ZN4ardb12BufferHelper13WriteVarInt64ERNS_6BufferEl(ptr noundef nonnull align 8 dereferenceable(33), i64 noundef) #2

declare void @_ZN4ardb4DataC1Ev(ptr noundef nonnull align 8 dereferenceable(13)) unnamed_addr #2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nounwind
declare void @_ZN4ardb4DataD1Ev(ptr noundef nonnull align 8 dereferenceable(13)) unnamed_addr #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { "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 = { 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 = { 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 #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 = !{!7, !7, i64 0}
!10 = !{!11, !7, i64 0}
!11 = !{!"_ZTSN4ardb10MetaObjectE", !7, i64 0, !12, i64 8, !12, i64 16, !13, i64 24, !14, i64 32}
!12 = !{!"long", !7, i64 0}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"_ZTSN4ardb8StreamIDE", !12, i64 0, !12, i64 8}
!15 = !{!11, !12, i64 8}
!16 = !{!11, !12, i64 16}
!17 = !{!11, !13, i64 24}
!18 = !{i8 0, i8 2}
!19 = !{}


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

%"struct.ardb::Data" = type <{ i64, i32, i8, [3 x i8] }>

; 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: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZN4ardb6Buffer9WriteByteEc(ptr noundef nonnull align 8 dereferenceable(33), i8 noundef signext) local_unnamed_addr #1 align 2

declare void @_ZNK4ardb4Data6EncodeERNS_6BufferE(ptr noundef nonnull align 8 dereferenceable(13), ptr noundef nonnull align 8 dereferenceable(33)) local_unnamed_addr #2

declare void @_ZNK4ardb8StreamID6EncodeERNS_4DataE(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(13)) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK4ardb10MetaObject6EncodeERNS_6BufferEh(ptr noundef nonnull align 8 dereferenceable(48) %0, ptr noundef nonnull align 8 dereferenceable(33) %1, i8 noundef zeroext %2) local_unnamed_addr #3 align 2 personality ptr @__gxx_personality_v0 {
  %4 = alloca %"struct.ardb::Data", align 8
  %5 = load i8, ptr %0, align 8, !tbaa !5
  %6 = tail call noundef i32 @_ZN4ardb6Buffer9WriteByteEc(ptr noundef nonnull align 8 dereferenceable(33) %1, i8 noundef signext %5)
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = load i64, ptr %7, align 8, !tbaa !12
  %9 = tail call noundef zeroext i1 @_ZN4ardb12BufferHelper13WriteVarInt64ERNS_6BufferEl(ptr noundef nonnull align 8 dereferenceable(33) %1, i64 noundef %8)
  switch i8 %2, label %24 [
    i8 12, label %10
    i8 5, label %10
    i8 7, label %10
    i8 9, label %10
    i8 3, label %10
  ]

10:                                               ; preds = %3, %3, %3, %3, %3
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  %12 = load i64, ptr %11, align 8, !tbaa !13
  %13 = tail call noundef zeroext i1 @_ZN4ardb12BufferHelper13WriteVarInt64ERNS_6BufferEl(ptr noundef nonnull align 8 dereferenceable(33) %1, i64 noundef %12)
  switch i8 %2, label %24 [
    i8 5, label %14
    i8 12, label %18
  ]

14:                                               ; preds = %10
  %15 = getelementptr inbounds i8, ptr %0, i64 24
  %16 = load i8, ptr %15, align 8, !tbaa !14, !range !15, !noundef !16
  %17 = tail call noundef i32 @_ZN4ardb6Buffer9WriteByteEc(ptr noundef nonnull align 8 dereferenceable(33) %1, i8 noundef signext %16)
  br label %24

18:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #5
  call void @_ZN4ardb4DataC1Ev(ptr noundef nonnull align 8 dereferenceable(13) %4)
  %19 = getelementptr inbounds i8, ptr %0, i64 32
  invoke void @_ZNK4ardb8StreamID6EncodeERNS_4DataE(ptr noundef nonnull align 8 dereferenceable(16) %19, ptr noundef nonnull align 8 dereferenceable(13) %4)
          to label %20 unwind label %22

20:                                               ; preds = %18
  invoke void @_ZNK4ardb4Data6EncodeERNS_6BufferE(ptr noundef nonnull align 8 dereferenceable(13) %4, ptr noundef nonnull align 8 dereferenceable(33) %1)
          to label %21 unwind label %22

21:                                               ; preds = %20
  call void @_ZN4ardb4DataD1Ev(ptr noundef nonnull align 8 dereferenceable(13) %4) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #5
  br label %24

22:                                               ; preds = %20, %18
  %23 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN4ardb4DataD1Ev(ptr noundef nonnull align 8 dereferenceable(13) %4) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #5
  resume { ptr, i32 } %23

24:                                               ; preds = %3, %10, %21, %14
  ret void
}

declare noundef zeroext i1 @_ZN4ardb12BufferHelper13WriteVarInt64ERNS_6BufferEl(ptr noundef nonnull align 8 dereferenceable(33), i64 noundef) local_unnamed_addr #2

declare void @_ZN4ardb4DataC1Ev(ptr noundef nonnull align 8 dereferenceable(13)) unnamed_addr #2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nounwind
declare void @_ZN4ardb4DataD1Ev(ptr noundef nonnull align 8 dereferenceable(13)) unnamed_addr #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { "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 = { 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 = { 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 #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, !7, i64 0}
!6 = !{!"_ZTSN4ardb10MetaObjectE", !7, i64 0, !9, i64 8, !9, i64 16, !10, i64 24, !11, i64 32}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"long", !7, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{!"_ZTSN4ardb8StreamIDE", !9, i64 0, !9, i64 8}
!12 = !{!6, !9, i64 8}
!13 = !{!6, !9, i64 16}
!14 = !{!6, !10, i64 24}
!15 = !{i8 0, i8 2}
!16 = !{}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass