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

; 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.GeoHashRange = type { double, double }
%struct.GeoHashBits = type { i64, i8 }
%struct.GeoHashArea = type { %struct.GeoHashBits, %struct.GeoHashRange, %struct.GeoHashRange }

; 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: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @geohash_fast_decode(double %0, double %1, double %2, double %3, i64 %4, i8 %5, ptr noundef %6) #2 {
  %8 = alloca i32, align 4
  %9 = alloca %struct.GeoHashRange, align 8
  %10 = alloca %struct.GeoHashRange, align 8
  %11 = alloca %struct.GeoHashBits, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i8, align 1
  %14 = alloca i64, align 8
  %15 = alloca double, align 8
  %16 = alloca double, align 8
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = getelementptr inbounds { double, double }, ptr %9, i32 0, i32 0
  store double %0, ptr %19, align 8
  %20 = getelementptr inbounds { double, double }, ptr %9, i32 0, i32 1
  store double %1, ptr %20, align 8
  %21 = getelementptr inbounds { double, double }, ptr %10, i32 0, i32 0
  store double %2, ptr %21, align 8
  %22 = getelementptr inbounds { double, double }, ptr %10, i32 0, i32 1
  store double %3, ptr %22, align 8
  %23 = getelementptr inbounds { i64, i8 }, ptr %11, i32 0, i32 0
  store i64 %4, ptr %23, align 8
  %24 = getelementptr inbounds { i64, i8 }, ptr %11, i32 0, i32 1
  store i8 %5, ptr %24, align 8
  store ptr %6, ptr %12, align 8, !tbaa !5
  %25 = load ptr, ptr %12, align 8, !tbaa !5
  %26 = icmp eq ptr null, %25
  br i1 %26, label %27, label %28

27:                                               ; preds = %7
  store i32 -1, ptr %8, align 4
  br label %117

28:                                               ; preds = %7
  %29 = load ptr, ptr %12, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.GeoHashArea, ptr %29, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %30, ptr align 8 %11, i64 16, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %13) #5
  %31 = getelementptr inbounds %struct.GeoHashBits, ptr %11, i32 0, i32 1
  %32 = load i8, ptr %31, align 8, !tbaa !13
  store i8 %32, ptr %13, align 1, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  %33 = getelementptr inbounds %struct.GeoHashBits, ptr %11, i32 0, i32 0
  %34 = load i64, ptr %33, align 8, !tbaa !15
  %35 = call i64 @deinterleave64(i64 noundef %34)
  store i64 %35, ptr %14, align 8, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #5
  %36 = getelementptr inbounds %struct.GeoHashRange, ptr %9, i32 0, i32 0
  %37 = load double, ptr %36, align 8, !tbaa !16
  %38 = getelementptr inbounds %struct.GeoHashRange, ptr %9, i32 0, i32 1
  %39 = load double, ptr %38, align 8, !tbaa !19
  %40 = fsub double %37, %39
  store double %40, ptr %15, align 8, !tbaa !20
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #5
  %41 = getelementptr inbounds %struct.GeoHashRange, ptr %10, i32 0, i32 0
  %42 = load double, ptr %41, align 8, !tbaa !16
  %43 = getelementptr inbounds %struct.GeoHashRange, ptr %10, i32 0, i32 1
  %44 = load double, ptr %43, align 8, !tbaa !19
  %45 = fsub double %42, %44
  store double %45, ptr %16, align 8, !tbaa !20
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #5
  %46 = load i64, ptr %14, align 8, !tbaa !10
  %47 = trunc i64 %46 to i32
  store i32 %47, ptr %17, align 4, !tbaa !21
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #5
  %48 = load i64, ptr %14, align 8, !tbaa !10
  %49 = lshr i64 %48, 32
  %50 = trunc i64 %49 to i32
  store i32 %50, ptr %18, align 4, !tbaa !21
  %51 = getelementptr inbounds %struct.GeoHashRange, ptr %9, i32 0, i32 1
  %52 = load double, ptr %51, align 8, !tbaa !19
  %53 = load i32, ptr %17, align 4, !tbaa !21
  %54 = uitofp i32 %53 to double
  %55 = fmul double %54, 1.000000e+00
  %56 = load i8, ptr %13, align 1, !tbaa !12
  %57 = zext i8 %56 to i32
  %58 = zext i32 %57 to i64
  %59 = shl i64 1, %58
  %60 = uitofp i64 %59 to double
  %61 = fdiv double %55, %60
  %62 = load double, ptr %15, align 8, !tbaa !20
  %63 = call double @llvm.fmuladd.f64(double %61, double %62, double %52)
  %64 = load ptr, ptr %12, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.GeoHashArea, ptr %64, i32 0, i32 1
  %66 = getelementptr inbounds %struct.GeoHashRange, ptr %65, i32 0, i32 1
  store double %63, ptr %66, align 8, !tbaa !23
  %67 = getelementptr inbounds %struct.GeoHashRange, ptr %9, i32 0, i32 1
  %68 = load double, ptr %67, align 8, !tbaa !19
  %69 = load i32, ptr %17, align 4, !tbaa !21
  %70 = add i32 %69, 1
  %71 = uitofp i32 %70 to double
  %72 = fmul double %71, 1.000000e+00
  %73 = load i8, ptr %13, align 1, !tbaa !12
  %74 = zext i8 %73 to i32
  %75 = zext i32 %74 to i64
  %76 = shl i64 1, %75
  %77 = uitofp i64 %76 to double
  %78 = fdiv double %72, %77
  %79 = load double, ptr %15, align 8, !tbaa !20
  %80 = call double @llvm.fmuladd.f64(double %78, double %79, double %68)
  %81 = load ptr, ptr %12, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.GeoHashArea, ptr %81, i32 0, i32 1
  %83 = getelementptr inbounds %struct.GeoHashRange, ptr %82, i32 0, i32 0
  store double %80, ptr %83, align 8, !tbaa !25
  %84 = getelementptr inbounds %struct.GeoHashRange, ptr %10, i32 0, i32 1
  %85 = load double, ptr %84, align 8, !tbaa !19
  %86 = load i32, ptr %18, align 4, !tbaa !21
  %87 = uitofp i32 %86 to double
  %88 = fmul double %87, 1.000000e+00
  %89 = load i8, ptr %13, align 1, !tbaa !12
  %90 = zext i8 %89 to i32
  %91 = zext i32 %90 to i64
  %92 = shl i64 1, %91
  %93 = uitofp i64 %92 to double
  %94 = fdiv double %88, %93
  %95 = load double, ptr %16, align 8, !tbaa !20
  %96 = call double @llvm.fmuladd.f64(double %94, double %95, double %85)
  %97 = load ptr, ptr %12, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.GeoHashArea, ptr %97, i32 0, i32 2
  %99 = getelementptr inbounds %struct.GeoHashRange, ptr %98, i32 0, i32 1
  store double %96, ptr %99, align 8, !tbaa !26
  %100 = getelementptr inbounds %struct.GeoHashRange, ptr %10, i32 0, i32 1
  %101 = load double, ptr %100, align 8, !tbaa !19
  %102 = load i32, ptr %18, align 4, !tbaa !21
  %103 = add i32 %102, 1
  %104 = uitofp i32 %103 to double
  %105 = fmul double %104, 1.000000e+00
  %106 = load i8, ptr %13, align 1, !tbaa !12
  %107 = zext i8 %106 to i32
  %108 = zext i32 %107 to i64
  %109 = shl i64 1, %108
  %110 = uitofp i64 %109 to double
  %111 = fdiv double %105, %110
  %112 = load double, ptr %16, align 8, !tbaa !20
  %113 = call double @llvm.fmuladd.f64(double %111, double %112, double %101)
  %114 = load ptr, ptr %12, align 8, !tbaa !5
  %115 = getelementptr inbounds %struct.GeoHashArea, ptr %114, i32 0, i32 2
  %116 = getelementptr inbounds %struct.GeoHashRange, ptr %115, i32 0, i32 0
  store double %113, ptr %116, align 8, !tbaa !27
  store i32 0, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %13) #5
  br label %117

117:                                              ; preds = %28, %27
  %118 = load i32, ptr %8, align 4
  ret i32 %118
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @deinterleave64(i64 noundef) #3

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{i64 0, i64 8, !10, i64 8, i64 1, !12}
!10 = !{!11, !11, i64 0}
!11 = !{!"long", !7, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!14, !7, i64 8}
!14 = !{!"", !11, i64 0, !7, i64 8}
!15 = !{!14, !11, i64 0}
!16 = !{!17, !18, i64 0}
!17 = !{!"", !18, i64 0, !18, i64 8}
!18 = !{!"double", !7, i64 0}
!19 = !{!17, !18, i64 8}
!20 = !{!18, !18, i64 0}
!21 = !{!22, !22, i64 0}
!22 = !{!"int", !7, i64 0}
!23 = !{!24, !18, i64 24}
!24 = !{!"", !14, i64 0, !17, i64 16, !17, i64 32}
!25 = !{!24, !18, i64 16}
!26 = !{!24, !18, i64 40}
!27 = !{!24, !18, i64 32}


; 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
define dso_local range(i32 -1, 1) i32 @geohash_fast_decode(double %0, double %1, double %2, double %3, i64 %4, i8 %5, ptr noundef writeonly %6) local_unnamed_addr #0 {
  %8 = icmp eq ptr %6, null
  br i1 %8, label %43, label %9

9:                                                ; preds = %7
  store i64 %4, ptr %6, align 8, !tbaa !5
  %.sroa.3.0..sroa_idx = getelementptr inbounds i8, ptr %6, i64 8
  store i8 %5, ptr %.sroa.3.0..sroa_idx, align 8, !tbaa !9
  %10 = tail call i64 @deinterleave64(i64 noundef %4)
  %11 = fsub double %0, %1
  %12 = fsub double %2, %3
  %13 = trunc i64 %10 to i32
  %14 = lshr i64 %10, 32
  %15 = trunc nuw i64 %14 to i32
  %16 = zext nneg i8 %5 to i64
  %17 = shl nuw i64 1, %16
  %18 = uitofp i64 %17 to double
  %19 = getelementptr inbounds i8, ptr %6, i64 16
  %20 = add i32 %13, 1
  %21 = insertelement <2 x i32> poison, i32 %20, i64 0
  %22 = insertelement <2 x i32> %21, i32 %13, i64 1
  %23 = uitofp <2 x i32> %22 to <2 x double>
  %24 = insertelement <2 x double> poison, double %18, i64 0
  %25 = shufflevector <2 x double> %24, <2 x double> poison, <2 x i32> zeroinitializer
  %26 = fdiv <2 x double> %23, %25
  %27 = insertelement <2 x double> poison, double %11, i64 0
  %28 = shufflevector <2 x double> %27, <2 x double> poison, <2 x i32> zeroinitializer
  %29 = insertelement <2 x double> poison, double %1, i64 0
  %30 = shufflevector <2 x double> %29, <2 x double> poison, <2 x i32> zeroinitializer
  %31 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %26, <2 x double> %28, <2 x double> %30)
  store <2 x double> %31, ptr %19, align 8, !tbaa !10
  %32 = getelementptr inbounds i8, ptr %6, i64 32
  %33 = add i32 %15, 1
  %34 = insertelement <2 x i32> poison, i32 %33, i64 0
  %35 = insertelement <2 x i32> %34, i32 %15, i64 1
  %36 = uitofp <2 x i32> %35 to <2 x double>
  %37 = fdiv <2 x double> %36, %25
  %38 = insertelement <2 x double> poison, double %12, i64 0
  %39 = shufflevector <2 x double> %38, <2 x double> poison, <2 x i32> zeroinitializer
  %40 = insertelement <2 x double> poison, double %3, i64 0
  %41 = shufflevector <2 x double> %40, <2 x double> poison, <2 x i32> zeroinitializer
  %42 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %37, <2 x double> %39, <2 x double> %41)
  store <2 x double> %42, ptr %32, align 8, !tbaa !10
  br label %43

43:                                               ; preds = %7, %9
  %.0 = phi i32 [ 0, %9 ], [ -1, %7 ]
  ret i32 %.0
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @deinterleave64(i64 noundef) local_unnamed_addr #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x double> @llvm.fmuladd.v2f64(<2 x double>, <2 x double>, <2 x double>) #2

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 = { inlinehint 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 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"double", !7, i64 0}


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