// File: /workspace/github_cpp_makefile_star2_O1/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 0xfc4ac(%rip), %xmm1    # 0x14f058
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 0x858ee
leaq 0x90(%rsp), %rdi
movl %ebp, %esi
movl %r15d, %edx
movl %r12d, %ecx
callq 0x858ee
xorpd %xmm0, %xmm0
movapd %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movq 0x8(%rsp), %rsi
testq %rsi, %rsi
je 0x52c4a
movq 0xa0(%rsp), %rax
movq %rax, 0x10(%rsi)
movupd 0x90(%rsp), %xmm0
movupd %xmm0, (%rsi)
addq $0x18, 0x8(%rsp)
jmp 0x52c5a
movq %rsp, %rdi
leaq 0x90(%rsp), %rdx
callq 0x68d54
movl $0xffffffff, 0x1c(%rsp) # imm = 0xFFFFFFFF
movabsq $-0x5555555555555555, %r13 # imm = 0xAAAAAAAAAAAAAAAB
movq (%rsp), %rax
cmpq %rax, 0x8(%rsp)
je 0x52e70
movl 0x8(%rax), %ecx
movl %ecx, 0x30(%rsp)
movq (%rax), %rcx
movq %rcx, 0x28(%rsp)
movl 0xc(%rax), %r12d
movl 0x10(%rax), %r15d
movl 0x14(%rax), %ebp
movq (%rsp), %rax
movq 0x8(%rsp), %rdi
movq %rdi, %rdx
subq %rax, %rdx
cmpq $0x18, %rdx
je 0x52d02
sarq $0x3, %rdx
imulq %r13, %rdx
movl $0x1, %esi
xorl %ecx, %ecx
cmpq %rsi, %rdx
jbe 0x52e9d
movq 0x28(%rax,%rcx), %rdx
movq %rdx, 0x10(%rax,%rcx)
movupd 0x18(%rax,%rcx), %xmm0
movupd %xmm0, (%rax,%rcx)
movq (%rsp), %rax
movq 0x8(%rsp), %rdi
movq %rdi, %rdx
subq %rax, %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 0x52cb9
addq $-0x18, %rdi
movq %rdi, 0x8(%rsp)
movl %r15d, %r14d
imull %r12d, %r14d
imull %ebp, %r14d
movl 0x1c(%rsp), %ecx
cmpl %ecx, %r14d
setl %al
testl %ecx, %ecx
sets %cl
orb %al, %cl
movb $0x1, %bl
je 0x52e68
movl %r12d, %edi
movl %r15d, %esi
movl %ebp, %edx
movsd 0x40(%rsp), %xmm0
movq 0x38(%rsp), %rcx
callq 0x52ed6
cmpl $-0x1, %eax
setne %bl
je 0x52d7d
cmpl $0x1, %eax
jne 0x52d8e
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 %r14d, 0x1c(%rsp)
jmp 0x52e68
leaq 0x1030c4(%rip), %rdi    # 0x155e48
callq 0x4660
jmp 0x52e68
leal 0x1(%r12), %esi
leaq 0x78(%rsp), %rdi
movl %r15d, %edx
movl %ebp, %ecx
callq 0x858ee
leal 0x1(%r15), %edx
leaq 0x60(%rsp), %rdi
movl %r12d, %esi
movl %ebp, %ecx
callq 0x858ee
incl %ebp
leaq 0x48(%rsp), %rdi
movl %r12d, %esi
movl %r15d, %edx
movl %ebp, %ecx
callq 0x858ee
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x52df3
movq 0x88(%rsp), %rax
movq %rax, 0x10(%rsi)
movupd 0x78(%rsp), %xmm0
movupd %xmm0, (%rsi)
addq $0x18, 0x8(%rsp)
jmp 0x52e00
movq %rsp, %rdi
leaq 0x78(%rsp), %rdx
callq 0x68d54
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x52e27
movq 0x70(%rsp), %rax
movq %rax, 0x10(%rsi)
movupd 0x60(%rsp), %xmm0
movupd %xmm0, (%rsi)
addq $0x18, 0x8(%rsp)
jmp 0x52e34
movq %rsp, %rdi
leaq 0x60(%rsp), %rdx
callq 0x68d54
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x52e5b
movq 0x58(%rsp), %rax
movq %rax, 0x10(%rsi)
movupd 0x48(%rsp), %xmm0
movupd %xmm0, (%rsi)
addq $0x18, 0x8(%rsp)
jmp 0x52e68
movq %rsp, %rdi
leaq 0x48(%rsp), %rdx
callq 0x68d54
testb %bl, %bl
jne 0x52c6c
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x52e86
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 0xfc801(%rip), %rdi     # 0x14f6a5
xorl %eax, %eax
callq 0x4630
jmp 0x52eb5
jmp 0x52eb5
jmp 0x52eb5
jmp 0x52eb5
jmp 0x52eb5
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x52ece
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq %rbx, %rdi
callq 0x4780