; 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.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 ptr @ba_alloc() #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN7UapkiNS4Util23attributeFromAttributesEPK10AttributesPKc(ptr noundef, ptr noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7UapkiNS4Util23attrValueFromAttributesEPK10AttributesPKcPP12ByteArray_st(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %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 i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  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) #3
  store i32 0, ptr %8, align 4, !tbaa !9
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %20

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

17:                                               ; preds = %14
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %21, label %20

20:                                               ; preds = %17, %14, %3
  store i32 4101, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %67

21:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = call noundef ptr @_ZN7UapkiNS4Util23attributeFromAttributesEPK10AttributesPKc(ptr noundef %22, ptr noundef %23)
  store ptr %24, ptr %10, align 8, !tbaa !5
  %25 = load ptr, ptr %10, align 8, !tbaa !5
  %26 = icmp ne ptr %25, null
  br i1 %26, label %28, label %27

27:                                               ; preds = %21
  store i32 4149, ptr %8, align 4, !tbaa !9
  br label %65

28:                                               ; preds = %21
  %29 = load ptr, ptr %10, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.Attribute, ptr %29, i32 0, i32 1
  %31 = getelementptr inbounds %"struct.Attribute::value", ptr %30, i32 0, i32 0
  %32 = getelementptr inbounds %struct.anon, ptr %31, i32 0, i32 1
  %33 = load i32, ptr %32, align 8, !tbaa !11
  %34 = icmp sgt i32 %33, 0
  br i1 %34, label %35, label %52

35:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.Attribute, ptr %36, i32 0, i32 1
  %38 = getelementptr inbounds %"struct.Attribute::value", ptr %37, i32 0, i32 0
  %39 = getelementptr inbounds %struct.anon, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !19
  %41 = getelementptr inbounds ptr, ptr %40, i64 0
  %42 = load ptr, ptr %41, align 8, !tbaa !5
  store ptr %42, ptr %11, align 8, !tbaa !5
  %43 = load ptr, ptr %11, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.ANY, ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !20
  %46 = load ptr, ptr %11, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.ANY, ptr %46, i32 0, i32 1
  %48 = load i32, ptr %47, align 8, !tbaa !22
  %49 = sext i32 %48 to i64
  %50 = call ptr @ba_alloc_from_uint8(ptr noundef %45, i64 noundef %49)
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %50, ptr %51, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  br label %55

52:                                               ; preds = %28
  %53 = call ptr @ba_alloc()
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %53, ptr %54, align 8, !tbaa !5
  br label %55

55:                                               ; preds = %52, %35
  br label %56

56:                                               ; preds = %55
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  %58 = load ptr, ptr %57, align 8, !tbaa !5
  %59 = icmp eq ptr null, %58
  br i1 %59, label %60, label %62

60:                                               ; preds = %56
  store i32 2, ptr %8, align 4, !tbaa !9
  %61 = load i32, ptr %8, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 255, i32 noundef %61)
  br label %65

62:                                               ; preds = %56
  br label %63

63:                                               ; preds = %62
  br label %64

64:                                               ; preds = %63
  br label %65

65:                                               ; preds = %64, %60, %27
  %66 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %66, ptr %4, align 4
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %67

67:                                               ; preds = %65, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %68 = load i32, ptr %4, align 4
  ret i32 %68
}

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}


; 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 ptr @ba_alloc() local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN7UapkiNS4Util23attributeFromAttributesEPK10AttributesPKc(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 4150) i32 @_ZN7UapkiNS4Util23attrValueFromAttributesEPK10AttributesPKcPP12ByteArray_st(ptr noundef %0, ptr noundef %1, ptr noundef writeonly %2) local_unnamed_addr #1 {
  %4 = icmp ne ptr %0, null
  %5 = icmp ne ptr %1, null
  %or.cond = and i1 %4, %5
  %6 = icmp ne ptr %2, null
  %or.cond3 = and i1 %or.cond, %6
  br i1 %or.cond3, label %7, label %27

7:                                                ; preds = %3
  %8 = tail call noundef ptr @_ZN7UapkiNS4Util23attributeFromAttributesEPK10AttributesPKc(ptr noundef nonnull %0, ptr noundef nonnull %1)
  %.not = icmp eq ptr %8, null
  br i1 %.not, label %27, label %9

9:                                                ; preds = %7
  %10 = getelementptr inbounds i8, ptr %8, i64 24
  %11 = load i32, ptr %10, align 8, !tbaa !5
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %13, label %22

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

22:                                               ; preds = %9
  %23 = tail call ptr @ba_alloc()
  br label %24

24:                                               ; preds = %13, %22
  %storemerge = phi ptr [ %23, %22 ], [ %21, %13 ]
  store ptr %storemerge, ptr %2, align 8, !tbaa !18
  %25 = icmp eq ptr %storemerge, null
  br i1 %25, label %26, label %27

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

27:                                               ; preds = %26, %24, %7, %3
  %.0 = phi i32 [ 4101, %3 ], [ 2, %26 ], [ 0, %24 ], [ 4149, %7 ]
  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 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,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass