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

; 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: nounwind uwtable
declare dso_local i32 @per_get_few_bits(ptr noundef, i32 noundef) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @uper_get_nsnnwn(ptr noundef %0) #0 {
  %2 = alloca i64, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = call i32 @per_get_few_bits(ptr noundef %6, i32 noundef 7)
  %8 = sext i32 %7 to i64
  store i64 %8, ptr %4, align 8, !tbaa !9
  %9 = load i64, ptr %4, align 8, !tbaa !9
  %10 = and i64 %9, 64
  %11 = icmp ne i64 %10, 0
  br i1 %11, label %12, label %42

12:                                               ; preds = %1
  %13 = load i64, ptr %4, align 8, !tbaa !9
  %14 = and i64 %13, 63
  store i64 %14, ptr %4, align 8, !tbaa !9
  %15 = load i64, ptr %4, align 8, !tbaa !9
  %16 = shl i64 %15, 2
  store i64 %16, ptr %4, align 8, !tbaa !9
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = call i32 @per_get_few_bits(ptr noundef %17, i32 noundef 2)
  %19 = sext i32 %18 to i64
  %20 = load i64, ptr %4, align 8, !tbaa !9
  %21 = or i64 %20, %19
  store i64 %21, ptr %4, align 8, !tbaa !9
  %22 = load i64, ptr %4, align 8, !tbaa !9
  %23 = and i64 %22, 128
  %24 = icmp ne i64 %23, 0
  br i1 %24, label %25, label %26

25:                                               ; preds = %12
  store i64 -1, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %44

26:                                               ; preds = %12
  %27 = load i64, ptr %4, align 8, !tbaa !9
  %28 = icmp eq i64 %27, 0
  br i1 %28, label %29, label %30

29:                                               ; preds = %26
  store i64 0, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %44

30:                                               ; preds = %26
  %31 = load i64, ptr %4, align 8, !tbaa !9
  %32 = icmp sge i64 %31, 3
  br i1 %32, label %33, label %34

33:                                               ; preds = %30
  store i64 -1, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %44

34:                                               ; preds = %30
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = load i64, ptr %4, align 8, !tbaa !9
  %37 = mul nsw i64 8, %36
  %38 = trunc i64 %37 to i32
  %39 = call i32 @per_get_few_bits(ptr noundef %35, i32 noundef %38)
  %40 = sext i32 %39 to i64
  store i64 %40, ptr %4, align 8, !tbaa !9
  %41 = load i64, ptr %4, align 8, !tbaa !9
  store i64 %41, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %44

42:                                               ; preds = %1
  %43 = load i64, ptr %4, align 8, !tbaa !9
  store i64 %43, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %44

44:                                               ; preds = %42, %34, %33, %29, %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  %45 = load i64, ptr %2, align 8
  ret i64 %45
}

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 }

!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}


; 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: nounwind uwtable
declare dso_local i32 @per_get_few_bits(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i64 -2147483648, 2147483648) i64 @uper_get_nsnnwn(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call i32 @per_get_few_bits(ptr noundef %0, i32 noundef 7)
  %3 = sext i32 %2 to i64
  %4 = and i64 %3, 64
  %.not = icmp eq i64 %4, 0
  br i1 %.not, label %20, label %5

5:                                                ; preds = %1
  %6 = shl nsw i64 %3, 2
  %7 = and i64 %6, 252
  %8 = tail call i32 @per_get_few_bits(ptr noundef %0, i32 noundef 2)
  %9 = sext i32 %8 to i64
  %10 = or i64 %7, %9
  %11 = and i64 %10, 128
  %.not14 = icmp eq i64 %11, 0
  br i1 %.not14, label %12, label %20

12:                                               ; preds = %5
  %13 = icmp eq i64 %10, 0
  br i1 %13, label %20, label %14

14:                                               ; preds = %12
  %15 = icmp sgt i64 %10, 2
  br i1 %15, label %20, label %16

16:                                               ; preds = %14
  %.tr = trunc nsw i64 %10 to i32
  %17 = shl i32 %.tr, 3
  %18 = tail call i32 @per_get_few_bits(ptr noundef %0, i32 noundef %17)
  %19 = sext i32 %18 to i64
  br label %20

20:                                               ; preds = %1, %14, %12, %5, %16
  %.0 = phi i64 [ %19, %16 ], [ -1, %5 ], [ 0, %12 ], [ -1, %14 ], [ %3, %1 ]
  ret i64 %.0
}

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

!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)"}


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