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

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

@OID_DSTU4145_WITH_GOST3411 = external global ptr, align 8
@OID_DSTU4145_WITH_DSTU7564 = external global ptr, align 8
@OID_EC_KEY = external global ptr, align 8
@OID_RSA = external global ptr, align 8
@_ZL14SIGN_ALGO_DSTU = external hidden global [4 x ptr], align 16
@_ZL16SIGN_ALGOS_ECDSA = external hidden global [6 x ptr], align 16
@_ZL14SIGN_ALGOS_RSA = external hidden global [8 x ptr], align 16

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN8CmPkcs1221signAlgoByMechanismIdEPKcP12json_array_t(ptr noundef %0, ptr noundef %1) #1 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store i64 0, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store ptr null, ptr %7, align 8, !tbaa !5
  %11 = load ptr, ptr @OID_DSTU4145_WITH_DSTU7564, align 8, !tbaa !5
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = call zeroext i1 @oid_is_parent(ptr noundef %11, ptr noundef %12)
  br i1 %13, label %18, label %14

14:                                               ; preds = %2
  %15 = load ptr, ptr @OID_DSTU4145_WITH_GOST3411, align 8, !tbaa !5
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = call zeroext i1 @oid_is_parent(ptr noundef %15, ptr noundef %16)
  br i1 %17, label %18, label %19

18:                                               ; preds = %14, %2
  store i64 4, ptr %6, align 8, !tbaa !9
  store ptr @_ZL14SIGN_ALGO_DSTU, ptr %7, align 8, !tbaa !5
  br label %31

19:                                               ; preds = %14
  %20 = load ptr, ptr @OID_EC_KEY, align 8, !tbaa !5
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = call zeroext i1 @oid_is_equal(ptr noundef %20, ptr noundef %21)
  br i1 %22, label %23, label %24

23:                                               ; preds = %19
  store i64 6, ptr %6, align 8, !tbaa !9
  store ptr @_ZL16SIGN_ALGOS_ECDSA, ptr %7, align 8, !tbaa !5
  br label %30

24:                                               ; preds = %19
  %25 = load ptr, ptr @OID_RSA, align 8, !tbaa !5
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = call zeroext i1 @oid_is_equal(ptr noundef %25, ptr noundef %26)
  br i1 %27, label %28, label %29

28:                                               ; preds = %24
  store i64 8, ptr %6, align 8, !tbaa !9
  store ptr @_ZL14SIGN_ALGOS_RSA, ptr %7, align 8, !tbaa !5
  br label %29

29:                                               ; preds = %28, %24
  br label %30

30:                                               ; preds = %29, %23
  br label %31

31:                                               ; preds = %30, %18
  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 i64 0, ptr %9, align 8, !tbaa !9
  br label %32

32:                                               ; preds = %47, %31
  %33 = load i64, ptr %9, align 8, !tbaa !9
  %34 = load i64, ptr %6, align 8, !tbaa !9
  %35 = icmp ult i64 %33, %34
  br i1 %35, label %37, label %36

36:                                               ; preds = %32
  store i32 2, ptr %10, align 4
  br label %50

37:                                               ; preds = %32
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = load i64, ptr %9, align 8, !tbaa !9
  %41 = getelementptr inbounds ptr, ptr %39, i64 %40
  %42 = load ptr, ptr %41, align 8, !tbaa !5
  %43 = call i32 @json_array_append_string(ptr noundef %38, ptr noundef %42)
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %45, label %46

45:                                               ; preds = %37
  store i32 1064, ptr %8, align 4, !tbaa !11
  store i32 5, ptr %10, align 4
  br label %50

46:                                               ; preds = %37
  br label %47

47:                                               ; preds = %46
  %48 = load i64, ptr %9, align 8, !tbaa !9
  %49 = add i64 %48, 1
  store i64 %49, ptr %9, align 8, !tbaa !9
  br label %32, !llvm.loop !13

50:                                               ; preds = %45, %36
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  %51 = load i32, ptr %10, align 4
  switch i32 %51, label %55 [
    i32 2, label %52
    i32 5, label %53
  ]

52:                                               ; preds = %50
  br label %53

53:                                               ; preds = %52, %50
  %54 = load i32, ptr %8, align 4, !tbaa !11
  store i32 %54, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %55

55:                                               ; preds = %53, %50
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %56 = load i32, ptr %3, align 4
  ret i32 %56
}

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

declare i32 @json_array_append_string(ptr noundef, ptr noundef) #2

declare zeroext i1 @oid_is_parent(ptr noundef, ptr noundef) #2

declare zeroext i1 @oid_is_equal(ptr noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { "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 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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

@OID_DSTU4145_WITH_GOST3411 = external local_unnamed_addr global ptr, align 8
@OID_DSTU4145_WITH_DSTU7564 = external local_unnamed_addr global ptr, align 8
@OID_EC_KEY = external local_unnamed_addr global ptr, align 8
@OID_RSA = external local_unnamed_addr global ptr, align 8
@_ZL14SIGN_ALGO_DSTU = external hidden local_unnamed_addr global [4 x ptr], align 16
@_ZL16SIGN_ALGOS_ECDSA = external hidden local_unnamed_addr global [6 x ptr], align 16
@_ZL14SIGN_ALGOS_RSA = external hidden local_unnamed_addr global [8 x ptr], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 1065) i32 @_ZN8CmPkcs1221signAlgoByMechanismIdEPKcP12json_array_t(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 align 2 {
  %3 = load ptr, ptr @OID_DSTU4145_WITH_DSTU7564, align 8, !tbaa !5
  %4 = tail call zeroext i1 @oid_is_parent(ptr noundef %3, ptr noundef %0)
  br i1 %4, label %.lr.ph.preheader, label %5

5:                                                ; preds = %2
  %6 = load ptr, ptr @OID_DSTU4145_WITH_GOST3411, align 8, !tbaa !5
  %7 = tail call zeroext i1 @oid_is_parent(ptr noundef %6, ptr noundef %0)
  br i1 %7, label %.lr.ph.preheader, label %8

8:                                                ; preds = %5
  %9 = load ptr, ptr @OID_EC_KEY, align 8, !tbaa !5
  %10 = tail call zeroext i1 @oid_is_equal(ptr noundef %9, ptr noundef %0)
  br i1 %10, label %.lr.ph.preheader, label %11

11:                                               ; preds = %8
  %12 = load ptr, ptr @OID_RSA, align 8, !tbaa !5
  %13 = tail call zeroext i1 @oid_is_equal(ptr noundef %12, ptr noundef %0)
  br i1 %13, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %11, %5, %2, %8
  %.015.ph = phi i64 [ 6, %8 ], [ 4, %2 ], [ 4, %5 ], [ 8, %11 ]
  %.014.ph = phi ptr [ @_ZL16SIGN_ALGOS_ECDSA, %8 ], [ @_ZL14SIGN_ALGO_DSTU, %2 ], [ @_ZL14SIGN_ALGO_DSTU, %5 ], [ @_ZL14SIGN_ALGOS_RSA, %11 ]
  br label %.lr.ph

14:                                               ; preds = %.lr.ph
  %15 = add nuw nsw i64 %.01218, 1
  %exitcond.not = icmp eq i64 %15, %.015.ph
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

.lr.ph:                                           ; preds = %.lr.ph.preheader, %14
  %.01218 = phi i64 [ %15, %14 ], [ 0, %.lr.ph.preheader ]
  %16 = getelementptr inbounds ptr, ptr %.014.ph, i64 %.01218
  %17 = load ptr, ptr %16, align 8, !tbaa !5
  %18 = tail call i32 @json_array_append_string(ptr noundef %1, ptr noundef %17)
  %.not = icmp eq i32 %18, 0
  br i1 %.not, label %14, label %._crit_edge

._crit_edge:                                      ; preds = %14, %.lr.ph, %11
  %.013 = phi i32 [ 0, %11 ], [ 1064, %.lr.ph ], [ 0, %14 ]
  ret i32 %.013
}

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

declare zeroext i1 @oid_is_parent(ptr noundef, ptr noundef) local_unnamed_addr #1

declare zeroext i1 @oid_is_equal(ptr noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { 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 #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" }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: ADCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass