; LLVM IR from dynexcoin/Dynex :: src/Serialization (KVBinaryOutputStreamSerializer)

; 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.Common::StringView" = type { ptr, i64 }
%"class.DynexCN::KVBinaryOutputStreamSerializer" = type { %"class.DynexCN::ISerializer", %"class.std::vector", %"class.std::vector.0" }
%"class.DynexCN::ISerializer" = type { ptr }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<DynexCN::MemoryStream, std::allocator<DynexCN::MemoryStream>>::_Vector_impl" }
%"struct.std::_Vector_base<DynexCN::MemoryStream, std::allocator<DynexCN::MemoryStream>>::_Vector_impl" = type { %"struct.std::_Vector_base<DynexCN::MemoryStream, std::allocator<DynexCN::MemoryStream>>::_Vector_impl_data" }
%"struct.std::_Vector_base<DynexCN::MemoryStream, std::allocator<DynexCN::MemoryStream>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::vector.0" = type { %"struct.std::_Vector_base.1" }
%"struct.std::_Vector_base.1" = type { %"struct.std::_Vector_base<DynexCN::KVBinaryOutputStreamSerializer::Level, std::allocator<DynexCN::KVBinaryOutputStreamSerializer::Level>>::_Vector_impl" }
%"struct.std::_Vector_base<DynexCN::KVBinaryOutputStreamSerializer::Level, std::allocator<DynexCN::KVBinaryOutputStreamSerializer::Level>>::_Vector_impl" = type { %"struct.std::_Vector_base<DynexCN::KVBinaryOutputStreamSerializer::Level, std::allocator<DynexCN::KVBinaryOutputStreamSerializer::Level>>::_Vector_impl_data" }
%"struct.std::_Vector_base<DynexCN::KVBinaryOutputStreamSerializer::Level, std::allocator<DynexCN::KVBinaryOutputStreamSerializer::Level>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"struct.DynexCN::KVBinaryOutputStreamSerializer::Level" = type { i32, %"class.std::__cxx11::basic_string", i64 }
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }

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

declare void @_ZN6Common10StringViewC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #1

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nounwind
declare void @_ZN6Common10StringViewD1Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #2

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

declare void @_ZN6Common5writeERNS_13IOutputStreamEPKvm(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef, i64 noundef) #1

; Function Attrs: mustprogress uwtable
declare hidden noundef i64 @_ZN12_GLOBAL__N_114writeArraySizeERN6Common13IOutputStreamEm(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(40) ptr @_ZN7DynexCN30KVBinaryOutputStreamSerializer6streamEv(ptr noundef nonnull align 8 dereferenceable(56)) #4 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7DynexCN30KVBinaryOutputStreamSerializer18checkArrayPreambleEh(ptr noundef nonnull align 8 dereferenceable(56) %0, i8 noundef zeroext %1) #3 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca %"class.Common::StringView", align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i8, align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i8 %1, ptr %4, align 1, !tbaa !9
  %11 = load ptr, ptr %3, align 8
  %12 = getelementptr inbounds %"class.DynexCN::KVBinaryOutputStreamSerializer", ptr %11, i32 0, i32 2
  %13 = call noundef zeroext i1 @_ZNKSt6vectorIN7DynexCN30KVBinaryOutputStreamSerializer5LevelESaIS2_EE5emptyEv(ptr noundef nonnull align 8 dereferenceable(24) %12) #5
  br i1 %13, label %14, label %15

14:                                               ; preds = %2
  br label %45

15:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %16 = getelementptr inbounds %"class.DynexCN::KVBinaryOutputStreamSerializer", ptr %11, i32 0, i32 2
  %17 = call noundef nonnull align 8 dereferenceable(48) ptr @_ZNSt6vectorIN7DynexCN30KVBinaryOutputStreamSerializer5LevelESaIS2_EE4backEv(ptr noundef nonnull align 8 dereferenceable(24) %16) #5
  store ptr %17, ptr %5, align 8, !tbaa !5
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %"struct.DynexCN::KVBinaryOutputStreamSerializer::Level", ptr %18, i32 0, i32 0
  %20 = load i32, ptr %19, align 8, !tbaa !10
  %21 = icmp eq i32 %20, 2
  br i1 %21, label %22, label %44

22:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %23 = call noundef nonnull align 8 dereferenceable(40) ptr @_ZN7DynexCN30KVBinaryOutputStreamSerializer6streamEv(ptr noundef nonnull align 8 dereferenceable(56) %11)
  store ptr %23, ptr %6, align 8, !tbaa !5
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %"struct.DynexCN::KVBinaryOutputStreamSerializer::Level", ptr %25, i32 0, i32 1
  call void @_ZN6Common10StringViewC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE(ptr noundef nonnull align 8 dereferenceable(16) %7, ptr noundef nonnull align 8 dereferenceable(32) %26)
  invoke void @_ZN12_GLOBAL__N_116writeElementNameERN6Common13IOutputStreamENS0_10StringViewE(ptr noundef nonnull align 8 dereferenceable(8) %24, ptr noundef %7)
          to label %27 unwind label %40

27:                                               ; preds = %22
  call void @_ZN6Common10StringViewD1Ev(ptr noundef nonnull align 8 dereferenceable(16) %7) #5
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #5
  %28 = load i8, ptr %4, align 1, !tbaa !9
  %29 = zext i8 %28 to i32
  %30 = or i32 128, %29
  %31 = trunc i32 %30 to i8
  store i8 %31, ptr %10, align 1, !tbaa !9
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_ZN6Common5writeERNS_13IOutputStreamEPKvm(ptr noundef nonnull align 8 dereferenceable(8) %32, ptr noundef %10, i64 noundef 1)
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %"struct.DynexCN::KVBinaryOutputStreamSerializer::Level", ptr %34, i32 0, i32 2
  %36 = load i64, ptr %35, align 8, !tbaa !16
  %37 = call noundef i64 @_ZN12_GLOBAL__N_114writeArraySizeERN6Common13IOutputStreamEm(ptr noundef nonnull align 8 dereferenceable(8) %33, i64 noundef %36)
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %"struct.DynexCN::KVBinaryOutputStreamSerializer::Level", ptr %38, i32 0, i32 0
  store i32 3, ptr %39, align 8, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  br label %44

40:                                               ; preds = %22
  %41 = landingpad { ptr, i32 }
          cleanup
  %42 = extractvalue { ptr, i32 } %41, 0
  store ptr %42, ptr %8, align 8
  %43 = extractvalue { ptr, i32 } %41, 1
  store i32 %43, ptr %9, align 4
  call void @_ZN6Common10StringViewD1Ev(ptr noundef nonnull align 8 dereferenceable(16) %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  br label %46

44:                                               ; preds = %27, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  br label %45

45:                                               ; preds = %44, %14
  ret void

46:                                               ; preds = %40
  %47 = load ptr, ptr %8, align 8
  %48 = load i32, ptr %9, align 4
  %49 = insertvalue { ptr, i32 } poison, ptr %47, 0
  %50 = insertvalue { ptr, i32 } %49, i32 %48, 1
  resume { ptr, i32 } %50
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(48) ptr @_ZNSt6vectorIN7DynexCN30KVBinaryOutputStreamSerializer5LevelESaIS2_EE4backEv(ptr noundef nonnull align 8 dereferenceable(24)) #4 align 2

; Function Attrs: mustprogress uwtable
declare hidden void @_ZN12_GLOBAL__N_116writeElementNameERN6Common13IOutputStreamENS0_10StringViewE(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNKSt6vectorIN7DynexCN30KVBinaryOutputStreamSerializer5LevelESaIS2_EE5emptyEv(ptr noundef nonnull align 8 dereferenceable(24)) #4 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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 = !{!7, !7, i64 0}
!10 = !{!11, !12, i64 0}
!11 = !{!"_ZTSN7DynexCN30KVBinaryOutputStreamSerializer5LevelE", !12, i64 0, !13, i64 8, !15, i64 40}
!12 = !{!"_ZTSN7DynexCN30KVBinaryOutputStreamSerializer5StateE", !7, i64 0}
!13 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !14, i64 0, !15, i64 8, !7, i64 16}
!14 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!11, !15, i64 40}


; 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.Common::StringView" = type { ptr, i64 }

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

declare void @_ZN6Common10StringViewC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #1

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nounwind
declare void @_ZN6Common10StringViewD1Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #2

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

declare void @_ZN6Common5writeERNS_13IOutputStreamEPKvm(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare hidden noundef i64 @_ZN12_GLOBAL__N_114writeArraySizeERN6Common13IOutputStreamEm(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(40) ptr @_ZN7DynexCN30KVBinaryOutputStreamSerializer6streamEv(ptr noundef nonnull align 8 dereferenceable(56)) local_unnamed_addr #4 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7DynexCN30KVBinaryOutputStreamSerializer18checkArrayPreambleEh(ptr noundef nonnull align 8 dereferenceable(56) %0, i8 noundef zeroext %1) local_unnamed_addr #3 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca %"class.Common::StringView", align 8
  %4 = alloca i8, align 1
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  %6 = tail call noundef zeroext i1 @_ZNKSt6vectorIN7DynexCN30KVBinaryOutputStreamSerializer5LevelESaIS2_EE5emptyEv(ptr noundef nonnull align 8 dereferenceable(24) %5) #5
  br i1 %6, label %21, label %7

7:                                                ; preds = %2
  %8 = tail call noundef nonnull align 8 dereferenceable(48) ptr @_ZNSt6vectorIN7DynexCN30KVBinaryOutputStreamSerializer5LevelESaIS2_EE4backEv(ptr noundef nonnull align 8 dereferenceable(24) %5) #5
  %9 = load i32, ptr %8, align 8, !tbaa !5
  %10 = icmp eq i32 %9, 2
  br i1 %10, label %11, label %21

11:                                               ; preds = %7
  %12 = tail call noundef nonnull align 8 dereferenceable(40) ptr @_ZN7DynexCN30KVBinaryOutputStreamSerializer6streamEv(ptr noundef nonnull align 8 dereferenceable(56) %0)
  %13 = getelementptr inbounds i8, ptr %8, i64 8
  call void @_ZN6Common10StringViewC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE(ptr noundef nonnull align 8 dereferenceable(16) %3, ptr noundef nonnull align 8 dereferenceable(32) %13)
  invoke void @_ZN12_GLOBAL__N_116writeElementNameERN6Common13IOutputStreamENS0_10StringViewE(ptr noundef nonnull align 8 dereferenceable(8) %12, ptr noundef nonnull %3)
          to label %14 unwind label %19

14:                                               ; preds = %11
  call void @_ZN6Common10StringViewD1Ev(ptr noundef nonnull align 8 dereferenceable(16) %3) #5
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %4) #5
  %15 = or i8 %1, -128
  store i8 %15, ptr %4, align 1, !tbaa !14
  call void @_ZN6Common5writeERNS_13IOutputStreamEPKvm(ptr noundef nonnull align 8 dereferenceable(8) %12, ptr noundef nonnull %4, i64 noundef 1)
  %16 = getelementptr inbounds i8, ptr %8, i64 40
  %17 = load i64, ptr %16, align 8, !tbaa !15
  %18 = call noundef i64 @_ZN12_GLOBAL__N_114writeArraySizeERN6Common13IOutputStreamEm(ptr noundef nonnull align 8 dereferenceable(8) %12, i64 noundef %17)
  store i32 3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %4) #5
  br label %21

19:                                               ; preds = %11
  %20 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN6Common10StringViewD1Ev(ptr noundef nonnull align 8 dereferenceable(16) %3) #5
  resume { ptr, i32 } %20

21:                                               ; preds = %7, %14, %2
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(48) ptr @_ZNSt6vectorIN7DynexCN30KVBinaryOutputStreamSerializer5LevelESaIS2_EE4backEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #4 align 2

; Function Attrs: mustprogress uwtable
declare hidden void @_ZN12_GLOBAL__N_116writeElementNameERN6Common13IOutputStreamENS0_10StringViewE(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNKSt6vectorIN7DynexCN30KVBinaryOutputStreamSerializer5LevelESaIS2_EE5emptyEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #4 align 2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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, !7, i64 0}
!6 = !{!"_ZTSN7DynexCN30KVBinaryOutputStreamSerializer5LevelE", !7, i64 0, !10, i64 8, !13, i64 40}
!7 = !{!"_ZTSN7DynexCN30KVBinaryOutputStreamSerializer5StateE", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !11, i64 0, !13, i64 8, !8, i64 16}
!11 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !12, i64 0}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!"long", !8, i64 0}
!14 = !{!8, !8, i64 0}
!15 = !{!6, !13, i64 40}


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