// File: 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
movq %rsp, %rbp
subq $0xb0, %rsp
movl %edi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movsd %xmm0, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movsd 0x15b7f3(%rip), %xmm0   # 0x1f2778
movsd %xmm0, -0x28(%rbp)
movb $0x0, -0x29(%rbp)
movl $0x0, -0x30(%rbp)
xorl %eax, %eax
cmpl $0x1, -0x30(%rbp)
movb %al, -0x89(%rbp)
jg 0x96fae
movb -0x29(%rbp), %al
xorb $-0x1, %al
movb %al, -0x89(%rbp)
movb -0x89(%rbp), %al
testb $0x1, %al
jne 0x96fbd
jmp 0x9713a
movl $0xffffffff, -0x34(%rbp) # imm = 0xFFFFFFFF
xorl %eax, %eax
cmpl $0x1, -0x34(%rbp)
movb %al, -0x8a(%rbp)
jg 0x96fdd
movb -0x29(%rbp), %al
xorb $-0x1, %al
movb %al, -0x8a(%rbp)
movb -0x8a(%rbp), %al
testb $0x1, %al
jne 0x96fec
jmp 0x9712a
movl $0xffffffff, -0x38(%rbp) # imm = 0xFFFFFFFF
xorl %eax, %eax
cmpl $0x1, -0x38(%rbp)
movb %al, -0x8b(%rbp)
jg 0x9700c
movb -0x29(%rbp), %al
xorb $-0x1, %al
movb %al, -0x8b(%rbp)
movb -0x8b(%rbp), %al
testb $0x1, %al
jne 0x9701b
jmp 0x9711a
cmpl $0x0, -0x30(%rbp)
jne 0x9702d
cmpl $0x0, -0x34(%rbp)
jne 0x9702d
cmpl $0x1, -0x38(%rbp)
je 0x97043
cmpl $0x0, -0x30(%rbp)
jne 0x97039
cmpl $0x1, -0x34(%rbp)
je 0x97043
cmpl $0x1, -0x30(%rbp)
jne 0x9710a
movl -0x8(%rbp), %eax
imull -0x30(%rbp), %eax
cvtsi2sd %eax, %xmm0
movl -0xc(%rbp), %eax
imull -0x34(%rbp), %eax
cvtsi2sd %eax, %xmm1
movl -0x10(%rbp), %eax
imull -0x38(%rbp), %eax
cvtsi2sd %eax, %xmm2
leaq -0x50(%rbp), %rdi
callq 0xe9c70
movq -0x20(%rbp), %rsi
movq -0x50(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x70(%rbp)
leaq -0x68(%rbp), %rdi
leaq -0x80(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0x961d0
leaq -0x68(%rbp), %rdi
callq 0xe9fb0
movsd %xmm0, -0x88(%rbp)
movsd -0x88(%rbp), %xmm1
movsd -0x28(%rbp), %xmm0
ucomisd %xmm1, %xmm0
ja 0x970dd
xorps %xmm0, %xmm0
ucomisd -0x28(%rbp), %xmm0
jbe 0x97108
movsd -0x88(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
movsd -0x28(%rbp), %xmm1
movsd 0x15af41(%rip), %xmm0   # 0x1f2038
addsd -0x18(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x97106
movb $0x1, -0x29(%rbp)
jmp 0x97108
jmp 0x9710a
jmp 0x9710c
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x96ff3
jmp 0x9711c
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x96fc4
jmp 0x9712c
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x96f95
xorps %xmm0, %xmm0
ucomisd -0x28(%rbp), %xmm0
jbe 0x9714d
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x97163
testb $0x1, -0x29(%rbp)
je 0x9715c
movl $0x0, -0x4(%rbp)
jmp 0x97163
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
nop