; LLVM IR from tleonhardt/practical_cryptography_engineering :: mbedtls (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_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 }
%struct.mbedtls_mpi = type { i32, i64, ptr }

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

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

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

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

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

declare ptr @mbedtls_md_info_from_type(i32 noundef) #3

declare zeroext i8 @mbedtls_md_get_size(ptr noundef) #3

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

; Function Attrs: nounwind uwtable
define dso_local i32 @mbedtls_rsa_rsassa_pkcs1_v15_sign(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5, ptr noundef %6, ptr noundef %7) #2 {
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca ptr, align 8
  %17 = alloca ptr, align 8
  %18 = alloca i64, align 8
  %19 = alloca i64, align 8
  %20 = alloca i64, align 8
  %21 = alloca ptr, align 8
  %22 = alloca ptr, align 8
  %23 = alloca ptr, align 8
  %24 = alloca ptr, align 8
  %25 = alloca i64, align 8
  %26 = alloca i8, align 1
  %27 = alloca i8, align 1
  %28 = alloca i32, align 4
  %29 = alloca i32, align 4
  %30 = alloca ptr, align 8
  store ptr %0, ptr %10, align 8, !tbaa !5
  store ptr %1, ptr %11, align 8, !tbaa !5
  store ptr %2, ptr %12, align 8, !tbaa !5
  store i32 %3, ptr %13, align 4, !tbaa !9
  store i32 %4, ptr %14, align 4, !tbaa !9
  store i32 %5, ptr %15, align 4, !tbaa !9
  store ptr %6, ptr %16, align 8, !tbaa !5
  store ptr %7, ptr %17, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #7
  store i64 0, ptr %20, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #7
  %31 = load ptr, ptr %17, align 8, !tbaa !5
  store ptr %31, ptr %21, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #7
  store ptr null, ptr %22, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %23) #7
  store ptr null, ptr %23, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %24) #7
  store ptr null, ptr %24, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %25) #7
  call void @llvm.lifetime.start.p0(i64 1, ptr %26) #7
  call void @llvm.lifetime.start.p0(i64 1, ptr %27) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %28) #7
  %32 = load i32, ptr %13, align 4, !tbaa !9
  %33 = icmp eq i32 %32, 1
  br i1 %33, label %34, label %40

34:                                               ; preds = %8
  %35 = load ptr, ptr %10, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %35, i32 0, i32 15
  %37 = load i32, ptr %36, align 8, !tbaa !13
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %40

39:                                               ; preds = %34
  store i32 -16512, ptr %9, align 4
  store i32 1, ptr %29, align 4
  br label %235

40:                                               ; preds = %34, %8
  %41 = load ptr, ptr %10, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %41, i32 0, i32 1
  %43 = load i64, ptr %42, align 8, !tbaa !16
  store i64 %43, ptr %19, align 8, !tbaa !11
  %44 = load i64, ptr %19, align 8, !tbaa !11
  %45 = sub i64 %44, 3
  store i64 %45, ptr %18, align 8, !tbaa !11
  %46 = load i32, ptr %14, align 4, !tbaa !9
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %48, label %70

48:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 8, ptr %30) #7
  %49 = load i32, ptr %14, align 4, !tbaa !9
  %50 = call ptr @mbedtls_md_info_from_type(i32 noundef %49)
  store ptr %50, ptr %30, align 8, !tbaa !5
  %51 = load ptr, ptr %30, align 8, !tbaa !5
  %52 = icmp eq ptr %51, null
  br i1 %52, label %53, label %54

53:                                               ; preds = %48
  store i32 -16512, ptr %9, align 4
  store i32 1, ptr %29, align 4
  br label %67

54:                                               ; preds = %48
  %55 = load i32, ptr %14, align 4, !tbaa !9
  %56 = call i32 @mbedtls_oid_get_oid_by_md(i32 noundef %55, ptr noundef %22, ptr noundef %20)
  %57 = icmp ne i32 %56, 0
  br i1 %57, label %58, label %59

58:                                               ; preds = %54
  store i32 -16512, ptr %9, align 4
  store i32 1, ptr %29, align 4
  br label %67

59:                                               ; preds = %54
  %60 = load i64, ptr %20, align 8, !tbaa !11
  %61 = add i64 10, %60
  %62 = load i64, ptr %18, align 8, !tbaa !11
  %63 = sub i64 %62, %61
  store i64 %63, ptr %18, align 8, !tbaa !11
  %64 = load ptr, ptr %30, align 8, !tbaa !5
  %65 = call zeroext i8 @mbedtls_md_get_size(ptr noundef %64)
  %66 = zext i8 %65 to i32
  store i32 %66, ptr %15, align 4, !tbaa !9
  store i32 0, ptr %29, align 4
  br label %67

67:                                               ; preds = %59, %58, %53
  call void @llvm.lifetime.end.p0(i64 8, ptr %30) #7
  %68 = load i32, ptr %29, align 4
  switch i32 %68, label %235 [
    i32 0, label %69
  ]

69:                                               ; preds = %67
  br label %70

70:                                               ; preds = %69, %40
  %71 = load i32, ptr %15, align 4, !tbaa !9
  %72 = zext i32 %71 to i64
  %73 = load i64, ptr %18, align 8, !tbaa !11
  %74 = sub i64 %73, %72
  store i64 %74, ptr %18, align 8, !tbaa !11
  %75 = load i64, ptr %18, align 8, !tbaa !11
  %76 = icmp ult i64 %75, 8
  br i1 %76, label %81, label %77

77:                                               ; preds = %70
  %78 = load i64, ptr %18, align 8, !tbaa !11
  %79 = load i64, ptr %19, align 8, !tbaa !11
  %80 = icmp ugt i64 %78, %79
  br i1 %80, label %81, label %82

81:                                               ; preds = %77, %70
  store i32 -16512, ptr %9, align 4
  store i32 1, ptr %29, align 4
  br label %235

82:                                               ; preds = %77
  %83 = load ptr, ptr %21, align 8, !tbaa !5
  %84 = getelementptr inbounds i8, ptr %83, i32 1
  store ptr %84, ptr %21, align 8, !tbaa !5
  store i8 0, ptr %83, align 1, !tbaa !17
  %85 = load ptr, ptr %21, align 8, !tbaa !5
  %86 = getelementptr inbounds i8, ptr %85, i32 1
  store ptr %86, ptr %21, align 8, !tbaa !5
  store i8 1, ptr %85, align 1, !tbaa !17
  %87 = load ptr, ptr %21, align 8, !tbaa !5
  %88 = load i64, ptr %18, align 8, !tbaa !11
  call void @llvm.memset.p0.i64(ptr align 1 %87, i8 -1, i64 %88, i1 false)
  %89 = load i64, ptr %18, align 8, !tbaa !11
  %90 = load ptr, ptr %21, align 8, !tbaa !5
  %91 = getelementptr inbounds i8, ptr %90, i64 %89
  store ptr %91, ptr %21, align 8, !tbaa !5
  %92 = load ptr, ptr %21, align 8, !tbaa !5
  %93 = getelementptr inbounds i8, ptr %92, i32 1
  store ptr %93, ptr %21, align 8, !tbaa !5
  store i8 0, ptr %92, align 1, !tbaa !17
  %94 = load i32, ptr %14, align 4, !tbaa !9
  %95 = icmp eq i32 %94, 0
  br i1 %95, label %96, label %101

96:                                               ; preds = %82
  %97 = load ptr, ptr %21, align 8, !tbaa !5
  %98 = load ptr, ptr %16, align 8, !tbaa !5
  %99 = load i32, ptr %15, align 4, !tbaa !9
  %100 = zext i32 %99 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %97, ptr align 1 %98, i64 %100, i1 false)
  br label %146

101:                                              ; preds = %82
  %102 = load ptr, ptr %21, align 8, !tbaa !5
  %103 = getelementptr inbounds i8, ptr %102, i32 1
  store ptr %103, ptr %21, align 8, !tbaa !5
  store i8 48, ptr %102, align 1, !tbaa !17
  %104 = load i64, ptr %20, align 8, !tbaa !11
  %105 = add i64 8, %104
  %106 = load i32, ptr %15, align 4, !tbaa !9
  %107 = zext i32 %106 to i64
  %108 = add i64 %105, %107
  %109 = trunc i64 %108 to i8
  %110 = load ptr, ptr %21, align 8, !tbaa !5
  %111 = getelementptr inbounds i8, ptr %110, i32 1
  store ptr %111, ptr %21, align 8, !tbaa !5
  store i8 %109, ptr %110, align 1, !tbaa !17
  %112 = load ptr, ptr %21, align 8, !tbaa !5
  %113 = getelementptr inbounds i8, ptr %112, i32 1
  store ptr %113, ptr %21, align 8, !tbaa !5
  store i8 48, ptr %112, align 1, !tbaa !17
  %114 = load i64, ptr %20, align 8, !tbaa !11
  %115 = add i64 4, %114
  %116 = trunc i64 %115 to i8
  %117 = load ptr, ptr %21, align 8, !tbaa !5
  %118 = getelementptr inbounds i8, ptr %117, i32 1
  store ptr %118, ptr %21, align 8, !tbaa !5
  store i8 %116, ptr %117, align 1, !tbaa !17
  %119 = load ptr, ptr %21, align 8, !tbaa !5
  %120 = getelementptr inbounds i8, ptr %119, i32 1
  store ptr %120, ptr %21, align 8, !tbaa !5
  store i8 6, ptr %119, align 1, !tbaa !17
  %121 = load i64, ptr %20, align 8, !tbaa !11
  %122 = and i64 %121, 255
  %123 = trunc i64 %122 to i8
  %124 = load ptr, ptr %21, align 8, !tbaa !5
  %125 = getelementptr inbounds i8, ptr %124, i32 1
  store ptr %125, ptr %21, align 8, !tbaa !5
  store i8 %123, ptr %124, align 1, !tbaa !17
  %126 = load ptr, ptr %21, align 8, !tbaa !5
  %127 = load ptr, ptr %22, align 8, !tbaa !5
  %128 = load i64, ptr %20, align 8, !tbaa !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %126, ptr align 1 %127, i64 %128, i1 false)
  %129 = load i64, ptr %20, align 8, !tbaa !11
  %130 = load ptr, ptr %21, align 8, !tbaa !5
  %131 = getelementptr inbounds i8, ptr %130, i64 %129
  store ptr %131, ptr %21, align 8, !tbaa !5
  %132 = load ptr, ptr %21, align 8, !tbaa !5
  %133 = getelementptr inbounds i8, ptr %132, i32 1
  store ptr %133, ptr %21, align 8, !tbaa !5
  store i8 5, ptr %132, align 1, !tbaa !17
  %134 = load ptr, ptr %21, align 8, !tbaa !5
  %135 = getelementptr inbounds i8, ptr %134, i32 1
  store ptr %135, ptr %21, align 8, !tbaa !5
  store i8 0, ptr %134, align 1, !tbaa !17
  %136 = load ptr, ptr %21, align 8, !tbaa !5
  %137 = getelementptr inbounds i8, ptr %136, i32 1
  store ptr %137, ptr %21, align 8, !tbaa !5
  store i8 4, ptr %136, align 1, !tbaa !17
  %138 = load i32, ptr %15, align 4, !tbaa !9
  %139 = trunc i32 %138 to i8
  %140 = load ptr, ptr %21, align 8, !tbaa !5
  %141 = getelementptr inbounds i8, ptr %140, i32 1
  store ptr %141, ptr %21, align 8, !tbaa !5
  store i8 %139, ptr %140, align 1, !tbaa !17
  %142 = load ptr, ptr %21, align 8, !tbaa !5
  %143 = load ptr, ptr %16, align 8, !tbaa !5
  %144 = load i32, ptr %15, align 4, !tbaa !9
  %145 = zext i32 %144 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %142, ptr align 1 %143, i64 %145, i1 false)
  br label %146

146:                                              ; preds = %101, %96
  %147 = load i32, ptr %13, align 4, !tbaa !9
  %148 = icmp eq i32 %147, 0
  br i1 %148, label %149, label %154

149:                                              ; preds = %146
  %150 = load ptr, ptr %10, align 8, !tbaa !5
  %151 = load ptr, ptr %17, align 8, !tbaa !5
  %152 = load ptr, ptr %17, align 8, !tbaa !5
  %153 = call i32 @mbedtls_rsa_public(ptr noundef %150, ptr noundef %151, ptr noundef %152)
  store i32 %153, ptr %9, align 4
  store i32 1, ptr %29, align 4
  br label %235

154:                                              ; preds = %146
  %155 = load ptr, ptr %10, align 8, !tbaa !5
  %156 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %155, i32 0, i32 1
  %157 = load i64, ptr %156, align 8, !tbaa !16
  %158 = call noalias ptr @calloc(i64 noundef 1, i64 noundef %157) #8
  store ptr %158, ptr %23, align 8, !tbaa !5
  %159 = load ptr, ptr %23, align 8, !tbaa !5
  %160 = icmp eq ptr %159, null
  br i1 %160, label %161, label %162

161:                                              ; preds = %154
  store i32 -16, ptr %9, align 4
  store i32 1, ptr %29, align 4
  br label %235

162:                                              ; preds = %154
  %163 = load ptr, ptr %10, align 8, !tbaa !5
  %164 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %163, i32 0, i32 1
  %165 = load i64, ptr %164, align 8, !tbaa !16
  %166 = call noalias ptr @calloc(i64 noundef 1, i64 noundef %165) #8
  store ptr %166, ptr %24, align 8, !tbaa !5
  %167 = load ptr, ptr %24, align 8, !tbaa !5
  %168 = icmp eq ptr %167, null
  br i1 %168, label %169, label %171

169:                                              ; preds = %162
  %170 = load ptr, ptr %23, align 8, !tbaa !5
  call void @free(ptr noundef %170) #7
  store i32 -16, ptr %9, align 4
  store i32 1, ptr %29, align 4
  br label %235

171:                                              ; preds = %162
  br label %172

172:                                              ; preds = %171
  %173 = load ptr, ptr %10, align 8, !tbaa !5
  %174 = load ptr, ptr %11, align 8, !tbaa !5
  %175 = load ptr, ptr %12, align 8, !tbaa !5
  %176 = load ptr, ptr %17, align 8, !tbaa !5
  %177 = load ptr, ptr %23, align 8, !tbaa !5
  %178 = call i32 @mbedtls_rsa_private(ptr noundef %173, ptr noundef %174, ptr noundef %175, ptr noundef %176, ptr noundef %177)
  store i32 %178, ptr %28, align 4, !tbaa !9
  %179 = icmp ne i32 %178, 0
  br i1 %179, label %180, label %181

180:                                              ; preds = %172
  br label %231

181:                                              ; preds = %172
  br label %182

182:                                              ; preds = %181
  br label %183

183:                                              ; preds = %182
  br label %184

184:                                              ; preds = %183
  %185 = load ptr, ptr %10, align 8, !tbaa !5
  %186 = load ptr, ptr %23, align 8, !tbaa !5
  %187 = load ptr, ptr %24, align 8, !tbaa !5
  %188 = call i32 @mbedtls_rsa_public(ptr noundef %185, ptr noundef %186, ptr noundef %187)
  store i32 %188, ptr %28, align 4, !tbaa !9
  %189 = icmp ne i32 %188, 0
  br i1 %189, label %190, label %191

190:                                              ; preds = %184
  br label %231

191:                                              ; preds = %184
  br label %192

192:                                              ; preds = %191
  br label %193

193:                                              ; preds = %192
  store i8 0, ptr %26, align 1, !tbaa !17
  store i64 0, ptr %25, align 8, !tbaa !11
  br label %194

194:                                              ; preds = %216, %193
  %195 = load i64, ptr %25, align 8, !tbaa !11
  %196 = load ptr, ptr %10, align 8, !tbaa !5
  %197 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %196, i32 0, i32 1
  %198 = load i64, ptr %197, align 8, !tbaa !16
  %199 = icmp ult i64 %195, %198
  br i1 %199, label %200, label %219

200:                                              ; preds = %194
  %201 = load ptr, ptr %24, align 8, !tbaa !5
  %202 = load i64, ptr %25, align 8, !tbaa !11
  %203 = getelementptr inbounds i8, ptr %201, i64 %202
  %204 = load i8, ptr %203, align 1, !tbaa !17
  %205 = zext i8 %204 to i32
  %206 = load ptr, ptr %17, align 8, !tbaa !5
  %207 = load i64, ptr %25, align 8, !tbaa !11
  %208 = getelementptr inbounds i8, ptr %206, i64 %207
  %209 = load i8, ptr %208, align 1, !tbaa !17
  %210 = zext i8 %209 to i32
  %211 = xor i32 %205, %210
  %212 = load i8, ptr %26, align 1, !tbaa !17
  %213 = zext i8 %212 to i32
  %214 = or i32 %213, %211
  %215 = trunc i32 %214 to i8
  store i8 %215, ptr %26, align 1, !tbaa !17
  br label %216

216:                                              ; preds = %200
  %217 = load i64, ptr %25, align 8, !tbaa !11
  %218 = add i64 %217, 1
  store i64 %218, ptr %25, align 8, !tbaa !11
  br label %194, !llvm.loop !18

219:                                              ; preds = %194
  %220 = load i8, ptr %26, align 1, !tbaa !17
  store volatile i8 %220, ptr %27, align 1, !tbaa !17
  %221 = load volatile i8, ptr %27, align 1, !tbaa !17
  %222 = zext i8 %221 to i32
  %223 = icmp ne i32 %222, 0
  br i1 %223, label %224, label %225

224:                                              ; preds = %219
  store i32 -17152, ptr %28, align 4, !tbaa !9
  br label %231

225:                                              ; preds = %219
  %226 = load ptr, ptr %17, align 8, !tbaa !5
  %227 = load ptr, ptr %23, align 8, !tbaa !5
  %228 = load ptr, ptr %10, align 8, !tbaa !5
  %229 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %228, i32 0, i32 1
  %230 = load i64, ptr %229, align 8, !tbaa !16
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %226, ptr align 1 %227, i64 %230, i1 false)
  br label %231

231:                                              ; preds = %225, %224, %190, %180
  %232 = load ptr, ptr %23, align 8, !tbaa !5
  call void @free(ptr noundef %232) #7
  %233 = load ptr, ptr %24, align 8, !tbaa !5
  call void @free(ptr noundef %233) #7
  %234 = load i32, ptr %28, align 4, !tbaa !9
  store i32 %234, ptr %9, align 4
  store i32 1, ptr %29, align 4
  br label %235

235:                                              ; preds = %231, %169, %161, %149, %81, %67, %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %28) #7
  call void @llvm.lifetime.end.p0(i64 1, ptr %27) #7
  call void @llvm.lifetime.end.p0(i64 1, ptr %26) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %25) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %24) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %23) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #7
  %236 = load i32, ptr %9, align 4
  ret i32 %236
}

declare i32 @mbedtls_oid_get_oid_by_md(i32 noundef, ptr noundef, ptr noundef) #3

; Function Attrs: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #5

; Function Attrs: nounwind
declare void @free(ptr noundef) #6

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nounwind allocsize(0,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 #6 = { 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 #7 = { nounwind }
attributes #8 = { nounwind allocsize(0,1) }

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

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

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

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

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

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

declare ptr @mbedtls_md_info_from_type(i32 noundef) local_unnamed_addr #3

declare zeroext i8 @mbedtls_md_get_size(ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

; Function Attrs: nounwind uwtable
define dso_local i32 @mbedtls_rsa_rsassa_pkcs1_v15_sign(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5, ptr nocapture noundef readonly %6, ptr noundef %7) local_unnamed_addr #2 {
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i8, align 1
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %9) #8
  store i64 0, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %10) #8
  store ptr null, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %11)
  %12 = icmp eq i32 %3, 1
  br i1 %12, label %13, label %16

13:                                               ; preds = %8
  %14 = getelementptr inbounds i8, ptr %0, i64 328
  %15 = load i32, ptr %14, align 8, !tbaa !11
  %.not = icmp eq i32 %15, 0
  br i1 %.not, label %16, label %.thread

16:                                               ; preds = %13, %8
  %17 = getelementptr inbounds i8, ptr %0, i64 8
  %18 = load i64, ptr %17, align 8, !tbaa !15
  %19 = add i64 %18, -3
  %.not93 = icmp eq i32 %4, 0
  br i1 %.not93, label %30, label %20

20:                                               ; preds = %16
  %21 = tail call ptr @mbedtls_md_info_from_type(i32 noundef %4) #8
  %22 = icmp eq ptr %21, null
  br i1 %22, label %.thread, label %23

23:                                               ; preds = %20
  %24 = call i32 @mbedtls_oid_get_oid_by_md(i32 noundef %4, ptr noundef nonnull %10, ptr noundef nonnull %9) #8
  %.not94 = icmp eq i32 %24, 0
  br i1 %.not94, label %25, label %.thread

25:                                               ; preds = %23
  %26 = load i64, ptr %9, align 8, !tbaa !5
  %.neg101 = add i64 %18, -13
  %27 = sub i64 %.neg101, %26
  %28 = call zeroext i8 @mbedtls_md_get_size(ptr noundef nonnull %21) #8
  %29 = zext i8 %28 to i32
  br label %30

30:                                               ; preds = %25, %16
  %.185 = phi i64 [ %27, %25 ], [ %19, %16 ]
  %.183 = phi i32 [ %29, %25 ], [ %5, %16 ]
  %31 = zext i32 %.183 to i64
  %32 = sub i64 %.185, %31
  %33 = icmp ult i64 %32, 8
  %34 = icmp ugt i64 %32, %18
  %or.cond = select i1 %33, i1 true, i1 %34
  br i1 %or.cond, label %.thread, label %35

35:                                               ; preds = %30
  %36 = getelementptr inbounds i8, ptr %7, i64 1
  store i8 0, ptr %7, align 1, !tbaa !16
  %37 = getelementptr inbounds i8, ptr %7, i64 2
  store i8 1, ptr %36, align 1, !tbaa !16
  call void @llvm.memset.p0.i64(ptr nonnull align 1 %37, i8 -1, i64 %32, i1 false)
  %38 = getelementptr inbounds i8, ptr %37, i64 %32
  %39 = getelementptr inbounds i8, ptr %38, i64 1
  store i8 0, ptr %38, align 1, !tbaa !16
  br i1 %.not93, label %60, label %40

40:                                               ; preds = %35
  %41 = getelementptr inbounds i8, ptr %38, i64 2
  store i8 48, ptr %39, align 1, !tbaa !16
  %42 = load i64, ptr %9, align 8, !tbaa !5
  %43 = add nuw nsw i64 %31, 8
  %44 = add i64 %43, %42
  %45 = trunc i64 %44 to i8
  %46 = getelementptr inbounds i8, ptr %38, i64 3
  store i8 %45, ptr %41, align 1, !tbaa !16
  %47 = getelementptr inbounds i8, ptr %38, i64 4
  store i8 48, ptr %46, align 1, !tbaa !16
  %48 = trunc i64 %42 to i8
  %49 = add i8 %48, 4
  %50 = getelementptr inbounds i8, ptr %38, i64 5
  store i8 %49, ptr %47, align 1, !tbaa !16
  %51 = getelementptr inbounds i8, ptr %38, i64 6
  store i8 6, ptr %50, align 1, !tbaa !16
  %52 = getelementptr inbounds i8, ptr %38, i64 7
  store i8 %48, ptr %51, align 1, !tbaa !16
  %53 = load ptr, ptr %10, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %52, ptr align 1 %53, i64 %42, i1 false)
  %54 = getelementptr inbounds i8, ptr %52, i64 %42
  %55 = getelementptr inbounds i8, ptr %54, i64 1
  store i8 5, ptr %54, align 1, !tbaa !16
  %56 = getelementptr inbounds i8, ptr %54, i64 2
  store i8 0, ptr %55, align 1, !tbaa !16
  %57 = getelementptr inbounds i8, ptr %54, i64 3
  store i8 4, ptr %56, align 1, !tbaa !16
  %58 = trunc i32 %.183 to i8
  %59 = getelementptr inbounds i8, ptr %54, i64 4
  store i8 %58, ptr %57, align 1, !tbaa !16
  br label %60

60:                                               ; preds = %35, %40
  %.sink = phi ptr [ %59, %40 ], [ %39, %35 ]
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %.sink, ptr align 1 %6, i64 %31, i1 false)
  %61 = icmp eq i32 %3, 0
  br i1 %61, label %62, label %64

62:                                               ; preds = %60
  %63 = call i32 @mbedtls_rsa_public(ptr noundef nonnull %0, ptr noundef nonnull %7, ptr noundef nonnull %7)
  br label %.thread

64:                                               ; preds = %60
  %65 = load i64, ptr %17, align 8, !tbaa !15
  %66 = call noalias ptr @calloc(i64 noundef 1, i64 noundef %65) #9
  %67 = icmp eq ptr %66, null
  br i1 %67, label %.thread, label %68

68:                                               ; preds = %64
  %69 = call noalias ptr @calloc(i64 noundef 1, i64 noundef %65) #9
  %70 = icmp eq ptr %69, null
  br i1 %70, label %71, label %72

71:                                               ; preds = %68
  call void @free(ptr noundef nonnull %66) #8
  br label %.thread

72:                                               ; preds = %68
  %73 = call i32 @mbedtls_rsa_private(ptr noundef nonnull %0, ptr noundef %1, ptr noundef %2, ptr noundef nonnull %7, ptr noundef nonnull %66)
  %.not95 = icmp eq i32 %73, 0
  br i1 %.not95, label %74, label %102

74:                                               ; preds = %72
  %75 = call i32 @mbedtls_rsa_public(ptr noundef nonnull %0, ptr noundef nonnull %66, ptr noundef nonnull %69)
  %.not96 = icmp eq i32 %75, 0
  br i1 %.not96, label %.preheader, label %102

.preheader:                                       ; preds = %74
  %76 = load i64, ptr %17, align 8, !tbaa !15
  %.not105 = icmp eq i64 %76, 0
  br i1 %.not105, label %._crit_edge, label %iter.check

iter.check:                                       ; preds = %.preheader
  %min.iters.check = icmp ult i64 %76, 8
  br i1 %min.iters.check, label %.lr.ph.preheader, label %vector.main.loop.iter.check

vector.main.loop.iter.check:                      ; preds = %iter.check
  %min.iters.check106 = icmp ult i64 %76, 32
  br i1 %min.iters.check106, label %vec.epilog.ph, label %vector.ph

vector.ph:                                        ; preds = %vector.main.loop.iter.check
  %n.vec = and i64 %76, -32
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <16 x i8> [ zeroinitializer, %vector.ph ], [ %83, %vector.body ]
  %vec.phi107 = phi <16 x i8> [ zeroinitializer, %vector.ph ], [ %84, %vector.body ]
  %77 = getelementptr inbounds i8, ptr %69, i64 %index
  %78 = getelementptr inbounds i8, ptr %77, i64 16
  %wide.load = load <16 x i8>, ptr %77, align 1, !tbaa !16
  %wide.load108 = load <16 x i8>, ptr %78, align 1, !tbaa !16
  %79 = getelementptr inbounds i8, ptr %7, i64 %index
  %80 = getelementptr inbounds i8, ptr %79, i64 16
  %wide.load109 = load <16 x i8>, ptr %79, align 1, !tbaa !16
  %wide.load110 = load <16 x i8>, ptr %80, align 1, !tbaa !16
  %81 = xor <16 x i8> %wide.load109, %wide.load
  %82 = xor <16 x i8> %wide.load110, %wide.load108
  %83 = or <16 x i8> %81, %vec.phi
  %84 = or <16 x i8> %82, %vec.phi107
  %index.next = add nuw i64 %index, 32
  %85 = icmp eq i64 %index.next, %n.vec
  br i1 %85, label %middle.block, label %vector.body, !llvm.loop !17

middle.block:                                     ; preds = %vector.body
  %bin.rdx = or <16 x i8> %84, %83
  %86 = call i8 @llvm.vector.reduce.or.v16i8(<16 x i8> %bin.rdx)
  %cmp.n = icmp eq i64 %76, %n.vec
  br i1 %cmp.n, label %._crit_edge, label %vec.epilog.iter.check

vec.epilog.iter.check:                            ; preds = %middle.block
  %n.vec.remaining = and i64 %76, 24
  %min.epilog.iters.check = icmp eq i64 %n.vec.remaining, 0
  br i1 %min.epilog.iters.check, label %.lr.ph.preheader, label %vec.epilog.ph

vec.epilog.ph:                                    ; preds = %vector.main.loop.iter.check, %vec.epilog.iter.check
  %bc.merge.rdx = phi i8 [ %86, %vec.epilog.iter.check ], [ 0, %vector.main.loop.iter.check ]
  %vec.epilog.resume.val = phi i64 [ %n.vec, %vec.epilog.iter.check ], [ 0, %vector.main.loop.iter.check ]
  %n.vec112 = and i64 %76, -8
  %87 = insertelement <8 x i8> <i8 poison, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0>, i8 %bc.merge.rdx, i64 0
  br label %vec.epilog.vector.body

vec.epilog.vector.body:                           ; preds = %vec.epilog.vector.body, %vec.epilog.ph
  %index113 = phi i64 [ %vec.epilog.resume.val, %vec.epilog.ph ], [ %index.next117, %vec.epilog.vector.body ]
  %vec.phi114 = phi <8 x i8> [ %87, %vec.epilog.ph ], [ %91, %vec.epilog.vector.body ]
  %88 = getelementptr inbounds i8, ptr %69, i64 %index113
  %wide.load115 = load <8 x i8>, ptr %88, align 1, !tbaa !16
  %89 = getelementptr inbounds i8, ptr %7, i64 %index113
  %wide.load116 = load <8 x i8>, ptr %89, align 1, !tbaa !16
  %90 = xor <8 x i8> %wide.load116, %wide.load115
  %91 = or <8 x i8> %90, %vec.phi114
  %index.next117 = add nuw i64 %index113, 8
  %92 = icmp eq i64 %index.next117, %n.vec112
  br i1 %92, label %vec.epilog.middle.block, label %vec.epilog.vector.body, !llvm.loop !21

vec.epilog.middle.block:                          ; preds = %vec.epilog.vector.body
  %93 = call i8 @llvm.vector.reduce.or.v8i8(<8 x i8> %91)
  %cmp.n118 = icmp eq i64 %76, %n.vec112
  br i1 %cmp.n118, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %vec.epilog.middle.block, %iter.check, %vec.epilog.iter.check
  %.080103.ph = phi i8 [ 0, %iter.check ], [ %86, %vec.epilog.iter.check ], [ %93, %vec.epilog.middle.block ]
  %.081102.ph = phi i64 [ 0, %iter.check ], [ %n.vec, %vec.epilog.iter.check ], [ %n.vec112, %vec.epilog.middle.block ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.080103 = phi i8 [ %99, %.lr.ph ], [ %.080103.ph, %.lr.ph.preheader ]
  %.081102 = phi i64 [ %100, %.lr.ph ], [ %.081102.ph, %.lr.ph.preheader ]
  %94 = getelementptr inbounds i8, ptr %69, i64 %.081102
  %95 = load i8, ptr %94, align 1, !tbaa !16
  %96 = getelementptr inbounds i8, ptr %7, i64 %.081102
  %97 = load i8, ptr %96, align 1, !tbaa !16
  %98 = xor i8 %97, %95
  %99 = or i8 %98, %.080103
  %100 = add nuw i64 %.081102, 1
  %exitcond.not = icmp eq i64 %100, %76
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !22

._crit_edge:                                      ; preds = %.lr.ph, %middle.block, %vec.epilog.middle.block, %.preheader
  %.080.lcssa = phi i8 [ 0, %.preheader ], [ %86, %middle.block ], [ %93, %vec.epilog.middle.block ], [ %99, %.lr.ph ]
  store volatile i8 %.080.lcssa, ptr %11, align 1, !tbaa !16
  %.0..0..0..0.3 = load volatile i8, ptr %11, align 1, !tbaa !16
  %.not97 = icmp eq i8 %.0..0..0..0.3, 0
  br i1 %.not97, label %101, label %102

101:                                              ; preds = %._crit_edge
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %7, ptr nonnull align 1 %66, i64 %76, i1 false)
  br label %102

102:                                              ; preds = %._crit_edge, %74, %72, %101
  %.079 = phi i32 [ %73, %72 ], [ %75, %74 ], [ 0, %101 ], [ -17152, %._crit_edge ]
  call void @free(ptr noundef %66) #8
  call void @free(ptr noundef nonnull %69) #8
  br label %.thread

.thread:                                          ; preds = %23, %20, %64, %30, %13, %102, %71, %62
  %.1 = phi i32 [ %63, %62 ], [ -16, %71 ], [ %.079, %102 ], [ -16512, %13 ], [ -16512, %30 ], [ -16, %64 ], [ -16512, %20 ], [ -16512, %23 ]
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %11)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %10) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %9) #8
  ret i32 %.1
}

declare i32 @mbedtls_oid_get_oid_by_md(i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #5

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #6

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i8 @llvm.vector.reduce.or.v16i8(<16 x i8>) #7

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i8 @llvm.vector.reduce.or.v8i8(<8 x i8>) #7

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #8 = { nounwind }
attributes #9 = { nounwind allocsize(0,1) }

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

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass