// File: /workspace/github_cpp_makefile_star2_O3/Luthaf[P]zeopp/networkstorage.cc
// Function: check_sphere_overlap(int, int, int, double, ATOM_NETWORK*)
int check_sphere_overlap(int num_a, int num_b, int num_c, double diam, ATOM_NETWORK *atmnet) {
    //check each neighbouring cell in three dimensions and find shortest distance to image
    //it is sufficient to check only those images (a b c) where the leftmost non-zero term is one, e.g. (0 1 -1) but we can skip (0 -1 1), since it is equivalent in magnitude
    double min_d = -1.0; //set min distance to invalid quantity - if we cannot find any result we can return the error case
    bool overlaps = false;
    for(int a=0; a<=1 && !overlaps; a++) {
        for(int b=-1; b<=1 && !overlaps; b++) {
            for(int c=-1; c<=1 && !overlaps; c++) {
                if (
                    (a==0 && b==0 && c==1)
                    ||
                    (a==0 && b==1)
                    ||
                    (a==1)
                    )
                {
                    Point image_abc(num_a*a, num_b*b, num_c*c);
                    Point image_xyz = atmnet->abc_to_xyz(image_abc);
                    double d=image_xyz.magnitude();
                    if(d<min_d || min_d<0) {
                        min_d = d;
                        if(min_d<diam+0.001) overlaps = true;
                    }
                }
            }
        }
    }
    if(min_d<0) return -1; //bad_angles!
    else if(overlaps) return 0; //wrong
    else return 1; //correct
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rcx, 0x48(%rsp)
movl %esi, 0x34(%rsp)
addsd 0xfa472(%rip), %xmm0    # 0x14d048
movsd %xmm0, 0x40(%rsp)
movl %edi, 0x2c(%rsp)
movl %edx, 0x3c(%rsp)
movl %edx, %eax
negl %eax
movl %eax, 0x30(%rsp)
movsd 0xfe76c(%rip), %xmm1    # 0x151360
movl $0x0, 0x20(%rsp)
movb $0x1, %al
movl %eax, 0x28(%rsp)
movl $0x0, 0x24(%rsp)
xorl %r15d, %r15d
testb $0x1, %r15b
jne 0x52d87
movl 0x24(%rsp), %eax
imull 0x2c(%rsp), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x50(%rsp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testb $0x1, %r15b
jne 0x52d63
movl %eax, %r14d
orl 0x24(%rsp), %r14d
cmpl $0x1, %eax
sete %r12b
movl %eax, 0x38(%rsp)
imull 0x34(%rsp), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x58(%rsp)
andb 0x28(%rsp), %r12b
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
orb 0x20(%rsp), %r12b
movl 0x30(%rsp), %r13d
movl %ebx, %eax
xorl $0x1, %eax
orl %r14d, %eax
sete %al
orb %r12b, %al
testb $0x1, %al
je 0x52d10
xorps %xmm2, %xmm2
cvtsi2sd %r13d, %xmm2
leaq 0x68(%rsp), %rdi
movsd 0x50(%rsp), %xmm0
movsd %xmm1, 0x60(%rsp)
movsd 0x58(%rsp), %xmm1
callq 0x83f68
movq 0x78(%rsp), %rax
movq %rax, 0x10(%rsp)
movupd 0x68(%rsp), %xmm0
movupd %xmm0, (%rsp)
leaq 0x80(%rsp), %rbp
movq %rbp, %rdi
movq 0x48(%rsp), %rsi
callq 0x51d04
movq %rbp, %rdi
callq 0x8406c
movsd 0x60(%rsp), %xmm1
xorpd %xmm2, %xmm2
ucomisd %xmm1, %xmm2
ja 0x52cfd
ucomisd %xmm0, %xmm1
ja 0x52cfd
movapd %xmm1, %xmm0
jmp 0x52d0c
movsd 0x40(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x52d0c
movb $0x1, %r15b
movapd %xmm0, %xmm1
testl %ebx, %ebx
jg 0x52d25
incl %ebx
addl 0x3c(%rsp), %r13d
testb $0x1, %r15b
je 0x52c75
movl 0x38(%rsp), %eax
testl %eax, %eax
jg 0x52d39
incl %eax
testb $0x1, %r15b
je 0x52c32
movl 0x20(%rsp), %eax
orb %r15b, %al
movl $0x1, 0x24(%rsp)
movl $0x0, 0x28(%rsp)
testb $0x1, %al
movb $0x1, %al
movl %eax, 0x20(%rsp)
je 0x52c0d
movl %r15d, %eax
jmp 0x52d89
xorl %ecx, %ecx
xorpd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmovbel %ecx, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, %al
notb %al
movzbl %al, %ecx
andl $0x1, %ecx
jmp 0x52d65
nop