; LLVM IR from ARMmbed/mbed-crypto :: library (rsa)

; 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.mbedtls_mpi = type { i32, i64, ptr }
%struct.mbedtls_rsa_context = type { i32, i64, %struct.mbedtls_mpi, %struct.mbedtls_mpi, %struct.mbedtls_mpi, %struct.mbedtls_mpi, %struct.mbedtls_mpi, %struct.mbedtls_mpi, %struct.mbedtls_mpi, %struct.mbedtls_mpi, %struct.mbedtls_mpi, %struct.mbedtls_mpi, %struct.mbedtls_mpi, %struct.mbedtls_mpi, %struct.mbedtls_mpi, i32, i32 }

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

declare i64 @mbedtls_mpi_size(ptr noundef) #1

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

declare i32 @mbedtls_mpi_cmp_int(ptr noundef, i64 noundef) #1

declare i32 @mbedtls_mpi_mul_mpi(ptr noundef, ptr noundef, ptr noundef) #1

declare i32 @mbedtls_rsa_deduce_crt(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @mbedtls_rsa_gen_key(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4) #2 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca %struct.mbedtls_mpi, align 8
  %14 = alloca %struct.mbedtls_mpi, align 8
  %15 = alloca %struct.mbedtls_mpi, align 8
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store i32 %3, ptr %10, align 4, !tbaa !9
  store i32 %4, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  store i32 -110, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 24, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 24, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 24, ptr %15) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  store i32 0, ptr %16, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %5
  br label %19

19:                                               ; preds = %18
  br label %20

20:                                               ; preds = %19
  br label %21

21:                                               ; preds = %20
  br label %22

22:                                               ; preds = %21
  br label %23

23:                                               ; preds = %22
  %24 = load i32, ptr %10, align 4, !tbaa !9
  %25 = icmp ult i32 %24, 128
  br i1 %25, label %33, label %26

26:                                               ; preds = %23
  %27 = load i32, ptr %11, align 4, !tbaa !9
  %28 = icmp slt i32 %27, 3
  br i1 %28, label %33, label %29

29:                                               ; preds = %26
  %30 = load i32, ptr %10, align 4, !tbaa !9
  %31 = urem i32 %30, 2
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %33, label %34

33:                                               ; preds = %29, %26, %23
  store i32 -16512, ptr %6, align 4
  store i32 1, ptr %17, align 4
  br label %277

34:                                               ; preds = %29
  %35 = load i32, ptr %10, align 4, !tbaa !9
  %36 = icmp ugt i32 %35, 1024
  br i1 %36, label %37, label %38

37:                                               ; preds = %34
  store i32 2, ptr %16, align 4, !tbaa !9
  br label %38

38:                                               ; preds = %37, %34
  call void @mbedtls_mpi_init(ptr noundef %13)
  call void @mbedtls_mpi_init(ptr noundef %14)
  call void @mbedtls_mpi_init(ptr noundef %15)
  br label %39

39:                                               ; preds = %38
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %40, i32 0, i32 3
  %42 = load i32, ptr %11, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = call i32 @mbedtls_mpi_lset(ptr noundef %41, i64 noundef %43)
  store i32 %44, ptr %12, align 4, !tbaa !9
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %46, label %47

46:                                               ; preds = %39
  br label %269

47:                                               ; preds = %39
  br label %48

48:                                               ; preds = %47
  br label %49

49:                                               ; preds = %48
  br label %50

50:                                               ; preds = %200, %49
  br label %51

51:                                               ; preds = %50
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %52, i32 0, i32 5
  %54 = load i32, ptr %10, align 4, !tbaa !9
  %55 = lshr i32 %54, 1
  %56 = zext i32 %55 to i64
  %57 = load i32, ptr %16, align 4, !tbaa !9
  %58 = load ptr, ptr %8, align 8, !tbaa !5
  %59 = load ptr, ptr %9, align 8, !tbaa !5
  %60 = call i32 @mbedtls_mpi_gen_prime(ptr noundef %53, i64 noundef %56, i32 noundef %57, ptr noundef %58, ptr noundef %59)
  store i32 %60, ptr %12, align 4, !tbaa !9
  %61 = icmp ne i32 %60, 0
  br i1 %61, label %62, label %63

62:                                               ; preds = %51
  br label %269

63:                                               ; preds = %51
  br label %64

64:                                               ; preds = %63
  br label %65

65:                                               ; preds = %64
  br label %66

66:                                               ; preds = %65
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %67, i32 0, i32 6
  %69 = load i32, ptr %10, align 4, !tbaa !9
  %70 = lshr i32 %69, 1
  %71 = zext i32 %70 to i64
  %72 = load i32, ptr %16, align 4, !tbaa !9
  %73 = load ptr, ptr %8, align 8, !tbaa !5
  %74 = load ptr, ptr %9, align 8, !tbaa !5
  %75 = call i32 @mbedtls_mpi_gen_prime(ptr noundef %68, i64 noundef %71, i32 noundef %72, ptr noundef %73, ptr noundef %74)
  store i32 %75, ptr %12, align 4, !tbaa !9
  %76 = icmp ne i32 %75, 0
  br i1 %76, label %77, label %78

77:                                               ; preds = %66
  br label %269

78:                                               ; preds = %66
  br label %79

79:                                               ; preds = %78
  br label %80

80:                                               ; preds = %79
  br label %81

81:                                               ; preds = %80
  %82 = load ptr, ptr %7, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %82, i32 0, i32 5
  %84 = load ptr, ptr %7, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %84, i32 0, i32 6
  %86 = call i32 @mbedtls_mpi_sub_mpi(ptr noundef %13, ptr noundef %83, ptr noundef %85)
  store i32 %86, ptr %12, align 4, !tbaa !9
  %87 = icmp ne i32 %86, 0
  br i1 %87, label %88, label %89

88:                                               ; preds = %81
  br label %269

89:                                               ; preds = %81
  br label %90

90:                                               ; preds = %89
  br label %91

91:                                               ; preds = %90
  %92 = call i64 @mbedtls_mpi_bitlen(ptr noundef %13)
  %93 = load i32, ptr %10, align 4, !tbaa !9
  %94 = icmp uge i32 %93, 200
  br i1 %94, label %95, label %99

95:                                               ; preds = %91
  %96 = load i32, ptr %10, align 4, !tbaa !9
  %97 = lshr i32 %96, 1
  %98 = sub i32 %97, 99
  br label %100

99:                                               ; preds = %91
  br label %100

100:                                              ; preds = %99, %95
  %101 = phi i32 [ %98, %95 ], [ 0, %99 ]
  %102 = zext i32 %101 to i64
  %103 = icmp ule i64 %92, %102
  br i1 %103, label %104, label %105

104:                                              ; preds = %100
  br label %200

105:                                              ; preds = %100
  %106 = getelementptr inbounds %struct.mbedtls_mpi, ptr %13, i32 0, i32 0
  %107 = load i32, ptr %106, align 8, !tbaa !11
  %108 = icmp slt i32 %107, 0
  br i1 %108, label %109, label %114

109:                                              ; preds = %105
  %110 = load ptr, ptr %7, align 8, !tbaa !5
  %111 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %110, i32 0, i32 5
  %112 = load ptr, ptr %7, align 8, !tbaa !5
  %113 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %112, i32 0, i32 6
  call void @mbedtls_mpi_swap(ptr noundef %111, ptr noundef %113)
  br label %114

114:                                              ; preds = %109, %105
  br label %115

115:                                              ; preds = %114
  %116 = load ptr, ptr %7, align 8, !tbaa !5
  %117 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %116, i32 0, i32 5
  %118 = load ptr, ptr %7, align 8, !tbaa !5
  %119 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %118, i32 0, i32 5
  %120 = call i32 @mbedtls_mpi_sub_int(ptr noundef %117, ptr noundef %119, i64 noundef 1)
  store i32 %120, ptr %12, align 4, !tbaa !9
  %121 = icmp ne i32 %120, 0
  br i1 %121, label %122, label %123

122:                                              ; preds = %115
  br label %269

123:                                              ; preds = %115
  br label %124

124:                                              ; preds = %123
  br label %125

125:                                              ; preds = %124
  br label %126

126:                                              ; preds = %125
  %127 = load ptr, ptr %7, align 8, !tbaa !5
  %128 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %127, i32 0, i32 6
  %129 = load ptr, ptr %7, align 8, !tbaa !5
  %130 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %129, i32 0, i32 6
  %131 = call i32 @mbedtls_mpi_sub_int(ptr noundef %128, ptr noundef %130, i64 noundef 1)
  store i32 %131, ptr %12, align 4, !tbaa !9
  %132 = icmp ne i32 %131, 0
  br i1 %132, label %133, label %134

133:                                              ; preds = %126
  br label %269

134:                                              ; preds = %126
  br label %135

135:                                              ; preds = %134
  br label %136

136:                                              ; preds = %135
  br label %137

137:                                              ; preds = %136
  %138 = load ptr, ptr %7, align 8, !tbaa !5
  %139 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %138, i32 0, i32 5
  %140 = load ptr, ptr %7, align 8, !tbaa !5
  %141 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %140, i32 0, i32 6
  %142 = call i32 @mbedtls_mpi_mul_mpi(ptr noundef %13, ptr noundef %139, ptr noundef %141)
  store i32 %142, ptr %12, align 4, !tbaa !9
  %143 = icmp ne i32 %142, 0
  br i1 %143, label %144, label %145

144:                                              ; preds = %137
  br label %269

145:                                              ; preds = %137
  br label %146

146:                                              ; preds = %145
  br label %147

147:                                              ; preds = %146
  br label %148

148:                                              ; preds = %147
  %149 = load ptr, ptr %7, align 8, !tbaa !5
  %150 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %149, i32 0, i32 3
  %151 = call i32 @mbedtls_mpi_gcd(ptr noundef %14, ptr noundef %150, ptr noundef %13)
  store i32 %151, ptr %12, align 4, !tbaa !9
  %152 = icmp ne i32 %151, 0
  br i1 %152, label %153, label %154

153:                                              ; preds = %148
  br label %269

154:                                              ; preds = %148
  br label %155

155:                                              ; preds = %154
  br label %156

156:                                              ; preds = %155
  %157 = call i32 @mbedtls_mpi_cmp_int(ptr noundef %14, i64 noundef 1)
  %158 = icmp ne i32 %157, 0
  br i1 %158, label %159, label %160

159:                                              ; preds = %156
  br label %200

160:                                              ; preds = %156
  br label %161

161:                                              ; preds = %160
  %162 = load ptr, ptr %7, align 8, !tbaa !5
  %163 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %162, i32 0, i32 5
  %164 = load ptr, ptr %7, align 8, !tbaa !5
  %165 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %164, i32 0, i32 6
  %166 = call i32 @mbedtls_mpi_gcd(ptr noundef %14, ptr noundef %163, ptr noundef %165)
  store i32 %166, ptr %12, align 4, !tbaa !9
  %167 = icmp ne i32 %166, 0
  br i1 %167, label %168, label %169

168:                                              ; preds = %161
  br label %269

169:                                              ; preds = %161
  br label %170

170:                                              ; preds = %169
  br label %171

171:                                              ; preds = %170
  br label %172

172:                                              ; preds = %171
  %173 = call i32 @mbedtls_mpi_div_mpi(ptr noundef %15, ptr noundef null, ptr noundef %13, ptr noundef %14)
  store i32 %173, ptr %12, align 4, !tbaa !9
  %174 = icmp ne i32 %173, 0
  br i1 %174, label %175, label %176

175:                                              ; preds = %172
  br label %269

176:                                              ; preds = %172
  br label %177

177:                                              ; preds = %176
  br label %178

178:                                              ; preds = %177
  br label %179

179:                                              ; preds = %178
  %180 = load ptr, ptr %7, align 8, !tbaa !5
  %181 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %180, i32 0, i32 4
  %182 = load ptr, ptr %7, align 8, !tbaa !5
  %183 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %182, i32 0, i32 3
  %184 = call i32 @mbedtls_mpi_inv_mod(ptr noundef %181, ptr noundef %183, ptr noundef %15)
  store i32 %184, ptr %12, align 4, !tbaa !9
  %185 = icmp ne i32 %184, 0
  br i1 %185, label %186, label %187

186:                                              ; preds = %179
  br label %269

187:                                              ; preds = %179
  br label %188

188:                                              ; preds = %187
  br label %189

189:                                              ; preds = %188
  %190 = load ptr, ptr %7, align 8, !tbaa !5
  %191 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %190, i32 0, i32 4
  %192 = call i64 @mbedtls_mpi_bitlen(ptr noundef %191)
  %193 = load i32, ptr %10, align 4, !tbaa !9
  %194 = add i32 %193, 1
  %195 = udiv i32 %194, 2
  %196 = zext i32 %195 to i64
  %197 = icmp ule i64 %192, %196
  br i1 %197, label %198, label %199

198:                                              ; preds = %189
  br label %200

199:                                              ; preds = %189
  br label %201

200:                                              ; preds = %198, %159, %104
  br i1 true, label %50, label %201

201:                                              ; preds = %200, %199
  br label %202

202:                                              ; preds = %201
  %203 = load ptr, ptr %7, align 8, !tbaa !5
  %204 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %203, i32 0, i32 5
  %205 = load ptr, ptr %7, align 8, !tbaa !5
  %206 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %205, i32 0, i32 5
  %207 = call i32 @mbedtls_mpi_add_int(ptr noundef %204, ptr noundef %206, i64 noundef 1)
  store i32 %207, ptr %12, align 4, !tbaa !9
  %208 = icmp ne i32 %207, 0
  br i1 %208, label %209, label %210

209:                                              ; preds = %202
  br label %269

210:                                              ; preds = %202
  br label %211

211:                                              ; preds = %210
  br label %212

212:                                              ; preds = %211
  br label %213

213:                                              ; preds = %212
  %214 = load ptr, ptr %7, align 8, !tbaa !5
  %215 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %214, i32 0, i32 6
  %216 = load ptr, ptr %7, align 8, !tbaa !5
  %217 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %216, i32 0, i32 6
  %218 = call i32 @mbedtls_mpi_add_int(ptr noundef %215, ptr noundef %217, i64 noundef 1)
  store i32 %218, ptr %12, align 4, !tbaa !9
  %219 = icmp ne i32 %218, 0
  br i1 %219, label %220, label %221

220:                                              ; preds = %213
  br label %269

221:                                              ; preds = %213
  br label %222

222:                                              ; preds = %221
  br label %223

223:                                              ; preds = %222
  br label %224

224:                                              ; preds = %223
  %225 = load ptr, ptr %7, align 8, !tbaa !5
  %226 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %225, i32 0, i32 2
  %227 = load ptr, ptr %7, align 8, !tbaa !5
  %228 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %227, i32 0, i32 5
  %229 = load ptr, ptr %7, align 8, !tbaa !5
  %230 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %229, i32 0, i32 6
  %231 = call i32 @mbedtls_mpi_mul_mpi(ptr noundef %226, ptr noundef %228, ptr noundef %230)
  store i32 %231, ptr %12, align 4, !tbaa !9
  %232 = icmp ne i32 %231, 0
  br i1 %232, label %233, label %234

233:                                              ; preds = %224
  br label %269

234:                                              ; preds = %224
  br label %235

235:                                              ; preds = %234
  br label %236

236:                                              ; preds = %235
  %237 = load ptr, ptr %7, align 8, !tbaa !5
  %238 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %237, i32 0, i32 2
  %239 = call i64 @mbedtls_mpi_size(ptr noundef %238)
  %240 = load ptr, ptr %7, align 8, !tbaa !5
  %241 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %240, i32 0, i32 1
  store i64 %239, ptr %241, align 8, !tbaa !14
  br label %242

242:                                              ; preds = %236
  %243 = load ptr, ptr %7, align 8, !tbaa !5
  %244 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %243, i32 0, i32 5
  %245 = load ptr, ptr %7, align 8, !tbaa !5
  %246 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %245, i32 0, i32 6
  %247 = load ptr, ptr %7, align 8, !tbaa !5
  %248 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %247, i32 0, i32 4
  %249 = load ptr, ptr %7, align 8, !tbaa !5
  %250 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %249, i32 0, i32 7
  %251 = load ptr, ptr %7, align 8, !tbaa !5
  %252 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %251, i32 0, i32 8
  %253 = load ptr, ptr %7, align 8, !tbaa !5
  %254 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %253, i32 0, i32 9
  %255 = call i32 @mbedtls_rsa_deduce_crt(ptr noundef %244, ptr noundef %246, ptr noundef %248, ptr noundef %250, ptr noundef %252, ptr noundef %254)
  store i32 %255, ptr %12, align 4, !tbaa !9
  %256 = icmp ne i32 %255, 0
  br i1 %256, label %257, label %258

257:                                              ; preds = %242
  br label %269

258:                                              ; preds = %242
  br label %259

259:                                              ; preds = %258
  br label %260

260:                                              ; preds = %259
  br label %261

261:                                              ; preds = %260
  %262 = load ptr, ptr %7, align 8, !tbaa !5
  %263 = call i32 @mbedtls_rsa_check_privkey(ptr noundef %262)
  store i32 %263, ptr %12, align 4, !tbaa !9
  %264 = icmp ne i32 %263, 0
  br i1 %264, label %265, label %266

265:                                              ; preds = %261
  br label %269

266:                                              ; preds = %261
  br label %267

267:                                              ; preds = %266
  br label %268

268:                                              ; preds = %267
  br label %269

269:                                              ; preds = %268, %265, %257, %233, %220, %209, %186, %175, %168, %153, %144, %133, %122, %88, %77, %62, %46
  call void @mbedtls_mpi_free(ptr noundef %13)
  call void @mbedtls_mpi_free(ptr noundef %14)
  call void @mbedtls_mpi_free(ptr noundef %15)
  %270 = load i32, ptr %12, align 4, !tbaa !9
  %271 = icmp ne i32 %270, 0
  br i1 %271, label %272, label %276

272:                                              ; preds = %269
  %273 = load ptr, ptr %7, align 8, !tbaa !5
  call void @mbedtls_rsa_free(ptr noundef %273)
  %274 = load i32, ptr %12, align 4, !tbaa !9
  %275 = add nsw i32 -16768, %274
  store i32 %275, ptr %6, align 4
  store i32 1, ptr %17, align 4
  br label %277

276:                                              ; preds = %269
  store i32 0, ptr %6, align 4
  store i32 1, ptr %17, align 4
  br label %277

277:                                              ; preds = %276, %272, %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  %278 = load i32, ptr %6, align 4
  ret i32 %278
}

declare void @mbedtls_mpi_init(ptr noundef) #1

declare i32 @mbedtls_mpi_lset(ptr noundef, i64 noundef) #1

declare i32 @mbedtls_mpi_gen_prime(ptr noundef, i64 noundef, i32 noundef, ptr noundef, ptr noundef) #1

declare i32 @mbedtls_mpi_sub_mpi(ptr noundef, ptr noundef, ptr noundef) #1

declare i64 @mbedtls_mpi_bitlen(ptr noundef) #1

declare void @mbedtls_mpi_swap(ptr noundef, ptr noundef) #1

declare i32 @mbedtls_mpi_sub_int(ptr noundef, ptr noundef, i64 noundef) #1

declare i32 @mbedtls_mpi_gcd(ptr noundef, ptr noundef, ptr noundef) #1

declare i32 @mbedtls_mpi_div_mpi(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #1

declare i32 @mbedtls_mpi_inv_mod(ptr noundef, ptr noundef, ptr noundef) #1

declare i32 @mbedtls_mpi_add_int(ptr noundef, ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @mbedtls_rsa_check_privkey(ptr noundef) #2

declare void @mbedtls_mpi_free(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @mbedtls_rsa_free(ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { 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 #3 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"mbedtls_mpi", !10, i64 0, !13, i64 8, !6, i64 16}
!13 = !{!"long", !7, i64 0}
!14 = !{!15, !13, i64 8}
!15 = !{!"mbedtls_rsa_context", !10, i64 0, !13, i64 8, !12, i64 16, !12, i64 40, !12, i64 64, !12, i64 88, !12, i64 112, !12, i64 136, !12, i64 160, !12, i64 184, !12, i64 208, !12, i64 232, !12, i64 256, !12, i64 280, !12, i64 304, !10, i64 328, !10, i64 332}


; 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.mbedtls_mpi = type { i32, i64, ptr }

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

declare i64 @mbedtls_mpi_size(ptr noundef) local_unnamed_addr #1

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

declare i32 @mbedtls_mpi_cmp_int(ptr noundef, i64 noundef) local_unnamed_addr #1

declare i32 @mbedtls_mpi_mul_mpi(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @mbedtls_rsa_deduce_crt(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 -2147483648, 2147466880) i32 @mbedtls_rsa_gen_key(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #2 {
  %6 = alloca %struct.mbedtls_mpi, align 8
  %7 = alloca %struct.mbedtls_mpi, align 8
  %8 = alloca %struct.mbedtls_mpi, align 8
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %6) #3
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %7) #3
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %8) #3
  %9 = icmp ugt i32 %3, 127
  %10 = icmp sgt i32 %4, 2
  %or.cond.not96 = and i1 %9, %10
  %11 = and i32 %3, 1
  %.not = icmp eq i32 %11, 0
  %or.cond93 = and i1 %.not, %or.cond.not96
  br i1 %or.cond93, label %12, label %75

12:                                               ; preds = %5
  %13 = icmp ugt i32 %3, 1024
  %spec.select = select i1 %13, i32 2, i32 0
  call void @mbedtls_mpi_init(ptr noundef nonnull %6) #3
  call void @mbedtls_mpi_init(ptr noundef nonnull %7) #3
  call void @mbedtls_mpi_init(ptr noundef nonnull %8) #3
  %14 = getelementptr inbounds i8, ptr %0, i64 40
  %15 = zext nneg i32 %4 to i64
  %16 = call i32 @mbedtls_mpi_lset(ptr noundef nonnull %14, i64 noundef %15) #3
  %.not74 = icmp eq i32 %16, 0
  br i1 %.not74, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %12
  %17 = getelementptr inbounds i8, ptr %0, i64 88
  %18 = lshr exact i32 %3, 1
  %19 = zext nneg i32 %18 to i64
  %20 = call i32 @mbedtls_mpi_gen_prime(ptr noundef nonnull %17, i64 noundef %19, i32 noundef %spec.select, ptr noundef %1, ptr noundef %2) #3
  %.not75100 = icmp eq i32 %20, 0
  br i1 %.not75100, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader
  %21 = getelementptr inbounds i8, ptr %0, i64 112
  %22 = icmp ugt i32 %3, 199
  %23 = add nsw i32 %18, -99
  %24 = select i1 %22, i32 %23, i32 0
  %25 = zext i32 %24 to i64
  %26 = getelementptr inbounds i8, ptr %0, i64 64
  br label %27

27:                                               ; preds = %.lr.ph, %55
  %28 = call i32 @mbedtls_mpi_gen_prime(ptr noundef nonnull %21, i64 noundef %19, i32 noundef %spec.select, ptr noundef %1, ptr noundef %2) #3
  %.not76 = icmp eq i32 %28, 0
  br i1 %.not76, label %29, label %.loopexit

29:                                               ; preds = %27
  %30 = call i32 @mbedtls_mpi_sub_mpi(ptr noundef nonnull %6, ptr noundef nonnull %17, ptr noundef nonnull %21) #3
  %.not77 = icmp eq i32 %30, 0
  br i1 %.not77, label %31, label %.loopexit

31:                                               ; preds = %29
  %32 = call i64 @mbedtls_mpi_bitlen(ptr noundef nonnull %6) #3
  %.not78 = icmp ugt i64 %32, %25
  br i1 %.not78, label %33, label %55

33:                                               ; preds = %31
  %34 = load i32, ptr %6, align 8, !tbaa !5
  %35 = icmp slt i32 %34, 0
  br i1 %35, label %36, label %37

36:                                               ; preds = %33
  call void @mbedtls_mpi_swap(ptr noundef nonnull %17, ptr noundef nonnull %21) #3
  br label %37

37:                                               ; preds = %33, %36
  %38 = call i32 @mbedtls_mpi_sub_int(ptr noundef nonnull %17, ptr noundef nonnull %17, i64 noundef 1) #3
  %.not79 = icmp eq i32 %38, 0
  br i1 %.not79, label %39, label %.loopexit

39:                                               ; preds = %37
  %40 = call i32 @mbedtls_mpi_sub_int(ptr noundef nonnull %21, ptr noundef nonnull %21, i64 noundef 1) #3
  %.not80 = icmp eq i32 %40, 0
  br i1 %.not80, label %41, label %.loopexit

41:                                               ; preds = %39
  %42 = call i32 @mbedtls_mpi_mul_mpi(ptr noundef nonnull %6, ptr noundef nonnull %17, ptr noundef nonnull %21) #3
  %.not81 = icmp eq i32 %42, 0
  br i1 %.not81, label %43, label %.loopexit

43:                                               ; preds = %41
  %44 = call i32 @mbedtls_mpi_gcd(ptr noundef nonnull %7, ptr noundef nonnull %14, ptr noundef nonnull %6) #3
  %.not82 = icmp eq i32 %44, 0
  br i1 %.not82, label %45, label %.loopexit

45:                                               ; preds = %43
  %46 = call i32 @mbedtls_mpi_cmp_int(ptr noundef nonnull %7, i64 noundef 1) #3
  %.not83 = icmp eq i32 %46, 0
  br i1 %.not83, label %47, label %55

47:                                               ; preds = %45
  %48 = call i32 @mbedtls_mpi_gcd(ptr noundef nonnull %7, ptr noundef nonnull %17, ptr noundef nonnull %21) #3
  %.not84 = icmp eq i32 %48, 0
  br i1 %.not84, label %49, label %.loopexit

49:                                               ; preds = %47
  %50 = call i32 @mbedtls_mpi_div_mpi(ptr noundef nonnull %8, ptr noundef null, ptr noundef nonnull %6, ptr noundef nonnull %7) #3
  %.not85 = icmp eq i32 %50, 0
  br i1 %.not85, label %51, label %.loopexit

51:                                               ; preds = %49
  %52 = call i32 @mbedtls_mpi_inv_mod(ptr noundef nonnull %26, ptr noundef nonnull %14, ptr noundef nonnull %8) #3
  %.not86 = icmp eq i32 %52, 0
  br i1 %.not86, label %53, label %.loopexit

53:                                               ; preds = %51
  %54 = call i64 @mbedtls_mpi_bitlen(ptr noundef nonnull %26) #3
  %.not87 = icmp ugt i64 %54, %19
  br i1 %.not87, label %57, label %55

55:                                               ; preds = %53, %45, %31
  %56 = call i32 @mbedtls_mpi_gen_prime(ptr noundef nonnull %17, i64 noundef %19, i32 noundef %spec.select, ptr noundef %1, ptr noundef %2) #3
  %.not75 = icmp eq i32 %56, 0
  br i1 %.not75, label %27, label %.loopexit

57:                                               ; preds = %53
  %58 = call i32 @mbedtls_mpi_add_int(ptr noundef nonnull %17, ptr noundef nonnull %17, i64 noundef 1) #3
  %.not88 = icmp eq i32 %58, 0
  br i1 %.not88, label %59, label %.loopexit

59:                                               ; preds = %57
  %60 = call i32 @mbedtls_mpi_add_int(ptr noundef nonnull %21, ptr noundef nonnull %21, i64 noundef 1) #3
  %.not89 = icmp eq i32 %60, 0
  br i1 %.not89, label %61, label %.loopexit

61:                                               ; preds = %59
  %62 = getelementptr inbounds i8, ptr %0, i64 16
  %63 = call i32 @mbedtls_mpi_mul_mpi(ptr noundef nonnull %62, ptr noundef nonnull %17, ptr noundef nonnull %21) #3
  %.not90 = icmp eq i32 %63, 0
  br i1 %.not90, label %64, label %.loopexit

64:                                               ; preds = %61
  %65 = call i64 @mbedtls_mpi_size(ptr noundef nonnull %62) #3
  %66 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 %65, ptr %66, align 8, !tbaa !12
  %67 = getelementptr inbounds i8, ptr %0, i64 136
  %68 = getelementptr inbounds i8, ptr %0, i64 160
  %69 = getelementptr inbounds i8, ptr %0, i64 184
  %70 = call i32 @mbedtls_rsa_deduce_crt(ptr noundef nonnull %17, ptr noundef nonnull %21, ptr noundef nonnull %26, ptr noundef nonnull %67, ptr noundef nonnull %68, ptr noundef nonnull %69) #3
  %.not91 = icmp eq i32 %70, 0
  br i1 %.not91, label %71, label %.loopexit

71:                                               ; preds = %64
  %72 = call i32 @mbedtls_rsa_check_privkey(ptr noundef nonnull %0)
  br label %.loopexit

.loopexit:                                        ; preds = %55, %27, %29, %37, %39, %41, %43, %47, %49, %51, %.preheader, %71, %64, %61, %59, %57, %12
  %.055 = phi i32 [ %16, %12 ], [ %58, %57 ], [ %60, %59 ], [ %63, %61 ], [ %70, %64 ], [ %72, %71 ], [ %20, %.preheader ], [ %56, %55 ], [ %28, %27 ], [ %30, %29 ], [ %38, %37 ], [ %40, %39 ], [ %42, %41 ], [ %44, %43 ], [ %48, %47 ], [ %50, %49 ], [ %52, %51 ]
  call void @mbedtls_mpi_free(ptr noundef nonnull %6) #3
  call void @mbedtls_mpi_free(ptr noundef nonnull %7) #3
  call void @mbedtls_mpi_free(ptr noundef nonnull %8) #3
  %.not92 = icmp eq i32 %.055, 0
  br i1 %.not92, label %75, label %73

73:                                               ; preds = %.loopexit
  call void @mbedtls_rsa_free(ptr noundef %0)
  %74 = add nsw i32 %.055, -16768
  br label %75

75:                                               ; preds = %.loopexit, %5, %73
  %.056 = phi i32 [ %74, %73 ], [ -16512, %5 ], [ 0, %.loopexit ]
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %8) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %7) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %6) #3
  ret i32 %.056
}

declare void @mbedtls_mpi_init(ptr noundef) local_unnamed_addr #1

declare i32 @mbedtls_mpi_lset(ptr noundef, i64 noundef) local_unnamed_addr #1

declare i32 @mbedtls_mpi_gen_prime(ptr noundef, i64 noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @mbedtls_mpi_sub_mpi(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare i64 @mbedtls_mpi_bitlen(ptr noundef) local_unnamed_addr #1

declare void @mbedtls_mpi_swap(ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @mbedtls_mpi_sub_int(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

declare i32 @mbedtls_mpi_gcd(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @mbedtls_mpi_div_mpi(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @mbedtls_mpi_inv_mod(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @mbedtls_mpi_add_int(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @mbedtls_rsa_check_privkey(ptr noundef) local_unnamed_addr #2

declare void @mbedtls_mpi_free(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @mbedtls_rsa_free(ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { 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 #3 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !7, i64 0}
!6 = !{!"mbedtls_mpi", !7, i64 0, !10, i64 8, !11, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!13, !10, i64 8}
!13 = !{!"mbedtls_rsa_context", !7, i64 0, !10, i64 8, !6, i64 16, !6, i64 40, !6, i64 64, !6, i64 88, !6, i64 112, !6, i64 136, !6, i64 160, !6, i64 184, !6, i64 208, !6, i64 232, !6, i64 256, !6, i64 280, !6, i64 304, !7, i64 328, !7, i64 332}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass