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

; 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.ECCrefPublicKey_st = type { i32, [64 x i8], [64 x i8] }
%struct.SM2_Z256_POINT = type { [4 x i64], [4 x i64], [4 x i64] }
%struct.SDF_PRIVATE_KEY = type { ptr, i32 }
%struct.SDF_SIGN_CTX = type { %struct.SM3_CTX, %struct.SM3_CTX, %struct.SDF_PRIVATE_KEY }
%struct.SM3_CTX = type { [8 x i32], i64, [64 x i8], 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 [61 x i8], align 1
@__FUNCTION__.sdf_sign_init = external hidden unnamed_addr constant [14 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

; Function Attrs: nounwind uwtable
declare hidden i32 @ECCrefPublicKey_to_SM2_Z256_POINT(ptr noundef, ptr noundef) #4

; Function Attrs: nounwind uwtable
define dso_local i32 @sdf_sign_init(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3) #4 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca %struct.ECCrefPublicKey_st, align 1
  %11 = alloca %struct.SM2_Z256_POINT, align 8
  %12 = alloca i32, align 4
  %13 = alloca [32 x i8], align 16
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i64 %3, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 132, ptr %10) #5
  call void @llvm.lifetime.start.p0(i64 96, ptr %11) #5
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %19

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

19:                                               ; preds = %16, %4
  br label %20

20:                                               ; preds = %19
  %21 = load ptr, ptr @stderr, align 8, !tbaa !5
  %22 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 847, ptr noundef @__FUNCTION__.sdf_sign_init) #5
  br label %23

23:                                               ; preds = %20
  br label %24

24:                                               ; preds = %23
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %96

25:                                               ; preds = %16
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.SDF_PRIVATE_KEY, ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !11
  %29 = icmp ne ptr %28, null
  br i1 %29, label %36, label %30

30:                                               ; preds = %25
  br label %31

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

34:                                               ; preds = %31
  br label %35

35:                                               ; preds = %34
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %96

36:                                               ; preds = %25
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.SDF_PRIVATE_KEY, ptr %37, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !11
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.SDF_PRIVATE_KEY, ptr %40, i32 0, i32 1
  %42 = load i32, ptr %41, align 8, !tbaa !14
  %43 = call i32 @SDF_ExportSignPublicKey_ECC(ptr noundef %39, i32 noundef %42, ptr noundef %10)
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %45, label %51

45:                                               ; preds = %36
  br label %46

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

49:                                               ; preds = %46
  br label %50

50:                                               ; preds = %49
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %96

51:                                               ; preds = %36
  %52 = call i32 @ECCrefPublicKey_to_SM2_Z256_POINT(ptr noundef %10, ptr noundef %11)
  %53 = icmp ne i32 %52, 1
  br i1 %53, label %54, label %60

54:                                               ; preds = %51
  br label %55

55:                                               ; preds = %54
  %56 = load ptr, ptr @stderr, align 8, !tbaa !5
  %57 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %56, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 860, ptr noundef @__FUNCTION__.sdf_sign_init) #5
  br label %58

58:                                               ; preds = %55
  br label %59

59:                                               ; preds = %58
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %96

60:                                               ; preds = %51
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.SDF_SIGN_CTX, ptr %61, i32 0, i32 0
  call void @sm3_init(ptr noundef %62)
  %63 = load ptr, ptr %8, align 8, !tbaa !5
  %64 = icmp ne ptr %63, null
  br i1 %64, label %65, label %88

65:                                               ; preds = %60
  call void @llvm.lifetime.start.p0(i64 32, ptr %13) #5
  %66 = load i64, ptr %9, align 8, !tbaa !9
  %67 = icmp ule i64 %66, 0
  br i1 %67, label %71, label %68

68:                                               ; preds = %65
  %69 = load i64, ptr %9, align 8, !tbaa !9
  %70 = icmp ugt i64 %69, 8191
  br i1 %70, label %71, label %77

71:                                               ; preds = %68, %65
  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 869, ptr noundef @__FUNCTION__.sdf_sign_init) #5
  br label %75

75:                                               ; preds = %72
  br label %76

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

77:                                               ; preds = %68
  %78 = getelementptr inbounds [32 x i8], ptr %13, i64 0, i64 0
  %79 = load ptr, ptr %8, align 8, !tbaa !5
  %80 = load i64, ptr %9, align 8, !tbaa !9
  %81 = call i32 @sm2_compute_z(ptr noundef %78, ptr noundef %11, ptr noundef %79, i64 noundef %80)
  %82 = load ptr, ptr %6, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.SDF_SIGN_CTX, ptr %82, i32 0, i32 0
  %84 = getelementptr inbounds [32 x i8], ptr %13, i64 0, i64 0
  call void @sm3_update(ptr noundef %83, ptr noundef %84, i64 noundef 32)
  store i32 0, ptr %12, align 4
  br label %85

85:                                               ; preds = %77, %76
  call void @llvm.lifetime.end.p0(i64 32, ptr %13) #5
  %86 = load i32, ptr %12, align 4
  switch i32 %86, label %96 [
    i32 0, label %87
  ]

87:                                               ; preds = %85
  br label %88

88:                                               ; preds = %87, %60
  %89 = load ptr, ptr %6, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.SDF_SIGN_CTX, ptr %89, i32 0, i32 1
  %91 = load ptr, ptr %6, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.SDF_SIGN_CTX, ptr %91, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %90, ptr align 8 %92, i64 112, i1 false), !tbaa.struct !15
  %93 = load ptr, ptr %6, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.SDF_SIGN_CTX, ptr %93, i32 0, i32 2
  %95 = load ptr, ptr %7, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %94, ptr align 8 %95, i64 16, i1 false), !tbaa.struct !17
  store i32 1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %96

96:                                               ; preds = %88, %85, %59, %50, %35, %24
  call void @llvm.lifetime.end.p0(i64 96, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 132, ptr %10) #5
  %97 = load i32, ptr %5, align 4
  ret i32 %97
}

declare void @sm3_init(ptr noundef) #3

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

declare void @sm3_update(ptr noundef, ptr noundef, i64 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 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 #5 = { 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, !6, i64 0}
!12 = !{!"", !6, i64 0, !13, i64 8}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !13, i64 8}
!15 = !{i64 0, i64 32, !16, i64 32, i64 8, !9, i64 40, i64 64, !16, i64 104, i64 8, !9}
!16 = !{!7, !7, i64 0}
!17 = !{i64 0, i64 8, !5, i64 8, i64 4, !18}
!18 = !{!13, !13, 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.ECCrefPublicKey_st = type { i32, [64 x i8], [64 x i8] }
%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 [61 x i8], align 1
@__FUNCTION__.sdf_sign_init = external hidden unnamed_addr constant [14 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

; Function Attrs: nounwind uwtable
declare hidden i32 @ECCrefPublicKey_to_SM2_Z256_POINT(ptr noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @sdf_sign_init(ptr noundef %0, ptr noundef readonly %1, ptr noundef %2, i64 noundef %3) local_unnamed_addr #4 {
  %5 = alloca %struct.ECCrefPublicKey_st, align 1
  %6 = alloca %struct.SM2_Z256_POINT, align 8
  %7 = alloca [32 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 132, ptr nonnull %5) #5
  call void @llvm.lifetime.start.p0(i64 96, ptr nonnull %6) #5
  %8 = icmp ne ptr %0, null
  %9 = icmp ne ptr %1, null
  %or.cond = and i1 %8, %9
  br i1 %or.cond, 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 847, ptr noundef nonnull @__FUNCTION__.sdf_sign_init) #6
  br label %40

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

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 851, ptr noundef nonnull @__FUNCTION__.sdf_sign_init) #6
  br label %40

18:                                               ; preds = %13
  %19 = getelementptr inbounds i8, ptr %1, i64 8
  %20 = load i32, ptr %19, align 8, !tbaa !12
  %21 = call i32 @SDF_ExportSignPublicKey_ECC(ptr noundef nonnull %14, i32 noundef %20, ptr noundef nonnull %5) #5
  %.not26 = icmp eq i32 %21, 0
  br i1 %.not26, label %25, label %22

22:                                               ; preds = %18
  %23 = load ptr, ptr @stderr, align 8, !tbaa !5
  %24 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %23, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 856, ptr noundef nonnull @__FUNCTION__.sdf_sign_init) #6
  br label %40

25:                                               ; preds = %18
  %26 = call i32 @ECCrefPublicKey_to_SM2_Z256_POINT(ptr noundef nonnull %5, ptr noundef nonnull %6)
  %.not27 = icmp eq i32 %26, 1
  br i1 %.not27, label %30, label %27

27:                                               ; preds = %25
  %28 = load ptr, ptr @stderr, align 8, !tbaa !5
  %29 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %28, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 860, ptr noundef nonnull @__FUNCTION__.sdf_sign_init) #6
  br label %40

30:                                               ; preds = %25
  call void @sm3_init(ptr noundef nonnull %0) #5
  %.not28 = icmp eq ptr %2, null
  br i1 %.not28, label %37, label %31

31:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %7) #5
  %32 = add i64 %3, -1
  %or.cond3 = icmp ult i64 %32, 8191
  br i1 %or.cond3, label %.thread, label %34

.thread:                                          ; preds = %31
  %33 = call i32 @sm2_compute_z(ptr noundef nonnull %7, ptr noundef nonnull %6, ptr noundef nonnull %2, i64 noundef %3) #5
  call void @sm3_update(ptr noundef nonnull %0, ptr noundef nonnull %7, i64 noundef 32) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %7) #5
  br label %37

34:                                               ; preds = %31
  %35 = load ptr, ptr @stderr, align 8, !tbaa !5
  %36 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %35, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 869, ptr noundef nonnull @__FUNCTION__.sdf_sign_init) #6
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %7) #5
  br label %40

37:                                               ; preds = %.thread, %30
  %38 = getelementptr inbounds i8, ptr %0, i64 112
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(112) %38, ptr noundef nonnull align 8 dereferenceable(112) %0, i64 112, i1 false), !tbaa.struct !13
  %39 = getelementptr inbounds i8, ptr %0, i64 224
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %39, ptr noundef nonnull align 8 dereferenceable(16) %1, i64 16, i1 false), !tbaa.struct !17
  br label %40

40:                                               ; preds = %34, %37, %27, %22, %15, %10
  %.1 = phi i32 [ -1, %22 ], [ -1, %27 ], [ 1, %37 ], [ -1, %34 ], [ -1, %15 ], [ -1, %10 ]
  call void @llvm.lifetime.end.p0(i64 96, ptr nonnull %6) #5
  call void @llvm.lifetime.end.p0(i64 132, ptr nonnull %5) #5
  ret i32 %.1
}

declare void @sm3_init(ptr noundef) local_unnamed_addr #3

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

declare void @sm3_update(ptr noundef, ptr noundef, i64 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 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 #5 = { nounwind }
attributes #6 = { 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, !6, i64 0}
!10 = !{!"", !6, i64 0, !11, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = !{i64 0, i64 32, !14, i64 32, i64 8, !15, i64 40, i64 64, !14, i64 104, i64 8, !15}
!14 = !{!7, !7, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"long", !7, i64 0}
!17 = !{i64 0, i64 8, !5, i64 8, i64 4, !18}
!18 = !{!11, !11, i64 0}


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