// File: /workspace/github_cpp_makefile_star2_O2/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 $0x88, %rsp
movq %rcx, 0x40(%rsp)
movl %edx, %r14d
movl %esi, 0x24(%rsp)
movl %edi, 0x1c(%rsp)
addsd 0xbd0f5(%rip), %xmm0    # 0xfc048
movsd %xmm0, 0x38(%rsp)
movl %edx, %eax
negl %eax
movl %eax, 0x20(%rsp)
xorl %r15d, %r15d
movsd 0xc137c(%rip), %xmm1    # 0x1002e8
xorl %edi, %edi
cmpl $0x1, %edi
ja 0x3f0bb
testb $0x1, %r15b
jne 0x3f0bb
movl %edi, %eax
imull 0x1c(%rsp), %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x48(%rsp)
pushq $-0x1
popq %r8
movl %edi, 0x28(%rsp)
cmpl $0x1, %r8d
jg 0x3f0b4
testb $0x1, %r15b
jne 0x3f0b4
cmpl $0x1, %edi
sete %al
movl %r8d, %r12d
orl %edi, %r12d
movl %r8d, %ecx
xorl $0x1, %ecx
orl %edi, %ecx
sete %cl
orb %al, %cl
movl %r8d, 0x2c(%rsp)
movl %r8d, %eax
imull 0x24(%rsp), %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x50(%rsp)
movl 0x20(%rsp), %ebx
pushq $-0x1
popq %r13
movb %cl, 0x1b(%rsp)
cmpl $0x1, %r13d
jg 0x3f0a3
testb $0x1, %r15b
jne 0x3f0a3
movl %r13d, %eax
xorl $0x1, %eax
orl %r12d, %eax
sete %al
orb %cl, %al
cmpb $0x1, %al
jne 0x3f098
cvtsi2sd %ebx, %xmm2
leaq 0x58(%rsp), %rdi
movsd 0x48(%rsp), %xmm0
movsd %xmm1, 0x30(%rsp)
movsd 0x50(%rsp), %xmm1
callq 0x63c46
movq 0x68(%rsp), %rax
movq %rax, 0x10(%rsp)
movupd 0x58(%rsp), %xmm0
movupd %xmm0, (%rsp)
leaq 0x70(%rsp), %rbp
movq %rbp, %rdi
movq 0x40(%rsp), %rsi
callq 0x3e536
movq %rbp, %rdi
callq 0x63d48
xorpd %xmm1, %xmm1
ucomisd 0x30(%rsp), %xmm1
movsd 0x30(%rsp), %xmm1
ja 0x3f081
ucomisd %xmm0, %xmm1
ja 0x3f081
movapd %xmm1, %xmm0
jmp 0x3f090
movsd 0x38(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x3f090
movb $0x1, %r15b
movb 0x1b(%rsp), %cl
movapd %xmm0, %xmm1
incl %r13d
addl %r14d, %ebx
jmp 0x3efea
movl 0x2c(%rsp), %r8d
incl %r8d
movl 0x28(%rsp), %edi
jmp 0x3ef9a
incl %edi
jmp 0x3ef6e
notb %r15b
movzbl %r15b, %ecx
andl $0x1, %ecx
xorpd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
pushq $-0x1
popq %rax
cmovbel %ecx, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop