; LLVM IR from specinfo-ua/UAPKI :: library/common/pkix/certreq-builder.ll (ZN7UapkiNS14CertReqBuilder4initEj)

; 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::CertReqBuilder" = type { ptr, %"class.std::__cxx11::basic_string", ptr, ptr }
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }
%struct.CertificationRequestInfo = type { %struct.ASN__PRIMITIVE_TYPE_s, %struct.Name, %struct.SubjectPublicKeyInfo, %struct.Attributes, %struct.asn_struct_ctx_s }
%struct.ASN__PRIMITIVE_TYPE_s = type { ptr, i32 }
%struct.Name = type { i32, %"union.Name::Name_u", %struct.asn_struct_ctx_s }
%"union.Name::Name_u" = type { %struct.RDNSequence }
%struct.RDNSequence = type { %struct.anon, %struct.asn_struct_ctx_s }
%struct.anon = type { ptr, i32, i32, ptr }
%struct.SubjectPublicKeyInfo = type { %struct.AlgorithmIdentifier, %struct.BIT_STRING_s, %struct.asn_struct_ctx_s }
%struct.AlgorithmIdentifier = type { %struct.ASN__PRIMITIVE_TYPE_s, ptr, %struct.asn_struct_ctx_s }
%struct.BIT_STRING_s = type { ptr, i32, i32, %struct.asn_struct_ctx_s }
%struct.Attributes = type { %struct.anon.0, %struct.asn_struct_ctx_s }
%struct.anon.0 = type { ptr, i32, i32, ptr }
%struct.asn_struct_ctx_s = type { i16, i16, i32, ptr, i64 }

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7UapkiNS14CertReqBuilder4initEj(ptr noundef nonnull align 8 dereferenceable(56) %0, i32 noundef %1) #0 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %7 = load ptr, ptr %4, align 8
  %8 = load i32, ptr %5, align 4, !tbaa !9
  %9 = icmp ult i32 %8, 1
  br i1 %9, label %10, label %11

10:                                               ; preds = %2
  store i32 4101, ptr %3, align 4
  br label %31

11:                                               ; preds = %2
  %12 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 280) #4
  %13 = getelementptr inbounds %"class.UapkiNS::CertReqBuilder", ptr %7, i32 0, i32 0
  store ptr %12, ptr %13, align 8, !tbaa !11
  %14 = getelementptr inbounds %"class.UapkiNS::CertReqBuilder", ptr %7, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  %16 = icmp ne ptr %15, null
  br i1 %16, label %18, label %17

17:                                               ; preds = %11
  store i32 4097, ptr %3, align 4
  br label %31

18:                                               ; preds = %11
  %19 = getelementptr inbounds %"class.UapkiNS::CertReqBuilder", ptr %7, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !11
  %21 = getelementptr inbounds %struct.CertificationRequestInfo, ptr %20, i32 0, i32 1
  %22 = getelementptr inbounds %struct.Name, ptr %21, i32 0, i32 0
  store i32 1, ptr %22, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %23 = getelementptr inbounds %"class.UapkiNS::CertReqBuilder", ptr %7, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8, !tbaa !11
  %25 = getelementptr inbounds %struct.CertificationRequestInfo, ptr %24, i32 0, i32 0
  %26 = load i32, ptr %5, align 4, !tbaa !9
  %27 = zext i32 %26 to i64
  %28 = sub i64 %27, 1
  %29 = call i32 @asn_ulong2INTEGER(ptr noundef %25, i64 noundef %28)
  store i32 %29, ptr %6, align 4, !tbaa !9
  %30 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %30, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %31

31:                                               ; preds = %18, %17, %10
  %32 = load i32, ptr %3, align 4
  ret i32 %32
}

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

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

declare i32 @asn_ulong2INTEGER(ptr noundef, i64 noundef) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 allocsize(0,1) }
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"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTSN7UapkiNS14CertReqBuilderE", !6, i64 0, !13, i64 8, !6, i64 40, !6, i64 48}
!13 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !14, i64 0, !15, i64 8, !7, i64 16}
!14 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!17, !20, i64 16}
!17 = !{!"_ZTS24CertificationRequestInfo", !18, i64 0, !19, i64 16, !23, i64 96, !26, i64 208, !21, i64 256}
!18 = !{!"_ZTS21ASN__PRIMITIVE_TYPE_s", !6, i64 0, !10, i64 8}
!19 = !{!"_ZTS4Name", !20, i64 0, !7, i64 8, !21, i64 56}
!20 = !{!"_ZTS7Name_PR", !7, i64 0}
!21 = !{!"_ZTS16asn_struct_ctx_s", !22, i64 0, !22, i64 2, !10, i64 4, !6, i64 8, !15, i64 16}
!22 = !{!"short", !7, i64 0}
!23 = !{!"_ZTS20SubjectPublicKeyInfo", !24, i64 0, !25, i64 48, !21, i64 88}
!24 = !{!"_ZTS19AlgorithmIdentifier", !18, i64 0, !6, i64 16, !21, i64 24}
!25 = !{!"_ZTS12BIT_STRING_s", !6, i64 0, !10, i64 8, !10, i64 12, !21, i64 16}
!26 = !{!"_ZTS10Attributes", !27, i64 0, !21, i64 24}
!27 = !{!"_ZTSN10AttributesUt_E", !6, i64 0, !10, i64 8, !10, i64 12, !6, i64 16}


; 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 @_ZN7UapkiNS14CertReqBuilder4initEj(ptr nocapture noundef nonnull writeonly align 8 dereferenceable(56) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = icmp eq i32 %1, 0
  br i1 %3, label %11, label %4

4:                                                ; preds = %2
  %5 = tail call noalias dereferenceable_or_null(280) ptr @calloc(i64 noundef 1, i64 noundef 280) #3
  store ptr %5, ptr %0, align 8, !tbaa !5
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %11, label %6

6:                                                ; preds = %4
  %7 = getelementptr inbounds i8, ptr %5, i64 16
  store i32 1, ptr %7, align 8, !tbaa !13
  %8 = zext i32 %1 to i64
  %9 = add nsw i64 %8, -1
  %10 = tail call i32 @asn_ulong2INTEGER(ptr noundef nonnull %5, i64 noundef %9)
  br label %11

11:                                               ; preds = %4, %2, %6
  %.0 = phi i32 [ %10, %6 ], [ 4101, %2 ], [ 4097, %4 ]
  ret i32 %.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_ulong2INTEGER(ptr noundef, i64 noundef) local_unnamed_addr #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 = { 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 = { "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 = !{!"_ZTSN7UapkiNS14CertReqBuilderE", !7, i64 0, !10, i64 8, !7, i64 40, !7, i64 48}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !11, i64 0, !12, i64 8, !8, i64 16}
!11 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !7, i64 0}
!12 = !{!"long", !8, i64 0}
!13 = !{!14, !18, i64 16}
!14 = !{!"_ZTS24CertificationRequestInfo", !15, i64 0, !17, i64 16, !21, i64 96, !24, i64 208, !19, i64 256}
!15 = !{!"_ZTS21ASN__PRIMITIVE_TYPE_s", !7, i64 0, !16, i64 8}
!16 = !{!"int", !8, i64 0}
!17 = !{!"_ZTS4Name", !18, i64 0, !8, i64 8, !19, i64 56}
!18 = !{!"_ZTS7Name_PR", !8, i64 0}
!19 = !{!"_ZTS16asn_struct_ctx_s", !20, i64 0, !20, i64 2, !16, i64 4, !7, i64 8, !12, i64 16}
!20 = !{!"short", !8, i64 0}
!21 = !{!"_ZTS20SubjectPublicKeyInfo", !22, i64 0, !23, i64 48, !19, i64 88}
!22 = !{!"_ZTS19AlgorithmIdentifier", !15, i64 0, !7, i64 16, !19, i64 24}
!23 = !{!"_ZTS12BIT_STRING_s", !7, i64 0, !16, i64 8, !16, i64 12, !19, i64 16}
!24 = !{!"_ZTS10Attributes", !25, i64 0, !19, i64 24}
!25 = !{!"_ZTSN10AttributesUt_E", !7, i64 0, !16, i64 8, !16, i64 12, !7, i64 16}


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