; 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
@__const.tls13_client_hello_exts_set.protocols = external hidden unnamed_addr constant [1 x i32], align 4
@__const.tls13_client_hello_exts_set.supported_groups = external hidden unnamed_addr constant [1 x i32], align 4
@__const.tls13_client_hello_exts_set.sig_algs = external hidden unnamed_addr constant [1 x i32], align 4
@__FUNCTION__.tls13_client_hello_exts_set = external hidden unnamed_addr constant [28 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; 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_client_hello_exts_set(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3) #3 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca [1 x i32], align 4
  %11 = alloca [1 x i32], align 4
  %12 = alloca [1 x i32], align 4
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca i64, align 8
  %16 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i64 %2, ptr %8, align 8, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %10, ptr align 4 @__const.tls13_client_hello_exts_set.protocols, i64 4, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %11, ptr align 4 @__const.tls13_client_hello_exts_set.supported_groups, i64 4, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %12, ptr align 4 @__const.tls13_client_hello_exts_set.sig_algs, i64 4, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  store i64 1, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  store i64 1, ptr %14, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #5
  store i64 1, ptr %15, align 8, !tbaa !9
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %25

19:                                               ; preds = %4
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %25

22:                                               ; preds = %19
  %23 = load ptr, ptr %9, align 8, !tbaa !5
  %24 = icmp ne ptr %23, null
  br i1 %24, label %31, label %25

25:                                               ; preds = %22, %19, %4
  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 612, ptr noundef @__FUNCTION__.tls13_client_hello_exts_set) #5
  br label %29

29:                                               ; preds = %26
  br label %30

30:                                               ; preds = %29
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %16, align 4
  br label %89

31:                                               ; preds = %22
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  store i64 0, ptr %32, align 8, !tbaa !9
  %33 = getelementptr inbounds [1 x i32], ptr %10, i64 0, i64 0
  %34 = load i64, ptr %13, align 8, !tbaa !9
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = call i32 @tls13_supported_versions_ext_to_bytes(i32 noundef 1, ptr noundef %33, i64 noundef %34, ptr noundef null, ptr noundef %35)
  %37 = icmp ne i32 %36, 1
  br i1 %37, label %55, label %38

38:                                               ; preds = %31
  %39 = getelementptr inbounds [1 x i32], ptr %11, i64 0, i64 0
  %40 = load i64, ptr %14, align 8, !tbaa !9
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = call i32 @tls_supported_groups_ext_to_bytes(ptr noundef %39, i64 noundef %40, ptr noundef null, ptr noundef %41)
  %43 = icmp ne i32 %42, 1
  br i1 %43, label %55, label %44

44:                                               ; preds = %38
  %45 = getelementptr inbounds [1 x i32], ptr %12, i64 0, i64 0
  %46 = load i64, ptr %15, align 8, !tbaa !9
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = call i32 @tls_signature_algorithms_ext_to_bytes(ptr noundef %45, i64 noundef %46, ptr noundef null, ptr noundef %47)
  %49 = icmp ne i32 %48, 1
  br i1 %49, label %55, label %50

50:                                               ; preds = %44
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = call i32 @tls13_client_key_share_ext_to_bytes(ptr noundef %51, ptr noundef null, ptr noundef %52)
  %54 = icmp ne i32 %53, 1
  br i1 %54, label %55, label %61

55:                                               ; preds = %50, %44, %38, %31
  br label %56

56:                                               ; preds = %55
  %57 = load ptr, ptr @stderr, align 8, !tbaa !5
  %58 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %57, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 621, ptr noundef @__FUNCTION__.tls13_client_hello_exts_set) #5
  br label %59

59:                                               ; preds = %56
  br label %60

60:                                               ; preds = %59
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %16, align 4
  br label %89

61:                                               ; preds = %50
  %62 = load ptr, ptr %7, align 8, !tbaa !5
  %63 = load i64, ptr %62, align 8, !tbaa !9
  %64 = load i64, ptr %8, align 8, !tbaa !9
  %65 = icmp ugt i64 %63, %64
  br i1 %65, label %66, label %72

66:                                               ; preds = %61
  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 625, ptr noundef @__FUNCTION__.tls13_client_hello_exts_set) #5
  br label %70

70:                                               ; preds = %67
  br label %71

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

72:                                               ; preds = %61
  %73 = load ptr, ptr %7, align 8, !tbaa !5
  store i64 0, ptr %73, align 8, !tbaa !9
  %74 = getelementptr inbounds [1 x i32], ptr %10, i64 0, i64 0
  %75 = load i64, ptr %13, align 8, !tbaa !9
  %76 = load ptr, ptr %7, align 8, !tbaa !5
  %77 = call i32 @tls13_supported_versions_ext_to_bytes(i32 noundef 1, ptr noundef %74, i64 noundef %75, ptr noundef %6, ptr noundef %76)
  %78 = getelementptr inbounds [1 x i32], ptr %11, i64 0, i64 0
  %79 = load i64, ptr %14, align 8, !tbaa !9
  %80 = load ptr, ptr %7, align 8, !tbaa !5
  %81 = call i32 @tls_supported_groups_ext_to_bytes(ptr noundef %78, i64 noundef %79, ptr noundef %6, ptr noundef %80)
  %82 = getelementptr inbounds [1 x i32], ptr %12, i64 0, i64 0
  %83 = load i64, ptr %15, align 8, !tbaa !9
  %84 = load ptr, ptr %7, align 8, !tbaa !5
  %85 = call i32 @tls_signature_algorithms_ext_to_bytes(ptr noundef %82, i64 noundef %83, ptr noundef %6, ptr noundef %84)
  %86 = load ptr, ptr %9, align 8, !tbaa !5
  %87 = load ptr, ptr %7, align 8, !tbaa !5
  %88 = call i32 @tls13_client_key_share_ext_to_bytes(ptr noundef %86, ptr noundef %6, ptr noundef %87)
  store i32 1, ptr %5, align 4
  store i32 1, ptr %16, align 4
  br label %89

89:                                               ; preds = %72, %71, %60, %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  %90 = load i32, ptr %5, align 4
  ret i32 %90
}

declare i32 @tls13_supported_versions_ext_to_bytes(i32 noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) #4

declare i32 @tls_supported_groups_ext_to_bytes(ptr noundef, i64 noundef, ptr noundef, ptr noundef) #4

declare i32 @tls_signature_algorithms_ext_to_bytes(ptr noundef, i64 noundef, ptr noundef, ptr noundef) #4

declare i32 @tls13_client_key_share_ext_to_bytes(ptr noundef, ptr noundef, ptr noundef) #4

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { "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 #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}


; 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
@__const.tls13_client_hello_exts_set.protocols = external hidden unnamed_addr constant [1 x i32], align 4
@__const.tls13_client_hello_exts_set.supported_groups = external hidden unnamed_addr constant [1 x i32], align 4
@__const.tls13_client_hello_exts_set.sig_algs = external hidden unnamed_addr constant [1 x i32], align 4
@__FUNCTION__.tls13_client_hello_exts_set = external hidden unnamed_addr constant [28 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 range(i32 -1, 2) i32 @tls13_client_hello_exts_set(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3) local_unnamed_addr #2 {
  %5 = alloca ptr, align 8
  %6 = alloca [1 x i32], align 4
  %7 = alloca [1 x i32], align 4
  %8 = alloca [1 x i32], align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #4
  %9 = load i32, ptr @__const.tls13_client_hello_exts_set.protocols, align 4
  store i32 %9, ptr %6, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %7) #4
  %10 = load i32, ptr @__const.tls13_client_hello_exts_set.supported_groups, align 4
  store i32 %10, ptr %7, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %8) #4
  %11 = load i32, ptr @__const.tls13_client_hello_exts_set.sig_algs, align 4
  store i32 %11, ptr %8, align 4
  %12 = icmp ne ptr %0, null
  %13 = icmp ne ptr %1, null
  %or.cond = and i1 %12, %13
  %14 = icmp ne ptr %3, null
  %or.cond3 = and i1 %or.cond, %14
  br i1 %or.cond3, label %18, label %15

15:                                               ; preds = %4
  %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 612, ptr noundef nonnull @__FUNCTION__.tls13_client_hello_exts_set) #5
  br label %40

18:                                               ; preds = %4
  store i64 0, ptr %1, align 8, !tbaa !9
  %19 = call i32 @tls13_supported_versions_ext_to_bytes(i32 noundef 1, ptr noundef nonnull %6, i64 noundef 1, ptr noundef null, ptr noundef nonnull %1) #4
  %.not = icmp eq i32 %19, 1
  br i1 %.not, label %20, label %26

20:                                               ; preds = %18
  %21 = call i32 @tls_supported_groups_ext_to_bytes(ptr noundef nonnull %7, i64 noundef 1, ptr noundef null, ptr noundef nonnull %1) #4
  %.not27 = icmp eq i32 %21, 1
  br i1 %.not27, label %22, label %26

22:                                               ; preds = %20
  %23 = call i32 @tls_signature_algorithms_ext_to_bytes(ptr noundef nonnull %8, i64 noundef 1, ptr noundef null, ptr noundef nonnull %1) #4
  %.not28 = icmp eq i32 %23, 1
  br i1 %.not28, label %24, label %26

24:                                               ; preds = %22
  %25 = call i32 @tls13_client_key_share_ext_to_bytes(ptr noundef nonnull %3, ptr noundef null, ptr noundef nonnull %1) #4
  %.not29 = icmp eq i32 %25, 1
  br i1 %.not29, label %29, label %26

26:                                               ; preds = %18, %20, %22, %24
  %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 621, ptr noundef nonnull @__FUNCTION__.tls13_client_hello_exts_set) #5
  br label %40

29:                                               ; preds = %24
  %30 = load i64, ptr %1, align 8, !tbaa !9
  %31 = icmp ugt i64 %30, %2
  br i1 %31, label %32, label %35

32:                                               ; preds = %29
  %33 = load ptr, ptr @stderr, align 8, !tbaa !5
  %34 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %33, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 625, ptr noundef nonnull @__FUNCTION__.tls13_client_hello_exts_set) #5
  br label %40

35:                                               ; preds = %29
  store i64 0, ptr %1, align 8, !tbaa !9
  %36 = call i32 @tls13_supported_versions_ext_to_bytes(i32 noundef 1, ptr noundef nonnull %6, i64 noundef 1, ptr noundef nonnull %5, ptr noundef nonnull %1) #4
  %37 = call i32 @tls_supported_groups_ext_to_bytes(ptr noundef nonnull %7, i64 noundef 1, ptr noundef nonnull %5, ptr noundef nonnull %1) #4
  %38 = call i32 @tls_signature_algorithms_ext_to_bytes(ptr noundef nonnull %8, i64 noundef 1, ptr noundef nonnull %5, ptr noundef nonnull %1) #4
  %39 = call i32 @tls13_client_key_share_ext_to_bytes(ptr noundef nonnull %3, ptr noundef nonnull %5, ptr noundef nonnull %1) #4
  br label %40

40:                                               ; preds = %35, %32, %26, %15
  %.0 = phi i32 [ -1, %26 ], [ -1, %32 ], [ 1, %35 ], [ -1, %15 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #4
  ret i32 %.0
}

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

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

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

declare i32 @tls13_client_key_share_ext_to_bytes(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}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass