// File: icemiliang[P]vot/src/vot/container.cc
// Function: voro::container::cell_index(double, double, double)
int container::cell_index(double x, double y, double z) {
    int ai, aj, ak, ci, cj, ck, ijk;
    particle_record w;
    double mrs;

    // If the given vector lies outside the domain, but the container
    // is periodic, then remap it back into the domain
    if (!remap(ai, aj, ak, ci, cj, ck, x, y, z, ijk)) return false;
    vc.find_voronoi_cell(x, y, z, ci, cj, ck, ijk, w, mrs);

    if (w.ijk != -1) {

        // Assemble the position vector of the particle to be returned,
        // applying a periodic remapping if necessary
        if (xperiodic) { ci += w.di; if (ci<0 || ci >= nx) ai += step_div(ci, nx); }
        if (yperiodic) { cj += w.dj; if (cj<0 || cj >= ny) aj += step_div(cj, ny); }
        if (zperiodic) { ck += w.dk; if (ck<0 || ck >= nz) ak += step_div(ck, nz); }
        
        // return cellIndex
        return id[w.ijk][w.l];
    }

    // If no particle if found then just return false
    return -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x90, %rsp
movq %rdi, -0x20(%rbp)
movsd %xmm0, -0x28(%rbp)
movsd %xmm1, -0x30(%rbp)
movsd %xmm2, -0x38(%rbp)
movq -0x20(%rbp), %rdi
movq %rdi, -0x78(%rbp)
leaq -0x3c(%rbp), %rsi
leaq -0x40(%rbp), %rdx
leaq -0x44(%rbp), %rcx
leaq -0x48(%rbp), %r8
leaq -0x4c(%rbp), %r9
leaq -0x50(%rbp), %r14
leaq -0x28(%rbp), %rbx
leaq -0x30(%rbp), %r11
leaq -0x38(%rbp), %r10
leaq -0x54(%rbp), %rax
movq %r14, (%rsp)
movq %rbx, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq %rax, 0x20(%rsp)
callq 0x589f0
testb $0x1, %al
jne 0x56f0e
movl $0x0, -0x14(%rbp)
jmp 0x57031
movq -0x78(%rbp), %rdi
addq $0xd0, %rdi
movsd -0x28(%rbp), %xmm0
movsd -0x30(%rbp), %xmm1
movsd -0x38(%rbp), %xmm2
movl -0x48(%rbp), %esi
movl -0x4c(%rbp), %edx
movl -0x50(%rbp), %ecx
movl -0x54(%rbp), %r8d
leaq -0x68(%rbp), %r9
leaq -0x70(%rbp), %rax
movq %rax, (%rsp)
callq 0x63360
cmpl $-0x1, -0x68(%rbp)
je 0x5702a
movq -0x78(%rbp), %rax
testb $0x1, 0xa0(%rax)
je 0x56f8d
movl -0x60(%rbp), %eax
addl -0x48(%rbp), %eax
movl %eax, -0x48(%rbp)
cmpl $0x0, -0x48(%rbp)
jl 0x56f77
movq -0x78(%rbp), %rcx
movl -0x48(%rbp), %eax
cmpl (%rcx), %eax
jl 0x56f8b
movq -0x78(%rbp), %rdi
movl -0x48(%rbp), %esi
movl (%rdi), %edx
callq 0x58ce0
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
jmp 0x56f8d
movq -0x78(%rbp), %rax
testb $0x1, 0xa1(%rax)
je 0x56fcc
movl -0x5c(%rbp), %eax
addl -0x4c(%rbp), %eax
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
jl 0x56fb5
movq -0x78(%rbp), %rcx
movl -0x4c(%rbp), %eax
cmpl 0x4(%rcx), %eax
jl 0x56fca
movq -0x78(%rbp), %rdi
movl -0x4c(%rbp), %esi
movl 0x4(%rdi), %edx
callq 0x58ce0
addl -0x40(%rbp), %eax
movl %eax, -0x40(%rbp)
jmp 0x56fcc
movq -0x78(%rbp), %rax
testb $0x1, 0xa2(%rax)
je 0x5700b
movl -0x58(%rbp), %eax
addl -0x50(%rbp), %eax
movl %eax, -0x50(%rbp)
cmpl $0x0, -0x50(%rbp)
jl 0x56ff4
movq -0x78(%rbp), %rcx
movl -0x50(%rbp), %eax
cmpl 0x8(%rcx), %eax
jl 0x57009
movq -0x78(%rbp), %rdi
movl -0x50(%rbp), %esi
movl 0x8(%rdi), %edx
callq 0x58ce0
addl -0x44(%rbp), %eax
movl %eax, -0x44(%rbp)
jmp 0x5700b
movq -0x78(%rbp), %rax
movq 0xa8(%rax), %rax
movslq -0x68(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x64(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x14(%rbp)
jmp 0x57031
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
movl -0x14(%rbp), %eax
addq $0x90, %rsp
popq %rbx
popq %r14
popq %rbp
retq