; LLVM IR from aws/s2n-tls :: tls/extensions (s2n_extension_type)

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

@s2n_extension_ianas_to_ids = external dso_local global [60 x i8], align 16
@s2n_supported_extensions = external hidden constant [21 x i16], align 16

; 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: nounwind uwtable
define dso_local zeroext i8 @s2n_extension_iana_value_to_id(i16 noundef zeroext %0) #1 {
  %2 = alloca i8, align 1
  %3 = alloca i16, align 2
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  store i16 %0, ptr %3, align 2, !tbaa !5
  %6 = load i16, ptr %3, align 2, !tbaa !5
  %7 = zext i16 %6 to i32
  %8 = icmp slt i32 %7, 60
  br i1 %8, label %9, label %14

9:                                                ; preds = %1
  %10 = load i16, ptr %3, align 2, !tbaa !5
  %11 = zext i16 %10 to i64
  %12 = getelementptr inbounds [60 x i8], ptr @s2n_extension_ianas_to_ids, i64 0, i64 %11
  %13 = load i8, ptr %12, align 1, !tbaa !9
  store i8 %13, ptr %2, align 1
  br label %37

14:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  store i64 0, ptr %4, align 8, !tbaa !10
  br label %15

15:                                               ; preds = %31, %14
  %16 = load i64, ptr %4, align 8, !tbaa !10
  %17 = icmp ult i64 %16, 21
  br i1 %17, label %19, label %18

18:                                               ; preds = %15
  store i32 2, ptr %5, align 4
  br label %34

19:                                               ; preds = %15
  %20 = load i64, ptr %4, align 8, !tbaa !10
  %21 = getelementptr inbounds [21 x i16], ptr @s2n_supported_extensions, i64 0, i64 %20
  %22 = load i16, ptr %21, align 2, !tbaa !5
  %23 = zext i16 %22 to i32
  %24 = load i16, ptr %3, align 2, !tbaa !5
  %25 = zext i16 %24 to i32
  %26 = icmp eq i32 %23, %25
  br i1 %26, label %27, label %30

27:                                               ; preds = %19
  %28 = load i64, ptr %4, align 8, !tbaa !10
  %29 = trunc i64 %28 to i8
  store i8 %29, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %34

30:                                               ; preds = %19
  br label %31

31:                                               ; preds = %30
  %32 = load i64, ptr %4, align 8, !tbaa !10
  %33 = add i64 %32, 1
  store i64 %33, ptr %4, align 8, !tbaa !10
  br label %15, !llvm.loop !12

34:                                               ; preds = %27, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  %35 = load i32, ptr %5, align 4
  switch i32 %35, label %39 [
    i32 2, label %36
    i32 1, label %37
  ]

36:                                               ; preds = %34
  store i8 21, ptr %2, align 1
  br label %37

37:                                               ; preds = %36, %34, %9
  %38 = load i8, ptr %2, align 1
  ret i8 %38

39:                                               ; preds = %34
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"long", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

@s2n_extension_ianas_to_ids = external dso_local local_unnamed_addr global [60 x i8], align 16
@s2n_supported_extensions = external hidden local_unnamed_addr constant [21 x i16], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) uwtable
define dso_local zeroext i8 @s2n_extension_iana_value_to_id(i16 noundef zeroext %0) local_unnamed_addr #0 {
  %2 = icmp ult i16 %0, 60
  br i1 %2, label %5, label %.preheader.preheader

.preheader.preheader:                             ; preds = %1
  %3 = load i16, ptr @s2n_supported_extensions, align 16, !tbaa !5
  %4 = icmp eq i16 %3, %0
  br i1 %4, label %.loopexit, label %.preheader.1

5:                                                ; preds = %1
  %6 = zext nneg i16 %0 to i64
  %7 = getelementptr inbounds [60 x i8], ptr @s2n_extension_ianas_to_ids, i64 0, i64 %6
  %8 = load i8, ptr %7, align 1, !tbaa !9
  br label %.loopexit

.preheader.1:                                     ; preds = %.preheader.preheader
  %9 = load i16, ptr getelementptr inbounds (i8, ptr @s2n_supported_extensions, i64 2), align 2, !tbaa !5
  %10 = icmp eq i16 %9, %0
  br i1 %10, label %.loopexit, label %.preheader.2

.preheader.2:                                     ; preds = %.preheader.1
  %11 = load i16, ptr getelementptr inbounds (i8, ptr @s2n_supported_extensions, i64 4), align 4, !tbaa !5
  %12 = icmp eq i16 %11, %0
  br i1 %12, label %.loopexit, label %.preheader.3

.preheader.3:                                     ; preds = %.preheader.2
  %13 = load i16, ptr getelementptr inbounds (i8, ptr @s2n_supported_extensions, i64 6), align 2, !tbaa !5
  %14 = icmp eq i16 %13, %0
  br i1 %14, label %.loopexit, label %.preheader.4

.preheader.4:                                     ; preds = %.preheader.3
  %15 = load i16, ptr getelementptr inbounds (i8, ptr @s2n_supported_extensions, i64 8), align 8, !tbaa !5
  %16 = icmp eq i16 %15, %0
  br i1 %16, label %.loopexit, label %.preheader.5

.preheader.5:                                     ; preds = %.preheader.4
  %17 = load i16, ptr getelementptr inbounds (i8, ptr @s2n_supported_extensions, i64 10), align 2, !tbaa !5
  %18 = icmp eq i16 %17, %0
  br i1 %18, label %.loopexit, label %.preheader.6

.preheader.6:                                     ; preds = %.preheader.5
  %19 = load i16, ptr getelementptr inbounds (i8, ptr @s2n_supported_extensions, i64 12), align 4, !tbaa !5
  %20 = icmp eq i16 %19, %0
  br i1 %20, label %.loopexit, label %.preheader.7

.preheader.7:                                     ; preds = %.preheader.6
  %21 = load i16, ptr getelementptr inbounds (i8, ptr @s2n_supported_extensions, i64 14), align 2, !tbaa !5
  %22 = icmp eq i16 %21, %0
  br i1 %22, label %.loopexit, label %.preheader.8

.preheader.8:                                     ; preds = %.preheader.7
  %23 = load i16, ptr getelementptr inbounds (i8, ptr @s2n_supported_extensions, i64 16), align 16, !tbaa !5
  %24 = icmp eq i16 %23, %0
  br i1 %24, label %.loopexit, label %.preheader.9

.preheader.9:                                     ; preds = %.preheader.8
  %25 = load i16, ptr getelementptr inbounds (i8, ptr @s2n_supported_extensions, i64 18), align 2, !tbaa !5
  %26 = icmp eq i16 %25, %0
  br i1 %26, label %.loopexit, label %.preheader.10

.preheader.10:                                    ; preds = %.preheader.9
  %27 = load i16, ptr getelementptr inbounds (i8, ptr @s2n_supported_extensions, i64 20), align 4, !tbaa !5
  %28 = icmp eq i16 %27, %0
  br i1 %28, label %.loopexit, label %.preheader.11

.preheader.11:                                    ; preds = %.preheader.10
  %29 = load i16, ptr getelementptr inbounds (i8, ptr @s2n_supported_extensions, i64 22), align 2, !tbaa !5
  %30 = icmp eq i16 %29, %0
  br i1 %30, label %.loopexit, label %.preheader.12

.preheader.12:                                    ; preds = %.preheader.11
  %31 = load i16, ptr getelementptr inbounds (i8, ptr @s2n_supported_extensions, i64 24), align 8, !tbaa !5
  %32 = icmp eq i16 %31, %0
  br i1 %32, label %.loopexit, label %.preheader.13

.preheader.13:                                    ; preds = %.preheader.12
  %33 = load i16, ptr getelementptr inbounds (i8, ptr @s2n_supported_extensions, i64 26), align 2, !tbaa !5
  %34 = icmp eq i16 %33, %0
  br i1 %34, label %.loopexit, label %.preheader.14

.preheader.14:                                    ; preds = %.preheader.13
  %35 = load i16, ptr getelementptr inbounds (i8, ptr @s2n_supported_extensions, i64 28), align 4, !tbaa !5
  %36 = icmp eq i16 %35, %0
  br i1 %36, label %.loopexit, label %.preheader.15

.preheader.15:                                    ; preds = %.preheader.14
  %37 = load i16, ptr getelementptr inbounds (i8, ptr @s2n_supported_extensions, i64 30), align 2, !tbaa !5
  %38 = icmp eq i16 %37, %0
  br i1 %38, label %.loopexit, label %.preheader.16

.preheader.16:                                    ; preds = %.preheader.15
  %39 = load i16, ptr getelementptr inbounds (i8, ptr @s2n_supported_extensions, i64 32), align 16, !tbaa !5
  %40 = icmp eq i16 %39, %0
  br i1 %40, label %.loopexit, label %.preheader.17

.preheader.17:                                    ; preds = %.preheader.16
  %41 = load i16, ptr getelementptr inbounds (i8, ptr @s2n_supported_extensions, i64 34), align 2, !tbaa !5
  %42 = icmp eq i16 %41, %0
  br i1 %42, label %.loopexit, label %.preheader.18

.preheader.18:                                    ; preds = %.preheader.17
  %43 = load i16, ptr getelementptr inbounds (i8, ptr @s2n_supported_extensions, i64 36), align 4, !tbaa !5
  %44 = icmp eq i16 %43, %0
  br i1 %44, label %.loopexit, label %.preheader.19

.preheader.19:                                    ; preds = %.preheader.18
  %45 = load i16, ptr getelementptr inbounds (i8, ptr @s2n_supported_extensions, i64 38), align 2, !tbaa !5
  %46 = icmp eq i16 %45, %0
  br i1 %46, label %.loopexit, label %.preheader.20

.preheader.20:                                    ; preds = %.preheader.19
  %47 = load i16, ptr getelementptr inbounds (i8, ptr @s2n_supported_extensions, i64 40), align 8, !tbaa !5
  %48 = icmp eq i16 %47, %0
  %spec.select = select i1 %48, i8 20, i8 21
  br label %.loopexit

.loopexit:                                        ; preds = %.preheader.20, %.preheader.preheader, %.preheader.1, %.preheader.2, %.preheader.3, %.preheader.4, %.preheader.5, %.preheader.6, %.preheader.7, %.preheader.8, %.preheader.9, %.preheader.10, %.preheader.11, %.preheader.12, %.preheader.13, %.preheader.14, %.preheader.15, %.preheader.16, %.preheader.17, %.preheader.18, %.preheader.19, %5
  %.1 = phi i8 [ %8, %5 ], [ 0, %.preheader.preheader ], [ 1, %.preheader.1 ], [ 2, %.preheader.2 ], [ 3, %.preheader.3 ], [ 4, %.preheader.4 ], [ 5, %.preheader.5 ], [ 6, %.preheader.6 ], [ 7, %.preheader.7 ], [ 8, %.preheader.8 ], [ 9, %.preheader.9 ], [ 10, %.preheader.10 ], [ 11, %.preheader.11 ], [ 12, %.preheader.12 ], [ 13, %.preheader.13 ], [ 14, %.preheader.14 ], [ 15, %.preheader.15 ], [ 16, %.preheader.16 ], [ 17, %.preheader.17 ], [ 18, %.preheader.18 ], [ 19, %.preheader.19 ], [ %spec.select, %.preheader.20 ]
  ret i8 %.1
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) 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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass