// File: 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:
subq $0xb8, %rsp
movq %rdi, 0xb0(%rsp)
movq 0xb0(%rsp), %rax
movsd 0x23141(%rip), %xmm0    # 0x3f140
mulsd 0x288(%rax), %xmm0
movsd %xmm0, 0x58(%rsp)
movq 0xb0(%rsp), %rax
movsd 0x23123(%rip), %xmm0    # 0x3f140
mulsd 0x290(%rax), %xmm0
movsd %xmm0, 0x40(%rsp)
movq 0xb0(%rsp), %rax
movsd 0x278(%rax), %xmm0
movsd %xmm0, 0x50(%rsp)
movq 0xb0(%rsp), %rax
movsd 0x280(%rax), %xmm0
movsd %xmm0, 0x48(%rsp)
movsd 0x50(%rsp), %xmm0
movsd 0x48(%rsp), %xmm1
movl $0x138, %edi            # imm = 0x138
leaq 0x332a1(%rip), %rsi     # 0x4f310
callq 0x15ff0
movl %eax, 0xa0(%rsp)
movl 0xa0(%rsp), %edx
xorl %eax, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpl $0x0, %edx
cmovel %ecx, %eax
movw %ax, %cx
movq 0xb0(%rsp), %rax
movw %cx, 0x1b2(%rax)
movsd 0x50(%rsp), %xmm0
subsd 0x58(%rsp), %xmm0
movsd %xmm0, 0x80(%rsp)
movsd 0x48(%rsp), %xmm0
subsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x60(%rsp)
movsd 0x50(%rsp), %xmm0
subsd 0x58(%rsp), %xmm0
movsd %xmm0, 0x88(%rsp)
movsd 0x48(%rsp), %xmm0
addsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x68(%rsp)
movsd 0x50(%rsp), %xmm0
addsd 0x58(%rsp), %xmm0
movsd %xmm0, 0x90(%rsp)
movsd 0x48(%rsp), %xmm0
subsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x70(%rsp)
movsd 0x50(%rsp), %xmm0
addsd 0x58(%rsp), %xmm0
movsd %xmm0, 0x98(%rsp)
movsd 0x48(%rsp), %xmm0
addsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x78(%rsp)
movl $0x0, 0x10(%rsp)
cmpl $0x1, 0x10(%rsp)
jge 0x1c2e0
movl $0x0, 0xa4(%rsp)
cmpl $0x4, 0xa4(%rsp)
jge 0x1c1e2
movslq 0xa4(%rsp), %rax
movsd 0x80(%rsp,%rax,8), %xmm0
movslq 0xa4(%rsp), %rax
movsd 0x60(%rsp,%rax,8), %xmm1
movslq 0x10(%rsp), %rcx
leaq 0x2f100(%rip), %rax     # 0x4b290
movl (%rax,%rcx,4), %edi
movslq 0x10(%rsp), %rax
leaq 0x2f271(%rip), %rsi     # 0x4b410
imulq $0x1f40, %rax, %rax     # imm = 0x1F40
addq %rax, %rsi
callq 0x15ff0
movl %eax, %edx
movslq 0x10(%rsp), %rcx
leaq 0x20(%rsp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movslq 0xa4(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0xa4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xa4(%rsp)
jmp 0x1c15b
movslq 0x10(%rsp), %rcx
leaq 0x20(%rsp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
cmpl $-0x1, (%rax)
jne 0x1c24f
movslq 0x10(%rsp), %rcx
leaq 0x20(%rsp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
cmpl $-0x1, 0x4(%rax)
jne 0x1c24f
movslq 0x10(%rsp), %rcx
leaq 0x20(%rsp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
cmpl $-0x1, 0x8(%rax)
jne 0x1c24f
movslq 0x10(%rsp), %rcx
leaq 0x20(%rsp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
cmpl $-0x1, 0xc(%rax)
jne 0x1c24f
movslq 0x10(%rsp), %rax
movl $0xffffffff, 0xa8(%rsp,%rax,4) # imm = 0xFFFFFFFF
jmp 0x1c2ce
movslq 0x10(%rsp), %rcx
leaq 0x20(%rsp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
cmpl $0x0, (%rax)
jne 0x1c2bc
movslq 0x10(%rsp), %rcx
leaq 0x20(%rsp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
cmpl $0x0, 0x4(%rax)
jne 0x1c2bc
movslq 0x10(%rsp), %rcx
leaq 0x20(%rsp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
cmpl $0x0, 0x8(%rax)
jne 0x1c2bc
movslq 0x10(%rsp), %rcx
leaq 0x20(%rsp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
cmpl $0x0, 0xc(%rax)
jne 0x1c2bc
movslq 0x10(%rsp), %rax
movl $0x0, 0xa8(%rsp,%rax,4)
jmp 0x1c2cc
movslq 0x10(%rsp), %rax
movl $0x2, 0xa8(%rsp,%rax,4)
jmp 0x1c2ce
jmp 0x1c2d0
movl 0x10(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10(%rsp)
jmp 0x1c145
movl $0x0, 0x14(%rsp)
movl $0x0, 0x18(%rsp)
movl $0x0, 0x1c(%rsp)
movl $0x0, 0xc(%rsp)
cmpl $0x1, 0xc(%rsp)
jge 0x1c364
movslq 0xc(%rsp), %rax
cmpl $0x0, 0xa8(%rsp,%rax,4)
jne 0x1c321
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
movslq 0xc(%rsp), %rax
cmpl $0x2, 0xa8(%rsp,%rax,4)
jne 0x1c33b
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
movslq 0xc(%rsp), %rax
cmpl $-0x1, 0xa8(%rsp,%rax,4)
jne 0x1c355
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
jmp 0x1c357
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x1c300
cmpl $0x1, 0x1c(%rsp)
jne 0x1c37e
movq 0xb0(%rsp), %rax
movw $0x0, 0x1b0(%rax)
jmp 0x1c3ab
cmpl $0x0, 0x14(%rsp)
jle 0x1c398
movq 0xb0(%rsp), %rax
movw $0x2, 0x1b0(%rax)
jmp 0x1c3a9
movq 0xb0(%rsp), %rax
movw $0xffff, 0x1b0(%rax)    # imm = 0xFFFF
jmp 0x1c3ab
movq 0xb0(%rsp), %rax
movswl 0x1b0(%rax), %eax
cmpl $0x2, %eax
jne 0x1c3e1
movslq 0x346e2(%rip), %rax     # 0x50aa8
leaq 0x2efb3(%rip), %rdi     # 0x4b380
imulq $0x18, %rax, %rax
addq %rax, %rdi
leaq 0xb0(%rsp), %rsi
callq 0x1b460
addq $0xb8, %rsp
retq
nopl (%rax)