; LLVM IR from specinfo-ua/UAPKI :: library/common/pkix (private-key)

; 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.PrivateKeyInfo = type { %struct.ASN__PRIMITIVE_TYPE_s, %struct.AlgorithmIdentifier, %struct.OCTET_STRING, ptr, %struct.asn_struct_ctx_s }
%struct.ASN__PRIMITIVE_TYPE_s = type { ptr, i32 }
%struct.AlgorithmIdentifier = type { %struct.ASN__PRIMITIVE_TYPE_s, ptr, %struct.asn_struct_ctx_s }
%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 [26 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_create(ptr noundef, i64 noundef, i32 noundef, ptr noundef) #1

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

declare ptr @get_PrivateKeyInfo_desc() #1

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

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #2

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

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

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

13:                                               ; preds = %4
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %18, label %16

16:                                               ; preds = %13
  store i32 2, ptr %9, align 4, !tbaa !9
  %17 = load i32, ptr %9, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 940, i32 noundef %17, ptr noundef null)
  br label %112

18:                                               ; preds = %13
  br label %19

19:                                               ; preds = %18
  br label %20

20:                                               ; preds = %19
  br label %21

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

24:                                               ; preds = %21
  store i32 2, ptr %9, align 4, !tbaa !9
  %25 = load i32, ptr %9, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 941, i32 noundef %25, ptr noundef null)
  br label %112

26:                                               ; preds = %21
  br label %27

27:                                               ; preds = %26
  br label %28

28:                                               ; preds = %27
  br label %29

29:                                               ; preds = %28
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = icmp ne ptr %30, null
  br i1 %31, label %34, label %32

32:                                               ; preds = %29
  store i32 2, ptr %9, align 4, !tbaa !9
  %33 = load i32, ptr %9, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 942, i32 noundef %33, ptr noundef null)
  br label %112

34:                                               ; preds = %29
  br label %35

35:                                               ; preds = %34
  br label %36

36:                                               ; preds = %35
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = call i32 @signature_from_oid(ptr noundef %37)
  store i32 %38, ptr %10, align 4, !tbaa !9
  %39 = icmp eq i32 %38, 0
  br i1 %39, label %40, label %45

40:                                               ; preds = %36
  br label %41

41:                                               ; preds = %40
  store i32 1047, ptr %9, align 4, !tbaa !9
  %42 = load i32, ptr %9, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 945, i32 noundef %42, ptr noundef null)
  br label %112

43:                                               ; No predecessors!
  br label %44

44:                                               ; preds = %43
  br label %45

45:                                               ; preds = %44, %36
  %46 = load i32, ptr %10, align 4, !tbaa !9
  %47 = icmp ne i32 8, %46
  br i1 %47, label %48, label %59

48:                                               ; preds = %45
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = call i32 @hash_from_oid(ptr noundef %49)
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  store i32 %50, ptr %51, align 4, !tbaa !9
  %52 = icmp eq i32 %50, 0
  br i1 %52, label %53, label %58

53:                                               ; preds = %48
  br label %54

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

56:                                               ; No predecessors!
  br label %57

57:                                               ; preds = %56
  br label %58

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

59:                                               ; preds = %45
  br label %60

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

66:                                               ; preds = %60
  %67 = load i32, ptr %9, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 954, i32 noundef %67)
  br label %112

68:                                               ; preds = %60
  br label %69

69:                                               ; preds = %68
  br label %70

70:                                               ; preds = %69
  %71 = load ptr, ptr %8, align 8, !tbaa !5
  %72 = load i32, ptr %71, align 4, !tbaa !9
  %73 = icmp eq i32 %72, 0
  br i1 %73, label %74, label %79

74:                                               ; preds = %70
  br label %75

75:                                               ; preds = %74
  store i32 1047, ptr %9, align 4, !tbaa !9
  %76 = load i32, ptr %9, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 956, i32 noundef %76, ptr noundef null)
  br label %112

77:                                               ; No predecessors!
  br label %78

78:                                               ; preds = %77
  br label %79

79:                                               ; preds = %78, %70
  br label %80

80:                                               ; preds = %79, %58
  br label %81

81:                                               ; preds = %80
  %82 = call ptr @get_PrivateKeyInfo_desc()
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  %84 = call ptr @asn_decode_ba_with_alloc(ptr noundef %82, ptr noundef %83)
  store ptr %84, ptr %11, align 8, !tbaa !5
  %85 = icmp eq ptr null, %84
  br i1 %85, label %86, label %88

86:                                               ; preds = %81
  store i32 2, ptr %9, align 4, !tbaa !9
  %87 = load i32, ptr %9, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 960, i32 noundef %87)
  br label %112

88:                                               ; preds = %81
  br label %89

89:                                               ; preds = %88
  br label %90

90:                                               ; preds = %89
  br label %91

91:                                               ; preds = %90
  %92 = load ptr, ptr %11, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.PrivateKeyInfo, ptr %92, i32 0, i32 1
  %94 = getelementptr inbounds %struct.AlgorithmIdentifier, ptr %93, i32 0, i32 0
  %95 = call i32 @asn_oid_to_text(ptr noundef %94, ptr noundef %12)
  store i32 %95, ptr %9, align 4, !tbaa !9
  %96 = load i32, ptr %9, align 4, !tbaa !9
  %97 = icmp ne i32 %96, 0
  br i1 %97, label %98, label %100

98:                                               ; preds = %91
  %99 = load i32, ptr %9, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 961, i32 noundef %99)
  br label %112

100:                                              ; preds = %91
  br label %101

101:                                              ; preds = %100
  br label %102

102:                                              ; preds = %101
  %103 = load ptr, ptr %12, align 8, !tbaa !5
  %104 = load i32, ptr %10, align 4, !tbaa !9
  %105 = call zeroext i1 @private_key_check_algo(ptr noundef %103, i32 noundef %104)
  br i1 %105, label %111, label %106

106:                                              ; preds = %102
  br label %107

107:                                              ; preds = %106
  store i32 1053, ptr %9, align 4, !tbaa !9
  %108 = load i32, ptr %9, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 964, i32 noundef %108, ptr noundef null)
  br label %112

109:                                              ; No predecessors!
  br label %110

110:                                              ; preds = %109
  br label %111

111:                                              ; preds = %110, %102
  br label %112

112:                                              ; preds = %111, %107, %98, %86, %75, %66, %54, %41, %32, %24, %16
  %113 = call ptr @get_PrivateKeyInfo_desc()
  %114 = load ptr, ptr %11, align 8, !tbaa !5
  call void @asn_free(ptr noundef %113, ptr noundef %114)
  %115 = load ptr, ptr %12, align 8, !tbaa !5
  call void @free(ptr noundef %115) #4
  %116 = load i32, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  ret i32 %116
}

declare i32 @signature_from_oid(ptr noundef) #1

declare i32 @hash_from_oid(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @hash_from_rsa_pss(ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @private_key_check_algo(ptr noundef, i32 noundef) #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 "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 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 = { 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}


; 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 [26 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_create(ptr noundef, i64 noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

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

declare ptr @get_PrivateKeyInfo_desc() local_unnamed_addr #1

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

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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #2

declare void @asn_free(ptr noundef, ptr 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

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

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

7:                                                ; preds = %4
  %.not35 = icmp eq ptr %1, null
  br i1 %.not35, label %8, label %9

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

9:                                                ; preds = %7
  %.not36 = icmp eq ptr %3, null
  br i1 %.not36, label %10, label %11

10:                                               ; preds = %9
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 942, i32 noundef 2, ptr noundef null) #4
  br label %38

11:                                               ; preds = %9
  %12 = tail call i32 @signature_from_oid(ptr noundef nonnull %1) #4
  switch i32 %12, label %14 [
    i32 0, label %13
    i32 8, label %18
  ]

13:                                               ; preds = %11
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 945, i32 noundef 1047, ptr noundef null) #4
  br label %38

14:                                               ; preds = %11
  %15 = tail call i32 @hash_from_oid(ptr noundef nonnull %1) #4
  store i32 %15, ptr %3, align 4, !tbaa !9
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %25

17:                                               ; preds = %14
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 950, i32 noundef 1047, ptr noundef null) #4
  br label %38

18:                                               ; preds = %11
  %19 = tail call i32 @hash_from_rsa_pss(ptr noundef %2, ptr noundef nonnull %3)
  %.not38 = icmp eq i32 %19, 0
  br i1 %.not38, label %21, label %20

20:                                               ; preds = %18
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 954, i32 noundef %19) #4
  br label %38

21:                                               ; preds = %18
  %22 = load i32, ptr %3, align 4, !tbaa !9
  %23 = icmp eq i32 %22, 0
  br i1 %23, label %24, label %25

24:                                               ; preds = %21
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 956, i32 noundef 1047, ptr noundef null) #4
  br label %38

25:                                               ; preds = %14, %21
  %26 = tail call ptr @get_PrivateKeyInfo_desc() #4
  %27 = tail call ptr @asn_decode_ba_with_alloc(ptr noundef %26, ptr noundef nonnull %0) #4
  %28 = icmp eq ptr %27, null
  br i1 %28, label %29, label %30

29:                                               ; preds = %25
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 960, i32 noundef 2) #4
  br label %38

30:                                               ; preds = %25
  %31 = getelementptr inbounds i8, ptr %27, i64 16
  %32 = call i32 @asn_oid_to_text(ptr noundef nonnull %31, ptr noundef nonnull %5) #4
  %.not39 = icmp eq i32 %32, 0
  br i1 %.not39, label %34, label %33

33:                                               ; preds = %30
  call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 961, i32 noundef %32) #4
  br label %38

34:                                               ; preds = %30
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = call zeroext i1 @private_key_check_algo(ptr noundef %35, i32 noundef %12)
  br i1 %36, label %38, label %37

37:                                               ; preds = %34
  call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 964, i32 noundef 1053, ptr noundef null) #4
  br label %38

38:                                               ; preds = %34, %37, %33, %29, %24, %20, %17, %13, %10, %8, %6
  %.026 = phi i32 [ 1047, %13 ], [ 1047, %17 ], [ 2, %29 ], [ %32, %33 ], [ 0, %34 ], [ 1053, %37 ], [ %19, %20 ], [ 1047, %24 ], [ 2, %10 ], [ 2, %8 ], [ 2, %6 ]
  %.0 = phi ptr [ null, %13 ], [ null, %17 ], [ null, %29 ], [ %27, %33 ], [ %27, %34 ], [ %27, %37 ], [ null, %20 ], [ null, %24 ], [ null, %10 ], [ null, %8 ], [ null, %6 ]
  %39 = call ptr @get_PrivateKeyInfo_desc() #4
  call void @asn_free(ptr noundef %39, ptr noundef %.0) #4
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  call void @free(ptr noundef %40) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  ret i32 %.026
}

declare i32 @signature_from_oid(ptr noundef) local_unnamed_addr #1

declare i32 @hash_from_oid(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i32 @hash_from_rsa_pss(ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @private_key_check_algo(ptr noundef, i32 noundef) 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 nounwind willreturn allockind("free") memory(argmem: readwrite, 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 = { 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 #4 = { 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}


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