; 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_put_few_bits(ptr noundef, i32 noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @uper_put_length(ptr noundef, i64 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @uper_put_nslength(ptr noundef %0, i64 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  %6 = load i64, ptr %5, align 8, !tbaa !9
  %7 = icmp ule i64 %6, 64
  br i1 %7, label %8, label %21

8:                                                ; preds = %2
  %9 = load i64, ptr %5, align 8, !tbaa !9
  %10 = icmp eq i64 %9, 0
  br i1 %10, label %11, label %12

11:                                               ; preds = %8
  store i32 -1, ptr %3, align 4
  br label %30

12:                                               ; preds = %8
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = load i64, ptr %5, align 8, !tbaa !9
  %15 = sub i64 %14, 1
  %16 = trunc i64 %15 to i32
  %17 = call i32 @per_put_few_bits(ptr noundef %13, i32 noundef %16, i32 noundef 7)
  %18 = icmp ne i32 %17, 0
  %19 = zext i1 %18 to i64
  %20 = select i1 %18, i32 -1, i32 0
  store i32 %20, ptr %3, align 4
  br label %30

21:                                               ; preds = %2
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = load i64, ptr %5, align 8, !tbaa !9
  %24 = call i64 @uper_put_length(ptr noundef %22, i64 noundef %23)
  %25 = load i64, ptr %5, align 8, !tbaa !9
  %26 = icmp ne i64 %24, %25
  br i1 %26, label %27, label %28

27:                                               ; preds = %21
  store i32 -1, ptr %3, align 4
  br label %30

28:                                               ; preds = %21
  br label %29

29:                                               ; preds = %28
  store i32 0, ptr %3, align 4
  br label %30

30:                                               ; preds = %29, %27, %12, %11
  %31 = load i32, ptr %3, align 4
  ret i32 %31
}

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)"}
!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_put_few_bits(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @uper_put_length(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @uper_put_nslength(ptr noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = icmp ult i64 %1, 65
  br i1 %3, label %4, label %11

4:                                                ; preds = %2
  %5 = icmp eq i64 %1, 0
  br i1 %5, label %13, label %6

6:                                                ; preds = %4
  %7 = trunc nuw i64 %1 to i32
  %8 = add nsw i32 %7, -1
  %9 = tail call i32 @per_put_few_bits(ptr noundef %0, i32 noundef %8, i32 noundef 7)
  %.not8 = icmp ne i32 %9, 0
  %10 = sext i1 %.not8 to i32
  br label %13

11:                                               ; preds = %2
  %12 = tail call i64 @uper_put_length(ptr noundef %0, i64 noundef %1)
  %.not = icmp ne i64 %12, %1
  %. = sext i1 %.not to i32
  br label %13

13:                                               ; preds = %11, %4, %6
  %.0 = phi i32 [ %10, %6 ], [ -1, %4 ], [ %., %11 ]
  ret i32 %.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: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass