; LLVM IR from specinfo-ua/UAPKI :: library/common/pkix/tsp-helper.ll (ZN7UapkiNS3Tsp9TspHelper8setNonceEPK12ByteArray_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.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: 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_add(ptr noundef, i64 noundef, i32 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7UapkiNS3Tsp9TspHelper8setNonceEPK12ByteArray_st(ptr noundef nonnull align 8 dereferenceable(48) %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 i64, align 8
  %8 = alloca i8, align 1
  %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
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = call i64 @ba_get_len(ptr noundef %11)
  store i64 %12, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #4
  store i8 0, ptr %8, align 1, !tbaa !13
  %13 = getelementptr inbounds %"class.UapkiNS::Tsp::TspHelper", ptr %10, i32 0, i32 0
  %14 = load ptr, ptr %13, align 8, !tbaa !14
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %22

16:                                               ; preds = %2
  %17 = load i64, ptr %7, align 8, !tbaa !11
  %18 = icmp ult i64 %17, 4
  br i1 %18, label %22, label %19

19:                                               ; preds = %16
  %20 = load i64, ptr %7, align 8, !tbaa !11
  %21 = icmp ugt i64 %20, 32
  br i1 %21, label %22, label %23

22:                                               ; preds = %19, %16, %2
  store i32 4101, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %92

23:                                               ; preds = %19
  br label %24

24:                                               ; preds = %23
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = call ptr @ba_copy_with_alloc(ptr noundef %25, i64 noundef 0, i64 noundef 0)
  %27 = getelementptr inbounds %"class.UapkiNS::Tsp::TspHelper", ptr %10, i32 0, i32 2
  store ptr %26, ptr %27, align 8, !tbaa !17
  %28 = icmp eq ptr null, %26
  br i1 %28, label %29, label %31

29:                                               ; preds = %24
  store i32 2, ptr %6, align 4, !tbaa !9
  %30 = load i32, ptr %6, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 157, i32 noundef %30)
  br label %90

31:                                               ; preds = %24
  br label %32

32:                                               ; preds = %31
  br label %33

33:                                               ; preds = %32
  br label %34

34:                                               ; preds = %33
  %35 = getelementptr inbounds %"class.UapkiNS::Tsp::TspHelper", ptr %10, i32 0, i32 2
  %36 = load ptr, ptr %35, align 8, !tbaa !17
  %37 = call i32 @ba_get_byte(ptr noundef %36, i64 noundef 0, ptr noundef %8)
  store i32 %37, ptr %6, align 4, !tbaa !9
  %38 = load i32, ptr %6, align 4, !tbaa !9
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %42

40:                                               ; preds = %34
  %41 = load i32, ptr %6, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 158, i32 noundef %41)
  br label %90

42:                                               ; preds = %34
  br label %43

43:                                               ; preds = %42
  br label %44

44:                                               ; preds = %43
  br label %45

45:                                               ; preds = %44
  %46 = getelementptr inbounds %"class.UapkiNS::Tsp::TspHelper", ptr %10, i32 0, i32 2
  %47 = load ptr, ptr %46, align 8, !tbaa !17
  %48 = load i8, ptr %8, align 1, !tbaa !13
  %49 = zext i8 %48 to i32
  %50 = and i32 %49, 127
  %51 = trunc i32 %50 to i8
  %52 = call i32 @ba_set_byte(ptr noundef %47, i64 noundef 0, i8 noundef zeroext %51)
  store i32 %52, ptr %6, align 4, !tbaa !9
  %53 = load i32, ptr %6, align 4, !tbaa !9
  %54 = icmp ne i32 %53, 0
  br i1 %54, label %55, label %57

55:                                               ; preds = %45
  %56 = load i32, ptr %6, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 159, i32 noundef %56)
  br label %90

57:                                               ; preds = %45
  br label %58

58:                                               ; preds = %57
  br label %59

59:                                               ; preds = %58
  %60 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 16) #5
  %61 = getelementptr inbounds %"class.UapkiNS::Tsp::TspHelper", ptr %10, i32 0, i32 0
  %62 = load ptr, ptr %61, align 8, !tbaa !14
  %63 = getelementptr inbounds %struct.TimeStampReq, ptr %62, i32 0, i32 3
  store ptr %60, ptr %63, align 8, !tbaa !18
  br label %64

64:                                               ; preds = %59
  %65 = getelementptr inbounds %"class.UapkiNS::Tsp::TspHelper", ptr %10, i32 0, i32 0
  %66 = load ptr, ptr %65, align 8, !tbaa !14
  %67 = getelementptr inbounds %struct.TimeStampReq, ptr %66, i32 0, i32 3
  %68 = load ptr, ptr %67, align 8, !tbaa !18
  %69 = icmp eq ptr %68, null
  br i1 %69, label %70, label %72

70:                                               ; preds = %64
  store i32 1, ptr %6, align 4, !tbaa !9
  %71 = load i32, ptr %6, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 161, i32 noundef %71, ptr noundef null)
  br label %90

72:                                               ; preds = %64
  br label %73

73:                                               ; preds = %72
  br label %74

74:                                               ; preds = %73
  br label %75

75:                                               ; preds = %74
  %76 = getelementptr inbounds %"class.UapkiNS::Tsp::TspHelper", ptr %10, i32 0, i32 2
  %77 = load ptr, ptr %76, align 8, !tbaa !17
  %78 = getelementptr inbounds %"class.UapkiNS::Tsp::TspHelper", ptr %10, i32 0, i32 0
  %79 = load ptr, ptr %78, align 8, !tbaa !14
  %80 = getelementptr inbounds %struct.TimeStampReq, ptr %79, i32 0, i32 3
  %81 = load ptr, ptr %80, align 8, !tbaa !18
  %82 = call i32 @asn_ba2INTEGER(ptr noundef %77, ptr noundef %81)
  store i32 %82, ptr %6, align 4, !tbaa !9
  %83 = load i32, ptr %6, align 4, !tbaa !9
  %84 = icmp ne i32 %83, 0
  br i1 %84, label %85, label %87

85:                                               ; preds = %75
  %86 = load i32, ptr %6, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 162, i32 noundef %86)
  br label %90

87:                                               ; preds = %75
  br label %88

88:                                               ; preds = %87
  br label %89

89:                                               ; preds = %88
  br label %90

90:                                               ; preds = %89, %85, %70, %55, %40, %29
  %91 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %91, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %92

92:                                               ; preds = %90, %22
  call void @llvm.lifetime.end.p0(i64 1, 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
  %93 = load i32, ptr %3, align 4
  ret i32 %93
}

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

declare i64 @ba_get_len(ptr noundef) #2

declare ptr @ba_copy_with_alloc(ptr noundef, i64 noundef, i64 noundef) #2

declare i32 @ba_get_byte(ptr noundef, i64 noundef, ptr noundef) #2

declare i32 @ba_set_byte(ptr noundef, i64 noundef, i8 noundef zeroext) #2

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

declare i32 @asn_ba2INTEGER(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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !6, i64 0}
!15 = !{!"_ZTSN7UapkiNS3Tsp9TspHelperE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !16, i64 32, !6, i64 40}
!16 = !{!"_ZTSN7UapkiNS3Tsp9PkiStatusE", !7, i64 0}
!17 = !{!15, !6, i64 16}
!18 = !{!19, !6, i64 136}
!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, !10, i64 8}
!21 = !{!"_ZTS14MessageImprint", !22, i64 0, !25, 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, !10, i64 4, !6, i64 8, !12, i64 16}
!24 = !{!"short", !7, i64 0}
!25 = !{!"_ZTS12OCTET_STRING", !6, i64 0, !10, 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 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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7UapkiNS3Tsp9TspHelper8setNonceEPK12ByteArray_st(ptr nocapture noundef nonnull align 8 dereferenceable(48) %0, ptr noundef %1) local_unnamed_addr #3 align 2 {
  %3 = alloca i8, align 1
  %4 = tail call i64 @ba_get_len(ptr noundef %1)
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %3) #4
  store i8 0, ptr %3, align 1, !tbaa !5
  %5 = load ptr, ptr %0, align 8, !tbaa !8
  %6 = icmp eq ptr %5, null
  %7 = add i64 %4, -33
  %8 = icmp ult i64 %7, -29
  %or.cond3 = select i1 %6, i1 true, i1 %8
  br i1 %or.cond3, label %33, label %9

9:                                                ; preds = %2
  %10 = tail call ptr @ba_copy_with_alloc(ptr noundef %1, i64 noundef 0, i64 noundef 0)
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %10, ptr %11, align 8, !tbaa !12
  %12 = icmp eq ptr %10, null
  br i1 %12, label %13, label %14

13:                                               ; preds = %9
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 157, i32 noundef 2)
  br label %33

14:                                               ; preds = %9
  %15 = call i32 @ba_get_byte(ptr noundef nonnull %10, i64 noundef 0, ptr noundef nonnull %3)
  %.not = icmp eq i32 %15, 0
  br i1 %.not, label %17, label %16

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

17:                                               ; preds = %14
  %18 = load ptr, ptr %11, align 8, !tbaa !12
  %19 = load i8, ptr %3, align 1, !tbaa !5
  %20 = and i8 %19, 127
  %21 = call i32 @ba_set_byte(ptr noundef %18, i64 noundef 0, i8 noundef zeroext %20)
  %.not23 = icmp eq i32 %21, 0
  br i1 %.not23, label %23, label %22

22:                                               ; preds = %17
  call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 159, i32 noundef %21)
  br label %33

23:                                               ; preds = %17
  %24 = call noalias dereferenceable_or_null(16) ptr @calloc(i64 noundef 1, i64 noundef 16) #5
  %25 = load ptr, ptr %0, align 8, !tbaa !8
  %26 = getelementptr inbounds i8, ptr %25, i64 136
  store ptr %24, ptr %26, align 8, !tbaa !13
  %27 = icmp eq ptr %24, null
  br i1 %27, label %28, label %29

28:                                               ; preds = %23
  call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 161, i32 noundef 1, ptr noundef null)
  br label %33

29:                                               ; preds = %23
  %30 = load ptr, ptr %11, align 8, !tbaa !12
  %31 = call i32 @asn_ba2INTEGER(ptr noundef %30, ptr noundef nonnull %24)
  %.not24 = icmp eq i32 %31, 0
  br i1 %.not24, label %33, label %32

32:                                               ; preds = %29
  call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 162, i32 noundef %31)
  br label %33

33:                                               ; preds = %13, %16, %22, %28, %32, %29, %2
  %.0 = phi i32 [ 4101, %2 ], [ 2, %13 ], [ %15, %16 ], [ %21, %22 ], [ 1, %28 ], [ %31, %32 ], [ 0, %29 ]
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %3) #4
  ret i32 %.0
}

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

declare i64 @ba_get_len(ptr noundef) local_unnamed_addr #2

declare ptr @ba_copy_with_alloc(ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #2

declare i32 @ba_get_byte(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #2

declare i32 @ba_set_byte(ptr noundef, i64 noundef, i8 noundef zeroext) local_unnamed_addr #2

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

declare i32 @asn_ba2INTEGER(ptr noundef, ptr noundef) local_unnamed_addr #2

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


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