; LLVM IR from specinfo-ua/UAPKI :: library/uapkif/src/asn1 (asn1-utils)

; 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"

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

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

declare ptr @ba_get_buf_const(ptr noundef) #1

declare i64 @ba_get_len(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @asn_bytes2INTEGER(ptr noundef, ptr noundef, i64 noundef) #3

; Function Attrs: nounwind uwtable
define dso_local i32 @asn_ba2INTEGER(ptr noundef %0, ptr noundef %1) #3 {
  %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 i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  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
  store ptr null, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  store i64 0, ptr %9, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  br label %13

13:                                               ; preds = %2
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %18, label %16

16:                                               ; preds = %13
  store i32 2, ptr %6, align 4, !tbaa !9
  %17 = load i32, ptr %6, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 985, i32 noundef %17, ptr noundef null)
  br label %124

18:                                               ; preds = %13
  br label %19

19:                                               ; preds = %18
  br label %20

20:                                               ; preds = %19
  br label %21

21:                                               ; preds = %20
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = icmp ne ptr %22, null
  br i1 %23, label %26, label %24

24:                                               ; preds = %21
  store i32 2, ptr %6, align 4, !tbaa !9
  %25 = load i32, ptr %6, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 986, i32 noundef %25, ptr noundef null)
  br label %124

26:                                               ; preds = %21
  br label %27

27:                                               ; preds = %26
  br label %28

28:                                               ; preds = %27
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = call i64 @ba_get_len(ptr noundef %29)
  store i64 %30, ptr %8, align 8, !tbaa !11
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = call ptr @ba_get_buf_const(ptr noundef %31)
  store ptr %32, ptr %10, align 8, !tbaa !5
  %33 = load i64, ptr %8, align 8, !tbaa !11
  %34 = icmp ugt i64 %33, 0
  br i1 %34, label %35, label %76

35:                                               ; preds = %28
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %36, i64 0
  %38 = load i8, ptr %37, align 1, !tbaa !13
  %39 = zext i8 %38 to i32
  %40 = icmp sgt i32 %39, 127
  br i1 %40, label %41, label %76

41:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  br label %42

42:                                               ; preds = %41
  %43 = load i64, ptr %8, align 8, !tbaa !11
  %44 = add i64 %43, 1
  %45 = call ptr @ba_alloc_by_len(i64 noundef %44)
  store ptr %45, ptr %7, align 8, !tbaa !5
  %46 = icmp eq ptr null, %45
  br i1 %46, label %47, label %49

47:                                               ; preds = %42
  store i32 2, ptr %6, align 4, !tbaa !9
  %48 = load i32, ptr %6, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 993, i32 noundef %48)
  store i32 4, ptr %12, align 4
  br label %73

49:                                               ; preds = %42
  br label %50

50:                                               ; preds = %49
  br label %51

51:                                               ; preds = %50
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = call ptr @ba_get_buf(ptr noundef %52)
  store ptr %53, ptr %11, align 8, !tbaa !5
  %54 = load ptr, ptr %11, align 8, !tbaa !5
  %55 = getelementptr inbounds i8, ptr %54, i64 0
  store i8 0, ptr %55, align 1, !tbaa !13
  %56 = load ptr, ptr %11, align 8, !tbaa !5
  %57 = getelementptr inbounds i8, ptr %56, i64 1
  %58 = load ptr, ptr %10, align 8, !tbaa !5
  %59 = load i64, ptr %8, align 8, !tbaa !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %57, ptr align 1 %58, i64 %59, i1 false)
  br label %60

60:                                               ; preds = %51
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = load ptr, ptr %11, align 8, !tbaa !5
  %63 = load i64, ptr %8, align 8, !tbaa !11
  %64 = add i64 %63, 1
  %65 = call i32 @asn_bytes2INTEGER(ptr noundef %61, ptr noundef %62, i64 noundef %64)
  store i32 %65, ptr %6, align 4, !tbaa !9
  %66 = load i32, ptr %6, align 4, !tbaa !9
  %67 = icmp ne i32 %66, 0
  br i1 %67, label %68, label %70

68:                                               ; preds = %60
  %69 = load i32, ptr %6, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 997, i32 noundef %69)
  store i32 4, ptr %12, align 4
  br label %73

70:                                               ; preds = %60
  br label %71

71:                                               ; preds = %70
  br label %72

72:                                               ; preds = %71
  store i32 0, ptr %12, align 4
  br label %73

73:                                               ; preds = %72, %68, %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  %74 = load i32, ptr %12, align 4
  switch i32 %74, label %127 [
    i32 0, label %75
    i32 4, label %124
  ]

75:                                               ; preds = %73
  br label %123

76:                                               ; preds = %35, %28
  %77 = load i64, ptr %8, align 8, !tbaa !11
  %78 = icmp ugt i64 %77, 1
  br i1 %78, label %79, label %106

79:                                               ; preds = %76
  br label %80

80:                                               ; preds = %102, %79
  %81 = load i64, ptr %9, align 8, !tbaa !11
  %82 = load i64, ptr %8, align 8, !tbaa !11
  %83 = sub i64 %82, 1
  %84 = icmp ult i64 %81, %83
  br i1 %84, label %85, label %105

85:                                               ; preds = %80
  %86 = load ptr, ptr %10, align 8, !tbaa !5
  %87 = load i64, ptr %9, align 8, !tbaa !11
  %88 = getelementptr inbounds i8, ptr %86, i64 %87
  %89 = load i8, ptr %88, align 1, !tbaa !13
  %90 = zext i8 %89 to i32
  %91 = icmp ne i32 %90, 0
  br i1 %91, label %100, label %92

92:                                               ; preds = %85
  %93 = load ptr, ptr %10, align 8, !tbaa !5
  %94 = load i64, ptr %9, align 8, !tbaa !11
  %95 = add i64 %94, 1
  %96 = getelementptr inbounds i8, ptr %93, i64 %95
  %97 = load i8, ptr %96, align 1, !tbaa !13
  %98 = zext i8 %97 to i32
  %99 = icmp sgt i32 %98, 127
  br i1 %99, label %100, label %101

100:                                              ; preds = %92, %85
  br label %105

101:                                              ; preds = %92
  br label %102

102:                                              ; preds = %101
  %103 = load i64, ptr %9, align 8, !tbaa !11
  %104 = add i64 %103, 1
  store i64 %104, ptr %9, align 8, !tbaa !11
  br label %80, !llvm.loop !14

105:                                              ; preds = %100, %80
  br label %106

106:                                              ; preds = %105, %76
  br label %107

107:                                              ; preds = %106
  %108 = load ptr, ptr %5, align 8, !tbaa !5
  %109 = load ptr, ptr %10, align 8, !tbaa !5
  %110 = load i64, ptr %9, align 8, !tbaa !11
  %111 = getelementptr inbounds i8, ptr %109, i64 %110
  %112 = load i64, ptr %8, align 8, !tbaa !11
  %113 = load i64, ptr %9, align 8, !tbaa !11
  %114 = sub i64 %112, %113
  %115 = call i32 @asn_bytes2INTEGER(ptr noundef %108, ptr noundef %111, i64 noundef %114)
  store i32 %115, ptr %6, align 4, !tbaa !9
  %116 = load i32, ptr %6, align 4, !tbaa !9
  %117 = icmp ne i32 %116, 0
  br i1 %117, label %118, label %120

118:                                              ; preds = %107
  %119 = load i32, ptr %6, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 1008, i32 noundef %119)
  br label %124

120:                                              ; preds = %107
  br label %121

121:                                              ; preds = %120
  br label %122

122:                                              ; preds = %121
  br label %123

123:                                              ; preds = %122, %75
  br label %124

124:                                              ; preds = %123, %118, %73, %24, %16
  %125 = load ptr, ptr %7, align 8, !tbaa !5
  call void @ba_free(ptr noundef %125)
  %126 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %126, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %127

127:                                              ; preds = %124, %73
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  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
  %128 = load i32, ptr %3, align 4
  ret i32 %128
}

declare ptr @ba_alloc_by_len(i64 noundef) #1

declare ptr @ba_get_buf(ptr noundef) #1

declare void @ba_free(ptr noundef) #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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nounwind 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 }

!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/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 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; 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 [25 x i8], align 1

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

declare ptr @ba_get_buf_const(ptr noundef) local_unnamed_addr #0

declare i64 @ba_get_len(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @asn_bytes2INTEGER(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local i32 @asn_ba2INTEGER(ptr noundef %0, ptr noundef %1) local_unnamed_addr #2 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %3, label %4

3:                                                ; preds = %2
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 985, i32 noundef 2, ptr noundef null) #3
  br label %36

4:                                                ; preds = %2
  %.not51 = icmp eq ptr %1, null
  br i1 %.not51, label %5, label %6

5:                                                ; preds = %4
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 986, i32 noundef 2, ptr noundef null) #3
  br label %36

6:                                                ; preds = %4
  %7 = tail call i64 @ba_get_len(ptr noundef nonnull %0) #3
  %8 = tail call ptr @ba_get_buf_const(ptr noundef nonnull %0) #3
  %.not52 = icmp eq i64 %7, 0
  br i1 %.not52, label %.thread, label %9

9:                                                ; preds = %6
  %10 = load i8, ptr %8, align 1, !tbaa !5
  %11 = icmp slt i8 %10, 0
  br i1 %11, label %12, label %22

12:                                               ; preds = %9
  %13 = add i64 %7, 1
  %14 = tail call ptr @ba_alloc_by_len(i64 noundef %13) #3
  %15 = icmp eq ptr %14, null
  br i1 %15, label %16, label %17

16:                                               ; preds = %12
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 993, i32 noundef 2) #3
  br label %36

17:                                               ; preds = %12
  %18 = tail call ptr @ba_get_buf(ptr noundef nonnull %14) #3
  store i8 0, ptr %18, align 1, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %18, i64 1
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %19, ptr nonnull align 1 %8, i64 %7, i1 false)
  %20 = tail call i32 @asn_bytes2INTEGER(ptr noundef nonnull %1, ptr noundef nonnull %18, i64 noundef %13)
  %.not55 = icmp eq i32 %20, 0
  br i1 %.not55, label %36, label %21

21:                                               ; preds = %17
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 997, i32 noundef %20) #3
  br label %36

22:                                               ; preds = %9
  %.not56 = icmp eq i64 %7, 1
  br i1 %.not56, label %.thread, label %.preheader

.preheader:                                       ; preds = %22
  %23 = add i64 %7, -1
  br label %24

24:                                               ; preds = %.preheader, %27
  %25 = phi i8 [ %30, %27 ], [ %10, %.preheader ]
  %.040 = phi i64 [ %28, %27 ], [ 0, %.preheader ]
  %exitcond.not = icmp eq i64 %.040, %23
  br i1 %exitcond.not, label %.thread, label %26

26:                                               ; preds = %24
  %.not53 = icmp eq i8 %25, 0
  br i1 %.not53, label %27, label %.thread

27:                                               ; preds = %26
  %28 = add i64 %.040, 1
  %29 = getelementptr inbounds i8, ptr %8, i64 %28
  %30 = load i8, ptr %29, align 1, !tbaa !5
  %31 = icmp slt i8 %30, 0
  br i1 %31, label %.thread, label %24, !llvm.loop !8

.thread:                                          ; preds = %26, %27, %24, %6, %22
  %.141 = phi i64 [ 0, %22 ], [ 0, %6 ], [ %.040, %26 ], [ %.040, %27 ], [ %23, %24 ]
  %32 = getelementptr inbounds i8, ptr %8, i64 %.141
  %33 = sub i64 %7, %.141
  %34 = tail call i32 @asn_bytes2INTEGER(ptr noundef nonnull %1, ptr noundef %32, i64 noundef %33)
  %.not54 = icmp eq i32 %34, 0
  br i1 %.not54, label %36, label %35

35:                                               ; preds = %.thread
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 1008, i32 noundef %34) #3
  br label %36

36:                                               ; preds = %16, %21, %17, %.thread, %35, %5, %3
  %.042 = phi ptr [ null, %35 ], [ null, %.thread ], [ null, %5 ], [ null, %3 ], [ %14, %17 ], [ %14, %21 ], [ null, %16 ]
  %.1 = phi i32 [ %34, %35 ], [ 0, %.thread ], [ 2, %5 ], [ 2, %3 ], [ 0, %17 ], [ %20, %21 ], [ 2, %16 ]
  tail call void @ba_free(ptr noundef %.042) #3
  ret i32 %.1
}

declare ptr @ba_alloc_by_len(i64 noundef) local_unnamed_addr #0

declare ptr @ba_get_buf(ptr noundef) local_unnamed_addr #0

declare void @ba_free(ptr noundef) local_unnamed_addr #0

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 nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass