; 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__.tls_process_client_ec_point_formats = external hidden unnamed_addr constant [36 x i8], align 1

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

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

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

declare ptr @tls_ec_point_format_name(i32 noundef) #3

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

; Function Attrs: nounwind uwtable
define dso_local i32 @tls_process_client_ec_point_formats(ptr noundef %0, i64 noundef %1, ptr noundef %2, ptr noundef %3) #0 {
  %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 [1 x i32], align 4
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca i32, align 4
  %15 = alloca i8, align 1
  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 4, ptr %10) #5
  call void @llvm.memset.p0.i64(ptr align 4 %10, i8 0, i64 4, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  store i64 0, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  %16 = call i32 @tls_uint8array_from_bytes(ptr noundef %12, ptr noundef %13, ptr noundef %6, ptr noundef %7)
  %17 = icmp ne i32 %16, 1
  br i1 %17, label %22, label %18

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

22:                                               ; preds = %18, %4
  br label %23

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

26:                                               ; preds = %23
  br label %27

27:                                               ; preds = %26
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %86

28:                                               ; preds = %18
  br label %29

29:                                               ; preds = %62, %28
  %30 = load i64, ptr %13, align 8, !tbaa !9
  %31 = icmp ne i64 %30, 0
  br i1 %31, label %32, label %63

32:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 1, ptr %15) #5
  %33 = call i32 @tls_uint8_from_bytes(ptr noundef %15, ptr noundef %12, ptr noundef %13)
  %34 = icmp ne i32 %33, 1
  br i1 %34, label %35, label %41

35:                                               ; preds = %32
  br label %36

36:                                               ; preds = %35
  %37 = load ptr, ptr @stderr, align 8, !tbaa !5
  %38 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %37, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 89, ptr noundef @__FUNCTION__.tls_process_client_ec_point_formats) #5
  br label %39

39:                                               ; preds = %36
  br label %40

40:                                               ; preds = %39
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %60

41:                                               ; preds = %32
  %42 = load i8, ptr %15, align 1, !tbaa !11
  %43 = zext i8 %42 to i32
  %44 = call ptr @tls_ec_point_format_name(i32 noundef %43)
  %45 = icmp ne ptr %44, null
  br i1 %45, label %52, label %46

46:                                               ; preds = %41
  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 93, ptr noundef @__FUNCTION__.tls_process_client_ec_point_formats) #5
  br label %50

50:                                               ; preds = %47
  br label %51

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

52:                                               ; preds = %41
  %53 = load i8, ptr %15, align 1, !tbaa !11
  %54 = zext i8 %53 to i32
  %55 = getelementptr inbounds [1 x i32], ptr %10, i64 0, i64 0
  %56 = load i32, ptr %55, align 4, !tbaa !12
  %57 = icmp eq i32 %54, %56
  br i1 %57, label %58, label %59

58:                                               ; preds = %52
  store i64 1, ptr %11, align 8, !tbaa !9
  br label %59

59:                                               ; preds = %58, %52
  store i32 0, ptr %14, align 4
  br label %60

60:                                               ; preds = %59, %51, %40
  call void @llvm.lifetime.end.p0(i64 1, ptr %15) #5
  %61 = load i32, ptr %14, align 4
  switch i32 %61, label %86 [
    i32 0, label %62
  ]

62:                                               ; preds = %60
  br label %29, !llvm.loop !14

63:                                               ; preds = %29
  %64 = load i64, ptr %11, align 8, !tbaa !9
  %65 = icmp ne i64 %64, 0
  br i1 %65, label %72, label %66

66:                                               ; preds = %63
  br label %67

67:                                               ; preds = %66
  %68 = load ptr, ptr @stderr, align 8, !tbaa !5
  %69 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %68, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 101, ptr noundef @__FUNCTION__.tls_process_client_ec_point_formats) #5
  br label %70

70:                                               ; preds = %67
  br label %71

71:                                               ; preds = %70
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %86

72:                                               ; preds = %63
  %73 = getelementptr inbounds [1 x i32], ptr %10, i64 0, i64 0
  %74 = load i64, ptr %11, align 8, !tbaa !9
  %75 = load ptr, ptr %8, align 8, !tbaa !5
  %76 = load ptr, ptr %9, align 8, !tbaa !5
  %77 = call i32 @tls_ec_point_formats_ext_to_bytes(ptr noundef %73, i64 noundef %74, ptr noundef %75, ptr noundef %76)
  %78 = icmp ne i32 %77, 1
  br i1 %78, label %79, label %85

79:                                               ; preds = %72
  br label %80

80:                                               ; preds = %79
  %81 = load ptr, ptr @stderr, align 8, !tbaa !5
  %82 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %81, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 105, ptr noundef @__FUNCTION__.tls_process_client_ec_point_formats) #5
  br label %83

83:                                               ; preds = %80
  br label %84

84:                                               ; preds = %83
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %86

85:                                               ; preds = %72
  store i32 1, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %86

86:                                               ; preds = %85, %84, %71, %60, %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  %87 = load i32, ptr %5, align 4
  ret i32 %87
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

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

declare i32 @tls_length_is_zero(i64 noundef) #3

declare i32 @tls_uint8_from_bytes(ptr noundef, 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 willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !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 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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__.tls_process_client_ec_point_formats = external hidden unnamed_addr constant [36 x i8], align 1

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

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

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

declare ptr @tls_ec_point_format_name(i32 noundef) local_unnamed_addr #3

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @tls_process_client_ec_point_formats(ptr noundef %0, i64 noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca [1 x i32], align 4
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i8, align 1
  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 4, ptr nonnull %7) #4
  store i32 0, ptr %7, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %9) #4
  %11 = call i32 @tls_uint8array_from_bytes(ptr noundef nonnull %8, ptr noundef nonnull %9, ptr noundef nonnull %5, ptr noundef nonnull %6) #4
  %.not = icmp eq i32 %11, 1
  br i1 %.not, label %12, label %16

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

.preheader:                                       ; preds = %12
  %15 = load i64, ptr %9, align 8, !tbaa !9
  %.not1019 = icmp eq i64 %15, 0
  br i1 %.not1019, label %._crit_edge.thread, label %.lr.ph

16:                                               ; preds = %4, %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 83, ptr noundef nonnull @__FUNCTION__.tls_process_client_ec_point_formats) #5
  br label %38

.lr.ph:                                           ; preds = %.preheader, %26
  %.0520 = phi i64 [ %spec.select, %26 ], [ 0, %.preheader ]
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %10) #4
  %19 = call i32 @tls_uint8_from_bytes(ptr noundef nonnull %10, ptr noundef nonnull %8, ptr noundef nonnull %9) #4
  %.not13 = icmp eq i32 %19, 1
  br i1 %.not13, label %20, label %.thread

20:                                               ; preds = %.lr.ph
  %21 = load i8, ptr %10, align 1, !tbaa !11
  %22 = zext i8 %21 to i32
  %23 = call ptr @tls_ec_point_format_name(i32 noundef %22) #4
  %.not14 = icmp eq ptr %23, null
  br i1 %.not14, label %.thread, label %26

.thread:                                          ; preds = %20, %.lr.ph
  %.sink22 = phi i32 [ 89, %.lr.ph ], [ 93, %20 ]
  %24 = load ptr, ptr @stderr, align 8, !tbaa !5
  %25 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %24, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef %.sink22, ptr noundef nonnull @__FUNCTION__.tls_process_client_ec_point_formats) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %10) #4
  br label %38

26:                                               ; preds = %20
  %27 = load i8, ptr %10, align 1, !tbaa !11
  %28 = icmp eq i8 %27, 0
  %spec.select = select i1 %28, i64 1, i64 %.0520
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %10) #4
  %29 = load i64, ptr %9, align 8, !tbaa !9
  %.not10 = icmp eq i64 %29, 0
  br i1 %.not10, label %._crit_edge, label %.lr.ph, !llvm.loop !12

._crit_edge:                                      ; preds = %26
  %30 = icmp eq i64 %spec.select, 0
  br i1 %30, label %._crit_edge.thread, label %33

._crit_edge.thread:                               ; preds = %.preheader, %._crit_edge
  %31 = load ptr, ptr @stderr, align 8, !tbaa !5
  %32 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %31, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 101, ptr noundef nonnull @__FUNCTION__.tls_process_client_ec_point_formats) #5
  br label %38

33:                                               ; preds = %._crit_edge
  %34 = call i32 @tls_ec_point_formats_ext_to_bytes(ptr noundef nonnull %7, i64 noundef 1, ptr noundef %2, ptr noundef %3)
  %.not12 = icmp eq i32 %34, 1
  br i1 %.not12, label %38, label %35

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

38:                                               ; preds = %.thread, %33, %35, %._crit_edge.thread, %16
  %.28 = phi i32 [ -1, %16 ], [ -1, %35 ], [ -1, %._crit_edge.thread ], [ 1, %33 ], [ -1, %.thread ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #4
  ret i32 %.28
}

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

declare i32 @tls_length_is_zero(i64 noundef) local_unnamed_addr #3

declare i32 @tls_uint8_from_bytes(ptr noundef, 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 willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 }
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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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