; 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.ECCCipher_st = type <{ [64 x i8], [64 x i8], [32 x i8], i32, [1 x i8], [254 x i8] }>
%struct.SM2_CIPHERTEXT = type { %struct.SM2_POINT, [32 x i8], i8, [255 x i8] }
%struct.SM2_POINT = 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_decrypt = external hidden unnamed_addr constant [12 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_ciphertext_from_der(ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @ECCCipher_from_SM2_CIPHERTEXT(ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local i32 @sdf_decrypt(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4) #3 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca %struct.ECCCipher_st, align 1
  %13 = alloca %struct.SM2_CIPHERTEXT, align 1
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i64 %2, ptr %9, align 8, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 419, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 352, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  store i32 0, ptr %14, align 4, !tbaa !11
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %24

18:                                               ; preds = %5
  %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 %11, align 8, !tbaa !5
  %23 = icmp ne ptr %22, null
  br i1 %23, label %30, label %24

24:                                               ; preds = %21, %18, %5
  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 809, ptr noundef @__FUNCTION__.sdf_decrypt) #4
  br label %28

28:                                               ; preds = %25
  br label %29

29:                                               ; preds = %28
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %89

30:                                               ; preds = %21
  %31 = load ptr, ptr %7, 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 !13
  %34 = icmp ne ptr %33, null
  br i1 %34, label %35, label %40

35:                                               ; preds = %30
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.SDF_PRIVATE_KEY, ptr %36, i32 0, i32 1
  %38 = load i32, ptr %37, align 8, !tbaa !15
  %39 = icmp slt i32 %38, 0
  br i1 %39, label %40, label %46

40:                                               ; preds = %35, %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 813, ptr noundef @__FUNCTION__.sdf_decrypt) #4
  br label %44

44:                                               ; preds = %41
  br label %45

45:                                               ; preds = %44
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %89

46:                                               ; preds = %35
  %47 = load ptr, ptr %10, align 8, !tbaa !5
  %48 = icmp ne ptr %47, null
  br i1 %48, label %51, label %49

49:                                               ; preds = %46
  %50 = load ptr, ptr %11, align 8, !tbaa !5
  store i64 255, ptr %50, align 8, !tbaa !9
  store i32 1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %89

51:                                               ; preds = %46
  %52 = call i32 @sm2_ciphertext_from_der(ptr noundef %13, ptr noundef %8, ptr noundef %9)
  %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 822, ptr noundef @__FUNCTION__.sdf_decrypt) #4
  br label %58

58:                                               ; preds = %55
  br label %59

59:                                               ; preds = %58
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %89

60:                                               ; preds = %51
  %61 = load i64, ptr %9, align 8, !tbaa !9
  %62 = icmp ne i64 %61, 0
  br i1 %62, label %63, label %69

63:                                               ; preds = %60
  br label %64

64:                                               ; preds = %63
  %65 = load ptr, ptr @stderr, align 8, !tbaa !5
  %66 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %65, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 826, ptr noundef @__FUNCTION__.sdf_decrypt) #4
  br label %67

67:                                               ; preds = %64
  br label %68

68:                                               ; preds = %67
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %89

69:                                               ; preds = %60
  call void @ECCCipher_from_SM2_CIPHERTEXT(ptr noundef %12, ptr noundef %13)
  %70 = load ptr, ptr %7, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.SDF_PRIVATE_KEY, ptr %70, i32 0, i32 0
  %72 = load ptr, ptr %71, align 8, !tbaa !13
  %73 = load ptr, ptr %7, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.SDF_PRIVATE_KEY, ptr %73, i32 0, i32 1
  %75 = load i32, ptr %74, align 8, !tbaa !15
  %76 = load ptr, ptr %10, align 8, !tbaa !5
  %77 = call i32 @SDF_InternalDecrypt_ECC(ptr noundef %72, i32 noundef %75, i32 noundef 133120, ptr noundef %12, ptr noundef %76, ptr noundef %14)
  %78 = icmp ne i32 %77, 0
  br i1 %78, label %79, label %85

79:                                               ; preds = %69
  br label %80

80:                                               ; preds = %79
  %81 = load ptr, ptr @stderr, align 8, !tbaa !5
  %82 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %81, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 833, ptr noundef @__FUNCTION__.sdf_decrypt) #4
  br label %83

83:                                               ; preds = %80
  br label %84

84:                                               ; preds = %83
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %89

85:                                               ; preds = %69
  %86 = load i32, ptr %14, align 4, !tbaa !11
  %87 = zext i32 %86 to i64
  %88 = load ptr, ptr %11, align 8, !tbaa !5
  store i64 %87, ptr %88, align 8, !tbaa !9
  store i32 1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %89

89:                                               ; preds = %85, %84, %68, %59, %49, %45, %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 352, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 419, ptr %12) #4
  %90 = load i32, ptr %6, align 4
  ret i32 %90
}

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


; 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.ECCCipher_st = type <{ [64 x i8], [64 x i8], [32 x i8], i32, [1 x i8], [254 x i8] }>
%struct.SM2_CIPHERTEXT = type { %struct.SM2_POINT, [32 x i8], i8, [255 x i8] }
%struct.SM2_POINT = 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_decrypt = external hidden unnamed_addr constant [12 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_ciphertext_from_der(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden void @ECCCipher_from_SM2_CIPHERTEXT(ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @sdf_decrypt(ptr noundef readonly %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef writeonly %4) local_unnamed_addr #3 {
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca %struct.ECCCipher_st, align 1
  %9 = alloca %struct.SM2_CIPHERTEXT, align 1
  %10 = alloca i32, align 4
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 419, ptr nonnull %8) #4
  call void @llvm.lifetime.start.p0(i64 352, ptr nonnull %9) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %10) #4
  store i32 0, ptr %10, align 4, !tbaa !11
  %11 = icmp ne ptr %0, null
  %12 = icmp ne ptr %1, null
  %or.cond = and i1 %11, %12
  %13 = icmp ne ptr %4, null
  %or.cond3 = and i1 %or.cond, %13
  br i1 %or.cond3, label %17, label %14

14:                                               ; preds = %5
  %15 = load ptr, ptr @stderr, align 8, !tbaa !5
  %16 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %15, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 809, ptr noundef nonnull @__FUNCTION__.sdf_decrypt) #5
  br label %48

17:                                               ; preds = %5
  %18 = load ptr, ptr %0, align 8, !tbaa !13
  %.not = icmp eq ptr %18, null
  br i1 %.not, label %23, label %19

19:                                               ; preds = %17
  %20 = getelementptr inbounds i8, ptr %0, i64 8
  %21 = load i32, ptr %20, align 8, !tbaa !15
  %22 = icmp slt i32 %21, 0
  br i1 %22, label %23, label %26

23:                                               ; preds = %17, %19
  %24 = load ptr, ptr @stderr, align 8, !tbaa !5
  %25 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %24, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 813, ptr noundef nonnull @__FUNCTION__.sdf_decrypt) #5
  br label %48

26:                                               ; preds = %19
  %.not16 = icmp eq ptr %3, null
  br i1 %.not16, label %27, label %28

27:                                               ; preds = %26
  store i64 255, ptr %4, align 8, !tbaa !9
  br label %48

28:                                               ; preds = %26
  %29 = call i32 @sm2_ciphertext_from_der(ptr noundef nonnull %9, ptr noundef nonnull %6, ptr noundef nonnull %7) #4
  %.not17 = icmp eq i32 %29, 1
  br i1 %.not17, label %33, label %30

30:                                               ; preds = %28
  %31 = load ptr, ptr @stderr, align 8, !tbaa !5
  %32 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %31, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 822, ptr noundef nonnull @__FUNCTION__.sdf_decrypt) #5
  br label %48

33:                                               ; preds = %28
  %34 = load i64, ptr %7, align 8, !tbaa !9
  %.not18 = icmp eq i64 %34, 0
  br i1 %.not18, label %38, label %35

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

38:                                               ; preds = %33
  call void @ECCCipher_from_SM2_CIPHERTEXT(ptr noundef nonnull %8, ptr noundef nonnull %9)
  %39 = load ptr, ptr %0, align 8, !tbaa !13
  %40 = load i32, ptr %20, align 8, !tbaa !15
  %41 = call i32 @SDF_InternalDecrypt_ECC(ptr noundef %39, i32 noundef %40, i32 noundef 133120, ptr noundef nonnull %8, ptr noundef nonnull %3, ptr noundef nonnull %10) #4
  %.not19 = icmp eq i32 %41, 0
  br i1 %.not19, label %45, label %42

42:                                               ; preds = %38
  %43 = load ptr, ptr @stderr, align 8, !tbaa !5
  %44 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %43, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 833, ptr noundef nonnull @__FUNCTION__.sdf_decrypt) #5
  br label %48

45:                                               ; preds = %38
  %46 = load i32, ptr %10, align 4, !tbaa !11
  %47 = zext i32 %46 to i64
  store i64 %47, ptr %4, align 8, !tbaa !9
  br label %48

48:                                               ; preds = %45, %42, %35, %30, %27, %23, %14
  %.0 = phi i32 [ -1, %23 ], [ -1, %30 ], [ -1, %35 ], [ -1, %42 ], [ 1, %45 ], [ 1, %27 ], [ -1, %14 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %10) #4
  call void @llvm.lifetime.end.p0(i64 352, ptr nonnull %9) #4
  call void @llvm.lifetime.end.p0(i64 419, ptr nonnull %8) #4
  ret i32 %.0
}

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


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