; 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.ContentInfo = type { %struct.ASN__PRIMITIVE_TYPE_s, %struct.ANY, %struct.asn_struct_ctx_s }
%struct.ASN__PRIMITIVE_TYPE_s = type { ptr, i32 }
%struct.ANY = type { ptr, i32, %struct.asn_struct_ctx_s }
%struct.asn_struct_ctx_s = type { i16, i16, i32, ptr, i64 }

@.str = external hidden unnamed_addr constant [37 x i8], align 1

declare void @asn_free(ptr noundef, ptr noundef) #0

declare ptr @get_EnvelopedData_desc() #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: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #2

declare void @stacktrace_create(ptr noundef, i64 noundef, i32 noundef, ptr noundef) #0

declare void @stacktrace_add(ptr noundef, i64 noundef, i32 noundef) #0

declare i32 @asn_set_oid_from_text(ptr noundef, ptr noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7UapkiNS5Pkcs720EnvelopedDataBuilder6encodeEPKc(ptr noundef nonnull align 8 dereferenceable(120) %0, ptr noundef %1) #3 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store ptr null, ptr %7, align 8, !tbaa !5
  %10 = getelementptr inbounds %"class.UapkiNS::Pkcs7::EnvelopedDataBuilder", ptr %9, i32 0, i32 1
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  %12 = icmp ne ptr %11, null
  br i1 %12, label %13, label %16

13:                                               ; preds = %2
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %17, label %16

16:                                               ; preds = %13, %2
  store i32 4101, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %69

17:                                               ; preds = %13
  %18 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 80) #5
  store ptr %18, ptr %7, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %17
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = icmp eq ptr %20, null
  br i1 %21, label %22, label %24

22:                                               ; preds = %19
  store i32 1, ptr %6, align 4, !tbaa !9
  %23 = load i32, ptr %6, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 269, i32 noundef %23, ptr noundef null)
  br label %65

24:                                               ; preds = %19
  br label %25

25:                                               ; preds = %24
  br label %26

26:                                               ; preds = %25
  br label %27

27:                                               ; preds = %26
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.ContentInfo, ptr %29, i32 0, i32 0
  %31 = call i32 @asn_set_oid_from_text(ptr noundef %28, ptr noundef %30)
  store i32 %31, ptr %6, align 4, !tbaa !9
  %32 = load i32, ptr %6, align 4, !tbaa !9
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %34, label %36

34:                                               ; preds = %27
  %35 = load i32, ptr %6, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 270, i32 noundef %35)
  br label %65

36:                                               ; preds = %27
  br label %37

37:                                               ; preds = %36
  br label %38

38:                                               ; preds = %37
  br label %39

39:                                               ; preds = %38
  %40 = call ptr @get_EnvelopedData_desc()
  %41 = getelementptr inbounds %"class.UapkiNS::Pkcs7::EnvelopedDataBuilder", ptr %9, i32 0, i32 1
  %42 = load ptr, ptr %41, align 8, !tbaa !11
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.ContentInfo, ptr %43, i32 0, i32 1
  %45 = call i32 @asn_set_any(ptr noundef %40, ptr noundef %42, ptr noundef %44)
  store i32 %45, ptr %6, align 4, !tbaa !9
  %46 = load i32, ptr %6, align 4, !tbaa !9
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %48, label %50

48:                                               ; preds = %39
  %49 = load i32, ptr %6, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 271, i32 noundef %49)
  br label %65

50:                                               ; preds = %39
  br label %51

51:                                               ; preds = %50
  br label %52

52:                                               ; preds = %51
  br label %53

53:                                               ; preds = %52
  %54 = call ptr @get_ContentInfo_desc()
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = getelementptr inbounds %"class.UapkiNS::Pkcs7::EnvelopedDataBuilder", ptr %9, i32 0, i32 3
  %57 = call i32 @asn_encode_ba(ptr noundef %54, ptr noundef %55, ptr noundef %56)
  store i32 %57, ptr %6, align 4, !tbaa !9
  %58 = load i32, ptr %6, align 4, !tbaa !9
  %59 = icmp ne i32 %58, 0
  br i1 %59, label %60, label %62

60:                                               ; preds = %53
  %61 = load i32, ptr %6, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 273, i32 noundef %61)
  br label %65

62:                                               ; preds = %53
  br label %63

63:                                               ; preds = %62
  br label %64

64:                                               ; preds = %63
  br label %65

65:                                               ; preds = %64, %60, %48, %34, %22
  %66 = call ptr @get_ContentInfo_desc()
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  call void @asn_free(ptr noundef %66, ptr noundef %67)
  %68 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %68, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %69

69:                                               ; preds = %65, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %70 = load i32, ptr %3, align 4
  ret i32 %70
}

declare i32 @asn_set_any(ptr noundef, ptr noundef, ptr noundef) #0

declare i32 @asn_encode_ba(ptr noundef, ptr noundef, ptr noundef) #0

declare ptr @get_ContentInfo_desc() #0

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 = { 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 = { 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 }
attributes #5 = { 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, !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"

@.str = external hidden unnamed_addr constant [37 x i8], align 1

declare void @asn_free(ptr noundef, ptr noundef) local_unnamed_addr #0

declare ptr @get_EnvelopedData_desc() local_unnamed_addr #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 void @stacktrace_create(ptr noundef, i64 noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

declare void @stacktrace_add(ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #0

declare i32 @asn_set_oid_from_text(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7UapkiNS5Pkcs720EnvelopedDataBuilder6encodeEPKc(ptr noundef nonnull align 8 dereferenceable(120) %0, ptr noundef %1) local_unnamed_addr #2 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 80
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = icmp ne ptr %4, null
  %6 = icmp ne ptr %1, null
  %or.cond = and i1 %6, %5
  br i1 %or.cond, label %7, label %27

7:                                                ; preds = %2
  %8 = tail call noalias dereferenceable_or_null(80) ptr @calloc(i64 noundef 1, i64 noundef 80) #3
  %9 = icmp eq ptr %8, null
  br i1 %9, label %10, label %11

10:                                               ; preds = %7
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 269, i32 noundef 1, ptr noundef null)
  br label %25

11:                                               ; preds = %7
  %12 = tail call i32 @asn_set_oid_from_text(ptr noundef nonnull %1, ptr noundef nonnull %8)
  %.not = icmp eq i32 %12, 0
  br i1 %.not, label %14, label %13

13:                                               ; preds = %11
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 270, i32 noundef %12)
  br label %25

14:                                               ; preds = %11
  %15 = tail call ptr @get_EnvelopedData_desc()
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %8, i64 16
  %18 = tail call i32 @asn_set_any(ptr noundef %15, ptr noundef %16, ptr noundef nonnull %17)
  %.not23 = icmp eq i32 %18, 0
  br i1 %.not23, label %20, label %19

19:                                               ; preds = %14
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 271, i32 noundef %18)
  br label %25

20:                                               ; preds = %14
  %21 = tail call ptr @get_ContentInfo_desc()
  %22 = getelementptr inbounds i8, ptr %0, i64 112
  %23 = tail call i32 @asn_encode_ba(ptr noundef %21, ptr noundef nonnull %8, ptr noundef nonnull %22)
  %.not24 = icmp eq i32 %23, 0
  br i1 %.not24, label %25, label %24

24:                                               ; preds = %20
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 273, i32 noundef %23)
  br label %25

25:                                               ; preds = %20, %24, %19, %13, %10
  %.0 = phi i32 [ 1, %10 ], [ %12, %13 ], [ %18, %19 ], [ %23, %24 ], [ 0, %20 ]
  %26 = tail call ptr @get_ContentInfo_desc()
  tail call void @asn_free(ptr noundef %26, ptr noundef %8)
  br label %27

27:                                               ; preds = %2, %25
  %.017 = phi i32 [ %.0, %25 ], [ 4101, %2 ]
  ret i32 %.017
}

declare i32 @asn_set_any(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

declare i32 @asn_encode_ba(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

declare ptr @get_ContentInfo_desc() local_unnamed_addr #0

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 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 = { 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 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,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass