; LLVM IR from devicehive/esp8266-firmware :: firmware-src/sources (dhterminal)

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

@mRcvBuff = external hidden global [1025 x i8], align 16
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@mRcvBuffPos = external hidden global i32, align 4
@mHistoryBuff = external hidden global [1024 x i8], align 16
@mMode = external hidden global i32, align 4
@mCompleaterCallBack = external hidden global ptr, align 8
@mFilterCallback = external hidden global ptr, align 8
@mInputLimiter = external hidden global i32, align 4
@isInUse = external hidden global i32, align 4
@mUsageTimer = external hidden global %struct._ETSTIMER_, align 8
@dh_uart_char_rcv_cb.lastRecieved = external hidden global i8, align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1
@mEscRecieving = external hidden global i32, align 4
@mEscSequencePos = external hidden global i32, align 4
@mEscSequence = external hidden global [4 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1
@mHistoryScrollBufPos = external hidden global i32, align 4
@mHistoryBuffPos = external hidden global i32, align 4
@mHistoryRcvBuff = external hidden global [78 x i8], align 16
@mHistoryRcvBuffFill = external hidden global i8, align 1
@.str.5 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [2 x i8], align 1

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

declare void @dh_uart_send_str(ptr noundef) #1

declare i32 @snprintf(ptr noundef, i32 noundef, ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
define dso_local void @dh_uart_char_rcv_cb(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca [2 x i8], align 1
  %9 = alloca i8, align 1
  %10 = alloca i8, align 1
  store i32 %0, ptr %2, align 4, !tbaa !5
  store i32 1, ptr @isInUse, align 4, !tbaa !5
  call void @ets_timer_disarm(ptr noundef @mUsageTimer)
  call void @ets_timer_setfn(ptr noundef @mUsageTimer, ptr noundef @usage_timer, ptr noundef null)
  call void @ets_timer_arm_new(ptr noundef @mUsageTimer, i32 noundef 300000, i8 noundef zeroext 0, i8 noundef zeroext 1)
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = icmp eq i32 %11, 10
  br i1 %12, label %13, label %20

13:                                               ; preds = %1
  %14 = load i8, ptr @dh_uart_char_rcv_cb.lastRecieved, align 1, !tbaa !9
  %15 = sext i8 %14 to i32
  %16 = icmp eq i32 %15, 13
  br i1 %16, label %17, label %20

17:                                               ; preds = %13
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = trunc i32 %18 to i8
  store i8 %19, ptr @dh_uart_char_rcv_cb.lastRecieved, align 1, !tbaa !9
  br label %404

20:                                               ; preds = %13, %1
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = trunc i32 %21 to i8
  store i8 %22, ptr @dh_uart_char_rcv_cb.lastRecieved, align 1, !tbaa !9
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = icmp eq i32 %23, 13
  br i1 %24, label %25, label %26

25:                                               ; preds = %20
  store i32 10, ptr %2, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %25, %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %27 = load i32, ptr @mMode, align 4, !tbaa !5
  %28 = icmp eq i32 %27, 1
  br i1 %28, label %35, label %29

29:                                               ; preds = %26
  %30 = load i32, ptr @mMode, align 4, !tbaa !5
  %31 = icmp eq i32 %30, 3
  br i1 %31, label %35, label %32

32:                                               ; preds = %29
  %33 = load i32, ptr @mMode, align 4, !tbaa !5
  %34 = icmp eq i32 %33, 2
  br i1 %34, label %35, label %58

35:                                               ; preds = %32, %29, %26
  %36 = load i32, ptr %2, align 4, !tbaa !5
  %37 = icmp eq i32 %36, 81
  br i1 %37, label %44, label %38

38:                                               ; preds = %35
  %39 = load i32, ptr %2, align 4, !tbaa !5
  %40 = icmp eq i32 %39, 113
  br i1 %40, label %44, label %41

41:                                               ; preds = %38
  %42 = load i32, ptr %2, align 4, !tbaa !5
  %43 = icmp eq i32 %42, 3
  br i1 %43, label %44, label %49

44:                                               ; preds = %41, %38, %35
  %45 = load i32, ptr %2, align 4, !tbaa !5
  %46 = icmp eq i32 %45, 3
  br i1 %46, label %47, label %48

47:                                               ; preds = %44
  call void @dh_uart_send_str(ptr noundef @.str.2)
  br label %48

48:                                               ; preds = %47, %44
  call void @dhterminal_reset()
  br label %57

49:                                               ; preds = %41
  %50 = load i32, ptr %2, align 4, !tbaa !5
  %51 = icmp eq i32 %50, 10
  br i1 %51, label %52, label %56

52:                                               ; preds = %49
  %53 = load i32, ptr @mMode, align 4, !tbaa !5
  %54 = icmp eq i32 %53, 1
  br i1 %54, label %55, label %56

55:                                               ; preds = %52
  call void @dh_uart_send_str(ptr noundef @.str.3)
  br label %56

56:                                               ; preds = %55, %52, %49
  br label %57

57:                                               ; preds = %56, %48
  store i32 1, ptr %4, align 4
  br label %402

58:                                               ; preds = %32
  %59 = load i32, ptr @mEscRecieving, align 4, !tbaa !5
  %60 = icmp ne i32 %59, 0
  br i1 %60, label %61, label %228

61:                                               ; preds = %58
  %62 = load i32, ptr @mEscSequencePos, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = icmp ult i64 %63, 3
  br i1 %64, label %65, label %75

65:                                               ; preds = %61
  %66 = load i32, ptr %2, align 4, !tbaa !5
  %67 = trunc i32 %66 to i8
  %68 = load i32, ptr @mEscSequencePos, align 4, !tbaa !5
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr @mEscSequencePos, align 4, !tbaa !5
  %70 = sext i32 %68 to i64
  %71 = getelementptr inbounds [4 x i8], ptr @mEscSequence, i64 0, i64 %70
  store i8 %67, ptr %71, align 1, !tbaa !9
  %72 = load i32, ptr @mEscSequencePos, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [4 x i8], ptr @mEscSequence, i64 0, i64 %73
  store i8 0, ptr %74, align 1, !tbaa !9
  br label %76

75:                                               ; preds = %61
  store i8 0, ptr @mEscSequence, align 1, !tbaa !9
  br label %76

76:                                               ; preds = %75, %65
  %77 = load i32, ptr @mEscSequencePos, align 4, !tbaa !5
  %78 = icmp sgt i32 %77, 1
  br i1 %78, label %79, label %227

79:                                               ; preds = %76
  %80 = load i32, ptr %2, align 4, !tbaa !5
  %81 = icmp sge i32 %80, 64
  br i1 %81, label %82, label %227

82:                                               ; preds = %79
  %83 = load i32, ptr %2, align 4, !tbaa !5
  %84 = icmp sle i32 %83, 126
  br i1 %84, label %85, label %227

85:                                               ; preds = %82
  store i32 0, ptr @mEscRecieving, align 4, !tbaa !5
  store i32 0, ptr @mEscSequencePos, align 4, !tbaa !5
  %86 = call i32 @ets_strcmp(ptr noundef @mEscSequence, ptr noundef @.str.4)
  %87 = icmp eq i32 %86, 0
  br i1 %87, label %88, label %122

88:                                               ; preds = %85
  %89 = load i32, ptr @mMode, align 4, !tbaa !5
  %90 = icmp eq i32 %89, 0
  br i1 %90, label %91, label %122

91:                                               ; preds = %88
  %92 = load i32, ptr @mHistoryScrollBufPos, align 4, !tbaa !5
  %93 = icmp sgt i32 %92, 1
  br i1 %93, label %94, label %121

94:                                               ; preds = %91
  %95 = load i32, ptr @mHistoryScrollBufPos, align 4, !tbaa !5
  %96 = load i32, ptr @mHistoryBuffPos, align 4, !tbaa !5
  %97 = icmp eq i32 %95, %96
  br i1 %97, label %98, label %100

98:                                               ; preds = %94
  %99 = call i32 (ptr, i32, ptr, ...) @snprintf(ptr noundef @mHistoryRcvBuff, i32 noundef 78, ptr noundef @.str.1, ptr noundef @mRcvBuff)
  store i8 1, ptr @mHistoryRcvBuffFill, align 1, !tbaa !9
  br label %100

100:                                              ; preds = %98, %94
  %101 = load i32, ptr @mHistoryScrollBufPos, align 4, !tbaa !5
  %102 = add nsw i32 %101, -1
  store i32 %102, ptr @mHistoryScrollBufPos, align 4, !tbaa !5
  br label %103

103:                                              ; preds = %116, %100
  %104 = load i32, ptr @mHistoryScrollBufPos, align 4, !tbaa !5
  %105 = sub nsw i32 %104, 1
  %106 = sext i32 %105 to i64
  %107 = getelementptr inbounds [1024 x i8], ptr @mHistoryBuff, i64 0, i64 %106
  %108 = load i8, ptr %107, align 1, !tbaa !9
  %109 = icmp ne i8 %108, 0
  br i1 %109, label %110, label %117

110:                                              ; preds = %103
  %111 = load i32, ptr @mHistoryScrollBufPos, align 4, !tbaa !5
  %112 = add nsw i32 %111, -1
  store i32 %112, ptr @mHistoryScrollBufPos, align 4, !tbaa !5
  %113 = load i32, ptr @mHistoryScrollBufPos, align 4, !tbaa !5
  %114 = icmp eq i32 %113, 0
  br i1 %114, label %115, label %116

115:                                              ; preds = %110
  br label %117

116:                                              ; preds = %110
  br label %103, !llvm.loop !10

117:                                              ; preds = %115, %103
  %118 = load i32, ptr @mHistoryScrollBufPos, align 4, !tbaa !5
  %119 = sext i32 %118 to i64
  %120 = getelementptr inbounds [1024 x i8], ptr @mHistoryBuff, i64 0, i64 %119
  call void @dhterminal_set_input(ptr noundef %120)
  br label %121

121:                                              ; preds = %117, %91
  br label %226

122:                                              ; preds = %88, %85
  %123 = call i32 @ets_strcmp(ptr noundef @mEscSequence, ptr noundef @.str.5)
  %124 = icmp eq i32 %123, 0
  br i1 %124, label %125, label %160

125:                                              ; preds = %122
  %126 = load i32, ptr @mMode, align 4, !tbaa !5
  %127 = icmp eq i32 %126, 0
  br i1 %127, label %128, label %160

128:                                              ; preds = %125
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %129

129:                                              ; preds = %135, %128
  %130 = load i32, ptr @mHistoryScrollBufPos, align 4, !tbaa !5
  %131 = sext i32 %130 to i64
  %132 = getelementptr inbounds [1024 x i8], ptr @mHistoryBuff, i64 0, i64 %131
  %133 = load i8, ptr %132, align 1, !tbaa !9
  %134 = icmp ne i8 %133, 0
  br i1 %134, label %135, label %138

135:                                              ; preds = %129
  %136 = load i32, ptr @mHistoryScrollBufPos, align 4, !tbaa !5
  %137 = add nsw i32 %136, 1
  store i32 %137, ptr @mHistoryScrollBufPos, align 4, !tbaa !5
  store i32 1, ptr %5, align 4, !tbaa !5
  br label %129, !llvm.loop !12

138:                                              ; preds = %129
  %139 = load i32, ptr %5, align 4, !tbaa !5
  %140 = icmp ne i32 %139, 0
  br i1 %140, label %141, label %144

141:                                              ; preds = %138
  %142 = load i32, ptr @mHistoryScrollBufPos, align 4, !tbaa !5
  %143 = add nsw i32 %142, 1
  store i32 %143, ptr @mHistoryScrollBufPos, align 4, !tbaa !5
  br label %144

144:                                              ; preds = %141, %138
  %145 = load i32, ptr @mHistoryScrollBufPos, align 4, !tbaa !5
  %146 = sext i32 %145 to i64
  %147 = getelementptr inbounds [1024 x i8], ptr @mHistoryBuff, i64 0, i64 %146
  %148 = load i8, ptr %147, align 1, !tbaa !9
  %149 = icmp ne i8 %148, 0
  br i1 %149, label %150, label %154

150:                                              ; preds = %144
  %151 = load i32, ptr @mHistoryScrollBufPos, align 4, !tbaa !5
  %152 = sext i32 %151 to i64
  %153 = getelementptr inbounds [1024 x i8], ptr @mHistoryBuff, i64 0, i64 %152
  call void @dhterminal_set_input(ptr noundef %153)
  br label %159

154:                                              ; preds = %144
  %155 = load i8, ptr @mHistoryRcvBuffFill, align 1, !tbaa !9
  %156 = icmp ne i8 %155, 0
  br i1 %156, label %157, label %158

157:                                              ; preds = %154
  call void @dhterminal_set_input(ptr noundef @mHistoryRcvBuff)
  store i8 0, ptr @mHistoryRcvBuffFill, align 1, !tbaa !9
  br label %158

158:                                              ; preds = %157, %154
  br label %159

159:                                              ; preds = %158, %150
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %225

160:                                              ; preds = %125, %122
  %161 = call i32 @ets_strcmp(ptr noundef @mEscSequence, ptr noundef @.str.6)
  %162 = icmp eq i32 %161, 0
  br i1 %162, label %163, label %173

163:                                              ; preds = %160
  %164 = load i32, ptr @mRcvBuffPos, align 4, !tbaa !5
  %165 = sext i32 %164 to i64
  %166 = getelementptr inbounds [1025 x i8], ptr @mRcvBuff, i64 0, i64 %165
  %167 = load i8, ptr %166, align 1, !tbaa !9
  %168 = icmp ne i8 %167, 0
  br i1 %168, label %169, label %172

169:                                              ; preds = %163
  %170 = load i32, ptr @mRcvBuffPos, align 4, !tbaa !5
  %171 = add nsw i32 %170, 1
  store i32 %171, ptr @mRcvBuffPos, align 4, !tbaa !5
  call void @dh_uart_send_str(ptr noundef @.str.7)
  call void @dh_uart_send_str(ptr noundef @mEscSequence)
  br label %172

172:                                              ; preds = %169, %163
  br label %224

173:                                              ; preds = %160
  %174 = call i32 @ets_strcmp(ptr noundef @mEscSequence, ptr noundef @.str.8)
  %175 = icmp eq i32 %174, 0
  br i1 %175, label %176, label %183

176:                                              ; preds = %173
  %177 = load i32, ptr @mRcvBuffPos, align 4, !tbaa !5
  %178 = icmp ne i32 %177, 0
  br i1 %178, label %179, label %182

179:                                              ; preds = %176
  %180 = load i32, ptr @mRcvBuffPos, align 4, !tbaa !5
  %181 = add nsw i32 %180, -1
  store i32 %181, ptr @mRcvBuffPos, align 4, !tbaa !5
  call void @dh_uart_send_str(ptr noundef @.str.7)
  call void @dh_uart_send_str(ptr noundef @mEscSequence)
  br label %182

182:                                              ; preds = %179, %176
  br label %223

183:                                              ; preds = %173
  %184 = call i32 @ets_strcmp(ptr noundef @mEscSequence, ptr noundef @.str.9)
  %185 = icmp eq i32 %184, 0
  br i1 %185, label %186, label %222

186:                                              ; preds = %183
  %187 = load i32, ptr @mRcvBuffPos, align 4, !tbaa !5
  %188 = sext i32 %187 to i64
  %189 = getelementptr inbounds [1025 x i8], ptr @mRcvBuff, i64 0, i64 %188
  %190 = load i8, ptr %189, align 1, !tbaa !9
  %191 = icmp ne i8 %190, 0
  br i1 %191, label %192, label %193

192:                                              ; preds = %186
  call void @dh_uart_send_str(ptr noundef @.str.10)
  br label %193

193:                                              ; preds = %192, %186
  %194 = load i32, ptr @mRcvBuffPos, align 4, !tbaa !5
  %195 = add nsw i32 %194, 1
  store i32 %195, ptr %3, align 4, !tbaa !5
  br label %196

196:                                              ; preds = %218, %193
  %197 = load i32, ptr %3, align 4, !tbaa !5
  %198 = sext i32 %197 to i64
  %199 = icmp ult i64 %198, 1025
  br i1 %199, label %200, label %221

200:                                              ; preds = %196
  %201 = load i32, ptr %3, align 4, !tbaa !5
  %202 = sub nsw i32 %201, 1
  %203 = sext i32 %202 to i64
  %204 = getelementptr inbounds [1025 x i8], ptr @mRcvBuff, i64 0, i64 %203
  %205 = load i8, ptr %204, align 1, !tbaa !9
  %206 = sext i8 %205 to i32
  %207 = icmp eq i32 %206, 0
  br i1 %207, label %208, label %209

208:                                              ; preds = %200
  br label %221

209:                                              ; preds = %200
  %210 = load i32, ptr %3, align 4, !tbaa !5
  %211 = sext i32 %210 to i64
  %212 = getelementptr inbounds [1025 x i8], ptr @mRcvBuff, i64 0, i64 %211
  %213 = load i8, ptr %212, align 1, !tbaa !9
  %214 = load i32, ptr %3, align 4, !tbaa !5
  %215 = sub nsw i32 %214, 1
  %216 = sext i32 %215 to i64
  %217 = getelementptr inbounds [1025 x i8], ptr @mRcvBuff, i64 0, i64 %216
  store i8 %213, ptr %217, align 1, !tbaa !9
  br label %218

218:                                              ; preds = %209
  %219 = load i32, ptr %3, align 4, !tbaa !5
  %220 = add nsw i32 %219, 1
  store i32 %220, ptr %3, align 4, !tbaa !5
  br label %196, !llvm.loop !13

221:                                              ; preds = %208, %196
  br label %222

222:                                              ; preds = %221, %183
  br label %223

223:                                              ; preds = %222, %182
  br label %224

224:                                              ; preds = %223, %172
  br label %225

225:                                              ; preds = %224, %159
  br label %226

226:                                              ; preds = %225, %121
  br label %227

227:                                              ; preds = %226, %82, %79, %76
  store i32 1, ptr %4, align 4
  br label %402

228:                                              ; preds = %58
  %229 = load i32, ptr %2, align 4, !tbaa !5
  %230 = icmp eq i32 %229, 10
  br i1 %230, label %231, label %232

231:                                              ; preds = %228
  call void @dh_uart_send_str(ptr noundef @.str.3)
  call void @do_command(ptr noundef null)
  br label %401

232:                                              ; preds = %228
  %233 = load i32, ptr %2, align 4, !tbaa !5
  %234 = icmp eq i32 %233, 9
  br i1 %234, label %235, label %257

235:                                              ; preds = %232
  %236 = load ptr, ptr @mCompleaterCallBack, align 8, !tbaa !14
  %237 = icmp ne ptr %236, null
  br i1 %237, label %238, label %256

238:                                              ; preds = %235
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store ptr @mRcvBuff, ptr %6, align 8, !tbaa !14
  br label %239

239:                                              ; preds = %244, %238
  %240 = load ptr, ptr %6, align 8, !tbaa !14
  %241 = load i8, ptr %240, align 1, !tbaa !9
  %242 = sext i8 %241 to i32
  %243 = icmp eq i32 %242, 32
  br i1 %243, label %244, label %247

244:                                              ; preds = %239
  %245 = load ptr, ptr %6, align 8, !tbaa !14
  %246 = getelementptr inbounds i8, ptr %245, i32 1
  store ptr %246, ptr %6, align 8, !tbaa !14
  br label %239, !llvm.loop !16

247:                                              ; preds = %239
  %248 = load ptr, ptr @mCompleaterCallBack, align 8, !tbaa !14
  %249 = load ptr, ptr %6, align 8, !tbaa !14
  %250 = call ptr %248(ptr noundef %249)
  store ptr %250, ptr %6, align 8, !tbaa !14
  %251 = load ptr, ptr %6, align 8, !tbaa !14
  %252 = icmp ne ptr %251, null
  br i1 %252, label %253, label %255

253:                                              ; preds = %247
  %254 = load ptr, ptr %6, align 8, !tbaa !14
  call void @dhterminal_set_input(ptr noundef %254)
  br label %255

255:                                              ; preds = %253, %247
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %256

256:                                              ; preds = %255, %235
  br label %400

257:                                              ; preds = %232
  %258 = load i32, ptr %2, align 4, !tbaa !5
  %259 = icmp eq i32 %258, 3
  br i1 %259, label %260, label %261

260:                                              ; preds = %257
  call void @dh_uart_send_str(ptr noundef @.str.2)
  call void @dhterminal_reset()
  br label %399

261:                                              ; preds = %257
  %262 = load i32, ptr %2, align 4, !tbaa !5
  %263 = icmp eq i32 %262, 27
  br i1 %263, label %264, label %265

264:                                              ; preds = %261
  store i32 1, ptr @mEscRecieving, align 4, !tbaa !5
  br label %398

265:                                              ; preds = %261
  %266 = load i32, ptr %2, align 4, !tbaa !5
  %267 = icmp eq i32 %266, 127
  br i1 %267, label %271, label %268

268:                                              ; preds = %265
  %269 = load i32, ptr %2, align 4, !tbaa !5
  %270 = icmp eq i32 %269, 8
  br i1 %270, label %271, label %304

271:                                              ; preds = %268, %265
  %272 = load i32, ptr @mRcvBuffPos, align 4, !tbaa !5
  %273 = icmp eq i32 %272, 0
  br i1 %273, label %274, label %275

274:                                              ; preds = %271
  store i32 1, ptr %4, align 4
  br label %402

275:                                              ; preds = %271
  %276 = load i32, ptr @mRcvBuffPos, align 4, !tbaa !5
  store i32 %276, ptr %3, align 4, !tbaa !5
  br label %277

277:                                              ; preds = %298, %275
  %278 = load i32, ptr %3, align 4, !tbaa !5
  %279 = sext i32 %278 to i64
  %280 = icmp ult i64 %279, 1025
  br i1 %280, label %281, label %301

281:                                              ; preds = %277
  %282 = load i32, ptr %3, align 4, !tbaa !5
  %283 = sext i32 %282 to i64
  %284 = getelementptr inbounds [1025 x i8], ptr @mRcvBuff, i64 0, i64 %283
  %285 = load i8, ptr %284, align 1, !tbaa !9
  %286 = load i32, ptr %3, align 4, !tbaa !5
  %287 = sub nsw i32 %286, 1
  %288 = sext i32 %287 to i64
  %289 = getelementptr inbounds [1025 x i8], ptr @mRcvBuff, i64 0, i64 %288
  store i8 %285, ptr %289, align 1, !tbaa !9
  %290 = load i32, ptr %3, align 4, !tbaa !5
  %291 = sext i32 %290 to i64
  %292 = getelementptr inbounds [1025 x i8], ptr @mRcvBuff, i64 0, i64 %291
  %293 = load i8, ptr %292, align 1, !tbaa !9
  %294 = sext i8 %293 to i32
  %295 = icmp eq i32 %294, 0
  br i1 %295, label %296, label %297

296:                                              ; preds = %281
  br label %301

297:                                              ; preds = %281
  br label %298

298:                                              ; preds = %297
  %299 = load i32, ptr %3, align 4, !tbaa !5
  %300 = add nsw i32 %299, 1
  store i32 %300, ptr %3, align 4, !tbaa !5
  br label %277, !llvm.loop !17

301:                                              ; preds = %296, %277
  %302 = load i32, ptr @mRcvBuffPos, align 4, !tbaa !5
  %303 = add nsw i32 %302, -1
  store i32 %303, ptr @mRcvBuffPos, align 4, !tbaa !5
  call void @dh_uart_send_str(ptr noundef @.str.11)
  br label %397

304:                                              ; preds = %268
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !5
  %305 = load i32, ptr @mInputLimiter, align 4, !tbaa !5
  %306 = icmp eq i32 %305, 1
  br i1 %306, label %307, label %312

307:                                              ; preds = %304
  %308 = load i32, ptr @mRcvBuffPos, align 4, !tbaa !5
  %309 = icmp eq i32 %308, 0
  br i1 %309, label %310, label %311

310:                                              ; preds = %307
  store i32 1, ptr %7, align 4, !tbaa !5
  br label %311

311:                                              ; preds = %310, %307
  br label %326

312:                                              ; preds = %304
  %313 = load i32, ptr @mInputLimiter, align 4, !tbaa !5
  %314 = icmp sgt i32 %313, 1
  br i1 %314, label %315, label %325

315:                                              ; preds = %312
  %316 = load i32, ptr @mInputLimiter, align 4, !tbaa !5
  %317 = sub nsw i32 %316, 2
  %318 = sext i32 %317 to i64
  %319 = getelementptr inbounds [1025 x i8], ptr @mRcvBuff, i64 0, i64 %318
  %320 = load i8, ptr %319, align 1, !tbaa !9
  %321 = sext i8 %320 to i32
  %322 = icmp eq i32 %321, 0
  br i1 %322, label %323, label %324

323:                                              ; preds = %315
  store i32 1, ptr %7, align 4, !tbaa !5
  br label %324

324:                                              ; preds = %323, %315
  br label %325

325:                                              ; preds = %324, %312
  br label %326

326:                                              ; preds = %325, %311
  %327 = load i32, ptr %7, align 4, !tbaa !5
  %328 = icmp ne i32 %327, 0
  br i1 %328, label %329, label %393

329:                                              ; preds = %326
  %330 = load i32, ptr %2, align 4, !tbaa !5
  %331 = icmp sgt i32 %330, 31
  br i1 %331, label %332, label %392

332:                                              ; preds = %329
  %333 = load ptr, ptr @mFilterCallback, align 8, !tbaa !14
  %334 = icmp ne ptr %333, null
  br i1 %334, label %335, label %343

335:                                              ; preds = %332
  %336 = load ptr, ptr @mFilterCallback, align 8, !tbaa !14
  %337 = load i32, ptr %2, align 4, !tbaa !5
  %338 = trunc i32 %337 to i8
  %339 = call i32 %336(i8 noundef signext %338)
  %340 = icmp eq i32 %339, 0
  br i1 %340, label %341, label %342

341:                                              ; preds = %335
  store i32 1, ptr %4, align 4
  br label %394

342:                                              ; preds = %335
  br label %343

343:                                              ; preds = %342, %332
  %344 = load i32, ptr @mRcvBuffPos, align 4, !tbaa !5
  %345 = sext i32 %344 to i64
  %346 = getelementptr inbounds [1025 x i8], ptr @mRcvBuff, i64 0, i64 %345
  %347 = load i8, ptr %346, align 1, !tbaa !9
  %348 = sext i8 %347 to i32
  %349 = icmp ne i32 %348, 0
  br i1 %349, label %350, label %351

350:                                              ; preds = %343
  call void @dh_uart_send_str(ptr noundef @.str.12)
  br label %351

351:                                              ; preds = %350, %343
  %352 = load i32, ptr @mMode, align 4, !tbaa !5
  %353 = icmp eq i32 %352, 5
  br i1 %353, label %354, label %355

354:                                              ; preds = %351
  call void @dh_uart_send_str(ptr noundef @.str.13)
  br label %360

355:                                              ; preds = %351
  call void @llvm.lifetime.start.p0(i64 2, ptr %8) #3
  %356 = load i32, ptr %2, align 4, !tbaa !5
  %357 = trunc i32 %356 to i8
  store i8 %357, ptr %8, align 1, !tbaa !9
  %358 = getelementptr inbounds i8, ptr %8, i64 1
  store i8 0, ptr %358, align 1, !tbaa !9
  %359 = getelementptr inbounds [2 x i8], ptr %8, i64 0, i64 0
  call void @dh_uart_send_str(ptr noundef %359)
  call void @llvm.lifetime.end.p0(i64 2, ptr %8) #3
  br label %360

360:                                              ; preds = %355, %354
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #3
  %361 = load i32, ptr %2, align 4, !tbaa !5
  %362 = trunc i32 %361 to i8
  store i8 %362, ptr %9, align 1, !tbaa !9
  %363 = load i32, ptr @mRcvBuffPos, align 4, !tbaa !5
  store i32 %363, ptr %3, align 4, !tbaa !5
  br label %364

364:                                              ; preds = %386, %360
  %365 = load i32, ptr %3, align 4, !tbaa !5
  %366 = sext i32 %365 to i64
  %367 = icmp ult i64 %366, 1025
  br i1 %367, label %368, label %389

368:                                              ; preds = %364
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #3
  %369 = load i8, ptr %9, align 1, !tbaa !9
  store i8 %369, ptr %10, align 1, !tbaa !9
  %370 = load i32, ptr %3, align 4, !tbaa !5
  %371 = sext i32 %370 to i64
  %372 = getelementptr inbounds [1025 x i8], ptr @mRcvBuff, i64 0, i64 %371
  %373 = load i8, ptr %372, align 1, !tbaa !9
  store i8 %373, ptr %9, align 1, !tbaa !9
  %374 = load i8, ptr %10, align 1, !tbaa !9
  %375 = load i32, ptr %3, align 4, !tbaa !5
  %376 = sext i32 %375 to i64
  %377 = getelementptr inbounds [1025 x i8], ptr @mRcvBuff, i64 0, i64 %376
  store i8 %374, ptr %377, align 1, !tbaa !9
  %378 = load i8, ptr %10, align 1, !tbaa !9
  %379 = sext i8 %378 to i32
  %380 = icmp eq i32 %379, 0
  br i1 %380, label %381, label %382

381:                                              ; preds = %368
  store i32 14, ptr %4, align 4
  br label %383

382:                                              ; preds = %368
  store i32 0, ptr %4, align 4
  br label %383

383:                                              ; preds = %382, %381
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #3
  %384 = load i32, ptr %4, align 4
  switch i32 %384, label %405 [
    i32 0, label %385
    i32 14, label %389
  ]

385:                                              ; preds = %383
  br label %386

386:                                              ; preds = %385
  %387 = load i32, ptr %3, align 4, !tbaa !5
  %388 = add nsw i32 %387, 1
  store i32 %388, ptr %3, align 4, !tbaa !5
  br label %364, !llvm.loop !18

389:                                              ; preds = %383, %364
  %390 = load i32, ptr @mRcvBuffPos, align 4, !tbaa !5
  %391 = add nsw i32 %390, 1
  store i32 %391, ptr @mRcvBuffPos, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #3
  br label %392

392:                                              ; preds = %389, %329
  br label %393

393:                                              ; preds = %392, %326
  store i32 0, ptr %4, align 4
  br label %394

394:                                              ; preds = %393, %341
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  %395 = load i32, ptr %4, align 4
  switch i32 %395, label %402 [
    i32 0, label %396
  ]

396:                                              ; preds = %394
  br label %397

397:                                              ; preds = %396, %301
  br label %398

398:                                              ; preds = %397, %264
  br label %399

399:                                              ; preds = %398, %260
  br label %400

400:                                              ; preds = %399, %256
  br label %401

401:                                              ; preds = %400, %231
  store i32 0, ptr %4, align 4
  br label %402

402:                                              ; preds = %401, %394, %274, %227, %57
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  %403 = load i32, ptr %4, align 4
  switch i32 %403, label %405 [
    i32 0, label %404
    i32 1, label %404
  ]

404:                                              ; preds = %402, %402, %17
  ret void

405:                                              ; preds = %402, %383
  unreachable
}

declare void @ets_timer_disarm(ptr noundef) #1

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

; Function Attrs: nounwind uwtable
declare hidden void @usage_timer(ptr noundef) #0

declare void @ets_timer_arm_new(ptr noundef, i32 noundef, i8 noundef zeroext, i8 noundef zeroext) #1

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

; Function Attrs: nounwind uwtable
declare hidden void @dhterminal_reset() #0

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

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

; Function Attrs: nounwind uwtable
declare hidden void @do_command(ptr 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 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}
!13 = distinct !{!13, !11}
!14 = !{!15, !15, i64 0}
!15 = !{!"any pointer", !7, i64 0}
!16 = distinct !{!16, !11}
!17 = distinct !{!17, !11}
!18 = distinct !{!18, !11}


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

@mRcvBuff = external hidden global [1025 x i8], align 16
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@mRcvBuffPos = external hidden local_unnamed_addr global i32, align 4
@mHistoryBuff = external hidden global [1024 x i8], align 16
@mMode = external hidden local_unnamed_addr global i32, align 4
@mCompleaterCallBack = external hidden local_unnamed_addr global ptr, align 8
@mFilterCallback = external hidden local_unnamed_addr global ptr, align 8
@mInputLimiter = external hidden local_unnamed_addr global i32, align 4
@isInUse = external hidden local_unnamed_addr global i32, align 4
@mUsageTimer = external hidden global %struct._ETSTIMER_, align 8
@dh_uart_char_rcv_cb.lastRecieved = external hidden local_unnamed_addr global i8, align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1
@mEscRecieving = external hidden local_unnamed_addr global i32, align 4
@mEscSequencePos = external hidden local_unnamed_addr global i32, align 4
@mEscSequence = external hidden global [4 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1
@mHistoryScrollBufPos = external hidden local_unnamed_addr global i32, align 4
@mHistoryBuffPos = external hidden local_unnamed_addr global i32, align 4
@mHistoryRcvBuff = external hidden global [78 x i8], align 16
@mHistoryRcvBuffFill = external hidden local_unnamed_addr global i8, align 1
@.str.5 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [2 x i8], align 1

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

declare void @dh_uart_send_str(ptr noundef) local_unnamed_addr #1

declare i32 @snprintf(ptr noundef, i32 noundef, ptr noundef, ...) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @dh_uart_char_rcv_cb(i32 noundef %0) local_unnamed_addr #0 {
  %2 = alloca [2 x i8], align 1
  store i32 1, ptr @isInUse, align 4, !tbaa !5
  tail call void @ets_timer_disarm(ptr noundef nonnull @mUsageTimer) #3
  tail call void @ets_timer_setfn(ptr noundef nonnull @mUsageTimer, ptr noundef nonnull @usage_timer, ptr noundef null) #3
  tail call void @ets_timer_arm_new(ptr noundef nonnull @mUsageTimer, i32 noundef 300000, i8 noundef zeroext 0, i8 noundef zeroext 1) #3
  %3 = icmp eq i32 %0, 10
  %4 = load i8, ptr @dh_uart_char_rcv_cb.lastRecieved, align 1
  %5 = icmp eq i8 %4, 13
  %or.cond = select i1 %3, i1 %5, i1 false
  br i1 %or.cond, label %6, label %7

6:                                                ; preds = %1
  store i8 10, ptr @dh_uart_char_rcv_cb.lastRecieved, align 1, !tbaa !9
  br label %.critedge

7:                                                ; preds = %1
  %8 = trunc i32 %0 to i8
  store i8 %8, ptr @dh_uart_char_rcv_cb.lastRecieved, align 1, !tbaa !9
  %9 = icmp eq i32 %0, 13
  %spec.store.select = select i1 %9, i32 10, i32 %0
  %10 = load i32, ptr @mMode, align 4
  %11 = icmp eq i32 %10, 1
  %12 = add i32 %10, -1
  %or.cond6 = icmp ult i32 %12, 3
  br i1 %or.cond6, label %13, label %19

13:                                               ; preds = %7
  switch i32 %0, label %16 [
    i32 3, label %14
    i32 81, label %15
    i32 113, label %15
  ]

14:                                               ; preds = %13
  tail call void @dh_uart_send_str(ptr noundef nonnull @.str.2) #3
  br label %15

15:                                               ; preds = %13, %13, %14
  tail call void @dhterminal_reset()
  br label %.critedge

16:                                               ; preds = %13
  %17 = icmp eq i32 %spec.store.select, 10
  %or.cond12 = and i1 %17, %11
  br i1 %or.cond12, label %18, label %.critedge

18:                                               ; preds = %16
  tail call void @dh_uart_send_str(ptr noundef nonnull @.str.3) #3
  br label %.critedge

19:                                               ; preds = %7
  %20 = load i32, ptr @mEscRecieving, align 4, !tbaa !5
  %.not = icmp eq i32 %20, 0
  br i1 %.not, label %123, label %21

21:                                               ; preds = %19
  %22 = load i32, ptr @mEscSequencePos, align 4, !tbaa !5
  %23 = icmp ult i32 %22, 3
  br i1 %23, label %24, label %31

24:                                               ; preds = %21
  %25 = zext nneg i32 %22 to i64
  %26 = trunc i32 %spec.store.select to i8
  %27 = add nuw nsw i32 %22, 1
  store i32 %27, ptr @mEscSequencePos, align 4, !tbaa !5
  %28 = getelementptr inbounds [4 x i8], ptr @mEscSequence, i64 0, i64 %25
  store i8 %26, ptr %28, align 1, !tbaa !9
  %29 = zext nneg i32 %27 to i64
  %30 = getelementptr inbounds [4 x i8], ptr @mEscSequence, i64 0, i64 %29
  br label %31

31:                                               ; preds = %21, %24
  %mEscSequence.sink = phi ptr [ %30, %24 ], [ @mEscSequence, %21 ]
  %32 = phi i32 [ %27, %24 ], [ %22, %21 ]
  store i8 0, ptr %mEscSequence.sink, align 1, !tbaa !9
  %33 = icmp sgt i32 %32, 1
  %34 = add i32 %spec.store.select, -64
  %35 = icmp ult i32 %34, 63
  %or.cond16 = and i1 %35, %33
  br i1 %or.cond16, label %36, label %.critedge

36:                                               ; preds = %31
  store i32 0, ptr @mEscRecieving, align 4, !tbaa !5
  store i32 0, ptr @mEscSequencePos, align 4, !tbaa !5
  %37 = tail call i32 @ets_strcmp(ptr noundef nonnull @mEscSequence, ptr noundef nonnull @.str.4) #3
  %38 = icmp eq i32 %37, 0
  %39 = load i32, ptr @mMode, align 4
  %40 = icmp eq i32 %39, 0
  %or.cond18 = select i1 %38, i1 %40, i1 false
  br i1 %or.cond18, label %41, label %63

41:                                               ; preds = %36
  %42 = load i32, ptr @mHistoryScrollBufPos, align 4, !tbaa !5
  %43 = icmp sgt i32 %42, 1
  br i1 %43, label %44, label %.critedge

44:                                               ; preds = %41
  %45 = load i32, ptr @mHistoryBuffPos, align 4, !tbaa !5
  %46 = icmp eq i32 %42, %45
  br i1 %46, label %47, label %49

47:                                               ; preds = %44
  %48 = tail call i32 (ptr, i32, ptr, ...) @snprintf(ptr noundef nonnull @mHistoryRcvBuff, i32 noundef 78, ptr noundef nonnull @.str.1, ptr noundef nonnull @mRcvBuff) #3
  store i8 1, ptr @mHistoryRcvBuffFill, align 1, !tbaa !9
  %.pre144 = load i32, ptr @mHistoryScrollBufPos, align 4, !tbaa !5
  br label %49

49:                                               ; preds = %47, %44
  %50 = phi i32 [ %.pre144, %47 ], [ %42, %44 ]
  %51 = add i32 %50, -1
  store i32 %51, ptr @mHistoryScrollBufPos, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %indvars.iv.next133147 = add nsw i64 %52, -1
  %53 = getelementptr inbounds [1024 x i8], ptr @mHistoryBuff, i64 0, i64 %indvars.iv.next133147
  %54 = load i8, ptr %53, align 1, !tbaa !9
  %.not99148 = icmp eq i8 %54, 0
  br i1 %.not99148, label %._crit_edge, label %.lr.ph150

55:                                               ; preds = %.lr.ph150
  %indvars.iv.next133 = add nsw i64 %indvars.iv.next133149, -1
  %56 = getelementptr inbounds [1024 x i8], ptr @mHistoryBuff, i64 0, i64 %indvars.iv.next133
  %57 = load i8, ptr %56, align 1, !tbaa !9
  %.not99 = icmp eq i8 %57, 0
  br i1 %.not99, label %._crit_edge.loopexit, label %.lr.ph150, !llvm.loop !10

.lr.ph150:                                        ; preds = %49, %55
  %indvars.iv.next133149 = phi i64 [ %indvars.iv.next133, %55 ], [ %indvars.iv.next133147, %49 ]
  %58 = trunc nsw i64 %indvars.iv.next133149 to i32
  %59 = icmp eq i64 %indvars.iv.next133149, 0
  br i1 %59, label %._crit_edge.loopexit, label %55, !llvm.loop !10

._crit_edge.loopexit:                             ; preds = %.lr.ph150, %55
  %.ph = phi i32 [ %58, %55 ], [ 0, %.lr.ph150 ]
  store i32 %58, ptr @mHistoryScrollBufPos, align 4, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %49
  %60 = phi i32 [ %51, %49 ], [ %.ph, %._crit_edge.loopexit ]
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [1024 x i8], ptr @mHistoryBuff, i64 0, i64 %61
  tail call void @dhterminal_set_input(ptr noundef nonnull %62)
  br label %.critedge

63:                                               ; preds = %36
  %64 = tail call i32 @ets_strcmp(ptr noundef nonnull @mEscSequence, ptr noundef nonnull @.str.5) #3
  %65 = icmp eq i32 %64, 0
  %66 = load i32, ptr @mMode, align 4
  %67 = icmp eq i32 %66, 0
  %or.cond20 = select i1 %65, i1 %67, i1 false
  br i1 %or.cond20, label %.preheader103, label %85

.preheader103:                                    ; preds = %63
  %mHistoryScrollBufPos.promoted = load i32, ptr @mHistoryScrollBufPos, align 4, !tbaa !5
  %68 = sext i32 %mHistoryScrollBufPos.promoted to i64
  %69 = getelementptr inbounds [1024 x i8], ptr @mHistoryBuff, i64 0, i64 %68
  %70 = load i8, ptr %69, align 1, !tbaa !9
  %.not95108 = icmp eq i8 %70, 0
  br i1 %.not95108, label %.thread, label %.lr.ph109

.lr.ph109:                                        ; preds = %.preheader103, %.lr.ph109
  %indvars.iv129 = phi i64 [ %indvars.iv.next130, %.lr.ph109 ], [ %68, %.preheader103 ]
  %indvars.iv.next130 = add nsw i64 %indvars.iv129, 1
  %71 = getelementptr inbounds [1024 x i8], ptr @mHistoryBuff, i64 0, i64 %indvars.iv.next130
  %72 = load i8, ptr %71, align 1, !tbaa !9
  %.not95 = icmp eq i8 %72, 0
  br i1 %.not95, label %73, label %.lr.ph109, !llvm.loop !12

73:                                               ; preds = %.lr.ph109
  %74 = trunc nsw i64 %indvars.iv.next130 to i32
  store i32 %74, ptr @mHistoryScrollBufPos, align 4, !tbaa !5
  br i1 %.not95108, label %.thread, label %75

75:                                               ; preds = %73
  %76 = add nsw i32 %74, 1
  store i32 %76, ptr @mHistoryScrollBufPos, align 4, !tbaa !5
  br label %.thread

.thread:                                          ; preds = %.preheader103, %75, %73
  %77 = phi i32 [ %76, %75 ], [ %74, %73 ], [ %mHistoryScrollBufPos.promoted, %.preheader103 ]
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [1024 x i8], ptr @mHistoryBuff, i64 0, i64 %78
  %80 = load i8, ptr %79, align 1, !tbaa !9
  %.not97 = icmp eq i8 %80, 0
  br i1 %.not97, label %82, label %81

81:                                               ; preds = %.thread
  tail call void @dhterminal_set_input(ptr noundef nonnull %79)
  br label %.critedge

82:                                               ; preds = %.thread
  %83 = load i8, ptr @mHistoryRcvBuffFill, align 1, !tbaa !9
  %.not98 = icmp eq i8 %83, 0
  br i1 %.not98, label %.critedge, label %84

84:                                               ; preds = %82
  tail call void @dhterminal_set_input(ptr noundef nonnull @mHistoryRcvBuff)
  store i8 0, ptr @mHistoryRcvBuffFill, align 1, !tbaa !9
  br label %.critedge

85:                                               ; preds = %63
  %86 = tail call i32 @ets_strcmp(ptr noundef nonnull @mEscSequence, ptr noundef nonnull @.str.6) #3
  %87 = icmp eq i32 %86, 0
  br i1 %87, label %88, label %95

88:                                               ; preds = %85
  %89 = load i32, ptr @mRcvBuffPos, align 4, !tbaa !5
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [1025 x i8], ptr @mRcvBuff, i64 0, i64 %90
  %92 = load i8, ptr %91, align 1, !tbaa !9
  %.not94 = icmp eq i8 %92, 0
  br i1 %.not94, label %.critedge, label %93

93:                                               ; preds = %88
  %94 = add nsw i32 %89, 1
  store i32 %94, ptr @mRcvBuffPos, align 4, !tbaa !5
  tail call void @dh_uart_send_str(ptr noundef nonnull @.str.7) #3
  tail call void @dh_uart_send_str(ptr noundef nonnull @mEscSequence) #3
  br label %.critedge

95:                                               ; preds = %85
  %96 = tail call i32 @ets_strcmp(ptr noundef nonnull @mEscSequence, ptr noundef nonnull @.str.8) #3
  %97 = icmp eq i32 %96, 0
  br i1 %97, label %98, label %102

98:                                               ; preds = %95
  %99 = load i32, ptr @mRcvBuffPos, align 4, !tbaa !5
  %.not93 = icmp eq i32 %99, 0
  br i1 %.not93, label %.critedge, label %100

100:                                              ; preds = %98
  %101 = add nsw i32 %99, -1
  store i32 %101, ptr @mRcvBuffPos, align 4, !tbaa !5
  tail call void @dh_uart_send_str(ptr noundef nonnull @.str.7) #3
  tail call void @dh_uart_send_str(ptr noundef nonnull @mEscSequence) #3
  br label %.critedge

102:                                              ; preds = %95
  %103 = tail call i32 @ets_strcmp(ptr noundef nonnull @mEscSequence, ptr noundef nonnull @.str.9) #3
  %104 = icmp eq i32 %103, 0
  br i1 %104, label %105, label %.critedge

105:                                              ; preds = %102
  %106 = load i32, ptr @mRcvBuffPos, align 4, !tbaa !5
  %107 = sext i32 %106 to i64
  %108 = getelementptr inbounds [1025 x i8], ptr @mRcvBuff, i64 0, i64 %107
  %109 = load i8, ptr %108, align 1, !tbaa !9
  %.not92 = icmp eq i8 %109, 0
  br i1 %.not92, label %111, label %110

110:                                              ; preds = %105
  tail call void @dh_uart_send_str(ptr noundef nonnull @.str.10) #3
  %.pre = load i32, ptr @mRcvBuffPos, align 4, !tbaa !5
  br label %111

111:                                              ; preds = %110, %105
  %112 = phi i32 [ %.pre, %110 ], [ %106, %105 ]
  %.075104 = add nsw i32 %112, 1
  %113 = icmp ult i32 %.075104, 1025
  br i1 %113, label %.lr.ph.preheader, label %.critedge

.lr.ph.preheader:                                 ; preds = %111
  %114 = sext i32 %112 to i64
  %115 = add nsw i64 %114, 1
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %119
  %indvars.iv124 = phi i64 [ %114, %.lr.ph.preheader ], [ %indvars.iv.next125, %119 ]
  %indvars.iv = phi i64 [ %115, %.lr.ph.preheader ], [ %indvars.iv.next, %119 ]
  %116 = getelementptr inbounds [1025 x i8], ptr @mRcvBuff, i64 0, i64 %indvars.iv124
  %117 = load i8, ptr %116, align 1, !tbaa !9
  %118 = icmp eq i8 %117, 0
  br i1 %118, label %.critedge, label %119

119:                                              ; preds = %.lr.ph
  %120 = getelementptr inbounds [1025 x i8], ptr @mRcvBuff, i64 0, i64 %indvars.iv
  %121 = load i8, ptr %120, align 1, !tbaa !9
  store i8 %121, ptr %116, align 1, !tbaa !9
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %indvars.iv.next125 = add nsw i64 %indvars.iv124, 1
  %122 = and i64 %indvars.iv.next, 4294967295
  %exitcond.not = icmp eq i64 %122, 1025
  br i1 %exitcond.not, label %.critedge, label %.lr.ph, !llvm.loop !13

123:                                              ; preds = %19
  switch i32 %spec.store.select, label %148 [
    i32 10, label %124
    i32 9, label %125
    i32 3, label %133
    i32 27, label %134
    i32 127, label %135
    i32 8, label %135
  ]

124:                                              ; preds = %123
  tail call void @dh_uart_send_str(ptr noundef nonnull @.str.3) #3
  tail call void @do_command(ptr noundef null)
  br label %.critedge

125:                                              ; preds = %123
  %126 = load ptr, ptr @mCompleaterCallBack, align 8, !tbaa !14
  %.not90 = icmp eq ptr %126, null
  br i1 %.not90, label %.critedge, label %.preheader

.preheader:                                       ; preds = %125, %.preheader
  %.072 = phi ptr [ %129, %.preheader ], [ @mRcvBuff, %125 ]
  %127 = load i8, ptr %.072, align 1, !tbaa !9
  %128 = icmp eq i8 %127, 32
  %129 = getelementptr inbounds i8, ptr %.072, i64 1
  br i1 %128, label %.preheader, label %130, !llvm.loop !16

130:                                              ; preds = %.preheader
  %131 = tail call ptr %126(ptr noundef nonnull %.072) #3
  %.not91 = icmp eq ptr %131, null
  br i1 %.not91, label %.critedge, label %132

132:                                              ; preds = %130
  tail call void @dhterminal_set_input(ptr noundef nonnull %131)
  br label %.critedge

133:                                              ; preds = %123
  tail call void @dh_uart_send_str(ptr noundef nonnull @.str.2) #3
  tail call void @dhterminal_reset()
  br label %.critedge

134:                                              ; preds = %123
  store i32 1, ptr @mEscRecieving, align 4, !tbaa !5
  br label %.critedge

135:                                              ; preds = %123, %123
  %136 = load i32, ptr @mRcvBuffPos, align 4, !tbaa !5
  %137 = icmp eq i32 %136, 0
  br i1 %137, label %.critedge, label %.preheader102

.preheader102:                                    ; preds = %135
  %138 = icmp ult i32 %136, 1025
  br i1 %138, label %.lr.ph114.preheader, label %._crit_edge115

.lr.ph114.preheader:                              ; preds = %.preheader102
  %139 = zext nneg i32 %136 to i64
  br label %.lr.ph114

140:                                              ; preds = %.lr.ph114
  %indvars.iv.next136 = add nuw nsw i64 %indvars.iv135, 1
  %141 = and i64 %indvars.iv.next136, 4294967295
  %exitcond139.not = icmp eq i64 %141, 1025
  br i1 %exitcond139.not, label %._crit_edge115, label %.lr.ph114, !llvm.loop !17

.lr.ph114:                                        ; preds = %.lr.ph114.preheader, %140
  %indvars.iv135 = phi i64 [ %139, %.lr.ph114.preheader ], [ %indvars.iv.next136, %140 ]
  %142 = getelementptr inbounds [1025 x i8], ptr @mRcvBuff, i64 0, i64 %indvars.iv135
  %143 = load i8, ptr %142, align 1, !tbaa !9
  %144 = add nsw i64 %indvars.iv135, -1
  %145 = getelementptr inbounds [1025 x i8], ptr @mRcvBuff, i64 0, i64 %144
  store i8 %143, ptr %145, align 1, !tbaa !9
  %146 = icmp eq i8 %143, 0
  br i1 %146, label %._crit_edge115, label %140

._crit_edge115:                                   ; preds = %140, %.lr.ph114, %.preheader102
  %147 = add nsw i32 %136, -1
  store i32 %147, ptr @mRcvBuffPos, align 4, !tbaa !5
  tail call void @dh_uart_send_str(ptr noundef nonnull @.str.11) #3
  br label %.critedge

148:                                              ; preds = %123
  %149 = load i32, ptr @mInputLimiter, align 4, !tbaa !5
  %150 = icmp eq i32 %149, 1
  br i1 %150, label %151, label %154

151:                                              ; preds = %148
  %152 = load i32, ptr @mRcvBuffPos, align 4, !tbaa !5
  %153 = icmp eq i32 %152, 0
  br label %162

154:                                              ; preds = %148
  %155 = icmp sgt i32 %149, 1
  br i1 %155, label %156, label %.critedge

156:                                              ; preds = %154
  %157 = add nsw i32 %149, -2
  %158 = zext nneg i32 %157 to i64
  %159 = getelementptr inbounds [1025 x i8], ptr @mRcvBuff, i64 0, i64 %158
  %160 = load i8, ptr %159, align 1, !tbaa !9
  %161 = icmp eq i8 %160, 0
  br label %162

162:                                              ; preds = %156, %151
  %163 = phi i1 [ %153, %151 ], [ %161, %156 ]
  %164 = icmp sgt i32 %spec.store.select, 31
  %or.cond24 = and i1 %164, %163
  br i1 %or.cond24, label %165, label %.critedge

165:                                              ; preds = %162
  %166 = load ptr, ptr @mFilterCallback, align 8, !tbaa !14
  %.not88 = icmp eq ptr %166, null
  br i1 %.not88, label %171, label %167

167:                                              ; preds = %165
  %168 = trunc i32 %spec.store.select to i8
  %169 = tail call i32 %166(i8 noundef signext %168) #3
  %170 = icmp eq i32 %169, 0
  br i1 %170, label %.critedge, label %171

171:                                              ; preds = %167, %165
  %172 = load i32, ptr @mRcvBuffPos, align 4, !tbaa !5
  %173 = sext i32 %172 to i64
  %174 = getelementptr inbounds [1025 x i8], ptr @mRcvBuff, i64 0, i64 %173
  %175 = load i8, ptr %174, align 1, !tbaa !9
  %.not89 = icmp eq i8 %175, 0
  br i1 %.not89, label %177, label %176

176:                                              ; preds = %171
  tail call void @dh_uart_send_str(ptr noundef nonnull @.str.12) #3
  br label %177

177:                                              ; preds = %176, %171
  %178 = load i32, ptr @mMode, align 4, !tbaa !5
  %179 = icmp eq i32 %178, 5
  %.pre145 = trunc i32 %spec.store.select to i8
  br i1 %179, label %180, label %181

180:                                              ; preds = %177
  tail call void @dh_uart_send_str(ptr noundef nonnull @.str.13) #3
  br label %183

181:                                              ; preds = %177
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %2) #3
  store i8 %.pre145, ptr %2, align 1, !tbaa !9
  %182 = getelementptr inbounds i8, ptr %2, i64 1
  store i8 0, ptr %182, align 1, !tbaa !9
  call void @dh_uart_send_str(ptr noundef nonnull %2) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %2) #3
  br label %183

183:                                              ; preds = %181, %180
  %184 = load i32, ptr @mRcvBuffPos, align 4, !tbaa !5
  %185 = icmp ult i32 %184, 1025
  br i1 %185, label %.lr.ph120.preheader, label %._crit_edge121

.lr.ph120.preheader:                              ; preds = %183
  %186 = zext nneg i32 %184 to i64
  br label %.lr.ph120

187:                                              ; preds = %.lr.ph120
  %indvars.iv.next141 = add nuw nsw i64 %indvars.iv140, 1
  %188 = and i64 %indvars.iv.next141, 4294967295
  %exitcond143.not = icmp eq i64 %188, 1025
  br i1 %exitcond143.not, label %._crit_edge121, label %.lr.ph120, !llvm.loop !18

.lr.ph120:                                        ; preds = %.lr.ph120.preheader, %187
  %indvars.iv140 = phi i64 [ %186, %.lr.ph120.preheader ], [ %indvars.iv.next141, %187 ]
  %.0118 = phi i8 [ %.pre145, %.lr.ph120.preheader ], [ %190, %187 ]
  %189 = getelementptr inbounds [1025 x i8], ptr @mRcvBuff, i64 0, i64 %indvars.iv140
  %190 = load i8, ptr %189, align 1, !tbaa !9
  store i8 %.0118, ptr %189, align 1, !tbaa !9
  %191 = icmp eq i8 %.0118, 0
  br i1 %191, label %._crit_edge121, label %187

._crit_edge121:                                   ; preds = %187, %.lr.ph120, %183
  %192 = add nsw i32 %184, 1
  store i32 %192, ptr @mRcvBuffPos, align 4, !tbaa !5
  br label %.critedge

.critedge:                                        ; preds = %119, %.lr.ph, %111, %154, %16, %18, %15, %81, %84, %82, %._crit_edge, %41, %93, %88, %102, %98, %100, %31, %135, %._crit_edge121, %162, %130, %132, %125, %134, %._crit_edge115, %133, %124, %167, %6
  ret void
}

declare void @ets_timer_disarm(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare hidden void @usage_timer(ptr noundef) #0

declare void @ets_timer_arm_new(ptr noundef, i32 noundef, i8 noundef zeroext, i8 noundef zeroext) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare hidden void @dhterminal_reset() local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
declare hidden void @do_command(ptr 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 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}
!13 = distinct !{!13, !11}
!14 = !{!15, !15, i64 0}
!15 = !{!"any pointer", !7, i64 0}
!16 = distinct !{!16, !11}
!17 = distinct !{!17, !11}
!18 = distinct !{!18, !11}


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