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

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

%class.ParsonHelper = type { ptr, ptr }

@.str = external hidden unnamed_addr constant [6 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 i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN8CmPkcs1210parseBytesEPhPP12ByteArray_st(ptr noundef %0, ptr noundef %1) #1 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca %class.ParsonHelper, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %13, label %12

12:                                               ; preds = %2
  store i32 0, ptr %3, align 4
  br label %39

13:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #5
  call void @_ZN12ParsonHelperC1Ev(ptr noundef nonnull align 8 dereferenceable(16) %6)
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = invoke noundef ptr @_ZN12ParsonHelper5parseEPKcb(ptr noundef nonnull align 8 dereferenceable(16) %6, ptr noundef %14, i1 noundef zeroext false)
          to label %16 unwind label %19

16:                                               ; preds = %13
  %17 = icmp ne ptr %15, null
  br i1 %17, label %23, label %18

18:                                               ; preds = %16
  store i32 1056, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %38

19:                                               ; preds = %29, %27, %23, %13
  %20 = landingpad { ptr, i32 }
          cleanup
  %21 = extractvalue { ptr, i32 } %20, 0
  store ptr %21, ptr %7, align 8
  %22 = extractvalue { ptr, i32 } %20, 1
  store i32 %22, ptr %8, align 4
  call void @_ZN12ParsonHelperD1Ev(ptr noundef nonnull align 8 dereferenceable(16) %6) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #5
  br label %41

23:                                               ; preds = %16
  %24 = invoke noundef zeroext i1 @_ZN12ParsonHelper8hasValueEPKci(ptr noundef nonnull align 8 dereferenceable(16) %6, ptr noundef @.str, i32 noundef 2)
          to label %25 unwind label %19

25:                                               ; preds = %23
  br i1 %24, label %27, label %26

26:                                               ; preds = %25
  store i32 1026, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %38

27:                                               ; preds = %25
  %28 = invoke noundef ptr @_ZNK12ParsonHelper10rootObjectEv(ptr noundef nonnull align 8 dereferenceable(16) %6)
          to label %29 unwind label %19

29:                                               ; preds = %27
  %30 = invoke ptr @json_object_get_base64(ptr noundef %28, ptr noundef @.str)
          to label %31 unwind label %19

31:                                               ; preds = %29
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %30, ptr %32, align 8, !tbaa !5
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = load ptr, ptr %33, align 8, !tbaa !5
  %35 = icmp ne ptr %34, null
  %36 = zext i1 %35 to i64
  %37 = select i1 %35, i32 0, i32 1056
  store i32 %37, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %38

38:                                               ; preds = %31, %26, %18
  call void @_ZN12ParsonHelperD1Ev(ptr noundef nonnull align 8 dereferenceable(16) %6) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #5
  br label %39

39:                                               ; preds = %38, %12
  %40 = load i32, ptr %3, align 4
  ret i32 %40

41:                                               ; preds = %19
  %42 = load ptr, ptr %7, align 8
  %43 = load i32, ptr %8, align 4
  %44 = insertvalue { ptr, i32 } poison, ptr %42, 0
  %45 = insertvalue { ptr, i32 } %44, i32 %43, 1
  resume { ptr, i32 } %45
}

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

declare void @_ZN12ParsonHelperC1Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #2

declare noundef ptr @_ZN12ParsonHelper5parseEPKcb(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef, i1 noundef zeroext) #2

declare noundef zeroext i1 @_ZN12ParsonHelper8hasValueEPKci(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef, i32 noundef) #2

declare ptr @json_object_get_base64(ptr noundef, ptr noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK12ParsonHelper10rootObjectEv(ptr noundef nonnull align 8 dereferenceable(16)) #3 align 2

; Function Attrs: nounwind
declare void @_ZN12ParsonHelperD1Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #4

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 = { mustprogress 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 "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 #5 = { 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"}


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

%class.ParsonHelper = type { ptr, ptr }

@.str = external hidden unnamed_addr constant [6 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 i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 1057) i32 @_ZN8CmPkcs1210parseBytesEPhPP12ByteArray_st(ptr noundef %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca %class.ParsonHelper, align 8
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %18, label %4

4:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #5
  call void @_ZN12ParsonHelperC1Ev(ptr noundef nonnull align 8 dereferenceable(16) %3)
  %5 = invoke noundef ptr @_ZN12ParsonHelper5parseEPKcb(ptr noundef nonnull align 8 dereferenceable(16) %3, ptr noundef nonnull %0, i1 noundef zeroext false)
          to label %6 unwind label %7

6:                                                ; preds = %4
  %.not7 = icmp eq ptr %5, null
  br i1 %.not7, label %17, label %9

7:                                                ; preds = %12, %9, %4
  %8 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN12ParsonHelperD1Ev(ptr noundef nonnull align 8 dereferenceable(16) %3) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #5
  resume { ptr, i32 } %8

9:                                                ; preds = %6
  %10 = invoke noundef zeroext i1 @_ZN12ParsonHelper8hasValueEPKci(ptr noundef nonnull align 8 dereferenceable(16) %3, ptr noundef nonnull @.str, i32 noundef 2)
          to label %11 unwind label %7

11:                                               ; preds = %9
  br i1 %10, label %12, label %17

12:                                               ; preds = %11
  %13 = call noundef ptr @_ZNK12ParsonHelper10rootObjectEv(ptr noundef nonnull align 8 dereferenceable(16) %3)
  %14 = invoke ptr @json_object_get_base64(ptr noundef %13, ptr noundef nonnull @.str)
          to label %15 unwind label %7

15:                                               ; preds = %12
  store ptr %14, ptr %1, align 8, !tbaa !5
  %.not8 = icmp eq ptr %14, null
  %16 = select i1 %.not8, i32 1056, i32 0
  br label %17

17:                                               ; preds = %11, %6, %15
  %.0 = phi i32 [ %16, %15 ], [ 1056, %6 ], [ 1026, %11 ]
  call void @_ZN12ParsonHelperD1Ev(ptr noundef nonnull align 8 dereferenceable(16) %3) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #5
  br label %18

18:                                               ; preds = %2, %17
  %.1 = phi i32 [ %.0, %17 ], [ 0, %2 ]
  ret i32 %.1
}

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

declare void @_ZN12ParsonHelperC1Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #2

declare noundef ptr @_ZN12ParsonHelper5parseEPKcb(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef, i1 noundef zeroext) local_unnamed_addr #2

declare noundef zeroext i1 @_ZN12ParsonHelper8hasValueEPKci(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef, i32 noundef) local_unnamed_addr #2

declare ptr @json_object_get_base64(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK12ParsonHelper10rootObjectEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #3 align 2

; Function Attrs: nounwind
declare void @_ZN12ParsonHelperD1Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #4

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


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