// File: /workspace/github_cpp_makefile_star2_O1/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 %rbx
subq $0x90, %rsp
movq %rdi, 0x8(%rsp)
movsd 0x11d37(%rip), %xmm1    # 0x1e148
movsd 0x288(%rdi), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rsp)
mulsd 0x290(%rdi), %xmm1
movsd %xmm1, 0x28(%rsp)
movsd 0x278(%rdi), %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x280(%rdi), %xmm1
movsd %xmm1, 0x18(%rsp)
leaq 0x1ce2c(%rip), %rsi     # 0x29280
movl $0x138, %edi            # imm = 0x138
callq 0xa82f
xorl %r14d, %r14d
cmpl $0x1, %eax
movl $0x0, %eax
sbbl %eax, %eax
movq 0x8(%rsp), %rcx
movw %ax, 0x1b2(%rcx)
movsd 0x10(%rsp), %xmm4
movapd %xmm4, %xmm0
movsd 0x20(%rsp), %xmm3
subsd %xmm3, %xmm0
movsd %xmm0, 0x70(%rsp)
movsd 0x18(%rsp), %xmm5
movapd %xmm5, %xmm1
movsd 0x28(%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 0x18d18(%rip), %r15     # 0x25200
leaq 0x18e91(%rip), %rbx     # 0x25380
movsd 0x70(%rsp,%r14,8), %xmm0
movsd 0x50(%rsp,%r14,8), %xmm1
movl (%r15), %edi
movq %rbx, %rsi
callq 0xa82f
movl %eax, 0x30(%rsp,%r14,4)
incq %r14
cmpq $0x4, %r14
jne 0xc4ef
movl 0x30(%rsp), %ecx
movl 0x34(%rsp), %esi
movl %ecx, %eax
andl %esi, %eax
movl 0x38(%rsp), %edi
movl 0x3c(%rsp), %edx
movl %edi, %r8d
andl %edx, %r8d
andl %eax, %r8d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl $-0x1, %r8d
je 0xc54b
orl %esi, %ecx
orl %edi, %ecx
xorl %eax, %eax
orl %edx, %ecx
setne %al
addl %eax, %eax
movq 0x8(%rsp), %rcx
xorl %edx, %edx
cmpl $0x2, %eax
sete %dl
leal (%rdx,%rdx,2), %edx
decl %edx
testl %eax, %eax
cmovel %eax, %edx
movw %dx, 0x1b0(%rcx)
movq 0x8(%rsp), %rax
cmpw $0x2, 0x1b0(%rax)
jne 0xc5ac
movslq 0x1e499(%rip), %rcx     # 0x2aa18
leaq (%rcx,%rcx,2), %rcx
leaq 0x18d66(%rip), %rdx     # 0x252f0
leaq (%rdx,%rcx,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0xc5a2
movq %rax, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0xc5ac
leaq 0x8(%rsp), %rdx
callq 0xc2bc
addq $0x90, %rsp
popq %rbx
popq %r14
popq %r15
retq