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

; 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_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 [20 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [44 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [39 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @UTF8String_constraint(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %10 = load ptr, ptr %6, align 8, !tbaa !5
  %11 = call i64 @UTF8String_length(ptr noundef %10)
  store i64 %11, ptr %9, align 8, !tbaa !9
  %12 = load i64, ptr %9, align 8, !tbaa !9
  switch i64 %12, label %73 [
    i64 -5, label %13
    i64 -1, label %25
    i64 -2, label %37
    i64 -3, label %49
    i64 -4, label %61
  ]

13:                                               ; preds = %4
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %24

16:                                               ; preds = %13
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.asn_TYPE_descriptor_s, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !11
  call void (ptr, ptr, ptr, ptr, ...) %17(ptr noundef %18, ptr noundef %19, ptr noundef %20, ptr noundef @.str.1, ptr noundef %23)
  br label %24

24:                                               ; preds = %16, %13
  br label %73

25:                                               ; preds = %4
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = icmp ne ptr %26, null
  br i1 %27, label %28, label %36

28:                                               ; preds = %25
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.asn_TYPE_descriptor_s, ptr %33, i32 0, i32 0
  %35 = load ptr, ptr %34, align 8, !tbaa !11
  call void (ptr, ptr, ptr, ptr, ...) %29(ptr noundef %30, ptr noundef %31, ptr noundef %32, ptr noundef @.str.2, ptr noundef %35, ptr noundef @.str.3, i32 noundef 115)
  br label %36

36:                                               ; preds = %28, %25
  br label %73

37:                                               ; preds = %4
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = icmp ne ptr %38, null
  br i1 %39, label %40, label %48

40:                                               ; preds = %37
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.asn_TYPE_descriptor_s, ptr %45, i32 0, i32 0
  %47 = load ptr, ptr %46, align 8, !tbaa !11
  call void (ptr, ptr, ptr, ptr, ...) %41(ptr noundef %42, ptr noundef %43, ptr noundef %44, ptr noundef @.str.4, ptr noundef %47, ptr noundef @.str.3, i32 noundef 120)
  br label %48

48:                                               ; preds = %40, %37
  br label %73

49:                                               ; preds = %4
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = icmp ne ptr %50, null
  br i1 %51, label %52, label %60

52:                                               ; preds = %49
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.asn_TYPE_descriptor_s, ptr %57, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !11
  call void (ptr, ptr, ptr, ptr, ...) %53(ptr noundef %54, ptr noundef %55, ptr noundef %56, ptr noundef @.str.5, ptr noundef %59, ptr noundef @.str.3, i32 noundef 125)
  br label %60

60:                                               ; preds = %52, %49
  br label %73

61:                                               ; preds = %4
  %62 = load ptr, ptr %7, align 8, !tbaa !5
  %63 = icmp ne ptr %62, null
  br i1 %63, label %64, label %72

64:                                               ; preds = %61
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.asn_TYPE_descriptor_s, ptr %69, i32 0, i32 0
  %71 = load ptr, ptr %70, align 8, !tbaa !11
  call void (ptr, ptr, ptr, ptr, ...) %65(ptr noundef %66, ptr noundef %67, ptr noundef %68, ptr noundef @.str.6, ptr noundef %71, ptr noundef @.str.3, i32 noundef 130)
  br label %72

72:                                               ; preds = %64, %61
  br label %73

73:                                               ; preds = %72, %60, %48, %36, %24, %4
  %74 = load i64, ptr %9, align 8, !tbaa !9
  %75 = icmp slt i64 %74, 0
  %76 = zext i1 %75 to i64
  %77 = select i1 %75, i32 -1, i32 0
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  ret i32 %77
}

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

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

; 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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"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, !13, i64 104, !6, i64 112, !13, i64 120, !6, i64 128, !6, i64 136, !13, i64 144, !6, i64 152}
!13 = !{!"int", !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"

@.str.1 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [44 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [39 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @UTF8String_constraint(ptr noundef %0, ptr noundef %1, ptr noundef readonly %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = tail call i64 @UTF8String_length(ptr noundef %1)
  switch i64 %5, label %21 [
    i64 -5, label %6
    i64 -1, label %9
    i64 -2, label %12
    i64 -3, label %15
    i64 -4, label %18
  ]

6:                                                ; preds = %4
  %.not35 = icmp eq ptr %2, null
  br i1 %.not35, label %21, label %7

7:                                                ; preds = %6
  %8 = load ptr, ptr %0, align 8, !tbaa !5
  tail call void (ptr, ptr, ptr, ptr, ...) %2(ptr noundef %3, ptr noundef nonnull %0, ptr noundef %1, ptr noundef nonnull @.str.1, ptr noundef %8) #1
  br label %21

9:                                                ; preds = %4
  %.not34 = icmp eq ptr %2, null
  br i1 %.not34, label %21, label %10

10:                                               ; preds = %9
  %11 = load ptr, ptr %0, align 8, !tbaa !5
  tail call void (ptr, ptr, ptr, ptr, ...) %2(ptr noundef %3, ptr noundef nonnull %0, ptr noundef %1, ptr noundef nonnull @.str.2, ptr noundef %11, ptr noundef nonnull @.str.3, i32 noundef 115) #1
  br label %21

12:                                               ; preds = %4
  %.not33 = icmp eq ptr %2, null
  br i1 %.not33, label %21, label %13

13:                                               ; preds = %12
  %14 = load ptr, ptr %0, align 8, !tbaa !5
  tail call void (ptr, ptr, ptr, ptr, ...) %2(ptr noundef %3, ptr noundef nonnull %0, ptr noundef %1, ptr noundef nonnull @.str.4, ptr noundef %14, ptr noundef nonnull @.str.3, i32 noundef 120) #1
  br label %21

15:                                               ; preds = %4
  %.not32 = icmp eq ptr %2, null
  br i1 %.not32, label %21, label %16

16:                                               ; preds = %15
  %17 = load ptr, ptr %0, align 8, !tbaa !5
  tail call void (ptr, ptr, ptr, ptr, ...) %2(ptr noundef %3, ptr noundef nonnull %0, ptr noundef %1, ptr noundef nonnull @.str.5, ptr noundef %17, ptr noundef nonnull @.str.3, i32 noundef 125) #1
  br label %21

18:                                               ; preds = %4
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %21, label %19

19:                                               ; preds = %18
  %20 = load ptr, ptr %0, align 8, !tbaa !5
  tail call void (ptr, ptr, ptr, ptr, ...) %2(ptr noundef %3, ptr noundef nonnull %0, ptr noundef %1, ptr noundef nonnull @.str.6, ptr noundef %20, ptr noundef nonnull @.str.3, i32 noundef 130) #1
  br label %21

21:                                               ; preds = %18, %19, %15, %16, %12, %13, %9, %10, %6, %7, %4
  %.lobit = ashr i64 %5, 63
  %22 = trunc nsw i64 %.lobit to i32
  ret i32 %22
}

; Function Attrs: nounwind uwtable
declare dso_local i64 @UTF8String_length(ptr noundef) local_unnamed_addr #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" }
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 = !{!"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}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}


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