// File: jamesliu516[P]amrdg2d/setflag.cpp
// Function: setFlagForAll()
void setFlagForAll()
{
    Node *current;
    OctCell *lsbl;
    OctCell *lss;
    OctCell *lse;
    OctCell *lsw;
    OctCell *lsn;
    double x1,y1;
    int value, flg[N_BODY+1];

    current = HeadListAllGrid;

    double xcn[4],ycn[4];
    int flgn[4], sflg;	
    int i;
    int n0,n2,nm;

    while(current != NULL)
    {
        lsbl = current->cell;

        x1=lsbl->xc1;
        y1=lsbl->yc1;

        for (int jj=0; jj<N_BODY;++jj){
            value = newFlagpoint(x1,y1,NWallPts[jj], MultiCircle[jj]);
            if(value==0) {
                flg[jj]=value;
            }
            else if(value==-1) {
                lss=SouthNeighbor(lsbl);
                lse=EastNeighbor(lsbl);
                lsw=WestNeighbor(lsbl);
                lsn=NorthNeighbor(lsbl);
                xcn[0]=lss->xc1;
                ycn[0]=lss->yc1;
                xcn[1]=lse->xc1;
                ycn[1]=lse->yc1;	
                xcn[2]=lsn->xc1;
                ycn[2]=lsn->yc1;
                xcn[3]=lsw->xc1;
                ycn[3]=lsw->yc1;	        
                sflg=0;
                for(i=0; i<4; ++i) {      
                    flgn[i]=newFlagpoint(xcn[i],ycn[i],NWallPts[jj], MultiCircle[jj]);

                    if(flgn[i]==0) {
                        flg[jj]=2;
                        ++sflg;
                        break;
                    }
                }  

                if(sflg==0) flg[jj]=-1;       
            }		       
        }
        n0=n2=nm=0;

        for (int jj=0; jj<N_BODY;++jj){
            if(flg[jj]==0) ++n0;
            if(flg[jj]==2) ++n2;
            if(flg[jj]==-1) ++nm;
        }

        if(n0==N_BODY) lsbl->flag=0;
        else if(n2>0) lsbl->flag=2;
        else lsbl->flag=-1;
        current=current->next;
    }
}

// Assembly:
subq $0xc8, %rsp
leaq 0x48dc2(%rip), %rax     # 0x506a0
movq (%rax), %rax
movq %rax, 0xc0(%rsp)
cmpq $0x0, 0xc0(%rsp)
je 0x7c68
movq 0xc0(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0xb8(%rsp)
movq 0xb8(%rsp), %rax
movsd 0x278(%rax), %xmm0
movsd %xmm0, 0x90(%rsp)
movq 0xb8(%rsp), %rax
movsd 0x280(%rax), %xmm0
movsd %xmm0, 0x88(%rsp)
movl $0x0, 0x8(%rsp)
cmpl $0x1, 0x8(%rsp)
jge 0x7b8d
movsd 0x90(%rsp), %xmm0
movsd 0x88(%rsp), %xmm1
movslq 0x8(%rsp), %rcx
leaq 0x43921(%rip), %rax     # 0x4b290
movl (%rax,%rcx,4), %edi
movslq 0x8(%rsp), %rax
leaq 0x43a92(%rip), %rsi     # 0x4b410
imulq $0x1f40, %rax, %rax     # imm = 0x1F40
addq %rax, %rsi
callq 0x15ff0
movl %eax, 0x84(%rsp)
cmpl $0x0, 0x84(%rsp)
jne 0x79b3
movl 0x84(%rsp), %ecx
movslq 0x8(%rsp), %rax
movl %ecx, 0x7c(%rsp,%rax,4)
jmp 0x7b7b
cmpl $-0x1, 0x84(%rsp)
jne 0x7b79
movq 0xb8(%rsp), %rdi
callq 0x11a00
movq %rax, 0xb0(%rsp)
movq 0xb8(%rsp), %rdi
callq 0x118d0
movq %rax, 0xa8(%rsp)
movq 0xb8(%rsp), %rdi
callq 0x117a0
movq %rax, 0xa0(%rsp)
movq 0xb8(%rsp), %rdi
callq 0x11670
movq %rax, 0x98(%rsp)
movq 0xb0(%rsp), %rax
movsd 0x278(%rax), %xmm0
movsd %xmm0, 0x50(%rsp)
movq 0xb0(%rsp), %rax
movsd 0x280(%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
movq 0xa8(%rsp), %rax
movsd 0x278(%rax), %xmm0
movsd %xmm0, 0x58(%rsp)
movq 0xa8(%rsp), %rax
movsd 0x280(%rax), %xmm0
movsd %xmm0, 0x38(%rsp)
movq 0x98(%rsp), %rax
movsd 0x278(%rax), %xmm0
movsd %xmm0, 0x60(%rsp)
movq 0x98(%rsp), %rax
movsd 0x280(%rax), %xmm0
movsd %xmm0, 0x40(%rsp)
movq 0xa0(%rsp), %rax
movsd 0x278(%rax), %xmm0
movsd %xmm0, 0x68(%rsp)
movq 0xa0(%rsp), %rax
movsd 0x280(%rax), %xmm0
movsd %xmm0, 0x48(%rsp)
movl $0x0, 0x1c(%rsp)
movl $0x0, 0x18(%rsp)
cmpl $0x4, 0x18(%rsp)
jge 0x7b63
movslq 0x18(%rsp), %rax
movsd 0x50(%rsp,%rax,8), %xmm0
movslq 0x18(%rsp), %rax
movsd 0x30(%rsp,%rax,8), %xmm1
movslq 0x8(%rsp), %rcx
leaq 0x4378e(%rip), %rax     # 0x4b290
movl (%rax,%rcx,4), %edi
movslq 0x8(%rsp), %rax
leaq 0x438ff(%rip), %rsi     # 0x4b410
imulq $0x1f40, %rax, %rax     # imm = 0x1F40
addq %rax, %rsi
callq 0x15ff0
movl %eax, %ecx
movslq 0x18(%rsp), %rax
movl %ecx, 0x20(%rsp,%rax,4)
movslq 0x18(%rsp), %rax
cmpl $0x0, 0x20(%rsp,%rax,4)
jne 0x7b51
movslq 0x8(%rsp), %rax
movl $0x2, 0x7c(%rsp,%rax,4)
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x7b63
jmp 0x7b53
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
jmp 0x7ad5
cmpl $0x0, 0x1c(%rsp)
jne 0x7b77
movslq 0x8(%rsp), %rax
movl $0xffffffff, 0x7c(%rsp,%rax,4) # imm = 0xFFFFFFFF
jmp 0x7b79
jmp 0x7b7b
jmp 0x7b7d
movl 0x8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x8(%rsp)
jmp 0x7946
movl $0x0, 0xc(%rsp)
movl $0x0, 0x10(%rsp)
movl $0x0, 0x14(%rsp)
movl $0x0, 0x4(%rsp)
cmpl $0x1, 0x4(%rsp)
jge 0x7c08
movslq 0x4(%rsp), %rax
cmpl $0x0, 0x7c(%rsp,%rax,4)
jne 0x7bcb
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
movslq 0x4(%rsp), %rax
cmpl $0x2, 0x7c(%rsp,%rax,4)
jne 0x7be2
movl 0x10(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10(%rsp)
movslq 0x4(%rsp), %rax
cmpl $-0x1, 0x7c(%rsp,%rax,4)
jne 0x7bf9
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x7bfb
movl 0x4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4(%rsp)
jmp 0x7bad
cmpl $0x1, 0x14(%rsp)
jne 0x7c22
movq 0xb8(%rsp), %rax
movw $0x0, 0x1b0(%rax)
jmp 0x7c4f
cmpl $0x0, 0x10(%rsp)
jle 0x7c3c
movq 0xb8(%rsp), %rax
movw $0x2, 0x1b0(%rax)
jmp 0x7c4d
movq 0xb8(%rsp), %rax
movw $0xffff, 0x1b0(%rax)    # imm = 0xFFFF
jmp 0x7c4f
movq 0xc0(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0xc0(%rsp)
jmp 0x78e9
addq $0xc8, %rsp
retq