; LLVM IR from guanzhi/GmSSL :: src (tls)

; 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.TLS_CLIENT_VERIFY_CTX = type { i32, [8 x ptr], [8 x i64] }

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [57 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [17 x i8], align 1
@__FUNCTION__.tls_client_verify_finish = external hidden unnamed_addr constant [25 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

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

declare i32 @sm2_verify_finish(ptr noundef, ptr noundef, i64 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @tls_client_verify_finish(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 %struct.SM2_VERIFY_CTX, align 8
  %12 = alloca i32, align 4
  %13 = 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) #4
  call void @llvm.lifetime.start.p0(i64 1888, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %25

16:                                               ; preds = %4
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %25

19:                                               ; preds = %16
  %20 = load i64, ptr %8, align 8, !tbaa !9
  %21 = icmp ne i64 %20, 0
  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, %16, %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 1980, ptr noundef @__FUNCTION__.tls_client_verify_finish) #4
  br label %29

29:                                               ; preds = %26
  br label %30

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

31:                                               ; preds = %22
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.TLS_CLIENT_VERIFY_CTX, ptr %32, i32 0, i32 0
  %34 = load i32, ptr %33, align 8, !tbaa !11
  %35 = icmp ne i32 %34, 8
  br i1 %35, label %36, label %42

36:                                               ; preds = %31
  br label %37

37:                                               ; preds = %36
  %38 = load ptr, ptr @stderr, align 8, !tbaa !5
  %39 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %38, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1985, ptr noundef @__FUNCTION__.tls_client_verify_finish) #4
  br label %40

40:                                               ; preds = %37
  br label %41

41:                                               ; preds = %40
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %94

42:                                               ; preds = %31
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  %44 = call i32 @sm2_verify_init(ptr noundef %11, ptr noundef %43, ptr noundef @.str.7, i64 noundef 16)
  %45 = icmp ne i32 %44, 1
  br i1 %45, label %46, label %52

46:                                               ; preds = %42
  br label %47

47:                                               ; preds = %46
  %48 = load ptr, ptr @stderr, align 8, !tbaa !5
  %49 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %48, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1989, ptr noundef @__FUNCTION__.tls_client_verify_finish) #4
  br label %50

50:                                               ; preds = %47
  br label %51

51:                                               ; preds = %50
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %94

52:                                               ; preds = %42
  store i32 0, ptr %12, align 4, !tbaa !14
  br label %53

53:                                               ; preds = %78, %52
  %54 = load i32, ptr %12, align 4, !tbaa !14
  %55 = icmp slt i32 %54, 8
  br i1 %55, label %56, label %81

56:                                               ; preds = %53
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.TLS_CLIENT_VERIFY_CTX, ptr %57, i32 0, i32 1
  %59 = load i32, ptr %12, align 4, !tbaa !14
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [8 x ptr], ptr %58, i64 0, i64 %60
  %62 = load ptr, ptr %61, align 8, !tbaa !5
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.TLS_CLIENT_VERIFY_CTX, ptr %63, i32 0, i32 2
  %65 = load i32, ptr %12, align 4, !tbaa !14
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [8 x i64], ptr %64, i64 0, i64 %66
  %68 = load i64, ptr %67, align 8, !tbaa !9
  %69 = call i32 @sm2_verify_update(ptr noundef %11, ptr noundef %62, i64 noundef %68)
  %70 = icmp ne i32 %69, 1
  br i1 %70, label %71, label %77

71:                                               ; preds = %56
  br label %72

72:                                               ; preds = %71
  %73 = load ptr, ptr @stderr, align 8, !tbaa !5
  %74 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %73, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1994, ptr noundef @__FUNCTION__.tls_client_verify_finish) #4
  br label %75

75:                                               ; preds = %72
  br label %76

76:                                               ; preds = %75
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %94

77:                                               ; preds = %56
  br label %78

78:                                               ; preds = %77
  %79 = load i32, ptr %12, align 4, !tbaa !14
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %12, align 4, !tbaa !14
  br label %53, !llvm.loop !15

81:                                               ; preds = %53
  %82 = load ptr, ptr %7, align 8, !tbaa !5
  %83 = load i64, ptr %8, align 8, !tbaa !9
  %84 = call i32 @sm2_verify_finish(ptr noundef %11, ptr noundef %82, i64 noundef %83)
  store i32 %84, ptr %10, align 4, !tbaa !14
  %85 = icmp slt i32 %84, 0
  br i1 %85, label %86, label %92

86:                                               ; preds = %81
  br label %87

87:                                               ; preds = %86
  %88 = load ptr, ptr @stderr, align 8, !tbaa !5
  %89 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %88, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1999, ptr noundef @__FUNCTION__.tls_client_verify_finish) #4
  br label %90

90:                                               ; preds = %87
  br label %91

91:                                               ; preds = %90
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %94

92:                                               ; preds = %81
  %93 = load i32, ptr %10, align 4, !tbaa !14
  store i32 %93, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %94

94:                                               ; preds = %92, %91, %76, %51, %41, %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 1888, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  %95 = load i32, ptr %5, align 4
  ret i32 %95
}

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 = { "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 = { 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, !13, i64 0}
!12 = !{!"", !13, i64 0, !7, i64 8, !7, i64 72}
!13 = !{!"int", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; 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] }

@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 [57 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [17 x i8], align 1
@__FUNCTION__.tls_client_verify_finish = external hidden unnamed_addr constant [25 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

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

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

declare i32 @sm2_verify_finish(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, -2147483648) i32 @tls_client_verify_finish(ptr noundef readonly %0, ptr noundef %1, i64 noundef %2, ptr noundef %3) local_unnamed_addr #3 {
  %5 = alloca %struct.SM2_VERIFY_CTX, align 8
  call void @llvm.lifetime.start.p0(i64 1888, ptr nonnull %5) #4
  %6 = icmp ne ptr %0, null
  %7 = icmp ne ptr %1, null
  %or.cond = and i1 %6, %7
  %8 = icmp ne i64 %2, 0
  %or.cond3 = and i1 %or.cond, %8
  %9 = icmp ne ptr %3, null
  %or.cond5 = and i1 %or.cond3, %9
  br i1 %or.cond5, label %13, label %10

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

13:                                               ; preds = %4
  %14 = load i32, ptr %0, align 8, !tbaa !9
  %.not = icmp eq i32 %14, 8
  br i1 %.not, label %18, label %15

15:                                               ; preds = %13
  %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 1985, ptr noundef nonnull @__FUNCTION__.tls_client_verify_finish) #5
  br label %79

18:                                               ; preds = %13
  %19 = call i32 @sm2_verify_init(ptr noundef nonnull %5, ptr noundef nonnull %3, ptr noundef nonnull @.str.7, i64 noundef 16) #4
  %.not26 = icmp eq i32 %19, 1
  br i1 %.not26, label %.preheader, label %25

.preheader:                                       ; preds = %18
  %20 = getelementptr inbounds i8, ptr %0, i64 8
  %21 = getelementptr inbounds i8, ptr %0, i64 72
  %22 = load ptr, ptr %20, align 8, !tbaa !5
  %23 = load i64, ptr %21, align 8, !tbaa !12
  %24 = call i32 @sm2_verify_update(ptr noundef nonnull %5, ptr noundef %22, i64 noundef %23) #4
  %.not27 = icmp eq i32 %24, 1
  br i1 %.not27, label %28, label %73

25:                                               ; preds = %18
  %26 = load ptr, ptr @stderr, align 8, !tbaa !5
  %27 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %26, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 1989, ptr noundef nonnull @__FUNCTION__.tls_client_verify_finish) #5
  br label %79

28:                                               ; preds = %.preheader
  %29 = getelementptr inbounds i8, ptr %0, i64 16
  %30 = load ptr, ptr %29, align 8, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %0, i64 80
  %32 = load i64, ptr %31, align 8, !tbaa !12
  %33 = call i32 @sm2_verify_update(ptr noundef nonnull %5, ptr noundef %30, i64 noundef %32) #4
  %.not27.1 = icmp eq i32 %33, 1
  br i1 %.not27.1, label %34, label %73

34:                                               ; preds = %28
  %35 = getelementptr inbounds i8, ptr %0, i64 24
  %36 = load ptr, ptr %35, align 8, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %0, i64 88
  %38 = load i64, ptr %37, align 8, !tbaa !12
  %39 = call i32 @sm2_verify_update(ptr noundef nonnull %5, ptr noundef %36, i64 noundef %38) #4
  %.not27.2 = icmp eq i32 %39, 1
  br i1 %.not27.2, label %40, label %73

40:                                               ; preds = %34
  %41 = getelementptr inbounds i8, ptr %0, i64 32
  %42 = load ptr, ptr %41, align 8, !tbaa !5
  %43 = getelementptr inbounds i8, ptr %0, i64 96
  %44 = load i64, ptr %43, align 8, !tbaa !12
  %45 = call i32 @sm2_verify_update(ptr noundef nonnull %5, ptr noundef %42, i64 noundef %44) #4
  %.not27.3 = icmp eq i32 %45, 1
  br i1 %.not27.3, label %46, label %73

46:                                               ; preds = %40
  %47 = getelementptr inbounds i8, ptr %0, i64 40
  %48 = load ptr, ptr %47, align 8, !tbaa !5
  %49 = getelementptr inbounds i8, ptr %0, i64 104
  %50 = load i64, ptr %49, align 8, !tbaa !12
  %51 = call i32 @sm2_verify_update(ptr noundef nonnull %5, ptr noundef %48, i64 noundef %50) #4
  %.not27.4 = icmp eq i32 %51, 1
  br i1 %.not27.4, label %52, label %73

52:                                               ; preds = %46
  %53 = getelementptr inbounds i8, ptr %0, i64 48
  %54 = load ptr, ptr %53, align 8, !tbaa !5
  %55 = getelementptr inbounds i8, ptr %0, i64 112
  %56 = load i64, ptr %55, align 8, !tbaa !12
  %57 = call i32 @sm2_verify_update(ptr noundef nonnull %5, ptr noundef %54, i64 noundef %56) #4
  %.not27.5 = icmp eq i32 %57, 1
  br i1 %.not27.5, label %58, label %73

58:                                               ; preds = %52
  %59 = getelementptr inbounds i8, ptr %0, i64 56
  %60 = load ptr, ptr %59, align 8, !tbaa !5
  %61 = getelementptr inbounds i8, ptr %0, i64 120
  %62 = load i64, ptr %61, align 8, !tbaa !12
  %63 = call i32 @sm2_verify_update(ptr noundef nonnull %5, ptr noundef %60, i64 noundef %62) #4
  %.not27.6 = icmp eq i32 %63, 1
  br i1 %.not27.6, label %64, label %73

64:                                               ; preds = %58
  %65 = getelementptr inbounds i8, ptr %0, i64 64
  %66 = load ptr, ptr %65, align 8, !tbaa !5
  %67 = getelementptr inbounds i8, ptr %0, i64 128
  %68 = load i64, ptr %67, align 8, !tbaa !12
  %69 = call i32 @sm2_verify_update(ptr noundef nonnull %5, ptr noundef %66, i64 noundef %68) #4
  %.not27.7 = icmp eq i32 %69, 1
  br i1 %.not27.7, label %70, label %73

70:                                               ; preds = %64
  %71 = call i32 @sm2_verify_finish(ptr noundef nonnull %5, ptr noundef nonnull %1, i64 noundef %2) #4
  %72 = icmp slt i32 %71, 0
  br i1 %72, label %76, label %79

73:                                               ; preds = %64, %58, %52, %46, %40, %34, %28, %.preheader
  %74 = load ptr, ptr @stderr, align 8, !tbaa !5
  %75 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %74, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 1994, ptr noundef nonnull @__FUNCTION__.tls_client_verify_finish) #5
  br label %79

76:                                               ; preds = %70
  %77 = load ptr, ptr @stderr, align 8, !tbaa !5
  %78 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %77, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 1999, ptr noundef nonnull @__FUNCTION__.tls_client_verify_finish) #5
  br label %79

79:                                               ; preds = %70, %76, %73, %25, %15, %10
  %.020 = phi i32 [ -1, %15 ], [ -1, %25 ], [ -1, %73 ], [ -1, %76 ], [ -1, %10 ], [ %71, %70 ]
  call void @llvm.lifetime.end.p0(i64 1888, ptr nonnull %5) #4
  ret i32 %.020
}

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 = { "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 = { 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 }
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, !11, i64 0}
!10 = !{!"", !11, i64 0, !7, i64 8, !7, i64 72}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"long", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass