; LLVM IR from specinfo-ua/UAPKI :: library/common/pkix/tsp-helper.ll (ZN7UapkiNS3Tsp9TspHelper10setCertReqEb)

; 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::Tsp::TspHelper" = type { ptr, ptr, ptr, ptr, i32, ptr }
%struct.TimeStampReq = type { %struct.ASN__PRIMITIVE_TYPE_s, %struct.MessageImprint, ptr, ptr, ptr, ptr, %struct.asn_struct_ctx_s }
%struct.ASN__PRIMITIVE_TYPE_s = type { ptr, i32 }
%struct.MessageImprint = type { %struct.AlgorithmIdentifier, %struct.OCTET_STRING, %struct.asn_struct_ctx_s }
%struct.AlgorithmIdentifier = type { %struct.ASN__PRIMITIVE_TYPE_s, ptr, %struct.asn_struct_ctx_s }
%struct.OCTET_STRING = type { ptr, i32, %struct.asn_struct_ctx_s }
%struct.asn_struct_ctx_s = type { i16, i16, i32, ptr, i64 }

@.str = external hidden unnamed_addr constant [27 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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7UapkiNS3Tsp9TspHelper10setCertReqEb(ptr noundef nonnull align 8 dereferenceable(48) %0, i1 noundef zeroext %1) #2 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  %9 = zext i1 %1 to i8
  store i8 %9, ptr %5, align 1, !tbaa !9
  %10 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 1, ptr %7, align 4, !tbaa !11
  %11 = getelementptr inbounds %"class.UapkiNS::Tsp::TspHelper", ptr %10, i32 0, i32 0
  %12 = load ptr, ptr %11, align 8, !tbaa !13
  %13 = icmp ne ptr %12, null
  br i1 %13, label %15, label %14

14:                                               ; preds = %2
  store i32 4101, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %34

15:                                               ; preds = %2
  %16 = load i8, ptr %5, align 1, !tbaa !9, !range !16, !noundef !17
  %17 = trunc i8 %16 to i1
  br i1 %17, label %18, label %31

18:                                               ; preds = %15
  br label %19

19:                                               ; preds = %18
  %20 = call ptr @get_BOOLEAN_desc()
  %21 = call ptr @asn_copy_with_alloc(ptr noundef %20, ptr noundef %7)
  %22 = getelementptr inbounds %"class.UapkiNS::Tsp::TspHelper", ptr %10, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !13
  %24 = getelementptr inbounds %struct.TimeStampReq, ptr %23, i32 0, i32 4
  store ptr %21, ptr %24, align 8, !tbaa !18
  %25 = icmp eq ptr null, %21
  br i1 %25, label %26, label %28

26:                                               ; preds = %19
  store i32 2, ptr %6, align 4, !tbaa !11
  %27 = load i32, ptr %6, align 4, !tbaa !11
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 120, i32 noundef %27)
  br label %32

28:                                               ; preds = %19
  br label %29

29:                                               ; preds = %28
  br label %30

30:                                               ; preds = %29
  br label %31

31:                                               ; preds = %30, %15
  br label %32

32:                                               ; preds = %31, %26
  %33 = load i32, ptr %6, align 4, !tbaa !11
  store i32 %33, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %34

34:                                               ; preds = %32, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %35 = load i32, ptr %3, align 4
  ret i32 %35
}

declare ptr @asn_copy_with_alloc(ptr noundef, ptr noundef) #1

declare ptr @get_BOOLEAN_desc() #1

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 = { 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 }

!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 = !{!"bool", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"_ZTSN7UapkiNS3Tsp9TspHelperE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !15, i64 32, !6, i64 40}
!15 = !{!"_ZTSN7UapkiNS3Tsp9PkiStatusE", !7, i64 0}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = !{!19, !6, i64 144}
!19 = !{!"_ZTS12TimeStampReq", !20, i64 0, !21, i64 16, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !23, i64 160}
!20 = !{!"_ZTS21ASN__PRIMITIVE_TYPE_s", !6, i64 0, !12, i64 8}
!21 = !{!"_ZTS14MessageImprint", !22, i64 0, !26, i64 48, !23, i64 88}
!22 = !{!"_ZTS19AlgorithmIdentifier", !20, i64 0, !6, i64 16, !23, i64 24}
!23 = !{!"_ZTS16asn_struct_ctx_s", !24, i64 0, !24, i64 2, !12, i64 4, !6, i64 8, !25, i64 16}
!24 = !{!"short", !7, i64 0}
!25 = !{!"long", !7, i64 0}
!26 = !{!"_ZTS12OCTET_STRING", !6, i64 0, !12, i64 8, !23, 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"

@.str = external hidden unnamed_addr constant [27 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 void @stacktrace_add(ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress 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 range(i32 0, 4102) i32 @_ZN7UapkiNS3Tsp9TspHelper10setCertReqEb(ptr nocapture noundef nonnull readonly align 8 dereferenceable(48) %0, i1 noundef zeroext %1) local_unnamed_addr #2 align 2 {
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  store i32 1, ptr %3, align 4, !tbaa !5
  %4 = load ptr, ptr %0, align 8, !tbaa !9
  %.not = icmp ne ptr %4, null
  %brmerge.not = and i1 %.not, %1
  %.mux = select i1 %.not, i32 0, i32 4101
  br i1 %brmerge.not, label %5, label %12

5:                                                ; preds = %2
  %6 = tail call ptr @get_BOOLEAN_desc()
  %7 = call ptr @asn_copy_with_alloc(ptr noundef %6, ptr noundef nonnull %3)
  %8 = load ptr, ptr %0, align 8, !tbaa !9
  %9 = getelementptr inbounds i8, ptr %8, i64 144
  store ptr %7, ptr %9, align 8, !tbaa !13
  %10 = icmp eq ptr %7, null
  br i1 %10, label %11, label %12

11:                                               ; preds = %5
  call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 120, i32 noundef 2)
  br label %12

12:                                               ; preds = %2, %11, %5
  %.04 = phi i32 [ %.mux, %2 ], [ 2, %11 ], [ 0, %5 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  ret i32 %.04
}

declare ptr @asn_copy_with_alloc(ptr noundef, ptr noundef) local_unnamed_addr #1

declare ptr @get_BOOLEAN_desc() local_unnamed_addr #1

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

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTSN7UapkiNS3Tsp9TspHelperE", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !12, i64 32, !11, i64 40}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"_ZTSN7UapkiNS3Tsp9PkiStatusE", !7, i64 0}
!13 = !{!14, !11, i64 144}
!14 = !{!"_ZTS12TimeStampReq", !15, i64 0, !16, i64 16, !11, i64 128, !11, i64 136, !11, i64 144, !11, i64 152, !18, i64 160}
!15 = !{!"_ZTS21ASN__PRIMITIVE_TYPE_s", !11, i64 0, !6, i64 8}
!16 = !{!"_ZTS14MessageImprint", !17, i64 0, !21, i64 48, !18, i64 88}
!17 = !{!"_ZTS19AlgorithmIdentifier", !15, i64 0, !11, i64 16, !18, i64 24}
!18 = !{!"_ZTS16asn_struct_ctx_s", !19, i64 0, !19, i64 2, !6, i64 4, !11, i64 8, !20, i64 16}
!19 = !{!"short", !7, i64 0}
!20 = !{!"long", !7, i64 0}
!21 = !{!"_ZTS12OCTET_STRING", !11, i64 0, !6, i64 8, !18, i64 16}


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