; LLVM IR from specinfo-ua/UAPKI :: library/common/pkix (envelopeddata-helper)

; 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.UapkiNS::Pkcs7::EnvelopedDataBuilder" = type { %"struct.UapkiNS::Pkcs7::EncryptedContentInfo", ptr, %"class.std::vector", ptr }
%"struct.UapkiNS::Pkcs7::EncryptedContentInfo" = type { %"class.std::__cxx11::basic_string", %"struct.UapkiNS::AlgorithmIdentifier", ptr }
%"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] }
%"struct.UapkiNS::AlgorithmIdentifier" = type { %"class.std::__cxx11::basic_string", ptr }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<UapkiNS::Pkcs7::EnvelopedDataBuilder::RecipientInfoBase *, std::allocator<UapkiNS::Pkcs7::EnvelopedDataBuilder::RecipientInfoBase *>>::_Vector_impl" }
%"struct.std::_Vector_base<UapkiNS::Pkcs7::EnvelopedDataBuilder::RecipientInfoBase *, std::allocator<UapkiNS::Pkcs7::EnvelopedDataBuilder::RecipientInfoBase *>>::_Vector_impl" = type { %"struct.std::_Vector_base<UapkiNS::Pkcs7::EnvelopedDataBuilder::RecipientInfoBase *, std::allocator<UapkiNS::Pkcs7::EnvelopedDataBuilder::RecipientInfoBase *>>::_Vector_impl_data" }
%"struct.std::_Vector_base<UapkiNS::Pkcs7::EnvelopedDataBuilder::RecipientInfoBase *, std::allocator<UapkiNS::Pkcs7::EnvelopedDataBuilder::RecipientInfoBase *>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%struct.EnvelopedData = type { %struct.ASN__PRIMITIVE_TYPE_s, ptr, %struct.RecipientInfos, %struct.EncryptedContentInfo, ptr, %struct.asn_struct_ctx_s }
%struct.ASN__PRIMITIVE_TYPE_s = type { ptr, i32 }
%struct.RecipientInfos = type { %struct.anon, %struct.asn_struct_ctx_s }
%struct.anon = type { ptr, i32, i32, ptr }
%struct.EncryptedContentInfo = type { %struct.ASN__PRIMITIVE_TYPE_s, %struct.AlgorithmIdentifier, ptr, %struct.asn_struct_ctx_s }
%struct.AlgorithmIdentifier = type { %struct.ASN__PRIMITIVE_TYPE_s, ptr, %struct.asn_struct_ctx_s }
%struct.asn_struct_ctx_s = type { i16, i16, i32, ptr, 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: mustprogress uwtable
define dso_local noundef i32 @_ZN7UapkiNS5Pkcs720EnvelopedDataBuilder4initEj(ptr noundef nonnull align 8 dereferenceable(120) %0, i32 noundef %1) #1 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %7 = load ptr, ptr %4, align 8
  %8 = load i32, ptr %5, align 4, !tbaa !9
  %9 = icmp ugt i32 %8, 5
  br i1 %9, label %10, label %11

10:                                               ; preds = %2
  store i32 4101, ptr %3, align 4
  br label %26

11:                                               ; preds = %2
  %12 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 200) #4
  %13 = getelementptr inbounds %"class.UapkiNS::Pkcs7::EnvelopedDataBuilder", ptr %7, i32 0, i32 1
  store ptr %12, ptr %13, align 8, !tbaa !11
  %14 = getelementptr inbounds %"class.UapkiNS::Pkcs7::EnvelopedDataBuilder", ptr %7, i32 0, i32 1
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  %16 = icmp ne ptr %15, null
  br i1 %16, label %18, label %17

17:                                               ; preds = %11
  store i32 4097, ptr %3, align 4
  br label %26

18:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %19 = getelementptr inbounds %"class.UapkiNS::Pkcs7::EnvelopedDataBuilder", ptr %7, i32 0, i32 1
  %20 = load ptr, ptr %19, align 8, !tbaa !11
  %21 = getelementptr inbounds %struct.EnvelopedData, ptr %20, i32 0, i32 0
  %22 = load i32, ptr %5, align 4, !tbaa !9
  %23 = zext i32 %22 to i64
  %24 = call i32 @asn_ulong2INTEGER(ptr noundef %21, i64 noundef %23)
  store i32 %24, ptr %6, align 4, !tbaa !9
  %25 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %25, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %26

26:                                               ; preds = %18, %17, %10
  %27 = load i32, ptr %3, align 4
  ret i32 %27
}

; Function Attrs: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #2

declare i32 @asn_ulong2INTEGER(ptr noundef, i64 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nounwind allocsize(0,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 #3 = { "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 allocsize(0,1) }
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 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 80}
!12 = !{!"_ZTSN7UapkiNS5Pkcs720EnvelopedDataBuilderE", !13, i64 0, !6, i64 80, !18, i64 88, !6, i64 112}
!13 = !{!"_ZTSN7UapkiNS5Pkcs720EncryptedContentInfoE", !14, i64 0, !17, i64 32, !6, i64 72}
!14 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !15, i64 0, !16, i64 8, !7, i64 16}
!15 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!16 = !{!"long", !7, i64 0}
!17 = !{!"_ZTSN7UapkiNS19AlgorithmIdentifierE", !14, i64 0, !6, i64 32}
!18 = !{!"_ZTSSt6vectorIPN7UapkiNS5Pkcs720EnvelopedDataBuilder17RecipientInfoBaseESaIS4_EE", !19, i64 0}
!19 = !{!"_ZTSSt12_Vector_baseIPN7UapkiNS5Pkcs720EnvelopedDataBuilder17RecipientInfoBaseESaIS4_EE", !20, i64 0}
!20 = !{!"_ZTSNSt12_Vector_baseIPN7UapkiNS5Pkcs720EnvelopedDataBuilder17RecipientInfoBaseESaIS4_EE12_Vector_implE", !21, i64 0}
!21 = !{!"_ZTSNSt12_Vector_baseIPN7UapkiNS5Pkcs720EnvelopedDataBuilder17RecipientInfoBaseESaIS4_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}


; 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
define dso_local noundef i32 @_ZN7UapkiNS5Pkcs720EnvelopedDataBuilder4initEj(ptr nocapture noundef nonnull writeonly align 8 dereferenceable(120) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = icmp ugt i32 %1, 5
  br i1 %3, label %10, label %4

4:                                                ; preds = %2
  %5 = tail call noalias dereferenceable_or_null(200) ptr @calloc(i64 noundef 1, i64 noundef 200) #3
  %6 = getelementptr inbounds i8, ptr %0, i64 80
  store ptr %5, ptr %6, align 8, !tbaa !5
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %10, label %7

7:                                                ; preds = %4
  %8 = zext nneg i32 %1 to i64
  %9 = tail call i32 @asn_ulong2INTEGER(ptr noundef nonnull %5, i64 noundef %8)
  br label %10

10:                                               ; preds = %4, %2, %7
  %.0 = phi i32 [ %9, %7 ], [ 4101, %2 ], [ 4097, %4 ]
  ret i32 %.0
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #1

declare i32 @asn_ulong2INTEGER(ptr noundef, i64 noundef) local_unnamed_addr #2

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 = { mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { nounwind allocsize(0,1) }

!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, !10, i64 80}
!6 = !{!"_ZTSN7UapkiNS5Pkcs720EnvelopedDataBuilderE", !7, i64 0, !10, i64 80, !15, i64 88, !10, i64 112}
!7 = !{!"_ZTSN7UapkiNS5Pkcs720EncryptedContentInfoE", !8, i64 0, !14, i64 32, !10, i64 72}
!8 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !9, i64 0, !13, i64 8, !11, i64 16}
!9 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !10, i64 0}
!10 = !{!"any pointer", !11, i64 0}
!11 = !{!"omnipotent char", !12, i64 0}
!12 = !{!"Simple C++ TBAA"}
!13 = !{!"long", !11, i64 0}
!14 = !{!"_ZTSN7UapkiNS19AlgorithmIdentifierE", !8, i64 0, !10, i64 32}
!15 = !{!"_ZTSSt6vectorIPN7UapkiNS5Pkcs720EnvelopedDataBuilder17RecipientInfoBaseESaIS4_EE", !16, i64 0}
!16 = !{!"_ZTSSt12_Vector_baseIPN7UapkiNS5Pkcs720EnvelopedDataBuilder17RecipientInfoBaseESaIS4_EE", !17, i64 0}
!17 = !{!"_ZTSNSt12_Vector_baseIPN7UapkiNS5Pkcs720EnvelopedDataBuilder17RecipientInfoBaseESaIS4_EE12_Vector_implE", !18, i64 0}
!18 = !{!"_ZTSNSt12_Vector_baseIPN7UapkiNS5Pkcs720EnvelopedDataBuilder17RecipientInfoBaseESaIS4_EE17_Vector_impl_dataE", !10, i64 0, !10, i64 8, !10, i64 16}


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