// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/deps/geohash-int/geohash_helper.c
// Function: geohashGetAreasByRadius
GeoHashRadius geohashGetAreasByRadius(double longitude, double latitude, double radius_meters) {
    GeoHashRange long_range, lat_range;
    GeoHashRadius radius;
    GeoHashBits hash;
    GeoHashNeighbors neighbors;
    GeoHashArea area;
    double min_lon, max_lon, min_lat, max_lat;
    double bounds[4];
    int steps;

    geohashBoundingBox(longitude, latitude, radius_meters, bounds);
    min_lon = bounds[0];
    min_lat = bounds[1];
    max_lon = bounds[2];
    max_lat = bounds[3];

    steps = geohashEstimateStepsByRadius(radius_meters,latitude);

    geohashGetCoordRange(&long_range,&lat_range);
    geohashEncode(&long_range,&lat_range,longitude,latitude,steps,&hash);
    geohashNeighbors(&hash,&neighbors);
    geohashDecode(long_range,lat_range,hash,&area);

    /* Check if the step is enough at the limits of the covered area.
     * Sometimes when the search area is near an edge of the
     * area, the estimated step is not small enough, since one of the
     * north / south / west / east square is too near to the search area
     * to cover everything. */
    int decrease_step = 0;
    {
        GeoHashArea north, south, east, west;

        geohashDecode(long_range, lat_range, neighbors.north, &north);
        geohashDecode(long_range, lat_range, neighbors.south, &south);
        geohashDecode(long_range, lat_range, neighbors.east, &east);
        geohashDecode(long_range, lat_range, neighbors.west, &west);

        if (geohashGetDistance(longitude,latitude,longitude,north.latitude.max)
            < radius_meters) decrease_step = 1;
        if (geohashGetDistance(longitude,latitude,longitude,south.latitude.min)
            < radius_meters) decrease_step = 1;
        if (geohashGetDistance(longitude,latitude,east.longitude.max,latitude)
            < radius_meters) decrease_step = 1;
        if (geohashGetDistance(longitude,latitude,west.longitude.min,latitude)
            < radius_meters) decrease_step = 1;
    }

    if (steps > 1 && decrease_step) {
        steps--;
        geohashEncode(&long_range,&lat_range,longitude,latitude,steps,&hash);
        geohashNeighbors(&hash,&neighbors);
        geohashDecode(long_range,lat_range,hash,&area);
    }

    /* Exclude the search areas that are useless. */
    if (area.latitude.min < min_lat) {
        GZERO(neighbors.south);
        GZERO(neighbors.south_west);
        GZERO(neighbors.south_east);
    }
    if (area.latitude.max > max_lat) {
        GZERO(neighbors.north);
        GZERO(neighbors.north_east);
        GZERO(neighbors.north_west);
    }
    if (area.longitude.min < min_lon) {
        GZERO(neighbors.west);
        GZERO(neighbors.south_west);
        GZERO(neighbors.north_west);
    }
    if (area.longitude.max > max_lon) {
        GZERO(neighbors.east);
        GZERO(neighbors.south_east);
        GZERO(neighbors.north_east);
    }
    radius.hash = hash;
    radius.neighbors = neighbors;
    radius.area = area;
    return radius;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x228, %rsp            # imm = 0x228
movapd %xmm2, 0x20(%rsp)
movsd %xmm1, 0x8(%rsp)
movsd %xmm0, 0x10(%rsp)
divsd 0x3409e(%rip), %xmm2    # 0xd54e8
movapd %xmm2, 0x40(%rsp)
movq %rdi, %rbx
movapd %xmm1, %xmm0
mulsd 0x32d69(%rip), %xmm0    # 0xd41c8
movsd %xmm0, 0x30(%rsp)
callq 0x263e0
movapd 0x40(%rsp), %xmm1
divsd %xmm0, %xmm1
movapd %xmm1, 0x130(%rsp)
movsd 0x30(%rsp), %xmm0
callq 0x263e0
movsd %xmm0, 0x50(%rsp)
movapd 0x40(%rsp), %xmm0
divsd 0x32d2c(%rip), %xmm0    # 0xd41c8
movsd 0x8(%rsp), %xmm1
movapd %xmm1, %xmm2
movapd %xmm0, 0x30(%rsp)
subsd %xmm0, %xmm2
movsd %xmm2, 0x58(%rsp)
movaps 0x20(%rsp), %xmm0
callq 0xa12f0
movl %eax, %ebp
leaq 0x158(%rsp), %r12
leaq 0x148(%rsp), %r15
movq %r12, %rdi
movq %r15, %rsi
callq 0xa0b34
movb %bpl, 0x7(%rsp)
movzbl %bpl, %edx
movl %edx, 0x1c(%rsp)
leaq 0x110(%rsp), %r14
movq %r12, %rdi
movq %r15, %rsi
movsd 0x10(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
movq %r14, %rcx
callq 0xa0b6b
leaq 0x60(%rsp), %r13
movq %r14, %rdi
movq %r13, %rsi
callq 0xa10f3
movsd (%r12), %xmm0
movsd 0x8(%r12), %xmm1
movsd (%r15), %xmm2
movsd 0x8(%r15), %xmm3
movq (%r14), %rdi
movl 0x8(%r14), %esi
leaq 0xe0(%rsp), %rdx
callq 0xa0e19
movsd (%r12), %xmm0
movsd 0x8(%r12), %xmm1
movsd (%r15), %xmm2
movsd 0x8(%r15), %xmm3
movq (%r13), %rdi
movl 0x8(%r13), %esi
leaq 0x168(%rsp), %rdx
callq 0xa0e19
movsd (%r12), %xmm0
movsd 0x8(%r12), %xmm1
movsd (%r15), %xmm2
movsd 0x8(%r15), %xmm3
movq 0x30(%r13), %rdi
movl 0x38(%r13), %esi
leaq 0x1f8(%rsp), %rbp
movq %rbp, %rdx
callq 0xa0e19
movsd (%r12), %xmm0
movsd 0x8(%r12), %xmm1
movsd (%r15), %xmm2
movsd 0x8(%r15), %xmm3
movq 0x10(%r13), %rdi
movl 0x18(%r13), %esi
leaq 0x1c8(%rsp), %r14
movq %r14, %rdx
callq 0xa0e19
movsd (%r12), %xmm0
movsd 0x8(%r12), %xmm1
movsd (%r15), %xmm2
movsd 0x8(%r15), %xmm3
movq 0x20(%r13), %rdi
movl 0x28(%r13), %esi
leaq 0x198(%rsp), %r15
movq %r15, %rdx
callq 0xa0e19
leaq 0x168(%rsp), %rax
movsd 0x28(%rax), %xmm3
movsd 0x10(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
movapd %xmm0, %xmm2
callq 0xa18c8
movapd 0x20(%rsp), %xmm1
ucomisd %xmm0, %xmm1
seta %r12b
movsd 0x20(%rbp), %xmm3
movsd 0x10(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
movapd %xmm0, %xmm2
callq 0xa18c8
movapd 0x20(%rsp), %xmm1
ucomisd %xmm0, %xmm1
seta %bpl
movsd 0x18(%r14), %xmm2
movsd 0x10(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
movaps %xmm1, %xmm3
callq 0xa18c8
movaps %xmm0, 0x120(%rsp)
movsd 0x10(%r15), %xmm2
movsd 0x10(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
movapd %xmm1, %xmm3
callq 0xa18c8
cmpb $0x2, 0x1c(%rsp)
jb 0xa1746
movapd 0x20(%rsp), %xmm1
movapd 0x120(%rsp), %xmm2
cmpltpd %xmm1, %xmm2
cmpltpd %xmm1, %xmm0
orpd %xmm2, %xmm0
movd %xmm0, %eax
orb %r12b, %bpl
orb %al, %bpl
testb $0x1, %bpl
je 0xa1746
movb 0x7(%rsp), %al
decb %al
movzbl %al, %edx
leaq 0x158(%rsp), %r14
leaq 0x148(%rsp), %r15
leaq 0x110(%rsp), %r12
movq %r14, %rdi
movq %r15, %rsi
movsd 0x10(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
movq %r12, %rcx
callq 0xa0b6b
leaq 0x60(%rsp), %rsi
movq %r12, %rdi
callq 0xa10f3
movsd (%r14), %xmm0
movsd 0x8(%r14), %xmm1
movsd (%r15), %xmm2
movsd 0x8(%r15), %xmm3
movq (%r12), %rdi
movl 0x8(%r12), %esi
leaq 0xe0(%rsp), %rdx
callq 0xa0e19
movapd 0x40(%rsp), %xmm2
divsd 0x50(%rsp), %xmm2
movsd 0x32a6e(%rip), %xmm0    # 0xd41c8
movapd 0x130(%rsp), %xmm1
divsd %xmm0, %xmm1
movapd 0x30(%rsp), %xmm4
addsd 0x8(%rsp), %xmm4
movsd 0x58(%rsp), %xmm3
ucomisd 0x100(%rsp), %xmm3
jbe 0xa17b3
xorl %eax, %eax
movb %al, 0x98(%rsp)
movq %rax, 0x90(%rsp)
movb %al, 0xd8(%rsp)
movq %rax, 0xd0(%rsp)
movb %al, 0xb8(%rsp)
movq %rax, 0xb0(%rsp)
divsd %xmm0, %xmm2
movsd 0x10(%rsp), %xmm3
movapd %xmm3, %xmm0
subsd %xmm1, %xmm0
movsd 0x108(%rsp), %xmm1
ucomisd %xmm4, %xmm1
jbe 0xa17fd
xorl %eax, %eax
movb %al, 0x68(%rsp)
movq %rax, 0x60(%rsp)
movb %al, 0xa8(%rsp)
movq %rax, 0xa0(%rsp)
movb %al, 0xc8(%rsp)
movq %rax, 0xc0(%rsp)
addsd %xmm3, %xmm2
ucomisd 0xf0(%rsp), %xmm0
jbe 0xa183b
xorl %eax, %eax
movb %al, 0x88(%rsp)
movq %rax, 0x80(%rsp)
movb %al, 0xd8(%rsp)
movq %rax, 0xd0(%rsp)
movb %al, 0xc8(%rsp)
movq %rax, 0xc0(%rsp)
movsd 0xf8(%rsp), %xmm0
ucomisd %xmm2, %xmm0
jbe 0xa1873
xorl %eax, %eax
movb %al, 0x78(%rsp)
movq %rax, 0x70(%rsp)
movb %al, 0xb8(%rsp)
movq %rax, 0xb0(%rsp)
movb %al, 0xa8(%rsp)
movq %rax, 0xa0(%rsp)
movups 0x110(%rsp), %xmm0
movups %xmm0, (%rbx)
leaq 0x40(%rbx), %rdi
leaq 0x60(%rsp), %rsi
movl $0x10, %ecx
rep  movsq (%rsi), %es:(%rdi)
movups 0xe0(%rsp), %xmm0
movups 0xf0(%rsp), %xmm1
movups 0x100(%rsp), %xmm2
movups %xmm2, 0x30(%rbx)
movups %xmm1, 0x20(%rbx)
movups %xmm0, 0x10(%rbx)
movq %rbx, %rax
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq