; 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_send = external hidden unnamed_addr constant [11 x i8], align 1

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @tls13_send(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3) #1 {
  %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 ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, 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 8, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.TLS_CONNECT, ptr %17, i32 0, i32 7
  %19 = getelementptr inbounds [18437 x i8], ptr %18, i64 0, i64 0
  store ptr %19, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  store i64 0, ptr %15, align 8, !tbaa !9
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.TLS_CONNECT, ptr %20, i32 0, i32 1
  %22 = load i32, ptr %21, align 4, !tbaa !11
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %33

24:                                               ; preds = %4
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.TLS_CONNECT, ptr %25, i32 0, i32 33
  store ptr %26, ptr %10, align 8, !tbaa !5
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.TLS_CONNECT, ptr %27, i32 0, i32 31
  %29 = getelementptr inbounds [12 x i8], ptr %28, i64 0, i64 0
  store ptr %29, ptr %11, align 8, !tbaa !5
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.TLS_CONNECT, ptr %30, i32 0, i32 29
  %32 = getelementptr inbounds [8 x i8], ptr %31, i64 0, i64 0
  store ptr %32, ptr %12, align 8, !tbaa !5
  br label %42

33:                                               ; preds = %4
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.TLS_CONNECT, ptr %34, i32 0, i32 34
  store ptr %35, ptr %10, align 8, !tbaa !5
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.TLS_CONNECT, ptr %36, i32 0, i32 32
  %38 = getelementptr inbounds [12 x i8], ptr %37, i64 0, i64 0
  store ptr %38, ptr %11, align 8, !tbaa !5
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.TLS_CONNECT, ptr %39, i32 0, i32 30
  %41 = getelementptr inbounds [8 x i8], ptr %40, i64 0, i64 0
  store ptr %41, ptr %12, align 8, !tbaa !5
  br label %42

42:                                               ; preds = %33, %24
  %43 = load ptr, ptr %10, align 8, !tbaa !5
  %44 = load ptr, ptr %11, align 8, !tbaa !5
  %45 = load ptr, ptr %12, align 8, !tbaa !5
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = load i64, ptr %8, align 8, !tbaa !9
  %48 = load i64, ptr %15, align 8, !tbaa !9
  %49 = load ptr, ptr %13, align 8, !tbaa !5
  %50 = getelementptr inbounds i8, ptr %49, i64 5
  %51 = call i32 @tls13_gcm_encrypt(ptr noundef %43, ptr noundef %44, ptr noundef %45, i32 noundef 23, ptr noundef %46, i64 noundef %47, i64 noundef %48, ptr noundef %50, ptr noundef %14)
  %52 = icmp ne i32 %51, 1
  br i1 %52, label %53, label %59

53:                                               ; preds = %42
  br label %54

54:                                               ; preds = %53
  %55 = load ptr, ptr @stderr, align 8, !tbaa !5
  %56 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %55, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 262, ptr noundef @__FUNCTION__.tls13_send) #4
  br label %57

57:                                               ; preds = %54
  br label %58

58:                                               ; preds = %57
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %16, align 4
  br label %87

59:                                               ; preds = %42
  %60 = load ptr, ptr %13, align 8, !tbaa !5
  %61 = getelementptr inbounds i8, ptr %60, i64 0
  store i8 23, ptr %61, align 1, !tbaa !20
  %62 = load ptr, ptr %13, align 8, !tbaa !5
  %63 = getelementptr inbounds i8, ptr %62, i64 1
  store i8 3, ptr %63, align 1, !tbaa !20
  %64 = load ptr, ptr %13, align 8, !tbaa !5
  %65 = getelementptr inbounds i8, ptr %64, i64 2
  store i8 3, ptr %65, align 1, !tbaa !20
  %66 = load i64, ptr %14, align 8, !tbaa !9
  %67 = lshr i64 %66, 8
  %68 = trunc i64 %67 to i8
  %69 = load ptr, ptr %13, align 8, !tbaa !5
  %70 = getelementptr inbounds i8, ptr %69, i64 3
  store i8 %68, ptr %70, align 1, !tbaa !20
  %71 = load i64, ptr %14, align 8, !tbaa !9
  %72 = trunc i64 %71 to i8
  %73 = load ptr, ptr %13, align 8, !tbaa !5
  %74 = getelementptr inbounds i8, ptr %73, i64 4
  store i8 %72, ptr %74, align 1, !tbaa !20
  %75 = load i64, ptr %14, align 8, !tbaa !9
  %76 = add i64 %75, 5
  store i64 %76, ptr %14, align 8, !tbaa !9
  %77 = load ptr, ptr %13, align 8, !tbaa !5
  %78 = load i64, ptr %14, align 8, !tbaa !9
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.TLS_CONNECT, ptr %79, i32 0, i32 4
  %81 = load i32, ptr %80, align 8, !tbaa !21
  %82 = call i32 @tls_record_send(ptr noundef %77, i64 noundef %78, i32 noundef %81)
  %83 = load ptr, ptr %12, align 8, !tbaa !5
  %84 = call i32 @tls_seq_num_incr(ptr noundef %83)
  %85 = load i64, ptr %8, align 8, !tbaa !9
  %86 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 %85, ptr %86, align 8, !tbaa !9
  store i32 1, ptr %5, align 4
  store i32 1, ptr %16, align 4
  br label %87

87:                                               ; preds = %59, %58
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %88 = load i32, ptr %5, align 4
  ret i32 %88
}

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

declare i32 @tls_seq_num_incr(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 = { 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !13, i64 4}
!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 = !{!7, !7, i64 0}
!21 = !{!12, !13, i64 272}


; 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_send = 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: nounwind uwtable
declare dso_local i32 @tls13_gcm_encrypt(ptr noundef, ptr noundef, ptr noundef, i32 noundef, ptr noundef, i64 noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @tls13_send(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #1 {
  %5 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #4
  %6 = getelementptr inbounds i8, ptr %0, i64 4
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %.not = icmp eq i32 %7, 0
  %.027.v = select i1 %.not, i64 62884, i64 62872
  %.027 = getelementptr inbounds i8, ptr %0, i64 %.027.v
  %.026.v = select i1 %.not, i64 62864, i64 62856
  %.026 = getelementptr inbounds i8, ptr %0, i64 %.026.v
  %.025.v = select i1 %.not, i64 63032, i64 62896
  %.025 = getelementptr inbounds i8, ptr %0, i64 %.025.v
  %8 = getelementptr inbounds i8, ptr %0, i64 18733
  %9 = call i32 @tls13_gcm_encrypt(ptr noundef nonnull %.025, ptr noundef nonnull %.027, ptr noundef nonnull %.026, i32 noundef 23, ptr noundef %1, i64 noundef %2, i64 noundef 0, ptr noundef nonnull %8, ptr noundef nonnull %5)
  %.not28 = icmp eq i32 %9, 1
  br i1 %.not28, label %13, label %10

10:                                               ; preds = %4
  %11 = load ptr, ptr @stderr, align 8, !tbaa !18
  %12 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %11, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 262, ptr noundef nonnull @__FUNCTION__.tls13_send) #5
  br label %28

13:                                               ; preds = %4
  %14 = getelementptr inbounds i8, ptr %0, i64 18728
  store i8 23, ptr %14, align 1, !tbaa !19
  %15 = getelementptr inbounds i8, ptr %0, i64 18729
  store i8 3, ptr %15, align 1, !tbaa !19
  %16 = getelementptr inbounds i8, ptr %0, i64 18730
  store i8 3, ptr %16, align 1, !tbaa !19
  %17 = load i64, ptr %5, align 8, !tbaa !20
  %18 = lshr i64 %17, 8
  %19 = trunc i64 %18 to i8
  %20 = getelementptr inbounds i8, ptr %0, i64 18731
  store i8 %19, ptr %20, align 1, !tbaa !19
  %21 = trunc i64 %17 to i8
  %22 = getelementptr inbounds i8, ptr %0, i64 18732
  store i8 %21, ptr %22, align 1, !tbaa !19
  %23 = add i64 %17, 5
  store i64 %23, ptr %5, align 8, !tbaa !20
  %24 = getelementptr inbounds i8, ptr %0, i64 272
  %25 = load i32, ptr %24, align 8, !tbaa !21
  %26 = call i32 @tls_record_send(ptr noundef nonnull %14, i64 noundef %23, i32 noundef %25) #4
  %27 = call i32 @tls_seq_num_incr(ptr noundef nonnull %.026) #4
  store i64 %2, ptr %3, align 8, !tbaa !20
  br label %28

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

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

declare i32 @tls_seq_num_incr(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 = { 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 #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !7, i64 4}
!6 = !{!"", !7, i64 0, !7, i64 4, !8, i64 8, !10, i64 264, !7, i64 272, !8, i64 276, !10, i64 18720, !8, i64 18728, !8, i64 37165, !11, i64 55608, !10, i64 55616, !7, i64 55624, !8, i64 55628, !10, i64 55664, !8, i64 55672, !10, i64 57720, !8, i64 57728, !10, i64 59776, !8, i64 59784, !10, i64 61832, !12, i64 61840, !12, i64 61968, !7, i64 62096, !8, i64 62100, !8, i64 62148, !14, i64 62248, !14, i64 62424, !16, i64 62600, !16, i64 62728, !8, i64 62856, !8, i64 62864, !8, i64 62872, !8, i64 62884, !17, i64 62896, !17, i64 63032, !7, i64 63168}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"", !13, i64 0, !8, i64 96}
!13 = !{!"", !8, i64 0, !8, i64 32, !8, i64 64}
!14 = !{!"", !15, i64 0, !8, i64 112}
!15 = !{!"", !8, i64 0, !10, i64 32, !8, i64 40, !10, i64 104}
!16 = !{!"", !8, i64 0}
!17 = !{!"BLOCK_CIPHER_KEY", !8, i64 0, !11, i64 128}
!18 = !{!11, !11, i64 0}
!19 = !{!8, !8, i64 0}
!20 = !{!10, !10, i64 0}
!21 = !{!6, !7, i64 272}


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