// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/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
movaps %xmm2, 0x20(%rsp)
movsd %xmm1, 0x8(%rsp)
movsd %xmm0, 0x10(%rsp)
movq %rdi, %rbx
leaq 0x170(%rsp), %r14
movq %r14, %rdi
callq 0x8e3b6
movsd (%r14), %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0x8(%r14), %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0x10(%r14), %xmm0
movsd %xmm0, 0x48(%rsp)
movsd 0x18(%r14), %xmm0
movsd %xmm0, 0x38(%rsp)
movaps 0x20(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
callq 0x8e358
movl %eax, %ebp
leaq 0x130(%rsp), %r12
leaq 0x120(%rsp), %r15
movq %r12, %rdi
movq %r15, %rsi
callq 0x8dd10
movb %bpl, 0x7(%rsp)
movzbl %bpl, %edx
movl %edx, 0x1c(%rsp)
leaq 0x100(%rsp), %r14
movq %r12, %rdi
movq %r15, %rsi
movsd 0x10(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
movq %r14, %rcx
callq 0x8dd25
leaq 0x50(%rsp), %r13
movq %r14, %rdi
movq %r13, %rsi
callq 0x8e19f
movsd (%r12), %xmm0
movsd 0x8(%r12), %xmm1
movsd (%r15), %xmm2
movsd 0x8(%r15), %xmm3
movq (%r14), %rdi
movl 0x8(%r14), %esi
leaq 0xd0(%rsp), %rdx
callq 0x8defb
movsd (%r12), %xmm0
movsd 0x8(%r12), %xmm1
movsd (%r15), %xmm2
movsd 0x8(%r15), %xmm3
movq (%r13), %rdi
movl 0x8(%r13), %esi
leaq 0x140(%rsp), %rdx
callq 0x8defb
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 0x8defb
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 0x8defb
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 0x8defb
leaq 0x140(%rsp), %rax
movsd 0x28(%rax), %xmm3
movsd 0x10(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
movapd %xmm0, %xmm2
callq 0x8e8c2
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 0x8e8c2
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 0x8e8c2
movaps %xmm0, 0x110(%rsp)
movsd 0x10(%r15), %xmm2
movsd 0x10(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
movapd %xmm1, %xmm3
callq 0x8e8c2
cmpb $0x2, 0x1c(%rsp)
jb 0x8e775
movapd 0x20(%rsp), %xmm1
movapd 0x110(%rsp), %xmm2
cmpltpd %xmm1, %xmm2
cmpltpd %xmm1, %xmm0
orpd %xmm2, %xmm0
movd %xmm0, %eax
orb %r12b, %bpl
orb %al, %bpl
testb $0x1, %bpl
je 0x8e775
movb 0x7(%rsp), %al
decb %al
movzbl %al, %edx
leaq 0x130(%rsp), %r14
leaq 0x120(%rsp), %r15
leaq 0x100(%rsp), %r12
movq %r14, %rdi
movq %r15, %rsi
movsd 0x10(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
movq %r12, %rcx
callq 0x8dd25
leaq 0x50(%rsp), %rsi
movq %r12, %rdi
callq 0x8e19f
movsd (%r14), %xmm0
movsd 0x8(%r14), %xmm1
movsd (%r15), %xmm2
movsd 0x8(%r15), %xmm3
movq (%r12), %rdi
movl 0x8(%r12), %esi
leaq 0xd0(%rsp), %rdx
callq 0x8defb
movsd 0x30(%rsp), %xmm0
ucomisd 0xf0(%rsp), %xmm0
jbe 0x8e7b8
xorl %eax, %eax
movb %al, 0x88(%rsp)
andq $0x0, 0x80(%rsp)
movb %al, 0xc8(%rsp)
andq $0x0, 0xc0(%rsp)
movb %al, 0xa8(%rsp)
andq $0x0, 0xa0(%rsp)
movsd 0xf8(%rsp), %xmm0
ucomisd 0x38(%rsp), %xmm0
jbe 0x8e7f5
xorl %eax, %eax
movb %al, 0x58(%rsp)
andq $0x0, 0x50(%rsp)
movb %al, 0x98(%rsp)
andq $0x0, 0x90(%rsp)
movb %al, 0xb8(%rsp)
andq $0x0, 0xb0(%rsp)
movsd 0x40(%rsp), %xmm0
ucomisd 0xe0(%rsp), %xmm0
jbe 0x8e832
xorl %eax, %eax
movb %al, 0x78(%rsp)
andq $0x0, 0x70(%rsp)
movb %al, 0xc8(%rsp)
andq $0x0, 0xc0(%rsp)
movb %al, 0xb8(%rsp)
andq $0x0, 0xb0(%rsp)
movsd 0xe8(%rsp), %xmm0
ucomisd 0x48(%rsp), %xmm0
jbe 0x8e86f
xorl %eax, %eax
movb %al, 0x68(%rsp)
andq $0x0, 0x60(%rsp)
movb %al, 0xa8(%rsp)
andq $0x0, 0xa0(%rsp)
movb %al, 0x98(%rsp)
andq $0x0, 0x90(%rsp)
movups 0x100(%rsp), %xmm0
movups %xmm0, (%rbx)
leaq 0x40(%rbx), %rdi
pushq $0x10
popq %rcx
leaq 0x50(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movups 0xd0(%rsp), %xmm0
movups 0xe0(%rsp), %xmm1
movups 0xf0(%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