; LLVM IR from apache/kvrocks :: src/types/geohash.ll (ZN13GeoHashHelper11BoundingBoxEP8GeoShape)

; 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.GeoShape = type { i32, [2 x double], double, [4 x double], double, double, double }

; 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 i32 @_ZN13GeoHashHelper11BoundingBoxEP8GeoShape(ptr noundef %0) #1 align 2 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca i8, align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %15, label %14

14:                                               ; preds = %1
  store i32 0, ptr %2, align 4
  br label %128

15:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.GeoShape, ptr %16, i32 0, i32 1
  %18 = getelementptr inbounds [2 x double], ptr %17, i64 0, i64 0
  %19 = load double, ptr %18, align 8, !tbaa !9
  store double %19, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.GeoShape, ptr %20, i32 0, i32 1
  %22 = getelementptr inbounds [2 x double], ptr %21, i64 0, i64 1
  %23 = load double, ptr %22, align 8, !tbaa !9
  store double %23, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.GeoShape, ptr %24, i32 0, i32 2
  %26 = load double, ptr %25, align 8, !tbaa !11
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.GeoShape, ptr %27, i32 0, i32 0
  %29 = load i32, ptr %28, align 8, !tbaa !14
  %30 = icmp eq i32 %29, 1
  br i1 %30, label %31, label %35

31:                                               ; preds = %15
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.GeoShape, ptr %32, i32 0, i32 4
  %34 = load double, ptr %33, align 8, !tbaa !15
  br label %40

35:                                               ; preds = %15
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.GeoShape, ptr %36, i32 0, i32 5
  %38 = load double, ptr %37, align 8, !tbaa !16
  %39 = fdiv double %38, 2.000000e+00
  br label %40

40:                                               ; preds = %35, %31
  %41 = phi double [ %34, %31 ], [ %39, %35 ]
  %42 = fmul double %26, %41
  store double %42, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.GeoShape, ptr %43, i32 0, i32 2
  %45 = load double, ptr %44, align 8, !tbaa !11
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.GeoShape, ptr %46, i32 0, i32 0
  %48 = load i32, ptr %47, align 8, !tbaa !14
  %49 = icmp eq i32 %48, 1
  br i1 %49, label %50, label %54

50:                                               ; preds = %40
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.GeoShape, ptr %51, i32 0, i32 4
  %53 = load double, ptr %52, align 8, !tbaa !15
  br label %59

54:                                               ; preds = %40
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.GeoShape, ptr %55, i32 0, i32 6
  %57 = load double, ptr %56, align 8, !tbaa !17
  %58 = fdiv double %57, 2.000000e+00
  br label %59

59:                                               ; preds = %54, %50
  %60 = phi double [ %53, %50 ], [ %58, %54 ]
  %61 = fmul double %45, %60
  store double %61, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %62 = load double, ptr %6, align 8, !tbaa !9
  %63 = fdiv double %62, 0x41584F6F63E51090
  %64 = call noundef double @_ZL6RadDegd(double noundef %63)
  store double %64, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %65 = load double, ptr %7, align 8, !tbaa !9
  %66 = fdiv double %65, 0x41584F6F63E51090
  %67 = load double, ptr %5, align 8, !tbaa !9
  %68 = load double, ptr %8, align 8, !tbaa !9
  %69 = fadd double %67, %68
  %70 = call noundef double @_ZL6DegRadd(double noundef %69)
  %71 = call double @cos(double noundef %70) #4
  %72 = fdiv double %66, %71
  %73 = call noundef double @_ZL6RadDegd(double noundef %72)
  store double %73, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %74 = load double, ptr %7, align 8, !tbaa !9
  %75 = fdiv double %74, 0x41584F6F63E51090
  %76 = load double, ptr %5, align 8, !tbaa !9
  %77 = load double, ptr %8, align 8, !tbaa !9
  %78 = fsub double %76, %77
  %79 = call noundef double @_ZL6DegRadd(double noundef %78)
  %80 = call double @cos(double noundef %79) #4
  %81 = fdiv double %75, %80
  %82 = call noundef double @_ZL6RadDegd(double noundef %81)
  store double %82, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %11) #4
  %83 = load double, ptr %5, align 8, !tbaa !9
  %84 = fcmp olt double %83, 0.000000e+00
  %85 = zext i1 %84 to i8
  store i8 %85, ptr %11, align 1, !tbaa !18
  %86 = load i8, ptr %11, align 1, !tbaa !18, !range !20, !noundef !21
  %87 = trunc i8 %86 to i1
  br i1 %87, label %88, label %92

88:                                               ; preds = %59
  %89 = load double, ptr %4, align 8, !tbaa !9
  %90 = load double, ptr %10, align 8, !tbaa !9
  %91 = fsub double %89, %90
  br label %96

92:                                               ; preds = %59
  %93 = load double, ptr %4, align 8, !tbaa !9
  %94 = load double, ptr %9, align 8, !tbaa !9
  %95 = fsub double %93, %94
  br label %96

96:                                               ; preds = %92, %88
  %97 = phi double [ %91, %88 ], [ %95, %92 ]
  %98 = load ptr, ptr %3, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.GeoShape, ptr %98, i32 0, i32 3
  %100 = getelementptr inbounds [4 x double], ptr %99, i64 0, i64 0
  store double %97, ptr %100, align 8, !tbaa !9
  %101 = load i8, ptr %11, align 1, !tbaa !18, !range !20, !noundef !21
  %102 = trunc i8 %101 to i1
  br i1 %102, label %103, label %107

103:                                              ; preds = %96
  %104 = load double, ptr %4, align 8, !tbaa !9
  %105 = load double, ptr %10, align 8, !tbaa !9
  %106 = fadd double %104, %105
  br label %111

107:                                              ; preds = %96
  %108 = load double, ptr %4, align 8, !tbaa !9
  %109 = load double, ptr %9, align 8, !tbaa !9
  %110 = fadd double %108, %109
  br label %111

111:                                              ; preds = %107, %103
  %112 = phi double [ %106, %103 ], [ %110, %107 ]
  %113 = load ptr, ptr %3, align 8, !tbaa !5
  %114 = getelementptr inbounds %struct.GeoShape, ptr %113, i32 0, i32 3
  %115 = getelementptr inbounds [4 x double], ptr %114, i64 0, i64 2
  store double %112, ptr %115, align 8, !tbaa !9
  %116 = load double, ptr %5, align 8, !tbaa !9
  %117 = load double, ptr %8, align 8, !tbaa !9
  %118 = fsub double %116, %117
  %119 = load ptr, ptr %3, align 8, !tbaa !5
  %120 = getelementptr inbounds %struct.GeoShape, ptr %119, i32 0, i32 3
  %121 = getelementptr inbounds [4 x double], ptr %120, i64 0, i64 1
  store double %118, ptr %121, align 8, !tbaa !9
  %122 = load double, ptr %5, align 8, !tbaa !9
  %123 = load double, ptr %8, align 8, !tbaa !9
  %124 = fadd double %122, %123
  %125 = load ptr, ptr %3, align 8, !tbaa !5
  %126 = getelementptr inbounds %struct.GeoShape, ptr %125, i32 0, i32 3
  %127 = getelementptr inbounds [4 x double], ptr %126, i64 0, i64 3
  store double %124, ptr %127, align 8, !tbaa !9
  store i32 1, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  br label %128

128:                                              ; preds = %111, %14
  %129 = load i32, ptr %2, align 4
  ret i32 %129
}

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

; Function Attrs: nounwind
declare double @cos(double noundef) #3

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

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 = { 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 #3 = { nounwind "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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !10, i64 24}
!12 = !{!"_ZTS8GeoShape", !13, i64 0, !7, i64 8, !10, i64 24, !7, i64 32, !10, i64 64, !10, i64 72, !10, i64 80}
!13 = !{!"_ZTS12GeoShapeType", !7, i64 0}
!14 = !{!12, !13, i64 0}
!15 = !{!12, !10, i64 64}
!16 = !{!12, !10, i64 72}
!17 = !{!12, !10, i64 80}
!18 = !{!19, !19, i64 0}
!19 = !{!"bool", !7, i64 0}
!20 = !{i8 0, i8 2}
!21 = !{}


; 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 range(i32 0, 2) i32 @_ZN13GeoHashHelper11BoundingBoxEP8GeoShape(ptr noundef %0) local_unnamed_addr #0 align 2 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %46, label %2

2:                                                ; preds = %1
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load double, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = load double, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  %8 = load double, ptr %7, align 8, !tbaa !9
  %9 = load i32, ptr %0, align 8, !tbaa !12
  %10 = icmp eq i32 %9, 1
  br i1 %10, label %11, label %16

11:                                               ; preds = %2
  %12 = getelementptr inbounds i8, ptr %0, i64 64
  %13 = load double, ptr %12, align 8, !tbaa !13
  %14 = insertelement <2 x double> poison, double %13, i64 0
  %15 = shufflevector <2 x double> %14, <2 x double> poison, <2 x i32> zeroinitializer
  br label %20

16:                                               ; preds = %2
  %17 = getelementptr inbounds i8, ptr %0, i64 72
  %18 = load <2 x double>, ptr %17, align 8, !tbaa !5
  %19 = fmul <2 x double> %18, <double 5.000000e-01, double 5.000000e-01>
  br label %20

20:                                               ; preds = %16, %11
  %21 = phi <2 x double> [ %15, %11 ], [ %19, %16 ]
  %22 = extractelement <2 x double> %21, i64 0
  %23 = fmul double %8, %22
  %24 = extractelement <2 x double> %21, i64 1
  %25 = fmul double %8, %24
  %26 = fdiv double %23, 0x41584F6F63E51090
  %27 = tail call noundef double @_ZL6RadDegd(double noundef %26)
  %28 = fdiv double %25, 0x41584F6F63E51090
  %29 = fadd double %6, %27
  %30 = tail call noundef double @_ZL6DegRadd(double noundef %29)
  %31 = tail call double @cos(double noundef %30) #3
  %32 = fdiv double %28, %31
  %33 = tail call noundef double @_ZL6RadDegd(double noundef %32)
  %34 = fsub double %6, %27
  %35 = tail call noundef double @_ZL6DegRadd(double noundef %34)
  %36 = tail call double @cos(double noundef %35) #3
  %37 = fdiv double %28, %36
  %38 = tail call noundef double @_ZL6RadDegd(double noundef %37)
  %39 = fcmp olt double %6, 0.000000e+00
  %. = select i1 %39, double %38, double %33
  %40 = fsub double %4, %.
  %41 = getelementptr inbounds i8, ptr %0, i64 32
  store double %40, ptr %41, align 8, !tbaa !5
  %42 = fadd double %4, %.
  %43 = getelementptr inbounds i8, ptr %0, i64 48
  store double %42, ptr %43, align 8, !tbaa !5
  %44 = getelementptr inbounds i8, ptr %0, i64 40
  store double %34, ptr %44, align 8, !tbaa !5
  %45 = getelementptr inbounds i8, ptr %0, i64 56
  store double %29, ptr %45, align 8, !tbaa !5
  br label %46

46:                                               ; preds = %1, %20
  %.0 = phi i32 [ 1, %20 ], [ 0, %1 ]
  ret i32 %.0
}

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @cos(double noundef) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef double @_ZL6DegRadd(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" }
attributes #2 = { mustprogress nofree nounwind willreturn memory(write) "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++ TBAA"}
!9 = !{!10, !6, i64 24}
!10 = !{!"_ZTS8GeoShape", !11, i64 0, !7, i64 8, !6, i64 24, !7, i64 32, !6, i64 64, !6, i64 72, !6, i64 80}
!11 = !{!"_ZTS12GeoShapeType", !7, i64 0}
!12 = !{!10, !11, i64 0}
!13 = !{!10, !6, i64 64}


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