; LLVM IR from guanzhi/GmSSL :: src (tls_ext)

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

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [61 x i8], align 1
@__FUNCTION__.tls13_process_client_supported_versions = external hidden unnamed_addr constant [40 x i8], align 1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

declare i32 @tls_uint8array_from_bytes(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

declare i32 @tls_length_is_zero(i64 noundef) #2

declare i32 @tls_uint16_from_bytes(ptr noundef, ptr noundef, ptr noundef) #2

declare ptr @tls_protocol_name(i32 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @tls13_supported_versions_ext_to_bytes(i32 noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local i32 @tls13_process_client_supported_versions(ptr noundef %0, i64 noundef %1, ptr noundef %2, ptr noundef %3) #3 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i16, align 2
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 -1, ptr %12, align 4, !tbaa !11
  %15 = call i32 @tls_uint8array_from_bytes(ptr noundef %10, ptr noundef %11, ptr noundef %6, ptr noundef %7)
  %16 = icmp ne i32 %15, 1
  br i1 %16, label %21, label %17

17:                                               ; preds = %4
  %18 = load i64, ptr %7, align 8, !tbaa !9
  %19 = call i32 @tls_length_is_zero(i64 noundef %18)
  %20 = icmp ne i32 %19, 1
  br i1 %20, label %21, label %27

21:                                               ; preds = %17, %4
  br label %22

22:                                               ; preds = %21
  %23 = load ptr, ptr @stderr, align 8, !tbaa !5
  %24 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %23, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 514, ptr noundef @__FUNCTION__.tls13_process_client_supported_versions) #4
  br label %25

25:                                               ; preds = %22
  br label %26

26:                                               ; preds = %25
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %95

27:                                               ; preds = %17
  %28 = load i64, ptr %11, align 8, !tbaa !9
  %29 = icmp ult i64 %28, 2
  br i1 %29, label %33, label %30

30:                                               ; preds = %27
  %31 = load i64, ptr %11, align 8, !tbaa !9
  %32 = icmp ugt i64 %31, 254
  br i1 %32, label %33, label %39

33:                                               ; preds = %30, %27
  br label %34

34:                                               ; preds = %33
  %35 = load ptr, ptr @stderr, align 8, !tbaa !5
  %36 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %35, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 518, ptr noundef @__FUNCTION__.tls13_process_client_supported_versions) #4
  br label %37

37:                                               ; preds = %34
  br label %38

38:                                               ; preds = %37
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %95

39:                                               ; preds = %30
  br label %40

40:                                               ; preds = %73, %39
  %41 = load i64, ptr %11, align 8, !tbaa !9
  %42 = icmp ne i64 %41, 0
  br i1 %42, label %43, label %74

43:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 2, ptr %14) #4
  %44 = call i32 @tls_uint16_from_bytes(ptr noundef %14, ptr noundef %10, ptr noundef %11)
  %45 = icmp ne i32 %44, 1
  br i1 %45, label %46, label %52

46:                                               ; preds = %43
  br label %47

47:                                               ; preds = %46
  %48 = load ptr, ptr @stderr, align 8, !tbaa !5
  %49 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %48, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 524, ptr noundef @__FUNCTION__.tls13_process_client_supported_versions) #4
  br label %50

50:                                               ; preds = %47
  br label %51

51:                                               ; preds = %50
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %71

52:                                               ; preds = %43
  %53 = load i16, ptr %14, align 2, !tbaa !13
  %54 = zext i16 %53 to i32
  %55 = call ptr @tls_protocol_name(i32 noundef %54)
  %56 = icmp ne ptr %55, null
  br i1 %56, label %63, label %57

57:                                               ; preds = %52
  br label %58

58:                                               ; preds = %57
  %59 = load ptr, ptr @stderr, align 8, !tbaa !5
  %60 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %59, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 528, ptr noundef @__FUNCTION__.tls13_process_client_supported_versions) #4
  br label %61

61:                                               ; preds = %58
  br label %62

62:                                               ; preds = %61
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %71

63:                                               ; preds = %52
  %64 = load i16, ptr %14, align 2, !tbaa !13
  %65 = zext i16 %64 to i32
  %66 = icmp eq i32 %65, 772
  br i1 %66, label %67, label %70

67:                                               ; preds = %63
  %68 = load i16, ptr %14, align 2, !tbaa !13
  %69 = zext i16 %68 to i32
  store i32 %69, ptr %12, align 4, !tbaa !11
  br label %70

70:                                               ; preds = %67, %63
  store i32 0, ptr %13, align 4
  br label %71

71:                                               ; preds = %70, %62, %51
  call void @llvm.lifetime.end.p0(i64 2, ptr %14) #4
  %72 = load i32, ptr %13, align 4
  switch i32 %72, label %95 [
    i32 0, label %73
  ]

73:                                               ; preds = %71
  br label %40, !llvm.loop !15

74:                                               ; preds = %40
  %75 = load i32, ptr %12, align 4, !tbaa !11
  %76 = icmp slt i32 %75, 0
  br i1 %76, label %77, label %83

77:                                               ; preds = %74
  br label %78

78:                                               ; preds = %77
  %79 = load ptr, ptr @stderr, align 8, !tbaa !5
  %80 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %79, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 536, ptr noundef @__FUNCTION__.tls13_process_client_supported_versions) #4
  br label %81

81:                                               ; preds = %78
  br label %82

82:                                               ; preds = %81
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %95

83:                                               ; preds = %74
  %84 = load ptr, ptr %8, align 8, !tbaa !5
  %85 = load ptr, ptr %9, align 8, !tbaa !5
  %86 = call i32 @tls13_supported_versions_ext_to_bytes(i32 noundef 2, ptr noundef %12, i64 noundef 1, ptr noundef %84, ptr noundef %85)
  %87 = icmp ne i32 %86, 1
  br i1 %87, label %88, label %94

88:                                               ; preds = %83
  br label %89

89:                                               ; preds = %88
  %90 = load ptr, ptr @stderr, align 8, !tbaa !5
  %91 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %90, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 540, ptr noundef @__FUNCTION__.tls13_process_client_supported_versions) #4
  br label %92

92:                                               ; preds = %89
  br label %93

93:                                               ; preds = %92
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %95

94:                                               ; preds = %83
  store i32 1, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %95

95:                                               ; preds = %94, %93, %82, %71, %38, %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %96 = load i32, ptr %5, align 4
  ret i32 %96
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind "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 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 }

!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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [61 x i8], align 1
@__FUNCTION__.tls13_process_client_supported_versions = external hidden unnamed_addr constant [40 x i8], align 1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

declare i32 @tls_uint8array_from_bytes(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @tls_length_is_zero(i64 noundef) local_unnamed_addr #2

declare i32 @tls_uint16_from_bytes(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare ptr @tls_protocol_name(i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @tls13_supported_versions_ext_to_bytes(i32 noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @tls13_process_client_supported_versions(ptr noundef %0, i64 noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #3 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i16, align 2
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %9) #4
  store i32 -1, ptr %9, align 4, !tbaa !11
  %11 = call i32 @tls_uint8array_from_bytes(ptr noundef nonnull %7, ptr noundef nonnull %8, ptr noundef nonnull %5, ptr noundef nonnull %6) #4
  %.not = icmp eq i32 %11, 1
  br i1 %.not, label %12, label %15

12:                                               ; preds = %4
  %13 = load i64, ptr %6, align 8, !tbaa !9
  %14 = call i32 @tls_length_is_zero(i64 noundef %13) #4
  %.not6 = icmp eq i32 %14, 1
  br i1 %.not6, label %18, label %15

15:                                               ; preds = %4, %12
  %16 = load ptr, ptr @stderr, align 8, !tbaa !5
  %17 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %16, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 514, ptr noundef nonnull @__FUNCTION__.tls13_process_client_supported_versions) #5
  br label %43

18:                                               ; preds = %12
  %19 = load i64, ptr %8, align 8
  %20 = add i64 %19, -255
  %or.cond = icmp ult i64 %20, -253
  br i1 %or.cond, label %22, label %.lr.ph.outer

.lr.ph.outer:                                     ; preds = %18, %.thread
  %21 = phi i1 [ false, %.thread ], [ true, %18 ]
  br label %.lr.ph

22:                                               ; preds = %18
  %23 = load ptr, ptr @stderr, align 8, !tbaa !5
  %24 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %23, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 518, ptr noundef nonnull @__FUNCTION__.tls13_process_client_supported_versions) #5
  br label %43

.lr.ph:                                           ; preds = %.lr.ph.outer, %33
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %10) #4
  %25 = call i32 @tls_uint16_from_bytes(ptr noundef nonnull %10, ptr noundef nonnull %7, ptr noundef nonnull %8) #4
  %.not9 = icmp eq i32 %25, 1
  br i1 %.not9, label %26, label %.critedge

26:                                               ; preds = %.lr.ph
  %27 = load i16, ptr %10, align 2, !tbaa !13
  %28 = zext i16 %27 to i32
  %29 = call ptr @tls_protocol_name(i32 noundef %28) #4
  %.not10 = icmp eq ptr %29, null
  br i1 %.not10, label %.critedge, label %30

30:                                               ; preds = %26
  %31 = load i16, ptr %10, align 2, !tbaa !13
  %32 = icmp eq i16 %31, 772
  br i1 %32, label %.thread, label %33

33:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %10) #4
  %.pr = load i64, ptr %8, align 8, !tbaa !9
  %.not7 = icmp eq i64 %.pr, 0
  br i1 %.not7, label %._crit_edge, label %.lr.ph, !llvm.loop !15

.thread:                                          ; preds = %30
  store i32 772, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %10) #4
  %.pr12 = load i64, ptr %8, align 8, !tbaa !9
  %.not713 = icmp eq i64 %.pr12, 0
  br i1 %.not713, label %._crit_edge.thread, label %.lr.ph.outer, !llvm.loop !15

._crit_edge:                                      ; preds = %33
  br i1 %21, label %34, label %._crit_edge.thread

34:                                               ; preds = %._crit_edge
  %35 = load ptr, ptr @stderr, align 8, !tbaa !5
  %36 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %35, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 536, ptr noundef nonnull @__FUNCTION__.tls13_process_client_supported_versions) #5
  br label %43

._crit_edge.thread:                               ; preds = %.thread, %._crit_edge
  %37 = call i32 @tls13_supported_versions_ext_to_bytes(i32 noundef 2, ptr noundef nonnull %9, i64 noundef 1, ptr noundef %2, ptr noundef %3)
  %.not8 = icmp eq i32 %37, 1
  br i1 %.not8, label %43, label %38

38:                                               ; preds = %._crit_edge.thread
  %39 = load ptr, ptr @stderr, align 8, !tbaa !5
  %40 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %39, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 540, ptr noundef nonnull @__FUNCTION__.tls13_process_client_supported_versions) #5
  br label %43

.critedge:                                        ; preds = %26, %.lr.ph
  %.sink17 = phi i32 [ 524, %.lr.ph ], [ 528, %26 ]
  %41 = load ptr, ptr @stderr, align 8, !tbaa !5
  %42 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %41, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef %.sink17, ptr noundef nonnull @__FUNCTION__.tls13_process_client_supported_versions) #5
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %10) #4
  br label %43

43:                                               ; preds = %._crit_edge.thread, %.critedge, %38, %34, %22, %15
  %.2 = phi i32 [ -1, %15 ], [ -1, %22 ], [ -1, %34 ], [ -1, %38 ], [ -1, %.critedge ], [ 1, %._crit_edge.thread ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #4
  ret i32 %.2
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nofree nounwind "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 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 }
attributes #5 = { cold 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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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