; 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.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 }

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

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

10:                                               ; preds = %2
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  br i1 %12, label %14, label %13

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

14:                                               ; preds = %10
  %15 = getelementptr inbounds %"class.UapkiNS::Pkcs7::EnvelopedDataBuilder::KeyAgreeRecipientInfo", ptr %6, i32 0, i32 1
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  %17 = getelementptr inbounds %struct.KeyAgreeRecipientInfo, ptr %16, i32 0, i32 1
  %18 = getelementptr inbounds %struct.OriginatorIdentifierOrKey, ptr %17, i32 0, i32 0
  store i32 2, ptr %18, align 8, !tbaa !13
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %"class.UapkiNS::Pkcs7::EnvelopedDataBuilder::KeyAgreeRecipientInfo", ptr %6, i32 0, i32 1
  %21 = load ptr, ptr %20, align 8, !tbaa !9
  %22 = getelementptr inbounds %struct.KeyAgreeRecipientInfo, ptr %21, i32 0, i32 1
  %23 = getelementptr inbounds %struct.OriginatorIdentifierOrKey, ptr %22, i32 0, i32 1
  %24 = call i32 @asn_ba2OCTSTRING(ptr noundef %19, ptr noundef %23)
  store i32 %24, ptr %3, align 4
  br label %25

25:                                               ; preds = %14, %13
  %26 = load i32, ptr %3, align 4
  ret i32 %26
}

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

!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, !18, i64 16}
!14 = !{!"_ZTS21KeyAgreeRecipientInfo", !15, i64 0, !17, i64 16, !6, i64 168, !22, i64 176, !23, i64 224, !19, i64 272}
!15 = !{!"_ZTS21ASN__PRIMITIVE_TYPE_s", !6, i64 0, !16, i64 8}
!16 = !{!"int", !7, i64 0}
!17 = !{!"_ZTS25OriginatorIdentifierOrKey", !18, i64 0, !7, i64 8, !19, i64 128}
!18 = !{!"_ZTS28OriginatorIdentifierOrKey_PR", !7, i64 0}
!19 = !{!"_ZTS16asn_struct_ctx_s", !20, i64 0, !20, i64 2, !16, i64 4, !6, i64 8, !21, i64 16}
!20 = !{!"short", !7, i64 0}
!21 = !{!"long", !7, i64 0}
!22 = !{!"_ZTS19AlgorithmIdentifier", !15, i64 0, !6, i64 16, !19, i64 24}
!23 = !{!"_ZTS22RecipientEncryptedKeys", !24, i64 0, !19, i64 24}
!24 = !{!"_ZTSN22RecipientEncryptedKeysUt_E", !6, i64 0, !16, i64 8, !16, 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"

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7UapkiNS5Pkcs720EnvelopedDataBuilder21KeyAgreeRecipientInfo27setOriginatorBySubjectKeyIdEPK12ByteArray_st(ptr nocapture noundef nonnull readonly align 8 dereferenceable(16) %0, ptr noundef %1) local_unnamed_addr #1 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %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 %11

7:                                                ; preds = %2
  %8 = getelementptr inbounds i8, ptr %4, i64 16
  store i32 2, ptr %8, align 8, !tbaa !12
  %9 = getelementptr inbounds i8, ptr %4, i64 24
  %10 = tail call i32 @asn_ba2OCTSTRING(ptr noundef nonnull %1, ptr noundef nonnull %9)
  br label %11

11:                                               ; preds = %2, %7
  %.0 = phi i32 [ %10, %7 ], [ 4101, %2 ]
  ret i32 %.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 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" }

!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, !17, i64 16}
!13 = !{!"_ZTS21KeyAgreeRecipientInfo", !14, i64 0, !16, i64 16, !11, i64 168, !21, i64 176, !22, i64 224, !18, i64 272}
!14 = !{!"_ZTS21ASN__PRIMITIVE_TYPE_s", !11, i64 0, !15, i64 8}
!15 = !{!"int", !9, i64 0}
!16 = !{!"_ZTS25OriginatorIdentifierOrKey", !17, i64 0, !9, i64 8, !18, i64 128}
!17 = !{!"_ZTS28OriginatorIdentifierOrKey_PR", !9, i64 0}
!18 = !{!"_ZTS16asn_struct_ctx_s", !19, i64 0, !19, i64 2, !15, i64 4, !11, i64 8, !20, i64 16}
!19 = !{!"short", !9, i64 0}
!20 = !{!"long", !9, i64 0}
!21 = !{!"_ZTS19AlgorithmIdentifier", !14, i64 0, !11, i64 16, !18, i64 24}
!22 = !{!"_ZTS22RecipientEncryptedKeys", !23, i64 0, !18, i64 24}
!23 = !{!"_ZTSN22RecipientEncryptedKeysUt_E", !11, i64 0, !15, i64 8, !15, i64 12, !11, i64 16}


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