; LLVM IR from specinfo-ua/UAPKI :: library/uapki/src/ocsp-helper.ll (ZN7UapkiNS4Ocsp10OcspHelper19addNonceToExtensionEv)

; 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::Ocsp::OcspHelper" = type <{ %"class.std::vector", ptr, ptr, ptr, ptr, ptr, ptr, ptr, i64, i32, [4 x i8] }>
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<UapkiNS::Ocsp::OcspHelper::SingleResponseInfo, std::allocator<UapkiNS::Ocsp::OcspHelper::SingleResponseInfo>>::_Vector_impl" }
%"struct.std::_Vector_base<UapkiNS::Ocsp::OcspHelper::SingleResponseInfo, std::allocator<UapkiNS::Ocsp::OcspHelper::SingleResponseInfo>>::_Vector_impl" = type { %"struct.std::_Vector_base<UapkiNS::Ocsp::OcspHelper::SingleResponseInfo, std::allocator<UapkiNS::Ocsp::OcspHelper::SingleResponseInfo>>::_Vector_impl_data" }
%"struct.std::_Vector_base<UapkiNS::Ocsp::OcspHelper::SingleResponseInfo, std::allocator<UapkiNS::Ocsp::OcspHelper::SingleResponseInfo>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%struct.OCSPRequest = type { %struct.TBSRequest, ptr, %struct.asn_struct_ctx_s }
%struct.TBSRequest = type { ptr, ptr, %"struct.TBSRequest::requestList", ptr, %struct.asn_struct_ctx_s }
%"struct.TBSRequest::requestList" = type { %struct.anon, %struct.asn_struct_ctx_s }
%struct.anon = type { ptr, i32, i32, ptr }
%struct.asn_struct_ctx_s = type { i16, i16, i32, ptr, i64 }

@.str = external hidden unnamed_addr constant [22 x i8], align 1

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

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

declare void @stacktrace_create(ptr noundef, i64 noundef, i32 noundef, ptr noundef) #2

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7UapkiNS4Ocsp10OcspHelper19addNonceToExtensionEv(ptr noundef nonnull align 8 dereferenceable(92) %0) #3 align 2 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !9
  %8 = getelementptr inbounds %"class.UapkiNS::Ocsp::OcspHelper", ptr %7, i32 0, i32 1
  %9 = load ptr, ptr %8, align 8, !tbaa !11
  %10 = icmp ne ptr %9, null
  br i1 %10, label %11, label %15

11:                                               ; preds = %1
  %12 = getelementptr inbounds %"class.UapkiNS::Ocsp::OcspHelper", ptr %7, i32 0, i32 4
  %13 = load ptr, ptr %12, align 8, !tbaa !19
  %14 = icmp ne ptr %13, null
  br i1 %14, label %16, label %15

15:                                               ; preds = %11, %1
  store i32 4101, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %55

16:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %17 = getelementptr inbounds %"class.UapkiNS::Ocsp::OcspHelper", ptr %7, i32 0, i32 1
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  %19 = getelementptr inbounds %struct.OCSPRequest, ptr %18, i32 0, i32 0
  store ptr %19, ptr %6, align 8, !tbaa !5
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.TBSRequest, ptr %20, i32 0, i32 3
  %22 = load ptr, ptr %21, align 8, !tbaa !20
  %23 = icmp ne ptr %22, null
  br i1 %23, label %38, label %24

24:                                               ; preds = %16
  %25 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 48) #5
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.TBSRequest, ptr %26, i32 0, i32 3
  store ptr %25, ptr %27, align 8, !tbaa !20
  br label %28

28:                                               ; preds = %24
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.TBSRequest, ptr %29, i32 0, i32 3
  %31 = load ptr, ptr %30, align 8, !tbaa !20
  %32 = icmp eq ptr %31, null
  br i1 %32, label %33, label %35

33:                                               ; preds = %28
  store i32 1, ptr %4, align 4, !tbaa !9
  %34 = load i32, ptr %4, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 223, i32 noundef %34, ptr noundef null)
  br label %53

35:                                               ; preds = %28
  br label %36

36:                                               ; preds = %35
  br label %37

37:                                               ; preds = %36
  br label %38

38:                                               ; preds = %37, %16
  br label %39

39:                                               ; preds = %38
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.TBSRequest, ptr %40, i32 0, i32 3
  %42 = load ptr, ptr %41, align 8, !tbaa !20
  %43 = getelementptr inbounds %"class.UapkiNS::Ocsp::OcspHelper", ptr %7, i32 0, i32 4
  %44 = load ptr, ptr %43, align 8, !tbaa !19
  %45 = call noundef i32 @_ZN7UapkiNS15ExtensionHelper12addOcspNonceEP10ExtensionsPK12ByteArray_st(ptr noundef %42, ptr noundef %44)
  store i32 %45, ptr %4, align 4, !tbaa !9
  %46 = load i32, ptr %4, align 4, !tbaa !9
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %48, label %50

48:                                               ; preds = %39
  %49 = load i32, ptr %4, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 226, i32 noundef %49)
  br label %53

50:                                               ; preds = %39
  br label %51

51:                                               ; preds = %50
  br label %52

52:                                               ; preds = %51
  br label %53

53:                                               ; preds = %52, %48, %33
  %54 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %54, ptr %2, align 4
  store i32 1, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %55

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

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 24}
!12 = !{!"_ZTSN7UapkiNS4Ocsp10OcspHelperE", !13, i64 0, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !17, i64 80, !18, i64 88}
!13 = !{!"_ZTSSt6vectorIN7UapkiNS4Ocsp10OcspHelper18SingleResponseInfoESaIS3_EE", !14, i64 0}
!14 = !{!"_ZTSSt12_Vector_baseIN7UapkiNS4Ocsp10OcspHelper18SingleResponseInfoESaIS3_EE", !15, i64 0}
!15 = !{!"_ZTSNSt12_Vector_baseIN7UapkiNS4Ocsp10OcspHelper18SingleResponseInfoESaIS3_EE12_Vector_implE", !16, i64 0}
!16 = !{!"_ZTSNSt12_Vector_baseIN7UapkiNS4Ocsp10OcspHelper18SingleResponseInfoESaIS3_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!17 = !{!"long", !7, i64 0}
!18 = !{!"_ZTSN7UapkiNS4Ocsp14ResponseStatusE", !7, i64 0}
!19 = !{!12, !6, i64 48}
!20 = !{!21, !6, i64 64}
!21 = !{!"_ZTS10TBSRequest", !6, i64 0, !6, i64 8, !22, i64 16, !6, i64 64, !24, i64 72}
!22 = !{!"_ZTSN10TBSRequest11requestListE", !23, i64 0, !24, i64 24}
!23 = !{!"_ZTSN10TBSRequest11requestListUt_E", !6, i64 0, !10, i64 8, !10, i64 12, !6, i64 16}
!24 = !{!"_ZTS16asn_struct_ctx_s", !25, i64 0, !25, i64 2, !10, i64 4, !6, i64 8, !17, i64 16}
!25 = !{!"short", !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 [22 x i8], align 1

; 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 #0

declare void @stacktrace_create(ptr noundef, i64 noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7UapkiNS4Ocsp10OcspHelper19addNonceToExtensionEv(ptr nocapture noundef nonnull readonly align 8 dereferenceable(92) %0) local_unnamed_addr #2 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 24
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %18, label %4

4:                                                ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 48
  %6 = load ptr, ptr %5, align 8, !tbaa !16
  %.not12 = icmp eq ptr %6, null
  br i1 %.not12, label %18, label %7

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %3, i64 64
  %9 = load ptr, ptr %8, align 8, !tbaa !17
  %.not13 = icmp eq ptr %9, null
  br i1 %.not13, label %10, label %14

10:                                               ; preds = %7
  %11 = tail call noalias dereferenceable_or_null(48) ptr @calloc(i64 noundef 1, i64 noundef 48) #3
  store ptr %11, ptr %8, align 8, !tbaa !17
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %14

13:                                               ; preds = %10
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 223, i32 noundef 1, ptr noundef null)
  br label %18

14:                                               ; preds = %7, %10
  %15 = phi ptr [ %9, %7 ], [ %11, %10 ]
  %16 = tail call noundef i32 @_ZN7UapkiNS15ExtensionHelper12addOcspNonceEP10ExtensionsPK12ByteArray_st(ptr noundef nonnull %15, ptr noundef nonnull %6)
  %.not14 = icmp eq i32 %16, 0
  br i1 %.not14, label %18, label %17

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

18:                                               ; preds = %13, %17, %14, %1, %4
  %.0 = phi i32 [ 4101, %4 ], [ 4101, %1 ], [ %16, %17 ], [ 0, %14 ], [ 1, %13 ]
  ret i32 %.0
}

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

attributes #0 = { 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 #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 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, !11, i64 24}
!6 = !{!"_ZTSN7UapkiNS4Ocsp10OcspHelperE", !7, i64 0, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !14, i64 80, !15, i64 88}
!7 = !{!"_ZTSSt6vectorIN7UapkiNS4Ocsp10OcspHelper18SingleResponseInfoESaIS3_EE", !8, i64 0}
!8 = !{!"_ZTSSt12_Vector_baseIN7UapkiNS4Ocsp10OcspHelper18SingleResponseInfoESaIS3_EE", !9, i64 0}
!9 = !{!"_ZTSNSt12_Vector_baseIN7UapkiNS4Ocsp10OcspHelper18SingleResponseInfoESaIS3_EE12_Vector_implE", !10, i64 0}
!10 = !{!"_ZTSNSt12_Vector_baseIN7UapkiNS4Ocsp10OcspHelper18SingleResponseInfoESaIS3_EE17_Vector_impl_dataE", !11, i64 0, !11, i64 8, !11, i64 16}
!11 = !{!"any pointer", !12, i64 0}
!12 = !{!"omnipotent char", !13, i64 0}
!13 = !{!"Simple C++ TBAA"}
!14 = !{!"long", !12, i64 0}
!15 = !{!"_ZTSN7UapkiNS4Ocsp14ResponseStatusE", !12, i64 0}
!16 = !{!6, !11, i64 48}
!17 = !{!18, !11, i64 64}
!18 = !{!"_ZTS10TBSRequest", !11, i64 0, !11, i64 8, !19, i64 16, !11, i64 64, !22, i64 72}
!19 = !{!"_ZTSN10TBSRequest11requestListE", !20, i64 0, !22, i64 24}
!20 = !{!"_ZTSN10TBSRequest11requestListUt_E", !11, i64 0, !21, i64 8, !21, i64 12, !11, i64 16}
!21 = !{!"int", !12, i64 0}
!22 = !{!"_ZTS16asn_struct_ctx_s", !23, i64 0, !23, i64 2, !21, i64 4, !11, i64 8, !14, i64 16}
!23 = !{!"short", !12, i64 0}


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