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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @s2n_ecdhe_send_public_key(ptr noundef %0, ptr noundef %1, i1 noundef zeroext %2) #0 {
  %4 = alloca %struct.s2n_result, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  %8 = zext i1 %2 to i8
  store i8 %8, ptr %7, align 1, !tbaa !9
  br label %9

9:                                                ; preds = %3
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %44, label %12

12:                                               ; preds = %9
  br label %13

13:                                               ; preds = %12
  br label %14

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

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

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

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

41:                                               ; preds = %35
  %42 = getelementptr inbounds %struct.s2n_result, ptr %4, i32 0, i32 0
  store i32 -1, ptr %42, align 4, !tbaa !16
  br label %127

43:                                               ; No predecessors!
  br label %44

44:                                               ; preds = %43, %9
  br label %45

45:                                               ; preds = %44
  br label %46

46:                                               ; preds = %45
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.s2n_ecc_evp_params, ptr %47, i32 0, i32 0
  %49 = load ptr, ptr %48, align 8, !tbaa !18
  %50 = icmp ne ptr %49, null
  br i1 %50, label %83, label %51

51:                                               ; preds = %46
  br label %52

52:                                               ; preds = %51
  br label %53

53:                                               ; preds = %52
  %54 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %55 = getelementptr inbounds %struct.s2n_debug_info, ptr %54, i32 0, i32 0
  store ptr @.str.1, ptr %55, align 8, !tbaa !11
  %56 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %57 = getelementptr inbounds %struct.s2n_debug_info, ptr %56, i32 0, i32 0
  %58 = load ptr, ptr %57, align 8, !tbaa !11
  %59 = getelementptr inbounds i8, ptr %58, i64 21
  %60 = call ptr @strrchr(ptr noundef %59, i32 noundef 47) #4
  %61 = icmp ne ptr %60, null
  br i1 %61, label %62, label %69

62:                                               ; preds = %53
  %63 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %64 = getelementptr inbounds %struct.s2n_debug_info, ptr %63, i32 0, i32 0
  %65 = load ptr, ptr %64, align 8, !tbaa !11
  %66 = getelementptr inbounds i8, ptr %65, i64 21
  %67 = call ptr @strrchr(ptr noundef %66, i32 noundef 47) #4
  %68 = getelementptr inbounds i8, ptr %67, i64 1
  br label %74

69:                                               ; preds = %53
  %70 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %71 = getelementptr inbounds %struct.s2n_debug_info, ptr %70, i32 0, i32 0
  %72 = load ptr, ptr %71, align 8, !tbaa !11
  %73 = getelementptr inbounds i8, ptr %72, i64 21
  br label %74

74:                                               ; preds = %69, %62
  %75 = phi ptr [ %68, %62 ], [ %73, %69 ]
  %76 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %77 = getelementptr inbounds %struct.s2n_debug_info, ptr %76, i32 0, i32 1
  store ptr %75, ptr %77, align 8, !tbaa !13
  %78 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  store i32 402653193, ptr %78, align 4, !tbaa !14
  %79 = call i32 @s2n_calculate_stacktrace()
  br label %80

80:                                               ; preds = %74
  %81 = getelementptr inbounds %struct.s2n_result, ptr %4, i32 0, i32 0
  store i32 -1, ptr %81, align 4, !tbaa !16
  br label %127

82:                                               ; No predecessors!
  br label %83

83:                                               ; preds = %82, %46
  br label %84

84:                                               ; preds = %83
  %85 = load i8, ptr %7, align 1, !tbaa !9, !range !20, !noundef !21
  %86 = trunc i8 %85 to i1
  br i1 %86, label %87, label %102

87:                                               ; preds = %84
  br label %88

88:                                               ; preds = %87
  %89 = load ptr, ptr %6, align 8, !tbaa !5
  %90 = load ptr, ptr %5, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.s2n_ecc_evp_params, ptr %90, i32 0, i32 0
  %92 = load ptr, ptr %91, align 8, !tbaa !18
  %93 = getelementptr inbounds %struct.s2n_ecc_named_curve, ptr %92, i32 0, i32 3
  %94 = load i8, ptr %93, align 8, !tbaa !22
  %95 = zext i8 %94 to i16
  %96 = call i32 @s2n_stuffer_write_uint16(ptr noundef %89, i16 noundef zeroext %95)
  %97 = icmp sgt i32 %96, -1
  br i1 %97, label %100, label %98

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

100:                                              ; preds = %88
  br label %101

101:                                              ; preds = %100
  br label %102

102:                                              ; preds = %101, %84
  %103 = load ptr, ptr %5, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.s2n_ecc_evp_params, ptr %103, i32 0, i32 1
  %105 = load ptr, ptr %104, align 8, !tbaa !25
  %106 = icmp eq ptr %105, null
  br i1 %106, label %107, label %116

107:                                              ; preds = %102
  br label %108

108:                                              ; preds = %107
  %109 = load ptr, ptr %5, align 8, !tbaa !5
  %110 = call i32 @s2n_ecc_evp_generate_ephemeral_key(ptr noundef %109)
  %111 = icmp sgt i32 %110, -1
  br i1 %111, label %114, label %112

112:                                              ; preds = %108
  %113 = getelementptr inbounds %struct.s2n_result, ptr %4, i32 0, i32 0
  store i32 -1, ptr %113, align 4, !tbaa !16
  br label %127

114:                                              ; preds = %108
  br label %115

115:                                              ; preds = %114
  br label %116

116:                                              ; preds = %115, %102
  br label %117

117:                                              ; preds = %116
  %118 = load ptr, ptr %5, align 8, !tbaa !5
  %119 = load ptr, ptr %6, align 8, !tbaa !5
  %120 = call i32 @s2n_ecc_evp_write_params_point(ptr noundef %118, ptr noundef %119)
  %121 = icmp sgt i32 %120, -1
  br i1 %121, label %124, label %122

122:                                              ; preds = %117
  %123 = getelementptr inbounds %struct.s2n_result, ptr %4, i32 0, i32 0
  store i32 -1, ptr %123, align 4, !tbaa !16
  br label %127

124:                                              ; preds = %117
  br label %125

125:                                              ; preds = %124
  %126 = getelementptr inbounds %struct.s2n_result, ptr %4, i32 0, i32 0
  store i32 0, ptr %126, align 4, !tbaa !16
  br label %127

127:                                              ; preds = %125, %122, %112, %98, %80, %41
  %128 = getelementptr inbounds %struct.s2n_result, ptr %4, i32 0, i32 0
  %129 = load i32, ptr %128, align 4
  ret i32 %129
}

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

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

declare i32 @s2n_calculate_stacktrace() #3

declare i32 @s2n_stuffer_write_uint16(ptr noundef, i16 noundef zeroext) #3

declare i32 @s2n_ecc_evp_generate_ephemeral_key(ptr noundef) #3

declare i32 @s2n_ecc_evp_write_params_point(ptr noundef, ptr noundef) #3

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 #3 = { "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 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, !10, i64 0}
!10 = !{!"_Bool", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"s2n_debug_info", !6, i64 0, !6, i64 8}
!13 = !{!12, !6, i64 8}
!14 = !{!15, !15, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = !{!17, !15, i64 0}
!17 = !{!"", !15, i64 0}
!18 = !{!19, !6, i64 0}
!19 = !{!"s2n_ecc_evp_params", !6, i64 0, !6, i64 8}
!20 = !{i8 0, i8 2}
!21 = !{}
!22 = !{!23, !7, i64 16}
!23 = !{!"s2n_ecc_named_curve", !24, i64 0, !15, i64 4, !6, i64 8, !7, i64 16, !6, i64 24}
!24 = !{!"short", !7, i64 0}
!25 = !{!19, !6, i64 8}


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

@.str = external hidden unnamed_addr constant [100 x i8], align 1
@_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.1 = external hidden unnamed_addr constant [100 x i8], align 1

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

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

12:                                               ; preds = %3
  %13 = load ptr, ptr %0, align 8, !tbaa !13
  %.not12 = icmp eq ptr %13, null
  br i1 %.not12, label %14, label %22

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

22:                                               ; preds = %12
  br i1 %2, label %23, label %29

23:                                               ; preds = %22
  %24 = getelementptr inbounds i8, ptr %13, i64 16
  %25 = load i8, ptr %24, align 8, !tbaa !15
  %26 = zext i8 %25 to i16
  %27 = tail call i32 @s2n_stuffer_write_uint16(ptr noundef %1, i16 noundef zeroext %26) #5
  %28 = icmp sgt i32 %27, -1
  br i1 %28, label %29, label %38

29:                                               ; preds = %23, %22
  %30 = getelementptr inbounds i8, ptr %0, i64 8
  %31 = load ptr, ptr %30, align 8, !tbaa !18
  %32 = icmp eq ptr %31, null
  br i1 %32, label %33, label %36

33:                                               ; preds = %29
  %34 = tail call i32 @s2n_ecc_evp_generate_ephemeral_key(ptr noundef nonnull %0) #5
  %35 = icmp sgt i32 %34, -1
  br i1 %35, label %36, label %38

36:                                               ; preds = %29, %33
  %37 = tail call i32 @s2n_ecc_evp_write_params_point(ptr noundef nonnull %0, ptr noundef %1) #5
  %.lobit = ashr i32 %37, 31
  br label %38

38:                                               ; preds = %36, %33, %23, %14, %4
  %.sroa.0.0 = phi i32 [ -1, %14 ], [ -1, %4 ], [ -1, %23 ], [ -1, %33 ], [ %.lobit, %36 ]
  ret i32 %.sroa.0.0
}

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

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

declare i32 @s2n_calculate_stacktrace() local_unnamed_addr #3

declare i32 @s2n_stuffer_write_uint16(ptr noundef, i16 noundef zeroext) local_unnamed_addr #3

declare i32 @s2n_ecc_evp_generate_ephemeral_key(ptr noundef) local_unnamed_addr #3

declare i32 @s2n_ecc_evp_write_params_point(ptr noundef, ptr noundef) local_unnamed_addr #3

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 #3 = { "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 willreturn memory(read) }
attributes #5 = { 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, !7, i64 0}
!14 = !{!"s2n_ecc_evp_params", !7, i64 0, !7, i64 8}
!15 = !{!16, !8, i64 16}
!16 = !{!"s2n_ecc_named_curve", !17, i64 0, !12, i64 4, !7, i64 8, !8, i64 16, !7, i64 24}
!17 = !{!"short", !8, i64 0}
!18 = !{!14, !7, i64 8}


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