; 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.SM2_SIGN_CTX = type { %struct.SM3_CTX, %struct.SM3_CTX, %struct.SM2_KEY, [4 x i64], [32 x %struct.SM2_SIGN_PRE_COMP], i32, [16 x %struct.SM2_Z256_POINT] }
%struct.SM3_CTX = type { [8 x i32], i64, [64 x i8], i64 }
%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.SM2_SIGN_PRE_COMP = type { [4 x i64], [4 x i64] }
%struct.DIGEST_CTX = type { %union.anon.0, ptr }
%union.anon.0 = type { %struct.SM3_CTX }

@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
@TLS13_client_context_str_and_zero = external hidden constant [34 x i8], align 16
@TLS13_client_context_str_and_zero_size = external hidden global i64, align 8
@TLS13_server_context_str_and_zero = external hidden constant [34 x i8], align 16
@TLS13_server_context_str_and_zero_size = external hidden global i64, align 8
@__FUNCTION__.tls13_sign_certificate_verify = external hidden unnamed_addr constant [30 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @tls13_sign_certificate_verify(i32 noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, ptr noundef %5, ptr noundef %6) #5 {
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca %struct.SM2_SIGN_CTX, align 8
  %17 = alloca [64 x i8], align 16
  %18 = alloca ptr, align 8
  %19 = alloca i64, align 8
  %20 = alloca %struct.DIGEST_CTX, align 8
  %21 = alloca [64 x i8], align 16
  %22 = alloca i64, align 8
  %23 = alloca i32, align 4
  store i32 %0, ptr %9, align 4, !tbaa !5
  store ptr %1, ptr %10, align 8, !tbaa !9
  store ptr %2, ptr %11, align 8, !tbaa !9
  store i64 %3, ptr %12, align 8, !tbaa !11
  store ptr %4, ptr %13, align 8, !tbaa !9
  store ptr %5, ptr %14, align 8, !tbaa !9
  store ptr %6, ptr %15, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 3976, ptr %16) #6
  call void @llvm.lifetime.start.p0(i64 64, ptr %17) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #6
  call void @llvm.lifetime.start.p0(i64 120, ptr %20) #6
  call void @llvm.lifetime.start.p0(i64 64, ptr %21) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #6
  %24 = getelementptr inbounds [64 x i8], ptr %17, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 16 %24, i8 32, i64 64, i1 false)
  %25 = load i32, ptr %9, align 4, !tbaa !5
  switch i32 %25, label %30 [
    i32 1, label %26
    i32 0, label %28
  ]

26:                                               ; preds = %7
  store ptr @TLS13_client_context_str_and_zero, ptr %18, align 8, !tbaa !9
  %27 = load i64, ptr @TLS13_client_context_str_and_zero_size, align 8, !tbaa !11
  store i64 %27, ptr %19, align 8, !tbaa !11
  br label %36

28:                                               ; preds = %7
  store ptr @TLS13_server_context_str_and_zero, ptr %18, align 8, !tbaa !9
  %29 = load i64, ptr @TLS13_server_context_str_and_zero_size, align 8, !tbaa !11
  store i64 %29, ptr %19, align 8, !tbaa !11
  br label %36

30:                                               ; preds = %7
  br label %31

31:                                               ; preds = %30
  %32 = load ptr, ptr @stderr, align 8, !tbaa !9
  %33 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %32, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 495, ptr noundef @__FUNCTION__.tls13_sign_certificate_verify) #6
  br label %34

34:                                               ; preds = %31
  br label %35

35:                                               ; preds = %34
  store i32 -1, ptr %8, align 4
  store i32 1, ptr %23, align 4
  br label %55

36:                                               ; preds = %28, %26
  %37 = load ptr, ptr %13, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %20, ptr align 8 %37, i64 120, i1 false), !tbaa.struct !13
  %38 = getelementptr inbounds [64 x i8], ptr %21, i64 0, i64 0
  %39 = call i32 @digest_finish(ptr noundef %20, ptr noundef %38, ptr noundef %22)
  %40 = load ptr, ptr %10, align 8, !tbaa !9
  %41 = load ptr, ptr %11, align 8, !tbaa !9
  %42 = load i64, ptr %12, align 8, !tbaa !11
  %43 = call i32 @sm2_sign_init(ptr noundef %16, ptr noundef %40, ptr noundef %41, i64 noundef %42)
  %44 = getelementptr inbounds [64 x i8], ptr %17, i64 0, i64 0
  %45 = call i32 @sm2_sign_update(ptr noundef %16, ptr noundef %44, i64 noundef 64)
  %46 = load ptr, ptr %18, align 8, !tbaa !9
  %47 = load i64, ptr %19, align 8, !tbaa !11
  %48 = call i32 @sm2_sign_update(ptr noundef %16, ptr noundef %46, i64 noundef %47)
  %49 = getelementptr inbounds [64 x i8], ptr %21, i64 0, i64 0
  %50 = load i64, ptr %22, align 8, !tbaa !11
  %51 = call i32 @sm2_sign_update(ptr noundef %16, ptr noundef %49, i64 noundef %50)
  %52 = load ptr, ptr %14, align 8, !tbaa !9
  %53 = load ptr, ptr %15, align 8, !tbaa !9
  %54 = call i32 @sm2_sign_finish(ptr noundef %16, ptr noundef %52, ptr noundef %53)
  call void @gmssl_secure_clear(ptr noundef %16, i64 noundef 3976)
  store i32 1, ptr %8, align 4
  store i32 1, ptr %23, align 4
  br label %55

55:                                               ; preds = %36, %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #6
  call void @llvm.lifetime.end.p0(i64 64, ptr %21) #6
  call void @llvm.lifetime.end.p0(i64 120, ptr %20) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #6
  call void @llvm.lifetime.end.p0(i64 64, ptr %17) #6
  call void @llvm.lifetime.end.p0(i64 3976, ptr %16) #6
  %56 = load i32, ptr %8, align 4
  ret i32 %56
}

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

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

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

declare void @gmssl_secure_clear(ptr noundef, i64 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 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 #6 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{i64 0, i64 112, !14, i64 112, i64 8, !9}
!14 = !{!7, !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"

%struct.SM2_SIGN_CTX = type { %struct.SM3_CTX, %struct.SM3_CTX, %struct.SM2_KEY, [4 x i64], [32 x %struct.SM2_SIGN_PRE_COMP], i32, [16 x %struct.SM2_Z256_POINT] }
%struct.SM3_CTX = type { [8 x i32], i64, [64 x i8], i64 }
%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.SM2_SIGN_PRE_COMP = type { [4 x i64], [4 x i64] }
%struct.DIGEST_CTX = type { %union.anon.0, ptr }
%union.anon.0 = type { %struct.SM3_CTX }

@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
@TLS13_client_context_str_and_zero = external hidden constant [34 x i8], align 16
@TLS13_client_context_str_and_zero_size = external hidden local_unnamed_addr global i64, align 8
@TLS13_server_context_str_and_zero = external hidden constant [34 x i8], align 16
@TLS13_server_context_str_and_zero_size = external hidden local_unnamed_addr global i64, align 8
@__FUNCTION__.tls13_sign_certificate_verify = external hidden unnamed_addr constant [30 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 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: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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

declare i32 @digest_finish(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @tls13_sign_certificate_verify(i32 noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3, ptr nocapture noundef readonly %4, ptr noundef %5, ptr noundef %6) local_unnamed_addr #5 {
  %8 = alloca %struct.SM2_SIGN_CTX, align 8
  %9 = alloca [64 x i8], align 16
  %10 = alloca %struct.DIGEST_CTX, align 8
  %11 = alloca [64 x i8], align 16
  %12 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 3976, ptr nonnull %8) #6
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %9) #6
  call void @llvm.lifetime.start.p0(i64 120, ptr nonnull %10) #6
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %11) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %12) #6
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(64) %9, i8 32, i64 64, i1 false)
  switch i32 %0, label %14 [
    i32 1, label %17
    i32 0, label %13
  ]

13:                                               ; preds = %7
  br label %17

14:                                               ; preds = %7
  %15 = load ptr, ptr @stderr, align 8, !tbaa !5
  %16 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %15, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 495, ptr noundef nonnull @__FUNCTION__.tls13_sign_certificate_verify) #7
  br label %25

17:                                               ; preds = %7, %13
  %.09 = phi ptr [ @TLS13_server_context_str_and_zero, %13 ], [ @TLS13_client_context_str_and_zero, %7 ]
  %.0.in = phi ptr [ @TLS13_server_context_str_and_zero_size, %13 ], [ @TLS13_client_context_str_and_zero_size, %7 ]
  %.0 = load i64, ptr %.0.in, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(120) %10, ptr noundef nonnull align 8 dereferenceable(120) %4, i64 120, i1 false), !tbaa.struct !11
  %18 = call i32 @digest_finish(ptr noundef nonnull %10, ptr noundef nonnull %11, ptr noundef nonnull %12) #6
  %19 = call i32 @sm2_sign_init(ptr noundef nonnull %8, ptr noundef %1, ptr noundef %2, i64 noundef %3) #6
  %20 = call i32 @sm2_sign_update(ptr noundef nonnull %8, ptr noundef nonnull %9, i64 noundef 64) #6
  %21 = call i32 @sm2_sign_update(ptr noundef nonnull %8, ptr noundef nonnull %.09, i64 noundef %.0) #6
  %22 = load i64, ptr %12, align 8, !tbaa !9
  %23 = call i32 @sm2_sign_update(ptr noundef nonnull %8, ptr noundef nonnull %11, i64 noundef %22) #6
  %24 = call i32 @sm2_sign_finish(ptr noundef nonnull %8, ptr noundef %5, ptr noundef %6) #6
  call void @gmssl_secure_clear(ptr noundef nonnull %8, i64 noundef 3976) #6
  br label %25

25:                                               ; preds = %17, %14
  %.010 = phi i32 [ -1, %14 ], [ 1, %17 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %12) #6
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %11) #6
  call void @llvm.lifetime.end.p0(i64 120, ptr nonnull %10) #6
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %9) #6
  call void @llvm.lifetime.end.p0(i64 3976, ptr nonnull %8) #6
  ret i32 %.010
}

declare i32 @sm2_sign_init(ptr noundef, ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #4

declare i32 @sm2_sign_update(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #4

declare i32 @sm2_sign_finish(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #4

declare void @gmssl_secure_clear(ptr noundef, i64 noundef) local_unnamed_addr #4

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 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 #6 = { nounwind }
attributes #7 = { 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 = !{i64 0, i64 112, !12, i64 112, i64 8, !5}
!12 = !{!7, !7, i64 0}


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