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

; 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"

@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__.sm2_private_key_info_to_der = external hidden unnamed_addr constant [28 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
declare dso_local i32 @sm2_public_key_algor_to_der(ptr noundef, ptr noundef) #2

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @sm2_private_key_info_to_der(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca [121 x i8], align 16
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  store i64 0, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 121, ptr %9) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %13 = getelementptr inbounds [121 x i8], ptr %9, i64 0, i64 0
  store ptr %13, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  store i64 0, ptr %11, align 8, !tbaa !9
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = call i32 @sm2_private_key_to_der(ptr noundef %14, ptr noundef %10, ptr noundef %11)
  %16 = icmp ne i32 %15, 1
  br i1 %16, label %17, label %23

17:                                               ; preds = %3
  br label %18

18:                                               ; preds = %17
  %19 = load ptr, ptr @stderr, align 8, !tbaa !5
  %20 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %19, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 281, ptr noundef @__FUNCTION__.sm2_private_key_info_to_der) #5
  br label %21

21:                                               ; preds = %18
  br label %22

22:                                               ; preds = %21
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %66

23:                                               ; preds = %3
  %24 = call i32 @asn1_int_to_der_ex(i32 noundef 2, i32 noundef 0, ptr noundef null, ptr noundef %8)
  %25 = icmp ne i32 %24, 1
  br i1 %25, label %57, label %26

26:                                               ; preds = %23
  %27 = call i32 @sm2_public_key_algor_to_der(ptr noundef null, ptr noundef %8)
  %28 = icmp ne i32 %27, 1
  br i1 %28, label %57, label %29

29:                                               ; preds = %26
  %30 = getelementptr inbounds [121 x i8], ptr %9, i64 0, i64 0
  %31 = load i64, ptr %11, align 8, !tbaa !9
  %32 = call i32 @asn1_type_to_der(i32 noundef 4, ptr noundef %30, i64 noundef %31, ptr noundef null, ptr noundef %8)
  %33 = icmp ne i32 %32, 1
  br i1 %33, label %57, label %34

34:                                               ; preds = %29
  %35 = load i64, ptr %8, align 8, !tbaa !9
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = call i32 @asn1_header_to_der(i32 noundef 48, i64 noundef %35, ptr noundef %36, ptr noundef %37)
  %39 = icmp ne i32 %38, 1
  br i1 %39, label %57, label %40

40:                                               ; preds = %34
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = call i32 @asn1_int_to_der_ex(i32 noundef 2, i32 noundef 0, ptr noundef %41, ptr noundef %42)
  %44 = icmp ne i32 %43, 1
  br i1 %44, label %57, label %45

45:                                               ; preds = %40
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = call i32 @sm2_public_key_algor_to_der(ptr noundef %46, ptr noundef %47)
  %49 = icmp ne i32 %48, 1
  br i1 %49, label %57, label %50

50:                                               ; preds = %45
  %51 = getelementptr inbounds [121 x i8], ptr %9, i64 0, i64 0
  %52 = load i64, ptr %11, align 8, !tbaa !9
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = call i32 @asn1_type_to_der(i32 noundef 4, ptr noundef %51, i64 noundef %52, ptr noundef %53, ptr noundef %54)
  %56 = icmp ne i32 %55, 1
  br i1 %56, label %57, label %64

57:                                               ; preds = %50, %45, %40, %34, %29, %26, %23
  %58 = getelementptr inbounds [121 x i8], ptr %9, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 16 %58, i8 0, i64 121, i1 false)
  br label %59

59:                                               ; preds = %57
  %60 = load ptr, ptr @stderr, align 8, !tbaa !5
  %61 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %60, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 292, ptr noundef @__FUNCTION__.sm2_private_key_info_to_der) #5
  br label %62

62:                                               ; preds = %59
  br label %63

63:                                               ; preds = %62
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %66

64:                                               ; preds = %50
  %65 = getelementptr inbounds [121 x i8], ptr %9, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 16 %65, i8 0, i64 121, i1 false)
  store i32 1, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %66

66:                                               ; preds = %64, %63, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 121, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  %67 = load i32, ptr %4, align 4
  ret i32 %67
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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}


; 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"

@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__.sm2_private_key_info_to_der = external hidden unnamed_addr constant [28 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
declare dso_local i32 @sm2_public_key_algor_to_der(ptr noundef, ptr noundef) local_unnamed_addr #2

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @sm2_private_key_info_to_der(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #2 {
  %4 = alloca i64, align 8
  %5 = alloca [121 x i8], align 16
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #5
  store i64 0, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 121, ptr nonnull %5) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #5
  store ptr %5, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #5
  store i64 0, ptr %7, align 8, !tbaa !5
  %8 = call i32 @sm2_private_key_to_der(ptr noundef %0, ptr noundef nonnull %6, ptr noundef nonnull %7)
  %.not = icmp eq i32 %8, 1
  br i1 %.not, label %9, label %.sink.split

9:                                                ; preds = %3
  %10 = call i32 @asn1_int_to_der_ex(i32 noundef 2, i32 noundef 0, ptr noundef null, ptr noundef nonnull %4) #5
  %.not9 = icmp eq i32 %10, 1
  br i1 %.not9, label %11, label %26

11:                                               ; preds = %9
  %12 = call i32 @sm2_public_key_algor_to_der(ptr noundef null, ptr noundef nonnull %4)
  %.not10 = icmp eq i32 %12, 1
  br i1 %.not10, label %13, label %26

13:                                               ; preds = %11
  %14 = load i64, ptr %7, align 8, !tbaa !5
  %15 = call i32 @asn1_type_to_der(i32 noundef 4, ptr noundef nonnull %5, i64 noundef %14, ptr noundef null, ptr noundef nonnull %4) #5
  %.not11 = icmp eq i32 %15, 1
  br i1 %.not11, label %16, label %26

16:                                               ; preds = %13
  %17 = load i64, ptr %4, align 8, !tbaa !5
  %18 = call i32 @asn1_header_to_der(i32 noundef 48, i64 noundef %17, ptr noundef %1, ptr noundef %2) #5
  %.not12 = icmp eq i32 %18, 1
  br i1 %.not12, label %19, label %26

19:                                               ; preds = %16
  %20 = call i32 @asn1_int_to_der_ex(i32 noundef 2, i32 noundef 0, ptr noundef %1, ptr noundef %2) #5
  %.not13 = icmp eq i32 %20, 1
  br i1 %.not13, label %21, label %26

21:                                               ; preds = %19
  %22 = call i32 @sm2_public_key_algor_to_der(ptr noundef %1, ptr noundef %2)
  %.not14 = icmp eq i32 %22, 1
  br i1 %.not14, label %23, label %26

23:                                               ; preds = %21
  %24 = load i64, ptr %7, align 8, !tbaa !5
  %25 = call i32 @asn1_type_to_der(i32 noundef 4, ptr noundef nonnull %5, i64 noundef %24, ptr noundef %1, ptr noundef %2) #5
  %.not15 = icmp eq i32 %25, 1
  br i1 %.not15, label %29, label %26

26:                                               ; preds = %23, %21, %19, %16, %13, %11, %9
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(121) %5, i8 0, i64 121, i1 false)
  br label %.sink.split

.sink.split:                                      ; preds = %3, %26
  %.sink16 = phi i32 [ 292, %26 ], [ 281, %3 ]
  %27 = load ptr, ptr @stderr, align 8, !tbaa !9
  %28 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %27, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef %.sink16, ptr noundef nonnull @__FUNCTION__.sm2_private_key_info_to_der) #6
  br label %29

29:                                               ; preds = %.sink.split, %23
  %.0 = phi i32 [ 1, %23 ], [ -1, %.sink.split ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #5
  call void @llvm.lifetime.end.p0(i64 121, ptr nonnull %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #5
  ret i32 %.0
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}


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