; LLVM IR from specinfo-ua/UAPKI :: library/cm-pkcs12/src/storage (pkcs12-utils)

; 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.CertBag = type { %struct.ASN__PRIMITIVE_TYPE_s, %struct.ANY, %struct.asn_struct_ctx_s }
%struct.ASN__PRIMITIVE_TYPE_s = type { ptr, i32 }
%struct.ANY = 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 [33 x i8], align 1
@OID_PKCS9_X509_CERTIFICATE = external global ptr, align 8
@OID_PKCS9_SDSI_CERTIFICATE = external global ptr, align 8

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

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

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 i32 @asn_OCTSTRING2ba(ptr noundef, ptr noundef) #1

declare zeroext i1 @OID_is_equal_oid(ptr noundef, ptr noundef) #1

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

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

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

10:                                               ; preds = %3
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  br i1 %12, label %15, label %13

13:                                               ; preds = %10
  store i32 2, ptr %7, align 4, !tbaa !9
  %14 = load i32, ptr %7, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 145, i32 noundef %14, ptr noundef null)
  br label %86

15:                                               ; preds = %10
  br label %16

16:                                               ; preds = %15
  br label %17

17:                                               ; preds = %16
  br label %18

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

21:                                               ; preds = %18
  store i32 2, ptr %7, align 4, !tbaa !9
  %22 = load i32, ptr %7, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 146, i32 noundef %22, ptr noundef null)
  br label %86

23:                                               ; preds = %18
  br label %24

24:                                               ; preds = %23
  br label %25

25:                                               ; preds = %24
  br label %26

26:                                               ; preds = %25
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = icmp ne ptr %27, null
  br i1 %28, label %31, label %29

29:                                               ; preds = %26
  store i32 2, ptr %7, align 4, !tbaa !9
  %30 = load i32, ptr %7, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 147, i32 noundef %30, ptr noundef null)
  br label %86

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 %4, align 8, !tbaa !5
  %36 = call ptr @get_CertBag_desc()
  %37 = call ptr @asn_any2type(ptr noundef %35, ptr noundef %36)
  store ptr %37, ptr %8, align 8, !tbaa !5
  %38 = icmp eq ptr null, %37
  br i1 %38, label %39, label %41

39:                                               ; preds = %34
  store i32 2, ptr %7, align 4, !tbaa !9
  %40 = load i32, ptr %7, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 149, i32 noundef %40)
  br label %86

41:                                               ; preds = %34
  br label %42

42:                                               ; preds = %41
  br label %43

43:                                               ; preds = %42
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.CertBag, ptr %44, i32 0, i32 0
  %46 = load ptr, ptr @OID_PKCS9_X509_CERTIFICATE, align 8, !tbaa !5
  %47 = call zeroext i1 @OID_is_equal_oid(ptr noundef %45, ptr noundef %46)
  br i1 %47, label %48, label %72

48:                                               ; preds = %43
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  store i8 0, ptr %49, align 1, !tbaa !11
  br label %50

50:                                               ; preds = %48
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.CertBag, ptr %51, i32 0, i32 1
  %53 = call ptr @get_OCTET_STRING_desc()
  %54 = call ptr @asn_any2type(ptr noundef %52, ptr noundef %53)
  store ptr %54, ptr %9, align 8, !tbaa !5
  %55 = icmp eq ptr null, %54
  br i1 %55, label %56, label %58

56:                                               ; preds = %50
  store i32 2, ptr %7, align 4, !tbaa !9
  %57 = load i32, ptr %7, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 153, i32 noundef %57)
  br label %86

58:                                               ; preds = %50
  br label %59

59:                                               ; preds = %58
  br label %60

60:                                               ; preds = %59
  br label %61

61:                                               ; preds = %60
  %62 = load ptr, ptr %9, align 8, !tbaa !5
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = call i32 @asn_OCTSTRING2ba(ptr noundef %62, ptr noundef %63)
  store i32 %64, ptr %7, align 4, !tbaa !9
  %65 = load i32, ptr %7, align 4, !tbaa !9
  %66 = icmp ne i32 %65, 0
  br i1 %66, label %67, label %69

67:                                               ; preds = %61
  %68 = load i32, ptr %7, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 154, i32 noundef %68)
  br label %86

69:                                               ; preds = %61
  br label %70

70:                                               ; preds = %69
  br label %71

71:                                               ; preds = %70
  br label %85

72:                                               ; preds = %43
  %73 = load ptr, ptr %8, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.CertBag, ptr %73, i32 0, i32 0
  %75 = load ptr, ptr @OID_PKCS9_SDSI_CERTIFICATE, align 8, !tbaa !5
  %76 = call zeroext i1 @OID_is_equal_oid(ptr noundef %74, ptr noundef %75)
  br i1 %76, label %77, label %79

77:                                               ; preds = %72
  %78 = load ptr, ptr %6, align 8, !tbaa !5
  store i8 1, ptr %78, align 1, !tbaa !11
  br label %84

79:                                               ; preds = %72
  br label %80

80:                                               ; preds = %79
  store i32 1039, ptr %7, align 4, !tbaa !9
  %81 = load i32, ptr %7, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 160, i32 noundef %81, ptr noundef null)
  br label %86

82:                                               ; No predecessors!
  br label %83

83:                                               ; preds = %82
  br label %84

84:                                               ; preds = %83, %77
  br label %85

85:                                               ; preds = %84, %71
  br label %86

86:                                               ; preds = %85, %80, %67, %56, %39, %29, %21, %13
  %87 = call ptr @get_OCTET_STRING_desc()
  %88 = load ptr, ptr %9, align 8, !tbaa !5
  call void @asn_free(ptr noundef %87, ptr noundef %88)
  %89 = call ptr @get_CertBag_desc()
  %90 = load ptr, ptr %8, align 8, !tbaa !5
  call void @asn_free(ptr noundef %89, ptr noundef %90)
  %91 = load i32, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret i32 %91
}

declare ptr @get_CertBag_desc() #1

declare ptr @get_OCTET_STRING_desc() #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 = { 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 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"_Bool", !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 [33 x i8], align 1
@OID_PKCS9_X509_CERTIFICATE = external local_unnamed_addr global ptr, align 8
@OID_PKCS9_SDSI_CERTIFICATE = external local_unnamed_addr global ptr, align 8

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

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

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

declare zeroext i1 @OID_is_equal_oid(ptr noundef, ptr noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @pkcs12_read_cert_bag(ptr noundef %0, ptr noundef %1, ptr noundef writeonly %2) local_unnamed_addr #1 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %4, label %5

4:                                                ; preds = %3
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 145, i32 noundef 2, ptr noundef null) #2
  br label %31

5:                                                ; preds = %3
  %.not31 = icmp eq ptr %1, null
  br i1 %.not31, label %6, label %7

6:                                                ; preds = %5
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 146, i32 noundef 2, ptr noundef null) #2
  br label %31

7:                                                ; preds = %5
  %.not32 = icmp eq ptr %2, null
  br i1 %.not32, label %8, label %9

8:                                                ; preds = %7
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 147, i32 noundef 2, ptr noundef null) #2
  br label %31

9:                                                ; preds = %7
  %10 = tail call ptr @get_CertBag_desc() #2
  %11 = tail call ptr @asn_any2type(ptr noundef nonnull %0, ptr noundef %10) #2
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %14

13:                                               ; preds = %9
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 149, i32 noundef 2) #2
  br label %31

14:                                               ; preds = %9
  %15 = load ptr, ptr @OID_PKCS9_X509_CERTIFICATE, align 8, !tbaa !5
  %16 = tail call zeroext i1 @OID_is_equal_oid(ptr noundef nonnull %11, ptr noundef %15) #2
  br i1 %16, label %17, label %26

17:                                               ; preds = %14
  store i8 0, ptr %2, align 1, !tbaa !9
  %18 = getelementptr inbounds i8, ptr %11, i64 16
  %19 = tail call ptr @get_OCTET_STRING_desc() #2
  %20 = tail call ptr @asn_any2type(ptr noundef nonnull %18, ptr noundef %19) #2
  %21 = icmp eq ptr %20, null
  br i1 %21, label %22, label %23

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

23:                                               ; preds = %17
  %24 = tail call i32 @asn_OCTSTRING2ba(ptr noundef nonnull %20, ptr noundef nonnull %1) #2
  %.not33 = icmp eq i32 %24, 0
  br i1 %.not33, label %31, label %25

25:                                               ; preds = %23
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 154, i32 noundef %24) #2
  br label %31

26:                                               ; preds = %14
  %27 = load ptr, ptr @OID_PKCS9_SDSI_CERTIFICATE, align 8, !tbaa !5
  %28 = tail call zeroext i1 @OID_is_equal_oid(ptr noundef nonnull %11, ptr noundef %27) #2
  br i1 %28, label %29, label %30

29:                                               ; preds = %26
  store i8 1, ptr %2, align 1, !tbaa !9
  br label %31

30:                                               ; preds = %26
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 160, i32 noundef 1039, ptr noundef null) #2
  br label %31

31:                                               ; preds = %29, %23, %30, %25, %22, %13, %8, %6, %4
  %.022 = phi i32 [ 2, %13 ], [ 2, %22 ], [ %24, %25 ], [ 0, %23 ], [ 0, %29 ], [ 1039, %30 ], [ 2, %8 ], [ 2, %6 ], [ 2, %4 ]
  %.021 = phi ptr [ null, %13 ], [ %11, %22 ], [ %11, %25 ], [ %11, %23 ], [ %11, %29 ], [ %11, %30 ], [ null, %8 ], [ null, %6 ], [ null, %4 ]
  %.0 = phi ptr [ null, %13 ], [ null, %22 ], [ %20, %25 ], [ %20, %23 ], [ null, %29 ], [ null, %30 ], [ null, %8 ], [ null, %6 ], [ null, %4 ]
  %32 = tail call ptr @get_OCTET_STRING_desc() #2
  tail call void @asn_free(ptr noundef %32, ptr noundef %.0) #2
  %33 = tail call ptr @get_CertBag_desc() #2
  tail call void @asn_free(ptr noundef %33, ptr noundef %.021) #2
  ret i32 %.022
}

declare ptr @get_CertBag_desc() local_unnamed_addr #0

declare ptr @get_OCTET_STRING_desc() 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 = { 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 #2 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"_Bool", !7, i64 0}


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