// File: /workspace/github_cpp_makefile_star2_O1/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 %esi, 0x24(%rsp)
movl %edi, 0x1c(%rsp)
addsd 0xfc14c(%rip), %xmm0    # 0x14f048
movsd %xmm0, 0x38(%rsp)
movl %edx, 0x2c(%rsp)
movl %edx, %eax
negl %eax
movl %eax, 0x20(%rsp)
movsd 0x1003ba(%rip), %xmm1   # 0x1532d0
xorl %edx, %edx
xorl %r15d, %r15d
testb $0x1, %r15b
jne 0x53056
movl %edx, %eax
imull 0x1c(%rsp), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x48(%rsp)
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl %edx, 0x18(%rsp)
testb $0x1, %r15b
movl %esi, 0x28(%rsp)
jne 0x53038
cmpl $0x1, %edx
sete %al
movl %esi, %r14d
orl %edx, %r14d
movl %esi, %ecx
xorl $0x1, %ecx
orl %edx, %ecx
sete %bl
orb %al, %bl
movl %esi, %eax
imull 0x24(%rsp), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x50(%rsp)
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movl 0x20(%rsp), %r12d
movl %r13d, %eax
xorl $0x1, %eax
orl %r14d, %eax
sete %al
orb %bl, %al
cmpb $0x1, %al
jne 0x53021
xorps %xmm2, %xmm2
cvtsi2sd %r12d, %xmm2
leaq 0x58(%rsp), %rdi
movsd 0x48(%rsp), %xmm0
movsd %xmm1, 0x30(%rsp)
movsd 0x50(%rsp), %xmm1
callq 0x85436
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 0x52144
movq %rbp, %rdi
callq 0x8555a
xorpd %xmm1, %xmm1
ucomisd 0x30(%rsp), %xmm1
movsd 0x30(%rsp), %xmm1
ja 0x5300e
ucomisd %xmm0, %xmm1
ja 0x5300e
movapd %xmm1, %xmm0
jmp 0x5301d
movsd 0x38(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x5301d
movb $0x1, %r15b
movapd %xmm0, %xmm1
testl %r13d, %r13d
jg 0x53038
incl %r13d
addl 0x2c(%rsp), %r12d
testb $0x1, %r15b
je 0x52f87
movl 0x28(%rsp), %esi
testl %esi, %esi
jg 0x53052
incl %esi
testb $0x1, %r15b
movl 0x18(%rsp), %edx
je 0x52f42
jmp 0x53056
movl 0x18(%rsp), %edx
testl %edx, %edx
jne 0x53066
incl %edx
testb $0x1, %r15b
je 0x52f1b
notb %r15b
movzbl %r15b, %ecx
andl $0x1, %ecx
xorpd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmovbel %ecx, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq