; LLVM IR from specinfo-ua/UAPKI :: library/common/pkix/signeddata-helper.ll (ZN7UapkiNS5Pkcs717SignedDataBuilder6encodeEPKc)

; 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::SignedDataBuilder" = type { ptr, %"class.std::vector", ptr }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<UapkiNS::Pkcs7::SignedDataBuilder::SignerInfo *, std::allocator<UapkiNS::Pkcs7::SignedDataBuilder::SignerInfo *>>::_Vector_impl" }
%"struct.std::_Vector_base<UapkiNS::Pkcs7::SignedDataBuilder::SignerInfo *, std::allocator<UapkiNS::Pkcs7::SignedDataBuilder::SignerInfo *>>::_Vector_impl" = type { %"struct.std::_Vector_base<UapkiNS::Pkcs7::SignedDataBuilder::SignerInfo *, std::allocator<UapkiNS::Pkcs7::SignedDataBuilder::SignerInfo *>>::_Vector_impl_data" }
%"struct.std::_Vector_base<UapkiNS::Pkcs7::SignedDataBuilder::SignerInfo *, std::allocator<UapkiNS::Pkcs7::SignedDataBuilder::SignerInfo *>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%struct.ContentInfo = type { %struct.ASN__PRIMITIVE_TYPE_s, %struct.ANY, %struct.asn_struct_ctx_s }
%struct.ASN__PRIMITIVE_TYPE_s = type { ptr, i32 }
%struct.ANY = type { ptr, i32, %struct.asn_struct_ctx_s }
%struct.asn_struct_ctx_s = type { i16, i16, i32, ptr, i64 }

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

declare void @asn_free(ptr noundef, ptr noundef) #0

declare ptr @get_SignedData_desc() #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 i32 @asn_set_oid_from_text(ptr noundef, ptr noundef) #0

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7UapkiNS5Pkcs717SignedDataBuilder6encodeEPKc(ptr noundef nonnull align 8 dereferenceable(40) %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
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store ptr null, ptr %7, align 8, !tbaa !5
  %10 = getelementptr inbounds %"class.UapkiNS::Pkcs7::SignedDataBuilder", ptr %9, i32 0, i32 0
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  %12 = icmp ne ptr %11, null
  br i1 %12, label %13, label %16

13:                                               ; preds = %2
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %17, label %16

16:                                               ; preds = %13, %2
  store i32 4101, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %78

17:                                               ; preds = %13
  br label %18

18:                                               ; preds = %17
  %19 = call noundef i32 @_ZN7UapkiNS5Pkcs717SignedDataBuilder23collectDigestAlgorithmsEv(ptr noundef nonnull align 8 dereferenceable(40) %9)
  store i32 %19, ptr %6, align 4, !tbaa !9
  %20 = load i32, ptr %6, align 4, !tbaa !9
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %24

22:                                               ; preds = %18
  %23 = load i32, ptr %6, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 209, i32 noundef %23)
  br label %74

24:                                               ; preds = %18
  br label %25

25:                                               ; preds = %24
  br label %26

26:                                               ; preds = %25
  %27 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 80) #5
  store ptr %27, ptr %7, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %26
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = icmp eq ptr %29, null
  br i1 %30, label %31, label %33

31:                                               ; preds = %28
  store i32 1, ptr %6, align 4, !tbaa !9
  %32 = load i32, ptr %6, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 211, i32 noundef %32, ptr noundef null)
  br label %74

33:                                               ; preds = %28
  br label %34

34:                                               ; preds = %33
  br label %35

35:                                               ; preds = %34
  br label %36

36:                                               ; preds = %35
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.ContentInfo, ptr %38, i32 0, i32 0
  %40 = call i32 @asn_set_oid_from_text(ptr noundef %37, ptr noundef %39)
  store i32 %40, ptr %6, align 4, !tbaa !9
  %41 = load i32, ptr %6, align 4, !tbaa !9
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %43, label %45

43:                                               ; preds = %36
  %44 = load i32, ptr %6, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 212, i32 noundef %44)
  br label %74

45:                                               ; preds = %36
  br label %46

46:                                               ; preds = %45
  br label %47

47:                                               ; preds = %46
  br label %48

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

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

59:                                               ; preds = %48
  br label %60

60:                                               ; preds = %59
  br label %61

61:                                               ; preds = %60
  br label %62

62:                                               ; preds = %61
  %63 = call ptr @get_ContentInfo_desc()
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  %65 = getelementptr inbounds %"class.UapkiNS::Pkcs7::SignedDataBuilder", ptr %9, i32 0, i32 2
  %66 = call i32 @asn_encode_ba(ptr noundef %63, ptr noundef %64, ptr noundef %65)
  store i32 %66, ptr %6, align 4, !tbaa !9
  %67 = load i32, ptr %6, align 4, !tbaa !9
  %68 = icmp ne i32 %67, 0
  br i1 %68, label %69, label %71

69:                                               ; preds = %62
  %70 = load i32, ptr %6, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 215, i32 noundef %70)
  br label %74

71:                                               ; preds = %62
  br label %72

72:                                               ; preds = %71
  br label %73

73:                                               ; preds = %72
  br label %74

74:                                               ; preds = %73, %69, %57, %43, %31, %22
  %75 = call ptr @get_ContentInfo_desc()
  %76 = load ptr, ptr %7, align 8, !tbaa !5
  call void @asn_free(ptr noundef %75, ptr noundef %76)
  %77 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %77, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %78

78:                                               ; preds = %74, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %79 = load i32, ptr %3, align 4
  ret i32 %79
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN7UapkiNS5Pkcs717SignedDataBuilder23collectDigestAlgorithmsEv(ptr noundef nonnull align 8 dereferenceable(40)) #3 align 2

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

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

declare ptr @get_ContentInfo_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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTSN7UapkiNS5Pkcs717SignedDataBuilderE", !6, i64 0, !13, i64 8, !6, i64 32}
!13 = !{!"_ZTSSt6vectorIPN7UapkiNS5Pkcs717SignedDataBuilder10SignerInfoESaIS4_EE", !14, i64 0}
!14 = !{!"_ZTSSt12_Vector_baseIPN7UapkiNS5Pkcs717SignedDataBuilder10SignerInfoESaIS4_EE", !15, i64 0}
!15 = !{!"_ZTSNSt12_Vector_baseIPN7UapkiNS5Pkcs717SignedDataBuilder10SignerInfoESaIS4_EE12_Vector_implE", !16, i64 0}
!16 = !{!"_ZTSNSt12_Vector_baseIPN7UapkiNS5Pkcs717SignedDataBuilder10SignerInfoESaIS4_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !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 [34 x i8], align 1

declare void @asn_free(ptr noundef, ptr noundef) local_unnamed_addr #0

declare ptr @get_SignedData_desc() 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 i32 @asn_set_oid_from_text(ptr noundef, ptr noundef) local_unnamed_addr #0

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7UapkiNS5Pkcs717SignedDataBuilder6encodeEPKc(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef %1) local_unnamed_addr #2 align 2 {
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %4 = icmp ne ptr %3, null
  %5 = icmp ne ptr %1, null
  %or.cond = and i1 %5, %4
  br i1 %or.cond, label %6, label %29

6:                                                ; preds = %2
  %7 = tail call noundef i32 @_ZN7UapkiNS5Pkcs717SignedDataBuilder23collectDigestAlgorithmsEv(ptr noundef nonnull align 8 dereferenceable(40) %0)
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %9, label %8

8:                                                ; preds = %6
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 209, i32 noundef %7)
  br label %27

9:                                                ; preds = %6
  %10 = tail call noalias dereferenceable_or_null(80) ptr @calloc(i64 noundef 1, i64 noundef 80) #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 211, i32 noundef 1, ptr noundef null)
  br label %27

13:                                               ; preds = %9
  %14 = tail call i32 @asn_set_oid_from_text(ptr noundef nonnull %1, ptr noundef nonnull %10)
  %.not28 = icmp eq i32 %14, 0
  br i1 %.not28, label %16, label %15

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

16:                                               ; preds = %13
  %17 = tail call ptr @get_SignedData_desc()
  %18 = load ptr, ptr %0, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %10, i64 16
  %20 = tail call i32 @asn_set_any(ptr noundef %17, ptr noundef %18, ptr noundef nonnull %19)
  %.not29 = icmp eq i32 %20, 0
  br i1 %.not29, label %22, label %21

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

22:                                               ; preds = %16
  %23 = tail call ptr @get_ContentInfo_desc()
  %24 = getelementptr inbounds i8, ptr %0, i64 32
  %25 = tail call i32 @asn_encode_ba(ptr noundef %23, ptr noundef nonnull %10, ptr noundef nonnull %24)
  %.not30 = icmp eq i32 %25, 0
  br i1 %.not30, label %27, label %26

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

27:                                               ; preds = %22, %26, %21, %15, %12, %8
  %.019 = phi i32 [ %7, %8 ], [ 1, %12 ], [ %14, %15 ], [ %20, %21 ], [ %25, %26 ], [ 0, %22 ]
  %.0 = phi ptr [ null, %8 ], [ null, %12 ], [ %10, %15 ], [ %10, %21 ], [ %10, %26 ], [ %10, %22 ]
  %28 = tail call ptr @get_ContentInfo_desc()
  tail call void @asn_free(ptr noundef %28, ptr noundef %.0)
  br label %29

29:                                               ; preds = %2, %27
  %.020 = phi i32 [ %.019, %27 ], [ 4101, %2 ]
  ret i32 %.020
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN7UapkiNS5Pkcs717SignedDataBuilder23collectDigestAlgorithmsEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #2 align 2

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

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

declare ptr @get_ContentInfo_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, !7, i64 0}
!6 = !{!"_ZTSN7UapkiNS5Pkcs717SignedDataBuilderE", !7, i64 0, !10, i64 8, !7, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSSt6vectorIPN7UapkiNS5Pkcs717SignedDataBuilder10SignerInfoESaIS4_EE", !11, i64 0}
!11 = !{!"_ZTSSt12_Vector_baseIPN7UapkiNS5Pkcs717SignedDataBuilder10SignerInfoESaIS4_EE", !12, i64 0}
!12 = !{!"_ZTSNSt12_Vector_baseIPN7UapkiNS5Pkcs717SignedDataBuilder10SignerInfoESaIS4_EE12_Vector_implE", !13, i64 0}
!13 = !{!"_ZTSNSt12_Vector_baseIPN7UapkiNS5Pkcs717SignedDataBuilder10SignerInfoESaIS4_EE17_Vector_impl_dataE", !7, i64 0, !7, i64 8, !7, i64 16}


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