; LLVM IR from guanzhi/GmSSL :: src (sm9_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"

%struct.SM9_ENC_KEY = type { %struct.SM9_Z256_POINT, %struct.SM9_Z256_TWIST_POINT }
%struct.SM9_Z256_POINT = type { [4 x i64], [4 x i64], [4 x i64] }
%struct.SM9_Z256_TWIST_POINT = type { [2 x [4 x i64]], [2 x [4 x i64]], [2 x [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 [61 x i8], align 1
@__FUNCTION__.sm9_enc_key_from_der = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

declare i32 @asn1_type_from_der(i32 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

declare i32 @asn1_bit_octets_from_der_ex(i32 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

declare i32 @asn1_check(i32 noundef) #2

declare i32 @asn1_length_is_zero(i64 noundef) #2

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

declare i32 @sm9_z256_twist_point_from_uncompressed_octets(ptr noundef, ptr noundef) #2

declare i32 @sm9_z256_point_from_uncompressed_octets(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @sm9_enc_key_from_der(ptr noundef %0, ptr noundef %1, ptr noundef %2) #4 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = 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 4, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = call i32 @asn1_type_from_der(i32 noundef 48, ptr noundef %9, ptr noundef %10, ptr noundef %16, ptr noundef %17)
  store i32 %18, ptr %8, align 4, !tbaa !9
  %19 = icmp ne i32 %18, 1
  br i1 %19, label %20, label %31

20:                                               ; preds = %3
  %21 = load i32, ptr %8, align 4, !tbaa !9
  %22 = icmp slt i32 %21, 0
  br i1 %22, label %23, label %29

23:                                               ; preds = %20
  br label %24

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

27:                                               ; preds = %24
  br label %28

28:                                               ; preds = %27
  br label %29

29:                                               ; preds = %28, %20
  %30 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %30, ptr %4, align 4
  store i32 1, ptr %15, align 4
  br label %79

31:                                               ; preds = %3
  %32 = call i32 @asn1_bit_octets_from_der_ex(i32 noundef 3, ptr noundef %11, ptr noundef %12, ptr noundef %9, ptr noundef %10)
  %33 = icmp ne i32 %32, 1
  br i1 %33, label %53, label %34

34:                                               ; preds = %31
  %35 = call i32 @asn1_bit_octets_from_der_ex(i32 noundef 3, ptr noundef %13, ptr noundef %14, ptr noundef %9, ptr noundef %10)
  %36 = icmp ne i32 %35, 1
  br i1 %36, label %53, label %37

37:                                               ; preds = %34
  %38 = load i64, ptr %12, align 8, !tbaa !11
  %39 = icmp eq i64 %38, 129
  %40 = zext i1 %39 to i32
  %41 = call i32 @asn1_check(i32 noundef %40)
  %42 = icmp ne i32 %41, 1
  br i1 %42, label %53, label %43

43:                                               ; preds = %37
  %44 = load i64, ptr %14, align 8, !tbaa !11
  %45 = icmp eq i64 %44, 65
  %46 = zext i1 %45 to i32
  %47 = call i32 @asn1_check(i32 noundef %46)
  %48 = icmp ne i32 %47, 1
  br i1 %48, label %53, label %49

49:                                               ; preds = %43
  %50 = load i64, ptr %10, align 8, !tbaa !11
  %51 = call i32 @asn1_length_is_zero(i64 noundef %50)
  %52 = icmp ne i32 %51, 1
  br i1 %52, label %53, label %59

53:                                               ; preds = %49, %43, %37, %34, %31
  br label %54

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

57:                                               ; preds = %54
  br label %58

58:                                               ; preds = %57
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %15, align 4
  br label %79

59:                                               ; preds = %49
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 8 %60, i8 0, i64 288, i1 false)
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.SM9_ENC_KEY, ptr %61, i32 0, i32 1
  %63 = load ptr, ptr %11, align 8, !tbaa !5
  %64 = call i32 @sm9_z256_twist_point_from_uncompressed_octets(ptr noundef %62, ptr noundef %63)
  %65 = icmp ne i32 %64, 1
  br i1 %65, label %72, label %66

66:                                               ; preds = %59
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.SM9_ENC_KEY, ptr %67, i32 0, i32 0
  %69 = load ptr, ptr %13, align 8, !tbaa !5
  %70 = call i32 @sm9_z256_point_from_uncompressed_octets(ptr noundef %68, ptr noundef %69)
  %71 = icmp ne i32 %70, 1
  br i1 %71, label %72, label %78

72:                                               ; preds = %66, %59
  br label %73

73:                                               ; preds = %72
  %74 = load ptr, ptr @stderr, align 8, !tbaa !5
  %75 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %74, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 350, ptr noundef @__FUNCTION__.sm9_enc_key_from_der) #5
  br label %76

76:                                               ; preds = %73
  br label %77

77:                                               ; preds = %76
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %15, align 4
  br label %79

78:                                               ; preds = %66
  store i32 1, ptr %4, align 4
  store i32 1, ptr %15, align 4
  br label %79

79:                                               ; preds = %78, %77, %58, %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  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 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  %80 = load i32, ptr %4, align 4
  ret i32 %80
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"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__.sm9_enc_key_from_der = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #1

declare i32 @asn1_type_from_der(i32 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @asn1_bit_octets_from_der_ex(i32 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @asn1_check(i32 noundef) local_unnamed_addr #2

declare i32 @asn1_length_is_zero(i64 noundef) local_unnamed_addr #2

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

declare i32 @sm9_z256_twist_point_from_uncompressed_octets(ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @sm9_z256_point_from_uncompressed_octets(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local i32 @sm9_enc_key_from_der(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #4 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %8) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %9) #5
  %10 = call i32 @asn1_type_from_der(i32 noundef 48, ptr noundef nonnull %4, ptr noundef nonnull %5, ptr noundef %1, ptr noundef %2) #5
  %.not = icmp eq i32 %10, 1
  br i1 %.not, label %13, label %11

11:                                               ; preds = %3
  %12 = icmp slt i32 %10, 0
  br i1 %12, label %.sink.split, label %39

13:                                               ; preds = %3
  %14 = call i32 @asn1_bit_octets_from_der_ex(i32 noundef 3, ptr noundef nonnull %6, ptr noundef nonnull %7, ptr noundef nonnull %4, ptr noundef nonnull %5) #5
  %.not8 = icmp eq i32 %14, 1
  br i1 %.not8, label %15, label %.sink.split

15:                                               ; preds = %13
  %16 = call i32 @asn1_bit_octets_from_der_ex(i32 noundef 3, ptr noundef nonnull %8, ptr noundef nonnull %9, ptr noundef nonnull %4, ptr noundef nonnull %5) #5
  %.not9 = icmp eq i32 %16, 1
  br i1 %.not9, label %17, label %.sink.split

17:                                               ; preds = %15
  %18 = load i64, ptr %7, align 8, !tbaa !5
  %19 = icmp eq i64 %18, 129
  %20 = zext i1 %19 to i32
  %21 = call i32 @asn1_check(i32 noundef %20) #5
  %.not10 = icmp eq i32 %21, 1
  br i1 %.not10, label %22, label %.sink.split

22:                                               ; preds = %17
  %23 = load i64, ptr %9, align 8, !tbaa !5
  %24 = icmp eq i64 %23, 65
  %25 = zext i1 %24 to i32
  %26 = call i32 @asn1_check(i32 noundef %25) #5
  %.not11 = icmp eq i32 %26, 1
  br i1 %.not11, label %27, label %.sink.split

27:                                               ; preds = %22
  %28 = load i64, ptr %5, align 8, !tbaa !5
  %29 = call i32 @asn1_length_is_zero(i64 noundef %28) #5
  %.not12 = icmp eq i32 %29, 1
  br i1 %.not12, label %30, label %.sink.split

30:                                               ; preds = %27
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(288) %0, i8 0, i64 288, i1 false)
  %31 = getelementptr inbounds i8, ptr %0, i64 96
  %32 = load ptr, ptr %6, align 8, !tbaa !9
  %33 = call i32 @sm9_z256_twist_point_from_uncompressed_octets(ptr noundef nonnull %31, ptr noundef %32) #5
  %.not13 = icmp eq i32 %33, 1
  br i1 %.not13, label %34, label %.sink.split

34:                                               ; preds = %30
  %35 = load ptr, ptr %8, align 8, !tbaa !9
  %36 = call i32 @sm9_z256_point_from_uncompressed_octets(ptr noundef nonnull %0, ptr noundef %35) #5
  %.not14 = icmp eq i32 %36, 1
  br i1 %.not14, label %39, label %.sink.split

.sink.split:                                      ; preds = %34, %30, %27, %22, %17, %15, %13, %11
  %.sink15 = phi i32 [ 336, %11 ], [ 344, %13 ], [ 344, %15 ], [ 344, %17 ], [ 344, %22 ], [ 344, %27 ], [ 350, %30 ], [ 350, %34 ]
  %.0.ph = phi i32 [ %10, %11 ], [ -1, %13 ], [ -1, %15 ], [ -1, %17 ], [ -1, %22 ], [ -1, %27 ], [ -1, %30 ], [ -1, %34 ]
  %37 = load ptr, ptr @stderr, align 8, !tbaa !9
  %38 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %37, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef %.sink15, ptr noundef nonnull @__FUNCTION__.sm9_enc_key_from_der) #6
  br label %39

39:                                               ; preds = %.sink.split, %34, %11
  %.0 = phi i32 [ %10, %11 ], [ 1, %34 ], [ %.0.ph, %.sink.split ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #5
  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 8, ptr nonnull %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #5
  ret i32 %.0
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"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: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass