; 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.Extension = type { %struct.ASN__PRIMITIVE_TYPE_s, ptr, %struct.OCTET_STRING, %struct.asn_struct_ctx_s }
%struct.ASN__PRIMITIVE_TYPE_s = type { ptr, i32 }
%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 [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 void @stacktrace_create(ptr noundef, i64 noundef, i32 noundef, ptr noundef) #1

; Function Attrs: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #2

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

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

declare ptr @asn_copy_with_alloc(ptr noundef, ptr noundef) #1

declare ptr @get_BOOLEAN_desc() #1

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

declare ptr @get_Extension_desc() #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7UapkiNS4Util15encodeExtensionERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEbPK12ByteArray_stPPS9_(ptr noundef nonnull align 8 dereferenceable(32) %0, i1 noundef zeroext %1, ptr noundef %2, ptr noundef %3) #3 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  %14 = zext i1 %1 to i8
  store i8 %14, ptr %7, align 1, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  store i32 0, ptr %10, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  store ptr null, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  store i32 1, ptr %12, align 4, !tbaa !11
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = call noundef zeroext i1 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5emptyEv(ptr noundef nonnull align 8 dereferenceable(32) %15) #5
  br i1 %16, label %23, label %17

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

20:                                               ; preds = %17
  %21 = load ptr, ptr %9, align 8, !tbaa !5
  %22 = icmp ne ptr %21, null
  br i1 %22, label %24, label %23

23:                                               ; preds = %20, %17, %4
  store i32 4101, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %89

24:                                               ; preds = %20
  %25 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 88) #6
  store ptr %25, ptr %11, align 8, !tbaa !5
  br label %26

26:                                               ; preds = %24
  %27 = load ptr, ptr %11, align 8, !tbaa !5
  %28 = icmp eq ptr %27, null
  br i1 %28, label %29, label %31

29:                                               ; preds = %26
  store i32 1, ptr %10, align 4, !tbaa !11
  %30 = load i32, ptr %10, align 4, !tbaa !11
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 322, i32 noundef %30, ptr noundef null)
  br label %85

31:                                               ; preds = %26
  br label %32

32:                                               ; preds = %31
  br label %33

33:                                               ; preds = %32
  br label %34

34:                                               ; preds = %33
  %35 = load ptr, ptr %11, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.Extension, ptr %35, i32 0, i32 0
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = call noundef i32 @_ZN7UapkiNS4Util9oidToAsn1EP21ASN__PRIMITIVE_TYPE_sRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE(ptr noundef %36, ptr noundef nonnull align 8 dereferenceable(32) %37)
  store i32 %38, ptr %10, align 4, !tbaa !11
  %39 = load i32, ptr %10, align 4, !tbaa !11
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %43

41:                                               ; preds = %34
  %42 = load i32, ptr %10, align 4, !tbaa !11
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 324, i32 noundef %42)
  br label %85

43:                                               ; preds = %34
  br label %44

44:                                               ; preds = %43
  br label %45

45:                                               ; preds = %44
  %46 = load i8, ptr %7, align 1, !tbaa !9, !range !13, !noundef !14
  %47 = trunc i8 %46 to i1
  br i1 %47, label %48, label %60

48:                                               ; preds = %45
  br label %49

49:                                               ; preds = %48
  %50 = call ptr @get_BOOLEAN_desc()
  %51 = call ptr @asn_copy_with_alloc(ptr noundef %50, ptr noundef %12)
  %52 = load ptr, ptr %11, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.Extension, ptr %52, i32 0, i32 1
  store ptr %51, ptr %53, align 8, !tbaa !15
  %54 = icmp eq ptr null, %51
  br i1 %54, label %55, label %57

55:                                               ; preds = %49
  store i32 2, ptr %10, align 4, !tbaa !11
  %56 = load i32, ptr %10, align 4, !tbaa !11
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 326, i32 noundef %56)
  br label %85

57:                                               ; preds = %49
  br label %58

58:                                               ; preds = %57
  br label %59

59:                                               ; preds = %58
  br label %60

60:                                               ; preds = %59, %45
  br label %61

61:                                               ; preds = %60
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  %63 = load ptr, ptr %11, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.Extension, ptr %63, i32 0, i32 2
  %65 = call i32 @asn_ba2OCTSTRING(ptr noundef %62, ptr noundef %64)
  store i32 %65, ptr %10, align 4, !tbaa !11
  %66 = load i32, ptr %10, align 4, !tbaa !11
  %67 = icmp ne i32 %66, 0
  br i1 %67, label %68, label %70

68:                                               ; preds = %61
  %69 = load i32, ptr %10, align 4, !tbaa !11
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 328, i32 noundef %69)
  br label %85

70:                                               ; preds = %61
  br label %71

71:                                               ; preds = %70
  br label %72

72:                                               ; preds = %71
  br label %73

73:                                               ; preds = %72
  %74 = call ptr @get_Extension_desc()
  %75 = load ptr, ptr %11, align 8, !tbaa !5
  %76 = load ptr, ptr %9, align 8, !tbaa !5
  %77 = call i32 @asn_encode_ba(ptr noundef %74, ptr noundef %75, ptr noundef %76)
  store i32 %77, ptr %10, align 4, !tbaa !11
  %78 = load i32, ptr %10, align 4, !tbaa !11
  %79 = icmp ne i32 %78, 0
  br i1 %79, label %80, label %82

80:                                               ; preds = %73
  %81 = load i32, ptr %10, align 4, !tbaa !11
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 330, i32 noundef %81)
  br label %85

82:                                               ; preds = %73
  br label %83

83:                                               ; preds = %82
  br label %84

84:                                               ; preds = %83
  br label %85

85:                                               ; preds = %84, %80, %68, %55, %41, %29
  %86 = call ptr @get_Extension_desc()
  %87 = load ptr, ptr %11, align 8, !tbaa !5
  call void @asn_free(ptr noundef %86, ptr noundef %87)
  %88 = load i32, ptr %10, align 4, !tbaa !11
  store i32 %88, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %89

89:                                               ; preds = %85, %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  %90 = load i32, ptr %5, align 4
  ret i32 %90
}

; Function Attrs: mustprogress nounwind uwtable
declare noundef zeroext i1 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5emptyEv(ptr noundef nonnull align 8 dereferenceable(32)) #4 align 2

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

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 = { 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 = { 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 #5 = { nounwind }
attributes #6 = { 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 = !{!"bool", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!16, !6, i64 16}
!16 = !{!"_ZTS9Extension", !17, i64 0, !6, i64 16, !18, i64 24, !19, i64 64}
!17 = !{!"_ZTS21ASN__PRIMITIVE_TYPE_s", !6, i64 0, !12, i64 8}
!18 = !{!"_ZTS12OCTET_STRING", !6, i64 0, !12, i64 8, !19, i64 16}
!19 = !{!"_ZTS16asn_struct_ctx_s", !20, i64 0, !20, i64 2, !12, i64 4, !6, i64 8, !21, i64 16}
!20 = !{!"short", !7, i64 0}
!21 = !{!"long", !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"

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

; Function Attrs: mustprogress 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) local_unnamed_addr #1

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

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

; 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 #2

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

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

declare ptr @asn_copy_with_alloc(ptr noundef, ptr noundef) local_unnamed_addr #1

declare ptr @get_BOOLEAN_desc() local_unnamed_addr #1

declare i32 @asn_ba2OCTSTRING(ptr noundef, ptr noundef) local_unnamed_addr #1

declare ptr @get_Extension_desc() local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7UapkiNS4Util15encodeExtensionERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEbPK12ByteArray_stPPS9_(ptr noundef nonnull align 8 dereferenceable(32) %0, i1 noundef zeroext %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #3 {
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #5
  store i32 1, ptr %5, align 4, !tbaa !5
  %6 = tail call noundef zeroext i1 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5emptyEv(ptr noundef nonnull align 8 dereferenceable(32) %0) #5
  %.not = xor i1 %6, true
  %7 = icmp ne ptr %2, null
  %or.cond = and i1 %7, %.not
  %8 = icmp ne ptr %3, null
  %or.cond3 = and i1 %8, %or.cond
  br i1 %or.cond3, label %9, label %33

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

13:                                               ; preds = %9
  %14 = tail call noundef i32 @_ZN7UapkiNS4Util9oidToAsn1EP21ASN__PRIMITIVE_TYPE_sRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE(ptr noundef nonnull %10, ptr noundef nonnull align 8 dereferenceable(32) %0)
  %.not32 = icmp eq i32 %14, 0
  br i1 %.not32, label %16, label %15

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

16:                                               ; preds = %13
  br i1 %1, label %17, label %23

17:                                               ; preds = %16
  %18 = tail call ptr @get_BOOLEAN_desc()
  %19 = call ptr @asn_copy_with_alloc(ptr noundef %18, ptr noundef nonnull %5)
  %20 = getelementptr inbounds i8, ptr %10, i64 16
  store ptr %19, ptr %20, align 8, !tbaa !9
  %21 = icmp eq ptr %19, null
  br i1 %21, label %22, label %23

22:                                               ; preds = %17
  call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 326, i32 noundef 2)
  br label %31

23:                                               ; preds = %16, %17
  %24 = getelementptr inbounds i8, ptr %10, i64 24
  %25 = call i32 @asn_ba2OCTSTRING(ptr noundef nonnull %2, ptr noundef nonnull %24)
  %.not33 = icmp eq i32 %25, 0
  br i1 %.not33, label %27, label %26

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

27:                                               ; preds = %23
  %28 = call ptr @get_Extension_desc()
  %29 = call i32 @asn_encode_ba(ptr noundef %28, ptr noundef nonnull %10, ptr noundef nonnull %3)
  %.not34 = icmp eq i32 %29, 0
  br i1 %.not34, label %31, label %30

30:                                               ; preds = %27
  call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 330, i32 noundef %29)
  br label %31

31:                                               ; preds = %27, %30, %26, %22, %15, %12
  %.0 = phi i32 [ 1, %12 ], [ %14, %15 ], [ 2, %22 ], [ %25, %26 ], [ %29, %30 ], [ 0, %27 ]
  %32 = call ptr @get_Extension_desc()
  call void @asn_free(ptr noundef %32, ptr noundef %10)
  br label %33

33:                                               ; preds = %4, %31
  %.025 = phi i32 [ %.0, %31 ], [ 4101, %4 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #5
  ret i32 %.025
}

; Function Attrs: mustprogress nounwind uwtable
declare noundef zeroext i1 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5emptyEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #4 align 2

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

attributes #0 = { mustprogress 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 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 #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 = { 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 #5 = { nounwind }
attributes #6 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !12, i64 16}
!10 = !{!"_ZTS9Extension", !11, i64 0, !12, i64 16, !13, i64 24, !14, i64 64}
!11 = !{!"_ZTS21ASN__PRIMITIVE_TYPE_s", !12, i64 0, !6, i64 8}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!"_ZTS12OCTET_STRING", !12, i64 0, !6, i64 8, !14, i64 16}
!14 = !{!"_ZTS16asn_struct_ctx_s", !15, i64 0, !15, i64 2, !6, i64 4, !12, i64 8, !16, i64 16}
!15 = !{!"short", !7, i64 0}
!16 = !{!"long", !7, i64 0}


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