// File: /workspace/github_cpp_makefile_star2_O3/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 $0xa8, %rsp
movapd %xmm0, %xmm2
divsd 0x8(%rsi), %xmm2
movsd 0xfa7a4(%rip), %xmm1    # 0x14d058
addsd %xmm1, %xmm2
cvttsd2si %xmm2, %ebp
movapd %xmm0, %xmm2
divsd 0x10(%rsi), %xmm2
addsd %xmm1, %xmm2
cvttsd2si %xmm2, %r15d
movsd %xmm0, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
divsd 0x18(%rsi), %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %r12d
movq %rdi, 0x20(%rsp)
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x842d4
leaq 0x90(%rsp), %r13
movq %r13, %rdi
movl %ebp, %esi
movl %r15d, %edx
movl %r12d, %ecx
callq 0x842d4
xorpd %xmm0, %xmm0
movq %rsp, %rdi
movapd %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
xorl %esi, %esi
movq %r13, %rdx
callq 0x683e8
movq (%rsp), %rdi
movq 0x8(%rsp), %rax
cmpq %rdi, %rax
je 0x52b52
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movabsq $-0x5555555555555555, %r13 # imm = 0xAAAAAAAAAAAAAAAB
movl 0x8(%rdi), %ecx
movl %ecx, 0x30(%rsp)
movq (%rdi), %rcx
movq %rcx, 0x28(%rsp)
movl 0xc(%rdi), %r12d
movl 0x10(%rdi), %r15d
movl 0x14(%rdi), %ebp
movq %rax, %rdx
subq %rdi, %rdx
cmpq $0x18, %rdx
je 0x529d5
sarq $0x3, %rdx
imulq %r13, %rdx
movl $0x1, %esi
xorl %ecx, %ecx
cmpq %rsi, %rdx
jbe 0x52b7b
movq 0x28(%rdi,%rcx), %rax
movq %rax, 0x10(%rdi,%rcx)
movupd 0x18(%rdi,%rcx), %xmm0
movupd %xmm0, (%rdi,%rcx)
movq (%rsp), %rdi
movq 0x8(%rsp), %rax
movq %rax, %rdx
subq %rdi, %rdx
sarq $0x3, %rdx
imulq %r13, %rdx
leaq -0x1(%rdx), %r8
addq $0x18, %rcx
leaq 0x1(%rsi), %r9
cmpq %rsi, %r8
movq %r9, %rsi
ja 0x5298c
addq $-0x18, %rax
movl %r15d, %ebx
imull %r12d, %ebx
imull %ebp, %ebx
movq %rax, 0x8(%rsp)
testl %r14d, %r14d
js 0x52a00
cmpl %r14d, %ebx
jl 0x52a00
cmpq %rdi, %rax
jne 0x52957
jmp 0x52b52
movl %r12d, %edi
movl %r15d, %esi
movl %ebp, %edx
movsd 0x40(%rsp), %xmm0
movq 0x38(%rsp), %rcx
callq 0x52bb4
cmpl $0x1, %eax
je 0x52a93
cmpl $-0x1, %eax
je 0x52b42
leal 0x1(%r12), %esi
leaq 0x78(%rsp), %rdi
movl %r15d, %edx
movl %ebp, %ecx
callq 0x842d4
leal 0x1(%r15), %edx
leaq 0x60(%rsp), %rdi
movl %r12d, %esi
movl %ebp, %ecx
callq 0x842d4
incl %ebp
leaq 0x48(%rsp), %rdi
movl %r12d, %esi
movl %r15d, %edx
movl %ebp, %ecx
callq 0x842d4
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x52ab7
movq 0x88(%rsp), %rax
movq %rax, 0x10(%rsi)
movupd 0x78(%rsp), %xmm0
movupd %xmm0, (%rsi)
movq 0x8(%rsp), %rsi
addq $0x18, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x52ac9
movl 0x30(%rsp), %eax
movq 0x20(%rsp), %rcx
movl %eax, 0x8(%rcx)
movq 0x28(%rsp), %rax
movq %rax, (%rcx)
movl %r12d, 0xc(%rcx)
movl %r15d, 0x10(%rcx)
movl %ebp, 0x14(%rcx)
movl %ebx, %r14d
jmp 0x52b34
movq %rsp, %rdi
leaq 0x78(%rsp), %rdx
callq 0x683e8
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x52af3
movq 0x70(%rsp), %rax
movq %rax, 0x10(%rsi)
movupd 0x60(%rsp), %xmm0
movupd %xmm0, (%rsi)
movq 0x8(%rsp), %rsi
addq $0x18, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x52b05
movq %rsp, %rdi
leaq 0x60(%rsp), %rdx
callq 0x683e8
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x52b27
movq 0x58(%rsp), %rax
movq %rax, 0x10(%rsi)
movupd 0x48(%rsp), %xmm0
movupd %xmm0, (%rsi)
addq $0x18, 0x8(%rsp)
jmp 0x52b34
movq %rsp, %rdi
leaq 0x48(%rsp), %rdx
callq 0x683e8
movq (%rsp), %rdi
movq 0x8(%rsp), %rax
jmp 0x529f2
leaq 0x1013ef(%rip), %rdi    # 0x153f38
callq 0x4660
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x52b64
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x20(%rsp), %rax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xfab73(%rip), %rdi     # 0x14d6f5
xorl %eax, %eax
callq 0x4630
jmp 0x52b93
jmp 0x52b93
jmp 0x52b93
jmp 0x52b93
jmp 0x52b93
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x52bac
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq %rbx, %rdi
callq 0x4780