; 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::EnvelopedDataParser::KeyAgreeRecipientIdentifier" = type { ptr }
%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.asn_struct_ctx_s = type { i16, i16, i32, ptr, i64 }

; 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 @ba_free(ptr noundef) #1

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZNK7UapkiNS5Pkcs719EnvelopedDataParser27KeyAgreeRecipientIdentifier13toIssuerAndSNEPP12ByteArray_stS5_(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef %1, ptr noundef %2) #2 align 2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  %10 = load ptr, ptr %5, align 8
  %11 = getelementptr inbounds %"class.UapkiNS::Pkcs7::EnvelopedDataParser::KeyAgreeRecipientIdentifier", ptr %10, i32 0, i32 0
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %13 = getelementptr inbounds %struct.KeyAgreeRecipientIdentifier, ptr %12, i32 0, i32 0
  %14 = load i32, ptr %13, align 8, !tbaa !11
  %15 = icmp ne i32 %14, 1
  br i1 %15, label %16, label %17

16:                                               ; preds = %3
  store i32 4145, ptr %4, align 4
  br label %44

17:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %18 = call ptr @get_Name_desc()
  %19 = getelementptr inbounds %"class.UapkiNS::Pkcs7::EnvelopedDataParser::KeyAgreeRecipientIdentifier", ptr %10, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !9
  %21 = getelementptr inbounds %struct.KeyAgreeRecipientIdentifier, ptr %20, i32 0, i32 1
  %22 = getelementptr inbounds %struct.IssuerAndSerialNumber, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = call i32 @asn_encode_ba(ptr noundef %18, ptr noundef %22, ptr noundef %23)
  store i32 %24, ptr %8, align 4, !tbaa !18
  %25 = load i32, ptr %8, align 4, !tbaa !18
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %29

27:                                               ; preds = %17
  %28 = load i32, ptr %8, align 4, !tbaa !18
  store i32 %28, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %43

29:                                               ; preds = %17
  %30 = getelementptr inbounds %"class.UapkiNS::Pkcs7::EnvelopedDataParser::KeyAgreeRecipientIdentifier", ptr %10, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !9
  %32 = getelementptr inbounds %struct.KeyAgreeRecipientIdentifier, ptr %31, i32 0, i32 1
  %33 = getelementptr inbounds %struct.IssuerAndSerialNumber, ptr %32, i32 0, i32 1
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = call i32 @asn_INTEGER2ba(ptr noundef %33, ptr noundef %34)
  store i32 %35, ptr %8, align 4, !tbaa !18
  %36 = load i32, ptr %8, align 4, !tbaa !18
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %41

38:                                               ; preds = %29
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = load ptr, ptr %39, align 8, !tbaa !5
  call void @ba_free(ptr noundef %40)
  br label %41

41:                                               ; preds = %38, %29
  %42 = load i32, ptr %8, align 4, !tbaa !18
  store i32 %42, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %43

43:                                               ; preds = %41, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %44

44:                                               ; preds = %43, %16
  %45 = load i32, ptr %4, align 4
  ret i32 %45
}

declare ptr @get_Name_desc() #1

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

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 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTSN7UapkiNS5Pkcs719EnvelopedDataParser27KeyAgreeRecipientIdentifierE", !6, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"_ZTS27KeyAgreeRecipientIdentifier", !13, i64 0, !7, i64 8, !14, i64 128}
!13 = !{!"_ZTS30KeyAgreeRecipientIdentifier_PR", !7, i64 0}
!14 = !{!"_ZTS16asn_struct_ctx_s", !15, i64 0, !15, i64 2, !16, i64 4, !6, i64 8, !17, i64 16}
!15 = !{!"short", !7, i64 0}
!16 = !{!"int", !7, i64 0}
!17 = !{!"long", !7, i64 0}
!18 = !{!16, !16, 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"

declare void @ba_free(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZNK7UapkiNS5Pkcs719EnvelopedDataParser27KeyAgreeRecipientIdentifier13toIssuerAndSNEPP12ByteArray_stS5_(ptr nocapture noundef nonnull readonly align 8 dereferenceable(8) %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #1 align 2 {
  %4 = load ptr, ptr %0, align 8, !tbaa !5
  %5 = load i32, ptr %4, align 8, !tbaa !10
  %.not = icmp eq i32 %5, 1
  br i1 %.not, label %6, label %17

6:                                                ; preds = %3
  %7 = tail call ptr @get_Name_desc()
  %8 = load ptr, ptr %0, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %8, i64 8
  %10 = tail call i32 @asn_encode_ba(ptr noundef %7, ptr noundef nonnull %9, ptr noundef %1)
  %.not9 = icmp eq i32 %10, 0
  br i1 %.not9, label %11, label %17

11:                                               ; preds = %6
  %12 = load ptr, ptr %0, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %12, i64 88
  %14 = tail call i32 @asn_INTEGER2ba(ptr noundef nonnull %13, ptr noundef %2)
  %.not10 = icmp eq i32 %14, 0
  br i1 %.not10, label %17, label %15

15:                                               ; preds = %11
  %16 = load ptr, ptr %1, align 8, !tbaa !17
  tail call void @ba_free(ptr noundef %16)
  br label %17

17:                                               ; preds = %6, %15, %11, %3
  %.1 = phi i32 [ 4145, %3 ], [ %10, %6 ], [ %14, %15 ], [ 0, %11 ]
  ret i32 %.1
}

declare ptr @get_Name_desc() local_unnamed_addr #0

declare i32 @asn_INTEGER2ba(ptr noundef, ptr noundef) 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 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, !7, i64 0}
!6 = !{!"_ZTSN7UapkiNS5Pkcs719EnvelopedDataParser27KeyAgreeRecipientIdentifierE", !7, i64 0}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!11, !12, i64 0}
!11 = !{!"_ZTS27KeyAgreeRecipientIdentifier", !12, i64 0, !8, i64 8, !13, i64 128}
!12 = !{!"_ZTS30KeyAgreeRecipientIdentifier_PR", !8, i64 0}
!13 = !{!"_ZTS16asn_struct_ctx_s", !14, i64 0, !14, i64 2, !15, i64 4, !7, i64 8, !16, i64 16}
!14 = !{!"short", !8, i64 0}
!15 = !{!"int", !8, i64 0}
!16 = !{!"long", !8, i64 0}
!17 = !{!7, !7, i64 0}


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