; 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_server_hello_exts = external hidden unnamed_addr constant [30 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

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @tls_ext_from_bytes(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

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

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

22:                                               ; preds = %19
  %23 = call i32 @tls_ext_from_bytes(ptr noundef %12, ptr noundef %13, ptr noundef %14, ptr noundef %7, ptr noundef %8)
  %24 = icmp ne i32 %23, 1
  br i1 %24, label %25, label %31

25:                                               ; preds = %22
  br label %26

26:                                               ; preds = %25
  %27 = load ptr, ptr @stderr, align 8, !tbaa !5
  %28 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %27, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 877, ptr noundef @__FUNCTION__.tls_process_server_hello_exts) #3
  br label %29

29:                                               ; preds = %26
  br label %30

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

31:                                               ; preds = %22
  %32 = load i32, ptr %12, align 4, !tbaa !11
  switch i32 %32, label %72 [
    i32 11, label %33
    i32 13, label %46
    i32 10, label %59
  ]

33:                                               ; preds = %31
  %34 = load ptr, ptr %13, align 8, !tbaa !5
  %35 = load i64, ptr %14, align 8, !tbaa !9
  %36 = call i32 @tls_process_server_ec_point_formats(ptr noundef %34, i64 noundef %35)
  %37 = icmp ne i32 %36, 1
  br i1 %37, label %38, label %44

38:                                               ; preds = %33
  br label %39

39:                                               ; preds = %38
  %40 = load ptr, ptr @stderr, align 8, !tbaa !5
  %41 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %40, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 884, ptr noundef @__FUNCTION__.tls_process_server_hello_exts) #3
  br label %42

42:                                               ; preds = %39
  br label %43

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

44:                                               ; preds = %33
  %45 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 0, ptr %45, align 4, !tbaa !11
  br label %78

46:                                               ; preds = %31
  %47 = load ptr, ptr %13, align 8, !tbaa !5
  %48 = load i64, ptr %14, align 8, !tbaa !9
  %49 = call i32 @tls_process_server_signature_algors(ptr noundef %47, i64 noundef %48)
  %50 = icmp ne i32 %49, 1
  br i1 %50, label %51, label %57

51:                                               ; preds = %46
  br label %52

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

55:                                               ; preds = %52
  br label %56

56:                                               ; preds = %55
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %80

57:                                               ; preds = %46
  %58 = load ptr, ptr %10, align 8, !tbaa !5
  store i32 41, ptr %58, align 4, !tbaa !11
  br label %78

59:                                               ; preds = %31
  %60 = load ptr, ptr %13, align 8, !tbaa !5
  %61 = load i64, ptr %14, align 8, !tbaa !9
  %62 = call i32 @tls_process_server_supported_groups(ptr noundef %60, i64 noundef %61)
  %63 = icmp ne i32 %62, 1
  br i1 %63, label %64, label %70

64:                                               ; preds = %59
  br label %65

65:                                               ; preds = %64
  %66 = load ptr, ptr @stderr, align 8, !tbaa !5
  %67 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %66, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 898, ptr noundef @__FUNCTION__.tls_process_server_hello_exts) #3
  br label %68

68:                                               ; preds = %65
  br label %69

69:                                               ; preds = %68
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %80

70:                                               ; preds = %59
  %71 = load ptr, ptr %11, align 8, !tbaa !5
  store i32 1800, ptr %71, align 4, !tbaa !11
  br label %78

72:                                               ; preds = %31
  br label %73

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

76:                                               ; preds = %73
  br label %77

77:                                               ; preds = %76
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %80

78:                                               ; preds = %70, %57, %44
  br label %19, !llvm.loop !13

79:                                               ; preds = %19
  store i32 1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %80

80:                                               ; preds = %79, %77, %69, %56, %43, %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  %81 = load i32, ptr %6, align 4
  ret i32 %81
}

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 = { 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 = { 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 = distinct !{!13, !14}
!14 = !{!"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_server_hello_exts = external hidden unnamed_addr constant [30 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

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @tls_ext_from_bytes(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @tls_process_server_hello_exts(ptr noundef %0, i64 noundef %1, ptr nocapture noundef writeonly %2, ptr nocapture noundef writeonly %3, ptr nocapture noundef writeonly %4) local_unnamed_addr #2 {
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %10) #3
  store i32 -1, ptr %2, align 4, !tbaa !11
  store i32 -1, ptr %3, align 4, !tbaa !11
  store i32 -1, ptr %4, align 4, !tbaa !11
  %.not10 = icmp eq i64 %1, 0
  br i1 %.not10, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %5, %29
  %11 = call i32 @tls_ext_from_bytes(ptr noundef nonnull %8, ptr noundef nonnull %9, ptr noundef nonnull %10, ptr noundef nonnull %6, ptr noundef nonnull %7)
  %.not6 = icmp eq i32 %11, 1
  br i1 %.not6, label %12, label %.loopexit.sink.split

12:                                               ; preds = %.lr.ph
  %13 = load i32, ptr %8, align 4, !tbaa !11
  switch i32 %13, label %.loopexit.sink.split [
    i32 11, label %14
    i32 13, label %19
    i32 10, label %24
  ]

14:                                               ; preds = %12
  %15 = load ptr, ptr %9, align 8, !tbaa !5
  %16 = load i64, ptr %10, align 8, !tbaa !9
  %17 = call i32 @tls_process_server_ec_point_formats(ptr noundef %15, i64 noundef %16)
  %.not9 = icmp eq i32 %17, 1
  br i1 %.not9, label %18, label %.loopexit.sink.split

18:                                               ; preds = %14
  store i32 0, ptr %2, align 4, !tbaa !11
  br label %29

19:                                               ; preds = %12
  %20 = load ptr, ptr %9, align 8, !tbaa !5
  %21 = load i64, ptr %10, align 8, !tbaa !9
  %22 = call i32 @tls_process_server_signature_algors(ptr noundef %20, i64 noundef %21)
  %.not8 = icmp eq i32 %22, 1
  br i1 %.not8, label %23, label %.loopexit.sink.split

23:                                               ; preds = %19
  store i32 41, ptr %3, align 4, !tbaa !11
  br label %29

24:                                               ; preds = %12
  %25 = load ptr, ptr %9, align 8, !tbaa !5
  %26 = load i64, ptr %10, align 8, !tbaa !9
  %27 = call i32 @tls_process_server_supported_groups(ptr noundef %25, i64 noundef %26)
  %.not7 = icmp eq i32 %27, 1
  br i1 %.not7, label %28, label %.loopexit.sink.split

28:                                               ; preds = %24
  store i32 1800, ptr %4, align 4, !tbaa !11
  br label %29

29:                                               ; preds = %28, %23, %18
  %30 = load i64, ptr %7, align 8, !tbaa !9
  %.not = icmp eq i64 %30, 0
  br i1 %.not, label %.loopexit, label %.lr.ph, !llvm.loop !13

.loopexit.sink.split:                             ; preds = %12, %24, %19, %14, %.lr.ph
  %.sink11 = phi i32 [ 877, %.lr.ph ], [ 884, %14 ], [ 891, %19 ], [ 898, %24 ], [ 904, %12 ]
  %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 %.sink11, ptr noundef nonnull @__FUNCTION__.tls_process_server_hello_exts) #4
  br label %.loopexit

.loopexit:                                        ; preds = %29, %.loopexit.sink.split, %5
  %.0 = phi i32 [ 1, %5 ], [ -1, %.loopexit.sink.split ], [ 1, %29 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %8) #3
  ret i32 %.0
}

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 = { 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 = { nounwind }
attributes #4 = { 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 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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