; LLVM IR from specinfo-ua/UAPKI :: library/common/pkix/uapki-ns-util.ll (ZN7UapkiNS4Util16decodeAsn1HeaderEPKhmRjRmS4_)

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

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN7UapkiNS4Util16decodeAsn1HeaderEPKhmRjRmS4_(ptr noundef %0, i64 noundef %1, ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef nonnull align 8 dereferenceable(8) %3, ptr noundef nonnull align 8 dereferenceable(8) %4) #1 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca i32, align 4
  %15 = alloca i64, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i64 %1, ptr %8, align 8, !tbaa !9
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  %16 = load i64, ptr %8, align 8, !tbaa !9
  %17 = icmp ult i64 %16, 2
  br i1 %17, label %18, label %19

18:                                               ; preds = %5
  store i32 0, ptr %6, align 4
  br label %77

19:                                               ; preds = %5
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %20, i64 0
  %22 = load i8, ptr %21, align 1, !tbaa !11
  %23 = zext i8 %22 to i32
  %24 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 %23, ptr %24, align 4, !tbaa !12
  %25 = load ptr, ptr %10, align 8, !tbaa !5
  store i64 2, ptr %25, align 8, !tbaa !9
  %26 = load ptr, ptr %11, align 8, !tbaa !5
  store i64 0, ptr %26, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %27, i64 1
  %29 = load i8, ptr %28, align 1, !tbaa !11
  %30 = zext i8 %29 to i64
  store i64 %30, ptr %12, align 8, !tbaa !9
  %31 = load i64, ptr %12, align 8, !tbaa !9
  %32 = icmp ult i64 %31, 128
  br i1 %32, label %33, label %36

33:                                               ; preds = %19
  %34 = load i64, ptr %12, align 8, !tbaa !9
  %35 = load ptr, ptr %11, align 8, !tbaa !5
  store i64 %34, ptr %35, align 8, !tbaa !9
  br label %75

36:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  %37 = load i64, ptr %12, align 8, !tbaa !9
  %38 = and i64 %37, 7
  store i64 %38, ptr %13, align 8, !tbaa !9
  %39 = load i64, ptr %13, align 8, !tbaa !9
  %40 = load ptr, ptr %10, align 8, !tbaa !5
  %41 = load i64, ptr %40, align 8, !tbaa !9
  %42 = add i64 %41, %39
  store i64 %42, ptr %40, align 8, !tbaa !9
  %43 = load i64, ptr %8, align 8, !tbaa !9
  %44 = load i64, ptr %13, align 8, !tbaa !9
  %45 = add i64 %44, 2
  %46 = icmp ult i64 %43, %45
  br i1 %46, label %47, label %48

47:                                               ; preds = %36
  store i32 0, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %72

48:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #2
  store i64 2, ptr %15, align 8, !tbaa !9
  br label %49

49:                                               ; preds = %68, %48
  %50 = load i64, ptr %15, align 8, !tbaa !9
  %51 = load ptr, ptr %10, align 8, !tbaa !5
  %52 = load i64, ptr %51, align 8, !tbaa !9
  %53 = icmp ult i64 %50, %52
  br i1 %53, label %55, label %54

54:                                               ; preds = %49
  store i32 2, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #2
  br label %71

55:                                               ; preds = %49
  %56 = load ptr, ptr %11, align 8, !tbaa !5
  %57 = load i64, ptr %56, align 8, !tbaa !9
  %58 = shl i64 %57, 8
  store i64 %58, ptr %56, align 8, !tbaa !9
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = load i64, ptr %15, align 8, !tbaa !9
  %61 = getelementptr inbounds i8, ptr %59, i64 %60
  %62 = load i8, ptr %61, align 1, !tbaa !11
  %63 = zext i8 %62 to i64
  store i64 %63, ptr %12, align 8, !tbaa !9
  %64 = load i64, ptr %12, align 8, !tbaa !9
  %65 = load ptr, ptr %11, align 8, !tbaa !5
  %66 = load i64, ptr %65, align 8, !tbaa !9
  %67 = or i64 %66, %64
  store i64 %67, ptr %65, align 8, !tbaa !9
  br label %68

68:                                               ; preds = %55
  %69 = load i64, ptr %15, align 8, !tbaa !9
  %70 = add i64 %69, 1
  store i64 %70, ptr %15, align 8, !tbaa !9
  br label %49, !llvm.loop !14

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

72:                                               ; preds = %71, %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  %73 = load i32, ptr %14, align 4
  switch i32 %73, label %76 [
    i32 0, label %74
  ]

74:                                               ; preds = %72
  br label %75

75:                                               ; preds = %74, %33
  store i32 1, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %76

76:                                               ; preds = %75, %72
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  br label %77

77:                                               ; preds = %76, %18
  %78 = load i32, ptr %6, align 4
  ret i32 %78
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 #2 = { 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 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local noundef range(i32 0, 2) i32 @_ZN7UapkiNS4Util16decodeAsn1HeaderEPKhmRjRmS4_(ptr nocapture noundef readonly %0, i64 noundef %1, ptr nocapture noundef nonnull writeonly align 4 dereferenceable(4) %2, ptr nocapture noundef nonnull align 8 dereferenceable(8) %3, ptr nocapture noundef nonnull align 8 dereferenceable(8) %4) local_unnamed_addr #0 {
  %6 = icmp ult i64 %1, 2
  br i1 %6, label %.critedge, label %7

7:                                                ; preds = %5
  %8 = load i8, ptr %0, align 1, !tbaa !5
  %9 = zext i8 %8 to i32
  store i32 %9, ptr %2, align 4, !tbaa !8
  store i64 2, ptr %3, align 8, !tbaa !10
  store i64 0, ptr %4, align 8, !tbaa !10
  %10 = getelementptr inbounds i8, ptr %0, i64 1
  %11 = load i8, ptr %10, align 1, !tbaa !5
  %12 = zext i8 %11 to i64
  %13 = icmp sgt i8 %11, -1
  br i1 %13, label %14, label %15

14:                                               ; preds = %7
  store i64 %12, ptr %4, align 8, !tbaa !10
  br label %.critedge

15:                                               ; preds = %7
  %16 = and i64 %12, 7
  %17 = load i64, ptr %3, align 8, !tbaa !10
  %18 = add i64 %17, %16
  store i64 %18, ptr %3, align 8, !tbaa !10
  %19 = add nuw nsw i64 %16, 2
  %.not = icmp ugt i64 %19, %1
  br i1 %.not, label %.critedge, label %.preheader

.preheader:                                       ; preds = %15
  %20 = icmp ugt i64 %18, 2
  br i1 %20, label %.lr.ph.preheader, label %.critedge

.lr.ph.preheader:                                 ; preds = %.preheader
  %.pre = load i64, ptr %4, align 8, !tbaa !10
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %21 = phi i64 [ %26, %.lr.ph ], [ %.pre, %.lr.ph.preheader ]
  %.028 = phi i64 [ %27, %.lr.ph ], [ 2, %.lr.ph.preheader ]
  %22 = shl i64 %21, 8
  store i64 %22, ptr %4, align 8, !tbaa !10
  %23 = getelementptr inbounds i8, ptr %0, i64 %.028
  %24 = load i8, ptr %23, align 1, !tbaa !5
  %25 = zext i8 %24 to i64
  %26 = or disjoint i64 %22, %25
  store i64 %26, ptr %4, align 8, !tbaa !10
  %27 = add nuw i64 %.028, 1
  %28 = load i64, ptr %3, align 8, !tbaa !10
  %29 = icmp ult i64 %27, %28
  br i1 %29, label %.lr.ph, label %.critedge, !llvm.loop !12

.critedge:                                        ; preds = %.lr.ph, %14, %.preheader, %15, %5
  %.2 = phi i32 [ 0, %5 ], [ 0, %15 ], [ 1, %.preheader ], [ 1, %14 ], [ 1, %.lr.ph ]
  ret i32 %.2
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(argmem: readwrite) 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" }

!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, !9, i64 0}
!9 = !{!"int", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"long", !6, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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