; LLVM IR from trustwallet/wallet-core :: src/Everscale/CommonTON/Messages.ll (ZNK2TW9CommonTON9StateInit7writeToEv)

; 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.TW::CommonTON::CellBuilder" = type { i16, %"class.std::vector", %"class.std::vector.0" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl" }
%"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl" = type { %"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl_data" }
%"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_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<std::shared_ptr<TW::CommonTON::Cell>, std::allocator<std::shared_ptr<TW::CommonTON::Cell>>>::_Vector_impl" }
%"struct.std::_Vector_base<std::shared_ptr<TW::CommonTON::Cell>, std::allocator<std::shared_ptr<TW::CommonTON::Cell>>>::_Vector_impl" = type { %"struct.std::_Vector_base<std::shared_ptr<TW::CommonTON::Cell>, std::allocator<std::shared_ptr<TW::CommonTON::Cell>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<std::shared_ptr<TW::CommonTON::Cell>, std::allocator<std::shared_ptr<TW::CommonTON::Cell>>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::shared_ptr" = type { %"class.std::__shared_ptr" }
%"class.std::__shared_ptr" = type { ptr, %"class.std::__shared_count" }
%"class.std::__shared_count" = type { ptr }
%"class.TW::CommonTON::StateInit" = type { %"class.std::shared_ptr", %"class.std::shared_ptr" }

declare void @_ZN2TW9CommonTON11CellBuilder12appendBitOneEv(ptr noundef nonnull align 8 dereferenceable(56)) #0

declare void @_ZN2TW9CommonTON11CellBuilder13appendBitZeroEv(ptr noundef nonnull align 8 dereferenceable(56)) #0

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK2TW9CommonTON9StateInit7writeToEv(ptr dead_on_unwind noalias writable sret(%"class.TW::CommonTON::CellBuilder") align 8 %0, ptr noundef nonnull align 8 dereferenceable(32) %1) #1 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i1, align 1
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca %"class.std::shared_ptr", align 8
  %9 = alloca %"class.std::shared_ptr", align 8
  store ptr %0, ptr %3, align 8
  store ptr %1, ptr %4, align 8, !tbaa !5
  %10 = load ptr, ptr %4, align 8
  store i1 false, ptr %5, align 1
  call void @_ZN2TW9CommonTON11CellBuilderC2Ev(ptr noundef nonnull align 8 dereferenceable(56) %0) #4
  invoke void @_ZN2TW9CommonTON11CellBuilder13appendBitZeroEv(ptr noundef nonnull align 8 dereferenceable(56) %0)
          to label %11 unwind label %21

11:                                               ; preds = %2
  invoke void @_ZN2TW9CommonTON11CellBuilder13appendBitZeroEv(ptr noundef nonnull align 8 dereferenceable(56) %0)
          to label %12 unwind label %21

12:                                               ; preds = %11
  invoke void @_ZN2TW9CommonTON11CellBuilder12appendBitOneEv(ptr noundef nonnull align 8 dereferenceable(56) %0)
          to label %13 unwind label %21

13:                                               ; preds = %12
  %14 = getelementptr inbounds %"class.TW::CommonTON::StateInit", ptr %10, i32 0, i32 0
  call void @_ZNSt10shared_ptrIN2TW9CommonTON4CellEEC2ERKS3_(ptr noundef nonnull align 8 dereferenceable(16) %8, ptr noundef nonnull align 8 dereferenceable(16) %14) #4
  invoke void @_ZN2TW9CommonTON11CellBuilder19appendReferenceCellESt10shared_ptrINS0_4CellEE(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr noundef %8)
          to label %15 unwind label %25

15:                                               ; preds = %13
  call void @_ZNSt12__shared_ptrIN2TW9CommonTON4CellELN9__gnu_cxx12_Lock_policyE2EED2Ev(ptr noundef nonnull align 8 dereferenceable(16) %8) #4
  invoke void @_ZN2TW9CommonTON11CellBuilder12appendBitOneEv(ptr noundef nonnull align 8 dereferenceable(56) %0)
          to label %16 unwind label %21

16:                                               ; preds = %15
  %17 = getelementptr inbounds %"class.TW::CommonTON::StateInit", ptr %10, i32 0, i32 1
  call void @_ZNSt10shared_ptrIN2TW9CommonTON4CellEEC2ERKS3_(ptr noundef nonnull align 8 dereferenceable(16) %9, ptr noundef nonnull align 8 dereferenceable(16) %17) #4
  invoke void @_ZN2TW9CommonTON11CellBuilder19appendReferenceCellESt10shared_ptrINS0_4CellEE(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr noundef %9)
          to label %18 unwind label %29

18:                                               ; preds = %16
  call void @_ZNSt12__shared_ptrIN2TW9CommonTON4CellELN9__gnu_cxx12_Lock_policyE2EED2Ev(ptr noundef nonnull align 8 dereferenceable(16) %9) #4
  invoke void @_ZN2TW9CommonTON11CellBuilder13appendBitZeroEv(ptr noundef nonnull align 8 dereferenceable(56) %0)
          to label %19 unwind label %21

19:                                               ; preds = %18
  store i1 true, ptr %5, align 1
  %20 = load i1, ptr %5, align 1
  br i1 %20, label %34, label %33

21:                                               ; preds = %18, %15, %12, %11, %2
  %22 = landingpad { ptr, i32 }
          cleanup
  %23 = extractvalue { ptr, i32 } %22, 0
  store ptr %23, ptr %6, align 8
  %24 = extractvalue { ptr, i32 } %22, 1
  store i32 %24, ptr %7, align 4
  br label %35

25:                                               ; preds = %13
  %26 = landingpad { ptr, i32 }
          cleanup
  %27 = extractvalue { ptr, i32 } %26, 0
  store ptr %27, ptr %6, align 8
  %28 = extractvalue { ptr, i32 } %26, 1
  store i32 %28, ptr %7, align 4
  call void @_ZNSt12__shared_ptrIN2TW9CommonTON4CellELN9__gnu_cxx12_Lock_policyE2EED2Ev(ptr noundef nonnull align 8 dereferenceable(16) %8) #4
  br label %35

29:                                               ; preds = %16
  %30 = landingpad { ptr, i32 }
          cleanup
  %31 = extractvalue { ptr, i32 } %30, 0
  store ptr %31, ptr %6, align 8
  %32 = extractvalue { ptr, i32 } %30, 1
  store i32 %32, ptr %7, align 4
  call void @_ZNSt12__shared_ptrIN2TW9CommonTON4CellELN9__gnu_cxx12_Lock_policyE2EED2Ev(ptr noundef nonnull align 8 dereferenceable(16) %9) #4
  br label %35

33:                                               ; preds = %19
  call void @_ZN2TW9CommonTON11CellBuilderD2Ev(ptr noundef nonnull align 8 dereferenceable(56) %0) #4
  br label %34

34:                                               ; preds = %33, %19
  ret void

35:                                               ; preds = %29, %25, %21
  call void @_ZN2TW9CommonTON11CellBuilderD2Ev(ptr noundef nonnull align 8 dereferenceable(56) %0) #4
  br label %36

36:                                               ; preds = %35
  %37 = load ptr, ptr %6, align 8
  %38 = load i32, ptr %7, align 4
  %39 = insertvalue { ptr, i32 } poison, ptr %37, 0
  %40 = insertvalue { ptr, i32 } %39, i32 %38, 1
  resume { ptr, i32 } %40
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN2TW9CommonTON11CellBuilderC2Ev(ptr noundef nonnull align 8 dereferenceable(56)) unnamed_addr #2 align 2

declare void @_ZN2TW9CommonTON11CellBuilder19appendReferenceCellESt10shared_ptrINS0_4CellEE(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt10shared_ptrIN2TW9CommonTON4CellEEC2ERKS3_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #2 align 2

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN2TW9CommonTON11CellBuilderD2Ev(ptr noundef nonnull align 8 dereferenceable(56)) unnamed_addr #3 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" }
attributes #2 = { 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 #3 = { inlinehint 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 #4 = { 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"}


; 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.TW::CommonTON::CellBuilder" = type { i16, %"class.std::vector", %"class.std::vector.0" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl" }
%"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl" = type { %"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl_data" }
%"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_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<std::shared_ptr<TW::CommonTON::Cell>, std::allocator<std::shared_ptr<TW::CommonTON::Cell>>>::_Vector_impl" }
%"struct.std::_Vector_base<std::shared_ptr<TW::CommonTON::Cell>, std::allocator<std::shared_ptr<TW::CommonTON::Cell>>>::_Vector_impl" = type { %"struct.std::_Vector_base<std::shared_ptr<TW::CommonTON::Cell>, std::allocator<std::shared_ptr<TW::CommonTON::Cell>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<std::shared_ptr<TW::CommonTON::Cell>, std::allocator<std::shared_ptr<TW::CommonTON::Cell>>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::shared_ptr" = type { %"class.std::__shared_ptr" }
%"class.std::__shared_ptr" = type { ptr, %"class.std::__shared_count" }
%"class.std::__shared_count" = type { ptr }

declare void @_ZN2TW9CommonTON11CellBuilder12appendBitOneEv(ptr noundef nonnull align 8 dereferenceable(56)) local_unnamed_addr #0

declare void @_ZN2TW9CommonTON11CellBuilder13appendBitZeroEv(ptr noundef nonnull align 8 dereferenceable(56)) local_unnamed_addr #0

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK2TW9CommonTON9StateInit7writeToEv(ptr dead_on_unwind noalias nonnull writable sret(%"class.TW::CommonTON::CellBuilder") align 8 %0, ptr noundef nonnull align 8 dereferenceable(32) %1) local_unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca %"class.std::shared_ptr", align 8
  %4 = alloca %"class.std::shared_ptr", align 8
  tail call void @_ZN2TW9CommonTON11CellBuilderC2Ev(ptr noundef nonnull align 8 dereferenceable(56) %0) #4
  invoke void @_ZN2TW9CommonTON11CellBuilder13appendBitZeroEv(ptr noundef nonnull align 8 dereferenceable(56) %0)
          to label %5 unwind label %12

5:                                                ; preds = %2
  invoke void @_ZN2TW9CommonTON11CellBuilder13appendBitZeroEv(ptr noundef nonnull align 8 dereferenceable(56) %0)
          to label %6 unwind label %12

6:                                                ; preds = %5
  invoke void @_ZN2TW9CommonTON11CellBuilder12appendBitOneEv(ptr noundef nonnull align 8 dereferenceable(56) %0)
          to label %7 unwind label %12

7:                                                ; preds = %6
  call void @_ZNSt10shared_ptrIN2TW9CommonTON4CellEEC2ERKS3_(ptr noundef nonnull align 8 dereferenceable(16) %3, ptr noundef nonnull align 8 dereferenceable(16) %1) #4
  invoke void @_ZN2TW9CommonTON11CellBuilder19appendReferenceCellESt10shared_ptrINS0_4CellEE(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr noundef nonnull %3)
          to label %8 unwind label %14

8:                                                ; preds = %7
  call void @_ZNSt12__shared_ptrIN2TW9CommonTON4CellELN9__gnu_cxx12_Lock_policyE2EED2Ev(ptr noundef nonnull align 8 dereferenceable(16) %3) #4
  invoke void @_ZN2TW9CommonTON11CellBuilder12appendBitOneEv(ptr noundef nonnull align 8 dereferenceable(56) %0)
          to label %9 unwind label %12

9:                                                ; preds = %8
  %10 = getelementptr inbounds i8, ptr %1, i64 16
  call void @_ZNSt10shared_ptrIN2TW9CommonTON4CellEEC2ERKS3_(ptr noundef nonnull align 8 dereferenceable(16) %4, ptr noundef nonnull align 8 dereferenceable(16) %10) #4
  invoke void @_ZN2TW9CommonTON11CellBuilder19appendReferenceCellESt10shared_ptrINS0_4CellEE(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr noundef nonnull %4)
          to label %11 unwind label %16

11:                                               ; preds = %9
  call void @_ZNSt12__shared_ptrIN2TW9CommonTON4CellELN9__gnu_cxx12_Lock_policyE2EED2Ev(ptr noundef nonnull align 8 dereferenceable(16) %4) #4
  invoke void @_ZN2TW9CommonTON11CellBuilder13appendBitZeroEv(ptr noundef nonnull align 8 dereferenceable(56) %0)
          to label %18 unwind label %12

12:                                               ; preds = %11, %8, %6, %5, %2
  %13 = landingpad { ptr, i32 }
          cleanup
  br label %19

14:                                               ; preds = %7
  %15 = landingpad { ptr, i32 }
          cleanup
  call void @_ZNSt12__shared_ptrIN2TW9CommonTON4CellELN9__gnu_cxx12_Lock_policyE2EED2Ev(ptr noundef nonnull align 8 dereferenceable(16) %3) #4
  br label %19

16:                                               ; preds = %9
  %17 = landingpad { ptr, i32 }
          cleanup
  call void @_ZNSt12__shared_ptrIN2TW9CommonTON4CellELN9__gnu_cxx12_Lock_policyE2EED2Ev(ptr noundef nonnull align 8 dereferenceable(16) %4) #4
  br label %19

18:                                               ; preds = %11
  ret void

19:                                               ; preds = %16, %14, %12
  %.pn = phi { ptr, i32 } [ %13, %12 ], [ %17, %16 ], [ %15, %14 ]
  call void @_ZN2TW9CommonTON11CellBuilderD2Ev(ptr noundef nonnull align 8 dereferenceable(56) %0) #4
  resume { ptr, i32 } %.pn
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN2TW9CommonTON11CellBuilderC2Ev(ptr noundef nonnull align 8 dereferenceable(56)) unnamed_addr #2 align 2

declare void @_ZN2TW9CommonTON11CellBuilder19appendReferenceCellESt10shared_ptrINS0_4CellEE(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt10shared_ptrIN2TW9CommonTON4CellEEC2ERKS3_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #2 align 2

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN2TW9CommonTON11CellBuilderD2Ev(ptr noundef nonnull align 8 dereferenceable(56)) unnamed_addr #3 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" }
attributes #2 = { 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 #3 = { inlinehint 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 #4 = { 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)"}


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