; LLVM IR from apache/kvrocks :: src/types/geohash.ll (ZN13GeoHashHelper21EstimateStepsByRadiusEdd)

; 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 nounwind uwtable
define dso_local noundef zeroext i8 @_ZN13GeoHashHelper21EstimateStepsByRadiusEdd(double noundef %0, double noundef %1) #1 align 2 {
  %3 = alloca i8, align 1
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca i32, align 4
  store double %0, ptr %4, align 8, !tbaa !5
  store double %1, ptr %5, align 8, !tbaa !5
  %7 = load double, ptr %4, align 8, !tbaa !5
  %8 = fcmp oeq double %7, 0.000000e+00
  br i1 %8, label %9, label %10

9:                                                ; preds = %2
  store i8 26, ptr %3, align 1
  br label %50

10:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 1, ptr %6, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %14, %10
  %12 = load double, ptr %4, align 8, !tbaa !5
  %13 = fcmp olt double %12, 0x41731C05E5EB851F
  br i1 %13, label %14, label %19

14:                                               ; preds = %11
  %15 = load double, ptr %4, align 8, !tbaa !5
  %16 = fmul double %15, 2.000000e+00
  store double %16, ptr %4, align 8, !tbaa !5
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = add nsw i32 %17, 1
  store i32 %18, ptr %6, align 4, !tbaa !9
  br label %11, !llvm.loop !11

19:                                               ; preds = %11
  %20 = load i32, ptr %6, align 4, !tbaa !9
  %21 = sub nsw i32 %20, 2
  store i32 %21, ptr %6, align 4, !tbaa !9
  %22 = load double, ptr %5, align 8, !tbaa !5
  %23 = fcmp ogt double %22, 6.600000e+01
  br i1 %23, label %27, label %24

24:                                               ; preds = %19
  %25 = load double, ptr %5, align 8, !tbaa !5
  %26 = fcmp olt double %25, -6.600000e+01
  br i1 %26, label %27, label %39

27:                                               ; preds = %24, %19
  %28 = load i32, ptr %6, align 4, !tbaa !9
  %29 = add nsw i32 %28, -1
  store i32 %29, ptr %6, align 4, !tbaa !9
  %30 = load double, ptr %5, align 8, !tbaa !5
  %31 = fcmp ogt double %30, 8.000000e+01
  br i1 %31, label %35, label %32

32:                                               ; preds = %27
  %33 = load double, ptr %5, align 8, !tbaa !5
  %34 = fcmp olt double %33, -8.000000e+01
  br i1 %34, label %35, label %38

35:                                               ; preds = %32, %27
  %36 = load i32, ptr %6, align 4, !tbaa !9
  %37 = add nsw i32 %36, -1
  store i32 %37, ptr %6, align 4, !tbaa !9
  br label %38

38:                                               ; preds = %35, %32
  br label %39

39:                                               ; preds = %38, %24
  %40 = load i32, ptr %6, align 4, !tbaa !9
  %41 = icmp slt i32 %40, 1
  br i1 %41, label %42, label %43

42:                                               ; preds = %39
  store i32 1, ptr %6, align 4, !tbaa !9
  br label %43

43:                                               ; preds = %42, %39
  %44 = load i32, ptr %6, align 4, !tbaa !9
  %45 = icmp sgt i32 %44, 26
  br i1 %45, label %46, label %47

46:                                               ; preds = %43
  store i32 26, ptr %6, align 4, !tbaa !9
  br label %47

47:                                               ; preds = %46, %43
  %48 = load i32, ptr %6, align 4, !tbaa !9
  %49 = trunc i32 %48 to i8
  store i8 %49, ptr %3, align 1
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %50

50:                                               ; preds = %47, %9
  %51 = load i8, ptr %3, align 1
  ret i8 %51
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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 nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local noundef zeroext i8 @_ZN13GeoHashHelper21EstimateStepsByRadiusEdd(double noundef %0, double noundef %1) local_unnamed_addr #0 align 2 {
  %3 = fcmp oeq double %0, 0.000000e+00
  br i1 %3, label %16, label %.preheader

.preheader:                                       ; preds = %2
  %4 = fcmp olt double %0, 0x41731C05E5EB851F
  br i1 %4, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.022 = phi i32 [ %6, %.lr.ph ], [ 1, %.preheader ]
  %.01921 = phi double [ %5, %.lr.ph ], [ %0, %.preheader ]
  %5 = fmul double %.01921, 2.000000e+00
  %6 = add nuw nsw i32 %.022, 1
  %7 = fcmp olt double %5, 0x41731C05E5EB851F
  br i1 %7, label %.lr.ph, label %._crit_edge, !llvm.loop !5

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %.0.lcssa = phi i32 [ 1, %.preheader ], [ %6, %.lr.ph ]
  %8 = add nsw i32 %.0.lcssa, -2
  %9 = tail call double @llvm.fabs.f64(double %1)
  %or.cond = fcmp ogt double %9, 6.600000e+01
  br i1 %or.cond, label %10, label %14

10:                                               ; preds = %._crit_edge
  %11 = add nsw i32 %.0.lcssa, -3
  %or.cond3 = fcmp ogt double %9, 8.000000e+01
  br i1 %or.cond3, label %12, label %14

12:                                               ; preds = %10
  %13 = add nsw i32 %.0.lcssa, -4
  br label %14

14:                                               ; preds = %12, %10, %._crit_edge
  %.1 = phi i32 [ %13, %12 ], [ %11, %10 ], [ %8, %._crit_edge ]
  %spec.store.select = tail call i32 @llvm.smax.i32(i32 %.1, i32 1)
  %spec.store.select4 = tail call i32 @llvm.umin.i32(i32 %spec.store.select, i32 26)
  %15 = trunc nuw nsw i32 %spec.store.select4 to i8
  br label %16

16:                                               ; preds = %2, %14
  %.018 = phi i8 [ %15, %14 ], [ 26, %2 ]
  ret i8 %.018
}

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umin.i32(i32, i32) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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