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

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

25:                                               ; preds = %7
  %26 = load ptr, ptr %12, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.GeoHashArea, ptr %26, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %27, ptr align 8 %11, i64 16, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %13) #4
  store i8 0, ptr %13, align 1, !tbaa !12
  %28 = getelementptr inbounds %struct.GeoHashRange, ptr %9, i32 0, i32 1
  %29 = load double, ptr %28, align 8, !tbaa !13
  %30 = load ptr, ptr %12, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.GeoHashArea, ptr %30, i32 0, i32 1
  %32 = getelementptr inbounds %struct.GeoHashRange, ptr %31, i32 0, i32 1
  store double %29, ptr %32, align 8, !tbaa !16
  %33 = getelementptr inbounds %struct.GeoHashRange, ptr %9, i32 0, i32 0
  %34 = load double, ptr %33, align 8, !tbaa !19
  %35 = load ptr, ptr %12, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.GeoHashArea, ptr %35, i32 0, i32 1
  %37 = getelementptr inbounds %struct.GeoHashRange, ptr %36, i32 0, i32 0
  store double %34, ptr %37, align 8, !tbaa !20
  %38 = getelementptr inbounds %struct.GeoHashRange, ptr %10, i32 0, i32 1
  %39 = load double, ptr %38, align 8, !tbaa !13
  %40 = load ptr, ptr %12, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.GeoHashArea, ptr %40, i32 0, i32 2
  %42 = getelementptr inbounds %struct.GeoHashRange, ptr %41, i32 0, i32 1
  store double %39, ptr %42, align 8, !tbaa !21
  %43 = getelementptr inbounds %struct.GeoHashRange, ptr %10, i32 0, i32 0
  %44 = load double, ptr %43, align 8, !tbaa !19
  %45 = load ptr, ptr %12, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.GeoHashArea, ptr %45, i32 0, i32 2
  %47 = getelementptr inbounds %struct.GeoHashRange, ptr %46, i32 0, i32 0
  store double %44, ptr %47, align 8, !tbaa !22
  br label %48

48:                                               ; preds = %144, %25
  %49 = load i8, ptr %13, align 1, !tbaa !12
  %50 = zext i8 %49 to i32
  %51 = getelementptr inbounds %struct.GeoHashBits, ptr %11, i32 0, i32 1
  %52 = load i8, ptr %51, align 8, !tbaa !23
  %53 = zext i8 %52 to i32
  %54 = icmp slt i32 %50, %53
  br i1 %54, label %55, label %147

55:                                               ; preds = %48
  call void @llvm.lifetime.start.p0(i64 1, ptr %14) #4
  call void @llvm.lifetime.start.p0(i64 1, ptr %15) #4
  %56 = getelementptr inbounds %struct.GeoHashBits, ptr %11, i32 0, i32 0
  %57 = load i64, ptr %56, align 8, !tbaa !24
  %58 = getelementptr inbounds %struct.GeoHashBits, ptr %11, i32 0, i32 1
  %59 = load i8, ptr %58, align 8, !tbaa !23
  %60 = zext i8 %59 to i32
  %61 = load i8, ptr %13, align 1, !tbaa !12
  %62 = zext i8 %61 to i32
  %63 = sub nsw i32 %60, %62
  %64 = mul nsw i32 %63, 2
  %65 = sub nsw i32 %64, 1
  %66 = trunc i32 %65 to i8
  %67 = call zeroext i8 @get_bit(i64 noundef %57, i8 noundef zeroext %66)
  store i8 %67, ptr %15, align 1, !tbaa !12
  %68 = getelementptr inbounds %struct.GeoHashBits, ptr %11, i32 0, i32 0
  %69 = load i64, ptr %68, align 8, !tbaa !24
  %70 = getelementptr inbounds %struct.GeoHashBits, ptr %11, i32 0, i32 1
  %71 = load i8, ptr %70, align 8, !tbaa !23
  %72 = zext i8 %71 to i32
  %73 = load i8, ptr %13, align 1, !tbaa !12
  %74 = zext i8 %73 to i32
  %75 = sub nsw i32 %72, %74
  %76 = mul nsw i32 %75, 2
  %77 = sub nsw i32 %76, 2
  %78 = trunc i32 %77 to i8
  %79 = call zeroext i8 @get_bit(i64 noundef %69, i8 noundef zeroext %78)
  store i8 %79, ptr %14, align 1, !tbaa !12
  %80 = load i8, ptr %14, align 1, !tbaa !12
  %81 = zext i8 %80 to i32
  %82 = icmp eq i32 %81, 0
  br i1 %82, label %83, label %97

83:                                               ; preds = %55
  %84 = load ptr, ptr %12, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.GeoHashArea, ptr %84, i32 0, i32 1
  %86 = getelementptr inbounds %struct.GeoHashRange, ptr %85, i32 0, i32 0
  %87 = load double, ptr %86, align 8, !tbaa !20
  %88 = load ptr, ptr %12, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.GeoHashArea, ptr %88, i32 0, i32 1
  %90 = getelementptr inbounds %struct.GeoHashRange, ptr %89, i32 0, i32 1
  %91 = load double, ptr %90, align 8, !tbaa !16
  %92 = fadd double %87, %91
  %93 = fdiv double %92, 2.000000e+00
  %94 = load ptr, ptr %12, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.GeoHashArea, ptr %94, i32 0, i32 1
  %96 = getelementptr inbounds %struct.GeoHashRange, ptr %95, i32 0, i32 0
  store double %93, ptr %96, align 8, !tbaa !20
  br label %111

97:                                               ; preds = %55
  %98 = load ptr, ptr %12, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.GeoHashArea, ptr %98, i32 0, i32 1
  %100 = getelementptr inbounds %struct.GeoHashRange, ptr %99, i32 0, i32 0
  %101 = load double, ptr %100, align 8, !tbaa !20
  %102 = load ptr, ptr %12, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.GeoHashArea, ptr %102, i32 0, i32 1
  %104 = getelementptr inbounds %struct.GeoHashRange, ptr %103, i32 0, i32 1
  %105 = load double, ptr %104, align 8, !tbaa !16
  %106 = fadd double %101, %105
  %107 = fdiv double %106, 2.000000e+00
  %108 = load ptr, ptr %12, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.GeoHashArea, ptr %108, i32 0, i32 1
  %110 = getelementptr inbounds %struct.GeoHashRange, ptr %109, i32 0, i32 1
  store double %107, ptr %110, align 8, !tbaa !16
  br label %111

111:                                              ; preds = %97, %83
  %112 = load i8, ptr %15, align 1, !tbaa !12
  %113 = zext i8 %112 to i32
  %114 = icmp eq i32 %113, 0
  br i1 %114, label %115, label %129

115:                                              ; preds = %111
  %116 = load ptr, ptr %12, align 8, !tbaa !5
  %117 = getelementptr inbounds %struct.GeoHashArea, ptr %116, i32 0, i32 2
  %118 = getelementptr inbounds %struct.GeoHashRange, ptr %117, i32 0, i32 0
  %119 = load double, ptr %118, align 8, !tbaa !22
  %120 = load ptr, ptr %12, align 8, !tbaa !5
  %121 = getelementptr inbounds %struct.GeoHashArea, ptr %120, i32 0, i32 2
  %122 = getelementptr inbounds %struct.GeoHashRange, ptr %121, i32 0, i32 1
  %123 = load double, ptr %122, align 8, !tbaa !21
  %124 = fadd double %119, %123
  %125 = fdiv double %124, 2.000000e+00
  %126 = load ptr, ptr %12, align 8, !tbaa !5
  %127 = getelementptr inbounds %struct.GeoHashArea, ptr %126, i32 0, i32 2
  %128 = getelementptr inbounds %struct.GeoHashRange, ptr %127, i32 0, i32 0
  store double %125, ptr %128, align 8, !tbaa !22
  br label %143

129:                                              ; preds = %111
  %130 = load ptr, ptr %12, align 8, !tbaa !5
  %131 = getelementptr inbounds %struct.GeoHashArea, ptr %130, i32 0, i32 2
  %132 = getelementptr inbounds %struct.GeoHashRange, ptr %131, i32 0, i32 0
  %133 = load double, ptr %132, align 8, !tbaa !22
  %134 = load ptr, ptr %12, align 8, !tbaa !5
  %135 = getelementptr inbounds %struct.GeoHashArea, ptr %134, i32 0, i32 2
  %136 = getelementptr inbounds %struct.GeoHashRange, ptr %135, i32 0, i32 1
  %137 = load double, ptr %136, align 8, !tbaa !21
  %138 = fadd double %133, %137
  %139 = fdiv double %138, 2.000000e+00
  %140 = load ptr, ptr %12, align 8, !tbaa !5
  %141 = getelementptr inbounds %struct.GeoHashArea, ptr %140, i32 0, i32 2
  %142 = getelementptr inbounds %struct.GeoHashRange, ptr %141, i32 0, i32 1
  store double %139, ptr %142, align 8, !tbaa !21
  br label %143

143:                                              ; preds = %129, %115
  call void @llvm.lifetime.end.p0(i64 1, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %14) #4
  br label %144

144:                                              ; preds = %143
  %145 = load i8, ptr %13, align 1, !tbaa !12
  %146 = add i8 %145, 1
  store i8 %146, ptr %13, align 1, !tbaa !12
  br label %48, !llvm.loop !25

147:                                              ; preds = %48
  store i32 0, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %13) #4
  br label %148

148:                                              ; preds = %147, %24
  %149 = load i32, ptr %8, align 4
  ret i32 %149
}

; 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) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i8 @get_bit(i64 noundef, i8 noundef zeroext) #3

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !15, i64 8}
!14 = !{!"", !15, i64 0, !15, i64 8}
!15 = !{!"double", !7, i64 0}
!16 = !{!17, !15, i64 24}
!17 = !{!"", !18, i64 0, !14, i64 16, !14, i64 32}
!18 = !{!"", !11, i64 0, !7, i64 8}
!19 = !{!14, !15, i64 0}
!20 = !{!17, !15, i64 16}
!21 = !{!17, !15, i64 40}
!22 = !{!17, !15, i64 32}
!23 = !{!18, !7, i64 8}
!24 = !{!18, !11, i64 0}
!25 = distinct !{!25, !26}
!26 = !{!"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: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @geohash_decode(double %0, double %1, double %2, double %3, i64 %4, i8 %5, ptr noundef %6) local_unnamed_addr #0 {
  %8 = icmp eq ptr %6, null
  br i1 %8, label %.loopexit, label %9

9:                                                ; preds = %7
  store i64 %4, ptr %6, align 8, !tbaa !5
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %6, i64 8
  store i8 %5, ptr %.sroa.4.0..sroa_idx, align 8, !tbaa !9
  %10 = getelementptr inbounds i8, ptr %6, i64 16
  %11 = getelementptr inbounds i8, ptr %6, i64 24
  store double %1, ptr %11, align 8, !tbaa !10
  store double %0, ptr %10, align 8, !tbaa !15
  %12 = getelementptr inbounds i8, ptr %6, i64 32
  %13 = getelementptr inbounds i8, ptr %6, i64 40
  store double %3, ptr %13, align 8, !tbaa !16
  store double %2, ptr %12, align 8, !tbaa !17
  %.not = icmp eq i8 %5, 0
  br i1 %.not, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %9, %.lr.ph
  %.03034 = phi i8 [ %30, %.lr.ph ], [ 0, %9 ]
  %14 = sub i8 %5, %.03034
  %15 = shl i8 %14, 1
  %16 = add i8 %15, -1
  %17 = tail call zeroext i8 @get_bit(i64 noundef %4, i8 noundef zeroext %16)
  %18 = add i8 %15, -2
  %19 = tail call zeroext i8 @get_bit(i64 noundef %4, i8 noundef zeroext %18)
  %20 = icmp eq i8 %19, 0
  %21 = load double, ptr %10, align 8, !tbaa !15
  %22 = load double, ptr %11, align 8, !tbaa !10
  %23 = fadd double %21, %22
  %24 = fmul double %23, 5.000000e-01
  %. = select i1 %20, ptr %10, ptr %11
  store double %24, ptr %., align 8, !tbaa !18
  %25 = icmp eq i8 %17, 0
  %.sink36 = select i1 %25, ptr %12, ptr %13
  %26 = load double, ptr %12, align 8, !tbaa !17
  %27 = load double, ptr %13, align 8, !tbaa !16
  %28 = fadd double %26, %27
  %29 = fmul double %28, 5.000000e-01
  store double %29, ptr %.sink36, align 8, !tbaa !18
  %30 = add nuw i8 %.03034, 1
  %exitcond.not = icmp eq i8 %30, %5
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !19

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i8 @get_bit(i64 noundef, i8 noundef zeroext) 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, !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, !14, i64 24}
!11 = !{!"", !12, i64 0, !13, i64 16, !13, i64 32}
!12 = !{!"", !6, i64 0, !7, i64 8}
!13 = !{!"", !14, i64 0, !14, i64 8}
!14 = !{!"double", !7, i64 0}
!15 = !{!11, !14, i64 16}
!16 = !{!11, !14, i64 40}
!17 = !{!11, !14, i64 32}
!18 = !{!14, !14, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass