; 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_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: 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) #0 {
  %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 %struct.mbedtls_mpi, align 8
  %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
  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 24, ptr %16) #3
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  %19 = icmp eq ptr %18, null
  br i1 %19, label %26, label %20

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

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

26:                                               ; preds = %23, %20, %5
  store i32 -16512, ptr %6, align 4
  store i32 1, ptr %17, align 4
  br label %213

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

31:                                               ; preds = %27
  store i32 -16512, ptr %6, align 4
  store i32 1, ptr %17, align 4
  br label %213

32:                                               ; preds = %27
  call void @mbedtls_mpi_init(ptr noundef %13)
  call void @mbedtls_mpi_init(ptr noundef %14)
  call void @mbedtls_mpi_init(ptr noundef %15)
  call void @mbedtls_mpi_init(ptr noundef %16)
  br label %33

33:                                               ; preds = %32
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %34, i32 0, i32 3
  %36 = load i32, ptr %11, align 4, !tbaa !9
  %37 = sext i32 %36 to i64
  %38 = call i32 @mbedtls_mpi_lset(ptr noundef %35, i64 noundef %37)
  store i32 %38, ptr %12, align 4, !tbaa !9
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %41

40:                                               ; preds = %33
  br label %205

41:                                               ; preds = %33
  br label %42

42:                                               ; preds = %41
  br label %43

43:                                               ; preds = %42
  br label %44

44:                                               ; preds = %148, %43
  br label %45

45:                                               ; preds = %44
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %46, i32 0, i32 5
  %48 = load i32, ptr %10, align 4, !tbaa !9
  %49 = lshr i32 %48, 1
  %50 = zext i32 %49 to i64
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = call i32 @mbedtls_mpi_gen_prime(ptr noundef %47, i64 noundef %50, i32 noundef 0, ptr noundef %51, ptr noundef %52)
  store i32 %53, ptr %12, align 4, !tbaa !9
  %54 = icmp ne i32 %53, 0
  br i1 %54, label %55, label %56

55:                                               ; preds = %45
  br label %205

56:                                               ; preds = %45
  br label %57

57:                                               ; preds = %56
  br label %58

58:                                               ; preds = %57
  br label %59

59:                                               ; preds = %58
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %60, i32 0, i32 6
  %62 = load i32, ptr %10, align 4, !tbaa !9
  %63 = lshr i32 %62, 1
  %64 = zext i32 %63 to i64
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  %66 = load ptr, ptr %9, align 8, !tbaa !5
  %67 = call i32 @mbedtls_mpi_gen_prime(ptr noundef %61, i64 noundef %64, i32 noundef 0, ptr noundef %65, ptr noundef %66)
  store i32 %67, ptr %12, align 4, !tbaa !9
  %68 = icmp ne i32 %67, 0
  br i1 %68, label %69, label %70

69:                                               ; preds = %59
  br label %205

70:                                               ; preds = %59
  br label %71

71:                                               ; preds = %70
  br label %72

72:                                               ; preds = %71
  %73 = load ptr, ptr %7, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %73, i32 0, i32 5
  %75 = load ptr, ptr %7, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %75, i32 0, i32 6
  %77 = call i32 @mbedtls_mpi_cmp_mpi(ptr noundef %74, ptr noundef %76)
  %78 = icmp eq i32 %77, 0
  br i1 %78, label %79, label %80

79:                                               ; preds = %72
  br label %148

80:                                               ; preds = %72
  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 2
  %84 = load ptr, ptr %7, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %84, i32 0, i32 5
  %86 = load ptr, ptr %7, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %86, i32 0, i32 6
  %88 = call i32 @mbedtls_mpi_mul_mpi(ptr noundef %83, ptr noundef %85, ptr noundef %87)
  store i32 %88, ptr %12, align 4, !tbaa !9
  %89 = icmp ne i32 %88, 0
  br i1 %89, label %90, label %91

90:                                               ; preds = %81
  br label %205

91:                                               ; preds = %81
  br label %92

92:                                               ; preds = %91
  br label %93

93:                                               ; preds = %92
  %94 = load ptr, ptr %7, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %94, i32 0, i32 2
  %96 = call i64 @mbedtls_mpi_bitlen(ptr noundef %95)
  %97 = load i32, ptr %10, align 4, !tbaa !9
  %98 = zext i32 %97 to i64
  %99 = icmp ne i64 %96, %98
  br i1 %99, label %100, label %101

100:                                              ; preds = %93
  br label %148

101:                                              ; preds = %93
  %102 = load ptr, ptr %7, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %102, i32 0, i32 5
  %104 = load ptr, ptr %7, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %104, i32 0, i32 6
  %106 = call i32 @mbedtls_mpi_cmp_mpi(ptr noundef %103, ptr noundef %105)
  %107 = icmp slt i32 %106, 0
  br i1 %107, label %108, label %113

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

113:                                              ; preds = %108, %101
  br label %114

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

119:                                              ; preds = %114
  br label %205

120:                                              ; preds = %114
  br label %121

121:                                              ; preds = %120
  br label %122

122:                                              ; preds = %121
  br label %123

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

128:                                              ; preds = %123
  br label %205

129:                                              ; preds = %123
  br label %130

130:                                              ; preds = %129
  br label %131

131:                                              ; preds = %130
  br label %132

132:                                              ; preds = %131
  %133 = call i32 @mbedtls_mpi_mul_mpi(ptr noundef %15, ptr noundef %13, ptr noundef %14)
  store i32 %133, ptr %12, align 4, !tbaa !9
  %134 = icmp ne i32 %133, 0
  br i1 %134, label %135, label %136

135:                                              ; preds = %132
  br label %205

136:                                              ; preds = %132
  br label %137

137:                                              ; preds = %136
  br label %138

138:                                              ; preds = %137
  br label %139

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

144:                                              ; preds = %139
  br label %205

145:                                              ; preds = %139
  br label %146

146:                                              ; preds = %145
  br label %147

147:                                              ; preds = %146
  br label %148

148:                                              ; preds = %147, %100, %79
  %149 = call i32 @mbedtls_mpi_cmp_int(ptr noundef %16, i64 noundef 1)
  %150 = icmp ne i32 %149, 0
  br i1 %150, label %44, label %151, !llvm.loop !11

151:                                              ; preds = %148
  br label %152

152:                                              ; preds = %151
  %153 = load ptr, ptr %7, align 8, !tbaa !5
  %154 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %153, i32 0, i32 4
  %155 = load ptr, ptr %7, align 8, !tbaa !5
  %156 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %155, i32 0, i32 3
  %157 = call i32 @mbedtls_mpi_inv_mod(ptr noundef %154, ptr noundef %156, ptr noundef %15)
  store i32 %157, ptr %12, align 4, !tbaa !9
  %158 = icmp ne i32 %157, 0
  br i1 %158, label %159, label %160

159:                                              ; preds = %152
  br label %205

160:                                              ; preds = %152
  br label %161

161:                                              ; preds = %160
  br label %162

162:                                              ; preds = %161
  br label %163

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

170:                                              ; preds = %163
  br label %205

171:                                              ; preds = %163
  br label %172

172:                                              ; preds = %171
  br label %173

173:                                              ; preds = %172
  br label %174

174:                                              ; preds = %173
  %175 = load ptr, ptr %7, align 8, !tbaa !5
  %176 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %175, i32 0, i32 8
  %177 = load ptr, ptr %7, align 8, !tbaa !5
  %178 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %177, i32 0, i32 4
  %179 = call i32 @mbedtls_mpi_mod_mpi(ptr noundef %176, ptr noundef %178, ptr noundef %14)
  store i32 %179, ptr %12, align 4, !tbaa !9
  %180 = icmp ne i32 %179, 0
  br i1 %180, label %181, label %182

181:                                              ; preds = %174
  br label %205

182:                                              ; preds = %174
  br label %183

183:                                              ; preds = %182
  br label %184

184:                                              ; preds = %183
  br label %185

185:                                              ; preds = %184
  %186 = load ptr, ptr %7, align 8, !tbaa !5
  %187 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %186, i32 0, i32 9
  %188 = load ptr, ptr %7, align 8, !tbaa !5
  %189 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %188, i32 0, i32 6
  %190 = load ptr, ptr %7, align 8, !tbaa !5
  %191 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %190, i32 0, i32 5
  %192 = call i32 @mbedtls_mpi_inv_mod(ptr noundef %187, ptr noundef %189, ptr noundef %191)
  store i32 %192, ptr %12, align 4, !tbaa !9
  %193 = icmp ne i32 %192, 0
  br i1 %193, label %194, label %195

194:                                              ; preds = %185
  br label %205

195:                                              ; preds = %185
  br label %196

196:                                              ; preds = %195
  br label %197

197:                                              ; preds = %196
  %198 = load ptr, ptr %7, align 8, !tbaa !5
  %199 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %198, i32 0, i32 2
  %200 = call i64 @mbedtls_mpi_bitlen(ptr noundef %199)
  %201 = add i64 %200, 7
  %202 = lshr i64 %201, 3
  %203 = load ptr, ptr %7, align 8, !tbaa !5
  %204 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %203, i32 0, i32 1
  store i64 %202, ptr %204, align 8, !tbaa !13
  br label %205

205:                                              ; preds = %197, %194, %181, %170, %159, %144, %135, %128, %119, %90, %69, %55, %40
  call void @mbedtls_mpi_free(ptr noundef %13)
  call void @mbedtls_mpi_free(ptr noundef %14)
  call void @mbedtls_mpi_free(ptr noundef %15)
  call void @mbedtls_mpi_free(ptr noundef %16)
  %206 = load i32, ptr %12, align 4, !tbaa !9
  %207 = icmp ne i32 %206, 0
  br i1 %207, label %208, label %212

208:                                              ; preds = %205
  %209 = load ptr, ptr %7, align 8, !tbaa !5
  call void @mbedtls_rsa_free(ptr noundef %209)
  %210 = load i32, ptr %12, align 4, !tbaa !9
  %211 = add nsw i32 -16768, %210
  store i32 %211, ptr %6, align 4
  store i32 1, ptr %17, align 4
  br label %213

212:                                              ; preds = %205
  store i32 0, ptr %6, align 4
  store i32 1, ptr %17, align 4
  br label %213

213:                                              ; preds = %212, %208, %31, %26
  call void @llvm.lifetime.end.p0(i64 24, 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
  %214 = load i32, ptr %6, align 4
  ret i32 %214
}

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

declare void @mbedtls_mpi_init(ptr noundef) #2

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

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

declare i32 @mbedtls_mpi_cmp_mpi(ptr noundef, ptr noundef) #2

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

declare i64 @mbedtls_mpi_bitlen(ptr noundef) #2

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

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

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

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

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

declare i32 @mbedtls_mpi_mod_mpi(ptr noundef, ptr noundef, ptr noundef) #2

declare void @mbedtls_mpi_free(ptr noundef) #2

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

; 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 = { "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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !15, i64 8}
!14 = !{!"", !10, i64 0, !15, i64 8, !16, i64 16, !16, i64 40, !16, i64 64, !16, i64 88, !16, i64 112, !16, i64 136, !16, i64 160, !16, i64 184, !16, i64 208, !16, i64 232, !16, i64 256, !16, i64 280, !16, i64 304, !10, i64 328, !10, i64 332}
!15 = !{!"long", !7, i64 0}
!16 = !{!"", !10, i64 0, !15, i64 8, !6, i64 16}


; 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: 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 #0 {
  %6 = alloca %struct.mbedtls_mpi, align 8
  %7 = alloca %struct.mbedtls_mpi, align 8
  %8 = alloca %struct.mbedtls_mpi, align 8
  %9 = 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
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %9) #3
  %10 = icmp ne ptr %1, null
  %11 = icmp ugt i32 %3, 127
  %or.cond.not81 = and i1 %10, %11
  %12 = icmp sgt i32 %4, 2
  %or.cond3.not78 = and i1 %or.cond.not81, %12
  %13 = and i32 %3, 1
  %.not = icmp eq i32 %13, 0
  %or.cond76 = and i1 %.not, %or.cond3.not78
  br i1 %or.cond76, label %14, label %68

14:                                               ; preds = %5
  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
  call void @mbedtls_mpi_init(ptr noundef nonnull %9) #3
  %15 = getelementptr inbounds i8, ptr %0, i64 40
  %16 = zext nneg i32 %4 to i64
  %17 = call i32 @mbedtls_mpi_lset(ptr noundef nonnull %15, i64 noundef %16) #3
  %.not61 = icmp eq i32 %17, 0
  br i1 %.not61, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %14
  %18 = getelementptr inbounds i8, ptr %0, i64 88
  %19 = lshr exact i32 %3, 1
  %20 = zext nneg i32 %19 to i64
  %21 = getelementptr inbounds i8, ptr %0, i64 112
  %22 = getelementptr inbounds i8, ptr %0, i64 16
  %23 = zext i32 %3 to i64
  br label %24

24:                                               ; preds = %.preheader, %47
  %25 = call i32 @mbedtls_mpi_gen_prime(ptr noundef nonnull %18, i64 noundef %20, i32 noundef 0, ptr noundef nonnull %1, ptr noundef %2) #3
  %.not62 = icmp eq i32 %25, 0
  br i1 %.not62, label %26, label %.loopexit

26:                                               ; preds = %24
  %27 = call i32 @mbedtls_mpi_gen_prime(ptr noundef nonnull %21, i64 noundef %20, i32 noundef 0, ptr noundef nonnull %1, ptr noundef %2) #3
  %.not63 = icmp eq i32 %27, 0
  br i1 %.not63, label %28, label %.loopexit

28:                                               ; preds = %26
  %29 = call i32 @mbedtls_mpi_cmp_mpi(ptr noundef nonnull %18, ptr noundef nonnull %21) #3
  %30 = icmp eq i32 %29, 0
  br i1 %30, label %47, label %31

31:                                               ; preds = %28
  %32 = call i32 @mbedtls_mpi_mul_mpi(ptr noundef nonnull %22, ptr noundef nonnull %18, ptr noundef nonnull %21) #3
  %.not64 = icmp eq i32 %32, 0
  br i1 %.not64, label %33, label %.loopexit

33:                                               ; preds = %31
  %34 = call i64 @mbedtls_mpi_bitlen(ptr noundef nonnull %22) #3
  %.not65 = icmp eq i64 %34, %23
  br i1 %.not65, label %35, label %47

35:                                               ; preds = %33
  %36 = call i32 @mbedtls_mpi_cmp_mpi(ptr noundef nonnull %18, ptr noundef nonnull %21) #3
  %37 = icmp slt i32 %36, 0
  br i1 %37, label %38, label %39

38:                                               ; preds = %35
  call void @mbedtls_mpi_swap(ptr noundef nonnull %18, ptr noundef nonnull %21) #3
  br label %39

39:                                               ; preds = %35, %38
  %40 = call i32 @mbedtls_mpi_sub_int(ptr noundef nonnull %6, ptr noundef nonnull %18, i64 noundef 1) #3
  %.not66 = icmp eq i32 %40, 0
  br i1 %.not66, label %41, label %.loopexit

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

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

45:                                               ; preds = %43
  %46 = call i32 @mbedtls_mpi_gcd(ptr noundef nonnull %9, ptr noundef nonnull %15, ptr noundef nonnull %8) #3
  %.not69 = icmp eq i32 %46, 0
  br i1 %.not69, label %47, label %.loopexit

47:                                               ; preds = %45, %33, %28
  %48 = call i32 @mbedtls_mpi_cmp_int(ptr noundef nonnull %9, i64 noundef 1) #3
  %.not70 = icmp eq i32 %48, 0
  br i1 %.not70, label %49, label %24, !llvm.loop !5

49:                                               ; preds = %47
  %50 = getelementptr inbounds i8, ptr %0, i64 64
  %51 = call i32 @mbedtls_mpi_inv_mod(ptr noundef nonnull %50, ptr noundef nonnull %15, ptr noundef nonnull %8) #3
  %.not71 = icmp eq i32 %51, 0
  br i1 %.not71, label %52, label %.loopexit

52:                                               ; preds = %49
  %53 = getelementptr inbounds i8, ptr %0, i64 136
  %54 = call i32 @mbedtls_mpi_mod_mpi(ptr noundef nonnull %53, ptr noundef nonnull %50, ptr noundef nonnull %6) #3
  %.not72 = icmp eq i32 %54, 0
  br i1 %.not72, label %55, label %.loopexit

55:                                               ; preds = %52
  %56 = getelementptr inbounds i8, ptr %0, i64 160
  %57 = call i32 @mbedtls_mpi_mod_mpi(ptr noundef nonnull %56, ptr noundef nonnull %50, ptr noundef nonnull %7) #3
  %.not73 = icmp eq i32 %57, 0
  br i1 %.not73, label %58, label %.loopexit

58:                                               ; preds = %55
  %59 = getelementptr inbounds i8, ptr %0, i64 184
  %60 = call i32 @mbedtls_mpi_inv_mod(ptr noundef nonnull %59, ptr noundef nonnull %21, ptr noundef nonnull %18) #3
  %.not74 = icmp eq i32 %60, 0
  br i1 %.not74, label %61, label %.loopexit

61:                                               ; preds = %58
  %62 = call i64 @mbedtls_mpi_bitlen(ptr noundef nonnull %22) #3
  %63 = add i64 %62, 7
  %64 = lshr i64 %63, 3
  %65 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 %64, ptr %65, align 8, !tbaa !7
  br label %.loopexit

.loopexit:                                        ; preds = %45, %43, %41, %39, %31, %26, %24, %58, %55, %52, %49, %14, %61
  %.0 = phi i32 [ %17, %14 ], [ %51, %49 ], [ %54, %52 ], [ %57, %55 ], [ %60, %58 ], [ 0, %61 ], [ %46, %45 ], [ %44, %43 ], [ %42, %41 ], [ %40, %39 ], [ %32, %31 ], [ %27, %26 ], [ %25, %24 ]
  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
  call void @mbedtls_mpi_free(ptr noundef nonnull %9) #3
  %.not75 = icmp eq i32 %.0, 0
  br i1 %.not75, label %68, label %66

66:                                               ; preds = %.loopexit
  call void @mbedtls_rsa_free(ptr noundef %0)
  %67 = add nsw i32 %.0, -16768
  br label %68

68:                                               ; preds = %.loopexit, %5, %66
  %.045 = phi i32 [ %67, %66 ], [ -16512, %5 ], [ 0, %.loopexit ]
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %9) #3
  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 %.045
}

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

declare void @mbedtls_mpi_init(ptr noundef) local_unnamed_addr #2

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

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

declare i32 @mbedtls_mpi_cmp_mpi(ptr noundef, ptr noundef) local_unnamed_addr #2

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

declare i64 @mbedtls_mpi_bitlen(ptr noundef) local_unnamed_addr #2

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

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

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

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

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

declare i32 @mbedtls_mpi_mod_mpi(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @mbedtls_mpi_free(ptr noundef) local_unnamed_addr #2

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

; 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 = { "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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !12, i64 8}
!8 = !{!"", !9, i64 0, !12, i64 8, !13, i64 16, !13, i64 40, !13, i64 64, !13, i64 88, !13, i64 112, !13, i64 136, !13, i64 160, !13, i64 184, !13, i64 208, !13, i64 232, !13, i64 256, !13, i64 280, !13, i64 304, !9, i64 328, !9, i64 332}
!9 = !{!"int", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C/C++ TBAA"}
!12 = !{!"long", !10, i64 0}
!13 = !{!"", !9, i64 0, !12, i64 8, !14, i64 16}
!14 = !{!"any pointer", !10, i64 0}


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