; 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_supported_versions_ext_to_bytes = external hidden unnamed_addr constant [38 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

declare void @tls_uint16_to_bytes(i16 noundef zeroext, ptr noundef, ptr noundef) #2

declare void @tls_uint8_to_bytes(i8 noundef zeroext, ptr noundef, ptr noundef) #2

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

declare ptr @tls_protocol_name(i32 noundef) #2

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

20:                                               ; preds = %5
  %21 = load i64, ptr %9, align 8, !tbaa !11
  %22 = icmp ne i64 %21, 0
  br i1 %22, label %23, label %26

23:                                               ; preds = %20
  %24 = load ptr, ptr %11, align 8, !tbaa !9
  %25 = icmp ne ptr %24, null
  br i1 %25, label %32, label %26

26:                                               ; preds = %23, %20, %5
  br label %27

27:                                               ; preds = %26
  %28 = load ptr, ptr @stderr, align 8, !tbaa !9
  %29 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %28, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 458, ptr noundef @__FUNCTION__.tls13_supported_versions_ext_to_bytes) #4
  br label %30

30:                                               ; preds = %27
  br label %31

31:                                               ; preds = %30
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %123

32:                                               ; preds = %23
  %33 = load i32, ptr %7, align 4, !tbaa !5
  switch i32 %33, label %116 [
    i32 1, label %34
    i32 2, label %90
    i32 6, label %90
  ]

34:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %35 = load i64, ptr %9, align 8, !tbaa !11
  %36 = icmp ugt i64 %35, 127
  br i1 %36, label %37, label %43

37:                                               ; preds = %34
  br label %38

38:                                               ; preds = %37
  %39 = load ptr, ptr @stderr, align 8, !tbaa !9
  %40 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %39, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 466, ptr noundef @__FUNCTION__.tls13_supported_versions_ext_to_bytes) #4
  br label %41

41:                                               ; preds = %38
  br label %42

42:                                               ; preds = %41
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %88

43:                                               ; preds = %34
  %44 = load i64, ptr %9, align 8, !tbaa !11
  %45 = mul i64 2, %44
  store i64 %45, ptr %16, align 8, !tbaa !11
  %46 = load i64, ptr %16, align 8, !tbaa !11
  %47 = add i64 1, %46
  store i64 %47, ptr %13, align 8, !tbaa !11
  %48 = load i16, ptr %12, align 2, !tbaa !13
  %49 = load ptr, ptr %10, align 8, !tbaa !9
  %50 = load ptr, ptr %11, align 8, !tbaa !9
  call void @tls_uint16_to_bytes(i16 noundef zeroext %48, ptr noundef %49, ptr noundef %50)
  %51 = load i64, ptr %13, align 8, !tbaa !11
  %52 = trunc i64 %51 to i16
  %53 = load ptr, ptr %10, align 8, !tbaa !9
  %54 = load ptr, ptr %11, align 8, !tbaa !9
  call void @tls_uint16_to_bytes(i16 noundef zeroext %52, ptr noundef %53, ptr noundef %54)
  %55 = load i64, ptr %16, align 8, !tbaa !11
  %56 = trunc i64 %55 to i8
  %57 = load ptr, ptr %10, align 8, !tbaa !9
  %58 = load ptr, ptr %11, align 8, !tbaa !9
  call void @tls_uint8_to_bytes(i8 noundef zeroext %56, ptr noundef %57, ptr noundef %58)
  store i64 0, ptr %14, align 8, !tbaa !11
  br label %59

59:                                               ; preds = %84, %43
  %60 = load i64, ptr %14, align 8, !tbaa !11
  %61 = load i64, ptr %9, align 8, !tbaa !11
  %62 = icmp ult i64 %60, %61
  br i1 %62, label %63, label %87

63:                                               ; preds = %59
  %64 = load ptr, ptr %8, align 8, !tbaa !9
  %65 = load i64, ptr %14, align 8, !tbaa !11
  %66 = getelementptr inbounds i32, ptr %64, i64 %65
  %67 = load i32, ptr %66, align 4, !tbaa !5
  %68 = call ptr @tls_protocol_name(i32 noundef %67)
  %69 = icmp ne ptr %68, null
  br i1 %69, label %76, label %70

70:                                               ; preds = %63
  br label %71

71:                                               ; preds = %70
  %72 = load ptr, ptr @stderr, align 8, !tbaa !9
  %73 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %72, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 476, ptr noundef @__FUNCTION__.tls13_supported_versions_ext_to_bytes) #4
  br label %74

74:                                               ; preds = %71
  br label %75

75:                                               ; preds = %74
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %88

76:                                               ; preds = %63
  %77 = load ptr, ptr %8, align 8, !tbaa !9
  %78 = load i64, ptr %14, align 8, !tbaa !11
  %79 = getelementptr inbounds i32, ptr %77, i64 %78
  %80 = load i32, ptr %79, align 4, !tbaa !5
  %81 = trunc i32 %80 to i16
  %82 = load ptr, ptr %10, align 8, !tbaa !9
  %83 = load ptr, ptr %11, align 8, !tbaa !9
  call void @tls_uint16_to_bytes(i16 noundef zeroext %81, ptr noundef %82, ptr noundef %83)
  br label %84

84:                                               ; preds = %76
  %85 = load i64, ptr %14, align 8, !tbaa !11
  %86 = add i64 %85, 1
  store i64 %86, ptr %14, align 8, !tbaa !11
  br label %59, !llvm.loop !15

87:                                               ; preds = %59
  store i32 4, ptr %15, align 4
  br label %88

88:                                               ; preds = %87, %75, %42
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  %89 = load i32, ptr %15, align 4
  switch i32 %89, label %123 [
    i32 4, label %122
  ]

90:                                               ; preds = %32, %32
  call void @llvm.lifetime.start.p0(i64 2, ptr %17) #4
  %91 = load i64, ptr %9, align 8, !tbaa !11
  %92 = icmp ugt i64 %91, 1
  br i1 %92, label %93, label %99

93:                                               ; preds = %90
  br label %94

94:                                               ; preds = %93
  %95 = load ptr, ptr @stderr, align 8, !tbaa !9
  %96 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %95, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 488, ptr noundef @__FUNCTION__.tls13_supported_versions_ext_to_bytes) #4
  br label %97

97:                                               ; preds = %94
  br label %98

98:                                               ; preds = %97
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %114

99:                                               ; preds = %90
  %100 = load ptr, ptr %8, align 8, !tbaa !9
  %101 = getelementptr inbounds i32, ptr %100, i64 0
  %102 = load i32, ptr %101, align 4, !tbaa !5
  %103 = trunc i32 %102 to i16
  store i16 %103, ptr %17, align 2, !tbaa !13
  store i64 2, ptr %13, align 8, !tbaa !11
  %104 = load i16, ptr %12, align 2, !tbaa !13
  %105 = load ptr, ptr %10, align 8, !tbaa !9
  %106 = load ptr, ptr %11, align 8, !tbaa !9
  call void @tls_uint16_to_bytes(i16 noundef zeroext %104, ptr noundef %105, ptr noundef %106)
  %107 = load i64, ptr %13, align 8, !tbaa !11
  %108 = trunc i64 %107 to i16
  %109 = load ptr, ptr %10, align 8, !tbaa !9
  %110 = load ptr, ptr %11, align 8, !tbaa !9
  call void @tls_uint16_to_bytes(i16 noundef zeroext %108, ptr noundef %109, ptr noundef %110)
  %111 = load i16, ptr %17, align 2, !tbaa !13
  %112 = load ptr, ptr %10, align 8, !tbaa !9
  %113 = load ptr, ptr %11, align 8, !tbaa !9
  call void @tls_uint16_to_bytes(i16 noundef zeroext %111, ptr noundef %112, ptr noundef %113)
  store i32 4, ptr %15, align 4
  br label %114

114:                                              ; preds = %99, %98
  call void @llvm.lifetime.end.p0(i64 2, ptr %17) #4
  %115 = load i32, ptr %15, align 4
  switch i32 %115, label %123 [
    i32 4, label %122
  ]

116:                                              ; preds = %32
  br label %117

117:                                              ; preds = %116
  %118 = load ptr, ptr @stderr, align 8, !tbaa !9
  %119 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %118, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 499, ptr noundef @__FUNCTION__.tls13_supported_versions_ext_to_bytes) #4
  br label %120

120:                                              ; preds = %117
  br label %121

121:                                              ; preds = %120
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %123

122:                                              ; preds = %114, %88
  store i32 1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %123

123:                                              ; preds = %122, %121, %114, %88, %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr %12) #4
  %124 = load i32, ptr %6, align 4
  ret i32 %124
}

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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !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
@__FUNCTION__.tls13_supported_versions_ext_to_bytes = external hidden unnamed_addr constant [38 x i8], align 1

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

declare void @tls_uint16_to_bytes(i16 noundef zeroext, ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @tls_uint8_to_bytes(i8 noundef zeroext, ptr noundef, ptr noundef) local_unnamed_addr #1

declare ptr @tls_protocol_name(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @tls13_supported_versions_ext_to_bytes(i32 noundef %0, ptr noundef readonly %1, i64 noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #2 {
  %6 = icmp ne ptr %1, null
  %7 = icmp ne i64 %2, 0
  %or.cond = and i1 %6, %7
  %8 = icmp ne ptr %4, null
  %or.cond4 = and i1 %or.cond, %8
  br i1 %or.cond4, label %12, label %9

9:                                                ; preds = %5
  %10 = load ptr, ptr @stderr, align 8, !tbaa !5
  %11 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %10, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 458, ptr noundef nonnull @__FUNCTION__.tls13_supported_versions_ext_to_bytes) #3
  br label %.critedge

12:                                               ; preds = %5
  switch i32 %0, label %41 [
    i32 1, label %13
    i32 2, label %34
    i32 6, label %34
  ]

13:                                               ; preds = %12
  %14 = icmp ugt i64 %2, 127
  br i1 %14, label %15, label %18

15:                                               ; preds = %13
  %16 = load ptr, ptr @stderr, align 8, !tbaa !5
  %17 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %16, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 466, ptr noundef nonnull @__FUNCTION__.tls13_supported_versions_ext_to_bytes) #3
  br label %.critedge

18:                                               ; preds = %13
  %19 = shl nuw nsw i64 %2, 1
  tail call void @tls_uint16_to_bytes(i16 noundef zeroext 43, ptr noundef %3, ptr noundef nonnull %4) #4
  %20 = trunc nuw i64 %19 to i16
  %21 = or disjoint i16 %20, 1
  tail call void @tls_uint16_to_bytes(i16 noundef zeroext %21, ptr noundef %3, ptr noundef nonnull %4) #4
  %22 = trunc nuw i64 %19 to i8
  tail call void @tls_uint8_to_bytes(i8 noundef zeroext %22, ptr noundef %3, ptr noundef nonnull %4) #4
  br label %23

23:                                               ; preds = %18, %30
  %.04447 = phi i64 [ 0, %18 ], [ %33, %30 ]
  %24 = getelementptr inbounds i32, ptr %1, i64 %.04447
  %25 = load i32, ptr %24, align 4, !tbaa !9
  %26 = tail call ptr @tls_protocol_name(i32 noundef %25) #4
  %.not = icmp eq ptr %26, null
  br i1 %.not, label %27, label %30

27:                                               ; preds = %23
  %28 = load ptr, ptr @stderr, align 8, !tbaa !5
  %29 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %28, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 476, ptr noundef nonnull @__FUNCTION__.tls13_supported_versions_ext_to_bytes) #3
  br label %.critedge

30:                                               ; preds = %23
  %31 = load i32, ptr %24, align 4, !tbaa !9
  %32 = trunc i32 %31 to i16
  tail call void @tls_uint16_to_bytes(i16 noundef zeroext %32, ptr noundef %3, ptr noundef nonnull %4) #4
  %33 = add nuw i64 %.04447, 1
  %exitcond.not = icmp eq i64 %33, %2
  br i1 %exitcond.not, label %.critedge, label %23, !llvm.loop !11

34:                                               ; preds = %12, %12
  %35 = icmp ult i64 %2, 2
  br i1 %35, label %.thread, label %38

.thread:                                          ; preds = %34
  %36 = load i32, ptr %1, align 4, !tbaa !9
  %37 = trunc i32 %36 to i16
  tail call void @tls_uint16_to_bytes(i16 noundef zeroext 43, ptr noundef %3, ptr noundef nonnull %4) #4
  tail call void @tls_uint16_to_bytes(i16 noundef zeroext 2, ptr noundef %3, ptr noundef nonnull %4) #4
  tail call void @tls_uint16_to_bytes(i16 noundef zeroext %37, ptr noundef %3, ptr noundef nonnull %4) #4
  br label %.critedge

38:                                               ; preds = %34
  %39 = load ptr, ptr @stderr, align 8, !tbaa !5
  %40 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %39, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 488, ptr noundef nonnull @__FUNCTION__.tls13_supported_versions_ext_to_bytes) #3
  br label %.critedge

41:                                               ; preds = %12
  %42 = load ptr, ptr @stderr, align 8, !tbaa !5
  %43 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %42, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 499, ptr noundef nonnull @__FUNCTION__.tls13_supported_versions_ext_to_bytes) #3
  br label %.critedge

.critedge:                                        ; preds = %30, %.thread, %38, %15, %27, %41, %9
  %.2 = phi i32 [ -1, %41 ], [ -1, %38 ], [ -1, %9 ], [ -1, %27 ], [ -1, %15 ], [ 1, %.thread ], [ 1, %30 ]
  ret i32 %.2
}

attributes #0 = { 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 #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 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 #3 = { cold nounwind }
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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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