; 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
@.str.3 = external hidden unnamed_addr constant [10 x i8], align 1
@__FUNCTION__.tls13_supported_versions_ext_print = external hidden unnamed_addr constant [35 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [31 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_uint16_from_bytes(ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @tls13_supported_versions_ext_print(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef %4, i64 noundef %5) #3 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  %16 = alloca i16, align 2
  %17 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store i32 %1, ptr %9, align 4, !tbaa !9
  store i32 %2, ptr %10, align 4, !tbaa !9
  store i32 %3, ptr %11, align 4, !tbaa !9
  store ptr %4, ptr %12, align 8, !tbaa !5
  store i64 %5, ptr %13, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.start.p0(i64 2, ptr %16) #4
  %18 = load i32, ptr %11, align 4, !tbaa !9
  switch i32 %18, label %89 [
    i32 1, label %19
    i32 2, label %70
    i32 6, label %70
  ]

19:                                               ; preds = %6
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  %21 = load i32, ptr %9, align 4, !tbaa !9
  %22 = load i32, ptr %10, align 4, !tbaa !9
  %23 = call i32 (ptr, i32, i32, ptr, ...) @format_print(ptr noundef %20, i32 noundef %21, i32 noundef %22, ptr noundef @.str.3)
  %24 = load i32, ptr %10, align 4, !tbaa !9
  %25 = add nsw i32 %24, 4
  store i32 %25, ptr %10, align 4, !tbaa !9
  %26 = call i32 @tls_uint8array_from_bytes(ptr noundef %14, ptr noundef %15, ptr noundef %12, ptr noundef %13)
  %27 = icmp ne i32 %26, 1
  br i1 %27, label %28, label %34

28:                                               ; preds = %19
  br label %29

29:                                               ; preds = %28
  %30 = load ptr, ptr @stderr, align 8, !tbaa !5
  %31 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %30, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 413, ptr noundef @__FUNCTION__.tls13_supported_versions_ext_print) #4
  br label %32

32:                                               ; preds = %29
  br label %33

33:                                               ; preds = %32
  store i32 -1, ptr %7, align 4
  store i32 1, ptr %17, align 4
  br label %105

34:                                               ; preds = %19
  %35 = load i64, ptr %15, align 8, !tbaa !11
  %36 = icmp ult i64 %35, 2
  br i1 %36, label %40, label %37

37:                                               ; preds = %34
  %38 = load i64, ptr %15, align 8, !tbaa !11
  %39 = icmp ugt i64 %38, 254
  br i1 %39, label %40, label %46

40:                                               ; preds = %37, %34
  br label %41

41:                                               ; preds = %40
  %42 = load ptr, ptr @stderr, align 8, !tbaa !5
  %43 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %42, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 417, ptr noundef @__FUNCTION__.tls13_supported_versions_ext_print) #4
  br label %44

44:                                               ; preds = %41
  br label %45

45:                                               ; preds = %44
  store i32 -1, ptr %7, align 4
  store i32 1, ptr %17, align 4
  br label %105

46:                                               ; preds = %37
  br label %47

47:                                               ; preds = %59, %46
  %48 = load i64, ptr %15, align 8, !tbaa !11
  %49 = icmp ne i64 %48, 0
  br i1 %49, label %50, label %69

50:                                               ; preds = %47
  %51 = call i32 @tls_uint16_from_bytes(ptr noundef %16, ptr noundef %14, ptr noundef %15)
  %52 = icmp ne i32 %51, 1
  br i1 %52, label %53, label %59

53:                                               ; preds = %50
  br label %54

54:                                               ; preds = %53
  %55 = load ptr, ptr @stderr, align 8, !tbaa !5
  %56 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %55, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 422, ptr noundef @__FUNCTION__.tls13_supported_versions_ext_print) #4
  br label %57

57:                                               ; preds = %54
  br label %58

58:                                               ; preds = %57
  store i32 -1, ptr %7, align 4
  store i32 1, ptr %17, align 4
  br label %105

59:                                               ; preds = %50
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  %61 = load i32, ptr %9, align 4, !tbaa !9
  %62 = load i32, ptr %10, align 4, !tbaa !9
  %63 = load i16, ptr %16, align 2, !tbaa !13
  %64 = zext i16 %63 to i32
  %65 = call ptr @tls_protocol_name(i32 noundef %64)
  %66 = load i16, ptr %16, align 2, !tbaa !13
  %67 = zext i16 %66 to i32
  %68 = call i32 (ptr, i32, i32, ptr, ...) @format_print(ptr noundef %60, i32 noundef %61, i32 noundef %62, ptr noundef @.str.4, ptr noundef %65, i32 noundef %67)
  br label %47, !llvm.loop !15

69:                                               ; preds = %47
  br label %95

70:                                               ; preds = %6, %6
  %71 = call i32 @tls_uint16_from_bytes(ptr noundef %16, ptr noundef %12, ptr noundef %13)
  %72 = icmp ne i32 %71, 1
  br i1 %72, label %73, label %79

73:                                               ; preds = %70
  br label %74

74:                                               ; preds = %73
  %75 = load ptr, ptr @stderr, align 8, !tbaa !5
  %76 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %75, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 432, ptr noundef @__FUNCTION__.tls13_supported_versions_ext_print) #4
  br label %77

77:                                               ; preds = %74
  br label %78

78:                                               ; preds = %77
  store i32 -1, ptr %7, align 4
  store i32 1, ptr %17, align 4
  br label %105

79:                                               ; preds = %70
  %80 = load ptr, ptr %8, align 8, !tbaa !5
  %81 = load i32, ptr %9, align 4, !tbaa !9
  %82 = load i32, ptr %10, align 4, !tbaa !9
  %83 = load i16, ptr %16, align 2, !tbaa !13
  %84 = zext i16 %83 to i32
  %85 = call ptr @tls_protocol_name(i32 noundef %84)
  %86 = load i16, ptr %16, align 2, !tbaa !13
  %87 = zext i16 %86 to i32
  %88 = call i32 (ptr, i32, i32, ptr, ...) @format_print(ptr noundef %80, i32 noundef %81, i32 noundef %82, ptr noundef @.str.5, ptr noundef %85, i32 noundef %87)
  br label %95

89:                                               ; preds = %6
  br label %90

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

93:                                               ; preds = %90
  br label %94

94:                                               ; preds = %93
  store i32 -1, ptr %7, align 4
  store i32 1, ptr %17, align 4
  br label %105

95:                                               ; preds = %79, %69
  %96 = load i64, ptr %13, align 8, !tbaa !11
  %97 = icmp ne i64 %96, 0
  br i1 %97, label %98, label %104

98:                                               ; preds = %95
  br label %99

99:                                               ; preds = %98
  %100 = load ptr, ptr @stderr, align 8, !tbaa !5
  %101 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %100, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 444, ptr noundef @__FUNCTION__.tls13_supported_versions_ext_print) #4
  br label %102

102:                                              ; preds = %99
  br label %103

103:                                              ; preds = %102
  store i32 -1, ptr %7, align 4
  store i32 1, ptr %17, align 4
  br label %105

104:                                              ; preds = %95
  store i32 1, ptr %7, align 4
  store i32 1, ptr %17, align 4
  br label %105

105:                                              ; preds = %104, %103, %94, %78, %58, %45, %33
  call void @llvm.lifetime.end.p0(i64 2, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  %106 = load i32, ptr %7, align 4
  ret i32 %106
}

declare i32 @format_print(ptr noundef, i32 noundef, i32 noundef, ptr noundef, ...) #2

declare ptr @tls_protocol_name(i32 noundef) #2

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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !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
@.str.3 = external hidden unnamed_addr constant [10 x i8], align 1
@__FUNCTION__.tls13_supported_versions_ext_print = external hidden unnamed_addr constant [35 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [31 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_uint16_from_bytes(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @tls13_supported_versions_ext_print(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef %4, i64 noundef %5) local_unnamed_addr #3 {
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i16, align 2
  store ptr %4, ptr %7, align 8, !tbaa !5
  store i64 %5, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %9) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %10) #4
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %11) #4
  switch i32 %3, label %48 [
    i32 1, label %12
    i32 2, label %36
    i32 6, label %36
  ]

12:                                               ; preds = %6
  %13 = tail call i32 (ptr, i32, i32, ptr, ...) @format_print(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef nonnull @.str.3) #4
  %14 = add nsw i32 %2, 4
  %15 = call i32 @tls_uint8array_from_bytes(ptr noundef nonnull %9, ptr noundef nonnull %10, ptr noundef nonnull %7, ptr noundef nonnull %8) #4
  %.not12 = icmp eq i32 %15, 1
  br i1 %.not12, label %19, label %16

16:                                               ; preds = %12
  %17 = load ptr, ptr @stderr, align 8, !tbaa !5
  %18 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %17, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 413, ptr noundef nonnull @__FUNCTION__.tls13_supported_versions_ext_print) #5
  br label %55

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

22:                                               ; preds = %19
  %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 417, ptr noundef nonnull @__FUNCTION__.tls13_supported_versions_ext_print) #5
  br label %55

.lr.ph:                                           ; preds = %19, %29
  %25 = call i32 @tls_uint16_from_bytes(ptr noundef nonnull %11, ptr noundef nonnull %9, ptr noundef nonnull %10) #4
  %.not15 = icmp eq i32 %25, 1
  br i1 %.not15, label %29, label %26

26:                                               ; preds = %.lr.ph
  %27 = load ptr, ptr @stderr, align 8, !tbaa !5
  %28 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %27, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 422, ptr noundef nonnull @__FUNCTION__.tls13_supported_versions_ext_print) #5
  br label %55

29:                                               ; preds = %.lr.ph
  %30 = load i16, ptr %11, align 2, !tbaa !11
  %31 = zext i16 %30 to i32
  %32 = call ptr @tls_protocol_name(i32 noundef %31) #4
  %33 = load i16, ptr %11, align 2, !tbaa !11
  %34 = zext i16 %33 to i32
  %35 = call i32 (ptr, i32, i32, ptr, ...) @format_print(ptr noundef %0, i32 noundef %1, i32 noundef %14, ptr noundef nonnull @.str.4, ptr noundef %32, i32 noundef %34) #4
  %.pr = load i64, ptr %10, align 8, !tbaa !9
  %.not13 = icmp eq i64 %.pr, 0
  br i1 %.not13, label %.loopexit, label %.lr.ph, !llvm.loop !13

36:                                               ; preds = %6, %6
  %37 = call i32 @tls_uint16_from_bytes(ptr noundef nonnull %11, ptr noundef nonnull %7, ptr noundef nonnull %8) #4
  %.not = icmp eq i32 %37, 1
  br i1 %.not, label %41, label %38

38:                                               ; preds = %36
  %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 432, ptr noundef nonnull @__FUNCTION__.tls13_supported_versions_ext_print) #5
  br label %55

41:                                               ; preds = %36
  %42 = load i16, ptr %11, align 2, !tbaa !11
  %43 = zext i16 %42 to i32
  %44 = call ptr @tls_protocol_name(i32 noundef %43) #4
  %45 = load i16, ptr %11, align 2, !tbaa !11
  %46 = zext i16 %45 to i32
  %47 = call i32 (ptr, i32, i32, ptr, ...) @format_print(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef nonnull @.str.5, ptr noundef %44, i32 noundef %46) #4
  br label %.loopexit

48:                                               ; preds = %6
  %49 = load ptr, ptr @stderr, align 8, !tbaa !5
  %50 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %49, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 439, ptr noundef nonnull @__FUNCTION__.tls13_supported_versions_ext_print) #5
  br label %55

.loopexit:                                        ; preds = %29, %41
  %51 = load i64, ptr %8, align 8, !tbaa !9
  %.not14 = icmp eq i64 %51, 0
  br i1 %.not14, label %55, label %52

52:                                               ; preds = %.loopexit
  %53 = load ptr, ptr @stderr, align 8, !tbaa !5
  %54 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %53, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 444, ptr noundef nonnull @__FUNCTION__.tls13_supported_versions_ext_print) #5
  br label %55

55:                                               ; preds = %.loopexit, %52, %48, %38, %26, %22, %16
  %.0 = phi i32 [ -1, %48 ], [ -1, %38 ], [ -1, %52 ], [ -1, %16 ], [ -1, %22 ], [ -1, %26 ], [ 1, %.loopexit ]
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %9) #4
  ret i32 %.0
}

declare i32 @format_print(ptr noundef, i32 noundef, i32 noundef, ptr noundef, ...) local_unnamed_addr #2

declare ptr @tls_protocol_name(i32 noundef) local_unnamed_addr #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 = !{!"short", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass