; 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.GeoHashBits = type { i64, i8 }

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

; Function Attrs: nounwind uwtable
define dso_local i32 @geohash_get_neighbor(i64 %0, i8 %1, i32 noundef %2, ptr noundef %3) #1 {
  %5 = alloca i32, align 4
  %6 = alloca %struct.GeoHashBits, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = getelementptr inbounds { i64, i8 }, ptr %6, i32 0, i32 0
  store i64 %0, ptr %9, align 8
  %10 = getelementptr inbounds { i64, i8 }, ptr %6, i32 0, i32 1
  store i8 %1, ptr %10, align 8
  store i32 %2, ptr %7, align 4, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !9
  %11 = load ptr, ptr %8, align 8, !tbaa !9
  %12 = icmp eq ptr null, %11
  br i1 %12, label %13, label %14

13:                                               ; preds = %4
  store i32 -1, ptr %5, align 4
  br label %59

14:                                               ; preds = %4
  %15 = load ptr, ptr %8, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %15, ptr align 8 %6, i64 16, i1 false), !tbaa.struct !11
  %16 = load i32, ptr %7, align 4, !tbaa !5
  switch i32 %16, label %57 [
    i32 0, label %17
    i32 3, label %22
    i32 1, label %27
    i32 2, label %32
    i32 4, label %37
    i32 5, label %42
    i32 6, label %47
    i32 7, label %52
  ]

17:                                               ; preds = %14
  %18 = load ptr, ptr %8, align 8, !tbaa !9
  %19 = call i32 @geohash_move_x(ptr noundef %18, i8 noundef signext 0)
  %20 = load ptr, ptr %8, align 8, !tbaa !9
  %21 = call i32 @geohash_move_y(ptr noundef %20, i8 noundef signext 1)
  br label %58

22:                                               ; preds = %14
  %23 = load ptr, ptr %8, align 8, !tbaa !9
  %24 = call i32 @geohash_move_x(ptr noundef %23, i8 noundef signext 0)
  %25 = load ptr, ptr %8, align 8, !tbaa !9
  %26 = call i32 @geohash_move_y(ptr noundef %25, i8 noundef signext -1)
  br label %58

27:                                               ; preds = %14
  %28 = load ptr, ptr %8, align 8, !tbaa !9
  %29 = call i32 @geohash_move_x(ptr noundef %28, i8 noundef signext 1)
  %30 = load ptr, ptr %8, align 8, !tbaa !9
  %31 = call i32 @geohash_move_y(ptr noundef %30, i8 noundef signext 0)
  br label %58

32:                                               ; preds = %14
  %33 = load ptr, ptr %8, align 8, !tbaa !9
  %34 = call i32 @geohash_move_x(ptr noundef %33, i8 noundef signext -1)
  %35 = load ptr, ptr %8, align 8, !tbaa !9
  %36 = call i32 @geohash_move_y(ptr noundef %35, i8 noundef signext 0)
  br label %58

37:                                               ; preds = %14
  %38 = load ptr, ptr %8, align 8, !tbaa !9
  %39 = call i32 @geohash_move_x(ptr noundef %38, i8 noundef signext -1)
  %40 = load ptr, ptr %8, align 8, !tbaa !9
  %41 = call i32 @geohash_move_y(ptr noundef %40, i8 noundef signext -1)
  br label %58

42:                                               ; preds = %14
  %43 = load ptr, ptr %8, align 8, !tbaa !9
  %44 = call i32 @geohash_move_x(ptr noundef %43, i8 noundef signext 1)
  %45 = load ptr, ptr %8, align 8, !tbaa !9
  %46 = call i32 @geohash_move_y(ptr noundef %45, i8 noundef signext -1)
  br label %58

47:                                               ; preds = %14
  %48 = load ptr, ptr %8, align 8, !tbaa !9
  %49 = call i32 @geohash_move_x(ptr noundef %48, i8 noundef signext -1)
  %50 = load ptr, ptr %8, align 8, !tbaa !9
  %51 = call i32 @geohash_move_y(ptr noundef %50, i8 noundef signext 1)
  br label %58

52:                                               ; preds = %14
  %53 = load ptr, ptr %8, align 8, !tbaa !9
  %54 = call i32 @geohash_move_x(ptr noundef %53, i8 noundef signext 1)
  %55 = load ptr, ptr %8, align 8, !tbaa !9
  %56 = call i32 @geohash_move_y(ptr noundef %55, i8 noundef signext 1)
  br label %58

57:                                               ; preds = %14
  store i32 -1, ptr %5, align 4
  br label %59

58:                                               ; preds = %52, %47, %42, %37, %32, %27, %22, %17
  store i32 0, ptr %5, align 4
  br label %59

59:                                               ; preds = %58, %57, %13
  %60 = load i32, ptr %5, align 4
  ret i32 %60
}

; Function Attrs: nounwind uwtable
declare hidden i32 @geohash_move_x(ptr noundef, i8 noundef signext) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @geohash_move_y(ptr noundef, i8 noundef signext) #1

attributes #0 = { nocallback nofree 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" }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{i64 0, i64 8, !12, i64 8, i64 1, !14}
!12 = !{!13, !13, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!7, !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_get_neighbor(i64 %0, i8 %1, i32 noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = icmp eq ptr %3, null
  br i1 %5, label %12, label %6

6:                                                ; preds = %4
  store i64 %0, ptr %3, align 8, !tbaa !5
  %.sroa.2.0..0.1.sroa_idx = getelementptr inbounds i8, ptr %3, i64 8
  store i8 %1, ptr %.sroa.2.0..0.1.sroa_idx, align 8, !tbaa !9
  %7 = icmp ult i32 %2, 8
  br i1 %7, label %switch.lookup, label %12

switch.lookup:                                    ; preds = %6
  %8 = shl nuw nsw i32 %2, 3
  %switch.shiftamt = zext nneg i32 %8 to i64
  %switch.downshift = lshr i64 143835907844145408, %switch.shiftamt
  %switch.masked = trunc i64 %switch.downshift to i8
  %9 = shl nuw nsw i32 %2, 3
  %switch.shiftamt22 = zext nneg i32 %9 to i64
  %switch.downshift23 = lshr i64 72620543974572033, %switch.shiftamt22
  %switch.masked24 = trunc i64 %switch.downshift23 to i8
  %10 = tail call i32 @geohash_move_x(ptr noundef nonnull %3, i8 noundef signext %switch.masked)
  %11 = tail call i32 @geohash_move_y(ptr noundef nonnull %3, i8 noundef signext %switch.masked24)
  br label %12

12:                                               ; preds = %6, %switch.lookup, %4
  %.0 = phi i32 [ -1, %4 ], [ -1, %6 ], [ 0, %switch.lookup ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden i32 @geohash_move_x(ptr noundef, i8 noundef signext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @geohash_move_y(ptr noundef, i8 noundef signext) local_unnamed_addr #0

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

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


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