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

; 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.OCTET_STRING = type { ptr, i32, %struct.asn_struct_ctx_s }
%struct.asn_struct_ctx_s = type { i16, i16, i32, ptr, i64 }
%struct.asn_TYPE_descriptor_s = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, ptr, i32, ptr, ptr, i32, ptr }

@.str.1 = external hidden unnamed_addr constant [64 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [28 x i8], align 1
@_PrintableString_alphabet = external hidden constant <{ [123 x i32], [133 x i32] }>, align 16

; Function Attrs: nounwind uwtable
define dso_local i32 @PrintableString_constraint(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %14, ptr %10, align 8, !tbaa !5
  %15 = load ptr, ptr %10, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %74

17:                                               ; preds = %4
  %18 = load ptr, ptr %10, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.OCTET_STRING, ptr %18, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !9
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %74

22:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %23 = load ptr, ptr %10, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.OCTET_STRING, ptr %23, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !9
  store ptr %25, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %26 = load ptr, ptr %11, align 8, !tbaa !5
  %27 = load ptr, ptr %10, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.OCTET_STRING, ptr %27, i32 0, i32 1
  %29 = load i32, ptr %28, align 8, !tbaa !15
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds i8, ptr %26, i64 %30
  store ptr %31, ptr %12, align 8, !tbaa !5
  br label %32

32:                                               ; preds = %67, %22
  %33 = load ptr, ptr %11, align 8, !tbaa !5
  %34 = load ptr, ptr %12, align 8, !tbaa !5
  %35 = icmp ult ptr %33, %34
  br i1 %35, label %36, label %70

36:                                               ; preds = %32
  %37 = load ptr, ptr %11, align 8, !tbaa !5
  %38 = load i8, ptr %37, align 1, !tbaa !16
  %39 = zext i8 %38 to i64
  %40 = getelementptr inbounds [256 x i32], ptr @_PrintableString_alphabet, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !17
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %66, label %43

43:                                               ; preds = %36
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = icmp ne ptr %44, null
  br i1 %45, label %46, label %65

46:                                               ; preds = %43
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = load ptr, ptr %9, align 8, !tbaa !5
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.asn_TYPE_descriptor_s, ptr %51, i32 0, i32 0
  %53 = load ptr, ptr %52, align 8, !tbaa !18
  %54 = load ptr, ptr %11, align 8, !tbaa !5
  %55 = load ptr, ptr %10, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.OCTET_STRING, ptr %55, i32 0, i32 0
  %57 = load ptr, ptr %56, align 8, !tbaa !9
  %58 = ptrtoint ptr %54 to i64
  %59 = ptrtoint ptr %57 to i64
  %60 = sub i64 %58, %59
  %61 = add nsw i64 %60, 1
  %62 = load ptr, ptr %11, align 8, !tbaa !5
  %63 = load i8, ptr %62, align 1, !tbaa !16
  %64 = zext i8 %63 to i32
  call void (ptr, ptr, ptr, ptr, ...) %47(ptr noundef %48, ptr noundef %49, ptr noundef %50, ptr noundef @.str.1, ptr noundef %53, i64 noundef %61, i32 noundef %64, ptr noundef @.str.2, i32 noundef 131)
  br label %65

65:                                               ; preds = %46, %43
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %71

66:                                               ; preds = %36
  br label %67

67:                                               ; preds = %66
  %68 = load ptr, ptr %11, align 8, !tbaa !5
  %69 = getelementptr inbounds i8, ptr %68, i32 1
  store ptr %69, ptr %11, align 8, !tbaa !5
  br label %32, !llvm.loop !20

70:                                               ; preds = %32
  store i32 0, ptr %13, align 4
  br label %71

71:                                               ; preds = %70, %65
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  %72 = load i32, ptr %13, align 4
  switch i32 %72, label %87 [
    i32 0, label %73
  ]

73:                                               ; preds = %71
  br label %86

74:                                               ; preds = %17, %4
  %75 = load ptr, ptr %8, align 8, !tbaa !5
  %76 = icmp ne ptr %75, null
  br i1 %76, label %77, label %85

77:                                               ; preds = %74
  %78 = load ptr, ptr %8, align 8, !tbaa !5
  %79 = load ptr, ptr %9, align 8, !tbaa !5
  %80 = load ptr, ptr %6, align 8, !tbaa !5
  %81 = load ptr, ptr %7, align 8, !tbaa !5
  %82 = load ptr, ptr %6, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.asn_TYPE_descriptor_s, ptr %82, i32 0, i32 0
  %84 = load ptr, ptr %83, align 8, !tbaa !18
  call void (ptr, ptr, ptr, ptr, ...) %78(ptr noundef %79, ptr noundef %80, ptr noundef %81, ptr noundef @.str.3, ptr noundef %84, ptr noundef @.str.2, i32 noundef 138)
  br label %85

85:                                               ; preds = %77, %74
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %87

86:                                               ; preds = %73
  store i32 0, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %87

87:                                               ; preds = %86, %85, %71
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  %88 = load i32, ptr %5, align 4
  ret i32 %88
}

; 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

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, !6, i64 0}
!10 = !{!"OCTET_STRING", !6, i64 0, !11, i64 8, !12, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!"asn_struct_ctx_s", !13, i64 0, !13, i64 2, !11, i64 4, !6, i64 8, !14, i64 16}
!13 = !{!"short", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!10, !11, i64 8}
!16 = !{!7, !7, i64 0}
!17 = !{!11, !11, i64 0}
!18 = !{!19, !6, i64 0}
!19 = !{!"asn_TYPE_descriptor_s", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !11, i64 104, !6, i64 112, !11, i64 120, !6, i64 128, !6, i64 136, !11, i64 144, !6, i64 152}
!20 = distinct !{!20, !21}
!21 = !{!"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 [64 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [28 x i8], align 1
@_PrintableString_alphabet = external hidden local_unnamed_addr constant <{ [123 x i32], [133 x i32] }>, align 16

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

5:                                                ; preds = %4
  %6 = load ptr, ptr %1, align 8, !tbaa !5
  %.not32 = icmp eq ptr %6, null
  br i1 %.not32, label %25, label %7

7:                                                ; preds = %5
  %8 = getelementptr inbounds i8, ptr %1, i64 8
  %9 = load i32, ptr %8, align 8, !tbaa !14
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds i8, ptr %6, i64 %10
  %.not3640 = icmp sgt i32 %9, 0
  br i1 %.not3640, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %7, %23
  %.02741 = phi ptr [ %24, %23 ], [ %6, %7 ]
  %12 = load i8, ptr %.02741, align 1, !tbaa !15
  %13 = zext i8 %12 to i64
  %14 = getelementptr inbounds [256 x i32], ptr @_PrintableString_alphabet, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !16
  %.not34 = icmp eq i32 %15, 0
  br i1 %.not34, label %16, label %23

16:                                               ; preds = %.lr.ph
  %.not35 = icmp eq ptr %2, null
  br i1 %.not35, label %.loopexit, label %17

17:                                               ; preds = %16
  %18 = load ptr, ptr %0, align 8, !tbaa !17
  %19 = ptrtoint ptr %.02741 to i64
  %20 = ptrtoint ptr %6 to i64
  %reass.sub = sub i64 %19, %20
  %21 = add i64 %reass.sub, 1
  %22 = zext i8 %12 to i32
  tail call void (ptr, ptr, ptr, ptr, ...) %2(ptr noundef %3, ptr noundef nonnull %0, ptr noundef nonnull %1, ptr noundef nonnull @.str.1, ptr noundef %18, i64 noundef %21, i32 noundef %22, ptr noundef nonnull @.str.2, i32 noundef 131) #1
  br label %.loopexit

23:                                               ; preds = %.lr.ph
  %24 = getelementptr inbounds i8, ptr %.02741, i64 1
  %.not36 = icmp ult ptr %24, %11
  br i1 %.not36, label %.lr.ph, label %.loopexit, !llvm.loop !19

25:                                               ; preds = %5, %4
  %.not33 = icmp eq ptr %2, null
  br i1 %.not33, label %.loopexit, label %26

26:                                               ; preds = %25
  %27 = load ptr, ptr %0, align 8, !tbaa !17
  tail call void (ptr, ptr, ptr, ptr, ...) %2(ptr noundef %3, ptr noundef nonnull %0, ptr noundef %1, ptr noundef nonnull @.str.3, ptr noundef %27, ptr noundef nonnull @.str.2, i32 noundef 138) #1
  br label %.loopexit

.loopexit:                                        ; preds = %23, %17, %16, %7, %25, %26
  %.1 = phi i32 [ -1, %26 ], [ -1, %25 ], [ -1, %16 ], [ -1, %17 ], [ 0, %7 ], [ 0, %23 ]
  ret i32 %.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 = { 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, !7, i64 0}
!6 = !{!"OCTET_STRING", !7, i64 0, !10, i64 8, !11, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"asn_struct_ctx_s", !12, i64 0, !12, i64 2, !10, i64 4, !7, i64 8, !13, i64 16}
!12 = !{!"short", !8, i64 0}
!13 = !{!"long", !8, i64 0}
!14 = !{!6, !10, i64 8}
!15 = !{!8, !8, i64 0}
!16 = !{!10, !10, i64 0}
!17 = !{!18, !7, i64 0}
!18 = !{!"asn_TYPE_descriptor_s", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !7, i64 88, !7, i64 96, !10, i64 104, !7, i64 112, !10, i64 120, !7, i64 128, !7, i64 136, !10, i64 144, !7, i64 152}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


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