// File: /workspace/github_cpp_makefile_star2_O3/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 0x10eaa(%rip), %xmm1    # 0x1d148
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 0x1bf9f(%rip), %rsi     # 0x28280
movl $0x138, %edi            # imm = 0x138
callq 0xa6f2
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 0x17e90(%rip), %r12     # 0x24200
leaq 0x18009(%rip), %r14     # 0x24380
movsd 0x70(%rsp,%r15,8), %xmm0
movsd 0x50(%rsp,%r15,8), %xmm1
movl (%r12), %edi
movq %r14, %rsi
callq 0xa6f2
movl %eax, 0x30(%rsp,%r15,4)
incq %r15
cmpq $0x4, %r15
jne 0xc377
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 0xc3cd
movw $0xffff, 0x1b0(%rbx)    # imm = 0xFFFF
jmp 0xc41d
orl %ecx, %eax
orl %esi, %eax
orl %edx, %eax
jne 0xc3e0
movw $0x0, 0x1b0(%rbx)
jmp 0xc41d
movw $0x2, 0x1b0(%rbx)
movslq 0x1d628(%rip), %rax     # 0x29a18
leaq (%rax,%rax,2), %rax
leaq 0x17ef5(%rip), %rcx     # 0x242f0
leaq (%rcx,%rax,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0xc413
movq %rbx, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0xc41d
leaq 0x28(%rsp), %rdx
callq 0xc142
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq