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

; 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 [59 x i8], align 1
@__FUNCTION__.tls13_process_client_hello_exts = external hidden unnamed_addr constant [32 x i8], align 1

; Function Attrs: nounwind
declare i32 @fprintf(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: 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 @tls13_process_client_hello_exts(ptr noundef %0, i64 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5, i64 noundef %6) #2 {
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  %16 = alloca i64, align 8
  %17 = alloca i16, align 2
  %18 = alloca ptr, align 8
  %19 = alloca i64, align 8
  %20 = alloca i32, align 4
  store ptr %0, ptr %9, align 8, !tbaa !5
  store i64 %1, ptr %10, align 8, !tbaa !9
  store ptr %2, ptr %11, align 8, !tbaa !5
  store ptr %3, ptr %12, align 8, !tbaa !5
  store ptr %4, ptr %13, align 8, !tbaa !5
  store ptr %5, ptr %14, align 8, !tbaa !5
  store i64 %6, ptr %15, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  store i64 0, ptr %16, align 8, !tbaa !9
  %21 = load ptr, ptr %14, align 8, !tbaa !5
  store i64 0, ptr %21, align 8, !tbaa !9
  br label %22

22:                                               ; preds = %83, %7
  %23 = load i64, ptr %10, align 8, !tbaa !9
  %24 = icmp ne i64 %23, 0
  br i1 %24, label %25, label %84

25:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 2, ptr %17) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #4
  %26 = call i32 @tls_uint16_from_bytes(ptr noundef %17, ptr noundef %9, ptr noundef %10)
  %27 = icmp ne i32 %26, 1
  br i1 %27, label %31, label %28

28:                                               ; preds = %25
  %29 = call i32 @tls_uint16array_from_bytes(ptr noundef %18, ptr noundef %19, ptr noundef %9, ptr noundef %10)
  %30 = icmp ne i32 %29, 1
  br i1 %30, label %31, label %37

31:                                               ; preds = %28, %25
  br label %32

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

35:                                               ; preds = %32
  br label %36

36:                                               ; preds = %35
  store i32 -1, ptr %8, align 4
  store i32 1, ptr %20, align 4
  br label %81

37:                                               ; preds = %28
  %38 = load i16, ptr %17, align 2, !tbaa !11
  %39 = zext i16 %38 to i32
  switch i32 %39, label %79 [
    i32 43, label %40
    i32 51, label %60
  ]

40:                                               ; preds = %37
  %41 = load ptr, ptr %18, align 8, !tbaa !5
  %42 = load i64, ptr %19, align 8, !tbaa !9
  %43 = call i32 @tls13_process_client_supported_versions(ptr noundef %41, i64 noundef %42, ptr noundef null, ptr noundef %16)
  %44 = icmp ne i32 %43, 1
  br i1 %44, label %49, label %45

45:                                               ; preds = %40
  %46 = load i64, ptr %16, align 8, !tbaa !9
  %47 = load i64, ptr %15, align 8, !tbaa !9
  %48 = icmp ugt i64 %46, %47
  br i1 %48, label %49, label %55

49:                                               ; preds = %45, %40
  br label %50

50:                                               ; preds = %49
  %51 = load ptr, ptr @stderr, align 8, !tbaa !5
  %52 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %51, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 677, ptr noundef @__FUNCTION__.tls13_process_client_hello_exts) #4
  br label %53

53:                                               ; preds = %50
  br label %54

54:                                               ; preds = %53
  store i32 -1, ptr %8, align 4
  store i32 1, ptr %20, align 4
  br label %81

55:                                               ; preds = %45
  %56 = load ptr, ptr %18, align 8, !tbaa !5
  %57 = load i64, ptr %19, align 8, !tbaa !9
  %58 = load ptr, ptr %14, align 8, !tbaa !5
  %59 = call i32 @tls13_process_client_supported_versions(ptr noundef %56, i64 noundef %57, ptr noundef %13, ptr noundef %58)
  br label %80

60:                                               ; preds = %37
  %61 = load ptr, ptr %18, align 8, !tbaa !5
  %62 = load i64, ptr %19, align 8, !tbaa !9
  %63 = load ptr, ptr %11, align 8, !tbaa !5
  %64 = load ptr, ptr %12, align 8, !tbaa !5
  %65 = load ptr, ptr %14, align 8, !tbaa !5
  %66 = call i32 @tls13_process_client_key_share(ptr noundef %61, i64 noundef %62, ptr noundef %63, ptr noundef %64, ptr noundef %13, ptr noundef %65)
  %67 = icmp ne i32 %66, 1
  br i1 %67, label %72, label %68

68:                                               ; preds = %60
  %69 = load i64, ptr %16, align 8, !tbaa !9
  %70 = load i64, ptr %15, align 8, !tbaa !9
  %71 = icmp ugt i64 %69, %70
  br i1 %71, label %72, label %78

72:                                               ; preds = %68, %60
  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 685, ptr noundef @__FUNCTION__.tls13_process_client_hello_exts) #4
  br label %76

76:                                               ; preds = %73
  br label %77

77:                                               ; preds = %76
  store i32 -1, ptr %8, align 4
  store i32 1, ptr %20, align 4
  br label %81

78:                                               ; preds = %68
  br label %80

79:                                               ; preds = %37
  br label %80

80:                                               ; preds = %79, %78, %55
  store i32 0, ptr %20, align 4
  br label %81

81:                                               ; preds = %80, %77, %54, %36
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr %17) #4
  %82 = load i32, ptr %20, align 4
  switch i32 %82, label %85 [
    i32 0, label %83
  ]

83:                                               ; preds = %81
  br label %22, !llvm.loop !13

84:                                               ; preds = %22
  store i32 1, ptr %8, align 4
  store i32 1, ptr %20, align 4
  br label %85

85:                                               ; preds = %84, %81
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  %86 = load i32, ptr %8, align 4
  ret i32 %86
}

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

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

declare i32 @tls13_process_client_supported_versions(ptr noundef, i64 noundef, ptr noundef, ptr noundef) #3

declare i32 @tls13_process_client_key_share(ptr noundef, i64 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #3

attributes #0 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 = !{!"short", !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 [59 x i8], align 1
@__FUNCTION__.tls13_process_client_hello_exts = external hidden unnamed_addr constant [32 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) 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: 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 @tls13_process_client_hello_exts(ptr noundef %0, i64 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5, i64 noundef %6) local_unnamed_addr #2 {
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i16, align 2
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  store ptr %0, ptr %8, align 8, !tbaa !5
  store i64 %1, ptr %9, align 8, !tbaa !9
  store ptr %4, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %11) #4
  store i64 0, ptr %11, align 8, !tbaa !9
  store i64 0, ptr %5, align 8, !tbaa !9
  %.not16 = icmp eq i64 %1, 0
  br i1 %.not16, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %7, %36
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %12) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %13) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %14) #4
  %15 = call i32 @tls_uint16_from_bytes(ptr noundef nonnull %12, ptr noundef nonnull %8, ptr noundef nonnull %9) #4
  %.not9 = icmp eq i32 %15, 1
  br i1 %.not9, label %16, label %.critedge

16:                                               ; preds = %.lr.ph
  %17 = call i32 @tls_uint16array_from_bytes(ptr noundef nonnull %13, ptr noundef nonnull %14, ptr noundef nonnull %8, ptr noundef nonnull %9) #4
  %.not10 = icmp eq i32 %17, 1
  br i1 %.not10, label %18, label %.critedge

18:                                               ; preds = %16
  %19 = load i16, ptr %12, align 2, !tbaa !11
  switch i16 %19, label %36 [
    i16 43, label %20
    i16 51, label %30
  ]

20:                                               ; preds = %18
  %21 = load ptr, ptr %13, align 8, !tbaa !5
  %22 = load i64, ptr %14, align 8, !tbaa !9
  %23 = call i32 @tls13_process_client_supported_versions(ptr noundef %21, i64 noundef %22, ptr noundef null, ptr noundef nonnull %11) #4
  %.not12 = icmp ne i32 %23, 1
  %24 = load i64, ptr %11, align 8
  %25 = icmp ugt i64 %24, %6
  %or.cond = select i1 %.not12, i1 true, i1 %25
  br i1 %or.cond, label %.critedge, label %26

26:                                               ; preds = %20
  %27 = load ptr, ptr %13, align 8, !tbaa !5
  %28 = load i64, ptr %14, align 8, !tbaa !9
  %29 = call i32 @tls13_process_client_supported_versions(ptr noundef %27, i64 noundef %28, ptr noundef nonnull %10, ptr noundef nonnull %5) #4
  br label %36

30:                                               ; preds = %18
  %31 = load ptr, ptr %13, align 8, !tbaa !5
  %32 = load i64, ptr %14, align 8, !tbaa !9
  %33 = call i32 @tls13_process_client_key_share(ptr noundef %31, i64 noundef %32, ptr noundef %2, ptr noundef %3, ptr noundef nonnull %10, ptr noundef nonnull %5) #4
  %.not11 = icmp ne i32 %33, 1
  %34 = load i64, ptr %11, align 8
  %35 = icmp ugt i64 %34, %6
  %or.cond15 = select i1 %.not11, i1 true, i1 %35
  br i1 %or.cond15, label %.critedge, label %36

36:                                               ; preds = %26, %18, %30
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %13) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %12) #4
  %.pr = load i64, ptr %9, align 8, !tbaa !9
  %.not = icmp eq i64 %.pr, 0
  br i1 %.not, label %.loopexit, label %.lr.ph, !llvm.loop !13

.critedge:                                        ; preds = %30, %20, %16, %.lr.ph
  %.sink17 = phi i32 [ 650, %.lr.ph ], [ 650, %16 ], [ 677, %20 ], [ 685, %30 ]
  %37 = load ptr, ptr @stderr, align 8, !tbaa !5
  %38 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %37, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef %.sink17, ptr noundef nonnull @__FUNCTION__.tls13_process_client_hello_exts) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %13) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %12) #4
  br label %.loopexit

.loopexit:                                        ; preds = %36, %7, %.critedge
  %.2 = phi i32 [ -1, %.critedge ], [ 1, %7 ], [ 1, %36 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %11) #4
  ret i32 %.2
}

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

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

declare i32 @tls13_process_client_supported_versions(ptr noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

declare i32 @tls13_process_client_key_share(ptr noundef, i64 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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: GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass