// File: /workspace/github_c_makefile_star2_O1/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, %r14
movl %ecx, %r12d
movq %rdi, %r13
testl %esi, %esi
jle 0x1003c
movl %esi, %ebp
testl %r12d, %r12d
jle 0x10067
movq %rdx, %r15
leaq 0x10(%rsp), %rax
movq %rax, (%rsp)
leaq 0x14(%rsp), %r9
movq %r13, %rdi
movl %ebp, %esi
movl %r12d, %ecx
movq %r14, %r8
callq 0xfa40
movl %eax, %r8d
cmpl $0x2, %eax
jl 0x100b5
movl 0x10(%r14), %eax
movl %r13d, %ecx
subl %eax, %ecx
movl %ecx, %eax
cltd
idivl %ebx
leal 0x1(%rax), %edx
imull %ebx, %edx
subl %ecx, %edx
movslq 0x14(%rsp), %rsi
cmpl %esi, %edx
jge 0x1018a
movl 0x10(%rsp), %ecx
movq %r13, %rdi
movq %r15, %rdx
movq %r8, 0x20(%rsp)
movq %r14, %r8
movq %rsi, 0x18(%rsp)
movl %ebx, %r9d
callq 0xff91
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %r8
jmp 0x101b0
subq 0x10(%r14), %r13
movslq %ebx, %rcx
movq %r13, %rax
cqto
idivq %rcx
addl %eax, %eax
movl %eax, 0x10(%rsp)
movq 0x8(%r14), %rcx
cltq
addw %r12w, (%rcx,%rax,2)
addw %r12w, 0x2(%rcx,%rax,2)
jmp 0x10221
subl 0x10(%r14), %r13d
movl %r13d, %eax
cltd
idivl %ebx
leal 0x1(%rax), %ecx
imull %ebx, %ecx
subl %r13d, %ecx
movl %ecx, 0x14(%rsp)
addl %eax, %eax
movl %eax, 0x10(%rsp)
movslq %eax, %rdx
addq %rdx, %rdx
addq 0x8(%r14), %rdx
movl %ebp, %esi
cmpl %esi, %ecx
cmovgel %esi, %ecx
addw %cx, (%rdx)
addq $0x4, %rdx
addl $0x2, %eax
subl %ecx, %esi
movl %ebx, %ecx
jg 0x10090
movl %ebx, 0x14(%rsp)
movl %eax, 0x10(%rsp)
movl %ebp, %r12d
jmp 0x10221
testl %r8d, %r8d
setne %al
cmpl %r12d, %ebp
setge %cl
andb %al, %cl
movslq 0x14(%rsp), %rsi
movzbl %cl, %eax
movl %esi, %edi
subl %eax, %edi
testl %edi, %edi
jle 0x1010b
movl 0x10(%r14), %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
movq 0x8(%r14), %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 0x100f9
testl %r8d, %r8d
je 0x1021e
xorl %ecx, %ecx
cmpl %r12d, %ebp
setge %cl
leaq (%rsi,%r13), %rax
subq %rcx, %rax
subq 0x10(%r14), %rax
movslq %ebx, %rcx
cqto
idivq %rcx
addl %eax, %eax
movl %eax, 0x10(%rsp)
movq 0x8(%r14), %rcx
cltq
incw (%rcx,%rax,2)
cmpl %r12d, %ebp
jg 0x10149
incw 0x2(%rcx,%rax,2)
subl %esi, %ebp
jle 0x1021e
addl %esi, %r13d
subl 0x10(%r14), %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
cmpl %ebp, %edx
cmovgel %ebp, %edx
addw %dx, (%rax)
addq $0x4, %rax
subl %edx, %ebp
movl %ebx, %edx
jg 0x10173
jmp 0x1021e
leal (%rax,%rax), %ecx
leal 0x1(%r8), %edx
shrl %edx
movq 0x8(%r14), %rdi
movslq %ecx, %rcx
addw %dx, (%rdi,%rcx,2)
movzwl 0x10(%rsp), %ecx
leal 0x1(,%rax,2), %eax
cltq
addw %cx, (%rdi,%rax,2)
addq %rsi, %r13
movl 0x10(%r14), %eax
movl %r13d, %ecx
subl %eax, %ecx
movl %ecx, %eax
cltd
idivl %ebx
leal 0x1(%rax), %edx
imull %ebx, %edx
subl %ecx, %edx
subl %esi, %ebp
cmpl %ebp, %edx
jge 0x101f8
movslq 0x10(%rsp), %rax
addq %rax, %r15
subl %eax, %r12d
movq %r13, %rdi
movl %ebp, %esi
movq %r15, %rdx
movl %r12d, %ecx
movq %r8, %r15
movq %r14, %r8
movl %ebx, %r9d
callq 0xff91
movl %r15d, %r12d
jmp 0x10221
leal (%rax,%rax), %ecx
movl %r8d, %edx
shrl %edx
movq 0x8(%r14), %rsi
movslq %ecx, %rcx
addw %dx, (%rsi,%rcx,2)
subl 0x10(%rsp), %r12d
leal 0x1(,%rax,2), %eax
cltq
addw %r12w, (%rsi,%rax,2)
movl %r8d, %r12d
movl %r12d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq