; LLVM IR from XiaoMi/mace :: micro/base/value_to_str.ll (ZN5micro4base8ToStringIfEEPcT_S2_S2_)

; 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: mustprogress uwtable
declare dso_local noundef ptr @_ZN5micro4base8ToStringIiEEPcT_S2_S2_(i32 noundef, ptr noundef, ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN5micro4base8ToStringIfEEPcT_S2_S2_(float noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca float, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca float, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store float %0, ptr %5, align 4, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !9
  %12 = load float, ptr %5, align 4, !tbaa !5
  %13 = fpext float %12 to double
  %14 = fcmp ole double %13, -1.000000e-08
  br i1 %14, label %15, label %18

15:                                               ; preds = %3
  %16 = load ptr, ptr %6, align 8, !tbaa !9
  %17 = getelementptr inbounds i8, ptr %16, i32 1
  store ptr %17, ptr %6, align 8, !tbaa !9
  store i8 45, ptr %16, align 1, !tbaa !11
  br label %18

18:                                               ; preds = %15, %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %19 = load float, ptr %5, align 4, !tbaa !5
  %20 = fptosi float %19 to i32
  store i32 %20, ptr %8, align 4, !tbaa !12
  %21 = load i32, ptr %8, align 4, !tbaa !12
  %22 = load ptr, ptr %6, align 8, !tbaa !9
  %23 = load ptr, ptr %7, align 8, !tbaa !9
  %24 = call noundef ptr @_ZN5micro4base8ToStringIiEEPcT_S2_S2_(i32 noundef %21, ptr noundef %22, ptr noundef %23)
  store ptr %24, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %25 = load float, ptr %5, align 4, !tbaa !5
  %26 = load i32, ptr %8, align 4, !tbaa !12
  %27 = sitofp i32 %26 to float
  %28 = fsub float %25, %27
  store float %28, ptr %9, align 4, !tbaa !5
  %29 = load float, ptr %9, align 4, !tbaa !5
  %30 = fpext float %29 to double
  %31 = fcmp olt double %30, 1.000000e-08
  br i1 %31, label %32, label %38

32:                                               ; preds = %18
  %33 = load float, ptr %9, align 4, !tbaa !5
  %34 = fpext float %33 to double
  %35 = fcmp ogt double %34, -1.000000e-08
  br i1 %35, label %36, label %38

36:                                               ; preds = %32
  %37 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %37, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %76

38:                                               ; preds = %32, %18
  %39 = load float, ptr %9, align 4, !tbaa !5
  %40 = fpext float %39 to double
  %41 = fcmp olt double %40, 0.000000e+00
  br i1 %41, label %42, label %45

42:                                               ; preds = %38
  %43 = load float, ptr %9, align 4, !tbaa !5
  %44 = fneg float %43
  store float %44, ptr %9, align 4, !tbaa !5
  br label %45

45:                                               ; preds = %42, %38
  %46 = load ptr, ptr %7, align 8, !tbaa !9
  %47 = getelementptr inbounds i8, ptr %46, i32 -1
  store ptr %47, ptr %7, align 8, !tbaa !9
  %48 = load ptr, ptr %6, align 8, !tbaa !9
  %49 = getelementptr inbounds i8, ptr %48, i32 1
  store ptr %49, ptr %6, align 8, !tbaa !9
  store i8 46, ptr %48, align 1, !tbaa !11
  br label %50

50:                                               ; preds = %71, %45
  %51 = load float, ptr %9, align 4, !tbaa !5
  %52 = fmul float %51, 1.000000e+01
  store float %52, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %53 = load float, ptr %9, align 4, !tbaa !5
  %54 = fptosi float %53 to i32
  store i32 %54, ptr %11, align 4, !tbaa !12
  %55 = load i32, ptr %11, align 4, !tbaa !12
  %56 = add nsw i32 48, %55
  %57 = trunc i32 %56 to i8
  %58 = load ptr, ptr %6, align 8, !tbaa !9
  %59 = getelementptr inbounds i8, ptr %58, i32 1
  store ptr %59, ptr %6, align 8, !tbaa !9
  store i8 %57, ptr %58, align 1, !tbaa !11
  %60 = load i32, ptr %11, align 4, !tbaa !12
  %61 = sitofp i32 %60 to float
  %62 = load float, ptr %9, align 4, !tbaa !5
  %63 = fsub float %62, %61
  store float %63, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  br label %64

64:                                               ; preds = %50
  %65 = load float, ptr %9, align 4, !tbaa !5
  %66 = fcmp ogt float %65, 0.000000e+00
  br i1 %66, label %67, label %71

67:                                               ; preds = %64
  %68 = load ptr, ptr %6, align 8, !tbaa !9
  %69 = load ptr, ptr %7, align 8, !tbaa !9
  %70 = icmp ult ptr %68, %69
  br label %71

71:                                               ; preds = %67, %64
  %72 = phi i1 [ false, %64 ], [ %70, %67 ]
  br i1 %72, label %50, label %73, !llvm.loop !14

73:                                               ; preds = %71
  %74 = load ptr, ptr %6, align 8, !tbaa !9
  store i8 0, ptr %74, align 1, !tbaa !11
  %75 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %75, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %76

76:                                               ; preds = %73, %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  %77 = load ptr, ptr %4, align 8
  ret ptr %77
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !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: mustprogress uwtable
declare dso_local noundef ptr @_ZN5micro4base8ToStringIiEEPcT_S2_S2_(i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN5micro4base8ToStringIfEEPcT_S2_S2_(float noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = fpext float %0 to double
  %5 = fcmp ugt double %4, -1.000000e-08
  br i1 %5, label %8, label %6

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %1, i64 1
  store i8 45, ptr %1, align 1, !tbaa !5
  br label %8

8:                                                ; preds = %6, %3
  %.027 = phi ptr [ %7, %6 ], [ %1, %3 ]
  %9 = fptosi float %0 to i32
  %10 = tail call noundef ptr @_ZN5micro4base8ToStringIiEEPcT_S2_S2_(i32 noundef %9, ptr noundef %.027, ptr noundef %2)
  %11 = sitofp i32 %9 to float
  %12 = fsub float %0, %11
  %13 = tail call float @llvm.fabs.f32(float %12)
  %14 = fpext float %13 to double
  %or.cond = fcmp olt double %14, 1.000000e-08
  br i1 %or.cond, label %32, label %15

15:                                               ; preds = %8
  %16 = fcmp olt float %12, 0.000000e+00
  %17 = fneg float %12
  %.026 = select i1 %16, float %17, float %12
  %18 = getelementptr inbounds i8, ptr %2, i64 -1
  %19 = getelementptr inbounds i8, ptr %10, i64 1
  store i8 46, ptr %10, align 1, !tbaa !5
  br label %20

20:                                               ; preds = %20, %15
  %.128 = phi ptr [ %19, %15 ], [ %25, %20 ]
  %.1 = phi float [ %.026, %15 ], [ %27, %20 ]
  %21 = fmul float %.1, 1.000000e+01
  %22 = fptosi float %21 to i32
  %23 = trunc i32 %22 to i8
  %24 = add i8 %23, 48
  %25 = getelementptr inbounds i8, ptr %.128, i64 1
  store i8 %24, ptr %.128, align 1, !tbaa !5
  %26 = sitofp i32 %22 to float
  %27 = fsub float %21, %26
  %28 = fcmp ogt float %27, 0.000000e+00
  %29 = icmp ult ptr %25, %18
  %30 = select i1 %28, i1 %29, i1 false
  br i1 %30, label %20, label %31, !llvm.loop !8

31:                                               ; preds = %20
  store i8 0, ptr %25, align 1, !tbaa !5
  br label %32

32:                                               ; preds = %8, %31
  %.0 = phi ptr [ %25, %31 ], [ %10, %8 ]
  ret ptr %.0
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fabs.f32(float) #1

attributes #0 = { mustprogress 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

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


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