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

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

%struct.asn_dec_rval_s = type { i32, i64 }

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

; Function Attrs: nounwind uwtable
define dso_local { i32, i64 } @BOOLEAN_decode_ber(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i64 noundef %4, i32 noundef %5) #0 {
  %7 = alloca %struct.asn_dec_rval_s, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  %16 = alloca i64, align 8
  %17 = alloca i32, align 4
  %18 = alloca %struct.asn_dec_rval_s, align 8
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store ptr %2, ptr %10, align 8, !tbaa !5
  store ptr %3, ptr %11, align 8, !tbaa !5
  store i64 %4, ptr %12, align 8, !tbaa !9
  store i32 %5, ptr %13, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  %19 = load ptr, ptr %10, align 8, !tbaa !5
  %20 = load ptr, ptr %19, align 8, !tbaa !5
  store ptr %20, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #5
  %21 = load ptr, ptr %14, align 8, !tbaa !5
  %22 = icmp eq ptr %21, null
  br i1 %22, label %23, label %32

23:                                               ; preds = %6
  %24 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 4) #6
  %25 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %24, ptr %25, align 8, !tbaa !5
  store ptr %24, ptr %14, align 8, !tbaa !5
  %26 = load ptr, ptr %14, align 8, !tbaa !5
  %27 = icmp eq ptr %26, null
  br i1 %27, label %28, label %31

28:                                               ; preds = %23
  %29 = getelementptr inbounds %struct.asn_dec_rval_s, ptr %7, i32 0, i32 0
  store i32 2, ptr %29, align 8, !tbaa !13
  %30 = getelementptr inbounds %struct.asn_dec_rval_s, ptr %7, i32 0, i32 1
  store i64 0, ptr %30, align 8, !tbaa !15
  call void @stacktrace_create(ptr noundef @.str.1, i64 noundef 87, i32 noundef 100, ptr noundef null)
  store i32 1, ptr %17, align 4
  br label %92

31:                                               ; preds = %23
  br label %32

32:                                               ; preds = %31, %6
  call void @llvm.lifetime.start.p0(i64 16, ptr %18) #5
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  %35 = load ptr, ptr %11, align 8, !tbaa !5
  %36 = load i64, ptr %12, align 8, !tbaa !9
  %37 = load i32, ptr %13, align 4, !tbaa !11
  %38 = call { i32, i64 } @ber_check_tags(ptr noundef %33, ptr noundef %34, ptr noundef null, ptr noundef %35, i64 noundef %36, i32 noundef %37, i32 noundef 0, ptr noundef %15, ptr noundef null)
  %39 = getelementptr inbounds { i32, i64 }, ptr %18, i32 0, i32 0
  %40 = extractvalue { i32, i64 } %38, 0
  store i32 %40, ptr %39, align 8
  %41 = getelementptr inbounds { i32, i64 }, ptr %18, i32 0, i32 1
  %42 = extractvalue { i32, i64 } %38, 1
  store i64 %42, ptr %41, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %7, ptr align 8 %18, i64 16, i1 false), !tbaa.struct !16
  call void @llvm.lifetime.end.p0(i64 16, ptr %18) #5
  %43 = getelementptr inbounds %struct.asn_dec_rval_s, ptr %7, i32 0, i32 0
  %44 = load i32, ptr %43, align 8, !tbaa !13
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %46, label %47

46:                                               ; preds = %32
  store i32 1, ptr %17, align 4
  br label %92

47:                                               ; preds = %32
  %48 = load ptr, ptr %11, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.asn_dec_rval_s, ptr %7, i32 0, i32 1
  %50 = load i64, ptr %49, align 8, !tbaa !15
  %51 = getelementptr inbounds i8, ptr %48, i64 %50
  store ptr %51, ptr %11, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.asn_dec_rval_s, ptr %7, i32 0, i32 1
  %53 = load i64, ptr %52, align 8, !tbaa !15
  %54 = load i64, ptr %12, align 8, !tbaa !9
  %55 = sub i64 %54, %53
  store i64 %55, ptr %12, align 8, !tbaa !9
  %56 = load i64, ptr %15, align 8, !tbaa !9
  %57 = load i64, ptr %12, align 8, !tbaa !9
  %58 = icmp sgt i64 %56, %57
  br i1 %58, label %59, label %62

59:                                               ; preds = %47
  %60 = getelementptr inbounds %struct.asn_dec_rval_s, ptr %7, i32 0, i32 0
  store i32 1, ptr %60, align 8, !tbaa !13
  %61 = getelementptr inbounds %struct.asn_dec_rval_s, ptr %7, i32 0, i32 1
  store i64 0, ptr %61, align 8, !tbaa !15
  call void @stacktrace_create(ptr noundef @.str.1, i64 noundef 111, i32 noundef 100, ptr noundef null)
  store i32 1, ptr %17, align 4
  br label %92

62:                                               ; preds = %47
  %63 = load ptr, ptr %14, align 8, !tbaa !5
  store i32 0, ptr %63, align 4, !tbaa !11
  store i64 0, ptr %16, align 8, !tbaa !9
  br label %64

64:                                               ; preds = %83, %62
  %65 = load i64, ptr %16, align 8, !tbaa !9
  %66 = load i64, ptr %15, align 8, !tbaa !9
  %67 = icmp slt i64 %65, %66
  br i1 %67, label %68, label %72

68:                                               ; preds = %64
  %69 = load ptr, ptr %14, align 8, !tbaa !5
  %70 = load i32, ptr %69, align 4, !tbaa !11
  %71 = icmp eq i32 %70, 0
  br label %72

72:                                               ; preds = %68, %64
  %73 = phi i1 [ false, %64 ], [ %71, %68 ]
  br i1 %73, label %74, label %86

74:                                               ; preds = %72
  %75 = load ptr, ptr %11, align 8, !tbaa !5
  %76 = load i64, ptr %16, align 8, !tbaa !9
  %77 = getelementptr inbounds i8, ptr %75, i64 %76
  %78 = load i8, ptr %77, align 1, !tbaa !17
  %79 = zext i8 %78 to i32
  %80 = load ptr, ptr %14, align 8, !tbaa !5
  %81 = load i32, ptr %80, align 4, !tbaa !11
  %82 = or i32 %81, %79
  store i32 %82, ptr %80, align 4, !tbaa !11
  br label %83

83:                                               ; preds = %74
  %84 = load i64, ptr %16, align 8, !tbaa !9
  %85 = add nsw i64 %84, 1
  store i64 %85, ptr %16, align 8, !tbaa !9
  br label %64, !llvm.loop !18

86:                                               ; preds = %72
  %87 = getelementptr inbounds %struct.asn_dec_rval_s, ptr %7, i32 0, i32 0
  store i32 0, ptr %87, align 8, !tbaa !13
  %88 = load i64, ptr %15, align 8, !tbaa !9
  %89 = getelementptr inbounds %struct.asn_dec_rval_s, ptr %7, i32 0, i32 1
  %90 = load i64, ptr %89, align 8, !tbaa !15
  %91 = add i64 %90, %88
  store i64 %91, ptr %89, align 8, !tbaa !15
  store i32 1, ptr %17, align 4
  br label %92

92:                                               ; preds = %86, %59, %46, %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  %93 = load { i32, i64 }, ptr %7, align 8
  ret { i32, i64 } %93
}

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

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

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

declare { i32, i64 } @ber_check_tags(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i64 noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef) #3

; 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) #4

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nounwind }
attributes #6 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"asn_dec_rval_s", !12, i64 0, !10, i64 8}
!15 = !{!14, !10, i64 8}
!16 = !{i64 0, i64 4, !11, i64 8, i64 8, !9}
!17 = !{!7, !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"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.1 = external hidden unnamed_addr constant [22 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local { i32, i64 } @BOOLEAN_decode_ber(ptr noundef %0, ptr noundef %1, ptr nocapture noundef %2, ptr noundef %3, i64 noundef %4, i32 noundef %5) local_unnamed_addr #0 {
  %7 = alloca i64, align 8
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #4
  %9 = icmp eq ptr %8, null
  br i1 %9, label %10, label %14

10:                                               ; preds = %6
  %11 = tail call noalias dereferenceable_or_null(4) ptr @calloc(i64 noundef 1, i64 noundef 4) #5
  store ptr %11, ptr %2, align 8, !tbaa !5
  %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.1, i64 noundef 87, i32 noundef 100, ptr noundef null) #4
  br label %34

14:                                               ; preds = %10, %6
  %.024 = phi ptr [ %11, %10 ], [ %8, %6 ]
  %15 = call { i32, i64 } @ber_check_tags(ptr noundef %0, ptr noundef %1, ptr noundef null, ptr noundef %3, i64 noundef %4, i32 noundef %5, i32 noundef 0, ptr noundef nonnull %7, ptr noundef null) #4
  %16 = extractvalue { i32, i64 } %15, 0
  %17 = extractvalue { i32, i64 } %15, 1
  %.not = icmp eq i32 %16, 0
  br i1 %.not, label %18, label %34

18:                                               ; preds = %14
  %19 = getelementptr inbounds i8, ptr %3, i64 %17
  %20 = sub i64 %4, %17
  %21 = load i64, ptr %7, align 8, !tbaa !9
  %22 = icmp sgt i64 %21, %20
  br i1 %22, label %23, label %24

23:                                               ; preds = %18
  call void @stacktrace_create(ptr noundef nonnull @.str.1, i64 noundef 111, i32 noundef 100, ptr noundef null) #4
  br label %34

24:                                               ; preds = %18
  store i32 0, ptr %.024, align 4, !tbaa !11
  %25 = icmp sgt i64 %21, 0
  br i1 %25, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %24, %28
  %26 = phi i32 [ %31, %28 ], [ 0, %24 ]
  %.029 = phi i64 [ %32, %28 ], [ 0, %24 ]
  %27 = icmp eq i32 %26, 0
  br i1 %27, label %28, label %.critedge

28:                                               ; preds = %.lr.ph
  %29 = getelementptr inbounds i8, ptr %19, i64 %.029
  %30 = load i8, ptr %29, align 1, !tbaa !13
  %31 = zext i8 %30 to i32
  store i32 %31, ptr %.024, align 4, !tbaa !11
  %32 = add nuw nsw i64 %.029, 1
  %exitcond.not = icmp eq i64 %32, %21
  br i1 %exitcond.not, label %.critedge, label %.lr.ph, !llvm.loop !14

.critedge:                                        ; preds = %.lr.ph, %28, %24
  %33 = add i64 %21, %17
  br label %34

34:                                               ; preds = %14, %.critedge, %23, %13
  %.sroa.019.0 = phi i32 [ 2, %13 ], [ 1, %23 ], [ 0, %.critedge ], [ %16, %14 ]
  %.sroa.7.0 = phi i64 [ 0, %13 ], [ 0, %23 ], [ %33, %.critedge ], [ %17, %14 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #4
  %.fca.0.insert = insertvalue { i32, i64 } poison, i32 %.sroa.019.0, 0
  %.fca.1.insert = insertvalue { i32, i64 } %.fca.0.insert, i64 %.sroa.7.0, 1
  ret { i32, i64 } %.fca.1.insert
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #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 #2

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

declare { i32, i64 } @ber_check_tags(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i64 noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

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

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 }
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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass