; 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_kem_preferences = type { i8, ptr, i8, ptr, 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_pq_extension(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @s2n_pq_kem_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 %91

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 = %39, %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 %42

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 %38

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 = lshr i8 %33, 1
  %35 = and i8 %34, 1
  %36 = zext i8 %35 to i32
  %37 = icmp eq i32 1, %36
  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 i32, ptr %4, align 4, !tbaa !9
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %4, align 4, !tbaa !9
  br label %12, !llvm.loop !14

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

44:                                               ; preds = %42
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.s2n_security_policy, ptr %45, i32 0, i32 2
  %47 = load ptr, ptr %46, align 8, !tbaa !16
  %48 = icmp ne ptr %47, null
  br i1 %48, label %49, label %58

49:                                               ; preds = %44
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.s2n_security_policy, ptr %50, i32 0, i32 2
  %52 = load ptr, ptr %51, align 8, !tbaa !16
  %53 = getelementptr inbounds %struct.s2n_kem_preferences, ptr %52, i32 0, i32 0
  %54 = load i8, ptr %53, align 8, !tbaa !19
  %55 = zext i8 %54 to i32
  %56 = icmp eq i32 %55, 0
  br i1 %56, label %57, label %58

57:                                               ; preds = %49
  store i1 false, ptr %2, align 1
  br label %91

58:                                               ; preds = %49, %44
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.s2n_security_policy, ptr %59, i32 0, i32 1
  %61 = load ptr, ptr %60, align 8, !tbaa !21
  store ptr %61, ptr %6, align 8, !tbaa !5
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = icmp eq ptr %62, null
  br i1 %63, label %64, label %65

64:                                               ; preds = %58
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %90

65:                                               ; preds = %58
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store i64 0, ptr %7, align 8, !tbaa !22
  br label %66

66:                                               ; preds = %84, %65
  %67 = load i64, ptr %7, align 8, !tbaa !22
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.s2n_cipher_preferences, ptr %68, i32 0, i32 0
  %70 = load i16, ptr %69, align 8, !tbaa !24
  %71 = zext i16 %70 to i64
  %72 = icmp ult i64 %67, %71
  br i1 %72, label %74, label %73

73:                                               ; preds = %66
  store i32 5, ptr %5, align 4
  br label %87

74:                                               ; preds = %66
  %75 = load ptr, ptr %6, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.s2n_cipher_preferences, ptr %75, i32 0, i32 1
  %77 = load ptr, ptr %76, align 8, !tbaa !27
  %78 = load i64, ptr %7, align 8, !tbaa !22
  %79 = getelementptr inbounds ptr, ptr %77, i64 %78
  %80 = load ptr, ptr %79, align 8, !tbaa !5
  %81 = call zeroext i1 @s2n_cipher_suite_requires_pq_extension(ptr noundef %80)
  br i1 %81, label %82, label %83

82:                                               ; preds = %74
  store i1 true, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %87

83:                                               ; preds = %74
  br label %84

84:                                               ; preds = %83
  %85 = load i64, ptr %7, align 8, !tbaa !22
  %86 = add i64 %85, 1
  store i64 %86, ptr %7, align 8, !tbaa !22
  br label %66, !llvm.loop !28

87:                                               ; preds = %82, %73
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  %88 = load i32, ptr %5, align 4
  switch i32 %88, label %90 [
    i32 5, label %89
  ]

89:                                               ; preds = %87
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %90

90:                                               ; preds = %89, %87, %64
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %91

91:                                               ; preds = %90, %57, %42, %10
  %92 = load i1, ptr %2, align 1
  ret i1 %92

93:                                               ; preds = %42
  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 16}
!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, !7, i64 0}
!20 = !{!"s2n_kem_preferences", !7, i64 0, !6, i64 8, !7, i64 16, !6, i64 24, !7, i64 32}
!21 = !{!17, !6, i64 8}
!22 = !{!23, !23, i64 0}
!23 = !{!"long", !7, i64 0}
!24 = !{!25, !26, i64 0}
!25 = !{!"s2n_cipher_preferences", !26, i64 0, !6, i64 8, !18, i64 16}
!26 = !{!"short", !7, i64 0}
!27 = !{!25, !6, i64 8}
!28 = distinct !{!28, !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_pq_extension(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @s2n_pq_kem_is_extension_required(ptr noundef readonly %0) local_unnamed_addr #1 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %.loopexit, label %.preheader31

.preheader31:                                     ; preds = %1
  %3 = load ptr, ptr @security_policy_selection, align 16, !tbaa !5
  %.not33 = icmp eq ptr %3, null
  br i1 %.not33, 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 = %.preheader31, %4
  %indvars.iv = phi i64 [ %indvars.iv.next, %4 ], [ 0, %.preheader31 ]
  %7 = phi ptr [ %5, %4 ], [ @security_policy_selection, %.preheader31 ]
  %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, 2
  %15 = icmp ne i8 %14, 0
  br label %.loopexit

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

18:                                               ; preds = %._crit_edge
  %19 = load i8, ptr %17, align 8, !tbaa !17
  %20 = icmp eq i8 %19, 0
  br i1 %20, label %.loopexit, label %21

21:                                               ; preds = %18, %._crit_edge
  %22 = getelementptr inbounds i8, ptr %0, i64 8
  %23 = load ptr, ptr %22, align 8, !tbaa !19
  %24 = icmp eq ptr %23, null
  br i1 %24, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %21
  %25 = load i16, ptr %23, align 8, !tbaa !20
  %.not2535.not = icmp eq i16 %25, 0
  br i1 %.not2535.not, label %.loopexit, label %.lr.ph37

.lr.ph37:                                         ; preds = %.preheader
  %26 = getelementptr inbounds i8, ptr %23, i64 8
  br label %31

27:                                               ; preds = %31
  %28 = add nuw nsw i64 %.036, 1
  %29 = load i16, ptr %23, align 8, !tbaa !20
  %30 = zext i16 %29 to i64
  %.not25 = icmp ult i64 %28, %30
  br i1 %.not25, label %31, label %.loopexit, !llvm.loop !23

31:                                               ; preds = %.lr.ph37, %27
  %.036 = phi i64 [ 0, %.lr.ph37 ], [ %28, %27 ]
  %32 = load ptr, ptr %26, align 8, !tbaa !24
  %33 = getelementptr inbounds ptr, ptr %32, i64 %.036
  %34 = load ptr, ptr %33, align 8, !tbaa !25
  %35 = tail call zeroext i1 @s2n_cipher_suite_requires_pq_extension(ptr noundef %34) #2
  br i1 %35, label %.loopexit, label %27

.loopexit:                                        ; preds = %31, %27, %.preheader, %11, %21, %18, %1
  %.3 = phi i1 [ %15, %11 ], [ false, %1 ], [ false, %18 ], [ false, %21 ], [ false, %.preheader ], [ %35, %27 ], [ %35, %31 ]
  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 16}
!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, !8, i64 0}
!18 = !{!"s2n_kem_preferences", !8, i64 0, !7, i64 8, !8, i64 16, !7, i64 24, !8, i64 32}
!19 = !{!15, !7, i64 8}
!20 = !{!21, !22, i64 0}
!21 = !{!"s2n_cipher_preferences", !22, i64 0, !7, i64 8, !16, i64 16}
!22 = !{!"short", !8, i64 0}
!23 = distinct !{!23, !12}
!24 = !{!21, !7, i64 8}
!25 = !{!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