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

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

@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 [61 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [64 x i8], align 1
@__FUNCTION__.sm9setup_main = external hidden unnamed_addr constant [14 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [31 x i8], align 1

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

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

34:                                               ; preds = %2
  br label %35

35:                                               ; preds = %145, %34
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = icmp sgt i32 %36, 0
  br i1 %37, label %38, label %150

38:                                               ; preds = %35
  %39 = load ptr, ptr %5, align 8, !tbaa !9
  %40 = load ptr, ptr %39, align 8, !tbaa !9
  %41 = call i32 @strcmp(ptr noundef %40, ptr noundef @.str.1) #6
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %49, label %43

43:                                               ; preds = %38
  %44 = load ptr, ptr %7, align 8, !tbaa !9
  %45 = load ptr, ptr @usage, align 8, !tbaa !9
  %46 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef %44, ptr noundef %45)
  %47 = load ptr, ptr @options, align 8, !tbaa !9
  %48 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, ptr noundef %47)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %17, align 4
  br label %234

49:                                               ; preds = %38
  %50 = load ptr, ptr %5, align 8, !tbaa !9
  %51 = load ptr, ptr %50, align 8, !tbaa !9
  %52 = call i32 @strcmp(ptr noundef %51, ptr noundef @.str.3) #6
  %53 = icmp ne i32 %52, 0
  br i1 %53, label %72, label %54

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

58:                                               ; preds = %54
  br label %135

59:                                               ; preds = %54
  %60 = load ptr, ptr %5, align 8, !tbaa !9
  %61 = getelementptr inbounds ptr, ptr %60, i32 1
  store ptr %61, ptr %5, align 8, !tbaa !9
  %62 = load ptr, ptr %61, align 8, !tbaa !9
  store ptr %62, ptr %8, align 8, !tbaa !9
  %63 = load ptr, ptr %8, align 8, !tbaa !9
  %64 = call i32 @sm9_oid_from_name(ptr noundef %63)
  store i32 %64, ptr %12, align 4, !tbaa !5
  %65 = icmp slt i32 %64, 1
  br i1 %65, label %66, label %71

66:                                               ; preds = %59
  %67 = load ptr, ptr @stdout, align 8, !tbaa !9
  %68 = load ptr, ptr %7, align 8, !tbaa !9
  %69 = load ptr, ptr %8, align 8, !tbaa !9
  %70 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %67, ptr noundef @.str.4, ptr noundef %68, ptr noundef %69) #5
  br label %215

71:                                               ; preds = %59
  br label %144

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

77:                                               ; preds = %72
  %78 = load i32, ptr %4, align 4, !tbaa !5
  %79 = add nsw i32 %78, -1
  store i32 %79, ptr %4, align 4, !tbaa !5
  %80 = icmp slt i32 %79, 1
  br i1 %80, label %81, label %82

81:                                               ; preds = %77
  br label %135

82:                                               ; preds = %77
  %83 = load ptr, ptr %5, align 8, !tbaa !9
  %84 = getelementptr inbounds ptr, ptr %83, i32 1
  store ptr %84, ptr %5, align 8, !tbaa !9
  %85 = load ptr, ptr %84, align 8, !tbaa !9
  store ptr %85, ptr %9, align 8, !tbaa !9
  br label %143

86:                                               ; preds = %72
  %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.6) #6
  %90 = icmp ne i32 %89, 0
  br i1 %90, label %110, 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 %135

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.7)
  store ptr %101, ptr %13, align 8, !tbaa !9
  %102 = icmp ne ptr %101, null
  br i1 %102, label %109, label %103

103:                                              ; preds = %96
  br label %104

104:                                              ; preds = %103
  %105 = load ptr, ptr @stderr, align 8, !tbaa !9
  %106 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %105, ptr noundef @.str.8, ptr noundef @.str.9, i32 noundef 76, ptr noundef @__FUNCTION__.sm9setup_main) #5
  br label %107

107:                                              ; preds = %104
  br label %108

108:                                              ; preds = %107
  br label %215

109:                                              ; preds = %96
  br label %142

110:                                              ; preds = %86
  %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.10) #6
  %114 = icmp ne i32 %113, 0
  br i1 %114, label %134, 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 %135

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 %11, align 8, !tbaa !9
  %124 = load ptr, ptr %11, align 8, !tbaa !9
  %125 = call noalias ptr @fopen(ptr noundef %124, ptr noundef @.str.7)
  store ptr %125, ptr %14, align 8, !tbaa !9
  %126 = icmp ne ptr %125, null
  br i1 %126, label %133, label %127

127:                                              ; preds = %120
  br label %128

128:                                              ; preds = %127
  %129 = load ptr, ptr @stderr, align 8, !tbaa !9
  %130 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %129, ptr noundef @.str.8, ptr noundef @.str.9, i32 noundef 83, ptr noundef @__FUNCTION__.sm9setup_main) #5
  br label %131

131:                                              ; preds = %128
  br label %132

132:                                              ; preds = %131
  br label %215

133:                                              ; preds = %120
  br label %141

134:                                              ; preds = %110
  br label %135

135:                                              ; preds = %134, %119, %95, %81, %58
  %136 = load ptr, ptr @stderr, align 8, !tbaa !9
  %137 = load ptr, ptr %7, align 8, !tbaa !9
  %138 = load ptr, ptr %5, align 8, !tbaa !9
  %139 = load ptr, ptr %138, align 8, !tbaa !9
  %140 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %136, ptr noundef @.str.11, ptr noundef %137, ptr noundef %139) #5
  store i32 1, ptr %3, align 4
  store i32 1, ptr %17, align 4
  br label %234

141:                                              ; preds = %133
  br label %142

142:                                              ; preds = %141, %109
  br label %143

143:                                              ; preds = %142, %82
  br label %144

144:                                              ; preds = %143, %71
  br label %145

145:                                              ; preds = %144
  %146 = load i32, ptr %4, align 4, !tbaa !5
  %147 = add nsw i32 %146, -1
  store i32 %147, ptr %4, align 4, !tbaa !5
  %148 = load ptr, ptr %5, align 8, !tbaa !9
  %149 = getelementptr inbounds ptr, ptr %148, i32 1
  store ptr %149, ptr %5, align 8, !tbaa !9
  br label %35, !llvm.loop !11

150:                                              ; preds = %35
  %151 = load ptr, ptr %8, align 8, !tbaa !9
  %152 = icmp ne ptr %151, null
  br i1 %152, label %159, label %153

153:                                              ; preds = %150
  br label %154

154:                                              ; preds = %153
  %155 = load ptr, ptr @stderr, align 8, !tbaa !9
  %156 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %155, ptr noundef @.str.8, ptr noundef @.str.9, i32 noundef 97, ptr noundef @__FUNCTION__.sm9setup_main) #5
  br label %157

157:                                              ; preds = %154
  br label %158

158:                                              ; preds = %157
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %17, align 4
  br label %234

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

162:                                              ; preds = %159
  br label %163

163:                                              ; preds = %162
  %164 = load ptr, ptr @stderr, align 8, !tbaa !9
  %165 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %164, ptr noundef @.str.8, ptr noundef @.str.9, i32 noundef 101, ptr noundef @__FUNCTION__.sm9setup_main) #5
  br label %166

166:                                              ; preds = %163
  br label %167

167:                                              ; preds = %166
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %17, align 4
  br label %234

168:                                              ; preds = %159
  %169 = load i32, ptr %12, align 4, !tbaa !5
  switch i32 %169, label %208 [
    i32 10, label %170
    i32 12, label %189
  ]

170:                                              ; preds = %168
  %171 = call i32 @sm9_sign_master_key_generate(ptr noundef %15)
  %172 = icmp ne i32 %171, 1
  br i1 %172, label %182, label %173

173:                                              ; preds = %170
  %174 = load ptr, ptr %9, align 8, !tbaa !9
  %175 = load ptr, ptr %13, align 8, !tbaa !9
  %176 = call i32 @sm9_sign_master_key_info_encrypt_to_pem(ptr noundef %15, ptr noundef %174, ptr noundef %175)
  %177 = icmp ne i32 %176, 1
  br i1 %177, label %182, label %178

178:                                              ; preds = %173
  %179 = load ptr, ptr %14, align 8, !tbaa !9
  %180 = call i32 @sm9_sign_master_public_key_to_pem(ptr noundef %15, ptr noundef %179)
  %181 = icmp ne i32 %180, 1
  br i1 %181, label %182, label %188

182:                                              ; preds = %178, %173, %170
  br label %183

183:                                              ; preds = %182
  %184 = load ptr, ptr @stderr, align 8, !tbaa !9
  %185 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %184, ptr noundef @.str.8, ptr noundef @.str.9, i32 noundef 110, ptr noundef @__FUNCTION__.sm9setup_main) #5
  br label %186

186:                                              ; preds = %183
  br label %187

187:                                              ; preds = %186
  br label %215

188:                                              ; preds = %178
  br label %214

189:                                              ; preds = %168
  %190 = call i32 @sm9_enc_master_key_generate(ptr noundef %16)
  %191 = icmp ne i32 %190, 1
  br i1 %191, label %201, label %192

192:                                              ; preds = %189
  %193 = load ptr, ptr %9, align 8, !tbaa !9
  %194 = load ptr, ptr %13, align 8, !tbaa !9
  %195 = call i32 @sm9_enc_master_key_info_encrypt_to_pem(ptr noundef %16, ptr noundef %193, ptr noundef %194)
  %196 = icmp ne i32 %195, 1
  br i1 %196, label %201, label %197

197:                                              ; preds = %192
  %198 = load ptr, ptr %14, align 8, !tbaa !9
  %199 = call i32 @sm9_enc_master_public_key_to_pem(ptr noundef %16, ptr noundef %198)
  %200 = icmp ne i32 %199, 1
  br i1 %200, label %201, label %207

201:                                              ; preds = %197, %192, %189
  br label %202

202:                                              ; preds = %201
  %203 = load ptr, ptr @stderr, align 8, !tbaa !9
  %204 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %203, ptr noundef @.str.8, ptr noundef @.str.9, i32 noundef 118, ptr noundef @__FUNCTION__.sm9setup_main) #5
  br label %205

205:                                              ; preds = %202
  br label %206

206:                                              ; preds = %205
  br label %215

207:                                              ; preds = %197
  br label %214

208:                                              ; preds = %168
  br label %209

209:                                              ; preds = %208
  %210 = load ptr, ptr @stderr, align 8, !tbaa !9
  %211 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %210, ptr noundef @.str.8, ptr noundef @.str.9, i32 noundef 123, ptr noundef @__FUNCTION__.sm9setup_main) #5
  br label %212

212:                                              ; preds = %209
  br label %213

213:                                              ; preds = %212
  br label %215

214:                                              ; preds = %207, %188
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %215

215:                                              ; preds = %214, %213, %206, %187, %132, %108, %66
  call void @gmssl_secure_clear(ptr noundef %15, i64 noundef 224)
  call void @gmssl_secure_clear(ptr noundef %16, i64 noundef 128)
  %216 = load ptr, ptr %10, align 8, !tbaa !9
  %217 = icmp ne ptr %216, null
  br i1 %217, label %218, label %224

218:                                              ; preds = %215
  %219 = load ptr, ptr %13, align 8, !tbaa !9
  %220 = icmp ne ptr %219, null
  br i1 %220, label %221, label %224

221:                                              ; preds = %218
  %222 = load ptr, ptr %13, align 8, !tbaa !9
  %223 = call i32 @fclose(ptr noundef %222)
  br label %224

224:                                              ; preds = %221, %218, %215
  %225 = load ptr, ptr %11, align 8, !tbaa !9
  %226 = icmp ne ptr %225, null
  br i1 %226, label %227, label %233

227:                                              ; preds = %224
  %228 = load ptr, ptr %14, align 8, !tbaa !9
  %229 = icmp ne ptr %228, null
  br i1 %229, label %230, label %233

230:                                              ; preds = %227
  %231 = load ptr, ptr %14, align 8, !tbaa !9
  %232 = call i32 @fclose(ptr noundef %231)
  br label %233

233:                                              ; preds = %230, %227, %224
  store i32 1, ptr %3, align 4
  store i32 1, ptr %17, align 4
  br label %234

234:                                              ; preds = %233, %167, %158, %135, %43, %29
  call void @llvm.lifetime.end.p0(i64 128, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 224, ptr %15) #5
  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 4, 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 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  %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

declare i32 @sm9_oid_from_name(ptr noundef) #4

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

declare i32 @sm9_sign_master_key_generate(ptr noundef) #4

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

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

declare i32 @sm9_enc_master_key_generate(ptr noundef) #4

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

declare i32 @sm9_enc_master_public_key_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 }
attributes #6 = { nounwind willreturn memory(read) }

!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.SM9_SIGN_MASTER_KEY = type { %struct.SM9_Z256_TWIST_POINT, [4 x i64] }
%struct.SM9_Z256_TWIST_POINT = type { [2 x [4 x i64]], [2 x [4 x i64]], [2 x [4 x i64]] }
%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] }

@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 [61 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [64 x i8], align 1
@__FUNCTION__.sm9setup_main = external hidden unnamed_addr constant [14 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [31 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @sm9setup_main(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = alloca %struct.SM9_SIGN_MASTER_KEY, align 8
  %4 = alloca %struct.SM9_ENC_MASTER_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 224, ptr nonnull %3) #5
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %4) #5
  %7 = icmp slt i32 %0, 2
  br i1 %7, label %9, label %.preheader.preheader

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

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

.preheader:                                       ; preds = %.preheader.preheader, %63
  %.0142 = phi ptr [ %.1, %63 ], [ %6, %.preheader.preheader ]
  %.047141 = phi ptr [ %.148, %63 ], [ %6, %.preheader.preheader ]
  %.050140 = phi i32 [ %.151, %63 ], [ undef, %.preheader.preheader ]
  %.052139 = phi ptr [ %.153, %63 ], [ null, %.preheader.preheader ]
  %.055138 = phi ptr [ %.156, %63 ], [ null, %.preheader.preheader ]
  %.058137 = phi ptr [ %.159, %63 ], [ null, %.preheader.preheader ]
  %.060136 = phi ptr [ %.161, %63 ], [ null, %.preheader.preheader ]
  %.063135 = phi ptr [ %64, %63 ], [ %8, %.preheader.preheader ]
  %.065.in134 = phi i32 [ %.166, %63 ], [ %0, %.preheader.preheader ]
  %13 = load ptr, ptr %.063135, align 8, !tbaa !5
  %14 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %13, ptr noundef nonnull dereferenceable(1) @.str.1) #7
  %.not84 = icmp eq i32 %14, 0
  br i1 %.not84, label %15, label %20

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

20:                                               ; preds = %.preheader
  %21 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %13, ptr noundef nonnull dereferenceable(1) @.str.3) #7
  %.not85 = icmp eq i32 %21, 0
  br i1 %.not85, label %22, label %32

22:                                               ; preds = %20
  %23 = icmp eq i32 %.065.in134, 2
  br i1 %23, label %60, label %24

24:                                               ; preds = %22
  %25 = getelementptr inbounds i8, ptr %.063135, i64 8
  %26 = load ptr, ptr %25, align 8, !tbaa !5
  %27 = tail call i32 @sm9_oid_from_name(ptr noundef %26) #5
  %28 = icmp slt i32 %27, 1
  br i1 %28, label %29, label %63

29:                                               ; preds = %24
  %30 = load ptr, ptr @stdout, align 8, !tbaa !5
  %31 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %30, ptr noundef nonnull @.str.4, ptr noundef %5, ptr noundef %26) #5
  br label %96

32:                                               ; preds = %20
  %33 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %13, ptr noundef nonnull dereferenceable(1) @.str.5) #7
  %.not86 = icmp eq i32 %33, 0
  br i1 %.not86, label %34, label %39

34:                                               ; preds = %32
  %35 = icmp eq i32 %.065.in134, 2
  br i1 %35, label %60, label %36

36:                                               ; preds = %34
  %37 = getelementptr inbounds i8, ptr %.063135, i64 8
  %38 = load ptr, ptr %37, align 8, !tbaa !5
  br label %63

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

41:                                               ; preds = %39
  %42 = icmp eq i32 %.065.in134, 2
  br i1 %42, label %60, label %43

43:                                               ; preds = %41
  %44 = getelementptr inbounds i8, ptr %.063135, i64 8
  %45 = load ptr, ptr %44, align 8, !tbaa !5
  %46 = tail call noalias ptr @fopen(ptr noundef %45, ptr noundef nonnull @.str.7)
  %.not88 = icmp eq ptr %46, null
  br i1 %.not88, label %47, label %63

47:                                               ; preds = %43
  %48 = load ptr, ptr @stderr, align 8, !tbaa !5
  %49 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %48, ptr noundef nonnull @.str.8, ptr noundef nonnull @.str.9, i32 noundef 76, ptr noundef nonnull @__FUNCTION__.sm9setup_main) #6
  br label %96

50:                                               ; preds = %39
  %51 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %13, ptr noundef nonnull dereferenceable(1) @.str.10) #7
  %.not89 = icmp ne i32 %51, 0
  %52 = icmp eq i32 %.065.in134, 2
  %or.cond91 = or i1 %52, %.not89
  br i1 %or.cond91, label %60, label %53

53:                                               ; preds = %50
  %54 = getelementptr inbounds i8, ptr %.063135, i64 8
  %55 = load ptr, ptr %54, align 8, !tbaa !5
  %56 = tail call noalias ptr @fopen(ptr noundef %55, ptr noundef nonnull @.str.7)
  %.not90 = icmp eq ptr %56, null
  br i1 %.not90, label %57, label %63

57:                                               ; preds = %53
  %58 = load ptr, ptr @stderr, align 8, !tbaa !5
  %59 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %58, ptr noundef nonnull @.str.8, ptr noundef nonnull @.str.9, i32 noundef 83, ptr noundef nonnull @__FUNCTION__.sm9setup_main) #6
  br label %96

60:                                               ; preds = %50, %41, %34, %22
  %61 = load ptr, ptr @stderr, align 8, !tbaa !5
  %62 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %61, ptr noundef nonnull @.str.11, ptr noundef %5, ptr noundef %13) #6
  br label %106

63:                                               ; preds = %24, %43, %53, %36
  %.161 = phi ptr [ %.060136, %53 ], [ %.060136, %43 ], [ %.060136, %36 ], [ %26, %24 ]
  %.159 = phi ptr [ %.058137, %53 ], [ %.058137, %43 ], [ %38, %36 ], [ %.058137, %24 ]
  %.156 = phi ptr [ %.055138, %53 ], [ %45, %43 ], [ %.055138, %36 ], [ %.055138, %24 ]
  %.153 = phi ptr [ %55, %53 ], [ %.052139, %43 ], [ %.052139, %36 ], [ %.052139, %24 ]
  %.151 = phi i32 [ %.050140, %53 ], [ %.050140, %43 ], [ %.050140, %36 ], [ %27, %24 ]
  %.148 = phi ptr [ %.047141, %53 ], [ %46, %43 ], [ %.047141, %36 ], [ %.047141, %24 ]
  %.1 = phi ptr [ %56, %53 ], [ %.0142, %43 ], [ %.0142, %36 ], [ %.0142, %24 ]
  %.166 = add nsw i32 %.065.in134, -2
  %64 = getelementptr inbounds i8, ptr %.063135, i64 16
  %65 = icmp sgt i32 %.065.in134, 3
  br i1 %65, label %.preheader, label %66, !llvm.loop !9

66:                                               ; preds = %63
  %.not = icmp eq ptr %.161, null
  br i1 %.not, label %67, label %70

67:                                               ; preds = %66
  %68 = load ptr, ptr @stderr, align 8, !tbaa !5
  %69 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %68, ptr noundef nonnull @.str.8, ptr noundef nonnull @.str.9, i32 noundef 97, ptr noundef nonnull @__FUNCTION__.sm9setup_main) #6
  br label %106

70:                                               ; preds = %66
  %.not77 = icmp eq ptr %.159, null
  br i1 %.not77, label %71, label %74

71:                                               ; preds = %70
  %72 = load ptr, ptr @stderr, align 8, !tbaa !5
  %73 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %72, ptr noundef nonnull @.str.8, ptr noundef nonnull @.str.9, i32 noundef 101, ptr noundef nonnull @__FUNCTION__.sm9setup_main) #6
  br label %106

74:                                               ; preds = %70
  switch i32 %.151, label %93 [
    i32 10, label %75
    i32 12, label %84
  ]

75:                                               ; preds = %74
  %76 = call i32 @sm9_sign_master_key_generate(ptr noundef nonnull %3) #5
  %.not81 = icmp eq i32 %76, 1
  br i1 %.not81, label %77, label %81

77:                                               ; preds = %75
  %78 = call i32 @sm9_sign_master_key_info_encrypt_to_pem(ptr noundef nonnull %3, ptr noundef nonnull %.159, ptr noundef %.148) #5
  %.not82 = icmp eq i32 %78, 1
  br i1 %.not82, label %79, label %81

79:                                               ; preds = %77
  %80 = call i32 @sm9_sign_master_public_key_to_pem(ptr noundef nonnull %3, ptr noundef %.1) #5
  %.not83 = icmp eq i32 %80, 1
  br i1 %.not83, label %96, label %81

81:                                               ; preds = %75, %77, %79
  %82 = load ptr, ptr @stderr, align 8, !tbaa !5
  %83 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %82, ptr noundef nonnull @.str.8, ptr noundef nonnull @.str.9, i32 noundef 110, ptr noundef nonnull @__FUNCTION__.sm9setup_main) #6
  br label %96

84:                                               ; preds = %74
  %85 = call i32 @sm9_enc_master_key_generate(ptr noundef nonnull %4) #5
  %.not78 = icmp eq i32 %85, 1
  br i1 %.not78, label %86, label %90

86:                                               ; preds = %84
  %87 = call i32 @sm9_enc_master_key_info_encrypt_to_pem(ptr noundef nonnull %4, ptr noundef nonnull %.159, ptr noundef %.148) #5
  %.not79 = icmp eq i32 %87, 1
  br i1 %.not79, label %88, label %90

88:                                               ; preds = %86
  %89 = call i32 @sm9_enc_master_public_key_to_pem(ptr noundef nonnull %4, ptr noundef %.1) #5
  %.not80 = icmp eq i32 %89, 1
  br i1 %.not80, label %96, label %90

90:                                               ; preds = %84, %86, %88
  %91 = load ptr, ptr @stderr, align 8, !tbaa !5
  %92 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %91, ptr noundef nonnull @.str.8, ptr noundef nonnull @.str.9, i32 noundef 118, ptr noundef nonnull @__FUNCTION__.sm9setup_main) #6
  br label %96

93:                                               ; preds = %74
  %94 = load ptr, ptr @stderr, align 8, !tbaa !5
  %95 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %94, ptr noundef nonnull @.str.8, ptr noundef nonnull @.str.9, i32 noundef 123, ptr noundef nonnull @__FUNCTION__.sm9setup_main) #6
  br label %96

96:                                               ; preds = %79, %88, %93, %90, %81, %57, %47, %29
  %.257 = phi ptr [ %.055138, %57 ], [ %45, %47 ], [ %.055138, %29 ], [ %.156, %93 ], [ %.156, %90 ], [ %.156, %81 ], [ %.156, %88 ], [ %.156, %79 ]
  %.254 = phi ptr [ %55, %57 ], [ %.052139, %47 ], [ %.052139, %29 ], [ %.153, %93 ], [ %.153, %90 ], [ %.153, %81 ], [ %.153, %88 ], [ %.153, %79 ]
  %.249 = phi ptr [ %.047141, %57 ], [ null, %47 ], [ %.047141, %29 ], [ %.148, %93 ], [ %.148, %90 ], [ %.148, %81 ], [ %.148, %88 ], [ %.148, %79 ]
  %.2 = phi ptr [ null, %57 ], [ %.0142, %47 ], [ %.0142, %29 ], [ %.1, %93 ], [ %.1, %90 ], [ %.1, %81 ], [ %.1, %88 ], [ %.1, %79 ]
  call void @gmssl_secure_clear(ptr noundef nonnull %3, i64 noundef 224) #5
  call void @gmssl_secure_clear(ptr noundef nonnull %4, i64 noundef 128) #5
  %97 = icmp ne ptr %.257, null
  %98 = icmp ne ptr %.249, null
  %or.cond = select i1 %97, i1 %98, i1 false
  br i1 %or.cond, label %99, label %101

99:                                               ; preds = %96
  %100 = call i32 @fclose(ptr noundef nonnull %.249)
  br label %101

101:                                              ; preds = %99, %96
  %102 = icmp ne ptr %.254, null
  %103 = icmp ne ptr %.2, null
  %or.cond3 = select i1 %102, i1 %103, i1 false
  br i1 %or.cond3, label %104, label %106

104:                                              ; preds = %101
  %105 = call i32 @fclose(ptr noundef nonnull %.2)
  br label %106

106:                                              ; preds = %101, %104, %71, %67, %60, %15, %9
  %.062 = phi i32 [ 1, %9 ], [ 1, %60 ], [ 0, %15 ], [ -1, %71 ], [ -1, %67 ], [ 1, %104 ], [ 1, %101 ]
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %4) #5
  call void @llvm.lifetime.end.p0(i64 224, ptr nonnull %3) #5
  ret i32 %.062
}

; 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

declare i32 @sm9_oid_from_name(ptr noundef) 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

declare i32 @sm9_sign_master_key_generate(ptr noundef) local_unnamed_addr #4

declare i32 @sm9_sign_master_key_info_encrypt_to_pem(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #4

declare i32 @sm9_sign_master_public_key_to_pem(ptr noundef, ptr noundef) local_unnamed_addr #4

declare i32 @sm9_enc_master_key_generate(ptr noundef) local_unnamed_addr #4

declare i32 @sm9_enc_master_key_info_encrypt_to_pem(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #4

declare i32 @sm9_enc_master_public_key_to_pem(ptr noundef, ptr noundef) local_unnamed_addr #4

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

; 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 = { "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 }
attributes #7 = { nounwind willreturn memory(read) }

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


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