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

@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

declare zeroext i1 @s2n_cipher_suite_requires_ecc_extension(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @s2n_ecc_is_extension_required(ptr noundef %0) #2 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %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 %76

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

12:                                               ; preds = %38, %11
  %13 = load i32, ptr %4, align 4, !tbaa !9
  %14 = sext i32 %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 !11
  %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 %41

20:                                               ; preds = %12
  %21 = load i32, ptr %4, align 4, !tbaa !9
  %22 = sext i32 %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 %37

28:                                               ; preds = %20
  %29 = load i32, ptr %4, align 4, !tbaa !9
  %30 = sext i32 %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 = and i8 %33, 1
  %35 = zext i8 %34 to i32
  %36 = icmp eq i32 1, %35
  store i1 %36, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %41

37:                                               ; preds = %20
  br label %38

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

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

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

49:                                               ; preds = %43
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %75

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

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

58:                                               ; preds = %51
  store i32 5, ptr %5, align 4
  br label %72

59:                                               ; preds = %51
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.s2n_cipher_preferences, ptr %60, i32 0, i32 1
  %62 = load ptr, ptr %61, align 8, !tbaa !24
  %63 = load i64, ptr %7, align 8, !tbaa !19
  %64 = getelementptr inbounds ptr, ptr %62, i64 %63
  %65 = load ptr, ptr %64, align 8, !tbaa !5
  %66 = call zeroext i1 @s2n_cipher_suite_requires_ecc_extension(ptr noundef %65)
  br i1 %66, label %67, label %68

67:                                               ; preds = %59
  store i1 true, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %72

68:                                               ; preds = %59
  br label %69

69:                                               ; preds = %68
  %70 = load i64, ptr %7, align 8, !tbaa !19
  %71 = add i64 %70, 1
  store i64 %71, ptr %7, align 8, !tbaa !19
  br label %51, !llvm.loop !25

72:                                               ; preds = %67, %58
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  %73 = load i32, ptr %5, align 4
  switch i32 %73, label %75 [
    i32 5, label %74
  ]

74:                                               ; preds = %72
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %75

75:                                               ; preds = %74, %72, %49
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %76

76:                                               ; preds = %75, %41, %10
  %77 = load i1, ptr %2, align 1
  ret i1 %77

78:                                               ; preds = %41
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 #3 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"s2n_security_policy_selection", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 16, !10, i64 16}
!13 = !{!12, !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 = distinct !{!25, !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

declare zeroext i1 @s2n_cipher_suite_requires_ecc_extension(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @s2n_ecc_is_extension_required(ptr noundef readonly %0) local_unnamed_addr #1 {
  %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
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %5 = getelementptr inbounds [119 x %struct.s2n_security_policy_selection], ptr @security_policy_selection, i64 0, i64 %indvars.iv.next
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11

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

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

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

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

.lr.ph33:                                         ; preds = %.preheader
  %20 = getelementptr inbounds i8, ptr %17, i64 8
  br label %25

21:                                               ; preds = %25
  %22 = add nuw nsw i64 %.032, 1
  %23 = load i16, ptr %17, align 8, !tbaa !17
  %24 = zext i16 %23 to i64
  %.not21 = icmp ult i64 %22, %24
  br i1 %.not21, label %25, label %.loopexit, !llvm.loop !20

25:                                               ; preds = %.lr.ph33, %21
  %.032 = phi i64 [ 0, %.lr.ph33 ], [ %22, %21 ]
  %26 = load ptr, ptr %20, align 8, !tbaa !21
  %27 = getelementptr inbounds ptr, ptr %26, i64 %.032
  %28 = load ptr, ptr %27, align 8, !tbaa !22
  %29 = tail call zeroext i1 @s2n_cipher_suite_requires_ecc_extension(ptr noundef %28) #2
  br i1 %29, label %.loopexit, label %21

.loopexit:                                        ; preds = %25, %21, %.preheader, %11, %._crit_edge, %1
  %.3 = phi i1 [ %15, %11 ], [ false, %1 ], [ false, %._crit_edge ], [ false, %.preheader ], [ %29, %21 ], [ %29, %25 ]
  ret i1 %.3
}

attributes #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 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, !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 = distinct !{!20, !12}
!21 = !{!18, !7, i64 8}
!22 = !{!7, !7, i64 0}


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