; LLVM IR from yinqiwen/ardb :: src/common/geo (geohash_helper)

; 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
define dso_local noundef zeroext i1 @_ZN4ardb13GeoHashHelper27GetDistanceSquareIfInRadiusEhdddddRdd(i8 noundef zeroext %0, double noundef %1, double noundef %2, double noundef %3, double noundef %4, double noundef %5, ptr noundef nonnull align 8 dereferenceable(8) %6, double noundef %7) #1 align 2 {
  %9 = alloca i1, align 1
  %10 = alloca i8, align 1
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  %13 = alloca double, align 8
  %14 = alloca double, align 8
  %15 = alloca double, align 8
  %16 = alloca ptr, align 8
  %17 = alloca double, align 8
  %18 = alloca double, align 8
  %19 = alloca double, align 8
  %20 = alloca double, align 8
  %21 = alloca double, align 8
  %22 = alloca i32, align 4
  store i8 %0, ptr %10, align 1, !tbaa !5
  store double %1, ptr %11, align 8, !tbaa !8
  store double %2, ptr %12, align 8, !tbaa !8
  store double %3, ptr %13, align 8, !tbaa !8
  store double %4, ptr %14, align 8, !tbaa !8
  store double %5, ptr %15, align 8, !tbaa !8
  store ptr %6, ptr %16, align 8, !tbaa !10
  store double %7, ptr %17, align 8, !tbaa !8
  %23 = load i8, ptr %10, align 1, !tbaa !5
  %24 = zext i8 %23 to i32
  %25 = icmp eq i32 %24, 1
  br i1 %25, label %26, label %55

26:                                               ; preds = %8
  %27 = load double, ptr %12, align 8, !tbaa !8
  %28 = load double, ptr %11, align 8, !tbaa !8
  %29 = load double, ptr %14, align 8, !tbaa !8
  %30 = load double, ptr %13, align 8, !tbaa !8
  %31 = call noundef double @_ZN4ardbL13distanceEarthEdddd(double noundef %27, double noundef %28, double noundef %29, double noundef %30)
  %32 = load ptr, ptr %16, align 8, !tbaa !10
  store double %31, ptr %32, align 8, !tbaa !8
  %33 = load ptr, ptr %16, align 8, !tbaa !10
  %34 = load double, ptr %33, align 8, !tbaa !8
  %35 = load double, ptr %15, align 8, !tbaa !8
  %36 = fcmp ogt double %34, %35
  br i1 %36, label %37, label %48

37:                                               ; preds = %26
  %38 = load ptr, ptr %16, align 8, !tbaa !10
  %39 = load double, ptr %38, align 8, !tbaa !8
  %40 = load double, ptr %15, align 8, !tbaa !8
  %41 = fsub double %39, %40
  %42 = call noundef double @_ZSt3absd(double noundef %41)
  %43 = load double, ptr %17, align 8, !tbaa !8
  %44 = call noundef double @_ZSt3absd(double noundef %43)
  %45 = fcmp ogt double %42, %44
  br i1 %45, label %46, label %47

46:                                               ; preds = %37
  store i1 false, ptr %9, align 1
  br label %91

47:                                               ; preds = %37
  br label %48

48:                                               ; preds = %47, %26
  %49 = load ptr, ptr %16, align 8, !tbaa !10
  %50 = load double, ptr %49, align 8, !tbaa !8
  %51 = load ptr, ptr %16, align 8, !tbaa !10
  %52 = load double, ptr %51, align 8, !tbaa !8
  %53 = fmul double %50, %52
  %54 = load ptr, ptr %16, align 8, !tbaa !10
  store double %53, ptr %54, align 8, !tbaa !8
  br label %90

55:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  %56 = load double, ptr %11, align 8, !tbaa !8
  %57 = load double, ptr %13, align 8, !tbaa !8
  %58 = fsub double %56, %57
  %59 = load double, ptr %11, align 8, !tbaa !8
  %60 = load double, ptr %13, align 8, !tbaa !8
  %61 = fsub double %59, %60
  %62 = fmul double %58, %61
  store double %62, ptr %18, align 8, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #4
  %63 = load double, ptr %12, align 8, !tbaa !8
  %64 = load double, ptr %14, align 8, !tbaa !8
  %65 = fsub double %63, %64
  %66 = load double, ptr %12, align 8, !tbaa !8
  %67 = load double, ptr %14, align 8, !tbaa !8
  %68 = fsub double %66, %67
  %69 = fmul double %65, %68
  store double %69, ptr %19, align 8, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #4
  %70 = load double, ptr %18, align 8, !tbaa !8
  %71 = load double, ptr %19, align 8, !tbaa !8
  %72 = fadd double %70, %71
  store double %72, ptr %20, align 8, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #4
  %73 = load double, ptr %15, align 8, !tbaa !8
  %74 = load double, ptr %17, align 8, !tbaa !8
  %75 = fadd double %73, %74
  %76 = load double, ptr %15, align 8, !tbaa !8
  %77 = load double, ptr %17, align 8, !tbaa !8
  %78 = fadd double %76, %77
  %79 = fmul double %75, %78
  store double %79, ptr %21, align 8, !tbaa !8
  %80 = load double, ptr %20, align 8, !tbaa !8
  %81 = load double, ptr %21, align 8, !tbaa !8
  %82 = fcmp ogt double %80, %81
  br i1 %82, label %83, label %84

83:                                               ; preds = %55
  store i1 false, ptr %9, align 1
  store i32 1, ptr %22, align 4
  br label %87

84:                                               ; preds = %55
  %85 = load double, ptr %20, align 8, !tbaa !8
  %86 = load ptr, ptr %16, align 8, !tbaa !10
  store double %85, ptr %86, align 8, !tbaa !8
  store i32 0, ptr %22, align 4
  br label %87

87:                                               ; preds = %84, %83
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  %88 = load i32, ptr %22, align 4
  switch i32 %88, label %93 [
    i32 0, label %89
    i32 1, label %91
  ]

89:                                               ; preds = %87
  br label %90

90:                                               ; preds = %89, %48
  store i1 true, ptr %9, align 1
  br label %91

91:                                               ; preds = %90, %87, %46
  %92 = load i1, ptr %9, align 1
  ret i1 %92

93:                                               ; preds = %87
  unreachable
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef double @_ZN4ardbL13distanceEarthEdddd(double noundef, double noundef, double noundef, double noundef) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt3absd(double noundef) #3

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 = { 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 #3 = { inlinehint 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 #4 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"double", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !6, 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"

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN4ardb13GeoHashHelper27GetDistanceSquareIfInRadiusEhdddddRdd(i8 noundef zeroext %0, double noundef %1, double noundef %2, double noundef %3, double noundef %4, double noundef %5, ptr nocapture noundef nonnull align 8 dereferenceable(8) %6, double noundef %7) local_unnamed_addr #0 align 2 {
  %9 = icmp eq i8 %0, 1
  br i1 %9, label %10, label %21

10:                                               ; preds = %8
  %11 = tail call noundef double @_ZN4ardbL13distanceEarthEdddd(double noundef %2, double noundef %1, double noundef %4, double noundef %3)
  store double %11, ptr %6, align 8, !tbaa !5
  %12 = fcmp ogt double %11, %5
  br i1 %12, label %13, label %18

13:                                               ; preds = %10
  %14 = fsub double %11, %5
  %15 = tail call noundef double @_ZSt3absd(double noundef %14)
  %16 = tail call noundef double @_ZSt3absd(double noundef %7)
  %17 = fcmp ogt double %15, %16
  br i1 %17, label %33, label %._crit_edge

._crit_edge:                                      ; preds = %13
  %.pre = load double, ptr %6, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %._crit_edge, %10
  %19 = phi double [ %.pre, %._crit_edge ], [ %11, %10 ]
  %20 = fmul double %19, %19
  br label %.sink.split

21:                                               ; preds = %8
  %22 = insertelement <2 x double> poison, double %1, i64 0
  %23 = insertelement <2 x double> %22, double %2, i64 1
  %24 = insertelement <2 x double> poison, double %3, i64 0
  %25 = insertelement <2 x double> %24, double %4, i64 1
  %26 = fsub <2 x double> %23, %25
  %27 = fmul <2 x double> %26, %26
  %shift = shufflevector <2 x double> %27, <2 x double> poison, <2 x i32> <i32 1, i32 poison>
  %28 = fadd <2 x double> %27, %shift
  %29 = extractelement <2 x double> %28, i64 0
  %30 = fadd double %5, %7
  %31 = fmul double %30, %30
  %32 = fcmp ogt double %29, %31
  br i1 %32, label %33, label %.sink.split

.sink.split:                                      ; preds = %21, %18
  %.sink = phi double [ %20, %18 ], [ %29, %21 ]
  store double %.sink, ptr %6, align 8, !tbaa !5
  br label %33

33:                                               ; preds = %.sink.split, %21, %13
  %.1 = phi i1 [ false, %13 ], [ false, %21 ], [ true, %.sink.split ]
  ret i1 %.1
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef double @_ZN4ardbL13distanceEarthEdddd(double noundef, double noundef, double noundef, double noundef) local_unnamed_addr #0

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt3absd(double noundef) local_unnamed_addr #1

attributes #0 = { 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 #1 = { inlinehint 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" }

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass,VectorCombinePass