// File: /workspace/github_c_makefile_star2_O3/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
movapd %xmm2, 0x20(%rsp)
movsd %xmm1, 0x8(%rsp)
movsd %xmm0, 0x10(%rsp)
divsd 0x347b4(%rip), %xmm2    # 0xd26a8
movapd %xmm2, 0x40(%rsp)
movq %rdi, %rbx
movapd %xmm1, %xmm0
mulsd 0x333ef(%rip), %xmm0    # 0xd12f8
movsd %xmm0, 0x30(%rsp)
callq 0x263d0
movapd 0x40(%rsp), %xmm1
divsd %xmm0, %xmm1
movapd %xmm1, 0x130(%rsp)
movsd 0x30(%rsp), %xmm0
callq 0x263d0
movsd %xmm0, 0x50(%rsp)
movapd 0x40(%rsp), %xmm0
divsd 0x333b2(%rip), %xmm0    # 0xd12f8
movsd 0x8(%rsp), %xmm1
movapd %xmm1, %xmm2
movapd %xmm0, 0x30(%rsp)
subsd %xmm0, %xmm2
movsd %xmm2, 0x58(%rsp)
movaps 0x20(%rsp), %xmm0
callq 0x9dd98
movl %eax, %ebp
leaq 0x158(%rsp), %r12
leaq 0x148(%rsp), %r15
movq %r12, %rdi
movq %r15, %rsi
callq 0x9d678
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 0x9d68d
leaq 0x60(%rsp), %r13
movq %r14, %rdi
movq %r13, %rsi
callq 0x9db9b
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 0x9d8b8
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 0x9d8b8
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 0x9d8b8
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 0x9d8b8
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 0x9d8b8
leaq 0x168(%rsp), %rax
movsd 0x28(%rax), %xmm3
movsd 0x10(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
movapd %xmm0, %xmm2
callq 0x9e372
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 0x9e372
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 0x9e372
movaps %xmm0, 0x120(%rsp)
movsd 0x10(%r15), %xmm2
movsd 0x10(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
movapd %xmm1, %xmm3
callq 0x9e372
cmpb $0x2, 0x1c(%rsp)
jb 0x9e1f0
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 0x9e1f0
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 0x9d68d
leaq 0x60(%rsp), %rsi
movq %r12, %rdi
callq 0x9db9b
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 0x9d8b8
movapd 0x40(%rsp), %xmm2
divsd 0x50(%rsp), %xmm2
movsd 0x330f4(%rip), %xmm0    # 0xd12f8
movapd 0x130(%rsp), %xmm1
divsd %xmm0, %xmm1
movapd 0x30(%rsp), %xmm4
addsd 0x8(%rsp), %xmm4
movsd 0x58(%rsp), %xmm3
ucomisd 0x100(%rsp), %xmm3
jbe 0x9e25d
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 0x9e2a7
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 0x9e2e5
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 0x9e31d
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