; 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::KeyAgreeRecipientInfo" = type { %"class.UapkiNS::Pkcs7::EnvelopedDataBuilder::RecipientInfoBase", ptr }
%"class.UapkiNS::Pkcs7::EnvelopedDataBuilder::RecipientInfoBase" = type { i32 }
%"struct.UapkiNS::AlgorithmIdentifier" = type { %"class.std::__cxx11::basic_string", 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.KeyAgreeRecipientInfo = type { %struct.ASN__PRIMITIVE_TYPE_s, %struct.OriginatorIdentifierOrKey, ptr, %struct.AlgorithmIdentifier, %struct.RecipientEncryptedKeys, %struct.asn_struct_ctx_s }
%struct.ASN__PRIMITIVE_TYPE_s = type { ptr, i32 }
%struct.OriginatorIdentifierOrKey = type { i32, %"union.OriginatorIdentifierOrKey::OriginatorIdentifierOrKey_u", %struct.asn_struct_ctx_s }
%"union.OriginatorIdentifierOrKey::OriginatorIdentifierOrKey_u" = type { %struct.IssuerAndSerialNumber }
%struct.IssuerAndSerialNumber = type { %struct.Name, %struct.ASN__PRIMITIVE_TYPE_s, %struct.asn_struct_ctx_s }
%struct.Name = type { i32, %"union.Name::Name_u", %struct.asn_struct_ctx_s }
%"union.Name::Name_u" = type { %struct.RDNSequence }
%struct.RDNSequence = type { %struct.anon.3, %struct.asn_struct_ctx_s }
%struct.anon.3 = type { ptr, i32, i32, ptr }
%struct.AlgorithmIdentifier = type { %struct.ASN__PRIMITIVE_TYPE_s, ptr, %struct.asn_struct_ctx_s }
%struct.RecipientEncryptedKeys = type { %struct.anon.7, %struct.asn_struct_ctx_s }
%struct.anon.7 = type { ptr, i32, i32, ptr }
%struct.asn_struct_ctx_s = type { i16, i16, i32, ptr, i64 }

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

; 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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare noundef ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5c_strEv(ptr noundef nonnull align 8 dereferenceable(32)) #2 align 2

declare ptr @asn_decode_ba_with_alloc(ptr noundef, ptr noundef) #1

declare ptr @get_ANY_desc() #1

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7UapkiNS5Pkcs720EnvelopedDataBuilder21KeyAgreeRecipientInfo25setKeyEncryptionAlgorithmERKNS_19AlgorithmIdentifierE(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull align 8 dereferenceable(40) %1) #3 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %7 = load ptr, ptr %4, align 8
  %8 = getelementptr inbounds %"class.UapkiNS::Pkcs7::EnvelopedDataBuilder::KeyAgreeRecipientInfo", ptr %7, i32 0, i32 1
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = icmp ne ptr %9, null
  br i1 %10, label %11, label %14

11:                                               ; preds = %2
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = call noundef zeroext i1 @_ZNK7UapkiNS19AlgorithmIdentifier9isPresentEv(ptr noundef nonnull align 8 dereferenceable(40) %12)
  br i1 %13, label %15, label %14

14:                                               ; preds = %11, %2
  store i32 4101, ptr %3, align 4
  br label %56

15:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !13
  br label %16

16:                                               ; preds = %15
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %"struct.UapkiNS::AlgorithmIdentifier", ptr %17, i32 0, i32 0
  %19 = call noundef ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5c_strEv(ptr noundef nonnull align 8 dereferenceable(32) %18) #4
  %20 = getelementptr inbounds %"class.UapkiNS::Pkcs7::EnvelopedDataBuilder::KeyAgreeRecipientInfo", ptr %7, i32 0, i32 1
  %21 = load ptr, ptr %20, align 8, !tbaa !9
  %22 = getelementptr inbounds %struct.KeyAgreeRecipientInfo, ptr %21, i32 0, i32 3
  %23 = getelementptr inbounds %struct.AlgorithmIdentifier, ptr %22, i32 0, i32 0
  %24 = call i32 @asn_set_oid_from_text(ptr noundef %19, ptr noundef %23)
  store i32 %24, ptr %6, align 4, !tbaa !13
  %25 = load i32, ptr %6, align 4, !tbaa !13
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %29

27:                                               ; preds = %16
  %28 = load i32, ptr %6, align 4, !tbaa !13
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 425, i32 noundef %28)
  br label %54

29:                                               ; preds = %16
  br label %30

30:                                               ; preds = %29
  br label %31

31:                                               ; preds = %30
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %"struct.UapkiNS::AlgorithmIdentifier", ptr %32, i32 0, i32 1
  %34 = load ptr, ptr %33, align 8, !tbaa !15
  %35 = icmp ne ptr %34, null
  br i1 %35, label %36, label %53

36:                                               ; preds = %31
  br label %37

37:                                               ; preds = %36
  %38 = call ptr @get_ANY_desc()
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds %"struct.UapkiNS::AlgorithmIdentifier", ptr %39, i32 0, i32 1
  %41 = load ptr, ptr %40, align 8, !tbaa !15
  %42 = call ptr @asn_decode_ba_with_alloc(ptr noundef %38, ptr noundef %41)
  %43 = getelementptr inbounds %"class.UapkiNS::Pkcs7::EnvelopedDataBuilder::KeyAgreeRecipientInfo", ptr %7, i32 0, i32 1
  %44 = load ptr, ptr %43, align 8, !tbaa !9
  %45 = getelementptr inbounds %struct.KeyAgreeRecipientInfo, ptr %44, i32 0, i32 3
  %46 = getelementptr inbounds %struct.AlgorithmIdentifier, ptr %45, i32 0, i32 1
  store ptr %42, ptr %46, align 8, !tbaa !20
  %47 = icmp eq ptr null, %42
  br i1 %47, label %48, label %50

48:                                               ; preds = %37
  store i32 2, ptr %6, align 4, !tbaa !13
  %49 = load i32, ptr %6, align 4, !tbaa !13
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 430, i32 noundef %49)
  br label %54

50:                                               ; preds = %37
  br label %51

51:                                               ; preds = %50
  br label %52

52:                                               ; preds = %51
  br label %53

53:                                               ; preds = %52, %31
  br label %54

54:                                               ; preds = %53, %48, %27
  %55 = load i32, ptr %6, align 4, !tbaa !13
  store i32 %55, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %56

56:                                               ; preds = %54, %14
  %57 = load i32, ptr %3, align 4
  ret i32 %57
}

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 = { 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 = { 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 }

!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, !6, i64 8}
!10 = !{!"_ZTSN7UapkiNS5Pkcs720EnvelopedDataBuilder21KeyAgreeRecipientInfoE", !11, i64 0, !6, i64 8}
!11 = !{!"_ZTSN7UapkiNS5Pkcs720EnvelopedDataBuilder17RecipientInfoBaseE", !12, i64 0}
!12 = !{!"_ZTS16RecipientInfo_PR", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!16, !6, i64 32}
!16 = !{!"_ZTSN7UapkiNS19AlgorithmIdentifierE", !17, i64 0, !6, i64 32}
!17 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !18, i64 0, !19, i64 8, !7, i64 16}
!18 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!19 = !{!"long", !7, i64 0}
!20 = !{!21, !6, i64 192}
!21 = !{!"_ZTS21KeyAgreeRecipientInfo", !22, i64 0, !23, i64 16, !6, i64 168, !27, i64 176, !28, i64 224, !25, i64 272}
!22 = !{!"_ZTS21ASN__PRIMITIVE_TYPE_s", !6, i64 0, !14, i64 8}
!23 = !{!"_ZTS25OriginatorIdentifierOrKey", !24, i64 0, !7, i64 8, !25, i64 128}
!24 = !{!"_ZTS28OriginatorIdentifierOrKey_PR", !7, i64 0}
!25 = !{!"_ZTS16asn_struct_ctx_s", !26, i64 0, !26, i64 2, !14, i64 4, !6, i64 8, !19, i64 16}
!26 = !{!"short", !7, i64 0}
!27 = !{!"_ZTS19AlgorithmIdentifier", !22, i64 0, !6, i64 16, !25, i64 24}
!28 = !{!"_ZTS22RecipientEncryptedKeys", !29, i64 0, !25, i64 24}
!29 = !{!"_ZTSN22RecipientEncryptedKeysUt_E", !6, i64 0, !14, i64 8, !14, i64 12, !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 @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 nounwind uwtable
declare noundef ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5c_strEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #1 align 2

declare ptr @asn_decode_ba_with_alloc(ptr noundef, ptr noundef) local_unnamed_addr #0

declare ptr @get_ANY_desc() local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK7UapkiNS19AlgorithmIdentifier9isPresentEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7UapkiNS5Pkcs720EnvelopedDataBuilder21KeyAgreeRecipientInfo25setKeyEncryptionAlgorithmERKNS_19AlgorithmIdentifierE(ptr nocapture noundef nonnull readonly align 8 dereferenceable(16) %0, ptr noundef nonnull align 8 dereferenceable(40) %1) local_unnamed_addr #2 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %24, label %5

5:                                                ; preds = %2
  %6 = tail call noundef zeroext i1 @_ZNK7UapkiNS19AlgorithmIdentifier9isPresentEv(ptr noundef nonnull align 8 dereferenceable(40) %1)
  br i1 %6, label %7, label %24

7:                                                ; preds = %5
  %8 = tail call noundef ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5c_strEv(ptr noundef nonnull align 8 dereferenceable(32) %1) #3
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %9, i64 176
  %11 = tail call i32 @asn_set_oid_from_text(ptr noundef %8, ptr noundef nonnull %10)
  %.not11 = icmp eq i32 %11, 0
  br i1 %.not11, label %13, label %12

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

13:                                               ; preds = %7
  %14 = getelementptr inbounds i8, ptr %1, i64 32
  %15 = load ptr, ptr %14, align 8, !tbaa !12
  %.not12 = icmp eq ptr %15, null
  br i1 %.not12, label %24, label %16

16:                                               ; preds = %13
  %17 = tail call ptr @get_ANY_desc()
  %18 = load ptr, ptr %14, align 8, !tbaa !12
  %19 = tail call ptr @asn_decode_ba_with_alloc(ptr noundef %17, ptr noundef %18)
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %20, i64 192
  store ptr %19, ptr %21, align 8, !tbaa !17
  %22 = icmp eq ptr %19, null
  br i1 %22, label %23, label %24

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

24:                                               ; preds = %12, %23, %16, %13, %2, %5
  %.09 = phi i32 [ 4101, %5 ], [ 4101, %2 ], [ %11, %12 ], [ 2, %23 ], [ 0, %16 ], [ 0, %13 ]
  ret i32 %.09
}

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 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 #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 }

!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, !11, i64 8}
!6 = !{!"_ZTSN7UapkiNS5Pkcs720EnvelopedDataBuilder21KeyAgreeRecipientInfoE", !7, i64 0, !11, i64 8}
!7 = !{!"_ZTSN7UapkiNS5Pkcs720EnvelopedDataBuilder17RecipientInfoBaseE", !8, i64 0}
!8 = !{!"_ZTS16RecipientInfo_PR", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"any pointer", !9, i64 0}
!12 = !{!13, !11, i64 32}
!13 = !{!"_ZTSN7UapkiNS19AlgorithmIdentifierE", !14, i64 0, !11, i64 32}
!14 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !15, i64 0, !16, i64 8, !9, i64 16}
!15 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !11, i64 0}
!16 = !{!"long", !9, i64 0}
!17 = !{!18, !11, i64 192}
!18 = !{!"_ZTS21KeyAgreeRecipientInfo", !19, i64 0, !21, i64 16, !11, i64 168, !25, i64 176, !26, i64 224, !23, i64 272}
!19 = !{!"_ZTS21ASN__PRIMITIVE_TYPE_s", !11, i64 0, !20, i64 8}
!20 = !{!"int", !9, i64 0}
!21 = !{!"_ZTS25OriginatorIdentifierOrKey", !22, i64 0, !9, i64 8, !23, i64 128}
!22 = !{!"_ZTS28OriginatorIdentifierOrKey_PR", !9, i64 0}
!23 = !{!"_ZTS16asn_struct_ctx_s", !24, i64 0, !24, i64 2, !20, i64 4, !11, i64 8, !16, i64 16}
!24 = !{!"short", !9, i64 0}
!25 = !{!"_ZTS19AlgorithmIdentifier", !19, i64 0, !11, i64 16, !23, i64 24}
!26 = !{!"_ZTS22RecipientEncryptedKeys", !27, i64 0, !23, i64 24}
!27 = !{!"_ZTSN22RecipientEncryptedKeysUt_E", !11, i64 0, !20, i64 8, !20, i64 12, !11, i64 16}


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