// File: /workspace/github_c_makefile_star2_O3/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, %r13
movl %ecx, %r14d
movq %rdi, %r12
testl %esi, %esi
jle 0xfe2e
movl %esi, %ebp
testl %r14d, %r14d
jle 0xfe62
movq %rdx, %r15
movq 0x38(%r13), %r8
movq 0x40(%r13), %r9
leaq 0xc(%rsp), %rax
leaq 0x10(%rsp), %r10
movq %r12, %rdi
movl %ebp, %esi
movl %r14d, %ecx
pushq %rax
pushq %r10
callq 0xf82c
addq $0x10, %rsp
movl %eax, %r9d
cmpl $0x2, %eax
jl 0xfe9c
movq 0x10(%r13), %r8
movl %r12d, %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 0xff6b
movl 0xc(%rsp), %ecx
movl %ecx, 0x14(%rsp)
movq %r12, %rdi
movq %r15, %rdx
movq %rsi, 0x18(%rsp)
movq %r13, %r8
movq %r9, 0x20(%rsp)
movl %ebx, %r9d
callq 0xfd6d
movl 0x14(%rsp), %r10d
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %r9
movq 0x10(%r13), %r8
jmp 0xff92
subq 0x10(%r13), %r12
movslq %ebx, %rcx
movq %r12, %rax
cqto
idivq %rcx
addl %eax, %eax
movq 0x8(%r13), %rcx
cltq
movd (%rcx,%rax,2), %xmm0
movd %r14d, %xmm1
pshuflw $0x0, %xmm1, %xmm1      # xmm1 = xmm1[0,0,0,0,4,5,6,7]
paddw %xmm0, %xmm1
movd %xmm1, (%rcx,%rax,2)
jmp 0xfffe
subl 0x10(%r13), %r12d
movl %r12d, %eax
cltd
idivl %ebx
leal 0x1(%rax), %ecx
imull %ebx, %ecx
subl %r12d, %ecx
addl %eax, %eax
cltq
addq %rax, %rax
addq 0x8(%r13), %rax
movl %ebp, %edx
cmpl %edx, %ecx
cmovgel %edx, %ecx
addw %cx, (%rax)
addq $0x4, %rax
subl %ecx, %edx
movl %ebx, %ecx
jg 0xfe82
movl %ebp, %r14d
jmp 0xfffe
testl %r9d, %r9d
setne %al
cmpl %r14d, %ebp
setae %cl
andb %al, %cl
movslq 0x10(%rsp), %rsi
movzbl %cl, %eax
movl %esi, %edi
subl %eax, %edi
testl %edi, %edi
jle 0xfef2
movl 0x10(%r13), %eax
movl %r12d, %ecx
subl %eax, %ecx
movl %ecx, %eax
cltd
idivl %ebx
leal 0x1(%rax), %edx
imull %ebx, %edx
subl %ecx, %edx
addl %eax, %eax
movq 0x8(%r13), %rcx
cltq
leaq (%rcx,%rax,2), %rax
addq $0x2, %rax
cmpl %edi, %edx
cmovgel %edi, %edx
addw %dx, (%rax)
addq $0x4, %rax
subl %edx, %edi
movl %ebx, %edx
jg 0xfee0
testl %r9d, %r9d
je 0xfffb
leaq (%r12,%rsi), %rax
cmpl %r14d, %ebp
adcq $-0x1, %rax
movq 0x8(%r13), %rcx
movq 0x10(%r13), %rdi
subq %rdi, %rax
movslq %ebx, %r8
cqto
idivq %r8
addl %eax, %eax
cltq
incw (%rcx,%rax,2)
cmpl %r14d, %ebp
jg 0xff2b
incw 0x2(%rcx,%rax,2)
subl %esi, %ebp
jle 0xfff6
addl %esi, %r12d
subl %edi, %r12d
movl %r12d, %eax
cltd
idivl %ebx
leal 0x1(%rax), %edx
imull %ebx, %edx
subl %r12d, %edx
addl %eax, %eax
cltq
leaq (%rcx,%rax,2), %rax
addq $0x2, %rax
cmpl %ebp, %edx
cmovgel %ebp, %edx
addw %dx, (%rax)
addq $0x4, %rax
subl %edx, %ebp
movl %ebx, %edx
jg 0xff54
jmp 0xfff6
leal (%rax,%rax), %ecx
leal 0x1(%r9), %edx
shrl %edx
movq 0x8(%r13), %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, %r12
movl %r12d, %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 0xffd2
movslq %r10d, %rax
addq %rax, %r15
subl %r10d, %r14d
movq %r12, %rdi
movl %ebp, %esi
movq %r15, %rdx
movl %r14d, %ecx
movq %r13, %r8
movq %r9, %r14
movl %ebx, %r9d
callq 0xfd6d
jmp 0xfffe
leal (%rax,%rax), %ecx
movl %r9d, %edx
shrl %edx
movq 0x8(%r13), %rsi
movslq %ecx, %rcx
addw %dx, (%rsi,%rcx,2)
subl %r10d, %r14d
leal 0x1(,%rax,2), %eax
cltq
addw %r14w, (%rsi,%rax,2)
movl %r9d, %r14d
jmp 0xfffe
xorl %r14d, %r14d
movl %r14d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq