; LLVM IR from guanzhi/GmSSL :: tools (sm2keygen)

; 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.SM2_KEY = type { %struct.SM2_Z256_POINT, [4 x i64] }
%struct.SM2_Z256_POINT = type { [4 x i64], [4 x i64], [4 x i64] }

@stdout = external global ptr, align 8
@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [20 x i8], align 1
@usage = external hidden global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@options = external hidden global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [25 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @sm2keygen_main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca %struct.SM2_KEY, align 8
  %14 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  store i32 1, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  %15 = load ptr, ptr %5, align 8, !tbaa !9
  %16 = getelementptr inbounds ptr, ptr %15, i64 0
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  store ptr %17, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  store ptr null, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  store ptr null, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  store ptr null, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #6
  %18 = load ptr, ptr @stdout, align 8, !tbaa !9
  store ptr %18, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #6
  %19 = load ptr, ptr @stdout, align 8, !tbaa !9
  store ptr %19, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 128, ptr %13) #6
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = add nsw i32 %20, -1
  store i32 %21, ptr %4, align 4, !tbaa !5
  %22 = load ptr, ptr %5, align 8, !tbaa !9
  %23 = getelementptr inbounds ptr, ptr %22, i32 1
  store ptr %23, ptr %5, align 8, !tbaa !9
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = icmp slt i32 %24, 1
  br i1 %25, label %26, label %31

26:                                               ; preds = %2
  %27 = load ptr, ptr @stderr, align 8, !tbaa !9
  %28 = load ptr, ptr %7, align 8, !tbaa !9
  %29 = load ptr, ptr @usage, align 8, !tbaa !9
  %30 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %27, ptr noundef @.str, ptr noundef %28, ptr noundef %29) #6
  store i32 1, ptr %3, align 4
  store i32 1, ptr %14, align 4
  br label %176

31:                                               ; preds = %2
  br label %32

32:                                               ; preds = %127, %31
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = icmp sgt i32 %33, 0
  br i1 %34, label %35, label %132

35:                                               ; preds = %32
  %36 = load ptr, ptr %5, align 8, !tbaa !9
  %37 = load ptr, ptr %36, align 8, !tbaa !9
  %38 = call i32 @strcmp(ptr noundef %37, ptr noundef @.str.1) #7
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %46, label %40

40:                                               ; preds = %35
  %41 = load ptr, ptr %7, align 8, !tbaa !9
  %42 = load ptr, ptr @usage, align 8, !tbaa !9
  %43 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef %41, ptr noundef %42)
  %44 = load ptr, ptr @options, align 8, !tbaa !9
  %45 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, ptr noundef %44)
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %156

46:                                               ; preds = %35
  %47 = load ptr, ptr %5, align 8, !tbaa !9
  %48 = load ptr, ptr %47, align 8, !tbaa !9
  %49 = call i32 @strcmp(ptr noundef %48, ptr noundef @.str.3) #7
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %60, label %51

51:                                               ; preds = %46
  %52 = load i32, ptr %4, align 4, !tbaa !5
  %53 = add nsw i32 %52, -1
  store i32 %53, ptr %4, align 4, !tbaa !5
  %54 = icmp slt i32 %53, 1
  br i1 %54, label %55, label %56

55:                                               ; preds = %51
  br label %118

56:                                               ; preds = %51
  %57 = load ptr, ptr %5, align 8, !tbaa !9
  %58 = getelementptr inbounds ptr, ptr %57, i32 1
  store ptr %58, ptr %5, align 8, !tbaa !9
  %59 = load ptr, ptr %58, align 8, !tbaa !9
  store ptr %59, ptr %8, align 8, !tbaa !9
  br label %126

60:                                               ; preds = %46
  %61 = load ptr, ptr %5, align 8, !tbaa !9
  %62 = load ptr, ptr %61, align 8, !tbaa !9
  %63 = call i32 @strcmp(ptr noundef %62, ptr noundef @.str.4) #7
  %64 = icmp ne i32 %63, 0
  br i1 %64, label %86, label %65

65:                                               ; preds = %60
  %66 = load i32, ptr %4, align 4, !tbaa !5
  %67 = add nsw i32 %66, -1
  store i32 %67, ptr %4, align 4, !tbaa !5
  %68 = icmp slt i32 %67, 1
  br i1 %68, label %69, label %70

69:                                               ; preds = %65
  br label %118

70:                                               ; preds = %65
  %71 = load ptr, ptr %5, align 8, !tbaa !9
  %72 = getelementptr inbounds ptr, ptr %71, i32 1
  store ptr %72, ptr %5, align 8, !tbaa !9
  %73 = load ptr, ptr %72, align 8, !tbaa !9
  store ptr %73, ptr %9, align 8, !tbaa !9
  %74 = load ptr, ptr %9, align 8, !tbaa !9
  %75 = call noalias ptr @fopen(ptr noundef %74, ptr noundef @.str.5)
  store ptr %75, ptr %11, align 8, !tbaa !9
  %76 = icmp ne ptr %75, null
  br i1 %76, label %85, label %77

77:                                               ; preds = %70
  %78 = load ptr, ptr @stderr, align 8, !tbaa !9
  %79 = load ptr, ptr %7, align 8, !tbaa !9
  %80 = load ptr, ptr %9, align 8, !tbaa !9
  %81 = call ptr @__errno_location() #8
  %82 = load i32, ptr %81, align 4, !tbaa !5
  %83 = call ptr @strerror(i32 noundef %82) #6
  %84 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %78, ptr noundef @.str.6, ptr noundef %79, ptr noundef %80, ptr noundef %83) #6
  br label %156

85:                                               ; preds = %70
  br label %125

86:                                               ; preds = %60
  %87 = load ptr, ptr %5, align 8, !tbaa !9
  %88 = load ptr, ptr %87, align 8, !tbaa !9
  %89 = call i32 @strcmp(ptr noundef %88, ptr noundef @.str.7) #7
  %90 = icmp ne i32 %89, 0
  br i1 %90, label %112, label %91

91:                                               ; preds = %86
  %92 = load i32, ptr %4, align 4, !tbaa !5
  %93 = add nsw i32 %92, -1
  store i32 %93, ptr %4, align 4, !tbaa !5
  %94 = icmp slt i32 %93, 1
  br i1 %94, label %95, label %96

95:                                               ; preds = %91
  br label %118

96:                                               ; preds = %91
  %97 = load ptr, ptr %5, align 8, !tbaa !9
  %98 = getelementptr inbounds ptr, ptr %97, i32 1
  store ptr %98, ptr %5, align 8, !tbaa !9
  %99 = load ptr, ptr %98, align 8, !tbaa !9
  store ptr %99, ptr %10, align 8, !tbaa !9
  %100 = load ptr, ptr %10, align 8, !tbaa !9
  %101 = call noalias ptr @fopen(ptr noundef %100, ptr noundef @.str.5)
  store ptr %101, ptr %12, align 8, !tbaa !9
  %102 = icmp ne ptr %101, null
  br i1 %102, label %111, label %103

103:                                              ; preds = %96
  %104 = load ptr, ptr @stderr, align 8, !tbaa !9
  %105 = load ptr, ptr %7, align 8, !tbaa !9
  %106 = load ptr, ptr %9, align 8, !tbaa !9
  %107 = call ptr @__errno_location() #8
  %108 = load i32, ptr %107, align 4, !tbaa !5
  %109 = call ptr @strerror(i32 noundef %108) #6
  %110 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %104, ptr noundef @.str.6, ptr noundef %105, ptr noundef %106, ptr noundef %109) #6
  br label %156

111:                                              ; preds = %96
  br label %124

112:                                              ; preds = %86
  %113 = load ptr, ptr @stderr, align 8, !tbaa !9
  %114 = load ptr, ptr %7, align 8, !tbaa !9
  %115 = load ptr, ptr %5, align 8, !tbaa !9
  %116 = load ptr, ptr %115, align 8, !tbaa !9
  %117 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %113, ptr noundef @.str.8, ptr noundef %114, ptr noundef %116) #6
  br label %156

118:                                              ; preds = %95, %69, %55
  %119 = load ptr, ptr @stderr, align 8, !tbaa !9
  %120 = load ptr, ptr %7, align 8, !tbaa !9
  %121 = load ptr, ptr %5, align 8, !tbaa !9
  %122 = load ptr, ptr %121, align 8, !tbaa !9
  %123 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %119, ptr noundef @.str.9, ptr noundef %120, ptr noundef %122) #6
  br label %156

124:                                              ; preds = %111
  br label %125

125:                                              ; preds = %124, %85
  br label %126

126:                                              ; preds = %125, %56
  br label %127

127:                                              ; preds = %126
  %128 = load i32, ptr %4, align 4, !tbaa !5
  %129 = add nsw i32 %128, -1
  store i32 %129, ptr %4, align 4, !tbaa !5
  %130 = load ptr, ptr %5, align 8, !tbaa !9
  %131 = getelementptr inbounds ptr, ptr %130, i32 1
  store ptr %131, ptr %5, align 8, !tbaa !9
  br label %32, !llvm.loop !11

132:                                              ; preds = %32
  %133 = load ptr, ptr %8, align 8, !tbaa !9
  %134 = icmp ne ptr %133, null
  br i1 %134, label %139, label %135

135:                                              ; preds = %132
  %136 = load ptr, ptr @stderr, align 8, !tbaa !9
  %137 = load ptr, ptr %7, align 8, !tbaa !9
  %138 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %136, ptr noundef @.str.10, ptr noundef %137) #6
  br label %156

139:                                              ; preds = %132
  %140 = call i32 @sm2_key_generate(ptr noundef %13)
  %141 = icmp ne i32 %140, 1
  br i1 %141, label %151, label %142

142:                                              ; preds = %139
  %143 = load ptr, ptr %8, align 8, !tbaa !9
  %144 = load ptr, ptr %11, align 8, !tbaa !9
  %145 = call i32 @sm2_private_key_info_encrypt_to_pem(ptr noundef %13, ptr noundef %143, ptr noundef %144)
  %146 = icmp ne i32 %145, 1
  br i1 %146, label %151, label %147

147:                                              ; preds = %142
  %148 = load ptr, ptr %12, align 8, !tbaa !9
  %149 = call i32 @sm2_public_key_info_to_pem(ptr noundef %13, ptr noundef %148)
  %150 = icmp ne i32 %149, 1
  br i1 %150, label %151, label %155

151:                                              ; preds = %147, %142, %139
  %152 = load ptr, ptr @stderr, align 8, !tbaa !9
  %153 = load ptr, ptr %7, align 8, !tbaa !9
  %154 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %152, ptr noundef @.str.11, ptr noundef %153) #6
  br label %156

155:                                              ; preds = %147
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %156

156:                                              ; preds = %155, %151, %135, %118, %112, %103, %77, %40
  call void @gmssl_secure_clear(ptr noundef %13, i64 noundef 128)
  %157 = load ptr, ptr %9, align 8, !tbaa !9
  %158 = icmp ne ptr %157, null
  br i1 %158, label %159, label %165

159:                                              ; preds = %156
  %160 = load ptr, ptr %11, align 8, !tbaa !9
  %161 = icmp ne ptr %160, null
  br i1 %161, label %162, label %165

162:                                              ; preds = %159
  %163 = load ptr, ptr %11, align 8, !tbaa !9
  %164 = call i32 @fclose(ptr noundef %163)
  br label %165

165:                                              ; preds = %162, %159, %156
  %166 = load ptr, ptr %10, align 8, !tbaa !9
  %167 = icmp ne ptr %166, null
  br i1 %167, label %168, label %174

168:                                              ; preds = %165
  %169 = load ptr, ptr %12, align 8, !tbaa !9
  %170 = icmp ne ptr %169, null
  br i1 %170, label %171, label %174

171:                                              ; preds = %168
  %172 = load ptr, ptr %12, align 8, !tbaa !9
  %173 = call i32 @fclose(ptr noundef %172)
  br label %174

174:                                              ; preds = %171, %168, %165
  %175 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %175, ptr %3, align 4
  store i32 1, ptr %14, align 4
  br label %176

176:                                              ; preds = %174, %26
  call void @llvm.lifetime.end.p0(i64 128, ptr %13) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  %177 = load i32, ptr %3, align 4
  ret i32 %177
}

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

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

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #3

declare i32 @printf(ptr noundef, ...) #4

declare noalias ptr @fopen(ptr noundef, ptr noundef) #4

; Function Attrs: nounwind
declare ptr @strerror(i32 noundef) #2

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #5

declare i32 @sm2_key_generate(ptr noundef) #4

declare i32 @sm2_private_key_info_encrypt_to_pem(ptr noundef, ptr noundef, ptr noundef) #4

declare i32 @sm2_public_key_info_to_pem(ptr noundef, ptr noundef) #4

declare void @gmssl_secure_clear(ptr noundef, i64 noundef) #4

declare i32 @fclose(ptr noundef) #4

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { nounwind willreturn memory(read) "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 = { "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 willreturn memory(none) "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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }
attributes #8 = { nounwind willreturn memory(none) }

!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 = !{!"int", !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}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; 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.SM2_KEY = type { %struct.SM2_Z256_POINT, [4 x i64] }
%struct.SM2_Z256_POINT = type { [4 x i64], [4 x i64], [4 x i64] }

@stdout = external local_unnamed_addr global ptr, align 8
@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [20 x i8], align 1
@usage = external hidden local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@options = external hidden local_unnamed_addr global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [25 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @sm2keygen_main(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = alloca %struct.SM2_KEY, align 8
  %4 = load ptr, ptr %1, align 8, !tbaa !5
  %5 = load ptr, ptr @stdout, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %3) #7
  %6 = icmp slt i32 %0, 2
  br i1 %6, label %8, label %.preheader.preheader

.preheader.preheader:                             ; preds = %2
  %7 = getelementptr inbounds i8, ptr %1, i64 8
  br label %.preheader

8:                                                ; preds = %2
  %9 = load ptr, ptr @stderr, align 8, !tbaa !5
  %10 = load ptr, ptr @usage, align 8, !tbaa !5
  %11 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %9, ptr noundef nonnull @.str, ptr noundef %4, ptr noundef %10) #8
  br label %86

.preheader:                                       ; preds = %.preheader.preheader, %60
  %.0116 = phi ptr [ %.1, %60 ], [ %5, %.preheader.preheader ]
  %.045115 = phi ptr [ %.146, %60 ], [ %5, %.preheader.preheader ]
  %.048114 = phi ptr [ %.149, %60 ], [ null, %.preheader.preheader ]
  %.051113 = phi ptr [ %.152, %60 ], [ null, %.preheader.preheader ]
  %.054112 = phi ptr [ %.155, %60 ], [ null, %.preheader.preheader ]
  %.058111 = phi ptr [ %61, %60 ], [ %7, %.preheader.preheader ]
  %.060.in110 = phi i32 [ %.161, %60 ], [ %0, %.preheader.preheader ]
  %12 = load ptr, ptr %.058111, align 8, !tbaa !5
  %13 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %12, ptr noundef nonnull dereferenceable(1) @.str.1) #9
  %.not73 = icmp eq i32 %13, 0
  br i1 %.not73, label %14, label %19

14:                                               ; preds = %.preheader
  %15 = load ptr, ptr @usage, align 8, !tbaa !5
  %16 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef %4, ptr noundef %15)
  %17 = load ptr, ptr @options, align 8, !tbaa !5
  %18 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, ptr noundef %17)
  br label %76

19:                                               ; preds = %.preheader
  %20 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %12, ptr noundef nonnull dereferenceable(1) @.str.3) #9
  %.not74 = icmp eq i32 %20, 0
  br i1 %.not74, label %21, label %26

21:                                               ; preds = %19
  %22 = icmp eq i32 %.060.in110, 2
  br i1 %22, label %57, label %23

23:                                               ; preds = %21
  %24 = getelementptr inbounds i8, ptr %.058111, i64 8
  %25 = load ptr, ptr %24, align 8, !tbaa !5
  br label %60

26:                                               ; preds = %19
  %27 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %12, ptr noundef nonnull dereferenceable(1) @.str.4) #9
  %.not75 = icmp eq i32 %27, 0
  br i1 %.not75, label %28, label %40

28:                                               ; preds = %26
  %29 = icmp eq i32 %.060.in110, 2
  br i1 %29, label %57, label %30

30:                                               ; preds = %28
  %31 = getelementptr inbounds i8, ptr %.058111, i64 8
  %32 = load ptr, ptr %31, align 8, !tbaa !5
  %33 = tail call noalias ptr @fopen(ptr noundef %32, ptr noundef nonnull @.str.5)
  %.not76 = icmp eq ptr %33, null
  br i1 %.not76, label %34, label %60

34:                                               ; preds = %30
  %35 = load ptr, ptr @stderr, align 8, !tbaa !5
  %36 = tail call ptr @__errno_location() #10
  %37 = load i32, ptr %36, align 4, !tbaa !9
  %38 = tail call ptr @strerror(i32 noundef %37) #7
  %39 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %35, ptr noundef nonnull @.str.6, ptr noundef %4, ptr noundef %32, ptr noundef %38) #8
  br label %76

40:                                               ; preds = %26
  %41 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %12, ptr noundef nonnull dereferenceable(1) @.str.7) #9
  %.not77 = icmp eq i32 %41, 0
  br i1 %.not77, label %42, label %54

42:                                               ; preds = %40
  %43 = icmp eq i32 %.060.in110, 2
  br i1 %43, label %57, label %44

44:                                               ; preds = %42
  %45 = getelementptr inbounds i8, ptr %.058111, i64 8
  %46 = load ptr, ptr %45, align 8, !tbaa !5
  %47 = tail call noalias ptr @fopen(ptr noundef %46, ptr noundef nonnull @.str.5)
  %.not78 = icmp eq ptr %47, null
  br i1 %.not78, label %48, label %60

48:                                               ; preds = %44
  %49 = load ptr, ptr @stderr, align 8, !tbaa !5
  %50 = tail call ptr @__errno_location() #10
  %51 = load i32, ptr %50, align 4, !tbaa !9
  %52 = tail call ptr @strerror(i32 noundef %51) #7
  %53 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %49, ptr noundef nonnull @.str.6, ptr noundef %4, ptr noundef %.051113, ptr noundef %52) #8
  br label %76

54:                                               ; preds = %40
  %55 = load ptr, ptr @stderr, align 8, !tbaa !5
  %56 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %55, ptr noundef nonnull @.str.8, ptr noundef %4, ptr noundef %12) #8
  br label %76

57:                                               ; preds = %42, %28, %21
  %58 = load ptr, ptr @stderr, align 8, !tbaa !5
  %59 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %58, ptr noundef nonnull @.str.9, ptr noundef %4, ptr noundef %12) #8
  br label %76

60:                                               ; preds = %23, %44, %30
  %.155 = phi ptr [ %.054112, %44 ], [ %.054112, %30 ], [ %25, %23 ]
  %.152 = phi ptr [ %.051113, %44 ], [ %32, %30 ], [ %.051113, %23 ]
  %.149 = phi ptr [ %46, %44 ], [ %.048114, %30 ], [ %.048114, %23 ]
  %.146 = phi ptr [ %.045115, %44 ], [ %33, %30 ], [ %.045115, %23 ]
  %.1 = phi ptr [ %47, %44 ], [ %.0116, %30 ], [ %.0116, %23 ]
  %.161 = add nsw i32 %.060.in110, -2
  %61 = getelementptr inbounds i8, ptr %.058111, i64 16
  %62 = icmp sgt i32 %.060.in110, 3
  br i1 %62, label %.preheader, label %63, !llvm.loop !11

63:                                               ; preds = %60
  %.not = icmp eq ptr %.155, null
  br i1 %.not, label %64, label %67

64:                                               ; preds = %63
  %65 = load ptr, ptr @stderr, align 8, !tbaa !5
  %66 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %65, ptr noundef nonnull @.str.10, ptr noundef %4) #8
  br label %76

67:                                               ; preds = %63
  %68 = call i32 @sm2_key_generate(ptr noundef nonnull %3) #7
  %.not70 = icmp eq i32 %68, 1
  br i1 %.not70, label %69, label %73

69:                                               ; preds = %67
  %70 = call i32 @sm2_private_key_info_encrypt_to_pem(ptr noundef nonnull %3, ptr noundef nonnull %.155, ptr noundef %.146) #7
  %.not71 = icmp eq i32 %70, 1
  br i1 %.not71, label %71, label %73

71:                                               ; preds = %69
  %72 = call i32 @sm2_public_key_info_to_pem(ptr noundef nonnull %3, ptr noundef %.1) #7
  %.not72 = icmp eq i32 %72, 1
  br i1 %.not72, label %76, label %73

73:                                               ; preds = %71, %69, %67
  %74 = load ptr, ptr @stderr, align 8, !tbaa !5
  %75 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %74, ptr noundef nonnull @.str.11, ptr noundef %4) #8
  br label %76

76:                                               ; preds = %71, %73, %64, %57, %54, %48, %34, %14
  %.057 = phi i32 [ 1, %54 ], [ 1, %57 ], [ 1, %48 ], [ 1, %34 ], [ 0, %14 ], [ 1, %73 ], [ 1, %64 ], [ 0, %71 ]
  %.253 = phi ptr [ %.051113, %54 ], [ %.051113, %57 ], [ %.051113, %48 ], [ %32, %34 ], [ %.051113, %14 ], [ %.152, %73 ], [ %.152, %64 ], [ %.152, %71 ]
  %.250 = phi ptr [ %.048114, %54 ], [ %.048114, %57 ], [ %46, %48 ], [ %.048114, %34 ], [ %.048114, %14 ], [ %.149, %73 ], [ %.149, %64 ], [ %.149, %71 ]
  %.247 = phi ptr [ %.045115, %54 ], [ %.045115, %57 ], [ %.045115, %48 ], [ null, %34 ], [ %.045115, %14 ], [ %.146, %73 ], [ %.146, %64 ], [ %.146, %71 ]
  %.2 = phi ptr [ %.0116, %54 ], [ %.0116, %57 ], [ null, %48 ], [ %.0116, %34 ], [ %.0116, %14 ], [ %.1, %73 ], [ %.1, %64 ], [ %.1, %71 ]
  call void @gmssl_secure_clear(ptr noundef nonnull %3, i64 noundef 128) #7
  %77 = icmp ne ptr %.253, null
  %78 = icmp ne ptr %.247, null
  %or.cond = select i1 %77, i1 %78, i1 false
  br i1 %or.cond, label %79, label %81

79:                                               ; preds = %76
  %80 = call i32 @fclose(ptr noundef nonnull %.247)
  br label %81

81:                                               ; preds = %79, %76
  %82 = icmp ne ptr %.250, null
  %83 = icmp ne ptr %.2, null
  %or.cond3 = select i1 %82, i1 %83, i1 false
  br i1 %or.cond3, label %84, label %86

84:                                               ; preds = %81
  %85 = call i32 @fclose(ptr noundef nonnull %.2)
  br label %86

86:                                               ; preds = %81, %84, %8
  %.056 = phi i32 [ 1, %8 ], [ %.057, %84 ], [ %.057, %81 ]
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %3) #7
  ret i32 %.056
}

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

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strcmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #3

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

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #2

; Function Attrs: nounwind
declare ptr @strerror(i32 noundef) local_unnamed_addr #4

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #5

declare i32 @sm2_key_generate(ptr noundef) local_unnamed_addr #6

declare i32 @sm2_private_key_info_encrypt_to_pem(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #6

declare i32 @sm2_public_key_info_to_pem(ptr noundef, ptr noundef) local_unnamed_addr #6

declare void @gmssl_secure_clear(ptr noundef, i64 noundef) local_unnamed_addr #6

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #2

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

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 "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 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 #6 = { "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 #7 = { nounwind }
attributes #8 = { cold nounwind }
attributes #9 = { nounwind willreturn memory(read) }
attributes #10 = { nounwind willreturn memory(none) }

!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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass