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

; 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_debug_info = type { ptr, ptr }
%struct.s2n_result = type { i32 }
%struct.s2n_kem_group = type { ptr, i16, ptr, ptr, i8 }

@_s2n_debug_info = external thread_local global %struct.s2n_debug_info, align 8
@s2n_errno = external thread_local global i32, align 4
@.str.8 = external hidden unnamed_addr constant [94 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [94 x i8], align 1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #0

; Function Attrs: nounwind willreturn memory(read)
declare ptr @strrchr(ptr noundef, i32 noundef) #1

declare i32 @s2n_calculate_stacktrace() #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @s2n_result_is_ok(i32) #3

; Function Attrs: nounwind uwtable
declare dso_local i32 @s2n_fips_validate_curve(ptr noundef, ptr noundef) #4

; Function Attrs: nounwind uwtable
declare dso_local i32 @s2n_fips_validate_kem(ptr noundef, ptr noundef) #4

; Function Attrs: nounwind uwtable
define dso_local i32 @s2n_fips_validate_hybrid_group(ptr noundef %0, ptr noundef %1) #4 {
  %3 = alloca %struct.s2n_result, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca %struct.s2n_result, align 4
  %7 = alloca %struct.s2n_result, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  br label %8

8:                                                ; preds = %2
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %43, label %11

11:                                               ; preds = %8
  br label %12

12:                                               ; preds = %11
  br label %13

13:                                               ; preds = %12
  %14 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %15 = getelementptr inbounds %struct.s2n_debug_info, ptr %14, i32 0, i32 0
  store ptr @.str.8, ptr %15, align 8, !tbaa !9
  %16 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %17 = getelementptr inbounds %struct.s2n_debug_info, ptr %16, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  %19 = getelementptr inbounds i8, ptr %18, i64 21
  %20 = call ptr @strrchr(ptr noundef %19, i32 noundef 47) #5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %29

22:                                               ; preds = %13
  %23 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %24 = getelementptr inbounds %struct.s2n_debug_info, ptr %23, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !9
  %26 = getelementptr inbounds i8, ptr %25, i64 21
  %27 = call ptr @strrchr(ptr noundef %26, i32 noundef 47) #5
  %28 = getelementptr inbounds i8, ptr %27, i64 1
  br label %34

29:                                               ; preds = %13
  %30 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %31 = getelementptr inbounds %struct.s2n_debug_info, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !9
  %33 = getelementptr inbounds i8, ptr %32, i64 21
  br label %34

34:                                               ; preds = %29, %22
  %35 = phi ptr [ %28, %22 ], [ %33, %29 ]
  %36 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %37 = getelementptr inbounds %struct.s2n_debug_info, ptr %36, i32 0, i32 1
  store ptr %35, ptr %37, align 8, !tbaa !11
  %38 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  store i32 402653193, ptr %38, align 4, !tbaa !12
  %39 = call i32 @s2n_calculate_stacktrace()
  br label %40

40:                                               ; preds = %34
  %41 = getelementptr inbounds %struct.s2n_result, ptr %3, i32 0, i32 0
  store i32 -1, ptr %41, align 4, !tbaa !14
  br label %119

42:                                               ; No predecessors!
  br label %43

43:                                               ; preds = %42, %8
  br label %44

44:                                               ; preds = %43
  br label %45

45:                                               ; preds = %44
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = icmp ne ptr %46, null
  br i1 %47, label %80, label %48

48:                                               ; preds = %45
  br label %49

49:                                               ; preds = %48
  br label %50

50:                                               ; preds = %49
  %51 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %52 = getelementptr inbounds %struct.s2n_debug_info, ptr %51, i32 0, i32 0
  store ptr @.str.9, ptr %52, align 8, !tbaa !9
  %53 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %54 = getelementptr inbounds %struct.s2n_debug_info, ptr %53, i32 0, i32 0
  %55 = load ptr, ptr %54, align 8, !tbaa !9
  %56 = getelementptr inbounds i8, ptr %55, i64 21
  %57 = call ptr @strrchr(ptr noundef %56, i32 noundef 47) #5
  %58 = icmp ne ptr %57, null
  br i1 %58, label %59, label %66

59:                                               ; preds = %50
  %60 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %61 = getelementptr inbounds %struct.s2n_debug_info, ptr %60, i32 0, i32 0
  %62 = load ptr, ptr %61, align 8, !tbaa !9
  %63 = getelementptr inbounds i8, ptr %62, i64 21
  %64 = call ptr @strrchr(ptr noundef %63, i32 noundef 47) #5
  %65 = getelementptr inbounds i8, ptr %64, i64 1
  br label %71

66:                                               ; preds = %50
  %67 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %68 = getelementptr inbounds %struct.s2n_debug_info, ptr %67, i32 0, i32 0
  %69 = load ptr, ptr %68, align 8, !tbaa !9
  %70 = getelementptr inbounds i8, ptr %69, i64 21
  br label %71

71:                                               ; preds = %66, %59
  %72 = phi ptr [ %65, %59 ], [ %70, %66 ]
  %73 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %74 = getelementptr inbounds %struct.s2n_debug_info, ptr %73, i32 0, i32 1
  store ptr %72, ptr %74, align 8, !tbaa !11
  %75 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  store i32 402653193, ptr %75, align 4, !tbaa !12
  %76 = call i32 @s2n_calculate_stacktrace()
  br label %77

77:                                               ; preds = %71
  %78 = getelementptr inbounds %struct.s2n_result, ptr %3, i32 0, i32 0
  store i32 -1, ptr %78, align 4, !tbaa !14
  br label %119

79:                                               ; No predecessors!
  br label %80

80:                                               ; preds = %79, %45
  br label %81

81:                                               ; preds = %80
  %82 = load ptr, ptr %5, align 8, !tbaa !5
  store i8 0, ptr %82, align 1, !tbaa !16
  %83 = load ptr, ptr %4, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.s2n_kem_group, ptr %83, i32 0, i32 4
  %85 = load i8, ptr %84, align 8, !tbaa !18, !range !21, !noundef !22
  %86 = trunc i8 %85 to i1
  br i1 %86, label %87, label %102

87:                                               ; preds = %81
  br label %88

88:                                               ; preds = %87
  %89 = load ptr, ptr %4, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.s2n_kem_group, ptr %89, i32 0, i32 3
  %91 = load ptr, ptr %90, align 8, !tbaa !23
  %92 = load ptr, ptr %5, align 8, !tbaa !5
  %93 = call i32 @s2n_fips_validate_kem(ptr noundef %91, ptr noundef %92)
  %94 = getelementptr inbounds %struct.s2n_result, ptr %6, i32 0, i32 0
  store i32 %93, ptr %94, align 4
  %95 = getelementptr inbounds %struct.s2n_result, ptr %6, i32 0, i32 0
  %96 = load i32, ptr %95, align 4
  %97 = call zeroext i1 @s2n_result_is_ok(i32 %96)
  br i1 %97, label %100, label %98

98:                                               ; preds = %88
  %99 = getelementptr inbounds %struct.s2n_result, ptr %3, i32 0, i32 0
  store i32 -1, ptr %99, align 4, !tbaa !14
  br label %119

100:                                              ; preds = %88
  br label %101

101:                                              ; preds = %100
  br label %117

102:                                              ; preds = %81
  br label %103

103:                                              ; preds = %102
  %104 = load ptr, ptr %4, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.s2n_kem_group, ptr %104, i32 0, i32 2
  %106 = load ptr, ptr %105, align 8, !tbaa !24
  %107 = load ptr, ptr %5, align 8, !tbaa !5
  %108 = call i32 @s2n_fips_validate_curve(ptr noundef %106, ptr noundef %107)
  %109 = getelementptr inbounds %struct.s2n_result, ptr %7, i32 0, i32 0
  store i32 %108, ptr %109, align 4
  %110 = getelementptr inbounds %struct.s2n_result, ptr %7, i32 0, i32 0
  %111 = load i32, ptr %110, align 4
  %112 = call zeroext i1 @s2n_result_is_ok(i32 %111)
  br i1 %112, label %115, label %113

113:                                              ; preds = %103
  %114 = getelementptr inbounds %struct.s2n_result, ptr %3, i32 0, i32 0
  store i32 -1, ptr %114, align 4, !tbaa !14
  br label %119

115:                                              ; preds = %103
  br label %116

116:                                              ; preds = %115
  br label %117

117:                                              ; preds = %116, %101
  %118 = getelementptr inbounds %struct.s2n_result, ptr %3, i32 0, i32 0
  store i32 0, ptr %118, align 4, !tbaa !14
  br label %119

119:                                              ; preds = %117, %113, %98, %77, %40
  %120 = getelementptr inbounds %struct.s2n_result, ptr %3, i32 0, i32 0
  %121 = load i32, ptr %120, align 4
  ret i32 %121
}

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { nounwind willreturn memory(read) "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 = { "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 = { inlinehint 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 #4 = { 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 #5 = { nounwind willreturn memory(read) }

!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, !6, i64 0}
!10 = !{!"s2n_debug_info", !6, i64 0, !6, i64 8}
!11 = !{!10, !6, i64 8}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !13, i64 0}
!15 = !{!"", !13, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"_Bool", !7, i64 0}
!18 = !{!19, !17, i64 32}
!19 = !{!"s2n_kem_group", !6, i64 0, !20, i64 8, !6, i64 16, !6, i64 24, !17, i64 32}
!20 = !{!"short", !7, i64 0}
!21 = !{i8 0, i8 2}
!22 = !{}
!23 = !{!19, !6, i64 24}
!24 = !{!19, !6, i64 16}


; 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_debug_info = type { ptr, ptr }

@_s2n_debug_info = external thread_local local_unnamed_addr global %struct.s2n_debug_info, align 8
@s2n_errno = external thread_local local_unnamed_addr global i32, align 4
@.str.8 = external hidden unnamed_addr constant [94 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [94 x i8], align 1

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare ptr @strrchr(ptr noundef, i32 noundef) local_unnamed_addr #1

declare i32 @s2n_calculate_stacktrace() local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @s2n_result_is_ok(i32) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare dso_local i32 @s2n_fips_validate_curve(ptr noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
declare dso_local i32 @s2n_fips_validate_kem(ptr noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @s2n_fips_validate_hybrid_group(ptr noundef readonly %0, ptr noundef %1) local_unnamed_addr #4 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %3, label %11

3:                                                ; preds = %2
  %4 = tail call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  store ptr @.str.8, ptr %4, align 8, !tbaa !5
  %5 = tail call ptr @strrchr(ptr noundef nonnull dereferenceable(1) getelementptr inbounds (i8, ptr @.str.8, i64 21), i32 noundef 47) #5
  %.not13 = icmp eq ptr %5, null
  %6 = getelementptr inbounds i8, ptr %5, i64 1
  %7 = select i1 %.not13, ptr getelementptr inbounds (i8, ptr @.str.8, i64 21), ptr %6
  %8 = getelementptr inbounds i8, ptr %4, i64 8
  store ptr %7, ptr %8, align 8, !tbaa !10
  %9 = tail call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  store i32 402653193, ptr %9, align 4, !tbaa !11
  %10 = tail call i32 @s2n_calculate_stacktrace() #6
  br label %35

11:                                               ; preds = %2
  %.not14 = icmp eq ptr %1, null
  br i1 %.not14, label %12, label %20

12:                                               ; preds = %11
  %13 = tail call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  store ptr @.str.9, ptr %13, align 8, !tbaa !5
  %14 = tail call ptr @strrchr(ptr noundef nonnull dereferenceable(1) getelementptr inbounds (i8, ptr @.str.9, i64 21), i32 noundef 47) #5
  %.not15 = icmp eq ptr %14, null
  %15 = getelementptr inbounds i8, ptr %14, i64 1
  %16 = select i1 %.not15, ptr getelementptr inbounds (i8, ptr @.str.9, i64 21), ptr %15
  %17 = getelementptr inbounds i8, ptr %13, i64 8
  store ptr %16, ptr %17, align 8, !tbaa !10
  %18 = tail call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  store i32 402653193, ptr %18, align 4, !tbaa !11
  %19 = tail call i32 @s2n_calculate_stacktrace() #6
  br label %35

20:                                               ; preds = %11
  store i8 0, ptr %1, align 1, !tbaa !13
  %21 = getelementptr inbounds i8, ptr %0, i64 32
  %22 = load i8, ptr %21, align 8, !tbaa !15, !range !18, !noundef !19
  %23 = trunc nuw i8 %22 to i1
  br i1 %23, label %24, label %29

24:                                               ; preds = %20
  %25 = getelementptr inbounds i8, ptr %0, i64 24
  %26 = load ptr, ptr %25, align 8, !tbaa !20
  %27 = tail call i32 @s2n_fips_validate_kem(ptr noundef %26, ptr noundef nonnull %1)
  %28 = tail call zeroext i1 @s2n_result_is_ok(i32 %27)
  br i1 %28, label %34, label %35

29:                                               ; preds = %20
  %30 = getelementptr inbounds i8, ptr %0, i64 16
  %31 = load ptr, ptr %30, align 8, !tbaa !21
  %32 = tail call i32 @s2n_fips_validate_curve(ptr noundef %31, ptr noundef nonnull %1)
  %33 = tail call zeroext i1 @s2n_result_is_ok(i32 %32)
  br i1 %33, label %34, label %35

34:                                               ; preds = %29, %24
  br label %35

35:                                               ; preds = %29, %24, %34, %12, %3
  %.sroa.09.0 = phi i32 [ 0, %34 ], [ -1, %12 ], [ -1, %3 ], [ -1, %24 ], [ -1, %29 ]
  ret i32 %.sroa.09.0
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { "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 = { inlinehint 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 #4 = { 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 #5 = { nounwind willreturn memory(read) }
attributes #6 = { 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_debug_info", !7, i64 0, !7, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 8}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !8, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"_Bool", !8, i64 0}
!15 = !{!16, !14, i64 32}
!16 = !{!"s2n_kem_group", !7, i64 0, !17, i64 8, !7, i64 16, !7, i64 24, !14, i64 32}
!17 = !{!"short", !8, i64 0}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = !{!16, !7, i64 24}
!21 = !{!16, !7, i64 16}


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