// File: jamesliu516[P]amrdg2d/solveAMR.cpp
// Function: smoothcell()
void smoothcell()
{
    //	long Nac;
    int hoflag,hiflag,i,nncell;
    Node *current;//新生成的四个节点
    OctCell *pc,*parent,*pp[4];//定义4个叶子节点的地址   
    int n_smth=3;
    do
    {
        //		releaselist(0);
        //		releasecelllist(Adpcelllist);
        //创建新的链表				
        //		Nac=FormAdpCellList(cartcell,cNx,cNy);

        releaseList();
        formListForAllGrid();
     //   setFlagForAll0();
        nncell=0;
        //current=Adpcelllist;
        current = HeadListAllGrid;

        while(current!=NULL)
        {             			
            pc=current->cell;
            if(pc->flag==0 && current->flg==0){
            //if(current->flg!=6){
                hiflag=0;
                hoflag=0;
                hoflag=chargeholegrid(pc);//判断是否是hole grid
//cout<<"smooth\n";
                //if(hoflag==1){printf("hoflag=%d\n",hoflag);getchar();}
                hiflag=chargehillgrid(pc);//判断是否是hill grid
                //if(hiflag==1){printf("hiflag=%d\n",hiflag);getchar();}
                /**/			
                if(hoflag==1) 
                {
                    creat_sol_children(pc);
                  //  pc->reflag=1;
                    nncell++;
                }

                if(hiflag==1)
                {	
                    parent=pc->parent;
                    for(i=0;i<4;i++)
                    {
                        pp[i]=parent->children[i];
                        pp[i]->coflag=true;
                    }
                    creatsolcoarseparent(parent,pp);
                    parent->coflag=false;
                    parent->reflag=0;
                    nncell++;
                }
            }
            current=current->next;
        }
        //	printf("nncell=%d\n",nncell);
        cout<<"nncell= "<<nncell<<endl;
        --n_smth;
    }while(nncell>0&& n_smth>0);
}

// Assembly:
subq $0x58, %rsp
movl $0x3, 0xc(%rsp)
callq 0x1b260
callq 0x1abd0
movl $0x0, 0x48(%rsp)
leaq 0x1357b(%rip), %rax     # 0x506a0
movq (%rax), %rax
movq %rax, 0x40(%rsp)
cmpq $0x0, 0x40(%rsp)
je 0x3d263
movq 0x40(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rax
movswl 0x1b0(%rax), %eax
cmpl $0x0, %eax
jne 0x3d250
movq 0x40(%rsp), %rax
movswl (%rax), %eax
cmpl $0x0, %eax
jne 0x3d250
movl $0x0, 0x50(%rsp)
movl $0x0, 0x54(%rsp)
movq 0x38(%rsp), %rdi
callq 0x3cf80
movl %eax, 0x54(%rsp)
movq 0x38(%rsp), %rdi
callq 0x3d020
movl %eax, 0x50(%rsp)
cmpl $0x1, 0x54(%rsp)
jne 0x3d1b5
movq 0x38(%rsp), %rdi
callq 0x3b340
movl 0x48(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x48(%rsp)
cmpl $0x1, 0x50(%rsp)
jne 0x3d24e
movq 0x38(%rsp), %rax
movq 0x250(%rax), %rax
movq %rax, 0x30(%rsp)
movl $0x0, 0x4c(%rsp)
cmpl $0x4, 0x4c(%rsp)
jge 0x3d21a
movq 0x30(%rsp), %rax
movslq 0x4c(%rsp), %rcx
movq 0x258(%rax,%rcx,8), %rcx
movslq 0x4c(%rsp), %rax
movq %rcx, 0x10(%rsp,%rax,8)
movslq 0x4c(%rsp), %rax
movq 0x10(%rsp,%rax,8), %rax
movb $0x1, 0x1fe(%rax)
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
jmp 0x3d1d9
movq 0x30(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x3c4b0
movq 0x30(%rsp), %rax
movb $0x0, 0x1fe(%rax)
movq 0x30(%rsp), %rax
movw $0x0, 0x1fc(%rax)
movl 0x48(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x48(%rsp)
jmp 0x3d250
movq 0x40(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x40(%rsp)
jmp 0x3d12d
movq 0xdd66(%rip), %rdi      # 0x4afd0
leaq 0x29b3(%rip), %rsi      # 0x3fc24
callq 0x3240
movq %rax, %rdi
movl 0x48(%rsp), %esi
callq 0x3420
movq %rax, %rdi
movq 0xdd2c(%rip), %rsi      # 0x4afb8
callq 0x3290
movl 0xc(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0xc(%rsp)
xorl %eax, %eax
cmpl $0x0, 0x48(%rsp)
movb %al, 0xb(%rsp)
jle 0x3d2b5
cmpl $0x0, 0xc(%rsp)
setg %al
movb %al, 0xb(%rsp)
movb 0xb(%rsp), %al
testb $0x1, %al
jne 0x3d10c
addq $0x58, %rsp
retq
nopw %cs:(%rax,%rax)