; 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 }
%struct.RecipientKeyIdentifier = type { %struct.OCTET_STRING, ptr, ptr, %struct.asn_struct_ctx_s }
%struct.OCTET_STRING = type { ptr, i32, %struct.asn_struct_ctx_s }

@.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_encode_ba(ptr noundef, ptr noundef, ptr noundef) #1

declare ptr @get_OtherKeyAttribute_desc() #1

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

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

18:                                               ; preds = %4
  store i32 4145, ptr %5, align 4
  br label %75

19:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %20 = getelementptr inbounds %"class.UapkiNS::Pkcs7::EnvelopedDataParser::KeyAgreeRecipientIdentifier", ptr %12, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !9
  %22 = getelementptr inbounds %struct.KeyAgreeRecipientIdentifier, ptr %21, i32 0, i32 1
  store ptr %22, ptr %11, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %19
  %24 = load ptr, ptr %11, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.RecipientKeyIdentifier, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = call i32 @asn_OCTSTRING2ba(ptr noundef %25, ptr noundef %26)
  store i32 %27, ptr %10, align 4, !tbaa !18
  %28 = load i32, ptr %10, align 4, !tbaa !18
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %30, label %32

30:                                               ; preds = %23
  %31 = load i32, ptr %10, align 4, !tbaa !18
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 796, i32 noundef %31)
  br label %73

32:                                               ; preds = %23
  br label %33

33:                                               ; preds = %32
  br label %34

34:                                               ; preds = %33
  %35 = load ptr, ptr %11, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.RecipientKeyIdentifier, ptr %35, i32 0, i32 1
  %37 = load ptr, ptr %36, align 8, !tbaa !19
  %38 = icmp ne ptr %37, null
  br i1 %38, label %39, label %53

39:                                               ; preds = %34
  br label %40

40:                                               ; preds = %39
  %41 = load ptr, ptr %11, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.RecipientKeyIdentifier, ptr %41, i32 0, i32 1
  %43 = load ptr, ptr %42, align 8, !tbaa !19
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = call noundef i32 @_ZN7UapkiNS4Util15genTimeFromAsn1EPK12OCTET_STRINGRm(ptr noundef %43, ptr noundef nonnull align 8 dereferenceable(8) %44)
  store i32 %45, ptr %10, align 4, !tbaa !18
  %46 = load i32, ptr %10, align 4, !tbaa !18
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %48, label %50

48:                                               ; preds = %40
  %49 = load i32, ptr %10, align 4, !tbaa !18
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 800, i32 noundef %49)
  br label %73

50:                                               ; preds = %40
  br label %51

51:                                               ; preds = %50
  br label %52

52:                                               ; preds = %51
  br label %53

53:                                               ; preds = %52, %34
  %54 = load ptr, ptr %11, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.RecipientKeyIdentifier, ptr %54, i32 0, i32 2
  %56 = load ptr, ptr %55, align 8, !tbaa !22
  %57 = icmp ne ptr %56, null
  br i1 %57, label %58, label %72

58:                                               ; preds = %53
  br label %59

59:                                               ; preds = %58
  %60 = call ptr @get_OtherKeyAttribute_desc()
  %61 = load ptr, ptr %11, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.RecipientKeyIdentifier, ptr %61, i32 0, i32 2
  %63 = load ptr, ptr %9, align 8, !tbaa !5
  %64 = call i32 @asn_encode_ba(ptr noundef %60, ptr noundef %62, ptr noundef %63)
  store i32 %64, ptr %10, align 4, !tbaa !18
  %65 = load i32, ptr %10, align 4, !tbaa !18
  %66 = icmp ne i32 %65, 0
  br i1 %66, label %67, label %69

67:                                               ; preds = %59
  %68 = load i32, ptr %10, align 4, !tbaa !18
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 805, i32 noundef %68)
  br label %73

69:                                               ; preds = %59
  br label %70

70:                                               ; preds = %69
  br label %71

71:                                               ; preds = %70
  br label %72

72:                                               ; preds = %71, %53
  br label %73

73:                                               ; preds = %72, %67, %48, %30
  %74 = load i32, ptr %10, align 4, !tbaa !18
  store i32 %74, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %75

75:                                               ; preds = %73, %18
  %76 = load i32, ptr %5, align 4
  ret i32 %76
}

declare noundef i32 @_ZN7UapkiNS4Util15genTimeFromAsn1EPK12OCTET_STRINGRm(ptr noundef, ptr noundef nonnull align 8 dereferenceable(8)) #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}
!19 = !{!20, !6, i64 40}
!20 = !{!"_ZTS22RecipientKeyIdentifier", !21, i64 0, !6, i64 40, !6, i64 48, !14, i64 56}
!21 = !{!"_ZTS12OCTET_STRING", !6, i64 0, !16, i64 8, !14, i64 16}
!22 = !{!20, !6, i64 48}


; 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_encode_ba(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

declare ptr @get_OtherKeyAttribute_desc() local_unnamed_addr #0

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

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

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %5, i64 8
  %9 = tail call i32 @asn_OCTSTRING2ba(ptr noundef nonnull %8, ptr noundef %1)
  %.not24 = icmp eq i32 %9, 0
  br i1 %.not24, label %11, label %10

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

11:                                               ; preds = %7
  %12 = getelementptr inbounds i8, ptr %5, i64 48
  %13 = load ptr, ptr %12, align 8, !tbaa !17
  %.not25 = icmp eq ptr %13, null
  br i1 %.not25, label %17, label %14

14:                                               ; preds = %11
  %15 = tail call noundef i32 @_ZN7UapkiNS4Util15genTimeFromAsn1EPK12OCTET_STRINGRm(ptr noundef nonnull %13, ptr noundef nonnull align 8 dereferenceable(8) %2)
  %.not26 = icmp eq i32 %15, 0
  br i1 %.not26, label %17, label %16

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

17:                                               ; preds = %14, %11
  %18 = getelementptr inbounds i8, ptr %5, i64 56
  %19 = load ptr, ptr %18, align 8, !tbaa !20
  %.not27 = icmp eq ptr %19, null
  br i1 %.not27, label %24, label %20

20:                                               ; preds = %17
  %21 = tail call ptr @get_OtherKeyAttribute_desc()
  %22 = tail call i32 @asn_encode_ba(ptr noundef %21, ptr noundef nonnull %18, ptr noundef %3)
  %.not28 = icmp eq i32 %22, 0
  br i1 %.not28, label %24, label %23

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

24:                                               ; preds = %10, %16, %23, %20, %17, %4
  %.0 = phi i32 [ 4145, %4 ], [ %9, %10 ], [ %15, %16 ], [ %22, %23 ], [ 0, %20 ], [ 0, %17 ]
  ret i32 %.0
}

declare noundef i32 @_ZN7UapkiNS4Util15genTimeFromAsn1EPK12OCTET_STRINGRm(ptr noundef, ptr noundef nonnull align 8 dereferenceable(8)) 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 = !{!18, !7, i64 40}
!18 = !{!"_ZTS22RecipientKeyIdentifier", !19, i64 0, !7, i64 40, !7, i64 48, !13, i64 56}
!19 = !{!"_ZTS12OCTET_STRING", !7, i64 0, !15, i64 8, !13, i64 16}
!20 = !{!18, !7, i64 48}


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