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

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

@mKeepLED = external hidden global i32, align 4
@mDataMode = external hidden global i32, align 4
@mRecoverLEDTimer = external hidden global %struct._ETSTIMER_, align 8

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

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

; Function Attrs: nounwind uwtable
define dso_local void @dh_uart_send_str(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load i32, ptr @mDataMode, align 4, !tbaa !9
  %4 = icmp ne i32 %3, 1
  br i1 %4, label %5, label %6

5:                                                ; preds = %1
  br label %24

6:                                                ; preds = %1
  %7 = load i32, ptr @mKeepLED, align 4, !tbaa !9
  %8 = icmp ne i32 %7, 0
  br i1 %8, label %9, label %10

9:                                                ; preds = %6
  call void @ets_timer_disarm(ptr noundef @mRecoverLEDTimer)
  call void @led_off()
  br label %10

10:                                               ; preds = %9, %6
  br label %11

11:                                               ; preds = %15, %10
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = load i8, ptr %12, align 1, !tbaa !11
  %14 = icmp ne i8 %13, 0
  br i1 %14, label %15, label %20

15:                                               ; preds = %11
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %16, i32 1
  store ptr %17, ptr %2, align 8, !tbaa !5
  %18 = load i8, ptr %16, align 1, !tbaa !11
  %19 = sext i8 %18 to i32
  call void @send_char(i32 noundef %19)
  br label %11, !llvm.loop !12

20:                                               ; preds = %11
  %21 = load i32, ptr @mKeepLED, align 4, !tbaa !9
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %24

23:                                               ; preds = %20
  call void @ets_timer_setfn(ptr noundef @mRecoverLEDTimer, ptr noundef @led_recover, ptr noundef null)
  call void @ets_timer_arm_new(ptr noundef @mRecoverLEDTimer, i32 noundef 20, i8 noundef zeroext 0, i8 noundef zeroext 1)
  br label %24

24:                                               ; preds = %23, %20, %5
  ret void
}

declare void @ets_timer_disarm(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden void @send_char(i32 noundef) #0

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

declare void @ets_timer_arm_new(ptr noundef, i32 noundef, i8 noundef zeroext, i8 noundef zeroext) #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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

@mKeepLED = external hidden local_unnamed_addr global i32, align 4
@mDataMode = external hidden local_unnamed_addr global i32, align 4
@mRecoverLEDTimer = external hidden global %struct._ETSTIMER_, align 8

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

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

; Function Attrs: nounwind uwtable
define dso_local void @dh_uart_send_str(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @mDataMode, align 4, !tbaa !5
  %.not = icmp eq i32 %2, 1
  br i1 %.not, label %3, label %14

3:                                                ; preds = %1
  %4 = load i32, ptr @mKeepLED, align 4, !tbaa !5
  %.not3 = icmp eq i32 %4, 0
  br i1 %.not3, label %6, label %5

5:                                                ; preds = %3
  tail call void @ets_timer_disarm(ptr noundef nonnull @mRecoverLEDTimer) #2
  tail call void @led_off()
  br label %6

6:                                                ; preds = %5, %3
  %7 = load i8, ptr %0, align 1, !tbaa !9
  %.not46 = icmp eq i8 %7, 0
  br i1 %.not46, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %6, %.lr.ph
  %8 = phi i8 [ %11, %.lr.ph ], [ %7, %6 ]
  %.07 = phi ptr [ %9, %.lr.ph ], [ %0, %6 ]
  %9 = getelementptr inbounds i8, ptr %.07, i64 1
  %10 = sext i8 %8 to i32
  tail call void @send_char(i32 noundef %10)
  %11 = load i8, ptr %9, align 1, !tbaa !9
  %.not4 = icmp eq i8 %11, 0
  br i1 %.not4, label %._crit_edge, label %.lr.ph, !llvm.loop !10

._crit_edge:                                      ; preds = %.lr.ph, %6
  %12 = load i32, ptr @mKeepLED, align 4, !tbaa !5
  %.not5 = icmp eq i32 %12, 0
  br i1 %.not5, label %14, label %13

13:                                               ; preds = %._crit_edge
  tail call void @ets_timer_setfn(ptr noundef nonnull @mRecoverLEDTimer, ptr noundef nonnull @led_recover, ptr noundef null) #2
  tail call void @ets_timer_arm_new(ptr noundef nonnull @mRecoverLEDTimer, i32 noundef 20, i8 noundef zeroext 0, i8 noundef zeroext 1) #2
  br label %14

14:                                               ; preds = %1, %13, %._crit_edge
  ret void
}

declare void @ets_timer_disarm(ptr noundef) local_unnamed_addr #1

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

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

declare void @ets_timer_arm_new(ptr noundef, i32 noundef, i8 noundef zeroext, i8 noundef zeroext) local_unnamed_addr #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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass