; LLVM IR from specinfo-ua/UAPKI :: library/uapki/src/cer-item.ll (ZN7UapkiNS4Cert16parseIssuerAndSNEPK12ByteArray_stPPS1_S5_)

; 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::SmartBA" = type { ptr }
%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, %struct.asn_struct_ctx_s }
%struct.anon = type { ptr, i32, i32, ptr }
%struct.ASN__PRIMITIVE_TYPE_s = type { ptr, i32 }
%struct.asn_struct_ctx_s = type { i16, i16, i32, ptr, i64 }

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

declare i32 @__gxx_personality_v0(...)

declare void @asn_free(ptr noundef, ptr noundef) #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: mustprogress nounwind uwtable
declare dso_local void @_ZN7UapkiNS7SmartBAC2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN7UapkiNS7SmartBAadEv(ptr noundef nonnull align 8 dereferenceable(8)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN7UapkiNS7SmartBA3popEv(ptr noundef nonnull align 8 dereferenceable(8)) #2 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7UapkiNS7SmartBAD2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #2 align 2

declare ptr @asn_decode_ba_with_alloc(ptr noundef, ptr noundef) #0

declare ptr @get_Name_desc() #0

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

declare ptr @get_IssuerAndSerialNumber_desc() #0

declare i64 @ba_get_len(ptr noundef) #0

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7UapkiNS4Cert16parseIssuerAndSNEPK12ByteArray_stPPS1_S5_(ptr noundef %0, ptr noundef %1, ptr noundef %2) #3 personality ptr @__gxx_personality_v0 {
  %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 ptr, align 8
  %10 = alloca %"class.UapkiNS::SmartBA", align 8
  %11 = alloca %"class.UapkiNS::SmartBA", align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = 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
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  store ptr null, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  call void @_ZN7UapkiNS7SmartBAC2Ev(ptr noundef nonnull align 8 dereferenceable(8) %10)
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  invoke void @_ZN7UapkiNS7SmartBAC2Ev(ptr noundef nonnull align 8 dereferenceable(8) %11)
          to label %15 unwind label %27

15:                                               ; preds = %3
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = invoke i64 @ba_get_len(ptr noundef %16)
          to label %18 unwind label %31

18:                                               ; preds = %15
  %19 = icmp ult i64 %17, 3
  br i1 %19, label %26, label %20

20:                                               ; preds = %18
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %26

23:                                               ; preds = %20
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = icmp ne ptr %24, null
  br i1 %25, label %35, label %26

26:                                               ; preds = %23, %20, %18
  store i32 4101, ptr %4, align 4
  store i32 1, ptr %14, align 4
  br label %89

27:                                               ; preds = %3
  %28 = landingpad { ptr, i32 }
          cleanup
  %29 = extractvalue { ptr, i32 } %28, 0
  store ptr %29, ptr %12, align 8
  %30 = extractvalue { ptr, i32 } %28, 1
  store i32 %30, ptr %13, align 4
  br label %91

31:                                               ; preds = %85, %83, %78, %76, %71, %66, %62, %56, %51, %47, %45, %37, %35, %15
  %32 = landingpad { ptr, i32 }
          cleanup
  %33 = extractvalue { ptr, i32 } %32, 0
  store ptr %33, ptr %12, align 8
  %34 = extractvalue { ptr, i32 } %32, 1
  store i32 %34, ptr %13, align 4
  call void @_ZN7UapkiNS7SmartBAD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %11) #4
  br label %91

35:                                               ; preds = %23
  %36 = invoke ptr @get_IssuerAndSerialNumber_desc()
          to label %37 unwind label %31

37:                                               ; preds = %35
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = invoke ptr @asn_decode_ba_with_alloc(ptr noundef %36, ptr noundef %38)
          to label %40 unwind label %31

40:                                               ; preds = %37
  store ptr %39, ptr %9, align 8, !tbaa !5
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  %42 = icmp ne ptr %41, null
  br i1 %42, label %44, label %43

43:                                               ; preds = %40
  store i32 4101, ptr %4, align 4
  store i32 1, ptr %14, align 4
  br label %89

44:                                               ; preds = %40
  br label %45

45:                                               ; preds = %44
  %46 = invoke ptr @get_Name_desc()
          to label %47 unwind label %31

47:                                               ; preds = %45
  %48 = load ptr, ptr %9, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.IssuerAndSerialNumber, ptr %48, i32 0, i32 0
  %50 = invoke noundef ptr @_ZN7UapkiNS7SmartBAadEv(ptr noundef nonnull align 8 dereferenceable(8) %10)
          to label %51 unwind label %31

51:                                               ; preds = %47
  %52 = invoke i32 @asn_encode_ba(ptr noundef %46, ptr noundef %49, ptr noundef %50)
          to label %53 unwind label %31

53:                                               ; preds = %51
  store i32 %52, ptr %8, align 4, !tbaa !9
  %54 = load i32, ptr %8, align 4, !tbaa !9
  %55 = icmp ne i32 %54, 0
  br i1 %55, label %56, label %59

56:                                               ; preds = %53
  %57 = load i32, ptr %8, align 4, !tbaa !9
  invoke void @stacktrace_add(ptr noundef @.str, i64 noundef 708, i32 noundef %57)
          to label %58 unwind label %31

58:                                               ; preds = %56
  br label %83

59:                                               ; preds = %53
  br label %60

60:                                               ; preds = %59
  br label %61

61:                                               ; preds = %60
  br label %62

62:                                               ; preds = %61
  %63 = load ptr, ptr %9, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.IssuerAndSerialNumber, ptr %63, i32 0, i32 1
  %65 = invoke noundef ptr @_ZN7UapkiNS7SmartBAadEv(ptr noundef nonnull align 8 dereferenceable(8) %11)
          to label %66 unwind label %31

66:                                               ; preds = %62
  %67 = invoke i32 @asn_INTEGER2ba(ptr noundef %64, ptr noundef %65)
          to label %68 unwind label %31

68:                                               ; preds = %66
  store i32 %67, ptr %8, align 4, !tbaa !9
  %69 = load i32, ptr %8, align 4, !tbaa !9
  %70 = icmp ne i32 %69, 0
  br i1 %70, label %71, label %74

71:                                               ; preds = %68
  %72 = load i32, ptr %8, align 4, !tbaa !9
  invoke void @stacktrace_add(ptr noundef @.str, i64 noundef 709, i32 noundef %72)
          to label %73 unwind label %31

73:                                               ; preds = %71
  br label %83

74:                                               ; preds = %68
  br label %75

75:                                               ; preds = %74
  br label %76

76:                                               ; preds = %75
  %77 = invoke noundef ptr @_ZN7UapkiNS7SmartBA3popEv(ptr noundef nonnull align 8 dereferenceable(8) %10)
          to label %78 unwind label %31

78:                                               ; preds = %76
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %77, ptr %79, align 8, !tbaa !5
  %80 = invoke noundef ptr @_ZN7UapkiNS7SmartBA3popEv(ptr noundef nonnull align 8 dereferenceable(8) %11)
          to label %81 unwind label %31

81:                                               ; preds = %78
  %82 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %80, ptr %82, align 8, !tbaa !5
  br label %83

83:                                               ; preds = %81, %73, %58
  %84 = invoke ptr @get_IssuerAndSerialNumber_desc()
          to label %85 unwind label %31

85:                                               ; preds = %83
  %86 = load ptr, ptr %9, align 8, !tbaa !5
  invoke void @asn_free(ptr noundef %84, ptr noundef %86)
          to label %87 unwind label %31

87:                                               ; preds = %85
  %88 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %88, ptr %4, align 4
  store i32 1, ptr %14, align 4
  br label %89

89:                                               ; preds = %87, %43, %26
  call void @_ZN7UapkiNS7SmartBAD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @_ZN7UapkiNS7SmartBAD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %90 = load i32, ptr %4, align 4
  ret i32 %90

91:                                               ; preds = %31, %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @_ZN7UapkiNS7SmartBAD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %92

92:                                               ; preds = %91
  %93 = load ptr, ptr %12, align 8
  %94 = load i32, ptr %13, align 4
  %95 = insertvalue { ptr, i32 } poison, ptr %93, 0
  %96 = insertvalue { ptr, i32 } %95, i32 %94, 1
  resume { ptr, i32 } %96
}

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 = { mustprogress nounwind 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 = { 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 }

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


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

%"class.UapkiNS::SmartBA" = type { ptr }

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

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7UapkiNS7SmartBAC2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #2 align 2

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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7UapkiNS7SmartBAD2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #2 align 2

declare ptr @asn_decode_ba_with_alloc(ptr noundef, ptr noundef) local_unnamed_addr #0

declare ptr @get_Name_desc() local_unnamed_addr #0

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

declare ptr @get_IssuerAndSerialNumber_desc() local_unnamed_addr #0

declare i64 @ba_get_len(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7UapkiNS4Cert16parseIssuerAndSNEPK12ByteArray_stPPS1_S5_(ptr noundef %0, ptr noundef writeonly %1, ptr noundef writeonly %2) local_unnamed_addr #3 personality ptr @__gxx_personality_v0 {
  %4 = alloca %"class.UapkiNS::SmartBA", align 8
  %5 = alloca %"class.UapkiNS::SmartBA", align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  call void @_ZN7UapkiNS7SmartBAC2Ev(ptr noundef nonnull align 8 dereferenceable(8) %4)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #4
  call void @_ZN7UapkiNS7SmartBAC2Ev(ptr noundef nonnull align 8 dereferenceable(8) %5)
  %6 = invoke i64 @ba_get_len(ptr noundef %0)
          to label %7 unwind label %11

7:                                                ; preds = %3
  %8 = icmp ugt i64 %6, 2
  %9 = icmp ne ptr %1, null
  %or.cond = and i1 %9, %8
  %10 = icmp ne ptr %2, null
  %or.cond3 = and i1 %10, %or.cond
  br i1 %or.cond3, label %13, label %37

11:                                               ; preds = %36, %34, %30, %25, %24, %20, %18, %15, %13, %3
  %12 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN7UapkiNS7SmartBAD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  call void @_ZN7UapkiNS7SmartBAD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  resume { ptr, i32 } %12

13:                                               ; preds = %7
  %14 = invoke ptr @get_IssuerAndSerialNumber_desc()
          to label %15 unwind label %11

15:                                               ; preds = %13
  %16 = invoke ptr @asn_decode_ba_with_alloc(ptr noundef %14, ptr noundef %0)
          to label %17 unwind label %11

17:                                               ; preds = %15
  %.not = icmp eq ptr %16, null
  br i1 %.not, label %37, label %18

18:                                               ; preds = %17
  %19 = invoke ptr @get_Name_desc()
          to label %20 unwind label %11

20:                                               ; preds = %18
  %21 = call noundef ptr @_ZN7UapkiNS7SmartBAadEv(ptr noundef nonnull align 8 dereferenceable(8) %4)
  %22 = invoke i32 @asn_encode_ba(ptr noundef %19, ptr noundef nonnull %16, ptr noundef %21)
          to label %23 unwind label %11

23:                                               ; preds = %20
  %.not26 = icmp eq i32 %22, 0
  br i1 %.not26, label %25, label %24

24:                                               ; preds = %23
  invoke void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 708, i32 noundef %22)
          to label %34 unwind label %11

25:                                               ; preds = %23
  %26 = getelementptr inbounds i8, ptr %16, i64 80
  %27 = call noundef ptr @_ZN7UapkiNS7SmartBAadEv(ptr noundef nonnull align 8 dereferenceable(8) %5)
  %28 = invoke i32 @asn_INTEGER2ba(ptr noundef nonnull %26, ptr noundef %27)
          to label %29 unwind label %11

29:                                               ; preds = %25
  %.not27 = icmp eq i32 %28, 0
  br i1 %.not27, label %31, label %30

30:                                               ; preds = %29
  invoke void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 709, i32 noundef %28)
          to label %34 unwind label %11

31:                                               ; preds = %29
  %32 = call noundef ptr @_ZN7UapkiNS7SmartBA3popEv(ptr noundef nonnull align 8 dereferenceable(8) %4)
  store ptr %32, ptr %1, align 8, !tbaa !5
  %33 = call noundef ptr @_ZN7UapkiNS7SmartBA3popEv(ptr noundef nonnull align 8 dereferenceable(8) %5)
  store ptr %33, ptr %2, align 8, !tbaa !5
  br label %34

34:                                               ; preds = %30, %24, %31
  %.020 = phi i32 [ %22, %24 ], [ %28, %30 ], [ 0, %31 ]
  %35 = invoke ptr @get_IssuerAndSerialNumber_desc()
          to label %36 unwind label %11

36:                                               ; preds = %34
  invoke void @asn_free(ptr noundef %35, ptr noundef nonnull %16)
          to label %37 unwind label %11

37:                                               ; preds = %36, %17, %7
  %.0 = phi i32 [ 4101, %7 ], [ 4101, %17 ], [ %.020, %36 ]
  call void @_ZN7UapkiNS7SmartBAD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  call void @_ZN7UapkiNS7SmartBAD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  ret i32 %.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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nounwind 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 = { 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 }

!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"}


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