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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @tls_sign_server_ecdh_params(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, ptr noundef %4, ptr noundef %5, ptr noundef %6) #2 {
  %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 ptr, align 8
  %16 = alloca [69 x i8], align 16
  %17 = alloca %struct.SM2_SIGN_CTX, align 8
  %18 = 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 ptr %6, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 69, ptr %16) #4
  call void @llvm.lifetime.start.p0(i64 3976, ptr %17) #4
  %19 = load ptr, ptr %9, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %39

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

24:                                               ; preds = %21
  %25 = load ptr, ptr %11, align 8, !tbaa !5
  %26 = icmp ne ptr %25, null
  br i1 %26, label %27, label %39

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

30:                                               ; preds = %27
  %31 = load ptr, ptr %13, align 8, !tbaa !5
  %32 = icmp ne ptr %31, null
  br i1 %32, label %33, label %39

33:                                               ; preds = %30
  %34 = load ptr, ptr %14, align 8, !tbaa !5
  %35 = icmp ne ptr %34, null
  br i1 %35, label %36, label %39

36:                                               ; preds = %33
  %37 = load ptr, ptr %15, align 8, !tbaa !5
  %38 = icmp ne ptr %37, null
  br i1 %38, label %45, label %39

39:                                               ; preds = %36, %33, %30, %27, %24, %21, %7
  br label %40

40:                                               ; preds = %39
  %41 = load ptr, ptr @stderr, align 8, !tbaa !5
  %42 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %41, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 547, ptr noundef @__FUNCTION__.tls_sign_server_ecdh_params) #4
  br label %43

43:                                               ; preds = %40
  br label %44

44:                                               ; preds = %43
  store i32 -1, ptr %8, align 4
  store i32 1, ptr %18, align 4
  br label %70

45:                                               ; preds = %36
  %46 = getelementptr inbounds [69 x i8], ptr %16, i64 0, i64 0
  store i8 3, ptr %46, align 16, !tbaa !11
  %47 = load i32, ptr %12, align 4, !tbaa !9
  %48 = ashr i32 %47, 8
  %49 = trunc i32 %48 to i8
  %50 = getelementptr inbounds [69 x i8], ptr %16, i64 0, i64 1
  store i8 %49, ptr %50, align 1, !tbaa !11
  %51 = load i32, ptr %12, align 4, !tbaa !9
  %52 = trunc i32 %51 to i8
  %53 = getelementptr inbounds [69 x i8], ptr %16, i64 0, i64 2
  store i8 %52, ptr %53, align 2, !tbaa !11
  %54 = getelementptr inbounds [69 x i8], ptr %16, i64 0, i64 3
  store i8 65, ptr %54, align 1, !tbaa !11
  %55 = load ptr, ptr %13, align 8, !tbaa !5
  %56 = getelementptr inbounds [69 x i8], ptr %16, i64 0, i64 0
  %57 = getelementptr inbounds i8, ptr %56, i64 4
  %58 = call i32 @sm2_z256_point_to_uncompressed_octets(ptr noundef %55, ptr noundef %57)
  %59 = load ptr, ptr %9, align 8, !tbaa !5
  %60 = call i32 @sm2_sign_init(ptr noundef %17, ptr noundef %59, ptr noundef @.str.7, i64 noundef 16)
  %61 = load ptr, ptr %10, align 8, !tbaa !5
  %62 = call i32 @sm2_sign_update(ptr noundef %17, ptr noundef %61, i64 noundef 32)
  %63 = load ptr, ptr %11, align 8, !tbaa !5
  %64 = call i32 @sm2_sign_update(ptr noundef %17, ptr noundef %63, i64 noundef 32)
  %65 = getelementptr inbounds [69 x i8], ptr %16, i64 0, i64 0
  %66 = call i32 @sm2_sign_update(ptr noundef %17, ptr noundef %65, i64 noundef 69)
  %67 = load ptr, ptr %14, align 8, !tbaa !5
  %68 = load ptr, ptr %15, align 8, !tbaa !5
  %69 = call i32 @sm2_sign_finish(ptr noundef %17, ptr noundef %67, ptr noundef %68)
  store i32 1, ptr %8, align 4
  store i32 1, ptr %18, align 4
  br label %70

70:                                               ; preds = %45, %44
  call void @llvm.lifetime.end.p0(i64 3976, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 69, ptr %16) #4
  %71 = load i32, ptr %8, align 4
  ret i32 %71
}

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

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

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

declare i32 @sm2_sign_finish(ptr noundef, ptr noundef, 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = !{!"int", !7, i64 0}
!11 = !{!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] }

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @tls_sign_server_ecdh_params(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, ptr noundef %4, ptr noundef %5, ptr noundef %6) local_unnamed_addr #2 {
  %8 = alloca [69 x i8], align 16
  %9 = alloca %struct.SM2_SIGN_CTX, align 8
  call void @llvm.lifetime.start.p0(i64 69, ptr nonnull %8) #4
  call void @llvm.lifetime.start.p0(i64 3976, 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 i32 %3, 41
  %15 = icmp ne ptr %5, null
  %16 = icmp ne ptr %6, null
  %17 = icmp eq <4 x ptr> %13, zeroinitializer
  %18 = bitcast <4 x i1> %17 to i4
  %19 = icmp eq i4 %18, 0
  %op.rdx = and i1 %19, %15
  %op.rdx39 = and i1 %16, %14
  %op.rdx40 = and i1 %op.rdx, %op.rdx39
  br i1 %op.rdx40, label %23, label %20

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

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

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

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

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

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

declare i32 @sm2_sign_finish(ptr noundef, ptr noundef, 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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, !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: EarlyCSEPass,GlobalDCEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass