// File: /workspace/github_cpp_makefile_star2_O3/tlestang[P]IW_gene/topo.cpp
// Function: Topography::HalfWayFreeSlipBC(VelSite**, VelSite**)
void Topography::HalfWayFreeSlipBC(VelSite **sites, VelSite **_sites)
{  int x,y, xm, xp;
  int op[9] = {0, 1, 4, 3, 2, 6, 5, 8, 7};
  double dd; int cc= 0;

  // ofstream bb, lns, rns, ts;
  // bb.open("bb.dat");lns.open("lns.dat");rns.open("rns.dat");ts.open("ts.dat");
  for (int i=0;i<nbNodes;i++)
    {
      x = nodes[i][0]; y = nodes[i][1];
      xp = (x + 1 + nbNodes)%nbNodes; 
      xm = (x - 1 + nbNodes)%nbNodes; 
      //flat wall
      if(lbl[i] == 1)
	{
	  _sites[x][y].f[6] = sites[xm][y].f[7];
	  _sites[x][y].f[2] = sites[x][y].f[4];
	  _sites[x][y].f[5] = sites[xp][y].f[8];
	}

      //External corner
       else if(lbl[i] == 2)
	{
	  if(nodes[i][0] == 0 || nodes[i][0] == nbNodes-1){dd = +1;}
	  else{dd = (nodes[i+1][1]-nodes[i-1][1])/2.;}

	  if(dd > 0.) // if mur gauche
	    {
	      _sites[x][y].f[6] = sites[x][y].f[8];
	    }
	  else
	    {
	      _sites[x][y].f[5] = sites[x][y].f[7];
	    }
	}
      
      // internal corner
       else{
	 if(nodes[i][0] == 0 || nodes[i][0] == nbNodes-1){dd = +1;}
	 else{dd = (nodes[i+1][1]-nodes[i-1][1])/2.;}
	 if(dd > 0.)
	   {
	     _sites[x][y].f[2] = sites[x][y].f[4];
	     _sites[x][y].f[3] = sites[x][y].f[1];
	     _sites[x][y].f[6] = sites[x][y].f[8];
	     _sites[x][y].f[5] = sites[xm][y].f[8];
	   }
	 else
	   {
	     _sites[x][y].f[2] = sites[x][y].f[4];
	     _sites[x][y].f[1] = sites[x][y].f[3];
	     _sites[x][y].f[5] = sites[x][y].f[7];
	     _sites[x][y].f[6] = sites[xp][y].f[7];
	   }
       }
    }
}

// Assembly:
movslq 0x8(%rdi), %r8
testq %r8, %r8
jle 0x356e
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdx, %rcx
movq 0x10(%rdi), %r9
movq 0x18(%rdi), %r10
leal 0x1(%r8), %r11d
leal -0x1(%r8), %ebx
xorl %r14d, %r14d
movsd 0x2de9(%rip), %xmm0     # 0x6188
xorpd %xmm1, %xmm1
movq (%r9,%r14,8), %rax
movslq (%rax), %r15
movslq 0x4(%rax), %r12
leal (%r11,%r15), %eax
cltd
idivl %r8d
movl %edx, %edi
leal (%rbx,%r15), %eax
cltd
idivl %r8d
movl (%r10,%r14,4), %eax
cmpl $0x2, %eax
je 0x341d
cmpl $0x1, %eax
jne 0x3470
movslq %edx, %rax
movq (%rsi,%rax,8), %rax
movq %r12, %rdx
shlq $0x7, %rdx
leaq (%rdx,%r12,8), %rdx
movsd 0x40(%rax,%rdx), %xmm2
movq (%rcx,%r15,8), %rax
movsd %xmm2, 0x38(%rax,%rdx)
movq (%rsi,%r15,8), %r15
movsd 0x28(%r15,%rdx), %xmm2
movsd %xmm2, 0x18(%rax,%rdx)
movslq %edi, %rdi
movq (%rsi,%rdi,8), %rdi
movsd 0x48(%rdi,%rdx), %xmm2
movsd %xmm2, 0x30(%rax,%rdx)
jmp 0x3558
testl %r15d, %r15d
je 0x344c
cmpl %ebx, %r15d
je 0x344c
movq -0x8(%r9,%r14,8), %rax
movq 0x8(%r9,%r14,8), %rdx
movl 0x4(%rdx), %edx
subl 0x4(%rax), %edx
xorps %xmm2, %xmm2
cvtsi2sd %edx, %xmm2
mulsd %xmm0, %xmm2
ucomisd %xmm1, %xmm2
jbe 0x34ec
movq (%rsi,%r15,8), %rax
movq %r12, %rdx
shlq $0x7, %rdx
leaq (%rdx,%r12,8), %rdx
movsd 0x48(%rax,%rdx), %xmm2
movq (%rcx,%r15,8), %rax
movsd %xmm2, 0x38(%rax,%rdx)
jmp 0x3558
testl %r15d, %r15d
je 0x349c
cmpl %ebx, %r15d
je 0x349c
movq -0x8(%r9,%r14,8), %rax
movq 0x8(%r9,%r14,8), %r13
movl 0x4(%r13), %ebp
subl 0x4(%rax), %ebp
xorps %xmm2, %xmm2
cvtsi2sd %ebp, %xmm2
mulsd %xmm0, %xmm2
ucomisd %xmm1, %xmm2
jbe 0x350a
movq (%rsi,%r15,8), %rax
movq %r12, %rdi
shlq $0x7, %rdi
leaq (%rdi,%r12,8), %rdi
movsd 0x28(%rax,%rdi), %xmm2
movq (%rcx,%r15,8), %r15
movsd %xmm2, 0x18(%r15,%rdi)
movsd 0x10(%rax,%rdi), %xmm2
movsd %xmm2, 0x20(%r15,%rdi)
movsd 0x48(%rax,%rdi), %xmm2
movsd %xmm2, 0x38(%r15,%rdi)
movslq %edx, %rax
movq (%rsi,%rax,8), %rax
movsd 0x48(%rax,%rdi), %xmm2
movsd %xmm2, 0x30(%r15,%rdi)
jmp 0x3558
movq (%rsi,%r15,8), %rax
movq %r12, %rdx
shlq $0x7, %rdx
leaq (%rdx,%r12,8), %rdx
movsd 0x40(%rax,%rdx), %xmm2
movq (%rcx,%r15,8), %rax
jmp 0x3412
movq (%rsi,%r15,8), %rax
movq %r12, %rdx
shlq $0x7, %rdx
leaq (%rdx,%r12,8), %rdx
movsd 0x28(%rax,%rdx), %xmm2
movq (%rcx,%r15,8), %r15
movsd %xmm2, 0x18(%r15,%rdx)
movsd 0x20(%rax,%rdx), %xmm2
movsd %xmm2, 0x10(%r15,%rdx)
movsd 0x40(%rax,%rdx), %xmm2
movsd %xmm2, 0x30(%r15,%rdx)
movslq %edi, %rax
movq (%rsi,%rax,8), %rax
movsd 0x40(%rax,%rdx), %xmm2
movsd %xmm2, 0x38(%r15,%rdx)
incq %r14
cmpq %r14, %r8
jne 0x33a3
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop