; 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.ECCSignature_st = type { [64 x i8], [64 x i8] }
%struct.SM2_SIGNATURE = type { [32 x i8], [32 x i8] }
%struct.SDF_PRIVATE_KEY = type { ptr, i32 }

@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 = external hidden unnamed_addr constant [9 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 @sdf_sign(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #2 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca %struct.ECCSignature_st, align 1
  %11 = alloca %struct.SM2_SIGNATURE, align 1
  %12 = alloca i32, align 4
  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 ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 128, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 64, ptr %11) #4
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %24

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

18:                                               ; preds = %15
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %24

21:                                               ; preds = %18
  %22 = load ptr, ptr %9, align 8, !tbaa !5
  %23 = icmp ne ptr %22, null
  br i1 %23, label %30, label %24

24:                                               ; preds = %21, %18, %15, %4
  br label %25

25:                                               ; preds = %24
  %26 = load ptr, ptr @stderr, align 8, !tbaa !5
  %27 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %26, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 783, ptr noundef @__FUNCTION__.sdf_sign) #4
  br label %28

28:                                               ; preds = %25
  br label %29

29:                                               ; preds = %28
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %67

30:                                               ; preds = %21
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.SDF_PRIVATE_KEY, ptr %31, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8, !tbaa !9
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.SDF_PRIVATE_KEY, ptr %34, i32 0, i32 1
  %36 = load i32, ptr %35, align 8, !tbaa !12
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = call i32 @SDF_InternalSign_ECC(ptr noundef %33, i32 noundef %36, ptr noundef %37, i32 noundef 32, ptr noundef %10)
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %46

40:                                               ; preds = %30
  br label %41

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

44:                                               ; preds = %41
  br label %45

45:                                               ; preds = %44
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %67

46:                                               ; preds = %30
  %47 = call i32 @ECCSignature_to_SM2_SIGNATURE(ptr noundef %10, ptr noundef %11)
  %48 = icmp ne i32 %47, 1
  br i1 %48, label %49, label %55

49:                                               ; preds = %46
  br label %50

50:                                               ; preds = %49
  %51 = load ptr, ptr @stderr, align 8, !tbaa !5
  %52 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %51, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 791, ptr noundef @__FUNCTION__.sdf_sign) #4
  br label %53

53:                                               ; preds = %50
  br label %54

54:                                               ; preds = %53
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %67

55:                                               ; preds = %46
  %56 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 0, ptr %56, align 8, !tbaa !13
  %57 = load ptr, ptr %9, align 8, !tbaa !5
  %58 = call i32 @sm2_signature_to_der(ptr noundef %11, ptr noundef %8, ptr noundef %57)
  %59 = icmp ne i32 %58, 1
  br i1 %59, label %60, label %66

60:                                               ; preds = %55
  br label %61

61:                                               ; preds = %60
  %62 = load ptr, ptr @stderr, align 8, !tbaa !5
  %63 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %62, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 796, ptr noundef @__FUNCTION__.sdf_sign) #4
  br label %64

64:                                               ; preds = %61
  br label %65

65:                                               ; preds = %64
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %67

66:                                               ; preds = %55
  store i32 1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %67

67:                                               ; preds = %66, %65, %54, %45, %29
  call void @llvm.lifetime.end.p0(i64 64, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 128, ptr %10) #4
  %68 = load i32, ptr %5, align 4
  ret i32 %68
}

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

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

declare i32 @sm2_signature_to_der(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, !6, i64 0}
!10 = !{!"", !6, i64 0, !11, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !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.ECCSignature_st = type { [64 x i8], [64 x i8] }
%struct.SM2_SIGNATURE = type { [32 x i8], [32 x i8] }

@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 = external hidden unnamed_addr constant [9 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 @sdf_sign(ptr noundef readonly %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #2 {
  %5 = alloca ptr, align 8
  %6 = alloca %struct.ECCSignature_st, align 1
  %7 = alloca %struct.SM2_SIGNATURE, align 1
  store ptr %2, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %6) #4
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %7) #4
  %8 = insertelement <4 x ptr> poison, ptr %0, i64 0
  %9 = insertelement <4 x ptr> %8, ptr %1, i64 1
  %10 = insertelement <4 x ptr> %9, ptr %2, i64 2
  %11 = insertelement <4 x ptr> %10, ptr %3, i64 3
  %12 = icmp eq <4 x ptr> %11, zeroinitializer
  %13 = bitcast <4 x i1> %12 to i4
  %14 = icmp eq i4 %13, 0
  br i1 %14, label %18, label %15

15:                                               ; preds = %4
  %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 783, ptr noundef nonnull @__FUNCTION__.sdf_sign) #5
  br label %36

18:                                               ; preds = %4
  %19 = load ptr, ptr %0, align 8, !tbaa !9
  %20 = getelementptr inbounds i8, ptr %0, i64 8
  %21 = load i32, ptr %20, align 8, !tbaa !12
  %22 = call i32 @SDF_InternalSign_ECC(ptr noundef %19, i32 noundef %21, ptr noundef nonnull %1, i32 noundef 32, ptr noundef nonnull %6) #4
  %.not = icmp eq i32 %22, 0
  br i1 %.not, label %26, label %23

23:                                               ; preds = %18
  %24 = load ptr, ptr @stderr, align 8, !tbaa !5
  %25 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %24, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 787, ptr noundef nonnull @__FUNCTION__.sdf_sign) #5
  br label %36

26:                                               ; preds = %18
  %27 = call i32 @ECCSignature_to_SM2_SIGNATURE(ptr noundef nonnull %6, ptr noundef nonnull %7)
  %.not16 = icmp eq i32 %27, 1
  br i1 %.not16, label %31, label %28

28:                                               ; preds = %26
  %29 = load ptr, ptr @stderr, align 8, !tbaa !5
  %30 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %29, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 791, ptr noundef nonnull @__FUNCTION__.sdf_sign) #5
  br label %36

31:                                               ; preds = %26
  store i64 0, ptr %3, align 8, !tbaa !13
  %32 = call i32 @sm2_signature_to_der(ptr noundef nonnull %7, ptr noundef nonnull %5, ptr noundef nonnull %3) #4
  %.not17 = icmp eq i32 %32, 1
  br i1 %.not17, label %36, label %33

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

36:                                               ; preds = %31, %33, %28, %23, %15
  %.0 = phi i32 [ -1, %23 ], [ -1, %28 ], [ -1, %33 ], [ -1, %15 ], [ 1, %31 ]
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %7) #4
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %6) #4
  ret i32 %.0
}

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

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

declare i32 @sm2_signature_to_der(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 = !{!10, !6, i64 0}
!10 = !{!"", !6, i64 0, !11, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}


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