; 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_VERIFY_CTX = type { %struct.SM3_CTX, %struct.SM3_CTX, %struct.SM2_KEY, [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.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_verify_certificate_verify = 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 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_verify_certificate_verify(i32 noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, ptr noundef %5, i64 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 i64, align 8
  %16 = alloca i32, align 4
  %17 = alloca %struct.SM2_VERIFY_CTX, align 8
  %18 = alloca [64 x i8], align 16
  %19 = alloca ptr, align 8
  %20 = alloca i64, align 8
  %21 = alloca %struct.DIGEST_CTX, align 8
  %22 = alloca [64 x i8], align 16
  %23 = alloca i64, align 8
  %24 = 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 i64 %6, ptr %15, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #6
  call void @llvm.lifetime.start.p0(i64 1888, ptr %17) #6
  call void @llvm.lifetime.start.p0(i64 64, ptr %18) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #6
  call void @llvm.lifetime.start.p0(i64 120, ptr %21) #6
  call void @llvm.lifetime.start.p0(i64 64, ptr %22) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %23) #6
  %25 = getelementptr inbounds [64 x i8], ptr %18, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 16 %25, i8 32, i64 64, i1 false)
  %26 = load i32, ptr %9, align 4, !tbaa !5
  switch i32 %26, label %31 [
    i32 1, label %27
    i32 0, label %29
  ]

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

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

31:                                               ; preds = %7
  br label %32

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

35:                                               ; preds = %32
  br label %36

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

37:                                               ; preds = %29, %27
  %38 = load ptr, ptr %13, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %21, ptr align 8 %38, i64 120, i1 false), !tbaa.struct !13
  %39 = getelementptr inbounds [64 x i8], ptr %22, i64 0, i64 0
  %40 = call i32 @digest_finish(ptr noundef %21, ptr noundef %39, ptr noundef %23)
  %41 = load ptr, ptr %10, align 8, !tbaa !9
  %42 = load ptr, ptr %11, align 8, !tbaa !9
  %43 = load i64, ptr %12, align 8, !tbaa !11
  %44 = call i32 @sm2_verify_init(ptr noundef %17, ptr noundef %41, ptr noundef %42, i64 noundef %43)
  %45 = getelementptr inbounds [64 x i8], ptr %18, i64 0, i64 0
  %46 = call i32 @sm2_verify_update(ptr noundef %17, ptr noundef %45, i64 noundef 64)
  %47 = load ptr, ptr %19, align 8, !tbaa !9
  %48 = load i64, ptr %20, align 8, !tbaa !11
  %49 = call i32 @sm2_verify_update(ptr noundef %17, ptr noundef %47, i64 noundef %48)
  %50 = getelementptr inbounds [64 x i8], ptr %22, i64 0, i64 0
  %51 = load i64, ptr %23, align 8, !tbaa !11
  %52 = call i32 @sm2_verify_update(ptr noundef %17, ptr noundef %50, i64 noundef %51)
  %53 = load ptr, ptr %14, align 8, !tbaa !9
  %54 = load i64, ptr %15, align 8, !tbaa !11
  %55 = call i32 @sm2_verify_finish(ptr noundef %17, ptr noundef %53, i64 noundef %54)
  store i32 %55, ptr %16, align 4, !tbaa !5
  %56 = icmp slt i32 %55, 0
  br i1 %56, label %57, label %63

57:                                               ; preds = %37
  br label %58

58:                                               ; preds = %57
  %59 = load ptr, ptr @stderr, align 8, !tbaa !9
  %60 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %59, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 550, ptr noundef @__FUNCTION__.tls13_verify_certificate_verify) #6
  br label %61

61:                                               ; preds = %58
  br label %62

62:                                               ; preds = %61
  store i32 -1, ptr %8, align 4
  store i32 1, ptr %24, align 4
  br label %74

63:                                               ; preds = %37
  %64 = load i32, ptr %16, align 4, !tbaa !5
  %65 = icmp ne i32 %64, 1
  br i1 %65, label %66, label %72

66:                                               ; preds = %63
  br label %67

67:                                               ; preds = %66
  %68 = load ptr, ptr @stderr, align 8, !tbaa !9
  %69 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %68, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 554, ptr noundef @__FUNCTION__.tls13_verify_certificate_verify) #6
  br label %70

70:                                               ; preds = %67
  br label %71

71:                                               ; preds = %70
  br label %72

72:                                               ; preds = %71, %63
  %73 = load i32, ptr %16, align 4, !tbaa !5
  store i32 %73, ptr %8, align 4
  store i32 1, ptr %24, align 4
  br label %74

74:                                               ; preds = %72, %62, %36
  call void @llvm.lifetime.end.p0(i64 8, ptr %23) #6
  call void @llvm.lifetime.end.p0(i64 64, ptr %22) #6
  call void @llvm.lifetime.end.p0(i64 120, ptr %21) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #6
  call void @llvm.lifetime.end.p0(i64 64, ptr %18) #6
  call void @llvm.lifetime.end.p0(i64 1888, ptr %17) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #6
  %75 = load i32, ptr %8, align 4
  ret i32 %75
}

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

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

declare i32 @sm2_verify_finish(ptr noundef, 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_VERIFY_CTX = type { %struct.SM3_CTX, %struct.SM3_CTX, %struct.SM2_KEY, [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.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_verify_certificate_verify = 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 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, -2147483648) i32 @tls13_verify_certificate_verify(i32 noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3, ptr nocapture noundef readonly %4, ptr noundef %5, i64 noundef %6) local_unnamed_addr #5 {
  %8 = alloca %struct.SM2_VERIFY_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 1888, 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 537, ptr noundef nonnull @__FUNCTION__.tls13_verify_certificate_verify) #7
  br label %33

17:                                               ; preds = %7, %13
  %.011 = 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_verify_init(ptr noundef nonnull %8, ptr noundef %1, ptr noundef %2, i64 noundef %3) #6
  %20 = call i32 @sm2_verify_update(ptr noundef nonnull %8, ptr noundef nonnull %9, i64 noundef 64) #6
  %21 = call i32 @sm2_verify_update(ptr noundef nonnull %8, ptr noundef nonnull %.011, i64 noundef %.0) #6
  %22 = load i64, ptr %12, align 8, !tbaa !9
  %23 = call i32 @sm2_verify_update(ptr noundef nonnull %8, ptr noundef nonnull %11, i64 noundef %22) #6
  %24 = call i32 @sm2_verify_finish(ptr noundef nonnull %8, ptr noundef %5, i64 noundef %6) #6
  %25 = icmp slt i32 %24, 0
  br i1 %25, label %26, label %29

26:                                               ; preds = %17
  %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 550, ptr noundef nonnull @__FUNCTION__.tls13_verify_certificate_verify) #7
  br label %33

29:                                               ; preds = %17
  %.not = icmp eq i32 %24, 1
  br i1 %.not, label %33, label %30

30:                                               ; preds = %29
  %31 = load ptr, ptr @stderr, align 8, !tbaa !5
  %32 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %31, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 554, ptr noundef nonnull @__FUNCTION__.tls13_verify_certificate_verify) #7
  br label %33

33:                                               ; preds = %29, %30, %26, %14
  %.012 = phi i32 [ -1, %14 ], [ -1, %26 ], [ %24, %30 ], [ 1, %29 ]
  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 1888, ptr nonnull %8) #6
  ret i32 %.012
}

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

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

declare i32 @sm2_verify_finish(ptr noundef, 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: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass