// File: /workspace/github_cpp_makefile_star2_O1/jamesliu516[P]amrdg2d/background_grid.cpp
// Function: background_grid()
void background_grid()
{
    int j,k, m;
    unsigned NO;

    double xMin, yMin;

    OctCell *pc;
    pc=bodygrid+1;
    NO=1u;
#ifndef EQUAL_SPACE_STEP
    bgrid = new GRIDCELL [Ny][Nx];
    gpoint = new PXYZ [NPOINT+1];
    gcell = new GRIDCELL [NCELL+1];	
    load_grid();
#endif        
    xMin=xLeft-2.0*hx;  //�Ⱦ�����
    yMin=yLow- 2.0*hy;

    for(j=1;j<=Ny;j++) {
        for(k=1;k<=Nx;k++) {	
            //	�Ⱦ�����
#ifdef  EQUAL_SPACE_STEP            				       		       
            bodygrid[(j-1)*Nx +k].xc1=hx/2.0+(k-1)*hx+xMin;
            bodygrid[(j-1)*Nx +k].yc1=hy/2.0+(j-1)*hy+yMin;	
            bodygrid[(j-1)*Nx +k].dx=hx;
            bodygrid[(j-1)*Nx +k].dy=hy;

            //------------------------------------------------------------------				
            //bodygrid[(j-1)*Nx +k]
#else 
            bodygrid[(j-1)*Nx +k].xc1 = 0.5*(gpoint[bgrid[j-1][k-1].pn[0]].x
                +gpoint[bgrid[j-1][k-1].pn[2]].x);
            bodygrid[(j-1)*Nx +k].yc1 = 0.5*(gpoint[bgrid[j-1][k-1].pn[0]].y
                +gpoint[bgrid[j-1][k-1].pn[2]].y);

            bodygrid[(j-1)*Nx +k].dx=gpoint[bgrid[j-1][k-1].pn[2]].x-gpoint[bgrid[j-1][k-1].pn[1]].x;
            bodygrid[(j-1)*Nx +k].dy=gpoint[bgrid[j-1][k-1].pn[0]].y-gpoint[bgrid[j-1][k-1].pn[1]].y; 
#endif				 
            //=================================================================				
            pc->set_invM();

            pc->flag=0;
            pc->level=0;
            pc->reflag=0;
            pc->coflag=0;
            pc->NOparent=NO;
            pc->parent=NULL;

            for(m=0;m<4;m++)  pc->children[m]=NULL;
            pc++;
            NO++;									  

            //	bodygrid[j][k].d = sqrt(bodygrid[j][k].xc1*bodygrid[j][k].xc1
            //		+bodygrid[j][k].yc1*bodygrid[j][k].yc1) - RADII;
        }			
    }
    cout<<"total background grid: "<< NO-1<<endl;	
#ifndef EQUAL_SPACE_STEP		
    delete [] gpoint;
    delete [] gcell;
    delete [] bgrid;
#endif
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
leaq 0x20fd8(%rip), %rax     # 0x252e0
movl $0x360, %ecx            # imm = 0x360
addq (%rax), %rcx
movl $0x1, %r8d
movl $0x1, %edx
movl $0x5e8, %esi            # imm = 0x5E8
movsd 0x19ce0(%rip), %xmm0    # 0x1e008
movsd 0x19ce0(%rip), %xmm1    # 0x1e010
movsd 0x19ce0(%rip), %xmm2    # 0x1e018
xorl %edi, %edi
movsd 0x19cde(%rip), %xmm3    # 0x1e020
movsd 0x19cde(%rip), %xmm4    # 0x1e028
movsd 0x19cde(%rip), %xmm5    # 0x1e030
movaps 0x19ce7(%rip), %xmm6    # 0x1e040
movapd 0x19cef(%rip), %xmm7    # 0x1e050
movapd 0x19cf6(%rip), %xmm8    # 0x1e060
xorps %xmm9, %xmm9
leal -0x1(%rdx), %r9d
xorps %xmm10, %xmm10
cvtsi2sd %r9d, %xmm10
mulsd %xmm0, %xmm10
addsd %xmm1, %xmm10
addsd %xmm2, %xmm10
movl %r8d, %r14d
xorl %r8d, %r8d
xorl %r15d, %r15d
leal (%r14,%r15), %r9d
xorps %xmm11, %xmm11
cvtsi2sd %r15d, %xmm11
mulsd %xmm3, %xmm11
addsd %xmm4, %xmm11
addsd %xmm5, %xmm11
movq (%rax), %r10
addq %rsi, %r10
movsd %xmm11, -0x10(%r8,%r10)
movsd %xmm10, -0x8(%r8,%r10)
movups %xmm6, (%r8,%r10)
movsd 0x288(%rcx,%r8), %xmm11
movsd 0x290(%rcx,%r8), %xmm12
unpcklpd %xmm11, %xmm11          # xmm11 = xmm11[0,0]
movapd %xmm7, %xmm13
divpd %xmm11, %xmm13
unpcklpd %xmm12, %xmm12          # xmm12 = xmm12[0,0]
divpd %xmm12, %xmm13
movupd %xmm13, (%rcx,%r8)
movhpd %xmm13, 0x10(%rcx,%r8)
movapd %xmm8, %xmm13
divpd %xmm11, %xmm13
divpd %xmm12, %xmm13
movupd %xmm13, 0x18(%rcx,%r8)
movhpd %xmm13, 0x28(%rcx,%r8)
movw %di, 0x1b0(%rcx,%r8)
movw %di, 0x1f8(%rcx,%r8)
movw %di, 0x1fc(%rcx,%r8)
movb $0x0, 0x1fe(%rcx,%r8)
movl %r9d, 0x200(%rcx,%r8)
movq $0x0, 0x250(%rcx,%r8)
movups %xmm9, 0x258(%rcx,%r8)
movups %xmm9, 0x268(%rcx,%r8)
incq %r15
addq $0x360, %r8             # imm = 0x360
cmpq $0x19f20, %r8           # imm = 0x19F20
jne 0x4393
incq %rdx
addq $0x19f20, %rsi          # imm = 0x19F20
addq %r8, %rcx
leal (%r14,%r15), %r8d
cmpq $0x42, %rdx
jne 0x436e
movq 0x20b26(%rip), %rbx     # 0x24fc8
leaq 0x19bc7(%rip), %rsi     # 0x1e070
movl $0x17, %edx
movq %rbx, %rdi
callq 0x3250
leal (%r14,%r15), %esi
decl %esi
movq %rbx, %rdi
callq 0x3160
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3200
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x3170