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

; 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.SDF_DEVICE = type { ptr, [41 x i8], [17 x i8], [17 x i8] }
%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 [5 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [59 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [49 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [43 x i8], align 1

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

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

32:                                               ; preds = %2
  br label %33

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

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

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

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

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

56:                                               ; preds = %52
  br label %142

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

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

66:                                               ; preds = %61
  %67 = load i32, ptr %10, align 4, !tbaa !5
  %68 = icmp ne i32 %67, 0
  br i1 %68, label %69, label %73

69:                                               ; preds = %66
  %70 = load ptr, ptr @stderr, align 8, !tbaa !9
  %71 = load ptr, ptr %7, align 8, !tbaa !9
  %72 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %70, ptr noundef @.str.5, ptr noundef %71) #7
  br label %228

73:                                               ; preds = %66
  store i32 1, ptr %9, align 4, !tbaa !5
  br label %151

74:                                               ; preds = %61
  %75 = load ptr, ptr %5, align 8, !tbaa !9
  %76 = load ptr, ptr %75, align 8, !tbaa !9
  %77 = call i32 @strcmp(ptr noundef %76, ptr noundef @.str.6) #8
  %78 = icmp ne i32 %77, 0
  br i1 %78, label %87, label %79

79:                                               ; preds = %74
  %80 = load i32, ptr %9, align 4, !tbaa !5
  %81 = icmp ne i32 %80, 0
  br i1 %81, label %82, label %86

82:                                               ; preds = %79
  %83 = load ptr, ptr @stderr, align 8, !tbaa !9
  %84 = load ptr, ptr %7, align 8, !tbaa !9
  %85 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %83, ptr noundef @.str.5, ptr noundef %84) #7
  br label %228

86:                                               ; preds = %79
  store i32 1, ptr %10, align 4, !tbaa !5
  br label %150

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

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

96:                                               ; preds = %92
  br label %142

97:                                               ; preds = %92
  %98 = load ptr, ptr %5, align 8, !tbaa !9
  %99 = getelementptr inbounds ptr, ptr %98, i32 1
  store ptr %99, ptr %5, align 8, !tbaa !9
  %100 = load ptr, ptr %99, align 8, !tbaa !9
  %101 = call i32 @atoi(ptr noundef %100) #8
  store i32 %101, ptr %11, align 4, !tbaa !5
  %102 = load i32, ptr %11, align 4, !tbaa !5
  %103 = icmp slt i32 %102, 0
  br i1 %103, label %104, label %109

104:                                              ; preds = %97
  %105 = load ptr, ptr @stderr, align 8, !tbaa !9
  %106 = load ptr, ptr %7, align 8, !tbaa !9
  %107 = load i32, ptr %11, align 4, !tbaa !5
  %108 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %105, ptr noundef @.str.8, ptr noundef %106, i32 noundef %107) #7
  br label %228

109:                                              ; preds = %97
  br label %149

110:                                              ; preds = %87
  %111 = load ptr, ptr %5, align 8, !tbaa !9
  %112 = load ptr, ptr %111, align 8, !tbaa !9
  %113 = call i32 @strcmp(ptr noundef %112, ptr noundef @.str.9) #8
  %114 = icmp ne i32 %113, 0
  br i1 %114, label %136, label %115

115:                                              ; preds = %110
  %116 = load i32, ptr %4, align 4, !tbaa !5
  %117 = add nsw i32 %116, -1
  store i32 %117, ptr %4, align 4, !tbaa !5
  %118 = icmp slt i32 %117, 1
  br i1 %118, label %119, label %120

119:                                              ; preds = %115
  br label %142

120:                                              ; preds = %115
  %121 = load ptr, ptr %5, align 8, !tbaa !9
  %122 = getelementptr inbounds ptr, ptr %121, i32 1
  store ptr %122, ptr %5, align 8, !tbaa !9
  %123 = load ptr, ptr %122, align 8, !tbaa !9
  store ptr %123, ptr %12, align 8, !tbaa !9
  %124 = load ptr, ptr %12, align 8, !tbaa !9
  %125 = call noalias ptr @fopen(ptr noundef %124, ptr noundef @.str.10)
  store ptr %125, ptr %13, align 8, !tbaa !9
  %126 = icmp ne ptr %125, null
  br i1 %126, label %135, label %127

127:                                              ; preds = %120
  %128 = load ptr, ptr @stderr, align 8, !tbaa !9
  %129 = load ptr, ptr %7, align 8, !tbaa !9
  %130 = load ptr, ptr %12, align 8, !tbaa !9
  %131 = call ptr @__errno_location() #9
  %132 = load i32, ptr %131, align 4, !tbaa !5
  %133 = call ptr @strerror(i32 noundef %132) #7
  %134 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %128, ptr noundef @.str.11, ptr noundef %129, ptr noundef %130, ptr noundef %133) #7
  br label %228

135:                                              ; preds = %120
  br label %148

136:                                              ; preds = %110
  %137 = load ptr, ptr @stderr, align 8, !tbaa !9
  %138 = load ptr, ptr %7, align 8, !tbaa !9
  %139 = load ptr, ptr %5, align 8, !tbaa !9
  %140 = load ptr, ptr %139, align 8, !tbaa !9
  %141 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %137, ptr noundef @.str.12, ptr noundef %138, ptr noundef %140) #7
  br label %228

142:                                              ; preds = %119, %96, %56
  %143 = load ptr, ptr @stderr, align 8, !tbaa !9
  %144 = load ptr, ptr %7, align 8, !tbaa !9
  %145 = load ptr, ptr %5, align 8, !tbaa !9
  %146 = load ptr, ptr %145, align 8, !tbaa !9
  %147 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %143, ptr noundef @.str.13, ptr noundef %144, ptr noundef %146) #7
  br label %228

148:                                              ; preds = %135
  br label %149

149:                                              ; preds = %148, %109
  br label %150

150:                                              ; preds = %149, %86
  br label %151

151:                                              ; preds = %150, %73
  br label %152

152:                                              ; preds = %151, %57
  br label %153

153:                                              ; preds = %152
  %154 = load i32, ptr %4, align 4, !tbaa !5
  %155 = add nsw i32 %154, -1
  store i32 %155, ptr %4, align 4, !tbaa !5
  %156 = load ptr, ptr %5, align 8, !tbaa !9
  %157 = getelementptr inbounds ptr, ptr %156, i32 1
  store ptr %157, ptr %5, align 8, !tbaa !9
  br label %33, !llvm.loop !11

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

161:                                              ; preds = %158
  %162 = load ptr, ptr @stderr, align 8, !tbaa !9
  %163 = load ptr, ptr %7, align 8, !tbaa !9
  %164 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %162, ptr noundef @.str.14, ptr noundef %163) #7
  br label %228

165:                                              ; preds = %158
  %166 = load i32, ptr %9, align 4, !tbaa !5
  %167 = icmp ne i32 %166, 0
  br i1 %167, label %175, label %168

168:                                              ; preds = %165
  %169 = load i32, ptr %10, align 4, !tbaa !5
  %170 = icmp ne i32 %169, 0
  br i1 %170, label %175, label %171

171:                                              ; preds = %168
  %172 = load ptr, ptr @stderr, align 8, !tbaa !9
  %173 = load ptr, ptr %7, align 8, !tbaa !9
  %174 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %172, ptr noundef @.str.15, ptr noundef %173) #7
  br label %228

175:                                              ; preds = %168, %165
  %176 = load i32, ptr %11, align 4, !tbaa !5
  %177 = icmp slt i32 %176, 0
  br i1 %177, label %178, label %182

178:                                              ; preds = %175
  %179 = load ptr, ptr @stderr, align 8, !tbaa !9
  %180 = load ptr, ptr %7, align 8, !tbaa !9
  %181 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %179, ptr noundef @.str.16, ptr noundef %180) #7
  br label %228

182:                                              ; preds = %175
  %183 = load ptr, ptr %8, align 8, !tbaa !9
  %184 = call i32 @sdf_load_library(ptr noundef %183, ptr noundef null)
  %185 = icmp ne i32 %184, 1
  br i1 %185, label %186, label %190

186:                                              ; preds = %182
  %187 = load ptr, ptr @stderr, align 8, !tbaa !9
  %188 = load ptr, ptr %7, align 8, !tbaa !9
  %189 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %187, ptr noundef @.str.17, ptr noundef %188) #7
  br label %228

190:                                              ; preds = %182
  %191 = call i32 @sdf_open_device(ptr noundef %14)
  %192 = icmp ne i32 %191, 1
  br i1 %192, label %193, label %197

193:                                              ; preds = %190
  %194 = load ptr, ptr @stderr, align 8, !tbaa !9
  %195 = load ptr, ptr %7, align 8, !tbaa !9
  %196 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %194, ptr noundef @.str.18, ptr noundef %195) #7
  br label %228

197:                                              ; preds = %190
  %198 = load i32, ptr %9, align 4, !tbaa !5
  %199 = icmp ne i32 %198, 0
  br i1 %199, label %200, label %209

200:                                              ; preds = %197
  %201 = load i32, ptr %11, align 4, !tbaa !5
  %202 = call i32 @sdf_export_sign_public_key(ptr noundef %14, i32 noundef %201, ptr noundef %15)
  %203 = icmp ne i32 %202, 1
  br i1 %203, label %204, label %208

204:                                              ; preds = %200
  %205 = load ptr, ptr @stderr, align 8, !tbaa !9
  %206 = load ptr, ptr %7, align 8, !tbaa !9
  %207 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %205, ptr noundef @.str.19, ptr noundef %206) #7
  br label %228

208:                                              ; preds = %200
  br label %218

209:                                              ; preds = %197
  %210 = load i32, ptr %11, align 4, !tbaa !5
  %211 = call i32 @sdf_export_encrypt_public_key(ptr noundef %14, i32 noundef %210, ptr noundef %15)
  %212 = icmp ne i32 %211, 1
  br i1 %212, label %213, label %217

213:                                              ; preds = %209
  %214 = load ptr, ptr @stderr, align 8, !tbaa !9
  %215 = load ptr, ptr %7, align 8, !tbaa !9
  %216 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %214, ptr noundef @.str.19, ptr noundef %215) #7
  br label %228

217:                                              ; preds = %209
  br label %218

218:                                              ; preds = %217, %208
  %219 = load ptr, ptr %13, align 8, !tbaa !9
  %220 = call i32 @sm2_public_key_info_to_pem(ptr noundef %15, ptr noundef %219)
  %221 = icmp ne i32 %220, 1
  br i1 %221, label %222, label %226

222:                                              ; preds = %218
  %223 = load ptr, ptr @stderr, align 8, !tbaa !9
  %224 = load ptr, ptr %7, align 8, !tbaa !9
  %225 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %223, ptr noundef @.str.20, ptr noundef %224) #7
  br label %228

226:                                              ; preds = %218
  %227 = call i32 @sdf_close_device(ptr noundef %14)
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %228

228:                                              ; preds = %226, %222, %213, %204, %193, %186, %178, %171, %161, %142, %136, %127, %104, %82, %69, %41
  %229 = load ptr, ptr %8, align 8, !tbaa !9
  %230 = icmp ne ptr %229, null
  br i1 %230, label %231, label %232

231:                                              ; preds = %228
  call void @sdf_unload_library()
  br label %232

232:                                              ; preds = %231, %228
  %233 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %233, ptr %3, align 4
  store i32 1, ptr %16, align 4
  br label %234

234:                                              ; preds = %232, %27
  call void @llvm.lifetime.end.p0(i64 128, ptr %15) #7
  call void @llvm.lifetime.end.p0(i64 88, ptr %14) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #7
  %235 = load i32, ptr %3, align 4
  ret i32 %235
}

; 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

; Function Attrs: inlinehint nounwind willreturn memory(read) uwtable
declare i32 @atoi(ptr noundef nonnull) #5

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() #6

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

declare i32 @sdf_open_device(ptr noundef) #4

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

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

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

declare i32 @sdf_close_device(ptr noundef) #4

declare void @sdf_unload_library() #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 = { inlinehint nounwind willreturn memory(read) 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 #6 = { 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 #7 = { nounwind }
attributes #8 = { nounwind willreturn memory(read) }
attributes #9 = { 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.SDF_DEVICE = type { ptr, [41 x i8], [17 x i8], [17 x i8] }
%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 [5 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [59 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [49 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [43 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @sdfexport_main(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = alloca %struct.SDF_DEVICE, align 8
  %4 = alloca %struct.SM2_KEY, align 8
  %5 = load ptr, ptr %1, align 8, !tbaa !5
  %6 = load ptr, ptr @stdout, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 88, ptr nonnull %3) #8
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %4) #8
  %7 = icmp slt i32 %0, 2
  br i1 %7, label %8, 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 %5, ptr noundef %10) #9
  br label %118

.preheader:                                       ; preds = %2, %73
  %.0149 = phi ptr [ %.1, %73 ], [ %6, %2 ]
  %.055148 = phi i32 [ %.156, %73 ], [ -1, %2 ]
  %.057147 = phi i32 [ %.158, %73 ], [ 0, %2 ]
  %.059146 = phi i32 [ %.160, %73 ], [ 0, %2 ]
  %.061145 = phi ptr [ %.162, %73 ], [ null, %2 ]
  %.pn144 = phi ptr [ %.166, %73 ], [ %1, %2 ]
  %.067.in143 = phi i32 [ %.168, %73 ], [ %0, %2 ]
  %.065150 = getelementptr inbounds i8, ptr %.pn144, i64 8
  %.067151 = add nsw i32 %.067.in143, -1
  %12 = load ptr, ptr %.065150, align 8, !tbaa !5
  %13 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %12, ptr noundef nonnull dereferenceable(1) @.str.1) #10
  %.not81 = icmp eq i32 %13, 0
  br i1 %.not81, 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 %5, 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 %117

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

21:                                               ; preds = %19
  %22 = icmp eq i32 %.067.in143, 2
  br i1 %22, label %70, label %23

23:                                               ; preds = %21
  %24 = add nsw i32 %.067.in143, -2
  %25 = getelementptr inbounds i8, ptr %.pn144, i64 16
  %26 = load ptr, ptr %25, align 8, !tbaa !5
  br label %73

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

29:                                               ; preds = %27
  %.not84 = icmp eq i32 %.057147, 0
  br i1 %.not84, label %73, label %30

30:                                               ; preds = %29
  %31 = load ptr, ptr @stderr, align 8, !tbaa !5
  %32 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %31, ptr noundef nonnull @.str.5, ptr noundef %5) #9
  br label %117

33:                                               ; preds = %27
  %34 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %12, ptr noundef nonnull dereferenceable(1) @.str.6) #10
  %.not85 = icmp eq i32 %34, 0
  br i1 %.not85, label %35, label %39

35:                                               ; preds = %33
  %.not86 = icmp eq i32 %.059146, 0
  br i1 %.not86, label %73, label %36

36:                                               ; preds = %35
  %37 = load ptr, ptr @stderr, align 8, !tbaa !5
  %38 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %37, ptr noundef nonnull @.str.5, ptr noundef %5) #9
  br label %117

39:                                               ; preds = %33
  %40 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %12, ptr noundef nonnull dereferenceable(1) @.str.7) #10
  %.not87 = icmp eq i32 %40, 0
  br i1 %.not87, label %41, label %52

41:                                               ; preds = %39
  %42 = icmp eq i32 %.067.in143, 2
  br i1 %42, label %70, label %43

43:                                               ; preds = %41
  %44 = add nsw i32 %.067.in143, -2
  %45 = getelementptr inbounds i8, ptr %.pn144, i64 16
  %46 = load ptr, ptr %45, align 8, !tbaa !5
  %47 = tail call i32 @atoi(ptr nocapture noundef %46) #10
  %48 = icmp slt i32 %47, 0
  br i1 %48, label %49, label %73

49:                                               ; preds = %43
  %50 = load ptr, ptr @stderr, align 8, !tbaa !5
  %51 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %50, ptr noundef nonnull @.str.8, ptr noundef %5, i32 noundef %47) #9
  br label %117

52:                                               ; preds = %39
  %53 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %12, ptr noundef nonnull dereferenceable(1) @.str.9) #10
  %.not88 = icmp eq i32 %53, 0
  br i1 %.not88, label %54, label %67

54:                                               ; preds = %52
  %55 = icmp eq i32 %.067.in143, 2
  br i1 %55, label %70, label %56

56:                                               ; preds = %54
  %57 = add nsw i32 %.067.in143, -2
  %58 = getelementptr inbounds i8, ptr %.pn144, i64 16
  %59 = load ptr, ptr %58, align 8, !tbaa !5
  %60 = tail call noalias ptr @fopen(ptr noundef %59, ptr noundef nonnull @.str.10)
  %.not89 = icmp eq ptr %60, null
  br i1 %.not89, label %61, label %73

61:                                               ; preds = %56
  %62 = load ptr, ptr @stderr, align 8, !tbaa !5
  %63 = tail call ptr @__errno_location() #11
  %64 = load i32, ptr %63, align 4, !tbaa !9
  %65 = tail call ptr @strerror(i32 noundef %64) #8
  %66 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %62, ptr noundef nonnull @.str.11, ptr noundef %5, ptr noundef %59, ptr noundef %65) #9
  br label %117

67:                                               ; preds = %52
  %68 = load ptr, ptr @stderr, align 8, !tbaa !5
  %69 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %68, ptr noundef nonnull @.str.12, ptr noundef %5, ptr noundef %12) #9
  br label %117

70:                                               ; preds = %54, %41, %21
  %71 = load ptr, ptr @stderr, align 8, !tbaa !5
  %72 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %71, ptr noundef nonnull @.str.13, ptr noundef %5, ptr noundef %12) #9
  br label %117

73:                                               ; preds = %35, %29, %23, %56, %43
  %.168 = phi i32 [ %57, %56 ], [ %44, %43 ], [ %24, %23 ], [ %.067151, %29 ], [ %.067151, %35 ]
  %.166 = phi ptr [ %58, %56 ], [ %45, %43 ], [ %25, %23 ], [ %.065150, %29 ], [ %.065150, %35 ]
  %.162 = phi ptr [ %.061145, %56 ], [ %.061145, %43 ], [ %26, %23 ], [ %.061145, %29 ], [ %.061145, %35 ]
  %.160 = phi i32 [ %.059146, %56 ], [ %.059146, %43 ], [ %.059146, %23 ], [ 1, %29 ], [ 0, %35 ]
  %.158 = phi i32 [ %.057147, %56 ], [ %.057147, %43 ], [ %.057147, %23 ], [ 0, %29 ], [ 1, %35 ]
  %.156 = phi i32 [ %.055148, %56 ], [ %47, %43 ], [ %.055148, %23 ], [ %.055148, %29 ], [ %.055148, %35 ]
  %.1 = phi ptr [ %60, %56 ], [ %.0149, %43 ], [ %.0149, %23 ], [ %.0149, %29 ], [ %.0149, %35 ]
  %74 = icmp sgt i32 %.168, 1
  br i1 %74, label %.preheader, label %75, !llvm.loop !11

75:                                               ; preds = %73
  %.not = icmp eq ptr %.162, null
  br i1 %.not, label %.thread94, label %78

.thread94:                                        ; preds = %75
  %76 = load ptr, ptr @stderr, align 8, !tbaa !5
  %77 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %76, ptr noundef nonnull @.str.14, ptr noundef %5) #9
  br label %118

78:                                               ; preds = %75
  %79 = icmp ne i32 %.160, 0
  %80 = icmp ne i32 %.158, 0
  %or.cond = select i1 %79, i1 true, i1 %80
  br i1 %or.cond, label %84, label %81

81:                                               ; preds = %78
  %82 = load ptr, ptr @stderr, align 8, !tbaa !5
  %83 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %82, ptr noundef nonnull @.str.15, ptr noundef %5) #9
  br label %.thread

84:                                               ; preds = %78
  %85 = icmp slt i32 %.156, 0
  br i1 %85, label %86, label %89

86:                                               ; preds = %84
  %87 = load ptr, ptr @stderr, align 8, !tbaa !5
  %88 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %87, ptr noundef nonnull @.str.16, ptr noundef %5) #9
  br label %.thread

89:                                               ; preds = %84
  %90 = tail call i32 @sdf_load_library(ptr noundef nonnull %.162, ptr noundef null) #8
  %.not76 = icmp eq i32 %90, 1
  br i1 %.not76, label %94, label %91

91:                                               ; preds = %89
  %92 = load ptr, ptr @stderr, align 8, !tbaa !5
  %93 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %92, ptr noundef nonnull @.str.17, ptr noundef %5) #9
  br label %.thread

94:                                               ; preds = %89
  %95 = call i32 @sdf_open_device(ptr noundef nonnull %3) #8
  %.not77 = icmp eq i32 %95, 1
  br i1 %.not77, label %99, label %96

96:                                               ; preds = %94
  %97 = load ptr, ptr @stderr, align 8, !tbaa !5
  %98 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %97, ptr noundef nonnull @.str.18, ptr noundef %5) #9
  br label %.thread

99:                                               ; preds = %94
  br i1 %79, label %100, label %105

100:                                              ; preds = %99
  %101 = call i32 @sdf_export_sign_public_key(ptr noundef nonnull %3, i32 noundef %.156, ptr noundef nonnull %4) #8
  %.not79 = icmp eq i32 %101, 1
  br i1 %.not79, label %110, label %102

102:                                              ; preds = %100
  %103 = load ptr, ptr @stderr, align 8, !tbaa !5
  %104 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %103, ptr noundef nonnull @.str.19, ptr noundef %5) #9
  br label %.thread

105:                                              ; preds = %99
  %106 = call i32 @sdf_export_encrypt_public_key(ptr noundef nonnull %3, i32 noundef %.156, ptr noundef nonnull %4) #8
  %.not78 = icmp eq i32 %106, 1
  br i1 %.not78, label %110, label %107

107:                                              ; preds = %105
  %108 = load ptr, ptr @stderr, align 8, !tbaa !5
  %109 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %108, ptr noundef nonnull @.str.19, ptr noundef %5) #9
  br label %.thread

110:                                              ; preds = %105, %100
  %111 = call i32 @sm2_public_key_info_to_pem(ptr noundef nonnull %4, ptr noundef %.1) #8
  %.not80 = icmp eq i32 %111, 1
  br i1 %.not80, label %115, label %112

112:                                              ; preds = %110
  %113 = load ptr, ptr @stderr, align 8, !tbaa !5
  %114 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %113, ptr noundef nonnull @.str.20, ptr noundef %5) #9
  br label %.thread

115:                                              ; preds = %110
  %116 = call i32 @sdf_close_device(ptr noundef nonnull %3) #8
  br label %.thread

117:                                              ; preds = %70, %67, %61, %49, %36, %30, %14
  %.064 = phi i32 [ 1, %67 ], [ 1, %70 ], [ 1, %61 ], [ 1, %49 ], [ 1, %36 ], [ 1, %30 ], [ 0, %14 ]
  %.not90 = icmp eq ptr %.061145, null
  br i1 %.not90, label %118, label %.thread

.thread:                                          ; preds = %81, %86, %91, %96, %102, %107, %112, %115, %117
  %.06493 = phi i32 [ %.064, %117 ], [ 1, %81 ], [ 1, %107 ], [ 0, %115 ], [ 1, %112 ], [ 1, %102 ], [ 1, %96 ], [ 1, %91 ], [ 1, %86 ]
  call void @sdf_unload_library() #8
  br label %118

118:                                              ; preds = %.thread94, %117, %.thread, %8
  %.063 = phi i32 [ 1, %8 ], [ %.06493, %.thread ], [ %.064, %117 ], [ 1, %.thread94 ]
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %4) #8
  call void @llvm.lifetime.end.p0(i64 88, ptr nonnull %3) #8
  ret i32 %.063
}

; 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: inlinehint mustprogress nofree nounwind willreturn memory(read) uwtable
declare i32 @atoi(ptr nocapture noundef nonnull) local_unnamed_addr #4

; 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 #5

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

declare i32 @sdf_load_library(ptr noundef, ptr noundef) local_unnamed_addr #7

declare i32 @sdf_open_device(ptr noundef) local_unnamed_addr #7

declare i32 @sdf_export_sign_public_key(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #7

declare i32 @sdf_export_encrypt_public_key(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #7

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

declare i32 @sdf_close_device(ptr noundef) local_unnamed_addr #7

declare void @sdf_unload_library() local_unnamed_addr #7

; 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 = { inlinehint mustprogress nofree nounwind willreturn memory(read) 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 "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 = { 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 #7 = { "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 #8 = { nounwind }
attributes #9 = { cold nounwind }
attributes #10 = { nounwind willreturn memory(read) }
attributes #11 = { 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,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass