// File: jamesliu516[P]amrdg2d/wall4amrdg2013.cpp
// Function: findIntpltCell(bodygridclass*, pointxy const&, pointxy const&, std::vector<bodygridclass*, std::allocator<bodygridclass*>>&)
void findIntpltCell(OctCell * incell, const PXYZ &gstp, const PXYZ &smtricp, vector< OctCell * > &grid) 
{
    PXYZ drct, drct1;  
    OctCell *pp[8]={NULL};
    set<OctCell*> grid_set;

    grid.clear();
    pp[0]=EastNeighbor(incell);
    pp[1]=NorthNeighbor(pp[0]);
    pp[2]=NorthNeighbor(incell);
    pp[3]=WestNeighbor(pp[2]);
    pp[4]=WestNeighbor(incell);
    pp[5]=SouthNeighbor(pp[4]);
    pp[6]=SouthNeighbor(incell);
    pp[7]=EastNeighbor(pp[6]);

    drct.x=smtricp.x-gstp.x;
    drct.y=smtricp.y-gstp.y;
    // cout<<iy<<" "<<ix<<endl;
    //cout<<smtricp.x<<" "<<smtricp.y<<endl;
    insert_cell(incell, grid_set);
    for(int ii=0;ii<8;++ii) insert_cell(pp[ii], grid_set);

    for(set<OctCell*>::iterator itset=grid_set.begin(); itset!=grid_set.end(); ++itset) {
        if((*itset)->flag==0) {
            drct1.x= (*itset)->xc1-gstp.x;
            drct1.y= (*itset)->yc1-gstp.y;  
            if(drct.x*drct1.x+drct.y*drct1.y+1.0 >= 1.0) {
                grid.push_back(*itset); 
            }          
        }
    }

#ifdef DEBUG
    int itm;
    if(grid.size()==0){
        cout << "wrong findIntpltCell"<< endl;
        cout<<gstp.x<<" "<<gstp.y<<", "<<smtricp.x<<"  "<<smtricp.y<<endl;
        cin>>itm;
    }
#endif
}

// Assembly:
subq $0x168, %rsp            # imm = 0x168
movq %rdi, 0x160(%rsp)
movq %rsi, 0x158(%rsp)
movq %rdx, 0x150(%rsp)
movq %rcx, 0x148(%rsp)
leaq 0x138(%rsp), %rdi
callq 0x6310
leaq 0x128(%rsp), %rdi
callq 0x6310
xorps %xmm0, %xmm0
movaps %xmm0, 0x110(%rsp)
movaps %xmm0, 0x100(%rsp)
movaps %xmm0, 0xf0(%rsp)
movaps %xmm0, 0xe0(%rsp)
leaq 0xb0(%rsp), %rdi
callq 0x6510
movq 0x148(%rsp), %rdi
callq 0x1b440
movq 0x160(%rsp), %rdi
callq 0x118d0
movq %rax, 0x80(%rsp)
jmp 0x2a945
movq 0x80(%rsp), %rax
movq %rax, 0xe0(%rsp)
movq 0xe0(%rsp), %rdi
callq 0x11670
movq %rax, 0x78(%rsp)
jmp 0x2a969
movq 0x78(%rsp), %rax
movq %rax, 0xe8(%rsp)
movq 0x160(%rsp), %rdi
callq 0x11670
movq %rax, 0x70(%rsp)
jmp 0x2a98a
movq 0x70(%rsp), %rax
movq %rax, 0xf0(%rsp)
movq 0xf0(%rsp), %rdi
callq 0x117a0
movq %rax, 0x68(%rsp)
jmp 0x2a9ab
movq 0x68(%rsp), %rax
movq %rax, 0xf8(%rsp)
movq 0x160(%rsp), %rdi
callq 0x117a0
movq %rax, 0x60(%rsp)
jmp 0x2a9cc
movq 0x60(%rsp), %rax
movq %rax, 0x100(%rsp)
movq 0x100(%rsp), %rdi
callq 0x11a00
movq %rax, 0x58(%rsp)
jmp 0x2a9ed
movq 0x58(%rsp), %rax
movq %rax, 0x108(%rsp)
movq 0x160(%rsp), %rdi
callq 0x11a00
movq %rax, 0x50(%rsp)
jmp 0x2aa0e
movq 0x50(%rsp), %rax
movq %rax, 0x110(%rsp)
movq 0x110(%rsp), %rdi
callq 0x118d0
movq %rax, 0x48(%rsp)
jmp 0x2aa2f
movq 0x48(%rsp), %rax
movq %rax, 0x118(%rsp)
movq 0x150(%rsp), %rax
movsd (%rax), %xmm0
movq 0x158(%rsp), %rax
movsd (%rax), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, 0x138(%rsp)
movq 0x150(%rsp), %rax
movsd 0x8(%rax), %xmm0
movq 0x158(%rsp), %rax
movsd 0x8(%rax), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, 0x140(%rsp)
movq 0x160(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x2a830
jmp 0x2aa9f
movl $0x0, 0xa0(%rsp)
cmpl $0x8, 0xa0(%rsp)
jge 0x2ab0e
movslq 0xa0(%rsp), %rax
movq 0xe0(%rsp,%rax,8), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x2a830
jmp 0x2aad3
jmp 0x2aad5
movl 0xa0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xa0(%rsp)
jmp 0x2aaaa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa8(%rsp)
movl %eax, 0xa4(%rsp)
leaq 0xb0(%rsp), %rdi
callq 0x6520
jmp 0x2ad9a
leaq 0xb0(%rsp), %rdi
callq 0xb6f0
movq %rax, 0x98(%rsp)
leaq 0xb0(%rsp), %rdi
callq 0xb740
movq %rax, 0x90(%rsp)
leaq 0x98(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0xb720
testb $0x1, %al
jne 0x2ab56
jmp 0x2ac58
leaq 0x98(%rsp), %rdi
callq 0xb770
movq (%rax), %rax
movswl 0x1b0(%rax), %eax
cmpl $0x0, %eax
jne 0x2ac44
leaq 0x98(%rsp), %rdi
callq 0xb770
movq (%rax), %rax
movsd 0x278(%rax), %xmm0
movq 0x158(%rsp), %rax
subsd (%rax), %xmm0
movsd %xmm0, 0x128(%rsp)
leaq 0x98(%rsp), %rdi
callq 0xb770
movq (%rax), %rax
movsd 0x280(%rax), %xmm0
movq 0x158(%rsp), %rax
subsd 0x8(%rax), %xmm0
movsd %xmm0, 0x130(%rsp)
movsd 0x138(%rsp), %xmm0
movsd 0x128(%rsp), %xmm2
movsd 0x140(%rsp), %xmm1
mulsd 0x130(%rsp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd 0x14453(%rip), %xmm1    # 0x3f058
addsd %xmm1, %xmm0
movsd 0x14447(%rip), %xmm1    # 0x3f058
ucomisd %xmm1, %xmm0
jb 0x2ac42
movq 0x148(%rsp), %rax
movq %rax, 0x40(%rsp)
leaq 0x98(%rsp), %rdi
callq 0xb770
movq 0x40(%rsp), %rdi
movq %rax, %rsi
callq 0x1b460
jmp 0x2ac40
jmp 0x2ac42
jmp 0x2ac44
jmp 0x2ac46
leaq 0x98(%rsp), %rdi
callq 0xb850
jmp 0x2ab23
movq 0x148(%rsp), %rdi
callq 0x1bd50
cmpq $0x0, %rax
jne 0x2ad85
movq 0x2035a(%rip), %rdi     # 0x4afd0
leaq 0x14be1(%rip), %rsi     # 0x3f85e
callq 0x3240
movq %rax, 0x38(%rsp)
jmp 0x2ac89
movq 0x38(%rsp), %rdi
movq 0x20323(%rip), %rsi     # 0x4afb8
callq 0x3290
jmp 0x2ac9c
movq 0x158(%rsp), %rax
movsd (%rax), %xmm0
movq 0x20321(%rip), %rdi     # 0x4afd0
callq 0x3480
movq %rax, 0x30(%rsp)
jmp 0x2acbb
movq 0x30(%rsp), %rdi
leaq 0x14fc7(%rip), %rsi     # 0x3fc8e
callq 0x3240
movq %rax, 0x28(%rsp)
jmp 0x2acd3
movq 0x28(%rsp), %rdi
movq 0x158(%rsp), %rax
movsd 0x8(%rax), %xmm0
callq 0x3480
movq %rax, 0x20(%rsp)
jmp 0x2acf1
movq 0x20(%rsp), %rdi
leaq 0x14b76(%rip), %rsi     # 0x3f873
callq 0x3240
movq %rax, 0x18(%rsp)
jmp 0x2ad09
movq 0x18(%rsp), %rdi
movq 0x150(%rsp), %rax
movsd (%rax), %xmm0
callq 0x3480
movq %rax, 0x10(%rsp)
jmp 0x2ad26
movq 0x10(%rsp), %rdi
leaq 0x14f5b(%rip), %rsi     # 0x3fc8d
callq 0x3240
movq %rax, 0x8(%rsp)
jmp 0x2ad3e
movq 0x8(%rsp), %rdi
movq 0x150(%rsp), %rax
movsd 0x8(%rax), %xmm0
callq 0x3480
movq %rax, (%rsp)
jmp 0x2ad5b
movq (%rsp), %rdi
movq 0x20252(%rip), %rsi     # 0x4afb8
callq 0x3290
jmp 0x2ad6d
movq 0x2026c(%rip), %rdi     # 0x4afe0
leaq 0x8c(%rsp), %rsi
callq 0x3160
jmp 0x2ad83
jmp 0x2ad85
leaq 0xb0(%rsp), %rdi
callq 0x6520
addq $0x168, %rsp            # imm = 0x168
retq
movq 0xa8(%rsp), %rdi
callq 0x3440
nopw (%rax,%rax)