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

; 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_timing_hr_time = type { [32 x i8] }
%struct.mbedtls_timing_delay_context = type { %struct.mbedtls_timing_hr_time, i32, i32 }

@mbedtls_timing_alarmed = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [43 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [43 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [70 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [53 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [43 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [43 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i64 @mbedtls_timing_hardclock() #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 i64 @mbedtls_timing_get_timer(ptr noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @mbedtls_set_alarm(i32 noundef) #0

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @mbedtls_timing_get_delay(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @mbedtls_timing_self_test(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca %struct.mbedtls_timing_hr_time, align 1
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca %struct.mbedtls_timing_delay_context, align 4
  %13 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  store i64 0, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store i64 0, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store i64 0, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store i64 0, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 32, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 40, ptr %12) #3
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %16, label %18

16:                                               ; preds = %1
  %17 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  br label %18

18:                                               ; preds = %16, %1
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %21, label %23

21:                                               ; preds = %18
  %22 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  br label %23

23:                                               ; preds = %21, %18
  store i64 1, ptr %7, align 8, !tbaa !9
  %24 = call i64 @mbedtls_timing_get_timer(ptr noundef %9, i32 noundef 1)
  %25 = load i64, ptr %7, align 8, !tbaa !9
  %26 = trunc i64 %25 to i32
  call void @mbedtls_set_alarm(i32 noundef %26)
  br label %27

27:                                               ; preds = %31, %23
  %28 = load volatile i32, ptr @mbedtls_timing_alarmed, align 4, !tbaa !5
  %29 = icmp ne i32 %28, 0
  %30 = xor i1 %29, true
  br i1 %30, label %31, label %32

31:                                               ; preds = %27
  br label %27, !llvm.loop !11

32:                                               ; preds = %27
  %33 = call i64 @mbedtls_timing_get_timer(ptr noundef %9, i32 noundef 0)
  store i64 %33, ptr %6, align 8, !tbaa !9
  %34 = load i64, ptr %6, align 8, !tbaa !9
  %35 = load i64, ptr %7, align 8, !tbaa !9
  %36 = mul i64 800, %35
  %37 = icmp ult i64 %34, %36
  br i1 %37, label %44, label %38

38:                                               ; preds = %32
  %39 = load i64, ptr %6, align 8, !tbaa !9
  %40 = load i64, ptr %7, align 8, !tbaa !9
  %41 = mul i64 1200, %40
  %42 = add i64 %41, 300
  %43 = icmp ugt i64 %39, %42
  br i1 %43, label %44, label %68

44:                                               ; preds = %38, %32
  br label %45

45:                                               ; preds = %44
  %46 = load i32, ptr %3, align 4, !tbaa !5
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %48, label %65

48:                                               ; preds = %45
  %49 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef 447)
  %50 = load i64, ptr %4, align 8, !tbaa !9
  %51 = load i64, ptr %5, align 8, !tbaa !9
  %52 = load i64, ptr %6, align 8, !tbaa !9
  %53 = load i64, ptr %7, align 8, !tbaa !9
  %54 = load i32, ptr %8, align 4, !tbaa !5
  %55 = load i32, ptr %10, align 4, !tbaa !5
  %56 = zext i32 %55 to i64
  %57 = load i32, ptr %11, align 4, !tbaa !5
  %58 = zext i32 %57 to i64
  %59 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i64 noundef %50, i64 noundef %51, i64 noundef %52, i64 noundef %53, i32 noundef %54, i64 noundef %56, i64 noundef %58)
  %60 = call i64 @mbedtls_timing_get_timer(ptr noundef %9, i32 noundef 0)
  %61 = getelementptr inbounds %struct.mbedtls_timing_delay_context, ptr %12, i32 0, i32 0
  %62 = call i64 @mbedtls_timing_get_timer(ptr noundef %61, i32 noundef 0)
  %63 = call i32 @mbedtls_timing_get_delay(ptr noundef %12)
  %64 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i64 noundef %60, i64 noundef %62, i32 noundef %63)
  br label %65

65:                                               ; preds = %48, %45
  store i32 1, ptr %2, align 4
  store i32 1, ptr %13, align 4
  br label %277

66:                                               ; No predecessors!
  br label %67

67:                                               ; preds = %66
  br label %68

68:                                               ; preds = %67, %38
  %69 = load i32, ptr %3, align 4, !tbaa !5
  %70 = icmp ne i32 %69, 0
  br i1 %70, label %71, label %73

71:                                               ; preds = %68
  %72 = call i32 (ptr, ...) @printf(ptr noundef @.str.5)
  br label %73

73:                                               ; preds = %71, %68
  %74 = load i32, ptr %3, align 4, !tbaa !5
  %75 = icmp ne i32 %74, 0
  br i1 %75, label %76, label %78

76:                                               ; preds = %73
  %77 = call i32 (ptr, ...) @printf(ptr noundef @.str.6)
  br label %78

78:                                               ; preds = %76, %73
  store i32 800, ptr %10, align 4, !tbaa !5
  store i32 400, ptr %11, align 4, !tbaa !5
  %79 = load i32, ptr %10, align 4, !tbaa !5
  %80 = load i32, ptr %10, align 4, !tbaa !5
  %81 = load i32, ptr %11, align 4, !tbaa !5
  %82 = add i32 %80, %81
  call void @mbedtls_timing_set_delay(ptr noundef %12, i32 noundef %79, i32 noundef %82)
  %83 = load i32, ptr %10, align 4, !tbaa !5
  %84 = load i32, ptr %10, align 4, !tbaa !5
  %85 = udiv i32 %84, 4
  %86 = sub i32 %83, %85
  %87 = zext i32 %86 to i64
  call void @busy_msleep(i64 noundef %87)
  %88 = call i32 @mbedtls_timing_get_delay(ptr noundef %12)
  %89 = icmp ne i32 %88, 0
  br i1 %89, label %90, label %114

90:                                               ; preds = %78
  br label %91

91:                                               ; preds = %90
  %92 = load i32, ptr %3, align 4, !tbaa !5
  %93 = icmp ne i32 %92, 0
  br i1 %93, label %94, label %111

94:                                               ; preds = %91
  %95 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef 463)
  %96 = load i64, ptr %4, align 8, !tbaa !9
  %97 = load i64, ptr %5, align 8, !tbaa !9
  %98 = load i64, ptr %6, align 8, !tbaa !9
  %99 = load i64, ptr %7, align 8, !tbaa !9
  %100 = load i32, ptr %8, align 4, !tbaa !5
  %101 = load i32, ptr %10, align 4, !tbaa !5
  %102 = zext i32 %101 to i64
  %103 = load i32, ptr %11, align 4, !tbaa !5
  %104 = zext i32 %103 to i64
  %105 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i64 noundef %96, i64 noundef %97, i64 noundef %98, i64 noundef %99, i32 noundef %100, i64 noundef %102, i64 noundef %104)
  %106 = call i64 @mbedtls_timing_get_timer(ptr noundef %9, i32 noundef 0)
  %107 = getelementptr inbounds %struct.mbedtls_timing_delay_context, ptr %12, i32 0, i32 0
  %108 = call i64 @mbedtls_timing_get_timer(ptr noundef %107, i32 noundef 0)
  %109 = call i32 @mbedtls_timing_get_delay(ptr noundef %12)
  %110 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i64 noundef %106, i64 noundef %108, i32 noundef %109)
  br label %111

111:                                              ; preds = %94, %91
  store i32 1, ptr %2, align 4
  store i32 1, ptr %13, align 4
  br label %277

112:                                              ; No predecessors!
  br label %113

113:                                              ; preds = %112
  br label %114

114:                                              ; preds = %113, %78
  %115 = load i32, ptr %10, align 4, !tbaa !5
  %116 = udiv i32 %115, 4
  %117 = load i32, ptr %11, align 4, !tbaa !5
  %118 = udiv i32 %117, 4
  %119 = add i32 %116, %118
  %120 = zext i32 %119 to i64
  call void @busy_msleep(i64 noundef %120)
  %121 = call i32 @mbedtls_timing_get_delay(ptr noundef %12)
  %122 = icmp ne i32 %121, 1
  br i1 %122, label %123, label %147

123:                                              ; preds = %114
  br label %124

124:                                              ; preds = %123
  %125 = load i32, ptr %3, align 4, !tbaa !5
  %126 = icmp ne i32 %125, 0
  br i1 %126, label %127, label %144

127:                                              ; preds = %124
  %128 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef 467)
  %129 = load i64, ptr %4, align 8, !tbaa !9
  %130 = load i64, ptr %5, align 8, !tbaa !9
  %131 = load i64, ptr %6, align 8, !tbaa !9
  %132 = load i64, ptr %7, align 8, !tbaa !9
  %133 = load i32, ptr %8, align 4, !tbaa !5
  %134 = load i32, ptr %10, align 4, !tbaa !5
  %135 = zext i32 %134 to i64
  %136 = load i32, ptr %11, align 4, !tbaa !5
  %137 = zext i32 %136 to i64
  %138 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i64 noundef %129, i64 noundef %130, i64 noundef %131, i64 noundef %132, i32 noundef %133, i64 noundef %135, i64 noundef %137)
  %139 = call i64 @mbedtls_timing_get_timer(ptr noundef %9, i32 noundef 0)
  %140 = getelementptr inbounds %struct.mbedtls_timing_delay_context, ptr %12, i32 0, i32 0
  %141 = call i64 @mbedtls_timing_get_timer(ptr noundef %140, i32 noundef 0)
  %142 = call i32 @mbedtls_timing_get_delay(ptr noundef %12)
  %143 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i64 noundef %139, i64 noundef %141, i32 noundef %142)
  br label %144

144:                                              ; preds = %127, %124
  store i32 1, ptr %2, align 4
  store i32 1, ptr %13, align 4
  br label %277

145:                                              ; No predecessors!
  br label %146

146:                                              ; preds = %145
  br label %147

147:                                              ; preds = %146, %114
  %148 = load i32, ptr %11, align 4, !tbaa !5
  %149 = zext i32 %148 to i64
  call void @busy_msleep(i64 noundef %149)
  %150 = call i32 @mbedtls_timing_get_delay(ptr noundef %12)
  %151 = icmp ne i32 %150, 2
  br i1 %151, label %152, label %176

152:                                              ; preds = %147
  br label %153

153:                                              ; preds = %152
  %154 = load i32, ptr %3, align 4, !tbaa !5
  %155 = icmp ne i32 %154, 0
  br i1 %155, label %156, label %173

156:                                              ; preds = %153
  %157 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef 471)
  %158 = load i64, ptr %4, align 8, !tbaa !9
  %159 = load i64, ptr %5, align 8, !tbaa !9
  %160 = load i64, ptr %6, align 8, !tbaa !9
  %161 = load i64, ptr %7, align 8, !tbaa !9
  %162 = load i32, ptr %8, align 4, !tbaa !5
  %163 = load i32, ptr %10, align 4, !tbaa !5
  %164 = zext i32 %163 to i64
  %165 = load i32, ptr %11, align 4, !tbaa !5
  %166 = zext i32 %165 to i64
  %167 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i64 noundef %158, i64 noundef %159, i64 noundef %160, i64 noundef %161, i32 noundef %162, i64 noundef %164, i64 noundef %166)
  %168 = call i64 @mbedtls_timing_get_timer(ptr noundef %9, i32 noundef 0)
  %169 = getelementptr inbounds %struct.mbedtls_timing_delay_context, ptr %12, i32 0, i32 0
  %170 = call i64 @mbedtls_timing_get_timer(ptr noundef %169, i32 noundef 0)
  %171 = call i32 @mbedtls_timing_get_delay(ptr noundef %12)
  %172 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i64 noundef %168, i64 noundef %170, i32 noundef %171)
  br label %173

173:                                              ; preds = %156, %153
  store i32 1, ptr %2, align 4
  store i32 1, ptr %13, align 4
  br label %277

174:                                              ; No predecessors!
  br label %175

175:                                              ; preds = %174
  br label %176

176:                                              ; preds = %175, %147
  call void @mbedtls_timing_set_delay(ptr noundef %12, i32 noundef 0, i32 noundef 0)
  call void @busy_msleep(i64 noundef 200)
  %177 = call i32 @mbedtls_timing_get_delay(ptr noundef %12)
  %178 = icmp ne i32 %177, -1
  br i1 %178, label %179, label %203

179:                                              ; preds = %176
  br label %180

180:                                              ; preds = %179
  %181 = load i32, ptr %3, align 4, !tbaa !5
  %182 = icmp ne i32 %181, 0
  br i1 %182, label %183, label %200

183:                                              ; preds = %180
  %184 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef 477)
  %185 = load i64, ptr %4, align 8, !tbaa !9
  %186 = load i64, ptr %5, align 8, !tbaa !9
  %187 = load i64, ptr %6, align 8, !tbaa !9
  %188 = load i64, ptr %7, align 8, !tbaa !9
  %189 = load i32, ptr %8, align 4, !tbaa !5
  %190 = load i32, ptr %10, align 4, !tbaa !5
  %191 = zext i32 %190 to i64
  %192 = load i32, ptr %11, align 4, !tbaa !5
  %193 = zext i32 %192 to i64
  %194 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i64 noundef %185, i64 noundef %186, i64 noundef %187, i64 noundef %188, i32 noundef %189, i64 noundef %191, i64 noundef %193)
  %195 = call i64 @mbedtls_timing_get_timer(ptr noundef %9, i32 noundef 0)
  %196 = getelementptr inbounds %struct.mbedtls_timing_delay_context, ptr %12, i32 0, i32 0
  %197 = call i64 @mbedtls_timing_get_timer(ptr noundef %196, i32 noundef 0)
  %198 = call i32 @mbedtls_timing_get_delay(ptr noundef %12)
  %199 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i64 noundef %195, i64 noundef %197, i32 noundef %198)
  br label %200

200:                                              ; preds = %183, %180
  store i32 1, ptr %2, align 4
  store i32 1, ptr %13, align 4
  br label %277

201:                                              ; No predecessors!
  br label %202

202:                                              ; preds = %201
  br label %203

203:                                              ; preds = %202, %176
  %204 = load i32, ptr %3, align 4, !tbaa !5
  %205 = icmp ne i32 %204, 0
  br i1 %205, label %206, label %208

206:                                              ; preds = %203
  %207 = call i32 (ptr, ...) @printf(ptr noundef @.str.5)
  br label %208

208:                                              ; preds = %206, %203
  %209 = load i32, ptr %3, align 4, !tbaa !5
  %210 = icmp ne i32 %209, 0
  br i1 %210, label %211, label %213

211:                                              ; preds = %208
  %212 = call i32 (ptr, ...) @printf(ptr noundef @.str.7)
  br label %213

213:                                              ; preds = %211, %208
  br label %214

214:                                              ; preds = %258, %213
  %215 = load i32, ptr %8, align 4, !tbaa !5
  %216 = icmp sgt i32 %215, 1
  br i1 %216, label %217, label %223

217:                                              ; preds = %214
  %218 = load i32, ptr %3, align 4, !tbaa !5
  %219 = icmp ne i32 %218, 0
  br i1 %219, label %220, label %222

220:                                              ; preds = %217
  %221 = call i32 (ptr, ...) @printf(ptr noundef @.str.8)
  br label %222

222:                                              ; preds = %220, %217
  br label %271

223:                                              ; preds = %214
  store i64 1, ptr %6, align 8, !tbaa !9
  %224 = call i64 @mbedtls_timing_hardclock()
  store i64 %224, ptr %4, align 8, !tbaa !9
  %225 = load i64, ptr %6, align 8, !tbaa !9
  call void @busy_msleep(i64 noundef %225)
  %226 = call i64 @mbedtls_timing_hardclock()
  %227 = load i64, ptr %4, align 8, !tbaa !9
  %228 = sub i64 %226, %227
  store i64 %228, ptr %4, align 8, !tbaa !9
  %229 = load i64, ptr %4, align 8, !tbaa !9
  %230 = load i64, ptr %6, align 8, !tbaa !9
  %231 = udiv i64 %229, %230
  store i64 %231, ptr %5, align 8, !tbaa !9
  store i64 2, ptr %6, align 8, !tbaa !9
  br label %232

232:                                              ; preds = %262, %223
  %233 = load i64, ptr %6, align 8, !tbaa !9
  %234 = icmp ule i64 %233, 4
  br i1 %234, label %235, label %265

235:                                              ; preds = %232
  %236 = call i64 @mbedtls_timing_hardclock()
  store i64 %236, ptr %4, align 8, !tbaa !9
  %237 = load i64, ptr %6, align 8, !tbaa !9
  call void @busy_msleep(i64 noundef %237)
  %238 = call i64 @mbedtls_timing_hardclock()
  %239 = load i64, ptr %4, align 8, !tbaa !9
  %240 = sub i64 %238, %239
  store i64 %240, ptr %4, align 8, !tbaa !9
  %241 = load i64, ptr %4, align 8, !tbaa !9
  %242 = load i64, ptr %6, align 8, !tbaa !9
  %243 = udiv i64 %241, %242
  %244 = load i64, ptr %5, align 8, !tbaa !9
  %245 = load i64, ptr %5, align 8, !tbaa !9
  %246 = udiv i64 %245, 5
  %247 = sub i64 %244, %246
  %248 = icmp ult i64 %243, %247
  br i1 %248, label %258, label %249

249:                                              ; preds = %235
  %250 = load i64, ptr %4, align 8, !tbaa !9
  %251 = load i64, ptr %6, align 8, !tbaa !9
  %252 = udiv i64 %250, %251
  %253 = load i64, ptr %5, align 8, !tbaa !9
  %254 = load i64, ptr %5, align 8, !tbaa !9
  %255 = udiv i64 %254, 5
  %256 = add i64 %253, %255
  %257 = icmp ugt i64 %252, %256
  br i1 %257, label %258, label %261

258:                                              ; preds = %249, %235
  %259 = load i32, ptr %8, align 4, !tbaa !5
  %260 = add nsw i32 %259, 1
  store i32 %260, ptr %8, align 4, !tbaa !5
  br label %214

261:                                              ; preds = %249
  br label %262

262:                                              ; preds = %261
  %263 = load i64, ptr %6, align 8, !tbaa !9
  %264 = add i64 %263, 1
  store i64 %264, ptr %6, align 8, !tbaa !9
  br label %232, !llvm.loop !13

265:                                              ; preds = %232
  %266 = load i32, ptr %3, align 4, !tbaa !5
  %267 = icmp ne i32 %266, 0
  br i1 %267, label %268, label %270

268:                                              ; preds = %265
  %269 = call i32 (ptr, ...) @printf(ptr noundef @.str.5)
  br label %270

270:                                              ; preds = %268, %265
  br label %271

271:                                              ; preds = %270, %222
  %272 = load i32, ptr %3, align 4, !tbaa !5
  %273 = icmp ne i32 %272, 0
  br i1 %273, label %274, label %276

274:                                              ; preds = %271
  %275 = call i32 (ptr, ...) @printf(ptr noundef @.str.9)
  br label %276

276:                                              ; preds = %274, %271
  store i32 0, ptr %2, align 4
  store i32 1, ptr %13, align 4
  br label %277

277:                                              ; preds = %276, %200, %173, %144, %111, %65
  call void @llvm.lifetime.end.p0(i64 40, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %278 = load i32, ptr %2, align 4
  ret i32 %278
}

declare i32 @printf(ptr noundef, ...) #2

; Function Attrs: nounwind uwtable
declare hidden void @busy_msleep(i64 noundef) #0

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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; 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_timing_hr_time = type { [32 x i8] }
%struct.mbedtls_timing_delay_context = type { %struct.mbedtls_timing_hr_time, i32, i32 }

@mbedtls_timing_alarmed = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [43 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [43 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [70 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [53 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [43 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [43 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i64 @mbedtls_timing_hardclock() local_unnamed_addr #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 i64 @mbedtls_timing_get_timer(ptr noundef, i32 noundef) local_unnamed_addr #0

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

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @mbedtls_timing_self_test(i32 noundef %0) local_unnamed_addr #0 {
  %2 = alloca %struct.mbedtls_timing_hr_time, align 1
  %3 = alloca %struct.mbedtls_timing_delay_context, align 4
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %2) #3
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %3) #3
  %.not = icmp eq i32 %0, 0
  br i1 %.not, label %.critedge, label %4

4:                                                ; preds = %1
  %5 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  %6 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %.critedge

.critedge:                                        ; preds = %1, %4
  %7 = call i64 @mbedtls_timing_get_timer(ptr noundef nonnull %2, i32 noundef 1)
  call void @mbedtls_set_alarm(i32 noundef 1)
  br label %8

8:                                                ; preds = %8, %.critedge
  %9 = load volatile i32, ptr @mbedtls_timing_alarmed, align 4, !tbaa !5
  %.not85 = icmp eq i32 %9, 0
  br i1 %.not85, label %8, label %10, !llvm.loop !9

10:                                               ; preds = %8
  %11 = call i64 @mbedtls_timing_get_timer(ptr noundef nonnull %2, i32 noundef 0)
  %12 = add i64 %11, -1501
  %or.cond = icmp ult i64 %12, -701
  br i1 %or.cond, label %13, label %21

13:                                               ; preds = %10
  br i1 %.not, label %.critedge97, label %14

14:                                               ; preds = %13
  %15 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef 447)
  %16 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i64 noundef 0, i64 noundef 0, i64 noundef %11, i64 noundef 1, i32 noundef 0, i64 noundef 0, i64 noundef 0)
  %17 = call i64 @mbedtls_timing_get_timer(ptr noundef nonnull %2, i32 noundef 0)
  %18 = call i64 @mbedtls_timing_get_timer(ptr noundef nonnull %3, i32 noundef 0)
  %19 = call i32 @mbedtls_timing_get_delay(ptr noundef nonnull %3)
  %20 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i64 noundef %17, i64 noundef %18, i32 noundef %19)
  br label %.critedge97

21:                                               ; preds = %10
  br i1 %.not, label %.critedge91, label %22

22:                                               ; preds = %21
  %23 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5)
  %24 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6)
  br label %.critedge91

.critedge91:                                      ; preds = %21, %22
  call void @mbedtls_timing_set_delay(ptr noundef nonnull %3, i32 noundef 800, i32 noundef 1200)
  call void @busy_msleep(i64 noundef 600)
  %25 = call i32 @mbedtls_timing_get_delay(ptr noundef nonnull %3)
  %.not86 = icmp eq i32 %25, 0
  br i1 %.not86, label %34, label %26

26:                                               ; preds = %.critedge91
  br i1 %.not, label %.critedge97, label %27

27:                                               ; preds = %26
  %28 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef 463)
  %29 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i64 noundef 0, i64 noundef 0, i64 noundef %11, i64 noundef 1, i32 noundef 0, i64 noundef 800, i64 noundef 400)
  %30 = call i64 @mbedtls_timing_get_timer(ptr noundef nonnull %2, i32 noundef 0)
  %31 = call i64 @mbedtls_timing_get_timer(ptr noundef nonnull %3, i32 noundef 0)
  %32 = call i32 @mbedtls_timing_get_delay(ptr noundef nonnull %3)
  %33 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i64 noundef %30, i64 noundef %31, i32 noundef %32)
  br label %.critedge97

34:                                               ; preds = %.critedge91
  call void @busy_msleep(i64 noundef 300)
  %35 = call i32 @mbedtls_timing_get_delay(ptr noundef nonnull %3)
  %.not87 = icmp eq i32 %35, 1
  br i1 %.not87, label %44, label %36

36:                                               ; preds = %34
  br i1 %.not, label %.critedge97, label %37

37:                                               ; preds = %36
  %38 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef 467)
  %39 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i64 noundef 0, i64 noundef 0, i64 noundef %11, i64 noundef 1, i32 noundef 0, i64 noundef 800, i64 noundef 400)
  %40 = call i64 @mbedtls_timing_get_timer(ptr noundef nonnull %2, i32 noundef 0)
  %41 = call i64 @mbedtls_timing_get_timer(ptr noundef nonnull %3, i32 noundef 0)
  %42 = call i32 @mbedtls_timing_get_delay(ptr noundef nonnull %3)
  %43 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i64 noundef %40, i64 noundef %41, i32 noundef %42)
  br label %.critedge97

44:                                               ; preds = %34
  call void @busy_msleep(i64 noundef 400)
  %45 = call i32 @mbedtls_timing_get_delay(ptr noundef nonnull %3)
  %.not88 = icmp eq i32 %45, 2
  br i1 %.not88, label %54, label %46

46:                                               ; preds = %44
  br i1 %.not, label %.critedge97, label %47

47:                                               ; preds = %46
  %48 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef 471)
  %49 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i64 noundef 0, i64 noundef 0, i64 noundef %11, i64 noundef 1, i32 noundef 0, i64 noundef 800, i64 noundef 400)
  %50 = call i64 @mbedtls_timing_get_timer(ptr noundef nonnull %2, i32 noundef 0)
  %51 = call i64 @mbedtls_timing_get_timer(ptr noundef nonnull %3, i32 noundef 0)
  %52 = call i32 @mbedtls_timing_get_delay(ptr noundef nonnull %3)
  %53 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i64 noundef %50, i64 noundef %51, i32 noundef %52)
  br label %.critedge97

54:                                               ; preds = %44
  call void @mbedtls_timing_set_delay(ptr noundef nonnull %3, i32 noundef 0, i32 noundef 0)
  call void @busy_msleep(i64 noundef 200)
  %55 = call i32 @mbedtls_timing_get_delay(ptr noundef nonnull %3)
  %.not89 = icmp eq i32 %55, -1
  br i1 %.not89, label %64, label %56

56:                                               ; preds = %54
  br i1 %.not, label %.critedge97, label %57

57:                                               ; preds = %56
  %58 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef 477)
  %59 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i64 noundef 0, i64 noundef 0, i64 noundef %11, i64 noundef 1, i32 noundef 0, i64 noundef 800, i64 noundef 400)
  %60 = call i64 @mbedtls_timing_get_timer(ptr noundef nonnull %2, i32 noundef 0)
  %61 = call i64 @mbedtls_timing_get_timer(ptr noundef nonnull %3, i32 noundef 0)
  %62 = call i32 @mbedtls_timing_get_delay(ptr noundef nonnull %3)
  %63 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i64 noundef %60, i64 noundef %61, i32 noundef %62)
  br label %.critedge97

64:                                               ; preds = %54
  br i1 %.not, label %.critedge93, label %65

65:                                               ; preds = %64
  %66 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5)
  %67 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7)
  br label %.critedge93

.critedge93:                                      ; preds = %64, %65
  %68 = call i64 @mbedtls_timing_hardclock()
  call void @busy_msleep(i64 noundef 1)
  %69 = call i64 @mbedtls_timing_hardclock()
  %70 = sub i64 %69, %68
  %71 = udiv i64 %70, 5
  %72 = sub i64 %70, %71
  %73 = add i64 %71, %70
  %74 = call i64 @mbedtls_timing_hardclock()
  call void @busy_msleep(i64 noundef 2)
  %75 = call i64 @mbedtls_timing_hardclock()
  %76 = sub i64 %75, %74
  %77 = lshr i64 %76, 1
  %78 = icmp ult i64 %77, %72
  %79 = icmp ugt i64 %77, %73
  %or.cond95 = or i1 %78, %79
  br i1 %or.cond95, label %95, label %80

80:                                               ; preds = %.critedge93
  %81 = call i64 @mbedtls_timing_hardclock()
  call void @busy_msleep(i64 noundef 3)
  %82 = call i64 @mbedtls_timing_hardclock()
  %83 = sub i64 %82, %81
  %84 = udiv i64 %83, 3
  %85 = icmp ult i64 %84, %72
  %86 = icmp ugt i64 %84, %73
  %or.cond95.1 = or i1 %85, %86
  br i1 %or.cond95.1, label %95, label %87

87:                                               ; preds = %80
  %88 = call i64 @mbedtls_timing_hardclock()
  call void @busy_msleep(i64 noundef 4)
  %89 = call i64 @mbedtls_timing_hardclock()
  %90 = sub i64 %89, %88
  %91 = lshr i64 %90, 2
  %92 = icmp ult i64 %91, %72
  %93 = icmp ugt i64 %91, %73
  %or.cond95.2 = or i1 %92, %93
  br i1 %or.cond95.2, label %95, label %94

94:                                               ; preds = %115, %87
  br i1 %.not, label %.critedge97, label %123

95:                                               ; preds = %87, %80, %.critedge93
  %96 = call i64 @mbedtls_timing_hardclock()
  call void @busy_msleep(i64 noundef 1)
  %97 = call i64 @mbedtls_timing_hardclock()
  %98 = sub i64 %97, %96
  %99 = udiv i64 %98, 5
  %100 = sub i64 %98, %99
  %101 = add i64 %99, %98
  %102 = call i64 @mbedtls_timing_hardclock()
  call void @busy_msleep(i64 noundef 2)
  %103 = call i64 @mbedtls_timing_hardclock()
  %104 = sub i64 %103, %102
  %105 = lshr i64 %104, 1
  %106 = icmp ult i64 %105, %100
  %107 = icmp ugt i64 %105, %101
  %or.cond95.1101 = or i1 %106, %107
  br i1 %or.cond95.1101, label %122, label %108

108:                                              ; preds = %95
  %109 = call i64 @mbedtls_timing_hardclock()
  call void @busy_msleep(i64 noundef 3)
  %110 = call i64 @mbedtls_timing_hardclock()
  %111 = sub i64 %110, %109
  %112 = udiv i64 %111, 3
  %113 = icmp ult i64 %112, %100
  %114 = icmp ugt i64 %112, %101
  %or.cond95.1.1 = or i1 %113, %114
  br i1 %or.cond95.1.1, label %122, label %115

115:                                              ; preds = %108
  %116 = call i64 @mbedtls_timing_hardclock()
  call void @busy_msleep(i64 noundef 4)
  %117 = call i64 @mbedtls_timing_hardclock()
  %118 = sub i64 %117, %116
  %119 = lshr i64 %118, 2
  %120 = icmp ult i64 %119, %100
  %121 = icmp ugt i64 %119, %101
  %or.cond95.2.1 = or i1 %120, %121
  br i1 %or.cond95.2.1, label %122, label %94

122:                                              ; preds = %115, %108, %95
  br i1 %.not, label %.critedge97, label %123

123:                                              ; preds = %94, %122
  %.str.8.sink = phi ptr [ @.str.8, %122 ], [ @.str.5, %94 ]
  %124 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.8.sink)
  %125 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.9)
  br label %.critedge97

.critedge97:                                      ; preds = %123, %122, %94, %56, %57, %46, %47, %36, %37, %26, %27, %13, %14
  %.082 = phi i32 [ 1, %14 ], [ 1, %13 ], [ 1, %27 ], [ 1, %26 ], [ 1, %37 ], [ 1, %36 ], [ 1, %47 ], [ 1, %46 ], [ 1, %57 ], [ 1, %56 ], [ 0, %94 ], [ 0, %122 ], [ 0, %123 ]
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %2) #3
  ret i32 %.082
}

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden void @busy_msleep(i64 noundef) local_unnamed_addr #0

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nofree nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass