; LLVM IR from specinfo-ua/UAPKI :: library/cm-pkcs12/src/storage/file-storage.ll (ZN11FileStorage6decodeEPKc)

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN11FileStorage6decodeEPKc(ptr noundef nonnull align 8 dereferenceable(152) %0, ptr noundef %1) #1 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = call noundef i32 @_ZN11FileStorage12decodePkcs12EPKc(ptr noundef nonnull align 8 dereferenceable(152) %9, ptr noundef %10)
  store i32 %11, ptr %6, align 4, !tbaa !9
  %12 = load i32, ptr %6, align 4, !tbaa !9
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %15

14:                                               ; preds = %2
  br label %52

15:                                               ; preds = %2
  %16 = load i32, ptr %6, align 4, !tbaa !9
  %17 = icmp eq i32 %16, 1034
  br i1 %17, label %18, label %20

18:                                               ; preds = %15
  %19 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %19, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %59

20:                                               ; preds = %15
  %21 = load i32, ptr %6, align 4, !tbaa !9
  %22 = icmp eq i32 %21, 1035
  br i1 %22, label %23, label %35

23:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = call ptr @utf8_to_cp1251(ptr noundef %24)
  store ptr %25, ptr %8, align 8, !tbaa !5
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = call noundef i32 @_ZN11FileStorage12decodePkcs12EPKc(ptr noundef nonnull align 8 dereferenceable(152) %9, ptr noundef %26)
  store i32 %27, ptr %6, align 4, !tbaa !9
  %28 = load i32, ptr %6, align 4, !tbaa !9
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %30, label %32

30:                                               ; preds = %23
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  call void @_ZN11FileStorage7setOpenEPKc(ptr noundef nonnull align 8 dereferenceable(152) %9, ptr noundef %31)
  br label %32

32:                                               ; preds = %30, %23
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  call void @free(ptr noundef %33) #4
  %34 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %34, ptr %3, align 4
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %59

35:                                               ; preds = %20
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = call noundef i32 @_ZN11FileStorage9decodeJksEPKc(ptr noundef nonnull align 8 dereferenceable(152) %9, ptr noundef %36)
  store i32 %37, ptr %6, align 4, !tbaa !9
  %38 = load i32, ptr %6, align 4, !tbaa !9
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %43

40:                                               ; preds = %35
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = call noundef i32 @_ZN11FileStorage9decodeIitEPKc(ptr noundef nonnull align 8 dereferenceable(152) %9, ptr noundef %41)
  store i32 %42, ptr %6, align 4, !tbaa !9
  br label %43

43:                                               ; preds = %40, %35
  %44 = load i32, ptr %6, align 4, !tbaa !9
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %46, label %49

46:                                               ; preds = %43
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = call noundef i32 @_ZN11FileStorage12decodePkcs8eEPKc(ptr noundef nonnull align 8 dereferenceable(152) %9, ptr noundef %47)
  store i32 %48, ptr %6, align 4, !tbaa !9
  br label %49

49:                                               ; preds = %46, %43
  br label %50

50:                                               ; preds = %49
  br label %51

51:                                               ; preds = %50
  br label %52

52:                                               ; preds = %51, %14
  %53 = load i32, ptr %6, align 4, !tbaa !9
  %54 = icmp eq i32 %53, 0
  br i1 %54, label %55, label %57

55:                                               ; preds = %52
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_ZN11FileStorage7setOpenEPKc(ptr noundef nonnull align 8 dereferenceable(152) %9, ptr noundef %56)
  br label %57

57:                                               ; preds = %55, %52
  %58 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %58, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %59

59:                                               ; preds = %57, %32, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %60 = load i32, ptr %3, align 4
  ret i32 %60
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN11FileStorage12decodePkcs12EPKc(ptr noundef nonnull align 8 dereferenceable(152), ptr noundef) #1 align 2

declare ptr @utf8_to_cp1251(ptr noundef) #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN11FileStorage7setOpenEPKc(ptr noundef nonnull align 8 dereferenceable(152), ptr noundef) #1 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN11FileStorage9decodeJksEPKc(ptr noundef nonnull align 8 dereferenceable(152), ptr noundef) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN11FileStorage9decodeIitEPKc(ptr noundef nonnull align 8 dereferenceable(152), ptr noundef) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN11FileStorage12decodePkcs8eEPKc(ptr noundef nonnull align 8 dereferenceable(152), ptr noundef) #1 align 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 "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++ 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"

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN11FileStorage6decodeEPKc(ptr noundef nonnull align 8 dereferenceable(152) %0, ptr noundef %1) local_unnamed_addr #0 align 2 {
  %3 = tail call noundef i32 @_ZN11FileStorage12decodePkcs12EPKc(ptr noundef nonnull align 8 dereferenceable(152) %0, ptr noundef %1)
  switch i32 %3, label %10 [
    i32 0, label %.critedge.thread
    i32 1034, label %17
    i32 1035, label %4
  ]

4:                                                ; preds = %2
  %5 = tail call ptr @utf8_to_cp1251(ptr noundef %1)
  %6 = tail call noundef i32 @_ZN11FileStorage12decodePkcs12EPKc(ptr noundef nonnull align 8 dereferenceable(152) %0, ptr noundef %5)
  %7 = icmp eq i32 %6, 0
  br i1 %7, label %8, label %9

8:                                                ; preds = %4
  tail call void @_ZN11FileStorage7setOpenEPKc(ptr noundef nonnull align 8 dereferenceable(152) %0, ptr noundef %5)
  br label %9

9:                                                ; preds = %8, %4
  tail call void @free(ptr noundef %5) #3
  br label %17

10:                                               ; preds = %2
  %11 = tail call noundef i32 @_ZN11FileStorage9decodeJksEPKc(ptr noundef nonnull align 8 dereferenceable(152) %0, ptr noundef %1)
  %.not = icmp eq i32 %11, 0
  br i1 %.not, label %.critedge.thread, label %12

12:                                               ; preds = %10
  %13 = tail call noundef i32 @_ZN11FileStorage9decodeIitEPKc(ptr noundef nonnull align 8 dereferenceable(152) %0, ptr noundef %1)
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %.critedge.thread, label %.critedge

.critedge:                                        ; preds = %12
  %15 = tail call noundef i32 @_ZN11FileStorage12decodePkcs8eEPKc(ptr noundef nonnull align 8 dereferenceable(152) %0, ptr noundef %1)
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %.critedge.thread, label %17

.critedge.thread:                                 ; preds = %10, %12, %2, %.critedge
  tail call void @_ZN11FileStorage7setOpenEPKc(ptr noundef nonnull align 8 dereferenceable(152) %0, ptr noundef %1)
  br label %17

17:                                               ; preds = %.critedge, %.critedge.thread, %2, %9
  %.0 = phi i32 [ %6, %9 ], [ %3, %2 ], [ 0, %.critedge.thread ], [ %15, %.critedge ]
  ret i32 %.0
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN11FileStorage12decodePkcs12EPKc(ptr noundef nonnull align 8 dereferenceable(152), ptr noundef) local_unnamed_addr #0 align 2

declare ptr @utf8_to_cp1251(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN11FileStorage7setOpenEPKc(ptr noundef nonnull align 8 dereferenceable(152), ptr noundef) local_unnamed_addr #0 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN11FileStorage9decodeJksEPKc(ptr noundef nonnull align 8 dereferenceable(152), ptr noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN11FileStorage9decodeIitEPKc(ptr noundef nonnull align 8 dereferenceable(152), ptr noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN11FileStorage12decodePkcs8eEPKc(ptr noundef nonnull align 8 dereferenceable(152), ptr noundef) local_unnamed_addr #0 align 2

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

!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)"}


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