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

@.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

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

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7UapkiNS5Pkcs720EnvelopedDataBuilder21KeyAgreeRecipientInfo6setUkmEPK12ByteArray_st(ptr noundef nonnull align 8 dereferenceable(16) %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
  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 %12, label %11

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

12:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !13
  %13 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 40) #5
  %14 = getelementptr inbounds %"class.UapkiNS::Pkcs7::EnvelopedDataBuilder::KeyAgreeRecipientInfo", ptr %7, i32 0, i32 1
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  %16 = getelementptr inbounds %struct.KeyAgreeRecipientInfo, ptr %15, i32 0, i32 2
  store ptr %13, ptr %16, align 8, !tbaa !15
  br label %17

17:                                               ; preds = %12
  %18 = getelementptr inbounds %"class.UapkiNS::Pkcs7::EnvelopedDataBuilder::KeyAgreeRecipientInfo", ptr %7, i32 0, i32 1
  %19 = load ptr, ptr %18, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct.KeyAgreeRecipientInfo, ptr %19, i32 0, i32 2
  %21 = load ptr, ptr %20, align 8, !tbaa !15
  %22 = icmp eq ptr %21, null
  br i1 %22, label %23, label %25

23:                                               ; preds = %17
  store i32 1, ptr %6, align 4, !tbaa !13
  %24 = load i32, ptr %6, align 4, !tbaa !13
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 408, i32 noundef %24, ptr noundef null)
  br label %42

25:                                               ; preds = %17
  br label %26

26:                                               ; preds = %25
  br label %27

27:                                               ; preds = %26
  br label %28

28:                                               ; preds = %27
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %"class.UapkiNS::Pkcs7::EnvelopedDataBuilder::KeyAgreeRecipientInfo", ptr %7, i32 0, i32 1
  %31 = load ptr, ptr %30, align 8, !tbaa !9
  %32 = getelementptr inbounds %struct.KeyAgreeRecipientInfo, ptr %31, i32 0, i32 2
  %33 = load ptr, ptr %32, align 8, !tbaa !15
  %34 = call i32 @asn_ba2OCTSTRING(ptr noundef %29, ptr noundef %33)
  store i32 %34, ptr %6, align 4, !tbaa !13
  %35 = load i32, ptr %6, align 4, !tbaa !13
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %37, label %39

37:                                               ; preds = %28
  %38 = load i32, ptr %6, align 4, !tbaa !13
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 410, i32 noundef %38)
  br label %42

39:                                               ; preds = %28
  br label %40

40:                                               ; preds = %39
  br label %41

41:                                               ; preds = %40
  br label %42

42:                                               ; preds = %41, %37, %23
  %43 = load i32, ptr %6, align 4, !tbaa !13
  store i32 %43, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %44

44:                                               ; preds = %42, %11
  %45 = load i32, ptr %3, align 4
  ret i32 %45
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!16, !6, i64 168}
!16 = !{!"_ZTS21KeyAgreeRecipientInfo", !17, i64 0, !18, i64 16, !6, i64 168, !23, i64 176, !24, i64 224, !20, i64 272}
!17 = !{!"_ZTS21ASN__PRIMITIVE_TYPE_s", !6, i64 0, !14, i64 8}
!18 = !{!"_ZTS25OriginatorIdentifierOrKey", !19, i64 0, !7, i64 8, !20, i64 128}
!19 = !{!"_ZTS28OriginatorIdentifierOrKey_PR", !7, i64 0}
!20 = !{!"_ZTS16asn_struct_ctx_s", !21, i64 0, !21, i64 2, !14, i64 4, !6, i64 8, !22, i64 16}
!21 = !{!"short", !7, i64 0}
!22 = !{!"long", !7, i64 0}
!23 = !{!"_ZTS19AlgorithmIdentifier", !17, i64 0, !6, i64 16, !20, i64 24}
!24 = !{!"_ZTS22RecipientEncryptedKeys", !25, i64 0, !20, i64 24}
!25 = !{!"_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

; 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 #0

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7UapkiNS5Pkcs720EnvelopedDataBuilder21KeyAgreeRecipientInfo6setUkmEPK12ByteArray_st(ptr nocapture noundef nonnull readonly align 8 dereferenceable(16) %0, ptr noundef %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 %13, label %5

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

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

10:                                               ; preds = %5
  %11 = tail call i32 @asn_ba2OCTSTRING(ptr noundef %1, ptr noundef nonnull %6)
  %.not9 = icmp eq i32 %11, 0
  br i1 %.not9, label %13, label %12

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

13:                                               ; preds = %9, %12, %10, %2
  %.06 = phi i32 [ 4101, %2 ], [ 1, %9 ], [ %11, %12 ], [ 0, %10 ]
  ret i32 %.06
}

attributes #0 = { 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 #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 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 168}
!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,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass