; LLVM IR from specinfo-ua/UAPKI :: library/common/pkix (uapki-ns-util)

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

%struct.Attribute = type { %struct.ASN__PRIMITIVE_TYPE_s, %"struct.Attribute::value", %struct.asn_struct_ctx_s }
%struct.ASN__PRIMITIVE_TYPE_s = type { ptr, i32 }
%"struct.Attribute::value" = type { %struct.anon, %struct.asn_struct_ctx_s }
%struct.anon = type { ptr, i32, i32, ptr }
%struct.asn_struct_ctx_s = type { i16, i16, i32, ptr, i64 }
%"struct.UapkiNS::Attribute" = type { %"class.std::__cxx11::basic_string", ptr }
%"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.ANY = type { ptr, i32, %struct.asn_struct_ctx_s }

@.str = external hidden unnamed_addr constant [30 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

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

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

declare ptr @ba_alloc_from_uint8(ptr noundef, i64 noundef) #1

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7UapkiNS4Util17attributeFromAsn1ERK9AttributeRNS_9AttributeE(ptr noundef nonnull align 8 dereferenceable(88) %0, ptr noundef nonnull align 8 dereferenceable(40) %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %7

7:                                                ; preds = %2
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.Attribute, ptr %8, i32 0, i32 0
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %"struct.UapkiNS::Attribute", ptr %10, i32 0, i32 0
  %12 = call noundef i32 @_ZN7UapkiNS4Util11oidFromAsn1EPK21ASN__PRIMITIVE_TYPE_sRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE(ptr noundef %9, ptr noundef nonnull align 8 dereferenceable(32) %11)
  store i32 %12, ptr %5, align 4, !tbaa !9
  %13 = load i32, ptr %5, align 4, !tbaa !9
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %15, label %17

15:                                               ; preds = %7
  %16 = load i32, ptr %5, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 135, i32 noundef %16)
  br label %59

17:                                               ; preds = %7
  br label %18

18:                                               ; preds = %17
  br label %19

19:                                               ; preds = %18
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.Attribute, ptr %20, i32 0, i32 1
  %22 = getelementptr inbounds %"struct.Attribute::value", ptr %21, i32 0, i32 0
  %23 = getelementptr inbounds %struct.anon, ptr %22, i32 0, i32 1
  %24 = load i32, ptr %23, align 8, !tbaa !11
  %25 = icmp sgt i32 %24, 0
  br i1 %25, label %26, label %44

26:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.Attribute, ptr %27, i32 0, i32 1
  %29 = getelementptr inbounds %"struct.Attribute::value", ptr %28, i32 0, i32 0
  %30 = getelementptr inbounds %struct.anon, ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !19
  %32 = getelementptr inbounds ptr, ptr %31, i64 0
  %33 = load ptr, ptr %32, align 8, !tbaa !5
  store ptr %33, ptr %6, align 8, !tbaa !5
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.ANY, ptr %34, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !20
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.ANY, ptr %37, i32 0, i32 1
  %39 = load i32, ptr %38, align 8, !tbaa !22
  %40 = sext i32 %39 to i64
  %41 = call ptr @ba_alloc_from_uint8(ptr noundef %36, i64 noundef %40)
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %"struct.UapkiNS::Attribute", ptr %42, i32 0, i32 1
  store ptr %41, ptr %43, align 8, !tbaa !23
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %48

44:                                               ; preds = %19
  %45 = call ptr @ba_alloc()
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %"struct.UapkiNS::Attribute", ptr %46, i32 0, i32 1
  store ptr %45, ptr %47, align 8, !tbaa !23
  br label %48

48:                                               ; preds = %44, %26
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds %"struct.UapkiNS::Attribute", ptr %49, i32 0, i32 1
  %51 = load ptr, ptr %50, align 8, !tbaa !23
  %52 = icmp ne ptr %51, null
  br i1 %52, label %58, label %53

53:                                               ; preds = %48
  br label %54

54:                                               ; preds = %53
  store i32 4097, ptr %5, align 4, !tbaa !9
  %55 = load i32, ptr %5, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 146, i32 noundef %55, ptr noundef null)
  br label %59

56:                                               ; No predecessors!
  br label %57

57:                                               ; preds = %56
  br label %58

58:                                               ; preds = %57, %48
  br label %59

59:                                               ; preds = %58, %54, %15
  %60 = load i32, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret i32 %60
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN7UapkiNS4Util11oidFromAsn1EPK21ASN__PRIMITIVE_TYPE_sRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE(ptr noundef, ptr noundef nonnull align 8 dereferenceable(32)) #2

declare ptr @ba_alloc() #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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 24}
!12 = !{!"_ZTS9Attribute", !13, i64 0, !14, i64 16, !16, i64 64}
!13 = !{!"_ZTS21ASN__PRIMITIVE_TYPE_s", !6, i64 0, !10, i64 8}
!14 = !{!"_ZTSN9Attribute5valueE", !15, i64 0, !16, i64 24}
!15 = !{!"_ZTSN9Attribute5valueUt_E", !6, i64 0, !10, i64 8, !10, i64 12, !6, i64 16}
!16 = !{!"_ZTS16asn_struct_ctx_s", !17, i64 0, !17, i64 2, !10, i64 4, !6, i64 8, !18, i64 16}
!17 = !{!"short", !7, i64 0}
!18 = !{!"long", !7, i64 0}
!19 = !{!12, !6, i64 16}
!20 = !{!21, !6, i64 0}
!21 = !{!"_ZTS3ANY", !6, i64 0, !10, i64 8, !16, i64 16}
!22 = !{!21, !10, i64 8}
!23 = !{!24, !6, i64 32}
!24 = !{!"_ZTSN7UapkiNS9AttributeE", !25, i64 0, !6, i64 32}
!25 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !26, i64 0, !18, i64 8, !7, i64 16}
!26 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, 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"

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

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

declare ptr @ba_alloc_from_uint8(ptr noundef, i64 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 @_ZN7UapkiNS4Util17attributeFromAsn1ERK9AttributeRNS_9AttributeE(ptr noundef nonnull align 8 dereferenceable(88) %0, ptr noundef nonnull align 8 dereferenceable(40) %1) local_unnamed_addr #1 {
  %3 = tail call noundef i32 @_ZN7UapkiNS4Util11oidFromAsn1EPK21ASN__PRIMITIVE_TYPE_sRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE(ptr noundef nonnull %0, ptr noundef nonnull align 8 dereferenceable(32) %1)
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %5, label %4

4:                                                ; preds = %2
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 135, i32 noundef %3)
  br label %23

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 24
  %7 = load i32, ptr %6, align 8, !tbaa !5
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %9, label %18

9:                                                ; preds = %5
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  %11 = load ptr, ptr %10, align 8, !tbaa !17
  %12 = load ptr, ptr %11, align 8, !tbaa !18
  %13 = load ptr, ptr %12, align 8, !tbaa !19
  %14 = getelementptr inbounds i8, ptr %12, i64 8
  %15 = load i32, ptr %14, align 8, !tbaa !21
  %16 = sext i32 %15 to i64
  %17 = tail call ptr @ba_alloc_from_uint8(ptr noundef %13, i64 noundef %16)
  br label %20

18:                                               ; preds = %5
  %19 = tail call ptr @ba_alloc()
  br label %20

20:                                               ; preds = %18, %9
  %.sink = phi ptr [ %17, %9 ], [ %19, %18 ]
  %21 = getelementptr inbounds i8, ptr %1, i64 32
  store ptr %.sink, ptr %21, align 8
  %.not13 = icmp eq ptr %.sink, null
  br i1 %.not13, label %22, label %23

22:                                               ; preds = %20
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 146, i32 noundef 4097, ptr noundef null)
  br label %23

23:                                               ; preds = %20, %22, %4
  %.0 = phi i32 [ %3, %4 ], [ 0, %20 ], [ 4097, %22 ]
  ret i32 %.0
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN7UapkiNS4Util11oidFromAsn1EPK21ASN__PRIMITIVE_TYPE_sRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE(ptr noundef, ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #1

declare ptr @ba_alloc() 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, !11, i64 24}
!6 = !{!"_ZTS9Attribute", !7, i64 0, !12, i64 16, !14, i64 64}
!7 = !{!"_ZTS21ASN__PRIMITIVE_TYPE_s", !8, i64 0, !11, i64 8}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!"_ZTSN9Attribute5valueE", !13, i64 0, !14, i64 24}
!13 = !{!"_ZTSN9Attribute5valueUt_E", !8, i64 0, !11, i64 8, !11, i64 12, !8, i64 16}
!14 = !{!"_ZTS16asn_struct_ctx_s", !15, i64 0, !15, i64 2, !11, i64 4, !8, i64 8, !16, i64 16}
!15 = !{!"short", !9, i64 0}
!16 = !{!"long", !9, i64 0}
!17 = !{!6, !8, i64 16}
!18 = !{!8, !8, i64 0}
!19 = !{!20, !8, i64 0}
!20 = !{!"_ZTS3ANY", !8, i64 0, !11, i64 8, !14, i64 16}
!21 = !{!20, !11, i64 8}


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