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

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

@mCommands = external hidden constant [12 x %struct.DHCOMMAND], align 16
@.str.2 = external hidden unnamed_addr constant [41 x i8], align 1

declare void @dh_uart_send_line(ptr noundef) #0

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

declare void @dh_uart_send_str(ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local void @dhterminal_commandline_do(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 0
  %8 = load i8, ptr %7, align 1, !tbaa !9
  %9 = sext i8 %8 to i32
  %10 = icmp eq i32 %9, 0
  br i1 %10, label %11, label %12

11:                                               ; preds = %1
  br label %67

12:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !10
  br label %13

13:                                               ; preds = %60, %12
  %14 = load i32, ptr %3, align 4, !tbaa !10
  %15 = sext i32 %14 to i64
  %16 = icmp ult i64 %15, 12
  br i1 %16, label %17, label %63

17:                                               ; preds = %13
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = load i32, ptr %3, align 4, !tbaa !10
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [12 x %struct.DHCOMMAND], ptr @mCommands, i64 0, i64 %20
  %22 = getelementptr inbounds %struct.DHCOMMAND, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !12
  %24 = call i32 @line_containt_command(ptr noundef %18, ptr noundef %23, i32 noundef 1)
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %59

26:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %27, ptr %4, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %40, %26
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = load i8, ptr %29, align 1, !tbaa !9
  %31 = sext i8 %30 to i32
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %33, label %38

33:                                               ; preds = %28
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = load i8, ptr %34, align 1, !tbaa !9
  %36 = sext i8 %35 to i32
  %37 = icmp ne i32 %36, 32
  br label %38

38:                                               ; preds = %33, %28
  %39 = phi i1 [ false, %28 ], [ %37, %33 ]
  br i1 %39, label %40, label %43

40:                                               ; preds = %38
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds i8, ptr %41, i32 1
  store ptr %42, ptr %4, align 8, !tbaa !5
  br label %28, !llvm.loop !14

43:                                               ; preds = %38
  br label %44

44:                                               ; preds = %49, %43
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = load i8, ptr %45, align 1, !tbaa !9
  %47 = sext i8 %46 to i32
  %48 = icmp eq i32 %47, 32
  br i1 %48, label %49, label %52

49:                                               ; preds = %44
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds i8, ptr %50, i32 1
  store ptr %51, ptr %4, align 8, !tbaa !5
  br label %44, !llvm.loop !16

52:                                               ; preds = %44
  %53 = load i32, ptr %3, align 4, !tbaa !10
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [12 x %struct.DHCOMMAND], ptr @mCommands, i64 0, i64 %54
  %56 = getelementptr inbounds %struct.DHCOMMAND, ptr %55, i32 0, i32 2
  %57 = load ptr, ptr %56, align 8, !tbaa !17
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  call void %57(ptr noundef %58)
  store i32 1, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %65

59:                                               ; preds = %17
  br label %60

60:                                               ; preds = %59
  %61 = load i32, ptr %3, align 4, !tbaa !10
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %3, align 4, !tbaa !10
  br label %13, !llvm.loop !18

63:                                               ; preds = %13
  %64 = load ptr, ptr %2, align 8, !tbaa !5
  call void @dh_uart_send_str(ptr noundef %64)
  call void @dh_uart_send_line(ptr noundef @.str.2)
  store i32 0, ptr %5, align 4
  br label %65

65:                                               ; preds = %63, %52
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  %66 = load i32, ptr %5, align 4
  switch i32 %66, label %68 [
    i32 0, label %67
    i32 1, label %67
  ]

67:                                               ; preds = %65, %65, %11
  ret void

68:                                               ; preds = %65
  unreachable
}

attributes #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 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nounwind }

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

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}
!17 = !{!13, !6, i64 16}
!18 = distinct !{!18, !15}


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

@mCommands = external hidden local_unnamed_addr constant [12 x %struct.DHCOMMAND], align 16
@.str.2 = external hidden unnamed_addr constant [41 x i8], align 1

declare void @dh_uart_send_line(ptr noundef) local_unnamed_addr #0

declare void @dh_uart_send_str(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local void @dhterminal_commandline_do(ptr noundef %0) local_unnamed_addr #1 {
  %2 = load i8, ptr %0, align 1, !tbaa !5
  %3 = icmp eq i8 %2, 0
  br i1 %3, label %39, label %.preheader18.preheader

.preheader18.preheader:                           ; preds = %1
  %4 = load ptr, ptr @mCommands, align 16, !tbaa !8
  %5 = tail call i32 @line_containt_command(ptr noundef nonnull %0, ptr noundef %4, i32 noundef 1)
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %.preheader18.1, label %.preheader

.preheader18.1:                                   ; preds = %.preheader18.preheader
  %6 = load ptr, ptr getelementptr inbounds (i8, ptr @mCommands, i64 24), align 8, !tbaa !8
  %7 = tail call i32 @line_containt_command(ptr noundef nonnull %0, ptr noundef %6, i32 noundef 1)
  %.not.1 = icmp eq i32 %7, 0
  br i1 %.not.1, label %.preheader18.2, label %.preheader

.preheader18.2:                                   ; preds = %.preheader18.1
  %8 = load ptr, ptr getelementptr inbounds (i8, ptr @mCommands, i64 48), align 16, !tbaa !8
  %9 = tail call i32 @line_containt_command(ptr noundef nonnull %0, ptr noundef %8, i32 noundef 1)
  %.not.2 = icmp eq i32 %9, 0
  br i1 %.not.2, label %.preheader18.3, label %.preheader

.preheader18.3:                                   ; preds = %.preheader18.2
  %10 = load ptr, ptr getelementptr inbounds (i8, ptr @mCommands, i64 72), align 8, !tbaa !8
  %11 = tail call i32 @line_containt_command(ptr noundef nonnull %0, ptr noundef %10, i32 noundef 1)
  %.not.3 = icmp eq i32 %11, 0
  br i1 %.not.3, label %.preheader18.4, label %.preheader

.preheader18.4:                                   ; preds = %.preheader18.3
  %12 = load ptr, ptr getelementptr inbounds (i8, ptr @mCommands, i64 96), align 16, !tbaa !8
  %13 = tail call i32 @line_containt_command(ptr noundef nonnull %0, ptr noundef %12, i32 noundef 1)
  %.not.4 = icmp eq i32 %13, 0
  br i1 %.not.4, label %.preheader18.5, label %.preheader

.preheader18.5:                                   ; preds = %.preheader18.4
  %14 = load ptr, ptr getelementptr inbounds (i8, ptr @mCommands, i64 120), align 8, !tbaa !8
  %15 = tail call i32 @line_containt_command(ptr noundef nonnull %0, ptr noundef %14, i32 noundef 1)
  %.not.5 = icmp eq i32 %15, 0
  br i1 %.not.5, label %.preheader18.6, label %.preheader

.preheader18.6:                                   ; preds = %.preheader18.5
  %16 = load ptr, ptr getelementptr inbounds (i8, ptr @mCommands, i64 144), align 16, !tbaa !8
  %17 = tail call i32 @line_containt_command(ptr noundef nonnull %0, ptr noundef %16, i32 noundef 1)
  %.not.6 = icmp eq i32 %17, 0
  br i1 %.not.6, label %.preheader18.7, label %.preheader

.preheader18.7:                                   ; preds = %.preheader18.6
  %18 = load ptr, ptr getelementptr inbounds (i8, ptr @mCommands, i64 168), align 8, !tbaa !8
  %19 = tail call i32 @line_containt_command(ptr noundef nonnull %0, ptr noundef %18, i32 noundef 1)
  %.not.7 = icmp eq i32 %19, 0
  br i1 %.not.7, label %.preheader18.8, label %.preheader

.preheader18.8:                                   ; preds = %.preheader18.7
  %20 = load ptr, ptr getelementptr inbounds (i8, ptr @mCommands, i64 192), align 16, !tbaa !8
  %21 = tail call i32 @line_containt_command(ptr noundef nonnull %0, ptr noundef %20, i32 noundef 1)
  %.not.8 = icmp eq i32 %21, 0
  br i1 %.not.8, label %.preheader18.9, label %.preheader

.preheader18.9:                                   ; preds = %.preheader18.8
  %22 = load ptr, ptr getelementptr inbounds (i8, ptr @mCommands, i64 216), align 8, !tbaa !8
  %23 = tail call i32 @line_containt_command(ptr noundef nonnull %0, ptr noundef %22, i32 noundef 1)
  %.not.9 = icmp eq i32 %23, 0
  br i1 %.not.9, label %.preheader18.10, label %.preheader

.preheader18.10:                                  ; preds = %.preheader18.9
  %24 = load ptr, ptr getelementptr inbounds (i8, ptr @mCommands, i64 240), align 16, !tbaa !8
  %25 = tail call i32 @line_containt_command(ptr noundef nonnull %0, ptr noundef %24, i32 noundef 1)
  %.not.10 = icmp eq i32 %25, 0
  br i1 %.not.10, label %.preheader18.11, label %.preheader

.preheader18.11:                                  ; preds = %.preheader18.10
  %26 = load ptr, ptr getelementptr inbounds (i8, ptr @mCommands, i64 264), align 8, !tbaa !8
  %27 = tail call i32 @line_containt_command(ptr noundef nonnull %0, ptr noundef %26, i32 noundef 1)
  %.not.11 = icmp eq i32 %27, 0
  br i1 %.not.11, label %28, label %.preheader

28:                                               ; preds = %.preheader18.11
  tail call void @dh_uart_send_str(ptr noundef nonnull %0) #2
  tail call void @dh_uart_send_line(ptr noundef nonnull @.str.2) #2
  br label %39

.preheader:                                       ; preds = %.preheader18.11, %.preheader18.10, %.preheader18.9, %.preheader18.8, %.preheader18.7, %.preheader18.6, %.preheader18.5, %.preheader18.4, %.preheader18.3, %.preheader18.2, %.preheader18.1, %.preheader18.preheader
  %.lcssa = phi ptr [ @mCommands, %.preheader18.preheader ], [ getelementptr inbounds (i8, ptr @mCommands, i64 24), %.preheader18.1 ], [ getelementptr inbounds (i8, ptr @mCommands, i64 48), %.preheader18.2 ], [ getelementptr inbounds (i8, ptr @mCommands, i64 72), %.preheader18.3 ], [ getelementptr inbounds (i8, ptr @mCommands, i64 96), %.preheader18.4 ], [ getelementptr inbounds (i8, ptr @mCommands, i64 120), %.preheader18.5 ], [ getelementptr inbounds (i8, ptr @mCommands, i64 144), %.preheader18.6 ], [ getelementptr inbounds (i8, ptr @mCommands, i64 168), %.preheader18.7 ], [ getelementptr inbounds (i8, ptr @mCommands, i64 192), %.preheader18.8 ], [ getelementptr inbounds (i8, ptr @mCommands, i64 216), %.preheader18.9 ], [ getelementptr inbounds (i8, ptr @mCommands, i64 240), %.preheader18.10 ], [ getelementptr inbounds (i8, ptr @mCommands, i64 264), %.preheader18.11 ]
  br label %29

29:                                               ; preds = %.preheader, %31
  %.0 = phi ptr [ %32, %31 ], [ %0, %.preheader ]
  %30 = load i8, ptr %.0, align 1, !tbaa !5
  switch i8 %30, label %31 [
    i8 0, label %.critedge.preheader
    i8 32, label %.critedge.preheader
  ]

.critedge.preheader:                              ; preds = %29, %29
  br label %.critedge

31:                                               ; preds = %29
  %32 = getelementptr inbounds i8, ptr %.0, i64 1
  br label %29, !llvm.loop !11

.critedge:                                        ; preds = %.critedge.preheader, %.critedge
  %.1 = phi ptr [ %35, %.critedge ], [ %.0, %.critedge.preheader ]
  %33 = load i8, ptr %.1, align 1, !tbaa !5
  %34 = icmp eq i8 %33, 32
  %35 = getelementptr inbounds i8, ptr %.1, i64 1
  br i1 %34, label %.critedge, label %36, !llvm.loop !13

36:                                               ; preds = %.critedge
  %37 = getelementptr inbounds i8, ptr %.lcssa, i64 16
  %38 = load ptr, ptr %37, align 8, !tbaa !14
  tail call void %38(ptr noundef nonnull %.1) #2
  br label %39

39:                                               ; preds = %36, %28, %1
  ret void
}

attributes #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 = { 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 #2 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !10, i64 0}
!9 = !{!"", !10, i64 0, !10, i64 8, !10, i64 16}
!10 = !{!"any pointer", !6, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = !{!9, !10, i64 16}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass