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

; 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.s2n_security_policy_selection = type { ptr, ptr, i8 }
%struct.s2n_security_policy = type { i8, ptr, ptr, ptr, ptr, ptr, ptr, i8, [2 x i8] }
%struct.s2n_cipher_preferences = type { i16, ptr, i8 }
%struct.s2n_cipher_suite = type { i8, ptr, ptr, [2 x i8], ptr, i32, ptr, [2 x ptr], i8, ptr, ptr, i32, i8 }

@security_policy_selection = external dso_local global [119 x %struct.s2n_security_policy_selection], 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 i1 @s2n_security_policy_supports_tls13(ptr noundef %0) #1 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = icmp eq ptr %8, null
  br i1 %9, label %10, label %11

10:                                               ; preds = %1
  store i1 false, ptr %2, align 1
  br label %80

11:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #2
  store i8 0, ptr %4, align 1, !tbaa !9
  br label %12

12:                                               ; preds = %39, %11
  %13 = load i8, ptr %4, align 1, !tbaa !9
  %14 = zext i8 %13 to i64
  %15 = getelementptr inbounds [119 x %struct.s2n_security_policy_selection], ptr @security_policy_selection, i64 0, i64 %14
  %16 = getelementptr inbounds %struct.s2n_security_policy_selection, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !10
  %18 = icmp ne ptr %17, null
  br i1 %18, label %20, label %19

19:                                               ; preds = %12
  store i32 2, ptr %5, align 4
  br label %42

20:                                               ; preds = %12
  %21 = load i8, ptr %4, align 1, !tbaa !9
  %22 = zext i8 %21 to i64
  %23 = getelementptr inbounds [119 x %struct.s2n_security_policy_selection], ptr @security_policy_selection, i64 0, i64 %22
  %24 = getelementptr inbounds %struct.s2n_security_policy_selection, ptr %23, i32 0, i32 1
  %25 = load ptr, ptr %24, align 8, !tbaa !13
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = icmp eq ptr %25, %26
  br i1 %27, label %28, label %38

28:                                               ; preds = %20
  %29 = load i8, ptr %4, align 1, !tbaa !9
  %30 = zext i8 %29 to i64
  %31 = getelementptr inbounds [119 x %struct.s2n_security_policy_selection], ptr @security_policy_selection, i64 0, i64 %30
  %32 = getelementptr inbounds %struct.s2n_security_policy_selection, ptr %31, i32 0, i32 2
  %33 = load i8, ptr %32, align 8
  %34 = lshr i8 %33, 2
  %35 = and i8 %34, 1
  %36 = zext i8 %35 to i32
  %37 = icmp eq i32 %36, 1
  store i1 %37, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %42

38:                                               ; preds = %20
  br label %39

39:                                               ; preds = %38
  %40 = load i8, ptr %4, align 1, !tbaa !9
  %41 = add i8 %40, 1
  store i8 %41, ptr %4, align 1, !tbaa !9
  br label %12, !llvm.loop !14

42:                                               ; preds = %28, %19
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #2
  %43 = load i32, ptr %5, align 4
  switch i32 %43, label %82 [
    i32 2, label %44
    i32 1, label %80
  ]

44:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.s2n_security_policy, ptr %45, i32 0, i32 1
  %47 = load ptr, ptr %46, align 8, !tbaa !16
  store ptr %47, ptr %6, align 8, !tbaa !5
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = icmp eq ptr %48, null
  br i1 %49, label %50, label %51

50:                                               ; preds = %44
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %79

51:                                               ; preds = %44
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  store i64 0, ptr %7, align 8, !tbaa !19
  br label %52

52:                                               ; preds = %73, %51
  %53 = load i64, ptr %7, align 8, !tbaa !19
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.s2n_cipher_preferences, ptr %54, i32 0, i32 0
  %56 = load i16, ptr %55, align 8, !tbaa !21
  %57 = zext i16 %56 to i64
  %58 = icmp ult i64 %53, %57
  br i1 %58, label %60, label %59

59:                                               ; preds = %52
  store i32 5, ptr %5, align 4
  br label %76

60:                                               ; preds = %52
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.s2n_cipher_preferences, ptr %61, i32 0, i32 1
  %63 = load ptr, ptr %62, align 8, !tbaa !24
  %64 = load i64, ptr %7, align 8, !tbaa !19
  %65 = getelementptr inbounds ptr, ptr %63, i64 %64
  %66 = load ptr, ptr %65, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.s2n_cipher_suite, ptr %66, i32 0, i32 12
  %68 = load i8, ptr %67, align 4, !tbaa !25
  %69 = zext i8 %68 to i32
  %70 = icmp sge i32 %69, 34
  br i1 %70, label %71, label %72

71:                                               ; preds = %60
  store i1 true, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %76

72:                                               ; preds = %60
  br label %73

73:                                               ; preds = %72
  %74 = load i64, ptr %7, align 8, !tbaa !19
  %75 = add i64 %74, 1
  store i64 %75, ptr %7, align 8, !tbaa !19
  br label %52, !llvm.loop !27

76:                                               ; preds = %71, %59
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  %77 = load i32, ptr %5, align 4
  switch i32 %77, label %79 [
    i32 5, label %78
  ]

78:                                               ; preds = %76
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %79

79:                                               ; preds = %78, %76, %50
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %80

80:                                               ; preds = %79, %42, %10
  %81 = load i1, ptr %2, align 1
  ret i1 %81

82:                                               ; preds = %42
  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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !6, i64 0}
!11 = !{!"s2n_security_policy_selection", !6, i64 0, !6, i64 8, !12, i64 16, !12, i64 16, !12, i64 16}
!12 = !{!"int", !7, i64 0}
!13 = !{!11, !6, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!17, !6, i64 8}
!17 = !{!"s2n_security_policy", !7, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !18, i64 56, !7, i64 57}
!18 = !{!"_Bool", !7, i64 0}
!19 = !{!20, !20, i64 0}
!20 = !{!"long", !7, i64 0}
!21 = !{!22, !23, i64 0}
!22 = !{!"s2n_cipher_preferences", !23, i64 0, !6, i64 8, !18, i64 16}
!23 = !{!"short", !7, i64 0}
!24 = !{!22, !6, i64 8}
!25 = !{!26, !7, i64 100}
!26 = !{!"s2n_cipher_suite", !12, i64 0, !6, i64 8, !6, i64 16, !7, i64 24, !6, i64 32, !12, i64 40, !6, i64 48, !7, i64 56, !7, i64 72, !6, i64 80, !6, i64 88, !12, i64 96, !7, i64 100}
!27 = distinct !{!27, !15}


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

%struct.s2n_security_policy_selection = type { ptr, ptr, i8 }

@security_policy_selection = external dso_local local_unnamed_addr global [119 x %struct.s2n_security_policy_selection], align 16

; Function Attrs: nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local zeroext i1 @s2n_security_policy_supports_tls13(ptr noundef readonly %0) local_unnamed_addr #0 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %.loopexit, label %.preheader27

.preheader27:                                     ; preds = %1
  %3 = load ptr, ptr @security_policy_selection, align 16, !tbaa !5
  %.not29 = icmp eq ptr %3, null
  br i1 %.not29, label %._crit_edge, label %.lr.ph

4:                                                ; preds = %.lr.ph
  %5 = add i8 %.01830, 1
  %6 = zext i8 %5 to i64
  %7 = getelementptr inbounds [119 x %struct.s2n_security_policy_selection], ptr @security_policy_selection, i64 0, i64 %6
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %.not = icmp eq ptr %8, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11

.lr.ph:                                           ; preds = %.preheader27, %4
  %9 = phi ptr [ %7, %4 ], [ @security_policy_selection, %.preheader27 ]
  %.01830 = phi i8 [ %5, %4 ], [ 0, %.preheader27 ]
  %10 = getelementptr inbounds i8, ptr %9, i64 8
  %11 = load ptr, ptr %10, align 8, !tbaa !13
  %12 = icmp eq ptr %11, %0
  br i1 %12, label %13, label %4

13:                                               ; preds = %.lr.ph
  %14 = getelementptr inbounds i8, ptr %9, i64 16
  %15 = load i8, ptr %14, align 8
  %16 = and i8 %15, 4
  %17 = icmp ne i8 %16, 0
  br label %.loopexit

._crit_edge:                                      ; preds = %4, %.preheader27
  %18 = getelementptr inbounds i8, ptr %0, i64 8
  %19 = load ptr, ptr %18, align 8, !tbaa !14
  %20 = icmp eq ptr %19, null
  br i1 %20, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %._crit_edge
  %21 = load i16, ptr %19, align 8, !tbaa !17
  %22 = zext i16 %21 to i64
  %.not2131.not = icmp eq i16 %21, 0
  br i1 %.not2131.not, label %.loopexit, label %.lr.ph33

.lr.ph33:                                         ; preds = %.preheader
  %23 = getelementptr inbounds i8, ptr %19, i64 8
  %24 = load ptr, ptr %23, align 8, !tbaa !20
  br label %25

25:                                               ; preds = %25, %.lr.ph33
  %.032 = phi i64 [ 0, %.lr.ph33 ], [ %31, %25 ]
  %26 = getelementptr inbounds ptr, ptr %24, i64 %.032
  %27 = load ptr, ptr %26, align 8, !tbaa !21
  %28 = getelementptr inbounds i8, ptr %27, i64 100
  %29 = load i8, ptr %28, align 4, !tbaa !22
  %30 = icmp ugt i8 %29, 33
  %31 = add nuw nsw i64 %.032, 1
  %exitcond.not = icmp eq i64 %31, %22
  %or.cond = select i1 %30, i1 true, i1 %exitcond.not
  br i1 %or.cond, label %.loopexit, label %25, !llvm.loop !24

.loopexit:                                        ; preds = %25, %.preheader, %13, %._crit_edge, %1
  %.3 = phi i1 [ %17, %13 ], [ false, %1 ], [ false, %._crit_edge ], [ false, %.preheader ], [ %30, %25 ]
  ret i1 %.3
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, 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, !7, i64 0}
!6 = !{!"s2n_security_policy_selection", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 16, !10, 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!6, !7, i64 8}
!14 = !{!15, !7, i64 8}
!15 = !{!"s2n_security_policy", !8, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !16, i64 56, !8, i64 57}
!16 = !{!"_Bool", !8, i64 0}
!17 = !{!18, !19, i64 0}
!18 = !{!"s2n_cipher_preferences", !19, i64 0, !7, i64 8, !16, i64 16}
!19 = !{!"short", !8, i64 0}
!20 = !{!18, !7, i64 8}
!21 = !{!7, !7, i64 0}
!22 = !{!23, !8, i64 100}
!23 = !{!"s2n_cipher_suite", !10, i64 0, !7, i64 8, !7, i64 16, !8, i64 24, !7, i64 32, !10, i64 40, !7, i64 48, !8, i64 56, !8, i64 72, !7, i64 80, !7, i64 88, !10, i64 96, !8, i64 100}
!24 = distinct !{!24, !12}


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