; LLVM IR from specinfo-ua/UAPKI :: library/common/pkix (signeddata-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::SignedDataBuilder::SignerInfo" = type { ptr, ptr, ptr, i64, ptr, ptr, %"class.std::__cxx11::basic_string" }
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }
%struct.SignerInfo = type { %struct.ASN__PRIMITIVE_TYPE_s, %struct.ANY, %struct.AlgorithmIdentifier, %struct.ANY, %struct.AlgorithmIdentifier, %struct.OCTET_STRING, ptr, %struct.asn_struct_ctx_s }
%struct.ASN__PRIMITIVE_TYPE_s = type { ptr, i32 }
%struct.ANY = type { ptr, i32, %struct.asn_struct_ctx_s }
%struct.AlgorithmIdentifier = type { %struct.ASN__PRIMITIVE_TYPE_s, ptr, %struct.asn_struct_ctx_s }
%struct.OCTET_STRING = 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

; 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_decode_ba(ptr noundef, ptr noundef, ptr noundef) #1

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

declare ptr @get_Attributes_desc() #1

declare ptr @get_ANY_desc() #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7UapkiNS5Pkcs717SignedDataBuilder10SignerInfo17encodeSignedAttrsEv(ptr noundef nonnull align 8 dereferenceable(80) %0) #2 align 2 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %5 = load ptr, ptr %3, align 8
  %6 = getelementptr inbounds %"class.UapkiNS::Pkcs7::SignedDataBuilder::SignerInfo", ptr %5, i32 0, i32 0
  %7 = load ptr, ptr %6, align 8, !tbaa !9
  %8 = icmp ne ptr %7, null
  br i1 %8, label %9, label %13

9:                                                ; preds = %1
  %10 = getelementptr inbounds %"class.UapkiNS::Pkcs7::SignedDataBuilder::SignerInfo", ptr %5, i32 0, i32 1
  %11 = load ptr, ptr %10, align 8, !tbaa !15
  %12 = icmp ne ptr %11, null
  br i1 %12, label %14, label %13

13:                                               ; preds = %9, %1
  store i32 4101, ptr %2, align 4
  br label %67

14:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !16
  br label %15

15:                                               ; preds = %14
  %16 = call ptr @get_Attributes_desc()
  %17 = getelementptr inbounds %"class.UapkiNS::Pkcs7::SignedDataBuilder::SignerInfo", ptr %5, i32 0, i32 1
  %18 = load ptr, ptr %17, align 8, !tbaa !15
  %19 = getelementptr inbounds %"class.UapkiNS::Pkcs7::SignedDataBuilder::SignerInfo", ptr %5, i32 0, i32 5
  %20 = call i32 @asn_encode_ba(ptr noundef %16, ptr noundef %18, ptr noundef %19)
  store i32 %20, ptr %4, align 4, !tbaa !16
  %21 = load i32, ptr %4, align 4, !tbaa !16
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %25

23:                                               ; preds = %15
  %24 = load i32, ptr %4, align 4, !tbaa !16
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 421, i32 noundef %24)
  br label %65

25:                                               ; preds = %15
  br label %26

26:                                               ; preds = %25
  br label %27

27:                                               ; preds = %26
  br label %28

28:                                               ; preds = %27
  %29 = getelementptr inbounds %"class.UapkiNS::Pkcs7::SignedDataBuilder::SignerInfo", ptr %5, i32 0, i32 5
  %30 = load ptr, ptr %29, align 8, !tbaa !18
  %31 = call i32 @ba_set_byte(ptr noundef %30, i64 noundef 0, i8 noundef zeroext -96)
  store i32 %31, ptr %4, align 4, !tbaa !16
  %32 = load i32, ptr %4, align 4, !tbaa !16
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %34, label %36

34:                                               ; preds = %28
  %35 = load i32, ptr %4, align 4, !tbaa !16
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 423, i32 noundef %35)
  br label %65

36:                                               ; preds = %28
  br label %37

37:                                               ; preds = %36
  br label %38

38:                                               ; preds = %37
  br label %39

39:                                               ; preds = %38
  %40 = call ptr @get_ANY_desc()
  %41 = getelementptr inbounds %"class.UapkiNS::Pkcs7::SignedDataBuilder::SignerInfo", ptr %5, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !9
  %43 = getelementptr inbounds %struct.SignerInfo, ptr %42, i32 0, i32 3
  %44 = getelementptr inbounds %"class.UapkiNS::Pkcs7::SignedDataBuilder::SignerInfo", ptr %5, i32 0, i32 5
  %45 = load ptr, ptr %44, align 8, !tbaa !18
  %46 = call i32 @asn_decode_ba(ptr noundef %40, ptr noundef %43, ptr noundef %45)
  store i32 %46, ptr %4, align 4, !tbaa !16
  %47 = load i32, ptr %4, align 4, !tbaa !16
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %49, label %51

49:                                               ; preds = %39
  %50 = load i32, ptr %4, align 4, !tbaa !16
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 424, i32 noundef %50)
  br label %65

51:                                               ; preds = %39
  br label %52

52:                                               ; preds = %51
  br label %53

53:                                               ; preds = %52
  br label %54

54:                                               ; preds = %53
  %55 = getelementptr inbounds %"class.UapkiNS::Pkcs7::SignedDataBuilder::SignerInfo", ptr %5, i32 0, i32 5
  %56 = load ptr, ptr %55, align 8, !tbaa !18
  %57 = call i32 @ba_set_byte(ptr noundef %56, i64 noundef 0, i8 noundef zeroext 49)
  store i32 %57, ptr %4, align 4, !tbaa !16
  %58 = load i32, ptr %4, align 4, !tbaa !16
  %59 = icmp ne i32 %58, 0
  br i1 %59, label %60, label %62

60:                                               ; preds = %54
  %61 = load i32, ptr %4, align 4, !tbaa !16
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 425, i32 noundef %61)
  br label %65

62:                                               ; preds = %54
  br label %63

63:                                               ; preds = %62
  br label %64

64:                                               ; preds = %63
  br label %65

65:                                               ; preds = %64, %60, %49, %34, %23
  %66 = load i32, ptr %4, align 4, !tbaa !16
  store i32 %66, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %67

67:                                               ; preds = %65, %13
  %68 = load i32, ptr %2, align 4
  ret i32 %68
}

declare i32 @ba_set_byte(ptr noundef, i64 noundef, i8 noundef zeroext) #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 = !{!"_ZTSN7UapkiNS5Pkcs717SignedDataBuilder10SignerInfoE", !6, i64 0, !6, i64 8, !6, i64 16, !11, i64 24, !6, i64 32, !6, i64 40, !12, i64 48}
!11 = !{!"_ZTSN7UapkiNS5Pkcs720SignerIdentifierTypeE", !7, i64 0}
!12 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !13, i64 0, !14, i64 8, !7, i64 16}
!13 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!10, !6, i64 8}
!16 = !{!17, !17, i64 0}
!17 = !{!"int", !7, i64 0}
!18 = !{!10, !6, i64 40}


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

declare i32 @asn_decode_ba(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_Attributes_desc() local_unnamed_addr #0

declare ptr @get_ANY_desc() local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7UapkiNS5Pkcs717SignedDataBuilder10SignerInfo17encodeSignedAttrsEv(ptr noundef nonnull align 8 dereferenceable(80) %0) local_unnamed_addr #1 align 2 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %27, label %3

3:                                                ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !14
  %.not15 = icmp eq ptr %5, null
  br i1 %.not15, label %27, label %6

6:                                                ; preds = %3
  %7 = tail call ptr @get_Attributes_desc()
  %8 = load ptr, ptr %4, align 8, !tbaa !14
  %9 = getelementptr inbounds i8, ptr %0, i64 40
  %10 = tail call i32 @asn_encode_ba(ptr noundef %7, ptr noundef %8, ptr noundef nonnull %9)
  %.not16 = icmp eq i32 %10, 0
  br i1 %.not16, label %12, label %11

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

12:                                               ; preds = %6
  %13 = load ptr, ptr %9, align 8, !tbaa !15
  %14 = tail call i32 @ba_set_byte(ptr noundef %13, i64 noundef 0, i8 noundef zeroext -96)
  %.not17 = icmp eq i32 %14, 0
  br i1 %.not17, label %16, label %15

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

16:                                               ; preds = %12
  %17 = tail call ptr @get_ANY_desc()
  %18 = load ptr, ptr %0, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %18, i64 104
  %20 = load ptr, ptr %9, align 8, !tbaa !15
  %21 = tail call i32 @asn_decode_ba(ptr noundef %17, ptr noundef nonnull %19, ptr noundef %20)
  %.not18 = icmp eq i32 %21, 0
  br i1 %.not18, label %23, label %22

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

23:                                               ; preds = %16
  %24 = load ptr, ptr %9, align 8, !tbaa !15
  %25 = tail call i32 @ba_set_byte(ptr noundef %24, i64 noundef 0, i8 noundef zeroext 49)
  %.not19 = icmp eq i32 %25, 0
  br i1 %.not19, label %27, label %26

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

27:                                               ; preds = %11, %15, %22, %26, %23, %1, %3
  %.010 = phi i32 [ 4101, %3 ], [ 4101, %1 ], [ %10, %11 ], [ %14, %15 ], [ %21, %22 ], [ %25, %26 ], [ 0, %23 ]
  ret i32 %.010
}

declare i32 @ba_set_byte(ptr noundef, i64 noundef, i8 noundef zeroext) 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 = !{!"_ZTSN7UapkiNS5Pkcs717SignedDataBuilder10SignerInfoE", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !7, i64 32, !7, i64 40, !11, i64 48}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSN7UapkiNS5Pkcs720SignerIdentifierTypeE", !8, i64 0}
!11 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !12, i64 0, !13, i64 8, !8, i64 16}
!12 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !7, i64 0}
!13 = !{!"long", !8, i64 0}
!14 = !{!6, !7, i64 8}
!15 = !{!6, !7, i64 40}


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