// File: /workspace/github_cpp_makefile_star2_O2/Luthaf[P]zeopp/networkstorage.cc
// Function: ATOM_NETWORK::getSmallestSupercell(double)
TRIPLET ATOM_NETWORK::getSmallestSupercell(double diam) {
    //1) set lower bound based on lengths of cell axes
    int na = 1+ (diam/a);
    int nb = 1+ (diam/b);
    int nc = 1+ (diam/c);
    
    int fewest_cells = -1; //no supercell yet successful
    TRIPLET smallest_supercell(-1,-1,-1);
    
    //2) search all possible supercell sizes to find the smallest one satisfying
    // the minimum image convention for this radius
    TRIPLET lb(na, nb, nc);
    vector<TRIPLET> supercells;
    supercells.push_back(lb);
    while(supercells.size()>0) {
        //3) take the oldest candidate on the vector
        TRIPLET s = supercells.at(0); //oldest supercell candidate, s
        for(int i=0; i<supercells.size()-1; i++)
            supercells.at(i) = supercells.at(i+1); //shift vector up
        supercells.pop_back(); //delete last, which is now duplicated at last-1
        int num_cells = s.x*s.y*s.z;
        //4) is s a potential new smallest supercell?
        if(num_cells<fewest_cells || fewest_cells<0) {
            //5) does s satisfy the minimum image convention?
            int status = check_sphere_overlap(s.x, s.y, s.z, diam, this); //For time being
            if(status==-1) {
                printf("WARNING: bad unit cell angles!\n");
                return smallest_supercell;
            } else if(status==1) { //acceptable!
                fewest_cells = num_cells;
                smallest_supercell = s;
                //printf("smallest satisfactory supercell so far: (%d %d %d) =
                //%d cells\n", s.a, s.b, s.c, num_cells);
            } else { //unacceptable - try larger supercells in each direction
                TRIPLET s2(s.x+1, s.y, s.z);
                TRIPLET s3(s.x, s.y+1, s.z);
                TRIPLET s4(s.x, s.y, s.z+1);
                supercells.push_back(s2);
                supercells.push_back(s3);
                supercells.push_back(s4);
            }
        }
    }
    return smallest_supercell;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movapd %xmm0, %xmm2
divsd 0x8(%rsi), %xmm2
movsd 0xbd382(%rip), %xmm1    # 0xfc058
addsd %xmm1, %xmm2
cvttsd2si %xmm2, %ebx
movapd %xmm0, %xmm2
divsd 0x10(%rsi), %xmm2
addsd %xmm1, %xmm2
cvttsd2si %xmm2, %ebp
movsd %xmm0, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
divsd 0x18(%rsi), %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %r14d
pushq $-0x1
popq %rcx
movq %rdi, 0x30(%rsp)
movl %ecx, %esi
movl %ecx, %edx
movl %ecx, %r13d
callq 0x63fa0
leaq 0xa0(%rsp), %r15
movq %r15, %rdi
movl %ebx, %esi
movl %ebp, %edx
movl %r14d, %ecx
callq 0x63fa0
xorpd %xmm0, %xmm0
leaq 0x10(%rsp), %rdi
movapd %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
movq %r15, %rsi
callq 0x4b5f8
leaq 0x10(%rsp), %r15
pushq $0x18
popq %r12
movl %r13d, %r14d
movq 0x10(%rsp), %rcx
movq 0x18(%rsp), %r8
cmpq %rcx, %r8
je 0x3eee8
movl %r14d, %ebx
movq %r15, %rdi
xorl %esi, %esi
callq 0x4b61e
movl 0x8(%rax), %ecx
movl %ecx, 0x40(%rsp)
movq (%rax), %rcx
movq %rcx, 0x38(%rsp)
movl 0xc(%rax), %r13d
movl 0x10(%rax), %ecx
movq %rcx, 0x8(%rsp)
movl 0x14(%rax), %eax
movl %eax, 0x4(%rsp)
xorl %r14d, %r14d
movq 0x10(%rsp), %rcx
movq 0x18(%rsp), %r8
movq %r8, %rax
subq %rcx, %rax
cqto
idivq %r12
decq %rax
cmpq %r14, %rax
jbe 0x3edf0
incq %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x4b61e
movq %rax, %rbp
decq %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x4b61e
movq 0x10(%rbp), %rcx
movq %rcx, 0x10(%rax)
movupd (%rbp), %xmm0
movupd %xmm0, (%rax)
incq %r14
jmp 0x3ed9e
addq $-0x18, %r8
movq 0x8(%rsp), %rsi
movl %esi, %ebp
movq %r13, %rdi
imull %edi, %ebp
movl 0x4(%rsp), %edx
imull %edx, %ebp
movq %r8, 0x18(%rsp)
movl %ebx, %r14d
testl %ebx, %ebx
js 0x3ee1d
cmpl %r14d, %ebp
jge 0x3ed63
movsd 0x50(%rsp), %xmm0
movq 0x48(%rsp), %rcx
callq 0x3ef2a
cmpl $0x1, %eax
je 0x3eead
cmpl $-0x1, %eax
je 0x3eedc
leal 0x1(%r13), %esi
leaq 0x88(%rsp), %rdi
movq 0x8(%rsp), %rbx
movl %ebx, %edx
movl 0x4(%rsp), %ebp
movl %ebp, %ecx
callq 0x63fa0
leal 0x1(%rbx), %edx
leaq 0x70(%rsp), %rdi
movl %r13d, %esi
movl %ebp, %ecx
callq 0x63fa0
incl %ebp
leaq 0x58(%rsp), %rdi
movl %r13d, %esi
movl %ebx, %edx
movl %ebp, %ecx
callq 0x63fa0
movq %r15, %rdi
leaq 0x88(%rsp), %rsi
callq 0x4b5f8
movq %r15, %rdi
leaq 0x70(%rsp), %rsi
callq 0x4b5f8
movq %r15, %rdi
leaq 0x58(%rsp), %rsi
callq 0x4b5f8
jmp 0x3ed59
movl 0x40(%rsp), %eax
movq 0x30(%rsp), %rcx
movl %eax, 0x8(%rcx)
movq 0x38(%rsp), %rax
movq %rax, (%rcx)
movl %r13d, 0xc(%rcx)
movq 0x8(%rsp), %rax
movl %eax, 0x10(%rcx)
movl 0x4(%rsp), %eax
movl %eax, 0x14(%rcx)
movl %ebp, %r14d
jmp 0x3ed59
leaq 0xc3fb5(%rip), %rdi     # 0x102e98
callq 0x4670
leaq 0x10(%rsp), %rdi
callq 0x4c68c
movq 0x30(%rsp), %rax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3ef15
jmp 0x3ef15
jmp 0x3ef15
jmp 0x3ef15
jmp 0x3ef15
jmp 0x3ef15
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x4c68c
movq %rbx, %rdi
callq 0x4780