; 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"

%struct.TLS_CONNECT = type { i32, i32, [64 x i32], i64, i32, [18437 x i8], i64, [18437 x i8], [18437 x i8], ptr, i64, i32, [32 x i8], i64, [2048 x i8], i64, [2048 x i8], i64, [2048 x i8], i64, %struct.SM2_KEY, %struct.SM2_KEY, i32, [48 x i8], [96 x i8], %struct.SM3_HMAC_CTX, %struct.SM3_HMAC_CTX, %struct.SM4_KEY, %struct.SM4_KEY, [8 x i8], [8 x i8], [12 x i8], [12 x i8], %struct.BLOCK_CIPHER_KEY, %struct.BLOCK_CIPHER_KEY, i32 }
%struct.SM2_KEY = type { %struct.SM2_Z256_POINT, [4 x i64] }
%struct.SM2_Z256_POINT = type { [4 x i64], [4 x i64], [4 x i64] }
%struct.SM3_HMAC_CTX = type { %struct.SM3_CTX, [64 x i8] }
%struct.SM3_CTX = type { [8 x i32], i64, [64 x i8], i64 }
%struct.SM4_KEY = type { [32 x i32] }
%struct.BLOCK_CIPHER_KEY = type { %union.anon, ptr }
%union.anon = type { %struct.SM4_KEY }

@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_recv = external hidden unnamed_addr constant [11 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
declare dso_local i32 @tls13_do_recv(ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local i32 @tls13_recv(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 i32, align 4
  %11 = 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
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %23

14:                                               ; preds = %4
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %23

17:                                               ; preds = %14
  %18 = load i64, ptr %8, align 8, !tbaa !9
  %19 = icmp ne i64 %18, 0
  br i1 %19, label %20, label %23

20:                                               ; preds = %17
  %21 = load ptr, ptr %9, align 8, !tbaa !5
  %22 = icmp ne ptr %21, null
  br i1 %22, label %28, label %23

23:                                               ; preds = %20, %17, %14, %4
  br label %24

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

27:                                               ; preds = %24
  store i32 -1, ptr %5, align 4
  br label %85

28:                                               ; preds = %20
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.TLS_CONNECT, ptr %29, i32 0, i32 10
  %31 = load i64, ptr %30, align 8, !tbaa !11
  %32 = icmp eq i64 %31, 0
  br i1 %32, label %33, label %52

33:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = call i32 @tls13_do_recv(ptr noundef %34)
  store i32 %35, ptr %10, align 4, !tbaa !20
  %36 = icmp ne i32 %35, 1
  br i1 %36, label %37, label %48

37:                                               ; preds = %33
  %38 = load i32, ptr %10, align 4, !tbaa !20
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %46

40:                                               ; preds = %37
  br label %41

41:                                               ; preds = %40
  %42 = load ptr, ptr @stderr, align 8, !tbaa !5
  %43 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %42, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 391, ptr noundef @__FUNCTION__.tls13_recv) #4
  br label %44

44:                                               ; preds = %41
  br label %45

45:                                               ; preds = %44
  br label %46

46:                                               ; preds = %45, %37
  %47 = load i32, ptr %10, align 4, !tbaa !20
  store i32 %47, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %49

48:                                               ; preds = %33
  store i32 0, ptr %11, align 4
  br label %49

49:                                               ; preds = %48, %46
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  %50 = load i32, ptr %11, align 4
  switch i32 %50, label %87 [
    i32 0, label %51
    i32 1, label %85
  ]

51:                                               ; preds = %49
  br label %52

52:                                               ; preds = %51, %28
  %53 = load i64, ptr %8, align 8, !tbaa !9
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.TLS_CONNECT, ptr %54, i32 0, i32 10
  %56 = load i64, ptr %55, align 8, !tbaa !11
  %57 = icmp ule i64 %53, %56
  br i1 %57, label %58, label %60

58:                                               ; preds = %52
  %59 = load i64, ptr %8, align 8, !tbaa !9
  br label %64

60:                                               ; preds = %52
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.TLS_CONNECT, ptr %61, i32 0, i32 10
  %63 = load i64, ptr %62, align 8, !tbaa !11
  br label %64

64:                                               ; preds = %60, %58
  %65 = phi i64 [ %59, %58 ], [ %63, %60 ]
  %66 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 %65, ptr %66, align 8, !tbaa !9
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.TLS_CONNECT, ptr %68, i32 0, i32 9
  %70 = load ptr, ptr %69, align 8, !tbaa !21
  %71 = load ptr, ptr %9, align 8, !tbaa !5
  %72 = load i64, ptr %71, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %67, ptr align 1 %70, i64 %72, i1 false)
  %73 = load ptr, ptr %9, align 8, !tbaa !5
  %74 = load i64, ptr %73, align 8, !tbaa !9
  %75 = load ptr, ptr %6, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.TLS_CONNECT, ptr %75, i32 0, i32 9
  %77 = load ptr, ptr %76, align 8, !tbaa !21
  %78 = getelementptr inbounds i8, ptr %77, i64 %74
  store ptr %78, ptr %76, align 8, !tbaa !21
  %79 = load ptr, ptr %9, align 8, !tbaa !5
  %80 = load i64, ptr %79, align 8, !tbaa !9
  %81 = load ptr, ptr %6, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.TLS_CONNECT, ptr %81, i32 0, i32 10
  %83 = load i64, ptr %82, align 8, !tbaa !11
  %84 = sub i64 %83, %80
  store i64 %84, ptr %82, align 8, !tbaa !11
  store i32 1, ptr %5, align 4
  br label %85

85:                                               ; preds = %64, %49, %27
  %86 = load i32, ptr %5, align 4
  ret i32 %86

87:                                               ; preds = %49
  unreachable
}

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 = { 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, !10, i64 55616}
!12 = !{!"", !13, i64 0, !13, i64 4, !7, i64 8, !10, i64 264, !13, i64 272, !7, i64 276, !10, i64 18720, !7, i64 18728, !7, i64 37165, !6, i64 55608, !10, i64 55616, !13, i64 55624, !7, i64 55628, !10, i64 55664, !7, i64 55672, !10, i64 57720, !7, i64 57728, !10, i64 59776, !7, i64 59784, !10, i64 61832, !14, i64 61840, !14, i64 61968, !13, i64 62096, !7, i64 62100, !7, i64 62148, !16, i64 62248, !16, i64 62424, !18, i64 62600, !18, i64 62728, !7, i64 62856, !7, i64 62864, !7, i64 62872, !7, i64 62884, !19, i64 62896, !19, i64 63032, !13, i64 63168}
!13 = !{!"int", !7, i64 0}
!14 = !{!"", !15, i64 0, !7, i64 96}
!15 = !{!"", !7, i64 0, !7, i64 32, !7, i64 64}
!16 = !{!"", !17, i64 0, !7, i64 112}
!17 = !{!"", !7, i64 0, !10, i64 32, !7, i64 40, !10, i64 104}
!18 = !{!"", !7, i64 0}
!19 = !{!"BLOCK_CIPHER_KEY", !7, i64 0, !6, i64 128}
!20 = !{!13, !13, i64 0}
!21 = !{!12, !6, i64 55608}


; 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_recv = external hidden unnamed_addr constant [11 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @tls13_recv(ptr noundef %0, ptr noundef writeonly %1, i64 noundef %2, ptr noundef %3) local_unnamed_addr #2 {
  %5 = icmp ne ptr %0, null
  %6 = icmp ne ptr %1, null
  %or.cond = and i1 %5, %6
  %7 = icmp ne i64 %2, 0
  %or.cond3 = and i1 %or.cond, %7
  %8 = icmp ne ptr %3, null
  %or.cond5 = and i1 %or.cond3, %8
  br i1 %or.cond5, label %12, label %9

9:                                                ; preds = %4
  %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 385, ptr noundef nonnull @__FUNCTION__.tls13_recv) #4
  br label %30

12:                                               ; preds = %4
  %13 = getelementptr inbounds i8, ptr %0, i64 55616
  %14 = load i64, ptr %13, align 8, !tbaa !9
  %15 = icmp eq i64 %14, 0
  br i1 %15, label %16, label %21

16:                                               ; preds = %12
  %17 = tail call i32 @tls13_do_recv(ptr noundef nonnull %0)
  %or.cond35.not = icmp ugt i32 %17, 1
  br i1 %or.cond35.not, label %.thread, label %20

.thread:                                          ; preds = %16
  %18 = load ptr, ptr @stderr, align 8, !tbaa !5
  %19 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %18, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 391, ptr noundef nonnull @__FUNCTION__.tls13_recv) #4
  br label %30

20:                                               ; preds = %16
  %.not.not = icmp eq i32 %17, 1
  br i1 %.not.not, label %._crit_edge, label %30

._crit_edge:                                      ; preds = %20
  %.pre = load i64, ptr %13, align 8, !tbaa !9
  br label %21

21:                                               ; preds = %._crit_edge, %12
  %22 = phi i64 [ %.pre, %._crit_edge ], [ %14, %12 ]
  %. = tail call i64 @llvm.umin.i64(i64 %22, i64 %2)
  store i64 %., ptr %3, align 8, !tbaa !19
  %23 = getelementptr inbounds i8, ptr %0, i64 55608
  %24 = load ptr, ptr %23, align 8, !tbaa !20
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %1, ptr align 1 %24, i64 %., i1 false)
  %25 = load i64, ptr %3, align 8, !tbaa !19
  %26 = load ptr, ptr %23, align 8, !tbaa !20
  %27 = getelementptr inbounds i8, ptr %26, i64 %25
  store ptr %27, ptr %23, align 8, !tbaa !20
  %28 = load i64, ptr %13, align 8, !tbaa !9
  %29 = sub i64 %28, %25
  store i64 %29, ptr %13, align 8, !tbaa !9
  br label %30

30:                                               ; preds = %.thread, %20, %21, %9
  %.1 = phi i32 [ 0, %20 ], [ 1, %21 ], [ -1, %9 ], [ %17, %.thread ]
  ret i32 %.1
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umin.i64(i64, i64) #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 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !12, i64 55616}
!10 = !{!"", !11, i64 0, !11, i64 4, !7, i64 8, !12, i64 264, !11, i64 272, !7, i64 276, !12, i64 18720, !7, i64 18728, !7, i64 37165, !6, i64 55608, !12, i64 55616, !11, i64 55624, !7, i64 55628, !12, i64 55664, !7, i64 55672, !12, i64 57720, !7, i64 57728, !12, i64 59776, !7, i64 59784, !12, i64 61832, !13, i64 61840, !13, i64 61968, !11, i64 62096, !7, i64 62100, !7, i64 62148, !15, i64 62248, !15, i64 62424, !17, i64 62600, !17, i64 62728, !7, i64 62856, !7, i64 62864, !7, i64 62872, !7, i64 62884, !18, i64 62896, !18, i64 63032, !11, i64 63168}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!"", !14, i64 0, !7, i64 96}
!14 = !{!"", !7, i64 0, !7, i64 32, !7, i64 64}
!15 = !{!"", !16, i64 0, !7, i64 112}
!16 = !{!"", !7, i64 0, !12, i64 32, !7, i64 40, !12, i64 104}
!17 = !{!"", !7, i64 0}
!18 = !{!"BLOCK_CIPHER_KEY", !7, i64 0, !6, i64 128}
!19 = !{!12, !12, i64 0}
!20 = !{!10, !6, i64 55608}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass