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

@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_verify_server_ecdh_params = 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

declare i32 @sm2_z256_point_to_uncompressed_octets(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @tls_verify_server_ecdh_params(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, ptr noundef %4, ptr noundef %5, i64 noundef %6) #3 {
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  %16 = alloca i32, align 4
  %17 = alloca [69 x i8], align 16
  %18 = alloca %struct.SM2_VERIFY_CTX, align 8
  %19 = alloca i32, align 4
  store ptr %0, ptr %9, align 8, !tbaa !5
  store ptr %1, ptr %10, align 8, !tbaa !5
  store ptr %2, ptr %11, align 8, !tbaa !5
  store i32 %3, ptr %12, align 4, !tbaa !9
  store ptr %4, ptr %13, align 8, !tbaa !5
  store ptr %5, ptr %14, align 8, !tbaa !5
  store i64 %6, ptr %15, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #4
  call void @llvm.lifetime.start.p0(i64 69, ptr %17) #4
  call void @llvm.lifetime.start.p0(i64 1888, ptr %18) #4
  %20 = load ptr, ptr %9, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %43

22:                                               ; preds = %7
  %23 = load ptr, ptr %10, align 8, !tbaa !5
  %24 = icmp ne ptr %23, null
  br i1 %24, label %25, label %43

25:                                               ; preds = %22
  %26 = load ptr, ptr %11, align 8, !tbaa !5
  %27 = icmp ne ptr %26, null
  br i1 %27, label %28, label %43

28:                                               ; preds = %25
  %29 = load i32, ptr %12, align 4, !tbaa !9
  %30 = icmp ne i32 %29, 41
  br i1 %30, label %43, label %31

31:                                               ; preds = %28
  %32 = load ptr, ptr %13, align 8, !tbaa !5
  %33 = icmp ne ptr %32, null
  br i1 %33, label %34, label %43

34:                                               ; preds = %31
  %35 = load ptr, ptr %14, align 8, !tbaa !5
  %36 = icmp ne ptr %35, null
  br i1 %36, label %37, label %43

37:                                               ; preds = %34
  %38 = load i64, ptr %15, align 8, !tbaa !11
  %39 = icmp ne i64 %38, 0
  br i1 %39, label %40, label %43

40:                                               ; preds = %37
  %41 = load i64, ptr %15, align 8, !tbaa !11
  %42 = icmp ugt i64 %41, 72
  br i1 %42, label %43, label %49

43:                                               ; preds = %40, %37, %34, %31, %28, %25, %22, %7
  br label %44

44:                                               ; preds = %43
  %45 = load ptr, ptr @stderr, align 8, !tbaa !5
  %46 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %45, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 576, ptr noundef @__FUNCTION__.tls_verify_server_ecdh_params) #4
  br label %47

47:                                               ; preds = %44
  br label %48

48:                                               ; preds = %47
  store i32 -1, ptr %8, align 4
  store i32 1, ptr %19, align 4
  br label %84

49:                                               ; preds = %40
  %50 = getelementptr inbounds [69 x i8], ptr %17, i64 0, i64 0
  store i8 3, ptr %50, align 16, !tbaa !13
  %51 = load i32, ptr %12, align 4, !tbaa !9
  %52 = ashr i32 %51, 8
  %53 = trunc i32 %52 to i8
  %54 = getelementptr inbounds [69 x i8], ptr %17, i64 0, i64 1
  store i8 %53, ptr %54, align 1, !tbaa !13
  %55 = load i32, ptr %12, align 4, !tbaa !9
  %56 = trunc i32 %55 to i8
  %57 = getelementptr inbounds [69 x i8], ptr %17, i64 0, i64 2
  store i8 %56, ptr %57, align 2, !tbaa !13
  %58 = getelementptr inbounds [69 x i8], ptr %17, i64 0, i64 3
  store i8 65, ptr %58, align 1, !tbaa !13
  %59 = load ptr, ptr %13, align 8, !tbaa !5
  %60 = getelementptr inbounds [69 x i8], ptr %17, i64 0, i64 0
  %61 = getelementptr inbounds i8, ptr %60, i64 4
  %62 = call i32 @sm2_z256_point_to_uncompressed_octets(ptr noundef %59, ptr noundef %61)
  %63 = load ptr, ptr %9, align 8, !tbaa !5
  %64 = call i32 @sm2_verify_init(ptr noundef %18, ptr noundef %63, ptr noundef @.str.7, i64 noundef 16)
  %65 = load ptr, ptr %10, align 8, !tbaa !5
  %66 = call i32 @sm2_verify_update(ptr noundef %18, ptr noundef %65, i64 noundef 32)
  %67 = load ptr, ptr %11, align 8, !tbaa !5
  %68 = call i32 @sm2_verify_update(ptr noundef %18, ptr noundef %67, i64 noundef 32)
  %69 = getelementptr inbounds [69 x i8], ptr %17, i64 0, i64 0
  %70 = call i32 @sm2_verify_update(ptr noundef %18, ptr noundef %69, i64 noundef 69)
  %71 = load ptr, ptr %14, align 8, !tbaa !5
  %72 = load i64, ptr %15, align 8, !tbaa !11
  %73 = call i32 @sm2_verify_finish(ptr noundef %18, ptr noundef %71, i64 noundef %72)
  store i32 %73, ptr %16, align 4, !tbaa !9
  %74 = load i32, ptr %16, align 4, !tbaa !9
  %75 = icmp ne i32 %74, 1
  br i1 %75, label %76, label %82

76:                                               ; preds = %49
  br label %77

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

80:                                               ; preds = %77
  br label %81

81:                                               ; preds = %80
  br label %82

82:                                               ; preds = %81, %49
  %83 = load i32, ptr %16, align 4, !tbaa !9
  store i32 %83, ptr %8, align 4
  store i32 1, ptr %19, align 4
  br label %84

84:                                               ; preds = %82, %48
  call void @llvm.lifetime.end.p0(i64 1888, ptr %18) #4
  call void @llvm.lifetime.end.p0(i64 69, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  %85 = load i32, ptr %8, align 4
  ret i32 %85
}

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

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

@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_verify_server_ecdh_params = 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

declare i32 @sm2_z256_point_to_uncompressed_octets(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local i32 @tls_verify_server_ecdh_params(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, ptr noundef %4, ptr noundef %5, i64 noundef %6) local_unnamed_addr #3 {
  %8 = alloca [69 x i8], align 16
  %9 = alloca %struct.SM2_VERIFY_CTX, align 8
  call void @llvm.lifetime.start.p0(i64 69, ptr nonnull %8) #4
  call void @llvm.lifetime.start.p0(i64 1888, ptr nonnull %9) #4
  %10 = insertelement <4 x ptr> poison, ptr %0, i64 0
  %11 = insertelement <4 x ptr> %10, ptr %1, i64 1
  %12 = insertelement <4 x ptr> %11, ptr %2, i64 2
  %13 = insertelement <4 x ptr> %12, ptr %4, i64 3
  %14 = icmp eq <4 x ptr> %13, zeroinitializer
  %15 = icmp ne i32 %3, 41
  %16 = icmp eq ptr %5, null
  %17 = add i64 %6, -73
  %18 = icmp ult i64 %17, -72
  %19 = bitcast <4 x i1> %14 to i4
  %20 = icmp ne i4 %19, 0
  %op.rdx = or i1 %20, %16
  %op.rdx54 = or i1 %18, %15
  %op.rdx55 = or i1 %op.rdx, %op.rdx54
  br i1 %op.rdx55, label %21, label %24

21:                                               ; preds = %7
  %22 = load ptr, ptr @stderr, align 8, !tbaa !5
  %23 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %22, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 576, ptr noundef nonnull @__FUNCTION__.tls_verify_server_ecdh_params) #5
  br label %35

24:                                               ; preds = %7
  store <4 x i8> <i8 3, i8 0, i8 41, i8 65>, ptr %8, align 16, !tbaa !9
  %25 = getelementptr inbounds i8, ptr %8, i64 4
  %26 = call i32 @sm2_z256_point_to_uncompressed_octets(ptr noundef nonnull %4, ptr noundef nonnull %25) #4
  %27 = call i32 @sm2_verify_init(ptr noundef nonnull %9, ptr noundef %0, ptr noundef nonnull @.str.7, i64 noundef 16) #4
  %28 = call i32 @sm2_verify_update(ptr noundef nonnull %9, ptr noundef %1, i64 noundef 32) #4
  %29 = call i32 @sm2_verify_update(ptr noundef nonnull %9, ptr noundef nonnull %2, i64 noundef 32) #4
  %30 = call i32 @sm2_verify_update(ptr noundef nonnull %9, ptr noundef nonnull %8, i64 noundef 69) #4
  %31 = call i32 @sm2_verify_finish(ptr noundef nonnull %9, ptr noundef nonnull %5, i64 noundef %6) #4
  %.not = icmp eq i32 %31, 1
  br i1 %.not, label %35, label %32

32:                                               ; preds = %24
  %33 = load ptr, ptr @stderr, align 8, !tbaa !5
  %34 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %33, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 590, ptr noundef nonnull @__FUNCTION__.tls_verify_server_ecdh_params) #5
  br label %35

35:                                               ; preds = %24, %32, %21
  %.0 = phi i32 [ -1, %21 ], [ %31, %32 ], [ 1, %24 ]
  call void @llvm.lifetime.end.p0(i64 1888, ptr nonnull %9) #4
  call void @llvm.lifetime.end.p0(i64 69, ptr nonnull %8) #4
  ret i32 %.0
}

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

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 = !{!7, !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalDCEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass