// File: /workspace/github_c_makefile_star2_O2/thegenemyers[P]DASCRUBBER/align.c
// Function: trace_nd
static int trace_nd(char *A, int M, char *B, int N, Trace_Waves *wave, int tspace)
{ int x, y;
  int D, s;

#ifdef DEBUG_ALIGN
  printf("%*s %ld,%ld: %d vs %d\n",depth,"",A-wave->Aabs,B-wave->Babs,M,N);
  fflush(stdout);
#endif

  if (M <= 0)
    { y = (((A-wave->Aabs)/tspace) << 1);
      wave->Trace[y] += N;
      wave->Trace[y+1] += N;
#ifdef DEBUG_TRACE
      printf("%*s Adding1 (%d,%d) to tp %d(%d,%d)\n",depth,"",N,N,y>>1,
                                                     wave->Trace[y+1],wave->Trace[y]);
      fflush(stdout);
#endif
      return (N);
    }

  if (N <= 0)
    { x = A - wave->Aabs;
      y = x/tspace;
      x = (y+1)*tspace - x;
      y <<= 1;
      for (s = M; s > 0; s -= x, x = tspace)
        { if (x > s)
            x = s;
          wave->Trace[y] += x;
#ifdef DEBUG_TRACE
          printf("%*s Adding2 (0,%d) to tp %d(%d,%d)\n",depth,"",x,y>>1,
                                                        wave->Trace[y+1],wave->Trace[y]);
          fflush(stdout);
#endif
          y += 2;
        }
      return (M);
    }

  D = split_nd(A,M,B,N,wave,&x,&y);

  if (D > 1)
    {
#ifdef DEBUG_ALIGN
      printf("%*s (%d,%d) @ %d\n",depth,"",x,y,D);
      fflush(stdout);
      depth += 2;
#endif

      s = A-wave->Aabs;
      if ((s/tspace+1)*tspace - s >= x)
        { s = ((s/tspace)<<1);
          wave->Trace[s] += (D+1)/2;
          wave->Trace[s+1] += y;
#ifdef DEBUG_TRACE
          printf("%*s Adding3 (%d,%d) to tp %d(%d,%d)\n",depth,"",y,(D+1)/2,s>>1,
                                                         wave->Trace[s+1],wave->Trace[s]);
          fflush(stdout);
#endif
        }
      else
        trace_nd(A,x,B,y,wave,tspace);

      s = (A+x)-wave->Aabs;
      if ((s/tspace+1)*tspace - s >= M-x)
        { s = ((s/tspace)<<1);
          wave->Trace[s] += D/2;
          wave->Trace[s+1] += N-y;
#ifdef DEBUG_TRACE
          printf("%*s Adding4 (%d,%d)) to tp %d(%d,%d)\n",depth,"",N-y,D/2,s>>1,
                                                          wave->Trace[s+1],wave->Trace[s]);
          fflush(stdout);
#endif
        }
      else
        trace_nd(A+x,M-x,B+y,N-y,wave,tspace);

#ifdef DEBUG_ALIGN
      depth -= 2;
#endif
    }

  else
    { int u, v;

      if (D == 0 || M < N)
        s = x;
      else
        s = x-1;
      if (s > 0)
        { u = A - wave->Aabs;
          v = u/tspace;
          u = (v+1)*tspace - u;
          for (v <<= 1; s > 0; s -= u, u = tspace)
            { if (u > s)
                u = s;
              wave->Trace[v+1] += u;
#ifdef DEBUG_TRACE
              printf("%*s Adding5 (%d,0)) to tp %d(%d,%d)\n",depth,"",u,v>>1,
                                                             wave->Trace[v+1],wave->Trace[v]);
              fflush(stdout);
#endif
              v += 2;
            }
        }

      if (D == 0)
        return (D);

      if (M < N)
        y = ((((A+x)-wave->Aabs)/tspace)<<1);
      else
        y = ((((A+(x-1))-wave->Aabs)/tspace)<<1);
      wave->Trace[y] += 1;
      if (M <= N)
        wave->Trace[y+1] += 1;
#ifdef DEBUG_TRACE
      printf("%*s Adding5 (%d,1)) to tp %d(%d,%d)\n",depth,"",N>=M,y>>1,
                                                     wave->Trace[y+1],wave->Trace[y]);
      fflush(stdout);
#endif

      s = M-x;
      if (s > 0)
        { u = (A+x) - wave->Aabs;
          v = u/tspace;
          u = (v+1)*tspace - u;
          for (v <<= 1; s > 0; s -= u, u = tspace)
            { if (u > s)
                u = s;
              wave->Trace[v+1] += u;
#ifdef DEBUG_TRACE
              printf("%*s Adding5 (%d,0)) to tp %d(%d,%d)\n",depth,"",u,v>>1,
                                                             wave->Trace[v+1],wave->Trace[v]);
              fflush(stdout);
#endif
              v += 2;
            }
        }
    }

  return (D);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r9d, %ebx
movq %r8, %r12
movl %ecx, %r15d
movq %rdi, %r13
testl %esi, %esi
jle 0xe8e4
movl %esi, %ebp
testl %r15d, %r15d
jle 0xe91a
movq %rdx, %r14
leaq 0xc(%rsp), %rax
movq %rax, (%rsp)
leaq 0x10(%rsp), %r9
movq %r13, %rdi
movl %ebp, %esi
movl %r15d, %ecx
movq %r12, %r8
callq 0xe316
movl %eax, %r9d
cmpl $0x2, %eax
jl 0xe95b
movq 0x10(%r12), %r8
movl %r13d, %ecx
subl %r8d, %ecx
movl %ecx, %eax
cltd
idivl %ebx
leal 0x1(%rax), %edx
imull %ebx, %edx
subl %ecx, %edx
movslq 0x10(%rsp), %rsi
cmpl %esi, %edx
jge 0xea36
movl 0xc(%rsp), %ecx
movl %ecx, 0x14(%rsp)
movq %r13, %rdi
movq %r14, %rdx
movq %rsi, 0x18(%rsp)
movq %r12, %r8
movq %r9, 0x20(%rsp)
movl %ebx, %r9d
callq 0xe829
movl 0x14(%rsp), %r10d
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %r9
movq 0x10(%r12), %r8
jmp 0xea5e
subq 0x10(%r12), %r13
movslq %ebx, %rcx
movq %r13, %rax
cqto
idivq %rcx
addl %eax, %eax
movq 0x8(%r12), %rcx
cltq
movd (%rcx,%rax,2), %xmm0
movd %r15d, %xmm1
pshuflw $0x0, %xmm1, %xmm1      # xmm1 = xmm1[0,0,0,0,4,5,6,7]
paddw %xmm0, %xmm1
movd %xmm1, (%rcx,%rax,2)
jmp 0xeace
subl 0x10(%r12), %r13d
movl %r13d, %eax
cltd
idivl %ebx
leal 0x1(%rax), %ecx
imull %ebx, %ecx
subl %r13d, %ecx
addl %eax, %eax
cltq
addq %rax, %rax
movl %ebp, %edx
testl %edx, %edx
jle 0xe953
cmpl %edx, %ecx
cmovgel %edx, %ecx
movq 0x8(%r12), %rsi
addw %cx, (%rsi,%rax)
subl %ecx, %edx
addq $0x4, %rax
movl %ebx, %ecx
jmp 0xe937
movl %ebp, %r15d
jmp 0xeace
testl %r9d, %r9d
setne %al
cmpl %r15d, %ebp
setae %cl
andb %al, %cl
movslq 0x10(%rsp), %rsi
movzbl %cl, %eax
movl %esi, %edi
subl %eax, %edi
testl %edi, %edi
jle 0xe9b8
movl 0x10(%r12), %eax
movl %r13d, %ecx
subl %eax, %ecx
movl %ecx, %eax
cltd
idivl %ebx
leal 0x1(%rax), %edx
imull %ebx, %edx
subl %ecx, %edx
addl %eax, %eax
cltq
leaq 0x2(,%rax,2), %rax
testl %edi, %edi
jle 0xe9b8
cmpl %edi, %edx
cmovgel %edi, %edx
movq 0x8(%r12), %rcx
addw %dx, (%rcx,%rax)
subl %edx, %edi
addq $0x4, %rax
movl %ebx, %edx
jmp 0xe99c
testl %r9d, %r9d
je 0xeacb
leaq (%rsi,%r13), %rax
cmpl %r15d, %ebp
adcq $-0x1, %rax
movq 0x8(%r12), %rcx
movq 0x10(%r12), %rdi
subq %rdi, %rax
movslq %ebx, %r8
cqto
idivq %r8
addl %eax, %eax
cltq
incw (%rcx,%rax,2)
cmpl %r15d, %ebp
jg 0xe9f3
incw 0x2(%rcx,%rax,2)
subl %esi, %ebp
jle 0xeac6
addl %esi, %r13d
subl %edi, %r13d
movl %r13d, %eax
cltd
idivl %ebx
leal 0x1(%rax), %edx
imull %ebx, %edx
subl %r13d, %edx
addl %eax, %eax
cltq
leaq (%rcx,%rax,2), %rax
addq $0x2, %rax
testl %ebp, %ebp
jle 0xeac6
cmpl %ebp, %edx
cmovgel %ebp, %edx
addw %dx, (%rax)
subl %edx, %ebp
addq $0x4, %rax
movl %ebx, %edx
jmp 0xea1c
leal (%rax,%rax), %ecx
leal 0x1(%r9), %edx
shrl %edx
movq 0x8(%r12), %rdi
movslq %ecx, %rcx
addw %dx, (%rdi,%rcx,2)
movl 0xc(%rsp), %r10d
leal 0x1(,%rax,2), %eax
cltq
addw %r10w, (%rdi,%rax,2)
addq %rsi, %r13
movl %r13d, %ecx
subl %r8d, %ecx
movl %ecx, %eax
cltd
idivl %ebx
leal 0x1(%rax), %edx
imull %ebx, %edx
subl %ecx, %edx
subl %esi, %ebp
cmpl %ebp, %edx
jge 0xeaa1
movslq %r10d, %rax
addq %rax, %r14
subl %r10d, %r15d
movq %r13, %rdi
movl %ebp, %esi
movq %r14, %rdx
movl %r15d, %ecx
movq %r12, %r8
movq %r9, %r14
movl %ebx, %r9d
callq 0xe829
movl %r14d, %r15d
jmp 0xeace
leal (%rax,%rax), %ecx
movl %r9d, %edx
shrl %edx
movq 0x8(%r12), %rsi
movslq %ecx, %rcx
addw %dx, (%rsi,%rcx,2)
subl %r10d, %r15d
leal 0x1(,%rax,2), %eax
cltq
addw %r15w, (%rsi,%rax,2)
movl %r9d, %r15d
jmp 0xeace
xorl %r15d, %r15d
movl %r15d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq