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

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

declare ptr @get_OCTET_STRING_desc() #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7UapkiNS4Util15decodeAnyStringEPKhmRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE(ptr noundef %0, i64 noundef %1, ptr noundef nonnull align 8 dereferenceable(32) %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  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 !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store ptr null, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store ptr null, ptr %10, align 8, !tbaa !5
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %15, label %14

14:                                               ; preds = %3
  store i32 4101, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %71

15:                                               ; preds = %3
  %16 = load i64, ptr %6, align 8, !tbaa !9
  %17 = icmp ult i64 %16, 2
  br i1 %17, label %18, label %19

18:                                               ; preds = %15
  store i32 4145, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %71

19:                                               ; preds = %15
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %20, i64 0
  %22 = load i8, ptr %21, align 1, !tbaa !13
  %23 = zext i8 %22 to i32
  switch i32 %23, label %32 [
    i32 12, label %24
    i32 19, label %26
    i32 20, label %28
    i32 22, label %30
  ]

24:                                               ; preds = %19
  %25 = call ptr @get_UTF8String_desc()
  store ptr %25, ptr %10, align 8, !tbaa !5
  br label %37

26:                                               ; preds = %19
  %27 = call ptr @get_PrintableString_desc()
  store ptr %27, ptr %10, align 8, !tbaa !5
  br label %37

28:                                               ; preds = %19
  %29 = call ptr @get_TeletexString_desc()
  store ptr %29, ptr %10, align 8, !tbaa !5
  br label %37

30:                                               ; preds = %19
  %31 = call ptr @get_IA5String_desc()
  store ptr %31, ptr %10, align 8, !tbaa !5
  br label %37

32:                                               ; preds = %19
  br label %33

33:                                               ; preds = %32
  store i32 4145, ptr %8, align 4, !tbaa !11
  %34 = load i32, ptr %8, align 4, !tbaa !11
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 735, i32 noundef %34, ptr noundef null)
  br label %67

35:                                               ; No predecessors!
  br label %36

36:                                               ; preds = %35
  br label %37

37:                                               ; preds = %36, %30, %28, %26, %24
  %38 = load ptr, ptr %10, align 8, !tbaa !5
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = load i64, ptr %6, align 8, !tbaa !9
  %41 = call ptr @asn_decode_with_alloc(ptr noundef %38, ptr noundef %39, i64 noundef %40)
  store ptr %41, ptr %9, align 8, !tbaa !5
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  %43 = icmp ne ptr %42, null
  br i1 %43, label %49, label %44

44:                                               ; preds = %37
  br label %45

45:                                               ; preds = %44
  store i32 4145, ptr %8, align 4, !tbaa !11
  %46 = load i32, ptr %8, align 4, !tbaa !11
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 740, i32 noundef %46, ptr noundef null)
  br label %67

47:                                               ; No predecessors!
  br label %48

48:                                               ; preds = %47
  br label %49

49:                                               ; preds = %48, %37
  br label %50

50:                                               ; preds = %49
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.OCTET_STRING, ptr %51, i32 0, i32 0
  %53 = load ptr, ptr %52, align 8, !tbaa !14
  %54 = load ptr, ptr %9, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.OCTET_STRING, ptr %54, i32 0, i32 1
  %56 = load i32, ptr %55, align 8, !tbaa !18
  %57 = sext i32 %56 to i64
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = call noundef i32 @_ZN7UapkiNS4Util9pbufToStrEPKhmRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE(ptr noundef %53, i64 noundef %57, ptr noundef nonnull align 8 dereferenceable(32) %58)
  store i32 %59, ptr %8, align 4, !tbaa !11
  %60 = load i32, ptr %8, align 4, !tbaa !11
  %61 = icmp ne i32 %60, 0
  br i1 %61, label %62, label %64

62:                                               ; preds = %50
  %63 = load i32, ptr %8, align 4, !tbaa !11
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 743, i32 noundef %63)
  br label %67

64:                                               ; preds = %50
  br label %65

65:                                               ; preds = %64
  br label %66

66:                                               ; preds = %65
  br label %67

67:                                               ; preds = %66, %62, %45, %33
  %68 = call ptr @get_OCTET_STRING_desc()
  %69 = load ptr, ptr %9, align 8, !tbaa !5
  call void @asn_free(ptr noundef %68, ptr noundef %69)
  %70 = load i32, ptr %8, align 4, !tbaa !11
  store i32 %70, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %71

71:                                               ; preds = %67, %18, %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %72 = load i32, ptr %4, align 4
  ret i32 %72
}

declare ptr @get_UTF8String_desc() #1

declare ptr @get_PrintableString_desc() #1

declare ptr @get_TeletexString_desc() #1

declare ptr @get_IA5String_desc() #1

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

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

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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !6, i64 0}
!15 = !{!"_ZTS12OCTET_STRING", !6, i64 0, !12, i64 8, !16, i64 16}
!16 = !{!"_ZTS16asn_struct_ctx_s", !17, i64 0, !17, i64 2, !12, i64 4, !6, i64 8, !10, i64 16}
!17 = !{!"short", !7, i64 0}
!18 = !{!15, !12, 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 void @stacktrace_create(ptr noundef, i64 noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

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

declare ptr @get_OCTET_STRING_desc() local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7UapkiNS4Util15decodeAnyStringEPKhmRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE(ptr noundef %0, i64 noundef %1, ptr noundef nonnull align 8 dereferenceable(32) %2) local_unnamed_addr #1 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %29, label %4

4:                                                ; preds = %3
  %5 = icmp ult i64 %1, 2
  br i1 %5, label %29, label %6

6:                                                ; preds = %4
  %7 = load i8, ptr %0, align 1, !tbaa !5
  switch i8 %7, label %16 [
    i8 12, label %8
    i8 19, label %10
    i8 20, label %12
    i8 22, label %14
  ]

8:                                                ; preds = %6
  %9 = tail call ptr @get_UTF8String_desc()
  br label %17

10:                                               ; preds = %6
  %11 = tail call ptr @get_PrintableString_desc()
  br label %17

12:                                               ; preds = %6
  %13 = tail call ptr @get_TeletexString_desc()
  br label %17

14:                                               ; preds = %6
  %15 = tail call ptr @get_IA5String_desc()
  br label %17

16:                                               ; preds = %6
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 735, i32 noundef 4145, ptr noundef null)
  br label %27

17:                                               ; preds = %14, %12, %10, %8
  %.0 = phi ptr [ %15, %14 ], [ %13, %12 ], [ %11, %10 ], [ %9, %8 ]
  %18 = tail call ptr @asn_decode_with_alloc(ptr noundef %.0, ptr noundef nonnull %0, i64 noundef %1)
  %.not24 = icmp eq ptr %18, null
  br i1 %.not24, label %19, label %20

19:                                               ; preds = %17
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 740, i32 noundef 4145, ptr noundef null)
  br label %27

20:                                               ; preds = %17
  %21 = load ptr, ptr %18, align 8, !tbaa !8
  %22 = getelementptr inbounds i8, ptr %18, i64 8
  %23 = load i32, ptr %22, align 8, !tbaa !15
  %24 = sext i32 %23 to i64
  %25 = tail call noundef i32 @_ZN7UapkiNS4Util9pbufToStrEPKhmRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE(ptr noundef %21, i64 noundef %24, ptr noundef nonnull align 8 dereferenceable(32) %2)
  %.not25 = icmp eq i32 %25, 0
  br i1 %.not25, label %27, label %26

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

27:                                               ; preds = %20, %26, %19, %16
  %.017 = phi i32 [ 4145, %16 ], [ %25, %26 ], [ 0, %20 ], [ 4145, %19 ]
  %.016 = phi ptr [ null, %16 ], [ %18, %26 ], [ %18, %20 ], [ null, %19 ]
  %28 = tail call ptr @get_OCTET_STRING_desc()
  tail call void @asn_free(ptr noundef %28, ptr noundef %.016)
  br label %29

29:                                               ; preds = %4, %3, %27
  %.018 = phi i32 [ %.017, %27 ], [ 4101, %3 ], [ 4145, %4 ]
  ret i32 %.018
}

declare ptr @get_UTF8String_desc() local_unnamed_addr #0

declare ptr @get_PrintableString_desc() local_unnamed_addr #0

declare ptr @get_TeletexString_desc() local_unnamed_addr #0

declare ptr @get_IA5String_desc() local_unnamed_addr #0

declare ptr @asn_decode_with_alloc(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

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

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


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