; 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"

@mMode = external hidden global i32, align 4
@mInputCallBack = external hidden global ptr, align 8
@mCompleaterCallBack = external hidden global ptr, align 8
@mFilterCallback = external hidden global ptr, align 8
@mInputLimiter = external hidden global i32, align 4

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

; Function Attrs: nounwind uwtable
define dso_local void @dhterminal_set_mode(i32 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i32 noundef %4) #0 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store i32 %0, ptr %6, align 4, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !9
  store i32 %4, ptr %10, align 4, !tbaa !5
  %11 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %11, ptr @mMode, align 4, !tbaa !5
  %12 = load i32, ptr %6, align 4, !tbaa !5
  %13 = icmp eq i32 %12, 1
  %14 = zext i1 %13 to i64
  %15 = select i1 %13, i32 1, i32 0
  %16 = trunc i32 %15 to i8
  call void @system_set_os_print(i8 noundef zeroext %16)
  %17 = load i32, ptr @mMode, align 4, !tbaa !5
  %18 = icmp ne i32 %17, 2
  br i1 %18, label %19, label %20

19:                                               ; preds = %5
  call void @printWelcome()
  br label %20

20:                                               ; preds = %19, %5
  %21 = load i32, ptr @mMode, align 4, !tbaa !5
  %22 = icmp eq i32 %21, 4
  br i1 %22, label %26, label %23

23:                                               ; preds = %20
  %24 = load i32, ptr @mMode, align 4, !tbaa !5
  %25 = icmp eq i32 %24, 5
  br i1 %25, label %26, label %40

26:                                               ; preds = %23, %20
  %27 = load ptr, ptr %7, align 8, !tbaa !9
  store ptr %27, ptr @mInputCallBack, align 8, !tbaa !9
  %28 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %28, ptr @mCompleaterCallBack, align 8, !tbaa !9
  %29 = load ptr, ptr %9, align 8, !tbaa !9
  store ptr %29, ptr @mFilterCallback, align 8, !tbaa !9
  %30 = load i32, ptr %10, align 4, !tbaa !5
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %38

32:                                               ; preds = %26
  %33 = load i32, ptr %10, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = icmp ule i64 %34, 1025
  br i1 %35, label %36, label %38

36:                                               ; preds = %32
  %37 = load i32, ptr %10, align 4, !tbaa !5
  store i32 %37, ptr @mInputLimiter, align 4, !tbaa !5
  br label %39

38:                                               ; preds = %32, %26
  store i32 78, ptr @mInputLimiter, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %38, %36
  br label %41

40:                                               ; preds = %23
  store ptr @dhterminal_commandline_do, ptr @mInputCallBack, align 8, !tbaa !9
  store ptr @dhterminal_commandline_autocompleter, ptr @mCompleaterCallBack, align 8, !tbaa !9
  store ptr null, ptr @mFilterCallback, align 8, !tbaa !9
  store i32 78, ptr @mInputLimiter, align 4, !tbaa !5
  br label %41

41:                                               ; preds = %40, %39
  ret void
}

declare void @system_set_os_print(i8 noundef zeroext) #1

declare void @dhterminal_commandline_do(ptr noundef) #1

declare ptr @dhterminal_commandline_autocompleter(ptr noundef) #1

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

!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 = !{!"any pointer", !7, i64 0}


; 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"

@mMode = external hidden local_unnamed_addr global i32, align 4
@mInputCallBack = external hidden local_unnamed_addr global ptr, align 8
@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

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

; Function Attrs: nounwind uwtable
define dso_local void @dhterminal_set_mode(i32 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  store i32 %0, ptr @mMode, align 4, !tbaa !5
  %6 = icmp eq i32 %0, 1
  %7 = zext i1 %6 to i8
  tail call void @system_set_os_print(i8 noundef zeroext %7) #2
  %8 = load i32, ptr @mMode, align 4
  %.not = icmp eq i32 %8, 2
  br i1 %.not, label %.thread, label %9

9:                                                ; preds = %5
  tail call void @printWelcome()
  %.pre = load i32, ptr @mMode, align 4
  %10 = and i32 %.pre, -2
  %11 = icmp eq i32 %10, 4
  br i1 %11, label %12, label %.thread

12:                                               ; preds = %9
  store ptr %1, ptr @mInputCallBack, align 8, !tbaa !9
  store ptr %2, ptr @mCompleaterCallBack, align 8, !tbaa !9
  store ptr %3, ptr @mFilterCallback, align 8, !tbaa !9
  %13 = add i32 %4, -1
  %or.cond4 = icmp ult i32 %13, 1025
  %. = select i1 %or.cond4, i32 %4, i32 78
  br label %14

.thread:                                          ; preds = %5, %9
  store ptr @dhterminal_commandline_do, ptr @mInputCallBack, align 8, !tbaa !9
  store ptr @dhterminal_commandline_autocompleter, ptr @mCompleaterCallBack, align 8, !tbaa !9
  store ptr null, ptr @mFilterCallback, align 8, !tbaa !9
  br label %14

14:                                               ; preds = %12, %.thread
  %.sink = phi i32 [ 78, %.thread ], [ %., %12 ]
  store i32 %.sink, ptr @mInputLimiter, align 4, !tbaa !5
  ret void
}

declare void @system_set_os_print(i8 noundef zeroext) local_unnamed_addr #1

declare void @dhterminal_commandline_do(ptr noundef) #1

declare ptr @dhterminal_commandline_autocompleter(ptr noundef) #1

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { "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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InstCombinePass,JumpThreadingPass,SROAPass,SimplifyCFGPass,TailCallElimPass