; 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::Pkcs7::RecipientEncryptedKey" = type { ptr, ptr }
%struct.RecipientEncryptedKey = type { %struct.KeyAgreeRecipientIdentifier, %struct.OCTET_STRING, %struct.asn_struct_ctx_s }
%struct.KeyAgreeRecipientIdentifier = type { i32, %"union.KeyAgreeRecipientIdentifier::KeyAgreeRecipientIdentifier_u", %struct.asn_struct_ctx_s }
%"union.KeyAgreeRecipientIdentifier::KeyAgreeRecipientIdentifier_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.ASN__PRIMITIVE_TYPE_s = type { ptr, i32 }
%struct.OCTET_STRING = type { ptr, i32, %struct.asn_struct_ctx_s }
%struct.asn_struct_ctx_s = type { i16, i16, i32, ptr, i64 }
%struct.KeyAgreeRecipientInfo = type { %struct.ASN__PRIMITIVE_TYPE_s, %struct.OriginatorIdentifierOrKey, ptr, %struct.AlgorithmIdentifier, %struct.RecipientEncryptedKeys, %struct.asn_struct_ctx_s }
%struct.OriginatorIdentifierOrKey = type { i32, %"union.OriginatorIdentifierOrKey::OriginatorIdentifierOrKey_u", %struct.asn_struct_ctx_s }
%"union.OriginatorIdentifierOrKey::OriginatorIdentifierOrKey_u" = type { %struct.IssuerAndSerialNumber }
%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 }

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

declare void @asn_free(ptr noundef, ptr noundef) #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 i32 @asn_decode_ba(ptr noundef, ptr noundef, ptr noundef) #0

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7UapkiNS5Pkcs720EnvelopedDataBuilder21KeyAgreeRecipientInfo24addRecipientEncryptedKeyERKNS0_21RecipientEncryptedKeyE(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull align 8 dereferenceable(16) %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
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %8 = load ptr, ptr %4, align 8
  %9 = getelementptr inbounds %"class.UapkiNS::Pkcs7::EnvelopedDataBuilder::KeyAgreeRecipientInfo", ptr %8, i32 0, i32 1
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %22

12:                                               ; preds = %2
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %"struct.UapkiNS::Pkcs7::RecipientEncryptedKey", ptr %13, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !13
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %22

17:                                               ; preds = %12
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %"struct.UapkiNS::Pkcs7::RecipientEncryptedKey", ptr %18, i32 0, i32 1
  %20 = load ptr, ptr %19, align 8, !tbaa !15
  %21 = icmp ne ptr %20, null
  br i1 %21, label %23, label %22

22:                                               ; preds = %17, %12, %2
  store i32 4101, ptr %3, align 4
  br label %71

23:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store ptr null, ptr %7, align 8, !tbaa !5
  %24 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 216) #5
  store ptr %24, ptr %7, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %23
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = icmp eq ptr %26, null
  br i1 %27, label %28, label %30

28:                                               ; preds = %25
  store i32 1, ptr %6, align 4, !tbaa !16
  %29 = load i32, ptr %6, align 4, !tbaa !16
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 446, i32 noundef %29, ptr noundef null)
  br label %67

30:                                               ; preds = %25
  br label %31

31:                                               ; preds = %30
  br label %32

32:                                               ; preds = %31
  br label %33

33:                                               ; preds = %32
  %34 = call ptr @get_KeyAgreeRecipientIdentifier_desc()
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.RecipientEncryptedKey, ptr %35, i32 0, i32 0
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %"struct.UapkiNS::Pkcs7::RecipientEncryptedKey", ptr %37, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !13
  %40 = call i32 @asn_decode_ba(ptr noundef %34, ptr noundef %36, ptr noundef %39)
  store i32 %40, ptr %6, align 4, !tbaa !16
  %41 = load i32, ptr %6, align 4, !tbaa !16
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %43, label %45

43:                                               ; preds = %33
  %44 = load i32, ptr %6, align 4, !tbaa !16
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 449, i32 noundef %44)
  br label %67

45:                                               ; preds = %33
  br label %46

46:                                               ; preds = %45
  br label %47

47:                                               ; preds = %46
  br label %48

48:                                               ; preds = %47
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %"struct.UapkiNS::Pkcs7::RecipientEncryptedKey", ptr %49, i32 0, i32 1
  %51 = load ptr, ptr %50, align 8, !tbaa !15
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.RecipientEncryptedKey, ptr %52, i32 0, i32 1
  %54 = call i32 @asn_ba2OCTSTRING(ptr noundef %51, ptr noundef %53)
  store i32 %54, ptr %6, align 4, !tbaa !16
  %55 = load i32, ptr %6, align 4, !tbaa !16
  %56 = icmp ne i32 %55, 0
  br i1 %56, label %57, label %59

57:                                               ; preds = %48
  %58 = load i32, ptr %6, align 4, !tbaa !16
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 452, i32 noundef %58)
  br label %67

59:                                               ; preds = %48
  br label %60

60:                                               ; preds = %59
  br label %61

61:                                               ; preds = %60
  %62 = getelementptr inbounds %"class.UapkiNS::Pkcs7::EnvelopedDataBuilder::KeyAgreeRecipientInfo", ptr %8, i32 0, i32 1
  %63 = load ptr, ptr %62, align 8, !tbaa !9
  %64 = getelementptr inbounds %struct.KeyAgreeRecipientInfo, ptr %63, i32 0, i32 4
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = call i32 @asn_set_add(ptr noundef %64, ptr noundef %65)
  store ptr null, ptr %7, align 8, !tbaa !5
  br label %67

67:                                               ; preds = %61, %57, %43, %28
  %68 = call ptr @get_RecipientEncryptedKey_desc()
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  call void @asn_free(ptr noundef %68, ptr noundef %69)
  %70 = load i32, ptr %6, align 4, !tbaa !16
  store i32 %70, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %71

71:                                               ; preds = %67, %22
  %72 = load i32, ptr %3, align 4
  ret i32 %72
}

declare ptr @get_KeyAgreeRecipientIdentifier_desc() #0

declare ptr @get_RecipientEncryptedKey_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, !6, i64 8}
!10 = !{!"_ZTSN7UapkiNS5Pkcs720EnvelopedDataBuilder21KeyAgreeRecipientInfoE", !11, i64 0, !6, i64 8}
!11 = !{!"_ZTSN7UapkiNS5Pkcs720EnvelopedDataBuilder17RecipientInfoBaseE", !12, i64 0}
!12 = !{!"_ZTS16RecipientInfo_PR", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"_ZTSN7UapkiNS5Pkcs721RecipientEncryptedKeyE", !6, i64 0, !6, i64 8}
!15 = !{!14, !6, i64 8}
!16 = !{!17, !17, i64 0}
!17 = !{!"int", !7, i64 0}


; 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

; 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 i32 @asn_decode_ba(ptr noundef, ptr 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_add(ptr noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7UapkiNS5Pkcs720EnvelopedDataBuilder21KeyAgreeRecipientInfo24addRecipientEncryptedKeyERKNS0_21RecipientEncryptedKeyE(ptr nocapture noundef nonnull readonly align 8 dereferenceable(16) %0, ptr nocapture noundef nonnull readonly align 8 dereferenceable(16) %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
  %5 = load ptr, ptr %1, align 8
  %.not22 = icmp eq ptr %5, null
  %or.cond = select i1 %.not, i1 true, i1 %.not22
  br i1 %or.cond, label %29, label %6

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %1, i64 8
  %8 = load ptr, ptr %7, align 8, !tbaa !12
  %.not23 = icmp eq ptr %8, null
  br i1 %.not23, label %29, label %9

9:                                                ; preds = %6
  %10 = tail call noalias dereferenceable_or_null(216) ptr @calloc(i64 noundef 1, i64 noundef 216) #3
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %13

12:                                               ; preds = %9
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 446, i32 noundef 1, ptr noundef null)
  br label %27

13:                                               ; preds = %9
  %14 = tail call ptr @get_KeyAgreeRecipientIdentifier_desc()
  %15 = load ptr, ptr %1, align 8, !tbaa !14
  %16 = tail call i32 @asn_decode_ba(ptr noundef %14, ptr noundef nonnull %10, ptr noundef %15)
  %.not24 = icmp eq i32 %16, 0
  br i1 %.not24, label %18, label %17

17:                                               ; preds = %13
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 449, i32 noundef %16)
  br label %27

18:                                               ; preds = %13
  %19 = load ptr, ptr %7, align 8, !tbaa !12
  %20 = getelementptr inbounds i8, ptr %10, i64 152
  %21 = tail call i32 @asn_ba2OCTSTRING(ptr noundef %19, ptr noundef nonnull %20)
  %.not25 = icmp eq i32 %21, 0
  br i1 %.not25, label %23, label %22

22:                                               ; preds = %18
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 452, i32 noundef %21)
  br label %27

23:                                               ; preds = %18
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %24, i64 224
  %26 = tail call i32 @asn_set_add(ptr noundef nonnull %25, ptr noundef nonnull %10)
  br label %27

27:                                               ; preds = %23, %22, %17, %12
  %.016 = phi i32 [ 1, %12 ], [ %16, %17 ], [ %21, %22 ], [ 0, %23 ]
  %.0 = phi ptr [ null, %12 ], [ %10, %17 ], [ %10, %22 ], [ null, %23 ]
  %28 = tail call ptr @get_RecipientEncryptedKey_desc()
  tail call void @asn_free(ptr noundef %28, ptr noundef %.0)
  br label %29

29:                                               ; preds = %2, %6, %27
  %.017 = phi i32 [ %.016, %27 ], [ 4101, %6 ], [ 4101, %2 ]
  ret i32 %.017
}

declare ptr @get_KeyAgreeRecipientIdentifier_desc() local_unnamed_addr #0

declare ptr @get_RecipientEncryptedKey_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, !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 8}
!13 = !{!"_ZTSN7UapkiNS5Pkcs721RecipientEncryptedKeyE", !11, i64 0, !11, i64 8}
!14 = !{!13, !11, i64 0}


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