; LLVM IR from specinfo-ua/UAPKI :: library/common/pkix (attribute-helper)

; 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.UapkiNS::AttributeHelper::AtsHashIndexBuilder" = type { ptr, ptr, ptr }
%struct.ATSHashIndexDefault = type { %struct.certificatesHashIndex, %struct.crlsHashIndex, %struct.unsignedAttrsHashIndex, %struct.asn_struct_ctx_s }
%struct.certificatesHashIndex = type { %struct.anon.19, %struct.asn_struct_ctx_s }
%struct.anon.19 = type { ptr, i32, i32, ptr }
%struct.crlsHashIndex = type { %struct.anon.20, %struct.asn_struct_ctx_s }
%struct.anon.20 = type { ptr, i32, i32, ptr }
%struct.unsignedAttrsHashIndex = type { %struct.anon.21, %struct.asn_struct_ctx_s }
%struct.anon.21 = type { ptr, i32, i32, ptr }
%struct.asn_struct_ctx_s = type { i16, i16, i32, ptr, i64 }
%struct.ATSHashIndexFull = type { %struct.AlgorithmIdentifier, %struct.certificatesHashIndex, %struct.crlsHashIndex, %struct.unsignedAttrsHashIndex, %struct.asn_struct_ctx_s }
%struct.AlgorithmIdentifier = type { %struct.ASN__PRIMITIVE_TYPE_s, ptr, %struct.asn_struct_ctx_s }
%struct.ASN__PRIMITIVE_TYPE_s = type { ptr, i32 }

@.str = external hidden unnamed_addr constant [33 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_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 void @asn_free(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #2

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

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

declare ptr @get_OCTET_STRING_desc() #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7UapkiNS15AttributeHelper19AtsHashIndexBuilder10addHashCrlEPK12ByteArray_st(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef %1) #3 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %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
  %11 = getelementptr inbounds %"class.UapkiNS::AttributeHelper::AtsHashIndexBuilder", ptr %10, i32 0, i32 0
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %13 = icmp ne ptr %12, null
  br i1 %13, label %19, label %14

14:                                               ; preds = %2
  %15 = getelementptr inbounds %"class.UapkiNS::AttributeHelper::AtsHashIndexBuilder", ptr %10, i32 0, i32 1
  %16 = load ptr, ptr %15, align 8, !tbaa !11
  %17 = icmp ne ptr %16, null
  br i1 %17, label %19, label %18

18:                                               ; preds = %14
  store i32 4101, ptr %3, align 4
  br label %66

19:                                               ; preds = %14, %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %20 = getelementptr inbounds %"class.UapkiNS::AttributeHelper::AtsHashIndexBuilder", ptr %10, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !9
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %27

23:                                               ; preds = %19
  %24 = getelementptr inbounds %"class.UapkiNS::AttributeHelper::AtsHashIndexBuilder", ptr %10, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !9
  %26 = getelementptr inbounds %struct.ATSHashIndexDefault, ptr %25, i32 0, i32 1
  br label %31

27:                                               ; preds = %19
  %28 = getelementptr inbounds %"class.UapkiNS::AttributeHelper::AtsHashIndexBuilder", ptr %10, i32 0, i32 1
  %29 = load ptr, ptr %28, align 8, !tbaa !11
  %30 = getelementptr inbounds %struct.ATSHashIndexFull, ptr %29, i32 0, i32 2
  br label %31

31:                                               ; preds = %27, %23
  %32 = phi ptr [ %26, %23 ], [ %30, %27 ]
  store ptr %32, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %33 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 40) #5
  store ptr %33, ptr %8, align 8, !tbaa !5
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = icmp ne ptr %34, null
  br i1 %35, label %37, label %36

36:                                               ; preds = %31
  store i32 4097, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %65

37:                                               ; preds = %31
  br label %38

38:                                               ; preds = %37
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = call i32 @asn_ba2OCTSTRING(ptr noundef %39, ptr noundef %40)
  store i32 %41, ptr %6, align 4, !tbaa !12
  %42 = load i32, ptr %6, align 4, !tbaa !12
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %44, label %46

44:                                               ; preds = %38
  %45 = load i32, ptr %6, align 4, !tbaa !12
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 522, i32 noundef %45)
  br label %61

46:                                               ; preds = %38
  br label %47

47:                                               ; preds = %46
  br label %48

48:                                               ; preds = %47
  br label %49

49:                                               ; preds = %48
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.crlsHashIndex, ptr %50, i32 0, i32 0
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = call i32 @asn_set_add(ptr noundef %51, ptr noundef %52)
  store i32 %53, ptr %6, align 4, !tbaa !12
  %54 = load i32, ptr %6, align 4, !tbaa !12
  %55 = icmp ne i32 %54, 0
  br i1 %55, label %56, label %58

56:                                               ; preds = %49
  %57 = load i32, ptr %6, align 4, !tbaa !12
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 523, i32 noundef %57)
  br label %61

58:                                               ; preds = %49
  br label %59

59:                                               ; preds = %58
  br label %60

60:                                               ; preds = %59
  store ptr null, ptr %8, align 8, !tbaa !5
  br label %61

61:                                               ; preds = %60, %56, %44
  %62 = call ptr @get_OCTET_STRING_desc()
  %63 = load ptr, ptr %8, align 8, !tbaa !5
  call void @asn_free(ptr noundef %62, ptr noundef %63)
  %64 = load i32, ptr %6, align 4, !tbaa !12
  store i32 %64, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %65

65:                                               ; preds = %61, %36
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %66

66:                                               ; preds = %65, %18
  %67 = load i32, ptr %3, align 4
  ret i32 %67
}

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 allocsize(0,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 #3 = { 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 #4 = { nounwind }
attributes #5 = { nounwind allocsize(0,1) }

!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, !6, i64 0}
!10 = !{!"_ZTSN7UapkiNS15AttributeHelper19AtsHashIndexBuilderE", !6, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!10, !6, i64 8}
!12 = !{!13, !13, i64 0}
!13 = !{!"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 [33 x i8], align 1

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

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

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #1

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

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

declare ptr @get_OCTET_STRING_desc() local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7UapkiNS15AttributeHelper19AtsHashIndexBuilder10addHashCrlEPK12ByteArray_st(ptr nocapture noundef nonnull readonly align 8 dereferenceable(24) %0, ptr noundef %1) local_unnamed_addr #2 align 2 {
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %.not = icmp eq ptr %3, null
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load ptr, ptr %4, align 8
  %.not19 = icmp eq ptr %5, null
  %or.cond = select i1 %.not, i1 %.not19, i1 false
  br i1 %or.cond, label %19, label %6

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %3, i64 48
  %8 = getelementptr inbounds i8, ptr %5, i64 96
  %9 = select i1 %.not, ptr %8, ptr %7
  %10 = tail call noalias dereferenceable_or_null(40) ptr @calloc(i64 noundef 1, i64 noundef 40) #3
  %.not21 = icmp eq ptr %10, null
  br i1 %.not21, label %19, label %11

11:                                               ; preds = %6
  %12 = tail call i32 @asn_ba2OCTSTRING(ptr noundef %1, ptr noundef nonnull %10)
  %.not22 = icmp eq i32 %12, 0
  br i1 %.not22, label %14, label %13

13:                                               ; preds = %11
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 522, i32 noundef %12)
  br label %17

14:                                               ; preds = %11
  %15 = tail call i32 @asn_set_add(ptr noundef nonnull %9, ptr noundef nonnull %10)
  %.not23 = icmp eq i32 %15, 0
  br i1 %.not23, label %17, label %16

16:                                               ; preds = %14
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 523, i32 noundef %15)
  br label %17

17:                                               ; preds = %14, %16, %13
  %.013 = phi i32 [ %12, %13 ], [ %15, %16 ], [ 0, %14 ]
  %.0 = phi ptr [ %10, %13 ], [ %10, %16 ], [ null, %14 ]
  %18 = tail call ptr @get_OCTET_STRING_desc()
  tail call void @asn_free(ptr noundef %18, ptr noundef %.0)
  br label %19

19:                                               ; preds = %17, %6, %2
  %.1 = phi i32 [ 4101, %2 ], [ %.013, %17 ], [ 4097, %6 ]
  ret i32 %.1
}

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 = { mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(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 #2 = { 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 #3 = { nounwind allocsize(0,1) }

!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, !7, i64 0}
!6 = !{!"_ZTSN7UapkiNS15AttributeHelper19AtsHashIndexBuilderE", !7, i64 0, !7, i64 8, !7, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}


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