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

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

26:                                               ; preds = %8
  %27 = load i8, ptr %14, align 1, !tbaa !9
  %28 = zext i8 %27 to i32
  %29 = icmp sgt i32 %28, 32
  br i1 %29, label %34, label %30

30:                                               ; preds = %26
  %31 = load i8, ptr %14, align 1, !tbaa !9
  %32 = zext i8 %31 to i32
  %33 = icmp eq i32 %32, 0
  br i1 %33, label %34, label %35

34:                                               ; preds = %30, %26, %8
  store i32 -1, ptr %9, align 4
  br label %105

35:                                               ; preds = %30
  %36 = load ptr, ptr %15, align 8, !tbaa !10
  %37 = getelementptr inbounds %struct.GeoHashBits, ptr %36, i32 0, i32 0
  store i64 0, ptr %37, align 8, !tbaa !12
  %38 = load i8, ptr %14, align 1, !tbaa !9
  %39 = load ptr, ptr %15, align 8, !tbaa !10
  %40 = getelementptr inbounds %struct.GeoHashBits, ptr %39, i32 0, i32 1
  store i8 %38, ptr %40, align 8, !tbaa !15
  %41 = load double, ptr %12, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.GeoHashRange, ptr %10, i32 0, i32 1
  %43 = load double, ptr %42, align 8, !tbaa !16
  %44 = fcmp olt double %41, %43
  br i1 %44, label %60, label %45

45:                                               ; preds = %35
  %46 = load double, ptr %12, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.GeoHashRange, ptr %10, i32 0, i32 0
  %48 = load double, ptr %47, align 8, !tbaa !18
  %49 = fcmp ogt double %46, %48
  br i1 %49, label %60, label %50

50:                                               ; preds = %45
  %51 = load double, ptr %13, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.GeoHashRange, ptr %11, i32 0, i32 1
  %53 = load double, ptr %52, align 8, !tbaa !16
  %54 = fcmp olt double %51, %53
  br i1 %54, label %60, label %55

55:                                               ; preds = %50
  %56 = load double, ptr %13, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.GeoHashRange, ptr %11, i32 0, i32 0
  %58 = load double, ptr %57, align 8, !tbaa !18
  %59 = fcmp ogt double %56, %58
  br i1 %59, label %60, label %61

60:                                               ; preds = %55, %50, %45, %35
  store i32 -1, ptr %9, align 4
  br label %105

61:                                               ; preds = %55
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  %62 = load double, ptr %12, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.GeoHashRange, ptr %10, i32 0, i32 1
  %64 = load double, ptr %63, align 8, !tbaa !16
  %65 = fsub double %62, %64
  %66 = getelementptr inbounds %struct.GeoHashRange, ptr %10, i32 0, i32 0
  %67 = load double, ptr %66, align 8, !tbaa !18
  %68 = getelementptr inbounds %struct.GeoHashRange, ptr %10, i32 0, i32 1
  %69 = load double, ptr %68, align 8, !tbaa !16
  %70 = fsub double %67, %69
  %71 = fdiv double %65, %70
  store double %71, ptr %16, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  %72 = load double, ptr %13, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.GeoHashRange, ptr %11, i32 0, i32 1
  %74 = load double, ptr %73, align 8, !tbaa !16
  %75 = fsub double %72, %74
  %76 = getelementptr inbounds %struct.GeoHashRange, ptr %11, i32 0, i32 0
  %77 = load double, ptr %76, align 8, !tbaa !18
  %78 = getelementptr inbounds %struct.GeoHashRange, ptr %11, i32 0, i32 1
  %79 = load double, ptr %78, align 8, !tbaa !16
  %80 = fsub double %77, %79
  %81 = fdiv double %75, %80
  store double %81, ptr %17, align 8, !tbaa !5
  %82 = load i8, ptr %14, align 1, !tbaa !9
  %83 = zext i8 %82 to i32
  %84 = zext i32 %83 to i64
  %85 = shl i64 1, %84
  %86 = sitofp i64 %85 to double
  %87 = load double, ptr %16, align 8, !tbaa !5
  %88 = fmul double %87, %86
  store double %88, ptr %16, align 8, !tbaa !5
  %89 = load i8, ptr %14, align 1, !tbaa !9
  %90 = zext i8 %89 to i32
  %91 = zext i32 %90 to i64
  %92 = shl i64 1, %91
  %93 = sitofp i64 %92 to double
  %94 = load double, ptr %17, align 8, !tbaa !5
  %95 = fmul double %94, %93
  store double %95, ptr %17, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #3
  %96 = load double, ptr %16, align 8, !tbaa !5
  %97 = fptoui double %96 to i32
  store i32 %97, ptr %18, align 4, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #3
  %98 = load double, ptr %17, align 8, !tbaa !5
  %99 = fptoui double %98 to i32
  store i32 %99, ptr %19, align 4, !tbaa !19
  %100 = load i32, ptr %18, align 4, !tbaa !19
  %101 = load i32, ptr %19, align 4, !tbaa !19
  %102 = call i64 @interleave64(i32 noundef %100, i32 noundef %101)
  %103 = load ptr, ptr %15, align 8, !tbaa !10
  %104 = getelementptr inbounds %struct.GeoHashBits, ptr %103, i32 0, i32 0
  store i64 %102, ptr %104, align 8, !tbaa !12
  store i32 0, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  br label %105

105:                                              ; preds = %61, %60, %34
  %106 = load i32, ptr %9, align 4
  ret i32 %106
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @interleave64(i32 noundef, i32 noundef) #2

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 = { 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 #3 = { 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!13, !14, i64 0}
!13 = !{!"", !14, i64 0, !7, i64 8}
!14 = !{!"long", !7, i64 0}
!15 = !{!13, !7, i64 8}
!16 = !{!17, !6, i64 8}
!17 = !{!"", !6, i64 0, !6, i64 8}
!18 = !{!17, !6, i64 0}
!19 = !{!20, !20, i64 0}
!20 = !{!"int", !7, 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: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @geohash_fast_encode(double %0, double %1, double %2, double %3, double noundef %4, double noundef %5, i8 noundef zeroext %6, ptr noundef writeonly %7) local_unnamed_addr #0 {
  %9 = icmp eq ptr %7, null
  %10 = add i8 %6, -33
  %11 = icmp ult i8 %10, -32
  %or.cond5 = or i1 %9, %11
  br i1 %or.cond5, label %33, label %12

12:                                               ; preds = %8
  store i64 0, ptr %7, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %7, i64 8
  store i8 %6, ptr %13, align 8, !tbaa !10
  %14 = fcmp olt double %4, %1
  %15 = fcmp ogt double %4, %0
  %or.cond = select i1 %14, i1 true, i1 %15
  %16 = fcmp olt double %5, %3
  %or.cond42 = select i1 %or.cond, i1 true, i1 %16
  %17 = fcmp ogt double %5, %2
  %or.cond43 = select i1 %or.cond42, i1 true, i1 %17
  br i1 %or.cond43, label %33, label %18

18:                                               ; preds = %12
  %19 = fsub double %4, %1
  %20 = fsub double %0, %1
  %21 = fdiv double %19, %20
  %22 = fsub double %5, %3
  %23 = fsub double %2, %3
  %24 = fdiv double %22, %23
  %25 = zext nneg i8 %6 to i64
  %26 = shl nuw nsw i64 1, %25
  %27 = uitofp nneg i64 %26 to double
  %28 = fmul double %21, %27
  %29 = fmul double %24, %27
  %30 = fptoui double %28 to i32
  %31 = fptoui double %29 to i32
  %32 = tail call i64 @interleave64(i32 noundef %30, i32 noundef %31)
  store i64 %32, ptr %7, align 8, !tbaa !5
  br label %33

33:                                               ; preds = %12, %8, %18
  %.0 = phi i32 [ 0, %18 ], [ -1, %8 ], [ -1, %12 ]
  ret i32 %.0
}

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

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

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


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