; 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_MASTER_KEY = type { %struct.SM9_Z256_POINT, [4 x i64] }
%struct.SM9_Z256_POINT = type { [4 x i64], [4 x i64], [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_master_key_from_der = external hidden unnamed_addr constant [28 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_integer_from_der_ex(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 void @sm9_z256_from_bytes(ptr noundef, ptr noundef) #2

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

declare ptr @sm9_z256_order() #2

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

; Function Attrs: nounwind uwtable
define dso_local i32 @sm9_enc_master_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 236, ptr noundef @__FUNCTION__.sm9_enc_master_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 %90

31:                                               ; preds = %3
  %32 = call i32 @asn1_integer_from_der_ex(i32 noundef 2, 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, 32
  %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 244, ptr noundef @__FUNCTION__.sm9_enc_master_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 %90

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 128, i1 false)
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.SM9_ENC_MASTER_KEY, ptr %61, i32 0, i32 1
  %63 = getelementptr inbounds [4 x i64], ptr %62, i64 0, i64 0
  %64 = load ptr, ptr %11, align 8, !tbaa !5
  call void @sm9_z256_from_bytes(ptr noundef %63, ptr noundef %64)
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.SM9_ENC_MASTER_KEY, ptr %65, i32 0, i32 1
  %67 = getelementptr inbounds [4 x i64], ptr %66, i64 0, i64 0
  %68 = call ptr @sm9_z256_order()
  %69 = call i32 @sm9_z256_cmp(ptr noundef %67, ptr noundef %68)
  %70 = icmp sge i32 %69, 0
  br i1 %70, label %71, label %77

71:                                               ; preds = %59
  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 251, ptr noundef @__FUNCTION__.sm9_enc_master_key_from_der) #5
  br label %75

75:                                               ; preds = %72
  br label %76

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

77:                                               ; preds = %59
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.SM9_ENC_MASTER_KEY, ptr %78, i32 0, i32 0
  %80 = load ptr, ptr %13, align 8, !tbaa !5
  %81 = call i32 @sm9_z256_point_from_uncompressed_octets(ptr noundef %79, ptr noundef %80)
  %82 = icmp ne i32 %81, 1
  br i1 %82, label %83, label %89

83:                                               ; preds = %77
  br label %84

84:                                               ; preds = %83
  %85 = load ptr, ptr @stderr, align 8, !tbaa !5
  %86 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %85, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 255, ptr noundef @__FUNCTION__.sm9_enc_master_key_from_der) #5
  br label %87

87:                                               ; preds = %84
  br label %88

88:                                               ; preds = %87
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %15, align 4
  br label %90

89:                                               ; preds = %77
  store i32 1, ptr %4, align 4
  store i32 1, ptr %15, align 4
  br label %90

90:                                               ; preds = %89, %88, %76, %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
  %91 = load i32, ptr %4, align 4
  ret i32 %91
}

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_master_key_from_der = external hidden unnamed_addr constant [28 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_integer_from_der_ex(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 void @sm9_z256_from_bytes(ptr noundef, ptr noundef) local_unnamed_addr #2

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

declare ptr @sm9_z256_order() 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_master_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 %41

13:                                               ; preds = %3
  %14 = call i32 @asn1_integer_from_der_ex(i32 noundef 2, ptr noundef nonnull %6, ptr noundef nonnull %7, ptr noundef nonnull %4, ptr noundef nonnull %5) #5
  %.not9 = icmp eq i32 %14, 1
  br i1 %.not9, 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
  %.not10 = icmp eq i32 %16, 1
  br i1 %.not10, label %17, label %.sink.split

17:                                               ; preds = %15
  %18 = load i64, ptr %7, align 8, !tbaa !5
  %19 = icmp eq i64 %18, 32
  %20 = zext i1 %19 to i32
  %21 = call i32 @asn1_check(i32 noundef %20) #5
  %.not11 = icmp eq i32 %21, 1
  br i1 %.not11, 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
  %.not12 = icmp eq i32 %26, 1
  br i1 %.not12, 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
  %.not13 = icmp eq i32 %29, 1
  br i1 %.not13, label %30, label %.sink.split

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

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

.sink.split:                                      ; preds = %36, %30, %27, %22, %17, %15, %13, %11
  %.sink15 = phi i32 [ 236, %11 ], [ 244, %13 ], [ 244, %15 ], [ 244, %17 ], [ 244, %22 ], [ 244, %27 ], [ 251, %30 ], [ 255, %36 ]
  %.0.ph = phi i32 [ %10, %11 ], [ -1, %13 ], [ -1, %15 ], [ -1, %17 ], [ -1, %22 ], [ -1, %27 ], [ -1, %30 ], [ -1, %36 ]
  %39 = load ptr, ptr @stderr, align 8, !tbaa !9
  %40 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %39, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef %.sink15, ptr noundef nonnull @__FUNCTION__.sm9_enc_master_key_from_der) #6
  br label %41

41:                                               ; preds = %.sink.split, %36, %11
  %.0 = phi i32 [ %10, %11 ], [ 1, %36 ], [ %.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