; LLVM IR from lyg09270/TinyCmd :: Demo/Arduino/ATMEGA328P (TinyCmd)

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

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

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

; Function Attrs: nounwind uwtable
declare hidden zeroext i8 @TinyCmd_strlen(ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @dtoa(double noundef %0, ptr noundef %1, i32 noundef %2) #1 {
  %4 = alloca double, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca double, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store double %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %12 = load double, ptr %4, align 8, !tbaa !5
  %13 = fptosi double %12 to i32
  store i32 %13, ptr %7, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %14 = load double, ptr %4, align 8, !tbaa !5
  %15 = load i32, ptr %7, align 4, !tbaa !11
  %16 = sitofp i32 %15 to double
  %17 = fsub double %14, %16
  store double %17, ptr %8, align 8, !tbaa !5
  %18 = load i32, ptr %7, align 4, !tbaa !11
  %19 = load ptr, ptr %5, align 8, !tbaa !9
  call void @itoa(i32 noundef %18, ptr noundef %19, i32 noundef 10)
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %20 = load ptr, ptr %5, align 8, !tbaa !9
  %21 = load ptr, ptr %5, align 8, !tbaa !9
  %22 = call zeroext i8 @TinyCmd_strlen(ptr noundef %21)
  %23 = zext i8 %22 to i32
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds i8, ptr %20, i64 %24
  store ptr %25, ptr %9, align 8, !tbaa !9
  %26 = load ptr, ptr %9, align 8, !tbaa !9
  %27 = getelementptr inbounds i8, ptr %26, i32 1
  store ptr %27, ptr %9, align 8, !tbaa !9
  store i8 46, ptr %26, align 1, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  store i32 0, ptr %10, align 4, !tbaa !11
  br label %28

28:                                               ; preds = %47, %3
  %29 = load i32, ptr %10, align 4, !tbaa !11
  %30 = load i32, ptr %6, align 4, !tbaa !11
  %31 = icmp slt i32 %29, %30
  br i1 %31, label %33, label %32

32:                                               ; preds = %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  br label %50

33:                                               ; preds = %28
  %34 = load double, ptr %8, align 8, !tbaa !5
  %35 = fmul double %34, 1.000000e+01
  store double %35, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %36 = load double, ptr %8, align 8, !tbaa !5
  %37 = fptosi double %36 to i32
  store i32 %37, ptr %11, align 4, !tbaa !11
  %38 = load i32, ptr %11, align 4, !tbaa !11
  %39 = add nsw i32 %38, 48
  %40 = trunc i32 %39 to i8
  %41 = load ptr, ptr %9, align 8, !tbaa !9
  %42 = getelementptr inbounds i8, ptr %41, i32 1
  store ptr %42, ptr %9, align 8, !tbaa !9
  store i8 %40, ptr %41, align 1, !tbaa !13
  %43 = load i32, ptr %11, align 4, !tbaa !11
  %44 = sitofp i32 %43 to double
  %45 = load double, ptr %8, align 8, !tbaa !5
  %46 = fsub double %45, %44
  store double %46, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  br label %47

47:                                               ; preds = %33
  %48 = load i32, ptr %10, align 4, !tbaa !11
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %10, align 4, !tbaa !11
  br label %28, !llvm.loop !14

50:                                               ; preds = %32
  %51 = load ptr, ptr %9, align 8, !tbaa !9
  store i8 0, ptr %51, align 1, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"double", !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}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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"

; Function Attrs: nounwind uwtable
declare hidden zeroext i8 @TinyCmd_strlen(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local void @dtoa(double noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = fptosi double %0 to i32
  tail call void @itoa(i32 noundef %4, ptr noundef %1, i32 noundef 10)
  %5 = tail call zeroext i8 @TinyCmd_strlen(ptr noundef %1)
  %6 = zext i8 %5 to i64
  %7 = getelementptr inbounds i8, ptr %1, i64 %6
  store i8 46, ptr %7, align 1, !tbaa !5
  %.01819 = getelementptr inbounds i8, ptr %7, i64 1
  %8 = icmp sgt i32 %2, 0
  br i1 %8, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %3
  %9 = sitofp i32 %4 to double
  %10 = fsub double %0, %9
  %xtraiter = and i32 %2, 1
  %11 = icmp eq i32 %2, 1
  br i1 %11, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i32 %2, 2147483646
  br label %.lr.ph

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %.018.lcssa26.ph = phi ptr [ poison, %.lr.ph.preheader ], [ %.018.1, %.lr.ph ]
  %.01822.unr = phi ptr [ %.01819, %.lr.ph.preheader ], [ %.018.1, %.lr.ph ]
  %.021.unr = phi double [ %10, %.lr.ph.preheader ], [ %27, %.lr.ph ]
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa
  %12 = fmul double %.021.unr, 1.000000e+01
  %13 = fptosi double %12 to i32
  %14 = trunc i32 %13 to i8
  %15 = add i8 %14, 48
  store i8 %15, ptr %.01822.unr, align 1, !tbaa !5
  %.018.epil = getelementptr inbounds i8, ptr %.01822.unr, i64 1
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.epil, %._crit_edge.loopexit.unr-lcssa, %3
  %.018.lcssa = phi ptr [ %.01819, %3 ], [ %.018.lcssa26.ph, %._crit_edge.loopexit.unr-lcssa ], [ %.018.epil, %.lr.ph.epil ]
  store i8 0, ptr %.018.lcssa, align 1, !tbaa !5
  ret void

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.01822 = phi ptr [ %.01819, %.lr.ph.preheader.new ], [ %.018.1, %.lr.ph ]
  %.021 = phi double [ %10, %.lr.ph.preheader.new ], [ %27, %.lr.ph ]
  %niter = phi i32 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %16 = fmul double %.021, 1.000000e+01
  %17 = fptosi double %16 to i32
  %18 = trunc i32 %17 to i8
  %19 = add i8 %18, 48
  store i8 %19, ptr %.01822, align 1, !tbaa !5
  %20 = sitofp i32 %17 to double
  %21 = fsub double %16, %20
  %.018 = getelementptr inbounds i8, ptr %.01822, i64 1
  %22 = fmul double %21, 1.000000e+01
  %23 = fptosi double %22 to i32
  %24 = trunc i32 %23 to i8
  %25 = add i8 %24, 48
  store i8 %25, ptr %.018, align 1, !tbaa !5
  %26 = sitofp i32 %23 to double
  %27 = fsub double %22, %26
  %.018.1 = getelementptr inbounds i8, ptr %.01822, i64 2
  %niter.next.1 = add i32 %niter, 2
  %niter.ncmp.1 = icmp eq i32 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !8
}

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

!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 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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