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

; 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_connection = type { i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, [22 x i8], [22 x i8], [22 x i8], i32, i32, %struct.s2n_timer, i64, i64, [32 x i8], i8, i8, i8, i8, i8, i8, i8, ptr, ptr, %struct.s2n_secrets, ptr, ptr, %struct.s2n_kex_parameters, %struct.s2n_handshake_parameters, %struct.s2n_psk_parameters, ptr, i8, i32, [5 x i8], %struct.s2n_stuffer, %struct.s2n_stuffer, %struct.s2n_stuffer, %struct.s2n_stuffer, i32, i64, [2 x i8], %struct.s2n_stuffer, i8, i8, i8, i8, %struct.s2n_atomic_flag, %struct.s2n_atomic_flag, %struct.s2n_handshake, i16, i32, i16, i64, i8, i64, i64, i64, %struct.s2n_atomic_flag, %struct.s2n_atomic_flag, [256 x i8], [256 x i8], i32, %struct.s2n_blob, i32, %struct.s2n_blob, %struct.s2n_blob, %struct.s2n_blob, %struct.s2n_client_hello, %struct.s2n_x509_validator, ptr, ptr, i8, i32, %struct.s2n_blob, i32, %struct.s2n_ticket_fields, [138 x i8], %struct.s2n_stuffer, %struct.s2n_blob, %struct.s2n_blob, i8, i8, i8, i16, i16, i32, i32, %struct.s2n_blob, i32, %struct.s2n_post_handshake, %struct.s2n_atomic_flag, i8, i8 }
%struct.s2n_timer = type { i64 }
%struct.s2n_secrets = type { %union.anon, i32 }
%union.anon = type { %struct.s2n_tls13_secrets }
%struct.s2n_tls13_secrets = type { [48 x i8], [48 x i8], [48 x i8], [48 x i8], [48 x i8], [48 x i8], [48 x i8], [48 x i8], i32 }
%struct.s2n_kex_parameters = type { %struct.s2n_dh_params, %struct.s2n_ecc_evp_params, [4 x ptr], %struct.s2n_ecc_evp_params, %struct.s2n_kem_group_params, %struct.s2n_kem_group_params, [8 x ptr], %struct.s2n_kem_params, %struct.s2n_blob, %struct.s2n_blob }
%struct.s2n_dh_params = type { ptr }
%struct.s2n_ecc_evp_params = type { ptr, ptr }
%struct.s2n_kem_group_params = type { ptr, %struct.s2n_kem_params, %struct.s2n_ecc_evp_params }
%struct.s2n_kem_params = type { ptr, %struct.s2n_blob, %struct.s2n_blob, %struct.s2n_blob, i8 }
%struct.s2n_handshake_parameters = type { %struct.s2n_pkey, %struct.s2n_pkey, %struct.s2n_blob, i32, %struct.s2n_sig_scheme_list, ptr, ptr, ptr, [4 x ptr], [4 x ptr], i8, i8, [32 x i8], [32 x i8] }
%struct.s2n_pkey = type { ptr, ptr, ptr, ptr, ptr, ptr }
%struct.s2n_sig_scheme_list = type { [128 x i16], i8 }
%struct.s2n_psk_parameters = type { i32, %struct.s2n_array, i16, i16, ptr, i32 }
%struct.s2n_array = type { %struct.s2n_blob, i32, i32 }
%struct.s2n_handshake = type { %struct.s2n_stuffer, ptr, [8 x i8], [48 x i8], [48 x i8], i8, i32, i32, i32, i32, %struct.s2n_offered_early_data, i8, i32 }
%struct.s2n_offered_early_data = type { ptr }
%struct.s2n_client_hello = type { %struct.s2n_blob, %struct.s2n_parsed_extensions_list, %struct.s2n_blob, %struct.s2n_blob, %struct.s2n_blob, i8, i8, i8 }
%struct.s2n_parsed_extensions_list = type { [21 x %struct.s2n_parsed_extension], %struct.s2n_blob, i16 }
%struct.s2n_parsed_extension = type { %struct.s2n_blob, i16, i16, i8 }
%struct.s2n_x509_validator = type { ptr, ptr, i8, i8, i16, ptr, i32, ptr, %struct.s2n_cert_validation_info, i8 }
%struct.s2n_cert_validation_info = type { i8, [3 x i8] }
%struct.s2n_ticket_fields = type { %struct.s2n_blob, i32 }
%struct.s2n_stuffer = type { %struct.s2n_blob, i32, i32, i32, i8 }
%struct.s2n_blob = type { ptr, i32, i32, i8 }
%struct.s2n_post_handshake = type { %struct.s2n_stuffer, [4 x i8] }
%struct.s2n_atomic_flag = type { i32 }

; 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
declare dso_local zeroext i8 @s2n_connection_get_protocol_version(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @s2n_connection_check_io_status(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i8, align 1
  %7 = alloca i8, align 1
  %8 = alloca i8, align 1
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %13, label %12

12:                                               ; preds = %2
  store i1 false, ptr %3, align 1
  br label %68

13:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #3
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.s2n_connection, ptr %14, i32 0, i32 61
  %16 = call zeroext i1 @s2n_atomic_flag_test(ptr noundef %15)
  %17 = zext i1 %16 to i8
  store i8 %17, ptr %6, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #3
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.s2n_connection, ptr %18, i32 0, i32 62
  %20 = call zeroext i1 @s2n_atomic_flag_test(ptr noundef %19)
  %21 = zext i1 %20 to i8
  store i8 %21, ptr %7, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #3
  %22 = load i8, ptr %6, align 1, !tbaa !11, !range !13, !noundef !14
  %23 = trunc i8 %22 to i1
  br i1 %23, label %28, label %24

24:                                               ; preds = %13
  %25 = load i8, ptr %7, align 1, !tbaa !11, !range !13, !noundef !14
  %26 = trunc i8 %25 to i1
  %27 = xor i1 %26, true
  br label %28

28:                                               ; preds = %24, %13
  %29 = phi i1 [ false, %13 ], [ %27, %24 ]
  %30 = zext i1 %29 to i8
  store i8 %30, ptr %8, align 1, !tbaa !11
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = call zeroext i8 @s2n_connection_get_protocol_version(ptr noundef %31)
  %33 = zext i8 %32 to i32
  %34 = icmp slt i32 %33, 34
  br i1 %34, label %35, label %45

35:                                               ; preds = %28
  %36 = load i32, ptr %5, align 4, !tbaa !9
  switch i32 %36, label %44 [
    i32 0, label %37
    i32 1, label %37
    i32 2, label %37
    i32 3, label %40
  ]

37:                                               ; preds = %35, %35, %35
  %38 = load i8, ptr %8, align 1, !tbaa !11, !range !13, !noundef !14
  %39 = trunc i8 %38 to i1
  store i1 %39, ptr %3, align 1
  store i32 1, ptr %9, align 4
  br label %67

40:                                               ; preds = %35
  %41 = load i8, ptr %8, align 1, !tbaa !11, !range !13, !noundef !14
  %42 = trunc i8 %41 to i1
  %43 = xor i1 %42, true
  store i1 %43, ptr %3, align 1
  store i32 1, ptr %9, align 4
  br label %67

44:                                               ; preds = %35
  br label %45

45:                                               ; preds = %44, %28
  %46 = load i32, ptr %5, align 4, !tbaa !9
  switch i32 %46, label %66 [
    i32 0, label %47
    i32 1, label %51
    i32 2, label %55
    i32 3, label %58
  ]

47:                                               ; preds = %45
  %48 = load i8, ptr %7, align 1, !tbaa !11, !range !13, !noundef !14
  %49 = trunc i8 %48 to i1
  %50 = xor i1 %49, true
  store i1 %50, ptr %3, align 1
  store i32 1, ptr %9, align 4
  br label %67

51:                                               ; preds = %45
  %52 = load i8, ptr %6, align 1, !tbaa !11, !range !13, !noundef !14
  %53 = trunc i8 %52 to i1
  %54 = xor i1 %53, true
  store i1 %54, ptr %3, align 1
  store i32 1, ptr %9, align 4
  br label %67

55:                                               ; preds = %45
  %56 = load i8, ptr %8, align 1, !tbaa !11, !range !13, !noundef !14
  %57 = trunc i8 %56 to i1
  store i1 %57, ptr %3, align 1
  store i32 1, ptr %9, align 4
  br label %67

58:                                               ; preds = %45
  %59 = load i8, ptr %6, align 1, !tbaa !11, !range !13, !noundef !14
  %60 = trunc i8 %59 to i1
  br i1 %60, label %61, label %64

61:                                               ; preds = %58
  %62 = load i8, ptr %7, align 1, !tbaa !11, !range !13, !noundef !14
  %63 = trunc i8 %62 to i1
  br label %64

64:                                               ; preds = %61, %58
  %65 = phi i1 [ false, %58 ], [ %63, %61 ]
  store i1 %65, ptr %3, align 1
  store i32 1, ptr %9, align 4
  br label %67

66:                                               ; preds = %45
  store i1 false, ptr %3, align 1
  store i32 1, ptr %9, align 4
  br label %67

67:                                               ; preds = %66, %64, %55, %51, %47, %40, %37
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #3
  br label %68

68:                                               ; preds = %67, %12
  %69 = load i1, ptr %3, align 1
  ret i1 %69
}

declare zeroext i1 @s2n_atomic_flag_test(ptr noundef) #2

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 = { "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, !12, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}


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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @s2n_connection_get_protocol_version(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @s2n_connection_check_io_status(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %22, label %3

3:                                                ; preds = %2
  %4 = getelementptr inbounds i8, ptr %0, i64 2264
  %5 = tail call zeroext i1 @s2n_atomic_flag_test(ptr noundef nonnull %4) #2
  %6 = getelementptr inbounds i8, ptr %0, i64 2268
  %7 = tail call zeroext i1 @s2n_atomic_flag_test(ptr noundef nonnull %6) #2
  %8 = select i1 %5, i1 true, i1 %7
  %9 = xor i1 %8, true
  %10 = tail call zeroext i8 @s2n_connection_get_protocol_version(ptr noundef nonnull %0)
  %11 = icmp ult i8 %10, 34
  br i1 %11, label %12, label %14

12:                                               ; preds = %3
  switch i32 %1, label %21 [
    i32 0, label %22
    i32 1, label %22
    i32 2, label %22
    i32 3, label %13
  ]

13:                                               ; preds = %12
  br label %22

14:                                               ; preds = %3
  %15 = xor i1 %7, true
  switch i32 %1, label %21 [
    i32 0, label %22
    i32 1, label %16
    i32 2, label %18
    i32 3, label %19
  ]

16:                                               ; preds = %14
  %17 = xor i1 %5, true
  br label %22

18:                                               ; preds = %14
  br label %22

19:                                               ; preds = %14
  %20 = select i1 %5, i1 %7, i1 false
  br label %22

21:                                               ; preds = %12, %14
  br label %22

22:                                               ; preds = %13, %16, %18, %19, %21, %12, %12, %12, %14, %2
  %.1 = phi i1 [ false, %2 ], [ false, %21 ], [ %20, %19 ], [ %9, %18 ], [ %17, %16 ], [ %8, %13 ], [ %9, %12 ], [ %9, %12 ], [ %9, %12 ], [ %15, %14 ]
  ret i1 %.1
}

declare zeroext i1 @s2n_atomic_flag_test(ptr noundef) local_unnamed_addr #1

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 = { "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)"}


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