// File: /workspace/github_cpp_makefile_star2_O2/jamesliu516[P]amrdg2d/amr_grid_treat.cpp
// Function: charggrid(bodygridclass*)
void charggrid(OctCell *pg)//pgΪ������Ԫ��ָ��
{
    int flag[N_BODY+1],i;
    int exflag;
    //double plevel;
    double x[4],y[4];//���񶥵�������
    double hcx,xc,yc, hcy;
    int pflag[N_BODY+1][4];
    int n0,nm1,n2; 
    //plevel=pg->level+1.0;	
    //hc=h/pow(2.0,plevel);//�������Ĳ���	
    hcx=0.5*pg->dx;
    hcy=0.5*pg->dy;

    xc=pg->xc1;
    yc=pg->yc1;
#if IS_TUBE ==1
    exflag=newFlagpoint(xc,yc,NPT_EXT_WALL,ext_wall);
    pg->exflag=(exflag==0?-1:0);
#endif

    x[0]=xc-hcx; y[0]=yc-hcy;
    x[1]=xc-hcx; y[1]=yc+hcy;	
    x[2]=xc+hcx; y[2]=yc-hcy;
    x[3]=xc+hcx; y[3]=yc+hcy;
    //-------------------
    for (int jj=0; jj<N_BODY;++jj){
        for(i=0;i<4;i++) {
            pflag[jj][i]=newFlagpoint(x[i],y[i],
                NWallPts[jj], MultiCircle[jj]);
        }

        if(pflag[jj][0]==-1 && pflag[jj][1]==-1
            && pflag[jj][2]==-1 && pflag[jj][3]==-1)
        {
            flag[jj]=-1;
            // pg->flag=-1;
        }
        else if(pflag[jj][0]==0 && pflag[jj][1]==0
            && pflag[jj][2]==0 && pflag[jj][3]==0)
        {
            flag[jj]=0;
            //  pg->flag=0;
        }
        else 
        {			
            flag[jj]=2;			
            //     pg->flag=2;
            //  	printf("xc=%f,yc=%f\n",xc,yc);
        }
    }

    n0=nm1=n2=0;
    
    for(int jj=0;jj<N_BODY;++jj){
        if(flag[jj]==0) ++n0;
        if(flag[jj]==2) ++n2;
        if(flag[jj]==-1) ++nm1;
    }

    if(n0==N_BODY) pg->flag=0;
    else if(n2>0) pg->flag=2;
    else pg->flag=-1;

    //������������Ԫ��Ҫ������������ַ����������
    if(pg->flag==2)
    {
        //refcell[re][kref]=pg;
        //kref++;
        refcell[re].push_back(pg);
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdi, %rbx
movq %rdi, 0x28(%rsp)
movsd 0xfcfa(%rip), %xmm1     # 0x1b178
movsd 0x288(%rdi), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x18(%rsp)
mulsd 0x290(%rdi), %xmm1
movsd %xmm1, 0x20(%rsp)
movsd 0x278(%rdi), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x280(%rdi), %xmm1
movsd %xmm1, 0x10(%rsp)
leaq 0x1bdbf(%rip), %rsi     # 0x27280
movl $0x138, %edi            # imm = 0x138
callq 0x9c67
xorl %r15d, %r15d
cmpl $0x1, %eax
movl $0x0, %eax
sbbl %eax, %eax
movw %ax, 0x1b2(%rbx)
movsd 0x8(%rsp), %xmm4
movapd %xmm4, %xmm0
movsd 0x18(%rsp), %xmm3
subsd %xmm3, %xmm0
movsd %xmm0, 0x70(%rsp)
movsd 0x10(%rsp), %xmm5
movapd %xmm5, %xmm1
movsd 0x20(%rsp), %xmm2
subsd %xmm2, %xmm1
movsd %xmm1, 0x50(%rsp)
movsd %xmm0, 0x78(%rsp)
addsd %xmm5, %xmm2
movsd %xmm2, 0x58(%rsp)
movapd %xmm3, %xmm0
addsd %xmm4, %xmm0
movsd %xmm0, 0x80(%rsp)
movsd %xmm1, 0x60(%rsp)
movsd %xmm0, 0x88(%rsp)
movsd %xmm2, 0x68(%rsp)
leaq 0x17cb0(%rip), %r12     # 0x23200
leaq 0x17e29(%rip), %r14     # 0x23380
cmpq $0x4, %r15
je 0xb581
movsd 0x70(%rsp,%r15,8), %xmm0
movsd 0x50(%rsp,%r15,8), %xmm1
movl (%r12), %edi
movq %r14, %rsi
callq 0x9c67
movl %eax, 0x30(%rsp,%r15,4)
incq %r15
jmp 0xb557
movl 0x30(%rsp), %eax
movl 0x34(%rsp), %ecx
movl %eax, %edi
andl %ecx, %edi
movl 0x38(%rsp), %esi
movl 0x3c(%rsp), %edx
movl %esi, %r8d
andl %edx, %r8d
andl %edi, %r8d
cmpl $-0x1, %r8d
jne 0xb5ae
orw $-0x1, 0x1b0(%rbx)
jmp 0xb5e5
orl %ecx, %eax
orl %esi, %eax
orl %edx, %eax
jne 0xb5c0
andw $0x0, 0x1b0(%rbx)
jmp 0xb5e5
movw $0x2, 0x1b0(%rbx)
movslq 0x1d448(%rip), %rax     # 0x28a18
imulq $0x18, %rax, %rdi
addq 0x179ed(%rip), %rdi     # 0x22fc8
leaq 0x28(%rsp), %rsi
callq 0xb262
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq